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