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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3031b298779690d69993ba876ffbb9441394dcca | e514e8b939af519a1d5e9b30a850769d058df4e9 | /src/tactic/rewrite_search/metric/trivial.lean | 0aa0c482727a01040c4d598200f3fd964f39ab04 | [] | no_license | semorrison/lean-rewrite-search | dca317c5a52e170fb6ffc87c5ab767afb5e3e51a | e804b8f2753366b8957be839908230ee73f9e89f | refs/heads/master | 1,624,051,754,485 | 1,614,160,817,000 | 1,614,160,817,000 | 162,660,605 | 0 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 1,353 | lean | import tactic.rewrite_search.core
import tactic.rewrite_search.module
-- The trivial metric: I just report that every vertex is distance zero from every other.
open tactic.rewrite_search
namespace tactic.rewrite_search.metric.trivial
variables {Ξ± Ξ΄ : Type} (g : search_state Ξ± unit unit Ξ΄)
meta def trivial_init : tactic (init_result unit) := init_result.pure ()
meta def trivial_update (itr : β) : tactic (search_state Ξ± unit unit Ξ΄) := return g
meta def trivial_init_bound (_ : search_state Ξ± unit unit Ξ΄) (l r : vertex) : bound_progress unit := bound_progress.exactly 0 ()
meta def trivial_improve_estimate_over (_ : search_state Ξ± unit unit Ξ΄) (m : dnum) (l r : vertex) (bnd : bound_progress unit) : bound_progress unit := bound_progress.exactly 0 ()
end tactic.rewrite_search.metric.trivial
namespace tactic.rewrite_search.metric
open tactic.rewrite_search.metric.trivial
meta def trivial_cnst := Ξ» Ξ± Ξ΄, @metric.mk Ξ± unit unit Ξ΄ trivial_init trivial_update trivial_init_bound trivial_improve_estimate_over
meta def trivial : tactic expr :=
generic ``tactic.rewrite_search.metric.trivial_cnst
meta def trivial_cfg (_ : name) : cfgtactic unit :=
iconfig.publish `metric $ cfgopt.value.pexpr $ expr.const `trivial []
iconfig_add rewrite_search [ metric.trivial : custom trivial_cfg ]
end tactic.rewrite_search.metric
|
3c0cfa04b3d59a55e90d4cab2303b3e93e374889 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/ring_theory/derivation.lean | 53013c8efc68723e62465ef19fe402d574a52471 | [
"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 | 13,442 | lean | /-
Copyright Β© 2020 NicolΓ² Cavalleri. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: NicolΓ² Cavalleri
-/
import ring_theory.adjoin.basic
import algebra.lie.of_associative
/-!
# Derivations
This file defines derivation. A derivation `D` from the `R`-algebra `A` to the `A`-module `M` is an
`R`-linear map that satisfy the Leibniz rule `D (a * b) = a * D b + D a * b`.
## Notation
The notation `β
D1, D2β` is used for the commutator of two derivations.
TODO: this file is just a stub to go on with some PRs in the geometry section. It only
implements the definition of derivations in commutative algebra. This will soon change: as soon
as bimodules will be there in mathlib I will change this file to take into account the
non-commutative case. Any development on the theory of derivations is discouraged until the
definitive definition of derivation will be implemented.
-/
open algebra
open_locale big_operators
/-- `D : derivation R A M` is an `R`-linear map from `A` to `M` that satisfies the `leibniz`
equality. We also require that `D 1 = 0`. See `derivation.mk'` for a constructor that deduces this
assumption from the Leibniz rule when `M` is cancellative.
TODO: update this when bimodules are defined. -/
@[protect_proj]
structure derivation (R : Type*) (A : Type*) [comm_semiring R] [comm_semiring A]
[algebra R A] (M : Type*) [add_comm_monoid M] [module A M] [module R M]
extends A ββ[R] M :=
(map_one_eq_zero' : to_linear_map 1 = 0)
(leibniz' (a b : A) : to_linear_map (a * b) = a β’ to_linear_map b + b β’ to_linear_map a)
/-- The `linear_map` underlying a `derivation`. -/
add_decl_doc derivation.to_linear_map
namespace derivation
section
variables {R : Type*} [comm_semiring R]
variables {A : Type*} [comm_semiring A] [algebra R A]
variables {M : Type*} [add_comm_monoid M] [module A M] [module R M]
variables (D : derivation R A M) {D1 D2 : derivation R A M} (r : R) (a b : A)
instance : add_monoid_hom_class (derivation R A M) A M :=
{ coe := Ξ» D, D.to_fun,
coe_injective' := Ξ» D1 D2 h, by { cases D1, cases D2, congr, exact fun_like.coe_injective h },
map_add := Ξ» D, D.to_linear_map.map_add',
map_zero := Ξ» D, D.to_linear_map.map_zero }
/-- Helper instance for when there's too many metavariables to apply `fun_like.has_coe_to_fun`
directly. -/
instance : has_coe_to_fun (derivation R A M) (Ξ» _, A β M) := β¨Ξ» D, D.to_linear_map.to_funβ©
-- Not a simp lemma because it can be proved via `coe_fn_coe` + `to_linear_map_eq_coe`
lemma to_fun_eq_coe : D.to_fun = βD := rfl
instance has_coe_to_linear_map : has_coe (derivation R A M) (A ββ[R] M) :=
β¨Ξ» D, D.to_linear_mapβ©
@[simp] lemma to_linear_map_eq_coe : D.to_linear_map = D := rfl
@[simp] lemma mk_coe (f : A ββ[R] M) (hβ hβ) :
((β¨f, hβ, hββ© : derivation R A M) : A β M) = f := rfl
@[simp, norm_cast]
lemma coe_fn_coe (f : derivation R A M) : β(f : A ββ[R] M) = f := rfl
lemma coe_injective : @function.injective (derivation R A M) (A β M) coe_fn :=
fun_like.coe_injective
@[ext] theorem ext (H : β a, D1 a = D2 a) : D1 = D2 :=
fun_like.ext _ _ H
lemma congr_fun (h : D1 = D2) (a : A) : D1 a = D2 a := fun_like.congr_fun h a
protected lemma map_add : D (a + b) = D a + D b := map_add D a b
protected lemma map_zero : D 0 = 0 := map_zero D
@[simp] lemma map_smul : D (r β’ a) = r β’ D a := D.to_linear_map.map_smul r a
@[simp] lemma leibniz : D (a * b) = a β’ D b + b β’ D a := D.leibniz' _ _
lemma map_sum {ΞΉ : Type*} (s : finset ΞΉ) (f : ΞΉ β A) : D (β i in s, f i) = β i in s, D (f i) :=
D.to_linear_map.map_sum
@[simp, priority 900] lemma map_smul_of_tower {S : Type*} [has_scalar S A] [has_scalar S M]
[linear_map.compatible_smul A M S R] (D : derivation R A M) (r : S) (a : A) :
D (r β’ a) = r β’ D a :=
D.to_linear_map.map_smul_of_tower r a
@[simp] lemma map_one_eq_zero : D 1 = 0 := D.map_one_eq_zero'
@[simp] lemma map_algebra_map : D (algebra_map R A r) = 0 :=
by rw [βmul_one r, ring_hom.map_mul, ring_hom.map_one, βsmul_def, map_smul, map_one_eq_zero,
smul_zero]
@[simp] lemma map_coe_nat (n : β) : D (n : A) = 0 :=
by rw [β nsmul_one, D.map_smul_of_tower n, map_one_eq_zero, smul_zero]
@[simp] lemma leibniz_pow (n : β) : D (a ^ n) = n β’ a ^ (n - 1) β’ D a :=
begin
induction n with n ihn,
{ rw [pow_zero, map_one_eq_zero, zero_smul] },
{ rcases (zero_le n).eq_or_lt with (rfl|hpos),
{ rw [pow_one, one_smul, pow_zero, one_smul] },
{ have : a * a ^ (n - 1) = a ^ n, by rw [β pow_succ, nat.sub_add_cancel hpos],
simp only [pow_succ, leibniz, ihn, smul_comm a n, smul_smul a, add_smul, this,
nat.succ_eq_add_one, nat.add_succ_sub_one, add_zero, one_nsmul] } }
end
lemma eq_on_adjoin {s : set A} (h : set.eq_on D1 D2 s) : set.eq_on D1 D2 (adjoin R s) :=
Ξ» x hx, algebra.adjoin_induction hx h
(Ξ» r, (D1.map_algebra_map r).trans (D2.map_algebra_map r).symm)
(Ξ» x y hx hy, by simp only [map_add, *])
(Ξ» x y hx hy, by simp only [leibniz, *])
/-- If adjoin of a set is the whole algebra, then any two derivations equal on this set are equal
on the whole algebra. -/
lemma ext_of_adjoin_eq_top (s : set A) (hs : adjoin R s = β€) (h : set.eq_on D1 D2 s) : D1 = D2 :=
ext $ Ξ» a, eq_on_adjoin h $ hs.symm βΈ trivial
/- Data typeclasses -/
instance : has_zero (derivation R A M) :=
β¨{ to_linear_map := 0,
map_one_eq_zero' := rfl,
leibniz' := Ξ» a b, by simp only [add_zero, linear_map.zero_apply, smul_zero] }β©
@[simp] lemma coe_zero : β(0 : derivation R A M) = 0 := rfl
@[simp] lemma coe_zero_linear_map : β(0 : derivation R A M) = (0 : A ββ[R] M) := rfl
lemma zero_apply (a : A) : (0 : derivation R A M) a = 0 := rfl
instance : has_add (derivation R A M) :=
β¨Ξ» D1 D2,
{ to_linear_map := D1 + D2,
map_one_eq_zero' := by simp,
leibniz' := Ξ» a b, by simp only [leibniz, linear_map.add_apply,
coe_fn_coe, smul_add, add_add_add_comm] }β©
@[simp] lemma coe_add (D1 D2 : derivation R A M) : β(D1 + D2) = D1 + D2 := rfl
@[simp] lemma coe_add_linear_map (D1 D2 : derivation R A M) : β(D1 + D2) = (D1 + D2 : A ββ[R] M) :=
rfl
lemma add_apply : (D1 + D2) a = D1 a + D2 a := rfl
instance : inhabited (derivation R A M) := β¨0β©
section scalar
variables {S : Type*} [monoid S] [distrib_mul_action S M] [smul_comm_class R S M]
[smul_comm_class S A M]
@[priority 100]
instance : has_scalar S (derivation R A M) :=
β¨Ξ» r D,
{ to_linear_map := r β’ D,
map_one_eq_zero' := by rw [linear_map.smul_apply, coe_fn_coe, D.map_one_eq_zero, smul_zero],
leibniz' := Ξ» a b, by simp only [linear_map.smul_apply, coe_fn_coe, leibniz, smul_add,
smul_comm r] }β©
@[simp] lemma coe_smul (r : S) (D : derivation R A M) : β(r β’ D) = r β’ D := rfl
@[simp] lemma coe_smul_linear_map (r : S) (D : derivation R A M) :
β(r β’ D) = (r β’ D : A ββ[R] M) := rfl
lemma smul_apply (r : S) (D : derivation R A M) : (r β’ D) a = r β’ D a := rfl
instance : add_comm_monoid (derivation R A M) :=
coe_injective.add_comm_monoid _ coe_zero coe_add (Ξ» _ _, rfl)
/-- `coe_fn` as an `add_monoid_hom`. -/
def coe_fn_add_monoid_hom : derivation R A M β+ (A β M) :=
{ to_fun := coe_fn, map_zero' := coe_zero, map_add' := coe_add }
@[priority 100]
instance : distrib_mul_action S (derivation R A M) :=
function.injective.distrib_mul_action coe_fn_add_monoid_hom coe_injective coe_smul
instance [distrib_mul_action Sα΅α΅α΅ M] [is_central_scalar S M] :
is_central_scalar S (derivation R A M) :=
{ op_smul_eq_smul := Ξ» _ _, ext $ Ξ» _, op_smul_eq_smul _ _}
end scalar
@[priority 100]
instance {S : Type*} [semiring S] [module S M] [smul_comm_class R S M] [smul_comm_class S A M] :
module S (derivation R A M) :=
function.injective.module S coe_fn_add_monoid_hom coe_injective coe_smul
instance [is_scalar_tower R A M] : is_scalar_tower R A (derivation R A M) :=
β¨Ξ» x y z, ext (Ξ» a, smul_assoc _ _ _)β©
section push_forward
variables {N : Type*} [add_comm_monoid N] [module A N] [module R N] [is_scalar_tower R A M]
[is_scalar_tower R A N]
variables (f : M ββ[A] N)
/-- We can push forward derivations using linear maps, i.e., the composition of a derivation with a
linear map is a derivation. Furthermore, this operation is linear on the spaces of derivations. -/
def _root_.linear_map.comp_der : derivation R A M ββ[R] derivation R A N :=
{ to_fun := Ξ» D,
{ to_linear_map := (f : M ββ[R] N).comp (D : A ββ[R] M),
map_one_eq_zero' := by simp only [linear_map.comp_apply, coe_fn_coe, map_one_eq_zero, map_zero],
leibniz' := Ξ» a b, by simp only [coe_fn_coe, linear_map.comp_apply, linear_map.map_add,
leibniz, linear_map.coe_coe_is_scalar_tower, linear_map.map_smul] },
map_add' := Ξ» Dβ Dβ, by { ext, exact linear_map.map_add _ _ _, },
map_smul' := Ξ» r D, by { ext, exact linear_map.map_smul _ _ _, }, }
@[simp] lemma coe_to_linear_map_comp :
(f.comp_der D : A ββ[R] N) = (f : M ββ[R] N).comp (D : A ββ[R] M) :=
rfl
@[simp] lemma coe_comp :
(f.comp_der D : A β N) = (f : M ββ[R] N).comp (D : A ββ[R] M) :=
rfl
end push_forward
end
section cancel
variables {R : Type*} [comm_semiring R] {A : Type*} [comm_semiring A] [algebra R A]
{M : Type*} [add_cancel_comm_monoid M] [module R M] [module A M]
/-- Define `derivation R A M` from a linear map when `M` is cancellative by verifying the Leibniz
rule. -/
def mk' (D : A ββ[R] M) (h : β a b, D (a * b) = a β’ D b + b β’ D a) : derivation R A M :=
{ to_linear_map := D,
map_one_eq_zero' := add_right_eq_self.1 $ by simpa only [one_smul, one_mul] using (h 1 1).symm,
leibniz' := h }
@[simp] lemma coe_mk' (D : A ββ[R] M) (h) : β(mk' D h) = D := rfl
@[simp] lemma coe_mk'_linear_map (D : A ββ[R] M) (h) : (mk' D h : A ββ[R] M) = D := rfl
end cancel
section
variables {R : Type*} [comm_ring R]
variables {A : Type*} [comm_ring A] [algebra R A]
section
variables {M : Type*} [add_comm_group M] [module A M] [module R M]
variables (D : derivation R A M) {D1 D2 : derivation R A M} (r : R) (a b : A)
protected lemma map_neg : D (-a) = -D a := map_neg D a
protected lemma map_sub : D (a - b) = D a - D b := map_sub D a b
@[simp] lemma map_coe_int (n : β€) : D (n : A) = 0 :=
by rw [β zsmul_one, D.map_smul_of_tower n, map_one_eq_zero, smul_zero]
lemma leibniz_of_mul_eq_one {a b : A} (h : a * b = 1) : D a = -a^2 β’ D b :=
begin
rw neg_smul,
refine eq_neg_of_add_eq_zero_left _,
calc D a + a ^ 2 β’ D b = a β’ b β’ D a + a β’ a β’ D b : by simp only [smul_smul, h, one_smul, sq]
... = a β’ D (a * b) : by rw [leibniz, smul_add, add_comm]
... = 0 : by rw [h, map_one_eq_zero, smul_zero]
end
lemma leibniz_inv_of [invertible a] : D (β
a) = -β
a^2 β’ D a :=
D.leibniz_of_mul_eq_one $ inv_of_mul_self a
lemma leibniz_inv {K : Type*} [field K] [module K M] [algebra R K] (D : derivation R K M) (a : K) :
D (aβ»ΒΉ) = -aβ»ΒΉ ^ 2 β’ D a :=
begin
rcases eq_or_ne a 0 with (rfl|ha),
{ simp },
{ exact D.leibniz_of_mul_eq_one (inv_mul_cancel ha) }
end
instance : has_neg (derivation R A M) :=
β¨Ξ» D, mk' (-D) $ Ξ» a b,
by simp only [linear_map.neg_apply, smul_neg, neg_add_rev, leibniz, coe_fn_coe, add_comm]β©
@[simp] lemma coe_neg (D : derivation R A M) : β(-D) = -D := rfl
@[simp] lemma coe_neg_linear_map (D : derivation R A M) : β(-D) = (-D : A ββ[R] M) :=
rfl
lemma neg_apply : (-D) a = -D a := rfl
instance : has_sub (derivation R A M) :=
β¨Ξ» D1 D2, mk' (D1 - D2 : A ββ[R] M) $ Ξ» a b,
by simp only [linear_map.sub_apply, leibniz, coe_fn_coe, smul_sub, add_sub_add_comm]β©
@[simp] lemma coe_sub (D1 D2 : derivation R A M) : β(D1 - D2) = D1 - D2 := rfl
@[simp] lemma coe_sub_linear_map (D1 D2 : derivation R A M) : β(D1 - D2) = (D1 - D2 : A ββ[R] M) :=
rfl
lemma sub_apply : (D1 - D2) a = D1 a - D2 a := rfl
instance : add_comm_group (derivation R A M) :=
coe_injective.add_comm_group _ coe_zero coe_add coe_neg coe_sub (Ξ» _ _, rfl) (Ξ» _ _, rfl)
end
section lie_structures
/-! # Lie structures -/
variables (D : derivation R A A) {D1 D2 : derivation R A A} (r : R) (a b : A)
/-- The commutator of derivations is again a derivation. -/
instance : has_bracket (derivation R A A) (derivation R A A) :=
β¨Ξ» D1 D2, mk' (β
(D1 : module.End R A), (D2 : module.End R A)β) $ Ξ» a b,
by { simp only [ring.lie_def, map_add, id.smul_eq_mul, linear_map.mul_apply, leibniz, coe_fn_coe,
linear_map.sub_apply], ring, }β©
@[simp] lemma commutator_coe_linear_map :
ββ
D1, D2β = β
(D1 : module.End R A), (D2 : module.End R A)β := rfl
lemma commutator_apply : β
D1, D2β a = D1 (D2 a) - D2 (D1 a) := rfl
instance : lie_ring (derivation R A A) :=
{ add_lie := Ξ» d e f, by { ext a, simp only [commutator_apply, add_apply, map_add], ring, },
lie_add := Ξ» d e f, by { ext a, simp only [commutator_apply, add_apply, map_add], ring, },
lie_self := Ξ» d, by { ext a, simp only [commutator_apply, add_apply, map_add], ring_nf, },
leibniz_lie := Ξ» d e f,
by { ext a, simp only [commutator_apply, add_apply, sub_apply, map_sub], ring, } }
instance : lie_algebra R (derivation R A A) :=
{ lie_smul := Ξ» r d e, by { ext a, simp only [commutator_apply, map_smul, smul_sub, smul_apply]},
..derivation.module }
end lie_structures
end
end derivation
|
f91cd800a5cab7167054024ef853d4164370c99f | 5a6ff5f8d173cbfe51967eb4c96837e3a791fe3d | /mm0-lean/x86/assembly.lean | da7b6da9dbc855623c8b610d25171a0be8d189e3 | [
"CC0-1.0"
] | permissive | digama0/mm0 | 491ac09146708aa1bb775007bf3dbe339ffc0096 | 98496badaf6464e56ed7b4204e7d54b85667cb01 | refs/heads/master | 1,692,321,030,902 | 1,686,254,458,000 | 1,686,254,458,000 | 172,456,790 | 273 | 38 | CC0-1.0 | 1,689,939,563,000 | 1,551,080,059,000 | Rust | UTF-8 | Lean | false | false | 5,077 | lean | import x86.lemmas
namespace x86
inductive arg : Type
| imm : qword β arg
| reg : regnum β arg
| mem : option scale_index β base β β€ β arg
| label : β β arg
| loc : β β β€ β arg
inductive directive
| label : β β directive
| loc : β β arg β directive
inductive asm1
| unop : unop β wsize β arg β asm1
| binop : binop β wsize β arg β arg β asm1
| mul : wsize β arg β asm1
| div : wsize β arg β asm1
| lea : wsize β arg β arg β asm1
| movsx : wsize β arg β arg β wsize β asm1
| movzx : wsize β arg β arg β wsize β asm1
| xchg : wsize β arg β regnum β asm1
| cmpxchg : wsize β arg β regnum β asm1
| xadd : wsize β arg β regnum β asm1
| cmov : cond_code β wsize β arg β arg β asm1
| setcc : cond_code β bool β arg β asm1
| jump : arg β asm1
| jcc : cond_code β β β asm1
| call : arg β asm1
| ret : qword β asm1
| push : arg β asm1
| pop : arg β asm1
| leave : asm1
| cmc
| clc
| stc
| syscall
| exact : ast β asm1
inductive asm
| nil : asm
| cons : asm1 β asm β asm
| dir : directive β asm
| seq : asm β asm β asm
| block : asm β asm
def arg.offset : arg β β€ β option arg
| (arg.mem si b v) w := some $ arg.mem si b (v + w)
| (arg.loc i v) w := some $ arg.loc i (v + w)
| _ _ := none
inductive assemble_imm_rm (locs : list arg) : arg β imm_rm β Prop
| imm (q) : assemble_imm_rm (arg.imm q) (imm_rm.imm q)
| reg (r) : assemble_imm_rm (arg.reg r) (imm_rm.rm (RM.reg r))
| mem (si b q) : assemble_imm_rm
(arg.mem si b (bitvec.to_int q)) (imm_rm.rm (RM.mem si b q))
| loc (i off a rm) :
(locs.nth i).bind (Ξ» a, a.offset off) = some a β
assemble_imm_rm a rm β assemble_imm_rm (arg.loc i off) rm
def assemble_imm (locs : list arg) (a : arg) (q : qword) : Prop :=
assemble_imm_rm locs a (imm_rm.imm q)
def assemble_RM (locs : list arg) (a : arg) (rm : RM) : Prop :=
assemble_imm_rm locs a (imm_rm.rm rm)
def assemble_ds (locs : list arg) (d s : arg) : dest_src β Prop
| (dest_src.Rm_i rm q) := assemble_RM locs d rm β§ assemble_imm locs s q
| (dest_src.Rm_r rm r) := assemble_RM locs d rm β§ assemble_RM locs s (RM.reg r)
| (dest_src.R_rm r rm) := assemble_RM locs d (RM.reg r) β§ assemble_RM locs s rm
inductive assemble1 (locs : list arg) (labs : list qword)
(rip : qword) : asm1 β ast β Prop
| unop (op sz a rm) :
assemble_RM locs a rm β
assemble1 (asm1.unop op sz a) (ast.unop op sz rm)
| binop (op sz d s ds) :
assemble_ds locs d s ds β
assemble1 (asm1.binop op sz d s) (ast.binop op sz ds)
| mul (sz a rm) :
assemble_RM locs a rm β
assemble1 (asm1.mul sz a) (ast.mul sz rm)
| div (sz a rm) :
assemble_RM locs a rm β
assemble1 (asm1.div sz a) (ast.div sz rm)
| lea (sz d s ds) :
assemble_ds locs d s ds β
assemble1 (asm1.lea sz d s) (ast.lea sz ds)
| movsx (sz d s sz2 ds) :
assemble_ds locs d s ds β
assemble1 (asm1.movsx sz d s sz2) (ast.movsx sz ds sz2)
| xchg (sz a rm r) :
assemble_RM locs a rm β
assemble1 (asm1.xchg sz a r) (ast.xchg sz rm r)
| cmpxchg (sz a rm r) :
assemble_RM locs a rm β
assemble1 (asm1.cmpxchg sz a r) (ast.cmpxchg sz rm r)
| xadd (sz a rm r) :
assemble_RM locs a rm β
assemble1 (asm1.xadd sz a r) (ast.xadd sz rm r)
| cmov (c sz d s ds) :
assemble_ds locs d s ds β
assemble1 (asm1.cmov c sz d s) (ast.cmov c sz ds)
| setcc (c b a rm) :
assemble_RM locs a rm β
assemble1 (asm1.setcc c b a) (ast.setcc c b rm)
| jump (a rm) :
assemble_RM locs a rm β
assemble1 (asm1.jump a) (ast.jump rm)
| jcc (c i q) :
labs.nth i = some q β
assemble1 (asm1.jcc c i) (ast.jcc c (rip - q))
| call (a rm) :
assemble_imm_rm locs a rm β
assemble1 (asm1.call a) (ast.call rm)
| ret (q) : assemble1 (asm1.ret q) (ast.ret q)
| push (a rm) :
assemble_imm_rm locs a rm β
assemble1 (asm1.push a) (ast.push rm)
| pop (a rm) :
assemble_RM locs a rm β
assemble1 (asm1.pop a) (ast.pop rm)
| leave : assemble1 asm1.leave ast.leave
| cmc : assemble1 asm1.cmc ast.cmc
| clc : assemble1 asm1.clc ast.clc
| stc : assemble1 asm1.stc ast.stc
| syscall : assemble1 asm1.syscall ast.syscall
| exact (a) : assemble1 (asm1.exact a) a
inductive assemble (locs : list arg) :
list qword β qword β asm β list byte β qword β Prop
| nil (labs rip) : assemble labs rip asm.nil [] rip
| asm1 (labs rip a ast as l lβ rip') :
assemble1 locs labs rip a ast β
decode ast l β
assemble labs (rip + βl.length) as lβ rip' β
assemble labs rip (asm.cons a as) (l ++ lβ) rip'
| label (labs rip i) :
list.nth labs i = some rip β
assemble labs rip (asm.dir (directive.label i)) [] rip
| loc (labs i arg rip) :
locs.nth i = some arg β
assemble labs rip (asm.dir (directive.loc i arg)) [] rip
| seq (labs rip as1 as2 l1 l2 rip1 rip2) :
assemble labs rip as1 l1 rip1 β
assemble labs rip1 as2 l2 rip2 β
assemble labs rip (asm.seq as1 as2) (l1 ++ l2) rip2
| block (labs rip rip1 as l rip') :
assemble (rip1 :: labs) rip as l rip' β
assemble labs rip (asm.block as) l rip'
end x86 |
f64c06db179fafd6533356603e339371b509f301 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/number_theory/ramification_inertia.lean | 056498830a63f564cc53bc4ce15a1ba2a03136c4 | [
"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 | 39,064 | lean | /-
Copyright (c) 2022 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import linear_algebra.free_module.finite.rank
import ring_theory.dedekind_domain.ideal
/-!
# Ramification index and inertia degree
Given `P : ideal S` lying over `p : ideal R` for the ring extension `f : R β+* S`
(assuming `P` and `p` are prime or maximal where needed),
the **ramification index** `ideal.ramification_idx f p P` is the multiplicity of `P` in `map f p`,
and the **inertia degree** `ideal.inertia_deg f p P` is the degree of the field extension
`(S / P) : (R / p)`.
## Main results
The main theorem `ideal.sum_ramification_inertia` states that for all coprime `P` lying over `p`,
`Ξ£ P, ramification_idx f p P * inertia_deg f p P` equals the degree of the field extension
`Frac(S) : Frac(R)`.
## Implementation notes
Often the above theory is set up in the case where:
* `R` is the ring of integers of a number field `K`,
* `L` is a finite separable extension of `K`,
* `S` is the integral closure of `R` in `L`,
* `p` and `P` are maximal ideals,
* `P` is an ideal lying over `p`
We will try to relax the above hypotheses as much as possible.
## Notation
In this file, `e` stands for the ramification index and `f` for the inertia degree of `P` over `p`,
leaving `p` and `P` implicit.
-/
namespace ideal
universes u v
variables {R : Type u} [comm_ring R]
variables {S : Type v} [comm_ring S] (f : R β+* S)
variables (p : ideal R) (P : ideal S)
open finite_dimensional
open unique_factorization_monoid
section dec_eq
open_locale classical
/-- The ramification index of `P` over `p` is the largest exponent `n` such that
`p` is contained in `P^n`.
In particular, if `p` is not contained in `P^n`, then the ramification index is 0.
If there is no largest such `n` (e.g. because `p = β₯`), then `ramification_idx` is
defined to be 0.
-/
noncomputable def ramification_idx : β :=
Sup {n | map f p β€ P ^ n}
variables {f p P}
lemma ramification_idx_eq_find (h : β n, β k, map f p β€ P ^ k β k β€ n) :
ramification_idx f p P = nat.find h :=
nat.Sup_def h
lemma ramification_idx_eq_zero (h : β n : β, β k, map f p β€ P ^ k β§ n < k) :
ramification_idx f p P = 0 :=
dif_neg (by push_neg; exact h)
lemma ramification_idx_spec {n : β} (hle : map f p β€ P ^ n) (hgt : Β¬ map f p β€ P ^ (n + 1)) :
ramification_idx f p P = n :=
begin
have : β (k : β), map f p β€ P ^ k β k β€ n,
{ intros k hk,
refine le_of_not_lt (Ξ» hnk, _),
exact hgt (hk.trans (ideal.pow_le_pow hnk)) },
rw ramification_idx_eq_find β¨n, thisβ©,
{ refine le_antisymm (nat.find_min' _ this) (le_of_not_gt (Ξ» (h : nat.find _ < n), _)),
obtain this' := nat.find_spec β¨n, thisβ©,
exact h.not_le (this' _ hle) },
end
lemma ramification_idx_lt {n : β} (hgt : Β¬ (map f p β€ P ^ n)) :
ramification_idx f p P < n :=
begin
cases n,
{ simpa using hgt },
rw nat.lt_succ_iff,
have : β k, map f p β€ P ^ k β k β€ n,
{ refine Ξ» k hk, le_of_not_lt (Ξ» hnk, _),
exact hgt (hk.trans (ideal.pow_le_pow hnk)) },
rw ramification_idx_eq_find β¨n, thisβ©,
exact nat.find_min' β¨n, thisβ© this
end
@[simp] lemma ramification_idx_bot : ramification_idx f β₯ P = 0 :=
dif_neg $ not_exists.mpr $ Ξ» n hn, n.lt_succ_self.not_le (hn _ (by simp))
@[simp] lemma ramification_idx_of_not_le (h : Β¬ map f p β€ P) : ramification_idx f p P = 0 :=
ramification_idx_spec (by simp) (by simpa using h)
lemma ramification_idx_ne_zero {e : β} (he : e β 0)
(hle : map f p β€ P ^ e) (hnle : Β¬ map f p β€ P ^ (e + 1)):
ramification_idx f p P β 0 :=
by rwa ramification_idx_spec hle hnle
lemma le_pow_of_le_ramification_idx {n : β} (hn : n β€ ramification_idx f p P) :
map f p β€ P ^ n :=
begin
contrapose! hn,
exact ramification_idx_lt hn
end
lemma le_pow_ramification_idx :
map f p β€ P ^ ramification_idx f p P :=
le_pow_of_le_ramification_idx (le_refl _)
lemma le_comap_pow_ramification_idx :
p β€ comap f (P ^ ramification_idx f p P) :=
map_le_iff_le_comap.mp le_pow_ramification_idx
lemma le_comap_of_ramification_idx_ne_zero (h : ramification_idx f p P β 0) : p β€ comap f P :=
ideal.map_le_iff_le_comap.mp $ le_pow_ramification_idx.trans $ ideal.pow_le_self $ h
namespace is_dedekind_domain
variables [is_domain S] [is_dedekind_domain S]
lemma ramification_idx_eq_normalized_factors_count
(hp0 : map f p β β₯) (hP : P.is_prime) (hP0 : P β β₯) :
ramification_idx f p P = (normalized_factors (map f p)).count P :=
begin
have hPirr := (ideal.prime_of_is_prime hP0 hP).irreducible,
refine ramification_idx_spec (ideal.le_of_dvd _) (mt ideal.dvd_iff_le.mpr _);
rw [dvd_iff_normalized_factors_le_normalized_factors (pow_ne_zero _ hP0) hp0,
normalized_factors_pow, normalized_factors_irreducible hPirr, normalize_eq,
multiset.nsmul_singleton, β multiset.le_count_iff_repeat_le],
{ exact (nat.lt_succ_self _).not_le },
end
lemma ramification_idx_eq_factors_count (hp0 : map f p β β₯) (hP : P.is_prime) (hP0 : P β β₯) :
ramification_idx f p P = (factors (map f p)).count P :=
by rw [is_dedekind_domain.ramification_idx_eq_normalized_factors_count hp0 hP hP0,
factors_eq_normalized_factors]
lemma ramification_idx_ne_zero (hp0 : map f p β β₯) (hP : P.is_prime) (le : map f p β€ P) :
ramification_idx f p P β 0 :=
begin
have hP0 : P β β₯,
{ unfreezingI { rintro rfl },
have := le_bot_iff.mp le,
contradiction },
have hPirr := (ideal.prime_of_is_prime hP0 hP).irreducible,
rw is_dedekind_domain.ramification_idx_eq_normalized_factors_count hp0 hP hP0,
obtain β¨P', hP', P'_eqβ© :=
exists_mem_normalized_factors_of_dvd hp0 hPirr (ideal.dvd_iff_le.mpr le),
rwa [multiset.count_ne_zero, associated_iff_eq.mp P'_eq],
end
end is_dedekind_domain
variables (f p P)
local attribute [instance] ideal.quotient.field
/-- The inertia degree of `P : ideal S` lying over `p : ideal R` is the degree of the
extension `(S / P) : (R / p)`.
We do not assume `P` lies over `p` in the definition; we return `0` instead.
See `inertia_deg_algebra_map` for the common case where `f = algebra_map R S`
and there is an algebra structure `R / p β S / P`.
-/
noncomputable def inertia_deg [hp : p.is_maximal] : β :=
if hPp : comap f P = p
then @finrank (R β§Έ p) (S β§Έ P) _ _ $ @algebra.to_module _ _ _ _ $ ring_hom.to_algebra $
ideal.quotient.lift p (P^.quotient.mk^.comp f) $
Ξ» a ha, quotient.eq_zero_iff_mem.mpr $ mem_comap.mp $ hPp.symm βΈ ha
else 0
-- Useful for the `nontriviality` tactic using `comap_eq_of_scalar_tower_quotient`.
@[simp] lemma inertia_deg_of_subsingleton [hp : p.is_maximal] [hQ : subsingleton (S β§Έ P)] :
inertia_deg f p P = 0 :=
begin
have := ideal.quotient.subsingleton_iff.mp hQ,
unfreezingI { subst this },
exact dif_neg (Ξ» h, hp.ne_top $ h.symm.trans comap_top)
end
@[simp] lemma inertia_deg_algebra_map [algebra R S] [algebra (R β§Έ p) (S β§Έ P)]
[is_scalar_tower R (R β§Έ p) (S β§Έ P)]
[hp : p.is_maximal] :
inertia_deg (algebra_map R S) p P = finrank (R β§Έ p) (S β§Έ P) :=
begin
nontriviality (S β§Έ P) using [inertia_deg_of_subsingleton, finrank_zero_of_subsingleton],
have := comap_eq_of_scalar_tower_quotient (algebra_map (R β§Έ p) (S β§Έ P)).injective,
rw [inertia_deg, dif_pos this],
congr,
refine algebra.algebra_ext _ _ (Ξ» x', quotient.induction_on' x' $ Ξ» x, _),
change ideal.quotient.lift p _ _ (ideal.quotient.mk p x) =
algebra_map _ _ (ideal.quotient.mk p x),
rw [ideal.quotient.lift_mk, β ideal.quotient.algebra_map_eq, β is_scalar_tower.algebra_map_eq,
β ideal.quotient.algebra_map_eq, β is_scalar_tower.algebra_map_apply]
end
end dec_eq
section finrank_quotient_map
open_locale big_operators
open_locale non_zero_divisors
variables [algebra R S]
variables {K : Type*} [field K] [algebra R K] [hRK : is_fraction_ring R K]
variables {L : Type*} [field L] [algebra S L] [is_fraction_ring S L]
variables {V V' V'' : Type*}
variables [add_comm_group V] [module R V] [module K V] [is_scalar_tower R K V]
variables [add_comm_group V'] [module R V'] [module S V'] [is_scalar_tower R S V']
variables [add_comm_group V''] [module R V'']
variables (K)
include hRK
/-- Let `V` be a vector space over `K = Frac(R)`, `S / R` a ring extension
and `V'` a module over `S`. If `b`, in the intersection `V''` of `V` and `V'`,
is linear independent over `S` in `V'`, then it is linear independent over `R` in `V`.
The statement we prove is actually slightly more general:
* it suffices that the inclusion `algebra_map R S : R β S` is nontrivial
* the function `f' : V'' β V'` doesn't need to be injective
-/
lemma finrank_quotient_map.linear_independent_of_nontrivial
[is_domain R] [is_dedekind_domain R] (hRS : (algebra_map R S).ker β β€)
(f : V'' ββ[R] V) (hf : function.injective f) (f' : V'' ββ[R] V')
{ΞΉ : Type*} {b : ΞΉ β V''} (hb' : linear_independent S (f' β b)) :
linear_independent K (f β b) :=
begin
contrapose! hb' with hb,
-- Informally, if we have a nontrivial linear dependence with coefficients `g` in `K`,
-- then we can find a linear dependence with coefficients `I.quotient.mk g'` in `R/I`,
-- where `I = ker (algebra_map R S)`.
-- We make use of the same principle but stay in `R` everywhere.
simp only [linear_independent_iff', not_forall] at hb β’,
obtain β¨s, g, eq, j', hj's, hj'gβ© := hb,
use s,
obtain β¨a, hag, j, hjs, hgIβ© :=
ideal.exist_integer_multiples_not_mem hRS s g hj's hj'g,
choose g'' hg'' using hag,
letI := classical.prop_decidable,
let g' := Ξ» i, if h : i β s then g'' i h else 0,
have hg' : β i β s, algebra_map _ _ (g' i) = a * g i,
{ intros i hi, exact (congr_arg _ (dif_pos hi)).trans (hg'' i hi) },
-- Because `R/I` is nontrivial, we can lift `g` to a nontrivial linear dependence in `S`.
have hgI : algebra_map R S (g' j) β 0,
{ simp only [fractional_ideal.mem_coe_ideal, not_exists, not_and'] at hgI,
exact hgI _ (hg' j hjs) },
refine β¨Ξ» i, algebra_map R S (g' i), _, j, hjs, hgIβ©,
have eq : f (β i in s, g' i β’ (b i)) = 0,
{ rw [linear_map.map_sum, β smul_zero a, β eq, finset.smul_sum, finset.sum_congr rfl],
intros i hi,
rw [linear_map.map_smul, β is_scalar_tower.algebra_map_smul K, hg' i hi, β smul_assoc,
smul_eq_mul],
apply_instance },
simp only [is_scalar_tower.algebra_map_smul, β linear_map.map_smul, β linear_map.map_sum,
(f.map_eq_zero_iff hf).mp eq, linear_map.map_zero],
end
open_locale matrix
variables {K}
omit hRK
/-- If `b` mod `p` spans `S/p` as `R/p`-space, then `b` itself spans `Frac(S)` as `K`-space.
Here,
* `p` is an ideal of `R` such that `R / p` is nontrivial
* `K` is a field that has an embedding of `R` (in particular we can take `K = Frac(R)`)
* `L` is a field extension of `K`
* `S` is the integral closure of `R` in `L`
More precisely, we avoid quotients in this statement and instead require that `b βͺ pS` spans `S`.
-/
lemma finrank_quotient_map.span_eq_top [is_domain R] [is_domain S] [algebra K L] [is_noetherian R S]
[algebra R L] [is_scalar_tower R S L] [is_scalar_tower R K L] [is_integral_closure S R L]
[no_zero_smul_divisors R K]
(hp : p β β€)
(b : set S) (hb' : submodule.span R b β (p.map (algebra_map R S)).restrict_scalars R = β€) :
submodule.span K (algebra_map S L '' b) = β€ :=
begin
have hRL : function.injective (algebra_map R L),
{ rw is_scalar_tower.algebra_map_eq R K L,
exact (algebra_map K L).injective.comp (no_zero_smul_divisors.algebra_map_injective R K) },
-- Let `M` be the `R`-module spanned by the proposed basis elements.
set M : submodule R S := submodule.span R b with hM,
-- Then `S / M` is generated by some finite set of `n` vectors `a`.
letI h : module.finite R (S β§Έ M) :=
module.finite.of_surjective (submodule.mkq _) (submodule.quotient.mk_surjective _),
obtain β¨n, a, haβ© := @@module.finite.exists_fin _ _ _ h,
-- Because the image of `p` in `S / M` is `β€`,
have smul_top_eq : p β’ (β€ : submodule R (S β§Έ M)) = β€,
{ calc p β’ β€ = submodule.map M.mkq (p β’ β€) :
by rw [submodule.map_smul'', submodule.map_top, M.range_mkq]
... = β€ : by rw [ideal.smul_top_eq_map, (submodule.map_mkq_eq_top M _).mpr hb'] },
-- we can write the elements of `a` as `p`-linear combinations of other elements of `a`.
have exists_sum : β x : (S β§Έ M), β a' : fin n β R, (β i, a' i β p) β§ β i, a' i β’ a i = x,
{ intro x,
obtain β¨a'', ha'', hxβ© := (submodule.mem_ideal_smul_span_iff_exists_sum p a x).1 _,
{ refine β¨Ξ» i, a'' i, Ξ» i, ha'' _, _β©,
rw [β hx, finsupp.sum_fintype],
exact Ξ» _, zero_smul _ _ },
{ rw [ha, smul_top_eq],
exact submodule.mem_top } },
choose A' hA'p hA' using Ξ» i, exists_sum (a i),
-- This gives us a(n invertible) matrix `A` such that `det A β (M = span R b)`,
let A : matrix (fin n) (fin n) R := A' - 1,
let B := A.adjugate,
have A_smul : β i, β j, A i j β’ a j = 0,
{ intros,
simp only [A, pi.sub_apply, sub_smul, finset.sum_sub_distrib, hA', matrix.one_apply, ite_smul,
one_smul, zero_smul, finset.sum_ite_eq, finset.mem_univ, if_true, sub_self] },
-- since `span S {det A} / M = 0`.
have d_smul : β i, A.det β’ a i = 0,
{ intro i,
calc A.det β’ a i = β j, (B β¬ A) i j β’ a j : _
... = β k, B i k β’ β j, (A k j β’ a j) : _
... = 0 : finset.sum_eq_zero (Ξ» k _, _),
{ simp only [matrix.adjugate_mul, pi.smul_apply, matrix.one_apply, mul_ite, ite_smul,
smul_eq_mul, mul_one, mul_zero, one_smul, zero_smul, finset.sum_ite_eq, finset.mem_univ,
if_true] },
{ simp only [matrix.mul_apply, finset.smul_sum, finset.sum_smul, smul_smul],
rw finset.sum_comm },
{ rw [A_smul, smul_zero] } },
-- In the rings of integers we have the desired inclusion.
have span_d : (submodule.span S ({algebra_map R S A.det} : set S)).restrict_scalars R β€ M,
{ intros x hx,
rw submodule.restrict_scalars_mem at hx,
obtain β¨x', rflβ© := submodule.mem_span_singleton.mp hx,
rw [smul_eq_mul, mul_comm, β algebra.smul_def] at β’ hx,
rw [β submodule.quotient.mk_eq_zero, submodule.quotient.mk_smul],
obtain β¨a', _, quot_x_eqβ© := exists_sum (submodule.quotient.mk x'),
simp_rw [β quot_x_eq, finset.smul_sum, smul_comm A.det, d_smul, smul_zero,
finset.sum_const_zero] },
-- So now we lift everything to the fraction field.
refine top_le_iff.mp (calc β€ = (ideal.span {algebra_map R L A.det}).restrict_scalars K : _
... β€ submodule.span K (algebra_map S L '' b) : _),
-- Because `det A β 0`, we have `span L {det A} = β€`.
{ rw [eq_comm, submodule.restrict_scalars_eq_top_iff, ideal.span_singleton_eq_top],
refine is_unit.mk0 _ ((map_ne_zero_iff ((algebra_map R L)) hRL).mpr (
@ne_zero_of_map _ _ _ _ _ _ (ideal.quotient.mk p) _ _)),
haveI := ideal.quotient.nontrivial hp,
calc ideal.quotient.mk p (A.det)
= matrix.det ((ideal.quotient.mk p).map_matrix A) :
by rw [ring_hom.map_det, ring_hom.map_matrix_apply]
... = matrix.det ((ideal.quotient.mk p).map_matrix (A' - 1)) : rfl
... = matrix.det (Ξ» i j, (ideal.quotient.mk p) (A' i j) -
(1 : matrix (fin n) (fin n) (R β§Έ p)) i j) : _
... = matrix.det (-1 : matrix (fin n) (fin n) (R β§Έ p)) : _
... = (-1 : R β§Έ p) ^ n : by rw [matrix.det_neg, fintype.card_fin, matrix.det_one, mul_one]
... β 0 : is_unit.ne_zero (is_unit_one.neg.pow _),
{ refine congr_arg matrix.det (matrix.ext (Ξ» i j, _)),
rw [map_sub, ring_hom.map_matrix_apply, map_one],
refl },
{ refine congr_arg matrix.det (matrix.ext (Ξ» i j, _)),
rw [ideal.quotient.eq_zero_iff_mem.mpr (hA'p i j), zero_sub],
refl } },
-- And we conclude `L = span L {det A} β€ span K b`, so `span K b` spans everything.
{ intros x hx,
rw [submodule.restrict_scalars_mem, is_scalar_tower.algebra_map_apply R S L] at hx,
refine is_fraction_ring.ideal_span_singleton_map_subset R _ hRL span_d hx,
haveI : no_zero_smul_divisors R L := no_zero_smul_divisors.of_algebra_map_injective hRL,
rw β is_fraction_ring.is_algebraic_iff' R S,
intros x,
exact is_integral.is_algebraic _ (is_integral_of_noetherian infer_instance _) },
end
include hRK
variables (K L)
/-- If `p` is a maximal ideal of `R`, and `S` is the integral closure of `R` in `L`,
then the dimension `[S/pS : R/p]` is equal to `[Frac(S) : Frac(R)]`. -/
lemma finrank_quotient_map [is_domain R] [is_domain S] [is_dedekind_domain R]
[algebra K L] [algebra R L] [is_scalar_tower R K L] [is_scalar_tower R S L]
[is_integral_closure S R L]
[hp : p.is_maximal] [is_noetherian R S] :
finrank (R β§Έ p) (S β§Έ map (algebra_map R S) p) = finrank K L :=
begin
-- Choose an arbitrary basis `b` for `[S/pS : R/p]`.
-- We'll use the previous results to turn it into a basis on `[Frac(S) : Frac(R)]`.
letI : field (R β§Έ p) := ideal.quotient.field _,
let ΞΉ := module.free.choose_basis_index (R β§Έ p) (S β§Έ map (algebra_map R S) p),
let b : basis ΞΉ (R β§Έ p) (S β§Έ map (algebra_map R S) p) := module.free.choose_basis _ _,
-- Namely, choose a representative `b' i : S` for each `b i : S / pS`.
let b' : ΞΉ β S := Ξ» i, (ideal.quotient.mk_surjective (b i)).some,
have b_eq_b' : β b = (submodule.mkq _).restrict_scalars R β b' :=
funext (Ξ» i, (ideal.quotient.mk_surjective (b i)).some_spec.symm),
-- We claim `b'` is a basis for `Frac(S)` over `Frac(R)` because it is linear independent
-- and spans the whole of `Frac(S)`.
let b'' : ΞΉ β L := algebra_map S L β b',
have b''_li : linear_independent _ b'' := _,
have b''_sp : submodule.span _ (set.range b'') = β€ := _,
-- Since the two bases have the same index set, the spaces have the same dimension.
let c : basis ΞΉ K L := basis.mk b''_li b''_sp.ge,
rw [finrank_eq_card_basis b, finrank_eq_card_basis c],
-- It remains to show that the basis is indeed linear independent and spans the whole space.
{ rw set.range_comp,
refine finrank_quotient_map.span_eq_top p hp.ne_top _ (top_le_iff.mp _),
-- The nicest way to show `S β€ span b' β pS` is by reducing both sides modulo pS.
-- However, this would imply distinguishing between `pS` as `S`-ideal,
-- and `pS` as `R`-submodule, since they have different (non-defeq) quotients.
-- Instead we'll lift `x mod pS β span b` to `y β span b'` for some `y - x β pS`.
intros x hx,
have mem_span_b :
((submodule.mkq (map (algebra_map R S) p)) x :
S β§Έ map (algebra_map R S) p) β submodule.span (R β§Έ p) (set.range b) := b.mem_span _,
rw [β @submodule.restrict_scalars_mem R, algebra.span_restrict_scalars_eq_span_of_surjective
(show function.surjective (algebra_map R (R β§Έ p)), from ideal.quotient.mk_surjective) _,
b_eq_b', set.range_comp, β submodule.map_span]
at mem_span_b,
obtain β¨y, y_mem, y_eqβ© := submodule.mem_map.mp mem_span_b,
suffices : y + -(y - x) β _, { simpa },
rw [linear_map.restrict_scalars_apply, submodule.mkq_apply, submodule.mkq_apply,
submodule.quotient.eq] at y_eq,
exact add_mem (submodule.mem_sup_left y_mem) (neg_mem $ submodule.mem_sup_right y_eq) },
{ have := b.linear_independent, rw b_eq_b' at this,
convert finrank_quotient_map.linear_independent_of_nontrivial K _
((algebra.linear_map S L).restrict_scalars R) _
((submodule.mkq _).restrict_scalars R)
this,
{ rw [quotient.algebra_map_eq, ideal.mk_ker],
exact hp.ne_top },
{ exact is_fraction_ring.injective S L } },
end
end finrank_quotient_map
section fact_le_comap
local notation `e` := ramification_idx f p P
/-- `R / p` has a canonical map to `S / (P ^ e)`, where `e` is the ramification index
of `P` over `p`. -/
noncomputable instance quotient.algebra_quotient_pow_ramification_idx :
algebra (R β§Έ p) (S β§Έ (P ^ e)) :=
quotient.algebra_quotient_of_le_comap (ideal.map_le_iff_le_comap.mp le_pow_ramification_idx)
@[simp] lemma quotient.algebra_map_quotient_pow_ramification_idx (x : R) :
algebra_map (R β§Έ p) (S β§Έ P ^ e) (ideal.quotient.mk p x) = ideal.quotient.mk _ (f x) :=
rfl
variables [hfp : ne_zero (ramification_idx f p P)]
include hfp
/-- If `P` lies over `p`, then `R / p` has a canonical map to `S / P`.
This can't be an instance since the map `f : R β S` is generally not inferrable.
-/
def quotient.algebra_quotient_of_ramification_idx_ne_zero :
algebra (R β§Έ p) (S β§Έ P) :=
quotient.algebra_quotient_of_le_comap (le_comap_of_ramification_idx_ne_zero hfp.out)
-- In this file, the value for `f` can be inferred.
local attribute [instance] ideal.quotient.algebra_quotient_of_ramification_idx_ne_zero
@[simp] lemma quotient.algebra_map_quotient_of_ramification_idx_ne_zero (x : R) :
algebra_map (R β§Έ p) (S β§Έ P) (ideal.quotient.mk p x) = ideal.quotient.mk _ (f x) :=
rfl
omit hfp
/-- The inclusion `(P^(i + 1) / P^e) β (P^i / P^e)`. -/
@[simps]
def pow_quot_succ_inclusion (i : β) :
ideal.map (P^e)^.quotient.mk (P ^ (i + 1)) ββ[R β§Έ p] ideal.map (P^e)^.quotient.mk (P ^ i) :=
{ to_fun := Ξ» x, β¨x, ideal.map_mono (ideal.pow_le_pow i.le_succ) x.2β©,
map_add' := Ξ» x y, rfl,
map_smul' := Ξ» c x, rfl }
lemma pow_quot_succ_inclusion_injective (i : β) :
function.injective (pow_quot_succ_inclusion f p P i) :=
begin
rw [β linear_map.ker_eq_bot, linear_map.ker_eq_bot'],
rintro β¨x, hxβ© hx0,
rw subtype.ext_iff at hx0 β’,
rwa pow_quot_succ_inclusion_apply_coe at hx0
end
/-- `S β§Έ P` embeds into the quotient by `P^(i+1) β§Έ P^e` as a subspace of `P^i β§Έ P^e`.
See `quotient_to_quotient_range_pow_quot_succ` for this as a linear map,
and `quotient_range_pow_quot_succ_inclusion_equiv` for this as a linear equivalence.
-/
noncomputable def quotient_to_quotient_range_pow_quot_succ_aux {i : β} {a : S} (a_mem : a β P^i) :
S β§Έ P β ((P ^ i).map (P ^ e)^.quotient.mk β§Έ (pow_quot_succ_inclusion f p P i).range) :=
quotient.map' (Ξ» (x : S), β¨_, ideal.mem_map_of_mem _ (ideal.mul_mem_left _ x a_mem)β©)
(Ξ» x y h, begin
rw submodule.quotient_rel_r_def at β’ h,
simp only [_root_.map_mul, linear_map.mem_range],
refine β¨β¨_, ideal.mem_map_of_mem _ (ideal.mul_mem_mul h a_mem)β©, _β©,
ext,
rw [pow_quot_succ_inclusion_apply_coe, subtype.coe_mk, submodule.coe_sub, subtype.coe_mk,
subtype.coe_mk, _root_.map_mul, map_sub, sub_mul]
end)
lemma quotient_to_quotient_range_pow_quot_succ_aux_mk {i : β} {a : S} (a_mem : a β P^i) (x : S) :
quotient_to_quotient_range_pow_quot_succ_aux f p P a_mem (submodule.quotient.mk x) =
submodule.quotient.mk β¨_, ideal.mem_map_of_mem _ (ideal.mul_mem_left _ x a_mem)β© :=
by apply quotient.map'_mk'
include hfp
/-- `S β§Έ P` embeds into the quotient by `P^(i+1) β§Έ P^e` as a subspace of `P^i β§Έ P^e`. -/
noncomputable def quotient_to_quotient_range_pow_quot_succ {i : β} {a : S} (a_mem : a β P^i) :
S β§Έ P ββ[R β§Έ p] ((P ^ i).map (P ^ e)^.quotient.mk β§Έ (pow_quot_succ_inclusion f p P i).range) :=
{ to_fun := quotient_to_quotient_range_pow_quot_succ_aux f p P a_mem,
map_add' := begin
intros x y, refine quotient.induction_on' x (Ξ» x, quotient.induction_on' y (Ξ» y, _)),
simp only [submodule.quotient.mk'_eq_mk, β submodule.quotient.mk_add,
quotient_to_quotient_range_pow_quot_succ_aux_mk, add_mul],
refine congr_arg submodule.quotient.mk _,
ext,
refl
end,
map_smul' := begin
intros x y, refine quotient.induction_on' x (Ξ» x, quotient.induction_on' y (Ξ» y, _)),
simp only [submodule.quotient.mk'_eq_mk, β submodule.quotient.mk_add,
quotient_to_quotient_range_pow_quot_succ_aux_mk, ring_hom.id_apply],
refine congr_arg submodule.quotient.mk _,
ext,
simp only [subtype.coe_mk, _root_.map_mul, algebra.smul_def, submodule.coe_mk, mul_assoc,
ideal.quotient.mk_eq_mk, submodule.coe_smul_of_tower,
ideal.quotient.algebra_map_quotient_pow_ramification_idx]
end }
lemma quotient_to_quotient_range_pow_quot_succ_mk {i : β} {a : S} (a_mem : a β P^i) (x : S) :
quotient_to_quotient_range_pow_quot_succ f p P a_mem (submodule.quotient.mk x) =
submodule.quotient.mk β¨_, ideal.mem_map_of_mem _ (ideal.mul_mem_left _ x a_mem)β© :=
quotient_to_quotient_range_pow_quot_succ_aux_mk f p P a_mem x
lemma quotient_to_quotient_range_pow_quot_succ_injective [is_domain S] [is_dedekind_domain S]
[P.is_prime] {i : β} (hi : i < e) {a : S} (a_mem : a β P^i) (a_not_mem : a β P^(i + 1)) :
function.injective (quotient_to_quotient_range_pow_quot_succ f p P a_mem) :=
Ξ» x, quotient.induction_on' x $ Ξ» x y, quotient.induction_on' y $ Ξ» y h,
begin
have Pe_le_Pi1 : P^e β€ P^(i + 1) := ideal.pow_le_pow hi,
simp only [submodule.quotient.mk'_eq_mk, quotient_to_quotient_range_pow_quot_succ_mk,
submodule.quotient.eq, linear_map.mem_range, subtype.ext_iff, subtype.coe_mk,
submodule.coe_sub] at β’ h,
rcases h with β¨β¨β¨zβ©, hzβ©, hβ©,
rw [submodule.quotient.quot_mk_eq_mk, ideal.quotient.mk_eq_mk, ideal.mem_quotient_iff_mem_sup,
sup_eq_left.mpr Pe_le_Pi1] at hz,
rw [pow_quot_succ_inclusion_apply_coe, subtype.coe_mk, submodule.quotient.quot_mk_eq_mk,
ideal.quotient.mk_eq_mk, β map_sub, ideal.quotient.eq, β sub_mul] at h,
exact (ideal.is_prime.mul_mem_pow _
((submodule.sub_mem_iff_right _ hz).mp (Pe_le_Pi1 h))).resolve_right a_not_mem,
end
lemma quotient_to_quotient_range_pow_quot_succ_surjective [is_domain S] [is_dedekind_domain S]
(hP0 : P β β₯) [hP : P.is_prime] {i : β} (hi : i < e)
{a : S} (a_mem : a β P^i) (a_not_mem : a β P^(i + 1)) :
function.surjective (quotient_to_quotient_range_pow_quot_succ f p P a_mem) :=
begin
rintro β¨β¨β¨xβ©, hxβ©β©,
have Pe_le_Pi : P^e β€ P^i := ideal.pow_le_pow hi.le,
have Pe_le_Pi1 : P^e β€ P^(i + 1) := ideal.pow_le_pow hi,
rw [submodule.quotient.quot_mk_eq_mk, ideal.quotient.mk_eq_mk, ideal.mem_quotient_iff_mem_sup,
sup_eq_left.mpr Pe_le_Pi] at hx,
suffices hx' : x β ideal.span {a} β P^(i+1),
{ obtain β¨y', hy', z, hz, rflβ© := submodule.mem_sup.mp hx',
obtain β¨y, rflβ© := ideal.mem_span_singleton.mp hy',
refine β¨submodule.quotient.mk y, _β©,
simp only [submodule.quotient.quot_mk_eq_mk, quotient_to_quotient_range_pow_quot_succ_mk,
submodule.quotient.eq, linear_map.mem_range, subtype.ext_iff, subtype.coe_mk,
submodule.coe_sub],
refine β¨β¨_, ideal.mem_map_of_mem _ (submodule.neg_mem _ hz)β©, _β©,
rw [pow_quot_succ_inclusion_apply_coe, subtype.coe_mk, ideal.quotient.mk_eq_mk, map_add,
mul_comm y a, sub_add_cancel', map_neg] },
letI := classical.dec_eq (ideal S),
rw [sup_eq_prod_inf_factors _ (pow_ne_zero _ hP0), normalized_factors_pow,
normalized_factors_irreducible ((ideal.prime_iff_is_prime hP0).mpr hP).irreducible,
normalize_eq, multiset.nsmul_singleton, multiset.inter_repeat, multiset.prod_repeat],
rw [β submodule.span_singleton_le_iff_mem, ideal.submodule_span_eq] at a_mem a_not_mem,
rwa [ideal.count_normalized_factors_eq a_mem a_not_mem, min_eq_left i.le_succ],
{ intro ha,
rw ideal.span_singleton_eq_bot.mp ha at a_not_mem,
have := (P^(i+1)).zero_mem,
contradiction },
end
/-- Quotienting `P^i / P^e` by its subspace `P^(i+1) β§Έ P^e` is
`R β§Έ p`-linearly isomorphic to `S β§Έ P`. -/
noncomputable def quotient_range_pow_quot_succ_inclusion_equiv [is_domain S] [is_dedekind_domain S]
[P.is_prime] (hP : P β β₯) {i : β} (hi : i < e) :
((P ^ i).map (P ^ e)^.quotient.mk β§Έ (pow_quot_succ_inclusion f p P i).range) ββ[R β§Έ p] S β§Έ P :=
begin
choose a a_mem a_not_mem using set_like.exists_of_lt
(ideal.strict_anti_pow P hP (ideal.is_prime.ne_top infer_instance) (le_refl i.succ)),
refine (linear_equiv.of_bijective _ _ _).symm,
{ exact quotient_to_quotient_range_pow_quot_succ f p P a_mem },
{ exact quotient_to_quotient_range_pow_quot_succ_injective f p P hi a_mem a_not_mem },
{ exact quotient_to_quotient_range_pow_quot_succ_surjective f p P hP hi a_mem a_not_mem }
end
/-- Since the inclusion `(P^(i + 1) / P^e) β (P^i / P^e)` has a kernel isomorphic to `P / S`,
`[P^i / P^e : R / p] = [P^(i+1) / P^e : R / p] + [P / S : R / p]` -/
lemma dim_pow_quot_aux [is_domain S] [is_dedekind_domain S] [p.is_maximal] [P.is_prime]
(hP0 : P β β₯) {i : β} (hi : i < e) :
module.rank (R β§Έ p) (ideal.map (P^e)^.quotient.mk (P ^ i)) =
module.rank (R β§Έ p) (S β§Έ P) + module.rank (R β§Έ p) (ideal.map (P^e)^.quotient.mk (P ^ (i + 1))) :=
begin
letI : field (R β§Έ p) := ideal.quotient.field _,
rw [dim_eq_of_injective _ (pow_quot_succ_inclusion_injective f p P i),
(quotient_range_pow_quot_succ_inclusion_equiv f p P hP0 hi).symm.dim_eq],
exact (dim_quotient_add_dim (linear_map.range (pow_quot_succ_inclusion f p P i))).symm,
end
lemma dim_pow_quot [is_domain S] [is_dedekind_domain S] [p.is_maximal] [P.is_prime]
(hP0 : P β β₯) (i : β) (hi : i β€ e) :
module.rank (R β§Έ p) (ideal.map (P^e)^.quotient.mk (P ^ i)) =
(e - i) β’ module.rank (R β§Έ p) (S β§Έ P) :=
begin
refine @nat.decreasing_induction' _ i e (Ξ» j lt_e le_j ih, _) hi _,
{ rw [dim_pow_quot_aux f p P _ lt_e, ih, β succ_nsmul, nat.sub_succ, β nat.succ_eq_add_one,
nat.succ_pred_eq_of_pos (nat.sub_pos_of_lt lt_e)],
assumption },
{ rw [nat.sub_self, zero_nsmul, map_quotient_self],
exact dim_bot (R β§Έ p) (S β§Έ (P^e)) }
end
omit hfp
/-- If `p` is a maximal ideal of `R`, `S` extends `R` and `P^e` lies over `p`,
then the dimension `[S/(P^e) : R/p]` is equal to `e * [S/P : R/p]`. -/
lemma dim_prime_pow_ramification_idx [is_domain S] [is_dedekind_domain S] [p.is_maximal]
[P.is_prime] (hP0 : P β β₯) (he : e β 0) :
module.rank (R β§Έ p) (S β§Έ P^e) =
e β’ @module.rank (R β§Έ p) (S β§Έ P) _ _ (@algebra.to_module _ _ _ _ $
@@quotient.algebra_quotient_of_ramification_idx_ne_zero _ _ _ _ _ β¨heβ©) :=
begin
letI : ne_zero e := β¨heβ©,
have := dim_pow_quot f p P hP0 0 (nat.zero_le e),
rw [pow_zero, nat.sub_zero, ideal.one_eq_top, ideal.map_top] at this,
exact (dim_top (R β§Έ p) _).symm.trans this
end
/-- If `p` is a maximal ideal of `R`, `S` extends `R` and `P^e` lies over `p`,
then the dimension `[S/(P^e) : R/p]`, as a natural number, is equal to `e * [S/P : R/p]`. -/
lemma finrank_prime_pow_ramification_idx [is_domain S] [is_dedekind_domain S]
(hP0 : P β β₯) [p.is_maximal] [P.is_prime] (he : e β 0) :
finrank (R β§Έ p) (S β§Έ P^e) =
e * @finrank (R β§Έ p) (S β§Έ P) _ _ (@algebra.to_module _ _ _ _ $
@@quotient.algebra_quotient_of_ramification_idx_ne_zero _ _ _ _ _ β¨heβ©) :=
begin
letI : ne_zero e := β¨heβ©,
letI : algebra (R β§Έ p) (S β§Έ P) := quotient.algebra_quotient_of_ramification_idx_ne_zero f p P,
letI := ideal.quotient.field p,
have hdim := dim_prime_pow_ramification_idx _ _ _ hP0 he,
by_cases hP : finite_dimensional (R β§Έ p) (S β§Έ P),
{ haveI := hP,
haveI := (finite_dimensional_iff_of_rank_eq_nsmul he hdim).mpr hP,
refine cardinal.nat_cast_injective _,
rw [finrank_eq_dim, nat.cast_mul, finrank_eq_dim, hdim, nsmul_eq_mul] },
have hPe := mt (finite_dimensional_iff_of_rank_eq_nsmul he hdim).mp hP,
simp only [finrank_of_infinite_dimensional hP, finrank_of_infinite_dimensional hPe, mul_zero],
end
end fact_le_comap
section factors_map
open_locale classical
/-! ## Properties of the factors of `p.map (algebra_map R S)` -/
variables [is_domain S] [is_dedekind_domain S] [algebra R S]
lemma factors.ne_bot (P : (factors (map (algebra_map R S) p)).to_finset) :
(P : ideal S) β β₯ :=
(prime_of_factor _ (multiset.mem_to_finset.mp P.2)).ne_zero
instance factors.is_prime (P : (factors (map (algebra_map R S) p)).to_finset) :
is_prime (P : ideal S) :=
ideal.is_prime_of_prime (prime_of_factor _ (multiset.mem_to_finset.mp P.2))
lemma factors.ramification_idx_ne_zero (P : (factors (map (algebra_map R S) p)).to_finset) :
ramification_idx (algebra_map R S) p P β 0 :=
is_dedekind_domain.ramification_idx_ne_zero
(ne_zero_of_mem_factors (multiset.mem_to_finset.mp P.2))
(factors.is_prime p P)
(ideal.le_of_dvd (dvd_of_mem_factors (multiset.mem_to_finset.mp P.2)))
instance factors.fact_ramification_idx_ne_zero (P : (factors (map (algebra_map R S) p)).to_finset) :
ne_zero (ramification_idx (algebra_map R S) p P) :=
β¨factors.ramification_idx_ne_zero p Pβ©
local attribute [instance] quotient.algebra_quotient_of_ramification_idx_ne_zero
instance factors.is_scalar_tower
(P : (factors (map (algebra_map R S) p)).to_finset) :
is_scalar_tower R (R β§Έ p) (S β§Έ (P : ideal S)) :=
is_scalar_tower.of_algebra_map_eq (Ξ» x, by simp)
local attribute [instance] ideal.quotient.field
lemma factors.finrank_pow_ramification_idx [p.is_maximal]
(P : (factors (map (algebra_map R S) p)).to_finset) :
finrank (R β§Έ p) (S β§Έ (P : ideal S) ^ ramification_idx (algebra_map R S) p P) =
ramification_idx (algebra_map R S) p P * inertia_deg (algebra_map R S) p P :=
begin
rw [finrank_prime_pow_ramification_idx, inertia_deg_algebra_map],
exact factors.ne_bot p P,
end
instance factors.finite_dimensional_quotient [is_noetherian R S] [p.is_maximal]
(P : (factors (map (algebra_map R S) p)).to_finset) :
finite_dimensional (R β§Έ p) (S β§Έ (P : ideal S)) :=
is_noetherian.iff_fg.mp $
is_noetherian_of_tower R $
is_noetherian_of_surjective S (ideal.quotient.mkβ _ _).to_linear_map $
linear_map.range_eq_top.mpr ideal.quotient.mk_surjective
lemma factors.inertia_deg_ne_zero [is_noetherian R S] [p.is_maximal]
(P : (factors (map (algebra_map R S) p)).to_finset) :
inertia_deg (algebra_map R S) p P β 0 :=
by { rw inertia_deg_algebra_map, exact (finite_dimensional.finrank_pos_iff.mpr infer_instance).ne' }
instance factors.finite_dimensional_quotient_pow [is_noetherian R S] [p.is_maximal]
(P : (factors (map (algebra_map R S) p)).to_finset) :
finite_dimensional (R β§Έ p) (S β§Έ (P : ideal S) ^ ramification_idx (algebra_map R S) p P) :=
begin
refine finite_dimensional.finite_dimensional_of_finrank _,
rw [pos_iff_ne_zero, factors.finrank_pow_ramification_idx],
exact mul_ne_zero (factors.ramification_idx_ne_zero p P) (factors.inertia_deg_ne_zero p P)
end
universes w
/-- **Chinese remainder theorem** for a ring of integers: if the prime ideal `p : ideal R`
factors in `S` as `β i, P i ^ e i`, then `S β§Έ I` factors as `Ξ i, R β§Έ (P i ^ e i)`. -/
noncomputable def factors.pi_quotient_equiv
(p : ideal R) (hp : map (algebra_map R S) p β β₯) :
(S β§Έ map (algebra_map R S) p) β+* Ξ (P : (factors (map (algebra_map R S) p)).to_finset),
S β§Έ ((P : ideal S) ^ ramification_idx (algebra_map R S) p P) :=
(is_dedekind_domain.quotient_equiv_pi_factors hp).trans $
(@ring_equiv.Pi_congr_right (factors (map (algebra_map R S) p)).to_finset
(Ξ» P, S β§Έ (P : ideal S) ^ (factors (map (algebra_map R S) p)).count P)
(Ξ» P, S β§Έ (P : ideal S) ^ ramification_idx (algebra_map R S) p P) _ _
(Ξ» P : (factors (map (algebra_map R S) p)).to_finset, ideal.quot_equiv_of_eq $
by rw is_dedekind_domain.ramification_idx_eq_factors_count hp
(factors.is_prime p P) (factors.ne_bot p P)))
@[simp] lemma factors.pi_quotient_equiv_mk
(p : ideal R) (hp : map (algebra_map R S) p β β₯) (x : S) :
factors.pi_quotient_equiv p hp (ideal.quotient.mk _ x) = Ξ» P, ideal.quotient.mk _ x :=
rfl
@[simp] lemma factors.pi_quotient_equiv_map
(p : ideal R) (hp : map (algebra_map R S) p β β₯) (x : R) :
factors.pi_quotient_equiv p hp (algebra_map _ _ x) =
Ξ» P, ideal.quotient.mk _ (algebra_map _ _ x) :=
rfl
/-- **Chinese remainder theorem** for a ring of integers: if the prime ideal `p : ideal R`
factors in `S` as `β i, P i ^ e i`,
then `S β§Έ I` factors `R β§Έ I`-linearly as `Ξ i, R β§Έ (P i ^ e i)`. -/
noncomputable def factors.pi_quotient_linear_equiv
(p : ideal R) (hp : map (algebra_map R S) p β β₯) :
(S β§Έ map (algebra_map R S) p) ββ[R β§Έ p] Ξ (P : (factors (map (algebra_map R S) p)).to_finset),
S β§Έ ((P : ideal S) ^ ramification_idx (algebra_map R S) p P) :=
{ map_smul' := begin
rintro β¨cβ© β¨xβ©, ext P,
simp only [ideal.quotient.mk_algebra_map,
factors.pi_quotient_equiv_mk, factors.pi_quotient_equiv_map, submodule.quotient.quot_mk_eq_mk,
pi.algebra_map_apply, ring_equiv.to_fun_eq_coe, pi.mul_apply,
ideal.quotient.algebra_map_quotient_map_quotient, ideal.quotient.mk_eq_mk, algebra.smul_def,
_root_.map_mul, ring_hom_comp_triple.comp_apply],
congr
end,
.. factors.pi_quotient_equiv p hp }
open_locale big_operators
/-- The **fundamental identity** of ramification index `e` and inertia degree `f`:
for `P` ranging over the primes lying over `p`, `β P, e P * f P = [Frac(S) : Frac(R)]`;
here `S` is a finite `R`-module (and thus `Frac(S) : Frac(R)` is a finite extension) and `p`
is maximal.
-/
theorem sum_ramification_inertia (K L : Type*) [field K] [field L]
[is_domain R] [is_dedekind_domain R]
[algebra R K] [is_fraction_ring R K] [algebra S L] [is_fraction_ring S L]
[algebra K L] [algebra R L] [is_scalar_tower R S L] [is_scalar_tower R K L]
[is_noetherian R S] [is_integral_closure S R L] [p.is_maximal] (hp0 : p β β₯) :
β P in (factors (map (algebra_map R S) p)).to_finset,
ramification_idx (algebra_map R S) p P * inertia_deg (algebra_map R S) p P =
finrank K L :=
begin
set e := ramification_idx (algebra_map R S) p,
set f := inertia_deg (algebra_map R S) p,
have inj_RL : function.injective (algebra_map R L),
{ rw [is_scalar_tower.algebra_map_eq R K L, ring_hom.coe_comp],
exact (ring_hom.injective _).comp (is_fraction_ring.injective R K) },
have inj_RS : function.injective (algebra_map R S),
{ refine function.injective.of_comp (show function.injective (algebra_map S L β _), from _),
rw [β ring_hom.coe_comp, β is_scalar_tower.algebra_map_eq],
exact inj_RL },
calc β P in (factors (map (algebra_map R S) p)).to_finset, e P * f P
= β P in (factors (map (algebra_map R S) p)).to_finset.attach,
finrank (R β§Έ p) (S β§Έ (P : ideal S)^(e P)) : _
... = finrank (R β§Έ p) (Ξ P : (factors (map (algebra_map R S) p)).to_finset,
(S β§Έ (P : ideal S)^(e P))) :
(module.free.finrank_pi_fintype (R β§Έ p)).symm
... = finrank (R β§Έ p) (S β§Έ map (algebra_map R S) p) : _
... = finrank K L : _,
{ rw β finset.sum_attach,
refine finset.sum_congr rfl (Ξ» P _, _),
rw factors.finrank_pow_ramification_idx },
{ refine linear_equiv.finrank_eq (factors.pi_quotient_linear_equiv p _).symm,
rwa [ne.def, ideal.map_eq_bot_iff_le_ker, (ring_hom.injective_iff_ker_eq_bot _).mp inj_RS,
le_bot_iff] },
{ exact finrank_quotient_map p K L },
end
end factors_map
end ideal
|
7611977ad26b1e9cacda7072a2a153cda4671377 | 80cc5bf14c8ea85ff340d1d747a127dcadeb966f | /src/analysis/special_functions/trigonometric.lean | 4ed5ff6e3fb2fc048ccb790b7905231df4f09d1a | [
"Apache-2.0"
] | permissive | lacker/mathlib | f2439c743c4f8eb413ec589430c82d0f73b2d539 | ddf7563ac69d42cfa4a1bfe41db1fed521bd795f | refs/heads/master | 1,671,948,326,773 | 1,601,479,268,000 | 1,601,479,268,000 | 298,686,743 | 0 | 0 | Apache-2.0 | 1,601,070,794,000 | 1,601,070,794,000 | null | UTF-8 | Lean | false | false | 79,999 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne, Benjamin Davidson
-/
import analysis.special_functions.exp_log
/-!
# Trigonometric functions
## Main definitions
This file contains the following definitions:
* Ο, arcsin, arccos, arctan
* argument of a complex number
* logarithm on complex numbers
## Main statements
Many basic inequalities on trigonometric functions are established.
The continuity and differentiability of the usual trigonometric functions are proved, and their
derivatives are computed.
## Tags
log, sin, cos, tan, arcsin, arccos, arctan, angle, argument
-/
noncomputable theory
open_locale classical
open set
namespace complex
/-- The complex sine function is everywhere differentiable, with the derivative `cos x`. -/
lemma has_deriv_at_sin (x : β) : has_deriv_at sin (cos x) x :=
begin
simp only [cos, div_eq_mul_inv],
convert ((((has_deriv_at_id x).neg.mul_const I).cexp.sub
((has_deriv_at_id x).mul_const I).cexp).mul_const I).mul_const (2:β)β»ΒΉ,
simp only [function.comp, id],
rw [sub_mul, mul_assoc, mul_assoc, I_mul_I, neg_one_mul, neg_neg, mul_one, one_mul, mul_assoc,
I_mul_I, mul_neg_one, sub_neg_eq_add, add_comm]
end
lemma differentiable_sin : differentiable β sin :=
Ξ»x, (has_deriv_at_sin x).differentiable_at
lemma differentiable_at_sin {x : β} : differentiable_at β sin x :=
differentiable_sin x
@[simp] lemma deriv_sin : deriv sin = cos :=
funext $ Ξ» x, (has_deriv_at_sin x).deriv
lemma continuous_sin : continuous sin :=
differentiable_sin.continuous
/-- The complex cosine function is everywhere differentiable, with the derivative `-sin x`. -/
lemma has_deriv_at_cos (x : β) : has_deriv_at cos (-sin x) x :=
begin
simp only [sin, div_eq_mul_inv, neg_mul_eq_neg_mul],
convert (((has_deriv_at_id x).mul_const I).cexp.add
((has_deriv_at_id x).neg.mul_const I).cexp).mul_const (2:β)β»ΒΉ,
simp only [function.comp, id],
ring
end
lemma differentiable_cos : differentiable β cos :=
Ξ»x, (has_deriv_at_cos x).differentiable_at
lemma differentiable_at_cos {x : β} : differentiable_at β cos x :=
differentiable_cos x
lemma deriv_cos {x : β} : deriv cos x = -sin x :=
(has_deriv_at_cos x).deriv
@[simp] lemma deriv_cos' : deriv cos = (Ξ» x, -sin x) :=
funext $ Ξ» x, deriv_cos
lemma continuous_cos : continuous cos :=
differentiable_cos.continuous
/-- The complex hyperbolic sine function is everywhere differentiable, with the derivative `cosh x`. -/
lemma has_deriv_at_sinh (x : β) : has_deriv_at sinh (cosh x) x :=
begin
simp only [cosh, div_eq_mul_inv],
convert ((has_deriv_at_exp x).sub (has_deriv_at_id x).neg.cexp).mul_const (2:β)β»ΒΉ,
rw [id, mul_neg_one, neg_neg]
end
lemma differentiable_sinh : differentiable β sinh :=
Ξ»x, (has_deriv_at_sinh x).differentiable_at
lemma differentiable_at_sinh {x : β} : differentiable_at β sinh x :=
differentiable_sinh x
@[simp] lemma deriv_sinh : deriv sinh = cosh :=
funext $ Ξ» x, (has_deriv_at_sinh x).deriv
lemma continuous_sinh : continuous sinh :=
differentiable_sinh.continuous
/-- The complex hyperbolic cosine function is everywhere differentiable, with the derivative `sinh x`. -/
lemma has_deriv_at_cosh (x : β) : has_deriv_at cosh (sinh x) x :=
begin
simp only [sinh, div_eq_mul_inv],
convert ((has_deriv_at_exp x).add (has_deriv_at_id x).neg.cexp).mul_const (2:β)β»ΒΉ,
rw [id, mul_neg_one, sub_eq_add_neg]
end
lemma differentiable_cosh : differentiable β cosh :=
Ξ»x, (has_deriv_at_cosh x).differentiable_at
lemma differentiable_at_cosh {x : β} : differentiable_at β cos x :=
differentiable_cos x
@[simp] lemma deriv_cosh : deriv cosh = sinh :=
funext $ Ξ» x, (has_deriv_at_cosh x).deriv
lemma continuous_cosh : continuous cosh :=
differentiable_cosh.continuous
end complex
section
/-! Register lemmas for the derivatives of the composition of `complex.cos`, `complex.sin`,
`complex.cosh` and `complex.sinh` with a differentiable function, for standalone use and use with
`simp`. -/
variables {f : β β β} {f' x : β} {s : set β}
/-! `complex.cos`-/
lemma has_deriv_at.ccos (hf : has_deriv_at f f' x) :
has_deriv_at (Ξ» x, complex.cos (f x)) (- complex.sin (f x) * f') x :=
(complex.has_deriv_at_cos (f x)).comp x hf
lemma has_deriv_within_at.ccos (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (Ξ» x, complex.cos (f x)) (- complex.sin (f x) * f') s x :=
(complex.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf
lemma differentiable_within_at.ccos (hf : differentiable_within_at β f s x) :
differentiable_within_at β (Ξ» x, complex.cos (f x)) s x :=
hf.has_deriv_within_at.ccos.differentiable_within_at
@[simp] lemma differentiable_at.ccos (hc : differentiable_at β f x) :
differentiable_at β (Ξ»x, complex.cos (f x)) x :=
hc.has_deriv_at.ccos.differentiable_at
lemma differentiable_on.ccos (hc : differentiable_on β f s) :
differentiable_on β (Ξ»x, complex.cos (f x)) s :=
Ξ»x h, (hc x h).ccos
@[simp] lemma differentiable.ccos (hc : differentiable β f) :
differentiable β (Ξ»x, complex.cos (f x)) :=
Ξ»x, (hc x).ccos
lemma deriv_within_ccos (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
deriv_within (Ξ»x, complex.cos (f x)) s x = - complex.sin (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.ccos.deriv_within hxs
@[simp] lemma deriv_ccos (hc : differentiable_at β f x) :
deriv (Ξ»x, complex.cos (f x)) x = - complex.sin (f x) * (deriv f x) :=
hc.has_deriv_at.ccos.deriv
/-! `complex.sin`-/
lemma has_deriv_at.csin (hf : has_deriv_at f f' x) :
has_deriv_at (Ξ» x, complex.sin (f x)) (complex.cos (f x) * f') x :=
(complex.has_deriv_at_sin (f x)).comp x hf
lemma has_deriv_within_at.csin (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (Ξ» x, complex.sin (f x)) (complex.cos (f x) * f') s x :=
(complex.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf
lemma differentiable_within_at.csin (hf : differentiable_within_at β f s x) :
differentiable_within_at β (Ξ» x, complex.sin (f x)) s x :=
hf.has_deriv_within_at.csin.differentiable_within_at
@[simp] lemma differentiable_at.csin (hc : differentiable_at β f x) :
differentiable_at β (Ξ»x, complex.sin (f x)) x :=
hc.has_deriv_at.csin.differentiable_at
lemma differentiable_on.csin (hc : differentiable_on β f s) :
differentiable_on β (Ξ»x, complex.sin (f x)) s :=
Ξ»x h, (hc x h).csin
@[simp] lemma differentiable.csin (hc : differentiable β f) :
differentiable β (Ξ»x, complex.sin (f x)) :=
Ξ»x, (hc x).csin
lemma deriv_within_csin (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
deriv_within (Ξ»x, complex.sin (f x)) s x = complex.cos (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.csin.deriv_within hxs
@[simp] lemma deriv_csin (hc : differentiable_at β f x) :
deriv (Ξ»x, complex.sin (f x)) x = complex.cos (f x) * (deriv f x) :=
hc.has_deriv_at.csin.deriv
/-! `complex.cosh`-/
lemma has_deriv_at.ccosh (hf : has_deriv_at f f' x) :
has_deriv_at (Ξ» x, complex.cosh (f x)) (complex.sinh (f x) * f') x :=
(complex.has_deriv_at_cosh (f x)).comp x hf
lemma has_deriv_within_at.ccosh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (Ξ» x, complex.cosh (f x)) (complex.sinh (f x) * f') s x :=
(complex.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf
lemma differentiable_within_at.ccosh (hf : differentiable_within_at β f s x) :
differentiable_within_at β (Ξ» x, complex.cosh (f x)) s x :=
hf.has_deriv_within_at.ccosh.differentiable_within_at
@[simp] lemma differentiable_at.ccosh (hc : differentiable_at β f x) :
differentiable_at β (Ξ»x, complex.cosh (f x)) x :=
hc.has_deriv_at.ccosh.differentiable_at
lemma differentiable_on.ccosh (hc : differentiable_on β f s) :
differentiable_on β (Ξ»x, complex.cosh (f x)) s :=
Ξ»x h, (hc x h).ccosh
@[simp] lemma differentiable.ccosh (hc : differentiable β f) :
differentiable β (Ξ»x, complex.cosh (f x)) :=
Ξ»x, (hc x).ccosh
lemma deriv_within_ccosh (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
deriv_within (Ξ»x, complex.cosh (f x)) s x = complex.sinh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.ccosh.deriv_within hxs
@[simp] lemma deriv_ccosh (hc : differentiable_at β f x) :
deriv (Ξ»x, complex.cosh (f x)) x = complex.sinh (f x) * (deriv f x) :=
hc.has_deriv_at.ccosh.deriv
/-! `complex.sinh`-/
lemma has_deriv_at.csinh (hf : has_deriv_at f f' x) :
has_deriv_at (Ξ» x, complex.sinh (f x)) (complex.cosh (f x) * f') x :=
(complex.has_deriv_at_sinh (f x)).comp x hf
lemma has_deriv_within_at.csinh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (Ξ» x, complex.sinh (f x)) (complex.cosh (f x) * f') s x :=
(complex.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf
lemma differentiable_within_at.csinh (hf : differentiable_within_at β f s x) :
differentiable_within_at β (Ξ» x, complex.sinh (f x)) s x :=
hf.has_deriv_within_at.csinh.differentiable_within_at
@[simp] lemma differentiable_at.csinh (hc : differentiable_at β f x) :
differentiable_at β (Ξ»x, complex.sinh (f x)) x :=
hc.has_deriv_at.csinh.differentiable_at
lemma differentiable_on.csinh (hc : differentiable_on β f s) :
differentiable_on β (Ξ»x, complex.sinh (f x)) s :=
Ξ»x h, (hc x h).csinh
@[simp] lemma differentiable.csinh (hc : differentiable β f) :
differentiable β (Ξ»x, complex.sinh (f x)) :=
Ξ»x, (hc x).csinh
lemma deriv_within_csinh (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
deriv_within (Ξ»x, complex.sinh (f x)) s x = complex.cosh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.csinh.deriv_within hxs
@[simp] lemma deriv_csinh (hc : differentiable_at β f x) :
deriv (Ξ»x, complex.sinh (f x)) x = complex.cosh (f x) * (deriv f x) :=
hc.has_deriv_at.csinh.deriv
end
namespace real
variables {x y z : β}
lemma has_deriv_at_sin (x : β) : has_deriv_at sin (cos x) x :=
has_deriv_at_real_of_complex (complex.has_deriv_at_sin x)
lemma differentiable_sin : differentiable β sin :=
Ξ»x, (has_deriv_at_sin x).differentiable_at
lemma differentiable_at_sin : differentiable_at β sin x :=
differentiable_sin x
@[simp] lemma deriv_sin : deriv sin = cos :=
funext $ Ξ» x, (has_deriv_at_sin x).deriv
lemma continuous_sin : continuous sin :=
differentiable_sin.continuous
lemma has_deriv_at_cos (x : β) : has_deriv_at cos (-sin x) x :=
(has_deriv_at_real_of_complex (complex.has_deriv_at_cos x) : _)
lemma differentiable_cos : differentiable β cos :=
Ξ»x, (has_deriv_at_cos x).differentiable_at
lemma differentiable_at_cos : differentiable_at β cos x :=
differentiable_cos x
lemma deriv_cos : deriv cos x = - sin x :=
(has_deriv_at_cos x).deriv
@[simp] lemma deriv_cos' : deriv cos = (Ξ» x, - sin x) :=
funext $ Ξ» _, deriv_cos
lemma continuous_cos : continuous cos :=
differentiable_cos.continuous
lemma has_deriv_at_sinh (x : β) : has_deriv_at sinh (cosh x) x :=
has_deriv_at_real_of_complex (complex.has_deriv_at_sinh x)
lemma differentiable_sinh : differentiable β sinh :=
Ξ»x, (has_deriv_at_sinh x).differentiable_at
lemma differentiable_at_sinh : differentiable_at β sinh x :=
differentiable_sinh x
@[simp] lemma deriv_sinh : deriv sinh = cosh :=
funext $ Ξ» x, (has_deriv_at_sinh x).deriv
lemma continuous_sinh : continuous sinh :=
differentiable_sinh.continuous
lemma has_deriv_at_cosh (x : β) : has_deriv_at cosh (sinh x) x :=
has_deriv_at_real_of_complex (complex.has_deriv_at_cosh x)
lemma differentiable_cosh : differentiable β cosh :=
Ξ»x, (has_deriv_at_cosh x).differentiable_at
lemma differentiable_at_cosh : differentiable_at β cosh x :=
differentiable_cosh x
@[simp] lemma deriv_cosh : deriv cosh = sinh :=
funext $ Ξ» x, (has_deriv_at_cosh x).deriv
lemma continuous_cosh : continuous cosh :=
differentiable_cosh.continuous
/-- `sinh` is strictly monotone. -/
lemma sinh_strict_mono : strict_mono sinh :=
strict_mono_of_deriv_pos differentiable_sinh (by { rw [real.deriv_sinh], exact cosh_pos })
end real
section
/-! Register lemmas for the derivatives of the composition of `real.exp`, `real.cos`, `real.sin`,
`real.cosh` and `real.sinh` with a differentiable function, for standalone use and use with
`simp`. -/
variables {f : β β β} {f' x : β} {s : set β}
/-! `real.cos`-/
lemma has_deriv_at.cos (hf : has_deriv_at f f' x) :
has_deriv_at (Ξ» x, real.cos (f x)) (- real.sin (f x) * f') x :=
(real.has_deriv_at_cos (f x)).comp x hf
lemma has_deriv_within_at.cos (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (Ξ» x, real.cos (f x)) (- real.sin (f x) * f') s x :=
(real.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf
lemma differentiable_within_at.cos (hf : differentiable_within_at β f s x) :
differentiable_within_at β (Ξ» x, real.cos (f x)) s x :=
hf.has_deriv_within_at.cos.differentiable_within_at
@[simp] lemma differentiable_at.cos (hc : differentiable_at β f x) :
differentiable_at β (Ξ»x, real.cos (f x)) x :=
hc.has_deriv_at.cos.differentiable_at
lemma differentiable_on.cos (hc : differentiable_on β f s) :
differentiable_on β (Ξ»x, real.cos (f x)) s :=
Ξ»x h, (hc x h).cos
@[simp] lemma differentiable.cos (hc : differentiable β f) :
differentiable β (Ξ»x, real.cos (f x)) :=
Ξ»x, (hc x).cos
lemma deriv_within_cos (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
deriv_within (Ξ»x, real.cos (f x)) s x = - real.sin (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.cos.deriv_within hxs
@[simp] lemma deriv_cos (hc : differentiable_at β f x) :
deriv (Ξ»x, real.cos (f x)) x = - real.sin (f x) * (deriv f x) :=
hc.has_deriv_at.cos.deriv
/-! `real.sin`-/
lemma has_deriv_at.sin (hf : has_deriv_at f f' x) :
has_deriv_at (Ξ» x, real.sin (f x)) (real.cos (f x) * f') x :=
(real.has_deriv_at_sin (f x)).comp x hf
lemma has_deriv_within_at.sin (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (Ξ» x, real.sin (f x)) (real.cos (f x) * f') s x :=
(real.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf
lemma differentiable_within_at.sin (hf : differentiable_within_at β f s x) :
differentiable_within_at β (Ξ» x, real.sin (f x)) s x :=
hf.has_deriv_within_at.sin.differentiable_within_at
@[simp] lemma differentiable_at.sin (hc : differentiable_at β f x) :
differentiable_at β (Ξ»x, real.sin (f x)) x :=
hc.has_deriv_at.sin.differentiable_at
lemma differentiable_on.sin (hc : differentiable_on β f s) :
differentiable_on β (Ξ»x, real.sin (f x)) s :=
Ξ»x h, (hc x h).sin
@[simp] lemma differentiable.sin (hc : differentiable β f) :
differentiable β (Ξ»x, real.sin (f x)) :=
Ξ»x, (hc x).sin
lemma deriv_within_sin (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
deriv_within (Ξ»x, real.sin (f x)) s x = real.cos (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.sin.deriv_within hxs
@[simp] lemma deriv_sin (hc : differentiable_at β f x) :
deriv (Ξ»x, real.sin (f x)) x = real.cos (f x) * (deriv f x) :=
hc.has_deriv_at.sin.deriv
/-! `real.cosh`-/
lemma has_deriv_at.cosh (hf : has_deriv_at f f' x) :
has_deriv_at (Ξ» x, real.cosh (f x)) (real.sinh (f x) * f') x :=
(real.has_deriv_at_cosh (f x)).comp x hf
lemma has_deriv_within_at.cosh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (Ξ» x, real.cosh (f x)) (real.sinh (f x) * f') s x :=
(real.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf
lemma differentiable_within_at.cosh (hf : differentiable_within_at β f s x) :
differentiable_within_at β (Ξ» x, real.cosh (f x)) s x :=
hf.has_deriv_within_at.cosh.differentiable_within_at
@[simp] lemma differentiable_at.cosh (hc : differentiable_at β f x) :
differentiable_at β (Ξ»x, real.cosh (f x)) x :=
hc.has_deriv_at.cosh.differentiable_at
lemma differentiable_on.cosh (hc : differentiable_on β f s) :
differentiable_on β (Ξ»x, real.cosh (f x)) s :=
Ξ»x h, (hc x h).cosh
@[simp] lemma differentiable.cosh (hc : differentiable β f) :
differentiable β (Ξ»x, real.cosh (f x)) :=
Ξ»x, (hc x).cosh
lemma deriv_within_cosh (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
deriv_within (Ξ»x, real.cosh (f x)) s x = real.sinh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.cosh.deriv_within hxs
@[simp] lemma deriv_cosh (hc : differentiable_at β f x) :
deriv (Ξ»x, real.cosh (f x)) x = real.sinh (f x) * (deriv f x) :=
hc.has_deriv_at.cosh.deriv
/-! `real.sinh`-/
lemma has_deriv_at.sinh (hf : has_deriv_at f f' x) :
has_deriv_at (Ξ» x, real.sinh (f x)) (real.cosh (f x) * f') x :=
(real.has_deriv_at_sinh (f x)).comp x hf
lemma has_deriv_within_at.sinh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (Ξ» x, real.sinh (f x)) (real.cosh (f x) * f') s x :=
(real.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf
lemma differentiable_within_at.sinh (hf : differentiable_within_at β f s x) :
differentiable_within_at β (Ξ» x, real.sinh (f x)) s x :=
hf.has_deriv_within_at.sinh.differentiable_within_at
@[simp] lemma differentiable_at.sinh (hc : differentiable_at β f x) :
differentiable_at β (Ξ»x, real.sinh (f x)) x :=
hc.has_deriv_at.sinh.differentiable_at
lemma differentiable_on.sinh (hc : differentiable_on β f s) :
differentiable_on β (Ξ»x, real.sinh (f x)) s :=
Ξ»x h, (hc x h).sinh
@[simp] lemma differentiable.sinh (hc : differentiable β f) :
differentiable β (Ξ»x, real.sinh (f x)) :=
Ξ»x, (hc x).sinh
lemma deriv_within_sinh (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
deriv_within (Ξ»x, real.sinh (f x)) s x = real.cosh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.sinh.deriv_within hxs
@[simp] lemma deriv_sinh (hc : differentiable_at β f x) :
deriv (Ξ»x, real.sinh (f x)) x = real.cosh (f x) * (deriv f x) :=
hc.has_deriv_at.sinh.deriv
end
namespace real
lemma exists_cos_eq_zero : 0 β cos '' Icc (1:β) 2 :=
intermediate_value_Icc' (by norm_num) continuous_cos.continuous_on
β¨le_of_lt cos_two_neg, le_of_lt cos_one_posβ©
/-- The number Ο = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from
which one can derive all its properties. For explicit bounds on Ο, see `data.real.pi`. -/
noncomputable def pi : β := 2 * classical.some exists_cos_eq_zero
localized "notation `Ο` := real.pi" in real
@[simp] lemma cos_pi_div_two : cos (Ο / 2) = 0 :=
by rw [pi, mul_div_cancel_left _ (@two_ne_zero' β _ _ _)];
exact (classical.some_spec exists_cos_eq_zero).2
lemma one_le_pi_div_two : (1 : β) β€ Ο / 2 :=
by rw [pi, mul_div_cancel_left _ (@two_ne_zero' β _ _ _)];
exact (classical.some_spec exists_cos_eq_zero).1.1
lemma pi_div_two_le_two : Ο / 2 β€ 2 :=
by rw [pi, mul_div_cancel_left _ (@two_ne_zero' β _ _ _)];
exact (classical.some_spec exists_cos_eq_zero).1.2
lemma two_le_pi : (2 : β) β€ Ο :=
(div_le_div_right (show (0 : β) < 2, by norm_num)).1
(by rw div_self (@two_ne_zero' β _ _ _); exact one_le_pi_div_two)
lemma pi_le_four : Ο β€ 4 :=
(div_le_div_right (show (0 : β) < 2, by norm_num)).1
(calc Ο / 2 β€ 2 : pi_div_two_le_two
... = 4 / 2 : by norm_num)
lemma pi_pos : 0 < Ο :=
lt_of_lt_of_le (by norm_num) two_le_pi
lemma pi_div_two_pos : 0 < Ο / 2 :=
half_pos pi_pos
lemma two_pi_pos : 0 < 2 * Ο :=
by linarith [pi_pos]
@[simp] lemma sin_pi : sin Ο = 0 :=
by rw [β mul_div_cancel_left pi (@two_ne_zero β _), two_mul, add_div,
sin_add, cos_pi_div_two]; simp
@[simp] lemma cos_pi : cos Ο = -1 :=
by rw [β mul_div_cancel_left pi (@two_ne_zero β _), mul_div_assoc,
cos_two_mul, cos_pi_div_two];
simp [bit0, pow_add]
@[simp] lemma sin_two_pi : sin (2 * Ο) = 0 :=
by simp [two_mul, sin_add]
@[simp] lemma cos_two_pi : cos (2 * Ο) = 1 :=
by simp [two_mul, cos_add]
lemma sin_add_pi (x : β) : sin (x + Ο) = -sin x :=
by simp [sin_add]
lemma sin_add_two_pi (x : β) : sin (x + 2 * Ο) = sin x :=
by simp [sin_add_pi, sin_add, sin_two_pi, cos_two_pi]
lemma cos_add_two_pi (x : β) : cos (x + 2 * Ο) = cos x :=
by simp [cos_add, cos_two_pi, sin_two_pi]
lemma sin_pi_sub (x : β) : sin (Ο - x) = sin x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi (x : β) : cos (x + Ο) = -cos x :=
by simp [cos_add]
lemma cos_pi_sub (x : β) : cos (Ο - x) = -cos x :=
by simp [sub_eq_add_neg, cos_add]
lemma sin_pos_of_pos_of_lt_pi {x : β} (h0x : 0 < x) (hxp : x < Ο) : 0 < sin x :=
if hx2 : x β€ 2 then sin_pos_of_pos_of_le_two h0x hx2
else
have (2 : β) + 2 = 4, from rfl,
have Ο - x β€ 2, from sub_le_iff_le_add.2
(le_trans pi_le_four (this βΈ add_le_add_left (le_of_not_ge hx2) _)),
sin_pi_sub x βΈ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this
lemma sin_nonneg_of_nonneg_of_le_pi {x : β} (h0x : 0 β€ x) (hxp : x β€ Ο) : 0 β€ sin x :=
match lt_or_eq_of_le h0x with
| or.inl h0x := (lt_or_eq_of_le hxp).elim
(le_of_lt β sin_pos_of_pos_of_lt_pi h0x)
(Ξ» hpx, by simp [hpx])
| or.inr h0x := by simp [h0x.symm]
end
lemma sin_neg_of_neg_of_neg_pi_lt {x : β} (hx0 : x < 0) (hpx : -Ο < x) : sin x < 0 :=
neg_pos.1 $ sin_neg x βΈ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx)
lemma sin_nonpos_of_nonnpos_of_neg_pi_le {x : β} (hx0 : x β€ 0) (hpx : -Ο β€ x) : sin x β€ 0 :=
neg_nonneg.1 $ sin_neg x βΈ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx)
@[simp] lemma sin_pi_div_two : sin (Ο / 2) = 1 :=
have sin (Ο / 2) = 1 β¨ sin (Ο / 2) = -1 :=
by simpa [pow_two, mul_self_eq_one_iff] using sin_sq_add_cos_sq (Ο / 2),
this.resolve_right
(Ξ» h, (show Β¬(0 : β) < -1, by norm_num) $
h βΈ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos))
lemma sin_add_pi_div_two (x : β) : sin (x + Ο / 2) = cos x :=
by simp [sin_add]
lemma sin_sub_pi_div_two (x : β) : sin (x - Ο / 2) = -cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma sin_pi_div_two_sub (x : β) : sin (Ο / 2 - x) = cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi_div_two (x : β) : cos (x + Ο / 2) = -sin x :=
by simp [cos_add]
lemma cos_sub_pi_div_two (x : β) : cos (x - Ο / 2) = sin x :=
by simp [sub_eq_add_neg, cos_add]
lemma cos_pi_div_two_sub (x : β) : cos (Ο / 2 - x) = sin x :=
by rw [β cos_neg, neg_sub, cos_sub_pi_div_two]
lemma cos_pos_of_mem_Ioo
{x : β} (hxβ : -(Ο / 2) < x) (hxβ : x < Ο / 2) : 0 < cos x :=
sin_add_pi_div_two x βΈ sin_pos_of_pos_of_lt_pi (by linarith) (by linarith)
lemma cos_nonneg_of_mem_Icc
{x : β} (hxβ : -(Ο / 2) β€ x) (hxβ : x β€ Ο / 2) : 0 β€ cos x :=
match lt_or_eq_of_le hxβ, lt_or_eq_of_le hxβ with
| or.inl hxβ, or.inl hxβ := le_of_lt (cos_pos_of_mem_Ioo hxβ hxβ)
| or.inl hxβ, or.inr hxβ := by simp [hxβ]
| or.inr hxβ, _ := by simp [hxβ.symm]
end
lemma cos_neg_of_pi_div_two_lt_of_lt {x : β} (hxβ : Ο / 2 < x) (hxβ : x < Ο + Ο / 2) : cos x < 0 :=
neg_pos.1 $ cos_pi_sub x βΈ
cos_pos_of_mem_Ioo (by linarith) (by linarith)
lemma cos_nonpos_of_pi_div_two_le_of_le {x : β} (hxβ : Ο / 2 β€ x) (hxβ : x β€ Ο + Ο / 2) : cos x β€ 0 :=
neg_nonneg.1 $ cos_pi_sub x βΈ
cos_nonneg_of_mem_Icc (by linarith) (by linarith)
lemma sin_nat_mul_pi (n : β) : sin (n * Ο) = 0 :=
by induction n; simp [add_mul, sin_add, *]
lemma sin_int_mul_pi (n : β€) : sin (n * Ο) = 0 :=
by cases n; simp [add_mul, sin_add, *, sin_nat_mul_pi]
lemma cos_nat_mul_two_pi (n : β) : cos (n * (2 * Ο)) = 1 :=
by induction n; simp [*, mul_add, cos_add, add_mul, cos_two_pi, sin_two_pi]
lemma cos_int_mul_two_pi (n : β€) : cos (n * (2 * Ο)) = 1 :=
by cases n; simp only [cos_nat_mul_two_pi, int.of_nat_eq_coe,
int.neg_succ_of_nat_coe, int.cast_coe_nat, int.cast_neg,
(neg_mul_eq_neg_mul _ _).symm, cos_neg]
lemma cos_int_mul_two_pi_add_pi (n : β€) : cos (n * (2 * Ο) + Ο) = -1 :=
by simp [cos_add, sin_add, cos_int_mul_two_pi]
lemma sin_eq_zero_iff_of_lt_of_lt {x : β} (hxβ : -Ο < x) (hxβ : x < Ο) :
sin x = 0 β x = 0 :=
β¨Ξ» h, le_antisymm
(le_of_not_gt (Ξ» h0, lt_irrefl (0 : β) $
calc 0 < sin x : sin_pos_of_pos_of_lt_pi h0 hxβ
... = 0 : h))
(le_of_not_gt (Ξ» h0, lt_irrefl (0 : β) $
calc 0 = sin x : h.symm
... < 0 : sin_neg_of_neg_of_neg_pi_lt h0 hxβ)),
Ξ» h, by simp [h]β©
lemma sin_eq_zero_iff {x : β} : sin x = 0 β β n : β€, (n : β) * Ο = x :=
β¨Ξ» h, β¨βx / Οβ, le_antisymm (sub_nonneg.1 (sub_floor_div_mul_nonneg _ pi_pos))
(sub_nonpos.1 $ le_of_not_gt $ Ξ» hβ, ne_of_lt (sin_pos_of_pos_of_lt_pi hβ (sub_floor_div_mul_lt _ pi_pos))
(by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))β©,
Ξ» β¨n, hnβ©, hn βΈ sin_int_mul_pi _β©
lemma sin_eq_zero_iff_cos_eq {x : β} : sin x = 0 β cos x = 1 β¨ cos x = -1 :=
by rw [β mul_self_eq_one_iff, β sin_sq_add_cos_sq x,
pow_two, pow_two, β sub_eq_iff_eq_add, sub_self];
exact β¨Ξ» h, by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero β eq.symmβ©
theorem sin_sub_sin (ΞΈ Ο : β) : sin ΞΈ - sin Ο = 2 * sin((ΞΈ - Ο)/2) * cos((ΞΈ + Ο)/2) :=
begin
have s1 := sin_add ((ΞΈ + Ο) / 2) ((ΞΈ - Ο) / 2),
have s2 := sin_sub ((ΞΈ + Ο) / 2) ((ΞΈ - Ο) / 2),
rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel, add_self_div_two] at s1,
rw [div_sub_div_same, βsub_add, add_sub_cancel', add_self_div_two] at s2,
rw [s1, s2, βsub_add, add_sub_cancel', β two_mul, β mul_assoc, mul_right_comm]
end
lemma cos_eq_one_iff (x : β) : cos x = 1 β β n : β€, (n : β) * (2 * Ο) = x :=
β¨Ξ» h, let β¨n, hnβ© := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (or.inl h)) in
β¨n / 2, (int.mod_two_eq_zero_or_one n).elim
(Ξ» hn0, by rwa [β mul_assoc, β @int.cast_two β, β int.cast_mul, int.div_mul_cancel
((int.dvd_iff_mod_eq_zero _ _).2 hn0)])
(Ξ» hn1, by rw [β int.mod_add_div n 2, hn1, int.cast_add, int.cast_one, add_mul,
one_mul, add_comm, mul_comm (2 : β€), int.cast_mul, mul_assoc, int.cast_two] at hn;
rw [β hn, cos_int_mul_two_pi_add_pi] at h;
exact absurd h (by norm_num))β©,
Ξ» β¨n, hnβ©, hn βΈ cos_int_mul_two_pi _β©
lemma cos_eq_one_iff_of_lt_of_lt {x : β} (hxβ : -(2 * Ο) < x) (hxβ : x < 2 * Ο) : cos x = 1 β x = 0 :=
β¨Ξ» h, let β¨n, hnβ© := (cos_eq_one_iff x).1 h in
begin
clear _let_match,
subst hn,
rw [mul_lt_iff_lt_one_left two_pi_pos, β int.cast_one, int.cast_lt, β int.le_sub_one_iff, sub_self] at hxβ,
rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos, neg_lt,
β int.cast_one, β int.cast_neg, int.cast_lt, β int.add_one_le_iff, neg_add_self] at hxβ,
exact mul_eq_zero.2 (or.inl (int.cast_eq_zero.2 (le_antisymm hxβ hxβ))),
end,
Ξ» h, by simp [h]β©
theorem cos_sub_cos (ΞΈ Ο : β) : cos ΞΈ - cos Ο = -2 * sin((ΞΈ + Ο)/2) * sin((ΞΈ - Ο)/2) :=
by rw [β sin_pi_div_two_sub, β sin_pi_div_two_sub, sin_sub_sin, sub_sub_sub_cancel_left,
add_sub, sub_add_eq_add_sub, add_halves, sub_sub, sub_div Ο, cos_pi_div_two_sub,
β neg_sub, neg_div, sin_neg, β neg_mul_eq_mul_neg, neg_mul_eq_neg_mul, mul_right_comm]
lemma cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : β} (hxβ : 0 β€ x) (hyβ : y β€ Ο / 2) (hxy : x < y) :
cos y < cos x :=
calc cos y = cos x * cos (y - x) - sin x * sin (y - x) :
by rw [β cos_add, add_sub_cancel'_right]
... < (cos x * 1) - sin x * sin (y - x) :
sub_lt_sub_right ((mul_lt_mul_left
(cos_pos_of_mem_Ioo (lt_of_lt_of_le (neg_neg_of_pos pi_div_two_pos) hxβ)
(lt_of_lt_of_le hxy hyβ))).2
(lt_of_le_of_ne (cos_le_one _) (mt (cos_eq_one_iff_of_lt_of_lt
(show -(2 * Ο) < y - x, by linarith) (show y - x < 2 * Ο, by linarith)).1
(sub_ne_zero.2 (ne_of_lt hxy).symm)))) _
... β€ _ : by rw mul_one;
exact sub_le_self _ (mul_nonneg (sin_nonneg_of_nonneg_of_le_pi hxβ (by linarith))
(sin_nonneg_of_nonneg_of_le_pi (by linarith) (by linarith)))
lemma cos_lt_cos_of_nonneg_of_le_pi {x y : β} (hxβ : 0 β€ x) (hyβ : y β€ Ο) (hxy : x < y) :
cos y < cos x :=
match (le_total x (Ο / 2) : x β€ Ο / 2 β¨ Ο / 2 β€ x), le_total y (Ο / 2) with
| or.inl hx, or.inl hy := cos_lt_cos_of_nonneg_of_le_pi_div_two hxβ hy hxy
| or.inl hx, or.inr hy := (lt_or_eq_of_le hx).elim
(Ξ» hx, calc cos y β€ 0 : cos_nonpos_of_pi_div_two_le_of_le hy (by linarith [pi_pos])
... < cos x : cos_pos_of_mem_Ioo (by linarith) hx)
(Ξ» hx, calc cos y < 0 : cos_neg_of_pi_div_two_lt_of_lt (by linarith) (by linarith [pi_pos])
... = cos x : by rw [hx, cos_pi_div_two])
| or.inr hx, or.inl hy := by linarith
| or.inr hx, or.inr hy := neg_lt_neg_iff.1 (by rw [β cos_pi_sub, β cos_pi_sub];
apply cos_lt_cos_of_nonneg_of_le_pi_div_two; linarith)
end
lemma cos_le_cos_of_nonneg_of_le_pi {x y : β} (hxβ : 0 β€ x) (hyβ : y β€ Ο) (hxy : x β€ y) :
cos y β€ cos x :=
(lt_or_eq_of_le hxy).elim
(le_of_lt β cos_lt_cos_of_nonneg_of_le_pi hxβ hyβ)
(Ξ» h, h βΈ le_refl _)
lemma sin_lt_sin_of_le_of_le_pi_div_two {x y : β} (hxβ : -(Ο / 2) β€ x)
(hyβ : y β€ Ο / 2) (hxy : x < y) : sin x < sin y :=
by rw [β cos_sub_pi_div_two, β cos_sub_pi_div_two, β cos_neg (x - _), β cos_neg (y - _)];
apply cos_lt_cos_of_nonneg_of_le_pi; linarith
lemma sin_le_sin_of_le_of_le_pi_div_two {x y : β} (hxβ : -(Ο / 2) β€ x)
(hyβ : y β€ Ο / 2) (hxy : x β€ y) : sin x β€ sin y :=
(lt_or_eq_of_le hxy).elim
(le_of_lt β sin_lt_sin_of_le_of_le_pi_div_two hxβ hyβ)
(Ξ» h, h βΈ le_refl _)
lemma sin_inj_of_le_of_le_pi_div_two {x y : β} (hxβ : -(Ο / 2) β€ x) (hxβ : x β€ Ο / 2) (hyβ : -(Ο / 2) β€ y)
(hyβ : y β€ Ο / 2) (hxy : sin x = sin y) : x = y :=
match lt_trichotomy x y with
| or.inl h := absurd (sin_lt_sin_of_le_of_le_pi_div_two hxβ hyβ h) (by rw hxy; exact lt_irrefl _)
| or.inr (or.inl h) := h
| or.inr (or.inr h) := absurd (sin_lt_sin_of_le_of_le_pi_div_two hyβ hxβ h) (by rw hxy; exact lt_irrefl _)
end
lemma cos_inj_of_nonneg_of_le_pi {x y : β} (hxβ : 0 β€ x) (hxβ : x β€ Ο) (hyβ : 0 β€ y) (hyβ : y β€ Ο)
(hxy : cos x = cos y) : x = y :=
begin
rw [β sin_pi_div_two_sub, β sin_pi_div_two_sub] at hxy,
refine (sub_right_inj).1 (sin_inj_of_le_of_le_pi_div_two _ _ _ _ hxy);
linarith
end
lemma exists_sin_eq : Icc (-1:β) 1 β sin '' Icc (-(Ο / 2)) (Ο / 2) :=
by convert intermediate_value_Icc
(le_trans (neg_nonpos.2 (le_of_lt pi_div_two_pos)) (le_of_lt pi_div_two_pos))
continuous_sin.continuous_on; simp only [sin_neg, sin_pi_div_two]
lemma exists_cos_eq : (Icc (-1) 1 : set β) β cos '' Icc 0 Ο :=
by convert intermediate_value_Icc' real.pi_pos.le real.continuous_cos.continuous_on;
simp only [real.cos_pi, real.cos_zero]
lemma range_cos : range cos = (Icc (-1) 1 : set β) :=
begin
ext,
split,
{ rintros β¨y, rflβ©, exact β¨y.neg_one_le_cos, y.cos_le_oneβ© },
{ rintros h,
rcases real.exists_cos_eq h with β¨y, -, hyβ©,
exact β¨y, hyβ© }
end
lemma range_sin : range sin = (Icc (-1) 1 : set β) :=
begin
ext,
split,
{ rintros β¨y, rflβ©, exact β¨y.neg_one_le_sin, y.sin_le_oneβ© },
{ rintros h,
rcases real.exists_sin_eq h with β¨y, -, hyβ©,
exact β¨y, hyβ© }
end
lemma sin_lt {x : β} (h : 0 < x) : sin x < x :=
begin
cases le_or_gt x 1 with h' h',
{ have hx : abs x = x := abs_of_nonneg (le_of_lt h),
have : abs x β€ 1, rwa [hx],
have := sin_bound this, rw [abs_le] at this,
have := this.2, rw [sub_le_iff_le_add', hx] at this,
apply lt_of_le_of_lt this, rw [sub_add], apply lt_of_lt_of_le _ (le_of_eq (sub_zero x)),
apply sub_lt_sub_left, rw sub_pos, apply mul_lt_mul',
{ rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)),
rw mul_le_mul_right, exact h', apply pow_pos h },
norm_num, norm_num, apply pow_pos h },
exact lt_of_le_of_lt (sin_le_one x) h'
end
/- note 1: this inequality is not tight, the tighter inequality is sin x > x - x ^ 3 / 6.
note 2: this is also true for x > 1, but it's nontrivial for x just above 1. -/
lemma sin_gt_sub_cube {x : β} (h : 0 < x) (h' : x β€ 1) : x - x ^ 3 / 4 < sin x :=
begin
have hx : abs x = x := abs_of_nonneg (le_of_lt h),
have : abs x β€ 1, rwa [hx],
have := sin_bound this, rw [abs_le] at this,
have := this.1, rw [le_sub_iff_add_le, hx] at this,
refine lt_of_lt_of_le _ this,
rw [add_comm, sub_add, sub_neg_eq_add], apply sub_lt_sub_left,
apply add_lt_of_lt_sub_left,
rw (show x ^ 3 / 4 - x ^ 3 / 6 = x ^ 3 / 12,
by simp [div_eq_mul_inv, (mul_sub _ _ _).symm, -sub_eq_add_neg]; congr; norm_num),
apply mul_lt_mul',
{ rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)),
rw mul_le_mul_right, exact h', apply pow_pos h },
norm_num, norm_num, apply pow_pos h
end
section cos_div_pow_two
variable (x : β)
/-- the series `sqrt_two_add_series x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots,
starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrt_two_add_series 0 n / 2`
-/
@[simp] noncomputable def sqrt_two_add_series (x : β) : β β β
| 0 := x
| (n+1) := sqrt (2 + sqrt_two_add_series n)
lemma sqrt_two_add_series_zero : sqrt_two_add_series x 0 = x := by simp
lemma sqrt_two_add_series_one : sqrt_two_add_series 0 1 = sqrt 2 := by simp
lemma sqrt_two_add_series_two : sqrt_two_add_series 0 2 = sqrt (2 + sqrt 2) := by simp
lemma sqrt_two_add_series_zero_nonneg : β(n : β), 0 β€ sqrt_two_add_series 0 n
| 0 := le_refl 0
| (n+1) := sqrt_nonneg _
lemma sqrt_two_add_series_nonneg {x : β} (h : 0 β€ x) : β(n : β), 0 β€ sqrt_two_add_series x n
| 0 := h
| (n+1) := sqrt_nonneg _
lemma sqrt_two_add_series_lt_two : β(n : β), sqrt_two_add_series 0 n < 2
| 0 := by norm_num
| (n+1) :=
begin
refine lt_of_lt_of_le _ (le_of_eq $ sqrt_sqr $ le_of_lt two_pos),
rw [sqrt_two_add_series, sqrt_lt],
apply add_lt_of_lt_sub_left,
apply lt_of_lt_of_le (sqrt_two_add_series_lt_two n),
norm_num, apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg, norm_num
end
lemma sqrt_two_add_series_succ (x : β) :
β(n : β), sqrt_two_add_series x (n+1) = sqrt_two_add_series (sqrt (2 + x)) n
| 0 := rfl
| (n+1) := by rw [sqrt_two_add_series, sqrt_two_add_series_succ, sqrt_two_add_series]
lemma sqrt_two_add_series_monotone_left {x y : β} (h : x β€ y) :
β(n : β), sqrt_two_add_series x n β€ sqrt_two_add_series y n
| 0 := h
| (n+1) :=
begin
rw [sqrt_two_add_series, sqrt_two_add_series],
apply sqrt_le_sqrt, apply add_le_add_left, apply sqrt_two_add_series_monotone_left
end
@[simp] lemma cos_pi_over_two_pow : β(n : β), cos (pi / 2 ^ (n+1)) = sqrt_two_add_series 0 n / 2
| 0 := by simp
| (n+1) :=
begin
symmetry, rw [div_eq_iff_mul_eq], symmetry,
rw [sqrt_two_add_series, sqrt_eq_iff_sqr_eq, mul_pow, cos_square, βmul_div_assoc,
nat.add_succ, pow_succ, mul_div_mul_left, cos_pi_over_two_pow, add_mul],
congr, norm_num,
rw [mul_comm, pow_two, mul_assoc, βmul_div_assoc, mul_div_cancel_left, βmul_div_assoc,
mul_div_cancel_left],
norm_num, norm_num, norm_num,
apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg, norm_num,
apply le_of_lt, apply cos_pos_of_mem_Ioo,
{ transitivity (0 : β), rw neg_lt_zero, apply pi_div_two_pos,
apply div_pos pi_pos, apply pow_pos, norm_num },
apply div_lt_div' (le_refl pi) _ pi_pos _,
refine lt_of_le_of_lt (le_of_eq (pow_one _).symm) _,
apply pow_lt_pow, norm_num, apply nat.succ_lt_succ, apply nat.succ_pos, all_goals {norm_num}
end
lemma sin_square_pi_over_two_pow (n : β) :
sin (pi / 2 ^ (n+1)) ^ 2 = 1 - (sqrt_two_add_series 0 n / 2) ^ 2 :=
by rw [sin_square, cos_pi_over_two_pow]
lemma sin_square_pi_over_two_pow_succ (n : β) :
sin (pi / 2 ^ (n+2)) ^ 2 = 1 / 2 - sqrt_two_add_series 0 n / 4 :=
begin
rw [sin_square_pi_over_two_pow, sqrt_two_add_series, div_pow, sqr_sqrt, add_div, βsub_sub],
congr, norm_num, norm_num, apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg,
end
@[simp] lemma sin_pi_over_two_pow_succ (n : β) :
sin (pi / 2 ^ (n+2)) = sqrt (2 - sqrt_two_add_series 0 n) / 2 :=
begin
symmetry, rw [div_eq_iff_mul_eq], symmetry,
rw [sqrt_eq_iff_sqr_eq, mul_pow, sin_square_pi_over_two_pow_succ, sub_mul],
{ congr, norm_num, rw [mul_comm], convert mul_div_cancel' _ _, norm_num, norm_num },
{ rw [sub_nonneg], apply le_of_lt, apply sqrt_two_add_series_lt_two },
apply le_of_lt, apply mul_pos, apply sin_pos_of_pos_of_lt_pi,
{ apply div_pos pi_pos, apply pow_pos, norm_num },
refine lt_of_lt_of_le _ (le_of_eq (div_one _)), rw [div_lt_div_left],
refine lt_of_le_of_lt (le_of_eq (pow_zero 2).symm) _,
apply pow_lt_pow, norm_num, apply nat.succ_pos, apply pi_pos,
apply pow_pos, all_goals {norm_num}
end
lemma cos_pi_div_four : cos (pi / 4) = sqrt 2 / 2 :=
by { transitivity cos (pi / 2 ^ 2), congr, norm_num, simp }
lemma sin_pi_div_four : sin (pi / 4) = sqrt 2 / 2 :=
by { transitivity sin (pi / 2 ^ 2), congr, norm_num, simp }
lemma cos_pi_div_eight : cos (pi / 8) = sqrt (2 + sqrt 2) / 2 :=
by { transitivity cos (pi / 2 ^ 3), congr, norm_num, simp }
lemma sin_pi_div_eight : sin (pi / 8) = sqrt (2 - sqrt 2) / 2 :=
by { transitivity sin (pi / 2 ^ 3), congr, norm_num, simp }
lemma cos_pi_div_sixteen : cos (pi / 16) = sqrt (2 + sqrt (2 + sqrt 2)) / 2 :=
by { transitivity cos (pi / 2 ^ 4), congr, norm_num, simp }
lemma sin_pi_div_sixteen : sin (pi / 16) = sqrt (2 - sqrt (2 + sqrt 2)) / 2 :=
by { transitivity sin (pi / 2 ^ 4), congr, norm_num, simp }
lemma cos_pi_div_thirty_two : cos (pi / 32) = sqrt (2 + sqrt (2 + sqrt (2 + sqrt 2))) / 2 :=
by { transitivity cos (pi / 2 ^ 5), congr, norm_num, simp }
lemma sin_pi_div_thirty_two : sin (pi / 32) = sqrt (2 - sqrt (2 + sqrt (2 + sqrt 2))) / 2 :=
by { transitivity sin (pi / 2 ^ 5), congr, norm_num, simp }
end cos_div_pow_two
/-- The type of angles -/
def angle : Type :=
quotient_add_group.quotient (add_subgroup.gmultiples (2 * Ο))
namespace angle
instance angle.add_comm_group : add_comm_group angle :=
quotient_add_group.add_comm_group _
instance : inhabited angle := β¨0β©
instance angle.has_coe : has_coe β angle :=
β¨quotient.mk'β©
@[simp] lemma coe_zero : β(0 : β) = (0 : angle) := rfl
@[simp] lemma coe_add (x y : β) : β(x + y : β) = (βx + βy : angle) := rfl
@[simp] lemma coe_neg (x : β) : β(-x : β) = -(βx : angle) := rfl
@[simp] lemma coe_sub (x y : β) : β(x - y : β) = (βx - βy : angle) := rfl
@[simp, norm_cast] lemma coe_nat_mul_eq_nsmul (x : β) (n : β) :
β((n : β) * x) = n β’β (βx : angle) :=
by simpa using add_monoid_hom.map_nsmul β¨coe, coe_zero, coe_addβ© _ _
@[simp, norm_cast] lemma coe_int_mul_eq_gsmul (x : β) (n : β€) :
β((n : β) * x : β) = n β’β€ (βx : angle) :=
by simpa using add_monoid_hom.map_gsmul β¨coe, coe_zero, coe_addβ© _ _
@[simp] lemma coe_two_pi : β(2 * Ο : β) = (0 : angle) :=
quotient.sound' β¨-1, show (-1 : β€) β’β€ (2 * Ο) = _, by rw [neg_one_gsmul, add_zero]β©
lemma angle_eq_iff_two_pi_dvd_sub {Ο ΞΈ : β} : (ΞΈ : angle) = Ο β β k : β€, ΞΈ - Ο = 2 * Ο * k :=
by simp only [quotient_add_group.eq, add_subgroup.gmultiples_eq_closure,
add_subgroup.mem_closure_singleton, gsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm]
theorem cos_eq_iff_eq_or_eq_neg {ΞΈ Ο : β} : cos ΞΈ = cos Ο β (ΞΈ : angle) = Ο β¨ (ΞΈ : angle) = -Ο :=
begin
split,
{ intro Hcos,
rw [βsub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero, eq_false_intro two_ne_zero,
false_or, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos,
rcases Hcos with β¨n, hnβ© | β¨n, hnβ©,
{ right,
rw [eq_div_iff_mul_eq (@two_ne_zero β _), β sub_eq_iff_eq_add] at hn,
rw [β hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc,
coe_int_mul_eq_gsmul, mul_comm, coe_two_pi, gsmul_zero] },
{ left,
rw [eq_div_iff_mul_eq (@two_ne_zero β _), eq_sub_iff_add_eq] at hn,
rw [β hn, coe_add, mul_assoc,
coe_int_mul_eq_gsmul, mul_comm, coe_two_pi, gsmul_zero, zero_add] } },
{ rw [angle_eq_iff_two_pi_dvd_sub, β coe_neg, angle_eq_iff_two_pi_dvd_sub],
rintro (β¨k, Hβ© | β¨k, Hβ©),
rw [β sub_eq_zero_iff_eq, cos_sub_cos, H, mul_assoc 2 Ο k, mul_div_cancel_left _ (@two_ne_zero β _),
mul_comm Ο _, sin_int_mul_pi, mul_zero],
rw [βsub_eq_zero_iff_eq, cos_sub_cos, β sub_neg_eq_add, H, mul_assoc 2 Ο k,
mul_div_cancel_left _ (@two_ne_zero β _), mul_comm Ο _, sin_int_mul_pi, mul_zero, zero_mul] }
end
theorem sin_eq_iff_eq_or_add_eq_pi {ΞΈ Ο : β} : sin ΞΈ = sin Ο β (ΞΈ : angle) = Ο β¨ (ΞΈ : angle) + Ο = Ο :=
begin
split,
{ intro Hsin, rw [β cos_pi_div_two_sub, β cos_pi_div_two_sub] at Hsin,
cases cos_eq_iff_eq_or_eq_neg.mp Hsin with h h,
{ left, rw coe_sub at h, exact sub_right_inj.1 h },
right, rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub,
sub_add_eq_add_sub, β coe_add, add_halves, sub_sub, sub_eq_zero] at h,
exact h.symm },
{ rw [angle_eq_iff_two_pi_dvd_sub, βeq_sub_iff_add_eq, βcoe_sub, angle_eq_iff_two_pi_dvd_sub],
rintro (β¨k, Hβ© | β¨k, Hβ©),
rw [β sub_eq_zero_iff_eq, sin_sub_sin, H, mul_assoc 2 Ο k, mul_div_cancel_left _ (@two_ne_zero β _),
mul_comm Ο _, sin_int_mul_pi, mul_zero, zero_mul],
have H' : ΞΈ + Ο = (2 * k) * Ο + Ο := by rwa [βsub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add,
mul_assoc, mul_comm Ο _, βmul_assoc] at H,
rw [β sub_eq_zero_iff_eq, sin_sub_sin, H', add_div, mul_assoc 2 _ Ο, mul_div_cancel_left _ (@two_ne_zero β _),
cos_add_pi_div_two, sin_int_mul_pi, neg_zero, mul_zero] }
end
theorem cos_sin_inj {ΞΈ Ο : β} (Hcos : cos ΞΈ = cos Ο) (Hsin : sin ΞΈ = sin Ο) : (ΞΈ : angle) = Ο :=
begin
cases cos_eq_iff_eq_or_eq_neg.mp Hcos with hc hc, { exact hc },
cases sin_eq_iff_eq_or_add_eq_pi.mp Hsin with hs hs, { exact hs },
rw [eq_neg_iff_add_eq_zero, hs] at hc,
cases quotient.exact' hc with n hn, change n β’β€ _ = _ at hn,
rw [β neg_one_mul, add_zero, β sub_eq_zero_iff_eq, gsmul_eq_mul, β mul_assoc, β sub_mul,
mul_eq_zero, eq_false_intro (ne_of_gt pi_pos), or_false, sub_neg_eq_add,
β int.cast_zero, β int.cast_one, β int.cast_bit0, β int.cast_mul, β int.cast_add, int.cast_inj] at hn,
have : (n * 2 + 1) % (2:β€) = 0 % (2:β€) := congr_arg (%(2:β€)) hn,
rw [add_comm, int.add_mul_mod_self] at this,
exact absurd this one_ne_zero
end
end angle
/-- Inverse of the `sin` function, returns values in the range `-Ο / 2 β€ arcsin x` and `arcsin x β€ Ο / 2`.
If the argument is not between `-1` and `1` it defaults to `0` -/
noncomputable def arcsin (x : β) : β :=
if hx : -1 β€ x β§ x β€ 1 then classical.some (exists_sin_eq hx) else 0
lemma arcsin_le_pi_div_two (x : β) : arcsin x β€ Ο / 2 :=
if hx : -1 β€ x β§ x β€ 1
then by rw [arcsin, dif_pos hx]; exact (classical.some_spec (exists_sin_eq hx)).1.2
else by rw [arcsin, dif_neg hx]; exact le_of_lt pi_div_two_pos
lemma neg_pi_div_two_le_arcsin (x : β) : -(Ο / 2) β€ arcsin x :=
if hx : -1 β€ x β§ x β€ 1
then by rw [arcsin, dif_pos hx]; exact (classical.some_spec (exists_sin_eq hx)).1.1
else by rw [arcsin, dif_neg hx]; exact neg_nonpos.2 (le_of_lt pi_div_two_pos)
lemma sin_arcsin {x : β} (hxβ : -1 β€ x) (hxβ : x β€ 1) : sin (arcsin x) = x :=
by rw [arcsin, dif_pos (and.intro hxβ hxβ)];
exact (classical.some_spec (exists_sin_eq β¨hxβ, hxββ©)).2
lemma arcsin_sin {x : β} (hxβ : -(Ο / 2) β€ x) (hxβ : x β€ Ο / 2) : arcsin (sin x) = x :=
sin_inj_of_le_of_le_pi_div_two (neg_pi_div_two_le_arcsin _) (arcsin_le_pi_div_two _) hxβ hxβ
(by rw sin_arcsin (neg_one_le_sin _) (sin_le_one _))
lemma arcsin_inj {x y : β} (hxβ : -1 β€ x) (hxβ : x β€ 1) (hyβ : -1 β€ y) (hyβ : y β€ 1)
(hxy : arcsin x = arcsin y) : x = y :=
by rw [β sin_arcsin hxβ hxβ, β sin_arcsin hyβ hyβ, hxy]
@[simp] lemma arcsin_zero : arcsin 0 = 0 :=
sin_inj_of_le_of_le_pi_div_two
(neg_pi_div_two_le_arcsin _)
(arcsin_le_pi_div_two _)
(neg_nonpos.2 (le_of_lt pi_div_two_pos))
(le_of_lt pi_div_two_pos)
(by rw [sin_arcsin, sin_zero]; norm_num)
@[simp] lemma arcsin_one : arcsin 1 = Ο / 2 :=
sin_inj_of_le_of_le_pi_div_two
(neg_pi_div_two_le_arcsin _)
(arcsin_le_pi_div_two _)
(by linarith [pi_pos])
(le_refl _)
(by rw [sin_arcsin, sin_pi_div_two]; norm_num)
@[simp] lemma arcsin_neg (x : β) : arcsin (-x) = -arcsin x :=
if h : -1 β€ x β§ x β€ 1 then
have -1 β€ -x β§ -x β€ 1, by rwa [neg_le_neg_iff, neg_le, and.comm],
sin_inj_of_le_of_le_pi_div_two
(neg_pi_div_two_le_arcsin _)
(arcsin_le_pi_div_two _)
(neg_le_neg (arcsin_le_pi_div_two _))
(neg_le.1 (neg_pi_div_two_le_arcsin _))
(by rw [sin_arcsin this.1 this.2, sin_neg, sin_arcsin h.1 h.2])
else
have Β¬(-1 β€ -x β§ -x β€ 1) := by rwa [neg_le_neg_iff, neg_le, and.comm],
by rw [arcsin, arcsin, dif_neg h, dif_neg this, neg_zero]
@[simp] lemma arcsin_neg_one : arcsin (-1) = -(Ο / 2) := by simp
lemma arcsin_nonneg {x : β} (hx : 0 β€ x) : 0 β€ arcsin x :=
if hxβ : x β€ 1 then
not_lt.1 (Ξ» h, not_lt.2 hx begin
have := sin_lt_sin_of_le_of_le_pi_div_two
(neg_pi_div_two_le_arcsin _) (le_of_lt pi_div_two_pos) h,
rw [real.sin_arcsin, sin_zero] at this; linarith
end)
else by rw [arcsin, dif_neg]; simp [hxβ]
lemma arcsin_eq_zero_iff {x : β} (hxβ : -1 β€ x) (hxβ : x β€ 1) : arcsin x = 0 β x = 0 :=
β¨Ξ» h, have sin (arcsin x) = 0, by simp [h],
by rwa [sin_arcsin hxβ hxβ] at this,
Ξ» h, by simp [h]β©
lemma arcsin_pos {x : β} (hxβ : 0 < x) (hxβ : x β€ 1) : 0 < arcsin x :=
lt_of_le_of_ne (arcsin_nonneg (le_of_lt hxβ))
(ne.symm (mt (arcsin_eq_zero_iff (by linarith) hxβ).1 (ne_of_lt hxβ).symm))
lemma arcsin_nonpos {x : β} (hx : x β€ 0) : arcsin x β€ 0 :=
neg_nonneg.1 (arcsin_neg x βΈ arcsin_nonneg (neg_nonneg.2 hx))
/-- Inverse of the `cos` function, returns values in the range `0 β€ arccos x` and `arccos x β€ Ο`.
If the argument is not between `-1` and `1` it defaults to `Ο / 2` -/
noncomputable def arccos (x : β) : β :=
Ο / 2 - arcsin x
lemma arccos_eq_pi_div_two_sub_arcsin (x : β) : arccos x = Ο / 2 - arcsin x := rfl
lemma arcsin_eq_pi_div_two_sub_arccos (x : β) : arcsin x = Ο / 2 - arccos x :=
by simp [sub_eq_add_neg, arccos]
lemma arccos_le_pi (x : β) : arccos x β€ Ο :=
by unfold arccos; linarith [neg_pi_div_two_le_arcsin x]
lemma arccos_nonneg (x : β) : 0 β€ arccos x :=
by unfold arccos; linarith [arcsin_le_pi_div_two x]
lemma cos_arccos {x : β} (hxβ : -1 β€ x) (hxβ : x β€ 1) : cos (arccos x) = x :=
by rw [arccos, cos_pi_div_two_sub, sin_arcsin hxβ hxβ]
lemma arccos_cos {x : β} (hxβ : 0 β€ x) (hxβ : x β€ Ο) : arccos (cos x) = x :=
by rw [arccos, β sin_pi_div_two_sub, arcsin_sin]; simp [sub_eq_add_neg]; linarith
lemma arccos_inj {x y : β} (hxβ : -1 β€ x) (hxβ : x β€ 1) (hyβ : -1 β€ y) (hyβ : y β€ 1)
(hxy : arccos x = arccos y) : x = y :=
arcsin_inj hxβ hxβ hyβ hyβ $ by simp [arccos, *] at *
@[simp] lemma arccos_zero : arccos 0 = Ο / 2 := by simp [arccos]
@[simp] lemma arccos_one : arccos 1 = 0 := by simp [arccos]
@[simp] lemma arccos_neg_one : arccos (-1) = Ο := by simp [arccos, add_halves]
lemma arccos_neg (x : β) : arccos (-x) = Ο - arccos x :=
by rw [β add_halves Ο, arccos, arcsin_neg, arccos, add_sub_assoc, sub_sub_self]; simp
lemma cos_arcsin_nonneg (x : β) : 0 β€ cos (arcsin x) :=
cos_nonneg_of_mem_Icc
(neg_pi_div_two_le_arcsin _) (arcsin_le_pi_div_two _)
lemma cos_arcsin {x : β} (hxβ : -1 β€ x) (hxβ : x β€ 1) : cos (arcsin x) = sqrt (1 - x ^ 2) :=
have sin (arcsin x) ^ 2 + cos (arcsin x) ^ 2 = 1 := sin_sq_add_cos_sq (arcsin x),
begin
rw [β eq_sub_iff_add_eq', β sqrt_inj (pow_two_nonneg _) (sub_nonneg.2 (sin_sq_le_one (arcsin x))),
pow_two, sqrt_mul_self (cos_arcsin_nonneg _)] at this,
rw [this, sin_arcsin hxβ hxβ],
end
lemma sin_arccos {x : β} (hxβ : -1 β€ x) (hxβ : x β€ 1) : sin (arccos x) = sqrt (1 - x ^ 2) :=
by rw [arccos_eq_pi_div_two_sub_arcsin, sin_pi_div_two_sub, cos_arcsin hxβ hxβ]
lemma abs_div_sqrt_one_add_lt (x : β) : abs (x / sqrt (1 + x ^ 2)) < 1 :=
have hβ : 0 < 1 + x ^ 2, from add_pos_of_pos_of_nonneg zero_lt_one (pow_two_nonneg _),
have hβ : 0 < sqrt (1 + x ^ 2), from sqrt_pos.2 hβ,
by rw [abs_div, div_lt_iff (abs_pos_of_pos hβ), one_mul,
mul_self_lt_mul_self_iff (abs_nonneg x) (abs_nonneg _),
β abs_mul, β abs_mul, mul_self_sqrt (add_nonneg zero_le_one (pow_two_nonneg _)),
abs_of_nonneg (mul_self_nonneg x), abs_of_nonneg (le_of_lt hβ), pow_two, add_comm];
exact lt_add_one _
lemma div_sqrt_one_add_lt_one (x : β) : x / sqrt (1 + x ^ 2) < 1 :=
(abs_lt.1 (abs_div_sqrt_one_add_lt _)).2
lemma neg_one_lt_div_sqrt_one_add (x : β) : -1 < x / sqrt (1 + x ^ 2) :=
(abs_lt.1 (abs_div_sqrt_one_add_lt _)).1
@[simp] lemma tan_pi_div_four : tan (Ο / 4) = 1 :=
begin
rw [tan_eq_sin_div_cos, cos_pi_div_four, sin_pi_div_four],
have h : (sqrt 2) / 2 > 0 := by cancel_denoms,
exact div_self (ne_of_gt h),
end
lemma tan_pos_of_pos_of_lt_pi_div_two {x : β} (h0x : 0 < x) (hxp : x < Ο / 2) : 0 < tan x :=
by rw tan_eq_sin_div_cos; exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith))
(cos_pos_of_mem_Ioo (by linarith) hxp)
lemma tan_nonneg_of_nonneg_of_le_pi_div_two {x : β} (h0x : 0 β€ x) (hxp : x β€ Ο / 2) : 0 β€ tan x :=
match lt_or_eq_of_le h0x, lt_or_eq_of_le hxp with
| or.inl hx0, or.inl hxp := le_of_lt (tan_pos_of_pos_of_lt_pi_div_two hx0 hxp)
| or.inl hx0, or.inr hxp := by simp [hxp, tan_eq_sin_div_cos]
| or.inr hx0, _ := by simp [hx0.symm]
end
lemma tan_neg_of_neg_of_pi_div_two_lt {x : β} (hx0 : x < 0) (hpx : -(Ο / 2) < x) : tan x < 0 :=
neg_pos.1 (tan_neg x βΈ tan_pos_of_pos_of_lt_pi_div_two (by linarith) (by linarith [pi_pos]))
lemma tan_nonpos_of_nonpos_of_neg_pi_div_two_le {x : β} (hx0 : x β€ 0) (hpx : -(Ο / 2) β€ x) : tan x β€ 0 :=
neg_nonneg.1 (tan_neg x βΈ tan_nonneg_of_nonneg_of_le_pi_div_two (by linarith) (by linarith [pi_pos]))
lemma tan_lt_tan_of_nonneg_of_lt_pi_div_two {x y : β} (hxβ : 0 β€ x) (hyβ : y < Ο / 2) (hxy : x < y) :
tan x < tan y :=
begin
rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos],
exact div_lt_div
(sin_lt_sin_of_le_of_le_pi_div_two (by linarith) (le_of_lt hyβ) hxy)
(cos_le_cos_of_nonneg_of_le_pi hxβ (by linarith) (le_of_lt hxy))
(sin_nonneg_of_nonneg_of_le_pi (by linarith) (by linarith))
(cos_pos_of_mem_Ioo (by linarith) hyβ)
end
lemma tan_lt_tan_of_lt_of_lt_pi_div_two {x y : β} (hxβ : -(Ο / 2) < x)
(hyβ : y < Ο / 2) (hxy : x < y) : tan x < tan y :=
match le_total x 0, le_total y 0 with
| or.inl hx0, or.inl hy0 := neg_lt_neg_iff.1 $ by rw [β tan_neg, β tan_neg]; exact
tan_lt_tan_of_nonneg_of_lt_pi_div_two (neg_nonneg.2 hy0)
(neg_lt.2 hxβ) (neg_lt_neg hxy)
| or.inl hx0, or.inr hy0 := (lt_or_eq_of_le hy0).elim
(Ξ» hy0, calc tan x β€ 0 : tan_nonpos_of_nonpos_of_neg_pi_div_two_le hx0 (le_of_lt hxβ)
... < tan y : tan_pos_of_pos_of_lt_pi_div_two hy0 hyβ)
(Ξ» hy0, by rw [β hy0, tan_zero]; exact
tan_neg_of_neg_of_pi_div_two_lt (hy0.symm βΈ hxy) hxβ)
| or.inr hx0, or.inl hy0 := by linarith
| or.inr hx0, or.inr hy0 := tan_lt_tan_of_nonneg_of_lt_pi_div_two hx0 hyβ hxy
end
lemma tan_inj_of_lt_of_lt_pi_div_two {x y : β} (hxβ : -(Ο / 2) < x) (hxβ : x < Ο / 2)
(hyβ : -(Ο / 2) < y) (hyβ : y < Ο / 2) (hxy : tan x = tan y) : x = y :=
match lt_trichotomy x y with
| or.inl h := absurd (tan_lt_tan_of_lt_of_lt_pi_div_two hxβ hyβ h) (by rw hxy; exact lt_irrefl _)
| or.inr (or.inl h) := h
| or.inr (or.inr h) := absurd (tan_lt_tan_of_lt_of_lt_pi_div_two hyβ hxβ h) (by rw hxy; exact lt_irrefl _)
end
/-- Inverse of the `tan` function, returns values in the range `-Ο / 2 < arctan x` and `arctan x < Ο / 2` -/
noncomputable def arctan (x : β) : β :=
arcsin (x / sqrt (1 + x ^ 2))
lemma sin_arctan (x : β) : sin (arctan x) = x / sqrt (1 + x ^ 2) :=
sin_arcsin (le_of_lt (neg_one_lt_div_sqrt_one_add _)) (le_of_lt (div_sqrt_one_add_lt_one _))
lemma cos_arctan (x : β) : cos (arctan x) = 1 / sqrt (1 + x ^ 2) :=
have hβ : (0 : β) < 1 + x ^ 2,
from add_pos_of_pos_of_nonneg zero_lt_one (pow_two_nonneg _),
have hβ : (x / sqrt (1 + x ^ 2)) ^ 2 < 1,
by rw [pow_two, β abs_mul_self, _root_.abs_mul];
exact mul_lt_one_of_nonneg_of_lt_one_left (abs_nonneg _)
(abs_div_sqrt_one_add_lt _) (le_of_lt (abs_div_sqrt_one_add_lt _)),
by rw [arctan, cos_arcsin (le_of_lt (neg_one_lt_div_sqrt_one_add _)) (le_of_lt (div_sqrt_one_add_lt_one _)),
one_div, β sqrt_inv, sqrt_inj (sub_nonneg.2 (le_of_lt hβ)) (inv_nonneg.2 (le_of_lt hβ)),
div_pow, pow_two (sqrt _), mul_self_sqrt (le_of_lt hβ),
β mul_right_inj' (ne.symm (ne_of_lt hβ)), mul_sub,
mul_div_cancel' _ (ne.symm (ne_of_lt hβ)), mul_inv_cancel (ne.symm (ne_of_lt hβ))];
simp
lemma tan_arctan (x : β) : tan (arctan x) = x :=
by rw [tan_eq_sin_div_cos, sin_arctan, cos_arctan, div_div_div_div_eq, mul_one,
mul_div_assoc,
div_self (mt sqrt_eq_zero'.1 (not_le_of_gt (add_pos_of_pos_of_nonneg zero_lt_one (pow_two_nonneg x)))),
mul_one]
lemma arctan_lt_pi_div_two (x : β) : arctan x < Ο / 2 :=
lt_of_le_of_ne (arcsin_le_pi_div_two _)
(Ξ» h, ne_of_lt (div_sqrt_one_add_lt_one x) $
by rw [β sin_arcsin (le_of_lt (neg_one_lt_div_sqrt_one_add _))
(le_of_lt (div_sqrt_one_add_lt_one _)), β arctan, h, sin_pi_div_two])
lemma neg_pi_div_two_lt_arctan (x : β) : -(Ο / 2) < arctan x :=
lt_of_le_of_ne (neg_pi_div_two_le_arcsin _)
(Ξ» h, ne_of_lt (neg_one_lt_div_sqrt_one_add x) $
by rw [β sin_arcsin (le_of_lt (neg_one_lt_div_sqrt_one_add _))
(le_of_lt (div_sqrt_one_add_lt_one _)), β arctan, β h, sin_neg, sin_pi_div_two])
lemma arctan_mem_Ioo (x : β) : arctan x β Ioo (-(Ο / 2)) (Ο / 2) :=
β¨neg_pi_div_two_lt_arctan x, arctan_lt_pi_div_two xβ©
lemma tan_surjective : function.surjective tan :=
function.right_inverse.surjective tan_arctan
lemma arctan_tan {x : β} (hxβ : -(Ο / 2) < x) (hxβ : x < Ο / 2) : arctan (tan x) = x :=
tan_inj_of_lt_of_lt_pi_div_two (neg_pi_div_two_lt_arctan _)
(arctan_lt_pi_div_two _) hxβ hxβ (by rw tan_arctan)
@[simp] lemma arctan_zero : arctan 0 = 0 :=
by simp [arctan]
@[simp] lemma arctan_one : arctan 1 = Ο / 4 :=
begin
refine tan_inj_of_lt_of_lt_pi_div_two (neg_pi_div_two_lt_arctan 1) (arctan_lt_pi_div_two 1) _ _ _;
linarith [pi_pos, tan_arctan 1, tan_pi_div_four],
end
@[simp] lemma arctan_neg (x : β) : arctan (-x) = - arctan x :=
by simp [arctan, neg_div]
end real
namespace complex
open_locale real
/-- `arg` returns values in the range (-Ο, Ο], such that for `x β 0`,
`sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,
`arg 0` defaults to `0` -/
noncomputable def arg (x : β) : β :=
if 0 β€ x.re
then real.arcsin (x.im / x.abs)
else if 0 β€ x.im
then real.arcsin ((-x).im / x.abs) + Ο
else real.arcsin ((-x).im / x.abs) - Ο
lemma arg_le_pi (x : β) : arg x β€ Ο :=
if hxβ : 0 β€ x.re
then by rw [arg, if_pos hxβ];
exact le_trans (real.arcsin_le_pi_div_two _) (le_of_lt (half_lt_self real.pi_pos))
else
have hx : x β 0, from Ξ» h, by simpa [h, lt_irrefl] using hxβ,
if hxβ : 0 β€ x.im
then by rw [arg, if_neg hxβ, if_pos hxβ];
exact le_sub_iff_add_le.1 (by rw sub_self;
exact real.arcsin_nonpos (by rw [neg_im, neg_div, neg_nonpos]; exact div_nonneg hxβ (abs_nonneg _)))
else by rw [arg, if_neg hxβ, if_neg hxβ];
exact sub_le_iff_le_add.2 (le_trans (real.arcsin_le_pi_div_two _)
(by linarith [real.pi_pos]))
lemma neg_pi_lt_arg (x : β) : -Ο < arg x :=
if hxβ : 0 β€ x.re
then by rw [arg, if_pos hxβ];
exact lt_of_lt_of_le (neg_lt_neg (half_lt_self real.pi_pos)) (real.neg_pi_div_two_le_arcsin _)
else
have hx : x β 0, from Ξ» h, by simpa [h, lt_irrefl] using hxβ,
if hxβ : 0 β€ x.im
then by rw [arg, if_neg hxβ, if_pos hxβ];
exact sub_lt_iff_lt_add.1
(lt_of_lt_of_le (by linarith [real.pi_pos]) (real.neg_pi_div_two_le_arcsin _))
else by rw [arg, if_neg hxβ, if_neg hxβ];
exact lt_sub_iff_add_lt.2 (by rw neg_add_self;
exact real.arcsin_pos (by rw [neg_im]; exact div_pos (neg_pos.2 (lt_of_not_ge hxβ))
(abs_pos.2 hx)) (by rw [β abs_neg x]; exact (abs_le.1 (abs_im_div_abs_le_one _)).2))
lemma arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg {x : β} (hxr : x.re < 0) (hxi : 0 β€ x.im) :
arg x = arg (-x) + Ο :=
have 0 β€ (-x).re, from le_of_lt $ by simpa [neg_pos],
by rw [arg, arg, if_neg (not_le.2 hxr), if_pos this, if_pos hxi, abs_neg]
lemma arg_eq_arg_neg_sub_pi_of_im_neg_of_re_neg {x : β} (hxr : x.re < 0) (hxi : x.im < 0) :
arg x = arg (-x) - Ο :=
have 0 β€ (-x).re, from le_of_lt $ by simpa [neg_pos],
by rw [arg, arg, if_neg (not_le.2 hxr), if_neg (not_le.2 hxi), if_pos this, abs_neg]
@[simp] lemma arg_zero : arg 0 = 0 :=
by simp [arg, le_refl]
@[simp] lemma arg_one : arg 1 = 0 :=
by simp [arg, zero_le_one]
@[simp] lemma arg_neg_one : arg (-1) = Ο :=
by simp [arg, le_refl, not_le.2 (@zero_lt_one β _)]
@[simp] lemma arg_I : arg I = Ο / 2 :=
by simp [arg, le_refl]
@[simp] lemma arg_neg_I : arg (-I) = -(Ο / 2) :=
by simp [arg, le_refl]
lemma sin_arg (x : β) : real.sin (arg x) = x.im / x.abs :=
by unfold arg; split_ifs;
simp [sub_eq_add_neg, arg, real.sin_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1
(abs_le.1 (abs_im_div_abs_le_one x)).2, real.sin_add, neg_div, real.arcsin_neg,
real.sin_neg]
private lemma cos_arg_of_re_nonneg {x : β} (hx : x β 0) (hxr : 0 β€ x.re) : real.cos (arg x) = x.re / x.abs :=
have 0 β€ 1 - (x.im / abs x) ^ 2,
from sub_nonneg.2 $ by rw [pow_two, β _root_.abs_mul_self, _root_.abs_mul, β pow_two];
exact pow_le_one _ (_root_.abs_nonneg _) (abs_im_div_abs_le_one _),
by rw [eq_div_iff_mul_eq (mt abs_eq_zero.1 hx), β real.mul_self_sqrt (abs_nonneg x),
arg, if_pos hxr, real.cos_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1
(abs_le.1 (abs_im_div_abs_le_one x)).2, β real.sqrt_mul (abs_nonneg _), β real.sqrt_mul this,
sub_mul, div_pow, β pow_two, div_mul_cancel _ (pow_ne_zero 2 (mt abs_eq_zero.1 hx)),
one_mul, pow_two, mul_self_abs, norm_sq, pow_two, add_sub_cancel, real.sqrt_mul_self hxr]
lemma cos_arg {x : β} (hx : x β 0) : real.cos (arg x) = x.re / x.abs :=
if hxr : 0 β€ x.re then cos_arg_of_re_nonneg hx hxr
else
have 0 β€ (-x).re, from le_of_lt $ by simpa [neg_pos] using hxr,
if hxi : 0 β€ x.im
then have 0 β€ (-x).re, from le_of_lt $ by simpa [neg_pos] using hxr,
by rw [arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg (not_le.1 hxr) hxi, real.cos_add_pi,
cos_arg_of_re_nonneg (neg_ne_zero.2 hx) this];
simp [neg_div]
else by rw [arg_eq_arg_neg_sub_pi_of_im_neg_of_re_neg (not_le.1 hxr) (not_le.1 hxi)];
simp [sub_eq_add_neg, real.cos_add, neg_div, cos_arg_of_re_nonneg (neg_ne_zero.2 hx) this]
lemma tan_arg {x : β} : real.tan (arg x) = x.im / x.re :=
begin
by_cases h : x = 0,
{ simp only [h, zero_div, complex.zero_im, complex.arg_zero, real.tan_zero, complex.zero_re] },
rw [real.tan_eq_sin_div_cos, sin_arg, cos_arg h,
div_div_div_cancel_right _ (mt abs_eq_zero.1 h)]
end
lemma arg_cos_add_sin_mul_I {x : β} (hxβ : -Ο < x) (hxβ : x β€ Ο) :
arg (cos x + sin x * I) = x :=
if hxβ : -(Ο / 2) β€ x β§ x β€ Ο / 2
then
have hxβ : 0 β€ (cos x + sin x * I).re,
by simp; exact real.cos_nonneg_of_mem_Icc hxβ.1 hxβ.2,
by rw [arg, if_pos hxβ];
simp [abs_cos_add_sin_mul_I, sin_of_real_re, real.arcsin_sin hxβ.1 hxβ.2]
else if hxβ : x < -(Ο / 2)
then
have hxβ
: Β¬0 β€ (cos x + sin x * I).re :=
suffices Β¬ 0 β€ real.cos x, by simpa,
not_le.2 $ by rw β real.cos_neg;
apply real.cos_neg_of_pi_div_two_lt_of_lt; linarith,
have hxβ : Β¬0 β€ (cos βx + sin βx * I).im :=
suffices real.sin x < 0, by simpa,
by apply real.sin_neg_of_neg_of_neg_pi_lt; linarith,
suffices -Ο + -real.arcsin (real.sin x) = x,
by rw [arg, if_neg hxβ
, if_neg hxβ];
simpa [sub_eq_add_neg, add_comm, abs_cos_add_sin_mul_I, sin_of_real_re],
by rw [β real.arcsin_neg, β real.sin_add_pi, real.arcsin_sin]; try {simp [add_left_comm]}; linarith
else
have hxβ
: Ο / 2 < x, by cases not_and_distrib.1 hxβ; linarith,
have hxβ : Β¬0 β€ (cos x + sin x * I).re :=
suffices Β¬0 β€ real.cos x, by simpa,
not_le.2 $ by apply real.cos_neg_of_pi_div_two_lt_of_lt; linarith,
have hxβ : 0 β€ (cos x + sin x * I).im :=
suffices 0 β€ real.sin x, by simpa,
by apply real.sin_nonneg_of_nonneg_of_le_pi; linarith,
suffices Ο - real.arcsin (real.sin x) = x,
by rw [arg, if_neg hxβ, if_pos hxβ];
simpa [sub_eq_add_neg, add_comm, abs_cos_add_sin_mul_I, sin_of_real_re],
by rw [β real.sin_pi_sub, real.arcsin_sin]; simp [sub_eq_add_neg]; linarith
lemma arg_eq_arg_iff {x y : β} (hx : x β 0) (hy : y β 0) :
arg x = arg y β (abs y / abs x : β) * x = y :=
have hax : abs x β 0, from (mt abs_eq_zero.1 hx),
have hay : abs y β 0, from (mt abs_eq_zero.1 hy),
β¨Ξ» h,
begin
have hcos := congr_arg real.cos h,
rw [cos_arg hx, cos_arg hy, div_eq_div_iff hax hay] at hcos,
have hsin := congr_arg real.sin h,
rw [sin_arg, sin_arg, div_eq_div_iff hax hay] at hsin,
apply complex.ext,
{ rw [mul_re, β of_real_div, of_real_re, of_real_im, zero_mul, sub_zero, mul_comm,
β mul_div_assoc, hcos, mul_div_cancel _ hax] },
{ rw [mul_im, β of_real_div, of_real_re, of_real_im, zero_mul, add_zero,
mul_comm, β mul_div_assoc, hsin, mul_div_cancel _ hax] }
end,
Ξ» h,
have hre : abs (y / x) * x.re = y.re,
by rw β of_real_div at h;
simpa [-of_real_div] using congr_arg re h,
have hre' : abs (x / y) * y.re = x.re,
by rw [β hre, abs_div, abs_div, β mul_assoc, div_mul_div,
mul_comm (abs _), div_self (mul_ne_zero hay hax), one_mul],
have him : abs (y / x) * x.im = y.im,
by rw β of_real_div at h;
simpa [-of_real_div] using congr_arg im h,
have him' : abs (x / y) * y.im = x.im,
by rw [β him, abs_div, abs_div, β mul_assoc, div_mul_div,
mul_comm (abs _), div_self (mul_ne_zero hay hax), one_mul],
have hxya : x.im / abs x = y.im / abs y,
by rw [β him, abs_div, mul_comm, β mul_div_comm, mul_div_cancel_left _ hay],
have hnxya : (-x).im / abs x = (-y).im / abs y,
by rw [neg_im, neg_im, neg_div, neg_div, hxya],
if hxr : 0 β€ x.re
then
have hyr : 0 β€ y.re, from hre βΈ mul_nonneg (abs_nonneg _) hxr,
by simp [arg, *] at *
else
have hyr : Β¬ 0 β€ y.re, from Ξ» hyr, hxr $ hre' βΈ mul_nonneg (abs_nonneg _) hyr,
if hxi : 0 β€ x.im
then
have hyi : 0 β€ y.im, from him βΈ mul_nonneg (abs_nonneg _) hxi,
by simp [arg, *] at *
else
have hyi : Β¬ 0 β€ y.im, from Ξ» hyi, hxi $ him' βΈ mul_nonneg (abs_nonneg _) hyi,
by simp [arg, *] at *β©
lemma arg_real_mul (x : β) {r : β} (hr : 0 < r) : arg (r * x) = arg x :=
if hx : x = 0 then by simp [hx]
else (arg_eq_arg_iff (mul_ne_zero (of_real_ne_zero.2 (ne_of_lt hr).symm) hx) hx).2 $
by rw [abs_mul, abs_of_nonneg (le_of_lt hr), β mul_assoc,
of_real_mul, mul_comm (r : β), β div_div_eq_div_mul,
div_mul_cancel _ (of_real_ne_zero.2 (ne_of_lt hr).symm),
div_self (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), one_mul]
lemma ext_abs_arg {x y : β} (hβ : x.abs = y.abs) (hβ : x.arg = y.arg) : x = y :=
if hy : y = 0 then by simp * at *
else have hx : x β 0, from Ξ» hx, by simp [*, eq_comm] at *,
by rwa [arg_eq_arg_iff hx hy, hβ, div_self (of_real_ne_zero.2 (mt abs_eq_zero.1 hy)), one_mul] at hβ
lemma arg_of_real_of_nonneg {x : β} (hx : 0 β€ x) : arg x = 0 :=
by simp [arg, hx]
lemma arg_of_real_of_neg {x : β} (hx : x < 0) : arg x = Ο :=
by rw [arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg, β of_real_neg, arg_of_real_of_nonneg];
simp [*, le_iff_eq_or_lt, lt_neg]
/-- Inverse of the `exp` function. Returns values such that `(log x).im > - Ο` and `(log x).im β€ Ο`.
`log 0 = 0`-/
noncomputable def log (x : β) : β := x.abs.log + arg x * I
lemma log_re (x : β) : x.log.re = x.abs.log := by simp [log]
lemma log_im (x : β) : x.log.im = x.arg := by simp [log]
lemma exp_log {x : β} (hx : x β 0) : exp (log x) = x :=
by rw [log, exp_add_mul_I, β of_real_sin, sin_arg, β of_real_cos, cos_arg hx,
β of_real_exp, real.exp_log (abs_pos.2 hx), mul_add, of_real_div, of_real_div,
mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), β mul_assoc,
mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), re_add_im]
lemma exp_inj_of_neg_pi_lt_of_le_pi {x y : β} (hxβ : -Ο < x.im) (hxβ : x.im β€ Ο)
(hyβ : - Ο < y.im) (hyβ : y.im β€ Ο) (hxy : exp x = exp y) : x = y :=
by rw [exp_eq_exp_re_mul_sin_add_cos, exp_eq_exp_re_mul_sin_add_cos y] at hxy;
exact complex.ext
(real.exp_injective $
by simpa [abs_mul, abs_cos_add_sin_mul_I] using congr_arg complex.abs hxy)
(by simpa [(of_real_exp _).symm, - of_real_exp, arg_real_mul _ (real.exp_pos _),
arg_cos_add_sin_mul_I hxβ hxβ, arg_cos_add_sin_mul_I hyβ hyβ] using congr_arg arg hxy)
lemma log_exp {x : β} (hxβ : -Ο < x.im) (hxβ: x.im β€ Ο) : log (exp x) = x :=
exp_inj_of_neg_pi_lt_of_le_pi
(by rw log_im; exact neg_pi_lt_arg _)
(by rw log_im; exact arg_le_pi _)
hxβ hxβ (by rw [exp_log (exp_ne_zero _)])
lemma of_real_log {x : β} (hx : 0 β€ x) : (x.log : β) = log x :=
complex.ext
(by rw [log_re, of_real_re, abs_of_nonneg hx])
(by rw [of_real_im, log_im, arg_of_real_of_nonneg hx])
lemma log_of_real_re (x : β) : (log (x : β)).re = real.log x := by simp [log_re]
@[simp] lemma log_zero : log 0 = 0 := by simp [log]
@[simp] lemma log_one : log 1 = 0 := by simp [log]
lemma log_neg_one : log (-1) = Ο * I := by simp [log]
lemma log_I : log I = Ο / 2 * I := by simp [log]
lemma log_neg_I : log (-I) = -(Ο / 2) * I := by simp [log]
lemma exp_eq_one_iff {x : β} : exp x = 1 β β n : β€, x = n * ((2 * Ο) * I) :=
have real.exp (x.re) * real.cos (x.im) = 1 β real.cos x.im β -1,
from Ξ» hβ hβ, begin
rw [hβ, mul_neg_eq_neg_mul_symm, mul_one, neg_eq_iff_neg_eq] at hβ,
have := real.exp_pos x.re,
rw β hβ at this,
exact absurd this (by norm_num)
end,
calc exp x = 1 β (exp x).re = 1 β§ (exp x).im = 0 : by simp [complex.ext_iff]
... β real.cos x.im = 1 β§ real.sin x.im = 0 β§ x.re = 0 :
begin
rw exp_eq_exp_re_mul_sin_add_cos,
simp [complex.ext_iff, cos_of_real_re, sin_of_real_re, exp_of_real_re,
real.exp_ne_zero],
split; finish [real.sin_eq_zero_iff_cos_eq]
end
... β (β n : β€, βn * (2 * Ο) = x.im) β§ (β n : β€, βn * Ο = x.im) β§ x.re = 0 :
by rw [real.sin_eq_zero_iff, real.cos_eq_one_iff]
... β β n : β€, x = n * ((2 * Ο) * I) :
β¨Ξ» β¨β¨n, hnβ©, β¨m, hmβ©, hβ©, β¨n, by simp [complex.ext_iff, hn.symm, h]β©,
Ξ» β¨n, hnβ©, β¨β¨n, by simp [hn]β©, β¨2 * n, by simp [hn, mul_comm, mul_assoc, mul_left_comm]β©,
by simp [hn]β©β©
lemma exp_eq_exp_iff_exp_sub_eq_one {x y : β} : exp x = exp y β exp (x - y) = 1 :=
by rw [exp_sub, div_eq_one_iff_eq (exp_ne_zero _)]
lemma exp_eq_exp_iff_exists_int {x y : β} : exp x = exp y β β n : β€, x = y + n * ((2 * Ο) * I) :=
by simp only [exp_eq_exp_iff_exp_sub_eq_one, exp_eq_one_iff, sub_eq_iff_eq_add']
@[simp] lemma cos_pi_div_two : cos (Ο / 2) = 0 :=
calc cos (Ο / 2) = real.cos (Ο / 2) : by rw [of_real_cos]; simp
... = 0 : by simp
@[simp] lemma sin_pi_div_two : sin (Ο / 2) = 1 :=
calc sin (Ο / 2) = real.sin (Ο / 2) : by rw [of_real_sin]; simp
... = 1 : by simp
@[simp] lemma sin_pi : sin Ο = 0 :=
by rw [β of_real_sin, real.sin_pi]; simp
@[simp] lemma cos_pi : cos Ο = -1 :=
by rw [β of_real_cos, real.cos_pi]; simp
@[simp] lemma sin_two_pi : sin (2 * Ο) = 0 :=
by simp [two_mul, sin_add]
@[simp] lemma cos_two_pi : cos (2 * Ο) = 1 :=
by simp [two_mul, cos_add]
lemma sin_add_pi (x : β) : sin (x + Ο) = -sin x :=
by simp [sin_add]
lemma sin_add_two_pi (x : β) : sin (x + 2 * Ο) = sin x :=
by simp [sin_add_pi, sin_add, sin_two_pi, cos_two_pi]
lemma cos_add_two_pi (x : β) : cos (x + 2 * Ο) = cos x :=
by simp [cos_add, cos_two_pi, sin_two_pi]
lemma sin_pi_sub (x : β) : sin (Ο - x) = sin x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi (x : β) : cos (x + Ο) = -cos x :=
by simp [cos_add]
lemma cos_pi_sub (x : β) : cos (Ο - x) = -cos x :=
by simp [sub_eq_add_neg, cos_add]
lemma sin_add_pi_div_two (x : β) : sin (x + Ο / 2) = cos x :=
by simp [sin_add]
lemma sin_sub_pi_div_two (x : β) : sin (x - Ο / 2) = -cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma sin_pi_div_two_sub (x : β) : sin (Ο / 2 - x) = cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi_div_two (x : β) : cos (x + Ο / 2) = -sin x :=
by simp [cos_add]
lemma cos_sub_pi_div_two (x : β) : cos (x - Ο / 2) = sin x :=
by simp [sub_eq_add_neg, cos_add]
lemma cos_pi_div_two_sub (x : β) : cos (Ο / 2 - x) = sin x :=
by rw [β cos_neg, neg_sub, cos_sub_pi_div_two]
lemma sin_nat_mul_pi (n : β) : sin (n * Ο) = 0 :=
by induction n; simp [add_mul, sin_add, *]
lemma sin_int_mul_pi (n : β€) : sin (n * Ο) = 0 :=
by cases n; simp [add_mul, sin_add, *, sin_nat_mul_pi]
lemma cos_nat_mul_two_pi (n : β) : cos (n * (2 * Ο)) = 1 :=
by induction n; simp [*, mul_add, cos_add, add_mul, cos_two_pi, sin_two_pi]
lemma cos_int_mul_two_pi (n : β€) : cos (n * (2 * Ο)) = 1 :=
by cases n; simp only [cos_nat_mul_two_pi, int.of_nat_eq_coe,
int.neg_succ_of_nat_coe, int.cast_coe_nat, int.cast_neg,
(neg_mul_eq_neg_mul _ _).symm, cos_neg]
lemma cos_int_mul_two_pi_add_pi (n : β€) : cos (n * (2 * Ο) + Ο) = -1 :=
by simp [cos_add, sin_add, cos_int_mul_two_pi]
lemma exp_pi_mul_I : exp (Ο * I) = -1 := by { rw exp_mul_I, simp, }
theorem cos_eq_zero_iff {ΞΈ : β} : cos ΞΈ = 0 β β k : β€, ΞΈ = (2 * k + 1) * Ο / 2 :=
begin
have h : (exp (ΞΈ * I) + exp (-ΞΈ * I)) / 2 = 0 β exp (2 * ΞΈ * I) = -1,
{ rw [@div_eq_iff _ _ (exp (ΞΈ * I) + exp (-ΞΈ * I)) 2 0 (by norm_num), zero_mul, add_eq_zero_iff_eq_neg,
neg_eq_neg_one_mul (exp (-ΞΈ * I)), β div_eq_iff (exp_ne_zero (-ΞΈ * I)), β exp_sub],
field_simp, ring },
rw [cos, h, β exp_pi_mul_I, exp_eq_exp_iff_exists_int],
split; simp; intros; use x,
{ field_simp, ring at a,
rwa [mul_right_comm 2 I ΞΈ, mul_right_comm (2*(x:β)+1) I (Ο:β), mul_left_inj' I_ne_zero,
mul_comm 2 ΞΈ] at a },
{ field_simp at a, ring,
rw [mul_right_comm 2 I ΞΈ, mul_right_comm (2*(x:β)+1) I (Ο:β), mul_left_inj' I_ne_zero,
mul_comm 2 ΞΈ, a] },
end
theorem cos_ne_zero_iff {ΞΈ : β} : cos ΞΈ β 0 β β k : β€, ΞΈ β (2 * k + 1) * Ο / 2 :=
by rw [β not_exists, not_iff_not, cos_eq_zero_iff]
lemma has_deriv_at_tan {x : β} (h : β k : β€, x β (2 * k + 1) * Ο / 2) :
has_deriv_at tan (1 / (cos x)^2) x :=
begin
convert has_deriv_at.div (has_deriv_at_sin x) (has_deriv_at_cos x) (cos_ne_zero_iff.mpr h),
rw β sin_sq_add_cos_sq x,
ring,
end
lemma differentiable_at_tan {x : β} (h : β k : β€, x β (2 * k + 1) * Ο / 2) : differentiable_at β tan x :=
(has_deriv_at_tan h).differentiable_at
@[simp] lemma deriv_tan {x : β} (h : β k : β€, x β (2 * k + 1) * Ο / 2) : deriv tan x = 1 / (cos x)^2 :=
(has_deriv_at_tan h).deriv
lemma continuous_tan : continuous (Ξ» x : {x | cos x β 0}, tan x) :=
(continuous_sin.comp continuous_subtype_val).mul
(continuous.inv subtype.property (continuous_cos.comp continuous_subtype_val))
lemma continuous_on_tan : continuous_on tan {x | cos x β 0} :=
by { rw continuous_on_iff_continuous_restrict, convert continuous_tan }
end complex
namespace real
open_locale real
theorem cos_eq_zero_iff {ΞΈ : β} : cos ΞΈ = 0 β β k : β€, ΞΈ = (2 * k + 1) * Ο / 2 :=
begin
rw [β complex.of_real_eq_zero, complex.of_real_cos ΞΈ],
convert @complex.cos_eq_zero_iff ΞΈ,
norm_cast,
end
theorem cos_ne_zero_iff {ΞΈ : β} : cos ΞΈ β 0 β β k : β€, ΞΈ β (2 * k + 1) * Ο / 2 :=
by rw [β not_exists, not_iff_not, cos_eq_zero_iff]
lemma has_deriv_at_tan {x : β} (h : β k : β€, x β (2 * k + 1) * Ο / 2) :
has_deriv_at tan (1 / (cos x)^2) x :=
begin
convert has_deriv_at_real_of_complex (complex.has_deriv_at_tan (by { convert h, norm_cast } )),
rw β complex.of_real_re (1/((cos x)^2)),
simp,
end
lemma differentiable_at_tan {x : β} (h : β k : β€, x β (2 * k + 1) * Ο / 2) : differentiable_at β tan x :=
(has_deriv_at_tan h).differentiable_at
@[simp] lemma deriv_tan {x : β} (h : β k : β€, x β (2 * k + 1) * Ο / 2) : deriv tan x = 1 / (cos x)^2 :=
(has_deriv_at_tan h).deriv
lemma continuous_tan : continuous (Ξ» x : {x | cos x β 0}, tan x) :=
by simp only [tan_eq_sin_div_cos]; exact
(continuous_sin.comp continuous_subtype_val).mul
(continuous.inv subtype.property
(continuous_cos.comp continuous_subtype_val))
lemma continuous_on_tan : continuous_on tan {x | cos x β 0} :=
by { rw continuous_on_iff_continuous_restrict, convert continuous_tan }
lemma has_deriv_at_tan_of_mem_Ioo {x : β} (h : x β Ioo (-(Ο/2):β) (Ο/2)) :
has_deriv_at tan (1 / (cos x)^2) x :=
has_deriv_at_tan (cos_ne_zero_iff.mp (ne_of_gt (cos_pos_of_mem_Ioo h.1 h.2)))
lemma differentiable_at_tan_of_mem_Ioo {x : β} (h : x β Ioo (-(Ο/2):β) (Ο/2)) :
differentiable_at β tan x :=
(has_deriv_at_tan_of_mem_Ioo h).differentiable_at
lemma deriv_tan_of_mem_Ioo {x : β} (h : x β Ioo (-(Ο/2):β) (Ο/2)) : deriv tan x = 1 / (cos x)^2 :=
(has_deriv_at_tan_of_mem_Ioo h).deriv
lemma continuous_on_tan_Ioo : continuous_on tan (Ioo (-(Ο/2)) (Ο/2)) :=
begin
refine continuous_on_tan.mono _,
intros x hx,
simp only [mem_set_of_eq],
exact ne_of_gt (cos_pos_of_mem_Ioo hx.1 hx.2),
end
open filter
open_locale topological_space
lemma tendsto_sin_pi_div_two : tendsto sin (π[Iio (Ο/2)] (Ο/2)) (π 1) :=
by { convert continuous_sin.continuous_within_at, simp }
lemma tendsto_cos_pi_div_two : tendsto cos (π[Iio (Ο/2)] (Ο/2)) (π[Ioi 0] 0) :=
begin
apply tendsto_nhds_within_of_tendsto_nhds_of_eventually_within,
{ convert continuous_cos.continuous_within_at, simp },
{ filter_upwards [Ioo_mem_nhds_within_Iio (right_mem_Ioc.mpr (norm_num.lt_neg_pos
_ _ pi_div_two_pos pi_div_two_pos))] Ξ» x hx, cos_pos_of_mem_Ioo hx.1 hx.2 },
end
lemma tendsto_tan_pi_div_two : tendsto tan (π[Iio (Ο/2)] (Ο/2)) at_top :=
begin
convert tendsto_mul_at_top (by norm_num) (tendsto.inv_tendsto_zero tendsto_cos_pi_div_two)
tendsto_sin_pi_div_two,
ext x,
rw tan_eq_sin_div_cos x,
ring,
end
lemma tendsto_sin_neg_pi_div_two : tendsto sin (π[Ioi (-(Ο/2))] (-(Ο/2))) (π (-1)) :=
by { convert continuous_sin.continuous_within_at, simp }
lemma tendsto_cos_neg_pi_div_two : tendsto cos (π[Ioi (-(Ο/2))] (-(Ο/2))) (π[Ioi 0] 0) :=
begin
apply tendsto_nhds_within_of_tendsto_nhds_of_eventually_within,
{ convert continuous_cos.continuous_within_at, simp },
{ filter_upwards [Ioo_mem_nhds_within_Ioi (set.left_mem_Ico.mpr (norm_num.lt_neg_pos
_ _ pi_div_two_pos pi_div_two_pos))] Ξ» x hx, cos_pos_of_mem_Ioo hx.1 hx.2 },
end
lemma tendsto_tan_neg_pi_div_two : tendsto tan (π[Ioi (-(Ο/2))] (-(Ο/2))) at_bot :=
begin
convert tendsto_mul_at_bot (by norm_num) (tendsto.inv_tendsto_zero tendsto_cos_neg_pi_div_two)
tendsto_sin_neg_pi_div_two,
ext x,
rw tan_eq_sin_div_cos x,
ring,
end
/-!
### Continuity and differentiability of arctan
The continuity of `arctan` is difficult to prove due to `arctan` being (indirectly) defined naively
via `classical.some`. The proof therefore uses the general theorem that monotone functions are
homeomorphisms: `homeomorph_of_strict_mono_continuous_Ioo`. We first prove that `tan` (restricted)
is a homeomorphism whose inverse is definitionally equal to `arctan`. The fact that `arctan` is
continuous is then derived from the fact that it is equal to a homeomorphism, and its
differentiability is in turn derived from its continuity using `has_deriv_at.of_local_left_inverse`.
-/
/-- The function `tan`, restricted to the open interval (-Ο/2, Ο/2), is a homeomorphism. The inverse
function of that homeomorphism is definitionally equal to `arctan` via `homeomorph.change_inv`. -/
def tan_homeomorph : (Ioo (-(Ο/2)) (Ο/2)) ββ β :=
(homeomorph_of_strict_mono_continuous_Ioo tan (by linarith [pi_div_two_pos])
(Ξ» x y, tan_lt_tan_of_lt_of_lt_pi_div_two) continuous_on_tan_Ioo tendsto_tan_pi_div_two
tendsto_tan_neg_pi_div_two).change_inv (Ξ» x, β¨arctan x, arctan_mem_Ioo xβ©) tan_arctan
lemma tan_homeomorph_inv_fun_eq_arctan : coe β tan_homeomorph.inv_fun = arctan := rfl
lemma continuous_arctan : continuous arctan :=
continuous_subtype_coe.comp tan_homeomorph.continuous_inv_fun
lemma has_deriv_at_arctan (x : β) : has_deriv_at arctan (1 / (1 + x^2)) x :=
begin
have h1 : 0 < 1 + x^2 := by nlinarith,
have h2 : cos (arctan x) β 0 := by { rw cos_arctan, exact ne_of_gt (one_div_pos.mpr (sqrt_pos.mpr h1)) },
simpa [(cos_arctan x), sqr_sqrt (le_of_lt h1)] using has_deriv_at.of_local_left_inverse
continuous_arctan.continuous_at (has_deriv_at_tan (cos_ne_zero_iff.mp h2))
(one_div_ne_zero (pow_ne_zero 2 h2)) (by {apply eventually_of_forall, exact tan_arctan} ),
end
lemma differentiable_at_arctan (x : β) : differentiable_at β arctan x :=
(has_deriv_at_arctan x).differentiable_at
@[simp] lemma deriv_arctan : deriv arctan = (Ξ» x, 1 / (1 + x^2)) :=
funext $ Ξ» x, (has_deriv_at_arctan x).deriv
end real
section
/-! Register lemmas for the derivatives of the composition of `real.arctan` with a differentiable
function, for standalone use and use with `simp`. -/
variables {f : β β β} {f' x : β} {s : set β}
lemma has_deriv_at.arctan (hf : has_deriv_at f f' x) :
has_deriv_at (Ξ» x, real.arctan (f x)) ((1 / (1 + (f x)^2)) * f') x :=
(real.has_deriv_at_arctan (f x)).comp x hf
lemma has_deriv_within_at.arctan (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (Ξ» x, real.arctan (f x)) ((1 / (1 + (f x)^2)) * f') s x :=
(real.has_deriv_at_arctan (f x)).comp_has_deriv_within_at x hf
lemma differentiable_within_at.arctan (hf : differentiable_within_at β f s x) :
differentiable_within_at β (Ξ» x, real.arctan (f x)) s x :=
hf.has_deriv_within_at.arctan.differentiable_within_at
@[simp] lemma differentiable_at.arctan (hc : differentiable_at β f x) :
differentiable_at β (Ξ» x, real.arctan (f x)) x :=
hc.has_deriv_at.arctan.differentiable_at
lemma differentiable_on.arctan (hc : differentiable_on β f s) :
differentiable_on β (Ξ» x, real.arctan (f x)) s :=
Ξ» x h, (hc x h).arctan
@[simp] lemma differentiable.arctan (hc : differentiable β f) :
differentiable β (Ξ» x, real.arctan (f x)) :=
Ξ» x, (hc x).arctan
lemma deriv_within_arctan (hf : differentiable_within_at β f s x) (hxs : unique_diff_within_at β s x) :
deriv_within (Ξ» x, real.arctan (f x)) s x = (1 / (1 + (f x)^2)) * (deriv_within f s x) :=
hf.has_deriv_within_at.arctan.deriv_within hxs
@[simp] lemma deriv_arctan (hc : differentiable_at β f x) :
deriv (Ξ» x, real.arctan (f x)) x = (1 / (1 + (f x)^2)) * (deriv f x) :=
hc.has_deriv_at.arctan.deriv
end
|
906db9b89440c27a69f736efccb28a380373249c | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/data/analysis/filter.lean | ec5a7aabadc0c8302b24738c8b97a818da21ac6c | [
"Apache-2.0"
] | permissive | Lix0120/mathlib | 0020745240315ed0e517cbf32e738d8f9811dd80 | e14c37827456fc6707f31b4d1d16f1f3a3205e91 | refs/heads/master | 1,673,102,855,024 | 1,604,151,044,000 | 1,604,151,044,000 | 308,930,245 | 0 | 0 | Apache-2.0 | 1,604,164,710,000 | 1,604,163,547,000 | null | UTF-8 | Lean | false | false | 11,767 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
Computational realization of filters (experimental).
-/
import order.filter.cofinite
open set filter
/-- A `cfilter Ξ± Ο` is a realization of a filter (base) on `Ξ±`,
represented by a type `Ο` together with operations for the top element and
the binary inf operation. -/
structure cfilter (Ξ± Ο : Type*) [partial_order Ξ±] :=
(f : Ο β Ξ±)
(pt : Ο)
(inf : Ο β Ο β Ο)
(inf_le_left : β a b : Ο, f (inf a b) β€ f a)
(inf_le_right : β a b : Ο, f (inf a b) β€ f b)
variables {Ξ± : Type*} {Ξ² : Type*} {Ο : Type*} {Ο : Type*}
namespace cfilter
section
variables [partial_order Ξ±] (F : cfilter Ξ± Ο)
instance : has_coe_to_fun (cfilter Ξ± Ο) := β¨_, cfilter.fβ©
@[simp] theorem coe_mk (f pt inf hβ hβ a) : (@cfilter.mk Ξ± Ο _ f pt inf hβ hβ) a = f a := rfl
/-- Map a cfilter to an equivalent representation type. -/
def of_equiv (E : Ο β Ο) : cfilter Ξ± Ο β cfilter Ξ± Ο
| β¨f, p, g, hβ, hββ© :=
{ f := Ξ» a, f (E.symm a),
pt := E p,
inf := Ξ» a b, E (g (E.symm a) (E.symm b)),
inf_le_left := Ξ» a b, by simpa using hβ (E.symm a) (E.symm b),
inf_le_right := Ξ» a b, by simpa using hβ (E.symm a) (E.symm b) }
@[simp] theorem of_equiv_val (E : Ο β Ο) (F : cfilter Ξ± Ο) (a : Ο) :
F.of_equiv E a = F (E.symm a) := by cases F; refl
end
/-- The filter represented by a `cfilter` is the collection of supersets of
elements of the filter base. -/
def to_filter (F : cfilter (set Ξ±) Ο) : filter Ξ± :=
{ sets := {a | β b, F b β a},
univ_sets := β¨F.pt, subset_univ _β©,
sets_of_superset := Ξ» x y β¨b, hβ© s, β¨b, subset.trans h sβ©,
inter_sets := Ξ» x y β¨a, hββ© β¨b, hββ©, β¨F.inf a b,
subset_inter (subset.trans (F.inf_le_left _ _) hβ) (subset.trans (F.inf_le_right _ _) hβ)β© }
@[simp] theorem mem_to_filter_sets (F : cfilter (set Ξ±) Ο) {a : set Ξ±} :
a β F.to_filter β β b, F b β a := iff.rfl
end cfilter
/-- A realizer for filter `f` is a cfilter which generates `f`. -/
structure filter.realizer (f : filter Ξ±) :=
(Ο : Type*)
(F : cfilter (set Ξ±) Ο)
(eq : F.to_filter = f)
protected def cfilter.to_realizer (F : cfilter (set Ξ±) Ο) : F.to_filter.realizer := β¨Ο, F, rflβ©
namespace filter.realizer
theorem mem_sets {f : filter Ξ±} (F : f.realizer) {a : set Ξ±} : a β f β β b, F.F b β a :=
by cases F; subst f; simp
-- Used because it has better definitional equalities than the eq.rec proof
def of_eq {f g : filter Ξ±} (e : f = g) (F : f.realizer) : g.realizer :=
β¨F.Ο, F.F, F.eq.trans eβ©
/-- A filter realizes itself. -/
def of_filter (f : filter Ξ±) : f.realizer := β¨f.sets,
{ f := subtype.val,
pt := β¨univ, univ_mem_setsβ©,
inf := Ξ» β¨x, hββ© β¨y, hββ©, β¨_, inter_mem_sets hβ hββ©,
inf_le_left := Ξ» β¨x, hββ© β¨y, hββ©, inter_subset_left x y,
inf_le_right := Ξ» β¨x, hββ© β¨y, hββ©, inter_subset_right x y },
filter_eq $ set.ext $ Ξ» x, set_coe.exists.trans exists_sets_subset_iffβ©
/-- Transfer a filter realizer to another realizer on a different base type. -/
def of_equiv {f : filter Ξ±} (F : f.realizer) (E : F.Ο β Ο) : f.realizer :=
β¨Ο, F.F.of_equiv E, by refine eq.trans _ F.eq; exact filter_eq (set.ext $ Ξ» x,
β¨Ξ» β¨s, hβ©, β¨E.symm s, by simpa using hβ©, Ξ» β¨t, hβ©, β¨E t, by simp [h]β©β©)β©
@[simp] theorem of_equiv_Ο {f : filter Ξ±} (F : f.realizer) (E : F.Ο β Ο) : (F.of_equiv E).Ο = Ο := rfl
@[simp] theorem of_equiv_F {f : filter Ξ±} (F : f.realizer) (E : F.Ο β Ο) (s : Ο) :
(F.of_equiv E).F s = F.F (E.symm s) := by delta of_equiv; simp
/-- `unit` is a realizer for the principal filter -/
protected def principal (s : set Ξ±) : (principal s).realizer := β¨unit,
{ f := Ξ» _, s,
pt := (),
inf := Ξ» _ _, (),
inf_le_left := Ξ» _ _, le_refl _,
inf_le_right := Ξ» _ _, le_refl _ },
filter_eq $ set.ext $ Ξ» x,
β¨Ξ» β¨_, sβ©, s, Ξ» h, β¨(), hβ©β©β©
@[simp] theorem principal_Ο (s : set Ξ±) : (realizer.principal s).Ο = unit := rfl
@[simp] theorem principal_F (s : set Ξ±) (u : unit) : (realizer.principal s).F u = s := rfl
/-- `unit` is a realizer for the top filter -/
protected def top : (β€ : filter Ξ±).realizer :=
(realizer.principal _).of_eq principal_univ
@[simp] theorem top_Ο : (@realizer.top Ξ±).Ο = unit := rfl
@[simp] theorem top_F (u : unit) : (@realizer.top Ξ±).F u = univ := rfl
/-- `unit` is a realizer for the bottom filter -/
protected def bot : (β₯ : filter Ξ±).realizer :=
(realizer.principal _).of_eq principal_empty
@[simp] theorem bot_Ο : (@realizer.bot Ξ±).Ο = unit := rfl
@[simp] theorem bot_F (u : unit) : (@realizer.bot Ξ±).F u = β
:= rfl
/-- Construct a realizer for `map m f` given a realizer for `f` -/
protected def map (m : Ξ± β Ξ²) {f : filter Ξ±} (F : f.realizer) : (map m f).realizer := β¨F.Ο,
{ f := Ξ» s, image m (F.F s),
pt := F.F.pt,
inf := F.F.inf,
inf_le_left := Ξ» a b, image_subset _ (F.F.inf_le_left _ _),
inf_le_right := Ξ» a b, image_subset _ (F.F.inf_le_right _ _) },
filter_eq $ set.ext $ Ξ» x, by simp [cfilter.to_filter]; rw F.mem_sets; refl β©
@[simp] theorem map_Ο (m : Ξ± β Ξ²) {f : filter Ξ±} (F : f.realizer) : (F.map m).Ο = F.Ο := rfl
@[simp] theorem map_F (m : Ξ± β Ξ²) {f : filter Ξ±} (F : f.realizer) (s) :
(F.map m).F s = image m (F.F s) := rfl
/-- Construct a realizer for `comap m f` given a realizer for `f` -/
protected def comap (m : Ξ± β Ξ²) {f : filter Ξ²} (F : f.realizer) : (comap m f).realizer := β¨F.Ο,
{ f := Ξ» s, preimage m (F.F s),
pt := F.F.pt,
inf := F.F.inf,
inf_le_left := Ξ» a b, preimage_mono (F.F.inf_le_left _ _),
inf_le_right := Ξ» a b, preimage_mono (F.F.inf_le_right _ _) },
filter_eq $ set.ext $ Ξ» x, by cases F; subst f; simp [cfilter.to_filter, mem_comap_sets]; exact
β¨Ξ» β¨s, hβ©, β¨_, β¨s, subset.refl _β©, hβ©,
Ξ» β¨y, β¨s, hβ©, hββ©, β¨s, subset.trans (preimage_mono h) hββ©β©β©
/-- Construct a realizer for the sup of two filters -/
protected def sup {f g : filter Ξ±} (F : f.realizer) (G : g.realizer) : (f β g).realizer := β¨F.Ο Γ G.Ο,
{ f := Ξ» β¨s, tβ©, F.F s βͺ G.F t,
pt := (F.F.pt, G.F.pt),
inf := Ξ» β¨a, a'β© β¨b, b'β©, (F.F.inf a b, G.F.inf a' b'),
inf_le_left := Ξ» β¨a, a'β© β¨b, b'β©, union_subset_union (F.F.inf_le_left _ _) (G.F.inf_le_left _ _),
inf_le_right := Ξ» β¨a, a'β© β¨b, b'β©, union_subset_union (F.F.inf_le_right _ _) (G.F.inf_le_right _ _) },
filter_eq $ set.ext $ Ξ» x, by cases F; cases G; substs f g; simp [cfilter.to_filter]; exact
β¨Ξ» β¨s, t, hβ©, β¨β¨s, subset.trans (subset_union_left _ _) hβ©,
β¨t, subset.trans (subset_union_right _ _) hβ©β©,
Ξ» β¨β¨s, hββ©, β¨t, hββ©β©, β¨s, t, union_subset hβ hββ©β©β©
/-- Construct a realizer for the inf of two filters -/
protected def inf {f g : filter Ξ±} (F : f.realizer) (G : g.realizer) : (f β g).realizer := β¨F.Ο Γ G.Ο,
{ f := Ξ» β¨s, tβ©, F.F s β© G.F t,
pt := (F.F.pt, G.F.pt),
inf := Ξ» β¨a, a'β© β¨b, b'β©, (F.F.inf a b, G.F.inf a' b'),
inf_le_left := Ξ» β¨a, a'β© β¨b, b'β©, inter_subset_inter (F.F.inf_le_left _ _) (G.F.inf_le_left _ _),
inf_le_right := Ξ» β¨a, a'β© β¨b, b'β©, inter_subset_inter (F.F.inf_le_right _ _) (G.F.inf_le_right _ _) },
filter_eq $ set.ext $ Ξ» x, by cases F; cases G; substs f g; simp [cfilter.to_filter]; exact
β¨Ξ» β¨s, t, hβ©, β¨_, β¨s, subset.refl _β©, _, β¨t, subset.refl _β©, hβ©,
Ξ» β¨y, β¨s, hββ©, z, β¨t, hββ©, hβ©, β¨s, t, subset.trans (inter_subset_inter hβ hβ) hβ©β©β©
/-- Construct a realizer for the cofinite filter -/
protected def cofinite [decidable_eq Ξ±] : (@cofinite Ξ±).realizer := β¨finset Ξ±,
{ f := Ξ» s, {a | a β s},
pt := β
,
inf := (βͺ),
inf_le_left := Ξ» s t a, mt (finset.mem_union_left _),
inf_le_right := Ξ» s t a, mt (finset.mem_union_right _) },
filter_eq $ set.ext $ Ξ» x,
β¨Ξ» β¨s, hβ©, s.finite_to_set.subset (compl_subset_comm.1 h),
Ξ» β¨fsβ©, by exactI β¨xαΆ.to_finset, Ξ» a (h : a β xαΆ.to_finset),
classical.by_contradiction $ Ξ» h', h (mem_to_finset.2 h')β©β©β©
/-- Construct a realizer for filter bind -/
protected def bind {f : filter Ξ±} {m : Ξ± β filter Ξ²} (F : f.realizer) (G : β i, (m i).realizer) :
(f.bind m).realizer :=
β¨Ξ£ s : F.Ο, Ξ i β F.F s, (G i).Ο,
{ f := Ξ» β¨s, fβ©, β i β F.F s, (G i).F (f i H),
pt := β¨F.F.pt, Ξ» i H, (G i).F.ptβ©,
inf := Ξ» β¨a, fβ© β¨b, f'β©, β¨F.F.inf a b, Ξ» i h,
(G i).F.inf (f i (F.F.inf_le_left _ _ h)) (f' i (F.F.inf_le_right _ _ h))β©,
inf_le_left := Ξ» β¨a, fβ© β¨b, f'β© x,
show (x β β (i : Ξ±) (H : i β F.F (F.F.inf a b)), _) β
x β β i (H : i β F.F a), ((G i).F) (f i H), by simp; exact
Ξ» i hβ hβ, β¨i, F.F.inf_le_left _ _ hβ, (G i).F.inf_le_left _ _ hββ©,
inf_le_right := Ξ» β¨a, fβ© β¨b, f'β© x,
show (x β β (i : Ξ±) (H : i β F.F (F.F.inf a b)), _) β
x β β i (H : i β F.F b), ((G i).F) (f' i H), by simp; exact
Ξ» i hβ hβ, β¨i, F.F.inf_le_right _ _ hβ, (G i).F.inf_le_right _ _ hββ© },
filter_eq $ set.ext $ Ξ» x, by cases F with _ F _; subst f; simp [cfilter.to_filter, mem_bind_sets]; exact
β¨Ξ» β¨s, f, hβ©, β¨F s, β¨s, subset.refl _β©, Ξ» i H, (G i).mem_sets.2
β¨f i H, Ξ» a h', h β¨_, β¨i, rflβ©, _, β¨H, rflβ©, h'β©β©β©,
Ξ» β¨y, β¨s, hβ©, fβ©,
let β¨f', h'β© := classical.axiom_of_choice (Ξ» i:F s, (G i).mem_sets.1 (f i (h i.2))) in
β¨s, Ξ» i h, f' β¨i, hβ©, Ξ» a β¨_, β¨i, rflβ©, _, β¨H, rflβ©, mβ©, h' β¨_, Hβ© mβ©β©β©
/-- Construct a realizer for indexed supremum -/
protected def Sup {f : Ξ± β filter Ξ²} (F : β i, (f i).realizer) : (β¨ i, f i).realizer :=
let F' : (β¨ i, f i).realizer :=
((realizer.bind realizer.top F).of_eq $
filter_eq $ set.ext $ by simp [filter.bind, eq_univ_iff_forall, supr_sets_eq]) in
F'.of_equiv $ show (Ξ£ u:unit, Ξ (i : Ξ±), true β (F i).Ο) β Ξ i, (F i).Ο, from
β¨Ξ»β¨_,fβ© i, f i β¨β©, Ξ» f, β¨(), Ξ» i _, f iβ©,
Ξ» β¨β¨β©, fβ©, by dsimp; congr; simp, Ξ» f, rflβ©
/-- Construct a realizer for the product of filters -/
protected def prod {f g : filter Ξ±} (F : f.realizer) (G : g.realizer) : (f.prod g).realizer :=
(F.comap _).inf (G.comap _)
theorem le_iff {f g : filter Ξ±} (F : f.realizer) (G : g.realizer) :
f β€ g β β b : G.Ο, β a : F.Ο, F.F a β€ G.F b :=
β¨Ξ» H t, F.mem_sets.1 (H (G.mem_sets.2 β¨t, subset.refl _β©)),
Ξ» H x h, F.mem_sets.2 $
let β¨s, hββ© := G.mem_sets.1 h, β¨t, hββ© := H s in β¨t, subset.trans hβ hββ©β©
theorem tendsto_iff (f : Ξ± β Ξ²) {lβ : filter Ξ±} {lβ : filter Ξ²} (Lβ : lβ.realizer) (Lβ : lβ.realizer) :
tendsto f lβ lβ β β b, β a, β x β Lβ.F a, f x β Lβ.F b :=
(le_iff (Lβ.map f) Lβ).trans $ forall_congr $ Ξ» b, exists_congr $ Ξ» a, image_subset_iff
theorem ne_bot_iff {f : filter Ξ±} (F : f.realizer) :
f β β₯ β β a : F.Ο, (F.F a).nonempty :=
begin
classical,
rw [not_iff_comm, β le_bot_iff, F.le_iff realizer.bot, not_forall],
simp only [set.not_nonempty_iff_eq_empty],
exact β¨Ξ» β¨x, eβ© _, β¨x, le_of_eq eβ©,
Ξ» h, let β¨x, hβ© := h () in β¨x, le_bot_iff.1 hβ©β©
end
end filter.realizer
|
8ed50f4cf2af116fe5414c9231f032637b49012d | a8c03ed21a1bd6fc45901943b79dd6574ea3f0c2 | /clause_ops.lean | e38e9f13df9d91c45c0d116f4028357037b7d466 | [] | no_license | gebner/resolution.lean | 716c355fbb5204e5c4d0c5a7f3f3cc825892a2bf | c6fafe06fba1cfad73db68f2aa474b29fe892a2b | refs/heads/master | 1,601,111,444,528 | 1,475,256,701,000 | 1,475,256,701,000 | 67,711,151 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,609 | lean | import clause
open monad tactic expr
meta def on_left_at {m} [monad m] (c : clause) (i : β)
[has_coe_fam tactic m]
-- f gets a type and returns a list of proofs of that type
(f : expr β m (list (list expr Γ expr))) : m (list clause) := do
op : clause Γ list expr β β(cβ£open_constn (cβ£num_quants + i)),
() : unit β β(@guard tactic _ ((opβ£1β£get_lit 0)β£is_neg) _),
new_hyps β f (opβ£1β£get_lit 0)β£formula,
return $ new_hypsβ£for (Ξ»new_hyp,
(opβ£1β£inst new_hypβ£2)β£close_constn (opβ£2 ++ new_hypβ£1))
meta def on_right_at {m} [monad m] (c : clause) (i : β)
[has_coe_fam tactic m]
-- f gets a hypothesis and returns a list of proofs of false
(f : expr β m (list (list expr Γ expr))) : m (list clause) := do
op : clause Γ list expr β β(cβ£open_constn (cβ£num_quants + i)),
() : unit β β(@guard tactic _ ((opβ£1β£get_lit 0)β£is_pos) _),
hn β βmk_fresh_name,
h β return $ local_const hn `h binder_info.default (opβ£1β£get_lit 0)β£formula,
new_hyps β f h,
return $ new_hypsβ£for (Ξ»new_hyp,
(opβ£1β£inst (lambdas [h] new_hypβ£2))β£close_constn (opβ£2 ++ new_hypβ£1))
meta def on_right_at' {m} [monad m] (c : clause) (i : β)
[has_coe_fam tactic m]
-- f gets a hypothesis and returns a list of proofs
(f : expr β m (list (list expr Γ expr))) : m (list clause) := do
op : clause Γ list expr β β(cβ£open_constn (cβ£num_quants + i)),
() : unit β β(@guard tactic _ ((opβ£1β£get_lit 0)β£is_pos) _),
hn β βmk_fresh_name,
h β return $ local_const hn `h binder_info.default (opβ£1β£get_lit 0)β£formula,
new_hyps β f h,
forM new_hyps (Ξ»new_hyp, do
type β β(infer_type new_hypβ£2),
nhn β βmk_fresh_name,
nh β return $ local_const nhn `nh binder_info.default (imp type false_),
return $ (opβ£1β£inst (lambdas [h] (app nh new_hypβ£2)))β£close_constn (opβ£2 ++ new_hypβ£1 ++ [nh]))
meta def on_first_right (c : clause) (f : expr β tactic (list (list expr Γ expr))) : tactic (list clause) :=
first $ do i β list.range cβ£num_lits, [on_right_at c i f]
meta def on_first_right' (c : clause) (f : expr β tactic (list (list expr Γ expr))) : tactic (list clause) :=
first $ do i β list.range cβ£num_lits, [on_right_at' c i f]
meta def on_first_left (c : clause) (f : expr β tactic (list (list expr Γ expr))) : tactic (list clause) :=
first $ do i β list.range cβ£num_lits, [on_left_at c i f]
|
1f7c8c4402b62d7359d32e8280358a134dbf1bf4 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/number_theory/pell.lean | fc009cf1fa311528482a33f1fdac82dc1bb788f2 | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 37,768 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.nat.modeq
import number_theory.zsqrtd.basic
/-!
# Pell's equation and Matiyasevic's theorem
This file solves Pell's equation, i.e. integer solutions to `x ^ 2 - d * y ^ 2 = 1` in the special
case that `d = a ^ 2 - 1`. This is then applied to prove Matiyasevic's theorem that the power
function is Diophantine, which is the last key ingredient in the solution to Hilbert's tenth
problem. For the definition of Diophantine function, see `dioph.lean`.
## Main definition
* `pell` is a function assigning to a natural number `n` the `n`-th solution to Pell's equation
constructed recursively from the initial solution `(0, 1)`.
## Main statements
* `eq_pell` shows that every solution to Pell's equation is recursively obtained using `pell`
* `matiyasevic` shows that a certain system of Diophantine equations has a solution if and only if
the first variable is the `x`-component in a solution to Pell's equation - the key step towards
Hilbert's tenth problem in Davis' version of Matiyasevic's theorem.
* `eq_pow_of_pell` shows that the power function is Diophantine.
## Implementation notes
The proof of Matiyasevic's theorem doesn't follow Matiyasevic's original account of using Fibonacci
numbers but instead Davis' variant of using solutions to Pell's equation.
## References
* [M. Carneiro, _A Lean formalization of MatiyaseviΔ's theorem_][carneiro2018matiyasevic]
* [M. Davis, _Hilbert's tenth problem is unsolvable_][MR317916]
## Tags
Pell's equation, Matiyasevic's theorem, Hilbert's tenth problem
## TODO
* Provide solutions to Pell's equation for the case of arbitrary `d` (not just `d = a ^ 2 - 1` like
in the current version) and furthermore also for `x ^ 2 - d * y ^ 2 = -1`.
* Connect solutions to the continued fraction expansion of `βd`.
-/
namespace pell
open nat
section
parameters {a : β} (a1 : 1 < a)
include a1
private def d := a*a - 1
@[simp] theorem d_pos : 0 < d :=
tsub_pos_of_lt (mul_lt_mul a1 (le_of_lt a1) dec_trivial dec_trivial : 1*1<a*a)
/-- The Pell sequences, i.e. the sequence of integer solutions to `x ^ 2 - d * y ^ 2 = 1`, where
`d = a ^ 2 - 1`, defined together in mutual recursion. -/
-- TODO(lint): Fix double namespace issue
@[nolint dup_namespace] def pell : β β β Γ β :=
Ξ»n, nat.rec_on n (1, 0) (Ξ»n xy, (xy.1*a + d*xy.2, xy.1 + xy.2*a))
/-- The Pell `x` sequence. -/
def xn (n : β) : β := (pell n).1
/-- The Pell `y` sequence. -/
def yn (n : β) : β := (pell n).2
@[simp] theorem pell_val (n : β) : pell n = (xn n, yn n) :=
show pell n = ((pell n).1, (pell n).2), from match pell n with (a, b) := rfl end
@[simp] theorem xn_zero : xn 0 = 1 := rfl
@[simp] theorem yn_zero : yn 0 = 0 := rfl
@[simp] theorem xn_succ (n : β) : xn (n+1) = xn n * a + d * yn n := rfl
@[simp] theorem yn_succ (n : β) : yn (n+1) = xn n + yn n * a := rfl
@[simp] theorem xn_one : xn 1 = a := by simp
@[simp] theorem yn_one : yn 1 = 1 := by simp
/-- The Pell `x` sequence, considered as an integer sequence.-/
def xz (n : β) : β€ := xn n
/-- The Pell `y` sequence, considered as an integer sequence.-/
def yz (n : β) : β€ := yn n
section
omit a1
/-- The element `a` such that `d = a ^ 2 - 1`, considered as an integer.-/
def az : β€ := a
end
theorem asq_pos : 0 < a*a :=
le_trans (le_of_lt a1) (by have := @nat.mul_le_mul_left 1 a a (le_of_lt a1); rwa mul_one at this)
theorem dz_val : βd = az*az - 1 :=
have 1 β€ a*a, from asq_pos,
show β(a*a - 1) = _, by rw int.coe_nat_sub this; refl
@[simp] theorem xz_succ (n : β) : xz (n+1) = xz n * az + βd * yz n := rfl
@[simp] theorem yz_succ (n : β) : yz (n+1) = xz n + yz n * az := rfl
/-- The Pell sequence can also be viewed as an element of `β€βd` -/
def pell_zd (n : β) : β€βd := β¨xn n, yn nβ©
@[simp] theorem pell_zd_re (n : β) : (pell_zd n).re = xn n := rfl
@[simp] theorem pell_zd_im (n : β) : (pell_zd n).im = yn n := rfl
/-- The property of being a solution to the Pell equation, expressed
as a property of elements of `β€βd`. -/
def is_pell : β€βd β Prop | β¨x, yβ© := x*x - d*y*y = 1
theorem is_pell_nat {x y : β} : is_pell β¨x, yβ© β x*x - d*y*y = 1 :=
β¨Ξ»h, int.coe_nat_inj
(by rw int.coe_nat_sub (int.le_of_coe_nat_le_coe_nat $ int.le.intro_sub h); exact h),
Ξ»h, show ((x*x : β) - (d*y*y:β) : β€) = 1,
by rw [β int.coe_nat_sub $ le_of_lt $ nat.lt_of_sub_eq_succ h, h]; reflβ©
theorem is_pell_norm : Ξ {b : β€βd}, is_pell b β b * b.conj = 1
| β¨x, yβ© := by simp [zsqrtd.ext, is_pell, mul_comm]; ring_nf
theorem is_pell_mul {b c : β€βd} (hb : is_pell b) (hc : is_pell c) : is_pell (b * c) :=
is_pell_norm.2 (by simp [mul_comm, mul_left_comm,
zsqrtd.conj_mul, pell.is_pell_norm.1 hb, pell.is_pell_norm.1 hc])
theorem is_pell_conj : β {b : β€βd}, is_pell b β is_pell b.conj | β¨x, yβ© :=
by simp [is_pell, zsqrtd.conj]
@[simp] theorem pell_zd_succ (n : β) : pell_zd (n+1) = pell_zd n * β¨a, 1β© :=
by simp [zsqrtd.ext]
theorem is_pell_one : is_pell β¨a, 1β© :=
show az*az-d*1*1=1, by simp [dz_val]; ring
theorem is_pell_pell_zd : β (n : β), is_pell (pell_zd n)
| 0 := rfl
| (n+1) := let o := is_pell_one in by simp; exact pell.is_pell_mul (is_pell_pell_zd n) o
@[simp] theorem pell_eqz (n : β) : xz n * xz n - d * yz n * yz n = 1 := is_pell_pell_zd n
@[simp] theorem pell_eq (n : β) : xn n * xn n - d * yn n * yn n = 1 :=
let pn := pell_eqz n in
have h : (β(xn n * xn n) : β€) - β(d * yn n * yn n) = 1,
by repeat {rw int.coe_nat_mul}; exact pn,
have hl : d * yn n * yn n β€ xn n * xn n, from
int.le_of_coe_nat_le_coe_nat $ int.le.intro $ add_eq_of_eq_sub' $ eq.symm h,
int.coe_nat_inj (by rw int.coe_nat_sub hl; exact h)
instance dnsq : zsqrtd.nonsquare d := β¨Ξ»n h,
have n*n + 1 = a*a, by rw β h; exact nat.succ_pred_eq_of_pos (asq_pos a1),
have na : n < a, from nat.mul_self_lt_mul_self_iff.2 (by rw β this; exact nat.lt_succ_self _),
have (n+1)*(n+1) β€ n*n + 1, by rw this; exact nat.mul_self_le_mul_self na,
have n+n β€ 0, from @nat.le_of_add_le_add_right (n*n + 1) _ _ (by ring_nf at this β’; assumption),
ne_of_gt d_pos $ by rwa nat.eq_zero_of_le_zero ((nat.le_add_left _ _).trans this) at hβ©
theorem xn_ge_a_pow : β (n : β), a^n β€ xn n
| 0 := le_refl 1
| (n+1) := by simp [pow_succ']; exact le_trans
(nat.mul_le_mul_right _ (xn_ge_a_pow n)) (nat.le_add_right _ _)
theorem n_lt_a_pow : β (n : β), n < a^n
| 0 := nat.le_refl 1
| (n+1) := begin have IH := n_lt_a_pow n,
have : a^n + a^n β€ a^n * a,
{ rw β mul_two, exact nat.mul_le_mul_left _ a1 },
simp [pow_succ'], refine lt_of_lt_of_le _ this,
exact add_lt_add_of_lt_of_le IH (lt_of_le_of_lt (nat.zero_le _) IH)
end
theorem n_lt_xn (n) : n < xn n :=
lt_of_lt_of_le (n_lt_a_pow n) (xn_ge_a_pow n)
theorem x_pos (n) : 0 < xn n :=
lt_of_le_of_lt (nat.zero_le n) (n_lt_xn n)
lemma eq_pell_lem : βn (b:β€βd), 1 β€ b β is_pell b β b β€ pell_zd n β βn, b = pell_zd n
| 0 b := Ξ»h1 hp hl, β¨0, @zsqrtd.le_antisymm _ dnsq _ _ hl h1β©
| (n+1) b := Ξ»h1 hp h,
have a1p : (0:β€βd) β€ β¨a, 1β©, from trivial,
have am1p : (0:β€βd) β€ β¨a, -1β©, from show (_:nat) β€ _, by simp; exact nat.pred_le _,
have a1m : (β¨a, 1β© * β¨a, -1β© : β€βd) = 1, from is_pell_norm.1 is_pell_one,
if ha : (β¨βa, 1β© : β€βd) β€ b then
let β¨m, eβ© := eq_pell_lem n (b * β¨a, -1β©)
(by rw β a1m; exact mul_le_mul_of_nonneg_right ha am1p)
(is_pell_mul hp (is_pell_conj.1 is_pell_one))
(by have t := mul_le_mul_of_nonneg_right h am1p;
rwa [pell_zd_succ, mul_assoc, a1m, mul_one] at t) in
β¨m+1, by rw [show b = b * β¨a, -1β© * β¨a, 1β©, by rw [mul_assoc, eq.trans (mul_comm _ _) a1m];
simp, pell_zd_succ, e]β©
else
suffices Β¬1 < b, from β¨0, show b = 1, from (or.resolve_left (lt_or_eq_of_le h1) this).symmβ©,
Ξ» h1l, by cases b with x y; exact
have bm : (_*β¨_,_β© :β€β(d a1)) = 1, from pell.is_pell_norm.1 hp,
have y0l : (0:β€β(d a1)) < β¨x - x, y - -yβ©,
from sub_lt_sub h1l $ Ξ»(hn : (1:β€β(d a1)) β€ β¨x, -yβ©),
by have t := mul_le_mul_of_nonneg_left hn (le_trans zero_le_one h1);
rw [bm, mul_one] at t; exact h1l t,
have yl2 : (β¨_, _β© : β€β_) < β¨_, _β©, from
show (β¨x, yβ© - β¨x, -yβ© : β€β(d a1)) < β¨a, 1β© - β¨a, -1β©, from
sub_lt_sub (by exact ha) $ Ξ»(hn : (β¨x, -yβ© : β€β(d a1)) β€ β¨a, -1β©),
by have t := mul_le_mul_of_nonneg_right
(mul_le_mul_of_nonneg_left hn (le_trans zero_le_one h1)) a1p;
rw [bm, one_mul, mul_assoc, eq.trans (mul_comm _ _) a1m, mul_one] at t; exact ha t,
by simp at y0l; simp at yl2; exact
match y, y0l, (yl2 : (β¨_, _β© : β€β_) < β¨_, _β©) with
| 0, y0l, yl2 := y0l (le_refl 0)
| (y+1 : β), y0l, yl2 := yl2 (zsqrtd.le_of_le_le (le_refl 0)
(let t := int.coe_nat_le_coe_nat_of_le (nat.succ_pos y) in add_le_add t t))
| -[1+y], y0l, yl2 := y0l trivial
end
theorem eq_pell_zd (b : β€βd) (b1 : 1 β€ b) (hp : is_pell b) : βn, b = pell_zd n :=
let β¨n, hβ© := @zsqrtd.le_arch d b in
eq_pell_lem n b b1 hp $ zsqrtd.le_trans h $ by rw zsqrtd.coe_nat_val; exact
zsqrtd.le_of_le_le
(int.coe_nat_le_coe_nat_of_le $ le_of_lt $ n_lt_xn _ _) (int.coe_zero_le _)
/-- Every solution to **Pell's equation** is recursively obtained from the initial solution
`(1,0)` using the recursion `pell`. -/
theorem eq_pell {x y : β} (hp : x*x - d*y*y = 1) : βn, x = xn n β§ y = yn n :=
have (1:β€βd) β€ β¨x, yβ©, from match x, hp with
| 0, (hp : 0 - _ = 1) := by rw zero_tsub at hp; contradiction
| (x+1), hp := zsqrtd.le_of_le_le (int.coe_nat_le_coe_nat_of_le $ nat.succ_pos x)
(int.coe_zero_le _)
end,
let β¨m, eβ© := eq_pell_zd β¨x, yβ© this (is_pell_nat.2 hp) in
β¨m, match x, y, e with ._, ._, rfl := β¨rfl, rflβ© endβ©
theorem pell_zd_add (m) : β n, pell_zd (m + n) = pell_zd m * pell_zd n
| 0 := (mul_one _).symm
| (n+1) := by rw[β add_assoc, pell_zd_succ, pell_zd_succ, pell_zd_add n, β mul_assoc]
theorem xn_add (m n) : xn (m + n) = xn m * xn n + d * yn m * yn n :=
by injection (pell_zd_add _ m n) with h _;
repeat {rw β int.coe_nat_add at h <|> rw β int.coe_nat_mul at h};
exact int.coe_nat_inj h
theorem yn_add (m n) : yn (m + n) = xn m * yn n + yn m * xn n :=
by injection (pell_zd_add _ m n) with _ h;
repeat {rw β int.coe_nat_add at h <|> rw β int.coe_nat_mul at h};
exact int.coe_nat_inj h
theorem pell_zd_sub {m n} (h : n β€ m) : pell_zd (m - n) = pell_zd m * (pell_zd n).conj :=
let t := pell_zd_add n (m - n) in
by rw [add_tsub_cancel_of_le h] at t;
rw [t, mul_comm (pell_zd _ n) _, mul_assoc, (is_pell_norm _).1 (is_pell_pell_zd _ _), mul_one]
theorem xz_sub {m n} (h : n β€ m) : xz (m - n) = xz m * xz n - d * yz m * yz n :=
by injection (pell_zd_sub _ h) with h _; repeat {rw β neg_mul_eq_mul_neg at h}; exact h
theorem yz_sub {m n} (h : n β€ m) : yz (m - n) = xz n * yz m - xz m * yz n :=
by injection (pell_zd_sub a1 h) with _ h; repeat {rw β neg_mul_eq_mul_neg at h};
rw [add_comm, mul_comm] at h; exact h
theorem xy_coprime (n) : (xn n).coprime (yn n) :=
nat.coprime_of_dvd' $ Ξ»k kp kx ky,
let p := pell_eq n in by rw β p; exact
nat.dvd_sub (le_of_lt $ nat.lt_of_sub_eq_succ p)
(kx.mul_left _) (ky.mul_left _)
theorem strict_mono_y : strict_mono yn
| m 0 h := absurd h $ nat.not_lt_zero _
| m (n+1) h :=
have yn m β€ yn n, from or.elim (lt_or_eq_of_le $ nat.le_of_succ_le_succ h)
(Ξ»hl, le_of_lt $ strict_mono_y hl) (Ξ»e, by rw e),
by simp; refine lt_of_le_of_lt _ (nat.lt_add_of_pos_left $ x_pos a1 n);
rw β mul_one (yn a1 m);
exact mul_le_mul this (le_of_lt a1) (nat.zero_le _) (nat.zero_le _)
theorem strict_mono_x : strict_mono xn
| m 0 h := absurd h $ nat.not_lt_zero _
| m (n+1) h :=
have xn m β€ xn n, from or.elim (lt_or_eq_of_le $ nat.le_of_succ_le_succ h)
(Ξ»hl, le_of_lt $ strict_mono_x hl) (Ξ»e, by rw e),
by simp; refine lt_of_lt_of_le (lt_of_le_of_lt this _) (nat.le_add_right _ _);
have t := nat.mul_lt_mul_of_pos_left a1 (x_pos a1 n); rwa mul_one at t
theorem yn_ge_n : Ξ n, n β€ yn n
| 0 := nat.zero_le _
| (n+1) := show n < yn (n+1), from lt_of_le_of_lt (yn_ge_n n) (strict_mono_y $ nat.lt_succ_self n)
theorem y_mul_dvd (n) : βk, yn n β£ yn (n * k)
| 0 := dvd_zero _
| (k+1) := by rw [nat.mul_succ, yn_add]; exact
dvd_add (dvd_mul_left _ _) ((y_mul_dvd k).mul_right _)
theorem y_dvd_iff (m n) : yn m β£ yn n β m β£ n :=
β¨Ξ»h, nat.dvd_of_mod_eq_zero $ (nat.eq_zero_or_pos _).resolve_right $ Ξ»hp,
have co : nat.coprime (yn m) (xn (m * (n / m))), from nat.coprime.symm $
(xy_coprime _).coprime_dvd_right (y_mul_dvd m (n / m)),
have m0 : 0 < m, from m.eq_zero_or_pos.resolve_left $
Ξ»e, by rw [e, nat.mod_zero] at hp; rw [e] at h; exact
ne_of_lt (strict_mono_y a1 hp) (eq_zero_of_zero_dvd h).symm,
by rw [β nat.mod_add_div n m, yn_add] at h; exact
not_le_of_gt (strict_mono_y _ $ nat.mod_lt n m0)
(nat.le_of_dvd (strict_mono_y _ hp) $ co.dvd_of_dvd_mul_right $
(nat.dvd_add_iff_right $ (y_mul_dvd _ _ _).mul_left _).2 h),
Ξ»β¨k, eβ©, by rw e; apply y_mul_dvdβ©
theorem xy_modeq_yn (n) :
β k, xn (n * k) β‘ (xn n)^k [MOD (yn n)^2]
β§ yn (n * k) β‘ k * (xn n)^(k-1) * yn n [MOD (yn n)^3]
| 0 := by constructor; simp
| (k+1) :=
let β¨hx, hyβ© := xy_modeq_yn k in
have L : xn (n * k) * xn n + d * yn (n * k) * yn n β‘ xn n^k * xn n + 0 [MOD yn n^2], from
(hx.mul_right _ ).add $ modeq_zero_iff_dvd.2 $
by rw pow_succ'; exact
mul_dvd_mul_right (dvd_mul_of_dvd_right (modeq_zero_iff_dvd.1 $
(hy.modeq_of_dvd $ by simp [pow_succ']).trans $ modeq_zero_iff_dvd.2 $
by simp [-mul_comm, -mul_assoc]) _) _,
have R : xn (n * k) * yn n + yn (n * k) * xn n β‘
xn n^k * yn n + k * xn n^k * yn n [MOD yn n^3], from
modeq.add (by { rw pow_succ', exact hx.mul_right' _ }) $
have k * xn n^(k - 1) * yn n * xn n = k * xn n^k * yn n,
by clear _let_match; cases k with k; simp [pow_succ', mul_comm, mul_left_comm],
by { rw β this, exact hy.mul_right _ },
by { rw [add_tsub_cancel_right, nat.mul_succ, xn_add, yn_add, pow_succ' (xn _ n),
nat.succ_mul, add_comm (k * xn _ n^k) (xn _ n^k), right_distrib],
exact β¨L, Rβ© }
theorem ysq_dvd_yy (n) : yn n * yn n β£ yn (n * yn n) :=
modeq_zero_iff_dvd.1 $
((xy_modeq_yn n (yn n)).right.modeq_of_dvd $ by simp [pow_succ]).trans
(modeq_zero_iff_dvd.2 $ by simp [mul_dvd_mul_left, mul_assoc])
theorem dvd_of_ysq_dvd {n t} (h : yn n * yn n β£ yn t) : yn n β£ t :=
have nt : n β£ t, from (y_dvd_iff n t).1 $ dvd_of_mul_left_dvd h,
n.eq_zero_or_pos.elim (Ξ» n0, by rwa n0 at β’ nt) $ Ξ» (n0l : 0 < n),
let β¨k, keβ© := nt in
have yn n β£ k * (xn n)^(k-1), from
nat.dvd_of_mul_dvd_mul_right (strict_mono_y n0l) $ modeq_zero_iff_dvd.1 $
by have xm := (xy_modeq_yn a1 n k).right; rw β ke at xm; exact
(xm.modeq_of_dvd $ by simp [pow_succ]).symm.trans h.modeq_zero_nat,
by rw ke; exact dvd_mul_of_dvd_right
(((xy_coprime _ _).pow_left _).symm.dvd_of_dvd_mul_right this) _
theorem pell_zd_succ_succ (n) : pell_zd (n + 2) + pell_zd n = (2 * a : β) * pell_zd (n + 1) :=
have (1:β€βd) + β¨a, 1β© * β¨a, 1β© = β¨a, 1β© * (2 * a),
by { rw zsqrtd.coe_nat_val, change (β¨_,_β©:β€β(d a1))=β¨_,_β©,
rw dz_val, dsimp [az], rw zsqrtd.ext, dsimp, split; ring },
by simpa [mul_add, mul_comm, mul_left_comm, add_comm] using congr_arg (* pell_zd a1 n) this
theorem xy_succ_succ (n) : xn (n + 2) + xn n = (2 * a) * xn (n + 1) β§
yn (n + 2) + yn n = (2 * a) * yn (n + 1) := begin
have := pell_zd_succ_succ a1 n, unfold pell_zd at this,
rw [β int.cast_coe_nat, zsqrtd.smul_val] at this,
injection this with hβ hβ,
split; apply int.coe_nat_inj; [simpa using hβ, simpa using hβ]
end
theorem xn_succ_succ (n) : xn (n + 2) + xn n = (2 * a) * xn (n + 1) := (xy_succ_succ n).1
theorem yn_succ_succ (n) : yn (n + 2) + yn n = (2 * a) * yn (n + 1) := (xy_succ_succ n).2
theorem xz_succ_succ (n) : xz (n + 2) = (2 * a : β) * xz (n + 1) - xz n :=
eq_sub_of_add_eq $ by delta xz; rw [β int.coe_nat_add, β int.coe_nat_mul, xn_succ_succ]
theorem yz_succ_succ (n) : yz (n + 2) = (2 * a : β) * yz (n + 1) - yz n :=
eq_sub_of_add_eq $ by delta yz; rw [β int.coe_nat_add, β int.coe_nat_mul, yn_succ_succ]
theorem yn_modeq_a_sub_one : β n, yn n β‘ n [MOD a-1]
| 0 := by simp
| 1 := by simp
| (n+2) := (yn_modeq_a_sub_one n).add_right_cancel $
begin
rw [yn_succ_succ, (by ring : n + 2 + n = 2 * (n + 1))],
exact ((modeq_sub a1.le).mul_left 2).mul (yn_modeq_a_sub_one (n+1)),
end
theorem yn_modeq_two : β n, yn n β‘ n [MOD 2]
| 0 := by simp
| 1 := by simp
| (n+2) := (yn_modeq_two n).add_right_cancel $
begin
rw [yn_succ_succ, mul_assoc, (by ring : n + 2 + n = 2 * (n + 1))],
exact (dvd_mul_right 2 _).modeq_zero_nat.trans (dvd_mul_right 2 _).zero_modeq_nat,
end
section
omit a1
lemma x_sub_y_dvd_pow_lem (y2 y1 y0 yn1 yn0 xn1 xn0 ay a2 : β€) :
(a2 * yn1 - yn0) * ay + y2 - (a2 * xn1 - xn0) =
y2 - a2 * y1 + y0 + a2 * (yn1 * ay + y1 - xn1) - (yn0 * ay + y0 - xn0) := by ring
end
theorem x_sub_y_dvd_pow (y : β) :
β n, (2*a*y - y*y - 1 : β€) β£ yz n * (a - y) + β(y^n) - xz n
| 0 := by simp [xz, yz, int.coe_nat_zero, int.coe_nat_one]
| 1 := by simp [xz, yz, int.coe_nat_zero, int.coe_nat_one]
| (n+2) :=
have (2*a*y - y*y - 1 : β€) β£ β(y^(n + 2)) - β(2 * a) * β(y^(n + 1)) + β(y^n), from
β¨-β(y^n), by { simp [pow_succ, mul_add, int.coe_nat_mul,
show ((2:β):β€) = 2, from rfl, mul_comm, mul_left_comm], ring }β©,
by { rw [xz_succ_succ, yz_succ_succ, x_sub_y_dvd_pow_lem β(y^(n+2)) β(y^(n+1)) β(y^n)],
exact
dvd_sub (dvd_add this $ (x_sub_y_dvd_pow (n+1)).mul_left _) (x_sub_y_dvd_pow n) }
theorem xn_modeq_x2n_add_lem (n j) : xn n β£ d * yn n * (yn n * xn j) + xn j :=
have h1 : d * yn n * (yn n * xn j) + xn j = (d * yn n * yn n + 1) * xn j,
by simp [add_mul, mul_assoc],
have h2 : d * yn n * yn n + 1 = xn n * xn n, by apply int.coe_nat_inj;
repeat {rw int.coe_nat_add <|> rw int.coe_nat_mul}; exact
add_eq_of_eq_sub' (eq.symm $ pell_eqz _ _),
by rw h2 at h1; rw [h1, mul_assoc]; exact dvd_mul_right _ _
theorem xn_modeq_x2n_add (n j) : xn (2 * n + j) + xn j β‘ 0 [MOD xn n] :=
begin
rw [two_mul, add_assoc, xn_add, add_assoc, βzero_add 0],
refine (dvd_mul_right (xn a1 n) (xn a1 (n + j))).modeq_zero_nat.add _,
rw [yn_add, left_distrib, add_assoc, βzero_add 0],
exact ((dvd_mul_right _ _).mul_left _).modeq_zero_nat.add
(xn_modeq_x2n_add_lem _ _ _).modeq_zero_nat,
end
lemma xn_modeq_x2n_sub_lem {n j} (h : j β€ n) : xn (2 * n - j) + xn j β‘ 0 [MOD xn n] :=
have h1 : xz n β£ βd * yz n * yz (n - j) + xz j,
by rw [yz_sub _ h, mul_sub_left_distrib, sub_add_eq_add_sub]; exact
dvd_sub
(by delta xz; delta yz;
repeat {rw β int.coe_nat_add <|> rw β int.coe_nat_mul}; rw mul_comm (xn a1 j) (yn a1 n);
exact int.coe_nat_dvd.2 (xn_modeq_x2n_add_lem _ _ _))
((dvd_mul_right _ _).mul_left _),
begin
rw [two_mul, add_tsub_assoc_of_le h, xn_add, add_assoc, βzero_add 0],
exact (dvd_mul_right _ _).modeq_zero_nat.add
(int.coe_nat_dvd.1 $ by simpa [xz, yz] using h1).modeq_zero_nat,
end
theorem xn_modeq_x2n_sub {n j} (h : j β€ 2 * n) : xn (2 * n - j) + xn j β‘ 0 [MOD xn n] :=
(le_total j n).elim xn_modeq_x2n_sub_lem
(Ξ»jn, have 2 * n - j + j β€ n + j, by rw [tsub_add_cancel_of_le h, two_mul];
exact nat.add_le_add_left jn _,
let t := xn_modeq_x2n_sub_lem (nat.le_of_add_le_add_right this) in
by rwa [tsub_tsub_cancel_of_le h, add_comm] at t)
theorem xn_modeq_x4n_add (n j) : xn (4 * n + j) β‘ xn j [MOD xn n] :=
modeq.add_right_cancel' (xn (2 * n + j)) $
by refine @modeq.trans _ _ 0 _ _ (by rw add_comm; exact (xn_modeq_x2n_add _ _ _).symm);
rw [show 4*n = 2*n + 2*n, from right_distrib 2 2 n, add_assoc]; apply xn_modeq_x2n_add
theorem xn_modeq_x4n_sub {n j} (h : j β€ 2 * n) : xn (4 * n - j) β‘ xn j [MOD xn n] :=
have h' : j β€ 2*n, from le_trans h (by rw nat.succ_mul; apply nat.le_add_left),
modeq.add_right_cancel' (xn (2 * n - j)) $
by refine @modeq.trans _ _ 0 _ _ (by rw add_comm; exact (xn_modeq_x2n_sub _ h).symm);
rw [show 4*n = 2*n + 2*n, from right_distrib 2 2 n, add_tsub_assoc_of_le h'];
apply xn_modeq_x2n_add
theorem eq_of_xn_modeq_lem1 {i n} : Ξ {j}, i < j β j < n β xn i % xn n < xn j % xn n
| 0 ij _ := absurd ij (nat.not_lt_zero _)
| (j+1) ij jn :=
suffices xn j % xn n < xn (j + 1) % xn n, from
(lt_or_eq_of_le (nat.le_of_succ_le_succ ij)).elim
(Ξ»h, lt_trans (eq_of_xn_modeq_lem1 h (le_of_lt jn)) this)
(Ξ»h, by rw h; exact this),
by rw [nat.mod_eq_of_lt (strict_mono_x _ (nat.lt_of_succ_lt jn)),
nat.mod_eq_of_lt (strict_mono_x _ jn)];
exact strict_mono_x _ (nat.lt_succ_self _)
theorem eq_of_xn_modeq_lem2 {n} (h : 2 * xn n = xn (n + 1)) : a = 2 β§ n = 0 :=
by rw [xn_succ, mul_comm] at h; exact
have n = 0, from n.eq_zero_or_pos.resolve_right $ Ξ»np,
ne_of_lt (lt_of_le_of_lt (nat.mul_le_mul_left _ a1)
(nat.lt_add_of_pos_right $ mul_pos (d_pos a1) (strict_mono_y a1 np))) h,
by cases this; simp at h; exact β¨h.symm, rflβ©
theorem eq_of_xn_modeq_lem3 {i n} (npos : 0 < n) :
Ξ {j}, i < j β j β€ 2 * n β j β n β Β¬(a = 2 β§ n = 1 β§ i = 0 β§ j = 2) β xn i % xn n < xn j % xn n
| 0 ij _ _ _ := absurd ij (nat.not_lt_zero _)
| (j+1) ij j2n jnn ntriv :=
have lem2 : βk > n, k β€ 2*n β (β(xn k % xn n) : β€) = xn n - xn (2 * n - k), from Ξ»k kn k2n,
let k2nl := lt_of_add_lt_add_right $ show 2*n-k+k < n+k, by
{rw tsub_add_cancel_of_le, rw two_mul; exact (add_lt_add_left kn n), exact k2n } in
have xle : xn (2 * n - k) β€ xn n, from le_of_lt $ strict_mono_x k2nl,
suffices xn k % xn n = xn n - xn (2 * n - k), by rw [this, int.coe_nat_sub xle],
by {
rw β nat.mod_eq_of_lt (nat.sub_lt (x_pos a1 n) (x_pos a1 (2 * n - k))),
apply modeq.add_right_cancel' (xn a1 (2 * n - k)),
rw [tsub_add_cancel_of_le xle],
have t := xn_modeq_x2n_sub_lem a1 k2nl.le,
rw tsub_tsub_cancel_of_le k2n at t,
exact t.trans dvd_rfl.zero_modeq_nat },
(lt_trichotomy j n).elim
(Ξ» (jn : j < n), eq_of_xn_modeq_lem1 ij (lt_of_le_of_ne jn jnn)) $ Ξ» o, o.elim
(Ξ» (jn : j = n), by {
cases jn,
apply int.lt_of_coe_nat_lt_coe_nat,
rw [lem2 (n+1) (nat.lt_succ_self _) j2n,
show 2 * n - (n + 1) = n - 1, by rw[two_mul, tsub_add_eq_tsub_tsub, add_tsub_cancel_right]],
refine lt_sub_left_of_add_lt (int.coe_nat_lt_coe_nat_of_lt _),
cases (lt_or_eq_of_le $ nat.le_of_succ_le_succ ij) with lin ein,
{ rw nat.mod_eq_of_lt (strict_mono_x _ lin),
have ll : xn a1 (n-1) + xn a1 (n-1) β€ xn a1 n,
{ rw [β two_mul, mul_comm, show xn a1 n = xn a1 (n-1+1),
by rw [tsub_add_cancel_of_le (succ_le_of_lt npos)], xn_succ],
exact le_trans (nat.mul_le_mul_left _ a1) (nat.le_add_right _ _) },
have npm : (n-1).succ = n := nat.succ_pred_eq_of_pos npos,
have il : i β€ n - 1, { apply nat.le_of_succ_le_succ, rw npm, exact lin },
cases lt_or_eq_of_le il with ill ile,
{ exact lt_of_lt_of_le (nat.add_lt_add_left (strict_mono_x a1 ill) _) ll },
{ rw ile,
apply lt_of_le_of_ne ll,
rw β two_mul,
exact Ξ»e, ntriv $
let β¨a2, s1β© := @eq_of_xn_modeq_lem2 _ a1 (n-1)
(by rwa [tsub_add_cancel_of_le (succ_le_of_lt npos)]) in
have n1 : n = 1, from le_antisymm (tsub_eq_zero_iff_le.mp s1) npos,
by rw [ile, a2, n1]; exact β¨rfl, rfl, rfl, rflβ© } },
{ rw [ein, nat.mod_self, add_zero],
exact strict_mono_x _ (nat.pred_lt npos.ne') } })
(Ξ» (jn : j > n),
have lem1 : j β n β xn j % xn n < xn (j + 1) % xn n β xn i % xn n < xn (j + 1) % xn n,
from Ξ»jn s,
(lt_or_eq_of_le (nat.le_of_succ_le_succ ij)).elim
(Ξ»h, lt_trans (eq_of_xn_modeq_lem3 h (le_of_lt j2n) jn $ Ξ»β¨a1, n1, i0, j2β©,
by rw [n1, j2] at j2n; exact absurd j2n dec_trivial) s)
(Ξ»h, by rw h; exact s),
lem1 (ne_of_gt jn) $ int.lt_of_coe_nat_lt_coe_nat $ by {
rw [lem2 j jn (le_of_lt j2n), lem2 (j+1) (nat.le_succ_of_le jn) j2n],
refine sub_lt_sub_left (int.coe_nat_lt_coe_nat_of_lt $ strict_mono_x _ _) _,
rw [nat.sub_succ],
exact nat.pred_lt (ne_of_gt $ tsub_pos_of_lt j2n) })
theorem eq_of_xn_modeq_le {i j n} (npos : 0 < n) (ij : i β€ j) (j2n : j β€ 2 * n)
(h : xn i β‘ xn j [MOD xn n]) (ntriv : Β¬(a = 2 β§ n = 1 β§ i = 0 β§ j = 2)) : i = j :=
(lt_or_eq_of_le ij).resolve_left $ Ξ»ij',
if jn : j = n then by {
refine ne_of_gt _ h,
rw [jn, nat.mod_self],
have x0 : 0 < xn a1 0 % xn a1 n := by rw [nat.mod_eq_of_lt (strict_mono_x a1 npos)];
exact dec_trivial,
cases i with i, exact x0,
rw jn at ij',
exact x0.trans (eq_of_xn_modeq_lem3 _ npos (nat.succ_pos _) (le_trans ij j2n) (ne_of_lt ij') $
Ξ»β¨a1, n1, _, i2β©, by rw [n1, i2] at ij'; exact absurd ij' dec_trivial) }
else ne_of_lt (eq_of_xn_modeq_lem3 npos ij' j2n jn ntriv) h
theorem eq_of_xn_modeq {i j n} (npos : 0 < n) (i2n : i β€ 2 * n) (j2n : j β€ 2 * n)
(h : xn i β‘ xn j [MOD xn n]) (ntriv : a = 2 β n = 1 β (i = 0 β j β 2) β§ (i = 2 β j β 0)) :
i = j :=
(le_total i j).elim
(Ξ»ij, eq_of_xn_modeq_le npos ij j2n h $ Ξ»β¨a2, n1, i0, j2β©, (ntriv a2 n1).left i0 j2)
(Ξ»ij, (eq_of_xn_modeq_le npos ij i2n h.symm $ Ξ»β¨a2, n1, j0, i2β©,
(ntriv a2 n1).right i2 j0).symm)
theorem eq_of_xn_modeq' {i j n} (ipos : 0 < i) (hin : i β€ n) (j4n : j β€ 4 * n)
(h : xn j β‘ xn i [MOD xn n]) : j = i β¨ j + i = 4 * n :=
have i2n : i β€ 2*n, by apply le_trans hin; rw two_mul; apply nat.le_add_left,
have npos : 0 < n, from lt_of_lt_of_le ipos hin,
(le_or_gt j (2 * n)).imp
(Ξ»j2n : j β€ 2 * n, eq_of_xn_modeq npos j2n i2n h $
Ξ»a2 n1, β¨Ξ»j0 i2, by rw [n1, i2] at hin; exact absurd hin dec_trivial,
Ξ»j2 i0, ne_of_gt ipos i0β©)
(Ξ»j2n : 2 * n < j, suffices i = 4*n - j, by rw [this, add_tsub_cancel_of_le j4n],
have j42n : 4*n - j β€ 2*n, from @nat.le_of_add_le_add_right j _ _ $
by rw [tsub_add_cancel_of_le j4n, show 4*n = 2*n + 2*n, from right_distrib 2 2 n];
exact nat.add_le_add_left (le_of_lt j2n) _,
eq_of_xn_modeq npos i2n j42n
(h.symm.trans $ let t := xn_modeq_x4n_sub j42n in by rwa [tsub_tsub_cancel_of_le j4n] at t)
(Ξ»a2 n1, β¨Ξ»i0, absurd i0 (ne_of_gt ipos), Ξ»i2, by { rw [n1, i2] at hin,
exact absurd hin dec_trivial }β©))
theorem modeq_of_xn_modeq {i j n} (ipos : 0 < i) (hin : i β€ n) (h : xn j β‘ xn i [MOD xn n]) :
j β‘ i [MOD 4 * n] β¨ j + i β‘ 0 [MOD 4 * n] :=
let j' := j % (4 * n) in
have n4 : 0 < 4 * n, from mul_pos dec_trivial (ipos.trans_le hin),
have jl : j' < 4 * n, from nat.mod_lt _ n4,
have jj : j β‘ j' [MOD 4 * n], by delta modeq; rw nat.mod_eq_of_lt jl,
have βj q, xn (j + 4 * n * q) β‘ xn j [MOD xn n], begin
intros j q, induction q with q IH, { simp },
rw [nat.mul_succ, β add_assoc, add_comm],
exact (xn_modeq_x4n_add _ _ _).trans IH
end,
or.imp
(Ξ»(ji : j' = i), by rwa β ji)
(Ξ»(ji : j' + i = 4 * n), (jj.add_right _).trans $
by { rw ji, exact dvd_rfl.modeq_zero_nat })
(eq_of_xn_modeq' ipos hin jl.le $
(h.symm.trans $ by { rw β nat.mod_add_div j (4*n), exact this j' _ }).symm)
end
theorem xy_modeq_of_modeq {a b c} (a1 : 1 < a) (b1 : 1 < b) (h : a β‘ b [MOD c]) :
β n, xn a1 n β‘ xn b1 n [MOD c] β§ yn a1 n β‘ yn b1 n [MOD c]
| 0 := by constructor; refl
| 1 := by simp; exact β¨h, modeq.refl 1β©
| (n+2) := β¨
(xy_modeq_of_modeq n).left.add_right_cancel $
by { rw [xn_succ_succ a1, xn_succ_succ b1], exact
(h.mul_left _ ).mul (xy_modeq_of_modeq (n+1)).left },
(xy_modeq_of_modeq n).right.add_right_cancel $
by { rw [yn_succ_succ a1, yn_succ_succ b1], exact
(h.mul_left _ ).mul (xy_modeq_of_modeq (n+1)).right }β©
theorem matiyasevic {a k x y} : (β a1 : 1 < a, xn a1 k = x β§ yn a1 k = y) β
1 < a β§ k β€ y β§
(x = 1 β§ y = 0 β¨
β (u v s t b : β),
x * x - (a * a - 1) * y * y = 1 β§
u * u - (a * a - 1) * v * v = 1 β§
s * s - (b * b - 1) * t * t = 1 β§
1 < b β§ b β‘ 1 [MOD 4 * y] β§ b β‘ a [MOD u] β§
0 < v β§ y * y β£ v β§
s β‘ x [MOD u] β§
t β‘ k [MOD 4 * y]) :=
β¨Ξ»β¨a1, hx, hyβ©, by rw [β hx, β hy];
refine β¨a1, (nat.eq_zero_or_pos k).elim
(Ξ»k0, by rw k0; exact β¨le_rfl, or.inl β¨rfl, rflβ©β©) (Ξ»kpos, _)β©; exact
let x := xn a1 k, y := yn a1 k,
m := 2 * (k * y),
u := xn a1 m, v := yn a1 m in
have ky : k β€ y, from yn_ge_n a1 k,
have yv : y * y β£ v, from (ysq_dvd_yy a1 k).trans $ (y_dvd_iff _ _ _).2 $ dvd_mul_left _ _,
have uco : nat.coprime u (4 * y), from
have 2 β£ v, from modeq_zero_iff_dvd.1 $ (yn_modeq_two _ _).trans
(dvd_mul_right _ _).modeq_zero_nat,
have nat.coprime u 2, from
(xy_coprime a1 m).coprime_dvd_right this,
(this.mul_right this).mul_right $
(xy_coprime _ _).coprime_dvd_right (dvd_of_mul_left_dvd yv),
let β¨b, ba, bm1β© := chinese_remainder uco a 1 in
have m1 : 1 < m, from
have 0 < k * y, from mul_pos kpos (strict_mono_y a1 kpos),
nat.mul_le_mul_left 2 this,
have vp : 0 < v, from strict_mono_y a1 (lt_trans zero_lt_one m1),
have b1 : 1 < b, from
have xn a1 1 < u, from strict_mono_x a1 m1,
have a < u, by simp at this; exact this,
lt_of_lt_of_le a1 $ by delta modeq at ba;
rw nat.mod_eq_of_lt this at ba; rw β ba; apply nat.mod_le,
let s := xn b1 k, t := yn b1 k in
have sx : s β‘ x [MOD u], from (xy_modeq_of_modeq b1 a1 ba k).left,
have tk : t β‘ k [MOD 4 * y], from
have 4 * y β£ b - 1, from int.coe_nat_dvd.1 $
by rw int.coe_nat_sub (le_of_lt b1);
exact bm1.symm.dvd,
(yn_modeq_a_sub_one _ _).modeq_of_dvd this,
β¨ky, or.inr β¨u, v, s, t, b,
pell_eq _ _, pell_eq _ _, pell_eq _ _, b1, bm1, ba, vp, yv, sx, tkβ©β©,
Ξ»β¨a1, ky, oβ©, β¨a1, match o with
| or.inl β¨x1, y0β© := by rw y0 at ky; rw [nat.eq_zero_of_le_zero ky, x1, y0]; exact β¨rfl, rflβ©
| or.inr β¨u, v, s, t, b, xy, uv, st, b1, remβ© :=
match x, y, eq_pell a1 xy, u, v, eq_pell a1 uv, s, t, eq_pell b1 st, rem, ky with
| ._, ._, β¨i, rfl, rflβ©, ._, ._, β¨n, rfl, rflβ©, ._, ._, β¨j, rfl, rflβ©,
β¨(bm1 : b β‘ 1 [MOD 4 * yn a1 i]),
(ba : b β‘ a [MOD xn a1 n]),
(vp : 0 < yn a1 n),
(yv : yn a1 i * yn a1 i β£ yn a1 n),
(sx : xn b1 j β‘ xn a1 i [MOD xn a1 n]),
(tk : yn b1 j β‘ k [MOD 4 * yn a1 i])β©,
(ky : k β€ yn a1 i) :=
(nat.eq_zero_or_pos i).elim
(Ξ»i0, by simp [i0] at ky; rw [i0, ky]; exact β¨rfl, rflβ©) $ Ξ»ipos,
suffices i = k, by rw this; exact β¨rfl, rflβ©,
by clear _x o rem xy uv st _match _match _fun_match; exact
have iln : i β€ n, from le_of_not_gt $ Ξ»hin,
not_lt_of_ge (nat.le_of_dvd vp (dvd_of_mul_left_dvd yv)) (strict_mono_y a1 hin),
have yd : 4 * yn a1 i β£ 4 * n, from mul_dvd_mul_left _ $ dvd_of_ysq_dvd a1 yv,
have jk : j β‘ k [MOD 4 * yn a1 i], from
have 4 * yn a1 i β£ b - 1, from int.coe_nat_dvd.1 $
by rw int.coe_nat_sub (le_of_lt b1); exact bm1.symm.dvd,
((yn_modeq_a_sub_one b1 _).modeq_of_dvd this).symm.trans tk,
have ki : k + i < 4 * yn a1 i, from
lt_of_le_of_lt (add_le_add ky (yn_ge_n a1 i)) $
by rw β two_mul; exact nat.mul_lt_mul_of_pos_right dec_trivial (strict_mono_y a1 ipos),
have ji : j β‘ i [MOD 4 * n], from
have xn a1 j β‘ xn a1 i [MOD xn a1 n], from (xy_modeq_of_modeq b1 a1 ba j).left.symm.trans sx,
(modeq_of_xn_modeq a1 ipos iln this).resolve_right $ Ξ» (ji : j + i β‘ 0 [MOD 4 * n]),
not_le_of_gt ki $ nat.le_of_dvd (lt_of_lt_of_le ipos $ nat.le_add_left _ _) $
modeq_zero_iff_dvd.1 $ (jk.symm.add_right i).trans $
ji.modeq_of_dvd yd,
by have : i % (4 * yn a1 i) = k % (4 * yn a1 i) :=
(ji.modeq_of_dvd yd).symm.trans jk;
rwa [nat.mod_eq_of_lt (lt_of_le_of_lt (nat.le_add_left _ _) ki),
nat.mod_eq_of_lt (lt_of_le_of_lt (nat.le_add_right _ _) ki)] at this
end
endβ©β©
lemma eq_pow_of_pell_lem {a y k} (a1 : 1 < a) (ypos : 0 < y) : 0 < k β y^k < a β
(β(y^k) : β€) < 2*a*y - y*y - 1 :=
have y < a β a + (y*y + 1) β€ 2*a*y, begin
intro ya, induction y with y IH, exact absurd ypos (lt_irrefl _),
cases nat.eq_zero_or_pos y with y0 ypos,
{ rw y0, simpa [two_mul], },
{ rw [nat.mul_succ, nat.mul_succ, nat.succ_mul y],
have : y + nat.succ y β€ 2 * a,
{ change y + y < 2 * a, rw β two_mul,
exact mul_lt_mul_of_pos_left (nat.lt_of_succ_lt ya) dec_trivial },
have := add_le_add (IH ypos (nat.lt_of_succ_lt ya)) this,
convert this using 1,
ring }
end, Ξ»k0 yak,
lt_of_lt_of_le (int.coe_nat_lt_coe_nat_of_lt yak) $
by rw sub_sub; apply le_sub_right_of_add_le;
apply int.coe_nat_le_coe_nat_of_le;
have y1 := nat.pow_le_pow_of_le_right ypos k0; simp at y1;
exact this (lt_of_le_of_lt y1 yak)
theorem eq_pow_of_pell {m n k} : (n^k = m β
k = 0 β§ m = 1 β¨ 0 < k β§
(n = 0 β§ m = 0 β¨ 0 < n β§
β (w a t z : β) (a1 : 1 < a),
xn a1 k β‘ yn a1 k * (a - n) + m [MOD t] β§
2 * a * n = t + (n * n + 1) β§
m < t β§ n β€ w β§ k β€ w β§
a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1)) :=
β¨Ξ»e, by rw β e;
refine (nat.eq_zero_or_pos k).elim
(Ξ»k0, by rw k0; exact or.inl β¨rfl, rflβ©)
(Ξ»kpos, or.inr β¨kpos, _β©);
refine (nat.eq_zero_or_pos n).elim
(Ξ»n0, by rw [n0, zero_pow kpos]; exact or.inl β¨rfl, rflβ©)
(Ξ»npos, or.inr β¨npos, _β©); exact
let w := max n k in
have nw : n β€ w, from le_max_left _ _,
have kw : k β€ w, from le_max_right _ _,
have wpos : 0 < w, from lt_of_lt_of_le npos nw,
have w1 : 1 < w + 1, from nat.succ_lt_succ wpos,
let a := xn w1 w in
have a1 : 1 < a, from strict_mono_x w1 wpos,
let x := xn a1 k, y := yn a1 k in
let β¨z, zeβ© := show w β£ yn w1 w, from modeq_zero_iff_dvd.1 $
(yn_modeq_a_sub_one w1 w).trans dvd_rfl.modeq_zero_nat in
have nt : (β(n^k) : β€) < 2 * a * n - n * n - 1, from
eq_pow_of_pell_lem a1 npos kpos $ calc
n^k β€ n^w : nat.pow_le_pow_of_le_right npos kw
... < (w + 1)^w : nat.pow_lt_pow_of_lt_left (nat.lt_succ_of_le nw) wpos
... β€ a : xn_ge_a_pow w1 w,
let β¨t, teβ© := int.eq_coe_of_zero_le $
le_trans (int.coe_zero_le _) nt.le in
have na : n β€ a, from nw.trans $ le_of_lt $ n_lt_xn w1 w,
have tm : x β‘ y * (a - n) + n^k [MOD t], begin
apply modeq_of_dvd,
rw [int.coe_nat_add, int.coe_nat_mul, int.coe_nat_sub na, β te],
exact x_sub_y_dvd_pow a1 n k
end,
have ta : 2 * a * n = t + (n * n + 1), from int.coe_nat_inj $
by rw [int.coe_nat_add, β te, sub_sub];
repeat {rw int.coe_nat_add <|> rw int.coe_nat_mul};
rw [int.coe_nat_one, sub_add_cancel]; refl,
have mt : n^k < t, from int.lt_of_coe_nat_lt_coe_nat $
by rw β te; exact nt,
have zp : a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1,
by rw β ze; exact pell_eq w1 w,
β¨w, a, t, z, a1, tm, ta, mt, nw, kw, zpβ©,
Ξ»o, match o with
| or.inl β¨k0, m1β© := by rw [k0, m1]; refl
| or.inr β¨kpos, or.inl β¨n0, m0β©β© := by rw [n0, m0, zero_pow kpos]
| or.inr β¨kpos, or.inr β¨npos, w, a, t, z,
(a1 : 1 < a),
(tm : xn a1 k β‘ yn a1 k * (a - n) + m [MOD t]),
(ta : 2 * a * n = t + (n * n + 1)),
(mt : m < t),
(nw : n β€ w),
(kw : k β€ w),
(zp : a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1)β©β© :=
have wpos : 0 < w, from lt_of_lt_of_le npos nw,
have w1 : 1 < w + 1, from nat.succ_lt_succ wpos,
let β¨j, xj, yjβ© := eq_pell w1 zp in
by clear _match o _let_match; exact
have jpos : 0 < j, from (nat.eq_zero_or_pos j).resolve_left $ Ξ»j0,
have a1 : a = 1, by rw j0 at xj; exact xj,
have 2 * n = t + (n * n + 1), by rw a1 at ta; exact ta,
have n1 : n = 1, from
have n * n < n * 2, by rw [mul_comm n 2, this]; apply nat.le_add_left,
have n β€ 1, from nat.le_of_lt_succ $ lt_of_mul_lt_mul_left this (nat.zero_le _),
le_antisymm this npos,
by rw n1 at this;
rw β @nat.add_right_cancel 0 2 t this at mt;
exact nat.not_lt_zero _ mt,
have wj : w β€ j, from nat.le_of_dvd jpos $ modeq_zero_iff_dvd.1 $
(yn_modeq_a_sub_one w1 j).symm.trans $
modeq_zero_iff_dvd.2 β¨z, yj.symmβ©,
have nt : (β(n^k) : β€) < 2 * a * n - n * n - 1, from
eq_pow_of_pell_lem a1 npos kpos $ calc
n^k β€ n^j : nat.pow_le_pow_of_le_right npos (le_trans kw wj)
... < (w + 1)^j : nat.pow_lt_pow_of_lt_left (nat.lt_succ_of_le nw) jpos
... β€ xn w1 j : xn_ge_a_pow w1 j
... = a : xj.symm,
have na : n β€ a, by rw xj; exact
le_trans (le_trans nw wj) (le_of_lt $ n_lt_xn _ _),
have te : (t : β€) = 2 * βa * βn - βn * βn - 1, by
rw sub_sub; apply eq_sub_of_add_eq; apply (int.coe_nat_eq_coe_nat_iff _ _).2;
exact ta.symm,
have xn a1 k β‘ yn a1 k * (a - n) + n^k [MOD t],
by have := x_sub_y_dvd_pow a1 n k;
rw [β te, β int.coe_nat_sub na] at this; exact modeq_of_dvd this,
have n^k % t = m % t, from
(this.symm.trans tm).add_left_cancel' _,
by rw β te at nt;
rwa [nat.mod_eq_of_lt (int.lt_of_coe_nat_lt_coe_nat nt), nat.mod_eq_of_lt mt] at this
endβ©
end pell
|
e7f2dc7d55fe256044b9fbb704ed4eeef2184a3a | 54f4ad05b219d444b709f56c2f619dd87d14ec29 | /my_project/src/cong.lean | 924c18945ad318dd44803ee066b012716954adcc | [] | no_license | yizhou7/learning-lean | 8efcf838c7276e235a81bd291f467fa43ce56e0a | 91fb366c624df6e56e19555b2e482ce767cd8224 | refs/heads/master | 1,675,649,087,737 | 1,609,022,281,000 | 1,609,022,281,000 | 272,072,779 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,479 | lean | import data.nat.modeq -- modular arithmetic
import topology.basic
example : 5 β‘ 8 [MOD 3] :=
begin
apply rfl,
end
#check nat.modeq.modeq_mul
example (a b c d m : β) : a β‘ b [MOD m] β c β‘ d [MOD m] β a * c β‘ b * d [MOD m] :=
begin
apply nat.modeq.modeq_mul,
end
lemma cong_mul1 (a b c d m : β) : a β‘ b [MOD m] β a * c β‘ b * c [MOD m] :=
begin
intro h1,
apply nat.modeq.modeq_mul h1, apply rfl,
end
theorem cong_product (a b c d m : β) (h1: a β‘ b * c [MOD m]) (h2: c β‘ d [MOD m]) : a β‘ b * d [MOD m] :=
begin
have h3: b * c β‘ b * d [MOD m], from
begin
apply nat.modeq.modeq_mul, apply rfl, assumption
end,
apply nat.modeq.trans h1 h3,
end
lemma aaa (rr R R_INV a ar aar aaa n : β) :
R * R_INV β‘ 1 [MOD n] β
rr β‘ R * R [MOD n] β
ar β‘ a * R_INV * rr [MOD n] β
aar β‘ ar * ar * R_INV [MOD n] β
aaa β‘ aar * a * R_INV [MOD n] β
aaa β‘ a * a * a [MOD n] :=
begin
intros h1 h2 h3 h4 h5,
have h: ar β‘ a * R_INV * R * R [MOD n], from
begin
rw [mul_assoc],
apply cong_product ar (a * R_INV) rr (R * R) n,
assumption,
assumption,
end,
have h: ar β‘ a * R * 1 [MOD n], from
begin
apply cong_product ar (a * R) (R_INV * R) 1 n,
rw [<- mul_assoc, mul_assoc a R, mul_comm R R_INV, <-mul_assoc],
assumption,
rw [mul_comm],
assumption,
end,
sorry
end |
d5e1342df8190285ab7c9005c1dd7a8233a5e689 | 9dd3f3912f7321eb58ee9aa8f21778ad6221f87c | /tests/lean/run/auto_param.lean | 4aa2a0861b7cb0db52fcfea4094fad0294549910 | [
"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 | 630 | lean | open tactic
meta def my_tac : tactic unit :=
assumption <|> abstract (comp_val >> skip) <|> fail "my_tac failed to synthesize auto_param"
def f (x : nat) (h : auto_param (x > 0) `my_tac) : nat :=
nat.pred x
check f 12
check f 13
lemma f_inj {xβ xβ : nat} {hβ : xβ > 0} {hβ : xβ > 0} : f xβ = f xβ β xβ = xβ :=
begin
unfold f, intro h,
cases xβ,
exact absurd hβ (lt_irrefl _),
cases xβ,
exact absurd hβ (lt_irrefl _),
apply congr_arg nat.succ,
assumption
end
check @f_inj
lemma f_def {x : nat} (h : x > 0) : f x = nat.pred x :=
rfl
-- The following is an error
-- check Ξ» x, f x
|
8985416087083d081d1443659c76130e6e4912a7 | 57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d | /stage0/src/Leanpkg/Git.lean | a2ebcdcc8f32176bde0a8b419bfbf5a1a09d01e8 | [
"Apache-2.0"
] | permissive | collares/lean4 | 861a9269c4592bce49b71059e232ff0bfe4594cc | 52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee | refs/heads/master | 1,691,419,031,324 | 1,618,678,138,000 | 1,618,678,138,000 | 358,989,750 | 0 | 0 | Apache-2.0 | 1,618,696,333,000 | 1,618,696,333,000 | null | UTF-8 | Lean | false | false | 1,368 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Sebastian Ullrich
-/
import Leanpkg.LeanVersion
namespace Leanpkg
def upstreamGitBranch :=
"master"
def gitdefaultRevision : Option String β String
| none => upstreamGitBranch
| some branch => branch
def gitParseRevision (gitRepoDir : String) (rev : String) : IO String := do
let rev β IO.Process.run {cmd := "git", args := #["rev-parse", "-q", "--verify", rev], cwd := gitRepoDir}
rev.trim -- remove newline at end
def gitHeadRevision (gitRepoDir : String) : IO String :=
gitParseRevision gitRepoDir "HEAD"
def gitParseOriginRevision (gitRepoDir : String) (rev : String) : IO String :=
(gitParseRevision gitRepoDir $ "origin/" ++ rev) <|> gitParseRevision gitRepoDir rev
<|> throw (IO.userError s!"cannot find revision {rev} in repository {gitRepoDir}")
def gitLatestOriginRevision (gitRepoDir : String) (branch : Option String) : IO String := do
discard <| IO.Process.run {cmd := "git", args := #["fetch"], cwd := gitRepoDir}
gitParseOriginRevision gitRepoDir (gitdefaultRevision branch)
def gitRevisionExists (gitRepoDir : String) (rev : String) : IO Bool := do
try
discard <| gitParseRevision gitRepoDir (rev ++ "^{commit}")
true
catch _ => false
end Leanpkg
|
0829c38b7620b7e7c3f6432768803fbb31d36da1 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/algebra/algebra/operations.lean | ca196177368d8b08e7a6e96ffa7a9dbe44ef33c7 | [
"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 | 24,428 | lean | /-
Copyright (c) 2019 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import algebra.algebra.bilinear
import algebra.module.submodule.pointwise
import algebra.module.submodule.bilinear
import algebra.module.opposites
import data.finset.pointwise
import data.set.semiring
import group_theory.group_action.sub_mul_action.pointwise
/-!
# Multiplication and division of submodules of an algebra.
An interface for multiplication and division of sub-R-modules of an R-algebra A is developed.
## Main definitions
Let `R` be a commutative ring (or semiring) and let `A` be an `R`-algebra.
* `1 : submodule R A` : the R-submodule R of the R-algebra A
* `has_mul (submodule R A)` : multiplication of two sub-R-modules M and N of A is defined to be
the smallest submodule containing all the products `m * n`.
* `has_div (submodule R A)` : `I / J` is defined to be the submodule consisting of all `a : A` such
that `a β’ J β I`
It is proved that `submodule R A` is a semiring, and also an algebra over `set A`.
Additionally, in the `pointwise` locale we promote `submodule.pointwise_distrib_mul_action` to a
`mul_semiring_action` as `submodule.pointwise_mul_semiring_action`.
## Tags
multiplication of submodules, division of submodules, submodule semiring
-/
universes uΞΉ u v
open algebra set mul_opposite
open_locale big_operators
open_locale pointwise
namespace sub_mul_action
variables {R : Type u} {A : Type v} [comm_semiring R] [semiring A] [algebra R A]
lemma algebra_map_mem (r : R) : algebra_map R A r β (1 : sub_mul_action R A) :=
β¨r, (algebra_map_eq_smul_one r).symmβ©
lemma mem_one' {x : A} : x β (1 : sub_mul_action R A) β β y, algebra_map R A y = x :=
exists_congr $ Ξ» r, by rw algebra_map_eq_smul_one
end sub_mul_action
namespace submodule
variables {ΞΉ : Sort uΞΉ}
variables {R : Type u} [comm_semiring R]
section ring
variables {A : Type v} [semiring A] [algebra R A]
variables (S T : set A) {M N P Q : submodule R A} {m n : A}
/-- `1 : submodule R A` is the submodule R of A. -/
instance : has_one (submodule R A) :=
β¨(algebra.linear_map R A).rangeβ©
theorem one_eq_range :
(1 : submodule R A) = (algebra.linear_map R A).range := rfl
lemma le_one_to_add_submonoid :
1 β€ (1 : submodule R A).to_add_submonoid :=
begin
rintros x β¨n, rflβ©,
exact β¨n, map_nat_cast (algebra_map R A) nβ©,
end
lemma algebra_map_mem (r : R) : algebra_map R A r β (1 : submodule R A) :=
linear_map.mem_range_self _ _
@[simp] lemma mem_one {x : A} : x β (1 : submodule R A) β β y, algebra_map R A y = x :=
iff.rfl
@[simp] lemma to_sub_mul_action_one : (1 : submodule R A).to_sub_mul_action = 1 :=
set_like.ext $ Ξ» x, mem_one.trans sub_mul_action.mem_one'.symm
theorem one_eq_span : (1 : submodule R A) = R β 1 :=
begin
apply submodule.ext,
intro a,
simp only [mem_one, mem_span_singleton, algebra.smul_def, mul_one]
end
theorem one_eq_span_one_set : (1 : submodule R A) = span R 1 := one_eq_span
theorem one_le : (1 : submodule R A) β€ P β (1 : A) β P :=
by simpa only [one_eq_span, span_le, set.singleton_subset_iff]
protected lemma map_one {A'} [semiring A'] [algebra R A'] (f : A ββ[R] A') :
map f.to_linear_map (1 : submodule R A) = 1 :=
by { ext, simp }
@[simp] lemma map_op_one :
map (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅) : A ββ[R] Aα΅α΅α΅) (1 : submodule R A) = 1 :=
by { ext, induction x using mul_opposite.rec, simp }
@[simp] lemma comap_op_one :
comap (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅) : A ββ[R] Aα΅α΅α΅) (1 : submodule R Aα΅α΅α΅) = 1 :=
by { ext, simp }
@[simp] lemma map_unop_one :
map (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅).symm : Aα΅α΅α΅ ββ[R] A) (1 : submodule R Aα΅α΅α΅) = 1 :=
by rw [βcomap_equiv_eq_map_symm, comap_op_one]
@[simp] lemma comap_unop_one :
comap (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅).symm : Aα΅α΅α΅ ββ[R] A) (1 : submodule R A) = 1 :=
by rw [βmap_equiv_eq_comap_symm, map_op_one]
/-- Multiplication of sub-R-modules of an R-algebra A. The submodule `M * N` is the
smallest R-submodule of `A` containing the elements `m * n` for `m β M` and `n β N`. -/
instance : has_mul (submodule R A) := β¨submodule.mapβ $ linear_map.mul R Aβ©
theorem mul_mem_mul (hm : m β M) (hn : n β N) : m * n β M * N := apply_mem_mapβ _ hm hn
theorem mul_le : M * N β€ P β β (m β M) (n β N), m * n β P := mapβ_le
lemma mul_to_add_submonoid (M N : submodule R A) :
(M * N).to_add_submonoid = M.to_add_submonoid * N.to_add_submonoid :=
begin
dsimp [has_mul.mul],
simp_rw [βlinear_map.mul_left_to_add_monoid_hom R, linear_map.mul_left, βmap_to_add_submonoid _ N,
mapβ],
rw supr_to_add_submonoid,
refl,
end
@[elab_as_eliminator] protected theorem mul_induction_on
{C : A β Prop} {r : A} (hr : r β M * N)
(hm : β (m β M) (n β N), C (m * n)) (ha : β x y, C x β C y β C (x + y)) : C r :=
begin
rw [βmem_to_add_submonoid, mul_to_add_submonoid] at hr,
exact add_submonoid.mul_induction_on hr hm ha,
end
/-- A dependent version of `mul_induction_on`. -/
@[elab_as_eliminator] protected theorem mul_induction_on'
{C : Ξ r, r β M * N β Prop}
(hm : β (m β M) (n β N), C (m * n) (mul_mem_mul βΉ_βΊ βΉ_βΊ))
(ha : β x hx y hy, C x hx β C y hy β C (x + y) (add_mem βΉ_βΊ βΉ_βΊ))
{r : A} (hr : r β M * N) : C r hr :=
begin
refine exists.elim _ (Ξ» (hr : r β M * N) (hc : C r hr), hc),
exact submodule.mul_induction_on hr
(Ξ» x hx y hy, β¨_, hm _ hx _ hyβ©) (Ξ» x y β¨_, hxβ© β¨_, hyβ©, β¨_, ha _ _ _ _ hx hyβ©),
end
variables R
theorem span_mul_span : span R S * span R T = span R (S * T) := mapβ_span_span _ _ _ _
variables {R}
variables (M N P Q)
@[simp] theorem mul_bot : M * β₯ = β₯ := mapβ_bot_right _ _
@[simp] theorem bot_mul : β₯ * M = β₯ := mapβ_bot_left _ _
@[simp] protected theorem one_mul : (1 : submodule R A) * M = M :=
by { conv_lhs { rw [one_eq_span, β span_eq M] }, erw [span_mul_span, one_mul, span_eq] }
@[simp] protected theorem mul_one : M * 1 = M :=
by { conv_lhs { rw [one_eq_span, β span_eq M] }, erw [span_mul_span, mul_one, span_eq] }
variables {M N P Q}
@[mono] theorem mul_le_mul (hmp : M β€ P) (hnq : N β€ Q) : M * N β€ P * Q := mapβ_le_mapβ hmp hnq
theorem mul_le_mul_left (h : M β€ N) : M * P β€ N * P := mapβ_le_mapβ_left h
theorem mul_le_mul_right (h : N β€ P) : M * N β€ M * P := mapβ_le_mapβ_right h
variables (M N P)
theorem mul_sup : M * (N β P) = M * N β M * P := mapβ_sup_right _ _ _ _
theorem sup_mul : (M β N) * P = M * P β N * P := mapβ_sup_left _ _ _ _
lemma mul_subset_mul : (βM : set A) * (βN : set A) β (β(M * N) : set A) :=
image2_subset_mapβ (algebra.lmul R A).to_linear_map M N
protected lemma map_mul {A'} [semiring A'] [algebra R A'] (f : A ββ[R] A') :
map f.to_linear_map (M * N) = map f.to_linear_map M * map f.to_linear_map N :=
calc map f.to_linear_map (M * N)
= β¨ (i : M), (N.map (linear_map.mul R A i)).map f.to_linear_map : map_supr _ _
... = map f.to_linear_map M * map f.to_linear_map N :
begin
apply congr_arg Sup,
ext S,
split; rintros β¨y, hyβ©,
{ use [f y, mem_map.mpr β¨y.1, y.2, rflβ©],
refine trans _ hy,
ext,
simp },
{ obtain β¨y', hy', fy_eqβ© := mem_map.mp y.2,
use [y', hy'],
refine trans _ hy,
rw f.to_linear_map_apply at fy_eq,
ext,
simp [fy_eq] }
end
lemma map_op_mul :
map (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅) : A ββ[R] Aα΅α΅α΅) (M * N) =
map (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅) : A ββ[R] Aα΅α΅α΅) N *
map (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅) : A ββ[R] Aα΅α΅α΅) M :=
begin
apply le_antisymm,
{ simp_rw map_le_iff_le_comap,
refine mul_le.2 (Ξ» m hm n hn, _),
rw [mem_comap, map_equiv_eq_comap_symm, map_equiv_eq_comap_symm],
show op n * op m β _,
exact mul_mem_mul hn hm },
{ refine mul_le.2 (mul_opposite.rec $ Ξ» m hm, mul_opposite.rec $ Ξ» n hn, _),
rw submodule.mem_map_equiv at β’ hm hn,
exact mul_mem_mul hn hm, }
end
lemma comap_unop_mul :
comap (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅).symm : Aα΅α΅α΅ ββ[R] A) (M * N) =
comap (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅).symm : Aα΅α΅α΅ ββ[R] A) N *
comap (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅).symm : Aα΅α΅α΅ ββ[R] A) M :=
by simp_rw [βmap_equiv_eq_comap_symm, map_op_mul]
lemma map_unop_mul (M N : submodule R Aα΅α΅α΅) :
map (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅).symm : Aα΅α΅α΅ ββ[R] A) (M * N) =
map (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅).symm : Aα΅α΅α΅ ββ[R] A) N *
map (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅).symm : Aα΅α΅α΅ ββ[R] A) M :=
have function.injective (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅) : A ββ[R] Aα΅α΅α΅) :=
linear_equiv.injective _,
map_injective_of_injective this $
by rw [β map_comp, map_op_mul, βmap_comp, βmap_comp, linear_equiv.comp_coe,
linear_equiv.symm_trans_self, linear_equiv.refl_to_linear_map, map_id, map_id, map_id]
lemma comap_op_mul (M N : submodule R Aα΅α΅α΅) :
comap (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅) : A ββ[R] Aα΅α΅α΅) (M * N) =
comap (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅) : A ββ[R] Aα΅α΅α΅) N *
comap (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅) : A ββ[R] Aα΅α΅α΅) M :=
by simp_rw [comap_equiv_eq_map_symm, map_unop_mul]
section
open_locale pointwise
/-- `submodule.has_pointwise_neg` distributes over multiplication.
This is available as an instance in the `pointwise` locale. -/
protected def has_distrib_pointwise_neg {A} [ring A] [algebra R A] :
has_distrib_neg (submodule R A) :=
to_add_submonoid_injective.has_distrib_neg _ neg_to_add_submonoid mul_to_add_submonoid
localized "attribute [instance] submodule.has_distrib_pointwise_neg" in pointwise
end
section decidable_eq
open_locale classical
lemma mem_span_mul_finite_of_mem_span_mul
{R A} [semiring R] [add_comm_monoid A] [has_mul A] [module R A]
{S : set A} {S' : set A} {x : A} (hx : x β span R (S * S')) :
β (T T' : finset A), βT β S β§ βT' β S' β§ x β span R (T * T' : set A) :=
begin
obtain β¨U, h, hUβ© := mem_span_finite_of_mem_span hx,
obtain β¨T, T', hS, hS', hβ© := finset.subset_mul h,
use [T, T', hS, hS'],
have h' : (U : set A) β T * T', { assumption_mod_cast, },
have h'' := span_mono h' hU,
assumption,
end
end decidable_eq
lemma mul_eq_span_mul_set (s t : submodule R A) : s * t = span R ((s : set A) * (t : set A)) :=
mapβ_eq_span_image2 _ s t
lemma supr_mul (s : ΞΉ β submodule R A) (t : submodule R A) : (β¨ i, s i) * t = β¨ i, s i * t :=
mapβ_supr_left _ s t
lemma mul_supr (t : submodule R A) (s : ΞΉ β submodule R A) : t * (β¨ i, s i) = β¨ i, t * s i :=
mapβ_supr_right _ t s
lemma mem_span_mul_finite_of_mem_mul {P Q : submodule R A} {x : A} (hx : x β P * Q) :
β (T T' : finset A), (T : set A) β P β§ (T' : set A) β Q β§ x β span R (T * T' : set A) :=
submodule.mem_span_mul_finite_of_mem_span_mul
(by rwa [β submodule.span_eq P, β submodule.span_eq Q, submodule.span_mul_span] at hx)
variables {M N P}
/-- Sub-R-modules of an R-algebra form a semiring. -/
instance : semiring (submodule R A) :=
{ one_mul := submodule.one_mul,
mul_one := submodule.mul_one,
zero_mul := bot_mul,
mul_zero := mul_bot,
left_distrib := mul_sup,
right_distrib := sup_mul,
..to_add_submonoid_injective.semigroup _ (Ξ» m n : submodule R A, mul_to_add_submonoid m n),
..add_monoid_with_one.unary,
..submodule.pointwise_add_comm_monoid,
..submodule.has_one,
..submodule.has_mul }
variables (M)
lemma span_pow (s : set A) : β n : β, span R s ^ n = span R (s ^ n)
| 0 := by rw [pow_zero, pow_zero, one_eq_span_one_set]
| (n + 1) := by rw [pow_succ, pow_succ, span_pow, span_mul_span]
lemma pow_eq_span_pow_set (n : β) : M ^ n = span R ((M : set A) ^ n) := by rw [βspan_pow, span_eq]
lemma pow_subset_pow {n : β} : (βM : set A)^n β β(M^n : submodule R A) :=
(pow_eq_span_pow_set M n).symm βΈ subset_span
lemma pow_mem_pow {x : A} (hx : x β M) (n : β) : x ^ n β M ^ n :=
pow_subset_pow _ $ set.pow_mem_pow hx _
lemma pow_to_add_submonoid {n : β} (h : n β 0) :
(M ^ n).to_add_submonoid = M.to_add_submonoid ^ n :=
begin
induction n with n ih,
{ exact (h rfl).elim },
{ rw [pow_succ, pow_succ, mul_to_add_submonoid],
cases n,
{ rw [pow_zero, pow_zero, mul_one, βmul_to_add_submonoid, mul_one] },
{ rw ih n.succ_ne_zero } },
end
lemma le_pow_to_add_submonoid {n : β} :
M.to_add_submonoid ^ n β€ (M ^ n).to_add_submonoid :=
begin
obtain rfl | hn := decidable.eq_or_ne n 0,
{ rw [pow_zero, pow_zero], exact le_one_to_add_submonoid },
{ exact (pow_to_add_submonoid M hn).ge }
end
/-- Dependent version of `submodule.pow_induction_on_left`. -/
@[elab_as_eliminator] protected theorem pow_induction_on_left'
{C : Ξ (n : β) x, x β M ^ n β Prop}
(hr : β r : R, C 0 (algebra_map _ _ r) (algebra_map_mem r))
(hadd : β x y i hx hy, C i x hx β C i y hy β C i (x + y) (add_mem βΉ_βΊ βΉ_βΊ))
(hmul : β (m β M) i x hx, C i x hx β C (i.succ) (m * x) (mul_mem_mul H hx))
{x : A} {n : β} (hx : x β M ^ n) : C n x hx :=
begin
induction n with n n_ih generalizing x,
{ rw pow_zero at hx,
obtain β¨r, rflβ© := hx,
exact hr r, },
exact submodule.mul_induction_on'
(Ξ» m hm x ih, hmul _ hm _ _ _ (n_ih ih))
(Ξ» x hx y hy Cx Cy, hadd _ _ _ _ _ Cx Cy) hx,
end
/-- Dependent version of `submodule.pow_induction_on_right`. -/
@[elab_as_eliminator] protected theorem pow_induction_on_right'
{C : Ξ (n : β) x, x β M ^ n β Prop}
(hr : β r : R, C 0 (algebra_map _ _ r) (algebra_map_mem r))
(hadd : β x y i hx hy, C i x hx β C i y hy β C i (x + y) (add_mem βΉ_βΊ βΉ_βΊ))
(hmul : β i x hx, C i x hx β β m β M,
C (i.succ) (x * m) ((pow_succ' M i).symm βΈ mul_mem_mul hx H))
{x : A} {n : β} (hx : x β M ^ n) : C n x hx :=
begin
induction n with n n_ih generalizing x,
{ rw pow_zero at hx,
obtain β¨r, rflβ© := hx,
exact hr r, },
revert hx,
simp_rw pow_succ',
intro hx,
exact submodule.mul_induction_on'
(Ξ» m hm x ih, hmul _ _ hm (n_ih _) _ ih)
(Ξ» x hx y hy Cx Cy, hadd _ _ _ _ _ Cx Cy) hx,
end
/-- To show a property on elements of `M ^ n` holds, it suffices to show that it holds for scalars,
is closed under addition, and holds for `m * x` where `m β M` and it holds for `x` -/
@[elab_as_eliminator] protected theorem pow_induction_on_left
{C : A β Prop}
(hr : β r : R, C (algebra_map _ _ r))
(hadd : β x y, C x β C y β C (x + y))
(hmul : β (m β M) x, C x β C (m * x))
{x : A} {n : β} (hx : x β M ^ n) : C x :=
submodule.pow_induction_on_left' M
(by exact hr) (Ξ» x y i hx hy, hadd x y) (Ξ» m hm i x hx, hmul _ hm _) hx
/-- To show a property on elements of `M ^ n` holds, it suffices to show that it holds for scalars,
is closed under addition, and holds for `x * m` where `m β M` and it holds for `x` -/
@[elab_as_eliminator] protected theorem pow_induction_on_right
{C : A β Prop}
(hr : β r : R, C (algebra_map _ _ r))
(hadd : β x y, C x β C y β C (x + y))
(hmul : β x, C x β β (m β M), C (x * m))
{x : A} {n : β} (hx : x β M ^ n) : C x :=
submodule.pow_induction_on_right' M
(by exact hr) (Ξ» x y i hx hy, hadd x y) (Ξ» i x hx, hmul _) hx
/-- `submonoid.map` as a `monoid_with_zero_hom`, when applied to `alg_hom`s. -/
@[simps]
def map_hom {A'} [semiring A'] [algebra R A'] (f : A ββ[R] A') :
submodule R A β*β submodule R A' :=
{ to_fun := map f.to_linear_map,
map_zero' := submodule.map_bot _,
map_one' := submodule.map_one _,
map_mul' := Ξ» _ _, submodule.map_mul _ _ _}
/-- The ring of submodules of the opposite algebra is isomorphic to the opposite ring of
submodules. -/
@[simps apply symm_apply]
def equiv_opposite : submodule R Aα΅α΅α΅ β+* (submodule R A)α΅α΅α΅ :=
{ to_fun := Ξ» p, op $ p.comap (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅) : A ββ[R] Aα΅α΅α΅),
inv_fun := Ξ» p, p.unop.comap (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅).symm : Aα΅α΅α΅ ββ[R] A),
left_inv := Ξ» p, set_like.coe_injective $ rfl,
right_inv := Ξ» p, unop_injective $ set_like.coe_injective rfl,
map_add' := Ξ» p q, by simp [comap_equiv_eq_map_symm, βop_add],
map_mul' := Ξ» p q, congr_arg op $ comap_op_mul _ _ }
protected lemma map_pow {A'} [semiring A'] [algebra R A'] (f : A ββ[R] A') (n : β) :
map f.to_linear_map (M ^ n) = map f.to_linear_map M ^ n :=
map_pow (map_hom f) M n
lemma comap_unop_pow (n : β) :
comap (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅).symm : Aα΅α΅α΅ ββ[R] A) (M ^ n) =
comap (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅).symm : Aα΅α΅α΅ ββ[R] A) M ^ n :=
(equiv_opposite : submodule R Aα΅α΅α΅ β+* _).symm.map_pow (op M) n
lemma comap_op_pow (n : β) (M : submodule R Aα΅α΅α΅) :
comap (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅) : A ββ[R] Aα΅α΅α΅) (M ^ n) =
comap (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅) : A ββ[R] Aα΅α΅α΅) M ^ n :=
op_injective $ (equiv_opposite : submodule R Aα΅α΅α΅ β+* _).map_pow M n
lemma map_op_pow (n : β) :
map (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅) : A ββ[R] Aα΅α΅α΅) (M ^ n) =
map (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅) : A ββ[R] Aα΅α΅α΅) M ^ n :=
by rw [map_equiv_eq_comap_symm, map_equiv_eq_comap_symm, comap_unop_pow]
lemma map_unop_pow (n : β) (M : submodule R Aα΅α΅α΅) :
map (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅).symm : Aα΅α΅α΅ ββ[R] A) (M ^ n) =
map (β(op_linear_equiv R : A ββ[R] Aα΅α΅α΅).symm : Aα΅α΅α΅ ββ[R] A) M ^ n :=
by rw [βcomap_equiv_eq_map_symm, βcomap_equiv_eq_map_symm, comap_op_pow]
/-- `span` is a semiring homomorphism (recall multiplication is pointwise multiplication of subsets
on either side). -/
def span.ring_hom : set_semiring A β+* submodule R A :=
{ to_fun := submodule.span R,
map_zero' := span_empty,
map_one' := one_eq_span.symm,
map_add' := span_union,
map_mul' := Ξ» s t, by erw [span_mul_span, β image_mul_prod] }
section
variables {Ξ± : Type*} [monoid Ξ±] [mul_semiring_action Ξ± A] [smul_comm_class Ξ± R A]
/-- The action on a submodule corresponding to applying the action to every element.
This is available as an instance in the `pointwise` locale.
This is a stronger version of `submodule.pointwise_distrib_mul_action`. -/
protected def pointwise_mul_semiring_action : mul_semiring_action Ξ± (submodule R A) :=
{ smul_mul := Ξ» r x y, submodule.map_mul x y $ mul_semiring_action.to_alg_hom R A r,
smul_one := Ξ» r, submodule.map_one $ mul_semiring_action.to_alg_hom R A r,
..submodule.pointwise_distrib_mul_action }
localized "attribute [instance] submodule.pointwise_mul_semiring_action" in pointwise
end
end ring
section comm_ring
variables {A : Type v} [comm_semiring A] [algebra R A]
variables {M N : submodule R A} {m n : A}
theorem mul_mem_mul_rev (hm : m β M) (hn : n β N) : n * m β M * N :=
mul_comm m n βΈ mul_mem_mul hm hn
variables (M N)
protected theorem mul_comm : M * N = N * M :=
le_antisymm (mul_le.2 $ Ξ» r hrm s hsn, mul_mem_mul_rev hsn hrm)
(mul_le.2 $ Ξ» r hrn s hsm, mul_mem_mul_rev hsm hrn)
/-- Sub-R-modules of an R-algebra A form a semiring. -/
instance : comm_semiring (submodule R A) :=
{ mul_comm := submodule.mul_comm,
.. submodule.semiring }
lemma prod_span {ΞΉ : Type*} (s : finset ΞΉ) (M : ΞΉ β set A) :
(β i in s, submodule.span R (M i)) = submodule.span R (β i in s, M i) :=
begin
letI := classical.dec_eq ΞΉ,
refine finset.induction_on s _ _,
{ simp [one_eq_span, set.singleton_one] },
{ intros _ _ H ih,
rw [finset.prod_insert H, finset.prod_insert H, ih, span_mul_span] }
end
lemma prod_span_singleton {ΞΉ : Type*} (s : finset ΞΉ) (x : ΞΉ β A) :
(β i in s, span R ({x i} : set A)) = span R {β i in s, x i} :=
by rw [prod_span, set.finset_prod_singleton]
variables (R A)
/-- R-submodules of the R-algebra A are a module over `set A`. -/
instance module_set : module (set_semiring A) (submodule R A) :=
{ smul := Ξ» s P, span R s * P,
smul_add := Ξ» _ _ _, mul_add _ _ _,
add_smul := Ξ» s t P, show span R (s β t) * P = _, by { erw [span_union, right_distrib] },
mul_smul := Ξ» s t P, show _ = _ * (_ * _),
by { rw [β mul_assoc, span_mul_span, β image_mul_prod] },
one_smul := Ξ» P, show span R {(1 : A)} * P = _,
by { conv_lhs {erw β span_eq P}, erw [span_mul_span, one_mul, span_eq] },
zero_smul := Ξ» P, show span R β
* P = β₯, by erw [span_empty, bot_mul],
smul_zero := Ξ» _, mul_bot _ }
variables {R A}
lemma smul_def {s : set_semiring A} {P : submodule R A} : s β’ P = span R s * P := rfl
lemma smul_le_smul {s t : set_semiring A} {M N : submodule R A} (hβ : s.down β€ t.down)
(hβ : M β€ N) : s β’ M β€ t β’ N :=
mul_le_mul (span_mono hβ) hβ
lemma smul_singleton (a : A) (M : submodule R A) :
({a} : set A).up β’ M = M.map (linear_map.mul_left R a) :=
begin
conv_lhs {rw β span_eq M},
change span _ _ * span _ _ = _,
rw [span_mul_span],
apply le_antisymm,
{ rw span_le,
rintros _ β¨b, m, hb, hm, rflβ©,
rw [set_like.mem_coe, mem_map, set.mem_singleton_iff.mp hb],
exact β¨m, hm, rflβ© },
{ rintros _ β¨m, hm, rflβ©, exact subset_span β¨a, m, set.mem_singleton a, hm, rflβ© }
end
section quotient
/-- The elements of `I / J` are the `x` such that `x β’ J β I`.
In fact, we define `x β I / J` to be `β y β J, x * y β I` (see `mem_div_iff_forall_mul_mem`),
which is equivalent to `x β’ J β I` (see `mem_div_iff_smul_subset`), but nicer to use in proofs.
This is the general form of the ideal quotient, traditionally written $I : J$.
-/
instance : has_div (submodule R A) :=
β¨ Ξ» I J,
{ carrier := { x | β y β J, x * y β I },
zero_mem' := Ξ» y hy, by { rw zero_mul, apply submodule.zero_mem },
add_mem' := Ξ» a b ha hb y hy, by { rw add_mul, exact submodule.add_mem _ (ha _ hy) (hb _ hy) },
smul_mem' := Ξ» r x hx y hy, by { rw algebra.smul_mul_assoc,
exact submodule.smul_mem _ _ (hx _ hy) } } β©
lemma mem_div_iff_forall_mul_mem {x : A} {I J : submodule R A} :
x β I / J β β y β J, x * y β I :=
iff.refl _
lemma mem_div_iff_smul_subset {x : A} {I J : submodule R A} : x β I / J β x β’ (J : set A) β I :=
β¨ Ξ» h y β¨y', hy', xy'_eq_yβ©, by { rw β xy'_eq_y, apply h, assumption },
Ξ» h y hy, h (set.smul_mem_smul_set hy) β©
lemma le_div_iff {I J K : submodule R A} : I β€ J / K β β (x β I) (z β K), x * z β J := iff.refl _
lemma le_div_iff_mul_le {I J K : submodule R A} : I β€ J / K β I * K β€ J :=
by rw [le_div_iff, mul_le]
@[simp] lemma one_le_one_div {I : submodule R A} :
1 β€ 1 / I β I β€ 1 :=
begin
split, all_goals {intro hI},
{rwa [le_div_iff_mul_le, one_mul] at hI},
{rwa [le_div_iff_mul_le, one_mul]},
end
lemma le_self_mul_one_div {I : submodule R A} (hI : I β€ 1) :
I β€ I * (1 / I) :=
begin
rw [β mul_one I] {occs := occurrences.pos [1]},
apply mul_le_mul_right (one_le_one_div.mpr hI),
end
lemma mul_one_div_le_one {I : submodule R A} : I * (1 / I) β€ 1 :=
begin
rw submodule.mul_le,
intros m hm n hn,
rw [submodule.mem_div_iff_forall_mul_mem] at hn,
rw mul_comm,
exact hn m hm,
end
@[simp] protected lemma map_div {B : Type*} [comm_semiring B] [algebra R B]
(I J : submodule R A) (h : A ββ[R] B) :
(I / J).map h.to_linear_map = I.map h.to_linear_map / J.map h.to_linear_map :=
begin
ext x,
simp only [mem_map, mem_div_iff_forall_mul_mem],
split,
{ rintro β¨x, hx, rflβ© _ β¨y, hy, rflβ©,
exact β¨x * y, hx _ hy, h.map_mul x yβ© },
{ rintro hx,
refine β¨h.symm x, Ξ» z hz, _, h.apply_symm_apply xβ©,
obtain β¨xz, xz_mem, hxzβ© := hx (h z) β¨z, hz, rflβ©,
convert xz_mem,
apply h.injective,
erw [h.map_mul, h.apply_symm_apply, hxz] }
end
end quotient
end comm_ring
end submodule
|
a7b1d4d323475d310744c3ba5454d3c7523b7c9c | 1b8f093752ba748c5ca0083afef2959aaa7dace5 | /src/category_theory/universal/constructions/from_limits.lean | 1364b2b16396fe9b98a173664b5ceb28934d14b2 | [] | no_license | khoek/lean-category-theory | 7ec4cda9cc64a5a4ffeb84712ac7d020dbbba386 | 63dcb598e9270a3e8b56d1769eb4f825a177cd95 | refs/heads/master | 1,585,251,725,759 | 1,539,344,445,000 | 1,539,344,445,000 | 145,281,070 | 0 | 0 | null | 1,534,662,376,000 | 1,534,662,376,000 | null | UTF-8 | Lean | false | false | 3,853 | 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 category_theory.universal.complete
-- import category_theory.walking
-- import tidy.its
-- open category_theory
-- open category_theory.initial
-- open category_theory.walking
-- namespace category_theory.universal
-- universes uβ uβ uβ uβ
-- section
-- variable {J : Type uβ}
-- variable [small_category J]
-- variable {C : Type (uβ+1)}
-- variable [large_category C]
-- variables {F : J β₯€ C} {L : LimitCone F} {Z : C}
-- private def Cone_from_map_to_limit (f : Z βΆ L.obj.cone_point) : Cone F := {
-- cone_point := Z,
-- cone_maps := Ξ» j, f β« (L.obj.cone_maps j)
-- }
-- private def ConeMorphism_from_map_to_limit (f : Z βΆ L.obj.cone_point) : ConeMorphism (Cone_from_map_to_limit f) L.obj := {
-- cone_morphism := f
-- }
-- end
-- variable {C : Type (uβ+1)}
-- variable [large_category C]
-- -- PROJECT this construction is unpleasant
-- section
-- open tactic
-- meta def induction_WalkingParallelPair : tactic unit :=
-- do l β local_context,
-- at_least_one (l.reverse.map (Ξ» h, do t β infer_type h, t β whnf t, match t with | `(WalkingParallelPair) := induction h >> skip | `(Two) := induction h >> skip | _ := failed end)),
-- skip
-- end
-- local attribute [tidy] induction_WalkingParallelPair
-- instance Equalizers_from_Limits [Complete C] : has_Equalizers.{uβ+1 uβ} C := {
-- equalizer := Ξ» X Y f g, let lim := limitCone (ParallelPair_functor f g) in {
-- equalizer := lim.obj.cone_point,
-- inclusion := lim.obj.cone_maps WalkingParallelPair._1,
-- witness := let commutativity := @Cone.commutativity_lemma _ _ _ _ _ lim.obj WalkingParallelPair._1 WalkingParallelPair._2 in
-- begin
-- erw commutativity Two._0,
-- erw commutativity Two._1,
-- end,
-- map := by obviously,
-- factorisation := by obviously,
-- uniqueness := begin
-- tidy,
-- let Z_cone : Cone (ParallelPair_functor f g) :=
-- { cone_point := Z,
-- cone_maps := Ξ» j : WalkingParallelPair, a β« (lim.obj.cone_maps j), },
-- have p := lim.uniqueness Z_cone β¨ a, _ β© β¨ b, _ β©,
-- have q := congr_arg ConeMorphism.cone_morphism p,
-- exact q,
-- tidy,
-- have c := lim.obj.commutativity,
-- dsimp at c,
-- rw β @c WalkingParallelPair._1 WalkingParallelPair._2 Two._1,
-- repeat {rw β category.assoc},
-- rw witness,
-- end
-- }
-- }
-- instance Products_from_Limits [Complete C] : has_Products C := {
-- product := Ξ» {I : Type uβ} (F : I β C),
-- let lim_F := limitCone (functor.fromFunction F) in
-- {
-- product := lim_F.obj.cone_point,
-- projection := Ξ» i, lim_F.obj.cone_maps i,
-- uniqueness := Ξ» Z f g _, begin
-- have p := lim_F.uniqueness,
-- have q := p _ (ConeMorphism_from_map_to_limit f) {cone_morphism := g},
-- tidy,
-- end,
-- map := Ξ» Z i, (lim_F.Β«fromΒ» { cone_point := Z, cone_maps := i }).cone_morphism
-- }
-- }
-- end category_theory.universal |
829405acdb336f8d532d6d9058a75e059b8d4c1c | 07c76fbd96ea1786cc6392fa834be62643cea420 | /hott/homotopy/interval.hlean | 78a6ea0fa2beb7534dfffbe9a1e93e04a2896022 | [
"Apache-2.0"
] | permissive | fpvandoorn/lean2 | 5a430a153b570bf70dc8526d06f18fc000a60ad9 | 0889cf65b7b3cebfb8831b8731d89c2453dd1e9f | refs/heads/master | 1,592,036,508,364 | 1,545,093,958,000 | 1,545,093,958,000 | 75,436,854 | 0 | 0 | null | 1,480,718,780,000 | 1,480,718,780,000 | null | UTF-8 | Lean | false | false | 3,460 | hlean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
Declaration of the interval
-/
import .susp types.eq types.prod cubical.square
open eq susp unit equiv is_trunc nat prod pointed
definition interval : Typeβ := susp unit
namespace interval
definition zero : interval := north
definition one : interval := south
definition seg : zero = one := merid star
protected definition rec {P : interval β Type} (P0 : P zero) (P1 : P one)
(Ps : P0 =[seg] P1) (x : interval) : P x :=
begin
fapply susp.rec_on x,
{ exact P0},
{ exact P1},
{ intro x, cases x, exact Ps}
end
protected definition rec_on [reducible] {P : interval β Type} (x : interval)
(P0 : P zero) (P1 : P one) (Ps : P0 =[seg] P1) : P x :=
interval.rec P0 P1 Ps x
theorem rec_seg {P : interval β Type} (P0 : P zero) (P1 : P one) (Ps : P0 =[seg] P1)
: apd (interval.rec P0 P1 Ps) seg = Ps :=
!rec_merid
protected definition elim {P : Type} (P0 P1 : P) (Ps : P0 = P1) (x : interval) : P :=
interval.rec P0 P1 (pathover_of_eq _ Ps) x
protected definition elim_on [reducible] {P : Type} (x : interval) (P0 P1 : P)
(Ps : P0 = P1) : P :=
interval.elim P0 P1 Ps x
theorem elim_seg {P : Type} (P0 P1 : P) (Ps : P0 = P1)
: ap (interval.elim P0 P1 Ps) seg = Ps :=
begin
apply inj_inv !(pathover_constant seg),
rewrite [βΈ*,-apd_eq_pathover_of_eq_ap,βinterval.elim,rec_seg],
end
protected definition elim_type (P0 P1 : Type) (Ps : P0 β P1) (x : interval) : Type :=
interval.elim P0 P1 (ua Ps) x
protected definition elim_type_on [reducible] (x : interval) (P0 P1 : Type) (Ps : P0 β P1)
: Type :=
interval.elim_type P0 P1 Ps x
theorem elim_type_seg (P0 P1 : Type) (Ps : P0 β P1)
: transport (interval.elim_type P0 P1 Ps) seg = Ps :=
by rewrite [tr_eq_cast_ap_fn,βinterval.elim_type,elim_seg];apply cast_ua_fn
definition is_contr_interval [instance] [priority 900] : is_contr interval :=
is_contr.mk zero (Ξ»x, interval.rec_on x idp seg !eq_pathover_r_idp)
definition naive_funext_of_interval : naive_funext :=
Ξ»A P f g p, ap (Ξ»(i : interval) (x : A), interval.elim_on i (f x) (g x) (p x)) seg
definition funext_of_interval : funext :=
funext_from_naive_funext naive_funext_of_interval
end interval open interval
definition cube : β β Typeβ
| cube 0 := unit
| cube (succ n) := cube n Γ interval
abbreviation square := cube (succ (succ nat.zero))
definition cube_one_equiv_interval : cube 1 β interval :=
!prod_comm_equiv β¬e !prod_unit_equiv
definition prod_square {A B : Type} {a a' : A} {b b' : B} (p : a = a') (q : b = b')
: square (pair_eq p idp) (pair_eq p idp) (pair_eq idp q) (pair_eq idp q) :=
by cases p; cases q; exact ids
namespace square
definition tl : square := (star, zero, zero)
definition tr : square := (star, one, zero)
definition bl : square := (star, zero, one )
definition br : square := (star, one, one )
-- s stands for "square" in the following definitions
definition st : tl = tr := pair_eq (pair_eq idp seg) idp
definition sb : bl = br := pair_eq (pair_eq idp seg) idp
definition sl : tl = bl := pair_eq idp seg
definition sr : tr = br := pair_eq idp seg
definition sfill : square st sb sl sr := !prod_square
definition fill : st β¬ sr = sl β¬ sb := !square_equiv_eq sfill
end square
|
79cec0d82f4a433f5bf69c43ca84c3cbb524f140 | ec5a7ae10c533e1b1f4b0bc7713e91ecf829a3eb | /ijcar16/examples/cc5.lean | cd84695c6d6daa1876bd572d7e6ff80003850927 | [
"MIT"
] | permissive | leanprover/leanprover.github.io | cf248934af7c7e9aeff17cf8df3c12c5e7e73f1a | 071a20d2e059a2c3733e004c681d3949cac3c07a | refs/heads/master | 1,692,621,047,417 | 1,691,396,994,000 | 1,691,396,994,000 | 19,366,263 | 18 | 27 | MIT | 1,693,989,071,000 | 1,399,006,345,000 | Lean | UTF-8 | Lean | false | false | 584 | lean | /-
Example/test file for the congruence closure procedure described in the paper:
"Congruence Closure for Intensional Type Theory"
Daniel Selsam and Leonardo de Moura
The tactic `by blast` has been configured in this file to use just
the congruence closure procedure using the command
set_option blast.strategy "cc"
-/
set_option blast.strategy "cc"
/-
The implemented procedure supports arbitrary equivalence relations.
In the following example, it is using the relation β
-/
example (a b c : Prop) : (a β b) β ((a β§ (c β¨ b)) β (b β§ (c β¨ a))) :=
by blast
|
3ff77c083492fb85a32a62f37bcdc99507aefdca | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/analysis/special_functions/trigonometric/complex.lean | cfc98592859160d2198a230dd97e3dc473d29075 | [
"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 | 9,444 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne, Benjamin Davidson
-/
import algebra.quadratic_discriminant
import analysis.complex.polynomial
import field_theory.is_alg_closed.basic
import analysis.special_functions.trigonometric.basic
import analysis.convex.specific_functions
/-!
# Complex trigonometric functions
Basic facts and derivatives for the complex trigonometric functions.
Several facts about the real trigonometric functions have the proofs deferred here, rather than
`analysis.special_functions.trigonometric.basic`,
as they are most easily proved by appealing to the corresponding fact for complex trigonometric
functions, or require additional imports which are not available in that file.
-/
noncomputable theory
namespace complex
open set filter
open_locale real
theorem cos_eq_zero_iff {ΞΈ : β} : cos ΞΈ = 0 β β k : β€, ΞΈ = (2 * k + 1) * Ο / 2 :=
begin
have h : (exp (ΞΈ * I) + exp (-ΞΈ * I)) / 2 = 0 β exp (2 * ΞΈ * I) = -1,
{ rw [@div_eq_iff _ _ (exp (ΞΈ * I) + exp (-ΞΈ * I)) 2 0 two_ne_zero', zero_mul,
add_eq_zero_iff_eq_neg, neg_eq_neg_one_mul, β div_eq_iff (exp_ne_zero _), β exp_sub],
field_simp only, congr' 3, ring },
rw [cos, h, β exp_pi_mul_I, exp_eq_exp_iff_exists_int, mul_right_comm],
refine exists_congr (Ξ» x, _),
refine (iff_of_eq $ congr_arg _ _).trans (mul_right_inj' $ mul_ne_zero two_ne_zero' I_ne_zero),
field_simp, ring,
end
theorem cos_ne_zero_iff {ΞΈ : β} : cos ΞΈ β 0 β β k : β€, ΞΈ β (2 * k + 1) * Ο / 2 :=
by rw [β not_exists, not_iff_not, cos_eq_zero_iff]
theorem sin_eq_zero_iff {ΞΈ : β} : sin ΞΈ = 0 β β k : β€, ΞΈ = k * Ο :=
begin
rw [β complex.cos_sub_pi_div_two, cos_eq_zero_iff],
split,
{ rintros β¨k, hkβ©,
use k + 1,
field_simp [eq_add_of_sub_eq hk],
ring },
{ rintros β¨k, rflβ©,
use k - 1,
field_simp,
ring }
end
theorem sin_ne_zero_iff {ΞΈ : β} : sin ΞΈ β 0 β β k : β€, ΞΈ β k * Ο :=
by rw [β not_exists, not_iff_not, sin_eq_zero_iff]
lemma tan_eq_zero_iff {ΞΈ : β} : tan ΞΈ = 0 β β k : β€, ΞΈ = k * Ο / 2 :=
begin
have h := (sin_two_mul ΞΈ).symm,
rw mul_assoc at h,
rw [tan, div_eq_zero_iff, β mul_eq_zero, β zero_mul ((1/2):β), mul_one_div,
cancel_factors.cancel_factors_eq_div h two_ne_zero', mul_comm],
simpa only [zero_div, zero_mul, ne.def, not_false_iff] with field_simps using sin_eq_zero_iff,
end
lemma tan_ne_zero_iff {ΞΈ : β} : tan ΞΈ β 0 β β k : β€, ΞΈ β k * Ο / 2 :=
by rw [β not_exists, not_iff_not, tan_eq_zero_iff]
lemma tan_int_mul_pi_div_two (n : β€) : tan (n * Ο/2) = 0 :=
tan_eq_zero_iff.mpr (by use n)
lemma cos_eq_cos_iff {x y : β} :
cos x = cos y β β k : β€, y = 2 * k * Ο + x β¨ y = 2 * k * Ο - x :=
calc cos x = cos y β cos x - cos y = 0 : sub_eq_zero.symm
... β -2 * sin((x + y)/2) * sin((x - y)/2) = 0 : by rw cos_sub_cos
... β sin((x + y)/2) = 0 β¨ sin((x - y)/2) = 0 : by simp [(by norm_num : (2:β) β 0)]
... β sin((x - y)/2) = 0 β¨ sin((x + y)/2) = 0 : or.comm
... β (β k : β€, y = 2 * k * Ο + x) β¨ (β k :β€, y = 2 * k * Ο - x) :
begin
apply or_congr;
field_simp [sin_eq_zero_iff, (by norm_num : -(2:β) β 0), eq_sub_iff_add_eq',
sub_eq_iff_eq_add, mul_comm (2:β), mul_right_comm _ (2:β)],
split; { rintros β¨k, rflβ©, use -k, simp, },
end
... β β k : β€, y = 2 * k * Ο + x β¨ y = 2 * k * Ο - x : exists_or_distrib.symm
lemma sin_eq_sin_iff {x y : β} :
sin x = sin y β β k : β€, y = 2 * k * Ο + x β¨ y = (2 * k + 1) * Ο - x :=
begin
simp only [β complex.cos_sub_pi_div_two, cos_eq_cos_iff, sub_eq_iff_eq_add],
refine exists_congr (Ξ» k, or_congr _ _); refine eq.congr rfl _; field_simp; ring
end
lemma tan_add {x y : β}
(h : ((β k : β€, x β (2 * k + 1) * Ο / 2) β§ β l : β€, y β (2 * l + 1) * Ο / 2)
β¨ ((β k : β€, x = (2 * k + 1) * Ο / 2) β§ β l : β€, y = (2 * l + 1) * Ο / 2)) :
tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=
begin
rcases h with β¨h1, h2β© | β¨β¨k, rflβ©, β¨l, rflβ©β©,
{ rw [tan, sin_add, cos_add,
β div_div_div_cancel_right (sin x * cos y + cos x * sin y)
(mul_ne_zero (cos_ne_zero_iff.mpr h1) (cos_ne_zero_iff.mpr h2)),
add_div, sub_div],
simp only [βdiv_mul_div_comm, βtan, mul_one, one_mul,
div_self (cos_ne_zero_iff.mpr h1), div_self (cos_ne_zero_iff.mpr h2)] },
{ obtain β¨t, hx, hy, hxyβ© := β¨tan_int_mul_pi_div_two, t (2*k+1), t (2*l+1), t (2*k+1+(2*l+1))β©,
simp only [int.cast_add, int.cast_bit0, int.cast_mul, int.cast_one, hx, hy] at hx hy hxy,
rw [hx, hy, add_zero, zero_div,
mul_div_assoc, mul_div_assoc, β add_mul (2*(k:β)+1) (2*l+1) (Ο/2), β mul_div_assoc, hxy] },
end
lemma tan_add' {x y : β}
(h : ((β k : β€, x β (2 * k + 1) * Ο / 2) β§ β l : β€, y β (2 * l + 1) * Ο / 2)) :
tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=
tan_add (or.inl h)
lemma tan_two_mul {z : β} : tan (2 * z) = 2 * tan z / (1 - tan z ^ 2) :=
begin
by_cases h : β k : β€, z β (2 * k + 1) * Ο / 2,
{ rw [two_mul, two_mul, sq, tan_add (or.inl β¨h, hβ©)] },
{ rw not_forall_not at h,
rw [two_mul, two_mul, sq, tan_add (or.inr β¨h, hβ©)] },
end
lemma tan_add_mul_I {x y : β}
(h : ((β k : β€, x β (2 * k + 1) * Ο / 2) β§ β l : β€, y * I β (2 * l + 1) * Ο / 2)
β¨ ((β k : β€, x = (2 * k + 1) * Ο / 2) β§ β l : β€, y * I = (2 * l + 1) * Ο / 2)) :
tan (x + y*I) = (tan x + tanh y * I) / (1 - tan x * tanh y * I) :=
by rw [tan_add h, tan_mul_I, mul_assoc]
lemma tan_eq {z : β}
(h : ((β k : β€, (z.re:β) β (2 * k + 1) * Ο / 2) β§ β l : β€, (z.im:β) * I β (2 * l + 1) * Ο / 2)
β¨ ((β k : β€, (z.re:β) = (2 * k + 1) * Ο / 2) β§ β l : β€, (z.im:β) * I = (2 * l + 1) * Ο / 2)) :
tan z = (tan z.re + tanh z.im * I) / (1 - tan z.re * tanh z.im * I) :=
by convert tan_add_mul_I h; exact (re_add_im z).symm
open_locale topological_space
lemma continuous_on_tan : continuous_on tan {x | cos x β 0} :=
continuous_on_sin.div continuous_on_cos $ Ξ» x, id
@[continuity]
lemma continuous_tan : continuous (Ξ» x : {x | cos x β 0}, tan x) :=
continuous_on_iff_continuous_restrict.1 continuous_on_tan
lemma cos_eq_iff_quadratic {z w : β} :
cos z = w β (exp (z * I)) ^ 2 - 2 * w * exp (z * I) + 1 = 0 :=
begin
rw β sub_eq_zero,
field_simp [cos, exp_neg, exp_ne_zero],
refine eq.congr _ rfl,
ring
end
lemma cos_surjective : function.surjective cos :=
begin
intro x,
obtain β¨w, wβ, hwβ© : β w β 0, 1 * w * w + (-2 * x) * w + 1 = 0,
{ rcases exists_quadratic_eq_zero (@one_ne_zero β _ _) (is_alg_closed.exists_eq_mul_self _)
with β¨w, hwβ©,
refine β¨w, _, hwβ©,
rintro rfl,
simpa only [zero_add, one_ne_zero, mul_zero] using hw },
refine β¨log w / I, cos_eq_iff_quadratic.2 _β©,
rw [div_mul_cancel _ I_ne_zero, exp_log wβ],
convert hw,
ring
end
@[simp] lemma range_cos : range cos = set.univ :=
cos_surjective.range_eq
lemma sin_surjective : function.surjective sin :=
begin
intro x,
rcases cos_surjective x with β¨z, rflβ©,
exact β¨z + Ο / 2, sin_add_pi_div_two zβ©
end
@[simp] lemma range_sin : range sin = set.univ :=
sin_surjective.range_eq
end complex
namespace real
open_locale real
theorem cos_eq_zero_iff {ΞΈ : β} : cos ΞΈ = 0 β β k : β€, ΞΈ = (2 * k + 1) * Ο / 2 :=
by exact_mod_cast @complex.cos_eq_zero_iff ΞΈ
theorem cos_ne_zero_iff {ΞΈ : β} : cos ΞΈ β 0 β β k : β€, ΞΈ β (2 * k + 1) * Ο / 2 :=
by rw [β not_exists, not_iff_not, cos_eq_zero_iff]
lemma cos_eq_cos_iff {x y : β} :
cos x = cos y β β k : β€, y = 2 * k * Ο + x β¨ y = 2 * k * Ο - x :=
by exact_mod_cast @complex.cos_eq_cos_iff x y
lemma sin_eq_sin_iff {x y : β} :
sin x = sin y β β k : β€, y = 2 * k * Ο + x β¨ y = (2 * k + 1) * Ο - x :=
by exact_mod_cast @complex.sin_eq_sin_iff x y
lemma lt_sin_mul {x : β} (hx : 0 < x) (hx' : x < 1) : x < sin ((Ο / 2) * x) :=
by simpa [mul_comm x] using strict_concave_on_sin_Icc.2 β¨le_rfl, pi_pos.leβ©
β¨pi_div_two_pos.le, half_le_self pi_pos.leβ© pi_div_two_pos.ne (sub_pos.2 hx') hx
lemma le_sin_mul {x : β} (hx : 0 β€ x) (hx' : x β€ 1) : x β€ sin ((Ο / 2) * x) :=
by simpa [mul_comm x] using strict_concave_on_sin_Icc.concave_on.2 β¨le_rfl, pi_pos.leβ©
β¨pi_div_two_pos.le, half_le_self pi_pos.leβ© (sub_nonneg.2 hx') hx
lemma mul_lt_sin {x : β} (hx : 0 < x) (hx' : x < Ο / 2) : (2 / Ο) * x < sin x :=
begin
rw [βinv_div],
simpa [-inv_div, pi_div_two_pos.ne'] using @lt_sin_mul ((Ο / 2)β»ΒΉ * x) _ _,
{ exact mul_pos (inv_pos.2 pi_div_two_pos) hx },
{ rwa [βdiv_eq_inv_mul, div_lt_one pi_div_two_pos] },
end
/-- In the range `[0, Ο / 2]`, we have a linear lower bound on `sin`. This inequality forms one half
of Jordan's inequality, the other half is `real.sin_lt` -/
lemma mul_le_sin {x : β} (hx : 0 β€ x) (hx' : x β€ Ο / 2) : (2 / Ο) * x β€ sin x :=
begin
rw [βinv_div],
simpa [-inv_div, pi_div_two_pos.ne'] using @le_sin_mul ((Ο / 2)β»ΒΉ * x) _ _,
{ exact mul_nonneg (inv_nonneg.2 pi_div_two_pos.le) hx },
{ rwa [βdiv_eq_inv_mul, div_le_one pi_div_two_pos] },
end
end real
|
ddcf1ebe51a0fa94b1702d7e36f658173cc958fc | bb31430994044506fa42fd667e2d556327e18dfe | /src/data/enat/basic.lean | c3200de999f2a54e45048cc753c9a2834a39627a | [
"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 | 3,603 | lean | /-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import data.nat.succ_pred
import algebra.char_zero.lemmas
import algebra.order.sub.with_top
import algebra.order.ring.with_top
/-!
# Definition and basic properties of extended natural numbers
In this file we define `enat` (notation: `ββ`) to be `with_top β` and prove some basic lemmas
about this type.
-/
/-- Extended natural numbers `ββ = with_top β`. -/
@[derive [has_zero, add_comm_monoid_with_one, canonically_ordered_comm_semiring, nontrivial,
linear_order, order_bot, order_top, has_bot, has_top, canonically_linear_ordered_add_monoid,
has_sub, has_ordered_sub, linear_ordered_add_comm_monoid_with_top, succ_order, well_founded_lt,
has_well_founded, char_zero, has_coe_t β]]
def enat : Type := with_top β
notation `ββ` := enat
namespace enat
instance : inhabited ββ := β¨0β©
instance : is_well_order ββ (<) := { }
variables {m n : ββ}
@[simp, norm_cast] lemma coe_zero : ((0 : β) : ββ) = 0 := rfl
@[simp, norm_cast] lemma coe_one : ((1 : β) : ββ) = 1 := rfl
@[simp, norm_cast] lemma coe_add (m n : β) : β(m + n) = (m + n : ββ) := rfl
@[simp, norm_cast] lemma coe_sub (m n : β) : β(m - n) = (m - n : ββ) := rfl
@[simp, norm_cast] lemma coe_mul (m n : β) : β(m * n) = (m * n : ββ) := with_top.coe_mul
instance can_lift : can_lift ββ β coe (Ξ» n, n β β€) := with_top.can_lift
/-- Conversion of `ββ` to `β` sending `β` to `0`. -/
def to_nat : monoid_with_zero_hom ββ β :=
{ to_fun := with_top.untop' 0,
map_one' := rfl,
map_zero' := rfl,
map_mul' := with_top.untop'_zero_mul }
@[simp] lemma to_nat_coe (n : β) : to_nat n = n := rfl
@[simp] lemma to_nat_top : to_nat β€ = 0 := rfl
@[simp] lemma coe_to_nat_eq_self : βn.to_nat = n β n β β€ :=
with_top.rec_top_coe (by simp) (by simp) n
alias coe_to_nat_eq_self β _ coe_to_nat
lemma coe_to_nat_le_self (n : ββ) : β(to_nat n) β€ n := with_top.rec_top_coe le_top (Ξ» k, le_rfl) n
lemma to_nat_add {m n : ββ} (hm : m β β€) (hn : n β β€) : to_nat (m + n) = to_nat m + to_nat n :=
by { lift m to β using hm, lift n to β using hn, refl }
lemma to_nat_sub {n : ββ} (hn : n β β€) (m : ββ) : to_nat (m - n) = to_nat m - to_nat n :=
begin
lift n to β using hn,
induction m using with_top.rec_top_coe,
{ rw [with_top.top_sub_coe, to_nat_top, zero_tsub] },
{ rw [β coe_sub, to_nat_coe, to_nat_coe, to_nat_coe] }
end
lemma to_nat_eq_iff {m : ββ} {n : β} (hn : n β 0) : m.to_nat = n β m = n :=
by induction m using with_top.rec_top_coe; simp [hn.symm]
@[simp] lemma succ_def (m : ββ) : order.succ m = m + 1 := by cases m; refl
lemma add_one_le_of_lt (h : m < n) : m + 1 β€ n :=
m.succ_def βΈ order.succ_le_of_lt h
lemma add_one_le_iff (hm : m β β€) : m + 1 β€ n β m < n :=
m.succ_def βΈ (order.succ_le_iff_of_not_is_max $ by rwa [is_max_iff_eq_top])
lemma one_le_iff_pos : 1 β€ n β 0 < n := add_one_le_iff with_top.zero_ne_top
lemma one_le_iff_ne_zero : 1 β€ n β n β 0 := one_le_iff_pos.trans pos_iff_ne_zero
lemma le_of_lt_add_one (h : m < n + 1) : m β€ n := order.le_of_lt_succ $ n.succ_def.symm βΈ h
@[elab_as_eliminator]
lemma nat_induction {P : ββ β Prop} (a : ββ) (h0 : P 0) (hsuc : β n : β, P n β P n.succ)
(htop : (β n : β, P n) β P β€) : P a :=
begin
have A : β n : β, P n := Ξ» n, nat.rec_on n h0 hsuc,
cases a,
exacts [htop A, A a]
end
end enat
|
d19ad6fb619c67c301cf019cce62a223cba78577 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/ring_theory/subsemiring/pointwise.lean | 4ac6690cf4c33841b36ca02f55798a91b6f91095 | [
"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 | 4,796 | 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 algebra.group_ring_action.basic
import ring_theory.subsemiring.basic
import group_theory.submonoid.pointwise
import data.set.pointwise.basic
/-! # Pointwise instances on `subsemiring`s
This file provides the action `subsemiring.pointwise_mul_action` which matches the action of
`mul_action_set`.
This actions is available in the `pointwise` locale.
## Implementation notes
This file is almost identical to `group_theory/submonoid/pointwise.lean`. Where possible, try to
keep them in sync.
-/
open set
variables {M R : Type*}
namespace subsemiring
section monoid
variables [monoid M] [semiring R] [mul_semiring_action M R]
/-- The action on a subsemiring corresponding to applying the action to every element.
This is available as an instance in the `pointwise` locale. -/
protected def pointwise_mul_action : mul_action M (subsemiring R) :=
{ smul := Ξ» a S, S.map (mul_semiring_action.to_ring_hom _ _ a),
one_smul := Ξ» S,
(congr_arg (Ξ» f, S.map f) (ring_hom.ext $ by exact one_smul M)).trans S.map_id,
mul_smul := Ξ» aβ aβ S,
(congr_arg (Ξ» f, S.map f) (ring_hom.ext $ by exact mul_smul _ _)).trans (S.map_map _ _).symm }
localized "attribute [instance] subsemiring.pointwise_mul_action" in pointwise
open_locale pointwise
lemma pointwise_smul_def {a : M} (S : subsemiring R) :
a β’ S = S.map (mul_semiring_action.to_ring_hom _ _ a) := rfl
@[simp] lemma coe_pointwise_smul (m : M) (S : subsemiring R) : β(m β’ S) = m β’ (S : set R) := rfl
@[simp] lemma pointwise_smul_to_add_submonoid (m : M) (S : subsemiring R) :
(m β’ S).to_add_submonoid = m β’ S.to_add_submonoid := rfl
lemma smul_mem_pointwise_smul (m : M) (r : R) (S : subsemiring R) : r β S β m β’ r β m β’ S :=
(set.smul_mem_smul_set : _ β _ β m β’ (S : set R))
lemma mem_smul_pointwise_iff_exists (m : M) (r : R) (S : subsemiring R) :
r β m β’ S β β (s : R), s β S β§ m β’ s = r :=
(set.mem_smul_set : r β m β’ (S : set R) β _)
@[simp] lemma smul_bot (a : M) : a β’ (β₯ : subsemiring R) = β₯ := map_bot _
lemma smul_sup (a : M) (S T : subsemiring R) : a β’ (S β T) = a β’ S β a β’ T := map_sup _ _ _
lemma smul_closure (a : M) (s : set R) : a β’ closure s = closure (a β’ s) :=
ring_hom.map_sclosure _ _
instance pointwise_central_scalar [mul_semiring_action Mα΅α΅α΅ R] [is_central_scalar M R] :
is_central_scalar M (subsemiring R) :=
β¨Ξ» a S, congr_arg (Ξ» f, S.map f) $ ring_hom.ext $ by exact op_smul_eq_smul _β©
end monoid
section group
variables [group M] [semiring R] [mul_semiring_action M R]
open_locale pointwise
@[simp] lemma smul_mem_pointwise_smul_iff {a : M} {S : subsemiring R} {x : R} :
a β’ x β a β’ S β x β S :=
smul_mem_smul_set_iff
lemma mem_pointwise_smul_iff_inv_smul_mem {a : M} {S : subsemiring R} {x : R} :
x β a β’ S β aβ»ΒΉ β’ x β S :=
mem_smul_set_iff_inv_smul_mem
lemma mem_inv_pointwise_smul_iff {a : M} {S : subsemiring R} {x : R} : x β aβ»ΒΉ β’ S β a β’ x β S :=
mem_inv_smul_set_iff
@[simp] lemma pointwise_smul_le_pointwise_smul_iff {a : M} {S T : subsemiring R} :
a β’ S β€ a β’ T β S β€ T :=
set_smul_subset_set_smul_iff
lemma pointwise_smul_subset_iff {a : M} {S T : subsemiring R} : a β’ S β€ T β S β€ aβ»ΒΉ β’ T :=
set_smul_subset_iff
lemma subset_pointwise_smul_iff {a : M} {S T : subsemiring R} : S β€ a β’ T β aβ»ΒΉ β’ S β€ T :=
subset_set_smul_iff
/-! TODO: add `equiv_smul` like we have for subgroup. -/
end group
section group_with_zero
variables [group_with_zero M] [semiring R] [mul_semiring_action M R]
open_locale pointwise
@[simp] lemma smul_mem_pointwise_smul_iffβ {a : M} (ha : a β 0) (S : subsemiring R)
(x : R) : a β’ x β a β’ S β x β S :=
smul_mem_smul_set_iffβ ha (S : set R) x
lemma mem_pointwise_smul_iff_inv_smul_memβ {a : M} (ha : a β 0) (S : subsemiring R) (x : R) :
x β a β’ S β aβ»ΒΉ β’ x β S :=
mem_smul_set_iff_inv_smul_memβ ha (S : set R) x
lemma mem_inv_pointwise_smul_iffβ {a : M} (ha : a β 0) (S : subsemiring R) (x : R) :
x β aβ»ΒΉ β’ S β a β’ x β S :=
mem_inv_smul_set_iffβ ha (S : set R) x
@[simp] lemma pointwise_smul_le_pointwise_smul_iffβ {a : M} (ha : a β 0) {S T : subsemiring R} :
a β’ S β€ a β’ T β S β€ T :=
set_smul_subset_set_smul_iffβ ha
lemma pointwise_smul_le_iffβ {a : M} (ha : a β 0) {S T : subsemiring R} : a β’ S β€ T β S β€ aβ»ΒΉ β’ T :=
set_smul_subset_iffβ ha
lemma le_pointwise_smul_iffβ {a : M} (ha : a β 0) {S T : subsemiring R} : S β€ a β’ T β aβ»ΒΉ β’ S β€ T :=
subset_set_smul_iffβ ha
end group_with_zero
end subsemiring
|
63be86b97c97728bed6f3c39bec4208fdbab5e7f | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/category_theory/abelian/subobject.lean | 202ac19459a56e68a70c5a5667d4235b48980673 | [
"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 | 3,160 | lean | /-
Copyright (c) 2022 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import category_theory.subobject.limits
import category_theory.abelian.basic
/-!
# Equivalence between subobjects and quotients in an abelian category
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
-/
open category_theory category_theory.limits opposite
universes v u
noncomputable theory
namespace category_theory.abelian
variables {C : Type u} [category.{v} C]
/-- In an abelian category, the subobjects and quotient objects of an object `X` are
order-isomorphic via taking kernels and cokernels.
Implemented here using subobjects in the opposite category,
since mathlib does not have a notion of quotient objects at the time of writing. -/
@[simps]
def subobject_iso_subobject_op [abelian C] (X : C) : subobject X βo (subobject (op X))α΅α΅ :=
begin
refine order_iso.of_hom_inv (cokernel_order_hom X) (kernel_order_hom X) _ _,
{ change (cokernel_order_hom X).comp (kernel_order_hom X) = _,
refine order_hom.ext _ _ (funext (subobject.ind _ _)),
introsI A f hf,
dsimp only [order_hom.comp_coe, function.comp_app, kernel_order_hom_coe, subobject.lift_mk,
cokernel_order_hom_coe, order_hom.id_coe, id.def],
refine subobject.mk_eq_mk_of_comm _ _ β¨_, _, quiver.hom.unop_inj _, quiver.hom.unop_inj _β© _,
{ exact (abelian.epi_desc f.unop _ (cokernel.condition (kernel.ΞΉ f.unop))).op },
{ exact (cokernel.desc _ _ (kernel.condition f.unop)).op },
{ simp only [β cancel_epi (cokernel.Ο (kernel.ΞΉ f.unop)), unop_comp, quiver.hom.unop_op,
unop_id_op, cokernel.Ο_desc_assoc, comp_epi_desc, category.comp_id] },
{ simp only [β cancel_epi f.unop, unop_comp, quiver.hom.unop_op, unop_id, comp_epi_desc_assoc,
cokernel.Ο_desc, category.comp_id] },
{ exact quiver.hom.unop_inj (by simp only [unop_comp, quiver.hom.unop_op, comp_epi_desc]) } },
{ change (kernel_order_hom X).comp (cokernel_order_hom X) = _,
refine order_hom.ext _ _ (funext (subobject.ind _ _)),
introsI A f hf,
dsimp only [order_hom.comp_coe, function.comp_app, cokernel_order_hom_coe, subobject.lift_mk,
kernel_order_hom_coe, order_hom.id_coe, id.def, unop_op, quiver.hom.unop_op],
refine subobject.mk_eq_mk_of_comm _ _ β¨_, _, _, _β© _,
{ exact abelian.mono_lift f _ (kernel.condition (cokernel.Ο f)) },
{ exact kernel.lift _ _ (cokernel.condition f) },
{ simp only [β cancel_mono (kernel.ΞΉ (cokernel.Ο f)), category.assoc, image.fac, mono_lift_comp,
category.id_comp, auto_param_eq] },
{ simp only [β cancel_mono f, category.assoc, mono_lift_comp, image.fac, category.id_comp,
auto_param_eq] },
{ simp only [mono_lift_comp] } }
end
/-- A well-powered abelian category is also well-copowered. -/
instance well_powered_opposite [abelian C] [well_powered C] : well_powered Cα΅α΅ :=
{ subobject_small := Ξ» X,
(small_congr (subobject_iso_subobject_op (unop X)).to_equiv).1 infer_instance }
end category_theory.abelian
|
afee14c30e01da2a0700c84b8442ef225164ceae | 367134ba5a65885e863bdc4507601606690974c1 | /src/category_theory/limits/constructions/limits_of_products_and_equalizers.lean | a4922480e71bcb9487abe8744f66c34202c69eca | [
"Apache-2.0"
] | permissive | kodyvajjha/mathlib | 9bead00e90f68269a313f45f5561766cfd8d5cad | b98af5dd79e13a38d84438b850a2e8858ec21284 | refs/heads/master | 1,624,350,366,310 | 1,615,563,062,000 | 1,615,563,062,000 | 162,666,963 | 0 | 0 | Apache-2.0 | 1,545,367,651,000 | 1,545,367,651,000 | null | UTF-8 | Lean | false | false | 6,818 | lean | /-
-- Copyright (c) 2020 Bhavik Mehta. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Bhavik Mehta, Scott Morrison
-/
import category_theory.limits.shapes.equalizers
import category_theory.limits.shapes.finite_products
import category_theory.limits.preserves.shapes.products
import category_theory.limits.preserves.shapes.equalizers
/-!
# Constructing limits from products and equalizers.
If a category has all products, and all equalizers, then it has all limits.
Similarly, if it has all finite products, and all equalizers, then it has all finite limits.
If a functor preserves all products and equalizers, then it preserves all limits.
Similarly, if it preserves all finite products and equalizers, then it preserves all finite limits.
# TODO
Provide the dual results.
Show the analogous results for functors which reflect or create (co)limits.
-/
open category_theory
open opposite
namespace category_theory.limits
universes v u uβ
variables {C : Type u} [category.{v} C]
variables {J : Type v} [small_category J]
-- We hide the "implementation details" inside a namespace
namespace has_limit_of_has_products_of_has_equalizers
variables {F : J β₯€ C}
{cβ : fan F.obj}
{cβ : fan (Ξ» f : (Ξ£ p : J Γ J, p.1 βΆ p.2), F.obj f.1.2)}
(s t : cβ.X βΆ cβ.X)
(hs : β (f : Ξ£ p : J Γ J, p.1 βΆ p.2), s β« cβ.Ο.app f = cβ.Ο.app f.1.1 β« F.map f.2)
(ht : β (f : Ξ£ p : J Γ J, p.1 βΆ p.2), t β« cβ.Ο.app f = cβ.Ο.app f.1.2)
(i : fork s t)
include hs ht
/--
(Implementation) Given the appropriate product and equalizer cones, build the cone for `F` which is
limiting if the given cones are also.
-/
@[simps]
def build_limit : cone F :=
{ X := i.X,
Ο := { app := Ξ» j, i.ΞΉ β« cβ.Ο.app _,
naturality' := Ξ» jβ jβ f, by { dsimp, simp [β hs β¨β¨_, _β©, fβ©, i.condition_assoc, ht] } } }
variable {i}
/--
(Implementation) Show the cone constructed in `build_limit` is limiting, provided the cones used in
its construction are.
-/
def build_is_limit (tβ : is_limit cβ) (tβ : is_limit cβ) (hi : is_limit i) :
is_limit (build_limit s t hs ht i) :=
{ lift := Ξ» q,
begin
refine hi.lift (fork.of_ΞΉ _ _),
{ refine tβ.lift (fan.mk _ (Ξ» j, _)),
apply q.Ο.app j },
{ apply tβ.hom_ext,
simp [hs, ht] },
end,
uniq' := Ξ» q m w, hi.hom_ext (i.equalizer_ext (tβ.hom_ext (by simpa using w))) }
end has_limit_of_has_products_of_has_equalizers
open has_limit_of_has_products_of_has_equalizers
/--
Given the existence of the appropriate (possibly finite) products and equalizers, we know a limit of
`F` exists.
(This assumes the existence of all equalizers, which is technically stronger than needed.)
-/
lemma has_limit_of_equalizer_and_product (F : J β₯€ C)
[has_limit (discrete.functor F.obj)]
[has_limit (discrete.functor (Ξ» f : (Ξ£ p : J Γ J, p.1 βΆ p.2), F.obj f.1.2))]
[has_equalizers C] : has_limit F :=
has_limit.mk
{ cone := _,
is_limit :=
build_is_limit
(pi.lift (Ξ» f, limit.Ο _ _ β« F.map f.2))
(pi.lift (Ξ» f, limit.Ο _ f.1.2))
(by simp)
(by simp)
(limit.is_limit _)
(limit.is_limit _)
(limit.is_limit _) }
/--
Any category with products and equalizers has all limits.
See https://stacks.math.columbia.edu/tag/002N.
-/
lemma limits_from_equalizers_and_products
[has_products C] [has_equalizers C] : has_limits C :=
{ has_limits_of_shape := Ξ» J π₯,
{ has_limit := Ξ» F, by exactI has_limit_of_equalizer_and_product F } }
/--
Any category with finite products and equalizers has all finite limits.
See https://stacks.math.columbia.edu/tag/002O.
-/
lemma finite_limits_from_equalizers_and_finite_products
[has_finite_products C] [has_equalizers C] : has_finite_limits C :=
Ξ» J _ _, { has_limit := Ξ» F, by exactI has_limit_of_equalizer_and_product F }
variables {D : Type uβ} [category.{v} D]
noncomputable theory
section
variables [has_limits_of_shape (discrete J) C]
[has_limits_of_shape (discrete (Ξ£ p : J Γ J, p.1 βΆ p.2)) C]
[has_equalizers C]
variables (G : C β₯€ D)
[preserves_limits_of_shape walking_parallel_pair G]
[preserves_limits_of_shape (discrete J) G]
[preserves_limits_of_shape (discrete (Ξ£ p : J Γ J, p.1 βΆ p.2)) G]
/-- If a functor preserves equalizers and the appropriate products, it preserves limits. -/
def preserves_limit_of_preserves_equalizers_and_product :
preserves_limits_of_shape J G :=
{ preserves_limit := Ξ» K,
begin
let P := β K.obj,
let Q := β (Ξ» (f : (Ξ£ (p : J Γ J), p.fst βΆ p.snd)), K.obj f.1.2),
let s : P βΆ Q := pi.lift (Ξ» f, limit.Ο _ _ β« K.map f.2),
let t : P βΆ Q := pi.lift (Ξ» f, limit.Ο _ f.1.2),
let I := equalizer s t,
let i : I βΆ P := equalizer.ΞΉ s t,
apply preserves_limit_of_preserves_limit_cone
(build_is_limit s t (by simp) (by simp)
(limit.is_limit _)
(limit.is_limit _)
(limit.is_limit _)),
refine is_limit.of_iso_limit (build_is_limit _ _ _ _ _ _ _) _,
{ exact fan.mk _ (Ξ» j, G.map (pi.Ο _ j)) },
{ exact fan.mk (G.obj Q) (Ξ» f, G.map (pi.Ο _ f)) },
{ apply G.map s },
{ apply G.map t },
{ intro f,
dsimp,
simp only [βG.map_comp, limit.lift_Ο, fan.mk_Ο_app] },
{ intro f,
dsimp,
simp only [βG.map_comp, limit.lift_Ο, fan.mk_Ο_app] },
{ apply fork.of_ΞΉ (G.map i) _,
simp only [β G.map_comp, equalizer.condition] },
{ apply is_limit_of_has_product_of_preserves_limit },
{ apply is_limit_of_has_product_of_preserves_limit },
{ apply is_limit_fork_map_of_is_limit,
apply equalizer_is_equalizer },
refine cones.ext (iso.refl _) _,
intro j,
dsimp,
simp, -- See note [dsimp, simp].
end }
end
/-- If G preserves equalizers and finite products, it preserves finite limits. -/
def preserves_finite_limits_of_preserves_equalizers_and_finite_products
[has_equalizers C] [has_finite_products C]
(G : C β₯€ D) [preserves_limits_of_shape walking_parallel_pair G]
[β J [fintype J], preserves_limits_of_shape (discrete J) G]
(J : Type v) [small_category J] [fin_category J] :
preserves_limits_of_shape J G :=
preserves_limit_of_preserves_equalizers_and_product G
/-- If G preserves equalizers and products, it preserves all limits. -/
def preserves_limits_of_preserves_equalizers_and_products
[has_equalizers C] [has_products C]
(G : C β₯€ D) [preserves_limits_of_shape walking_parallel_pair G]
[β J, preserves_limits_of_shape (discrete J) G] :
preserves_limits G :=
{ preserves_limits_of_shape := Ξ» J π₯,
by exactI preserves_limit_of_preserves_equalizers_and_product G }
end category_theory.limits
|
5d61d3f614f382df42fe1c871febfa77b387d2f3 | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/measure_theory/prod.lean | c1563b89f320d8c6daf73c2618c85393f87ed483 | [
"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 | 40,453 | lean | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import measure_theory.giry_monad
import measure_theory.set_integral
/-!
# The product measure
In this file we define and prove properties about the binary product measure. If `Ξ±` and `Ξ²` have
Ο-finite measures `ΞΌ` resp. `Ξ½` then `Ξ± Γ Ξ²` can be equipped with a Ο-finite measure `ΞΌ.prod Ξ½` that
satisfies `(ΞΌ.prod Ξ½) s = β«β» x, Ξ½ {y | (x, y) β s} βΞΌ`.
We also have `(ΞΌ.prod Ξ½) (s.prod t) = ΞΌ s * Ξ½ t`, i.e. the measure of a rectangle is the product of
the measures of the sides.
We also prove Tonelli's theorem and Fubini's theorem.
## Main definition
* `measure_theory.measure.prod`: The product of two measures.
## Main results
* `measure_theory.measure.prod_apply` states `ΞΌ.prod Ξ½ s = β«β» x, Ξ½ {y | (x, y) β s} βΞΌ`
for measurable `s`. `measure_theory.measure.prod_apply_symm` is the reversed version.
* `measure_theory.measure.prod_prod` states `ΞΌ.prod Ξ½ (s.prod t) = ΞΌ s * Ξ½ t` for measurable sets
`s` and `t`.
* `measure_theory.lintegral_prod`: Tonelli's theorem. It states that for a measurable function
`Ξ± Γ Ξ² β ennreal` we have `β«β» z, f z β(ΞΌ.prod Ξ½) = β«β» x, β«β» y, f (x, y) βΞ½ βΞΌ`. The version
for functions `Ξ± β Ξ² β ennreal` is reversed, and called `lintegral_lintegral`. Both versions have
a variant with `_symm` appended, where the order of integration is reversed.
The lemma `measurable.lintegral_prod_right'` states that the inner integral of the right-hand side
is measurable.
* `measure_theory.integrable_prod_iff` states that a binary function is integrable iff both
* `y β¦ f (x, y)` is integrable for almost every `x`, and
* the function `x β¦ β« β₯f (x, y)β₯ dy` is integrable.
* `measure_theory.integral_prod`: Fubini's theorem. It states that for a integrable function
`Ξ± Γ Ξ² β E` (where `E` is a second countable Banach space) we have
`β« z, f z β(ΞΌ.prod Ξ½) = β« x, β« y, f (x, y) βΞ½ βΞΌ`. This theorem has the same variants as
Tonelli's theorem. The lemma `measure_theory.integrable.integral_prod_right` states that the
inner integral of the right-hand side is integrable.
## Implementation Notes
Many results are proven twice, once for functions in curried form (`Ξ± β Ξ² β Ξ³`) and one for
functions in uncurried form (`Ξ± Γ Ξ² β Ξ³`). The former often has an assumption
`measurable (uncurry f)`, which could be inconvenient to discharge, but for the latter it is more
common that the function has to be given explicitly, since Lean cannot synthesize the function by
itself. We name the lemmas about the uncurried form with a prime.
Tonelli's theorem and Fubini's theorem have a different naming scheme, since the version for the
uncurried version is reversed.
## Tags
product measure, Fubini's theorem, Tonelli's theorem, Fubini-Tonelli theorem
-/
noncomputable theory
open_locale classical topological_space
open set function real ennreal
open measure_theory measurable_space measure_theory.measure
open topological_space (hiding generate_from)
open filter (hiding prod_eq map)
variables {Ξ± Ξ±' Ξ² Ξ²' Ξ³ E : Type*}
/-- Rectangles formed by Ο-systems form a Ο-system. -/
lemma is_pi_system.prod {C : set (set Ξ±)} {D : set (set Ξ²)} (hC : is_pi_system C)
(hD : is_pi_system D) : is_pi_system (image2 set.prod C D) :=
begin
rintro _ _ β¨sβ, tβ, hsβ, htβ, rflβ© β¨sβ, tβ, hsβ, htβ, rflβ© hst,
rw [prod_inter_prod] at hst β’, rw [prod_nonempty_iff] at hst,
exact mem_image2_of_mem (hC _ _ hsβ hsβ hst.1) (hD _ _ htβ htβ hst.2)
end
/-- Rectangles of countably spanning sets are countably spanning. -/
lemma is_countably_spanning.prod {C : set (set Ξ±)} {D : set (set Ξ²)}
(hC : is_countably_spanning C) (hD : is_countably_spanning D) :
is_countably_spanning (image2 set.prod C D) :=
begin
rcases β¨hC, hDβ© with β¨β¨s, h1s, h2sβ©, t, h1t, h2tβ©,
refine β¨Ξ» n, (s n.unpair.1).prod (t n.unpair.2), Ξ» n, mem_image2_of_mem (h1s _) (h1t _), _β©,
rw [Union_unpair_prod, h2s, h2t, univ_prod_univ]
end
variables [measurable_space Ξ±] [measurable_space Ξ±'] [measurable_space Ξ²] [measurable_space Ξ²']
variables [measurable_space Ξ³]
variables {ΞΌ : measure Ξ±} {Ξ½ : measure Ξ²} {Ο : measure Ξ³}
variables [normed_group E] [measurable_space E]
/-! ### Measurability
Before we define the product measure, we can talk about the measurability of operations on binary
functions. We show that if `f` is a binary measurable function, then the function that integrates
along one of the variables (using either the Lebesgue or Bochner integral) is measurable.
-/
/-- The product of generated Ο-algebras is the one generated by rectangles, if both generating sets
are countably spanning. -/
lemma generate_from_prod_eq {Ξ± Ξ²} {C : set (set Ξ±)} {D : set (set Ξ²)}
(hC : is_countably_spanning C) (hD : is_countably_spanning D) :
@prod.measurable_space _ _ (generate_from C) (generate_from D) =
generate_from (image2 set.prod C D) :=
begin
apply le_antisymm,
{ refine sup_le _ _; rw [comap_generate_from];
apply generate_from_le; rintro _ β¨s, hs, rflβ©,
{ rcases hD with β¨t, h1t, h2tβ©,
rw [β prod_univ, β h2t, prod_Union],
apply is_measurable.Union,
intro n, apply is_measurable_generate_from,
exact β¨s, t n, hs, h1t n, rflβ© },
{ rcases hC with β¨t, h1t, h2tβ©,
rw [β univ_prod, β h2t, Union_prod],
apply is_measurable.Union,
rintro n, apply is_measurable_generate_from,
exact mem_image2_of_mem (h1t n) hs } },
{ apply generate_from_le, rintro _ β¨s, t, hs, ht, rflβ©, rw [prod_eq],
apply (measurable_fst _).inter (measurable_snd _),
{ exact is_measurable_generate_from hs },
{ exact is_measurable_generate_from ht } }
end
/-- If `C` and `D` generate the Ο-algebras on `Ξ±` resp. `Ξ²`, then rectangles formed by `C` and `D`
generate the Ο-algebra on `Ξ± Γ Ξ²`. -/
lemma generate_from_eq_prod {C : set (set Ξ±)} {D : set (set Ξ²)} (hC : generate_from C = βΉ_βΊ)
(hD : generate_from D = βΉ_βΊ) (h2C : is_countably_spanning C) (h2D : is_countably_spanning D) :
generate_from (image2 set.prod C D) = prod.measurable_space :=
by rw [β hC, β hD, generate_from_prod_eq h2C h2D]
/-- The product Ο-algebra is generated from boxes, i.e. `s.prod t` for sets `s : set Ξ±` and
`t : set Ξ²`. -/
lemma generate_from_prod :
generate_from (image2 set.prod { s : set Ξ± | is_measurable s } { t : set Ξ² | is_measurable t }) =
prod.measurable_space :=
generate_from_eq_prod generate_from_is_measurable generate_from_is_measurable
is_countably_spanning_is_measurable is_countably_spanning_is_measurable
/-- Rectangles form a Ο-system. -/
lemma is_pi_system_prod :
is_pi_system (image2 set.prod { s : set Ξ± | is_measurable s } { t : set Ξ² | is_measurable t }) :=
is_pi_system_is_measurable.prod is_pi_system_is_measurable
/-- If `Ξ½` is a finite measure, and `s β Ξ± Γ Ξ²` is measurable, then `x β¦ Ξ½ { y | (x, y) β s }` is
a measurable function. `measurable_measure_prod_mk_left` is strictly more general. -/
lemma measurable_measure_prod_mk_left_finite [finite_measure Ξ½] {s : set (Ξ± Γ Ξ²)}
(hs : is_measurable s) : measurable (Ξ» x, Ξ½ (prod.mk x β»ΒΉ' s)) :=
begin
refine induction_on_inter generate_from_prod.symm is_pi_system_prod _ _ _ _ hs,
{ simp [measurable_zero, const_def] },
{ rintro _ β¨s, t, hs, ht, rflβ©, simp only [mk_preimage_prod_right_eq_if, measure_if],
exact measurable_const.indicator hs },
{ intros t ht h2t,
simp_rw [preimage_compl, measure_compl (measurable_prod_mk_left ht) (measure_lt_top Ξ½ _)],
exact measurable_const.ennreal_sub h2t },
{ intros f h1f h2f h3f, simp_rw [preimage_Union],
have : β b, Ξ½ (β i, prod.mk b β»ΒΉ' f i) = β' i, Ξ½ (prod.mk b β»ΒΉ' f i) :=
Ξ» b, measure_Union (Ξ» i j hij, disjoint.preimage _ (h1f i j hij))
(Ξ» i, measurable_prod_mk_left (h2f i)),
simp_rw [this], apply measurable.ennreal_tsum h3f },
end
/-- If `Ξ½` is a Ο-finite measure, and `s β Ξ± Γ Ξ²` is measurable, then `x β¦ Ξ½ { y | (x, y) β s }` is
a measurable function. -/
lemma measurable_measure_prod_mk_left [sigma_finite Ξ½] {s : set (Ξ± Γ Ξ²)}
(hs : is_measurable s) : measurable (Ξ» x, Ξ½ (prod.mk x β»ΒΉ' s)) :=
begin
have : β x, is_measurable (prod.mk x β»ΒΉ' s) := Ξ» x, measurable_prod_mk_left hs,
simp only [β @supr_restrict_spanning_sets _ _ Ξ½, this],
apply measurable_supr, intro i,
haveI : fact _ := measure_spanning_sets_lt_top Ξ½ i,
exact measurable_measure_prod_mk_left_finite hs
end
/-- If `ΞΌ` is a Ο-finite measure, and `s β Ξ± Γ Ξ²` is measurable, then `y β¦ ΞΌ { x | (x, y) β s }` is
a measurable function. -/
lemma measurable_measure_prod_mk_right {ΞΌ : measure Ξ±} [sigma_finite ΞΌ] {s : set (Ξ± Γ Ξ²)}
(hs : is_measurable s) : measurable (Ξ» y, ΞΌ ((Ξ» x, (x, y)) β»ΒΉ' s)) :=
measurable_measure_prod_mk_left (is_measurable_swap_iff.mpr hs)
lemma measurable.map_prod_mk_left [sigma_finite Ξ½] : measurable (Ξ» x : Ξ±, map (prod.mk x) Ξ½) :=
begin
apply measurable_of_measurable_coe, intros s hs,
simp_rw [map_apply measurable_prod_mk_left hs],
exact measurable_measure_prod_mk_left hs
end
lemma measurable.map_prod_mk_right {ΞΌ : measure Ξ±} [sigma_finite ΞΌ] :
measurable (Ξ» y : Ξ², map (Ξ» x : Ξ±, (x, y)) ΞΌ) :=
begin
apply measurable_of_measurable_coe, intros s hs,
simp_rw [map_apply measurable_prod_mk_right hs],
exact measurable_measure_prod_mk_right hs
end
/-- The Lebesgue intergral is measurable. This shows that the integrand of (the right-hand-side of)
Tonelli's theorem is measurable. -/
lemma measurable.lintegral_prod_right' [sigma_finite Ξ½] :
β {f : Ξ± Γ Ξ² β ennreal} (hf : measurable f), measurable (Ξ» x, β«β» y, f (x, y) βΞ½) :=
begin
have m := @measurable_prod_mk_left,
refine measurable.ennreal_induction _ _ _,
{ intros c s hs, simp only [β indicator_comp_right],
suffices : measurable (Ξ» x, c * Ξ½ (prod.mk x β»ΒΉ' s)),
{ simpa [lintegral_indicator _ (m hs)] },
exact measurable_const.ennreal_mul (measurable_measure_prod_mk_left hs) },
{ rintro f g - hf hg h2f h2g, simp_rw [pi.add_apply, lintegral_add (hf.comp m) (hg.comp m)],
exact h2f.add h2g },
{ intros f hf h2f h3f,
have := measurable_supr h3f,
have : β x, monotone (Ξ» n y, f n (x, y)) := Ξ» x i j hij y, h2f hij (x, y),
simpa [lintegral_supr (Ξ» n, (hf n).comp m), this] }
end
/-- The Lebesgue intergral is measurable. This shows that the integrand of (the right-hand-side of)
Tonelli's theorem is measurable.
This version has the argument `f` in curried form. -/
lemma measurable.lintegral_prod_right [sigma_finite Ξ½] {f : Ξ± β Ξ² β ennreal}
(hf : measurable (uncurry f)) : measurable (Ξ» x, β«β» y, f x y βΞ½) :=
hf.lintegral_prod_right'
/-- The Lebesgue intergral is measurable. This shows that the integrand of (the right-hand-side of)
the symmetric version of Tonelli's theorem is measurable. -/
lemma measurable.lintegral_prod_left' [sigma_finite ΞΌ] {f : Ξ± Γ Ξ² β ennreal}
(hf : measurable f) : measurable (Ξ» y, β«β» x, f (x, y) βΞΌ) :=
(measurable_swap_iff.mpr hf).lintegral_prod_right'
/-- The Lebesgue intergral is measurable. This shows that the integrand of (the right-hand-side of)
the symmetric version of Tonelli's theorem is measurable.
This version has the argument `f` in curried form. -/
lemma measurable.lintegral_prod_left [sigma_finite ΞΌ] {f : Ξ± β Ξ² β ennreal}
(hf : measurable (uncurry f)) : measurable (Ξ» y, β«β» x, f x y βΞΌ) :=
hf.lintegral_prod_left'
lemma is_measurable_integrable [sigma_finite Ξ½] [opens_measurable_space E] β¦f : Ξ± β Ξ² β Eβ¦
(hf : measurable (uncurry f)) : is_measurable { x | integrable (f x) Ξ½ } :=
begin
simp_rw [integrable, hf.of_uncurry_left, true_and],
exact is_measurable_lt (measurable.lintegral_prod_right hf.ennnorm) measurable_const
end
section
variables [second_countable_topology E] [normed_space β E]
[complete_space E] [borel_space E]
/-- The Bochner intergral is measurable. This shows that the integrand of (the right-hand-side of)
Fubini's theorem is measurable.
This version has `f` in curried form. -/
lemma measurable.integral_prod_right [sigma_finite Ξ½] β¦f : Ξ± β Ξ² β Eβ¦
(hf : measurable (uncurry f)) : measurable (Ξ» x, β« y, f x y βΞ½) :=
begin
let s : β β simple_func (Ξ± Γ Ξ²) E := simple_func.approx_on _ hf univ _ (mem_univ 0),
let s' : β β Ξ± β simple_func Ξ² E := Ξ» n x, (s n).comp (prod.mk x) measurable_prod_mk_left,
let f' : β β Ξ± β E := Ξ» n, {x | integrable (f x) Ξ½}.indicator
(Ξ» x, (s' n x).integral Ξ½),
have hf' : β n, measurable (f' n),
{ intro n, refine measurable.indicator _ (is_measurable_integrable hf),
have : β x, (s' n x).range.filter (Ξ» x, x β 0) β
(s n).range,
{ intros x, refine finset.subset.trans (finset.filter_subset _) _, intro y,
simp_rw [simple_func.mem_range], rintro β¨z, rflβ©, exact β¨(x, z), rflβ© },
simp only [simple_func.integral_eq_sum_of_subset (this _)],
refine finset.measurable_sum _ _, intro x,
refine (measurable.to_real _).smul measurable_const,
simp only [simple_func.coe_comp, preimage_comp] {single_pass := tt},
apply measurable_measure_prod_mk_left,
exact (s n).is_measurable_fiber x },
have h2f' : tendsto f' at_top (π (Ξ» (x : Ξ±), β« (y : Ξ²), f x y βΞ½)),
{ rw [tendsto_pi], intro x,
by_cases hfx : integrable (f x) Ξ½,
{ have : β n, integrable (s' n x) Ξ½,
{ intro n, apply (hfx.norm.add hfx.norm).mono' (s' n x).measurable,
apply eventually_of_forall, intro y,
simp_rw [s', simple_func.coe_comp], exact simple_func.norm_approx_on_zero_le _ _ (x, y) n },
simp only [f', hfx, simple_func.integral_eq_integral _ (this _), indicator_of_mem,
mem_set_of_eq],
refine tendsto_integral_of_dominated_convergence (Ξ» y, β₯f x yβ₯ + β₯f x yβ₯)
(Ξ» n, (s' n x).measurable) hf.of_uncurry_left (hfx.norm.add hfx.norm) _ _,
{ exact Ξ» n, eventually_of_forall (Ξ» y, simple_func.norm_approx_on_zero_le _ _ (x, y) n) },
{ exact eventually_of_forall (Ξ» y, simple_func.tendsto_approx_on _ _ (by simp)) } },
{ simpa [f', hfx, integral_undef] using @tendsto_const_nhds _ _ _ (0 : E) _, }
},
exact measurable_of_tendsto_metric hf' h2f'
end
/-- The Bochner intergral is measurable. This shows that the integrand of (the right-hand-side of)
Fubini's theorem is measurable. -/
lemma measurable.integral_prod_right' [sigma_finite Ξ½] β¦f : Ξ± Γ Ξ² β Eβ¦
(hf : measurable f) : measurable (Ξ» x, β« y, f (x, y) βΞ½) :=
by { rw [β uncurry_curry f] at hf, exact hf.integral_prod_right }
/-- The Bochner intergral is measurable. This shows that the integrand of (the right-hand-side of)
the symmetric version of Fubini's theorem is measurable.
This version has `f` in curried form. -/
lemma measurable.integral_prod_left [sigma_finite ΞΌ] β¦f : Ξ± β Ξ² β Eβ¦
(hf : measurable (uncurry f)) : measurable (Ξ» y, β« x, f x y βΞΌ) :=
(hf.comp measurable_swap).integral_prod_right'
/-- The Bochner intergral is measurable. This shows that the integrand of (the right-hand-side of)
the symmetric version of Fubini's theorem is measurable. -/
lemma measurable.integral_prod_left' [sigma_finite ΞΌ] β¦f : Ξ± Γ Ξ² β Eβ¦
(hf : measurable f) : measurable (Ξ» y, β« x, f (x, y) βΞΌ) :=
(hf.comp measurable_swap).integral_prod_right'
end
/-! ### The product measure -/
namespace measure_theory
namespace measure
/-- The binary product of measures. They are defined for arbitrary measures, but we basically
prove all properties under the assumption that at least one of them is Ο-finite. -/
protected def prod (ΞΌ : measure Ξ±) (Ξ½ : measure Ξ²) : measure (Ξ± Γ Ξ²) :=
bind ΞΌ $ Ξ» x : Ξ±, map (prod.mk x) Ξ½
instance prod.measure_space {Ξ± Ξ²} [measure_space Ξ±] [measure_space Ξ²] : measure_space (Ξ± Γ Ξ²) :=
{ volume := volume.prod volume }
variables {ΞΌ Ξ½} [sigma_finite Ξ½]
lemma prod_apply {s : set (Ξ± Γ Ξ²)} (hs : is_measurable s) :
ΞΌ.prod Ξ½ s = β«β» x, Ξ½ (prod.mk x β»ΒΉ' s) βΞΌ :=
by simp_rw [measure.prod, bind_apply hs measurable.map_prod_mk_left,
map_apply measurable_prod_mk_left hs]
@[simp] lemma prod_prod {s : set Ξ±} {t : set Ξ²}
(hs : is_measurable s) (ht : is_measurable t) : ΞΌ.prod Ξ½ (s.prod t) = ΞΌ s * Ξ½ t :=
by simp_rw [prod_apply (hs.prod ht), mk_preimage_prod_right_eq_if, measure_if,
lintegral_indicator _ hs, lintegral_const, restrict_apply is_measurable.univ,
univ_inter, mul_comm]
lemma ae_measure_lt_top {s : set (Ξ± Γ Ξ²)} (hs : is_measurable s)
(h2s : (ΞΌ.prod Ξ½) s < β€) : βα΅ x βΞΌ, Ξ½ (prod.mk x β»ΒΉ' s) < β€ :=
by { simp_rw [prod_apply hs] at h2s, refine ae_lt_top (measurable_measure_prod_mk_left hs) h2s }
lemma integrable_measure_prod_mk_left {s : set (Ξ± Γ Ξ²)}
(hs : is_measurable s) (h2s : (ΞΌ.prod Ξ½) s < β€) :
integrable (Ξ» x, (Ξ½ (prod.mk x β»ΒΉ' s)).to_real) ΞΌ :=
begin
refine β¨(measurable_measure_prod_mk_left hs).to_real, _β©,
simp_rw [has_finite_integral, ennnorm_eq_of_real to_real_nonneg],
convert h2s using 1, simp_rw [prod_apply hs], apply lintegral_congr_ae,
refine (ae_measure_lt_top hs h2s).mp _, apply eventually_of_forall, intros x hx,
rw [lt_top_iff_ne_top] at hx, simp [of_real_to_real, hx],
end
/-- Note: the assumption `hs` cannot be dropped. For a counterexample, see
Walter Rudin *Real and Complex Analysis*, example (c) in section 8.9. -/
lemma measure_prod_null {s : set (Ξ± Γ Ξ²)}
(hs : is_measurable s) : ΞΌ.prod Ξ½ s = 0 β (Ξ» x, Ξ½ (prod.mk x β»ΒΉ' s)) =α΅[ΞΌ] 0 :=
by simp_rw [prod_apply hs, lintegral_eq_zero_iff (measurable_measure_prod_mk_left hs)]
/-- Note: the converse is not true without assuming that `s` is measurable. For a counterexample,
see Walter Rudin *Real and Complex Analysis*, example (c) in section 8.9. -/
lemma measure_ae_null_of_prod_null {s : set (Ξ± Γ Ξ²)}
(h : ΞΌ.prod Ξ½ s = 0) : (Ξ» x, Ξ½ (prod.mk x β»ΒΉ' s)) =α΅[ΞΌ] 0 :=
begin
obtain β¨t, hst, mt, htβ© := exists_is_measurable_superset_of_measure_eq_zero h,
simp_rw [measure_prod_null mt] at ht,
rw [eventually_le_antisymm_iff],
exact β¨eventually_le.trans_eq
(eventually_of_forall $ Ξ» x, (measure_mono (preimage_mono hst) : _)) ht,
eventually_of_forall $ Ξ» x, zero_le _β©
end
/-- Note: the converse is not true. For a counterexample, see
Walter Rudin *Real and Complex Analysis*, example (c) in section 8.9. -/
lemma ae_ae_of_ae_prod {p : Ξ± Γ Ξ² β Prop} (h : βα΅ z βΞΌ.prod Ξ½, p z) :
βα΅ x β ΞΌ, βα΅ y β Ξ½, p (x, y) :=
measure_ae_null_of_prod_null h
/-- `ΞΌ.prod Ξ½` has finite spanning sets in rectangles of finite spanning sets. -/
def finite_spanning_sets_in.prod {Ξ½ : measure Ξ²} {C : set (set Ξ±)} {D : set (set Ξ²)}
(hΞΌ : ΞΌ.finite_spanning_sets_in C) (hΞ½ : Ξ½.finite_spanning_sets_in D)
(hC : β s β C, is_measurable s) (hD : β t β D, is_measurable t) :
(ΞΌ.prod Ξ½).finite_spanning_sets_in (image2 set.prod C D) :=
begin
haveI := hΞ½.sigma_finite hD,
refine β¨Ξ» n, (hΞΌ.set n.unpair.1).prod (hΞ½.set n.unpair.2),
Ξ» n, mem_image2_of_mem (hΞΌ.set_mem _) (hΞ½.set_mem _), Ξ» n, _, _β©,
{ simp_rw [prod_prod (hC _ (hΞΌ.set_mem _)) (hD _ (hΞ½.set_mem _))],
exact mul_lt_top (hΞΌ.finite _) (hΞ½.finite _) },
{ simp_rw [Union_unpair_prod, hΞΌ.spanning, hΞ½.spanning, univ_prod_univ] }
end
variables [sigma_finite ΞΌ]
instance prod.sigma_finite : sigma_finite (ΞΌ.prod Ξ½) :=
β¨(ΞΌ.to_finite_spanning_sets_in.prod Ξ½.to_finite_spanning_sets_in (Ξ» _, id) (Ξ» _, id)).mono $
by { rintro _ β¨s, t, hs, ht, rflβ©, exact hs.prod ht }β©
/-- Measures on a product space are equal the product measure if they are equal on rectangles
with as sides sets that generate the corresponding Ο-algebras. -/
lemma prod_eq_generate_from {ΞΌ : measure Ξ±} {Ξ½ : measure Ξ²} {C : set (set Ξ±)}
{D : set (set Ξ²)} (hC : generate_from C = βΉ_βΊ)
(hD : generate_from D = βΉ_βΊ) (h2C : is_pi_system C) (h2D : is_pi_system D)
(h3C : ΞΌ.finite_spanning_sets_in C) (h3D : Ξ½.finite_spanning_sets_in D)
{ΞΌΞ½ : measure (Ξ± Γ Ξ²)}
(hβ : β (s β C) (t β D), ΞΌΞ½ (set.prod s t) = ΞΌ s * Ξ½ t) : ΞΌ.prod Ξ½ = ΞΌΞ½ :=
begin
have h4C : β (s : set Ξ±), s β C β is_measurable s,
{ intros s hs, rw [β hC], exact is_measurable_generate_from hs },
have h4D : β (t : set Ξ²), t β D β is_measurable t,
{ intros t ht, rw [β hD], exact is_measurable_generate_from ht },
refine (h3C.prod h3D h4C h4D).ext
(generate_from_eq_prod hC hD h3C.is_countably_spanning h3D.is_countably_spanning).symm
(h2C.prod h2D) _,
{ rintro _ β¨s, t, hs, ht, rflβ©, haveI := h3D.sigma_finite h4D,
simp_rw [hβ s hs t ht, prod_prod (h4C s hs) (h4D t ht)] }
end
/-- Measures on a product space are equal to the product measure if they are equal on rectangles. -/
lemma prod_eq {ΞΌΞ½ : measure (Ξ± Γ Ξ²)}
(h : β s t, is_measurable s β is_measurable t β ΞΌΞ½ (s.prod t) = ΞΌ s * Ξ½ t) : ΞΌ.prod Ξ½ = ΞΌΞ½ :=
prod_eq_generate_from generate_from_is_measurable generate_from_is_measurable
is_pi_system_is_measurable is_pi_system_is_measurable
ΞΌ.to_finite_spanning_sets_in Ξ½.to_finite_spanning_sets_in (Ξ» s hs t ht, h s t hs ht)
lemma prod_swap : map prod.swap (ΞΌ.prod Ξ½) = Ξ½.prod ΞΌ :=
begin
refine (prod_eq _).symm,
intros s t hs ht,
simp_rw [map_apply measurable_swap (hs.prod ht), preimage_swap_prod, prod_prod ht hs, mul_comm]
end
lemma prod_apply_symm {s : set (Ξ± Γ Ξ²)} (hs : is_measurable s) :
ΞΌ.prod Ξ½ s = β«β» y, ΞΌ ((Ξ» x, (x, y)) β»ΒΉ' s) βΞ½ :=
by { rw [β prod_swap, map_apply measurable_swap hs],
simp only [prod_apply (measurable_swap hs)], refl }
lemma prod_assoc_prod [sigma_finite Ο] :
map measurable_equiv.prod_assoc ((ΞΌ.prod Ξ½).prod Ο) = ΞΌ.prod (Ξ½.prod Ο) :=
begin
refine (prod_eq_generate_from generate_from_is_measurable generate_from_prod
is_pi_system_is_measurable is_pi_system_prod ΞΌ.to_finite_spanning_sets_in
(Ξ½.to_finite_spanning_sets_in.prod Ο.to_finite_spanning_sets_in (Ξ» _, id) (Ξ» _, id)) _).symm,
rintro s hs _ β¨t, u, ht, hu, rflβ©, rw [mem_set_of_eq] at hs ht hu,
simp_rw [map_apply (measurable_equiv.measurable _) (hs.prod (ht.prod hu)), prod_prod ht hu,
measurable_equiv.prod_assoc, measurable_equiv.coe_eq, equiv.prod_assoc_preimage,
prod_prod (hs.prod ht) hu, prod_prod hs ht, mul_assoc]
end
/-! ### The product of specific measures -/
lemma prod_restrict {s : set Ξ±} {t : set Ξ²} (hs : is_measurable s) (ht : is_measurable t) :
(ΞΌ.restrict s).prod (Ξ½.restrict t) = (ΞΌ.prod Ξ½).restrict (s.prod t) :=
begin
refine prod_eq (Ξ» s' t' hs' ht', _),
simp_rw [restrict_apply (hs'.prod ht'), prod_inter_prod, prod_prod (hs'.inter hs) (ht'.inter ht),
restrict_apply hs', restrict_apply ht']
end
lemma prod_dirac (y : Ξ²) : ΞΌ.prod (dirac y) = map (Ξ» x, (x, y)) ΞΌ :=
begin
refine prod_eq (Ξ» s t hs ht, _),
simp_rw [map_apply measurable_prod_mk_right (hs.prod ht), mk_preimage_prod_left_eq_if, measure_if,
dirac_apply _ ht, β indicator_mul_right _ (Ξ» x, ΞΌ s), pi.one_apply, mul_one]
end
lemma dirac_prod (x : Ξ±) : (dirac x).prod Ξ½ = map (prod.mk x) Ξ½ :=
begin
refine prod_eq (Ξ» s t hs ht, _),
simp_rw [map_apply measurable_prod_mk_left (hs.prod ht), mk_preimage_prod_right_eq_if, measure_if,
dirac_apply _ hs, β indicator_mul_left _ _ (Ξ» x, Ξ½ t), pi.one_apply, one_mul]
end
lemma dirac_prod_dirac {x : Ξ±} {y : Ξ²} : (dirac x).prod (dirac y) = dirac (x, y) :=
by rw [prod_dirac, map_dirac measurable_prod_mk_right]
lemma prod_sum {ΞΉ : Type*} [fintype ΞΉ] (Ξ½ : ΞΉ β measure Ξ²) [β i, sigma_finite (Ξ½ i)] :
ΞΌ.prod (sum Ξ½) = sum (Ξ» i, ΞΌ.prod (Ξ½ i)) :=
begin
refine prod_eq (Ξ» s t hs ht, _),
simp_rw [sum_apply _ (hs.prod ht), sum_apply _ ht, prod_prod hs ht, tsum_fintype, finset.mul_sum]
end
lemma sum_prod {ΞΉ : Type*} [fintype ΞΉ] (ΞΌ : ΞΉ β measure Ξ±) [β i, sigma_finite (ΞΌ i)] :
(sum ΞΌ).prod Ξ½ = sum (Ξ» i, (ΞΌ i).prod Ξ½) :=
begin
refine prod_eq (Ξ» s t hs ht, _),
simp_rw [sum_apply _ (hs.prod ht), sum_apply _ hs, prod_prod hs ht, tsum_fintype, finset.sum_mul]
end
lemma prod_add (Ξ½' : measure Ξ²) [sigma_finite Ξ½'] : ΞΌ.prod (Ξ½ + Ξ½') = ΞΌ.prod Ξ½ + ΞΌ.prod Ξ½' :=
by { refine prod_eq (Ξ» s t hs ht, _), simp_rw [add_apply, prod_prod hs ht, left_distrib] }
lemma add_prod (ΞΌ' : measure Ξ±) [sigma_finite ΞΌ'] : (ΞΌ + ΞΌ').prod Ξ½ = ΞΌ.prod Ξ½ + ΞΌ'.prod Ξ½ :=
by { refine prod_eq (Ξ» s t hs ht, _), simp_rw [add_apply, prod_prod hs ht, right_distrib] }
end measure
open measure_theory.measure
/-! ### The Lebesgue integral on a product -/
variables [sigma_finite Ξ½]
lemma lintegral_prod_swap [sigma_finite ΞΌ] (f : Ξ± Γ Ξ² β ennreal)
(hf : measurable f) : β«β» z, f z.swap β(Ξ½.prod ΞΌ) = β«β» z, f z β(ΞΌ.prod Ξ½) :=
by rw [β lintegral_map hf measurable_swap, prod_swap]
/-- Tonelli's Theorem: For `ennreal`-valued measurable functions on `Ξ± Γ Ξ²`,
the integral of `f` is equal to the iterated integral. -/
lemma lintegral_prod :
β (f : Ξ± Γ Ξ² β ennreal) (hf : measurable f), β«β» z, f z β(ΞΌ.prod Ξ½) = β«β» x, β«β» y, f (x, y) βΞ½ βΞΌ :=
begin
have m := @measurable_prod_mk_left,
refine measurable.ennreal_induction _ _ _,
{ intros c s hs, simp only [β indicator_comp_right],
simp [lintegral_indicator, m hs, hs, lintegral_const_mul, measurable_measure_prod_mk_left hs,
prod_apply] },
{ rintro f g - hf hg h2f h2g,
simp [lintegral_add, measurable.lintegral_prod_right', hf.comp m, hg.comp m,
hf, hg, h2f, h2g] },
{ intros f hf h2f h3f,
have kf : β x n, measurable (Ξ» y, f n (x, y)) := Ξ» x n, (hf n).comp m,
have k2f : β x, monotone (Ξ» n y, f n (x, y)) := Ξ» x i j hij y, h2f hij (x, y),
have lf : β n, measurable (Ξ» x, β«β» y, f n (x, y) βΞ½) := Ξ» n, (hf n).lintegral_prod_right',
have l2f : monotone (Ξ» n x, β«β» y, f n (x, y) βΞ½) := Ξ» i j hij x, lintegral_mono (k2f x hij),
simp only [lintegral_supr hf h2f, lintegral_supr (kf _), k2f, lintegral_supr lf l2f, h3f] },
end
/-- The symmetric verion of Tonelli's Theorem: For `ennreal`-valued measurable functions on `Ξ± Γ Ξ²`,
the integral of `f` is equal to the iterated integral, in reverse order. -/
lemma lintegral_prod_symm [sigma_finite ΞΌ] (f : Ξ± Γ Ξ² β ennreal)
(hf : measurable f) : β«β» z, f z β(ΞΌ.prod Ξ½) = β«β» y, β«β» x, f (x, y) βΞΌ βΞ½ :=
by { simp_rw [β lintegral_prod_swap f hf], exact lintegral_prod _ (hf.comp measurable_swap) }
/-- The reversed version of Tonelli's Theorem. In this version `f` is in curried form, which makes
it easier for the elaborator to figure out `f` automatically. -/
lemma lintegral_lintegral β¦f : Ξ± β Ξ² β ennrealβ¦
(hf : measurable (uncurry f)) :
β«β» x, β«β» y, f x y βΞ½ βΞΌ = β«β» z, f z.1 z.2 β(ΞΌ.prod Ξ½) :=
(lintegral_prod _ hf).symm
/-- The reversed version of Tonelli's Theorem (symmetric version). In this version `f` is in curried
form, which makes it easier for the elaborator to figure out `f` automatically. -/
lemma lintegral_lintegral_symm [sigma_finite ΞΌ] β¦f : Ξ± β Ξ² β ennrealβ¦
(hf : measurable (uncurry f)) :
β«β» x, β«β» y, f x y βΞ½ βΞΌ = β«β» z, f z.2 z.1 β(Ξ½.prod ΞΌ) :=
(lintegral_prod_symm _ (hf.comp measurable_swap)).symm
/-- Change the order of Lebesgue integration. -/
lemma lintegral_lintegral_swap [sigma_finite ΞΌ] β¦f : Ξ± β Ξ² β ennrealβ¦
(hf : measurable (uncurry f)) :
β«β» x, β«β» y, f x y βΞ½ βΞΌ = β«β» y, β«β» x, f x y βΞΌ βΞ½ :=
(lintegral_lintegral hf).trans (lintegral_prod_symm _ hf)
/-! ### Integrability on a product -/
section
variables [opens_measurable_space E]
lemma integrable.swap [sigma_finite ΞΌ] β¦f : Ξ± Γ Ξ² β Eβ¦
(hf : integrable f (ΞΌ.prod Ξ½)) : integrable (f β prod.swap) (Ξ½.prod ΞΌ) :=
β¨hf.measurable.comp measurable_swap,
(lintegral_prod_swap _ hf.measurable.ennnorm : _).le.trans_lt hf.has_finite_integralβ©
lemma integrable_swap_iff [sigma_finite ΞΌ] β¦f : Ξ± Γ Ξ² β Eβ¦ :
integrable (f β prod.swap) (Ξ½.prod ΞΌ) β integrable f (ΞΌ.prod Ξ½) :=
β¨Ξ» hf, by { convert hf.swap, ext β¨x, yβ©, refl }, Ξ» hf, hf.swapβ©
lemma has_finite_integral_prod_iff β¦f : Ξ± Γ Ξ² β Eβ¦ (h1f : measurable f) :
has_finite_integral f (ΞΌ.prod Ξ½) β (βα΅ x β ΞΌ, has_finite_integral (Ξ» y, f (x, y)) Ξ½) β§
has_finite_integral (Ξ» x, β« y, β₯f (x, y)β₯ βΞ½) ΞΌ :=
begin
simp only [has_finite_integral, lintegral_prod _ h1f.ennnorm],
have : β x, βα΅ y βΞ½, 0 β€ β₯f (x, y)β₯ := Ξ» x, eventually_of_forall (Ξ» y, norm_nonneg _),
simp_rw [integral_eq_lintegral_of_nonneg_ae (this _) (h1f.norm.comp measurable_prod_mk_left),
ennnorm_eq_of_real to_real_nonneg, of_real_norm_eq_coe_nnnorm],
-- this fact is probably too specialized to be its own lemma
have : β {p q r : Prop} (h1 : r β p), (r β p β§ q) β (p β (r β q)) :=
Ξ» p q r h1, by rw [β and.congr_right_iff, and_iff_right_of_imp h1],
rw [this],
{ intro h2f, rw lintegral_congr_ae,
refine h2f.mp _, apply eventually_of_forall, intros x hx, dsimp only,
rw [of_real_to_real], rw [β lt_top_iff_ne_top], exact hx },
{ intro h2f, refine ae_lt_top _ h2f, exact h1f.ennnorm.lintegral_prod_right' },
end
/-- A binary function is integrable if the function `y β¦ f (x, y)` is integrable for almost every
`x` and the function `x β¦ β« β₯f (x, y)β₯ dy` is integrable. -/
lemma integrable_prod_iff β¦f : Ξ± Γ Ξ² β Eβ¦ (h1f : measurable f) :
integrable f (ΞΌ.prod Ξ½) β
(βα΅ x β ΞΌ, integrable (Ξ» y, f (x, y)) Ξ½) β§ integrable (Ξ» x, β« y, β₯f (x, y)β₯ βΞ½) ΞΌ :=
by simp only [integrable, h1f, h1f.comp measurable_prod_mk_left, h1f.norm.integral_prod_right',
true_and, has_finite_integral_prod_iff]
/-- A binary function is integrable if the function `x β¦ f (x, y)` is integrable for almost every
`y` and the function `y β¦ β« β₯f (x, y)β₯ dx` is integrable. -/
lemma integrable_prod_iff' [sigma_finite ΞΌ] β¦f : Ξ± Γ Ξ² β Eβ¦ (h1f : measurable f) :
integrable f (ΞΌ.prod Ξ½) β
(βα΅ y β Ξ½, integrable (Ξ» x, f (x, y)) ΞΌ) β§ integrable (Ξ» y, β« x, β₯f (x, y)β₯ βΞΌ) Ξ½ :=
by { convert integrable_prod_iff (h1f.comp measurable_swap) using 1, rw [integrable_swap_iff],
apply_instance }
lemma integrable.prod_left_ae [sigma_finite ΞΌ] β¦f : Ξ± Γ Ξ² β Eβ¦
(hf : integrable f (ΞΌ.prod Ξ½)) : βα΅ y β Ξ½, integrable (Ξ» x, f (x, y)) ΞΌ :=
((integrable_prod_iff' hf.measurable).mp hf).1
lemma integrable.prod_right_ae [sigma_finite ΞΌ] β¦f : Ξ± Γ Ξ² β Eβ¦
(hf : integrable f (ΞΌ.prod Ξ½)) : βα΅ x β ΞΌ, integrable (Ξ» y, f (x, y)) Ξ½ :=
hf.swap.prod_left_ae
lemma integrable.integral_norm_prod_left β¦f : Ξ± Γ Ξ² β Eβ¦
(hf : integrable f (ΞΌ.prod Ξ½)) : integrable (Ξ» x, β« y, β₯f (x, y)β₯ βΞ½) ΞΌ :=
((integrable_prod_iff hf.measurable).mp hf).2
lemma integrable.integral_norm_prod_right [sigma_finite ΞΌ] β¦f : Ξ± Γ Ξ² β Eβ¦
(hf : integrable f (ΞΌ.prod Ξ½)) : integrable (Ξ» y, β« x, β₯f (x, y)β₯ βΞΌ) Ξ½ :=
hf.swap.integral_norm_prod_left
end
variables [second_countable_topology E] [normed_space β E]
[complete_space E] [borel_space E]
lemma integrable.integral_prod_left β¦f : Ξ± Γ Ξ² β Eβ¦
(hf : integrable f (ΞΌ.prod Ξ½)) : integrable (Ξ» x, β« y, f (x, y) βΞ½) ΞΌ :=
integrable.mono hf.integral_norm_prod_left hf.measurable.integral_prod_right' $
eventually_of_forall $ Ξ» x, (norm_integral_le_integral_norm _).trans_eq $
(norm_of_nonneg $ integral_nonneg_of_ae $ eventually_of_forall $ Ξ» y, (norm_nonneg _ : _)).symm
lemma integrable.integral_prod_right [sigma_finite ΞΌ] β¦f : Ξ± Γ Ξ² β Eβ¦
(hf : integrable f (ΞΌ.prod Ξ½)) : integrable (Ξ» y, β« x, f (x, y) βΞΌ) Ξ½ :=
hf.swap.integral_prod_left
/-! ### The Bochner integral on a product -/
variables [sigma_finite ΞΌ]
lemma integral_prod_swap (f : Ξ± Γ Ξ² β E)
(hf : measurable f) : β« z, f z.swap β(Ξ½.prod ΞΌ) = β« z, f z β(ΞΌ.prod Ξ½) :=
by rw [β integral_map measurable_swap hf, prod_swap]
variables {E' : Type*} [measurable_space E'] [normed_group E'] [borel_space E'] [complete_space E']
[normed_space β E'] [second_countable_topology E']
/-! Some rules about the sum/difference of double integrals. They follow from `integral_add`, but
we separate them out as separate lemmas, because they involve quite some steps. -/
/-- Integrals commute with addition inside another integral. `F` can be any measurable function. -/
lemma integral_fn_integral_add β¦f g : Ξ± Γ Ξ² β Eβ¦
{F : E β E'} (hF : measurable F)
(hf : integrable f (ΞΌ.prod Ξ½))
(hg : integrable g (ΞΌ.prod Ξ½)) :
β« x, F (β« y, f (x, y) + g (x, y) βΞ½) βΞΌ = β« x, F (β« y, f (x, y) βΞ½ + β« y, g (x, y) βΞ½) βΞΌ :=
begin
refine integral_congr_ae
(hF.comp (hf.add hg).measurable.integral_prod_right')
(hF.comp (hf.measurable.integral_prod_right'.add hg.measurable.integral_prod_right')) _,
filter_upwards [hf.prod_right_ae, hg.prod_right_ae],
intros x h2f h2g, simp [integral_add h2f h2g],
end
/-- Integrals commute with subtraction inside another integral.
`F` can be any measurable function. -/
lemma integral_fn_integral_sub β¦f g : Ξ± Γ Ξ² β Eβ¦
{F : E β E'} (hF : measurable F)
(hf : integrable f (ΞΌ.prod Ξ½))
(hg : integrable g (ΞΌ.prod Ξ½)) :
β« x, F (β« y, f (x, y) - g (x, y) βΞ½) βΞΌ = β« x, F (β« y, f (x, y) βΞ½ - β« y, g (x, y) βΞ½) βΞΌ :=
begin
refine integral_congr_ae
(hF.comp (hf.sub hg).measurable.integral_prod_right')
(hF.comp (hf.measurable.integral_prod_right'.sub hg.measurable.integral_prod_right')) _,
filter_upwards [hf.prod_right_ae, hg.prod_right_ae],
intros x h2f h2g, simp [integral_sub h2f h2g]
end
/-- Integrals commute with subtraction inside a lower Lebesgue integral.
`F` can be any function. -/
lemma lintegral_fn_integral_sub β¦f g : Ξ± Γ Ξ² β Eβ¦
(F : E β ennreal) (hf : integrable f (ΞΌ.prod Ξ½)) (hg : integrable g (ΞΌ.prod Ξ½)) :
β«β» x, F (β« y, f (x, y) - g (x, y) βΞ½) βΞΌ = β«β» x, F (β« y, f (x, y) βΞ½ - β« y, g (x, y) βΞ½) βΞΌ :=
begin
refine lintegral_congr_ae _,
filter_upwards [hf.prod_right_ae, hg.prod_right_ae],
intros x h2f h2g, simp [integral_sub h2f h2g]
end
/-- Double integrals commute with addition. -/
lemma integral_integral_add β¦f g : Ξ± Γ Ξ² β Eβ¦
(hf : integrable f (ΞΌ.prod Ξ½))
(hg : integrable g (ΞΌ.prod Ξ½)) :
β« x, β« y, f (x, y) + g (x, y) βΞ½ βΞΌ = β« x, β« y, f (x, y) βΞ½ βΞΌ + β« x, β« y, g (x, y) βΞ½ βΞΌ :=
(integral_fn_integral_add measurable_id hf hg).trans $
integral_add hf.integral_prod_left hg.integral_prod_left
/-- Double integrals commute with addition. This is the version with `(f + g) (x, y)`
(instead of `f (x, y) + g (x, y)`) in the LHS. -/
lemma integral_integral_add' β¦f g : Ξ± Γ Ξ² β Eβ¦
(hf : integrable f (ΞΌ.prod Ξ½))
(hg : integrable g (ΞΌ.prod Ξ½)) :
β« x, β« y, (f + g) (x, y) βΞ½ βΞΌ = β« x, β« y, f (x, y) βΞ½ βΞΌ + β« x, β« y, g (x, y) βΞ½ βΞΌ :=
integral_integral_add hf hg
/-- Double integrals commute with subtraction. -/
lemma integral_integral_sub β¦f g : Ξ± Γ Ξ² β Eβ¦
(hf : integrable f (ΞΌ.prod Ξ½))
(hg : integrable g (ΞΌ.prod Ξ½)) :
β« x, β« y, f (x, y) - g (x, y) βΞ½ βΞΌ = β« x, β« y, f (x, y) βΞ½ βΞΌ - β« x, β« y, g (x, y) βΞ½ βΞΌ :=
(integral_fn_integral_sub measurable_id hf hg).trans $
integral_sub hf.integral_prod_left hg.integral_prod_left
/-- Double integrals commute with subtraction. This is the version with `(f - g) (x, y)`
(instead of `f (x, y) - g (x, y)`) in the LHS. -/
lemma integral_integral_sub' β¦f g : Ξ± Γ Ξ² β Eβ¦
(hf : integrable f (ΞΌ.prod Ξ½))
(hg : integrable g (ΞΌ.prod Ξ½)) :
β« x, β« y, (f - g) (x, y) βΞ½ βΞΌ = β« x, β« y, f (x, y) βΞ½ βΞΌ - β« x, β« y, g (x, y) βΞ½ βΞΌ :=
integral_integral_sub hf hg
/-- The map that sends an LΒΉ-function `f : Ξ± Γ Ξ² β E` to `β«β«f` is continuous. -/
lemma continuous_integral_integral :
continuous (Ξ» (f : Ξ± Γ Ξ² ββ[ΞΌ.prod Ξ½] E), β« x, β« y, f (x, y) βΞ½ βΞΌ) :=
begin
rw [continuous_iff_continuous_at], intro g,
refine tendsto_integral_of_l1 _ g.integrable.integral_prod_left
(eventually_of_forall $ Ξ» h, h.integrable.integral_prod_left) _,
simp_rw [edist_eq_coe_nnnorm_sub,
β lintegral_fn_integral_sub (Ξ» x, (nnnorm x : ennreal)) (l1.integrable _) g.integrable],
refine tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds _ (Ξ» i, zero_le _) _,
{ exact Ξ» i, β«β» x, β«β» y, nnnorm (i (x, y) - g (x, y)) βΞ½ βΞΌ },
swap, { exact Ξ» i, lintegral_mono (Ξ» x, ennnorm_integral_le_lintegral_ennnorm _) },
show tendsto (Ξ» (i : Ξ± Γ Ξ² ββ[ΞΌ.prod Ξ½] E),
β«β» x, β«β» (y : Ξ²), nnnorm (i (x, y) - g (x, y)) βΞ½ βΞΌ) (π g) (π 0),
have : β (i : Ξ± Γ Ξ² ββ[ΞΌ.prod Ξ½] E), measurable (Ξ» z, (nnnorm (i z - g z) : ennreal)) :=
Ξ» i, (i.measurable.sub g.measurable).ennnorm,
simp_rw [β lintegral_prod _ (this _), β l1.of_real_norm_sub_eq_lintegral, β of_real_zero],
refine (continuous_of_real.tendsto 0).comp _,
rw [β tendsto_iff_norm_tendsto_zero], exact tendsto_id
end
/-- Fubini's Theorem: For integrable functions on `Ξ± Γ Ξ²`,
the Bochner integral of `f` is equal to the iterated Bochner integral.
`integrable_prod_iff` can be useful to show that the function in question in integrable.
`measure_theory.integrable.integral_prod_right` is useful to show that the inner integral
of the right-hand side is integrable. -/
lemma integral_prod : β (f : Ξ± Γ Ξ² β E) (hf : integrable f (ΞΌ.prod Ξ½)),
β« z, f z β(ΞΌ.prod Ξ½) = β« x, β« y, f (x, y) βΞ½ βΞΌ :=
begin
apply integrable.induction,
{ intros c s hs h2s, simp_rw [integral_indicator measurable_const hs, β indicator_comp_right,
function.comp, integral_indicator measurable_const (measurable_prod_mk_left hs),
set_integral_const, integral_smul_const,
integral_to_real (measurable_measure_prod_mk_left hs) (ae_measure_lt_top hs h2s),
prod_apply hs] },
{ intros f g hfg i_f i_g hf hg,
simp_rw [integral_add' i_f i_g, integral_integral_add' i_f i_g, hf, hg] },
{ exact is_closed_eq continuous_integral continuous_integral_integral },
{ intros f g hfg i_f m_g hf, convert hf using 1,
{ exact integral_congr_ae m_g i_f.measurable hfg.symm },
{ refine integral_congr_ae m_g.integral_prod_right' i_f.measurable.integral_prod_right' _,
rw [eventually_eq] at hfg, refine (ae_ae_of_ae_prod hfg).mp _,
apply eventually_of_forall, intros x hfgx,
refine integral_congr_ae (m_g.comp measurable_prod_mk_left)
(i_f.measurable.comp measurable_prod_mk_left) (ae_eq_symm hfgx) } }
end
/-- Symmetric version of Fubini's Theorem: For integrable functions on `Ξ± Γ Ξ²`,
the Bochner integral of `f` is equal to the iterated Bochner integral.
This version has the integrals on the right-hand side in the other order. -/
lemma integral_prod_symm (f : Ξ± Γ Ξ² β E) (hf : integrable f (ΞΌ.prod Ξ½)) :
β« z, f z β(ΞΌ.prod Ξ½) = β« y, β« x, f (x, y) βΞΌ βΞ½ :=
by { simp_rw [β integral_prod_swap f hf.measurable], exact integral_prod _ hf.swap }
/-- Reversed version of Fubini's Theorem. -/
lemma integral_integral {f : Ξ± β Ξ² β E} (hf : integrable (uncurry f) (ΞΌ.prod Ξ½)) :
β« x, β« y, f x y βΞ½ βΞΌ = β« z, f z.1 z.2 β(ΞΌ.prod Ξ½) :=
(integral_prod _ hf).symm
/-- Reversed version of Fubini's Theorem (symmetric version). -/
lemma integral_integral_symm {f : Ξ± β Ξ² β E} (hf : integrable (uncurry f) (ΞΌ.prod Ξ½)) :
β« x, β« y, f x y βΞ½ βΞΌ = β« z, f z.2 z.1 β(Ξ½.prod ΞΌ) :=
(integral_prod_symm _ hf.swap).symm
/-- Change the order of Bochner integration. -/
lemma integral_integral_swap β¦f : Ξ± β Ξ² β Eβ¦ (hf : integrable (uncurry f) (ΞΌ.prod Ξ½)) :
β« x, β« y, f x y βΞ½ βΞΌ = β« y, β« x, f x y βΞΌ βΞ½ :=
(integral_integral hf).trans (integral_prod_symm _ hf)
end measure_theory
|
6fef838afd92cc8c36d7fb13445089acc834d3ed | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/inaccessible2.lean | 18276ee2cf071f82bc281b28281968de951aaca5 | [
"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 | 883 | lean | inductive imf {A B : Sort*} (f : A β B) : B β Sort*
| mk : β (a : A), imf (f a)
definition inv_1 {A B : Sort*} (f : A β B) : β (b : B), imf f b β A
| .(f .(a)) (imf.mk a) := a -- Error inaccessible annotation inside inaccessible annotation
definition inv_2 {A B : Sort*} (f : A β B) : β (b : B), imf f b β A
| .(f a) (let x := (imf.mk a) in x) := a -- Error invalid occurrence of 'let' expression
definition inv_3 {A B : Sort*} (f : A β B) : β (b : B), imf f b β A
| .(f a) ((Ξ» (x : imf f b), x) (imf.mk a)) := a -- Error invalid occurrence of 'lambda' expression
definition sym {A : Sort*} : β a b : A, a = b β b = a
| .(a) .(a) (eq.refl a) := rfl -- Error `a` in eq.refl must be marked as inaccessible since it is an inductive datatype parameter
definition symm2 {A : Sort*} : β a b : A, a = b β b = a
| _ _ rfl := rfl -- correct version
|
1ac02cd1bcd85457cad0f0fcfabb3d6899389849 | 3f7026ea8bef0825ca0339a275c03b911baef64d | /src/data/fin.lean | ee01d7f0a85067dfccb15a3375a1a0d4309f7840 | [
"Apache-2.0"
] | permissive | rspencer01/mathlib | b1e3afa5c121362ef0881012cc116513ab09f18c | c7d36292c6b9234dc40143c16288932ae38fdc12 | refs/heads/master | 1,595,010,346,708 | 1,567,511,503,000 | 1,567,511,503,000 | 206,071,681 | 0 | 0 | Apache-2.0 | 1,567,513,643,000 | 1,567,513,643,000 | null | UTF-8 | Lean | false | false | 13,816 | lean | /-
Copyright (c) 2017 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Keeley Hoek
More about finite numbers.
-/
import data.nat.basic
open fin nat
/-- `fin 0` is empty -/
def fin_zero_elim {C : Sort*} : fin 0 β C :=
Ξ» x, false.elim $ nat.not_lt_zero x.1 x.2
def {u} fin_zero_elim' {Ξ± : fin 0 β Sort u} : β(x : fin 0), Ξ± x
| β¨n, hnβ© := false.elim (nat.not_lt_zero n hn)
namespace fin
variables {n m : β} {a b : fin n}
@[simp] protected lemma eta (a : fin n) (h : a.1 < n) : (β¨a.1, hβ© : fin n) = a :=
by cases a; refl
protected lemma ext_iff (a b : fin n) : a = b β a.val = b.val :=
iff.intro (congr_arg _) fin.eq_of_veq
lemma eq_iff_veq (a b : fin n) : a = b β a.1 = b.1 :=
β¨veq_of_eq, eq_of_veqβ©
@[simp] protected lemma mk.inj_iff {n a b : β} {ha : a < n} {hb : b < n} :
fin.mk a ha = fin.mk b hb β a = b :=
β¨fin.mk.inj, Ξ» h, by subst hβ©
instance fin_to_nat (n : β) : has_coe (fin n) nat := β¨fin.valβ©
@[simp] lemma mk_val {m n : β} (h : m < n) : (β¨m, hβ© : fin n).val = m := rfl
@[simp] lemma coe_mk {m n : β} (h : m < n) : ((β¨m, hβ© : fin n) : β) = m := rfl
lemma coe_eq_val (a : fin n) : (a : β) = a.val := rfl
instance {n : β} : decidable_linear_order (fin n) :=
decidable_linear_order.lift fin.val (@fin.eq_of_veq _) (by apply_instance)
lemma exists_iff {p : fin n β Prop} : (β i, p i) β β i h, p β¨i, hβ© :=
β¨Ξ» h, exists.elim h (Ξ» β¨i, hiβ© hpi, β¨i, hi, hpiβ©),
Ξ» h, exists.elim h (Ξ» i hi, β¨β¨i, hi.fstβ©, hi.sndβ©)β©
lemma forall_iff {p : fin n β Prop} : (β i, p i) β β i h, p β¨i, hβ© :=
β¨Ξ» h i hi, h β¨i, hiβ©, Ξ» h β¨i, hiβ©, h i hiβ©
lemma zero_le (a : fin (n + 1)) : 0 β€ a := zero_le a.1
lemma lt_iff_val_lt_val : a < b β a.val < b.val := iff.refl _
lemma le_iff_val_le_val : a β€ b β a.val β€ b.val := iff.refl _
@[simp] lemma succ_val (j : fin n) : j.succ.val = j.val.succ :=
by cases j; simp [fin.succ]
protected theorem succ.inj (p : fin.succ a = fin.succ b) : a = b :=
by cases a; cases b; exact eq_of_veq (nat.succ.inj (veq_of_eq p))
lemma succ_ne_zero {n} : β k : fin n, fin.succ k β 0
| β¨k, hkβ© heq := nat.succ_ne_zero k $ (fin.ext_iff _ _).1 heq
@[simp] lemma pred_val (j : fin (n+1)) (h : j β 0) : (j.pred h).val = j.val.pred :=
by cases j; simp [fin.pred]
@[simp] lemma succ_pred : β(i : fin (n+1)) (h : i β 0), (i.pred h).succ = i
| β¨0, hβ© hi := by contradiction
| β¨n + 1, hβ© hi := rfl
@[simp] lemma pred_succ (i : fin n) {h : i.succ β 0} : i.succ.pred h = i :=
by cases i; refl
@[simp] lemma pred_inj :
β {a b : fin (n + 1)} {ha : a β 0} {hb : b β 0}, a.pred ha = b.pred hb β a = b
| β¨0, _β© b ha hb := by contradiction
| β¨i+1, _β© β¨0, _β© ha hb := by contradiction
| β¨i+1, hiβ© β¨j+1, hjβ© ha hb := by simp [fin.eq_iff_veq]
/-- The greatest value of `fin (n+1)` -/
def last (n : β) : fin (n+1) := β¨_, n.lt_succ_selfβ©
/-- `cast_lt i h` embeds `i` into a `fin` where `h` proves it belongs into. -/
def cast_lt (i : fin m) (h : i.1 < n) : fin n := β¨i.1, hβ©
/-- `cast_le h i` embeds `i` into a larger `fin` type. -/
def cast_le (h : n β€ m) (a : fin n) : fin m := cast_lt a (lt_of_lt_of_le a.2 h)
/-- `cast eq i` embeds `i` into a equal `fin` type. -/
def cast (eq : n = m) : fin n β fin m := cast_le $ le_of_eq eq
/-- `cast_add m i` embedds `i` in `fin (n+m)`. -/
def cast_add (m) : fin n β fin (n + m) := cast_le $ le_add_right n m
/-- `cast_succ i` embedds `i` in `fin (n+1)`. -/
def cast_succ : fin n β fin (n + 1) := cast_add 1
/-- `succ_above p i` embeds into `fin (n + 1)` with a hole around `p`. -/
def succ_above (p : fin (n+1)) (i : fin n) : fin (n+1) :=
if i.1 < p.1 then i.cast_succ else i.succ
/-- `pred_above p i h` embeds `i` into `fin n` by ignoring `p`. -/
def pred_above (p : fin (n+1)) (i : fin (n+1)) (hi : i β p) : fin n :=
if h : i < p
then i.cast_lt (lt_of_lt_of_le h $ nat.le_of_lt_succ p.2)
else i.pred $
have p < i, from lt_of_le_of_ne (le_of_not_gt h) hi.symm,
ne_of_gt (lt_of_le_of_lt (zero_le p) this)
/-- `sub_nat i h` subtracts `m` from `i`, generalizes `fin.pred`. -/
def sub_nat (m) (i : fin (n + m)) (h : i.val β₯ m) : fin n :=
β¨i.val - m, by simp [nat.sub_lt_right_iff_lt_add h, i.is_lt]β©
/-- `add_nat i h` adds `m` on `i`, generalizes `fin.succ`. -/
def add_nat (m) (i : fin n) : fin (n + m) :=
β¨i.1 + m, add_lt_add_right i.2 _β©
/-- `nat_add i h` adds `n` on `i` -/
def nat_add (n) {m} (i : fin m) : fin (n + m) :=
β¨n + i.1, add_lt_add_left i.2 _β©
theorem le_last (i : fin (n+1)) : i β€ last n :=
le_of_lt_succ i.is_lt
@[simp] lemma cast_val (k : fin n) (h : n = m) : (fin.cast h k).val = k.val := rfl
@[simp] lemma cast_succ_val (k : fin n) : k.cast_succ.val = k.val := rfl
@[simp] lemma cast_lt_val (k : fin m) (h : k.1 < n) : (k.cast_lt h).val = k.val := rfl
@[simp] lemma cast_le_val (k : fin m) (h : m β€ n) : (k.cast_le h).val = k.val := rfl
@[simp] lemma cast_add_val (k : fin m) : (k.cast_add n).val = k.val := rfl
@[simp] lemma last_val (n : β) : (last n).val = n := rfl
@[simp] lemma cast_succ_cast_lt (i : fin (n + 1)) (h : i.val < n) : cast_succ (cast_lt i h) = i :=
fin.eq_of_veq rfl
@[simp] lemma cast_lt_cast_succ {n : β} (a : fin n) (h : a.1 < n) : cast_lt (cast_succ a) h = a :=
by cases a; refl
@[simp] lemma sub_nat_val (i : fin (n + m)) (h : i.val β₯ m) : (i.sub_nat m h).val = i.val - m :=
rfl
@[simp] lemma add_nat_val (i : fin (n + m)) (h : i.val β₯ m) : (i.add_nat m).val = i.val + m :=
rfl
@[simp] lemma cast_succ_inj {a b : fin n} : a.cast_succ = b.cast_succ β a = b :=
by simp [eq_iff_veq]
def clamp (n m : β) : fin (m + 1) := fin.of_nat $ min n m
@[simp] lemma clamp_val (n m : β) : (clamp n m).val = min n m :=
nat.mod_eq_of_lt $ nat.lt_succ_iff.mpr $ min_le_right _ _
lemma injective_cast_le {nβ nβ : β} (h : nβ β€ nβ) : function.injective (fin.cast_le h)
| β¨iβ, hββ© β¨iβ, hββ© eq := fin.eq_of_veq $ show iβ = iβ, from fin.veq_of_eq eq
theorem succ_above_ne (p : fin (n+1)) (i : fin n) : p.succ_above i β p :=
begin
assume eq,
unfold fin.succ_above at eq,
split_ifs at eq with h;
simpa [lt_irrefl, nat.lt_succ_self, eq.symm] using h
end
@[simp] lemma succ_above_descend : β(p i : fin (n+1)) (h : i β p), p.succ_above (p.pred_above i h) = i
| β¨p, hpβ© β¨0, hiβ© h := fin.eq_of_veq $ by simp [succ_above, pred_above]; split_ifs; simp * at *
| β¨p, hpβ© β¨i+1, hiβ© h := fin.eq_of_veq
begin
have : i + 1 β p, by rwa [(β ), fin.ext_iff] at h,
unfold succ_above pred_above,
split_ifs with h1 h2;
simp only [fin.cast_succ_cast_lt, add_right_inj, pred_val, ne.def, cast_succ_val,
nat.pred_succ, fin.succ_pred, add_right_inj] at *,
exact (this (le_antisymm h2 (le_of_not_gt h1))).elim
end
@[simp] lemma pred_above_succ_above (p : fin (n+1)) (i : fin n) (h : p.succ_above i β p) :
p.pred_above (p.succ_above i) h = i :=
begin
unfold fin.succ_above,
apply eq_of_veq,
split_ifs with hβ,
{ simp [pred_above, hβ, lt_iff_val_lt_val], },
{ unfold pred_above,
split_ifs with hβ,
{ exfalso,
rw [lt_iff_val_lt_val, succ_val] at hβ,
exact hβ (lt_trans (nat.lt_succ_self _) hβ) },
{ rw [pred_succ] } }
end
section rec
@[elab_as_eliminator] def succ_rec
{C : β n, fin n β Sort*}
(H0 : β n, C (succ n) 0)
(Hs : β n i, C n i β C (succ n) i.succ) : β {n : β} (i : fin n), C n i
| 0 i := i.elim0
| (succ n) β¨0, _β© := H0 _
| (succ n) β¨succ i, hβ© := Hs _ _ (succ_rec β¨i, lt_of_succ_lt_succ hβ©)
@[elab_as_eliminator] def succ_rec_on {n : β} (i : fin n)
{C : β n, fin n β Sort*}
(H0 : β n, C (succ n) 0)
(Hs : β n i, C n i β C (succ n) i.succ) : C n i :=
i.succ_rec H0 Hs
@[simp] theorem succ_rec_on_zero {C : β n, fin n β Sort*} {H0 Hs} (n) :
@fin.succ_rec_on (succ n) 0 C H0 Hs = H0 n :=
rfl
@[simp] theorem succ_rec_on_succ {C : β n, fin n β Sort*} {H0 Hs} {n} (i : fin n) :
@fin.succ_rec_on (succ n) i.succ C H0 Hs = Hs n i (fin.succ_rec_on i H0 Hs) :=
by cases i; refl
@[elab_as_eliminator] def cases
{C : fin (succ n) β Sort*} (H0 : C 0) (Hs : β i : fin n, C (i.succ)) :
β (i : fin (succ n)), C i
| β¨0, hβ© := H0
| β¨succ i, hβ© := Hs β¨i, lt_of_succ_lt_succ hβ©
@[simp] theorem cases_zero {n} {C : fin (succ n) β Sort*} {H0 Hs} : @fin.cases n C H0 Hs 0 = H0 :=
rfl
@[simp] theorem cases_succ {n} {C : fin (succ n) β Sort*} {H0 Hs} (i : fin n) :
@fin.cases n C H0 Hs i.succ = Hs i :=
by cases i; refl
lemma forall_fin_succ {P : fin (n+1) β Prop} :
(β i, P i) β P 0 β§ (β i:fin n, P i.succ) :=
β¨Ξ» H, β¨H 0, Ξ» i, H _β©, Ξ» β¨H0, H1β© i, fin.cases H0 H1 iβ©
lemma exists_fin_succ {P : fin (n+1) β Prop} :
(β i, P i) β P 0 β¨ (βi:fin n, P i.succ) :=
β¨Ξ» β¨i, hβ©, fin.cases or.inl (Ξ» i hi, or.inr β¨i, hiβ©) i h,
Ξ» h, or.elim h (Ξ» h, β¨0, hβ©) $ Ξ»β¨i, hiβ©, β¨i.succ, hiβ©β©
end rec
section tuple
/- We can think of the type `fin n β Ξ±` as `n`-tuples in `Ξ±`. Here are some relevant operations. -/
def tail {Ξ±} (p : fin (n+1) β Ξ±) : fin n β Ξ± := Ξ» i, p i.succ
def cons {Ξ±} (x : Ξ±) (v : fin n β Ξ±) : fin (n+1) β Ξ± :=
Ξ» j, fin.cases x v j
@[simp] lemma tail_cons {Ξ±} (x : Ξ±) (p : fin n β Ξ±) : tail (cons x p) = p :=
by simp [tail, cons]
@[simp] lemma cons_succ {Ξ±} (x : Ξ±) (p : fin n β Ξ±) (i : fin n) : cons x p i.succ = p i :=
by simp [cons]
@[simp] lemma cons_zero {Ξ±} (x : Ξ±) (p : fin n β Ξ±) : cons x p 0 = x :=
by simp [cons]
end tuple
section find
def find : Ξ {n : β} (p : fin n β Prop) [decidable_pred p], option (fin n)
| 0 p _ := none
| (n+1) p _ := by resetI; exact option.cases_on
(@find n (Ξ» i, p (i.cast_lt (nat.lt_succ_of_lt i.2))) _)
(if h : p (fin.last n) then some (fin.last n) else none)
(Ξ» i, some (i.cast_lt (nat.lt_succ_of_lt i.2)))
lemma find_spec : Ξ {n : β} (p : fin n β Prop) [decidable_pred p] {i : fin n}
(hi : i β by exactI fin.find p), p i
| 0 p I i hi := option.no_confusion hi
| (n+1) p I i hi := begin
dsimp [find] at hi,
resetI,
cases h : find (Ξ» i : fin n, (p (i.cast_lt (nat.lt_succ_of_lt i.2)))) with j,
{ rw h at hi,
dsimp at hi,
split_ifs at hi with hl hl,
{ exact option.some_inj.1 hi βΈ hl },
{ exact option.no_confusion hi } },
{ rw h at hi,
rw [β option.some_inj.1 hi],
exact find_spec _ h }
end
lemma is_some_find_iff : Ξ {n : β} {p : fin n β Prop} [decidable_pred p],
by exactI (find p).is_some β β i, p i
| 0 p _ := iff_of_false (Ξ» h, bool.no_confusion h) (Ξ» β¨i, _β©, fin.elim0 i)
| (n+1) p _ := β¨Ξ» h, begin
resetI,
rw [option.is_some_iff_exists] at h,
cases h with i hi,
exact β¨i, find_spec _ hiβ©
end, Ξ» β¨β¨i, hinβ©, hiβ©,
begin
resetI,
dsimp [find],
cases h : find (Ξ» i : fin n, (p (i.cast_lt (nat.lt_succ_of_lt i.2)))) with j,
{ split_ifs with hl hl,
{ exact option.is_some_some },
{ have := (@is_some_find_iff n (Ξ» x, p (x.cast_lt (nat.lt_succ_of_lt x.2))) _).2
β¨β¨i, lt_of_le_of_ne (nat.le_of_lt_succ hin)
(Ξ» h, by clear_aux_decl; subst h; exact hl hi)β©, hiβ©,
rw h at this,
exact this } },
{ simp }
endβ©
lemma find_eq_none_iff {n : β} {p : fin n β Prop} [decidable_pred p] :
find p = none β β i, Β¬ p i :=
by rw [β not_exists, β is_some_find_iff]; cases (find p); simp
lemma find_min : Ξ {n : β} {p : fin n β Prop} [decidable_pred p] {i : fin n}
(hi : i β by exactI fin.find p) {j : fin n} (hj : j < i), Β¬ p j
| 0 p _ i hi j hj hpj := option.no_confusion hi
| (n+1) p _ i hi β¨j, hjnβ© hj hpj := begin
resetI,
dsimp [find] at hi,
cases h : find (Ξ» i : fin n, (p (i.cast_lt (nat.lt_succ_of_lt i.2)))) with k,
{ rw [h] at hi,
split_ifs at hi with hl hl,
{ have := option.some_inj.1 hi,
subst this,
rw [find_eq_none_iff] at h,
exact h β¨j, hjβ© hpj },
{ exact option.no_confusion hi } },
{ rw h at hi,
dsimp at hi,
have := option.some_inj.1 hi,
subst this,
exact find_min h (show (β¨j, lt_trans hj k.2β© : fin n) < k, from hj) hpj }
end
lemma find_min' {p : fin n β Prop} [decidable_pred p] {i : fin n}
(h : i β fin.find p) {j : fin n} (hj : p j) : i β€ j :=
le_of_not_gt (Ξ» hij, find_min h hij hj)
lemma nat_find_mem_find {p : fin n β Prop} [decidable_pred p]
(h : β i, β hin : i < n, p β¨i, hinβ©) :
(β¨nat.find h, (nat.find_spec h).fstβ© : fin n) β find p :=
let β¨i, hin, hiβ© := h in
begin
cases hf : find p with f,
{ rw [find_eq_none_iff] at hf,
exact (hf β¨i, hinβ© hi).elim },
{ refine option.some_inj.2 (le_antisymm _ _),
{ exact find_min' hf (nat.find_spec h).snd },
{ exact nat.find_min' _ β¨f.2, by convert find_spec p hf;
exact fin.eta _ _β© } }
end
lemma mem_find_iff {p : fin n β Prop} [decidable_pred p] {i : fin n} :
i β fin.find p β p i β§ β j, p j β i β€ j :=
β¨Ξ» hi, β¨find_spec _ hi, Ξ» _, find_min' hiβ©,
begin
rintros β¨hpi, hjβ©,
cases hfp : fin.find p,
{ rw [find_eq_none_iff] at hfp,
exact (hfp _ hpi).elim },
{ exact option.some_inj.2 (le_antisymm (find_min' hfp hpi) (hj _ (find_spec _ hfp))) }
endβ©
lemma find_eq_some_iff {p : fin n β Prop} [decidable_pred p] {i : fin n} :
fin.find p = some i β p i β§ β j, p j β i β€ j :=
mem_find_iff
lemma mem_find_of_unique {p : fin n β Prop} [decidable_pred p]
(h : β i j, p i β p j β i = j) {i : fin n} (hi : p i) : i β fin.find p :=
mem_find_iff.2 β¨hi, Ξ» j hj, le_of_eq $ h i j hi hjβ©
end find
end fin
|
498994c864be1de7d3bbd7fbb4fe3c4ba1154e05 | fcf3ffa92a3847189ca669cb18b34ef6b2ec2859 | /src/world3/level6.lean | 68a1717328b6bb60c4d4de04ab3ee9e5672f0974 | [
"Apache-2.0"
] | permissive | nomoid/lean-proofs | 4a80a97888699dee42b092b7b959b22d9aa0c066 | b9f03a24623d1a1d111d6c2bbf53c617e2596d6a | refs/heads/master | 1,674,955,317,080 | 1,607,475,706,000 | 1,607,475,706,000 | 314,104,281 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 547 | lean | import mynat.definition
import mynat.mul
import world2.level2
import world2.level5
import world2.level6
namespace mynat
lemma succ_mul (a b : mynat) : succ(a) * b = a * b + b :=
begin [nat_num_game]
induction b with d hd,
{
repeat {rw mul_zero},
rw add_zero,
refl,
},
{
rw mul_succ,
rw hd,
rw mul_succ,
rw succ_eq_add_one,
rw succ_eq_add_one,
rw β add_assoc,
rw β add_assoc,
rw add_right_comm (a * d),
refl,
},
end
end mynat |
cac48cb78d3a7e56bc733519415d63dbaae6537d | 59a4b050600ed7b3d5826a8478db0a9bdc190252 | /src/category_theory/examples/rings/universal.lean | e58ee7200301d2041537b68ecf4233156749ee3c | [] | no_license | rwbarton/lean-category-theory | f720268d800b62a25d69842ca7b5d27822f00652 | 00df814d463406b7a13a56f5dcda67758ba1b419 | refs/heads/master | 1,585,366,296,767 | 1,536,151,349,000 | 1,536,151,349,000 | 147,652,096 | 0 | 0 | null | 1,536,226,960,000 | 1,536,226,960,000 | null | UTF-8 | Lean | false | false | 3,277 | lean | import ring_theory.ideals
import linear_algebra.quotient_module
import category_theory.examples.rings
import category_theory.limits
import category_theory.filtered
universes v
namespace category_theory.examples
open category_theory
open category_theory.limits
variables {Ξ± : Type v}
instance : has_products.{v+1 v} CommRing := sorry
def coequalizer_ideal {R S : CommRing} (f g : ring_hom R S) : set S.1 :=
span (set.range (Ξ» x : R.1, f.map x - g.map x))
instance {R S : CommRing} (f g : ring_hom R S) : is_ideal (coequalizer_ideal f g) := sorry
local attribute [instance] classical.prop_decidable
instance : has_coequalizers.{v+1 v} CommRing :=
{ coequalizer := Ξ» R S f g,
{ X := β¨ quotient_ring.quotient (coequalizer_ideal f g), by apply_instance β©,
Ο := β¨ quotient_ring.mk, by apply_instance β©,
w := sorry /- almost there: -/
/- begin
ext, dsimp, apply quotient.sound, fsplit,
exact finsupp.single 1 (f.map x - g.map x), obviously,
sorry, sorry
end -/ },
is_coequalizer := Ξ» R S f g,
{ desc := Ξ» s,
{ map := sorry,
is_ring_hom := sorry, },
fac := sorry,
uniq := sorry }
}
instance : has_colimits.{v+1 v} CommRing := sorry
section
variables {J : Type v} [π₯ : small_category J] [filtered.{v v} J]
include π₯
def matching (F : J β₯€ CommRing) (a b : Ξ£ j : J, (F j).1) : Prop :=
β (j : J) (f_a : a.1 βΆ j) (f_b : b.1 βΆ j),
(F.map f_a).map a.2 = (F.map f_b).map b.2
def filtered_colimit (F : J β₯€ CommRing) :=
@quot (Ξ£ j : J, (F j).1) (matching F)
local attribute [elab_with_expected_type] quot.lift
def filtered_colimit.zero (F : J β₯€ CommRing) : filtered_colimit F :=
quot.mk _ β¨ filtered.default.{v v} J, 0 β©
-- TODO do this in two steps.
def filtered_colimit.add (F : J β₯€ CommRing) (x y : filtered_colimit F) : filtered_colimit F :=
quot.lift (Ξ» p : Ξ£ j, (F j).1,
quot.lift (Ξ» q : Ξ£ j, (F j).1,
quot.mk _ (begin
have s := filtered.obj_bound.{v v} p.1 q.1,
exact β¨ s.X, ((F.map s.ΞΉβ).map p.2) + ((F.map s.ΞΉβ).map q.2) β©
end : Ξ£ j, (F j).1))
(Ξ» q q' (r : matching F q q'), @quot.sound _ (matching F) _ _
begin
dunfold matching,
dsimp,
dsimp [matching] at r,
rcases r with β¨j, f_a, f_b, eβ©,
/- this is messy, but doable -/
sorry
end))
(Ξ» p p' (r : matching F p p'), funext $ Ξ» q, begin dsimp, /- no idea -/ sorry end) x y
def filtered_colimit_is_comm_ring (F : J β₯€ CommRing) : comm_ring (filtered_colimit F) :=
{ add := filtered_colimit.add F,
neg := sorry,
mul := sorry,
zero := filtered_colimit.zero F,
one := sorry,
add_comm := sorry,
add_assoc := sorry,
zero_add := sorry,
add_zero := sorry,
add_left_neg := sorry,
mul_comm := sorry,
mul_assoc := sorry,
one_mul := sorry,
mul_one := sorry,
left_distrib := sorry,
right_distrib := sorry }
end
instance : has_filtered_colimits.{v+1 v} CommRing :=
{ colimit := Ξ» J π₯ f F,
begin
resetI, exact
{ X := β¨ filtered_colimit F, filtered_colimit_is_comm_ring F β©,
ΞΉ := Ξ» j, { map := Ξ» x, begin sorry end,
is_ring_hom := sorry },
w := sorry, }
end,
is_colimit := sorry }
end category_theory.examples |
d8e4ca5dda30aeb45488933f46f9856968448d64 | 367134ba5a65885e863bdc4507601606690974c1 | /src/representation_theory/maschke.lean | 9efb91063616d553d9c9b05451b8df57d403aa79 | [
"Apache-2.0"
] | permissive | kodyvajjha/mathlib | 9bead00e90f68269a313f45f5561766cfd8d5cad | b98af5dd79e13a38d84438b850a2e8858ec21284 | refs/heads/master | 1,624,350,366,310 | 1,615,563,062,000 | 1,615,563,062,000 | 162,666,963 | 0 | 0 | Apache-2.0 | 1,545,367,651,000 | 1,545,367,651,000 | null | UTF-8 | Lean | false | false | 6,234 | lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Scott Morrison
-/
import algebra.monoid_algebra
import algebra.invertible
import algebra.char_p.basic
import linear_algebra.basis
import ring_theory.simple_module
/-!
# Maschke's theorem
We prove Maschke's theorem for finite groups,
in the formulation that every submodule of a `k[G]` module has a complement,
when `k` is a field with `Β¬(ring_char k β£ fintype.card G)`.
We do the core computation in greater generality.
For any `[comm_ring k]` in which `[invertible (fintype.card G : k)]`,
and a `k[G]`-linear map `i : V β W` which admits a `k`-linear retraction `Ο`,
we produce a `k[G]`-linear retraction by
taking the average over `G` of the conjugates of `Ο`.
## Future work
It's not so far to give the usual statement, that every finite dimensional representation
of a finite group is semisimple (i.e. a direct sum of irreducibles).
-/
universes u
noncomputable theory
open semimodule
open monoid_algebra
open_locale big_operators
section
-- At first we work with any `[comm_ring k]`, and add the assumption that
-- `[invertible (fintype.card G : k)]` when it is required.
variables {k : Type u} [comm_ring k] {G : Type u} [group G]
variables {V : Type u} [add_comm_group V] [module k V] [module (monoid_algebra k G) V]
variables [is_scalar_tower k (monoid_algebra k G) V]
variables {W : Type u} [add_comm_group W] [module k W] [module (monoid_algebra k G) W]
variables [is_scalar_tower k (monoid_algebra k G) W]
/-!
We now do the key calculation in Maschke's theorem.
Given `V β W`, an inclusion of `k[G]` modules,,
assume we have some retraction `Ο` (i.e. `β v, Ο (i v) = v`),
just as a `k`-linear map.
(When `k` is a field, this will be available cheaply, by choosing a basis.)
We now construct a retraction of the inclusion as a `k[G]`-linear map,
by the formula
$$ \frac{1}{|G|} \sum_{g \in G} gβ»ΒΉ β’ Ο(g β’ -). $$
-/
namespace linear_map
variables (Ο : W ββ[k] V)
include Ο
/--
We define the conjugate of `Ο` by `g`, as a `k`-linear map.
-/
def conjugate (g : G) : W ββ[k] V :=
((group_smul.linear_map k V gβ»ΒΉ).comp Ο).comp (group_smul.linear_map k W g)
variables (i : V ββ[monoid_algebra k G] W) (h : β v : V, Ο (i v) = v)
section
include h
lemma conjugate_i (g : G) (v : V) : (conjugate Ο g) (i v) = v :=
begin
dsimp [conjugate],
simp only [βi.map_smul, h, βmul_smul, single_mul_single, mul_one, mul_left_inv],
change (1 : monoid_algebra k G) β’ v = v,
simp,
end
end
variables (G) [fintype G]
/--
The sum of the conjugates of `Ο` by each element `g : G`, as a `k`-linear map.
(We postpone dividing by the size of the group as long as possible.)
-/
def sum_of_conjugates : W ββ[k] V :=
β g : G, Ο.conjugate g
/--
In fact, the sum over `g : G` of the conjugate of `Ο` by `g` is a `k[G]`-linear map.
-/
def sum_of_conjugates_equivariant : W ββ[monoid_algebra k G] V :=
monoid_algebra.equivariant_of_linear_of_comm (Ο.sum_of_conjugates G) (Ξ» g v,
begin
dsimp [sum_of_conjugates],
simp only [linear_map.sum_apply, finset.smul_sum],
dsimp [conjugate],
conv_lhs {
rw [βfinset.univ_map_embedding (mul_right_embedding gβ»ΒΉ)],
simp only [mul_right_embedding],
},
simp only [βmul_smul, single_mul_single, mul_inv_rev, mul_one, function.embedding.coe_fn_mk,
finset.sum_map, inv_inv, inv_mul_cancel_right],
recover,
end)
section
variables [inv : invertible (fintype.card G : k)]
include inv
/--
We construct our `k[G]`-linear retraction of `i` as
$$ \frac{1}{|G|} \sum_{g \in G} gβ»ΒΉ β’ Ο(g β’ -). $$
-/
def equivariant_projection : W ββ[monoid_algebra k G] V :=
β
(fintype.card G : k) β’ (Ο.sum_of_conjugates_equivariant G)
include h
lemma equivariant_projection_condition (v : V) : (Ο.equivariant_projection G) (i v) = v :=
begin
rw [equivariant_projection, smul_apply, sum_of_conjugates_equivariant,
equivariant_of_linear_of_comm_apply, sum_of_conjugates],
rw [linear_map.sum_apply],
simp only [conjugate_i Ο i h],
rw [finset.sum_const, finset.card_univ, nsmul_eq_smul_cast k,
βmul_smul, invertible.inv_of_mul_self, one_smul],
end
end
end linear_map
end
namespace monoid_algebra
-- Now we work over a `[field k]`, and replace the assumption `[invertible (fintype.card G : k)]`
-- with `Β¬(ring_char k β£ fintype.card G)`.
variables {k : Type u} [field k] {G : Type u} [fintype G] [group G]
variables {V : Type u} [add_comm_group V] [module k V] [module (monoid_algebra k G) V]
variables [is_scalar_tower k (monoid_algebra k G) V]
variables {W : Type u} [add_comm_group W] [module k W] [module (monoid_algebra k G) W]
variables [is_scalar_tower k (monoid_algebra k G) W]
lemma exists_left_inverse_of_injective
(not_dvd : Β¬(ring_char k β£ fintype.card G)) (f : V ββ[monoid_algebra k G] W) (hf : f.ker = β₯) :
β (g : W ββ[monoid_algebra k G] V), g.comp f = linear_map.id :=
begin
haveI : invertible (fintype.card G : k) :=
invertible_of_ring_char_not_dvd not_dvd,
obtain β¨Ο, hΟβ© := (f.restrict_scalars k).exists_left_inverse_of_injective
(by simp only [hf, submodule.restrict_scalars_bot, linear_map.ker_restrict_scalars]),
refine β¨Ο.equivariant_projection G, _β©,
ext v,
simp only [linear_map.id_coe, id.def, linear_map.comp_apply],
apply linear_map.equivariant_projection_condition,
intro v,
have := congr_arg linear_map.to_fun hΟ,
exact congr_fun this v
end
namespace submodule
lemma exists_is_compl
(not_dvd : Β¬(ring_char k β£ fintype.card G)) (p : submodule (monoid_algebra k G) V) :
β q : submodule (monoid_algebra k G) V, is_compl p q :=
let β¨f, hfβ© := monoid_algebra.exists_left_inverse_of_injective not_dvd p.subtype p.ker_subtype in
β¨f.ker, linear_map.is_compl_of_proj $ linear_map.ext_iff.1 hfβ©
theorem is_complemented (not_dvd : Β¬(ring_char k β£ fintype.card G)) :
is_complemented (submodule (monoid_algebra k G) V) := β¨exists_is_compl not_dvdβ©
end submodule
theorem is_semisimple_module (not_dvd : Β¬(ring_char k β£ fintype.card G)) :
is_semisimple_module (monoid_algebra k G) V :=
submodule.is_complemented not_dvd
end monoid_algebra
|
a0dfc1101aef7ffc958d90518019fcb171a83c0a | 57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d | /src/Lean/Meta/Basic.lean | 1f4cbf842523a70a328596feb7f4b86ae99df4ab | [
"Apache-2.0"
] | permissive | collares/lean4 | 861a9269c4592bce49b71059e232ff0bfe4594cc | 52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee | refs/heads/master | 1,691,419,031,324 | 1,618,678,138,000 | 1,618,678,138,000 | 358,989,750 | 0 | 0 | Apache-2.0 | 1,618,696,333,000 | 1,618,696,333,000 | null | UTF-8 | Lean | false | false | 46,736 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Data.LOption
import Lean.Environment
import Lean.Class
import Lean.ReducibilityAttrs
import Lean.Util.Trace
import Lean.Util.RecDepth
import Lean.Util.PPExt
import Lean.Util.OccursCheck
import Lean.Util.MonadBacktrack
import Lean.Compiler.InlineAttrs
import Lean.Meta.TransparencyMode
import Lean.Meta.DiscrTreeTypes
import Lean.Eval
import Lean.CoreM
/-
This module provides four (mutually dependent) goodies that are needed for building the elaborator and tactic frameworks.
1- Weak head normal form computation with support for metavariables and transparency modes.
2- Definitionally equality checking with support for metavariables (aka unification modulo definitional equality).
3- Type inference.
4- Type class resolution.
They are packed into the MetaM monad.
-/
namespace Lean.Meta
builtin_initialize isDefEqStuckExceptionId : InternalExceptionId β registerInternalExceptionId `isDefEqStuck
structure Config where
foApprox : Bool := false
ctxApprox : Bool := false
quasiPatternApprox : Bool := false
/- When `constApprox` is set to true,
we solve `?m t =?= c` using
`?m := fun _ => c`
when `?m t` is not a higher-order pattern and `c` is not an application as -/
constApprox : Bool := false
/-
When the following flag is set,
`isDefEq` throws the exeption `Exeption.isDefEqStuck`
whenever it encounters a constraint `?m ... =?= t` where
`?m` is read only.
This feature is useful for type class resolution where
we may want to notify the caller that the TC problem may be solveable
later after it assigns `?m`. -/
isDefEqStuckEx : Bool := false
transparency : TransparencyMode := TransparencyMode.default
/- If zetaNonDep == false, then non dependent let-decls are not zeta expanded. -/
zetaNonDep : Bool := true
/- When `trackZeta == true`, we store zetaFVarIds all free variables that have been zeta-expanded. -/
trackZeta : Bool := false
unificationHints : Bool := true
structure ParamInfo where
implicit : Bool := false
instImplicit : Bool := false
hasFwdDeps : Bool := false
backDeps : Array Nat := #[]
deriving Inhabited
def ParamInfo.isExplicit (p : ParamInfo) : Bool :=
!p.implicit && !p.instImplicit
structure FunInfo where
paramInfo : Array ParamInfo := #[]
resultDeps : Array Nat := #[]
structure InfoCacheKey where
transparency : TransparencyMode
expr : Expr
nargs? : Option Nat
deriving Inhabited, BEq
namespace InfoCacheKey
instance : Hashable InfoCacheKey :=
β¨fun β¨transparency, expr, nargsβ© => mixHash (hash transparency) <| mixHash (hash expr) (hash nargs)β©
end InfoCacheKey
open Std (PersistentArray PersistentHashMap)
abbrev SynthInstanceCache := PersistentHashMap Expr (Option Expr)
abbrev InferTypeCache := PersistentExprStructMap Expr
abbrev FunInfoCache := PersistentHashMap InfoCacheKey FunInfo
abbrev WhnfCache := PersistentExprStructMap Expr
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`
deriving Inhabited
/--
"Context" for a postponed universe constraint.
`lhs` and `rhs` are the surrounding `isDefEq` call when the postponed constraint was created.
-/
structure DefEqContext where
lhs : Expr
rhs : Expr
lctx : LocalContext
localInstances : LocalInstances
/--
Auxiliary structure for representing postponed universe constraints.
Remark: the fields `ref` and `rootDefEq?` are used for error message generation only.
Remark: we may consider improving the error message generation in the future.
-/
structure PostponedEntry where
ref : Syntax -- We save the `ref` at entry creation time
lhs : Level
rhs : Level
ctx? : Option DefEqContext -- Context for the surrounding `isDefEq` call when entry was created
deriving Inhabited
structure State where
mctx : MetavarContext := {}
cache : Cache := {}
/- When `trackZeta == true`, then any let-decl free variable that is zeta expansion performed by `MetaM` is stored in `zetaFVarIds`. -/
zetaFVarIds : NameSet := {}
postponed : PersistentArray PostponedEntry := {}
deriving Inhabited
structure SavedState where
core : Core.State
meta : State
deriving Inhabited
structure Context where
config : Config := {}
lctx : LocalContext := {}
localInstances : LocalInstances := #[]
/-- Not `none` when inside of an `isDefEq` test. See `PostponedEntry`. -/
defEqCtx? : Option DefEqContext := none
abbrev MetaM := ReaderT Context $ StateRefT State CoreM
instance : Inhabited (MetaM Ξ±) where
default := fun _ _ => arbitrary
instance : MonadLCtx MetaM where
getLCtx := return (β read).lctx
instance : MonadMCtx MetaM where
getMCtx := return (β get).mctx
modifyMCtx f := modify fun s => { s with mctx := f s.mctx }
instance : AddMessageContext MetaM where
addMessageContext := addMessageContextFull
protected def saveState : MetaM SavedState :=
return { core := (β getThe Core.State), meta := (β get) }
/-- Restore backtrackable parts of the state. -/
def SavedState.restore (b : SavedState) : MetaM Unit := do
Core.restore b.core
modify fun s => { s with mctx := b.meta.mctx, zetaFVarIds := b.meta.zetaFVarIds, postponed := b.meta.postponed }
instance : MonadBacktrack SavedState MetaM where
saveState := Meta.saveState
restoreState s := s.restore
@[inline] def MetaM.run (x : MetaM Ξ±) (ctx : Context := {}) (s : State := {}) : CoreM (Ξ± Γ State) :=
x ctx |>.run s
@[inline] def MetaM.run' (x : MetaM Ξ±) (ctx : Context := {}) (s : State := {}) : CoreM Ξ± :=
Prod.fst <$> x.run ctx s
@[inline] def MetaM.toIO (x : MetaM Ξ±) (ctxCore : Core.Context) (sCore : Core.State) (ctx : Context := {}) (s : State := {}) : IO (Ξ± Γ Core.State Γ State) := do
let ((a, s), sCore) β (x.run ctx s).toIO ctxCore sCore
pure (a, sCore, s)
instance [MetaEval Ξ±] : MetaEval (MetaM Ξ±) :=
β¨fun env opts x _ => MetaEval.eval env opts x.run' trueβ©
protected def throwIsDefEqStuck : MetaM Ξ± :=
throw <| Exception.internal isDefEqStuckExceptionId
builtin_initialize
registerTraceClass `Meta
registerTraceClass `Meta.debug
@[inline] def liftMetaM [MonadLiftT MetaM m] (x : MetaM Ξ±) : m Ξ± :=
liftM x
@[inline] def mapMetaM [MonadControlT MetaM m] [Monad m] (f : forall {Ξ±}, MetaM Ξ± β MetaM Ξ±) {Ξ±} (x : m Ξ±) : m Ξ± :=
controlAt MetaM fun runInBase => f <| runInBase x
@[inline] def map1MetaM [MonadControlT MetaM m] [Monad m] (f : forall {Ξ±}, (Ξ² β MetaM Ξ±) β MetaM Ξ±) {Ξ±} (k : Ξ² β m Ξ±) : m Ξ± :=
controlAt MetaM fun runInBase => f fun b => runInBase <| k b
@[inline] def map2MetaM [MonadControlT MetaM m] [Monad m] (f : forall {Ξ±}, (Ξ² β Ξ³ β MetaM Ξ±) β MetaM Ξ±) {Ξ±} (k : Ξ² β Ξ³ β m Ξ±) : m Ξ± :=
controlAt MetaM fun runInBase => f fun b c => runInBase <| k b c
section Methods
variable [MonadControlT MetaM n] [Monad n]
@[inline] def modifyCache (f : Cache β Cache) : MetaM Unit :=
modify fun β¨mctx, cache, zetaFVarIds, postponedβ© => β¨mctx, f cache, zetaFVarIds, postponedβ©
@[inline] def modifyInferTypeCache (f : InferTypeCache β InferTypeCache) : MetaM Unit :=
modifyCache fun β¨ic, c1, c2, c3, c4β© => β¨f ic, c1, c2, c3, c4β©
def getLocalInstances : MetaM LocalInstances :=
return (β read).localInstances
def getConfig : MetaM Config :=
return (β read).config
def setMCtx (mctx : MetavarContext) : MetaM Unit :=
modify fun s => { s with mctx := mctx }
def resetZetaFVarIds : MetaM Unit :=
modify fun s => { s with zetaFVarIds := {} }
def getZetaFVarIds : MetaM NameSet :=
return (β get).zetaFVarIds
def getPostponed : MetaM (PersistentArray PostponedEntry) :=
return (β get).postponed
def setPostponed (postponed : PersistentArray PostponedEntry) : MetaM Unit :=
modify fun s => { s with postponed := postponed }
@[inline] def modifyPostponed (f : PersistentArray PostponedEntry β PersistentArray PostponedEntry) : MetaM Unit :=
modify fun s => { s with postponed := f s.postponed }
builtin_initialize whnfRef : IO.Ref (Expr β MetaM Expr) β IO.mkRef fun _ => throwError "whnf implementation was not set"
builtin_initialize inferTypeRef : IO.Ref (Expr β MetaM Expr) β IO.mkRef fun _ => throwError "inferType implementation was not set"
builtin_initialize isExprDefEqAuxRef : IO.Ref (Expr β Expr β MetaM Bool) β IO.mkRef fun _ _ => throwError "isDefEq implementation was not set"
builtin_initialize synthPendingRef : IO.Ref (MVarId β MetaM Bool) β IO.mkRef fun _ => pure false
def whnf (e : Expr) : MetaM Expr :=
withIncRecDepth do (β whnfRef.get) e
def whnfForall (e : Expr) : MetaM Expr := do
let e' β whnf e
if e'.isForall then pure e' else pure e
def inferType (e : Expr) : MetaM Expr :=
withIncRecDepth do (β inferTypeRef.get) e
protected def isExprDefEqAux (t s : Expr) : MetaM Bool :=
withIncRecDepth do (β isExprDefEqAuxRef.get) t s
protected def synthPending (mvarId : MVarId) : MetaM Bool :=
withIncRecDepth do (β synthPendingRef.get) mvarId
-- 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
let mvarId β mkFreshId
mkFreshExprMVarAtCore mvarId lctx localInsts type kind userName numScopeArgs
def mkFreshLevelMVar : MetaM Level := do
let mvarId β mkFreshId
modifyMCtx fun mctx => mctx.addLevelMVarDecl mvarId;
return mkLevelMVar mvarId
private def mkFreshExprMVarCore (type : Expr) (kind : MetavarKind) (userName : Name) : MetaM Expr := do
let lctx β getLCtx
let localInsts β getLocalInstances
mkFreshExprMVarAt lctx localInsts 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
let lctx β getLCtx
let localInsts β getLocalInstances
mkFreshExprMVarAtCore mvarId lctx localInsts type kind userName numScopeArgs
def mkFreshExprMVarWithId (mvarId : MVarId) (type? : Option Expr := none) (kind : MetavarKind := MetavarKind.natural) (userName := Name.anonymous) : MetaM Expr :=
match type? with
| some type => mkFreshExprMVarWithIdCore mvarId type kind userName
| none => do
let u β mkFreshLevelMVar
let type β mkFreshExprMVar (mkSort u)
mkFreshExprMVarWithIdCore mvarId type kind userName
def mkFreshLevelMVars (num : Nat) : MetaM (List Level) :=
num.foldM (init := []) fun _ us =>
return (β mkFreshLevelMVar)::us
def mkFreshLevelMVarsFor (info : ConstantInfo) : MetaM (List Level) :=
mkFreshLevelMVars info.numLevelParams
def mkConstWithFreshMVarLevels (declName : Name) : MetaM Expr := do
let info β getConstInfo declName
return mkConst declName (β mkFreshLevelMVarsFor info)
def getTransparency : MetaM TransparencyMode :=
return (β getConfig).transparency
def shouldReduceAll : MetaM Bool :=
return (β getTransparency) == TransparencyMode.all
def shouldReduceReducibleOnly : MetaM Bool :=
return (β getTransparency) == TransparencyMode.reducible
def getMVarDecl (mvarId : MVarId) : MetaM MetavarDecl := do
let mctx β getMCtx
match mctx.findDecl? mvarId with
| some d => pure d
| none => throwError "unknown metavariable '?{mvarId}'"
def setMVarKind (mvarId : MVarId) (kind : MetavarKind) : MetaM Unit :=
modifyMCtx fun mctx => mctx.setMVarKind mvarId kind
/- Update the type of the given metavariable. This function assumes the new type is
definitionally equal to the current one -/
def setMVarType (mvarId : MVarId) (type : Expr) : MetaM Unit := do
modifyMCtx fun mctx => mctx.setMVarType mvarId type
def isReadOnlyExprMVar (mvarId : MVarId) : MetaM Bool := do
let mvarDecl β getMVarDecl mvarId
let mctx β getMCtx
return mvarDecl.depth != mctx.depth
def isReadOnlyOrSyntheticOpaqueExprMVar (mvarId : MVarId) : MetaM Bool := do
let mvarDecl β getMVarDecl mvarId
match mvarDecl.kind with
| MetavarKind.syntheticOpaque => pure true
| _ =>
let mctx β getMCtx
return mvarDecl.depth != mctx.depth
def isReadOnlyLevelMVar (mvarId : MVarId) : MetaM Bool := do
let mctx β getMCtx
match mctx.findLevelDepth? mvarId with
| some depth => return depth != mctx.depth
| _ => throwError "unknown universe metavariable '?{mvarId}'"
def renameMVar (mvarId : MVarId) (newUserName : Name) : MetaM Unit :=
modifyMCtx fun mctx => mctx.renameMVar mvarId newUserName
def isExprMVarAssigned (mvarId : MVarId) : MetaM Bool :=
return (β getMCtx).isExprAssigned mvarId
def getExprMVarAssignment? (mvarId : MVarId) : MetaM (Option Expr) :=
return (β getMCtx).getExprAssignment? mvarId
/-- Return true if `e` contains `mvarId` directly or indirectly -/
def occursCheck (mvarId : MVarId) (e : Expr) : MetaM Bool :=
return (β getMCtx).occursCheck mvarId e
def assignExprMVar (mvarId : MVarId) (val : Expr) : MetaM Unit :=
modifyMCtx fun mctx => mctx.assignExpr mvarId val
def isDelayedAssigned (mvarId : MVarId) : MetaM Bool :=
return (β getMCtx).isDelayedAssigned mvarId
def getDelayedAssignment? (mvarId : MVarId) : MetaM (Option DelayedMetavarAssignment) :=
return (β getMCtx).getDelayedAssignment? mvarId
def hasAssignableMVar (e : Expr) : MetaM Bool :=
return (β getMCtx).hasAssignableMVar e
def throwUnknownFVar (fvarId : FVarId) : MetaM Ξ± :=
throwError "unknown free variable '{mkFVar fvarId}'"
def findLocalDecl? (fvarId : FVarId) : MetaM (Option LocalDecl) :=
return (β getLCtx).find? fvarId
def getLocalDecl (fvarId : FVarId) : MetaM LocalDecl := do
match (β getLCtx).find? fvarId with
| some d => pure d
| none => throwUnknownFVar fvarId
def getFVarLocalDecl (fvar : Expr) : MetaM LocalDecl :=
getLocalDecl fvar.fvarId!
def getLocalDeclFromUserName (userName : Name) : MetaM LocalDecl := do
match (β getLCtx).findFromUserName? userName with
| some d => pure d
| none => throwError "unknown local declaration '{userName}'"
def instantiateLevelMVars (u : Level) : MetaM Level :=
MetavarContext.instantiateLevelMVars u
def instantiateMVars (e : Expr) : MetaM Expr :=
(MetavarContext.instantiateExprMVars e).run
def instantiateLocalDeclMVars (localDecl : LocalDecl) : MetaM LocalDecl := do
match localDecl with
| LocalDecl.cdecl idx id n type bi =>
let type β instantiateMVars type
return LocalDecl.cdecl idx id n type bi
| LocalDecl.ldecl idx id n type val nonDep =>
let type β instantiateMVars type
let val β instantiateMVars val
return LocalDecl.ldecl idx id n type val nonDep
@[inline] def liftMkBindingM (x : MetavarContext.MkBindingM Ξ±) : MetaM Ξ± := do
match x (β getLCtx) { mctx := (β getMCtx), ngen := (β getNGen) } with
| EStateM.Result.ok e newS => do
setNGen newS.ngen;
setMCtx newS.mctx;
pure e
| EStateM.Result.error (MetavarContext.MkBinding.Exception.revertFailure mctx lctx toRevert decl) newS => do
setMCtx newS.mctx;
setNGen newS.ngen;
throwError "failed to create binder due to failure when reverting variable dependencies"
def mkForallFVars (xs : Array Expr) (e : Expr) (usedOnly : Bool := false) (usedLetOnly : Bool := true) : MetaM Expr :=
if xs.isEmpty then pure e else liftMkBindingM <| MetavarContext.mkForall xs e usedOnly usedLetOnly
def mkLambdaFVars (xs : Array Expr) (e : Expr) (usedOnly : Bool := false) (usedLetOnly : Bool := true) : MetaM Expr :=
if xs.isEmpty then pure e else liftMkBindingM <| MetavarContext.mkLambda xs e usedOnly usedLetOnly
def mkLetFVars (xs : Array Expr) (e : Expr) : MetaM Expr :=
mkLambdaFVars xs e
def mkArrow (d b : Expr) : MetaM Expr := do
let n β mkFreshUserName `x
return Lean.mkForall n BinderInfo.default d b
def elimMVarDeps (xs : Array Expr) (e : Expr) (preserveOrder : Bool := false) : MetaM Expr :=
if xs.isEmpty then pure e else liftMkBindingM <| MetavarContext.elimMVarDeps xs e preserveOrder
@[inline] def withConfig (f : Config β Config) : n Ξ± β n Ξ± :=
mapMetaM <| withReader (fun ctx => { ctx with config := f ctx.config })
@[inline] def withTrackingZeta (x : n Ξ±) : n Ξ± :=
withConfig (fun cfg => { cfg with trackZeta := true }) x
@[inline] def withTransparency (mode : TransparencyMode) : n Ξ± β n Ξ± :=
mapMetaM <| withConfig (fun config => { config with transparency := mode })
@[inline] def withDefault (x : n Ξ±) : n Ξ± :=
withTransparency TransparencyMode.default x
@[inline] def withReducible (x : n Ξ±) : n Ξ± :=
withTransparency TransparencyMode.reducible x
@[inline] def withReducibleAndInstances (x : n Ξ±) : n Ξ± :=
withTransparency TransparencyMode.instances x
@[inline] def withAtLeastTransparency (mode : TransparencyMode) (x : n Ξ±) : n Ξ± :=
withConfig
(fun config =>
let oldMode := config.transparency
let mode := if oldMode.lt mode then mode else oldMode
{ config with transparency := mode })
x
/-- Save cache, execute `x`, restore cache -/
@[inline] private def savingCacheImpl (x : MetaM Ξ±) : MetaM Ξ± := do
let s β get
let savedCache := s.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
let env β getEnv
match env.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
let env β getEnv
if isClass env constName then
pure (LOption.some constName)
else
match (β getConstTemp? constName) with
| some _ => pure LOption.undef
| none => pure LOption.none
private partial def isClassQuick? : Expr β MetaM (LOption Name)
| Expr.bvar .. => pure LOption.none
| Expr.lit .. => pure LOption.none
| Expr.fvar .. => pure LOption.none
| Expr.sort .. => pure LOption.none
| Expr.lam .. => pure LOption.none
| Expr.letE .. => pure LOption.undef
| Expr.proj .. => pure LOption.undef
| Expr.forallE _ _ b _ => isClassQuick? b
| Expr.mdata _ e _ => isClassQuick? e
| Expr.const n _ _ => isClassQuickConst? n
| Expr.mvar mvarId _ => do
match (β getExprMVarAssignment? mvarId) with
| some val => isClassQuick? val
| none => pure LOption.none
| Expr.app f _ _ =>
match f.getAppFn with
| Expr.const n .. => isClassQuickConst? n
| Expr.lam .. => pure LOption.undef
| _ => pure LOption.none
def saveAndResetSynthInstanceCache : MetaM SynthInstanceCache := do
let s β get
let savedSythInstance := s.cache.synthInstance
modifyCache fun c => { c with synthInstance := {} }
pure savedSythInstance
def restoreSynthInstanceCache (cache : SynthInstanceCache) : MetaM Unit :=
modifyCache fun c => { c with synthInstance := cache }
@[inline] private def resettingSynthInstanceCacheImpl (x : MetaM Ξ±) : MetaM Ξ± := do
let savedSythInstance β saveAndResetSynthInstanceCache
try x finally restoreSynthInstanceCache savedSythInstance
/-- Reset `synthInstance` cache, execute `x`, and restore cache -/
@[inline] def resettingSynthInstanceCache : n Ξ± β n Ξ± :=
mapMetaM resettingSynthInstanceCacheImpl
@[inline] def resettingSynthInstanceCacheWhen (b : Bool) (x : n Ξ±) : n Ξ± :=
if b then resettingSynthInstanceCache x else x
private def withNewLocalInstanceImp (className : Name) (fvar : Expr) (k : MetaM Ξ±) : MetaM Ξ± := do
let localDecl β getFVarLocalDecl fvar
/- Recall that we use `auxDecl` binderInfo when compiling recursive declarations. -/
match localDecl.binderInfo with
| BinderInfo.auxDecl => k
| _ =>
resettingSynthInstanceCache <|
withReader
(fun ctx => { ctx with localInstances := ctx.localInstances.push { className := className, fvar := fvar } })
k
/-- Add entry `{ className := className, fvar := fvar }` to localInstances,
and then execute continuation `k`.
It resets the type class cache using `resettingSynthInstanceCache`. -/
def withNewLocalInstance (className : Name) (fvar : Expr) : n Ξ± β n Ξ± :=
mapMetaM <| withNewLocalInstanceImp className fvar
private def fvarsSizeLtMaxFVars (fvars : Array Expr) (maxFVars? : Option Nat) : Bool :=
match maxFVars? with
| some maxFVars => fvars.size < maxFVars
| none => true
mutual
/--
`withNewLocalInstances isClassExpensive fvars j k` updates the vector or local instances
using free variables `fvars[j] ... fvars.back`, and execute `k`.
- `isClassExpensive` is defined later.
- The type class chache is reset whenever a new local instance is found.
- `isClassExpensive` uses `whnf` which depends (indirectly) on the set of local instances.
Thus, each new local instance requires a new `resettingSynthInstanceCache`. -/
private partial def withNewLocalInstancesImp
(fvars : Array Expr) (i : Nat) (k : MetaM Ξ±) : MetaM Ξ± := do
if h : i < fvars.size then
let fvar := fvars.get β¨i, hβ©
let decl β getFVarLocalDecl fvar
match (β isClassQuick? decl.type) with
| LOption.none => withNewLocalInstancesImp fvars (i+1) k
| LOption.undef =>
match (β isClassExpensive? decl.type) with
| none => withNewLocalInstancesImp fvars (i+1) k
| some c => withNewLocalInstance c fvar <| withNewLocalInstancesImp fvars (i+1) k
| LOption.some c => withNewLocalInstance c fvar <| withNewLocalInstancesImp fvars (i+1) k
else
k
/--
`forallTelescopeAuxAux lctx fvars j type`
Remarks:
- `lctx` is the `MetaM` local context extended with declarations for `fvars`.
- `type` is the type we are computing the telescope for. It contains only
dangling bound variables in the range `[j, fvars.size)`
- if `reducing? == true` and `type` is not `forallE`, we use `whnf`.
- when `type` is not a `forallE` nor it can't be reduced to one, we
excute the continuation `k`.
Here is an example that demonstrates the `reducing?`.
Suppose we have
```
abbrev StateM s a := s -> Prod a s
```
Now, assume we are trying to build the telescope for
```
forall (x : Nat), StateM Int Bool
```
if `reducing == true`, the function executes `k #[(x : Nat) (s : Int)] Bool`.
if `reducing == false`, the function executes `k #[(x : Nat)] (StateM Int Bool)`
if `maxFVars?` is `some max`, then we interrupt the telescope construction
when `fvars.size == max`
-/
private partial def forallTelescopeReducingAuxAux
(reducing : Bool) (maxFVars? : Option Nat)
(type : Expr)
(k : Array Expr β Expr β MetaM Ξ±) : MetaM Ξ± := do
let rec process (lctx : LocalContext) (fvars : Array Expr) (j : Nat) (type : Expr) : MetaM Ξ± := do
match type with
| Expr.forallE n d b c =>
if fvarsSizeLtMaxFVars fvars maxFVars? then
let d := d.instantiateRevRange j fvars.size fvars
let fvarId β mkFreshId
let lctx := lctx.mkLocalDecl fvarId n d c.binderInfo
let fvar := mkFVar fvarId
let fvars := fvars.push fvar
process lctx fvars j b
else
let type := type.instantiateRevRange j fvars.size fvars;
withReader (fun ctx => { ctx with lctx := lctx }) do
withNewLocalInstancesImp fvars j do
k fvars type
| _ =>
let type := type.instantiateRevRange j fvars.size fvars;
withReader (fun ctx => { ctx with lctx := lctx }) do
withNewLocalInstancesImp fvars j do
if reducing && fvarsSizeLtMaxFVars fvars maxFVars? then
let newType β whnf type
if newType.isForall then
process lctx fvars fvars.size newType
else
k fvars type
else
k fvars type
process (β getLCtx) #[] 0 type
private partial def forallTelescopeReducingAux (type : Expr) (maxFVars? : Option Nat) (k : Array Expr β Expr β MetaM Ξ±) : MetaM Ξ± := do
match maxFVars? with
| some 0 => k #[] type
| _ => do
let newType β whnf type
if newType.isForall then
forallTelescopeReducingAuxAux true maxFVars? newType k
else
k #[] type
private partial def isClassExpensive? : Expr β MetaM (Option Name)
| type => withReducible <| -- when testing whether a type is a type class, we only unfold reducible constants.
forallTelescopeReducingAux type none fun xs type => do
let env β getEnv
match type.getAppFn with
| Expr.const c _ _ => do
if isClass env c then
return some c
else
-- make sure abbreviations are unfolded
match (β whnf type).getAppFn with
| Expr.const c _ _ => return if isClass env c then some c else none
| _ => return none
| _ => return none
private partial def isClassImp? (type : Expr) : MetaM (Option Name) := do
match (β isClassQuick? type) with
| LOption.none => pure none
| LOption.some c => pure (some c)
| LOption.undef => isClassExpensive? type
end
def isClass? (type : Expr) : MetaM (Option Name) :=
try isClassImp? type catch _ => pure none
private def withNewLocalInstancesImpAux (fvars : Array Expr) (j : Nat) : n Ξ± β n Ξ± :=
mapMetaM <| withNewLocalInstancesImp fvars j
partial def withNewLocalInstances (fvars : Array Expr) (j : Nat) : n Ξ± β n Ξ± :=
mapMetaM <| withNewLocalInstancesImpAux fvars j
@[inline] private def forallTelescopeImp (type : Expr) (k : Array Expr β Expr β MetaM Ξ±) : MetaM Ξ± := do
forallTelescopeReducingAuxAux (reducing := false) (maxFVars? := none) type k
/--
Given `type` of the form `forall xs, A`, execute `k xs A`.
This combinator will declare local declarations, create free variables for them,
execute `k` with updated local context, and make sure the cache is restored after executing `k`. -/
def forallTelescope (type : Expr) (k : Array Expr β Expr β n Ξ±) : n Ξ± :=
map2MetaM (fun k => forallTelescopeImp type k) k
private def forallTelescopeReducingImp (type : Expr) (k : Array Expr β Expr β MetaM Ξ±) : MetaM Ξ± :=
forallTelescopeReducingAux type (maxFVars? := none) k
/--
Similar to `forallTelescope`, but given `type` of the form `forall xs, A`,
it reduces `A` and continues bulding the telescope if it is a `forall`. -/
def forallTelescopeReducing (type : Expr) (k : Array Expr β Expr β n Ξ±) : n Ξ± :=
map2MetaM (fun k => forallTelescopeReducingImp type k) k
private def forallBoundedTelescopeImp (type : Expr) (maxFVars? : Option Nat) (k : Array Expr β Expr β MetaM Ξ±) : MetaM Ξ± :=
forallTelescopeReducingAux type maxFVars? k
/--
Similar to `forallTelescopeReducing`, stops constructing the telescope when
it reaches size `maxFVars`. -/
def forallBoundedTelescope (type : Expr) (maxFVars? : Option Nat) (k : Array Expr β Expr β n Ξ±) : n Ξ± :=
map2MetaM (fun k => forallBoundedTelescopeImp type maxFVars? k) k
/-- Similar to `forallTelescopeAuxAux` but for lambda and let expressions. -/
private partial def lambdaTelescopeAux
(k : Array Expr β Expr β MetaM Ξ±)
: Bool β LocalContext β Array Expr β Nat β Expr β MetaM Ξ±
| consumeLet, lctx, fvars, j, Expr.lam n d b c => do
let d := d.instantiateRevRange j fvars.size fvars
let fvarId β mkFreshId
let lctx := lctx.mkLocalDecl fvarId n d c.binderInfo
let fvar := mkFVar fvarId
lambdaTelescopeAux k consumeLet lctx (fvars.push fvar) j b
| true, lctx, fvars, j, Expr.letE n t v b _ => do
let t := t.instantiateRevRange j fvars.size fvars
let v := v.instantiateRevRange j fvars.size fvars
let fvarId β mkFreshId
let lctx := lctx.mkLetDecl fvarId n t v
let fvar := mkFVar fvarId
lambdaTelescopeAux k true lctx (fvars.push fvar) j b
| _, lctx, fvars, j, e =>
let e := e.instantiateRevRange j fvars.size fvars;
withReader (fun ctx => { ctx with lctx := lctx }) do
withNewLocalInstancesImp fvars j do
k fvars e
private partial def lambdaTelescopeImp (e : Expr) (consumeLet : Bool) (k : Array Expr β Expr β MetaM Ξ±) : MetaM Ξ± := do
let rec process (consumeLet : Bool) (lctx : LocalContext) (fvars : Array Expr) (j : Nat) (e : Expr) : MetaM Ξ± := do
match consumeLet, e with
| _, Expr.lam n d b c =>
let d := d.instantiateRevRange j fvars.size fvars
let fvarId β mkFreshId
let lctx := lctx.mkLocalDecl fvarId n d c.binderInfo
let fvar := mkFVar fvarId
process consumeLet lctx (fvars.push fvar) j b
| true, Expr.letE n t v b _ => do
let t := t.instantiateRevRange j fvars.size fvars
let v := v.instantiateRevRange j fvars.size fvars
let fvarId β mkFreshId
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
process consumeLet (β getLCtx) #[] 0 e
/-- Similar to `forallTelescope` but for lambda and let expressions. -/
def lambdaLetTelescope (type : Expr) (k : Array Expr β Expr β n Ξ±) : n Ξ± :=
map2MetaM (fun k => lambdaTelescopeImp type true k) k
/-- Similar to `forallTelescope` but for lambda expressions. -/
def lambdaTelescope (type : Expr) (k : Array Expr β Expr β n Ξ±) : n Ξ± :=
map2MetaM (fun k => lambdaTelescopeImp type false k) k
/-- Return the parameter names for the givel global declaration. -/
def getParamNames (declName : Name) : MetaM (Array Name) := do
let cinfo β getConstInfo declName
forallTelescopeReducing cinfo.type fun xs _ => do
xs.mapM fun x => do
let localDecl β getLocalDecl x.fvarId!
pure localDecl.userName
-- `kind` specifies the metavariable kind for metavariables not corresponding to instance implicit `[ ... ]` arguments.
private partial def forallMetaTelescopeReducingAux
(e : Expr) (reducing : Bool) (maxMVars? : Option Nat) (kind : MetavarKind) : MetaM (Array Expr Γ Array BinderInfo Γ Expr) :=
let rec process (mvars : Array Expr) (bis : Array BinderInfo) (j : Nat) (type : Expr) : MetaM (Array Expr Γ Array BinderInfo Γ Expr) := do
match type with
| Expr.forallE n d b c =>
let cont : Unit β MetaM (Array Expr Γ Array BinderInfo Γ Expr) := fun _ => do
let d := d.instantiateRevRange j mvars.size mvars
let k := if c.binderInfo.isInstImplicit then MetavarKind.synthetic else kind
let mvar β mkFreshExprMVar d k n
let mvars := mvars.push mvar
let bis := bis.push c.binderInfo
process mvars bis j b
match maxMVars? with
| none => cont ()
| some maxMVars =>
if mvars.size < maxMVars then
cont ()
else
let type := type.instantiateRevRange j mvars.size mvars;
pure (mvars, bis, type)
| _ =>
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
pure (mvars, bis, type)
else
pure (mvars, bis, type)
process #[] #[] 0 e
/-- Similar to `forallTelescope`, but creates metavariables instead of free variables. -/
def forallMetaTelescope (e : Expr) (kind := MetavarKind.natural) : MetaM (Array Expr Γ Array BinderInfo Γ Expr) :=
forallMetaTelescopeReducingAux e (reducing := false) (maxMVars? := none) kind
/-- Similar to `forallTelescopeReducing`, but creates metavariables instead of free variables. -/
def forallMetaTelescopeReducing (e : Expr) (maxMVars? : Option Nat := none) (kind := MetavarKind.natural) : MetaM (Array Expr Γ Array BinderInfo Γ Expr) :=
forallMetaTelescopeReducingAux e (reducing := true) maxMVars? kind
/-- Similar to `forallMetaTelescopeReducingAux` but for lambda expressions. -/
partial def lambdaMetaTelescope (e : Expr) (maxMVars? : Option Nat := none) : MetaM (Array Expr Γ Array BinderInfo Γ Expr) :=
let rec process (mvars : Array Expr) (bis : Array BinderInfo) (j : Nat) (type : Expr) : MetaM (Array Expr Γ Array BinderInfo Γ Expr) := do
let finalize : Unit β MetaM (Array Expr Γ Array BinderInfo Γ Expr) := fun _ => do
let type := type.instantiateRevRange j mvars.size mvars
pure (mvars, bis, type)
let cont : Unit β MetaM (Array Expr Γ Array BinderInfo Γ Expr) := fun _ => do
match type with
| Expr.lam n d b c =>
let d := d.instantiateRevRange j mvars.size mvars
let mvar β mkFreshExprMVar d
let mvars := mvars.push mvar
let bis := bis.push c.binderInfo
process mvars bis j b
| _ => finalize ()
match maxMVars? with
| none => cont ()
| some maxMVars =>
if mvars.size < maxMVars then
cont ()
else
finalize ()
process #[] #[] 0 e
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 β mkFreshId
let ctx β read
let lctx := ctx.lctx.mkLocalDecl fvarId n type bi
let fvar := mkFVar fvarId
withReader (fun ctx => { ctx with lctx := lctx }) do
withNewFVar fvar type k
def withLocalDecl (name : Name) (bi : BinderInfo) (type : Expr) (k : Expr β n Ξ±) : n Ξ± :=
map1MetaM (fun k => withLocalDeclImp name bi type k) k
def withLocalDeclD (name : Name) (type : Expr) (k : Expr β n Ξ±) : n Ξ± :=
withLocalDecl name BinderInfo.default type k
partial def withLocalDecls
[Inhabited Ξ±]
(declInfos : Array (Name Γ BinderInfo Γ (Array Expr β n Expr)))
(k : (xs : Array Expr) β n Ξ±)
: n Ξ± :=
let rec 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
loop #[]
def withLocalDeclsD
[Inhabited Ξ±]
(declInfos : Array (Name Γ (Array Expr β n Expr)))
(k : (xs : Array Expr) β n Ξ±)
: n Ξ± :=
withLocalDecls
(declInfos.map (fun (name, typeCtor) => (name, BinderInfo.default, typeCtor))) k
private def withNewBinderInfosImp (bs : Array (FVarId Γ BinderInfo)) (k : MetaM Ξ±) : MetaM Ξ± := do
let lctx := bs.foldl (init := (β getLCtx)) fun lctx (fvarId, bi) =>
lctx.setBinderInfo fvarId bi
withReader (fun ctx => { ctx with lctx := lctx }) k
def withNewBinderInfos (bs : Array (FVarId Γ BinderInfo)) (k : n Ξ±) : n Ξ± :=
mapMetaM (fun k => withNewBinderInfosImp bs k) k
private def withLetDeclImp (n : Name) (type : Expr) (val : Expr) (k : Expr β MetaM Ξ±) : MetaM Ξ± := do
let fvarId β mkFreshId
let ctx β read
let lctx := ctx.lctx.mkLetDecl fvarId n type val
let fvar := mkFVar fvarId
withReader (fun ctx => { ctx with lctx := lctx }) do
withNewFVar fvar type k
def withLetDecl (name : Name) (type : Expr) (val : Expr) (k : Expr β n Ξ±) : n Ξ± :=
map1MetaM (fun k => withLetDeclImp name type val k) k
private def withExistingLocalDeclsImp (decls : List LocalDecl) (k : MetaM Ξ±) : MetaM Ξ± := do
let ctx β read
let numLocalInstances := ctx.localInstances.size
let lctx := decls.foldl (fun (lctx : LocalContext) decl => lctx.addDecl decl) ctx.lctx
withReader (fun ctx => { ctx with lctx := lctx }) do
let newLocalInsts β decls.foldlM
(fun (newlocalInsts : Array LocalInstance) (decl : LocalDecl) => (do {
match (β isClass? decl.type) with
| none => pure newlocalInsts
| some c => pure <| newlocalInsts.push { className := c, fvar := decl.toExpr } } : MetaM _))
ctx.localInstances;
if newLocalInsts.size == numLocalInstances then
k
else
resettingSynthInstanceCache <| withReader (fun ctx => { ctx with localInstances := newLocalInsts }) k
def withExistingLocalDecls (decls : List LocalDecl) : n Ξ± β n Ξ± :=
mapMetaM <| withExistingLocalDeclsImp decls
private def withNewMCtxDepthImp (x : MetaM Ξ±) : MetaM Ξ± := do
let s β get
let savedMCtx := s.mctx
modifyMCtx fun mctx => mctx.incDepth
try x finally setMCtx savedMCtx
/--
Save cache and `MetavarContext`, bump the `MetavarContext` depth, execute `x`,
and restore saved data. -/
def withNewMCtxDepth : n Ξ± β n Ξ± :=
mapMetaM withNewMCtxDepthImp
private def withLocalContextImp (lctx : LocalContext) (localInsts : LocalInstances) (x : MetaM Ξ±) : MetaM Ξ± := do
let localInstsCurr β getLocalInstances
withReader (fun ctx => { ctx with lctx := lctx, localInstances := localInsts }) do
if localInsts == localInstsCurr then
x
else
resettingSynthInstanceCache x
def withLCtx (lctx : LocalContext) (localInsts : LocalInstances) : n Ξ± β n Ξ± :=
mapMetaM <| withLocalContextImp lctx localInsts
private def withMVarContextImp (mvarId : MVarId) (x : MetaM Ξ±) : MetaM Ξ± := do
let mvarDecl β getMVarDecl mvarId
withLocalContextImp mvarDecl.lctx mvarDecl.localInstances x
/--
Execute `x` using the given metavariable `LocalContext` and `LocalInstances`.
The type class resolution cache is flushed when executing `x` if its `LocalInstances` are
different from the current ones. -/
def withMVarContext (mvarId : MVarId) : n Ξ± β n Ξ± :=
mapMetaM <| withMVarContextImp mvarId
private def withMCtxImp (mctx : MetavarContext) (x : MetaM Ξ±) : MetaM Ξ± := do
let mctx' β getMCtx
setMCtx mctx
try x finally setMCtx mctx'
def withMCtx (mctx : MetavarContext) : n Ξ± β n Ξ± :=
mapMetaM <| withMCtxImp mctx
@[inline] private def approxDefEqImp (x : MetaM Ξ±) : MetaM Ξ± :=
withConfig (fun config => { config with foApprox := true, ctxApprox := true, quasiPatternApprox := true}) x
/-- Execute `x` using approximate unification: `foApprox`, `ctxApprox` and `quasiPatternApprox`. -/
@[inline] def approxDefEq : n Ξ± β n Ξ± :=
mapMetaM approxDefEqImp
@[inline] private def fullApproxDefEqImp (x : MetaM Ξ±) : MetaM Ξ± :=
withConfig (fun config => { config with foApprox := true, ctxApprox := true, quasiPatternApprox := true, constApprox := true }) x
/--
Similar to `approxDefEq`, but uses all available approximations.
We don't use `constApprox` by default at `approxDefEq` because it often produces undesirable solution for monadic code.
For example, suppose we have `pure (x > 0)` which has type `?m Prop`. We also have the goal `[Pure ?m]`.
Now, assume the expected type is `IO Bool`. Then, the unification constraint `?m Prop =?= IO Bool` could be solved
as `?m := fun _ => IO Bool` using `constApprox`, but this spurious solution would generate a failure when we try to
solve `[Pure (fun _ => IO Bool)]` -/
@[inline] def fullApproxDefEq : n Ξ± β n Ξ± :=
mapMetaM fullApproxDefEqImp
def normalizeLevel (u : Level) : MetaM Level := do
let u β instantiateLevelMVars u
pure u.normalize
def assignLevelMVar (mvarId : MVarId) (u : Level) : MetaM Unit := do
modifyMCtx fun mctx => mctx.assignLevel mvarId u
def whnfR (e : Expr) : MetaM Expr :=
withTransparency TransparencyMode.reducible <| whnf e
def whnfD (e : Expr) : MetaM Expr :=
withTransparency TransparencyMode.default <| whnf e
def whnfI (e : Expr) : MetaM Expr :=
withTransparency TransparencyMode.instances <| whnf e
def setInlineAttribute (declName : Name) (kind := Compiler.InlineAttributeKind.inline): MetaM Unit := do
let env β getEnv
match Compiler.setInlineAttribute env declName kind with
| Except.ok env => setEnv env
| Except.error msg => throwError msg
private partial def instantiateForallAux (ps : Array Expr) (i : Nat) (e : Expr) : MetaM Expr := do
if h : i < ps.size then
let p := ps.get β¨i, hβ©
let e β whnf e
match e with
| Expr.forallE _ _ b _ => instantiateForallAux ps (i+1) (b.instantiate1 p)
| _ => throwError "invalid instantiateForall, too many parameters"
else
pure e
/- Given `e` of the form `forall (a_1 : A_1) ... (a_n : A_n), B[a_1, ..., a_n]` and `p_1 : A_1, ... p_n : A_n`, return `B[p_1, ..., p_n]`. -/
def instantiateForall (e : Expr) (ps : Array Expr) : MetaM Expr :=
instantiateForallAux ps 0 e
private partial def instantiateLambdaAux (ps : Array Expr) (i : Nat) (e : Expr) : MetaM Expr := do
if h : i < ps.size then
let p := ps.get β¨i, hβ©
let e β whnf e
match e with
| Expr.lam _ _ b _ => instantiateLambdaAux ps (i+1) (b.instantiate1 p)
| _ => throwError "invalid instantiateLambda, too many parameters"
else
pure e
/- Given `e` of the form `fun (a_1 : A_1) ... (a_n : A_n) => t[a_1, ..., a_n]` and `p_1 : A_1, ... p_n : A_n`, return `t[p_1, ..., p_n]`.
It uses `whnf` to reduce `e` if it is not a lambda -/
def instantiateLambda (e : Expr) (ps : Array Expr) : MetaM Expr :=
instantiateLambdaAux ps 0 e
/-- Return true iff `e` depends on the free variable `fvarId` -/
def dependsOn (e : Expr) (fvarId : FVarId) : MetaM Bool :=
return (β getMCtx).exprDependsOn e fvarId
def ppExpr (e : Expr) : MetaM Format := do
let env β getEnv
let mctx β getMCtx
let lctx β getLCtx
let opts β getOptions
let ctxCore β readThe Core.Context
Lean.ppExpr { env := env, mctx := mctx, lctx := lctx, opts := opts, currNamespace := ctxCore.currNamespace, openDecls := ctxCore.openDecls } e
@[inline] protected def orelse (x y : MetaM Ξ±) : MetaM Ξ± := do
let env β getEnv
let mctx β getMCtx
try x catch _ => setEnv env; setMCtx mctx; y
instance : OrElse (MetaM Ξ±) := β¨Meta.orelseβ©
@[inline] private def orelseMergeErrorsImp (x y : MetaM Ξ±)
(mergeRef : Syntax β Syntax β Syntax := fun rβ rβ => rβ)
(mergeMsg : MessageData β MessageData β MessageData := fun mβ mβ => mβ ++ Format.line ++ mβ) : MetaM Ξ± := do
let env β getEnv
let mctx β getMCtx
try
x
catch ex =>
setEnv env
setMCtx mctx
match ex with
| Exception.error refβ mβ =>
try
y
catch
| Exception.error refβ mβ => throw <| Exception.error (mergeRef refβ refβ) (mergeMsg mβ mβ)
| ex => throw ex
| ex => throw ex
/--
Similar to `orelse`, but merge errors. Note that internal errors are not caught.
The default `mergeRef` uses the `ref` (position information) for the first message.
The default `mergeMsg` combines error messages using `Format.line ++ Format.line` as a separator. -/
@[inline] def orelseMergeErrors [MonadControlT MetaM m] [Monad m] (x y : m Ξ±)
(mergeRef : Syntax β Syntax β Syntax := fun rβ rβ => rβ)
(mergeMsg : MessageData β MessageData β MessageData := fun mβ mβ => mβ ++ Format.line ++ Format.line ++ mβ) : m Ξ± := do
controlAt MetaM fun runInBase => orelseMergeErrorsImp (runInBase x) (runInBase y) mergeRef mergeMsg
/-- Execute `x`, and apply `f` to the produced error message -/
def mapErrorImp (x : MetaM Ξ±) (f : MessageData β MessageData) : MetaM Ξ± := do
try
x
catch
| Exception.error ref msg => throw <| Exception.error ref <| f msg
| ex => throw ex
@[inline] def mapError [MonadControlT MetaM m] [Monad m] (x : m Ξ±) (f : MessageData β MessageData) : m Ξ± :=
controlAt MetaM fun runInBase => mapErrorImp (runInBase x) f
end Methods
end Meta
export Meta (MetaM)
end Lean
|
c532b2209f3c147a1e55f54ec1e36b74d5fda821 | 8e6cad62ec62c6c348e5faaa3c3f2079012bdd69 | /src/linear_algebra/basic.lean | de41edee2e5b9f0c4b817ade19d720917cc758fd | [
"Apache-2.0"
] | permissive | benjamindavidson/mathlib | 8cc81c865aa8e7cf4462245f58d35ae9a56b150d | fad44b9f670670d87c8e25ff9cdf63af87ad731e | refs/heads/master | 1,679,545,578,362 | 1,615,343,014,000 | 1,615,343,014,000 | 312,926,983 | 0 | 0 | Apache-2.0 | 1,615,360,301,000 | 1,605,399,418,000 | Lean | UTF-8 | Lean | false | false | 99,273 | 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
-/
import algebra.big_operators.pi
import algebra.module.pi
import algebra.module.prod
import algebra.module.submodule
import algebra.group.prod
import data.finsupp.basic
import data.dfinsupp
import algebra.pointwise
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. If `p` and `q` are submodules of a module, `p β€ q`
means that `p β q`.
Many of the relevant definitions, including `module`, `submodule`, and `linear_map`, are found in
`src/algebra/module`.
## Main definitions
* Many constructors for linear maps
* `submodule.span s` is defined to be the smallest submodule containing the set `s`.
* If `p` is a submodule of `M`, `submodule.quotient p` is the quotient of `M` with respect to `p`:
that is, elements of `M` are identified if their difference is in `p`. This is itself a module.
* 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.
## Main statements
* The first and second isomorphism laws for modules are proved as `quot_ker_equiv_range` and
`quotient_inf_equiv_sup_quotient`.
## Notations
* We continue to use the notation `M ββ[R] Mβ` for the type of linear maps from `M` to `Mβ` over the
ring `R`.
* We introduce the notations `M ββ Mβ` and `M ββ[R] Mβ` for `linear_equiv M Mβ`. In the first, the
ring `R` is implicit.
* We introduce the notation `R β v` for the span of a singleton, `submodule.span R {v}`. This is
`\.`, not the same as the scalar multiplication `β’`/`\bub`.
## 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.
## Tags
linear algebra, vector space, module
-/
open function
open_locale big_operators
universes u v w x y z u' v' w' y'
variables {R : Type u} {K : Type u'} {M : Type v} {V : Type v'} {Mβ : Type w} {Vβ : Type w'}
variables {Mβ : Type y} {Vβ : Type y'} {Mβ : Type z} {ΞΉ : Type x}
namespace finsupp
lemma smul_sum {Ξ± : Type u} {Ξ² : Type v} {R : Type w} {M : Type y}
[has_zero Ξ²] [semiring R] [add_comm_monoid M] [semimodule R M]
{v : Ξ± ββ Ξ²} {c : R} {h : Ξ± β Ξ² β M} :
c β’ (v.sum h) = v.sum (Ξ»a b, c β’ h a b) :=
finset.smul_sum
end finsupp
section
open_locale classical
/-- decomposing `x : ΞΉ β R` as a sum along the canonical basis -/
lemma pi_eq_sum_univ {ΞΉ : Type u} [fintype ΞΉ] {R : Type v} [semiring R] (x : ΞΉ β R) :
x = β i, x i β’ (Ξ»j, if i = j then 1 else 0) :=
by { ext, simp }
end
/-! ### Properties of linear maps -/
namespace linear_map
section add_comm_monoid
variables [semiring R]
variables [add_comm_monoid M] [add_comm_monoid Mβ] [add_comm_monoid Mβ] [add_comm_monoid Mβ]
variables [semimodule R M] [semimodule R Mβ] [semimodule R Mβ] [semimodule R Mβ]
variables (f g : M ββ[R] Mβ)
include R
@[simp] theorem comp_id : f.comp id = f :=
linear_map.ext $ Ξ» x, rfl
@[simp] theorem id_comp : id.comp f = f :=
linear_map.ext $ Ξ» x, rfl
theorem comp_assoc (g : Mβ ββ[R] Mβ) (h : Mβ ββ[R] Mβ) : (h.comp g).comp f = h.comp (g.comp f) :=
rfl
/-- 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 ββ[R] Mβ) (p : submodule R M) : p ββ[R] Mβ := f.comp p.subtype
@[simp] lemma dom_restrict_apply (f : M ββ[R] 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β ββ[R] M) (h : βc, f c β p) : Mβ ββ[R] 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β ββ[R] 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, f b β p) (g : Mβ ββ[R] M) :
(cod_restrict p f h).comp g = cod_restrict p (f.comp g) (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 $ submodule.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
/-- The constant 0 map is linear. -/
instance : has_zero (M ββ[R] Mβ) := β¨β¨Ξ» _, 0, by simp, by simpβ©β©
instance : inhabited (M ββ[R] Mβ) := β¨0β©
@[simp] lemma zero_apply (x : M) : (0 : M ββ[R] Mβ) x = 0 := rfl
@[simp] lemma default_def : default (M ββ[R] Mβ) = 0 := rfl
instance unique_of_left [subsingleton M] : unique (M ββ[R] 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 ββ[R] Mβ) :=
coe_injective.unique
/-- The sum of two linear maps is linear. -/
instance : has_add (M ββ[R] Mβ) :=
β¨Ξ» f g, β¨Ξ» b, f b + g b, by simp [add_comm, add_left_comm], by simp [smul_add]β©β©
@[simp] lemma add_apply (x : M) : (f + g) x = f x + g x := rfl
/-- The type of linear maps is an additive monoid. -/
instance : add_comm_monoid (M ββ[R] Mβ) :=
by refine {zero := 0, add := (+), ..};
intros; ext; simp [add_comm, add_left_comm]
instance linear_map_apply_is_add_monoid_hom (a : M) :
is_add_monoid_hom (Ξ» f : M ββ[R] Mβ, f a) :=
{ map_add := Ξ» f g, linear_map.add_apply f g a,
map_zero := rfl }
lemma add_comp (g : Mβ ββ[R] Mβ) (h : Mβ ββ[R] Mβ) :
(h + g).comp f = h.comp f + g.comp f := rfl
lemma comp_add (g : M ββ[R] Mβ) (h : Mβ ββ[R] Mβ) :
h.comp (f + g) = h.comp f + h.comp g := by { ext, simp }
lemma sum_apply (t : finset ΞΉ) (f : ΞΉ β M ββ[R] Mβ) (b : M) :
(β d in t, f d) b = β d in t, f d b :=
(t.sum_hom (Ξ» g : M ββ[R] Mβ, g b)).symm
section smul_right
variables {S : Type*} [semiring S] [semimodule R S] [semimodule 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 rw [f.map_smul, smul_assoc] }
@[simp] 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 : has_one (M ββ[R] M) := β¨linear_map.idβ©
instance : has_mul (M ββ[R] M) := β¨linear_map.compβ©
lemma mul_eq_comp (f g : M ββ[R] M) : f * g = f.comp g := rfl
@[simp] lemma one_apply (x : M) : (1 : M ββ[R] M) x = x := rfl
@[simp] lemma mul_apply (f g : M ββ[R] M) (x : M) : (f * g) x = f (g x) := rfl
lemma coe_one : β(1 : M ββ[R] M) = _root_.id := rfl
lemma coe_mul (f g : M ββ[R] M) : β(f * g) = f β g := rfl
@[simp] theorem comp_zero : f.comp (0 : Mβ ββ[R] M) = 0 :=
ext $ assume c, by rw [comp_apply, zero_apply, zero_apply, f.map_zero]
@[simp] theorem zero_comp : (0 : Mβ ββ[R] Mβ).comp f = 0 :=
rfl
@[simp, norm_cast] lemma coe_fn_sum {ΞΉ : Type*} (t : finset ΞΉ) (f : ΞΉ β M ββ[R] Mβ) :
β(β i in t, f i) = β i in t, (f i : M β Mβ) :=
add_monoid_hom.map_sum β¨@to_fun R M Mβ _ _ _ _ _, rfl, Ξ» x y, rflβ© _ _
instance : monoid (M ββ[R] M) :=
by refine {mul := (*), one := 1, ..}; { intros, apply linear_map.ext, simp {proj := ff} }
@[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 coe_pow (f : M ββ[R] M) (n : β) : β(f^n) = (f^[n]) :=
by { ext m, apply pow_apply, }
section
open_locale classical
/-- 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 ΞΉ] (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 f.map_smul
end
end
end add_comm_monoid
section add_comm_group
variables [semiring R]
[add_comm_monoid M] [add_comm_group Mβ] [add_comm_group Mβ] [add_comm_group Mβ]
[semimodule R M] [semimodule R Mβ] [semimodule R Mβ] [semimodule R Mβ]
(f g : M ββ[R] Mβ)
/-- The negation of a linear map is linear. -/
instance : has_neg (M ββ[R] Mβ) :=
β¨Ξ» f, β¨Ξ» b, - f b, by simp [add_comm], by simpβ©β©
@[simp] lemma neg_apply (x : M) : (- f) x = - f x := rfl
@[simp] lemma comp_neg (g : Mβ ββ[R] Mβ) : g.comp (- f) = - g.comp f := by { ext, simp }
/-- The negation of a linear map is linear. -/
instance : has_sub (M ββ[R] Mβ) :=
β¨Ξ» f g,
β¨Ξ» b, f b - g b,
by { simp only [map_add, sub_eq_add_neg, neg_add], cc },
by { intros, simp only [map_smul, smul_sub] }β©β©
@[simp] lemma sub_apply (x : M) : (f - g) x = f x - g x := rfl
lemma sub_comp (g : Mβ ββ[R] Mβ) (h : Mβ ββ[R] Mβ) :
(g - h).comp f = g.comp f - h.comp f := rfl
lemma comp_sub (g : M ββ[R] Mβ) (h : Mβ ββ[R] Mβ) :
h.comp (g - f) = h.comp g - h.comp f := by { ext, simp }
/-- The type of linear maps is an additive group. -/
instance : add_comm_group (M ββ[R] Mβ) :=
by refine {zero := 0, add := (+), neg := has_neg.neg, sub := has_sub.sub, sub_eq_add_neg := _, ..};
intros; ext; simp [add_comm, add_left_comm, sub_eq_add_neg]
instance linear_map_apply_is_add_group_hom (a : M) :
is_add_group_hom (Ξ» f : M ββ[R] Mβ, f a) :=
{ map_add := Ξ» f g, linear_map.add_apply f g a }
end add_comm_group
section has_scalar
variables {S : Type*} [semiring R] [monoid S]
[add_comm_monoid M] [add_comm_monoid Mβ] [add_comm_monoid Mβ]
[semimodule R M] [semimodule R Mβ] [semimodule R Mβ]
[distrib_mul_action S Mβ] [smul_comm_class R S Mβ]
(f : M ββ[R] Mβ)
instance : has_scalar S (M ββ[R] Mβ) :=
β¨Ξ» a f, β¨Ξ» b, a β’ f b, Ξ» x y, by rw [f.map_add, smul_add],
Ξ» c x, by simp only [f.map_smul, smul_comm c]β©β©
@[simp] lemma smul_apply (a : S) (x : M) : (a β’ f) x = a β’ f x := rfl
instance {T : Type*} [monoid T] [distrib_mul_action T Mβ] [smul_comm_class R T Mβ]
[smul_comm_class S T Mβ] :
smul_comm_class S T (M ββ[R] Mβ) :=
β¨Ξ» a b f, ext $ Ξ» x, smul_comm _ _ _β©
-- example application of this instance: if S -> T -> R are homomorphisms of commutative rings and
-- M and Mβ are R-modules then the S-module and T-module structures on Hom_R(M,Mβ) are compatible.
instance {T : Type*} [monoid T] [has_scalar S T] [distrib_mul_action T Mβ] [smul_comm_class R T Mβ]
[is_scalar_tower S T Mβ] :
is_scalar_tower S T (M ββ[R] Mβ) :=
{ smul_assoc := Ξ» _ _ _, ext $ Ξ» _, smul_assoc _ _ _ }
instance : distrib_mul_action S (M ββ[R] Mβ) :=
{ one_smul := Ξ» f, ext $ Ξ» _, one_smul _ _,
mul_smul := Ξ» c c' f, ext $ Ξ» _, mul_smul _ _ _,
smul_add := Ξ» c f g, ext $ Ξ» x, smul_add _ _ _,
smul_zero := Ξ» c, ext $ Ξ» x, smul_zero _ }
theorem smul_comp (a : S) (g : Mβ ββ[R] Mβ) (f : M ββ[R] Mβ) : (a β’ g).comp f = a β’ (g.comp f) :=
rfl
end has_scalar
section semimodule
variables {S : Type*} [semiring R] [semiring S]
[add_comm_monoid M] [add_comm_monoid Mβ] [add_comm_monoid Mβ]
[semimodule R M] [semimodule R Mβ] [semimodule R Mβ]
[semimodule S Mβ] [semimodule S Mβ] [smul_comm_class R S Mβ] [smul_comm_class R S Mβ]
(f : M ββ[R] Mβ)
instance : semimodule S (M ββ[R] Mβ) :=
{ add_smul := Ξ» a b f, ext $ Ξ» x, add_smul _ _ _,
zero_smul := Ξ» f, ext $ Ξ» x, zero_smul _ _ }
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 [semimodule 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 semimodule
section comm_semiring
variables [comm_semiring R] [add_comm_monoid M] [add_comm_monoid Mβ] [add_comm_monoid Mβ]
variables [semimodule R M] [semimodule R Mβ] [semimodule R Mβ]
variables (f g : M ββ[R] Mβ)
include R
theorem comp_smul (g : Mβ ββ[R] Mβ) (a : R) : g.comp (a β’ f) = a β’ (g.comp f) :=
ext $ assume b, by rw [comp_apply, smul_apply, g.map_smul]; refl
/-- 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β) :=
β¨f.comp,
Ξ» _ _, linear_map.ext $ Ξ» _, f.2 _ _,
Ξ» _ _, linear_map.ext $ Ξ» _, f.3 _ _β©
/-- 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, f.map_smul _ _,
..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
end comm_semiring
section semiring
variables [semiring R] [add_comm_monoid M] [semimodule R M]
instance endomorphism_semiring : semiring (M ββ[R] M) :=
by refine {mul := (*), one := 1, ..linear_map.add_comm_monoid, ..};
{ intros, apply linear_map.ext, simp {proj := ff} }
end semiring
section ring
variables [ring R] [add_comm_group M] [semimodule R M]
instance endomorphism_ring : ring (M ββ[R] M) :=
{ ..linear_map.endomorphism_semiring, ..linear_map.add_comm_group }
end ring
section comm_ring
variables [comm_ring R] [add_comm_group M] [add_comm_group Mβ] [add_comm_group Mβ]
variables [semimodule R M] [semimodule R Mβ] [semimodule R Mβ]
/--
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) ββ M ββ Mβ ββ M) f x c = (f c) β’ x := rfl
end comm_ring
end linear_map
/-! ### Properties of submodules -/
namespace submodule
section add_comm_monoid
variables [semiring R] [add_comm_monoid M] [add_comm_monoid Mβ] [add_comm_monoid Mβ]
variables [semimodule R M] [semimodule R Mβ] [semimodule R Mβ]
variables (p p' : submodule R M) (q q' : submodule R Mβ)
variables {r : R} {x y : M}
open set
instance : partial_order (submodule R M) :=
{ le := Ξ» p p', β β¦xβ¦, x β p β x β p',
..partial_order.lift (coe : submodule R M β set M) coe_injective }
variables {p p'}
lemma le_def : p β€ p' β (p : set M) β p' := iff.rfl
@[simp, norm_cast] lemma coe_subset_coe : (p : set M) β p' β p β€ p' := iff.rfl
lemma le_def' : p β€ p' β β x β p, x β p' := iff.rfl
lemma lt_def : p < p' β (p : set M) β p' := iff.rfl
lemma not_le_iff_exists : Β¬ (p β€ p') β β x β p, x β p' := not_subset
lemma exists_of_lt {p p' : submodule R M} : p < p' β β x β p', x β p := exists_of_ssubset
lemma lt_iff_le_and_exists : p < p' β p β€ p' β§ β x β p', x β p :=
by rw [lt_iff_le_not_le, not_le_iff_exists]
/-- 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
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 }
/-- The set `{0}` is the bottom element of the lattice of submodules. -/
instance : has_bot (submodule R M) :=
β¨{ carrier := {0}, smul_mem' := by simp { contextual := tt }, .. (β₯ : add_submonoid M)}β©
instance inhabited' : inhabited (submodule R M) := β¨β₯β©
@[simp] lemma bot_coe : ((β₯ : submodule R M) : set M) = {0} := rfl
section
variables (R)
@[simp] lemma mem_bot : x β (β₯ : submodule R M) β x = 0 := mem_singleton_iff
end
instance unique_bot : unique (β₯ : submodule R M) :=
β¨infer_instance, Ξ» x, subtype.ext $ (mem_bot R).1 x.memβ©
lemma nonzero_mem_of_bot_lt {I : submodule R M} (bot_lt : β₯ < I) : β a : I, a β 0 :=
begin
have h := (submodule.lt_iff_le_and_exists.1 bot_lt).2,
tidy,
end
instance : order_bot (submodule R M) :=
{ bot := β₯,
bot_le := Ξ» p x, by simp {contextual := tt},
..submodule.partial_order }
protected lemma eq_bot_iff (p : submodule R M) : p = β₯ β β x β p, x = (0 : M) :=
β¨ Ξ» h, h.symm βΈ Ξ» x hx, (mem_bot R).mp hx,
Ξ» h, eq_bot_iff.mpr (Ξ» x hx, (mem_bot R).mpr (h x hx)) β©
protected lemma ne_bot_iff (p : submodule R M) : p β β₯ β β x β p, x β (0 : M) :=
by { haveI := classical.prop_decidable, simp_rw [ne.def, p.eq_bot_iff, not_forall] }
/-- The universal set is the top element of the lattice of submodules. -/
instance : has_top (submodule R M) :=
β¨{ carrier := univ, smul_mem' := Ξ» _ _ _, trivial, .. (β€ : add_submonoid M)}β©
@[simp] lemma top_coe : ((β€ : submodule R M) : set M) = univ := rfl
@[simp] lemma mem_top : x β (β€ : submodule R M) := trivial
instance : order_top (submodule R M) :=
{ top := β€,
le_top := Ξ» p x _, trivial,
..submodule.partial_order }
instance : has_Inf (submodule R M) :=
β¨Ξ» S, {
carrier := β s β S, (s : set M),
zero_mem' := by simp,
add_mem' := by simp [add_mem] {contextual := tt},
smul_mem' := by simp [smul_mem] {contextual := tt} }β©
private lemma Inf_le' {S : set (submodule R M)} {p} : p β S β Inf S β€ p :=
bInter_subset_of_mem
private lemma le_Inf' {S : set (submodule R M)} {p} : (βp' β S, p β€ p') β p β€ Inf S :=
subset_bInter
instance : has_inf (submodule R M) :=
β¨Ξ» p p', {
carrier := p β© p',
zero_mem' := by simp,
add_mem' := by simp [add_mem] {contextual := tt},
smul_mem' := by simp [smul_mem] {contextual := tt} }β©
instance : complete_lattice (submodule R M) :=
{ sup := Ξ» a b, Inf {x | a β€ x β§ b β€ x},
le_sup_left := Ξ» a b, le_Inf' $ Ξ» x β¨ha, hbβ©, ha,
le_sup_right := Ξ» a b, le_Inf' $ Ξ» x β¨ha, hbβ©, hb,
sup_le := Ξ» a b c hβ hβ, Inf_le' β¨hβ, hββ©,
inf := (β),
le_inf := Ξ» a b c, subset_inter,
inf_le_left := Ξ» a b, inter_subset_left _ _,
inf_le_right := Ξ» a b, inter_subset_right _ _,
Sup := Ξ»tt, Inf {t | βt'βtt, t' β€ t},
le_Sup := Ξ» s p hs, le_Inf' $ Ξ» p' hp', hp' _ hs,
Sup_le := Ξ» s p hs, Inf_le' hs,
Inf := Inf,
le_Inf := Ξ» s a, le_Inf',
Inf_le := Ξ» s a, Inf_le',
..submodule.order_top,
..submodule.order_bot }
instance add_comm_monoid_submodule : add_comm_monoid (submodule R M) :=
{ add := (β),
add_assoc := Ξ» _ _ _, sup_assoc,
zero := β₯,
zero_add := Ξ» _, bot_sup_eq,
add_zero := Ξ» _, sup_bot_eq,
add_comm := Ξ» _ _, sup_comm }
@[simp] lemma add_eq_sup (p q : submodule R M) : p + q = p β q := rfl
@[simp] lemma zero_eq_bot : (0 : submodule R M) = β₯ := rfl
lemma eq_top_iff' {p : submodule R M} : p = β€ β β x, x β p :=
eq_top_iff.trans β¨Ξ» h x, @h x trivial, Ξ» h x _, h xβ©
variables (R)
@[simp] lemma bot_to_add_submonoid : (β₯ : submodule R M).to_add_submonoid = β₯ := rfl
@[simp] lemma top_to_add_submonoid : (β€ : submodule R M).to_add_submonoid = β€ := rfl
lemma subsingleton_iff : subsingleton M β subsingleton (submodule R M) :=
add_submonoid.subsingleton_iff.trans $ begin
rw [βsubsingleton_iff_bot_eq_top, βsubsingleton_iff_bot_eq_top],
convert to_add_submonoid_eq; refl
end
lemma nontrivial_iff : nontrivial M β nontrivial (submodule R 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).mp βΉ_βΊ) a _β©
instance unique' [subsingleton R] : unique (submodule R M) :=
by haveI := semimodule.subsingleton R M; apply_instance
instance [nontrivial M] : nontrivial (submodule R M) := (nontrivial_iff R).mp βΉ_βΊ
@[simp] theorem inf_coe : (p β p' : set M) = p β© p' := rfl
@[simp] theorem mem_inf {p p' : submodule R M} :
x β p β p' β x β p β§ x β p' := iff.rfl
@[simp] theorem Inf_coe (P : set (submodule R M)) : (β(Inf P) : set M) = β p β P, βp := rfl
@[simp] theorem infi_coe {ΞΉ} (p : ΞΉ β submodule R M) :
(ββ¨
i, p i : set M) = β i, β(p i) :=
by rw [infi, Inf_coe]; ext a; simp; exact
β¨Ξ» h i, h _ i rfl, Ξ» h i x e, e βΈ h _β©
@[simp] lemma mem_Inf {S : set (submodule R M)} {x : M} : x β Inf S β β p β S, x β p :=
set.mem_bInter_iff
@[simp] theorem mem_infi {ΞΉ} (p : ΞΉ β submodule R M) :
x β (β¨
i, p i) β β i, x β p i :=
by rw [β mem_coe, infi_coe, mem_Inter]; refl
theorem disjoint_def {p p' : submodule R M} :
disjoint p p' β β x β p, x β p' β x = (0:M) :=
show (β x, x β p β§ x β p' β x β ({0} : set M)) β _, by simp
theorem disjoint_def' {p p' : submodule R M} :
disjoint p p' β β (x β p) (y β p'), x = y β x = (0:M) :=
disjoint_def.trans β¨Ξ» h x hx y hy hxy, h x hx $ hxy.symm βΈ hy,
Ξ» h x hx hx', h _ hx x hx' rflβ©
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β©
/-- The pushforward of a submodule `p β M` by `f : M β Mβ` -/
def map (f : M ββ[R] Mβ) (p : submodule R M) : submodule R Mβ :=
{ carrier := f '' p,
smul_mem' := by rintro a _ β¨b, hb, rflβ©; exact β¨_, p.smul_mem _ hb, f.map_smul _ _β©,
.. p.to_add_submonoid.map f.to_add_monoid_hom }
@[simp] lemma map_coe (f : M ββ[R] Mβ) (p : submodule R M) :
(map f p : set Mβ) = f '' p := rfl
@[simp] lemma mem_map {f : M ββ[R] 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 ββ[R] Mβ} {p : submodule R M} {r} (h : r β p) : f r β map f p :=
set.mem_image_of_mem _ h
@[simp] lemma map_id : map linear_map.id p = p :=
submodule.ext $ Ξ» a, by simp
lemma map_comp (f : M ββ[R] Mβ) (g : Mβ ββ[R] Mβ) (p : submodule R M) :
map (g.comp f) p = map g (map f p) :=
submodule.coe_injective $ by simp [map_coe]; rw β image_comp
lemma map_mono {f : M ββ[R] Mβ} {p p' : submodule R M} : p β€ p' β map f p β€ map f p' :=
image_subset _
@[simp] lemma map_zero : map (0 : M ββ[R] Mβ) p = β₯ :=
have β (x : M), x β p := β¨0, p.zero_memβ©,
ext $ by simp [this, eq_comm]
lemma range_map_nonempty (N : submodule R M) :
(set.range (Ξ» Ο, submodule.map Ο N : (M ββ[R] Mβ) β submodule R Mβ)).nonempty :=
β¨_, set.mem_range.mpr β¨0, rflβ©β©
/-- The pullback of a submodule `p β Mβ` along `f : M β Mβ` -/
def comap (f : M ββ[R] 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 ββ[R] Mβ) (p : submodule R Mβ) :
(comap f p : set M) = f β»ΒΉ' p := rfl
@[simp] lemma mem_comap {f : M ββ[R] Mβ} {p : submodule R Mβ} :
x β comap f p β f x β p := iff.rfl
lemma comap_id : comap linear_map.id p = p :=
submodule.coe_injective rfl
lemma comap_comp (f : M ββ[R] Mβ) (g : Mβ ββ[R] Mβ) (p : submodule R Mβ) :
comap (g.comp f) p = comap f (comap g p) := rfl
lemma comap_mono {f : M ββ[R] Mβ} {q q' : submodule R Mβ} : q β€ q' β comap f q β€ comap f q' :=
preimage_mono
lemma map_le_iff_le_comap {f : M ββ[R] 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 ββ[R] Mβ) : galois_connection (map f) (comap f)
| p q := map_le_iff_le_comap
@[simp] lemma map_bot (f : M ββ[R] Mβ) : map f β₯ = β₯ :=
(gc_map_comap f).l_bot
@[simp] lemma map_sup (f : M ββ[R] Mβ) : map f (p β p') = map f p β map f p' :=
(gc_map_comap f).l_sup
@[simp] lemma map_supr {ΞΉ : Sort*} (f : M ββ[R] Mβ) (p : ΞΉ β submodule R M) :
map f (β¨i, p i) = (β¨i, map f (p i)) :=
(gc_map_comap f).l_supr
@[simp] lemma comap_top (f : M ββ[R] Mβ) : comap f β€ = β€ := rfl
@[simp] lemma comap_inf (f : M ββ[R] Mβ) : comap f (q β q') = comap f q β comap f q' := rfl
@[simp] lemma comap_infi {ΞΉ : Sort*} (f : M ββ[R] 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 ββ[R] Mβ) q = β€ :=
ext $ by simp
lemma map_comap_le (f : M ββ[R] Mβ) (q : submodule R Mβ) : map f (comap f q) β€ q :=
(gc_map_comap f).l_u_le _
lemma le_comap_map (f : M ββ[R] Mβ) (p : submodule R M) : p β€ comap f (map f p) :=
(gc_map_comap f).le_u_l _
--TODO(Mario): is there a way to prove this from order properties?
lemma map_inf_eq_map_inf_comap {f : M ββ[R] 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
section
variables (R)
/-- The span of a set `s β M` is the smallest submodule of M that contains `s`. -/
def span (s : set M) : submodule R M := Inf {p | s β p}
end
variables {s t : set M}
lemma mem_span : x β span R s β β p : submodule R M, s β p β x β p :=
mem_bInter_iff
lemma subset_span : s β span R s :=
Ξ» x h, mem_span.2 $ Ξ» p hp, hp h
lemma span_le {p} : span R s β€ p β s β p :=
β¨subset.trans subset_span, Ξ» ss x h, mem_span.1 h _ ssβ©
lemma span_mono (h : s β t) : span R s β€ span R t :=
span_le.2 $ subset.trans h subset_span
lemma span_eq_of_le (hβ : s β p) (hβ : p β€ span R s) : span R s = p :=
le_antisymm (span_le.2 hβ) hβ
@[simp] lemma span_eq : span R (p : set M) = p :=
span_eq_of_le _ (subset.refl _) subset_span
lemma map_span (f : M ββ[R] Mβ) (s : set M) :
(span R s).map f = span R (f '' s) :=
eq.symm $ span_eq_of_le _ (set.image_subset f subset_span) $
map_le_iff_le_comap.2 $ span_le.2 $ Ξ» x hx, subset_span β¨x, hx, rflβ©
/- See also `span_preimage_eq` below. -/
lemma span_preimage_le (f : M ββ[R] Mβ) (s : set Mβ) :
span R (f β»ΒΉ' s) β€ (span R s).comap f :=
by { rw [span_le, comap_coe], exact preimage_mono (subset_span), }
/-- An induction principle for span membership. If `p` holds for 0 and all elements of `s`, and is
preserved under addition and scalar multiplication, then `p` holds for all elements of the span of
`s`. -/
@[elab_as_eliminator] lemma span_induction {p : M β Prop} (h : x β span R s)
(Hs : β x β s, p x) (H0 : p 0)
(H1 : β x y, p x β p y β p (x + y))
(H2 : β (a:R) x, p x β p (a β’ x)) : p x :=
(@span_le _ _ _ _ _ _ β¨p, H0, H1, H2β©).2 Hs h
section
variables (R M)
/-- `span` forms a Galois insertion with the coercion from submodule to set. -/
protected def gi : galois_insertion (@span R M _ _ _) coe :=
{ choice := Ξ» s _, span R s,
gc := Ξ» s t, span_le,
le_l_u := Ξ» s, subset_span,
choice_eq := Ξ» s h, rfl }
end
@[simp] lemma span_empty : span R (β
: set M) = β₯ :=
(submodule.gi R M).gc.l_bot
@[simp] lemma span_univ : span R (univ : set M) = β€ :=
eq_top_iff.2 $ le_def.2 $ subset_span
lemma span_union (s t : set M) : span R (s βͺ t) = span R s β span R t :=
(submodule.gi R M).gc.l_sup
lemma span_Union {ΞΉ} (s : ΞΉ β set M) : span R (β i, s i) = β¨ i, span R (s i) :=
(submodule.gi R M).gc.l_supr
lemma span_eq_supr_of_singleton_spans (s : set M) : span R s = β¨ x β s, span R {x} :=
by simp only [βspan_Union, set.bUnion_of_singleton s]
@[simp] theorem coe_supr_of_directed {ΞΉ} [hΞΉ : nonempty ΞΉ]
(S : ΞΉ β submodule R M) (H : directed (β€) S) :
((supr S : submodule R M) : set M) = β i, S i :=
begin
refine subset.antisymm _ (Union_subset $ le_supr S),
suffices : (span R (β i, (S i : set M)) : set M) β β (i : ΞΉ), β(S i),
by simpa only [span_Union, span_eq] using this,
refine (Ξ» x hx, span_induction hx (Ξ» _, id) _ _ _);
simp only [mem_Union, exists_imp_distrib],
{ exact hΞΉ.elim (Ξ» i, β¨i, (S i).zero_memβ©) },
{ intros x y i hi j hj,
rcases H i j with β¨k, ik, jkβ©,
exact β¨k, add_mem _ (ik hi) (jk hj)β© },
{ exact Ξ» a x i hi, β¨i, smul_mem _ a hiβ© },
end
lemma mem_sup_left {S T : submodule R M} : β {x : M}, x β S β x β S β T :=
show S β€ S β T, from le_sup_left
lemma mem_sup_right {S T : submodule R M} : β {x : M}, x β T β x β S β T :=
show T β€ S β T, from le_sup_right
lemma mem_supr_of_mem {ΞΉ : Sort*} {b : M} {p : ΞΉ β submodule R M} (i : ΞΉ) (h : b β p i) :
b β (β¨i, p i) :=
have p i β€ (β¨i, p i) := le_supr p i,
@this b h
lemma sum_mem_bsupr {ΞΉ : Type*} {s : finset ΞΉ} {f : ΞΉ β M} {p : ΞΉ β submodule R M}
(h : β i β s, f i β p i) :
β i in s, f i β β¨ i β s, p i :=
sum_mem _ $ Ξ» i hi, mem_supr_of_mem i $ mem_supr_of_mem hi (h i hi)
lemma sum_mem_supr {ΞΉ : Type*} [fintype ΞΉ] {f : ΞΉ β M} {p : ΞΉ β submodule R M}
(h : β i, f i β p i) :
β i, f i β β¨ i, p i :=
sum_mem _ $ Ξ» i hi, mem_supr_of_mem i (h i)
lemma mem_Sup_of_mem {S : set (submodule R M)} {s : submodule R M}
(hs : s β S) : β {x : M}, x β s β x β Sup S :=
show s β€ Sup S, from le_Sup hs
@[simp] theorem mem_supr_of_directed {ΞΉ} [nonempty ΞΉ]
(S : ΞΉ β submodule R M) (H : directed (β€) S) {x} :
x β supr S β β i, x β S i :=
by { rw [β mem_coe, coe_supr_of_directed S H, mem_Union], refl }
theorem mem_Sup_of_directed {s : set (submodule R M)}
{z} (hs : s.nonempty) (hdir : directed_on (β€) s) :
z β Sup s β β y β s, z β y :=
begin
haveI : nonempty s := hs.to_subtype,
simp only [Sup_eq_supr', mem_supr_of_directed _ hdir.directed_coe, set_coe.exists, subtype.coe_mk]
end
section
variables {p p'}
lemma mem_sup : x β p β p' β β (y β p) (z β p'), y + z = x :=
β¨Ξ» h, begin
rw [β span_eq p, β span_eq p', β span_union] at h,
apply span_induction h,
{ rintro y (h | h),
{ exact β¨y, h, 0, by simp, by simpβ© },
{ exact β¨0, by simp, y, h, by simpβ© } },
{ exact β¨0, by simp, 0, by simpβ© },
{ rintro _ _ β¨yβ, hyβ, zβ, hzβ, rflβ© β¨yβ, hyβ, zβ, hzβ, rflβ©,
exact β¨_, add_mem _ hyβ hyβ, _, add_mem _ hzβ hzβ, by simp [add_assoc]; ccβ© },
{ rintro a _ β¨y, hy, z, hz, rflβ©,
exact β¨_, smul_mem _ a hy, _, smul_mem _ a hz, by simp [smul_add]β© }
end,
by rintro β¨y, hy, z, hz, rflβ©; exact add_mem _
((le_sup_left : p β€ p β p') hy)
((le_sup_right : p' β€ p β p') hz)β©
lemma mem_sup' : x β p β p' β β (y : p) (z : p'), (y:M) + z = x :=
mem_sup.trans $ by simp only [submodule.exists, coe_mk]
end
notation R`β`:1000 x := span R (@singleton _ _ set.has_singleton x)
lemma mem_span_singleton_self (x : M) : x β R β x := subset_span rfl
lemma nontrivial_span_singleton {x : M} (h : x β 0) : nontrivial (R β x) :=
β¨begin
use [0, x, submodule.mem_span_singleton_self x],
intros H,
rw [eq_comm, submodule.mk_eq_zero] at H,
exact h H
endβ©
lemma mem_span_singleton {y : M} : x β (R β y) β β a:R, a β’ y = x :=
β¨Ξ» h, begin
apply span_induction h,
{ rintro y (rfl|β¨β¨β©β©), exact β¨1, by simpβ© },
{ exact β¨0, by simpβ© },
{ rintro _ _ β¨a, rflβ© β¨b, rflβ©,
exact β¨a + b, by simp [add_smul]β© },
{ rintro a _ β¨b, rflβ©,
exact β¨a * b, by simp [smul_smul]β© }
end,
by rintro β¨a, y, rflβ©; exact
smul_mem _ _ (subset_span $ by simp)β©
lemma le_span_singleton_iff {s : submodule R M} {vβ : M} :
s β€ (R β vβ) β β v β s, β r : R, r β’ vβ = v :=
by simp_rw [le_def', mem_span_singleton]
@[simp] lemma span_zero_singleton : (R β (0:M)) = β₯ :=
by { ext, simp [mem_span_singleton, eq_comm] }
lemma span_singleton_eq_range (y : M) : β(R β y) = range ((β’ y) : R β M) :=
set.ext $ Ξ» x, mem_span_singleton
lemma span_singleton_smul_le (r : R) (x : M) : (R β (r β’ x)) β€ R β x :=
begin
rw [span_le, set.singleton_subset_iff, mem_coe],
exact smul_mem _ _ (mem_span_singleton_self _)
end
lemma span_singleton_smul_eq {K E : Type*} [division_ring K] [add_comm_group E] [module K E]
{r : K} (x : E) (hr : r β 0) : (K β (r β’ x)) = K β x :=
begin
refine le_antisymm (span_singleton_smul_le r x) _,
convert span_singleton_smul_le rβ»ΒΉ (r β’ x),
exact (inv_smul_smul' hr _).symm
end
lemma disjoint_span_singleton {K E : Type*} [division_ring K] [add_comm_group E] [module K E]
{s : submodule K E} {x : E} :
disjoint s (K β x) β (x β s β x = 0) :=
begin
refine disjoint_def.trans β¨Ξ» H hx, H x hx $ subset_span $ mem_singleton x, _β©,
assume H y hy hyx,
obtain β¨c, hcβ© := mem_span_singleton.1 hyx,
subst y,
classical, by_cases hc : c = 0, by simp only [hc, zero_smul],
rw [s.smul_mem_iff hc] at hy,
rw [H hy, smul_zero]
end
lemma disjoint_span_singleton' {K E : Type*} [division_ring K] [add_comm_group E] [module K E]
{p : submodule K E} {x : E} (x0 : x β 0) :
disjoint p (K β x) β x β p :=
disjoint_span_singleton.trans β¨Ξ» hβ hβ, x0 (hβ hβ), Ξ» hβ hβ, (hβ hβ).elimβ©
lemma mem_span_insert {y} : x β span R (insert y s) β β (a:R) (z β span R s), x = a β’ y + z :=
begin
simp only [β union_singleton, span_union, mem_sup, mem_span_singleton, exists_prop,
exists_exists_eq_and],
rw [exists_comm],
simp only [eq_comm, add_comm, exists_and_distrib_left]
end
lemma span_insert_eq_span (h : x β span R s) : span R (insert x s) = span R s :=
span_eq_of_le _ (set.insert_subset.mpr β¨h, subset_spanβ©) (span_mono $ subset_insert _ _)
lemma span_span : span R (span R s : set M) = span R s := span_eq _
lemma span_eq_bot : span R (s : set M) = β₯ β β x β s, (x:M) = 0 :=
eq_bot_iff.trans β¨
Ξ» H x h, (mem_bot R).1 $ H $ subset_span h,
Ξ» H, span_le.2 (Ξ» x h, (mem_bot R).2 $ H x h)β©
@[simp] lemma span_singleton_eq_bot : (R β x) = β₯ β x = 0 :=
span_eq_bot.trans $ by simp
@[simp] lemma span_zero : span R (0 : set M) = β₯ := by rw [βsingleton_zero, span_singleton_eq_bot]
@[simp] lemma span_image (f : M ββ[R] Mβ) : span R (f '' s) = map f (span R s) :=
span_eq_of_le _ (image_subset _ subset_span) $ map_le_iff_le_comap.2 $
span_le.2 $ image_subset_iff.1 subset_span
lemma apply_mem_span_image_of_mem_span
(f : M ββ[R] Mβ) {x : M} {s : set M} (h : x β submodule.span R s) :
f x β submodule.span R (f '' s) :=
begin
rw submodule.span_image,
exact submodule.mem_map_of_mem h
end
/-- `f` is an explicit argument so we can `apply` this theorem and obtain `h` as a new goal. -/
lemma not_mem_span_of_apply_not_mem_span_image
(f : M ββ[R] Mβ) {x : M} {s : set M} (h : f x β submodule.span R (f '' s)) :
x β submodule.span R s :=
not.imp h (apply_mem_span_image_of_mem_span f)
lemma supr_eq_span {ΞΉ : Sort w} (p : ΞΉ β submodule R M) :
(β¨ (i : ΞΉ), p i) = submodule.span R (β (i : ΞΉ), β(p i)) :=
le_antisymm
(supr_le $ assume i, subset.trans (assume m hm, set.mem_Union.mpr β¨i, hmβ©) subset_span)
(span_le.mpr $ Union_subset_iff.mpr $ assume i m hm, mem_supr_of_mem i hm)
lemma span_singleton_le_iff_mem (m : M) (p : submodule R M) : (R β m) β€ p β m β p :=
by rw [span_le, singleton_subset_iff, mem_coe]
lemma singleton_span_is_compact_element (x : M) :
complete_lattice.is_compact_element (span R {x} : submodule R M) :=
begin
rw complete_lattice.is_compact_element_iff_le_of_directed_Sup_le,
intros d hemp hdir hsup,
have : x β Sup d, from (le_def.mp hsup) (mem_span_singleton_self x),
obtain β¨y, β¨hyd, hxyβ©β© := (mem_Sup_of_directed hemp hdir).mp this,
exact β¨y, β¨hyd, by simpa only [span_le, singleton_subset_iff]β©β©,
end
instance : is_compactly_generated (submodule R M) :=
β¨Ξ» s, β¨(Ξ» x, span R {x}) '' s, β¨Ξ» t ht, begin
rcases (set.mem_image _ _ _).1 ht with β¨x, hx, rflβ©,
apply singleton_span_is_compact_element,
end, by rw [Sup_eq_supr, supr_image, βspan_eq_supr_of_singleton_spans, span_eq]β©β©β©
lemma lt_add_iff_not_mem {I : submodule R M} {a : M} : I < I + (R β a) β a β I :=
begin
split,
{ intro h,
by_contra akey,
have h1 : I + (R β a) β€ I,
{ simp only [add_eq_sup, sup_le_iff],
split,
{ exact le_refl I, },
{ exact (span_singleton_le_iff_mem a I).mpr akey, } },
have h2 := gt_of_ge_of_gt h1 h,
exact lt_irrefl I h2, },
{ intro h,
apply lt_iff_le_and_exists.mpr, split,
simp only [add_eq_sup, le_sup_left],
use a,
split, swap, { assumption, },
{ have : (R β a) β€ I + (R β a) := le_sup_right,
exact this (mem_span_singleton_self a), } },
end
lemma mem_supr {ΞΉ : Sort w} (p : ΞΉ β submodule R M) {m : M} :
(m β β¨ i, p i) β (β N, (β i, p i β€ N) β m β N) :=
begin
rw [β span_singleton_le_iff_mem, le_supr_iff],
simp only [span_singleton_le_iff_mem],
end
section
open_locale classical
/-- For every element in the span of a set, there exists a finite subset of the set
such that the element is contained in the span of the subset. -/
lemma mem_span_finite_of_mem_span {S : set M} {x : M} (hx : x β span R S) :
β T : finset M, βT β S β§ x β span R (T : set M) :=
begin
refine span_induction hx (Ξ» x hx, _) _ _ _,
{ refine β¨{x}, _, _β©,
{ rwa [finset.coe_singleton, set.singleton_subset_iff] },
{ rw finset.coe_singleton,
exact submodule.mem_span_singleton_self x } },
{ use β
, simp },
{ rintros x y β¨X, hX, hxXβ© β¨Y, hY, hyYβ©,
refine β¨X βͺ Y, _, _β©,
{ rw finset.coe_union,
exact set.union_subset hX hY },
rw [finset.coe_union, span_union, mem_sup],
exact β¨x, hxX, y, hyY, rflβ©, },
{ rintros a x β¨T, hT, h2β©,
exact β¨T, hT, smul_mem _ _ h2β© }
end
end
/-- The product of two submodules is a submodule. -/
def prod : submodule R (M Γ Mβ) :=
{ carrier := set.prod p q,
smul_mem' := by rintro a β¨x, yβ© β¨hx, hyβ©; exact β¨smul_mem _ a hx, smul_mem _ a hyβ©,
.. p.to_add_submonoid.prod q.to_add_submonoid }
@[simp] lemma prod_coe :
(prod p q : set (M Γ Mβ)) = set.prod p q := rfl
@[simp] lemma mem_prod {p : submodule R M} {q : submodule R Mβ} {x : M Γ Mβ} :
x β prod p q β x.1 β p β§ x.2 β q := set.mem_prod
lemma span_prod_le (s : set M) (t : set Mβ) :
span R (set.prod s t) β€ prod (span R s) (span R t) :=
span_le.2 $ set.prod_mono subset_span subset_span
@[simp] lemma prod_top : (prod β€ β€ : submodule R (M Γ Mβ)) = β€ :=
by ext; simp
@[simp] lemma prod_bot : (prod β₯ β₯ : submodule R (M Γ Mβ)) = β₯ :=
by ext β¨x, yβ©; simp [prod.zero_eq_mk]
lemma prod_mono {p p' : submodule R M} {q q' : submodule R Mβ} :
p β€ p' β q β€ q' β prod p q β€ prod p' q' := prod_mono
@[simp] lemma prod_inf_prod : prod p q β prod p' q' = prod (p β p') (q β q') :=
coe_injective set.prod_inter_prod
@[simp] lemma prod_sup_prod : prod p q β prod p' q' = prod (p β p') (q β q') :=
begin
refine le_antisymm (sup_le
(prod_mono le_sup_left le_sup_left)
(prod_mono le_sup_right le_sup_right)) _,
simp [le_def'], intros xx yy hxx hyy,
rcases mem_sup.1 hxx with β¨x, hx, x', hx', rflβ©,
rcases mem_sup.1 hyy with β¨y, hy, y', hy', rflβ©,
refine mem_sup.2 β¨(x, y), β¨hx, hyβ©, (x', y'), β¨hx', hy'β©, rflβ©
end
end add_comm_monoid
variables [ring R] [add_comm_group M] [add_comm_group Mβ] [add_comm_group Mβ]
variables [semimodule R M] [semimodule R Mβ] [semimodule R Mβ]
variables (p p' : submodule R M) (q q' : submodule R Mβ)
variables {r : R} {x y : M}
open set
@[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, neg_mem _ hx, f.map_neg xβ©,
Ξ» β¨x, hx, hyβ©, hy βΈ β¨-x, neg_mem _ hx, ((-f).map_neg _).trans (neg_neg (f x))β©β©
@[simp] lemma span_neg (s : set M) : span R (-s) = span R s :=
calc span R (-s) = span R ((-linear_map.id : M ββ[R] M) '' s) : by simp
... = map (-linear_map.id) (span R s) : (map_span _ _).symm
... = span R s : by simp
lemma mem_span_insert' {y} {s : set M} : x β span R (insert y s) β β(a:R), x + a β’ y β span R s :=
begin
rw mem_span_insert, split,
{ rintro β¨a, z, hz, rflβ©, exact β¨-a, by simp [hz, add_assoc]β© },
{ rintro β¨a, hβ©, exact β¨-a, _, h, by simp [add_comm, add_left_comm]β© }
end
-- TODO(Mario): Factor through add_subgroup
/-- The equivalence relation associated to a submodule `p`, defined by `x β y` iff `y - x β p`. -/
def quotient_rel : setoid M :=
β¨Ξ» x y, x - y β p, Ξ» x, by simp,
Ξ» x y h, by simpa using neg_mem _ h,
Ξ» x y z hβ hβ, by simpa [sub_eq_add_neg, add_left_comm, add_assoc] using add_mem _ hβ hββ©
/-- The quotient of a module `M` by a submodule `p β M`. -/
def quotient : Type* := quotient (quotient_rel p)
namespace quotient
/-- Map associating to an element of `M` the corresponding element of `M/p`,
when `p` is a submodule of `M`. -/
def mk {p : submodule R M} : M β quotient p := quotient.mk'
@[simp] theorem mk_eq_mk {p : submodule R M} (x : M) : (quotient.mk x : quotient p) = mk x := rfl
@[simp] theorem mk'_eq_mk {p : submodule R M} (x : M) : (quotient.mk' x : quotient p) = mk x := rfl
@[simp] theorem quot_mk_eq_mk {p : submodule R M} (x : M) : (quot.mk _ x : quotient p) = mk x := rfl
protected theorem eq {x y : M} : (mk x : quotient p) = mk y β x - y β p := quotient.eq'
instance : has_zero (quotient p) := β¨mk 0β©
instance : inhabited (quotient p) := β¨0β©
@[simp] theorem mk_zero : mk 0 = (0 : quotient p) := rfl
@[simp] theorem mk_eq_zero : (mk x : quotient p) = 0 β x β p :=
by simpa using (quotient.eq p : mk x = 0 β _)
instance : has_add (quotient p) :=
β¨Ξ» a b, quotient.lift_onβ' a b (Ξ» a b, mk (a + b)) $
Ξ» aβ aβ bβ bβ hβ hβ, (quotient.eq p).2 $
by simpa [sub_eq_add_neg, add_left_comm, add_comm] using add_mem p hβ hββ©
@[simp] theorem mk_add : (mk (x + y) : quotient p) = mk x + mk y := rfl
instance : has_neg (quotient p) :=
β¨Ξ» a, quotient.lift_on' a (Ξ» a, mk (-a)) $
Ξ» a b h, (quotient.eq p).2 $ by simpa using neg_mem p hβ©
@[simp] theorem mk_neg : (mk (-x) : quotient p) = -mk x := rfl
instance : has_sub (quotient p) :=
β¨Ξ» a b, quotient.lift_onβ' a b (Ξ» a b, mk (a - b)) $
Ξ» aβ aβ bβ bβ hβ hβ, (quotient.eq p).2 $
by simpa [sub_eq_add_neg, add_left_comm, add_comm] using add_mem p hβ (neg_mem p hβ)β©
@[simp] theorem mk_sub : (mk (x - y) : quotient p) = mk x - mk y := rfl
instance : add_comm_group (quotient p) :=
by refine {zero := 0, add := (+), neg := has_neg.neg, sub := has_sub.sub, sub_eq_add_neg := _, ..};
repeat {rintro β¨β©};
simp [-mk_zero, β mk_zero p, -mk_add, β mk_add p, -mk_neg, β mk_neg p, -mk_sub,
β mk_sub p, sub_eq_add_neg];
cc
instance : has_scalar R (quotient p) :=
β¨Ξ» a x, quotient.lift_on' x (Ξ» x, mk (a β’ x)) $
Ξ» x y h, (quotient.eq p).2 $ by simpa [smul_sub] using smul_mem p a hβ©
@[simp] theorem mk_smul : (mk (r β’ x) : quotient p) = r β’ mk x := rfl
instance : semimodule R (quotient p) :=
semimodule.of_core $ by refine {smul := (β’), ..};
repeat {rintro β¨β© <|> intro}; simp [smul_add, add_smul, smul_smul,
-mk_add, (mk_add p).symm, -mk_smul, (mk_smul p).symm]
lemma mk_surjective : function.surjective (@mk _ _ _ _ _ p) :=
by { rintros β¨xβ©, exact β¨x, rflβ© }
lemma nontrivial_of_lt_top (h : p < β€) : nontrivial (p.quotient) :=
begin
obtain β¨x, _, not_mem_sβ© := exists_of_lt h,
refine β¨β¨mk x, 0, _β©β©,
simpa using not_mem_s
end
end quotient
lemma quot_hom_ext β¦f g : quotient p ββ[R] Mββ¦ (h : β x, f (quotient.mk x) = g (quotient.mk x)) :
f = g :=
linear_map.ext $ Ξ» x, quotient.induction_on' x h
end submodule
namespace submodule
variables [field K]
variables [add_comm_group V] [vector_space K V]
variables [add_comm_group Vβ] [vector_space 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_refl _ end
begin rw [map_le_iff_le_comap, β comap_smul f _ a h, β map_le_iff_le_comap], exact le_refl _ 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] [add_comm_monoid M] [add_comm_monoid Mβ] [add_comm_monoid Mβ]
variables [semimodule R M] [semimodule R Mβ] [semimodule R Mβ]
include R
open submodule
/-- If two linear maps are equal on a set `s`, then they are equal on `submodule.span s`.
See also `linear_map.eq_on_span'` for a version using `set.eq_on`. -/
lemma eq_on_span {s : set M} {f g : M ββ[R] Mβ} (H : set.eq_on f g s) β¦xβ¦ (h : x β span R s) :
f x = g x :=
by apply span_induction h H; simp {contextual := tt}
/-- If two linear maps are equal on a set `s`, then they are equal on `submodule.span s`.
This version uses `set.eq_on`, and the hidden argument will expand to `h : x β (span R s : set M)`.
See `linear_map.eq_on_span` for a version that takes `h : x β span R s` as an argument. -/
lemma eq_on_span' {s : set M} {f g : M ββ[R] Mβ} (H : set.eq_on f g s) :
set.eq_on f g (span R s : set M) :=
eq_on_span H
/-- If `s` generates the whole semimodule and linear maps `f`, `g` are equal on `s`, then they are
equal. -/
lemma ext_on {s : set M} {f g : M ββ[R] Mβ} (hv : span R s = β€) (h : set.eq_on f g s) :
f = g :=
linear_map.ext (Ξ» x, eq_on_span h (eq_top_iff'.1 hv _))
/-- If the range of `v : ΞΉ β M` generates the whole semimodule and linear maps `f`, `g` are equal at
each `v i`, then they are equal. -/
lemma ext_on_range {v : ΞΉ β M} {f g : M ββ[R] Mβ} (hv : span R (set.range v) = β€)
(h : βi, f (v i) = g (v i)) : f = g :=
ext_on hv (set.forall_range_iff.2 h)
section finsupp
variables {Ξ³ : Type*} [has_zero Ξ³]
@[simp] lemma map_finsupp_sum (f : M ββ[R] 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 ββ[R] Mβ) :
β(t.sum g) = t.sum (Ξ» i d, g i d) := coe_fn_sum _ _
@[simp] lemma finsupp_sum_apply (t : ΞΉ ββ Ξ³) (g : ΞΉ β Ξ³ β M ββ[R] Mβ) (b : M) :
(t.sum g) b = t.sum (Ξ» i d, g i d b) := sum_apply _ _ _
end finsupp
section dfinsupp
variables {Ξ³ : ΞΉ β Type*} [decidable_eq ΞΉ] [Ξ i, has_zero (Ξ³ i)] [Ξ i (x : Ξ³ i), decidable (x β 0)]
@[simp] lemma map_dfinsupp_sum (f : M ββ[R] 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 ββ[R] 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 ββ[R] Mβ) (b : M) :
(t.sum g) b = t.sum (Ξ» i d, g i d b) := sum_apply _ _ _
end dfinsupp
theorem map_cod_restrict (p : submodule R M) (f : Mβ ββ[R] 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β ββ[R] 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β©
/-- The range of a linear map `f : M β Mβ` is a submodule of `Mβ`. -/
def range (f : M ββ[R] Mβ) : submodule R Mβ := map f β€
theorem range_coe (f : M ββ[R] Mβ) : (range f : set Mβ) = set.range f := set.image_univ
@[simp] theorem mem_range {f : M ββ[R] Mβ} : β {x}, x β range f β β y, f y = x :=
set.ext_iff.1 (range_coe f)
theorem mem_range_self (f : M ββ[R] Mβ) (x : M) : f x β f.range := mem_range.2 β¨x, rflβ©
@[simp] theorem range_id : range (linear_map.id : M ββ[R] M) = β€ := map_id _
theorem range_comp (f : M ββ[R] Mβ) (g : Mβ ββ[R] Mβ) : range (g.comp f) = map g (range f) :=
map_comp _ _ _
theorem range_comp_le_range (f : M ββ[R] Mβ) (g : Mβ ββ[R] Mβ) : range (g.comp f) β€ range g :=
by rw range_comp; exact map_mono le_top
theorem range_eq_top {f : M ββ[R] Mβ} : range f = β€ β surjective f :=
by rw [submodule.ext'_iff, range_coe, top_coe, set.range_iff_surjective]
lemma range_le_iff_comap {f : M ββ[R] Mβ} {p : submodule R Mβ} : range f β€ p β comap f p = β€ :=
by rw [range, map_le_iff_le_comap, eq_top_iff]
lemma map_le_range {f : M ββ[R] Mβ} {p : submodule R M} : map f p β€ range f :=
map_mono le_top
/-- Restrict the codomain of a linear map `f` to `f.range`.
This is the bundled version of `set.range_factorization`. -/
@[reducible] def range_restrict (f : M ββ[R] Mβ) : M ββ[R] f.range :=
f.cod_restrict f.range f.mem_range_self
section
variables (R) (M)
/-- Given an element `x` of a module `M` over `R`, the natural map from
`R` to scalar multiples of `x`.-/
def to_span_singleton (x : M) : R ββ[R] M := linear_map.id.smul_right x
/-- The range of `to_span_singleton x` is the span of `x`.-/
lemma span_singleton_eq_range (x : M) : (R β x) = (to_span_singleton R M x).range :=
submodule.ext $ Ξ» y, by {refine iff.trans _ mem_range.symm, exact mem_span_singleton }
lemma to_span_singleton_one (x : M) : to_span_singleton R M x 1 = x := one_smul _ _
end
/-- 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 ββ[R] Mβ) : submodule R M := comap f β₯
@[simp] theorem mem_ker {f : M ββ[R] 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 ββ[R] Mβ) (x : ker f) : f x = 0 := mem_ker.1 x.2
lemma comp_ker_subtype (f : M ββ[R] 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 ββ[R] Mβ) (g : Mβ ββ[R] Mβ) : ker (g.comp f) = comap f (ker g) := rfl
theorem ker_le_ker_comp (f : M ββ[R] Mβ) (g : Mβ ββ[R] Mβ) : ker f β€ ker (g.comp f) :=
by rw ker_comp; exact comap_mono bot_le
theorem disjoint_ker {f : M ββ[R] 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 ββ[R] Mβ} :
ker f = β₯ β (β m, f m = 0 β m = 0) :=
by simpa [disjoint] using @disjoint_ker _ _ _ _ _ _ _ _ f β€
theorem ker_eq_bot_of_inverse {f : M ββ[R] Mβ} {g : Mβ ββ[R] M} (h : g.comp f = 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 {f : M ββ[R] 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 (p : submodule R M) (f : Mβ ββ[R] M) (hf) :
ker (cod_restrict p f hf) = ker f :=
by rw [ker, comap_cod_restrict, map_bot]; refl
lemma range_cod_restrict (p : submodule R M) (f : Mβ ββ[R] M) (hf) :
range (cod_restrict p f hf) = comap p.subtype f.range :=
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 map_comap_eq (f : M ββ[R] Mβ) (q : submodule R Mβ) :
map f (comap f q) = range f β q :=
le_antisymm (le_inf (map_mono le_top) (map_comap_le _ _)) $
by rintro _ β¨β¨x, _, rflβ©, hxβ©; exact β¨x, hx, rflβ©
lemma map_comap_eq_self {f : M ββ[R] Mβ} {q : submodule R Mβ} (h : q β€ range f) :
map f (comap f q) = q :=
by rwa [map_comap_eq, inf_eq_right]
@[simp] theorem ker_zero : ker (0 : M ββ[R] Mβ) = β€ :=
eq_top_iff'.2 $ Ξ» x, by simp
@[simp] theorem range_zero : range (0 : M ββ[R] Mβ) = β₯ :=
submodule.map_zero _
theorem ker_eq_top {f : M ββ[R] Mβ} : ker f = β€ β f = 0 :=
β¨Ξ» h, ext $ Ξ» x, mem_ker.1 $ h.symm βΈ trivial, Ξ» h, h.symm βΈ ker_zeroβ©
lemma range_le_bot_iff (f : M ββ[R] Mβ) : range f β€ β₯ β f = 0 :=
by rw [range_le_iff_comap]; exact ker_eq_top
theorem range_eq_bot {f : M ββ[R] Mβ} : range f = β₯ β f = 0 :=
by rw [β range_le_bot_iff, le_bot_iff]
lemma range_le_ker_iff {f : M ββ[R] Mβ} {g : Mβ ββ[R] Mβ} : range f β€ ker g β g.comp f = 0 :=
β¨Ξ» h, ker_eq_top.1 $ eq_top_iff'.2 $ Ξ» x, h $ mem_map_of_mem trivial,
Ξ» 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 ββ[R] 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 ββ[R] 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))
theorem ker_eq_bot_of_injective {f : M ββ[R] 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
end add_comm_monoid
section add_comm_group
variables [semiring R] [add_comm_group M] [add_comm_group Mβ] [add_comm_group Mβ]
variables [semimodule R M] [semimodule R Mβ] [semimodule R Mβ]
include R
open submodule
lemma comap_map_eq (f : M ββ[R] Mβ) (p : submodule R M) :
comap f (map f p) = p β ker f :=
begin
refine le_antisymm _ (sup_le (le_comap_map _ _) (comap_mono bot_le)),
rintro x β¨y, hy, eβ©,
exact mem_sup.2 β¨y, hy, x - y, by simpa using sub_eq_zero.2 e.symm, by simpβ©
end
lemma comap_map_eq_self {f : M ββ[R] Mβ} {p : submodule R M} (h : ker f β€ p) :
comap f (map f p) = p :=
by rw [comap_map_eq, sup_of_le_left h]
theorem map_le_map_iff (f : M ββ[R] Mβ) {p p'} : map f p β€ map f p' β p β€ p' β ker f :=
by rw [map_le_iff_le_comap, comap_map_eq]
theorem map_le_map_iff' {f : M ββ[R] Mβ} (hf : ker f = β₯) {p p'} : map f p β€ map f p' β p β€ p' :=
by rw [map_le_map_iff, hf, sup_bot_eq]
theorem map_injective {f : M ββ[R] Mβ} (hf : ker f = β₯) : injective (map f) :=
Ξ» p p' h, le_antisymm ((map_le_map_iff' hf).1 (le_of_eq h)) ((map_le_map_iff' hf).1 (ge_of_eq h))
theorem map_eq_top_iff {f : M ββ[R] Mβ} (hf : range f = β€) {p : submodule R M} :
p.map f = β€ β p β f.ker = β€ :=
by simp_rw [β top_le_iff, β hf, range, map_le_map_iff]
end add_comm_group
section ring
variables [ring R] [add_comm_group M] [add_comm_group Mβ] [add_comm_group Mβ]
variables [semimodule R M] [semimodule R Mβ] [semimodule R Mβ]
variables {f : M ββ[R] Mβ}
include R
open submodule
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 y hx hy h, eq_of_sub_eq_zero $ H _ (sub_mem _ hx hy) (by simp [h]),
Ξ» H x hβ hβ, H x 0 hβ (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 y hx 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 {p : submodule R M} : ker f β€ p β β (y β range f), f β»ΒΉ' {y} β p :=
begin
split,
{ intros h, use 0, rw [β mem_coe, f.range_coe], exact β¨β¨0, map_zero fβ©, hβ©, },
{ rintros β¨y, hβ, hββ©,
rw le_def, intros z hz, simp only [mem_ker, mem_coe] at hz,
rw [β 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]
variables [add_comm_group V] [vector_space K V]
variables [add_comm_group Vβ] [vector_space 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 :=
submodule.map_smul f _ a h
lemma range_smul' (f : V ββ[K] Vβ) (a : K) : range (a β’ f) = β¨(h : a β 0), range f :=
submodule.map_smul' f _ a
lemma span_singleton_sup_ker_eq_top (f : V ββ[K] K) {x : V} (hx : f x β 0) :
(K β x) β f.ker = β€ :=
eq_top_iff.2 (Ξ» y hy, submodule.mem_sup.2 β¨(f y * (f x)β»ΒΉ) β’ x,
submodule.mem_span_singleton.2 β¨f y * (f x)β»ΒΉ, rflβ©,
β¨y - (f y * (f x)β»ΒΉ) β’ x,
by rw [linear_map.mem_ker, f.map_sub, f.map_smul, smul_eq_mul, mul_assoc,
inv_mul_cancel hx, mul_one, sub_self],
by simp only [add_sub_cancel'_right]β©β©)
end field
end linear_map
namespace is_linear_map
lemma is_linear_map_add [semiring R] [add_comm_monoid M] [semimodule 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] [semimodule 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 {T : semiring R} [add_comm_monoid M] [add_comm_monoid Mβ]
variables [semimodule R M] [semimodule R Mβ]
variables (p p' : submodule R M) (q : submodule R Mβ)
include T
open linear_map
@[simp] theorem map_top (f : M ββ[R] Mβ) : map f β€ = range f := rfl
@[simp] theorem comap_bot (f : M ββ[R] 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_mono le_top : 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_refl _)
@[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]
end add_comm_monoid
section ring
variables {T : ring R} [add_comm_group M] [add_comm_group Mβ] [semimodule R M] [semimodule R Mβ]
variables (p p' : submodule R M) (q : submodule R Mβ)
include T
open linear_map
lemma disjoint_iff_comap_eq_bot {p q : submodule R M} :
disjoint p q β comap p.subtype q = β₯ :=
by rw [eq_bot_iff, β map_le_map_iff' p.ker_subtype, map_bot, map_comap_subtype, disjoint]
/-- 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_self $ by simp,
right_inv := Ξ» β¨q, hqβ©, subtype.ext_val $ by simp [map_comap_subtype p, inf_of_le_right hq],
map_rel_iff' := Ξ» pβ pβ, map_le_map_iff' (ker_subtype p) }
/-- 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
/-- The map from a module `M` to the quotient of `M` by a submodule `p` as a linear map. -/
def mkq : M ββ[R] p.quotient := β¨quotient.mk, by simp, by simpβ©
@[simp] theorem mkq_apply (x : M) : p.mkq x = quotient.mk x := rfl
/-- The map from the quotient of `M` by a submodule `p` to `Mβ` induced by a linear map `f : M β Mβ`
vanishing on `p`, as a linear map. -/
def liftq (f : M ββ[R] Mβ) (h : p β€ f.ker) : p.quotient ββ[R] Mβ :=
β¨Ξ» x, _root_.quotient.lift_on' x f $
Ξ» a b (ab : a - b β p), eq_of_sub_eq_zero $ by simpa using h ab,
by rintro β¨xβ© β¨yβ©; exact f.map_add x y,
by rintro a β¨xβ©; exact f.map_smul a xβ©
@[simp] theorem liftq_apply (f : M ββ[R] Mβ) {h} (x : M) :
p.liftq f h (quotient.mk x) = f x := rfl
@[simp] theorem liftq_mkq (f : M ββ[R] Mβ) (h) : (p.liftq f h).comp p.mkq = f :=
by ext; refl
@[simp] theorem range_mkq : p.mkq.range = β€ :=
eq_top_iff'.2 $ by rintro β¨xβ©; exact β¨x, trivial, rflβ©
@[simp] theorem ker_mkq : p.mkq.ker = p :=
by ext; simp
lemma le_comap_mkq (p' : submodule R p.quotient) : p β€ comap p.mkq p' :=
by simpa using (comap_mono bot_le : p.mkq.ker β€ comap p.mkq p')
@[simp] theorem mkq_map_self : map p.mkq p = β₯ :=
by rw [eq_bot_iff, map_le_iff_le_comap, comap_bot, ker_mkq]; exact le_refl _
@[simp] theorem comap_map_mkq : comap p.mkq (map p.mkq p') = p β p' :=
by simp [comap_map_eq, sup_comm]
@[simp] theorem map_mkq_eq_top : map p.mkq p' = β€ β p β p' = β€ :=
by simp only [map_eq_top_iff p.range_mkq, sup_comm, ker_mkq]
/-- The map from the quotient of `M` by submodule `p` to the quotient of `Mβ` by submodule `q` along
`f : M β Mβ` is linear. -/
def mapq (f : M ββ[R] Mβ) (h : p β€ comap f q) : p.quotient ββ[R] q.quotient :=
p.liftq (q.mkq.comp f) $ by simpa [ker_comp] using h
@[simp] theorem mapq_apply (f : M ββ[R] Mβ) {h} (x : M) :
mapq p q f h (quotient.mk x) = quotient.mk (f x) := rfl
theorem mapq_mkq (f : M ββ[R] Mβ) {h} : (mapq p q f h).comp p.mkq = q.mkq.comp f :=
by ext x; refl
theorem comap_liftq (f : M ββ[R] Mβ) (h) :
q.comap (p.liftq f h) = (q.comap f).map (mkq p) :=
le_antisymm
(by rintro β¨xβ© hx; exact β¨_, hx, rflβ©)
(by rw [map_le_iff_le_comap, β comap_comp, liftq_mkq]; exact le_refl _)
theorem map_liftq (f : M ββ[R] Mβ) (h) (q : submodule R (quotient p)) :
q.map (p.liftq f h) = (q.comap p.mkq).map f :=
le_antisymm
(by rintro _ β¨β¨xβ©, hxq, rflβ©; exact β¨x, hxq, rflβ©)
(by rintro _ β¨x, hxq, rflβ©; exact β¨quotient.mk x, hxq, rflβ©)
theorem ker_liftq (f : M ββ[R] Mβ) (h) :
ker (p.liftq f h) = (ker f).map (mkq p) := comap_liftq _ _ _ _
theorem range_liftq (f : M ββ[R] Mβ) (h) :
range (p.liftq f h) = range f := map_liftq _ _ _ _
theorem ker_liftq_eq_bot (f : M ββ[R] Mβ) (h) (h' : ker f β€ p) : ker (p.liftq f h) = β₯ :=
by rw [ker_liftq, le_antisymm h h', mkq_map_self]
/-- The correspondence theorem for modules: there is an order isomorphism between submodules of the
quotient of `M` by `p`, and submodules of `M` larger than `p`. -/
def comap_mkq.rel_iso :
submodule R p.quotient βo {p' : submodule R M // p β€ p'} :=
{ to_fun := Ξ» p', β¨comap p.mkq p', le_comap_mkq p _β©,
inv_fun := Ξ» q, map p.mkq q,
left_inv := Ξ» p', map_comap_eq_self $ by simp,
right_inv := Ξ» β¨q, hqβ©, subtype.ext_val $ by simpa [comap_map_mkq p],
map_rel_iff' := Ξ» pβ pβ, comap_le_comap_iff $ range_mkq _ }
/-- The ordering on submodules of the quotient of `M` by `p` embeds into the ordering on submodules
of `M`. -/
def comap_mkq.order_embedding :
submodule R p.quotient βͺo submodule R M :=
(rel_iso.to_rel_embedding $ comap_mkq.rel_iso p).trans (subtype.rel_embedding _ _)
@[simp] lemma comap_mkq_embedding_eq (p' : submodule R p.quotient) :
comap_mkq.order_embedding p p' = comap p.mkq p' := rfl
lemma span_preimage_eq {f : M ββ[R] Mβ} {s : set Mβ} (hβ : s.nonempty) (hβ : s β range f) :
span R (f β»ΒΉ' s) = (span R s).comap f :=
begin
suffices : (span R s).comap f β€ span R (f β»ΒΉ' s),
{ exact le_antisymm (span_preimage_le f s) this, },
have hk : ker f β€ span R (f β»ΒΉ' s),
{ let y := classical.some hβ, have hy : y β s, { exact classical.some_spec hβ, },
rw ker_le_iff, use [y, hβ hy], rw β set.singleton_subset_iff at hy,
exact set.subset.trans subset_span (span_mono (set.preimage_mono hy)), },
rw β left_eq_sup at hk, rw f.range_coe at hβ,
rw [hk, β map_le_map_iff, map_span, map_comap_eq, set.image_preimage_eq_of_subset hβ],
exact inf_le_right,
end
end ring
end submodule
namespace linear_map
variables [ring R] [add_comm_group M] [add_comm_group Mβ] [add_comm_group Mβ]
variables [module R M] [module R Mβ] [module R Mβ]
lemma range_mkq_comp (f : M ββ[R] Mβ) : f.range.mkq.comp f = 0 :=
linear_map.ext $ Ξ» x, by simp
lemma ker_le_range_iff {f : M ββ[R] Mβ} {g : Mβ ββ[R] Mβ} :
g.ker β€ f.range β f.range.mkq.comp g.ker.subtype = 0 :=
by rw [βrange_le_ker_iff, submodule.ker_mkq, submodule.range_subtype]
/-- A monomorphism is injective. -/
lemma ker_eq_bot_of_cancel {f : M ββ[R] 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
/-- An epimorphism is surjective. -/
lemma range_eq_top_of_cancel {f : M ββ[R] Mβ}
(h : β (u v : Mβ ββ[R] f.range.quotient), u.comp f = v.comp f β u = v) : f.range = β€ :=
begin
have hβ : (0 : Mβ ββ[R] f.range.quotient).comp f = 0 := zero_comp _,
rw [βsubmodule.ker_mkq f.range, βh 0 f.range.mkq (eq.trans hβ (range_mkq_comp _).symm)],
exact ker_zero
end
end linear_map
@[simp] lemma linear_map.range_range_restrict [semiring R] [add_comm_monoid M] [add_comm_monoid Mβ]
[semimodule R M] [semimodule 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
variables [semiring R] [add_comm_monoid M] [add_comm_monoid Mβ]
[add_comm_monoid Mβ] [add_comm_monoid Mβ]
section
variables {semimodule_M : semimodule R M} {semimodule_Mβ : semimodule R Mβ}
variables (e e' : M ββ[R] Mβ)
lemma map_eq_comap {p : submodule R M} : (p.map e : submodule R Mβ) = p.comap e.symm :=
submodule.coe_injective $ by simp [e.image_eq_preimage]
/-- A linear equivalence of two modules restricts to a linear equivalence from any submodule
of the domain onto the image of the submodule. -/
def of_submodule (p : submodule R M) : p ββ[R] β₯(p.map βe : submodule R Mβ) :=
{ inv_fun := Ξ» y, β¨e.symm 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,
right_inv := Ξ» y, by { apply set_coe.ext, simp, },
..((e : M ββ[R] Mβ).dom_restrict p).cod_restrict (p.map βe) (Ξ» x, β¨x, by simpβ©) }
@[simp] lemma of_submodule_apply (p : submodule R M) (x : p) :
β(e.of_submodule p x) = e x := rfl
@[simp] lemma of_submodule_symm_apply (p : submodule R M) (x : (p.map βe : submodule R Mβ)) :
β((e.of_submodule p).symm x) = e.symm x := rfl
end
section uncurry
variables (V Vβ R)
/-- Linear equivalence between a curried and uncurried function.
Differs from `tensor_product.curry`. -/
protected def uncurry :
(V β Vβ β R) ββ[R] (V Γ Vβ β R) :=
{ map_add' := Ξ» _ _, by { ext β¨β©, refl },
map_smul' := Ξ» _ _, by { ext β¨β©, refl },
.. equiv.arrow_arrow_equiv_prod_arrow _ _ _}
@[simp] lemma coe_uncurry : β(linear_equiv.uncurry R V Vβ) = uncurry := rfl
@[simp] lemma coe_uncurry_symm : β(linear_equiv.uncurry R V Vβ).symm = curry := rfl
end uncurry
section
variables {semimodule_M : semimodule R M} {semimodule_Mβ : semimodule R Mβ}
variables (f : M ββ[R] Mβ) (g : Mβ ββ[R] M) (e : M ββ[R] 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
/-- 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 = q) : p ββ[R] q :=
(e.of_submodule 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
variable (p)
/-- 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
/-- 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 ββ[R] Mβ :=
{ inv_fun := g,
left_inv := linear_map.ext_iff.1 hβ,
right_inv := linear_map.ext_iff.1 hβ,
..f }
@[simp] theorem of_linear_apply {hβ hβ} (x : M) : of_linear f g hβ hβ x = f x := rfl
@[simp] theorem of_linear_symm_apply {hβ hβ} (x : Mβ) : (of_linear f g hβ hβ).symm x = g x := rfl
@[simp] protected theorem range : (e : M ββ[R] Mβ).range = β€ :=
linear_map.range_eq_top.2 e.to_equiv.surjective
lemma eq_bot_of_equiv [semimodule R Mβ] (e : p ββ[R] (β₯ : submodule R Mβ)) : p = β₯ :=
begin
refine bot_unique (submodule.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
@[simp] protected theorem ker : (e : M ββ[R] Mβ).ker = β₯ :=
linear_map.ker_eq_bot_of_injective e.to_equiv.injective
variables {f g}
/-- 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 {g : Mβ β M} (h : function.left_inverse g f) : M ββ[R] 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 }
@[simp] lemma of_left_inverse_apply
(h : function.left_inverse g f) (x : M) :
β(of_left_inverse h x) = f x := rfl
@[simp] lemma of_left_inverse_symm_apply
(h : function.left_inverse g f) (x : f.range) :
(of_left_inverse h).symm x = g x := rfl
end
end add_comm_monoid
section add_comm_group
variables [semiring R]
variables [add_comm_group M] [add_comm_group Mβ] [add_comm_group Mβ] [add_comm_group Mβ]
variables {semimodule_M : semimodule R M} {semimodule_Mβ : semimodule R Mβ}
variables {semimodule_Mβ : semimodule R Mβ} {semimodule_Mβ : semimodule R Mβ}
variables (e eβ : M ββ[R] Mβ) (eβ : Mβ ββ[R] 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] [semimodule 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 ring
variables [ring R] [add_comm_group M] [add_comm_group Mβ]
variables {semimodule_M : semimodule R M} {semimodule_Mβ : semimodule R Mβ}
variables (f : M ββ[R] Mβ) (e : M ββ[R] Mβ)
/-- 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 (h : f.ker = β₯) : M ββ[R] f.range :=
of_left_inverse $ classical.some_spec (linear_map.ker_eq_bot.1 h).has_left_inverse
@[simp] theorem of_injective_apply {h : f.ker = β₯} (x : M) :
β(of_injective f h x) = f x := rfl
/-- A bijective linear map is a linear equivalence. Here, bijectivity is described by saying that
the kernel of `f` is `{0}` and the range is the universal set. -/
noncomputable def of_bijective (hfβ : f.ker = β₯) (hfβ : f.range = β€) : M ββ[R] Mβ :=
(of_injective f hfβ).trans (of_top _ hfβ)
@[simp] theorem of_bijective_apply {hfβ hfβ} (x : M) :
of_bijective f hfβ hfβ x = f x := rfl
end ring
section comm_ring
variables [comm_ring R] [add_comm_group M] [add_comm_group Mβ] [add_comm_group Mβ]
variables [semimodule R M] [semimodule R Mβ] [semimodule R Mβ]
open linear_map
/-- Multiplying by a unit `a` of the ring `R` is a linear equivalence. -/
def smul_of_unit (a : units R) : M ββ[R] M :=
of_linear ((a:R) β’ 1 : M ββ M) (((aβ»ΒΉ : units R) : R) β’ 1 : M ββ M)
(by rw [smul_comp, comp_smul, smul_smul, units.mul_inv, one_smul]; refl)
(by rw [smul_comp, comp_smul, smul_smul, units.inv_mul, one_smul]; refl)
/-- 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_ring R]
[add_comm_group Mβ] [add_comm_group Mβ] [add_comm_group Mββ] [add_comm_group 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, (eβ : Mββ ββ[R] Mββ).comp $ f.comp eβ.symm,
inv_fun := Ξ» f, (eβ.symm : Mββ ββ[R] Mββ).comp $ f.comp eβ,
left_inv := Ξ» f, by { ext x, simp },
right_inv := Ξ» f, by { ext x, simp },
map_add' := Ξ» f g, by { ext x, simp },
map_smul' := Ξ» c f, by { ext x, simp } }
@[simp] lemma arrow_congr_apply {R Mβ Mβ Mββ Mββ : Sort*} [comm_ring R]
[add_comm_group Mβ] [add_comm_group Mβ] [add_comm_group Mββ] [add_comm_group 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_ring R]
[add_comm_group Mβ] [add_comm_group Mβ] [add_comm_group Mββ] [add_comm_group 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_group N] [add_comm_group Nβ] [add_comm_group 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_group Mβ] [module R Mβ] [add_comm_group Mβ] [module R Mβ]
[add_comm_group Mβ] [module R Mβ] [add_comm_group Nβ] [module R Nβ]
[add_comm_group Nβ] [module R Nβ] [add_comm_group 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β) ββ (M ββ 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 := 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 := 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_ring
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 linear_map
/-- Multiplying by a nonzero element `a` of the field `K` is a linear equivalence. -/
def smul_of_ne_zero (a : K) (ha : a β 0) : M ββ[K] M :=
smul_of_unit $ units.mk0 a ha
section
noncomputable theory
open_locale classical
lemma ker_to_span_singleton {x : M} (h : x β 0) : (to_span_singleton K M x).ker = β₯ :=
begin
ext c, split,
{ intros hc, rw submodule.mem_bot, rw mem_ker at hc, by_contra hc',
have : x = 0,
calc x = cβ»ΒΉ β’ (c β’ x) : by rw [β mul_smul, inv_mul_cancel hc', one_smul]
... = cβ»ΒΉ β’ ((to_span_singleton K M x) c) : rfl
... = 0 : by rw [hc, smul_zero],
tauto },
{ rw [mem_ker, submodule.mem_bot], intros h, rw h, simp }
end
/-- Given a nonzero element `x` of a vector space `M` over a field `K`, the natural
map from `K` to the span of `x`, with invertibility check to consider it as an
isomorphism.-/
def to_span_nonzero_singleton (x : M) (h : x β 0) : K ββ[K] (K β x) :=
linear_equiv.trans
(linear_equiv.of_injective (to_span_singleton K M x) (ker_to_span_singleton K M h))
(of_eq (to_span_singleton K M x).range (K β x)
(span_singleton_eq_range K M x).symm)
lemma to_span_nonzero_singleton_one (x : M) (h : x β 0) : to_span_nonzero_singleton K M x h 1
= (β¨x, submodule.mem_span_singleton_self xβ© : K β x) :=
begin
apply submodule.coe_eq_coe.mp,
have : β(to_span_nonzero_singleton K M x h 1) = to_span_singleton K M x 1 := rfl,
rw [this, to_span_singleton_one, submodule.coe_mk],
end
/-- Given a nonzero element `x` of a vector space `M` over a field `K`, the natural map
from the span of `x` to `K`.-/
abbreviation coord (x : M) (h : x β 0) : (K β x) ββ[K] K :=
(to_span_nonzero_singleton K M x h).symm
lemma coord_self (x : M) (h : x β 0) :
(coord K M x h) (β¨x, submodule.mem_span_singleton_self xβ© : K β x) = 1 :=
by rw [β to_span_nonzero_singleton_one K M x h, symm_apply_apply]
end
end field
end linear_equiv
namespace submodule
section semimodule
variables [semiring R] [add_comm_monoid M] [semimodule R M]
/-- If `s β€ t`, then we can view `s` as a submodule of `t` by taking the comap
of `t.subtype`. -/
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, submodule.eta, coe_coe],
right_inv := Ξ» x, by simp only [subtype.coe_mk, submodule.eta, coe_coe],
map_add' := Ξ» x y, rfl,
map_smul' := Ξ» c x, rfl }
end semimodule
variables [ring R] [add_comm_group M] [module R M]
variables (p : submodule R M)
open linear_map
/-- If `p = β₯`, then `M / p ββ[R] M`. -/
def quot_equiv_of_eq_bot (hp : p = β₯) : p.quotient ββ[R] M :=
linear_equiv.of_linear (p.liftq id $ hp.symm βΈ bot_le) p.mkq (liftq_mkq _ _ _) $
p.quot_hom_ext $ Ξ» x, rfl
@[simp] lemma quot_equiv_of_eq_bot_apply_mk (hp : p = β₯) (x : M) :
p.quot_equiv_of_eq_bot hp (quotient.mk x) = x := rfl
@[simp] lemma quot_equiv_of_eq_bot_symm_apply (hp : p = β₯) (x : M) :
(p.quot_equiv_of_eq_bot hp).symm x = quotient.mk x := rfl
@[simp] lemma coe_quot_equiv_of_eq_bot_symm (hp : p = β₯) :
((p.quot_equiv_of_eq_bot hp).symm : M ββ[R] p.quotient) = p.mkq := rfl
variables (q : submodule R M)
/-- Quotienting by equal submodules gives linearly equivalent quotients. -/
def quot_equiv_of_eq (h : p = q) : p.quotient ββ[R] q.quotient :=
{ map_add' := by { rintros β¨xβ© β¨yβ©, refl }, map_smul' := by { rintros x β¨yβ©, refl },
..@quotient.congr _ _ (quotient_rel p) (quotient_rel q) (equiv.refl _) $
Ξ» a b, by { subst h, refl } }
end submodule
namespace submodule
variables [comm_ring R] [add_comm_group M] [add_comm_group Mβ] [module R M] [module R Mβ]
variables (p : submodule R M) (q : submodule R Mβ)
@[simp] lemma mem_map_equiv {e : M ββ[R] Mβ} {x : Mβ} : x β p.map (e : M ββ[R] 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
lemma comap_le_comap_smul (f : M ββ[R] Mβ) (c : R) :
comap f q β€ comap (c β’ f) q :=
begin
rw 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 ββ[R] Mβ) :
comap fβ q β comap fβ q β€ comap (fβ + fβ) q :=
begin
rw 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 (M ββ[R] Mβ) :=
{ 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), }
/-- Given modules `M`, `Mβ` over a commutative ring, together with submodules `p β M`, `q β Mβ`, the
natural map $\{f β Hom(M, Mβ) | f(p) β q \} \to Hom(M/p, Mβ/q)$ is linear. -/
def mapq_linear : compatible_maps p q ββ[R] p.quotient ββ[R] q.quotient :=
{ to_fun := Ξ» f, mapq _ _ f.val f.property,
map_add' := Ξ» x y, by { ext m', apply quotient.induction_on' m', intros m, refl, },
map_smul' := Ξ» c f, by { ext m', apply quotient.induction_on' m', intros m, refl, } }
end submodule
namespace equiv
variables [semiring R] [add_comm_monoid M] [semimodule R M] [add_comm_monoid Mβ] [semimodule 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
namespace add_equiv
variables [semiring R] [add_comm_monoid M] [semimodule R M] [add_comm_monoid Mβ] [semimodule R Mβ]
/-- An additive equivalence whose underlying function preserves `smul` is a linear equivalence. -/
def to_linear_equiv (e : M β+ Mβ) (h : β (c : R) x, e (c β’ x) = c β’ e x) : M ββ[R] Mβ :=
{ map_smul' := h, .. e, }
@[simp] lemma coe_to_linear_equiv (e : M β+ Mβ) (h : β (c : R) x, e (c β’ x) = c β’ e x) :
β(e.to_linear_equiv h) = e :=
rfl
@[simp] lemma coe_to_linear_equiv_symm (e : M β+ Mβ) (h : β (c : R) x, e (c β’ x) = c β’ e x) :
β(e.to_linear_equiv h).symm = e.symm :=
rfl
end add_equiv
namespace linear_map
open submodule
section isomorphism_laws
variables [ring R] [add_comm_group M] [add_comm_group Mβ] [add_comm_group Mβ]
variables [module R M] [module R Mβ] [module R Mβ]
variables (f : M ββ[R] Mβ)
/-- The first isomorphism law for modules. The quotient of `M` by the kernel of `f` is linearly
equivalent to the range of `f`. -/
noncomputable def quot_ker_equiv_range : f.ker.quotient ββ[R] f.range :=
(linear_equiv.of_injective (f.ker.liftq f $ le_refl _) $
submodule.ker_liftq_eq_bot _ _ _ (le_refl f.ker)).trans
(linear_equiv.of_eq _ _ $ submodule.range_liftq _ _ _)
/-- The first isomorphism theorem for surjective linear maps. -/
noncomputable def quot_ker_equiv_of_surjective
(f : M ββ[R] Mβ) (hf : function.surjective f) : f.ker.quotient ββ[R] Mβ :=
f.quot_ker_equiv_range.trans
(linear_equiv.of_top f.range (linear_map.range_eq_top.2 hf))
@[simp] lemma quot_ker_equiv_range_apply_mk (x : M) :
(f.quot_ker_equiv_range (submodule.quotient.mk x) : Mβ) = f x :=
rfl
@[simp] lemma quot_ker_equiv_range_symm_apply_image (x : M) (h : f x β f.range) :
f.quot_ker_equiv_range.symm β¨f x, hβ© = f.ker.mkq x :=
f.quot_ker_equiv_range.symm_apply_apply (f.ker.mkq x)
/--
Canonical linear map from the quotient `p/(p β© p')` to `(p+p')/p'`, mapping `x + (p β© p')`
to `x + p'`, where `p` and `p'` are submodules of an ambient module.
-/
def quotient_inf_to_sup_quotient (p p' : submodule R M) :
(comap p.subtype (p β p')).quotient ββ[R] (comap (p β p').subtype p').quotient :=
(comap p.subtype (p β p')).liftq
((comap (p β p').subtype p').mkq.comp (of_le le_sup_left)) begin
rw [ker_comp, of_le, comap_cod_restrict, ker_mkq, map_comap_subtype],
exact comap_mono (inf_le_inf_right _ le_sup_left) end
/--
Second Isomorphism Law : the canonical map from `p/(p β© p')` to `(p+p')/p'` as a linear isomorphism.
-/
noncomputable def quotient_inf_equiv_sup_quotient (p p' : submodule R M) :
(comap p.subtype (p β p')).quotient ββ[R] (comap (p β p').subtype p').quotient :=
linear_equiv.of_bijective (quotient_inf_to_sup_quotient p p')
begin
rw [quotient_inf_to_sup_quotient, ker_liftq_eq_bot],
rw [ker_comp, ker_mkq],
exact Ξ» β¨x, hx1β© hx2, β¨hx1, hx2β©
end
begin
rw [quotient_inf_to_sup_quotient, range_liftq, eq_top_iff'],
rintros β¨x, hxβ©, rcases mem_sup.1 hx with β¨y, hy, z, hz, rflβ©,
use [β¨y, hyβ©, trivial], apply (submodule.quotient.eq _).2,
change y - (y + z) β p',
rwa [sub_add_eq_sub_sub, sub_self, zero_sub, neg_mem_iff]
end
@[simp] lemma coe_quotient_inf_to_sup_quotient (p p' : submodule R M) :
β(quotient_inf_to_sup_quotient p p') = quotient_inf_equiv_sup_quotient p p' := rfl
@[simp] lemma quotient_inf_equiv_sup_quotient_apply_mk (p p' : submodule R M) (x : p) :
quotient_inf_equiv_sup_quotient p p' (submodule.quotient.mk x) =
submodule.quotient.mk (of_le (le_sup_left : p β€ p β p') x) :=
rfl
lemma quotient_inf_equiv_sup_quotient_symm_apply_left (p p' : submodule R M)
(x : p β p') (hx : (x:M) β p) :
(quotient_inf_equiv_sup_quotient p p').symm (submodule.quotient.mk x) =
submodule.quotient.mk β¨x, hxβ© :=
(linear_equiv.symm_apply_eq _).2 $ by simp [of_le_apply]
@[simp] lemma quotient_inf_equiv_sup_quotient_symm_apply_eq_zero_iff {p p' : submodule R M}
{x : p β p'} :
(quotient_inf_equiv_sup_quotient p p').symm (submodule.quotient.mk x) = 0 β (x:M) β p' :=
(linear_equiv.symm_apply_eq _).trans $ by simp [of_le_apply]
lemma quotient_inf_equiv_sup_quotient_symm_apply_right (p p' : submodule R M) {x : p β p'}
(hx : (x:M) β p') :
(quotient_inf_equiv_sup_quotient p p').symm (submodule.quotient.mk x) = 0 :=
quotient_inf_equiv_sup_quotient_symm_apply_eq_zero_iff.2 hx
end isomorphism_laws
section fun_left
variables (R M) [semiring R] [add_comm_monoid M] [semimodule R M]
variables {m n p : Type*}
/-- 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) :=
mk (βf) (Ξ» _ _, rfl) (Ξ» _ _, 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
/-- 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)
(ext $ Ξ» x, funext $ Ξ» i,
by rw [id_apply, β fun_left_comp, equiv.symm_comp_self, fun_left_id])
(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 fun_left
universe i
variables [semiring R] [add_comm_monoid M] [semimodule R M]
variables (R M)
instance automorphism_group : group (M ββ[R] M) :=
{ mul := Ξ» f g, g.trans f,
one := linear_equiv.refl R M,
inv := Ξ» f, f.symm,
mul_assoc := Ξ» f g h, by {ext, refl},
mul_one := Ξ» f, by {ext, refl},
one_mul := Ξ» f, by {ext, refl},
mul_left_inv := Ξ» f, by {ext, exact f.left_inv x} }
instance automorphism_group.to_linear_map_is_monoid_hom :
is_monoid_hom (linear_equiv.to_linear_map : (M ββ[R] M) β (M ββ[R] M)) :=
{ map_one := rfl,
map_mul := Ξ» f g, rfl }
/-- The group of invertible linear maps from `M` to itself -/
@[reducible] def general_linear_group := units (M ββ[R] M)
namespace general_linear_group
variables {R M}
instance : has_coe_to_fun (general_linear_group R 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,
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}
end general_linear_group
end linear_map
namespace submodule
variables [ring R] [add_comm_group M] [module R M]
instance : is_modular_lattice (submodule R M) :=
β¨Ξ» x y z xz a ha, begin
rw [mem_inf, mem_sup] at ha,
rcases ha with β¨β¨b, hb, c, hc, rflβ©, hazβ©,
rw mem_sup,
refine β¨b, hb, c, mem_inf.2 β¨hc, _β©, rflβ©,
rw [β add_sub_cancel c b, add_comm],
apply z.sub_mem haz (xz hb),
endβ©
end submodule
|
ca460af20bb9ed76ae85953ea4dbe59c98067c0d | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/analysis/analytic/radius_liminf.lean | f706addfdb95be0b465a0afacc2246bed0196f53 | [
"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,510 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import analysis.analytic.basic
import analysis.special_functions.pow
/-!
# Representation of `formal_multilinear_series.radius` as a `liminf`
In this file we prove that the radius of convergence of a `formal_multilinear_series` is equal to
$\liminf_{n\to\infty} \frac{1}{\sqrt[n]{βp nβ}}$. This lemma can't go to `basic.lean` because this
would create a circular dependency once we redefine `exp` using `formal_multilinear_series`.
-/
variables {π : Type*} [nontrivially_normed_field π]
{E : Type*} [normed_add_comm_group E] [normed_space π E]
{F : Type*} [normed_add_comm_group F] [normed_space π F]
open_locale topological_space classical big_operators nnreal ennreal
open filter asymptotics
namespace formal_multilinear_series
variables (p : formal_multilinear_series π E F)
/-- The radius of a formal multilinear series is equal to
$\liminf_{n\to\infty} \frac{1}{\sqrt[n]{βp nβ}}$. The actual statement uses `ββ₯0` and some
coercions. -/
lemma radius_eq_liminf : p.radius = liminf (Ξ» n, 1/((βp nββ) ^ (1 / (n : β)) : ββ₯0)) at_top :=
begin
have : β (r : ββ₯0) {n : β}, 0 < n β
((r : ββ₯0β) β€ 1 / β(βp nββ ^ (1 / (n : β))) β βp nββ * r ^ n β€ 1),
{ intros r n hn,
have : 0 < (n : β) := nat.cast_pos.2 hn,
conv_lhs {rw [one_div, ennreal.le_inv_iff_mul_le, β ennreal.coe_mul,
ennreal.coe_le_one_iff, one_div, β nnreal.rpow_one r, β mul_inv_cancel this.ne',
nnreal.rpow_mul, β nnreal.mul_rpow, β nnreal.one_rpow (nβ»ΒΉ),
nnreal.rpow_le_rpow_iff (inv_pos.2 this), mul_comm, nnreal.rpow_nat_cast] } },
apply le_antisymm; refine ennreal.le_of_forall_nnreal_lt (Ξ» r hr, _),
{ rcases ((tfae_exists_lt_is_o_pow (Ξ» n, βp nβ * r ^ n) 1).out 1 7).1 (p.is_o_of_lt_radius hr)
with β¨a, ha, Hβ©,
refine le_Liminf_of_le (by apply_auto_param) (eventually_map.2 $ _),
refine H.mp ((eventually_gt_at_top 0).mono $ Ξ» n hnβ hn, (this _ hnβ).2
(nnreal.coe_le_coe.1 _)),
push_cast,
exact (le_abs_self _).trans (hn.trans (pow_le_one _ ha.1.le ha.2.le)) },
{ refine p.le_radius_of_is_O (is_O.of_bound 1 _),
refine (eventually_lt_of_lt_liminf hr).mp ((eventually_gt_at_top 0).mono (Ξ» n hnβ hn, _)),
simpa using nnreal.coe_le_coe.2 ((this _ hnβ).1 hn.le) }
end
end formal_multilinear_series
|
55556442e43b8356f46e569fa1b402193352097b | 36c7a18fd72e5b57229bd8ba36493daf536a19ce | /hott/types/list.hlean | 2ea8b8600569ede50cccd548ad814d11ce212d56 | [
"Apache-2.0"
] | permissive | YHVHvx/lean | 732bf0fb7a298cd7fe0f15d82f8e248c11db49e9 | 038369533e0136dd395dc252084d3c1853accbf2 | refs/heads/master | 1,610,701,080,210 | 1,449,128,595,000 | 1,449,128,595,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 36,099 | hlean | /-
Copyright (c) 2014 Parikshit Khanna. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn
Basic properties of lists.
Ported from the standard library (list.basic and list.comb)
Some lemmas are commented out, their proofs need to be repaired when needed
-/
import .pointed .nat .pi
open eq lift nat is_trunc pi pointed sum function prod option sigma
inductive list (T : Type) : Type :=
| nil {} : list T
| cons : T β list T β list T
definition pointed_list [instance] (A : Type) : pointed (list A) :=
pointed.mk list.nil
namespace list
notation h :: t := cons h t
notation `[` l:(foldr `, ` (h t, cons h t) nil `]`) := l
universe variable u
variable {T : Type.{u}}
lemma cons_ne_nil (a : T) (l : list T) : a::l β [] :=
by contradiction
lemma head_eq_of_cons_eq {A : Type} {hβ hβ : A} {tβ tβ : list A} :
(hβ::tβ) = (hβ::tβ) β hβ = hβ :=
assume Peq, down (list.no_confusion Peq (assume Pheq Pteq, Pheq))
lemma tail_eq_of_cons_eq {A : Type} {hβ hβ : A} {tβ tβ : list A} :
(hβ::tβ) = (hβ::tβ) β tβ = tβ :=
assume Peq, down (list.no_confusion Peq (assume Pheq Pteq, Pteq))
/- append -/
definition append : list T β list T β list T
| [] l := l
| (h :: s) t := h :: (append s t)
notation lβ ++ lβ := append lβ lβ
theorem append_nil_left (t : list T) : [] ++ t = t := idp
theorem append_cons (x : T) (s t : list T) : (x::s) ++ t = x :: (s ++ t) := idp
theorem append_nil_right : β (t : list T), t ++ [] = t
| [] := rfl
| (a :: l) := calc
(a :: l) ++ [] = a :: (l ++ []) : rfl
... = a :: l : append_nil_right l
theorem append.assoc : β (s t u : list T), s ++ t ++ u = s ++ (t ++ u)
| [] t u := rfl
| (a :: l) t u :=
show a :: (l ++ t ++ u) = (a :: l) ++ (t ++ u),
by rewrite (append.assoc l t u)
/- length -/
definition length : list T β nat
| [] := 0
| (a :: l) := length l + 1
theorem length_nil : length (@nil T) = 0 := idp
theorem length_cons (x : T) (t : list T) : length (x::t) = length t + 1 := idp
theorem length_append : β (s t : list T), length (s ++ t) = length s + length t
| [] t := calc
length ([] ++ t) = length t : rfl
... = length [] + length t : by rewrite [length_nil, zero_add]
| (a :: s) t := calc
length (a :: s ++ t) = length (s ++ t) + 1 : rfl
... = length s + length t + 1 : length_append
... = (length s + 1) + length t : succ_add
... = length (a :: s) + length t : rfl
theorem eq_nil_of_length_eq_zero : β {l : list T}, length l = 0 β l = []
| [] H := rfl
| (a::s) H := by contradiction
theorem ne_nil_of_length_eq_succ : β {l : list T} {n : nat}, length l = succ n β l β []
| [] n h := by contradiction
| (a::l) n h := by contradiction
-- add_rewrite length_nil length_cons
/- concat -/
definition concat : Ξ (x : T), list T β list T
| a [] := [a]
| a (b :: l) := b :: concat a l
theorem concat_nil (x : T) : concat x [] = [x] := idp
theorem concat_cons (x y : T) (l : list T) : concat x (y::l) = y::(concat x l) := idp
theorem concat_eq_append (a : T) : β (l : list T), concat a l = l ++ [a]
| [] := rfl
| (b :: l) :=
show b :: (concat a l) = (b :: l) ++ (a :: []),
by rewrite concat_eq_append
theorem concat_ne_nil (a : T) : β (l : list T), concat a l β [] :=
by intro l; induction l; repeat contradiction
theorem length_concat (a : T) : β (l : list T), length (concat a l) = length l + 1
| [] := rfl
| (x::xs) := by rewrite [concat_cons, *length_cons, length_concat]
theorem concat_append (a : T) : β (lβ lβ : list T), concat a lβ ++ lβ = lβ ++ a :: lβ
| [] := Ξ»lβ, rfl
| (x::xs) := Ξ»lβ, begin rewrite [concat_cons,append_cons, concat_append] end
theorem append_concat (a : T) : β(lβ lβ : list T), lβ ++ concat a lβ = concat a (lβ ++ lβ)
| [] := Ξ»lβ, rfl
| (x::xs) := Ξ»lβ, begin rewrite [+append_cons, concat_cons, append_concat] end
/- last -/
definition last : Ξ l : list T, l β [] β T
| [] h := absurd rfl h
| [a] h := a
| (aβ::aβ::l) h := last (aβ::l) !cons_ne_nil
lemma last_singleton (a : T) (h : [a] β []) : last [a] h = a :=
rfl
lemma last_cons_cons (aβ aβ : T) (l : list T) (h : aβ::aβ::l β [])
: last (aβ::aβ::l) h = last (aβ::l) !cons_ne_nil :=
rfl
theorem last_congr {lβ lβ : list T} (hβ : lβ β []) (hβ : lβ β []) (hβ : lβ = lβ)
: last lβ hβ = last lβ hβ :=
apd011 last hβ !is_hprop.elim
theorem last_concat {x : T} : β {l : list T} (h : concat x l β []), last (concat x l) h = x
| [] h := rfl
| [a] h := rfl
| (aβ::aβ::l) h :=
begin
change last (aβ::aβ::concat x l) !cons_ne_nil = x,
rewrite last_cons_cons,
change last (concat x (aβ::l)) (cons_ne_nil aβ (concat x l)) = x,
apply last_concat
end
-- add_rewrite append_nil append_cons
/- reverse -/
definition reverse : list T β list T
| [] := []
| (a :: l) := concat a (reverse l)
theorem reverse_nil : reverse (@nil T) = [] := idp
theorem reverse_cons (x : T) (l : list T) : reverse (x::l) = concat x (reverse l) := idp
theorem reverse_singleton (x : T) : reverse [x] = [x] := idp
theorem reverse_append : β (s t : list T), reverse (s ++ t) = (reverse t) ++ (reverse s)
| [] t2 := calc
reverse ([] ++ t2) = reverse t2 : rfl
... = (reverse t2) ++ [] : append_nil_right
... = (reverse t2) ++ (reverse []) : by rewrite reverse_nil
| (a2 :: s2) t2 := calc
reverse ((a2 :: s2) ++ t2) = concat a2 (reverse (s2 ++ t2)) : rfl
... = concat a2 (reverse t2 ++ reverse s2) : reverse_append
... = (reverse t2 ++ reverse s2) ++ [a2] : concat_eq_append
... = reverse t2 ++ (reverse s2 ++ [a2]) : append.assoc
... = reverse t2 ++ concat a2 (reverse s2) : concat_eq_append
... = reverse t2 ++ reverse (a2 :: s2) : rfl
theorem reverse_reverse : β (l : list T), reverse (reverse l) = l
| [] := rfl
| (a :: l) := calc
reverse (reverse (a :: l)) = reverse (concat a (reverse l)) : rfl
... = reverse (reverse l ++ [a]) : concat_eq_append
... = reverse [a] ++ reverse (reverse l) : reverse_append
... = reverse [a] ++ l : reverse_reverse
... = a :: l : rfl
theorem concat_eq_reverse_cons (x : T) (l : list T) : concat x l = reverse (x :: reverse l) :=
calc
concat x l = concat x (reverse (reverse l)) : reverse_reverse
... = reverse (x :: reverse l) : rfl
theorem length_reverse : β (l : list T), length (reverse l) = length l
| [] := rfl
| (x::xs) := begin unfold reverse, rewrite [length_concat, length_cons, length_reverse] end
/- head and tail -/
definition head [h : pointed T] : list T β T
| [] := pt
| (a :: l) := a
theorem head_cons [h : pointed T] (a : T) (l : list T) : head (a::l) = a := idp
theorem head_append [h : pointed T] (t : list T) : β {s : list T}, s β [] β head (s ++ t) = head s
| [] H := absurd rfl H
| (a :: s) H :=
show head (a :: (s ++ t)) = head (a :: s),
by rewrite head_cons
definition tail : list T β list T
| [] := []
| (a :: l) := l
theorem tail_nil : tail (@nil T) = [] := idp
theorem tail_cons (a : T) (l : list T) : tail (a::l) = l := idp
theorem cons_head_tail [h : pointed T] {l : list T} : l β [] β (head l)::(tail l) = l :=
list.cases_on l
(suppose [] β [], absurd rfl this)
(take x l, suppose x::l β [], rfl)
/- list membership -/
definition mem : T β list T β Type.{u}
| a [] := lift empty
| a (b :: l) := a = b β mem a l
notation e β s := mem e s
notation e β s := Β¬ e β s
theorem mem_nil_iff (x : T) : x β [] β empty :=
iff.intro down up
theorem not_mem_nil (x : T) : x β [] :=
iff.mp !mem_nil_iff
theorem mem_cons (x : T) (l : list T) : x β x :: l :=
sum.inl rfl
theorem mem_cons_of_mem (y : T) {x : T} {l : list T} : x β l β x β y :: l :=
assume H, sum.inr H
theorem mem_cons_iff (x y : T) (l : list T) : x β y::l β (x = y β x β l) :=
iff.rfl
theorem eq_or_mem_of_mem_cons {x y : T} {l : list T} : x β y::l β x = y β x β l :=
assume h, h
theorem mem_singleton {x a : T} : x β [a] β x = a :=
suppose x β [a], sum.rec_on (eq_or_mem_of_mem_cons this)
(suppose x = a, this)
(suppose x β [], absurd this !not_mem_nil)
theorem mem_of_mem_cons_of_mem {a b : T} {l : list T} : a β b::l β b β l β a β l :=
assume ainbl binl, sum.rec_on (eq_or_mem_of_mem_cons ainbl)
(suppose a = b, by substvars; exact binl)
(suppose a β l, this)
theorem mem_or_mem_of_mem_append {x : T} {s t : list T} : x β s ++ t β x β s β x β t :=
list.rec_on s sum.inr
(take y s,
assume IH : x β s ++ t β x β s β x β t,
suppose x β y::s ++ t,
have x = y β x β s ++ t, from this,
have x = y β x β s β x β t, from sum_of_sum_of_imp_right this IH,
iff.elim_right sum.assoc this)
theorem mem_append_of_mem_or_mem {x : T} {s t : list T} : (x β s β x β t) β x β s ++ t :=
list.rec_on s
(take H, sum.rec_on H (empty.elim β down) (assume H, H))
(take y s,
assume IH : (x β s β x β t) β x β s ++ t,
suppose x β y::s β x β t,
sum.rec_on this
(suppose x β y::s,
sum.rec_on (eq_or_mem_of_mem_cons this)
(suppose x = y, sum.inl this)
(suppose x β s, sum.inr (IH (sum.inl this))))
(suppose x β t, sum.inr (IH (sum.inr this))))
theorem mem_append_iff (x : T) (s t : list T) : x β s ++ t β x β s β x β t :=
iff.intro mem_or_mem_of_mem_append mem_append_of_mem_or_mem
theorem not_mem_of_not_mem_append_left {x : T} {s t : list T} : x β s++t β x β s :=
Ξ» nxinst xins, absurd (mem_append_of_mem_or_mem (sum.inl xins)) nxinst
theorem not_mem_of_not_mem_append_right {x : T} {s t : list T} : x β s++t β x β t :=
Ξ» nxinst xint, absurd (mem_append_of_mem_or_mem (sum.inr xint)) nxinst
theorem not_mem_append {x : T} {s t : list T} : x β s β x β t β x β s++t :=
Ξ» nxins nxint xinst, sum.rec_on (mem_or_mem_of_mem_append xinst)
(Ξ» xins, by contradiction)
(Ξ» xint, by contradiction)
lemma length_pos_of_mem {a : T} : β {l : list T}, a β l β 0 < length l
| [] := assume Pinnil, by induction Pinnil; contradiction
| (b::l) := assume Pin, !zero_lt_succ
local attribute mem [reducible]
local attribute append [reducible]
theorem mem_split {x : T} {l : list T} : x β l β Ξ£s t : list T, l = s ++ (x::t) :=
list.rec_on l
(suppose x β [], empty.elim (iff.elim_left !mem_nil_iff this))
(take y l,
assume IH : x β l β Ξ£s t : list T, l = s ++ (x::t),
suppose x β y::l,
sum.rec_on (eq_or_mem_of_mem_cons this)
(suppose x = y,
sigma.mk [] (!sigma.mk (this βΈ rfl)))
(suppose x β l,
obtain s (H2 : Ξ£t : list T, l = s ++ (x::t)), from IH this,
obtain t (H3 : l = s ++ (x::t)), from H2,
have y :: l = (y::s) ++ (x::t),
from H3 βΈ rfl,
!sigma.mk (!sigma.mk this)))
theorem mem_append_left {a : T} {lβ : list T} (lβ : list T) : a β lβ β a β lβ ++ lβ :=
assume ainlβ, mem_append_of_mem_or_mem (sum.inl ainlβ)
theorem mem_append_right {a : T} (lβ : list T) {lβ : list T} : a β lβ β a β lβ ++ lβ :=
assume ainlβ, mem_append_of_mem_or_mem (sum.inr ainlβ)
definition decidable_mem [instance] [H : decidable_eq T] (x : T) (l : list T) : decidable (x β l) :=
list.rec_on l
(decidable.inr begin intro x, induction x, contradiction end)
(take (h : T) (l : list T) (iH : decidable (x β l)),
show decidable (x β h::l), from
decidable.rec_on iH
(assume Hp : x β l,
decidable.rec_on (H x h)
(suppose x = h,
decidable.inl (sum.inl this))
(suppose x β h,
decidable.inl (sum.inr Hp)))
(suppose Β¬x β l,
decidable.rec_on (H x h)
(suppose x = h, decidable.inl (sum.inl this))
(suppose x β h,
have Β¬(x = h β x β l), from
suppose x = h β x β l, sum.rec_on this
(suppose x = h, by contradiction)
(suppose x β l, by contradiction),
have Β¬x β h::l, from
iff.elim_right (not_iff_not_of_iff !mem_cons_iff) this,
decidable.inr this)))
theorem mem_of_ne_of_mem {x y : T} {l : list T} (Hβ : x β y) (Hβ : x β y :: l) : x β l :=
sum.rec_on (eq_or_mem_of_mem_cons Hβ) (Ξ»e, absurd e Hβ) (Ξ»r, r)
theorem ne_of_not_mem_cons {a b : T} {l : list T} : a β b::l β a β b :=
assume nin aeqb, absurd (sum.inl aeqb) nin
theorem not_mem_of_not_mem_cons {a b : T} {l : list T} : a β b::l β a β l :=
assume nin nainl, absurd (sum.inr nainl) nin
lemma not_mem_cons_of_ne_of_not_mem {x y : T} {l : list T} : x β y β x β l β x β y::l :=
assume P1 P2, not.intro (assume Pxin, absurd (eq_or_mem_of_mem_cons Pxin) (not_sum P1 P2))
lemma ne_and_not_mem_of_not_mem_cons {x y : T} {l : list T} : x β y::l β x β y Γ x β l :=
assume P, prod.mk (ne_of_not_mem_cons P) (not_mem_of_not_mem_cons P)
definition sublist (lβ lβ : list T) := β β¦a : Tβ¦, a β lβ β a β lβ
infix β := sublist
theorem nil_sub (l : list T) : [] β l :=
Ξ» b i, empty.elim (iff.mp (mem_nil_iff b) i)
theorem sub.refl (l : list T) : l β l :=
Ξ» b i, i
theorem sub.trans {lβ lβ lβ : list T} (Hβ : lβ β lβ) (Hβ : lβ β lβ) : lβ β lβ :=
Ξ» b i, Hβ (Hβ i)
theorem sub_cons (a : T) (l : list T) : l β a::l :=
Ξ» b i, sum.inr i
theorem sub_of_cons_sub {a : T} {lβ lβ : list T} : a::lβ β lβ β lβ β lβ :=
Ξ» s b i, s b (mem_cons_of_mem _ i)
theorem cons_sub_cons {lβ lβ : list T} (a : T) (s : lβ β lβ) : (a::lβ) β (a::lβ) :=
Ξ» b Hin, sum.rec_on (eq_or_mem_of_mem_cons Hin)
(Ξ» e : b = a, sum.inl e)
(Ξ» i : b β lβ, sum.inr (s i))
theorem sub_append_left (lβ lβ : list T) : lβ β lβ++lβ :=
Ξ» b i, iff.mpr (mem_append_iff b lβ lβ) (sum.inl i)
theorem sub_append_right (lβ lβ : list T) : lβ β lβ++lβ :=
Ξ» b i, iff.mpr (mem_append_iff b lβ lβ) (sum.inr i)
theorem sub_cons_of_sub (a : T) {lβ lβ : list T} : lβ β lβ β lβ β (a::lβ) :=
Ξ» (s : lβ β lβ) (x : T) (i : x β lβ), sum.inr (s i)
theorem sub_app_of_sub_left (l lβ lβ : list T) : l β lβ β l β lβ++lβ :=
Ξ» (s : l β lβ) (x : T) (xinl : x β l),
have x β lβ, from s xinl,
mem_append_of_mem_or_mem (sum.inl this)
theorem sub_app_of_sub_right (l lβ lβ : list T) : l β lβ β l β lβ++lβ :=
Ξ» (s : l β lβ) (x : T) (xinl : x β l),
have x β lβ, from s xinl,
mem_append_of_mem_or_mem (sum.inr this)
theorem cons_sub_of_sub_of_mem {a : T} {l m : list T} : a β m β l β m β a::l β m :=
Ξ» (ainm : a β m) (lsubm : l β m) (x : T) (xinal : x β a::l), sum.rec_on (eq_or_mem_of_mem_cons xinal)
(suppose x = a, by substvars; exact ainm)
(suppose x β l, lsubm this)
theorem app_sub_of_sub_of_sub {lβ lβ l : list T} : lβ β l β lβ β l β lβ++lβ β l :=
Ξ» (lβsubl : lβ β l) (lβsubl : lβ β l) (x : T) (xinlβlβ : x β lβ++lβ),
sum.rec_on (mem_or_mem_of_mem_append xinlβlβ)
(suppose x β lβ, lβsubl this)
(suppose x β lβ, lβsubl this)
/- find -/
section
variable [H : decidable_eq T]
include H
definition find : T β list T β nat
| a [] := 0
| a (b :: l) := if a = b then 0 else succ (find a l)
theorem find_nil (x : T) : find x [] = 0 := idp
theorem find_cons (x y : T) (l : list T) : find x (y::l) = if x = y then 0 else succ (find x l) :=
idp
theorem find_cons_of_eq {x y : T} (l : list T) : x = y β find x (y::l) = 0 :=
assume e, if_pos e
theorem find_cons_of_ne {x y : T} (l : list T) : x β y β find x (y::l) = succ (find x l) :=
assume n, if_neg n
/-theorem find_of_not_mem {l : list T} {x : T} : Β¬x β l β find x l = length l :=
list.rec_on l
(suppose Β¬x β [], _)
(take y l,
assume iH : Β¬x β l β find x l = length l,
suppose Β¬x β y::l,
have Β¬(x = y β x β l), from iff.elim_right (not_iff_not_of_iff !mem_cons_iff) this,
have Β¬x = y Γ Β¬x β l, from (iff.elim_left not_sum_iff_not_prod_not this),
calc
find x (y::l) = if x = y then 0 else succ (find x l) : !find_cons
... = succ (find x l) : if_neg (prod.pr1 this)
... = succ (length l) : {iH (prod.pr2 this)}
... = length (y::l) : !length_consβ»ΒΉ)-/
lemma find_le_length : β {a} {l : list T}, find a l β€ length l
| a [] := !le.refl
| a (b::l) := decidable.rec_on (H a b)
(assume Peq, by rewrite [find_cons_of_eq l Peq]; exact !zero_le)
(assume Pne,
begin
rewrite [find_cons_of_ne l Pne, length_cons],
apply succ_le_succ, apply find_le_length
end)
/-lemma not_mem_of_find_eq_length : β {a} {l : list T}, find a l = length l β a β l
| a [] := assume Peq, !not_mem_nil
| a (b::l) := decidable.rec_on (H a b)
(assume Peq, by rewrite [find_cons_of_eq l Peq, length_cons]; contradiction)
(assume Pne,
begin
rewrite [find_cons_of_ne l Pne, length_cons, mem_cons_iff],
intro Plen, apply (not_or Pne),
exact not_mem_of_find_eq_length (succ.inj Plen)
end)-/
/-lemma find_lt_length {a} {l : list T} (Pin : a β l) : find a l < length l :=
begin
apply nat.lt_of_le_prod_ne,
apply find_le_length,
apply not.intro, intro Peq,
exact absurd Pin (not_mem_of_find_eq_length Peq)
end-/
end
/- nth element -/
section nth
definition nth : list T β nat β option T
| [] n := none
| (a :: l) 0 := some a
| (a :: l) (n+1) := nth l n
theorem nth_zero (a : T) (l : list T) : nth (a :: l) 0 = some a := idp
theorem nth_succ (a : T) (l : list T) (n : nat) : nth (a::l) (succ n) = nth l n := idp
theorem nth_eq_some : β {l : list T} {n : nat}, n < length l β Ξ£ a : T, nth l n = some a
| [] n h := absurd h !not_lt_zero
| (a::l) 0 h := β¨a, rflβ©
| (a::l) (succ n) h :=
have n < length l, from lt_of_succ_lt_succ h,
obtain (r : T) (req : nth l n = some r), from nth_eq_some this,
β¨r, by rewrite [nth_succ, req]β©
open decidable
theorem find_nth [h : decidable_eq T] {a : T} : β {l}, a β l β nth l (find a l) = some a
| [] ain := absurd ain !not_mem_nil
| (b::l) ainbl := by_cases
(Ξ» aeqb : a = b, by rewrite [find_cons_of_eq _ aeqb, nth_zero, aeqb])
(Ξ» aneb : a β b, sum.rec_on (eq_or_mem_of_mem_cons ainbl)
(Ξ» aeqb : a = b, absurd aeqb aneb)
(Ξ» ainl : a β l, by rewrite [find_cons_of_ne _ aneb, nth_succ, find_nth ainl]))
definition inth [h : pointed T] (l : list T) (n : nat) : T :=
match nth l n with
| some a := a
| none := pt
end
theorem inth_zero [h : pointed T] (a : T) (l : list T) : inth (a :: l) 0 = a := idp
theorem inth_succ [h : pointed T] (a : T) (l : list T) (n : nat) : inth (a::l) (n+1) = inth l n :=
idp
end nth
section ith
definition ith : Ξ (l : list T) (i : nat), i < length l β T
| nil i h := absurd h !not_lt_zero
| (x::xs) 0 h := x
| (x::xs) (succ i) h := ith xs i (lt_of_succ_lt_succ h)
lemma ith_zero (a : T) (l : list T) (h : 0 < length (a::l)) : ith (a::l) 0 h = a :=
rfl
lemma ith_succ (a : T) (l : list T) (i : nat) (h : succ i < length (a::l))
: ith (a::l) (succ i) h = ith l i (lt_of_succ_lt_succ h) :=
rfl
end ith
open decidable
definition has_decidable_eq {A : Type} [H : decidable_eq A] : β lβ lβ : list A, decidable (lβ = lβ)
| [] [] := inl rfl
| [] (b::lβ) := inr (by contradiction)
| (a::lβ) [] := inr (by contradiction)
| (a::lβ) (b::lβ) :=
match H a b with
| inl Hab :=
match has_decidable_eq lβ lβ with
| inl He := inl (by congruence; repeat assumption)
| inr Hn := inr (by intro H; injection H; contradiction)
end
| inr Hnab := inr (by intro H; injection H; contradiction)
end
/- quasiequal a l l' means that l' is exactly l, with a added
once somewhere -/
section qeq
variable {A : Type.{u}}
inductive qeq (a : A) : list A β list A β Type.{u} :=
| qhead : β l, qeq a l (a::l)
| qcons : β (b : A) {l l' : list A}, qeq a l l' β qeq a (b::l) (b::l')
open qeq
notation l' `β`:50 a `|` l:50 := qeq a l l'
theorem qeq_app : β (lβ : list A) (a : A) (lβ : list A), lβ++(a::lβ) β a|lβ++lβ
| [] a lβ := qhead a lβ
| (x::xs) a lβ := qcons x (qeq_app xs a lβ)
theorem mem_head_of_qeq {a : A} {lβ lβ : list A} : lββa|lβ β a β lβ :=
take q, qeq.rec_on q
(Ξ» l, !mem_cons)
(Ξ» b l l' q r, sum.inr r)
theorem mem_tail_of_qeq {a : A} {lβ lβ : list A} : lββa|lβ β β x, x β lβ β x β lβ :=
take q, qeq.rec_on q
(Ξ» l x i, sum.inr i)
(Ξ» b l l' q r x xinbl, sum.rec_on (eq_or_mem_of_mem_cons xinbl)
(Ξ» xeqb : x = b, xeqb βΈ mem_cons x l')
(Ξ» xinl : x β l, sum.inr (r x xinl)))
/-
theorem mem_cons_of_qeq {a : A} {lβ lβ : list A} : lββa|lβ β β x, x β lβ β x β a::lβ :=
take q, qeq.rec_on q
(Ξ» l x i, i)
(Ξ» b l l' q r x xinbl', sum.elim_on (eq_or_mem_of_mem_cons xinbl')
(Ξ» xeqb : x = b, xeqb βΈ sum.inr (mem_cons x l))
(Ξ» xinl' : x β l', sum.rec_on (eq_or_mem_of_mem_cons (r x xinl'))
(Ξ» xeqa : x = a, xeqa βΈ mem_cons x (b::l))
(Ξ» xinl : x β l, sum.inr (sum.inr xinl))))-/
theorem length_eq_of_qeq {a : A} {lβ lβ : list A} : lββa|lβ β length lβ = succ (length lβ) :=
take q, qeq.rec_on q
(Ξ» l, rfl)
(Ξ» b l l' q r, by rewrite [*length_cons, r])
theorem qeq_of_mem {a : A} {l : list A} : a β l β (Ξ£l', lβa|l') :=
list.rec_on l
(Ξ» h : a β nil, absurd h (not_mem_nil a))
(Ξ» x xs r ainxxs, sum.rec_on (eq_or_mem_of_mem_cons ainxxs)
(Ξ» aeqx : a = x,
assert aux : Ξ£ l, x::xsβx|l, from
sigma.mk xs (qhead x xs),
by rewrite aeqx; exact aux)
(Ξ» ainxs : a β xs,
have Ξ£l', xs β a|l', from r ainxs,
obtain (l' : list A) (q : xs β a|l'), from this,
have x::xs β a | x::l', from qcons x q,
sigma.mk (x::l') this))
theorem qeq_split {a : A} {l l' : list A} : l'βa|l β Ξ£lβ lβ, l = lβ++lβ Γ l' = lβ++(a::lβ) :=
take q, qeq.rec_on q
(Ξ» t,
have t = []++t Γ a::t = []++(a::t), from prod.mk rfl rfl,
sigma.mk [] (sigma.mk t this))
(Ξ» b t t' q r,
obtain (lβ lβ : list A) (h : t = lβ++lβ Γ t' = lβ++(a::lβ)), from r,
have b::t = (b::lβ)++lβ Γ b::t' = (b::lβ)++(a::lβ),
begin
rewrite [prod.pr2 h, prod.pr1 h],
constructor, repeat reflexivity
end,
sigma.mk (b::lβ) (sigma.mk lβ this))
/-theorem sub_of_mem_of_sub_of_qeq {a : A} {l : list A} {u v : list A} : a β l β a::l β v β vβa|u β l β u :=
Ξ» (nainl : a β l) (s : a::l β v) (q : vβa|u) (x : A) (xinl : x β l),
have x β v, from s (sum.inr xinl),
have x β a::u, from mem_cons_of_qeq q x this,
sum.rec_on (eq_or_mem_of_mem_cons this)
(suppose x = a, by substvars; contradiction)
(suppose x β u, this)-/
end qeq
section firstn
variable {A : Type}
definition firstn : nat β list A β list A
| 0 l := []
| (n+1) [] := []
| (n+1) (a::l) := a :: firstn n l
lemma firstn_zero : β (l : list A), firstn 0 l = [] :=
by intros; reflexivity
lemma firstn_nil : β n, firstn n [] = ([] : list A)
| 0 := rfl
| (n+1) := rfl
lemma firstn_cons : β n (a : A) (l : list A), firstn (succ n) (a::l) = a :: firstn n l :=
by intros; reflexivity
lemma firstn_all : β (l : list A), firstn (length l) l = l
| [] := rfl
| (a::l) := begin unfold [length, firstn], rewrite firstn_all end
/-lemma firstn_all_of_ge : β {n} {l : list A}, n β₯ length l β firstn n l = l
| 0 [] h := rfl
| 0 (a::l) h := absurd h (not_le_of_gt !succ_pos)
| (n+1) [] h := rfl
| (n+1) (a::l) h := begin unfold firstn, rewrite [firstn_all_of_ge (le_of_succ_le_succ h)] end-/
/-lemma firstn_firstn : β (n m) (l : list A), firstn n (firstn m l) = firstn (min n m) l
| n 0 l := by rewrite [min_zero, firstn_zero, firstn_nil]
| 0 m l := by rewrite [zero_min]
| (succ n) (succ m) nil := by rewrite [*firstn_nil]
| (succ n) (succ m) (a::l) := by rewrite [*firstn_cons, firstn_firstn, min_succ_succ]-/
lemma length_firstn_le : β (n) (l : list A), length (firstn n l) β€ n
| 0 l := by rewrite [firstn_zero]
| (succ n) (a::l) := by rewrite [firstn_cons, length_cons, add_one]; apply succ_le_succ; apply length_firstn_le
| (succ n) [] := by rewrite [firstn_nil, length_nil]; apply zero_le
/-lemma length_firstn_eq : β (n) (l : list A), length (firstn n l) = min n (length l)
| 0 l := by rewrite [firstn_zero, zero_min]
| (succ n) (a::l) := by rewrite [firstn_cons, *length_cons, *add_one, min_succ_succ, length_firstn_eq]
| (succ n) [] := by rewrite [firstn_nil]-/
end firstn
section count
variable {A : Type}
variable [decA : decidable_eq A]
include decA
definition count (a : A) : list A β nat
| [] := 0
| (x::xs) := if a = x then succ (count xs) else count xs
lemma count_nil (a : A) : count a [] = 0 :=
rfl
lemma count_cons (a b : A) (l : list A) : count a (b::l) = if a = b then succ (count a l) else count a l :=
rfl
lemma count_cons_eq (a : A) (l : list A) : count a (a::l) = succ (count a l) :=
if_pos rfl
lemma count_cons_of_ne {a b : A} (h : a β b) (l : list A) : count a (b::l) = count a l :=
if_neg h
lemma count_cons_ge_count (a b : A) (l : list A) : count a (b::l) β₯ count a l :=
by_cases
(suppose a = b, begin subst b, rewrite count_cons_eq, apply le_succ end)
(suppose a β b, begin rewrite (count_cons_of_ne this), apply le.refl end)
lemma count_singleton (a : A) : count a [a] = 1 :=
by rewrite count_cons_eq
lemma count_append (a : A) : β lβ lβ, count a (lβ++lβ) = count a lβ + count a lβ
| [] lβ := by rewrite [append_nil_left, count_nil, zero_add]
| (b::lβ) lβ := by_cases
(suppose a = b, by rewrite [-this, append_cons, *count_cons_eq, succ_add, count_append])
(suppose a β b, by rewrite [append_cons, *count_cons_of_ne this, count_append])
lemma count_concat (a : A) (l : list A) : count a (concat a l) = succ (count a l) :=
by rewrite [concat_eq_append, count_append, count_singleton]
lemma mem_of_count_gt_zero : β {a : A} {l : list A}, count a l > 0 β a β l
| a [] h := absurd h !lt.irrefl
| a (b::l) h := by_cases
(suppose a = b, begin subst b, apply mem_cons end)
(suppose a β b,
have count a l > 0, by rewrite [count_cons_of_ne this at h]; exact h,
have a β l, from mem_of_count_gt_zero this,
show a β b::l, from mem_cons_of_mem _ this)
/-lemma count_gt_zero_of_mem : β {a : A} {l : list A}, a β l β count a l > 0
| a [] h := absurd h !not_mem_nil
| a (b::l) h := sum.rec_on h
(suppose a = b, begin subst b, rewrite count_cons_eq, apply zero_lt_succ end)
(suppose a β l, calc
count a (b::l) β₯ count a l : count_cons_ge_count
... > 0 : count_gt_zero_of_mem this)-/
/-lemma count_eq_zero_of_not_mem {a : A} {l : list A} (h : a β l) : count a l = 0 :=
match count a l with
| zero := suppose count a l = zero, this
| (succ n) := suppose count a l = succ n, absurd (mem_of_count_gt_zero (begin rewrite this, exact dec_trivial end)) h
end rfl-/
end count
end list
attribute list.has_decidable_eq [instance]
--attribute list.decidable_mem [instance]
namespace list
variables {A B C : Type}
/- map -/
definition map (f : A β B) : list A β list B
| [] := []
| (a :: l) := f a :: map l
theorem map_nil (f : A β B) : map f [] = [] := idp
theorem map_cons (f : A β B) (a : A) (l : list A) : map f (a :: l) = f a :: map f l := idp
lemma map_concat (f : A β B) (a : A) : Ξ l, map f (concat a l) = concat (f a) (map f l)
| nil := rfl
| (b::l) := begin rewrite [concat_cons, +map_cons, concat_cons, map_concat] end
lemma map_append (f : A β B) : Ξ lβ lβ, map f (lβ++lβ) = (map f lβ)++(map f lβ)
| nil := take l, rfl
| (a::l) := take l', begin rewrite [append_cons, *map_cons, append_cons, map_append] end
lemma map_reverse (f : A β B) : Ξ l, map f (reverse l) = reverse (map f l)
| nil := rfl
| (b::l) := begin rewrite [reverse_cons, +map_cons, reverse_cons, map_concat, map_reverse] end
lemma map_singleton (f : A β B) (a : A) : map f [a] = [f a] := rfl
theorem map_id : Ξ l : list A, map id l = l
| [] := rfl
| (x::xs) := begin rewrite [map_cons, map_id] end
theorem map_id' {f : A β A} (H : Ξ x, f x = x) : Ξ l : list A, map f l = l
| [] := rfl
| (x::xs) := begin rewrite [map_cons, H, map_id'] end
theorem map_map (g : B β C) (f : A β B) : Ξ l, map g (map f l) = map (g β f) l
| [] := rfl
| (a :: l) :=
show (g β f) a :: map g (map f l) = map (g β f) (a :: l),
by rewrite (map_map l)
theorem length_map (f : A β B) : Ξ l : list A, length (map f l) = length l
| [] := by esimp
| (a :: l) :=
show length (map f l) + 1 = length l + 1,
by rewrite (length_map l)
theorem mem_map {A B : Type} (f : A β B) : Ξ {a l}, a β l β f a β map f l
| a [] i := absurd i !not_mem_nil
| a (x::xs) i := sum.rec_on (eq_or_mem_of_mem_cons i)
(suppose a = x, by rewrite [this, map_cons]; apply mem_cons)
(suppose a β xs, sum.inr (mem_map this))
theorem exists_of_mem_map {A B : Type} {f : A β B} {b : B} :
Ξ {l}, b β map f l β Ξ£a, a β l Γ f a = b
| [] H := empty.elim (down H)
| (c::l) H := sum.rec_on (iff.mp !mem_cons_iff H)
(suppose b = f c,
sigma.mk c (pair !mem_cons (inverse this)))
(suppose b β map f l,
obtain a (Hl : a β l) (Hr : f a = b), from exists_of_mem_map this,
sigma.mk a (pair (mem_cons_of_mem _ Hl) Hr))
theorem eq_of_map_const {A B : Type} {bβ bβ : B} : Ξ {l : list A}, bβ β map (const A bβ) l β bβ = bβ
| [] h := absurd h !not_mem_nil
| (a::l) h :=
sum.rec_on (eq_or_mem_of_mem_cons h)
(suppose bβ = bβ, this)
(suppose bβ β map (const A bβ) l, eq_of_map_const this)
definition mapβ (f : A β B β C) : list A β list B β list C
| [] _ := []
| _ [] := []
| (x::xs) (y::ys) := f x y :: mapβ xs ys
/- filter -/
definition filter (p : A β Type) [h : decidable_pred p] : list A β list A
| [] := []
| (a::l) := if p a then a :: filter l else filter l
theorem filter_nil (p : A β Type) [h : decidable_pred p] : filter p [] = [] := idp
theorem filter_cons_of_pos {p : A β Type} [h : decidable_pred p] {a : A} : Ξ l, p a β filter p (a::l) = a :: filter p l :=
Ξ» l pa, if_pos pa
theorem filter_cons_of_neg {p : A β Type} [h : decidable_pred p] {a : A} : Ξ l, Β¬ p a β filter p (a::l) = filter p l :=
Ξ» l pa, if_neg pa
/-
theorem of_mem_filter {p : A β Type} [h : decidable_pred p] {a : A} : Ξ {l}, a β filter p l β p a
| [] ain := absurd ain !not_mem_nil
| (b::l) ain := by_cases
(assume pb : p b,
have a β b :: filter p l, by rewrite [filter_cons_of_pos _ pb at ain]; exact ain,
sum.rec_on (eq_or_mem_of_mem_cons this)
(suppose a = b, by rewrite [-this at pb]; exact pb)
(suppose a β filter p l, of_mem_filter this))
(suppose Β¬ p b, by rewrite [filter_cons_of_neg _ this at ain]; exact (of_mem_filter ain))
theorem mem_of_mem_filter {p : A β Type} [h : decidable_pred p] {a : A} : Ξ {l}, a β filter p l β a β l
| [] ain := absurd ain !not_mem_nil
| (b::l) ain := by_cases
(Ξ» pb : p b,
have a β b :: filter p l, by rewrite [filter_cons_of_pos _ pb at ain]; exact ain,
sum.rec_on (eq_or_mem_of_mem_cons this)
(suppose a = b, by rewrite this; exact !mem_cons)
(suppose a β filter p l, mem_cons_of_mem _ (mem_of_mem_filter this)))
(suppose Β¬ p b, by rewrite [filter_cons_of_neg _ this at ain]; exact (mem_cons_of_mem _ (mem_of_mem_filter ain)))
theorem mem_filter_of_mem {p : A β Type} [h : decidable_pred p] {a : A} : Ξ {l}, a β l β p a β a β filter p l
| [] ain pa := absurd ain !not_mem_nil
| (b::l) ain pa := by_cases
(Ξ» pb : p b, sum.rec_on (eq_or_mem_of_mem_cons ain)
(Ξ» aeqb : a = b, by rewrite [filter_cons_of_pos _ pb, aeqb]; exact !mem_cons)
(Ξ» ainl : a β l, by rewrite [filter_cons_of_pos _ pb]; exact (mem_cons_of_mem _ (mem_filter_of_mem ainl pa))))
(Ξ» npb : Β¬ p b, sum.rec_on (eq_or_mem_of_mem_cons ain)
(Ξ» aeqb : a = b, absurd (eq.rec_on aeqb pa) npb)
(Ξ» ainl : a β l, by rewrite [filter_cons_of_neg _ npb]; exact (mem_filter_of_mem ainl pa)))
theorem filter_sub {p : A β Type} [h : decidable_pred p] (l : list A) : filter p l β l :=
Ξ» a ain, mem_of_mem_filter ain
theorem filter_append {p : A β Type} [h : decidable_pred p] : Ξ (lβ lβ : list A), filter p (lβ++lβ) = filter p lβ ++ filter p lβ
| [] lβ := rfl
| (a::lβ) lβ := by_cases
(suppose p a, by rewrite [append_cons, *filter_cons_of_pos _ this, filter_append])
(suppose Β¬ p a, by rewrite [append_cons, *filter_cons_of_neg _ this, filter_append])
-/
/- foldl & foldr -/
definition foldl (f : A β B β A) : A β list B β A
| a [] := a
| a (b :: l) := foldl (f a b) l
theorem foldl_nil (f : A β B β A) (a : A) : foldl f a [] = a := idp
theorem foldl_cons (f : A β B β A) (a : A) (b : B) (l : list B) : foldl f a (b::l) = foldl f (f a b) l := idp
definition foldr (f : A β B β B) : B β list A β B
| b [] := b
| b (a :: l) := f a (foldr b l)
theorem foldr_nil (f : A β B β B) (b : B) : foldr f b [] = b := idp
theorem foldr_cons (f : A β B β B) (b : B) (a : A) (l : list A) : foldr f b (a::l) = f a (foldr f b l) := idp
section foldl_eq_foldr
-- foldl and foldr coincide when f is commutative and associative
parameters {Ξ± : Type} {f : Ξ± β Ξ± β Ξ±}
hypothesis (Hcomm : Ξ a b, f a b = f b a)
hypothesis (Hassoc : Ξ a b c, f (f a b) c = f a (f b c))
include Hcomm Hassoc
theorem foldl_eq_of_comm_of_assoc : Ξ a b l, foldl f a (b::l) = f b (foldl f a l)
| a b nil := Hcomm a b
| a b (c::l) :=
begin
change foldl f (f (f a b) c) l = f b (foldl f (f a c) l),
rewrite -foldl_eq_of_comm_of_assoc,
change foldl f (f (f a b) c) l = foldl f (f (f a c) b) l,
have Hβ : f (f a b) c = f (f a c) b, by rewrite [Hassoc, Hassoc, Hcomm b c],
rewrite Hβ
end
theorem foldl_eq_foldr : Ξ a l, foldl f a l = foldr f a l
| a nil := rfl
| a (b :: l) :=
begin
rewrite foldl_eq_of_comm_of_assoc,
esimp,
change f b (foldl f a l) = f b (foldr f a l),
rewrite foldl_eq_foldr
end
end foldl_eq_foldr
theorem foldl_append (f : B β A β B) : Ξ (b : B) (lβ lβ : list A), foldl f b (lβ++lβ) = foldl f (foldl f b lβ) lβ
| b [] lβ := rfl
| b (a::lβ) lβ := by rewrite [append_cons, *foldl_cons, foldl_append]
theorem foldr_append (f : A β B β B) : Ξ (b : B) (lβ lβ : list A), foldr f b (lβ++lβ) = foldr f (foldr f b lβ) lβ
| b [] lβ := rfl
| b (a::lβ) lβ := by rewrite [append_cons, *foldr_cons, foldr_append]
end list
|
9581db7fde97bf9e08ac1983b5d790dd7038cdce | 4727251e0cd73359b15b664c3170e5d754078599 | /src/combinatorics/simple_graph/density.lean | 16999a66346775287d6605d21223836003f17fa7 | [
"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 | 10,134 | lean | /-
Copyright (c) 2022 YaΓ«l Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: YaΓ«l Dillies, Bhavik Mehta
-/
import combinatorics.simple_graph.basic
import order.partition.finpartition
/-!
# Edge density
This file defines the number and density of edges of a relation/graph.
## Main declarations
Between two finsets of vertices,
* `rel.interedges`: Finset of edges of a relation.
* `rel.edge_density`: Edge density of a relation.
* `simple_graph.interedges`: Finset of edges of a graph.
* `simple_graph.edge_density`: Edge density of a graph.
-/
open finset
variables {ΞΉ ΞΊ Ξ± Ξ² : Type*}
/-! ### Density of a relation -/
namespace rel
section asymmetric
variables (r : Ξ± β Ξ² β Prop) [Ξ a, decidable_pred (r a)] {s sβ sβ : finset Ξ±} {t tβ tβ : finset Ξ²}
{a : Ξ±} {b : Ξ²}
/-- Finset of edges of a relation between two finsets of vertices. -/
def interedges (s : finset Ξ±) (t : finset Ξ²) : finset (Ξ± Γ Ξ²) :=
(s.product t).filter $ Ξ» e, r e.1 e.2
/-- Edge density of a relation between two finsets of vertices. -/
def edge_density (s : finset Ξ±) (t : finset Ξ²) : β := (interedges r s t).card / (s.card * t.card)
variables {r}
lemma mem_interedges_iff {x : Ξ± Γ Ξ²} : x β interedges r s t β x.1 β s β§ x.2 β t β§ r x.1 x.2 :=
by simp only [interedges, and_assoc, mem_filter, finset.mem_product]
lemma mk_mem_interedges_iff : (a, b) β interedges r s t β a β s β§ b β t β§ r a b :=
mem_interedges_iff
@[simp] lemma interedges_empty_left (t : finset Ξ²) : interedges r β
t = β
:=
by rw [interedges, finset.empty_product, filter_empty]
lemma interedges_mono (hs : sβ β sβ) (ht : tβ β tβ) : interedges r sβ tβ β interedges r sβ tβ :=
Ξ» x, by { simp_rw mem_interedges_iff, exact Ξ» h, β¨hs h.1, ht h.2.1, h.2.2β© }
variables (r)
lemma card_interedges_add_card_interedges_compl (s : finset Ξ±) (t : finset Ξ²) :
(interedges r s t).card + (interedges (Ξ» x y, Β¬r x y) s t).card = s.card * t.card :=
begin
classical,
rw [βcard_product, interedges, interedges, βcard_union_eq, filter_union_filter_neg_eq],
convert disjoint_filter.2 (Ξ» x _, not_not.2),
end
section decidable_eq
variables [decidable_eq Ξ±] [decidable_eq Ξ²]
lemma interedges_disjoint_left {s s' : finset Ξ±} (hs : disjoint s s') (t : finset Ξ²) :
disjoint (interedges r s t) (interedges r s' t) :=
begin
rintro x hx,
rw [inf_eq_inter, mem_inter, mem_interedges_iff, mem_interedges_iff] at hx,
exact hs (mem_inter.2 β¨hx.1.1, hx.2.1β©),
end
lemma interedges_disjoint_right (s : finset Ξ±) {t t' : finset Ξ²} (ht : disjoint t t') :
disjoint (interedges r s t) (interedges r s t') :=
begin
rintro x hx,
rw [inf_eq_inter, mem_inter, mem_interedges_iff, mem_interedges_iff] at hx,
exact ht (mem_inter.2 β¨hx.1.2.1, hx.2.2.1β©),
end
lemma interedges_bUnion_left (s : finset ΞΉ) (t : finset Ξ²) (f : ΞΉ β finset Ξ±) :
interedges r (s.bUnion f) t = s.bUnion (Ξ» a, interedges r (f a) t) :=
ext $ Ξ» a, by simp only [mem_bUnion, mem_interedges_iff, exists_and_distrib_right]
lemma interedges_bUnion_right (s : finset Ξ±) (t : finset ΞΉ) (f : ΞΉ β finset Ξ²) :
interedges r s (t.bUnion f) = t.bUnion (Ξ» b, interedges r s (f b)) :=
ext $ Ξ» a, by simp only [mem_interedges_iff, mem_bUnion, βexists_and_distrib_left,
βexists_and_distrib_right]
lemma interedges_bUnion (s : finset ΞΉ) (t : finset ΞΊ) (f : ΞΉ β finset Ξ±) (g : ΞΊ β finset Ξ²) :
interedges r (s.bUnion f) (t.bUnion g) =
(s.product t).bUnion (Ξ» ab, interedges r (f ab.1) (g ab.2)) :=
by simp_rw [product_bUnion, interedges_bUnion_left, interedges_bUnion_right]
end decidable_eq
lemma card_interedges_le_mul (s : finset Ξ±) (t : finset Ξ²) :
(interedges r s t).card β€ s.card * t.card :=
(card_filter_le _ _).trans (card_product _ _).le
lemma edge_density_nonneg (s : finset Ξ±) (t : finset Ξ²) : 0 β€ edge_density r s t :=
by { apply div_nonneg; exact_mod_cast nat.zero_le _ }
lemma edge_density_le_one (s : finset Ξ±) (t : finset Ξ²) : edge_density r s t β€ 1 :=
div_le_one_of_le (by exact_mod_cast (card_interedges_le_mul _ _ _)) $
by exact_mod_cast (nat.zero_le _)
lemma edge_density_add_edge_density_compl (hs : s.nonempty) (ht : t.nonempty) :
edge_density r s t + edge_density (Ξ» x y, Β¬r x y) s t = 1 :=
begin
rw [edge_density, edge_density, div_add_div_same, div_eq_one_iff_eq],
{ exact_mod_cast card_interedges_add_card_interedges_compl r s t },
{ exact_mod_cast (mul_pos hs.card_pos ht.card_pos).ne' }
end
@[simp] lemma edge_density_empty_left (t : finset Ξ²) : edge_density r β
t = 0 :=
by rw [edge_density, finset.card_empty, nat.cast_zero, zero_mul, div_zero]
@[simp] lemma edge_density_empty_right (s : finset Ξ±) : edge_density r s β
= 0 :=
by rw [edge_density, finset.card_empty, nat.cast_zero, mul_zero, div_zero]
end asymmetric
section symmetric
variables (r : Ξ± β Ξ± β Prop) [decidable_rel r] {s sβ sβ t tβ tβ : finset Ξ±} {a b : Ξ±}
variables {r} (hr : symmetric r)
include hr
@[simp] lemma swap_mem_interedges_iff {x : Ξ± Γ Ξ±} :
x.swap β interedges r s t β x β interedges r t s :=
by { rw [mem_interedges_iff, mem_interedges_iff, hr.iff], exact and.left_comm }
lemma mk_mem_interedges_comm : (a, b) β interedges r s t β (b, a) β interedges r t s :=
@swap_mem_interedges_iff _ _ _ _ _ hr (b, a)
lemma card_interedges_comm (s t : finset Ξ±) : (interedges r s t).card = (interedges r t s).card :=
finset.card_congr (Ξ» (x : Ξ± Γ Ξ±) _, x.swap) (Ξ» x, (swap_mem_interedges_iff hr).2)
(Ξ» _ _ _ _ h, prod.swap_injective h)
(Ξ» x h, β¨x.swap, (swap_mem_interedges_iff hr).2 h, x.swap_swapβ©)
lemma edge_density_comm (s t : finset Ξ±) : edge_density r s t = edge_density r t s :=
by rw [edge_density, mul_comm, card_interedges_comm hr, edge_density]
end symmetric
end rel
open rel
/-! ### Density of a graph -/
namespace simple_graph
variables (G : simple_graph Ξ±) [decidable_rel G.adj] {s sβ sβ t tβ tβ : finset Ξ±} {a b : Ξ±}
/-- Finset of edges of a relation between two finsets of vertices. -/
def interedges (s t : finset Ξ±) : finset (Ξ± Γ Ξ±) := interedges G.adj s t
/-- Density of edges of a graph between two finsets of vertices. -/
def edge_density : finset Ξ± β finset Ξ± β β := edge_density G.adj
lemma interedges_def (s t : finset Ξ±) :
G.interedges s t = (s.product t).filter (Ξ» e, G.adj e.1 e.2) := rfl
lemma edge_density_def (s t : finset Ξ±) :
G.edge_density s t = (G.interedges s t).card / (s.card * t.card) := rfl
@[simp] lemma card_interedges_div_card (s t : finset Ξ±) :
((G.interedges s t).card : β) / (s.card * t.card) = G.edge_density s t := rfl
lemma mem_interedges_iff {x : Ξ± Γ Ξ±} : x β G.interedges s t β x.1 β s β§ x.2 β t β§ G.adj x.1 x.2 :=
mem_interedges_iff
lemma mk_mem_interedges_iff : (a, b) β G.interedges s t β a β s β§ b β t β§ G.adj a b :=
mk_mem_interedges_iff
@[simp] lemma interedges_empty_left (t : finset Ξ±) : G.interedges β
t = β
:= interedges_empty_left _
lemma interedges_mono : sβ β sβ β tβ β tβ β G.interedges sβ tβ β G.interedges sβ tβ :=
interedges_mono
section decidable_eq
variables [decidable_eq Ξ±]
lemma interedges_disjoint_left (hs : disjoint sβ sβ) (t : finset Ξ±) :
disjoint (G.interedges sβ t) (G.interedges sβ t) :=
interedges_disjoint_left _ hs _
lemma interedges_disjoint_right (s : finset Ξ±) (ht : disjoint tβ tβ) :
disjoint (G.interedges s tβ) (G.interedges s tβ) :=
interedges_disjoint_right _ _ ht
lemma interedges_bUnion_left (s : finset ΞΉ) (t : finset Ξ±) (f : ΞΉ β finset Ξ±) :
G.interedges (s.bUnion f) t = s.bUnion (Ξ» a, G.interedges (f a) t) :=
interedges_bUnion_left _ _ _ _
lemma interedges_bUnion_right (s : finset Ξ±) (t : finset ΞΉ) (f : ΞΉ β finset Ξ±) :
G.interedges s (t.bUnion f) = t.bUnion (Ξ» b, G.interedges s (f b)) :=
interedges_bUnion_right _ _ _ _
lemma interedges_bUnion (s : finset ΞΉ) (t : finset ΞΊ) (f : ΞΉ β finset Ξ±) (g : ΞΊ β finset Ξ±) :
G.interedges (s.bUnion f) (t.bUnion g) =
(s.product t).bUnion (Ξ» ab, G.interedges (f ab.1) (g ab.2)) :=
interedges_bUnion _ _ _ _ _
lemma card_interedges_add_card_interedges_compl (h : disjoint s t) :
(G.interedges s t).card + (GαΆ.interedges s t).card = s.card * t.card :=
begin
rw [βcard_product, interedges_def, interedges_def],
have : (s.product t).filter (Ξ» e , GαΆ.adj e.1 e.2) = (s.product t).filter (Ξ» e , Β¬ G.adj e.1 e.2),
{ refine filter_congr (Ξ» x hx, _),
rw mem_product at hx,
rw [compl_adj, and_iff_right (h.forall_ne_finset hx.1 hx.2)] },
rw [this, βcard_union_eq, filter_union_filter_neg_eq],
exact disjoint_filter.2 (Ξ» x _, not_not.2),
end
lemma edge_density_add_edge_density_compl (hs : s.nonempty) (ht : t.nonempty) (h : disjoint s t) :
G.edge_density s t + GαΆ.edge_density s t = 1 :=
begin
rw [edge_density_def, edge_density_def, div_add_div_same, div_eq_one_iff_eq],
{ exact_mod_cast card_interedges_add_card_interedges_compl _ h },
{ exact_mod_cast (mul_pos hs.card_pos ht.card_pos).ne' }
end
end decidable_eq
lemma card_interedges_le_mul (s t : finset Ξ±) : (G.interedges s t).card β€ s.card * t.card :=
card_interedges_le_mul _ _ _
lemma edge_density_nonneg (s t : finset Ξ±) : 0 β€ G.edge_density s t := edge_density_nonneg _ _ _
lemma edge_density_le_one (s t : finset Ξ±) : G.edge_density s t β€ 1 := edge_density_le_one _ _ _
@[simp] lemma edge_density_empty_left (t : finset Ξ±) : G.edge_density β
t = 0 :=
edge_density_empty_left _ _
@[simp] lemma edge_density_empty_right (s : finset Ξ±) : G.edge_density s β
= 0 :=
edge_density_empty_right _ _
@[simp] lemma swap_mem_interedges_iff {x : Ξ± Γ Ξ±} :
x.swap β G.interedges s t β x β G.interedges t s :=
swap_mem_interedges_iff G.symm
lemma mk_mem_interedges_comm : (a, b) β G.interedges s t β (b, a) β G.interedges t s :=
mk_mem_interedges_comm G.symm
lemma edge_density_comm (s t : finset Ξ±) : G.edge_density s t = G.edge_density t s :=
edge_density_comm G.symm s t
end simple_graph
|
11b531b4557350df2ff8dca029578bdde3624f34 | ebf7140a9ea507409ff4c994124fa36e79b4ae35 | /src/hints/category_theory/exercise4/hint3.lean | 673fbb182b701cb0f7c8115e8c1763d94aa8936f | [] | no_license | fundou/lftcm2020 | 3e88d58a92755ea5dd49f19c36239c35286ecf5e | 99d11bf3bcd71ffeaef0250caa08ecc46e69b55b | refs/heads/master | 1,685,610,799,304 | 1,624,070,416,000 | 1,624,070,416,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 840 | lean | import algebra.category.CommRing
import category_theory.yoneda
import data.polynomial.algebra_map
noncomputable theory
open category_theory
open opposite
open polynomial
/-!
Now let's give the backwards map.
-/
def CommRing_forget_representable : Ξ£ (R : CommRing), (forget CommRing) β
coyoneda.obj (op R) :=
β¨CommRing.of (polynomial β€),
{ hom :=
{ app := Ξ» R r, polynomial.evalβ_ring_hom (algebra_map β€ R) r,
naturality' := sorry, },
inv :=
{ app := Ξ» R f,
begin
dsimp at f,
-- The only possible thing to do is evaluate the ring homomorphism `f` at `X`.
exact f X,
end, },
hom_inv_id' := sorry,
inv_hom_id' := sorry, }β©
-- In fact, notice we didn't write a `sorry` for `naturality'` here:
-- automation could do it automatically.
-- What about the remaining `sorry`s?
|
27415fabe49a506e77c6f8d26305846bf0854ff1 | 2c819623a83d8c53b7282622429e344389ce4030 | /proofs/thm2.lean | 9e9c864439fbe2808be0a222abcebac2d5661e6f | [] | no_license | uw-unsat/jitsynth | 6bc97dd1ede9da42c0b9313a4766095345493adc | 69529e18d4a8d4dace884bfde91aa26b549523fa | refs/heads/master | 1,653,802,737,129 | 1,588,361,732,000 | 1,588,361,732,000 | 260,513,113 | 14 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,304 | lean | import tactic
import tactic.find
import tactic.core
import .lib
import .util.nat
import .util.list
namespace jitsynth
def Naive_param_0 : imp_param β Prop
| param :=
(β n m,
param = imp_param.sparam_sreg n β¨
param = imp_param.sparam_smem n β¨
param = imp_param.sparam_imm n β¨
param = imp_param.treg n β¨
param = imp_param.imm n m)
def Naive_param : β β imp_param β Prop
| 0 param := Naive_param_0 param
| (d+1) param :=
Naive_param_0 param β¨
β subparam f,
Naive_param d subparam β§
param = imp_param.exp f subparam
def Naive_instr : β β imp_instr β Prop
| d (imp_instr.mk op []) := true
| d (imp_instr.mk op (h::t)) :=
Naive_param d h β§
Naive_instr d (imp_instr.mk op t)
def Naive_helper : β β list imp_instr β Prop
| d [] := true
| d (h::t) := Naive_instr d h β§ Naive_helper d t
def Naive : β β β β list imp_instr β Prop
| k d imp := imp.length β€ k β§ Naive_helper d imp
-- TODO derive enumeration somehow
def enumerate_Naive : β β β β β β β
| k d op := k * d * op
/-
-- Same proof for any r/w set mapping
constant rw_param_match : aparam β imp_param β Prop
constant rw_instr_match : β β β β Prop
def RW_param_0 : aparam β imp_param β Prop
| ap ip :=
rw_param_match ap ip β§
(β n m,
ip = imp_param.sparam_sreg n β¨
ip = imp_param.sparam_smem n β¨
ip = imp_param.sparam_imm n β¨
ip = imp_param.treg n β¨
ip = imp_param.imm n m)
def RW_param : β β aparam β imp_param β Prop
| 0 ap ip := RW_param_0 ap ip
| (d+1) ap ip :=
RW_param_0 ap ip β¨
β subparam f,
RW_param d ap ip β§
ip = imp_param.exp f subparam
def RW_params : β β list (aparam Γ imp_param) β Prop
| d [] := true
| d [(ap, ip) :: tl] :=
def RW_instr : β β ainstr β imp_instr β Prop
| d (ainstr.mk aop []) (imp_instr.mk iop []) :=
| d ai (imp_instr.mk op (h::t)) :=
RW_param d h β§
RW_instr d (imp_instr.mk op t)
def RW_helper : β β list imp_instr β Prop
| d [] := true
| d (h::t) := RW_instr d h β§ RW_helper d t
def RW : β β β β list imp_instr β Prop
| k d imp := imp.length β€ k β§ RW_helper d imp
-- TODO parameter loads
-/
-- For completeness, want to say that
-- sketches in RW, PLD, and Naive are finite for given k and d
theorem completeness :
β k d ops : β, β x : β, x = enumerate_Naive k d ops
| k d ops :=
begin
apply exists.intro,
reflexivity
end
-- For soundness, want to say that
-- sketches in RW, PLD, and Naive obey sound_minic
-- when they are correct_impl
theorem soundness :
β k d : β,
β imp : list imp_instr,
β regmap memmap : (βββ),
β s t : arm,
β sai : ainstr,
β sci : cinstr,
β C : (cinstr β list cinstr),
(β params : list β, P sai params = some sci) β
(β ci : cinstr,
remove_option
(concretize_prog regmap memmap ci imp) =
some (C ci)) β
Naive k d imp β
correct_impl regmap memmap s t sai imp β
sound_minic_instr s t C sci
| k d imp regmap memmap s t sai sci C eparams Ch nh cih :=
begin
unfold sound_minic_instr,
intros tp Οs Οt f congh tpch fbound,
unfold correct_impl at cih,
apply cih,
---
apply eparams,
---
apply Ch,
---
repeat {assumption}
end
end jitsynth |
2c2e3181746b44d76379058a7112acd3cf994f5f | 64874bd1010548c7f5a6e3e8902efa63baaff785 | /hott/init/axioms/ua.hlean | ed8bc55286ad6a8d56f38510534ac403c6fbd17e | [
"Apache-2.0"
] | permissive | tjiaqi/lean | 4634d729795c164664d10d093f3545287c76628f | d0ce4cf62f4246b0600c07e074d86e51f2195e30 | refs/heads/master | 1,622,323,796,480 | 1,422,643,069,000 | 1,422,643,069,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,234 | hlean | -- Copyright (c) 2014 Jakob von Raumer. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Author: Jakob von Raumer
-- Ported from Coq HoTT
prelude
import ..path ..equiv
open eq equiv
--Ensure that the types compared are in the same universe
section
universe variable l
variables {A B : Type.{l}}
definition isequiv_path (H : A = B) :=
(@is_equiv.transport Type (Ξ»X, X) A B H)
definition equiv_path (H : A = B) : A β B :=
equiv.mk _ (isequiv_path H)
end
axiom ua_is_equiv (A B : Type) : is_equiv (@equiv_path A B)
-- Make the Equivalence given by the axiom an instance
protected definition inst [instance] (A B : Type) : is_equiv (@equiv_path A B) :=
ua_is_equiv A B
-- This is the version of univalence axiom we will probably use most often
definition ua {A B : Type} : A β B β A = B :=
@is_equiv.inv _ _ (@equiv_path A B) (inst A B)
-- One consequence of UA is that we can transport along equivalencies of types
namespace Equiv
universe variable l
protected definition subst (P : Type β Type) {A B : Type.{l}} (H : A β B)
: P A β P B :=
eq.transport P (ua H)
-- We can use this for calculation evironments
calc_subst subst
end Equiv
|
bddb79dc4b556a8f61685ba72d5ab62e1b92253f | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/algebra/continued_fractions/basic.lean | 88d96c8fb994e0224bb29f5f650fe79697974ceb | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,776 | 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.seq.seq
import algebra.field
/-!
# Basic Definitions/Theorems for Continued Fractions
## Summary
We define generalised, simple, and regular continued fractions and functions to evaluate their
convergents. We follow the naming conventions from Wikipedia and [wall2018analytic], Chapter 1.
## Main definitions
1. Generalised continued fractions (gcfs)
2. Simple continued fractions (scfs)
3. (Regular) continued fractions ((r)cfs)
4. Computation of convergents using the recurrence relation in `convergents`.
5. Computation of convergents by directly evaluating the fraction described by the gcf in
`convergents'`.
## Implementation notes
1. The most commonly used kind of continued fractions in the literature are regular continued
fractions. We hence just call them `continued_fractions` in the library.
2. We use sequences from `data.seq` to encode potentially infinite sequences.
## References
- <https://en.wikipedia.org/wiki/Generalized_continued_fraction>
- [Wall, H.S., *Analytic Theory of Continued Fractions*][wall2018analytic]
## Tags
numerics, number theory, approximations, fractions
-/
-- Fix a carrier `Ξ±`.
variable (Ξ± : Type*)
/-!### Definitions-/
/-- We collect a partial numerator `aα΅’` and partial denominator `bα΅’` in a pair `β¨aα΅’,bα΅’β©`. -/
@[derive inhabited]
protected structure generalized_continued_fraction.pair := (a : Ξ±) (b : Ξ±)
open generalized_continued_fraction
/-! Interlude: define some expected coercions and instances. -/
namespace generalized_continued_fraction.pair
variable {Ξ±}
/-- Make a `gcf.pair` printable. -/
instance [has_repr Ξ±] : has_repr (pair Ξ±) :=
β¨Ξ» p, "(a : " ++ (repr p.a) ++ ", b : " ++ (repr p.b) ++ ")"β©
/-- Maps a function `f` on both components of a given pair. -/
def map {Ξ² : Type*} (f : Ξ± β Ξ²) (gp : pair Ξ±) : pair Ξ² :=
β¨f gp.a, f gp.bβ©
section coe
/- Fix another type `Ξ²` which we will convert to. -/
variables {Ξ² : Type*} [has_coe Ξ± Ξ²]
/-- Coerce a pair by elementwise coercion. -/
instance has_coe_to_generalized_continued_fraction_pair : has_coe (pair Ξ±) (pair Ξ²) :=
β¨map coeβ©
@[simp, norm_cast]
lemma coe_to_generalized_continued_fraction_pair {a b : Ξ±} :
(β(pair.mk a b) : pair Ξ²) = pair.mk (a : Ξ²) (b : Ξ²) := rfl
end coe
end generalized_continued_fraction.pair
variable (Ξ±)
/--
A *generalised continued fraction* (gcf) is a potentially infinite expression of the form
aβ
h + ---------------------------
aβ
bβ + --------------------
aβ
bβ + --------------
aβ
bβ + --------
bβ + ...
where `h` is called the *head term* or *integer part*, the `aα΅’` are called the
*partial numerators* and the `bα΅’` the *partial denominators* of the gcf.
We store the sequence of partial numerators and denominators in a sequence of
generalized_continued_fraction.pairs `s`.
For convenience, one often writes `[h; (aβ, bβ), (aβ, bβ), (aβ, bβ),...]`.
-/
structure generalized_continued_fraction :=
(h : Ξ±) (s : seq $ pair Ξ±)
variable {Ξ±}
namespace generalized_continued_fraction
/-- Constructs a generalized continued fraction without fractional part. -/
def of_integer (a : Ξ±) : generalized_continued_fraction Ξ± :=
β¨a, seq.nilβ©
instance [inhabited Ξ±] : inhabited (generalized_continued_fraction Ξ±) := β¨of_integer (default _)β©
/-- Returns the sequence of partial numerators `aα΅’` of `g`. -/
def partial_numerators (g : generalized_continued_fraction Ξ±) : seq Ξ± :=
g.s.map pair.a
/-- Returns the sequence of partial denominators `bα΅’` of `g`. -/
def partial_denominators (g : generalized_continued_fraction Ξ±) : seq Ξ± :=
g.s.map pair.b
/-- A gcf terminated at position `n` if its sequence terminates at position `n`. -/
def terminated_at (g : generalized_continued_fraction Ξ±) (n : β) : Prop := g.s.terminated_at n
/-- It is decidable whether a gcf terminated at a given position. -/
instance terminated_at_decidable (g : generalized_continued_fraction Ξ±) (n : β) :
decidable (g.terminated_at n) :=
by { unfold terminated_at, apply_instance }
/-- A gcf terminates if its sequence terminates. -/
def terminates (g : generalized_continued_fraction Ξ±) : Prop := g.s.terminates
section coe
/-! Interlude: define some expected coercions. -/
/- Fix another type `Ξ²` which we will convert to. -/
variables {Ξ² : Type*} [has_coe Ξ± Ξ²]
/-- Coerce a gcf by elementwise coercion. -/
instance has_coe_to_generalized_continued_fraction :
has_coe (generalized_continued_fraction Ξ±) (generalized_continued_fraction Ξ²) :=
β¨Ξ» g, β¨(g.h : Ξ²), (g.s.map coe : seq $ pair Ξ²)β©β©
@[simp, norm_cast]
lemma coe_to_generalized_continued_fraction {g : generalized_continued_fraction Ξ±} :
(β(g : generalized_continued_fraction Ξ±) : generalized_continued_fraction Ξ²) =
β¨(g.h : Ξ²), (g.s.map coe : seq $ pair Ξ²)β© :=
rfl
end coe
end generalized_continued_fraction
/--
A generalized continued fraction is a *simple continued fraction* if all partial numerators are
equal to one.
1
h + ---------------------------
1
bβ + --------------------
1
bβ + --------------
1
bβ + --------
bβ + ...
-/
def generalized_continued_fraction.is_simple_continued_fraction
(g : generalized_continued_fraction Ξ±) [has_one Ξ±] : Prop :=
β (n : β) (aβ : Ξ±), g.partial_numerators.nth n = some aβ β aβ = 1
variable (Ξ±)
/--
A *simple continued fraction* (scf) is a generalized continued fraction (gcf) whose partial
numerators are equal to one.
1
h + ---------------------------
1
bβ + --------------------
1
bβ + --------------
1
bβ + --------
bβ + ...
For convenience, one often writes `[h; bβ, bβ, bβ,...]`.
It is encoded as the subtype of gcfs that satisfy
`generalized_continued_fraction.is_simple_continued_fraction`.
-/
def simple_continued_fraction [has_one Ξ±] :=
{g : generalized_continued_fraction Ξ± // g.is_simple_continued_fraction}
variable {Ξ±}
/- Interlude: define some expected coercions. -/
namespace simple_continued_fraction
variable [has_one Ξ±]
/-- Constructs a simple continued fraction without fractional part. -/
def of_integer (a : Ξ±) : simple_continued_fraction Ξ± :=
β¨generalized_continued_fraction.of_integer a, Ξ» n aβ h, by cases hβ©
instance : inhabited (simple_continued_fraction Ξ±) := β¨of_integer 1β©
/-- Lift a scf to a gcf using the inclusion map. -/
instance has_coe_to_generalized_continued_fraction :
has_coe (simple_continued_fraction Ξ±) (generalized_continued_fraction Ξ±) :=
by {unfold simple_continued_fraction, apply_instance}
lemma coe_to_generalized_continued_fraction {s : simple_continued_fraction Ξ±} :
(βs : generalized_continued_fraction Ξ±) = s.val := rfl
end simple_continued_fraction
/--
A simple continued fraction is a *(regular) continued fraction* ((r)cf) if all partial denominators
`bα΅’` are positive, i.e. `0 < bα΅’`.
-/
def simple_continued_fraction.is_continued_fraction [has_one Ξ±] [has_zero Ξ±] [has_lt Ξ±]
(s : simple_continued_fraction Ξ±) : Prop :=
β (n : β) (bβ : Ξ±),
(βs : generalized_continued_fraction Ξ±).partial_denominators.nth n = some bβ β 0 < bβ
variable (Ξ±)
/--
A *(regular) continued fraction* ((r)cf) is a simple continued fraction (scf) whose partial
denominators are all positive. It is the subtype of scfs that satisfy
`simple_continued_fraction.is_continued_fraction`.
-/
def continued_fraction [has_one Ξ±] [has_zero Ξ±] [has_lt Ξ±] :=
{s : simple_continued_fraction Ξ± // s.is_continued_fraction}
variable {Ξ±}
/-! Interlude: define some expected coercions. -/
namespace continued_fraction
variables [has_one Ξ±] [has_zero Ξ±] [has_lt Ξ±]
/-- Constructs a continued fraction without fractional part. -/
def of_integer (a : Ξ±) : continued_fraction Ξ± :=
β¨simple_continued_fraction.of_integer a, Ξ» n bβ h, by cases hβ©
instance : inhabited (continued_fraction Ξ±) := β¨of_integer 0β©
/-- Lift a cf to a scf using the inclusion map. -/
instance has_coe_to_simple_continued_fraction :
has_coe (continued_fraction Ξ±) (simple_continued_fraction Ξ±) :=
by {unfold continued_fraction, apply_instance}
lemma coe_to_simple_continued_fraction {c : continued_fraction Ξ±} :
(βc : simple_continued_fraction Ξ±) = c.val := rfl
/-- Lift a cf to a scf using the inclusion map. -/
instance has_coe_to_generalized_continued_fraction :
has_coe (continued_fraction Ξ±) (generalized_continued_fraction Ξ±) :=
β¨Ξ» c, β(βc : simple_continued_fraction Ξ±)β©
lemma coe_to_generalized_continued_fraction {c : continued_fraction Ξ±} :
(βc : generalized_continued_fraction Ξ±) = c.val := rfl
end continued_fraction
namespace generalized_continued_fraction
/-!
### Computation of Convergents
We now define how to compute the convergents of a gcf. There are two standard ways to do this:
directly evaluating the (infinite) fraction described by the gcf or using a recurrence relation.
For (r)cfs, these computations are equivalent as shown in
`algebra.continued_fractions.convergents_equiv`.
-/
-- Fix a division ring for the computations.
variables {K : Type*} [division_ring K]
/-!
We start with the definition of the recurrence relation. Given a gcf `g`, for all `n β₯ 1`, we define
- `Aββ = 1, Aβ = h, Aβ = bβββ * Aβββ + aβββ * Aβββ`, and
- `Bββ = 0, Bβ = 1, Bβ = bβββ * Bβββ + aβββ * Bβββ`.
`Aβ, `Bβ` are called the *nth continuants*, Aβ the *nth numerator*, and `Bβ` the
*nth denominator* of `g`. The *nth convergent* of `g` is given by `Aβ / Bβ`.
-/
/--
Returns the next numerator `Aβ = bβββ * Aβββ + aβββ * Aβββ`, where `predA` is `Aβββ`,
`ppredA` is `Aβββ`, `a` is `aβββ`, and `b` is `bβββ`.
-/
def next_numerator (a b ppredA predA : K) : K := b * predA + a * ppredA
/--
Returns the next denominator `Bβ = bβββ * Bβββ + aβββ * Bβββ``, where `predB` is `Bβββ` and
`ppredB` is `Bβββ`, `a` is `aβββ`, and `b` is `bβββ`.
-/
def next_denominator (aβ bβ ppredB predB : K) : K := bβ * predB + aβ * ppredB
/--
Returns the next continuants `β¨Aβ, Bββ©` using `next_numerator` and `next_denominator`, where `pred`
is `β¨Aβββ, Bββββ©`, `ppred` is `β¨Aβββ, Bββββ©`, `a` is `aβββ`, and `b` is `bβββ`.
-/
def next_continuants (a b : K) (ppred pred : pair K) : pair K :=
β¨next_numerator a b ppred.a pred.a, next_denominator a b ppred.b pred.bβ©
/-- Returns the continuants `β¨Aβββ, Bββββ©` of `g`. -/
def continuants_aux (g : generalized_continued_fraction K) : stream (pair K)
| 0 := β¨1, 0β©
| 1 := β¨g.h, 1β©
| (n + 2) :=
match g.s.nth n with
| none := continuants_aux (n + 1)
| some gp := next_continuants gp.a gp.b (continuants_aux n) (continuants_aux $ n + 1)
end
/-- Returns the continuants `β¨Aβ, Bββ©` of `g`. -/
def continuants (g : generalized_continued_fraction K) : stream (pair K) :=
g.continuants_aux.tail
/-- Returns the numerators `Aβ` of `g`. -/
def numerators (g : generalized_continued_fraction K) : stream K :=
g.continuants.map pair.a
/-- Returns the denominators `Bβ` of `g`. -/
def denominators (g : generalized_continued_fraction K) : stream K :=
g.continuants.map pair.b
/-- Returns the convergents `Aβ / Bβ` of `g`, where `Aβ, Bβ` are the nth continuants of `g`. -/
def convergents (g : generalized_continued_fraction K) : stream K :=
Ξ» (n : β), (g.numerators n) / (g.denominators n)
/--
Returns the approximation of the fraction described by the given sequence up to a given position n.
For example, `convergents'_aux [(1, 2), (3, 4), (5, 6)] 2 = 1 / (2 + 3 / 4)` and
`convergents'_aux [(1, 2), (3, 4), (5, 6)] 0 = 0`.
-/
def convergents'_aux : seq (pair K) β β β K
| s 0 := 0
| s (n + 1) := match s.head with
| none := 0
| some gp := gp.a / (gp.b + convergents'_aux s.tail n)
end
/--
Returns the convergents of `g` by evaluating the fraction described by `g` up to a given
position `n`. For example, `convergents' [9; (1, 2), (3, 4), (5, 6)] 2 = 9 + 1 / (2 + 3 / 4)` and
`convergents' [9; (1, 2), (3, 4), (5, 6)] 0 = 9`
-/
def convergents' (g : generalized_continued_fraction K) (n : β) : K := g.h + convergents'_aux g.s n
end generalized_continued_fraction
-- Now, some basic, general theorems
namespace generalized_continued_fraction
/-- Two gcfs `g` and `g'` are equal if and only if their components are equal. -/
protected lemma ext_iff {g g' : generalized_continued_fraction Ξ±} :
g = g' β g.h = g'.h β§ g.s = g'.s :=
by { cases g, cases g', simp }
@[ext]
protected lemma ext {g g' : generalized_continued_fraction Ξ±} (hyp : g.h = g'.h β§ g.s = g'.s) :
g = g' :=
generalized_continued_fraction.ext_iff.elim_right hyp
end generalized_continued_fraction
|
2ab0db570253c199198a06ce5c1e36d53ec5dce5 | 4fa161becb8ce7378a709f5992a594764699e268 | /src/data/equiv/ring.lean | f0cd6c2f3b305afd5a4476d8a23ae086c0e39344 | [
"Apache-2.0"
] | permissive | laughinggas/mathlib | e4aa4565ae34e46e834434284cb26bd9d67bc373 | 86dcd5cda7a5017c8b3c8876c89a510a19d49aad | refs/heads/master | 1,669,496,232,688 | 1,592,831,995,000 | 1,592,831,995,000 | 274,155,979 | 0 | 0 | Apache-2.0 | 1,592,835,190,000 | 1,592,835,189,000 | null | UTF-8 | Lean | false | false | 10,889 | lean | /-
Copyright (c) 2018 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl, Callum Sutton, Yury Kudryashov
-/
import data.equiv.mul_add
import algebra.field
import algebra.opposites
import deprecated.ring
/-!
# (Semi)ring equivs
In this file we define extension of `equiv` called `ring_equiv`, which is a datatype representing an
isomorphism of `semiring`s, `ring`s, `division_ring`s, or `field`s. We also introduce the
corresponding group of automorphisms `ring_aut`.
## Notations
The extended equiv have coercions to functions, and the coercion is the canonical notation when
treating the isomorphism as maps.
## Implementation notes
The fields for `ring_equiv` now avoid the unbundled `is_mul_hom` and `is_add_hom`, as these are
deprecated.
Definition of multiplication in the groups of automorphisms agrees with function composition,
multiplication in `equiv.perm`, and multiplication in `category_theory.End`, not with
`category_theory.comp`.
## Tags
equiv, mul_equiv, add_equiv, ring_equiv, mul_aut, add_aut, ring_aut
-/
variables {R : Type*} {S : Type*} {S' : Type*}
set_option old_structure_cmd true
/- (semi)ring equivalence. -/
structure ring_equiv (R S : Type*) [has_mul R] [has_add R] [has_mul S] [has_add S]
extends R β S, R β* S, R β+ S
infix ` β+* `:25 := ring_equiv
namespace ring_equiv
section basic
variables [has_mul R] [has_add R] [has_mul S] [has_add S] [has_mul S'] [has_add S']
instance : has_coe_to_fun (R β+* S) := β¨_, ring_equiv.to_funβ©
@[simp] lemma to_fun_eq_coe_fun (f : R β+* S) : f.to_fun = f := rfl
instance has_coe_to_mul_equiv : has_coe (R β+* S) (R β* S) := β¨ring_equiv.to_mul_equivβ©
instance has_coe_to_add_equiv : has_coe (R β+* S) (R β+ S) := β¨ring_equiv.to_add_equivβ©
@[norm_cast] lemma coe_mul_equiv (f : R β+* S) (a : R) :
(f : R β* S) a = f a := rfl
@[norm_cast] lemma coe_add_equiv (f : R β+* S) (a : R) :
(f : R β+ S) a = f a := rfl
variable (R)
/-- The identity map is a ring isomorphism. -/
@[refl] protected def refl : R β+* R := { .. mul_equiv.refl R, .. add_equiv.refl R }
@[simp] lemma refl_apply (x : R) : ring_equiv.refl R x = x := rfl
@[simp] lemma coe_add_equiv_refl : (ring_equiv.refl R : R β+ R) = add_equiv.refl R := rfl
@[simp] lemma coe_mul_equiv_refl : (ring_equiv.refl R : R β* R) = mul_equiv.refl R := rfl
variables {R}
/-- The inverse of a ring isomorphism is a ring isomorphism. -/
@[symm] protected def symm (e : R β+* S) : S β+* R :=
{ .. e.to_mul_equiv.symm, .. e.to_add_equiv.symm }
/-- Transitivity of `ring_equiv`. -/
@[trans] protected def trans (eβ : R β+* S) (eβ : S β+* S') : R β+* S' :=
{ .. (eβ.to_mul_equiv.trans eβ.to_mul_equiv), .. (eβ.to_add_equiv.trans eβ.to_add_equiv) }
protected lemma bijective (e : R β+* S) : function.bijective e := e.to_equiv.bijective
protected lemma injective (e : R β+* S) : function.injective e := e.to_equiv.injective
protected lemma surjective (e : R β+* S) : function.surjective e := e.to_equiv.surjective
@[simp] lemma apply_symm_apply (e : R β+* S) : β x, e (e.symm x) = x := e.to_equiv.apply_symm_apply
@[simp] lemma symm_apply_apply (e : R β+* S) : β x, e.symm (e x) = x := e.to_equiv.symm_apply_apply
lemma image_eq_preimage (e : R β+* S) (s : set R) : e '' s = e.symm β»ΒΉ' s :=
e.to_equiv.image_eq_preimage s
end basic
section comm_semiring
open opposite
variables (R) [comm_semiring R]
/-- A commutative ring is isomorphic to its opposite. -/
def to_opposite : R β+* Rα΅α΅ :=
{ map_add' := Ξ» x y, rfl,
map_mul' := Ξ» x y, mul_comm (op y) (op x),
..equiv_to_opposite }
@[simp]
lemma to_opposite_apply (r : R) : to_opposite R r = op r := rfl
@[simp]
lemma to_opposite_symm_apply (r : Rα΅α΅) : (to_opposite R).symm r = unop r := rfl
end comm_semiring
section
variables [semiring R] [semiring S] (f : R β+* S) (x y : R)
/-- A ring isomorphism preserves multiplication. -/
@[simp] lemma map_mul : f (x * y) = f x * f y := f.map_mul' x y
/-- A ring isomorphism sends one to one. -/
@[simp] lemma map_one : f 1 = 1 := (f : R β* S).map_one
/-- A ring isomorphism preserves addition. -/
@[simp] lemma map_add : f (x + y) = f x + f y := f.map_add' x y
/-- A ring isomorphism sends zero to zero. -/
@[simp] lemma map_zero : f 0 = 0 := (f : R β+ S).map_zero
variable {x}
@[simp] lemma map_eq_one_iff : f x = 1 β x = 1 := (f : R β* S).map_eq_one_iff
@[simp] lemma map_eq_zero_iff : f x = 0 β x = 0 := (f : R β+ S).map_eq_zero_iff
lemma map_ne_one_iff : f x β 1 β x β 1 := (f : R β* S).map_ne_one_iff
lemma map_ne_zero_iff : f x β 0 β x β 0 := (f : R β+ S).map_ne_zero_iff
end
section
variables [ring R] [ring S] (f : R β+* S) (x y : R)
@[simp] lemma map_neg : f (-x) = -f x := (f : R β+ S).map_neg x
@[simp] lemma map_sub : f (x - y) = f x - f y := (f : R β+ S).map_sub x y
@[simp] lemma map_neg_one : f (-1) = -1 := f.map_one βΈ f.map_neg 1
end
section semiring_hom
variables [semiring R] [semiring S]
/-- Reinterpret a ring equivalence as a ring homomorphism. -/
def to_ring_hom (e : R β+* S) : R β+* S :=
{ .. e.to_mul_equiv.to_monoid_hom, .. e.to_add_equiv.to_add_monoid_hom }
/-- Reinterpret a ring equivalence as a monoid homomorphism. -/
abbreviation to_monoid_hom (e : R β+* S) : R β* S := e.to_ring_hom.to_monoid_hom
/-- Reinterpret a ring equivalence as an `add_monoid` homomorphism. -/
abbreviation to_add_monoid_hom (e : R β+* S) : R β+ S := e.to_ring_hom.to_add_monoid_hom
/-- Interpret an equivalence `f : R β S` as a ring equivalence `R β+* S`. -/
def of (e : R β S) [is_semiring_hom e] : R β+* S :=
{ .. e, .. monoid_hom.of e, .. add_monoid_hom.of e }
instance (e : R β+* S) : is_semiring_hom e := e.to_ring_hom.is_semiring_hom
@[simp]
lemma to_ring_hom_refl : (ring_equiv.refl R).to_ring_hom = ring_hom.id R := rfl
@[simp]
lemma to_monoid_hom_refl : (ring_equiv.refl R).to_monoid_hom = monoid_hom.id R := rfl
@[simp]
lemma to_add_monoid_hom_refl : (ring_equiv.refl R).to_add_monoid_hom = add_monoid_hom.id R := rfl
@[simp]
lemma to_ring_hom_apply_symm_to_ring_hom_apply {R S} [semiring R] [semiring S] (e : R β+* S) :
β (y : S), e.to_ring_hom (e.symm.to_ring_hom y) = y :=
e.to_equiv.apply_symm_apply
@[simp]
lemma symm_to_ring_hom_apply_to_ring_hom_apply {R S} [semiring R] [semiring S] (e : R β+* S) :
β (x : R), e.symm.to_ring_hom (e.to_ring_hom x) = x :=
equiv.symm_apply_apply (e.to_equiv)
end semiring_hom
end ring_equiv
namespace mul_equiv
/-- Gives an `is_semiring_hom` instance from a `mul_equiv` of semirings that preserves addition. -/
protected lemma to_semiring_hom {R : Type*} {S : Type*} [semiring R] [semiring S]
(h : R β* S) (H : β x y : R, h (x + y) = h x + h y) : is_semiring_hom h :=
β¨add_equiv.map_zero $ add_equiv.mk' h.to_equiv H, h.map_one, H, h.5β©
/-- Gives a `ring_equiv` from a `mul_equiv` preserving addition.-/
def to_ring_equiv {R : Type*} {S : Type*} [has_add R] [has_add S] [has_mul R] [has_mul S]
(h : R β* S) (H : β x y : R, h (x + y) = h x + h y) : R β+* S :=
{..h.to_equiv, ..h, ..add_equiv.mk' h.to_equiv H }
end mul_equiv
namespace add_equiv
/-- Gives an `is_semiring_hom` instance from a `mul_equiv` of semirings that preserves addition. -/
protected lemma to_semiring_hom {R : Type*} {S : Type*} [semiring R] [semiring S]
(h : R β+ S) (H : β x y : R, h (x * y) = h x * h y) : is_semiring_hom h :=
β¨h.map_zero, mul_equiv.map_one $ mul_equiv.mk' h.to_equiv H, h.5, Hβ©
end add_equiv
namespace ring_equiv
section ring_hom
variables [ring R] [ring S]
/-- Interpret an equivalence `f : R β S` as a ring equivalence `R β+* S`. -/
def of' (e : R β S) [is_ring_hom e] : R β+* S :=
{ .. e, .. monoid_hom.of e, .. add_monoid_hom.of e }
instance (e : R β+* S) : is_ring_hom e := e.to_ring_hom.is_ring_hom
end ring_hom
/-- Two ring isomorphisms agree if they are defined by the
same underlying function. -/
@[ext] lemma ext {R S : Type*} [has_mul R] [has_add R] [has_mul S] [has_add S]
{f g : R β+* S} (h : β x, f x = g x) : f = g :=
begin
have hβ : f.to_equiv = g.to_equiv := equiv.ext h,
cases f, cases g, congr,
{ exact (funext h) },
{ exact congr_arg equiv.inv_fun hβ }
end
/-- If two rings are isomorphic, and the second is an integral domain, then so is the first. -/
protected lemma is_integral_domain {A : Type*} (B : Type*) [ring A] [ring B]
(hB : is_integral_domain B) (e : A β+* B) : is_integral_domain A :=
{ mul_comm := Ξ» x y, have e.symm (e x * e y) = e.symm (e y * e x), by rw hB.mul_comm, by simpa,
eq_zero_or_eq_zero_of_mul_eq_zero := Ξ» x y hxy,
have e x * e y = 0, by rw [β e.map_mul, hxy, e.map_zero],
(hB.eq_zero_or_eq_zero_of_mul_eq_zero _ _ this).imp (Ξ» hx, by simpa using congr_arg e.symm hx)
(Ξ» hy, by simpa using congr_arg e.symm hy),
zero_ne_one := Ξ» H, hB.zero_ne_one $ by rw [β e.map_zero, β e.map_one, H] }
/-- If two rings are isomorphic, and the second is an integral domain, then so is the first. -/
protected def integral_domain {A : Type*} (B : Type*) [ring A] [integral_domain B]
(e : A β+* B) : integral_domain A :=
{ .. (βΉ_βΊ : ring A), .. e.is_integral_domain B (integral_domain.to_is_integral_domain B) }
end ring_equiv
/-- The group of ring automorphisms. -/
@[reducible] def ring_aut (R : Type*) [has_mul R] [has_add R] := ring_equiv R R
namespace ring_aut
variables (R) [has_mul R] [has_add R]
/--
The group operation on automorphisms of a ring is defined by
Ξ» g h, ring_equiv.trans h g.
This means that multiplication agrees with composition, (g*h)(x) = g (h x) .
-/
instance : group (ring_aut R) :=
by refine_struct
{ mul := Ξ» g h, ring_equiv.trans h g,
one := ring_equiv.refl R,
inv := ring_equiv.symm };
intros; ext; try { refl }; apply equiv.left_inv
instance : inhabited (ring_aut R) := β¨1β©
/-- Monoid homomorphism from ring automorphisms to additive automorphisms. -/
def to_add_aut : ring_aut R β* add_aut R :=
by refine_struct { to_fun := ring_equiv.to_add_equiv }; intros; refl
/-- Monoid homomorphism from ring automorphisms to multiplicative automorphisms. -/
def to_mul_aut : ring_aut R β* mul_aut R :=
by refine_struct { to_fun := ring_equiv.to_mul_equiv }; intros; refl
/-- Monoid homomorphism from ring automorphisms to permutations. -/
def to_perm : ring_aut R β* equiv.perm R :=
by refine_struct { to_fun := ring_equiv.to_equiv }; intros; refl
end ring_aut
namespace equiv
variables (K : Type*) [division_ring K]
def units_equiv_ne_zero : units K β {a : K | a β 0} :=
β¨Ξ» a, β¨a.1, a.coe_ne_zeroβ©, Ξ» a, units.mk0 _ a.2, Ξ» β¨_, _, _, _β©, units.ext rfl, Ξ» β¨_, _β©, rflβ©
variable {K}
@[simp]
lemma coe_units_equiv_ne_zero (a : units K) :
((units_equiv_ne_zero K a) : K) = a := rfl
end equiv
|
2e114a1a56ca34ee1c0d084ecd6cb94fb5415139 | 624f6f2ae8b3b1adc5f8f67a365c51d5126be45a | /stage0/src/Init/Lean/Meta/Tactic/LocalDecl.lean | eb51efce3c4fd38663469f473a3a5afa75360c48 | [
"Apache-2.0"
] | permissive | mhuisi/lean4 | 28d35a4febc2e251c7f05492e13f3b05d6f9b7af | dda44bc47f3e5d024508060dac2bcb59fd12e4c0 | refs/heads/master | 1,621,225,489,283 | 1,585,142,689,000 | 1,585,142,689,000 | 250,590,438 | 0 | 2 | Apache-2.0 | 1,602,443,220,000 | 1,585,327,814,000 | C | UTF-8 | Lean | false | false | 832 | lean | /-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Lean.Meta.AppBuilder
import Init.Lean.Meta.Tactic.Util
import Init.Lean.Meta.Tactic.Assert
import Init.Lean.Meta.Tactic.Intro
import Init.Lean.Meta.Tactic.Clear
namespace Lean
namespace Meta
def replaceLocalDecl (mvarId : MVarId) (fvarId : FVarId) (newType : Expr) (eqProof : Expr) : MetaM (FVarId Γ MVarId) := do
withMVarContext mvarId $ do
localDecl β getLocalDecl fvarId;
newTypePr β mkEqMP eqProof (mkFVar fvarId);
mvarId β assert mvarId localDecl.userName newType newTypePr;
(fvarIdNew, mvarId) β intro1 mvarId;
(do mvarId β clear mvarId fvarId; pure (fvarIdNew, mvarId)) <|> pure (fvarIdNew, mvarId)
end Meta
end Lean
|
de7a1167edabc7a3409699b1c0aea8d4791e6731 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/simpperf/pre500.lean | 1f938dbd19cfbc43d636c5675ef1e8d0bf010f78 | [
"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 | 42,032 | lean | axiom f (x : Prop) : Prop
axiom g0 (x : Prop) : Prop
axiom g1 (x : Prop) : Prop
axiom g2 (x : Prop) : Prop
axiom g3 (x : Prop) : Prop
axiom g4 (x : Prop) : Prop
axiom g5 (x : Prop) : Prop
axiom g6 (x : Prop) : Prop
axiom g7 (x : Prop) : Prop
axiom g8 (x : Prop) : Prop
axiom g9 (x : Prop) : Prop
axiom g10 (x : Prop) : Prop
axiom g11 (x : Prop) : Prop
axiom g12 (x : Prop) : Prop
axiom g13 (x : Prop) : Prop
axiom g14 (x : Prop) : Prop
axiom g15 (x : Prop) : Prop
axiom g16 (x : Prop) : Prop
axiom g17 (x : Prop) : Prop
axiom g18 (x : Prop) : Prop
axiom g19 (x : Prop) : Prop
axiom g20 (x : Prop) : Prop
axiom g21 (x : Prop) : Prop
axiom g22 (x : Prop) : Prop
axiom g23 (x : Prop) : Prop
axiom g24 (x : Prop) : Prop
axiom g25 (x : Prop) : Prop
axiom g26 (x : Prop) : Prop
axiom g27 (x : Prop) : Prop
axiom g28 (x : Prop) : Prop
axiom g29 (x : Prop) : Prop
axiom g30 (x : Prop) : Prop
axiom g31 (x : Prop) : Prop
axiom g32 (x : Prop) : Prop
axiom g33 (x : Prop) : Prop
axiom g34 (x : Prop) : Prop
axiom g35 (x : Prop) : Prop
axiom g36 (x : Prop) : Prop
axiom g37 (x : Prop) : Prop
axiom g38 (x : Prop) : Prop
axiom g39 (x : Prop) : Prop
axiom g40 (x : Prop) : Prop
axiom g41 (x : Prop) : Prop
axiom g42 (x : Prop) : Prop
axiom g43 (x : Prop) : Prop
axiom g44 (x : Prop) : Prop
axiom g45 (x : Prop) : Prop
axiom g46 (x : Prop) : Prop
axiom g47 (x : Prop) : Prop
axiom g48 (x : Prop) : Prop
axiom g49 (x : Prop) : Prop
axiom g50 (x : Prop) : Prop
axiom g51 (x : Prop) : Prop
axiom g52 (x : Prop) : Prop
axiom g53 (x : Prop) : Prop
axiom g54 (x : Prop) : Prop
axiom g55 (x : Prop) : Prop
axiom g56 (x : Prop) : Prop
axiom g57 (x : Prop) : Prop
axiom g58 (x : Prop) : Prop
axiom g59 (x : Prop) : Prop
axiom g60 (x : Prop) : Prop
axiom g61 (x : Prop) : Prop
axiom g62 (x : Prop) : Prop
axiom g63 (x : Prop) : Prop
axiom g64 (x : Prop) : Prop
axiom g65 (x : Prop) : Prop
axiom g66 (x : Prop) : Prop
axiom g67 (x : Prop) : Prop
axiom g68 (x : Prop) : Prop
axiom g69 (x : Prop) : Prop
axiom g70 (x : Prop) : Prop
axiom g71 (x : Prop) : Prop
axiom g72 (x : Prop) : Prop
axiom g73 (x : Prop) : Prop
axiom g74 (x : Prop) : Prop
axiom g75 (x : Prop) : Prop
axiom g76 (x : Prop) : Prop
axiom g77 (x : Prop) : Prop
axiom g78 (x : Prop) : Prop
axiom g79 (x : Prop) : Prop
axiom g80 (x : Prop) : Prop
axiom g81 (x : Prop) : Prop
axiom g82 (x : Prop) : Prop
axiom g83 (x : Prop) : Prop
axiom g84 (x : Prop) : Prop
axiom g85 (x : Prop) : Prop
axiom g86 (x : Prop) : Prop
axiom g87 (x : Prop) : Prop
axiom g88 (x : Prop) : Prop
axiom g89 (x : Prop) : Prop
axiom g90 (x : Prop) : Prop
axiom g91 (x : Prop) : Prop
axiom g92 (x : Prop) : Prop
axiom g93 (x : Prop) : Prop
axiom g94 (x : Prop) : Prop
axiom g95 (x : Prop) : Prop
axiom g96 (x : Prop) : Prop
axiom g97 (x : Prop) : Prop
axiom g98 (x : Prop) : Prop
axiom g99 (x : Prop) : Prop
axiom g100 (x : Prop) : Prop
axiom g101 (x : Prop) : Prop
axiom g102 (x : Prop) : Prop
axiom g103 (x : Prop) : Prop
axiom g104 (x : Prop) : Prop
axiom g105 (x : Prop) : Prop
axiom g106 (x : Prop) : Prop
axiom g107 (x : Prop) : Prop
axiom g108 (x : Prop) : Prop
axiom g109 (x : Prop) : Prop
axiom g110 (x : Prop) : Prop
axiom g111 (x : Prop) : Prop
axiom g112 (x : Prop) : Prop
axiom g113 (x : Prop) : Prop
axiom g114 (x : Prop) : Prop
axiom g115 (x : Prop) : Prop
axiom g116 (x : Prop) : Prop
axiom g117 (x : Prop) : Prop
axiom g118 (x : Prop) : Prop
axiom g119 (x : Prop) : Prop
axiom g120 (x : Prop) : Prop
axiom g121 (x : Prop) : Prop
axiom g122 (x : Prop) : Prop
axiom g123 (x : Prop) : Prop
axiom g124 (x : Prop) : Prop
axiom g125 (x : Prop) : Prop
axiom g126 (x : Prop) : Prop
axiom g127 (x : Prop) : Prop
axiom g128 (x : Prop) : Prop
axiom g129 (x : Prop) : Prop
axiom g130 (x : Prop) : Prop
axiom g131 (x : Prop) : Prop
axiom g132 (x : Prop) : Prop
axiom g133 (x : Prop) : Prop
axiom g134 (x : Prop) : Prop
axiom g135 (x : Prop) : Prop
axiom g136 (x : Prop) : Prop
axiom g137 (x : Prop) : Prop
axiom g138 (x : Prop) : Prop
axiom g139 (x : Prop) : Prop
axiom g140 (x : Prop) : Prop
axiom g141 (x : Prop) : Prop
axiom g142 (x : Prop) : Prop
axiom g143 (x : Prop) : Prop
axiom g144 (x : Prop) : Prop
axiom g145 (x : Prop) : Prop
axiom g146 (x : Prop) : Prop
axiom g147 (x : Prop) : Prop
axiom g148 (x : Prop) : Prop
axiom g149 (x : Prop) : Prop
axiom g150 (x : Prop) : Prop
axiom g151 (x : Prop) : Prop
axiom g152 (x : Prop) : Prop
axiom g153 (x : Prop) : Prop
axiom g154 (x : Prop) : Prop
axiom g155 (x : Prop) : Prop
axiom g156 (x : Prop) : Prop
axiom g157 (x : Prop) : Prop
axiom g158 (x : Prop) : Prop
axiom g159 (x : Prop) : Prop
axiom g160 (x : Prop) : Prop
axiom g161 (x : Prop) : Prop
axiom g162 (x : Prop) : Prop
axiom g163 (x : Prop) : Prop
axiom g164 (x : Prop) : Prop
axiom g165 (x : Prop) : Prop
axiom g166 (x : Prop) : Prop
axiom g167 (x : Prop) : Prop
axiom g168 (x : Prop) : Prop
axiom g169 (x : Prop) : Prop
axiom g170 (x : Prop) : Prop
axiom g171 (x : Prop) : Prop
axiom g172 (x : Prop) : Prop
axiom g173 (x : Prop) : Prop
axiom g174 (x : Prop) : Prop
axiom g175 (x : Prop) : Prop
axiom g176 (x : Prop) : Prop
axiom g177 (x : Prop) : Prop
axiom g178 (x : Prop) : Prop
axiom g179 (x : Prop) : Prop
axiom g180 (x : Prop) : Prop
axiom g181 (x : Prop) : Prop
axiom g182 (x : Prop) : Prop
axiom g183 (x : Prop) : Prop
axiom g184 (x : Prop) : Prop
axiom g185 (x : Prop) : Prop
axiom g186 (x : Prop) : Prop
axiom g187 (x : Prop) : Prop
axiom g188 (x : Prop) : Prop
axiom g189 (x : Prop) : Prop
axiom g190 (x : Prop) : Prop
axiom g191 (x : Prop) : Prop
axiom g192 (x : Prop) : Prop
axiom g193 (x : Prop) : Prop
axiom g194 (x : Prop) : Prop
axiom g195 (x : Prop) : Prop
axiom g196 (x : Prop) : Prop
axiom g197 (x : Prop) : Prop
axiom g198 (x : Prop) : Prop
axiom g199 (x : Prop) : Prop
axiom g200 (x : Prop) : Prop
axiom g201 (x : Prop) : Prop
axiom g202 (x : Prop) : Prop
axiom g203 (x : Prop) : Prop
axiom g204 (x : Prop) : Prop
axiom g205 (x : Prop) : Prop
axiom g206 (x : Prop) : Prop
axiom g207 (x : Prop) : Prop
axiom g208 (x : Prop) : Prop
axiom g209 (x : Prop) : Prop
axiom g210 (x : Prop) : Prop
axiom g211 (x : Prop) : Prop
axiom g212 (x : Prop) : Prop
axiom g213 (x : Prop) : Prop
axiom g214 (x : Prop) : Prop
axiom g215 (x : Prop) : Prop
axiom g216 (x : Prop) : Prop
axiom g217 (x : Prop) : Prop
axiom g218 (x : Prop) : Prop
axiom g219 (x : Prop) : Prop
axiom g220 (x : Prop) : Prop
axiom g221 (x : Prop) : Prop
axiom g222 (x : Prop) : Prop
axiom g223 (x : Prop) : Prop
axiom g224 (x : Prop) : Prop
axiom g225 (x : Prop) : Prop
axiom g226 (x : Prop) : Prop
axiom g227 (x : Prop) : Prop
axiom g228 (x : Prop) : Prop
axiom g229 (x : Prop) : Prop
axiom g230 (x : Prop) : Prop
axiom g231 (x : Prop) : Prop
axiom g232 (x : Prop) : Prop
axiom g233 (x : Prop) : Prop
axiom g234 (x : Prop) : Prop
axiom g235 (x : Prop) : Prop
axiom g236 (x : Prop) : Prop
axiom g237 (x : Prop) : Prop
axiom g238 (x : Prop) : Prop
axiom g239 (x : Prop) : Prop
axiom g240 (x : Prop) : Prop
axiom g241 (x : Prop) : Prop
axiom g242 (x : Prop) : Prop
axiom g243 (x : Prop) : Prop
axiom g244 (x : Prop) : Prop
axiom g245 (x : Prop) : Prop
axiom g246 (x : Prop) : Prop
axiom g247 (x : Prop) : Prop
axiom g248 (x : Prop) : Prop
axiom g249 (x : Prop) : Prop
axiom g250 (x : Prop) : Prop
axiom g251 (x : Prop) : Prop
axiom g252 (x : Prop) : Prop
axiom g253 (x : Prop) : Prop
axiom g254 (x : Prop) : Prop
axiom g255 (x : Prop) : Prop
axiom g256 (x : Prop) : Prop
axiom g257 (x : Prop) : Prop
axiom g258 (x : Prop) : Prop
axiom g259 (x : Prop) : Prop
axiom g260 (x : Prop) : Prop
axiom g261 (x : Prop) : Prop
axiom g262 (x : Prop) : Prop
axiom g263 (x : Prop) : Prop
axiom g264 (x : Prop) : Prop
axiom g265 (x : Prop) : Prop
axiom g266 (x : Prop) : Prop
axiom g267 (x : Prop) : Prop
axiom g268 (x : Prop) : Prop
axiom g269 (x : Prop) : Prop
axiom g270 (x : Prop) : Prop
axiom g271 (x : Prop) : Prop
axiom g272 (x : Prop) : Prop
axiom g273 (x : Prop) : Prop
axiom g274 (x : Prop) : Prop
axiom g275 (x : Prop) : Prop
axiom g276 (x : Prop) : Prop
axiom g277 (x : Prop) : Prop
axiom g278 (x : Prop) : Prop
axiom g279 (x : Prop) : Prop
axiom g280 (x : Prop) : Prop
axiom g281 (x : Prop) : Prop
axiom g282 (x : Prop) : Prop
axiom g283 (x : Prop) : Prop
axiom g284 (x : Prop) : Prop
axiom g285 (x : Prop) : Prop
axiom g286 (x : Prop) : Prop
axiom g287 (x : Prop) : Prop
axiom g288 (x : Prop) : Prop
axiom g289 (x : Prop) : Prop
axiom g290 (x : Prop) : Prop
axiom g291 (x : Prop) : Prop
axiom g292 (x : Prop) : Prop
axiom g293 (x : Prop) : Prop
axiom g294 (x : Prop) : Prop
axiom g295 (x : Prop) : Prop
axiom g296 (x : Prop) : Prop
axiom g297 (x : Prop) : Prop
axiom g298 (x : Prop) : Prop
axiom g299 (x : Prop) : Prop
axiom g300 (x : Prop) : Prop
axiom g301 (x : Prop) : Prop
axiom g302 (x : Prop) : Prop
axiom g303 (x : Prop) : Prop
axiom g304 (x : Prop) : Prop
axiom g305 (x : Prop) : Prop
axiom g306 (x : Prop) : Prop
axiom g307 (x : Prop) : Prop
axiom g308 (x : Prop) : Prop
axiom g309 (x : Prop) : Prop
axiom g310 (x : Prop) : Prop
axiom g311 (x : Prop) : Prop
axiom g312 (x : Prop) : Prop
axiom g313 (x : Prop) : Prop
axiom g314 (x : Prop) : Prop
axiom g315 (x : Prop) : Prop
axiom g316 (x : Prop) : Prop
axiom g317 (x : Prop) : Prop
axiom g318 (x : Prop) : Prop
axiom g319 (x : Prop) : Prop
axiom g320 (x : Prop) : Prop
axiom g321 (x : Prop) : Prop
axiom g322 (x : Prop) : Prop
axiom g323 (x : Prop) : Prop
axiom g324 (x : Prop) : Prop
axiom g325 (x : Prop) : Prop
axiom g326 (x : Prop) : Prop
axiom g327 (x : Prop) : Prop
axiom g328 (x : Prop) : Prop
axiom g329 (x : Prop) : Prop
axiom g330 (x : Prop) : Prop
axiom g331 (x : Prop) : Prop
axiom g332 (x : Prop) : Prop
axiom g333 (x : Prop) : Prop
axiom g334 (x : Prop) : Prop
axiom g335 (x : Prop) : Prop
axiom g336 (x : Prop) : Prop
axiom g337 (x : Prop) : Prop
axiom g338 (x : Prop) : Prop
axiom g339 (x : Prop) : Prop
axiom g340 (x : Prop) : Prop
axiom g341 (x : Prop) : Prop
axiom g342 (x : Prop) : Prop
axiom g343 (x : Prop) : Prop
axiom g344 (x : Prop) : Prop
axiom g345 (x : Prop) : Prop
axiom g346 (x : Prop) : Prop
axiom g347 (x : Prop) : Prop
axiom g348 (x : Prop) : Prop
axiom g349 (x : Prop) : Prop
axiom g350 (x : Prop) : Prop
axiom g351 (x : Prop) : Prop
axiom g352 (x : Prop) : Prop
axiom g353 (x : Prop) : Prop
axiom g354 (x : Prop) : Prop
axiom g355 (x : Prop) : Prop
axiom g356 (x : Prop) : Prop
axiom g357 (x : Prop) : Prop
axiom g358 (x : Prop) : Prop
axiom g359 (x : Prop) : Prop
axiom g360 (x : Prop) : Prop
axiom g361 (x : Prop) : Prop
axiom g362 (x : Prop) : Prop
axiom g363 (x : Prop) : Prop
axiom g364 (x : Prop) : Prop
axiom g365 (x : Prop) : Prop
axiom g366 (x : Prop) : Prop
axiom g367 (x : Prop) : Prop
axiom g368 (x : Prop) : Prop
axiom g369 (x : Prop) : Prop
axiom g370 (x : Prop) : Prop
axiom g371 (x : Prop) : Prop
axiom g372 (x : Prop) : Prop
axiom g373 (x : Prop) : Prop
axiom g374 (x : Prop) : Prop
axiom g375 (x : Prop) : Prop
axiom g376 (x : Prop) : Prop
axiom g377 (x : Prop) : Prop
axiom g378 (x : Prop) : Prop
axiom g379 (x : Prop) : Prop
axiom g380 (x : Prop) : Prop
axiom g381 (x : Prop) : Prop
axiom g382 (x : Prop) : Prop
axiom g383 (x : Prop) : Prop
axiom g384 (x : Prop) : Prop
axiom g385 (x : Prop) : Prop
axiom g386 (x : Prop) : Prop
axiom g387 (x : Prop) : Prop
axiom g388 (x : Prop) : Prop
axiom g389 (x : Prop) : Prop
axiom g390 (x : Prop) : Prop
axiom g391 (x : Prop) : Prop
axiom g392 (x : Prop) : Prop
axiom g393 (x : Prop) : Prop
axiom g394 (x : Prop) : Prop
axiom g395 (x : Prop) : Prop
axiom g396 (x : Prop) : Prop
axiom g397 (x : Prop) : Prop
axiom g398 (x : Prop) : Prop
axiom g399 (x : Prop) : Prop
axiom g400 (x : Prop) : Prop
axiom g401 (x : Prop) : Prop
axiom g402 (x : Prop) : Prop
axiom g403 (x : Prop) : Prop
axiom g404 (x : Prop) : Prop
axiom g405 (x : Prop) : Prop
axiom g406 (x : Prop) : Prop
axiom g407 (x : Prop) : Prop
axiom g408 (x : Prop) : Prop
axiom g409 (x : Prop) : Prop
axiom g410 (x : Prop) : Prop
axiom g411 (x : Prop) : Prop
axiom g412 (x : Prop) : Prop
axiom g413 (x : Prop) : Prop
axiom g414 (x : Prop) : Prop
axiom g415 (x : Prop) : Prop
axiom g416 (x : Prop) : Prop
axiom g417 (x : Prop) : Prop
axiom g418 (x : Prop) : Prop
axiom g419 (x : Prop) : Prop
axiom g420 (x : Prop) : Prop
axiom g421 (x : Prop) : Prop
axiom g422 (x : Prop) : Prop
axiom g423 (x : Prop) : Prop
axiom g424 (x : Prop) : Prop
axiom g425 (x : Prop) : Prop
axiom g426 (x : Prop) : Prop
axiom g427 (x : Prop) : Prop
axiom g428 (x : Prop) : Prop
axiom g429 (x : Prop) : Prop
axiom g430 (x : Prop) : Prop
axiom g431 (x : Prop) : Prop
axiom g432 (x : Prop) : Prop
axiom g433 (x : Prop) : Prop
axiom g434 (x : Prop) : Prop
axiom g435 (x : Prop) : Prop
axiom g436 (x : Prop) : Prop
axiom g437 (x : Prop) : Prop
axiom g438 (x : Prop) : Prop
axiom g439 (x : Prop) : Prop
axiom g440 (x : Prop) : Prop
axiom g441 (x : Prop) : Prop
axiom g442 (x : Prop) : Prop
axiom g443 (x : Prop) : Prop
axiom g444 (x : Prop) : Prop
axiom g445 (x : Prop) : Prop
axiom g446 (x : Prop) : Prop
axiom g447 (x : Prop) : Prop
axiom g448 (x : Prop) : Prop
axiom g449 (x : Prop) : Prop
axiom g450 (x : Prop) : Prop
axiom g451 (x : Prop) : Prop
axiom g452 (x : Prop) : Prop
axiom g453 (x : Prop) : Prop
axiom g454 (x : Prop) : Prop
axiom g455 (x : Prop) : Prop
axiom g456 (x : Prop) : Prop
axiom g457 (x : Prop) : Prop
axiom g458 (x : Prop) : Prop
axiom g459 (x : Prop) : Prop
axiom g460 (x : Prop) : Prop
axiom g461 (x : Prop) : Prop
axiom g462 (x : Prop) : Prop
axiom g463 (x : Prop) : Prop
axiom g464 (x : Prop) : Prop
axiom g465 (x : Prop) : Prop
axiom g466 (x : Prop) : Prop
axiom g467 (x : Prop) : Prop
axiom g468 (x : Prop) : Prop
axiom g469 (x : Prop) : Prop
axiom g470 (x : Prop) : Prop
axiom g471 (x : Prop) : Prop
axiom g472 (x : Prop) : Prop
axiom g473 (x : Prop) : Prop
axiom g474 (x : Prop) : Prop
axiom g475 (x : Prop) : Prop
axiom g476 (x : Prop) : Prop
axiom g477 (x : Prop) : Prop
axiom g478 (x : Prop) : Prop
axiom g479 (x : Prop) : Prop
axiom g480 (x : Prop) : Prop
axiom g481 (x : Prop) : Prop
axiom g482 (x : Prop) : Prop
axiom g483 (x : Prop) : Prop
axiom g484 (x : Prop) : Prop
axiom g485 (x : Prop) : Prop
axiom g486 (x : Prop) : Prop
axiom g487 (x : Prop) : Prop
axiom g488 (x : Prop) : Prop
axiom g489 (x : Prop) : Prop
axiom g490 (x : Prop) : Prop
axiom g491 (x : Prop) : Prop
axiom g492 (x : Prop) : Prop
axiom g493 (x : Prop) : Prop
axiom g494 (x : Prop) : Prop
axiom g495 (x : Prop) : Prop
axiom g496 (x : Prop) : Prop
axiom g497 (x : Prop) : Prop
axiom g498 (x : Prop) : Prop
axiom g499 (x : Prop) : Prop
@[simp] axiom s0 (x : Prop) : f (g1 x) = f (g0 x)
@[simp] axiom s1 (x : Prop) : f (g2 x) = f (g1 x)
@[simp] axiom s2 (x : Prop) : f (g3 x) = f (g2 x)
@[simp] axiom s3 (x : Prop) : f (g4 x) = f (g3 x)
@[simp] axiom s4 (x : Prop) : f (g5 x) = f (g4 x)
@[simp] axiom s5 (x : Prop) : f (g6 x) = f (g5 x)
@[simp] axiom s6 (x : Prop) : f (g7 x) = f (g6 x)
@[simp] axiom s7 (x : Prop) : f (g8 x) = f (g7 x)
@[simp] axiom s8 (x : Prop) : f (g9 x) = f (g8 x)
@[simp] axiom s9 (x : Prop) : f (g10 x) = f (g9 x)
@[simp] axiom s10 (x : Prop) : f (g11 x) = f (g10 x)
@[simp] axiom s11 (x : Prop) : f (g12 x) = f (g11 x)
@[simp] axiom s12 (x : Prop) : f (g13 x) = f (g12 x)
@[simp] axiom s13 (x : Prop) : f (g14 x) = f (g13 x)
@[simp] axiom s14 (x : Prop) : f (g15 x) = f (g14 x)
@[simp] axiom s15 (x : Prop) : f (g16 x) = f (g15 x)
@[simp] axiom s16 (x : Prop) : f (g17 x) = f (g16 x)
@[simp] axiom s17 (x : Prop) : f (g18 x) = f (g17 x)
@[simp] axiom s18 (x : Prop) : f (g19 x) = f (g18 x)
@[simp] axiom s19 (x : Prop) : f (g20 x) = f (g19 x)
@[simp] axiom s20 (x : Prop) : f (g21 x) = f (g20 x)
@[simp] axiom s21 (x : Prop) : f (g22 x) = f (g21 x)
@[simp] axiom s22 (x : Prop) : f (g23 x) = f (g22 x)
@[simp] axiom s23 (x : Prop) : f (g24 x) = f (g23 x)
@[simp] axiom s24 (x : Prop) : f (g25 x) = f (g24 x)
@[simp] axiom s25 (x : Prop) : f (g26 x) = f (g25 x)
@[simp] axiom s26 (x : Prop) : f (g27 x) = f (g26 x)
@[simp] axiom s27 (x : Prop) : f (g28 x) = f (g27 x)
@[simp] axiom s28 (x : Prop) : f (g29 x) = f (g28 x)
@[simp] axiom s29 (x : Prop) : f (g30 x) = f (g29 x)
@[simp] axiom s30 (x : Prop) : f (g31 x) = f (g30 x)
@[simp] axiom s31 (x : Prop) : f (g32 x) = f (g31 x)
@[simp] axiom s32 (x : Prop) : f (g33 x) = f (g32 x)
@[simp] axiom s33 (x : Prop) : f (g34 x) = f (g33 x)
@[simp] axiom s34 (x : Prop) : f (g35 x) = f (g34 x)
@[simp] axiom s35 (x : Prop) : f (g36 x) = f (g35 x)
@[simp] axiom s36 (x : Prop) : f (g37 x) = f (g36 x)
@[simp] axiom s37 (x : Prop) : f (g38 x) = f (g37 x)
@[simp] axiom s38 (x : Prop) : f (g39 x) = f (g38 x)
@[simp] axiom s39 (x : Prop) : f (g40 x) = f (g39 x)
@[simp] axiom s40 (x : Prop) : f (g41 x) = f (g40 x)
@[simp] axiom s41 (x : Prop) : f (g42 x) = f (g41 x)
@[simp] axiom s42 (x : Prop) : f (g43 x) = f (g42 x)
@[simp] axiom s43 (x : Prop) : f (g44 x) = f (g43 x)
@[simp] axiom s44 (x : Prop) : f (g45 x) = f (g44 x)
@[simp] axiom s45 (x : Prop) : f (g46 x) = f (g45 x)
@[simp] axiom s46 (x : Prop) : f (g47 x) = f (g46 x)
@[simp] axiom s47 (x : Prop) : f (g48 x) = f (g47 x)
@[simp] axiom s48 (x : Prop) : f (g49 x) = f (g48 x)
@[simp] axiom s49 (x : Prop) : f (g50 x) = f (g49 x)
@[simp] axiom s50 (x : Prop) : f (g51 x) = f (g50 x)
@[simp] axiom s51 (x : Prop) : f (g52 x) = f (g51 x)
@[simp] axiom s52 (x : Prop) : f (g53 x) = f (g52 x)
@[simp] axiom s53 (x : Prop) : f (g54 x) = f (g53 x)
@[simp] axiom s54 (x : Prop) : f (g55 x) = f (g54 x)
@[simp] axiom s55 (x : Prop) : f (g56 x) = f (g55 x)
@[simp] axiom s56 (x : Prop) : f (g57 x) = f (g56 x)
@[simp] axiom s57 (x : Prop) : f (g58 x) = f (g57 x)
@[simp] axiom s58 (x : Prop) : f (g59 x) = f (g58 x)
@[simp] axiom s59 (x : Prop) : f (g60 x) = f (g59 x)
@[simp] axiom s60 (x : Prop) : f (g61 x) = f (g60 x)
@[simp] axiom s61 (x : Prop) : f (g62 x) = f (g61 x)
@[simp] axiom s62 (x : Prop) : f (g63 x) = f (g62 x)
@[simp] axiom s63 (x : Prop) : f (g64 x) = f (g63 x)
@[simp] axiom s64 (x : Prop) : f (g65 x) = f (g64 x)
@[simp] axiom s65 (x : Prop) : f (g66 x) = f (g65 x)
@[simp] axiom s66 (x : Prop) : f (g67 x) = f (g66 x)
@[simp] axiom s67 (x : Prop) : f (g68 x) = f (g67 x)
@[simp] axiom s68 (x : Prop) : f (g69 x) = f (g68 x)
@[simp] axiom s69 (x : Prop) : f (g70 x) = f (g69 x)
@[simp] axiom s70 (x : Prop) : f (g71 x) = f (g70 x)
@[simp] axiom s71 (x : Prop) : f (g72 x) = f (g71 x)
@[simp] axiom s72 (x : Prop) : f (g73 x) = f (g72 x)
@[simp] axiom s73 (x : Prop) : f (g74 x) = f (g73 x)
@[simp] axiom s74 (x : Prop) : f (g75 x) = f (g74 x)
@[simp] axiom s75 (x : Prop) : f (g76 x) = f (g75 x)
@[simp] axiom s76 (x : Prop) : f (g77 x) = f (g76 x)
@[simp] axiom s77 (x : Prop) : f (g78 x) = f (g77 x)
@[simp] axiom s78 (x : Prop) : f (g79 x) = f (g78 x)
@[simp] axiom s79 (x : Prop) : f (g80 x) = f (g79 x)
@[simp] axiom s80 (x : Prop) : f (g81 x) = f (g80 x)
@[simp] axiom s81 (x : Prop) : f (g82 x) = f (g81 x)
@[simp] axiom s82 (x : Prop) : f (g83 x) = f (g82 x)
@[simp] axiom s83 (x : Prop) : f (g84 x) = f (g83 x)
@[simp] axiom s84 (x : Prop) : f (g85 x) = f (g84 x)
@[simp] axiom s85 (x : Prop) : f (g86 x) = f (g85 x)
@[simp] axiom s86 (x : Prop) : f (g87 x) = f (g86 x)
@[simp] axiom s87 (x : Prop) : f (g88 x) = f (g87 x)
@[simp] axiom s88 (x : Prop) : f (g89 x) = f (g88 x)
@[simp] axiom s89 (x : Prop) : f (g90 x) = f (g89 x)
@[simp] axiom s90 (x : Prop) : f (g91 x) = f (g90 x)
@[simp] axiom s91 (x : Prop) : f (g92 x) = f (g91 x)
@[simp] axiom s92 (x : Prop) : f (g93 x) = f (g92 x)
@[simp] axiom s93 (x : Prop) : f (g94 x) = f (g93 x)
@[simp] axiom s94 (x : Prop) : f (g95 x) = f (g94 x)
@[simp] axiom s95 (x : Prop) : f (g96 x) = f (g95 x)
@[simp] axiom s96 (x : Prop) : f (g97 x) = f (g96 x)
@[simp] axiom s97 (x : Prop) : f (g98 x) = f (g97 x)
@[simp] axiom s98 (x : Prop) : f (g99 x) = f (g98 x)
@[simp] axiom s99 (x : Prop) : f (g100 x) = f (g99 x)
@[simp] axiom s100 (x : Prop) : f (g101 x) = f (g100 x)
@[simp] axiom s101 (x : Prop) : f (g102 x) = f (g101 x)
@[simp] axiom s102 (x : Prop) : f (g103 x) = f (g102 x)
@[simp] axiom s103 (x : Prop) : f (g104 x) = f (g103 x)
@[simp] axiom s104 (x : Prop) : f (g105 x) = f (g104 x)
@[simp] axiom s105 (x : Prop) : f (g106 x) = f (g105 x)
@[simp] axiom s106 (x : Prop) : f (g107 x) = f (g106 x)
@[simp] axiom s107 (x : Prop) : f (g108 x) = f (g107 x)
@[simp] axiom s108 (x : Prop) : f (g109 x) = f (g108 x)
@[simp] axiom s109 (x : Prop) : f (g110 x) = f (g109 x)
@[simp] axiom s110 (x : Prop) : f (g111 x) = f (g110 x)
@[simp] axiom s111 (x : Prop) : f (g112 x) = f (g111 x)
@[simp] axiom s112 (x : Prop) : f (g113 x) = f (g112 x)
@[simp] axiom s113 (x : Prop) : f (g114 x) = f (g113 x)
@[simp] axiom s114 (x : Prop) : f (g115 x) = f (g114 x)
@[simp] axiom s115 (x : Prop) : f (g116 x) = f (g115 x)
@[simp] axiom s116 (x : Prop) : f (g117 x) = f (g116 x)
@[simp] axiom s117 (x : Prop) : f (g118 x) = f (g117 x)
@[simp] axiom s118 (x : Prop) : f (g119 x) = f (g118 x)
@[simp] axiom s119 (x : Prop) : f (g120 x) = f (g119 x)
@[simp] axiom s120 (x : Prop) : f (g121 x) = f (g120 x)
@[simp] axiom s121 (x : Prop) : f (g122 x) = f (g121 x)
@[simp] axiom s122 (x : Prop) : f (g123 x) = f (g122 x)
@[simp] axiom s123 (x : Prop) : f (g124 x) = f (g123 x)
@[simp] axiom s124 (x : Prop) : f (g125 x) = f (g124 x)
@[simp] axiom s125 (x : Prop) : f (g126 x) = f (g125 x)
@[simp] axiom s126 (x : Prop) : f (g127 x) = f (g126 x)
@[simp] axiom s127 (x : Prop) : f (g128 x) = f (g127 x)
@[simp] axiom s128 (x : Prop) : f (g129 x) = f (g128 x)
@[simp] axiom s129 (x : Prop) : f (g130 x) = f (g129 x)
@[simp] axiom s130 (x : Prop) : f (g131 x) = f (g130 x)
@[simp] axiom s131 (x : Prop) : f (g132 x) = f (g131 x)
@[simp] axiom s132 (x : Prop) : f (g133 x) = f (g132 x)
@[simp] axiom s133 (x : Prop) : f (g134 x) = f (g133 x)
@[simp] axiom s134 (x : Prop) : f (g135 x) = f (g134 x)
@[simp] axiom s135 (x : Prop) : f (g136 x) = f (g135 x)
@[simp] axiom s136 (x : Prop) : f (g137 x) = f (g136 x)
@[simp] axiom s137 (x : Prop) : f (g138 x) = f (g137 x)
@[simp] axiom s138 (x : Prop) : f (g139 x) = f (g138 x)
@[simp] axiom s139 (x : Prop) : f (g140 x) = f (g139 x)
@[simp] axiom s140 (x : Prop) : f (g141 x) = f (g140 x)
@[simp] axiom s141 (x : Prop) : f (g142 x) = f (g141 x)
@[simp] axiom s142 (x : Prop) : f (g143 x) = f (g142 x)
@[simp] axiom s143 (x : Prop) : f (g144 x) = f (g143 x)
@[simp] axiom s144 (x : Prop) : f (g145 x) = f (g144 x)
@[simp] axiom s145 (x : Prop) : f (g146 x) = f (g145 x)
@[simp] axiom s146 (x : Prop) : f (g147 x) = f (g146 x)
@[simp] axiom s147 (x : Prop) : f (g148 x) = f (g147 x)
@[simp] axiom s148 (x : Prop) : f (g149 x) = f (g148 x)
@[simp] axiom s149 (x : Prop) : f (g150 x) = f (g149 x)
@[simp] axiom s150 (x : Prop) : f (g151 x) = f (g150 x)
@[simp] axiom s151 (x : Prop) : f (g152 x) = f (g151 x)
@[simp] axiom s152 (x : Prop) : f (g153 x) = f (g152 x)
@[simp] axiom s153 (x : Prop) : f (g154 x) = f (g153 x)
@[simp] axiom s154 (x : Prop) : f (g155 x) = f (g154 x)
@[simp] axiom s155 (x : Prop) : f (g156 x) = f (g155 x)
@[simp] axiom s156 (x : Prop) : f (g157 x) = f (g156 x)
@[simp] axiom s157 (x : Prop) : f (g158 x) = f (g157 x)
@[simp] axiom s158 (x : Prop) : f (g159 x) = f (g158 x)
@[simp] axiom s159 (x : Prop) : f (g160 x) = f (g159 x)
@[simp] axiom s160 (x : Prop) : f (g161 x) = f (g160 x)
@[simp] axiom s161 (x : Prop) : f (g162 x) = f (g161 x)
@[simp] axiom s162 (x : Prop) : f (g163 x) = f (g162 x)
@[simp] axiom s163 (x : Prop) : f (g164 x) = f (g163 x)
@[simp] axiom s164 (x : Prop) : f (g165 x) = f (g164 x)
@[simp] axiom s165 (x : Prop) : f (g166 x) = f (g165 x)
@[simp] axiom s166 (x : Prop) : f (g167 x) = f (g166 x)
@[simp] axiom s167 (x : Prop) : f (g168 x) = f (g167 x)
@[simp] axiom s168 (x : Prop) : f (g169 x) = f (g168 x)
@[simp] axiom s169 (x : Prop) : f (g170 x) = f (g169 x)
@[simp] axiom s170 (x : Prop) : f (g171 x) = f (g170 x)
@[simp] axiom s171 (x : Prop) : f (g172 x) = f (g171 x)
@[simp] axiom s172 (x : Prop) : f (g173 x) = f (g172 x)
@[simp] axiom s173 (x : Prop) : f (g174 x) = f (g173 x)
@[simp] axiom s174 (x : Prop) : f (g175 x) = f (g174 x)
@[simp] axiom s175 (x : Prop) : f (g176 x) = f (g175 x)
@[simp] axiom s176 (x : Prop) : f (g177 x) = f (g176 x)
@[simp] axiom s177 (x : Prop) : f (g178 x) = f (g177 x)
@[simp] axiom s178 (x : Prop) : f (g179 x) = f (g178 x)
@[simp] axiom s179 (x : Prop) : f (g180 x) = f (g179 x)
@[simp] axiom s180 (x : Prop) : f (g181 x) = f (g180 x)
@[simp] axiom s181 (x : Prop) : f (g182 x) = f (g181 x)
@[simp] axiom s182 (x : Prop) : f (g183 x) = f (g182 x)
@[simp] axiom s183 (x : Prop) : f (g184 x) = f (g183 x)
@[simp] axiom s184 (x : Prop) : f (g185 x) = f (g184 x)
@[simp] axiom s185 (x : Prop) : f (g186 x) = f (g185 x)
@[simp] axiom s186 (x : Prop) : f (g187 x) = f (g186 x)
@[simp] axiom s187 (x : Prop) : f (g188 x) = f (g187 x)
@[simp] axiom s188 (x : Prop) : f (g189 x) = f (g188 x)
@[simp] axiom s189 (x : Prop) : f (g190 x) = f (g189 x)
@[simp] axiom s190 (x : Prop) : f (g191 x) = f (g190 x)
@[simp] axiom s191 (x : Prop) : f (g192 x) = f (g191 x)
@[simp] axiom s192 (x : Prop) : f (g193 x) = f (g192 x)
@[simp] axiom s193 (x : Prop) : f (g194 x) = f (g193 x)
@[simp] axiom s194 (x : Prop) : f (g195 x) = f (g194 x)
@[simp] axiom s195 (x : Prop) : f (g196 x) = f (g195 x)
@[simp] axiom s196 (x : Prop) : f (g197 x) = f (g196 x)
@[simp] axiom s197 (x : Prop) : f (g198 x) = f (g197 x)
@[simp] axiom s198 (x : Prop) : f (g199 x) = f (g198 x)
@[simp] axiom s199 (x : Prop) : f (g200 x) = f (g199 x)
@[simp] axiom s200 (x : Prop) : f (g201 x) = f (g200 x)
@[simp] axiom s201 (x : Prop) : f (g202 x) = f (g201 x)
@[simp] axiom s202 (x : Prop) : f (g203 x) = f (g202 x)
@[simp] axiom s203 (x : Prop) : f (g204 x) = f (g203 x)
@[simp] axiom s204 (x : Prop) : f (g205 x) = f (g204 x)
@[simp] axiom s205 (x : Prop) : f (g206 x) = f (g205 x)
@[simp] axiom s206 (x : Prop) : f (g207 x) = f (g206 x)
@[simp] axiom s207 (x : Prop) : f (g208 x) = f (g207 x)
@[simp] axiom s208 (x : Prop) : f (g209 x) = f (g208 x)
@[simp] axiom s209 (x : Prop) : f (g210 x) = f (g209 x)
@[simp] axiom s210 (x : Prop) : f (g211 x) = f (g210 x)
@[simp] axiom s211 (x : Prop) : f (g212 x) = f (g211 x)
@[simp] axiom s212 (x : Prop) : f (g213 x) = f (g212 x)
@[simp] axiom s213 (x : Prop) : f (g214 x) = f (g213 x)
@[simp] axiom s214 (x : Prop) : f (g215 x) = f (g214 x)
@[simp] axiom s215 (x : Prop) : f (g216 x) = f (g215 x)
@[simp] axiom s216 (x : Prop) : f (g217 x) = f (g216 x)
@[simp] axiom s217 (x : Prop) : f (g218 x) = f (g217 x)
@[simp] axiom s218 (x : Prop) : f (g219 x) = f (g218 x)
@[simp] axiom s219 (x : Prop) : f (g220 x) = f (g219 x)
@[simp] axiom s220 (x : Prop) : f (g221 x) = f (g220 x)
@[simp] axiom s221 (x : Prop) : f (g222 x) = f (g221 x)
@[simp] axiom s222 (x : Prop) : f (g223 x) = f (g222 x)
@[simp] axiom s223 (x : Prop) : f (g224 x) = f (g223 x)
@[simp] axiom s224 (x : Prop) : f (g225 x) = f (g224 x)
@[simp] axiom s225 (x : Prop) : f (g226 x) = f (g225 x)
@[simp] axiom s226 (x : Prop) : f (g227 x) = f (g226 x)
@[simp] axiom s227 (x : Prop) : f (g228 x) = f (g227 x)
@[simp] axiom s228 (x : Prop) : f (g229 x) = f (g228 x)
@[simp] axiom s229 (x : Prop) : f (g230 x) = f (g229 x)
@[simp] axiom s230 (x : Prop) : f (g231 x) = f (g230 x)
@[simp] axiom s231 (x : Prop) : f (g232 x) = f (g231 x)
@[simp] axiom s232 (x : Prop) : f (g233 x) = f (g232 x)
@[simp] axiom s233 (x : Prop) : f (g234 x) = f (g233 x)
@[simp] axiom s234 (x : Prop) : f (g235 x) = f (g234 x)
@[simp] axiom s235 (x : Prop) : f (g236 x) = f (g235 x)
@[simp] axiom s236 (x : Prop) : f (g237 x) = f (g236 x)
@[simp] axiom s237 (x : Prop) : f (g238 x) = f (g237 x)
@[simp] axiom s238 (x : Prop) : f (g239 x) = f (g238 x)
@[simp] axiom s239 (x : Prop) : f (g240 x) = f (g239 x)
@[simp] axiom s240 (x : Prop) : f (g241 x) = f (g240 x)
@[simp] axiom s241 (x : Prop) : f (g242 x) = f (g241 x)
@[simp] axiom s242 (x : Prop) : f (g243 x) = f (g242 x)
@[simp] axiom s243 (x : Prop) : f (g244 x) = f (g243 x)
@[simp] axiom s244 (x : Prop) : f (g245 x) = f (g244 x)
@[simp] axiom s245 (x : Prop) : f (g246 x) = f (g245 x)
@[simp] axiom s246 (x : Prop) : f (g247 x) = f (g246 x)
@[simp] axiom s247 (x : Prop) : f (g248 x) = f (g247 x)
@[simp] axiom s248 (x : Prop) : f (g249 x) = f (g248 x)
@[simp] axiom s249 (x : Prop) : f (g250 x) = f (g249 x)
@[simp] axiom s250 (x : Prop) : f (g251 x) = f (g250 x)
@[simp] axiom s251 (x : Prop) : f (g252 x) = f (g251 x)
@[simp] axiom s252 (x : Prop) : f (g253 x) = f (g252 x)
@[simp] axiom s253 (x : Prop) : f (g254 x) = f (g253 x)
@[simp] axiom s254 (x : Prop) : f (g255 x) = f (g254 x)
@[simp] axiom s255 (x : Prop) : f (g256 x) = f (g255 x)
@[simp] axiom s256 (x : Prop) : f (g257 x) = f (g256 x)
@[simp] axiom s257 (x : Prop) : f (g258 x) = f (g257 x)
@[simp] axiom s258 (x : Prop) : f (g259 x) = f (g258 x)
@[simp] axiom s259 (x : Prop) : f (g260 x) = f (g259 x)
@[simp] axiom s260 (x : Prop) : f (g261 x) = f (g260 x)
@[simp] axiom s261 (x : Prop) : f (g262 x) = f (g261 x)
@[simp] axiom s262 (x : Prop) : f (g263 x) = f (g262 x)
@[simp] axiom s263 (x : Prop) : f (g264 x) = f (g263 x)
@[simp] axiom s264 (x : Prop) : f (g265 x) = f (g264 x)
@[simp] axiom s265 (x : Prop) : f (g266 x) = f (g265 x)
@[simp] axiom s266 (x : Prop) : f (g267 x) = f (g266 x)
@[simp] axiom s267 (x : Prop) : f (g268 x) = f (g267 x)
@[simp] axiom s268 (x : Prop) : f (g269 x) = f (g268 x)
@[simp] axiom s269 (x : Prop) : f (g270 x) = f (g269 x)
@[simp] axiom s270 (x : Prop) : f (g271 x) = f (g270 x)
@[simp] axiom s271 (x : Prop) : f (g272 x) = f (g271 x)
@[simp] axiom s272 (x : Prop) : f (g273 x) = f (g272 x)
@[simp] axiom s273 (x : Prop) : f (g274 x) = f (g273 x)
@[simp] axiom s274 (x : Prop) : f (g275 x) = f (g274 x)
@[simp] axiom s275 (x : Prop) : f (g276 x) = f (g275 x)
@[simp] axiom s276 (x : Prop) : f (g277 x) = f (g276 x)
@[simp] axiom s277 (x : Prop) : f (g278 x) = f (g277 x)
@[simp] axiom s278 (x : Prop) : f (g279 x) = f (g278 x)
@[simp] axiom s279 (x : Prop) : f (g280 x) = f (g279 x)
@[simp] axiom s280 (x : Prop) : f (g281 x) = f (g280 x)
@[simp] axiom s281 (x : Prop) : f (g282 x) = f (g281 x)
@[simp] axiom s282 (x : Prop) : f (g283 x) = f (g282 x)
@[simp] axiom s283 (x : Prop) : f (g284 x) = f (g283 x)
@[simp] axiom s284 (x : Prop) : f (g285 x) = f (g284 x)
@[simp] axiom s285 (x : Prop) : f (g286 x) = f (g285 x)
@[simp] axiom s286 (x : Prop) : f (g287 x) = f (g286 x)
@[simp] axiom s287 (x : Prop) : f (g288 x) = f (g287 x)
@[simp] axiom s288 (x : Prop) : f (g289 x) = f (g288 x)
@[simp] axiom s289 (x : Prop) : f (g290 x) = f (g289 x)
@[simp] axiom s290 (x : Prop) : f (g291 x) = f (g290 x)
@[simp] axiom s291 (x : Prop) : f (g292 x) = f (g291 x)
@[simp] axiom s292 (x : Prop) : f (g293 x) = f (g292 x)
@[simp] axiom s293 (x : Prop) : f (g294 x) = f (g293 x)
@[simp] axiom s294 (x : Prop) : f (g295 x) = f (g294 x)
@[simp] axiom s295 (x : Prop) : f (g296 x) = f (g295 x)
@[simp] axiom s296 (x : Prop) : f (g297 x) = f (g296 x)
@[simp] axiom s297 (x : Prop) : f (g298 x) = f (g297 x)
@[simp] axiom s298 (x : Prop) : f (g299 x) = f (g298 x)
@[simp] axiom s299 (x : Prop) : f (g300 x) = f (g299 x)
@[simp] axiom s300 (x : Prop) : f (g301 x) = f (g300 x)
@[simp] axiom s301 (x : Prop) : f (g302 x) = f (g301 x)
@[simp] axiom s302 (x : Prop) : f (g303 x) = f (g302 x)
@[simp] axiom s303 (x : Prop) : f (g304 x) = f (g303 x)
@[simp] axiom s304 (x : Prop) : f (g305 x) = f (g304 x)
@[simp] axiom s305 (x : Prop) : f (g306 x) = f (g305 x)
@[simp] axiom s306 (x : Prop) : f (g307 x) = f (g306 x)
@[simp] axiom s307 (x : Prop) : f (g308 x) = f (g307 x)
@[simp] axiom s308 (x : Prop) : f (g309 x) = f (g308 x)
@[simp] axiom s309 (x : Prop) : f (g310 x) = f (g309 x)
@[simp] axiom s310 (x : Prop) : f (g311 x) = f (g310 x)
@[simp] axiom s311 (x : Prop) : f (g312 x) = f (g311 x)
@[simp] axiom s312 (x : Prop) : f (g313 x) = f (g312 x)
@[simp] axiom s313 (x : Prop) : f (g314 x) = f (g313 x)
@[simp] axiom s314 (x : Prop) : f (g315 x) = f (g314 x)
@[simp] axiom s315 (x : Prop) : f (g316 x) = f (g315 x)
@[simp] axiom s316 (x : Prop) : f (g317 x) = f (g316 x)
@[simp] axiom s317 (x : Prop) : f (g318 x) = f (g317 x)
@[simp] axiom s318 (x : Prop) : f (g319 x) = f (g318 x)
@[simp] axiom s319 (x : Prop) : f (g320 x) = f (g319 x)
@[simp] axiom s320 (x : Prop) : f (g321 x) = f (g320 x)
@[simp] axiom s321 (x : Prop) : f (g322 x) = f (g321 x)
@[simp] axiom s322 (x : Prop) : f (g323 x) = f (g322 x)
@[simp] axiom s323 (x : Prop) : f (g324 x) = f (g323 x)
@[simp] axiom s324 (x : Prop) : f (g325 x) = f (g324 x)
@[simp] axiom s325 (x : Prop) : f (g326 x) = f (g325 x)
@[simp] axiom s326 (x : Prop) : f (g327 x) = f (g326 x)
@[simp] axiom s327 (x : Prop) : f (g328 x) = f (g327 x)
@[simp] axiom s328 (x : Prop) : f (g329 x) = f (g328 x)
@[simp] axiom s329 (x : Prop) : f (g330 x) = f (g329 x)
@[simp] axiom s330 (x : Prop) : f (g331 x) = f (g330 x)
@[simp] axiom s331 (x : Prop) : f (g332 x) = f (g331 x)
@[simp] axiom s332 (x : Prop) : f (g333 x) = f (g332 x)
@[simp] axiom s333 (x : Prop) : f (g334 x) = f (g333 x)
@[simp] axiom s334 (x : Prop) : f (g335 x) = f (g334 x)
@[simp] axiom s335 (x : Prop) : f (g336 x) = f (g335 x)
@[simp] axiom s336 (x : Prop) : f (g337 x) = f (g336 x)
@[simp] axiom s337 (x : Prop) : f (g338 x) = f (g337 x)
@[simp] axiom s338 (x : Prop) : f (g339 x) = f (g338 x)
@[simp] axiom s339 (x : Prop) : f (g340 x) = f (g339 x)
@[simp] axiom s340 (x : Prop) : f (g341 x) = f (g340 x)
@[simp] axiom s341 (x : Prop) : f (g342 x) = f (g341 x)
@[simp] axiom s342 (x : Prop) : f (g343 x) = f (g342 x)
@[simp] axiom s343 (x : Prop) : f (g344 x) = f (g343 x)
@[simp] axiom s344 (x : Prop) : f (g345 x) = f (g344 x)
@[simp] axiom s345 (x : Prop) : f (g346 x) = f (g345 x)
@[simp] axiom s346 (x : Prop) : f (g347 x) = f (g346 x)
@[simp] axiom s347 (x : Prop) : f (g348 x) = f (g347 x)
@[simp] axiom s348 (x : Prop) : f (g349 x) = f (g348 x)
@[simp] axiom s349 (x : Prop) : f (g350 x) = f (g349 x)
@[simp] axiom s350 (x : Prop) : f (g351 x) = f (g350 x)
@[simp] axiom s351 (x : Prop) : f (g352 x) = f (g351 x)
@[simp] axiom s352 (x : Prop) : f (g353 x) = f (g352 x)
@[simp] axiom s353 (x : Prop) : f (g354 x) = f (g353 x)
@[simp] axiom s354 (x : Prop) : f (g355 x) = f (g354 x)
@[simp] axiom s355 (x : Prop) : f (g356 x) = f (g355 x)
@[simp] axiom s356 (x : Prop) : f (g357 x) = f (g356 x)
@[simp] axiom s357 (x : Prop) : f (g358 x) = f (g357 x)
@[simp] axiom s358 (x : Prop) : f (g359 x) = f (g358 x)
@[simp] axiom s359 (x : Prop) : f (g360 x) = f (g359 x)
@[simp] axiom s360 (x : Prop) : f (g361 x) = f (g360 x)
@[simp] axiom s361 (x : Prop) : f (g362 x) = f (g361 x)
@[simp] axiom s362 (x : Prop) : f (g363 x) = f (g362 x)
@[simp] axiom s363 (x : Prop) : f (g364 x) = f (g363 x)
@[simp] axiom s364 (x : Prop) : f (g365 x) = f (g364 x)
@[simp] axiom s365 (x : Prop) : f (g366 x) = f (g365 x)
@[simp] axiom s366 (x : Prop) : f (g367 x) = f (g366 x)
@[simp] axiom s367 (x : Prop) : f (g368 x) = f (g367 x)
@[simp] axiom s368 (x : Prop) : f (g369 x) = f (g368 x)
@[simp] axiom s369 (x : Prop) : f (g370 x) = f (g369 x)
@[simp] axiom s370 (x : Prop) : f (g371 x) = f (g370 x)
@[simp] axiom s371 (x : Prop) : f (g372 x) = f (g371 x)
@[simp] axiom s372 (x : Prop) : f (g373 x) = f (g372 x)
@[simp] axiom s373 (x : Prop) : f (g374 x) = f (g373 x)
@[simp] axiom s374 (x : Prop) : f (g375 x) = f (g374 x)
@[simp] axiom s375 (x : Prop) : f (g376 x) = f (g375 x)
@[simp] axiom s376 (x : Prop) : f (g377 x) = f (g376 x)
@[simp] axiom s377 (x : Prop) : f (g378 x) = f (g377 x)
@[simp] axiom s378 (x : Prop) : f (g379 x) = f (g378 x)
@[simp] axiom s379 (x : Prop) : f (g380 x) = f (g379 x)
@[simp] axiom s380 (x : Prop) : f (g381 x) = f (g380 x)
@[simp] axiom s381 (x : Prop) : f (g382 x) = f (g381 x)
@[simp] axiom s382 (x : Prop) : f (g383 x) = f (g382 x)
@[simp] axiom s383 (x : Prop) : f (g384 x) = f (g383 x)
@[simp] axiom s384 (x : Prop) : f (g385 x) = f (g384 x)
@[simp] axiom s385 (x : Prop) : f (g386 x) = f (g385 x)
@[simp] axiom s386 (x : Prop) : f (g387 x) = f (g386 x)
@[simp] axiom s387 (x : Prop) : f (g388 x) = f (g387 x)
@[simp] axiom s388 (x : Prop) : f (g389 x) = f (g388 x)
@[simp] axiom s389 (x : Prop) : f (g390 x) = f (g389 x)
@[simp] axiom s390 (x : Prop) : f (g391 x) = f (g390 x)
@[simp] axiom s391 (x : Prop) : f (g392 x) = f (g391 x)
@[simp] axiom s392 (x : Prop) : f (g393 x) = f (g392 x)
@[simp] axiom s393 (x : Prop) : f (g394 x) = f (g393 x)
@[simp] axiom s394 (x : Prop) : f (g395 x) = f (g394 x)
@[simp] axiom s395 (x : Prop) : f (g396 x) = f (g395 x)
@[simp] axiom s396 (x : Prop) : f (g397 x) = f (g396 x)
@[simp] axiom s397 (x : Prop) : f (g398 x) = f (g397 x)
@[simp] axiom s398 (x : Prop) : f (g399 x) = f (g398 x)
@[simp] axiom s399 (x : Prop) : f (g400 x) = f (g399 x)
@[simp] axiom s400 (x : Prop) : f (g401 x) = f (g400 x)
@[simp] axiom s401 (x : Prop) : f (g402 x) = f (g401 x)
@[simp] axiom s402 (x : Prop) : f (g403 x) = f (g402 x)
@[simp] axiom s403 (x : Prop) : f (g404 x) = f (g403 x)
@[simp] axiom s404 (x : Prop) : f (g405 x) = f (g404 x)
@[simp] axiom s405 (x : Prop) : f (g406 x) = f (g405 x)
@[simp] axiom s406 (x : Prop) : f (g407 x) = f (g406 x)
@[simp] axiom s407 (x : Prop) : f (g408 x) = f (g407 x)
@[simp] axiom s408 (x : Prop) : f (g409 x) = f (g408 x)
@[simp] axiom s409 (x : Prop) : f (g410 x) = f (g409 x)
@[simp] axiom s410 (x : Prop) : f (g411 x) = f (g410 x)
@[simp] axiom s411 (x : Prop) : f (g412 x) = f (g411 x)
@[simp] axiom s412 (x : Prop) : f (g413 x) = f (g412 x)
@[simp] axiom s413 (x : Prop) : f (g414 x) = f (g413 x)
@[simp] axiom s414 (x : Prop) : f (g415 x) = f (g414 x)
@[simp] axiom s415 (x : Prop) : f (g416 x) = f (g415 x)
@[simp] axiom s416 (x : Prop) : f (g417 x) = f (g416 x)
@[simp] axiom s417 (x : Prop) : f (g418 x) = f (g417 x)
@[simp] axiom s418 (x : Prop) : f (g419 x) = f (g418 x)
@[simp] axiom s419 (x : Prop) : f (g420 x) = f (g419 x)
@[simp] axiom s420 (x : Prop) : f (g421 x) = f (g420 x)
@[simp] axiom s421 (x : Prop) : f (g422 x) = f (g421 x)
@[simp] axiom s422 (x : Prop) : f (g423 x) = f (g422 x)
@[simp] axiom s423 (x : Prop) : f (g424 x) = f (g423 x)
@[simp] axiom s424 (x : Prop) : f (g425 x) = f (g424 x)
@[simp] axiom s425 (x : Prop) : f (g426 x) = f (g425 x)
@[simp] axiom s426 (x : Prop) : f (g427 x) = f (g426 x)
@[simp] axiom s427 (x : Prop) : f (g428 x) = f (g427 x)
@[simp] axiom s428 (x : Prop) : f (g429 x) = f (g428 x)
@[simp] axiom s429 (x : Prop) : f (g430 x) = f (g429 x)
@[simp] axiom s430 (x : Prop) : f (g431 x) = f (g430 x)
@[simp] axiom s431 (x : Prop) : f (g432 x) = f (g431 x)
@[simp] axiom s432 (x : Prop) : f (g433 x) = f (g432 x)
@[simp] axiom s433 (x : Prop) : f (g434 x) = f (g433 x)
@[simp] axiom s434 (x : Prop) : f (g435 x) = f (g434 x)
@[simp] axiom s435 (x : Prop) : f (g436 x) = f (g435 x)
@[simp] axiom s436 (x : Prop) : f (g437 x) = f (g436 x)
@[simp] axiom s437 (x : Prop) : f (g438 x) = f (g437 x)
@[simp] axiom s438 (x : Prop) : f (g439 x) = f (g438 x)
@[simp] axiom s439 (x : Prop) : f (g440 x) = f (g439 x)
@[simp] axiom s440 (x : Prop) : f (g441 x) = f (g440 x)
@[simp] axiom s441 (x : Prop) : f (g442 x) = f (g441 x)
@[simp] axiom s442 (x : Prop) : f (g443 x) = f (g442 x)
@[simp] axiom s443 (x : Prop) : f (g444 x) = f (g443 x)
@[simp] axiom s444 (x : Prop) : f (g445 x) = f (g444 x)
@[simp] axiom s445 (x : Prop) : f (g446 x) = f (g445 x)
@[simp] axiom s446 (x : Prop) : f (g447 x) = f (g446 x)
@[simp] axiom s447 (x : Prop) : f (g448 x) = f (g447 x)
@[simp] axiom s448 (x : Prop) : f (g449 x) = f (g448 x)
@[simp] axiom s449 (x : Prop) : f (g450 x) = f (g449 x)
@[simp] axiom s450 (x : Prop) : f (g451 x) = f (g450 x)
@[simp] axiom s451 (x : Prop) : f (g452 x) = f (g451 x)
@[simp] axiom s452 (x : Prop) : f (g453 x) = f (g452 x)
@[simp] axiom s453 (x : Prop) : f (g454 x) = f (g453 x)
@[simp] axiom s454 (x : Prop) : f (g455 x) = f (g454 x)
@[simp] axiom s455 (x : Prop) : f (g456 x) = f (g455 x)
@[simp] axiom s456 (x : Prop) : f (g457 x) = f (g456 x)
@[simp] axiom s457 (x : Prop) : f (g458 x) = f (g457 x)
@[simp] axiom s458 (x : Prop) : f (g459 x) = f (g458 x)
@[simp] axiom s459 (x : Prop) : f (g460 x) = f (g459 x)
@[simp] axiom s460 (x : Prop) : f (g461 x) = f (g460 x)
@[simp] axiom s461 (x : Prop) : f (g462 x) = f (g461 x)
@[simp] axiom s462 (x : Prop) : f (g463 x) = f (g462 x)
@[simp] axiom s463 (x : Prop) : f (g464 x) = f (g463 x)
@[simp] axiom s464 (x : Prop) : f (g465 x) = f (g464 x)
@[simp] axiom s465 (x : Prop) : f (g466 x) = f (g465 x)
@[simp] axiom s466 (x : Prop) : f (g467 x) = f (g466 x)
@[simp] axiom s467 (x : Prop) : f (g468 x) = f (g467 x)
@[simp] axiom s468 (x : Prop) : f (g469 x) = f (g468 x)
@[simp] axiom s469 (x : Prop) : f (g470 x) = f (g469 x)
@[simp] axiom s470 (x : Prop) : f (g471 x) = f (g470 x)
@[simp] axiom s471 (x : Prop) : f (g472 x) = f (g471 x)
@[simp] axiom s472 (x : Prop) : f (g473 x) = f (g472 x)
@[simp] axiom s473 (x : Prop) : f (g474 x) = f (g473 x)
@[simp] axiom s474 (x : Prop) : f (g475 x) = f (g474 x)
@[simp] axiom s475 (x : Prop) : f (g476 x) = f (g475 x)
@[simp] axiom s476 (x : Prop) : f (g477 x) = f (g476 x)
@[simp] axiom s477 (x : Prop) : f (g478 x) = f (g477 x)
@[simp] axiom s478 (x : Prop) : f (g479 x) = f (g478 x)
@[simp] axiom s479 (x : Prop) : f (g480 x) = f (g479 x)
@[simp] axiom s480 (x : Prop) : f (g481 x) = f (g480 x)
@[simp] axiom s481 (x : Prop) : f (g482 x) = f (g481 x)
@[simp] axiom s482 (x : Prop) : f (g483 x) = f (g482 x)
@[simp] axiom s483 (x : Prop) : f (g484 x) = f (g483 x)
@[simp] axiom s484 (x : Prop) : f (g485 x) = f (g484 x)
@[simp] axiom s485 (x : Prop) : f (g486 x) = f (g485 x)
@[simp] axiom s486 (x : Prop) : f (g487 x) = f (g486 x)
@[simp] axiom s487 (x : Prop) : f (g488 x) = f (g487 x)
@[simp] axiom s488 (x : Prop) : f (g489 x) = f (g488 x)
@[simp] axiom s489 (x : Prop) : f (g490 x) = f (g489 x)
@[simp] axiom s490 (x : Prop) : f (g491 x) = f (g490 x)
@[simp] axiom s491 (x : Prop) : f (g492 x) = f (g491 x)
@[simp] axiom s492 (x : Prop) : f (g493 x) = f (g492 x)
@[simp] axiom s493 (x : Prop) : f (g494 x) = f (g493 x)
@[simp] axiom s494 (x : Prop) : f (g495 x) = f (g494 x)
@[simp] axiom s495 (x : Prop) : f (g496 x) = f (g495 x)
@[simp] axiom s496 (x : Prop) : f (g497 x) = f (g496 x)
@[simp] axiom s497 (x : Prop) : f (g498 x) = f (g497 x)
@[simp] axiom s498 (x : Prop) : f (g499 x) = f (g498 x)
|
160d66b8790b8097ae0789cc706d1b96523fa6e5 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/algebra/category/Group/abelian.lean | a11ad5a1a383aa8a2263337029e1adda4fb07810 | [
"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 | 1,438 | lean | /-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import algebra.category.Group.Z_Module_equivalence
import algebra.category.Group.limits
import algebra.category.Group.colimits
import algebra.category.Module.abelian
import category_theory.abelian.basic
/-!
# The category of abelian groups is abelian
-/
open category_theory
open category_theory.limits
universe u
noncomputable theory
namespace AddCommGroup
section
variables {X Y : AddCommGroup.{u}} (f : X βΆ Y)
/-- In the category of abelian groups, every monomorphism is normal. -/
def normal_mono (hf : mono f) : normal_mono f :=
equivalence_reflects_normal_mono (forgetβ (Module.{u} β€) AddCommGroup.{u}).inv $
Module.normal_mono _ infer_instance
/-- In the category of abelian groups, every epimorphism is normal. -/
def normal_epi (hf : epi f) : normal_epi f :=
equivalence_reflects_normal_epi (forgetβ (Module.{u} β€) AddCommGroup.{u}).inv $
Module.normal_epi _ infer_instance
end
/-- The category of abelian groups is abelian. -/
instance : abelian AddCommGroup.{u} :=
{ has_finite_products := β¨by apply_instanceβ©,
normal_mono_of_mono := Ξ» X Y, normal_mono,
normal_epi_of_epi := Ξ» X Y, normal_epi,
add_comp' := by { intros, simp only [preadditive.add_comp] },
comp_add' := by { intros, simp only [preadditive.comp_add] } }
end AddCommGroup
|
544f5d2fda35ee48d46e8013cea041e4d37953d5 | e953c38599905267210b87fb5d82dcc3e52a4214 | /library/data/real/division.lean | b91cdfb364b056337ff6641f8fda9d909180dc03 | [
"Apache-2.0"
] | permissive | c-cube/lean | 563c1020bff98441c4f8ba60111fef6f6b46e31b | 0fb52a9a139f720be418dafac35104468e293b66 | refs/heads/master | 1,610,753,294,113 | 1,440,451,356,000 | 1,440,499,588,000 | 41,748,334 | 0 | 0 | null | 1,441,122,656,000 | 1,441,122,656,000 | null | UTF-8 | Lean | false | false | 21,969 | lean | /-
Copyright (c) 2015 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Robert Y. Lewis
The real numbers, constructed as equivalence classes of Cauchy sequences of rationals.
This construction follows Bishop and Bridges (1985).
At this point, we no longer proceed constructively: this file makes heavy use of decidability
and excluded middle.
-/
import data.real.basic data.real.order data.rat data.nat
open -[coercions] rat
open -[coercions] nat
open eq.ops pnat classical
local notation 0 := rat.of_num 0
local notation 1 := rat.of_num 1
local notation 2 := subtype.tag (nat.of_num 2) dec_trivial
namespace s
-----------------------------
-- helper lemmas
theorem and_of_not_or {a b : Prop} (H : Β¬ (a β¨ b)) : Β¬ a β§ Β¬ b :=
and.intro (assume H', H (or.inl H')) (assume H', H (or.inr H'))
-----------------------------
-- Facts about absolute values of sequences, to define inverse
definition s_abs (s : seq) : seq := Ξ» n, abs (s n)
theorem abs_reg_of_reg {s : seq} (Hs : regular s) : regular (s_abs s) :=
begin
intros,
apply rat.le.trans,
apply abs_abs_sub_abs_le_abs_sub,
apply Hs
end
theorem abs_pos_of_nonzero {s : seq} (Hs : regular s) (Hnz : sep s zero) :
β N : β+, β m : β+, m β₯ N β abs (s m) β₯ Nβ»ΒΉ :=
begin
rewrite [βsep at Hnz, βs_lt at Hnz],
apply or.elim Hnz,
intro Hnz1,
have H' : pos (sneg s), begin
apply pos_of_pos_equiv,
rotate 2,
apply Hnz1,
rotate 1,
apply s_zero_add,
repeat (assumption | apply reg_add_reg | apply reg_neg_reg | apply zero_is_reg)
end,
cases bdd_away_of_pos (reg_neg_reg Hs) H' with [N, HN],
existsi N,
intro m Hm,
apply rat.le.trans,
apply HN m Hm,
rewrite βsneg,
apply neg_le_abs_self,
intro Hnz2,
let H' := pos_of_pos_equiv (reg_add_reg Hs (reg_neg_reg zero_is_reg)) (s_add_zero s Hs) Hnz2,
let H'' := bdd_away_of_pos Hs H',
cases H'' with [N, HN],
existsi N,
intro m Hm,
apply rat.le.trans,
apply HN m Hm,
apply le_abs_self
end
theorem sep_zero_of_pos {s : seq} (Hs : regular s) (Hpos : pos s) : sep s zero :=
begin
apply or.inr,
apply pos_of_pos_equiv,
rotate 2,
apply Hpos,
apply Hs,
apply equiv.symm,
apply s_sub_zero Hs
end
------------------------
-- This section could be cleaned up.
noncomputable definition pb {s : seq} (Hs : regular s) (Hpos : pos s) :=
some (abs_pos_of_nonzero Hs (sep_zero_of_pos Hs Hpos))
noncomputable definition ps {s : seq} (Hs : regular s) (Hsep : sep s zero) :=
some (abs_pos_of_nonzero Hs Hsep)
theorem pb_spec {s : seq} (Hs : regular s) (Hpos : pos s) :
β m : β+, m β₯ (pb Hs Hpos) β abs (s m) β₯ (pb Hs Hpos)β»ΒΉ :=
some_spec (abs_pos_of_nonzero Hs (sep_zero_of_pos Hs Hpos))
theorem ps_spec {s : seq} (Hs : regular s) (Hsep : sep s zero) :
β m : β+, m β₯ (ps Hs Hsep) β abs (s m) β₯ (ps Hs Hsep)β»ΒΉ :=
some_spec (abs_pos_of_nonzero Hs Hsep)
noncomputable definition s_inv {s : seq} (Hs : regular s) (n : β+) : β :=
if H : sep s zero then
(if n < (ps Hs H) then 1 / (s ((ps Hs H) * (ps Hs H) * (ps Hs H)))
else 1 / (s ((ps Hs H) * (ps Hs H) * n)))
else 0
theorem peq {s : seq} (Hsep : sep s zero) (Hpos : pos s) (Hs : regular s) :
pb Hs Hpos = ps Hs Hsep := rfl
theorem s_inv_of_sep_lt_p {s : seq} (Hs : regular s) (Hsep : sep s zero) {n : β+}
(Hn : n < (ps Hs Hsep)) : s_inv Hs n = 1 / s ((ps Hs Hsep) * (ps Hs Hsep) * (ps Hs Hsep)) :=
begin
apply eq.trans,
apply dif_pos Hsep,
apply dif_pos Hn
end
theorem s_inv_of_sep_gt_p {s : seq} (Hs : regular s) (Hsep : sep s zero) {n : β+}
(Hn : n β₯ (ps Hs Hsep)) : s_inv Hs n = 1 / s ((ps Hs Hsep) * (ps Hs Hsep) * n) :=
begin
apply eq.trans,
apply dif_pos Hsep,
apply dif_neg (pnat.not_lt_of_ge Hn)
end
theorem s_inv_of_pos_lt_p {s : seq} (Hs : regular s) (Hpos : pos s) {n : β+}
(Hn : n < (pb Hs Hpos)) : s_inv Hs n = 1 / s ((pb Hs Hpos) * (pb Hs Hpos) * (pb Hs Hpos)) :=
s_inv_of_sep_lt_p Hs (sep_zero_of_pos Hs Hpos) Hn
theorem s_inv_of_pos_gt_p {s : seq} (Hs : regular s) (Hpos : pos s) {n : β+}
(Hn : n β₯ (pb Hs Hpos)) : s_inv Hs n = 1 / s ((pb Hs Hpos) * (pb Hs Hpos) * n) :=
s_inv_of_sep_gt_p Hs (sep_zero_of_pos Hs Hpos) Hn
theorem le_ps {s : seq} (Hs : regular s) (Hsep : sep s zero) (n : β+) :
abs (s_inv Hs n) β€ (rat_of_pnat (ps Hs Hsep)) :=
if Hn : n < ps Hs Hsep then
(begin
rewrite [(s_inv_of_sep_lt_p Hs Hsep Hn), abs_one_div],
apply div_le_pnat,
apply ps_spec,
apply pnat.mul_le_mul_left
end)
else
(begin
rewrite [(s_inv_of_sep_gt_p Hs Hsep (le_of_not_gt Hn)), abs_one_div],
apply div_le_pnat,
apply ps_spec,
rewrite pnat.mul.assoc,
apply pnat.mul_le_mul_right
end)
theorem s_inv_zero : s_inv zero_is_reg = zero :=
funext (Ξ» n, dif_neg (!not_sep_self))
theorem s_inv_of_zero' {s : seq} (Hs : regular s) (Hz : Β¬ sep s zero) (n : β+) : s_inv Hs n = 0 :=
dif_neg Hz
theorem s_inv_of_zero {s : seq} (Hs : regular s) (Hz : Β¬ sep s zero) : s_inv Hs = zero :=
begin
apply funext,
intro n,
apply s_inv_of_zero' Hs Hz n
end
theorem s_ne_zero_of_ge_p {s : seq} (Hs : regular s) (Hsep : sep s zero) {n : β+}
(Hn : n β₯ (ps Hs Hsep)) : s n β 0 :=
begin
let Hps := ps_spec Hs Hsep,
apply ne_zero_of_abs_ne_zero,
apply ne_of_gt,
apply gt_of_ge_of_gt,
apply Hps,
apply Hn,
apply inv_pos
end
theorem reg_inv_reg {s : seq} (Hs : regular s) (Hsep : sep s zero) : regular (s_inv Hs) :=
begin
rewrite βregular,
intros,
have Hsp : s ((ps Hs Hsep) * (ps Hs Hsep) * (ps Hs Hsep)) β 0, from
s_ne_zero_of_ge_p Hs Hsep !mul_le_mul_left,
have Hspn : s ((ps Hs Hsep) * (ps Hs Hsep) * n) β 0, from
s_ne_zero_of_ge_p Hs Hsep (show (ps Hs Hsep) * (ps Hs Hsep) * n β₯ ps Hs Hsep, by
rewrite pnat.mul.assoc; apply pnat.mul_le_mul_right),
have Hspm : s ((ps Hs Hsep) * (ps Hs Hsep) * m) β 0, from
s_ne_zero_of_ge_p Hs Hsep (show (ps Hs Hsep) * (ps Hs Hsep) * m β₯ ps Hs Hsep, by
rewrite pnat.mul.assoc; apply pnat.mul_le_mul_right),
cases em (m < ps Hs Hsep) with [Hmlt, Hmlt],
cases em (n < ps Hs Hsep) with [Hnlt, Hnlt],
rewrite [(s_inv_of_sep_lt_p Hs Hsep Hmlt), (s_inv_of_sep_lt_p Hs Hsep Hnlt)],
rewrite [sub_self, abs_zero],
apply add_invs_nonneg,
rewrite [(s_inv_of_sep_lt_p Hs Hsep Hmlt),
(s_inv_of_sep_gt_p Hs Hsep (le_of_not_gt Hnlt))],
rewrite [(div_sub_div Hsp Hspn), div_eq_mul_one_div, *abs_mul, *mul_one, *one_mul],
apply rat.le.trans,
apply rat.mul_le_mul,
apply Hs,
rewrite [-(mul_one 1), -(div_mul_div Hsp Hspn), abs_mul],
apply rat.mul_le_mul,
rewrite -(s_inv_of_sep_lt_p Hs Hsep Hmlt),
apply le_ps Hs Hsep,
rewrite -(s_inv_of_sep_gt_p Hs Hsep (le_of_not_gt Hnlt)),
apply le_ps Hs Hsep,
apply abs_nonneg,
apply le_of_lt !rat_of_pnat_is_pos,
apply abs_nonneg,
apply add_invs_nonneg,
rewrite [right_distrib, *pnat_cancel', rat.add.comm],
apply rat.add_le_add_right,
apply inv_ge_of_le,
apply pnat.le_of_lt,
apply Hmlt,
cases em (n < ps Hs Hsep) with [Hnlt, Hnlt],
rewrite [(s_inv_of_sep_lt_p Hs Hsep Hnlt),
(s_inv_of_sep_gt_p Hs Hsep (le_of_not_gt Hmlt))],
rewrite [(div_sub_div Hspm Hsp), div_eq_mul_one_div, *abs_mul, *mul_one, *one_mul],
apply rat.le.trans,
apply rat.mul_le_mul,
apply Hs,
rewrite [-(mul_one 1), -(div_mul_div Hspm Hsp), abs_mul],
apply rat.mul_le_mul,
rewrite -(s_inv_of_sep_gt_p Hs Hsep (le_of_not_gt Hmlt)),
apply le_ps Hs Hsep,
rewrite -(s_inv_of_sep_lt_p Hs Hsep Hnlt),
apply le_ps Hs Hsep,
apply abs_nonneg,
apply le_of_lt !rat_of_pnat_is_pos,
apply abs_nonneg,
apply add_invs_nonneg,
rewrite [right_distrib, *pnat_cancel', rat.add.comm],
apply rat.add_le_add_left,
apply inv_ge_of_le,
apply pnat.le_of_lt,
apply Hnlt,
rewrite [(s_inv_of_sep_gt_p Hs Hsep (le_of_not_gt Hnlt)),
(s_inv_of_sep_gt_p Hs Hsep (le_of_not_gt Hmlt))],
rewrite [(div_sub_div Hspm Hspn), div_eq_mul_one_div, abs_mul, *one_mul, *mul_one],
apply rat.le.trans,
apply rat.mul_le_mul,
apply Hs,
rewrite [-(mul_one 1), -(div_mul_div Hspm Hspn), abs_mul],
apply rat.mul_le_mul,
rewrite -(s_inv_of_sep_gt_p Hs Hsep (le_of_not_gt Hmlt)),
apply le_ps Hs Hsep,
rewrite -(s_inv_of_sep_gt_p Hs Hsep (le_of_not_gt Hnlt)),
apply le_ps Hs Hsep,
apply abs_nonneg,
apply le_of_lt !rat_of_pnat_is_pos,
apply abs_nonneg,
apply add_invs_nonneg,
rewrite [right_distrib, *pnat_cancel', rat.add.comm],
apply rat.le.refl
end
theorem s_inv_ne_zero {s : seq} (Hs : regular s) (Hsep : sep s zero) (n : β+) : s_inv Hs n β 0 :=
if H : n β₯ ps Hs Hsep then
(begin
rewrite (s_inv_of_sep_gt_p Hs Hsep H),
apply one_div_ne_zero,
apply s_ne_zero_of_ge_p,
apply pnat.le.trans,
apply H,
apply pnat.mul_le_mul_left
end)
else
(begin
rewrite (s_inv_of_sep_lt_p Hs Hsep (lt_of_not_ge H)),
apply one_div_ne_zero,
apply s_ne_zero_of_ge_p,
apply pnat.mul_le_mul_left
end)
theorem mul_inv {s : seq} (Hs : regular s) (Hsep : sep s zero) : smul s (s_inv Hs) β‘ one :=
begin
let Rsi := reg_inv_reg Hs Hsep,
let Rssi := reg_mul_reg Hs Rsi,
apply eq_of_bdd Rssi one_is_reg,
intros,
existsi max (ps Hs Hsep) j,
intro n Hn,
have Hnz : s_inv Hs ((Kβ s (s_inv Hs)) * 2 * n) β 0, from s_inv_ne_zero Hs Hsep _,
rewrite [βsmul, βone, rat.mul.comm, -(mul_one_div_cancel Hnz),
-rat.mul_sub_left_distrib, abs_mul],
apply rat.le.trans,
apply rat.mul_le_mul_of_nonneg_right,
apply canon_2_bound_right s,
apply Rsi,
apply abs_nonneg,
have Hp : (Kβ s (s_inv Hs)) * 2 * n β₯ ps Hs Hsep, begin
apply pnat.le.trans,
apply max_left,
rotate 1,
apply pnat.le.trans,
apply Hn,
apply pnat.mul_le_mul_left
end,
have Hnz' : s (((ps Hs Hsep) * (ps Hs Hsep)) * ((Kβ s (s_inv Hs)) * 2 * n)) β 0, from
s_ne_zero_of_ge_p Hs Hsep
(show ps Hs Hsep β€ ((ps Hs Hsep) * (ps Hs Hsep)) * ((Kβ s (s_inv Hs)) * 2 * n),
by rewrite *pnat.mul.assoc; apply pnat.mul_le_mul_right),
rewrite [(s_inv_of_sep_gt_p Hs Hsep Hp), (div_div Hnz')],
apply rat.le.trans,
apply rat.mul_le_mul_of_nonneg_left,
apply Hs,
apply le_of_lt,
apply rat_of_pnat_is_pos,
rewrite [rat.mul.left_distrib, mul.comm ((ps Hs Hsep) * (ps Hs Hsep)), *pnat.mul.assoc,
*(@inv_mul_eq_mul_inv (Kβ s (s_inv Hs))), -*rat.mul.assoc, *inv_cancel_left,
*one_mul, -(add_halves j)],
apply rat.add_le_add,
apply inv_ge_of_le,
apply pnat_mul_le_mul_left',
apply pnat.le.trans,
rotate 1,
apply Hn,
rotate_right 1,
apply max_right,
apply inv_ge_of_le,
apply pnat_mul_le_mul_left',
apply pnat.le.trans,
apply max_right,
rotate 1,
apply pnat.le.trans,
apply Hn,
apply pnat.mul_le_mul_right
end
theorem inv_mul {s : seq} (Hs : regular s) (Hsep : sep s zero) : smul (s_inv Hs) s β‘ one :=
begin
apply equiv.trans,
rotate 3,
apply s_mul_comm,
apply mul_inv,
repeat (assumption | apply reg_mul_reg | apply reg_inv_reg | apply zero_is_reg)
end
theorem sep_of_equiv_sep {s t : seq} (Hs : regular s) (Ht : regular t) (Heq : s β‘ t)
(Hsep : sep s zero) : sep t zero :=
begin
apply or.elim Hsep,
intro Hslt,
apply or.inl,
rewrite βs_lt at *,
apply pos_of_pos_equiv,
rotate 2,
apply Hslt,
rotate_right 1,
apply add_well_defined,
rotate 4,
apply equiv.refl,
apply neg_well_defined,
apply Heq,
intro Hslt,
apply or.inr,
rewrite βs_lt at *,
apply pos_of_pos_equiv,
rotate 2,
apply Hslt,
rotate_right 1,
apply add_well_defined,
rotate 5,
apply equiv.refl,
repeat (assumption | apply reg_neg_reg | apply reg_add_reg | apply zero_is_reg)
end
theorem inv_unique {s t : seq} (Hs : regular s) (Ht : regular t) (Hsep : sep s zero)
(Heq : smul s t β‘ one) : s_inv Hs β‘ t :=
begin
apply equiv.trans,
rotate 3,
apply equiv.symm,
apply s_mul_one,
rotate 1,
apply equiv.trans,
rotate 3,
apply mul_well_defined,
rotate 4,
apply equiv.refl,
apply equiv.symm,
apply Heq,
apply equiv.trans,
rotate 3,
apply equiv.symm,
apply s_mul_assoc,
rotate 3,
apply equiv.trans,
rotate 3,
apply mul_well_defined,
rotate 4,
apply inv_mul,
rotate 1,
apply equiv.refl,
apply s_one_mul,
repeat (assumption | apply reg_inv_reg | apply reg_mul_reg | apply one_is_reg)
end
theorem inv_well_defined {s t : seq} (Hs : regular s) (Ht : regular t) (Heq : s β‘ t) :
s_inv Hs β‘ s_inv Ht :=
if Hsep : sep s zero then
(begin
let Hsept := sep_of_equiv_sep Hs Ht Heq Hsep,
have Hm : smul t (s_inv Hs) β‘ smul s (s_inv Hs), begin
apply mul_well_defined,
repeat (assumption | apply reg_inv_reg),
apply equiv.symm s t Heq,
apply equiv.refl
end,
apply equiv.symm,
apply inv_unique,
rotate 2,
apply equiv.trans,
rotate 3,
apply Hm,
apply mul_inv,
repeat (assumption | apply reg_inv_reg | apply reg_mul_reg),
apply one_is_reg
end)
else
(have H : s_inv Hs = zero, from funext (Ξ» n, dif_neg Hsep),
have Hsept : Β¬ sep t zero, from
assume H', Hsep (sep_of_equiv_sep Ht Hs (equiv.symm _ _ Heq) H'),
have H' : s_inv Ht = zero, from funext (Ξ» n, dif_neg Hsept),
H'β»ΒΉ βΈ (Hβ»ΒΉ βΈ equiv.refl zero))
theorem s_neg_neg {s : seq} : sneg (sneg s) β‘ s :=
begin
rewrite [βequiv, βsneg],
intro n,
rewrite [neg_neg, sub_self, abs_zero],
apply add_invs_nonneg
end
theorem s_neg_sub {s t : seq} (Hs : regular s) (Ht : regular t) :
sneg (sadd s (sneg t)) β‘ sadd t (sneg s) :=
begin
apply equiv.trans,
rotate 3,
apply s_neg_add_eq_s_add_neg,
apply equiv.trans,
rotate 3,
apply add_well_defined,
rotate 4,
apply equiv.refl,
apply s_neg_neg,
apply s_add_comm,
repeat (assumption | apply reg_add_reg | apply reg_neg_reg)
end
theorem s_le_total {s t : seq} (Hs : regular s) (Ht : regular t) : s_le s t β¨ s_le t s :=
if H : s_le s t then or.inl H else or.inr begin
rewrite [βs_le at *],
have H' : β n : β+, -nβ»ΒΉ > sadd t (sneg s) n, begin
apply by_contradiction,
intro Hex,
have Hex' : β n : β+, -nβ»ΒΉ β€ sadd t (sneg s) n, begin
intro m,
apply by_contradiction,
intro Hm,
let Hm' := rat.lt_of_not_ge Hm,
let Hex'' := exists.intro m Hm',
apply Hex Hex''
end,
apply H Hex'
end,
eapply exists.elim H',
intro m Hm,
let Hm' := neg_lt_neg Hm,
rewrite neg_neg at Hm',
apply s_nonneg_of_pos,
rotate 1,
apply pos_of_pos_equiv,
rotate 1,
apply s_neg_sub,
rotate 2,
rewrite [βpos, βsneg],
existsi m,
apply Hm',
repeat (assumption | apply reg_add_reg | apply reg_neg_reg)
end
theorem s_le_of_not_lt {s t : seq} (Hle : Β¬ s_lt s t) : s_le t s :=
begin
rewrite [βs_le, βnonneg, βs_lt at Hle, βpos at Hle],
let Hle' := iff.mp forall_iff_not_exists Hle,
intro n,
let Hn := neg_le_neg (rat.le_of_not_gt (Hle' n)),
rewrite [βsadd, βsneg, add_neg_eq_neg_add_rev],
apply Hn
end
theorem sep_of_nequiv {s t : seq} (Hs : regular s) (Ht : regular t) (Hneq : Β¬ equiv s t) :
sep s t :=
begin
rewrite βsep,
apply by_contradiction,
intro Hnor,
let Hand := and_of_not_or Hnor,
let Hle1 := s_le_of_not_lt (and.left Hand),
let Hle2 := s_le_of_not_lt (and.right Hand),
apply Hneq (equiv_of_le_of_ge Hs Ht Hle2 Hle1)
end
theorem s_zero_inv_equiv_zero : s_inv zero_is_reg β‘ zero :=
by rewrite s_inv_zero; apply equiv.refl
theorem lt_or_equiv_of_le {s t : seq} (Hs : regular s) (Ht : regular t) (Hle : s_le s t) :
s_lt s t β¨ s β‘ t :=
if H : s β‘ t then or.inr H else
or.inl (lt_of_le_and_sep Hs Ht (and.intro Hle (sep_of_nequiv Hs Ht H)))
theorem s_le_of_equiv_le_left {s t u : seq} (Hs : regular s) (Ht : regular t) (Hu : regular u)
(Heq : s β‘ t) (Hle : s_le s u) : s_le t u :=
begin
rewrite βs_le at *,
apply nonneg_of_nonneg_equiv,
rotate 2,
apply add_well_defined,
rotate 4,
apply equiv.refl,
apply neg_well_defined,
apply Heq,
repeat (assumption | apply reg_add_reg | apply reg_neg_reg)
end
theorem s_le_of_equiv_le_right {s t u : seq} (Hs : regular s) (Ht : regular t) (Hu : regular u)
(Heq : t β‘ u) (Hle : s_le s t) : s_le s u :=
begin
rewrite βs_le at *,
apply nonneg_of_nonneg_equiv,
rotate 2,
apply add_well_defined,
rotate 4,
apply Heq,
apply equiv.refl,
repeat (assumption | apply reg_add_reg | apply reg_neg_reg)
end
-----------------------------
noncomputable definition r_inv (s : reg_seq) : reg_seq := reg_seq.mk (s_inv (reg_seq.is_reg s))
(if H : sep (reg_seq.sq s) zero then reg_inv_reg (reg_seq.is_reg s) H else
have Hz : s_inv (reg_seq.is_reg s) = zero, from funext (Ξ» n, dif_neg H), Hzβ»ΒΉ βΈ zero_is_reg)
theorem r_inv_zero : requiv (r_inv r_zero) r_zero :=
s_zero_inv_equiv_zero
theorem r_inv_well_defined {s t : reg_seq} (H : requiv s t) : requiv (r_inv s) (r_inv t) :=
inv_well_defined (reg_seq.is_reg s) (reg_seq.is_reg t) H
theorem r_le_total (s t : reg_seq) : r_le s t β¨ r_le t s :=
s_le_total (reg_seq.is_reg s) (reg_seq.is_reg t)
theorem r_mul_inv (s : reg_seq) (Hsep : r_sep s r_zero) : requiv (s * (r_inv s)) r_one :=
mul_inv (reg_seq.is_reg s) Hsep
theorem r_sep_of_nequiv (s t : reg_seq) (Hneq : Β¬ requiv s t) : r_sep s t :=
sep_of_nequiv (reg_seq.is_reg s) (reg_seq.is_reg t) Hneq
theorem r_lt_or_equiv_of_le (s t : reg_seq) (Hle : r_le s t) : r_lt s t β¨ requiv s t :=
lt_or_equiv_of_le (reg_seq.is_reg s) (reg_seq.is_reg t) Hle
theorem r_le_of_equiv_le_left {s t u : reg_seq} (Heq : requiv s t) (Hle : r_le s u) : r_le t u :=
s_le_of_equiv_le_left (reg_seq.is_reg s) (reg_seq.is_reg t) (reg_seq.is_reg u) Heq Hle
theorem r_le_of_equiv_le_right {s t u : reg_seq} (Heq : requiv t u) (Hle : r_le s t) : r_le s u :=
s_le_of_equiv_le_right (reg_seq.is_reg s) (reg_seq.is_reg t) (reg_seq.is_reg u) Heq Hle
end s
namespace real
open [classes] s
noncomputable definition inv (x : β) : β := quot.lift_on x (Ξ» a, quot.mk (s.r_inv a))
(Ξ» a b H, quot.sound (s.r_inv_well_defined H))
postfix [priority real.prio] `β»ΒΉ` := inv
theorem le_total (x y : β) : x β€ y β¨ y β€ x :=
quot.induction_onβ x y (Ξ» s t, s.r_le_total s t)
theorem mul_inv' (x : β) : x β’ zero β x * xβ»ΒΉ = one :=
quot.induction_on x (Ξ» s H, quot.sound (s.r_mul_inv s H))
theorem inv_mul' (x : β) : x β’ zero β xβ»ΒΉ * x = one :=
by rewrite real.mul_comm; apply mul_inv'
theorem neq_of_sep {x y : β} (H : x β’ y) : Β¬ x = y :=
assume Heq, !not_sep_self (Heq βΈ H)
theorem sep_of_neq {x y : β} : Β¬ x = y β x β’ y :=
quot.induction_onβ x y (Ξ» s t H, s.r_sep_of_nequiv s t (assume Heq, H (quot.sound Heq)))
theorem sep_is_neq (x y : β) : (x β’ y) = (Β¬ x = y) :=
propext (iff.intro neq_of_sep sep_of_neq)
theorem mul_inv (x : β) : x β zero β x * xβ»ΒΉ = one := !sep_is_neq βΈ !mul_inv'
theorem inv_mul (x : β) : x β zero β xβ»ΒΉ * x = one := !sep_is_neq βΈ !inv_mul'
theorem inv_zero : zeroβ»ΒΉ = zero := quot.sound (s.r_inv_zero)
theorem lt_or_eq_of_le (x y : β) : x β€ y β x < y β¨ x = y :=
quot.induction_onβ x y (Ξ» s t H, or.elim (s.r_lt_or_equiv_of_le s t H)
(assume H1, or.inl H1)
(assume H2, or.inr (quot.sound H2)))
theorem le_iff_lt_or_eq (x y : β) : x β€ y β x < y β¨ x = y :=
iff.intro (lt_or_eq_of_le x y) (le_of_lt_or_eq x y)
noncomputable definition dec_lt : decidable_rel lt :=
begin
rewrite βdecidable_rel,
intros,
apply prop_decidable
end
section migrate_algebra
open [classes] algebra
protected noncomputable definition discrete_linear_ordered_field [reducible] :
algebra.discrete_linear_ordered_field β :=
β¦ algebra.discrete_linear_ordered_field, real.comm_ring, real.ordered_ring,
le_total := le_total,
mul_inv_cancel := mul_inv,
inv_mul_cancel := inv_mul,
zero_lt_one := zero_lt_one,
inv_zero := inv_zero,
le_iff_lt_or_eq := le_iff_lt_or_eq,
decidable_lt := dec_lt
β¦
local attribute real.discrete_linear_ordered_field [trans-instance]
local attribute real.comm_ring [instance]
local attribute real.ordered_ring [instance]
noncomputable definition abs (n : β) : β := algebra.abs n
noncomputable definition sign (n : β) : β := algebra.sign n
noncomputable definition max (a b : β) : β := algebra.max a b
noncomputable definition min (a b : β) : β := algebra.min a b
noncomputable definition divide (a b : β): β := algebra.divide a b
migrate from algebra with real
replacing has_le.ge β ge, has_lt.gt β gt, sub β sub, abs β abs, sign β sign, dvd β dvd,
divide β divide, max β max, min β min, pow β pow, nmul β nmul, imul β imul
end migrate_algebra
infix / := divide
end real
|
671bcad0af5f8c89ff800d47ca29083dde3c2874 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/ring_theory/dedekind_domain/finite_adele_ring.lean | 8c599af57d482306481c74d4985edc87c46508d2 | [
"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 | 9,079 | lean | /-
Copyright (c) 2023 MarΓa InΓ©s de Frutos-FernΓ‘ndez. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: MarΓa InΓ©s de Frutos-FernΓ‘ndez
-/
import ring_theory.dedekind_domain.adic_valuation
/-!
# The finite adèle ring of a Dedekind domain
We define the ring of finite adèles of a Dedekind domain `R`.
## Main definitions
- `dedekind_domain.finite_integral_adeles` : product of `adic_completion_integers`, where `v`
runs over all maximal ideals of `R`.
- `dedekind_domain.prod_adic_completions` : the product of `adic_completion`, where `v` runs over
all maximal ideals of `R`.
- `dedekind_domain.finite_adele_ring` : The finite adèle ring of `R`, defined as the
restricted product `Ξ '_v K_v`.
## Implementation notes
We are only interested on Dedekind domains of Krull dimension 1 (i.e., not fields). If `R` is a
field, its finite adèle ring is just defined to be the trivial ring.
## References
* [J.W.S. Cassels, A. FrΓΆlich, *Algebraic Number Theory*][cassels1967algebraic]
## Tags
finite adèle ring, dedekind domain
-/
noncomputable theory
open function set is_dedekind_domain is_dedekind_domain.height_one_spectrum
namespace dedekind_domain
variables (R K : Type*) [comm_ring R] [is_domain R] [is_dedekind_domain R] [field K]
[algebra R K] [is_fraction_ring R K] (v : height_one_spectrum R)
/-- The product of all `adic_completion_integers`, where `v` runs over the maximal ideals of `R`. -/
@[derive [comm_ring, topological_space, inhabited]]
def finite_integral_adeles : Type* := Ξ (v : height_one_spectrum R), v.adic_completion_integers K
local notation `R_hat` := finite_integral_adeles
/-- The product of all `adic_completion`, where `v` runs over the maximal ideals of `R`. -/
@[derive [non_unital_non_assoc_ring, topological_space, topological_ring, comm_ring, inhabited]]
def prod_adic_completions := Ξ (v : height_one_spectrum R), v.adic_completion K
local notation `K_hat` := prod_adic_completions
namespace finite_integral_adeles
noncomputable! instance : has_coe (R_hat R K) (K_hat R K) := { coe := Ξ» x v, x v }
lemma coe_apply (x : R_hat R K) (v : height_one_spectrum R) : (x : K_hat R K) v = β(x v) := rfl
/-- The inclusion of `R_hat` in `K_hat` as a homomorphism of additive monoids. -/
@[simps] def coe.add_monoid_hom : add_monoid_hom (R_hat R K) (K_hat R K) :=
{ to_fun := coe,
map_zero' := rfl,
map_add' := Ξ» x y, by { ext v, simp only [coe_apply, pi.add_apply, subring.coe_add] }}
/-- The inclusion of `R_hat` in `K_hat` as a ring homomorphism. -/
@[simps] def coe.ring_hom : ring_hom (R_hat R K) (K_hat R K) :=
{ to_fun := coe,
map_one' := rfl,
map_mul' := Ξ» x y, by {ext p, simp only [pi.mul_apply, subring.coe_mul], refl },
..coe.add_monoid_hom R K }
end finite_integral_adeles
section algebra_instances
instance : algebra K (K_hat R K) :=
(by apply_instance : algebra K $ Ξ v : height_one_spectrum R, v.adic_completion K)
instance prod_adic_completions.algebra' : algebra R (K_hat R K) :=
(by apply_instance : algebra R $ Ξ v : height_one_spectrum R, v.adic_completion K)
instance : is_scalar_tower R K (K_hat R K) :=
(by apply_instance : is_scalar_tower R K $ Ξ v : height_one_spectrum R, v.adic_completion K)
instance : algebra R (R_hat R K) :=
(by apply_instance : algebra R $ Ξ v : height_one_spectrum R, v.adic_completion_integers K)
instance prod_adic_completions.algebra_completions : algebra (R_hat R K) (K_hat R K) :=
(finite_integral_adeles.coe.ring_hom R K).to_algebra
instance prod_adic_completions.is_scalar_tower_completions :
is_scalar_tower R (R_hat R K) (K_hat R K) :=
(by apply_instance : is_scalar_tower R (Ξ v : height_one_spectrum R, v.adic_completion_integers K) $
Ξ v : height_one_spectrum R, v.adic_completion K)
end algebra_instances
namespace finite_integral_adeles
/-- The inclusion of `R_hat` in `K_hat` as an algebra homomorphism. -/
def coe.alg_hom : alg_hom R (R_hat R K) (K_hat R K) :=
{ to_fun := coe,
commutes' := Ξ» r, rfl,
..coe.ring_hom R K }
lemma coe.alg_hom_apply (x : R_hat R K) (v : height_one_spectrum R) :
(coe.alg_hom R K) x v = x v := rfl
end finite_integral_adeles
/-! ### The finite adèle ring of a Dedekind domain
We define the finite adèle ring of `R` as the restricted product over all maximal ideals `v` of `R`
of `adic_completion` with respect to `adic_completion_integers`. We prove that it is a commutative
ring. TODO: show that it is a topological ring with the restricted product topology. -/
namespace prod_adic_completions
variables {R K}
/-- An element `x : K_hat R K` is a finite adèle if for all but finitely many height one ideals
`v`, the component `x v` is a `v`-adic integer. -/
def is_finite_adele (x : K_hat R K) :=
βαΆ v : height_one_spectrum R in filter.cofinite, x v β v.adic_completion_integers K
namespace is_finite_adele
/-- The sum of two finite adèles is a finite adèle. -/
lemma add {x y : K_hat R K} (hx : x.is_finite_adele) (hy : y.is_finite_adele) :
(x + y).is_finite_adele :=
begin
rw [is_finite_adele, filter.eventually_cofinite] at hx hy β’,
have h_subset : {v : height_one_spectrum R | Β¬ (x + y) v β (v.adic_completion_integers K)} β
{v : height_one_spectrum R | Β¬ x v β (v.adic_completion_integers K)} βͺ
{v : height_one_spectrum R | Β¬ y v β (v.adic_completion_integers K)},
{ intros v hv,
rw [mem_union, mem_set_of_eq, mem_set_of_eq],
rw mem_set_of_eq at hv,
contrapose! hv,
rw [mem_adic_completion_integers, mem_adic_completion_integers, β max_le_iff] at hv,
rw [mem_adic_completion_integers, pi.add_apply],
exact le_trans (valued.v.map_add_le_max' (x v) (y v)) hv },
exact (hx.union hy).subset h_subset,
end
/-- The tuple `(0)_v` is a finite adèle. -/
lemma zero : (0 : K_hat R K).is_finite_adele :=
begin
rw [is_finite_adele, filter.eventually_cofinite],
have h_empty : {v : height_one_spectrum R |
Β¬ ((0 : v.adic_completion K) β v.adic_completion_integers K)} = β
,
{ ext v, rw [mem_empty_iff_false, iff_false], intro hv,
rw mem_set_of_eq at hv, apply hv, rw mem_adic_completion_integers,
have h_zero : (valued.v (0 : v.adic_completion K) : (with_zero(multiplicative β€))) = 0 :=
valued.v.map_zero',
rw h_zero, exact zero_le_one' _ },
simp_rw [pi.zero_apply, h_empty],
exact finite_empty,
end
/-- The negative of a finite adèle is a finite adèle. -/
lemma neg {x : K_hat R K} (hx : x.is_finite_adele) : (-x).is_finite_adele :=
begin
rw is_finite_adele at hx β’,
have h : β (v : height_one_spectrum R), (-x v β v.adic_completion_integers K) β
(x v β v.adic_completion_integers K),
{ intro v,
rw [mem_adic_completion_integers, mem_adic_completion_integers, valuation.map_neg], },
simpa only [pi.neg_apply, h] using hx,
end
/-- The product of two finite adèles is a finite adèle. -/
lemma mul {x y : K_hat R K} (hx : x.is_finite_adele) (hy : y.is_finite_adele) :
(x * y).is_finite_adele :=
begin
rw [is_finite_adele, filter.eventually_cofinite] at hx hy β’,
have h_subset : {v : height_one_spectrum R | Β¬ (x * y) v β (v.adic_completion_integers K)} β
{v : height_one_spectrum R | Β¬ x v β (v.adic_completion_integers K)} βͺ
{v : height_one_spectrum R | Β¬ y v β (v.adic_completion_integers K)},
{ intros v hv,
rw [mem_union, mem_set_of_eq, mem_set_of_eq],
rw mem_set_of_eq at hv,
contrapose! hv,
rw [mem_adic_completion_integers, mem_adic_completion_integers] at hv,
have h_mul : valued.v (x v * y v) = (valued.v (x v)) * (valued.v (y v)) :=
(valued.v).map_mul' (x v) (y v),
rw [mem_adic_completion_integers, pi.mul_apply, h_mul],
exact @mul_le_one' (with_zero (multiplicative β€)) _ _
(ordered_comm_monoid.to_covariant_class_left _) _ _ hv.left hv.right },
exact (hx.union hy).subset h_subset,
end
/-- The tuple `(1)_v` is a finite adèle. -/
lemma one : (1 : K_hat R K).is_finite_adele :=
begin
rw [is_finite_adele, filter.eventually_cofinite],
have h_empty : {v : height_one_spectrum R |
Β¬ ((1 : v.adic_completion K) β v.adic_completion_integers K)} = β
,
{ ext v, rw [mem_empty_iff_false, iff_false], intro hv,
rw mem_set_of_eq at hv, apply hv, rw mem_adic_completion_integers,
exact le_of_eq valued.v.map_one' },
simp_rw [pi.one_apply, h_empty],
exact finite_empty,
end
end is_finite_adele
end prod_adic_completions
open prod_adic_completions.is_finite_adele
variables (R K)
/-- The finite adèle ring of `R` is the restricted product over all maximal ideals `v` of `R`
of `adic_completion` with respect to `adic_completion_integers`. -/
noncomputable! def finite_adele_ring : subring (K_hat R K) :=
{ carrier := { x : K_hat R K | x.is_finite_adele },
mul_mem' := Ξ» _ _ hx hy, mul hx hy,
one_mem' := one,
add_mem' := Ξ» _ _ hx hy, add hx hy,
zero_mem' := zero,
neg_mem' := Ξ» _ hx, neg hx, }
variables {R K}
@[simp] lemma mem_finite_adele_ring_iff (x : K_hat R K) :
x β finite_adele_ring R K β x.is_finite_adele :=
iff.rfl
end dedekind_domain
|
c33540ec10611ddb6854623c836451cf83d22697 | c86b74188c4b7a462728b1abd659ab4e5828dd61 | /stage0/src/Lean/Server/FileWorker.lean | d44845d5fa6022afdcc2a25e1a947f93ad26b3cc | [
"Apache-2.0"
] | permissive | cwb96/lean4 | 75e1f92f1ba98bbaa6b34da644b3dfab2ce7bf89 | b48831cda76e64f13dd1c0edde7ba5fb172ed57a | refs/heads/master | 1,686,347,881,407 | 1,624,483,842,000 | 1,624,483,842,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 17,486 | lean | /-
Copyright (c) 2020 Marc Huisinga. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Marc Huisinga, Wojciech Nawrocki
-/
import Init.System.IO
import Std.Data.RBMap
import Lean.Environment
import Lean.Data.Lsp
import Lean.Data.Json.FromToJson
import Lean.Server.Utils
import Lean.Server.Snapshots
import Lean.Server.AsyncList
import Lean.Server.FileWorker.Utils
import Lean.Server.FileWorker.RequestHandling
/-!
For general server architecture, see `README.md`. For details of IPC communication, see `Watchdog.lean`.
This module implements per-file worker processes.
File processing and requests+notifications against a file should be concurrent for two reasons:
- By the LSP standard, requests should be cancellable.
- Since Lean allows arbitrary user code to be executed during elaboration via the tactic framework,
elaboration can be extremely slow and even not halt in some cases. Users should be able to
work with the file while this is happening, e.g. make new changes to the file or send requests.
To achieve these goals, elaboration is executed in a chain of tasks, where each task corresponds to
the elaboration of one command. When the elaboration of one command is done, the next task is spawned.
On didChange notifications, we search for the task in which the change occured. If we stumble across
a task that has not yet finished before finding the task we're looking for, we terminate it
and start the elaboration there, otherwise we start the elaboration at the task where the change occured.
Requests iterate over tasks until they find the command that they need to answer the request.
In order to not block the main thread, this is done in a request task.
If a task that the request task waits for is terminated, a change occured somewhere before the
command that the request is looking for and the request sends a "content changed" error.
-/
namespace Lean.Server.FileWorker
open Lsp
open IO
open Snapshots
open Std (RBMap RBMap.empty)
open JsonRpc
/- Asynchronous snapshot elaboration. -/
section Elab
/-- Elaborates the next command after `parentSnap` and emits diagnostics into `hOut`. -/
private def nextCmdSnap (m : DocumentMeta) (parentSnap : Snapshot) (cancelTk : CancelToken) (hOut : FS.Stream)
: ExceptT ElabTaskError IO Snapshot := do
cancelTk.check
publishProgressAtPos m parentSnap.endPos hOut
let maybeSnap β compileNextCmd m.text.source parentSnap
-- TODO(MH): check for interrupt with increased precision
cancelTk.check
match maybeSnap with
| Sum.inl snap =>
/- NOTE(MH): This relies on the client discarding old diagnostics upon receiving new ones
while prefering newer versions over old ones. The former is necessary because we do
not explicitly clear older diagnostics, while the latter is necessary because we do
not guarantee that diagnostics are emitted in order. Specifically, it may happen that
we interrupted this elaboration task right at this point and a newer elaboration task
emits diagnostics, after which we emit old diagnostics because we did not yet detect
the interrupt. Explicitly clearing diagnostics is difficult for a similar reason,
because we cannot guarantee that no further diagnostics are emitted after clearing
them. -/
publishMessages m snap.msgLog hOut
snap
| Sum.inr msgLog =>
publishMessages m msgLog hOut
publishProgressDone m hOut
throw ElabTaskError.eof
/-- Elaborates all commands after `initSnap`, emitting the diagnostics into `hOut`. -/
def unfoldCmdSnaps (m : DocumentMeta) (initSnap : Snapshot) (cancelTk : CancelToken) (hOut : FS.Stream)
(initial : Bool) :
IO (AsyncList ElabTaskError Snapshot) := do
if initial && initSnap.msgLog.hasErrors then
-- treat header processing errors as fatal so users aren't swamped with followup errors
AsyncList.nil
else
AsyncList.unfoldAsync (nextCmdSnap m . cancelTk hOut) initSnap
end Elab
-- Pending requests are tracked so they can be cancelled
abbrev PendingRequestMap := RBMap RequestID (Task (Except IO.Error Unit)) compare
structure WorkerContext where
hIn : FS.Stream
hOut : FS.Stream
hLog : FS.Stream
srcSearchPath : SearchPath
docRef : IO.Ref EditableDocument
pendingRequestsRef : IO.Ref PendingRequestMap
abbrev WorkerM := ReaderT WorkerContext IO
/- Worker initialization sequence. -/
section Initialization
/-- Use `leanpkg print-paths` to compile dependencies on the fly and add them to `LEAN_PATH`.
Compilation progress is reported to `hOut` via LSP notifications. Return the search path for
source files. -/
partial def leanpkgSetupSearchPath (leanpkgPath : System.FilePath) (m : DocumentMeta) (imports : Array Import) (hOut : FS.Stream) : IO SearchPath := do
let leanpkgProc β Process.spawn {
stdin := Process.Stdio.null
stdout := Process.Stdio.piped
stderr := Process.Stdio.piped
cmd := leanpkgPath.toString
args := #["print-paths"] ++ imports.map (toString Β·.module)
}
-- progress notification: report latest stderr line
let rec processStderr (acc : String) : IO String := do
let line β leanpkgProc.stderr.getLine
if line == "" then
return acc
else
publishDiagnostics m #[{ range := β¨β¨0, 0β©, β¨0, 0β©β©, severity? := DiagnosticSeverity.information, message := line }] hOut
processStderr (acc ++ line)
let stderr β IO.asTask (processStderr "") Task.Priority.dedicated
let stdout := String.trim (β leanpkgProc.stdout.readToEnd)
let stderr β IO.ofExcept stderr.get
if (β leanpkgProc.wait) == 0 then
let leanpkgLines := stdout.split (Β· == '\n')
-- ignore any output up to the last two lines
-- TODO: leanpkg should instead redirect nested stdout output to stderr
let leanpkgLines := leanpkgLines.drop (leanpkgLines.length - 2)
match leanpkgLines with
| [""] => pure [] -- e.g. no leanpkg.toml
| [leanPath, leanSrcPath] => let sp β getBuiltinSearchPath
let sp β addSearchPathFromEnv sp
let sp := System.SearchPath.parse leanPath ++ sp
searchPathRef.set sp
let srcPath := System.SearchPath.parse leanSrcPath
srcPath.mapM realPathNormalized
| _ => throwServerError s!"unexpected output from `leanpkg print-paths`:\n{stdout}\nstderr:\n{stderr}"
else
throwServerError s!"`leanpkg print-paths` failed:\n{stdout}\nstderr:\n{stderr}"
def compileHeader (m : DocumentMeta) (hOut : FS.Stream) : IO (Snapshot Γ SearchPath) := do
let opts := {} -- TODO
let inputCtx := Parser.mkInputContext m.text.source "<input>"
let (headerStx, headerParserState, msgLog) β Parser.parseHeader inputCtx
let leanpkgPath β match (β IO.getEnv "LEAN_SYSROOT") with
| some path => pure <| System.FilePath.mk path / "bin" / "leanpkg"
| _ => pure <| (β appDir) / "leanpkg"
let leanpkgPath := leanpkgPath.withExtension System.FilePath.exeExtension
let mut srcSearchPath := [(β appDir) / ".." / "lib" / "lean" / "src"]
if let some p := (β IO.getEnv "LEAN_SRC_PATH") then
srcSearchPath := srcSearchPath ++ System.SearchPath.parse p
let (headerEnv, msgLog) β try
-- NOTE: leanpkg does not exist in stage 0 (yet?)
if (β System.FilePath.pathExists leanpkgPath) then
let pkgSearchPath β leanpkgSetupSearchPath leanpkgPath m (Lean.Elab.headerToImports headerStx).toArray hOut
srcSearchPath := srcSearchPath ++ pkgSearchPath
Elab.processHeader headerStx opts msgLog inputCtx
catch e => -- should be from `leanpkg print-paths`
let msgs := MessageLog.empty.add { fileName := "<ignored>", pos := β¨0, 0β©, data := e.toString }
pure (β mkEmptyEnvironment, msgs)
publishMessages m msgLog hOut
let cmdState := Elab.Command.mkState headerEnv msgLog opts
let cmdState := { cmdState with infoState.enabled := true, scopes := [{ header := "", opts := opts }] }
let headerSnap := {
beginPos := 0
stx := headerStx
mpState := headerParserState
cmdState := cmdState
}
return (headerSnap, srcSearchPath)
def initializeWorker (meta : DocumentMeta) (i o e : FS.Stream)
: IO WorkerContext := do
/- NOTE(WN): `toFileMap` marks line beginnings as immediately following
"\n", which should be enough to handle both LF and CRLF correctly.
This is because LSP always refers to characters by (line, column),
so if we get the line number correct it shouldn't matter that there
is a CR there. -/
let (headerSnap, srcSearchPath) β compileHeader meta o
let cancelTk β CancelToken.new
let cmdSnaps β unfoldCmdSnaps meta headerSnap cancelTk o (initial := true)
let doc : EditableDocument := β¨meta, headerSnap, cmdSnaps, cancelTkβ©
return {
hIn := i
hOut := o
hLog := e
srcSearchPath := srcSearchPath
docRef := βIO.mkRef doc
pendingRequestsRef := βIO.mkRef RBMap.empty
}
end Initialization
section Updates
def updatePendingRequests (map : PendingRequestMap β PendingRequestMap) : WorkerM Unit := do
(βread).pendingRequestsRef.modify map
/-- Given the new document and `changePos`, the UTF-8 offset of a change into the pre-change source,
updates editable doc state. -/
def updateDocument (newMeta : DocumentMeta) (changePos : String.Pos) : WorkerM Unit := do
-- The watchdog only restarts the file worker when the syntax tree of the header changes.
-- If e.g. a newline is deleted, it will not restart this file worker, but we still
-- need to reparse the header so that the offsets are correct.
let st β read
let oldDoc β st.docRef.get
let newHeaderSnap β reparseHeader newMeta.text.source oldDoc.headerSnap
if newHeaderSnap.stx != oldDoc.headerSnap.stx then
throwServerError "Internal server error: header changed but worker wasn't restarted."
let β¨cmdSnaps, e?β© β oldDoc.cmdSnaps.updateFinishedPrefix
match e? with
-- This case should not be possible. only the main task aborts tasks and ensures that aborted tasks
-- do not show up in `snapshots` of an EditableDocument.
| some ElabTaskError.aborted =>
throwServerError "Internal server error: elab task was aborted while still in use."
| some (ElabTaskError.ioError ioError) => throw ioError
| _ => -- No error or EOF
oldDoc.cancelTk.set
-- NOTE(WN): we invalidate eagerly as `endPos` consumes input greedily. To re-elaborate only
-- when really necessary, we could do a whitespace-aware `Syntax` comparison instead.
let mut validSnaps := cmdSnaps.finishedPrefix.takeWhile (fun s => s.endPos < changePos)
if validSnaps.length = 0 then
let cancelTk β CancelToken.new
let newCmdSnaps β unfoldCmdSnaps newMeta newHeaderSnap cancelTk st.hOut (initial := true)
st.docRef.set β¨newMeta, newHeaderSnap, newCmdSnaps, cancelTkβ©
else
/- When at least one valid non-header snap exists, it may happen that a change does not fall
within the syntactic range of that last snap but still modifies it by appending tokens.
We check for this here. We do not currently handle crazy grammars in which an appended
token can merge two or more previous commands into one. To do so would require reparsing
the entire file. -/
let mut lastSnap := validSnaps.getLast!
let preLastSnap :=
if validSnaps.length β₯ 2
then validSnaps.get! (validSnaps.length - 2)
else newHeaderSnap
let newLastStx β parseNextCmd newMeta.text.source preLastSnap
if newLastStx != lastSnap.stx then
validSnaps β validSnaps.dropLast
lastSnap β preLastSnap
let cancelTk β CancelToken.new
let newSnaps β unfoldCmdSnaps newMeta lastSnap cancelTk st.hOut (initial := false)
let newCmdSnaps := AsyncList.ofList validSnaps ++ newSnaps
st.docRef.set β¨newMeta, newHeaderSnap, newCmdSnaps, cancelTkβ©
end Updates
/- Notifications are handled in the main thread. They may change global worker state
such as the current file contents. -/
section NotificationHandling
def handleDidChange (p : DidChangeTextDocumentParams) : WorkerM Unit := do
let docId := p.textDocument
let changes := p.contentChanges
let oldDoc β (βread).docRef.get
let some newVersion β pure docId.version?
| throwServerError "Expected version number"
if newVersion β€ oldDoc.meta.version then
-- TODO(WN): This happens on restart sometimes.
IO.eprintln s!"Got outdated version number: {newVersion} β€ {oldDoc.meta.version}"
else if Β¬ changes.isEmpty then
let (newDocText, minStartOff) := foldDocumentChanges changes oldDoc.meta.text
updateDocument β¨docId.uri, newVersion, newDocTextβ© minStartOff
def handleCancelRequest (p : CancelParams) : WorkerM Unit := do
updatePendingRequests (fun pendingRequests => pendingRequests.erase p.id)
end NotificationHandling
section MessageHandling
def parseParams (paramType : Type) [FromJson paramType] (params : Json) : WorkerM paramType :=
match fromJson? params with
| Except.ok parsed => pure parsed
| Except.error inner => throwServerError s!"Got param with wrong structure: {params.compress}\n{inner}"
def handleNotification (method : String) (params : Json) : WorkerM Unit := do
let handle := fun paramType [FromJson paramType] (handler : paramType β WorkerM Unit) =>
parseParams paramType params >>= handler
match method with
| "textDocument/didChange" => handle DidChangeTextDocumentParams handleDidChange
| "$/cancelRequest" => handle CancelParams handleCancelRequest
| _ => throwServerError s!"Got unsupported notification method: {method}"
def queueRequest (id : RequestID) (requestTask : Task (Except IO.Error Unit))
: WorkerM Unit := do
updatePendingRequests (fun pendingRequests => pendingRequests.insert id requestTask)
def handleRequest (id : RequestID) (method : String) (params : Json)
: WorkerM Unit := do
let st β read
let rc : Requests.RequestContext := { srcSearchPath := st.srcSearchPath, docRef := st.docRef }
let t? β (ExceptT.run <| Requests.handleLspRequest method params rc : IO _)
let tβ β match t? with
| Except.error e =>
IO.asTask do
st.hOut.writeLspResponseError <| e.toLspResponseError id
| Except.ok t => (IO.mapTask Β· t) fun
| Except.ok resp =>
st.hOut.writeLspResponse β¨id, respβ©
| Except.error e =>
st.hOut.writeLspResponseError <| e.toLspResponseError id
queueRequest id tβ
end MessageHandling
section MainLoop
partial def mainLoop : WorkerM Unit := do
let st β read
let msg β st.hIn.readLspMessage
let pendingRequests β st.pendingRequestsRef.get
let filterFinishedTasks (acc : PendingRequestMap) (id : RequestID) (task : Task (Except IO.Error Unit))
: WorkerM PendingRequestMap := do
if (βhasFinished task) then
/- Handler tasks are constructed so that the only possible errors here
are failures of writing a response into the stream. -/
if let Except.error e := task.get then
throwServerError s!"Failed responding to request {id}: {e}"
acc.erase id
else acc
let pendingRequests β pendingRequests.foldM filterFinishedTasks pendingRequests
st.pendingRequestsRef.set pendingRequests
match msg with
| Message.request id method (some params) =>
handleRequest id method (toJson params)
mainLoop
| Message.notification "exit" none =>
let doc β st.docRef.get
doc.cancelTk.set
return ()
| Message.notification method (some params) =>
handleNotification method (toJson params)
mainLoop
| _ => throwServerError "Got invalid JSON-RPC message"
end MainLoop
def initAndRunWorker (i o e : FS.Stream) : IO UInt32 := do
let i β maybeTee "fwIn.txt" false i
let o β maybeTee "fwOut.txt" true o
let _ β i.readLspRequestAs "initialize" InitializeParams
let β¨_, paramβ© β i.readLspNotificationAs "textDocument/didOpen" DidOpenTextDocumentParams
let doc := param.textDocument
let meta : DocumentMeta := β¨doc.uri, doc.version, doc.text.toFileMapβ©
let e β e.withPrefix s!"[{param.textDocument.uri}] "
let _ β IO.setStderr e
try
let ctx β initializeWorker meta i o e
ReaderT.run (r := ctx) mainLoop
return 0
catch e =>
IO.eprintln e
publishDiagnostics meta #[{ range := β¨β¨0, 0β©, β¨0, 0β©β©, severity? := DiagnosticSeverity.error, message := e.toString }] o
return 1
@[export lean_server_worker_main]
def workerMain : IO UInt32 := do
let i β IO.getStdin
let o β IO.getStdout
let e β IO.getStderr
try
initAndRunWorker i o e
catch err =>
e.putStrLn s!"worker initialization error: {err}"
return (1 : UInt32)
end Lean.Server.FileWorker
|
bf1a5b731659e48af26f2291e1a27b3d598ce81c | 74caf7451c921a8d5ab9c6e2b828c9d0a35aae95 | /library/init/meta/relation_tactics.lean | 93107a94548a3a6fdf4d0a8a825a47ff2893a580 | [
"Apache-2.0"
] | permissive | sakas--/lean | f37b6fad4fd4206f2891b89f0f8135f57921fc3f | 570d9052820be1d6442a5cc58ece37397f8a9e4c | refs/heads/master | 1,586,127,145,194 | 1,480,960,018,000 | 1,480,960,635,000 | 40,137,176 | 0 | 0 | null | 1,438,621,351,000 | 1,438,621,351,000 | null | UTF-8 | Lean | false | false | 1,440 | 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.function
namespace tactic
open expr
private meta def relation_tactic (op_for : environment β name β option name) (tac_name : string) : tactic unit :=
do tgt β target,
env β get_env,
r β return $ get_app_fn tgt,
match (op_for env (const_name r)) with
| (some refl) := mk_const refl >>= apply
| none := fail $ tac_name ++ " tactic failed, target is not a relation application with the expected property."
end
meta def reflexivity : tactic unit :=
relation_tactic environment.refl_for "reflexivity"
meta def symmetry : tactic unit :=
relation_tactic environment.symm_for "symmetry"
meta def transitivity : tactic unit :=
relation_tactic environment.trans_for "transitivity"
meta def relation_lhs_rhs : expr β tactic (name Γ expr Γ expr) :=
Ξ» e, do
(const c _) β return e^.get_app_fn | failed,
env β get_env,
(some (arity, lhs_pos, rhs_pos)) β return $ env^.relation_info c | failed,
args β return $ get_app_args e,
guard (args^.length = arity),
(some lhs) β return $ args^.nth lhs_pos | failed,
(some rhs) β return $ args^.nth rhs_pos | failed,
return (c, lhs, rhs)
meta def target_lhs_rhs : tactic (name Γ expr Γ expr) :=
target >>= relation_lhs_rhs
end tactic
|
1da183ebcc5589fb923c7a6b599f338a9f163d59 | 5a6ff5f8d173cbfe51967eb4c96837e3a791fe3d | /mm0-lean/mm0/meta/meta.lean | b2d665f6929b75ec35a8447439ed8ceeb013787c | [
"CC0-1.0"
] | permissive | digama0/mm0 | 491ac09146708aa1bb775007bf3dbe339ffc0096 | 98496badaf6464e56ed7b4204e7d54b85667cb01 | refs/heads/master | 1,692,321,030,902 | 1,686,254,458,000 | 1,686,254,458,000 | 172,456,790 | 273 | 38 | CC0-1.0 | 1,689,939,563,000 | 1,551,080,059,000 | Rust | UTF-8 | Lean | false | false | 8,690 | lean | import data.buffer category.basic tactic.core .basic
def name.to_simple : name β string
| (name.mk_string s _) := s
| _ := ""
meta def lean.parser.tk' (n : name) : lean.parser unit :=
do x β lean.parser.ident, tactic.trace (x, n), guard (x = n)
meta def user_attribute.get_param' {Ξ± Ξ² : Type} [reflected Ξ²] (attr : user_attribute Ξ± Ξ²) (n : name) : tactic Ξ² :=
attr.get_param_untyped n >>= tactic.eval_expr' Ξ²
meta def declaration.value_opt : declaration β option expr
| (declaration.defn _ _ _ v _ _) := some v
| (declaration.thm _ _ _ v) := some v.get
| _ := none
namespace mm0
open tactic native
@[derive has_reflect]
inductive mm0_param
| ax : mm0_param
| none : mm0_param
| loc : mm0_param
| sd : sort_data β mm0_param
def mm0_param.is_ax : mm0_param β bool
| mm0_param.ax := tt
| _ := ff
def mm0_param.is_local : mm0_param β bool
| mm0_param.loc := tt
| _ := ff
meta def mm0_param.to_sd : mm0_param β option sort_data
| mm0_param.none := return {}
| (mm0_param.sd sd) := return sd
| _ := none
meta def list_name_to_sort_data : list name β option sort_data
| [] := return {}
| (a :: l) := do sd β list_name_to_sort_data l,
match a with
| `pure := return {pure := tt, ..sd}
| `strict := return {strict := tt, ..sd}
| `provable := return {provable := tt, ..sd}
| `free := return {free := tt, ..sd}
| _ := none
end
meta def parse_mm0_param : lean.parser mm0_param :=
do x β lean.parser.many lean.parser.ident,
match x with
| [] := return mm0_param.none
| [`ax] := return mm0_param.ax
| [`Local] := return mm0_param.loc
| l := mm0_param.sd <$> list_name_to_sort_data l
end
@[user_attribute]
meta def mm0 : user_attribute unit mm0_param :=
{ name := `mm0,
parser := parse_mm0_param,
after_set := some (Ξ» n _ _, do
tac β tactic.eval_expr (name β tactic unit) (expr.const `mm0.after_set []),
tac n),
descr := "Metamath Zero declaration" }
@[user_attribute]
meta def mm0_alias : user_attribute unit string :=
{ name := `mm0_alias,
parser := name.to_simple <$> lean.parser.ident,
descr := "Metamath Zero alias" }
meta def get_stmt (n : name) : tactic stmt :=
eval_expr _ (expr.const (n <.> "_stmt") [])
meta def get_term (n : name) : tactic (list binder Γ dep_type) :=
(do s β get_stmt n, match s with
| (stmt.term _ _ bs t _) := return (bs, t)
| _ := failed
end) <|> fail ("term" ++ n.to_string ++ " is not a mm0 term")
meta def binder_tac (Ξ±) := reader_t (buffer ident) (state_t (buffer binder Γ rb_set ident) tactic) Ξ±
meta instance : monad binder_tac := reader_t.monad
meta instance : alternative binder_tac := reader_t.alternative
meta instance binder_tac.monad_state : monad_state (buffer binder Γ rb_set ident) binder_tac :=
β¨Ξ» Ξ± m, reader_t.lift (monad_state.lift m)β©
meta instance : monad_reader (buffer ident) binder_tac := reader_t.monad_reader
meta instance : has_monad_lift tactic binder_tac :=
β¨Ξ» Ξ± m, reader_t.lift (state_t.lift m)β©
meta def binder_tac.run {Ξ±} (m : binder_tac Ξ±) :
tactic (Ξ± Γ buffer binder Γ rb_set ident) :=
state_t.run (reader_t.run m mk_buffer) (mk_buffer, mk_rb_set)
meta def get_var_name (n : β) : binder_tac ident :=
do ns β read,
if n < ns.size then
return (ns.read' (ns.size - 1 - n))
else monad_lift $ fail "get_var_name"
meta def push_bound {Ξ±} (n : name) (s : ident) (m : binder_tac Ξ±) : binder_tac Ξ± :=
do (bs, vs) β get,
let x := n.to_string,
monad.unlessb (vs.contains x) $
put (bs.push_back (binder.bound x s), vs.insert x),
reader_t.adapt (Ξ» ctx, ctx.push_back x) m
meta def parse_binders1_aux (x : string) : expr β buffer ident β
binder_tac unit
| (expr.pi n _ (expr.const s []) e) l :=
push_bound n s.to_simple $
parse_binders1_aux e (l.push_back n.to_string)
| (expr.const s []) l :=
modify $ Ξ» β¨bs, vsβ©, (bs.push_back (binder.reg x (s.to_simple, l.to_list)), vs)
| x e := monad_lift $ do f β pp e,
fail $ "parse_binders1_aux " ++ x.to_string ++ " " ++ f.to_string
meta def parse_binders1 (x : string) (e : expr) : binder_tac unit :=
parse_binders1_aux x e mk_buffer
meta def parse_term_aux : expr β binder_tac dep_type
| (expr.pi n _ t e) := parse_binders1 n.to_string t >> parse_term_aux e
| (expr.const s []) := return (s.to_simple, [])
| e := monad_lift $ do f β pp e, fail $ "parse_term_aux " ++ f.to_string
meta def parse_term (e : expr) : tactic (list binder Γ dep_type) :=
do (d, bs, _) β binder_tac.run (parse_term_aux e),
return (bs.to_list, d)
meta def as_sort : expr β tactic ident
| (expr.const s []) := do stmt.sort _ _ β get_stmt s, return s.to_simple
| e := do f β pp e, fail $ f.to_string ++ " is not a sort"
meta def try_bind {Ξ± Ξ²} (t : tactic Ξ±) (f : tactic Ξ²) (g : Ξ± β tactic Ξ²) : tactic Ξ² :=
do o β try_core t, option.cases_on o f g
meta mutual def parse_sexpr, parse_sexpr_list, parse_sexpr_list1
with parse_sexpr : expr β binder_tac sexpr
| e := match e.get_app_fn with
| (expr.const fn []) := do
fn' β monad_lift $ mcond (succeeds (has_attribute `mm0 fn))
(return fn.to_simple) (mm0_alias.get_param' fn),
sexpr.apps fn.to_simple <$>
parse_sexpr_list e.get_app_args (mk_name_set, mk_buffer)
| (expr.var n) := sexpr.var <$> get_var_name n
| (expr.pi n i d e) := parse_sexpr $ (expr.const `al []).app (expr.lam n i d e)
| e := monad_lift $ fail $ "unrecognized head expr " ++ e.to_string
end
with parse_sexpr_list : list expr β name_set Γ buffer sexpr β binder_tac (list sexpr)
| [] (_, buf) := return buf.to_list
| (e :: es) (m, buf) := parse_sexpr_list1 e m buf >>= parse_sexpr_list es
with parse_sexpr_list1 : expr β name_set β buffer sexpr β binder_tac (name_set Γ buffer sexpr)
| (expr.lam n _ (expr.const s []) e) m es :=
push_bound n s.to_simple $
let n' := n.to_string in
if m.contains n then
parse_sexpr_list1 e m es
else
parse_sexpr_list1 e (m.insert n) (es.push_back (sexpr.var n'))
| e m es := do
e' β parse_sexpr e,
return (m, es.push_back e')
meta def parse_hyp_aux : expr β binder_tac sexpr
| e'@(expr.pi n _ t e) := do
o β monad_lift $ try_core (as_sort t),
match o with
| some s := push_bound n s (parse_hyp_aux e)
| none := parse_sexpr e'
end
| e := parse_sexpr e
meta def parse_hyp (x : string) (e : expr) : binder_tac unit :=
do e' β parse_hyp_aux e,
modify $ Ξ» β¨bs, vsβ©, (bs.push_back (binder.hyp x e'), vs)
meta def parse_thm_aux : expr β binder_tac sexpr
| (expr.pi n binder_info.strict_implicit (expr.const t []) e) :=
push_bound n t.to_simple (parse_thm_aux e)
| (expr.pi n _ t e) := do
let n' := n.to_string,
parse_binders1 n' t <|> parse_hyp n' t,
reader_t.adapt (Ξ» ctx, ctx.push_back n') (parse_thm_aux e)
| e := parse_sexpr e
meta def parse_thm (e : expr) : tactic (list binder Γ sexpr) :=
do (d, bs, _) β binder_tac.run (parse_thm_aux e),
return (bs.to_list, d)
meta def parse_def_aux : expr β binder_tac sexpr
| (expr.lam n _ t e) := do
let n' := n.to_string,
parse_binders1 n.to_string t,
reader_t.adapt (Ξ» ctx, ctx.push_back n') (parse_def_aux e)
| e := do
(bs, _) β get,
let n := bs.size,
e' β parse_sexpr e,
(bs, _) β get,
modify $ Ξ» β¨bs, vsβ©, (bs.drop n, vs),
return e'
meta def parse_def (e : expr) : tactic (list binder Γ sexpr) :=
do (d, bs, _) β binder_tac.run (parse_def_aux e),
return (bs.to_list, d)
meta def parse_proof_aux : expr β binder_tac sexpr
| (expr.lam n binder_info.strict_implicit (expr.const t []) e) :=
push_bound n t.to_simple (parse_proof_aux e)
| (expr.lam n _ t e) := do
let n' := n.to_string,
parse_binders1 n.to_string t <|> parse_hyp n' t,
reader_t.adapt (Ξ» ctx, ctx.push_back n') (parse_proof_aux e)
| e := do
(bs, _) β get,
let n := bs.size,
e' β parse_sexpr e,
(bs, _) β get,
modify $ Ξ» β¨bs, vsβ©, (bs.drop n, vs),
return e'
meta def parse_proof (e : expr) : tactic (list binder Γ sexpr) :=
do (d, bs, _) β binder_tac.run (parse_proof_aux e),
return (bs.to_list, d)
meta def to_stmt (n : name) : tactic stmt :=
do d β get_decl n,
p β mm0.get_param' n,
match d.type with
| `(Type) := stmt.sort n.to_simple <$> p.to_sd
| e := do
pt β (sum.inl <$> parse_term e) <|> (sum.inr <$> parse_thm e),
match pt, d.value_opt.filter (Ξ» a:expr, Β¬ p.is_ax) with
| sum.inl (ls, d), e := stmt.term (Β¬ p.is_local) n.to_simple ls d <$> option.traverse parse_def e
| sum.inr (ls, d), e := stmt.thm (Β¬ p.is_local) n.to_simple ls d <$> option.traverse parse_proof e
end
end
meta def after_set (n : name) : tactic unit :=
do s β to_stmt n,
add_decl (mk_definition (n <.> "_stmt") [] `(stmt) (reflect s))
end mm0
|
7c61a37e70b4047b9e3cdae838466a472778541a | b147e1312077cdcfea8e6756207b3fa538982e12 | /algebra/ordered_group.lean | 511306fb2579aa453a1e3c465c39845d87cec59f | [
"Apache-2.0"
] | permissive | SzJS/mathlib | 07836ee708ca27cd18347e1e11ce7dd5afb3e926 | 23a5591fca0d43ee5d49d89f6f0ee07a24a6ca29 | refs/heads/master | 1,584,980,332,064 | 1,532,063,841,000 | 1,532,063,841,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 20,499 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes HΓΆlzl
Ordered monoids and groups.
-/
import algebra.group order.bounded_lattice tactic.basic
universe u
variable {Ξ± : Type u}
section old_structure_cmd
set_option old_structure_cmd true
/-- An ordered (additive) commutative monoid is a commutative monoid
with a partial order such that addition is an order embedding, i.e.
`a + b β€ a + c β b β€ c`. These monoids are automatically cancellative. -/
class ordered_comm_monoid (Ξ± : Type*) extends add_comm_monoid Ξ±, partial_order Ξ± :=
(add_le_add_left : β a b : Ξ±, a β€ b β β c : Ξ±, c + a β€ c + b)
(lt_of_add_lt_add_left : β a b c : Ξ±, a + b < a + c β b < c)
/-- A canonically ordered monoid is an ordered commutative monoid
in which the ordering coincides with the divisibility relation,
which is to say, `a β€ b` iff there exists `c` with `b = a + c`.
This is satisfied by the natural numbers, for example, but not
the integers or other ordered groups. -/
class canonically_ordered_monoid (Ξ± : Type*) extends ordered_comm_monoid Ξ± :=
(le_iff_exists_add : βa b:Ξ±, a β€ b β βc, b = a + c)
end old_structure_cmd
section ordered_comm_monoid
variables [ordered_comm_monoid Ξ±] {a b c d : Ξ±}
lemma add_le_add_left' (h : a β€ b) : c + a β€ c + b :=
ordered_comm_monoid.add_le_add_left a b h c
lemma add_le_add_right' (h : a β€ b) : a + c β€ b + c :=
add_comm c a βΈ add_comm c b βΈ add_le_add_left' h
lemma lt_of_add_lt_add_left' : a + b < a + c β b < c :=
ordered_comm_monoid.lt_of_add_lt_add_left a b c
lemma add_le_add' (hβ : a β€ b) (hβ : c β€ d) : a + c β€ b + d :=
le_trans (add_le_add_right' hβ) (add_le_add_left' hβ)
lemma le_add_of_nonneg_right' (h : b β₯ 0) : a β€ a + b :=
have a + b β₯ a + 0, from add_le_add_left' h,
by rwa add_zero at this
lemma le_add_of_nonneg_left' (h : b β₯ 0) : a β€ b + a :=
have 0 + a β€ b + a, from add_le_add_right' h,
by rwa zero_add at this
lemma lt_of_add_lt_add_right' (h : a + b < c + b) : a < c :=
lt_of_add_lt_add_left'
(show b + a < b + c, begin rw [add_comm b a, add_comm b c], assumption end)
-- here we start using properties of zero.
lemma le_add_of_nonneg_of_le' (ha : 0 β€ a) (hbc : b β€ c) : b β€ a + c :=
zero_add b βΈ add_le_add' ha hbc
lemma le_add_of_le_of_nonneg' (hbc : b β€ c) (ha : 0 β€ a) : b β€ c + a :=
add_zero b βΈ add_le_add' hbc ha
lemma add_nonneg' (ha : 0 β€ a) (hb : 0 β€ b) : 0 β€ a + b :=
le_add_of_nonneg_of_le' ha hb
lemma add_pos_of_pos_of_nonneg' (ha : 0 < a) (hb : 0 β€ b) : 0 < a + b :=
lt_of_lt_of_le ha $ le_add_of_nonneg_right' hb
lemma add_pos' (ha : 0 < a) (hb : 0 < b) : 0 < a + b :=
add_pos_of_pos_of_nonneg' ha $ le_of_lt hb
lemma add_pos_of_nonneg_of_pos' (ha : 0 β€ a) (hb : 0 < b) : 0 < a + b :=
lt_of_lt_of_le hb $ le_add_of_nonneg_left' ha
lemma add_nonpos' (ha : a β€ 0) (hb : b β€ 0) : a + b β€ 0 :=
zero_add (0:Ξ±) βΈ (add_le_add' ha hb)
lemma add_le_of_nonpos_of_le' (ha : a β€ 0) (hbc : b β€ c) : a + b β€ c :=
zero_add c βΈ add_le_add' ha hbc
lemma add_le_of_le_of_nonpos' (hbc : b β€ c) (ha : a β€ 0) : b + a β€ c :=
add_zero c βΈ add_le_add' hbc ha
lemma add_neg_of_neg_of_nonpos' (ha : a < 0) (hb : b β€ 0) : a + b < 0 :=
lt_of_le_of_lt (add_le_of_le_of_nonpos' (le_refl _) hb) ha
lemma add_neg_of_nonpos_of_neg' (ha : a β€ 0) (hb : b < 0) : a + b < 0 :=
lt_of_le_of_lt (add_le_of_nonpos_of_le' ha (le_refl _)) hb
lemma add_neg' (ha : a < 0) (hb : b < 0) : a + b < 0 :=
add_neg_of_nonpos_of_neg' (le_of_lt ha) hb
lemma lt_add_of_nonneg_of_lt' (ha : 0 β€ a) (hbc : b < c) : b < a + c :=
lt_of_lt_of_le hbc $ le_add_of_nonneg_left' ha
lemma lt_add_of_lt_of_nonneg' (hbc : b < c) (ha : 0 β€ a) : b < c + a :=
lt_of_lt_of_le hbc $ le_add_of_nonneg_right' ha
lemma lt_add_of_pos_of_lt' (ha : 0 < a) (hbc : b < c) : b < a + c :=
lt_add_of_nonneg_of_lt' (le_of_lt ha) hbc
lemma lt_add_of_lt_of_pos' (hbc : b < c) (ha : 0 < a) : b < c + a :=
lt_add_of_lt_of_nonneg' hbc (le_of_lt ha)
lemma add_lt_of_nonpos_of_lt' (ha : a β€ 0) (hbc : b < c) : a + b < c :=
lt_of_le_of_lt (add_le_of_nonpos_of_le' ha (le_refl _)) hbc
lemma add_lt_of_lt_of_nonpos' (hbc : b < c) (ha : a β€ 0) : b + a < c :=
lt_of_le_of_lt (add_le_of_le_of_nonpos' (le_refl _) ha) hbc
lemma add_lt_of_neg_of_lt' (ha : a < 0) (hbc : b < c) : a + b < c :=
add_lt_of_nonpos_of_lt' (le_of_lt ha) hbc
lemma add_lt_of_lt_of_neg' (hbc : b < c) (ha : a < 0) : b + a < c :=
add_lt_of_lt_of_nonpos' hbc (le_of_lt ha)
lemma add_eq_zero_iff_eq_zero_and_eq_zero_of_nonneg_of_nonneg'
(ha : 0 β€ a) (hb : 0 β€ b) : a + b = 0 β a = 0 β§ b = 0 :=
iff.intro
(assume hab : a + b = 0,
have a β€ 0, from hab βΈ le_add_of_le_of_nonneg' (le_refl _) hb,
have a = 0, from le_antisymm this ha,
have b β€ 0, from hab βΈ le_add_of_nonneg_of_le' ha (le_refl _),
have b = 0, from le_antisymm this hb,
and.intro βΉa = 0βΊ βΉb = 0βΊ)
(assume β¨ha', hb'β©, by rw [ha', hb', add_zero])
lemma bit0_pos {a : Ξ±} (h : 0 < a) : 0 < bit0 a :=
add_pos' h h
end ordered_comm_monoid
namespace with_zero
open lattice
instance [partial_order Ξ±] : partial_order (with_zero Ξ±) := with_bot.partial_order
instance [partial_order Ξ±] : order_bot (with_zero Ξ±) := with_bot.order_bot
instance [lattice Ξ±] : lattice (with_zero Ξ±) := with_bot.lattice
instance [linear_order Ξ±] : linear_order (with_zero Ξ±) := with_bot.linear_order
instance [decidable_linear_order Ξ±] :
decidable_linear_order (with_zero Ξ±) := with_bot.decidable_linear_order
def ordered_comm_monoid [ordered_comm_monoid Ξ±]
(zero_le : β a : Ξ±, 0 β€ a) : ordered_comm_monoid (with_zero Ξ±) :=
begin
suffices, refine {
add_le_add_left := this,
..with_zero.partial_order,
..with_zero.add_comm_monoid, ..},
{ intros a b c h,
refine β¨Ξ» b hβ, _, Ξ» hβ, h.2 $ this _ _ hβ _β©,
cases hβ, cases c with c,
{ cases h.2 (this _ _ bot_le a) },
{ refine β¨_, rfl, _β©,
cases a with a,
{ exact with_bot.some_le_some.1 h.1 },
{ exact le_of_lt (lt_of_add_lt_add_left' $
with_bot.some_lt_some.1 h), } } },
{ intros a b h c ca hβ,
cases b with b,
{ rw le_antisymm h bot_le at hβ,
exact β¨_, hβ, le_refl _β© },
cases a with a,
{ change c + 0 = some ca at hβ,
simp at hβ, simp [hβ],
exact β¨_, rfl, by simpa using add_le_add_left' (zero_le b)β© },
{ simp at h,
cases c with c; change some _ = _ at hβ;
simp [-add_comm] at hβ; subst ca; refine β¨_, rfl, _β©,
{ exact h },
{ exact add_le_add_left' h } } }
end
end with_zero
namespace with_top
open lattice
instance [add_semigroup Ξ±] : add_semigroup (with_top Ξ±) :=
{ add := Ξ» oβ oβ, oβ.bind (Ξ» a, oβ.map (Ξ» b, a + b)),
..@additive.add_semigroup _ $ @with_zero.semigroup (multiplicative Ξ±) _ }
instance [add_comm_semigroup Ξ±] : add_comm_semigroup (with_top Ξ±) :=
{ ..@additive.add_comm_semigroup _ $
@with_zero.comm_semigroup (multiplicative Ξ±) _ }
instance [add_monoid Ξ±] : add_monoid (with_top Ξ±) :=
{ zero := some 0,
..@additive.add_monoid _ $ @with_zero.monoid (multiplicative Ξ±) _ }
instance [add_comm_monoid Ξ±] : add_comm_monoid (with_top Ξ±) :=
{ ..@additive.add_comm_monoid _ $
@with_zero.comm_monoid (multiplicative Ξ±) _ }
instance [ordered_comm_monoid Ξ±] : ordered_comm_monoid (with_top Ξ±) :=
begin
suffices, refine {
add_le_add_left := this,
..with_top.partial_order,
..with_top.add_comm_monoid, ..},
{ intros a b c h,
refine β¨Ξ» c hβ, _, Ξ» hβ, h.2 $ this _ _ hβ _β©,
cases hβ, cases a with a,
{ exact (not_le_of_lt h).elim le_top },
cases b with b,
{ exact (not_le_of_lt h).elim le_top },
{ exact β¨_, rfl, le_of_lt (lt_of_add_lt_add_left' $
with_top.some_lt_some.1 h)β© } },
{ intros a b h c cb hβ,
cases c with c, {cases hβ},
cases b with b; cases hβ,
cases a with a, {cases le_antisymm h le_top},
simp at h,
exact β¨_, rfl, add_le_add_left' hβ©, }
end
end with_top
namespace with_bot
open lattice
instance [add_semigroup Ξ±] : add_semigroup (with_bot Ξ±) := with_top.add_semigroup
instance [add_comm_semigroup Ξ±] : add_comm_semigroup (with_bot Ξ±) := with_top.add_comm_semigroup
instance [add_monoid Ξ±] : add_monoid (with_bot Ξ±) := with_top.add_monoid
instance [add_comm_monoid Ξ±] : add_comm_monoid (with_bot Ξ±) := with_top.add_comm_monoid
instance [ordered_comm_monoid Ξ±] : ordered_comm_monoid (with_bot Ξ±) :=
begin
suffices, refine {
add_le_add_left := this,
..with_bot.partial_order,
..with_bot.add_comm_monoid, ..},
{ intros a b c h,
refine β¨Ξ» b hβ, _, Ξ» hβ, h.2 $ this _ _ hβ _β©,
cases hβ, cases a with a,
{ exact (not_le_of_lt h).elim bot_le },
cases c with c,
{ exact (not_le_of_lt h).elim bot_le },
{ exact β¨_, rfl, le_of_lt (lt_of_add_lt_add_left' $
with_bot.some_lt_some.1 h)β© } },
{ intros a b h c ca hβ,
cases c with c, {cases hβ},
cases a with a; cases hβ,
cases b with b, {cases le_antisymm h bot_le},
simp at h,
exact β¨_, rfl, add_le_add_left' hβ©, }
end
@[simp] lemma coe_add [add_semigroup Ξ±] (a b : Ξ±) : ((a + b : Ξ±) : with_bot Ξ±) = a + b := rfl
@[simp] lemma bot_add [ordered_comm_monoid Ξ±] (a : with_bot Ξ±) : β₯ + a = β₯ := rfl
@[simp] lemma add_bot [ordered_comm_monoid Ξ±] (a : with_bot Ξ±) : a + β₯ = β₯ := by cases a; refl
lemma coe_lt_coe {a b : β} : (a : with_bot β) < b β a < b := with_bot.some_lt_some
lemma bot_lt_some (a : β) : (β₯ : with_bot β) < some a :=
lt_of_le_of_ne bot_le (Ξ» h, option.no_confusion h)
instance has_one : has_one (with_bot β) := β¨(1 : β)β©
end with_bot
section canonically_ordered_monoid
variables [canonically_ordered_monoid Ξ±] {a b c d : Ξ±}
lemma le_iff_exists_add : a β€ b β βc, b = a + c :=
canonically_ordered_monoid.le_iff_exists_add a b
@[simp] lemma zero_le (a : Ξ±) : 0 β€ a := le_iff_exists_add.mpr β¨a, by simpβ©
@[simp] lemma add_eq_zero_iff : a + b = 0 β a = 0 β§ b = 0 :=
add_eq_zero_iff_eq_zero_and_eq_zero_of_nonneg_of_nonneg' (zero_le _) (zero_le _)
@[simp] lemma le_zero_iff_eq : a β€ 0 β a = 0 :=
iff.intro
(assume h, le_antisymm h (zero_le a))
(assume h, h βΈ le_refl a)
instance with_zero.canonically_ordered_monoid :
canonically_ordered_monoid (with_zero Ξ±) :=
{ le_iff_exists_add := Ξ» a b, begin
cases a with a,
{ exact iff_of_true lattice.bot_le β¨b, (zero_add b).symmβ© },
cases b with b,
{ exact iff_of_false
(mt (le_antisymm lattice.bot_le) (by simp))
(Ξ» β¨c, hβ©, by cases c; cases h) },
{ simp [le_iff_exists_add, -add_comm],
split; intro h; rcases h with β¨c, hβ©,
{ exact β¨some c, congr_arg some hβ© },
{ cases c; cases h,
{ exact β¨_, (add_zero _).symmβ© },
{ exact β¨_, rflβ© } } }
end,
..with_zero.ordered_comm_monoid zero_le }
end canonically_ordered_monoid
instance ordered_cancel_comm_monoid.to_ordered_comm_monoid
[H : ordered_cancel_comm_monoid Ξ±] : ordered_comm_monoid Ξ± :=
{ lt_of_add_lt_add_left := @lt_of_add_lt_add_left _ _, ..H }
section ordered_cancel_comm_monoid
variables [ordered_cancel_comm_monoid Ξ±] {a b c : Ξ±}
@[simp] lemma add_le_add_iff_left (a : Ξ±) {b c : Ξ±} : a + b β€ a + c β b β€ c :=
β¨le_of_add_le_add_left, Ξ» h, add_le_add_left h _β©
@[simp] lemma add_le_add_iff_right (c : Ξ±) : a + c β€ b + c β a β€ b :=
add_comm c a βΈ add_comm c b βΈ add_le_add_iff_left c
@[simp] lemma add_lt_add_iff_left (a : Ξ±) {b c : Ξ±} : a + b < a + c β b < c :=
β¨lt_of_add_lt_add_left, Ξ» h, add_lt_add_left h _β©
@[simp] lemma add_lt_add_iff_right (c : Ξ±) : a + c < b + c β a < b :=
add_comm c a βΈ add_comm c b βΈ add_lt_add_iff_left c
@[simp] lemma le_add_iff_nonneg_right (a : Ξ±) {b : Ξ±} : a β€ a + b β 0 β€ b :=
have a + 0 β€ a + b β 0 β€ b, from add_le_add_iff_left a,
by rwa add_zero at this
@[simp] lemma le_add_iff_nonneg_left (a : Ξ±) {b : Ξ±} : a β€ b + a β 0 β€ b :=
by rw [add_comm, le_add_iff_nonneg_right]
@[simp] lemma lt_add_iff_pos_right (a : Ξ±) {b : Ξ±} : a < a + b β 0 < b :=
have a + 0 < a + b β 0 < b, from add_lt_add_iff_left a,
by rwa add_zero at this
@[simp] lemma lt_add_iff_pos_left (a : Ξ±) {b : Ξ±} : a < b + a β 0 < b :=
by rw [add_comm, lt_add_iff_pos_right]
lemma add_eq_zero_iff_eq_zero_of_nonneg
(ha : 0 β€ a) (hb : 0 β€ b) : a + b = 0 β a = 0 β§ b = 0 :=
β¨Ξ» hab : a + b = 0,
by split; apply le_antisymm; try {assumption};
rw β hab; simp [ha, hb],
Ξ» β¨ha', hb'β©, by rw [ha', hb', add_zero]β©
end ordered_cancel_comm_monoid
section ordered_comm_group
variables [ordered_comm_group Ξ±] {a b c : Ξ±}
@[simp] lemma neg_le_neg_iff : -a β€ -b β b β€ a :=
have a + b + -a β€ a + b + -b β -a β€ -b, from add_le_add_iff_left _,
by simp at this; simp [this]
lemma neg_le : -a β€ b β -b β€ a :=
have -a β€ -(-b) β -b β€ a, from neg_le_neg_iff,
by rwa neg_neg at this
lemma le_neg : a β€ -b β b β€ -a :=
have -(-a) β€ -b β b β€ -a, from neg_le_neg_iff,
by rwa neg_neg at this
@[simp] lemma neg_nonpos : -a β€ 0 β 0 β€ a :=
have -a β€ -0 β 0 β€ a, from neg_le_neg_iff,
by rwa neg_zero at this
@[simp] lemma neg_nonneg : 0 β€ -a β a β€ 0 :=
have -0 β€ -a β a β€ 0, from neg_le_neg_iff,
by rwa neg_zero at this
@[simp] lemma neg_lt_neg_iff : -a < -b β b < a :=
have a + b + -a < a + b + -b β -a < -b, from add_lt_add_iff_left _,
by simp at this; simp [this]
lemma neg_lt_zero : -a < 0 β 0 < a :=
have -a < -0 β 0 < a, from neg_lt_neg_iff,
by rwa neg_zero at this
lemma neg_pos : 0 < -a β a < 0 :=
have -0 < -a β a < 0, from neg_lt_neg_iff,
by rwa neg_zero at this
lemma neg_lt : -a < b β -b < a :=
have -a < -(-b) β -b < a, from neg_lt_neg_iff,
by rwa neg_neg at this
lemma lt_neg : a < -b β b < -a :=
have -(-a) < -b β b < -a, from neg_lt_neg_iff,
by rwa neg_neg at this
lemma sub_le_sub_iff_left (a : Ξ±) {b c : Ξ±} : a - b β€ a - c β c β€ b :=
(add_le_add_iff_left _).trans neg_le_neg_iff
lemma sub_le_sub_iff_right (c : Ξ±) : a - c β€ b - c β a β€ b :=
add_le_add_iff_right _
lemma sub_lt_sub_iff_left (a : Ξ±) {b c : Ξ±} : a - b < a - c β c < b :=
(add_lt_add_iff_left _).trans neg_lt_neg_iff
lemma sub_lt_sub_iff_right (c : Ξ±) : a - c < b - c β a < b :=
add_lt_add_iff_right _
@[simp] lemma sub_nonneg : 0 β€ a - b β b β€ a :=
have a - a β€ a - b β b β€ a, from sub_le_sub_iff_left a,
by rwa sub_self at this
@[simp] lemma sub_nonpos : a - b β€ 0 β a β€ b :=
have a - b β€ b - b β a β€ b, from sub_le_sub_iff_right b,
by rwa sub_self at this
@[simp] lemma sub_pos : 0 < a - b β b < a :=
have a - a < a - b β b < a, from sub_lt_sub_iff_left a,
by rwa sub_self at this
@[simp] lemma sub_lt_zero : a - b < 0 β a < b :=
have a - b < b - b β a < b, from sub_lt_sub_iff_right b,
by rwa sub_self at this
lemma le_neg_add_iff_add_le : b β€ -a + c β a + b β€ c :=
have -a + (a + b) β€ -a + c β a + b β€ c, from add_le_add_iff_left _,
by rwa neg_add_cancel_left at this
lemma le_sub_iff_add_le' : b β€ c - a β a + b β€ c :=
by rw [sub_eq_add_neg, add_comm, le_neg_add_iff_add_le]
lemma le_sub_iff_add_le : a β€ c - b β a + b β€ c :=
by rw [le_sub_iff_add_le', add_comm]
@[simp] lemma neg_add_le_iff_le_add : -b + a β€ c β a β€ b + c :=
have -b + a β€ -b + (b + c) β a β€ b + c, from add_le_add_iff_left _,
by rwa neg_add_cancel_left at this
lemma sub_le_iff_le_add' : a - b β€ c β a β€ b + c :=
by rw [sub_eq_add_neg, add_comm, neg_add_le_iff_le_add]
lemma sub_le_iff_le_add : a - c β€ b β a β€ b + c :=
by rw [sub_le_iff_le_add', add_comm]
@[simp] lemma add_neg_le_iff_le_add : a + -c β€ b β a β€ b + c :=
sub_le_iff_le_add
@[simp] lemma add_neg_le_iff_le_add' : a + -b β€ c β a β€ b + c :=
sub_le_iff_le_add'
lemma neg_add_le_iff_le_add' : -c + a β€ b β a β€ b + c :=
by rw [neg_add_le_iff_le_add, add_comm]
@[simp] lemma neg_le_sub_iff_le_add : -b β€ a - c β c β€ a + b :=
le_sub_iff_add_le.trans neg_add_le_iff_le_add'
lemma neg_le_sub_iff_le_add' : -a β€ b - c β c β€ a + b :=
by rw [neg_le_sub_iff_le_add, add_comm]
lemma sub_le : a - b β€ c β a - c β€ b :=
sub_le_iff_le_add'.trans sub_le_iff_le_add.symm
theorem le_sub : a β€ b - c β c β€ b - a :=
le_sub_iff_add_le'.trans le_sub_iff_add_le.symm
@[simp] lemma lt_neg_add_iff_add_lt : b < -a + c β a + b < c :=
have -a + (a + b) < -a + c β a + b < c, from add_lt_add_iff_left _,
by rwa neg_add_cancel_left at this
lemma lt_sub_iff_add_lt' : b < c - a β a + b < c :=
by rw [sub_eq_add_neg, add_comm, lt_neg_add_iff_add_lt]
lemma lt_sub_iff_add_lt : a < c - b β a + b < c :=
by rw [lt_sub_iff_add_lt', add_comm]
@[simp] lemma neg_add_lt_iff_lt_add : -b + a < c β a < b + c :=
have -b + a < -b + (b + c) β a < b + c, from add_lt_add_iff_left _,
by rwa neg_add_cancel_left at this
lemma sub_lt_iff_lt_add' : a - b < c β a < b + c :=
by rw [sub_eq_add_neg, add_comm, neg_add_lt_iff_lt_add]
lemma sub_lt_iff_lt_add : a - c < b β a < b + c :=
by rw [sub_lt_iff_lt_add', add_comm]
lemma neg_add_lt_iff_lt_add_right : -c + a < b β a < b + c :=
by rw [neg_add_lt_iff_lt_add, add_comm]
@[simp] lemma neg_lt_sub_iff_lt_add : -b < a - c β c < a + b :=
lt_sub_iff_add_lt.trans neg_add_lt_iff_lt_add_right
lemma neg_lt_sub_iff_lt_add' : -a < b - c β c < a + b :=
by rw [neg_lt_sub_iff_lt_add, add_comm]
lemma sub_lt : a - b < c β a - c < b :=
sub_lt_iff_lt_add'.trans sub_lt_iff_lt_add.symm
theorem lt_sub : a < b - c β c < b - a :=
lt_sub_iff_add_lt'.trans lt_sub_iff_add_lt.symm
lemma sub_le_self_iff (a : Ξ±) {b : Ξ±} : a - b β€ a β 0 β€ b :=
sub_le_iff_le_add'.trans (le_add_iff_nonneg_left _)
lemma sub_lt_self_iff (a : Ξ±) {b : Ξ±} : a - b < a β 0 < b :=
sub_lt_iff_lt_add'.trans (lt_add_iff_pos_left _)
end ordered_comm_group
set_option old_structure_cmd true
/-- This is not so much a new structure as a construction mechanism
for ordered groups, by specifying only the "positive cone" of the group. -/
class nonneg_comm_group (Ξ± : Type*) extends add_comm_group Ξ± :=
(nonneg : Ξ± β Prop)
(pos : Ξ± β Prop := Ξ» a, nonneg a β§ Β¬ nonneg (neg a))
(pos_iff : β a, pos a β nonneg a β§ Β¬ nonneg (-a) . order_laws_tac)
(zero_nonneg : nonneg 0)
(add_nonneg : β {a b}, nonneg a β nonneg b β nonneg (a + b))
(nonneg_antisymm : β {a}, nonneg a β nonneg (-a) β a = 0)
namespace nonneg_comm_group
variable [s : nonneg_comm_group Ξ±]
include s
@[reducible] instance to_ordered_comm_group : ordered_comm_group Ξ± :=
{ le := Ξ» a b, nonneg (b - a),
lt := Ξ» a b, pos (b - a),
lt_iff_le_not_le := Ξ» a b, by simp; rw [pos_iff]; simp,
le_refl := Ξ» a, by simp [zero_nonneg],
le_trans := Ξ» a b c nab nbc, by simp [-sub_eq_add_neg];
rw β sub_add_sub_cancel; exact add_nonneg nbc nab,
le_antisymm := Ξ» a b nab nba, eq_of_sub_eq_zero $
nonneg_antisymm nba (by rw neg_sub; exact nab),
add_le_add_left := Ξ» a b nab c, by simpa [(β€), preorder.le] using nab,
add_lt_add_left := Ξ» a b nab c, by simpa [(<), preorder.lt] using nab, ..s }
theorem nonneg_def {a : Ξ±} : nonneg a β 0 β€ a :=
show _ β nonneg _, by simp
theorem pos_def {a : Ξ±} : pos a β 0 < a :=
show _ β pos _, by simp
theorem not_zero_pos : Β¬ pos (0 : Ξ±) :=
mt pos_def.1 (lt_irrefl _)
theorem zero_lt_iff_nonneg_nonneg {a : Ξ±} :
0 < a β nonneg a β§ Β¬ nonneg (-a) :=
pos_def.symm.trans (pos_iff Ξ± _)
theorem nonneg_total_iff :
(β a : Ξ±, nonneg a β¨ nonneg (-a)) β
(β a b : Ξ±, a β€ b β¨ b β€ a) :=
β¨Ξ» h a b, by have := h (b - a); rwa [neg_sub] at this,
Ξ» h a, by rw [nonneg_def, nonneg_def, neg_nonneg]; apply hβ©
def to_decidable_linear_ordered_comm_group
[decidable_pred (@nonneg Ξ± _)]
(nonneg_total : β a : Ξ±, nonneg a β¨ nonneg (-a))
: decidable_linear_ordered_comm_group Ξ± :=
{ le := (β€),
lt := (<),
lt_iff_le_not_le := @lt_iff_le_not_le _ _,
le_refl := @le_refl _ _,
le_trans := @le_trans _ _,
le_antisymm := @le_antisymm _ _,
le_total := nonneg_total_iff.1 nonneg_total,
decidable_le := by apply_instance,
decidable_eq := by apply_instance,
decidable_lt := by apply_instance,
..@nonneg_comm_group.to_ordered_comm_group _ s }
end nonneg_comm_group
|
3e07be93dd53b97240c781fe39936e4af43e00c8 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/linear_algebra/free_module/finite/matrix.lean | 330c3b24583d0c70fce0a6851240ad5dfbe8f745 | [
"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 | 3,441 | 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 linear_algebra.finrank
import linear_algebra.free_module.finite.rank
import linear_algebra.matrix.to_lin
/-!
# Finite and free modules using matrices
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We provide some instances for finite and free modules involving matrices.
## Main results
* `module.free.linear_map` : if `M` and `N` are finite and free, then `M ββ[R] N` is free.
* `module.finite.of_basis` : A free module with a basis indexed by a `fintype` is finite.
* `module.finite.linear_map` : if `M` and `N` are finite and free, then `M ββ[R] N`
is finite.
-/
universes u v w
variables (R : Type u) (M : Type v) (N : Type w)
open module.free (choose_basis)
open finite_dimensional (finrank)
section comm_ring
variables [comm_ring R] [add_comm_group M] [module R M] [module.free R M]
variables [add_comm_group N] [module R N] [module.free R N]
instance module.free.linear_map [module.finite R M] [module.finite R N] :
module.free R (M ββ[R] N) :=
begin
casesI subsingleton_or_nontrivial R,
{ apply module.free.of_subsingleton' },
classical,
exact module.free.of_equiv (linear_map.to_matrix (choose_basis R M) (choose_basis R N)).symm,
end
variables {R}
instance module.finite.linear_map [module.finite R M] [module.finite R N] :
module.finite R (M ββ[R] N) :=
begin
casesI subsingleton_or_nontrivial R,
{ apply_instance },
classical,
have f := (linear_map.to_matrix (choose_basis R M) (choose_basis R N)).symm,
exact module.finite.of_surjective f.to_linear_map (linear_equiv.surjective f),
end
end comm_ring
section integer
variables [add_comm_group M] [module.finite β€ M] [module.free β€ M]
variables [add_comm_group N] [module.finite β€ N] [module.free β€ N]
instance module.finite.add_monoid_hom : module.finite β€ (M β+ N) :=
module.finite.equiv (add_monoid_hom_lequiv_int β€).symm
instance module.free.add_monoid_hom : module.free β€ (M β+ N) :=
begin
letI : module.free β€ (M ββ[β€] N) := module.free.linear_map _ _ _,
exact module.free.of_equiv (add_monoid_hom_lequiv_int β€).symm
end
end integer
section comm_ring
variables [comm_ring R] [strong_rank_condition R]
variables [add_comm_group M] [module R M] [module.free R M] [module.finite R M]
variables [add_comm_group N] [module R N] [module.free R N] [module.finite R N]
/-- The finrank of `M ββ[R] N` is `(finrank R M) * (finrank R N)`. -/
lemma finite_dimensional.finrank_linear_map :
finrank R (M ββ[R] N) = (finrank R M) * (finrank R N) :=
begin
classical,
letI := nontrivial_of_invariant_basis_number R,
have h := (linear_map.to_matrix (choose_basis R M) (choose_basis R N)),
simp_rw [h.finrank_eq, finite_dimensional.finrank_matrix,
finite_dimensional.finrank_eq_card_choose_basis_index, mul_comm],
end
end comm_ring
lemma matrix.rank_vec_mul_vec {K m n : Type u}
[comm_ring K] [strong_rank_condition K] [fintype n] [decidable_eq n]
(w : m β K) (v : n β K) :
(matrix.vec_mul_vec w v).to_lin'.rank β€ 1 :=
begin
rw [matrix.vec_mul_vec_eq, matrix.to_lin'_mul],
refine le_trans (linear_map.rank_comp_le_left _ _) _,
refine (linear_map.rank_le_domain _).trans_eq _,
rw [rank_fun', fintype.card_unit, nat.cast_one]
end
|
fc515c292825fe5a0bf747d0b7292c70f040f4a6 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/order/ord_continuous.lean | 29a53afed5cf1f60a07aad788bd208fdbddb5161 | [
"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,022 | lean | /-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov, Johannes HΓΆlzl
-/
import order.conditionally_complete_lattice
import logic.function.iterate
import order.rel_iso
/-!
# Order continuity
We say that a function is *left order continuous* if it sends all least upper bounds
to least upper bounds. The order dual notion is called *right order continuity*.
For monotone functions `β β β` these notions correspond to the usual left and right continuity.
We prove some basic lemmas (`map_sup`, `map_Sup` etc) and prove that an `rel_iso` is both left
and right order continuous.
-/
universes u v w x
variables {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} {ΞΉ : Sort x}
open set function
/-!
### Definitions
-/
/-- A function `f` between preorders is left order continuous if it preserves all suprema. We
define it using `is_lub` instead of `Sup` so that the proof works both for complete lattices and
conditionally complete lattices. -/
def left_ord_continuous [preorder Ξ±] [preorder Ξ²] (f : Ξ± β Ξ²) :=
β β¦s : set Ξ±β¦ β¦xβ¦, is_lub s x β is_lub (f '' s) (f x)
/-- A function `f` between preorders is right order continuous if it preserves all infima. We
define it using `is_glb` instead of `Inf` so that the proof works both for complete lattices and
conditionally complete lattices. -/
def right_ord_continuous [preorder Ξ±] [preorder Ξ²] (f : Ξ± β Ξ²) :=
β β¦s : set Ξ±β¦ β¦xβ¦, is_glb s x β is_glb (f '' s) (f x)
namespace left_ord_continuous
section preorder
variables (Ξ±) [preorder Ξ±] [preorder Ξ²] [preorder Ξ³] {g : Ξ² β Ξ³} {f : Ξ± β Ξ²}
protected lemma id : left_ord_continuous (id : Ξ± β Ξ±) := Ξ» s x h, by simpa only [image_id] using h
variable {Ξ±}
protected lemma order_dual (hf : left_ord_continuous f) :
@right_ord_continuous (order_dual Ξ±) (order_dual Ξ²) _ _ f := hf
lemma map_is_greatest (hf : left_ord_continuous f) {s : set Ξ±} {x : Ξ±} (h : is_greatest s x):
is_greatest (f '' s) (f x) :=
β¨mem_image_of_mem f h.1, (hf h.is_lub).1β©
lemma mono (hf : left_ord_continuous f) : monotone f :=
Ξ» aβ aβ h,
have is_greatest {aβ, aβ} aβ := β¨or.inr rfl, by simp [*]β©,
(hf.map_is_greatest this).2 $ mem_image_of_mem _ (or.inl rfl)
lemma comp (hg : left_ord_continuous g) (hf : left_ord_continuous f) :
left_ord_continuous (g β f) :=
Ξ» s x h, by simpa only [image_image] using hg (hf h)
protected lemma iterate {f : Ξ± β Ξ±} (hf : left_ord_continuous f) (n : β) :
left_ord_continuous (f^[n]) :=
nat.rec_on n (left_ord_continuous.id Ξ±) $ Ξ» n ihn, ihn.comp hf
end preorder
section semilattice_sup
variables [semilattice_sup Ξ±] [semilattice_sup Ξ²] {f : Ξ± β Ξ²}
lemma map_sup (hf : left_ord_continuous f) (x y : Ξ±) :
f (x β y) = f x β f y :=
(hf is_lub_pair).unique $ by simp only [image_pair, is_lub_pair]
lemma le_iff (hf : left_ord_continuous f) (h : injective f) {x y} :
f x β€ f y β x β€ y :=
by simp only [β sup_eq_right, β hf.map_sup, h.eq_iff]
lemma lt_iff (hf : left_ord_continuous f) (h : injective f) {x y} :
f x < f y β x < y :=
by simp only [lt_iff_le_not_le, hf.le_iff h]
variable (f)
/-- Convert an injective left order continuous function to an order embedding. -/
def to_order_embedding (hf : left_ord_continuous f) (h : injective f) :
Ξ± βͺo Ξ² :=
β¨β¨f, hβ©, Ξ» x y, hf.le_iff hβ©
variable {f}
@[simp] lemma coe_to_order_embedding (hf : left_ord_continuous f) (h : injective f) :
β(hf.to_order_embedding f h) = f := rfl
end semilattice_sup
section complete_lattice
variables [complete_lattice Ξ±] [complete_lattice Ξ²] {f : Ξ± β Ξ²}
lemma map_Sup' (hf : left_ord_continuous f) (s : set Ξ±) :
f (Sup s) = Sup (f '' s) :=
(hf $ is_lub_Sup s).Sup_eq.symm
lemma map_Sup (hf : left_ord_continuous f) (s : set Ξ±) :
f (Sup s) = β¨ x β s, f x :=
by rw [hf.map_Sup', Sup_image]
lemma map_supr (hf : left_ord_continuous f) (g : ΞΉ β Ξ±) :
f (β¨ i, g i) = β¨ i, f (g i) :=
by simp only [supr, hf.map_Sup', β range_comp]
end complete_lattice
section conditionally_complete_lattice
variables [conditionally_complete_lattice Ξ±] [conditionally_complete_lattice Ξ²] [nonempty ΞΉ]
{f : Ξ± β Ξ²}
lemma map_cSup (hf : left_ord_continuous f) {s : set Ξ±} (sne : s.nonempty) (sbdd : bdd_above s) :
f (Sup s) = Sup (f '' s) :=
((hf $ is_lub_cSup sne sbdd).cSup_eq $ sne.image f).symm
lemma map_csupr (hf : left_ord_continuous f) {g : ΞΉ β Ξ±} (hg : bdd_above (range g)) :
f (β¨ i, g i) = β¨ i, f (g i) :=
by simp only [supr, hf.map_cSup (range_nonempty _) hg, β range_comp]
end conditionally_complete_lattice
end left_ord_continuous
namespace right_ord_continuous
section preorder
variables (Ξ±) [preorder Ξ±] [preorder Ξ²] [preorder Ξ³] {g : Ξ² β Ξ³} {f : Ξ± β Ξ²}
protected lemma id : right_ord_continuous (id : Ξ± β Ξ±) := Ξ» s x h, by simpa only [image_id] using h
variable {Ξ±}
protected lemma order_dual (hf : right_ord_continuous f) :
@left_ord_continuous (order_dual Ξ±) (order_dual Ξ²) _ _ f := hf
lemma map_is_least (hf : right_ord_continuous f) {s : set Ξ±} {x : Ξ±} (h : is_least s x):
is_least (f '' s) (f x) :=
hf.order_dual.map_is_greatest h
lemma mono (hf : right_ord_continuous f) : monotone f :=
hf.order_dual.mono.order_dual
lemma comp (hg : right_ord_continuous g) (hf : right_ord_continuous f) :
right_ord_continuous (g β f) :=
hg.order_dual.comp hf.order_dual
protected lemma iterate {f : Ξ± β Ξ±} (hf : right_ord_continuous f) (n : β) :
right_ord_continuous (f^[n]) :=
hf.order_dual.iterate n
end preorder
section semilattice_inf
variables [semilattice_inf Ξ±] [semilattice_inf Ξ²] {f : Ξ± β Ξ²}
lemma map_inf (hf : right_ord_continuous f) (x y : Ξ±) :
f (x β y) = f x β f y :=
hf.order_dual.map_sup x y
lemma le_iff (hf : right_ord_continuous f) (h : injective f) {x y} :
f x β€ f y β x β€ y :=
hf.order_dual.le_iff h
lemma lt_iff (hf : right_ord_continuous f) (h : injective f) {x y} :
f x < f y β x < y :=
hf.order_dual.lt_iff h
variable (f)
/-- Convert an injective left order continuous function to a `order_embedding`. -/
def to_order_embedding (hf : right_ord_continuous f) (h : injective f) : Ξ± βͺo Ξ² :=
β¨β¨f, hβ©, Ξ» x y, hf.le_iff hβ©
variable {f}
@[simp] lemma coe_to_order_embedding (hf : right_ord_continuous f) (h : injective f) :
β(hf.to_order_embedding f h) = f := rfl
end semilattice_inf
section complete_lattice
variables [complete_lattice Ξ±] [complete_lattice Ξ²] {f : Ξ± β Ξ²}
lemma map_Inf' (hf : right_ord_continuous f) (s : set Ξ±) :
f (Inf s) = Inf (f '' s) :=
hf.order_dual.map_Sup' s
lemma map_Inf (hf : right_ord_continuous f) (s : set Ξ±) :
f (Inf s) = β¨
x β s, f x :=
hf.order_dual.map_Sup s
lemma map_infi (hf : right_ord_continuous f) (g : ΞΉ β Ξ±) :
f (β¨
i, g i) = β¨
i, f (g i) :=
hf.order_dual.map_supr g
end complete_lattice
section conditionally_complete_lattice
variables [conditionally_complete_lattice Ξ±] [conditionally_complete_lattice Ξ²] [nonempty ΞΉ]
{f : Ξ± β Ξ²}
lemma map_cInf (hf : right_ord_continuous f) {s : set Ξ±} (sne : s.nonempty) (sbdd : bdd_below s) :
f (Inf s) = Inf (f '' s) :=
hf.order_dual.map_cSup sne sbdd
lemma map_cinfi (hf : right_ord_continuous f) {g : ΞΉ β Ξ±} (hg : bdd_below (range g)) :
f (β¨
i, g i) = β¨
i, f (g i) :=
hf.order_dual.map_csupr hg
end conditionally_complete_lattice
end right_ord_continuous
namespace order_iso
section preorder
variables [preorder Ξ±] [preorder Ξ²] (e : Ξ± βo Ξ²)
{s : set Ξ±} {x : Ξ±}
protected lemma left_ord_continuous : left_ord_continuous e :=
Ξ» s x hx,
β¨monotone.mem_upper_bounds_image (Ξ» x y, e.map_rel_iff.2) hx.1,
Ξ» y hy, e.rel_symm_apply.1 $ (is_lub_le_iff hx).2 $ Ξ» x' hx', e.rel_symm_apply.2 $ hy $
mem_image_of_mem _ hx'β©
protected lemma right_ord_continuous : right_ord_continuous e :=
order_iso.left_ord_continuous e.dual
end preorder
end order_iso
|
62a3e287e7ecd35e2f61e30f8412620af1eed6ae | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/data/list/prod_sigma.lean | fe6885d2f91c26ee6a4def1191d5804dd0db6242 | [
"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 | 2,548 | lean | /-
Copyright (c) 2015 Leonardo de Moura. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Mario Carneiro
-/
import data.list.big_operators
/-!
# Lists in product and sigma types
This file proves basic properties of `list.product` and `list.sigma`, which are list constructions
living in `prod` and `sigma` types respectively. Their definitions can be found in
[`data.list.defs`](./data/list/defs). Beware, this is not about `list.prod`, the multiplicative
product.
-/
variables {Ξ± Ξ² : Type*}
namespace list
/-! ### product -/
@[simp] lemma nil_product (l : list Ξ²) : product (@nil Ξ±) l = [] := rfl
@[simp] lemma product_cons (a : Ξ±) (lβ : list Ξ±) (lβ : list Ξ²)
: product (a::lβ) lβ = map (Ξ» b, (a, b)) lβ ++ product lβ lβ := rfl
@[simp] lemma product_nil : β (l : list Ξ±), product l (@nil Ξ²) = []
| [] := rfl
| (a::l) := by rw [product_cons, product_nil]; refl
@[simp] lemma mem_product {lβ : list Ξ±} {lβ : list Ξ²} {a : Ξ±} {b : Ξ²} :
(a, b) β product lβ lβ β a β lβ β§ b β lβ :=
by simp only [product, mem_bind, mem_map, prod.ext_iff, exists_prop,
and.left_comm, exists_and_distrib_left, exists_eq_left, exists_eq_right]
lemma length_product (lβ : list Ξ±) (lβ : list Ξ²) :
length (product lβ lβ) = length lβ * length lβ :=
by induction lβ with x lβ IH; [exact (zero_mul _).symm,
simp only [length, product_cons, length_append, IH,
right_distrib, one_mul, length_map, add_comm]]
/-! ### sigma -/
variable {Ο : Ξ± β Type*}
@[simp] lemma nil_sigma (l : Ξ a, list (Ο a)) : (@nil Ξ±).sigma l = [] := rfl
@[simp] lemma sigma_cons (a : Ξ±) (lβ : list Ξ±) (lβ : Ξ a, list (Ο a))
: (a::lβ).sigma lβ = map (sigma.mk a) (lβ a) ++ lβ.sigma lβ := rfl
@[simp] lemma sigma_nil : β (l : list Ξ±), l.sigma (Ξ» a, @nil (Ο a)) = []
| [] := rfl
| (a::l) := by rw [sigma_cons, sigma_nil]; refl
@[simp] lemma mem_sigma {lβ : list Ξ±} {lβ : Ξ a, list (Ο a)} {a : Ξ±} {b : Ο a} :
sigma.mk a b β lβ.sigma lβ β a β lβ β§ b β lβ a :=
by simp only [list.sigma, mem_bind, mem_map, exists_prop, exists_and_distrib_left,
and.left_comm, exists_eq_left, heq_iff_eq, exists_eq_right]
lemma length_sigma (lβ : list Ξ±) (lβ : Ξ a, list (Ο a)) :
length (lβ.sigma lβ) = (lβ.map (Ξ» a, length (lβ a))).sum :=
by induction lβ with x lβ IH; [refl,
simp only [map, sigma_cons, length_append, length_map, IH, sum_cons]]
end list
|
4382253b4cf143cc477f6d7cc9aee1d9d8d4b003 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/topology/algebra/order/liminf_limsup.lean | 30d7484a0e540cd76fe938ec7bdac6a91b8c5beb | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 8,407 | lean | /-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl, Mario Carneiro, Yury Kudryashov
-/
import order.liminf_limsup
import topology.algebra.order.basic
/-!
# Lemmas about liminf and limsup in an order topology.
-/
open filter
open_locale topological_space classical
universes u v
variables {Ξ± : Type u} {Ξ² : Type v}
section liminf_limsup
section order_closed_topology
variables [semilattice_sup Ξ±] [topological_space Ξ±] [order_topology Ξ±]
lemma is_bounded_le_nhds (a : Ξ±) : (π a).is_bounded (β€) :=
match forall_le_or_exists_lt_sup a with
| or.inl h := β¨a, eventually_of_forall hβ©
| or.inr β¨b, hbβ© := β¨b, ge_mem_nhds hbβ©
end
lemma filter.tendsto.is_bounded_under_le {f : filter Ξ²} {u : Ξ² β Ξ±} {a : Ξ±}
(h : tendsto u f (π a)) : f.is_bounded_under (β€) u :=
(is_bounded_le_nhds a).mono h
lemma filter.tendsto.bdd_above_range_of_cofinite {u : Ξ² β Ξ±} {a : Ξ±}
(h : tendsto u cofinite (π a)) : bdd_above (set.range u) :=
h.is_bounded_under_le.bdd_above_range_of_cofinite
lemma filter.tendsto.bdd_above_range {u : β β Ξ±} {a : Ξ±}
(h : tendsto u at_top (π a)) : bdd_above (set.range u) :=
h.is_bounded_under_le.bdd_above_range
lemma is_cobounded_ge_nhds (a : Ξ±) : (π a).is_cobounded (β₯) :=
(is_bounded_le_nhds a).is_cobounded_flip
lemma filter.tendsto.is_cobounded_under_ge {f : filter Ξ²} {u : Ξ² β Ξ±} {a : Ξ±}
[ne_bot f] (h : tendsto u f (π a)) : f.is_cobounded_under (β₯) u :=
h.is_bounded_under_le.is_cobounded_flip
end order_closed_topology
section order_closed_topology
variables [semilattice_inf Ξ±] [topological_space Ξ±] [order_topology Ξ±]
lemma is_bounded_ge_nhds (a : Ξ±) : (π a).is_bounded (β₯) := @is_bounded_le_nhds Ξ±α΅α΅ _ _ _ a
lemma filter.tendsto.is_bounded_under_ge {f : filter Ξ²} {u : Ξ² β Ξ±} {a : Ξ±}
(h : tendsto u f (π a)) : f.is_bounded_under (β₯) u :=
(is_bounded_ge_nhds a).mono h
lemma filter.tendsto.bdd_below_range_of_cofinite {u : Ξ² β Ξ±} {a : Ξ±}
(h : tendsto u cofinite (π a)) : bdd_below (set.range u) :=
h.is_bounded_under_ge.bdd_below_range_of_cofinite
lemma filter.tendsto.bdd_below_range {u : β β Ξ±} {a : Ξ±}
(h : tendsto u at_top (π a)) : bdd_below (set.range u) :=
h.is_bounded_under_ge.bdd_below_range
lemma is_cobounded_le_nhds (a : Ξ±) : (π a).is_cobounded (β€) :=
(is_bounded_ge_nhds a).is_cobounded_flip
lemma filter.tendsto.is_cobounded_under_le {f : filter Ξ²} {u : Ξ² β Ξ±} {a : Ξ±}
[ne_bot f] (h : tendsto u f (π a)) : f.is_cobounded_under (β€) u :=
h.is_bounded_under_ge.is_cobounded_flip
end order_closed_topology
section conditionally_complete_linear_order
variables [conditionally_complete_linear_order Ξ±]
theorem lt_mem_sets_of_Limsup_lt {f : filter Ξ±} {b} (h : f.is_bounded (β€)) (l : f.Limsup < b) :
βαΆ a in f, a < b :=
let β¨c, (h : βαΆ a in f, a β€ c), hcbβ© := exists_lt_of_cInf_lt h l in
mem_of_superset h $ assume a hac, lt_of_le_of_lt hac hcb
theorem gt_mem_sets_of_Liminf_gt : β {f : filter Ξ±} {b}, f.is_bounded (β₯) β b < f.Liminf β
βαΆ a in f, b < a :=
@lt_mem_sets_of_Limsup_lt Ξ±α΅α΅ _
variables [topological_space Ξ±] [order_topology Ξ±]
/-- If the liminf and the limsup of a filter coincide, then this filter converges to
their common value, at least if the filter is eventually bounded above and below. -/
theorem le_nhds_of_Limsup_eq_Liminf {f : filter Ξ±} {a : Ξ±}
(hl : f.is_bounded (β€)) (hg : f.is_bounded (β₯)) (hs : f.Limsup = a) (hi : f.Liminf = a) :
f β€ π a :=
tendsto_order.2 $ and.intro
(assume b hb, gt_mem_sets_of_Liminf_gt hg $ hi.symm βΈ hb)
(assume b hb, lt_mem_sets_of_Limsup_lt hl $ hs.symm βΈ hb)
theorem Limsup_nhds (a : Ξ±) : Limsup (π a) = a :=
cInf_eq_of_forall_ge_of_forall_gt_exists_lt (is_bounded_le_nhds a)
(assume a' (h : {n : Ξ± | n β€ a'} β π a), show a β€ a', from @mem_of_mem_nhds Ξ± _ a _ h)
(assume b (hba : a < b), show βc (h : {n : Ξ± | n β€ c} β π a), c < b, from
match dense_or_discrete a b with
| or.inl β¨c, hac, hcbβ© := β¨c, ge_mem_nhds hac, hcbβ©
| or.inr β¨_, hβ© := β¨a, (π a).sets_of_superset (gt_mem_nhds hba) h, hbaβ©
end)
theorem Liminf_nhds : β (a : Ξ±), Liminf (π a) = a := @Limsup_nhds Ξ±α΅α΅ _ _ _
/-- If a filter is converging, its limsup coincides with its limit. -/
theorem Liminf_eq_of_le_nhds {f : filter Ξ±} {a : Ξ±} [ne_bot f] (h : f β€ π a) : f.Liminf = a :=
have hb_ge : is_bounded (β₯) f, from (is_bounded_ge_nhds a).mono h,
have hb_le : is_bounded (β€) f, from (is_bounded_le_nhds a).mono h,
le_antisymm
(calc f.Liminf β€ f.Limsup : Liminf_le_Limsup hb_le hb_ge
... β€ (π a).Limsup :
Limsup_le_Limsup_of_le h hb_ge.is_cobounded_flip (is_bounded_le_nhds a)
... = a : Limsup_nhds a)
(calc a = (π a).Liminf : (Liminf_nhds a).symm
... β€ f.Liminf :
Liminf_le_Liminf_of_le h (is_bounded_ge_nhds a) hb_le.is_cobounded_flip)
/-- If a filter is converging, its liminf coincides with its limit. -/
theorem Limsup_eq_of_le_nhds : β {f : filter Ξ±} {a : Ξ±} [ne_bot f], f β€ π a β f.Limsup = a :=
@Liminf_eq_of_le_nhds Ξ±α΅α΅ _ _ _
/-- If a function has a limit, then its limsup coincides with its limit. -/
theorem filter.tendsto.limsup_eq {f : filter Ξ²} {u : Ξ² β Ξ±} {a : Ξ±} [ne_bot f]
(h : tendsto u f (π a)) : limsup f u = a :=
Limsup_eq_of_le_nhds h
/-- If a function has a limit, then its liminf coincides with its limit. -/
theorem filter.tendsto.liminf_eq {f : filter Ξ²} {u : Ξ² β Ξ±} {a : Ξ±} [ne_bot f]
(h : tendsto u f (π a)) : liminf f u = a :=
Liminf_eq_of_le_nhds h
/-- If the liminf and the limsup of a function coincide, then the limit of the function
exists and has the same value -/
theorem tendsto_of_liminf_eq_limsup {f : filter Ξ²} {u : Ξ² β Ξ±} {a : Ξ±}
(hinf : liminf f u = a) (hsup : limsup f u = a)
(h : f.is_bounded_under (β€) u . is_bounded_default)
(h' : f.is_bounded_under (β₯) u . is_bounded_default) :
tendsto u f (π a) :=
le_nhds_of_Limsup_eq_Liminf h h' hsup hinf
/-- If a number `a` is less than or equal to the `liminf` of a function `f` at some filter
and is greater than or equal to the `limsup` of `f`, then `f` tends to `a` along this filter. -/
theorem tendsto_of_le_liminf_of_limsup_le {f : filter Ξ²} {u : Ξ² β Ξ±} {a : Ξ±}
(hinf : a β€ liminf f u) (hsup : limsup f u β€ a)
(h : f.is_bounded_under (β€) u . is_bounded_default)
(h' : f.is_bounded_under (β₯) u . is_bounded_default) :
tendsto u f (π a) :=
if hf : f = β₯ then hf.symm βΈ tendsto_bot
else by haveI : ne_bot f := β¨hfβ©; exact tendsto_of_liminf_eq_limsup
(le_antisymm (le_trans (liminf_le_limsup h h') hsup) hinf)
(le_antisymm hsup (le_trans hinf (liminf_le_limsup h h'))) h h'
/-- Assume that, for any `a < b`, a sequence can not be infinitely many times below `a` and
above `b`. If it is also ultimately bounded above and below, then it has to converge. This even
works if `a` and `b` are restricted to a dense subset.
-/
lemma tendsto_of_no_upcrossings [densely_ordered Ξ±]
{f : filter Ξ²} {u : Ξ² β Ξ±} {s : set Ξ±} (hs : dense s)
(H : β (a β s) (b β s), a < b β Β¬((βαΆ n in f, u n < a) β§ (βαΆ n in f, b < u n)))
(h : f.is_bounded_under (β€) u . is_bounded_default)
(h' : f.is_bounded_under (β₯) u . is_bounded_default) :
β (c : Ξ±), tendsto u f (π c) :=
begin
by_cases hbot : f = β₯, { rw hbot, exact β¨Inf β
, tendsto_botβ© },
haveI : ne_bot f := β¨hbotβ©,
refine β¨limsup f u, _β©,
apply tendsto_of_le_liminf_of_limsup_le _ le_rfl h h',
by_contra' hlt,
obtain β¨a, β¨β¨la, auβ©, asβ©β© : β a, (f.liminf u < a β§ a < f.limsup u) β§ a β s :=
dense_iff_inter_open.1 hs (set.Ioo (f.liminf u) (f.limsup u)) is_open_Ioo
(set.nonempty_Ioo.2 hlt),
obtain β¨b, β¨β¨ab, buβ©, bsβ©β© : β b, (a < b β§ b < f.limsup u) β§ b β s :=
dense_iff_inter_open.1 hs (set.Ioo a (f.limsup u)) is_open_Ioo
(set.nonempty_Ioo.2 au),
have A : βαΆ n in f, u n < a :=
frequently_lt_of_liminf_lt (is_bounded.is_cobounded_ge h) la,
have B : βαΆ n in f, b < u n :=
frequently_lt_of_lt_limsup (is_bounded.is_cobounded_le h') bu,
exact H a as b bs ab β¨A, Bβ©,
end
end conditionally_complete_linear_order
end liminf_limsup
|
fda814a1ac6edcc6a94dccdadc0f1056d5d31bd9 | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /stage0/src/Lean/Parser/Attr.lean | 2901522d49ffe059c4288ea9639a8e8a66b0ab1b | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | EdAyers/lean4 | 57ac632d6b0789cb91fab2170e8c9e40441221bd | 37ba0df5841bde51dbc2329da81ac23d4f6a4de4 | refs/heads/master | 1,676,463,245,298 | 1,660,619,433,000 | 1,660,619,433,000 | 183,433,437 | 1 | 0 | Apache-2.0 | 1,657,612,672,000 | 1,556,196,574,000 | Lean | UTF-8 | Lean | false | false | 2,028 | lean | /-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Parser.Basic
import Lean.Parser.Extra
namespace Lean.Parser
builtin_initialize
registerBuiltinParserAttribute `builtinPrioParser ``Category.prio .both
registerBuiltinDynamicParserAttribute `prioParser `prio
builtin_initialize
registerBuiltinParserAttribute `builtinAttrParser ``Category.attr .symbol
registerBuiltinDynamicParserAttribute `attrParser `attr
@[inline] def priorityParser (rbp : Nat := 0) : Parser :=
categoryParser `prio rbp
@[inline] def attrParser (rbp : Nat := 0) : Parser :=
categoryParser `attr rbp
attribute [runBuiltinParserAttributeHooks]
priorityParser attrParser
namespace Priority
@[builtinPrioParser] def numPrio := checkPrec maxPrec >> numLit
attribute [runBuiltinParserAttributeHooks] numPrio
end Priority
namespace Attr
@[builtinAttrParser] def simple := leading_parser ident >> optional (priorityParser <|> ident)
/- Remark, We can't use `simple` for `class`, `instance`, `export`, and `macro` because they are keywords. -/
@[builtinAttrParser] def Β«macroΒ» := leading_parser "macro " >> ident
@[builtinAttrParser] def Β«exportΒ» := leading_parser "export " >> ident
/- We don't use `simple` for recursor because the argument is not a priority -/
@[builtinAttrParser] def recursor := leading_parser nonReservedSymbol "recursor " >> numLit
@[builtinAttrParser] def Β«classΒ» := leading_parser "class"
@[builtinAttrParser] def Β«instanceΒ» := leading_parser "instance" >> optional priorityParser
@[builtinAttrParser] def defaultInstance := leading_parser nonReservedSymbol "defaultInstance " >> optional priorityParser
def externEntry := leading_parser optional ident >> optional (nonReservedSymbol "inline ") >> strLit
@[builtinAttrParser] def extern := leading_parser nonReservedSymbol "extern " >> optional numLit >> many externEntry
end Attr
end Lean.Parser
|
92164f1883d43ce47f32e2ebdad617fa6aac77f1 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/data/polynomial/eval.lean | 21ccdc0c6cbe9fccd4edd84f3ff9ab9dd84c8f07 | [
"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 | 32,033 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes HΓΆlzl, Scott Morrison, Jens Wagemaker
-/
import data.polynomial.degree.definitions
import algebra.geom_sum
/-!
# Theory of univariate polynomials
The main defs here are `evalβ`, `eval`, and `map`.
We give several lemmas about their interaction with each other and with module operations.
-/
noncomputable theory
open finset add_monoid_algebra
open_locale big_operators polynomial
namespace polynomial
universes u v w y
variables {R : Type u} {S : Type v} {T : Type w} {ΞΉ : Type y} {a b : R} {m n : β}
section semiring
variables [semiring R] {p q r : R[X]}
section
variables [semiring S]
variables (f : R β+* S) (x : S)
/-- Evaluate a polynomial `p` given a ring hom `f` from the scalar ring
to the target and a value `x` for the variable in the target -/
def evalβ (p : R[X]) : S :=
p.sum (Ξ» e a, f a * x ^ e)
lemma evalβ_eq_sum {f : R β+* S} {x : S} : p.evalβ f x = p.sum (Ξ» e a, f a * x ^ e) := rfl
lemma evalβ_congr {R S : Type*} [semiring R] [semiring S]
{f g : R β+* S} {s t : S} {Ο Ο : R[X]} :
f = g β s = t β Ο = Ο β evalβ f s Ο = evalβ g t Ο :=
by rintro rfl rfl rfl; refl
@[simp] lemma evalβ_at_zero : p.evalβ f 0 = f (coeff p 0) :=
by simp only [evalβ_eq_sum, zero_pow_eq, mul_ite, mul_zero, mul_one, sum, not_not, mem_support_iff,
sum_ite_eq', ite_eq_left_iff, ring_hom.map_zero, implies_true_iff, eq_self_iff_true]
{contextual := tt}
@[simp] lemma evalβ_zero : (0 : R[X]).evalβ f x = 0 :=
by simp [evalβ_eq_sum]
@[simp] lemma evalβ_C : (C a).evalβ f x = f a :=
by simp [evalβ_eq_sum]
@[simp] lemma evalβ_X : X.evalβ f x = x :=
by simp [evalβ_eq_sum]
@[simp] lemma evalβ_monomial {n : β} {r : R} : (monomial n r).evalβ f x = (f r) * x^n :=
by simp [evalβ_eq_sum]
@[simp] lemma evalβ_X_pow {n : β} : (X^n).evalβ f x = x^n :=
begin
rw X_pow_eq_monomial,
convert evalβ_monomial f x,
simp,
end
@[simp] lemma evalβ_add : (p + q).evalβ f x = p.evalβ f x + q.evalβ f x :=
by { apply sum_add_index; simp [add_mul] }
@[simp] lemma evalβ_one : (1 : R[X]).evalβ f x = 1 :=
by rw [β C_1, evalβ_C, f.map_one]
@[simp] lemma evalβ_bit0 : (bit0 p).evalβ f x = bit0 (p.evalβ f x) :=
by rw [bit0, evalβ_add, bit0]
@[simp] lemma evalβ_bit1 : (bit1 p).evalβ f x = bit1 (p.evalβ f x) :=
by rw [bit1, evalβ_add, evalβ_bit0, evalβ_one, bit1]
@[simp] lemma evalβ_smul (g : R β+* S) (p : R[X]) (x : S) {s : R} :
evalβ g x (s β’ p) = g s * evalβ g x p :=
begin
have A : p.nat_degree < p.nat_degree.succ := nat.lt_succ_self _,
have B : (s β’ p).nat_degree < p.nat_degree.succ := (nat_degree_smul_le _ _).trans_lt A,
rw [evalβ_eq_sum, evalβ_eq_sum, sum_over_range' _ _ _ A, sum_over_range' _ _ _ B];
simp [mul_sum, mul_assoc],
end
@[simp] lemma evalβ_C_X : evalβ C X p = p :=
polynomial.induction_on' p (Ξ» p q hp hq, by simp [hp, hq])
(Ξ» n x, by rw [evalβ_monomial, monomial_eq_smul_X, C_mul'])
/-- `evalβ_add_monoid_hom (f : R β+* S) (x : S)` is the `add_monoid_hom` from
`polynomial R` to `S` obtained by evaluating the pushforward of `p` along `f` at `x`. -/
@[simps] def evalβ_add_monoid_hom : R[X] β+ S :=
{ to_fun := evalβ f x,
map_zero' := evalβ_zero _ _,
map_add' := Ξ» _ _, evalβ_add _ _ }
@[simp] lemma evalβ_nat_cast (n : β) : (n : R[X]).evalβ f x = n :=
begin
induction n with n ih,
{ simp only [evalβ_zero, nat.cast_zero] },
{ rw [n.cast_succ, evalβ_add, ih, evalβ_one, n.cast_succ] }
end
variables [semiring T]
lemma evalβ_sum (p : T[X]) (g : β β T β R[X]) (x : S) :
(p.sum g).evalβ f x = p.sum (Ξ» n a, (g n a).evalβ f x) :=
begin
let T : R[X] β+ S :=
{ to_fun := evalβ f x, map_zero' := evalβ_zero _ _, map_add' := Ξ» p q, evalβ_add _ _ },
have A : β y, evalβ f x y = T y := Ξ» y, rfl,
simp only [A],
rw [sum, T.map_sum, sum]
end
lemma evalβ_list_sum (l : list R[X]) (x : S) :
evalβ f x l.sum = (l.map (evalβ f x)).sum :=
map_list_sum (evalβ_add_monoid_hom f x) l
lemma evalβ_multiset_sum (s : multiset R[X]) (x : S) :
evalβ f x s.sum = (s.map (evalβ f x)).sum :=
map_multiset_sum (evalβ_add_monoid_hom f x) s
lemma evalβ_finset_sum (s : finset ΞΉ) (g : ΞΉ β R[X]) (x : S) :
(β i in s, g i).evalβ f x = β i in s, (g i).evalβ f x :=
map_sum (evalβ_add_monoid_hom f x) _ _
lemma evalβ_of_finsupp {f : R β+* S} {x : S} {p : add_monoid_algebra R β} :
evalβ f x (β¨pβ© : R[X]) = lift_nc βf (powers_hom S x) p :=
by { simp only [evalβ_eq_sum, sum, to_finsupp_sum, support, coeff], refl }
lemma evalβ_mul_noncomm (hf : β k, commute (f $ q.coeff k) x) :
evalβ f x (p * q) = evalβ f x p * evalβ f x q :=
begin
rcases p, rcases q,
simp only [coeff] at hf,
simp only [βof_finsupp_mul, evalβ_of_finsupp],
exact lift_nc_mul _ _ p q (Ξ» k n hn, (hf k).pow_right n)
end
@[simp] lemma evalβ_mul_X : evalβ f x (p * X) = evalβ f x p * x :=
begin
refine trans (evalβ_mul_noncomm _ _ $ Ξ» k, _) (by rw evalβ_X),
rcases em (k = 1) with (rfl|hk),
{ simp },
{ simp [coeff_X_of_ne_one hk] }
end
@[simp] lemma evalβ_X_mul : evalβ f x (X * p) = evalβ f x p * x :=
by rw [X_mul, evalβ_mul_X]
lemma evalβ_mul_C' (h : commute (f a) x) : evalβ f x (p * C a) = evalβ f x p * f a :=
begin
rw [evalβ_mul_noncomm, evalβ_C],
intro k,
by_cases hk : k = 0,
{ simp only [hk, h, coeff_C_zero, coeff_C_ne_zero] },
{ simp only [coeff_C_ne_zero hk, ring_hom.map_zero, commute.zero_left] }
end
lemma evalβ_list_prod_noncomm (ps : list R[X])
(hf : β (p β ps) k, commute (f $ coeff p k) x) :
evalβ f x ps.prod = (ps.map (polynomial.evalβ f x)).prod :=
begin
induction ps using list.reverse_rec_on with ps p ihp,
{ simp },
{ simp only [list.forall_mem_append, list.forall_mem_singleton] at hf,
simp [evalβ_mul_noncomm _ _ hf.2, ihp hf.1] }
end
/-- `evalβ` as a `ring_hom` for noncommutative rings -/
def evalβ_ring_hom' (f : R β+* S) (x : S) (hf : β a, commute (f a) x) : R[X] β+* S :=
{ to_fun := evalβ f x,
map_add' := Ξ» _ _, evalβ_add _ _,
map_zero' := evalβ_zero _ _,
map_mul' := Ξ» p q, evalβ_mul_noncomm f x (Ξ» k, hf $ coeff q k),
map_one' := evalβ_one _ _ }
end
/-!
We next prove that evalβ is multiplicative
as long as target ring is commutative
(even if the source ring is not).
-/
section evalβ
section
variables [semiring S] (f : R β+* S) (x : S)
lemma evalβ_eq_sum_range :
p.evalβ f x = β i in finset.range (p.nat_degree + 1), f (p.coeff i) * x^i :=
trans (congr_arg _ p.as_sum_range) (trans (evalβ_finset_sum f _ _ x) (congr_arg _ (by simp)))
lemma evalβ_eq_sum_range' (f : R β+* S) {p : R[X]} {n : β} (hn : p.nat_degree < n) (x : S) :
evalβ f x p = β i in finset.range n, f (p.coeff i) * x ^ i :=
begin
rw [evalβ_eq_sum, p.sum_over_range' _ _ hn],
intro i,
rw [f.map_zero, zero_mul]
end
end
section
variables [comm_semiring S] (f : R β+* S) (x : S)
@[simp] lemma evalβ_mul : (p * q).evalβ f x = p.evalβ f x * q.evalβ f x :=
evalβ_mul_noncomm _ _ $ Ξ» k, commute.all _ _
lemma evalβ_mul_eq_zero_of_left (q : R[X]) (hp : p.evalβ f x = 0) :
(p * q).evalβ f x = 0 :=
begin
rw evalβ_mul f x,
exact mul_eq_zero_of_left hp (q.evalβ f x)
end
lemma evalβ_mul_eq_zero_of_right (p : R[X]) (hq : q.evalβ f x = 0) :
(p * q).evalβ f x = 0 :=
begin
rw evalβ_mul f x,
exact mul_eq_zero_of_right (p.evalβ f x) hq
end
/-- `evalβ` as a `ring_hom` -/
def evalβ_ring_hom (f : R β+* S) (x : S) : R[X] β+* S :=
{ map_one' := evalβ_one _ _,
map_mul' := Ξ» _ _, evalβ_mul _ _,
..evalβ_add_monoid_hom f x }
@[simp] lemma coe_evalβ_ring_hom (f : R β+* S) (x) : β(evalβ_ring_hom f x) = evalβ f x := rfl
lemma evalβ_pow (n : β) : (p ^ n).evalβ f x = p.evalβ f x ^ n := (evalβ_ring_hom _ _).map_pow _ _
lemma evalβ_dvd : p β£ q β evalβ f x p β£ evalβ f x q :=
(evalβ_ring_hom f x).map_dvd
lemma evalβ_eq_zero_of_dvd_of_evalβ_eq_zero (h : p β£ q) (h0 : evalβ f x p = 0) :
evalβ f x q = 0 :=
zero_dvd_iff.mp (h0 βΈ evalβ_dvd f x h)
lemma evalβ_list_prod (l : list R[X]) (x : S) :
evalβ f x l.prod = (l.map (evalβ f x)).prod :=
map_list_prod (evalβ_ring_hom f x) l
end
end evalβ
section eval
variables {x : R}
/-- `eval x p` is the evaluation of the polynomial `p` at `x` -/
def eval : R β R[X] β R := evalβ (ring_hom.id _)
lemma eval_eq_sum : p.eval x = p.sum (Ξ» e a, a * x ^ e) :=
rfl
lemma eval_eq_sum_range {p : R[X]} (x : R) :
p.eval x = β i in finset.range (p.nat_degree + 1), p.coeff i * x ^ i :=
by rw [eval_eq_sum, sum_over_range]; simp
lemma eval_eq_sum_range' {p : R[X]} {n : β} (hn : p.nat_degree < n) (x : R) :
p.eval x = β i in finset.range n, p.coeff i * x ^ i :=
by rw [eval_eq_sum, p.sum_over_range' _ _ hn]; simp
@[simp] lemma evalβ_at_apply {S : Type*} [semiring S] (f : R β+* S) (r : R) :
p.evalβ f (f r) = f (p.eval r) :=
begin
rw [evalβ_eq_sum, eval_eq_sum, sum, sum, f.map_sum],
simp only [f.map_mul, f.map_pow],
end
@[simp] lemma evalβ_at_one {S : Type*} [semiring S] (f : R β+* S) : p.evalβ f 1 = f (p.eval 1) :=
begin
convert evalβ_at_apply f 1,
simp,
end
@[simp] lemma evalβ_at_nat_cast {S : Type*} [semiring S] (f : R β+* S) (n : β) :
p.evalβ f n = f (p.eval n) :=
begin
convert evalβ_at_apply f n,
simp,
end
@[simp] lemma eval_C : (C a).eval x = a := evalβ_C _ _
@[simp] lemma eval_nat_cast {n : β} : (n : R[X]).eval x = n :=
by simp only [βC_eq_nat_cast, eval_C]
@[simp] lemma eval_X : X.eval x = x := evalβ_X _ _
@[simp] lemma eval_monomial {n a} : (monomial n a).eval x = a * x^n :=
evalβ_monomial _ _
@[simp] lemma eval_zero : (0 : R[X]).eval x = 0 := evalβ_zero _ _
@[simp] lemma eval_add : (p + q).eval x = p.eval x + q.eval x := evalβ_add _ _
@[simp] lemma eval_one : (1 : R[X]).eval x = 1 := evalβ_one _ _
@[simp] lemma eval_bit0 : (bit0 p).eval x = bit0 (p.eval x) := evalβ_bit0 _ _
@[simp] lemma eval_bit1 : (bit1 p).eval x = bit1 (p.eval x) := evalβ_bit1 _ _
@[simp] lemma eval_smul [monoid S] [distrib_mul_action S R] [is_scalar_tower S R R]
(s : S) (p : R[X]) (x : R) :
(s β’ p).eval x = s β’ p.eval x :=
by rw [β smul_one_smul R s p, eval, evalβ_smul, ring_hom.id_apply, smul_one_mul]
@[simp] lemma eval_C_mul : (C a * p).eval x = a * p.eval x :=
begin
apply polynomial.induction_on' p,
{ intros p q ph qh,
simp only [mul_add, eval_add, ph, qh], },
{ intros n b,
simp only [mul_assoc, C_mul_monomial, eval_monomial], }
end
/-- `polynomial.eval` as linear map -/
@[simps] def leval {R : Type*} [semiring R] (r : R) : R[X] ββ[R] R :=
{ to_fun := Ξ» f, f.eval r,
map_add' := Ξ» f g, eval_add,
map_smul' := Ξ» c f, eval_smul c f r }
@[simp] lemma eval_nat_cast_mul {n : β} : ((n : R[X]) * p).eval x = n * p.eval x :=
by rw [βC_eq_nat_cast, eval_C_mul]
@[simp] lemma eval_mul_X : (p * X).eval x = p.eval x * x :=
begin
apply polynomial.induction_on' p,
{ intros p q ph qh,
simp only [add_mul, eval_add, ph, qh], },
{ intros n a,
simp only [βmonomial_one_one_eq_X, monomial_mul_monomial, eval_monomial,
mul_one, pow_succ', mul_assoc], }
end
@[simp] lemma eval_mul_X_pow {k : β} : (p * X^k).eval x = p.eval x * x^k :=
begin
induction k with k ih,
{ simp, },
{ simp [pow_succ', βmul_assoc, ih], }
end
lemma eval_sum (p : R[X]) (f : β β R β R[X]) (x : R) :
(p.sum f).eval x = p.sum (Ξ» n a, (f n a).eval x) :=
evalβ_sum _ _ _ _
lemma eval_finset_sum (s : finset ΞΉ) (g : ΞΉ β R[X]) (x : R) :
(β i in s, g i).eval x = β i in s, (g i).eval x := evalβ_finset_sum _ _ _ _
/-- `is_root p x` implies `x` is a root of `p`. The evaluation of `p` at `x` is zero -/
def is_root (p : R[X]) (a : R) : Prop := p.eval a = 0
instance [decidable_eq R] : decidable (is_root p a) := by unfold is_root; apply_instance
@[simp] lemma is_root.def : is_root p a β p.eval a = 0 := iff.rfl
lemma is_root.eq_zero (h : is_root p x) : eval x p = 0 := h
lemma coeff_zero_eq_eval_zero (p : R[X]) :
coeff p 0 = p.eval 0 :=
calc coeff p 0 = coeff p 0 * 0 ^ 0 : by simp
... = p.eval 0 : eq.symm $
finset.sum_eq_single _ (Ξ» b _ hb, by simp [zero_pow (nat.pos_of_ne_zero hb)]) (by simp)
lemma zero_is_root_of_coeff_zero_eq_zero {p : R[X]} (hp : p.coeff 0 = 0) :
is_root p 0 :=
by rwa coeff_zero_eq_eval_zero at hp
lemma is_root.dvd {R : Type*} [comm_semiring R] {p q : R[X]} {x : R}
(h : p.is_root x) (hpq : p β£ q) : q.is_root x :=
by rwa [is_root, eval, evalβ_eq_zero_of_dvd_of_evalβ_eq_zero _ _ hpq]
lemma not_is_root_C (r a : R) (hr : r β 0) : Β¬ is_root (C r) a :=
by simpa using hr
end eval
section comp
/-- The composition of polynomials as a polynomial. -/
def comp (p q : R[X]) : R[X] := p.evalβ C q
lemma comp_eq_sum_left : p.comp q = p.sum (Ξ» e a, C a * q ^ e) :=
rfl
@[simp] lemma comp_X : p.comp X = p :=
begin
simp only [comp, evalβ, β monomial_eq_C_mul_X],
exact sum_monomial_eq _,
end
@[simp] lemma X_comp : X.comp p = p := evalβ_X _ _
@[simp] lemma comp_C : p.comp (C a) = C (p.eval a) :=
by simp [comp, (C : R β+* _).map_sum]
@[simp] lemma C_comp : (C a).comp p = C a := evalβ_C _ _
@[simp] lemma nat_cast_comp {n : β} : (n : R[X]).comp p = n :=
by rw [βC_eq_nat_cast, C_comp]
@[simp] lemma comp_zero : p.comp (0 : R[X]) = C (p.eval 0) :=
by rw [β C_0, comp_C]
@[simp] lemma zero_comp : comp (0 : R[X]) p = 0 :=
by rw [β C_0, C_comp]
@[simp] lemma comp_one : p.comp 1 = C (p.eval 1) :=
by rw [β C_1, comp_C]
@[simp] lemma one_comp : comp (1 : R[X]) p = 1 :=
by rw [β C_1, C_comp]
@[simp] lemma add_comp : (p + q).comp r = p.comp r + q.comp r := evalβ_add _ _
@[simp] lemma monomial_comp (n : β) : (monomial n a).comp p = C a * p^n :=
evalβ_monomial _ _
@[simp] lemma mul_X_comp : (p * X).comp r = p.comp r * r :=
begin
apply polynomial.induction_on' p,
{ intros p q hp hq, simp only [hp, hq, add_mul, add_comp] },
{ intros n b, simp only [pow_succ', mul_assoc, monomial_mul_X, monomial_comp] }
end
@[simp] lemma X_pow_comp {k : β} : (X^k).comp p = p^k :=
begin
induction k with k ih,
{ simp, },
{ simp [pow_succ', mul_X_comp, ih], },
end
@[simp] lemma mul_X_pow_comp {k : β} : (p * X^k).comp r = p.comp r * r^k :=
begin
induction k with k ih,
{ simp, },
{ simp [ih, pow_succ', βmul_assoc, mul_X_comp], },
end
@[simp] lemma C_mul_comp : (C a * p).comp r = C a * p.comp r :=
begin
apply polynomial.induction_on' p,
{ intros p q hp hq, simp [hp, hq, mul_add], },
{ intros n b, simp [mul_assoc], }
end
@[simp] lemma nat_cast_mul_comp {n : β} : ((n : R[X]) * p).comp r = n * p.comp r :=
by rw [βC_eq_nat_cast, C_mul_comp, C_eq_nat_cast]
@[simp] lemma mul_comp {R : Type*} [comm_semiring R] (p q r : R[X]) :
(p * q).comp r = p.comp r * q.comp r := evalβ_mul _ _
lemma prod_comp {R : Type*} [comm_semiring R] (s : multiset R[X]) (p : R[X]) :
s.prod.comp p = (s.map (Ξ» q : R[X], q.comp p)).prod :=
(s.prod_hom (monoid_hom.mk (Ξ» q : R[X], q.comp p) one_comp (Ξ» q r, mul_comp q r p))).symm
@[simp] lemma pow_comp {R : Type*} [comm_semiring R] (p q : R[X]) (n : β) :
(p^n).comp q = (p.comp q)^n :=
((monoid_hom.mk (Ξ» r : R[X], r.comp q)) one_comp (Ξ» r s, mul_comp r s q)).map_pow p n
@[simp] lemma bit0_comp : comp (bit0 p : R[X]) q = bit0 (p.comp q) :=
by simp only [bit0, add_comp]
@[simp] lemma bit1_comp : comp (bit1 p : R[X]) q = bit1 (p.comp q) :=
by simp only [bit1, add_comp, bit0_comp, one_comp]
@[simp] lemma smul_comp [monoid S] [distrib_mul_action S R] [is_scalar_tower S R R]
(s : S) (p q : R[X]) : (s β’ p).comp q = s β’ p.comp q :=
by rw [β smul_one_smul R s p, comp, comp, evalβ_smul, β smul_eq_C_mul, smul_assoc, one_smul]
lemma comp_assoc {R : Type*} [comm_semiring R] (Ο Ο Ο : R[X]) :
(Ο.comp Ο).comp Ο = Ο.comp (Ο.comp Ο) :=
begin
apply polynomial.induction_on Ο;
{ intros, simp only [add_comp, mul_comp, C_comp, X_comp, pow_succ', β mul_assoc, *] at * }
end
lemma coeff_comp_degree_mul_degree (hqd0 : nat_degree q β 0) :
coeff (p.comp q) (nat_degree p * nat_degree q) =
leading_coeff p * leading_coeff q ^ nat_degree p :=
begin
rw [comp, evalβ, coeff_sum],
convert finset.sum_eq_single p.nat_degree _ _,
{ simp only [coeff_nat_degree, coeff_C_mul, coeff_pow_mul_nat_degree] },
{ assume b hbs hbp,
refine coeff_eq_zero_of_nat_degree_lt ((nat_degree_mul_le).trans_lt _),
rw [nat_degree_C, zero_add],
refine (nat_degree_pow_le).trans_lt ((mul_lt_mul_right (pos_iff_ne_zero.mpr hqd0)).mpr _),
exact lt_of_le_of_ne (le_nat_degree_of_mem_supp _ hbs) hbp },
{ simp {contextual := tt} }
end
end comp
section map
variables [semiring S]
variables (f : R β+* S)
/-- `map f p` maps a polynomial `p` across a ring hom `f` -/
def map : R[X] β S[X] := evalβ (C.comp f) X
@[simp] lemma map_C : (C a).map f = C (f a) := evalβ_C _ _
@[simp] lemma map_X : X.map f = X := evalβ_X _ _
@[simp] lemma map_monomial {n a} : (monomial n a).map f = monomial n (f a) :=
begin
dsimp only [map],
rw [evalβ_monomial, monomial_eq_C_mul_X], refl,
end
@[simp] protected lemma map_zero : (0 : R[X]).map f = 0 := evalβ_zero _ _
@[simp] protected lemma map_add : (p + q).map f = p.map f + q.map f := evalβ_add _ _
@[simp] protected lemma map_one : (1 : R[X]).map f = 1 := evalβ_one _ _
@[simp] protected lemma map_mul : (p * q).map f = p.map f * q.map f :=
by { rw [map, evalβ_mul_noncomm], exact Ξ» k, (commute_X _).symm }
@[simp] lemma map_smul (r : R) : (r β’ p).map f = f r β’ p.map f :=
by rw [map, evalβ_smul, ring_hom.comp_apply, C_mul']
/-- `polynomial.map` as a `ring_hom`. -/
-- `map` is a ring-hom unconditionally, and theoretically the definition could be replaced,
-- but this turns out not to be easy because `p.map f` does not resolve to `polynomial.map`
-- if `map` is a `ring_hom` instead of a plain function; the elaborator does not try to coerce
-- to a function before trying field (dot) notation (this may be technically infeasible);
-- the relevant code is (both lines): https://github.com/leanprover-community/
-- lean/blob/487ac5d7e9b34800502e1ddf3c7c806c01cf9d51/src/frontends/lean/elaborator.cpp#L1876-L1913
def map_ring_hom (f : R β+* S) : R[X] β+* S[X] :=
{ to_fun := polynomial.map f,
map_add' := Ξ» _ _, polynomial.map_add f,
map_zero' := polynomial.map_zero f,
map_mul' := Ξ» _ _, polynomial.map_mul f,
map_one' := polynomial.map_one f }
@[simp] lemma coe_map_ring_hom (f : R β+* S) : β(map_ring_hom f) = map f := rfl
-- This is protected to not clash with the global `map_nat_cast`.
@[simp] protected theorem map_nat_cast (n : β) : (n : R[X]).map f = n :=
map_nat_cast (map_ring_hom f) n
@[simp]
lemma coeff_map (n : β) : coeff (p.map f) n = f (coeff p n) :=
begin
rw [map, evalβ, coeff_sum, sum],
conv_rhs { rw [β sum_C_mul_X_eq p, coeff_sum, sum, ring_hom.map_sum], },
refine finset.sum_congr rfl (Ξ» x hx, _),
simp [function.comp, coeff_C_mul_X_pow, f.map_mul],
split_ifs; simp [f.map_zero],
end
/-- If `R` and `S` are isomorphic, then so are their polynomial rings. -/
@[simps] def map_equiv (e : R β+* S) : R[X] β+* S[X] :=
ring_equiv.of_hom_inv
(map_ring_hom (e : R β+* S))
(map_ring_hom (e.symm : S β+* R))
(by ext; simp)
(by ext; simp)
lemma map_map [semiring T] (g : S β+* T)
(p : R[X]) : (p.map f).map g = p.map (g.comp f) :=
ext (by simp [coeff_map])
@[simp] lemma map_id : p.map (ring_hom.id _) = p := by simp [polynomial.ext_iff, coeff_map]
lemma evalβ_eq_eval_map {x : S} : p.evalβ f x = (p.map f).eval x :=
begin
apply polynomial.induction_on' p,
{ intros p q hp hq, simp [hp, hq], },
{ intros n r, simp, }
end
lemma map_injective (hf : function.injective f) : function.injective (map f) :=
Ξ» p q h, ext $ Ξ» m, hf $ by rw [β coeff_map f, β coeff_map f, h]
lemma map_surjective (hf : function.surjective f) : function.surjective (map f) :=
Ξ» p, polynomial.induction_on' p
(Ξ» p q hp hq, let β¨p', hp'β© := hp, β¨q', hq'β© := hq
in β¨p' + q', by rw [polynomial.map_add f, hp', hq']β©)
(Ξ» n s, let β¨r, hrβ© := hf s in β¨monomial n r, by rw [map_monomial f, hr]β©)
lemma degree_map_le (p : R[X]) : degree (p.map f) β€ degree p :=
begin
apply (degree_le_iff_coeff_zero _ _).2 (Ξ» m hm, _),
rw degree_lt_iff_coeff_zero at hm,
simp [hm m le_rfl],
end
lemma nat_degree_map_le (p : R[X]) : nat_degree (p.map f) β€ nat_degree p :=
nat_degree_le_nat_degree (degree_map_le f p)
variables {f}
lemma map_monic_eq_zero_iff (hp : p.monic) : p.map f = 0 β β x, f x = 0 :=
β¨ Ξ» hfp x, calc f x = f x * f p.leading_coeff : by simp only [mul_one, hp.leading_coeff, f.map_one]
... = f x * (p.map f).coeff p.nat_degree : congr_arg _ (coeff_map _ _).symm
... = 0 : by simp only [hfp, mul_zero, coeff_zero],
Ξ» h, ext (Ξ» n, by simp only [h, coeff_map, coeff_zero]) β©
lemma map_monic_ne_zero (hp : p.monic) [nontrivial S] : p.map f β 0 :=
Ξ» h, f.map_one_ne_zero ((map_monic_eq_zero_iff hp).mp h _)
lemma degree_map_eq_of_leading_coeff_ne_zero (f : R β+* S)
(hf : f (leading_coeff p) β 0) : degree (p.map f) = degree p :=
le_antisymm (degree_map_le f _) $
have hp0 : p β 0, from leading_coeff_ne_zero.mp (Ξ» hp0, hf (trans (congr_arg _ hp0) f.map_zero)),
begin
rw [degree_eq_nat_degree hp0],
refine le_degree_of_ne_zero _,
rw [coeff_map], exact hf
end
lemma nat_degree_map_of_leading_coeff_ne_zero (f : R β+* S)
(hf : f (leading_coeff p) β 0) : nat_degree (p.map f) = nat_degree p :=
nat_degree_eq_of_degree_eq (degree_map_eq_of_leading_coeff_ne_zero f hf)
lemma leading_coeff_map_of_leading_coeff_ne_zero (f : R β+* S)
(hf : f (leading_coeff p) β 0) : leading_coeff (p.map f) = f (leading_coeff p) :=
begin
unfold leading_coeff,
rw [coeff_map, nat_degree_map_of_leading_coeff_ne_zero f hf],
end
variables (f)
@[simp] lemma map_ring_hom_id : map_ring_hom (ring_hom.id R) = ring_hom.id R[X] :=
ring_hom.ext $ Ξ» x, map_id
@[simp] lemma map_ring_hom_comp [semiring T] (f : S β+* T) (g : R β+* S) :
(map_ring_hom f).comp (map_ring_hom g) = map_ring_hom (f.comp g) :=
ring_hom.ext $ polynomial.map_map g f
protected lemma map_list_prod (L : list R[X]) : L.prod.map f = (L.map $ map f).prod :=
eq.symm $ list.prod_hom _ (map_ring_hom f).to_monoid_hom
@[simp] protected lemma map_pow (n : β) : (p ^ n).map f = p.map f ^ n :=
(map_ring_hom f).map_pow _ _
lemma mem_map_srange {p : S[X]} :
p β (map_ring_hom f).srange β β n, p.coeff n β f.srange :=
begin
split,
{ rintro β¨p, rflβ© n, rw [coe_map_ring_hom, coeff_map], exact set.mem_range_self _ },
{ intro h, rw p.as_sum_range_C_mul_X_pow,
refine (map_ring_hom f).srange.sum_mem _,
intros i hi,
rcases h i with β¨c, hcβ©,
use [C c * X^i],
rw [coe_map_ring_hom, polynomial.map_mul, map_C, hc, polynomial.map_pow, map_X] }
end
lemma mem_map_range {R S : Type*} [ring R] [ring S] (f : R β+* S)
{p : S[X]} : p β (map_ring_hom f).range β β n, p.coeff n β f.range :=
mem_map_srange f
lemma evalβ_map [semiring T] (g : S β+* T) (x : T) :
(p.map f).evalβ g x = p.evalβ (g.comp f) x :=
by rw [evalβ_eq_eval_map, evalβ_eq_eval_map, map_map]
lemma eval_map (x : S) : (p.map f).eval x = p.evalβ f x :=
(evalβ_eq_eval_map f).symm
protected lemma map_sum {ΞΉ : Type*} (g : ΞΉ β R[X]) (s : finset ΞΉ) :
(β i in s, g i).map f = β i in s, (g i).map f :=
(map_ring_hom f).map_sum _ _
lemma map_comp (p q : R[X]) : map f (p.comp q) = (map f p).comp (map f q) :=
polynomial.induction_on p
(by simp only [map_C, forall_const, C_comp, eq_self_iff_true])
(by simp only [polynomial.map_add, add_comp, forall_const, implies_true_iff, eq_self_iff_true]
{contextual := tt})
(by simp only [pow_succ', βmul_assoc, comp, forall_const, evalβ_mul_X, implies_true_iff,
eq_self_iff_true, map_X, polynomial.map_mul] {contextual := tt})
@[simp]
lemma eval_zero_map (f : R β+* S) (p : R[X]) :
(p.map f).eval 0 = f (p.eval 0) :=
by simp [βcoeff_zero_eq_eval_zero]
@[simp]
lemma eval_one_map (f : R β+* S) (p : R[X]) :
(p.map f).eval 1 = f (p.eval 1) :=
begin
apply polynomial.induction_on' p,
{ intros p q hp hq, simp only [hp, hq, polynomial.map_add, ring_hom.map_add, eval_add] },
{ intros n r, simp only [one_pow, mul_one, eval_monomial, map_monomial] }
end
@[simp]
lemma eval_nat_cast_map (f : R β+* S) (p : R[X]) (n : β) :
(p.map f).eval n = f (p.eval n) :=
begin
apply polynomial.induction_on' p,
{ intros p q hp hq, simp only [hp, hq, polynomial.map_add, ring_hom.map_add, eval_add] },
{ intros n r, simp only [map_nat_cast f, eval_monomial, map_monomial, f.map_pow, f.map_mul] }
end
@[simp]
lemma eval_int_cast_map {R S : Type*} [ring R] [ring S]
(f : R β+* S) (p : R[X]) (i : β€) :
(p.map f).eval i = f (p.eval i) :=
begin
apply polynomial.induction_on' p,
{ intros p q hp hq, simp only [hp, hq, polynomial.map_add, ring_hom.map_add, eval_add] },
{ intros n r, simp only [f.map_int_cast, eval_monomial, map_monomial, f.map_pow, f.map_mul] }
end
end map
/-!
After having set up the basic theory of `evalβ`, `eval`, `comp`, and `map`,
we make `evalβ` irreducible.
Perhaps we can make the others irreducible too?
-/
attribute [irreducible] polynomial.evalβ
section hom_evalβ
variables [semiring S] [semiring T] (f : R β+* S) (g : S β+* T) (p)
lemma hom_evalβ (x : S) : g (p.evalβ f x) = p.evalβ (g.comp f) (g x) :=
by rw [βevalβ_map, evalβ_at_apply, eval_map]
end hom_evalβ
end semiring
section comm_semiring
section eval
section
variables [semiring R] {p q : R[X]} {x : R} [semiring S] (f : R β+* S)
lemma evalβ_hom (x : R) :
p.evalβ f (f x) = f (p.eval x) :=
(ring_hom.comp_id f) βΈ (hom_evalβ p (ring_hom.id R) f x).symm
end
section
variables [semiring R] {p q : R[X]} {x : R} [comm_semiring S] (f : R β+* S)
lemma evalβ_comp {x : S} :
evalβ f x (p.comp q) = evalβ f (evalβ f x q) p :=
by rw [comp, p.as_sum_range]; simp [evalβ_finset_sum, evalβ_pow]
end
section
variables [comm_semiring R] {p q : R[X]} {x : R} [comm_semiring S] (f : R β+* S)
@[simp] lemma eval_mul : (p * q).eval x = p.eval x * q.eval x := evalβ_mul _ _
/-- `eval r`, regarded as a ring homomorphism from `polynomial R` to `R`. -/
def eval_ring_hom : R β R[X] β+* R := evalβ_ring_hom (ring_hom.id _)
@[simp] lemma coe_eval_ring_hom (r : R) : ((eval_ring_hom r) : R[X] β R) = eval r := rfl
@[simp] lemma eval_pow (n : β) : (p ^ n).eval x = p.eval x ^ n := evalβ_pow _ _ _
@[simp]
lemma eval_comp : (p.comp q).eval x = p.eval (q.eval x) :=
begin
apply polynomial.induction_on' p,
{ intros r s hr hs, simp [add_comp, hr, hs], },
{ intros n a, simp, }
end
/-- `comp p`, regarded as a ring homomorphism from `polynomial R` to itself. -/
def comp_ring_hom : R[X] β R[X] β+* R[X] :=
evalβ_ring_hom C
lemma root_mul_left_of_is_root (p : R[X]) {q : R[X]} :
is_root q a β is_root (p * q) a :=
Ξ» H, by rw [is_root, eval_mul, is_root.def.1 H, mul_zero]
lemma root_mul_right_of_is_root {p : R[X]} (q : R[X]) :
is_root p a β is_root (p * q) a :=
Ξ» H, by rw [is_root, eval_mul, is_root.def.1 H, zero_mul]
lemma evalβ_multiset_prod (s : multiset R[X]) (x : S) :
evalβ f x s.prod = (s.map (evalβ f x)).prod :=
map_multiset_prod (evalβ_ring_hom f x) s
lemma evalβ_finset_prod (s : finset ΞΉ) (g : ΞΉ β R[X]) (x : S) :
(β i in s, g i).evalβ f x = β i in s, (g i).evalβ f x :=
map_prod (evalβ_ring_hom f x) _ _
/--
Polynomial evaluation commutes with `list.prod`
-/
lemma eval_list_prod (l : list R[X]) (x : R) :
eval x l.prod = (l.map (eval x)).prod :=
(eval_ring_hom x).map_list_prod l
/--
Polynomial evaluation commutes with `multiset.prod`
-/
lemma eval_multiset_prod (s : multiset R[X]) (x : R) :
eval x s.prod = (s.map (eval x)).prod :=
(eval_ring_hom x).map_multiset_prod s
/--
Polynomial evaluation commutes with `finset.prod`
-/
lemma eval_prod {ΞΉ : Type*} (s : finset ΞΉ) (p : ΞΉ β R[X]) (x : R) :
eval x (β j in s, p j) = β j in s, eval x (p j) :=
(eval_ring_hom x).map_prod _ _
lemma is_root_prod {R} [comm_ring R] [is_domain R] {ΞΉ : Type*}
(s : finset ΞΉ) (p : ΞΉ β R[X]) (x : R) :
is_root (β j in s, p j) x β β i β s, is_root (p i) x :=
by simp only [is_root, eval_prod, finset.prod_eq_zero_iff]
lemma eval_dvd : p β£ q β eval x p β£ eval x q :=
evalβ_dvd _ _
lemma eval_eq_zero_of_dvd_of_eval_eq_zero : p β£ q β eval x p = 0 β eval x q = 0 :=
evalβ_eq_zero_of_dvd_of_evalβ_eq_zero _ _
@[simp]
lemma eval_geom_sum {R} [comm_semiring R] {n : β} {x : R} : eval x (geom_sum X n) = geom_sum x n :=
by simp [geom_sum_def, eval_finset_sum]
end
end eval
section map
--TODO rename to `map_dvd_map`
lemma map_dvd {R S} [semiring R] [comm_semiring S] (f : R β+* S) {x y : R[X]} :
x β£ y β x.map f β£ y.map f := evalβ_dvd _ _
lemma support_map_subset [semiring R] [comm_semiring S] (f : R β+* S) (p : R[X]) :
(map f p).support β p.support :=
begin
intros x,
contrapose!,
simp { contextual := tt },
end
variables [comm_semiring R] [comm_semiring S] (f : R β+* S)
protected lemma map_multiset_prod (m : multiset R[X]) : m.prod.map f = (m.map $ map f).prod :=
eq.symm $ multiset.prod_hom _ (map_ring_hom f).to_monoid_hom
protected lemma map_prod {ΞΉ : Type*} (g : ΞΉ β R[X]) (s : finset ΞΉ) :
(β i in s, g i).map f = β i in s, (g i).map f :=
(map_ring_hom f).map_prod _ _
lemma is_root.map {f : R β+* S} {x : R} {p : R[X]} (h : is_root p x) :
is_root (p.map f) (f x) :=
by rw [is_root, eval_map, evalβ_hom, h.eq_zero, f.map_zero]
lemma is_root.of_map {R} [comm_ring R] {f : R β+* S} {x : R} {p : R[X]}
(h : is_root (p.map f) (f x)) (hf : function.injective f) : is_root p x :=
by rwa [is_root, β(injective_iff_map_eq_zero' f).mp hf, βevalβ_hom, βeval_map]
lemma is_root_map_iff {R : Type*} [comm_ring R] {f : R β+* S} {x : R} {p : R[X]}
(hf : function.injective f) : is_root (p.map f) (f x) β is_root p x :=
β¨Ξ» h, h.of_map hf, Ξ» h, h.mapβ©
end map
end comm_semiring
section ring
variables [ring R] {p q r : R[X]}
lemma C_neg : C (-a) = -C a := ring_hom.map_neg C a
lemma C_sub : C (a - b) = C a - C b := ring_hom.map_sub C a b
@[simp] protected lemma map_sub {S} [ring S] (f : R β+* S) :
(p - q).map f = p.map f - q.map f :=
(map_ring_hom f).map_sub p q
@[simp] protected lemma map_neg {S} [ring S] (f : R β+* S) :
(-p).map f = -(p.map f) :=
(map_ring_hom f).map_neg p
@[simp] lemma map_int_cast {S} [ring S] (f : R β+* S) (n : β€) :
map f βn = βn :=
(map_ring_hom f).map_int_cast n
@[simp] lemma eval_int_cast {n : β€} {x : R} : (n : R[X]).eval x = n :=
by simp only [βC_eq_int_cast, eval_C]
@[simp] lemma evalβ_neg {S} [ring S] (f : R β+* S) {x : S} :
(-p).evalβ f x = -p.evalβ f x :=
by rw [eq_neg_iff_add_eq_zero, βevalβ_add, add_left_neg, evalβ_zero]
@[simp] lemma evalβ_sub {S} [ring S] (f : R β+* S) {x : S} :
(p - q).evalβ f x = p.evalβ f x - q.evalβ f x :=
by rw [sub_eq_add_neg, evalβ_add, evalβ_neg, sub_eq_add_neg]
@[simp] lemma eval_neg (p : R[X]) (x : R) : (-p).eval x = -p.eval x :=
evalβ_neg _
@[simp] lemma eval_sub (p q : R[X]) (x : R) : (p - q).eval x = p.eval x - q.eval x :=
evalβ_sub _
lemma root_X_sub_C : is_root (X - C a) b β a = b :=
by rw [is_root.def, eval_sub, eval_X, eval_C, sub_eq_zero, eq_comm]
@[simp] lemma neg_comp : (-p).comp q = -p.comp q := evalβ_neg _
@[simp] lemma sub_comp : (p - q).comp r = p.comp r - q.comp r := evalβ_sub _
@[simp] lemma cast_int_comp (i : β€) : comp (i : R[X]) p = i :=
by cases i; simp
end ring
end polynomial
|
26bee4fd3663ebff1086c7ef560b204c942d5fd2 | 30b012bb72d640ec30c8fdd4c45fdfa67beb012c | /data/set/function.lean | 7649b5fb2a918a85e12342f202ca04117d31f421 | [
"Apache-2.0"
] | permissive | kckennylau/mathlib | 21fb810b701b10d6606d9002a4004f7672262e83 | 47b3477e20ffb5a06588dd3abb01fe0fe3205646 | refs/heads/master | 1,634,976,409,281 | 1,542,042,832,000 | 1,542,319,733,000 | 109,560,458 | 0 | 0 | Apache-2.0 | 1,542,369,208,000 | 1,509,867,494,000 | Lean | UTF-8 | Lean | false | false | 10,093 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad, Andrew Zipperer, Haitao Zhang, Minchao Wu
Functions over sets.
-/
import data.set.basic
open function
namespace set
universes u v w x
variables {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} {ΞΉ : Sort x}
/- maps to -/
/-- `maps_to f a b` means that the image of `a` is contained in `b`. -/
@[reducible] def maps_to (f : Ξ± β Ξ²) (a : set Ξ±) (b : set Ξ²) : Prop := a β f β»ΒΉ' b
theorem maps_to_of_eq_on {f1 f2 : Ξ± β Ξ²} {a : set Ξ±} {b : set Ξ²} (hβ : eq_on f1 f2 a)
(hβ : maps_to f1 a b) :
maps_to f2 a b :=
Ξ» x h, by rw [mem_preimage_eq, β hβ _ h]; exact hβ h
theorem maps_to_comp {g : Ξ² β Ξ³} {f : Ξ± β Ξ²} {a : set Ξ±} {b : set Ξ²} {c : set Ξ³}
(hβ : maps_to g b c) (hβ : maps_to f a b) : maps_to (g β f) a c :=
Ξ» x h, hβ (hβ h)
theorem maps_to_univ (f : Ξ± β Ξ²) (a) : maps_to f a univ :=
Ξ» x h, trivial
theorem image_subset_of_maps_to_of_subset {f : Ξ± β Ξ²} {a c : set Ξ±} {b : set Ξ²} (hβ : maps_to f a b)
(hβ : c β a) :
f '' c β b :=
Ξ» y hy, let β¨x, hx, heqβ© := hy in
by rw [βheq]; apply hβ; apply hβ; assumption
theorem image_subset_of_maps_to {f : Ξ± β Ξ²} {a : set Ξ±} {b : set Ξ²} (h : maps_to f a b) :
f '' a β b :=
image_subset_of_maps_to_of_subset h (subset.refl _)
/- injectivity -/
/-- `f` is injective on `a` if the restriction of `f` to `a` is injective. -/
@[reducible] def inj_on (f : Ξ± β Ξ²) (a : set Ξ±) : Prop :=
ββ¦x1 x2 : Ξ±β¦, x1 β a β x2 β a β f x1 = f x2 β x1 = x2
theorem inj_on_empty (f : Ξ± β Ξ²) : inj_on f β
:=
Ξ» _ _ hβ _ _, false.elim hβ
theorem inj_on_of_eq_on {f1 f2 : Ξ± β Ξ²} {a : set Ξ±} (hβ : eq_on f1 f2 a)
(hβ : inj_on f1 a) :
inj_on f2 a :=
Ξ» _ _ hβ' hβ' heq, by apply hβ hβ' hβ'; rw [hβ, heq, βhβ]; repeat {assumption}
theorem inj_on_comp {g : Ξ² β Ξ³} {f : Ξ± β Ξ²} {a : set Ξ±} {b : set Ξ²}
(hβ : maps_to f a b) (hβ : inj_on g b) (hβ: inj_on f a) :
inj_on (g β f) a :=
Ξ» _ _ hβ' hβ' heq,
by apply hβ hβ' hβ'; apply hβ; repeat {apply hβ, assumption}; assumption
theorem inj_on_of_inj_on_of_subset {f : Ξ± β Ξ²} {a b : set Ξ±} (hβ : inj_on f b) (hβ : a β b) :
inj_on f a :=
Ξ» _ _ hβ' hβ' heq, hβ (hβ hβ') (hβ hβ') heq
lemma injective_iff_inj_on_univ {f : Ξ± β Ξ²} : injective f β inj_on f univ :=
iff.intro (Ξ» h _ _ _ _ heq, h heq) (Ξ» h _ _ heq, h trivial trivial heq)
lemma inj_on_iff_injective {f : Ξ± β Ξ²} {s : set Ξ±} : inj_on f s β injective (Ξ» x:s, f x.1) :=
β¨Ξ» H a b h, subtype.eq $ H a.2 b.2 h,
Ξ» H a b as bs h, congr_arg subtype.val $ @H β¨a, asβ© β¨b, bsβ© hβ©
/- surjectivity -/
/-- `f` is surjective from `a` to `b` if `b` is contained in the image of `a`. -/
@[reducible] def surj_on (f : Ξ± β Ξ²) (a : set Ξ±) (b : set Ξ²) : Prop := b β f '' a
theorem surj_on_of_eq_on {f1 f2 : Ξ± β Ξ²} {a : set Ξ±} {b : set Ξ²} (hβ : eq_on f1 f2 a)
(hβ : surj_on f1 a b) :
surj_on f2 a b :=
Ξ» _ h, let β¨x, hxβ© := hβ h in
β¨x, hx.left, by rw [βhβ _ hx.left]; exact hx.rightβ©
theorem surj_on_comp {g : Ξ² β Ξ³} {f : Ξ± β Ξ²} {a : set Ξ±} {b : set Ξ²} {c : set Ξ³}
(hβ : surj_on g b c) (hβ : surj_on f a b) :
surj_on (g β f) a c :=
Ξ» z h, let β¨y, hyβ© := hβ h, β¨x, hxβ© := hβ hy.left in
β¨x, hx.left, calc g (f x) = g y : by rw [hx.right]
... = z : hy.rightβ©
lemma surjective_iff_surj_on_univ {f : Ξ± β Ξ²} : surjective f β surj_on f univ univ :=
by simp [surjective, surj_on, subset_def]
lemma surj_on_iff_surjective {f : Ξ± β Ξ²} {s : set Ξ±} : surj_on f s univ β surjective (Ξ» x:s, f x.1) :=
β¨Ξ» H b, let β¨a, as, eβ© := @H b trivial in β¨β¨a, asβ©, eβ©,
Ξ» H b _, let β¨β¨a, asβ©, eβ© := H b in β¨a, as, eβ©β©
lemma image_eq_of_maps_to_of_surj_on {f : Ξ± β Ξ²} {a : set Ξ±} {b : set Ξ²}
(hβ : maps_to f a b) (hβ : surj_on f a b) :
f '' a = b :=
eq_of_subset_of_subset (image_subset_of_maps_to hβ) hβ
/- bijectivity -/
/-- `f` is bijective from `a` to `b` if `f` is injective on `a` and `f '' a = b`. -/
@[reducible] def bij_on (f : Ξ± β Ξ²) (a : set Ξ±) (b : set Ξ²) : Prop :=
maps_to f a b β§ inj_on f a β§ surj_on f a b
lemma maps_to_of_bij_on {f : Ξ± β Ξ²} {a : set Ξ±} {b : set Ξ²} (h : bij_on f a b) :
maps_to f a b :=
h.left
lemma inj_on_of_bij_on {f : Ξ± β Ξ²} {a : set Ξ±} {b : set Ξ²} (h : bij_on f a b) :
inj_on f a :=
h.right.left
lemma surj_on_of_bij_on {f : Ξ± β Ξ²} {a : set Ξ±} {b : set Ξ²} (h : bij_on f a b) :
surj_on f a b :=
h.right.right
lemma bij_on.mk {f : Ξ± β Ξ²} {a : set Ξ±} {b : set Ξ²}
(hβ : maps_to f a b) (hβ : inj_on f a) (hβ : surj_on f a b) :
bij_on f a b :=
β¨hβ, hβ, hββ©
theorem bij_on_of_eq_on {f1 f2 : Ξ± β Ξ²} {a : set Ξ±} {b : set Ξ²} (hβ : eq_on f1 f2 a)
(hβ : bij_on f1 a b) : bij_on f2 a b :=
let β¨map, inj, surjβ© := hβ in
β¨maps_to_of_eq_on hβ map, inj_on_of_eq_on hβ inj, surj_on_of_eq_on hβ surjβ©
lemma image_eq_of_bij_on {f : Ξ± β Ξ²} {a : set Ξ±} {b : set Ξ²} (h : bij_on f a b) :
f '' a = b :=
image_eq_of_maps_to_of_surj_on h.left h.right.right
theorem bij_on_comp {g : Ξ² β Ξ³} {f : Ξ± β Ξ²} {a : set Ξ±} {b : set Ξ²} {c : set Ξ³}
(hβ : bij_on g b c) (hβ: bij_on f a b) :
bij_on (g β f) a c :=
let β¨gmap, ginj, gsurjβ© := hβ, β¨fmap, finj, fsurjβ© := hβ in
β¨maps_to_comp gmap fmap, inj_on_comp fmap ginj finj, surj_on_comp gsurj fsurjβ©
lemma bijective_iff_bij_on_univ {f : Ξ± β Ξ²} : bijective f β bij_on f univ univ :=
iff.intro
(Ξ» h, let β¨inj, surjβ© := h in
β¨maps_to_univ f _, iff.mp injective_iff_inj_on_univ inj, iff.mp surjective_iff_surj_on_univ surjβ©)
(Ξ» h, let β¨map, inj, surjβ© := h in
β¨iff.mpr injective_iff_inj_on_univ inj, iff.mpr surjective_iff_surj_on_univ surjβ©)
/- left inverse -/
/-- `g` is a left inverse to `f` on `a` means that `g (f x) = x` for all `x β a`. -/
@[reducible] def left_inv_on (g : Ξ² β Ξ±) (f : Ξ± β Ξ²) (a : set Ξ±) : Prop :=
β x β a, g (f x) = x
theorem left_inv_on_of_eq_on_left {g1 g2 : Ξ² β Ξ±} {f : Ξ± β Ξ²} {a : set Ξ±} {b : set Ξ²}
(hβ : maps_to f a b) (hβ : eq_on g1 g2 b) (hβ : left_inv_on g1 f a) : left_inv_on g2 f a :=
Ξ» x h,
calc
g2 (f x) = g1 (f x) : eq.symm $ hβ _ (hβ h)
... = x : hβ _ h
theorem left_inv_on_of_eq_on_right {g : Ξ² β Ξ±} {f1 f2 : Ξ± β Ξ²} {a : set Ξ±}
(hβ : eq_on f1 f2 a) (hβ : left_inv_on g f1 a) : left_inv_on g f2 a :=
Ξ» x h,
calc
g (f2 x) = g (f1 x) : congr_arg g (hβ _ h).symm
... = x : hβ _ h
theorem inj_on_of_left_inv_on {g : Ξ² β Ξ±} {f : Ξ± β Ξ²} {a : set Ξ±} (h : left_inv_on g f a) :
inj_on f a :=
Ξ» xβ xβ hβ hβ heq,
calc
xβ = g (f xβ) : eq.symm $ h _ hβ
... = g (f xβ) : congr_arg g heq
... = xβ : h _ hβ
theorem left_inv_on_comp {f' : Ξ² β Ξ±} {g' : Ξ³ β Ξ²} {g : Ξ² β Ξ³} {f : Ξ± β Ξ²}
{a : set Ξ±} {b : set Ξ²} (hβ : maps_to f a b)
(hβ : left_inv_on f' f a) (hβ : left_inv_on g' g b) : left_inv_on (f' β g') (g β f) a :=
Ξ» x h,
calc
(f' β g') ((g β f) x) = f' (f x) : congr_arg f' (hβ _ (hβ h))
... = x : hβ _ h
/- right inverse -/
/-- `g` is a right inverse to `f` on `b` if `f (g x) = x` for all `x β b`. -/
@[reducible] def right_inv_on (g : Ξ² β Ξ±) (f : Ξ± β Ξ²) (b : set Ξ²) : Prop :=
left_inv_on f g b
theorem right_inv_on_of_eq_on_left {g1 g2 : Ξ² β Ξ±} {f : Ξ± β Ξ²} {a : set Ξ±} {b : set Ξ²}
(hβ : eq_on g1 g2 b) (hβ : right_inv_on g1 f b) : right_inv_on g2 f b :=
left_inv_on_of_eq_on_right hβ hβ
theorem right_inv_on_of_eq_on_right {g : Ξ² β Ξ±} {f1 f2 : Ξ± β Ξ²} {a : set Ξ±} {b : set Ξ²}
(hβ : maps_to g b a) (hβ : eq_on f1 f2 a) (hβ : right_inv_on g f1 b) : right_inv_on g f2 b :=
left_inv_on_of_eq_on_left hβ hβ hβ
theorem surj_on_of_right_inv_on {g : Ξ² β Ξ±} {f : Ξ± β Ξ²} {a : set Ξ±} {b : set Ξ²}
(hβ : maps_to g b a) (hβ : right_inv_on g f b) :
surj_on f a b :=
Ξ» y h, β¨g y, hβ h, hβ _ hβ©
theorem right_inv_on_comp {f' : Ξ² β Ξ±} {g' : Ξ³ β Ξ²} {g : Ξ² β Ξ³} {f : Ξ± β Ξ²}
{c : set Ξ³} {b : set Ξ²} (g'cb : maps_to g' c b)
(hβ : right_inv_on f' f b) (hβ : right_inv_on g' g c) : right_inv_on (f' β g') (g β f) c :=
left_inv_on_comp g'cb hβ hβ
theorem right_inv_on_of_inj_on_of_left_inv_on {f : Ξ± β Ξ²} {g : Ξ² β Ξ±} {a : set Ξ±} {b : set Ξ²}
(hβ : maps_to f a b) (hβ : maps_to g b a) (hβ : inj_on f a) (hβ : left_inv_on f g b) :
right_inv_on f g a :=
Ξ» x h, hβ (hβ $ hβ h) h (hβ _ (hβ h))
theorem eq_on_of_left_inv_of_right_inv {gβ gβ : Ξ² β Ξ±} {f : Ξ± β Ξ²} {a : set Ξ±} {b : set Ξ²}
(hβ : maps_to gβ b a) (hβ : left_inv_on gβ f a) (hβ : right_inv_on gβ f b) : eq_on gβ gβ b :=
Ξ» y h,
calc
gβ y = (gβ β f β gβ) y : congr_arg gβ (hβ _ h).symm
... = gβ y : hβ _ (hβ h)
theorem left_inv_on_of_surj_on_right_inv_on {f : Ξ± β Ξ²} {g : Ξ² β Ξ±} {a : set Ξ±} {b : set Ξ²}
(hβ : surj_on f a b) (hβ : right_inv_on f g a) :
left_inv_on f g b :=
Ξ» y h, let β¨x, hx, heqβ© := hβ h in
calc
(f β g) y = (f β g β f) x : congr_arg (f β g) heq.symm
... = f x : congr_arg f (hβ _ hx)
... = y : heq
/- inverses -/
/-- `g` is an inverse to `f` viewed as a map from `a` to `b` -/
@[reducible] def inv_on (g : Ξ² β Ξ±) (f : Ξ± β Ξ²) (a : set Ξ±) (b : set Ξ²) : Prop :=
left_inv_on g f a β§ right_inv_on g f b
theorem bij_on_of_inv_on {g : Ξ² β Ξ±} {f : Ξ± β Ξ²} {a : set Ξ±} {b : set Ξ²} (hβ : maps_to f a b)
(hβ : maps_to g b a) (hβ : inv_on g f a b) : bij_on f a b :=
β¨hβ, inj_on_of_left_inv_on hβ.left, surj_on_of_right_inv_on hβ hβ.rightβ©
end set
|
08d14e016c129702f37dab6313a012f67bae83ff | 367134ba5a65885e863bdc4507601606690974c1 | /src/data/nat/log.lean | 9efe63701a64aadec49e56ead768cdc3a0085b88 | [
"Apache-2.0"
] | permissive | kodyvajjha/mathlib | 9bead00e90f68269a313f45f5561766cfd8d5cad | b98af5dd79e13a38d84438b850a2e8858ec21284 | refs/heads/master | 1,624,350,366,310 | 1,615,563,062,000 | 1,615,563,062,000 | 162,666,963 | 0 | 0 | Apache-2.0 | 1,545,367,651,000 | 1,545,367,651,000 | null | UTF-8 | Lean | false | false | 2,159 | 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.nat.basic
/-!
# Natural number logarithm
This file defines `log b n`, the logarithm of `n` with base `b`, to be the largest `k` such that
`b ^ k β€ n`.
-/
namespace nat
/-- `log b n`, is the logarithm of natural number `n` in base `b`. It returns the largest `k : β`
such that `b^k β€ n`, so if `b^k = n`, it returns exactly `k`. -/
@[pp_nodot] def log (b : β) : β β β
| n :=
if h : b β€ n β§ 1 < b then
have n / b < n,
from div_lt_self
(nat.lt_of_lt_of_le (lt_trans zero_lt_one h.2) h.1) h.2,
log (n / b) + 1
else 0
lemma pow_le_iff_le_log (x y : β) {b} (hb : 1 < b) (hy : 1 β€ y) :
b^x β€ y β x β€ log b y :=
begin
induction y using nat.strong_induction_on with y ih
generalizing x,
rw [log], split_ifs,
{ have h'' : 0 < b := lt_of_le_of_lt (zero_le _) hb,
cases h with hβ hβ,
rw [β nat.sub_le_right_iff_le_add,β ih (y / b),
le_div_iff_mul_le _ _ h'',β pow_succ'],
{ cases x; simp [hβ,hy] },
{ apply div_lt_self; assumption },
{ rwa [le_div_iff_mul_le _ _ h'',one_mul], } },
{ replace h := lt_of_not_ge (not_and'.1 h hb),
split; intros h',
{ have := lt_of_le_of_lt h' h,
apply le_of_succ_le_succ,
change x < 1, rw [β pow_lt_iff_lt_right hb,pow_one],
exact this },
{ replace h' := le_antisymm h' (zero_le _),
rw [h',pow_zero], exact hy} },
end
lemma log_pow (b x : β) (hb : 1 < b) : log b (b ^ x) = x :=
eq_of_forall_le_iff $ Ξ» z,
by { rwa [β pow_le_iff_le_log _ _ hb,pow_le_iff_le_right],
rw β pow_zero b, apply pow_le_pow_of_le_right,
apply lt_of_le_of_lt (zero_le _) hb, apply zero_le }
lemma pow_succ_log_gt_self (b x : β) (hb : 1 < b) (hy : 1 β€ x) :
x < b ^ succ (log b x) :=
begin
apply lt_of_not_ge,
rw [(β₯),pow_le_iff_le_log _ _ hb hy],
apply not_le_of_lt, apply lt_succ_self,
end
lemma pow_log_le_self (b x : β) (hb : 1 < b) (hx : 1 β€ x) : b ^ log b x β€ x :=
by rw [pow_le_iff_le_log _ _ hb hx]
end nat
|
62c3ffac3211e81246fa03eaf674c3134b8b7478 | 618003631150032a5676f229d13a079ac875ff77 | /src/category_theory/elements.lean | 4d0ab5086a2bf8f89707b242358c079732b17325 | [
"Apache-2.0"
] | permissive | awainverse/mathlib | 939b68c8486df66cfda64d327ad3d9165248c777 | ea76bd8f3ca0a8bf0a166a06a475b10663dec44a | refs/heads/master | 1,659,592,962,036 | 1,590,987,592,000 | 1,590,987,592,000 | 268,436,019 | 1 | 0 | Apache-2.0 | 1,590,990,500,000 | 1,590,990,500,000 | null | UTF-8 | Lean | false | false | 4,467 | 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.comma
import category_theory.groupoid
/-!
# The category of elements
This file defines the category of elements, also known as (a special case of) the Grothendieck construction.
Given a functor `F : C β₯€ Type`, an object of `F.elements` is a pair `(X : C, x : F.obj X)`.
A morphism `(X, x) βΆ (Y, y)` is a morphism `f : X βΆ Y` in `C`, so `F.map f` takes `x` to `y`.
## Implementation notes
This construction is equivalent to a special case of a comma construction, so this is mostly just
a more convenient API. We prove the equivalence in `category_theory.category_of_elements.comma_equivalence`.
## References
* [Emily Riehl, *Category Theory in Context*, Section 2.4][riehl2017]
* <https://en.wikipedia.org/wiki/Category_of_elements>
* <https://ncatlab.org/nlab/show/category+of+elements>
## Tags
category of elements, Grothendieck construction, comma category
-/
namespace category_theory
universes w v u
variables {C : Type u} [π : category.{v} C]
include π
/-- The type of objects for the category of elements of a functor `F : C β₯€ Type` is a pair `(X : C, x : F.obj X)`. -/
def functor.elements (F : C β₯€ Type w) := (Ξ£ c : C, F.obj c)
/-- The category structure on `F.elements`, for `F : C β₯€ Type`.
A morphism `(X, x) βΆ (Y, y)` is a morphism `f : X βΆ Y` in `C`, so `F.map f` takes `x` to `y`.
-/
instance category_of_elements (F : C β₯€ Type w) : category F.elements :=
{ hom := Ξ» p q, { f : p.1 βΆ q.1 // (F.map f) p.2 = q.2 },
id := Ξ» p, β¨π p.1, by obviouslyβ©,
comp := Ξ» p q r f g, β¨f.val β« g.val, by obviouslyβ© }
namespace category_of_elements
@[ext]
lemma ext (F : C β₯€ Type w) {x y : F.elements} (f g : x βΆ y) (w : f.val = g.val) : f = g :=
subtype.eq' w
@[simp] lemma comp_val {F : C β₯€ Type w} {p q r : F.elements} {f : p βΆ q} {g : q βΆ r} :
(f β« g).val = f.val β« g.val := rfl
@[simp] lemma id_val {F : C β₯€ Type w} {p : F.elements} : (π p : p βΆ p).val = π p.1 := rfl
end category_of_elements
omit π -- We'll assume C has a groupoid structure, so temporarily forget its category structure
-- to avoid conflicts.
instance groupoid_of_elements [groupoid C] (F : C β₯€ Type w) : groupoid F.elements :=
{ inv := Ξ» p q f, β¨inv f.val,
calc F.map (inv f.val) q.2 = F.map (inv f.val) (F.map f.val p.2) : by rw f.2
... = (F.map f.val β« F.map (inv f.val)) p.2 : by simp
... = p.2 : by {rw βfunctor.map_comp, simp}β© }
include π
namespace category_of_elements
variable (F : C β₯€ Type w)
/-- The functor out of the category of elements which forgets the element. -/
def Ο : F.elements β₯€ C :=
{ obj := Ξ» X, X.1,
map := Ξ» X Y f, f.val }
@[simp] lemma Ο_obj (X : F.elements) : (Ο F).obj X = X.1 := rfl
@[simp] lemma Ο_map {X Y : F.elements} (f : X βΆ Y) : (Ο F).map f = f.val := rfl
/-- The forward direction of the equivalence `F.elements β
(*, F)`. -/
def to_comma : F.elements β₯€ comma ((functor.const punit).obj punit) F :=
{ obj := Ξ» X, { left := punit.star, right := X.1, hom := Ξ» _, X.2 },
map := Ξ» X Y f, { right := f.val } }
@[simp] lemma to_comma_obj (X) :
(to_comma F).obj X = { left := punit.star, right := X.1, hom := Ξ» _, X.2 } := rfl
@[simp] lemma to_comma_map {X Y} (f : X βΆ Y) :
(to_comma F).map f = { right := f.val } := rfl
/-- The reverse direction of the equivalence `F.elements β
(*, F)`. -/
def from_comma : comma ((functor.const punit).obj punit) F β₯€ F.elements :=
{ obj := Ξ» X, β¨X.right, X.hom (punit.star)β©,
map := Ξ» X Y f, β¨f.right, congr_fun f.w'.symm punit.starβ© }
@[simp] lemma from_comma_obj (X) :
(from_comma F).obj X = β¨X.right, X.hom (punit.star)β© := rfl
@[simp] lemma from_comma_map {X Y} (f : X βΆ Y) :
(from_comma F).map f = β¨f.right, congr_fun f.w'.symm punit.starβ© := rfl
/-- The equivalence between the category of elements `F.elements`
and the comma category `(*, F)`. -/
def comma_equivalence : F.elements β comma ((functor.const punit).obj punit) F :=
equivalence.mk (to_comma F) (from_comma F)
(nat_iso.of_components (Ξ» X, eq_to_iso (by tidy)) (by tidy))
(nat_iso.of_components
(Ξ» X, { hom := { right := π _ }, inv := { right := π _ } })
(by tidy))
end category_of_elements
end category_theory
|
9bf72c5e70378db176f814472a04b92738e920aa | aa3f8992ef7806974bc1ffd468baa0c79f4d6643 | /library/logic/instances.lean | a3eeedceae480ded84a626c4b36c5b06e6aed1ba | [
"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 | 4,606 | lean | -- Copyright (c) 2014 Microsoft Corporation. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Author: Jeremy Avigad
-- logic.instances
-- ====================
import logic.connectives algebra.relation
namespace relation
open relation
-- Congruences for logic
-- ---------------------
theorem congruence_not : congruence iff iff not :=
congruence.mk
(take a b,
assume H : a β b, iff.intro
(assume H1 : Β¬a, assume H2 : b, H1 (iff.elim_right H H2))
(assume H1 : Β¬b, assume H2 : a, H1 (iff.elim_left H H2)))
theorem congruence_and : congruence2 iff iff iff and :=
congruence2.mk
(take a1 b1 a2 b2,
assume H1 : a1 β b1, assume H2 : a2 β b2,
iff.intro
(assume H3 : a1 β§ a2, and.imp_and H3 (iff.elim_left H1) (iff.elim_left H2))
(assume H3 : b1 β§ b2, and.imp_and H3 (iff.elim_right H1) (iff.elim_right H2)))
theorem congruence_or : congruence2 iff iff iff or :=
congruence2.mk
(take a1 b1 a2 b2,
assume H1 : a1 β b1, assume H2 : a2 β b2,
iff.intro
(assume H3 : a1 β¨ a2, or.imp_or H3 (iff.elim_left H1) (iff.elim_left H2))
(assume H3 : b1 β¨ b2, or.imp_or H3 (iff.elim_right H1) (iff.elim_right H2)))
theorem congruence_imp : congruence2 iff iff iff imp :=
congruence2.mk
(take a1 b1 a2 b2,
assume H1 : a1 β b1, assume H2 : a2 β b2,
iff.intro
(assume H3 : a1 β a2, assume Hb1 : b1, iff.elim_left H2 (H3 ((iff.elim_right H1) Hb1)))
(assume H3 : b1 β b2, assume Ha1 : a1, iff.elim_right H2 (H3 ((iff.elim_left H1) Ha1))))
theorem congruence_iff : congruence2 iff iff iff iff :=
congruence2.mk
(take a1 b1 a2 b2,
assume H1 : a1 β b1, assume H2 : a2 β b2,
iff.intro
(assume H3 : a1 β a2, iff.trans (iff.symm H1) (iff.trans H3 H2))
(assume H3 : b1 β b2, iff.trans H1 (iff.trans H3 (iff.symm H2))))
-- theorem congruence_const_iff [instance] := congruence.const iff iff.refl
definition congruence_not_compose [instance] := congruence.compose congruence_not
definition congruence_and_compose [instance] := congruence.compose21 congruence_and
definition congruence_or_compose [instance] := congruence.compose21 congruence_or
definition congruence_implies_compose [instance] := congruence.compose21 congruence_imp
definition congruence_iff_compose [instance] := congruence.compose21 congruence_iff
-- Generalized substitution
-- ------------------------
-- TODO: note that the target has to be "iff". Otherwise, there is not enough
-- information to infer an mp-like relation.
namespace general_operations
theorem subst {T : Type} (R : T β T β Prop) β¦P : T β Propβ¦ [C : congruence R iff P]
{a b : T} (H : R a b) (H1 : P a) : P b := iff.elim_left (congruence.app C H) H1
end general_operations
-- = is an equivalence relation
-- ----------------------------
theorem is_reflexive_eq [instance] (T : Type) : relation.is_reflexive (@eq T) :=
relation.is_reflexive.mk (@eq.refl T)
theorem is_symmetric_eq [instance] (T : Type) : relation.is_symmetric (@eq T) :=
relation.is_symmetric.mk (@eq.symm T)
theorem is_transitive_eq [instance] (T : Type) : relation.is_transitive (@eq T) :=
relation.is_transitive.mk (@eq.trans T)
-- TODO: this is only temporary, needed to inform Lean that is_equivalence is a class
theorem is_equivalence_eq [instance] (T : Type) : relation.is_equivalence (@eq T) :=
relation.is_equivalence.mk _ _ _
-- iff is an equivalence relation
-- ------------------------------
theorem is_reflexive_iff [instance] : relation.is_reflexive iff :=
relation.is_reflexive.mk (@iff.refl)
theorem is_symmetric_iff [instance] : relation.is_symmetric iff :=
relation.is_symmetric.mk (@iff.symm)
theorem is_transitive_iff [instance] : relation.is_transitive iff :=
relation.is_transitive.mk (@iff.trans)
-- Mp-like for iff
-- ---------------
theorem mp_like_iff [instance] (a b : Prop) (H : a β b) : @relation.mp_like iff a b H :=
relation.mp_like.mk (iff.elim_left H)
-- Substition for iff
-- ------------------
namespace iff
theorem subst {P : Prop β Prop} [C : congruence iff iff P] {a b : Prop} (H : a β b) (H1 : P a) :
P b :=
@general_operations.subst Prop iff P C a b H H1
end iff
-- Support for calculations with iff
-- ----------------
calc_subst iff.subst
namespace iff_ops
notation H β»ΒΉ := iff.symm H
notation H1 β¬ H2 := iff.trans H1 H2
notation H1 βΈ H2 := iff.subst H1 H2
definition refl := iff.refl
definition symm := @iff.symm
definition trans := @iff.trans
definition subst := @iff.subst
definition mp := @iff.mp
end iff_ops
end relation
|
ec395130137e4155a69473154e8d20b71c71cfe5 | c3f2fcd060adfa2ca29f924839d2d925e8f2c685 | /hott/init/logic.hlean | 994801ab0a5d45b88a673f43b09fccb9dba73455 | [
"Apache-2.0"
] | permissive | respu/lean | 6582d19a2f2838a28ecd2b3c6f81c32d07b5341d | 8c76419c60b63d0d9f7bc04ebb0b99812d0ec654 | refs/heads/master | 1,610,882,451,231 | 1,427,747,084,000 | 1,427,747,429,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 11,464 | hlean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: init.logic
Authors: Leonardo de Moura
-/
prelude
import init.datatypes init.reserved_notation
definition not.{l} (a : Type.{l}) := a β empty.{l}
prefix `Β¬` := not
definition absurd {a : Type} {b : Type} (Hβ : a) (Hβ : Β¬a) : b :=
empty.rec (Ξ» e, b) (Hβ Hβ)
definition mt {a b : Type} (Hβ : a β b) (Hβ : Β¬b) : Β¬a :=
assume Ha : a, absurd (Hβ Ha) Hβ
/- not -/
protected definition not_empty : Β¬ empty :=
assume H : empty, H
definition not_not_intro {a : Type} (Ha : a) : ¬¬a :=
assume Hna : Β¬a, absurd Ha Hna
definition not.intro {a : Type} (H : a β empty) : Β¬a := H
definition not.elim {a : Type} (Hβ : Β¬a) (Hβ : a) : empty := Hβ Hβ
definition not_not_of_not_implies {a b : Type} (H : Β¬(a β b)) : ¬¬a :=
assume Hna : Β¬a, absurd (assume Ha : a, absurd Ha Hna) H
definition not_of_not_implies {a b : Type} (H : Β¬(a β b)) : Β¬b :=
assume Hb : b, absurd (assume Ha : a, Hb) H
/- eq -/
notation a = b := eq a b
definition rfl {A : Type} {a : A} := eq.refl a
namespace eq
variables {A : Type}
variables {a b c a' : A}
definition subst {P : A β Type} (Hβ : a = b) (Hβ : P a) : P b :=
eq.rec Hβ Hβ
definition trans (Hβ : a = b) (Hβ : b = c) : a = c :=
subst Hβ Hβ
definition symm (H : a = b) : b = a :=
subst H (refl a)
namespace ops
notation H `β»ΒΉ` := symm H --input with \sy or \-1 or \inv
notation H1 β¬ H2 := trans H1 H2
notation H1 βΈ H2 := subst H1 H2
end ops
end eq
calc_subst eq.subst
calc_refl eq.refl
calc_trans eq.trans
calc_symm eq.symm
namespace lift
definition down_up.{lβ lβ} {A : Type.{lβ}} (a : A) : down (up.{lβ lβ} a) = a :=
rfl
definition up_down.{lβ lβ} {A : Type.{lβ}} (a : lift.{lβ lβ} A) : up (down a) = a :=
lift.rec_on a (Ξ» d, rfl)
end lift
/- ne -/
definition ne {A : Type} (a b : A) := Β¬(a = b)
notation a β b := ne a b
namespace ne
open eq.ops
variable {A : Type}
variables {a b : A}
definition intro : (a = b β empty) β a β b :=
assume H, H
definition elim : a β b β a = b β empty :=
assume Hβ Hβ, Hβ Hβ
definition irrefl : a β a β empty :=
assume H, H rfl
definition symm : a β b β b β a :=
assume (H : a β b) (Hβ : b = a), H Hββ»ΒΉ
end ne
section
open eq.ops
variables {A : Type} {a b c : A}
definition false.of_ne : a β a β empty :=
assume H, H rfl
definition ne.of_eq_of_ne : a = b β b β c β a β c :=
assume Hβ Hβ, Hββ»ΒΉ βΈ Hβ
definition ne.of_ne_of_eq : a β b β b = c β a β c :=
assume Hβ Hβ, Hβ βΈ Hβ
end
calc_trans ne.of_eq_of_ne
calc_trans ne.of_ne_of_eq
/- iff -/
definition iff (a b : Type) := prod (a β b) (b β a)
notation a <-> b := iff a b
notation a β b := iff a b
namespace iff
variables {a b c : Type}
definition def : (a β b) = (prod (a β b) (b β a)) :=
rfl
definition intro (Hβ : a β b) (Hβ : b β a) : a β b :=
prod.mk Hβ Hβ
definition elim (Hβ : (a β b) β (b β a) β c) (Hβ : a β b) : c :=
prod.rec Hβ Hβ
definition elim_left (H : a β b) : a β b :=
elim (assume Hβ Hβ, Hβ) H
definition mp := @elim_left
definition elim_right (H : a β b) : b β a :=
elim (assume Hβ Hβ, Hβ) H
definition flip_sign (Hβ : a β b) : Β¬a β Β¬b :=
intro
(assume Hna, mt (elim_right Hβ) Hna)
(assume Hnb, mt (elim_left Hβ) Hnb)
definition refl (a : Type) : a β a :=
intro (assume H, H) (assume H, H)
definition rfl {a : Type} : a β a :=
refl a
definition trans (Hβ : a β b) (Hβ : b β c) : a β c :=
intro
(assume Ha, elim_left Hβ (elim_left Hβ Ha))
(assume Hc, elim_right Hβ (elim_right Hβ Hc))
definition symm (H : a β b) : b β a :=
intro
(assume Hb, elim_right H Hb)
(assume Ha, elim_left H Ha)
definition true_elim (H : a β unit) : a :=
mp (symm H) unit.star
definition false_elim (H : a β empty) : Β¬a :=
assume Ha : a, mp H Ha
open eq.ops
definition of_eq {a b : Type} (H : a = b) : a β b :=
iff.intro (Ξ» Ha, H βΈ Ha) (Ξ» Hb, Hβ»ΒΉ βΈ Hb)
end iff
calc_refl iff.refl
calc_trans iff.trans
/- inhabited -/
inductive inhabited [class] (A : Type) : Type :=
mk : A β inhabited A
namespace inhabited
protected definition destruct {A : Type} {B : Type} (H1 : inhabited A) (H2 : A β B) : B :=
inhabited.rec H2 H1
definition inhabited_fun [instance] (A : Type) {B : Type} [H : inhabited B] : inhabited (A β B) :=
destruct H (Ξ»b, mk (Ξ»a, b))
definition inhabited_Pi [instance] (A : Type) {B : A β Type} [H : Ξ x, inhabited (B x)] :
inhabited (Ξ x, B x) :=
mk (Ξ»a, destruct (H a) (Ξ»b, b))
definition default (A : Type) [H : inhabited A] : A := destruct H (take a, a)
end inhabited
/- decidable -/
inductive decidable.{l} [class] (p : Type.{l}) : Type.{l} :=
| inl : p β decidable p
| inr : Β¬p β decidable p
namespace decidable
variables {p q : Type}
definition pos_witness [C : decidable p] (H : p) : p :=
decidable.rec_on C (Ξ» Hp, Hp) (Ξ» Hnp, absurd H Hnp)
definition neg_witness [C : decidable p] (H : Β¬ p) : Β¬ p :=
decidable.rec_on C (Ξ» Hp, absurd Hp H) (Ξ» Hnp, Hnp)
definition by_cases {q : Type} [C : decidable p] (Hpq : p β q) (Hnpq : Β¬p β q) : q :=
decidable.rec_on C (assume Hp, Hpq Hp) (assume Hnp, Hnpq Hnp)
definition em (p : Type) [H : decidable p] : sum p Β¬p :=
by_cases (Ξ» Hp, sum.inl Hp) (Ξ» Hnp, sum.inr Hnp)
definition by_contradiction [Hp : decidable p] (H : Β¬p β empty) : p :=
by_cases
(assume Hβ : p, Hβ)
(assume Hβ : Β¬p, empty.rec (Ξ» e, p) (H Hβ))
definition decidable_iff_equiv (Hp : decidable p) (H : p β q) : decidable q :=
decidable.rec_on Hp
(assume Hp : p, inl (iff.elim_left H Hp))
(assume Hnp : Β¬p, inr (iff.elim_left (iff.flip_sign H) Hnp))
definition decidable_eq_equiv.{l} {p q : Type.{l}} (Hp : decidable p) (H : p = q) : decidable q :=
decidable_iff_equiv Hp (iff.of_eq H)
end decidable
section
variables {p q : Type}
open decidable (rec_on inl inr)
definition decidable_unit [instance] : decidable unit :=
inl unit.star
definition decidable_empty [instance] : decidable empty :=
inr not_empty
definition decidable_prod [instance] [Hp : decidable p] [Hq : decidable q] : decidable (prod p q) :=
rec_on Hp
(assume Hp : p, rec_on Hq
(assume Hq : q, inl (prod.mk Hp Hq))
(assume Hnq : Β¬q, inr (Ξ» H : prod p q, prod.rec_on H (Ξ» Hp Hq, absurd Hq Hnq))))
(assume Hnp : Β¬p, inr (Ξ» H : prod p q, prod.rec_on H (Ξ» Hp Hq, absurd Hp Hnp)))
definition decidable_sum [instance] [Hp : decidable p] [Hq : decidable q] : decidable (sum p q) :=
rec_on Hp
(assume Hp : p, inl (sum.inl Hp))
(assume Hnp : Β¬p, rec_on Hq
(assume Hq : q, inl (sum.inr Hq))
(assume Hnq : Β¬q, inr (Ξ» H : sum p q, sum.rec_on H (Ξ» Hp, absurd Hp Hnp) (Ξ» Hq, absurd Hq Hnq))))
definition decidable_not [instance] [Hp : decidable p] : decidable (Β¬p) :=
rec_on Hp
(assume Hp, inr (not_not_intro Hp))
(assume Hnp, inl Hnp)
definition decidable_implies [instance] [Hp : decidable p] [Hq : decidable q] : decidable (p β q) :=
rec_on Hp
(assume Hp : p, rec_on Hq
(assume Hq : q, inl (assume H, Hq))
(assume Hnq : Β¬q, inr (assume H : p β q, absurd (H Hp) Hnq)))
(assume Hnp : Β¬p, inl (assume Hp, absurd Hp Hnp))
definition decidable_if [instance] [Hp : decidable p] [Hq : decidable q] : decidable (p β q) :=
show decidable (prod (p β q) (q β p)), from _
end
definition decidable_pred [reducible] {A : Type} (R : A β Type) := Ξ (a : A), decidable (R a)
definition decidable_rel [reducible] {A : Type} (R : A β A β Type) := Ξ (a b : A), decidable (R a b)
definition decidable_eq [reducible] (A : Type) := decidable_rel (@eq A)
definition decidable_ne [instance] {A : Type} [H : decidable_eq A] : decidable_rel (@ne A) :=
show β x y : A, decidable (x = y β empty), from _
definition ite (c : Type) [H : decidable c] {A : Type} (t e : A) : A :=
decidable.rec_on H (Ξ» Hc, t) (Ξ» Hnc, e)
definition if_pos {c : Type} [H : decidable c] (Hc : c) {A : Type} {t e : A} : (if c then t else e) = t :=
decidable.rec
(Ξ» Hc : c, eq.refl (@ite c (decidable.inl Hc) A t e))
(Ξ» Hnc : Β¬c, absurd Hc Hnc)
H
definition if_neg {c : Type} [H : decidable c] (Hnc : Β¬c) {A : Type} {t e : A} : (if c then t else e) = e :=
decidable.rec
(Ξ» Hc : c, absurd Hc Hnc)
(Ξ» Hnc : Β¬c, eq.refl (@ite c (decidable.inr Hnc) A t e))
H
definition if_t_t (c : Type) [H : decidable c] {A : Type} (t : A) : (if c then t else t) = t :=
decidable.rec
(Ξ» Hc : c, eq.refl (@ite c (decidable.inl Hc) A t t))
(Ξ» Hnc : Β¬c, eq.refl (@ite c (decidable.inr Hnc) A t t))
H
definition if_unit {A : Type} (t e : A) : (if unit then t else e) = t :=
if_pos unit.star
definition if_empty {A : Type} (t e : A) : (if empty then t else e) = e :=
if_neg not_empty
definition if_cond_congr {cβ cβ : Type} [Hβ : decidable cβ] [Hβ : decidable cβ] (Heq : cβ β cβ) {A : Type} (t e : A)
: (if cβ then t else e) = (if cβ then t else e) :=
decidable.rec_on Hβ
(Ξ» Hcβ : cβ, decidable.rec_on Hβ
(Ξ» Hcβ : cβ, if_pos Hcβ β¬ (if_pos Hcβ)β»ΒΉ)
(Ξ» Hncβ : Β¬cβ, absurd (iff.elim_left Heq Hcβ) Hncβ))
(Ξ» Hncβ : Β¬cβ, decidable.rec_on Hβ
(Ξ» Hcβ : cβ, absurd (iff.elim_right Heq Hcβ) Hncβ)
(Ξ» Hncβ : Β¬cβ, if_neg Hncβ β¬ (if_neg Hncβ)β»ΒΉ))
definition if_congr_aux {cβ cβ : Type} [Hβ : decidable cβ] [Hβ : decidable cβ] {A : Type} {tβ tβ eβ eβ : A}
(Hc : cβ β cβ) (Ht : tβ = tβ) (He : eβ = eβ) :
(if cβ then tβ else eβ) = (if cβ then tβ else eβ) :=
Ht βΈ He βΈ (if_cond_congr Hc tβ eβ)
definition if_congr {cβ cβ : Type} [Hβ : decidable cβ] {A : Type} {tβ tβ eβ eβ : A} (Hc : cβ β cβ) (Ht : tβ = tβ) (He : eβ = eβ) :
(if cβ then tβ else eβ) = (@ite cβ (decidable.decidable_iff_equiv Hβ Hc) A tβ eβ) :=
have H2 [visible] : decidable cβ, from (decidable.decidable_iff_equiv Hβ Hc),
if_congr_aux Hc Ht He
-- We use "dependent" if-then-else to be able to communicate the if-then-else condition
-- to the branches
definition dite (c : Type) [H : decidable c] {A : Type} (t : c β A) (e : Β¬ c β A) : A :=
decidable.rec_on H (Ξ» Hc, t Hc) (Ξ» Hnc, e Hnc)
definition dif_pos {c : Type} [H : decidable c] (Hc : c) {A : Type} {t : c β A} {e : Β¬ c β A} : (if H : c then t H else e H) = t (decidable.pos_witness Hc) :=
decidable.rec
(Ξ» Hc : c, eq.refl (@dite c (decidable.inl Hc) A t e))
(Ξ» Hnc : Β¬c, absurd Hc Hnc)
H
definition dif_neg {c : Type} [H : decidable c] (Hnc : Β¬c) {A : Type} {t : c β A} {e : Β¬ c β A} : (if H : c then t H else e H) = e (decidable.neg_witness Hnc) :=
decidable.rec
(Ξ» Hc : c, absurd Hc Hnc)
(Ξ» Hnc : Β¬c, eq.refl (@dite c (decidable.inr Hnc) A t e))
H
-- Remark: dite and ite are "definitionally equal" when we ignore the proofs.
definition dite_ite_eq (c : Type) [H : decidable c] {A : Type} (t : A) (e : A) : dite c (Ξ»h, t) (Ξ»h, e) = ite c t e :=
rfl
|
c1e88f23b668182ae2cc7050e1e8428eb7741a8d | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/algebra/group/ext.lean | 9dd4666a7a8d17dc9e4f604ae05a40b11ba03302 | [
"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 | 4,991 | lean | /-
Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bryan Gin-ge Chen, Yury Kudryashov
-/
import algebra.group.hom
/-!
# Extensionality lemmas for monoid and group structures
In this file we prove extensionality lemmas for `monoid` and higher algebraic structures with one
binary operation. Extensionality lemmas for structures that are lower in the hierarchy can be found
in `algebra.group.defs`.
## Implementation details
To get equality of `npow` etc, we define a monoid homomorphism between two monoid structures on the
same type, then apply lemmas like `monoid_hom.map_div`, `monoid_hom.map_pow` etc.
## Tags
monoid, group, extensionality
-/
universe u
@[ext, to_additive]
lemma monoid.ext {M : Type u} β¦mβ mβ : monoid Mβ¦ (h_mul : mβ.mul = mβ.mul) : mβ = mβ :=
begin
have hβ : (@monoid.to_mul_one_class _ mβ).one = (@monoid.to_mul_one_class _ mβ).one,
from congr_arg (@mul_one_class.one M) (mul_one_class.ext h_mul),
set f : @monoid_hom M M (@monoid.to_mul_one_class _ mβ) (@monoid.to_mul_one_class _ mβ) :=
{ to_fun := id, map_one' := hβ, map_mul' := Ξ» x y, congr_fun (congr_fun h_mul x) y },
have hpow : mβ.npow = mβ.npow, by { ext n x, exact @monoid_hom.map_pow M M mβ mβ f x n },
unfreezingI { cases mβ, cases mβ },
congr; assumption
end
@[to_additive]
lemma comm_monoid.to_monoid_injective {M : Type u} :
function.injective (@comm_monoid.to_monoid M) :=
begin
rintros β¨β© β¨β© h,
congr'; injection h,
end
@[ext, to_additive]
lemma comm_monoid.ext {M : Type*} β¦mβ mβ : comm_monoid Mβ¦ (h_mul : mβ.mul = mβ.mul) : mβ = mβ :=
comm_monoid.to_monoid_injective $ monoid.ext h_mul
@[to_additive]
lemma left_cancel_monoid.to_monoid_injective {M : Type u} :
function.injective (@left_cancel_monoid.to_monoid M) :=
begin
rintros β¨β© β¨β© h,
congr'; injection h,
end
@[ext, to_additive]
lemma left_cancel_monoid.ext {M : Type u} β¦mβ mβ : left_cancel_monoid Mβ¦
(h_mul : mβ.mul = mβ.mul) : mβ = mβ :=
left_cancel_monoid.to_monoid_injective $ monoid.ext h_mul
@[to_additive]
lemma right_cancel_monoid.to_monoid_injective {M : Type u} :
function.injective (@right_cancel_monoid.to_monoid M) :=
begin
rintros β¨β© β¨β© h,
congr'; injection h,
end
@[ext, to_additive]
lemma right_cancel_monoid.ext {M : Type u} β¦mβ mβ : right_cancel_monoid Mβ¦
(h_mul : mβ.mul = mβ.mul) : mβ = mβ :=
right_cancel_monoid.to_monoid_injective $ monoid.ext h_mul
@[to_additive]
lemma cancel_monoid.to_left_cancel_monoid_injective {M : Type u} :
function.injective (@cancel_monoid.to_left_cancel_monoid M) :=
begin
rintros β¨β© β¨β© h,
congr'; injection h,
end
@[ext, to_additive]
lemma cancel_monoid.ext {M : Type*} β¦mβ mβ : cancel_monoid Mβ¦
(h_mul : mβ.mul = mβ.mul) : mβ = mβ :=
cancel_monoid.to_left_cancel_monoid_injective $ left_cancel_monoid.ext h_mul
@[to_additive]
lemma cancel_comm_monoid.to_comm_monoid_injective {M : Type u} :
function.injective (@cancel_comm_monoid.to_comm_monoid M) :=
begin
rintros β¨β© β¨β© h,
congr'; injection h,
end
@[ext, to_additive]
lemma cancel_comm_monoid.ext {M : Type*} β¦mβ mβ : cancel_comm_monoid Mβ¦
(h_mul : mβ.mul = mβ.mul) : mβ = mβ :=
cancel_comm_monoid.to_comm_monoid_injective $ comm_monoid.ext h_mul
@[ext, to_additive]
lemma div_inv_monoid.ext {M : Type*} β¦mβ mβ : div_inv_monoid Mβ¦ (h_mul : mβ.mul = mβ.mul)
(h_inv : mβ.inv = mβ.inv) : mβ = mβ :=
begin
have hβ : (@div_inv_monoid.to_monoid _ mβ).one = (@div_inv_monoid.to_monoid _ mβ).one,
from congr_arg (@monoid.one M) (monoid.ext h_mul),
set f : @monoid_hom M M (by letI := mβ; apply_instance) (by letI := mβ; apply_instance) :=
{ to_fun := id, map_one' := hβ, map_mul' := Ξ» x y, congr_fun (congr_fun h_mul x) y },
have hpow : (@div_inv_monoid.to_monoid _ mβ).npow = (@div_inv_monoid.to_monoid _ mβ).npow :=
congr_arg (@monoid.npow M) (monoid.ext h_mul),
have hzpow : mβ.zpow = mβ.zpow,
{ ext m x,
exact @monoid_hom.map_zpow' M M mβ mβ f (congr_fun h_inv) x m },
have hdiv : mβ.div = mβ.div,
{ ext a b,
exact @monoid_hom.map_div' M M mβ mβ f (congr_fun h_inv) a b },
unfreezingI { cases mβ, cases mβ },
congr, exacts [h_mul, hβ, hpow, h_inv, hdiv, hzpow]
end
@[ext, to_additive]
lemma group.ext {G : Type*} β¦gβ gβ : group Gβ¦ (h_mul : gβ.mul = gβ.mul) : gβ = gβ :=
begin
set f := @monoid_hom.mk' G G (by letI := gβ; apply_instance) gβ id
(Ξ» a b, congr_fun (congr_fun h_mul a) b),
exact group.to_div_inv_monoid_injective (div_inv_monoid.ext h_mul
(funext $ @monoid_hom.map_inv G G gβ gβ f))
end
@[ext, to_additive]
lemma comm_group.ext {G : Type*} β¦gβ gβ : comm_group Gβ¦
(h_mul : gβ.mul = gβ.mul) : gβ = gβ :=
comm_group.to_group_injective $ group.ext h_mul
|
c6789dd464cf4e19436e36a0b86d54267a0e7fdf | 947b78d97130d56365ae2ec264df196ce769371a | /tests/lean/run/def18.lean | 0581c4ad62943ee0d3d9c2798747dd0def90ddca | [
"Apache-2.0"
] | permissive | shyamalschandra/lean4 | 27044812be8698f0c79147615b1d5090b9f4b037 | 6e7a883b21eaf62831e8111b251dc9b18f40e604 | refs/heads/master | 1,671,417,126,371 | 1,601,859,995,000 | 1,601,860,020,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 257 | lean | new_frontend
universe u
variable {Ξ± : Type u}
def split : List Ξ± β List Ξ± Γ List Ξ±
| [] => ([], [])
| [a] => ([a], [])
| a::b::as => (a :: (split as).1, b :: (split as).2)
theorem ex1 : split [1, 2, 3, 4, 5] = ([1, 3, 5], [2, 4]) :=
rfl
|
d5f65b13a0fcdfcf05b70bfb8ff21012ee2564e3 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/data/fin/tuple/sort.lean | ee93cbc77b8e416f4d63462f59dfc3916b060b28 | [
"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 | 2,700 | lean | /-
Copyright (c) 2021 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import data.fin.basic
import data.finset.sort
import order.lexicographic
/-!
# Sorting tuples by their values
Given an `n`-tuple `f : fin n β Ξ±` where `Ξ±` is ordered,
we may want to turn it into a sorted `n`-tuple.
This file provides an API for doing so, with the sorted `n`-tuple given by
`f β tuple.sort f`.
## Main declarations
* `tuple.sort`: given `f : fin n β Ξ±`, produces a permutation on `fin n`
* `tuple.monotone_sort`: `f β tuple.sort f` is `monotone`
-/
namespace tuple
variables {n : β}
variables {Ξ± : Type*} [linear_order Ξ±]
/--
`graph f` produces the finset of pairs `(f i, i)`
equipped with the lexicographic order.
-/
def graph (f : fin n β Ξ±) : finset (Ξ± Γβ (fin n)) :=
finset.univ.image (Ξ» i, (f i, i))
/--
Given `p : Ξ± Γβ (fin n) := (f i, i)` with `p β graph f`,
`graph.proj p` is defined to be `f i`.
-/
def graph.proj {f : fin n β Ξ±} : graph f β Ξ± := Ξ» p, p.1.1
@[simp] lemma graph.card (f : fin n β Ξ±) : (graph f).card = n :=
begin
rw [graph, finset.card_image_of_injective],
{ exact finset.card_fin _ },
{ intros _ _,
simp }
end
/--
`graph_equivβ f` is the natural equivalence between `fin n` and `graph f`,
mapping `i` to `(f i, i)`. -/
def graph_equivβ (f : fin n β Ξ±) : fin n β graph f :=
{ to_fun := Ξ» i, β¨(f i, i), by simp [graph]β©,
inv_fun := Ξ» p, p.1.2,
left_inv := Ξ» i, by simp,
right_inv := Ξ» β¨β¨x, iβ©, hβ©, by simpa [graph] using h }
@[simp] lemma proj_equivβ' (f : fin n β Ξ±) : graph.proj β graph_equivβ f = f :=
rfl
/--
`graph_equivβ f` is an equivalence between `fin n` and `graph f` that respects the order.
-/
def graph_equivβ (f : fin n β Ξ±) : fin n βo graph f :=
finset.order_iso_of_fin _ (by simp)
/-- `sort f` is the permutation that orders `fin n` according to the order of the outputs of `f`. -/
def sort (f : fin n β Ξ±) : equiv.perm (fin n) :=
(graph_equivβ f).to_equiv.trans (graph_equivβ f).symm
lemma self_comp_sort (f : fin n β Ξ±) : f β sort f = graph.proj β graph_equivβ f :=
show graph.proj β ((graph_equivβ f) β (graph_equivβ f).symm) β (graph_equivβ f).to_equiv = _,
by simp
lemma monotone_proj (f : fin n β Ξ±) : monotone (graph.proj : graph f β Ξ±) :=
begin
rintro β¨β¨x, iβ©, hxβ© β¨β¨y, jβ©, hyβ© (h|h),
{ exact le_of_lt βΉ_βΊ },
{ simp [graph.proj] },
end
lemma monotone_sort (f : fin n β Ξ±) : monotone (f β sort f) :=
begin
rw [self_comp_sort],
exact (monotone_proj f).comp (graph_equivβ f).monotone,
end
end tuple
|
ebf733a02e420e873f27440d00164df30469d764 | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/topology/algebra/open_subgroup.lean | 4af90db556483cee269483e0e8e2a35c47801893 | [
"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 | 5,909 | lean | import order.filter.lift
import linear_algebra.basic
import topology.opens topology.algebra.ring
section
open topological_space
variables (G : Type*) [group G] [topological_space G]
/-- The type of open subgroups of a topological group. -/
@[to_additive open_add_subgroup]
def open_subgroup := { U : set G // is_open U β§ is_subgroup U }
@[to_additive]
instance open_subgroup.has_coe :
has_coe (open_subgroup G) (opens G) := β¨Ξ» U, β¨U.1, U.2.1β©β©
end
-- Tell Lean that `open_add_subgroup` is a namespace
namespace open_add_subgroup
end open_add_subgroup
namespace open_subgroup
open function lattice topological_space
open_locale topological_space
variables {G : Type*} [group G] [topological_space G]
variables {U V : open_subgroup G}
@[to_additive]
instance : has_mem G (open_subgroup G) := β¨Ξ» g U, g β (U : set G)β©
@[to_additive]
lemma ext : (U = V) β ((U : set G) = V) :=
by cases U; cases V; split; intro h; try {congr}; assumption
@[ext, to_additive]
lemma ext' (h : (U : set G) = V) : (U = V) :=
ext.mpr h
@[to_additive]
lemma coe_injective : injective (Ξ» U : open_subgroup G, (U : set G)) :=
Ξ» U V h, ext' h
@[to_additive is_add_subgroup]
instance : is_subgroup (U : set G) := U.2.2
variable (U)
@[to_additive]
protected lemma is_open : is_open (U : set G) := U.2.1
@[to_additive]
protected lemma one_mem : (1 : G) β U := is_submonoid.one_mem (U : set G)
@[to_additive]
protected lemma inv_mem {g : G} (h : g β U) : gβ»ΒΉ β U :=
@is_subgroup.inv_mem G _ U _ g h
@[to_additive]
protected lemma mul_mem {gβ gβ : G} (hβ : gβ β U) (hβ : gβ β U) : gβ * gβ β U :=
@is_submonoid.mul_mem G _ U _ gβ gβ hβ hβ
@[to_additive]
lemma mem_nhds_one : (U : set G) β π (1 : G) :=
mem_nhds_sets U.is_open U.one_mem
variable {U}
@[to_additive]
instance : inhabited (open_subgroup G) :=
{ default := β¨set.univ, β¨is_open_univ, by apply_instanceβ©β© }
@[to_additive]
lemma is_open_of_nonempty_open_subset [topological_monoid G] {s : set G} [is_subgroup s]
(h : β U : opens G, nonempty U β§ (U : set G) β s) :
is_open s :=
begin
rw is_open_iff_forall_mem_open,
intros x hx,
rcases h with β¨U, β¨g, hgβ©, hUβ©,
use (Ξ» y, y * (xβ»ΒΉ * g)) β»ΒΉ' U,
split,
{ intros u hu,
erw set.mem_preimage at hu,
replace hu := hU hu,
replace hg := hU hg,
have : (xβ»ΒΉ * g)β»ΒΉ β s,
{ simp [*, is_subgroup.inv_mem, is_submonoid.mul_mem], },
convert is_submonoid.mul_mem hu this, simp [mul_assoc] },
split,
{ exact continuous_id.mul continuous_const _ U.property },
{ change x * (xβ»ΒΉ * g) β U,
convert hg,
rw [β mul_assoc, mul_right_inv, one_mul] }
end
@[to_additive is_open_of_open_add_subgroup]
lemma is_open_of_open_subgroup [topological_monoid G] {s : set G} [is_subgroup s]
(h : β U : open_subgroup G, (U : set G) β s) : is_open s :=
is_open_of_nonempty_open_subset $ let β¨U, hUβ© := h in β¨U, β¨β¨1, U.one_memβ©β©, hUβ©
@[to_additive]
lemma is_closed [topological_monoid G] (U : open_subgroup G) : is_closed (U : set G) :=
begin
show is_open (-(U : set G)),
rw is_open_iff_forall_mem_open,
intros x hx,
use (Ξ» y, y * xβ»ΒΉ) β»ΒΉ' U,
split,
{ intros u hux,
erw set.mem_preimage at hux,
rw set.mem_compl_iff at hx β’,
intro hu, apply hx,
convert is_submonoid.mul_mem (is_subgroup.inv_mem hux) hu,
simp },
split,
{ exact (continuous_mul_right _) _ U.is_open },
{ simpa using is_submonoid.one_mem (U : set G) }
end
section
variables {H : Type*} [group H] [topological_space H]
@[to_additive]
def prod (U : open_subgroup G) (V : open_subgroup H) : open_subgroup (G Γ H) :=
β¨(U : set G).prod (V : set H), is_open_prod U.is_open V.is_open, by apply_instanceβ©
end
@[to_additive]
instance : partial_order (open_subgroup G) := partial_order.lift _ coe_injective (by apply_instance)
@[to_additive]
instance : semilattice_inf_top (open_subgroup G) :=
{ inf := Ξ» U V, β¨(U : set G) β© V, is_open_inter U.is_open V.is_open, by apply_instanceβ©,
inf_le_left := Ξ» U V, set.inter_subset_left _ _,
inf_le_right := Ξ» U V, set.inter_subset_right _ _,
le_inf := Ξ» U V W hV hW, set.subset_inter hV hW,
top := default _,
le_top := Ξ» U, set.subset_univ _,
..open_subgroup.partial_order }
@[to_additive]
instance [topological_monoid G] : semilattice_sup_top (open_subgroup G) :=
{ sup := Ξ» U V,
{ val := group.closure ((U : set G) βͺ V),
property :=
begin
haveI subgrp := _, refine β¨_, subgrpβ©,
{ refine is_open_of_open_subgroup _,
exact β¨U, set.subset.trans (set.subset_union_left _ _) group.subset_closureβ© },
{ apply_instance }
end },
le_sup_left := Ξ» U V, set.subset.trans (set.subset_union_left _ _) group.subset_closure,
le_sup_right := Ξ» U V, set.subset.trans (set.subset_union_right _ _) group.subset_closure,
sup_le := Ξ» U V W hU hV, group.closure_subset $ set.union_subset hU hV,
..open_subgroup.lattice.semilattice_inf_top }
@[simp, to_additive] lemma coe_inf : (β(U β V) : set G) = (U : set G) β© V := rfl
@[to_additive] lemma le_iff : U β€ V β (U : set G) β V := iff.rfl
end open_subgroup
namespace submodule
open open_add_subgroup
variables {R : Type*} {M : Type*} [comm_ring R]
variables [add_comm_group M] [topological_space M] [topological_add_group M] [module R M]
lemma is_open_of_open_submodule {P : submodule R M}
(h : β U : submodule R M, is_open (U : set M) β§ U β€ P) : is_open (P : set M) :=
let β¨U, hβ, hββ© := h in is_open_of_open_add_subgroup β¨β¨U, hβ, by apply_instanceβ©, hββ©
end submodule
namespace ideal
variables {R : Type*} [comm_ring R]
variables [topological_space R] [topological_ring R]
lemma is_open_of_open_subideal {I : ideal R}
(h : β U : ideal R, is_open (U : set R) β§ U β€ I) : is_open (I : set R) :=
submodule.is_open_of_open_submodule h
end ideal
|
49f590099a55c8e1786275f90161fe87a5072b5e | 8eeb99d0fdf8125f5d39a0ce8631653f588ee817 | /src/measure_theory/bochner_integration.lean | 60404f3717d718374933c506f68de218ca4b865a | [
"Apache-2.0"
] | permissive | jesse-michael-han/mathlib | a15c58378846011b003669354cbab7062b893cfe | fa6312e4dc971985e6b7708d99a5bc3062485c89 | refs/heads/master | 1,625,200,760,912 | 1,602,081,753,000 | 1,602,081,753,000 | 181,787,230 | 0 | 0 | null | 1,555,460,682,000 | 1,555,460,682,000 | null | UTF-8 | Lean | false | false | 62,736 | lean | /-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov
-/
import measure_theory.simple_func_dense
import analysis.normed_space.bounded_linear_maps
import topology.sequences
/-!
# Bochner integral
The Bochner integral extends the definition of the Lebesgue integral to functions that map from a
measure space into a Banach space (complete normed vector space). It is constructed here by
extending the integral on simple functions.
## Main definitions
The Bochner integral is defined following these steps:
1. Define the integral on simple functions of the type `simple_func Ξ± E` (notation : `Ξ± ββ E`)
where `E` is a real normed space.
(See `simple_func.bintegral` and section `bintegral` for details. Also see `simple_func.integral`
for the integral on simple functions of the type `simple_func Ξ± ennreal`.)
2. Use `Ξ± ββ E` to cut out the simple functions from L1 functions, and define integral
on these. The type of simple functions in L1 space is written as `Ξ± βββ[ΞΌ] E`.
3. Show that the embedding of `Ξ± βββ[ΞΌ] E` into L1 is a dense and uniform one.
4. Show that the integral defined on `Ξ± βββ[ΞΌ] E` is a continuous linear map.
5. Define the Bochner integral on L1 functions by extending the integral on integrable simple
functions `Ξ± βββ[ΞΌ] E` using `continuous_linear_map.extend`. Define the Bochner integral on functions
as the Bochner integral of its equivalence class in L1 space.
## Main statements
1. Basic properties of the Bochner integral on functions of type `Ξ± β E`, where `Ξ±` is a measure
space and `E` is a real normed space.
* `integral_zero` : `β« 0 βΞΌ = 0`
* `integral_add` : `β« x, f x + g x βΞΌ = β« x, f βΞΌ + β« x, g x βΞΌ`
* `integral_neg` : `β« x, - f x βΞΌ = - β« x, f x βΞΌ`
* `integral_sub` : `β« x, f x - g x βΞΌ = β« x, f x βΞΌ - β« x, g x βΞΌ`
* `integral_smul` : `β« x, r β’ f x βΞΌ = r β’ β« x, f x βΞΌ`
* `integral_congr_ae` : `f =α΅[ΞΌ] g β β« x, f x βΞΌ = β« x, g x βΞΌ`
* `norm_integral_le_integral_norm` : `β₯β« x, f x βΞΌβ₯ β€ β« x, β₯f xβ₯ βΞΌ`
2. Basic properties of the Bochner integral on functions of type `Ξ± β β`, where `Ξ±` is a measure
space.
* `integral_nonneg_of_ae` : `0 β€α΅[ΞΌ] f β 0 β€ β« x, f x βΞΌ`
* `integral_nonpos_of_ae` : `f β€α΅[ΞΌ] 0 β β« x, f x βΞΌ β€ 0`
* `integral_mono_ae` : `f β€α΅[ΞΌ] g β β« x, f x βΞΌ β€ β« x, g x βΞΌ`
* `integral_nonneg` : `0 β€ f β 0 β€ β« x, f x βΞΌ`
* `integral_nonpos` : `f β€ 0 β β« x, f x βΞΌ β€ 0`
* `integral_mono` : `f β€α΅[ΞΌ] g β β« x, f x βΞΌ β€ β« x, g x βΞΌ`
3. Propositions connecting the Bochner integral with the integral on `ennreal`-valued functions,
which is called `lintegral` and has the notation `β«β»`.
* `integral_eq_lintegral_max_sub_lintegral_min` : `β« x, f x βΞΌ = β«β» x, fβΊ x βΞΌ - β«β» x, fβ» x βΞΌ`,
where `fβΊ` is the positive part of `f` and `fβ»` is the negative part of `f`.
* `integral_eq_lintegral_of_nonneg_ae` : `0 β€α΅[ΞΌ] f β β« x, f x βΞΌ = β«β» x, f x βΞΌ`
4. `tendsto_integral_of_dominated_convergence` : the Lebesgue dominated convergence theorem
## Notes
Some tips on how to prove a proposition if the API for the Bochner integral is not enough so that
you need to unfold the definition of the Bochner integral and go back to simple functions.
One method is to use the theorem `integrable.induction` in the file `set_integral`, which allows
you to prove something for an arbitrary measurable + integrable function.
Another method is using the following steps.
See `integral_eq_lintegral_max_sub_lintegral_min` for a complicated example, which proves that
`β« f = β«β» fβΊ - β«β» fβ»`, with the first integral sign being the Bochner integral of a real-valued
function `f : Ξ± β β`, and second and third integral sign being the integral on ennreal-valued
functions (called `lintegral`). The proof of `integral_eq_lintegral_max_sub_lintegral_min` is
scattered in sections with the name `pos_part`.
Here are the usual steps of proving that a property `p`, say `β« f = β«β» fβΊ - β«β» fβ»`, holds for all
functions :
1. First go to the `LΒΉ` space.
For example, if you see `ennreal.to_real (β«β» a, ennreal.of_real $ β₯f aβ₯)`, that is the norm of `f` in
`LΒΉ` space. Rewrite using `l1.norm_of_fun_eq_lintegral_norm`.
2. Show that the set `{f β LΒΉ | β« f = β«β» fβΊ - β«β» fβ»}` is closed in `LΒΉ` using `is_closed_eq`.
3. Show that the property holds for all simple functions `s` in `LΒΉ` space.
Typically, you need to convert various notions to their `simple_func` counterpart, using lemmas like
`l1.integral_coe_eq_integral`.
4. Since simple functions are dense in `LΒΉ`,
```
univ = closure {s simple}
= closure {s simple | β« s = β«β» sβΊ - β«β» sβ»} : the property holds for all simple functions
β closure {f | β« f = β«β» fβΊ - β«β» fβ»}
= {f | β« f = β«β» fβΊ - β«β» fβ»} : closure of a closed set is itself
```
Use `is_closed_property` or `dense_range.induction_on` for this argument.
## Notations
* `Ξ± ββ E` : simple functions (defined in `measure_theory/integration`)
* `Ξ± ββ[ΞΌ] E` : functions in L1 space, i.e., equivalence classes of integrable functions (defined in
`measure_theory/l1_space`)
* `Ξ± βββ[ΞΌ] E` : simple functions in L1 space, i.e., equivalence classes of integrable simple functions
Note : `β` is typed using `\_s`. Sometimes it shows as a box if font is missing.
## Tags
Bochner integral, simple function, function space, Lebesgue dominated convergence theorem
-/
noncomputable theory
open_locale classical topological_space big_operators
namespace measure_theory
variables {Ξ± E : Type*} [measurable_space Ξ±] [decidable_linear_order E] [has_zero E]
local infixr ` ββ `:25 := simple_func
namespace simple_func
section pos_part
/-- Positive part of a simple function. -/
def pos_part (f : Ξ± ββ E) : Ξ± ββ E := f.map (Ξ»b, max b 0)
/-- Negative part of a simple function. -/
def neg_part [has_neg E] (f : Ξ± ββ E) : Ξ± ββ E := pos_part (-f)
lemma pos_part_map_norm (f : Ξ± ββ β) : (pos_part f).map norm = pos_part f :=
begin
ext,
rw [map_apply, real.norm_eq_abs, abs_of_nonneg],
rw [pos_part, map_apply],
exact le_max_right _ _
end
lemma neg_part_map_norm (f : Ξ± ββ β) : (neg_part f).map norm = neg_part f :=
by { rw neg_part, exact pos_part_map_norm _ }
lemma pos_part_sub_neg_part (f : Ξ± ββ β) : f.pos_part - f.neg_part = f :=
begin
simp only [pos_part, neg_part],
ext,
exact max_zero_sub_eq_self (f a)
end
end pos_part
end simple_func
end measure_theory
namespace measure_theory
open set filter topological_space ennreal emetric
variables {Ξ± E F : Type*} [measurable_space Ξ±]
local infixr ` ββ `:25 := simple_func
namespace simple_func
section integral
/-!
### The Bochner integral of simple functions
Define the Bochner integral of simple functions of the type `Ξ± ββ Ξ²` where `Ξ²` is a normed group,
and prove basic property of this integral.
-/
open finset
variables [normed_group E] [measurable_space E] [normed_group F]
variables {ΞΌ : measure Ξ±}
/-- For simple functions with a `normed_group` as codomain, being integrable is the same as having
finite volume support. -/
lemma integrable_iff_fin_meas_supp {f : Ξ± ββ E} {ΞΌ : measure Ξ±} :
integrable f ΞΌ β f.fin_meas_supp ΞΌ :=
calc integrable f ΞΌ β β«β» x, f.map (coe β nnnorm : E β ennreal) x βΞΌ < β€ : and_iff_right f.measurable
... β (f.map (coe β nnnorm : E β ennreal)).lintegral ΞΌ < β€ : by rw lintegral_eq_lintegral
... β (f.map (coe β nnnorm : E β ennreal)).fin_meas_supp ΞΌ : iff.symm $
fin_meas_supp.iff_lintegral_lt_top $ eventually_of_forall $ Ξ» x, coe_lt_top
... β _ : fin_meas_supp.map_iff $ Ξ» b, coe_eq_zero.trans nnnorm_eq_zero
lemma fin_meas_supp.integrable {f : Ξ± ββ E} (h : f.fin_meas_supp ΞΌ) : integrable f ΞΌ :=
integrable_iff_fin_meas_supp.2 h
lemma integrable_pair [measurable_space F] {f : Ξ± ββ E} {g : Ξ± ββ F} :
integrable f ΞΌ β integrable g ΞΌ β integrable (pair f g) ΞΌ :=
by simpa only [integrable_iff_fin_meas_supp] using fin_meas_supp.pair
variables [normed_space β F]
/-- Bochner integral of simple functions whose codomain is a real `normed_space`. -/
def integral (ΞΌ : measure Ξ±) (f : Ξ± ββ F) : F :=
β x in f.range, (ennreal.to_real (ΞΌ (f β»ΒΉ' {x}))) β’ x
lemma integral_eq_sum_filter (f : Ξ± ββ F) (ΞΌ) :
f.integral ΞΌ = β x in f.range.filter (Ξ» x, x β 0), (ennreal.to_real (ΞΌ (f β»ΒΉ' {x}))) β’ x :=
eq.symm $ sum_filter_of_ne $ Ξ» x _, mt $ Ξ» h0, h0.symm βΈ smul_zero _
/-- Calculate the integral of `g β f : Ξ± ββ F`, where `f` is an integrable function from `Ξ±` to `E`
and `g` is a function from `E` to `F`. We require `g 0 = 0` so that `g β f` is integrable. -/
lemma map_integral (f : Ξ± ββ E) (g : E β F) (hf : integrable f ΞΌ) (hg : g 0 = 0) :
(f.map g).integral ΞΌ = β x in f.range, (ennreal.to_real (ΞΌ (f β»ΒΉ' {x}))) β’ (g x) :=
begin
-- We start as in the proof of `map_lintegral`
simp only [integral, range_map],
refine finset.sum_image' _ (assume b hb, _),
rcases mem_range.1 hb with β¨a, rflβ©,
rw [map_preimage_singleton, β sum_measure_preimage_singleton _
(Ξ» _ _, f.is_measurable_preimage _)],
-- Now we use `hf : integrable f ΞΌ` to show that `ennreal.to_real` is additive.
by_cases ha : g (f a) = 0,
{ simp only [ha, smul_zero],
refine (sum_eq_zero $ Ξ» x hx, _).symm,
simp only [mem_filter] at hx,
simp [hx.2] },
{ rw [to_real_sum, sum_smul],
{ refine sum_congr rfl (Ξ» x hx, _),
simp only [mem_filter] at hx,
rw [hx.2] },
{ intros x hx,
simp only [mem_filter] at hx,
refine (integrable_iff_fin_meas_supp.1 hf).meas_preimage_singleton_ne_zero _,
exact Ξ» h0, ha (hx.2 βΈ h0.symm βΈ hg) } },
end
/-- `simple_func.integral` and `simple_func.lintegral` agree when the integrand has type
`Ξ± ββ ennreal`. But since `ennreal` is not a `normed_space`, we need some form of coercion.
See `integral_eq_lintegral` for a simpler version. -/
lemma integral_eq_lintegral' {f : Ξ± ββ E} {g : E β ennreal} (hf : integrable f ΞΌ) (hg0 : g 0 = 0)
(hgt : βb, g b < β€):
(f.map (ennreal.to_real β g)).integral ΞΌ = ennreal.to_real (β«β» a, g (f a) βΞΌ) :=
begin
have hf' : f.fin_meas_supp ΞΌ := integrable_iff_fin_meas_supp.1 hf,
simp only [β map_apply g f, lintegral_eq_lintegral],
rw [map_integral f _ hf, map_lintegral, ennreal.to_real_sum],
{ refine finset.sum_congr rfl (Ξ»b hb, _),
rw [smul_eq_mul, to_real_mul_to_real, mul_comm] },
{ assume a ha,
by_cases a0 : a = 0,
{ rw [a0, hg0, zero_mul], exact with_top.zero_lt_top },
{ apply mul_lt_top (hgt a) (hf'.meas_preimage_singleton_ne_zero a0) } },
{ simp [hg0] }
end
variables [normed_space β E]
lemma integral_congr {f g : Ξ± ββ E} (hf : integrable f ΞΌ) (h : f =α΅[ΞΌ] g):
f.integral ΞΌ = g.integral ΞΌ :=
show ((pair f g).map prod.fst).integral ΞΌ = ((pair f g).map prod.snd).integral ΞΌ, from
begin
have inte := integrable_pair hf (hf.congr g.measurable h),
rw [map_integral (pair f g) _ inte prod.fst_zero, map_integral (pair f g) _ inte prod.snd_zero],
refine finset.sum_congr rfl (assume p hp, _),
rcases mem_range.1 hp with β¨a, rflβ©,
by_cases eq : f a = g a,
{ dsimp only [pair_apply], rw eq },
{ have : ΞΌ ((pair f g) β»ΒΉ' {(f a, g a)}) = 0,
{ refine measure_mono_null (assume a' ha', _) h,
simp only [set.mem_preimage, mem_singleton_iff, pair_apply, prod.mk.inj_iff] at ha',
show f a' β g a',
rwa [ha'.1, ha'.2] },
simp only [this, pair_apply, zero_smul, ennreal.zero_to_real] },
end
/-- `simple_func.bintegral` and `simple_func.integral` agree when the integrand has type
`Ξ± ββ ennreal`. But since `ennreal` is not a `normed_space`, we need some form of coercion. -/
lemma integral_eq_lintegral {f : Ξ± ββ β} (hf : integrable f ΞΌ) (h_pos : 0 β€α΅[ΞΌ] f) :
f.integral ΞΌ = ennreal.to_real (β«β» a, ennreal.of_real (f a) βΞΌ) :=
begin
have : f =α΅[ΞΌ] f.map (ennreal.to_real β ennreal.of_real) :=
h_pos.mono (Ξ» a h, (ennreal.to_real_of_real h).symm),
rw [β integral_eq_lintegral' hf],
{ exact integral_congr hf this },
{ exact ennreal.of_real_zero },
{ assume b, rw ennreal.lt_top_iff_ne_top, exact ennreal.of_real_ne_top }
end
lemma integral_add {f g : Ξ± ββ E} (hf : integrable f ΞΌ) (hg : integrable g ΞΌ) :
integral ΞΌ (f + g) = integral ΞΌ f + integral ΞΌ g :=
calc integral ΞΌ (f + g) = β x in (pair f g).range,
ennreal.to_real (ΞΌ ((pair f g) β»ΒΉ' {x})) β’ (x.fst + x.snd) :
begin
rw [add_eq_mapβ, map_integral (pair f g)],
{ exact integrable_pair hf hg },
{ simp only [add_zero, prod.fst_zero, prod.snd_zero] }
end
... = β x in (pair f g).range,
(ennreal.to_real (ΞΌ ((pair f g) β»ΒΉ' {x})) β’ x.fst +
ennreal.to_real (ΞΌ ((pair f g) β»ΒΉ' {x})) β’ x.snd) :
finset.sum_congr rfl $ assume a ha, smul_add _ _ _
... = β x in (pair f g).range,
ennreal.to_real (ΞΌ ((pair f g) β»ΒΉ' {x})) β’ x.fst +
β x in (pair f g).range,
ennreal.to_real (ΞΌ ((pair f g) β»ΒΉ' {x})) β’ x.snd :
by rw finset.sum_add_distrib
... = ((pair f g).map prod.fst).integral ΞΌ + ((pair f g).map prod.snd).integral ΞΌ :
begin
rw [map_integral (pair f g), map_integral (pair f g)],
{ exact integrable_pair hf hg }, { refl },
{ exact integrable_pair hf hg }, { refl }
end
... = integral ΞΌ f + integral ΞΌ g : rfl
lemma integral_neg {f : Ξ± ββ E} (hf : integrable f ΞΌ) : integral ΞΌ (-f) = - integral ΞΌ f :=
calc integral ΞΌ (-f) = integral ΞΌ (f.map (has_neg.neg)) : rfl
... = - integral ΞΌ f :
begin
rw [map_integral f _ hf neg_zero, integral, β sum_neg_distrib],
refine finset.sum_congr rfl (Ξ»x h, smul_neg _ _),
end
lemma integral_sub [borel_space E] {f g : Ξ± ββ E} (hf : integrable f ΞΌ) (hg : integrable g ΞΌ) :
integral ΞΌ (f - g) = integral ΞΌ f - integral ΞΌ g :=
begin
rw [sub_eq_add_neg, integral_add hf, integral_neg hg, sub_eq_add_neg],
exact hg.neg
end
lemma integral_smul (r : β) {f : Ξ± ββ E} (hf : integrable f ΞΌ) :
integral ΞΌ (r β’ f) = r β’ integral ΞΌ f :=
calc integral ΞΌ (r β’ f) = β x in f.range, ennreal.to_real (ΞΌ (f β»ΒΉ' {x})) β’ r β’ x :
by rw [smul_eq_map r f, map_integral f _ hf (smul_zero _)]
... = β x in f.range, ((ennreal.to_real (ΞΌ (f β»ΒΉ' {x}))) * r) β’ x :
finset.sum_congr rfl $ Ξ»b hb, by apply smul_smul
... = r β’ integral ΞΌ f :
by simp only [integral, smul_sum, smul_smul, mul_comm]
lemma norm_integral_le_integral_norm (f : Ξ± ββ E) (hf : integrable f ΞΌ) :
β₯f.integral ΞΌβ₯ β€ (f.map norm).integral ΞΌ :=
begin
rw [map_integral f norm hf norm_zero, integral],
calc β₯β x in f.range, ennreal.to_real (ΞΌ (f β»ΒΉ' {x})) β’ xβ₯ β€
β x in f.range, β₯ennreal.to_real (ΞΌ (f β»ΒΉ' {x})) β’ xβ₯ :
norm_sum_le _ _
... = β x in f.range, ennreal.to_real (ΞΌ (f β»ΒΉ' {x})) β’ β₯xβ₯ :
begin
refine finset.sum_congr rfl (Ξ»b hb, _),
rw [norm_smul, smul_eq_mul, real.norm_eq_abs, abs_of_nonneg to_real_nonneg]
end
end
lemma integral_add_measure {Ξ½} (f : Ξ± ββ E) (hf : integrable f (ΞΌ + Ξ½)) :
f.integral (ΞΌ + Ξ½) = f.integral ΞΌ + f.integral Ξ½ :=
begin
simp only [integral_eq_sum_filter, β sum_add_distrib, β add_smul, measure.add_apply],
refine sum_congr rfl (Ξ» x hx, _),
rw [to_real_add];
refine ne_of_lt ((integrable_iff_fin_meas_supp.1 _).meas_preimage_singleton_ne_zero
(mem_filter.1 hx).2),
exacts [hf.left_of_add_measure, hf.right_of_add_measure]
end
end integral
end simple_func
namespace l1
open ae_eq_fun
variables
[normed_group E] [second_countable_topology E] [measurable_space E] [borel_space E]
[normed_group F] [second_countable_topology F] [measurable_space F] [borel_space F]
{ΞΌ : measure Ξ±}
variables (Ξ± E ΞΌ)
-- We use `Type*` instead of `add_subgroup` because otherwise we loose dot notation.
/-- `l1.simple_func` is a subspace of L1 consisting of equivalence classes of an integrable simple
function. -/
def simple_func : Type* :=
β₯({ carrier := {f : Ξ± ββ[ΞΌ] E | β (s : Ξ± ββ E), (ae_eq_fun.mk s s.measurable : Ξ± ββ[ΞΌ] E) = f},
zero_mem' := β¨0, rflβ©,
add_mem' := Ξ» f g β¨s, hsβ© β¨t, htβ©,
β¨s + t, by simp only [coe_add, β hs, β ht, mk_add_mk, β simple_func.coe_add]β©,
neg_mem' := Ξ» f β¨s, hsβ©, β¨-s, by simp only [coe_neg, β hs, neg_mk, β simple_func.coe_neg]β© } :
add_subgroup (Ξ± ββ[ΞΌ] E))
variables {Ξ± E ΞΌ}
notation Ξ± ` βββ[`:25 ΞΌ `] ` E := measure_theory.l1.simple_func Ξ± E ΞΌ
namespace simple_func
section instances
/-! Simple functions in L1 space form a `normed_space`. -/
instance : has_coe (Ξ± βββ[ΞΌ] E) (Ξ± ββ[ΞΌ] E) := coe_subtype
instance : has_coe_to_fun (Ξ± βββ[ΞΌ] E) := β¨Ξ» f, Ξ± β E, Ξ» f, β(f : Ξ± ββ[ΞΌ] E)β©
@[simp, norm_cast] lemma coe_coe (f : Ξ± βββ[ΞΌ] E) : β(f : Ξ± ββ[ΞΌ] E) = f := rfl
protected lemma eq {f g : Ξ± βββ[ΞΌ] E} : (f : Ξ± ββ[ΞΌ] E) = (g : Ξ± ββ[ΞΌ] E) β f = g := subtype.eq
protected lemma eq' {f g : Ξ± βββ[ΞΌ] E} : (f : Ξ± ββ[ΞΌ] E) = (g : Ξ± ββ[ΞΌ] E) β f = g := subtype.eq β subtype.eq
@[norm_cast] protected lemma eq_iff {f g : Ξ± βββ[ΞΌ] E} : (f : Ξ± ββ[ΞΌ] E) = g β f = g :=
subtype.ext_iff.symm
@[norm_cast] protected lemma eq_iff' {f g : Ξ± βββ[ΞΌ] E} : (f : Ξ± ββ[ΞΌ] E) = g β f = g :=
iff.intro (simple_func.eq') (congr_arg _)
/-- L1 simple functions forms a `emetric_space`, with the emetric being inherited from L1 space,
i.e., `edist f g = β«β» a, edist (f a) (g a)`.
Not declared as an instance as `Ξ± βββ[ΞΌ] Ξ²` will only be useful in the construction of the bochner
integral. -/
protected def emetric_space : emetric_space (Ξ± βββ[ΞΌ] E) := subtype.emetric_space
/-- L1 simple functions forms a `metric_space`, with the metric being inherited from L1 space,
i.e., `dist f g = ennreal.to_real (β«β» a, edist (f a) (g a)`).
Not declared as an instance as `Ξ± βββ[ΞΌ] Ξ²` will only be useful in the construction of the bochner
integral. -/
protected def metric_space : metric_space (Ξ± βββ[ΞΌ] E) := subtype.metric_space
local attribute [instance] simple_func.metric_space simple_func.emetric_space
/-- Functions `Ξ± βββ[ΞΌ] E` form an additive commutative group. -/
local attribute [instance, priority 10000]
protected def add_comm_group : add_comm_group (Ξ± βββ[ΞΌ] E) := add_subgroup.to_add_comm_group _
instance : inhabited (Ξ± βββ[ΞΌ] E) := β¨0β©
@[simp, norm_cast] lemma coe_zero : ((0 : Ξ± βββ[ΞΌ] E) : Ξ± ββ[ΞΌ] E) = 0 := rfl
@[simp, norm_cast] lemma coe_add (f g : Ξ± βββ[ΞΌ] E) : ((f + g : Ξ± βββ[ΞΌ] E) : Ξ± ββ[ΞΌ] E) = f + g := rfl
@[simp, norm_cast] lemma coe_neg (f : Ξ± βββ[ΞΌ] E) : ((-f : Ξ± βββ[ΞΌ] E) : Ξ± ββ[ΞΌ] E) = -f := rfl
@[simp, norm_cast] lemma coe_sub (f g : Ξ± βββ[ΞΌ] E) : ((f - g : Ξ± βββ[ΞΌ] E) : Ξ± ββ[ΞΌ] E) = f - g := rfl
@[simp] lemma edist_eq (f g : Ξ± βββ[ΞΌ] E) : edist f g = edist (f : Ξ± ββ[ΞΌ] E) (g : Ξ± ββ[ΞΌ] E) := rfl
@[simp] lemma dist_eq (f g : Ξ± βββ[ΞΌ] E) : dist f g = dist (f : Ξ± ββ[ΞΌ] E) (g : Ξ± ββ[ΞΌ] E) := rfl
/-- The norm on `Ξ± βββ[ΞΌ] E` is inherited from L1 space. That is, `β₯fβ₯ = β«β» a, edist (f a) 0`.
Not declared as an instance as `Ξ± βββ[ΞΌ] E` will only be useful in the construction of the bochner
integral. -/
protected def has_norm : has_norm (Ξ± βββ[ΞΌ] E) := β¨Ξ»f, β₯(f : Ξ± ββ[ΞΌ] E)β₯β©
local attribute [instance] simple_func.has_norm
lemma norm_eq (f : Ξ± βββ[ΞΌ] E) : β₯fβ₯ = β₯(f : Ξ± ββ[ΞΌ] E)β₯ := rfl
lemma norm_eq' (f : Ξ± βββ[ΞΌ] E) : β₯fβ₯ = ennreal.to_real (edist (f : Ξ± ββ[ΞΌ] E) 0) := rfl
/-- Not declared as an instance as `Ξ± βββ[ΞΌ] E` will only be useful in the construction of the bochner
integral. -/
protected def normed_group : normed_group (Ξ± βββ[ΞΌ] E) :=
normed_group.of_add_dist (Ξ» x, rfl) $ by
{ intros, simp only [dist_eq, coe_add, l1.dist_eq, l1.coe_add], rw edist_add_right }
variables {π : Type*} [normed_field π] [normed_space π E]
/-- Not declared as an instance as `Ξ± βββ[ΞΌ] E` will only be useful in the construction of the bochner
integral. -/
protected def has_scalar : has_scalar π (Ξ± βββ[ΞΌ] E) := β¨Ξ»k f, β¨k β’ f,
begin
rcases f with β¨f, β¨s, hsβ©β©,
use k β’ s,
rw [coe_smul, subtype.coe_mk, β hs], refl
end β©β©
local attribute [instance, priority 10000] simple_func.has_scalar
@[simp, norm_cast] lemma coe_smul (c : π) (f : Ξ± βββ[ΞΌ] E) :
((c β’ f : Ξ± βββ[ΞΌ] E) : Ξ± ββ[ΞΌ] E) = c β’ (f : Ξ± ββ[ΞΌ] E) := rfl
/-- Not declared as an instance as `Ξ± βββ[ΞΌ] E` will only be useful in the construction of the bochner
integral. -/
protected def semimodule : semimodule π (Ξ± βββ[ΞΌ] E) :=
{ one_smul := Ξ»f, simple_func.eq (by { simp only [coe_smul], exact one_smul _ _ }),
mul_smul := Ξ»x y f, simple_func.eq (by { simp only [coe_smul], exact mul_smul _ _ _ }),
smul_add := Ξ»x f g, simple_func.eq (by { simp only [coe_smul, coe_add], exact smul_add _ _ _ }),
smul_zero := Ξ»x, simple_func.eq (by { simp only [coe_zero, coe_smul], exact smul_zero _ }),
add_smul := Ξ»x y f, simple_func.eq (by { simp only [coe_smul], exact add_smul _ _ _ }),
zero_smul := Ξ»f, simple_func.eq (by { simp only [coe_smul], exact zero_smul _ _ }) }
local attribute [instance] simple_func.normed_group simple_func.semimodule
/-- Not declared as an instance as `Ξ± βββ[ΞΌ] E` will only be useful in the construction of the bochner
integral. -/
protected def normed_space : normed_space π (Ξ± βββ[ΞΌ] E) :=
β¨ Ξ»c f, by { rw [norm_eq, norm_eq, coe_smul, norm_smul] } β©
end instances
local attribute [instance] simple_func.normed_group simple_func.normed_space
section of_simple_func
/-- Construct the equivalence class `[f]` of an integrable simple function `f`. -/
@[reducible] def of_simple_func (f : Ξ± ββ E) (hf : integrable f ΞΌ) : (Ξ± βββ[ΞΌ] E) :=
β¨l1.of_fun f hf, β¨f, rflβ©β©
lemma of_simple_func_eq_of_fun (f : Ξ± ββ E) (hf : integrable f ΞΌ) :
(of_simple_func f hf : Ξ± ββ[ΞΌ] E) = l1.of_fun f hf := rfl
lemma of_simple_func_eq_mk (f : Ξ± ββ E) (hf : integrable f ΞΌ) :
(of_simple_func f hf : Ξ± ββ[ΞΌ] E) = ae_eq_fun.mk f f.measurable := rfl
lemma of_simple_func_zero : of_simple_func (0 : Ξ± ββ E) (integrable_zero Ξ± E ΞΌ) = 0 := rfl
lemma of_simple_func_add (f g : Ξ± ββ E) (hf : integrable f ΞΌ) (hg : integrable g ΞΌ) :
of_simple_func (f + g) (hf.add hg) = of_simple_func f hf + of_simple_func g hg := rfl
lemma of_simple_func_neg (f : Ξ± ββ E) (hf : integrable f ΞΌ) :
of_simple_func (-f) hf.neg = -of_simple_func f hf := rfl
lemma of_simple_func_sub (f g : Ξ± ββ E) (hf : integrable f ΞΌ) (hg : integrable g ΞΌ) :
of_simple_func (f - g) (hf.sub hg) = of_simple_func f hf - of_simple_func g hg := rfl
variables {π : Type*} [normed_field π] [normed_space π E]
lemma of_simple_func_smul (f : Ξ± ββ E) (hf : integrable f ΞΌ) (c : π) :
of_simple_func (c β’ f) (hf.smul c) = c β’ of_simple_func f hf := rfl
lemma norm_of_simple_func (f : Ξ± ββ E) (hf : integrable f ΞΌ) :
β₯of_simple_func f hfβ₯ = ennreal.to_real (β«β» a, edist (f a) 0 βΞΌ) :=
rfl
end of_simple_func
section to_simple_func
/-- Find a representative of a `l1.simple_func`. -/
def to_simple_func (f : Ξ± βββ[ΞΌ] E) : Ξ± ββ E := classical.some f.2
/-- `f.to_simple_func` is measurable. -/
protected lemma measurable (f : Ξ± βββ[ΞΌ] E) : measurable f.to_simple_func :=
f.to_simple_func.measurable
/-- `f.to_simple_func` is integrable. -/
protected lemma integrable (f : Ξ± βββ[ΞΌ] E) : integrable f.to_simple_func ΞΌ :=
let h := classical.some_spec f.2 in (integrable_mk f.measurable).1 $ h.symm βΈ (f : Ξ± ββ[ΞΌ] E).2
lemma of_simple_func_to_simple_func (f : Ξ± βββ[ΞΌ] E) :
of_simple_func (f.to_simple_func) f.integrable = f :=
by { rw β simple_func.eq_iff', exact classical.some_spec f.2 }
lemma to_simple_func_of_simple_func (f : Ξ± ββ E) (hfi : integrable f ΞΌ) :
(of_simple_func f hfi).to_simple_func =α΅[ΞΌ] f :=
by { rw β mk_eq_mk, exact classical.some_spec (of_simple_func f hfi).2 }
lemma to_simple_func_eq_to_fun (f : Ξ± βββ[ΞΌ] E) : f.to_simple_func =α΅[ΞΌ] f :=
begin
rw [β of_fun_eq_of_fun f.to_simple_func f f.integrable (f : Ξ± ββ[ΞΌ] E).integrable, β l1.eq_iff],
simp only [of_fun_eq_mk, β coe_coe, mk_to_fun],
exact classical.some_spec f.coe_prop
end
variables (Ξ± E)
lemma zero_to_simple_func : (0 : Ξ± βββ[ΞΌ] E).to_simple_func =α΅[ΞΌ] 0 :=
begin
filter_upwards [to_simple_func_eq_to_fun (0 : Ξ± βββ[ΞΌ] E), l1.zero_to_fun Ξ± E],
simp only [mem_set_of_eq],
assume a h,
rw h,
exact id
end
variables {Ξ± E}
lemma add_to_simple_func (f g : Ξ± βββ[ΞΌ] E) :
(f + g).to_simple_func =α΅[ΞΌ] f.to_simple_func + g.to_simple_func :=
begin
filter_upwards [to_simple_func_eq_to_fun (f + g), to_simple_func_eq_to_fun f,
to_simple_func_eq_to_fun g, l1.add_to_fun (f : Ξ± ββ[ΞΌ] E) g],
assume a,
simp only [mem_set_of_eq, β coe_coe, coe_add, pi.add_apply],
iterate 4 { assume h, rw h }
end
lemma neg_to_simple_func (f : Ξ± βββ[ΞΌ] E) : (-f).to_simple_func =α΅[ΞΌ] - f.to_simple_func :=
begin
filter_upwards [to_simple_func_eq_to_fun (-f), to_simple_func_eq_to_fun f,
l1.neg_to_fun (f : Ξ± ββ[ΞΌ] E)],
assume a,
simp only [mem_set_of_eq, pi.neg_apply, coe_neg, β coe_coe],
repeat { assume h, rw h }
end
lemma sub_to_simple_func (f g : Ξ± βββ[ΞΌ] E) :
(f - g).to_simple_func =α΅[ΞΌ] f.to_simple_func - g.to_simple_func :=
begin
filter_upwards [to_simple_func_eq_to_fun (f - g), to_simple_func_eq_to_fun f,
to_simple_func_eq_to_fun g, l1.sub_to_fun (f : Ξ± ββ[ΞΌ] E) g],
assume a,
simp only [mem_set_of_eq, coe_sub, pi.sub_apply, β coe_coe],
repeat { assume h, rw h }
end
variables {π : Type*} [normed_field π] [normed_space π E]
lemma smul_to_simple_func (k : π) (f : Ξ± βββ[ΞΌ] E) :
(k β’ f).to_simple_func =α΅[ΞΌ] k β’ f.to_simple_func :=
begin
filter_upwards [to_simple_func_eq_to_fun (k β’ f), to_simple_func_eq_to_fun f,
l1.smul_to_fun k (f : Ξ± ββ[ΞΌ] E)],
assume a,
simp only [mem_set_of_eq, pi.smul_apply, coe_smul, β coe_coe],
repeat { assume h, rw h }
end
lemma lintegral_edist_to_simple_func_lt_top (f g : Ξ± βββ[ΞΌ] E) :
β«β» (x : Ξ±), edist ((to_simple_func f) x) ((to_simple_func g) x) βΞΌ < β€ :=
begin
rw lintegral_rwβ (to_simple_func_eq_to_fun f) (to_simple_func_eq_to_fun g),
exact lintegral_edist_to_fun_lt_top _ _
end
lemma dist_to_simple_func (f g : Ξ± βββ[ΞΌ] E) : dist f g =
ennreal.to_real (β«β» x, edist (f.to_simple_func x) (g.to_simple_func x) βΞΌ) :=
begin
rw [dist_eq, l1.dist_to_fun, ennreal.to_real_eq_to_real],
{ rw lintegral_rwβ, repeat { exact ae_eq_symm (to_simple_func_eq_to_fun _) } },
{ exact l1.lintegral_edist_to_fun_lt_top _ _ },
{ exact lintegral_edist_to_simple_func_lt_top _ _ }
end
lemma norm_to_simple_func (f : Ξ± βββ[ΞΌ] E) :
β₯fβ₯ = ennreal.to_real (β«β» (a : Ξ±), nnnorm ((to_simple_func f) a) βΞΌ) :=
calc β₯fβ₯ = ennreal.to_real (β«β»x, edist (f.to_simple_func x) ((0 : Ξ± βββ[ΞΌ] E).to_simple_func x) βΞΌ) :
begin
rw [β dist_zero_right, dist_to_simple_func]
end
... = ennreal.to_real (β«β» (x : Ξ±), (coe β nnnorm) (f.to_simple_func x) βΞΌ) :
begin
rw lintegral_nnnorm_eq_lintegral_edist,
have : β«β» x, edist ((to_simple_func f) x) ((to_simple_func (0 : Ξ± βββ[ΞΌ] E)) x) βΞΌ =
β«β» x, edist ((to_simple_func f) x) 0 βΞΌ,
{ refine lintegral_congr_ae ((zero_to_simple_func Ξ± E).mono (Ξ» a h, _)),
rw [h, pi.zero_apply] },
rw [ennreal.to_real_eq_to_real],
{ exact this },
{ exact lintegral_edist_to_simple_func_lt_top _ _ },
{ rw β this, exact lintegral_edist_to_simple_func_lt_top _ _ }
end
lemma norm_eq_integral (f : Ξ± βββ[ΞΌ] E) : β₯fβ₯ = (f.to_simple_func.map norm).integral ΞΌ :=
-- calc β₯fβ₯ = ennreal.to_real (β«β» (x : Ξ±), (coe β nnnorm) (f.to_simple_func x) βΞΌ) :
-- by { rw norm_to_simple_func }
-- ... = (f.to_simple_func.map norm).integral ΞΌ :
begin
rw [norm_to_simple_func, simple_func.integral_eq_lintegral],
{ simp only [simple_func.map_apply, of_real_norm_eq_coe_nnnorm] },
{ exact f.integrable.norm },
{ exact eventually_of_forall (Ξ» x, norm_nonneg _) }
end
end to_simple_func
section coe_to_l1
protected lemma uniform_continuous : uniform_continuous (coe : (Ξ± βββ[ΞΌ] E) β (Ξ± ββ[ΞΌ] E)) :=
uniform_continuous_comap
protected lemma uniform_embedding : uniform_embedding (coe : (Ξ± βββ[ΞΌ] E) β (Ξ± ββ[ΞΌ] E)) :=
uniform_embedding_comap subtype.val_injective
protected lemma uniform_inducing : uniform_inducing (coe : (Ξ± βββ[ΞΌ] E) β (Ξ± ββ[ΞΌ] E)) :=
simple_func.uniform_embedding.to_uniform_inducing
protected lemma dense_embedding : dense_embedding (coe : (Ξ± βββ[ΞΌ] E) β (Ξ± ββ[ΞΌ] E)) :=
begin
apply simple_func.uniform_embedding.dense_embedding,
rintros β¨β¨f, hfmβ©, hfiβ©,
rw mem_closure_iff_seq_limit,
have hfi' := (integrable_mk hfm).1 hfi,
refine β¨Ξ» n, β(of_simple_func (simple_func.approx_on f hfm univ 0 trivial n)
(simple_func.integrable_approx_on_univ hfi' n)), Ξ» n, mem_range_self _, _β©,
rw tendsto_iff_edist_tendsto_0,
simpa [edist_mk_mk] using simple_func.tendsto_approx_on_univ_l1_edist hfi'
end
protected lemma dense_inducing : dense_inducing (coe : (Ξ± βββ[ΞΌ] E) β (Ξ± ββ[ΞΌ] E)) :=
simple_func.dense_embedding.to_dense_inducing
protected lemma dense_range : dense_range (coe : (Ξ± βββ[ΞΌ] E) β (Ξ± ββ[ΞΌ] E)) :=
simple_func.dense_inducing.dense
variables (π : Type*) [normed_field π] [normed_space π E]
variables (Ξ± E)
/-- The uniform and dense embedding of L1 simple functions into L1 functions. -/
def coe_to_l1 : (Ξ± βββ[ΞΌ] E) βL[π] (Ξ± ββ[ΞΌ] E) :=
{ to_fun := (coe : (Ξ± βββ[ΞΌ] E) β (Ξ± ββ[ΞΌ] E)),
map_add' := Ξ»f g, rfl,
map_smul' := Ξ»k f, rfl,
cont := l1.simple_func.uniform_continuous.continuous, }
variables {Ξ± E π}
end coe_to_l1
section pos_part
/-- Positive part of a simple function in L1 space. -/
def pos_part (f : Ξ± βββ[ΞΌ] β) : Ξ± βββ[ΞΌ] β := β¨l1.pos_part (f : Ξ± ββ[ΞΌ] β),
begin
rcases f with β¨f, s, hsfβ©,
use s.pos_part,
simp only [subtype.coe_mk, l1.coe_pos_part, β hsf, ae_eq_fun.pos_part_mk, simple_func.pos_part,
simple_func.coe_map]
end β©
/-- Negative part of a simple function in L1 space. -/
def neg_part (f : Ξ± βββ[ΞΌ] β) : Ξ± βββ[ΞΌ] β := pos_part (-f)
@[norm_cast] lemma coe_pos_part (f : Ξ± βββ[ΞΌ] β) : (f.pos_part : Ξ± ββ[ΞΌ] β) = (f : Ξ± ββ[ΞΌ] β).pos_part := rfl
@[norm_cast] lemma coe_neg_part (f : Ξ± βββ[ΞΌ] β) : (f.neg_part : Ξ± ββ[ΞΌ] β) = (f : Ξ± ββ[ΞΌ] β).neg_part := rfl
end pos_part
section simple_func_integral
/-! Define the Bochner integral on `Ξ± βββ[ΞΌ] E` and prove basic properties of this integral. -/
variables [normed_space β E]
/-- The Bochner integral over simple functions in l1 space. -/
def integral (f : Ξ± βββ[ΞΌ] E) : E := (f.to_simple_func).integral ΞΌ
lemma integral_eq_integral (f : Ξ± βββ[ΞΌ] E) : integral f = (f.to_simple_func).integral ΞΌ := rfl
lemma integral_eq_lintegral {f : Ξ± βββ[ΞΌ] β} (h_pos : 0 β€α΅[ΞΌ] f.to_simple_func) :
integral f = ennreal.to_real (β«β» a, ennreal.of_real (f.to_simple_func a) βΞΌ) :=
by rw [integral, simple_func.integral_eq_lintegral f.integrable h_pos]
lemma integral_congr {f g : Ξ± βββ[ΞΌ] E} (h : f.to_simple_func =α΅[ΞΌ] g.to_simple_func) :
integral f = integral g :=
simple_func.integral_congr f.integrable h
lemma integral_add (f g : Ξ± βββ[ΞΌ] E) : integral (f + g) = integral f + integral g :=
begin
simp only [integral],
rw β simple_func.integral_add f.integrable g.integrable,
apply measure_theory.simple_func.integral_congr (f + g).integrable,
apply add_to_simple_func
end
lemma integral_smul (r : β) (f : Ξ± βββ[ΞΌ] E) : integral (r β’ f) = r β’ integral f :=
begin
simp only [integral],
rw β simple_func.integral_smul _ f.integrable,
apply measure_theory.simple_func.integral_congr (r β’ f).integrable,
apply smul_to_simple_func
end
lemma norm_integral_le_norm (f : Ξ± βββ[ΞΌ] E) : β₯ integral f β₯ β€ β₯fβ₯ :=
begin
rw [integral, norm_eq_integral],
exact f.to_simple_func.norm_integral_le_integral_norm f.integrable
end
/-- The Bochner integral over simple functions in l1 space as a continuous linear map. -/
def integral_clm : (Ξ± βββ[ΞΌ] E) βL[β] E :=
linear_map.mk_continuous β¨integral, integral_add, integral_smulβ©
1 (Ξ»f, le_trans (norm_integral_le_norm _) $ by rw one_mul)
local notation `Integral` := @integral_clm Ξ± E _ _ _ _ _ ΞΌ _
open continuous_linear_map
lemma norm_Integral_le_one : β₯Integralβ₯ β€ 1 :=
linear_map.mk_continuous_norm_le _ (zero_le_one) _
section pos_part
lemma pos_part_to_simple_func (f : Ξ± βββ[ΞΌ] β) :
f.pos_part.to_simple_func =α΅[ΞΌ] f.to_simple_func.pos_part :=
begin
have eq : β a, f.to_simple_func.pos_part a = max (f.to_simple_func a) 0 := Ξ»a, rfl,
have ae_eq : βα΅ a βΞΌ, f.pos_part.to_simple_func a = max (f.to_simple_func a) 0,
{ filter_upwards [to_simple_func_eq_to_fun f.pos_part, pos_part_to_fun (f : Ξ± ββ[ΞΌ] β),
to_simple_func_eq_to_fun f],
simp only [mem_set_of_eq],
assume a hβ hβ hβ,
rw [hβ, β coe_coe, coe_pos_part, hβ, coe_coe, β hβ] },
refine ae_eq.mono (assume a h, _),
rw [h, eq]
end
lemma neg_part_to_simple_func (f : Ξ± βββ[ΞΌ] β) :
f.neg_part.to_simple_func =α΅[ΞΌ] f.to_simple_func.neg_part :=
begin
rw [simple_func.neg_part, measure_theory.simple_func.neg_part],
filter_upwards [pos_part_to_simple_func (-f), neg_to_simple_func f],
simp only [mem_set_of_eq],
assume a hβ hβ,
rw hβ,
show max _ _ = max _ _,
rw hβ,
refl
end
lemma integral_eq_norm_pos_part_sub (f : Ξ± βββ[ΞΌ] β) : f.integral = β₯f.pos_partβ₯ - β₯f.neg_partβ₯ :=
begin
-- Convert things in `LΒΉ` to their `simple_func` counterpart
have ae_eqβ : f.to_simple_func.pos_part =α΅[ΞΌ] (f.pos_part).to_simple_func.map norm,
{ filter_upwards [pos_part_to_simple_func f],
simp only [mem_set_of_eq],
assume a h,
rw [simple_func.map_apply, h],
conv_lhs { rw [β simple_func.pos_part_map_norm, simple_func.map_apply] } },
-- Convert things in `LΒΉ` to their `simple_func` counterpart
have ae_eqβ : f.to_simple_func.neg_part =α΅[ΞΌ] (f.neg_part).to_simple_func.map norm,
{ filter_upwards [neg_part_to_simple_func f],
simp only [mem_set_of_eq],
assume a h,
rw [simple_func.map_apply, h],
conv_lhs { rw [β simple_func.neg_part_map_norm, simple_func.map_apply] } },
-- Convert things in `LΒΉ` to their `simple_func` counterpart
have ae_eq : βα΅ a βΞΌ, f.to_simple_func.pos_part a - f.to_simple_func.neg_part a =
(f.pos_part).to_simple_func.map norm a - (f.neg_part).to_simple_func.map norm a,
{ filter_upwards [ae_eqβ, ae_eqβ],
simp only [mem_set_of_eq],
assume a hβ hβ,
rw [hβ, hβ] },
rw [integral, norm_eq_integral, norm_eq_integral, β simple_func.integral_sub],
{ show f.to_simple_func.integral ΞΌ =
((f.pos_part.to_simple_func).map norm - f.neg_part.to_simple_func.map norm).integral ΞΌ,
apply measure_theory.simple_func.integral_congr f.integrable,
filter_upwards [ae_eqβ, ae_eqβ],
simp only [mem_set_of_eq],
assume a hβ hβ, show _ = _ - _,
rw [β hβ, β hβ],
have := f.to_simple_func.pos_part_sub_neg_part,
conv_lhs {rw β this},
refl },
{ exact f.integrable.max_zero.congr (measure_theory.simple_func.measurable _) ae_eqβ },
{ exact f.integrable.neg.max_zero.congr (measure_theory.simple_func.measurable _) ae_eqβ }
end
end pos_part
end simple_func_integral
end simple_func
open simple_func
variables [normed_space β E] [normed_space β F] [complete_space E]
section integration_in_l1
local notation `to_l1` := coe_to_l1 Ξ± E β
local attribute [instance] simple_func.normed_group simple_func.normed_space
open continuous_linear_map
/-- The Bochner integral in l1 space as a continuous linear map. -/
def integral_clm : (Ξ± ββ[ΞΌ] E) βL[β] E :=
integral_clm.extend to_l1 simple_func.dense_range simple_func.uniform_inducing
/-- The Bochner integral in l1 space -/
def integral (f : Ξ± ββ[ΞΌ] E) : E := integral_clm f
lemma integral_eq (f : Ξ± ββ[ΞΌ] E) : integral f = integral_clm f := rfl
@[norm_cast] lemma simple_func.integral_l1_eq_integral (f : Ξ± βββ[ΞΌ] E) :
integral (f : Ξ± ββ[ΞΌ] E) = f.integral :=
uniformly_extend_of_ind simple_func.uniform_inducing simple_func.dense_range
simple_func.integral_clm.uniform_continuous _
variables (Ξ± E)
@[simp] lemma integral_zero : integral (0 : Ξ± ββ[ΞΌ] E) = 0 :=
map_zero integral_clm
variables {Ξ± E}
lemma integral_add (f g : Ξ± ββ[ΞΌ] E) : integral (f + g) = integral f + integral g :=
map_add integral_clm f g
lemma integral_neg (f : Ξ± ββ[ΞΌ] E) : integral (-f) = - integral f :=
map_neg integral_clm f
lemma integral_sub (f g : Ξ± ββ[ΞΌ] E) : integral (f - g) = integral f - integral g :=
map_sub integral_clm f g
lemma integral_smul (r : β) (f : Ξ± ββ[ΞΌ] E) : integral (r β’ f) = r β’ integral f :=
map_smul r integral_clm f
local notation `Integral` := @integral_clm Ξ± E _ _ _ _ _ ΞΌ _ _
local notation `sIntegral` := @simple_func.integral_clm Ξ± E _ _ _ _ _ ΞΌ _
lemma norm_Integral_le_one : β₯Integralβ₯ β€ 1 :=
calc β₯Integralβ₯ β€ (1 : nnreal) * β₯sIntegralβ₯ :
op_norm_extend_le _ _ _ $ Ξ»s, by {rw [nnreal.coe_one, one_mul], refl}
... = β₯sIntegralβ₯ : one_mul _
... β€ 1 : norm_Integral_le_one
lemma norm_integral_le (f : Ξ± ββ[ΞΌ] E) : β₯integral fβ₯ β€ β₯fβ₯ :=
calc β₯integral fβ₯ = β₯Integral fβ₯ : rfl
... β€ β₯Integralβ₯ * β₯fβ₯ : le_op_norm _ _
... β€ 1 * β₯fβ₯ : mul_le_mul_of_nonneg_right norm_Integral_le_one $ norm_nonneg _
... = β₯fβ₯ : one_mul _
@[continuity]
lemma continuous_integral : continuous (Ξ» (f : Ξ± ββ[ΞΌ] E), f.integral) :=
by simp [l1.integral, l1.integral_clm.continuous]
section pos_part
lemma integral_eq_norm_pos_part_sub (f : Ξ± ββ[ΞΌ] β) : integral f = β₯pos_part fβ₯ - β₯neg_part fβ₯ :=
begin
-- Use `is_closed_property` and `is_closed_eq`
refine @is_closed_property _ _ _ (coe : (Ξ± βββ[ΞΌ] β) β (Ξ± ββ[ΞΌ] β))
(Ξ» f : Ξ± ββ[ΞΌ] β, integral f = β₯pos_part fβ₯ - β₯neg_part fβ₯)
l1.simple_func.dense_range (is_closed_eq _ _) _ f,
{ exact cont _ },
{ refine continuous.sub (continuous_norm.comp l1.continuous_pos_part)
(continuous_norm.comp l1.continuous_neg_part) },
-- Show that the property holds for all simple functions in the `LΒΉ` space.
{ assume s,
norm_cast,
rw [β simple_func.norm_eq, β simple_func.norm_eq],
exact simple_func.integral_eq_norm_pos_part_sub _}
end
end pos_part
end integration_in_l1
end l1
variables [normed_group E] [second_countable_topology E] [normed_space β E] [complete_space E]
[measurable_space E] [borel_space E]
[normed_group F] [second_countable_topology F] [normed_space β F] [complete_space F]
[measurable_space F] [borel_space F]
/-- The Bochner integral -/
def integral (ΞΌ : measure Ξ±) (f : Ξ± β E) : E :=
if hf : integrable f ΞΌ then (l1.of_fun f hf).integral else 0
notation `β«` binders `, ` r:(scoped:60 f, f) ` β` ΞΌ:70 := integral ΞΌ r
notation `β«` binders `, ` r:(scoped:60 f, integral volume f) := r
notation `β«` binders ` in ` s `, ` r:(scoped:60 f, f) ` β` ΞΌ:70 := integral (measure.restrict ΞΌ s) r
notation `β«` binders ` in ` s `, ` r:(scoped:60 f, integral (measure.restrict volume s) f) := r
section properties
open continuous_linear_map measure_theory.simple_func
variables {f g : Ξ± β E} {ΞΌ : measure Ξ±}
lemma integral_eq (f : Ξ± β E) (hf : integrable f ΞΌ) :
β« a, f a βΞΌ = (l1.of_fun f hf).integral :=
dif_pos hf
lemma l1.integral_eq_integral (f : Ξ± ββ[ΞΌ] E) : f.integral = β« a, f a βΞΌ :=
by rw [integral_eq, l1.of_fun_to_fun]
lemma integral_undef (h : Β¬ integrable f ΞΌ) : β« a, f a βΞΌ = 0 :=
dif_neg h
lemma integral_non_measurable (h : Β¬ measurable f) : β« a, f a βΞΌ = 0 :=
integral_undef $ not_and_of_not_left _ h
variables (Ξ± E)
local attribute [simp] -- Follows from `integral_const` below
lemma integral_zero : β« a : Ξ±, (0:E) βΞΌ = 0 :=
by rw [integral_eq, l1.of_fun_zero, l1.integral_zero]
variables {Ξ± E}
lemma integral_add (hf : integrable f ΞΌ) (hg : integrable g ΞΌ) :
β« a, f a + g a βΞΌ = β« a, f a βΞΌ + β« a, g a βΞΌ :=
by { rw [integral_eq, integral_eq f hf, integral_eq g hg, β l1.integral_add, β l1.of_fun_add],
refl }
lemma integral_neg (f : Ξ± β E) : β« a, -f a βΞΌ = - β« a, f a βΞΌ :=
begin
by_cases hf : integrable f ΞΌ,
{ rw [integral_eq f hf, integral_eq (Ξ»a, - f a) hf.neg, β l1.integral_neg, β l1.of_fun_neg],
refl },
{ rw [integral_undef hf, integral_undef, neg_zero], rwa [β integrable_neg_iff] at hf }
end
lemma integral_sub (hf : integrable f ΞΌ) (hg : integrable g ΞΌ) :
β« a, f a - g a βΞΌ = β« a, f a βΞΌ - β« a, g a βΞΌ :=
by { rw [sub_eq_add_neg, β integral_neg], exact integral_add hf hg.neg }
lemma integral_smul (r : β) (f : Ξ± β E) : β« a, r β’ (f a) βΞΌ = r β’ β« a, f a βΞΌ :=
begin
by_cases hf : integrable f ΞΌ,
{ rw [integral_eq f hf, integral_eq (Ξ»a, r β’ (f a)), l1.of_fun_smul, l1.integral_smul] },
{ by_cases hr : r = 0,
{ simp only [hr, measure_theory.integral_zero, zero_smul] },
have hf' : Β¬ integrable (Ξ» x, r β’ f x) ΞΌ,
{ change Β¬ integrable (r β’ f) ΞΌ, rwa [integrable_smul_iff hr f] },
rw [integral_undef hf, integral_undef hf', smul_zero] }
end
lemma integral_mul_left (r : β) (f : Ξ± β β) : β« a, r * (f a) βΞΌ = r * β« a, f a βΞΌ :=
integral_smul r f
lemma integral_mul_right (r : β) (f : Ξ± β β) : β« a, (f a) * r βΞΌ = β« a, f a βΞΌ * r :=
by { simp only [mul_comm], exact integral_mul_left r f }
lemma integral_div (r : β) (f : Ξ± β β) : β« a, (f a) / r βΞΌ = β« a, f a βΞΌ / r :=
integral_mul_right rβ»ΒΉ f
lemma integral_congr_ae (hfm : measurable f) (hgm : measurable g) (h : f =α΅[ΞΌ] g) :
β« a, f a βΞΌ = β« a, g a βΞΌ :=
begin
by_cases hfi : integrable f ΞΌ,
{ have hgi : integrable g ΞΌ := hfi.congr hgm h,
rw [integral_eq f hfi, integral_eq g hgi, (l1.of_fun_eq_of_fun f g hfi hgi).2 h] },
{ have hgi : Β¬ integrable g ΞΌ, { rw integrable_congr hfm hgm h at hfi, exact hfi },
rw [integral_undef hfi, integral_undef hgi] },
end
@[simp] lemma l1.integral_of_fun_eq_integral {f : Ξ± β E} (hf : integrable f ΞΌ) :
β« a, (l1.of_fun f hf) a βΞΌ = β« a, f a βΞΌ :=
integral_congr_ae (l1.measurable _) hf.measurable (l1.to_fun_of_fun f hf)
@[continuity]
lemma continuous_integral : continuous (Ξ» (f : Ξ± ββ[ΞΌ] E), β« a, f a βΞΌ) :=
by { simp only [β l1.integral_eq_integral], exact l1.continuous_integral }
lemma norm_integral_le_lintegral_norm (f : Ξ± β E) :
β₯β« a, f a βΞΌβ₯ β€ ennreal.to_real (β«β» a, (ennreal.of_real β₯f aβ₯) βΞΌ) :=
begin
by_cases hf : integrable f ΞΌ,
{ rw [integral_eq f hf, β l1.norm_of_fun_eq_lintegral_norm f hf], exact l1.norm_integral_le _ },
{ rw [integral_undef hf, norm_zero], exact to_real_nonneg }
end
lemma integral_eq_zero_of_ae {f : Ξ± β E} (hf : f =α΅[ΞΌ] 0) : β« a, f a βΞΌ = 0 :=
if hfm : measurable f then by simp [integral_congr_ae hfm measurable_zero hf]
else integral_non_measurable hfm
/-- If `F i β f` in `L1`, then `β« x, F i x βΞΌ β β« x, f xβΞΌ`. -/
lemma tendsto_integral_of_l1 {ΞΉ} (f : Ξ± β E) (hfi : integrable f ΞΌ)
{F : ΞΉ β Ξ± β E} {l : filter ΞΉ} (hFi : βαΆ i in l, integrable (F i) ΞΌ)
(hF : tendsto (Ξ» i, β«β» x, edist (F i x) (f x) βΞΌ) l (π 0)) :
tendsto (Ξ» i, β« x, F i x βΞΌ) l (π $ β« x, f x βΞΌ) :=
begin
rw [tendsto_iff_norm_tendsto_zero],
replace hF : tendsto (Ξ» i, ennreal.to_real $ β«β» x, edist (F i x) (f x) βΞΌ) l (π 0) :=
(ennreal.tendsto_to_real zero_ne_top).comp hF,
refine squeeze_zero_norm' (hFi.mp $ hFi.mono $ Ξ» i hFi hFm, _) hF,
simp only [norm_norm, β integral_sub hFi hfi, edist_dist, dist_eq_norm],
apply norm_integral_le_lintegral_norm
end
/-- Lebesgue dominated convergence theorem provides sufficient conditions under which almost
everywhere convergence of a sequence of functions implies the convergence of their integrals. -/
theorem tendsto_integral_of_dominated_convergence {F : β β Ξ± β E} {f : Ξ± β E} (bound : Ξ± β β)
(F_measurable : β n, measurable (F n))
(f_measurable : measurable f)
(bound_integrable : integrable bound ΞΌ)
(h_bound : β n, βα΅ a βΞΌ, β₯F n aβ₯ β€ bound a)
(h_lim : βα΅ a βΞΌ, tendsto (Ξ» n, F n a) at_top (π (f a))) :
tendsto (Ξ»n, β« a, F n a βΞΌ) at_top (π $ β« a, f a βΞΌ) :=
begin
/- To show `(β« a, F n a) --> (β« f)`, suffices to show `β₯β« a, F n a - β« fβ₯ --> 0` -/
rw tendsto_iff_norm_tendsto_zero,
/- But `0 β€ β₯β« a, F n a - β« fβ₯ = β₯β« a, (F n a - f a) β₯ β€ β« a, β₯F n a - f aβ₯, and thus we apply the
sandwich theorem and prove that `β« a, β₯F n a - f aβ₯ --> 0` -/
have lintegral_norm_tendsto_zero :
tendsto (Ξ»n, ennreal.to_real $ β«β» a, (ennreal.of_real β₯F n a - f aβ₯) βΞΌ) at_top (π 0) :=
(tendsto_to_real zero_ne_top).comp
(tendsto_lintegral_norm_of_dominated_convergence
F_measurable f_measurable bound_integrable.has_finite_integral h_bound h_lim),
-- Use the sandwich theorem
refine squeeze_zero (Ξ» n, norm_nonneg _) _ lintegral_norm_tendsto_zero,
-- Show `β₯β« a, F n a - β« fβ₯ β€ β« a, β₯F n a - f aβ₯` for all `n`
{ assume n,
have hβ : integrable (F n) ΞΌ := bound_integrable.mono' (F_measurable n) (h_bound _),
have hβ : integrable f ΞΌ :=
β¨f_measurable, has_finite_integral_of_dominated_convergence
bound_integrable.has_finite_integral h_bound h_limβ©,
rw β integral_sub hβ hβ,
exact norm_integral_le_lintegral_norm _ }
end
/-- Lebesgue dominated convergence theorem for filters with a countable basis -/
lemma tendsto_integral_filter_of_dominated_convergence {ΞΉ} {l : filter ΞΉ}
{F : ΞΉ β Ξ± β E} {f : Ξ± β E} (bound : Ξ± β β)
(hl_cb : l.is_countably_generated)
(hF_meas : βαΆ n in l, measurable (F n))
(f_measurable : measurable f)
(h_bound : βαΆ n in l, βα΅ a βΞΌ, β₯F n aβ₯ β€ bound a)
(bound_integrable : integrable bound ΞΌ)
(h_lim : βα΅ a βΞΌ, tendsto (Ξ» n, F n a) l (π (f a))) :
tendsto (Ξ»n, β« a, F n a βΞΌ) l (π $ β« a, f a βΞΌ) :=
begin
rw hl_cb.tendsto_iff_seq_tendsto,
{ intros x xl,
have hxl, { rw tendsto_at_top' at xl, exact xl },
have h := inter_mem_sets hF_meas h_bound,
replace h := hxl _ h,
rcases h with β¨k, hβ©,
rw β tendsto_add_at_top_iff_nat k,
refine tendsto_integral_of_dominated_convergence _ _ _ _ _ _,
{ exact bound },
{ intro, refine (h _ _).1, exact nat.le_add_left _ _ },
{ assumption },
{ assumption },
{ intro, refine (h _ _).2, exact nat.le_add_left _ _ },
{ filter_upwards [h_lim],
simp only [mem_set_of_eq],
assume a h_lim,
apply @tendsto.comp _ _ _ (Ξ»n, x (n + k)) (Ξ»n, F n a),
{ assumption },
rw tendsto_add_at_top_iff_nat,
assumption } },
end
/-- The Bochner integral of a real-valued function `f : Ξ± β β` is the difference between the
integral of the positive part of `f` and the integral of the negative part of `f`. -/
lemma integral_eq_lintegral_max_sub_lintegral_min {f : Ξ± β β} (hf : integrable f ΞΌ) :
β« a, f a βΞΌ =
ennreal.to_real (β«β» a, (ennreal.of_real $ max (f a) 0) βΞΌ) -
ennreal.to_real (β«β» a, (ennreal.of_real $ - min (f a) 0) βΞΌ) :=
let fβ : Ξ± ββ[ΞΌ] β := l1.of_fun f hf in
-- Go to the `LΒΉ` space
have eqβ : ennreal.to_real (β«β» a, (ennreal.of_real $ max (f a) 0) βΞΌ) = β₯l1.pos_part fββ₯ :=
begin
rw l1.norm_eq_norm_to_fun,
congr' 1,
apply lintegral_congr_ae,
filter_upwards [l1.pos_part_to_fun fβ, l1.to_fun_of_fun f hf],
simp only [mem_set_of_eq],
assume a hβ hβ,
rw [hβ, hβ, real.norm_eq_abs, abs_of_nonneg],
exact le_max_right _ _
end,
-- Go to the `LΒΉ` space
have eqβ : ennreal.to_real (β«β» a, (ennreal.of_real $ -min (f a) 0) βΞΌ) = β₯l1.neg_part fββ₯ :=
begin
rw l1.norm_eq_norm_to_fun,
congr' 1,
apply lintegral_congr_ae,
filter_upwards [l1.neg_part_to_fun_eq_min fβ, l1.to_fun_of_fun f hf],
simp only [mem_set_of_eq],
assume a hβ hβ,
rw [hβ, hβ, real.norm_eq_abs, abs_of_nonneg],
rw [min_eq_neg_max_neg_neg, _root_.neg_neg, neg_zero],
exact le_max_right _ _
end,
begin
rw [eqβ, eqβ, integral, dif_pos],
exact l1.integral_eq_norm_pos_part_sub _
end
lemma integral_eq_lintegral_of_nonneg_ae {f : Ξ± β β} (hf : 0 β€α΅[ΞΌ] f) (hfm : measurable f) :
β« a, f a βΞΌ = ennreal.to_real (β«β» a, (ennreal.of_real $ f a) βΞΌ) :=
begin
by_cases hfi : integrable f ΞΌ,
{ rw integral_eq_lintegral_max_sub_lintegral_min hfi,
have h_min : β«β» a, ennreal.of_real (-min (f a) 0) βΞΌ = 0,
{ rw lintegral_eq_zero_iff,
{ refine hf.mono _,
simp only [pi.zero_apply],
assume a h,
simp only [min_eq_right h, neg_zero, ennreal.of_real_zero] },
{ exact measurable_of_real.comp (measurable_id.neg.comp $ hfm.min measurable_const) } },
have h_max : β«β» a, ennreal.of_real (max (f a) 0) βΞΌ = β«β» a, ennreal.of_real (f a) βΞΌ,
{ refine lintegral_congr_ae (hf.mono (Ξ» a h, _)),
rw [pi.zero_apply] at h,
rw max_eq_left h },
rw [h_min, h_max, zero_to_real, _root_.sub_zero] },
{ rw integral_undef hfi,
simp_rw [integrable, hfm, has_finite_integral_iff_norm, lt_top_iff_ne_top, ne.def, true_and,
not_not] at hfi,
have : β«β» (a : Ξ±), ennreal.of_real (f a) βΞΌ = β«β» a, (ennreal.of_real β₯f aβ₯) βΞΌ,
{ refine lintegral_congr_ae (hf.mono $ assume a h, _),
rw [real.norm_eq_abs, abs_of_nonneg h] },
rw [this, hfi], refl }
end
lemma integral_nonneg_of_ae {f : Ξ± β β} (hf : 0 β€α΅[ΞΌ] f) : 0 β€ β« a, f a βΞΌ :=
begin
by_cases hfm : measurable f,
{ rw integral_eq_lintegral_of_nonneg_ae hf hfm, exact to_real_nonneg },
{ rw integral_non_measurable hfm }
end
lemma integral_nonneg {f : Ξ± β β} (hf : 0 β€ f) : 0 β€ β« a, f a βΞΌ :=
integral_nonneg_of_ae $ eventually_of_forall hf
lemma integral_nonpos_of_ae {f : Ξ± β β} (hf : f β€α΅[ΞΌ] 0) : β« a, f a βΞΌ β€ 0 :=
begin
have hf : 0 β€α΅[ΞΌ] (-f) := hf.mono (assume a h, by rwa [pi.neg_apply, pi.zero_apply, neg_nonneg]),
have : 0 β€ β« a, -f a βΞΌ := integral_nonneg_of_ae hf,
rwa [integral_neg, neg_nonneg] at this,
end
lemma integral_nonpos {f : Ξ± β β} (hf : f β€ 0) : β« a, f a βΞΌ β€ 0 :=
integral_nonpos_of_ae $ eventually_of_forall hf
lemma integral_eq_zero_iff_of_nonneg_ae {f : Ξ± β β} (hf : 0 β€α΅[ΞΌ] f) (hfi : integrable f ΞΌ) :
β« x, f x βΞΌ = 0 β f =α΅[ΞΌ] 0 :=
by simp_rw [integral_eq_lintegral_of_nonneg_ae hf hfi.1, ennreal.to_real_eq_zero_iff,
lintegral_eq_zero_iff (ennreal.measurable_of_real.comp hfi.1), β ennreal.not_lt_top,
β has_finite_integral_iff_of_real hf, hfi.2, not_true, or_false, β hf.le_iff_eq,
filter.eventually_eq, filter.eventually_le, (β), pi.zero_apply, ennreal.of_real_eq_zero]
lemma integral_eq_zero_iff_of_nonneg {f : Ξ± β β} (hf : 0 β€ f) (hfi : integrable f ΞΌ) :
β« x, f x βΞΌ = 0 β f =α΅[ΞΌ] 0 :=
integral_eq_zero_iff_of_nonneg_ae (eventually_of_forall hf) hfi
lemma integral_pos_iff_support_of_nonneg_ae {f : Ξ± β β} (hf : 0 β€α΅[ΞΌ] f) (hfi : integrable f ΞΌ) :
(0 < β« x, f x βΞΌ) β 0 < ΞΌ (function.support f) :=
by simp_rw [(integral_nonneg_of_ae hf).lt_iff_ne, zero_lt_iff_ne_zero, ne.def, @eq_comm β 0,
integral_eq_zero_iff_of_nonneg_ae hf hfi, filter.eventually_eq, ae_iff, pi.zero_apply,
function.support]
lemma integral_pos_iff_support_of_nonneg {f : Ξ± β β} (hf : 0 β€ f) (hfi : integrable f ΞΌ) :
(0 < β« x, f x βΞΌ) β 0 < ΞΌ (function.support f) :=
integral_pos_iff_support_of_nonneg_ae (eventually_of_forall hf) hfi
section normed_group
variables {H : Type*} [normed_group H] [second_countable_topology H] [measurable_space H]
[borel_space H]
lemma l1.norm_eq_integral_norm (f : Ξ± ββ[ΞΌ] H) : β₯fβ₯ = β« a, β₯f aβ₯ βΞΌ :=
by rw [l1.norm_eq_norm_to_fun,
integral_eq_lintegral_of_nonneg_ae (eventually_of_forall $ by simp [norm_nonneg])
(continuous_norm.measurable.comp f.measurable)]
lemma l1.norm_of_fun_eq_integral_norm {f : Ξ± β H} (hf : integrable f ΞΌ) :
β₯ l1.of_fun f hf β₯ = β« a, β₯f aβ₯ βΞΌ :=
begin
rw l1.norm_eq_integral_norm,
refine integral_congr_ae (l1.measurable_norm _) hf.measurable.norm _,
apply (l1.to_fun_of_fun f hf).mono,
intros a ha,
simp [ha]
end
end normed_group
lemma integral_mono_ae {f g : Ξ± β β} (hf : integrable f ΞΌ) (hg : integrable g ΞΌ) (h : f β€α΅[ΞΌ] g) :
β« a, f a βΞΌ β€ β« a, g a βΞΌ :=
le_of_sub_nonneg $ integral_sub hg hf βΈ integral_nonneg_of_ae $ h.mono (Ξ» a, sub_nonneg_of_le)
lemma integral_mono {f g : Ξ± β β} (hf : integrable f ΞΌ) (hg : integrable g ΞΌ) (h : f β€ g) :
β« a, f a βΞΌ β€ β« a, g a βΞΌ :=
integral_mono_ae hf hg $ eventually_of_forall h
lemma integral_mono_of_nonneg {f g : Ξ± β β} (hf : 0 β€α΅[ΞΌ] f) (hgi : integrable g ΞΌ)
(h : f β€α΅[ΞΌ] g) : β« a, f a βΞΌ β€ β« a, g a βΞΌ :=
begin
by_cases hfm : measurable f,
{ refine integral_mono_ae β¨hfm, _β© hgi h,
refine (hgi.has_finite_integral.mono $ h.mp $ hf.mono $ Ξ» x hf hfg, _),
simpa [real.norm_eq_abs, abs_of_nonneg hf, abs_of_nonneg (le_trans hf hfg)] },
{ rw [integral_non_measurable hfm],
exact integral_nonneg_of_ae (hf.trans h) }
end
lemma norm_integral_le_integral_norm (f : Ξ± β E) : β₯(β« a, f a βΞΌ)β₯ β€ β« a, β₯f aβ₯ βΞΌ :=
have le_ae : βα΅ a βΞΌ, 0 β€ β₯f aβ₯ := eventually_of_forall (Ξ»a, norm_nonneg _),
classical.by_cases
( Ξ»h : measurable f,
calc β₯β« a, f a βΞΌβ₯ β€ ennreal.to_real (β«β» a, (ennreal.of_real β₯f aβ₯) βΞΌ) : norm_integral_le_lintegral_norm _
... = β« a, β₯f aβ₯ βΞΌ : (integral_eq_lintegral_of_nonneg_ae le_ae $ measurable.norm h).symm )
( Ξ»h : Β¬measurable f,
begin
rw [integral_non_measurable h, norm_zero],
exact integral_nonneg_of_ae le_ae
end )
lemma norm_integral_le_of_norm_le {f : Ξ± β E} {g : Ξ± β β} (hg : integrable g ΞΌ)
(h : βα΅ x βΞΌ, β₯f xβ₯ β€ g x) : β₯β« x, f x βΞΌβ₯ β€ β« x, g x βΞΌ :=
calc β₯β« x, f x βΞΌβ₯ β€ β« x, β₯f xβ₯ βΞΌ : norm_integral_le_integral_norm f
... β€ β« x, g x βΞΌ :
integral_mono_of_nonneg (eventually_of_forall $ Ξ» x, norm_nonneg _) hg h
lemma integral_finset_sum {ΞΉ} (s : finset ΞΉ) {f : ΞΉ β Ξ± β E} (hf : β i, integrable (f i) ΞΌ) :
β« a, β i in s, f i a βΞΌ = β i in s, β« a, f i a βΞΌ :=
begin
refine finset.induction_on s _ _,
{ simp only [integral_zero, finset.sum_empty] },
{ assume i s his ih,
simp only [his, finset.sum_insert, not_false_iff],
rw [integral_add (hf _) (integrable_finset_sum s hf), ih] }
end
lemma simple_func.integral_eq_integral (f : Ξ± ββ E) (hfi : integrable f ΞΌ) :
f.integral ΞΌ = β« x, f x βΞΌ :=
begin
rw [integral_eq f hfi, β l1.simple_func.of_simple_func_eq_of_fun,
l1.simple_func.integral_l1_eq_integral, l1.simple_func.integral_eq_integral],
exact simple_func.integral_congr hfi (l1.simple_func.to_simple_func_of_simple_func _ _).symm
end
@[simp] lemma integral_const (c : E) : β« x : Ξ±, c βΞΌ = (ΞΌ univ).to_real β’ c :=
begin
by_cases hΞΌ : ΞΌ univ < β€,
{ haveI : finite_measure ΞΌ := β¨hΞΌβ©,
calc β« x : Ξ±, c βΞΌ = (simple_func.const Ξ± c).integral ΞΌ :
((simple_func.const Ξ± c).integral_eq_integral (integrable_const _)).symm
... = _ : _,
rw [simple_func.integral],
by_cases ha : nonempty Ξ±,
{ resetI, simp [preimage_const_of_mem] },
{ simp [ΞΌ.eq_zero_of_not_nonempty ha] } },
{ by_cases hc : c = 0,
{ simp [hc] },
{ have : Β¬integrable (Ξ» x : Ξ±, c) ΞΌ,
{ simp only [integrable_const_iff, not_or_distrib],
exact β¨hc, hΞΌβ© },
simp only [not_lt, top_le_iff] at hΞΌ,
simp [integral_undef, *] } }
end
lemma norm_integral_le_of_norm_le_const [finite_measure ΞΌ] {f : Ξ± β E} {C : β}
(h : βα΅ x βΞΌ, β₯f xβ₯ β€ C) :
β₯β« x, f x βΞΌβ₯ β€ C * (ΞΌ univ).to_real :=
calc β₯β« x, f x βΞΌβ₯ β€ β« x, C βΞΌ : norm_integral_le_of_norm_le (integrable_const C) h
... = C * (ΞΌ univ).to_real : by rw [integral_const, smul_eq_mul, mul_comm]
lemma tendsto_integral_approx_on_univ {f : Ξ± β E} (hf : integrable f ΞΌ) :
tendsto (Ξ» n, (simple_func.approx_on f hf.1 univ 0 trivial n).integral ΞΌ) at_top
(π $ β« x, f x βΞΌ) :=
begin
have : tendsto (Ξ» n, β« x, simple_func.approx_on f hf.1 univ 0 trivial n x βΞΌ)
at_top (π $ β« x, f x βΞΌ) :=
tendsto_integral_of_l1 _ hf (eventually_of_forall $ simple_func.integrable_approx_on_univ hf)
(simple_func.tendsto_approx_on_univ_l1_edist hf),
simpa only [simple_func.integral_eq_integral, simple_func.integrable_approx_on_univ hf]
end
variable {Ξ½ : measure Ξ±}
lemma integral_add_measure {f : Ξ± β E} (hΞΌ : integrable f ΞΌ) (hΞ½ : integrable f Ξ½) :
β« x, f x β(ΞΌ + Ξ½) = β« x, f x βΞΌ + β« x, f x βΞ½ :=
begin
have hfi := hΞΌ.add_measure hΞ½,
refine tendsto_nhds_unique (tendsto_integral_approx_on_univ hfi) _,
simpa only [simple_func.integral_add_measure _ (simple_func.integrable_approx_on_univ hfi _)]
using (tendsto_integral_approx_on_univ hΞΌ).add (tendsto_integral_approx_on_univ hΞ½)
end
lemma integral_add_measure' {f : Ξ± β E} (hΞΌ : has_finite_integral f ΞΌ) (hΞ½ : has_finite_integral f Ξ½) :
β« x, f x β(ΞΌ + Ξ½) = β« x, f x βΞΌ + β« x, f x βΞ½ :=
begin
by_cases hfm : measurable f,
{ exact integral_add_measure β¨hfm, hΞΌβ© β¨hfm, hΞ½β© },
{ simp only [integral_non_measurable hfm, zero_add] }
end
@[simp] lemma integral_zero_measure (f : Ξ± β E) : β« x, f x β0 = 0 :=
norm_le_zero_iff.1 $ le_trans (norm_integral_le_lintegral_norm f) $ by simp
@[simp] lemma integral_smul_measure (f : Ξ± β E) (c : ennreal) :
β« x, f x β(c β’ ΞΌ) = c.to_real β’ β« x, f x βΞΌ :=
begin
-- First we consider βdegenerateβ cases:
-- `f` is not measurable
by_cases hfm : measurable f, swap, { simp [integral_non_measurable hfm] },
-- `c = 0`
rcases (zero_le c).eq_or_lt with rfl|h0, { simp },
-- `c = β€`
rcases (le_top : c β€ β€).eq_or_lt with rfl|hc,
{ rw [ennreal.top_to_real, zero_smul],
by_cases hf : f =α΅[ΞΌ] 0,
{ have : f =α΅[β€ β’ ΞΌ] 0 := ae_smul_measure hf β€,
exact integral_eq_zero_of_ae this },
{ apply integral_undef,
rw [integrable, has_finite_integral, iff_true_intro hfm, true_and, lintegral_smul_measure,
top_mul, if_neg],
{ apply lt_irrefl },
{ rw [lintegral_eq_zero_iff hfm.ennnorm],
refine Ξ» h, hf (h.mono $ Ξ» x, _),
simp } } },
-- `f` is not integrable and `0 < c < β€`
by_cases hfi : integrable f ΞΌ, swap,
{ rw [integral_undef hfi, smul_zero],
refine integral_undef (mt (Ξ» h, _) hfi),
convert h.smul_measure (ennreal.inv_lt_top.2 h0),
rw [smul_smul, ennreal.inv_mul_cancel (ne_of_gt h0) (ne_of_lt hc), one_smul] },
-- Main case: `0 < c < β€`, `f` is measurable and integrable
refine tendsto_nhds_unique _ (tendsto_const_nhds.smul (tendsto_integral_approx_on_univ hfi)),
convert tendsto_integral_approx_on_univ (hfi.smul_measure hc),
simp only [simple_func.integral, measure.smul_apply, finset.smul_sum, smul_smul,
ennreal.to_real_mul_to_real]
end
lemma integral_map_measure {Ξ²} [measurable_space Ξ²] {Ο : Ξ± β Ξ²} (hΟ : measurable Ο)
{f : Ξ² β E} (hfm : measurable f) :
β« y, f y β(measure.map Ο ΞΌ) = β« x, f (Ο x) βΞΌ :=
begin
by_cases hfi : integrable f (measure.map Ο ΞΌ), swap,
{ rw [integral_undef hfi, integral_undef],
rwa [β integrable_map_measure hΟ hfm] },
refine tendsto_nhds_unique (tendsto_integral_approx_on_univ hfi) _,
convert tendsto_integral_approx_on_univ ((integrable_map_measure hΟ hfm).1 hfi),
ext1 i,
simp only [simple_func.approx_on_comp, simple_func.integral, measure.map_apply, hΟ,
simple_func.is_measurable_preimage, β preimage_comp, simple_func.coe_comp],
refine (finset.sum_subset (simple_func.range_comp_subset_range _ hΟ) (Ξ» y _ hy, _)).symm,
rw [simple_func.mem_range, β set.preimage_singleton_eq_empty, simple_func.coe_comp] at hy,
simp [hy]
end
lemma integral_dirac (f : Ξ± β E) (a : Ξ±) (hfm : measurable f) :
β« x, f x β(measure.dirac a) = f a :=
calc β« x, f x β(measure.dirac a) = β« x, f a β(measure.dirac a) :
integral_congr_ae hfm measurable_const $ eventually_eq_dirac hfm
... = f a : by simp [measure.dirac_apply_of_mem]
end properties
mk_simp_attribute integral_simps "Simp set for integral rules."
attribute [integral_simps] integral_neg integral_smul l1.integral_add l1.integral_sub
l1.integral_smul l1.integral_neg
attribute [irreducible] integral l1.integral
end measure_theory
|
79d6679774cd18d164fdaae6b75862e815f38069 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/algebra/lie/matrix.lean | c38085e480964db2b6e38390240d116ebf698780 | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 3,345 | lean | /-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import algebra.lie.of_associative
import linear_algebra.matrix.reindex
import linear_algebra.matrix.to_linear_equiv
/-!
# Lie algebras of matrices
An important class of Lie algebras are those arising from the associative algebra structure on
square matrices over a commutative ring. This file provides some very basic definitions whose
primary value stems from their utility when constructing the classical Lie algebras using matrices.
## Main definitions
* `lie_equiv_matrix'`
* `matrix.lie_conj`
* `matrix.reindex_lie_equiv`
## Tags
lie algebra, matrix
-/
universes u v w wβ wβ
section matrices
open_locale matrix
variables {R : Type u} [comm_ring R]
variables {n : Type w} [decidable_eq n] [fintype n]
/-- The natural equivalence between linear endomorphisms of finite free modules and square matrices
is compatible with the Lie algebra structures. -/
def lie_equiv_matrix' : module.End R (n β R) βββ
Rβ matrix n n R :=
{ map_lie' := Ξ» T S,
begin
let f := @linear_map.to_matrix' R _ n n _ _,
change f (T.comp S - S.comp T) = (f T) * (f S) - (f S) * (f T),
have h : β (T S : module.End R _), f (T.comp S) = (f T) β¬ (f S) := linear_map.to_matrix'_comp,
rw [linear_equiv.map_sub, h, h, matrix.mul_eq_mul, matrix.mul_eq_mul],
end,
..linear_map.to_matrix' }
@[simp] lemma lie_equiv_matrix'_apply (f : module.End R (n β R)) :
lie_equiv_matrix' f = f.to_matrix' := rfl
@[simp] lemma lie_equiv_matrix'_symm_apply (A : matrix n n R) :
(@lie_equiv_matrix' R _ n _ _).symm A = A.to_lin' := rfl
/-- An invertible matrix induces a Lie algebra equivalence from the space of matrices to itself. -/
def matrix.lie_conj (P : matrix n n R) (h : invertible P) :
matrix n n R βββ
Rβ matrix n n R :=
((@lie_equiv_matrix' R _ n _ _).symm.trans (P.to_linear_equiv' h).lie_conj).trans lie_equiv_matrix'
@[simp] lemma matrix.lie_conj_apply (P A : matrix n n R) (h : invertible P) :
P.lie_conj h A = P β¬ A β¬ Pβ»ΒΉ :=
by simp [linear_equiv.conj_apply, matrix.lie_conj, linear_map.to_matrix'_comp,
linear_map.to_matrix'_to_lin']
@[simp] lemma matrix.lie_conj_symm_apply (P A : matrix n n R) (h : invertible P) :
(P.lie_conj h).symm A = Pβ»ΒΉ β¬ A β¬ P :=
by simp [linear_equiv.symm_conj_apply, matrix.lie_conj, linear_map.to_matrix'_comp,
linear_map.to_matrix'_to_lin']
variables {m : Type wβ} [decidable_eq m] [fintype m] (e : n β m)
/-- For square matrices, the natural map that reindexes a matrix's rows and columns with equivalent
types, `matrix.reindex`, is an equivalence of Lie algebras. -/
def matrix.reindex_lie_equiv : matrix n n R βββ
Rβ matrix m m R :=
{ to_fun := matrix.reindex e e,
map_lie' := Ξ» M N, by simp only [lie_ring.of_associative_ring_bracket, matrix.reindex_apply,
matrix.minor_mul_equiv, matrix.mul_eq_mul, matrix.minor_sub, pi.sub_apply],
..(matrix.reindex_linear_equiv R R e e) }
@[simp] lemma matrix.reindex_lie_equiv_apply (M : matrix n n R) :
matrix.reindex_lie_equiv e M = matrix.reindex e e M := rfl
@[simp] lemma matrix.reindex_lie_equiv_symm :
(matrix.reindex_lie_equiv e : _ βββ
Rβ _).symm = matrix.reindex_lie_equiv e.symm := rfl
end matrices
|
1b9f6a011b887bc50fc893121314871b46f36d9f | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/category_theory/limits/lattice.lean | 8b9ee30169dd8b608a52e26bc2a9e3e5011a616c | [
"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 | 3,867 | 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.limits.shapes.finite_limits
import order.complete_lattice
universes u
open category_theory
open category_theory.limits
namespace category_theory.limits.complete_lattice
variables {Ξ± : Type u}
@[priority 100] -- see Note [lower instance priority]
instance has_finite_limits_of_semilattice_inf_top [semilattice_inf_top Ξ±] :
has_finite_limits Ξ± :=
β¨Ξ» J π₯β π₯β, by exactI
{ has_limit := Ξ» F, has_limit.mk
{ cone :=
{ X := finset.univ.inf F.obj,
Ο := { app := Ξ» j, hom_of_le (finset.inf_le (fintype.complete _)) } },
is_limit := { lift := Ξ» s, hom_of_le (finset.le_inf (Ξ» j _, (s.Ο.app j).down.down)) } } }β©
@[priority 100] -- see Note [lower instance priority]
instance has_finite_colimits_of_semilattice_sup_bot [semilattice_sup_bot Ξ±] :
has_finite_colimits Ξ± :=
β¨Ξ» J π₯β π₯β, by exactI
{ has_colimit := Ξ» F, has_colimit.mk
{ cocone :=
{ X := finset.univ.sup F.obj,
ΞΉ := { app := Ξ» i, hom_of_le (finset.le_sup (fintype.complete _)) } },
is_colimit := { desc := Ξ» s, hom_of_le (finset.sup_le (Ξ» j _, (s.ΞΉ.app j).down.down)) } } }β©
variables {J : Type u} [small_category J]
/--
The limit cone over any functor into a complete lattice.
-/
def limit_cone [complete_lattice Ξ±] (F : J β₯€ Ξ±) : limit_cone F :=
{ cone :=
{ X := infi F.obj,
Ο :=
{ app := Ξ» j, hom_of_le (complete_lattice.Inf_le _ _ (set.mem_range_self _)) } },
is_limit :=
{ lift := Ξ» s, hom_of_le (complete_lattice.le_Inf _ _
begin rintros _ β¨j, rflβ©, exact (s.Ο.app j).le, end) } }
/--
The colimit cocone over any functor into a complete lattice.
-/
def colimit_cocone [complete_lattice Ξ±] (F : J β₯€ Ξ±) : colimit_cocone F :=
{ cocone :=
{ X := supr F.obj,
ΞΉ :=
{ app := Ξ» j, hom_of_le (complete_lattice.le_Sup _ _ (set.mem_range_self _)) } },
is_colimit :=
{ desc := Ξ» s, hom_of_le (complete_lattice.Sup_le _ _
begin rintros _ β¨j, rflβ©, exact (s.ΞΉ.app j).le, end) } }
-- It would be nice to only use the `Inf` half of the complete lattice, but
-- this seems not to have been described separately.
@[priority 100] -- see Note [lower instance priority]
instance has_limits_of_complete_lattice [complete_lattice Ξ±] : has_limits Ξ± :=
{ has_limits_of_shape := Ξ» J π₯, by exactI
{ has_limit := Ξ» F, has_limit.mk (limit_cone F) } }
@[priority 100] -- see Note [lower instance priority]
instance has_colimits_of_complete_lattice [complete_lattice Ξ±] : has_colimits Ξ± :=
{ has_colimits_of_shape := Ξ» J π₯, by exactI
{ has_colimit := Ξ» F, has_colimit.mk (colimit_cocone F) } }
noncomputable theory
variables [complete_lattice Ξ±] (F : J β₯€ Ξ±)
/--
The limit of a functor into a complete lattice is the infimum of the objects in the image.
-/
def limit_iso_infi : limit F β
infi F.obj :=
is_limit.cone_point_unique_up_to_iso (limit.is_limit F) (limit_cone F).is_limit
@[simp] lemma limit_iso_infi_hom (j : J) :
(limit_iso_infi F).hom β« hom_of_le (infi_le _ j) = limit.Ο F j := by tidy
@[simp] lemma limit_iso_infi_inv (j : J) :
(limit_iso_infi F).inv β« limit.Ο F j = hom_of_le (infi_le _ j) := rfl
/--
The colimit of a functor into a complete lattice is the supremum of the objects in the image.
-/
def colimit_iso_supr : colimit F β
supr F.obj :=
is_colimit.cocone_point_unique_up_to_iso (colimit.is_colimit F) (colimit_cocone F).is_colimit
@[simp] lemma colimit_iso_supr_hom (j : J) :
colimit.ΞΉ F j β« (colimit_iso_supr F).hom = hom_of_le (le_supr _ j) := rfl
@[simp] lemma colimit_iso_supr_inv (j : J) :
hom_of_le (le_supr _ j) β« (colimit_iso_supr F).inv = colimit.ΞΉ F j := by tidy
end category_theory.limits.complete_lattice
|
aaf2b18fc54414f3f9f864d0df3492e1dec93c68 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/category_theory/sigma/basic.lean | bd9cfb824dd18fbd8fe133ebb9281f57fad037bd | [
"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 | 7,780 | 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.whiskering
import category_theory.fully_faithful
import category_theory.natural_isomorphism
import data.sigma.basic
/-!
# Disjoint union of categories
We define the category structure on a sigma-type (disjoint union) of categories.
-/
namespace category_theory
namespace sigma
universes wβ wβ wβ vβ vβ uβ uβ
variables {I : Type wβ} {C : I β Type uβ} [Ξ i, category.{vβ} (C i)]
/--
The type of morphisms of a disjoint union of categories: for `X : C i` and `Y : C j`, a morphism
`(i, X) βΆ (j, Y)` if `i = j` is just a morphism `X βΆ Y`, and if `i β j` there are no such morphisms.
-/
inductive sigma_hom : (Ξ£ i, C i) β (Ξ£ i, C i) β Type (max wβ vβ uβ)
| mk : Ξ {i : I} {X Y : C i}, (X βΆ Y) β sigma_hom β¨i, Xβ© β¨i, Yβ©
namespace sigma_hom
/-- The identity morphism on an object. -/
def id : Ξ (X : Ξ£ i, C i), sigma_hom X X
| β¨i, Xβ© := mk (π _)
instance (X : Ξ£ i, C i) : inhabited (sigma_hom X X) := β¨id Xβ©
/-- Composition of sigma homomorphisms. -/
def comp : Ξ {X Y Z : Ξ£ i, C i}, sigma_hom X Y β sigma_hom Y Z β sigma_hom X Z
| _ _ _ (mk f) (mk g) := mk (f β« g)
instance : category_struct (Ξ£ i, C i) :=
{ hom := sigma_hom,
id := id,
comp := Ξ» X Y Z f g, comp f g }
@[simp]
lemma comp_def (i : I) (X Y Z : C i) (f : X βΆ Y) (g : Y βΆ Z) :
comp (mk f) (mk g) = mk (f β« g) :=
rfl
lemma assoc : β (X Y Z W : Ξ£ i, C i) (f : X βΆ Y) (g : Y βΆ Z) (h : Z βΆ W), (f β« g) β« h = f β« g β« h
| _ _ _ _ (mk f) (mk g) (mk h) := congr_arg mk (category.assoc _ _ _)
lemma id_comp : β (X Y : Ξ£ i, C i) (f : X βΆ Y), π X β« f = f
| _ _ (mk f) := congr_arg mk (category.id_comp _)
lemma comp_id : β (X Y : Ξ£ i, C i) (f : X βΆ Y), f β« π Y = f
| _ _ (mk f) := congr_arg mk (category.comp_id _)
end sigma_hom
instance sigma : category (Ξ£ i, C i) :=
{ id_comp' := sigma_hom.id_comp,
comp_id' := sigma_hom.comp_id,
assoc' := sigma_hom.assoc }
/-- The inclusion functor into the disjoint union of categories. -/
@[simps map]
def incl (i : I) : C i β₯€ Ξ£ i, C i :=
{ obj := Ξ» X, β¨i, Xβ©,
map := Ξ» X Y, sigma_hom.mk }
@[simp] lemma incl_obj {i : I} (X : C i) : (incl i).obj X = β¨i, Xβ© := rfl
instance (i : I) : full (incl i : C i β₯€ Ξ£ i, C i) :=
{ preimage := Ξ» X Y β¨fβ©, f,
witness' := Ξ» X Y β¨fβ©, rfl }.
instance (i : I) : faithful (incl i : C i β₯€ Ξ£ i, C i) := {}.
section
variables {D : Type uβ} [category.{vβ} D] (F : Ξ i, C i β₯€ D)
/--
To build a natural transformation over the sigma category, it suffices to specify it restricted to
each subcategory.
-/
def nat_trans {F G : (Ξ£ i, C i) β₯€ D} (h : Ξ (i : I), incl i β F βΆ incl i β G) : F βΆ G :=
{ app := Ξ» β¨j, Xβ©, (h j).app X,
naturality' := by { rintro β¨j, Xβ© β¨_, _β© β¨_, _, Y, fβ©, apply (h j).naturality } }
@[simp]
lemma nat_trans_app {F G : (Ξ£ i, C i) β₯€ D} (h : Ξ (i : I), incl i β F βΆ incl i β G)
(i : I) (X : C i) :
(nat_trans h).app β¨i, Xβ© = (h i).app X :=
rfl
/-- (Implementation). An auxiliary definition to build the functor `desc`. -/
def desc_map : β (X Y : Ξ£ i, C i), (X βΆ Y) β ((F X.1).obj X.2 βΆ (F Y.1).obj Y.2)
| _ _ (sigma_hom.mk g) := (F _).map g
/--
Given a collection of functors `F i : C i β₯€ D`, we can produce a functor `(Ξ£ i, C i) β₯€ D`.
The produced functor `desc F` satisfies: `incl i β desc F β
F i`, i.e. restricted to just the
subcategory `C i`, `desc F` agrees with `F i`, and it is unique (up to natural isomorphism) with
this property.
This witnesses that the sigma-type is the coproduct in Cat.
-/
@[simps obj]
def desc : (Ξ£ i, C i) β₯€ D :=
{ obj := Ξ» X, (F X.1).obj X.2,
map := Ξ» X Y g, desc_map F X Y g,
map_id' := by { rintro β¨i, Xβ©, apply (F i).map_id },
map_comp' := by { rintro β¨i, Xβ© β¨_, Yβ© β¨_, Zβ© β¨i, _, Y, fβ© β¨_, _, Z, gβ©, apply (F i).map_comp } }
@[simp]
lemma desc_map_mk {i : I} (X Y : C i) (f : X βΆ Y) :
(desc F).map (sigma_hom.mk f) = (F i).map f :=
rfl
/--
This shows that when `desc F` is restricted to just the subcategory `C i`, `desc F` agrees with
`F i`.
-/
-- We hand-generate the simp lemmas about this since they come out cleaner.
def incl_desc (i : I) : incl i β desc F β
F i :=
nat_iso.of_components (Ξ» X, iso.refl _) (by tidy)
@[simp]
lemma incl_desc_hom_app (i : I) (X : C i) :
(incl_desc F i).hom.app X = π ((F i).obj X) :=
rfl
@[simp]
lemma incl_desc_inv_app (i : I) (X : C i) :
(incl_desc F i).inv.app X = π ((F i).obj X) :=
rfl
/--
If `q` when restricted to each subcategory `C i` agrees with `F i`, then `q` is isomorphic to
`desc F`.
-/
def desc_uniq (q : (Ξ£ i, C i) β₯€ D) (h : Ξ i, incl i β q β
F i) : q β
desc F :=
nat_iso.of_components (Ξ» β¨i, Xβ©, (h i).app X) $
by { rintro β¨i, Xβ© β¨_, _β© β¨_, _, Y, fβ©, apply (h i).hom.naturality f }
@[simp]
lemma desc_uniq_hom_app (q : (Ξ£ i, C i) β₯€ D) (h : Ξ i, incl i β q β
F i) (i : I) (X : C i) :
(desc_uniq F q h).hom.app β¨i, Xβ© = (h i).hom.app X :=
rfl
@[simp]
lemma desc_uniq_inv_app (q : (Ξ£ i, C i) β₯€ D) (h : Ξ i, incl i β q β
F i) (i : I) (X : C i) :
(desc_uniq F q h).inv.app β¨i, Xβ© = (h i).inv.app X :=
rfl
/--
If `qβ` and `qβ` when restricted to each subcategory `C i` agree, then `qβ` and `qβ` are isomorphic.
-/
@[simps]
def nat_iso {qβ qβ : (Ξ£ i, C i) β₯€ D} (h : Ξ i, incl i β qβ β
incl i β qβ) :
qβ β
qβ :=
{ hom := nat_trans (Ξ» i, (h i).hom),
inv := nat_trans (Ξ» i, (h i).inv) }
end
section
variables (C) {J : Type wβ} (g : J β I)
/-- A function `J β I` induces a functor `Ξ£ j, C (g j) β₯€ Ξ£ i, C i`. -/
def map : (Ξ£ (j : J), C (g j)) β₯€ (Ξ£ (i : I), C i) :=
desc (Ξ» j, incl (g j))
@[simp] lemma map_obj (j : J) (X : C (g j)) : (sigma.map C g).obj β¨j, Xβ© = β¨g j, Xβ© := rfl
@[simp] lemma map_map {j : J} {X Y : C (g j)} (f : X βΆ Y) :
(sigma.map C g).map (sigma_hom.mk f) = sigma_hom.mk f :=
rfl
/--
The functor `sigma.map C g` restricted to the subcategory `C j` acts as the inclusion of `g j`.
-/
@[simps]
def incl_comp_map (j : J) : incl j β map C g β
incl (g j) := iso.refl _
variable (I)
/-- The functor `sigma.map` applied to the identity function is just the identity functor. -/
@[simps]
def map_id : map C (id : I β I) β
π (Ξ£ i, C i) :=
nat_iso (Ξ» i, nat_iso.of_components (Ξ» X, iso.refl _) (by tidy))
variables {I} {K : Type wβ}
/-- The functor `sigma.map` applied to a composition is a composition of functors. -/
@[simps]
def map_comp (f : K β J) (g : J β I) : map (C β g) f β (map C g : _) β
map C (g β f) :=
desc_uniq _ _ $ Ξ» k,
(iso_whisker_right (incl_comp_map (C β g) f k) (map C g : _) : _) βͺβ« incl_comp_map _ _ _
end
namespace functor
variables {C}
variables {D : I β Type uβ} [β i, category.{vβ} (D i)]
/--
Assemble an `I`-indexed family of functors into a functor between the sigma types.
-/
def sigma (F : Ξ i, C i β₯€ D i) : (Ξ£ i, C i) β₯€ (Ξ£ i, D i) :=
desc (Ξ» i, F i β incl i)
end functor
namespace nat_trans
variables {C}
variables {D : I β Type uβ} [β i, category.{vβ} (D i)]
variables {F G : Ξ i, C i β₯€ D i}
/--
Assemble an `I`-indexed family of natural transformations into a single natural transformation.
-/
def sigma (Ξ± : Ξ i, F i βΆ G i) : functor.sigma F βΆ functor.sigma G :=
{ app := Ξ» f, sigma_hom.mk ((Ξ± f.1).app _),
naturality' :=
begin
rintro β¨i, Xβ© β¨_, _β© β¨_, _, Y, fβ©,
change sigma_hom.mk _ = sigma_hom.mk _,
rw (Ξ± i).naturality,
end }
end nat_trans
end sigma
end category_theory
|
8660eab2fbd31cdf2d25fb4ca9802936b1e4de04 | 947b78d97130d56365ae2ec264df196ce769371a | /tests/lean/run/structInst3.lean | 4b73a8c7b74e2a2a252b53eca4e2a20562608508 | [
"Apache-2.0"
] | permissive | shyamalschandra/lean4 | 27044812be8698f0c79147615b1d5090b9f4b037 | 6e7a883b21eaf62831e8111b251dc9b18f40e604 | refs/heads/master | 1,671,417,126,371 | 1,601,859,995,000 | 1,601,860,020,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 611 | lean | new_frontend
universes u
namespace Ex1
structure A (Ξ± : Type u) :=
(x : Ξ±) (f : Ξ± β Ξ± := Ξ» x => x)
structure B (Ξ± : Type u) extends A Ξ± :=
(y : Ξ± := f (f x)) (g : Ξ± β Ξ± β Ξ± := Ξ» x y => f x)
structure C (Ξ± : Type u) extends B Ξ± :=
(z : Ξ± := g x y) (x := f z)
end Ex1
open Ex1
def c1 : C Nat := { x := 1 }
#check { c1 with z := 2 }
#check { c1 with z := 2 }
theorem ex1 : { c1 with z := 2 }.z = 2 :=
rfl
#check ex1
theorem ex2 : { c1 with z := 2 }.x = c1.x :=
rfl
#check ex2
def c2 : C (Nat Γ Nat) := { z := (1, 1) }
#check { c2 with x.fst := 2 }
#check { c2 with x.1 := 3 }
|
3c6dd0b4a62f230d01ded133c9276e7f6310ea84 | 57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d | /src/Lean/Data/Options.lean | 8e45e4806ef2b2bc3202456938301a632f5923ab | [
"Apache-2.0"
] | permissive | collares/lean4 | 861a9269c4592bce49b71059e232ff0bfe4594cc | 52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee | refs/heads/master | 1,691,419,031,324 | 1,618,678,138,000 | 1,618,678,138,000 | 358,989,750 | 0 | 0 | Apache-2.0 | 1,618,696,333,000 | 1,618,696,333,000 | null | UTF-8 | Lean | false | false | 4,625 | lean | /-
Copyright (c) 2018 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sebastian Ullrich and Leonardo de Moura
-/
import Lean.Data.KVMap
namespace Lean
def Options := KVMap
def Options.empty : Options := {}
instance : Inhabited Options where
default := {}
instance : ToString Options := inferInstanceAs (ToString KVMap)
structure OptionDecl where
defValue : DataValue
group : String := ""
descr : String := ""
deriving Inhabited
def OptionDecls := NameMap OptionDecl
instance : Inhabited OptionDecls := β¨({} : NameMap OptionDecl)β©
private def initOptionDeclsRef : IO (IO.Ref OptionDecls) :=
IO.mkRef (mkNameMap OptionDecl)
@[builtinInit initOptionDeclsRef]
private constant optionDeclsRef : IO.Ref OptionDecls
@[export lean_register_option]
def registerOption (name : Name) (decl : OptionDecl) : IO Unit := do
let decls β optionDeclsRef.get
if decls.contains name then
throw $ IO.userError s!"invalid option declaration '{name}', option already exists"
optionDeclsRef.set $ decls.insert name decl
def getOptionDecls : IO OptionDecls := optionDeclsRef.get
@[export lean_get_option_decls_array]
def getOptionDeclsArray : IO (Array (Name Γ OptionDecl)) := do
let decls β getOptionDecls
pure $ decls.fold
(fun (r : Array (Name Γ OptionDecl)) k v => r.push (k, v))
#[]
def getOptionDecl (name : Name) : IO OptionDecl := do
let decls β getOptionDecls
let (some decl) β pure (decls.find? name) | throw $ IO.userError s!"unknown option '{name}'"
pure decl
def getOptionDefaulValue (name : Name) : IO DataValue := do
let decl β getOptionDecl name
pure decl.defValue
def getOptionDescr (name : Name) : IO String := do
let decl β getOptionDecl name
pure decl.descr
def setOptionFromString (opts : Options) (entry : String) : IO Options := do
let ps := (entry.splitOn "=").map String.trim
let [key, val] β pure ps | throw $ IO.userError "invalid configuration option entry, it must be of the form '<key> = <value>'"
let key := Name.mkSimple key
let defValue β getOptionDefaulValue key
match defValue with
| DataValue.ofString v => pure $ opts.setString key val
| DataValue.ofBool v =>
if key == `true then pure $ opts.setBool key true
else if key == `false then pure $ opts.setBool key false
else throw $ IO.userError s!"invalid Bool option value '{val}'"
| DataValue.ofName v => pure $ opts.setName key val.toName
| DataValue.ofNat v =>
match val.toNat? with
| none => throw (IO.userError s!"invalid Nat option value '{val}'")
| some v => pure $ opts.setNat key v
| DataValue.ofInt v =>
match val.toInt? with
| none => throw (IO.userError s!"invalid Int option value '{val}'")
| some v => pure $ opts.setInt key v
class MonadOptions (m : Type β Type) where
getOptions : m Options
export MonadOptions (getOptions)
instance (m n) [MonadLift m n] [MonadOptions m] : MonadOptions n where
getOptions := liftM (getOptions : m _)
variable {m} [Monad m] [MonadOptions m]
def getBoolOption (k : Name) (defValue := false) : m Bool := do
let opts β getOptions
pure $ opts.getBool k defValue
def getNatOption (k : Name) (defValue := 0) : m Nat := do
let opts β getOptions
pure $ opts.getNat k defValue
/-- A strongly-typed reference to an option. -/
protected structure Option (Ξ± : Type) where
name : Name
defValue : Ξ±
deriving Inhabited
namespace Option
protected structure Decl (Ξ± : Type) where
defValue : Ξ±
group : String := ""
descr : String := ""
protected def get [KVMap.Value Ξ±] (opts : Options) (opt : Lean.Option Ξ±) : Ξ± :=
opts.get opt.name opt.defValue
protected def set [KVMap.Value Ξ±] (opts : Options) (opt : Lean.Option Ξ±) (val : Ξ±) : Options :=
opts.set opt.name val
/-- Similar to `set`, but update `opts` only if it doesn't already contains an setting for `opt.name` -/
protected def setIfNotSet [KVMap.Value Ξ±] (opts : Options) (opt : Lean.Option Ξ±) (val : Ξ±) : Options :=
if opts.contains opt.name then opts else opt.set opts val
protected def register [KVMap.Value Ξ±] (name : Name) (decl : Lean.Option.Decl Ξ±) : IO (Lean.Option Ξ±) := do
registerOption name { defValue := KVMap.Value.toDataValue decl.defValue, group := decl.group, descr := decl.descr }
return { name := name, defValue := decl.defValue }
macro "register_builtin_option" name:ident " : " type:term " := " decl:term : command =>
`(builtin_initialize $name : Lean.Option $type β Lean.Option.register $(quote name.getId) $decl)
end Option
end Lean
|
3250c04d326bb29a3522f6a8802a5ac7f46ac145 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/parser_run.lean | 840799fb45d9cae8136fc7cedd44dd3463f5982a | [
"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 | 338 | lean | import system.io
open lean.parser
meta def parse_hello : tactic unit := do
e β lean.parser.run_with_input (lean.parser.get_env) "hello",
e2 β tactic.get_env,
tactic.trace (to_bool $ e.fingerprint = e2.fingerprint),
n β lean.parser.run_with_input (lean.parser.ident) "hello",
tactic.trace n.to_string
run_cmd parse_hello
|
c25800c1314cef71e1deb3a3a1e4fc2f7eba9753 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/ring_theory/fractional_ideal_auto.lean | c162834ea5aba5fa704fe8bdfbbe7c749e075fb6 | [] | 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 | 43,056 | lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Filippo A. E. Nuccio
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.ring_theory.localization
import Mathlib.ring_theory.noetherian
import Mathlib.ring_theory.principal_ideal_domain
import Mathlib.tactic.field_simp
import Mathlib.PostPort
universes u_1 u_2 u_3 u_4 u_5
namespace Mathlib
/-!
# Fractional ideals
This file defines fractional ideals of an integral domain and proves basic facts about them.
## Main definitions
Let `S` be a submonoid of an integral domain `R`, `P` the localization of `R` at `S`, and `f` the
natural ring hom from `R` to `P`.
* `is_fractional` defines which `R`-submodules of `P` are fractional ideals
* `fractional_ideal f` is the type of fractional ideals in `P`
* `has_coe (ideal R) (fractional_ideal f)` instance
* `comm_semiring (fractional_ideal f)` instance:
the typical ideal operations generalized to fractional ideals
* `lattice (fractional_ideal f)` instance
* `map` is the pushforward of a fractional ideal along an algebra morphism
Let `K` be the localization of `R` at `R \ {0}` and `g` the natural ring hom from `R` to `K`.
* `has_div (fractional_ideal g)` instance:
the ideal quotient `I / J` (typically written $I : J$, but a `:` operator cannot be defined)
## Main statements
* `mul_left_mono` and `mul_right_mono` state that ideal multiplication is monotone
* `prod_one_self_div_eq` states that `1 / I` is the inverse of `I` if one exists
* `is_noetherian` states that very fractional ideal of a noetherian integral domain is noetherian
## Implementation notes
Fractional ideals are considered equal when they contain the same elements,
independent of the denominator `a : R` such that `a I β R`.
Thus, we define `fractional_ideal` to be the subtype of the predicate `is_fractional`,
instead of having `fractional_ideal` be a structure of which `a` is a field.
Most definitions in this file specialize operations from submodules to fractional ideals,
proving that the result of this operation is fractional if the input is fractional.
Exceptions to this rule are defining `(+) := (β)` and `β₯ := 0`,
in order to re-use their respective proof terms.
We can still use `simp` to show `I.1 + J.1 = (I + J).1` and `β₯.1 = 0.1`.
In `ring_theory.localization`, we define a copy of the localization map `f`'s codomain `P`
(`f.codomain`) so that the `R`-algebra instance on `P` can 'know' the map needed to induce
the `R`-algebra structure.
We don't assume that the localization is a field until we need it to define ideal quotients.
When this assumption is needed, we replace `S` with `non_zero_divisors R`, making the localization
a field.
## References
* https://en.wikipedia.org/wiki/Fractional_ideal
## Tags
fractional ideal, fractional ideals, invertible ideal
-/
namespace ring
/-- A submodule `I` is a fractional ideal if `a I β R` for some `a β 0`. -/
def is_fractional {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
(f : localization_map S P) (I : submodule R (localization_map.codomain f)) :=
β (a : R),
β (H : a β S),
β (b : P), b β I β localization_map.is_integer f (coe_fn (localization_map.to_map f) a * b)
/-- The fractional ideals of a domain `R` are ideals of `R` divided by some `a β R`.
More precisely, let `P` be a localization of `R` at some submonoid `S`,
then a fractional ideal `I β P` is an `R`-submodule of `P`,
such that there is a nonzero `a : R` with `a I β R`.
-/
def fractional_ideal {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
(f : localization_map S P) :=
Subtype fun (I : submodule R (localization_map.codomain f)) => is_fractional f I
namespace fractional_ideal
protected instance submodule.has_coe {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} :
has_coe (fractional_ideal f) (submodule R (localization_map.codomain f)) :=
has_coe.mk fun (I : fractional_ideal f) => subtype.val I
@[simp] theorem val_eq_coe {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} (I : fractional_ideal f) : subtype.val I = βI :=
rfl
@[simp] theorem coe_mk {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} (I : submodule R (localization_map.codomain f))
(hI : is_fractional f I) : β{ val := I, property := hI } = I :=
rfl
protected instance has_mem {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} : has_mem P (fractional_ideal f) :=
has_mem.mk fun (x : P) (I : fractional_ideal f) => x β βI
/-- Fractional ideals are equal if their submodules are equal.
Combined with `submodule.ext` this gives that fractional ideals are equal if
they have the same elements.
-/
theorem ext {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {I : fractional_ideal f} {J : fractional_ideal f} :
βI = βJ β I = J :=
iff.mpr subtype.ext_iff_val
theorem ext_iff {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {I : fractional_ideal f} {J : fractional_ideal f} :
(β (x : P), x β I β x β J) β I = J :=
{ mp := fun (h : β (x : P), x β I β x β J) => ext (submodule.ext h),
mpr := fun (h : I = J) (x : P) => h βΈ iff.rfl }
theorem fractional_of_subset_one {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} (I : submodule R (localization_map.codomain f))
(h : I β€ submodule.span R (singleton 1)) : is_fractional f I :=
sorry
theorem is_fractional_of_le {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {I : submodule R (localization_map.codomain f)}
{J : fractional_ideal f} (hIJ : I β€ βJ) : is_fractional f I :=
sorry
protected instance coe_to_fractional_ideal {R : Type u_1} [comm_ring R] {S : submonoid R}
{P : Type u_2} [comm_ring P] {f : localization_map S P} :
has_coe (ideal R) (fractional_ideal f) :=
has_coe.mk fun (I : ideal R) => { val := localization_map.coe_submodule f I, property := sorry }
@[simp] theorem coe_coe_ideal {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} (I : ideal R) :
ββI = localization_map.coe_submodule f I :=
rfl
@[simp] theorem mem_coe_ideal {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {x : localization_map.codomain f} {I : ideal R} :
x β βI β β (x' : R), β (H : x' β I), coe_fn (localization_map.to_map f) x' = x :=
sorry
protected instance has_zero {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} : HasZero (fractional_ideal f) :=
{ zero := β0 }
@[simp] theorem mem_zero_iff {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {x : P} : x β 0 β x = 0 :=
sorry
@[simp] theorem coe_zero {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} : β0 = β₯ :=
submodule.ext fun (_x : localization_map.codomain f) => mem_zero_iff
@[simp] theorem coe_to_fractional_ideal_bot {R : Type u_1} [comm_ring R] {S : submonoid R}
{P : Type u_2} [comm_ring P] {f : localization_map S P} : ββ₯ = 0 :=
rfl
@[simp] theorem exists_mem_to_map_eq {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {x : R} {I : ideal R} (h : S β€ non_zero_divisors R) :
(β (x' : R),
x' β I β§ coe_fn (localization_map.to_map f) x' = coe_fn (localization_map.to_map f) x) β
x β I :=
sorry
theorem coe_to_fractional_ideal_injective {R : Type u_1} [comm_ring R] {S : submonoid R}
{P : Type u_2} [comm_ring P] {f : localization_map S P} (h : S β€ non_zero_divisors R) :
function.injective coe :=
sorry
theorem coe_to_fractional_ideal_eq_zero {R : Type u_1} [comm_ring R] {S : submonoid R}
{P : Type u_2} [comm_ring P] {f : localization_map S P} {I : ideal R}
(hS : S β€ non_zero_divisors R) : βI = 0 β I = β₯ :=
sorry
theorem coe_to_fractional_ideal_ne_zero {R : Type u_1} [comm_ring R] {S : submonoid R}
{P : Type u_2} [comm_ring P] {f : localization_map S P} {I : ideal R}
(hS : S β€ non_zero_divisors R) : βI β 0 β I β β₯ :=
iff.mpr not_iff_not (coe_to_fractional_ideal_eq_zero hS)
theorem coe_to_submodule_eq_bot {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {I : fractional_ideal f} : βI = β₯ β I = 0 :=
sorry
theorem coe_to_submodule_ne_bot {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {I : fractional_ideal f} : βI β β₯ β I β 0 :=
iff.mpr not_iff_not coe_to_submodule_eq_bot
protected instance inhabited {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} : Inhabited (fractional_ideal f) :=
{ default := 0 }
protected instance has_one {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} : HasOne (fractional_ideal f) :=
{ one := β1 }
theorem mem_one_iff {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {x : P} :
x β 1 β β (x' : R), coe_fn (localization_map.to_map f) x' = x :=
sorry
theorem coe_mem_one {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} (x : R) : coe_fn (localization_map.to_map f) x β 1 :=
iff.mpr mem_one_iff (Exists.intro x rfl)
theorem one_mem_one {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} : 1 β 1 :=
iff.mpr mem_one_iff (Exists.intro 1 (ring_hom.map_one (localization_map.to_map f)))
/-- `(1 : fractional_ideal f)` is defined as the R-submodule `f(R) β€ K`.
However, this is not definitionally equal to `1 : submodule R K`,
which is proved in the actual `simp` lemma `coe_one`. -/
theorem coe_one_eq_coe_submodule_one {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} : β1 = localization_map.coe_submodule f 1 :=
rfl
@[simp] theorem coe_one {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} : β1 = 1 :=
sorry
/-!
### `lattice` section
Defines the order on fractional ideals as inclusion of their underlying sets,
and ports the lattice structure on submodules to fractional ideals.
-/
protected instance partial_order {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} : partial_order (fractional_ideal f) :=
partial_order.mk (fun (I J : fractional_ideal f) => subtype.val I β€ subtype.val J)
(preorder.lt._default fun (I J : fractional_ideal f) => subtype.val I β€ subtype.val J) sorry
sorry sorry
theorem le_iff_mem {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {I : fractional_ideal f} {J : fractional_ideal f} :
I β€ J β β (x : P), x β I β x β J :=
iff.rfl
@[simp] theorem coe_le_coe {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {I : fractional_ideal f} {J : fractional_ideal f} :
βI β€ βJ β I β€ J :=
iff.rfl
theorem zero_le {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} (I : fractional_ideal f) : 0 β€ I :=
sorry
protected instance order_bot {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} : order_bot (fractional_ideal f) :=
order_bot.mk 0 partial_order.le partial_order.lt sorry sorry sorry zero_le
@[simp] theorem bot_eq_zero {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} : β₯ = 0 :=
rfl
@[simp] theorem le_zero_iff {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {I : fractional_ideal f} : I β€ 0 β I = 0 :=
le_bot_iff
theorem eq_zero_iff {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {I : fractional_ideal f} : I = 0 β β (x : P), x β I β x = 0 :=
sorry
theorem fractional_sup {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} (I : fractional_ideal f) (J : fractional_ideal f) :
is_fractional f (subtype.val I β subtype.val J) :=
sorry
theorem fractional_inf {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} (I : fractional_ideal f) (J : fractional_ideal f) :
is_fractional f (subtype.val I β subtype.val J) :=
sorry
protected instance lattice {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} : lattice (fractional_ideal f) :=
lattice.mk
(fun (I J : fractional_ideal f) =>
{ val := subtype.val I β subtype.val J, property := fractional_sup I J })
partial_order.le partial_order.lt sorry sorry sorry sorry sorry sorry
(fun (I J : fractional_ideal f) =>
{ val := subtype.val I β subtype.val J, property := fractional_inf I J })
sorry sorry sorry
protected instance semilattice_sup_bot {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} : semilattice_sup_bot (fractional_ideal f) :=
semilattice_sup_bot.mk order_bot.bot order_bot.le order_bot.lt sorry sorry sorry sorry lattice.sup
sorry sorry sorry
protected instance has_add {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} : Add (fractional_ideal f) :=
{ add := has_sup.sup }
@[simp] theorem sup_eq_add {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} (I : fractional_ideal f) (J : fractional_ideal f) :
I β J = I + J :=
rfl
@[simp] theorem coe_add {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} (I : fractional_ideal f) (J : fractional_ideal f) :
β(I + J) = βI + βJ :=
rfl
theorem fractional_mul {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} (I : fractional_ideal f) (J : fractional_ideal f) :
is_fractional f (subtype.val I * subtype.val J) :=
sorry
/-- `fractional_ideal.mul` is the product of two fractional ideals,
used to define the `has_mul` instance.
This is only an auxiliary definition: the preferred way of writing `I.mul J` is `I * J`.
Elaborated terms involving `fractional_ideal` tend to grow quite large,
so by making definitions irreducible, we hope to avoid deep unfolds.
-/
def mul {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} (I : fractional_ideal f) (J : fractional_ideal f) :
fractional_ideal f :=
{ val := subtype.val I * subtype.val J, property := fractional_mul I J }
protected instance has_mul {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} : Mul (fractional_ideal f) :=
{ mul := fun (I J : fractional_ideal f) => mul I J }
@[simp] theorem mul_eq_mul {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} (I : fractional_ideal f) (J : fractional_ideal f) :
mul I J = I * J :=
rfl
@[simp] theorem coe_mul {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} (I : fractional_ideal f) (J : fractional_ideal f) :
β(I * J) = βI * βJ :=
rfl
theorem mul_left_mono {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} (I : fractional_ideal f) : monotone (Mul.mul I) :=
sorry
theorem mul_right_mono {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} (I : fractional_ideal f) :
monotone fun (J : fractional_ideal f) => J * I :=
sorry
theorem mul_mem_mul {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {I : fractional_ideal f} {J : fractional_ideal f}
{i : localization_map.codomain f} {j : localization_map.codomain f} (hi : i β I) (hj : j β J) :
i * j β I * J :=
submodule.mul_mem_mul hi hj
theorem mul_le {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {I : fractional_ideal f} {J : fractional_ideal f}
{K : fractional_ideal f} : I * J β€ K β β (i : P), i β I β β (j : P), j β J β i * j β K :=
submodule.mul_le
protected theorem mul_induction_on {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {I : fractional_ideal f} {J : fractional_ideal f}
{C : localization_map.codomain f β Prop} {r : localization_map.codomain f} (hr : r β I * J)
(hm :
β (i : localization_map.codomain f),
i β I β β (j : localization_map.codomain f), j β J β C (i * j))
(h0 : C 0) (ha : β (x y : localization_map.codomain f), C x β C y β C (x + y))
(hs : β (r : R) (x : localization_map.codomain f), C x β C (r β’ x)) : C r :=
submodule.mul_induction_on hr hm h0 ha hs
protected instance comm_semiring {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} : comm_semiring (fractional_ideal f) :=
comm_semiring.mk Add.add sorry 0 sorry sorry sorry Mul.mul sorry 1 sorry sorry sorry sorry sorry
sorry sorry
theorem add_le_add_left {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {I : fractional_ideal f} {J : fractional_ideal f} (hIJ : I β€ J)
(J' : fractional_ideal f) : J' + I β€ J' + J :=
sup_le_sup_left hIJ J'
theorem mul_le_mul_left {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {I : fractional_ideal f} {J : fractional_ideal f} (hIJ : I β€ J)
(J' : fractional_ideal f) : J' * I β€ J' * J :=
iff.mpr mul_le fun (k : P) (hk : k β J') (j : P) (hj : j β I) => mul_mem_mul hk (hIJ hj)
theorem le_self_mul_self {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {I : fractional_ideal f} (hI : 1 β€ I) : I β€ I * I :=
sorry
theorem mul_self_le_self {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {I : fractional_ideal f} (hI : I β€ 1) : I * I β€ I :=
sorry
theorem coe_ideal_le_one {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {I : ideal R} : βI β€ 1 :=
sorry
theorem le_one_iff_exists_coe_ideal {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {J : fractional_ideal f} :
J β€ 1 β β (I : ideal R), βI = J :=
sorry
theorem fractional_map {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {P' : Type u_3} [comm_ring P'] {f' : localization_map S P'}
(g : alg_hom R (localization_map.codomain f) (localization_map.codomain f'))
(I : fractional_ideal f) :
is_fractional f' (submodule.map (alg_hom.to_linear_map g) (subtype.val I)) :=
sorry
/-- `I.map g` is the pushforward of the fractional ideal `I` along the algebra morphism `g` -/
def map {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {P' : Type u_3} [comm_ring P'] {f' : localization_map S P'}
(g : alg_hom R (localization_map.codomain f) (localization_map.codomain f')) :
fractional_ideal f β fractional_ideal f' :=
fun (I : fractional_ideal f) =>
{ val := submodule.map (alg_hom.to_linear_map g) (subtype.val I),
property := fractional_map g I }
@[simp] theorem coe_map {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {P' : Type u_3} [comm_ring P'] {f' : localization_map S P'}
(g : alg_hom R (localization_map.codomain f) (localization_map.codomain f'))
(I : fractional_ideal f) : β(map g I) = submodule.map (alg_hom.to_linear_map g) βI :=
rfl
@[simp] theorem mem_map {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {P' : Type u_3} [comm_ring P'] {f' : localization_map S P'}
{I : fractional_ideal f}
{g : alg_hom R (localization_map.codomain f) (localization_map.codomain f')}
{y : localization_map.codomain f'} :
y β map g I β β (x : localization_map.codomain f), x β I β§ coe_fn g x = y :=
submodule.mem_map
@[simp] theorem map_id {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} (I : fractional_ideal f) :
map (alg_hom.id R (localization_map.codomain f)) I = I :=
ext (submodule.map_id (subtype.val I))
@[simp] theorem map_comp {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {P' : Type u_3} [comm_ring P'] {f' : localization_map S P'}
{P'' : Type u_4} [comm_ring P''] {f'' : localization_map S P''} (I : fractional_ideal f)
(g : alg_hom R (localization_map.codomain f) (localization_map.codomain f'))
(g' : alg_hom R (localization_map.codomain f') (localization_map.codomain f'')) :
map (alg_hom.comp g' g) I = map g' (map g I) :=
ext (submodule.map_comp (alg_hom.to_linear_map g) (alg_hom.to_linear_map g') (subtype.val I))
@[simp] theorem map_coe_ideal {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {P' : Type u_3} [comm_ring P']
{f' : localization_map S P'}
(g : alg_hom R (localization_map.codomain f) (localization_map.codomain f')) (I : ideal R) :
map g βI = βI :=
sorry
@[simp] theorem map_one {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {P' : Type u_3} [comm_ring P'] {f' : localization_map S P'}
(g : alg_hom R (localization_map.codomain f) (localization_map.codomain f')) : map g 1 = 1 :=
map_coe_ideal g 1
@[simp] theorem map_zero {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {P' : Type u_3} [comm_ring P'] {f' : localization_map S P'}
(g : alg_hom R (localization_map.codomain f) (localization_map.codomain f')) : map g 0 = 0 :=
map_coe_ideal g 0
@[simp] theorem map_add {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {P' : Type u_3} [comm_ring P'] {f' : localization_map S P'}
(I : fractional_ideal f) (J : fractional_ideal f)
(g : alg_hom R (localization_map.codomain f) (localization_map.codomain f')) :
map g (I + J) = map g I + map g J :=
ext (submodule.map_sup (subtype.val I) (subtype.val J) (alg_hom.to_linear_map g))
@[simp] theorem map_mul {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {P' : Type u_3} [comm_ring P'] {f' : localization_map S P'}
(I : fractional_ideal f) (J : fractional_ideal f)
(g : alg_hom R (localization_map.codomain f) (localization_map.codomain f')) :
map g (I * J) = map g I * map g J :=
ext (submodule.map_mul (subtype.val I) (subtype.val J) g)
@[simp] theorem map_map_symm {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {P' : Type u_3} [comm_ring P']
{f' : localization_map S P'} (I : fractional_ideal f)
(g : alg_equiv R (localization_map.codomain f) (localization_map.codomain f')) :
map (β(alg_equiv.symm g)) (map (βg) I) = I :=
sorry
@[simp] theorem map_symm_map {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {P' : Type u_3} [comm_ring P']
{f' : localization_map S P'} (I : fractional_ideal f')
(g : alg_equiv R (localization_map.codomain f) (localization_map.codomain f')) :
map (βg) (map (β(alg_equiv.symm g)) I) = I :=
sorry
/-- If `g` is an equivalence, `map g` is an isomorphism -/
def map_equiv {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} {P' : Type u_3} [comm_ring P'] {f' : localization_map S P'}
(g : alg_equiv R (localization_map.codomain f) (localization_map.codomain f')) :
fractional_ideal f β+* fractional_ideal f' :=
ring_equiv.mk (map βg) (map β(alg_equiv.symm g)) sorry sorry sorry sorry
@[simp] theorem coe_fun_map_equiv {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {P' : Type u_3} [comm_ring P']
{f' : localization_map S P'}
(g : alg_equiv R (localization_map.codomain f) (localization_map.codomain f')) :
β(map_equiv g) = map βg :=
rfl
@[simp] theorem map_equiv_apply {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {P' : Type u_3} [comm_ring P']
{f' : localization_map S P'}
(g : alg_equiv R (localization_map.codomain f) (localization_map.codomain f'))
(I : fractional_ideal f) : coe_fn (map_equiv g) I = map (βg) I :=
rfl
@[simp] theorem map_equiv_symm {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {P' : Type u_3} [comm_ring P']
{f' : localization_map S P'}
(g : alg_equiv R (localization_map.codomain f) (localization_map.codomain f')) :
ring_equiv.symm (map_equiv g) = map_equiv (alg_equiv.symm g) :=
rfl
@[simp] theorem map_equiv_refl {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} :
map_equiv alg_equiv.refl = ring_equiv.refl (fractional_ideal f) :=
sorry
theorem is_fractional_span_iff {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {s : set (localization_map.codomain f)} :
is_fractional f (submodule.span R s) β
β (a : R),
β (H : a β S),
β (b : P),
b β s β localization_map.is_integer f (coe_fn (localization_map.to_map f) a * b) :=
sorry
theorem is_fractional_of_fg {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {I : submodule R (localization_map.codomain f)}
(hI : submodule.fg I) : is_fractional f I :=
sorry
/-- `canonical_equiv f f'` is the canonical equivalence between the fractional
ideals in `f.codomain` and in `f'.codomain` -/
def canonical_equiv {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{P' : Type u_3} [comm_ring P'] (f : localization_map S P) (f' : localization_map S P') :
fractional_ideal f β+* fractional_ideal f' :=
map_equiv
(alg_equiv.mk
(ring_equiv.to_fun (localization_map.ring_equiv_of_ring_equiv f f' (ring_equiv.refl R) sorry))
(ring_equiv.inv_fun
(localization_map.ring_equiv_of_ring_equiv f f' (ring_equiv.refl R) sorry))
sorry sorry sorry sorry sorry)
@[simp] theorem mem_canonical_equiv_apply {R : Type u_1} [comm_ring R] {S : submonoid R}
{P : Type u_2} [comm_ring P] {f : localization_map S P} {P' : Type u_3} [comm_ring P']
{f' : localization_map S P'} {I : fractional_ideal f} {x : localization_map.codomain f'} :
x β coe_fn (canonical_equiv f f') I β
β (y : P),
β (H : y β I),
coe_fn
(localization_map.map f
(fun (_x : β₯S) =>
(fun (_a : β₯S) =>
subtype.cases_on _a
fun (val : R) (property : val β S) => idRhs (val β S) property)
_x)
f')
y =
x :=
sorry
@[simp] theorem canonical_equiv_symm {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {P' : Type u_3} [comm_ring P'] (f : localization_map S P)
(f' : localization_map S P') : ring_equiv.symm (canonical_equiv f f') = canonical_equiv f' f :=
sorry
@[simp] theorem canonical_equiv_flip {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {P' : Type u_3} [comm_ring P'] (f : localization_map S P)
(f' : localization_map S P') (I : fractional_ideal f') :
coe_fn (canonical_equiv f f') (coe_fn (canonical_equiv f' f) I) = I :=
sorry
/-!
### `fraction_map` section
This section concerns fractional ideals in the field of fractions,
i.e. the type `fractional_ideal g` when `g` is a `fraction_map R K`.
-/
/-- Nonzero fractional ideals contain a nonzero integer. -/
theorem exists_ne_zero_mem_is_integer {R : Type u_1} [comm_ring R] {K : Type u_3} [field K]
{g : fraction_map R K} {I : fractional_ideal g} [nontrivial R] (hI : I β 0) :
β (x : R), β (H : x β 0), coe_fn (localization_map.to_map g) x β I :=
sorry
theorem map_ne_zero {R : Type u_1} [comm_ring R] {K : Type u_3} {K' : Type u_4} [field K] [field K']
{g : fraction_map R K} {g' : fraction_map R K'} {I : fractional_ideal g}
(h : alg_hom R (localization_map.codomain g) (localization_map.codomain g')) [nontrivial R]
(hI : I β 0) : map h I β 0 :=
sorry
@[simp] theorem map_eq_zero_iff {R : Type u_1} [comm_ring R] {K : Type u_3} {K' : Type u_4}
[field K] [field K'] {g : fraction_map R K} {g' : fraction_map R K'} {I : fractional_ideal g}
(h : alg_hom R (localization_map.codomain g) (localization_map.codomain g')) [nontrivial R] :
map h I = 0 β I = 0 :=
{ mp := imp_of_not_imp_not (map h I = 0) (I = 0) (map_ne_zero h),
mpr := fun (hI : I = 0) => Eq.symm hI βΈ map_zero h }
/-!
### `quotient` section
This section defines the ideal quotient of fractional ideals.
In this section we need that each non-zero `y : R` has an inverse in
the localization, i.e. that the localization is a field. We satisfy this
assumption by taking `S = non_zero_divisors R`, `R`'s localization at which
is a field because `R` is a domain.
-/
protected instance nontrivial {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} : nontrivial (fractional_ideal g) :=
nontrivial.mk
(Exists.intro 0
(Exists.intro 1
fun (h : 0 = 1) =>
(fun (this : 1 β 0) => one_ne_zero (iff.mp mem_zero_iff this))
(eq.mpr
(id
(Eq._oldrec (Eq.refl (1 β 0))
(Eq.symm (ring_hom.map_one (localization_map.to_map g)))))
(eq.mpr
((fun (αΎ° αΎ°_1 : K) (e_2 : αΎ° = αΎ°_1) (αΎ°_2 αΎ°_3 : fractional_ideal g)
(e_3 : αΎ°_2 = αΎ°_3) => congr (congr_arg has_mem.mem e_2) e_3)
(coe_fn (localization_map.to_map g) 1) (coe_fn (localization_map.to_map g) 1)
(Eq.refl (coe_fn (localization_map.to_map g) 1)) 0 1 h)
(coe_mem_one 1)))))
theorem fractional_div_of_nonzero {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} {I : fractional_ideal g} {J : fractional_ideal g} (h : J β 0) :
is_fractional g (subtype.val I / subtype.val J) :=
sorry
protected instance fractional_ideal_has_div {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4}
[field K] {g : fraction_map Rβ K} : Div (fractional_ideal g) :=
{ div :=
fun (I J : fractional_ideal g) =>
dite (J = 0) (fun (h : J = 0) => 0)
fun (h : Β¬J = 0) =>
{ val := subtype.val I / subtype.val J, property := fractional_div_of_nonzero h } }
@[simp] theorem div_zero {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} {I : fractional_ideal g} : I / 0 = 0 :=
dif_pos rfl
theorem div_nonzero {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} {I : fractional_ideal g} {J : fractional_ideal g} (h : J β 0) :
I / J = { val := subtype.val I / subtype.val J, property := fractional_div_of_nonzero h } :=
dif_neg h
@[simp] theorem coe_div {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} {I : fractional_ideal g} {J : fractional_ideal g} (hJ : J β 0) :
β(I / J) = βI / βJ :=
sorry
theorem mem_div_iff_of_nonzero {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} {I : fractional_ideal g} {J : fractional_ideal g} (h : J β 0) {x : K} :
x β I / J β β (y : K), y β J β x * y β I :=
eq.mpr (id (Eq._oldrec (Eq.refl (x β I / J β β (y : K), y β J β x * y β I)) (div_nonzero h)))
submodule.mem_div_iff_forall_mul_mem
theorem mul_one_div_le_one {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} {I : fractional_ideal g} : I * (1 / I) β€ 1 :=
sorry
theorem le_self_mul_one_div {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} {I : fractional_ideal g} (hI : I β€ 1) : I β€ I * (1 / I) :=
sorry
theorem le_div_iff_of_nonzero {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} {I : fractional_ideal g} {J : fractional_ideal g}
{J' : fractional_ideal g} (hJ' : J' β 0) :
I β€ J / J' β β (x : K), x β I β β (y : K), y β J' β x * y β J :=
sorry
theorem le_div_iff_mul_le {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} {I : fractional_ideal g} {J : fractional_ideal g}
{J' : fractional_ideal g} (hJ' : J' β 0) : I β€ J / J' β I * J' β€ J :=
sorry
@[simp] theorem div_one {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} {I : fractional_ideal g} : I / 1 = I :=
sorry
theorem ne_zero_of_mul_eq_one {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} (I : fractional_ideal g) (J : fractional_ideal g) (h : I * J = 1) :
I β 0 :=
sorry
theorem eq_one_div_of_mul_eq_one {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} (I : fractional_ideal g) (J : fractional_ideal g) (h : I * J = 1) :
J = 1 / I :=
congr_arg units.inv (units.ext rfl)
theorem mul_div_self_cancel_iff {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} {I : fractional_ideal g} :
I * (1 / I) = 1 β β (J : fractional_ideal g), I * J = 1 :=
sorry
@[simp] theorem map_div {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} {K' : Type u_5} [field K'] {g' : fraction_map Rβ K'}
(I : fractional_ideal g) (J : fractional_ideal g)
(h : alg_equiv Rβ (localization_map.codomain g) (localization_map.codomain g')) :
map (βh) (I / J) = map (βh) I / map (βh) J :=
sorry
@[simp] theorem map_one_div {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} {K' : Type u_5} [field K'] {g' : fraction_map Rβ K'}
(I : fractional_ideal g)
(h : alg_equiv Rβ (localization_map.codomain g) (localization_map.codomain g')) :
map (βh) (1 / I) = 1 / map (βh) I :=
eq.mpr (id (Eq._oldrec (Eq.refl (map (βh) (1 / I) = 1 / map (βh) I)) (map_div 1 I h)))
(eq.mpr (id (Eq._oldrec (Eq.refl (map (βh) 1 / map (βh) I = 1 / map (βh) I)) (map_one βh)))
(Eq.refl (1 / map (βh) I)))
theorem is_fractional_span_singleton {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} (x : localization_map.codomain f) :
is_fractional f (submodule.span R (singleton x)) :=
sorry
/-- `span_singleton x` is the fractional ideal generated by `x` if `0 β S` -/
def span_singleton {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} (x : localization_map.codomain f) : fractional_ideal f :=
{ val := submodule.span R (singleton x), property := is_fractional_span_singleton x }
@[simp] theorem coe_span_singleton {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} (x : localization_map.codomain f) :
β(span_singleton x) = submodule.span R (singleton x) :=
rfl
@[simp] theorem mem_span_singleton {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {x : localization_map.codomain f}
{y : localization_map.codomain f} : x β span_singleton y β β (z : R), z β’ y = x :=
submodule.mem_span_singleton
theorem mem_span_singleton_self {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} (x : localization_map.codomain f) :
x β span_singleton x :=
iff.mpr mem_span_singleton (Exists.intro 1 (one_smul R x))
theorem eq_span_singleton_of_principal {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} (I : fractional_ideal f) [submodule.is_principal βI] :
I = span_singleton (submodule.is_principal.generator βI) :=
ext (Eq.symm (submodule.is_principal.span_singleton_generator (subtype.val I)))
theorem is_principal_iff {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2} [comm_ring P]
{f : localization_map S P} (I : fractional_ideal f) :
submodule.is_principal βI β β (x : localization_map.codomain f), I = span_singleton x :=
sorry
@[simp] theorem span_singleton_zero {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} : span_singleton 0 = 0 :=
sorry
theorem span_singleton_eq_zero_iff {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {y : localization_map.codomain f} :
span_singleton y = 0 β y = 0 :=
sorry
theorem span_singleton_ne_zero_iff {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {y : localization_map.codomain f} :
span_singleton y β 0 β y β 0 :=
not_congr span_singleton_eq_zero_iff
@[simp] theorem span_singleton_one {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} : span_singleton 1 = 1 :=
sorry
@[simp] theorem span_singleton_mul_span_singleton {R : Type u_1} [comm_ring R] {S : submonoid R}
{P : Type u_2} [comm_ring P] {f : localization_map S P} (x : localization_map.codomain f)
(y : localization_map.codomain f) :
span_singleton x * span_singleton y = span_singleton (x * y) :=
sorry
@[simp] theorem coe_ideal_span_singleton {R : Type u_1} [comm_ring R] {S : submonoid R}
{P : Type u_2} [comm_ring P] {f : localization_map S P} (x : R) :
β(submodule.span R (singleton x)) = span_singleton (coe_fn (localization_map.to_map f) x) :=
sorry
@[simp] theorem canonical_equiv_span_singleton {R : Type u_1} [comm_ring R] {S : submonoid R}
{P : Type u_2} [comm_ring P] (f : localization_map S P) {P' : Type u_3} [comm_ring P']
(f' : localization_map S P') (x : localization_map.codomain f) :
coe_fn (canonical_equiv f f') (span_singleton x) =
span_singleton
(coe_fn
(localization_map.map f
((fun (this : β (y : β₯S), coe_fn (ring_hom.id R) (subtype.val y) β S) => this)
fun (y : β₯S) => subtype.property y)
f')
x) :=
sorry
theorem mem_singleton_mul {R : Type u_1} [comm_ring R] {S : submonoid R} {P : Type u_2}
[comm_ring P] {f : localization_map S P} {x : localization_map.codomain f}
{y : localization_map.codomain f} {I : fractional_ideal f} :
y β span_singleton x * I β β (y' : localization_map.codomain f), β (H : y' β I), y = x * y' :=
sorry
theorem one_div_span_singleton {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} (x : localization_map.codomain g) :
1 / span_singleton x = span_singleton (xβ»ΒΉ) :=
sorry
@[simp] theorem div_span_singleton {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} (J : fractional_ideal g) (d : localization_map.codomain g) :
J / span_singleton d = span_singleton (dβ»ΒΉ) * J :=
sorry
theorem exists_eq_span_singleton_mul {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} (I : fractional_ideal g) :
β (a : Rβ),
β (aI : ideal Rβ),
a β 0 β§ I = span_singleton (coe_fn (localization_map.to_map g) aβ»ΒΉ) * βaI :=
sorry
protected instance is_principal {K : Type u_4} [field K] {R : Type u_1} [integral_domain R]
[is_principal_ideal_ring R] {f : fraction_map R K} (I : fractional_ideal f) :
submodule.is_principal βI :=
sorry
theorem is_noetherian_zero {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} : is_noetherian Rβ β₯0 :=
sorry
theorem is_noetherian_iff {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} {I : fractional_ideal g} :
is_noetherian Rβ β₯I β β (J : fractional_ideal g), J β€ I β submodule.fg βJ :=
sorry
theorem is_noetherian_coe_to_fractional_ideal {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4}
[field K] {g : fraction_map Rβ K} [is_noetherian_ring Rβ] (I : ideal Rβ) :
is_noetherian Rβ β₯βI :=
sorry
theorem is_noetherian_span_singleton_inv_to_map_mul {Rβ : Type u_3} [integral_domain Rβ]
{K : Type u_4} [field K] {g : fraction_map Rβ K} (x : Rβ) {I : fractional_ideal g}
(hI : is_noetherian Rβ β₯I) :
is_noetherian Rβ β₯(span_singleton (coe_fn (localization_map.to_map g) xβ»ΒΉ) * I) :=
sorry
/-- Every fractional ideal of a noetherian integral domain is noetherian. -/
theorem is_noetherian {Rβ : Type u_3} [integral_domain Rβ] {K : Type u_4} [field K]
{g : fraction_map Rβ K} [is_noetherian_ring Rβ] (I : fractional_ideal g) :
is_noetherian Rβ β₯I :=
sorry
end Mathlib |
add32ba7feca42b1f19748f37ef4b0dabfa22857 | 624f6f2ae8b3b1adc5f8f67a365c51d5126be45a | /stage0/src/Init/Lean/Elab/Tactic/Injection.lean | 15af6a8f6b6fcedf208bca41939f59137d5b6438 | [
"Apache-2.0"
] | permissive | mhuisi/lean4 | 28d35a4febc2e251c7f05492e13f3b05d6f9b7af | dda44bc47f3e5d024508060dac2bcb59fd12e4c0 | refs/heads/master | 1,621,225,489,283 | 1,585,142,689,000 | 1,585,142,689,000 | 250,590,438 | 0 | 2 | Apache-2.0 | 1,602,443,220,000 | 1,585,327,814,000 | C | UTF-8 | Lean | false | false | 1,274 | lean | /-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Lean.Meta.Tactic.Injection
import Init.Lean.Elab.Tactic.ElabTerm
namespace Lean
namespace Elab
namespace Tactic
-- optional (" with " >> many1 ident')
private def getInjectionNewIds (stx : Syntax) : List Name :=
if stx.isNone then []
else (stx.getArg 1).getArgs.toList.map Syntax.getId
private def checkUnusedIds (mvarId : MVarId) (unusedIds : List Name) : MetaM Unit :=
unless unusedIds.isEmpty $
Meta.throwTacticEx `injection mvarId ("too many identifiers provided, unused: " ++ toString unusedIds)
@[builtinTactic Β«injectionΒ»] def evalInjection : Tactic :=
fun stx => do
-- parser! nonReservedSymbol "injection " >> termParser >> withIds
fvarId β elabAsFVar (stx.getArg 1);
let ids := getInjectionNewIds (stx.getArg 2);
liftMetaTactic stx $ fun mvarId => do
r β Meta.injection mvarId fvarId ids (!ids.isEmpty);
match r with
| Meta.InjectionResult.solved => do checkUnusedIds mvarId ids; pure []
| Meta.InjectionResult.subgoal mvarId' _ unusedIds => do checkUnusedIds mvarId unusedIds; pure [mvarId']
end Tactic
end Elab
end Lean
|
e6544bbda82e66e005a15f678487f61034519724 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /library/data/list/basic.lean | 98d6c6ec267e37d86f9eb624dd192c18d7984c7c | [
"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 | 26,592 | lean | /-
Copyright (c) 2014 Parikshit Khanna. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn
Basic properties of lists.
-/
import logic tools.helper_tactics data.nat.order data.nat.sub
open eq.ops nat prod function option
inductive list (T : Type) : Type :=
| nil {} : list T
| cons : T β list T β list T
protected definition list.is_inhabited [instance] (A : Type) : inhabited (list A) :=
inhabited.mk list.nil
namespace list
notation h :: t := cons h t
notation `[` l:(foldr `, ` (h t, cons h t) nil `]`) := l
variable {T : Type}
lemma cons_ne_nil [simp] (a : T) (l : list T) : a::l β [] :=
by contradiction
lemma head_eq_of_cons_eq {A : Type} {hβ hβ : A} {tβ tβ : list A} :
(hβ::tβ) = (hβ::tβ) β hβ = hβ :=
assume Peq, list.no_confusion Peq (assume Pheq Pteq, Pheq)
lemma tail_eq_of_cons_eq {A : Type} {hβ hβ : A} {tβ tβ : list A} :
(hβ::tβ) = (hβ::tβ) β tβ = tβ :=
assume Peq, list.no_confusion Peq (assume Pheq Pteq, Pteq)
lemma cons_inj {A : Type} {a : A} : injective (cons a) :=
take lβ lβ, assume Pe, tail_eq_of_cons_eq Pe
/- append -/
definition append : list T β list T β list T
| [] l := l
| (h :: s) t := h :: (append s t)
notation lβ ++ lβ := append lβ lβ
theorem append_nil_left [simp] (t : list T) : [] ++ t = t :=
rfl
theorem append_cons [simp] (x : T) (s t : list T) : (x::s) ++ t = x::(s ++ t) :=
rfl
theorem append_nil_right [simp] : β (t : list T), t ++ [] = t :=
by rec_inst_simp
theorem append.assoc [simp] : β (s t u : list T), s ++ t ++ u = s ++ (t ++ u) :=
by rec_inst_simp
/- length -/
definition length : list T β nat
| [] := 0
| (a :: l) := length l + 1
theorem length_nil [simp] : length (@nil T) = 0 :=
rfl
theorem length_cons [simp] (x : T) (t : list T) : length (x::t) = length t + 1 :=
rfl
theorem length_append [simp] : β (s t : list T), length (s ++ t) = length s + length t :=
by rec_inst_simp
theorem eq_nil_of_length_eq_zero : β {l : list T}, length l = 0 β l = []
| [] H := rfl
| (a::s) H := by contradiction
theorem length_cons_pos (h : T) (tt : list T) : 0 < length (h::tt) :=
begin
apply lt_of_not_ge,
intro H,
let H' := list.eq_nil_of_length_eq_zero (eq_zero_of_le_zero H),
apply !list.cons_ne_nil H'
end
theorem ne_nil_of_length_eq_succ : β {l : list T} {n : nat}, length l = succ n β l β []
| [] n h := by contradiction
| (a::l) n h := by contradiction
/- concat -/
definition concat : Ξ (x : T), list T β list T
| a [] := [a]
| a (b :: l) := b :: concat a l
theorem concat_nil [simp] (x : T) : concat x [] = [x] :=
rfl
theorem concat_cons [simp] (x y : T) (l : list T) : concat x (y::l) = y::(concat x l) :=
rfl
theorem concat_eq_append [simp] (a : T) : β (l : list T), concat a l = l ++ [a] :=
by rec_inst_simp
theorem concat_ne_nil [simp] (a : T) : β (l : list T), concat a l β [] :=
by intro l; induction l; repeat contradiction
theorem length_concat [simp] (a : T) : β (l : list T), length (concat a l) = length l + 1 :=
by rec_inst_simp
theorem concat_append [simp] (a : T) : β (lβ lβ : list T), concat a lβ ++ lβ = lβ ++ a :: lβ :=
by rec_inst_simp
theorem append_concat (a : T) : β(lβ lβ : list T), lβ ++ concat a lβ = concat a (lβ ++ lβ) :=
by rec_inst_simp
/- last -/
definition last : Ξ l : list T, l β [] β T
| [] h := absurd rfl h
| [a] h := a
| (aβ::aβ::l) h := last (aβ::l) !cons_ne_nil
lemma last_singleton [simp] (a : T) (h : [a] β []) : last [a] h = a :=
rfl
lemma last_cons_cons [simp] (aβ aβ : T) (l : list T) (h : aβ::aβ::l β []) : last (aβ::aβ::l) h = last (aβ::l) !cons_ne_nil :=
rfl
theorem last_congr {lβ lβ : list T} (hβ : lβ β []) (hβ : lβ β []) (hβ : lβ = lβ) : last lβ hβ = last lβ hβ :=
by subst lβ
theorem last_concat [simp] {x : T} : β {l : list T} (h : concat x l β []), last (concat x l) h = x :=
by rec_simp
-- add_rewrite append_nil append_cons
/- reverse -/
definition reverse : list T β list T
| [] := []
| (a :: l) := concat a (reverse l)
theorem reverse_nil [simp] : reverse (@nil T) = [] :=
rfl
theorem reverse_cons [simp] (x : T) (l : list T) : reverse (x::l) = concat x (reverse l) :=
rfl
theorem reverse_singleton [simp] (x : T) : reverse [x] = [x] :=
rfl
theorem reverse_append [simp] : β (s t : list T), reverse (s ++ t) = (reverse t) ++ (reverse s) :=
by rec_inst_simp
theorem reverse_reverse [simp] : β (l : list T), reverse (reverse l) = l :=
by rec_inst_simp
theorem concat_eq_reverse_cons (x : T) (l : list T) : concat x l = reverse (x :: reverse l) :=
by inst_simp
theorem length_reverse : β (l : list T), length (reverse l) = length l :=
by rec_inst_simp
/- head and tail -/
definition head [h : inhabited T] : list T β T
| [] := arbitrary T
| (a :: l) := a
theorem head_cons [simp] [h : inhabited T] (a : T) (l : list T) : head (a::l) = a :=
rfl
theorem head_append [simp] [h : inhabited T] (t : list T) : β {s : list T}, s β [] β head (s ++ t) = head s :=
by rec_inst_simp
definition tail : list T β list T
| [] := []
| (a :: l) := l
theorem tail_nil [simp] : tail (@nil T) = [] :=
rfl
theorem tail_cons [simp] (a : T) (l : list T) : tail (a::l) = l :=
rfl
theorem cons_head_tail [h : inhabited T] {l : list T} : l β [] β (head l)::(tail l) = l :=
by rec_inst_simp
/- list membership -/
definition mem : T β list T β Prop
| a [] := false
| a (b :: l) := a = b β¨ mem a l
notation e β s := mem e s
notation e β s := Β¬ e β s
theorem mem_nil_iff (x : T) : x β [] β false :=
iff.rfl
theorem not_mem_nil (x : T) : x β [] :=
iff.mp !mem_nil_iff
theorem mem_cons [simp] (x : T) (l : list T) : x β x :: l :=
or.inl rfl
theorem mem_cons_of_mem (y : T) {x : T} {l : list T} : x β l β x β y :: l :=
assume H, or.inr H
theorem mem_cons_iff (x y : T) (l : list T) : x β y::l β (x = y β¨ x β l) :=
iff.rfl
theorem eq_or_mem_of_mem_cons {x y : T} {l : list T} : x β y::l β x = y β¨ x β l :=
assume h, h
theorem mem_singleton {x a : T} : x β [a] β x = a :=
suppose x β [a], or.elim (eq_or_mem_of_mem_cons this)
(suppose x = a, this)
(suppose x β [], absurd this !not_mem_nil)
theorem mem_of_mem_cons_of_mem {a b : T} {l : list T} : a β b::l β b β l β a β l :=
assume ainbl binl, or.elim (eq_or_mem_of_mem_cons ainbl)
(suppose a = b, by substvars; exact binl)
(suppose a β l, this)
theorem mem_or_mem_of_mem_append {x : T} {s t : list T} : x β s ++ t β x β s β¨ x β t :=
list.induction_on s or.inr
(take y s,
assume IH : x β s ++ t β x β s β¨ x β t,
suppose x β y::s ++ t,
have x = y β¨ x β s ++ t, from this,
have x = y β¨ x β s β¨ x β t, from or_of_or_of_imp_right this IH,
iff.elim_right or.assoc this)
theorem mem_append_of_mem_or_mem {x : T} {s t : list T} : x β s β¨ x β t β x β s ++ t :=
list.induction_on s
(take H, or.elim H false.elim (assume H, H))
(take y s,
assume IH : x β s β¨ x β t β x β s ++ t,
suppose x β y::s β¨ x β t,
or.elim this
(suppose x β y::s,
or.elim (eq_or_mem_of_mem_cons this)
(suppose x = y, or.inl this)
(suppose x β s, or.inr (IH (or.inl this))))
(suppose x β t, or.inr (IH (or.inr this))))
theorem mem_append_iff (x : T) (s t : list T) : x β s ++ t β x β s β¨ x β t :=
iff.intro mem_or_mem_of_mem_append mem_append_of_mem_or_mem
theorem not_mem_of_not_mem_append_left {x : T} {s t : list T} : x β s++t β x β s :=
Ξ» nxinst xins, absurd (mem_append_of_mem_or_mem (or.inl xins)) nxinst
theorem not_mem_of_not_mem_append_right {x : T} {s t : list T} : x β s++t β x β t :=
Ξ» nxinst xint, absurd (mem_append_of_mem_or_mem (or.inr xint)) nxinst
theorem not_mem_append {x : T} {s t : list T} : x β s β x β t β x β s++t :=
Ξ» nxins nxint xinst, or.elim (mem_or_mem_of_mem_append xinst)
(Ξ» xins, by contradiction)
(Ξ» xint, by contradiction)
lemma length_pos_of_mem {a : T} : β {l : list T}, a β l β 0 < length l
| [] := assume Pinnil, by contradiction
| (b::l) := assume Pin, !zero_lt_succ
section
local attribute mem [reducible]
local attribute append [reducible]
theorem mem_split {x : T} {l : list T} : x β l β βs t : list T, l = s ++ (x::t) :=
list.induction_on l
(suppose x β [], false.elim (iff.elim_left !mem_nil_iff this))
(take y l,
assume IH : x β l β βs t : list T, l = s ++ (x::t),
suppose x β y::l,
or.elim (eq_or_mem_of_mem_cons this)
(suppose x = y,
exists.intro [] (!exists.intro (this βΈ rfl)))
(suppose x β l,
obtain s (H2 : βt : list T, l = s ++ (x::t)), from IH this,
obtain t (H3 : l = s ++ (x::t)), from H2,
have y :: l = (y::s) ++ (x::t),
from H3 βΈ rfl,
!exists.intro (!exists.intro this)))
end
theorem mem_append_left {a : T} {lβ : list T} (lβ : list T) : a β lβ β a β lβ ++ lβ :=
assume ainlβ, mem_append_of_mem_or_mem (or.inl ainlβ)
theorem mem_append_right {a : T} (lβ : list T) {lβ : list T} : a β lβ β a β lβ ++ lβ :=
assume ainlβ, mem_append_of_mem_or_mem (or.inr ainlβ)
definition decidable_mem [instance] [H : decidable_eq T] (x : T) (l : list T) : decidable (x β l) :=
list.rec_on l
(decidable.inr (not_of_iff_false !mem_nil_iff))
(take (h : T) (l : list T) (iH : decidable (x β l)),
show decidable (x β h::l), from
decidable.rec_on iH
(assume Hp : x β l,
decidable.rec_on (H x h)
(suppose x = h,
decidable.inl (or.inl this))
(suppose x β h,
decidable.inl (or.inr Hp)))
(suppose Β¬x β l,
decidable.rec_on (H x h)
(suppose x = h, decidable.inl (or.inl this))
(suppose x β h,
have Β¬(x = h β¨ x β l), from
suppose x = h β¨ x β l, or.elim this
(suppose x = h, by contradiction)
(suppose x β l, by contradiction),
have Β¬x β h::l, from
iff.elim_right (not_iff_not_of_iff !mem_cons_iff) this,
decidable.inr this)))
theorem mem_of_ne_of_mem {x y : T} {l : list T} (Hβ : x β y) (Hβ : x β y :: l) : x β l :=
or.elim (eq_or_mem_of_mem_cons Hβ) (Ξ»e, absurd e Hβ) (Ξ»r, r)
theorem ne_of_not_mem_cons {a b : T} {l : list T} : a β b::l β a β b :=
assume nin aeqb, absurd (or.inl aeqb) nin
theorem not_mem_of_not_mem_cons {a b : T} {l : list T} : a β b::l β a β l :=
assume nin nainl, absurd (or.inr nainl) nin
lemma not_mem_cons_of_ne_of_not_mem {x y : T} {l : list T} : x β y β x β l β x β y::l :=
assume P1 P2, not.intro (assume Pxin, absurd (eq_or_mem_of_mem_cons Pxin) (not_or P1 P2))
lemma ne_and_not_mem_of_not_mem_cons {x y : T} {l : list T} : x β y::l β x β y β§ x β l :=
assume P, and.intro (ne_of_not_mem_cons P) (not_mem_of_not_mem_cons P)
definition sublist (lβ lβ : list T) := β β¦a : Tβ¦, a β lβ β a β lβ
infix β := sublist
theorem nil_sub [simp] (l : list T) : [] β l :=
Ξ» b i, false.elim (iff.mp (mem_nil_iff b) i)
theorem sub.refl [simp] (l : list T) : l β l :=
Ξ» b i, i
theorem sub.trans {lβ lβ lβ : list T} (Hβ : lβ β lβ) (Hβ : lβ β lβ) : lβ β lβ :=
Ξ» b i, Hβ (Hβ i)
theorem sub_cons [simp] (a : T) (l : list T) : l β a::l :=
Ξ» b i, or.inr i
theorem sub_of_cons_sub {a : T} {lβ lβ : list T} : a::lβ β lβ β lβ β lβ :=
Ξ» s b i, s b (mem_cons_of_mem _ i)
theorem cons_sub_cons {lβ lβ : list T} (a : T) (s : lβ β lβ) : (a::lβ) β (a::lβ) :=
Ξ» b Hin, or.elim (eq_or_mem_of_mem_cons Hin)
(Ξ» e : b = a, or.inl e)
(Ξ» i : b β lβ, or.inr (s i))
theorem sub_append_left [simp] (lβ lβ : list T) : lβ β lβ++lβ :=
Ξ» b i, iff.mpr (mem_append_iff b lβ lβ) (or.inl i)
theorem sub_append_right [simp] (lβ lβ : list T) : lβ β lβ++lβ :=
Ξ» b i, iff.mpr (mem_append_iff b lβ lβ) (or.inr i)
theorem sub_cons_of_sub (a : T) {lβ lβ : list T} : lβ β lβ β lβ β (a::lβ) :=
Ξ» (s : lβ β lβ) (x : T) (i : x β lβ), or.inr (s i)
theorem sub_app_of_sub_left (l lβ lβ : list T) : l β lβ β l β lβ++lβ :=
Ξ» (s : l β lβ) (x : T) (xinl : x β l),
have x β lβ, from s xinl,
mem_append_of_mem_or_mem (or.inl this)
theorem sub_app_of_sub_right (l lβ lβ : list T) : l β lβ β l β lβ++lβ :=
Ξ» (s : l β lβ) (x : T) (xinl : x β l),
have x β lβ, from s xinl,
mem_append_of_mem_or_mem (or.inr this)
theorem cons_sub_of_sub_of_mem {a : T} {l m : list T} : a β m β l β m β a::l β m :=
Ξ» (ainm : a β m) (lsubm : l β m) (x : T) (xinal : x β a::l), or.elim (eq_or_mem_of_mem_cons xinal)
(suppose x = a, by substvars; exact ainm)
(suppose x β l, lsubm this)
theorem app_sub_of_sub_of_sub {lβ lβ l : list T} : lβ β l β lβ β l β lβ++lβ β l :=
Ξ» (lβsubl : lβ β l) (lβsubl : lβ β l) (x : T) (xinlβlβ : x β lβ++lβ),
or.elim (mem_or_mem_of_mem_append xinlβlβ)
(suppose x β lβ, lβsubl this)
(suppose x β lβ, lβsubl this)
/- find -/
section
variable [H : decidable_eq T]
include H
definition find : T β list T β nat
| a [] := 0
| a (b :: l) := if a = b then 0 else succ (find a l)
theorem find_nil [simp] (x : T) : find x [] = 0 :=
rfl
theorem find_cons (x y : T) (l : list T) : find x (y::l) = if x = y then 0 else succ (find x l) :=
rfl
theorem find_cons_of_eq {x y : T} (l : list T) : x = y β find x (y::l) = 0 :=
assume e, if_pos e
theorem find_cons_of_ne {x y : T} (l : list T) : x β y β find x (y::l) = succ (find x l) :=
assume n, if_neg n
theorem find_of_not_mem {l : list T} {x : T} : Β¬x β l β find x l = length l :=
list.rec_on l
(suppose Β¬x β [], rfl)
(take y l,
assume iH : Β¬x β l β find x l = length l,
suppose Β¬x β y::l,
have Β¬(x = y β¨ x β l), from iff.elim_right (not_iff_not_of_iff !mem_cons_iff) this,
have Β¬x = y β§ Β¬x β l, from (iff.elim_left !not_or_iff_not_and_not this),
calc
find x (y::l) = if x = y then 0 else succ (find x l) : !find_cons
... = succ (find x l) : if_neg (and.elim_left this)
... = succ (length l) : {iH (and.elim_right this)}
... = length (y::l) : !length_consβ»ΒΉ)
lemma find_le_length : β {a} {l : list T}, find a l β€ length l
| a [] := !le.refl
| a (b::l) := decidable.rec_on (H a b)
(assume Peq, by rewrite [find_cons_of_eq l Peq]; exact !zero_le)
(assume Pne,
begin
rewrite [find_cons_of_ne l Pne, length_cons],
apply succ_le_succ, apply find_le_length
end)
lemma not_mem_of_find_eq_length : β {a} {l : list T}, find a l = length l β a β l
| a [] := assume Peq, !not_mem_nil
| a (b::l) := decidable.rec_on (H a b)
(assume Peq, by rewrite [find_cons_of_eq l Peq, length_cons]; contradiction)
(assume Pne,
begin
rewrite [find_cons_of_ne l Pne, length_cons, mem_cons_iff],
intro Plen, apply (not_or Pne),
exact not_mem_of_find_eq_length (succ.inj Plen)
end)
lemma find_lt_length {a} {l : list T} (Pin : a β l) : find a l < length l :=
begin
apply nat.lt_of_le_and_ne,
apply find_le_length,
apply not.intro, intro Peq,
exact absurd Pin (not_mem_of_find_eq_length Peq)
end
end
/- nth element -/
section nth
definition nth : list T β nat β option T
| [] n := none
| (a :: l) 0 := some a
| (a :: l) (n+1) := nth l n
theorem nth_zero [simp] (a : T) (l : list T) : nth (a :: l) 0 = some a :=
rfl
theorem nth_succ [simp] (a : T) (l : list T) (n : nat) : nth (a::l) (succ n) = nth l n :=
rfl
theorem nth_eq_some : β {l : list T} {n : nat}, n < length l β Ξ£ a : T, nth l n = some a
| [] n h := absurd h !not_lt_zero
| (a::l) 0 h := β¨a, rflβ©
| (a::l) (succ n) h :=
have n < length l, from lt_of_succ_lt_succ h,
obtain (r : T) (req : nth l n = some r), from nth_eq_some this,
β¨r, by rewrite [nth_succ, req]β©
open decidable
theorem find_nth [decidable_eq T] {a : T} : β {l}, a β l β nth l (find a l) = some a
| [] ain := absurd ain !not_mem_nil
| (b::l) ainbl := by_cases
(Ξ» aeqb : a = b, by rewrite [find_cons_of_eq _ aeqb, nth_zero, aeqb])
(Ξ» aneb : a β b, or.elim (eq_or_mem_of_mem_cons ainbl)
(Ξ» aeqb : a = b, absurd aeqb aneb)
(Ξ» ainl : a β l, by rewrite [find_cons_of_ne _ aneb, nth_succ, find_nth ainl]))
definition inth [h : inhabited T] (l : list T) (n : nat) : T :=
match nth l n with
| some a := a
| none := arbitrary T
end
theorem inth_zero [inhabited T] (a : T) (l : list T) : inth (a :: l) 0 = a :=
rfl
theorem inth_succ [inhabited T] (a : T) (l : list T) (n : nat) : inth (a::l) (n+1) = inth l n :=
rfl
end nth
section ith
definition ith : Ξ (l : list T) (i : nat), i < length l β T
| nil i h := absurd h !not_lt_zero
| (x::xs) 0 h := x
| (x::xs) (succ i) h := ith xs i (lt_of_succ_lt_succ h)
lemma ith_zero [simp] (a : T) (l : list T) (h : 0 < length (a::l)) : ith (a::l) 0 h = a :=
rfl
lemma ith_succ [simp] (a : T) (l : list T) (i : nat) (h : succ i < length (a::l))
: ith (a::l) (succ i) h = ith l i (lt_of_succ_lt_succ h) :=
rfl
end ith
open decidable
definition has_decidable_eq {A : Type} [H : decidable_eq A] : β lβ lβ : list A, decidable (lβ = lβ)
| [] [] := inl rfl
| [] (b::lβ) := inr (by contradiction)
| (a::lβ) [] := inr (by contradiction)
| (a::lβ) (b::lβ) :=
match H a b with
| inl Hab :=
match has_decidable_eq lβ lβ with
| inl He := inl (by congruence; repeat assumption)
| inr Hn := inr (by intro H; injection H; contradiction)
end
| inr Hnab := inr (by intro H; injection H; contradiction)
end
/- quasiequal a l l' means that l' is exactly l, with a added
once somewhere -/
section qeq
variable {A : Type}
inductive qeq (a : A) : list A β list A β Prop :=
| qhead : β l, qeq a l (a::l)
| qcons : β (b : A) {l l' : list A}, qeq a l l' β qeq a (b::l) (b::l')
open qeq
notation l' `β`:50 a `|` l:50 := qeq a l l'
theorem qeq_app : β (lβ : list A) (a : A) (lβ : list A), lβ++(a::lβ) β a|lβ++lβ
| [] a lβ := qhead a lβ
| (x::xs) a lβ := qcons x (qeq_app xs a lβ)
theorem mem_head_of_qeq {a : A} {lβ lβ : list A} : lββa|lβ β a β lβ :=
take q, qeq.induction_on q
(Ξ» l, !mem_cons)
(Ξ» b l l' q r, or.inr r)
theorem mem_tail_of_qeq {a : A} {lβ lβ : list A} : lββa|lβ β β x, x β lβ β x β lβ :=
take q, qeq.induction_on q
(Ξ» l x i, or.inr i)
(Ξ» b l l' q r x xinbl, or.elim (eq_or_mem_of_mem_cons xinbl)
(Ξ» xeqb : x = b, xeqb βΈ mem_cons x l')
(Ξ» xinl : x β l, or.inr (r x xinl)))
theorem mem_cons_of_qeq {a : A} {lβ lβ : list A} : lββa|lβ β β x, x β lβ β x β a::lβ :=
take q, qeq.induction_on q
(Ξ» l x i, i)
(Ξ» b l l' q r x xinbl', or.elim (eq_or_mem_of_mem_cons xinbl')
(Ξ» xeqb : x = b, xeqb βΈ or.inr (mem_cons x l))
(Ξ» xinl' : x β l', or.elim (eq_or_mem_of_mem_cons (r x xinl'))
(Ξ» xeqa : x = a, xeqa βΈ mem_cons x (b::l))
(Ξ» xinl : x β l, or.inr (or.inr xinl))))
theorem length_eq_of_qeq {a : A} {lβ lβ : list A} : lββa|lβ β length lβ = succ (length lβ) :=
take q, qeq.induction_on q
(Ξ» l, rfl)
(Ξ» b l l' q r, by rewrite [*length_cons, r])
theorem qeq_of_mem {a : A} {l : list A} : a β l β (βl', lβa|l') :=
list.induction_on l
(Ξ» h : a β nil, absurd h (not_mem_nil a))
(Ξ» x xs r ainxxs, or.elim (eq_or_mem_of_mem_cons ainxxs)
(Ξ» aeqx : a = x,
have aux : β l, x::xsβx|l, from
exists.intro xs (qhead x xs),
by rewrite aeqx; exact aux)
(Ξ» ainxs : a β xs,
have βl', xs β a|l', from r ainxs,
obtain (l' : list A) (q : xs β a|l'), from this,
have x::xs β a | x::l', from qcons x q,
exists.intro (x::l') this))
theorem qeq_split {a : A} {l l' : list A} : l'βa|l β βlβ lβ, l = lβ++lβ β§ l' = lβ++(a::lβ) :=
take q, qeq.induction_on q
(Ξ» t,
have t = []++t β§ a::t = []++(a::t), from and.intro rfl rfl,
exists.intro [] (exists.intro t this))
(Ξ» b t t' q r,
obtain (lβ lβ : list A) (h : t = lβ++lβ β§ t' = lβ++(a::lβ)), from r,
have b::t = (b::lβ)++lβ β§ b::t' = (b::lβ)++(a::lβ),
begin
rewrite [and.elim_right h, and.elim_left h],
constructor, repeat reflexivity
end,
exists.intro (b::lβ) (exists.intro lβ this))
theorem sub_of_mem_of_sub_of_qeq {a : A} {l : list A} {u v : list A} : a β l β a::l β v β vβa|u β l β u :=
Ξ» (nainl : a β l) (s : a::l β v) (q : vβa|u) (x : A) (xinl : x β l),
have x β v, from s (or.inr xinl),
have x β a::u, from mem_cons_of_qeq q x this,
or.elim (eq_or_mem_of_mem_cons this)
(suppose x = a, by substvars; contradiction)
(suppose x β u, this)
end qeq
section firstn
variable {A : Type}
definition firstn : nat β list A β list A
| 0 l := []
| (n+1) [] := []
| (n+1) (a::l) := a :: firstn n l
lemma firstn_zero [simp] : β (l : list A), firstn 0 l = [] :=
by intros; reflexivity
lemma firstn_nil [simp] : β n, firstn n [] = ([] : list A)
| 0 := rfl
| (n+1) := rfl
lemma firstn_cons : β n (a : A) (l : list A), firstn (succ n) (a::l) = a :: firstn n l :=
by intros; reflexivity
lemma firstn_all : β (l : list A), firstn (length l) l = l
| [] := rfl
| (a::l) := begin unfold [length, firstn], rewrite firstn_all end
lemma firstn_all_of_ge : β {n} {l : list A}, n β₯ length l β firstn n l = l
| 0 [] h := rfl
| 0 (a::l) h := absurd h (not_le_of_gt !succ_pos)
| (n+1) [] h := rfl
| (n+1) (a::l) h := begin unfold firstn, rewrite [firstn_all_of_ge (le_of_succ_le_succ h)] end
lemma firstn_firstn : β (n m) (l : list A), firstn n (firstn m l) = firstn (min n m) l
| n 0 l := by rewrite [min_zero, firstn_zero, firstn_nil]
| 0 m l := by rewrite [zero_min]
| (succ n) (succ m) nil := by rewrite [*firstn_nil]
| (succ n) (succ m) (a::l) := by rewrite [*firstn_cons, firstn_firstn, min_succ_succ]
lemma length_firstn_le : β (n) (l : list A), length (firstn n l) β€ n
| 0 l := by rewrite [firstn_zero]
| (succ n) (a::l) := by rewrite [firstn_cons, length_cons, add_one]; apply succ_le_succ; apply length_firstn_le
| (succ n) [] := by rewrite [firstn_nil, length_nil]; apply zero_le
lemma length_firstn_eq : β (n) (l : list A), length (firstn n l) = min n (length l)
| 0 l := by rewrite [firstn_zero, zero_min]
| (succ n) (a::l) := by rewrite [firstn_cons, *length_cons, *add_one, min_succ_succ, length_firstn_eq]
| (succ n) [] := by rewrite [firstn_nil]
end firstn
section dropn
variables {A : Type}
-- 'dropn n l' drops the first 'n' elements of 'l'
definition dropn : β β list A β list A
| 0 a := a
| (succ n) [] := []
| (succ n) (x::r) := dropn n r
theorem length_dropn
: β (i : β) (l : list A), length (dropn i l) = length l - i
| 0 l := rfl
| (succ i) [] := calc
length (dropn (succ i) []) = 0 - succ i : nat.zero_sub (succ i)
| (succ i) (x::l) := calc
length (dropn (succ i) (x::l))
= length (dropn i l) : rfl
... = length l - i : length_dropn i l
... = succ (length l) - succ i : succ_sub_succ (length l) i
end dropn
section count
variable {A : Type}
variable [decA : decidable_eq A]
include decA
definition count (a : A) : list A β nat
| [] := 0
| (x::xs) := if a = x then succ (count xs) else count xs
lemma count_nil (a : A) : count a [] = 0 :=
rfl
lemma count_cons (a b : A) (l : list A) : count a (b::l) = if a = b then succ (count a l) else count a l :=
rfl
lemma count_cons_eq (a : A) (l : list A) : count a (a::l) = succ (count a l) :=
if_pos rfl
lemma count_cons_of_ne {a b : A} (h : a β b) (l : list A) : count a (b::l) = count a l :=
if_neg h
lemma count_cons_ge_count (a b : A) (l : list A) : count a (b::l) β₯ count a l :=
by_cases
(suppose a = b, begin subst b, rewrite count_cons_eq, apply le_succ end)
(suppose a β b, begin rewrite (count_cons_of_ne this), apply le.refl end)
lemma count_singleton (a : A) : count a [a] = 1 :=
by rewrite count_cons_eq
lemma count_append (a : A) : β lβ lβ, count a (lβ++lβ) = count a lβ + count a lβ
| [] lβ := by rewrite [append_nil_left, count_nil, zero_add]
| (b::lβ) lβ := by_cases
(suppose a = b, by rewrite [-this, append_cons, *count_cons_eq, succ_add, count_append])
(suppose a β b, by rewrite [append_cons, *count_cons_of_ne this, count_append])
lemma count_concat (a : A) (l : list A) : count a (concat a l) = succ (count a l) :=
by rewrite [concat_eq_append, count_append, count_singleton]
lemma mem_of_count_gt_zero : β {a : A} {l : list A}, count a l > 0 β a β l
| a [] h := absurd h !lt.irrefl
| a (b::l) h := by_cases
(suppose a = b, begin subst b, apply mem_cons end)
(suppose a β b,
have count a l > 0, by rewrite [count_cons_of_ne this at h]; exact h,
have a β l, from mem_of_count_gt_zero this,
show a β b::l, from mem_cons_of_mem _ this)
lemma count_gt_zero_of_mem : β {a : A} {l : list A}, a β l β count a l > 0
| a [] h := absurd h !not_mem_nil
| a (b::l) h := or.elim h
(suppose a = b, begin subst b, rewrite count_cons_eq, apply zero_lt_succ end)
(suppose a β l, calc
count a (b::l) β₯ count a l : count_cons_ge_count
... > 0 : count_gt_zero_of_mem this)
lemma count_eq_zero_of_not_mem {a : A} {l : list A} (h : a β l) : count a l = 0 :=
match count a l with
| zero := suppose count a l = zero, this
| (succ n) := suppose count a l = succ n, absurd (mem_of_count_gt_zero (begin rewrite this, exact dec_trivial end)) h
end rfl
end count
end list
attribute list.has_decidable_eq [instance]
attribute list.decidable_mem [instance]
|
47bfaa0b53f3e9fd1cac95342f95ec69ea8e71ed | f2fbd9ce3f46053c664b74a5294d7d2f584e72d3 | /src/for_mathlib/topological_structures.lean | ed01c7c2cbe2c3f7b9a3052a33c35550f5a3eeb7 | [
"Apache-2.0"
] | permissive | jcommelin/lean-perfectoid-spaces | c656ae26a2338ee7a0072dab63baf577f079ca12 | d5ed816bcc116fd4cde5ce9aaf03905d00ee391c | refs/heads/master | 1,584,610,432,107 | 1,538,491,594,000 | 1,538,491,594,000 | 136,299,168 | 0 | 0 | null | 1,528,274,452,000 | 1,528,274,452,000 | null | UTF-8 | Lean | false | false | 12,569 | lean | import analysis.topology.topological_structures
import tactic.ring
import for_mathlib.completion
section
variables {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*}
/-- This is a helper lemma for associativity of addition in `completion_group_str`.
It could probably be inlined. TODO: prove every permutation of a finite product
of top spaces is continuous. -/
lemma continuous_pat_perm [topological_space Ξ±] [topological_space Ξ²] [topological_space Ξ³] :
continuous (Ξ» x : Ξ± Γ Ξ² Γ Ξ³, (x.2.2, (x.1, x.2.1))) :=
have c : continuous (Ξ» x : Ξ± Γ Ξ² Γ Ξ³, x.2.2) :=
continuous.comp continuous_snd continuous_snd,
have c' : continuous (Ξ» x : Ξ± Γ Ξ² Γ Ξ³, (x.1, x.2.1)) :=
continuous.prod_mk continuous_fst (continuous.comp continuous_snd continuous_fst),
continuous.prod_mk c c'
end
open filter
--lemma set.preimage_subset_iff {Ξ± : Type*} {Ξ² : Type*} {A : set Ξ±} {B : set Ξ²} {f : Ξ± β Ξ²} :
-- (β a : Ξ±, f a β B β a β A) β fβ»ΒΉ' B β A :=
--β¨Ξ» H x h, H x h, Ξ» H x h, H hβ©
--lemma comap_eq_of_inverse {Ξ± : Type*} {Ξ² : Type*} {f : filter Ξ±} {g : filter Ξ²}
-- {Ο : Ξ± β Ξ²} {Ο : Ξ² β Ξ±} (invβ : Ο β Ο = id) (invβ : Ο β Ο = id)
-- (limβ : tendsto Ο f g) (limβ : tendsto Ο g f)
-- : comap Ο g = f :=
--begin
-- have ineqβ := calc
-- comap Ο g = map Ο g : eq.symm (map_eq_comap_of_inverse invβ invβ)
-- ... β€ f : limβ,
-- have ineqβ : f β€ comap Ο g := map_le_iff_le_comap.1 limβ,
-- exact le_antisymm ineqβ ineqβ
--end
--lemma pure_le_nhds {Ξ± : Type*} [topological_space Ξ±] (a : Ξ±) : pure a β€ nhds a :=
--assume s s_nhds, by simp[mem_of_nhds s_nhds]
section topological_add_group
universe u
variables {G : Type u} [add_group G] [topological_space G] [topological_add_group G]
lemma half_nhd (U β (nhds (0 : G)).sets) :
β V β (nhds (0 : G)).sets, β v w β V, v + w β U :=
/- Here is the story : by continuity of addition, and because 0 + 0 = 0,
(+)β»ΒΉ(U) is a neighborhood of (0, 0). Hence it contains some Vβ Γ Vβ. Then set V = Vβ β© Vβ -/
begin
have nhdb_in_prod : ((Ξ» a : G Γ G, a.1+a.2)β»ΒΉ' U) β (nhds ((0, 0) : G Γ G)).sets,
by apply tendsto_add' ; simp [H],
rw nhds_prod_eq at nhdb_in_prod,
rcases mem_prod_iff.1 nhdb_in_prod with β¨Vβ, Hβ, Vβ, Hβ, Hβ©,
have H12: Vβ β© Vβ β (nhds (0 : G)).sets := inter_mem_sets Hβ Hβ,
existsi [(Vβ β© Vβ), H12],
intros v w Hv Hw,
have : (v,w) β set.prod Vβ Vβ, by finish,
simpa using H this
end
lemma quarter_nhd (U β (nhds (0 : G)).sets) :
β V β (nhds (0 : G)).sets, β {v w s t}, v β V β w β V β s β V β t β V β v + w + s + t β U :=
begin
rcases half_nhd U H with β¨W, W_nhd, hβ©,
rcases half_nhd W W_nhd with β¨V, V_nhd, h'β©,
existsi [V, V_nhd],
intros v w s t v_in w_in s_in t_in,
simpa using h _ _ (h' v w v_in w_in) (h' s t s_in t_in)
end
lemma continuous_translation (a : G) : continuous (Ξ» b, b + a) :=
have cont : continuous (Ξ» b : G, (b, a)) := continuous.prod_mk continuous_id continuous_const,
by simp[continuous.comp cont continuous_add']
lemma continuous_neg_translation (a : G) :
continuous (Ξ» b, b - a) := continuous_translation (-a)
variable (G)
lemma nhds_zero_symm : comap (Ξ» r : G, -r) (nhds (0 : G)) = nhds (0 : G) :=
begin
let neg := (Ξ» r : G, -r),
have inv : neg β neg = id, { funext x, simp[neg_eq_iff_neg_eq] },
have lim : tendsto neg (nhds 0) (nhds 0) :=
by simpa using continuous.tendsto (topological_add_group.continuous_neg G) 0,
exact comap_eq_of_inverse inv inv lim lim
end
variable {G}
lemma nhds_translation (x : G) : nhds x = comap (Ξ» y, y-x) (nhds (0 : G)) :=
begin
have limβ : tendsto (Ξ» (y : G), y-x) (nhds x) (nhds 0),
by simpa using continuous.tendsto (continuous_neg_translation x) x,
have limβ : tendsto (Ξ» (y : G), y+x) (nhds 0) (nhds x),
by simpa using continuous.tendsto (continuous_translation x) 0,
have invβ : (Ξ» y, y-x) β (Ξ» y, y+x) = id, by {funext x, dsimp[id, (β)], rw [add_assoc, add_right_neg], simp },
have invβ : (Ξ» y, y+x) β (Ξ» y, y-x) = id, by {funext x, dsimp[id, (β)], simp, },
exact eq.symm (comap_eq_of_inverse invβ invβ limβ limβ)
end
end topological_add_group
section topological_add_comm_group
universe u
variables {G : Type u} [add_comm_group G] [topological_space G] [topological_add_group G]
def Ξ΄ : G Γ G β G := Ξ» p, p.2 - p.1
def Ξ : filter (G Γ G) := principal id_rel
variable (G)
instance topological_add_group.to_uniform_space : uniform_space G :=
{ uniformity := comap Ξ΄ (nhds 0),
refl :=
begin
suffices : map Ξ΄ Ξ β€ nhds (0: G), from map_le_iff_le_comap.1 this,
suffices : map Ξ΄ Ξ β€ pure (0 : G), from le_trans this (pure_le_nhds 0),
dsimp [Ξ],
rw map_principal,
have : (Ξ΄ '' id_rel : set G) = {(0 : G)},
{ ext,
simp [Ξ΄, id_rel],
split; try { intro H, existsi (0 : G) } ; finish },
finish
end,
symm :=
begin
suffices : comap Ξ΄ (nhds (0 : G)) β€ comap prod.swap (comap Ξ΄ (nhds (0 : G))),
from map_le_iff_le_comap.2 this,
suffices : comap Ξ΄ (nhds (0 : G)) β€ comap (Ξ΄ β prod.swap) (nhds (0 : G)),
by simp[comap_comap_comp, this],
have Ξ΄_swap : (Ξ΄ β prod.swap : G Γ G β G) = (Ξ» p, -p) β Ξ΄, by {funext, simp[Ξ΄] },
have : comap (Ξ΄ β prod.swap) (nhds (0 : G)) = comap Ξ΄ (nhds 0),
by rw [Ξ΄_swap, βcomap_comap_comp, nhds_zero_symm G],
finish
end,
comp :=
begin
intros D H,
rw mem_lift'_sets,
{ rcases H with β¨U, U_nhds, U_subβ©,
rcases half_nhd U U_nhds with β¨V, β¨V_nhds, V_sumβ©β©,
existsi Ξ΄β»ΒΉ'V,
have H : Ξ΄β»ΒΉ'V β (comap Ξ΄ (nhds (0 : G))).sets,
by existsi [V, V_nhds] ; refl,
existsi H,
have comp_rel_sub : comp_rel (Ξ΄β»ΒΉ'V) (Ξ΄β»ΒΉ'V) β Ξ΄β»ΒΉ' U,
begin
intros p p_comp_rel,
rcases p_comp_rel with β¨z, β¨Hz1, Hz2β©β©,
simpa[Ξ΄] using V_sum _ _ Hz1 Hz2
end,
exact set.subset.trans comp_rel_sub U_sub },
{ exact monotone_comp_rel monotone_id monotone_id }
end,
is_open_uniformity :=
begin
intro S,
let S' := Ξ» x, {p : G Γ G | p.1 = x β p.2 β S},
change is_open S β β (x : G), x β S β S' x β (comap Ξ΄ (nhds (0 : G))).sets,
have := calc
is_open S β β (x : G), x β S β S β (nhds x).sets : is_open_iff_mem_nhds
... β β (x : G), x β S β S β (comap (Ξ» y, y-x) (nhds (0:G))).sets : by conv in (_ β _) {rw (nhds_translation x)},
have : (β x β S, S β (comap (Ξ» y, y-x) (nhds (0 : G))).sets) β (β x β S, S' x β (comap Ξ΄ (nhds (0 : G))).sets),
{ split ; intros H x x_in_S ; specialize H x x_in_S;
{ rcases H with β¨U, U_nhds, U_propβ©,
existsi [U, U_nhds],
have := calc
(Ξ» y, y-x)β»ΒΉ' U β S β (β y, y-x β U β y β S) : set.preimage_subset_iff
... β (β p : G Γ G, p.2-p.1 β U β p.1 = x β p.2 β S) :
begin
split,
{ intros H h h' h'',
apply H, cc },
{ intros H y h,
specialize H (x,y),
finish }
end
... β (β p : G Γ G, Ξ΄ p β U β p β S' x) : by simp[Ξ΄, S' x]
... β Ξ΄β»ΒΉ'U β S' x : set.preimage_subset_iff,
cc } },
cc
end,}
variable {G}
lemma uniformity_eq_comap_nhds_zero : uniformity = comap Ξ΄ (nhds (0 : G)) := rfl
instance topological_add_group_is_uniform : uniform_add_group G :=
β¨begin
rw [uniform_continuous, uniformity_prod_eq_prod],
apply tendsto_map',
apply tendsto_comap_iff.2,
suffices : tendsto (Ξ» (x : (G Γ G) Γ G Γ G), (x.1).2 - (x.1).1 - ((x.2).2 - (x.2).1))
(filter.prod uniformity uniformity)
(nhds 0),
{ simpa [(β), Ξ΄] },
suffices : tendsto (Ξ» (x : (G Γ G) Γ G Γ G), (x.1).2 - (x.1).1 - ((x.2).2 - (x.2).1))
(comap (Ξ» (p : (G Γ G) Γ G Γ G), ((p.1).2 - (p.1).1, (p.2).2 - (p.2).1))
(filter.prod (nhds 0) (nhds 0)))
(nhds 0),
by simpa [(β), Ξ΄, uniformity_eq_comap_nhds_zero, prod_comap_comap_eq, -sub_eq_add_neg],
conv { for (nhds _) [3] { rw [show (0:G) = 0 - 0, by simp] }},
exact tendsto_sub (tendsto.comp tendsto_comap tendsto_fst) (tendsto.comp tendsto_comap tendsto_snd),
endβ©
variables {H : Type*} [add_comm_group H] [topological_space H] [topological_add_group H]
lemma uniform_continuous_of_continuous {f : G β H} [is_add_group_hom f] (h : continuous f) :
uniform_continuous f :=
begin
simp only [uniform_continuous, uniformity_eq_comap_nhds_zero],
rw [tendsto_iff_comap, comap_comap_comp],
change comap Ξ΄ (nhds 0) β€ comap ( Ξ» (x : G Γ G), f x.2 - f x.1) (nhds 0),
have : (Ξ» (x : G Γ G), f (x.snd) - f (x.fst)) = Ξ» (x : G Γ G), f (x.snd - x.fst),
by simp only [is_add_group_hom.sub f],
rw [this, βtendsto_iff_comap],
exact tendsto.comp tendsto_comap (is_add_group_hom.zero f βΈ continuous.tendsto h (0:G))
end
lemma inter_comap_sets {Ξ± : Type*} {Ξ²: Type*} (f : Ξ± β Ξ²) (F : filter Ξ²) :
ββ(comap f F).sets = β U β F.sets, f β»ΒΉ' U :=
begin
ext x,
suffices : (β (A : set Ξ±) (B : set Ξ²), B β F.sets β f β»ΒΉ' B β A β x β A) β
β (B : set Ξ²), B β F.sets β f x β B,
by simp [set.mem_sInter, set.mem_Inter, mem_comap_sets, this],
split,
{ intros h U U_in,
simpa [set.subset.refl] using h (f β»ΒΉ' U) U U_in },
{ intros h V U U_in f_U_V,
exact f_U_V (h U U_in) },
end
lemma set.inter_singleton_neq_empty {Ξ± : Type*} {s : set Ξ±} {a : Ξ±} : s β© {a} β β
β a β s :=
by finish [set.inter_singleton_eq_empty]
lemma group_separation_rel (x y : G) : (x, y) β separation_rel G β x - y β closure ({0} : set G) :=
begin
change (x, y) β ββ uniformity.sets β x - y β closure ({0} : set G),
rw uniformity_eq_comap_nhds_zero,
rw inter_comap_sets,
rw mem_closure_iff_nhds,
rw nhds_translation (x - y),
simp [-sub_eq_add_neg, set.inter_singleton_eq_empty, Ξ΄],
split,
{ rintros h U V V_in h',
specialize h V V_in,
suffices : (0:G) β U, by finish,
have : (0:G) β (Ξ» z, z - (x - y)) β»ΒΉ' V,
by simpa using h,
exact h' this },
{ intros h U U_nhd,
specialize h ((Ξ» z, z+x-y) '' U) U U_nhd,
have li : function.left_inverse (Ξ» (z : G), z + x - y) (Ξ» (y_1 : G), y_1 - (x - y)),
{ intro z,
simp,
rw βadd_assoc,
simp [add_assoc, add_comm] },
have := h (set.preimage_subset_image_of_inverse li U),
have : (0:G) β ((Ξ» (z : G), z + x - y) '' U), by finish,
have ri : function.right_inverse (Ξ» (z : G), z + x - y) (Ξ» (y_1 : G), y_1 - (x - y)),
{ intro z,
simp,
rw βadd_assoc,
simp [add_assoc, add_comm] },
rw set.mem_image_iff_of_inverse ri li at this,
simpa using this }
end
section
variables {E : Type*} [topological_space E] [add_comm_group E] [topological_add_group E]
-- A is a dense subgroup of E, inclusion is denoted by e
variables {A : Type*} [topological_space A] [add_comm_group A] [topological_add_group A]
variables {e : A β E} [is_add_group_hom e] (de : dense_embedding e)
include de
lemma tendsto_sub_comap_self (xβ : E) :
tendsto (Ξ» (t : A Γ A), t.2 - t.1) (comap (Ξ» p : A Γ A, (e p.1, e p.2)) $ nhds (xβ, xβ)) (nhds 0) :=
begin
have comm : (Ξ» x : E Γ E, x.2-x.1) β (Ξ» (t : A Γ A), (e t.1, e t.2)) = e β (Ξ» (t : A Γ A), t.2 - t.1),
{ ext t,
change e t.2 - e t.1 = e (t.2 - t.1),
rwa β is_add_group_hom.sub e t.2 t.1 },
have lim : tendsto (Ξ» x : E Γ E, x.2-x.1) (nhds (xβ, xβ)) (nhds (e 0)),
{ have := continuous.tendsto (continuous.comp continuous_swap continuous_sub') (xβ, xβ),
simpa [-sub_eq_add_neg, sub_self, eq.symm (is_add_group_hom.zero e)] using this },
have := de.tendsto_comap_nhds_nhds lim comm,
simp [-sub_eq_add_neg, this]
end
end
end topological_add_comm_group
|
4fd1fa1243014e9a7eddb8d9e6a7a49363852a78 | 9dd3f3912f7321eb58ee9aa8f21778ad6221f87c | /tests/lean/run/record10.lean | dc833a745df642b85e8afb4e8d274213a489fa00 | [
"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 | 448 | lean | print prefix semigroup
print "======================="
structure [class] has_two_muls (A : Type) extends has_mul A renaming mulβmul1,
private has_mul A renaming mulβmul2
print prefix has_two_muls
print "======================="
structure [class] another_two_muls (A : Type) extends has_mul A renaming mulβmul1,
has_mul A renaming mulβmul2
|
55ac6428382f94d63568a60077c1d68afab3c8e8 | 592ee40978ac7604005a4e0d35bbc4b467389241 | /Library/generated/mathscheme-lean/AntiCommutativeRing.lean | ca828671cc0e7d1c0df69e74ffa9bce3631ee4f1 | [] | no_license | ysharoda/Deriving-Definitions | 3e149e6641fae440badd35ac110a0bd705a49ad2 | dfecb27572022de3d4aa702cae8db19957523a59 | refs/heads/master | 1,679,127,857,700 | 1,615,939,007,000 | 1,615,939,007,000 | 229,785,731 | 4 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 16,508 | lean | import init.data.nat.basic
import init.data.fin.basic
import data.vector
import .Prelude
open Staged
open nat
open fin
open vector
section AntiCommutativeRing
structure AntiCommutativeRing (A : Type) : Type :=
(times : (A β (A β A)))
(plus : (A β (A β A)))
(zero : A)
(lunit_zero : (β {x : A} , (plus zero x) = x))
(runit_zero : (β {x : A} , (plus x zero) = x))
(associative_plus : (β {x y z : A} , (plus (plus x y) z) = (plus x (plus y z))))
(commutative_plus : (β {x y : A} , (plus x y) = (plus y x)))
(associative_times : (β {x y z : A} , (times (times x y) z) = (times x (times y z))))
(leftDistributive_times_plus : (β {x y z : A} , (times x (plus y z)) = (plus (times x y) (times x z))))
(rightDistributive_times_plus : (β {x y z : A} , (times (plus y z) x) = (plus (times y x) (times z x))))
(neg : (A β A))
(leftInverse_inv_op_zero : (β {x : A} , (plus x (neg x)) = zero))
(rightInverse_inv_op_zero : (β {x : A} , (plus (neg x) x) = zero))
(one : A)
(lunit_one : (β {x : A} , (times one x) = x))
(runit_one : (β {x : A} , (times x one) = x))
(leftZero_op_zero : (β {x : A} , (times zero x) = zero))
(rightZero_op_zero : (β {x : A} , (times x zero) = zero))
(antiCommutative : (β {x y : A} , (times x y) = (neg (times y x))))
open AntiCommutativeRing
structure Sig (AS : Type) : Type :=
(timesS : (AS β (AS β AS)))
(plusS : (AS β (AS β AS)))
(zeroS : AS)
(negS : (AS β AS))
(oneS : AS)
structure Product (A : Type) : Type :=
(timesP : ((Prod A A) β ((Prod A A) β (Prod A A))))
(plusP : ((Prod A A) β ((Prod A A) β (Prod A A))))
(zeroP : (Prod A A))
(negP : ((Prod A A) β (Prod A A)))
(oneP : (Prod A A))
(lunit_0P : (β {xP : (Prod A A)} , (plusP zeroP xP) = xP))
(runit_0P : (β {xP : (Prod A A)} , (plusP xP zeroP) = xP))
(associative_plusP : (β {xP yP zP : (Prod A A)} , (plusP (plusP xP yP) zP) = (plusP xP (plusP yP zP))))
(commutative_plusP : (β {xP yP : (Prod A A)} , (plusP xP yP) = (plusP yP xP)))
(associative_timesP : (β {xP yP zP : (Prod A A)} , (timesP (timesP xP yP) zP) = (timesP xP (timesP yP zP))))
(leftDistributive_times_plusP : (β {xP yP zP : (Prod A A)} , (timesP xP (plusP yP zP)) = (plusP (timesP xP yP) (timesP xP zP))))
(rightDistributive_times_plusP : (β {xP yP zP : (Prod A A)} , (timesP (plusP yP zP) xP) = (plusP (timesP yP xP) (timesP zP xP))))
(leftInverse_inv_op_0P : (β {xP : (Prod A A)} , (plusP xP (negP xP)) = zeroP))
(rightInverse_inv_op_0P : (β {xP : (Prod A A)} , (plusP (negP xP) xP) = zeroP))
(lunit_1P : (β {xP : (Prod A A)} , (timesP oneP xP) = xP))
(runit_1P : (β {xP : (Prod A A)} , (timesP xP oneP) = xP))
(leftZero_op_0P : (β {xP : (Prod A A)} , (timesP zeroP xP) = zeroP))
(rightZero_op_0P : (β {xP : (Prod A A)} , (timesP xP zeroP) = zeroP))
(antiCommutativeP : (β {xP yP : (Prod A A)} , (timesP xP yP) = (negP (timesP yP xP))))
structure Hom {A1 : Type} {A2 : Type} (An1 : (AntiCommutativeRing A1)) (An2 : (AntiCommutativeRing A2)) : Type :=
(hom : (A1 β A2))
(pres_times : (β {x1 x2 : A1} , (hom ((times An1) x1 x2)) = ((times An2) (hom x1) (hom x2))))
(pres_plus : (β {x1 x2 : A1} , (hom ((plus An1) x1 x2)) = ((plus An2) (hom x1) (hom x2))))
(pres_zero : (hom (zero An1)) = (zero An2))
(pres_neg : (β {x1 : A1} , (hom ((neg An1) x1)) = ((neg An2) (hom x1))))
(pres_one : (hom (one An1)) = (one An2))
structure RelInterp {A1 : Type} {A2 : Type} (An1 : (AntiCommutativeRing A1)) (An2 : (AntiCommutativeRing A2)) : Type 1 :=
(interp : (A1 β (A2 β Type)))
(interp_times : (β {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) β ((interp x2 y2) β (interp ((times An1) x1 x2) ((times An2) y1 y2))))))
(interp_plus : (β {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) β ((interp x2 y2) β (interp ((plus An1) x1 x2) ((plus An2) y1 y2))))))
(interp_zero : (interp (zero An1) (zero An2)))
(interp_neg : (β {x1 : A1} {y1 : A2} , ((interp x1 y1) β (interp ((neg An1) x1) ((neg An2) y1)))))
(interp_one : (interp (one An1) (one An2)))
inductive AntiCommutativeRingTerm : Type
| timesL : (AntiCommutativeRingTerm β (AntiCommutativeRingTerm β AntiCommutativeRingTerm))
| plusL : (AntiCommutativeRingTerm β (AntiCommutativeRingTerm β AntiCommutativeRingTerm))
| zeroL : AntiCommutativeRingTerm
| negL : (AntiCommutativeRingTerm β AntiCommutativeRingTerm)
| oneL : AntiCommutativeRingTerm
open AntiCommutativeRingTerm
inductive ClAntiCommutativeRingTerm (A : Type) : Type
| sing : (A β ClAntiCommutativeRingTerm)
| timesCl : (ClAntiCommutativeRingTerm β (ClAntiCommutativeRingTerm β ClAntiCommutativeRingTerm))
| plusCl : (ClAntiCommutativeRingTerm β (ClAntiCommutativeRingTerm β ClAntiCommutativeRingTerm))
| zeroCl : ClAntiCommutativeRingTerm
| negCl : (ClAntiCommutativeRingTerm β ClAntiCommutativeRingTerm)
| oneCl : ClAntiCommutativeRingTerm
open ClAntiCommutativeRingTerm
inductive OpAntiCommutativeRingTerm (n : β) : Type
| v : ((fin n) β OpAntiCommutativeRingTerm)
| timesOL : (OpAntiCommutativeRingTerm β (OpAntiCommutativeRingTerm β OpAntiCommutativeRingTerm))
| plusOL : (OpAntiCommutativeRingTerm β (OpAntiCommutativeRingTerm β OpAntiCommutativeRingTerm))
| zeroOL : OpAntiCommutativeRingTerm
| negOL : (OpAntiCommutativeRingTerm β OpAntiCommutativeRingTerm)
| oneOL : OpAntiCommutativeRingTerm
open OpAntiCommutativeRingTerm
inductive OpAntiCommutativeRingTerm2 (n : β) (A : Type) : Type
| v2 : ((fin n) β OpAntiCommutativeRingTerm2)
| sing2 : (A β OpAntiCommutativeRingTerm2)
| timesOL2 : (OpAntiCommutativeRingTerm2 β (OpAntiCommutativeRingTerm2 β OpAntiCommutativeRingTerm2))
| plusOL2 : (OpAntiCommutativeRingTerm2 β (OpAntiCommutativeRingTerm2 β OpAntiCommutativeRingTerm2))
| zeroOL2 : OpAntiCommutativeRingTerm2
| negOL2 : (OpAntiCommutativeRingTerm2 β OpAntiCommutativeRingTerm2)
| oneOL2 : OpAntiCommutativeRingTerm2
open OpAntiCommutativeRingTerm2
def simplifyCl {A : Type} : ((ClAntiCommutativeRingTerm A) β (ClAntiCommutativeRingTerm A))
| (plusCl zeroCl x) := x
| (plusCl x zeroCl) := x
| (timesCl oneCl x) := x
| (timesCl x oneCl) := x
| (negCl (timesCl y x)) := (timesCl x y)
| (timesCl x1 x2) := (timesCl (simplifyCl x1) (simplifyCl x2))
| (plusCl x1 x2) := (plusCl (simplifyCl x1) (simplifyCl x2))
| zeroCl := zeroCl
| (negCl x1) := (negCl (simplifyCl x1))
| oneCl := oneCl
| (sing x1) := (sing x1)
def simplifyOpB {n : β} : ((OpAntiCommutativeRingTerm n) β (OpAntiCommutativeRingTerm n))
| (plusOL zeroOL x) := x
| (plusOL x zeroOL) := x
| (timesOL oneOL x) := x
| (timesOL x oneOL) := x
| (negOL (timesOL y x)) := (timesOL x y)
| (timesOL x1 x2) := (timesOL (simplifyOpB x1) (simplifyOpB x2))
| (plusOL x1 x2) := (plusOL (simplifyOpB x1) (simplifyOpB x2))
| zeroOL := zeroOL
| (negOL x1) := (negOL (simplifyOpB x1))
| oneOL := oneOL
| (v x1) := (v x1)
def simplifyOp {n : β} {A : Type} : ((OpAntiCommutativeRingTerm2 n A) β (OpAntiCommutativeRingTerm2 n A))
| (plusOL2 zeroOL2 x) := x
| (plusOL2 x zeroOL2) := x
| (timesOL2 oneOL2 x) := x
| (timesOL2 x oneOL2) := x
| (negOL2 (timesOL2 y x)) := (timesOL2 x y)
| (timesOL2 x1 x2) := (timesOL2 (simplifyOp x1) (simplifyOp x2))
| (plusOL2 x1 x2) := (plusOL2 (simplifyOp x1) (simplifyOp x2))
| zeroOL2 := zeroOL2
| (negOL2 x1) := (negOL2 (simplifyOp x1))
| oneOL2 := oneOL2
| (v2 x1) := (v2 x1)
| (sing2 x1) := (sing2 x1)
def evalB {A : Type} : ((AntiCommutativeRing A) β (AntiCommutativeRingTerm β A))
| An (timesL x1 x2) := ((times An) (evalB An x1) (evalB An x2))
| An (plusL x1 x2) := ((plus An) (evalB An x1) (evalB An x2))
| An zeroL := (zero An)
| An (negL x1) := ((neg An) (evalB An x1))
| An oneL := (one An)
def evalCl {A : Type} : ((AntiCommutativeRing A) β ((ClAntiCommutativeRingTerm A) β A))
| An (sing x1) := x1
| An (timesCl x1 x2) := ((times An) (evalCl An x1) (evalCl An x2))
| An (plusCl x1 x2) := ((plus An) (evalCl An x1) (evalCl An x2))
| An zeroCl := (zero An)
| An (negCl x1) := ((neg An) (evalCl An x1))
| An oneCl := (one An)
def evalOpB {A : Type} {n : β} : ((AntiCommutativeRing A) β ((vector A n) β ((OpAntiCommutativeRingTerm n) β A)))
| An vars (v x1) := (nth vars x1)
| An vars (timesOL x1 x2) := ((times An) (evalOpB An vars x1) (evalOpB An vars x2))
| An vars (plusOL x1 x2) := ((plus An) (evalOpB An vars x1) (evalOpB An vars x2))
| An vars zeroOL := (zero An)
| An vars (negOL x1) := ((neg An) (evalOpB An vars x1))
| An vars oneOL := (one An)
def evalOp {A : Type} {n : β} : ((AntiCommutativeRing A) β ((vector A n) β ((OpAntiCommutativeRingTerm2 n A) β A)))
| An vars (v2 x1) := (nth vars x1)
| An vars (sing2 x1) := x1
| An vars (timesOL2 x1 x2) := ((times An) (evalOp An vars x1) (evalOp An vars x2))
| An vars (plusOL2 x1 x2) := ((plus An) (evalOp An vars x1) (evalOp An vars x2))
| An vars zeroOL2 := (zero An)
| An vars (negOL2 x1) := ((neg An) (evalOp An vars x1))
| An vars oneOL2 := (one An)
def inductionB {P : (AntiCommutativeRingTerm β Type)} : ((β (x1 x2 : AntiCommutativeRingTerm) , ((P x1) β ((P x2) β (P (timesL x1 x2))))) β ((β (x1 x2 : AntiCommutativeRingTerm) , ((P x1) β ((P x2) β (P (plusL x1 x2))))) β ((P zeroL) β ((β (x1 : AntiCommutativeRingTerm) , ((P x1) β (P (negL x1)))) β ((P oneL) β (β (x : AntiCommutativeRingTerm) , (P x)))))))
| ptimesl pplusl p0l pnegl p1l (timesL x1 x2) := (ptimesl _ _ (inductionB ptimesl pplusl p0l pnegl p1l x1) (inductionB ptimesl pplusl p0l pnegl p1l x2))
| ptimesl pplusl p0l pnegl p1l (plusL x1 x2) := (pplusl _ _ (inductionB ptimesl pplusl p0l pnegl p1l x1) (inductionB ptimesl pplusl p0l pnegl p1l x2))
| ptimesl pplusl p0l pnegl p1l zeroL := p0l
| ptimesl pplusl p0l pnegl p1l (negL x1) := (pnegl _ (inductionB ptimesl pplusl p0l pnegl p1l x1))
| ptimesl pplusl p0l pnegl p1l oneL := p1l
def inductionCl {A : Type} {P : ((ClAntiCommutativeRingTerm A) β Type)} : ((β (x1 : A) , (P (sing x1))) β ((β (x1 x2 : (ClAntiCommutativeRingTerm A)) , ((P x1) β ((P x2) β (P (timesCl x1 x2))))) β ((β (x1 x2 : (ClAntiCommutativeRingTerm A)) , ((P x1) β ((P x2) β (P (plusCl x1 x2))))) β ((P zeroCl) β ((β (x1 : (ClAntiCommutativeRingTerm A)) , ((P x1) β (P (negCl x1)))) β ((P oneCl) β (β (x : (ClAntiCommutativeRingTerm A)) , (P x))))))))
| psing ptimescl ppluscl p0cl pnegcl p1cl (sing x1) := (psing x1)
| psing ptimescl ppluscl p0cl pnegcl p1cl (timesCl x1 x2) := (ptimescl _ _ (inductionCl psing ptimescl ppluscl p0cl pnegcl p1cl x1) (inductionCl psing ptimescl ppluscl p0cl pnegcl p1cl x2))
| psing ptimescl ppluscl p0cl pnegcl p1cl (plusCl x1 x2) := (ppluscl _ _ (inductionCl psing ptimescl ppluscl p0cl pnegcl p1cl x1) (inductionCl psing ptimescl ppluscl p0cl pnegcl p1cl x2))
| psing ptimescl ppluscl p0cl pnegcl p1cl zeroCl := p0cl
| psing ptimescl ppluscl p0cl pnegcl p1cl (negCl x1) := (pnegcl _ (inductionCl psing ptimescl ppluscl p0cl pnegcl p1cl x1))
| psing ptimescl ppluscl p0cl pnegcl p1cl oneCl := p1cl
def inductionOpB {n : β} {P : ((OpAntiCommutativeRingTerm n) β Type)} : ((β (fin : (fin n)) , (P (v fin))) β ((β (x1 x2 : (OpAntiCommutativeRingTerm n)) , ((P x1) β ((P x2) β (P (timesOL x1 x2))))) β ((β (x1 x2 : (OpAntiCommutativeRingTerm n)) , ((P x1) β ((P x2) β (P (plusOL x1 x2))))) β ((P zeroOL) β ((β (x1 : (OpAntiCommutativeRingTerm n)) , ((P x1) β (P (negOL x1)))) β ((P oneOL) β (β (x : (OpAntiCommutativeRingTerm n)) , (P x))))))))
| pv ptimesol pplusol p0ol pnegol p1ol (v x1) := (pv x1)
| pv ptimesol pplusol p0ol pnegol p1ol (timesOL x1 x2) := (ptimesol _ _ (inductionOpB pv ptimesol pplusol p0ol pnegol p1ol x1) (inductionOpB pv ptimesol pplusol p0ol pnegol p1ol x2))
| pv ptimesol pplusol p0ol pnegol p1ol (plusOL x1 x2) := (pplusol _ _ (inductionOpB pv ptimesol pplusol p0ol pnegol p1ol x1) (inductionOpB pv ptimesol pplusol p0ol pnegol p1ol x2))
| pv ptimesol pplusol p0ol pnegol p1ol zeroOL := p0ol
| pv ptimesol pplusol p0ol pnegol p1ol (negOL x1) := (pnegol _ (inductionOpB pv ptimesol pplusol p0ol pnegol p1ol x1))
| pv ptimesol pplusol p0ol pnegol p1ol oneOL := p1ol
def inductionOp {n : β} {A : Type} {P : ((OpAntiCommutativeRingTerm2 n A) β Type)} : ((β (fin : (fin n)) , (P (v2 fin))) β ((β (x1 : A) , (P (sing2 x1))) β ((β (x1 x2 : (OpAntiCommutativeRingTerm2 n A)) , ((P x1) β ((P x2) β (P (timesOL2 x1 x2))))) β ((β (x1 x2 : (OpAntiCommutativeRingTerm2 n A)) , ((P x1) β ((P x2) β (P (plusOL2 x1 x2))))) β ((P zeroOL2) β ((β (x1 : (OpAntiCommutativeRingTerm2 n A)) , ((P x1) β (P (negOL2 x1)))) β ((P oneOL2) β (β (x : (OpAntiCommutativeRingTerm2 n A)) , (P x)))))))))
| pv2 psing2 ptimesol2 pplusol2 p0ol2 pnegol2 p1ol2 (v2 x1) := (pv2 x1)
| pv2 psing2 ptimesol2 pplusol2 p0ol2 pnegol2 p1ol2 (sing2 x1) := (psing2 x1)
| pv2 psing2 ptimesol2 pplusol2 p0ol2 pnegol2 p1ol2 (timesOL2 x1 x2) := (ptimesol2 _ _ (inductionOp pv2 psing2 ptimesol2 pplusol2 p0ol2 pnegol2 p1ol2 x1) (inductionOp pv2 psing2 ptimesol2 pplusol2 p0ol2 pnegol2 p1ol2 x2))
| pv2 psing2 ptimesol2 pplusol2 p0ol2 pnegol2 p1ol2 (plusOL2 x1 x2) := (pplusol2 _ _ (inductionOp pv2 psing2 ptimesol2 pplusol2 p0ol2 pnegol2 p1ol2 x1) (inductionOp pv2 psing2 ptimesol2 pplusol2 p0ol2 pnegol2 p1ol2 x2))
| pv2 psing2 ptimesol2 pplusol2 p0ol2 pnegol2 p1ol2 zeroOL2 := p0ol2
| pv2 psing2 ptimesol2 pplusol2 p0ol2 pnegol2 p1ol2 (negOL2 x1) := (pnegol2 _ (inductionOp pv2 psing2 ptimesol2 pplusol2 p0ol2 pnegol2 p1ol2 x1))
| pv2 psing2 ptimesol2 pplusol2 p0ol2 pnegol2 p1ol2 oneOL2 := p1ol2
def stageB : (AntiCommutativeRingTerm β (Staged AntiCommutativeRingTerm))
| (timesL x1 x2) := (stage2 timesL (codeLift2 timesL) (stageB x1) (stageB x2))
| (plusL x1 x2) := (stage2 plusL (codeLift2 plusL) (stageB x1) (stageB x2))
| zeroL := (Now zeroL)
| (negL x1) := (stage1 negL (codeLift1 negL) (stageB x1))
| oneL := (Now oneL)
def stageCl {A : Type} : ((ClAntiCommutativeRingTerm A) β (Staged (ClAntiCommutativeRingTerm A)))
| (sing x1) := (Now (sing x1))
| (timesCl x1 x2) := (stage2 timesCl (codeLift2 timesCl) (stageCl x1) (stageCl x2))
| (plusCl x1 x2) := (stage2 plusCl (codeLift2 plusCl) (stageCl x1) (stageCl x2))
| zeroCl := (Now zeroCl)
| (negCl x1) := (stage1 negCl (codeLift1 negCl) (stageCl x1))
| oneCl := (Now oneCl)
def stageOpB {n : β} : ((OpAntiCommutativeRingTerm n) β (Staged (OpAntiCommutativeRingTerm n)))
| (v x1) := (const (code (v x1)))
| (timesOL x1 x2) := (stage2 timesOL (codeLift2 timesOL) (stageOpB x1) (stageOpB x2))
| (plusOL x1 x2) := (stage2 plusOL (codeLift2 plusOL) (stageOpB x1) (stageOpB x2))
| zeroOL := (Now zeroOL)
| (negOL x1) := (stage1 negOL (codeLift1 negOL) (stageOpB x1))
| oneOL := (Now oneOL)
def stageOp {n : β} {A : Type} : ((OpAntiCommutativeRingTerm2 n A) β (Staged (OpAntiCommutativeRingTerm2 n A)))
| (sing2 x1) := (Now (sing2 x1))
| (v2 x1) := (const (code (v2 x1)))
| (timesOL2 x1 x2) := (stage2 timesOL2 (codeLift2 timesOL2) (stageOp x1) (stageOp x2))
| (plusOL2 x1 x2) := (stage2 plusOL2 (codeLift2 plusOL2) (stageOp x1) (stageOp x2))
| zeroOL2 := (Now zeroOL2)
| (negOL2 x1) := (stage1 negOL2 (codeLift1 negOL2) (stageOp x1))
| oneOL2 := (Now oneOL2)
structure StagedRepr (A : Type) (Repr : (Type β Type)) : Type :=
(timesT : ((Repr A) β ((Repr A) β (Repr A))))
(plusT : ((Repr A) β ((Repr A) β (Repr A))))
(zeroT : (Repr A))
(negT : ((Repr A) β (Repr A)))
(oneT : (Repr A))
end AntiCommutativeRing |
0128524001e190f46e3e32bbd9e951c91931c194 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/ring_theory/noetherian.lean | 2e59f4a21cb44b6e2dcee9e0029b8e1baa84d931 | [
"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 | 22,750 | lean | /-
Copyright (c) 2018 Mario Carneiro, Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kevin Buzzard
-/
import algebra.algebra.subalgebra.basic
import algebra.algebra.tower
import algebra.ring.idempotents
import group_theory.finiteness
import linear_algebra.linear_independent
import order.compactly_generated
import order.order_iso_nat
import ring_theory.finiteness
import ring_theory.nilpotent
/-!
# Noetherian rings and modules
The following are equivalent for a module M over a ring R:
1. Every increasing chain of submodules Mβ β Mβ β Mβ β β― eventually stabilises.
2. Every submodule is finitely generated.
A module satisfying these equivalent conditions is said to be a *Noetherian* R-module.
A ring is a *Noetherian ring* if it is Noetherian as a module over itself.
(Note that we do not assume yet that our rings are commutative,
so perhaps this should be called "left Noetherian".
To avoid cumbersome names once we specialize to the commutative case,
we don't make this explicit in the declaration names.)
## Main definitions
Let `R` be a ring and let `M` and `P` be `R`-modules. Let `N` be an `R`-submodule of `M`.
* `is_noetherian R M` is the proposition that `M` is a Noetherian `R`-module. It is a class,
implemented as the predicate that all `R`-submodules of `M` are finitely generated.
## Main statements
* `is_noetherian_iff_well_founded` is the theorem that an R-module M is Noetherian iff
`>` is well-founded on `submodule R M`.
Note that the Hilbert basis theorem, that if a commutative ring R is Noetherian then so is R[X],
is proved in `ring_theory.polynomial`.
## References
* [M. F. Atiyah and I. G. Macdonald, *Introduction to commutative algebra*][atiyah-macdonald]
* [samuel1967]
## Tags
Noetherian, noetherian, Noetherian ring, Noetherian module, noetherian ring, noetherian module
-/
open set
open_locale big_operators pointwise
/--
`is_noetherian R M` is the proposition that `M` is a Noetherian `R`-module,
implemented as the predicate that all `R`-submodules of `M` are finitely generated.
-/
class is_noetherian (R M) [semiring R] [add_comm_monoid M] [module R M] : Prop :=
(noetherian : β (s : submodule R M), s.fg)
section
variables {R : Type*} {M : Type*} {P : Type*}
variables [semiring R] [add_comm_monoid M] [add_comm_monoid P]
variables [module R M] [module R P]
open is_noetherian
include R
/-- An R-module is Noetherian iff all its submodules are finitely-generated. -/
lemma is_noetherian_def : is_noetherian R M β β (s : submodule R M), s.fg :=
β¨Ξ» h, h.noetherian, is_noetherian.mkβ©
theorem is_noetherian_submodule {N : submodule R M} :
is_noetherian R N β β s : submodule R M, s β€ N β s.fg :=
begin
refine β¨Ξ» β¨hnβ©, Ξ» s hs, have s β€ N.subtype.range, from (N.range_subtype).symm βΈ hs,
submodule.map_comap_eq_self this βΈ (hn _).map _, Ξ» h, β¨Ξ» s, _β©β©,
have f := (submodule.equiv_map_of_injective N.subtype subtype.val_injective s).symm,
have hβ := h (s.map N.subtype) (submodule.map_subtype_le N s),
have hβ : (β€ : submodule R (s.map N.subtype)).map f = β€ := by simp,
have hβ := ((submodule.fg_top _).2 hβ).map (βf : _ ββ[R] s),
exact (submodule.fg_top _).1 (hβ βΈ hβ),
end
theorem is_noetherian_submodule_left {N : submodule R M} :
is_noetherian R N β β s : submodule R M, (N β s).fg :=
is_noetherian_submodule.trans
β¨Ξ» H s, H _ inf_le_left, Ξ» H s hs, (inf_of_le_right hs) βΈ H _β©
theorem is_noetherian_submodule_right {N : submodule R M} :
is_noetherian R N β β s : submodule R M, (s β N).fg :=
is_noetherian_submodule.trans
β¨Ξ» H s, H _ inf_le_right, Ξ» H s hs, (inf_of_le_left hs) βΈ H _β©
instance is_noetherian_submodule' [is_noetherian R M] (N : submodule R M) : is_noetherian R N :=
is_noetherian_submodule.2 $ Ξ» _ _, is_noetherian.noetherian _
lemma is_noetherian_of_le {s t : submodule R M} [ht : is_noetherian R t]
(h : s β€ t) : is_noetherian R s :=
is_noetherian_submodule.mpr (Ξ» s' hs', is_noetherian_submodule.mp ht _ (le_trans hs' h))
variable (M)
theorem is_noetherian_of_surjective (f : M ββ[R] P) (hf : f.range = β€)
[is_noetherian R M] : is_noetherian R P :=
β¨Ξ» s, have (s.comap f).map f = s, from submodule.map_comap_eq_self $ hf.symm βΈ le_top,
this βΈ (noetherian _).map _β©
variable {M}
theorem is_noetherian_of_linear_equiv (f : M ββ[R] P)
[is_noetherian R M] : is_noetherian R P :=
is_noetherian_of_surjective _ f.to_linear_map f.range
lemma is_noetherian_top_iff :
is_noetherian R (β€ : submodule R M) β is_noetherian R M :=
begin
unfreezingI { split; assume h },
{ exact is_noetherian_of_linear_equiv (linear_equiv.of_top (β€ : submodule R M) rfl) },
{ exact is_noetherian_of_linear_equiv (linear_equiv.of_top (β€ : submodule R M) rfl).symm },
end
lemma is_noetherian_of_injective [is_noetherian R P] (f : M ββ[R] P) (hf : function.injective f) :
is_noetherian R M :=
is_noetherian_of_linear_equiv (linear_equiv.of_injective f hf).symm
lemma fg_of_injective [is_noetherian R P] {N : submodule R M} (f : M ββ[R] P)
(hf : function.injective f) : N.fg :=
@@is_noetherian.noetherian _ _ _ (is_noetherian_of_injective f hf) N
end
namespace module
variables {R M N : Type*}
variables [semiring R] [add_comm_monoid M] [add_comm_monoid N] [module R M] [module R N]
variables (R M)
@[priority 100] -- see Note [lower instance priority]
instance is_noetherian.finite [is_noetherian R M] : finite R M :=
β¨is_noetherian.noetherian β€β©
variables {R M}
lemma finite.of_injective [is_noetherian R N] (f : M ββ[R] N)
(hf : function.injective f) : finite R M :=
β¨fg_of_injective f hfβ©
end module
section
variables {R : Type*} {M : Type*} {P : Type*}
variables [ring R] [add_comm_group M] [add_comm_group P]
variables [module R M] [module R P]
open is_noetherian
include R
lemma is_noetherian_of_ker_bot [is_noetherian R P] (f : M ββ[R] P) (hf : f.ker = β₯) :
is_noetherian R M :=
is_noetherian_of_linear_equiv (linear_equiv.of_injective f $ linear_map.ker_eq_bot.mp hf).symm
lemma fg_of_ker_bot [is_noetherian R P] {N : submodule R M} (f : M ββ[R] P) (hf : f.ker = β₯) :
N.fg :=
@@is_noetherian.noetherian _ _ _ (is_noetherian_of_ker_bot f hf) N
instance is_noetherian_prod [is_noetherian R M]
[is_noetherian R P] : is_noetherian R (M Γ P) :=
β¨Ξ» s, submodule.fg_of_fg_map_of_fg_inf_ker (linear_map.snd R M P) (noetherian _) $
have s β linear_map.ker (linear_map.snd R M P) β€ linear_map.range (linear_map.inl R M P),
from Ξ» x β¨hx1, hx2β©, β¨x.1, prod.ext rfl $ eq.symm $ linear_map.mem_ker.1 hx2β©,
submodule.map_comap_eq_self this βΈ (noetherian _).map _β©
instance is_noetherian_pi {R ΞΉ : Type*} {M : ΞΉ β Type*} [ring R]
[Ξ i, add_comm_group (M i)] [Ξ i, module R (M i)] [finite ΞΉ]
[β i, is_noetherian R (M i)] : is_noetherian R (Ξ i, M i) :=
begin
casesI nonempty_fintype ΞΉ,
haveI := classical.dec_eq ΞΉ,
suffices on_finset : β s : finset ΞΉ, is_noetherian R (Ξ i : s, M i),
{ let coe_e := equiv.subtype_univ_equiv finset.mem_univ,
letI : is_noetherian R (Ξ i : finset.univ, M (coe_e i)) := on_finset finset.univ,
exact is_noetherian_of_linear_equiv (linear_equiv.Pi_congr_left R M coe_e), },
intro s,
induction s using finset.induction with a s has ih,
{ exact β¨Ξ» s, by convert submodule.fg_botβ© },
refine @is_noetherian_of_linear_equiv _ _ _ _ _ _ _ _
_ (@is_noetherian_prod _ (M a) _ _ _ _ _ _ _ ih),
fconstructor,
{ exact Ξ» f i, or.by_cases (finset.mem_insert.1 i.2)
(Ξ» h : i.1 = a, show M i.1, from (eq.rec_on h.symm f.1))
(Ξ» h : i.1 β s, show M i.1, from f.2 β¨i.1, hβ©) },
{ intros f g, ext i, unfold or.by_cases, cases i with i hi,
rcases finset.mem_insert.1 hi with rfl | h,
{ change _ = _ + _, simp only [dif_pos], refl },
{ change _ = _ + _, have : Β¬i = a, { rintro rfl, exact has h },
simp only [dif_neg this, dif_pos h], refl } },
{ intros c f, ext i, unfold or.by_cases, cases i with i hi,
rcases finset.mem_insert.1 hi with rfl | h,
{ change _ = c β’ _, simp only [dif_pos], refl },
{ change _ = c β’ _, have : Β¬i = a, { rintro rfl, exact has h },
simp only [dif_neg this, dif_pos h], refl } },
{ exact Ξ» f, (f β¨a, finset.mem_insert_self _ _β©, Ξ» i, f β¨i.1, finset.mem_insert_of_mem i.2β©) },
{ intro f, apply prod.ext,
{ simp only [or.by_cases, dif_pos] },
{ ext β¨i, hisβ©,
have : Β¬i = a, { rintro rfl, exact has his },
simp only [or.by_cases, this, not_false_iff, dif_neg] } },
{ intro f, ext β¨i, hiβ©,
rcases finset.mem_insert.1 hi with rfl | h,
{ simp only [or.by_cases, dif_pos], },
{ have : Β¬i = a, { rintro rfl, exact has h },
simp only [or.by_cases, dif_neg this, dif_pos h], } }
end
/-- A version of `is_noetherian_pi` for non-dependent functions. We need this instance because
sometimes Lean fails to apply the dependent version in non-dependent settings (e.g., it fails to
prove that `ΞΉ β β` is finite dimensional over `β`). -/
instance is_noetherian_pi' {R ΞΉ M : Type*} [ring R] [add_comm_group M] [module R M] [finite ΞΉ]
[is_noetherian R M] : is_noetherian R (ΞΉ β M) :=
is_noetherian_pi
end
open is_noetherian submodule function
section
universe w
variables {R M P : Type*} {N : Type w} [semiring R] [add_comm_monoid M] [module R M]
[add_comm_monoid N] [module R N] [add_comm_monoid P] [module R P]
theorem is_noetherian_iff_well_founded :
is_noetherian R M β well_founded ((>) : submodule R M β submodule R M β Prop) :=
begin
rw (complete_lattice.well_founded_characterisations $ submodule R M).out 0 3,
exact β¨Ξ» β¨hβ©, Ξ» k, (fg_iff_compact k).mp (h k), Ξ» h, β¨Ξ» k, (fg_iff_compact k).mpr (h k)β©β©,
end
lemma is_noetherian_iff_fg_well_founded :
is_noetherian R M β well_founded
((>) : { N : submodule R M // N.fg } β { N : submodule R M // N.fg } β Prop) :=
begin
let Ξ± := { N : submodule R M // N.fg },
split,
{ introI H,
let f : Ξ± βͺo submodule R M := order_embedding.subtype _,
exact order_embedding.well_founded f.dual (is_noetherian_iff_well_founded.mp H) },
{ intro H,
constructor,
intro N,
obtain β¨β¨Nβ, hββ©, e : Nβ β€ N, hββ© := well_founded.well_founded_iff_has_max'.mp
H { N' : Ξ± | N'.1 β€ N } β¨β¨β₯, submodule.fg_botβ©, bot_leβ©,
convert hβ,
refine (e.antisymm _).symm,
by_contra hβ,
obtain β¨x, hxβ : x β N, hxβ : x β Nββ© := set.not_subset.mp hβ,
apply hxβ,
have := hβ β¨(R β x) β Nβ, _β© _ _,
{ injection this with eq,
rw β eq,
exact (le_sup_left : (R β x) β€ (R β x) β Nβ) (submodule.mem_span_singleton_self _) },
{ exact submodule.fg.sup β¨{x}, by rw [finset.coe_singleton]β© hβ },
{ exact sup_le ((submodule.span_singleton_le_iff_mem _ _).mpr hxβ) e },
{ show Nβ β€ (R β x) β Nβ, from le_sup_right } }
end
variables (R M)
lemma well_founded_submodule_gt (R M) [semiring R] [add_comm_monoid M] [module R M] :
β [is_noetherian R M], well_founded ((>) : submodule R M β submodule R M β Prop) :=
is_noetherian_iff_well_founded.mp
variables {R M}
/-- A module is Noetherian iff every nonempty set of submodules has a maximal submodule among them.
-/
theorem set_has_maximal_iff_noetherian :
(β a : set $ submodule R M, a.nonempty β β M' β a, β I β a, M' β€ I β I = M') β
is_noetherian R M :=
by rw [is_noetherian_iff_well_founded, well_founded.well_founded_iff_has_max']
/-- A module is Noetherian iff every increasing chain of submodules stabilizes. -/
theorem monotone_stabilizes_iff_noetherian :
(β (f : β βo submodule R M), β n, β m, n β€ m β f n = f m)
β is_noetherian R M :=
by rw [is_noetherian_iff_well_founded, well_founded.monotone_chain_condition]
/-- If `β I > J, P I` implies `P J`, then `P` holds for all submodules. -/
lemma is_noetherian.induction [is_noetherian R M] {P : submodule R M β Prop}
(hgt : β I, (β J > I, P J) β P I) (I : submodule R M) : P I :=
well_founded.recursion (well_founded_submodule_gt R M) I hgt
end
section
universe w
variables {R M P : Type*} {N : Type w} [ring R] [add_comm_group M] [module R M]
[add_comm_group N] [module R N] [add_comm_group P] [module R P]
lemma finite_of_linear_independent [nontrivial R] [is_noetherian R M]
{s : set M} (hs : linear_independent R (coe : s β M)) : s.finite :=
begin
refine classical.by_contradiction (Ξ» hf, (rel_embedding.well_founded_iff_no_descending_seq.1
(well_founded_submodule_gt R M)).elim' _),
have f : β βͺ s, from set.infinite.nat_embedding s hf,
have : β n, (coe β f) '' {m | m β€ n} β s,
{ rintros n x β¨y, hyβ, rflβ©, exact (f y).2 },
have : β a b : β, a β€ b β
span R ((coe β f) '' {m | m β€ a}) β€ span R ((coe β f) '' {m | m β€ b}),
{ assume a b,
rw [span_le_span_iff hs (this a) (this b),
set.image_subset_image_iff (subtype.coe_injective.comp f.injective),
set.subset_def],
exact β¨Ξ» hab x (hxa : x β€ a), le_trans hxa hab, Ξ» hx, hx a (le_refl a)β© },
exact β¨β¨Ξ» n, span R ((coe β f) '' {m | m β€ n}),
Ξ» x y, by simp [le_antisymm_iff, (this _ _).symm] {contextual := tt}β©,
by dsimp [gt]; simp only [lt_iff_le_not_le, (this _ _).symm]; tautoβ©
end
/-- If the first and final modules in a short exact sequence are noetherian,
then the middle module is also noetherian. -/
theorem is_noetherian_of_range_eq_ker
[is_noetherian R M] [is_noetherian R P]
(f : M ββ[R] N) (g : N ββ[R] P)
(hf : function.injective f)
(hg : function.surjective g)
(h : f.range = g.ker) :
is_noetherian R N :=
is_noetherian_iff_well_founded.2 $
well_founded_gt_exact_sequence
(well_founded_submodule_gt R M)
(well_founded_submodule_gt R P)
f.range
(submodule.map f)
(submodule.comap f)
(submodule.comap g)
(submodule.map g)
(submodule.gci_map_comap hf)
(submodule.gi_map_comap hg)
(by simp [submodule.map_comap_eq, inf_comm])
(by simp [submodule.comap_map_eq, h])
/--
For any endomorphism of a Noetherian module, there is some nontrivial iterate
with disjoint kernel and range.
-/
theorem is_noetherian.exists_endomorphism_iterate_ker_inf_range_eq_bot
[I : is_noetherian R M] (f : M ββ[R] M) : β n : β, n β 0 β§ (f ^ n).ker β (f ^ n).range = β₯ :=
begin
obtain β¨n, wβ© := monotone_stabilizes_iff_noetherian.mpr I
(f.iterate_ker.comp β¨Ξ» n, n+1, Ξ» n m w, by linarithβ©),
specialize w (2 * n + 1) (by linarith only),
dsimp at w,
refine β¨n+1, nat.succ_ne_zero _, _β©,
rw eq_bot_iff,
rintros - β¨h, β¨y, rflβ©β©,
rw [mem_bot, βlinear_map.mem_ker, w],
erw linear_map.mem_ker at h β’,
change ((f ^ (n + 1)) * (f ^ (n + 1))) y = 0 at h,
rw βpow_add at h,
convert h using 3,
ring
end
/-- Any surjective endomorphism of a Noetherian module is injective. -/
theorem is_noetherian.injective_of_surjective_endomorphism [is_noetherian R M]
(f : M ββ[R] M) (s : surjective f) : injective f :=
begin
obtain β¨n, ne, wβ© := is_noetherian.exists_endomorphism_iterate_ker_inf_range_eq_bot f,
rw [linear_map.range_eq_top.mpr (linear_map.iterate_surjective s n), inf_top_eq,
linear_map.ker_eq_bot] at w,
exact linear_map.injective_of_iterate_injective ne w,
end
/-- Any surjective endomorphism of a Noetherian module is bijective. -/
theorem is_noetherian.bijective_of_surjective_endomorphism [is_noetherian R M]
(f : M ββ[R] M) (s : surjective f) : bijective f :=
β¨is_noetherian.injective_of_surjective_endomorphism f s, sβ©
/--
A sequence `f` of submodules of a noetherian module,
with `f (n+1)` disjoint from the supremum of `f 0`, ..., `f n`,
is eventually zero.
-/
lemma is_noetherian.disjoint_partial_sups_eventually_bot [I : is_noetherian R M]
(f : β β submodule R M) (h : β n, disjoint (partial_sups f n) (f (n+1))) :
β n : β, β m, n β€ m β f m = β₯ :=
begin
-- A little off-by-one cleanup first:
suffices t : β n : β, β m, n β€ m β f (m+1) = β₯,
{ obtain β¨n, wβ© := t,
use n+1,
rintros (_|m) p,
{ cases p, },
{ apply w,
exact nat.succ_le_succ_iff.mp p }, },
obtain β¨n, wβ© := monotone_stabilizes_iff_noetherian.mpr I (partial_sups f),
exact β¨n, Ξ» m p, (h m).eq_bot_of_ge $ sup_eq_left.1 $ (w (m + 1) $ le_add_right p).symm.trans $
w m pβ©
end
/--
If `M β N` embeds into `M`, for `M` noetherian over `R`, then `N` is trivial.
-/
noncomputable def is_noetherian.equiv_punit_of_prod_injective [is_noetherian R M]
(f : M Γ N ββ[R] M) (i : injective f) : N ββ[R] punit.{w+1} :=
begin
apply nonempty.some,
obtain β¨n, wβ© := is_noetherian.disjoint_partial_sups_eventually_bot (f.tailing i)
(f.tailings_disjoint_tailing i),
specialize w n (le_refl n),
apply nonempty.intro,
refine (f.tailing_linear_equiv i n).symm βͺβ«β _,
rw w,
exact submodule.bot_equiv_punit,
end
end
/--
A (semi)ring is Noetherian if it is Noetherian as a module over itself,
i.e. all its ideals are finitely generated.
-/
@[reducible] def is_noetherian_ring (R) [semiring R] := is_noetherian R R
theorem is_noetherian_ring_iff {R} [semiring R] : is_noetherian_ring R β is_noetherian R R :=
iff.rfl
/-- A ring is Noetherian if and only if all its ideals are finitely-generated. -/
lemma is_noetherian_ring_iff_ideal_fg (R : Type*) [semiring R] :
is_noetherian_ring R β β I : ideal R, I.fg :=
is_noetherian_ring_iff.trans is_noetherian_def
@[priority 80] -- see Note [lower instance priority]
instance is_noetherian_of_finite (R M) [finite M] [semiring R] [add_comm_monoid M] [module R M] :
is_noetherian R M :=
β¨Ξ» s, β¨(s : set M).to_finite.to_finset, by rw [set.finite.coe_to_finset, submodule.span_eq]β©β©
/-- Modules over the trivial ring are Noetherian. -/
@[priority 100] -- see Note [lower instance priority]
instance is_noetherian_of_subsingleton (R M) [subsingleton R] [semiring R] [add_comm_monoid M]
[module R M] : is_noetherian R M :=
by { haveI := module.subsingleton R M, exact is_noetherian_of_finite R M }
theorem is_noetherian_of_submodule_of_noetherian (R M) [semiring R] [add_comm_monoid M] [module R M]
(N : submodule R M) (h : is_noetherian R M) : is_noetherian R N :=
begin
rw is_noetherian_iff_well_founded at h β’,
exact order_embedding.well_founded (submodule.map_subtype.order_embedding N).dual h,
end
instance submodule.quotient.is_noetherian {R} [ring R] {M} [add_comm_group M] [module R M]
(N : submodule R M) [h : is_noetherian R M] : is_noetherian R (M β§Έ N) :=
begin
rw is_noetherian_iff_well_founded at h β’,
exact order_embedding.well_founded (submodule.comap_mkq.order_embedding N).dual h,
end
/-- If `M / S / R` is a scalar tower, and `M / R` is Noetherian, then `M / S` is
also noetherian. -/
theorem is_noetherian_of_tower (R) {S M} [semiring R] [semiring S]
[add_comm_monoid M] [has_smul R S] [module S M] [module R M] [is_scalar_tower R S M]
(h : is_noetherian R M) : is_noetherian S M :=
begin
rw is_noetherian_iff_well_founded at h β’,
refine (submodule.restrict_scalars_embedding R S M).dual.well_founded h
end
instance ideal.quotient.is_noetherian_ring {R : Type*} [comm_ring R] [h : is_noetherian_ring R]
(I : ideal R) : is_noetherian_ring (R β§Έ I) :=
is_noetherian_ring_iff.mpr $ is_noetherian_of_tower R $ submodule.quotient.is_noetherian _
theorem is_noetherian_of_fg_of_noetherian {R M} [ring R] [add_comm_group M] [module R M]
(N : submodule R M) [is_noetherian_ring R] (hN : N.fg) : is_noetherian R N :=
let β¨s, hsβ© := hN in
begin
haveI := classical.dec_eq M,
haveI := classical.dec_eq R,
letI : is_noetherian R R := by apply_instance,
have : β x β s, x β N, from Ξ» x hx, hs βΈ submodule.subset_span hx,
refine @@is_noetherian_of_surjective ((βs : set M) β R) _ _ _ (pi.module _ _ _)
_ _ _ is_noetherian_pi,
{ fapply linear_map.mk,
{ exact Ξ» f, β¨β i in s.attach, f i β’ i.1, N.sum_mem (Ξ» c _, N.smul_mem _ $ this _ c.2)β© },
{ intros f g, apply subtype.eq,
change β i in s.attach, (f i + g i) β’ _ = _,
simp only [add_smul, finset.sum_add_distrib], refl },
{ intros c f, apply subtype.eq,
change β i in s.attach, (c β’ f i) β’ _ = _,
simp only [smul_eq_mul, mul_smul],
exact finset.smul_sum.symm } },
rw linear_map.range_eq_top,
rintro β¨n, hnβ©, change n β N at hn,
rw [β hs, β set.image_id βs, finsupp.mem_span_image_iff_total] at hn,
rcases hn with β¨l, hl1, hl2β©,
refine β¨Ξ» x, l x, subtype.ext _β©,
change β i in s.attach, l i β’ (i : M) = n,
rw [@finset.sum_attach M M s _ (Ξ» i, l i β’ i), β hl2,
finsupp.total_apply, finsupp.sum, eq_comm],
refine finset.sum_subset hl1 (Ξ» x _ hx, _),
rw [finsupp.not_mem_support_iff.1 hx, zero_smul]
end
lemma is_noetherian_of_fg_of_noetherian' {R M} [ring R] [add_comm_group M] [module R M]
[is_noetherian_ring R] (h : (β€ : submodule R M).fg) : is_noetherian R M :=
have is_noetherian R (β€ : submodule R M), from is_noetherian_of_fg_of_noetherian _ h,
by exactI is_noetherian_of_linear_equiv (linear_equiv.of_top (β€ : submodule R M) rfl)
/-- In a module over a noetherian ring, the submodule generated by finitely many vectors is
noetherian. -/
theorem is_noetherian_span_of_finite (R) {M} [ring R] [add_comm_group M] [module R M]
[is_noetherian_ring R] {A : set M} (hA : A.finite) : is_noetherian R (submodule.span R A) :=
is_noetherian_of_fg_of_noetherian _ (submodule.fg_def.mpr β¨A, hA, rflβ©)
theorem is_noetherian_ring_of_surjective (R) [ring R] (S) [ring S]
(f : R β+* S) (hf : function.surjective f)
[H : is_noetherian_ring R] : is_noetherian_ring S :=
begin
rw [is_noetherian_ring_iff, is_noetherian_iff_well_founded] at H β’,
exact order_embedding.well_founded (ideal.order_embedding_of_surjective f hf).dual H,
end
instance is_noetherian_ring_range {R} [ring R] {S} [ring S] (f : R β+* S)
[is_noetherian_ring R] : is_noetherian_ring f.range :=
is_noetherian_ring_of_surjective R f.range f.range_restrict
f.range_restrict_surjective
theorem is_noetherian_ring_of_ring_equiv (R) [ring R] {S} [ring S]
(f : R β+* S) [is_noetherian_ring R] : is_noetherian_ring S :=
is_noetherian_ring_of_surjective R S f.to_ring_hom f.to_equiv.surjective
lemma is_noetherian_ring.is_nilpotent_nilradical (R : Type*) [comm_ring R] [is_noetherian_ring R] :
is_nilpotent (nilradical R) :=
begin
obtain β¨n, hnβ© := ideal.exists_radical_pow_le_of_fg (β₯ : ideal R) (is_noetherian.noetherian _),
exact β¨n, eq_bot_iff.mpr hnβ©
end
|
336e10edc3aa54933150349acffc03fe5860a9d9 | 4efff1f47634ff19e2f786deadd394270a59ecd2 | /src/category_theory/limits/pi.lean | d6bd5c452a9e6522a1e53b4faf1389e467bf4789 | [
"Apache-2.0"
] | permissive | agjftucker/mathlib | d634cd0d5256b6325e3c55bb7fb2403548371707 | 87fe50de17b00af533f72a102d0adefe4a2285e8 | refs/heads/master | 1,625,378,131,941 | 1,599,166,526,000 | 1,599,166,526,000 | 160,748,509 | 0 | 0 | Apache-2.0 | 1,544,141,789,000 | 1,544,141,789,000 | null | UTF-8 | Lean | false | false | 2,847 | lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import category_theory.pi.basic
import category_theory.limits.limits
/-!
# Limits in the category of indexed families of objects.
Given a functor `F : J β₯€ Ξ i, C i` into a category of indexed families,
1. we can assemble a collection of cones over `F β pi.eval C i` into a cone over `F`
2. if all those cones are limit cones, the assembled cone is a limit cone, and
3. if we have chosen limits for each of `F β pi.eval C i`, we can produce a
`has_limit F` instance
-/
open category_theory
open category_theory.limits
namespace category_theory.pi
universes vβ vβ uβ uβ
variables {I : Type vβ} {C : I β Type uβ} [Ξ i, category.{vβ} (C i)]
variables {J : Type vβ} [small_category J]
variables {F : J β₯€ Ξ i, C i}
/--
A cone over `F : J β₯€ Ξ i, C i` has as its components cones over each of the `F β pi.eval C i`.
-/
def cone_comp_eval (c : cone F) (i : I) : cone (F β pi.eval C i) :=
{ X := c.X i,
Ο :=
{ app := Ξ» j, c.Ο.app j i,
naturality' := Ξ» j j' f, congr_fun (c.Ο.naturality f) i, } }
/--
Given a family of cones over the `F β pi.eval C i`, we can assemble these together as a `cone F`.
-/
def cone_of_cone_comp_eval (c : Ξ i, cone (F β pi.eval C i)) : cone F :=
{ X := Ξ» i, (c i).X,
Ο :=
{ app := Ξ» j i, (c i).Ο.app j,
naturality' := Ξ» j j' f, by { ext i, exact (c i).Ο.naturality f, } } }
/--
Given a family of limit cones over the `F β pi.eval C i`,
assembling them together as a `cone F` produces a limit cone.
-/
def cone_of_cone_eval_is_limit {c : Ξ i, cone (F β pi.eval C i)} (P : Ξ i, is_limit (c i)) :
is_limit (cone_of_cone_comp_eval c) :=
{ lift := Ξ» s i, (P i).lift (cone_comp_eval s i),
fac' := Ξ» s j,
begin
ext i,
exact (P i).fac (cone_comp_eval s i) j,
end,
uniq' := Ξ» s m w,
begin
ext i,
exact (P i).uniq (cone_comp_eval s i) (m i) (Ξ» j, congr_fun (w j) i)
end }
variables [β i, has_limit (F β pi.eval C i)]
/--
If we have a functor `F : J β₯€ Ξ i, C i` into a category of indexed families,
and we have chosen limits for each of the `F β pi.eval C i`,
there is a canonical choice of chosen limit for `F`.
-/
def has_limit_of_has_limit_comp_eval : has_limit F :=
{ cone := cone_of_cone_comp_eval (Ξ» i, limit.cone _),
is_limit := cone_of_cone_eval_is_limit (Ξ» i, limit.is_limit _), }
/-!
As an example, we can use this to construct particular shapes of limits
in a category of indexed families.
With the addition of
`import category_theory.limits.shapes.types`
we can use:
```
local attribute [instance] has_limit_of_has_limit_comp_eval
example : has_binary_products (I β Type vβ) := β¨by apply_instanceβ©
```
-/
end category_theory.pi
|
f7ee8c53e06ed09e0484524da8f7770a0ccc2ff5 | 737dc4b96c97368cb66b925eeea3ab633ec3d702 | /src/Init/System/IO.lean | da152abde1810ba7ad5e1dd19526126cbaf5cd80 | [
"Apache-2.0"
] | permissive | Bioye97/lean4 | 1ace34638efd9913dc5991443777b01a08983289 | bc3900cbb9adda83eed7e6affeaade7cfd07716d | refs/heads/master | 1,690,589,820,211 | 1,631,051,000,000 | 1,631,067,598,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 20,718 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Luke Nelson, Jared Roesch, Leonardo de Moura, Sebastian Ullrich
-/
prelude
import Init.Control.EState
import Init.Control.Reader
import Init.Data.String
import Init.Data.ByteArray
import Init.System.IOError
import Init.System.FilePath
import Init.System.ST
import Init.Data.ToString.Macro
import Init.Data.Ord
open System
/-- Like https://hackage.haskell.org/package/ghc-Prim-0.5.2.0/docs/GHC-Prim.html#t:RealWorld.
Makes sure we never reorder `IO` operations.
TODO: mark opaque -/
def IO.RealWorld : Type := Unit
/- TODO(Leo): mark it as an opaque definition. Reason: prevent
functions defined in other modules from accessing `IO.RealWorld`.
We don't want action such as
```
def getWorld : IO (IO.RealWorld) := get
```
-/
def EIO (Ξ΅ : Type) : Type β Type := EStateM Ξ΅ IO.RealWorld
@[inline] def EIO.catchExceptions (x : EIO Ξ΅ Ξ±) (h : Ξ΅ β EIO Empty Ξ±) : EIO Empty Ξ± :=
fun s => match x s with
| EStateM.Result.ok a s => EStateM.Result.ok a s
| EStateM.Result.error ex s => h ex s
instance : Monad (EIO Ξ΅) := inferInstanceAs (Monad (EStateM Ξ΅ IO.RealWorld))
instance : MonadFinally (EIO Ξ΅) := inferInstanceAs (MonadFinally (EStateM Ξ΅ IO.RealWorld))
instance : MonadExceptOf Ξ΅ (EIO Ξ΅) := inferInstanceAs (MonadExceptOf Ξ΅ (EStateM Ξ΅ IO.RealWorld))
instance : OrElse (EIO Ξ΅ Ξ±) := β¨MonadExcept.orElseβ©
instance [Inhabited Ξ΅] : Inhabited (EIO Ξ΅ Ξ±) := inferInstanceAs (Inhabited (EStateM Ξ΅ IO.RealWorld Ξ±))
open IO (Error) in
abbrev IO : Type β Type := EIO Error
@[inline] def EIO.toIO (f : Ξ΅ β IO.Error) (x : EIO Ξ΅ Ξ±) : IO Ξ± :=
x.adaptExcept f
@[inline] def EIO.toIO' (x : EIO Ξ΅ Ξ±) : IO (Except Ξ΅ Ξ±) :=
EIO.toIO (fun _ => unreachable!) (observing x)
@[inline] def IO.toEIO (f : IO.Error β Ξ΅) (x : IO Ξ±) : EIO Ξ΅ Ξ± :=
x.adaptExcept f
/- After we inline `EState.run'`, the closed term `((), ())` is generated, where the second `()`
represents the "initial world". We don't want to cache this closed term. So, we disable
the "extract closed terms" optimization. -/
set_option compiler.extract_closed false in
@[inline] unsafe def unsafeEIO (fn : EIO Ξ΅ Ξ±) : Except Ξ΅ Ξ± :=
match fn.run () with
| EStateM.Result.ok a _ => Except.ok a
| EStateM.Result.error e _ => Except.error e
@[inline] unsafe def unsafeIO (fn : IO Ξ±) : Except IO.Error Ξ± :=
unsafeEIO fn
@[extern "lean_io_timeit"] constant timeit (msg : @& String) (fn : IO Ξ±) : IO Ξ±
@[extern "lean_io_allocprof"] constant allocprof (msg : @& String) (fn : IO Ξ±) : IO Ξ±
/- Programs can execute IO actions during initialization that occurs before
the `main` function is executed. The attribute `[init <action>]` specifies
which IO action is executed to set the value of an opaque constant.
The action `initializing` returns `true` iff it is invoked during initialization. -/
@[extern "lean_io_initializing"] constant IO.initializing : IO Bool
namespace IO
def ofExcept [ToString Ξ΅] (e : Except Ξ΅ Ξ±) : IO Ξ± :=
match e with
| Except.ok a => pure a
| Except.error e => throw (IO.userError (toString e))
def lazyPure (fn : Unit β Ξ±) : IO Ξ± :=
pure (fn ())
/-- Monotonically increasing time since an unspecified past point in milliseconds. No relation to wall clock time. -/
@[extern "lean_io_mono_ms_now"] constant monoMsNow : IO Nat
/-- Read bytes from a system entropy source. Not guaranteed to be cryptographically secure.
If `nBytes = 0`, return immediately with an empty buffer. -/
@[extern "lean_io_get_random_bytes"] constant getRandomBytes (nBytes : USize) : IO ByteArray
def sleep (ms : UInt32) : IO Unit :=
-- TODO: add a proper primitive for IO.sleep
fun s => dbgSleep ms fun _ => EStateM.Result.ok () s
/--
Run `act` in a separate `Task`. This is similar to Haskell's [`unsafeInterleaveIO`](http://hackage.haskell.org/package/base-4.14.0.0/docs/System-IO-Unsafe.html#v:unsafeInterleaveIO),
except that the `Task` is started eagerly as usual. Thus pure accesses to the `Task` do not influence the impure `act`
computation.
Unlike with pure tasks created by `Task.mk`, tasks created by this function will be run even if the last reference
to the task is dropped. `act` should manually check for cancellation via `IO.checkCanceled` if it wants to react
to that. -/
@[extern "lean_io_as_task"]
constant asTask (act : IO Ξ±) (prio := Task.Priority.default) : IO (Task (Except IO.Error Ξ±))
/-- See `IO.asTask`. -/
@[extern "lean_io_map_task"]
constant mapTask (f : Ξ± β IO Ξ²) (t : Task Ξ±) (prio := Task.Priority.default) : IO (Task (Except IO.Error Ξ²))
/-- See `IO.asTask`. -/
@[extern "lean_io_bind_task"]
constant bindTask (t : Task Ξ±) (f : Ξ± β IO (Task (Except IO.Error Ξ²))) (prio := Task.Priority.default) : IO (Task (Except IO.Error Ξ²))
def mapTasks (f : List Ξ± β IO Ξ²) (tasks : List (Task Ξ±)) (prio := Task.Priority.default) : IO (Task (Except IO.Error Ξ²)) :=
go tasks []
where
go
| t::ts, as =>
IO.bindTask t (fun a => go ts (a :: as)) prio
| [], as => IO.asTask (f as.reverse) prio
/-- Check if the task's cancellation flag has been set by calling `IO.cancel` or dropping the last reference to the task. -/
@[extern "lean_io_check_canceled"] constant checkCanceled : IO Bool
/-- Request cooperative cancellation of the task. The task must explicitly call `IO.checkCanceled` to react to the cancellation. -/
@[extern "lean_io_cancel"] constant cancel : @& Task Ξ± β IO Unit
/-- Check if the task has finished execution, at which point calling `Task.get` will return immediately. -/
@[extern "lean_io_has_finished"] constant hasFinished : @& Task Ξ± β IO Bool
/-- Wait for the task to finish, then return its result. -/
@[extern "lean_io_wait"] constant wait : Task Ξ± β IO Ξ±
/-- Wait until any of the tasks in the given list has finished, then return its result. -/
@[extern "lean_io_wait_any"] constant waitAny : @& List (Task Ξ±) β IO Ξ±
/-- Helper method for implementing "deterministic" timeouts. It is the numbe of "small" memory allocations performed by the current execution thread. -/
@[extern "lean_io_get_num_heartbeats"] constant getNumHeartbeats : EIO Ξ΅ Nat
inductive FS.Mode where
| read | write | readWrite | append
constant FS.Handle : Type := Unit
/--
A pure-Lean abstraction of POSIX streams. We use `Stream`s for the standard streams stdin/stdout/stderr so we can
capture output of `#eval` commands into memory. -/
structure FS.Stream where
isEof : IO Bool
flush : IO Unit
read : USize β IO ByteArray
write : ByteArray β IO Unit
getLine : IO String
putStr : String β IO Unit
open FS
@[extern "lean_get_stdin"] constant getStdin : IO FS.Stream
@[extern "lean_get_stdout"] constant getStdout : IO FS.Stream
@[extern "lean_get_stderr"] constant getStderr : IO FS.Stream
/-- Replaces the stdin stream of the current thread and returns its previous value. -/
@[extern "lean_get_set_stdin"] constant setStdin : FS.Stream β IO FS.Stream
/-- Replaces the stdout stream of the current thread and returns its previous value. -/
@[extern "lean_get_set_stdout"] constant setStdout : FS.Stream β IO FS.Stream
/-- Replaces the stderr stream of the current thread and returns its previous value. -/
@[extern "lean_get_set_stderr"] constant setStderr : FS.Stream β IO FS.Stream
@[specialize] partial def iterate (a : Ξ±) (f : Ξ± β IO (Sum Ξ± Ξ²)) : IO Ξ² := do
let v β f a
match v with
| Sum.inl a => iterate a f
| Sum.inr b => pure b
namespace FS
namespace Handle
private def fopenFlags (m : FS.Mode) (b : Bool) : String :=
let mode :=
match m with
| FS.Mode.read => "r"
| FS.Mode.write => "w"
| FS.Mode.readWrite => "r+"
| FS.Mode.append => "a" ;
let bin := if b then "b" else "t"
mode ++ bin
@[extern "lean_io_prim_handle_mk"] constant mkPrim (fn : @& FilePath) (mode : @& String) : IO Handle
def mk (fn : FilePath) (Mode : Mode) (bin : Bool := true) : IO Handle :=
mkPrim fn (fopenFlags Mode bin)
/--
Returns whether the end of the file has been reached while reading a file.
`h.isEof` returns true /after/ the first attempt at reading past the end of `h`.
Once `h.isEof` is true, reading `h` will always return an empty array.
-/
@[extern "lean_io_prim_handle_is_eof"] constant isEof (h : @& Handle) : IO Bool
@[extern "lean_io_prim_handle_flush"] constant flush (h : @& Handle) : IO Unit
@[extern "lean_io_prim_handle_read"] constant read (h : @& Handle) (bytes : USize) : IO ByteArray
@[extern "lean_io_prim_handle_write"] constant write (h : @& Handle) (buffer : @& ByteArray) : IO Unit
@[extern "lean_io_prim_handle_get_line"] constant getLine (h : @& Handle) : IO String
@[extern "lean_io_prim_handle_put_str"] constant putStr (h : @& Handle) (s : @& String) : IO Unit
end Handle
@[extern "lean_io_realpath"] constant realPath (fname : FilePath) : IO FilePath
@[extern "lean_io_remove_file"] constant removeFile (fname : @& FilePath) : IO Unit
@[extern "lean_io_create_dir"] constant createDir : @& FilePath β IO Unit
end FS
@[extern "lean_io_getenv"] constant getEnv (var : @& String) : IO (Option String)
@[extern "lean_io_app_path"] constant appPath : IO FilePath
@[extern "lean_io_current_dir"] constant currentDir : IO FilePath
namespace FS
@[inline]
def withFile (fn : FilePath) (mode : Mode) (f : Handle β IO Ξ±) : IO Ξ± :=
Handle.mk fn mode >>= f
def Handle.putStrLn (h : Handle) (s : String) : IO Unit :=
h.putStr (s.push '\n')
partial def Handle.readBinToEnd (h : Handle) : IO ByteArray := do
let rec loop (acc : ByteArray) : IO ByteArray := do
let buf β h.read 1024
if buf.isEmpty then
return acc
else
loop (acc ++ buf)
loop ByteArray.empty
partial def Handle.readToEnd (h : Handle) : IO String := do
let rec loop (s : String) := do
let line β h.getLine
if line.isEmpty then
return s
else
loop (s ++ line)
loop ""
def readBinFile (fname : FilePath) : IO ByteArray := do
let h β Handle.mk fname Mode.read true
h.readBinToEnd
def readFile (fname : FilePath) : IO String := do
let h β Handle.mk fname Mode.read false
h.readToEnd
partial def lines (fname : FilePath) : IO (Array String) := do
let h β Handle.mk fname Mode.read false
let rec read (lines : Array String) := do
let line β h.getLine
if line.length == 0 then
pure lines
else if line.back == '\n' then
let line := line.dropRight 1
let line := if System.Platform.isWindows && line.back == '\x0d' then line.dropRight 1 else line
read <| lines.push line
else
pure <| lines.push line
read #[]
def writeBinFile (fname : FilePath) (content : ByteArray) : IO Unit := do
let h β Handle.mk fname Mode.write true
h.write content
def writeFile (fname : FilePath) (content : String) : IO Unit := do
let h β Handle.mk fname Mode.write false
h.putStr content
def Stream.putStrLn (strm : FS.Stream) (s : String) : IO Unit :=
strm.putStr (s.push '\n')
structure DirEntry where
root : FilePath
fileName : String
deriving Repr
def DirEntry.path (entry : DirEntry) : FilePath :=
entry.root / entry.fileName
inductive FileType where
| dir
| file
| symlink
| other
deriving Repr, BEq
structure SystemTime where
sec : Int
nsec : UInt32
deriving Repr, BEq, Ord, Inhabited
instance : LT SystemTime := ltOfOrd
instance : LE SystemTime := leOfOrd
structure Metadata where
--permissions : ...
accessed : SystemTime
modified : SystemTime
byteSize : UInt64
type : FileType
deriving Repr
end FS
end IO
namespace System.FilePath
open IO
@[extern "lean_io_read_dir"]
constant readDir : @& FilePath β IO (Array IO.FS.DirEntry)
@[extern "lean_io_metadata"]
constant metadata : @& FilePath β IO IO.FS.Metadata
def isDir (p : FilePath) : IO Bool :=
try
return (β p.metadata).type == IO.FS.FileType.dir
catch _ =>
return false
def pathExists (p : FilePath) : IO Bool :=
(p.metadata *> pure true) <|> pure false
end System.FilePath
namespace IO
def withStdin [Monad m] [MonadFinally m] [MonadLiftT IO m] (h : FS.Stream) (x : m Ξ±) : m Ξ± := do
let prev β setStdin h
try x finally discard <| setStdin prev
def withStdout [Monad m] [MonadFinally m] [MonadLiftT IO m] (h : FS.Stream) (x : m Ξ±) : m Ξ± := do
let prev β setStdout h
try
x
finally
discard <| setStdout prev
def withStderr [Monad m] [MonadFinally m] [MonadLiftT IO m] (h : FS.Stream) (x : m Ξ±) : m Ξ± := do
let prev β setStderr h
try x finally discard <| setStderr prev
def print [ToString Ξ±] (s : Ξ±) : IO Unit := do
let out β getStdout
out.putStr <| toString s
def println [ToString Ξ±] (s : Ξ±) : IO Unit :=
print ((toString s).push '\n')
def eprint [ToString Ξ±] (s : Ξ±) : IO Unit := do
let out β getStderr
out.putStr <| toString s
def eprintln [ToString Ξ±] (s : Ξ±) : IO Unit :=
eprint <| toString s |>.push '\n'
@[export lean_io_eprintln]
private def eprintlnAux (s : String) : IO Unit :=
eprintln s
def appDir : IO FilePath := do
let p β appPath
let some p β pure p.parent
| throw <| IO.userError s!"System.IO.appDir: unexpected filename '{p}'"
FS.realPath p
partial def FS.createDirAll (p : FilePath) : IO Unit := do
if β p.isDir then
return ()
if let some parent := p.parent then
createDirAll parent
try
createDir p
catch
| e =>
if β p.isDir then
pure () -- I guess someone else was faster
else
throw e
namespace Process
inductive Stdio where
| piped
| inherit
| null
def Stdio.toHandleType : Stdio β Type
| Stdio.piped => FS.Handle
| Stdio.inherit => Unit
| Stdio.null => Unit
structure StdioConfig where
/- Configuration for the process' stdin handle. -/
stdin := Stdio.inherit
/- Configuration for the process' stdout handle. -/
stdout := Stdio.inherit
/- Configuration for the process' stderr handle. -/
stderr := Stdio.inherit
structure SpawnArgs extends StdioConfig where
/- Command name. -/
cmd : String
/- Arguments for the process -/
args : Array String := #[]
/- Working directory for the process. Inherit from current process if `none`. -/
cwd : Option FilePath := none
/- Add or remove environment variables for the process. -/
env : Array (String Γ Option String) := #[]
-- TODO(Sebastian): constructor must be private
structure Child (cfg : StdioConfig) where
stdin : cfg.stdin.toHandleType
stdout : cfg.stdout.toHandleType
stderr : cfg.stderr.toHandleType
@[extern "lean_io_process_spawn"] constant spawn (args : SpawnArgs) : IO (Child args.toStdioConfig)
@[extern "lean_io_process_child_wait"] constant Child.wait {cfg : @& StdioConfig} : @& Child cfg β IO UInt32
/--
Extract the `stdin` field from a `Child` object, allowing them to be freed independently.
This operation is necessary for closing the child process' stdin while still holding on to a process handle,
e.g. for `Child.wait`. A file handle is closed when all references to it are dropped, which without this
operation includes the `Child` object.
-/
@[extern "lean_io_process_child_take_stdin"] constant Child.takeStdin {cfg : @& StdioConfig} : Child cfg β
IO (cfg.stdin.toHandleType Γ Child { cfg with stdin := Stdio.null })
structure Output where
exitCode : UInt32
stdout : String
stderr : String
/-- Run process to completion and capture output. -/
def output (args : SpawnArgs) : IO Output := do
let child β spawn { args with stdout := Stdio.piped, stderr := Stdio.piped }
let stdout β IO.asTask child.stdout.readToEnd Task.Priority.dedicated
let stderr β child.stderr.readToEnd
let exitCode β child.wait
let stdout β IO.ofExcept stdout.get
pure { exitCode := exitCode, stdout := stdout, stderr := stderr }
/-- Run process to completion and return stdout on success. -/
def run (args : SpawnArgs) : IO String := do
let out β output args
if out.exitCode != 0 then
throw <| IO.userError <| "process '" ++ args.cmd ++ "' exited with code " ++ toString out.exitCode
pure out.stdout
@[extern "lean_io_exit"] constant exit : UInt8 β IO Ξ±
end Process
structure AccessRight where
read : Bool := false
write : Bool := false
execution : Bool := false
def AccessRight.flags (acc : AccessRight) : UInt32 :=
let r : UInt32 := if acc.read then 0x4 else 0
let w : UInt32 := if acc.write then 0x2 else 0
let x : UInt32 := if acc.execution then 0x1 else 0
r.lor <| w.lor x
structure FileRight where
user : AccessRight := {}
group : AccessRight := {}
other : AccessRight := {}
def FileRight.flags (acc : FileRight) : UInt32 :=
let u : UInt32 := acc.user.flags.shiftLeft 6
let g : UInt32 := acc.group.flags.shiftLeft 3
let o : UInt32 := acc.other.flags
u.lor <| g.lor o
@[extern "lean_chmod"] constant Prim.setAccessRights (filename : @& FilePath) (mode : UInt32) : IO Unit
def setAccessRights (filename : FilePath) (mode : FileRight) : IO Unit :=
Prim.setAccessRights filename mode.flags
/- References -/
abbrev Ref (Ξ± : Type) := ST.Ref IO.RealWorld Ξ±
instance : MonadLift (ST IO.RealWorld) (EIO Ξ΅) := β¨fun x s =>
match x s with
| EStateM.Result.ok a s => EStateM.Result.ok a s
| EStateM.Result.error ex _ => nomatch exβ©
def mkRef (a : Ξ±) : IO (IO.Ref Ξ±) :=
ST.mkRef a
namespace FS
namespace Stream
@[export lean_stream_of_handle]
def ofHandle (h : Handle) : Stream := {
isEof := Handle.isEof h,
flush := Handle.flush h,
read := Handle.read h,
write := Handle.write h,
getLine := Handle.getLine h,
putStr := Handle.putStr h,
}
structure Buffer where
data : ByteArray := ByteArray.empty
pos : Nat := 0
def ofBuffer (r : Ref Buffer) : Stream := {
isEof := do let b β r.get; pure <| b.pos >= b.data.size,
flush := pure (),
read := fun n => r.modifyGet fun b =>
let data := b.data.extract b.pos (b.pos + n.toNat)
(data, { b with pos := b.pos + data.size }),
write := fun data => r.modify fun b =>
-- set `exact` to `false` so that repeatedly writing to the stream does not impose quadratic run time
{ b with data := data.copySlice 0 b.data b.pos data.size false, pos := b.pos + data.size },
getLine := r.modifyGet fun b =>
let pos := match b.data.findIdx? (start := b.pos) fun u => u == 0 || u = '\n'.toNat.toUInt8 with
-- include '\n', but not '\0'
| some pos => if b.data.get! pos == 0 then pos else pos + 1
| none => b.data.size
(String.fromUTF8Unchecked <| b.data.extract b.pos pos, { b with pos := pos }),
putStr := fun s => r.modify fun b =>
let data := s.toUTF8
{ b with data := data.copySlice 0 b.data b.pos data.size false, pos := b.pos + data.size },
}
end Stream
/-- Run action with `stdin` emptied and `stdout+stderr` captured into a `String`. -/
def withIsolatedStreams [Monad m] [MonadFinally m] [MonadExceptOf IO.Error m] [MonadLiftT IO m] (x : m Ξ±) : m (String Γ Except IO.Error Ξ±) := do
let bIn β mkRef { : Stream.Buffer }
let bOut β mkRef { : Stream.Buffer }
let r β withStdin (Stream.ofBuffer bIn) <|
withStdout (Stream.ofBuffer bOut) <|
withStderr (Stream.ofBuffer bOut) <|
observing x
let bOut β liftM (m := IO) bOut.get
let out := String.fromUTF8Unchecked bOut.data
pure (out, r)
end FS
end IO
universe u
namespace Lean
/-- Typeclass used for presenting the output of an `#eval` command. -/
class Eval (Ξ± : Type u) where
-- We default `hideUnit` to `true`, but set it to `false` in the direct call from `#eval`
-- so that `()` output is hidden in chained instances such as for some `IO Unit`.
-- We take `Unit β Ξ±` instead of `Ξ±` because β΅Ξ±` may contain effectful debugging primitives (e.g., `dbg_trace`)
eval : (Unit β Ξ±) β forall (hideUnit : optParam Bool true), IO Unit
instance [ToString Ξ±] : Eval Ξ± :=
β¨fun a _ => IO.println (toString (a ()))β©
instance [Repr Ξ±] : Eval Ξ± :=
β¨fun a _ => IO.println (repr (a ()))β©
instance : Eval Unit :=
β¨fun u hideUnit => if hideUnit then pure () else IO.println (repr (u ()))β©
instance [Eval Ξ±] : Eval (IO Ξ±) :=
β¨fun x _ => do let a β x (); Eval.eval (fun _ => a)β©
@[noinline, nospecialize] def runEval [Eval Ξ±] (a : Unit β Ξ±) : IO (String Γ Except IO.Error Unit) :=
IO.FS.withIsolatedStreams (Eval.eval a false)
end Lean
syntax "println! " (interpolatedStr(term) <|> term) : term
macro_rules
| `(println! $msg) =>
if msg.getKind == Lean.interpolatedStrKind then
`((IO.println (s! $msg) : IO Unit))
else
`((IO.println $msg : IO Unit))
|
b6cf714a23f297f3a1a9b01f61888cd615168785 | 1dd482be3f611941db7801003235dc84147ec60a | /src/tactic/basic.lean | 5e4c76e07553fb6ceed845b2b770e8173d09f2ac | [
"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 | 30,041 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Simon Hudon, Scott Morrison, Keeley Hoek
-/
import data.dlist.basic category.basic meta.expr meta.rb_map
namespace expr
open tactic
attribute [derive has_reflect] binder_info
protected meta def of_nat (Ξ± : expr) : β β tactic expr :=
nat.binary_rec
(tactic.mk_mapp ``has_zero.zero [some Ξ±, none])
(Ξ» b n tac, if n = 0 then mk_mapp ``has_one.one [some Ξ±, none] else
do e β tac, tactic.mk_app (cond b ``bit1 ``bit0) [e])
protected meta def of_int (Ξ± : expr) : β€ β tactic expr
| (n : β) := expr.of_nat Ξ± n
| -[1+ n] := do
e β expr.of_nat Ξ± (n+1),
tactic.mk_app ``has_neg.neg [e]
/- only traverses the direct descendents -/
meta def {u} traverse {m : Type β Type u} [applicative m]
{elab elab' : bool} (f : expr elab β m (expr elab')) :
expr elab β m (expr elab')
| (var v) := pure $ var v
| (sort l) := pure $ sort l
| (const n ls) := pure $ const n ls
| (mvar n n' e) := mvar n n' <$> f e
| (local_const n n' bi e) := local_const n n' bi <$> f e
| (app eβ eβ) := app <$> f eβ <*> f eβ
| (lam n bi eβ eβ) := lam n bi <$> f eβ <*> f eβ
| (pi n bi eβ eβ) := pi n bi <$> f eβ <*> f eβ
| (elet n eβ eβ eβ) := elet n <$> f eβ <*> f eβ <*> f eβ
| (macro mac es) := macro mac <$> list.traverse f es
meta def mfoldl {Ξ± : Type} {m} [monad m] (f : Ξ± β expr β m Ξ±) : Ξ± β expr β m Ξ±
| x e := prod.snd <$> (state_t.run (e.traverse $ Ξ» e',
(get >>= monad_lift β flip f e' >>= put) $> e') x : m _)
end expr
namespace interaction_monad
open result
meta def get_result {Ο Ξ±} (tac : interaction_monad Ο Ξ±) :
interaction_monad Ο (interaction_monad.result Ο Ξ±) | s :=
match tac s with
| r@(success _ s') := success r s'
| r@(exception _ _ s') := success r s'
end
end interaction_monad
namespace lean.parser
open lean interaction_monad.result
meta def of_tactic' {Ξ±} (tac : tactic Ξ±) : parser Ξ± :=
do r β of_tactic (interaction_monad.get_result tac),
match r with
| (success a _) := return a
| (exception f pos _) := exception f pos
end
-- Override the builtin `lean.parser.of_tactic` coe, which is broken.
-- (See test/tactics.lean for a failure case.)
@[priority 2000]
meta instance has_coe' {Ξ±} : has_coe (tactic Ξ±) (parser Ξ±) :=
β¨of_tactic'β©
meta def emit_command_here (str : string) : lean.parser string :=
do (_, left) β with_input command_like str,
return left
-- Emit a source code string at the location being parsed.
meta def emit_code_here : string β lean.parser unit
| str := do left β emit_command_here str,
if left.length = 0 then return ()
else emit_code_here left
end lean.parser
namespace tactic
meta def eval_expr' (Ξ± : Type*) [_inst_1 : reflected Ξ±] (e : expr) : tactic Ξ± :=
mk_app ``id [e] >>= eval_expr Ξ±
-- `mk_fresh_name` returns identifiers starting with underscores,
-- which are not legal when emitted by tactic programs. Turn the
-- useful source of random names provided by `mk_fresh_name` into
-- names which are usable by tactic programs.
--
-- The returned name has four components.
meta def mk_user_fresh_name : tactic name :=
do nm β mk_fresh_name,
return $ `user__ ++ nm.pop_prefix.sanitize_name ++ `user__
meta def is_simp_lemma : name β tactic bool :=
succeeds β tactic.has_attribute `simp
meta def local_decls : tactic (name_map declaration) :=
do e β tactic.get_env,
let xs := e.fold native.mk_rb_map
(Ξ» d s, if environment.in_current_file' e d.to_name
then s.insert d.to_name d else s),
pure xs
meta def simp_lemmas_from_file : tactic name_set :=
do s β local_decls,
let s := s.map (expr.list_constant β declaration.value),
xs β s.to_list.mmap ((<$>) name_set.of_list β mfilter tactic.is_simp_lemma β name_set.to_list β prod.snd),
return $ name_set.filter (xs.foldl name_set.union mk_name_set) (Ξ» x, Β¬ s.contains x)
meta def file_simp_attribute_decl (attr : name) : tactic unit :=
do s β simp_lemmas_from_file,
trace format!"run_cmd mk_simp_attr `{attr}",
let lmms := format.join $ list.intersperse " " $ s.to_list.map to_fmt,
trace format!"local attribute [{attr}] {lmms}"
meta def mk_local (n : name) : expr :=
expr.local_const n n binder_info.default (expr.const n [])
meta def local_def_value (e : expr) : tactic expr := do
do (v,_) β solve_aux `(true) (do
(expr.elet n t v _) β (revert e >> target)
| fail format!"{e} is not a local definition",
return v),
return v
meta def check_defn (n : name) (e : pexpr) : tactic unit :=
do (declaration.defn _ _ _ d _ _) β get_decl n,
e' β to_expr e,
guard (d =β e') <|> trace d >> failed
-- meta def compile_eqn (n : name) (univ : list name) (args : list expr) (val : expr) (num : β) : tactic unit :=
-- do let lhs := (expr.const n $ univ.map level.param).mk_app args,
-- stmt β mk_app `eq [lhs,val],
-- let vs := stmt.list_local_const,
-- let stmt := stmt.pis vs,
-- (_,pr) β solve_aux stmt (tactic.intros >> reflexivity),
-- add_decl $ declaration.thm (n <.> "equations" <.> to_string (format!"_eqn_{num}")) univ stmt (pure pr)
meta def to_implicit : expr β expr
| (expr.local_const uniq n bi t) := expr.local_const uniq n binder_info.implicit t
| e := e
meta def pis : list expr β expr β tactic expr
| (e@(expr.local_const uniq pp info _) :: es) f := do
t β infer_type e,
f' β pis es f,
pure $ expr.pi pp info t (expr.abstract_local f' uniq)
| _ f := pure f
meta def lambdas : list expr β expr β tactic expr
| (e@(expr.local_const uniq pp info _) :: es) f := do
t β infer_type e,
f' β lambdas es f,
pure $ expr.lam pp info t (expr.abstract_local f' uniq)
| _ f := pure f
meta def extract_def (n : name) (trusted : bool) (elab_def : tactic unit) : tactic unit :=
do cxt β list.map to_implicit <$> local_context,
t β target,
(eqns,d) β solve_aux t elab_def,
d β instantiate_mvars d,
t' β pis cxt t,
d' β lambdas cxt d,
let univ := t'.collect_univ_params,
add_decl $ declaration.defn n univ t' d' (reducibility_hints.regular 1 tt) trusted,
applyc n
meta def exact_dec_trivial : tactic unit := `[exact dec_trivial]
/-- Runs a tactic for a result, reverting the state after completion -/
meta def retrieve {Ξ±} (tac : tactic Ξ±) : tactic Ξ± :=
Ξ» s, result.cases_on (tac s)
(Ξ» a s', result.success a s)
result.exception
/-- Repeat a tactic at least once, calling it recursively on all subgoals,
until it fails. This tactic fails if the first invocation fails. -/
meta def repeat1 (t : tactic unit) : tactic unit := t; repeat t
/-- `iterate_range m n t`: Repeat the given tactic at least `m` times and
at most `n` times or until `t` fails. Fails if `t` does not run at least m times. -/
meta def iterate_range : β β β β tactic unit β tactic unit
| 0 0 t := skip
| 0 (n+1) t := try (t >> iterate_range 0 n t)
| (m+1) n t := t >> iterate_range m (n-1) t
meta def replace_at (tac : expr β tactic (expr Γ expr)) (hs : list expr) (tgt : bool) : tactic bool :=
do to_remove β hs.mfilter $ Ξ» h, do {
h_type β infer_type h,
succeeds $ do
(new_h_type, pr) β tac h_type,
assert h.local_pp_name new_h_type,
mk_eq_mp pr h >>= tactic.exact },
goal_simplified β succeeds $ do {
guard tgt,
(new_t, pr) β target >>= tac,
replace_target new_t pr },
to_remove.mmap' (Ξ» h, try (clear h)),
return (Β¬ to_remove.empty β¨ goal_simplified)
meta def simp_bottom_up' (post : expr β tactic (expr Γ expr)) (e : expr) (cfg : simp_config := {}) : tactic (expr Γ expr) :=
prod.snd <$> simplify_bottom_up () (Ξ» _, (<$>) (prod.mk ()) β post) e cfg
meta structure instance_cache :=
(Ξ± : expr)
(univ : level)
(inst : name_map expr)
meta def mk_instance_cache (Ξ± : expr) : tactic instance_cache :=
do u β mk_meta_univ,
infer_type Ξ± >>= unify (expr.sort (level.succ u)),
u β get_univ_assignment u,
return β¨Ξ±, u, mk_name_mapβ©
namespace instance_cache
meta def get (c : instance_cache) (n : name) : tactic (instance_cache Γ expr) :=
match c.inst.find n with
| some i := return (c, i)
| none := do e β mk_app n [c.Ξ±] >>= mk_instance,
return (β¨c.Ξ±, c.univ, c.inst.insert n eβ©, e)
end
open expr
meta def append_typeclasses : expr β instance_cache β list expr β
tactic (instance_cache Γ list expr)
| (pi _ binder_info.inst_implicit (app (const n _) (var _)) body) c l :=
do (c, p) β c.get n, return (c, p :: l)
| _ c l := return (c, l)
meta def mk_app (c : instance_cache) (n : name) (l : list expr) : tactic (instance_cache Γ expr) :=
do d β get_decl n,
(c, l) β append_typeclasses d.type.binding_body c l,
return (c, (expr.const n [c.univ]).mk_app (c.Ξ± :: l))
end instance_cache
/-- Reset the instance cache for the main goal. -/
meta def reset_instance_cache : tactic unit := unfreeze_local_instances
meta def match_head (e : expr) : expr β tactic unit
| e' :=
unify e e'
<|> do `(_ β %%e') β whnf e',
v β mk_mvar,
match_head (e'.instantiate_var v)
meta def find_matching_head : expr β list expr β tactic (list expr)
| e [] := return []
| e (H :: Hs) :=
do t β infer_type H,
((::) H <$ match_head e t <|> pure id) <*> find_matching_head e Hs
meta def subst_locals (s : list (expr Γ expr)) (e : expr) : expr :=
(e.abstract_locals (s.map (expr.local_uniq_name β prod.fst)).reverse).instantiate_vars (s.map prod.snd)
meta def set_binder : expr β list binder_info β expr
| e [] := e
| (expr.pi v _ d b) (bi :: bs) := expr.pi v bi d (set_binder b bs)
| e _ := e
meta def last_explicit_arg : expr β tactic expr
| (expr.app f e) :=
do t β infer_type f >>= whnf,
if t.binding_info = binder_info.default
then pure e
else last_explicit_arg f
| e := pure e
private meta def get_expl_pi_arity_aux : expr β tactic nat
| (expr.pi n bi d b) :=
do m β mk_fresh_name,
let l := expr.local_const m n bi d,
new_b β whnf (expr.instantiate_var b l),
r β get_expl_pi_arity_aux new_b,
if bi = binder_info.default then
return (r + 1)
else
return r
| e := return 0
/-- Compute the arity of explicit arguments of the given (Pi-)type -/
meta def get_expl_pi_arity (type : expr) : tactic nat :=
whnf type >>= get_expl_pi_arity_aux
/-- Compute the arity of explicit arguments of the given function -/
meta def get_expl_arity (fn : expr) : tactic nat :=
infer_type fn >>= get_expl_pi_arity
/-- variation on `assert` where a (possibly incomplete)
proof of the assertion is provided as a parameter.
``(h,gs) β local_proof `h p tac`` creates a local `h : p` and
use `tac` to (partially) construct a proof for it. `gs` is the
list of remaining goals in the proof of `h`.
The benefits over assert are:
- unlike with ``h β assert `h p, tac`` , `h` cannot be used by `tac`;
- when `tac` does not complete the proof of `h`, returning the list
of goals allows one to write a tactic using `h` and with the confidence
that a proof will not boil over to goals left over from the proof of `h`,
unlike what would be the case when using `tactic.swap`.
-/
meta def local_proof (h : name) (p : expr) (tacβ : tactic unit) :
tactic (expr Γ list expr) :=
focus1 $
do h' β assert h p,
[gβ,gβ] β get_goals,
set_goals [gβ], tacβ,
gs β get_goals,
set_goals [gβ],
return (h', gs)
meta def var_names : expr β list name
| (expr.pi n _ _ b) := n :: var_names b
| _ := []
meta def drop_binders : expr β tactic expr
| (expr.pi n bi t b) := b.instantiate_var <$> mk_local' n bi t >>= drop_binders
| e := pure e
meta def subobject_names (struct_n : name) : tactic (list name Γ list name) :=
do env β get_env,
[c] β pure $ env.constructors_of struct_n | fail "too many constructors",
vs β var_names <$> (mk_const c >>= infer_type),
fields β env.structure_fields struct_n,
return $ fields.partition (Ξ» fn, β("_" ++ fn.to_string) β vs)
meta def expanded_field_list' : name β tactic (dlist $ name Γ name) | struct_n :=
do (so,fs) β subobject_names struct_n,
ts β so.mmap (Ξ» n, do
e β mk_const (n.update_prefix struct_n) >>= infer_type >>= drop_binders,
expanded_field_list' $ e.get_app_fn.const_name),
return $ dlist.join ts ++ dlist.of_list (fs.map $ prod.mk struct_n)
open functor function
meta def expanded_field_list (struct_n : name) : tactic (list $ name Γ name) :=
dlist.to_list <$> expanded_field_list' struct_n
meta def get_classes (e : expr) : tactic (list name) :=
attribute.get_instances `class >>= list.mfilter (Ξ» n,
succeeds $ mk_app n [e] >>= mk_instance)
open nat
meta def mk_mvar_list : β β tactic (list expr)
| 0 := pure []
| (succ n) := (::) <$> mk_mvar <*> mk_mvar_list n
/--`iterate_at_most_on_all_goals n t`: repeat the given tactic at most `n` times on all goals,
or until it fails. Always succeeds. -/
meta def iterate_at_most_on_all_goals : nat β tactic unit β tactic unit
| 0 tac := trace "maximal iterations reached"
| (succ n) tac := tactic.all_goals $ (do tac, iterate_at_most_on_all_goals n tac) <|> skip
/--`iterate_at_most_on_subgoals n t`: repeat the tactic `t` at most `n` times on the first
goal and on all subgoals thus produced, or until it fails. Fails iff `t` fails on
current goal. -/
meta def iterate_at_most_on_subgoals : nat β tactic unit β tactic unit
| 0 tac := trace "maximal iterations reached"
| (succ n) tac := focus1 (do tac, iterate_at_most_on_all_goals n tac)
/--`apply_list l`: try to apply the tactics in the list `l` on the first goal, and
fail if none succeeds -/
meta def apply_list_expr : list expr β tactic unit
| [] := fail "no matching rule"
| (h::t) := do interactive.concat_tags (apply h) <|> apply_list_expr t
/-- constructs a list of expressions given a list of p-expressions, as follows:
- if the p-expression is the name of a theorem, use `i_to_expr_for_apply` on it
- if the p-expression is a user attribute, add all the theorems with this attribute
to the list.-/
meta def build_list_expr_for_apply : list pexpr β tactic (list expr)
| [] := return []
| (h::t) := do
tail β build_list_expr_for_apply t,
a β i_to_expr_for_apply h,
(do l β attribute.get_instances (expr.const_name a),
m β list.mmap mk_const l,
return (m.append tail))
<|> return (a::tail)
/--`apply_rules hs n`: apply the list of rules `hs` (given as pexpr) and `assumption` on the
first goal and the resulting subgoals, iteratively, at most `n` times -/
meta def apply_rules (hs : list pexpr) (n : nat) : tactic unit :=
do l β build_list_expr_for_apply hs,
iterate_at_most_on_subgoals n (assumption <|> apply_list_expr l)
meta def replace (h : name) (p : pexpr) : tactic unit :=
do h' β get_local h,
p β to_expr p,
note h none p,
clear h'
meta def symm_apply (e : expr) (cfg : apply_cfg := {}) : tactic (list (name Γ expr)) :=
tactic.apply e cfg <|> (symmetry >> tactic.apply e cfg)
meta def apply_assumption
(asms : tactic (list expr) := local_context)
(tac : tactic unit := skip) : tactic unit :=
do { ctx β asms,
ctx.any_of (Ξ» H, symm_apply H >> tac) } <|>
do { exfalso,
ctx β asms,
ctx.any_of (Ξ» H, symm_apply H >> tac) }
<|> fail "assumption tactic failed"
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
open nat
meta def solve_by_elim_aux (discharger : tactic unit) (asms : tactic (list expr)) : β β tactic unit
| 0 := done
| (succ n) := discharger <|> (apply_assumption asms $ solve_by_elim_aux n)
meta structure by_elim_opt :=
(discharger : tactic unit := done)
(assumptions : tactic (list expr) := local_context)
(max_rep : β := 3)
meta def solve_by_elim (opt : by_elim_opt := { }) : tactic unit :=
do
tactic.fail_if_no_goals,
focus1 $
solve_by_elim_aux opt.discharger opt.assumptions opt.max_rep
meta def metavariables : tactic (list expr) :=
do r β result,
pure (r.list_meta_vars)
/-- Succeeds only if the current goal is a proposition. -/
meta def propositional_goal : tactic unit :=
do goals β get_goals,
p β is_proof goals.head,
guard p
meta def triv' : tactic unit := do c β mk_const `trivial, exact c reducible
variable {Ξ± : Type}
private meta def iterate_aux (t : tactic Ξ±) : list Ξ± β tactic (list Ξ±)
| L := (do r β t, iterate_aux (r :: L)) <|> return L
/-- Apply a tactic as many times as possible, collecting the results in a list. -/
meta def iterate' (t : tactic Ξ±) : tactic (list Ξ±) :=
list.reverse <$> iterate_aux t []
/-- Like iterate', but fail if the tactic does not succeed at least once. -/
meta def iterate1 (t : tactic Ξ±) : tactic (Ξ± Γ list Ξ±) :=
do r β decorate_ex "iterate1 failed: tactic did not succeed" t,
L β iterate' t,
return (r, L)
meta def intros1 : tactic (list expr) :=
iterate1 intro1 >>= Ξ» p, return (p.1 :: p.2)
/-- `successes` invokes each tactic in turn, returning the list of successful results. -/
meta def successes (tactics : list (tactic Ξ±)) : tactic (list Ξ±) :=
list.filter_map id <$> monad.sequence (tactics.map (Ξ» t, try_core t))
/-- Return target after instantiating metavars and whnf -/
private meta def target' : tactic expr :=
target >>= instantiate_mvars >>= whnf
/--
Just like `split`, `fsplit` applies the constructor when the type of the target is an inductive data type with one constructor.
However it does not reorder goals or invoke `auto_param` tactics.
-/
-- FIXME check if we can remove `auto_param := ff`
meta def fsplit : tactic unit :=
do [c] β target' >>= get_constructors_for | tactic.fail "fsplit tactic failed, target is not an inductive datatype with only one constructor",
mk_const c >>= Ξ» e, apply e {new_goals := new_goals.all, auto_param := ff} >> skip
run_cmd add_interactive [`fsplit]
/-- Calls `injection` on each hypothesis, and then, for each hypothesis on which `injection`
succeeds, clears the old hypothesis. -/
meta def injections_and_clear : tactic unit :=
do l β local_context,
results β successes $ l.map $ Ξ» e, injection e >> clear e,
when (results.empty) (fail "could not use `injection` then `clear` on any hypothesis")
run_cmd add_interactive [`injections_and_clear]
meta def note_anon (e : expr) : tactic unit :=
do n β get_unused_name "lh",
note n none e, skip
/-- `find_local t` returns a local constant with type t, or fails if none exists. -/
meta def find_local (t : pexpr) : tactic expr :=
do t' β to_expr t,
prod.snd <$> solve_aux t' assumption
/-- `dependent_pose_core l`: introduce dependent hypothesis, where the proofs depend on the values
of the previous local constants. `l` is a list of local constants and their values. -/
meta def dependent_pose_core (l : list (expr Γ expr)) : tactic unit := do
let lc := l.map prod.fst,
let lm := l.map (Ξ»β¨l, vβ©, (l.local_uniq_name, v)),
t β target,
new_goal β mk_meta_var (t.pis lc),
old::other_goals β get_goals,
set_goals (old :: new_goal :: other_goals),
exact ((new_goal.mk_app lc).instantiate_locals lm),
return ()
/-- like `mk_local_pis` but translating into weak head normal form before checking if it is a Ξ . -/
meta def mk_local_pis_whnf : expr β tactic (list expr Γ expr) | e := do
(expr.pi n bi d b) β whnf e | return ([], e),
p β mk_local' n bi d,
(ps, r) β mk_local_pis (expr.instantiate_var b p),
return ((p :: ps), r)
/-- Changes `(h : βxs, βa:Ξ±, p a) β’ g` to `(d : βxs, a) (s : βxs, p (d xs) β’ g` -/
meta def choose1 (h : expr) (data : name) (spec : name) : tactic expr := do
t β infer_type h,
(ctxt, t) β mk_local_pis_whnf t,
`(@Exists %%Ξ± %%p) β whnf t transparency.all | fail "expected a term of the shape βxs, βa, p xs a",
Ξ±_t β infer_type Ξ±,
expr.sort u β whnf Ξ±_t transparency.all,
value β mk_local_def data (Ξ±.pis ctxt),
t' β head_beta (p.app (value.mk_app ctxt)),
spec β mk_local_def spec (t'.pis ctxt),
dependent_pose_core [
(value, ((((expr.const `classical.some [u]).app Ξ±).app p).app (h.mk_app ctxt)).lambdas ctxt),
(spec, ((((expr.const `classical.some_spec [u]).app Ξ±).app p).app (h.mk_app ctxt)).lambdas ctxt)],
try (tactic.clear h),
intro1,
intro1
/-- Changes `(h : βxs, βas, p as) β’ g` to a list of functions `as`, an a final hypothesis on `p as` -/
meta def choose : expr β list name β tactic unit
| h [] := fail "expect list of variables"
| h [n] := do
cnt β revert h,
intro n,
intron (cnt - 1),
return ()
| h (n::ns) := do
v β get_unused_name >>= choose1 h n,
choose v ns
/-- This makes sure that the execution of the tactic does not change the tactic state.
This can be helpful while using rewrite, apply, or expr munging.
Remember to instantiate your metavariables before you're done! -/
meta def lock_tactic_state {Ξ±} (t : tactic Ξ±) : tactic Ξ±
| s := match t s with
| result.success a s' := result.success a s
| result.exception msg pos s' := result.exception msg pos s
end
/--
Hole command used to fill in a structure's field when specifying an instance.
In the following:
```
instance : monad id :=
{! !}
```
invoking hole command `Instance Stub` produces:
```
instance : monad id :=
{ map := _,
map_const := _,
pure := _,
seq := _,
seq_left := _,
seq_right := _,
bind := _ }
```
-/
@[hole_command] meta def instance_stub : hole_command :=
{ name := "Instance Stub",
descr := "Generate a skeleton for the structure under construction.",
action := Ξ» _,
do tgt β target >>= whnf,
let cl := tgt.get_app_fn.const_name,
env β get_env,
fs β expanded_field_list cl,
let fs := fs.map prod.snd,
let fs := list.intersperse (",\n " : format) $ fs.map (Ξ» fn, format!"{fn} := _"),
let out := format.to_string format!"{{ {format.join fs} }",
return [(out,"")] }
meta def is_default_local : expr β bool
| (expr.local_const _ _ binder_info.default _) := tt
| _ := ff
meta def mk_patterns (t : expr) : tactic (list format) :=
do let cl := t.get_app_fn.const_name,
env β get_env,
let fs := env.constructors_of cl,
fs.mmap $ Ξ» f,
do { (vs,_) β mk_const f >>= infer_type >>= mk_local_pis,
let vs := vs.filter (Ξ» v, is_default_local v),
vs β vs.mmap (Ξ» v,
do v' β get_unused_name v.local_pp_name,
pose v' none `(()),
pure v' ),
vs.mmap' $ Ξ» v, get_local v >>= clear,
let args := list.intersperse (" " : format) $ vs.map to_fmt,
if args.empty
then pure $ format!"| {f} := _\n"
else pure format!"| ({f} {format.join args}) := _\n" }
/--
Hole command used to generate a `match` expression.
In the following:
```
meta def foo (e : expr) : tactic unit :=
{! e !}
```
invoking hole command `Match Stub` produces:
```
meta def foo (e : expr) : tactic unit :=
match e with
| (expr.var a) := _
| (expr.sort a) := _
| (expr.const a a_1) := _
| (expr.mvar a a_1 a_2) := _
| (expr.local_const a a_1 a_2 a_3) := _
| (expr.app a a_1) := _
| (expr.lam a a_1 a_2 a_3) := _
| (expr.pi a a_1 a_2 a_3) := _
| (expr.elet a a_1 a_2 a_3) := _
| (expr.macro a a_1) := _
end
```
-/
@[hole_command] meta def match_stub : hole_command :=
{ name := "Match Stub",
descr := "Generate a list of equations for a `match` expression.",
action := Ξ» es,
do [e] β pure es | fail "expecting one expression",
e β to_expr e,
t β infer_type e >>= whnf,
fs β mk_patterns t,
e β pp e,
let out := format.to_string format!"match {e} with\n{format.join fs}end\n",
return [(out,"")] }
/--
Hole command used to generate a `match` expression.
In the following:
```
meta def foo : {! expr β tactic unit !} -- `:=` is omitted
```
invoking hole command `Equations Stub` produces:
```
meta def foo : expr β tactic unit
| (expr.var a) := _
| (expr.sort a) := _
| (expr.const a a_1) := _
| (expr.mvar a a_1 a_2) := _
| (expr.local_const a a_1 a_2 a_3) := _
| (expr.app a a_1) := _
| (expr.lam a a_1 a_2 a_3) := _
| (expr.pi a a_1 a_2 a_3) := _
| (expr.elet a a_1 a_2 a_3) := _
| (expr.macro a a_1) := _
```
A similar result can be obtained by invoking `Equations Stub` on the following:
```
meta def foo : expr β tactic unit := -- do not forget to write `:=`!!
{! !}
```
```
meta def foo : expr β tactic unit := -- don't forget to erase `:=`!!
| (expr.var a) := _
| (expr.sort a) := _
| (expr.const a a_1) := _
| (expr.mvar a a_1 a_2) := _
| (expr.local_const a a_1 a_2 a_3) := _
| (expr.app a a_1) := _
| (expr.lam a a_1 a_2 a_3) := _
| (expr.pi a a_1 a_2 a_3) := _
| (expr.elet a a_1 a_2 a_3) := _
| (expr.macro a a_1) := _
```
-/
@[hole_command] meta def eqn_stub : hole_command :=
{ name := "Equations Stub",
descr := "Generate a list of equations for a recursive definition.",
action := Ξ» es,
do t β match es with
| [t] := to_expr t
| [] := target
| _ := fail "expecting one type"
end,
e β whnf t,
(v :: _,_) β mk_local_pis e | fail "expecting a Pi-type",
t' β infer_type v,
fs β mk_patterns t',
t β pp t,
let out :=
if es.empty then
format.to_string format!"-- do not forget to erase `:=`!!\n{format.join fs}"
else format.to_string format!"{t}\n{format.join fs}",
return [(out,"")] }
/--
This command lists the constructors that can be used to satisfy the expected type.
When used in the following hole:
```
def foo : β€ β β :=
{! !}
```
the command will produce:
```
def foo : β€ β β :=
{! sum.inl, sum.inr !}
```
and will display:
```
sum.inl : β€ β β€ β β
sum.inr : β β β€ β β
```
-/
@[hole_command] meta def list_constructors_hole : hole_command :=
{ name := "List Constructors",
descr := "Show the list of constructors of the expected type.",
action := Ξ» es,
do t β target >>= whnf,
(_,t) β mk_local_pis t,
let cl := t.get_app_fn.const_name,
let args := t.get_app_args,
env β get_env,
let cs := env.constructors_of cl,
ts β cs.mmap $ Ξ» c,
do { e β mk_const c,
t β infer_type (e.mk_app args) >>= pp,
pure format!"\n{c} : {t}\n" },
let fs := list.intersperse (", " : format) $ cs.map to_fmt,
let out := format.to_string format!"{{! {format.join fs} !}",
trace (format.join ts).to_string,
return [(out,"")] }
meta def classical : tactic unit :=
do h β get_unused_name `_inst,
mk_const `classical.prop_decidable >>= note h none,
reset_instance_cache
open expr
meta def add_prime : name β name
| (name.mk_string s p) := name.mk_string (s ++ "'") p
| n := (name.mk_string "x'" n)
meta def mk_comp (v : expr) : expr β tactic expr
| (app f e) :=
if e = v then pure f
else do
guard (Β¬ v.occurs f) <|> fail "bad guard",
e' β mk_comp e >>= instantiate_mvars,
f β instantiate_mvars f,
mk_mapp ``function.comp [none,none,none,f,e']
| e :=
do guard (e = v),
t β infer_type e,
mk_mapp ``id [t]
meta def mk_higher_order_type : expr β tactic expr
| (pi n bi d b@(pi _ _ _ _)) :=
do v β mk_local_def n d,
let b' := (b.instantiate_var v),
(pi n bi d β flip abstract_local v.local_uniq_name) <$> mk_higher_order_type b'
| (pi n bi d b) :=
do v β mk_local_def n d,
let b' := (b.instantiate_var v),
(l,r) β match_eq b' <|> fail format!"not an equality {b'}",
l' β mk_comp v l,
r' β mk_comp v r,
mk_app ``eq [l',r']
| e := failed
open lean.parser interactive.types
@[user_attribute]
meta def higher_order_attr : user_attribute unit (option name) :=
{ name := `higher_order,
parser := optional ident,
descr :=
"From a lemma of the shape `f (g x) = h x` derive an auxiliary lemma of the
form `f β g = h` for reasoning about higher-order functions.",
after_set := some $ Ξ» lmm _ _,
do env β get_env,
decl β env.get lmm,
let num := decl.univ_params.length,
let lvls := (list.iota num).map (`l).append_after,
let l : expr := expr.const lmm $ lvls.map level.param,
t β infer_type l >>= instantiate_mvars,
t' β mk_higher_order_type t,
(_,pr) β solve_aux t' $ do {
intros, applyc ``_root_.funext, intro1, applyc lmm; assumption },
pr β instantiate_mvars pr,
lmm' β higher_order_attr.get_param lmm,
lmm' β (flip name.update_prefix lmm.get_prefix <$> lmm') <|> pure (add_prime lmm),
add_decl $ declaration.thm lmm' lvls t' (pure pr),
copy_attribute `simp lmm tt lmm',
copy_attribute `functor_norm lmm tt lmm' }
attribute [higher_order map_comp_pure] map_pure
private meta def tactic.use_aux (h : pexpr) : tactic unit :=
(focus1 (refine h >> done)) <|> (fconstructor >> tactic.use_aux)
meta def tactic.use (l : list pexpr) : tactic unit :=
focus1 $ l.mmap' $ Ξ» h, tactic.use_aux h <|> fail format!"failed to instantiate goal with {h}"
meta def clear_aux_decl_aux : list expr β tactic unit
| [] := skip
| (e::l) := do cond e.is_aux_decl (tactic.clear e) skip, clear_aux_decl_aux l
meta def clear_aux_decl : tactic unit :=
local_context >>= clear_aux_decl_aux
protected meta def set (a h : name) (v : expr) (b_simp : bool := ff) (b_symm : bool := false) : tactic unit :=
do tp β infer_type v,
nv β definev a tp v,
pf β to_expr (cond b_symm ``(%%v = %%nv) ``(%%nv = %%v)) >>= assert h,
reflexivity,
when b_simp $ do
rw β cond b_symm (return pf) (mk_app `eq.symm [pf]),
s β simp_lemmas.mk.add rw,
hyps β list.filter (Ξ» e, e β pf) <$> non_dep_prop_hyps,
interactive.simp_core_aux {} tactic.failed s [] hyps tt
end tactic
|
ffefc23ca01c5a2193d48c9312bb316e2fb28822 | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/analysis/special_functions/trigonometric/deriv.lean | 22f70695f67388eb946aa9fbe1520bf3c442572a | [
"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 | 37,849 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne, Benjamin Davidson
-/
import analysis.special_functions.exp_deriv
import analysis.special_functions.trigonometric.basic
import data.set.intervals.monotone
/-!
# Differentiability of trigonometric functions
## Main statements
The differentiability of the usual trigonometric functions is proved, and their derivatives are
computed.
## Tags
sin, cos, tan, angle
-/
noncomputable theory
open_locale classical topological_space filter
open set filter
namespace complex
/-- The complex sine function is everywhere strictly differentiable, with the derivative `cos x`. -/
lemma has_strict_deriv_at_sin (x : β) : has_strict_deriv_at sin (cos x) x :=
begin
simp only [cos, div_eq_mul_inv],
convert ((((has_strict_deriv_at_id x).neg.mul_const I).cexp.sub
((has_strict_deriv_at_id x).mul_const I).cexp).mul_const I).mul_const (2:β)β»ΒΉ,
simp only [function.comp, id],
rw [sub_mul, mul_assoc, mul_assoc, I_mul_I, neg_one_mul, neg_neg, mul_one, one_mul, mul_assoc,
I_mul_I, mul_neg_one, sub_neg_eq_add, add_comm]
end
/-- The complex sine function is everywhere differentiable, with the derivative `cos x`. -/
lemma has_deriv_at_sin (x : β) : has_deriv_at sin (cos x) x :=
(has_strict_deriv_at_sin x).has_deriv_at
lemma cont_diff_sin {n} : cont_diff β n sin :=
(((cont_diff_neg.mul cont_diff_const).cexp.sub
(cont_diff_id.mul cont_diff_const).cexp).mul cont_diff_const).div_const
lemma differentiable_sin : differentiable β sin :=
Ξ»x, (has_deriv_at_sin x).differentiable_at
lemma differentiable_at_sin {x : β} : differentiable_at β sin x :=
differentiable_sin x
@[simp] lemma deriv_sin : deriv sin = cos :=
funext $ Ξ» x, (has_deriv_at_sin x).deriv
/-- The complex cosine function is everywhere strictly differentiable, with the derivative
`-sin x`. -/
lemma has_strict_deriv_at_cos (x : β) : has_strict_deriv_at cos (-sin x) x :=
begin
simp only [sin, div_eq_mul_inv, neg_mul_eq_neg_mul],
convert (((has_strict_deriv_at_id x).mul_const I).cexp.add
((has_strict_deriv_at_id x).neg.mul_const I).cexp).mul_const (2:β)β»ΒΉ,
simp only [function.comp, id],
ring
end
/-- The complex cosine function is everywhere differentiable, with the derivative `-sin x`. -/
lemma has_deriv_at_cos (x : β) : has_deriv_at cos (-sin x) x :=
(has_strict_deriv_at_cos x).has_deriv_at
lemma cont_diff_cos {n} : cont_diff β n cos :=
((cont_diff_id.mul cont_diff_const).cexp.add
(cont_diff_neg.mul cont_diff_const).cexp).div_const
lemma differentiable_cos : differentiable β cos :=
Ξ»x, (has_deriv_at_cos x).differentiable_at
lemma differentiable_at_cos {x : β} : differentiable_at β cos x :=
differentiable_cos x
lemma deriv_cos {x : β} : deriv cos x = -sin x :=
(has_deriv_at_cos x).deriv
@[simp] lemma deriv_cos' : deriv cos = (Ξ» x, -sin x) :=
funext $ Ξ» x, deriv_cos
/-- The complex hyperbolic sine function is everywhere strictly differentiable, with the derivative
`cosh x`. -/
lemma has_strict_deriv_at_sinh (x : β) : has_strict_deriv_at sinh (cosh x) x :=
begin
simp only [cosh, div_eq_mul_inv],
convert ((has_strict_deriv_at_exp x).sub (has_strict_deriv_at_id x).neg.cexp).mul_const (2:β)β»ΒΉ,
rw [id, mul_neg_one, sub_eq_add_neg, neg_neg]
end
/-- The complex hyperbolic sine function is everywhere differentiable, with the derivative
`cosh x`. -/
lemma has_deriv_at_sinh (x : β) : has_deriv_at sinh (cosh x) x :=
(has_strict_deriv_at_sinh x).has_deriv_at
lemma cont_diff_sinh {n} : cont_diff β n sinh :=
(cont_diff_exp.sub cont_diff_neg.cexp).div_const
lemma differentiable_sinh : differentiable β sinh :=
Ξ»x, (has_deriv_at_sinh x).differentiable_at
lemma differentiable_at_sinh {x : β} : differentiable_at β sinh x :=
differentiable_sinh x
@[simp] lemma deriv_sinh : deriv sinh = cosh :=
funext $ Ξ» x, (has_deriv_at_sinh x).deriv
/-- The complex hyperbolic cosine function is everywhere strictly differentiable, with the
derivative `sinh x`. -/
lemma has_strict_deriv_at_cosh (x : β) : has_strict_deriv_at cosh (sinh x) x :=
begin
simp only [sinh, div_eq_mul_inv],
convert ((has_strict_deriv_at_exp x).add (has_strict_deriv_at_id x).neg.cexp).mul_const (2:β)β»ΒΉ,
rw [id, mul_neg_one, sub_eq_add_neg]
end
/-- The complex hyperbolic cosine function is everywhere differentiable, with the derivative
`sinh x`. -/
lemma has_deriv_at_cosh (x : β) : has_deriv_at cosh (sinh x) x :=
(has_strict_deriv_at_cosh x).has_deriv_at
lemma cont_diff_cosh {n} : cont_diff β n cosh :=
(cont_diff_exp.add cont_diff_neg.cexp).div_const
lemma differentiable_cosh : differentiable β cosh :=
Ξ»x, (has_deriv_at_cosh x).differentiable_at
lemma differentiable_at_cosh {x : β} : differentiable_at β cosh x :=
differentiable_cosh x
@[simp] lemma deriv_cosh : deriv cosh = sinh :=
funext $ Ξ» x, (has_deriv_at_cosh x).deriv
end complex
section
/-! ### Simp lemmas for derivatives of `Ξ» x, complex.cos (f x)` etc., `f : β β β` -/
variables {f : β β β} {f' x : β} {s : set β}
/-! #### `complex.cos` -/
lemma has_strict_deriv_at.ccos (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (Ξ» x, complex.cos (f x)) (- complex.sin (f x) * f') x :=
(complex.has_strict_deriv_at_cos (f x)).comp x hf
lemma has_deriv_at.ccos (hf : has_deriv_at f f' x) :
has_deriv_at (Ξ» x, complex.cos (f x)) (- complex.sin (f x) * f') x :=
(complex.has_deriv_at_cos (f x)).comp x hf
lemma has_deriv_within_at.ccos (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (Ξ» x, complex.cos (f x)) (- complex.sin (f x) * f') s x :=
(complex.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_ccos (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
deriv_within (Ξ»x, complex.cos (f x)) s x = - complex.sin (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.ccos.deriv_within hxs
@[simp] lemma deriv_ccos (hc : differentiable_at β f x) :
deriv (Ξ»x, complex.cos (f x)) x = - complex.sin (f x) * (deriv f x) :=
hc.has_deriv_at.ccos.deriv
/-! #### `complex.sin` -/
lemma has_strict_deriv_at.csin (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (Ξ» x, complex.sin (f x)) (complex.cos (f x) * f') x :=
(complex.has_strict_deriv_at_sin (f x)).comp x hf
lemma has_deriv_at.csin (hf : has_deriv_at f f' x) :
has_deriv_at (Ξ» x, complex.sin (f x)) (complex.cos (f x) * f') x :=
(complex.has_deriv_at_sin (f x)).comp x hf
lemma has_deriv_within_at.csin (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (Ξ» x, complex.sin (f x)) (complex.cos (f x) * f') s x :=
(complex.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_csin (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
deriv_within (Ξ»x, complex.sin (f x)) s x = complex.cos (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.csin.deriv_within hxs
@[simp] lemma deriv_csin (hc : differentiable_at β f x) :
deriv (Ξ»x, complex.sin (f x)) x = complex.cos (f x) * (deriv f x) :=
hc.has_deriv_at.csin.deriv
/-! #### `complex.cosh` -/
lemma has_strict_deriv_at.ccosh (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (Ξ» x, complex.cosh (f x)) (complex.sinh (f x) * f') x :=
(complex.has_strict_deriv_at_cosh (f x)).comp x hf
lemma has_deriv_at.ccosh (hf : has_deriv_at f f' x) :
has_deriv_at (Ξ» x, complex.cosh (f x)) (complex.sinh (f x) * f') x :=
(complex.has_deriv_at_cosh (f x)).comp x hf
lemma has_deriv_within_at.ccosh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (Ξ» x, complex.cosh (f x)) (complex.sinh (f x) * f') s x :=
(complex.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_ccosh (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
deriv_within (Ξ»x, complex.cosh (f x)) s x = complex.sinh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.ccosh.deriv_within hxs
@[simp] lemma deriv_ccosh (hc : differentiable_at β f x) :
deriv (Ξ»x, complex.cosh (f x)) x = complex.sinh (f x) * (deriv f x) :=
hc.has_deriv_at.ccosh.deriv
/-! #### `complex.sinh` -/
lemma has_strict_deriv_at.csinh (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (Ξ» x, complex.sinh (f x)) (complex.cosh (f x) * f') x :=
(complex.has_strict_deriv_at_sinh (f x)).comp x hf
lemma has_deriv_at.csinh (hf : has_deriv_at f f' x) :
has_deriv_at (Ξ» x, complex.sinh (f x)) (complex.cosh (f x) * f') x :=
(complex.has_deriv_at_sinh (f x)).comp x hf
lemma has_deriv_within_at.csinh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (Ξ» x, complex.sinh (f x)) (complex.cosh (f x) * f') s x :=
(complex.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_csinh (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
deriv_within (Ξ»x, complex.sinh (f x)) s x = complex.cosh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.csinh.deriv_within hxs
@[simp] lemma deriv_csinh (hc : differentiable_at β f x) :
deriv (Ξ»x, complex.sinh (f x)) x = complex.cosh (f x) * (deriv f x) :=
hc.has_deriv_at.csinh.deriv
end
section
/-! ### Simp lemmas for derivatives of `Ξ» x, complex.cos (f x)` etc., `f : E β β` -/
variables {E : Type*} [normed_add_comm_group E] [normed_space β E] {f : E β β} {f' : E βL[β] β}
{x : E} {s : set E}
/-! #### `complex.cos` -/
lemma has_strict_fderiv_at.ccos (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (Ξ» x, complex.cos (f x)) (- complex.sin (f x) β’ f') x :=
(complex.has_strict_deriv_at_cos (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.ccos (hf : has_fderiv_at f f' x) :
has_fderiv_at (Ξ» x, complex.cos (f x)) (- complex.sin (f x) β’ f') x :=
(complex.has_deriv_at_cos (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.ccos (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (Ξ» x, complex.cos (f x)) (- complex.sin (f x) β’ f') s x :=
(complex.has_deriv_at_cos (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.ccos (hf : differentiable_within_at β f s x) :
differentiable_within_at β (Ξ» x, complex.cos (f x)) s x :=
hf.has_fderiv_within_at.ccos.differentiable_within_at
@[simp] lemma differentiable_at.ccos (hc : differentiable_at β f x) :
differentiable_at β (Ξ»x, complex.cos (f x)) x :=
hc.has_fderiv_at.ccos.differentiable_at
lemma differentiable_on.ccos (hc : differentiable_on β f s) :
differentiable_on β (Ξ»x, complex.cos (f x)) s :=
Ξ»x h, (hc x h).ccos
@[simp] lemma differentiable.ccos (hc : differentiable β f) :
differentiable β (Ξ»x, complex.cos (f x)) :=
Ξ»x, (hc x).ccos
lemma fderiv_within_ccos (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
fderiv_within β (Ξ»x, complex.cos (f x)) s x = - complex.sin (f x) β’ (fderiv_within β f s x) :=
hf.has_fderiv_within_at.ccos.fderiv_within hxs
@[simp] lemma fderiv_ccos (hc : differentiable_at β f x) :
fderiv β (Ξ»x, complex.cos (f x)) x = - complex.sin (f x) β’ (fderiv β f x) :=
hc.has_fderiv_at.ccos.fderiv
lemma cont_diff.ccos {n} (h : cont_diff β n f) :
cont_diff β n (Ξ» x, complex.cos (f x)) :=
complex.cont_diff_cos.comp h
lemma cont_diff_at.ccos {n} (hf : cont_diff_at β n f x) :
cont_diff_at β n (Ξ» x, complex.cos (f x)) x :=
complex.cont_diff_cos.cont_diff_at.comp x hf
lemma cont_diff_on.ccos {n} (hf : cont_diff_on β n f s) :
cont_diff_on β n (Ξ» x, complex.cos (f x)) s :=
complex.cont_diff_cos.comp_cont_diff_on hf
lemma cont_diff_within_at.ccos {n} (hf : cont_diff_within_at β n f s x) :
cont_diff_within_at β n (Ξ» x, complex.cos (f x)) s x :=
complex.cont_diff_cos.cont_diff_at.comp_cont_diff_within_at x hf
/-! #### `complex.sin` -/
lemma has_strict_fderiv_at.csin (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (Ξ» x, complex.sin (f x)) (complex.cos (f x) β’ f') x :=
(complex.has_strict_deriv_at_sin (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.csin (hf : has_fderiv_at f f' x) :
has_fderiv_at (Ξ» x, complex.sin (f x)) (complex.cos (f x) β’ f') x :=
(complex.has_deriv_at_sin (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.csin (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (Ξ» x, complex.sin (f x)) (complex.cos (f x) β’ f') s x :=
(complex.has_deriv_at_sin (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.csin (hf : differentiable_within_at β f s x) :
differentiable_within_at β (Ξ» x, complex.sin (f x)) s x :=
hf.has_fderiv_within_at.csin.differentiable_within_at
@[simp] lemma differentiable_at.csin (hc : differentiable_at β f x) :
differentiable_at β (Ξ»x, complex.sin (f x)) x :=
hc.has_fderiv_at.csin.differentiable_at
lemma differentiable_on.csin (hc : differentiable_on β f s) :
differentiable_on β (Ξ»x, complex.sin (f x)) s :=
Ξ»x h, (hc x h).csin
@[simp] lemma differentiable.csin (hc : differentiable β f) :
differentiable β (Ξ»x, complex.sin (f x)) :=
Ξ»x, (hc x).csin
lemma fderiv_within_csin (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
fderiv_within β (Ξ»x, complex.sin (f x)) s x = complex.cos (f x) β’ (fderiv_within β f s x) :=
hf.has_fderiv_within_at.csin.fderiv_within hxs
@[simp] lemma fderiv_csin (hc : differentiable_at β f x) :
fderiv β (Ξ»x, complex.sin (f x)) x = complex.cos (f x) β’ (fderiv β f x) :=
hc.has_fderiv_at.csin.fderiv
lemma cont_diff.csin {n} (h : cont_diff β n f) :
cont_diff β n (Ξ» x, complex.sin (f x)) :=
complex.cont_diff_sin.comp h
lemma cont_diff_at.csin {n} (hf : cont_diff_at β n f x) :
cont_diff_at β n (Ξ» x, complex.sin (f x)) x :=
complex.cont_diff_sin.cont_diff_at.comp x hf
lemma cont_diff_on.csin {n} (hf : cont_diff_on β n f s) :
cont_diff_on β n (Ξ» x, complex.sin (f x)) s :=
complex.cont_diff_sin.comp_cont_diff_on hf
lemma cont_diff_within_at.csin {n} (hf : cont_diff_within_at β n f s x) :
cont_diff_within_at β n (Ξ» x, complex.sin (f x)) s x :=
complex.cont_diff_sin.cont_diff_at.comp_cont_diff_within_at x hf
/-! #### `complex.cosh` -/
lemma has_strict_fderiv_at.ccosh (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (Ξ» x, complex.cosh (f x)) (complex.sinh (f x) β’ f') x :=
(complex.has_strict_deriv_at_cosh (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.ccosh (hf : has_fderiv_at f f' x) :
has_fderiv_at (Ξ» x, complex.cosh (f x)) (complex.sinh (f x) β’ f') x :=
(complex.has_deriv_at_cosh (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.ccosh (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (Ξ» x, complex.cosh (f x)) (complex.sinh (f x) β’ f') s x :=
(complex.has_deriv_at_cosh (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.ccosh (hf : differentiable_within_at β f s x) :
differentiable_within_at β (Ξ» x, complex.cosh (f x)) s x :=
hf.has_fderiv_within_at.ccosh.differentiable_within_at
@[simp] lemma differentiable_at.ccosh (hc : differentiable_at β f x) :
differentiable_at β (Ξ»x, complex.cosh (f x)) x :=
hc.has_fderiv_at.ccosh.differentiable_at
lemma differentiable_on.ccosh (hc : differentiable_on β f s) :
differentiable_on β (Ξ»x, complex.cosh (f x)) s :=
Ξ»x h, (hc x h).ccosh
@[simp] lemma differentiable.ccosh (hc : differentiable β f) :
differentiable β (Ξ»x, complex.cosh (f x)) :=
Ξ»x, (hc x).ccosh
lemma fderiv_within_ccosh (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
fderiv_within β (Ξ»x, complex.cosh (f x)) s x = complex.sinh (f x) β’ (fderiv_within β f s x) :=
hf.has_fderiv_within_at.ccosh.fderiv_within hxs
@[simp] lemma fderiv_ccosh (hc : differentiable_at β f x) :
fderiv β (Ξ»x, complex.cosh (f x)) x = complex.sinh (f x) β’ (fderiv β f x) :=
hc.has_fderiv_at.ccosh.fderiv
lemma cont_diff.ccosh {n} (h : cont_diff β n f) :
cont_diff β n (Ξ» x, complex.cosh (f x)) :=
complex.cont_diff_cosh.comp h
lemma cont_diff_at.ccosh {n} (hf : cont_diff_at β n f x) :
cont_diff_at β n (Ξ» x, complex.cosh (f x)) x :=
complex.cont_diff_cosh.cont_diff_at.comp x hf
lemma cont_diff_on.ccosh {n} (hf : cont_diff_on β n f s) :
cont_diff_on β n (Ξ» x, complex.cosh (f x)) s :=
complex.cont_diff_cosh.comp_cont_diff_on hf
lemma cont_diff_within_at.ccosh {n} (hf : cont_diff_within_at β n f s x) :
cont_diff_within_at β n (Ξ» x, complex.cosh (f x)) s x :=
complex.cont_diff_cosh.cont_diff_at.comp_cont_diff_within_at x hf
/-! #### `complex.sinh` -/
lemma has_strict_fderiv_at.csinh (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (Ξ» x, complex.sinh (f x)) (complex.cosh (f x) β’ f') x :=
(complex.has_strict_deriv_at_sinh (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.csinh (hf : has_fderiv_at f f' x) :
has_fderiv_at (Ξ» x, complex.sinh (f x)) (complex.cosh (f x) β’ f') x :=
(complex.has_deriv_at_sinh (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.csinh (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (Ξ» x, complex.sinh (f x)) (complex.cosh (f x) β’ f') s x :=
(complex.has_deriv_at_sinh (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.csinh (hf : differentiable_within_at β f s x) :
differentiable_within_at β (Ξ» x, complex.sinh (f x)) s x :=
hf.has_fderiv_within_at.csinh.differentiable_within_at
@[simp] lemma differentiable_at.csinh (hc : differentiable_at β f x) :
differentiable_at β (Ξ»x, complex.sinh (f x)) x :=
hc.has_fderiv_at.csinh.differentiable_at
lemma differentiable_on.csinh (hc : differentiable_on β f s) :
differentiable_on β (Ξ»x, complex.sinh (f x)) s :=
Ξ»x h, (hc x h).csinh
@[simp] lemma differentiable.csinh (hc : differentiable β f) :
differentiable β (Ξ»x, complex.sinh (f x)) :=
Ξ»x, (hc x).csinh
lemma fderiv_within_csinh (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
fderiv_within β (Ξ»x, complex.sinh (f x)) s x = complex.cosh (f x) β’ (fderiv_within β f s x) :=
hf.has_fderiv_within_at.csinh.fderiv_within hxs
@[simp] lemma fderiv_csinh (hc : differentiable_at β f x) :
fderiv β (Ξ»x, complex.sinh (f x)) x = complex.cosh (f x) β’ (fderiv β f x) :=
hc.has_fderiv_at.csinh.fderiv
lemma cont_diff.csinh {n} (h : cont_diff β n f) :
cont_diff β n (Ξ» x, complex.sinh (f x)) :=
complex.cont_diff_sinh.comp h
lemma cont_diff_at.csinh {n} (hf : cont_diff_at β n f x) :
cont_diff_at β n (Ξ» x, complex.sinh (f x)) x :=
complex.cont_diff_sinh.cont_diff_at.comp x hf
lemma cont_diff_on.csinh {n} (hf : cont_diff_on β n f s) :
cont_diff_on β n (Ξ» x, complex.sinh (f x)) s :=
complex.cont_diff_sinh.comp_cont_diff_on hf
lemma cont_diff_within_at.csinh {n} (hf : cont_diff_within_at β n f s x) :
cont_diff_within_at β n (Ξ» x, complex.sinh (f x)) s x :=
complex.cont_diff_sinh.cont_diff_at.comp_cont_diff_within_at x hf
end
namespace real
variables {x y z : β}
lemma has_strict_deriv_at_sin (x : β) : has_strict_deriv_at sin (cos x) x :=
(complex.has_strict_deriv_at_sin x).real_of_complex
lemma has_deriv_at_sin (x : β) : has_deriv_at sin (cos x) x :=
(has_strict_deriv_at_sin x).has_deriv_at
lemma cont_diff_sin {n} : cont_diff β n sin :=
complex.cont_diff_sin.real_of_complex
lemma differentiable_sin : differentiable β sin :=
Ξ»x, (has_deriv_at_sin x).differentiable_at
lemma differentiable_at_sin : differentiable_at β sin x :=
differentiable_sin x
@[simp] lemma deriv_sin : deriv sin = cos :=
funext $ Ξ» x, (has_deriv_at_sin x).deriv
lemma has_strict_deriv_at_cos (x : β) : has_strict_deriv_at cos (-sin x) x :=
(complex.has_strict_deriv_at_cos x).real_of_complex
lemma has_deriv_at_cos (x : β) : has_deriv_at cos (-sin x) x :=
(complex.has_deriv_at_cos x).real_of_complex
lemma cont_diff_cos {n} : cont_diff β n cos :=
complex.cont_diff_cos.real_of_complex
lemma differentiable_cos : differentiable β cos :=
Ξ»x, (has_deriv_at_cos x).differentiable_at
lemma differentiable_at_cos : differentiable_at β cos x :=
differentiable_cos x
lemma deriv_cos : deriv cos x = - sin x :=
(has_deriv_at_cos x).deriv
@[simp] lemma deriv_cos' : deriv cos = (Ξ» x, - sin x) :=
funext $ Ξ» _, deriv_cos
lemma has_strict_deriv_at_sinh (x : β) : has_strict_deriv_at sinh (cosh x) x :=
(complex.has_strict_deriv_at_sinh x).real_of_complex
lemma has_deriv_at_sinh (x : β) : has_deriv_at sinh (cosh x) x :=
(complex.has_deriv_at_sinh x).real_of_complex
lemma cont_diff_sinh {n} : cont_diff β n sinh :=
complex.cont_diff_sinh.real_of_complex
lemma differentiable_sinh : differentiable β sinh :=
Ξ»x, (has_deriv_at_sinh x).differentiable_at
lemma differentiable_at_sinh : differentiable_at β sinh x :=
differentiable_sinh x
@[simp] lemma deriv_sinh : deriv sinh = cosh :=
funext $ Ξ» x, (has_deriv_at_sinh x).deriv
lemma has_strict_deriv_at_cosh (x : β) : has_strict_deriv_at cosh (sinh x) x :=
(complex.has_strict_deriv_at_cosh x).real_of_complex
lemma has_deriv_at_cosh (x : β) : has_deriv_at cosh (sinh x) x :=
(complex.has_deriv_at_cosh x).real_of_complex
lemma cont_diff_cosh {n} : cont_diff β n cosh :=
complex.cont_diff_cosh.real_of_complex
lemma differentiable_cosh : differentiable β cosh :=
Ξ»x, (has_deriv_at_cosh x).differentiable_at
lemma differentiable_at_cosh : differentiable_at β cosh x :=
differentiable_cosh x
@[simp] lemma deriv_cosh : deriv cosh = sinh :=
funext $ Ξ» x, (has_deriv_at_cosh x).deriv
/-- `sinh` is strictly monotone. -/
lemma sinh_strict_mono : strict_mono sinh :=
strict_mono_of_deriv_pos $ by { rw real.deriv_sinh, exact cosh_pos }
/-- `sinh` is injective, `β a b, sinh a = sinh b β a = b`. -/
lemma sinh_injective : function.injective sinh := sinh_strict_mono.injective
@[simp] lemma sinh_inj : sinh x = sinh y β x = y := sinh_injective.eq_iff
@[simp] lemma sinh_le_sinh : sinh x β€ sinh y β x β€ y := sinh_strict_mono.le_iff_le
@[simp] lemma sinh_lt_sinh : sinh x < sinh y β x < y := sinh_strict_mono.lt_iff_lt
@[simp] lemma sinh_pos_iff : 0 < sinh x β 0 < x :=
by simpa only [sinh_zero] using @sinh_lt_sinh 0 x
@[simp] lemma sinh_nonpos_iff : sinh x β€ 0 β x β€ 0 :=
by simpa only [sinh_zero] using @sinh_le_sinh x 0
@[simp] lemma sinh_neg_iff : sinh x < 0 β x < 0 :=
by simpa only [sinh_zero] using @sinh_lt_sinh x 0
@[simp] lemma sinh_nonneg_iff : 0 β€ sinh x β 0 β€ x :=
by simpa only [sinh_zero] using @sinh_le_sinh 0 x
lemma cosh_strict_mono_on : strict_mono_on cosh (Ici 0) :=
(convex_Ici _).strict_mono_on_of_deriv_pos continuous_cosh.continuous_on $ Ξ» x hx,
by { rw [interior_Ici, mem_Ioi] at hx, rwa [deriv_cosh, sinh_pos_iff] }
@[simp] lemma cosh_le_cosh : cosh x β€ cosh y β |x| β€ |y| :=
cosh_abs x βΈ cosh_abs y βΈ cosh_strict_mono_on.le_iff_le (_root_.abs_nonneg x) (_root_.abs_nonneg y)
@[simp] lemma cosh_lt_cosh : cosh x < cosh y β |x| < |y| :=
lt_iff_lt_of_le_iff_le cosh_le_cosh
@[simp] lemma one_le_cosh (x : β) : 1 β€ cosh x :=
cosh_zero βΈ cosh_le_cosh.2 (by simp only [_root_.abs_zero, _root_.abs_nonneg])
@[simp] lemma one_lt_cosh : 1 < cosh x β x β 0 :=
cosh_zero βΈ cosh_lt_cosh.trans (by simp only [_root_.abs_zero, abs_pos])
lemma sinh_sub_id_strict_mono : strict_mono (Ξ» x, sinh x - x) :=
begin
refine strict_mono_of_odd_strict_mono_on_nonneg (Ξ» x, by simp) _,
refine (convex_Ici _).strict_mono_on_of_deriv_pos _ (Ξ» x hx, _),
{ exact (continuous_sinh.sub continuous_id).continuous_on },
{ rw [interior_Ici, mem_Ioi] at hx,
rw [deriv_sub, deriv_sinh, deriv_id'', sub_pos, one_lt_cosh],
exacts [hx.ne', differentiable_at_sinh, differentiable_at_id] }
end
@[simp] lemma self_le_sinh_iff : x β€ sinh x β 0 β€ x :=
calc x β€ sinh x β sinh 0 - 0 β€ sinh x - x : by simp
... β 0 β€ x : sinh_sub_id_strict_mono.le_iff_le
@[simp] lemma sinh_le_self_iff : sinh x β€ x β x β€ 0 :=
calc sinh x β€ x β sinh x - x β€ sinh 0 - 0 : by simp
... β x β€ 0 : sinh_sub_id_strict_mono.le_iff_le
@[simp] lemma self_lt_sinh_iff : x < sinh x β 0 < x :=
lt_iff_lt_of_le_iff_le sinh_le_self_iff
@[simp] lemma sinh_lt_self_iff : sinh x < x β x < 0 :=
lt_iff_lt_of_le_iff_le self_le_sinh_iff
end real
section
/-! ### Simp lemmas for derivatives of `Ξ» x, real.cos (f x)` etc., `f : β β β` -/
variables {f : β β β} {f' x : β} {s : set β}
/-! #### `real.cos` -/
lemma has_strict_deriv_at.cos (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (Ξ» x, real.cos (f x)) (- real.sin (f x) * f') x :=
(real.has_strict_deriv_at_cos (f x)).comp x hf
lemma has_deriv_at.cos (hf : has_deriv_at f f' x) :
has_deriv_at (Ξ» x, real.cos (f x)) (- real.sin (f x) * f') x :=
(real.has_deriv_at_cos (f x)).comp x hf
lemma has_deriv_within_at.cos (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (Ξ» x, real.cos (f x)) (- real.sin (f x) * f') s x :=
(real.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_cos (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
deriv_within (Ξ»x, real.cos (f x)) s x = - real.sin (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.cos.deriv_within hxs
@[simp] lemma deriv_cos (hc : differentiable_at β f x) :
deriv (Ξ»x, real.cos (f x)) x = - real.sin (f x) * (deriv f x) :=
hc.has_deriv_at.cos.deriv
/-! #### `real.sin` -/
lemma has_strict_deriv_at.sin (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (Ξ» x, real.sin (f x)) (real.cos (f x) * f') x :=
(real.has_strict_deriv_at_sin (f x)).comp x hf
lemma has_deriv_at.sin (hf : has_deriv_at f f' x) :
has_deriv_at (Ξ» x, real.sin (f x)) (real.cos (f x) * f') x :=
(real.has_deriv_at_sin (f x)).comp x hf
lemma has_deriv_within_at.sin (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (Ξ» x, real.sin (f x)) (real.cos (f x) * f') s x :=
(real.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_sin (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
deriv_within (Ξ»x, real.sin (f x)) s x = real.cos (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.sin.deriv_within hxs
@[simp] lemma deriv_sin (hc : differentiable_at β f x) :
deriv (Ξ»x, real.sin (f x)) x = real.cos (f x) * (deriv f x) :=
hc.has_deriv_at.sin.deriv
/-! #### `real.cosh` -/
lemma has_strict_deriv_at.cosh (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (Ξ» x, real.cosh (f x)) (real.sinh (f x) * f') x :=
(real.has_strict_deriv_at_cosh (f x)).comp x hf
lemma has_deriv_at.cosh (hf : has_deriv_at f f' x) :
has_deriv_at (Ξ» x, real.cosh (f x)) (real.sinh (f x) * f') x :=
(real.has_deriv_at_cosh (f x)).comp x hf
lemma has_deriv_within_at.cosh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (Ξ» x, real.cosh (f x)) (real.sinh (f x) * f') s x :=
(real.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_cosh (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
deriv_within (Ξ»x, real.cosh (f x)) s x = real.sinh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.cosh.deriv_within hxs
@[simp] lemma deriv_cosh (hc : differentiable_at β f x) :
deriv (Ξ»x, real.cosh (f x)) x = real.sinh (f x) * (deriv f x) :=
hc.has_deriv_at.cosh.deriv
/-! #### `real.sinh` -/
lemma has_strict_deriv_at.sinh (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (Ξ» x, real.sinh (f x)) (real.cosh (f x) * f') x :=
(real.has_strict_deriv_at_sinh (f x)).comp x hf
lemma has_deriv_at.sinh (hf : has_deriv_at f f' x) :
has_deriv_at (Ξ» x, real.sinh (f x)) (real.cosh (f x) * f') x :=
(real.has_deriv_at_sinh (f x)).comp x hf
lemma has_deriv_within_at.sinh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (Ξ» x, real.sinh (f x)) (real.cosh (f x) * f') s x :=
(real.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_sinh (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
deriv_within (Ξ»x, real.sinh (f x)) s x = real.cosh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.sinh.deriv_within hxs
@[simp] lemma deriv_sinh (hc : differentiable_at β f x) :
deriv (Ξ»x, real.sinh (f x)) x = real.cosh (f x) * (deriv f x) :=
hc.has_deriv_at.sinh.deriv
end
section
/-! ### Simp lemmas for derivatives of `Ξ» x, real.cos (f x)` etc., `f : E β β` -/
variables {E : Type*} [normed_add_comm_group E] [normed_space β E] {f : E β β} {f' : E βL[β] β}
{x : E} {s : set E}
/-! #### `real.cos` -/
lemma has_strict_fderiv_at.cos (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (Ξ» x, real.cos (f x)) (- real.sin (f x) β’ f') x :=
(real.has_strict_deriv_at_cos (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.cos (hf : has_fderiv_at f f' x) :
has_fderiv_at (Ξ» x, real.cos (f x)) (- real.sin (f x) β’ f') x :=
(real.has_deriv_at_cos (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.cos (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (Ξ» x, real.cos (f x)) (- real.sin (f x) β’ f') s x :=
(real.has_deriv_at_cos (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.cos (hf : differentiable_within_at β f s x) :
differentiable_within_at β (Ξ» x, real.cos (f x)) s x :=
hf.has_fderiv_within_at.cos.differentiable_within_at
@[simp] lemma differentiable_at.cos (hc : differentiable_at β f x) :
differentiable_at β (Ξ»x, real.cos (f x)) x :=
hc.has_fderiv_at.cos.differentiable_at
lemma differentiable_on.cos (hc : differentiable_on β f s) :
differentiable_on β (Ξ»x, real.cos (f x)) s :=
Ξ»x h, (hc x h).cos
@[simp] lemma differentiable.cos (hc : differentiable β f) :
differentiable β (Ξ»x, real.cos (f x)) :=
Ξ»x, (hc x).cos
lemma fderiv_within_cos (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
fderiv_within β (Ξ»x, real.cos (f x)) s x = - real.sin (f x) β’ (fderiv_within β f s x) :=
hf.has_fderiv_within_at.cos.fderiv_within hxs
@[simp] lemma fderiv_cos (hc : differentiable_at β f x) :
fderiv β (Ξ»x, real.cos (f x)) x = - real.sin (f x) β’ (fderiv β f x) :=
hc.has_fderiv_at.cos.fderiv
lemma cont_diff.cos {n} (h : cont_diff β n f) :
cont_diff β n (Ξ» x, real.cos (f x)) :=
real.cont_diff_cos.comp h
lemma cont_diff_at.cos {n} (hf : cont_diff_at β n f x) :
cont_diff_at β n (Ξ» x, real.cos (f x)) x :=
real.cont_diff_cos.cont_diff_at.comp x hf
lemma cont_diff_on.cos {n} (hf : cont_diff_on β n f s) :
cont_diff_on β n (Ξ» x, real.cos (f x)) s :=
real.cont_diff_cos.comp_cont_diff_on hf
lemma cont_diff_within_at.cos {n} (hf : cont_diff_within_at β n f s x) :
cont_diff_within_at β n (Ξ» x, real.cos (f x)) s x :=
real.cont_diff_cos.cont_diff_at.comp_cont_diff_within_at x hf
/-! #### `real.sin` -/
lemma has_strict_fderiv_at.sin (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (Ξ» x, real.sin (f x)) (real.cos (f x) β’ f') x :=
(real.has_strict_deriv_at_sin (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.sin (hf : has_fderiv_at f f' x) :
has_fderiv_at (Ξ» x, real.sin (f x)) (real.cos (f x) β’ f') x :=
(real.has_deriv_at_sin (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.sin (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (Ξ» x, real.sin (f x)) (real.cos (f x) β’ f') s x :=
(real.has_deriv_at_sin (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.sin (hf : differentiable_within_at β f s x) :
differentiable_within_at β (Ξ» x, real.sin (f x)) s x :=
hf.has_fderiv_within_at.sin.differentiable_within_at
@[simp] lemma differentiable_at.sin (hc : differentiable_at β f x) :
differentiable_at β (Ξ»x, real.sin (f x)) x :=
hc.has_fderiv_at.sin.differentiable_at
lemma differentiable_on.sin (hc : differentiable_on β f s) :
differentiable_on β (Ξ»x, real.sin (f x)) s :=
Ξ»x h, (hc x h).sin
@[simp] lemma differentiable.sin (hc : differentiable β f) :
differentiable β (Ξ»x, real.sin (f x)) :=
Ξ»x, (hc x).sin
lemma fderiv_within_sin (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
fderiv_within β (Ξ»x, real.sin (f x)) s x = real.cos (f x) β’ (fderiv_within β f s x) :=
hf.has_fderiv_within_at.sin.fderiv_within hxs
@[simp] lemma fderiv_sin (hc : differentiable_at β f x) :
fderiv β (Ξ»x, real.sin (f x)) x = real.cos (f x) β’ (fderiv β f x) :=
hc.has_fderiv_at.sin.fderiv
lemma cont_diff.sin {n} (h : cont_diff β n f) :
cont_diff β n (Ξ» x, real.sin (f x)) :=
real.cont_diff_sin.comp h
lemma cont_diff_at.sin {n} (hf : cont_diff_at β n f x) :
cont_diff_at β n (Ξ» x, real.sin (f x)) x :=
real.cont_diff_sin.cont_diff_at.comp x hf
lemma cont_diff_on.sin {n} (hf : cont_diff_on β n f s) :
cont_diff_on β n (Ξ» x, real.sin (f x)) s :=
real.cont_diff_sin.comp_cont_diff_on hf
lemma cont_diff_within_at.sin {n} (hf : cont_diff_within_at β n f s x) :
cont_diff_within_at β n (Ξ» x, real.sin (f x)) s x :=
real.cont_diff_sin.cont_diff_at.comp_cont_diff_within_at x hf
/-! #### `real.cosh` -/
lemma has_strict_fderiv_at.cosh (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (Ξ» x, real.cosh (f x)) (real.sinh (f x) β’ f') x :=
(real.has_strict_deriv_at_cosh (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.cosh (hf : has_fderiv_at f f' x) :
has_fderiv_at (Ξ» x, real.cosh (f x)) (real.sinh (f x) β’ f') x :=
(real.has_deriv_at_cosh (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.cosh (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (Ξ» x, real.cosh (f x)) (real.sinh (f x) β’ f') s x :=
(real.has_deriv_at_cosh (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.cosh (hf : differentiable_within_at β f s x) :
differentiable_within_at β (Ξ» x, real.cosh (f x)) s x :=
hf.has_fderiv_within_at.cosh.differentiable_within_at
@[simp] lemma differentiable_at.cosh (hc : differentiable_at β f x) :
differentiable_at β (Ξ»x, real.cosh (f x)) x :=
hc.has_fderiv_at.cosh.differentiable_at
lemma differentiable_on.cosh (hc : differentiable_on β f s) :
differentiable_on β (Ξ»x, real.cosh (f x)) s :=
Ξ»x h, (hc x h).cosh
@[simp] lemma differentiable.cosh (hc : differentiable β f) :
differentiable β (Ξ»x, real.cosh (f x)) :=
Ξ»x, (hc x).cosh
lemma fderiv_within_cosh (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
fderiv_within β (Ξ»x, real.cosh (f x)) s x = real.sinh (f x) β’ (fderiv_within β f s x) :=
hf.has_fderiv_within_at.cosh.fderiv_within hxs
@[simp] lemma fderiv_cosh (hc : differentiable_at β f x) :
fderiv β (Ξ»x, real.cosh (f x)) x = real.sinh (f x) β’ (fderiv β f x) :=
hc.has_fderiv_at.cosh.fderiv
lemma cont_diff.cosh {n} (h : cont_diff β n f) :
cont_diff β n (Ξ» x, real.cosh (f x)) :=
real.cont_diff_cosh.comp h
lemma cont_diff_at.cosh {n} (hf : cont_diff_at β n f x) :
cont_diff_at β n (Ξ» x, real.cosh (f x)) x :=
real.cont_diff_cosh.cont_diff_at.comp x hf
lemma cont_diff_on.cosh {n} (hf : cont_diff_on β n f s) :
cont_diff_on β n (Ξ» x, real.cosh (f x)) s :=
real.cont_diff_cosh.comp_cont_diff_on hf
lemma cont_diff_within_at.cosh {n} (hf : cont_diff_within_at β n f s x) :
cont_diff_within_at β n (Ξ» x, real.cosh (f x)) s x :=
real.cont_diff_cosh.cont_diff_at.comp_cont_diff_within_at x hf
/-! #### `real.sinh` -/
lemma has_strict_fderiv_at.sinh (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (Ξ» x, real.sinh (f x)) (real.cosh (f x) β’ f') x :=
(real.has_strict_deriv_at_sinh (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.sinh (hf : has_fderiv_at f f' x) :
has_fderiv_at (Ξ» x, real.sinh (f x)) (real.cosh (f x) β’ f') x :=
(real.has_deriv_at_sinh (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.sinh (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (Ξ» x, real.sinh (f x)) (real.cosh (f x) β’ f') s x :=
(real.has_deriv_at_sinh (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.sinh (hf : differentiable_within_at β f s x) :
differentiable_within_at β (Ξ» x, real.sinh (f x)) s x :=
hf.has_fderiv_within_at.sinh.differentiable_within_at
@[simp] lemma differentiable_at.sinh (hc : differentiable_at β f x) :
differentiable_at β (Ξ»x, real.sinh (f x)) x :=
hc.has_fderiv_at.sinh.differentiable_at
lemma differentiable_on.sinh (hc : differentiable_on β f s) :
differentiable_on β (Ξ»x, real.sinh (f x)) s :=
Ξ»x h, (hc x h).sinh
@[simp] lemma differentiable.sinh (hc : differentiable β f) :
differentiable β (Ξ»x, real.sinh (f x)) :=
Ξ»x, (hc x).sinh
lemma fderiv_within_sinh (hf : differentiable_within_at β f s x)
(hxs : unique_diff_within_at β s x) :
fderiv_within β (Ξ»x, real.sinh (f x)) s x = real.cosh (f x) β’ (fderiv_within β f s x) :=
hf.has_fderiv_within_at.sinh.fderiv_within hxs
@[simp] lemma fderiv_sinh (hc : differentiable_at β f x) :
fderiv β (Ξ»x, real.sinh (f x)) x = real.cosh (f x) β’ (fderiv β f x) :=
hc.has_fderiv_at.sinh.fderiv
lemma cont_diff.sinh {n} (h : cont_diff β n f) :
cont_diff β n (Ξ» x, real.sinh (f x)) :=
real.cont_diff_sinh.comp h
lemma cont_diff_at.sinh {n} (hf : cont_diff_at β n f x) :
cont_diff_at β n (Ξ» x, real.sinh (f x)) x :=
real.cont_diff_sinh.cont_diff_at.comp x hf
lemma cont_diff_on.sinh {n} (hf : cont_diff_on β n f s) :
cont_diff_on β n (Ξ» x, real.sinh (f x)) s :=
real.cont_diff_sinh.comp_cont_diff_on hf
lemma cont_diff_within_at.sinh {n} (hf : cont_diff_within_at β n f s x) :
cont_diff_within_at β n (Ξ» x, real.sinh (f x)) s x :=
real.cont_diff_sinh.cont_diff_at.comp_cont_diff_within_at x hf
end
|
e6a8e6647461ccd5605809e4eed3c03fe25678e4 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/analysis/normed/group/basic.lean | 7b25f1a4fc0029f5075d2cd68c631b6f3ee56c99 | [
"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 | 83,217 | lean | /-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Johannes HΓΆlzl, YaΓ«l Dillies
-/
import analysis.normed.group.seminorm
import order.liminf_limsup
import topology.algebra.uniform_group
import topology.instances.rat
import topology.metric_space.algebra
import topology.metric_space.isometric_smul
import topology.sequences
/-!
# Normed (semi)groups
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In this file we define 10 classes:
* `has_norm`, `has_nnnorm`: auxiliary classes endowing a type `Ξ±` with a function `norm : Ξ± β β`
(notation: `βxβ`) and `nnnorm : Ξ± β ββ₯0` (notation: `βxββ`), respectively;
* `seminormed_..._group`: A seminormed (additive) (commutative) group is an (additive) (commutative)
group with a norm and a compatible pseudometric space structure:
`β x y, dist x y = βx / yβ` or `β x y, dist x y = βx - yβ`, depending on the group operation.
* `normed_..._group`: A normed (additive) (commutative) group is an (additive) (commutative) group
with a norm and a compatible metric space structure.
We also prove basic properties of (semi)normed groups and provide some instances.
## Notes
The current convention `dist x y = βx - yβ` means that the distance is invariant under right
addition, but actions in mathlib are usually from the left. This means we might want to change it to
`dist x y = β-x + yβ`.
The normed group hierarchy would lend itself well to a mixin design (that is, having
`seminormed_group` and `seminormed_add_group` not extend `group` and `add_group`), but we choose not
to for performance concerns.
## Tags
normed group
-/
variables {π π Ξ± ΞΉ ΞΊ E F G : Type*}
open filter function metric
open_locale big_operators ennreal filter nnreal uniformity pointwise topology
/-- Auxiliary class, endowing a type `E` with a function `norm : E β β` with notation `βxβ`. This
class is designed to be extended in more interesting classes specifying the properties of the norm.
-/
@[notation_class] class has_norm (E : Type*) := (norm : E β β)
/-- Auxiliary class, endowing a type `Ξ±` with a function `nnnorm : Ξ± β ββ₯0` with notation `βxββ`. -/
@[notation_class] class has_nnnorm (E : Type*) := (nnnorm : E β ββ₯0)
export has_norm (norm)
export has_nnnorm (nnnorm)
notation `β` e `β` := norm e
notation `β` e `ββ` := nnnorm e
/-- A seminormed group is an additive group endowed with a norm for which `dist x y = βx - yβ`
defines a pseudometric space structure. -/
class seminormed_add_group (E : Type*) extends has_norm E, add_group E, pseudo_metric_space E :=
(dist := Ξ» x y, βx - yβ)
(dist_eq : β x y, dist x y = βx - yβ . obviously)
/-- A seminormed group is a group endowed with a norm for which `dist x y = βx / yβ` defines a
pseudometric space structure. -/
@[to_additive]
class seminormed_group (E : Type*) extends has_norm E, group E, pseudo_metric_space E :=
(dist := Ξ» x y, βx / yβ)
(dist_eq : β x y, dist x y = βx / yβ . obviously)
/-- A normed group is an additive group endowed with a norm for which `dist x y = βx - yβ` defines a
metric space structure. -/
class normed_add_group (E : Type*) extends has_norm E, add_group E, metric_space E :=
(dist := Ξ» x y, βx - yβ)
(dist_eq : β x y, dist x y = βx - yβ . obviously)
/-- A normed group is a group endowed with a norm for which `dist x y = βx / yβ` defines a metric
space structure. -/
@[to_additive]
class normed_group (E : Type*) extends has_norm E, group E, metric_space E :=
(dist := Ξ» x y, βx / yβ)
(dist_eq : β x y, dist x y = βx / yβ . obviously)
/-- A seminormed group is an additive group endowed with a norm for which `dist x y = βx - yβ`
defines a pseudometric space structure. -/
class seminormed_add_comm_group (E : Type*)
extends has_norm E, add_comm_group E, pseudo_metric_space E :=
(dist := Ξ» x y, βx - yβ)
(dist_eq : β x y, dist x y = βx - yβ . obviously)
/-- A seminormed group is a group endowed with a norm for which `dist x y = βx / yβ`
defines a pseudometric space structure. -/
@[to_additive]
class seminormed_comm_group (E : Type*)
extends has_norm E, comm_group E, pseudo_metric_space E :=
(dist := Ξ» x y, βx / yβ)
(dist_eq : β x y, dist x y = βx / yβ . obviously)
/-- A normed group is an additive group endowed with a norm for which `dist x y = βx - yβ` defines a
metric space structure. -/
class normed_add_comm_group (E : Type*) extends has_norm E, add_comm_group E, metric_space E :=
(dist := Ξ» x y, βx - yβ)
(dist_eq : β x y, dist x y = βx - yβ . obviously)
/-- A normed group is a group endowed with a norm for which `dist x y = βx / yβ` defines a metric
space structure. -/
@[to_additive]
class normed_comm_group (E : Type*) extends has_norm E, comm_group E, metric_space E :=
(dist := Ξ» x y, βx / yβ)
(dist_eq : β x y, dist x y = βx / yβ . obviously)
@[priority 100, to_additive] -- See note [lower instance priority]
instance normed_group.to_seminormed_group [normed_group E] : seminormed_group E :=
{ ..βΉnormed_group EβΊ }
@[priority 100, to_additive] -- See note [lower instance priority]
instance normed_comm_group.to_seminormed_comm_group [normed_comm_group E] :
seminormed_comm_group E :=
{ ..βΉnormed_comm_group EβΊ }
@[priority 100, to_additive] -- See note [lower instance priority]
instance seminormed_comm_group.to_seminormed_group [seminormed_comm_group E] : seminormed_group E :=
{ ..βΉseminormed_comm_group EβΊ }
@[priority 100, to_additive] -- See note [lower instance priority]
instance normed_comm_group.to_normed_group [normed_comm_group E] : normed_group E :=
{ ..βΉnormed_comm_group EβΊ }
/-- Construct a `normed_group` from a `seminormed_group` satisfying `β x, βxβ = 0 β x = 1`. This
avoids having to go back to the `(pseudo_)metric_space` level when declaring a `normed_group`
instance as a special case of a more general `seminormed_group` instance. -/
@[to_additive "Construct a `normed_add_group` from a `seminormed_add_group` satisfying
`β x, βxβ = 0 β x = 0`. This avoids having to go back to the `(pseudo_)metric_space` level when
declaring a `normed_add_group` instance as a special case of a more general `seminormed_add_group`
instance.", reducible] -- See note [reducible non-instances]
def normed_group.of_separation [seminormed_group E] (h : β x : E, βxβ = 0 β x = 1) :
normed_group E :=
{ to_metric_space :=
{ eq_of_dist_eq_zero := Ξ» x y hxy, div_eq_one.1 $ h _ $ by rwa ββΉseminormed_group EβΊ.dist_eq },
..βΉseminormed_group EβΊ }
/-- Construct a `normed_comm_group` from a `seminormed_comm_group` satisfying
`β x, βxβ = 0 β x = 1`. This avoids having to go back to the `(pseudo_)metric_space` level when
declaring a `normed_comm_group` instance as a special case of a more general `seminormed_comm_group`
instance. -/
@[to_additive "Construct a `normed_add_comm_group` from a `seminormed_add_comm_group` satisfying
`β x, βxβ = 0 β x = 0`. This avoids having to go back to the `(pseudo_)metric_space` level when
declaring a `normed_add_comm_group` instance as a special case of a more general
`seminormed_add_comm_group` instance.", reducible] -- See note [reducible non-instances]
def normed_comm_group.of_separation [seminormed_comm_group E] (h : β x : E, βxβ = 0 β x = 1) :
normed_comm_group E :=
{ ..βΉseminormed_comm_group EβΊ, ..normed_group.of_separation h }
/-- Construct a seminormed group from a multiplication-invariant distance. -/
@[to_additive "Construct a seminormed group from a translation-invariant distance."]
def seminormed_group.of_mul_dist [has_norm E] [group E] [pseudo_metric_space E]
(hβ : β x : E, βxβ = dist x 1) (hβ : β x y z : E, dist x y β€ dist (x * z) (y * z)) :
seminormed_group E :=
{ dist_eq := Ξ» x y, begin
rw hβ, apply le_antisymm,
{ simpa only [div_eq_mul_inv, β mul_right_inv y] using hβ _ _ _ },
{ simpa only [div_mul_cancel', one_mul] using hβ (x/y) 1 y }
end }
/-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/
@[to_additive "Construct a seminormed group from a translation-invariant pseudodistance."]
def seminormed_group.of_mul_dist' [has_norm E] [group E] [pseudo_metric_space E]
(hβ : β x : E, βxβ = dist x 1) (hβ : β x y z : E, dist (x * z) (y * z) β€ dist x y) :
seminormed_group E :=
{ dist_eq := Ξ» x y, begin
rw hβ, apply le_antisymm,
{ simpa only [div_mul_cancel', one_mul] using hβ (x/y) 1 y },
{ simpa only [div_eq_mul_inv, β mul_right_inv y] using hβ _ _ _ }
end }
/-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/
@[to_additive "Construct a seminormed group from a translation-invariant pseudodistance."]
def seminormed_comm_group.of_mul_dist [has_norm E] [comm_group E] [pseudo_metric_space E]
(hβ : β x : E, βxβ = dist x 1) (hβ : β x y z : E, dist x y β€ dist (x * z) (y * z)) :
seminormed_comm_group E :=
{ ..seminormed_group.of_mul_dist hβ hβ }
/-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/
@[to_additive "Construct a seminormed group from a translation-invariant pseudodistance."]
def seminormed_comm_group.of_mul_dist' [has_norm E] [comm_group E] [pseudo_metric_space E]
(hβ : β x : E, βxβ = dist x 1) (hβ : β x y z : E, dist (x * z) (y * z) β€ dist x y) :
seminormed_comm_group E :=
{ ..seminormed_group.of_mul_dist' hβ hβ }
/-- Construct a normed group from a multiplication-invariant distance. -/
@[to_additive "Construct a normed group from a translation-invariant distance."]
def normed_group.of_mul_dist [has_norm E] [group E] [metric_space E]
(hβ : β x : E, βxβ = dist x 1) (hβ : β x y z : E, dist x y β€ dist (x * z) (y * z)) :
normed_group E :=
{ ..seminormed_group.of_mul_dist hβ hβ }
/-- Construct a normed group from a multiplication-invariant pseudodistance. -/
@[to_additive "Construct a normed group from a translation-invariant pseudodistance."]
def normed_group.of_mul_dist' [has_norm E] [group E] [metric_space E]
(hβ : β x : E, βxβ = dist x 1) (hβ : β x y z : E, dist (x * z) (y * z) β€ dist x y) :
normed_group E :=
{ ..seminormed_group.of_mul_dist' hβ hβ }
/-- Construct a normed group from a multiplication-invariant pseudodistance. -/
@[to_additive "Construct a normed group from a translation-invariant pseudodistance."]
def normed_comm_group.of_mul_dist [has_norm E] [comm_group E] [metric_space E]
(hβ : β x : E, βxβ = dist x 1) (hβ : β x y z : E, dist x y β€ dist (x * z) (y * z)) :
normed_comm_group E :=
{ ..normed_group.of_mul_dist hβ hβ }
/-- Construct a normed group from a multiplication-invariant pseudodistance. -/
@[to_additive "Construct a normed group from a translation-invariant pseudodistance."]
def normed_comm_group.of_mul_dist' [has_norm E] [comm_group E] [metric_space E]
(hβ : β x : E, βxβ = dist x 1) (hβ : β x y z : E, dist (x * z) (y * z) β€ dist x y) :
normed_comm_group E :=
{ ..normed_group.of_mul_dist' hβ hβ }
set_option old_structure_cmd true
/-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the
pseudometric space structure from the seminorm properties. Note that in most cases this instance
creates bad definitional equalities (e.g., it does not take into account a possibly existing
`uniform_space` instance on `E`). -/
@[to_additive "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance*
and the pseudometric space structure from the seminorm properties. Note that in most cases this
instance creates bad definitional equalities (e.g., it does not take into account a possibly
existing `uniform_space` instance on `E`)."]
def group_seminorm.to_seminormed_group [group E] (f : group_seminorm E) : seminormed_group E :=
{ dist := Ξ» x y, f (x / y),
norm := f,
dist_eq := Ξ» x y, rfl,
dist_self := Ξ» x, by simp only [div_self', map_one_eq_zero],
dist_triangle := le_map_div_add_map_div f,
dist_comm := map_div_rev f }
/-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the
pseudometric space structure from the seminorm properties. Note that in most cases this instance
creates bad definitional equalities (e.g., it does not take into account a possibly existing
`uniform_space` instance on `E`). -/
@[to_additive "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance*
and the pseudometric space structure from the seminorm properties. Note that in most cases this
instance creates bad definitional equalities (e.g., it does not take into account a possibly
existing `uniform_space` instance on `E`)."]
def group_seminorm.to_seminormed_comm_group [comm_group E] (f : group_seminorm E) :
seminormed_comm_group E :=
{ ..f.to_seminormed_group }
/-- Construct a normed group from a norm, i.e., registering the distance and the metric space
structure from the norm properties. Note that in most cases this instance creates bad definitional
equalities (e.g., it does not take into account a possibly existing `uniform_space` instance on
`E`). -/
@[to_additive "Construct a normed group from a norm, i.e., registering the distance and the metric
space structure from the norm properties. Note that in most cases this instance creates bad
definitional equalities (e.g., it does not take into account a possibly existing `uniform_space`
instance on `E`)."]
def group_norm.to_normed_group [group E] (f : group_norm E) : normed_group E :=
{ eq_of_dist_eq_zero := Ξ» x y h, div_eq_one.1 $ eq_one_of_map_eq_zero f h,
..f.to_group_seminorm.to_seminormed_group }
/-- Construct a normed group from a norm, i.e., registering the distance and the metric space
structure from the norm properties. Note that in most cases this instance creates bad definitional
equalities (e.g., it does not take into account a possibly existing `uniform_space` instance on
`E`). -/
@[to_additive "Construct a normed group from a norm, i.e., registering the distance and the metric
space structure from the norm properties. Note that in most cases this instance creates bad
definitional equalities (e.g., it does not take into account a possibly existing `uniform_space`
instance on `E`)."]
def group_norm.to_normed_comm_group [comm_group E] (f : group_norm E) : normed_comm_group E :=
{ ..f.to_normed_group }
instance : normed_add_comm_group punit :=
{ norm := function.const _ 0,
dist_eq := Ξ» _ _, rfl, }
@[simp] lemma punit.norm_eq_zero (r : punit) : βrβ = 0 := rfl
section seminormed_group
variables [seminormed_group E] [seminormed_group F] [seminormed_group G] {s : set E}
{a aβ aβ b bβ bβ : E} {r rβ rβ : β}
@[to_additive]
lemma dist_eq_norm_div (a b : E) : dist a b = βa / bβ := seminormed_group.dist_eq _ _
@[to_additive]
lemma dist_eq_norm_div' (a b : E) : dist a b = βb / aβ := by rw [dist_comm, dist_eq_norm_div]
alias dist_eq_norm_sub β dist_eq_norm
alias dist_eq_norm_sub' β dist_eq_norm'
@[to_additive] instance normed_group.to_has_isometric_smul_right : has_isometric_smul Eα΅α΅α΅ E :=
β¨Ξ» a, isometry.of_dist_eq $ Ξ» b c, by simp [dist_eq_norm_div]β©
@[simp, to_additive] lemma dist_one_right (a : E) : dist a 1 = βaβ :=
by rw [dist_eq_norm_div, div_one]
@[simp, to_additive] lemma dist_one_left : dist (1 : E) = norm :=
funext $ Ξ» a, by rw [dist_comm, dist_one_right]
@[to_additive]
lemma isometry.norm_map_of_map_one {f : E β F} (hi : isometry f) (hβ : f 1 = 1) (x : E) :
βf xβ = βxβ :=
by rw [βdist_one_right, βhβ, hi.dist_eq, dist_one_right]
@[to_additive tendsto_norm_cocompact_at_top]
lemma tendsto_norm_cocompact_at_top' [proper_space E] : tendsto norm (cocompact E) at_top :=
by simpa only [dist_one_right] using tendsto_dist_right_cocompact_at_top (1 : E)
@[to_additive] lemma norm_div_rev (a b : E) : βa / bβ = βb / aβ :=
by simpa only [dist_eq_norm_div] using dist_comm a b
@[simp, to_additive norm_neg]
lemma norm_inv' (a : E) : βaβ»ΒΉβ = βaβ := by simpa using norm_div_rev 1 a
@[simp, to_additive] lemma dist_mul_self_right (a b : E) : dist b (a * b) = βaβ :=
by rw [βdist_one_left, βdist_mul_right 1 a b, one_mul]
@[simp, to_additive] lemma dist_mul_self_left (a b : E) : dist (a * b) b = βaβ :=
by rw [dist_comm, dist_mul_self_right]
@[simp, to_additive] lemma dist_div_eq_dist_mul_left (a b c : E) :
dist (a / b) c = dist a (c * b) :=
by rw [βdist_mul_right _ _ b, div_mul_cancel']
@[simp, to_additive] lemma dist_div_eq_dist_mul_right (a b c : E) :
dist a (b / c) = dist (a * c) b :=
by rw [βdist_mul_right _ _ c, div_mul_cancel']
/-- In a (semi)normed group, inversion `x β¦ xβ»ΒΉ` tends to infinity at infinity. TODO: use
`bornology.cobounded` instead of `filter.comap has_norm.norm filter.at_top`. -/
@[to_additive "In a (semi)normed group, negation `x β¦ -x` tends to infinity at infinity. TODO: use
`bornology.cobounded` instead of `filter.comap has_norm.norm filter.at_top`."]
lemma filter.tendsto_inv_cobounded :
tendsto (has_inv.inv : E β E) (comap norm at_top) (comap norm at_top) :=
by simpa only [norm_inv', tendsto_comap_iff, (β)] using tendsto_comap
/-- **Triangle inequality** for the norm. -/
@[to_additive norm_add_le "**Triangle inequality** for the norm."]
lemma norm_mul_le' (a b : E) : βa * bβ β€ βaβ + βbβ :=
by simpa [dist_eq_norm_div] using dist_triangle a 1 bβ»ΒΉ
@[to_additive] lemma norm_mul_le_of_le (hβ : βaββ β€ rβ) (hβ : βaββ β€ rβ) : βaβ * aββ β€ rβ + rβ :=
(norm_mul_le' aβ aβ).trans $ add_le_add hβ hβ
@[to_additive norm_addβ_le] lemma norm_mulβ_le (a b c : E) : βa * b * cβ β€ βaβ + βbβ + βcβ :=
norm_mul_le_of_le (norm_mul_le' _ _) le_rfl
@[simp, to_additive norm_nonneg] lemma norm_nonneg' (a : E) : 0 β€ βaβ :=
by { rw [βdist_one_right], exact dist_nonneg }
section
open tactic tactic.positivity
/-- Extension for the `positivity` tactic: norms are nonnegative. -/
@[positivity]
meta def _root_.tactic.positivity_norm : expr β tactic strictness
| `(β%%aβ) := nonnegative <$> mk_app ``norm_nonneg [a] <|> nonnegative <$> mk_app ``norm_nonneg' [a]
| _ := failed
end
@[simp, to_additive norm_zero] lemma norm_one' : β(1 : E)β = 0 := by rw [βdist_one_right, dist_self]
@[to_additive] lemma ne_one_of_norm_ne_zero : βaβ β 0 β a β 1 :=
mt $ by { rintro rfl, exact norm_one' }
@[nontriviality, to_additive norm_of_subsingleton]
lemma norm_of_subsingleton' [subsingleton E] (a : E) : βaβ = 0 :=
by rw [subsingleton.elim a 1, norm_one']
attribute [nontriviality] norm_of_subsingleton
@[to_additive zero_lt_one_add_norm_sq]
lemma zero_lt_one_add_norm_sq' (x : E) : 0 < 1 + βxβ^2 := by positivity
@[to_additive] lemma norm_div_le (a b : E) : βa / bβ β€ βaβ + βbβ :=
by simpa [dist_eq_norm_div] using dist_triangle a 1 b
@[to_additive] lemma norm_div_le_of_le {rβ rβ : β} (Hβ : βaββ β€ rβ) (Hβ : βaββ β€ rβ) :
βaβ / aββ β€ rβ + rβ :=
(norm_div_le aβ aβ).trans $ add_le_add Hβ Hβ
@[to_additive] lemma dist_le_norm_mul_norm (a b : E) : dist a b β€ βaβ + βbβ :=
by { rw dist_eq_norm_div, apply norm_div_le }
@[to_additive abs_norm_sub_norm_le] lemma abs_norm_sub_norm_le' (a b : E) : |βaβ - βbβ| β€ βa / bβ :=
by simpa [dist_eq_norm_div] using abs_dist_sub_le a b 1
@[to_additive norm_sub_norm_le] lemma norm_sub_norm_le' (a b : E) : βaβ - βbβ β€ βa / bβ :=
(le_abs_self _).trans (abs_norm_sub_norm_le' a b)
@[to_additive dist_norm_norm_le] lemma dist_norm_norm_le' (a b : E) : dist βaβ βbβ β€ βa / bβ :=
abs_norm_sub_norm_le' a b
@[to_additive] lemma norm_le_norm_add_norm_div' (u v : E) : βuβ β€ βvβ + βu / vβ :=
by { rw add_comm, refine (norm_mul_le' _ _).trans_eq' _, rw div_mul_cancel' }
@[to_additive] lemma norm_le_norm_add_norm_div (u v : E) : βvβ β€ βuβ + βu / vβ :=
by { rw norm_div_rev, exact norm_le_norm_add_norm_div' v u }
alias norm_le_norm_add_norm_sub' β norm_le_insert'
alias norm_le_norm_add_norm_sub β norm_le_insert
@[to_additive] lemma norm_le_mul_norm_add (u v : E) : βuβ β€ βu * vβ + βvβ :=
calc βuβ = βu * v / vβ : by rw mul_div_cancel''
... β€ βu * vβ + βvβ : norm_div_le _ _
@[to_additive ball_eq] lemma ball_eq' (y : E) (Ξ΅ : β) : ball y Ξ΅ = {x | βx / yβ < Ξ΅} :=
set.ext $ Ξ» a, by simp [dist_eq_norm_div]
@[to_additive] lemma ball_one_eq (r : β) : ball (1 : E) r = {x | βxβ < r} :=
set.ext $ assume a, by simp
@[to_additive mem_ball_iff_norm] lemma mem_ball_iff_norm'' : b β ball a r β βb / aβ < r :=
by rw [mem_ball, dist_eq_norm_div]
@[to_additive mem_ball_iff_norm'] lemma mem_ball_iff_norm''' : b β ball a r β βa / bβ < r :=
by rw [mem_ball', dist_eq_norm_div]
@[simp, to_additive] lemma mem_ball_one_iff : a β ball (1 : E) r β βaβ < r :=
by rw [mem_ball, dist_one_right]
@[to_additive mem_closed_ball_iff_norm]
lemma mem_closed_ball_iff_norm'' : b β closed_ball a r β βb / aβ β€ r :=
by rw [mem_closed_ball, dist_eq_norm_div]
@[simp, to_additive] lemma mem_closed_ball_one_iff : a β closed_ball (1 : E) r β βaβ β€ r :=
by rw [mem_closed_ball, dist_one_right]
@[to_additive mem_closed_ball_iff_norm']
lemma mem_closed_ball_iff_norm''' : b β closed_ball a r β βa / bβ β€ r :=
by rw [mem_closed_ball', dist_eq_norm_div]
@[to_additive norm_le_of_mem_closed_ball]
lemma norm_le_of_mem_closed_ball' (h : b β closed_ball a r) : βbβ β€ βaβ + r :=
(norm_le_norm_add_norm_div' _ _).trans $ add_le_add_left (by rwa βdist_eq_norm_div) _
@[to_additive norm_le_norm_add_const_of_dist_le]
lemma norm_le_norm_add_const_of_dist_le' : dist a b β€ r β βaβ β€ βbβ + r :=
norm_le_of_mem_closed_ball'
@[to_additive norm_lt_of_mem_ball]
lemma norm_lt_of_mem_ball' (h : b β ball a r) : βbβ < βaβ + r :=
(norm_le_norm_add_norm_div' _ _).trans_lt $ add_lt_add_left (by rwa βdist_eq_norm_div) _
@[to_additive]
lemma norm_div_sub_norm_div_le_norm_div (u v w : E) : βu / wβ - βv / wβ β€ βu / vβ :=
by simpa only [div_div_div_cancel_right'] using norm_sub_norm_le' (u / w) (v / w)
@[to_additive bounded_iff_forall_norm_le]
lemma bounded_iff_forall_norm_le' : bounded s β β C, β x β s, βxβ β€ C :=
by simpa only [set.subset_def, mem_closed_ball_one_iff] using bounded_iff_subset_ball (1 : E)
alias bounded_iff_forall_norm_le' β metric.bounded.exists_norm_le' _
alias bounded_iff_forall_norm_le β metric.bounded.exists_norm_le _
attribute [to_additive metric.bounded.exists_norm_le] metric.bounded.exists_norm_le'
@[to_additive metric.bounded.exists_pos_norm_le]
lemma metric.bounded.exists_pos_norm_le' (hs : metric.bounded s) : β R > 0, β x β s, βxβ β€ R :=
let β¨Rβ, hRββ© := hs.exists_norm_le' in
β¨max Rβ 1, by positivity, Ξ» x hx, (hRβ x hx).trans $ le_max_left _ _β©
@[simp, to_additive mem_sphere_iff_norm]
lemma mem_sphere_iff_norm' : b β sphere a r β βb / aβ = r := by simp [dist_eq_norm_div]
@[simp, to_additive] lemma mem_sphere_one_iff_norm : a β sphere (1 : E) r β βaβ = r :=
by simp [dist_eq_norm_div]
@[simp, to_additive norm_eq_of_mem_sphere]
lemma norm_eq_of_mem_sphere' (x : sphere (1:E) r) : β(x : E)β = r := mem_sphere_one_iff_norm.mp x.2
@[to_additive] lemma ne_one_of_mem_sphere (hr : r β 0) (x : sphere (1 : E) r) : (x : E) β 1 :=
ne_one_of_norm_ne_zero $ by rwa norm_eq_of_mem_sphere' x
@[to_additive ne_zero_of_mem_unit_sphere]
lemma ne_one_of_mem_unit_sphere (x : sphere (1 : E) 1) : (x:E) β 1 :=
ne_one_of_mem_sphere one_ne_zero _
variables (E)
/-- The norm of a seminormed group as a group seminorm. -/
@[to_additive "The norm of a seminormed group as an additive group seminorm."]
def norm_group_seminorm : group_seminorm E := β¨norm, norm_one', norm_mul_le', norm_inv'β©
@[simp, to_additive] lemma coe_norm_group_seminorm : β(norm_group_seminorm E) = norm := rfl
variables {E}
@[to_additive] lemma normed_comm_group.tendsto_nhds_one {f : Ξ± β E} {l : filter Ξ±} :
tendsto f l (π 1) β β Ξ΅ > 0, βαΆ x in l, β f x β < Ξ΅ :=
metric.tendsto_nhds.trans $ by simp only [dist_one_right]
@[to_additive] lemma normed_comm_group.tendsto_nhds_nhds {f : E β F} {x : E} {y : F} :
tendsto f (π x) (π y) β β Ξ΅ > 0, β Ξ΄ > 0, β x', βx' / xβ < Ξ΄ β βf x' / yβ < Ξ΅ :=
by simp_rw [metric.tendsto_nhds_nhds, dist_eq_norm_div]
@[to_additive] lemma normed_comm_group.cauchy_seq_iff [nonempty Ξ±] [semilattice_sup Ξ±] {u : Ξ± β E} :
cauchy_seq u β β Ξ΅ > 0, β N, β m, N β€ m β β n, N β€ n β βu m / u nβ < Ξ΅ :=
by simp [metric.cauchy_seq_iff, dist_eq_norm_div]
@[to_additive] lemma normed_comm_group.nhds_basis_norm_lt (x : E) :
(π x).has_basis (Ξ» Ξ΅ : β, 0 < Ξ΅) (Ξ» Ξ΅, {y | βy / xβ < Ξ΅}) :=
by { simp_rw β ball_eq', exact metric.nhds_basis_ball }
@[to_additive] lemma normed_comm_group.nhds_one_basis_norm_lt :
(π (1 : E)).has_basis (Ξ» Ξ΅ : β, 0 < Ξ΅) (Ξ» Ξ΅, {y | βyβ < Ξ΅}) :=
by { convert normed_comm_group.nhds_basis_norm_lt (1 : E), simp }
@[to_additive] lemma normed_comm_group.uniformity_basis_dist :
(π€ E).has_basis (Ξ» Ξ΅ : β, 0 < Ξ΅) (Ξ» Ξ΅, {p : E Γ E | βp.fst / p.sndβ < Ξ΅}) :=
by { convert metric.uniformity_basis_dist, simp [dist_eq_norm_div] }
open finset
/-- A homomorphism `f` of seminormed groups is Lipschitz, if there exists a constant `C` such that
for all `x`, one has `βf xβ β€ C * βxβ`. The analogous condition for a linear map of
(semi)normed spaces is in `normed_space.operator_norm`. -/
@[to_additive "A homomorphism `f` of seminormed groups is Lipschitz, if there exists a constant `C`
such that for all `x`, one has `βf xβ β€ C * βxβ`. The analogous condition for a linear map of
(semi)normed spaces is in `normed_space.operator_norm`."]
lemma monoid_hom_class.lipschitz_of_bound [monoid_hom_class π E F] (f : π) (C : β)
(h : β x, βf xβ β€ C * βxβ) : lipschitz_with (real.to_nnreal C) f :=
lipschitz_with.of_dist_le' $ Ξ» x y, by simpa only [dist_eq_norm_div, map_div] using h (x / y)
@[to_additive] lemma lipschitz_on_with_iff_norm_div_le {f : E β F} {C : ββ₯0} :
lipschitz_on_with C f s β β β¦xβ¦, x β s β β β¦yβ¦, y β s β βf x / f yβ β€ C * βx / yβ :=
by simp only [lipschitz_on_with_iff_dist_le_mul, dist_eq_norm_div]
alias lipschitz_on_with_iff_norm_div_le β lipschitz_on_with.norm_div_le _
attribute [to_additive] lipschitz_on_with.norm_div_le
@[to_additive] lemma lipschitz_on_with.norm_div_le_of_le {f : E β F} {C : ββ₯0}
(h : lipschitz_on_with C f s) (ha : a β s) (hb : b β s) (hr : βa / bβ β€ r) :
βf a / f bβ β€ C * r :=
(h.norm_div_le ha hb).trans $ mul_le_mul_of_nonneg_left hr C.2
@[to_additive] lemma lipschitz_with_iff_norm_div_le {f : E β F} {C : ββ₯0} :
lipschitz_with C f β β x y, βf x / f yβ β€ C * βx / yβ :=
by simp only [lipschitz_with_iff_dist_le_mul, dist_eq_norm_div]
alias lipschitz_with_iff_norm_div_le β lipschitz_with.norm_div_le _
attribute [to_additive] lipschitz_with.norm_div_le
@[to_additive] lemma lipschitz_with.norm_div_le_of_le {f : E β F} {C : ββ₯0} (h : lipschitz_with C f)
(hr : βa / bβ β€ r) : βf a / f bβ β€ C * r :=
(h.norm_div_le _ _).trans $ mul_le_mul_of_nonneg_left hr C.2
/-- A homomorphism `f` of seminormed groups is continuous, if there exists a constant `C` such that
for all `x`, one has `βf xβ β€ C * βxβ`. -/
@[to_additive "A homomorphism `f` of seminormed groups is continuous, if there exists a constant `C`
such that for all `x`, one has `βf xβ β€ C * βxβ`"]
lemma monoid_hom_class.continuous_of_bound [monoid_hom_class π E F] (f : π) (C : β)
(h : β x, βf xβ β€ C * βxβ) : continuous f :=
(monoid_hom_class.lipschitz_of_bound f C h).continuous
@[to_additive] lemma monoid_hom_class.uniform_continuous_of_bound [monoid_hom_class π E F]
(f : π) (C : β) (h : βx, βf xβ β€ C * βxβ) : uniform_continuous f :=
(monoid_hom_class.lipschitz_of_bound f C h).uniform_continuous
@[to_additive is_compact.exists_bound_of_continuous_on]
lemma is_compact.exists_bound_of_continuous_on' [topological_space Ξ±] {s : set Ξ±}
(hs : is_compact s) {f : Ξ± β E} (hf : continuous_on f s) :
β C, β x β s, βf xβ β€ C :=
(bounded_iff_forall_norm_le'.1 (hs.image_of_continuous_on hf).bounded).imp $ Ξ» C hC x hx,
hC _ $ set.mem_image_of_mem _ hx
@[to_additive] lemma monoid_hom_class.isometry_iff_norm [monoid_hom_class π E F] (f : π) :
isometry f β β x, βf xβ = βxβ :=
begin
simp only [isometry_iff_dist_eq, dist_eq_norm_div, βmap_div],
refine β¨Ξ» h x, _, Ξ» h x y, h _β©,
simpa using h x 1,
end
alias monoid_hom_class.isometry_iff_norm β _ monoid_hom_class.isometry_of_norm
attribute [to_additive] monoid_hom_class.isometry_of_norm
section nnnorm
@[priority 100, to_additive] -- See note [lower instance priority]
instance seminormed_group.to_has_nnnorm : has_nnnorm E := β¨Ξ» a, β¨βaβ, norm_nonneg' aβ©β©
@[simp, norm_cast, to_additive coe_nnnorm] lemma coe_nnnorm' (a : E) : (βaββ : β) = βaβ := rfl
@[simp, to_additive coe_comp_nnnorm]
lemma coe_comp_nnnorm' : (coe : ββ₯0 β β) β (nnnorm : E β ββ₯0) = norm := rfl
@[to_additive norm_to_nnreal]
lemma norm_to_nnreal' : βaβ.to_nnreal = βaββ := @real.to_nnreal_coe βaββ
@[to_additive]
lemma nndist_eq_nnnorm_div (a b : E) : nndist a b = βa / bββ := nnreal.eq $ dist_eq_norm_div _ _
alias nndist_eq_nnnorm_sub β nndist_eq_nnnorm
@[simp, to_additive nnnorm_zero] lemma nnnorm_one' : β(1 : E)ββ = 0 := nnreal.eq norm_one'
@[to_additive] lemma ne_one_of_nnnorm_ne_zero {a : E} : βaββ β 0 β a β 1 :=
mt $ by { rintro rfl, exact nnnorm_one' }
@[to_additive nnnorm_add_le]
lemma nnnorm_mul_le' (a b : E) : βa * bββ β€ βaββ + βbββ := nnreal.coe_le_coe.1 $ norm_mul_le' a b
@[simp, to_additive nnnorm_neg] lemma nnnorm_inv' (a : E) : βaβ»ΒΉββ = βaββ := nnreal.eq $ norm_inv' a
@[to_additive] lemma nnnorm_div_le (a b : E) : βa / bββ β€ βaββ + βbββ :=
nnreal.coe_le_coe.1 $ norm_div_le _ _
@[to_additive nndist_nnnorm_nnnorm_le]
lemma nndist_nnnorm_nnnorm_le' (a b : E) : nndist βaββ βbββ β€ βa / bββ :=
nnreal.coe_le_coe.1 $ dist_norm_norm_le' a b
@[to_additive] lemma nnnorm_le_nnnorm_add_nnnorm_div (a b : E) : βbββ β€ βaββ + βa / bββ :=
norm_le_norm_add_norm_div _ _
@[to_additive] lemma nnnorm_le_nnnorm_add_nnnorm_div' (a b : E) : βaββ β€ βbββ + βa / bββ :=
norm_le_norm_add_norm_div' _ _
alias nnnorm_le_nnnorm_add_nnnorm_sub' β nnnorm_le_insert'
alias nnnorm_le_nnnorm_add_nnnorm_sub β nnnorm_le_insert
@[to_additive]
lemma nnnorm_le_mul_nnnorm_add (a b : E) : βaββ β€ βa * bββ + βbββ := norm_le_mul_norm_add _ _
@[to_additive of_real_norm_eq_coe_nnnorm]
lemma of_real_norm_eq_coe_nnnorm' (a : E) : ennreal.of_real βaβ = βaββ :=
ennreal.of_real_eq_coe_nnreal _
@[to_additive] lemma edist_eq_coe_nnnorm_div (a b : E) : edist a b = βa / bββ :=
by rw [edist_dist, dist_eq_norm_div, of_real_norm_eq_coe_nnnorm']
@[to_additive edist_eq_coe_nnnorm] lemma edist_eq_coe_nnnorm' (x : E) : edist x 1 = (βxββ : ββ₯0β) :=
by rw [edist_eq_coe_nnnorm_div, div_one]
@[to_additive]
lemma mem_emetric_ball_one_iff {r : ββ₯0β} : a β emetric.ball (1 : E) r β ββaββ < r :=
by rw [emetric.mem_ball, edist_eq_coe_nnnorm']
@[to_additive] lemma monoid_hom_class.lipschitz_of_bound_nnnorm [monoid_hom_class π E F] (f : π)
(C : ββ₯0) (h : β x, βf xββ β€ C * βxββ) : lipschitz_with C f :=
@real.to_nnreal_coe C βΈ monoid_hom_class.lipschitz_of_bound f C h
@[to_additive] lemma monoid_hom_class.antilipschitz_of_bound [monoid_hom_class π E F] (f : π)
{K : ββ₯0} (h : β x, βxβ β€ K * βf xβ) :
antilipschitz_with K f :=
antilipschitz_with.of_le_mul_dist $ Ξ» x y, by simpa only [dist_eq_norm_div, map_div] using h (x / y)
@[to_additive] lemma monoid_hom_class.bound_of_antilipschitz [monoid_hom_class π E F] (f : π)
{K : ββ₯0} (h : antilipschitz_with K f) (x) : βxβ β€ K * βf xβ :=
by simpa only [dist_one_right, map_one] using h.le_mul_dist x 1
end nnnorm
@[to_additive] lemma tendsto_iff_norm_tendsto_one {f : Ξ± β E} {a : filter Ξ±} {b : E} :
tendsto f a (π b) β tendsto (Ξ» e, βf e / bβ) a (π 0) :=
by { convert tendsto_iff_dist_tendsto_zero, simp [dist_eq_norm_div] }
@[to_additive] lemma tendsto_one_iff_norm_tendsto_one {f : Ξ± β E} {a : filter Ξ±} :
tendsto f a (π 1) β tendsto (Ξ» e, βf eβ) a (π 0) :=
by { rw tendsto_iff_norm_tendsto_one, simp only [div_one] }
@[to_additive] lemma comap_norm_nhds_one : comap norm (π 0) = π (1 : E) :=
by simpa only [dist_one_right] using nhds_comap_dist (1 : E)
/-- Special case of the sandwich theorem: if the norm of `f` is eventually bounded by a real
function `a` which tends to `0`, then `f` tends to `1`. In this pair of lemmas (`squeeze_one_norm'`
and `squeeze_one_norm`), following a convention of similar lemmas in `topology.metric_space.basic`
and `topology.algebra.order`, the `'` version is phrased using "eventually" and the non-`'` version
is phrased absolutely. -/
@[to_additive "Special case of the sandwich theorem: if the norm of `f` is eventually bounded by a
real function `a` which tends to `0`, then `f` tends to `1`. In this pair of lemmas
(`squeeze_zero_norm'` and `squeeze_zero_norm`), following a convention of similar lemmas in
`topology.metric_space.basic` and `topology.algebra.order`, the `'` version is phrased using
\"eventually\" and the non-`'` version is phrased absolutely."]
lemma squeeze_one_norm' {f : Ξ± β E} {a : Ξ± β β} {tβ : filter Ξ±} (h : βαΆ n in tβ, βf nβ β€ a n)
(h' : tendsto a tβ (π 0)) : tendsto f tβ (π 1) :=
tendsto_one_iff_norm_tendsto_one.2 $ squeeze_zero' (eventually_of_forall $ Ξ» n, norm_nonneg' _) h h'
/-- Special case of the sandwich theorem: if the norm of `f` is bounded by a real function `a` which
tends to `0`, then `f` tends to `1`. -/
@[to_additive "Special case of the sandwich theorem: if the norm of `f` is bounded by a real
function `a` which tends to `0`, then `f` tends to `0`."]
lemma squeeze_one_norm {f : Ξ± β E} {a : Ξ± β β} {tβ : filter Ξ±} (h : β n, βf nβ β€ a n) :
tendsto a tβ (π 0) β tendsto f tβ (π 1) :=
squeeze_one_norm' $ eventually_of_forall h
@[to_additive] lemma tendsto_norm_div_self (x : E) : tendsto (Ξ» a, βa / xβ) (π x) (π 0) :=
by simpa [dist_eq_norm_div] using
tendsto_id.dist (tendsto_const_nhds : tendsto (Ξ» a, (x:E)) (π x) _)
@[to_additive tendsto_norm]lemma tendsto_norm' {x : E} : tendsto (Ξ» a, βaβ) (π x) (π βxβ) :=
by simpa using tendsto_id.dist (tendsto_const_nhds : tendsto (Ξ» a, (1:E)) _ _)
@[to_additive] lemma tendsto_norm_one : tendsto (Ξ» a : E, βaβ) (π 1) (π 0) :=
by simpa using tendsto_norm_div_self (1:E)
@[continuity, to_additive continuous_norm] lemma continuous_norm' : continuous (Ξ» a : E, βaβ) :=
by simpa using continuous_id.dist (continuous_const : continuous (Ξ» a, (1:E)))
@[continuity, to_additive continuous_nnnorm]
lemma continuous_nnnorm' : continuous (Ξ» a : E, βaββ) := continuous_norm'.subtype_mk _
@[to_additive lipschitz_with_one_norm] lemma lipschitz_with_one_norm' :
lipschitz_with 1 (norm : E β β) :=
by simpa only [dist_one_left] using lipschitz_with.dist_right (1 : E)
@[to_additive lipschitz_with_one_nnnorm] lemma lipschitz_with_one_nnnorm' :
lipschitz_with 1 (has_nnnorm.nnnorm : E β ββ₯0) :=
lipschitz_with_one_norm'
@[to_additive uniform_continuous_norm]
lemma uniform_continuous_norm' : uniform_continuous (norm : E β β) :=
lipschitz_with_one_norm'.uniform_continuous
@[to_additive uniform_continuous_nnnorm]
lemma uniform_continuous_nnnorm' : uniform_continuous (Ξ» (a : E), βaββ) :=
uniform_continuous_norm'.subtype_mk _
@[to_additive] lemma mem_closure_one_iff_norm {x : E} : x β closure ({1} : set E) β βxβ = 0 :=
by rw [βclosed_ball_zero', mem_closed_ball_one_iff, (norm_nonneg' x).le_iff_eq]
@[to_additive] lemma closure_one_eq : closure ({1} : set E) = {x | βxβ = 0} :=
set.ext (Ξ» x, mem_closure_one_iff_norm)
/-- A helper lemma used to prove that the (scalar or usual) product of a function that tends to one
and a bounded function tends to one. This lemma is formulated for any binary operation
`op : E β F β G` with an estimate `βop x yβ β€ A * βxβ * βyβ` for some constant A instead of
multiplication so that it can be applied to `(*)`, `flip (*)`, `(β’)`, and `flip (β’)`. -/
@[to_additive "A helper lemma used to prove that the (scalar or usual) product of a function that
tends to zero and a bounded function tends to zero. This lemma is formulated for any binary
operation `op : E β F β G` with an estimate `βop x yβ β€ A * βxβ * βyβ` for some constant A instead
of multiplication so that it can be applied to `(*)`, `flip (*)`, `(β’)`, and `flip (β’)`."]
lemma filter.tendsto.op_one_is_bounded_under_le' {f : Ξ± β E} {g : Ξ± β F} {l : filter Ξ±}
(hf : tendsto f l (π 1)) (hg : is_bounded_under (β€) l (norm β g)) (op : E β F β G)
(h_op : β A, β x y, βop x yβ β€ A * βxβ * βyβ) :
tendsto (Ξ» x, op (f x) (g x)) l (π 1) :=
begin
cases h_op with A h_op,
rcases hg with β¨C, hCβ©, rw eventually_map at hC,
rw normed_comm_group.tendsto_nhds_one at hf β’,
intros Ξ΅ Ξ΅β,
rcases exists_pos_mul_lt Ξ΅β (A * C) with β¨Ξ΄, Ξ΄β, hΞ΄β©,
filter_upwards [hf Ξ΄ Ξ΄β, hC] with i hf hg,
refine (h_op _ _).trans_lt _,
cases le_total A 0 with hA hA,
{ exact (mul_nonpos_of_nonpos_of_nonneg (mul_nonpos_of_nonpos_of_nonneg hA $ norm_nonneg' _) $
norm_nonneg' _).trans_lt Ξ΅β },
calc A * βf iβ * βg iβ β€ A * Ξ΄ * C :
mul_le_mul (mul_le_mul_of_nonneg_left hf.le hA) hg (norm_nonneg' _) (mul_nonneg hA Ξ΄β.le)
... = A * C * Ξ΄ : mul_right_comm _ _ _
... < Ξ΅ : hΞ΄,
end
/-- A helper lemma used to prove that the (scalar or usual) product of a function that tends to one
and a bounded function tends to one. This lemma is formulated for any binary operation
`op : E β F β G` with an estimate `βop x yβ β€ βxβ * βyβ` instead of multiplication so that it
can be applied to `(*)`, `flip (*)`, `(β’)`, and `flip (β’)`. -/
@[to_additive "A helper lemma used to prove that the (scalar or usual) product of a function that
tends to zero and a bounded function tends to zero. This lemma is formulated for any binary
operation `op : E β F β G` with an estimate `βop x yβ β€ βxβ * βyβ` instead of multiplication so that
it can be applied to `(*)`, `flip (*)`, `(β’)`, and `flip (β’)`."]
lemma filter.tendsto.op_one_is_bounded_under_le {f : Ξ± β E} {g : Ξ± β F} {l : filter Ξ±}
(hf : tendsto f l (π 1)) (hg : is_bounded_under (β€) l (norm β g)) (op : E β F β G)
(h_op : β x y, βop x yβ β€ βxβ * βyβ) :
tendsto (Ξ» x, op (f x) (g x)) l (π 1) :=
hf.op_one_is_bounded_under_le' hg op β¨1, Ξ» x y, (one_mul (βxβ)).symm βΈ h_op x yβ©
section
variables {l : filter Ξ±} {f : Ξ± β E}
@[to_additive filter.tendsto.norm] lemma filter.tendsto.norm' (h : tendsto f l (π a)) :
tendsto (Ξ» x, βf xβ) l (π βaβ) :=
tendsto_norm'.comp h
@[to_additive filter.tendsto.nnnorm] lemma filter.tendsto.nnnorm' (h : tendsto f l (π a)) :
tendsto (Ξ» x, βf xββ) l (π (βaββ)) :=
tendsto.comp continuous_nnnorm'.continuous_at h
end
section
variables [topological_space Ξ±] {f : Ξ± β E}
@[to_additive continuous.norm] lemma continuous.norm' : continuous f β continuous (Ξ» x, βf xβ) :=
continuous_norm'.comp
@[to_additive continuous.nnnorm]
lemma continuous.nnnorm' : continuous f β continuous (Ξ» x, βf xββ) := continuous_nnnorm'.comp
@[to_additive continuous_at.norm]
lemma continuous_at.norm' {a : Ξ±} (h : continuous_at f a) : continuous_at (Ξ» x, βf xβ) a := h.norm'
@[to_additive continuous_at.nnnorm]
lemma continuous_at.nnnorm' {a : Ξ±} (h : continuous_at f a) : continuous_at (Ξ» x, βf xββ) a :=
h.nnnorm'
@[to_additive continuous_within_at.norm]
lemma continuous_within_at.norm' {s : set Ξ±} {a : Ξ±} (h : continuous_within_at f s a) :
continuous_within_at (Ξ» x, βf xβ) s a :=
h.norm'
@[to_additive continuous_within_at.nnnorm]
lemma continuous_within_at.nnnorm' {s : set Ξ±} {a : Ξ±} (h : continuous_within_at f s a) :
continuous_within_at (Ξ» x, βf xββ) s a :=
h.nnnorm'
@[to_additive continuous_on.norm]
lemma continuous_on.norm' {s : set Ξ±} (h : continuous_on f s) : continuous_on (Ξ» x, βf xβ) s :=
Ξ» x hx, (h x hx).norm'
@[to_additive continuous_on.nnnorm]
lemma continuous_on.nnnorm' {s : set Ξ±} (h : continuous_on f s) : continuous_on (Ξ» x, βf xββ) s :=
Ξ» x hx, (h x hx).nnnorm'
end
/-- If `βyβ β β`, then we can assume `y β x` for any fixed `x`. -/
@[to_additive eventually_ne_of_tendsto_norm_at_top "If `βyβββ`, then we can assume `yβ x` for any
fixed `x`"]
lemma eventually_ne_of_tendsto_norm_at_top' {l : filter Ξ±} {f : Ξ± β E}
(h : tendsto (Ξ» y, βf yβ) l at_top) (x : E) :
βαΆ y in l, f y β x :=
(h.eventually_ne_at_top _).mono $ Ξ» x, ne_of_apply_ne norm
@[to_additive] lemma seminormed_comm_group.mem_closure_iff :
a β closure s β β Ξ΅, 0 < Ξ΅ β β b β s, βa / bβ < Ξ΅ :=
by simp [metric.mem_closure_iff, dist_eq_norm_div]
@[to_additive norm_le_zero_iff'] lemma norm_le_zero_iff''' [t0_space E] {a : E} : βaβ β€ 0 β a = 1 :=
begin
letI : normed_group E :=
{ to_metric_space := metric_space.of_t0_pseudo_metric_space E, ..βΉseminormed_group EβΊ },
rw [βdist_one_right, dist_le_zero],
end
@[to_additive norm_eq_zero'] lemma norm_eq_zero''' [t0_space E] {a : E} : βaβ = 0 β a = 1 :=
(norm_nonneg' a).le_iff_eq.symm.trans norm_le_zero_iff'''
@[to_additive norm_pos_iff'] lemma norm_pos_iff''' [t0_space E] {a : E} : 0 < βaβ β a β 1 :=
by rw [β not_le, norm_le_zero_iff''']
@[to_additive]
lemma seminormed_group.tendsto_uniformly_on_one {f : ΞΉ β ΞΊ β G} {s : set ΞΊ} {l : filter ΞΉ} :
tendsto_uniformly_on f 1 l s β β Ξ΅ > 0, βαΆ i in l, β x β s, βf i xβ < Ξ΅ :=
by simp_rw [tendsto_uniformly_on_iff, pi.one_apply, dist_one_left]
@[to_additive]
lemma seminormed_group.uniform_cauchy_seq_on_filter_iff_tendsto_uniformly_on_filter_one
{f : ΞΉ β ΞΊ β G} {l : filter ΞΉ} {l' : filter ΞΊ} : uniform_cauchy_seq_on_filter f l l' β
tendsto_uniformly_on_filter (Ξ» n : ΞΉ Γ ΞΉ, Ξ» z, f n.fst z / f n.snd z) 1 (l ΓαΆ l) l' :=
begin
refine β¨Ξ» hf u hu, _, Ξ» hf u hu, _β©,
{ obtain β¨Ξ΅, hΞ΅, Hβ© := uniformity_basis_dist.mem_uniformity_iff.mp hu,
refine (hf {p : G Γ G | dist p.fst p.snd < Ξ΅} $ dist_mem_uniformity hΞ΅).mono (Ξ» x hx,
H 1 (f x.fst.fst x.snd / f x.fst.snd x.snd) _),
simpa [dist_eq_norm_div, norm_div_rev] using hx },
{ obtain β¨Ξ΅, hΞ΅, Hβ© := uniformity_basis_dist.mem_uniformity_iff.mp hu,
refine (hf {p : G Γ G | dist p.fst p.snd < Ξ΅} $ dist_mem_uniformity hΞ΅).mono (Ξ» x hx,
H (f x.fst.fst x.snd) (f x.fst.snd x.snd) _),
simpa [dist_eq_norm_div, norm_div_rev] using hx }
end
@[to_additive]
lemma seminormed_group.uniform_cauchy_seq_on_iff_tendsto_uniformly_on_one
{f : ΞΉ β ΞΊ β G} {s : set ΞΊ} {l : filter ΞΉ} :
uniform_cauchy_seq_on f l s β
tendsto_uniformly_on (Ξ» n : ΞΉ Γ ΞΉ, Ξ» z, f n.fst z / f n.snd z) 1 (l ΓαΆ l) s :=
by rw [tendsto_uniformly_on_iff_tendsto_uniformly_on_filter,
uniform_cauchy_seq_on_iff_uniform_cauchy_seq_on_filter,
seminormed_group.uniform_cauchy_seq_on_filter_iff_tendsto_uniformly_on_filter_one]
end seminormed_group
section induced
variables (E F)
/-- A group homomorphism from a `group` to a `seminormed_group` induces a `seminormed_group`
structure on the domain. -/
@[reducible, -- See note [reducible non-instances]
to_additive "A group homomorphism from an `add_group` to a `seminormed_add_group` induces a
`seminormed_add_group` structure on the domain."]
def seminormed_group.induced [group E] [seminormed_group F] [monoid_hom_class π E F] (f : π) :
seminormed_group E :=
{ norm := Ξ» x, βf xβ,
dist_eq := Ξ» x y, by simpa only [map_div, βdist_eq_norm_div],
..pseudo_metric_space.induced f _ }
/-- A group homomorphism from a `comm_group` to a `seminormed_group` induces a
`seminormed_comm_group` structure on the domain. -/
@[reducible, -- See note [reducible non-instances]
to_additive "A group homomorphism from an `add_comm_group` to a `seminormed_add_group` induces a
`seminormed_add_comm_group` structure on the domain."]
def seminormed_comm_group.induced [comm_group E] [seminormed_group F] [monoid_hom_class π E F]
(f : π) : seminormed_comm_group E :=
{ ..seminormed_group.induced E F f }
/-- An injective group homomorphism from a `group` to a `normed_group` induces a `normed_group`
structure on the domain. -/
@[reducible, -- See note [reducible non-instances].
to_additive "An injective group homomorphism from an `add_group` to a `normed_add_group` induces a
`normed_add_group` structure on the domain."]
def normed_group.induced [group E] [normed_group F] [monoid_hom_class π E F] (f : π)
(h : injective f) : normed_group E :=
{ ..seminormed_group.induced E F f, ..metric_space.induced f h _ }
/-- An injective group homomorphism from an `comm_group` to a `normed_group` induces a
`normed_comm_group` structure on the domain. -/
@[reducible, -- See note [reducible non-instances].
to_additive "An injective group homomorphism from an `comm_group` to a `normed_comm_group` induces a
`normed_comm_group` structure on the domain."]
def normed_comm_group.induced [comm_group E] [normed_group F] [monoid_hom_class π E F] (f : π)
(h : injective f) : normed_comm_group E :=
{ ..seminormed_group.induced E F f, ..metric_space.induced f h _ }
end induced
section seminormed_comm_group
variables [seminormed_comm_group E] [seminormed_comm_group F] {a aβ aβ b bβ bβ : E} {r rβ rβ : β}
@[to_additive] instance normed_group.to_has_isometric_smul_left : has_isometric_smul E E :=
β¨Ξ» a, isometry.of_dist_eq $ Ξ» b c, by simp [dist_eq_norm_div]β©
@[to_additive] lemma dist_inv (x y : E) : dist xβ»ΒΉ y = dist x yβ»ΒΉ :=
by simp_rw [dist_eq_norm_div, βnorm_inv' (xβ»ΒΉ / y), inv_div, div_inv_eq_mul, mul_comm]
@[simp, to_additive] lemma dist_self_mul_right (a b : E) : dist a (a * b) = βbβ :=
by rw [βdist_one_left, βdist_mul_left a 1 b, mul_one]
@[simp, to_additive] lemma dist_self_mul_left (a b : E) : dist (a * b) a = βbβ :=
by rw [dist_comm, dist_self_mul_right]
@[simp, to_additive] lemma dist_self_div_right (a b : E) : dist a (a / b) = βbβ :=
by rw [div_eq_mul_inv, dist_self_mul_right, norm_inv']
@[simp, to_additive] lemma dist_self_div_left (a b : E) : dist (a / b) a = βbβ :=
by rw [dist_comm, dist_self_div_right]
@[to_additive] lemma dist_mul_mul_le (aβ aβ bβ bβ : E) :
dist (aβ * aβ) (bβ * bβ) β€ dist aβ bβ + dist aβ bβ :=
by simpa only [dist_mul_left, dist_mul_right] using dist_triangle (aβ * aβ) (bβ * aβ) (bβ * bβ)
@[to_additive] lemma dist_mul_mul_le_of_le (hβ : dist aβ bβ β€ rβ) (hβ : dist aβ bβ β€ rβ) :
dist (aβ * aβ) (bβ * bβ) β€ rβ + rβ :=
(dist_mul_mul_le aβ aβ bβ bβ).trans $ add_le_add hβ hβ
@[to_additive] lemma dist_div_div_le (aβ aβ bβ bβ : E) :
dist (aβ / aβ) (bβ / bβ) β€ dist aβ bβ + dist aβ bβ :=
by simpa only [div_eq_mul_inv, dist_inv_inv] using dist_mul_mul_le aβ aββ»ΒΉ bβ bββ»ΒΉ
@[to_additive] lemma dist_div_div_le_of_le (hβ : dist aβ bβ β€ rβ) (hβ : dist aβ bβ β€ rβ) :
dist (aβ / aβ) (bβ / bβ) β€ rβ + rβ :=
(dist_div_div_le aβ aβ bβ bβ).trans $ add_le_add hβ hβ
@[to_additive] lemma abs_dist_sub_le_dist_mul_mul (aβ aβ bβ bβ : E) :
|dist aβ bβ - dist aβ bβ| β€ dist (aβ * aβ) (bβ * bβ) :=
by simpa only [dist_mul_left, dist_mul_right, dist_comm bβ]
using abs_dist_sub_le (aβ * aβ) (bβ * bβ) (bβ * aβ)
lemma norm_multiset_sum_le {E} [seminormed_add_comm_group E] (m : multiset E) :
βm.sumβ β€ (m.map (Ξ» x, βxβ)).sum :=
m.le_sum_of_subadditive norm norm_zero norm_add_le
@[to_additive]
lemma norm_multiset_prod_le (m : multiset E) : βm.prodβ β€ (m.map $ Ξ» x, βxβ).sum :=
begin
rw [βmultiplicative.of_add_le, of_add_multiset_prod, multiset.map_map],
refine multiset.le_prod_of_submultiplicative (multiplicative.of_add β norm) _ (Ξ» x y, _) _,
{ simp only [comp_app, norm_one', of_add_zero] },
{ exact norm_mul_le' _ _ }
end
lemma norm_sum_le {E} [seminormed_add_comm_group E] (s : finset ΞΉ) (f : ΞΉ β E) :
ββ i in s, f iβ β€ β i in s, βf iβ :=
s.le_sum_of_subadditive norm norm_zero norm_add_le f
@[to_additive] lemma norm_prod_le (s : finset ΞΉ) (f : ΞΉ β E) : ββ i in s, f iβ β€ β i in s, βf iβ :=
begin
rw [βmultiplicative.of_add_le, of_add_sum],
refine finset.le_prod_of_submultiplicative (multiplicative.of_add β norm) _ (Ξ» x y, _) _ _,
{ simp only [comp_app, norm_one', of_add_zero] },
{ exact norm_mul_le' _ _ }
end
@[to_additive]
lemma norm_prod_le_of_le (s : finset ΞΉ) {f : ΞΉ β E} {n : ΞΉ β β} (h : β b β s, βf bβ β€ n b) :
ββ b in s, f bβ β€ β b in s, n b :=
(norm_prod_le s f).trans $ finset.sum_le_sum h
@[to_additive] lemma dist_prod_prod_le_of_le (s : finset ΞΉ) {f a : ΞΉ β E} {d : ΞΉ β β}
(h : β b β s, dist (f b) (a b) β€ d b) :
dist (β b in s, f b) (β b in s, a b) β€ β b in s, d b :=
by { simp only [dist_eq_norm_div, β finset.prod_div_distrib] at *, exact norm_prod_le_of_le s h }
@[to_additive] lemma dist_prod_prod_le (s : finset ΞΉ) (f a : ΞΉ β E) :
dist (β b in s, f b) (β b in s, a b) β€ β b in s, dist (f b) (a b) :=
dist_prod_prod_le_of_le s $ Ξ» _ _, le_rfl
@[to_additive] lemma mul_mem_ball_iff_norm : a * b β ball a r β βbβ < r :=
by rw [mem_ball_iff_norm'', mul_div_cancel''']
@[to_additive] lemma mul_mem_closed_ball_iff_norm : a * b β closed_ball a r β βbβ β€ r :=
by rw [mem_closed_ball_iff_norm'', mul_div_cancel''']
@[simp, to_additive] lemma preimage_mul_ball (a b : E) (r : β) :
((*) b) β»ΒΉ' ball a r = ball (a / b) r :=
by { ext c, simp only [dist_eq_norm_div, set.mem_preimage, mem_ball, div_div_eq_mul_div, mul_comm] }
@[simp, to_additive] lemma preimage_mul_closed_ball (a b : E) (r : β) :
((*) b) β»ΒΉ' (closed_ball a r) = closed_ball (a / b) r :=
by { ext c,
simp only [dist_eq_norm_div, set.mem_preimage, mem_closed_ball, div_div_eq_mul_div, mul_comm] }
@[simp, to_additive] lemma preimage_mul_sphere (a b : E) (r : β) :
((*) b) β»ΒΉ' sphere a r = sphere (a / b) r :=
by { ext c, simp only [set.mem_preimage, mem_sphere_iff_norm', div_div_eq_mul_div, mul_comm] }
@[to_additive norm_nsmul_le] lemma norm_pow_le_mul_norm (n : β) (a : E) : βa^nβ β€ n * βaβ :=
begin
induction n with n ih, { simp, },
simpa only [pow_succ', nat.cast_succ, add_mul, one_mul] using norm_mul_le_of_le ih le_rfl,
end
@[to_additive nnnorm_nsmul_le] lemma nnnorm_pow_le_mul_norm (n : β) (a : E) : βa^nββ β€ n * βaββ :=
by simpa only [β nnreal.coe_le_coe, nnreal.coe_mul, nnreal.coe_nat_cast]
using norm_pow_le_mul_norm n a
@[to_additive] lemma pow_mem_closed_ball {n : β} (h : a β closed_ball b r) :
a^n β closed_ball (b^n) (n β’ r) :=
begin
simp only [mem_closed_ball, dist_eq_norm_div, β div_pow] at h β’,
refine (norm_pow_le_mul_norm n (a / b)).trans _,
simpa only [nsmul_eq_mul] using mul_le_mul_of_nonneg_left h n.cast_nonneg,
end
@[to_additive] lemma pow_mem_ball {n : β} (hn : 0 < n) (h : a β ball b r) :
a^n β ball (b^n) (n β’ r) :=
begin
simp only [mem_ball, dist_eq_norm_div, β div_pow] at h β’,
refine lt_of_le_of_lt (norm_pow_le_mul_norm n (a / b)) _,
replace hn : 0 < (n : β), { norm_cast, assumption, },
rw nsmul_eq_mul,
nlinarith,
end
@[simp, to_additive] lemma mul_mem_closed_ball_mul_iff {c : E} :
a * c β closed_ball (b * c) r β a β closed_ball b r :=
by simp only [mem_closed_ball, dist_eq_norm_div, mul_div_mul_right_eq_div]
@[simp, to_additive] lemma mul_mem_ball_mul_iff {c : E} :
a * c β ball (b * c) r β a β ball b r :=
by simp only [mem_ball, dist_eq_norm_div, mul_div_mul_right_eq_div]
@[to_additive] lemma smul_closed_ball'' :
a β’ closed_ball b r = closed_ball (a β’ b) r :=
by { ext, simp [mem_closed_ball, set.mem_smul_set, dist_eq_norm_div, div_eq_inv_mul,
β eq_inv_mul_iff_mul_eq, mul_assoc], }
@[to_additive] lemma smul_ball'' :
a β’ ball b r = ball (a β’ b) r :=
by { ext, simp [mem_ball, set.mem_smul_set, dist_eq_norm_div, div_eq_inv_mul,
β eq_inv_mul_iff_mul_eq, mul_assoc], }
open finset
@[to_additive] lemma controlled_prod_of_mem_closure {s : subgroup E} (hg : a β closure (s : set E))
{b : β β β} (b_pos : β n, 0 < b n) :
β v : β β E,
tendsto (Ξ» n, β i in range (n+1), v i) at_top (π a) β§
(β n, v n β s) β§
βv 0 / aβ < b 0 β§
β n, 0 < n β βv nβ < b n :=
begin
obtain β¨u : β β E, u_in : β n, u n β s, lim_u : tendsto u at_top (π a)β© :=
mem_closure_iff_seq_limit.mp hg,
obtain β¨nβ, hnββ© : β nβ, β n β₯ nβ, βu n / aβ < b 0,
{ have : {x | βx / aβ < b 0} β π a,
{ simp_rw β dist_eq_norm_div,
exact metric.ball_mem_nhds _ (b_pos _) },
exact filter.tendsto_at_top'.mp lim_u _ this },
set z : β β E := Ξ» n, u (n + nβ),
have lim_z : tendsto z at_top (π a) := lim_u.comp (tendsto_add_at_top_nat nβ),
have mem_π€ : β n, {p : E Γ E | βp.1 / p.2β < b (n + 1)} β π€ E :=
Ξ» n, by simpa [β dist_eq_norm_div] using metric.dist_mem_uniformity (b_pos $ n+1),
obtain β¨Ο : β β β, Ο_extr : strict_mono Ο,
hΟ : β n, βz (Ο $ n + 1) / z (Ο n)β < b (n + 1)β© :=
lim_z.cauchy_seq.subseq_mem mem_π€,
set w : β β E := z β Ο,
have hw : tendsto w at_top (π a),
from lim_z.comp Ο_extr.tendsto_at_top,
set v : β β E := Ξ» i, if i = 0 then w 0 else w i / w (i - 1),
refine β¨v, tendsto.congr (finset.eq_prod_range_div' w) hw , _,
hnβ _ (nβ.le_add_left _), _β©,
{ rintro β¨β©,
{ change w 0 β s,
apply u_in },
{ apply s.div_mem ; apply u_in }, },
{ intros l hl,
obtain β¨k, rflβ© : β k, l = k+1, exact nat.exists_eq_succ_of_ne_zero hl.ne',
apply hΟ }
end
@[to_additive] lemma controlled_prod_of_mem_closure_range {j : E β* F} {b : F}
(hb : b β closure (j.range : set F)) {f : β β β} (b_pos : β n, 0 < f n) :
β a : β β E,
tendsto (Ξ» n, β i in range (n + 1), j (a i)) at_top (π b) β§
βj (a 0) / bβ < f 0 β§
β n, 0 < n β βj (a n)β < f n :=
begin
obtain β¨v, sum_v, v_in, hvβ, hv_posβ© := controlled_prod_of_mem_closure hb b_pos,
choose g hg using v_in,
refine β¨g, by simpa [β hg] using sum_v, by simpa [hg 0] using hvβ, Ξ» n hn,
by simpa [hg] using hv_pos n hnβ©,
end
@[to_additive] lemma nndist_mul_mul_le (aβ aβ bβ bβ : E) :
nndist (aβ * aβ) (bβ * bβ) β€ nndist aβ bβ + nndist aβ bβ :=
nnreal.coe_le_coe.1 $ dist_mul_mul_le aβ aβ bβ bβ
@[to_additive]
lemma edist_mul_mul_le (aβ aβ bβ bβ : E) : edist (aβ * aβ) (bβ * bβ) β€ edist aβ bβ + edist aβ bβ :=
by { simp only [edist_nndist], norm_cast, apply nndist_mul_mul_le }
@[to_additive]
lemma nnnorm_multiset_prod_le (m : multiset E) : βm.prodββ β€ (m.map (Ξ» x, βxββ)).sum :=
nnreal.coe_le_coe.1 $ by { push_cast, rw multiset.map_map, exact norm_multiset_prod_le _ }
@[to_additive] lemma nnnorm_prod_le (s : finset ΞΉ) (f : ΞΉ β E) :
ββ a in s, f aββ β€ β a in s, βf aββ :=
nnreal.coe_le_coe.1 $ by { push_cast, exact norm_prod_le _ _ }
@[to_additive]
lemma nnnorm_prod_le_of_le (s : finset ΞΉ) {f : ΞΉ β E} {n : ΞΉ β ββ₯0} (h : β b β s, βf bββ β€ n b) :
ββ b in s, f bββ β€ β b in s, n b :=
(norm_prod_le_of_le s h).trans_eq nnreal.coe_sum.symm
namespace real
instance : has_norm β := { norm := Ξ» r, |r| }
@[simp] lemma norm_eq_abs (r : β) : βrβ = |r| := rfl
instance : normed_add_comm_group β := β¨Ξ» r y, rflβ©
lemma norm_of_nonneg (hr : 0 β€ r) : βrβ = r := abs_of_nonneg hr
lemma norm_of_nonpos (hr : r β€ 0) : βrβ = -r := abs_of_nonpos hr
lemma le_norm_self (r : β) : r β€ βrβ := le_abs_self r
@[simp] lemma norm_coe_nat (n : β) : β(n : β)β = n := abs_of_nonneg n.cast_nonneg
@[simp] lemma nnnorm_coe_nat (n : β) : β(n : β)ββ = n := nnreal.eq $ norm_coe_nat _
@[simp] lemma norm_two : β(2 : β)β = 2 := abs_of_pos zero_lt_two
@[simp] lemma nnnorm_two : β(2 : β)ββ = 2 := nnreal.eq $ by simp
lemma nnnorm_of_nonneg (hr : 0 β€ r) : βrββ = β¨r, hrβ© := nnreal.eq $ norm_of_nonneg hr
@[simp] lemma nnnorm_abs (r : β) : β(|r|)ββ = βrββ := by simp [nnnorm]
lemma ennnorm_eq_of_real (hr : 0 β€ r) : (βrββ : ββ₯0β) = ennreal.of_real r :=
by { rw [β of_real_norm_eq_coe_nnnorm, norm_of_nonneg hr] }
lemma ennnorm_eq_of_real_abs (r : β) : (βrββ : ββ₯0β) = ennreal.of_real (|r|) :=
by rw [β real.nnnorm_abs r, real.ennnorm_eq_of_real (abs_nonneg _)]
lemma to_nnreal_eq_nnnorm_of_nonneg (hr : 0 β€ r) : r.to_nnreal = βrββ :=
begin
rw real.to_nnreal_of_nonneg hr,
congr,
rw [real.norm_eq_abs, abs_of_nonneg hr],
end
lemma of_real_le_ennnorm (r : β) : ennreal.of_real r β€ βrββ :=
begin
obtain hr | hr := le_total 0 r,
{ exact (real.ennnorm_eq_of_real hr).ge },
{ rw [ennreal.of_real_eq_zero.2 hr],
exact bot_le }
end
end real
namespace int
instance : normed_add_comm_group β€ :=
{ norm := Ξ» n, β(n : β)β,
dist_eq := Ξ» m n, by simp only [int.dist_eq, norm, int.cast_sub] }
@[norm_cast] lemma norm_cast_real (m : β€) : β(m : β)β = βmβ := rfl
lemma norm_eq_abs (n : β€) : βnβ = |n| := rfl
@[simp] lemma norm_coe_nat (n : β) : β(n : β€)β = n := by simp [int.norm_eq_abs]
lemma _root_.nnreal.coe_nat_abs (n : β€) : (n.nat_abs : ββ₯0) = βnββ :=
nnreal.eq $ calc ((n.nat_abs : ββ₯0) : β)
= (n.nat_abs : β€) : by simp only [int.cast_coe_nat, nnreal.coe_nat_cast]
... = |n| : by simp only [int.coe_nat_abs, int.cast_abs]
... = βnβ : rfl
lemma abs_le_floor_nnreal_iff (z : β€) (c : ββ₯0) : |z| β€ βcββ β βzββ β€ c :=
begin
rw [int.abs_eq_nat_abs, int.coe_nat_le, nat.le_floor_iff (zero_le c)],
congr',
exact nnreal.coe_nat_abs z,
end
end int
namespace rat
instance : normed_add_comm_group β :=
{ norm := Ξ» r, β(r : β)β,
dist_eq := Ξ» rβ rβ, by simp only [rat.dist_eq, norm, rat.cast_sub] }
@[norm_cast, simp] lemma norm_cast_real (r : β) : β(r : β)β = βrβ := rfl
@[norm_cast, simp] lemma _root_.int.norm_cast_rat (m : β€) : β(m : β)β = βmβ :=
by rw [β rat.norm_cast_real, β int.norm_cast_real]; congr' 1; norm_cast
end rat
-- Now that we've installed the norm on `β€`,
-- we can state some lemmas about `zsmul`.
section
variables [seminormed_comm_group Ξ±]
@[to_additive norm_zsmul_le]
lemma norm_zpow_le_mul_norm (n : β€) (a : Ξ±) : βa^nβ β€ βnβ * βaβ :=
by rcases n.eq_coe_or_neg with β¨n, rfl | rflβ©; simpa using norm_pow_le_mul_norm n a
@[to_additive nnnorm_zsmul_le]
lemma nnnorm_zpow_le_mul_norm (n : β€) (a : Ξ±) : βa^nββ β€ βnββ * βaββ :=
by simpa only [β nnreal.coe_le_coe, nnreal.coe_mul] using norm_zpow_le_mul_norm n a
end
namespace lipschitz_with
variables [pseudo_emetric_space Ξ±] {K Kf Kg : ββ₯0} {f g : Ξ± β E}
@[to_additive] lemma inv (hf : lipschitz_with K f) : lipschitz_with K (Ξ» x, (f x)β»ΒΉ) :=
Ξ» x y, (edist_inv_inv _ _).trans_le $ hf x y
@[to_additive add] lemma mul' (hf : lipschitz_with Kf f) (hg : lipschitz_with Kg g) :
lipschitz_with (Kf + Kg) (Ξ» x, f x * g x) :=
Ξ» x y, calc
edist (f x * g x) (f y * g y) β€ edist (f x) (f y) + edist (g x) (g y) : edist_mul_mul_le _ _ _ _
... β€ Kf * edist x y + Kg * edist x y : add_le_add (hf x y) (hg x y)
... = (Kf + Kg) * edist x y : (add_mul _ _ _).symm
@[to_additive] lemma div (hf : lipschitz_with Kf f) (hg : lipschitz_with Kg g) :
lipschitz_with (Kf + Kg) (Ξ» x, f x / g x) :=
by simpa only [div_eq_mul_inv] using hf.mul' hg.inv
end lipschitz_with
namespace antilipschitz_with
variables [pseudo_emetric_space Ξ±] {K Kf Kg : ββ₯0} {f g : Ξ± β E}
@[to_additive] lemma mul_lipschitz_with (hf : antilipschitz_with Kf f) (hg : lipschitz_with Kg g)
(hK : Kg < Kfβ»ΒΉ) : antilipschitz_with (Kfβ»ΒΉ - Kg)β»ΒΉ (Ξ» x, f x * g x) :=
begin
letI : pseudo_metric_space Ξ± := pseudo_emetric_space.to_pseudo_metric_space hf.edist_ne_top,
refine antilipschitz_with.of_le_mul_dist (Ξ» x y, _),
rw [nnreal.coe_inv, β div_eq_inv_mul],
rw le_div_iff (nnreal.coe_pos.2 $ tsub_pos_iff_lt.2 hK),
rw [mul_comm, nnreal.coe_sub hK.le, sub_mul],
calc βKfβ»ΒΉ * dist x y - Kg * dist x y β€ dist (f x) (f y) - dist (g x) (g y) :
sub_le_sub (hf.mul_le_dist x y) (hg.dist_le_mul x y)
... β€ _ : le_trans (le_abs_self _) (abs_dist_sub_le_dist_mul_mul _ _ _ _),
end
@[to_additive] lemma mul_div_lipschitz_with (hf : antilipschitz_with Kf f)
(hg : lipschitz_with Kg (g / f)) (hK : Kg < Kfβ»ΒΉ) : antilipschitz_with (Kfβ»ΒΉ - Kg)β»ΒΉ g :=
by simpa only [pi.div_apply, mul_div_cancel'_right] using hf.mul_lipschitz_with hg hK
@[to_additive] lemma le_mul_norm_div {f : E β F} (hf : antilipschitz_with K f) (x y : E) :
βx / yβ β€ K * βf x / f yβ :=
by simp [β dist_eq_norm_div, hf.le_mul_dist x y]
end antilipschitz_with
@[priority 100, to_additive] -- See note [lower instance priority]
instance seminormed_comm_group.to_has_lipschitz_mul : has_lipschitz_mul E :=
β¨β¨1 + 1, lipschitz_with.prod_fst.mul' lipschitz_with.prod_sndβ©β©
/-- A seminormed group is a uniform group, i.e., multiplication and division are uniformly
continuous. -/
@[priority 100, to_additive "A seminormed group is a uniform additive group, i.e., addition and
subtraction are uniformly continuous."] -- See note [lower instance priority]
instance seminormed_comm_group.to_uniform_group : uniform_group E :=
β¨(lipschitz_with.prod_fst.div lipschitz_with.prod_snd).uniform_continuousβ©
-- short-circuit type class inference
@[priority 100, to_additive] -- See note [lower instance priority]
instance seminormed_comm_group.to_topological_group : topological_group E := infer_instance
@[to_additive] lemma cauchy_seq_prod_of_eventually_eq {u v : β β E} {N : β}
(huv : β n β₯ N, u n = v n) (hv : cauchy_seq (Ξ» n, β k in range (n+1), v k)) :
cauchy_seq (Ξ» n, β k in range (n + 1), u k) :=
begin
let d : β β E := Ξ» n, β k in range (n + 1), (u k / v k),
rw show (Ξ» n, β k in range (n + 1), u k) = d * (Ξ» n, β k in range (n + 1), v k),
by { ext n, simp [d] },
suffices : β n β₯ N, d n = d N,
{ exact (tendsto_at_top_of_eventually_const this).cauchy_seq.mul hv },
intros n hn,
dsimp [d],
rw eventually_constant_prod _ hn,
intros m hm,
simp [huv m hm],
end
end seminormed_comm_group
section normed_group
variables [normed_group E] [normed_group F] {a b : E}
@[simp, to_additive norm_eq_zero] lemma norm_eq_zero'' : βaβ = 0 β a = 1 := norm_eq_zero'''
@[to_additive norm_ne_zero_iff] lemma norm_ne_zero_iff' : βaβ β 0 β a β 1 := norm_eq_zero''.not
@[simp, to_additive norm_pos_iff] lemma norm_pos_iff'' : 0 < βaβ β a β 1 := norm_pos_iff'''
@[simp, to_additive norm_le_zero_iff]
lemma norm_le_zero_iff'' : βaβ β€ 0 β a = 1 := norm_le_zero_iff'''
@[to_additive]
lemma norm_div_eq_zero_iff : βa / bβ = 0 β a = b := by rw [norm_eq_zero'', div_eq_one]
@[to_additive] lemma norm_div_pos_iff : 0 < βa / bβ β a β b :=
by { rw [(norm_nonneg' _).lt_iff_ne, ne_comm], exact norm_div_eq_zero_iff.not }
@[to_additive] lemma eq_of_norm_div_le_zero (h : βa / bβ β€ 0) : a = b :=
by rwa [βdiv_eq_one, β norm_le_zero_iff'']
alias norm_div_eq_zero_iff β eq_of_norm_div_eq_zero _
attribute [to_additive] eq_of_norm_div_eq_zero
@[simp, to_additive nnnorm_eq_zero] lemma nnnorm_eq_zero' : βaββ = 0 β a = 1 :=
by rw [β nnreal.coe_eq_zero, coe_nnnorm', norm_eq_zero'']
@[to_additive nnnorm_ne_zero_iff]
lemma nnnorm_ne_zero_iff' : βaββ β 0 β a β 1 := nnnorm_eq_zero'.not
@[to_additive]
lemma tendsto_norm_div_self_punctured_nhds (a : E) : tendsto (Ξ» x, βx / aβ) (π[β ] a) (π[>] 0) :=
(tendsto_norm_div_self a).inf $ tendsto_principal_principal.2 $ Ξ» x hx, norm_pos_iff''.2 $
div_ne_one.2 hx
@[to_additive] lemma tendsto_norm_nhds_within_one : tendsto (norm : E β β) (π[β ] 1) (π[>] 0) :=
tendsto_norm_one.inf $ tendsto_principal_principal.2 $ Ξ» x, norm_pos_iff''.2
variables (E)
/-- The norm of a normed group as a group norm. -/
@[to_additive "The norm of a normed group as an additive group norm."]
def norm_group_norm : group_norm E :=
{ eq_one_of_map_eq_zero' := Ξ» _, norm_eq_zero''.1, ..norm_group_seminorm _ }
@[simp] lemma coe_norm_group_norm : β(norm_group_norm E) = norm := rfl
end normed_group
section normed_add_group
variables [normed_add_group E] [topological_space Ξ±] {f : Ξ± β E}
/-! Some relations with `has_compact_support` -/
lemma has_compact_support_norm_iff : has_compact_support (Ξ» x, βf xβ) β has_compact_support f :=
has_compact_support_comp_left $ Ξ» x, norm_eq_zero
alias has_compact_support_norm_iff β _ has_compact_support.norm
lemma continuous.bounded_above_of_compact_support (hf : continuous f) (h : has_compact_support f) :
β C, β x, βf xβ β€ C :=
by simpa [bdd_above_def] using hf.norm.bdd_above_range_of_has_compact_support h.norm
end normed_add_group
section normed_add_group_source
variables [normed_add_group Ξ±] {f : Ξ± β E}
@[to_additive]
lemma has_compact_mul_support.exists_pos_le_norm [has_one E] (hf : has_compact_mul_support f) :
β (R : β), (0 < R) β§ (β (x : Ξ±), (R β€ βxβ) β (f x = 1)) :=
begin
obtain β¨K, β¨hK1, hK2β©β© := exists_compact_iff_has_compact_mul_support.mpr hf,
obtain β¨S, hS, hS'β© := hK1.bounded.exists_pos_norm_le,
refine β¨S + 1, by positivity, Ξ» x hx, hK2 x ((mt $ hS' x) _)β©,
contrapose! hx,
exact lt_add_of_le_of_pos hx zero_lt_one
end
end normed_add_group_source
/-! ### `ulift` -/
namespace ulift
section has_norm
variables [has_norm E]
instance : has_norm (ulift E) := β¨Ξ» x, βx.downββ©
lemma norm_def (x : ulift E) : βxβ = βx.downβ := rfl
@[simp] lemma norm_up (x : E) : βulift.up xβ = βxβ := rfl
@[simp] lemma norm_down (x : ulift E) : βx.downβ = βxβ := rfl
end has_norm
section has_nnnorm
variables [has_nnnorm E]
instance : has_nnnorm (ulift E) := β¨Ξ» x, βx.downβββ©
lemma nnnorm_def (x : ulift E) : βxββ = βx.downββ := rfl
@[simp] lemma nnnorm_up (x : E) : βulift.up xββ = βxββ := rfl
@[simp] lemma nnnorm_down (x : ulift E) : βx.downββ = βxββ := rfl
end has_nnnorm
@[to_additive] instance seminormed_group [seminormed_group E] : seminormed_group (ulift E) :=
seminormed_group.induced _ _ (β¨ulift.down, rfl, Ξ» _ _, rflβ© : ulift E β* E)
@[to_additive]
instance seminormed_comm_group [seminormed_comm_group E] : seminormed_comm_group (ulift E) :=
seminormed_comm_group.induced _ _ (β¨ulift.down, rfl, Ξ» _ _, rflβ© : ulift E β* E)
@[to_additive] instance normed_group [normed_group E] : normed_group (ulift E) :=
normed_group.induced _ _ (β¨ulift.down, rfl, Ξ» _ _, rflβ© : ulift E β* E) down_injective
@[to_additive]
instance normed_comm_group [normed_comm_group E] : normed_comm_group (ulift E) :=
normed_comm_group.induced _ _ (β¨ulift.down, rfl, Ξ» _ _, rflβ© : ulift E β* E) down_injective
end ulift
/-! ### `additive`, `multiplicative` -/
section additive_multiplicative
open additive multiplicative
section has_norm
variables [has_norm E]
instance : has_norm (additive E) := βΉhas_norm EβΊ
instance : has_norm (multiplicative E) := βΉhas_norm EβΊ
@[simp] lemma norm_to_mul (x) : β(to_mul x : E)β = βxβ := rfl
@[simp] lemma norm_of_mul (x : E) : βof_mul xβ = βxβ := rfl
@[simp] lemma norm_to_add (x) : β(to_add x : E)β = βxβ := rfl
@[simp] lemma norm_of_add (x : E) : βof_add xβ = βxβ := rfl
end has_norm
section has_nnnorm
variables [has_nnnorm E]
instance : has_nnnorm (additive E) := βΉhas_nnnorm EβΊ
instance : has_nnnorm (multiplicative E) := βΉhas_nnnorm EβΊ
@[simp] lemma nnnorm_to_mul (x) : β(to_mul x : E)ββ = βxββ := rfl
@[simp] lemma nnnorm_of_mul (x : E) : βof_mul xββ = βxββ := rfl
@[simp] lemma nnnorm_to_add (x) : β(to_add x : E)ββ = βxββ := rfl
@[simp] lemma nnnorm_of_add (x : E) : βof_add xββ = βxββ := rfl
end has_nnnorm
instance [seminormed_group E] : seminormed_add_group (additive E) :=
{ dist_eq := dist_eq_norm_div }
instance [seminormed_add_group E] : seminormed_group (multiplicative E) :=
{ dist_eq := dist_eq_norm_sub }
instance [seminormed_comm_group E] : seminormed_add_comm_group (additive E) :=
{ ..additive.seminormed_add_group }
instance [seminormed_add_comm_group E] : seminormed_comm_group (multiplicative E) :=
{ ..multiplicative.seminormed_group }
instance [normed_group E] : normed_add_group (additive E) :=
{ ..additive.seminormed_add_group }
instance [normed_add_group E] : normed_group (multiplicative E) :=
{ ..multiplicative.seminormed_group }
instance [normed_comm_group E] : normed_add_comm_group (additive E) :=
{ ..additive.seminormed_add_group }
instance [normed_add_comm_group E] : normed_comm_group (multiplicative E) :=
{ ..multiplicative.seminormed_group }
end additive_multiplicative
/-! ### Order dual -/
section order_dual
open order_dual
section has_norm
variables [has_norm E]
instance : has_norm Eα΅α΅ := βΉhas_norm EβΊ
@[simp] lemma norm_to_dual (x : E) : βto_dual xβ = βxβ := rfl
@[simp] lemma norm_of_dual (x : Eα΅α΅) : βof_dual xβ = βxβ := rfl
end has_norm
section has_nnnorm
variables [has_nnnorm E]
instance : has_nnnorm Eα΅α΅ := βΉhas_nnnorm EβΊ
@[simp] lemma nnnorm_to_dual (x : E) : βto_dual xββ = βxββ := rfl
@[simp] lemma nnnorm_of_dual (x : Eα΅α΅) : βof_dual xββ = βxββ := rfl
end has_nnnorm
@[priority 100, to_additive] -- See note [lower instance priority]
instance [seminormed_group E] : seminormed_group Eα΅α΅ := βΉseminormed_group EβΊ
@[priority 100, to_additive] -- See note [lower instance priority]
instance [seminormed_comm_group E] : seminormed_comm_group Eα΅α΅ := βΉseminormed_comm_group EβΊ
@[priority 100, to_additive] -- See note [lower instance priority]
instance [normed_group E] : normed_group Eα΅α΅ := βΉnormed_group EβΊ
@[priority 100, to_additive] -- See note [lower instance priority]
instance [normed_comm_group E] : normed_comm_group Eα΅α΅ := βΉnormed_comm_group EβΊ
end order_dual
/-! ### Binary product of normed groups -/
section has_norm
variables [has_norm E] [has_norm F] {x : E Γ F} {r : β}
instance : has_norm (E Γ F) := β¨Ξ» x, βx.1β β βx.2ββ©
lemma prod.norm_def (x : E Γ F) : βxβ = (max βx.1β βx.2β) := rfl
lemma norm_fst_le (x : E Γ F) : βx.1β β€ βxβ := le_max_left _ _
lemma norm_snd_le (x : E Γ F) : βx.2β β€ βxβ := le_max_right _ _
lemma norm_prod_le_iff : βxβ β€ r β βx.1β β€ r β§ βx.2β β€ r := max_le_iff
end has_norm
section seminormed_group
variables [seminormed_group E] [seminormed_group F]
/-- Product of seminormed groups, using the sup norm. -/
@[to_additive "Product of seminormed groups, using the sup norm."]
instance : seminormed_group (E Γ F) :=
β¨Ξ» x y, by simp only [prod.norm_def, prod.dist_eq, dist_eq_norm_div, prod.fst_div, prod.snd_div]β©
@[to_additive prod.nnnorm_def']
lemma prod.nnorm_def (x : E Γ F) : βxββ = (max βx.1ββ βx.2ββ) := rfl
end seminormed_group
/-- Product of seminormed groups, using the sup norm. -/
@[to_additive "Product of seminormed groups, using the sup norm."]
instance [seminormed_comm_group E] [seminormed_comm_group F] : seminormed_comm_group (E Γ F) :=
{ ..prod.seminormed_group }
/-- Product of normed groups, using the sup norm. -/
@[to_additive "Product of normed groups, using the sup norm."]
instance [normed_group E] [normed_group F] : normed_group (E Γ F) := { ..prod.seminormed_group }
/-- Product of normed groups, using the sup norm. -/
@[to_additive "Product of normed groups, using the sup norm."]
instance [normed_comm_group E] [normed_comm_group F] : normed_comm_group (E Γ F) :=
{ ..prod.seminormed_group }
/-! ### Finite product of normed groups -/
section pi
variables {Ο : ΞΉ β Type*} [fintype ΞΉ]
section seminormed_group
variables [Ξ i, seminormed_group (Ο i)] [seminormed_group E] (f : Ξ i, Ο i) {x : Ξ i, Ο i} {r : β}
/-- Finite product of seminormed groups, using the sup norm. -/
@[to_additive "Finite product of seminormed groups, using the sup norm."]
instance : seminormed_group (Ξ i, Ο i) :=
{ norm := Ξ» f, β(finset.univ.sup (Ξ» b, βf bββ)),
dist_eq := Ξ» x y,
congr_arg (coe : ββ₯0 β β) $ congr_arg (finset.sup finset.univ) $ funext $ Ξ» a,
show nndist (x a) (y a) = βx a / y aββ, from nndist_eq_nnnorm_div (x a) (y a) }
@[to_additive pi.norm_def] lemma pi.norm_def' : βfβ = β(finset.univ.sup (Ξ» b, βf bββ)) := rfl
@[to_additive pi.nnnorm_def] lemma pi.nnnorm_def' : βfββ = finset.univ.sup (Ξ» b, βf bββ) :=
subtype.eta _ _
/-- The seminorm of an element in a product space is `β€ r` if and only if the norm of each
component is. -/
@[to_additive pi_norm_le_iff_of_nonneg "The seminorm of an element in a product space is `β€ r` if
and only if the norm of each component is."]
lemma pi_norm_le_iff_of_nonneg' (hr : 0 β€ r) : βxβ β€ r β β i, βx iβ β€ r :=
by simp only [βdist_one_right, dist_pi_le_iff hr, pi.one_apply]
@[to_additive pi_nnnorm_le_iff]
lemma pi_nnnorm_le_iff' {r : ββ₯0} : βxββ β€ r β β i, βx iββ β€ r :=
pi_norm_le_iff_of_nonneg' r.coe_nonneg
@[to_additive pi_norm_le_iff_of_nonempty]
lemma pi_norm_le_iff_of_nonempty' [nonempty ΞΉ] : βfβ β€ r β β b, βf bβ β€ r :=
begin
by_cases hr : 0 β€ r,
{ exact pi_norm_le_iff_of_nonneg' hr },
{ exact iff_of_false (Ξ» h, hr $ (norm_nonneg' _).trans h)
(Ξ» h, hr $ (norm_nonneg' _).trans $ h $ classical.arbitrary _) }
end
/-- The seminorm of an element in a product space is `< r` if and only if the norm of each
component is. -/
@[to_additive pi_norm_lt_iff "The seminorm of an element in a product space is `< r` if and only if
the norm of each component is."]
lemma pi_norm_lt_iff' (hr : 0 < r) : βxβ < r β β i, βx iβ < r :=
by simp only [βdist_one_right, dist_pi_lt_iff hr, pi.one_apply]
@[to_additive pi_nnnorm_lt_iff]
lemma pi_nnnorm_lt_iff' {r : ββ₯0} (hr : 0 < r) : βxββ < r β β i, βx iββ < r := pi_norm_lt_iff' hr
@[to_additive norm_le_pi_norm]
lemma norm_le_pi_norm' (i : ΞΉ) : βf iβ β€ βfβ :=
(pi_norm_le_iff_of_nonneg' $ norm_nonneg' _).1 le_rfl i
@[to_additive nnnorm_le_pi_nnnorm]
lemma nnnorm_le_pi_nnnorm' (i : ΞΉ) : βf iββ β€ βfββ := norm_le_pi_norm' _ i
@[to_additive pi_norm_const_le]
lemma pi_norm_const_le' (a : E) : β(Ξ» _ : ΞΉ, a)β β€ βaβ :=
(pi_norm_le_iff_of_nonneg' $ norm_nonneg' _).2 $ Ξ» _, le_rfl
@[to_additive pi_nnnorm_const_le]
lemma pi_nnnorm_const_le' (a : E) : β(Ξ» _ : ΞΉ, a)ββ β€ βaββ := pi_norm_const_le' _
@[simp, to_additive pi_norm_const]
lemma pi_norm_const' [nonempty ΞΉ] (a : E) : β(Ξ» i : ΞΉ, a)β = βaβ :=
by simpa only [βdist_one_right] using dist_pi_const a 1
@[simp, to_additive pi_nnnorm_const]
lemma pi_nnnorm_const' [nonempty ΞΉ] (a : E) : β(Ξ» i : ΞΉ, a)ββ = βaββ := nnreal.eq $ pi_norm_const' a
/-- The $L^1$ norm is less than the $L^\infty$ norm scaled by the cardinality. -/
@[to_additive pi.sum_norm_apply_le_norm "The $L^1$ norm is less than the $L^\\infty$ norm scaled by
the cardinality."]
lemma pi.sum_norm_apply_le_norm' : β i, βf iβ β€ fintype.card ΞΉ β’ βfβ :=
finset.sum_le_card_nsmul _ _ _ $ Ξ» i hi, norm_le_pi_norm' _ i
/-- The $L^1$ norm is less than the $L^\infty$ norm scaled by the cardinality. -/
@[to_additive pi.sum_nnnorm_apply_le_nnnorm "The $L^1$ norm is less than the $L^\\infty$ norm scaled
by the cardinality."]
lemma pi.sum_nnnorm_apply_le_nnnorm' : β i, βf iββ β€ fintype.card ΞΉ β’ βfββ :=
nnreal.coe_sum.trans_le $ pi.sum_norm_apply_le_norm' _
end seminormed_group
/-- Finite product of seminormed groups, using the sup norm. -/
@[to_additive "Finite product of seminormed groups, using the sup norm."]
instance pi.seminormed_comm_group [Ξ i, seminormed_comm_group (Ο i)] :
seminormed_comm_group (Ξ i, Ο i) :=
{ ..pi.seminormed_group }
/-- Finite product of normed groups, using the sup norm. -/
@[to_additive "Finite product of seminormed groups, using the sup norm."]
instance pi.normed_group [Ξ i, normed_group (Ο i)] : normed_group (Ξ i, Ο i) :=
{ ..pi.seminormed_group }
/-- Finite product of normed groups, using the sup norm. -/
@[to_additive "Finite product of seminormed groups, using the sup norm."]
instance pi.normed_comm_group [Ξ i, normed_comm_group (Ο i)] : normed_comm_group (Ξ i, Ο i) :=
{ ..pi.seminormed_group }
end pi
/-! ### Multiplicative opposite -/
namespace mul_opposite
/-- The (additive) norm on the multiplicative opposite is the same as the norm on the original type.
Note that we do not provide this more generally as `has_norm Eα΅α΅α΅`, as this is not always a good
choice of norm in the multiplicative `seminormed_group E` case.
We could repeat this instance to provide a `[seminormed_group E] : seminormed_group Eα΅α΅α΅` instance,
but that case would likely never be used.
-/
instance [seminormed_add_group E] : seminormed_add_group Eα΅α΅α΅ :=
{ norm := Ξ» x, βx.unopβ,
dist_eq := Ξ» _ _, dist_eq_norm _ _,
to_pseudo_metric_space := mul_opposite.pseudo_metric_space }
lemma norm_op [seminormed_add_group E] (a : E) : βmul_opposite.op aβ = βaβ := rfl
lemma norm_unop [seminormed_add_group E] (a : Eα΅α΅α΅) : βmul_opposite.unop aβ = βaβ := rfl
lemma nnnorm_op [seminormed_add_group E] (a : E) : βmul_opposite.op aββ = βaββ := rfl
lemma nnnorm_unop [seminormed_add_group E] (a : Eα΅α΅α΅) : βmul_opposite.unop aββ = βaββ := rfl
instance [normed_add_group E] : normed_add_group Eα΅α΅α΅ :=
{ .. mul_opposite.seminormed_add_group }
instance [seminormed_add_comm_group E] : seminormed_add_comm_group Eα΅α΅α΅ :=
{ dist_eq := Ξ» _ _, dist_eq_norm _ _ }
instance [normed_add_comm_group E] : normed_add_comm_group Eα΅α΅α΅ :=
{ .. mul_opposite.seminormed_add_comm_group }
end mul_opposite
/-! ### Subgroups of normed groups -/
namespace subgroup
section seminormed_group
variables [seminormed_group E] {s : subgroup E}
/-- A subgroup of a seminormed group is also a seminormed group,
with the restriction of the norm. -/
@[to_additive "A subgroup of a seminormed group is also a seminormed group,
with the restriction of the norm."]
instance seminormed_group : seminormed_group s := seminormed_group.induced _ _ s.subtype
/-- If `x` is an element of a subgroup `s` of a seminormed group `E`, its norm in `s` is equal to
its norm in `E`. -/
@[simp, to_additive "If `x` is an element of a subgroup `s` of a seminormed group `E`, its norm in
`s` is equal to its norm in `E`."]
lemma coe_norm (x : s) : βxβ = β(x : E)β := rfl
/-- If `x` is an element of a subgroup `s` of a seminormed group `E`, its norm in `s` is equal to
its norm in `E`.
This is a reversed version of the `simp` lemma `subgroup.coe_norm` for use by `norm_cast`. -/
@[norm_cast, to_additive "If `x` is an element of a subgroup `s` of a seminormed group `E`, its norm
in `s` is equal to its norm in `E`.
This is a reversed version of the `simp` lemma `add_subgroup.coe_norm` for use by `norm_cast`."]
lemma norm_coe {s : subgroup E} (x : s) : β(x : E)β = βxβ := rfl
end seminormed_group
@[to_additive] instance seminormed_comm_group [seminormed_comm_group E] {s : subgroup E} :
seminormed_comm_group s :=
seminormed_comm_group.induced _ _ s.subtype
@[to_additive] instance normed_group [normed_group E] {s : subgroup E} : normed_group s :=
normed_group.induced _ _ s.subtype subtype.coe_injective
@[to_additive]
instance normed_comm_group [normed_comm_group E] {s : subgroup E} : normed_comm_group s :=
normed_comm_group.induced _ _ s.subtype subtype.coe_injective
end subgroup
/-! ### Submodules of normed groups -/
namespace submodule
/-- A submodule of a seminormed group is also a seminormed group, with the restriction of the norm.
-/
-- See note [implicit instance arguments]
instance seminormed_add_comm_group {_ : ring π} [seminormed_add_comm_group E] {_ : module π E}
(s : submodule π E) :
seminormed_add_comm_group s :=
seminormed_add_comm_group.induced _ _ s.subtype.to_add_monoid_hom
/-- If `x` is an element of a submodule `s` of a normed group `E`, its norm in `s` is equal to its
norm in `E`. -/
-- See note [implicit instance arguments].
@[simp] lemma coe_norm {_ : ring π} [seminormed_add_comm_group E] {_ : module π E}
{s : submodule π E} (x : s) :
βxβ = β(x : E)β := rfl
/-- If `x` is an element of a submodule `s` of a normed group `E`, its norm in `E` is equal to its
norm in `s`.
This is a reversed version of the `simp` lemma `submodule.coe_norm` for use by `norm_cast`. -/
-- See note [implicit instance arguments].
@[norm_cast] lemma norm_coe {_ : ring π} [seminormed_add_comm_group E] {_ : module π E}
{s : submodule π E} (x : s) :
β(x : E)β = βxβ := rfl
/-- A submodule of a normed group is also a normed group, with the restriction of the norm. -/
-- See note [implicit instance arguments].
instance {_ : ring π} [normed_add_comm_group E] {_ : module π E} (s : submodule π E) :
normed_add_comm_group s :=
{ ..submodule.seminormed_add_comm_group s }
end submodule
|
c77329e29d73e40a61aa6bbc112c0cbe5cd0548a | 4fa118f6209450d4e8d058790e2967337811b2b5 | /src/adic_space.lean | c8b1b904ed1e6305002c66eeca6623b9999af639 | [
"Apache-2.0"
] | permissive | leanprover-community/lean-perfectoid-spaces | 16ab697a220ed3669bf76311daa8c466382207f7 | 95a6520ce578b30a80b4c36e36ab2d559a842690 | refs/heads/master | 1,639,557,829,139 | 1,638,797,866,000 | 1,638,797,866,000 | 135,769,296 | 96 | 10 | Apache-2.0 | 1,638,797,866,000 | 1,527,892,754,000 | Lean | UTF-8 | Lean | false | false | 10,901 | lean | import algebra.group_power
import topology.algebra.ring
import topology.opens
import category_theory.category
import category_theory.full_subcategory
import for_mathlib.open_embeddings
import for_mathlib.topological_groups
import sheaves.f_map
import Spa.stalk_valuation
/-!
# Adic spaces
Adic spaces were introduced by Huber in [Huber]. They form a very general category of objects
suitable for p-adic geometry.
In this file we define the category of adic spaces. The category of schemes (from algebraic
geometry) may provide some useful intuition for the definition.
One defines the category of βringed spacesβ, and for every commutative ring R
a ringed space Spec(R). A scheme is a ringed space that admits a cover by subspaces that
are isomorphic to spaces of the form Spec(R) for some ring R.
Similarly, for adic spaces we need two ingredients: a category CLVRS,
and the so-called βadic spectrumβ Spa(_), which is defined in Spa.lean.
An adic space is an object of CLVRS is that admits a cover by subspaces of the form Spa(A).
The main bulk of this file consists in setting up the category that we called CLVRS,
and that never got a proper name in the literature. (For example, Wedhorn calls this category `π±`.)
CLVRS (complete locally valued ringed space) is the category of topological spaces endowed
with a sheaf of complete topological rings and (an equivalence class of) valuations on the stalks
(which are required to be local rings; moreover the support of the valuation must be
the maximal ideal of the stalk).
Once we have the category CLVRS in place, the definition of adic spaces is made in
a couple of lines.
-/
universe u
open nat function
open topological_space
open spa
open_locale classical
/-- A convenient auxiliary category whose objects are topological spaces equipped with
a presheaf of topological rings and on each stalk (considered as abstract ring) an
equivalence class of valuations. The point of this category is that the local isomorphism
between a general adic space and an affinoid model Spa(A) can be checked in this category.
-/
structure PreValuedRingedSpace :=
(space : Type u)
[top : topological_space space]
(presheaf : presheaf_of_topological_rings.{u u} space)
(valuation : β x : space, Spv (stalk_of_rings presheaf.to_presheaf_of_rings x))
namespace PreValuedRingedSpace
variables (X : PreValuedRingedSpace.{u})
/-- Coercion from a PreValuedRingedSpace to the underlying topological space.-/
instance : has_coe_to_sort PreValuedRingedSpace.{u} :=
{ S := Type u,
coe := Ξ» X, X.space }
/-- The topology on the underlying space of a PreValuedRingedSpace.-/
instance : topological_space X := X.top
end PreValuedRingedSpace
/- Remainder of this file:
* Morphisms and isomorphisms in PreValuedRingedSpace.
* Open set in X -> restrict structure to obtain object of PreValuedRingedSpace
* Definition of adic space
* A morphism in PreValuedRingedSpace is a map of topological spaces,
and an f-map of presheaves, such that the induced
map on the stalks pulls one valuation back to the other.
-/
namespace PreValuedRingedSpace
open category_theory
/-- A morphism of pre-valued ringed spaces is a morphism of the structure presheaves
(of topological rings, hence *continuous* on sections),
such that for every point x in the domain the induced map on stalks pulls valuation on the stalk
back to the valuation of the stalk on the image of x.-/
structure hom (X Y : PreValuedRingedSpace.{u}) :=
(fmap : presheaf_of_topological_rings.f_map X.presheaf Y.presheaf)
(stalk : β x : X,
Spv.comap (stalk_map fmap.to_presheaf_of_rings_f_map x) (X.valuation x) = Y.valuation (fmap.f x))
attribute [simp] hom.stalk
/-- A morphism of pre-valued ringed spaces is determined by the data
of the morphism of the structure presheaves.-/
@[ext]
lemma hom_ext {X Y : PreValuedRingedSpace.{u}} (f g : hom X Y) :
f.fmap = g.fmap β f = g :=
by { cases f, cases g, tidy }
/--The identity morphism of a pre-valued ringed space.-/
def id (X : PreValuedRingedSpace.{u}) : hom X X :=
{ fmap := presheaf_of_topological_rings.f_map_id _,
stalk := Ξ» x, by { dsimp, simp, } }
@[simp] lemma id_fmap {X : PreValuedRingedSpace} :
(id X).fmap = presheaf_of_topological_rings.f_map_id _ := rfl
/--The composition of morphisms of pre-valued ringed spaces.-/
def comp {X Y Z : PreValuedRingedSpace.{u}} (f : hom X Y) (g : hom Y Z) : hom X Z :=
{ fmap := f.fmap.comp g.fmap,
stalk := Ξ» x,
begin
dsimp, simp only [comp_app, stalk_map.stalk_map_comp', hom.stalk, Spv.comap_comp],
dsimp, simp only [hom.stalk],
end }
/--Pre-valued ringed spaces form a large category.-/
instance large_category : large_category (PreValuedRingedSpace.{u}) :=
{ hom := hom,
id := id,
comp := Ξ» X Y Z f g, comp f g,
id_comp' :=
begin
intros X Y f, ext, dsimp [comp],
exact presheaf_of_rings.f_map.id_comp _,
end,
comp_id' :=
begin
intros X Y f, ext, dsimp [comp],
exact presheaf_of_rings.f_map.comp_id _,
end }
end PreValuedRingedSpace
/--If U is an open subset of a pre-valued ringed space X, then there is a natural way
to view U as a pre-valued ringed space by restricting the structure presheaf from X.-/
noncomputable instance PreValuedRingedSpace.restrict {X : PreValuedRingedSpace.{u}} :
has_coe (opens X) PreValuedRingedSpace :=
{ coe := Ξ» U,
{ space := U,
top := by apply_instance,
presheaf := presheaf_of_topological_rings.restrict U X.presheaf,
valuation :=
Ξ» u, Spv.mk (valuation.comap (presheaf_of_rings.restrict_stalk_map _ _) (X.valuation u).out) } }
namespace sheaf_of_topological_rings
/-- The sections of a sheaf of topological rings form a uniform space.
When this is made an instance, beware of diamonds.-/
def uniform_space {X : Type u} [topological_space X] (πͺX : sheaf_of_topological_rings X)
(U : opens X) : uniform_space (πͺX.F.F U) :=
topological_add_group.to_uniform_space (πͺX.F.F U)
end sheaf_of_topological_rings
section
local attribute [instance] sheaf_of_topological_rings.uniform_space
/--Category of topological spaces endowed with a sheaf of complete topological rings
and (an equivalence class of) valuations on the stalks (which are required to be local
rings; moreover the support of the valuation must be the maximal ideal of the stalk).
Wedhorn calls this category `π±`.-/
structure CLVRS :=
(space : Type) -- change this to (Type u) to enable universes
[top : topological_space space]
(sheaf' : sheaf_of_topological_rings.{0 0} space)
(complete : β U : opens space, complete_space (sheaf'.F.F U))
(valuation : β x : space, Spv (stalk_of_rings sheaf'.to_presheaf_of_topological_rings.to_presheaf_of_rings x))
(local_stalks : β x : space, is_local_ring (stalk_of_rings sheaf'.to_presheaf_of_rings x))
(supp_maximal : β x : space, ideal.is_maximal (valuation x).supp)
end
namespace CLVRS
open category_theory
attribute [instance] top
/--A CLVRS is naturally a pre-valued ringed space.-/
def to_PreValuedRingedSpace (X : CLVRS) : PreValuedRingedSpace.{0} :=
{ presheaf := sheaf_of_topological_rings.to_presheaf_of_topological_rings X.sheaf',
..X }
/--The coercion from a CLVRS to a pre-valued ringed space.-/
instance : has_coe CLVRS PreValuedRingedSpace.{0} :=
β¨to_PreValuedRingedSpaceβ©
/-- The topology on the underlying space of a CLVRS. -/
instance (X : CLVRS) : topological_space X := X.top
/-- The structure sheaf of a CLVRS. -/
def sheaf (X : CLVRS) : sheaf_of_topological_rings X := X.sheaf'
/--CLVRS is a full subcategory of PreValuedRingedSpace.-/
instance : large_category CLVRS := induced_category.category to_PreValuedRingedSpace
variables {X Y : CLVRS} (f : X βΆ Y) (x : X)
/-- The underlying morphism of structure presheaves of a morphism of CLVRSs.-/
def fmap : presheaf_of_rings.f_map _ _:=
(PreValuedRingedSpace.hom.fmap f).to_presheaf_of_rings_f_map
/-- The coercion of a morphims of CLVRSs to the map between the underlying topological spaces.-/
instance : has_coe_to_fun (X βΆ Y) :=
{ F := Ξ» f, X β Y,
coe := Ξ» f, (fmap f).f }
/-- The stalk of the structure sheaf at a point of a CLVRS.-/
def stalk (X : CLVRS) := stalk_of_rings (X.sheaf.to_presheaf_of_rings)
/-- The ring structure on the stalk of the structure sheaf of a CLVRS. -/
instance stalk.comm_ring : comm_ring (X.stalk x) := stalk_of_rings_is_comm_ring _ _
/-- The stalk of the structure sheaf of a CLVRS is a local ring. -/
instance stalk.is_local_ring : local_ring (X.stalk x) :=
local_of_is_local_ring $ X.local_stalks x
/-- The ring homomorphism on the stalks induced by a morphism of CLVRSs.-/
noncomputable def stalk_map : Y.stalk (f x) β X.stalk x :=
stalk_map (fmap f) x
/-- The map on the stalks induced by a morphism of CLVRSs is a ring homomorphism.-/
instance : is_ring_hom (stalk_map f x) := stalk_map.is_ring_hom _ _
section local_ring
open local_ring
/-- For every point in a CLVRS,
the support of the valuation on a stalk is the maximal ideal of the stalk.-/
lemma nonunits_eq_supp : nonunits_ideal (X.stalk x) = (X.valuation x).supp :=
unique_of_exists_unique (max_ideal_unique _) (nonunits_ideal.is_maximal _) (X.supp_maximal x)
/-- The map on stalks induced by a morphism of CLVRSs is compatible with the valuations
on the stalks: the pullback of the valuation on the source is the valuation on the target. -/
lemma comap_valuation :
Spv.comap (stalk_map f x) (X.valuation x) = Y.valuation (f x) :=
PreValuedRingedSpace.hom.stalk _ _
/-- The map on stalks induced by a morphism of CLVRSs is a morphism of local rings. -/
lemma is_local_ring_hom :
is_local_ring_hom (stalk_map f x) :=
{ map_nonunit :=
begin
intros s h,
contrapose! h,
rw [β mem_nonunits_iff, β mem_nonunits_ideal, nonunits_eq_supp] at h β’,
rwa [β comap_valuation, Spv.supp_comap] at h,
end }
end local_ring
end CLVRS
/--The adic spectrum of a Huber pair.-/
noncomputable def Spa (A : Huber_pair) : PreValuedRingedSpace :=
{ space := spa A,
presheaf := spa.presheaf_of_topological_rings A,
valuation := Ξ» x, Spv.mk (spa.presheaf.stalk_valuation x) }
open lattice
-- Notation for the proposition that an isomorphism exists between A and B
notation A `β` B := nonempty (A β
B)
namespace CLVRS
/--A CLVRS is an adic space if every point has an open neighbourhood that is isomorphic
to the adic spectrum of a Huber pair.-/
def is_adic_space (X : CLVRS) : Prop :=
β x : X, β (U : opens X) (R : Huber_pair), x β U β§ (Spa R β U)
end CLVRS
/--A CLVRS is an adic space if every point has an open neighbourhood that is isomorphic
to the adic spectrum of a Huber pair.-/
def AdicSpace := {X : CLVRS // X.is_adic_space}
namespace AdicSpace
open category_theory
/--The category of adic spaces is the full subcategory of CLVRS that
consists of the objects that are adic spaces.-/
instance : large_category AdicSpace := category_theory.full_subcategory _
end AdicSpace
|
c1f3912e504a48bf39bbaa262ec3a9b362977178 | 5fbbd711f9bfc21ee168f46a4be146603ece8835 | /lean/natural_number_game/power/7.lean | 0146e1a1ed4195d598d5febed9344f3e59694ced | [
"LicenseRef-scancode-warranty-disclaimer"
] | no_license | goedel-gang/maths | 22596f71e3fde9c088e59931f128a3b5efb73a2c | a20a6f6a8ce800427afd595c598a5ad43da1408d | refs/heads/master | 1,623,055,941,960 | 1,621,599,441,000 | 1,621,599,441,000 | 169,335,840 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 171 | lean | lemma pow_pow (a m n : mynat) : (a ^ m) ^ n = a ^ (m * n) :=
induction n with d hd,
rw mul_zero,
repeat {rw pow_zero},
rwa [pow_succ, hd, mul_succ, pow_add],
end
|
dbe25cc3a86395fbe09da0bb0accc8ae8a94006f | 947b78d97130d56365ae2ec264df196ce769371a | /tests/lean/run/ptrAddr.lean | dabac248d45474d930034a9e569fb58b3f5764a4 | [
"Apache-2.0"
] | permissive | shyamalschandra/lean4 | 27044812be8698f0c79147615b1d5090b9f4b037 | 6e7a883b21eaf62831e8111b251dc9b18f40e604 | refs/heads/master | 1,671,417,126,371 | 1,601,859,995,000 | 1,601,860,020,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 477 | lean | new_frontend
axiom TrustMe {p : Prop} : p
def x := (1, 2)
def y := x
@[noinline] def mk (v : Nat) := (v, v+1)
#eval withPtrAddr x (fun a => dbgTrace (">> " ++ toString a) $ fun _ => 0) TrustMe
#eval withPtrEq x y (fun _ => dbgTrace (">> " ++ toString x ++ " == " ++ toString y) $ fun _ => x == y) TrustMe -- should not print message
#eval withPtrEq x (mk 1) (fun _ => dbgTrace (">> " ++ toString x ++ " == " ++ toString y) $ fun _ => x == y) TrustMe -- should print message
|
a6ba5f635f6cc458e9539c287a3f2594ee17ed80 | 5df84495ec6c281df6d26411cc20aac5c941e745 | /src/formal_ml/measurable_space.lean | 15bd91ef173f31e942f1307173fa0e22194469c5 | [
"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 | 20,265 | lean | /-
Copyright 2020 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-/
import measure_theory.measurable_space
import measure_theory.measure_space
import formal_ml.set
import formal_ml.finset
import formal_ml.classical
lemma set_Prop_le_def {Ξ±:Type*}
(M M2:set Ξ± β Prop):
M β€ M2 β
(β X:set Ξ±, M X β M2 X)
:=
begin
refl,
end
lemma finset_union_measurable {Ξ±:Type*} {T:finset Ξ±} {Ξ²:Type*} [measurable_space Ξ²] {U:Ξ± β set Ξ²}:
(β tβ T, measurable_set (U t)) β
measurable_set (β x β T, U x) :=
begin
intros a,
have A1:(set.sUnion (set.image U ({a|aβ T}:set Ξ±))) = (β x β T, U x),
{
simp,
},
rw β A1,
apply measurable_set.sUnion,
{
apply set.countable.image,
apply set.finite.countable,
apply finite_finset,
},
{
intros,
simp at H,
cases H with x H,
cases H with A2 A3,
subst t,
apply a,
exact A2,
}
end
lemma finset_inter_measurable {Ξ±:Type*} {T:finset Ξ±} {Ξ²:Type*} [measurable_space Ξ²] {U:Ξ± β set Ξ²}:
(β tβ T, measurable_set (U t)) β
measurable_set (β x β T, U x) :=
begin
intros a,
have A1:(set.sInter (set.image U ({a|aβ T}:set Ξ±))) = (β x β T, U x),
{
simp,
},
rw β A1,
apply measurable_set.sInter,
{
apply set.countable.image,
apply set.finite.countable,
apply finite_finset,
},
{
intros,
simp at H,
cases H with x H,
cases H with A2 A3,
subst t,
apply a,
exact A2,
}
end
lemma measurable_space_le_def {Ξ±:Type*}
(M:measurable_space Ξ±) (M2:measurable_space Ξ±):
M.measurable_set' β€ M2.measurable_set'
β M β€ M2 :=
begin
refl,
end
lemma measurable_space_le_def2 {Ξ±:Type*}
(M:measurable_space Ξ±) (M2:measurable_space Ξ±):
(β X:set Ξ±, M.measurable_set' X β M2.measurable_set' X) β
M β€ M2 :=
begin
intros,
apply iff.trans,
{
apply set_Prop_le_def,
},
{
apply measurable_space_le_def,
}
end
-- Delete?
lemma measurable_space_le_intro {Ξ±:Type*}
(M:measurable_space Ξ±) (M2:measurable_space Ξ±):
(β X:set Ξ±, M.measurable_set' X β M2.measurable_set' X) β
M β€ M2 :=
begin
intros a,
have A1:M.measurable_set' β€ M2.measurable_set'
β M β€ M2,
{
apply measurable_space_le_def,
},
apply A1.mp,
have A2:M.measurable_set' β€ M2.measurable_set' β
(β X:set Ξ±, M.measurable_set' X β M2.measurable_set' X),
{
apply set_Prop_le_def,
},
apply A2.mpr,
apply a,
end
lemma measurable_def {Ξ± Ξ²:Type*}
[M1:measurable_space Ξ±] [M2:measurable_space Ξ²] (f:Ξ± β Ξ²):
(β B:(set Ξ²), (measurable_set B) β measurable_set (f β»ΒΉ' B))
β (measurable f) :=
begin
unfold measurable,
end
lemma measurable_intro {Ξ± Ξ²:Type*}
[measurable_space Ξ±] [measurable_space Ξ²] (f:Ξ± β Ξ²):
(β B:(set Ξ²), measurable_set B β measurable_set (f β»ΒΉ' B))
β (measurable f) :=
begin
apply (measurable_def _).mp,
end
lemma measurable_elim {Ξ± Ξ²:Type*}
[measurable_space Ξ±] [measurable_space Ξ²] (f:Ξ± β Ξ²) (B:set Ξ²):
(measurable f)β (measurable_set B) β (measurable_set (f β»ΒΉ' B)) :=
begin
intros a a_1,
apply (measurable_def _).mpr,
apply a,
apply a_1,
end
lemma measurable_fun_product_measurableh {Ξ± Ξ²:Type*}
[M1:measurable_space Ξ±] [M2:measurable_space Ξ²]:
(@prod.measurable_space Ξ± Ξ² M1 M2) = M1.comap prod.fst β M2.comap prod.snd :=
begin
refl
end
lemma comap_elim {Ξ± Ξ²:Type*} [M2:measurable_space Ξ²] (f:Ξ± β Ξ²) (B:set Ξ²):
(measurable_set B) β
(M2.comap f).measurable_set' (set.preimage f B) :=
begin
intros a,
unfold measurable_space.comap,
simp,
apply exists.intro B,
split,
apply a,
refl
end
lemma measurable_comap {Ξ± Ξ²:Type*} [M1:measurable_space Ξ±] [M2:measurable_space Ξ²] (f:Ξ± β Ξ²):
(M2.comap f) β€ M1 β measurable f :=
begin
intros a,
apply measurable_intro,
intros B a_1,
have A1:(M2.comap f).measurable_set' (set.preimage f B),
{
apply comap_elim,
apply a_1,
},
rw β measurable_space_le_def2 at a,
apply a,
apply A1,
end
lemma fst_measurable {Ξ± Ξ²:Type*}
[M1:measurable_space Ξ±] [M2:measurable_space Ξ²]:measurable (Ξ» x:(Ξ± Γ Ξ²), x.fst) :=
begin
apply measurable_comap,
have A1:M1.comap prod.fst β€ (@prod.measurable_space Ξ± Ξ² M1 M2),
{
rw measurable_fun_product_measurableh,
apply complete_lattice.le_sup_left (M1.comap prod.fst) (M2.comap prod.snd),
},
apply A1,
end
lemma snd_measurable {Ξ± Ξ²:Type*}
[M1:measurable_space Ξ±] [M2:measurable_space Ξ²]:measurable (Ξ» x:(Ξ± Γ Ξ²), x.snd) :=
begin
apply measurable_comap,
have A1:M2.comap prod.snd β€ (@prod.measurable_space Ξ± Ξ² M1 M2),
{
rw measurable_fun_product_measurableh,
apply complete_lattice.le_sup_right (M1.comap prod.fst) (M2.comap prod.snd),
},
apply A1,
end
lemma comap_def {Ξ± Ξ²:Type*} {B:set (set Ξ²)}
(f:Ξ± β Ξ²):
@measurable_space.comap Ξ± Ξ² f (measurable_space.generate_from B)
= (measurable_space.generate_from (set.image (set.preimage f) B)) :=
begin
apply measurable_space.comap_generate_from,
end
lemma comap_fst_def {Ξ± Ξ²:Type*} {BΞ±:set (set Ξ±)}:
(measurable_space.generate_from BΞ±).comap (@prod.fst Ξ± Ξ²) =
measurable_space.generate_from {U:set (Ξ± Γ Ξ²)|β Aβ BΞ±, U = set.prod A set.univ} :=
begin
rw measurable_space.comap_generate_from,
rw set.preimage_fst_def,
end
lemma comap_snd_def {Ξ± Ξ²:Type*} {BΞ²:set (set Ξ²)}:
(measurable_space.generate_from BΞ²).comap (@prod.snd Ξ± Ξ²) =
measurable_space.generate_from {U:set (Ξ± Γ Ξ²)|β Bβ BΞ², U = set.prod set.univ B} :=
begin
rw measurable_space.comap_generate_from,
rw set.preimage_snd_def,
end
lemma measurable_space_sup_def {Ξ±:Type*} {B C:set (set Ξ±)}:
(measurable_space.generate_from B) β (measurable_space.generate_from C) =
(measurable_space.generate_from (B βͺ C)) :=
begin
apply measurable_space.generate_from_sup_generate_from,
end
lemma prod_measurable_space_def {Ξ± Ξ²:Type*} {BΞ±:set (set Ξ±)}
{BΞ²:set (set Ξ²)}:
(@prod.measurable_space Ξ± Ξ² (measurable_space.generate_from BΞ±)
(measurable_space.generate_from BΞ²)) =
@measurable_space.generate_from (Ξ± Γ Ξ²) (
{U:set (Ξ± Γ Ξ²)|β Aβ BΞ±, U = set.prod A set.univ} βͺ
{U:set (Ξ± Γ Ξ²)|β Bβ BΞ², U = set.prod set.univ B})
:=
begin
rw measurable_fun_product_measurableh,
rw comap_fst_def,
rw comap_snd_def,
rw measurable_space_sup_def,
end
lemma set.sUnion_eq_univ_elim {Ξ±:Type*} {S:set (set Ξ±)} (a:Ξ±):
(set.sUnion S = set.univ) β (β TβS, aβ T) :=
begin
intro A1,
have A2:aβ set.univ := set.mem_univ a,
rw β A1 at A2,
simp at A2,
cases A2 with T A2,
apply exists.intro T,
apply exists.intro A2.left,
apply A2.right,
end
lemma prod_measurable_space_le {Ξ± Ξ²:Type*} {BΞ±:set (set Ξ±)}
{BΞ²:set (set Ξ²)}:
@measurable_space.generate_from (Ξ± Γ Ξ²)
{U:set (Ξ± Γ Ξ²)|β Aβ BΞ±, β BβBΞ², U = set.prod A B} β€
(@prod.measurable_space Ξ± Ξ² (measurable_space.generate_from BΞ±)
(measurable_space.generate_from BΞ²))
:=
begin
rw prod_measurable_space_def,
apply measurable_space.generate_from_le, intros X A5,
simp at A5,
cases A5 with A A5,
cases A5 with A5 A6,
cases A6 with B A6,
cases A6 with A6 A7,
have A8:(set.prod A (@set.univ Ξ²)) β©
(set.prod (@set.univ Ξ±) B) = set.prod A B,
{
ext p,split;intros A3A;{
simp at A3A,
simp,
--cases p,
apply A3A,
},
},
rw β A8 at A7,
rw A7,
apply measurable_set.inter,
{
apply measurable_space.measurable_set_generate_from,
apply set.mem_union_left,
simp,
apply exists.intro A,
split,
apply A5,
refl,
},
{
apply measurable_space.measurable_set_generate_from,
apply set.mem_union_right,
simp,
apply exists.intro B,
split,
apply A6,
refl,
},
end
lemma prod_measurable_space_def2 {Ξ± Ξ²:Type*} {BΞ±:set (set Ξ±)}
{BΞ²:set (set Ξ²)} {CΞ±:set (set Ξ±)} {CΞ²:set (set Ξ²)}:
(set.countable CΞ±) β
(set.countable CΞ²) β
(CΞ± β BΞ±) β
(CΞ² β BΞ²) β
(set.sUnion CΞ± = set.univ) β
(set.sUnion CΞ² = set.univ) β
(@prod.measurable_space Ξ± Ξ² (measurable_space.generate_from BΞ±)
(measurable_space.generate_from BΞ²)) =
@measurable_space.generate_from (Ξ± Γ Ξ²)
{U:set (Ξ± Γ Ξ²)|β Aβ BΞ±, β BβBΞ², U = set.prod A B}
:=
begin
intros A1 A2 A3 A4 AX1 AX2,
--rw prod_measurable_space_def,
apply le_antisymm,
{
rw prod_measurable_space_def,
apply measurable_space.generate_from_le,
intros X A5,
simp at A5,
cases A5,
{
cases A5 with A A5,
cases A5 with A5 A6,
have A7:X = set.sUnion (set.image (set.prod A) CΞ²),
{
rw A6,
ext a,split;intro A7A;simp;simp at A7A,
{
have A7B := set.sUnion_eq_univ_elim a.snd AX2,
cases A7B with i A7B,
cases A7B with A7B A7C,
apply exists.intro i,
apply and.intro A7B (and.intro A7A A7C),
},
{
cases A7A with i A7A,
apply A7A.right.left,
},
},
rw A7,
--apply measurable_space.measurable_set_generate_from,
apply measurable_set.sUnion,
apply set.countable.image,
apply A2,
intro U,
intro A8,
simp at A8,
cases A8 with B A8,
cases A8 with A8 A9,
subst U,
apply measurable_space.measurable_set_generate_from,
simp,
apply exists.intro A,
split,
apply A5,
apply exists.intro B,
split,
rw set.subset_def at A4,
apply A4,
apply A8,
refl,
},
{
cases A5 with B A5,
cases A5 with A5 A6,
have A7:X = set.sUnion (set.image (Ξ» x, set.prod x B) CΞ±),
{
rw A6,
ext a,split;intro A7A;simp;simp at A7A,
{
have A7B := set.sUnion_eq_univ_elim a.fst AX1,
cases A7B with i A7B,
cases A7B with A7B A7C,
apply exists.intro i,
apply and.intro A7B (and.intro A7C A7A),
},
{
cases A7A with i A7A,
apply A7A.right.right,
},
},
rw A7,
--apply measurable_space.measurable_set_generate_from,
apply measurable_set.sUnion,
apply set.countable.image,
apply A1,
intro U,
intro A8,
simp at A8,
cases A8 with A A8,
cases A8 with A8 A9,
subst U,
apply measurable_space.measurable_set_generate_from,
simp,
apply exists.intro A,
split,
rw set.subset_def at A3,
apply A3,
apply A8,
apply exists.intro B,
split,
apply A5,
refl,
},
},
{
apply prod_measurable_space_le,
}
end
lemma preimage_compl {Ξ± Ξ²:Type*} (f:Ξ± β Ξ²) (S:set Ξ²):
(f β»ΒΉ' SαΆ) = ((f β»ΒΉ' S)αΆ) :=
begin
ext,
split;intros a,
{
intro a_1,
unfold set.preimage at a,
simp at a,
apply a,
apply a_1,
},
{
unfold set.preimage,
simp,
intro a_1,
apply a,
apply a_1,
}
end
lemma preimage_Union {Ξ± Ξ²:Type*} (f:Ξ± β Ξ²) (g:β β set Ξ²):
(f β»ΒΉ' β (i : β), g i)=(β (i : β), f β»ΒΉ' (g i)) :=
begin
ext,
split;intros a,
{
cases a with B a,
cases a with H a,
cases H with y H,
split,
simp,
split,
apply exists.intro y,
{
simp at H,
},
{
simp at H,
subst B,
apply a,
}
},
{
cases a with A a,
cases a with A1 A2,
cases A1 with i A3,
simp at A3,
subst A,
split,
simp,
split,
{
apply exists.intro i,
refl,
},
{
apply A2,
},
}
end
lemma generate_from_measurable {Ξ± Ξ²:Type*} [M:measurable_space Ξ±] [M2:measurable_space Ξ²]
(X:set (set Ξ²)) (f:Ξ± β Ξ²):
(measurable_space.generate_from X = M2)β
(β Bβ X, measurable_set (set.preimage f B))β
(measurable f) :=
begin
intros a a_1,
apply measurable_intro,
intros B a_2,
have A1:@measurable_set Ξ² (measurable_space.generate_from X) B,
{
rw a,
apply a_2,
},
clear a_2, -- Important for induction later.
have A2:measurable_space.generate_measurable X B,
{
apply A1,
},
induction A2,
{
apply a_1,
apply A2_H,
},
{
simp,
},
{ -- β’ measurable_set (f β»ΒΉ' -A2_s)
rw preimage_compl,
apply measurable_space.measurable_set_compl,
apply A2_ih,
{
apply (measurable_set.compl_iff).mp,
apply A1,
},
},
{
rw preimage_Union,
apply measurable_space.measurable_set_Union,
intros i,
apply A2_ih,
{
apply A2_αΎ°,
}
}
end
lemma generate_from_self {Ξ±:Type*}
(M:measurable_space Ξ±):
M = measurable_space.generate_from {s : set Ξ±|measurable_space.measurable_set' M s} :=
begin
ext,
split;intros a,
{
apply measurable_space.generate_measurable.basic,
apply a,
},
{
induction a,
{
apply a_H,
},
{
apply measurable_space.measurable_set_empty,
},
{
apply measurable_space.measurable_set_compl,
apply a_ih,
},
{
apply measurable_space.measurable_set_Union,
apply a_ih,
},
}
end
lemma measurable_fun_comap_def {Ξ± Ξ²:Type*}
[M2:measurable_space Ξ²] (f:Ξ± β Ξ²):
measurable_space.comap f M2 = measurable_space.generate_from
{s : set Ξ±|β (s' : set Ξ²), measurable_space.measurable_set' M2 s' β§ f β»ΒΉ' s' = s} :=
begin
unfold measurable_space.comap,
apply generate_from_self,
end
lemma measurable_fun_product_measurable {Ξ± Ξ² Ξ³:Type*}
[M1:measurable_space Ξ±] [M2:measurable_space Ξ²] [M3:measurable_space Ξ³]
(X: Ξ± β Ξ²) (Y: Ξ± β Ξ³):
measurable X β
measurable Y β
measurable (Ξ» a:Ξ±, prod.mk (X a) (Y a)) :=
begin
intros B1 B2,
have A1:@measurable _ _ _ (@prod.measurable_space Ξ² Ξ³ M2 M3) (Ξ» a:Ξ±, prod.mk (X a) (Y a)),
{
have A1A:(@prod.measurable_space Ξ² Ξ³ M2 M3)=measurable_space.generate_from (
{s : set (Ξ² Γ Ξ³) | β (s' : set Ξ²), measurable_space.measurable_set' M2 s' β§ prod.fst β»ΒΉ' s' = s} βͺ
{s : set (Ξ² Γ Ξ³) | β (s' : set Ξ³), measurable_space.measurable_set' M3 s' β§ prod.snd β»ΒΉ' s' = s}),
{
rw measurable_fun_product_measurableh,
rw measurable_fun_comap_def,
rw measurable_fun_comap_def,
rw measurable_space.generate_from_sup_generate_from,
},
rw A1A,
apply generate_from_measurable,
{
refl,
},
{
intro BC,
intros H,
cases H,
{
cases H with B H,
cases H,
subst BC,
have A1B:(Ξ» (a : Ξ±), (X a, Y a)) β»ΒΉ' (prod.fst β»ΒΉ' B) = (X β»ΒΉ' B),
{
ext,split;intros a,
{
simp at a,
apply a,
},
{
simp,
apply a,
}
},
rw A1B,
apply B1,
apply H_left,
},
{
cases H with C H,
cases H,
subst BC,
have A1C:(Ξ» (a : Ξ±), (X a, Y a)) β»ΒΉ' (prod.snd β»ΒΉ' C) = (Y β»ΒΉ' C),
{
ext,split;intros a,
{
simp at a,
apply a,
},
{
simp,
apply a,
}
},
rw A1C,
apply B2,
apply H_left,
}
}
},
apply A1,
end
lemma compose_measurable_fun_measurable {Ξ± Ξ² Ξ³:Type*}
[measurable_space Ξ±] [measurable_space Ξ²] [measurable_space Ξ³]
(X:Ξ² β Ξ³) (Y: Ξ±β Ξ²):
measurable X β
measurable Y β
measurable (X β Y) :=
begin
intros B1 B2,
apply measurable_intro,
intros B a,
have A1:(X β Y β»ΒΉ' B)=(Y β»ΒΉ' (X β»ΒΉ' B)),
{
refl,
},
rw A1,
apply measurable_elim Y _ B2,
apply measurable_elim X _ B1,
apply a
end
-- Constant functions are measurable.
-- Different than measurable_set.const
lemma const_measurable {Ξ©:Type*} [measurable_space Ξ©] {Ξ²:Type*} [measurable_space Ξ²] (c:Ξ²):
(measurable (Ξ» Ο:Ξ©, c)) :=
begin
apply measurable_const,
end
lemma measurable_set_of_le_of_measurable_set
{Ξ± : Type*} {M1 : measurable_space Ξ±} {M2 : measurable_space Ξ±}
{X:set Ξ±}:
M1 β€ M2 β
measurable_space.measurable_set' M1 X β
measurable_space.measurable_set' M2 X :=
begin
intros A2 A1,
rw β measurable_space_le_def2 at A2,
apply A2,
apply A1,
end
-- cf. measurable_set_prod
lemma measurable_set_prod' {Ξ² : Type*} {Ξ³ : Type*}
{MΞ² : measurable_space Ξ²} {MΞ³ : measurable_space Ξ³}
{X:set Ξ²} {Y:set Ξ³}:measurable_set X β
measurable_set Y β
measurable_set (set.prod X Y) :=
begin
--apply measurable_set_of_le_of_measurable_set,
intros A1 A2,
rw generate_from_self MΞ²,
rw generate_from_self MΞ³,
apply measurable_set_of_le_of_measurable_set,
apply prod_measurable_space_le,
apply measurable_space.measurable_set_generate_from,
simp,
apply exists.intro X,
split,
apply A1,
apply exists.intro Y,
split,
apply A2,
refl,
end
lemma measurable.preimage {Ξ± Ξ²:Type*} [measurable_space Ξ±] [measurable_space Ξ²] {f:Ξ± β Ξ²}
{S:set Ξ²}:measurable f β measurable_set S β measurable_set (set.preimage f S) :=
begin
intros A1 A2,
apply A1,
apply A2,
end
lemma measurable.if {Ξ± Ξ²:Type*}
{MΞ±:measurable_space Ξ±} {MΞ²:measurable_space Ξ²}
{E:set Ξ±} {D:decidable_pred E}
{X Y:Ξ± β Ξ²}:measurable_set E β
measurable X β
measurable Y β
measurable (Ξ» a:Ξ±, if (E a) then (X a) else (Y a)) :=
begin
intros A1 A2 A3,
intros S B1,
rw preimage_if,
apply measurable_set.union,
{
apply measurable_set.inter,
apply A1,
apply A2,
apply B1,
},
{
apply measurable_set.inter,
apply measurable_set.compl,
apply A1,
apply A3,
apply B1,
},
end
lemma measurable_set.pi' {Ξ±:Type*} [F:fintype Ξ±] {Ξ²:Ξ± β Type*} [M:β a, measurable_space (Ξ² a)]
{P:Ξ a, set (Ξ² a)} (T:set Ξ±):(β a, measurable_set (P a)) β
measurable_set (set.pi T P) := begin
classical,
intros A0,
have A1:(set.pi T P) = β (a β T), ((Ξ» (p:Ξ a, Ξ² a), p a) β»ΒΉ' (P a)),
{ ext x, simp, },
rw A1,
have A3:trunc (encodable Ξ±) := encodable.trunc_encodable_of_fintype Ξ±,
trunc_cases A3,
haveI:encodable Ξ± := A3,
apply measurable_set.Inter,
intros a',
cases classical.em (a' β T) with A4 A4,
{ have A5:(β (H : a' β T), (Ξ» (p : Ξ (a : Ξ±), Ξ² a), p a') β»ΒΉ' P a') =
(Ξ» (p : Ξ (a : Ξ±), Ξ² a), p a') β»ΒΉ' P a',
{ ext, simp; split; intros A5_1,
apply A5_1 A4,
intros A5_2, apply A5_1 },
rw A5,
have A2:measurable_space.comap (Ξ» (p:Ξ a, Ξ² a), p a') (M a') β€ measurable_space.pi,
{ simp [measurable_space.pi], apply @le_supr (measurable_space (Ξ a, Ξ² a)) _ _ _ (a') },
apply A2,
simp [measurable_space.comap],
apply exists.intro (P a'),
simp,
apply A0 a' },
{ have A6:(β (H : a' β T), (Ξ» (p : Ξ (a : Ξ±), Ξ² a), p a') β»ΒΉ' P a') = set.univ,
{ ext, simp; intros A6_1,
apply absurd A4,
simp,apply A6_1 },
rw A6,
simp, },
end
--Unused.
lemma measurable_space.generate_measurable_monotone {Ξ±:Type*} {s t:set (set Ξ±)}:
(s β t) β
(β u, (measurable_space.generate_measurable s u β
measurable_space.generate_measurable t u)) :=
begin
intros h1 u h2,
induction h2 with u' h_u' u' h_u' h_ind f h_f h_ind,
{ apply measurable_space.generate_measurable.basic,
apply h1,
apply h_u' },
{ apply measurable_space.generate_measurable.empty },
{ apply measurable_space.generate_measurable.compl,
apply h_ind },
{ apply measurable_space.generate_measurable.union,
apply h_ind },
end
|
02fa2106fdb9d9652dc1c760aaa1b7902830f20d | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/order/rel_classes.lean | 8ab31590606f902dc20e34d81158ac3a62c92f14 | [
"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 | 14,323 | lean | /-
Copyright (c) 2020 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Mario Carneiro, Yury G. Kudryashov
-/
import order.basic
/-!
# Unbundled relation classes
In this file we prove some properties of `is_*` classes defined in `init.algebra.classes`. The main
difference between these classes and the usual order classes (`preorder` etc) is that usual classes
extend `has_le` and/or `has_lt` while these classes take a relation as an explicit argument.
-/
universes u v
variables {Ξ± : Type u} {Ξ² : Type v} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
open function
theorem is_refl.swap (r) [is_refl Ξ± r] : is_refl Ξ± (swap r) := β¨refl_of rβ©
theorem is_irrefl.swap (r) [is_irrefl Ξ± r] : is_irrefl Ξ± (swap r) := β¨irrefl_of rβ©
theorem is_trans.swap (r) [is_trans Ξ± r] : is_trans Ξ± (swap r) :=
β¨Ξ» a b c hβ hβ, trans_of r hβ hββ©
theorem is_antisymm.swap (r) [is_antisymm Ξ± r] : is_antisymm Ξ± (swap r) :=
β¨Ξ» a b hβ hβ, antisymm hβ hββ©
theorem is_asymm.swap (r) [is_asymm Ξ± r] : is_asymm Ξ± (swap r) :=
β¨Ξ» a b hβ hβ, asymm_of r hβ hββ©
theorem is_total.swap (r) [is_total Ξ± r] : is_total Ξ± (swap r) :=
β¨Ξ» a b, (total_of r a b).swapβ©
theorem is_trichotomous.swap (r) [is_trichotomous Ξ± r] : is_trichotomous Ξ± (swap r) :=
β¨Ξ» a b, by simpa [swap, or.comm, or.left_comm] using trichotomous_of r a bβ©
theorem is_preorder.swap (r) [is_preorder Ξ± r] : is_preorder Ξ± (swap r) :=
{..@is_refl.swap Ξ± r _, ..@is_trans.swap Ξ± r _}
theorem is_strict_order.swap (r) [is_strict_order Ξ± r] : is_strict_order Ξ± (swap r) :=
{..@is_irrefl.swap Ξ± r _, ..@is_trans.swap Ξ± r _}
theorem is_partial_order.swap (r) [is_partial_order Ξ± r] : is_partial_order Ξ± (swap r) :=
{..@is_preorder.swap Ξ± r _, ..@is_antisymm.swap Ξ± r _}
theorem is_total_preorder.swap (r) [is_total_preorder Ξ± r] : is_total_preorder Ξ± (swap r) :=
{..@is_preorder.swap Ξ± r _, ..@is_total.swap Ξ± r _}
theorem is_linear_order.swap (r) [is_linear_order Ξ± r] : is_linear_order Ξ± (swap r) :=
{..@is_partial_order.swap Ξ± r _, ..@is_total.swap Ξ± r _}
protected theorem is_asymm.is_antisymm (r) [is_asymm Ξ± r] : is_antisymm Ξ± r :=
β¨Ξ» x y hβ hβ, (asymm hβ hβ).elimβ©
protected theorem is_asymm.is_irrefl [is_asymm Ξ± r] : is_irrefl Ξ± r :=
β¨Ξ» a h, asymm h hβ©
/- Convert algebraic structure style to explicit relation style typeclasses -/
instance [preorder Ξ±] : is_refl Ξ± (β€) := β¨le_reflβ©
instance [preorder Ξ±] : is_refl Ξ± (β₯) := is_refl.swap _
instance [preorder Ξ±] : is_trans Ξ± (β€) := β¨@le_trans _ _β©
instance [preorder Ξ±] : is_trans Ξ± (β₯) := is_trans.swap _
instance [preorder Ξ±] : is_preorder Ξ± (β€) := {}
instance [preorder Ξ±] : is_preorder Ξ± (β₯) := {}
instance [preorder Ξ±] : is_irrefl Ξ± (<) := β¨lt_irreflβ©
instance [preorder Ξ±] : is_irrefl Ξ± (>) := is_irrefl.swap _
instance [preorder Ξ±] : is_trans Ξ± (<) := β¨@lt_trans _ _β©
instance [preorder Ξ±] : is_trans Ξ± (>) := is_trans.swap _
instance [preorder Ξ±] : is_asymm Ξ± (<) := β¨@lt_asymm _ _β©
instance [preorder Ξ±] : is_asymm Ξ± (>) := is_asymm.swap _
instance [preorder Ξ±] : is_antisymm Ξ± (<) := is_asymm.is_antisymm _
instance [preorder Ξ±] : is_antisymm Ξ± (>) := is_asymm.is_antisymm _
instance [preorder Ξ±] : is_strict_order Ξ± (<) := {}
instance [preorder Ξ±] : is_strict_order Ξ± (>) := {}
instance preorder.is_total_preorder [preorder Ξ±] [is_total Ξ± (β€)] : is_total_preorder Ξ± (β€) := {}
instance [partial_order Ξ±] : is_antisymm Ξ± (β€) := β¨@le_antisymm _ _β©
instance [partial_order Ξ±] : is_antisymm Ξ± (β₯) := is_antisymm.swap _
instance [partial_order Ξ±] : is_partial_order Ξ± (β€) := {}
instance [partial_order Ξ±] : is_partial_order Ξ± (β₯) := {}
instance [linear_order Ξ±] : is_total Ξ± (β€) := β¨le_totalβ©
instance [linear_order Ξ±] : is_total Ξ± (β₯) := is_total.swap _
instance linear_order.is_total_preorder [linear_order Ξ±] : is_total_preorder Ξ± (β€) :=
by apply_instance
instance [linear_order Ξ±] : is_total_preorder Ξ± (β₯) := {}
instance [linear_order Ξ±] : is_linear_order Ξ± (β€) := {}
instance [linear_order Ξ±] : is_linear_order Ξ± (β₯) := {}
instance [linear_order Ξ±] : is_trichotomous Ξ± (<) := β¨lt_trichotomyβ©
instance [linear_order Ξ±] : is_trichotomous Ξ± (>) := is_trichotomous.swap _
instance order_dual.is_total_le [has_le Ξ±] [is_total Ξ± (β€)] : is_total (order_dual Ξ±) (β€) :=
@is_total.swap Ξ± _ _
lemma ne_of_irrefl {r} [is_irrefl Ξ± r] : β {x y : Ξ±}, r x y β x β y
| _ _ h rfl := irrefl _ h
lemma trans_trichotomous_left [is_trans Ξ± r] [is_trichotomous Ξ± r] {a b c : Ξ±} :
Β¬r b a β r b c β r a c :=
begin
intros hβ hβ, rcases trichotomous_of r a b with hβ|hβ|hβ,
exact trans hβ hβ, rw hβ, exact hβ, exfalso, exact hβ hβ
end
lemma trans_trichotomous_right [is_trans Ξ± r] [is_trichotomous Ξ± r] {a b c : Ξ±} :
r a b β Β¬r c b β r a c :=
begin
intros hβ hβ, rcases trichotomous_of r b c with hβ|hβ|hβ,
exact trans hβ hβ, rw βhβ, exact hβ, exfalso, exact hβ hβ
end
/-- Construct a partial order from a `is_strict_order` relation -/
def partial_order_of_SO (r) [is_strict_order Ξ± r] : partial_order Ξ± :=
{ le := Ξ» x y, x = y β¨ r x y,
lt := r,
le_refl := Ξ» x, or.inl rfl,
le_trans := Ξ» x y z hβ hβ,
match y, z, hβ, hβ with
| _, _, or.inl rfl, hβ := hβ
| _, _, hβ, or.inl rfl := hβ
| _, _, or.inr hβ, or.inr hβ := or.inr (trans hβ hβ)
end,
le_antisymm := Ξ» x y hβ hβ,
match y, hβ, hβ with
| _, or.inl rfl, hβ := rfl
| _, hβ, or.inl rfl := rfl
| _, or.inr hβ, or.inr hβ := (asymm hβ hβ).elim
end,
lt_iff_le_not_le := Ξ» x y,
β¨Ξ» h, β¨or.inr h, not_or
(Ξ» e, by rw e at h; exact irrefl _ h)
(asymm h)β©,
Ξ» β¨hβ, hββ©, hβ.resolve_left (Ξ» e, hβ $ e βΈ or.inl rfl)β© }
/-- This is basically the same as `is_strict_total_order`, but that definition is
in Type (probably by mistake) and also has redundant assumptions. -/
@[algebra] class is_strict_total_order' (Ξ± : Type u) (lt : Ξ± β Ξ± β Prop)
extends is_trichotomous Ξ± lt, is_strict_order Ξ± lt : Prop.
/-- Construct a linear order from an `is_strict_total_order'` relation -/
def linear_order_of_STO' (r) [is_strict_total_order' Ξ± r] [Ξ x y, decidable (Β¬ r x y)] :
linear_order Ξ± :=
{ le_total := Ξ» x y,
match y, trichotomous_of r x y with
| y, or.inl h := or.inl (or.inr h)
| _, or.inr (or.inl rfl) := or.inl (or.inl rfl)
| _, or.inr (or.inr h) := or.inr (or.inr h)
end,
decidable_le := Ξ» x y, decidable_of_iff (Β¬ r y x)
β¨Ξ» h, ((trichotomous_of r y x).resolve_left h).imp eq.symm id,
Ξ» h, h.elim (Ξ» h, h βΈ irrefl_of _ _) (asymm_of r)β©,
..partial_order_of_SO r }
theorem is_strict_total_order'.swap (r) [is_strict_total_order' Ξ± r] :
is_strict_total_order' Ξ± (swap r) :=
{..is_trichotomous.swap r, ..is_strict_order.swap r}
instance [linear_order Ξ±] : is_strict_total_order' Ξ± (<) := {}
/-- A connected order is one satisfying the condition `a < c β a < b β¨ b < c`.
This is recognizable as an intuitionistic substitute for `a β€ b β¨ b β€ a` on
the constructive reals, and is also known as negative transitivity,
since the contrapositive asserts transitivity of the relation `Β¬ a < b`. -/
@[algebra] class is_order_connected (Ξ± : Type u) (lt : Ξ± β Ξ± β Prop) : Prop :=
(conn : β a b c, lt a c β lt a b β¨ lt b c)
theorem is_order_connected.neg_trans {r : Ξ± β Ξ± β Prop} [is_order_connected Ξ± r]
{a b c} (hβ : Β¬ r a b) (hβ : Β¬ r b c) : Β¬ r a c :=
mt (is_order_connected.conn a b c) $ by simp [hβ, hβ]
theorem is_strict_weak_order_of_is_order_connected [is_asymm Ξ± r]
[is_order_connected Ξ± r] : is_strict_weak_order Ξ± r :=
{ trans := Ξ» a b c hβ hβ, (is_order_connected.conn _ c _ hβ).resolve_right (asymm hβ),
incomp_trans := Ξ» a b c β¨hβ, hββ© β¨hβ, hββ©,
β¨is_order_connected.neg_trans hβ hβ, is_order_connected.neg_trans hβ hββ©,
..@is_asymm.is_irrefl Ξ± r _ }
@[priority 100] -- see Note [lower instance priority]
instance is_order_connected_of_is_strict_total_order'
[is_strict_total_order' Ξ± r] : is_order_connected Ξ± r :=
β¨Ξ» a b c h, (trichotomous _ _).imp_right (Ξ» o,
o.elim (Ξ» e, e βΈ h) (Ξ» h', trans h' h))β©
@[priority 100] -- see Note [lower instance priority]
instance is_strict_total_order_of_is_strict_total_order'
[is_strict_total_order' Ξ± r] : is_strict_total_order Ξ± r :=
{..is_strict_weak_order_of_is_order_connected}
instance [linear_order Ξ±] : is_strict_total_order Ξ± (<) := by apply_instance
instance [linear_order Ξ±] : is_order_connected Ξ± (<) := by apply_instance
instance [linear_order Ξ±] : is_incomp_trans Ξ± (<) := by apply_instance
instance [linear_order Ξ±] : is_strict_weak_order Ξ± (<) := by apply_instance
/-- An extensional relation is one in which an element is determined by its set
of predecessors. It is named for the `x β y` relation in set theory, whose
extensionality is one of the first axioms of ZFC. -/
@[algebra] class is_extensional (Ξ± : Type u) (r : Ξ± β Ξ± β Prop) : Prop :=
(ext : β a b, (β x, r x a β r x b) β a = b)
@[priority 100] -- see Note [lower instance priority]
instance is_extensional_of_is_strict_total_order'
[is_strict_total_order' Ξ± r] : is_extensional Ξ± r :=
β¨Ξ» a b H, ((@trichotomous _ r _ a b)
.resolve_left $ mt (H _).2 (irrefl a))
.resolve_right $ mt (H _).1 (irrefl b)β©
/-- A well order is a well-founded linear order. -/
@[algebra] class is_well_order (Ξ± : Type u) (r : Ξ± β Ξ± β Prop)
extends is_strict_total_order' Ξ± r : Prop :=
(wf : well_founded r)
@[priority 100] -- see Note [lower instance priority]
instance is_well_order.is_strict_total_order {Ξ±} (r : Ξ± β Ξ± β Prop) [is_well_order Ξ± r] :
is_strict_total_order Ξ± r := by apply_instance
@[priority 100] -- see Note [lower instance priority]
instance is_well_order.is_extensional {Ξ±} (r : Ξ± β Ξ± β Prop) [is_well_order Ξ± r] :
is_extensional Ξ± r := by apply_instance
@[priority 100] -- see Note [lower instance priority]
instance is_well_order.is_trichotomous {Ξ±} (r : Ξ± β Ξ± β Prop) [is_well_order Ξ± r] :
is_trichotomous Ξ± r := by apply_instance
@[priority 100] -- see Note [lower instance priority]
instance is_well_order.is_trans {Ξ±} (r : Ξ± β Ξ± β Prop) [is_well_order Ξ± r] :
is_trans Ξ± r := by apply_instance
@[priority 100] -- see Note [lower instance priority]
instance is_well_order.is_irrefl {Ξ±} (r : Ξ± β Ξ± β Prop) [is_well_order Ξ± r] :
is_irrefl Ξ± r := by apply_instance
@[priority 100] -- see Note [lower instance priority]
instance is_well_order.is_asymm {Ξ±} (r : Ξ± β Ξ± β Prop) [is_well_order Ξ± r] :
is_asymm Ξ± r := by apply_instance
/-- Construct a decidable linear order from a well-founded linear order. -/
noncomputable def is_well_order.linear_order (r : Ξ± β Ξ± β Prop) [is_well_order Ξ± r] :
linear_order Ξ± :=
by { letI := Ξ» x y, classical.dec (Β¬r x y), exact linear_order_of_STO' r }
instance empty_relation.is_well_order [subsingleton Ξ±] : is_well_order Ξ± empty_relation :=
{ trichotomous := Ξ» a b, or.inr $ or.inl $ subsingleton.elim _ _,
irrefl := Ξ» a, id,
trans := Ξ» a b c, false.elim,
wf := β¨Ξ» a, β¨_, Ξ» y, false.elimβ©β© }
instance nat.lt.is_well_order : is_well_order β (<) := β¨nat.lt_wfβ©
instance sum.lex.is_well_order [is_well_order Ξ± r] [is_well_order Ξ² s] :
is_well_order (Ξ± β Ξ²) (sum.lex r s) :=
{ trichotomous := Ξ» a b, by cases a; cases b; simp; apply trichotomous,
irrefl := Ξ» a, by cases a; simp; apply irrefl,
trans := Ξ» a b c, by cases a; cases b; simp; cases c; simp; apply trans,
wf := sum.lex_wf is_well_order.wf is_well_order.wf }
instance prod.lex.is_well_order [is_well_order Ξ± r] [is_well_order Ξ² s] :
is_well_order (Ξ± Γ Ξ²) (prod.lex r s) :=
{ trichotomous := Ξ» β¨aβ, aββ© β¨bβ, bββ©,
match @trichotomous _ r _ aβ bβ with
| or.inl hβ := or.inl $ prod.lex.left _ _ hβ
| or.inr (or.inr hβ) := or.inr $ or.inr $ prod.lex.left _ _ hβ
| or.inr (or.inl e) := e βΈ match @trichotomous _ s _ aβ bβ with
| or.inl h := or.inl $ prod.lex.right _ h
| or.inr (or.inr h) := or.inr $ or.inr $ prod.lex.right _ h
| or.inr (or.inl e) := e βΈ or.inr $ or.inl rfl
end
end,
irrefl := Ξ» β¨aβ, aββ© h, by cases h with _ _ _ _ h _ _ _ h;
[exact irrefl _ h, exact irrefl _ h],
trans := Ξ» a b c hβ hβ, begin
cases hβ with aβ aβ bβ bβ ab aβ bβ bβ ab;
cases hβ with _ _ cβ cβ bc _ _ cβ bc,
{ exact prod.lex.left _ _ (trans ab bc) },
{ exact prod.lex.left _ _ ab },
{ exact prod.lex.left _ _ bc },
{ exact prod.lex.right _ (trans ab bc) }
end,
wf := prod.lex_wf is_well_order.wf is_well_order.wf }
/-- An unbounded or cofinal set -/
def unbounded (r : Ξ± β Ξ± β Prop) (s : set Ξ±) : Prop := β a, β b β s, Β¬ r b a
/-- A bounded or final set -/
def bounded (r : Ξ± β Ξ± β Prop) (s : set Ξ±) : Prop := βa, β b β s, r b a
@[simp] lemma not_bounded_iff {r : Ξ± β Ξ± β Prop} (s : set Ξ±) : Β¬bounded r s β unbounded r s :=
begin
classical,
simp only [bounded, unbounded, not_forall, not_exists, exists_prop, not_and, not_not]
end
@[simp] lemma not_unbounded_iff {r : Ξ± β Ξ± β Prop} (s : set Ξ±) : Β¬unbounded r s β bounded r s :=
by { classical, rw [not_iff_comm, not_bounded_iff] }
namespace prod
instance is_refl_preimage_fst {r : Ξ± β Ξ± β Prop} [h : is_refl Ξ± r] :
is_refl (Ξ± Γ Ξ±) (prod.fst β»ΒΉ'o r) := β¨Ξ» a, refl_of r a.1β©
instance is_refl_preimage_snd {r : Ξ± β Ξ± β Prop} [h : is_refl Ξ± r] :
is_refl (Ξ± Γ Ξ±) (prod.snd β»ΒΉ'o r) := β¨Ξ» a, refl_of r a.2β©
instance is_trans_preimage_fst {r : Ξ± β Ξ± β Prop} [h : is_trans Ξ± r] :
is_trans (Ξ± Γ Ξ±) (prod.fst β»ΒΉ'o r) := β¨Ξ» _ _ _, trans_of rβ©
instance is_trans_preimage_snd {r : Ξ± β Ξ± β Prop} [h : is_trans Ξ± r] :
is_trans (Ξ± Γ Ξ±) (prod.snd β»ΒΉ'o r) := β¨Ξ» _ _ _, trans_of rβ©
end prod
|
7d9e197c19be5f1fe2b774dd7d968699b4d1a76d | 80cc5bf14c8ea85ff340d1d747a127dcadeb966f | /test/qpf.lean | 933eda0695b4a00c0442c10ae54ad615f24e9427 | [
"Apache-2.0"
] | permissive | lacker/mathlib | f2439c743c4f8eb413ec589430c82d0f73b2d539 | ddf7563ac69d42cfa4a1bfe41db1fed521bd795f | refs/heads/master | 1,671,948,326,773 | 1,601,479,268,000 | 1,601,479,268,000 | 298,686,743 | 0 | 0 | Apache-2.0 | 1,601,070,794,000 | 1,601,070,794,000 | null | UTF-8 | Lean | false | false | 6,194 | lean | import data.qpf.univariate.basic
import control.bifunctor
universes u
variables {F : Type u β Type u} [functor F]
namespace qpf
section box
variables (F)
/-- apply a functor to a set of values. taken from
[Basil FΓΌrer, Andreas Lochbihler, Joshua Schneider, Dmitriy Traytel *Quotients of Bounded Natural Functors*][fuerer-lochbihler-schneider-traytel2020]
henceforth referred to as the QBNF paper
-/
def box {Ξ±} (A : set Ξ±) : set (F Ξ±) :=
{ x | β Ξ² (f g : Ξ± β Ξ²), (β a β A, f a = g a) β f <$> x = g <$> x }
variables {F}
/--
Alternate notion of support set based on `box`.
Taken from the QBNF paper
-/
def supp' {Ξ±} (x : F Ξ±) : set Ξ± :=
β A β { A : set Ξ± | x β box F A}, A
/--
Alternate notion of predicate lifting based on `box`.
Taken from the QBNF paper
-/
def liftp' {Ξ±} (x : F Ξ±) (p : Ξ± β Prop) : Prop :=
β a β supp' x, p a
end box
end qpf
namespace ex
/-- polynomial functor isomorph to `Ξ± Γ _` for some `Ξ±` -/
def prod.pfunctor (Ξ± : Type) : pfunctor :=
β¨ Ξ±, Ξ» _, unit β©
instance {Ξ±} : qpf (prod Ξ±) :=
{ P := prod.pfunctor Ξ±,
abs := Ξ» Ξ² β¨a,fβ©, (a, f ()),
repr := Ξ» Ξ² β¨x,yβ©, β¨x, Ξ» _, yβ©,
abs_repr := Ξ» Ξ² β¨x,yβ©, rfl,
abs_map := Ξ» Ξ² Ξ³ f β¨a,gβ©, rfl }
/-- example relation for products -/
def foo.R (Ξ± : Type) (x y : bool Γ Ξ±) : Prop :=
x.1 = y.1 β§ (x.1 β x.2 = y.2)
lemma equivalence_foo.R (Ξ±) : equivalence (foo.R Ξ±) :=
begin
refine β¨_,_,_β©,
{ intro, exact β¨rfl,Ξ» _, rflβ© },
{ intros x y h, refine β¨h.1.symm, Ξ» _, (h.2 _).symmβ©,
rwa h.1 },
{ rintros x y z β¨ha,ha'β© β¨hb,hb'β©,
refine β¨ha.trans hb, Ξ» hh, _β©,
refine (ha' hh).trans (hb' _),
rwa β ha }
end
/-- example of a qpf -/
def foo (Ξ± : Type) :=
quot $ foo.R Ξ±
instance {Ξ±} [inhabited Ξ±] : inhabited (foo Ξ±) := β¨ quot.mk _ (default _) β©
/-- functor operation of `foo` -/
def foo.map {Ξ± Ξ²} (f : Ξ± β Ξ²) (x : foo Ξ±) : foo Ξ² :=
quot.lift_on x (Ξ» x : bool Γ Ξ±, quot.mk (foo.R Ξ²) $ f <$> x)
(Ξ» β¨aβ,aββ© β¨bβ,bββ© h, quot.sound β¨h.1,Ξ» h', show f aβ = f bβ, from congr_arg f (h.2 h')β©)
instance : functor foo :=
{ map := @foo.map }
@[simp]
lemma foo.map_mk {Ξ± Ξ² : Type} (f : Ξ± β Ξ²) (x : bool Γ Ξ±) :
(f <$> quot.mk _ x : foo Ξ²) = quot.mk _ (f <$> x) :=
by simp [(<$>),foo.map]
noncomputable instance qpf.foo : qpf foo :=
@qpf.quotient_qpf (prod bool) _ ex.qpf foo _ (Ξ» Ξ±, quot.mk _) (Ξ» Ξ±, quot.out)
(by simp)
(by intros; simp)
/-- constructor for `foo` -/
def foo.mk {Ξ±} (b : bool) (x : Ξ±) : foo Ξ± := quot.mk _ (b, x)
@[simp]
lemma foo.map_mk' {Ξ± Ξ² : Type} (f : Ξ± β Ξ²) (b : bool) (x : Ξ±) :
f <$> foo.mk b x = foo.mk b (f x) :=
by simp only [foo.mk, foo.map_mk]; refl
@[simp]
lemma foo.map_tt {Ξ± : Type} (x y : Ξ±) :
foo.mk tt x = foo.mk tt y β x = y :=
by simp [foo.mk]; split; intro h; [replace h := quot.exact _ h, rw h];
rw relation.eqv_gen_iff_of_equivalence at h;
[exact h.2 rfl, apply equivalence_foo.R]
/-- consequence of original definition of `supp`. If there exists more than
one value of type `Ξ±`, then the support of `foo.mk ff x` is empty -/
lemma supp_mk_ffβ {Ξ±} (x y : Ξ±) (h : Β¬ x = y) : functor.supp (foo.mk ff x) = {} :=
begin
dsimp [functor.supp], ext z, simp, -- split; intro h,
classical, by_cases x = z,
{ use (Ξ» a, Β¬ z = a), subst z,
dsimp [functor.liftp],
simp, refine β¨foo.mk ff β¨y,hβ©,_β©,
simp, apply quot.sound, simp [foo.R] },
{ use (Ξ» a, x = a),
dsimp [functor.liftp],
simp [h], use foo.mk ff β¨x,rflβ©,
simp }
end
/-- consequence of original definition of `supp`. If there exists only
one value of type `Ξ±`, then the support of `foo.mk ff x` contains that value -/
lemma supp_mk_ffβ {Ξ±} (x : Ξ±) (h : β z, x = z) : functor.supp (foo.mk ff x) = {x} :=
begin
dsimp [functor.supp], ext y, simp, split; intro h',
{ apply @h' (= x), dsimp [functor.liftp],
use foo.mk ff β¨x,rflβ©, refl },
{ introv hp, simp [functor.liftp] at hp,
rcases hp with β¨β¨z,z',hzβ©,hpβ©,
simp at hp, convert hz,
rw [h'], apply h },
end
/--
Such a QPF is not uniform
-/
lemma foo_not_uniform : Β¬ @qpf.is_uniform foo _ qpf.foo :=
begin
simp only [qpf.is_uniform, foo, qpf.foo, set.image_univ, not_forall, not_imp],
existsi [bool,ff,ff,Ξ» a : unit, tt,Ξ» a : unit, ff], split,
{ apply quot.sound, simp [foo.R,qpf.abs,qpf._match_1], },
{ simp! only [set.range, set.ext_iff],
simp only [not_exists, false_iff, bool.forall_bool, eq_self_iff_true, exists_false, not_true,
and_self, set.mem_set_of_eq, iff_false],
exact Ξ» h, h () }
end
/-- intuitive consequence of original definition of `supp`. -/
lemma supp_mk_tt {Ξ±} (x : Ξ±) : functor.supp (foo.mk tt x) = {x} :=
begin
dsimp [functor.supp], ext y, simp, split; intro h',
{ apply @h' (= x), dsimp [functor.liftp],
use foo.mk tt β¨x,rflβ©, refl },
{ introv hp, simp [functor.liftp] at hp,
rcases hp with β¨β¨z,z',hzβ©,hpβ©,
simp at hp, replace hp := quot.exact _ hp,
rw relation.eqv_gen_iff_of_equivalence (equivalence_foo.R _) at hp,
rcases hp with β¨β¨β©,hpβ©, subst y,
replace hp := hp rfl, cases hp,
exact hz }
end
/-- simple consequence of the definition of `supp` from the QBNF paper -/
lemma supp_mk_ff' {Ξ±} (x : Ξ±) : qpf.supp' (foo.mk ff x) = {} :=
begin
dsimp [qpf.supp'], ext, simp, dsimp [qpf.box],
use β
, simp [foo.mk], intros, apply quot.sound,
dsimp [foo.R], split, refl, rintro β¨ β©
end
/-- simple consequence of the definition of `supp` from the QBNF paper -/
lemma supp_mk_tt' {Ξ±} (x : Ξ±) : qpf.supp' (foo.mk tt x) = {x} :=
begin
dsimp [qpf.supp'], ext, simp, dsimp [qpf.box], split; intro h,
{ specialize h {x} _, { simp at h, assumption },
clear h, introv hfg, simp, rw hfg, simp },
{ introv hfg, subst x_1, classical,
let f : Ξ± β Ξ± β bool := Ξ» x, if x β i then sum.inl x else sum.inr tt,
let g : Ξ± β Ξ± β bool := Ξ» x, if x β i then sum.inl x else sum.inr ff,
specialize hfg _ f g _,
{ simp [f,g] at hfg, split_ifs at hfg,
assumption, cases hfg },
{ intros, simp [*,f,g,if_pos] } }
end
end ex
|
8b1741b22cb8c372307644e29915cd507c481298 | ff5230333a701471f46c57e8c115a073ebaaa448 | /library/init/data/option/basic.lean | 4d15ea7218fd2e788104873b308be8722946c462 | [
"Apache-2.0"
] | permissive | stanford-cs242/lean | f81721d2b5d00bc175f2e58c57b710d465e6c858 | 7bd861261f4a37326dcf8d7a17f1f1f330e4548c | refs/heads/master | 1,600,957,431,849 | 1,576,465,093,000 | 1,576,465,093,000 | 225,779,423 | 0 | 3 | Apache-2.0 | 1,575,433,936,000 | 1,575,433,935,000 | null | UTF-8 | Lean | false | false | 2,243 | lean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.logic init.category.monad init.category.alternative
open decidable
universes u v
namespace option
def to_monad {m : Type β Type} [monad m] [alternative m] {A} : option A β m A
| none := failure
| (some a) := return a
def get_or_else {Ξ± : Type u} : option Ξ± β Ξ± β Ξ±
| (some x) _ := x
| none e := e
def is_some {Ξ± : Type u} : option Ξ± β bool
| (some _) := tt
| none := ff
def is_none {Ξ± : Type u} : option Ξ± β bool
| (some _) := ff
| none := tt
def get {Ξ± : Type u} : Ξ {o : option Ξ±}, is_some o β Ξ±
| (some x) h := x
| none h := false.rec _ $ bool.ff_ne_tt h
def rhoare {Ξ± : Type u} : bool β Ξ± β option Ξ±
| tt a := none
| ff a := some a
def lhoare {Ξ± : Type u} : Ξ± β option Ξ± β Ξ±
| a none := a
| _ (some b) := b
infixr `|>`:1 := rhoare
infixr `<|`:1 := lhoare
@[inline] protected def bind {Ξ± : Type u} {Ξ² : Type v} : option Ξ± β (Ξ± β option Ξ²) β option Ξ²
| none b := none
| (some a) b := b a
protected def map {Ξ± Ξ²} (f : Ξ± β Ξ²) (o : option Ξ±) : option Ξ² :=
option.bind o (some β f)
theorem map_id {Ξ±} : (option.map id : option Ξ± β option Ξ±) = id :=
funext (Ξ»o, match o with | none := rfl | some x := rfl end)
instance : monad option :=
{pure := @some, bind := @option.bind, map := @option.map}
protected def orelse {Ξ± : Type u} : option Ξ± β option Ξ± β option Ξ±
| (some a) o := some a
| none (some a) := some a
| none none := none
instance : alternative option :=
{ failure := @none,
orelse := @option.orelse }
end option
instance (Ξ± : Type u) : inhabited (option Ξ±) :=
β¨noneβ©
instance {Ξ± : Type u} [d : decidable_eq Ξ±] : decidable_eq (option Ξ±)
| none none := is_true rfl
| none (some vβ) := is_false (Ξ» h, option.no_confusion h)
| (some vβ) none := is_false (Ξ» h, option.no_confusion h)
| (some vβ) (some vβ) :=
match (d vβ vβ) with
| (is_true e) := is_true (congr_arg (@some Ξ±) e)
| (is_false n) := is_false (Ξ» h, option.no_confusion h (Ξ» e, absurd e n))
end
|
7e7567c0e1b316194267fa8f5b6fe311a37cbd2b | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/Lean/Widget/TaggedText.lean | 62708e82cc44ca2ecbececc4eac4962abd89cbcf | [
"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 | 4,302 | lean | /-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Wojciech Nawrocki
-/
import Lean.Data.Json.FromToJson
import Lean.Server.Rpc.Basic
namespace Lean.Widget
open Server
/-- The minimal structure needed to represent "string with interesting (tagged) substrings".
Much like Lean 3 [`sf`](https://github.com/leanprover-community/mathlib/blob/bfa6bbbce69149792cc009ab7f9bc146181dc051/src/tactic/interactive_expr.lean#L38),
but with indentation already stringified. -/
inductive TaggedText (Ξ± : Type u) where
| text : String β TaggedText Ξ±
/-- Invariants:
- non-empty
- no adjacent `text` elements (they should be collapsed)
- no directly nested `append`s (but `append #[tag _ (append ..)]` is okay) -/
| append : Array (TaggedText Ξ±) β TaggedText Ξ±
| tag : Ξ± β TaggedText Ξ± β TaggedText Ξ±
deriving Inhabited, BEq, Repr, FromJson, ToJson
namespace TaggedText
def appendText (sβ : String) : TaggedText Ξ± β TaggedText Ξ±
| text s => text (s ++ sβ)
| append as => match as.back with
| text s => append <| as.set! (as.size - 1) <| text (s ++ sβ)
| _ => append <| as.push (text sβ)
| a => append #[a, text sβ]
def appendTag (acc : TaggedText Ξ±) (tβ : Ξ±) (aβ : TaggedText Ξ±) : TaggedText Ξ± :=
match acc with
| append as => append (as.push <| tag tβ aβ)
| text "" => tag tβ aβ
| a => append #[a, tag tβ aβ]
variable (f : Ξ± β Ξ²) in
partial def map : TaggedText Ξ± β TaggedText Ξ²
| text s => text s
| append as => append (as.map map)
| tag t a => tag (f t) (map a)
variable [Monad m] (f : Ξ± β m Ξ²) in
partial def mapM : TaggedText Ξ± β m (TaggedText Ξ²)
| text s => return text s
| append as => return append (β as.mapM mapM)
| tag t a => return tag (β f t) (β mapM a)
variable (f : Ξ± β TaggedText Ξ± β TaggedText Ξ²) in
partial def rewrite : TaggedText Ξ± β TaggedText Ξ²
| text s => text s
| append as => append (as.map rewrite)
| tag t a => f t a
variable [Monad m] (f : Ξ± β TaggedText Ξ± β m (TaggedText Ξ²)) in
/-- Like `mapM` but allows rewriting the whole subtree at `tag` nodes. -/
partial def rewriteM : TaggedText Ξ± β m (TaggedText Ξ²)
| text s => return text s
| append as => return append (β as.mapM rewriteM)
| tag t a => f t a
instance [RpcEncodable Ξ±] : RpcEncodable (TaggedText Ξ±) where
rpcEncode a := toJson <$> a.mapM rpcEncode
rpcDecode a := do TaggedText.mapM rpcDecode (β fromJson? a)
private structure TaggedState where
out : TaggedText (Nat Γ Nat) := TaggedText.text ""
tagStack : List (Nat Γ Nat Γ TaggedText (Nat Γ Nat)) := []
column : Nat := 0
deriving Inhabited
instance : Std.Format.MonadPrettyFormat (StateM TaggedState) where
pushOutput s := modify fun β¨out, ts, colβ© => β¨out.appendText s, ts, col + s.lengthβ©
pushNewline indent := modify fun β¨out, ts, _β© => β¨out.appendText ("\n".pushn ' ' indent), ts, indentβ©
currColumn := return (βget).column
startTag n := modify fun β¨out, ts, colβ© => β¨TaggedText.text "", (n, col, out) :: ts, colβ©
endTags n := modify fun β¨out, ts, colβ© =>
let (ended, left) := (ts.take n, ts.drop n)
let out' := ended.foldl (init := out) fun acc (n, col', top) => top.appendTag (n, col') acc
β¨out', left, colβ©
/-- The output is tagged with `(tag, indent)` where `tag` is from the input `Format` and `indent`
is the indentation level at this point. The latter is used to print sub-trees accurately by passing
it again as the `indent` argument. -/
def prettyTagged (f : Format) (indent := 0) (w : Nat := Std.Format.defWidth) : TaggedText (Nat Γ Nat) :=
(f.prettyM w indent : StateM TaggedState Unit) {} |>.snd.out
/-- Remove tags, leaving just the pretty-printed string. -/
partial def stripTags (tt : TaggedText Ξ±) : String :=
go "" #[tt]
where go (acc : String) : Array (TaggedText Ξ±) β String
| #[] => acc
| ts => match ts.back with
| text s => go (acc ++ s) ts.pop
| append as => go acc (ts.pop ++ as.reverse)
| tag _ a => go acc (ts.set! (ts.size - 1) a)
end TaggedText
end Lean.Widget
|
02ab58cce294a02cb33c7aae3ac201ca18fe5cdd | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /test/ring.lean | ca22a8dee51747e0217bd695b2eba74fb8bc7485 | [
"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 | 2,847 | lean | import tactic.ring
import data.real.basic
example (x y : β) : x + y = y + x := by ring
example (x y : β) : x + y + y = 2 * y + x := by ring
example (x y : β) : x + id y = y + id x := by ring!
example {Ξ±} [comm_ring Ξ±] (x y : Ξ±) : x + y + y - x = 2 * y := by ring
example (x y : β) : x / 2 + x / 2 = x := by ring
example (x y : β) : (x + y) ^ 3 = x ^ 3 + y ^ 3 + 3 * (x * y ^ 2 + x ^ 2 * y) := by ring
example (x y : β) : (x + y) ^ 3 = x ^ 3 + y ^ 3 + 3 * (x * y ^ 2 + x ^ 2 * y) := by ring
example {Ξ±} [comm_semiring Ξ±] (x : Ξ±) : (x + 1) ^ 6 = (1 + x) ^ 6 := by try_for 15000 {ring}
example (n : β) : (n / 2) + (n / 2) = 2 * (n / 2) := by ring
example {Ξ±} [field Ξ±] [char_zero Ξ±] (a : Ξ±) : a / 2 = a / 2 := by ring
example {Ξ±} [linear_ordered_field Ξ±] (a b c : Ξ±) :
a * (-c / b) * (-c / b) + -c + c = a * (c / b * (c / b)) := by ring
example {Ξ±} [linear_ordered_field Ξ±] (a b c : Ξ±) :
b ^ 2 - 4 * c * a = -(4 * c * a) + b ^ 2 := by ring
example (x : β) : x ^ (2 + 2) = x^4 := by ring_nf -- TODO: ring should work?
example {Ξ±} [comm_ring Ξ±] (x : Ξ±) : x ^ 2 = x * x := by ring
example {Ξ±} [linear_ordered_field Ξ±] (a b c : Ξ±) :
b ^ 2 - 4 * c * a = -(4 * c * a) + b ^ 2 := by ring
example {Ξ±} [linear_ordered_field Ξ±] (a b c : Ξ±) :
b ^ 2 - 4 * a * c = 4 * a * 0 + b * b - 4 * a * c := by ring
example {Ξ±} [comm_semiring Ξ±] (x y z : Ξ±) (n : β) :
(x + y) * (z * (y * y) + (x * x ^ n + (1 + βn) * x ^ n * y)) =
x * (x * x ^ n) + ((2 + βn) * (x * x ^ n) * y + (x * z + (z * y + (1 + βn) * x ^ n)) * (y * y)) := by ring
example {Ξ±} [comm_ring Ξ±] (a b c d e : Ξ±) :
(-(a * b) + c + d) * e = (c + (d + -a * b)) * e := by ring
example (a n s: β) : a * (n - s) = (n - s) * a := by ring
example (x y z : β) (hx : x β 0) (hy : y β 0) (hz : z β 0) :
x / (y / z) + y β»ΒΉ + 1 / (y * -x) = -1/ (x * y) + (x * z + 1) / y :=
begin
field_simp,
ring
end
example (a b c d x y : β) (hx : x β 0) (hy : y β 0) :
a + b / x - c / x^2 + d / x^3 = a + xβ»ΒΉ * (y * b / y + (d / x - c) / x) :=
begin
field_simp,
ring
end
example : (876544 : β€) * -1 + (1000000 - 123456) = 0 := by ring
example (x y : β) (hx : x β 0) (hy : y β 0) :
2 * x ^ 3 * 2 / (24 * x) = x ^ 2 / 6 :=
begin
field_simp,
ring
end
-- this proof style is not recommended practice
example (A B : β) (H : B * A = 2) : A * B = 2 := by {ring_nf, exact H}
example (a : β€) : odd ((2 * a + 1) ^ 2) :=
begin
use 2 * a ^ 2 + 2 * a,
ring_nf,
end
example {x y : β}
(hxy : -y ^ 2 + x ^ 2 = -(5 * y) + 5 * x) :
x ^ 2 - y ^ 2 = 5 * x - 5 * y :=
begin
ring_nf at hxy β’,
exact hxy
end
example {Ξ±} [field Ξ±] {x y : Ξ±}
(h : 0 = (1 - x) ^ 2 * (x * (2 ^ 2 * y ^ 2 + 4 * (1 - x) ^ 2))) :
0 = x * ((2 ^ 2 * y ^ 2 + 4 * (1 - x) ^ 2) * (1 - x) ^ 2) :=
by transitivity; [exact h, ring]
|
9701f71b5f937781a008f8104b7df4e769284894 | d29d82a0af640c937e499f6be79fc552eae0aa13 | /src/linear_algebra/multilinear.lean | b1fd208c4e8bcafaaf3f23b446469f282e822cb5 | [
"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 | 54,196 | lean | /-
Copyright (c) 2020 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel
-/
import linear_algebra.basic
import algebra.algebra.basic
import algebra.big_operators.order
import data.fintype.sort
/-!
# Multilinear maps
We define multilinear maps as maps from `Ξ (i : ΞΉ), Mβ i` to `Mβ` which are linear in each
coordinate. Here, `Mβ i` and `Mβ` are modules over a ring `R`, and `ΞΉ` is an arbitrary type
(although some statements will require it to be a fintype). This space, denoted by
`multilinear_map R Mβ Mβ`, inherits a module structure by pointwise addition and multiplication.
## Main definitions
* `multilinear_map R Mβ Mβ` is the space of multilinear maps from `Ξ (i : ΞΉ), Mβ i` to `Mβ`.
* `f.map_smul` is the multiplicativity of the multilinear map `f` along each coordinate.
* `f.map_add` is the additivity of the multilinear map `f` along each coordinate.
* `f.map_smul_univ` expresses the multiplicativity of `f` over all coordinates at the same time,
writing `f (Ξ»i, c i β’ m i)` as `(β i, c i) β’ f m`.
* `f.map_add_univ` expresses the additivity of `f` over all coordinates at the same time, writing
`f (m + m')` as the sum over all subsets `s` of `ΞΉ` of `f (s.piecewise m m')`.
* `f.map_sum` expresses `f (Ξ£_{jβ} gβ jβ, ..., Ξ£_{jβ} gβ jβ)` as the sum of
`f (gβ (r 1), ..., gβ (r n))` where `r` ranges over all possible functions.
We also register isomorphisms corresponding to currying or uncurrying variables, transforming a
multilinear function `f` on `n+1` variables into a linear function taking values in multilinear
functions in `n` variables, and into a multilinear function in `n` variables taking values in linear
functions. These operations are called `f.curry_left` and `f.curry_right` respectively
(with inverses `f.uncurry_left` and `f.uncurry_right`). These operations induce linear equivalences
between spaces of multilinear functions in `n+1` variables and spaces of linear functions into
multilinear functions in `n` variables (resp. multilinear functions in `n` variables taking values
in linear functions), called respectively `multilinear_curry_left_equiv` and
`multilinear_curry_right_equiv`.
## Implementation notes
Expressing that a map is linear along the `i`-th coordinate when all other coordinates are fixed
can be done in two (equivalent) different ways:
* fixing a vector `m : Ξ (j : ΞΉ - i), Mβ j.val`, and then choosing separately the `i`-th coordinate
* fixing a vector `m : Ξ j, Mβ j`, and then modifying its `i`-th coordinate
The second way is more artificial as the value of `m` at `i` is not relevant, but it has the
advantage of avoiding subtype inclusion issues. This is the definition we use, based on
`function.update` that allows to change the value of `m` at `i`.
-/
open function fin set
open_locale big_operators
universes u v v' vβ vβ vβ w u'
variables {R : Type u} {ΞΉ : Type u'} {n : β}
{M : fin n.succ β Type v} {Mβ : ΞΉ β Type vβ} {Mβ : Type vβ} {Mβ : Type vβ} {M' : Type v'}
[decidable_eq ΞΉ]
/-- Multilinear maps over the ring `R`, from `Ξ i, Mβ i` to `Mβ` where `Mβ i` and `Mβ` are modules
over `R`. -/
structure multilinear_map (R : Type u) {ΞΉ : Type u'} (Mβ : ΞΉ β Type v) (Mβ : Type w)
[decidable_eq ΞΉ] [semiring R] [βi, add_comm_monoid (Mβ i)] [add_comm_monoid Mβ]
[βi, module R (Mβ i)] [module R Mβ] :=
(to_fun : (Ξ i, Mβ i) β Mβ)
(map_add' : β(m : Ξ i, Mβ i) (i : ΞΉ) (x y : Mβ i),
to_fun (update m i (x + y)) = to_fun (update m i x) + to_fun (update m i y))
(map_smul' : β(m : Ξ i, Mβ i) (i : ΞΉ) (c : R) (x : Mβ i),
to_fun (update m i (c β’ x)) = c β’ to_fun (update m i x))
namespace multilinear_map
section semiring
variables [semiring R]
[βi, add_comm_monoid (M i)] [βi, add_comm_monoid (Mβ i)] [add_comm_monoid Mβ] [add_comm_monoid Mβ]
[add_comm_monoid M']
[βi, module R (M i)] [βi, module R (Mβ i)] [module R Mβ] [module R Mβ]
[module R M']
(f f' : multilinear_map R Mβ Mβ)
instance : has_coe_to_fun (multilinear_map R Mβ Mβ) := β¨_, to_funβ©
initialize_simps_projections multilinear_map (to_fun β apply)
@[simp] lemma to_fun_eq_coe : f.to_fun = f := rfl
@[simp] lemma coe_mk (f : (Ξ i, Mβ i) β Mβ) (hβ hβ ) :
β(β¨f, hβ, hββ© : multilinear_map R Mβ Mβ) = f := rfl
theorem congr_fun {f g : multilinear_map R Mβ Mβ} (h : f = g) (x : Ξ i, Mβ i) : f x = g x :=
congr_arg (Ξ» h : multilinear_map R Mβ Mβ, h x) h
theorem congr_arg (f : multilinear_map R Mβ Mβ) {x y : Ξ i, Mβ i} (h : x = y) : f x = f y :=
congr_arg (Ξ» x : Ξ i, Mβ i, f x) h
theorem coe_inj β¦f g : multilinear_map R Mβ Mββ¦ (h : βf = g) : f = g :=
by cases f; cases g; cases h; refl
@[ext] theorem ext {f f' : multilinear_map R Mβ Mβ} (H : β x, f x = f' x) : f = f' :=
coe_inj (funext H)
theorem ext_iff {f g : multilinear_map R Mβ Mβ} : f = g β β x, f x = g x :=
β¨Ξ» h x, h βΈ rfl, Ξ» h, ext hβ©
@[simp] lemma map_add (m : Ξ i, Mβ i) (i : ΞΉ) (x y : Mβ i) :
f (update m i (x + y)) = f (update m i x) + f (update m i y) :=
f.map_add' m i x y
@[simp] lemma map_smul (m : Ξ i, Mβ i) (i : ΞΉ) (c : R) (x : Mβ i) :
f (update m i (c β’ x)) = c β’ f (update m i x) :=
f.map_smul' m i c x
lemma map_coord_zero {m : Ξ i, Mβ i} (i : ΞΉ) (h : m i = 0) : f m = 0 :=
begin
have : (0 : R) β’ (0 : Mβ i) = 0, by simp,
rw [β update_eq_self i m, h, β this, f.map_smul, zero_smul]
end
@[simp] lemma map_update_zero (m : Ξ i, Mβ i) (i : ΞΉ) : f (update m i 0) = 0 :=
f.map_coord_zero i (update_same i 0 m)
@[simp] lemma map_zero [nonempty ΞΉ] : f 0 = 0 :=
begin
obtain β¨i, _β© : βi:ΞΉ, i β set.univ := set.exists_mem_of_nonempty ΞΉ,
exact map_coord_zero f i rfl
end
instance : has_add (multilinear_map R Mβ Mβ) :=
β¨Ξ»f f', β¨Ξ»x, f x + f' x, Ξ»m i x y, by simp [add_left_comm, add_assoc],
Ξ»m i c x, by simp [smul_add]β©β©
@[simp] lemma add_apply (m : Ξ i, Mβ i) : (f + f') m = f m + f' m := rfl
instance : has_zero (multilinear_map R Mβ Mβ) :=
β¨β¨Ξ» _, 0, Ξ»m i x y, by simp, Ξ»m i c x, by simpβ©β©
instance : inhabited (multilinear_map R Mβ Mβ) := β¨0β©
@[simp] lemma zero_apply (m : Ξ i, Mβ i) : (0 : multilinear_map R Mβ Mβ) m = 0 := rfl
instance : add_comm_monoid (multilinear_map R Mβ Mβ) :=
{ zero := (0 : multilinear_map R Mβ Mβ),
add := (+),
add_assoc := by intros; ext; simp [add_comm, add_left_comm],
zero_add := by intros; ext; simp [add_comm, add_left_comm],
add_zero := by intros; ext; simp [add_comm, add_left_comm],
add_comm := by intros; ext; simp [add_comm, add_left_comm],
nsmul := Ξ» n f, β¨Ξ» m, n β’ f m, Ξ»m i x y, by simp [smul_add], Ξ»l i x d, by simp [βsmul_comm x n] β©,
nsmul_zero' := Ξ» f, by { ext, simp },
nsmul_succ' := Ξ» n f, by { ext, simp [add_smul, nat.succ_eq_one_add] } }
@[simp] lemma sum_apply {Ξ± : Type*} (f : Ξ± β multilinear_map R Mβ Mβ)
(m : Ξ i, Mβ i) : β {s : finset Ξ±}, (β a in s, f a) m = β a in s, f a m :=
begin
classical,
apply finset.induction,
{ rw finset.sum_empty, simp },
{ assume a s has H, rw finset.sum_insert has, simp [H, has] }
end
/-- If `f` is a multilinear map, then `f.to_linear_map m i` is the linear map obtained by fixing all
coordinates but `i` equal to those of `m`, and varying the `i`-th coordinate. -/
def to_linear_map (m : Ξ i, Mβ i) (i : ΞΉ) : Mβ i ββ[R] Mβ :=
{ to_fun := Ξ»x, f (update m i x),
map_add' := Ξ»x y, by simp,
map_smul' := Ξ»c x, by simp }
/-- The cartesian product of two multilinear maps, as a multilinear map. -/
def prod (f : multilinear_map R Mβ Mβ) (g : multilinear_map R Mβ Mβ) :
multilinear_map R Mβ (Mβ Γ Mβ) :=
{ to_fun := Ξ» m, (f m, g m),
map_add' := Ξ» m i x y, by simp,
map_smul' := Ξ» m i c x, by simp }
/-- Combine a family of multilinear maps with the same domain and codomains `M' i` into a
multilinear map taking values in the space of functions `Ξ i, M' i`. -/
@[simps] def pi {ΞΉ' : Type*} {M' : ΞΉ' β Type*} [Ξ i, add_comm_monoid (M' i)]
[Ξ i, module R (M' i)] (f : Ξ i, multilinear_map R Mβ (M' i)) :
multilinear_map R Mβ (Ξ i, M' i) :=
{ to_fun := Ξ» m i, f i m,
map_add' := Ξ» m i x y, funext $ Ξ» j, (f j).map_add _ _ _ _,
map_smul' := Ξ» m i c x, funext $ Ξ» j, (f j).map_smul _ _ _ _ }
/-- Given a multilinear map `f` on `n` variables (parameterized by `fin n`) and a subset `s` of `k`
of these variables, one gets a new multilinear map on `fin k` by varying these variables, and fixing
the other ones equal to a given value `z`. It is denoted by `f.restr s hk z`, where `hk` is a
proof that the cardinality of `s` is `k`. The implicit identification between `fin k` and `s` that
we use is the canonical (increasing) bijection. -/
def restr {k n : β} (f : multilinear_map R (Ξ» i : fin n, M') Mβ) (s : finset (fin n))
(hk : s.card = k) (z : M') :
multilinear_map R (Ξ» i : fin k, M') Mβ :=
{ to_fun := Ξ» v, f (Ξ» j, if h : j β s then v ((s.order_iso_of_fin hk).symm β¨j, hβ©) else z),
map_add' := Ξ» v i x y,
by { erw [dite_comp_equiv_update, dite_comp_equiv_update, dite_comp_equiv_update], simp },
map_smul' := Ξ» v i c x, by { erw [dite_comp_equiv_update, dite_comp_equiv_update], simp } }
variable {R}
/-- In the specific case of multilinear maps on spaces indexed by `fin (n+1)`, where one can build
an element of `Ξ (i : fin (n+1)), M i` using `cons`, one can express directly the additivity of a
multilinear map along the first variable. -/
lemma cons_add (f : multilinear_map R M Mβ) (m : Ξ (i : fin n), M i.succ) (x y : M 0) :
f (cons (x+y) m) = f (cons x m) + f (cons y m) :=
by rw [β update_cons_zero x m (x+y), f.map_add, update_cons_zero, update_cons_zero]
/-- In the specific case of multilinear maps on spaces indexed by `fin (n+1)`, where one can build
an element of `Ξ (i : fin (n+1)), M i` using `cons`, one can express directly the multiplicativity
of a multilinear map along the first variable. -/
lemma cons_smul (f : multilinear_map R M Mβ) (m : Ξ (i : fin n), M i.succ) (c : R) (x : M 0) :
f (cons (c β’ x) m) = c β’ f (cons x m) :=
by rw [β update_cons_zero x m (c β’ x), f.map_smul, update_cons_zero]
/-- In the specific case of multilinear maps on spaces indexed by `fin (n+1)`, where one can build
an element of `Ξ (i : fin (n+1)), M i` using `snoc`, one can express directly the additivity of a
multilinear map along the first variable. -/
lemma snoc_add (f : multilinear_map R M Mβ) (m : Ξ (i : fin n), M i.cast_succ) (x y : M (last n)) :
f (snoc m (x+y)) = f (snoc m x) + f (snoc m y) :=
by rw [β update_snoc_last x m (x+y), f.map_add, update_snoc_last, update_snoc_last]
/-- In the specific case of multilinear maps on spaces indexed by `fin (n+1)`, where one can build
an element of `Ξ (i : fin (n+1)), M i` using `cons`, one can express directly the multiplicativity
of a multilinear map along the first variable. -/
lemma snoc_smul (f : multilinear_map R M Mβ)
(m : Ξ (i : fin n), M i.cast_succ) (c : R) (x : M (last n)) :
f (snoc m (c β’ x)) = c β’ f (snoc m x) :=
by rw [β update_snoc_last x m (c β’ x), f.map_smul, update_snoc_last]
section
variables {Mβ' : ΞΉ β Type*} [Ξ i, add_comm_monoid (Mβ' i)] [Ξ i, module R (Mβ' i)]
/-- If `g` is a multilinear map and `f` is a collection of linear maps,
then `g (fβ mβ, ..., fβ mβ)` is again a multilinear map, that we call
`g.comp_linear_map f`. -/
def comp_linear_map (g : multilinear_map R Mβ' Mβ) (f : Ξ i, Mβ i ββ[R] Mβ' i) :
multilinear_map R Mβ Mβ :=
{ to_fun := Ξ» m, g $ Ξ» i, f i (m i),
map_add' := Ξ» m i x y,
have β j z, f j (update m i z j) = update (Ξ» k, f k (m k)) i (f i z) j :=
Ξ» j z, function.apply_update (Ξ» k, f k) _ _ _ _,
by simp [this],
map_smul' := Ξ» m i c x,
have β j z, f j (update m i z j) = update (Ξ» k, f k (m k)) i (f i z) j :=
Ξ» j z, function.apply_update (Ξ» k, f k) _ _ _ _,
by simp [this] }
@[simp] lemma comp_linear_map_apply (g : multilinear_map R Mβ' Mβ) (f : Ξ i, Mβ i ββ[R] Mβ' i)
(m : Ξ i, Mβ i) :
g.comp_linear_map f m = g (Ξ» i, f i (m i)) :=
rfl
end
/-- If one adds to a vector `m'` another vector `m`, but only for coordinates in a finset `t`, then
the image under a multilinear map `f` is the sum of `f (s.piecewise m m')` along all subsets `s` of
`t`. This is mainly an auxiliary statement to prove the result when `t = univ`, given in
`map_add_univ`, although it can be useful in its own right as it does not require the index set `ΞΉ`
to be finite.-/
lemma map_piecewise_add (m m' : Ξ i, Mβ i) (t : finset ΞΉ) :
f (t.piecewise (m + m') m') = β s in t.powerset, f (s.piecewise m m') :=
begin
revert m',
refine finset.induction_on t (by simp) _,
assume i t hit Hrec m',
have A : (insert i t).piecewise (m + m') m' = update (t.piecewise (m + m') m') i (m i + m' i) :=
t.piecewise_insert _ _ _,
have B : update (t.piecewise (m + m') m') i (m' i) = t.piecewise (m + m') m',
{ ext j,
by_cases h : j = i,
{ rw h, simp [hit] },
{ simp [h] } },
let m'' := update m' i (m i),
have C : update (t.piecewise (m + m') m') i (m i) = t.piecewise (m + m'') m'',
{ ext j,
by_cases h : j = i,
{ rw h, simp [m'', hit] },
{ by_cases h' : j β t; simp [h, hit, m'', h'] } },
rw [A, f.map_add, B, C, finset.sum_powerset_insert hit, Hrec, Hrec, add_comm],
congr' 1,
apply finset.sum_congr rfl (Ξ»s hs, _),
have : (insert i s).piecewise m m' = s.piecewise m m'',
{ ext j,
by_cases h : j = i,
{ rw h, simp [m'', finset.not_mem_of_mem_powerset_of_not_mem hs hit] },
{ by_cases h' : j β s; simp [h, m'', h'] } },
rw this
end
/-- Additivity of a multilinear map along all coordinates at the same time,
writing `f (m + m')` as the sum of `f (s.piecewise m m')` over all sets `s`. -/
lemma map_add_univ [fintype ΞΉ] (m m' : Ξ i, Mβ i) :
f (m + m') = β s : finset ΞΉ, f (s.piecewise m m') :=
by simpa using f.map_piecewise_add m m' finset.univ
section apply_sum
variables {Ξ± : ΞΉ β Type*} (g : Ξ i, Ξ± i β Mβ i) (A : Ξ i, finset (Ξ± i))
open_locale classical
open fintype finset
/-- If `f` is multilinear, then `f (Ξ£_{jβ β Aβ} gβ jβ, ..., Ξ£_{jβ β Aβ} gβ jβ)` is the sum of
`f (gβ (r 1), ..., gβ (r n))` where `r` ranges over all functions with `r 1 β Aβ`, ...,
`r n β Aβ`. This follows from multilinearity by expanding successively with respect to each
coordinate. Here, we give an auxiliary statement tailored for an inductive proof. Use instead
`map_sum_finset`. -/
lemma map_sum_finset_aux [fintype ΞΉ] {n : β} (h : β i, (A i).card = n) :
f (Ξ» i, β j in A i, g i j) = β r in pi_finset A, f (Ξ» i, g i (r i)) :=
begin
induction n using nat.strong_induction_on with n IH generalizing A,
-- If one of the sets is empty, then all the sums are zero
by_cases Ai_empty : β i, A i = β
,
{ rcases Ai_empty with β¨i, hiβ©,
have : β j in A i, g i j = 0, by convert sum_empty,
rw f.map_coord_zero i this,
have : pi_finset A = β
,
{ apply finset.eq_empty_of_forall_not_mem (Ξ» r hr, _),
have : r i β A i := mem_pi_finset.mp hr i,
rwa hi at this },
convert sum_empty.symm },
push_neg at Ai_empty,
-- Otherwise, if all sets are at most singletons, then they are exactly singletons and the result
-- is again straightforward
by_cases Ai_singleton : β i, (A i).card β€ 1,
{ have Ai_card : β i, (A i).card = 1,
{ assume i,
have pos : finset.card (A i) β 0, by simp [finset.card_eq_zero, Ai_empty i],
have : finset.card (A i) β€ 1 := Ai_singleton i,
exact le_antisymm this (nat.succ_le_of_lt (_root_.pos_iff_ne_zero.mpr pos)) },
have : β (r : Ξ i, Ξ± i), r β pi_finset A β f (Ξ» i, g i (r i)) = f (Ξ» i, β j in A i, g i j),
{ assume r hr,
unfold_coes,
congr' with i,
have : β j β A i, g i j = g i (r i),
{ assume j hj,
congr,
apply finset.card_le_one_iff.1 (Ai_singleton i) hj,
exact mem_pi_finset.mp hr i },
simp only [finset.sum_congr rfl this, finset.mem_univ, finset.sum_const, Ai_card i,
one_nsmul] },
simp only [sum_congr rfl this, Ai_card, card_pi_finset, prod_const_one, one_nsmul,
finset.sum_const] },
-- Remains the interesting case where one of the `A i`, say `A iβ`, has cardinality at least 2.
-- We will split into two parts `B iβ` and `C iβ` of smaller cardinality, let `B i = C i = A i`
-- for `i β iβ`, apply the inductive assumption to `B` and `C`, and add up the corresponding
-- parts to get the sum for `A`.
push_neg at Ai_singleton,
obtain β¨iβ, hiββ© : β i, 1 < (A i).card := Ai_singleton,
obtain β¨jβ, jβ, hjβ, hjβ, jβ_ne_jββ© : β jβ jβ, (jβ β A iβ) β§ (jβ β A iβ) β§ jβ β jβ :=
finset.one_lt_card_iff.1 hiβ,
let B := function.update A iβ (A iβ \ {jβ}),
let C := function.update A iβ {jβ},
have B_subset_A : β i, B i β A i,
{ assume i,
by_cases hi : i = iβ,
{ rw hi, simp only [B, sdiff_subset, update_same]},
{ simp only [hi, B, update_noteq, ne.def, not_false_iff, finset.subset.refl] } },
have C_subset_A : β i, C i β A i,
{ assume i,
by_cases hi : i = iβ,
{ rw hi, simp only [C, hjβ, finset.singleton_subset_iff, update_same] },
{ simp only [hi, C, update_noteq, ne.def, not_false_iff, finset.subset.refl] } },
-- split the sum at `iβ` as the sum over `B iβ` plus the sum over `C iβ`, to use additivity.
have A_eq_BC : (Ξ» i, β j in A i, g i j) =
function.update (Ξ» i, β j in A i, g i j) iβ (β j in B iβ, g iβ j + β j in C iβ, g iβ j),
{ ext i,
by_cases hi : i = iβ,
{ rw [hi],
simp only [function.update_same],
have : A iβ = B iβ βͺ C iβ,
{ simp only [B, C, function.update_same, finset.sdiff_union_self_eq_union],
symmetry,
simp only [hjβ, finset.singleton_subset_iff, union_eq_left_iff_subset] },
rw this,
apply finset.sum_union,
apply finset.disjoint_right.2 (Ξ» j hj, _),
have : j = jβ, by { dsimp [C] at hj, simpa using hj },
rw this,
dsimp [B],
simp only [mem_sdiff, eq_self_iff_true, not_true, not_false_iff, finset.mem_singleton,
update_same, and_false] },
{ simp [hi] } },
have Beq : function.update (Ξ» i, β j in A i, g i j) iβ (β j in B iβ, g iβ j) =
(Ξ» i, β j in B i, g i j),
{ ext i,
by_cases hi : i = iβ,
{ rw hi, simp only [update_same] },
{ simp only [hi, B, update_noteq, ne.def, not_false_iff] } },
have Ceq : function.update (Ξ» i, β j in A i, g i j) iβ (β j in C iβ, g iβ j) =
(Ξ» i, β j in C i, g i j),
{ ext i,
by_cases hi : i = iβ,
{ rw hi, simp only [update_same] },
{ simp only [hi, C, update_noteq, ne.def, not_false_iff] } },
-- Express the inductive assumption for `B`
have Brec : f (Ξ» i, β j in B i, g i j) = β r in pi_finset B, f (Ξ» i, g i (r i)),
{ have : β i, finset.card (B i) < β i, finset.card (A i),
{ refine finset.sum_lt_sum (Ξ» i hi, finset.card_le_of_subset (B_subset_A i))
β¨iβ, finset.mem_univ _, _β©,
have : {jβ} β A iβ, by simp [hjβ],
simp only [B, finset.card_sdiff this, function.update_same, finset.card_singleton],
exact nat.pred_lt (ne_of_gt (lt_trans nat.zero_lt_one hiβ)) },
rw h at this,
exact IH _ this B rfl },
-- Express the inductive assumption for `C`
have Crec : f (Ξ» i, β j in C i, g i j) = β r in pi_finset C, f (Ξ» i, g i (r i)),
{ have : β i, finset.card (C i) < β i, finset.card (A i) :=
finset.sum_lt_sum (Ξ» i hi, finset.card_le_of_subset (C_subset_A i))
β¨iβ, finset.mem_univ _, by simp [C, hiβ]β©,
rw h at this,
exact IH _ this C rfl },
have D : disjoint (pi_finset B) (pi_finset C),
{ have : disjoint (B iβ) (C iβ), by simp [B, C],
exact pi_finset_disjoint_of_disjoint B C this },
have pi_BC : pi_finset A = pi_finset B βͺ pi_finset C,
{ apply finset.subset.antisymm,
{ assume r hr,
by_cases hriβ : r iβ = jβ,
{ apply finset.mem_union_right,
apply mem_pi_finset.2 (Ξ» i, _),
by_cases hi : i = iβ,
{ have : r iβ β C iβ, by simp [C, hriβ],
convert this },
{ simp [C, hi, mem_pi_finset.1 hr i] } },
{ apply finset.mem_union_left,
apply mem_pi_finset.2 (Ξ» i, _),
by_cases hi : i = iβ,
{ have : r iβ β B iβ,
by simp [B, hriβ, mem_pi_finset.1 hr iβ],
convert this },
{ simp [B, hi, mem_pi_finset.1 hr i] } } },
{ exact finset.union_subset (pi_finset_subset _ _ (Ξ» i, B_subset_A i))
(pi_finset_subset _ _ (Ξ» i, C_subset_A i)) } },
rw A_eq_BC,
simp only [multilinear_map.map_add, Beq, Ceq, Brec, Crec, pi_BC],
rw β finset.sum_union D,
end
/-- If `f` is multilinear, then `f (Ξ£_{jβ β Aβ} gβ jβ, ..., Ξ£_{jβ β Aβ} gβ jβ)` is the sum of
`f (gβ (r 1), ..., gβ (r n))` where `r` ranges over all functions with `r 1 β Aβ`, ...,
`r n β Aβ`. This follows from multilinearity by expanding successively with respect to each
coordinate. -/
lemma map_sum_finset [fintype ΞΉ] :
f (Ξ» i, β j in A i, g i j) = β r in pi_finset A, f (Ξ» i, g i (r i)) :=
f.map_sum_finset_aux _ _ rfl
/-- If `f` is multilinear, then `f (Ξ£_{jβ} gβ jβ, ..., Ξ£_{jβ} gβ jβ)` is the sum of
`f (gβ (r 1), ..., gβ (r n))` where `r` ranges over all functions `r`. This follows from
multilinearity by expanding successively with respect to each coordinate. -/
lemma map_sum [fintype ΞΉ] [β i, fintype (Ξ± i)] :
f (Ξ» i, β j, g i j) = β r : Ξ i, Ξ± i, f (Ξ» i, g i (r i)) :=
f.map_sum_finset g (Ξ» i, finset.univ)
lemma map_update_sum {Ξ± : Type*} (t : finset Ξ±) (i : ΞΉ) (g : Ξ± β Mβ i) (m : Ξ i, Mβ i):
f (update m i (β a in t, g a)) = β a in t, f (update m i (g a)) :=
begin
induction t using finset.induction with a t has ih h,
{ simp },
{ simp [finset.sum_insert has, ih] }
end
end apply_sum
section restrict_scalar
variables (R) {A : Type*} [semiring A] [has_scalar R A] [Ξ (i : ΞΉ), module A (Mβ i)]
[module A Mβ] [β i, is_scalar_tower R A (Mβ i)] [is_scalar_tower R A Mβ]
/-- Reinterpret an `A`-multilinear map as an `R`-multilinear map, if `A` is an algebra over `R`
and their actions on all involved modules agree with the action of `R` on `A`. -/
def restrict_scalars (f : multilinear_map A Mβ Mβ) : multilinear_map R Mβ Mβ :=
{ to_fun := f,
map_add' := f.map_add,
map_smul' := Ξ» m i, (f.to_linear_map m i).map_smul_of_tower }
@[simp] lemma coe_restrict_scalars (f : multilinear_map A Mβ Mβ) :
β(f.restrict_scalars R) = f := rfl
end restrict_scalar
section
variables {ΞΉβ ΞΉβ ΞΉβ : Type*} [decidable_eq ΞΉβ] [decidable_eq ΞΉβ] [decidable_eq ΞΉβ]
/-- Transfer the arguments to a map along an equivalence between argument indices.
The naming is derived from `finsupp.dom_congr`, noting that here the permutation applies to the
domain of the domain. -/
@[simps apply]
def dom_dom_congr (Ο : ΞΉβ β ΞΉβ) (m : multilinear_map R (Ξ» i : ΞΉβ, Mβ) Mβ) :
multilinear_map R (Ξ» i : ΞΉβ, Mβ) Mβ :=
{ to_fun := Ξ» v, m (Ξ» i, v (Ο i)),
map_add' := Ξ» v i a b, by { simp_rw function.update_apply_equiv_apply v, rw m.map_add, },
map_smul' := Ξ» v i a b, by { simp_rw function.update_apply_equiv_apply v, rw m.map_smul, }, }
lemma dom_dom_congr_trans (Οβ : ΞΉβ β ΞΉβ) (Οβ : ΞΉβ β ΞΉβ) (m : multilinear_map R (Ξ» i : ΞΉβ, Mβ) Mβ) :
m.dom_dom_congr (Οβ.trans Οβ) = (m.dom_dom_congr Οβ).dom_dom_congr Οβ := rfl
lemma dom_dom_congr_mul (Οβ : equiv.perm ΞΉβ) (Οβ : equiv.perm ΞΉβ)
(m : multilinear_map R (Ξ» i : ΞΉβ, Mβ) Mβ) :
m.dom_dom_congr (Οβ * Οβ) = (m.dom_dom_congr Οβ).dom_dom_congr Οβ := rfl
/-- `multilinear_map.dom_dom_congr` as an equivalence.
This is declared separately because it does not work with dot notation. -/
@[simps apply symm_apply]
def dom_dom_congr_equiv (Ο : ΞΉβ β ΞΉβ) :
multilinear_map R (Ξ» i : ΞΉβ, Mβ) Mβ β+ multilinear_map R (Ξ» i : ΞΉβ, Mβ) Mβ :=
{ to_fun := dom_dom_congr Ο,
inv_fun := dom_dom_congr Ο.symm,
left_inv := Ξ» m, by {ext, simp},
right_inv := Ξ» m, by {ext, simp},
map_add' := Ξ» a b, by {ext, simp} }
end
end semiring
end multilinear_map
namespace linear_map
variables [semiring R]
[Ξ i, add_comm_monoid (Mβ i)] [add_comm_monoid Mβ] [add_comm_monoid Mβ] [add_comm_monoid M']
[βi, module R (Mβ i)] [module R Mβ] [module R Mβ] [module R M']
/-- Composing a multilinear map with a linear map gives again a multilinear map. -/
def comp_multilinear_map (g : Mβ ββ[R] Mβ) (f : multilinear_map R Mβ Mβ) :
multilinear_map R Mβ Mβ :=
{ to_fun := g β f,
map_add' := Ξ» m i x y, by simp,
map_smul' := Ξ» m i c x, by simp }
@[simp] lemma coe_comp_multilinear_map (g : Mβ ββ[R] Mβ) (f : multilinear_map R Mβ Mβ) :
β(g.comp_multilinear_map f) = g β f := rfl
lemma comp_multilinear_map_apply (g : Mβ ββ[R] Mβ) (f : multilinear_map R Mβ Mβ) (m : Ξ i, Mβ i) :
g.comp_multilinear_map f m = g (f m) := rfl
variables {ΞΉβ ΞΉβ : Type*} [decidable_eq ΞΉβ] [decidable_eq ΞΉβ]
@[simp] lemma comp_multilinear_map_dom_dom_congr (Ο : ΞΉβ β ΞΉβ) (g : Mβ ββ[R] Mβ)
(f : multilinear_map R (Ξ» i : ΞΉβ, M') Mβ) :
(g.comp_multilinear_map f).dom_dom_congr Ο = g.comp_multilinear_map (f.dom_dom_congr Ο) :=
by { ext, simp }
end linear_map
namespace multilinear_map
section comm_semiring
variables [comm_semiring R] [βi, add_comm_monoid (Mβ i)] [βi, add_comm_monoid (M i)]
[add_comm_monoid Mβ] [βi, module R (M i)] [βi, module R (Mβ i)] [module R Mβ]
(f f' : multilinear_map R Mβ Mβ)
/-- If one multiplies by `c i` the coordinates in a finset `s`, then the image under a multilinear
map is multiplied by `β i in s, c i`. This is mainly an auxiliary statement to prove the result when
`s = univ`, given in `map_smul_univ`, although it can be useful in its own right as it does not
require the index set `ΞΉ` to be finite. -/
lemma map_piecewise_smul (c : ΞΉ β R) (m : Ξ i, Mβ i) (s : finset ΞΉ) :
f (s.piecewise (Ξ»i, c i β’ m i) m) = (β i in s, c i) β’ f m :=
begin
refine s.induction_on (by simp) _,
assume j s j_not_mem_s Hrec,
have A : function.update (s.piecewise (Ξ»i, c i β’ m i) m) j (m j) =
s.piecewise (Ξ»i, c i β’ m i) m,
{ ext i,
by_cases h : i = j,
{ rw h, simp [j_not_mem_s] },
{ simp [h] } },
rw [s.piecewise_insert, f.map_smul, A, Hrec],
simp [j_not_mem_s, mul_smul]
end
/-- Multiplicativity of a multilinear map along all coordinates at the same time,
writing `f (Ξ»i, c i β’ m i)` as `(β i, c i) β’ f m`. -/
lemma map_smul_univ [fintype ΞΉ] (c : ΞΉ β R) (m : Ξ i, Mβ i) :
f (Ξ»i, c i β’ m i) = (β i, c i) β’ f m :=
by simpa using map_piecewise_smul f c m finset.univ
section distrib_mul_action
variables {R' A : Type*} [monoid R'] [semiring A]
[Ξ i, module A (Mβ i)] [distrib_mul_action R' Mβ] [module A Mβ] [smul_comm_class A R' Mβ]
instance : has_scalar R' (multilinear_map A Mβ Mβ) := β¨Ξ» c f,
β¨Ξ» m, c β’ f m, Ξ»m i x y, by simp [smul_add], Ξ»l i x d, by simp [βsmul_comm x c] β©β©
@[simp] lemma smul_apply (f : multilinear_map A Mβ Mβ) (c : R') (m : Ξ i, Mβ i) :
(c β’ f) m = c β’ f m := rfl
instance : distrib_mul_action R' (multilinear_map A Mβ Mβ) :=
{ one_smul := Ξ» f, ext $ Ξ» x, one_smul _ _,
mul_smul := Ξ» cβ cβ f, ext $ Ξ» x, mul_smul _ _ _,
smul_zero := Ξ» r, ext $ Ξ» x, smul_zero _,
smul_add := Ξ» r fβ fβ, ext $ Ξ» x, smul_add _ _ _ }
end distrib_mul_action
section module
variables {R' A : Type*} [semiring R'] [semiring A]
[Ξ i, module A (Mβ i)] [module A Mβ]
[add_comm_monoid Mβ] [module R' Mβ] [module A Mβ] [smul_comm_class A R' Mβ]
/-- The space of multilinear maps over an algebra over `R` is a module over `R`, for the pointwise
addition and scalar multiplication. -/
instance [module R' Mβ] [smul_comm_class A R' Mβ] : module R' (multilinear_map A Mβ Mβ) :=
{ add_smul := Ξ» rβ rβ f, ext $ Ξ» x, add_smul _ _ _,
zero_smul := Ξ» f, ext $ Ξ» x, zero_smul _ _ }
variables (Mβ Mβ R' A)
/-- `multilinear_map.dom_dom_congr` as a `linear_equiv`. -/
@[simps apply symm_apply]
def dom_dom_congr_linear_equiv {ΞΉβ ΞΉβ} [decidable_eq ΞΉβ] [decidable_eq ΞΉβ] (Ο : ΞΉβ β ΞΉβ) :
multilinear_map A (Ξ» i : ΞΉβ, Mβ) Mβ ββ[R'] multilinear_map A (Ξ» i : ΞΉβ, Mβ) Mβ :=
{ map_smul' := Ξ» c f, by { ext, simp },
.. (dom_dom_congr_equiv Ο : multilinear_map A (Ξ» i : ΞΉβ, Mβ) Mβ β+
multilinear_map A (Ξ» i : ΞΉβ, Mβ) Mβ) }
end module
section dom_coprod
open_locale tensor_product
variables {ΞΉβ ΞΉβ ΞΉβ ΞΉβ : Type*}
variables [decidable_eq ΞΉβ] [decidable_eq ΞΉβ][decidable_eq ΞΉβ] [decidable_eq ΞΉβ]
variables {Nβ : Type*} [add_comm_monoid Nβ] [module R Nβ]
variables {Nβ : Type*} [add_comm_monoid Nβ] [module R Nβ]
variables {N : Type*} [add_comm_monoid N] [module R N]
/-- Given two multilinear maps `(ΞΉβ β N) β Nβ` and `(ΞΉβ β N) β Nβ`, this produces the map
`(ΞΉβ β ΞΉβ β N) β Nβ β Nβ` by taking the coproduct of the domain and the tensor product
of the codomain.
This can be thought of as combining `equiv.sum_arrow_equiv_prod_arrow.symm` with
`tensor_product.map`, noting that the two operations can't be separated as the intermediate result
is not a `multilinear_map`.
While this can be generalized to work for dependent `Ξ i : ΞΉβ, N'β i` instead of `ΞΉβ β N`, doing so
introduces `sum.elim N'β N'β` types in the result which are difficult to work with and not defeq
to the simple case defined here. See [this zulip thread](
https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there.20code.20for.20X.3F/topic/Instances.20on.20.60sum.2Eelim.20A.20B.20i.60/near/218484619).
-/
@[simps apply]
def dom_coprod
(a : multilinear_map R (Ξ» _ : ΞΉβ, N) Nβ) (b : multilinear_map R (Ξ» _ : ΞΉβ, N) Nβ) :
multilinear_map R (Ξ» _ : ΞΉβ β ΞΉβ, N) (Nβ β[R] Nβ) :=
{ to_fun := Ξ» v, a (Ξ» i, v (sum.inl i)) ββ b (Ξ» i, v (sum.inr i)),
map_add' := Ξ» v i p q, by cases i; simp [tensor_product.add_tmul, tensor_product.tmul_add],
map_smul' := Ξ» v i c p, by cases i; simp [tensor_product.smul_tmul', tensor_product.tmul_smul] }
/-- A more bundled version of `multilinear_map.dom_coprod` that maps
`((ΞΉβ β N) β Nβ) β ((ΞΉβ β N) β Nβ)` to `(ΞΉβ β ΞΉβ β N) β Nβ β Nβ`. -/
def dom_coprod' :
multilinear_map R (Ξ» _ : ΞΉβ, N) Nβ β[R] multilinear_map R (Ξ» _ : ΞΉβ, N) Nβ ββ[R]
multilinear_map R (Ξ» _ : ΞΉβ β ΞΉβ, N) (Nβ β[R] Nβ) :=
tensor_product.lift $ linear_map.mkβ R (dom_coprod)
(Ξ» mβ mβ n, by { ext, simp only [dom_coprod_apply, tensor_product.add_tmul, add_apply] })
(Ξ» c m n, by { ext, simp only [dom_coprod_apply, tensor_product.smul_tmul', smul_apply] })
(Ξ» m nβ nβ, by { ext, simp only [dom_coprod_apply, tensor_product.tmul_add, add_apply] })
(Ξ» c m n, by { ext, simp only [dom_coprod_apply, tensor_product.tmul_smul, smul_apply] })
@[simp]
lemma dom_coprod'_apply
(a : multilinear_map R (Ξ» _ : ΞΉβ, N) Nβ) (b : multilinear_map R (Ξ» _ : ΞΉβ, N) Nβ) :
dom_coprod' (a ββ[R] b) = dom_coprod a b := rfl
/-- When passed an `equiv.sum_congr`, `multilinear_map.dom_dom_congr` distributes over
`multilinear_map.dom_coprod`. -/
lemma dom_coprod_dom_dom_congr_sum_congr
(a : multilinear_map R (Ξ» _ : ΞΉβ, N) Nβ) (b : multilinear_map R (Ξ» _ : ΞΉβ, N) Nβ)
(Οa : ΞΉβ β ΞΉβ) (Οb : ΞΉβ β ΞΉβ) :
(a.dom_coprod b).dom_dom_congr (Οa.sum_congr Οb) =
(a.dom_dom_congr Οa).dom_coprod (b.dom_dom_congr Οb) := rfl
end dom_coprod
section
variables (R ΞΉ) (A : Type*) [comm_semiring A] [algebra R A] [fintype ΞΉ]
/-- Given an `R`-algebra `A`, `mk_pi_algebra` is the multilinear map on `A^ΞΉ` associating
to `m` the product of all the `m i`.
See also `multilinear_map.mk_pi_algebra_fin` for a version that works with a non-commutative
algebra `A` but requires `ΞΉ = fin n`. -/
protected def mk_pi_algebra : multilinear_map R (Ξ» i : ΞΉ, A) A :=
{ to_fun := Ξ» m, β i, m i,
map_add' := Ξ» m i x y, by simp [finset.prod_update_of_mem, add_mul],
map_smul' := Ξ» m i c x, by simp [finset.prod_update_of_mem] }
variables {R A ΞΉ}
@[simp] lemma mk_pi_algebra_apply (m : ΞΉ β A) :
multilinear_map.mk_pi_algebra R ΞΉ A m = β i, m i :=
rfl
end
section
variables (R n) (A : Type*) [semiring A] [algebra R A]
/-- Given an `R`-algebra `A`, `mk_pi_algebra_fin` is the multilinear map on `A^n` associating
to `m` the product of all the `m i`.
See also `multilinear_map.mk_pi_algebra` for a version that assumes `[comm_semiring A]` but works
for `A^ΞΉ` with any finite type `ΞΉ`. -/
protected def mk_pi_algebra_fin : multilinear_map R (Ξ» i : fin n, A) A :=
{ to_fun := Ξ» m, (list.of_fn m).prod,
map_add' :=
begin
intros m i x y,
have : (list.fin_range n).index_of i < n,
by simpa using list.index_of_lt_length.2 (list.mem_fin_range i),
simp [list.of_fn_eq_map, (list.nodup_fin_range n).map_update, list.prod_update_nth, add_mul,
this, mul_add, add_mul]
end,
map_smul' :=
begin
intros m i c x,
have : (list.fin_range n).index_of i < n,
by simpa using list.index_of_lt_length.2 (list.mem_fin_range i),
simp [list.of_fn_eq_map, (list.nodup_fin_range n).map_update, list.prod_update_nth, this]
end }
variables {R A n}
@[simp] lemma mk_pi_algebra_fin_apply (m : fin n β A) :
multilinear_map.mk_pi_algebra_fin R n A m = (list.of_fn m).prod :=
rfl
lemma mk_pi_algebra_fin_apply_const (a : A) :
multilinear_map.mk_pi_algebra_fin R n A (Ξ» _, a) = a ^ n :=
by simp
end
/-- Given an `R`-multilinear map `f` taking values in `R`, `f.smul_right z` is the map
sending `m` to `f m β’ z`. -/
def smul_right (f : multilinear_map R Mβ R) (z : Mβ) : multilinear_map R Mβ Mβ :=
(linear_map.smul_right linear_map.id z).comp_multilinear_map f
@[simp] lemma smul_right_apply (f : multilinear_map R Mβ R) (z : Mβ) (m : Ξ i, Mβ i) :
f.smul_right z m = f m β’ z :=
rfl
variables (R ΞΉ)
/-- The canonical multilinear map on `R^ΞΉ` when `ΞΉ` is finite, associating to `m` the product of
all the `m i` (multiplied by a fixed reference element `z` in the target module). See also
`mk_pi_algebra` for a more general version. -/
protected def mk_pi_ring [fintype ΞΉ] (z : Mβ) : multilinear_map R (Ξ»(i : ΞΉ), R) Mβ :=
(multilinear_map.mk_pi_algebra R ΞΉ R).smul_right z
variables {R ΞΉ}
@[simp] lemma mk_pi_ring_apply [fintype ΞΉ] (z : Mβ) (m : ΞΉ β R) :
(multilinear_map.mk_pi_ring R ΞΉ z : (ΞΉ β R) β Mβ) m = (β i, m i) β’ z := rfl
lemma mk_pi_ring_apply_one_eq_self [fintype ΞΉ] (f : multilinear_map R (Ξ»(i : ΞΉ), R) Mβ) :
multilinear_map.mk_pi_ring R ΞΉ (f (Ξ»i, 1)) = f :=
begin
ext m,
have : m = (Ξ»i, m i β’ 1), by { ext j, simp },
conv_rhs { rw [this, f.map_smul_univ] },
refl
end
end comm_semiring
section range_add_comm_group
variables [semiring R] [βi, add_comm_monoid (Mβ i)] [add_comm_group Mβ]
[βi, module R (Mβ i)] [module R Mβ]
(f g : multilinear_map R Mβ Mβ)
instance : has_neg (multilinear_map R Mβ Mβ) :=
β¨Ξ» f, β¨Ξ» m, - f m, Ξ»m i x y, by simp [add_comm], Ξ»m i c x, by simpβ©β©
@[simp] lemma neg_apply (m : Ξ i, Mβ i) : (-f) m = - (f m) := rfl
instance : has_sub (multilinear_map R Mβ Mβ) :=
β¨Ξ» f g,
β¨Ξ» m, f m - g m,
Ξ» m i x y, by { simp only [map_add, sub_eq_add_neg, neg_add], cc },
Ξ» m i c x, by { simp only [map_smul, smul_sub] }β©β©
@[simp] lemma sub_apply (m : Ξ i, Mβ i) : (f - g) m = f m - g m := rfl
instance : add_comm_group (multilinear_map R Mβ Mβ) :=
by refine
{ zero := (0 : multilinear_map R Mβ Mβ),
add := (+),
neg := has_neg.neg,
sub := has_sub.sub,
sub_eq_add_neg := _,
nsmul := Ξ» n f, β¨Ξ» m, n β’ f m, Ξ»m i x y, by simp [smul_add], Ξ»l i x d, by simp [βsmul_comm x n] β©,
gsmul := Ξ» n f, β¨Ξ» m, n β’ f m, Ξ»m i x y, by simp [smul_add], Ξ»l i x d, by simp [βsmul_comm x n] β©,
gsmul_zero' := _,
gsmul_succ' := _,
gsmul_neg' := _,
.. multilinear_map.add_comm_monoid, .. };
intros; ext; simp [add_comm, add_left_comm, sub_eq_add_neg, add_smul, nat.succ_eq_add_one]
end range_add_comm_group
section add_comm_group
variables [semiring R] [βi, add_comm_group (Mβ i)] [add_comm_group Mβ]
[βi, module R (Mβ i)] [module R Mβ]
(f : multilinear_map R Mβ Mβ)
@[simp] lemma map_neg (m : Ξ i, Mβ i) (i : ΞΉ) (x : Mβ i) :
f (update m i (-x)) = -f (update m i x) :=
eq_neg_of_add_eq_zero $ by rw [βmap_add, add_left_neg, f.map_coord_zero i (update_same i 0 m)]
@[simp] lemma map_sub (m : Ξ i, Mβ i) (i : ΞΉ) (x y : Mβ i) :
f (update m i (x - y)) = f (update m i x) - f (update m i y) :=
by rw [sub_eq_add_neg, sub_eq_add_neg, map_add, map_neg]
end add_comm_group
section comm_semiring
variables [comm_semiring R] [βi, add_comm_monoid (Mβ i)] [add_comm_monoid Mβ]
[βi, module R (Mβ i)] [module R Mβ]
/-- When `ΞΉ` is finite, multilinear maps on `R^ΞΉ` with values in `Mβ` are in bijection with `Mβ`,
as such a multilinear map is completely determined by its value on the constant vector made of ones.
We register this bijection as a linear equivalence in `multilinear_map.pi_ring_equiv`. -/
protected def pi_ring_equiv [fintype ΞΉ] : Mβ ββ[R] (multilinear_map R (Ξ»(i : ΞΉ), R) Mβ) :=
{ to_fun := Ξ» z, multilinear_map.mk_pi_ring R ΞΉ z,
inv_fun := Ξ» f, f (Ξ»i, 1),
map_add' := Ξ» z z', by { ext m, simp [smul_add] },
map_smul' := Ξ» c z, by { ext m, simp [smul_smul, mul_comm] },
left_inv := Ξ» z, by simp,
right_inv := Ξ» f, f.mk_pi_ring_apply_one_eq_self }
end comm_semiring
end multilinear_map
section currying
/-!
### Currying
We associate to a multilinear map in `n+1` variables (i.e., based on `fin n.succ`) two
curried functions, named `f.curry_left` (which is a linear map on `E 0` taking values
in multilinear maps in `n` variables) and `f.curry_right` (wich is a multilinear map in `n`
variables taking values in linear maps on `E 0`). In both constructions, the variable that is
singled out is `0`, to take advantage of the operations `cons` and `tail` on `fin n`.
The inverse operations are called `uncurry_left` and `uncurry_right`.
We also register linear equiv versions of these correspondences, in
`multilinear_curry_left_equiv` and `multilinear_curry_right_equiv`.
-/
open multilinear_map
variables {R M Mβ}
[comm_semiring R] [βi, add_comm_monoid (M i)] [add_comm_monoid M'] [add_comm_monoid Mβ]
[βi, module R (M i)] [module R M'] [module R Mβ]
/-! #### Left currying -/
/-- Given a linear map `f` from `M 0` to multilinear maps on `n` variables,
construct the corresponding multilinear map on `n+1` variables obtained by concatenating
the variables, given by `m β¦ f (m 0) (tail m)`-/
def linear_map.uncurry_left
(f : M 0 ββ[R] (multilinear_map R (Ξ»(i : fin n), M i.succ) Mβ)) :
multilinear_map R M Mβ :=
{ to_fun := Ξ»m, f (m 0) (tail m),
map_add' := Ξ»m i x y, begin
by_cases h : i = 0,
{ subst i,
rw [update_same, update_same, update_same, f.map_add, add_apply,
tail_update_zero, tail_update_zero, tail_update_zero] },
{ rw [update_noteq (ne.symm h), update_noteq (ne.symm h), update_noteq (ne.symm h)],
revert x y,
rw β succ_pred i h,
assume x y,
rw [tail_update_succ, map_add, tail_update_succ, tail_update_succ] }
end,
map_smul' := Ξ»m i c x, begin
by_cases h : i = 0,
{ subst i,
rw [update_same, update_same, tail_update_zero, tail_update_zero,
β smul_apply, f.map_smul] },
{ rw [update_noteq (ne.symm h), update_noteq (ne.symm h)],
revert x,
rw β succ_pred i h,
assume x,
rw [tail_update_succ, tail_update_succ, map_smul] }
end }
@[simp] lemma linear_map.uncurry_left_apply
(f : M 0 ββ[R] (multilinear_map R (Ξ»(i : fin n), M i.succ) Mβ)) (m : Ξ i, M i) :
f.uncurry_left m = f (m 0) (tail m) := rfl
/-- Given a multilinear map `f` in `n+1` variables, split the first variable to obtain
a linear map into multilinear maps in `n` variables, given by `x β¦ (m β¦ f (cons x m))`. -/
def multilinear_map.curry_left
(f : multilinear_map R M Mβ) :
M 0 ββ[R] (multilinear_map R (Ξ»(i : fin n), M i.succ) Mβ) :=
{ to_fun := Ξ»x,
{ to_fun := Ξ»m, f (cons x m),
map_add' := Ξ»m i y y', by simp,
map_smul' := Ξ»m i y c, by simp },
map_add' := Ξ»x y, by { ext m, exact cons_add f m x y },
map_smul' := Ξ»c x, by { ext m, exact cons_smul f m c x } }
@[simp] lemma multilinear_map.curry_left_apply
(f : multilinear_map R M Mβ) (x : M 0) (m : Ξ (i : fin n), M i.succ) :
f.curry_left x m = f (cons x m) := rfl
@[simp] lemma linear_map.curry_uncurry_left
(f : M 0 ββ[R] (multilinear_map R (Ξ»(i : fin n), M i.succ) Mβ)) :
f.uncurry_left.curry_left = f :=
begin
ext m x,
simp only [tail_cons, linear_map.uncurry_left_apply, multilinear_map.curry_left_apply],
rw cons_zero
end
@[simp] lemma multilinear_map.uncurry_curry_left
(f : multilinear_map R M Mβ) :
f.curry_left.uncurry_left = f :=
by { ext m, simp, }
variables (R M Mβ)
/-- The space of multilinear maps on `Ξ (i : fin (n+1)), M i` is canonically isomorphic to
the space of linear maps from `M 0` to the space of multilinear maps on
`Ξ (i : fin n), M i.succ `, by separating the first variable. We register this isomorphism as a
linear isomorphism in `multilinear_curry_left_equiv R M Mβ`.
The direct and inverse maps are given by `f.uncurry_left` and `f.curry_left`. Use these
unless you need the full framework of linear equivs. -/
def multilinear_curry_left_equiv :
(M 0 ββ[R] (multilinear_map R (Ξ»(i : fin n), M i.succ) Mβ)) ββ[R] (multilinear_map R M Mβ) :=
{ to_fun := linear_map.uncurry_left,
map_add' := Ξ»fβ fβ, by { ext m, refl },
map_smul' := Ξ»c f, by { ext m, refl },
inv_fun := multilinear_map.curry_left,
left_inv := linear_map.curry_uncurry_left,
right_inv := multilinear_map.uncurry_curry_left }
variables {R M Mβ}
/-! #### Right currying -/
/-- Given a multilinear map `f` in `n` variables to the space of linear maps from `M (last n)` to
`Mβ`, construct the corresponding multilinear map on `n+1` variables obtained by concatenating
the variables, given by `m β¦ f (init m) (m (last n))`-/
def multilinear_map.uncurry_right
(f : (multilinear_map R (Ξ»(i : fin n), M i.cast_succ) (M (last n) ββ[R] Mβ))) :
multilinear_map R M Mβ :=
{ to_fun := Ξ»m, f (init m) (m (last n)),
map_add' := Ξ»m i x y, begin
by_cases h : i.val < n,
{ have : last n β i := ne.symm (ne_of_lt h),
rw [update_noteq this, update_noteq this, update_noteq this],
revert x y,
rw [(cast_succ_cast_lt i h).symm],
assume x y,
rw [init_update_cast_succ, map_add, init_update_cast_succ, init_update_cast_succ,
linear_map.add_apply] },
{ revert x y,
rw eq_last_of_not_lt h,
assume x y,
rw [init_update_last, init_update_last, init_update_last,
update_same, update_same, update_same, linear_map.map_add] }
end,
map_smul' := Ξ»m i c x, begin
by_cases h : i.val < n,
{ have : last n β i := ne.symm (ne_of_lt h),
rw [update_noteq this, update_noteq this],
revert x,
rw [(cast_succ_cast_lt i h).symm],
assume x,
rw [init_update_cast_succ, init_update_cast_succ, map_smul, linear_map.smul_apply] },
{ revert x,
rw eq_last_of_not_lt h,
assume x,
rw [update_same, update_same, init_update_last, init_update_last,
linear_map.map_smul] }
end }
@[simp] lemma multilinear_map.uncurry_right_apply
(f : (multilinear_map R (Ξ»(i : fin n), M i.cast_succ) ((M (last n)) ββ[R] Mβ))) (m : Ξ i, M i) :
f.uncurry_right m = f (init m) (m (last n)) := rfl
/-- Given a multilinear map `f` in `n+1` variables, split the last variable to obtain
a multilinear map in `n` variables taking values in linear maps from `M (last n)` to `Mβ`, given by
`m β¦ (x β¦ f (snoc m x))`. -/
def multilinear_map.curry_right (f : multilinear_map R M Mβ) :
multilinear_map R (Ξ»(i : fin n), M (fin.cast_succ i)) ((M (last n)) ββ[R] Mβ) :=
{ to_fun := Ξ»m,
{ to_fun := Ξ»x, f (snoc m x),
map_add' := Ξ»x y, by rw f.snoc_add,
map_smul' := Ξ»c x, by rw f.snoc_smul },
map_add' := Ξ»m i x y, begin
ext z,
change f (snoc (update m i (x + y)) z)
= f (snoc (update m i x) z) + f (snoc (update m i y) z),
rw [snoc_update, snoc_update, snoc_update, f.map_add]
end,
map_smul' := Ξ»m i c x, begin
ext z,
change f (snoc (update m i (c β’ x)) z) = c β’ f (snoc (update m i x) z),
rw [snoc_update, snoc_update, f.map_smul]
end }
@[simp] lemma multilinear_map.curry_right_apply
(f : multilinear_map R M Mβ) (m : Ξ (i : fin n), M i.cast_succ) (x : M (last n)) :
f.curry_right m x = f (snoc m x) := rfl
@[simp] lemma multilinear_map.curry_uncurry_right
(f : (multilinear_map R (Ξ»(i : fin n), M i.cast_succ) ((M (last n)) ββ[R] Mβ))) :
f.uncurry_right.curry_right = f :=
begin
ext m x,
simp only [snoc_last, multilinear_map.curry_right_apply, multilinear_map.uncurry_right_apply],
rw init_snoc
end
@[simp] lemma multilinear_map.uncurry_curry_right
(f : multilinear_map R M Mβ) : f.curry_right.uncurry_right = f :=
by { ext m, simp }
variables (R M Mβ)
/-- The space of multilinear maps on `Ξ (i : fin (n+1)), M i` is canonically isomorphic to
the space of linear maps from the space of multilinear maps on `Ξ (i : fin n), M i.cast_succ` to the
space of linear maps on `M (last n)`, by separating the last variable. We register this isomorphism
as a linear isomorphism in `multilinear_curry_right_equiv R M Mβ`.
The direct and inverse maps are given by `f.uncurry_right` and `f.curry_right`. Use these
unless you need the full framework of linear equivs. -/
def multilinear_curry_right_equiv :
(multilinear_map R (Ξ»(i : fin n), M i.cast_succ) ((M (last n)) ββ[R] Mβ))
ββ[R] (multilinear_map R M Mβ) :=
{ to_fun := multilinear_map.uncurry_right,
map_add' := Ξ»fβ fβ, by { ext m, refl },
map_smul' := Ξ»c f, by { ext m, rw [smul_apply], refl },
inv_fun := multilinear_map.curry_right,
left_inv := multilinear_map.curry_uncurry_right,
right_inv := multilinear_map.uncurry_curry_right }
namespace multilinear_map
variables {ΞΉ' : Type*} [decidable_eq ΞΉ'] [decidable_eq (ΞΉ β ΞΉ')] {R Mβ}
/-- A multilinear map on `Ξ i : ΞΉ β ΞΉ', M'` defines a multilinear map on `Ξ i : ΞΉ, M'`
taking values in the space of multilinear maps on `Ξ i : ΞΉ', M'`. -/
def curry_sum (f : multilinear_map R (Ξ» x : ΞΉ β ΞΉ', M') Mβ) :
multilinear_map R (Ξ» x : ΞΉ, M') (multilinear_map R (Ξ» x : ΞΉ', M') Mβ) :=
{ to_fun := Ξ» u,
{ to_fun := Ξ» v, f (sum.elim u v),
map_add' := Ξ» v i x y, by simp only [β sum.update_elim_inr, f.map_add],
map_smul' := Ξ» v i c x, by simp only [β sum.update_elim_inr, f.map_smul] },
map_add' := Ξ» u i x y, ext $ Ξ» v,
by simp only [multilinear_map.coe_mk, add_apply, β sum.update_elim_inl, f.map_add],
map_smul' := Ξ» u i c x, ext $ Ξ» v,
by simp only [multilinear_map.coe_mk, smul_apply, β sum.update_elim_inl, f.map_smul] }
@[simp] lemma curry_sum_apply (f : multilinear_map R (Ξ» x : ΞΉ β ΞΉ', M') Mβ)
(u : ΞΉ β M') (v : ΞΉ' β M') :
f.curry_sum u v = f (sum.elim u v) :=
rfl
/-- A multilinear map on `Ξ i : ΞΉ, M'` taking values in the space of multilinear maps
on `Ξ i : ΞΉ', M'` defines a multilinear map on `Ξ i : ΞΉ β ΞΉ', M'`. -/
def uncurry_sum (f : multilinear_map R (Ξ» x : ΞΉ, M') (multilinear_map R (Ξ» x : ΞΉ', M') Mβ)) :
multilinear_map R (Ξ» x : ΞΉ β ΞΉ', M') Mβ :=
{ to_fun := Ξ» u, f (u β sum.inl) (u β sum.inr),
map_add' := Ξ» u i x y, by cases i;
simp only [map_add, add_apply, sum.update_inl_comp_inl, sum.update_inl_comp_inr,
sum.update_inr_comp_inl, sum.update_inr_comp_inr],
map_smul' := Ξ» u i c x, by cases i;
simp only [map_smul, smul_apply, sum.update_inl_comp_inl, sum.update_inl_comp_inr,
sum.update_inr_comp_inl, sum.update_inr_comp_inr] }
@[simp] lemma uncurry_sum_aux_apply
(f : multilinear_map R (Ξ» x : ΞΉ, M') (multilinear_map R (Ξ» x : ΞΉ', M') Mβ)) (u : ΞΉ β ΞΉ' β M') :
f.uncurry_sum u = f (u β sum.inl) (u β sum.inr) :=
rfl
variables (ΞΉ ΞΉ' R Mβ M')
/-- Linear equivalence between the space of multilinear maps on `Ξ i : ΞΉ β ΞΉ', M'` and the space
of multilinear maps on `Ξ i : ΞΉ, M'` taking values in the space of multilinear maps
on `Ξ i : ΞΉ', M'`. -/
def curry_sum_equiv : multilinear_map R (Ξ» x : ΞΉ β ΞΉ', M') Mβ ββ[R]
multilinear_map R (Ξ» x : ΞΉ, M') (multilinear_map R (Ξ» x : ΞΉ', M') Mβ) :=
{ to_fun := curry_sum,
inv_fun := uncurry_sum,
left_inv := Ξ» f, ext $ Ξ» u, by simp,
right_inv := Ξ» f, by { ext, simp },
map_add' := Ξ» f g, by { ext, refl },
map_smul' := Ξ» c f, by { ext, refl } }
variables {ΞΉ ΞΉ' R Mβ M'}
@[simp] lemma coe_curry_sum_equiv : β(curry_sum_equiv R ΞΉ Mβ M' ΞΉ') = curry_sum := rfl
@[simp] lemma coe_curr_sum_equiv_symm : β(curry_sum_equiv R ΞΉ Mβ M' ΞΉ').symm = uncurry_sum := rfl
variables (R Mβ M')
/-- If `s : finset (fin n)` is a finite set of cardinality `k` and its complement has cardinality
`l`, then the space of multilinear maps on `Ξ» i : fin n, M'` is isomorphic to the space of
multilinear maps on `Ξ» i : fin k, M'` taking values in the space of multilinear maps
on `Ξ» i : fin l, M'`. -/
def curry_fin_finset {k l n : β} {s : finset (fin n)}
(hk : s.card = k) (hl : sαΆ.card = l) :
multilinear_map R (Ξ» x : fin n, M') Mβ ββ[R]
multilinear_map R (Ξ» x : fin k, M') (multilinear_map R (Ξ» x : fin l, M') Mβ) :=
(dom_dom_congr_linear_equiv M' Mβ R R (fin_sum_equiv_of_finset hk hl).symm).trans
(curry_sum_equiv R (fin k) Mβ M' (fin l))
variables {R Mβ M'}
@[simp]
lemma curry_fin_finset_apply {k l n : β} {s : finset (fin n)}
(hk : s.card = k) (hl : sαΆ.card = l) (f : multilinear_map R (Ξ» x : fin n, M') Mβ)
(mk : fin k β M') (ml : fin l β M') :
curry_fin_finset R Mβ M' hk hl f mk ml =
f (Ξ» i, sum.elim mk ml ((fin_sum_equiv_of_finset hk hl).symm i)) :=
rfl
@[simp] lemma curry_fin_finset_symm_apply {k l n : β} {s : finset (fin n)}
(hk : s.card = k) (hl : sαΆ.card = l)
(f : multilinear_map R (Ξ» x : fin k, M') (multilinear_map R (Ξ» x : fin l, M') Mβ))
(m : fin n β M') :
(curry_fin_finset R Mβ M' hk hl).symm f m =
f (Ξ» i, m $ fin_sum_equiv_of_finset hk hl (sum.inl i))
(Ξ» i, m $ fin_sum_equiv_of_finset hk hl (sum.inr i)) :=
rfl
@[simp] lemma curry_fin_finset_symm_apply_piecewise_const {k l n : β} {s : finset (fin n)}
(hk : s.card = k) (hl : sαΆ.card = l)
(f : multilinear_map R (Ξ» x : fin k, M') (multilinear_map R (Ξ» x : fin l, M') Mβ)) (x y : M') :
(curry_fin_finset R Mβ M' hk hl).symm f (s.piecewise (Ξ» _, x) (Ξ» _, y)) = f (Ξ» _, x) (Ξ» _, y) :=
begin
rw curry_fin_finset_symm_apply, congr,
{ ext i, rw [fin_sum_equiv_of_finset_inl, finset.piecewise_eq_of_mem],
apply finset.order_emb_of_fin_mem },
{ ext i, rw [fin_sum_equiv_of_finset_inr, finset.piecewise_eq_of_not_mem],
exact finset.mem_compl.1 (finset.order_emb_of_fin_mem _ _ _) }
end
@[simp] lemma curry_fin_finset_symm_apply_const {k l n : β} {s : finset (fin n)}
(hk : s.card = k) (hl : sαΆ.card = l)
(f : multilinear_map R (Ξ» x : fin k, M') (multilinear_map R (Ξ» x : fin l, M') Mβ)) (x : M') :
(curry_fin_finset R Mβ M' hk hl).symm f (Ξ» _, x) = f (Ξ» _, x) (Ξ» _, x) :=
rfl
@[simp] lemma curry_fin_finset_apply_const {k l n : β} {s : finset (fin n)}
(hk : s.card = k) (hl : sαΆ.card = l) (f : multilinear_map R (Ξ» x : fin n, M') Mβ) (x y : M') :
curry_fin_finset R Mβ M' hk hl f (Ξ» _, x) (Ξ» _, y) = f (s.piecewise (Ξ» _, x) (Ξ» _, y)) :=
begin
refine (curry_fin_finset_symm_apply_piecewise_const hk hl _ _ _).symm.trans _, -- `rw` fails
rw linear_equiv.symm_apply_apply
end
end multilinear_map
end currying
section submodule
variables {R M Mβ}
[ring R] [βi, add_comm_monoid (Mβ i)] [add_comm_monoid M'] [add_comm_monoid Mβ]
[βi, module R (Mβ i)] [module R M'] [module R Mβ]
namespace multilinear_map
/-- The pushforward of an indexed collection of submodule `p i β Mβ i` by `f : Mβ β Mβ`.
Note that this is not a submodule - it is not closed under addition. -/
def map [nonempty ΞΉ] (f : multilinear_map R Mβ Mβ) (p : Ξ i, submodule R (Mβ i)) :
sub_mul_action R Mβ :=
{ carrier := f '' { v | β i, v i β p i},
smul_mem' := Ξ» c _ β¨x, hx, hfβ©, let β¨iβ© := βΉnonempty ΞΉβΊ in by {
refine β¨update x i (c β’ x i), Ξ» j, if hij : j = i then _ else _, hf βΈ _β©,
{ rw [hij, update_same], exact (p i).smul_mem _ (hx i) },
{ rw [update_noteq hij], exact hx j },
{ rw [f.map_smul, update_eq_self] } } }
/-- The map is always nonempty. This lemma is needed to apply `sub_mul_action.zero_mem`. -/
lemma map_nonempty [nonempty ΞΉ] (f : multilinear_map R Mβ Mβ) (p : Ξ i, submodule R (Mβ i)) :
(map f p : set Mβ).nonempty :=
β¨f 0, 0, Ξ» i, (p i).zero_mem, rflβ©
/-- The range of a multilinear map, closed under scalar multiplication. -/
def range [nonempty ΞΉ] (f : multilinear_map R Mβ Mβ) : sub_mul_action R Mβ :=
f.map (Ξ» i, β€)
end multilinear_map
end submodule
|
38b015743d4f2131468d3b038c19bd17164bf127 | 5756a081670ba9c1d1d3fca7bd47cb4e31beae66 | /Mathport/Syntax/Translate/Tactic/Mathlib/Suggest.lean | 58cb233ec5af6b4c6ddbc338b7066cb223c2bde3 | [
"Apache-2.0"
] | permissive | leanprover-community/mathport | 2c9bdc8292168febf59799efdc5451dbf0450d4a | 13051f68064f7638970d39a8fecaede68ffbf9e1 | refs/heads/master | 1,693,841,364,079 | 1,693,813,111,000 | 1,693,813,111,000 | 379,357,010 | 27 | 10 | Apache-2.0 | 1,691,309,132,000 | 1,624,384,521,000 | Lean | UTF-8 | Lean | false | false | 1,380 | lean | /-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathport.Syntax.Translate.Tactic.Basic
import Mathport.Syntax.Translate.Tactic.Lean3
open Lean
namespace Mathport.Translate.Tactic
open AST3 Mathport.Translate.Parser
-- # tactic.suggest
@[tr_tactic suggest] def trSuggest : TacM Syntax.Tactic := do
let n := (β parse (smallNat)?).map Quote.quote
let hs β trSimpArgs (β parse simpArgList)
let attrs := (β parse (tk "with" *> ident*)?).getD #[]
let hs := (hs ++ attrs.map trSimpExt).asNonempty
let use := (β parse (tk "using" *> ident_*)?).getD #[] |>.map trBinderIdent |>.asNonempty
let cfg β liftM $ (β expr?).mapM trExpr
`(tactic| suggest $[(config := $cfg)]? $(n)? $[[$hs,*]]? $[using $use*]?)
@[tr_tactic library_search] def trLibrarySearch : TacM Syntax.Tactic := do
let bang β parse (tk "!")?
let hs β trSimpArgs (β parse simpArgList)
let attrs := (β parse (tk "with" *> ident*)?).getD #[]
let hs := (hs ++ attrs.map trSimpExt).asNonempty
let use := (β parse (tk "using" *> ident_*)?).getD #[] |>.map trIdent_ |>.asNonempty
let cfg β liftM $ (β expr?).mapM trExpr
if bang.isSome then warn! "ignoring ! flag to library_search"
`(tactic| apply? $[(config := $cfg)]? $[[$hs,*]]? $[using $use,*]?)
|
7a2355d23681875bfa9653148350d9d9fe4525a6 | 2c22329192c4b07152b2deb50a0867391132a1fb | /test.lean | cb81be6a7af76da21434da588823290e5ceda090 | [] | no_license | ThuongThuongtlu/ThuongThuong | 4cc97beb714a829e1596da9720854287d1ad424e | 66c2a9f54b33e05d7d3ebe69fd058558536c115b | refs/heads/master | 1,584,615,614,436 | 1,528,359,683,000 | 1,528,359,683,000 | 136,420,369 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 21 | lean | #print"Hello teacher" |
178200ff1929bc47b813ea47f6d98e55e03d68ce | 3bdd27ffdff3ffa22d4bb010eba695afcc96bc4a | /src/combinatorics/simplicial_complex/basic.lean | df16c0318068030fd613f9015bd93267bfb116d9 | [] | no_license | mmasdeu/brouwerfixedpoint | 684d712c982c6a8b258b4e2c6b2eab923f2f1289 | 548270f79ecf12d7e20a256806ccb9fcf57b87e2 | refs/heads/main | 1,690,539,793,996 | 1,631,801,831,000 | 1,631,801,831,000 | 368,139,809 | 4 | 3 | null | 1,624,453,250,000 | 1,621,246,034,000 | Lean | UTF-8 | Lean | false | false | 15,340 | lean | /-
Copyright (c) 2021 YaΓ«l Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: YaΓ«l Dillies, Bhavik Mehta
-/
import combinatorics.simplicial_complex.simplex
-- import data.nat.parity
open_locale classical affine big_operators
open set
namespace affine
/--
A simplicial complex in `R^m`.
TODO: generalise to normed affine spaces `E`, so this is `simplicial_complex E`.
-/
@[ext] structure simplicial_complex (E : Type*) [normed_group E] [normed_space β E] :=
(faces : set (finset E))
(indep : β {X}, X β faces β affine_independent β (Ξ» p, p : (X : set E) β E))
(down_closed : β {X Y}, X β faces β Y β X β Y β faces)
(disjoint : β {X Y}, X β faces β Y β faces β
convex_hull βX β© convex_hull βY β convex_hull (X β© Y : set E))
variables {m n : β} {E : Type*} [normed_group E] [normed_space β E] {S : simplicial_complex E}
{x y : E} {X Y : finset E} {A : set (finset E)}
--local notation `E` := E
/--
A constructor for simplicial complexes by specifying a surcomplex whose set of faces is
downward closed.
-/
@[simp] def simplicial_complex.of_surcomplex
(faces : set (finset E)) (subset_surcomplex : faces β S.faces)
(down_closed : β {X Y}, X β faces β Y β X β Y β faces) :
simplicial_complex E :=
{ faces := faces,
indep := Ξ» X hX, S.indep (subset_surcomplex hX),
down_closed := Ξ» X Y hX hYX, down_closed hX hYX,
disjoint := Ξ» X Y hX hY, S.disjoint (subset_surcomplex hX) (subset_surcomplex hY) }
/--
A constructor for simplicial complexes by specifying a set of faces to close downward.
-/
@[simp] def simplicial_complex.of_set_closure
(indep : β {X}, X β A β affine_independent β (Ξ» p, p : (X : set E) β E))
(disjoint : β {X Y}, X β A β Y β A β
convex_hull βX β© convex_hull βY β convex_hull (X β© Y : set E)) :
simplicial_complex E :=
{ faces := {X | β Y, Y β A β§ X β Y},
indep := Ξ» X β¨Y, hY, hXYβ©, affine_independent_of_subset_affine_independent (indep hY) hXY,
down_closed := Ξ» X Y β¨Z, hZ, hXZβ© hYX, β¨Z, hZ, subset.trans hYX hXZβ©,
disjoint :=
begin
rintro W X β¨Y, hY, hWYβ© β¨Z, hZ, hXZβ© x β¨hxW, hxXβ©,
have hxYZ : x β convex_hull (Y β© Z : set E) :=
disjoint hY hZ β¨convex_hull_mono hWY hxW, convex_hull_mono hXZ hxXβ©,
have hxWZ : x β convex_hull (W β© Z : set E),
{ have := disjoint_convex_hull_of_subsets (indep hY) hWY (finset.inter_subset_left Y Z),
norm_cast at this hxYZ,
exact_mod_cast convex_hull_mono
(finset.inter_subset_inter_left (finset.inter_subset_right Y Z)) (this β¨hxW, hxYZβ©), },
have hxYX : x β convex_hull (Y β© X : set E),
{ have := disjoint_convex_hull_of_subsets (indep hZ) (finset.inter_subset_right Y Z) hXZ,
norm_cast at this hxYZ,
exact_mod_cast convex_hull_mono
(finset.inter_subset_inter_right (finset.inter_subset_left Y Z)) (this β¨hxYZ, hxXβ©), },
norm_cast at hxWZ hxYX,
have hxWX := disjoint_convex_hull_of_subsets (indep hY)
(subset.trans (finset.inter_subset_inter_right hWY) (finset.inter_subset_left Y Z))
(finset.inter_subset_left Y X) β¨hxWZ, hxYXβ©,
norm_cast at hxWX,
exact_mod_cast convex_hull_mono (subset.trans
(finset.inter_subset_inter_right (finset.inter_subset_left W Z))
(finset.inter_subset_inter_left (finset.inter_subset_right Y X))) hxWX,
end}
/--
A constructor for simplicial complexes by specifying a face to close downward.
-/
@[simp] def simplicial_complex.of_simplex
(indep : affine_independent β (Ξ» p, p : (X : set E) β E)) :
simplicial_complex E :=
simplicial_complex.of_set_closure
begin rintro Y (hY : Y = X), rw hY, exact indep end
begin rintro Y Z (hY : Y = X) (hZ : Z = X), rw [hY, hZ, inter_self _, inter_self _],
exact subset.refl _ end
lemma mem_simplex_complex_iff
(hX : affine_independent β (Ξ» p, p : (X : set E) β E)) :
Y β (simplicial_complex.of_simplex hX).faces β Y β X :=
begin
split,
{ rintro β¨Z, (hZ : Z = X), hYXβ©,
rw β hZ,
exact hYX },
{ rintro hYX,
exact β¨X, rfl, hYXβ© }
end
/--
The empty simplicial complex is made up of only the empty simplex
-/
def empty_simplicial_complex (E : Type*) [normed_group E] [normed_space β E] :
simplicial_complex E :=
{ faces := {β
},
indep :=
begin
rintro X (rfl : _ = _),
apply affine_independent_of_subsingleton β _,
simp,
end,
down_closed := Ξ» X Y hX, hX.symm βΈ finset.subset_empty.1,
disjoint :=
begin
rintro X _ (rfl : X = β
) (rfl : Y = β
),
simp,
end, }
lemma empty_mem_faces_of_nonempty :
(S.faces).nonempty β β
β S.faces :=
Ξ» β¨X, hXβ©, S.down_closed hX (empty_subset X)
/--
The underlying space of a simplicial complex.
-/
def simplicial_complex.space (S : simplicial_complex E) :
set E :=
β X β S.faces, convex_hull (X : set E)
lemma mem_space_iff :
x β S.space β β X β S.faces, x β convex_hull (X : set E) :=
begin
unfold simplicial_complex.space,
rw mem_bUnion_iff,
end
lemma empty_space_of_empty_simplicial_complex :
(empty_simplicial_complex E).space = β
:=
begin
unfold empty_simplicial_complex simplicial_complex.space,
simp,
end
lemma convex_hull_face_subset_space (hX : X β S.faces) :
convex_hull βX β S.space :=
Ξ» x hx, mem_bUnion hX hx
lemma face_subset_space (hX : X β S.faces) :
(X : set E) β S.space :=
set.subset.trans (subset_convex_hull _) (convex_hull_face_subset_space hX)
def simplicial_complex.points (S : simplicial_complex E) :
set E :=
β k β S.faces, (k : set E)
lemma points_subset_space :
S.points β S.space :=
bUnion_subset_bUnion_right (Ξ» x hx, subset_convex_hull x)
--noncomputable def simplicial_complex.dim (S : simplicial_complex E) :
-- β :=
-- Dumb bug in mathlib, see
--https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there.20code.20for.20X.3F/topic/R.5Em.20is.20finite.20dimensional.20over.20R/near/231748016
--instance {m : β} : finite_dimensional β E := sorry
--Refinement of `size_bound`
lemma face_dimension_le_space_dimension [finite_dimensional β E] (hX : X β S.faces) :
finset.card X β€ finite_dimensional.finrank β E + 1 :=
size_bound (S.indep hX)
def simplicial_complex.facets (S : simplicial_complex E) :
set (finset E) :=
{X | X β S.faces β§ (β {Y}, Y β S.faces β X β Y β X = Y)}
lemma facets_subset : S.facets β S.faces := Ξ» X hX, hX.1
lemma not_facet_iff_subface : X β S.faces β (X β S.facets β β {Y}, Y β S.faces β§ X β Y) :=
begin
rintro hX,
split,
{ rintro (hX' : Β¬(X β S.faces β§ (β {Y}, Y β S.faces β X β Y β X = Y))),
push_neg at hX',
obtain β¨Y, hYβ© := hX' hX,
exact β¨Y, hY.1, β¨hY.2.1, (Ξ» hYX, hY.2.2 (finset.subset.antisymm hY.2.1 hYX))β©β©, },
rintro β¨Y, hYβ© β¨hX, hX'β©,
have := hX' hY.1 hY.2.1,
rw this at hY,
exact hY.2.2 (subset.refl Y),
end
lemma subfacet [finite_dimensional β E] (hX : X β S.faces) :
β {Y}, Y β S.facets β§ X β Y :=
begin
have := id hX,
revert this,
apply finset.strong_downward_induction_on X,
{ rintro Y h hYcard hY,
by_cases hYfacet : Y β S.facets,
{ exact β¨Y, hYfacet, finset.subset.refl _β©, },
obtain β¨Z, hZ, hYZβ© := (not_facet_iff_subface hY).mp hYfacet,
obtain β¨W, hWβ© := h (face_dimension_le_space_dimension hZ) hYZ hZ,
exact β¨W, hW.1, finset.subset.trans hYZ.1 hW.2β© },
exact face_dimension_le_space_dimension hX,
end
lemma facets_empty (hS : S.faces = β
) :
S.facets = β
:=
begin
rw [βsubset_empty_iff, βhS],
exact facets_subset,
end
lemma facets_empty_iff_faces_empty [finite_dimensional β E] :
S.facets = β
β S.faces = β
:=
begin
classical,
split,
{ intro h,
by_contra h',
rw [βne.def, set.ne_empty_iff_nonempty] at h',
obtain β¨X, hXβ© := h',
obtain β¨Y, hY, hZβ© := subfacet hX,
rw h at hY,
apply hY },
exact facets_empty,
end
lemma facets_singleton (hS : S.faces = {X}) :
S.facets = {X} :=
begin
ext X,
unfold simplicial_complex.facets,
rw hS,
simp,
exact Ξ» hX _, hX,
end
lemma facets_singleton_empty (hS : S.faces = {β
}) :
S.facets = {β
} :=
facets_singleton hS
/--
The cells of a simplicial complex are its simplices whose dimension matches the one of the space.
-/
def simplicial_complex.cells (S : simplicial_complex E) :
set (finset E) :=
{X | X β S.faces β§ X.card = finite_dimensional.finrank β E + 1}
lemma cells_subset_facets [finite_dimensional β E] :
S.cells β S.facets :=
begin
rintro X β¨hX, hXcardβ©,
by_contra,
obtain β¨Y, hY, hXYβ© := (not_facet_iff_subface hX).mp h,
have := finset.card_lt_card hXY,
have := face_dimension_le_space_dimension hY,
linarith,
end
/--
The subcells of a simplicial complex are its simplices whose cardinality matches the dimension of
the space. They are thus one smaller than cells.
-/
def simplicial_complex.subcells (S : simplicial_complex E) :
set (finset E) :=
{X | X β S.faces β§ X.card = finite_dimensional.finrank β E}
def simplicial_complex.vertices (S : simplicial_complex E) :
set E :=
{x | {x} β S.faces}
lemma mem_of_mem_convex_hull (hx : {x} β S.faces) (hX : X β S.faces)
(hxX : x β convex_hull (X : set E)) :
x β X :=
begin
have h := S.disjoint hx hX β¨by simp, hxXβ©,
by_contra H,
norm_cast at h,
rw [finset.inter_comm, finset.disjoint_iff_inter_eq_empty.1 (finset.disjoint_singleton.2 H)] at h,
simp at h,
exact h,
end
lemma subset_of_convex_hull_subset_convex_hull (hX : X β S.faces) (hY : Y β S.faces)
(hXY : convex_hull (X : set E) β convex_hull βY) :
X β Y :=
Ξ» x hxX, mem_of_mem_convex_hull (S.down_closed hX (finset.singleton_subset_iff.2 hxX)) hY
(hXY (subset_convex_hull βX hxX))
lemma disjoint_interiors (hX : X β S.faces) (hY : Y β S.faces) (hxX : x β combi_interior X)
(hxY : x β combi_interior Y) :
X = Y :=
begin
by_contra,
have hXY : X β© Y β X,
{ use finset.inter_subset_left X Y,
intro H,
exact hxY.2 (set.mem_bUnion β¨subset.trans H (finset.inter_subset_right X Y), (Ξ» H2,
h (finset.subset.antisymm (subset.trans H (finset.inter_subset_right X Y)) H2))β© hxX.1) },
refine hxX.2 (mem_bUnion hXY _),
exact_mod_cast S.disjoint hX hY β¨hxX.1, hxY.1β©,
end
lemma disjoint_interiors_aux (hX : X β S.faces) (hY : Y β S.faces) (h : X β Y) :
disjoint (combi_interior X) (combi_interior Y) :=
Ξ» x hx, h (disjoint_interiors hX hY hx.1 hx.2)
lemma eq_singleton_of_singleton_mem_combi_interior (hx : {x} β S.faces) (hX : X β S.faces)
(hxX : x β combi_interior X) :
X = {x} :=
begin
apply disjoint_interiors hX hx hxX,
rw combi_interior_singleton,
exact mem_singleton x,
end
lemma combi_interiors_cover :
S.space = β X β S.faces, combi_interior X :=
begin
apply subset.antisymm _ _,
{ apply bUnion_subset,
rintro X hX,
rw simplex_combi_interiors_cover,
exact Union_subset (Ξ» Y, Union_subset (Ξ» YX, subset_bUnion_of_mem (S.down_closed hX YX)))},
{ apply bUnion_subset,
rintro Y hY,
exact subset.trans (diff_subset _ _) (subset_bUnion_of_mem hY) }
end
/- The simplices interiors form a partition of the underlying space (except that they contain the
empty set) -/
lemma combi_interiors_partition (hx : x β S.space) :
β! X, X β S.faces β§ x β combi_interior X :=
begin
rw combi_interiors_cover at hx,
simp only [set.mem_bUnion_iff] at hx,
obtain β¨X, hX, hxXβ© := hx,
exact β¨X, β¨β¨hX, hxXβ©, (Ξ» Y β¨hY, hxYβ©, disjoint_interiors hY hX hxY hxX)β©β©,
end
lemma mem_convex_hull_iff :
x β convex_hull (X : set E) β β Y β X, x β combi_interior Y :=
begin
simp [simplex_combi_interiors_cover],
end
lemma mem_combi_frontier_iff' :
x β combi_frontier X β β {Y}, Y β X β§ x β combi_interior Y :=
begin
rw mem_combi_frontier_iff,
split,
{
rintro β¨Y, hYX, hxYβ©,
--rw [simplex_combi_interiors_cover, mem_bUnion_iff] at hxY,
--obtain β¨Z, hZβ© := simplex_combi_interiors_cover
sorry
},
{ rintro β¨Y, hYX, hxYβ©,
exact β¨Y, hYX, hxY.1β© }
end
lemma subset_of_combi_interior_inter_convex_hull_nonempty (hX : X β S.faces) (hY : Y β S.faces)
(hXY : (combi_interior X β© convex_hull (Y : set E)).nonempty) :
X β Y :=
begin
obtain β¨x, hxX, hxYβ© := hXY,
obtain β¨Z, hZY, hxZβ© := mem_convex_hull_iff.1 hxY,
rw disjoint_interiors hX (S.down_closed hY hZY) hxX hxZ,
exact hZY,
end
lemma simplex_combi_interiors_split_interiors (hY : affine_independent β (Ξ» p, p : (Y : set E) β E))
(hXY : convex_hull (X : set E) β convex_hull βY) :
β Z β Y, combi_interior X β combi_interior Z :=
begin
let S := simplicial_complex.of_simplex hY,
--let F := Y.powerset.filter (Ξ» W : finset E, (X : set E) β convex_hull W),
sorry
/-obtain β¨Z, hZ, hZminβ© := finset.inf' _
(begin
use Y,
simp only [true_and, finset.mem_powerset_self, finset.mem_filter],
exact subset.trans (subset_convex_hull _) hXY,
end : F.nonempty)
begin
rintro A B hA hB,
simp at β’ hA hB,
exact β¨finset.subset.trans (finset.inter_subset_left _ _) hA.1,
subset.trans (subset_inter hA.2 hB.2) (S.disjoint ((mem_simplex_complex_iff hY).2 hA.1)
((mem_simplex_complex_iff hY).2 hB.1))β©
end,
simp at hZ,
use [Z, hZ.1],
rintro x hxX,
use convex_hull_min hZ.2 (convex_convex_hull _) hxX.1,
rintro hxZ,
rw mem_combi_frontier_iff' at hxZ,
obtain β¨W, hWZ, hxWβ© := hxZ,
apply hWZ.2 (hZmin W _),
simp,
use [subset.trans hWZ.1 hZ.1],
rw finset.convex_hull_eq _ at β’ hZ,
obtain β¨v, hvpos, hvsum, hvcenterβ© := combi_interior_subset_positive_weighings hxX,
obtain β¨w, hwpos, hwsum, hwcenterβ© := combi_interior_subset_positive_weighings hxW,
let u : E β E β β := Ξ» a, if ha : a β X then classical.some (hZ.2 ha) else (Ξ» b, 0),
have hupos : β {a}, a β X β β (b : E), b β Z β 0 < u a b,
{
rintro a ha,
have := classical.some_spec (hZ.2 ha),
sorry
},
have husum : β {a}, a β X β β (b : E) in Z, u a b = 1,
{
sorry
},
have hucenter : β {a}, a β X β Z.center_mass (u a) id = a,
{
sorry
},
let t : E β β := Ξ» b, if hb : b β Z then β (a : E) in X, v a * u a b else 0,-/
/-rintro y (hyX : y β X),
obtain β¨v, hvpos, hvsum, hvcenterβ© := combi_interior_subset_positive_weighings hxX,
obtain β¨w, hwpos, hwsum, hwcenterβ© := combi_interior_subset_positive_weighings hxW,-/
--rw mem_convex_hull,
/-by_contra hXW,
obtain β¨y, hyX, hyWβ© := not_subset.1 hXW,-/
/-apply hxX.2,
rw mem_combi_frontier_iff at β’,
use [X.filter (Ξ» w : E, w β convex_hull (W : set E)), finset.filter_subset _ _],
{
rintro hXW,
apply hWZ.2 (hZmin W _),
simp,
use [subset.trans hWZ.1 hZ.1],
rintro y (hyX : y β X),
have := hXW hyX,
simp at this,
exact this.2,
},
{
simp,
apply convex_hull_mono (subset_inter (subset.refl _) _) hxX.1,
by_contra hXW,
rw not_subset at hXW,
/-suffices hXW : βX β convex_hull βW,
{
apply convex_hull_mono (subset_inter (subset.refl _) hXW) hxX.1,
},-/
sorry
}-/
end
end affine
|
3cab2d6521190ed10ab3e2603f4117fa01140500 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/algebra/jordan/basic.lean | a7259c6b0e11e8a54cd261feda2a67faf7c53f6a | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 11,096 | lean | /-
Copyright (c) 2021 Christopher Hoskin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Christopher Hoskin
-/
import algebra.lie.of_associative
/-!
# Jordan rings
Let `A` be a non-unital, non-associative ring. Then `A` is said to be a (commutative, linear) Jordan
ring if the multiplication is commutative and satisfies a weak associativity law known as the
Jordan Identity: for all `a` and `b` in `A`,
```
(a * b) * a^2 = a * (b * a^2)
```
i.e. the operators of multiplication by `a` and `a^2` commute.
A more general concept of a (non-commutative) Jordan ring can also be defined, as a
(non-commutative, non-associative) ring `A` where, for each `a` in `A`, the operators of left and
right multiplication by `a` and `a^2` commute.
Every associative algebra can be equipped with a symmetrized multiplication (characterized by
`sym_alg.sym_mul_sym`) making it into a commutative Jordan algebra (`sym_alg.is_comm_jordan`).
Jordan algebras arising this way are said to be special.
A real Jordan algebra `A` can be introduced by
```lean
variables {A : Type*} [non_unital_non_assoc_ring A] [module β A] [smul_comm_class β A A]
[is_scalar_tower β A A] [is_comm_jordan A]
```
## Main results
- `two_nsmul_lie_lmul_lmul_add_add_eq_zero` : Linearisation of the commutative Jordan axiom
## Implementation notes
We shall primarily be interested in linear Jordan algebras (i.e. over rings of characteristic not
two) leaving quadratic algebras to those better versed in that theory.
The conventional way to linearise the Jordan axiom is to equate coefficients (more formally, assume
that the axiom holds in all field extensions). For simplicity we use brute force algebraic expansion
and substitution instead.
## Motivation
Every Jordan algebra `A` has a triple product defined, for `a` `b` and `c` in `A` by
$$
{a\,b\,c} = (a * b) * c - (a * c) * b + a * (b * c).
$$
Via this triple product Jordan algebras are related to a number of other mathematical structures:
Jordan triples, partial Jordan triples, Jordan pairs and quadratic Jordan algebras. In addition to
their considerable algebraic interest ([mccrimmon2004]) these structures have been shown to have
deep connections to mathematical physics, functional analysis and differential geometry. For more
information about these connections the interested reader is referred to [alfsenshultz2003],
[chu2012], [friedmanscarr2005], [iordanescu2003] and [upmeier1987].
There are also exceptional Jordan algebras which can be shown not to be the symmetrization of any
associative algebra. The 3x3 matrices of octonions is the canonical example.
Non-commutative Jordan algebras have connections to the Vidav-Palmer theorem
[cabreragarciarodriguezpalacios2014].
## References
* [Cabrera GarcΓa and RodrΓguez Palacios, Non-associative normed algebras. Volume 1]
[cabreragarciarodriguezpalacios2014]
* [Hanche-Olsen and StΓΈrmer, Jordan Operator Algebras][hancheolsenstormer1984]
* [McCrimmon, A taste of Jordan algebras][mccrimmon2004]
-/
variables (A : Type*)
/-- A (non-commutative) Jordan multiplication. -/
class is_jordan [has_mul A] :=
(lmul_comm_rmul : β a b : A, (a * b) * a = a * (b * a))
(lmul_lmul_comm_lmul : β a b : A, (a * a) * (a * b) = a * ((a * a) * b))
(lmul_lmul_comm_rmul : β a b : A, (a * a) * (b * a) = ((a * a) * b) * a)
(lmul_comm_rmul_rmul : β a b : A, (a * b) * (a * a) = a * (b * (a * a)))
(rmul_comm_rmul_rmul : β a b : A, (b * a) * (a * a) = (b * (a * a)) * a)
/-- A commutative Jordan multipication -/
class is_comm_jordan [has_mul A] :=
(mul_comm : β a b : A, a * b = b * a)
(lmul_comm_rmul_rmul : β a b : A, (a * b) * (a * a) = a * (b * (a * a)))
/-- A (commutative) Jordan multiplication is also a Jordan multipication -/
@[priority 100] -- see Note [lower instance priority]
instance is_comm_jordan.to_is_jordan [has_mul A] [is_comm_jordan A] : is_jordan A :=
{ lmul_comm_rmul := Ξ» a b, by rw [is_comm_jordan.mul_comm, is_comm_jordan.mul_comm a b],
lmul_lmul_comm_lmul := Ξ» a b, by rw [is_comm_jordan.mul_comm (a * a) (a * b),
is_comm_jordan.lmul_comm_rmul_rmul, is_comm_jordan.mul_comm b (a * a)],
lmul_comm_rmul_rmul := is_comm_jordan.lmul_comm_rmul_rmul,
lmul_lmul_comm_rmul := Ξ» a b, by rw [is_comm_jordan.mul_comm (a * a) (b * a),
is_comm_jordan.mul_comm b a, is_comm_jordan.lmul_comm_rmul_rmul, is_comm_jordan.mul_comm,
is_comm_jordan.mul_comm b (a * a)],
rmul_comm_rmul_rmul := Ξ» a b, by rw [is_comm_jordan.mul_comm b a,
is_comm_jordan.lmul_comm_rmul_rmul, is_comm_jordan.mul_comm], }
/-- Semigroup multiplication satisfies the (non-commutative) Jordan axioms-/
@[priority 100] -- see Note [lower instance priority]
instance semigroup.is_jordan [semigroup A] : is_jordan A :=
{ lmul_comm_rmul := Ξ» a b, by rw mul_assoc,
lmul_lmul_comm_lmul := Ξ» a b, by rw [mul_assoc, mul_assoc],
lmul_comm_rmul_rmul := Ξ» a b, by rw [mul_assoc],
lmul_lmul_comm_rmul := Ξ» a b, by rw [βmul_assoc],
rmul_comm_rmul_rmul := Ξ» a b, by rw [β mul_assoc, β mul_assoc], }
@[priority 100] -- see Note [lower instance priority]
instance comm_semigroup.is_comm_jordan [comm_semigroup A] : is_comm_jordan A :=
{ mul_comm := mul_comm,
lmul_comm_rmul_rmul := Ξ» a b, mul_assoc _ _ _, }
local notation `L` := add_monoid.End.mul_left
local notation `R` := add_monoid.End.mul_right
/-!
The Jordan axioms can be expressed in terms of commuting multiplication operators.
-/
section commute
variables {A} [non_unital_non_assoc_ring A] [is_jordan A]
@[simp] lemma commute_lmul_rmul (a : A) : commute (L a) (R a) :=
add_monoid_hom.ext $ Ξ» b, (is_jordan.lmul_comm_rmul _ _).symm
@[simp] lemma commute_lmul_lmul_sq (a : A) : commute (L a) (L (a * a)) :=
add_monoid_hom.ext $ Ξ» b, (is_jordan.lmul_lmul_comm_lmul _ _).symm
@[simp] lemma commute_lmul_rmul_sq (a : A) : commute (L a) (R (a * a)) :=
add_monoid_hom.ext $ Ξ» b, (is_jordan.lmul_comm_rmul_rmul _ _).symm
@[simp] lemma commute_lmul_sq_rmul (a : A) : commute (L (a * a)) (R a) :=
add_monoid_hom.ext $ Ξ» b, (is_jordan.lmul_lmul_comm_rmul _ _)
@[simp] lemma commute_rmul_rmul_sq (a : A) : commute (R a) (R (a * a)) :=
add_monoid_hom.ext $ Ξ» b, (is_jordan.rmul_comm_rmul_rmul _ _).symm
end commute
variables {A} [non_unital_non_assoc_ring A] [is_comm_jordan A]
/-!
The endomorphisms on an additive monoid `add_monoid.End` form a `ring`, and this may be equipped
with a Lie Bracket via `ring.has_bracket`.
-/
lemma two_nsmul_lie_lmul_lmul_add_eq_lie_lmul_lmul_add (a b : A) :
2β’(β
L a, L (a * b)β + β
L b, L (b * a)β) = β
L (a * a), L bβ + β
L (b * b), L aβ :=
begin
suffices : 2 β’ β
L a, L (a * b)β + 2 β’ β
L b, L (b * a)β + β
L b, L (a * a)β + β
L a, L (b * b)β = 0,
{ rwa [β sub_eq_zero, β sub_sub, sub_eq_add_neg, sub_eq_add_neg, lie_skew, lie_skew, nsmul_add] },
convert (commute_lmul_lmul_sq (a + b)).lie_eq,
simp only [add_mul, mul_add, map_add, lie_add, add_lie, is_comm_jordan.mul_comm b a,
(commute_lmul_lmul_sq a).lie_eq, (commute_lmul_lmul_sq b).lie_eq],
abel,
end
lemma two_nsmul_lie_lmul_lmul_add_add_eq_zero (a b c : A) :
2β’(β
L a, L (b * c)β + β
L b, L (c * a)β + β
L c, L (a * b)β) = 0 :=
begin
symmetry,
calc 0 = β
L (a + b + c), L ((a + b + c) * (a + b + c))β :
by rw (commute_lmul_lmul_sq (a + b + c)).lie_eq
... = β
L a + L b + L c,
L (a * a) + L (a * b) + L (a * c) + (L (b * a) + L (b * b) + L (b * c))
+ (L (c * a) + L (c * b) + L (c * c))β :
by rw [add_mul, add_mul, mul_add, mul_add, mul_add, mul_add, mul_add, mul_add,
map_add, map_add, map_add, map_add, map_add, map_add, map_add, map_add, map_add, map_add]
... = β
L a + L b + L c,
L (a * a) + L (a * b) + L (c * a) + (L (a * b) + L (b * b) + L (b * c))
+ (L (c * a) + L (b * c) + L (c * c))β :
by rw [is_comm_jordan.mul_comm b a, is_comm_jordan.mul_comm c a, is_comm_jordan.mul_comm c b]
... = β
L a + L b + L c, L (a * a) + L (b * b) + L (c * c) + 2β’L (a * b) + 2β’L (c * a)
+ 2β’L (b * c) β :
by {rw [two_smul, two_smul, two_smul],
simp only [lie_add, add_lie, commute_lmul_lmul_sq, zero_add, add_zero], abel}
... = β
L a, L (a * a)β + β
L a, L (b * b)β + β
L a, L (c * c)β + β
L a, 2β’L (a * b)β
+ β
L a, 2β’L(c * a)β + β
L a, 2β’L (b * c)β
+ (β
L b, L (a * a)β + β
L b, L (b * b)β + β
L b, L (c * c)β + β
L b, 2β’L (a * b)β
+ β
L b, 2β’L (c * a)β + β
L b, 2β’L (b * c)β)
+ (β
L c, L (a * a)β + β
L c, L (b * b)β + β
L c, L (c * c)β + β
L c, 2β’L (a * b)β
+ β
L c, 2β’L (c * a)β + β
L c, 2β’L (b * c)β) :
by rw [add_lie, add_lie, lie_add, lie_add, lie_add, lie_add, lie_add, lie_add, lie_add, lie_add,
lie_add, lie_add, lie_add, lie_add, lie_add, lie_add, lie_add]
... = β
L a, L (b * b)β + β
L a, L (c * c)β + β
L a, 2β’L (a * b)β + β
L a, 2β’L (c * a)β
+ β
L a, 2β’L (b * c)β
+ (β
L b, L (a * a)β + β
L b, L (c * c)β + β
L b, 2β’L (a * b)β + β
L b, 2β’L (c * a)β
+ β
L b, 2β’L (b * c)β)
+ (β
L c, L (a * a)β + β
L c, L (b * b)β + β
L c, 2β’L (a * b)β + β
L c, 2β’L (c * a)β
+ β
L c, 2β’L (b * c)β) :
by rw [(commute_lmul_lmul_sq a).lie_eq, (commute_lmul_lmul_sq b).lie_eq,
(commute_lmul_lmul_sq c).lie_eq, zero_add, add_zero, add_zero]
... = β
L a, L (b * b)β + β
L a, L (c * c)β + 2β’β
L a, L (a * b)β + 2β’β
L a, L (c * a)β
+ 2β’β
L a, L (b * c)β
+ (β
L b, L (a * a)β + β
L b, L (c * c)β + 2β’β
L b, L (a * b)β + 2β’β
L b, L (c * a)β
+ 2β’β
L b, L (b * c)β)
+ (β
L c, L (a * a)β + β
L c, L (b * b)β + 2β’β
L c, L (a * b)β + 2β’β
L c, L (c * a)β
+ 2β’β
L c, L (b * c)β) :
by simp only [lie_nsmul]
... = (β
L a, L (b * b)β+ β
L b, L (a * a)β + 2β’(β
L a, L (a * b)β + β
L b, L (a * b)β))
+ (β
L a, L (c * c)β + β
L c, L (a * a)β + 2β’(β
L a, L (c * a)β + β
L c, L (c * a)β))
+ (β
L b, L (c * c)β + β
L c, L (b * b)β + 2β’(β
L b, L (b * c)β + β
L c, L (b * c)β))
+ (2β’β
L a, L (b * c)β + 2β’β
L b, L (c * a)β + 2β’β
L c, L (a * b)β) : by abel
... = 2β’β
L a, L (b * c)β + 2β’β
L b, L (c * a)β + 2β’β
L c, L (a * b)β :
by begin
rw add_left_eq_self,
nth_rewrite 1 is_comm_jordan.mul_comm a b,
nth_rewrite 0 is_comm_jordan.mul_comm c a,
nth_rewrite 1 is_comm_jordan.mul_comm b c,
rw [two_nsmul_lie_lmul_lmul_add_eq_lie_lmul_lmul_add,
two_nsmul_lie_lmul_lmul_add_eq_lie_lmul_lmul_add,
two_nsmul_lie_lmul_lmul_add_eq_lie_lmul_lmul_add,
β lie_skew (L (a * a)), β lie_skew (L (b * b)), β lie_skew (L (c * c)),
β lie_skew (L (a * a)), β lie_skew (L (b * b)), β lie_skew (L (c * c))],
abel,
end
... = 2β’(β
L a, L (b * c)β + β
L b, L (c * a)β + β
L c, L (a * b)β) : by rw [nsmul_add, nsmul_add]
end
|
22d5b952ec6e01098909f70c5fa5b5efca7acc2b | 4727251e0cd73359b15b664c3170e5d754078599 | /src/algebraic_geometry/prime_spectrum/noetherian.lean | c9abaabee3c720487eee8513f0ea019df9715e21 | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 4,022 | lean | /-
Copyright (c) 2020 Filippo A. E. Nuccio. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Filippo A. E. Nuccio
-/
import algebraic_geometry.prime_spectrum.basic
/-!
This file proves additional properties of the prime spectrum a ring is Noetherian.
-/
universes u v
namespace prime_spectrum
open submodule
variables (R : Type u) [comm_ring R] [is_noetherian_ring R]
variables {A : Type u} [comm_ring A] [is_domain A] [is_noetherian_ring A]
/--In a noetherian ring, every ideal contains a product of prime ideals
([samuel, Β§ 3.3, Lemma 3])-/
lemma exists_prime_spectrum_prod_le (I : ideal R) :
β (Z : multiset (prime_spectrum R)), multiset.prod (Z.map (coe : subtype _ β ideal R)) β€ I :=
begin
refine is_noetherian.induction (Ξ» (M : ideal R) hgt, _) I,
by_cases h_prM : M.is_prime,
{ use {β¨M, h_prMβ©},
rw [multiset.map_singleton, multiset.prod_singleton, subtype.coe_mk],
exact le_rfl },
by_cases htop : M = β€,
{ rw htop,
exact β¨0, le_topβ© },
have lt_add : β z β M, M < M + span R {z},
{ intros z hz,
refine lt_of_le_of_ne le_sup_left (Ξ» m_eq, hz _),
rw m_eq,
exact ideal.mem_sup_right (mem_span_singleton_self z) },
obtain β¨x, hx, y, hy, hxyβ© := (ideal.not_is_prime_iff.mp h_prM).resolve_left htop,
obtain β¨Wx, h_Wxβ© := hgt (M + span R {x}) (lt_add _ hx),
obtain β¨Wy, h_Wyβ© := hgt (M + span R {y}) (lt_add _ hy),
use Wx + Wy,
rw [multiset.map_add, multiset.prod_add],
apply le_trans (submodule.mul_le_mul h_Wx h_Wy),
rw add_mul,
apply sup_le (show M * (M + span R {y}) β€ M, from ideal.mul_le_right),
rw mul_add,
apply sup_le (show span R {x} * M β€ M, from ideal.mul_le_left),
rwa [span_mul_span, set.singleton_mul_singleton, span_singleton_le_iff_mem],
end
/--In a noetherian integral domain which is not a field, every non-zero ideal contains a non-zero
product of prime ideals; in a field, the whole ring is a non-zero ideal containing only 0 as
product or prime ideals ([samuel, Β§ 3.3, Lemma 3]) -/
lemma exists_prime_spectrum_prod_le_and_ne_bot_of_domain
(h_fA : Β¬ is_field A) {I : ideal A} (h_nzI: I β β₯) :
β (Z : multiset (prime_spectrum A)), multiset.prod (Z.map (coe : subtype _ β ideal A)) β€ I β§
multiset.prod (Z.map (coe : subtype _ β ideal A)) β β₯ :=
begin
revert h_nzI,
refine is_noetherian.induction (Ξ» (M : ideal A) hgt, _) I,
intro h_nzM,
have hA_nont : nontrivial A,
apply is_domain.to_nontrivial A,
by_cases h_topM : M = β€,
{ rcases h_topM with rfl,
obtain β¨p_id, h_nzp, h_ppβ© : β (p : ideal A), p β β₯ β§ p.is_prime,
{ apply ring.not_is_field_iff_exists_prime.mp h_fA },
use [({β¨p_id, h_ppβ©} : multiset (prime_spectrum A)), le_top],
rwa [multiset.map_singleton, multiset.prod_singleton, subtype.coe_mk] },
by_cases h_prM : M.is_prime,
{ use ({β¨M, h_prMβ©} : multiset (prime_spectrum A)),
rw [multiset.map_singleton, multiset.prod_singleton, subtype.coe_mk],
exact β¨le_rfl, h_nzMβ© },
obtain β¨x, hx, y, hy, h_xyβ© := (ideal.not_is_prime_iff.mp h_prM).resolve_left h_topM,
have lt_add : β z β M, M < M + span A {z},
{ intros z hz,
refine lt_of_le_of_ne le_sup_left (Ξ» m_eq, hz _),
rw m_eq,
exact mem_sup_right (mem_span_singleton_self z) },
obtain β¨Wx, h_Wx_le, h_Wx_neβ© := hgt (M + span A {x}) (lt_add _ hx) (ne_bot_of_gt (lt_add _ hx)),
obtain β¨Wy, h_Wy_le, h_Wx_neβ© := hgt (M + span A {y}) (lt_add _ hy) (ne_bot_of_gt (lt_add _ hy)),
use Wx + Wy,
rw [multiset.map_add, multiset.prod_add],
refine β¨le_trans (submodule.mul_le_mul h_Wx_le h_Wy_le) _, mt ideal.mul_eq_bot.mp _β©,
{ rw add_mul,
apply sup_le (show M * (M + span A {y}) β€ M, from ideal.mul_le_right),
rw mul_add,
apply sup_le (show span A {x} * M β€ M, from ideal.mul_le_left),
rwa [span_mul_span, set.singleton_mul_singleton, span_singleton_le_iff_mem] },
{ rintro (hx | hy); contradiction },
end
end prime_spectrum
|
62110f82d5b393ad48be7f8c9f134f5dede56586 | f3849be5d845a1cb97680f0bbbe03b85518312f0 | /library/tools/super/selection.lean | d26c17b6c7ed13bc86a60d4262de4320efc9e35d | [
"Apache-2.0"
] | permissive | bjoeris/lean | 0ed95125d762b17bfcb54dad1f9721f953f92eeb | 4e496b78d5e73545fa4f9a807155113d8e6b0561 | refs/heads/master | 1,611,251,218,281 | 1,495,337,658,000 | 1,495,337,658,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,954 | lean | /-
Copyright (c) 2016 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner
-/
import .prover_state
namespace super
meta def simple_selection_strategy (f : (expr β expr β bool) β clause β list β) : selection_strategy :=
take dc, do gt β get_term_order, return $
if dc.selected.empty β§ dc.c.num_lits > 0
then { dc with selected := f gt dc.c }
else dc
meta def dumb_selection : selection_strategy :=
simple_selection_strategy $ Ξ»gt c,
match c.lits_where clause.literal.is_neg with
| [] := list.range c.num_lits
| neg_lit::_ := [neg_lit]
end
meta def selection21 : selection_strategy :=
simple_selection_strategy $ Ξ»gt c,
let maximal_lits := list.filter_maximal (Ξ»i j,
gt (c.get_lit i).formula (c.get_lit j).formula) (list.range c.num_lits) in
if list.length maximal_lits = 1 then maximal_lits else
let neg_lits := list.filter (Ξ»i, (c.get_lit i).is_neg) (list.range c.num_lits),
maximal_neg_lits := list.filter_maximal (Ξ»i j,
gt (c.get_lit i).formula (c.get_lit j).formula) neg_lits in
if Β¬maximal_neg_lits.empty then
list.taken 1 maximal_neg_lits
else
maximal_lits
meta def selection22 : selection_strategy :=
simple_selection_strategy $ Ξ»gt c,
let maximal_lits := list.filter_maximal (Ξ»i j,
gt (c.get_lit i).formula (c.get_lit j).formula) (list.range c.num_lits),
maximal_lits_neg := list.filter (Ξ»i, (c.get_lit i).is_neg) maximal_lits in
if Β¬maximal_lits_neg.empty then
list.taken 1 maximal_lits_neg
else
maximal_lits
meta def clause_weight (c : derived_clause) : nat :=
(c.c.get_lits.for (Ξ»l, expr_size l.formula + if l.is_pos then 10 else 1)).sum
meta def find_minimal_by (passive : rb_map clause_id derived_clause)
{A} [has_ordering A]
(f : derived_clause β A) : clause_id :=
match rb_map.min $ rb_map.of_list $ passive.values.map $ Ξ»c, (f c, c.id) with
| some id := id
| none := nat.zero
end
meta def age_of_clause_id : name β β
| (name.mk_numeral i _) := unsigned.to_nat i
| _ := 0
meta def find_minimal_weight (passive : rb_map clause_id derived_clause) : clause_id :=
find_minimal_by passive $ Ξ»c, (c.sc.priority, clause_weight c + c.sc.cost, c.sc.age, c.id)
meta def find_minimal_age (passive : rb_map clause_id derived_clause) : clause_id :=
find_minimal_by passive $ Ξ»c, (c.sc.priority, c.sc.age, c.id)
meta def weight_clause_selection : clause_selection_strategy :=
take iter, do state β state_t.read, return $ find_minimal_weight state.passive
meta def oldest_clause_selection : clause_selection_strategy :=
take iter, do state β state_t.read, return $ find_minimal_age state.passive
meta def age_weight_clause_selection (thr mod : β) : clause_selection_strategy :=
take iter, if iter % mod < thr then
weight_clause_selection iter
else
oldest_clause_selection iter
end super
|
239753d7ae31851ee1bc47d099bf4e3ba7131852 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/data/int/modeq.lean | 99b5957c2f857c6ee8fd909365a41b12a291b20a | [] | 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 | 5,517 | 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 Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.nat.modeq
import Mathlib.tactic.ring
import Mathlib.PostPort
namespace Mathlib
namespace int
/-- `a β‘ b [ZMOD n]` when `a % n = b % n`. -/
def modeq (n : β€) (a : β€) (b : β€) :=
a % n = b % n
namespace modeq
protected theorem refl {n : β€} (a : β€) : modeq n a a :=
rfl
protected theorem symm {n : β€} {a : β€} {b : β€} : modeq n a b β modeq n b a :=
Eq.symm
protected theorem trans {n : β€} {a : β€} {b : β€} {c : β€} : modeq n a b β modeq n b c β modeq n a c :=
Eq.trans
theorem coe_nat_modeq_iff {a : β} {b : β} {n : β} : modeq βn βa βb β nat.modeq n a b := sorry
protected instance decidable {n : β€} {a : β€} {b : β€} : Decidable (modeq n a b) :=
eq.mpr sorry (int.decidable_eq (a % n) (b % n))
theorem modeq_zero_iff {n : β€} {a : β€} : modeq n a 0 β n β£ a :=
eq.mpr (id (Eq._oldrec (Eq.refl (modeq n a 0 β n β£ a)) (equations._eqn_1 n a 0)))
(eq.mpr (id (Eq._oldrec (Eq.refl (a % n = 0 % n β n β£ a)) (zero_mod n)))
(eq.mpr (id (Eq._oldrec (Eq.refl (a % n = 0 β n β£ a)) (propext (dvd_iff_mod_eq_zero n a)))) (iff.refl (a % n = 0))))
theorem modeq_iff_dvd {n : β€} {a : β€} {b : β€} : modeq n a b β n β£ b - a := sorry
theorem modeq_of_dvd_of_modeq {n : β€} {m : β€} {a : β€} {b : β€} (d : m β£ n) (h : modeq n a b) : modeq m a b :=
iff.mpr modeq_iff_dvd (dvd_trans d (iff.mp modeq_iff_dvd h))
theorem modeq_mul_left' {n : β€} {a : β€} {b : β€} {c : β€} (hc : 0 β€ c) (h : modeq n a b) : modeq (c * n) (c * a) (c * b) := sorry
theorem modeq_mul_right' {n : β€} {a : β€} {b : β€} {c : β€} (hc : 0 β€ c) (h : modeq n a b) : modeq (n * c) (a * c) (b * c) :=
eq.mpr (id (Eq._oldrec (Eq.refl (modeq (n * c) (a * c) (b * c))) (mul_comm a c)))
(eq.mpr (id (Eq._oldrec (Eq.refl (modeq (n * c) (c * a) (b * c))) (mul_comm b c)))
(eq.mpr (id (Eq._oldrec (Eq.refl (modeq (n * c) (c * a) (c * b))) (mul_comm n c))) (modeq_mul_left' hc h)))
theorem modeq_add {n : β€} {a : β€} {b : β€} {c : β€} {d : β€} (hβ : modeq n a b) (hβ : modeq n c d) : modeq n (a + c) (b + d) := sorry
theorem modeq_add_cancel_left {n : β€} {a : β€} {b : β€} {c : β€} {d : β€} (hβ : modeq n a b) (hβ : modeq n (a + c) (b + d)) : modeq n c d := sorry
theorem modeq_add_cancel_right {n : β€} {a : β€} {b : β€} {c : β€} {d : β€} (hβ : modeq n c d) (hβ : modeq n (a + c) (b + d)) : modeq n a b :=
modeq_add_cancel_left hβ
(eq.mp (Eq._oldrec (Eq.refl (modeq n (c + a) (b + d))) (add_comm b d))
(eq.mp (Eq._oldrec (Eq.refl (modeq n (a + c) (b + d))) (add_comm a c)) hβ))
theorem mod_modeq (a : β€) (n : β€) : modeq n (a % n) a :=
mod_mod a n
theorem modeq_neg {n : β€} {a : β€} {b : β€} (h : modeq n a b) : modeq n (-a) (-b) := sorry
theorem modeq_sub {n : β€} {a : β€} {b : β€} {c : β€} {d : β€} (hβ : modeq n a b) (hβ : modeq n c d) : modeq n (a - c) (b - d) :=
eq.mpr (id (Eq._oldrec (Eq.refl (modeq n (a - c) (b - d))) (sub_eq_add_neg a c)))
(eq.mpr (id (Eq._oldrec (Eq.refl (modeq n (a + -c) (b - d))) (sub_eq_add_neg b d))) (modeq_add hβ (modeq_neg hβ)))
theorem modeq_mul_left {n : β€} {a : β€} {b : β€} (c : β€) (h : modeq n a b) : modeq n (c * a) (c * b) := sorry
theorem modeq_mul_right {n : β€} {a : β€} {b : β€} (c : β€) (h : modeq n a b) : modeq n (a * c) (b * c) :=
eq.mpr (id (Eq._oldrec (Eq.refl (modeq n (a * c) (b * c))) (mul_comm a c)))
(eq.mpr (id (Eq._oldrec (Eq.refl (modeq n (c * a) (b * c))) (mul_comm b c))) (modeq_mul_left c h))
theorem modeq_mul {n : β€} {a : β€} {b : β€} {c : β€} {d : β€} (hβ : modeq n a b) (hβ : modeq n c d) : modeq n (a * c) (b * d) :=
modeq.trans (modeq_mul_left a hβ) (modeq_mul_right d hβ)
theorem modeq_of_modeq_mul_left {n : β€} {a : β€} {b : β€} (m : β€) (h : modeq (m * n) a b) : modeq n a b :=
eq.mpr (id (Eq._oldrec (Eq.refl (modeq n a b)) (propext modeq_iff_dvd)))
(dvd.trans (dvd_mul_left n m) (eq.mp (Eq._oldrec (Eq.refl (modeq (m * n) a b)) (propext modeq_iff_dvd)) h))
theorem modeq_of_modeq_mul_right {n : β€} {a : β€} {b : β€} (m : β€) : modeq (n * m) a b β modeq n a b :=
mul_comm m n βΈ modeq_of_modeq_mul_left m
theorem modeq_and_modeq_iff_modeq_mul {a : β€} {b : β€} {m : β€} {n : β€} (hmn : nat.coprime (nat_abs m) (nat_abs n)) : modeq m a b β§ modeq n a b β modeq (m * n) a b := sorry
theorem gcd_a_modeq (a : β) (b : β) : modeq (βb) (βa * nat.gcd_a a b) β(nat.gcd a b) := sorry
theorem modeq_add_fac {a : β€} {b : β€} {n : β€} (c : β€) (ha : modeq n a b) : modeq n (a + n * c) b := sorry
theorem mod_coprime {a : β} {b : β} (hab : nat.coprime a b) : β (y : β€), modeq (βb) (βa * y) 1 := sorry
theorem exists_unique_equiv (a : β€) {b : β€} (hb : 0 < b) : β (z : β€), 0 β€ z β§ z < b β§ modeq b z a := sorry
theorem exists_unique_equiv_nat (a : β€) {b : β€} (hb : 0 < b) : β (z : β), βz < b β§ modeq b (βz) a := sorry
end modeq
@[simp] theorem mod_mul_right_mod (a : β€) (b : β€) (c : β€) : a % (b * c) % b = a % b :=
modeq.modeq_of_modeq_mul_right c (modeq.mod_modeq a (b * c))
@[simp] theorem mod_mul_left_mod (a : β€) (b : β€) (c : β€) : a % (b * c) % c = a % c :=
modeq.modeq_of_modeq_mul_left b (modeq.mod_modeq a (b * c))
|
7f9256425fed1897611195d05a2f675463ea0452 | 35677d2df3f081738fa6b08138e03ee36bc33cad | /src/topology/instances/ennreal.lean | ad7ef4f32c44430b39c50a1416171369c51d99ab | [
"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 | 38,629 | lean | /-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Johannes HΓΆlzl
-/
import topology.instances.nnreal data.real.ennreal
/-!
# Extended non-negative reals
-/
noncomputable theory
open classical set filter metric
open_locale classical
open_locale topological_space
variables {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*}
open_locale ennreal
namespace ennreal
variables {a b c d : ennreal} {r p q : nnreal}
variables {x y z : ennreal} {Ξ΅ Ξ΅β Ξ΅β : ennreal} {s : set ennreal}
section topological_space
open topological_space
/-- Topology on `ennreal`.
Note: this is different from the `emetric_space` topology. The `emetric_space` topology has
`is_open {β€}`, while this topology doesn't have singleton elements. -/
instance : topological_space ennreal := preorder.topology ennreal
instance : order_topology ennreal := β¨rflβ©
instance : t2_space ennreal := by apply_instance -- short-circuit type class inference
instance : second_countable_topology ennreal :=
β¨β¨βq β₯ (0:β), {{a : ennreal | a < nnreal.of_real q}, {a : ennreal | β(nnreal.of_real q) < a}},
countable_bUnion (countable_encodable _) $ assume a ha, countable_insert (countable_singleton _),
le_antisymm
(le_generate_from $ by simp [or_imp_distrib, is_open_lt', is_open_gt'] {contextual := tt})
(le_generate_from $ Ξ» s h, begin
rcases h with β¨a, hs | hsβ©;
[ rw show s = βqβ{q:β | 0 β€ q β§ a < nnreal.of_real q}, {b | β(nnreal.of_real q) < b},
from set.ext (assume b, by simp [hs, @ennreal.lt_iff_exists_rat_btwn a b, and_assoc]),
rw show s = βqβ{q:β | 0 β€ q β§ β(nnreal.of_real q) < a}, {b | b < β(nnreal.of_real q)},
from set.ext (assume b, by simp [hs, @ennreal.lt_iff_exists_rat_btwn b a, and_comm, and_assoc])];
{ apply is_open_Union, intro q,
apply is_open_Union, intro hq,
exact generate_open.basic _ (mem_bUnion hq.1 $ by simp) }
end)β©β©
lemma embedding_coe : embedding (coe : nnreal β ennreal) :=
β¨β¨begin
refine le_antisymm _ _,
{ rw [@order_topology.topology_eq_generate_intervals ennreal _,
β coinduced_le_iff_le_induced],
refine le_generate_from (assume s ha, _),
rcases ha with β¨a, rfl | rflβ©,
show is_open {b : nnreal | a < βb},
{ cases a; simp [none_eq_top, some_eq_coe, is_open_lt'] },
show is_open {b : nnreal | βb < a},
{ cases a; simp [none_eq_top, some_eq_coe, is_open_gt', is_open_const] } },
{ rw [@order_topology.topology_eq_generate_intervals nnreal _],
refine le_generate_from (assume s ha, _),
rcases ha with β¨a, rfl | rflβ©,
exact β¨Ioi a, is_open_Ioi, by simp [Ioi]β©,
exact β¨Iio a, is_open_Iio, by simp [Iio]β© }
endβ©,
assume a b, coe_eq_coe.1β©
lemma is_open_ne_top : is_open {a : ennreal | a β β€} :=
is_open_neg (is_closed_eq continuous_id continuous_const)
lemma is_open_Ico_zero : is_open (Ico 0 b) := by { rw ennreal.Ico_eq_Iio, exact is_open_Iio}
lemma coe_range_mem_nhds : range (coe : nnreal β ennreal) β π (r : ennreal) :=
have {a : ennreal | a β β€} = range (coe : nnreal β ennreal),
from set.ext $ assume a, by cases a; simp [none_eq_top, some_eq_coe],
this βΈ mem_nhds_sets is_open_ne_top coe_ne_top
@[elim_cast] lemma tendsto_coe {f : filter Ξ±} {m : Ξ± β nnreal} {a : nnreal} :
tendsto (Ξ»a, (m a : ennreal)) f (π βa) β tendsto m f (π a) :=
embedding_coe.tendsto_nhds_iff.symm
lemma continuous_coe {Ξ±} [topological_space Ξ±] {f : Ξ± β nnreal} :
continuous (Ξ»a, (f a : ennreal)) β continuous f :=
embedding_coe.continuous_iff.symm
lemma nhds_coe {r : nnreal} : π (r : ennreal) = (π r).map coe :=
by rw [embedding_coe.induced, map_nhds_induced_eq coe_range_mem_nhds]
lemma nhds_coe_coe {r p : nnreal} : π ((r : ennreal), (p : ennreal)) =
(π (r, p)).map (Ξ»p:nnrealΓnnreal, (p.1, p.2)) :=
begin
rw [(embedding_coe.prod_mk embedding_coe).map_nhds_eq],
rw [β prod_range_range_eq],
exact prod_mem_nhds_sets coe_range_mem_nhds coe_range_mem_nhds
end
lemma continuous_of_real : continuous ennreal.of_real :=
(continuous_coe.2 continuous_id).comp nnreal.continuous_of_real
lemma tendsto_of_real {f : filter Ξ±} {m : Ξ± β β} {a : β} (h : tendsto m f (π a)) :
tendsto (Ξ»a, ennreal.of_real (m a)) f (π (ennreal.of_real a)) :=
tendsto.comp (continuous.tendsto continuous_of_real _) h
lemma tendsto_to_nnreal {a : ennreal} : a β β€ β
tendsto (ennreal.to_nnreal) (π a) (π a.to_nnreal) :=
begin
cases a; simp [some_eq_coe, none_eq_top, nhds_coe, tendsto_map'_iff, (β)],
exact tendsto_id
end
lemma continuous_on_to_nnreal : continuous_on ennreal.to_nnreal {a | a β β} :=
continuous_on_iff_continuous_restrict.2 $ continuous_iff_continuous_at.2 $ Ξ» x,
(tendsto_to_nnreal x.2).comp continuous_at_subtype_val
lemma tendsto_to_real {a : ennreal} : a β β€ β tendsto (ennreal.to_real) (π a) (π a.to_real) :=
Ξ» ha, tendsto.comp ((@nnreal.tendsto_coe _ (π a.to_nnreal) id (a.to_nnreal)).2 tendsto_id)
(tendsto_to_nnreal ha)
lemma tendsto_nhds_top {m : Ξ± β ennreal} {f : filter Ξ±}
(h : β n : β, βαΆ a in f, βn < m a) : tendsto m f (π β€) :=
tendsto_nhds_generate_from $ assume s hs,
match s, hs with
| _, β¨none, or.inl rflβ©, hr := (lt_irrefl β€ hr).elim
| _, β¨some r, or.inl rflβ©, hr :=
let β¨n, hrnβ© := exists_nat_gt r in
mem_sets_of_superset (h n) $ assume a hnma, show βr < m a, from
lt_trans (show (r : ennreal) < n, from (coe_nat n) βΈ coe_lt_coe.2 hrn) hnma
| _, β¨a, or.inr rflβ©, hr := (not_top_lt $ show β€ < a, from hr).elim
end
lemma tendsto_nat_nhds_top : tendsto (Ξ» n : β, βn) at_top (π β) :=
tendsto_nhds_top $ Ξ» n, mem_at_top_sets.2
β¨n+1, Ξ» m hm, ennreal.coe_nat_lt_coe_nat.2 $ nat.lt_of_succ_le hmβ©
lemma nhds_top : π β = β¨
a β β, principal (Ioi a) :=
nhds_top_order.trans $ by simp [lt_top_iff_ne_top, Ioi]
lemma nhds_zero : π (0 : ennreal) = β¨
a β 0, principal (Iio a) :=
nhds_bot_order.trans $ by simp [bot_lt_iff_ne_bot, Iio]
/-- The set of finite `ennreal` numbers is homeomorphic to `nnreal`. -/
def ne_top_homeomorph_nnreal : {a | a β β} ββ nnreal :=
{ to_fun := Ξ» x, ennreal.to_nnreal x,
inv_fun := Ξ» x, β¨x, coe_ne_topβ©,
left_inv := Ξ» β¨x, hxβ©, subtype.eq $ coe_to_nnreal hx,
right_inv := Ξ» x, to_nnreal_coe,
continuous_to_fun := continuous_on_iff_continuous_restrict.1 continuous_on_to_nnreal,
continuous_inv_fun := continuous_subtype_mk _ (continuous_coe.2 continuous_id) }
/-- The set of finite `ennreal` numbers is homeomorphic to `nnreal`. -/
def lt_top_homeomorph_nnreal : {a | a < β} ββ nnreal :=
by refine (homeomorph.set_congr $ set.ext $ Ξ» x, _).trans ne_top_homeomorph_nnreal;
simp only [mem_set_of_eq, lt_top_iff_ne_top]
-- using Icc because
-- β’ don't have 'Ioo (x - Ξ΅) (x + Ξ΅) β π x' unless x > 0
-- β’ (x - y β€ Ξ΅ β x β€ Ξ΅ + y) is true, while (x - y < Ξ΅ β x < Ξ΅ + y) is not
lemma Icc_mem_nhds : x β β€ β Ξ΅ > 0 β Icc (x - Ξ΅) (x + Ξ΅) β π x :=
begin
assume xt Ξ΅0, rw mem_nhds_sets_iff,
by_cases x0 : x = 0,
{ use Iio (x + Ξ΅),
have : Iio (x + Ξ΅) β Icc (x - Ξ΅) (x + Ξ΅), assume a, rw x0, simpa using le_of_lt,
use this, exact β¨is_open_Iio, mem_Iio_self_add xt Ξ΅0β© },
{ use Ioo (x - Ξ΅) (x + Ξ΅), use Ioo_subset_Icc_self,
exact β¨is_open_Ioo, mem_Ioo_self_sub_add xt x0 Ξ΅0 Ξ΅0 β© }
end
lemma nhds_of_ne_top : x β β€ β π x = β¨
Ξ΅ > 0, principal (Icc (x - Ξ΅) (x + Ξ΅)) :=
begin
assume xt, refine le_antisymm _ _,
-- first direction
simp only [le_infi_iff, le_principal_iff], assume Ξ΅ Ξ΅0, exact Icc_mem_nhds xt Ξ΅0,
-- second direction
rw nhds_generate_from, refine le_infi (assume s, le_infi $ assume hs, _),
simp only [mem_set_of_eq] at hs, rcases hs with β¨xs, β¨a, haβ©β©,
cases ha,
{ rw ha at *,
rcases dense xs with β¨b, β¨ab, bxβ©β©,
have xb_pos : x - b > 0 := zero_lt_sub_iff_lt.2 bx,
have xxb : x - (x - b) = b := sub_sub_cancel (by rwa lt_top_iff_ne_top) (le_of_lt bx),
refine infi_le_of_le (x - b) (infi_le_of_le xb_pos _),
simp only [mem_principal_sets, le_principal_iff],
assume y, rintros β¨hβ, hββ©, rw xxb at hβ, calc a < b : ab ... β€ y : hβ },
{ rw ha at *,
rcases dense xs with β¨b, β¨xb, baβ©β©,
have bx_pos : b - x > 0 := zero_lt_sub_iff_lt.2 xb,
have xbx : x + (b - x) = b := add_sub_cancel_of_le (le_of_lt xb),
refine infi_le_of_le (b - x) (infi_le_of_le bx_pos _),
simp only [mem_principal_sets, le_principal_iff],
assume y, rintros β¨hβ, hββ©, rw xbx at hβ, calc y β€ b : hβ ... < a : ba },
end
/-- Characterization of neighborhoods for `ennreal` numbers. See also `tendsto_order`
for a version with strict inequalities. -/
protected theorem tendsto_nhds {f : filter Ξ±} {u : Ξ± β ennreal} {a : ennreal} (ha : a β β€) :
tendsto u f (π a) β β Ξ΅ > 0, βαΆ x in f, (u x) β Icc (a - Ξ΅) (a + Ξ΅) :=
by simp only [nhds_of_ne_top ha, tendsto_infi, tendsto_principal, mem_Icc]
protected lemma tendsto_at_top [nonempty Ξ²] [semilattice_sup Ξ²] {f : Ξ² β ennreal} {a : ennreal}
(ha : a β β€) : tendsto f at_top (π a) β βΞ΅>0, βN, βnβ₯N, (f n) β Icc (a - Ξ΅) (a + Ξ΅) :=
by simp only [ennreal.tendsto_nhds ha, mem_at_top_sets, mem_set_of_eq, filter.eventually]
lemma tendsto_coe_nnreal_nhds_top {Ξ±} {l : filter Ξ±} {f : Ξ± β nnreal} (h : tendsto f l at_top) :
tendsto (Ξ»a, (f a : ennreal)) l (π β) :=
tendsto_nhds_top $ assume n,
have βαΆ a in l, β(n+1) β€ f a := h $ mem_at_top _,
mem_sets_of_superset this $ assume a (ha : β(n+1) β€ f a),
begin
rw [β coe_nat],
dsimp,
exact coe_lt_coe.2 (lt_of_lt_of_le (nat.cast_lt.2 (nat.lt_succ_self _)) ha)
end
instance : topological_add_monoid ennreal :=
β¨ continuous_iff_continuous_at.2 $
have hl : βa:ennreal, tendsto (Ξ» (p : ennreal Γ ennreal), p.fst + p.snd) (π (β€, a)) (π β€), from
assume a, tendsto_nhds_top $ assume n,
have set.prod {a | βn < a } univ β π ((β€:ennreal), a), from
prod_mem_nhds_sets (lt_mem_nhds $ coe_nat n βΈ coe_lt_top) univ_mem_sets,
show {a : ennreal Γ ennreal | βn < a.fst + a.snd} β π (β€, a),
begin filter_upwards [this] assume β¨aβ, aββ© β¨hβ, hββ©, lt_of_lt_of_le hβ (le_add_right $ le_refl _) end,
begin
rintro β¨aβ, aββ©,
cases aβ, { simp [continuous_at, none_eq_top, hl aβ], },
cases aβ, { simp [continuous_at, none_eq_top, some_eq_coe, nhds_swap (aβ : ennreal) β€,
tendsto_map'_iff, (β)], convert hl aβ, simp [add_comm] },
simp [continuous_at, some_eq_coe, nhds_coe_coe, tendsto_map'_iff, (β)],
simp only [coe_add.symm, tendsto_coe, tendsto_add]
end β©
protected lemma tendsto_mul (ha : a β 0 β¨ b β β€) (hb : b β 0 β¨ a β β€) :
tendsto (Ξ»p:ennrealΓennreal, p.1 * p.2) (π (a, b)) (π (a * b)) :=
have ht : βb:ennreal, b β 0 β tendsto (Ξ»p:ennrealΓennreal, p.1 * p.2) (π ((β€:ennreal), b)) (π β€),
begin
refine assume b hb, tendsto_nhds_top $ assume n, _,
rcases dense (zero_lt_iff_ne_zero.2 hb) with β¨Ξ΅', hΞ΅', hΞ΅b'β©,
rcases ennreal.lt_iff_exists_coe.1 hΞ΅b' with β¨Ξ΅, rfl, hβ©,
rcases exists_nat_gt (βn / Ξ΅) with β¨m, hmβ©,
have hΞ΅ : Ξ΅ > 0, from coe_lt_coe.1 hΞ΅',
refine mem_sets_of_superset (prod_mem_nhds_sets (lt_mem_nhds $ @coe_lt_top m) (lt_mem_nhds $ h)) _,
rintros β¨aβ, aββ© β¨hβ, hββ©,
dsimp at hβ hβ β’,
calc (n:ennreal) = β(((n:nnreal) / Ξ΅) * Ξ΅) :
begin
simp [nnreal.div_def],
rw [mul_assoc, β coe_mul, nnreal.inv_mul_cancel, coe_one, β coe_nat, mul_one],
exact zero_lt_iff_ne_zero.1 hΞ΅
end
... < (βm * Ξ΅ : nnreal) : coe_lt_coe.2 $ mul_lt_mul hm (le_refl _) hΞ΅ (nat.cast_nonneg _)
... β€ aβ * aβ : by rw [coe_mul]; exact canonically_ordered_semiring.mul_le_mul
(le_of_lt hβ)
(le_of_lt hβ)
end,
begin
cases a, {simp [none_eq_top] at hb, simp [none_eq_top, ht b hb, top_mul, hb] },
cases b, {
simp [none_eq_top] at ha,
simp [*, nhds_swap (a : ennreal) β€, none_eq_top, some_eq_coe, top_mul, tendsto_map'_iff, (β), mul_comm] },
simp [some_eq_coe, nhds_coe_coe, tendsto_map'_iff, (β)],
simp only [coe_mul.symm, tendsto_coe, tendsto_mul]
end
protected lemma tendsto.mul {f : filter Ξ±} {ma : Ξ± β ennreal} {mb : Ξ± β ennreal} {a b : ennreal}
(hma : tendsto ma f (π a)) (ha : a β 0 β¨ b β β€) (hmb : tendsto mb f (π b)) (hb : b β 0 β¨ a β β€) :
tendsto (Ξ»a, ma a * mb a) f (π (a * b)) :=
show tendsto ((Ξ»p:ennrealΓennreal, p.1 * p.2) β (Ξ»a, (ma a, mb a))) f (π (a * b)), from
tendsto.comp (ennreal.tendsto_mul ha hb) (hma.prod_mk_nhds hmb)
protected lemma tendsto.const_mul {f : filter Ξ±} {m : Ξ± β ennreal} {a b : ennreal}
(hm : tendsto m f (π b)) (hb : b β 0 β¨ a β β€) : tendsto (Ξ»b, a * m b) f (π (a * b)) :=
by_cases
(assume : a = 0, by simp [this, tendsto_const_nhds])
(assume ha : a β 0, ennreal.tendsto.mul tendsto_const_nhds (or.inl ha) hm hb)
protected lemma tendsto.mul_const {f : filter Ξ±} {m : Ξ± β ennreal} {a b : ennreal}
(hm : tendsto m f (π a)) (ha : a β 0 β¨ b β β€) : tendsto (Ξ»x, m x * b) f (π (a * b)) :=
by simpa only [mul_comm] using ennreal.tendsto.const_mul hm ha
protected lemma continuous_const_mul {a : ennreal} (ha : a < β€) : continuous ((*) a) :=
continuous_iff_continuous_at.2 $ Ξ» x, tendsto.const_mul tendsto_id $ or.inr $ ne_of_lt ha
protected lemma continuous_mul_const {a : ennreal} (ha : a < β€) : continuous (Ξ» x, x * a) :=
by simpa only [mul_comm] using ennreal.continuous_const_mul ha
protected lemma continuous_inv : continuous (has_inv.inv : ennreal β ennreal) :=
continuous_iff_continuous_at.2 $ Ξ» a, tendsto_order.2
β¨begin
assume b hb,
simp only [@ennreal.lt_inv_iff_lt_inv b],
exact gt_mem_nhds (ennreal.lt_inv_iff_lt_inv.1 hb),
end,
begin
assume b hb,
simp only [gt_iff_lt, @ennreal.inv_lt_iff_inv_lt _ b],
exact lt_mem_nhds (ennreal.inv_lt_iff_inv_lt.1 hb)
endβ©
@[simp] protected lemma tendsto_inv_iff {f : filter Ξ±} {m : Ξ± β ennreal} {a : ennreal} :
tendsto (Ξ» x, (m x)β»ΒΉ) f (π aβ»ΒΉ) β tendsto m f (π a) :=
β¨Ξ» h, by simpa only [function.comp, ennreal.inv_inv]
using (ennreal.continuous_inv.tendsto aβ»ΒΉ).comp h,
(ennreal.continuous_inv.tendsto a).compβ©
protected lemma tendsto.div {f : filter Ξ±} {ma : Ξ± β ennreal} {mb : Ξ± β ennreal} {a b : ennreal}
(hma : tendsto ma f (π a)) (ha : a β 0 β¨ b β 0) (hmb : tendsto mb f (π b)) (hb : b β β€ β¨ a β β€) :
tendsto (Ξ»a, ma a / mb a) f (π (a / b)) :=
by { apply tendsto.mul hma _ (ennreal.tendsto_inv_iff.2 hmb) _; simp [ha, hb] }
protected lemma tendsto.const_div {f : filter Ξ±} {m : Ξ± β ennreal} {a b : ennreal}
(hm : tendsto m f (π b)) (hb : b β β€ β¨ a β β€) : tendsto (Ξ»b, a / m b) f (π (a / b)) :=
by { apply tendsto.const_mul (ennreal.tendsto_inv_iff.2 hm), simp [hb] }
protected lemma tendsto.div_const {f : filter Ξ±} {m : Ξ± β ennreal} {a b : ennreal}
(hm : tendsto m f (π a)) (ha : a β 0 β¨ b β 0) : tendsto (Ξ»x, m x / b) f (π (a / b)) :=
by { apply tendsto.mul_const hm, simp [ha] }
protected lemma tendsto_inv_nat_nhds_zero : tendsto (Ξ» n : β, (n : ennreal)β»ΒΉ) at_top (π 0) :=
ennreal.inv_top βΈ ennreal.tendsto_inv_iff.2 tendsto_nat_nhds_top
lemma Sup_add {s : set ennreal} (hs : s.nonempty) : Sup s + a = β¨bβs, b + a :=
have Sup ((Ξ»b, b + a) '' s) = Sup s + a,
from is_lub.Sup_eq (is_lub_of_is_lub_of_tendsto
(assume x _ y _ h, add_le_add' h (le_refl _))
(is_lub_Sup s)
hs
(tendsto.add (tendsto_id' inf_le_left) tendsto_const_nhds)),
by simp [Sup_image, -add_comm] at this; exact this.symm
lemma supr_add {ΞΉ : Sort*} {s : ΞΉ β ennreal} [h : nonempty ΞΉ] : supr s + a = β¨b, s b + a :=
let β¨xβ© := h in
calc supr s + a = Sup (range s) + a : by simp [Sup_range]
... = (β¨bβrange s, b + a) : Sup_add β¨s x, x, rflβ©
... = _ : supr_range
lemma add_supr {ΞΉ : Sort*} {s : ΞΉ β ennreal} [h : nonempty ΞΉ] : a + supr s = β¨b, a + s b :=
by rw [add_comm, supr_add]; simp [add_comm]
lemma supr_add_supr {ΞΉ : Sort*} {f g : ΞΉ β ennreal} (h : βi j, βk, f i + g j β€ f k + g k) :
supr f + supr g = (β¨ a, f a + g a) :=
begin
by_cases hΞΉ : nonempty ΞΉ,
{ letI := hΞΉ,
refine le_antisymm _ (supr_le $ Ξ» a, add_le_add' (le_supr _ _) (le_supr _ _)),
simpa [add_supr, supr_add] using
Ξ» i j:ΞΉ, show f i + g j β€ β¨ a, f a + g a, from
let β¨k, hkβ© := h i j in le_supr_of_le k hk },
{ have : βf:ΞΉ β ennreal, (β¨i, f i) = 0 := assume f, bot_unique (supr_le $ assume i, (hΞΉ β¨iβ©).elim),
rw [this, this, this, zero_add] }
end
lemma supr_add_supr_of_monotone {ΞΉ : Sort*} [semilattice_sup ΞΉ]
{f g : ΞΉ β ennreal} (hf : monotone f) (hg : monotone g) :
supr f + supr g = (β¨ a, f a + g a) :=
supr_add_supr $ assume i j, β¨i β j, add_le_add' (hf $ le_sup_left) (hg $ le_sup_right)β©
lemma finset_sum_supr_nat {Ξ±} {ΞΉ} [semilattice_sup ΞΉ] {s : finset Ξ±} {f : Ξ± β ΞΉ β ennreal}
(hf : βa, monotone (f a)) :
s.sum (Ξ»a, supr (f a)) = (β¨ n, s.sum (Ξ»a, f a n)) :=
begin
refine finset.induction_on s _ _,
{ simp,
exact (bot_unique $ supr_le $ assume i, le_refl β₯).symm },
{ assume a s has ih,
simp only [finset.sum_insert has],
rw [ih, supr_add_supr_of_monotone (hf a)],
assume i j h,
exact (finset.sum_le_sum $ assume a ha, hf a h) }
end
section priority
-- for some reason the next proof fails without changing the priority of this instance
local attribute [instance, priority 1000] classical.prop_decidable
lemma mul_Sup {s : set ennreal} {a : ennreal} : a * Sup s = β¨iβs, a * i :=
begin
by_cases hs : βxβs, x = (0:ennreal),
{ have hβ : Sup s = 0 := (bot_unique $ Sup_le $ assume a ha, (hs a ha).symm βΈ le_refl 0),
have hβ : (β¨i β s, a * i) = 0 :=
(bot_unique $ supr_le $ assume a, supr_le $ assume ha, by simp [hs a ha]),
rw [hβ, hβ, mul_zero] },
{ simp only [not_forall] at hs,
rcases hs with β¨x, hx, hx0β©,
have sβ : Sup s β 0 :=
zero_lt_iff_ne_zero.1 (lt_of_lt_of_le (zero_lt_iff_ne_zero.2 hx0) (le_Sup hx)),
have : Sup ((Ξ»b, a * b) '' s) = a * Sup s :=
is_lub.Sup_eq (is_lub_of_is_lub_of_tendsto
(assume x _ y _ h, canonically_ordered_semiring.mul_le_mul (le_refl _) h)
(is_lub_Sup _)
β¨x, hxβ©
(ennreal.tendsto.const_mul (tendsto_id' inf_le_left) (or.inl sβ))),
rw [this.symm, Sup_image] }
end
end priority
lemma mul_supr {ΞΉ : Sort*} {f : ΞΉ β ennreal} {a : ennreal} : a * supr f = β¨i, a * f i :=
by rw [β Sup_range, mul_Sup, supr_range]
lemma supr_mul {ΞΉ : Sort*} {f : ΞΉ β ennreal} {a : ennreal} : supr f * a = β¨i, f i * a :=
by rw [mul_comm, mul_supr]; congr; funext; rw [mul_comm]
protected lemma tendsto_coe_sub : β{b:ennreal}, tendsto (Ξ»b:ennreal, βr - b) (π b) (π (βr - b)) :=
begin
refine (forall_ennreal.2 $ and.intro (assume a, _) _),
{ simp [@nhds_coe a, tendsto_map'_iff, (β), tendsto_coe, coe_sub.symm],
exact nnreal.tendsto.sub tendsto_const_nhds tendsto_id },
simp,
exact (tendsto.congr' (mem_sets_of_superset (lt_mem_nhds $ @coe_lt_top r) $
by simp [le_of_lt] {contextual := tt})) tendsto_const_nhds
end
lemma sub_supr {ΞΉ : Sort*} [hΞΉ : nonempty ΞΉ] {b : ΞΉ β ennreal} (hr : a < β€) :
a - (β¨i, b i) = (β¨
i, a - b i) :=
let β¨iβ© := hΞΉ in
let β¨r, eq, _β© := lt_iff_exists_coe.mp hr in
have Inf ((Ξ»b, βr - b) '' range b) = βr - (β¨i, b i),
from is_glb.Inf_eq $ is_glb_of_is_lub_of_tendsto
(assume x _ y _, sub_le_sub (le_refl _))
is_lub_supr
β¨_, i, rflβ©
(tendsto.comp ennreal.tendsto_coe_sub (tendsto_id' inf_le_left)),
by rw [eq, βthis]; simp [Inf_image, infi_range, -mem_range]; exact le_refl _
end topological_space
section tsum
variables {f g : Ξ± β ennreal}
@[elim_cast] protected lemma has_sum_coe {f : Ξ± β nnreal} {r : nnreal} :
has_sum (Ξ»a, (f a : ennreal)) βr β has_sum f r :=
have (Ξ»s:finset Ξ±, s.sum (coe β f)) = (coe : nnreal β ennreal) β (Ξ»s:finset Ξ±, s.sum f),
from funext $ assume s, ennreal.coe_finset_sum.symm,
by unfold has_sum; rw [this, tendsto_coe]
protected lemma tsum_coe_eq {f : Ξ± β nnreal} (h : has_sum f r) : (βa, (f a : ennreal)) = r :=
tsum_eq_has_sum $ ennreal.has_sum_coe.2 $ h
protected lemma coe_tsum {f : Ξ± β nnreal} : summable f β β(tsum f) = (βa, (f a : ennreal))
| β¨r, hrβ© := by rw [tsum_eq_has_sum hr, ennreal.tsum_coe_eq hr]
protected lemma has_sum : has_sum f (β¨s:finset Ξ±, s.sum f) :=
tendsto_order.2
β¨assume a' ha',
let β¨s, hsβ© := lt_supr_iff.mp ha' in
mem_at_top_sets.mpr β¨s, assume t ht, lt_of_lt_of_le hs $ finset.sum_le_sum_of_subset htβ©,
assume a' ha',
univ_mem_sets' $ assume s,
have s.sum f β€ β¨(s : finset Ξ±), s.sum f,
from le_supr (Ξ»(s : finset Ξ±), s.sum f) s,
lt_of_le_of_lt this ha'β©
@[simp] protected lemma summable : summable f := β¨_, ennreal.has_sumβ©
lemma tsum_coe_ne_top_iff_summable {f : Ξ² β nnreal} :
(β b, (f b:ennreal)) β β β summable f :=
begin
refine β¨Ξ» h, _, Ξ» h, ennreal.coe_tsum h βΈ ennreal.coe_ne_topβ©,
lift (β b, (f b:ennreal)) to nnreal using h with a ha,
refine β¨a, ennreal.has_sum_coe.1 _β©,
rw ha,
exact ennreal.summable.has_sum
end
protected lemma tsum_eq_supr_sum : (βa, f a) = (β¨s:finset Ξ±, s.sum f) :=
tsum_eq_has_sum ennreal.has_sum
protected lemma tsum_eq_top_of_eq_top : (β a, f a = β) β (β a, f a) = β
| β¨a, haβ© :=
begin
rw [ennreal.tsum_eq_supr_sum],
apply le_antisymm le_top,
convert le_supr (Ξ» s:finset Ξ±, s.sum f) (finset.singleton a),
rw [finset.sum_singleton, ha]
end
protected lemma ne_top_of_tsum_ne_top (h : (β a, f a) β β) (a : Ξ±) : f a β β :=
Ξ» ha, h $ ennreal.tsum_eq_top_of_eq_top β¨a, haβ©
protected lemma tsum_sigma {Ξ² : Ξ± β Type*} (f : Ξ a, Ξ² a β ennreal) :
(βp:Ξ£a, Ξ² a, f p.1 p.2) = (βa b, f a b) :=
tsum_sigma (assume b, ennreal.summable) ennreal.summable
protected lemma tsum_sigma' {Ξ² : Ξ± β Type*} (f : (Ξ£ a, Ξ² a) β ennreal) :
(βp:(Ξ£a, Ξ² a), f p) = (βa b, f β¨a, bβ©) :=
tsum_sigma (assume b, ennreal.summable) ennreal.summable
protected lemma tsum_prod {f : Ξ± β Ξ² β ennreal} : (βp:Ξ±ΓΞ², f p.1 p.2) = (βa, βb, f a b) :=
let j : Ξ± Γ Ξ² β (Ξ£a:Ξ±, Ξ²) := Ξ»p, sigma.mk p.1 p.2 in
let i : (Ξ£a:Ξ±, Ξ²) β Ξ± Γ Ξ² := Ξ»p, (p.1, p.2) in
let f' : (Ξ£a:Ξ±, Ξ²) β ennreal := Ξ»p, f p.1 p.2 in
calc (βp:Ξ±ΓΞ², f' (j p)) = (βp:Ξ£a:Ξ±, Ξ², f p.1 p.2) :
tsum_eq_tsum_of_iso j i (assume β¨a, bβ©, rfl) (assume β¨a, bβ©, rfl)
... = (βa, βb, f a b) : ennreal.tsum_sigma f
protected lemma tsum_comm {f : Ξ± β Ξ² β ennreal} : (βa, βb, f a b) = (βb, βa, f a b) :=
let f' : Ξ±ΓΞ² β ennreal := Ξ»p, f p.1 p.2 in
calc (βa, βb, f a b) = (βp:Ξ±ΓΞ², f' p) : ennreal.tsum_prod.symm
... = (βp:Ξ²ΓΞ±, f' (prod.swap p)) :
(tsum_eq_tsum_of_iso prod.swap (@prod.swap Ξ± Ξ²) (assume β¨a, bβ©, rfl) (assume β¨a, bβ©, rfl)).symm
... = (βb, βa, f' (prod.swap (b, a))) : @ennreal.tsum_prod Ξ² Ξ± (Ξ»b a, f' (prod.swap (b, a)))
protected lemma tsum_add : (βa, f a + g a) = (βa, f a) + (βa, g a) :=
tsum_add ennreal.summable ennreal.summable
protected lemma tsum_le_tsum (h : βa, f a β€ g a) : (βa, f a) β€ (βa, g a) :=
tsum_le_tsum h ennreal.summable ennreal.summable
protected lemma tsum_eq_supr_nat {f : β β ennreal} :
(βi:β, f i) = (β¨i:β, (finset.range i).sum f) :=
calc _ = (β¨s:finset β, s.sum f) : ennreal.tsum_eq_supr_sum
... = (β¨i:β, (finset.range i).sum f) : le_antisymm
(supr_le_supr2 $ assume s,
let β¨n, hnβ© := finset.exists_nat_subset_range s in
β¨n, finset.sum_le_sum_of_subset hnβ©)
(supr_le_supr2 $ assume i, β¨finset.range i, le_refl _β©)
protected lemma le_tsum (a : Ξ±) : f a β€ (βa, f a) :=
calc f a = ({a} : finset Ξ±).sum f : by simp
... β€ (β¨s:finset Ξ±, s.sum f) : le_supr (Ξ»s:finset Ξ±, s.sum f) _
... = (βa, f a) : by rw [ennreal.tsum_eq_supr_sum]
protected lemma tsum_mul_left : (βi, a * f i) = a * (βi, f i) :=
if h : βi, f i = 0 then by simp [h] else
let β¨i, (hi : f i β 0)β© := classical.not_forall.mp h in
have sum_ne_0 : (βi, f i) β 0, from ne_of_gt $
calc 0 < f i : lt_of_le_of_ne (zero_le _) hi.symm
... β€ (βi, f i) : ennreal.le_tsum _,
have tendsto (Ξ»s:finset Ξ±, s.sum ((*) a β f)) at_top (π (a * (βi, f i))),
by rw [β show (*) a β (Ξ»s:finset Ξ±, s.sum f) = Ξ»s, s.sum ((*) a β f),
from funext $ Ξ» s, finset.mul_sum];
exact ennreal.tendsto.const_mul ennreal.summable.has_sum (or.inl sum_ne_0),
tsum_eq_has_sum this
protected lemma tsum_mul_right : (βi, f i * a) = (βi, f i) * a :=
by simp [mul_comm, ennreal.tsum_mul_left]
@[simp] lemma tsum_supr_eq {Ξ± : Type*} (a : Ξ±) {f : Ξ± β ennreal} :
(βb:Ξ±, β¨ (h : a = b), f b) = f a :=
le_antisymm
(by rw [ennreal.tsum_eq_supr_sum]; exact supr_le (assume s,
calc s.sum (Ξ»b, β¨ (h : a = b), f b) β€ (finset.singleton a).sum (Ξ»b, β¨ (h : a = b), f b) :
finset.sum_le_sum_of_ne_zero $ assume b _ hb,
suffices a = b, by simpa using this.symm,
classical.by_contradiction $ assume h,
by simpa [h] using hb
... = f a : by simp))
(calc f a β€ (β¨ (h : a = a), f a) : le_supr (Ξ»h:a=a, f a) rfl
... β€ (βb:Ξ±, β¨ (h : a = b), f b) : ennreal.le_tsum _)
lemma has_sum_iff_tendsto_nat {f : β β ennreal} (r : ennreal) :
has_sum f r β tendsto (Ξ»n:β, (finset.range n).sum f) at_top (π r) :=
begin
refine β¨has_sum.tendsto_sum_nat, assume h, _β©,
rw [β supr_eq_of_tendsto _ h, β ennreal.tsum_eq_supr_nat],
{ exact ennreal.summable.has_sum },
{ exact assume s t hst, finset.sum_le_sum_of_subset (finset.range_subset.2 hst) }
end
end tsum
end ennreal
namespace nnreal
lemma exists_le_has_sum_of_le {f g : Ξ² β nnreal} {r : nnreal}
(hgf : βb, g b β€ f b) (hfr : has_sum f r) : βpβ€r, has_sum g p :=
have (βb, (g b : ennreal)) β€ r,
begin
refine has_sum_le (assume b, _) ennreal.summable.has_sum (ennreal.has_sum_coe.2 hfr),
exact ennreal.coe_le_coe.2 (hgf _)
end,
let β¨p, eq, hprβ© := ennreal.le_coe_iff.1 this in
β¨p, hpr, ennreal.has_sum_coe.1 $ eq βΈ ennreal.summable.has_sumβ©
lemma summable_of_le {f g : Ξ² β nnreal} (hgf : βb, g b β€ f b) : summable f β summable g
| β¨r, hfrβ© := let β¨p, _, hpβ© := exists_le_has_sum_of_le hgf hfr in hp.summable
lemma has_sum_iff_tendsto_nat {f : β β nnreal} (r : nnreal) :
has_sum f r β tendsto (Ξ»n:β, (finset.range n).sum f) at_top (π r) :=
begin
rw [β ennreal.has_sum_coe, ennreal.has_sum_iff_tendsto_nat],
simp only [ennreal.coe_finset_sum.symm],
exact ennreal.tendsto_coe
end
lemma tsum_comp_le_tsum_of_inj {Ξ² : Type*} {f : Ξ± β nnreal} (hf : summable f)
{i : Ξ² β Ξ±} (hi : function.injective i) : tsum (f β i) β€ tsum f :=
tsum_le_tsum_of_inj i hi (Ξ» c hc, zero_le _) (Ξ» b, le_refl _) (summable_comp_injective hf hi) hf
end nnreal
lemma tsum_comp_le_tsum_of_inj {Ξ² : Type*} {f : Ξ± β β} (hf : summable f) (hn : β a, 0 β€ f a)
{i : Ξ² β Ξ±} (hi : function.injective i) : tsum (f β i) β€ tsum f :=
begin
let g : Ξ± β nnreal := Ξ» a, β¨f a, hn aβ©,
have hg : summable g, by rwa β nnreal.summable_coe,
convert nnreal.coe_le_coe.2 (nnreal.tsum_comp_le_tsum_of_inj hg hi);
{ rw nnreal.coe_tsum, congr }
end
lemma summable_of_nonneg_of_le {f g : Ξ² β β}
(hg : βb, 0 β€ g b) (hgf : βb, g b β€ f b) (hf : summable f) : summable g :=
let f' (b : Ξ²) : nnreal := β¨f b, le_trans (hg b) (hgf b)β© in
let g' (b : Ξ²) : nnreal := β¨g b, hg bβ© in
have summable f', from nnreal.summable_coe.1 hf,
have summable g', from
nnreal.summable_of_le (assume b, (@nnreal.coe_le_coe (g' b) (f' b)).2 $ hgf b) this,
show summable (Ξ»b, g' b : Ξ² β β), from nnreal.summable_coe.2 this
lemma has_sum_iff_tendsto_nat_of_nonneg {f : β β β} (hf : βi, 0 β€ f i) (r : β) :
has_sum f r β tendsto (Ξ»n:β, (finset.range n).sum f) at_top (π r) :=
β¨has_sum.tendsto_sum_nat,
assume hfr,
have 0 β€ r := ge_of_tendsto at_top_ne_bot hfr $ univ_mem_sets' $ assume i,
show 0 β€ (finset.range i).sum f, from finset.sum_nonneg $ assume i _, hf i,
let f' (n : β) : nnreal := β¨f n, hf nβ©, r' : nnreal := β¨r, thisβ© in
have f_eq : f = (Ξ»i:β, (f' i : β)) := rfl,
have r_eq : r = r' := rfl,
begin
rw [f_eq, r_eq, nnreal.has_sum_coe, nnreal.has_sum_iff_tendsto_nat, β nnreal.tendsto_coe],
simp only [nnreal.coe_sum],
exact hfr
endβ©
lemma infi_real_pos_eq_infi_nnreal_pos {Ξ± : Type*} [complete_lattice Ξ±] {f : β β Ξ±} :
(β¨
(n:β) (h : n > 0), f n) = (β¨
(n:nnreal) (h : n > 0), f n) :=
le_antisymm
(le_infi $ assume n, le_infi $ assume hn, infi_le_of_le n $ infi_le _ (nnreal.coe_pos.2 hn))
(le_infi $ assume r, le_infi $ assume hr, infi_le_of_le β¨r, le_of_lt hrβ© $ infi_le _ hr)
section
variables [emetric_space Ξ²]
open ennreal filter emetric
/-- In an emetric ball, the distance between points is everywhere finite -/
lemma edist_ne_top_of_mem_ball {a : Ξ²} {r : ennreal} (x y : ball a r) : edist x.1 y.1 β β€ :=
lt_top_iff_ne_top.1 $
calc edist x y β€ edist a x + edist a y : edist_triangle_left x.1 y.1 a
... < r + r : by rw [edist_comm a x, edist_comm a y]; exact add_lt_add x.2 y.2
... β€ β€ : le_top
/-- Each ball in an extended metric space gives us a metric space, as the edist
is everywhere finite. -/
def metric_space_emetric_ball (a : Ξ²) (r : ennreal) : metric_space (ball a r) :=
emetric_space.to_metric_space edist_ne_top_of_mem_ball
local attribute [instance] metric_space_emetric_ball
lemma nhds_eq_nhds_emetric_ball (a x : Ξ²) (r : ennreal) (h : x β ball a r) :
π x = map (coe : ball a r β Ξ²) (π β¨x, hβ©) :=
(map_nhds_subtype_val_eq _ $ mem_nhds_sets emetric.is_open_ball h).symm
end
section
variable [emetric_space Ξ±]
open emetric
lemma tendsto_iff_edist_tendsto_0 {l : filter Ξ²} {f : Ξ² β Ξ±} {y : Ξ±} :
tendsto f l (π y) β tendsto (Ξ» x, edist (f x) y) l (π 0) :=
by simp only [emetric.nhds_basis_eball.tendsto_right_iff, emetric.mem_ball,
@tendsto_order ennreal Ξ² _ _, forall_prop_of_false ennreal.not_lt_zero, forall_const, true_and]
/-- Yet another metric characterization of Cauchy sequences on integers. This one is often the
most efficient. -/
lemma emetric.cauchy_seq_iff_le_tendsto_0 [nonempty Ξ²] [semilattice_sup Ξ²] {s : Ξ² β Ξ±} :
cauchy_seq s β (β (b: Ξ² β ennreal), (β n m N : Ξ², N β€ n β N β€ m β edist (s n) (s m) β€ b N)
β§ (tendsto b at_top (π 0))) :=
β¨begin
assume hs,
rw emetric.cauchy_seq_iff at hs,
/- `s` is Cauchy sequence. The sequence `b` will be constructed by taking
the supremum of the distances between `s n` and `s m` for `n m β₯ N`-/
let b := Ξ»N, Sup ((Ξ»(p : Ξ² Γ Ξ²), edist (s p.1) (s p.2))''{p | p.1 β₯ N β§ p.2 β₯ N}),
--Prove that it bounds the distances of points in the Cauchy sequence
have C : β n m N, N β€ n β N β€ m β edist (s n) (s m) β€ b N,
{ refine Ξ»m n N hm hn, le_Sup _,
use (prod.mk m n),
simp only [and_true, eq_self_iff_true, set.mem_set_of_eq],
exact β¨hm, hnβ© },
--Prove that it tends to `0`, by using the Cauchy property of `s`
have D : tendsto b at_top (π 0),
{ refine tendsto_order.2 β¨Ξ»a ha, absurd ha (ennreal.not_lt_zero), λΡ Ξ΅pos, _β©,
rcases dense Ξ΅pos with β¨Ξ΄, Ξ΄pos, Ξ΄ltβ©,
rcases hs Ξ΄ Ξ΄pos with β¨N, hNβ©,
refine filter.mem_at_top_sets.2 β¨N, Ξ»n hn, _β©,
have : b n β€ Ξ΄ := Sup_le begin
simp only [and_imp, set.mem_image, set.mem_set_of_eq, exists_imp_distrib, prod.exists],
intros d p q hp hq hd,
rw β hd,
exact le_of_lt (hN p q (le_trans hn hp) (le_trans hn hq))
end,
simpa using lt_of_le_of_lt this Ξ΄lt },
-- Conclude
exact β¨b, β¨C, Dβ©β©
end,
begin
rintros β¨b, β¨b_bound, b_limβ©β©,
/-b : β β β, b_bound : β (n m N : β), N β€ n β N β€ m β edist (s n) (s m) β€ b N,
b_lim : tendsto b at_top (π 0)-/
refine emetric.cauchy_seq_iff.2 (λΡ Ρpos, _),
have : βαΆ n in at_top, b n < Ξ΅ := (tendsto_order.1 b_lim ).2 _ Ξ΅pos,
rcases filter.mem_at_top_sets.1 this with β¨N, hNβ©,
exact β¨N, Ξ»m n hm hn, calc
edist (s m) (s n) β€ b N : b_bound m n N hm hn
... < Ξ΅ : (hN _ (le_refl N)) β©
endβ©
lemma continuous_of_le_add_edist {f : Ξ± β ennreal} (C : ennreal)
(hC : C β β€) (h : βx y, f x β€ f y + C * edist x y) : continuous f :=
begin
refine continuous_iff_continuous_at.2 (Ξ»x, tendsto_order.2 β¨_, _β©),
show βe, e < f x β βαΆ y in π x, e < f y,
{ assume e he,
let Ξ΅ := min (f x - e) 1,
have : Ξ΅ < β€ := lt_of_le_of_lt (min_le_right _ _) (by simp [lt_top_iff_ne_top]),
have : 0 < Ξ΅ := by simp [Ξ΅, hC, he, ennreal.zero_lt_one],
have : 0 < Cβ»ΒΉ * (Ξ΅/2) := bot_lt_iff_ne_bot.2 (by simp [hC, (ne_of_lt this).symm, ennreal.mul_eq_zero]),
have I : C * (Cβ»ΒΉ * (Ξ΅/2)) < Ξ΅,
{ by_cases C_zero : C = 0,
{ simp [C_zero, βΉ0 < Ξ΅βΊ] },
{ calc C * (Cβ»ΒΉ * (Ξ΅/2)) = (C * Cβ»ΒΉ) * (Ξ΅/2) : by simp [mul_assoc]
... = Ξ΅/2 : by simp [ennreal.mul_inv_cancel C_zero hC]
... < Ξ΅ : ennreal.half_lt_self (bot_lt_iff_ne_bot.1 βΉ0 < Ξ΅βΊ) (lt_top_iff_ne_top.1 βΉΞ΅ < β€βΊ) }},
have : ball x (Cβ»ΒΉ * (Ξ΅/2)) β {y : Ξ± | e < f y},
{ rintros y hy,
by_cases htop : f y = β€,
{ simp [htop, lt_top_iff_ne_top, ne_top_of_lt he] },
{ simp at hy,
have : e + Ξ΅ < f y + Ξ΅ := calc
e + Ξ΅ β€ e + (f x - e) : add_le_add_left' (min_le_left _ _)
... = f x : by simp [le_of_lt he]
... β€ f y + C * edist x y : h x y
... = f y + C * edist y x : by simp [edist_comm]
... β€ f y + C * (Cβ»ΒΉ * (Ξ΅/2)) :
add_le_add_left' $ canonically_ordered_semiring.mul_le_mul (le_refl _) (le_of_lt hy)
... < f y + Ξ΅ : (ennreal.add_lt_add_iff_left (lt_top_iff_ne_top.2 htop)).2 I,
show e < f y, from
(ennreal.add_lt_add_iff_right βΉΞ΅ < β€βΊ).1 this }},
apply filter.mem_sets_of_superset (ball_mem_nhds _ (βΉ0 < Cβ»ΒΉ * (Ξ΅/2)βΊ)) this },
show βe, f x < e β βαΆ y in π x, f y < e,
{ assume e he,
let Ξ΅ := min (e - f x) 1,
have : Ξ΅ < β€ := lt_of_le_of_lt (min_le_right _ _) (by simp [lt_top_iff_ne_top]),
have : 0 < Ξ΅ := by simp [Ξ΅, he, ennreal.zero_lt_one],
have : 0 < Cβ»ΒΉ * (Ξ΅/2) := bot_lt_iff_ne_bot.2 (by simp [hC, (ne_of_lt this).symm, ennreal.mul_eq_zero]),
have I : C * (Cβ»ΒΉ * (Ξ΅/2)) < Ξ΅,
{ by_cases C_zero : C = 0,
simp [C_zero, βΉ0 < Ξ΅βΊ],
calc C * (Cβ»ΒΉ * (Ξ΅/2)) = (C * Cβ»ΒΉ) * (Ξ΅/2) : by simp [mul_assoc]
... = Ξ΅/2 : by simp [ennreal.mul_inv_cancel C_zero hC]
... < Ξ΅ : ennreal.half_lt_self (bot_lt_iff_ne_bot.1 βΉ0 < Ξ΅βΊ) (lt_top_iff_ne_top.1 βΉΞ΅ < β€βΊ) },
have : ball x (Cβ»ΒΉ * (Ξ΅/2)) β {y : Ξ± | f y < e},
{ rintros y hy,
have htop : f x β β€ := ne_top_of_lt he,
show f y < e, from calc
f y β€ f x + C * edist y x : h y x
... β€ f x + C * (Cβ»ΒΉ * (Ξ΅/2)) :
add_le_add_left' $ canonically_ordered_semiring.mul_le_mul (le_refl _) (le_of_lt hy)
... < f x + Ξ΅ : (ennreal.add_lt_add_iff_left (lt_top_iff_ne_top.2 htop)).2 I
... β€ f x + (e - f x) : add_le_add_left' (min_le_left _ _)
... = e : by simp [le_of_lt he] },
apply filter.mem_sets_of_superset (ball_mem_nhds _ (βΉ0 < Cβ»ΒΉ * (Ξ΅/2)βΊ)) this },
end
theorem continuous_edist : continuous (Ξ»p:Ξ±ΓΞ±, edist p.1 p.2) :=
begin
apply continuous_of_le_add_edist 2 (by simp),
rintros β¨x, yβ© β¨x', y'β©,
calc edist x y β€ edist x x' + edist x' y' + edist y' y : edist_triangle4 _ _ _ _
... = edist x' y' + (edist x x' + edist y y') : by simp [edist_comm]; cc
... β€ edist x' y' + (edist (x, y) (x', y') + edist (x, y) (x', y')) :
add_le_add_left' (add_le_add' (by simp [edist, le_refl]) (by simp [edist, le_refl]))
... = edist x' y' + 2 * edist (x, y) (x', y') : by rw [β mul_two, mul_comm]
end
theorem continuous.edist [topological_space Ξ²] {f g : Ξ² β Ξ±}
(hf : continuous f) (hg : continuous g) : continuous (Ξ»b, edist (f b) (g b)) :=
continuous_edist.comp (hf.prod_mk hg)
theorem filter.tendsto.edist {f g : Ξ² β Ξ±} {x : filter Ξ²} {a b : Ξ±}
(hf : tendsto f x (π a)) (hg : tendsto g x (π b)) :
tendsto (Ξ»x, edist (f x) (g x)) x (π (edist a b)) :=
(continuous_edist.tendsto (a, b)).comp (hf.prod_mk_nhds hg)
lemma cauchy_seq_of_edist_le_of_tsum_ne_top {f : β β Ξ±} (d : β β ennreal)
(hf : β n, edist (f n) (f n.succ) β€ d n) (hd : tsum d β β) :
cauchy_seq f :=
begin
lift d to (β β nnreal) using (Ξ» i, ennreal.ne_top_of_tsum_ne_top hd i),
rw ennreal.tsum_coe_ne_top_iff_summable at hd,
exact cauchy_seq_of_edist_le_of_summable d hf hd
end
/-- If `edist (f n) (f (n+1))` is bounded above by a function `d : β β ennreal`,
then the distance from `f n` to the limit is bounded by `β_{k=n}^β d k`. -/
lemma edist_le_tsum_of_edist_le_of_tendsto {f : β β Ξ±} (d : β β ennreal)
(hf : β n, edist (f n) (f n.succ) β€ d n)
{a : Ξ±} (ha : tendsto f at_top (π a)) (n : β) :
edist (f n) a β€ β m, d (n + m) :=
begin
refine le_of_tendsto at_top_ne_bot (tendsto_const_nhds.edist ha)
(mem_at_top_sets.2 β¨n, Ξ» m hnm, _β©),
refine le_trans (edist_le_Ico_sum_of_edist_le hnm (Ξ» k _ _, hf k)) _,
rw [finset.sum_Ico_eq_sum_range],
exact sum_le_tsum _ (Ξ» _ _, zero_le _) ennreal.summable
end
/-- If `edist (f n) (f (n+1))` is bounded above by a function `d : β β ennreal`,
then the distance from `f 0` to the limit is bounded by `β_{k=0}^β d k`. -/
lemma edist_le_tsum_of_edist_le_of_tendstoβ {f : β β Ξ±} (d : β β ennreal)
(hf : β n, edist (f n) (f n.succ) β€ d n)
{a : Ξ±} (ha : tendsto f at_top (π a)) :
edist (f 0) a β€ β m, d m :=
by simpa using edist_le_tsum_of_edist_le_of_tendsto d hf ha 0
end --section
|
04db3dd1f7f99d5028050932b99c9d51e235f1c0 | b794ca1df49bc5a3bd3fd5552eed3bc4f63b8b93 | /src/instructor/lectures/lecture_4.lean | b1eab97d404909db8b79960828c488728021af65 | [] | no_license | akraisinger/cs2120f21 | 8235ac98375e04ffcec504cff5cab7833ee69e54 | 4ef83d7151bb6a284028092aa4f1d509c0eb8237 | refs/heads/main | 1,691,714,771,612 | 1,632,889,465,000 | 1,632,889,465,000 | 399,946,508 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,707 | lean | /-
We've seen that logics start with i that
can then be combined (with other information)
using *inference rules* to derive theorems. In
this file we review what we've covered so far
and then we introduce:
(1) The concept of introduction and elimination
rules for a given logical construct.
(2) We distinguish the reflexivity axiom as an
*introduction* rule (one that produces a proof
of an equality), and the substitutability of
equals as an *elimination* rule (one that uses,
or consumes) a proof of an equality to produce
some other kind of result.
(3) We explicitly identity the introduction
rules for β and for β. To produce a proof of
β (x : T), P x (where T is a type and P is a
predicate that asserts some property of x), we
*assume* that we're given an arbitrary but
specific (x : T) ["x of type T"], and then
we prove (P x) *for that x*. Because we made
no assumptions whatsoever about x, if we can
show that (P x) is true, then it must be true
*for all* (x : T).
-/
/-
Introduction rule for equality.
-/
axiom eq_refl :
β (T : Type) -- if T is any type (of thing)
(t : T), -- and t is thing of that type, T
t = t -- the result type: proof of t = t
/-
Elimination rule for equality.
-/
axiom eq_subst :
β (T : Type) -- if T is a type
(P : T β Prop) -- and P is a property of T objects
(x y : T) -- and x and y are T objects
(e : x = y) -- and you have a proof that x = y
(px : P x), -- and you have a proof that x has property P
P y -- then you can deduce (and get a proof) of P y
/-
The Lean versions of these axioms are called eq.refl and eq.subst.
They're defined in ways that allow (and require) one not to give the
T, P, x, or y parameters explicitly when applying eq_subst. More
details come later.
-/
/-
CONJECTURES (review)
-/
-- A conjecture: equality is symmetric.
def eq_symm : Prop :=
β (T : Type)
(x y : T),
x = y β
y = x
-- A conjecture: equality is transitive.
def eq_trans : Prop :=
β (T : Type)
(x y z : T),
x = y β
y = z β
x = z
/-
PROOFS: From conjectures to theorems
-/
example : eq_symm :=
begin
unfold eq_symm, -- replace name with definition
assume T x y e, -- Introduction rule for β
rw e, -- Elimination rule for =
-- QED.
end
/-
A different proof, now using eq.subst explicitly.
Any proof of a proposition is as good as any other
for showing the truth of a proposition. We do not
care what proofs you give, as long as they're correct
(unless stated otherwise).
-/
example : eq_symm :=
begin
unfold eq_symm, -- replace name with definition
assume T x y e, -- introduction rule for β
apply eq.subst e, -- elimination rule for =
exact eq.refl x, -- introduction rule for =
-- QED.
end
/-
Review: Proof: equality is transitive.
-/
example : eq_trans :=
begin
unfold eq_trans,
assume T x y z e1 e2, -- introduction rule for β
rw e1, -- elimination rule for =
exact e2,
end
/-
Note: Lean defines these rules as
- eq.refl
- eq.subst
- eq.symm
- eq.trans
-/
/-
Practice
-/
example : β (T : Type) (x y z : T), x = y β y = z β z = x :=
begin
assume T x y z h1 h2, -- introduction rule for β
apply eq.symm _, -- application of symm *theorem*
apply eq.trans h1 h2, -- application of trans theorem
end
/-
INTRODUCTION and ELIMINATION RULES
-/
/-
For =
- introduction rule: eq.refl
- elimination rule: eq.subst
-/
/-
For β x, P x
- introduction rule: assume arbitrary x, then show P x
- elimination rule: next time!
-/
/-
For P β Q
- introduction rule: assume arbitrary P, then show Q
- elimination rule: next time.
-/
|
a3228664e8c8ee48d0fd738260aeca0ee7c134b1 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/analysis/normed_space/operator_norm.lean | a83d745bcad7fc377fdf1ddabe3f49ae021748bb | [
"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 | 57,539 | lean | /-
Copyright (c) 2019 Jan-David Salchow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jan-David Salchow, SΓ©bastien GouΓ«zel, Jean Lo
-/
import linear_algebra.finite_dimensional
import analysis.normed_space.linear_isometry
import analysis.normed_space.riesz_lemma
import analysis.normed_space.normed_group_hom
import analysis.asymptotics.asymptotics
import algebra.algebra.tower
import data.equiv.transfer_instance
/-!
# Operator norm on the space of continuous linear maps
Define the operator norm on the space of continuous linear maps between normed spaces, and prove
its basic properties. In particular, show that this space is itself a normed space.
Since a lot of elementary properties don't require `β₯xβ₯ = 0 β x = 0` we start setting up the
theory for `semi_normed_space` and we specialize to `normed_space` at the end.
-/
noncomputable theory
open_locale classical nnreal topological_space
variables {π : Type*} {E : Type*} {F : Type*} {G : Type*}
section semi_normed
variables [semi_normed_group E] [semi_normed_group F] [semi_normed_group G]
open metric continuous_linear_map
section normed_field
/-! Most statements in this file require the field to be non-discrete,
as this is necessary to deduce an inequality `β₯f xβ₯ β€ C β₯xβ₯` from the continuity of f.
However, the other direction always holds.
In this section, we just assume that `π` is a normed field.
In the remainder of the file, it will be non-discrete. -/
variables [normed_field π] [semi_normed_space π E] [semi_normed_space π F] (f : E ββ[π] F)
lemma linear_map.lipschitz_of_bound (C : β) (h : βx, β₯f xβ₯ β€ C * β₯xβ₯) :
lipschitz_with (real.to_nnreal C) f :=
lipschitz_with.of_dist_le' $ Ξ» x y, by simpa only [dist_eq_norm, f.map_sub] using h (x - y)
theorem linear_map.antilipschitz_of_bound {K : ββ₯0} (h : β x, β₯xβ₯ β€ K * β₯f xβ₯) :
antilipschitz_with K f :=
antilipschitz_with.of_le_mul_dist $
Ξ» x y, by simpa only [dist_eq_norm, f.map_sub] using h (x - y)
lemma linear_map.bound_of_antilipschitz {K : ββ₯0} (h : antilipschitz_with K f) (x) :
β₯xβ₯ β€ K * β₯f xβ₯ :=
by simpa only [dist_zero_right, f.map_zero] using h.le_mul_dist x 0
lemma linear_map.uniform_continuous_of_bound (C : β) (h : βx, β₯f xβ₯ β€ C * β₯xβ₯) :
uniform_continuous f :=
(f.lipschitz_of_bound C h).uniform_continuous
lemma linear_map.continuous_of_bound (C : β) (h : βx, β₯f xβ₯ β€ C * β₯xβ₯) :
continuous f :=
(f.lipschitz_of_bound C h).continuous
/-- Construct a continuous linear map from a linear map and a bound on this linear map.
The fact that the norm of the continuous linear map is then controlled is given in
`linear_map.mk_continuous_norm_le`. -/
def linear_map.mk_continuous (C : β) (h : βx, β₯f xβ₯ β€ C * β₯xβ₯) : E βL[π] F :=
β¨f, linear_map.continuous_of_bound f C hβ©
/-- Reinterpret a linear map `π ββ[π] E` as a continuous linear map. This construction
is generalized to the case of any finite dimensional domain
in `linear_map.to_continuous_linear_map`. -/
def linear_map.to_continuous_linear_mapβ (f : π ββ[π] E) : π βL[π] E :=
f.mk_continuous (β₯f 1β₯) $ Ξ» x, le_of_eq $
by { conv_lhs { rw β mul_one x }, rw [β smul_eq_mul, f.map_smul, norm_smul, mul_comm] }
/-- Construct a continuous linear map from a linear map and the existence of a bound on this linear
map. If you have an explicit bound, use `linear_map.mk_continuous` instead, as a norm estimate will
follow automatically in `linear_map.mk_continuous_norm_le`. -/
def linear_map.mk_continuous_of_exists_bound (h : βC, βx, β₯f xβ₯ β€ C * β₯xβ₯) : E βL[π] F :=
β¨f, let β¨C, hCβ© := h in linear_map.continuous_of_bound f C hCβ©
lemma continuous_of_linear_of_bound {f : E β F} (h_add : β x y, f (x + y) = f x + f y)
(h_smul : β (c : π) x, f (c β’ x) = c β’ f x) {C : β} (h_bound : β x, β₯f xβ₯ β€ C*β₯xβ₯) :
continuous f :=
let Ο : E ββ[π] F := { to_fun := f, map_add' := h_add, map_smul' := h_smul } in
Ο.continuous_of_bound C h_bound
@[simp, norm_cast] lemma linear_map.mk_continuous_coe (C : β) (h : βx, β₯f xβ₯ β€ C * β₯xβ₯) :
((f.mk_continuous C h) : E ββ[π] F) = f := rfl
@[simp] lemma linear_map.mk_continuous_apply (C : β) (h : βx, β₯f xβ₯ β€ C * β₯xβ₯) (x : E) :
f.mk_continuous C h x = f x := rfl
@[simp, norm_cast] lemma linear_map.mk_continuous_of_exists_bound_coe
(h : βC, βx, β₯f xβ₯ β€ C * β₯xβ₯) :
((f.mk_continuous_of_exists_bound h) : E ββ[π] F) = f := rfl
@[simp] lemma linear_map.mk_continuous_of_exists_bound_apply (h : βC, βx, β₯f xβ₯ β€ C * β₯xβ₯) (x : E) :
f.mk_continuous_of_exists_bound h x = f x := rfl
@[simp] lemma linear_map.to_continuous_linear_mapβ_coe (f : π ββ[π] E) :
(f.to_continuous_linear_mapβ : π ββ[π] E) = f :=
rfl
@[simp] lemma linear_map.to_continuous_linear_mapβ_apply (f : π ββ[π] E) (x) :
f.to_continuous_linear_mapβ x = f x :=
rfl
end normed_field
variables [nondiscrete_normed_field π] [semi_normed_space π E] [semi_normed_space π F]
[semi_normed_space π G] (c : π) (f g : E βL[π] F) (h : F βL[π] G) (x y z : E)
include π
lemma linear_map.bound_of_shell_semi_normed (f : E ββ[π] F) {Ξ΅ C : β} (Ξ΅_pos : 0 < Ξ΅) {c : π}
(hc : 1 < β₯cβ₯) (hf : β x, Ξ΅ / β₯cβ₯ β€ β₯xβ₯ β β₯xβ₯ < Ξ΅ β β₯f xβ₯ β€ C * β₯xβ₯) {x : E} (hx : β₯xβ₯ β 0) :
β₯f xβ₯ β€ C * β₯xβ₯ :=
begin
rcases rescale_to_shell_semi_normed hc Ξ΅_pos hx with β¨Ξ΄, hΞ΄, Ξ΄xle, leΞ΄x, Ξ΄invβ©,
simpa only [f.map_smul, norm_smul, mul_left_comm C, mul_le_mul_left (norm_pos_iff.2 hΞ΄)]
using hf (Ξ΄ β’ x) leΞ΄x Ξ΄xle
end
/-- If `β₯xβ₯ = 0` and `f` is continuous then `β₯f xβ₯ = 0`. -/
lemma norm_image_of_norm_zero {f : E ββ[π] F} (hf : continuous f) {x : E} (hx : β₯xβ₯ = 0) :
β₯f xβ₯ = 0 :=
begin
refine le_antisymm (le_of_forall_pos_le_add (Ξ» Ξ΅ hΞ΅, _)) (norm_nonneg (f x)),
rcases normed_group.tendsto_nhds_nhds.1 (hf.tendsto 0) Ξ΅ hΞ΅ with β¨Ξ΄, Ξ΄_pos, hΞ΄β©,
replace hΞ΄ := hΞ΄ x,
rw [sub_zero, hx] at hΞ΄,
replace hΞ΄ := le_of_lt (hΞ΄ Ξ΄_pos),
rw [linear_map.map_zero, sub_zero] at hΞ΄,
rwa [zero_add]
end
/-- A continuous linear map between seminormed spaces is bounded when the field is nondiscrete. The
continuity ensures boundedness on a ball of some radius `Ξ΅`. The nondiscreteness is then used to
rescale any element into an element of norm in `[Ξ΅/C, Ξ΅]`, whose image has a controlled norm. The
norm control for the original element follows by rescaling. -/
lemma linear_map.bound_of_continuous (f : E ββ[π] F) (hf : continuous f) :
β C, 0 < C β§ (β x : E, β₯f xβ₯ β€ C * β₯xβ₯) :=
begin
rcases normed_group.tendsto_nhds_nhds.1 (hf.tendsto 0) 1 zero_lt_one with β¨Ξ΅, Ξ΅_pos, hΞ΅β©,
simp only [sub_zero, f.map_zero] at hΞ΅,
rcases normed_field.exists_one_lt_norm π with β¨c, hcβ©,
have : 0 < β₯cβ₯ / Ξ΅, from div_pos (zero_lt_one.trans hc) Ξ΅_pos,
refine β¨β₯cβ₯ / Ξ΅, this, Ξ» x, _β©,
by_cases hx : β₯xβ₯ = 0,
{ rw [hx, mul_zero],
exact le_of_eq (norm_image_of_norm_zero hf hx) },
refine f.bound_of_shell_semi_normed Ξ΅_pos hc (Ξ» x hle hlt, _) hx,
refine (hΞ΅ _ hlt).le.trans _,
rwa [β div_le_iff' this, one_div_div]
end
namespace continuous_linear_map
theorem bound : β C, 0 < C β§ (β x : E, β₯f xβ₯ β€ C * β₯xβ₯) :=
f.to_linear_map.bound_of_continuous f.2
section
open asymptotics filter
theorem is_O_id (l : filter E) : is_O f (Ξ» x, x) l :=
let β¨M, hMp, hMβ© := f.bound in is_O_of_le' l hM
theorem is_O_comp {Ξ± : Type*} (g : F βL[π] G) (f : Ξ± β F) (l : filter Ξ±) :
is_O (Ξ» x', g (f x')) f l :=
(g.is_O_id β€).comp_tendsto le_top
theorem is_O_sub (f : E βL[π] F) (l : filter E) (x : E) :
is_O (Ξ» x', f (x' - x)) (Ξ» x', x' - x) l :=
f.is_O_comp _ l
/-- A linear map which is a homothety is a continuous linear map.
Since the field `π` need not have `β` as a subfield, this theorem is not directly deducible from
the corresponding theorem about isometries plus a theorem about scalar multiplication. Likewise
for the other theorems about homotheties in this file.
-/
def of_homothety (f : E ββ[π] F) (a : β) (hf : βx, β₯f xβ₯ = a * β₯xβ₯) : E βL[π] F :=
f.mk_continuous a (Ξ» x, le_of_eq (hf x))
variable (π)
lemma to_span_singleton_homothety (x : E) (c : π) :
β₯linear_map.to_span_singleton π E x cβ₯ = β₯xβ₯ * β₯cβ₯ :=
by {rw mul_comm, exact norm_smul _ _}
/-- Given an element `x` of a normed space `E` over a field `π`, the natural continuous
linear map from `E` to the span of `x`.-/
def to_span_singleton (x : E) : π βL[π] E :=
of_homothety (linear_map.to_span_singleton π E x) β₯xβ₯ (to_span_singleton_homothety π x)
end
section op_norm
open set real
/-- The operator norm of a continuous linear map is the inf of all its bounds. -/
def op_norm := Inf {c | 0 β€ c β§ β x, β₯f xβ₯ β€ c * β₯xβ₯}
instance has_op_norm : has_norm (E βL[π] F) := β¨op_normβ©
lemma norm_def : β₯fβ₯ = Inf {c | 0 β€ c β§ β x, β₯f xβ₯ β€ c * β₯xβ₯} := rfl
-- So that invocations of `real.Inf_le` make sense: we show that the set of
-- bounds is nonempty and bounded below.
lemma bounds_nonempty {f : E βL[π] F} :
β c, c β { c | 0 β€ c β§ β x, β₯f xβ₯ β€ c * β₯xβ₯ } :=
let β¨M, hMp, hMbβ© := f.bound in β¨M, le_of_lt hMp, hMbβ©
lemma bounds_bdd_below {f : E βL[π] F} :
bdd_below { c | 0 β€ c β§ β x, β₯f xβ₯ β€ c * β₯xβ₯ } :=
β¨0, Ξ» _ β¨hn, _β©, hnβ©
lemma op_norm_nonneg : 0 β€ β₯fβ₯ :=
lb_le_Inf _ bounds_nonempty (Ξ» _ β¨hx, _β©, hx)
/-- The fundamental property of the operator norm: `β₯f xβ₯ β€ β₯fβ₯ * β₯xβ₯`. -/
theorem le_op_norm : β₯f xβ₯ β€ β₯fβ₯ * β₯xβ₯ :=
begin
obtain β¨C, Cpos, hCβ© := f.bound,
replace hC := hC x,
by_cases h : β₯xβ₯ = 0,
{ rwa [h, mul_zero] at β’ hC },
have hlt : 0 < β₯xβ₯ := lt_of_le_of_ne (norm_nonneg x) (ne.symm h),
exact (div_le_iff hlt).mp ((real.le_Inf _ bounds_nonempty bounds_bdd_below).2 (Ξ» c β¨_, hcβ©,
(div_le_iff hlt).mpr $ by { apply hc })),
end
theorem le_op_norm_of_le {c : β} {x} (h : β₯xβ₯ β€ c) : β₯f xβ₯ β€ β₯fβ₯ * c :=
le_trans (f.le_op_norm x) (mul_le_mul_of_nonneg_left h f.op_norm_nonneg)
theorem le_of_op_norm_le {c : β} (h : β₯fβ₯ β€ c) (x : E) : β₯f xβ₯ β€ c * β₯xβ₯ :=
(f.le_op_norm x).trans (mul_le_mul_of_nonneg_right h (norm_nonneg x))
/-- continuous linear maps are Lipschitz continuous. -/
theorem lipschitz : lipschitz_with β¨β₯fβ₯, op_norm_nonneg fβ© f :=
lipschitz_with.of_dist_le_mul $ Ξ» x y,
by { rw [dist_eq_norm, dist_eq_norm, βmap_sub], apply le_op_norm }
lemma ratio_le_op_norm : β₯f xβ₯ / β₯xβ₯ β€ β₯fβ₯ :=
div_le_of_nonneg_of_le_mul (norm_nonneg _) f.op_norm_nonneg (le_op_norm _ _)
/-- The image of the unit ball under a continuous linear map is bounded. -/
lemma unit_le_op_norm : β₯xβ₯ β€ 1 β β₯f xβ₯ β€ β₯fβ₯ :=
mul_one β₯fβ₯ βΈ f.le_op_norm_of_le
/-- If one controls the norm of every `A x`, then one controls the norm of `A`. -/
lemma op_norm_le_bound {M : β} (hMp: 0 β€ M) (hM : β x, β₯f xβ₯ β€ M * β₯xβ₯) :
β₯fβ₯ β€ M :=
Inf_le _ bounds_bdd_below β¨hMp, hMβ©
theorem op_norm_le_of_lipschitz {f : E βL[π] F} {K : ββ₯0} (hf : lipschitz_with K f) :
β₯fβ₯ β€ K :=
f.op_norm_le_bound K.2 $ Ξ» x, by simpa only [dist_zero_right, f.map_zero] using hf.dist_le_mul x 0
lemma op_norm_le_of_shell {f : E βL[π] F} {Ξ΅ C : β} (Ξ΅_pos : 0 < Ξ΅) (hC : 0 β€ C)
{c : π} (hc : 1 < β₯cβ₯) (hf : β x, Ξ΅ / β₯cβ₯ β€ β₯xβ₯ β β₯xβ₯ < Ξ΅ β β₯f xβ₯ β€ C * β₯xβ₯) :
β₯fβ₯ β€ C :=
begin
refine f.op_norm_le_bound hC (Ξ» x, _),
by_cases hx : β₯xβ₯ = 0,
{ rw [hx, mul_zero],
exact le_of_eq (norm_image_of_norm_zero f.2 hx) },
exact linear_map.bound_of_shell_semi_normed f Ξ΅_pos hc hf hx
end
lemma op_norm_le_of_ball {f : E βL[π] F} {Ξ΅ : β} {C : β} (Ξ΅_pos : 0 < Ξ΅) (hC : 0 β€ C)
(hf : β x β ball (0 : E) Ξ΅, β₯f xβ₯ β€ C * β₯xβ₯) : β₯fβ₯ β€ C :=
begin
rcases normed_field.exists_one_lt_norm π with β¨c, hcβ©,
refine op_norm_le_of_shell Ξ΅_pos hC hc (Ξ» x _ hx, hf x _),
rwa ball_0_eq
end
lemma op_norm_le_of_nhds_zero {f : E βL[π] F} {C : β} (hC : 0 β€ C)
(hf : βαΆ x in π (0 : E), β₯f xβ₯ β€ C * β₯xβ₯) : β₯fβ₯ β€ C :=
let β¨Ξ΅, Ξ΅0, hΞ΅β© := metric.eventually_nhds_iff_ball.1 hf in op_norm_le_of_ball Ξ΅0 hC hΞ΅
lemma op_norm_le_of_shell' {f : E βL[π] F} {Ξ΅ C : β} (Ξ΅_pos : 0 < Ξ΅) (hC : 0 β€ C)
{c : π} (hc : β₯cβ₯ < 1) (hf : β x, Ξ΅ * β₯cβ₯ β€ β₯xβ₯ β β₯xβ₯ < Ξ΅ β β₯f xβ₯ β€ C * β₯xβ₯) :
β₯fβ₯ β€ C :=
begin
by_cases h0 : c = 0,
{ refine op_norm_le_of_ball Ξ΅_pos hC (Ξ» x hx, hf x _ _),
{ simp [h0] },
{ rwa ball_0_eq at hx } },
{ rw [β inv_inv' c, normed_field.norm_inv,
inv_lt_one_iff_of_pos (norm_pos_iff.2 $ inv_ne_zero h0)] at hc,
refine op_norm_le_of_shell Ξ΅_pos hC hc _,
rwa [normed_field.norm_inv, div_eq_mul_inv, inv_inv'] }
end
lemma op_norm_eq_of_bounds {Ο : E βL[π] F} {M : β} (M_nonneg : 0 β€ M)
(h_above : β x, β₯Ο xβ₯ β€ M*β₯xβ₯) (h_below : β N β₯ 0, (β x, β₯Ο xβ₯ β€ N*β₯xβ₯) β M β€ N) :
β₯Οβ₯ = M :=
le_antisymm (Ο.op_norm_le_bound M_nonneg h_above)
((le_cInf_iff continuous_linear_map.bounds_bdd_below β¨M, M_nonneg, h_aboveβ©).mpr $
Ξ» N β¨N_nonneg, hNβ©, h_below N N_nonneg hN)
/-- The operator norm satisfies the triangle inequality. -/
theorem op_norm_add_le : β₯f + gβ₯ β€ β₯fβ₯ + β₯gβ₯ :=
show β₯f + gβ₯ β€ (coe : ββ₯0 β β) (β¨_, f.op_norm_nonnegβ© + β¨_, g.op_norm_nonnegβ©),
from op_norm_le_of_lipschitz (f.lipschitz.add g.lipschitz)
/-- The norm of the `0` operator is `0`. -/
theorem op_norm_zero : β₯(0 : E βL[π] F)β₯ = 0 :=
le_antisymm (real.Inf_le _ bounds_bdd_below
β¨ge_of_eq rfl, Ξ» _, le_of_eq (by { rw [zero_mul], exact norm_zero })β©)
(op_norm_nonneg _)
/-- The norm of the identity is at most `1`. It is in fact `1`, except when the space is trivial
where it is `0`. It means that one can not do better than an inequality in general. -/
lemma norm_id_le : β₯id π Eβ₯ β€ 1 :=
op_norm_le_bound _ zero_le_one (Ξ»x, by simp)
/-- If there is an element with norm different from `0`, then the norm of the identity equals `1`.
(Since we are working with seminorms supposing that the space is non-trivial is not enough.) -/
lemma norm_id_of_nontrivial_seminorm (h : β (x : E), β₯xβ₯ β 0 ) : β₯id π Eβ₯ = 1 :=
le_antisymm norm_id_le $ let β¨x, hxβ© := h in
have _ := (id π E).ratio_le_op_norm x,
by rwa [id_apply, div_self hx] at this
lemma op_norm_smul_le {π' : Type*} [normed_field π'] [semi_normed_space π' F]
[smul_comm_class π π' F] (c : π') (f : E βL[π] F) : β₯c β’ fβ₯ β€ β₯cβ₯ * β₯fβ₯ :=
((c β’ f).op_norm_le_bound
(mul_nonneg (norm_nonneg _) (op_norm_nonneg _)) (Ξ» _,
begin
erw [norm_smul, mul_assoc],
exact mul_le_mul_of_nonneg_left (le_op_norm _ _) (norm_nonneg _)
end))
lemma op_norm_neg : β₯-fβ₯ = β₯fβ₯ := by simp only [norm_def, neg_apply, norm_neg]
/-- Continuous linear maps themselves form a seminormed space with respect to
the operator norm. -/
instance to_semi_normed_group : semi_normed_group (E βL[π] F) :=
semi_normed_group.of_core _ β¨op_norm_zero, op_norm_add_le, op_norm_negβ©
instance to_semi_normed_space {π' : Type*} [normed_field π'] [semi_normed_space π' F]
[smul_comm_class π π' F] : semi_normed_space π' (E βL[π] F) :=
β¨op_norm_smul_leβ©
/-- The operator norm is submultiplicative. -/
lemma op_norm_comp_le (f : E βL[π] F) : β₯h.comp fβ₯ β€ β₯hβ₯ * β₯fβ₯ :=
(Inf_le _ bounds_bdd_below
β¨mul_nonneg (op_norm_nonneg _) (op_norm_nonneg _), Ξ» x,
by { rw mul_assoc, exact h.le_op_norm_of_le (f.le_op_norm x) } β©)
/-- Continuous linear maps form a seminormed ring with respect to the operator norm. -/
instance to_semi_normed_ring : semi_normed_ring (E βL[π] E) :=
{ norm_mul := op_norm_comp_le,
.. continuous_linear_map.to_semi_normed_group }
theorem le_op_normβ (f : E βL[π] F βL[π] G) (x : E) (y : F) :
β₯f x yβ₯ β€ β₯fβ₯ * β₯xβ₯ * β₯yβ₯ :=
(f x).le_of_op_norm_le (f.le_op_norm x) y
theorem op_norm_le_boundβ (f : E βL[π] F βL[π] G) {C : β} (h0 : 0 β€ C)
(hC : β x y, β₯f x yβ₯ β€ C * β₯xβ₯ * β₯yβ₯) :
β₯fβ₯ β€ C :=
f.op_norm_le_bound h0 $ Ξ» x,
(f x).op_norm_le_bound (mul_nonneg h0 (norm_nonneg _)) $ hC x
@[simp] lemma op_norm_prod (f : E βL[π] F) (g : E βL[π] G) : β₯f.prod gβ₯ = β₯(f, g)β₯ :=
le_antisymm
(op_norm_le_bound _ (norm_nonneg _) $ Ξ» x,
by simpa only [prod_apply, prod.semi_norm_def, max_mul_of_nonneg, norm_nonneg]
using max_le_max (le_op_norm f x) (le_op_norm g x)) $
max_le
(op_norm_le_bound _ (norm_nonneg _) $ Ξ» x, (le_max_left _ _).trans ((f.prod g).le_op_norm x))
(op_norm_le_bound _ (norm_nonneg _) $ Ξ» x, (le_max_right _ _).trans ((f.prod g).le_op_norm x))
/-- `continuous_linear_map.prod` as a `linear_isometry_equiv`. -/
def prodβα΅’ (R : Type*) [ring R] [topological_space R] [module R F] [module R G]
[has_continuous_smul R F] [has_continuous_smul R G]
[smul_comm_class π R F] [smul_comm_class π R G] :
(E βL[π] F) Γ (E βL[π] G) ββα΅’[R] (E βL[π] F Γ G) :=
β¨prodβ R, Ξ» β¨f, gβ©, op_norm_prod f gβ©
/-- A continuous linear map is automatically uniformly continuous. -/
protected theorem uniform_continuous : uniform_continuous f :=
f.lipschitz.uniform_continuous
@[simp, nontriviality] lemma op_norm_subsingleton [subsingleton E] : β₯fβ₯ = 0 :=
begin
refine le_antisymm _ (norm_nonneg _),
apply op_norm_le_bound _ rfl.ge,
intros x,
simp [subsingleton.elim x 0]
end
/-- A continuous linear map is an isometry if and only if it preserves the norm. -/
lemma isometry_iff_norm : isometry f β βx, β₯f xβ₯ = β₯xβ₯ :=
f.to_linear_map.to_add_monoid_hom.isometry_iff_norm
end op_norm
end continuous_linear_map
namespace linear_isometry
lemma norm_to_continuous_linear_map_le (f : E ββα΅’[π] F) :
β₯f.to_continuous_linear_mapβ₯ β€ 1 :=
f.to_continuous_linear_map.op_norm_le_bound zero_le_one $ Ξ» x, by simp
end linear_isometry
namespace linear_map
/-- If a continuous linear map is constructed from a linear map via the constructor `mk_continuous`,
then its norm is bounded by the bound given to the constructor if it is nonnegative. -/
lemma mk_continuous_norm_le (f : E ββ[π] F) {C : β} (hC : 0 β€ C) (h : βx, β₯f xβ₯ β€ C * β₯xβ₯) :
β₯f.mk_continuous C hβ₯ β€ C :=
continuous_linear_map.op_norm_le_bound _ hC h
/-- If a continuous linear map is constructed from a linear map via the constructor `mk_continuous`,
then its norm is bounded by the bound or zero if bound is negative. -/
lemma mk_continuous_norm_le' (f : E ββ[π] F) {C : β} (h : βx, β₯f xβ₯ β€ C * β₯xβ₯) :
β₯f.mk_continuous C hβ₯ β€ max C 0 :=
continuous_linear_map.op_norm_le_bound _ (le_max_right _ _) $ Ξ» x, (h x).trans $
mul_le_mul_of_nonneg_right (le_max_left _ _) (norm_nonneg x)
/-- Create a bilinear map (represented as a map `E βL[π] F βL[π] G`) from the corresponding linear
map and a bound on the norm of the image. The linear map can be constructed using
`linear_map.mkβ`. -/
def mk_continuousβ (f : E ββ[π] F ββ[π] G) (C : β)
(hC : β x y, β₯f x yβ₯ β€ C * β₯xβ₯ * β₯yβ₯) :
E βL[π] F βL[π] G :=
linear_map.mk_continuous
{ to_fun := Ξ» x, (f x).mk_continuous (C * β₯xβ₯) (hC x),
map_add' := Ξ» x y, by { ext z, simp },
map_smul' := Ξ» c x, by { ext z, simp } }
(max C 0) $ Ξ» x, (mk_continuous_norm_le' _ _).trans_eq $
by rw [max_mul_of_nonneg _ _ (norm_nonneg x), zero_mul]
@[simp] lemma mk_continuousβ_apply (f : E ββ[π] F ββ[π] G) {C : β}
(hC : β x y, β₯f x yβ₯ β€ C * β₯xβ₯ * β₯yβ₯) (x : E) (y : F) :
f.mk_continuousβ C hC x y = f x y :=
rfl
lemma mk_continuousβ_norm_le' (f : E ββ[π] F ββ[π] G) {C : β}
(hC : β x y, β₯f x yβ₯ β€ C * β₯xβ₯ * β₯yβ₯) :
β₯f.mk_continuousβ C hCβ₯ β€ max C 0 :=
mk_continuous_norm_le _ (le_max_iff.2 $ or.inr le_rfl) _
lemma mk_continuousβ_norm_le (f : E ββ[π] F ββ[π] G) {C : β} (h0 : 0 β€ C)
(hC : β x y, β₯f x yβ₯ β€ C * β₯xβ₯ * β₯yβ₯) :
β₯f.mk_continuousβ C hCβ₯ β€ C :=
(f.mk_continuousβ_norm_le' hC).trans_eq $ max_eq_left h0
end linear_map
namespace continuous_linear_map
/-- Flip the order of arguments of a continuous bilinear map.
For a version bundled as `linear_isometry_equiv`, see
`continuous_linear_map.flipL`. -/
def flip (f : E βL[π] F βL[π] G) : F βL[π] E βL[π] G :=
linear_map.mk_continuousβ
(linear_map.mkβ π (Ξ» y x, f x y) (Ξ» x y z, (f z).map_add x y) (Ξ» c y x, (f x).map_smul c y)
(Ξ» z x y, by rw [f.map_add, add_apply]) (Ξ» c y x, by rw [map_smul, smul_apply]))
β₯fβ₯ (Ξ» y x, (f.le_op_normβ x y).trans_eq $ by rw mul_right_comm)
private lemma le_norm_flip (f : E βL[π] F βL[π] G) : β₯fβ₯ β€ β₯flip fβ₯ :=
f.op_norm_le_boundβ (norm_nonneg _) $ Ξ» x y,
by { rw mul_right_comm, exact (flip f).le_op_normβ y x }
@[simp] lemma flip_apply (f : E βL[π] F βL[π] G) (x : E) (y : F) : f.flip y x = f x y := rfl
@[simp] lemma flip_flip (f : E βL[π] F βL[π] G) :
f.flip.flip = f :=
by { ext, refl }
@[simp] lemma op_norm_flip (f : E βL[π] F βL[π] G) :
β₯f.flipβ₯ = β₯fβ₯ :=
le_antisymm (by simpa only [flip_flip] using le_norm_flip f.flip) (le_norm_flip f)
@[simp] lemma flip_add (f g : E βL[π] F βL[π] G) :
(f + g).flip = f.flip + g.flip :=
rfl
@[simp] lemma flip_smul (c : π) (f : E βL[π] F βL[π] G) :
(c β’ f).flip = c β’ f.flip :=
rfl
variables (π E F G)
/-- Flip the order of arguments of a continuous bilinear map.
This is a version bundled as a `linear_isometry_equiv`.
For an unbundled version see `continuous_linear_map.flip`. -/
def flipβα΅’ : (E βL[π] F βL[π] G) ββα΅’[π] (F βL[π] E βL[π] G) :=
{ to_fun := flip,
inv_fun := flip,
map_add' := flip_add,
map_smul' := flip_smul,
left_inv := flip_flip,
right_inv := flip_flip,
norm_map' := op_norm_flip }
variables {π E F G}
@[simp] lemma flipβα΅’_symm : (flipβα΅’ π E F G).symm = flipβα΅’ π F E G := rfl
@[simp] lemma coe_flipβα΅’ : β(flipβα΅’ π E F G) = flip := rfl
variables (π F)
/-- The continuous linear map obtained by applying a continuous linear map at a given vector.
This is the continuous version of `linear_map.applyβ`. -/
def apply : E βL[π] (E βL[π] F) βL[π] F := flip (id π (E βL[π] F))
variables {π F}
@[simp] lemma apply_apply (v : E) (f : E βL[π] F) : apply π F v f = f v := rfl
variables (π E F G)
/-- Composition of continuous linear maps as a continuous bilinear map. -/
def compL : (F βL[π] G) βL[π] (E βL[π] F) βL[π] (E βL[π] G) :=
linear_map.mk_continuousβ
(linear_map.mkβ _ comp add_comp smul_comp comp_add (Ξ» c f g, comp_smul _ _ _))
1 $ Ξ» f g, by simpa only [one_mul] using op_norm_comp_le f g
variables {π E F G}
@[simp] lemma compL_apply (f : F βL[π] G) (g : E βL[π] F) : compL π E F G f g = f.comp g := rfl
section multiplication_linear
variables (π) (π' : Type*) [normed_ring π'] [normed_algebra π π']
/-- Left multiplication in a normed algebra as a linear isometry to the space of
continuous linear maps. -/
def lmulβα΅’ : π' ββα΅’[π] π' βL[π] π' :=
{ to_linear_map := (algebra.lmul π π').to_linear_map.mk_continuousβ 1 $
Ξ» x y, by simpa using norm_mul_le x y,
norm_map' := Ξ» x, le_antisymm
(op_norm_le_bound _ (norm_nonneg x) (norm_mul_le x))
(by { convert ratio_le_op_norm _ (1 : π'), simp [normed_algebra.norm_one π π'] }) }
/-- Left multiplication in a normed algebra as a continuous bilinear map. -/
def lmul : π' βL[π] π' βL[π] π' :=
(lmulβα΅’ π π').to_continuous_linear_map
@[simp] lemma lmul_apply (x y : π') : lmul π π' x y = x * y := rfl
@[simp] lemma coe_lmulβα΅’ : β(lmulβα΅’ π π') = lmul π π' := rfl
@[simp] lemma op_norm_lmul_apply (x : π') : β₯lmul π π' xβ₯ = β₯xβ₯ :=
(lmulβα΅’ π π').norm_map x
/-- Right-multiplication in a normed algebra, considered as a continuous linear map. -/
def lmul_right : π' βL[π] π' βL[π] π' := (lmul π π').flip
@[simp] lemma lmul_right_apply (x y : π') : lmul_right π π' x y = y * x := rfl
@[simp] lemma op_norm_lmul_right_apply (x : π') : β₯lmul_right π π' xβ₯ = β₯xβ₯ :=
le_antisymm
(op_norm_le_bound _ (norm_nonneg x) (Ξ» y, (norm_mul_le y x).trans_eq (mul_comm _ _)))
(by { convert ratio_le_op_norm _ (1 : π'), simp [normed_algebra.norm_one π π'] })
/-- Right-multiplication in a normed algebra, considered as a linear isometry to the space of
continuous linear maps. -/
def lmul_rightβα΅’ : π' ββα΅’[π] π' βL[π] π' :=
{ to_linear_map := lmul_right π π',
norm_map' := op_norm_lmul_right_apply π π' }
@[simp] lemma coe_lmul_rightβα΅’ : β(lmul_rightβα΅’ π π') = lmul_right π π' := rfl
/-- Simultaneous left- and right-multiplication in a normed algebra, considered as a continuous
trilinear map. -/
def lmul_left_right : π' βL[π] π' βL[π] π' βL[π] π' :=
((compL π π' π' π').comp (lmul_right π π')).flip.comp (lmul π π')
@[simp] lemma lmul_left_right_apply (x y z : π') :
lmul_left_right π π' x y z = x * z * y := rfl
lemma op_norm_lmul_left_right_apply_apply_le (x y : π') :
β₯lmul_left_right π π' x yβ₯ β€ β₯xβ₯ * β₯yβ₯ :=
(op_norm_comp_le _ _).trans_eq $ by simp [mul_comm]
lemma op_norm_lmul_left_right_apply_le (x : π') :
β₯lmul_left_right π π' xβ₯ β€ β₯xβ₯ :=
op_norm_le_bound _ (norm_nonneg x) (op_norm_lmul_left_right_apply_apply_le π π' x)
lemma op_norm_lmul_left_right_le :
β₯lmul_left_right π π'β₯ β€ 1 :=
op_norm_le_bound _ zero_le_one (Ξ» x, (one_mul β₯xβ₯).symm βΈ op_norm_lmul_left_right_apply_le π π' x)
end multiplication_linear
section smul_linear
variables (π) (π' : Type*) [normed_field π'] [normed_algebra π π']
[semi_normed_space π' E] [is_scalar_tower π π' E]
/-- Scalar multiplication as a continuous bilinear map. -/
def lsmul : π' βL[π] E βL[π] E :=
((algebra.lsmul π E).to_linear_map : π' ββ[π] E ββ[π] E).mk_continuousβ 1 $
Ξ» c x, by simpa only [one_mul] using (norm_smul c x).le
end smul_linear
section restrict_scalars
variables {π' : Type*} [nondiscrete_normed_field π'] [normed_algebra π' π]
variables [semi_normed_space π' E] [is_scalar_tower π' π E]
variables [semi_normed_space π' F] [is_scalar_tower π' π F]
@[simp] lemma norm_restrict_scalars (f : E βL[π] F) : β₯f.restrict_scalars π'β₯ = β₯fβ₯ :=
le_antisymm (op_norm_le_bound _ (norm_nonneg _) $ Ξ» x, f.le_op_norm x)
(op_norm_le_bound _ (norm_nonneg _) $ Ξ» x, f.le_op_norm x)
variables (π E F π') (π'' : Type*) [ring π''] [topological_space π''] [module π'' F]
[has_continuous_smul π'' F] [smul_comm_class π π'' F] [smul_comm_class π' π'' F]
/-- `continuous_linear_map.restrict_scalars` as a `linear_isometry`. -/
def restrict_scalars_isometry : (E βL[π] F) ββα΅’[π''] (E βL[π'] F) :=
β¨restrict_scalarsβ π E F π' π'', norm_restrict_scalarsβ©
variables {π E F π' π''}
@[simp] lemma coe_restrict_scalars_isometry :
β(restrict_scalars_isometry π E F π' π'') = restrict_scalars π' :=
rfl
@[simp] lemma restrict_scalars_isometry_to_linear_map :
(restrict_scalars_isometry π E F π' π'').to_linear_map = restrict_scalarsβ π E F π' π'' :=
rfl
variables (π E F π' π'')
/-- `continuous_linear_map.restrict_scalars` as a `continuous_linear_map`. -/
def restrict_scalarsL : (E βL[π] F) βL[π''] (E βL[π'] F) :=
(restrict_scalars_isometry π E F π' π'').to_continuous_linear_map
variables {π E F π' π''}
@[simp] lemma coe_restrict_scalarsL :
(restrict_scalarsL π E F π' π'' : (E βL[π] F) ββ[π''] (E βL[π'] F)) =
restrict_scalarsβ π E F π' π'' :=
rfl
@[simp] lemma coe_restrict_scalarsL' :
β(restrict_scalarsL π E F π' π'') = restrict_scalars π' :=
rfl
end restrict_scalars
end continuous_linear_map
namespace submodule
lemma norm_subtypeL_le (K : submodule π E) : β₯K.subtypeLβ₯ β€ 1 :=
K.subtypeβα΅’.norm_to_continuous_linear_map_le
end submodule
section has_sum
-- Results in this section hold for continuous additive monoid homomorphisms or equivalences but we
-- don't have bundled continuous additive homomorphisms.
variables {ΞΉ R M Mβ : Type*} [semiring R] [add_comm_monoid M] [module R M]
[add_comm_monoid Mβ] [module R Mβ] [topological_space M] [topological_space Mβ]
omit π
/-- Applying a continuous linear map commutes with taking an (infinite) sum. -/
protected lemma continuous_linear_map.has_sum {f : ΞΉ β M} (Ο : M βL[R] Mβ) {x : M}
(hf : has_sum f x) :
has_sum (Ξ» (b:ΞΉ), Ο (f b)) (Ο x) :=
by simpa only using hf.map Ο.to_linear_map.to_add_monoid_hom Ο.continuous
alias continuous_linear_map.has_sum β has_sum.mapL
protected lemma continuous_linear_map.summable {f : ΞΉ β M} (Ο : M βL[R] Mβ) (hf : summable f) :
summable (Ξ» b:ΞΉ, Ο (f b)) :=
(hf.has_sum.mapL Ο).summable
alias continuous_linear_map.summable β summable.mapL
protected lemma continuous_linear_map.map_tsum [t2_space Mβ] {f : ΞΉ β M}
(Ο : M βL[R] Mβ) (hf : summable f) : Ο (β' z, f z) = β' z, Ο (f z) :=
(hf.has_sum.mapL Ο).tsum_eq.symm
/-- Applying a continuous linear map commutes with taking an (infinite) sum. -/
protected lemma continuous_linear_equiv.has_sum {f : ΞΉ β M} (e : M βL[R] Mβ) {y : Mβ} :
has_sum (Ξ» (b:ΞΉ), e (f b)) y β has_sum f (e.symm y) :=
β¨Ξ» h, by simpa only [e.symm.coe_coe, e.symm_apply_apply] using h.mapL (e.symm : Mβ βL[R] M),
Ξ» h, by simpa only [e.coe_coe, e.apply_symm_apply] using (e : M βL[R] Mβ).has_sum hβ©
protected lemma continuous_linear_equiv.summable {f : ΞΉ β M} (e : M βL[R] Mβ) :
summable (Ξ» b:ΞΉ, e (f b)) β summable f :=
β¨Ξ» hf, (e.has_sum.1 hf.has_sum).summable, (e : M βL[R] Mβ).summableβ©
lemma continuous_linear_equiv.tsum_eq_iff [t2_space M] [t2_space Mβ] {f : ΞΉ β M}
(e : M βL[R] Mβ) {y : Mβ} : β' z, e (f z) = y β β' z, f z = e.symm y :=
begin
by_cases hf : summable f,
{ exact β¨Ξ» h, (e.has_sum.mp ((e.summable.mpr hf).has_sum_iff.mpr h)).tsum_eq,
Ξ» h, (e.has_sum.mpr (hf.has_sum_iff.mpr h)).tsum_eqβ© },
{ have hf' : Β¬summable (Ξ» z, e (f z)) := Ξ» h, hf (e.summable.mp h),
rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hf'],
exact β¨by { rintro rfl, simp }, Ξ» H, by simpa using (congr_arg (Ξ» z, e z) H)β© }
end
protected lemma continuous_linear_equiv.map_tsum [t2_space M] [t2_space Mβ] {f : ΞΉ β M}
(e : M βL[R] Mβ) : e (β' z, f z) = β' z, e (f z) :=
by { refine symm (e.tsum_eq_iff.mpr _), rw e.symm_apply_apply _ }
end has_sum
namespace continuous_linear_equiv
variables (e : E βL[π] F)
protected lemma lipschitz : lipschitz_with (nnnorm (e : E βL[π] F)) e :=
(e : E βL[π] F).lipschitz
theorem is_O_comp {Ξ± : Type*} (f : Ξ± β E) (l : filter Ξ±) :
asymptotics.is_O (Ξ» x', e (f x')) f l :=
(e : E βL[π] F).is_O_comp f l
theorem is_O_sub (l : filter E) (x : E) :
asymptotics.is_O (Ξ» x', e (x' - x)) (Ξ» x', x' - x) l :=
(e : E βL[π] F).is_O_sub l x
theorem is_O_comp_rev {Ξ± : Type*} (f : Ξ± β E) (l : filter Ξ±) :
asymptotics.is_O f (Ξ» x', e (f x')) l :=
(e.symm.is_O_comp _ l).congr_left $ Ξ» _, e.symm_apply_apply _
theorem is_O_sub_rev (l : filter E) (x : E) :
asymptotics.is_O (Ξ» x', x' - x) (Ξ» x', e (x' - x)) l :=
e.is_O_comp_rev _ _
lemma homothety_inverse (a : β) (ha : 0 < a) (f : E ββ[π] F) :
(β (x : E), β₯f xβ₯ = a * β₯xβ₯) β (β (y : F), β₯f.symm yβ₯ = aβ»ΒΉ * β₯yβ₯) :=
begin
intros hf y,
calc β₯(f.symm) yβ₯ = aβ»ΒΉ * (a * β₯ (f.symm) yβ₯) : _
... = aβ»ΒΉ * β₯f ((f.symm) y)β₯ : by rw hf
... = aβ»ΒΉ * β₯yβ₯ : by simp,
rw [β mul_assoc, inv_mul_cancel (ne_of_lt ha).symm, one_mul],
end
/-- A linear equivalence which is a homothety is a continuous linear equivalence. -/
def of_homothety (f : E ββ[π] F) (a : β) (ha : 0 < a) (hf : βx, β₯f xβ₯ = a * β₯xβ₯) : E βL[π] F :=
{ to_linear_equiv := f,
continuous_to_fun := f.to_linear_map.continuous_of_bound a (Ξ» x, le_of_eq (hf x)),
continuous_inv_fun := f.symm.to_linear_map.continuous_of_bound aβ»ΒΉ
(Ξ» x, le_of_eq (homothety_inverse a ha f hf x)) }
variable (π)
lemma to_span_nonzero_singleton_homothety (x : E) (h : x β 0) (c : π) :
β₯linear_equiv.to_span_nonzero_singleton π E x h cβ₯ = β₯xβ₯ * β₯cβ₯ :=
continuous_linear_map.to_span_singleton_homothety _ _ _
end continuous_linear_equiv
/-- Construct a continuous linear equivalence from a linear equivalence together with
bounds in both directions. -/
def linear_equiv.to_continuous_linear_equiv_of_bounds (e : E ββ[π] F) (C_to C_inv : β)
(h_to : β x, β₯e xβ₯ β€ C_to * β₯xβ₯) (h_inv : β x : F, β₯e.symm xβ₯ β€ C_inv * β₯xβ₯) : E βL[π] F :=
{ to_linear_equiv := e,
continuous_to_fun := e.to_linear_map.continuous_of_bound C_to h_to,
continuous_inv_fun := e.symm.to_linear_map.continuous_of_bound C_inv h_inv }
namespace continuous_linear_map
variables (π) (π' : Type*) [normed_ring π'] [normed_algebra π π']
variables {π}
variables {E' F' : Type*} [semi_normed_group E'] [semi_normed_group F']
[semi_normed_space π E'] [semi_normed_space π F']
/--
Compose a bilinear map `E βL[π] F βL[π] G` with two linear maps `E' βL[π] E` and `F' βL[π] F`.
-/
def bilinear_comp (f : E βL[π] F βL[π] G) (gE : E' βL[π] E) (gF : F' βL[π] F) :
E' βL[π] F' βL[π] G :=
((f.comp gE).flip.comp gF).flip
@[simp] lemma bilinear_comp_apply (f : E βL[π] F βL[π] G) (gE : E' βL[π] E) (gF : F' βL[π] F)
(x : E') (y : F') :
f.bilinear_comp gE gF x y = f (gE x) (gF y) :=
rfl
/-- Derivative of a continuous bilinear map `f : E βL[π] F βL[π] G` interpreted as a map `E Γ F β G`
at point `p : E Γ F` evaluated at `q : E Γ F`, as a continuous bilinear map. -/
def derivβ (f : E βL[π] F βL[π] G) : (E Γ F) βL[π] (E Γ F) βL[π] G :=
f.bilinear_comp (fst _ _ _) (snd _ _ _) + f.flip.bilinear_comp (snd _ _ _) (fst _ _ _)
@[simp] lemma coe_derivβ (f : E βL[π] F βL[π] G) (p : E Γ F) :
β(f.derivβ p) = Ξ» q : E Γ F, f p.1 q.2 + f q.1 p.2 := rfl
lemma map_addβ (f : E βL[π] F βL[π] G) (x x' : E) (y y' : F) :
f (x + x') (y + y') = f x y + f.derivβ (x, y) (x', y') + f x' y' :=
by simp only [map_add, add_apply, coe_derivβ, add_assoc]
end continuous_linear_map
end semi_normed
section normed
variables [normed_group E] [normed_group F] [normed_group G]
open metric continuous_linear_map
section normed_field
variables [normed_field π] [normed_space π E] [normed_space π F] (f : E ββ[π] F)
lemma linear_map.continuous_iff_is_closed_ker {f : E ββ[π] π} :
continuous f β is_closed (f.ker : set E) :=
begin
-- the continuity of f obviously implies that its kernel is closed
refine β¨Ξ»h, (t1_space.t1 (0 : π)).preimage h, Ξ»h, _β©,
-- for the other direction, we assume that the kernel is closed
by_cases hf : βx, x β f.ker,
{ -- if `f = 0`, its continuity is obvious
have : (f : E β π) = (Ξ»x, 0), by { ext x, simpa using hf x },
rw this,
exact continuous_const },
{ /- if `f` is not zero, we use an element `xβ β ker f` such that `β₯xββ₯ β€ 2 β₯xβ - yβ₯` for all
`y β ker f`, given by Riesz's lemma, and prove that `2 β₯f xββ₯ / β₯xββ₯` gives a bound on the
operator norm of `f`. For this, start from an arbitrary `x` and note that
`y = xβ - (f xβ / f x) x` belongs to the kernel of `f`. Applying the above inequality to `xβ`
and `y` readily gives the conclusion. -/
push_neg at hf,
let r : β := (2 : β)β»ΒΉ,
have : 0 β€ r, by norm_num [r],
have : r < 1, by norm_num [r],
obtain β¨xβ, xβker, hββ© : β (xβ : E), xβ β f.ker β§ β y β linear_map.ker f,
r * β₯xββ₯ β€ β₯xβ - yβ₯, from riesz_lemma h hf this,
have : xβ β 0,
{ assume h,
have : xβ β f.ker, by { rw h, exact (linear_map.ker f).zero_mem },
exact xβker this },
have rxβ_ne_zero : r * β₯xββ₯ β 0, by { simp [norm_eq_zero, this], },
have : βx, β₯f xβ₯ β€ (((r * β₯xββ₯)β»ΒΉ) * β₯f xββ₯) * β₯xβ₯,
{ assume x,
by_cases hx : f x = 0,
{ rw [hx, norm_zero],
apply_rules [mul_nonneg, norm_nonneg, inv_nonneg.2] },
{ let y := xβ - (f xβ * (f x)β»ΒΉ ) β’ x,
have fy_zero : f y = 0, by calc
f y = f xβ - (f xβ * (f x)β»ΒΉ ) * f x : by simp [y]
... = 0 :
by { rw [mul_assoc, inv_mul_cancel hx, mul_one, sub_eq_zero_of_eq], refl },
have A : r * β₯xββ₯ β€ β₯f xββ₯ * β₯f xβ₯β»ΒΉ * β₯xβ₯, from calc
r * β₯xββ₯ β€ β₯xβ - yβ₯ : hβ _ (linear_map.mem_ker.2 fy_zero)
... = β₯(f xβ * (f x)β»ΒΉ ) β’ xβ₯ : by { dsimp [y], congr, abel }
... = β₯f xββ₯ * β₯f xβ₯β»ΒΉ * β₯xβ₯ :
by rw [norm_smul, normed_field.norm_mul, normed_field.norm_inv],
calc
β₯f xβ₯ = (r * β₯xββ₯)β»ΒΉ * (r * β₯xββ₯) * β₯f xβ₯ : by rwa [inv_mul_cancel, one_mul]
... β€ (r * β₯xββ₯)β»ΒΉ * (β₯f xββ₯ * β₯f xβ₯β»ΒΉ * β₯xβ₯) * β₯f xβ₯ : begin
apply mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left A _) (norm_nonneg _),
exact inv_nonneg.2 (mul_nonneg (by norm_num) (norm_nonneg _))
end
... = (β₯f xβ₯ β»ΒΉ * β₯f xβ₯) * (((r * β₯xββ₯)β»ΒΉ) * β₯f xββ₯) * β₯xβ₯ : by ring
... = (((r * β₯xββ₯)β»ΒΉ) * β₯f xββ₯) * β₯xβ₯ :
by { rw [inv_mul_cancel, one_mul], simp [norm_eq_zero, hx] } } },
exact linear_map.continuous_of_bound f _ this }
end
end normed_field
variables [nondiscrete_normed_field π] [normed_space π E] [normed_space π F]
[normed_space π G] (c : π) (f g : E βL[π] F) (h : F βL[π] G) (x y z : E)
include π
lemma linear_map.bound_of_shell (f : E ββ[π] F) {Ξ΅ C : β} (Ξ΅_pos : 0 < Ξ΅) {c : π}
(hc : 1 < β₯cβ₯) (hf : β x, Ξ΅ / β₯cβ₯ β€ β₯xβ₯ β β₯xβ₯ < Ξ΅ β β₯f xβ₯ β€ C * β₯xβ₯) (x : E) :
β₯f xβ₯ β€ C * β₯xβ₯ :=
begin
by_cases hx : x = 0, { simp [hx] },
exact linear_map.bound_of_shell_semi_normed f Ξ΅_pos hc hf (ne_of_lt (norm_pos_iff.2 hx)).symm
end
namespace continuous_linear_map
section op_norm
open set real
/-- An operator is zero iff its norm vanishes. -/
theorem op_norm_zero_iff : β₯fβ₯ = 0 β f = 0 :=
iff.intro
(Ξ» hn, continuous_linear_map.ext (Ξ» x, norm_le_zero_iff.1
(calc _ β€ β₯fβ₯ * β₯xβ₯ : le_op_norm _ _
... = _ : by rw [hn, zero_mul])))
(Ξ» hf, le_antisymm (Inf_le _ bounds_bdd_below
β¨ge_of_eq rfl, Ξ» _, le_of_eq (by { rw [zero_mul, hf], exact norm_zero })β©)
(op_norm_nonneg _))
/-- If a normed space is non-trivial, then the norm of the identity equals `1`. -/
lemma norm_id [nontrivial E] : β₯id π Eβ₯ = 1 :=
begin
refine norm_id_of_nontrivial_seminorm _,
obtain β¨x, hxβ© := exists_ne (0 : E),
exact β¨x, ne_of_gt (norm_pos_iff.2 hx)β©,
end
@[simp] lemma norm_id_field : β₯id π πβ₯ = 1 :=
norm_id
@[simp] lemma norm_id_field' : β₯(1 : π βL[π] π)β₯ = 1 :=
norm_id_field
/-- Continuous linear maps themselves form a normed space with respect to
the operator norm. -/
instance to_normed_group : normed_group (E βL[π] F) :=
normed_group.of_core _ β¨op_norm_zero_iff, op_norm_add_le, op_norm_negβ©
instance to_normed_space {π' : Type*} [normed_field π'] [normed_space π' F]
[smul_comm_class π π' F] : normed_space π' (E βL[π] F) :=
β¨op_norm_smul_leβ©
/-- Continuous linear maps form a normed ring with respect to the operator norm. -/
instance to_normed_ring : normed_ring (E βL[π] E) :=
{ norm_mul := op_norm_comp_le,
.. continuous_linear_map.to_normed_group }
/-- For a nonzero normed space `E`, continuous linear endomorphisms form a normed algebra with
respect to the operator norm. -/
instance to_normed_algebra [nontrivial E] : normed_algebra π (E βL[π] E) :=
{ norm_algebra_map_eq := Ξ» c, show β₯c β’ id π Eβ₯ = β₯cβ₯,
by {rw [norm_smul, norm_id], simp},
.. continuous_linear_map.algebra }
variable {f}
lemma homothety_norm [nontrivial E] (f : E βL[π] F) {a : β} (hf : βx, β₯f xβ₯ = a * β₯xβ₯) :
β₯fβ₯ = a :=
begin
obtain β¨x, hxβ© : β (x : E), x β 0 := exists_ne 0,
rw β norm_pos_iff at hx,
have ha : 0 β€ a, by simpa only [hf, hx, zero_le_mul_right] using norm_nonneg (f x),
apply le_antisymm (f.op_norm_le_bound ha (Ξ» y, le_of_eq (hf y))),
simpa only [hf, hx, mul_le_mul_right] using f.le_op_norm x,
end
lemma to_span_singleton_norm (x : E) : β₯to_span_singleton π xβ₯ = β₯xβ₯ :=
homothety_norm _ (to_span_singleton_homothety π x)
variable (f)
theorem uniform_embedding_of_bound {K : ββ₯0} (hf : β x, β₯xβ₯ β€ K * β₯f xβ₯) :
uniform_embedding f :=
(f.to_linear_map.antilipschitz_of_bound hf).uniform_embedding f.uniform_continuous
/-- If a continuous linear map is a uniform embedding, then it is expands the distances
by a positive factor.-/
theorem antilipschitz_of_uniform_embedding (hf : uniform_embedding f) :
β K, antilipschitz_with K f :=
begin
obtain β¨Ξ΅, Ξ΅pos, hΞ΅β© : β (Ξ΅ : β) (H : Ξ΅ > 0), β {x y : E}, dist (f x) (f y) < Ξ΅ β dist x y < 1,
from (uniform_embedding_iff.1 hf).2.2 1 zero_lt_one,
let Ξ΄ := Ξ΅/2,
have Ξ΄_pos : Ξ΄ > 0 := half_pos Ξ΅pos,
have H : β{x}, β₯f xβ₯ β€ Ξ΄ β β₯xβ₯ β€ 1,
{ assume x hx,
have : dist x 0 β€ 1,
{ refine (hΞ΅ _).le,
rw [f.map_zero, dist_zero_right],
exact hx.trans_lt (half_lt_self Ξ΅pos) },
simpa using this },
rcases normed_field.exists_one_lt_norm π with β¨c, hcβ©,
refine β¨β¨Ξ΄β»ΒΉ, _β© * nnnorm c, f.to_linear_map.antilipschitz_of_bound $ Ξ»x, _β©,
exact inv_nonneg.2 (le_of_lt Ξ΄_pos),
by_cases hx : f x = 0,
{ have : f x = f 0, by { simp [hx] },
have : x = 0 := (uniform_embedding_iff.1 hf).1 this,
simp [this] },
{ rcases rescale_to_shell hc Ξ΄_pos hx with β¨d, hd, dxlt, ledx, dinvβ©,
rw [β f.map_smul d] at dxlt,
have : β₯d β’ xβ₯ β€ 1 := H dxlt.le,
calc β₯xβ₯ = β₯dβ₯β»ΒΉ * β₯d β’ xβ₯ :
by rwa [β normed_field.norm_inv, β norm_smul, β mul_smul, inv_mul_cancel, one_smul]
... β€ β₯dβ₯β»ΒΉ * 1 :
mul_le_mul_of_nonneg_left this (inv_nonneg.2 (norm_nonneg _))
... β€ Ξ΄β»ΒΉ * β₯cβ₯ * β₯f xβ₯ :
by rwa [mul_one] }
end
section completeness
open_locale topological_space
open filter
/-- If the target space is complete, the space of continuous linear maps with its norm is also
complete. This works also if the source space is seminormed. -/
instance {E : Type*} [semi_normed_group E] [semi_normed_space π E] [complete_space F] :
complete_space (E βL[π] F) :=
begin
-- We show that every Cauchy sequence converges.
refine metric.complete_of_cauchy_seq_tendsto (Ξ» f hf, _),
-- We now expand out the definition of a Cauchy sequence,
rcases cauchy_seq_iff_le_tendsto_0.1 hf with β¨b, b0, b_bound, b_limβ©, clear hf,
-- and establish that the evaluation at any point `v : E` is Cauchy.
have cau : β v, cauchy_seq (Ξ» n, f n v),
{ assume v,
apply cauchy_seq_iff_le_tendsto_0.2 β¨Ξ» n, b n * β₯vβ₯, Ξ» n, _, _, _β©,
{ exact mul_nonneg (b0 n) (norm_nonneg _) },
{ assume n m N hn hm,
rw dist_eq_norm,
apply le_trans ((f n - f m).le_op_norm v) _,
exact mul_le_mul_of_nonneg_right (b_bound n m N hn hm) (norm_nonneg v) },
{ simpa using b_lim.mul tendsto_const_nhds } },
-- We assemble the limits points of those Cauchy sequences
-- (which exist as `F` is complete)
-- into a function which we call `G`.
choose G hG using Ξ»v, cauchy_seq_tendsto_of_complete (cau v),
-- Next, we show that this `G` is linear,
let Glin : E ββ[π] F :=
{ to_fun := G,
map_add' := Ξ» v w, begin
have A := hG (v + w),
have B := (hG v).add (hG w),
simp only [map_add] at A B,
exact tendsto_nhds_unique A B,
end,
map_smul' := Ξ» c v, begin
have A := hG (c β’ v),
have B := filter.tendsto.smul (@tendsto_const_nhds _ β _ c _) (hG v),
simp only [map_smul] at A B,
exact tendsto_nhds_unique A B
end },
-- and that `G` has norm at most `(b 0 + β₯f 0β₯)`.
have Gnorm : β v, β₯G vβ₯ β€ (b 0 + β₯f 0β₯) * β₯vβ₯,
{ assume v,
have A : β n, β₯f n vβ₯ β€ (b 0 + β₯f 0β₯) * β₯vβ₯,
{ assume n,
apply le_trans ((f n).le_op_norm _) _,
apply mul_le_mul_of_nonneg_right _ (norm_nonneg v),
calc β₯f nβ₯ = β₯(f n - f 0) + f 0β₯ : by { congr' 1, abel }
... β€ β₯f n - f 0β₯ + β₯f 0β₯ : norm_add_le _ _
... β€ b 0 + β₯f 0β₯ : begin
apply add_le_add_right,
simpa [dist_eq_norm] using b_bound n 0 0 (zero_le _) (zero_le _)
end },
exact le_of_tendsto (hG v).norm (eventually_of_forall A) },
-- Thus `G` is continuous, and we propose that as the limit point of our original Cauchy sequence.
let Gcont := Glin.mk_continuous _ Gnorm,
use Gcont,
-- Our last task is to establish convergence to `G` in norm.
have : β n, β₯f n - Gcontβ₯ β€ b n,
{ assume n,
apply op_norm_le_bound _ (b0 n) (Ξ» v, _),
have A : βαΆ m in at_top, β₯(f n - f m) vβ₯ β€ b n * β₯vβ₯,
{ refine eventually_at_top.2 β¨n, Ξ» m hm, _β©,
apply le_trans ((f n - f m).le_op_norm _) _,
exact mul_le_mul_of_nonneg_right (b_bound n m n (le_refl _) hm) (norm_nonneg v) },
have B : tendsto (Ξ» m, β₯(f n - f m) vβ₯) at_top (π (β₯(f n - Gcont) vβ₯)) :=
tendsto.norm (tendsto_const_nhds.sub (hG v)),
exact le_of_tendsto B A },
erw tendsto_iff_norm_tendsto_zero,
exact squeeze_zero (Ξ» n, norm_nonneg _) this b_lim,
end
end completeness
section uniformly_extend
variables [complete_space F] (e : E βL[π] G) (h_dense : dense_range e)
section
variables (h_e : uniform_inducing e)
/-- Extension of a continuous linear map `f : E βL[π] F`, with `E` a normed space and `F` a
complete normed space, along a uniform and dense embedding `e : E βL[π] G`. -/
def extend : G βL[π] F :=
/- extension of `f` is continuous -/
have cont : _ := (uniform_continuous_uniformly_extend h_e h_dense f.uniform_continuous).continuous,
/- extension of `f` agrees with `f` on the domain of the embedding `e` -/
have eq : _ := uniformly_extend_of_ind h_e h_dense f.uniform_continuous,
{ to_fun := (h_e.dense_inducing h_dense).extend f,
map_add' :=
begin
refine h_dense.induction_onβ _ _,
{ exact is_closed_eq (cont.comp continuous_add)
((cont.comp continuous_fst).add (cont.comp continuous_snd)) },
{ assume x y, simp only [eq, β e.map_add], exact f.map_add _ _ },
end,
map_smul' := Ξ»k,
begin
refine (Ξ» b, h_dense.induction_on b _ _),
{ exact is_closed_eq (cont.comp (continuous_const.smul continuous_id))
((continuous_const.smul continuous_id).comp cont) },
{ assume x, rw β map_smul, simp only [eq], exact map_smul _ _ _ },
end,
cont := cont
}
lemma extend_unique (g : G βL[π] F) (H : g.comp e = f) : extend f e h_dense h_e = g :=
continuous_linear_map.coe_fn_injective $
uniformly_extend_unique h_e h_dense (continuous_linear_map.ext_iff.1 H) g.continuous
@[simp] lemma extend_zero : extend (0 : E βL[π] F) e h_dense h_e = 0 :=
extend_unique _ _ _ _ _ (zero_comp _)
end
section
variables {N : ββ₯0} (h_e : βx, β₯xβ₯ β€ N * β₯e xβ₯)
local notation `Ο` := f.extend e h_dense (uniform_embedding_of_bound _ h_e).to_uniform_inducing
/-- If a dense embedding `e : E βL[π] G` expands the norm by a constant factor `Nβ»ΒΉ`, then the
norm of the extension of `f` along `e` is bounded by `N * β₯fβ₯`. -/
lemma op_norm_extend_le : β₯Οβ₯ β€ N * β₯fβ₯ :=
begin
have uni : uniform_inducing e := (uniform_embedding_of_bound _ h_e).to_uniform_inducing,
have eq : βx, Ο (e x) = f x := uniformly_extend_of_ind uni h_dense f.uniform_continuous,
by_cases N0 : 0 β€ N,
{ refine op_norm_le_bound Ο _ (is_closed_property h_dense (is_closed_le _ _) _),
{ exact mul_nonneg N0 (norm_nonneg _) },
{ exact continuous_norm.comp (cont Ο) },
{ exact continuous_const.mul continuous_norm },
{ assume x,
rw eq,
calc β₯f xβ₯ β€ β₯fβ₯ * β₯xβ₯ : le_op_norm _ _
... β€ β₯fβ₯ * (N * β₯e xβ₯) : mul_le_mul_of_nonneg_left (h_e x) (norm_nonneg _)
... β€ N * β₯fβ₯ * β₯e xβ₯ : by rw [mul_comm βN β₯fβ₯, mul_assoc] } },
{ have he : β x : E, x = 0,
{ assume x,
have N0 : N β€ 0 := le_of_lt (lt_of_not_ge N0),
rw β norm_le_zero_iff,
exact le_trans (h_e x) (mul_nonpos_of_nonpos_of_nonneg N0 (norm_nonneg _)) },
have hf : f = 0, { ext, simp only [he x, zero_apply, map_zero] },
have hΟ : Ο = 0, { rw hf, apply extend_zero },
rw [hΟ, hf, norm_zero, norm_zero, mul_zero] }
end
end
end uniformly_extend
end op_norm
end continuous_linear_map
namespace linear_isometry
@[simp] lemma norm_to_continuous_linear_map [nontrivial E] (f : E ββα΅’[π] F) :
β₯f.to_continuous_linear_mapβ₯ = 1 :=
f.to_continuous_linear_map.homothety_norm $ by simp
end linear_isometry
namespace continuous_linear_map
/-- Precomposition with a linear isometry preserves the operator norm. -/
lemma op_norm_comp_linear_isometry_equiv {G : Type*} [semi_normed_group G] [semi_normed_space π G]
(f : F βL[π] G) (g : E ββα΅’[π] F) :
β₯f.comp g.to_linear_isometry.to_continuous_linear_mapβ₯ = β₯fβ₯ :=
begin
casesI subsingleton_or_nontrivial E,
{ haveI := g.symm.to_linear_equiv.to_equiv.subsingleton,
simp },
refine le_antisymm _ _,
{ convert f.op_norm_comp_le g.to_linear_isometry.to_continuous_linear_map,
simp [g.to_linear_isometry.norm_to_continuous_linear_map] },
{ convert (f.comp g.to_linear_isometry.to_continuous_linear_map).op_norm_comp_le
g.symm.to_linear_isometry.to_continuous_linear_map,
{ ext,
simp },
haveI := g.symm.to_linear_equiv.to_equiv.nontrivial,
simp [g.symm.to_linear_isometry.norm_to_continuous_linear_map] },
end
/-- The norm of the tensor product of a scalar linear map and of an element of a normed space
is the product of the norms. -/
@[simp] lemma norm_smul_right_apply (c : E βL[π] π) (f : F) :
β₯smul_right c fβ₯ = β₯cβ₯ * β₯fβ₯ :=
begin
refine le_antisymm _ _,
{ apply op_norm_le_bound _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) (Ξ»x, _),
calc
β₯(c x) β’ fβ₯ = β₯c xβ₯ * β₯fβ₯ : norm_smul _ _
... β€ (β₯cβ₯ * β₯xβ₯) * β₯fβ₯ :
mul_le_mul_of_nonneg_right (le_op_norm _ _) (norm_nonneg _)
... = β₯cβ₯ * β₯fβ₯ * β₯xβ₯ : by ring },
{ by_cases h : f = 0,
{ simp [h] },
{ have : 0 < β₯fβ₯ := norm_pos_iff.2 h,
rw β le_div_iff this,
apply op_norm_le_bound _ (div_nonneg (norm_nonneg _) (norm_nonneg f)) (Ξ»x, _),
rw [div_mul_eq_mul_div, le_div_iff this],
calc β₯c xβ₯ * β₯fβ₯ = β₯c x β’ fβ₯ : (norm_smul _ _).symm
... = β₯smul_right c f xβ₯ : rfl
... β€ β₯smul_right c fβ₯ * β₯xβ₯ : le_op_norm _ _ } },
end
variables (π E F)
/-- `continuous_linear_map.smul_right` as a continuous trilinear map:
`smul_rightL (c : E βL[π] π) (f : F) (x : E) = c x β’ f`. -/
def smul_rightL : (E βL[π] π) βL[π] F βL[π] E βL[π] F :=
linear_map.mk_continuousβ
{ to_fun := smul_rightβ,
map_add' := Ξ» cβ cβ, by { ext x, simp [add_smul] },
map_smul' := Ξ» m c, by { ext x, simp [smul_smul] } }
1 $ Ξ» c x, by simp
variables {π E F}
@[simp] lemma norm_smul_rightL_apply (c : E βL[π] π) (f : F) :
β₯smul_rightL π E F c fβ₯ = β₯cβ₯ * β₯fβ₯ :=
norm_smul_right_apply c f
@[simp] lemma norm_smul_rightL (c : E βL[π] π) [nontrivial F] :
β₯smul_rightL π E F cβ₯ = β₯cβ₯ :=
continuous_linear_map.homothety_norm _ c.norm_smul_right_apply
variables (π) (π' : Type*) [normed_ring π'] [normed_algebra π π']
@[simp] lemma op_norm_lmul : β₯lmul π π'β₯ = 1 :=
by haveI := normed_algebra.nontrivial π π'; exact (lmulβα΅’ π π').norm_to_continuous_linear_map
@[simp] lemma op_norm_lmul_right : β₯lmul_right π π'β₯ = 1 :=
(op_norm_flip (@lmul π _ π' _ _)).trans (op_norm_lmul _ _)
end continuous_linear_map
namespace submodule
lemma norm_subtypeL (K : submodule π E) [nontrivial K] : β₯K.subtypeLβ₯ = 1 :=
K.subtypeβα΅’.norm_to_continuous_linear_map
end submodule
namespace continuous_linear_equiv
variables (e : E βL[π] F)
protected lemma antilipschitz : antilipschitz_with (nnnorm (e.symm : F βL[π] E)) e :=
e.symm.lipschitz.to_right_inverse e.left_inv
/-- A continuous linear equiv is a uniform embedding. -/
lemma uniform_embedding : uniform_embedding e :=
e.antilipschitz.uniform_embedding e.lipschitz.uniform_continuous
lemma one_le_norm_mul_norm_symm [nontrivial E] :
1 β€ β₯(e : E βL[π] F)β₯ * β₯(e.symm : F βL[π] E)β₯ :=
begin
rw [mul_comm],
convert (e.symm : F βL[π] E).op_norm_comp_le (e : E βL[π] F),
rw [e.coe_symm_comp_coe, continuous_linear_map.norm_id]
end
lemma norm_pos [nontrivial E] : 0 < β₯(e : E βL[π] F)β₯ :=
pos_of_mul_pos_right (lt_of_lt_of_le zero_lt_one e.one_le_norm_mul_norm_symm) (norm_nonneg _)
lemma norm_symm_pos [nontrivial E] : 0 < β₯(e.symm : F βL[π] E)β₯ :=
pos_of_mul_pos_left (lt_of_lt_of_le zero_lt_one e.one_le_norm_mul_norm_symm) (norm_nonneg _)
lemma nnnorm_symm_pos [nontrivial E] : 0 < nnnorm (e.symm : F βL[π] E) :=
e.norm_symm_pos
lemma subsingleton_or_norm_symm_pos : subsingleton E β¨ 0 < β₯(e.symm : F βL[π] E)β₯ :=
begin
rcases subsingleton_or_nontrivial E with _i|_i; resetI,
{ left, apply_instance },
{ right, exact e.norm_symm_pos }
end
lemma subsingleton_or_nnnorm_symm_pos : subsingleton E β¨ 0 < (nnnorm $ (e.symm : F βL[π] E)) :=
subsingleton_or_norm_symm_pos e
variable (π)
/-- Given a nonzero element `x` of a normed space `Eβ` over a field `π`, the natural
continuous linear equivalence from `Eβ` to the span of `x`.-/
def to_span_nonzero_singleton (x : E) (h : x β 0) : π βL[π] (π β x) :=
of_homothety
(linear_equiv.to_span_nonzero_singleton π E x h)
β₯xβ₯
(norm_pos_iff.mpr h)
(to_span_nonzero_singleton_homothety π x h)
/-- Given a nonzero element `x` of a normed space `Eβ` over a field `π`, the natural continuous
linear map from the span of `x` to `π`.-/
def coord (x : E) (h : x β 0) : (π β x) βL[π] π := (to_span_nonzero_singleton π x h).symm
@[simp] lemma coe_to_span_nonzero_singleton_symm {x : E} (h : x β 0) :
β(to_span_nonzero_singleton π x h).symm = coord π x h := rfl
@[simp] lemma coord_to_span_nonzero_singleton {x : E} (h : x β 0) (c : π) :
coord π x h (to_span_nonzero_singleton π x h c) = c :=
(to_span_nonzero_singleton π x h).symm_apply_apply c
@[simp] lemma to_span_nonzero_singleton_coord {x : E} (h : x β 0) (y : π β x) :
to_span_nonzero_singleton π x h (coord π x h y) = y :=
(to_span_nonzero_singleton π x h).apply_symm_apply y
@[simp] lemma coord_norm (x : E) (h : x β 0) : β₯coord π x hβ₯ = β₯xβ₯β»ΒΉ :=
begin
have hx : 0 < β₯xβ₯ := (norm_pos_iff.mpr h),
haveI : nontrivial (π β x) := submodule.nontrivial_span_singleton h,
exact continuous_linear_map.homothety_norm _
(Ξ» y, homothety_inverse _ hx _ (to_span_nonzero_singleton_homothety π x h) _)
end
@[simp] lemma coord_self (x : E) (h : x β 0) :
(coord π x h) (β¨x, submodule.mem_span_singleton_self xβ© : π β x) = 1 :=
linear_equiv.coord_self π E x h
end continuous_linear_equiv
lemma linear_equiv.uniform_embedding (e : E ββ[π] F) (hβ : continuous e)
(hβ : continuous e.symm) : uniform_embedding e :=
continuous_linear_equiv.uniform_embedding
{ continuous_to_fun := hβ,
continuous_inv_fun := hβ,
.. e }
end normed
|
ad95f707eebd55102c62076b832348baf66e8cd7 | 07f5f86b00fed90a419ccda4298d8b795a68f657 | /library/init/algebra/order.lean | c93e0541a68836225a060601485827ae404561be | [
"Apache-2.0"
] | permissive | VBaratham/lean | 8ec5c3167b4835cfbcd7f25e2173d61ad9416b3a | 450ca5834c1c35318e4b47d553bb9820c1b3eee7 | refs/heads/master | 1,629,649,471,814 | 1,512,060,373,000 | 1,512,060,469,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 8,762 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.logic init.classical init.meta.name init.algebra.classes
/- Make sure instances defined in this file have lower priority than the ones
defined for concrete structures -/
set_option default_priority 100
set_option old_structure_cmd true
universe u
variables {Ξ± : Type u}
set_option auto_param.check_exists false
class preorder (Ξ± : Type u) extends has_le Ξ±, has_lt Ξ± :=
(le_refl : β a : Ξ±, a β€ a)
(le_trans : β a b c : Ξ±, a β€ b β b β€ c β a β€ c)
(lt := Ξ» a b, a β€ b β§ Β¬ b β€ a)
(lt_iff_le_not_le : β a b : Ξ±, a < b β (a β€ b β§ Β¬ b β€ a) . order_laws_tac)
class partial_order (Ξ± : Type u) extends preorder Ξ± :=
(le_antisymm : β a b : Ξ±, a β€ b β b β€ a β a = b)
class linear_order (Ξ± : Type u) extends partial_order Ξ± :=
(le_total : β a b : Ξ±, a β€ b β¨ b β€ a)
@[refl] lemma le_refl [preorder Ξ±] : β a : Ξ±, a β€ a :=
preorder.le_refl
@[trans] lemma le_trans [preorder Ξ±] : β {a b c : Ξ±}, a β€ b β b β€ c β a β€ c :=
preorder.le_trans
lemma lt_iff_le_not_le [preorder Ξ±] : β {a b : Ξ±}, a < b β (a β€ b β§ Β¬ b β€ a) :=
preorder.lt_iff_le_not_le _
lemma lt_of_le_not_le [preorder Ξ±] : β {a b : Ξ±}, a β€ b β Β¬ b β€ a β a < b
| a b hab hba := lt_iff_le_not_le.mpr β¨hab, hbaβ©
lemma le_not_le_of_lt [preorder Ξ±] : β {a b : Ξ±}, a < b β a β€ b β§ Β¬ b β€ a
| a b hab := lt_iff_le_not_le.mp hab
lemma le_antisymm [partial_order Ξ±] : β {a b : Ξ±}, a β€ b β b β€ a β a = b :=
partial_order.le_antisymm
lemma le_of_eq [preorder Ξ±] {a b : Ξ±} : a = b β a β€ b :=
Ξ» h, h βΈ le_refl a
lemma le_antisymm_iff [partial_order Ξ±] {a b : Ξ±} : a = b β a β€ b β§ b β€ a :=
β¨Ξ»e, β¨le_of_eq e, le_of_eq e.symmβ©, Ξ»β¨h1, h2β©, le_antisymm h1 h2β©
@[trans] lemma ge_trans [preorder Ξ±] : β {a b c : Ξ±}, a β₯ b β b β₯ c β a β₯ c :=
Ξ» a b c hβ hβ, le_trans hβ hβ
lemma le_total [linear_order Ξ±] : β a b : Ξ±, a β€ b β¨ b β€ a :=
linear_order.le_total
lemma le_of_not_ge [linear_order Ξ±] {a b : Ξ±} : Β¬ a β₯ b β a β€ b :=
or.resolve_left (le_total b a)
lemma le_of_not_le [linear_order Ξ±] {a b : Ξ±} : Β¬ a β€ b β b β€ a :=
or.resolve_left (le_total a b)
lemma lt_irrefl [preorder Ξ±] : β a : Ξ±, Β¬ a < a
| a haa := match le_not_le_of_lt haa with
| β¨h1, h2β© := false.rec _ (h2 h1)
end
lemma gt_irrefl [preorder Ξ±] : β a : Ξ±, Β¬ a > a :=
lt_irrefl
@[trans] lemma lt_trans [preorder Ξ±] : β {a b c : Ξ±}, a < b β b < c β a < c
| a b c hab hbc :=
match le_not_le_of_lt hab, le_not_le_of_lt hbc with
| β¨hab, hbaβ©, β¨hbc, hcbβ© := lt_of_le_not_le (le_trans hab hbc) (Ξ» hca, hcb (le_trans hca hab))
end
def lt.trans := @lt_trans
@[trans] lemma gt_trans [preorder Ξ±] : β {a b c : Ξ±}, a > b β b > c β a > c :=
Ξ» a b c hβ hβ, lt_trans hβ hβ
def gt.trans := @gt_trans
lemma ne_of_lt [preorder Ξ±] {a b : Ξ±} (h : a < b) : a β b :=
Ξ» he, absurd h (he βΈ lt_irrefl a)
lemma ne_of_gt [preorder Ξ±] {a b : Ξ±} (h : a > b) : a β b :=
Ξ» he, absurd h (he βΈ lt_irrefl a)
lemma lt_asymm [preorder Ξ±] {a b : Ξ±} (h : a < b) : Β¬ b < a :=
Ξ» h1 : b < a, lt_irrefl a (lt_trans h h1)
lemma not_lt_of_gt [linear_order Ξ±] {a b : Ξ±} (h : a > b) : Β¬ a < b :=
lt_asymm h
lemma le_of_lt [preorder Ξ±] : β {a b : Ξ±}, a < b β a β€ b
| a b hab := (le_not_le_of_lt hab).left
@[trans] lemma lt_of_lt_of_le [preorder Ξ±] : β {a b c : Ξ±}, a < b β b β€ c β a < c
| a b c hab hbc :=
let β¨hab, hbaβ© := le_not_le_of_lt hab in
lt_of_le_not_le (le_trans hab hbc) $ Ξ» hca, hba (le_trans hbc hca)
@[trans] lemma lt_of_le_of_lt [preorder Ξ±] : β {a b c : Ξ±}, a β€ b β b < c β a < c
| a b c hab hbc :=
let β¨hbc, hcbβ© := le_not_le_of_lt hbc in
lt_of_le_not_le (le_trans hab hbc) $ Ξ» hca, hcb (le_trans hca hab)
@[trans] lemma gt_of_gt_of_ge [preorder Ξ±] {a b c : Ξ±} (hβ : a > b) (hβ : b β₯ c) : a > c :=
lt_of_le_of_lt hβ hβ
@[trans] lemma gt_of_ge_of_gt [preorder Ξ±] {a b c : Ξ±} (hβ : a β₯ b) (hβ : b > c) : a > c :=
lt_of_lt_of_le hβ hβ
lemma not_le_of_gt [preorder Ξ±] {a b : Ξ±} (h : a > b) : Β¬ a β€ b :=
(le_not_le_of_lt h).right
lemma not_lt_of_ge [preorder Ξ±] {a b : Ξ±} (h : a β₯ b) : Β¬ a < b :=
Ξ» hab, not_le_of_gt hab h
lemma lt_or_eq_of_le [partial_order Ξ±] : β {a b : Ξ±}, a β€ b β a < b β¨ a = b
| a b hab := classical.by_cases
(Ξ» hba : b β€ a, or.inr (le_antisymm hab hba))
(Ξ» hba, or.inl (lt_of_le_not_le hab hba))
lemma le_of_lt_or_eq [preorder Ξ±] : β {a b : Ξ±}, (a < b β¨ a = b) β a β€ b
| a b (or.inl hab) := le_of_lt hab
| a b (or.inr hab) := hab βΈ le_refl _
lemma le_iff_lt_or_eq [partial_order Ξ±] : β {a b : Ξ±}, a β€ b β a < b β¨ a = b
| a b := β¨lt_or_eq_of_le, le_of_lt_or_eqβ©
lemma lt_of_le_of_ne [partial_order Ξ±] {a b : Ξ±} : a β€ b β a β b β a < b :=
Ξ» hβ hβ, or.resolve_right (lt_or_eq_of_le hβ) hβ
lemma lt_trichotomy [linear_order Ξ±] (a b : Ξ±) : a < b β¨ a = b β¨ b < a :=
or.elim (le_total a b)
(Ξ» h : a β€ b, or.elim (lt_or_eq_of_le h)
(Ξ» h : a < b, or.inl h)
(Ξ» h : a = b, or.inr (or.inl h)))
(Ξ» h : b β€ a, or.elim (lt_or_eq_of_le h)
(Ξ» h : b < a, or.inr (or.inr h))
(Ξ» h : b = a, or.inr (or.inl h.symm)))
lemma le_of_not_gt [linear_order Ξ±] {a b : Ξ±} (h : Β¬ a > b) : a β€ b :=
match lt_trichotomy a b with
| or.inl hlt := le_of_lt hlt
| or.inr (or.inl heq) := heq βΈ le_refl a
| or.inr (or.inr hgt) := absurd hgt h
end
lemma lt_of_not_ge [linear_order Ξ±] {a b : Ξ±} (h : Β¬ a β₯ b) : a < b :=
match lt_trichotomy a b with
| or.inl hlt := hlt
| or.inr (or.inl heq) := absurd (heq βΈ le_refl a : a β₯ b) h
| or.inr (or.inr hgt) := absurd (le_of_lt hgt) h
end
lemma lt_or_ge [linear_order Ξ±] (a b : Ξ±) : a < b β¨ a β₯ b :=
match lt_trichotomy a b with
| or.inl hlt := or.inl hlt
| or.inr (or.inl heq) := or.inr (heq βΈ le_refl a)
| or.inr (or.inr hgt) := or.inr (le_of_lt hgt)
end
lemma le_or_gt [linear_order Ξ±] (a b : Ξ±) : a β€ b β¨ a > b :=
or.swap (lt_or_ge b a)
lemma lt_or_gt_of_ne [linear_order Ξ±] {a b : Ξ±} (h : a β b) : a < b β¨ a > b :=
match lt_trichotomy a b with
| or.inl hlt := or.inl hlt
| or.inr (or.inl heq) := absurd heq h
| or.inr (or.inr hgt) := or.inr hgt
end
lemma le_of_eq_or_lt [preorder Ξ±] {a b : Ξ±} (h : a = b β¨ a < b) : a β€ b :=
or.elim h le_of_eq le_of_lt
lemma ne_iff_lt_or_gt [linear_order Ξ±] {a b : Ξ±} : a β b β a < b β¨ a > b :=
β¨lt_or_gt_of_ne, Ξ»o, or.elim o ne_of_lt ne_of_gtβ©
lemma lt_iff_not_ge [linear_order Ξ±] (x y : Ξ±) : x < y β Β¬ x β₯ y :=
β¨not_le_of_gt, lt_of_not_geβ©
instance decidable_lt_of_decidable_le [preorder Ξ±]
[decidable_rel ((β€) : Ξ± β Ξ± β Prop)] :
decidable_rel ((<) : Ξ± β Ξ± β Prop)
| a b :=
if hab : a β€ b then
if hba : b β€ a then
is_false $ Ξ» hab', not_le_of_gt hab' hba
else
is_true $ lt_of_le_not_le hab hba
else
is_false $ Ξ» hab', hab (le_of_lt hab')
instance decidable_eq_of_decidable_le [partial_order Ξ±]
[decidable_rel ((β€) : Ξ± β Ξ± β Prop)] :
decidable_eq Ξ±
| a b :=
if hab : a β€ b then
if hba : b β€ a then
is_true (le_antisymm hab hba)
else
is_false (Ξ» heq, hba (heq βΈ le_refl _))
else
is_false (Ξ» heq, hab (heq βΈ le_refl _))
class decidable_linear_order (Ξ± : Type u) extends linear_order Ξ± :=
(decidable_le : decidable_rel (β€))
(decidable_eq : decidable_eq Ξ± := @decidable_eq_of_decidable_le _ _ decidable_le)
(decidable_lt : decidable_rel ((<) : Ξ± β Ξ± β Prop) :=
@decidable_lt_of_decidable_le _ _ decidable_le)
instance [decidable_linear_order Ξ±] (a b : Ξ±) : decidable (a < b) :=
decidable_linear_order.decidable_lt Ξ± a b
instance [decidable_linear_order Ξ±] (a b : Ξ±) : decidable (a β€ b) :=
decidable_linear_order.decidable_le Ξ± a b
instance [decidable_linear_order Ξ±] (a b : Ξ±) : decidable (a = b) :=
decidable_linear_order.decidable_eq Ξ± a b
lemma eq_or_lt_of_not_lt [decidable_linear_order Ξ±] {a b : Ξ±} (h : Β¬ a < b) : a = b β¨ b < a :=
if hβ : a = b then or.inl hβ
else or.inr (lt_of_not_ge (Ξ» hge, h (lt_of_le_of_ne hge hβ)))
instance [decidable_linear_order Ξ±] : is_total_preorder Ξ± (β€) :=
{trans := @le_trans _ _, total := le_total}
/- TODO(Leo): decide whether we should keep this instance or not -/
instance is_strict_weak_order_of_decidable_linear_order [decidable_linear_order Ξ±] : is_strict_weak_order Ξ± (<) :=
is_strict_weak_order_of_is_total_preorder lt_iff_not_ge
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.