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
fa980d3207fb197b05aab18c33e61bd353b61511
367134ba5a65885e863bdc4507601606690974c1
/src/control/lawful_fix.lean
02e31140c00c22709adc517189bebbe4859e2189
[ "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
7,818
lean
/- Copyright (c) 2020 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Simon Hudon -/ import tactic.apply import control.fix import order.omega_complete_partial_order /-! # Lawful fixed point operators This module defines the laws required of a `has_fix` instance, using the theory of omega complete partial orders (ωCPO). Proofs of the lawfulness of all `has_fix` instances in `control.fix` are provided. ## Main definition * class `lawful_fix` -/ universes u v open_locale classical variables {α : Type*} {β : α → Type*} open omega_complete_partial_order /-- Intuitively, a fixed point operator `fix` is lawful if it satisfies `fix f = f (fix f)` for all `f`, but this is inconsistent / uninteresting in most cases due to the existence of "exotic" functions `f`, such as the function that is defined iff its argument is not, familiar from the halting problem. Instead, this requirement is limited to only functions that are `continuous` in the sense of `ω`-complete partial orders, which excludes the example because it is not monotone (making the input argument less defined can make `f` more defined). -/ class lawful_fix (α : Type*) [omega_complete_partial_order α] extends has_fix α := (fix_eq : ∀ {f : α →ₘ α}, continuous f → has_fix.fix f = f (has_fix.fix f)) lemma lawful_fix.fix_eq' {α} [omega_complete_partial_order α] [lawful_fix α] {f : α → α} (hf : continuous' f) : has_fix.fix f = f (has_fix.fix f) := lawful_fix.fix_eq (continuous.to_bundled _ hf) namespace roption open roption nat nat.upto namespace fix variables (f : (Π a, roption $ β a) →ₘ (Π a, roption $ β a)) lemma approx_mono' {i : ℕ} : fix.approx f i ≤ fix.approx f (succ i) := begin induction i, dsimp [approx], apply @bot_le _ _ (f ⊥), intro, apply f.monotone, apply i_ih end lemma approx_mono ⦃i j : ℕ⦄ (hij : i ≤ j) : approx f i ≤ approx f j := begin induction j, cases hij, refine @le_refl _ _ _, cases hij, apply @le_refl _ _ _, apply @le_trans _ _ _ (approx f j_n) _ (j_ih ‹_›), apply approx_mono' f end lemma mem_iff (a : α) (b : β a) : b ∈ roption.fix f a ↔ ∃ i, b ∈ approx f i a := begin by_cases h₀ : ∃ (i : ℕ), (approx f i a).dom, { simp only [roption.fix_def f h₀], split; intro hh, exact ⟨_,hh⟩, have h₁ := nat.find_spec h₀, rw [dom_iff_mem] at h₁, cases h₁ with y h₁, replace h₁ := approx_mono' f _ _ h₁, suffices : y = b, subst this, exact h₁, cases hh with i hh, revert h₁, generalize : (succ (nat.find h₀)) = j, intro, wlog : i ≤ j := le_total i j using [i j b y,j i y b], replace hh := approx_mono f case _ _ hh, apply roption.mem_unique h₁ hh }, { simp only [fix_def' ⇑f h₀, not_exists, false_iff, not_mem_none], simp only [dom_iff_mem, not_exists] at h₀, intro, apply h₀ } end lemma approx_le_fix (i : ℕ) : approx f i ≤ roption.fix f := assume a b hh, by { rw [mem_iff f], exact ⟨_,hh⟩ } lemma exists_fix_le_approx (x : α) : ∃ i, roption.fix f x ≤ approx f i x := begin by_cases hh : ∃ i b, b ∈ approx f i x, { rcases hh with ⟨i,b,hb⟩, existsi i, intros b' h', have hb' := approx_le_fix f i _ _ hb, have hh := roption.mem_unique h' hb', subst hh, exact hb }, { simp only [not_exists] at hh, existsi 0, intros b' h', simp only [mem_iff f] at h', cases h' with i h', cases hh _ _ h' } end include f /-- The series of approximations of `fix f` (see `approx`) as a `chain` -/ def approx_chain : chain (Π a, roption $ β a) := ⟨approx f, approx_mono f⟩ lemma le_f_of_mem_approx {x} (hx : x ∈ approx_chain f) : x ≤ f x := begin revert hx, simp [(∈)], intros i hx, subst x, apply approx_mono' end lemma approx_mem_approx_chain {i} : approx f i ∈ approx_chain f := stream.mem_of_nth_eq rfl end fix open fix variables {α} variables (f : (Π a, roption $ β a) →ₘ (Π a, roption $ β a)) open omega_complete_partial_order open roption (hiding ωSup) nat open nat.upto omega_complete_partial_order lemma fix_eq_ωSup : roption.fix f = ωSup (approx_chain f) := begin apply le_antisymm, { intro x, cases exists_fix_le_approx f x with i hx, transitivity' approx f i.succ x, { transitivity', apply hx, apply approx_mono' f }, apply' le_ωSup_of_le i.succ, dsimp [approx], refl', }, { apply ωSup_le _ _ _, simp only [fix.approx_chain, preorder_hom.coe_fun_mk], intros y x, apply approx_le_fix f }, end lemma fix_le {X : Π a, roption $ β a} (hX : f X ≤ X) : roption.fix f ≤ X := begin rw fix_eq_ωSup f, apply ωSup_le _ _ _, simp only [fix.approx_chain, preorder_hom.coe_fun_mk], intros i, induction i, dsimp [fix.approx], apply' bot_le, transitivity' f X, apply f.monotone i_ih, apply hX end variables {f} (hc : continuous f) include hc lemma fix_eq : roption.fix f = f (roption.fix f) := begin rw [fix_eq_ωSup f,hc], apply le_antisymm, { apply ωSup_le_ωSup_of_le _, intros i, existsi [i], intro x, -- intros x y hx, apply le_f_of_mem_approx _ ⟨i, rfl⟩, }, { apply ωSup_le_ωSup_of_le _, intros i, existsi i.succ, refl', } end end roption namespace roption /-- `to_unit` as a monotone function -/ @[simps] def to_unit_mono (f : roption α →ₘ roption α) : (unit → roption α) →ₘ (unit → roption α) := { to_fun := λ x u, f (x u), monotone' := λ x y (h : x ≤ y) u, f.monotone $ h u } lemma to_unit_cont (f : roption α →ₘ roption α) (hc : continuous f) : continuous (to_unit_mono f) | c := begin ext ⟨⟩ : 1, dsimp [omega_complete_partial_order.ωSup], erw [hc, chain.map_comp], refl end noncomputable instance : lawful_fix (roption α) := ⟨λ f hc, show roption.fix (to_unit_mono f) () = _, by rw roption.fix_eq (to_unit_cont f hc); refl⟩ end roption open sigma namespace pi noncomputable instance {β} : lawful_fix (α → roption β) := ⟨λ f, roption.fix_eq⟩ variables {γ : Π a : α, β a → Type*} section monotone variables (α β γ) /-- `sigma.curry` as a monotone function. -/ @[simps] def monotone_curry [∀ x y, preorder $ γ x y] : (Π x : Σ a, β a, γ x.1 x.2) →ₘ (Π a (b : β a), γ a b) := { to_fun := curry, monotone' := λ x y h a b, h ⟨a,b⟩ } /-- `sigma.uncurry` as a monotone function. -/ @[simps] def monotone_uncurry [∀ x y, preorder $ γ x y] : (Π a (b : β a), γ a b) →ₘ (Π x : Σ a, β a, γ x.1 x.2) := { to_fun := uncurry, monotone' := λ x y h a, h a.1 a.2 } variables [∀ x y, omega_complete_partial_order $ γ x y] open omega_complete_partial_order.chain lemma continuous_curry : continuous $ monotone_curry α β γ := λ c, by { ext x y, dsimp [curry,ωSup], rw [map_comp,map_comp], refl } lemma continuous_uncurry : continuous $ monotone_uncurry α β γ := λ c, by { ext x y, dsimp [uncurry,ωSup], rw [map_comp,map_comp], refl } end monotone open has_fix instance [has_fix $ Π x : sigma β, γ x.1 x.2] : has_fix (Π x (y : β x), γ x y) := ⟨ λ f, curry (fix $ uncurry ∘ f ∘ curry) ⟩ variables [∀ x y, omega_complete_partial_order $ γ x y] section curry variables {f : (Π x (y : β x), γ x y) →ₘ (Π x (y : β x), γ x y)} variables (hc : continuous f) lemma uncurry_curry_continuous : continuous $ (monotone_uncurry α β γ).comp $ f.comp $ monotone_curry α β γ := continuous_comp _ _ (continuous_comp _ _ (continuous_curry _ _ _) hc) (continuous_uncurry _ _ _) end curry instance pi.lawful_fix' [lawful_fix $ Π x : sigma β, γ x.1 x.2] : lawful_fix (Π x y, γ x y) := { fix_eq := λ f hc, begin dsimp [fix], conv { to_lhs, erw [lawful_fix.fix_eq (uncurry_curry_continuous hc)] }, refl, end, } end pi
d971688c1652db58a029119e25491b179ab6536a
624f6f2ae8b3b1adc5f8f67a365c51d5126be45a
/tests/lean/inst.lean
6f20b2a9804d1618a3f02d8a88e3b34faf637cd0
[ "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
500
lean
import Init.Lean.Expr open Lean def tst : IO Unit := do let f := mkConst `f; let x := mkBVar 0; let y := mkBVar 1; let t := mkApp (mkApp (mkApp f x) y) x; let a := mkConst `a; let b := mkApp f (mkConst `b); let c := mkConst `c; IO.println t; IO.println (t.instantiate #[a, b]); IO.println (t.instantiateRange 0 2 #[a, b]); IO.println (t.instantiateRange 2 4 #[c, c, a, b, c]); IO.println (t.instantiateRev #[a, b]); IO.println (t.instantiate #[a]); IO.println (t.instantiate1 a); pure () #eval tst
9a1d8d0d85efa6fce48aeb9ac824c838c4ebd6cb
5756a081670ba9c1d1d3fca7bd47cb4e31beae66
/Mathport/Syntax/Translate/Tactic/Mathlib/Hint.lean
1627e5f0740b7c0dc8b9175e711ed5c6a3170fba
[ "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
743
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 open Lean namespace Mathport.Translate.Tactic open AST3 Parser -- # tactic.hint @[tr_user_attr hint_tactic] def trHintAttr := tagAttr `hint_tactic @[tr_user_cmd «add_hint_tactic»] def trAddHintTactic : Parse1 Syntax.Command := parse1 (pExpr *> withInput pExpr) fun (e, _) => do let tac ← match e with | ⟨_, Expr.«`[]» tacs⟩ => trIdTactic ⟨false, none, none, tacs⟩ | _ => warn! "unsupported (impossible)" `(command| add_hint_tactic $tac) @[tr_tactic hint] def trHint : TacM Syntax.Tactic := `(tactic| hint)
47dfbe1962ead286ef9ef469e220a0ce3d662a8e
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/number_theory/function_field.lean
d2424fdcc35816d41de8aa712bb3c35a4f684e00
[ "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,290
lean
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Ashvni Narayanan -/ import field_theory.ratfunc import ring_theory.algebraic import ring_theory.dedekind_domain import ring_theory.integrally_closed /-! # Function fields This file defines a function field and the ring of integers corresponding to it. ## Main definitions - `function_field Fq F` states that `F` is a function field over the (finite) field `Fq`, i.e. it is a finite extension of the field of rational functions in one variable over `Fq`. - `function_field.ring_of_integers` defines the ring of integers corresponding to a function field as the integral closure of `polynomial Fq` in the function field. ## Implementation notes The definitions that involve a field of fractions choose a canonical field of fractions, but are independent of that choice. We also omit assumptions like `finite Fq` or `is_scalar_tower (polynomial Fq) (fraction_ring (polynomial Fq)) F` in definitions, adding them back in lemmas when they are needed. ## References * [D. Marcus, *Number Fields*][marcus1977number] * [J.W.S. Cassels, A. Frölich, *Algebraic Number Theory*][cassels1967algebraic] * [P. Samuel, *Algebraic Theory of Numbers*][samuel1970algebraic] ## Tags function field, ring of integers -/ noncomputable theory variables (Fq F : Type) [field Fq] [field F] /-- `F` is a function field over the finite field `Fq` if it is a finite extension of the field of rational functions in one variable over `Fq`. Note that `F` can be a function field over multiple, non-isomorphic, `Fq`. -/ abbreviation function_field [algebra (ratfunc Fq) F] : Prop := finite_dimensional (ratfunc Fq) F /-- `F` is a function field over `Fq` iff it is a finite extension of `Fq(t)`. -/ protected lemma function_field_iff (Fqt : Type*) [field Fqt] [algebra (polynomial Fq) Fqt] [is_fraction_ring (polynomial Fq) Fqt] [algebra (ratfunc Fq) F] [algebra Fqt F] [algebra (polynomial Fq) F] [is_scalar_tower (polynomial Fq) Fqt F] [is_scalar_tower (polynomial Fq) (ratfunc Fq) F] : function_field Fq F ↔ finite_dimensional Fqt F := begin let e := is_localization.alg_equiv (non_zero_divisors (polynomial Fq)) (ratfunc Fq) Fqt, have : ∀ c (x : F), e c • x = c • x, { intros c x, rw [algebra.smul_def, algebra.smul_def], congr, refine congr_fun _ c, refine is_localization.ext (non_zero_divisors (polynomial Fq)) _ _ _ _ _ _ _; intros; simp only [alg_equiv.map_one, ring_hom.map_one, alg_equiv.map_mul, ring_hom.map_mul, alg_equiv.commutes, ← is_scalar_tower.algebra_map_apply], }, split; intro h; resetI, { let b := finite_dimensional.fin_basis (ratfunc Fq) F, exact finite_dimensional.of_fintype_basis (b.map_coeffs e this) }, { let b := finite_dimensional.fin_basis Fqt F, refine finite_dimensional.of_fintype_basis (b.map_coeffs e.symm _), intros c x, convert (this (e.symm c) x).symm, simp only [e.apply_symm_apply] }, end namespace function_field /-- The function field analogue of `number_field.ring_of_integers`: `function_field.ring_of_integers Fq Fqt F` is the integral closure of `Fq[t]` in `F`. We don't actually assume `F` is a function field over `Fq` in the definition, only when proving its properties. -/ def ring_of_integers [algebra (polynomial Fq) F] := integral_closure (polynomial Fq) F namespace ring_of_integers variables [algebra (polynomial Fq) F] instance : is_domain (ring_of_integers Fq F) := (ring_of_integers Fq F).is_domain instance : is_integral_closure (ring_of_integers Fq F) (polynomial Fq) F := integral_closure.is_integral_closure _ _ variables [algebra (ratfunc Fq) F] [function_field Fq F] variables [is_scalar_tower (polynomial Fq) (ratfunc Fq) F] instance : is_fraction_ring (ring_of_integers Fq F) F := integral_closure.is_fraction_ring_of_finite_extension (ratfunc Fq) F instance : is_integrally_closed (ring_of_integers Fq F) := integral_closure.is_integrally_closed_of_finite_extension (ratfunc Fq) instance [is_separable (ratfunc Fq) F] : is_dedekind_domain (ring_of_integers Fq F) := is_integral_closure.is_dedekind_domain (polynomial Fq) (ratfunc Fq) F _ end ring_of_integers end function_field
bd12fa7cd29df6a3c24cf0eb2bd16f09adbdb68b
4b846d8dabdc64e7ea03552bad8f7fa74763fc67
/library/init/data/array.lean
78873cc8ad44b5d3035a9fc7157b8a713d9228d1
[ "Apache-2.0" ]
permissive
pacchiano/lean
9324b33f3ac3b5c5647285160f9f6ea8d0d767dc
fdadada3a970377a6df8afcd629a6f2eab6e84e8
refs/heads/master
1,611,357,380,399
1,489,870,101,000
1,489,870,101,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
3,729
lean
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ prelude import init.data.nat universes u w structure array (α : Type u) (n : nat) := (data : fin n → α) def mk_array {α} (n) (v : α) : array α n := {data := λ _, v} namespace array variables {α : Type u} {β : Type w} {n : nat} def read (a : array α n) (i : fin n) : α := a^.data i def read' [inhabited α] (a : array α n) (i : nat) : α := if h : i < n then a^.read ⟨i,h⟩ else default α def write (a : array α n) (i : fin n) (v : α) : array α n := {data := λ j, if i = j then v else a^.read j} def write' (a : array α n) (i : nat) (v : α) : array α n := if h : i < n then a^.write ⟨i, h⟩ v else a lemma push_back_idx {j n} : j < n + 1 → j ≠ n → j < n := λ h₁ h₂, nat.lt_of_le_and_ne (nat.le_of_lt_succ h₁) h₂ def push_back (a : array α n) (v : α) : array α (n+1) := {data := λ ⟨j, h₁⟩, if h₂ : j = n then v else a^.read ⟨j, push_back_idx h₁ h₂⟩} lemma pop_back_idx {j n} : j < n → j < n + 1 := λ h, nat.lt.step h def pop_back (a : array α (n+1)) : array α n := {data := λ ⟨j, h⟩, a^.read ⟨j, pop_back_idx h⟩} lemma lt_aux_1 {a b c : nat} : a + c < b → a < b := λ h, lt_of_le_of_lt (nat.le_add_right a c) h lemma lt_aux_2 {n} : n > 0 → n - 1 < n := assume h, have h₁ : 1 > 0, from dec_trivial, nat.sub_lt h h₁ lemma lt_aux_3 {n i} : i + 1 < n → n - 2 - i < n := assume h, have n > 0, from lt.trans (nat.zero_lt_succ i) h, have n - 2 < n, from nat.sub_lt this (dec_trivial), lt_of_le_of_lt (nat.sub_le _ _) this def foreach_aux (f : fin n → α → α) : Π (i : nat), i < n → array α n → array α n | 0 h a := let i : fin n := ⟨n - 1, lt_aux_2 h⟩ in a^.write i (f i (a^.read i)) | (j+1) h a := let i : fin n := ⟨n - 2 - j, lt_aux_3 h⟩ in foreach_aux j (lt_aux_1 h) (a^.write i (f i (a^.read i))) def foreach : Π {n}, array α n → (fin n → α → α) → array α n | 0 a f:= a | (n+1) a f := foreach_aux f n (nat.lt_succ_self _) a def map {α} {n} (f : α → α) (a : array α n) : array α n := foreach a (λ _, f) def map₂ {α} {n} (f : α → α → α) (a b : array α n) : array α n := foreach b (λ i, f (a^.read i)) def iterate_aux (f : fin n → α → β → β) : Π (i : nat), i < n → array α n → β → β | 0 h a b := let i : fin n := ⟨n - 1, lt_aux_2 h⟩ in f i (a^.read i) b | (j+1) h a b := let i : fin n := ⟨n - 2 - j, lt_aux_3 h⟩ in iterate_aux j (lt_aux_1 h) a (f i (a^.read i) b) def iterate : Π {n}, array α n → β → (fin n → α → β → β) → β | 0 a b fn := b | (n+1) a b fn := iterate_aux fn n (nat.lt_succ_self _) a b def foldl {n} (a : array α n) (b : β) (f : α → β → β) : β := iterate a b (λ _, f) def rev_iterate_aux (f : fin n → α → β → β) : Π (i : nat), i < n → array α n → β → β | 0 h a b := let z : fin n := ⟨0, h⟩ in f z (a^.read z) b | (j+1) h a b := let i : fin n := ⟨j+1, h⟩ in rev_iterate_aux j (lt_aux_1 h) a (f i (a^.read i) b) def rev_iterate : Π {n : nat}, array α n → β → (fin n → α → β → β) → β | 0 a b fn := b | (n+1) a b fn := rev_iterate_aux fn n (nat.lt_succ_self _) a b def to_list (a : array α n) : list α := a^.rev_iterate [] (λ _ v l, v :: l) instance [has_to_string α] : has_to_string (array α n) := ⟨to_string ∘ to_list⟩ meta instance [has_to_format α] : has_to_format (array α n) := ⟨to_fmt ∘ to_list⟩ meta instance [has_to_tactic_format α] : has_to_tactic_format (array α n) := ⟨tactic.pp ∘ to_list⟩ end array
bab67c022940dfc0f51933a4d45c908d4affdd29
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/run/let2.lean
07535a5b0586f3029b0383d51ebb39183452c8d7
[ "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
451
lean
definition b := let a := true ∧ true, a := a ∧ a, a := a ∧ a, a := a ∧ a, a := a ∧ a, a := a ∧ a, a := a ∧ a, a := a ∧ a, a := a ∧ a, a := a ∧ a, a := a ∧ a, a := a ∧ a, a := a ∧ a, a := a ∧ a, a := a ∧ a, a := a ∧ a, a := a ∧ a in a #check b
9ae1eca2c464464dd99c340f31db8c2545387a56
b3fced0f3ff82d577384fe81653e47df68bb2fa1
/src/measure_theory/probability_mass_function.lean
7682dc2b0378113e2ca0aebe5c19f0489e0f0050
[ "Apache-2.0" ]
permissive
ratmice/mathlib
93b251ef5df08b6fd55074650ff47fdcc41a4c75
3a948a6a4cd5968d60e15ed914b1ad2f4423af8d
refs/heads/master
1,599,240,104,318
1,572,981,183,000
1,572,981,183,000
219,830,178
0
0
Apache-2.0
1,572,980,897,000
1,572,980,896,000
null
UTF-8
Lean
false
false
4,784
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 Probability mass function -- discrete probability measures -/ import topology.instances.nnreal topology.instances.ennreal topology.algebra.infinite_sum noncomputable theory variables {α : Type*} {β : Type*} {γ : Type*} open_locale classical /-- Probability mass functions, i.e. discrete probability measures -/ def {u} pmf (α : Type u) : Type u := { f : α → nnreal // has_sum f 1 } namespace pmf instance : has_coe_to_fun (pmf α) := ⟨λp, α → nnreal, λp a, p.1 a⟩ @[extensionality] protected lemma ext : ∀{p q : pmf α}, (∀a, p a = q a) → p = q | ⟨f, hf⟩ ⟨g, hg⟩ eq := subtype.eq $ funext eq lemma has_sum_coe_one (p : pmf α) : has_sum p 1 := p.2 lemma summable_coe (p : pmf α) : summable p := summable_spec p.has_sum_coe_one @[simp] lemma tsum_coe (p : pmf α) : (∑a, p a) = 1 := tsum_eq_has_sum p.has_sum_coe_one def support (p : pmf α) : set α := {a | p.1 a ≠ 0} def pure (a : α) : pmf α := ⟨λa', if a' = a then 1 else 0, has_sum_ite_eq _ _⟩ @[simp] lemma pure_apply (a a' : α) : pure a a' = (if a' = a then 1 else 0) := rfl instance [inhabited α] : inhabited (pmf α) := ⟨pure (default α)⟩ lemma coe_le_one (p : pmf α) (a : α) : p a ≤ 1 := has_sum_le (by intro b; split_ifs; simp [h]; exact le_refl _) (has_sum_ite_eq a (p a)) p.2 protected lemma bind.summable (p : pmf α) (f : α → pmf β) (b : β) : summable (λa:α, p a * f a b) := begin refine nnreal.summable_of_le (assume a, _) p.summable_coe, suffices : p a * f a b ≤ p a * 1, { simpa }, exact mul_le_mul_of_nonneg_left ((f a).coe_le_one _) (p a).2 end def bind (p : pmf α) (f : α → pmf β) : pmf β := ⟨λb, (∑a, p a * f a b), begin simp [ennreal.has_sum_coe.symm, (ennreal.tsum_coe (bind.summable p f _)).symm], rw [has_sum_iff_of_summable ennreal.summable, ennreal.tsum_comm], simp [ennreal.mul_tsum, (ennreal.tsum_coe (f _).summable_coe), ennreal.tsum_coe p.summable_coe] end⟩ @[simp] lemma bind_apply (p : pmf α) (f : α → pmf β) (b : β) : p.bind f b = (∑a, p a * f a b) := rfl lemma coe_bind_apply (p : pmf α) (f : α → pmf β) (b : β) : (p.bind f b : ennreal) = (∑a, p a * f a b) := eq.trans (ennreal.tsum_coe $ bind.summable p f b).symm $ by simp @[simp] lemma pure_bind (a : α) (f : α → pmf β) : (pure a).bind f = f a := have ∀b a', ite (a' = a) 1 0 * f a' b = ite (a' = a) (f a b) 0, from assume b a', by split_ifs; simp; subst h; simp, by ext b; simp [this] @[simp] lemma bind_pure (p : pmf α) : p.bind pure = p := have ∀a a', (p a * ite (a' = a) 1 0) = ite (a = a') (p a') 0, from assume a a', begin split_ifs; try { subst a }; try { subst a' }; simp * at * end, by ext b; simp [this] @[simp] lemma bind_bind (p : pmf α) (f : α → pmf β) (g : β → pmf γ) : (p.bind f).bind g = p.bind (λa, (f a).bind g) := begin ext b, simp only [ennreal.coe_eq_coe.symm, coe_bind_apply, ennreal.mul_tsum.symm, ennreal.tsum_mul.symm], rw [ennreal.tsum_comm], simp [mul_assoc, mul_left_comm, mul_comm] end lemma bind_comm (p : pmf α) (q : pmf β) (f : α → β → pmf γ) : p.bind (λa, q.bind (f a)) = q.bind (λb, p.bind (λa, f a b)) := begin ext b, simp only [ennreal.coe_eq_coe.symm, coe_bind_apply, ennreal.mul_tsum.symm, ennreal.tsum_mul.symm], rw [ennreal.tsum_comm], simp [mul_assoc, mul_left_comm, mul_comm] end def map (f : α → β) (p : pmf α) : pmf β := bind p (pure ∘ f) lemma bind_pure_comp (f : α → β) (p : pmf α) : bind p (pure ∘ f) = map f p := rfl lemma map_id (p : pmf α) : map id p = p := by simp [map] lemma map_comp (p : pmf α) (f : α → β) (g : β → γ) : (p.map f).map g = p.map (g ∘ f) := by simp [map] lemma pure_map (a : α) (f : α → β) : (pure a).map f = pure (f a) := by simp [map] def seq (f : pmf (α → β)) (p : pmf α) : pmf β := f.bind (λm, p.bind $ λa, pure (m a)) def of_multiset (s : multiset α) (hs : s ≠ 0) : pmf α := ⟨λa, s.count a / s.card, have s.to_finset.sum (λa, (s.count a : ℝ) / s.card) = 1, by simp [div_eq_inv_mul, finset.mul_sum.symm, (finset.sum_nat_cast _ _).symm, hs], have s.to_finset.sum (λa, (s.count a : nnreal) / s.card) = 1, by rw [← nnreal.eq_iff, nnreal.coe_one, ← this, nnreal.sum_coe]; simp, begin rw ← this, apply has_sum_sum_of_ne_finset_zero, simp {contextual := tt}, end⟩ def of_fintype [fintype α] (f : α → nnreal) (h : finset.univ.sum f = 1) : pmf α := ⟨f, h ▸ has_sum_sum_of_ne_finset_zero (by simp)⟩ def bernoulli (p : nnreal) (h : p ≤ 1) : pmf bool := of_fintype (λb, cond b p (1 - p)) (nnreal.eq $ by simp [h]) end pmf
1c87e2ea317d8c45d81998e7ec8e234dde0d12c5
5a5e1bb8063d7934afac91f30aa17c715821040b
/lean3SOS/src/float/div.lean
bd3646734ec5ecd4d97b176c7b0dc02f11645161
[]
no_license
ramonfmir/leanSOS
1883392d73710db5c6e291a2abd03a6c5b44a42b
14b50713dc887f6d408b7b2bce1f8af5bb619958
refs/heads/main
1,683,348,826,105
1,622,056,982,000
1,622,056,982,000
341,232,766
1
0
null
null
null
null
UTF-8
Lean
false
false
2,023
lean
import float.basic import float.round open float variable (prec : ℕ) def divl (x y : 𝔽) : 𝔽 := round_down prec (eval x / eval y) def divr (x y : 𝔽) : 𝔽 := round_up prec (eval x / eval y) meta def div_rat' (x y : 𝔽) : ℚ := let x' := quot.unquot x, y' := quot.unquot y in if x'.e ≤ y'.e then rat.mk (x'.m) (y'.m * 2 ^ int.to_nat (y'.e - x'.e)) else rat.mk (x'.m * 2 ^ int.to_nat (x'.e - y'.e)) (y'.m) meta def divl' (x y : 𝔽) : 𝔽 := round_down prec (div_rat' x y) meta def divr' (x y : 𝔽) : 𝔽 := round_up prec (div_rat' x y) --instance : has_div 𝔽 := ⟨divl 10⟩ -- Fixed precision for now meta instance : has_div 𝔽 := ⟨divl' 10⟩ -- Fixed precision for now -- Lemmas. lemma divl_bound (x y : 𝔽) : eval (divl prec x y) ≤ eval x / eval y := begin simp [divl, round_down, eval_mk], have h : 0 < ((2 : ℚ) ^ prec), { norm_num, }, rw [mul_inv_le_iff h, mul_comm], exact floor_le _, end lemma divr_bound (x y : 𝔽) : eval x / eval y ≤ eval (divr prec x y) := begin simp [divr, round_up, eval_mk], have h : 0 < ((2 : ℚ) ^ prec), { norm_num, }, rw [←mul_le_mul_right h, mul_assoc, inv_mul_cancel (ne_of_gt h), mul_one], exact le_ceil _, end lemma divl_diff_lb (x y : 𝔽) : 0 ≤ (eval x / eval y) - eval (divl prec x y) := sub_nonneg_of_le (divl_bound prec x y) lemma divl_diff_ub (x y : 𝔽) : (eval x / eval y) - eval (divl prec x y) ≤ 2 ^ (-(prec : ℤ)) := begin have h := divr_bound prec x y, replace h := sub_le_sub_right h (eval (divl prec x y)), apply le_trans h, simp only [divr, divl], rw [←eval_sub], have h1 : 2 ^ (-(prec : ℤ)) = eval (float.mk 1 (-prec)), { simp [eval_mk], }, rw h1, exact round_up_diff_round_down prec _, end -- #eval divl 10 (mk 50 0) (mk 3 2) -- Isabelle version: -- lift_definition float_divr :: "nat => float => float => float" is -- "λ(prec::nat) a b. round_up (prec + ⌊ log 2 ¦b¦ ⌋ - ⌊ log 2 ¦a¦ ⌋) (a / b)" by simp -- TODO: Precision needs to change?
e829bfd342c927f6cbfd5bd74f515c9a65669333
6094e25ea0b7699e642463b48e51b2ead6ddc23f
/library/data/int/basic.lean
f549ef27ea858f364baaee69e0f3a2b7d014c92e
[ "Apache-2.0" ]
permissive
gbaz/lean
a7835c4e3006fbbb079e8f8ffe18aacc45adebfb
a501c308be3acaa50a2c0610ce2e0d71becf8032
refs/heads/master
1,611,198,791,433
1,451,339,111,000
1,451,339,111,000
48,713,797
0
0
null
1,451,338,939,000
1,451,338,939,000
null
UTF-8
Lean
false
false
25,859
lean
/- Copyright (c) 2014 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Jeremy Avigad The integers, with addition, multiplication, and subtraction. The representation of the integers is chosen to compute efficiently. To faciliate proving things about these operations, we show that the integers are a quotient of ℕ × ℕ with the usual equivalence relation, ≡, and functions abstr : ℕ × ℕ → ℤ repr : ℤ → ℕ × ℕ satisfying: abstr_repr (a : ℤ) : abstr (repr a) = a repr_abstr (p : ℕ × ℕ) : repr (abstr p) ≡ p abstr_eq (p q : ℕ × ℕ) : p ≡ q → abstr p = abstr q For example, to "lift" statements about add to statements about padd, we need to prove the following: repr_add (a b : ℤ) : repr (a + b) = padd (repr a) (repr b) padd_congr (p p' q q' : ℕ × ℕ) (H1 : p ≡ p') (H2 : q ≡ q') : padd p q ≡ p' q' -/ import data.nat.sub algebra.relation data.prod open eq.ops open prod relation nat open decidable binary /- the type of integers -/ inductive int : Type := | of_nat : nat → int | neg_succ_of_nat : nat → int notation `ℤ` := int definition int.of_num [coercion] [reducible] [constructor] (n : num) : ℤ := int.of_nat (nat.of_num n) namespace int attribute int.of_nat [coercion] notation `-[1+ ` n `]` := int.neg_succ_of_nat n -- for pretty-printing output protected definition prio : num := num.pred nat.prio definition int_has_zero [reducible] [instance] [priority int.prio] : has_zero int := has_zero.mk (of_nat 0) definition int_has_one [reducible] [instance] [priority int.prio] : has_one int := has_one.mk (of_nat 1) theorem of_nat_zero : of_nat (0:nat) = (0:int) := rfl theorem of_nat_one : of_nat (1:nat) = (1:int) := rfl /- definitions of basic functions -/ definition neg_of_nat : ℕ → ℤ | 0 := 0 | (succ m) := -[1+ m] definition sub_nat_nat (m n : ℕ) : ℤ := match (n - m : nat) with | 0 := of_nat (m - n) -- m ≥ n | (succ k) := -[1+ k] -- m < n, and n - m = succ k end protected definition neg (a : ℤ) : ℤ := int.cases_on a neg_of_nat succ protected definition add : ℤ → ℤ → ℤ | (of_nat m) (of_nat n) := m + n | (of_nat m) -[1+ n] := sub_nat_nat m (succ n) | -[1+ m] (of_nat n) := sub_nat_nat n (succ m) | -[1+ m] -[1+ n] := neg_of_nat (succ m + succ n) protected definition mul : ℤ → ℤ → ℤ | (of_nat m) (of_nat n) := m * n | (of_nat m) -[1+ n] := neg_of_nat (m * succ n) | -[1+ m] (of_nat n) := neg_of_nat (succ m * n) | -[1+ m] -[1+ n] := succ m * succ n /- notation -/ definition int_has_add [reducible] [instance] [priority int.prio] : has_add int := has_add.mk int.add definition int_has_neg [reducible] [instance] [priority int.prio] : has_neg int := has_neg.mk int.neg definition int_has_mul [reducible] [instance] [priority int.prio] : has_mul int := has_mul.mk int.mul lemma mul_of_nat_of_nat (m n : nat) : of_nat m * of_nat n = of_nat (m * n) := rfl lemma mul_of_nat_neg_succ_of_nat (m n : nat) : of_nat m * -[1+ n] = neg_of_nat (m * succ n) := rfl lemma mul_neg_succ_of_nat_of_nat (m n : nat) : -[1+ m] * of_nat n = neg_of_nat (succ m * n) := rfl lemma mul_neg_succ_of_nat_neg_succ_of_nat (m n : nat) : -[1+ m] * -[1+ n] = succ m * succ n := rfl /- some basic functions and properties -/ theorem of_nat.inj {m n : ℕ} (H : of_nat m = of_nat n) : m = n := int.no_confusion H imp.id theorem eq_of_of_nat_eq_of_nat {m n : ℕ} (H : of_nat m = of_nat n) : m = n := of_nat.inj H theorem of_nat_eq_of_nat_iff (m n : ℕ) : of_nat m = of_nat n ↔ m = n := iff.intro of_nat.inj !congr_arg theorem neg_succ_of_nat.inj {m n : ℕ} (H : neg_succ_of_nat m = neg_succ_of_nat n) : m = n := int.no_confusion H imp.id theorem neg_succ_of_nat_eq (n : ℕ) : -[1+ n] = -(n + 1) := rfl private definition has_decidable_eq₂ : Π (a b : ℤ), decidable (a = b) | (of_nat m) (of_nat n) := decidable_of_decidable_of_iff (nat.has_decidable_eq m n) (iff.symm (of_nat_eq_of_nat_iff m n)) | (of_nat m) -[1+ n] := inr (by contradiction) | -[1+ m] (of_nat n) := inr (by contradiction) | -[1+ m] -[1+ n] := if H : m = n then inl (congr_arg neg_succ_of_nat H) else inr (not.mto neg_succ_of_nat.inj H) definition has_decidable_eq [instance] [priority int.prio] : decidable_eq ℤ := has_decidable_eq₂ theorem of_nat_add (n m : nat) : of_nat (n + m) = of_nat n + of_nat m := rfl theorem of_nat_succ (n : ℕ) : of_nat (succ n) = of_nat n + 1 := rfl theorem of_nat_mul (n m : ℕ) : of_nat (n * m) = of_nat n * of_nat m := rfl theorem sub_nat_nat_of_ge {m n : ℕ} (H : m ≥ n) : sub_nat_nat m n = of_nat (m - n) := show sub_nat_nat m n = nat.cases_on 0 (m -[nat] n) _, from (sub_eq_zero_of_le H) ▸ rfl section local attribute sub_nat_nat [reducible] theorem sub_nat_nat_of_lt {m n : ℕ} (H : m < n) : sub_nat_nat m n = -[1+ pred (n - m)] := have H1 : n - m = succ (pred (n - m)), from eq.symm (succ_pred_of_pos (nat.sub_pos_of_lt H)), show sub_nat_nat m n = nat.cases_on (succ (nat.pred (n - m))) (m -[nat] n) _, from H1 ▸ rfl end definition nat_abs (a : ℤ) : ℕ := int.cases_on a id succ theorem nat_abs_of_nat (n : ℕ) : nat_abs n = n := rfl theorem eq_zero_of_nat_abs_eq_zero : Π {a : ℤ}, nat_abs a = 0 → a = 0 | (of_nat m) H := congr_arg of_nat H | -[1+ m'] H := absurd H !succ_ne_zero theorem nat_abs_zero : nat_abs (0:int) = (0:nat) := rfl theorem nat_abs_one : nat_abs (1:int) = (1:nat) := rfl /- int is a quotient of ordered pairs of natural numbers -/ protected definition equiv (p q : ℕ × ℕ) : Prop := pr1 p + pr2 q = pr2 p + pr1 q local infix ≡ := int.equiv protected theorem equiv.refl [refl] {p : ℕ × ℕ} : p ≡ p := !add.comm protected theorem equiv.symm [symm] {p q : ℕ × ℕ} (H : p ≡ q) : q ≡ p := calc pr1 q + pr2 p = pr2 p + pr1 q : by rewrite add.comm ... = pr1 p + pr2 q : H⁻¹ ... = pr2 q + pr1 p : by rewrite add.comm protected theorem equiv.trans [trans] {p q r : ℕ × ℕ} (H1 : p ≡ q) (H2 : q ≡ r) : p ≡ r := add.right_cancel (calc pr1 p + pr2 r + pr2 q = pr1 p + pr2 q + pr2 r : by rewrite add.right_comm ... = pr2 p + pr1 q + pr2 r : {H1} ... = pr2 p + (pr1 q + pr2 r) : by rewrite add.assoc ... = pr2 p + (pr2 q + pr1 r) : {H2} ... = pr2 p + pr2 q + pr1 r : by rewrite add.assoc ... = pr2 p + pr1 r + pr2 q : by rewrite add.right_comm) protected theorem equiv_equiv : is_equivalence int.equiv := is_equivalence.mk @equiv.refl @equiv.symm @equiv.trans protected theorem equiv_cases {p q : ℕ × ℕ} (H : p ≡ q) : (pr1 p ≥ pr2 p ∧ pr1 q ≥ pr2 q) ∨ (pr1 p < pr2 p ∧ pr1 q < pr2 q) := or.elim (@le_or_gt _ _ (pr2 p) (pr1 p)) (suppose pr1 p ≥ pr2 p, have pr2 p + pr1 q ≥ pr2 p + pr2 q, from H ▸ add_le_add_right this (pr2 q), or.inl (and.intro `pr1 p ≥ pr2 p` (le_of_add_le_add_left this))) (suppose H₁ : pr1 p < pr2 p, have pr2 p + pr1 q < pr2 p + pr2 q, from H ▸ add_lt_add_right H₁ (pr2 q), or.inr (and.intro H₁ (lt_of_add_lt_add_left this))) protected theorem equiv_of_eq {p q : ℕ × ℕ} (H : p = q) : p ≡ q := H ▸ equiv.refl /- the representation and abstraction functions -/ definition abstr (a : ℕ × ℕ) : ℤ := sub_nat_nat (pr1 a) (pr2 a) theorem abstr_of_ge {p : ℕ × ℕ} (H : pr1 p ≥ pr2 p) : abstr p = of_nat (pr1 p - pr2 p) := sub_nat_nat_of_ge H theorem abstr_of_lt {p : ℕ × ℕ} (H : pr1 p < pr2 p) : abstr p = -[1+ pred (pr2 p - pr1 p)] := sub_nat_nat_of_lt H definition repr : ℤ → ℕ × ℕ | (of_nat m) := (m, 0) | -[1+ m] := (0, succ m) theorem abstr_repr : Π (a : ℤ), abstr (repr a) = a | (of_nat m) := (sub_nat_nat_of_ge (zero_le m)) | -[1+ m] := rfl theorem repr_sub_nat_nat (m n : ℕ) : repr (sub_nat_nat m n) ≡ (m, n) := nat.lt_ge_by_cases (take H : m < n, have H1 : repr (sub_nat_nat m n) = (0, n - m), by rewrite [sub_nat_nat_of_lt H, -(succ_pred_of_pos (nat.sub_pos_of_lt H))], H1⁻¹ ▸ (!zero_add ⬝ (nat.sub_add_cancel (le_of_lt H))⁻¹)) (take H : m ≥ n, have H1 : repr (sub_nat_nat m n) = (m - n, 0), from sub_nat_nat_of_ge H ▸ rfl, H1⁻¹ ▸ ((nat.sub_add_cancel H) ⬝ !zero_add⁻¹)) theorem repr_abstr (p : ℕ × ℕ) : repr (abstr p) ≡ p := !prod.eta ▸ !repr_sub_nat_nat theorem abstr_eq {p q : ℕ × ℕ} (Hequiv : p ≡ q) : abstr p = abstr q := or.elim (int.equiv_cases Hequiv) (and.rec (assume (Hp : pr1 p ≥ pr2 p) (Hq : pr1 q ≥ pr2 q), have H : pr1 p - pr2 p = pr1 q - pr2 q, from calc pr1 p - pr2 p = pr1 p + pr2 q - pr2 q - pr2 p : by rewrite nat.add_sub_cancel ... = pr2 p + pr1 q - pr2 q - pr2 p : Hequiv ... = pr2 p + (pr1 q - pr2 q) - pr2 p : nat.add_sub_assoc Hq ... = pr1 q - pr2 q + pr2 p - pr2 p : by rewrite add.comm ... = pr1 q - pr2 q : by rewrite nat.add_sub_cancel, abstr_of_ge Hp ⬝ (H ▸ rfl) ⬝ (abstr_of_ge Hq)⁻¹)) (and.rec (assume (Hp : pr1 p < pr2 p) (Hq : pr1 q < pr2 q), have H : pr2 p - pr1 p = pr2 q - pr1 q, from calc pr2 p - pr1 p = pr2 p + pr1 q - pr1 q - pr1 p : by rewrite nat.add_sub_cancel ... = pr1 p + pr2 q - pr1 q - pr1 p : Hequiv ... = pr1 p + (pr2 q - pr1 q) - pr1 p : nat.add_sub_assoc (le_of_lt Hq) ... = pr2 q - pr1 q + pr1 p - pr1 p : by rewrite add.comm ... = pr2 q - pr1 q : by rewrite nat.add_sub_cancel, abstr_of_lt Hp ⬝ (H ▸ rfl) ⬝ (abstr_of_lt Hq)⁻¹)) theorem equiv_iff (p q : ℕ × ℕ) : (p ≡ q) ↔ (abstr p = abstr q) := iff.intro abstr_eq (assume H, equiv.trans (H ▸ equiv.symm (repr_abstr p)) (repr_abstr q)) theorem equiv_iff3 (p q : ℕ × ℕ) : (p ≡ q) ↔ ((p ≡ p) ∧ (q ≡ q) ∧ (abstr p = abstr q)) := iff.trans !equiv_iff (iff.symm (iff.trans (and_iff_right !equiv.refl) (and_iff_right !equiv.refl))) theorem eq_abstr_of_equiv_repr {a : ℤ} {p : ℕ × ℕ} (Hequiv : repr a ≡ p) : a = abstr p := !abstr_repr⁻¹ ⬝ abstr_eq Hequiv theorem eq_of_repr_equiv_repr {a b : ℤ} (H : repr a ≡ repr b) : a = b := eq_abstr_of_equiv_repr H ⬝ !abstr_repr section local attribute abstr [reducible] local attribute dist [reducible] theorem nat_abs_abstr : Π (p : ℕ × ℕ), nat_abs (abstr p) = dist (pr1 p) (pr2 p) | (m, n) := nat.lt_ge_by_cases (assume H : m < n, calc nat_abs (abstr (m, n)) = nat_abs (-[1+ pred (n - m)]) : int.abstr_of_lt H ... = n - m : succ_pred_of_pos (nat.sub_pos_of_lt H) ... = dist m n : dist_eq_sub_of_le (le_of_lt H)) (assume H : m ≥ n, (abstr_of_ge H)⁻¹ ▸ (dist_eq_sub_of_ge H)⁻¹) end theorem cases_of_nat_succ (a : ℤ) : (∃n : ℕ, a = of_nat n) ∨ (∃n : ℕ, a = - (of_nat (succ n))) := int.cases_on a (take m, or.inl (exists.intro _ rfl)) (take m, or.inr (exists.intro _ rfl)) theorem cases_of_nat (a : ℤ) : (∃n : ℕ, a = of_nat n) ∨ (∃n : ℕ, a = - of_nat n) := or.imp_right (Exists.rec (take n, (exists.intro _))) !cases_of_nat_succ theorem by_cases_of_nat {P : ℤ → Prop} (a : ℤ) (H1 : ∀n : ℕ, P (of_nat n)) (H2 : ∀n : ℕ, P (- of_nat n)) : P a := or.elim (cases_of_nat a) (assume H, obtain (n : ℕ) (H3 : a = n), from H, H3⁻¹ ▸ H1 n) (assume H, obtain (n : ℕ) (H3 : a = -n), from H, H3⁻¹ ▸ H2 n) theorem by_cases_of_nat_succ {P : ℤ → Prop} (a : ℤ) (H1 : ∀n : ℕ, P (of_nat n)) (H2 : ∀n : ℕ, P (- of_nat (succ n))) : P a := or.elim (cases_of_nat_succ a) (assume H, obtain (n : ℕ) (H3 : a = n), from H, H3⁻¹ ▸ H1 n) (assume H, obtain (n : ℕ) (H3 : a = -(succ n)), from H, H3⁻¹ ▸ H2 n) /- int is a ring -/ /- addition -/ definition padd (p q : ℕ × ℕ) : ℕ × ℕ := (pr1 p + pr1 q, pr2 p + pr2 q) theorem repr_add : Π (a b : ℤ), repr (add a b) ≡ padd (repr a) (repr b) | (of_nat m) (of_nat n) := !equiv.refl | (of_nat m) -[1+ n] := begin change repr (sub_nat_nat m (succ n)) ≡ (m + 0, 0 + succ n), rewrite [zero_add, add_zero], apply repr_sub_nat_nat end | -[1+ m] (of_nat n) := begin change repr (-[1+ m] + n) ≡ (0 + n, succ m + 0), rewrite [zero_add, add_zero], apply repr_sub_nat_nat end | -[1+ m] -[1+ n] := !repr_sub_nat_nat theorem padd_congr {p p' q q' : ℕ × ℕ} (Ha : p ≡ p') (Hb : q ≡ q') : padd p q ≡ padd p' q' := calc pr1 p + pr1 q + (pr2 p' + pr2 q') = pr1 p + pr2 p' + (pr1 q + pr2 q') : add.comm4 ... = pr2 p + pr1 p' + (pr1 q + pr2 q') : {Ha} ... = pr2 p + pr1 p' + (pr2 q + pr1 q') : {Hb} ... = pr2 p + pr2 q + (pr1 p' + pr1 q') : add.comm4 theorem padd_comm (p q : ℕ × ℕ) : padd p q = padd q p := calc (pr1 p + pr1 q, pr2 p + pr2 q) = (pr1 q + pr1 p, pr2 p + pr2 q) : by rewrite add.comm ... = (pr1 q + pr1 p, pr2 q + pr2 p) : by rewrite (add.comm (pr2 p) (pr2 q)) theorem padd_assoc (p q r : ℕ × ℕ) : padd (padd p q) r = padd p (padd q r) := calc (pr1 p + pr1 q + pr1 r, pr2 p + pr2 q + pr2 r) = (pr1 p + (pr1 q + pr1 r), pr2 p + pr2 q + pr2 r) : by rewrite add.assoc ... = (pr1 p + (pr1 q + pr1 r), pr2 p + (pr2 q + pr2 r)) : by rewrite add.assoc protected theorem add_comm (a b : ℤ) : a + b = b + a := eq_of_repr_equiv_repr (equiv.trans !repr_add (equiv.symm (!padd_comm ▸ !repr_add))) protected theorem add_assoc (a b c : ℤ) : a + b + c = a + (b + c) := eq_of_repr_equiv_repr (calc repr (a + b + c) ≡ padd (repr (a + b)) (repr c) : repr_add ... ≡ padd (padd (repr a) (repr b)) (repr c) : padd_congr !repr_add !equiv.refl ... = padd (repr a) (padd (repr b) (repr c)) : !padd_assoc ... ≡ padd (repr a) (repr (b + c)) : padd_congr !equiv.refl !repr_add ... ≡ repr (a + (b + c)) : repr_add) protected theorem add_zero : Π (a : ℤ), a + 0 = a := int.rec (λm, rfl) (λm, rfl) protected theorem zero_add (a : ℤ) : 0 + a = a := !int.add_comm ▸ !int.add_zero /- negation -/ definition pneg (p : ℕ × ℕ) : ℕ × ℕ := (pr2 p, pr1 p) -- note: this is =, not just ≡ theorem repr_neg : Π (a : ℤ), repr (- a) = pneg (repr a) | 0 := rfl | (succ m) := rfl | -[1+ m] := rfl theorem pneg_congr {p p' : ℕ × ℕ} (H : p ≡ p') : pneg p ≡ pneg p' := eq.symm H theorem pneg_pneg (p : ℕ × ℕ) : pneg (pneg p) = p := !prod.eta theorem nat_abs_neg (a : ℤ) : nat_abs (-a) = nat_abs a := calc nat_abs (-a) = nat_abs (abstr (repr (-a))) : abstr_repr ... = nat_abs (abstr (pneg (repr a))) : repr_neg ... = dist (pr1 (pneg (repr a))) (pr2 (pneg (repr a))) : nat_abs_abstr ... = dist (pr2 (pneg (repr a))) (pr1 (pneg (repr a))) : dist.comm ... = nat_abs (abstr (repr a)) : nat_abs_abstr ... = nat_abs a : abstr_repr theorem padd_pneg (p : ℕ × ℕ) : padd p (pneg p) ≡ (0, 0) := show pr1 p + pr2 p + 0 = pr2 p + pr1 p + 0, from !nat.add_comm ▸ rfl theorem padd_padd_pneg (p q : ℕ × ℕ) : padd (padd p q) (pneg q) ≡ p := calc pr1 p + pr1 q + pr2 q + pr2 p = pr1 p + (pr1 q + pr2 q) + pr2 p : add.assoc ... = pr1 p + (pr1 q + pr2 q + pr2 p) : add.assoc ... = pr1 p + (pr2 q + pr1 q + pr2 p) : add.comm ... = pr1 p + (pr2 q + pr2 p + pr1 q) : add.right_comm ... = pr1 p + (pr2 p + pr2 q + pr1 q) : add.comm ... = pr2 p + pr2 q + pr1 q + pr1 p : add.comm protected theorem add_left_inv (a : ℤ) : -a + a = 0 := have H : repr (-a + a) ≡ repr 0, from calc repr (-a + a) ≡ padd (repr (neg a)) (repr a) : repr_add ... = padd (pneg (repr a)) (repr a) : repr_neg ... ≡ repr 0 : padd_pneg, eq_of_repr_equiv_repr H /- nat abs -/ definition pabs (p : ℕ × ℕ) : ℕ := dist (pr1 p) (pr2 p) theorem pabs_congr {p q : ℕ × ℕ} (H : p ≡ q) : pabs p = pabs q := calc pabs p = nat_abs (abstr p) : nat_abs_abstr ... = nat_abs (abstr q) : abstr_eq H ... = pabs q : nat_abs_abstr theorem nat_abs_eq_pabs_repr (a : ℤ) : nat_abs a = pabs (repr a) := calc nat_abs a = nat_abs (abstr (repr a)) : abstr_repr ... = pabs (repr a) : nat_abs_abstr theorem nat_abs_add_le (a b : ℤ) : nat_abs (a + b) ≤ nat_abs a + nat_abs b := calc nat_abs (a + b) = pabs (repr (a + b)) : nat_abs_eq_pabs_repr ... = pabs (padd (repr a) (repr b)) : pabs_congr !repr_add ... ≤ pabs (repr a) + pabs (repr b) : dist_add_add_le_add_dist_dist ... = pabs (repr a) + nat_abs b : nat_abs_eq_pabs_repr ... = nat_abs a + nat_abs b : nat_abs_eq_pabs_repr theorem nat_abs_neg_of_nat (n : nat) : nat_abs (neg_of_nat n) = n := begin cases n, reflexivity, reflexivity end section local attribute nat_abs [reducible] theorem nat_abs_mul : Π (a b : ℤ), nat_abs (a * b) = (nat_abs a) * (nat_abs b) | (of_nat m) (of_nat n) := rfl | (of_nat m) -[1+ n] := by rewrite [mul_of_nat_neg_succ_of_nat, nat_abs_neg_of_nat] | -[1+ m] (of_nat n) := by rewrite [mul_neg_succ_of_nat_of_nat, nat_abs_neg_of_nat] | -[1+ m] -[1+ n] := rfl end /- multiplication -/ definition pmul (p q : ℕ × ℕ) : ℕ × ℕ := (pr1 p * pr1 q + pr2 p * pr2 q, pr1 p * pr2 q + pr2 p * pr1 q) theorem repr_neg_of_nat (m : ℕ) : repr (neg_of_nat m) = (0, m) := nat.cases_on m rfl (take m', rfl) -- note: we have =, not just ≡ theorem repr_mul : Π (a b : ℤ), repr (a * b) = pmul (repr a) (repr b) | (of_nat m) (of_nat n) := calc (m * n + 0 * 0, m * 0 + 0) = (m * n + 0 * 0, m * 0 + 0 * n) : by rewrite *zero_mul | (of_nat m) -[1+ n] := calc repr ((m : int) * -[1+ n]) = (m * 0 + 0, m * succ n + 0 * 0) : repr_neg_of_nat ... = (m * 0 + 0 * succ n, m * succ n + 0 * 0) : by rewrite *zero_mul | -[1+ m] (of_nat n) := calc repr (-[1+ m] * (n:int)) = (0 + succ m * 0, succ m * n) : repr_neg_of_nat ... = (0 + succ m * 0, 0 + succ m * n) : nat.zero_add ... = (0 * n + succ m * 0, 0 + succ m * n) : by rewrite zero_mul | -[1+ m] -[1+ n] := calc (succ m * succ n, 0) = (succ m * succ n, 0 * succ n) : by rewrite zero_mul ... = (0 + succ m * succ n, 0 * succ n) : nat.zero_add theorem equiv_mul_prep {xa ya xb yb xn yn xm ym : ℕ} (H1 : xa + yb = ya + xb) (H2 : xn + ym = yn + xm) : xa*xn+ya*yn+(xb*ym+yb*xm) = xa*yn+ya*xn+(xb*xm+yb*ym) := nat.add_right_cancel (calc xa*xn+ya*yn + (xb*ym+yb*xm) + (yb*xn+xb*yn + (xb*xn+yb*yn)) = xa*xn+ya*yn + (yb*xn+xb*yn) + (xb*ym+yb*xm + (xb*xn+yb*yn)) : by rewrite add.comm4 ... = xa*xn+ya*yn + (yb*xn+xb*yn) + (xb*xn+yb*yn + (xb*ym+yb*xm)) : by rewrite {xb*ym+yb*xm +_}nat.add_comm ... = xa*xn+yb*xn + (ya*yn+xb*yn) + (xb*xn+xb*ym + (yb*yn+yb*xm)) : by exact !congr_arg2 !add.comm4 !add.comm4 ... = ya*xn+xb*xn + (xa*yn+yb*yn) + (xb*yn+xb*xm + (yb*xn+yb*ym)) : by rewrite[-+left_distrib,-+right_distrib]; exact H1 ▸ H2 ▸ rfl ... = ya*xn+xa*yn + (xb*xn+yb*yn) + (xb*yn+yb*xn + (xb*xm+yb*ym)) : by exact !congr_arg2 !add.comm4 !add.comm4 ... = xa*yn+ya*xn + (xb*xn+yb*yn) + (xb*yn+yb*xn + (xb*xm+yb*ym)) : by rewrite {xa*yn + _}nat.add_comm ... = xa*yn+ya*xn + (xb*xn+yb*yn) + (yb*xn+xb*yn + (xb*xm+yb*ym)) : by rewrite {xb*yn + _}nat.add_comm ... = xa*yn+ya*xn + (yb*xn+xb*yn) + (xb*xn+yb*yn + (xb*xm+yb*ym)) : by rewrite (!add.comm4) ... = xa*yn+ya*xn + (yb*xn+xb*yn) + (xb*xm+yb*ym + (xb*xn+yb*yn)) : by rewrite {xb*xn+yb*yn + _}nat.add_comm ... = xa*yn+ya*xn + (xb*xm+yb*ym) + (yb*xn+xb*yn + (xb*xn+yb*yn)) : by rewrite add.comm4) theorem pmul_congr {p p' q q' : ℕ × ℕ} : p ≡ p' → q ≡ q' → pmul p q ≡ pmul p' q' := equiv_mul_prep theorem pmul_comm (p q : ℕ × ℕ) : pmul p q = pmul q p := show (_,_) = (_,_), begin congruence, { congruence, repeat rewrite mul.comm }, { rewrite add.comm, congruence, repeat rewrite mul.comm } end protected theorem mul_comm (a b : ℤ) : a * b = b * a := eq_of_repr_equiv_repr ((calc repr (a * b) = pmul (repr a) (repr b) : repr_mul ... = pmul (repr b) (repr a) : pmul_comm ... = repr (b * a) : repr_mul) ▸ !equiv.refl) private theorem pmul_assoc_prep {p1 p2 q1 q2 r1 r2 : ℕ} : ((p1*q1+p2*q2)*r1+(p1*q2+p2*q1)*r2, (p1*q1+p2*q2)*r2+(p1*q2+p2*q1)*r1) = (p1*(q1*r1+q2*r2)+p2*(q1*r2+q2*r1), p1*(q1*r2+q2*r1)+p2*(q1*r1+q2*r2)) := begin rewrite [+left_distrib, +right_distrib, *mul.assoc], rewrite (add.comm4 (p1 * (q1 * r1)) (p2 * (q2 * r1)) (p1 * (q2 * r2)) (p2 * (q1 * r2))), rewrite (add.comm (p2 * (q2 * r1)) (p2 * (q1 * r2))), rewrite (add.comm4 (p1 * (q1 * r2)) (p2 * (q2 * r2)) (p1 * (q2 * r1)) (p2 * (q1 * r1))), rewrite (add.comm (p2 * (q2 * r2)) (p2 * (q1 * r1))) end theorem pmul_assoc (p q r: ℕ × ℕ) : pmul (pmul p q) r = pmul p (pmul q r) := pmul_assoc_prep protected theorem mul_assoc (a b c : ℤ) : (a * b) * c = a * (b * c) := eq_of_repr_equiv_repr ((calc repr (a * b * c) = pmul (repr (a * b)) (repr c) : repr_mul ... = pmul (pmul (repr a) (repr b)) (repr c) : repr_mul ... = pmul (repr a) (pmul (repr b) (repr c)) : pmul_assoc ... = pmul (repr a) (repr (b * c)) : repr_mul ... = repr (a * (b * c)) : repr_mul) ▸ !equiv.refl) protected theorem mul_one : Π (a : ℤ), a * 1 = a | (of_nat m) := !int.zero_add -- zero_add happens to be def. = to this thm | -[1+ m] := !nat.zero_add ▸ rfl protected theorem one_mul (a : ℤ) : 1 * a = a := int.mul_comm a 1 ▸ int.mul_one a private theorem mul_distrib_prep {a1 a2 b1 b2 c1 c2 : ℕ} : ((a1+b1)*c1+(a2+b2)*c2, (a1+b1)*c2+(a2+b2)*c1) = (a1*c1+a2*c2+(b1*c1+b2*c2), a1*c2+a2*c1+(b1*c2+b2*c1)) := begin rewrite +right_distrib, congruence, {rewrite add.comm4}, {rewrite add.comm4} end protected theorem right_distrib (a b c : ℤ) : (a + b) * c = a * c + b * c := eq_of_repr_equiv_repr (calc repr ((a + b) * c) = pmul (repr (a + b)) (repr c) : repr_mul ... ≡ pmul (padd (repr a) (repr b)) (repr c) : pmul_congr !repr_add equiv.refl ... = padd (pmul (repr a) (repr c)) (pmul (repr b) (repr c)) : mul_distrib_prep ... = padd (repr (a * c)) (pmul (repr b) (repr c)) : repr_mul ... = padd (repr (a * c)) (repr (b * c)) : repr_mul ... ≡ repr (a * c + b * c) : repr_add) protected theorem left_distrib (a b c : ℤ) : a * (b + c) = a * b + a * c := calc a * (b + c) = (b + c) * a : int.mul_comm ... = b * a + c * a : int.right_distrib ... = a * b + c * a : int.mul_comm ... = a * b + a * c : int.mul_comm protected theorem zero_ne_one : (0 : int) ≠ 1 := assume H : 0 = 1, !succ_ne_zero (of_nat.inj H)⁻¹ protected theorem eq_zero_or_eq_zero_of_mul_eq_zero {a b : ℤ} (H : a * b = 0) : a = 0 ∨ b = 0 := or.imp eq_zero_of_nat_abs_eq_zero eq_zero_of_nat_abs_eq_zero (eq_zero_or_eq_zero_of_mul_eq_zero (by rewrite [-nat_abs_mul, H])) protected definition integral_domain [reducible] [trans_instance] : integral_domain int := ⦃integral_domain, add := int.add, add_assoc := int.add_assoc, zero := 0, zero_add := int.zero_add, add_zero := int.add_zero, neg := int.neg, add_left_inv := int.add_left_inv, add_comm := int.add_comm, mul := int.mul, mul_assoc := int.mul_assoc, one := 1, one_mul := int.one_mul, mul_one := int.mul_one, left_distrib := int.left_distrib, right_distrib := int.right_distrib, mul_comm := int.mul_comm, zero_ne_one := int.zero_ne_one, eq_zero_or_eq_zero_of_mul_eq_zero := @int.eq_zero_or_eq_zero_of_mul_eq_zero⦄ definition int_has_sub [reducible] [instance] [priority int.prio] : has_sub int := has_sub.mk has_sub.sub definition int_has_dvd [reducible] [instance] [priority int.prio] : has_dvd int := has_dvd.mk has_dvd.dvd /- additional properties -/ theorem of_nat_sub {m n : ℕ} (H : m ≥ n) : of_nat (m - n) = of_nat m - of_nat n := assert m - n + n = m, from nat.sub_add_cancel H, begin symmetry, apply sub_eq_of_eq_add, rewrite [-of_nat_add, this] end theorem neg_succ_of_nat_eq' (m : ℕ) : -[1+ m] = -m - 1 := by rewrite [neg_succ_of_nat_eq, neg_add] definition succ (a : ℤ) := a + (succ zero) definition pred (a : ℤ) := a - (succ zero) definition nat_succ_eq_int_succ (n : ℕ) : nat.succ n = int.succ n := rfl theorem pred_succ (a : ℤ) : pred (succ a) = a := !sub_add_cancel theorem succ_pred (a : ℤ) : succ (pred a) = a := !add_sub_cancel theorem neg_succ (a : ℤ) : -succ a = pred (-a) := by rewrite [↑succ,neg_add] theorem succ_neg_succ (a : ℤ) : succ (-succ a) = -a := by rewrite [neg_succ,succ_pred] theorem neg_pred (a : ℤ) : -pred a = succ (-a) := by rewrite [↑pred,neg_sub,sub_eq_add_neg,add.comm] theorem pred_neg_pred (a : ℤ) : pred (-pred a) = -a := by rewrite [neg_pred,pred_succ] theorem pred_nat_succ (n : ℕ) : pred (nat.succ n) = n := pred_succ n theorem neg_nat_succ (n : ℕ) : -nat.succ n = pred (-n) := !neg_succ theorem succ_neg_nat_succ (n : ℕ) : succ (-nat.succ n) = -n := !succ_neg_succ definition rec_nat_on [unfold 2] {P : ℤ → Type} (z : ℤ) (H0 : P 0) (Hsucc : Π⦃n : ℕ⦄, P n → P (succ n)) (Hpred : Π⦃n : ℕ⦄, P (-n) → P (-nat.succ n)) : P z := int.rec (nat.rec H0 Hsucc) (λn, nat.rec H0 Hpred (nat.succ n)) z --the only computation rule of rec_nat_on which is not definitional theorem rec_nat_on_neg {P : ℤ → Type} (n : nat) (H0 : P zero) (Hsucc : Π⦃n : nat⦄, P n → P (succ n)) (Hpred : Π⦃n : nat⦄, P (-n) → P (-nat.succ n)) : rec_nat_on (-nat.succ n) H0 Hsucc Hpred = Hpred (rec_nat_on (-n) H0 Hsucc Hpred) := nat.rec rfl (λn H, rfl) n end int
0a8e9c31603e31a25090890eb654c1787df3e318
d5ff69c5608a867046609101d89910f1257aaf8c
/src/2020/functions/two_sided_inverse.lean
c2f0948f240a4e23d4057aa18ea961e0aa4dfc11
[]
no_license
jiaminglimjm/M40001_lean
c299ff574a22d3a636a2b9720dc9b5e853a3bab0
c8bd8922f37f3e10e2d448f226798ebd0a2af232
refs/heads/master
1,672,312,761,737
1,603,095,035,000
1,603,095,035,000
304,831,347
0
0
null
1,603,094,893,000
1,602,922,986,000
null
UTF-8
Lean
false
false
895
lean
import tactic /-! # Two-sided inverses We define two-sided inverses, and prove that a function is a bijection if and only if it has a two-sided inverse. -/ -- let X and Y be types, and let f be a function. variables {X Y : Type} (f : X → Y) -- two-sided inverse structure tsi (f : X → Y) := (g : Y → X) (hX : ∀ x : X, g (f x) = x) (hY : ∀ y : Y, f (g y) = y) open function example : bijective f ↔ nonempty (tsi f) := begin split, { intro hf, cases hf with hi hs, choose g hg using hs, let G : tsi f := { g := g, hX := begin intro x, apply hi, rw hg end, hY := begin exact hg, end }, use G }, { rintro ⟨g, hX, hY⟩, split, { intros a b hab, apply_fun g at hab, rw [hX, hX] at hab, assumption }, { intro y, use g y, apply hY, } } end
b2a103e9b71b0b6e7f0f18888788f9820f8d45b9
f3a5af2927397cf346ec0e24312bfff077f00425
/src/game/world6/level8.lean
621a6b6ff2f7313bcb5826a0b6a1a637ca8a8cfc
[ "Apache-2.0" ]
permissive
ImperialCollegeLondon/natural_number_game
05c39e1586408cfb563d1a12e1085a90726ab655
f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd
refs/heads/master
1,688,570,964,990
1,636,908,242,000
1,636,908,242,000
195,403,790
277
84
Apache-2.0
1,694,547,955,000
1,562,328,792,000
Lean
UTF-8
Lean
false
false
1,457
lean
/- Axiom : not_iff_imp_false (P : Prop) : ¬ P ↔ P → false -/ lemma not_iff_imp_false (P : Prop) : ¬ P ↔ P → false := iff.rfl -- hide /- # Proposition world. ## Level 8 : `(P → Q) → (¬ Q → ¬ P)` There is a false proposition `false`, with no proof. It is easy to check that $\lnot Q$ is equivalent to $Q\implies {\tt false}$, and in the natural number game we call this `not_iff_imp_false (P : Prop) : ¬ P ↔ (P → false)` So you can start the proof of the contrapositive below with `repeat {rw not_iff_imp_false},` to get rid of the two occurences of `¬`, and I'm sure you can take it from there (note that we just added `not_iff_imp_false` to the theorem statements in the menu on the left). At some point your goal might be to prove `false`. At that point I guess you must be proving something by contradiction. Or are you? -/ /- Lemma : no-side-bar If $P$ and $Q$ are propositions, and $P\implies Q$, then $\lnot Q\implies \lnot P$. -/ lemma contrapositive (P Q : Prop) : (P → Q) → (¬ Q → ¬ P) := begin repeat {rw not_iff_imp_false}, intro f, intro h, intro p, apply h, apply f, exact p, end /- ## Technical note All of that rewriting you did with `rw` in addition world was rewriting hypothesis of the form `h : X = Y`, but you can also `rw h` if `h : P ↔ Q` (because propositional extensionality says that if $P\iff Q$ then $P=Q$, and mathematicians use this whether or not they notice.) -/
3b6251bf374c1265e5dd657653673d860f79c3f1
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/dep_cases_clear_hyp.lean
213683281265e6a0b6aedb22e6022a3ac503853b
[ "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
588
lean
universes u v inductive tree (α : Type u) | leaf {} : tree | node (l : tree) (v : α) (r : tree) : tree namespace tree variables {α : Type u} inductive is_searchable (lt : α → α → Prop) : tree α → α → α → Prop | leaf_s {lo hi} : lt lo hi → is_searchable leaf lo hi | node_s {l r v lo hi} (hs₁ : is_searchable l lo v) (hs₂ : is_searchable r v hi) : is_searchable (node l v r) lo hi example (l r : tree α) {lo v hi lt} (h : is_searchable lt (node l v r) lo hi) : true := begin cases h, trace_state, /- Should not contain h -/ trivial end end tree
0720430900ccd8b747e5a79719ca0a00aa414ec2
57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d
/stage0/src/Lean/Server/Completion.lean
1ff495962a67f296db33013f72059de5c4709a21
[ "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
11,892
lean
/- Copyright (c) 2021 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Environment import Lean.Parser.Term import Lean.Data.Lsp.LanguageFeatures import Lean.Meta.Tactic.Apply import Lean.Meta.Match.MatcherInfo import Lean.Server.InfoUtils import Lean.Parser.Extension namespace Lean.Server.Completion open Lsp open Elab open Meta builtin_initialize completionBlackListExt : TagDeclarationExtension ← mkTagDeclarationExtension `blackListCompletion @[export lean_completion_add_to_black_list] def addToBlackList (env : Environment) (declName : Name) : Environment := completionBlackListExt.tag env declName private def isBlackListed (declName : Name) : MetaM Bool := do let env ← getEnv declName.isInternal <||> isAuxRecursor env declName <||> isNoConfusion env declName <||> isRec declName <||> completionBlackListExt.isTagged env declName <||> isMatcher declName private partial def consumeImplicitPrefix (e : Expr) : MetaM Expr := do match e with | Expr.forallE n d b c => -- We do not consume instance implicit arguments because the user probably wants be aware of this dependency if c.binderInfo == BinderInfo.implicit then let arg ← mkFreshExprMVar (userName := n) d consumeImplicitPrefix (b.instantiate1 arg) else return e | _ => return e private def isTypeApplicable (type : Expr) (expectedType? : Option Expr) : MetaM Bool := try match expectedType? with | none => return true | some expectedType => let mut (numArgs, hasMVarHead) ← getExpectedNumArgsAux type unless hasMVarHead do let targetTypeNumArgs ← getExpectedNumArgs expectedType numArgs := numArgs - targetTypeNumArgs let (newMVars, _, type) ← forallMetaTelescopeReducing type (some numArgs) -- TODO take coercions into account -- We use `withReducible` to make sure we don't spend too much time unfolding definitions -- Alternative: use default and small number of heartbeats withReducible <| withoutModifyingState <| isDefEq type expectedType catch _ => return false private def sortCompletionItems (items : Array CompletionItem) : Array CompletionItem := items.qsort fun i1 i2 => i1.label < i2.label private def mkCompletionItem (label : Name) (type : Expr) : MetaM CompletionItem := do let detail ← Meta.ppExpr (← consumeImplicitPrefix type) return { label := label.getString!, detail? := some (toString detail), documentation? := none } structure State where itemsMain : Array CompletionItem := #[] itemsOther : Array CompletionItem := #[] abbrev M := OptionT $ StateRefT State MetaM private def addCompletionItem (label : Name) (type : Expr) (expectedType? : Option Expr) : M Unit := do let item ← mkCompletionItem label type if (← isTypeApplicable type expectedType?) then modify fun s => { s with itemsMain := s.itemsMain.push item } else modify fun s => { s with itemsOther := s.itemsOther.push item } private def addCompletionItemForDecl (label : Name) (declName : Name) (expectedType? : Option Expr) : M Unit := do if let some c ← (← getEnv).find? declName then addCompletionItem label c.type expectedType? private def runM (ctx : ContextInfo) (lctx : LocalContext) (x : M Unit) : IO (Option CompletionList) := ctx.runMetaM lctx do match (← x.run |>.run {}) with | (none, _) => return none | (some _, s) => return some { items := sortCompletionItems s.itemsMain ++ sortCompletionItems s.itemsOther, isIncomplete := true } private def matchAtomic (id: Name) (declName : Name) : Bool := match id, declName with | Name.str Name.anonymous s₁ _, Name.str Name.anonymous s₂ _ => s₁.isPrefixOf s₂ | _, _ => false /-- Return the auto-completion label if `id` can be auto completed using `declName` assuming namespace `ns` is open. This function only succeeds with atomic labels. BTW, it seems most clients only use the last part. Remark: `danglingDot == true` when the completion point is an identifier followed by `.`. -/ private def matchDecl? (ns : Name) (id : Name) (danglingDot : Bool) (declName : Name) : Option Name := -- dbg_trace "{ns}, {id}, {declName}, {danglingDot}" if !ns.isPrefixOf declName then none else let declName := declName.replacePrefix ns Name.anonymous if id.isPrefixOf declName && danglingDot then let declName := declName.replacePrefix id Name.anonymous if declName.isAtomic && !declName.isAnonymous then some declName else none else if !danglingDot then match id, declName with | Name.str p₁ s₁ _, Name.str p₂ s₂ _ => if p₁ == p₂ && s₁.isPrefixOf s₂ then some s₂ else none | _, _ => none else none private def idCompletionCore (ctx : ContextInfo) (id : Name) (danglingDot : Bool) (expectedType? : Option Expr) : M Unit := do let id := id.eraseMacroScopes -- dbg_trace ">> id {id} : {expectedType?}" if id.isAtomic then -- search for matches in the local context for localDecl in (← getLCtx) do if matchAtomic id localDecl.userName then addCompletionItem localDecl.userName localDecl.type expectedType? -- search for matches in the environment let env ← getEnv env.constants.forM fun declName c => do unless (← isBlackListed declName) do let matchUsingNamespace (ns : Name): M Bool := do if let some label := matchDecl? ns id danglingDot declName then -- dbg_trace "matched with {id}, {declName}, {label}" addCompletionItem label c.type expectedType? return true else return false if (← matchUsingNamespace Name.anonymous) then return () -- use current namespace let rec visitNamespaces (ns : Name) : M Bool := do match ns with | Name.str p .. => matchUsingNamespace ns <||> visitNamespaces p | _ => return false if (← visitNamespaces ctx.currNamespace) then return () -- use open decls for openDecl in ctx.openDecls do match openDecl with | OpenDecl.simple ns exs => unless exs.contains declName do if (← matchUsingNamespace ns) then return () | _ => pure () -- search explicitily open `ids` for openDecl in ctx.openDecls do match openDecl with | OpenDecl.explicit openedId resolvedId => unless (← isBlackListed resolvedId) do if matchAtomic id openedId then addCompletionItemForDecl openedId resolvedId expectedType? | _ => pure () -- search for aliases getAliasState env |>.forM fun alias declNames => do if matchAtomic id alias then declNames.forM fun declName => do unless (← isBlackListed declName) do addCompletionItemForDecl alias declName expectedType? -- TODO search macros -- TODO search namespaces private def idCompletion (ctx : ContextInfo) (lctx : LocalContext) (id : Name) (danglingDot : Bool) (expectedType? : Option Expr) : IO (Option CompletionList) := runM ctx lctx do idCompletionCore ctx id danglingDot expectedType? private def isDotCompletionMethod (info : ConstantInfo) : MetaM Bool := forallTelescopeReducing info.type fun xs _ => do for x in xs do let localDecl ← getLocalDecl x.fvarId! let type := localDecl.type.consumeMData if type.getAppFn.isConstOf info.name.getPrefix then return true return false /-- Given a type, try to extract relevant type names for dot notation field completion. We extract the type name, parent struct names, and unfold the type. The process mimics the dot notation elaboration procedure at `App.lean` -/ private partial def getDotCompletionTypeNames (type : Expr) : MetaM NameSet := return (← visit type |>.run {}).2 where visit (type : Expr) : StateRefT NameSet MetaM Unit := do match type.getAppFn with | Expr.const typeName .. => modify fun s => s.insert typeName if isStructureLike (← getEnv) typeName then for parentName in getAllParentStructures (← getEnv) typeName do modify fun s => s.insert parentName let type? ← try unfoldDefinition? type catch _ => pure none match type? with | some type => visit type | none => pure () | _ => pure () private def dotCompletion (ctx : ContextInfo) (info : TermInfo) (expectedType? : Option Expr) : IO (Option CompletionList) := runM ctx info.lctx do let nameSet ← try getDotCompletionTypeNames (← instantiateMVars (← inferType info.expr)) catch _ => pure {} if nameSet.isEmpty then if info.stx.isIdent then idCompletionCore ctx info.stx.getId (danglingDot := false) expectedType? else if info.stx.getKind == ``Lean.Parser.Term.completion && info.stx[0].isIdent then idCompletionCore ctx info.stx[0].getId (danglingDot := true) expectedType? else failure else (← getEnv).constants.forM fun declName c => do if nameSet.contains declName.getPrefix then unless (← isBlackListed c.name) do if (← isDotCompletionMethod c) then addCompletionItem c.name.getString! c.type expectedType? private def optionCompletion (ctx : ContextInfo) : IO (Option CompletionList) := do ctx.runMetaM {} do let decls ← getOptionDecls let opts ← getOptions let items : Array CompletionItem := decls.fold (init := #[]) fun items name decl => items.push { label := name.toString, detail? := s!"({opts.get name decl.defValue}), {decl.descr}", documentation? := none } return some { items := sortCompletionItems items, isIncomplete := true } private def tacticCompletion (ctx : ContextInfo) : IO (Option CompletionList) := -- Just return the list of tactics for now. ctx.runMetaM {} do let table := Parser.getCategory (Parser.parserExtension.getState (← getEnv)).categories `tactic |>.get!.tables.leadingTable let items : Array CompletionItem := table.fold (init := #[]) fun items tk parser => -- TODO pretty print tactic syntax items.push { label := tk.toString, detail? := none, documentation? := none } return some { items := sortCompletionItems items, isIncomplete := true } partial def find? (fileMap : FileMap) (hoverPos : String.Pos) (infoTree : InfoTree) : IO (Option CompletionList) := do let ⟨hoverLine, _⟩ := fileMap.toPosition hoverPos match infoTree.foldInfo (init := none) (choose fileMap hoverLine) with | some (ctx, Info.ofCompletionInfo info) => match info with | CompletionInfo.dot info (expectedType? := expectedType?) .. => dotCompletion ctx info expectedType? | CompletionInfo.id stx id danglingDot lctx expectedType? => idCompletion ctx lctx id danglingDot expectedType? | CompletionInfo.option .. => optionCompletion ctx | CompletionInfo.tactic .. => tacticCompletion ctx | _ => return none | _ => -- TODO try to extract id from `fileMap` and some `ContextInfo` from `InfoTree` return none where choose (fileMap : FileMap) (hoverLine : Nat) (ctx : ContextInfo) (info : Info) (best? : Option (ContextInfo × Info)) : Option (ContextInfo × Info) := if !info.isCompletion then best? else if let some d := info.occursBefore? hoverPos then let pos := info.tailPos?.get! let ⟨line, _⟩ := fileMap.toPosition pos if line != hoverLine then best? else match best? with | none => return (ctx, info) | some (_, best) => let dBest := best.occursBefore? hoverPos |>.get! if d < dBest || (d == dBest && info.isSmaller best) then return (ctx, info) else best? else best? end Lean.Server.Completion
8217079c76921b470402c85a65f8d34f9df7c263
1b8f093752ba748c5ca0083afef2959aaa7dace5
/src/category_theory/presheaves.lean
aa2d8ed2ed5c67a26737e2644c5cf9a5f7fc6f40
[]
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
4,790
lean
-- Copyright (c) 2018 Scott Morrison. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Authors: Scott Morrison, Mario Carneiro, Reid Barton import category_theory.examples.topological_spaces import category_theory.functor_category import category_theory.functor_categories.whiskering import category_theory.natural_isomorphism universes u v u₂ v₂ open category_theory open category_theory.examples namespace category_theory.presheaves variables (C : Type u) [𝒞 : category.{u v} C] include 𝒞 structure Presheaf := (X : Top.{v}) (𝒪 : (open_set X) ⥤ C) variables {C} instance Presheaf_topological_space (F : Presheaf.{u v} C) : topological_space F.X.α := F.X.str structure Presheaf_hom (F G : Presheaf.{u v} C) := (f : F.X ⟶ G.X) (c : G.𝒪 ⟹ ((open_set.map f) ⋙ F.𝒪)) @[extensionality] lemma ext {F G : Presheaf.{u v} C} (α β : Presheaf_hom F G) (w : α.f = β.f) (h : α.c ⊟ (whisker_on_right (open_set.map_iso _ _ w).hom F.𝒪) = β.c) : α = β := begin cases α, cases β, dsimp at w, subst w, congr, ext, have h' := congr_fun (congr_arg nat_trans.app h) X, dsimp at h', dsimp [open_set.map_iso, whisker_on_right, whiskering_on_right, nat_iso.of_components, nat_trans.hcomp] at h', simp at h', dsimp at h', rw category.comp_id at h', exact h' end. namespace Presheaf_hom def id (F : Presheaf.{u v} C) : Presheaf_hom F F := { f := 𝟙 F.X, c := ((functor.id_comp _).inv) ⊟ (whisker_on_right (open_set.map_id _).inv _) } def comp {F G H : Presheaf.{u v} C} (α : Presheaf_hom F G) (β : Presheaf_hom G H) : Presheaf_hom F H := { f := α.f ≫ β.f, c := β.c ⊟ (whisker_on_left (open_set.map β.f) α.c) } /- I tried to break out the axioms for `category (Presheaf C)` below as lemmas here, but mysteriously `ext` (nor `apply ext`) doesn't work here! -/ -- lemma comp_id {F G : Presheaf.{u v} C} (α : Presheaf_hom F G) : @comp C _ _ _ _ α (id G) = α := -- begin -- -- ext1, -- why is this failing here, but okay below?! -- sorry -- end. -- lemma id_comp {F G : Presheaf.{u v} C} (α : Presheaf_hom F G) : comp (id F) α = α := -- sorry -- lemma assoc {F G H K : Presheaf.{u v} C} (α : Presheaf_hom F G) (β : Presheaf_hom G H) (γ : Presheaf_hom H K) : -- comp (comp α β) γ = comp α (comp β γ) := sorry end Presheaf_hom variables (C) instance category_of_presheaves : category (Presheaf.{u v} C) := { hom := Presheaf_hom, id := Presheaf_hom.id, comp := @Presheaf_hom.comp C _, comp_id' := λ X Y f, begin ext1, -- Check the comorphisms ext1, -- compare natural transformations componentwise dsimp [Presheaf_hom.id, Presheaf_hom.comp], dsimp [whisker_on_right, whiskering_on_right, whisker_on_left, whiskering_on_left], simp, erw [category_theory.functor.map_id], simp, cases X_1, -- Why do we need to do cases before we can finish??! simp, refl, -- Check the functions dsimp [Presheaf_hom.id, Presheaf_hom.comp], simp, end, id_comp' := λ X Y f, begin ext1, -- Check the comorphisms ext1, -- compare natural transformations componentwise dsimp [Presheaf_hom.id, Presheaf_hom.comp], dsimp [whisker_on_right, whiskering_on_right, whisker_on_left, whiskering_on_left], simp, erw [category_theory.functor.map_id, category.comp_id, category.comp_id], -- Check the functions dsimp [Presheaf_hom.id, Presheaf_hom.comp], simp, end, assoc' := λ W X Y Z f g h, begin ext1, swap, -- Check the functions { dsimp [Presheaf_hom.comp], simp only [category.assoc, eq_self_iff_true], }, -- Check the comorphisms { ext1, dsimp only [Presheaf_hom.comp, whisker_on_right, whiskering_on_right, whisker_on_left, whiskering_on_left, open_set.map_iso, nat_iso.of_components], dsimp, -- This is really slow. simp only [category.assoc, category_theory.functor.map_id, category.comp_id], erw [category_theory.functor.map_id], erw [category_theory.functor.map_id], erw [category.comp_id], erw [category.comp_id], erw [category.id_comp] }, end }. namespace Presheaf_hom @[simp] lemma id_f (F : Presheaf.{u v} C) : ((𝟙 F) : F ⟶ F).f = 𝟙 F.X := rfl @[simp] lemma id_c (F : Presheaf.{u v} C) : ((𝟙 F) : F ⟶ F).c = (((functor.id_comp _).inv) ⊟ (whisker_on_right (open_set.map_id _).inv _)) := rfl @[simp] lemma comp_f {F G H : Presheaf.{u v} C} (α : F ⟶ G) (β : G ⟶ H) : (α ≫ β).f = α.f ≫ β.f := rfl @[simp] lemma comp_c {F G H : Presheaf.{u v} C} (α : F ⟶ G) (β : G ⟶ H) : (α ≫ β).c = (β.c ⊟ (whisker_on_left (open_set.map β.f) α.c)) := rfl end Presheaf_hom end category_theory.presheaves
f3ba2a0e7a0f01e1441b2bcfc703cd2d6f2c0e47
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/category_theory/concrete_category/bundled_hom.lean
df097a786d24e2dc2bea40b4014519098a6d0cea
[ "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
5,740
lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Yury Kudryashov -/ import category_theory.concrete_category.basic import category_theory.concrete_category.bundled /-! # Category instances for algebraic structures that use bundled homs. Many algebraic structures in Lean initially used unbundled homs (e.g. a bare function between types, along with an `is_monoid_hom` typeclass), but the general trend is towards using bundled homs. This file provides a basic infrastructure to define concrete categories using bundled homs, and define forgetful functors between them. -/ universes u namespace category_theory variables {c : Type u → Type u} (hom : Π ⦃α β : Type u⦄ (Iα : c α) (Iβ : c β), Type u) /-- Class for bundled homs. Note that the arguments order follows that of lemmas for `monoid_hom`. This way we can use `⟨@monoid_hom.to_fun, @monoid_hom.id ...⟩` in an instance. -/ structure bundled_hom := (to_fun : Π {α β : Type u} (Iα : c α) (Iβ : c β), hom Iα Iβ → α → β) (id : Π {α : Type u} (I : c α), hom I I) (comp : Π {α β γ : Type u} (Iα : c α) (Iβ : c β) (Iγ : c γ), hom Iβ Iγ → hom Iα Iβ → hom Iα Iγ) (hom_ext : ∀ {α β : Type u} (Iα : c α) (Iβ : c β), function.injective (to_fun Iα Iβ) . obviously) (id_to_fun : ∀ {α : Type u} (I : c α), to_fun I I (id I) = _root_.id . obviously) (comp_to_fun : ∀ {α β γ : Type u} (Iα : c α) (Iβ : c β) (Iγ : c γ) (f : hom Iα Iβ) (g : hom Iβ Iγ), to_fun Iα Iγ (comp Iα Iβ Iγ g f) = (to_fun Iβ Iγ g) ∘ (to_fun Iα Iβ f) . obviously) attribute [class] bundled_hom attribute [simp] bundled_hom.id_to_fun bundled_hom.comp_to_fun namespace bundled_hom variable [𝒞 : bundled_hom hom] include 𝒞 /-- Every `@bundled_hom c _` defines a category with objects in `bundled c`. This instance generates the type-class problem `bundled_hom ?m` (which is why this is marked as `[nolint]`). Currently that is not a problem, as there are almost no instances of `bundled_hom`. -/ @[nolint dangerous_instance] instance category : category (bundled c) := by refine { hom := λ X Y, @hom X Y X.str Y.str, id := λ X, @bundled_hom.id c hom 𝒞 X X.str, comp := λ X Y Z f g, @bundled_hom.comp c hom 𝒞 X Y Z X.str Y.str Z.str g f, comp_id' := _, id_comp' := _, assoc' := _}; intros; apply 𝒞.hom_ext; simp only [𝒞.id_to_fun, 𝒞.comp_to_fun, function.left_id, function.right_id] /-- A category given by `bundled_hom` is a concrete category. This instance generates the type-class problem `bundled_hom ?m` (which is why this is marked as `[nolint]`). Currently that is not a problem, as there are almost no instances of `bundled_hom`. -/ @[nolint dangerous_instance] instance : concrete_category.{u} (bundled c) := { forget := { obj := λ X, X, map := λ X Y f, 𝒞.to_fun X.str Y.str f, map_id' := λ X, 𝒞.id_to_fun X.str, map_comp' := by intros; erw 𝒞.comp_to_fun; refl }, forget_faithful := { map_injective' := by intros; apply 𝒞.hom_ext } } variables {hom} local attribute [instance] concrete_category.has_coe_to_fun /-- A version of `has_forget₂.mk'` for categories defined using `@bundled_hom`. -/ def mk_has_forget₂ {d : Type u → Type u} {hom_d : Π ⦃α β : Type u⦄ (Iα : d α) (Iβ : d β), Type u} [bundled_hom hom_d] (obj : Π ⦃α⦄, c α → d α) (map : Π {X Y : bundled c}, (X ⟶ Y) → ((bundled.map obj X) ⟶ (bundled.map obj Y))) (h_map : ∀ {X Y : bundled c} (f : X ⟶ Y), (map f : X → Y) = f) : has_forget₂ (bundled c) (bundled d) := has_forget₂.mk' (bundled.map @obj) (λ _, rfl) @map (by intros; apply heq_of_eq; apply h_map) variables {d : Type u → Type u} variables (hom) section omit 𝒞 /-- The `hom` corresponding to first forgetting along `F`, then taking the `hom` associated to `c`. For typical usage, see the construction of `CommMon` from `Mon`. -/ @[reducible] def map_hom (F : Π {α}, d α → c α) : Π ⦃α β : Type u⦄ (Iα : d α) (Iβ : d β), Type u := λ α β iα iβ, hom (F iα) (F iβ) end /-- Construct the `bundled_hom` induced by a map between type classes. This is useful for building categories such as `CommMon` from `Mon`. -/ def map (F : Π {α}, d α → c α) : bundled_hom (map_hom hom @F) := { to_fun := λ α β iα iβ f, 𝒞.to_fun (F iα) (F iβ) f, id := λ α iα, 𝒞.id (F iα), comp := λ α β γ iα iβ iγ f g, 𝒞.comp (F iα) (F iβ) (F iγ) f g, hom_ext := λ α β iα iβ f g h, 𝒞.hom_ext (F iα) (F iβ) h } section omit 𝒞 /-- We use the empty `parent_projection` class to label functions like `comm_monoid.to_monoid`, which we would like to use to automatically construct `bundled_hom` instances from. Once we've set up `Mon` as the category of bundled monoids, this allows us to set up `CommMon` by defining an instance ```instance : parent_projection (comm_monoid.to_monoid) := ⟨⟩``` -/ class parent_projection (F : Π {α}, d α → c α) end @[nolint unused_arguments] -- The `parent_projection` typeclass is just a marker, so won't be used. instance bundled_hom_of_parent_projection (F : Π {α}, d α → c α) [parent_projection @F] : bundled_hom (map_hom hom @F) := map hom @F instance forget₂ (F : Π {α}, d α → c α) [parent_projection @F] : has_forget₂ (bundled d) (bundled c) := { forget₂ := { obj := λ X, ⟨X, F X.2⟩, map := λ X Y f, f } } instance forget₂_full (F : Π {α}, d α → c α) [parent_projection @F] : full (forget₂ (bundled d) (bundled c)) := { preimage := λ X Y f, f } end bundled_hom end category_theory
78f6bf6f05da393553dd4d0d7c445fed033dbe65
c31182a012eec69da0a1f6c05f42b0f0717d212d
/src/combinatorial_lemma/partition.lean
5a25cbc4b1e8582717bf1a13b8fe7ac60c9c3aab
[]
no_license
Ja1941/lean-liquid
fbec3ffc7fc67df1b5ca95b7ee225685ab9ffbdc
8e80ed0cbdf5145d6814e833a674eaf05a1495c1
refs/heads/master
1,689,437,983,362
1,628,362,719,000
1,628,362,719,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
7,865
lean
import data.real.nnreal import topology.algebra.infinite_sum import topology.instances.ennreal import topology.algebra.monoid open_locale nnreal big_operators open finset /-! # A technical lemma on the way to `lem98` The purpose of this file is to prove the following lemma: ``` lemma exists_partition (N : ℕ) (hN : 0 < N) (f : ℕ → ℝ≥0) (hf : ∀ n, f n ≤ 1) (hf' : summable f) : ∃ (mask : fin N → set ℕ), (∀ n, ∃! i, n ∈ mask i) ∧ (∀ i, ∑' n, set.indicator (mask i) f n ≤ (∑' n, f n) / N + 1) := ``` In disguise, this is `lem98` (`combinatorial_lemma/default.lean`) specialized to `Λ = ℤ`. The proof of the general case makes a reduction to this special case. ## Informal explanation of the statement The lemma `exists_partition` informally says the following: Suppose we have a sequence of real numbers `f 0`, `f 1`, …, all between `0` and `1`, and suppose that `c = ∑ (f i)` exists. Then, for every positive natural number `N`, we can split `f` into `N` subsequences `g 1`, …, `g N`, such that `∑ (g j i) ≤ c/N + 1`. The informal proof is easy: consider `N` buckets, that are initially empty. Now view the numbers `f i` as an incoming stream of numbers, and place each of these in the buckets with the smallest total sum. The formal proof is a bit trickier: we need to make sure that every number ends up in a bucket, we need to show that the final subsequences have a converging sum, etc… We model the subsqeuences by using indicator functions to mask parts of `f` using `N` subsets of `ℕ` (`mask` in the statement). In `recursion_data` below, we setup the `N` buckets, and define the recursion step in `recursion_data_succ`. The rest of the file consists of assembling the pieces. -/ namespace combinatorial_lemma /-- A data structure for recording partial sums of subsequences of a sequence of real numbers, such that all the partial sums are rougly the same size. The field `m` records to which partial sum the next entry in the sequence will be added. -/ structure recursion_data (N : ℕ) (hN : 0 < N) (f : ℕ → ℝ≥0) (hf : ∀ n, f n ≤ 1) (k : ℕ) := (m : fin N → Prop) (hm : ∃! i, m i) (partial_sums : fin N → ℝ≥0) (h₁ : ∑ i, partial_sums i = ∑ n in range (k + 1), f n) (h₂ : ∀ i, partial_sums i ≤ (∑ n in range (k + 1), f n) / N + 1) [dec_inst : ∀ i, decidable (m i)] attribute [instance] recursion_data.dec_inst /-- The starting point for recursively constructing subsequences of a sequence of real numbers such that all the subsequences sum to be roughly the same size: we start by placing the first element of the sequence into the subsequence `0`. -/ def recursion_data_zero (N : ℕ) (hN : 0 < N) (f : ℕ → ℝ≥0) (hf : ∀ n, f n ≤ 1) : recursion_data N hN f hf 0 := { m := λ j, j = ⟨0, hN⟩, hm := ⟨_, rfl, λ _, id⟩, partial_sums := λ j, if j = ⟨0, hN⟩ then f 0 else 0, h₁ := by simp only [sum_ite_eq', if_true, mem_univ, sum_singleton, range_one], h₂ := begin intros i, split_ifs, { simp only [sum_singleton, range_one], refine (hf 0).trans _, exact self_le_add_left 1 (f 0 / ↑N) }, { exact zero_le' } end } instance (N : ℕ) (hN : 0 < N) (f : ℕ → ℝ≥0) (hf : ∀ n, f n ≤ 1) : inhabited (recursion_data N hN f hf 0) := ⟨recursion_data_zero N hN f hf⟩ /-- Given partial sums of subsequences up to the `k`-th element in a sequence of real numbers, add the `k+1`st element to the smallest partial sum so far. -/ noncomputable def recursion_data_succ (N : ℕ) (hN : 0 < N) (f : ℕ → ℝ≥0) (hf : ∀ n, f n ≤ 1) (k : ℕ) (dat : recursion_data N hN f hf k) : recursion_data N hN f hf (k + 1) := let I := (finset.univ : finset (fin N)).exists_min_image dat.partial_sums ⟨⟨0, hN⟩, finset.mem_univ _⟩ in { m := λ j, j = I.some, hm := ⟨I.some, rfl, λ _, id⟩, partial_sums := λ i, dat.partial_sums i + (if i = I.some then f (k + 1) else 0), h₁ := begin rw sum_range_succ _ (k + 1), simp [finset.sum_add_distrib, dat.h₁, add_comm], end, h₂ := begin intros i, split_ifs, { rw h, have : dat.partial_sums I.some * N ≤ (∑ n in range (k + 1 + 1), f n), { calc dat.partial_sums I.some * N = ∑ i : fin N, dat.partial_sums I.some : _ ... ≤ ∑ i, dat.partial_sums i : _ -- follows from I ... = ∑ n in range (k + 1), f n : dat.h₁ ... ≤ ∑ n in range (k + 1 + 1), f n : _, { simp only [finset.sum_const, finset.card_fin, nsmul_eq_mul, mul_comm] }, { obtain ⟨-, HI⟩ := I.some_spec, apply finset.sum_le_sum, intros j hj, exact HI j hj }, { rw sum_range_succ _ (k + 1), simp } }, have : dat.partial_sums I.some ≤ (∑ n in range (k + 1 + 1), f n) / ↑N, { rwa nnreal.le_div_iff_mul_le, exact_mod_cast hN.ne' }, exact add_le_add this (hf (k + 1)) }, { calc dat.partial_sums i + 0 ≤ (∑ n in range (k + 1), f n) / ↑N + 1 : by simpa using dat.h₂ i ... ≤ (∑ n in range (k + 1 + 1), f n) / ↑N + 1 : add_le_add _ le_rfl, simp only [div_eq_mul_inv, fin.sum_univ_eq_sum_range], refine mul_le_mul' _ le_rfl, simp only [finset.sum_range_succ], exact self_le_add_right _ _ } end } /-- Recursively construct subsequences of a given sequence of real numbers, in such a way that the sums of the subsequences are all roughly of the same size. -/ noncomputable def partition (N : ℕ) (hN : 0 < N) (f : ℕ → ℝ≥0) (hf : ∀ n, f n ≤ 1) : Π i : ℕ, (recursion_data N hN f hf i) | 0 := recursion_data_zero N hN f hf | (k + 1) := recursion_data_succ N hN f hf k (partition k) lemma partition_sums_aux (k : ℕ) (N : ℕ) (hN : 0 < N) (f : ℕ → ℝ≥0) (hf : ∀ n, f n ≤ 1) (i : fin N) : (partition N hN f hf (k + 1)).partial_sums i = (partition N hN f hf k).partial_sums i + if (partition N hN f hf (k + 1)).m i then f (k + 1) else 0 := by simp [partition, recursion_data_succ] lemma partition_sums (k : ℕ) (N : ℕ) (hN : 0 < N) (f : ℕ → ℝ≥0) (hf : ∀ n, f n ≤ 1) (i : fin N) : (partition N hN f hf k).partial_sums i = ∑ n in range (k + 1), set.indicator {k | (partition N hN f hf k).m i} f n := begin induction k with k IH, { dsimp [partition], simp, dsimp [partition, recursion_data_zero], congr }, rw [partition_sums_aux, IH, sum_range_succ _ k.succ, set.indicator, add_right_inj], congr' 1, end lemma exists_partition (N : ℕ) (hN : 0 < N) (f : ℕ → ℝ≥0) (hf : ∀ n, f n ≤ 1) (hf' : summable f) : ∃ (mask : fin N → set ℕ), (∀ n, ∃! i, n ∈ mask i) ∧ (∀ i, ∑' n, set.indicator (mask i) f n ≤ (∑' n, f n) / N + 1) := begin let mask : fin N → ℕ → Prop := λ i, {n | (partition N hN f hf n).m i}, have h_sum : ∀ k i, ∑ n in range k, set.indicator (mask i) f n ≤ (∑ n in range k, f n) / N + 1, { rintros ⟨k⟩ i, { simp [mask] }, rw ← partition_sums k N hN f hf i, exact (partition N hN f hf k).h₂ i, }, refine ⟨mask, _, _⟩, { intros n, exact (partition N hN f hf n).hm }, { intros i, set S₁ : ℝ≥0 := ∑' (n : ℕ), f n, have hf'' : has_sum f S₁ := hf'.has_sum, have hf''' : has_sum _ (S₁ / N) := hf''.mul_right (N:ℝ≥0)⁻¹, have : set.indicator (mask i) f ≤ f, { intros n, dsimp [set.indicator], split_ifs, exacts [le_rfl, zero_le'] }, obtain ⟨S₂, -, h_mask⟩ := nnreal.exists_le_has_sum_of_le this hf'', rw h_mask.tsum_eq, rw nnreal.has_sum_iff_tendsto_nat at hf''' h_mask, have := filter.tendsto.add_const 1 hf''', apply le_of_tendsto_of_tendsto' h_mask this, intros n, simp only [div_eq_mul_inv, finset.sum_mul] at h_sum ⊢, exact h_sum n i } end end combinatorial_lemma #lint-
4ea06176a9b70e134809f2558eef8151dd7a9389
e30ff3aabdac29f8ea40ad76887544d0f9be9018
/ircbot/default.lean
5bfcd1631438680532ef5197d596b6ed323b2634
[]
no_license
forked-from-1kasper/leanbot
bdef0efa3e4d0eb75b06c1707fb4e35086bb57fa
c61c8c7fdad7b05877e0d232719ce23d2999557f
refs/heads/master
1,651,846,081,986
1,646,404,009,000
1,646,404,009,000
127,132,795
12
1
null
1,605,183,650,000
1,522,237,998,000
Lean
UTF-8
Lean
false
false
79
lean
import ircbot.types ircbot.effects ircbot.support ircbot.login ircbot.datetime
3cb131dbfd0ee5e5f57fcd5a314fbda19662bc68
80162757f50b09d3cad5564907e4c9b00742e045
/quot.lean
3395f1ca084e421e0992a1696055bda036baa3b8
[]
no_license
EdAyers/edlib
cc30d0a54fed347a85b6df6045f68e6b48bc71a3
78b8c5d91f023f939c102837d748868e2f3ed27d
refs/heads/master
1,586,459,758,216
1,571,322,179,000
1,571,322,179,000
160,538,917
2
0
null
null
null
null
UTF-8
Lean
false
false
19
lean
#check quot.lift_on
28cfcb9471f56ca9a01748f68b91344051f4ac84
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/data/qpf/multivariate/constructions/fix.lean
381e335d8faffbed5a11680c88d1b0282df6b609
[]
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
11,674
lean
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Jeremy Avigad, Simon Hudon -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.pfunctor.multivariate.W import Mathlib.data.qpf.multivariate.basic import Mathlib.PostPort universes u u_1 namespace Mathlib /-! # The initial algebra of a multivariate qpf is again a qpf. For a `(n+1)`-ary QPF `F (α₀,..,αₙ)`, we take the least fixed point of `F` with regards to its last argument `αₙ`. The result is a `n`-ary functor: `fix F (α₀,..,αₙ₋₁)`. Making `fix F` into a functor allows us to take the fixed point, compose with other functors and take a fixed point again. ## Main definitions * `fix.mk` - constructor * `fix.dest - destructor * `fix.rec` - recursor: basis for defining functions by structural recursion on `fix F α` * `fix.drec` - dependent recursor: generalization of `fix.rec` where the result type of the function is allowed to dependent on the `fix F α` value * `fix.rec_eq` - defining equation for `recursor` * `fix.ind` - induction principle for `fix F α` ## Implementation notes For `F` a QPF`, we define `fix F α` in terms of the W-type of the polynomial functor `P` of `F`. We define the relation `Wequiv` and take its quotient as the definition of `fix F α`. ```lean inductive Wequiv {α : typevec n} : q.P.W α → q.P.W α → Prop | ind (a : q.P.A) (f' : q.P.drop.B a ⟹ α) (f₀ f₁ : q.P.last.B a → q.P.W α) : (∀ x, Wequiv (f₀ x) (f₁ x)) → Wequiv (q.P.W_mk a f' f₀) (q.P.W_mk a f' f₁) | abs (a₀ : q.P.A) (f'₀ : q.P.drop.B a₀ ⟹ α) (f₀ : q.P.last.B a₀ → q.P.W α) (a₁ : q.P.A) (f'₁ : q.P.drop.B a₁ ⟹ α) (f₁ : q.P.last.B a₁ → q.P.W α) : abs ⟨a₀, q.P.append_contents f'₀ f₀⟩ = abs ⟨a₁, q.P.append_contents f'₁ f₁⟩ → Wequiv (q.P.W_mk a₀ f'₀ f₀) (q.P.W_mk a₁ f'₁ f₁) | trans (u v w : q.P.W α) : Wequiv u v → Wequiv v w → Wequiv u w ``` See [avigad-carneiro-hudon2019] for more details. ## Reference * [Jeremy Avigad, Mario M. Carneiro and Simon Hudon, *Data Types as Quotients of Polynomial Functors*][avigad-carneiro-hudon2019] -/ namespace mvqpf /-- `recF` is used as a basis for defining the recursor on `fix F α`. `recF` traverses recursively the W-type generated by `q.P` using a function on `F` as a recursive step -/ def recF {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} {β : Type u} (g : F (α ::: β) → β) : mvpfunctor.W (P F) α → β := mvpfunctor.W_rec (P F) fun (a : mvpfunctor.A (P F)) (f' : typevec.arrow (mvpfunctor.B (mvpfunctor.drop (P F)) a) α) (f : pfunctor.B (mvpfunctor.last (P F)) a → mvpfunctor.W (P F) α) (rec : pfunctor.B (mvpfunctor.last (P F)) a → β) => g (abs (sigma.mk a (typevec.split_fun f' rec))) theorem recF_eq {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} {β : Type u} (g : F (α ::: β) → β) (a : mvpfunctor.A (P F)) (f' : typevec.arrow (mvpfunctor.B (mvpfunctor.drop (P F)) a) α) (f : pfunctor.B (mvpfunctor.last (P F)) a → mvpfunctor.W (P F) α) : recF g (mvpfunctor.W_mk (P F) a f' f) = g (abs (sigma.mk a (typevec.split_fun f' (recF g ∘ f)))) := sorry theorem recF_eq' {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} {β : Type u} (g : F (α ::: β) → β) (x : mvpfunctor.W (P F) α) : recF g x = g (abs (mvfunctor.map (typevec.id ::: recF g) (mvpfunctor.W_dest' (P F) x))) := sorry /-- Equivalence relation on W-types that represent the same `fix F` value -/ inductive Wequiv {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} : mvpfunctor.W (P F) α → mvpfunctor.W (P F) α → Prop where | ind : ∀ (a : mvpfunctor.A (P F)) (f' : typevec.arrow (mvpfunctor.B (mvpfunctor.drop (P F)) a) α) (f₀ f₁ : pfunctor.B (mvpfunctor.last (P F)) a → mvpfunctor.W (P F) α), (∀ (x : pfunctor.B (mvpfunctor.last (P F)) a), Wequiv (f₀ x) (f₁ x)) → Wequiv (mvpfunctor.W_mk (P F) a f' f₀) (mvpfunctor.W_mk (P F) a f' f₁) | abs : ∀ (a₀ : mvpfunctor.A (P F)) (f'₀ : typevec.arrow (mvpfunctor.B (mvpfunctor.drop (P F)) a₀) α) (f₀ : pfunctor.B (mvpfunctor.last (P F)) a₀ → mvpfunctor.W (P F) α) (a₁ : mvpfunctor.A (P F)) (f'₁ : typevec.arrow (mvpfunctor.B (mvpfunctor.drop (P F)) a₁) α) (f₁ : pfunctor.B (mvpfunctor.last (P F)) a₁ → mvpfunctor.W (P F) α), abs (sigma.mk a₀ (mvpfunctor.append_contents (P F) f'₀ f₀)) = abs (sigma.mk a₁ (mvpfunctor.append_contents (P F) f'₁ f₁)) → Wequiv (mvpfunctor.W_mk (P F) a₀ f'₀ f₀) (mvpfunctor.W_mk (P F) a₁ f'₁ f₁) | trans : ∀ (u v w : mvpfunctor.W (P F) α), Wequiv u v → Wequiv v w → Wequiv u w theorem recF_eq_of_Wequiv {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] (α : typevec n) {β : Type u} (u : F (α ::: β) → β) (x : mvpfunctor.W (P F) α) (y : mvpfunctor.W (P F) α) : Wequiv x y → recF u x = recF u y := sorry theorem Wequiv.abs' {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} (x : mvpfunctor.W (P F) α) (y : mvpfunctor.W (P F) α) (h : abs (mvpfunctor.W_dest' (P F) x) = abs (mvpfunctor.W_dest' (P F) y)) : Wequiv x y := sorry theorem Wequiv.refl {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} (x : mvpfunctor.W (P F) α) : Wequiv x x := sorry theorem Wequiv.symm {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} (x : mvpfunctor.W (P F) α) (y : mvpfunctor.W (P F) α) : Wequiv x y → Wequiv y x := sorry /-- maps every element of the W type to a canonical representative -/ def Wrepr {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} : mvpfunctor.W (P F) α → mvpfunctor.W (P F) α := recF (mvpfunctor.W_mk' (P F) ∘ repr) theorem Wrepr_W_mk {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} (a : mvpfunctor.A (P F)) (f' : typevec.arrow (mvpfunctor.B (mvpfunctor.drop (P F)) a) α) (f : pfunctor.B (mvpfunctor.last (P F)) a → mvpfunctor.W (P F) α) : Wrepr (mvpfunctor.W_mk (P F) a f' f) = mvpfunctor.W_mk' (P F) (repr (abs (mvfunctor.map (typevec.id ::: Wrepr) (sigma.mk a (mvpfunctor.append_contents (P F) f' f))))) := sorry theorem Wrepr_equiv {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} (x : mvpfunctor.W (P F) α) : Wequiv (Wrepr x) x := sorry theorem Wequiv_map {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} {β : typevec n} (g : typevec.arrow α β) (x : mvpfunctor.W (P F) α) (y : mvpfunctor.W (P F) α) : Wequiv x y → Wequiv (mvfunctor.map g x) (mvfunctor.map g y) := sorry /-- Define the fixed point as the quotient of trees under the equivalence relation. -/ def W_setoid {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] (α : typevec n) : setoid (mvpfunctor.W (P F) α) := setoid.mk Wequiv sorry /-- Least fixed point of functor F. The result is a functor with one fewer parameters than the input. For `F a b c` a ternary functor, fix F is a binary functor such that ```lean fix F a b = F a b (fix F a b) ``` -/ def fix {n : ℕ} (F : typevec (n + 1) → Type u_1) [mvfunctor F] [q : mvqpf F] (α : typevec n) := quotient (W_setoid α) /-- `fix F` is a functor -/ def fix.map {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} {β : typevec n} (g : typevec.arrow α β) : fix F α → fix F β := quotient.lift (fun (x : mvpfunctor.W (P F) α) => quotient.mk (mvpfunctor.W_map (P F) g x)) sorry protected instance fix.mvfunctor {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] : mvfunctor (fix F) := mvfunctor.mk fix.map /-- Recursor for `fix F` -/ def fix.rec {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} {β : Type u} (g : F (α ::: β) → β) : fix F α → β := Quot.lift (recF g) (recF_eq_of_Wequiv α g) /-- Access W-type underlying `fix F` -/ def fix_to_W {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} : fix F α → mvpfunctor.W (P F) α := quotient.lift Wrepr sorry /-- Constructor for `fix F` -/ def fix.mk {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} (x : F (α ::: fix F α)) : fix F α := Quot.mk setoid.r (mvpfunctor.W_mk' (P F) (mvfunctor.map (typevec.id ::: fix_to_W) (repr x))) /-- Destructor for `fix F` -/ def fix.dest {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} : fix F α → F (α ::: fix F α) := fix.rec (mvfunctor.map (typevec.id ::: fix.mk)) theorem fix.rec_eq {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} {β : Type u} (g : F (α ::: β) → β) (x : F (α ::: fix F α)) : fix.rec g (fix.mk x) = g (mvfunctor.map (typevec.id ::: fix.rec g) x) := sorry theorem fix.ind_aux {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} (a : mvpfunctor.A (P F)) (f' : typevec.arrow (mvpfunctor.B (mvpfunctor.drop (P F)) a) α) (f : pfunctor.B (mvpfunctor.last (P F)) a → mvpfunctor.W (P F) α) : fix.mk (abs (sigma.mk a (mvpfunctor.append_contents (P F) f' fun (x : pfunctor.B (mvpfunctor.last (P F)) a) => quotient.mk (f x)))) = quotient.mk (mvpfunctor.W_mk (P F) a f' f) := sorry theorem fix.ind_rec {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} {β : Type u} (g₁ : fix F α → β) (g₂ : fix F α → β) (h : ∀ (x : F (α ::: fix F α)), mvfunctor.map (typevec.id ::: g₁) x = mvfunctor.map (typevec.id ::: g₂) x → g₁ (fix.mk x) = g₂ (fix.mk x)) (x : fix F α) : g₁ x = g₂ x := sorry theorem fix.rec_unique {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} {β : Type u} (g : F (α ::: β) → β) (h : fix F α → β) (hyp : ∀ (x : F (α ::: fix F α)), h (fix.mk x) = g (mvfunctor.map (typevec.id ::: h) x)) : fix.rec g = h := sorry theorem fix.mk_dest {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} (x : fix F α) : fix.mk (fix.dest x) = x := sorry theorem fix.dest_mk {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} (x : F (α ::: fix F α)) : fix.dest (fix.mk x) = x := sorry theorem fix.ind {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} (p : fix F α → Prop) (h : ∀ (x : F (α ::: fix F α)), mvfunctor.liftp (typevec.pred_last α p) x → p (fix.mk x)) (x : fix F α) : p x := sorry protected instance mvqpf_fix {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] : mvqpf (fix F) := mk (mvpfunctor.Wp (P F)) (fun (α : typevec n) => Quot.mk Wequiv) (fun (α : typevec n) => fix_to_W) sorry sorry /-- Dependent recursor for `fix F` -/ def fix.drec {n : ℕ} {F : typevec (n + 1) → Type u} [mvfunctor F] [q : mvqpf F] {α : typevec n} {β : fix F α → Type u} (g : (x : F (α ::: sigma β)) → β (fix.mk (mvfunctor.map (typevec.id ::: sigma.fst) x))) (x : fix F α) : β x := let y : sigma β := fix.rec (fun (i : F (α ::: sigma β)) => sigma.mk (fix.mk (mvfunctor.map (typevec.id ::: sigma.fst) i)) (g i)) x; (fun (this : x = sigma.fst y) => cast sorry (sigma.snd y)) sorry
cd679d7e2c37b46aaae8dc5c98a299a44de07ba3
1437b3495ef9020d5413178aa33c0a625f15f15f
/category_theory/limits/cones.lean
f3da03f2aee450f5a50565fbe1d616cfeea7eece
[ "Apache-2.0" ]
permissive
jean002/mathlib
c66bbb2d9fdc9c03ae07f869acac7ddbfce67a30
dc6c38a765799c99c4d9c8d5207d9e6c9e0e2cfd
refs/heads/master
1,587,027,806,375
1,547,306,358,000
1,547,306,358,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
8,795
lean
-- Copyright (c) 2017 Scott Morrison. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Authors: Stephen Morgan, Scott Morrison import category_theory.natural_isomorphism import category_theory.whiskering import category_theory.const import category_theory.opposites import category_theory.yoneda universes v u u' -- declare the `v`'s first; see `category_theory.category` for an explanation open category_theory variables {J : Type v} [small_category J] variables {C : Type u} [𝒞 : category.{v} C] include 𝒞 open category_theory open category_theory.category open category_theory.functor namespace category_theory namespace functor variables {J C} (F : J ⥤ C) /-- `F.cones` is the functor assigning to an object `X` the type of natural transformations from the constant functor with value `X` to `F`. An object representing this functor is a limit of `F`. -/ def cones : Cᵒᵖ ⥤ Type v := ((const (Jᵒᵖ)) ⋙ (op_inv J C)) ⋙ (yoneda.obj F) lemma cones_obj (X : C) : F.cones.obj X = ((const J).obj X ⟹ F) := rfl /-- `F.cocones` is the functor assigning to an object `X` the type of natural transformations from `F` to the constant functor with value `X`. An object corepresenting this functor is a colimit of `F`. -/ def cocones : C ⥤ Type v := (const J) ⋙ (coyoneda.obj F) lemma cocones_obj (X : C) : F.cocones.obj X = (F ⟹ (const J).obj X) := rfl end functor section variables (J C) def cones : (J ⥤ C) ⥤ (Cᵒᵖ ⥤ Type v) := { obj := functor.cones, map := λ F G f, whisker_left _ (yoneda.map f) } def cocones : (J ⥤ C)ᵒᵖ ⥤ (C ⥤ Type v) := { obj := functor.cocones, map := λ F G f, whisker_left _ (coyoneda.map f) } variables {J C} @[simp] lemma cones_obj (F : J ⥤ C) : (cones J C).obj F = F.cones := rfl @[simp] lemma cones_map {F G : J ⥤ C} {f : F ⟶ G} : (cones J C).map f = (whisker_left _ (yoneda.map f)) := rfl @[simp] lemma cocones_obj (F : J ⥤ C) : (cocones J C).obj F = F.cocones := rfl @[simp] lemma cocones_map {F G : J ⥤ C} {f : F ⟶ G} : (cocones J C).map f = (whisker_left _ (coyoneda.map f)) := rfl end namespace limits /-- A `c : cone F` is: * an object `c.X` and * a natural transformation `c.π : c.X ⟹ F` from the constant `c.X` functor to `F`. `cone F` is equivalent, in the obvious way, to `Σ X, F.cones.obj X`. -/ structure cone (F : J ⥤ C) := (X : C) (π : (const J).obj X ⟹ F) @[simp] lemma cone.w {F : J ⥤ C} (c : cone F) {j j' : J} (f : j ⟶ j') : c.π.app j ≫ F.map f = c.π.app j' := by convert ←(c.π.naturality f).symm; apply id_comp /-- A `c : cocone F` is * an object `c.X` and * a natural transformation `c.ι : F ⟹ c.X` from `F` to the constant `c.X` functor. `cocone F` is equivalent, in the obvious way, to `Σ X, F.cocones.obj X`. -/ structure cocone (F : J ⥤ C) := (X : C) (ι : F ⟹ (const J).obj X) @[simp] lemma cocone.w {F : J ⥤ C} (c : cocone F) {j j' : J} (f : j ⟶ j') : F.map f ≫ c.ι.app j' = c.ι.app j := by convert ←(c.ι.naturality f); apply comp_id variables {F : J ⥤ C} namespace cone @[simp] def extensions (c : cone F) : yoneda.obj c.X ⟶ F.cones := { app := λ X f, ((const J).map f) ≫ c.π } /-- A map to the vertex of a cone induces a cone by composition. -/ @[simp] def extend (c : cone F) {X : C} (f : X ⟶ c.X) : cone F := { X := X, π := c.extensions.app X f } def postcompose {G : J ⥤ C} (α : F ⟹ G) (c : cone F) : cone G := { X := c.X, π := c.π ⊟ α } def whisker {K : Type v} [small_category K] (E : K ⥤ J) (c : cone F) : cone (E ⋙ F) := { X := c.X, π := whisker_left E c.π } @[simp] lemma whisker_π_app (c : cone F) {K : Type v} [small_category K] (E : K ⥤ J) (k : K) : (c.whisker E).π.app k = (c.π).app (E.obj k) := rfl end cone namespace cocone @[simp] def extensions (c : cocone F) : coyoneda.obj c.X ⟶ F.cocones := { app := λ X f, c.ι ≫ ((const J).map f), naturality' := by intros X Y f; ext g j; dsimp; rw ←assoc; refl } /-- A map from the vertex of a cocone induces a cocone by composition. -/ @[simp] def extend (c : cocone F) {X : C} (f : c.X ⟶ X) : cocone F := { X := X, ι := c.extensions.app X f } def precompose {G : J ⥤ C} (α : G ⟹ F) (c : cocone F) : cocone G := { X := c.X, ι := α ⊟ c.ι } def whisker {K : Type v} [small_category K] (E : K ⥤ J) (c : cocone F) : cocone (E ⋙ F) := { X := c.X, ι := whisker_left E c.ι } @[simp] lemma whisker_ι_app (c : cocone F) {K : Type v} [small_category K] (E : K ⥤ J) (k : K) : (c.whisker E).ι.app k = (c.ι).app (E.obj k) := rfl end cocone structure cone_morphism (A B : cone F) := (hom : A.X ⟶ B.X) (w' : ∀ j : J, hom ≫ B.π.app j = A.π.app j . obviously) restate_axiom cone_morphism.w' attribute [simp] cone_morphism.w @[extensionality] lemma cone_morphism.ext {A B : cone F} {f g : cone_morphism A B} (w : f.hom = g.hom) : f = g := by cases f; cases g; simpa using w instance cone.category : category.{v} (cone F) := { hom := λ A B, cone_morphism A B, comp := λ X Y Z f g, { hom := f.hom ≫ g.hom, w' := by intro j; rw [assoc, g.w, f.w] }, id := λ B, { hom := 𝟙 B.X } } namespace cones @[simp] lemma id.hom (c : cone F) : (𝟙 c : cone_morphism c c).hom = 𝟙 (c.X) := rfl @[simp] lemma comp.hom {c d e : cone F} (f : c ⟶ d) (g : d ⟶ e) : (f ≫ g).hom = f.hom ≫ g.hom := rfl /-- To give an isomorphism between cones, it suffices to give an isomorphism between their vertices which commutes with the cone maps. -/ @[extensionality] def ext {c c' : cone F} (φ : c.X ≅ c'.X) (w : ∀ j, c.π.app j = φ.hom ≫ c'.π.app j) : c ≅ c' := { hom := { hom := φ.hom }, inv := { hom := φ.inv, w' := λ j, φ.inv_comp_eq.mpr (w j) } } section variables {D : Type u'} [𝒟 : category.{v} D] include 𝒟 @[simp] def functoriality (G : C ⥤ D) : cone F ⥤ cone (F ⋙ G) := { obj := λ A, { X := G.obj A.X, π := { app := λ j, G.map (A.π.app j), naturality' := by intros; erw ←G.map_comp; tidy } }, map := λ X Y f, { hom := G.map f.hom, w' := by intros; rw [←functor.map_comp, f.w] } } end end cones structure cocone_morphism (A B : cocone F) := (hom : A.X ⟶ B.X) (w' : ∀ j : J, A.ι.app j ≫ hom = B.ι.app j . obviously) restate_axiom cocone_morphism.w' attribute [simp] cocone_morphism.w @[extensionality] lemma cocone_morphism.ext {A B : cocone F} {f g : cocone_morphism A B} (w : f.hom = g.hom) : f = g := by cases f; cases g; simpa using w instance cocone.category : category.{v} (cocone F) := { hom := λ A B, cocone_morphism A B, comp := λ _ _ _ f g, { hom := f.hom ≫ g.hom, w' := by intro j; rw [←assoc, f.w, g.w] }, id := λ B, { hom := 𝟙 B.X } } namespace cocones @[simp] lemma id.hom (c : cocone F) : (𝟙 c : cocone_morphism c c).hom = 𝟙 (c.X) := rfl @[simp] lemma comp.hom {c d e : cocone F} (f : c ⟶ d) (g : d ⟶ e) : (f ≫ g).hom = f.hom ≫ g.hom := rfl /-- To give an isomorphism between cocones, it suffices to give an isomorphism between their vertices which commutes with the cocone maps. -/ @[extensionality] def ext {c c' : cocone F} (φ : c.X ≅ c'.X) (w : ∀ j, c.ι.app j ≫ φ.hom = c'.ι.app j) : c ≅ c' := { hom := { hom := φ.hom }, inv := { hom := φ.inv, w' := λ j, φ.comp_inv_eq.mpr (w j).symm } } section variables {D : Type u'} [𝒟 : category.{v} D] include 𝒟 @[simp] def functoriality (G : C ⥤ D) : cocone F ⥤ cocone (F ⋙ G) := { obj := λ A, { X := G.obj A.X, ι := { app := λ j, G.map (A.ι.app j), naturality' := by intros; erw ←G.map_comp; tidy } }, map := λ _ _ f, { hom := G.map f.hom, w' := by intros; rw [←functor.map_comp, cocone_morphism.w] } } end end cocones end limits namespace functor variables {D : Type u'} [category.{v} D] variables {F : J ⥤ C} {G : J ⥤ C} (H : C ⥤ D) open category_theory.limits /-- The image of a cone in C under a functor G : C ⥤ D is a cone in D. -/ def map_cone (c : cone F) : cone (F ⋙ H) := (cones.functoriality H).obj c /-- The image of a cocone in C under a functor G : C ⥤ D is a cocone in D. -/ def map_cocone (c : cocone F) : cocone (F ⋙ H) := (cocones.functoriality H).obj c def map_cone_morphism {c c' : cone F} (f : cone_morphism c c') : cone_morphism (H.map_cone c) (H.map_cone c') := (cones.functoriality H).map f def map_cocone_morphism {c c' : cocone F} (f : cocone_morphism c c') : cocone_morphism (H.map_cocone c) (H.map_cocone c') := (cocones.functoriality H).map f @[simp] lemma map_cone_π (c : cone F) (j : J) : (map_cone H c).π.app j = H.map (c.π.app j) := rfl @[simp] lemma map_cocone_ι (c : cocone F) (j : J) : (map_cocone H c).ι.app j = H.map (c.ι.app j) := rfl end functor end category_theory
74b283bfda94d6cae8c93fc679b525ff4edf1036
1717bcbca047a0d25d687e7e9cd482fba00d058f
/src/analysis/special_functions/trigonometric.lean
0eb1d02abfb1ae5c110fc20b01cec5ad3c410f62
[ "Apache-2.0" ]
permissive
swapnilkapoor22/mathlib
51ad5804e6a0635ed5c7611cee73e089ab271060
3e7efd4ecd5d379932a89212eebd362beb01309e
refs/heads/master
1,676,467,741,465
1,610,301,556,000
1,610,301,556,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
118,803
lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson -/ import analysis.special_functions.exp_log import data.set.intervals.infinite import algebra.quadratic_discriminant import ring_theory.polynomial.chebyshev.defs /-! # Trigonometric functions ## Main definitions This file contains the following definitions: * π, arcsin, arccos, arctan * argument of a complex number * logarithm on complex numbers ## Main statements Many basic inequalities on trigonometric functions are established. The continuity and differentiability of the usual trigonometric functions are proved, and their derivatives are computed. * `polynomial.chebyshev₁_complex_cos`: the `n`-th Chebyshev polynomial evaluates on `complex.cos θ` to the value `n * complex.cos θ`. ## Tags log, sin, cos, tan, arcsin, arccos, arctan, angle, argument -/ noncomputable theory open_locale classical topological_space filter open set filter namespace complex /-- The complex sine function is everywhere differentiable, with the derivative `cos x`. -/ lemma has_deriv_at_sin (x : ℂ) : has_deriv_at sin (cos x) x := begin simp only [cos, div_eq_mul_inv], convert ((((has_deriv_at_id x).neg.mul_const I).cexp.sub ((has_deriv_at_id x).mul_const I).cexp).mul_const I).mul_const (2:ℂ)⁻¹, simp only [function.comp, id], rw [sub_mul, mul_assoc, mul_assoc, I_mul_I, neg_one_mul, neg_neg, mul_one, one_mul, mul_assoc, I_mul_I, mul_neg_one, sub_neg_eq_add, add_comm] end lemma times_cont_diff_sin {n} : times_cont_diff ℂ n sin := (((times_cont_diff_neg.mul times_cont_diff_const).cexp.sub (times_cont_diff_id.mul times_cont_diff_const).cexp).mul times_cont_diff_const).div_const lemma differentiable_sin : differentiable ℂ sin := λx, (has_deriv_at_sin x).differentiable_at lemma differentiable_at_sin {x : ℂ} : differentiable_at ℂ sin x := differentiable_sin x @[simp] lemma deriv_sin : deriv sin = cos := funext $ λ x, (has_deriv_at_sin x).deriv lemma continuous_sin : continuous sin := differentiable_sin.continuous lemma continuous_on_sin {s : set ℂ} : continuous_on sin s := continuous_sin.continuous_on lemma measurable_sin : measurable sin := continuous_sin.measurable /-- The complex cosine function is everywhere differentiable, with the derivative `-sin x`. -/ lemma has_deriv_at_cos (x : ℂ) : has_deriv_at cos (-sin x) x := begin simp only [sin, div_eq_mul_inv, neg_mul_eq_neg_mul], convert (((has_deriv_at_id x).mul_const I).cexp.add ((has_deriv_at_id x).neg.mul_const I).cexp).mul_const (2:ℂ)⁻¹, simp only [function.comp, id], ring end lemma times_cont_diff_cos {n} : times_cont_diff ℂ n cos := ((times_cont_diff_id.mul times_cont_diff_const).cexp.add (times_cont_diff_neg.mul times_cont_diff_const).cexp).div_const lemma differentiable_cos : differentiable ℂ cos := λx, (has_deriv_at_cos x).differentiable_at lemma differentiable_at_cos {x : ℂ} : differentiable_at ℂ cos x := differentiable_cos x lemma deriv_cos {x : ℂ} : deriv cos x = -sin x := (has_deriv_at_cos x).deriv @[simp] lemma deriv_cos' : deriv cos = (λ x, -sin x) := funext $ λ x, deriv_cos lemma continuous_cos : continuous cos := differentiable_cos.continuous lemma continuous_on_cos {s : set ℂ} : continuous_on cos s := continuous_cos.continuous_on lemma measurable_cos : measurable cos := continuous_cos.measurable /-- The complex hyperbolic sine function is everywhere differentiable, with the derivative `cosh x`. -/ lemma has_deriv_at_sinh (x : ℂ) : has_deriv_at sinh (cosh x) x := begin simp only [cosh, div_eq_mul_inv], convert ((has_deriv_at_exp x).sub (has_deriv_at_id x).neg.cexp).mul_const (2:ℂ)⁻¹, rw [id, mul_neg_one, sub_eq_add_neg, neg_neg] end lemma times_cont_diff_sinh {n} : times_cont_diff ℂ n sinh := (times_cont_diff_exp.sub times_cont_diff_neg.cexp).div_const lemma differentiable_sinh : differentiable ℂ sinh := λx, (has_deriv_at_sinh x).differentiable_at lemma differentiable_at_sinh {x : ℂ} : differentiable_at ℂ sinh x := differentiable_sinh x @[simp] lemma deriv_sinh : deriv sinh = cosh := funext $ λ x, (has_deriv_at_sinh x).deriv lemma continuous_sinh : continuous sinh := differentiable_sinh.continuous lemma measurable_sinh : measurable sinh := continuous_sinh.measurable /-- The complex hyperbolic cosine function is everywhere differentiable, with the derivative `sinh x`. -/ lemma has_deriv_at_cosh (x : ℂ) : has_deriv_at cosh (sinh x) x := begin simp only [sinh, div_eq_mul_inv], convert ((has_deriv_at_exp x).add (has_deriv_at_id x).neg.cexp).mul_const (2:ℂ)⁻¹, rw [id, mul_neg_one, sub_eq_add_neg] end lemma times_cont_diff_cosh {n} : times_cont_diff ℂ n cosh := (times_cont_diff_exp.add times_cont_diff_neg.cexp).div_const lemma differentiable_cosh : differentiable ℂ cosh := λx, (has_deriv_at_cosh x).differentiable_at lemma differentiable_at_cosh {x : ℂ} : differentiable_at ℂ cos x := differentiable_cos x @[simp] lemma deriv_cosh : deriv cosh = sinh := funext $ λ x, (has_deriv_at_cosh x).deriv lemma continuous_cosh : continuous cosh := differentiable_cosh.continuous lemma measurable_cosh : measurable cosh := continuous_cosh.measurable end complex section /-! ### Simp lemmas for derivatives of `λ x, complex.cos (f x)` etc., `f : ℂ → ℂ` -/ variables {f : ℂ → ℂ} {f' x : ℂ} {s : set ℂ} /-! #### `complex.cos` -/ lemma measurable.ccos {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) : measurable (λ x, complex.cos (f x)) := complex.measurable_cos.comp hf lemma has_deriv_at.ccos (hf : has_deriv_at f f' x) : has_deriv_at (λ x, complex.cos (f x)) (- complex.sin (f x) * f') x := (complex.has_deriv_at_cos (f x)).comp x hf lemma has_deriv_within_at.ccos (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, complex.cos (f x)) (- complex.sin (f x) * f') s x := (complex.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf lemma deriv_within_ccos (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : deriv_within (λx, complex.cos (f x)) s x = - complex.sin (f x) * (deriv_within f s x) := hf.has_deriv_within_at.ccos.deriv_within hxs @[simp] lemma deriv_ccos (hc : differentiable_at ℂ f x) : deriv (λx, complex.cos (f x)) x = - complex.sin (f x) * (deriv f x) := hc.has_deriv_at.ccos.deriv /-! #### `complex.sin` -/ lemma measurable.csin {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) : measurable (λ x, complex.sin (f x)) := complex.measurable_sin.comp hf lemma has_deriv_at.csin (hf : has_deriv_at f f' x) : has_deriv_at (λ x, complex.sin (f x)) (complex.cos (f x) * f') x := (complex.has_deriv_at_sin (f x)).comp x hf lemma has_deriv_within_at.csin (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, complex.sin (f x)) (complex.cos (f x) * f') s x := (complex.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf lemma deriv_within_csin (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : deriv_within (λx, complex.sin (f x)) s x = complex.cos (f x) * (deriv_within f s x) := hf.has_deriv_within_at.csin.deriv_within hxs @[simp] lemma deriv_csin (hc : differentiable_at ℂ f x) : deriv (λx, complex.sin (f x)) x = complex.cos (f x) * (deriv f x) := hc.has_deriv_at.csin.deriv /-! #### `complex.cosh` -/ lemma measurable.ccosh {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) : measurable (λ x, complex.cosh (f x)) := complex.measurable_cosh.comp hf lemma has_deriv_at.ccosh (hf : has_deriv_at f f' x) : has_deriv_at (λ x, complex.cosh (f x)) (complex.sinh (f x) * f') x := (complex.has_deriv_at_cosh (f x)).comp x hf lemma has_deriv_within_at.ccosh (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, complex.cosh (f x)) (complex.sinh (f x) * f') s x := (complex.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf lemma deriv_within_ccosh (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : deriv_within (λx, complex.cosh (f x)) s x = complex.sinh (f x) * (deriv_within f s x) := hf.has_deriv_within_at.ccosh.deriv_within hxs @[simp] lemma deriv_ccosh (hc : differentiable_at ℂ f x) : deriv (λx, complex.cosh (f x)) x = complex.sinh (f x) * (deriv f x) := hc.has_deriv_at.ccosh.deriv /-! #### `complex.sinh` -/ lemma measurable.csinh {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) : measurable (λ x, complex.sinh (f x)) := complex.measurable_sinh.comp hf lemma has_deriv_at.csinh (hf : has_deriv_at f f' x) : has_deriv_at (λ x, complex.sinh (f x)) (complex.cosh (f x) * f') x := (complex.has_deriv_at_sinh (f x)).comp x hf lemma has_deriv_within_at.csinh (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, complex.sinh (f x)) (complex.cosh (f x) * f') s x := (complex.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf lemma deriv_within_csinh (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : deriv_within (λx, complex.sinh (f x)) s x = complex.cosh (f x) * (deriv_within f s x) := hf.has_deriv_within_at.csinh.deriv_within hxs @[simp] lemma deriv_csinh (hc : differentiable_at ℂ f x) : deriv (λx, complex.sinh (f x)) x = complex.cosh (f x) * (deriv f x) := hc.has_deriv_at.csinh.deriv end section /-! ### Simp lemmas for derivatives of `λ x, complex.cos (f x)` etc., `f : E → ℂ` -/ variables {E : Type*} [normed_group E] [normed_space ℂ E] {f : E → ℂ} {f' : E →L[ℂ] ℂ} {x : E} {s : set E} /-! #### `complex.cos` -/ lemma has_fderiv_at.ccos (hf : has_fderiv_at f f' x) : has_fderiv_at (λ x, complex.cos (f x)) (- complex.sin (f x) • f') x := (complex.has_deriv_at_cos (f x)).comp_has_fderiv_at x hf lemma has_fderiv_within_at.ccos (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, complex.cos (f x)) (- complex.sin (f x) • f') s x := (complex.has_deriv_at_cos (f x)).comp_has_fderiv_within_at x hf lemma differentiable_within_at.ccos (hf : differentiable_within_at ℂ f s x) : differentiable_within_at ℂ (λ x, complex.cos (f x)) s x := hf.has_fderiv_within_at.ccos.differentiable_within_at @[simp] lemma differentiable_at.ccos (hc : differentiable_at ℂ f x) : differentiable_at ℂ (λx, complex.cos (f x)) x := hc.has_fderiv_at.ccos.differentiable_at lemma differentiable_on.ccos (hc : differentiable_on ℂ f s) : differentiable_on ℂ (λx, complex.cos (f x)) s := λx h, (hc x h).ccos @[simp] lemma differentiable.ccos (hc : differentiable ℂ f) : differentiable ℂ (λx, complex.cos (f x)) := λx, (hc x).ccos lemma fderiv_within_ccos (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : fderiv_within ℂ (λx, complex.cos (f x)) s x = - complex.sin (f x) • (fderiv_within ℂ f s x) := hf.has_fderiv_within_at.ccos.fderiv_within hxs @[simp] lemma fderiv_ccos (hc : differentiable_at ℂ f x) : fderiv ℂ (λx, complex.cos (f x)) x = - complex.sin (f x) • (fderiv ℂ f x) := hc.has_fderiv_at.ccos.fderiv lemma times_cont_diff.ccos {n} (h : times_cont_diff ℂ n f) : times_cont_diff ℂ n (λ x, complex.cos (f x)) := complex.times_cont_diff_cos.comp h lemma times_cont_diff_at.ccos {n} (hf : times_cont_diff_at ℂ n f x) : times_cont_diff_at ℂ n (λ x, complex.cos (f x)) x := complex.times_cont_diff_cos.times_cont_diff_at.comp x hf lemma times_cont_diff_on.ccos {n} (hf : times_cont_diff_on ℂ n f s) : times_cont_diff_on ℂ n (λ x, complex.cos (f x)) s := complex.times_cont_diff_cos.comp_times_cont_diff_on hf lemma times_cont_diff_within_at.ccos {n} (hf : times_cont_diff_within_at ℂ n f s x) : times_cont_diff_within_at ℂ n (λ x, complex.cos (f x)) s x := complex.times_cont_diff_cos.times_cont_diff_at.comp_times_cont_diff_within_at x hf /-! #### `complex.sin` -/ lemma has_fderiv_at.csin (hf : has_fderiv_at f f' x) : has_fderiv_at (λ x, complex.sin (f x)) (complex.cos (f x) • f') x := (complex.has_deriv_at_sin (f x)).comp_has_fderiv_at x hf lemma has_fderiv_within_at.csin (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, complex.sin (f x)) (complex.cos (f x) • f') s x := (complex.has_deriv_at_sin (f x)).comp_has_fderiv_within_at x hf lemma differentiable_within_at.csin (hf : differentiable_within_at ℂ f s x) : differentiable_within_at ℂ (λ x, complex.sin (f x)) s x := hf.has_fderiv_within_at.csin.differentiable_within_at @[simp] lemma differentiable_at.csin (hc : differentiable_at ℂ f x) : differentiable_at ℂ (λx, complex.sin (f x)) x := hc.has_fderiv_at.csin.differentiable_at lemma differentiable_on.csin (hc : differentiable_on ℂ f s) : differentiable_on ℂ (λx, complex.sin (f x)) s := λx h, (hc x h).csin @[simp] lemma differentiable.csin (hc : differentiable ℂ f) : differentiable ℂ (λx, complex.sin (f x)) := λx, (hc x).csin lemma fderiv_within_csin (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : fderiv_within ℂ (λx, complex.sin (f x)) s x = complex.cos (f x) • (fderiv_within ℂ f s x) := hf.has_fderiv_within_at.csin.fderiv_within hxs @[simp] lemma fderiv_csin (hc : differentiable_at ℂ f x) : fderiv ℂ (λx, complex.sin (f x)) x = complex.cos (f x) • (fderiv ℂ f x) := hc.has_fderiv_at.csin.fderiv lemma times_cont_diff.csin {n} (h : times_cont_diff ℂ n f) : times_cont_diff ℂ n (λ x, complex.sin (f x)) := complex.times_cont_diff_sin.comp h lemma times_cont_diff_at.csin {n} (hf : times_cont_diff_at ℂ n f x) : times_cont_diff_at ℂ n (λ x, complex.sin (f x)) x := complex.times_cont_diff_sin.times_cont_diff_at.comp x hf lemma times_cont_diff_on.csin {n} (hf : times_cont_diff_on ℂ n f s) : times_cont_diff_on ℂ n (λ x, complex.sin (f x)) s := complex.times_cont_diff_sin.comp_times_cont_diff_on hf lemma times_cont_diff_within_at.csin {n} (hf : times_cont_diff_within_at ℂ n f s x) : times_cont_diff_within_at ℂ n (λ x, complex.sin (f x)) s x := complex.times_cont_diff_sin.times_cont_diff_at.comp_times_cont_diff_within_at x hf /-! #### `complex.cosh` -/ lemma has_fderiv_at.ccosh (hf : has_fderiv_at f f' x) : has_fderiv_at (λ x, complex.cosh (f x)) (complex.sinh (f x) • f') x := (complex.has_deriv_at_cosh (f x)).comp_has_fderiv_at x hf lemma has_fderiv_within_at.ccosh (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, complex.cosh (f x)) (complex.sinh (f x) • f') s x := (complex.has_deriv_at_cosh (f x)).comp_has_fderiv_within_at x hf lemma differentiable_within_at.ccosh (hf : differentiable_within_at ℂ f s x) : differentiable_within_at ℂ (λ x, complex.cosh (f x)) s x := hf.has_fderiv_within_at.ccosh.differentiable_within_at @[simp] lemma differentiable_at.ccosh (hc : differentiable_at ℂ f x) : differentiable_at ℂ (λx, complex.cosh (f x)) x := hc.has_fderiv_at.ccosh.differentiable_at lemma differentiable_on.ccosh (hc : differentiable_on ℂ f s) : differentiable_on ℂ (λx, complex.cosh (f x)) s := λx h, (hc x h).ccosh @[simp] lemma differentiable.ccosh (hc : differentiable ℂ f) : differentiable ℂ (λx, complex.cosh (f x)) := λx, (hc x).ccosh lemma fderiv_within_ccosh (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : fderiv_within ℂ (λx, complex.cosh (f x)) s x = complex.sinh (f x) • (fderiv_within ℂ f s x) := hf.has_fderiv_within_at.ccosh.fderiv_within hxs @[simp] lemma fderiv_ccosh (hc : differentiable_at ℂ f x) : fderiv ℂ (λx, complex.cosh (f x)) x = complex.sinh (f x) • (fderiv ℂ f x) := hc.has_fderiv_at.ccosh.fderiv lemma times_cont_diff.ccosh {n} (h : times_cont_diff ℂ n f) : times_cont_diff ℂ n (λ x, complex.cosh (f x)) := complex.times_cont_diff_cosh.comp h lemma times_cont_diff_at.ccosh {n} (hf : times_cont_diff_at ℂ n f x) : times_cont_diff_at ℂ n (λ x, complex.cosh (f x)) x := complex.times_cont_diff_cosh.times_cont_diff_at.comp x hf lemma times_cont_diff_on.ccosh {n} (hf : times_cont_diff_on ℂ n f s) : times_cont_diff_on ℂ n (λ x, complex.cosh (f x)) s := complex.times_cont_diff_cosh.comp_times_cont_diff_on hf lemma times_cont_diff_within_at.ccosh {n} (hf : times_cont_diff_within_at ℂ n f s x) : times_cont_diff_within_at ℂ n (λ x, complex.cosh (f x)) s x := complex.times_cont_diff_cosh.times_cont_diff_at.comp_times_cont_diff_within_at x hf /-! #### `complex.sinh` -/ lemma has_fderiv_at.csinh (hf : has_fderiv_at f f' x) : has_fderiv_at (λ x, complex.sinh (f x)) (complex.cosh (f x) • f') x := (complex.has_deriv_at_sinh (f x)).comp_has_fderiv_at x hf lemma has_fderiv_within_at.csinh (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, complex.sinh (f x)) (complex.cosh (f x) • f') s x := (complex.has_deriv_at_sinh (f x)).comp_has_fderiv_within_at x hf lemma differentiable_within_at.csinh (hf : differentiable_within_at ℂ f s x) : differentiable_within_at ℂ (λ x, complex.sinh (f x)) s x := hf.has_fderiv_within_at.csinh.differentiable_within_at @[simp] lemma differentiable_at.csinh (hc : differentiable_at ℂ f x) : differentiable_at ℂ (λx, complex.sinh (f x)) x := hc.has_fderiv_at.csinh.differentiable_at lemma differentiable_on.csinh (hc : differentiable_on ℂ f s) : differentiable_on ℂ (λx, complex.sinh (f x)) s := λx h, (hc x h).csinh @[simp] lemma differentiable.csinh (hc : differentiable ℂ f) : differentiable ℂ (λx, complex.sinh (f x)) := λx, (hc x).csinh lemma fderiv_within_csinh (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : fderiv_within ℂ (λx, complex.sinh (f x)) s x = complex.cosh (f x) • (fderiv_within ℂ f s x) := hf.has_fderiv_within_at.csinh.fderiv_within hxs @[simp] lemma fderiv_csinh (hc : differentiable_at ℂ f x) : fderiv ℂ (λx, complex.sinh (f x)) x = complex.cosh (f x) • (fderiv ℂ f x) := hc.has_fderiv_at.csinh.fderiv lemma times_cont_diff.csinh {n} (h : times_cont_diff ℂ n f) : times_cont_diff ℂ n (λ x, complex.sinh (f x)) := complex.times_cont_diff_sinh.comp h lemma times_cont_diff_at.csinh {n} (hf : times_cont_diff_at ℂ n f x) : times_cont_diff_at ℂ n (λ x, complex.sinh (f x)) x := complex.times_cont_diff_sinh.times_cont_diff_at.comp x hf lemma times_cont_diff_on.csinh {n} (hf : times_cont_diff_on ℂ n f s) : times_cont_diff_on ℂ n (λ x, complex.sinh (f x)) s := complex.times_cont_diff_sinh.comp_times_cont_diff_on hf lemma times_cont_diff_within_at.csinh {n} (hf : times_cont_diff_within_at ℂ n f s x) : times_cont_diff_within_at ℂ n (λ x, complex.sinh (f x)) s x := complex.times_cont_diff_sinh.times_cont_diff_at.comp_times_cont_diff_within_at x hf end namespace real variables {x y z : ℝ} lemma has_deriv_at_sin (x : ℝ) : has_deriv_at sin (cos x) x := (complex.has_deriv_at_sin x).real_of_complex lemma times_cont_diff_sin {n} : times_cont_diff ℝ n sin := complex.times_cont_diff_sin.real_of_complex lemma differentiable_sin : differentiable ℝ sin := λx, (has_deriv_at_sin x).differentiable_at lemma differentiable_at_sin : differentiable_at ℝ sin x := differentiable_sin x @[simp] lemma deriv_sin : deriv sin = cos := funext $ λ x, (has_deriv_at_sin x).deriv lemma continuous_sin : continuous sin := differentiable_sin.continuous lemma measurable_sin : measurable sin := continuous_sin.measurable lemma has_deriv_at_cos (x : ℝ) : has_deriv_at cos (-sin x) x := (complex.has_deriv_at_cos x).real_of_complex lemma times_cont_diff_cos {n} : times_cont_diff ℝ n cos := complex.times_cont_diff_cos.real_of_complex lemma differentiable_cos : differentiable ℝ cos := λx, (has_deriv_at_cos x).differentiable_at lemma differentiable_at_cos : differentiable_at ℝ cos x := differentiable_cos x lemma deriv_cos : deriv cos x = - sin x := (has_deriv_at_cos x).deriv @[simp] lemma deriv_cos' : deriv cos = (λ x, - sin x) := funext $ λ _, deriv_cos lemma continuous_cos : continuous cos := differentiable_cos.continuous lemma continuous_on_cos {s} : continuous_on cos s := continuous_cos.continuous_on lemma measurable_cos : measurable cos := continuous_cos.measurable lemma has_deriv_at_sinh (x : ℝ) : has_deriv_at sinh (cosh x) x := (complex.has_deriv_at_sinh x).real_of_complex lemma times_cont_diff_sinh {n} : times_cont_diff ℝ n sinh := complex.times_cont_diff_sinh.real_of_complex lemma differentiable_sinh : differentiable ℝ sinh := λx, (has_deriv_at_sinh x).differentiable_at lemma differentiable_at_sinh : differentiable_at ℝ sinh x := differentiable_sinh x @[simp] lemma deriv_sinh : deriv sinh = cosh := funext $ λ x, (has_deriv_at_sinh x).deriv lemma continuous_sinh : continuous sinh := differentiable_sinh.continuous lemma measurable_sinh : measurable sinh := continuous_sinh.measurable lemma has_deriv_at_cosh (x : ℝ) : has_deriv_at cosh (sinh x) x := (complex.has_deriv_at_cosh x).real_of_complex lemma times_cont_diff_cosh {n} : times_cont_diff ℝ n cosh := complex.times_cont_diff_cosh.real_of_complex lemma differentiable_cosh : differentiable ℝ cosh := λx, (has_deriv_at_cosh x).differentiable_at lemma differentiable_at_cosh : differentiable_at ℝ cosh x := differentiable_cosh x @[simp] lemma deriv_cosh : deriv cosh = sinh := funext $ λ x, (has_deriv_at_cosh x).deriv lemma continuous_cosh : continuous cosh := differentiable_cosh.continuous lemma measurable_cosh : measurable cosh := continuous_cosh.measurable /-- `sinh` is strictly monotone. -/ lemma sinh_strict_mono : strict_mono sinh := strict_mono_of_deriv_pos differentiable_sinh (by { rw [real.deriv_sinh], exact cosh_pos }) end real section /-! ### Simp lemmas for derivatives of `λ x, real.cos (f x)` etc., `f : ℝ → ℝ` -/ variables {f : ℝ → ℝ} {f' x : ℝ} {s : set ℝ} /-! #### `real.cos` -/ lemma measurable.cos {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) : measurable (λ x, real.cos (f x)) := real.measurable_cos.comp hf lemma has_deriv_at.cos (hf : has_deriv_at f f' x) : has_deriv_at (λ x, real.cos (f x)) (- real.sin (f x) * f') x := (real.has_deriv_at_cos (f x)).comp x hf lemma has_deriv_within_at.cos (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, real.cos (f x)) (- real.sin (f x) * f') s x := (real.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf lemma deriv_within_cos (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : deriv_within (λx, real.cos (f x)) s x = - real.sin (f x) * (deriv_within f s x) := hf.has_deriv_within_at.cos.deriv_within hxs @[simp] lemma deriv_cos (hc : differentiable_at ℝ f x) : deriv (λx, real.cos (f x)) x = - real.sin (f x) * (deriv f x) := hc.has_deriv_at.cos.deriv /-! #### `real.sin` -/ lemma measurable.sin {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) : measurable (λ x, real.sin (f x)) := real.measurable_sin.comp hf lemma has_deriv_at.sin (hf : has_deriv_at f f' x) : has_deriv_at (λ x, real.sin (f x)) (real.cos (f x) * f') x := (real.has_deriv_at_sin (f x)).comp x hf lemma has_deriv_within_at.sin (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, real.sin (f x)) (real.cos (f x) * f') s x := (real.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf lemma deriv_within_sin (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : deriv_within (λx, real.sin (f x)) s x = real.cos (f x) * (deriv_within f s x) := hf.has_deriv_within_at.sin.deriv_within hxs @[simp] lemma deriv_sin (hc : differentiable_at ℝ f x) : deriv (λx, real.sin (f x)) x = real.cos (f x) * (deriv f x) := hc.has_deriv_at.sin.deriv /-! #### `real.cosh` -/ lemma measurable.cosh {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) : measurable (λ x, real.cosh (f x)) := real.measurable_cosh.comp hf lemma has_deriv_at.cosh (hf : has_deriv_at f f' x) : has_deriv_at (λ x, real.cosh (f x)) (real.sinh (f x) * f') x := (real.has_deriv_at_cosh (f x)).comp x hf lemma has_deriv_within_at.cosh (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, real.cosh (f x)) (real.sinh (f x) * f') s x := (real.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf lemma deriv_within_cosh (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : deriv_within (λx, real.cosh (f x)) s x = real.sinh (f x) * (deriv_within f s x) := hf.has_deriv_within_at.cosh.deriv_within hxs @[simp] lemma deriv_cosh (hc : differentiable_at ℝ f x) : deriv (λx, real.cosh (f x)) x = real.sinh (f x) * (deriv f x) := hc.has_deriv_at.cosh.deriv /-! #### `real.sinh` -/ lemma measurable.sinh {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) : measurable (λ x, real.sinh (f x)) := real.measurable_sinh.comp hf lemma has_deriv_at.sinh (hf : has_deriv_at f f' x) : has_deriv_at (λ x, real.sinh (f x)) (real.cosh (f x) * f') x := (real.has_deriv_at_sinh (f x)).comp x hf lemma has_deriv_within_at.sinh (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, real.sinh (f x)) (real.cosh (f x) * f') s x := (real.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf lemma deriv_within_sinh (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : deriv_within (λx, real.sinh (f x)) s x = real.cosh (f x) * (deriv_within f s x) := hf.has_deriv_within_at.sinh.deriv_within hxs @[simp] lemma deriv_sinh (hc : differentiable_at ℝ f x) : deriv (λx, real.sinh (f x)) x = real.cosh (f x) * (deriv f x) := hc.has_deriv_at.sinh.deriv end section /-! ### Simp lemmas for derivatives of `λ x, real.cos (f x)` etc., `f : E → ℝ` -/ variables {E : Type*} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {f' : E →L[ℝ] ℝ} {x : E} {s : set E} /-! #### `real.cos` -/ lemma has_fderiv_at.cos (hf : has_fderiv_at f f' x) : has_fderiv_at (λ x, real.cos (f x)) (- real.sin (f x) • f') x := (real.has_deriv_at_cos (f x)).comp_has_fderiv_at x hf lemma has_fderiv_within_at.cos (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, real.cos (f x)) (- real.sin (f x) • f') s x := (real.has_deriv_at_cos (f x)).comp_has_fderiv_within_at x hf lemma differentiable_within_at.cos (hf : differentiable_within_at ℝ f s x) : differentiable_within_at ℝ (λ x, real.cos (f x)) s x := hf.has_fderiv_within_at.cos.differentiable_within_at @[simp] lemma differentiable_at.cos (hc : differentiable_at ℝ f x) : differentiable_at ℝ (λx, real.cos (f x)) x := hc.has_fderiv_at.cos.differentiable_at lemma differentiable_on.cos (hc : differentiable_on ℝ f s) : differentiable_on ℝ (λx, real.cos (f x)) s := λx h, (hc x h).cos @[simp] lemma differentiable.cos (hc : differentiable ℝ f) : differentiable ℝ (λx, real.cos (f x)) := λx, (hc x).cos lemma fderiv_within_cos (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : fderiv_within ℝ (λx, real.cos (f x)) s x = - real.sin (f x) • (fderiv_within ℝ f s x) := hf.has_fderiv_within_at.cos.fderiv_within hxs @[simp] lemma fderiv_cos (hc : differentiable_at ℝ f x) : fderiv ℝ (λx, real.cos (f x)) x = - real.sin (f x) • (fderiv ℝ f x) := hc.has_fderiv_at.cos.fderiv lemma times_cont_diff.cos {n} (h : times_cont_diff ℝ n f) : times_cont_diff ℝ n (λ x, real.cos (f x)) := real.times_cont_diff_cos.comp h lemma times_cont_diff_at.cos {n} (hf : times_cont_diff_at ℝ n f x) : times_cont_diff_at ℝ n (λ x, real.cos (f x)) x := real.times_cont_diff_cos.times_cont_diff_at.comp x hf lemma times_cont_diff_on.cos {n} (hf : times_cont_diff_on ℝ n f s) : times_cont_diff_on ℝ n (λ x, real.cos (f x)) s := real.times_cont_diff_cos.comp_times_cont_diff_on hf lemma times_cont_diff_within_at.cos {n} (hf : times_cont_diff_within_at ℝ n f s x) : times_cont_diff_within_at ℝ n (λ x, real.cos (f x)) s x := real.times_cont_diff_cos.times_cont_diff_at.comp_times_cont_diff_within_at x hf /-! #### `real.sin` -/ lemma has_fderiv_at.sin (hf : has_fderiv_at f f' x) : has_fderiv_at (λ x, real.sin (f x)) (real.cos (f x) • f') x := (real.has_deriv_at_sin (f x)).comp_has_fderiv_at x hf lemma has_fderiv_within_at.sin (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, real.sin (f x)) (real.cos (f x) • f') s x := (real.has_deriv_at_sin (f x)).comp_has_fderiv_within_at x hf lemma differentiable_within_at.sin (hf : differentiable_within_at ℝ f s x) : differentiable_within_at ℝ (λ x, real.sin (f x)) s x := hf.has_fderiv_within_at.sin.differentiable_within_at @[simp] lemma differentiable_at.sin (hc : differentiable_at ℝ f x) : differentiable_at ℝ (λx, real.sin (f x)) x := hc.has_fderiv_at.sin.differentiable_at lemma differentiable_on.sin (hc : differentiable_on ℝ f s) : differentiable_on ℝ (λx, real.sin (f x)) s := λx h, (hc x h).sin @[simp] lemma differentiable.sin (hc : differentiable ℝ f) : differentiable ℝ (λx, real.sin (f x)) := λx, (hc x).sin lemma fderiv_within_sin (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : fderiv_within ℝ (λx, real.sin (f x)) s x = real.cos (f x) • (fderiv_within ℝ f s x) := hf.has_fderiv_within_at.sin.fderiv_within hxs @[simp] lemma fderiv_sin (hc : differentiable_at ℝ f x) : fderiv ℝ (λx, real.sin (f x)) x = real.cos (f x) • (fderiv ℝ f x) := hc.has_fderiv_at.sin.fderiv lemma times_cont_diff.sin {n} (h : times_cont_diff ℝ n f) : times_cont_diff ℝ n (λ x, real.sin (f x)) := real.times_cont_diff_sin.comp h lemma times_cont_diff_at.sin {n} (hf : times_cont_diff_at ℝ n f x) : times_cont_diff_at ℝ n (λ x, real.sin (f x)) x := real.times_cont_diff_sin.times_cont_diff_at.comp x hf lemma times_cont_diff_on.sin {n} (hf : times_cont_diff_on ℝ n f s) : times_cont_diff_on ℝ n (λ x, real.sin (f x)) s := real.times_cont_diff_sin.comp_times_cont_diff_on hf lemma times_cont_diff_within_at.sin {n} (hf : times_cont_diff_within_at ℝ n f s x) : times_cont_diff_within_at ℝ n (λ x, real.sin (f x)) s x := real.times_cont_diff_sin.times_cont_diff_at.comp_times_cont_diff_within_at x hf /-! #### `real.cosh` -/ lemma has_fderiv_at.cosh (hf : has_fderiv_at f f' x) : has_fderiv_at (λ x, real.cosh (f x)) (real.sinh (f x) • f') x := (real.has_deriv_at_cosh (f x)).comp_has_fderiv_at x hf lemma has_fderiv_within_at.cosh (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, real.cosh (f x)) (real.sinh (f x) • f') s x := (real.has_deriv_at_cosh (f x)).comp_has_fderiv_within_at x hf lemma differentiable_within_at.cosh (hf : differentiable_within_at ℝ f s x) : differentiable_within_at ℝ (λ x, real.cosh (f x)) s x := hf.has_fderiv_within_at.cosh.differentiable_within_at @[simp] lemma differentiable_at.cosh (hc : differentiable_at ℝ f x) : differentiable_at ℝ (λx, real.cosh (f x)) x := hc.has_fderiv_at.cosh.differentiable_at lemma differentiable_on.cosh (hc : differentiable_on ℝ f s) : differentiable_on ℝ (λx, real.cosh (f x)) s := λx h, (hc x h).cosh @[simp] lemma differentiable.cosh (hc : differentiable ℝ f) : differentiable ℝ (λx, real.cosh (f x)) := λx, (hc x).cosh lemma fderiv_within_cosh (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : fderiv_within ℝ (λx, real.cosh (f x)) s x = real.sinh (f x) • (fderiv_within ℝ f s x) := hf.has_fderiv_within_at.cosh.fderiv_within hxs @[simp] lemma fderiv_cosh (hc : differentiable_at ℝ f x) : fderiv ℝ (λx, real.cosh (f x)) x = real.sinh (f x) • (fderiv ℝ f x) := hc.has_fderiv_at.cosh.fderiv lemma times_cont_diff.cosh {n} (h : times_cont_diff ℝ n f) : times_cont_diff ℝ n (λ x, real.cosh (f x)) := real.times_cont_diff_cosh.comp h lemma times_cont_diff_at.cosh {n} (hf : times_cont_diff_at ℝ n f x) : times_cont_diff_at ℝ n (λ x, real.cosh (f x)) x := real.times_cont_diff_cosh.times_cont_diff_at.comp x hf lemma times_cont_diff_on.cosh {n} (hf : times_cont_diff_on ℝ n f s) : times_cont_diff_on ℝ n (λ x, real.cosh (f x)) s := real.times_cont_diff_cosh.comp_times_cont_diff_on hf lemma times_cont_diff_within_at.cosh {n} (hf : times_cont_diff_within_at ℝ n f s x) : times_cont_diff_within_at ℝ n (λ x, real.cosh (f x)) s x := real.times_cont_diff_cosh.times_cont_diff_at.comp_times_cont_diff_within_at x hf /-! #### `real.sinh` -/ lemma has_fderiv_at.sinh (hf : has_fderiv_at f f' x) : has_fderiv_at (λ x, real.sinh (f x)) (real.cosh (f x) • f') x := (real.has_deriv_at_sinh (f x)).comp_has_fderiv_at x hf lemma has_fderiv_within_at.sinh (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, real.sinh (f x)) (real.cosh (f x) • f') s x := (real.has_deriv_at_sinh (f x)).comp_has_fderiv_within_at x hf lemma differentiable_within_at.sinh (hf : differentiable_within_at ℝ f s x) : differentiable_within_at ℝ (λ x, real.sinh (f x)) s x := hf.has_fderiv_within_at.sinh.differentiable_within_at @[simp] lemma differentiable_at.sinh (hc : differentiable_at ℝ f x) : differentiable_at ℝ (λx, real.sinh (f x)) x := hc.has_fderiv_at.sinh.differentiable_at lemma differentiable_on.sinh (hc : differentiable_on ℝ f s) : differentiable_on ℝ (λx, real.sinh (f x)) s := λx h, (hc x h).sinh @[simp] lemma differentiable.sinh (hc : differentiable ℝ f) : differentiable ℝ (λx, real.sinh (f x)) := λx, (hc x).sinh lemma fderiv_within_sinh (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : fderiv_within ℝ (λx, real.sinh (f x)) s x = real.cosh (f x) • (fderiv_within ℝ f s x) := hf.has_fderiv_within_at.sinh.fderiv_within hxs @[simp] lemma fderiv_sinh (hc : differentiable_at ℝ f x) : fderiv ℝ (λx, real.sinh (f x)) x = real.cosh (f x) • (fderiv ℝ f x) := hc.has_fderiv_at.sinh.fderiv lemma times_cont_diff.sinh {n} (h : times_cont_diff ℝ n f) : times_cont_diff ℝ n (λ x, real.sinh (f x)) := real.times_cont_diff_sinh.comp h lemma times_cont_diff_at.sinh {n} (hf : times_cont_diff_at ℝ n f x) : times_cont_diff_at ℝ n (λ x, real.sinh (f x)) x := real.times_cont_diff_sinh.times_cont_diff_at.comp x hf lemma times_cont_diff_on.sinh {n} (hf : times_cont_diff_on ℝ n f s) : times_cont_diff_on ℝ n (λ x, real.sinh (f x)) s := real.times_cont_diff_sinh.comp_times_cont_diff_on hf lemma times_cont_diff_within_at.sinh {n} (hf : times_cont_diff_within_at ℝ n f s x) : times_cont_diff_within_at ℝ n (λ x, real.sinh (f x)) s x := real.times_cont_diff_sinh.times_cont_diff_at.comp_times_cont_diff_within_at x hf end namespace real lemma exists_cos_eq_zero : 0 ∈ cos '' Icc (1:ℝ) 2 := intermediate_value_Icc' (by norm_num) continuous_on_cos ⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩ /-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from which one can derive all its properties. For explicit bounds on π, see `data.real.pi`. -/ noncomputable def pi : ℝ := 2 * classical.some exists_cos_eq_zero localized "notation `π` := real.pi" in real @[simp] lemma cos_pi_div_two : cos (π / 2) = 0 := by rw [pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)]; exact (classical.some_spec exists_cos_eq_zero).2 lemma one_le_pi_div_two : (1 : ℝ) ≤ π / 2 := by rw [pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)]; exact (classical.some_spec exists_cos_eq_zero).1.1 lemma pi_div_two_le_two : π / 2 ≤ 2 := by rw [pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)]; exact (classical.some_spec exists_cos_eq_zero).1.2 lemma two_le_pi : (2 : ℝ) ≤ π := (div_le_div_right (show (0 : ℝ) < 2, by norm_num)).1 (by rw div_self (@two_ne_zero' ℝ _ _ _); exact one_le_pi_div_two) lemma pi_le_four : π ≤ 4 := (div_le_div_right (show (0 : ℝ) < 2, by norm_num)).1 (calc π / 2 ≤ 2 : pi_div_two_le_two ... = 4 / 2 : by norm_num) lemma pi_pos : 0 < π := lt_of_lt_of_le (by norm_num) two_le_pi lemma pi_ne_zero : pi ≠ 0 := ne_of_gt pi_pos lemma pi_div_two_pos : 0 < π / 2 := half_pos pi_pos lemma two_pi_pos : 0 < 2 * π := by linarith [pi_pos] @[simp] lemma sin_pi : sin π = 0 := by rw [← mul_div_cancel_left pi (@two_ne_zero ℝ _ _), two_mul, add_div, sin_add, cos_pi_div_two]; simp @[simp] lemma cos_pi : cos π = -1 := by rw [← mul_div_cancel_left pi (@two_ne_zero ℝ _ _), mul_div_assoc, cos_two_mul, cos_pi_div_two]; simp [bit0, pow_add] @[simp] lemma sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add] @[simp] lemma cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add] lemma sin_add_pi (x : ℝ) : sin (x + π) = -sin x := by simp [sin_add] lemma sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x := by simp [sin_add_pi, sin_add, sin_two_pi, cos_two_pi] lemma cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x := by simp [cos_add, cos_two_pi, sin_two_pi] lemma sin_pi_sub (x : ℝ) : sin (π - x) = sin x := by simp [sub_eq_add_neg, sin_add] lemma cos_add_pi (x : ℝ) : cos (x + π) = -cos x := by simp [cos_add] lemma cos_pi_sub (x : ℝ) : cos (π - x) = -cos x := by simp [sub_eq_add_neg, cos_add] lemma sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x := if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2 else have (2 : ℝ) + 2 = 4, from rfl, have π - x ≤ 2, from sub_le_iff_le_add.2 (le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _)), sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this lemma sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 π) : 0 < sin x := sin_pos_of_pos_of_lt_pi hx.1 hx.2 lemma sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 π) : 0 ≤ sin x := begin rw ← closure_Ioo pi_pos at hx, exact closure_lt_subset_le continuous_const continuous_sin (closure_mono (λ y, sin_pos_of_mem_Ioo) hx) end lemma sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x := sin_nonneg_of_mem_Icc ⟨h0x, hxp⟩ lemma sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 := neg_pos.1 $ sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx) lemma sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 := neg_nonneg.1 $ sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx) @[simp] lemma sin_pi_div_two : sin (π / 2) = 1 := have sin (π / 2) = 1 ∨ sin (π / 2) = -1 := by simpa [pow_two, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2), this.resolve_right (λ h, (show ¬(0 : ℝ) < -1, by norm_num) $ h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos)) lemma sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x := by simp [sin_add] lemma sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add] lemma sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add] lemma cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x := by simp [cos_add] lemma cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x := by simp [sub_eq_add_neg, cos_add] lemma cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x := by rw [← cos_neg, neg_sub, cos_sub_pi_div_two] lemma cos_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : 0 < cos x := sin_add_pi_div_two x ▸ sin_pos_of_mem_Ioo ⟨by linarith [hx.1], by linarith [hx.2]⟩ lemma cos_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : 0 ≤ cos x := sin_add_pi_div_two x ▸ sin_nonneg_of_mem_Icc ⟨by linarith [hx.1], by linarith [hx.2]⟩ lemma cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) : cos x < 0 := neg_pos.1 $ cos_pi_sub x ▸ cos_pos_of_mem_Ioo ⟨by linarith, by linarith⟩ lemma cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≤ x) (hx₂ : x ≤ π + π / 2) : cos x ≤ 0 := neg_nonneg.1 $ cos_pi_sub x ▸ cos_nonneg_of_mem_Icc ⟨by linarith, by linarith⟩ lemma sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 := by induction n; simp [add_mul, sin_add, *] lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 := by cases n; simp [add_mul, sin_add, *, sin_nat_mul_pi] lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 := by induction n; simp [*, mul_add, cos_add, add_mul, cos_two_pi, sin_two_pi] lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 := by cases n; simp only [cos_nat_mul_two_pi, int.of_nat_eq_coe, int.neg_succ_of_nat_coe, int.cast_coe_nat, int.cast_neg, (neg_mul_eq_neg_mul _ _).symm, cos_neg] lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 := by simp [cos_add, sin_add, cos_int_mul_two_pi] lemma sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -π < x) (hx₂ : x < π) : sin x = 0 ↔ x = 0 := ⟨λ h, le_antisymm (le_of_not_gt (λ h0, lt_irrefl (0 : ℝ) $ calc 0 < sin x : sin_pos_of_pos_of_lt_pi h0 hx₂ ... = 0 : h)) (le_of_not_gt (λ h0, lt_irrefl (0 : ℝ) $ calc 0 = sin x : h.symm ... < 0 : sin_neg_of_neg_of_neg_pi_lt h0 hx₁)), λ h, by simp [h]⟩ lemma sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : ℤ, (n : ℝ) * π = x := ⟨λ h, ⟨⌊x / π⌋, le_antisymm (sub_nonneg.1 (sub_floor_div_mul_nonneg _ pi_pos)) (sub_nonpos.1 $ le_of_not_gt $ λ h₃, ne_of_lt (sin_pos_of_pos_of_lt_pi h₃ (sub_floor_div_mul_lt _ pi_pos)) (by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩, λ ⟨n, hn⟩, hn ▸ sin_int_mul_pi _⟩ lemma sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 := by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x, pow_two, pow_two, ← sub_eq_iff_eq_add, sub_self]; exact ⟨λ h, by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ eq.symm⟩ lemma cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : ℤ, (n : ℝ) * (2 * π) = x := ⟨λ h, let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (or.inl h)) in ⟨n / 2, (int.mod_two_eq_zero_or_one n).elim (λ hn0, by rwa [← mul_assoc, ← @int.cast_two ℝ, ← int.cast_mul, int.div_mul_cancel ((int.dvd_iff_mod_eq_zero _ _).2 hn0)]) (λ hn1, by rw [← int.mod_add_div n 2, hn1, int.cast_add, int.cast_one, add_mul, one_mul, add_comm, mul_comm (2 : ℤ), int.cast_mul, mul_assoc, int.cast_two] at hn; rw [← hn, cos_int_mul_two_pi_add_pi] at h; exact absurd h (by norm_num))⟩, λ ⟨n, hn⟩, hn ▸ cos_int_mul_two_pi _⟩ lemma cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x < 2 * π) : cos x = 1 ↔ x = 0 := ⟨λ h, begin rcases (cos_eq_one_iff _).1 h with ⟨n, rfl⟩, rw [mul_lt_iff_lt_one_left two_pi_pos] at hx₂, rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx₁, norm_cast at hx₁ hx₂, obtain rfl : n = 0, by omega, simp end, λ h, by simp [h]⟩ lemma cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π / 2) (hxy : x < y) : cos y < cos x := begin rw [← sub_lt_zero, cos_sub_cos], have : 0 < sin ((y + x) / 2), { refine sin_pos_of_pos_of_lt_pi _ _; linarith }, have : 0 < sin ((y - x) / 2), { refine sin_pos_of_pos_of_lt_pi _ _; linarith }, nlinarith, end lemma cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x < y) : cos y < cos x := match (le_total x (π / 2) : x ≤ π / 2 ∨ π / 2 ≤ x), le_total y (π / 2) with | or.inl hx, or.inl hy := cos_lt_cos_of_nonneg_of_le_pi_div_two hx₁ hy hxy | or.inl hx, or.inr hy := (lt_or_eq_of_le hx).elim (λ hx, calc cos y ≤ 0 : cos_nonpos_of_pi_div_two_le_of_le hy (by linarith [pi_pos]) ... < cos x : cos_pos_of_mem_Ioo ⟨by linarith, hx⟩) (λ hx, calc cos y < 0 : cos_neg_of_pi_div_two_lt_of_lt (by linarith) (by linarith [pi_pos]) ... = cos x : by rw [hx, cos_pi_div_two]) | or.inr hx, or.inl hy := by linarith | or.inr hx, or.inr hy := neg_lt_neg_iff.1 (by rw [← cos_pi_sub, ← cos_pi_sub]; apply cos_lt_cos_of_nonneg_of_le_pi_div_two; linarith) end lemma strict_mono_decr_on_cos : strict_mono_decr_on cos (Icc 0 π) := λ x hx y hy hxy, cos_lt_cos_of_nonneg_of_le_pi hx.1 hy.2 hxy lemma cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x ≤ y) : cos y ≤ cos x := (strict_mono_decr_on_cos.le_iff_le ⟨hx₁.trans hxy, hy₂⟩ ⟨hx₁, hxy.trans hy₂⟩).2 hxy lemma sin_lt_sin_of_lt_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2) (hxy : x < y) : sin x < sin y := by rw [← cos_sub_pi_div_two, ← cos_sub_pi_div_two, ← cos_neg (x - _), ← cos_neg (y - _)]; apply cos_lt_cos_of_nonneg_of_le_pi; linarith lemma strict_mono_incr_on_sin : strict_mono_incr_on sin (Icc (-(π / 2)) (π / 2)) := λ x hx y hy hxy, sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy lemma sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2) (hxy : x ≤ y) : sin x ≤ sin y := (strict_mono_incr_on_sin.le_iff_le ⟨hx₁, hxy.trans hy₂⟩ ⟨hx₁.trans hxy, hy₂⟩).2 hxy lemma inj_on_sin : inj_on sin (Icc (-(π / 2)) (π / 2)) := strict_mono_incr_on_sin.inj_on lemma inj_on_cos : inj_on cos (Icc 0 π) := strict_mono_decr_on_cos.inj_on lemma surj_on_sin : surj_on sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) := by simpa only [sin_neg, sin_pi_div_two] using intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuous_on lemma surj_on_cos : surj_on cos (Icc 0 π) (Icc (-1) 1) := by simpa only [cos_zero, cos_pi] using intermediate_value_Icc' pi_pos.le continuous_cos.continuous_on lemma sin_mem_Icc (x : ℝ) : sin x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_sin x, sin_le_one x⟩ lemma cos_mem_Icc (x : ℝ) : cos x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_cos x, cos_le_one x⟩ lemma maps_to_sin (s : set ℝ) : maps_to sin s (Icc (-1 : ℝ) 1) := λ x _, sin_mem_Icc x lemma maps_to_cos (s : set ℝ) : maps_to cos s (Icc (-1 : ℝ) 1) := λ x _, cos_mem_Icc x lemma bij_on_sin : bij_on sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) := ⟨maps_to_sin _, inj_on_sin, surj_on_sin⟩ lemma bij_on_cos : bij_on cos (Icc 0 π) (Icc (-1) 1) := ⟨maps_to_cos _, inj_on_cos, surj_on_cos⟩ @[simp] lemma range_cos : range cos = (Icc (-1) 1 : set ℝ) := subset.antisymm (range_subset_iff.2 cos_mem_Icc) surj_on_cos.subset_range @[simp] lemma range_sin : range sin = (Icc (-1) 1 : set ℝ) := subset.antisymm (range_subset_iff.2 sin_mem_Icc) surj_on_sin.subset_range lemma range_cos_infinite : (range real.cos).infinite := by { rw real.range_cos, exact Icc.infinite (by norm_num) } lemma range_sin_infinite : (range real.sin).infinite := by { rw real.range_sin, exact Icc.infinite (by norm_num) } lemma sin_lt {x : ℝ} (h : 0 < x) : sin x < x := begin cases le_or_gt x 1 with h' h', { have hx : abs x = x := abs_of_nonneg (le_of_lt h), have : abs x ≤ 1, rwa [hx], have := sin_bound this, rw [abs_le] at this, have := this.2, rw [sub_le_iff_le_add', hx] at this, apply lt_of_le_of_lt this, rw [sub_add], apply lt_of_lt_of_le _ (le_of_eq (sub_zero x)), apply sub_lt_sub_left, rw [sub_pos, div_eq_mul_inv (x ^ 3)], apply mul_lt_mul', { rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)), rw mul_le_mul_right, exact h', apply pow_pos h }, norm_num, norm_num, apply pow_pos h }, exact lt_of_le_of_lt (sin_le_one x) h' end /- note 1: this inequality is not tight, the tighter inequality is sin x > x - x ^ 3 / 6. note 2: this is also true for x > 1, but it's nontrivial for x just above 1. -/ lemma sin_gt_sub_cube {x : ℝ} (h : 0 < x) (h' : x ≤ 1) : x - x ^ 3 / 4 < sin x := begin have hx : abs x = x := abs_of_nonneg (le_of_lt h), have : abs x ≤ 1, rwa [hx], have := sin_bound this, rw [abs_le] at this, have := this.1, rw [le_sub_iff_add_le, hx] at this, refine lt_of_lt_of_le _ this, rw [add_comm, sub_add, sub_neg_eq_add], apply sub_lt_sub_left, apply add_lt_of_lt_sub_left, rw (show x ^ 3 / 4 - x ^ 3 / 6 = x ^ 3 * 12⁻¹, by simp [div_eq_mul_inv, ← mul_sub]; norm_num), apply mul_lt_mul', { rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)), rw mul_le_mul_right, exact h', apply pow_pos h }, norm_num, norm_num, apply pow_pos h end section cos_div_pow_two variable (x : ℝ) /-- the series `sqrt_two_add_series x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots, starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrt_two_add_series 0 n / 2` -/ @[simp, pp_nodot] noncomputable def sqrt_two_add_series (x : ℝ) : ℕ → ℝ | 0 := x | (n+1) := sqrt (2 + sqrt_two_add_series n) lemma sqrt_two_add_series_zero : sqrt_two_add_series x 0 = x := by simp lemma sqrt_two_add_series_one : sqrt_two_add_series 0 1 = sqrt 2 := by simp lemma sqrt_two_add_series_two : sqrt_two_add_series 0 2 = sqrt (2 + sqrt 2) := by simp lemma sqrt_two_add_series_zero_nonneg : ∀(n : ℕ), 0 ≤ sqrt_two_add_series 0 n | 0 := le_refl 0 | (n+1) := sqrt_nonneg _ lemma sqrt_two_add_series_nonneg {x : ℝ} (h : 0 ≤ x) : ∀(n : ℕ), 0 ≤ sqrt_two_add_series x n | 0 := h | (n+1) := sqrt_nonneg _ lemma sqrt_two_add_series_lt_two : ∀(n : ℕ), sqrt_two_add_series 0 n < 2 | 0 := by norm_num | (n+1) := begin refine lt_of_lt_of_le _ (le_of_eq $ sqrt_sqr $ le_of_lt zero_lt_two), rw [sqrt_two_add_series, sqrt_lt, ← lt_sub_iff_add_lt'], { refine (sqrt_two_add_series_lt_two n).trans_le _, norm_num }, { exact add_nonneg zero_le_two (sqrt_two_add_series_zero_nonneg n) } end lemma sqrt_two_add_series_succ (x : ℝ) : ∀(n : ℕ), sqrt_two_add_series x (n+1) = sqrt_two_add_series (sqrt (2 + x)) n | 0 := rfl | (n+1) := by rw [sqrt_two_add_series, sqrt_two_add_series_succ, sqrt_two_add_series] lemma sqrt_two_add_series_monotone_left {x y : ℝ} (h : x ≤ y) : ∀(n : ℕ), sqrt_two_add_series x n ≤ sqrt_two_add_series y n | 0 := h | (n+1) := begin rw [sqrt_two_add_series, sqrt_two_add_series], exact sqrt_le_sqrt (add_le_add_left (sqrt_two_add_series_monotone_left _) _) end @[simp] lemma cos_pi_over_two_pow : ∀(n : ℕ), cos (pi / 2 ^ (n+1)) = sqrt_two_add_series 0 n / 2 | 0 := by simp | (n+1) := begin have : (2 : ℝ) ≠ 0 := two_ne_zero, symmetry, rw [div_eq_iff_mul_eq this], symmetry, rw [sqrt_two_add_series, sqrt_eq_iff_sqr_eq, mul_pow, cos_square, ←mul_div_assoc, nat.add_succ, pow_succ, mul_div_mul_left _ _ this, cos_pi_over_two_pow, add_mul], congr, { norm_num }, rw [mul_comm, pow_two, mul_assoc, ←mul_div_assoc, mul_div_cancel_left, ←mul_div_assoc, mul_div_cancel_left]; try { exact this }, apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg, norm_num, apply le_of_lt, apply cos_pos_of_mem_Ioo ⟨_, _⟩, { transitivity (0 : ℝ), rw neg_lt_zero, apply pi_div_two_pos, apply div_pos pi_pos, apply pow_pos, norm_num }, apply div_lt_div' (le_refl pi) _ pi_pos _, refine lt_of_le_of_lt (le_of_eq (pow_one _).symm) _, apply pow_lt_pow, norm_num, apply nat.succ_lt_succ, apply nat.succ_pos, all_goals {norm_num} end lemma sin_square_pi_over_two_pow (n : ℕ) : sin (pi / 2 ^ (n+1)) ^ 2 = 1 - (sqrt_two_add_series 0 n / 2) ^ 2 := by rw [sin_square, cos_pi_over_two_pow] lemma sin_square_pi_over_two_pow_succ (n : ℕ) : sin (pi / 2 ^ (n+2)) ^ 2 = 1 / 2 - sqrt_two_add_series 0 n / 4 := begin rw [sin_square_pi_over_two_pow, sqrt_two_add_series, div_pow, sqr_sqrt, add_div, ←sub_sub], congr, norm_num, norm_num, apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg, end @[simp] lemma sin_pi_over_two_pow_succ (n : ℕ) : sin (pi / 2 ^ (n+2)) = sqrt (2 - sqrt_two_add_series 0 n) / 2 := begin symmetry, rw [div_eq_iff_mul_eq], symmetry, rw [sqrt_eq_iff_sqr_eq, mul_pow, sin_square_pi_over_two_pow_succ, sub_mul], { congr, norm_num, rw [mul_comm], convert mul_div_cancel' _ _, norm_num, norm_num }, { rw [sub_nonneg], apply le_of_lt, apply sqrt_two_add_series_lt_two }, apply le_of_lt, apply mul_pos, apply sin_pos_of_pos_of_lt_pi, { apply div_pos pi_pos, apply pow_pos, norm_num }, refine lt_of_lt_of_le _ (le_of_eq (div_one _)), rw [div_lt_div_left], refine lt_of_le_of_lt (le_of_eq (pow_zero 2).symm) _, apply pow_lt_pow, norm_num, apply nat.succ_pos, apply pi_pos, apply pow_pos, all_goals {norm_num} end @[simp] lemma cos_pi_div_four : cos (pi / 4) = sqrt 2 / 2 := by { transitivity cos (pi / 2 ^ 2), congr, norm_num, simp } @[simp] lemma sin_pi_div_four : sin (pi / 4) = sqrt 2 / 2 := by { transitivity sin (pi / 2 ^ 2), congr, norm_num, simp } @[simp] lemma cos_pi_div_eight : cos (pi / 8) = sqrt (2 + sqrt 2) / 2 := by { transitivity cos (pi / 2 ^ 3), congr, norm_num, simp } @[simp] lemma sin_pi_div_eight : sin (pi / 8) = sqrt (2 - sqrt 2) / 2 := by { transitivity sin (pi / 2 ^ 3), congr, norm_num, simp } @[simp] lemma cos_pi_div_sixteen : cos (pi / 16) = sqrt (2 + sqrt (2 + sqrt 2)) / 2 := by { transitivity cos (pi / 2 ^ 4), congr, norm_num, simp } @[simp] lemma sin_pi_div_sixteen : sin (pi / 16) = sqrt (2 - sqrt (2 + sqrt 2)) / 2 := by { transitivity sin (pi / 2 ^ 4), congr, norm_num, simp } @[simp] lemma cos_pi_div_thirty_two : cos (pi / 32) = sqrt (2 + sqrt (2 + sqrt (2 + sqrt 2))) / 2 := by { transitivity cos (pi / 2 ^ 5), congr, norm_num, simp } @[simp] lemma sin_pi_div_thirty_two : sin (pi / 32) = sqrt (2 - sqrt (2 + sqrt (2 + sqrt 2))) / 2 := by { transitivity sin (pi / 2 ^ 5), congr, norm_num, simp } -- This section is also a convenient location for other explicit values of `sin` and `cos`. /-- The cosine of `π / 3` is `1 / 2`. -/ @[simp] lemma cos_pi_div_three : cos (π / 3) = 1 / 2 := begin have h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0, { have : cos (3 * (π / 3)) = cos π := by { congr' 1, ring }, linarith [cos_pi, cos_three_mul (π / 3)] }, cases mul_eq_zero.mp h₁ with h h, { linarith [pow_eq_zero h] }, { have : cos π < cos (π / 3), { refine cos_lt_cos_of_nonneg_of_le_pi _ rfl.ge _; linarith [pi_pos] }, linarith [cos_pi] } end /-- The square of the cosine of `π / 6` is `3 / 4` (this is sometimes more convenient than the result for cosine itself). -/ lemma square_cos_pi_div_six : cos (π / 6) ^ 2 = 3 / 4 := begin have h1 : cos (π / 6) ^ 2 = 1 / 2 + 1 / 2 / 2, { convert cos_square (π / 6), have h2 : 2 * (π / 6) = π / 3 := by cancel_denoms, rw [h2, cos_pi_div_three] }, rw ← sub_eq_zero at h1 ⊢, convert h1 using 1, ring end /-- The cosine of `π / 6` is `√3 / 2`. -/ @[simp] lemma cos_pi_div_six : cos (π / 6) = (sqrt 3) / 2 := begin suffices : sqrt 3 = cos (π / 6) * 2, { field_simp [(by norm_num : 0 ≠ 2)], exact this.symm }, rw sqrt_eq_iff_sqr_eq, { have h1 := (mul_right_inj' (by norm_num : (4:ℝ) ≠ 0)).mpr square_cos_pi_div_six, rw ← sub_eq_zero at h1 ⊢, convert h1 using 1, ring }, { norm_num }, { have : 0 < cos (π / 6) := by { apply cos_pos_of_mem_Ioo; split; linarith [pi_pos] }, linarith }, end /-- The sine of `π / 6` is `1 / 2`. -/ @[simp] lemma sin_pi_div_six : sin (π / 6) = 1 / 2 := begin rw [← cos_pi_div_two_sub, ← cos_pi_div_three], congr, ring end /-- The square of the sine of `π / 3` is `3 / 4` (this is sometimes more convenient than the result for cosine itself). -/ lemma square_sin_pi_div_three : sin (π / 3) ^ 2 = 3 / 4 := begin rw [← cos_pi_div_two_sub, ← square_cos_pi_div_six], congr, ring end /-- The sine of `π / 3` is `√3 / 2`. -/ @[simp] lemma sin_pi_div_three : sin (π / 3) = (sqrt 3) / 2 := begin rw [← cos_pi_div_two_sub, ← cos_pi_div_six], congr, ring end end cos_div_pow_two /-- The type of angles -/ def angle : Type := quotient_add_group.quotient (add_subgroup.gmultiples (2 * π)) namespace angle instance angle.add_comm_group : add_comm_group angle := quotient_add_group.add_comm_group _ instance : inhabited angle := ⟨0⟩ instance angle.has_coe : has_coe ℝ angle := ⟨quotient.mk'⟩ @[simp] lemma coe_zero : ↑(0 : ℝ) = (0 : angle) := rfl @[simp] lemma coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : angle) := rfl @[simp] lemma coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : angle) := rfl @[simp] lemma coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : angle) := by rw [sub_eq_add_neg, sub_eq_add_neg, coe_add, coe_neg] @[simp, norm_cast] lemma coe_nat_mul_eq_nsmul (x : ℝ) (n : ℕ) : ↑((n : ℝ) * x) = n •ℕ (↑x : angle) := by simpa using add_monoid_hom.map_nsmul ⟨coe, coe_zero, coe_add⟩ _ _ @[simp, norm_cast] lemma coe_int_mul_eq_gsmul (x : ℝ) (n : ℤ) : ↑((n : ℝ) * x : ℝ) = n •ℤ (↑x : angle) := by simpa using add_monoid_hom.map_gsmul ⟨coe, coe_zero, coe_add⟩ _ _ @[simp] lemma coe_two_pi : ↑(2 * π : ℝ) = (0 : angle) := quotient.sound' ⟨-1, show (-1 : ℤ) •ℤ (2 * π) = _, by rw [neg_one_gsmul, add_zero]⟩ lemma angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k := by simp only [quotient_add_group.eq, add_subgroup.gmultiples_eq_closure, add_subgroup.mem_closure_singleton, gsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] theorem cos_eq_iff_eq_or_eq_neg {θ ψ : ℝ} : cos θ = cos ψ ↔ (θ : angle) = ψ ∨ (θ : angle) = -ψ := begin split, { intro Hcos, rw [←sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero, eq_false_intro two_ne_zero, false_or, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos, rcases Hcos with ⟨n, hn⟩ | ⟨n, hn⟩, { right, rw [eq_div_iff_mul_eq (@two_ne_zero ℝ _ _), ← sub_eq_iff_eq_add] at hn, rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc, coe_int_mul_eq_gsmul, mul_comm, coe_two_pi, gsmul_zero] }, { left, rw [eq_div_iff_mul_eq (@two_ne_zero ℝ _ _), eq_sub_iff_add_eq] at hn, rw [← hn, coe_add, mul_assoc, coe_int_mul_eq_gsmul, mul_comm, coe_two_pi, gsmul_zero, zero_add] }, apply_instance, }, { rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub], rintro (⟨k, H⟩ | ⟨k, H⟩), rw [← sub_eq_zero_iff_eq, cos_sub_cos, H, mul_assoc 2 π k, mul_div_cancel_left _ (@two_ne_zero ℝ _ _), mul_comm π _, sin_int_mul_pi, mul_zero], rw [←sub_eq_zero_iff_eq, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k, mul_div_cancel_left _ (@two_ne_zero ℝ _ _), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] } end theorem sin_eq_iff_eq_or_add_eq_pi {θ ψ : ℝ} : sin θ = sin ψ ↔ (θ : angle) = ψ ∨ (θ : angle) + ψ = π := begin split, { intro Hsin, rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin, cases cos_eq_iff_eq_or_eq_neg.mp Hsin with h h, { left, rw [coe_sub, coe_sub] at h, exact sub_right_inj.1 h }, right, rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub, sub_add_eq_add_sub, ← coe_add, add_halves, sub_sub, sub_eq_zero] at h, exact h.symm }, { rw [angle_eq_iff_two_pi_dvd_sub, ←eq_sub_iff_add_eq, ←coe_sub, angle_eq_iff_two_pi_dvd_sub], rintro (⟨k, H⟩ | ⟨k, H⟩), rw [← sub_eq_zero_iff_eq, sin_sub_sin, H, mul_assoc 2 π k, mul_div_cancel_left _ (@two_ne_zero ℝ _ _), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul], have H' : θ + ψ = (2 * k) * π + π := by rwa [←sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add, mul_assoc, mul_comm π _, ←mul_assoc] at H, rw [← sub_eq_zero_iff_eq, sin_sub_sin, H', add_div, mul_assoc 2 _ π, mul_div_cancel_left _ (@two_ne_zero ℝ _ _), cos_add_pi_div_two, sin_int_mul_pi, neg_zero, mul_zero] } end theorem cos_sin_inj {θ ψ : ℝ} (Hcos : cos θ = cos ψ) (Hsin : sin θ = sin ψ) : (θ : angle) = ψ := begin cases cos_eq_iff_eq_or_eq_neg.mp Hcos with hc hc, { exact hc }, cases sin_eq_iff_eq_or_add_eq_pi.mp Hsin with hs hs, { exact hs }, rw [eq_neg_iff_add_eq_zero, hs] at hc, cases quotient.exact' hc with n hn, change n •ℤ _ = _ at hn, rw [← neg_one_mul, add_zero, ← sub_eq_zero_iff_eq, gsmul_eq_mul, ← mul_assoc, ← sub_mul, mul_eq_zero, eq_false_intro (ne_of_gt pi_pos), or_false, sub_neg_eq_add, ← int.cast_zero, ← int.cast_one, ← int.cast_bit0, ← int.cast_mul, ← int.cast_add, int.cast_inj] at hn, have : (n * 2 + 1) % (2:ℤ) = 0 % (2:ℤ) := congr_arg (%(2:ℤ)) hn, rw [add_comm, int.add_mul_mod_self] at this, exact absurd this one_ne_zero end end angle /-- `real.sin` as an `order_iso` between `[-(π / 2), π / 2]` and `[-1, 1]`. -/ def sin_order_iso : Icc (-(π / 2)) (π / 2) ≃o Icc (-1:ℝ) 1 := (strict_mono_incr_on_sin.order_iso _ _).trans $ order_iso.set_congr _ _ bij_on_sin.image_eq @[simp] lemma coe_sin_order_iso_apply (x : Icc (-(π / 2)) (π / 2)) : (sin_order_iso x : ℝ) = sin x := rfl lemma sin_order_iso_apply (x : Icc (-(π / 2)) (π / 2)) : sin_order_iso x = ⟨sin x, sin_mem_Icc x⟩ := rfl /-- Inverse of the `sin` function, returns values in the range `-π / 2 ≤ arcsin x ≤ π / 2`. It defaults to `-π / 2` on `(-∞, -1)` and to `π / 2` to `(1, ∞)`. -/ @[pp_nodot] noncomputable def arcsin : ℝ → ℝ := coe ∘ Icc_extend (neg_le_self zero_le_one) sin_order_iso.symm lemma arcsin_mem_Icc (x : ℝ) : arcsin x ∈ Icc (-(π / 2)) (π / 2) := subtype.coe_prop _ @[simp] lemma range_arcsin : range arcsin = Icc (-(π / 2)) (π / 2) := by { rw [arcsin, range_comp coe], simp [Icc] } lemma arcsin_le_pi_div_two (x : ℝ) : arcsin x ≤ π / 2 := (arcsin_mem_Icc x).2 lemma neg_pi_div_two_le_arcsin (x : ℝ) : -(π / 2) ≤ arcsin x := (arcsin_mem_Icc x).1 lemma arcsin_proj_Icc (x : ℝ) : arcsin (proj_Icc (-1) 1 (neg_le_self $ @zero_le_one ℝ _) x) = arcsin x := by rw [arcsin, function.comp_app, Icc_extend_coe, function.comp_app, Icc_extend] lemma sin_arcsin' {x : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) : sin (arcsin x) = x := by simpa [arcsin, Icc_extend_of_mem _ _ hx, -order_iso.apply_symm_apply] using subtype.ext_iff.1 (sin_order_iso.apply_symm_apply ⟨x, hx⟩) lemma sin_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arcsin x) = x := sin_arcsin' ⟨hx₁, hx₂⟩ lemma arcsin_sin' {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin (sin x) = x := inj_on_sin (arcsin_mem_Icc _) hx $ by rw [sin_arcsin (neg_one_le_sin _) (sin_le_one _)] lemma arcsin_sin {x : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : arcsin (sin x) = x := arcsin_sin' ⟨hx₁, hx₂⟩ lemma strict_mono_incr_on_arcsin : strict_mono_incr_on arcsin (Icc (-1) 1) := (subtype.strict_mono_coe _).comp_strict_mono_incr_on $ sin_order_iso.symm.strict_mono.strict_mono_incr_on_Icc_extend _ lemma monotone_arcsin : monotone arcsin := (subtype.mono_coe _).comp $ sin_order_iso.symm.monotone.Icc_extend _ lemma inj_on_arcsin : inj_on arcsin (Icc (-1) 1) := strict_mono_incr_on_arcsin.inj_on lemma arcsin_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) : arcsin x = arcsin y ↔ x = y := inj_on_arcsin.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ lemma continuous_arcsin : continuous arcsin := continuous_subtype_coe.comp sin_order_iso.symm.continuous.Icc_extend lemma continuous_at_arcsin {x : ℝ} : continuous_at arcsin x := continuous_arcsin.continuous_at lemma arcsin_eq_of_sin_eq {x y : ℝ} (h₁ : sin x = y) (h₂ : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin y = x := begin subst y, exact inj_on_sin (arcsin_mem_Icc _) h₂ (sin_arcsin' (sin_mem_Icc x)) end @[simp] lemma arcsin_zero : arcsin 0 = 0 := arcsin_eq_of_sin_eq sin_zero ⟨neg_nonpos.2 pi_div_two_pos.le, pi_div_two_pos.le⟩ @[simp] lemma arcsin_one : arcsin 1 = π / 2 := arcsin_eq_of_sin_eq sin_pi_div_two $ right_mem_Icc.2 (neg_le_self pi_div_two_pos.le) lemma arcsin_of_one_le {x : ℝ} (hx : 1 ≤ x) : arcsin x = π / 2 := by rw [← arcsin_proj_Icc, proj_Icc_of_right_le _ hx, subtype.coe_mk, arcsin_one] lemma arcsin_neg_one : arcsin (-1) = -(π / 2) := arcsin_eq_of_sin_eq (by rw [sin_neg, sin_pi_div_two]) $ left_mem_Icc.2 (neg_le_self pi_div_two_pos.le) lemma arcsin_of_le_neg_one {x : ℝ} (hx : x ≤ -1) : arcsin x = -(π / 2) := by rw [← arcsin_proj_Icc, proj_Icc_of_le_left _ hx, subtype.coe_mk, arcsin_neg_one] @[simp] lemma arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x := begin cases le_total x (-1) with hx₁ hx₁, { rw [arcsin_of_le_neg_one hx₁, neg_neg, arcsin_of_one_le (le_neg.2 hx₁)] }, cases le_total 1 x with hx₂ hx₂, { rw [arcsin_of_one_le hx₂, arcsin_of_le_neg_one (neg_le_neg hx₂)] }, refine arcsin_eq_of_sin_eq _ _, { rw [sin_neg, sin_arcsin hx₁ hx₂] }, { exact ⟨neg_le_neg (arcsin_le_pi_div_two _), neg_le.2 (neg_pi_div_two_le_arcsin _)⟩ } end lemma arcsin_le_iff_le_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) : arcsin x ≤ y ↔ x ≤ sin y := by rw [← arcsin_sin' hy, strict_mono_incr_on_arcsin.le_iff_le hx (sin_mem_Icc _), arcsin_sin' hy] lemma arcsin_le_iff_le_sin' {x y : ℝ} (hy : y ∈ Ico (-(π / 2)) (π / 2)) : arcsin x ≤ y ↔ x ≤ sin y := begin cases le_total x (-1) with hx₁ hx₁, { simp [arcsin_of_le_neg_one hx₁, hy.1, hx₁.trans (neg_one_le_sin _)] }, cases lt_or_le 1 x with hx₂ hx₂, { simp [arcsin_of_one_le hx₂.le, hy.2.not_le, (sin_le_one y).trans_lt hx₂] }, exact arcsin_le_iff_le_sin ⟨hx₁, hx₂⟩ (mem_Icc_of_Ico hy) end lemma le_arcsin_iff_sin_le {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) : x ≤ arcsin y ↔ sin x ≤ y := by rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin ⟨neg_le_neg hy.2, neg_le.2 hy.1⟩ ⟨neg_le_neg hx.2, neg_le.2 hx.1⟩, sin_neg, neg_le_neg_iff] lemma le_arcsin_iff_sin_le' {x y : ℝ} (hx : x ∈ Ioc (-(π / 2)) (π / 2)) : x ≤ arcsin y ↔ sin x ≤ y := by rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin' ⟨neg_le_neg hx.2, neg_lt.2 hx.1⟩, sin_neg, neg_le_neg_iff] lemma arcsin_lt_iff_lt_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) : arcsin x < y ↔ x < sin y := not_le.symm.trans $ (not_congr $ le_arcsin_iff_sin_le hy hx).trans not_le lemma arcsin_lt_iff_lt_sin' {x y : ℝ} (hy : y ∈ Ioc (-(π / 2)) (π / 2)) : arcsin x < y ↔ x < sin y := not_le.symm.trans $ (not_congr $ le_arcsin_iff_sin_le' hy).trans not_le lemma lt_arcsin_iff_sin_lt {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) : x < arcsin y ↔ sin x < y := not_le.symm.trans $ (not_congr $ arcsin_le_iff_le_sin hy hx).trans not_le lemma lt_arcsin_iff_sin_lt' {x y : ℝ} (hx : x ∈ Ico (-(π / 2)) (π / 2)) : x < arcsin y ↔ sin x < y := not_le.symm.trans $ (not_congr $ arcsin_le_iff_le_sin' hx).trans not_le lemma arcsin_eq_iff_eq_sin {x y : ℝ} (hy : y ∈ Ioo (-(π / 2)) (π / 2)) : arcsin x = y ↔ x = sin y := by simp only [le_antisymm_iff, arcsin_le_iff_le_sin' (mem_Ico_of_Ioo hy), le_arcsin_iff_sin_le' (mem_Ioc_of_Ioo hy)] @[simp] lemma arcsin_nonneg {x : ℝ} : 0 ≤ arcsin x ↔ 0 ≤ x := (le_arcsin_iff_sin_le' ⟨neg_lt_zero.2 pi_div_two_pos, pi_div_two_pos.le⟩).trans $ by rw [sin_zero] @[simp] lemma arcsin_nonpos {x : ℝ} : arcsin x ≤ 0 ↔ x ≤ 0 := neg_nonneg.symm.trans $ arcsin_neg x ▸ arcsin_nonneg.trans neg_nonneg @[simp] lemma arcsin_eq_zero_iff {x : ℝ} : arcsin x = 0 ↔ x = 0 := by simp [le_antisymm_iff] @[simp] lemma zero_eq_arcsin_iff {x} : 0 = arcsin x ↔ x = 0 := eq_comm.trans arcsin_eq_zero_iff @[simp] lemma arcsin_pos {x : ℝ} : 0 < arcsin x ↔ 0 < x := lt_iff_lt_of_le_iff_le arcsin_nonpos @[simp] lemma arcsin_lt_zero {x : ℝ} : arcsin x < 0 ↔ x < 0 := lt_iff_lt_of_le_iff_le arcsin_nonneg @[simp] lemma arcsin_lt_pi_div_two {x : ℝ} : arcsin x < π / 2 ↔ x < 1 := (arcsin_lt_iff_lt_sin' (right_mem_Ioc.2 $ neg_lt_self pi_div_two_pos)).trans $ by rw sin_pi_div_two @[simp] lemma neg_pi_div_two_lt_arcsin {x : ℝ} : -(π / 2) < arcsin x ↔ -1 < x := (lt_arcsin_iff_sin_lt' $ left_mem_Ico.2 $ neg_lt_self pi_div_two_pos).trans $ by rw [sin_neg, sin_pi_div_two] @[simp] lemma arcsin_eq_pi_div_two {x : ℝ} : arcsin x = π / 2 ↔ 1 ≤ x := ⟨λ h, not_lt.1 $ λ h', (arcsin_lt_pi_div_two.2 h').ne h, arcsin_of_one_le⟩ @[simp] lemma pi_div_two_eq_arcsin {x} : π / 2 = arcsin x ↔ 1 ≤ x := eq_comm.trans arcsin_eq_pi_div_two @[simp] lemma pi_div_two_le_arcsin {x} : π / 2 ≤ arcsin x ↔ 1 ≤ x := (arcsin_le_pi_div_two x).le_iff_eq.trans pi_div_two_eq_arcsin @[simp] lemma arcsin_eq_neg_pi_div_two {x : ℝ} : arcsin x = -(π / 2) ↔ x ≤ -1 := ⟨λ h, not_lt.1 $ λ h', (neg_pi_div_two_lt_arcsin.2 h').ne' h, arcsin_of_le_neg_one⟩ @[simp] lemma neg_pi_div_two_eq_arcsin {x} : -(π / 2) = arcsin x ↔ x ≤ -1 := eq_comm.trans arcsin_eq_neg_pi_div_two @[simp] lemma arcsin_le_neg_pi_div_two {x} : arcsin x ≤ -(π / 2) ↔ x ≤ -1 := (neg_pi_div_two_le_arcsin x).le_iff_eq.trans arcsin_eq_neg_pi_div_two lemma maps_to_sin_Ioo : maps_to sin (Ioo (-(π / 2)) (π / 2)) (Ioo (-1) 1) := λ x h, by rwa [mem_Ioo, ← arcsin_lt_pi_div_two, ← neg_pi_div_two_lt_arcsin, arcsin_sin h.1.le h.2.le] /-- `real.sin` as a `local_homeomorph` between `(-π / 2, π / 2)` and `(-1, 1)`. -/ @[simp] def sin_local_homeomorph : local_homeomorph ℝ ℝ := { to_fun := sin, inv_fun := arcsin, source := Ioo (-(π / 2)) (π / 2), target := Ioo (-1) 1, map_source' := maps_to_sin_Ioo, map_target' := λ y hy, ⟨neg_pi_div_two_lt_arcsin.2 hy.1, arcsin_lt_pi_div_two.2 hy.2⟩, left_inv' := λ x hx, arcsin_sin hx.1.le hx.2.le, right_inv' := λ y hy, sin_arcsin hy.1.le hy.2.le, open_source := is_open_Ioo, open_target := is_open_Ioo, continuous_to_fun := continuous_sin.continuous_on, continuous_inv_fun := continuous_arcsin.continuous_on } 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 deriv_arcsin_aux {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) : has_deriv_at arcsin (1 / sqrt (1 - x ^ 2)) x ∧ times_cont_diff_at ℝ ⊤ arcsin x := begin cases h₁.lt_or_lt with h₁ h₁, { have : 1 - x ^ 2 < 0, by nlinarith [h₁], rw [sqrt_eq_zero'.2 this.le, div_zero], have : arcsin =ᶠ[𝓝 x] λ _, -(π / 2) := (gt_mem_nhds h₁).mono (λ y hy, arcsin_of_le_neg_one hy.le), exact ⟨(has_deriv_at_const _ _).congr_of_eventually_eq this, times_cont_diff_at_const.congr_of_eventually_eq this⟩ }, cases h₂.lt_or_lt with h₂ h₂, { have : 0 < sqrt (1 - x ^ 2) := sqrt_pos.2 (by nlinarith [h₁, h₂]), simp only [← cos_arcsin h₁.le h₂.le, one_div] at this ⊢, exact ⟨sin_local_homeomorph.has_deriv_at_symm ⟨h₁, h₂⟩ this.ne' (has_deriv_at_sin _), sin_local_homeomorph.times_cont_diff_at_symm_deriv this.ne' ⟨h₁, h₂⟩ (has_deriv_at_sin _) times_cont_diff_sin.times_cont_diff_at⟩ }, { have : 1 - x ^ 2 < 0, by nlinarith [h₂], rw [sqrt_eq_zero'.2 this.le, div_zero], have : arcsin =ᶠ[𝓝 x] λ _, π / 2 := (lt_mem_nhds h₂).mono (λ y hy, arcsin_of_one_le hy.le), exact ⟨(has_deriv_at_const _ _).congr_of_eventually_eq this, times_cont_diff_at_const.congr_of_eventually_eq this⟩ } end lemma has_deriv_at_arcsin {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) : has_deriv_at arcsin (1 / sqrt (1 - x ^ 2)) x := (deriv_arcsin_aux h₁ h₂).1 lemma times_cont_diff_at_arcsin {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) {n : with_top ℕ} : times_cont_diff_at ℝ n arcsin x := (deriv_arcsin_aux h₁ h₂).2.of_le le_top lemma has_deriv_within_at_arcsin_Ici {x : ℝ} (h : x ≠ -1) : has_deriv_within_at arcsin (1 / sqrt (1 - x ^ 2)) (Ici x) x := begin rcases em (x = 1) with (rfl|h'), { convert (has_deriv_within_at_const _ _ (π / 2)).congr _ _; simp [arcsin_of_one_le] { contextual := tt } }, { exact (has_deriv_at_arcsin h h').has_deriv_within_at } end lemma has_deriv_within_at_arcsin_Iic {x : ℝ} (h : x ≠ 1) : has_deriv_within_at arcsin (1 / sqrt (1 - x ^ 2)) (Iic x) x := begin rcases em (x = -1) with (rfl|h'), { convert (has_deriv_within_at_const _ _ (-(π / 2))).congr _ _; simp [arcsin_of_le_neg_one] { contextual := tt } }, { exact (has_deriv_at_arcsin h' h).has_deriv_within_at } end lemma differentiable_within_at_arcsin_Ici {x : ℝ} : differentiable_within_at ℝ arcsin (Ici x) x ↔ x ≠ -1 := begin refine ⟨_, λ h, (has_deriv_within_at_arcsin_Ici h).differentiable_within_at⟩, rintro h rfl, have : sin ∘ arcsin =ᶠ[𝓝[Ici (-1:ℝ)] (-1)] id, { filter_upwards [Icc_mem_nhds_within_Ici ⟨le_rfl, neg_lt_self (@zero_lt_one ℝ _ _)⟩], exact λ x, sin_arcsin' }, have := h.has_deriv_within_at.sin.congr_of_eventually_eq this.symm (by simp), simpa using (unique_diff_on_Ici _ _ left_mem_Ici).eq_deriv _ this (has_deriv_within_at_id _ _) end lemma differentiable_within_at_arcsin_Iic {x : ℝ} : differentiable_within_at ℝ arcsin (Iic x) x ↔ x ≠ 1 := begin refine ⟨λ h, _, λ h, (has_deriv_within_at_arcsin_Iic h).differentiable_within_at⟩, rw [← neg_neg x, ← image_neg_Ici] at h, have := (h.comp (-x) differentiable_within_at_id.neg (maps_to_image _ _)).neg, simpa [(∘), differentiable_within_at_arcsin_Ici] using this end lemma differentiable_at_arcsin {x : ℝ} : differentiable_at ℝ arcsin x ↔ x ≠ -1 ∧ x ≠ 1 := ⟨λ h, ⟨differentiable_within_at_arcsin_Ici.1 h.differentiable_within_at, differentiable_within_at_arcsin_Iic.1 h.differentiable_within_at⟩, λ h, (has_deriv_at_arcsin h.1 h.2).differentiable_at⟩ @[simp] lemma deriv_arcsin : deriv arcsin = λ x, 1 / sqrt (1 - x ^ 2) := begin funext x, by_cases h : x ≠ -1 ∧ x ≠ 1, { exact (has_deriv_at_arcsin h.1 h.2).deriv }, { rw [deriv_zero_of_not_differentiable_at (mt differentiable_at_arcsin.1 h)], simp only [not_and_distrib, ne.def, not_not] at h, rcases h with (rfl|rfl); simp } end lemma differentiable_on_arcsin : differentiable_on ℝ arcsin {-1, 1}ᶜ := λ x hx, (differentiable_at_arcsin.2 ⟨λ h, hx (or.inl h), λ h, hx (or.inr h)⟩).differentiable_within_at lemma times_cont_diff_on_arcsin {n : with_top ℕ} : times_cont_diff_on ℝ n arcsin {-1, 1}ᶜ := λ x hx, (times_cont_diff_at_arcsin (mt or.inl hx) (mt or.inr hx)).times_cont_diff_within_at lemma times_cont_diff_at_arcsin_iff {x : ℝ} {n : with_top ℕ} : times_cont_diff_at ℝ n arcsin x ↔ n = 0 ∨ (x ≠ -1 ∧ x ≠ 1) := ⟨λ h, or_iff_not_imp_left.2 $ λ hn, differentiable_at_arcsin.1 $ h.differentiable_at $ with_top.one_le_iff_pos.2 (pos_iff_ne_zero.2 hn), λ h, h.elim (λ hn, hn.symm ▸ (times_cont_diff_zero.2 continuous_arcsin).times_cont_diff_at) $ λ hx, times_cont_diff_at_arcsin hx.1 hx.2⟩ lemma measurable_arcsin : measurable arcsin := continuous_arcsin.measurable /-- 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` -/ @[pp_nodot] 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 [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 strict_mono_decr_on_arccos : strict_mono_decr_on arccos (Icc (-1) 1) := λ x hx y hy h, sub_lt_sub_left (strict_mono_incr_on_arcsin hx hy h) _ lemma arccos_inj_on : inj_on arccos (Icc (-1) 1) := strict_mono_decr_on_arccos.inj_on lemma arccos_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) : arccos x = arccos y ↔ x = y := arccos_inj_on.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ @[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] @[simp] lemma arccos_eq_zero {x} : arccos x = 0 ↔ 1 ≤ x := by simp [arccos, sub_eq_zero] @[simp] lemma arccos_eq_pi_div_two {x} : arccos x = π / 2 ↔ x = 0 := by simp [arccos, sub_eq_iff_eq_add] @[simp] lemma arccos_eq_pi {x} : arccos x = π ↔ x ≤ -1 := by rw [arccos, sub_eq_iff_eq_add, ← sub_eq_iff_eq_add', div_two_sub_self, neg_pi_div_two_eq_arcsin] lemma arccos_neg (x : ℝ) : arccos (-x) = π - arccos x := by rw [← add_halves π, arccos, arcsin_neg, arccos, add_sub_assoc, sub_sub_self, sub_neg_eq_add] 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 continuous_arccos : continuous arccos := continuous_const.sub continuous_arcsin lemma has_deriv_at_arccos {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) : has_deriv_at arccos (-(1 / sqrt (1 - x ^ 2))) x := (has_deriv_at_arcsin h₁ h₂).const_sub (π / 2) lemma times_cont_diff_at_arccos {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) {n : with_top ℕ} : times_cont_diff_at ℝ n arccos x := times_cont_diff_at_const.sub (times_cont_diff_at_arcsin h₁ h₂) lemma has_deriv_within_at_arccos_Ici {x : ℝ} (h : x ≠ -1) : has_deriv_within_at arccos (-(1 / sqrt (1 - x ^ 2))) (Ici x) x := (has_deriv_within_at_arcsin_Ici h).const_sub _ lemma has_deriv_within_at_arccos_Iic {x : ℝ} (h : x ≠ 1) : has_deriv_within_at arccos (-(1 / sqrt (1 - x ^ 2))) (Iic x) x := (has_deriv_within_at_arcsin_Iic h).const_sub _ lemma differentiable_within_at_arccos_Ici {x : ℝ} : differentiable_within_at ℝ arccos (Ici x) x ↔ x ≠ -1 := (differentiable_within_at_const_sub_iff _).trans differentiable_within_at_arcsin_Ici lemma differentiable_within_at_arccos_Iic {x : ℝ} : differentiable_within_at ℝ arccos (Iic x) x ↔ x ≠ 1 := (differentiable_within_at_const_sub_iff _).trans differentiable_within_at_arcsin_Iic lemma differentiable_at_arccos {x : ℝ} : differentiable_at ℝ arccos x ↔ x ≠ -1 ∧ x ≠ 1 := (differentiable_at_const_sub_iff _).trans differentiable_at_arcsin @[simp] lemma deriv_arccos : deriv arccos = λ x, -(1 / sqrt (1 - x ^ 2)) := funext $ λ x, (deriv_const_sub _).trans $ by simp only [deriv_arcsin] lemma differentiable_on_arccos : differentiable_on ℝ arccos {-1, 1}ᶜ := differentiable_on_arcsin.const_sub _ lemma times_cont_diff_on_arccos {n : with_top ℕ} : times_cont_diff_on ℝ n arccos {-1, 1}ᶜ := times_cont_diff_on_const.sub times_cont_diff_on_arcsin lemma times_cont_diff_at_arccos_iff {x : ℝ} {n : with_top ℕ} : times_cont_diff_at ℝ n arccos x ↔ n = 0 ∨ (x ≠ -1 ∧ x ≠ 1) := by refine iff.trans ⟨λ h, _, λ h, _⟩ times_cont_diff_at_arcsin_iff; simpa [arccos] using (@times_cont_diff_at_const _ _ _ _ _ _ _ _ _ _ (π / 2)).sub h lemma measurable_arccos : measurable arccos := continuous_arccos.measurable @[simp] lemma tan_pi_div_four : tan (π / 4) = 1 := begin rw [tan_eq_sin_div_cos, cos_pi_div_four, sin_pi_div_four], have h : (sqrt 2) / 2 > 0 := by cancel_denoms, exact div_self (ne_of_gt h), end @[simp] lemma tan_pi_div_two : tan (π / 2) = 0 := by simp [tan_eq_sin_div_cos] lemma tan_pos_of_pos_of_lt_pi_div_two {x : ℝ} (h0x : 0 < x) (hxp : x < π / 2) : 0 < tan x := by rw tan_eq_sin_div_cos; exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith)) (cos_pos_of_mem_Ioo ⟨by linarith, hxp⟩) lemma tan_nonneg_of_nonneg_of_le_pi_div_two {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π / 2) : 0 ≤ tan x := match lt_or_eq_of_le h0x, lt_or_eq_of_le hxp with | or.inl hx0, or.inl hxp := le_of_lt (tan_pos_of_pos_of_lt_pi_div_two hx0 hxp) | or.inl hx0, or.inr hxp := by simp [hxp, tan_eq_sin_div_cos] | or.inr hx0, _ := by simp [hx0.symm] end lemma tan_neg_of_neg_of_pi_div_two_lt {x : ℝ} (hx0 : x < 0) (hpx : -(π / 2) < x) : tan x < 0 := neg_pos.1 (tan_neg x ▸ tan_pos_of_pos_of_lt_pi_div_two (by linarith) (by linarith [pi_pos])) lemma tan_nonpos_of_nonpos_of_neg_pi_div_two_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -(π / 2) ≤ x) : tan x ≤ 0 := neg_nonneg.1 (tan_neg x ▸ tan_nonneg_of_nonneg_of_le_pi_div_two (by linarith) (by linarith)) lemma tan_lt_tan_of_nonneg_of_lt_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y := begin rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos], exact div_lt_div (sin_lt_sin_of_lt_of_le_pi_div_two (by linarith) (le_of_lt hy₂) hxy) (cos_le_cos_of_nonneg_of_le_pi hx₁ (by linarith) (le_of_lt hxy)) (sin_nonneg_of_nonneg_of_le_pi (by linarith) (by linarith)) (cos_pos_of_mem_Ioo ⟨by linarith, hy₂⟩) end lemma tan_lt_tan_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y := match le_total x 0, le_total y 0 with | or.inl hx0, or.inl hy0 := neg_lt_neg_iff.1 $ by rw [← tan_neg, ← tan_neg]; exact tan_lt_tan_of_nonneg_of_lt_pi_div_two (neg_nonneg.2 hy0) (neg_lt.2 hx₁) (neg_lt_neg hxy) | or.inl hx0, or.inr hy0 := (lt_or_eq_of_le hy0).elim (λ hy0, calc tan x ≤ 0 : tan_nonpos_of_nonpos_of_neg_pi_div_two_le hx0 (le_of_lt hx₁) ... < tan y : tan_pos_of_pos_of_lt_pi_div_two hy0 hy₂) (λ hy0, by rw [← hy0, tan_zero]; exact tan_neg_of_neg_of_pi_div_two_lt (hy0.symm ▸ hxy) hx₁) | or.inr hx0, or.inl hy0 := by linarith | or.inr hx0, or.inr hy0 := tan_lt_tan_of_nonneg_of_lt_pi_div_two hx0 hy₂ hxy end lemma strict_mono_incr_on_tan : strict_mono_incr_on tan (Ioo (-(π / 2)) (π / 2)) := λ x hx y hy, tan_lt_tan_of_lt_of_lt_pi_div_two hx.1 hy.2 lemma inj_on_tan : inj_on tan (Ioo (-(π / 2)) (π / 2)) := strict_mono_incr_on_tan.inj_on lemma tan_inj_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) (hy₁ : -(π / 2) < y) (hy₂ : y < π / 2) (hxy : tan x = tan y) : x = y := inj_on_tan ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ hxy end real namespace complex open_locale real /-- `arg` returns values in the range (-π, π], such that for `x ≠ 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`, `arg 0` defaults to `0` -/ noncomputable def arg (x : ℂ) : ℝ := if 0 ≤ x.re then real.arcsin (x.im / x.abs) else if 0 ≤ x.im then real.arcsin ((-x).im / x.abs) + π else real.arcsin ((-x).im / x.abs) - π lemma arg_le_pi (x : ℂ) : arg x ≤ π := if hx₁ : 0 ≤ x.re then by rw [arg, if_pos hx₁]; exact le_trans (real.arcsin_le_pi_div_two _) (le_of_lt (half_lt_self real.pi_pos)) else if hx₂ : 0 ≤ x.im then by rw [arg, if_neg hx₁, if_pos hx₂, ← le_sub_iff_add_le, sub_self, real.arcsin_nonpos, 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₂, ← sub_lt_iff_lt_add]; exact (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₂, lt_sub_iff_add_lt, neg_add_self, real.arcsin_pos, neg_im]; exact div_pos (neg_pos.2 (lt_of_not_ge hx₂)) (abs_pos.2 hx) 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_apply, pow_two, add_sub_cancel, real.sqrt_mul_self hxr] lemma cos_arg {x : ℂ} (hx : x ≠ 0) : real.cos (arg x) = x.re / x.abs := if hxr : 0 ≤ x.re then cos_arg_of_re_nonneg hx hxr else have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos] using hxr, if hxi : 0 ≤ x.im then have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos] using hxr, by rw [arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg (not_le.1 hxr) hxi, real.cos_add_pi, cos_arg_of_re_nonneg (neg_ne_zero.2 hx) this]; simp [neg_div] else by rw [arg_eq_arg_neg_sub_pi_of_im_neg_of_re_neg (not_le.1 hxr) (not_le.1 hxi)]; simp [sub_eq_add_neg, real.cos_add, neg_div, cos_arg_of_re_nonneg (neg_ne_zero.2 hx) this] lemma tan_arg {x : ℂ} : real.tan (arg x) = x.im / x.re := begin by_cases h : x = 0, { simp only [h, zero_div, complex.zero_im, complex.arg_zero, real.tan_zero, complex.zero_re] }, rw [real.tan_eq_sin_div_cos, sin_arg, cos_arg h, div_div_div_cancel_right _ (mt abs_eq_zero.1 h)] end lemma arg_cos_add_sin_mul_I {x : ℝ} (hx₁ : -π < x) (hx₂ : x ≤ π) : arg (cos x + sin x * I) = x := if hx₃ : -(π / 2) ≤ x ∧ x ≤ π / 2 then have hx₄ : 0 ≤ (cos x + sin x * I).re, by simp; exact real.cos_nonneg_of_mem_Icc hx₃, by rw [arg, if_pos hx₄]; simp [abs_cos_add_sin_mul_I, sin_of_real_re, real.arcsin_sin hx₃.1 hx₃.2] else if hx₄ : x < -(π / 2) then have hx₅ : ¬0 ≤ (cos x + sin x * I).re := suffices ¬ 0 ≤ real.cos x, by simpa, not_le.2 $ by rw ← real.cos_neg; apply real.cos_neg_of_pi_div_two_lt_of_lt; linarith, have hx₆ : ¬0 ≤ (cos ↑x + sin ↑x * I).im := suffices real.sin x < 0, by simpa, by apply real.sin_neg_of_neg_of_neg_pi_lt; linarith, suffices -π + -real.arcsin (real.sin x) = x, by rw [arg, if_neg hx₅, if_neg hx₆]; simpa [sub_eq_add_neg, add_comm, abs_cos_add_sin_mul_I, sin_of_real_re], by rw [← real.arcsin_neg, ← real.sin_add_pi, real.arcsin_sin]; try {simp [add_left_comm]}; linarith else have hx₅ : π / 2 < x, by cases not_and_distrib.1 hx₃; linarith, have hx₆ : ¬0 ≤ (cos x + sin x * I).re := suffices ¬0 ≤ real.cos x, by simpa, not_le.2 $ by apply real.cos_neg_of_pi_div_two_lt_of_lt; linarith, have hx₇ : 0 ≤ (cos x + sin x * I).im := suffices 0 ≤ real.sin x, by simpa, by apply real.sin_nonneg_of_nonneg_of_le_pi; linarith, suffices π - real.arcsin (real.sin x) = x, by rw [arg, if_neg hx₆, if_pos hx₇]; simpa [sub_eq_add_neg, add_comm, abs_cos_add_sin_mul_I, sin_of_real_re], by rw [← real.sin_pi_sub, real.arcsin_sin]; simp [sub_eq_add_neg]; linarith lemma arg_eq_arg_iff {x y : ℂ} (hx : x ≠ 0) (hy : y ≠ 0) : arg x = arg y ↔ (abs y / abs x : ℂ) * x = y := have hax : abs x ≠ 0, from (mt abs_eq_zero.1 hx), have hay : abs y ≠ 0, from (mt abs_eq_zero.1 hy), ⟨λ h, begin have hcos := congr_arg real.cos h, rw [cos_arg hx, cos_arg hy, div_eq_div_iff hax hay] at hcos, have hsin := congr_arg real.sin h, rw [sin_arg, sin_arg, div_eq_div_iff hax hay] at hsin, apply complex.ext, { rw [mul_re, ← of_real_div, of_real_re, of_real_im, zero_mul, sub_zero, mul_comm, ← mul_div_assoc, hcos, mul_div_cancel _ hax] }, { rw [mul_im, ← of_real_div, of_real_re, of_real_im, zero_mul, add_zero, mul_comm, ← mul_div_assoc, hsin, mul_div_cancel _ hax] } end, λ h, have hre : abs (y / x) * x.re = y.re, by rw ← of_real_div at h; simpa [-of_real_div] using congr_arg re h, have hre' : abs (x / y) * y.re = x.re, by rw [← hre, abs_div, abs_div, ← mul_assoc, div_mul_div, mul_comm (abs _), div_self (mul_ne_zero hay hax), one_mul], have him : abs (y / x) * x.im = y.im, by rw ← of_real_div at h; simpa [-of_real_div] using congr_arg im h, have him' : abs (x / y) * y.im = x.im, by rw [← him, abs_div, abs_div, ← mul_assoc, div_mul_div, mul_comm (abs _), div_self (mul_ne_zero hay hax), one_mul], have hxya : x.im / abs x = y.im / abs y, by rw [← him, abs_div, mul_comm, ← mul_div_comm, mul_div_cancel_left _ hay], have hnxya : (-x).im / abs x = (-y).im / abs y, by rw [neg_im, neg_im, neg_div, neg_div, hxya], if hxr : 0 ≤ x.re then have hyr : 0 ≤ y.re, from hre ▸ mul_nonneg (abs_nonneg _) hxr, by simp [arg, *] at * else have hyr : ¬ 0 ≤ y.re, from λ hyr, hxr $ hre' ▸ mul_nonneg (abs_nonneg _) hyr, if hxi : 0 ≤ x.im then have hyi : 0 ≤ y.im, from him ▸ mul_nonneg (abs_nonneg _) hxi, by simp [arg, *] at * else have hyi : ¬ 0 ≤ y.im, from λ hyi, hxi $ him' ▸ mul_nonneg (abs_nonneg _) hyi, by simp [arg, *] at *⟩ lemma arg_real_mul (x : ℂ) {r : ℝ} (hr : 0 < r) : arg (r * x) = arg x := if hx : x = 0 then by simp [hx] else (arg_eq_arg_iff (mul_ne_zero (of_real_ne_zero.2 (ne_of_lt hr).symm) hx) hx).2 $ by rw [abs_mul, abs_of_nonneg (le_of_lt hr), ← mul_assoc, of_real_mul, mul_comm (r : ℂ), ← div_div_eq_div_mul, div_mul_cancel _ (of_real_ne_zero.2 (ne_of_lt hr).symm), div_self (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), one_mul] lemma ext_abs_arg {x y : ℂ} (h₁ : x.abs = y.abs) (h₂ : x.arg = y.arg) : x = y := if hy : y = 0 then by simp * at * else have hx : x ≠ 0, from λ hx, by simp [*, eq_comm] at *, by rwa [arg_eq_arg_iff hx hy, h₁, div_self (of_real_ne_zero.2 (mt abs_eq_zero.1 hy)), one_mul] at h₂ lemma arg_of_real_of_nonneg {x : ℝ} (hx : 0 ≤ x) : arg x = 0 := by simp [arg, hx] lemma arg_of_real_of_neg {x : ℝ} (hx : x < 0) : arg x = π := by rw [arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg, ← of_real_neg, arg_of_real_of_nonneg]; simp [*, le_iff_eq_or_lt, lt_neg] /-- Inverse of the `exp` function. Returns values such that `(log x).im > - π` and `(log x).im ≤ π`. `log 0 = 0`-/ @[pp_nodot] noncomputable def log (x : ℂ) : ℂ := x.abs.log + arg x * I lemma log_re (x : ℂ) : x.log.re = x.abs.log := by simp [log] lemma log_im (x : ℂ) : x.log.im = x.arg := by simp [log] lemma exp_log {x : ℂ} (hx : x ≠ 0) : exp (log x) = x := by rw [log, exp_add_mul_I, ← of_real_sin, sin_arg, ← of_real_cos, cos_arg hx, ← of_real_exp, real.exp_log (abs_pos.2 hx), mul_add, of_real_div, of_real_div, mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), ← mul_assoc, mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), re_add_im] lemma range_exp : range exp = {x | x ≠ 0} := set.ext $ λ x, ⟨by { rintro ⟨x, rfl⟩, exact exp_ne_zero x }, λ hx, ⟨log x, exp_log hx⟩⟩ lemma exp_inj_of_neg_pi_lt_of_le_pi {x y : ℂ} (hx₁ : -π < x.im) (hx₂ : x.im ≤ π) (hy₁ : - π < y.im) (hy₂ : y.im ≤ π) (hxy : exp x = exp y) : x = y := by rw [exp_eq_exp_re_mul_sin_add_cos, exp_eq_exp_re_mul_sin_add_cos y] at hxy; exact complex.ext (real.exp_injective $ by simpa [abs_mul, abs_cos_add_sin_mul_I] using congr_arg complex.abs hxy) (by simpa [(of_real_exp _).symm, - of_real_exp, arg_real_mul _ (real.exp_pos _), arg_cos_add_sin_mul_I hx₁ hx₂, arg_cos_add_sin_mul_I hy₁ hy₂] using congr_arg arg hxy) lemma log_exp {x : ℂ} (hx₁ : -π < x.im) (hx₂: x.im ≤ π) : log (exp x) = x := exp_inj_of_neg_pi_lt_of_le_pi (by rw log_im; exact neg_pi_lt_arg _) (by rw log_im; exact arg_le_pi _) hx₁ hx₂ (by rw [exp_log (exp_ne_zero _)]) lemma of_real_log {x : ℝ} (hx : 0 ≤ x) : (x.log : ℂ) = log x := complex.ext (by rw [log_re, of_real_re, abs_of_nonneg hx]) (by rw [of_real_im, log_im, arg_of_real_of_nonneg hx]) lemma log_of_real_re (x : ℝ) : (log (x : ℂ)).re = real.log x := by simp [log_re] @[simp] lemma log_zero : log 0 = 0 := by simp [log] @[simp] lemma log_one : log 1 = 0 := by simp [log] lemma log_neg_one : log (-1) = π * I := by simp [log] lemma log_I : log I = π / 2 * I := by simp [log] lemma log_neg_I : log (-I) = -(π / 2) * I := by simp [log] lemma exists_pow_nat_eq (x : ℂ) {n : ℕ} (hn : 0 < n) : ∃ z, z ^ n = x := begin by_cases hx : x = 0, { use 0, simp only [hx, zero_pow_eq_zero, hn] }, { use exp (log x / n), rw [← exp_nat_mul, mul_div_cancel', exp_log hx], exact_mod_cast (pos_iff_ne_zero.mp hn) } end lemma exists_eq_mul_self (x : ℂ) : ∃ z, x = z * z := begin obtain ⟨z, rfl⟩ := exists_pow_nat_eq x zero_lt_two, exact ⟨z, pow_two z⟩ end lemma two_pi_I_ne_zero : (2 * π * I : ℂ) ≠ 0 := by norm_num [real.pi_ne_zero, I_ne_zero] lemma exp_eq_one_iff {x : ℂ} : exp x = 1 ↔ ∃ n : ℤ, x = n * ((2 * π) * I) := have real.exp (x.re) * real.cos (x.im) = 1 → real.cos x.im ≠ -1, from λ h₁ h₂, begin rw [h₂, mul_neg_eq_neg_mul_symm, mul_one, neg_eq_iff_neg_eq] at h₁, have := real.exp_pos x.re, rw ← h₁ at this, exact absurd this (by norm_num) end, calc exp x = 1 ↔ (exp x).re = 1 ∧ (exp x).im = 0 : by simp [complex.ext_iff] ... ↔ real.cos x.im = 1 ∧ real.sin x.im = 0 ∧ x.re = 0 : begin rw exp_eq_exp_re_mul_sin_add_cos, simp [complex.ext_iff, cos_of_real_re, sin_of_real_re, exp_of_real_re, real.exp_ne_zero], split; finish [real.sin_eq_zero_iff_cos_eq] end ... ↔ (∃ n : ℤ, ↑n * (2 * π) = x.im) ∧ (∃ n : ℤ, ↑n * π = x.im) ∧ x.re = 0 : by rw [real.sin_eq_zero_iff, real.cos_eq_one_iff] ... ↔ ∃ n : ℤ, x = n * ((2 * π) * I) : ⟨λ ⟨⟨n, hn⟩, ⟨m, hm⟩, h⟩, ⟨n, by simp [complex.ext_iff, hn.symm, h]⟩, λ ⟨n, hn⟩, ⟨⟨n, by simp [hn]⟩, ⟨2 * n, by simp [hn, mul_comm, mul_assoc, mul_left_comm]⟩, by simp [hn]⟩⟩ lemma exp_eq_exp_iff_exp_sub_eq_one {x y : ℂ} : exp x = exp y ↔ exp (x - y) = 1 := by rw [exp_sub, div_eq_one_iff_eq (exp_ne_zero _)] lemma exp_eq_exp_iff_exists_int {x y : ℂ} : exp x = exp y ↔ ∃ n : ℤ, x = y + n * ((2 * π) * I) := by simp only [exp_eq_exp_iff_exp_sub_eq_one, exp_eq_one_iff, sub_eq_iff_eq_add'] @[simp] lemma cos_pi_div_two : cos (π / 2) = 0 := calc cos (π / 2) = real.cos (π / 2) : by rw [of_real_cos]; simp ... = 0 : by simp @[simp] lemma sin_pi_div_two : sin (π / 2) = 1 := calc sin (π / 2) = real.sin (π / 2) : by rw [of_real_sin]; simp ... = 1 : by simp @[simp] lemma sin_pi : sin π = 0 := by rw [← of_real_sin, real.sin_pi]; simp @[simp] lemma cos_pi : cos π = -1 := by rw [← of_real_cos, real.cos_pi]; simp @[simp] lemma sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add] @[simp] lemma cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add] lemma sin_add_pi (x : ℂ) : sin (x + π) = -sin x := by simp [sin_add] lemma sin_add_two_pi (x : ℂ) : sin (x + 2 * π) = sin x := by simp [sin_add_pi, sin_add, sin_two_pi, cos_two_pi] lemma cos_add_two_pi (x : ℂ) : cos (x + 2 * π) = cos x := by simp [cos_add, cos_two_pi, sin_two_pi] lemma sin_pi_sub (x : ℂ) : sin (π - x) = sin x := by simp [sub_eq_add_neg, sin_add] lemma cos_add_pi (x : ℂ) : cos (x + π) = -cos x := by simp [cos_add] lemma cos_pi_sub (x : ℂ) : cos (π - x) = -cos x := by simp [sub_eq_add_neg, cos_add] lemma sin_add_pi_div_two (x : ℂ) : sin (x + π / 2) = cos x := by simp [sin_add] lemma sin_sub_pi_div_two (x : ℂ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add] lemma sin_pi_div_two_sub (x : ℂ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add] lemma cos_add_pi_div_two (x : ℂ) : cos (x + π / 2) = -sin x := by simp [cos_add] lemma cos_sub_pi_div_two (x : ℂ) : cos (x - π / 2) = sin x := by simp [sub_eq_add_neg, cos_add] lemma cos_pi_div_two_sub (x : ℂ) : cos (π / 2 - x) = sin x := by rw [← cos_neg, neg_sub, cos_sub_pi_div_two] lemma sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 := by induction n; simp [add_mul, sin_add, *] lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 := by cases n; simp [add_mul, sin_add, *, sin_nat_mul_pi] lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 := by induction n; simp [*, mul_add, cos_add, add_mul, cos_two_pi, sin_two_pi] lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 := by cases n; simp only [cos_nat_mul_two_pi, int.of_nat_eq_coe, int.neg_succ_of_nat_coe, int.cast_coe_nat, int.cast_neg, (neg_mul_eq_neg_mul _ _).symm, cos_neg] lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 := by simp [cos_add, sin_add, cos_int_mul_two_pi] lemma exp_pi_mul_I : exp (π * I) = -1 := by { rw exp_mul_I, simp, } theorem cos_eq_zero_iff {θ : ℂ} : cos θ = 0 ↔ ∃ k : ℤ, θ = (2 * k + 1) * π / 2 := begin have h : (exp (θ * I) + exp (-θ * I)) / 2 = 0 ↔ exp (2 * θ * I) = -1, { rw [@div_eq_iff _ _ (exp (θ * I) + exp (-θ * I)) 2 0 (by norm_num), zero_mul, add_eq_zero_iff_eq_neg, neg_eq_neg_one_mul (exp (-θ * I)), ← div_eq_iff (exp_ne_zero (-θ * I)), ← exp_sub], field_simp, ring }, rw [cos, h, ← exp_pi_mul_I, exp_eq_exp_iff_exists_int], split; simp; intros x h2; use x, { field_simp, ring at h2, rwa [mul_right_comm 2 I θ, mul_right_comm (2*(x:ℂ)+1) I (π:ℂ), mul_left_inj' I_ne_zero, mul_comm 2 θ] at h2}, { field_simp at h2, ring, rw [mul_right_comm 2 I θ, mul_right_comm (2*(x:ℂ)+1) I (π:ℂ), mul_left_inj' I_ne_zero, mul_comm 2 θ, h2] }, end theorem cos_ne_zero_iff {θ : ℂ} : cos θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ (2 * k + 1) * π / 2 := by rw [← not_exists, not_iff_not, cos_eq_zero_iff] theorem sin_eq_zero_iff {θ : ℂ} : sin θ = 0 ↔ ∃ k : ℤ, θ = k * π := begin rw [← complex.cos_sub_pi_div_two, cos_eq_zero_iff], split, { rintros ⟨k, hk⟩, use k + 1, field_simp [eq_add_of_sub_eq hk], ring }, { rintros ⟨k, rfl⟩, use k - 1, field_simp, ring } end theorem sin_ne_zero_iff {θ : ℂ} : sin θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ k * π := by rw [← not_exists, not_iff_not, sin_eq_zero_iff] lemma cos_eq_cos_iff {x y : ℂ} : cos x = cos y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x := calc cos x = cos y ↔ cos x - cos y = 0 : sub_eq_zero.symm ... ↔ -2 * sin((x + y)/2) * sin((x - y)/2) = 0 : by rw cos_sub_cos ... ↔ sin((x + y)/2) = 0 ∨ sin((x - y)/2) = 0 : by 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 has_deriv_at_tan {x : ℂ} (h : cos x ≠ 0) : 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) h, rw ← sin_sq_add_cos_sq x, ring, end lemma tendsto_abs_tan_of_cos_eq_zero {x : ℂ} (hx : cos x = 0) : tendsto (λ x, abs (tan x)) (𝓝[{x}ᶜ] x) at_top := begin simp only [tan_eq_sin_div_cos, ← norm_eq_abs, normed_field.norm_div], have A : sin x ≠ 0 := λ h, by simpa [*, pow_two] using sin_sq_add_cos_sq x, have B : tendsto cos (𝓝[{x}ᶜ] (x)) (𝓝[{0}ᶜ] 0), { refine tendsto_inf.2 ⟨tendsto.mono_left _ inf_le_left, tendsto_principal.2 _⟩, exacts [continuous_cos.tendsto' x 0 hx, hx ▸ (has_deriv_at_cos _).eventually_ne (neg_ne_zero.2 A)] }, exact tendsto.mul_at_top (norm_pos_iff.2 A) continuous_sin.continuous_within_at.norm (tendsto.inv_tendsto_zero $ tendsto_norm_nhds_within_zero.comp B), end lemma tendsto_abs_tan_at_top (k : ℤ) : tendsto (λ x, abs (tan x)) (𝓝[{(2 * k + 1) * π / 2}ᶜ] ((2 * k + 1) * π / 2)) at_top := tendsto_abs_tan_of_cos_eq_zero $ cos_eq_zero_iff.2 ⟨k, rfl⟩ @[simp] lemma continuous_at_tan {x : ℂ} : continuous_at tan x ↔ cos x ≠ 0 := begin refine ⟨λ hc h₀, _, λ h, (has_deriv_at_tan h).continuous_at⟩, exact not_tendsto_nhds_of_tendsto_at_top (tendsto_abs_tan_of_cos_eq_zero h₀) _ (hc.norm.tendsto.mono_left inf_le_left) end @[simp] lemma differentiable_at_tan {x : ℂ} : differentiable_at ℂ tan x ↔ cos x ≠ 0:= ⟨λ h, continuous_at_tan.1 h.continuous_at, λ h, (has_deriv_at_tan h).differentiable_at⟩ @[simp] lemma deriv_tan (x : ℂ) : deriv tan x = 1 / (cos x)^2 := if h : cos x = 0 then have ¬differentiable_at ℂ tan x := mt differentiable_at_tan.1 (not_not.2 h), by simp [deriv_zero_of_not_differentiable_at this, h, pow_two] else (has_deriv_at_tan h).deriv lemma continuous_on_tan : continuous_on tan {x | cos x ≠ 0} := continuous_on_sin.div continuous_on_cos $ λ x, id lemma continuous_tan : continuous (λ x : {x | cos x ≠ 0}, tan x) := continuous_on_iff_continuous_restrict.1 continuous_on_tan @[simp] lemma times_cont_diff_at_tan {x : ℂ} {n : with_top ℕ} : times_cont_diff_at ℂ n tan x ↔ cos x ≠ 0 := ⟨λ h, continuous_at_tan.1 h.continuous_at, times_cont_diff_sin.times_cont_diff_at.div times_cont_diff_cos.times_cont_diff_at⟩ 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 (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 section chebyshev₁ open polynomial complex /-- the `n`-th Chebyshev polynomial evaluates on `cos θ` to the value `cos (n * θ)`. -/ lemma chebyshev₁_complex_cos (θ : ℂ) : ∀ n, (chebyshev₁ ℂ n).eval (cos θ) = cos (n * θ) | 0 := by simp only [chebyshev₁_zero, eval_one, nat.cast_zero, zero_mul, cos_zero] | 1 := by simp only [eval_X, one_mul, chebyshev₁_one, nat.cast_one] | (n + 2) := begin simp only [eval_X, eval_one, chebyshev₁_add_two, eval_sub, eval_bit0, nat.cast_succ, eval_mul], rw [chebyshev₁_complex_cos (n + 1), chebyshev₁_complex_cos n], have aux : sin θ * sin θ = 1 - cos θ * cos θ, { rw ← sin_sq_add_cos_sq θ, ring, }, simp only [nat.cast_add, nat.cast_one, add_mul, cos_add, one_mul, sin_add, mul_assoc, aux], ring, end /-- `cos (n * θ)` is equal to the `n`-th Chebyshev polynomial evaluated on `cos θ`. -/ lemma cos_nat_mul (n : ℕ) (θ : ℂ) : cos (n * θ) = (chebyshev₁ ℂ n).eval (cos θ) := (chebyshev₁_complex_cos θ n).symm end chebyshev₁ namespace real open_locale real theorem cos_eq_zero_iff {θ : ℝ} : cos θ = 0 ↔ ∃ k : ℤ, θ = (2 * k + 1) * π / 2 := 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 has_deriv_at_tan {x : ℝ} (h : cos x ≠ 0) : has_deriv_at tan (1 / (cos x)^2) x := by exact_mod_cast (complex.has_deriv_at_tan (by exact_mod_cast h)).real_of_complex lemma tendsto_abs_tan_of_cos_eq_zero {x : ℝ} (hx : cos x = 0) : tendsto (λ x, abs (tan x)) (𝓝[{x}ᶜ] x) at_top := begin have hx : complex.cos x = 0, by exact_mod_cast hx, simp only [← complex.abs_of_real, complex.of_real_tan], refine (complex.tendsto_abs_tan_of_cos_eq_zero hx).comp _, refine tendsto.inf complex.continuous_of_real.continuous_at _, exact tendsto_principal_principal.2 (λ y, mt complex.of_real_inj.1) end lemma tendsto_abs_tan_at_top (k : ℤ) : tendsto (λ x, abs (tan x)) (𝓝[{(2 * k + 1) * π / 2}ᶜ] ((2 * k + 1) * π / 2)) at_top := tendsto_abs_tan_of_cos_eq_zero $ cos_eq_zero_iff.2 ⟨k, rfl⟩ lemma continuous_at_tan {x : ℝ} : continuous_at tan x ↔ cos x ≠ 0 := begin refine ⟨λ hc h₀, _, λ h, (has_deriv_at_tan h).continuous_at⟩, exact not_tendsto_nhds_of_tendsto_at_top (tendsto_abs_tan_of_cos_eq_zero h₀) _ (hc.norm.tendsto.mono_left inf_le_left) end lemma differentiable_at_tan {x : ℝ} : differentiable_at ℝ tan x ↔ cos x ≠ 0 := ⟨λ h, continuous_at_tan.1 h.continuous_at, λ h, (has_deriv_at_tan h).differentiable_at⟩ @[simp] lemma deriv_tan (x : ℝ) : deriv tan x = 1 / (cos x)^2 := if h : cos x = 0 then have ¬differentiable_at ℝ tan x := mt differentiable_at_tan.1 (not_not.2 h), by simp [deriv_zero_of_not_differentiable_at this, h, pow_two] else (has_deriv_at_tan h).deriv @[simp] lemma times_cont_diff_at_tan {n x} : times_cont_diff_at ℝ n tan x ↔ cos x ≠ 0 := ⟨λ h, continuous_at_tan.1 h.continuous_at, λ h, (complex.times_cont_diff_at_tan.2 $ by exact_mod_cast h).real_of_complex⟩ lemma continuous_on_tan : continuous_on tan {x | cos x ≠ 0} := λ x hx, (continuous_at_tan.2 hx).continuous_within_at 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_pos_of_mem_Ioo h).ne' 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 continuous_on_tan_Ioo : continuous_on tan (Ioo (-(π/2)) (π/2)) := λ x hx, (differentiable_at_tan_of_mem_Ioo hx).continuous_at.continuous_within_at lemma tendsto_sin_pi_div_two : tendsto sin (𝓝[Iio (π/2)] (π/2)) (𝓝 1) := by { convert continuous_sin.continuous_within_at, simp } lemma tendsto_cos_pi_div_two : tendsto cos (𝓝[Iio (π/2)] (π/2)) (𝓝[Ioi 0] 0) := begin apply tendsto_nhds_within_of_tendsto_nhds_of_eventually_within, { convert continuous_cos.continuous_within_at, simp }, { filter_upwards [Ioo_mem_nhds_within_Iio (right_mem_Ioc.mpr (norm_num.lt_neg_pos _ _ pi_div_two_pos pi_div_two_pos))] λ x hx, cos_pos_of_mem_Ioo hx }, end lemma tendsto_tan_pi_div_two : tendsto tan (𝓝[Iio (π/2)] (π/2)) at_top := begin convert (tendsto.inv_tendsto_zero tendsto_cos_pi_div_two).at_top_mul (by norm_num) tendsto_sin_pi_div_two, simp only [pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos] end lemma tendsto_sin_neg_pi_div_two : tendsto sin (𝓝[Ioi (-(π/2))] (-(π/2))) (𝓝 (-1)) := by { convert continuous_sin.continuous_within_at, simp } lemma tendsto_cos_neg_pi_div_two : tendsto cos (𝓝[Ioi (-(π/2))] (-(π/2))) (𝓝[Ioi 0] 0) := begin apply tendsto_nhds_within_of_tendsto_nhds_of_eventually_within, { convert continuous_cos.continuous_within_at, simp }, { filter_upwards [Ioo_mem_nhds_within_Ioi (set.left_mem_Ico.mpr (norm_num.lt_neg_pos _ _ pi_div_two_pos pi_div_two_pos))] λ x hx, cos_pos_of_mem_Ioo hx }, end lemma tendsto_tan_neg_pi_div_two : tendsto tan (𝓝[Ioi (-(π/2))] (-(π/2))) at_bot := begin convert (tendsto.inv_tendsto_zero tendsto_cos_neg_pi_div_two).at_top_mul_neg (by norm_num) tendsto_sin_neg_pi_div_two, simp only [pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos] end lemma surj_on_tan : surj_on tan (Ioo (-(π / 2)) (π / 2)) univ := have _ := neg_lt_self pi_div_two_pos, continuous_on_tan_Ioo.surj_on_of_tendsto (nonempty_Ioo.2 this) (by simp [tendsto_tan_neg_pi_div_two, this]) (by simp [tendsto_tan_pi_div_two, this]) lemma tan_surjective : function.surjective tan := λ x, surj_on_tan.subset_range trivial lemma image_tan_Ioo : tan '' (Ioo (-(π / 2)) (π / 2)) = univ := univ_subset_iff.1 surj_on_tan /-- `real.tan` as an `order_iso` between `(-(π / 2), π / 2)` and `ℝ`. -/ def tan_order_iso : Ioo (-(π / 2)) (π / 2) ≃o ℝ := (strict_mono_incr_on_tan.order_iso _ _).trans $ (order_iso.set_congr _ _ image_tan_Ioo).trans order_iso.set.univ /-- Inverse of the `tan` function, returns values in the range `-π / 2 < arctan x` and `arctan x < π / 2` -/ @[pp_nodot] noncomputable def arctan (x : ℝ) : ℝ := tan_order_iso.symm x @[simp] lemma tan_arctan (x : ℝ) : tan (arctan x) = x := tan_order_iso.apply_symm_apply x lemma arctan_mem_Ioo (x : ℝ) : arctan x ∈ Ioo (-(π / 2)) (π / 2) := subtype.coe_prop _ lemma arctan_tan {x : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) : arctan (tan x) = x := subtype.ext_iff.1 $ tan_order_iso.symm_apply_apply ⟨x, hx₁, hx₂⟩ lemma cos_arctan_pos (x : ℝ) : 0 < cos (arctan x) := cos_pos_of_mem_Ioo $ arctan_mem_Ioo x lemma cos_sq_arctan (x : ℝ) : cos (arctan x) ^ 2 = 1 / (1 + x ^ 2) := by rw [one_div, ← inv_one_add_tan_sq (cos_arctan_pos x).ne', tan_arctan] lemma sin_arctan (x : ℝ) : sin (arctan x) = x / sqrt (1 + x ^ 2) := by rw [← tan_div_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan] lemma cos_arctan (x : ℝ) : cos (arctan x) = 1 / sqrt (1 + x ^ 2) := by rw [one_div, ← inv_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan] lemma arctan_lt_pi_div_two (x : ℝ) : arctan x < π / 2 := (arctan_mem_Ioo x).2 lemma neg_pi_div_two_lt_arctan (x : ℝ) : -(π / 2) < arctan x := (arctan_mem_Ioo x).1 lemma arctan_eq_arcsin (x : ℝ) : arctan x = arcsin (x / sqrt (1 + x ^ 2)) := eq.symm $ arcsin_eq_of_sin_eq (sin_arctan x) (mem_Icc_of_Ioo $ arctan_mem_Ioo x) @[simp] lemma arctan_zero : arctan 0 = 0 := by simp [arctan_eq_arcsin] lemma arctan_eq_of_tan_eq {x y : ℝ} (h : tan x = y) (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : arctan y = x := inj_on_tan (arctan_mem_Ioo _) hx (by rw [tan_arctan, h]) @[simp] lemma arctan_one : arctan 1 = π / 4 := arctan_eq_of_tan_eq tan_pi_div_four $ by split; linarith [pi_pos] @[simp] lemma arctan_neg (x : ℝ) : arctan (-x) = - arctan x := by simp [arctan_eq_arcsin, neg_div] lemma continuous_arctan : continuous arctan := continuous_subtype_coe.comp tan_order_iso.to_homeomorph.continuous_inv_fun lemma continuous_at_arctan {x : ℝ} : continuous_at arctan x := continuous_arctan.continuous_at /-- `real.tan` as a `local_homeomorph` between `(-(π / 2), π / 2)` and the whole line. -/ def tan_local_homeomorph : local_homeomorph ℝ ℝ := { to_fun := tan, inv_fun := arctan, source := Ioo (-(π / 2)) (π / 2), target := univ, map_source' := maps_to_univ _ _, map_target' := λ y hy, arctan_mem_Ioo y, left_inv' := λ x hx, arctan_tan hx.1 hx.2, right_inv' := λ y hy, tan_arctan y, open_source := is_open_Ioo, open_target := is_open_univ, continuous_to_fun := continuous_on_tan_Ioo, continuous_inv_fun := continuous_arctan.continuous_on } @[simp] lemma coe_tan_local_homeomorph : ⇑tan_local_homeomorph = tan := rfl @[simp] lemma coe_tan_local_homeomorph_symm : ⇑tan_local_homeomorph.symm = arctan := rfl lemma has_deriv_at_arctan (x : ℝ) : has_deriv_at arctan (1 / (1 + x^2)) x := have A : cos (arctan x) ≠ 0 := (cos_arctan_pos x).ne', by simpa [cos_sq_arctan] using tan_local_homeomorph.has_deriv_at_symm trivial (by simpa) (has_deriv_at_tan A) lemma differentiable_at_arctan (x : ℝ) : differentiable_at ℝ arctan x := (has_deriv_at_arctan x).differentiable_at lemma differentiable_arctan : differentiable ℝ arctan := differentiable_at_arctan @[simp] lemma deriv_arctan : deriv arctan = (λ x, 1 / (1 + x^2)) := funext $ λ x, (has_deriv_at_arctan x).deriv lemma times_cont_diff_arctan {n : with_top ℕ} : times_cont_diff ℝ n arctan := times_cont_diff_iff_times_cont_diff_at.2 $ λ x, have cos (arctan x) ≠ 0 := (cos_arctan_pos x).ne', tan_local_homeomorph.times_cont_diff_at_symm_deriv (by simpa) trivial (has_deriv_at_tan this) (times_cont_diff_at_tan.2 this) lemma measurable_arctan : measurable arctan := continuous_arctan.measurable end real section /-! ### Lemmas for derivatives of the composition of `real.arctan` with a differentiable function In this section we register lemmas for the derivatives of the composition of `real.arctan` with a differentiable function, for standalone use and use with `simp`. -/ open real lemma measurable.arctan {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) : measurable (λ x, arctan (f x)) := measurable_arctan.comp hf section deriv variables {f : ℝ → ℝ} {f' x : ℝ} {s : set ℝ} lemma has_deriv_at.arctan (hf : has_deriv_at f f' x) : has_deriv_at (λ x, 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, 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 deriv_within_arctan (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : deriv_within (λ x, 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, arctan (f x)) x = (1 / (1 + (f x)^2)) * (deriv f x) := hc.has_deriv_at.arctan.deriv end deriv section fderiv variables {E : Type*} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {f' : E →L[ℝ] ℝ} {x : E} {s : set E} {n : with_top ℕ} lemma has_fderiv_at.arctan (hf : has_fderiv_at f f' x) : has_fderiv_at (λ x, arctan (f x)) ((1 / (1 + (f x)^2)) • f') x := (has_deriv_at_arctan (f x)).comp_has_fderiv_at x hf lemma has_fderiv_within_at.arctan (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, arctan (f x)) ((1 / (1 + (f x)^2)) • f') s x := (has_deriv_at_arctan (f x)).comp_has_fderiv_within_at x hf lemma fderiv_within_arctan (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : fderiv_within ℝ (λ x, arctan (f x)) s x = (1 / (1 + (f x)^2)) • (fderiv_within ℝ f s x) := hf.has_fderiv_within_at.arctan.fderiv_within hxs @[simp] lemma fderiv_arctan (hc : differentiable_at ℝ f x) : fderiv ℝ (λ x, arctan (f x)) x = (1 / (1 + (f x)^2)) • (fderiv ℝ f x) := hc.has_fderiv_at.arctan.fderiv lemma differentiable_within_at.arctan (hf : differentiable_within_at ℝ f s x) : differentiable_within_at ℝ (λ x, real.arctan (f x)) s x := hf.has_fderiv_within_at.arctan.differentiable_within_at @[simp] lemma differentiable_at.arctan (hc : differentiable_at ℝ f x) : differentiable_at ℝ (λ x, arctan (f x)) x := hc.has_fderiv_at.arctan.differentiable_at lemma differentiable_on.arctan (hc : differentiable_on ℝ f s) : differentiable_on ℝ (λ x, arctan (f x)) s := λ x h, (hc x h).arctan @[simp] lemma differentiable.arctan (hc : differentiable ℝ f) : differentiable ℝ (λ x, arctan (f x)) := λ x, (hc x).arctan lemma times_cont_diff_at.arctan (h : times_cont_diff_at ℝ n f x) : times_cont_diff_at ℝ n (λ x, arctan (f x)) x := times_cont_diff_arctan.times_cont_diff_at.comp x h lemma times_cont_diff.arctan (h : times_cont_diff ℝ n f) : times_cont_diff ℝ n (λ x, arctan (f x)) := times_cont_diff_arctan.comp h lemma times_cont_diff_within_at.arctan (h : times_cont_diff_within_at ℝ n f s x) : times_cont_diff_within_at ℝ n (λ x, arctan (f x)) s x := times_cont_diff_arctan.comp_times_cont_diff_within_at h lemma times_cont_diff_on.arctan (h : times_cont_diff_on ℝ n f s) : times_cont_diff_on ℝ n (λ x, arctan (f x)) s := times_cont_diff_arctan.comp_times_cont_diff_on h end fderiv end
b806765c40efb0fd441aba590d113fedca35f9af
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/topology/list.lean
5f4fef4fe0861cfcd03babb460ca62d2bcc5d640
[]
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,900
lean
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.topology.constructions import Mathlib.topology.algebra.group import Mathlib.PostPort universes u_1 u_2 namespace Mathlib /-! # Topology on lists and vectors -/ protected instance list.topological_space {α : Type u_1} [topological_space α] : topological_space (List α) := topological_space.mk_of_nhds (traverse nhds) theorem nhds_list {α : Type u_1} [topological_space α] (as : List α) : nhds as = traverse nhds as := sorry @[simp] theorem nhds_nil {α : Type u_1} [topological_space α] : nhds [] = pure [] := eq.mpr (id (Eq._oldrec (Eq.refl (nhds [] = pure [])) (nhds_list []))) (eq.mpr (id (Eq._oldrec (Eq.refl (traverse nhds [] = pure [])) (list.traverse_nil nhds))) (Eq.refl (pure []))) theorem nhds_cons {α : Type u_1} [topological_space α] (a : α) (l : List α) : nhds (a :: l) = List.cons <$> nhds a <*> nhds l := sorry theorem list.tendsto_cons {α : Type u_1} [topological_space α] {a : α} {l : List α} : filter.tendsto (fun (p : α × List α) => prod.fst p :: prod.snd p) (filter.prod (nhds a) (nhds l)) (nhds (a :: l)) := sorry theorem filter.tendsto.cons {β : Type u_2} [topological_space β] {α : Type u_1} {f : α → β} {g : α → List β} {a : filter α} {b : β} {l : List β} (hf : filter.tendsto f a (nhds b)) (hg : filter.tendsto g a (nhds l)) : filter.tendsto (fun (a : α) => f a :: g a) a (nhds (b :: l)) := filter.tendsto.comp list.tendsto_cons (filter.tendsto.prod_mk hf hg) namespace list theorem tendsto_cons_iff {α : Type u_1} [topological_space α] {β : Type u_2} {f : List α → β} {b : filter β} {a : α} {l : List α} : filter.tendsto f (nhds (a :: l)) b ↔ filter.tendsto (fun (p : α × List α) => f (prod.fst p :: prod.snd p)) (filter.prod (nhds a) (nhds l)) b := sorry theorem continuous_cons {α : Type u_1} [topological_space α] : continuous fun (x : α × List α) => prod.fst x :: prod.snd x := sorry theorem tendsto_nhds {α : Type u_1} [topological_space α] {β : Type u_2} {f : List α → β} {r : List α → filter β} (h_nil : filter.tendsto f (pure []) (r [])) (h_cons : ∀ (l : List α) (a : α), filter.tendsto f (nhds l) (r l) → filter.tendsto (fun (p : α × List α) => f (prod.fst p :: prod.snd p)) (filter.prod (nhds a) (nhds l)) (r (a :: l))) (l : List α) : filter.tendsto f (nhds l) (r l) := sorry theorem continuous_at_length {α : Type u_1} [topological_space α] (l : List α) : continuous_at length l := sorry theorem tendsto_insert_nth' {α : Type u_1} [topological_space α] {a : α} {n : ℕ} {l : List α} : filter.tendsto (fun (p : α × List α) => insert_nth n (prod.fst p) (prod.snd p)) (filter.prod (nhds a) (nhds l)) (nhds (insert_nth n a l)) := sorry theorem tendsto_insert_nth {α : Type u_1} [topological_space α] {β : Type u_2} {n : ℕ} {a : α} {l : List α} {f : β → α} {g : β → List α} {b : filter β} (hf : filter.tendsto f b (nhds a)) (hg : filter.tendsto g b (nhds l)) : filter.tendsto (fun (b : β) => insert_nth n (f b) (g b)) b (nhds (insert_nth n a l)) := filter.tendsto.comp tendsto_insert_nth' (filter.tendsto.prod_mk hf hg) theorem continuous_insert_nth {α : Type u_1} [topological_space α] {n : ℕ} : continuous fun (p : α × List α) => insert_nth n (prod.fst p) (prod.snd p) := sorry theorem tendsto_remove_nth {α : Type u_1} [topological_space α] {n : ℕ} {l : List α} : filter.tendsto (fun (l : List α) => remove_nth l n) (nhds l) (nhds (remove_nth l n)) := sorry theorem continuous_remove_nth {α : Type u_1} [topological_space α] {n : ℕ} : continuous fun (l : List α) => remove_nth l n := iff.mpr continuous_iff_continuous_at fun (a : List α) => tendsto_remove_nth theorem tendsto_sum {α : Type u_1} [topological_space α] [add_monoid α] [has_continuous_add α] {l : List α} : filter.tendsto sum (nhds l) (nhds (sum l)) := sorry theorem continuous_sum {α : Type u_1} [topological_space α] [add_monoid α] [has_continuous_add α] : continuous sum := iff.mpr continuous_iff_continuous_at fun (l : List α) => tendsto_sum end list namespace vector protected instance topological_space {α : Type u_1} [topological_space α] (n : ℕ) : topological_space (vector α n) := eq.mpr sorry subtype.topological_space theorem tendsto_cons {α : Type u_1} [topological_space α] {n : ℕ} {a : α} {l : vector α n} : filter.tendsto (fun (p : α × vector α n) => prod.fst p::ᵥprod.snd p) (filter.prod (nhds a) (nhds l)) (nhds (a::ᵥl)) := sorry theorem tendsto_insert_nth {α : Type u_1} [topological_space α] {n : ℕ} {i : fin (n + 1)} {a : α} {l : vector α n} : filter.tendsto (fun (p : α × vector α n) => insert_nth (prod.fst p) i (prod.snd p)) (filter.prod (nhds a) (nhds l)) (nhds (insert_nth a i l)) := sorry theorem continuous_insert_nth' {α : Type u_1} [topological_space α] {n : ℕ} {i : fin (n + 1)} : continuous fun (p : α × vector α n) => insert_nth (prod.fst p) i (prod.snd p) := sorry theorem continuous_insert_nth {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β] {n : ℕ} {i : fin (n + 1)} {f : β → α} {g : β → vector α n} (hf : continuous f) (hg : continuous g) : continuous fun (b : β) => insert_nth (f b) i (g b) := continuous.comp continuous_insert_nth' (continuous.prod_mk hf hg) theorem continuous_at_remove_nth {α : Type u_1} [topological_space α] {n : ℕ} {i : fin (n + 1)} {l : vector α (n + 1)} : continuous_at (remove_nth i) l := sorry -- ∀{l:vector α (n+1)}, tendsto (remove_nth i) (𝓝 l) (𝓝 (remove_nth i l)) --| ⟨l, hl⟩ := theorem continuous_remove_nth {α : Type u_1} [topological_space α] {n : ℕ} {i : fin (n + 1)} : continuous (remove_nth i) := sorry
0867834d31ff6db5b812edc32cea9e8c082a5af0
cf39355caa609c0f33405126beee2739aa3cb77e
/library/init/meta/interactive_base.lean
8dbe3e2c0ba1db582dba1c18e573ba79c7b47c08
[ "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
9,034
lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ prelude import init.data.option.basic import init.meta.lean.parser init.meta.tactic init.meta.has_reflect open lean open lean.parser local postfix `?`:9001 := optional local postfix *:9001 := many namespace interactive /-- (parse p) as the parameter type of an interactive tactic will instruct the Lean parser to run `p` when parsing the parameter and to pass the parsed value as an argument to the tactic. -/ @[reducible] meta def parse {α : Type} (p : parser α) [lean.parser.reflectable p] : Type := α /-- A `loc` is either a 'wildcard', which means "everywhere", or a list of `option name`s. `none` means `target` and `some n` means `n` in the local context.-/ inductive loc : Type | wildcard : loc | ns : list (option name) → loc meta def loc.include_goal : loc → bool | loc.wildcard := tt | (loc.ns ls) := (ls.map option.is_none).bor meta def loc.get_locals : loc → tactic (list expr) | loc.wildcard := tactic.local_context | (loc.ns xs) := xs.mfoldl (λ ls n, match n with | none := pure ls | some n := do l ← tactic.get_local n, pure $ l :: ls end) [] meta def loc.apply (hyp_tac : expr → tactic unit) (goal_tac : tactic unit) (l : loc) : tactic unit := do hs ← l.get_locals, hs.mmap' hyp_tac, if l.include_goal then goal_tac else pure () meta def loc.try_apply (hyp_tac : expr → tactic unit) (goal_tac : tactic unit) (l : loc) : tactic unit := do hs ← l.get_locals, let hts := hs.map hyp_tac, tactic.try_lst $ if l.include_goal then hts ++ [goal_tac] else hts /-- Use `desc` as the interactive description of `p`. -/ meta def with_desc {α : Type} (desc : format) (p : parser α) : parser α := p meta instance with_desc.reflectable {α : Type} (p : parser α) [h : lean.parser.reflectable p] (f : format) : reflectable (with_desc f p) := h namespace types variables {α β : Type} -- optimized pretty printer meta def brackets (l r : string) (p : parser α) := tk l *> p <* tk r meta def list_of (p : parser α) := brackets "[" "]" $ sep_by (skip_info (tk ",")) p precedence `⊢` : 0 precedence `|-` : 0 /-- The right-binding power 2 will terminate expressions by '<|>' (rbp 2), ';' (rbp 1), and ',' (rbp 0). It should be used for any (potentially) trailing expression parameters. -/ meta def tac_rbp := 2 /-- A 'tactic expression', which uses right-binding power 2 so that it is terminated by '<|>' (rbp 2), ';' (rbp 1), and ',' (rbp 0). It should be used for any (potentially) trailing expression parameters. -/ meta def texpr := parser.pexpr tac_rbp /-- Parse an identifier or a '_' -/ meta def ident_ : parser name := ident <|> tk "_" *> return `_ meta def using_ident := (tk "using" *> ident)? meta def with_ident_list := (tk "with" *> ident_*) <|> return [] meta def without_ident_list := (tk "without" *> ident*) <|> return [] meta def location := (tk "at" *> (tk "*" *> return loc.wildcard <|> (loc.ns <$> (((with_desc "⊢" $ tk "⊢" <|> tk "|-") *> return none) <|> some <$> ident)*))) <|> return (loc.ns [none]) meta def pexpr_list := list_of (parser.pexpr 0) meta def opt_pexpr_list := pexpr_list <|> return [] meta def pexpr_list_or_texpr := pexpr_list <|> list.ret <$> texpr meta def only_flag : parser bool := (tk "only" *> return tt) <|> return ff end types precedence only:0 open expr format tactic types private meta def maybe_paren : list format → format | [] := "" | [f] := f | fs := paren (join fs) private meta def unfold (e : expr) : tactic expr := do (expr.const f_name f_lvls) ← return e.get_app_fn | failed, env ← get_env, decl ← env.get f_name, new_f ← decl.instantiate_value_univ_params f_lvls, head_beta (expr.mk_app new_f e.get_app_args) private meta def concat (f₁ f₂ : list format) := if f₁.empty then f₂ else if f₂.empty then f₁ else f₁ ++ [" "] ++ f₂ private meta def parser_desc_aux : expr → tactic (list format) | `(ident) := return ["id"] | `(ident_) := return ["id"] | `(parser.pexpr %%v) := return ["expr"] | `(small_nat) := return ["n"] | `(tk %%c) := list.ret <$> to_fmt <$> eval_expr string c | `(cur_pos) := return [] | `(pure ._) := return [] | `(._ <$> %%p) := parser_desc_aux p | `(skip_info %%p) := parser_desc_aux p | `(._ <$ %%p) := parser_desc_aux p | `(set_goal_info_pos %%p) := parser_desc_aux p | `(with_desc %%desc %%p) := list.ret <$> eval_expr format desc | `(%%p₁ <*> %%p₂) := do f₁ ← parser_desc_aux p₁, f₂ ← parser_desc_aux p₂, return $ concat f₁ f₂ | `(%%p₁ <* %%p₂) := do f₁ ← parser_desc_aux p₁, f₂ ← parser_desc_aux p₂, return $ concat f₁ f₂ | `(%%p₁ *> %%p₂) := do f₁ ← parser_desc_aux p₁, f₂ ← parser_desc_aux p₂, return $ concat f₁ f₂ | `(%%p₁ >> %%p₂) := do f₁ ← parser_desc_aux p₁, f₂ ← parser_desc_aux p₂, return $ concat f₁ f₂ | `(many %%p) := do f ← parser_desc_aux p, return [maybe_paren f ++ "*"] | `(optional %%p) := do f ← parser_desc_aux p, return [maybe_paren f ++ "?"] | `(sep_by %%sep %%p) := do f₁ ← parser_desc_aux sep, f₂ ← parser_desc_aux p, return [maybe_paren f₂ ++ join f₁, " ..."] | `(%%p₁ <|> %%p₂) := do f₁ ← parser_desc_aux p₁, f₂ ← parser_desc_aux p₂, return $ if f₁.empty then [maybe_paren f₂ ++ "?"] else if f₂.empty then [maybe_paren f₁ ++ "?"] else [paren $ join $ f₁ ++ [to_fmt " | "] ++ f₂] | `(brackets %%l %%r %%p) := do f ← parser_desc_aux p, l ← eval_expr string l, r ← eval_expr string r, -- much better than the naive [l, " ", f, " ", r] return [to_fmt l ++ join f ++ to_fmt r] | e := do e' ← (do e' ← unfold e, guard $ e' ≠ e, return e') <|> (do f ← pp e, fail $ to_fmt "don't know how to pretty print " ++ f), parser_desc_aux e' meta def param_desc : expr → tactic format | `(parse %%p) := join <$> parser_desc_aux p | `(opt_param %%t ._) := (++ "?") <$> pp t | e := if is_constant e ∧ (const_name e).components.ilast = `itactic then return $ to_fmt "{ tactic }" else paren <$> pp e private meta constant parse_binders_core (rbp : ℕ) : parser (list pexpr) meta def parse_binders (rbp := std.prec.max) := with_desc "<binders>" (parse_binders_core rbp) meta constant decl_attributes : Type meta constant decl_attributes.apply : decl_attributes → name → parser unit meta inductive noncomputable_modifier | computable | «noncomputable» | force_noncomputable meta structure decl_modifiers := (is_private : bool) (is_protected : bool) (is_meta : bool) (is_mutual : bool) (is_noncomputable : noncomputable_modifier) meta structure decl_meta_info := (attrs : decl_attributes) (modifiers : decl_modifiers) (doc_string : option string) meta structure single_inductive_decl := (attrs : decl_attributes) (sig : expr) (intros : list expr) meta def single_inductive_decl.name (d : single_inductive_decl) : name := d.sig.app_fn.const_name meta structure inductive_decl := (u_names : list name) (params : list expr) (decls : list single_inductive_decl) /-- Parses and elaborates a single or multiple mutual inductive declarations (without the `inductive` keyword), depending on `is_mutual` -/ meta constant inductive_decl.parse : decl_meta_info → parser inductive_decl end interactive section macros open interaction_monad open interactive private meta def parse_format : string → list char → parser pexpr | acc [] := pure ``(to_fmt %%(reflect acc)) | acc ('\n'::s) := do f ← parse_format "" s, pure ``(to_fmt %%(reflect acc) ++ format.line ++ %%f) | acc ('{'::'{'::s) := parse_format (acc ++ "{") s | acc ('{'::s) := do (e, s) ← with_input (lean.parser.pexpr 0) s.as_string, '}'::s ← return s.to_list | fail "'}' expected", f ← parse_format "" s, pure ``(to_fmt %%(reflect acc) ++ to_fmt %%e ++ %%f) | acc ('}'::'}'::s) := parse_format (acc ++ "}") s | acc ('}'::s) := fail "'}}' expected" | acc (c::s) := parse_format (acc.str c) s reserve prefix `format! `:100 @[user_notation] meta def format_macro (_ : parse $ tk "format!") (s : string) : parser pexpr := parse_format "" s.to_list private meta def parse_sformat : string → list char → parser pexpr | acc [] := pure $ pexpr.of_expr (reflect acc) | acc ('{'::'{'::s) := parse_sformat (acc ++ "{") s | acc ('{'::s) := do (e, s) ← with_input (lean.parser.pexpr 0) s.as_string, '}'::s ← return s.to_list | fail "'}' expected", f ← parse_sformat "" s, pure ``(%%(reflect acc) ++ to_string %%e ++ %%f) | acc ('}'::'}'::s) := parse_sformat (acc ++ "}") s | acc ('}'::s) := fail "'}}' expected" | acc (c::s) := parse_sformat (acc.str c) s reserve prefix `sformat! `:100 @[user_notation] meta def sformat_macro (_ : parse $ tk "sformat!") (s : string) : parser pexpr := parse_sformat "" s.to_list end macros
2095241a11da2a468e38bfa39ccbe0cfd4f156a0
1dd482be3f611941db7801003235dc84147ec60a
/src/linear_algebra/multivariate_polynomial.lean
e22e8a75737ebc58b0da4287f28ded01dc8c4611
[ "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
15,242
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro Multivariate Polynomial -/ import data.finsupp linear_algebra.basic algebra.ring open set function finsupp lattice universes u v w x variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x} /-- Multivariate polynomial, where `σ` is the index set of the variables and `α` is the coefficient ring -/ def mv_polynomial (σ : Type*) (α : Type*) [comm_semiring α] := (σ →₀ ℕ) →₀ α namespace mv_polynomial variables {σ : Type*} {a a' a₁ a₂ : α} {e : ℕ} {n m : σ} {s : σ →₀ ℕ} variables [decidable_eq σ] [decidable_eq α] section comm_semiring variables [comm_semiring α] {p q : mv_polynomial σ α} instance : decidable_eq (mv_polynomial σ α) := finsupp.decidable_eq instance : has_zero (mv_polynomial σ α) := finsupp.has_zero instance : has_one (mv_polynomial σ α) := finsupp.has_one instance : has_add (mv_polynomial σ α) := finsupp.has_add instance : has_mul (mv_polynomial σ α) := finsupp.has_mul instance : comm_semiring (mv_polynomial σ α) := finsupp.to_comm_semiring /-- `monomial s a` is the monomial `a * X^s` -/ def monomial (s : σ →₀ ℕ) (a : α) : mv_polynomial σ α := single s a /-- `C a` is the constant polynomial with value `a` -/ def C (a : α) : mv_polynomial σ α := monomial 0 a /-- `X n` is the polynomial with value X_n -/ def X (n : σ) : mv_polynomial σ α := monomial (single n 1) 1 @[simp] lemma C_0 : C 0 = (0 : mv_polynomial σ α) := by simp [C, monomial]; refl @[simp] lemma C_1 : C 1 = (1 : mv_polynomial σ α) := rfl lemma C_mul_monomial : C a * monomial s a' = monomial s (a * a') := by simp [C, monomial, single_mul_single] @[simp] lemma C_add : (C (a + a') : mv_polynomial σ α) = C a + C a' := single_add @[simp] lemma C_mul : (C (a * a') : mv_polynomial σ α) = C a * C a' := C_mul_monomial.symm instance : is_semiring_hom (C : α → mv_polynomial σ α) := { map_zero := C_0, map_one := C_1, map_add := λ a a', C_add, map_mul := λ a a', C_mul } lemma X_pow_eq_single : X n ^ e = monomial (single n e) (1 : α) := begin induction e, { simp [X], refl }, { simp [pow_succ, e_ih], simp [X, monomial, single_mul_single, nat.succ_eq_add_one] } end lemma monomial_add_single : monomial (s + single n e) a = (monomial s a * X n ^ e):= by rw [X_pow_eq_single, monomial, monomial, monomial, single_mul_single]; simp lemma monomial_single_add : monomial (single n e + s) a = (X n ^ e * monomial s a):= by rw [X_pow_eq_single, monomial, monomial, monomial, single_mul_single]; simp lemma monomial_eq : monomial s a = C a * (s.prod $ λn e, X n ^ e : mv_polynomial σ α) := begin apply @finsupp.induction σ ℕ _ _ _ _ s, { simp [C, prod_zero_index]; exact (mul_one _).symm }, { assume n e s hns he ih, simp [prod_add_index, prod_single_index, pow_zero, pow_add, (mul_assoc _ _ _).symm, ih.symm, monomial_add_single] } end @[recursor 7] lemma induction_on {M : mv_polynomial σ α → Prop} (p : mv_polynomial σ α) (h_C : ∀a, M (C a)) (h_add : ∀p q, M p → M q → M (p + q)) (h_X : ∀p n, M p → M (p * X n)) : M p := have ∀s a, M (monomial s a), begin assume s a, apply @finsupp.induction σ ℕ _ _ _ _ s, { show M (monomial 0 a), from h_C a, }, { assume n e p hpn he ih, have : ∀e:ℕ, M (monomial p a * X n ^ e), { intro e, induction e, { simp [ih] }, { simp [ih, pow_succ', (mul_assoc _ _ _).symm, h_X, e_ih] } }, simp [monomial_add_single, this] } end, finsupp.induction p (by have : M (C 0) := h_C 0; rwa [C_0] at this) (assume s a p hsp ha hp, h_add _ _ (this s a) hp) lemma hom_eq_hom [semiring γ] (f g : mv_polynomial σ α → γ) (hf : is_semiring_hom f) (hg : is_semiring_hom g) (hC : ∀a:α, f (C a) = g (C a)) (hX : ∀n:σ, f (X n) = g (X n)) (p : mv_polynomial σ α) : f p = g p := mv_polynomial.induction_on p hC begin assume p q hp hq, rw [is_semiring_hom.map_add f, is_semiring_hom.map_add g, hp, hq] end begin assume p n hp, rw [is_semiring_hom.map_mul f, is_semiring_hom.map_mul g, hp, hX] end lemma is_id (f : mv_polynomial σ α → mv_polynomial σ α) (hf : is_semiring_hom f) (hC : ∀a:α, f (C a) = (C a)) (hX : ∀n:σ, f (X n) = (X n)) (p : mv_polynomial σ α) : f p = p := hom_eq_hom f id hf is_semiring_hom.id hC hX p section eval₂ variables [comm_semiring β] variables (f : α → β) (g : σ → β) /-- Evaluate a polynomial `p` given a valuation `g` of all the variables and a ring hom `f` from the scalar ring to the target -/ def eval₂ (p : mv_polynomial σ α) : β := p.sum (λs a, f a * s.prod (λn e, g n ^ e)) @[simp] lemma eval₂_zero : (0 : mv_polynomial σ α).eval₂ f g = 0 := finsupp.sum_zero_index variables [is_semiring_hom f] @[simp] lemma eval₂_add : (p + q).eval₂ f g = p.eval₂ f g + q.eval₂ f g := finsupp.sum_add_index (by simp [is_semiring_hom.map_zero f]) (by simp [add_mul, is_semiring_hom.map_add f]) @[simp] lemma eval₂_monomial : (monomial s a).eval₂ f g = f a * s.prod (λn e, g n ^ e) := finsupp.sum_single_index (by simp [is_semiring_hom.map_zero f]) @[simp] lemma eval₂_C (a) : (C a).eval₂ f g = f a := by simp [eval₂_monomial, C, prod_zero_index] @[simp] lemma eval₂_one : (1 : mv_polynomial σ α).eval₂ f g = 1 := (eval₂_C _ _ _).trans (is_semiring_hom.map_one f) @[simp] lemma eval₂_X (n) : (X n).eval₂ f g = g n := by simp [eval₂_monomial, is_semiring_hom.map_one f, X, prod_single_index, pow_one] lemma eval₂_mul_monomial : ∀{s a}, (p * monomial s a).eval₂ f g = p.eval₂ f g * f a * s.prod (λn e, g n ^ e) := begin apply mv_polynomial.induction_on p, { assume a' s a, simp [C_mul_monomial, eval₂_monomial, is_semiring_hom.map_mul f] }, { assume p q ih_p ih_q, simp [add_mul, eval₂_add, ih_p, ih_q] }, { assume p n ih s a, from calc (p * X n * monomial s a).eval₂ f g = (p * monomial (single n 1 + s) a).eval₂ f g : by simp [monomial_single_add, -add_comm, pow_one, mul_assoc] ... = (p * monomial (single n 1) 1).eval₂ f g * f a * s.prod (λn e, g n ^ e) : by simp [ih, prod_single_index, prod_add_index, pow_one, pow_add, mul_assoc, mul_left_comm, is_semiring_hom.map_one f, -add_comm] } end lemma eval₂_mul : ∀{p}, (p * q).eval₂ f g = p.eval₂ f g * q.eval₂ f g := begin apply mv_polynomial.induction_on q, { simp [C, eval₂_monomial, eval₂_mul_monomial, prod_zero_index] }, { simp [mul_add, eval₂_add] {contextual := tt} }, { simp [X, eval₂_monomial, eval₂_mul_monomial, (mul_assoc _ _ _).symm] { contextual := tt} } end lemma eval₂_pow {p:mv_polynomial σ α} : ∀{n:ℕ}, (p ^ n).eval₂ f g = (p.eval₂ f g)^n | 0 := eval₂_one _ _ | (n + 1) := by rw [pow_add, pow_one, pow_add, pow_one, eval₂_mul, eval₂_pow] instance eval₂.is_semiring_hom : is_semiring_hom (eval₂ f g) := { map_zero := eval₂_zero _ _, map_one := eval₂_one _ _, map_add := λ p q, eval₂_add _ _, map_mul := λ p q, eval₂_mul _ _ } lemma eval₂_comp_left {γ} [comm_semiring γ] (k : β → γ) [is_semiring_hom k] (f : α → β) [is_semiring_hom f] (g : σ → β) (p) : k (eval₂ f g p) = eval₂ (k ∘ f) (k ∘ g) p := by apply mv_polynomial.induction_on p; simp [ eval₂_add, is_semiring_hom.map_add k, eval₂_mul, is_semiring_hom.map_mul k] {contextual := tt} lemma eval₂_eta (p : mv_polynomial σ α) : eval₂ C X p = p := by apply mv_polynomial.induction_on p; simp [eval₂_add, eval₂_mul] {contextual := tt} end eval₂ section eval variables {f : σ → α} /-- Evaluate a polynomial `p` given a valuation `f` of all the variables -/ def eval (f : σ → α) : mv_polynomial σ α → α := eval₂ id f @[simp] lemma eval_zero : (0 : mv_polynomial σ α).eval f = 0 := eval₂_zero _ _ @[simp] lemma eval_add : (p + q).eval f = p.eval f + q.eval f := eval₂_add _ _ lemma eval_monomial : (monomial s a).eval f = a * s.prod (λn e, f n ^ e) := eval₂_monomial _ _ @[simp] lemma eval_C : ∀ a, (C a).eval f = a := eval₂_C _ _ @[simp] lemma eval_X : ∀ n, (X n).eval f = f n := eval₂_X _ _ @[simp] lemma eval_mul : (p * q).eval f = p.eval f * q.eval f := eval₂_mul _ _ instance eval.is_semiring_hom : is_semiring_hom (eval f) := eval₂.is_semiring_hom _ _ theorem eval_assoc {τ} [decidable_eq τ] (f : σ → mv_polynomial τ α) (g : τ → α) (p : mv_polynomial σ α) : p.eval (eval g ∘ f) = (eval₂ C f p).eval g := begin rw eval₂_comp_left (eval g), unfold eval, congr; funext a; simp end end eval section map variables [comm_semiring β] [decidable_eq β] variables (f : α → β) [is_semiring_hom f] /-- `map f p` maps a polynomial `p` across a ring hom `f` -/ def map : mv_polynomial σ α → mv_polynomial σ β := eval₂ (C ∘ f) X @[simp] theorem map_monomial (s : σ →₀ ℕ) (a : α) : map f (monomial s a) = monomial s (f a) := (eval₂_monomial _ _).trans monomial_eq.symm @[simp] theorem map_C : ∀ (a : α), map f (C a : mv_polynomial σ α) = C (f a) := map_monomial _ _ @[simp] theorem map_X : ∀ (n : σ), map f (X n : mv_polynomial σ α) = X n := eval₂_X _ _ @[simp] theorem map_one : map f (1 : mv_polynomial σ α) = 1 := eval₂_one _ _ @[simp] theorem map_add (p q : mv_polynomial σ α) : map f (p + q) = map f p + map f q := eval₂_add _ _ @[simp] theorem map_mul (p q : mv_polynomial σ α) : map f (p * q) = map f p * map f q := eval₂_mul _ _ instance map.is_semiring_hom : is_semiring_hom (map f : mv_polynomial σ α → mv_polynomial σ β) := eval₂.is_semiring_hom _ _ theorem map_id : ∀ (p : mv_polynomial σ α), map id p = p := eval₂_eta theorem map_map [comm_semiring γ] [decidable_eq γ] (g : β → γ) [is_semiring_hom g] (p : mv_polynomial σ α) : map g (map f p) = map (g ∘ f) p := (eval₂_comp_left (map g) (C ∘ f) X p).trans $ by congr; funext a; simp theorem eval₂_eq_eval_map (g : σ → β) (p : mv_polynomial σ α) : p.eval₂ f g = (map f p).eval g := begin unfold map eval, rw eval₂_comp_left (eval₂ id g), congr; funext a; simp end end map section vars /-- `vars p` is the set of variables appearing in the polynomial `p` -/ def vars (p : mv_polynomial σ α) : finset σ := p.support.bind finsupp.support @[simp] lemma vars_0 : (0 : mv_polynomial σ α).vars = ∅ := show (0 : (σ →₀ ℕ) →₀ α).support.bind finsupp.support = ∅, by simp @[simp] lemma vars_monomial (h : a ≠ 0) : (monomial s a).vars = s.support := show (single s a : (σ →₀ ℕ) →₀ α).support.bind finsupp.support = s.support, by simp [support_single_ne_zero, h] @[simp] lemma vars_C : (C a : mv_polynomial σ α).vars = ∅ := decidable.by_cases (assume h : a = 0, by simp [h]) (assume h : a ≠ 0, by simp [C, h]) @[simp] lemma vars_X (h : 0 ≠ (1 : α)) : (X n : mv_polynomial σ α).vars = {n} := calc (X n : mv_polynomial σ α).vars = (single n 1).support : vars_monomial h.symm ... = {n} : by rw [support_single_ne_zero nat.zero_ne_one.symm] end vars section degree_of /-- `degree_of n p` gives the highest power of X_n that appears in `p` -/ def degree_of (n : σ) (p : mv_polynomial σ α) : ℕ := p.support.sup (λs, s n) end degree_of section total_degree /-- `total_degree p` gives the maximum |s| over the monomials X^s in `p` -/ def total_degree (p : mv_polynomial σ α) : ℕ := p.support.sup (λs, s.sum $ λn e, e) end total_degree end comm_semiring section comm_ring variable [comm_ring α] variables {p q : mv_polynomial σ α} instance : ring (mv_polynomial σ α) := finsupp.to_ring instance : comm_ring (mv_polynomial σ α) := finsupp.to_comm_ring instance : has_scalar α (mv_polynomial σ α) := finsupp.to_has_scalar instance : module α (mv_polynomial σ α) := finsupp.to_module _ α instance C.is_ring_hom : is_ring_hom (C : α → mv_polynomial σ α) := by apply is_ring_hom.of_semiring variables (σ a a') lemma C_sub : (C (a - a') : mv_polynomial σ α) = C a - C a' := is_ring_hom.map_sub _ @[simp] lemma C_neg : (C (-a) : mv_polynomial σ α) = -C a := is_ring_hom.map_neg _ variables {σ} (p) theorem C_mul' : mv_polynomial.C a * p = a • p := begin apply finsupp.induction p, { exact (mul_zero $ mv_polynomial.C a).trans (@smul_zero α (mv_polynomial σ α) _ _ _ a).symm }, intros p b f haf hb0 ih, rw [mul_add, ih, @smul_add α (mv_polynomial σ α) _ _ _ a], congr' 1, rw [finsupp.mul_def, finsupp.smul_single, mv_polynomial.C, mv_polynomial.monomial], rw [finsupp.sum_single_index, finsupp.sum_single_index, zero_add, smul_eq_mul], { rw [mul_zero, finsupp.single_zero] }, { rw finsupp.sum_single_index, all_goals { rw [zero_mul, finsupp.single_zero] } } end section eval₂ variables [decidable_eq β] [comm_ring β] variables (f : α → β) [is_ring_hom f] (g : σ → β) instance eval₂.is_ring_hom : is_ring_hom (eval₂ f g) := by apply is_ring_hom.of_semiring lemma eval₂_sub : (p - q).eval₂ f g = p.eval₂ f g - q.eval₂ f g := is_ring_hom.map_sub _ @[simp] lemma eval₂_neg : (-p).eval₂ f g = -(p.eval₂ f g) := is_ring_hom.map_neg _ end eval₂ section eval variables (f : σ → α) instance eval.is_ring_hom : is_ring_hom (eval f) := eval₂.is_ring_hom _ _ lemma eval_sub : (p - q).eval f = p.eval f - q.eval f := is_ring_hom.map_sub _ @[simp] lemma eval_neg : (-p).eval f = -(p.eval f) := is_ring_hom.map_neg _ end eval section map variables [decidable_eq β] [comm_ring β] variables (f : α → β) [is_ring_hom f] instance map.is_ring_hom : is_ring_hom (map f : mv_polynomial σ α → mv_polynomial σ β) := eval₂.is_ring_hom _ _ lemma map_sub : (p - q).map f = p.map f - q.map f := is_ring_hom.map_sub _ @[simp] lemma map_neg : (-p).map f = -(p.map f) := is_ring_hom.map_neg _ end map end comm_ring section rename variables {α} [comm_semiring α] [decidable_eq α] [decidable_eq β] [decidable_eq γ] [decidable_eq δ] def rename (f : β → γ) : mv_polynomial β α → mv_polynomial γ α := eval₂ C (X ∘ f) instance rename.is_semiring_hom (f : β → γ) : is_semiring_hom (rename f : mv_polynomial β α → mv_polynomial γ α) := by unfold rename; apply_instance @[simp] lemma rename_C (f : β → γ) (a : α) : rename f (C a) = C a := eval₂_C _ _ _ @[simp] lemma rename_X (f : β → γ) (b : β) : rename f (X b : mv_polynomial β α) = X (f b) := eval₂_X _ _ _ lemma rename_rename (f : β → γ) (g : γ → δ) (p : mv_polynomial β α) : rename g (rename f p) = rename (g ∘ f) p := show rename g (eval₂ C (X ∘ f) p) = _, by simp only [eval₂_comp_left (rename g) C (X ∘ f) p, (∘), rename_C, rename_X]; refl lemma rename_id (p : mv_polynomial β α) : rename id p = p := eval₂_eta p end rename instance rename.is_ring_hom {α} [comm_ring α] [decidable_eq α] [decidable_eq β] [decidable_eq γ] (f : β → γ) : is_ring_hom (rename f : mv_polynomial β α → mv_polynomial γ α) := @is_ring_hom.of_semiring (mv_polynomial β α) (mv_polynomial γ α) _ _ (rename f) (rename.is_semiring_hom f) end mv_polynomial
6951fa853b5d01534248ac888956edf9f76bdb08
32025d5c2d6e33ad3b6dd8a3c91e1e838066a7f7
/tests/lean/run/subst1.lean
6fada4e88ec7472bc9dc88cab632de8ac00bf07f
[ "Apache-2.0" ]
permissive
walterhu1015/lean4
b2c71b688975177402758924eaa513475ed6ce72
2214d81e84646a905d0b20b032c89caf89c737ad
refs/heads/master
1,671,342,096,906
1,599,695,985,000
1,599,695,985,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
660
lean
new_frontend set_option trace.Meta.Tactic.subst true theorem tst1 (x y z : Nat) : y = z → x = x → x = y → x = z := by { intros h1 h2 h3; subst x; assumption } theorem tst2 (x y z : Nat) : y = z → x = z + y → x = z + z := by { intros h1 h2; subst h1; subst h2; exact rfl } def BV (n : Nat) : Type := Unit theorem tst3 (n m : Nat) (v : BV n) (w : BV m) (h1 : n = m) (h2 : forall (v1 v2 : BV n), v1 = v2) : v = cast (congrArg BV h1) w := by { subst h1; apply h2 } theorem tst4 (n m : Nat) (v : BV n) (w : BV m) (h1 : n = m) (h2 : forall (v1 v2 : BV n), v1 = v2) : v = cast (congrArg BV h1.symm) w := by { subst n; apply h2 }
4b1cf470d11277b76a16e254efb94ba760fb9372
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/order/upper_lower/locally_finite.lean
87855c6b90aa02f25756e9b7f8cf14688540c232
[ "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
953
lean
/- Copyright (c) 2023 Yaël Dillies, Sara Rousta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import order.locally_finite import order.upper_lower.basic /-! # Upper and lower sets in a locally finite order > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. In this file we characterise the interaction of `upper_set`/`lower_set` and `locally_finite_order`. -/ namespace set variables {α : Type*} [preorder α] {s : set α} protected lemma finite.upper_closure [locally_finite_order_top α] (hs : s.finite) : (upper_closure s : set α).finite := by { rw coe_upper_closure, exact hs.bUnion (λ _ _, finite_Ici _) } protected lemma finite.lower_closure [locally_finite_order_bot α] (hs : s.finite) : (lower_closure s : set α).finite := by { rw coe_lower_closure, exact hs.bUnion (λ _ _, finite_Iic _) } end set
35dd8c01743817607829c809023b7af66f19d793
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
/stage0/src/Lean/Elab/PreDefinition/WF/Main.lean
36de5cca13c0ff42e39d3d6fb261c51063d6b533
[ "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
5,520
lean
/- Copyright (c) 2021 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Elab.PreDefinition.Basic import Lean.Elab.PreDefinition.WF.TerminationHint import Lean.Elab.PreDefinition.WF.PackDomain import Lean.Elab.PreDefinition.WF.PackMutual import Lean.Elab.PreDefinition.WF.Rel import Lean.Elab.PreDefinition.WF.Fix import Lean.Elab.PreDefinition.WF.Eqns import Lean.Elab.PreDefinition.WF.Ite namespace Lean.Elab open WF open Meta private def isOnlyOneUnaryDef (preDefs : Array PreDefinition) (fixedPrefixSize : Nat) : MetaM Bool := do if preDefs.size == 1 then lambdaTelescope preDefs[0]!.value fun xs _ => return xs.size == fixedPrefixSize + 1 else return false private partial def addNonRecPreDefs (preDefs : Array PreDefinition) (preDefNonRec : PreDefinition) (fixedPrefixSize : Nat) : TermElabM Unit := do if (← isOnlyOneUnaryDef preDefs fixedPrefixSize) then return () let us := preDefNonRec.levelParams.map mkLevelParam let all := preDefs.toList.map (·.declName) for fidx in [:preDefs.size] do let preDef := preDefs[fidx]! let value ← lambdaTelescope preDef.value fun xs _ => do let packedArgs : Array Expr := xs[fixedPrefixSize:] let mkProd (type : Expr) : MetaM Expr := do mkUnaryArg type packedArgs let rec mkSum (i : Nat) (type : Expr) : MetaM Expr := do if i == preDefs.size - 1 then mkProd type else (← whnfD type).withApp fun f args => do assert! args.size == 2 if i == fidx then return mkApp3 (mkConst ``PSum.inl f.constLevels!) args[0]! args[1]! (← mkProd args[0]!) else let r ← mkSum (i+1) args[1]! return mkApp3 (mkConst ``PSum.inr f.constLevels!) args[0]! args[1]! r let Expr.forallE _ domain _ _ := (← instantiateForall preDefNonRec.type xs[:fixedPrefixSize]) | unreachable! let arg ← mkSum 0 domain mkLambdaFVars xs (mkApp (mkAppN (mkConst preDefNonRec.declName us) xs[:fixedPrefixSize]) arg) trace[Elab.definition.wf] "{preDef.declName} := {value}" addNonRec { preDef with value } (applyAttrAfterCompilation := false) (all := all) partial def withCommonTelescope (preDefs : Array PreDefinition) (k : Array Expr → Array Expr → TermElabM α) : TermElabM α := go #[] (preDefs.map (·.value)) where go (fvars : Array Expr) (vals : Array Expr) : TermElabM α := do if !(vals.all fun val => val.isLambda) then k fvars vals else if !(← vals.allM fun val => return val.bindingName! == vals[0]!.bindingName! && val.binderInfo == vals[0]!.binderInfo && (← isDefEq val.bindingDomain! vals[0]!.bindingDomain!)) then k fvars vals else withLocalDecl vals[0]!.bindingName! vals[0]!.binderInfo vals[0]!.bindingDomain! fun x => go (fvars.push x) (vals.map fun val => val.bindingBody!.instantiate1 x) def getFixedPrefix (preDefs : Array PreDefinition) : TermElabM Nat := withCommonTelescope preDefs fun xs vals => do let resultRef ← IO.mkRef xs.size for val in vals do if (← resultRef.get) == 0 then return 0 forEachExpr' val fun e => do if preDefs.any fun preDef => e.isAppOf preDef.declName then let args := e.getAppArgs resultRef.modify (min args.size ·) for arg in args, x in xs do if !(← withoutProofIrrelevance <| withReducible <| isDefEq arg x) then -- We continue searching if e's arguments are not a prefix of `xs` return true return false else return true resultRef.get def wfRecursion (preDefs : Array PreDefinition) (wf? : Option TerminationWF) (decrTactic? : Option Syntax) : TermElabM Unit := do let (unaryPreDef, fixedPrefixSize) ← withoutModifyingEnv do for preDef in preDefs do addAsAxiom preDef let fixedPrefixSize ← getFixedPrefix preDefs trace[Elab.definition.wf] "fixed prefix: {fixedPrefixSize}" let preDefsDIte ← preDefs.mapM fun preDef => return { preDef with value := (← iteToDIte preDef.value) } let unaryPreDefs ← packDomain fixedPrefixSize preDefsDIte return (← packMutual fixedPrefixSize preDefs unaryPreDefs, fixedPrefixSize) let preDefNonRec ← forallBoundedTelescope unaryPreDef.type fixedPrefixSize fun prefixArgs type => do let packedArgType := type.bindingDomain! elabWFRel preDefs unaryPreDef.declName fixedPrefixSize packedArgType wf? fun wfRel => do trace[Elab.definition.wf] "wfRel: {wfRel}" let (value, envNew) ← withoutModifyingEnv' do addAsAxiom unaryPreDef let value ← mkFix unaryPreDef prefixArgs wfRel decrTactic? eraseRecAppSyntaxExpr value /- `mkFix` invokes `decreasing_tactic` which may add auxiliary theorems to the environment. -/ let value ← unfoldDeclsFrom envNew value return { unaryPreDef with value } trace[Elab.definition.wf] ">> {preDefNonRec.declName} :=\n{preDefNonRec.value}" let preDefs ← preDefs.mapM fun d => eraseRecAppSyntax d addNonRec preDefNonRec (applyAttrAfterCompilation := false) addNonRecPreDefs preDefs preDefNonRec fixedPrefixSize registerEqnsInfo preDefs preDefNonRec.declName fixedPrefixSize for preDef in preDefs do applyAttributesOf #[preDef] AttributeApplicationTime.afterCompilation addAndCompilePartialRec preDefs builtin_initialize registerTraceClass `Elab.definition.wf end Lean.Elab
0f0f1f602d7edbf7da1f26135639e5e24400fa97
4efff1f47634ff19e2f786deadd394270a59ecd2
/src/measure_theory/outer_measure.lean
5e9dc29e9d0071bac42da4911b5b83fed8b90717
[ "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
35,355
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import analysis.specific_limits import measure_theory.measurable_space import topology.algebra.infinite_sum /-! # Outer Measures An outer measure is a function `μ : set α → ennreal`, from the powerset of a type to the extended nonnegative real numbers that satisfies the following conditions: 1. `μ ∅ = 0`; 2. `μ` is monotone; 3. `μ` is countably subadditive. This means that the outer measure of a countable union is at most the sum of the outer measure on the individual sets. Note that we do not need `α` to be measurable to define an outer measure. The outer measures on a type `α` form a complete lattice. Given an arbitrary function `m : set α → ennreal` that sends `∅` to `0` we can define an outer measure on `α` that on `s` is defined to be the infimum of `∑ᵢ, m (sᵢ)` for all collections of sets `sᵢ` that cover `s`. This is the unique maximal outer measure that is at most the given function. We also define this for functions `m` defined on a subset of `set α`, by treating the function as having value `∞` outside its domain. Given an outer measure `m`, the Carathéodory-measurable sets are the sets `s` such that for all sets `t` we have `m t = m (t ∩ s) + m (t \ s)`. This forms a measurable space. ## Main definitions and statements * `outer_measure.of_function` is the greatest outer measure that is at most the given function. * `caratheodory` is the Carathéodory-measurable space of an outer measure. * `Inf_eq_of_function_Inf_gen` is a characterization of the infimum of outer measures. * `induced_outer_measure` is the measure induced by a function on a subset of `set α` ## References * <https://en.wikipedia.org/wiki/Outer_measure> * <https://en.wikipedia.org/wiki/Carath%C3%A9odory%27s_criterion> ## Tags outer measure, Carathéodory-measurable, Carathéodory's criterion -/ noncomputable theory open set finset function filter encodable open_locale classical big_operators namespace measure_theory /-- An outer measure is a countably subadditive monotone function that sends `∅` to `0`. -/ structure outer_measure (α : Type*) := (measure_of : set α → ennreal) (empty : measure_of ∅ = 0) (mono : ∀{s₁ s₂}, s₁ ⊆ s₂ → measure_of s₁ ≤ measure_of s₂) (Union_nat : ∀(s:ℕ → set α), measure_of (⋃i, s i) ≤ (∑'i, measure_of (s i))) namespace outer_measure section basic variables {α : Type*} {β : Type*} {ms : set (outer_measure α)} {m : outer_measure α} instance : has_coe_to_fun (outer_measure α) := ⟨_, λ m, m.measure_of⟩ @[simp] lemma measure_of_eq_coe (m : outer_measure α) : m.measure_of = m := rfl @[simp] theorem empty' (m : outer_measure α) : m ∅ = 0 := m.empty theorem mono' (m : outer_measure α) {s₁ s₂} (h : s₁ ⊆ s₂) : m s₁ ≤ m s₂ := m.mono h protected theorem Union (m : outer_measure α) {β} [encodable β] (s : β → set α) : m (⋃i, s i) ≤ (∑'i, m (s i)) := rel_supr_tsum m m.empty (≤) m.Union_nat s lemma Union_null (m : outer_measure α) {β} [encodable β] {s : β → set α} (h : ∀ i, m (s i) = 0) : m (⋃i, s i) = 0 := by simpa [h] using m.Union s protected lemma Union_finset (m : outer_measure α) (s : β → set α) (t : finset β) : m (⋃i ∈ t, s i) ≤ ∑ i in t, m (s i) := rel_supr_sum m m.empty (≤) m.Union_nat s t protected lemma union (m : outer_measure α) (s₁ s₂ : set α) : m (s₁ ∪ s₂) ≤ m s₁ + m s₂ := rel_sup_add m m.empty (≤) m.Union_nat s₁ s₂ lemma le_inter_add_diff {m : outer_measure α} {t : set α} (s : set α) : m t ≤ m (t ∩ s) + m (t \ s) := by { convert m.union _ _, rw inter_union_diff t s } lemma diff_null (m : outer_measure α) (s : set α) {t : set α} (ht : m t = 0) : m (s \ t) = m s := begin refine le_antisymm (m.mono $ diff_subset _ _) _, calc m s ≤ m (s ∩ t) + m (s \ t) : le_inter_add_diff _ ... ≤ m t + m (s \ t) : add_le_add_right (m.mono $ inter_subset_right _ _) _ ... = m (s \ t) : by rw [ht, zero_add] end lemma union_null (m : outer_measure α) {s₁ s₂ : set α} (h₁ : m s₁ = 0) (h₂ : m s₂ = 0) : m (s₁ ∪ s₂) = 0 := by simpa [h₁, h₂] using m.union s₁ s₂ lemma coe_fn_injective ⦃μ₁ μ₂ : outer_measure α⦄ (h : ⇑μ₁ = μ₂) : μ₁ = μ₂ := by { cases μ₁, cases μ₂, congr, exact h } @[ext] lemma ext {μ₁ μ₂ : outer_measure α} (h : ∀ s, μ₁ s = μ₂ s) : μ₁ = μ₂ := coe_fn_injective $ funext h instance : has_zero (outer_measure α) := ⟨{ measure_of := λ_, 0, empty := rfl, mono := assume _ _ _, le_refl 0, Union_nat := assume s, zero_le _ }⟩ @[simp] theorem coe_zero : ⇑(0 : outer_measure α) = 0 := rfl instance : inhabited (outer_measure α) := ⟨0⟩ instance : has_add (outer_measure α) := ⟨λm₁ m₂, { measure_of := λs, m₁ s + m₂ s, empty := show m₁ ∅ + m₂ ∅ = 0, by simp [outer_measure.empty], mono := assume s₁ s₂ h, add_le_add (m₁.mono h) (m₂.mono h), Union_nat := assume s, calc m₁ (⋃i, s i) + m₂ (⋃i, s i) ≤ (∑'i, m₁ (s i)) + (∑'i, m₂ (s i)) : add_le_add (m₁.Union_nat s) (m₂.Union_nat s) ... = _ : ennreal.tsum_add.symm}⟩ @[simp] theorem coe_add (m₁ m₂ : outer_measure α) : ⇑(m₁ + m₂) = m₁ + m₂ := rfl theorem add_apply (m₁ m₂ : outer_measure α) (s : set α) : (m₁ + m₂) s = m₁ s + m₂ s := rfl instance add_comm_monoid : add_comm_monoid (outer_measure α) := { zero := 0, add := (+), .. injective.add_comm_monoid (show outer_measure α → set α → ennreal, from coe_fn) coe_fn_injective rfl (λ _ _, rfl) } instance : has_scalar ennreal (outer_measure α) := ⟨λ c m, { measure_of := λ s, c * m s, empty := by simp, mono := λ s t h, ennreal.mul_left_mono $ m.mono h, Union_nat := λ s, by { rw [ennreal.tsum_mul_left], exact ennreal.mul_left_mono (m.Union _) } }⟩ @[simp] lemma coe_smul (c : ennreal) (m : outer_measure α) : ⇑(c • m) = c • m := rfl lemma smul_apply (c : ennreal) (m : outer_measure α) (s : set α) : (c • m) s = c * m s := rfl instance : semimodule ennreal (outer_measure α) := { smul := (•), .. injective.semimodule ennreal ⟨show outer_measure α → set α → ennreal, from coe_fn, coe_zero, coe_add⟩ coe_fn_injective coe_smul } instance : has_bot (outer_measure α) := ⟨0⟩ instance outer_measure.order_bot : order_bot (outer_measure α) := { le := λm₁ m₂, ∀s, m₁ s ≤ m₂ s, bot := 0, le_refl := assume a s, le_refl _, le_trans := assume a b c hab hbc s, le_trans (hab s) (hbc s), le_antisymm := assume a b hab hba, ext $ assume s, le_antisymm (hab s) (hba s), bot_le := assume a s, zero_le _ } section supremum instance : has_Sup (outer_measure α) := ⟨λms, { measure_of := λs, ⨆ m ∈ ms, (m : outer_measure α) s, empty := le_zero_iff_eq.1 $ bsupr_le $ λ m h, le_of_eq m.empty, mono := assume s₁ s₂ hs, bsupr_le_bsupr $ assume m hm, m.mono hs, Union_nat := assume f, bsupr_le $ assume m hm, calc m (⋃i, f i) ≤ (∑' (i : ℕ), m (f i)) : m.Union_nat _ ... ≤ (∑'i, ⨆ m ∈ ms, (m : outer_measure α) (f i)) : ennreal.tsum_le_tsum $ assume i, le_bsupr m hm }⟩ instance : complete_lattice (outer_measure α) := { .. outer_measure.order_bot, .. complete_lattice_of_Sup (outer_measure α) (λ ms, ⟨λ m hm s, le_bsupr m hm, λ m hm s, bsupr_le (λ m' hm', hm hm' s)⟩) } @[simp] theorem Sup_apply (ms : set (outer_measure α)) (s : set α) : (Sup ms) s = ⨆ m ∈ ms, (m : outer_measure α) s := rfl @[simp] theorem supr_apply {ι} (f : ι → outer_measure α) (s : set α) : (⨆ i : ι, f i) s = ⨆ i, f i s := by rw [supr, Sup_apply, supr_range, supr] @[norm_cast] theorem coe_supr {ι} (f : ι → outer_measure α) : ⇑(⨆ i, f i) = ⨆ i, f i := funext $ λ s, by rw [supr_apply, _root_.supr_apply] @[simp] theorem sup_apply (m₁ m₂ : outer_measure α) (s : set α) : (m₁ ⊔ m₂) s = m₁ s ⊔ m₂ s := by have := supr_apply (λ b, cond b m₁ m₂) s; rwa [supr_bool_eq, supr_bool_eq] at this end supremum /-- The pushforward of `m` along `f`. The outer measure on `s` is defined to be `m (f ⁻¹' s)`. -/ def map {β} (f : α → β) : outer_measure α →ₗ[ennreal] outer_measure β := { to_fun := λ m, { measure_of := λs, m (f ⁻¹' s), empty := m.empty, mono := λ s t h, m.mono (preimage_mono h), Union_nat := λ s, by rw [preimage_Union]; exact m.Union_nat (λ i, f ⁻¹' s i) }, map_add' := λ m₁ m₂, coe_fn_injective rfl, map_smul' := λ c m, coe_fn_injective rfl } @[simp] theorem map_apply {β} (f : α → β) (m : outer_measure α) (s : set β) : map f m s = m (f ⁻¹' s) := rfl @[simp] theorem map_id (m : outer_measure α) : map id m = m := ext $ λ s, rfl @[simp] theorem map_map {β γ} (f : α → β) (g : β → γ) (m : outer_measure α) : map g (map f m) = map (g ∘ f) m := ext $ λ s, rfl instance : functor outer_measure := {map := λ α β f, map f} instance : is_lawful_functor outer_measure := { id_map := λ α, map_id, comp_map := λ α β γ f g m, (map_map f g m).symm } /-- The dirac outer measure. -/ def dirac (a : α) : outer_measure α := { measure_of := λs, ⨆ h : a ∈ s, 1, empty := by simp, mono := λ s t h, supr_le_supr2 (λ h', ⟨h h', le_refl _⟩), Union_nat := λ s, supr_le $ λ h, let ⟨i, h⟩ := mem_Union.1 h in le_trans (by exact le_supr _ h) (ennreal.le_tsum i) } @[simp] theorem dirac_apply (a : α) (s : set α) : dirac a s = ⨆ h : a ∈ s, 1 := rfl /-- The sum of an (arbitrary) collection of outer measures. -/ def sum {ι} (f : ι → outer_measure α) : outer_measure α := { measure_of := λs, ∑' i, f i s, empty := by simp, mono := λ s t h, ennreal.tsum_le_tsum (λ i, (f i).mono' h), Union_nat := λ s, by rw ennreal.tsum_comm; exact ennreal.tsum_le_tsum (λ i, (f i).Union_nat _) } @[simp] theorem sum_apply {ι} (f : ι → outer_measure α) (s : set α) : sum f s = ∑' i, f i s := rfl theorem smul_dirac_apply (a : ennreal) (b : α) (s : set α) : (a • dirac b) s = ⨆ h : b ∈ s, a := by by_cases b ∈ s; simp [h] /-- Pullback of an `outer_measure`: `comap f μ s = μ (f '' s)`. -/ def comap {β} (f : α → β) : outer_measure β →ₗ[ennreal] outer_measure α := { to_fun := λ m, { measure_of := λ s, m (f '' s), empty := by simp, mono := λ s t h, m.mono $ image_subset f h, Union_nat := λ s, by { rw [image_Union], apply m.Union_nat } }, map_add' := λ m₁ m₂, rfl, map_smul' := λ c m, rfl } @[simp] lemma comap_apply {β} (f : α → β) (m : outer_measure β) (s : set α) : comap f m s = m (f '' s) := rfl /-- Restrict an `outer_measure` to a set. -/ def restrict (s : set α) : outer_measure α →ₗ[ennreal] outer_measure α := (map coe).comp (comap (coe : s → α)) @[simp] lemma restrict_apply (s t : set α) (m : outer_measure α) : restrict s m t = m (t ∩ s) := by simp [restrict] theorem top_apply {s : set α} (h : s.nonempty) : (⊤ : outer_measure α) s = ⊤ := let ⟨a, as⟩ := h in top_unique $ le_trans (by simp [smul_dirac_apply, as]) (le_bsupr ((⊤ : ennreal) • dirac a) trivial) end basic section of_function set_option eqn_compiler.zeta true variables {α : Type*} (m : set α → ennreal) (m_empty : m ∅ = 0) include m_empty /-- Given any function `m` assigning measures to sets satisying `m ∅ = 0`, there is a unique maximal outer measure `μ` satisfying `μ s ≤ m s` for all `s : set α`. -/ protected def of_function : outer_measure α := let μ := λs, ⨅{f : ℕ → set α} (h : s ⊆ ⋃i, f i), ∑'i, m (f i) in { measure_of := μ, empty := le_antisymm (infi_le_of_le (λ_, ∅) $ infi_le_of_le (empty_subset _) $ by simp [m_empty]) (zero_le _), mono := assume s₁ s₂ hs, infi_le_infi $ assume f, infi_le_infi2 $ assume hb, ⟨subset.trans hs hb, le_refl _⟩, Union_nat := assume s, ennreal.le_of_forall_epsilon_le $ begin assume ε hε (hb : (∑'i, μ (s i)) < ⊤), rcases ennreal.exists_pos_sum_of_encodable (ennreal.coe_lt_coe.2 hε) ℕ with ⟨ε', hε', hl⟩, refine le_trans _ (add_le_add_left (le_of_lt hl) _), rw ← ennreal.tsum_add, choose f hf using show ∀i, ∃f:ℕ → set α, s i ⊆ (⋃i, f i) ∧ (∑'i, m (f i)) < μ (s i) + ε' i, { intro, have : μ (s i) < μ (s i) + ε' i := ennreal.lt_add_right (lt_of_le_of_lt (by apply ennreal.le_tsum) hb) (by simpa using hε' i), simpa [μ, infi_lt_iff] }, refine le_trans _ (ennreal.tsum_le_tsum $ λ i, le_of_lt (hf i).2), rw [← ennreal.tsum_prod, ← equiv.nat_prod_nat_equiv_nat.symm.tsum_eq], swap, {apply_instance}, refine infi_le_of_le _ (infi_le _ _), exact Union_subset (λ i, subset.trans (hf i).1 $ Union_subset $ λ j, subset.trans (by simp) $ subset_Union _ $ equiv.nat_prod_nat_equiv_nat (i, j)), end } variables {m m_empty} theorem of_function_le (s : set α) : outer_measure.of_function m m_empty s ≤ m s := let f : ℕ → set α := λi, nat.rec_on i s (λn s, ∅) in infi_le_of_le f $ infi_le_of_le (subset_Union f 0) $ le_of_eq $ calc (∑'i, m (f i)) = ∑ i in {0}, m (f i) : tsum_eq_sum $ by intro i; cases i; simp [m_empty] ... = m s : by simp; refl theorem of_function_eq (s : set α) (m_mono : ∀ ⦃t : set α⦄, s ⊆ t → m s ≤ m t) (m_subadd : ∀ (s : ℕ → set α), m (⋃i, s i) ≤ (∑'i, m (s i))) : outer_measure.of_function m m_empty s = m s := le_antisymm (of_function_le s) $ le_infi $ λ f, le_infi $ λ hf, le_trans (m_mono hf) (m_subadd f) theorem le_of_function {μ : outer_measure α} : μ ≤ outer_measure.of_function m m_empty ↔ ∀ s, μ s ≤ m s := ⟨λ H s, le_trans (H s) (of_function_le s), λ H s, le_infi $ λ f, le_infi $ λ hs, le_trans (μ.mono hs) $ le_trans (μ.Union f) $ ennreal.tsum_le_tsum $ λ i, H _⟩ end of_function section caratheodory_measurable universe u parameters {α : Type u} (m : outer_measure α) include m local attribute [simp] set.inter_comm set.inter_left_comm set.inter_assoc variables {s s₁ s₂ : set α} /-- A set `s` is Carathéodory-measurable for an outer measure `m` if for all sets `t` we have `m t = m (t ∩ s) + m (t \ s)`. -/ def is_caratheodory (s : set α) : Prop := ∀t, m t = m (t ∩ s) + m (t \ s) lemma is_caratheodory_iff_le' {s : set α} : is_caratheodory s ↔ ∀t, m (t ∩ s) + m (t \ s) ≤ m t := forall_congr $ λ t, le_antisymm_iff.trans $ and_iff_right $ le_inter_add_diff _ @[simp] lemma is_caratheodory_empty : is_caratheodory ∅ := by simp [is_caratheodory, m.empty, diff_empty] lemma is_caratheodory_compl : is_caratheodory s₁ → is_caratheodory s₁ᶜ := by simp [is_caratheodory, diff_eq, add_comm] @[simp] lemma is_caratheodory_compl_iff : is_caratheodory sᶜ ↔ is_caratheodory s := ⟨λ h, by simpa using is_caratheodory_compl m h, is_caratheodory_compl⟩ lemma is_caratheodory_union (h₁ : is_caratheodory s₁) (h₂ : is_caratheodory s₂) : is_caratheodory (s₁ ∪ s₂) := λ t, begin rw [h₁ t, h₂ (t ∩ s₁), h₂ (t \ s₁), h₁ (t ∩ (s₁ ∪ s₂)), inter_diff_assoc _ _ s₁, set.inter_assoc _ _ s₁, inter_eq_self_of_subset_right (set.subset_union_left _ _), union_diff_left, h₂ (t ∩ s₁)], simp [diff_eq, add_assoc] end lemma measure_inter_union (h : s₁ ∩ s₂ ⊆ ∅) (h₁ : is_caratheodory s₁) {t : set α} : m (t ∩ (s₁ ∪ s₂)) = m (t ∩ s₁) + m (t ∩ s₂) := by rw [h₁, set.inter_assoc, set.union_inter_cancel_left, inter_diff_assoc, union_diff_cancel_left h] lemma is_caratheodory_Union_lt {s : ℕ → set α} : ∀{n:ℕ}, (∀i<n, is_caratheodory (s i)) → is_caratheodory (⋃i<n, s i) | 0 h := by simp [nat.not_lt_zero] | (n + 1) h := by rw Union_lt_succ; exact is_caratheodory_union m (h n (le_refl (n + 1))) (is_caratheodory_Union_lt $ assume i hi, h i $ lt_of_lt_of_le hi $ nat.le_succ _) lemma is_caratheodory_inter (h₁ : is_caratheodory s₁) (h₂ : is_caratheodory s₂) : is_caratheodory (s₁ ∩ s₂) := by { rw [← is_caratheodory_compl_iff, compl_inter], exact is_caratheodory_union _ (is_caratheodory_compl _ h₁) (is_caratheodory_compl _ h₂) } lemma is_caratheodory_sum {s : ℕ → set α} (h : ∀i, is_caratheodory (s i)) (hd : pairwise (disjoint on s)) {t : set α} : ∀ {n}, ∑ i in finset.range n, m (t ∩ s i) = m (t ∩ ⋃i<n, s i) | 0 := by simp [nat.not_lt_zero, m.empty] | (nat.succ n) := begin simp [Union_lt_succ, range_succ], rw [measure_inter_union m _ (h n), is_caratheodory_sum], intro a, simpa [range_succ] using λ h₁ i hi h₂, hd _ _ (ne_of_gt hi) ⟨h₁, h₂⟩ end lemma is_caratheodory_Union_nat {s : ℕ → set α} (h : ∀i, is_caratheodory (s i)) (hd : pairwise (disjoint on s)) : is_caratheodory (⋃i, s i) := is_caratheodory_iff_le'.2 $ λ t, begin have hp : m (t ∩ ⋃i, s i) ≤ (⨆n, m (t ∩ ⋃i<n, s i)), { convert m.Union (λ i, t ∩ s i), { rw inter_Union }, { simp [ennreal.tsum_eq_supr_nat, is_caratheodory_sum m h hd] } }, refine le_trans (add_le_add_right hp _) _, rw ennreal.supr_add, refine supr_le (λ n, le_trans (add_le_add_left _ _) (ge_of_eq (is_caratheodory_Union_lt m (λ i _, h i) _))), refine m.mono (diff_subset_diff_right _), exact bUnion_subset (λ i _, subset_Union _ i), end lemma f_Union {s : ℕ → set α} (h : ∀i, is_caratheodory (s i)) (hd : pairwise (disjoint on s)) : m (⋃i, s i) = ∑'i, m (s i) := begin refine le_antisymm (m.Union_nat s) _, rw ennreal.tsum_eq_supr_nat, refine supr_le (λ n, _), have := @is_caratheodory_sum _ m _ h hd univ n, simp at this, simp [this], exact m.mono (bUnion_subset (λ i _, subset_Union _ i)), end /-- The Carathéodory-measurable sets for an outer measure `m` form a Dynkin system. -/ def caratheodory_dynkin : measurable_space.dynkin_system α := { has := is_caratheodory, has_empty := is_caratheodory_empty, has_compl := assume s, is_caratheodory_compl, has_Union_nat := assume f hf hn, is_caratheodory_Union_nat hn hf } /-- Given an outer measure `μ`, the Carathéodory-measurable space is defined such that `s` is measurable if `∀t, μ t = μ (t ∩ s) + μ (t \ s)`. -/ protected def caratheodory : measurable_space α := caratheodory_dynkin.to_measurable_space $ assume s₁ s₂, is_caratheodory_inter lemma is_caratheodory_iff {s : set α} : caratheodory.is_measurable s ↔ ∀t, m t = m (t ∩ s) + m (t \ s) := iff.rfl lemma is_caratheodory_iff_le {s : set α} : caratheodory.is_measurable s ↔ ∀t, m (t ∩ s) + m (t \ s) ≤ m t := is_caratheodory_iff_le' protected lemma Union_eq_of_caratheodory {s : ℕ → set α} (h : ∀i, caratheodory.is_measurable (s i)) (hd : pairwise (disjoint on s)) : m (⋃i, s i) = ∑'i, m (s i) := f_Union h hd end caratheodory_measurable variables {α : Type*} lemma of_function_caratheodory {m : set α → ennreal} {s : set α} {h₀ : m ∅ = 0} (hs : ∀t, m (t ∩ s) + m (t \ s) ≤ m t) : (outer_measure.of_function m h₀).caratheodory.is_measurable s := begin apply (is_caratheodory_iff_le _).mpr, refine λ t, le_infi (λ f, le_infi $ λ hf, _), refine le_trans (add_le_add (infi_le_of_le (λi, f i ∩ s) $ infi_le _ _) (infi_le_of_le (λi, f i \ s) $ infi_le _ _)) _, { rw ← Union_inter, exact inter_subset_inter_left _ hf }, { rw ← Union_diff, exact diff_subset_diff_left hf }, { rw ← ennreal.tsum_add, exact ennreal.tsum_le_tsum (λ i, hs _) } end @[simp] theorem zero_caratheodory : (0 : outer_measure α).caratheodory = ⊤ := top_unique $ λ s _ t, (add_zero _).symm theorem top_caratheodory : (⊤ : outer_measure α).caratheodory = ⊤ := top_unique $ assume s hs, (is_caratheodory_iff_le _).2 $ assume t, t.eq_empty_or_nonempty.elim (λ ht, by simp [ht]) (λ ht, by simp only [ht, top_apply, le_top]) theorem le_add_caratheodory (m₁ m₂ : outer_measure α) : m₁.caratheodory ⊓ m₂.caratheodory ≤ (m₁ + m₂ : outer_measure α).caratheodory := λ s ⟨hs₁, hs₂⟩ t, by simp [hs₁ t, hs₂ t, add_left_comm, add_assoc] theorem le_sum_caratheodory {ι} (m : ι → outer_measure α) : (⨅ i, (m i).caratheodory) ≤ (sum m).caratheodory := λ s h t, by simp [λ i, measurable_space.is_measurable_infi.1 h i t, ennreal.tsum_add] theorem le_smul_caratheodory (a : ennreal) (m : outer_measure α) : m.caratheodory ≤ (a • m).caratheodory := λ s h t, by simp [h t, mul_add] @[simp] theorem dirac_caratheodory (a : α) : (dirac a).caratheodory = ⊤ := top_unique $ λ s _ t, begin by_cases a ∈ t; simp [h], by_cases a ∈ s; simp [h] end section Inf_gen /-- Given a set of outer measures, we define a new function that on a set `s` is defined to be the infimum of `μ(s)` for the outer measures `μ` in the collection. We ensure that this function is defined to be `0` on `∅`, even if the collection of outer measures is empty. The outer measure generated by this function is the infimum of the given outer measures. -/ def Inf_gen (m : set (outer_measure α)) (s : set α) : ennreal := ⨆(h : s.nonempty), ⨅ (μ : outer_measure α) (h : μ ∈ m), μ s @[simp] lemma Inf_gen_empty (m : set (outer_measure α)) : Inf_gen m ∅ = 0 := by simp [Inf_gen, empty_not_nonempty] lemma Inf_gen_nonempty1 (m : set (outer_measure α)) (t : set α) (h : t.nonempty) : Inf_gen m t = (⨅ (μ : outer_measure α) (h : μ ∈ m), μ t) := by rw [Inf_gen, supr_pos h] lemma Inf_gen_nonempty2 (m : set (outer_measure α)) (μ) (h : μ ∈ m) (t) : Inf_gen m t = (⨅ (μ : outer_measure α) (h : μ ∈ m), μ t) := begin cases t.eq_empty_or_nonempty with ht ht, { simp [ht], refine (bot_unique $ infi_le_of_le μ $ _).symm, refine infi_le_of_le h (le_refl ⊥) }, { exact Inf_gen_nonempty1 m t ht } end lemma Inf_eq_of_function_Inf_gen (m : set (outer_measure α)) : Inf m = outer_measure.of_function (Inf_gen m) (Inf_gen_empty m) := begin refine le_antisymm (assume t', le_of_function.2 (assume t, _) _) (le_Inf $ assume μ hμ t, le_trans (outer_measure.of_function_le _) _); cases t.eq_empty_or_nonempty with ht ht; simp [ht, Inf_gen_nonempty1], { assume μ hμ, exact (show Inf m ≤ μ, from _root_.Inf_le hμ) t }, { exact infi_le_of_le μ (infi_le _ hμ) } end end Inf_gen end outer_measure open outer_measure /-! ### Induced Outer Measure We can extend a function defined on a subset of `set α` to an outer measure. The underlying function is called `extend`, and the measure it induces is called `induced_outer_measure`. Some lemmas below are proven twice, once in the general case, and one where the function `m` is only defined on measurable sets (i.e. when `P = is_measurable`). In the latter cases, we can remove some hypotheses in the statement. The general version has the same name, but with a prime at the end. -/ section extend variables {α : Type*} {P : α → Prop} variables (m : Π (s : α), P s → ennreal) /-- We can trivially extend a function defined on a subclass of objects (with codomain `ennreal`) to all objects by defining it to be `∞` on the objects not in the class. -/ def extend (s : α) : ennreal := ⨅ h : P s, m s h lemma extend_eq {s : α} (h : P s) : extend m s = m s h := by simp [extend, h] lemma le_extend {s : α} (h : P s) : m s h ≤ extend m s := by { simp only [extend, le_infi_iff], intro, refl' } end extend section extend_set variables {α : Type*} {P : set α → Prop} variables {m : Π (s : set α), P s → ennreal} variables (P0 : P ∅) (m0 : m ∅ P0 = 0) variables (PU : ∀{{f : ℕ → set α}} (hm : ∀i, P (f i)), P (⋃i, f i)) variables (mU : ∀ {{f : ℕ → set α}} (hm : ∀i, P (f i)), pairwise (disjoint on f) → m (⋃i, f i) (PU hm) = (∑'i, m (f i) (hm i))) variables (msU : ∀ {{f : ℕ → set α}} (hm : ∀i, P (f i)), m (⋃i, f i) (PU hm) ≤ (∑'i, m (f i) (hm i))) variables (m_mono : ∀⦃s₁ s₂ : set α⦄ (hs₁ : P s₁) (hs₂ : P s₂), s₁ ⊆ s₂ → m s₁ hs₁ ≤ m s₂ hs₂) lemma extend_empty : extend m ∅ = 0 := (extend_eq _ P0).trans m0 lemma extend_Union_nat {f : ℕ → set α} (hm : ∀i, P (f i)) (mU : m (⋃i, f i) (PU hm) = (∑'i, m (f i) (hm i))) : extend m (⋃i, f i) = (∑'i, extend m (f i)) := (extend_eq _ _).trans $ mU.trans $ by { congr' with i, rw extend_eq } section subadditive include PU msU lemma extend_Union_le_tsum_nat' (s : ℕ → set α) : extend m (⋃i, s i) ≤ (∑'i, extend m (s i)) := begin by_cases h : ∀i, P (s i), { rw [extend_eq _ (PU h), congr_arg tsum _], { apply msU h }, funext i, apply extend_eq _ (h i) }, { cases not_forall.1 h with i hi, exact le_trans (le_infi $ λ h, hi.elim h) (ennreal.le_tsum i) } end end subadditive section mono include m_mono lemma extend_mono' ⦃s₁ s₂ : set α⦄ (h₁ : P s₁) (hs : s₁ ⊆ s₂) : extend m s₁ ≤ extend m s₂ := by { refine le_infi _, intro h₂, rw [extend_eq m h₁], exact m_mono h₁ h₂ hs } end mono section unions include P0 m0 PU mU lemma extend_Union {β} [encodable β] {f : β → set α} (hd : pairwise (disjoint on f)) (hm : ∀i, P (f i)) : extend m (⋃i, f i) = (∑'i, extend m (f i)) := begin rw [← encodable.Union_decode2, ← tsum_Union_decode2], { exact extend_Union_nat PU (λ n, encodable.Union_decode2_cases P0 hm) (mU _ (encodable.Union_decode2_disjoint_on hd)) }, { exact extend_empty P0 m0 } end lemma extend_union {s₁ s₂ : set α} (hd : disjoint s₁ s₂) (h₁ : P s₁) (h₂ : P s₂) : extend m (s₁ ∪ s₂) = extend m s₁ + extend m s₂ := begin rw [union_eq_Union, extend_Union P0 m0 PU mU (pairwise_disjoint_on_bool.2 hd) (bool.forall_bool.2 ⟨h₂, h₁⟩), tsum_fintype], simp end end unions variable (m) /-- Given an arbitrary function on a subset of sets, we can define the outer measure corresponding to it (this is the unique maximal outer measure that is at most `m` on the domain of `m`). -/ def induced_outer_measure : outer_measure α := outer_measure.of_function (extend m) (extend_empty P0 m0) variables {m P0 m0} include msU m_mono lemma induced_outer_measure_eq_extend' {s : set α} (hs : P s) : induced_outer_measure m P0 m0 s = extend m s := of_function_eq s (λ t, extend_mono' m_mono hs) (extend_Union_le_tsum_nat' PU msU) lemma induced_outer_measure_eq' {s : set α} (hs : P s) : induced_outer_measure m P0 m0 s = m s hs := (induced_outer_measure_eq_extend' PU msU m_mono hs).trans $ extend_eq _ _ lemma induced_outer_measure_eq_infi (s : set α) : induced_outer_measure m P0 m0 s = ⨅ (t : set α) (ht : P t) (h : s ⊆ t), m t ht := begin apply le_antisymm, { simp only [le_infi_iff], intros t ht, simp only [le_infi_iff], intro hs, refine le_trans (mono' _ hs) _, exact le_of_eq (induced_outer_measure_eq' _ msU m_mono _) }, { refine le_infi _, intro f, refine le_infi _, intro hf, refine le_trans _ (extend_Union_le_tsum_nat' _ msU _), refine le_infi _, intro h2f, refine infi_le_of_le _ (infi_le_of_le h2f $ infi_le _ hf) } end lemma induced_outer_measure_preimage (f : α ≃ α) (Pm : ∀ (s : set α), P (f ⁻¹' s) ↔ P s) (mm : ∀ (s : set α) (hs : P s), m (f ⁻¹' s) ((Pm _).mpr hs) = m s hs) {A : set α} : induced_outer_measure m P0 m0 (f ⁻¹' A) = induced_outer_measure m P0 m0 A := begin simp only [induced_outer_measure_eq_infi _ msU m_mono], symmetry, refine infi_congr (preimage f) f.injective.preimage_surjective _, intro s, refine infi_congr_Prop (Pm s) _, intro hs, refine infi_congr_Prop f.surjective.preimage_subset_preimage_iff _, intro h2s, exact mm s hs end lemma induced_outer_measure_exists_set {s : set α} (hs : induced_outer_measure m P0 m0 s < ⊤) {ε : nnreal} (hε : 0 < ε) : ∃ (t : set α) (ht : P t), s ⊆ t ∧ induced_outer_measure m P0 m0 t ≤ induced_outer_measure m P0 m0 s + ε := begin have := ennreal.lt_add_right hs (ennreal.zero_lt_coe_iff.2 hε), conv at this {to_lhs, rw induced_outer_measure_eq_infi _ msU m_mono }, simp only [infi_lt_iff] at this, rcases this with ⟨t, h1t, h2t, h3t⟩, exact ⟨t, h1t, h2t, le_trans (le_of_eq $ induced_outer_measure_eq' _ msU m_mono h1t) (le_of_lt h3t)⟩ end /-- To test whether `s` is Carathéodory-measurable we only need to check the sets `t` for which `P t` holds. See `of_function_caratheodory` for another way to show the Carathéodory-measurability of `s`. -/ lemma induced_outer_measure_caratheodory (s : set α) : (induced_outer_measure m P0 m0).caratheodory.is_measurable s ↔ ∀ (t : set α), P t → induced_outer_measure m P0 m0 (t ∩ s) + induced_outer_measure m P0 m0 (t \ s) ≤ induced_outer_measure m P0 m0 t := begin rw is_caratheodory_iff_le, split, { intros h t ht, exact h t }, { intros h u, conv_rhs { rw induced_outer_measure_eq_infi _ msU m_mono }, refine le_infi _, intro t, refine le_infi _, intro ht, refine le_infi _, intro h2t, refine le_trans _ (le_trans (h t ht) $ le_of_eq $ induced_outer_measure_eq' _ msU m_mono ht), refine add_le_add (mono' _ $ set.inter_subset_inter_left _ h2t) (mono' _ $ diff_subset_diff_left h2t) } end end extend_set /-! If `P` is `is_measurable` for some measurable space, then we can remove some hypotheses of the above lemmas. -/ section measurable_space variables {α : Type*} [measurable_space α] variables {m : Π (s : set α), is_measurable s → ennreal} variables (m0 : m ∅ is_measurable.empty = 0) variable (mU : ∀ {{f : ℕ → set α}} (hm : ∀i, is_measurable (f i)), pairwise (disjoint on f) → m (⋃i, f i) (is_measurable.Union hm) = (∑'i, m (f i) (hm i))) include m0 mU lemma extend_mono {s₁ s₂ : set α} (h₁ : is_measurable s₁) (hs : s₁ ⊆ s₂) : extend m s₁ ≤ extend m s₂ := begin refine le_infi _, intro h₂, have := extend_union is_measurable.empty m0 is_measurable.Union mU disjoint_diff h₁ (h₂.diff h₁), rw union_diff_cancel hs at this, rw ← extend_eq m, exact le_iff_exists_add.2 ⟨_, this⟩, end lemma extend_Union_le_tsum_nat : ∀ (s : ℕ → set α), extend m (⋃i, s i) ≤ (∑'i, extend m (s i)) := begin refine extend_Union_le_tsum_nat' is_measurable.Union _, intros f h, simp [Union_disjointed.symm] {single_pass := tt}, rw [mU (is_measurable.disjointed h) disjoint_disjointed], refine ennreal.tsum_le_tsum (λ i, _), rw [← extend_eq m, ← extend_eq m], exact extend_mono m0 mU (is_measurable.disjointed h _) (inter_subset_left _ _) end lemma induced_outer_measure_eq_extend {s : set α} (hs : is_measurable s) : induced_outer_measure m is_measurable.empty m0 s = extend m s := of_function_eq s (λ t, extend_mono m0 mU hs) (extend_Union_le_tsum_nat m0 mU) lemma induced_outer_measure_eq {s : set α} (hs : is_measurable s) : induced_outer_measure m is_measurable.empty m0 s = m s hs := (induced_outer_measure_eq_extend m0 mU hs).trans $ extend_eq _ _ end measurable_space namespace outer_measure variables {α : Type*} [measurable_space α] (m : outer_measure α) /-- Given an outer measure `m` we can forget its value on non-measurable sets, and then consider `m.trim`, the unique maximal outer measure less than that function. -/ def trim : outer_measure α := induced_outer_measure (λ s _, m s) is_measurable.empty m.empty theorem le_trim : m ≤ m.trim := le_of_function.mpr $ λ s, le_infi $ λ _, le_refl _ theorem trim_eq {s : set α} (hs : is_measurable s) : m.trim s = m s := induced_outer_measure_eq' is_measurable.Union (λ f hf, m.Union_nat f) (λ _ _ _ _ h, m.mono h) hs theorem trim_congr {m₁ m₂ : outer_measure α} (H : ∀ {s : set α}, is_measurable s → m₁ s = m₂ s) : m₁.trim = m₂.trim := by { unfold trim, congr, funext s hs, exact H hs } theorem trim_le_trim {m₁ m₂ : outer_measure α} (H : m₁ ≤ m₂) : m₁.trim ≤ m₂.trim := λ s, binfi_le_binfi $ λ f hs, ennreal.tsum_le_tsum $ λ b, infi_le_infi $ λ hf, H _ theorem le_trim_iff {m₁ m₂ : outer_measure α} : m₁ ≤ m₂.trim ↔ ∀ s, is_measurable s → m₁ s ≤ m₂ s := le_of_function.trans $ forall_congr $ λ s, le_infi_iff theorem trim_eq_infi (s : set α) : m.trim s = ⨅ t (st : s ⊆ t) (ht : is_measurable t), m t := by { simp only [infi_comm] {single_pass := tt}, exact induced_outer_measure_eq_infi is_measurable.Union (λ f _, m.Union_nat f) (λ _ _ _ _ h, m.mono h) s } theorem trim_eq_infi' (s : set α) : m.trim s = ⨅ t : {t // s ⊆ t ∧ is_measurable t}, m t := by simp [infi_subtype, infi_and, trim_eq_infi] theorem trim_trim (m : outer_measure α) : m.trim.trim = m.trim := le_antisymm (le_trim_iff.2 $ λ s hs, by simp [trim_eq _ hs, le_refl]) (le_trim _) @[simp] theorem trim_zero : (0 : outer_measure α).trim = 0 := ext $ λ s, le_antisymm (le_trans ((trim 0).mono (subset_univ s)) $ le_of_eq $ trim_eq _ is_measurable.univ) (zero_le _) theorem trim_add (m₁ m₂ : outer_measure α) : (m₁ + m₂).trim = m₁.trim + m₂.trim := begin ext1 s, simp only [trim_eq_infi', add_apply], rw ennreal.infi_add_infi, rintro ⟨t₁, st₁, ht₁⟩ ⟨t₂, st₂, ht₂⟩, exact ⟨⟨_, subset_inter_iff.2 ⟨st₁, st₂⟩, ht₁.inter ht₂⟩, add_le_add (m₁.mono' (inter_subset_left _ _)) (m₂.mono' (inter_subset_right _ _))⟩, end theorem trim_sum_ge {ι} (m : ι → outer_measure α) : sum (λ i, (m i).trim) ≤ (sum m).trim := λ s, by simp [trim_eq_infi]; exact λ t st ht, ennreal.tsum_le_tsum (λ i, infi_le_of_le t $ infi_le_of_le st $ infi_le _ ht) lemma exists_is_measurable_superset_of_trim_eq_zero {m : outer_measure α} {s : set α} (h : m.trim s = 0) : ∃t, s ⊆ t ∧ is_measurable t ∧ m t = 0 := begin erw [trim_eq_infi, infi_eq_bot] at h, choose t ht using show ∀n:ℕ, ∃t, s ⊆ t ∧ is_measurable t ∧ m t < n⁻¹, { assume n, have : (0 : ennreal) < n⁻¹ := (ennreal.inv_pos.2 $ ennreal.nat_ne_top _), rcases h _ this with ⟨t, ht⟩, use [t], simpa only [infi_lt_iff, exists_prop] using ht }, refine ⟨⋂n, t n, subset_Inter (λn, (ht n).1), is_measurable.Inter (λn, (ht n).2.1), _⟩, refine le_antisymm _ (zero_le _), refine le_of_tendsto_of_tendsto tendsto_const_nhds ennreal.tendsto_inv_nat_nhds_zero (eventually_of_forall $ assume n, _), exact le_trans (m.mono' $ Inter_subset _ _) (le_of_lt (ht n).2.2) end theorem trim_smul (c : ennreal) (m : outer_measure α) : (c • m).trim = c • m.trim := begin ext1 s, simp only [trim_eq_infi', smul_apply], haveI : nonempty {t // s ⊆ t ∧ is_measurable t} := ⟨⟨univ, subset_univ _, is_measurable.univ⟩⟩, refine ennreal.infi_mul_left (assume hc hs, _), rw ← trim_eq_infi' at hs, simpa [and_assoc] using exists_is_measurable_superset_of_trim_eq_zero hs end end outer_measure end measure_theory
721d1c1a6c93a99d959c791976edba6d22aea1d4
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/topology/sheaves/stalks.lean
f0b24e3cd2a9ce5f4bb0b3aab0905660a14f9dd4
[]
no_license
AurelienSaue/Mathlib4_auto
f538cfd0980f65a6361eadea39e6fc639e9dae14
590df64109b08190abe22358fabc3eae000943f2
refs/heads/master
1,683,906,849,776
1,622,564,669,000
1,622,564,669,000
371,723,747
0
0
null
null
null
null
UTF-8
Lean
false
false
7,694
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 Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.topology.category.Top.open_nhds import Mathlib.topology.sheaves.presheaf import Mathlib.category_theory.limits.limits import Mathlib.category_theory.limits.types import Mathlib.PostPort universes u v u_1 namespace Mathlib namespace Top.presheaf /-- Stalks are functorial with respect to morphisms of presheaves over a fixed `X`. -/ def stalk_functor (C : Type u) [category_theory.category C] [category_theory.limits.has_colimits C] {X : Top} (x : ↥X) : presheaf C X ⥤ C := category_theory.functor.obj (category_theory.whiskering_left (topological_space.open_nhds xᵒᵖ) (topological_space.opens ↥Xᵒᵖ) C) (category_theory.functor.op (topological_space.open_nhds.inclusion x)) ⋙ category_theory.limits.colim /-- The stalk of a presheaf `F` at a point `x` is calculated as the colimit of the functor nbhds x ⥤ opens F.X ⥤ C -/ def stalk {C : Type u} [category_theory.category C] [category_theory.limits.has_colimits C] {X : Top} (ℱ : presheaf C X) (x : ↥X) : C := category_theory.functor.obj (stalk_functor C x) ℱ @[simp] theorem stalk_functor_obj {C : Type u} [category_theory.category C] [category_theory.limits.has_colimits C] {X : Top} (ℱ : presheaf C X) (x : ↥X) : category_theory.functor.obj (stalk_functor C x) ℱ = stalk ℱ x := rfl /-- The germ of a section of a presheaf over an open at a point of that open. -/ def germ {C : Type u} [category_theory.category C] [category_theory.limits.has_colimits C] {X : Top} (F : presheaf C X) {U : topological_space.opens ↥X} (x : ↥U) : category_theory.functor.obj F (opposite.op U) ⟶ stalk F ↑x := category_theory.limits.colimit.ι (category_theory.functor.op (topological_space.open_nhds.inclusion (subtype.val x)) ⋙ F) (opposite.op { val := U, property := sorry }) /-- For a `Type` valued presheaf, every point in a stalk is a germ. -/ theorem germ_exist {X : Top} (F : presheaf (Type v) X) (x : ↥X) (t : stalk F x) : ∃ (U : topological_space.opens ↥X), ∃ (m : x ∈ U), ∃ (s : category_theory.functor.obj F (opposite.op U)), germ F { val := x, property := m } s = t := sorry theorem germ_eq {X : Top} (F : presheaf (Type v) X) {U : topological_space.opens ↥X} {V : topological_space.opens ↥X} (x : ↥X) (mU : x ∈ U) (mV : x ∈ V) (s : category_theory.functor.obj F (opposite.op U)) (t : category_theory.functor.obj F (opposite.op V)) (h : germ F { val := x, property := mU } s = germ F { val := x, property := mV } t) : ∃ (W : topological_space.opens ↥X), ∃ (m : x ∈ W), ∃ (iU : W ⟶ U), ∃ (iV : W ⟶ V), category_theory.functor.map F (category_theory.has_hom.hom.op iU) s = category_theory.functor.map F (category_theory.has_hom.hom.op iV) t := sorry @[simp] theorem germ_res {C : Type u} [category_theory.category C] [category_theory.limits.has_colimits C] {X : Top} (F : presheaf C X) {U : topological_space.opens ↥X} {V : topological_space.opens ↥X} (i : U ⟶ V) (x : ↥U) : category_theory.functor.map F (category_theory.has_hom.hom.op i) ≫ germ F x = germ F (coe_fn i x) := sorry @[simp] theorem germ_res_apply {X : Top} (F : presheaf (Type v) X) {U : topological_space.opens ↥X} {V : topological_space.opens ↥X} (i : U ⟶ V) (x : ↥U) (f : category_theory.functor.obj F (opposite.op V)) : germ F x (category_theory.functor.map F (category_theory.has_hom.hom.op i) f) = germ F (coe_fn i x) f := sorry /-- A variant when the open sets are written in `(opens X)ᵒᵖ`. -/ @[simp] theorem germ_res_apply' {X : Top} (F : presheaf (Type v) X) {U : topological_space.opens ↥Xᵒᵖ} {V : topological_space.opens ↥Xᵒᵖ} (i : V ⟶ U) (x : ↥(opposite.unop U)) (f : category_theory.functor.obj F V) : germ F x (category_theory.functor.map F i f) = germ F (coe_fn (category_theory.has_hom.hom.unop i) x) f := sorry theorem germ_ext {X : Top} {D : Type u} [category_theory.category D] [category_theory.concrete_category D] [category_theory.limits.has_colimits D] (F : presheaf D X) {U : topological_space.opens ↥X} {V : topological_space.opens ↥X} {x : ↥X} {hxU : x ∈ U} {hxV : x ∈ V} (W : topological_space.opens ↥X) (hxW : x ∈ W) (iWU : W ⟶ U) (iWV : W ⟶ V) {sU : ↥(category_theory.functor.obj F (opposite.op U))} {sV : ↥(category_theory.functor.obj F (opposite.op V))} (ih : coe_fn (category_theory.functor.map F (category_theory.has_hom.hom.op iWU)) sU = coe_fn (category_theory.functor.map F (category_theory.has_hom.hom.op iWV)) sV) : coe_fn (germ F { val := x, property := hxU }) sU = coe_fn (germ F { val := x, property := hxV }) sV := sorry theorem stalk_hom_ext {C : Type u} [category_theory.category C] [category_theory.limits.has_colimits C] {X : Top} (F : presheaf C X) {x : ↥X} {Y : C} {f₁ : stalk F x ⟶ Y} {f₂ : stalk F x ⟶ Y} (ih : ∀ (U : topological_space.opens ↥X) (hxU : x ∈ U), germ F { val := x, property := hxU } ≫ f₁ = germ F { val := x, property := hxU } ≫ f₂) : f₁ = f₂ := sorry def stalk_pushforward (C : Type u) [category_theory.category C] [category_theory.limits.has_colimits C] {X : Top} {Y : Top} (f : X ⟶ Y) (ℱ : presheaf C X) (x : ↥X) : stalk (f _* ℱ) (coe_fn f x) ⟶ stalk ℱ x := category_theory.functor.map category_theory.limits.colim (category_theory.whisker_right (category_theory.nat_trans.op (category_theory.iso.inv (topological_space.open_nhds.inclusion_map_iso f x))) ℱ) ≫ category_theory.limits.colimit.pre (category_theory.functor.obj (category_theory.functor.obj (category_theory.whiskering_left (topological_space.open_nhds xᵒᵖ) (topological_space.opens ↥Xᵒᵖ) C) (category_theory.functor.op (topological_space.open_nhds.inclusion x))) ℱ) (category_theory.functor.op (topological_space.open_nhds.map f x)) -- Here are two other potential solutions, suggested by @fpvandoorn at -- <https://github.com/leanprover-community/mathlib/pull/1018#discussion_r283978240> -- However, I can't get the subsequent two proofs to work with either one. -- def stalk_pushforward (f : X ⟶ Y) (ℱ : X.presheaf C) (x : X) : (f _* ℱ).stalk (f x) ⟶ ℱ.stalk x := -- colim.map ((functor.associator _ _ _).inv ≫ -- whisker_right (nat_trans.op (open_nhds.inclusion_map_iso f x).inv) ℱ) ≫ -- colimit.pre ((open_nhds.inclusion x).op ⋙ ℱ) (open_nhds.map f x).op -- def stalk_pushforward (f : X ⟶ Y) (ℱ : X.presheaf C) (x : X) : (f _* ℱ).stalk (f x) ⟶ ℱ.stalk x := -- (colim.map (whisker_right (nat_trans.op (open_nhds.inclusion_map_iso f x).inv) ℱ) : -- colim.obj ((open_nhds.inclusion (f x) ⋙ opens.map f).op ⋙ ℱ) ⟶ _) ≫ -- colimit.pre ((open_nhds.inclusion x).op ⋙ ℱ) (open_nhds.map f x).op namespace stalk_pushforward @[simp] theorem id (C : Type u) [category_theory.category C] [category_theory.limits.has_colimits C] {X : Top} (ℱ : presheaf C X) (x : ↥X) : stalk_pushforward C 𝟙 ℱ x = category_theory.functor.map (stalk_functor C x) (category_theory.iso.hom (pushforward.id ℱ)) := sorry -- This proof is sadly not at all robust: -- having to use `erw` at all is a bad sign. @[simp] theorem comp (C : Type u) [category_theory.category C] [category_theory.limits.has_colimits C] {X : Top} {Y : Top} {Z : Top} (ℱ : presheaf C X) (f : X ⟶ Y) (g : Y ⟶ Z) (x : ↥X) : stalk_pushforward C (f ≫ g) ℱ x = stalk_pushforward C g (f _* ℱ) (coe_fn f x) ≫ stalk_pushforward C f ℱ x := sorry
d3d7c94a114794c89e91156d1b145c1aebfbbcff
87fd6b43d22688237c02b87c30d2a524f53bab24
/src/game/sets/sets_level05.lean
6981e19951a8322917d6b00b648fb2a4670432e2
[ "Apache-2.0" ]
permissive
grthomson/real-number-game
66142fedf0987db90f66daed52f9c8b42b70f909
8ddc15fdddc241c246653f7bb341df36e4e880a8
refs/heads/master
1,668,059,330,605
1,592,873,454,000
1,592,873,454,000
262,025,764
0
0
null
1,588,849,107,000
1,588,849,106,000
null
UTF-8
Lean
false
false
1,180
lean
import game.sets.sets_level04 -- hide namespace xena -- hide open_locale classical -- hide variable X : Type --hide /- # Chapter 1 : Sets ## Level 5 -/ /- If `h : ∀ (x : X), x ∈ A → x ∈ B` then `h` is a function which takes an element of x as input, and a proof that `x ∈ A`, and outputs a proof that `x ∈ B`. If you want to run this function `h` on some term `x : X` then any of the following work: ``` have h2 := h x, replace h := h x, specialize h x ``` -/ /- Lemma If $A$ and $B$ are sets of any type $X$, then $$ A \subseteq B \iff A \cap B = A.$$ -/ theorem subset_iff_intersection_eq (A : set X) (B : set X) : A ⊆ B ↔ A ∩ B = A := begin rw subset_iff, rw eq_iff, split, { intros h x, specialize h x, rw mem_inter_iff, tauto! }, { intros h x hx, specialize h x, rw mem_inter_iff at h, tauto!, } end -- begin hide -- theorem subset_iff_intersection_eq' (A : set X) (B : set X) : A ⊆ B ↔ A ∩ B = A := -- begin -- rw subset_iff, -- rw eq_iff, -- apply forall_congr, -- clever trick -- intro x, -- rw mem_inter_iff, -- no longer under a binder -- tauto! -- end -- end hide end xena -- hide
f978822e10da54a7ba641fda561ba793251b5d86
9dc8cecdf3c4634764a18254e94d43da07142918
/src/data/buffer/basic.lean
c5f0b084a399afe87e4a33782734738e5aa2353d
[ "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
7,346
lean
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon General utility functions for buffers. -/ import data.buffer import data.array.lemmas import control.traversable.instances namespace buffer open function variables {α : Type*} {xs : list α} instance : inhabited (buffer α) := ⟨nil⟩ @[ext] lemma ext : ∀ {b₁ b₂ : buffer α}, to_list b₁ = to_list b₂ → b₁ = b₂ | ⟨n₁, a₁⟩ ⟨n₂, a₂⟩ h := begin simp [to_list, to_array] at h, have e : n₁ = n₂ := by rw [←array.to_list_length a₁, ←array.to_list_length a₂, h], subst e, have h : a₁ == a₂.to_list.to_array := h ▸ a₁.to_list_to_array.symm, rw eq_of_heq (h.trans a₂.to_list_to_array) end lemma ext_iff {b₁ b₂ : buffer α} : b₁ = b₂ ↔ to_list b₁ = to_list b₂ := ⟨λ h, h ▸ rfl, ext⟩ lemma size_eq_zero_iff {b : buffer α} : b.size = 0 ↔ b = nil := begin rcases b with ⟨_|n, ⟨a⟩⟩, { simp only [size, nil, mk_buffer, true_and, true_iff, eq_self_iff_true, heq_iff_eq, sigma.mk.inj_iff], ext i, exact fin.elim0 i }, { simp [size, nil, mk_buffer, nat.succ_ne_zero] } end @[simp] lemma size_nil : (@nil α).size = 0 := by rw size_eq_zero_iff @[simp] lemma to_list_nil : to_list (@nil α) = [] := rfl instance (α) [decidable_eq α] : decidable_eq (buffer α) := by tactic.mk_dec_eq_instance @[simp] lemma to_list_append_list {b : buffer α} : to_list (append_list b xs) = to_list b ++ xs := by induction xs generalizing b; simp! [*]; cases b; simp! [to_list,to_array] @[simp] lemma append_list_mk_buffer : append_list mk_buffer xs = array.to_buffer (list.to_array xs) := by ext x : 1; simp [array.to_buffer,to_list,to_list_append_list]; induction xs; [refl,skip]; simp [to_array]; refl @[simp] lemma to_buffer_to_list (b : buffer α) : b.to_list.to_buffer = b := begin cases b, rw [to_list, to_array, list.to_buffer, append_list_mk_buffer], congr, { simpa }, { apply array.to_list_to_array } end @[simp] lemma to_list_to_buffer (l : list α) : l.to_buffer.to_list = l := begin cases l, { refl }, { rw [list.to_buffer, to_list_append_list], refl } end @[simp] lemma to_list_to_array (b : buffer α) : b.to_array.to_list = b.to_list := by { cases b, simp [to_list] } @[simp] lemma append_list_nil (b : buffer α) : b.append_list [] = b := rfl lemma to_buffer_cons (c : α) (l : list α) : (c :: l).to_buffer = [c].to_buffer.append_list l := begin induction l with hd tl hl, { simp }, { apply ext, simp [hl] } end @[simp] lemma size_push_back (b : buffer α) (a : α) : (b.push_back a).size = b.size + 1 := by { cases b, simp [size, push_back] } @[simp] lemma size_append_list (b : buffer α) (l : list α) : (b.append_list l).size = b.size + l.length := begin induction l with hd tl hl generalizing b, { simp }, { simp [append_list, hl, add_comm, add_assoc] } end @[simp] lemma size_to_buffer (l : list α) : l.to_buffer.size = l.length := begin induction l with hd tl hl, { simpa }, { rw [to_buffer_cons], have : [hd].to_buffer.size = 1 := rfl, simp [add_comm, this] } end @[simp] lemma length_to_list (b : buffer α) : b.to_list.length = b.size := by rw [←to_buffer_to_list b, to_list_to_buffer, size_to_buffer] lemma size_singleton (a : α) : [a].to_buffer.size = 1 := rfl lemma read_push_back_left (b : buffer α) (a : α) {i : ℕ} (h : i < b.size) : (b.push_back a).read ⟨i, by { convert nat.lt_succ_of_lt h, simp }⟩ = b.read ⟨i, h⟩ := by { cases b, convert array.read_push_back_left _, simp } @[simp] lemma read_push_back_right (b : buffer α) (a : α) : (b.push_back a).read ⟨b.size, by simp⟩ = a := by { cases b, convert array.read_push_back_right } lemma read_append_list_left' (b : buffer α) (l : list α) {i : ℕ} (h : i < (b.append_list l).size) (h' : i < b.size) : (b.append_list l).read ⟨i, h⟩ = b.read ⟨i, h'⟩ := begin induction l with hd tl hl generalizing b, { refl }, { have hb : i < ((b.push_back hd).append_list tl).size := by convert h using 1, have hb' : i < (b.push_back hd).size := by { convert nat.lt_succ_of_lt h', simp }, have : (append_list b (hd :: tl)).read ⟨i, h⟩ = read ((push_back b hd).append_list tl) ⟨i, hb⟩ := rfl, simp [this, hl _ hb hb', read_push_back_left _ _ h'] } end lemma read_append_list_left (b : buffer α) (l : list α) {i : ℕ} (h : i < b.size) : (b.append_list l).read ⟨i, by simpa using nat.lt_add_right _ _ _ h⟩ = b.read ⟨i, h⟩ := read_append_list_left' b l _ h @[simp] lemma read_append_list_right (b : buffer α) (l : list α) {i : ℕ} (h : i < l.length) : (b.append_list l).read ⟨b.size + i, by simp [h]⟩ = l.nth_le i h := begin induction l with hd tl hl generalizing b i, { exact absurd i.zero_le (not_le_of_lt h) }, { convert_to ((b.push_back hd).append_list tl).read _ = _, cases i, { convert read_append_list_left _ _ _; simp }, { rw [list.length, nat.succ_lt_succ_iff] at h, have : b.size + i.succ = (b.push_back hd).size + i, { simp [add_comm, add_left_comm, nat.succ_eq_add_one] }, convert hl (b.push_back hd) h using 1, simpa [nat.add_succ, nat.succ_add] } } end lemma read_to_buffer' (l : list α) {i : ℕ} (h : i < l.to_buffer.size) (h' : i < l.length) : l.to_buffer.read ⟨i, h⟩ = l.nth_le i h' := begin cases l with hd tl, { simpa using h' }, { have hi : i < ([hd].to_buffer.append_list tl).size := by simpa [add_comm] using h, convert_to ([hd].to_buffer.append_list tl).read ⟨i, hi⟩ = _, cases i, { convert read_append_list_left _ _ _, simp }, { rw list.nth_le, convert read_append_list_right _ _ _, simp [nat.succ_eq_add_one, add_comm] } } end @[simp] lemma read_to_buffer (l : list α) (i) : l.to_buffer.read i = l.nth_le i (by { convert i.property, simp }) := by { convert read_to_buffer' _ _ _, { simp }, { simpa using i.property } } lemma nth_le_to_list' (b : buffer α) {i : ℕ} (h h') : b.to_list.nth_le i h = b.read ⟨i, h'⟩ := begin have : b.to_list.to_buffer.read ⟨i, (by simpa using h')⟩ = b.read ⟨i, h'⟩, { congr' 1; simp [fin.heq_ext_iff] }, simp [←this] end lemma nth_le_to_list (b : buffer α) {i : ℕ} (h) : b.to_list.nth_le i h = b.read ⟨i, by simpa using h⟩ := nth_le_to_list' _ _ _ lemma read_eq_nth_le_to_list (b : buffer α) (i) : b.read i = b.to_list.nth_le i (by simp) := by simp [nth_le_to_list] lemma read_singleton (c : α) : [c].to_buffer.read ⟨0, by simp⟩ = c := by simp /-- The natural equivalence between lists and buffers, using `list.to_buffer` and `buffer.to_list`. -/ def list_equiv_buffer (α : Type*) : list α ≃ buffer α := begin refine { to_fun := list.to_buffer, inv_fun := buffer.to_list, .. }; simp [left_inverse,function.right_inverse] end instance : traversable buffer := equiv.traversable list_equiv_buffer instance : is_lawful_traversable buffer := equiv.is_lawful_traversable list_equiv_buffer /-- A convenience wrapper around `read` that just fails if the index is out of bounds. -/ meta def read_t (b : buffer α) (i : ℕ) : tactic α := if h : i < b.size then return $ b.read (fin.mk i h) else tactic.fail "invalid buffer access" end buffer
d0b031990c36b0c5d7d1ff899df740dfba51a230
9dc8cecdf3c4634764a18254e94d43da07142918
/src/number_theory/sum_four_squares.lean
5c36439501b47587428512e3c4caa3d840143faa
[ "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
11,841
lean
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import algebra.group_power.identities import data.zmod.basic import field_theory.finite.basic import data.int.parity import data.fintype.card /-! # Lagrange's four square theorem The main result in this file is `sum_four_squares`, a proof that every natural number is the sum of four square numbers. ## Implementation Notes The proof used is close to Lagrange's original proof. -/ open finset polynomial finite_field equiv open_locale big_operators namespace int lemma sq_add_sq_of_two_mul_sq_add_sq {m x y : ℤ} (h : 2 * m = x^2 + y^2) : m = ((x - y) / 2) ^ 2 + ((x + y) / 2) ^ 2 := have even (x^2 + y^2), by simp [h.symm, even_mul], have hxaddy : even (x + y), by simpa [sq] with parity_simps, have hxsuby : even (x - y), by simpa [sq] with parity_simps, (mul_right_inj' (show (2*2 : ℤ) ≠ 0, from dec_trivial)).1 $ calc 2 * 2 * m = (x - y)^2 + (x + y)^2 : by rw [mul_assoc, h]; ring ... = (2 * ((x - y) / 2))^2 + (2 * ((x + y) / 2))^2 : by { rw even_iff_two_dvd at hxsuby hxaddy, rw [int.mul_div_cancel' hxsuby, int.mul_div_cancel' hxaddy] } ... = 2 * 2 * (((x - y) / 2) ^ 2 + ((x + y) / 2) ^ 2) : by simp [mul_add, pow_succ, mul_comm, mul_assoc, mul_left_comm] lemma exists_sq_add_sq_add_one_eq_k (p : ℕ) [hp : fact p.prime] : ∃ (a b : ℤ) (k : ℕ), a^2 + b^2 + 1 = k * p ∧ k < p := hp.1.eq_two_or_odd.elim (λ hp2, hp2.symm ▸ ⟨1, 0, 1, rfl, dec_trivial⟩) $ λ hp1, let ⟨a, b, hab⟩ := zmod.sq_add_sq p (-1) in have hab' : (p : ℤ) ∣ a.val_min_abs ^ 2 + b.val_min_abs ^ 2 + 1, from (char_p.int_cast_eq_zero_iff (zmod p) p _).1 $ by simpa [eq_neg_iff_add_eq_zero] using hab, let ⟨k, hk⟩ := hab' in have hk0 : 0 ≤ k, from nonneg_of_mul_nonneg_right (by rw ← hk; exact (add_nonneg (add_nonneg (sq_nonneg _) (sq_nonneg _)) zero_le_one)) (int.coe_nat_pos.2 hp.1.pos), ⟨a.val_min_abs, b.val_min_abs, k.nat_abs, by rw [hk, int.nat_abs_of_nonneg hk0, mul_comm], lt_of_mul_lt_mul_left (calc p * k.nat_abs = a.val_min_abs.nat_abs ^ 2 + b.val_min_abs.nat_abs ^ 2 + 1 : by rw [← int.coe_nat_inj', int.coe_nat_add, int.coe_nat_add, int.coe_nat_pow, int.coe_nat_pow, int.nat_abs_sq, int.nat_abs_sq, int.coe_nat_one, hk, int.coe_nat_mul, int.nat_abs_of_nonneg hk0] ... ≤ (p / 2) ^ 2 + (p / 2)^2 + 1 : add_le_add (add_le_add (nat.pow_le_pow_of_le_left (zmod.nat_abs_val_min_abs_le _) _) (nat.pow_le_pow_of_le_left (zmod.nat_abs_val_min_abs_le _) _)) le_rfl ... < (p / 2) ^ 2 + (p / 2)^ 2 + (p % 2)^2 + ((2 * (p / 2)^2 + (4 * (p / 2) * (p % 2)))) : by rw [hp1, one_pow, mul_one]; exact (lt_add_iff_pos_right _).2 (add_pos_of_nonneg_of_pos (nat.zero_le _) (mul_pos dec_trivial (nat.div_pos hp.1.two_le dec_trivial))) ... = p * p : by { conv_rhs { rw [← nat.mod_add_div p 2] }, ring }) (show 0 ≤ p, from nat.zero_le _)⟩ end int namespace nat open int open_locale classical private lemma sum_four_squares_of_two_mul_sum_four_squares {m a b c d : ℤ} (h : a^2 + b^2 + c^2 + d^2 = 2 * m) : ∃ w x y z : ℤ, w^2 + x^2 + y^2 + z^2 = m := have ∀ f : fin 4 → zmod 2, (f 0)^2 + (f 1)^2 + (f 2)^2 + (f 3)^2 = 0 → ∃ i : (fin 4), (f i)^2 + f (swap i 0 1)^2 = 0 ∧ f (swap i 0 2)^2 + f (swap i 0 3)^2 = 0, from dec_trivial, let f : fin 4 → ℤ := vector.nth (a ::ᵥ b ::ᵥ c ::ᵥ d ::ᵥ vector.nil) in let ⟨i, hσ⟩ := this (coe ∘ f) (by rw [← @zero_mul (zmod 2) _ m, ← show ((2 : ℤ) : zmod 2) = 0, from rfl, ← int.cast_mul, ← h]; simp only [int.cast_add, int.cast_pow]; refl) in let σ := swap i 0 in have h01 : 2 ∣ f (σ 0) ^ 2 + f (σ 1) ^ 2, from (char_p.int_cast_eq_zero_iff (zmod 2) 2 _).1 $ by simpa [σ] using hσ.1, have h23 : 2 ∣ f (σ 2) ^ 2 + f (σ 3) ^ 2, from (char_p.int_cast_eq_zero_iff (zmod 2) 2 _).1 $ by simpa using hσ.2, let ⟨x, hx⟩ := h01 in let ⟨y, hy⟩ := h23 in ⟨(f (σ 0) - f (σ 1)) / 2, (f (σ 0) + f (σ 1)) / 2, (f (σ 2) - f (σ 3)) / 2, (f (σ 2) + f (σ 3)) / 2, begin rw [← int.sq_add_sq_of_two_mul_sq_add_sq hx.symm, add_assoc, ← int.sq_add_sq_of_two_mul_sq_add_sq hy.symm, ← mul_right_inj' (show (2 : ℤ) ≠ 0, from dec_trivial), ← h, mul_add, ← hx, ← hy], have : ∑ x, f (σ x)^2 = ∑ x, f x^2, { conv_rhs { rw ←equiv.sum_comp σ } }, have fin4univ : (univ : finset (fin 4)).1 = 0 ::ₘ 1 ::ₘ 2 ::ₘ 3 ::ₘ 0, from dec_trivial, simpa [finset.sum_eq_multiset_sum, fin4univ, multiset.sum_cons, f, add_assoc] end⟩ private lemma prime_sum_four_squares (p : ℕ) [hp : fact p.prime] : ∃ a b c d : ℤ, a^2 + b^2 + c^2 + d^2 = p := have hm : ∃ m < p, 0 < m ∧ ∃ a b c d : ℤ, a^2 + b^2 + c^2 + d^2 = m * p, from let ⟨a, b, k, hk⟩ := exists_sq_add_sq_add_one_eq_k p in ⟨k, hk.2, nat.pos_of_ne_zero $ (λ hk0, by { rw [hk0, int.coe_nat_zero, zero_mul] at hk, exact ne_of_gt (show a^2 + b^2 + 1 > 0, from add_pos_of_nonneg_of_pos (add_nonneg (sq_nonneg _) (sq_nonneg _)) zero_lt_one) hk.1 }), a, b, 1, 0, by simpa [sq] using hk.1⟩, let m := nat.find hm in let ⟨a, b, c, d, (habcd : a^2 + b^2 + c^2 + d^2 = m * p)⟩ := (nat.find_spec hm).snd.2 in by haveI hm0 : ne_zero m := ne_zero.of_pos (nat.find_spec hm).snd.1; exact have hmp : m < p, from (nat.find_spec hm).fst, m.mod_two_eq_zero_or_one.elim (λ hm2 : m % 2 = 0, let ⟨k, hk⟩ := nat.dvd_iff_mod_eq_zero.2 hm2 in have hk0 : 0 < k, from nat.pos_of_ne_zero $ λ _, by { simp [*, lt_irrefl] at * }, have hkm : k < m, { rw [hk, two_mul], exact (lt_add_iff_pos_left _).2 hk0 }, false.elim $ nat.find_min hm hkm ⟨lt_trans hkm hmp, hk0, sum_four_squares_of_two_mul_sum_four_squares (show a^2 + b^2 + c^2 + d^2 = 2 * (k * p), by { rw [habcd, hk, int.coe_nat_mul, mul_assoc], norm_num })⟩) (λ hm2 : m % 2 = 1, if hm1 : m = 1 then ⟨a, b, c, d, by simp only [hm1, habcd, int.coe_nat_one, one_mul]⟩ else let w := (a : zmod m).val_min_abs, x := (b : zmod m).val_min_abs, y := (c : zmod m).val_min_abs, z := (d : zmod m).val_min_abs in have hnat_abs : w^2 + x^2 + y^2 + z^2 = (w.nat_abs^2 + x.nat_abs^2 + y.nat_abs ^2 + z.nat_abs ^ 2 : ℕ), by simp [sq], have hwxyzlt : w^2 + x^2 + y^2 + z^2 < m^2, from calc w^2 + x^2 + y^2 + z^2 = (w.nat_abs^2 + x.nat_abs^2 + y.nat_abs ^2 + z.nat_abs ^ 2 : ℕ) : hnat_abs ... ≤ ((m / 2) ^ 2 + (m / 2) ^ 2 + (m / 2) ^ 2 + (m / 2) ^ 2 : ℕ) : int.coe_nat_le.2 $ add_le_add (add_le_add (add_le_add (nat.pow_le_pow_of_le_left (zmod.nat_abs_val_min_abs_le _) _) (nat.pow_le_pow_of_le_left (zmod.nat_abs_val_min_abs_le _) _)) (nat.pow_le_pow_of_le_left (zmod.nat_abs_val_min_abs_le _) _)) (nat.pow_le_pow_of_le_left (zmod.nat_abs_val_min_abs_le _) _) ... = 4 * (m / 2 : ℕ) ^ 2 : by simp [sq, bit0, bit1, mul_add, add_mul, add_assoc] ... < 4 * (m / 2 : ℕ) ^ 2 + ((4 * (m / 2) : ℕ) * (m % 2 : ℕ) + (m % 2 : ℕ)^2) : (lt_add_iff_pos_right _).2 (by { rw [hm2, int.coe_nat_one, one_pow, mul_one], exact add_pos_of_nonneg_of_pos (int.coe_nat_nonneg _) zero_lt_one }) ... = m ^ 2 : by { conv_rhs {rw [← nat.mod_add_div m 2]}, simp [-nat.mod_add_div, mul_add, add_mul, bit0, bit1, mul_comm, mul_assoc, mul_left_comm, pow_add, add_comm, add_left_comm] }, have hwxyzabcd : ((w^2 + x^2 + y^2 + z^2 : ℤ) : zmod m) = ((a^2 + b^2 + c^2 + d^2 : ℤ) : zmod m), by simp [w, x, y, z, sq], have hwxyz0 : ((w^2 + x^2 + y^2 + z^2 : ℤ) : zmod m) = 0, by rw [hwxyzabcd, habcd, int.cast_mul, cast_coe_nat, zmod.nat_cast_self, zero_mul], let ⟨n, hn⟩ := ((char_p.int_cast_eq_zero_iff _ m _).1 hwxyz0) in have hn0 : 0 < n.nat_abs, from int.nat_abs_pos_of_ne_zero (λ hn0, have hwxyz0 : (w.nat_abs^2 + x.nat_abs^2 + y.nat_abs^2 + z.nat_abs^2 : ℕ) = 0, by { rw [← int.coe_nat_eq_zero, ← hnat_abs], rwa [hn0, mul_zero] at hn }, have habcd0 : (m : ℤ) ∣ a ∧ (m : ℤ) ∣ b ∧ (m : ℤ) ∣ c ∧ (m : ℤ) ∣ d, by simpa [add_eq_zero_iff' (sq_nonneg (_ : ℤ)) (sq_nonneg _), pow_two, w, x, y, z, (char_p.int_cast_eq_zero_iff _ m _), and.assoc] using hwxyz0, let ⟨ma, hma⟩ := habcd0.1, ⟨mb, hmb⟩ := habcd0.2.1, ⟨mc, hmc⟩ := habcd0.2.2.1, ⟨md, hmd⟩ := habcd0.2.2.2 in have hmdvdp : m ∣ p, from int.coe_nat_dvd.1 ⟨ma^2 + mb^2 + mc^2 + md^2, (mul_right_inj' (show (m : ℤ) ≠ 0, from int.coe_nat_ne_zero.2 hm0.1)).1 $ by { rw [← habcd, hma, hmb, hmc, hmd], ring }⟩, (hp.1.eq_one_or_self_of_dvd _ hmdvdp).elim hm1 (λ hmeqp, by simpa [lt_irrefl, hmeqp] using hmp)), have hawbxcydz : ((m : ℕ) : ℤ) ∣ a * w + b * x + c * y + d * z, from (char_p.int_cast_eq_zero_iff (zmod m) m _).1 $ by { rw [← hwxyz0], simp, ring }, have haxbwczdy : ((m : ℕ) : ℤ) ∣ a * x - b * w - c * z + d * y, from (char_p.int_cast_eq_zero_iff (zmod m) m _).1 $ by { simp [sub_eq_add_neg], ring }, have haybzcwdx : ((m : ℕ) : ℤ) ∣ a * y + b * z - c * w - d * x, from (char_p.int_cast_eq_zero_iff (zmod m) m _).1 $ by { simp [sub_eq_add_neg], ring }, have hazbycxdw : ((m : ℕ) : ℤ) ∣ a * z - b * y + c * x - d * w, from (char_p.int_cast_eq_zero_iff (zmod m) m _).1 $ by { simp [sub_eq_add_neg], ring }, let ⟨s, hs⟩ := hawbxcydz, ⟨t, ht⟩ := haxbwczdy, ⟨u, hu⟩ := haybzcwdx, ⟨v, hv⟩ := hazbycxdw in have hn_nonneg : 0 ≤ n, from nonneg_of_mul_nonneg_right (by { erw [← hn], repeat {try {refine add_nonneg _ _}, try {exact sq_nonneg _}} }) (int.coe_nat_pos.2 $ ne_zero.pos m), have hnm : n.nat_abs < m, from int.coe_nat_lt.1 (lt_of_mul_lt_mul_left (by { rw [int.nat_abs_of_nonneg hn_nonneg, ← hn, ← sq], exact hwxyzlt }) (int.coe_nat_nonneg m)), have hstuv : s^2 + t^2 + u^2 + v^2 = n.nat_abs * p, from (mul_right_inj' (show (m^2 : ℤ) ≠ 0, from pow_ne_zero 2 (int.coe_nat_ne_zero.2 hm0.1))).1 $ calc (m : ℤ)^2 * (s^2 + t^2 + u^2 + v^2) = ((m : ℕ) * s)^2 + ((m : ℕ) * t)^2 + ((m : ℕ) * u)^2 + ((m : ℕ) * v)^2 : by { simp [mul_pow], ring } ... = (w^2 + x^2 + y^2 + z^2) * (a^2 + b^2 + c^2 + d^2) : by { simp only [hs.symm, ht.symm, hu.symm, hv.symm], ring } ... = _ : by { rw [hn, habcd, int.nat_abs_of_nonneg hn_nonneg], dsimp [m], ring }, false.elim $ nat.find_min hm hnm ⟨lt_trans hnm hmp, hn0, s, t, u, v, hstuv⟩) /-- **Four squares theorem** -/ lemma sum_four_squares : ∀ n : ℕ, ∃ a b c d : ℕ, a^2 + b^2 + c^2 + d^2 = n | 0 := ⟨0, 0, 0, 0, rfl⟩ | 1 := ⟨1, 0, 0, 0, rfl⟩ | n@(k+2) := have hm : fact (min_fac (k+2)).prime := ⟨min_fac_prime dec_trivial⟩, have n / min_fac n < n := factors_lemma, let ⟨a, b, c, d, h₁⟩ := show ∃ a b c d : ℤ, a^2 + b^2 + c^2 + d^2 = min_fac n, by exactI prime_sum_four_squares (min_fac (k+2)) in let ⟨w, x, y, z, h₂⟩ := sum_four_squares (n / min_fac n) in ⟨(a * w - b * x - c * y - d * z).nat_abs, (a * x + b * w + c * z - d * y).nat_abs, (a * y - b * z + c * w + d * x).nat_abs, (a * z + b * y - c * x + d * w).nat_abs, begin rw [← int.coe_nat_inj', ← nat.mul_div_cancel' (min_fac_dvd (k+2)), int.coe_nat_mul, ← h₁, ← h₂], simp [sum_four_sq_mul_sum_four_sq], end⟩ end nat
9a9b83f127f7c1108579d334b8866dad4afb7e7e
9dc8cecdf3c4634764a18254e94d43da07142918
/src/data/finset/noncomm_prod.lean
5cef6169bb93bfad108f303891256cd0e37fa24d
[ "Apache-2.0" ]
permissive
jcommelin/mathlib
d8456447c36c176e14d96d9e76f39841f69d2d9b
ee8279351a2e434c2852345c51b728d22af5a156
refs/heads/master
1,664,782,136,488
1,663,638,983,000
1,663,638,983,000
132,563,656
0
0
Apache-2.0
1,663,599,929,000
1,525,760,539,000
Lean
UTF-8
Lean
false
false
15,370
lean
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import algebra.big_operators.basic /-! # Products (respectively, sums) over a finset or a multiset. The regular `finset.prod` and `multiset.prod` require `[comm_monoid α]`. Often, there are collections `s : finset α` where `[monoid α]` and we know, in a dependent fashion, that for all the terms `∀ (x ∈ s) (y ∈ s), commute x y`. This allows to still have a well-defined product over `s`. ## Main definitions - `finset.noncomm_prod`, requiring a proof of commutativity of held terms - `multiset.noncomm_prod`, requiring a proof of commutativity of held terms ## Implementation details While `list.prod` is defined via `list.foldl`, `noncomm_prod` is defined via `multiset.foldr` for neater proofs and definitions. By the commutativity assumption, the two must be equal. -/ variables {α β γ : Type*} (f : α → β → β) (op : α → α → α) namespace multiset /-- Fold of a `s : multiset α` with `f : α → β → β`, given a proof that `left_commutative f` on all elements `x ∈ s`. -/ def noncomm_foldr (s : multiset α) (comm : ∀ (x ∈ s) (y ∈ s) b, f x (f y b) = f y (f x b)) (b : β) : β := s.attach.foldr (f ∘ subtype.val) (λ ⟨x, hx⟩ ⟨y, hy⟩, comm x hx y hy) b @[simp] lemma noncomm_foldr_coe (l : list α) (comm : ∀ (x ∈ (l : multiset α)) (y ∈ (l : multiset α)) b, f x (f y b) = f y (f x b)) (b : β) : noncomm_foldr f (l : multiset α) comm b = l.foldr f b := begin simp only [noncomm_foldr, coe_foldr, coe_attach, list.attach], rw ←list.foldr_map, simp [list.map_pmap, list.pmap_eq_map] end @[simp] lemma noncomm_foldr_empty (h : ∀ (x ∈ (0 : multiset α)) (y ∈ (0 : multiset α)) b, f x (f y b) = f y (f x b)) (b : β) : noncomm_foldr f (0 : multiset α) h b = b := rfl lemma noncomm_foldr_cons (s : multiset α) (a : α) (h : ∀ (x ∈ (a ::ₘ s)) (y ∈ (a ::ₘ s)) b, f x (f y b) = f y (f x b)) (h' : ∀ (x ∈ s) (y ∈ s) b, f x (f y b) = f y (f x b)) (b : β) : noncomm_foldr f (a ::ₘ s) h b = f a (noncomm_foldr f s h' b) := begin induction s using quotient.induction_on, simp end lemma noncomm_foldr_eq_foldr (s : multiset α) (h : left_commutative f) (b : β) : noncomm_foldr f s (λ x _ y _, h x y) b = foldr f h b s := begin induction s using quotient.induction_on, simp end variables [assoc : is_associative α op] include assoc /-- Fold of a `s : multiset α` with an associative `op : α → α → α`, given a proofs that `op` is commutative on all elements `x ∈ s`. -/ def noncomm_fold (s : multiset α) (comm : ∀ (x ∈ s) (y ∈ s), op x y = op y x) (a : α) : α := noncomm_foldr op s (λ x hx y hy b, by rw [←assoc.assoc, comm _ hx _ hy, assoc.assoc]) a @[simp] lemma noncomm_fold_coe (l : list α) (comm : ∀ (x ∈ (l : multiset α)) (y ∈ (l : multiset α)), op x y = op y x) (a : α) : noncomm_fold op (l : multiset α) comm a = l.foldr op a := by simp [noncomm_fold] @[simp] lemma noncomm_fold_empty (h : ∀ (x ∈ (0 : multiset α)) (y ∈ (0 : multiset α)), op x y = op y x) (a : α) : noncomm_fold op (0 : multiset α) h a = a := rfl lemma noncomm_fold_cons (s : multiset α) (a : α) (h : ∀ (x ∈ a ::ₘ s) (y ∈ a ::ₘ s), op x y = op y x) (h' : ∀ (x ∈ s) (y ∈ s), op x y = op y x) (x : α) : noncomm_fold op (a ::ₘ s) h x = op a (noncomm_fold op s h' x) := begin induction s using quotient.induction_on, simp end lemma noncomm_fold_eq_fold (s : multiset α) [is_commutative α op] (a : α) : noncomm_fold op s (λ x _ y _, is_commutative.comm x y) a = fold op a s := begin induction s using quotient.induction_on, simp end omit assoc variables [monoid α] [monoid β] /-- Product of a `s : multiset α` with `[monoid α]`, given a proof that `*` commutes on all elements `x ∈ s`. -/ @[to_additive "Sum of a `s : multiset α` with `[add_monoid α]`, given a proof that `+` commutes on all elements `x ∈ s`." ] def noncomm_prod (s : multiset α) (comm : ∀ (x ∈ s) (y ∈ s), commute x y) : α := s.noncomm_fold (*) comm 1 @[simp, to_additive] lemma noncomm_prod_coe (l : list α) (comm : ∀ (x ∈ (l : multiset α)) (y ∈ (l : multiset α)), commute x y) : noncomm_prod (l : multiset α) comm = l.prod := begin rw [noncomm_prod], simp only [noncomm_fold_coe], induction l with hd tl hl, { simp }, { rw [list.prod_cons, list.foldr, hl], intros x hx y hy, exact comm x (list.mem_cons_of_mem _ hx) y (list.mem_cons_of_mem _ hy) } end @[simp, to_additive] lemma noncomm_prod_empty (h : ∀ (x ∈ (0 : multiset α)) (y ∈ (0 : multiset α)), commute x y) : noncomm_prod (0 : multiset α) h = 1 := rfl @[simp, to_additive] lemma noncomm_prod_cons (s : multiset α) (a : α) (comm : ∀ (x ∈ a ::ₘ s) (y ∈ a ::ₘ s), commute x y) : noncomm_prod (a ::ₘ s) comm = a * noncomm_prod s (λ x hx y hy, comm _ (mem_cons_of_mem hx) _ (mem_cons_of_mem hy)) := begin induction s using quotient.induction_on, simp end @[to_additive] lemma noncomm_prod_cons' (s : multiset α) (a : α) (comm : ∀ (x ∈ a ::ₘ s) (y ∈ a ::ₘ s), commute x y) : noncomm_prod (a ::ₘ s) comm = noncomm_prod s (λ x hx y hy, comm _ (mem_cons_of_mem hx) _ (mem_cons_of_mem hy)) * a := begin induction s using quotient.induction_on with s, simp only [quot_mk_to_coe, cons_coe, noncomm_prod_coe, list.prod_cons], induction s with hd tl IH, { simp }, { rw [list.prod_cons, mul_assoc, ←IH, ←mul_assoc, ←mul_assoc], { congr' 1, apply comm; simp }, { intros x hx y hy, simp only [quot_mk_to_coe, list.mem_cons_iff, mem_coe, cons_coe] at hx hy, apply comm, { cases hx; simp [hx] }, { cases hy; simp [hy] } } } end @[protected, to_additive] lemma nocomm_prod_map_aux (s : multiset α) (comm : ∀ (x ∈ s) (y ∈ s), commute x y) {F : Type*} [monoid_hom_class F α β] (f : F) : ∀ (x ∈ s.map f) (y ∈ s.map f), commute x y := begin simp only [multiset.mem_map], rintros _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩, exact (comm _ hx _ hy).map f, end @[to_additive] lemma noncomm_prod_map (s : multiset α) (comm : ∀ (x ∈ s) (y ∈ s), commute x y) {F : Type*} [monoid_hom_class F α β] (f : F) : f (s.noncomm_prod comm) = (s.map f).noncomm_prod (nocomm_prod_map_aux s comm f) := begin induction s using quotient.induction_on, simpa using map_list_prod f _, end @[to_additive noncomm_sum_eq_card_nsmul] lemma noncomm_prod_eq_pow_card (s : multiset α) (comm : ∀ (x ∈ s) (y ∈ s), commute x y) (m : α) (h : ∀ (x ∈ s), x = m) : s.noncomm_prod comm = m ^ s.card := begin induction s using quotient.induction_on, simp only [quot_mk_to_coe, noncomm_prod_coe, coe_card, mem_coe] at *, exact list.prod_eq_pow_card _ m h, end @[to_additive] lemma noncomm_prod_eq_prod {α : Type*} [comm_monoid α] (s : multiset α) : noncomm_prod s (λ _ _ _ _, commute.all _ _) = prod s := begin induction s using quotient.induction_on, simp end @[to_additive noncomm_sum_add_commute] lemma noncomm_prod_commute (s : multiset α) (comm : ∀ (x : α), x ∈ s → ∀ (y : α), y ∈ s → commute x y) (y : α) (h : ∀ (x : α), x ∈ s → commute y x) : commute y (s.noncomm_prod comm) := begin induction s using quotient.induction_on, simp only [quot_mk_to_coe, noncomm_prod_coe], exact commute.list_prod_right _ _ h, end end multiset namespace finset variables [monoid β] [monoid γ] /-- Product of a `s : finset α` mapped with `f : α → β` with `[monoid β]`, given a proof that `*` commutes on all elements `f x` for `x ∈ s`. -/ @[to_additive "Sum of a `s : finset α` mapped with `f : α → β` with `[add_monoid β]`, given a proof that `+` commutes on all elements `f x` for `x ∈ s`."] def noncomm_prod (s : finset α) (f : α → β) (comm : ∀ (x ∈ s) (y ∈ s), commute (f x) (f y)) : β := (s.1.map f).noncomm_prod (by simpa [multiset.mem_map, ←finset.mem_def] using comm) @[congr, to_additive] lemma noncomm_prod_congr {s₁ s₂ : finset α} {f g : α → β} (h₁ : s₁ = s₂) (h₂ : ∀ (x ∈ s₂), f x = g x) (comm : ∀ (x ∈ s₁) (y ∈ s₁), commute (f x) (f y)) : noncomm_prod s₁ f comm = noncomm_prod s₂ g (λ x hx y hy, h₂ x hx ▸ h₂ y hy ▸ comm x (h₁.symm ▸ hx) y (h₁.symm ▸ hy)) := by simp_rw [noncomm_prod, multiset.map_congr (congr_arg _ h₁) h₂] @[simp, to_additive] lemma noncomm_prod_to_finset [decidable_eq α] (l : list α) (f : α → β) (comm : ∀ (x ∈ l.to_finset) (y ∈ l.to_finset), commute (f x) (f y)) (hl : l.nodup) : noncomm_prod l.to_finset f comm = (l.map f).prod := begin rw ←list.dedup_eq_self at hl, simp [noncomm_prod, hl] end @[simp, to_additive] lemma noncomm_prod_empty (f : α → β) (h : ∀ (x ∈ (∅ : finset α)) (y ∈ (∅ : finset α)), commute (f x) (f y)) : noncomm_prod (∅ : finset α) f h = 1 := rfl @[simp, to_additive] lemma noncomm_prod_insert_of_not_mem [decidable_eq α] (s : finset α) (a : α) (f : α → β) (comm : ∀ (x ∈ insert a s) (y ∈ insert a s), commute (f x) (f y)) (ha : a ∉ s) : noncomm_prod (insert a s) f comm = f a * noncomm_prod s f (λ x hx y hy, comm _ (mem_insert_of_mem hx) _ (mem_insert_of_mem hy)) := by simp [insert_val_of_not_mem ha, noncomm_prod] @[to_additive] lemma noncomm_prod_insert_of_not_mem' [decidable_eq α] (s : finset α) (a : α) (f : α → β) (comm : ∀ (x ∈ insert a s) (y ∈ insert a s), commute (f x) (f y)) (ha : a ∉ s) : noncomm_prod (insert a s) f comm = noncomm_prod s f (λ x hx y hy, comm _ (mem_insert_of_mem hx) _ (mem_insert_of_mem hy)) * f a := by simp [noncomm_prod, insert_val_of_not_mem ha, multiset.noncomm_prod_cons'] @[simp, to_additive] lemma noncomm_prod_singleton (a : α) (f : α → β) : noncomm_prod ({a} : finset α) f (λ x hx y hy, by rw [mem_singleton.mp hx, mem_singleton.mp hy]) = f a := by simp [noncomm_prod, ←multiset.cons_zero] @[to_additive] lemma noncomm_prod_map (s : finset α) (f : α → β) (comm : ∀ (x : α), x ∈ s → ∀ (y : α), y ∈ s → commute (f x) (f y)) {F : Type*} [monoid_hom_class F β γ] (g : F) : g (s.noncomm_prod f comm) = s.noncomm_prod (λ i, g (f i)) (λ x hx y hy, (comm x hx y hy).map g) := by simp [noncomm_prod, multiset.noncomm_prod_map] @[to_additive noncomm_sum_eq_card_nsmul] lemma noncomm_prod_eq_pow_card (s : finset α) (f : α → β) (comm : ∀ (x : α), x ∈ s → ∀ (y : α), y ∈ s → commute (f x) (f y)) (m : β) (h : ∀ (x : α), x ∈ s → f x = m) : s.noncomm_prod f comm = m ^ s.card := begin rw [noncomm_prod, multiset.noncomm_prod_eq_pow_card _ _ m], simp only [finset.card_def, multiset.card_map], simpa using h, end @[to_additive noncomm_sum_add_commute] lemma noncomm_prod_commute (s : finset α) (f : α → β) (comm : ∀ (x : α), x ∈ s → ∀ (y : α), y ∈ s → commute (f x) (f y)) (y : β) (h : ∀ (x : α), x ∈ s → commute y (f x)) : commute y (s.noncomm_prod f comm) := begin apply multiset.noncomm_prod_commute, intro y, rw multiset.mem_map, rintros ⟨x, ⟨hx, rfl⟩⟩, exact h x hx, end @[to_additive] lemma noncomm_prod_eq_prod {β : Type*} [comm_monoid β] (s : finset α) (f : α → β) : noncomm_prod s f (λ _ _ _ _, commute.all _ _) = s.prod f := begin classical, induction s using finset.induction_on with a s ha IH, { simp }, { simp [ha, IH] } end /- The non-commutative version of `finset.prod_union` -/ @[to_additive "The non-commutative version of `finset.sum_union`"] lemma noncomm_prod_union_of_disjoint [decidable_eq α] {s t : finset α} (h : disjoint s t) (f : α → β) (comm : ∀ (x ∈ s ∪ t) (y ∈ s ∪ t), commute (f x) (f y)) (scomm : ∀ (x ∈ s) (y ∈ s), commute (f x) (f y) := λ _ hx _ hy, comm _ (mem_union_left _ hx) _ (mem_union_left _ hy)) (tcomm : ∀ (x ∈ t) (y ∈ t), commute (f x) (f y) := λ _ hx _ hy, comm _ (mem_union_right _ hx) _ (mem_union_right _ hy)) : noncomm_prod (s ∪ t) f comm = noncomm_prod s f scomm * noncomm_prod t f tcomm := begin obtain ⟨sl, sl', rfl⟩ := exists_list_nodup_eq s, obtain ⟨tl, tl', rfl⟩ := exists_list_nodup_eq t, rw list.disjoint_to_finset_iff_disjoint at h, simp [sl', tl', noncomm_prod_to_finset, ←list.prod_append, ←list.to_finset_append, sl'.append tl' h] end @[protected, to_additive] lemma noncomm_prod_mul_distrib_aux {s : finset α} {f : α → β} {g : α → β} (comm_ff : ∀ (x ∈ s) (y ∈ s), commute (f x) (f y)) (comm_gg : ∀ (x ∈ s) (y ∈ s), commute (g x) (g y)) (comm_gf : ∀ (x ∈ s) (y ∈ s), x ≠ y → commute (g x) (f y)) : (∀ (x ∈ s) (y ∈ s), commute ((f * g) x) ((f * g) y)) := begin intros x hx y hy, by_cases h : x = y, { subst h }, apply commute.mul_left; apply commute.mul_right, { exact comm_ff x hx y hy }, { exact (comm_gf y hy x hx (ne.symm h)).symm }, { exact comm_gf x hx y hy h }, { exact comm_gg x hx y hy }, end /-- The non-commutative version of `finset.prod_mul_distrib` -/ @[to_additive "The non-commutative version of `finset.sum_add_distrib`"] lemma noncomm_prod_mul_distrib {s : finset α} (f : α → β) (g : α → β) (comm_ff : ∀ (x ∈ s) (y ∈ s), commute (f x) (f y)) (comm_gg : ∀ (x ∈ s) (y ∈ s), commute (g x) (g y)) (comm_gf : ∀ (x ∈ s) (y ∈ s), x ≠ y → commute (g x) (f y)) : noncomm_prod s (f * g) (noncomm_prod_mul_distrib_aux comm_ff comm_gg comm_gf) = noncomm_prod s f comm_ff * noncomm_prod s g comm_gg := begin classical, induction s using finset.induction_on with x s hnmem ih, { simp, }, { simp only [finset.noncomm_prod_insert_of_not_mem _ _ _ _ hnmem], specialize ih (λ x hx y hy, comm_ff x (mem_insert_of_mem hx) y (mem_insert_of_mem hy)) (λ x hx y hy, comm_gg x (mem_insert_of_mem hx) y (mem_insert_of_mem hy)) (λ x hx y hy hne, comm_gf x (mem_insert_of_mem hx) y (mem_insert_of_mem hy) hne), rw [ih, pi.mul_apply], simp only [mul_assoc], congr' 1, simp only [← mul_assoc], congr' 1, apply noncomm_prod_commute, intros y hy, have : x ≠ y, by {rintro rfl, contradiction}, exact comm_gf x (mem_insert_self x s) y (mem_insert_of_mem hy) this, } end section finite_pi variables {ι : Type*} [fintype ι] [decidable_eq ι] {M : ι → Type*} [∀ i, monoid (M i)] variables (x : Π i, M i) @[to_additive] lemma noncomm_prod_mul_single : univ.noncomm_prod (λ i, pi.mul_single i (x i)) (λ i _ j _, pi.mul_single_apply_commute x i j) = x := begin ext i, apply (univ.noncomm_prod_map (λ i, monoid_hom.single M i (x i)) _ (pi.eval_monoid_hom M i)).trans, rw [ ← insert_erase (mem_univ i), noncomm_prod_insert_of_not_mem' _ _ _ _ (not_mem_erase _ _), noncomm_prod_eq_pow_card, one_pow], { simp, }, { intros i h, simp at h, simp [h], }, end @[to_additive] lemma _root_.monoid_hom.pi_ext {f g : (Π i, M i) →* γ} (h : ∀ i x, f (pi.mul_single i x) = g (pi.mul_single i x)) : f = g := begin ext x, rw [← noncomm_prod_mul_single x, univ.noncomm_prod_map, univ.noncomm_prod_map], congr' 1 with i, exact h i (x i), end end finite_pi end finset
5d2f68260e29473214da61c9cb3016c980fe7548
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/classBadOutParam.lean
5f3b9c725049b778a9675a7ccf244bcf4e6d4135
[ "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
203
lean
class C1 (x : outParam Nat) (y : { n : Nat // n > x }) (α : Type) := -- should fail (val : α) class C2 (x : outParam Nat) (y : outParam { n : Nat // n > x }) (α : Type) := -- should work (val : α)
1e25231529f72b80acd7f26c100d63929b3c5d8d
35677d2df3f081738fa6b08138e03ee36bc33cad
/src/category_theory/core.lean
8e5476ca4cea88ff0e3f7705600810aebaab8ef6
[ "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
2,364
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.groupoid import category_theory.whiskering import category.equiv_functor import category_theory.types namespace category_theory universes v₁ v₂ u₁ u₂ -- declare the `v`'s first; see `category_theory.category` for an explanation /-- The core of a category C is the groupoid whose morphisms are all the isomorphisms of C. -/ def core (C : Type u₁) := C variables {C : Type u₁} [𝒞 : category.{v₁} C] include 𝒞 instance core_category : groupoid.{v₁} (core C) := { hom := λ X Y : C, X ≅ Y, inv := λ X Y f, iso.symm f, id := λ X, iso.refl X, comp := λ X Y Z f g, iso.trans f g } namespace core @[simp] lemma id_hom (X : core C) : iso.hom (𝟙 X) = 𝟙 X := rfl @[simp] lemma comp_hom {X Y Z : core C} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).hom = f.hom ≫ g.hom := rfl /-- The core of a category is naturally included in the category. -/ def inclusion : core C ⥤ C := { obj := id, map := λ X Y f, f.hom } variables {G : Type u₂} [𝒢 : groupoid.{v₂} G] include 𝒢 /-- A functor from a groupoid to a category C factors through the core of C. -/ -- Note that this function is not functorial -- (consider the two functors from [0] to [1], and the natural transformation between them). def functor_to_core (F : G ⥤ C) : G ⥤ core C := { obj := λ X, F.obj X, map := λ X Y f, ⟨F.map f, F.map (inv f)⟩ } def forget_functor_to_core : (G ⥤ core C) ⥤ (G ⥤ C) := (whiskering_right _ _ _).obj inclusion end core omit 𝒞 /-- `of_equiv_functor m` lifts a type-level `equiv_functor` to a categorical functor `core (Type u₁) ⥤ core (Type u₂)`. -/ def of_equiv_functor (m : Type u₁ → Type u₂) [equiv_functor m] : core (Type u₁) ⥤ core (Type u₂) := { obj := m, map := λ α β f, (equiv_functor.map_equiv m f.to_equiv).to_iso, -- These are not very pretty. map_id' := λ α, begin ext, exact (congr_fun (equiv_functor.map_refl _) x), end, map_comp' := λ α β γ f g, begin ext, simp only [equiv_functor.map_equiv_apply, equiv.to_iso_hom, function.comp_app, core.comp_hom, types_comp], erw [iso.to_equiv_comp, equiv_functor.map_trans], end, } end category_theory
efd486e3b9e485258475f691f174182718d5d281
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/tactic/omega/nat/neg_elim_auto.lean
652cebe37c4e70679faa75768ea213f4c3639411
[]
no_license
AurelienSaue/Mathlib4_auto
f538cfd0980f65a6361eadea39e6fc639e9dae14
590df64109b08190abe22358fabc3eae000943f2
refs/heads/master
1,683,906,849,776
1,622,564,669,000
1,622,564,669,000
371,723,747
0
0
null
null
null
null
UTF-8
Lean
false
false
1,834
lean
/- Copyright (c) 2019 Seul Baek. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Seul Baek -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.tactic.omega.nat.form import Mathlib.PostPort namespace Mathlib /- Negation elimination. -/ namespace omega namespace nat /-- push_neg p returns the result of normalizing ¬ p by pushing the outermost negation all the way down, until it reaches either a negation or an atom -/ @[simp] def push_neg : preform → preform := sorry theorem push_neg_equiv {p : preform} : preform.equiv (push_neg p) (preform.not p) := sorry /-- NNF transformation -/ def nnf : preform → preform := sorry /-- Asserts that the given preform is in NNF -/ def is_nnf : preform → Prop := sorry theorem is_nnf_push_neg (p : preform) : is_nnf p → is_nnf (push_neg p) := sorry theorem is_nnf_nnf (p : preform) : is_nnf (nnf p) := sorry theorem nnf_equiv {p : preform} : preform.equiv (nnf p) p := sorry @[simp] def neg_elim_core : preform → preform := sorry theorem neg_free_neg_elim_core (p : preform) : is_nnf p → preform.neg_free (neg_elim_core p) := sorry theorem le_and_le_iff_eq {α : Type} [partial_order α] {a : α} {b : α} : a ≤ b ∧ b ≤ a ↔ a = b := sorry theorem implies_neg_elim_core {p : preform} : preform.implies p (neg_elim_core p) := sorry /-- Eliminate all negations in a preform -/ def neg_elim : preform → preform := neg_elim_core ∘ nnf theorem neg_free_neg_elim {p : preform} : preform.neg_free (neg_elim p) := neg_free_neg_elim_core (nnf p) (is_nnf_nnf p) theorem implies_neg_elim {p : preform} : preform.implies p (neg_elim p) := id fun (v : ℕ → ℕ) (h1 : preform.holds v p) => implies_neg_elim_core v (iff.elim_right (nnf_equiv v) h1) end Mathlib
c5cdb2ec8b738de448acb139c473dba31cd72625
4727251e0cd73359b15b664c3170e5d754078599
/src/category_theory/limits/is_limit.lean
9b220c75b965ffca12fe7c7ed9998141054ce782
[ "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
38,205
lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Scott Morrison, Floris van Doorn -/ import category_theory.adjunction.basic import category_theory.limits.cones /-! # Limits and colimits We set up the general theory of limits and colimits in a category. In this introduction we only describe the setup for limits; it is repeated, with slightly different names, for colimits. The main structures defined in this file is * `is_limit c`, for `c : cone F`, `F : J ⥤ C`, expressing that `c` is a limit cone, See also `category_theory.limits.has_limits` which further builds: * `limit_cone F`, which consists of a choice of cone for `F` and the fact it is a limit cone, and * `has_limit F`, asserting the mere existence of some limit cone for `F`. ## Implementation At present we simply say everything twice, in order to handle both limits and colimits. It would be highly desirable to have some automation support, e.g. a `@[dualize]` attribute that behaves similarly to `@[to_additive]`. ## References * [Stacks: Limits and colimits](https://stacks.math.columbia.edu/tag/002D) -/ noncomputable theory open category_theory category_theory.category category_theory.functor opposite namespace category_theory.limits -- declare the `v`'s first; see `category_theory.category` for an explanation universes v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ variables {J : Type u₁} [category.{v₁} J] {K : Type u₂} [category.{v₂} K] variables {C : Type u₃} [category.{v₃} C] variables {F : J ⥤ C} /-- A cone `t` on `F` is a limit cone if each cone on `F` admits a unique cone morphism to `t`. See <https://stacks.math.columbia.edu/tag/002E>. -/ @[nolint has_inhabited_instance] structure is_limit (t : cone F) := (lift : Π (s : cone F), s.X ⟶ t.X) (fac' : ∀ (s : cone F) (j : J), lift s ≫ t.π.app j = s.π.app j . obviously) (uniq' : ∀ (s : cone F) (m : s.X ⟶ t.X) (w : ∀ j : J, m ≫ t.π.app j = s.π.app j), m = lift s . obviously) restate_axiom is_limit.fac' attribute [simp, reassoc] is_limit.fac restate_axiom is_limit.uniq' namespace is_limit instance subsingleton {t : cone F} : subsingleton (is_limit t) := ⟨by intros P Q; cases P; cases Q; congr; ext; solve_by_elim⟩ /-- Given a natural transformation `α : F ⟶ G`, we give a morphism from the cone point of any cone over `F` to the cone point of a limit cone over `G`. -/ def map {F G : J ⥤ C} (s : cone F) {t : cone G} (P : is_limit t) (α : F ⟶ G) : s.X ⟶ t.X := P.lift ((cones.postcompose α).obj s) @[simp, reassoc] lemma map_π {F G : J ⥤ C} (c : cone F) {d : cone G} (hd : is_limit d) (α : F ⟶ G) (j : J) : hd.map c α ≫ d.π.app j = c.π.app j ≫ α.app j := fac _ _ _ lemma lift_self {c : cone F} (t : is_limit c) : t.lift c = 𝟙 c.X := (t.uniq _ _ (λ j, id_comp _)).symm /- Repackaging the definition in terms of cone morphisms. -/ /-- The universal morphism from any other cone to a limit cone. -/ @[simps] def lift_cone_morphism {t : cone F} (h : is_limit t) (s : cone F) : s ⟶ t := { hom := h.lift s } lemma uniq_cone_morphism {s t : cone F} (h : is_limit t) {f f' : s ⟶ t} : f = f' := have ∀ {g : s ⟶ t}, g = h.lift_cone_morphism s, by intro g; ext; exact h.uniq _ _ g.w, this.trans this.symm /-- Restating the definition of a limit cone in terms of the ∃! operator. -/ lemma exists_unique {t : cone F} (h : is_limit t) (s : cone F) : ∃! (l : s.X ⟶ t.X), ∀ j, l ≫ t.π.app j = s.π.app j := ⟨h.lift s, h.fac s, h.uniq s⟩ /-- Noncomputably make a colimit cocone from the existence of unique factorizations. -/ def of_exists_unique {t : cone F} (ht : ∀ s : cone F, ∃! l : s.X ⟶ t.X, ∀ j, l ≫ t.π.app j = s.π.app j) : is_limit t := by { choose s hs hs' using ht, exact ⟨s, hs, hs'⟩ } /-- Alternative constructor for `is_limit`, providing a morphism of cones rather than a morphism between the cone points and separately the factorisation condition. -/ @[simps] def mk_cone_morphism {t : cone F} (lift : Π (s : cone F), s ⟶ t) (uniq' : ∀ (s : cone F) (m : s ⟶ t), m = lift s) : is_limit t := { lift := λ s, (lift s).hom, uniq' := λ s m w, have cone_morphism.mk m w = lift s, by apply uniq', congr_arg cone_morphism.hom this } /-- Limit cones on `F` are unique up to isomorphism. -/ @[simps] def unique_up_to_iso {s t : cone F} (P : is_limit s) (Q : is_limit t) : s ≅ t := { hom := Q.lift_cone_morphism s, inv := P.lift_cone_morphism t, hom_inv_id' := P.uniq_cone_morphism, inv_hom_id' := Q.uniq_cone_morphism } /-- Any cone morphism between limit cones is an isomorphism. -/ lemma hom_is_iso {s t : cone F} (P : is_limit s) (Q : is_limit t) (f : s ⟶ t) : is_iso f := ⟨⟨P.lift_cone_morphism t, ⟨P.uniq_cone_morphism, Q.uniq_cone_morphism⟩⟩⟩ /-- Limits of `F` are unique up to isomorphism. -/ def cone_point_unique_up_to_iso {s t : cone F} (P : is_limit s) (Q : is_limit t) : s.X ≅ t.X := (cones.forget F).map_iso (unique_up_to_iso P Q) @[simp, reassoc] lemma cone_point_unique_up_to_iso_hom_comp {s t : cone F} (P : is_limit s) (Q : is_limit t) (j : J) : (cone_point_unique_up_to_iso P Q).hom ≫ t.π.app j = s.π.app j := (unique_up_to_iso P Q).hom.w _ @[simp, reassoc] lemma cone_point_unique_up_to_iso_inv_comp {s t : cone F} (P : is_limit s) (Q : is_limit t) (j : J) : (cone_point_unique_up_to_iso P Q).inv ≫ s.π.app j = t.π.app j := (unique_up_to_iso P Q).inv.w _ @[simp, reassoc] lemma lift_comp_cone_point_unique_up_to_iso_hom {r s t : cone F} (P : is_limit s) (Q : is_limit t) : P.lift r ≫ (cone_point_unique_up_to_iso P Q).hom = Q.lift r := Q.uniq _ _ (by simp) @[simp, reassoc] lemma lift_comp_cone_point_unique_up_to_iso_inv {r s t : cone F} (P : is_limit s) (Q : is_limit t) : Q.lift r ≫ (cone_point_unique_up_to_iso P Q).inv = P.lift r := P.uniq _ _ (by simp) /-- Transport evidence that a cone is a limit cone across an isomorphism of cones. -/ def of_iso_limit {r t : cone F} (P : is_limit r) (i : r ≅ t) : is_limit t := is_limit.mk_cone_morphism (λ s, P.lift_cone_morphism s ≫ i.hom) (λ s m, by rw ←i.comp_inv_eq; apply P.uniq_cone_morphism) @[simp] lemma of_iso_limit_lift {r t : cone F} (P : is_limit r) (i : r ≅ t) (s) : (P.of_iso_limit i).lift s = P.lift s ≫ i.hom.hom := rfl /-- Isomorphism of cones preserves whether or not they are limiting cones. -/ def equiv_iso_limit {r t : cone F} (i : r ≅ t) : is_limit r ≃ is_limit t := { to_fun := λ h, h.of_iso_limit i, inv_fun := λ h, h.of_iso_limit i.symm, left_inv := by tidy, right_inv := by tidy } @[simp] lemma equiv_iso_limit_apply {r t : cone F} (i : r ≅ t) (P : is_limit r) : equiv_iso_limit i P = P.of_iso_limit i := rfl @[simp] lemma equiv_iso_limit_symm_apply {r t : cone F} (i : r ≅ t) (P : is_limit t) : (equiv_iso_limit i).symm P = P.of_iso_limit i.symm := rfl /-- If the canonical morphism from a cone point to a limiting cone point is an iso, then the first cone was limiting also. -/ def of_point_iso {r t : cone F} (P : is_limit r) [i : is_iso (P.lift t)] : is_limit t := of_iso_limit P begin haveI : is_iso (P.lift_cone_morphism t).hom := i, haveI : is_iso (P.lift_cone_morphism t) := cones.cone_iso_of_hom_iso _, symmetry, apply as_iso (P.lift_cone_morphism t), end variables {t : cone F} lemma hom_lift (h : is_limit t) {W : C} (m : W ⟶ t.X) : m = h.lift { X := W, π := { app := λ b, m ≫ t.π.app b } } := h.uniq { X := W, π := { app := λ b, m ≫ t.π.app b } } m (λ b, rfl) /-- Two morphisms into a limit are equal if their compositions with each cone morphism are equal. -/ lemma hom_ext (h : is_limit t) {W : C} {f f' : W ⟶ t.X} (w : ∀ j, f ≫ t.π.app j = f' ≫ t.π.app j) : f = f' := by rw [h.hom_lift f, h.hom_lift f']; congr; exact funext w /-- Given a right adjoint functor between categories of cones, the image of a limit cone is a limit cone. -/ def of_right_adjoint {D : Type u₄} [category.{v₄} D] {G : K ⥤ D} (h : cone G ⥤ cone F) [is_right_adjoint h] {c : cone G} (t : is_limit c) : is_limit (h.obj c) := mk_cone_morphism (λ s, (adjunction.of_right_adjoint h).hom_equiv s c (t.lift_cone_morphism _)) (λ s m, (adjunction.eq_hom_equiv_apply _ _ _).2 t.uniq_cone_morphism) /-- Given two functors which have equivalent categories of cones, we can transport a limiting cone across the equivalence. -/ def of_cone_equiv {D : Type u₄} [category.{v₄} D] {G : K ⥤ D} (h : cone G ≌ cone F) {c : cone G} : is_limit (h.functor.obj c) ≃ is_limit c := { to_fun := λ P, of_iso_limit (of_right_adjoint h.inverse P) (h.unit_iso.symm.app c), inv_fun := of_right_adjoint h.functor, left_inv := by tidy, right_inv := by tidy, } @[simp] lemma of_cone_equiv_apply_desc {D : Type u₄} [category.{v₄} D] {G : K ⥤ D} (h : cone G ≌ cone F) {c : cone G} (P : is_limit (h.functor.obj c)) (s) : (of_cone_equiv h P).lift s = ((h.unit_iso.hom.app s).hom ≫ (h.functor.inv.map (P.lift_cone_morphism (h.functor.obj s))).hom) ≫ (h.unit_iso.inv.app c).hom := rfl @[simp] lemma of_cone_equiv_symm_apply_desc {D : Type u₄} [category.{v₄} D] {G : K ⥤ D} (h : cone G ≌ cone F) {c : cone G} (P : is_limit c) (s) : ((of_cone_equiv h).symm P).lift s = (h.counit_iso.inv.app s).hom ≫ (h.functor.map (P.lift_cone_morphism (h.inverse.obj s))).hom := rfl /-- A cone postcomposed with a natural isomorphism is a limit cone if and only if the original cone is. -/ def postcompose_hom_equiv {F G : J ⥤ C} (α : F ≅ G) (c : cone F) : is_limit ((cones.postcompose α.hom).obj c) ≃ is_limit c := of_cone_equiv (cones.postcompose_equivalence α) /-- A cone postcomposed with the inverse of a natural isomorphism is a limit cone if and only if the original cone is. -/ def postcompose_inv_equiv {F G : J ⥤ C} (α : F ≅ G) (c : cone G) : is_limit ((cones.postcompose α.inv).obj c) ≃ is_limit c := postcompose_hom_equiv α.symm c /-- Constructing an equivalence `is_limit c ≃ is_limit d` from a natural isomorphism between the underlying functors, and then an isomorphism between `c` transported along this and `d`. -/ def equiv_of_nat_iso_of_iso {F G : J ⥤ C} (α : F ≅ G) (c : cone F) (d : cone G) (w : (cones.postcompose α.hom).obj c ≅ d) : is_limit c ≃ is_limit d := (postcompose_hom_equiv α _).symm.trans (equiv_iso_limit w) /-- The cone points of two limit cones for naturally isomorphic functors are themselves isomorphic. -/ @[simps] def cone_points_iso_of_nat_iso {F G : J ⥤ C} {s : cone F} {t : cone G} (P : is_limit s) (Q : is_limit t) (w : F ≅ G) : s.X ≅ t.X := { hom := Q.map s w.hom, inv := P.map t w.inv, hom_inv_id' := P.hom_ext (by tidy), inv_hom_id' := Q.hom_ext (by tidy), } @[reassoc] lemma cone_points_iso_of_nat_iso_hom_comp {F G : J ⥤ C} {s : cone F} {t : cone G} (P : is_limit s) (Q : is_limit t) (w : F ≅ G) (j : J) : (cone_points_iso_of_nat_iso P Q w).hom ≫ t.π.app j = s.π.app j ≫ w.hom.app j := by simp @[reassoc] lemma cone_points_iso_of_nat_iso_inv_comp {F G : J ⥤ C} {s : cone F} {t : cone G} (P : is_limit s) (Q : is_limit t) (w : F ≅ G) (j : J) : (cone_points_iso_of_nat_iso P Q w).inv ≫ s.π.app j = t.π.app j ≫ w.inv.app j := by simp @[reassoc] lemma lift_comp_cone_points_iso_of_nat_iso_hom {F G : J ⥤ C} {r s : cone F} {t : cone G} (P : is_limit s) (Q : is_limit t) (w : F ≅ G) : P.lift r ≫ (cone_points_iso_of_nat_iso P Q w).hom = Q.map r w.hom := Q.hom_ext (by simp) @[reassoc] lemma lift_comp_cone_points_iso_of_nat_iso_inv {F G : J ⥤ C} {r s : cone G} {t : cone F} (P : is_limit t) (Q : is_limit s) (w : F ≅ G) : Q.lift r ≫ (cone_points_iso_of_nat_iso P Q w).inv = P.map r w.inv := P.hom_ext (by simp) section equivalence open category_theory.equivalence /-- If `s : cone F` is a limit cone, so is `s` whiskered by an equivalence `e`. -/ def whisker_equivalence {s : cone F} (P : is_limit s) (e : K ≌ J) : is_limit (s.whisker e.functor) := of_right_adjoint (cones.whiskering_equivalence e).functor P /-- If `s : cone F` whiskered by an equivalence `e` is a limit cone, so is `s`. -/ def of_whisker_equivalence {s : cone F} (e : K ≌ J) (P : is_limit (s.whisker e.functor)) : is_limit s := equiv_iso_limit ((cones.whiskering_equivalence e).unit_iso.app s).symm (of_right_adjoint (cones.whiskering_equivalence e).inverse P : _) /-- Given an equivalence of diagrams `e`, `s` is a limit cone iff `s.whisker e.functor` is. -/ def whisker_equivalence_equiv {s : cone F} (e : K ≌ J) : is_limit s ≃ is_limit (s.whisker e.functor) := ⟨λ h, h.whisker_equivalence e, of_whisker_equivalence e, by tidy, by tidy⟩ /-- We can prove two cone points `(s : cone F).X` and `(t.cone G).X` are isomorphic if * both cones are limit cones * their indexing categories are equivalent via some `e : J ≌ K`, * the triangle of functors commutes up to a natural isomorphism: `e.functor ⋙ G ≅ F`. This is the most general form of uniqueness of cone points, allowing relabelling of both the indexing category (up to equivalence) and the functor (up to natural isomorphism). -/ @[simps] def cone_points_iso_of_equivalence {F : J ⥤ C} {s : cone F} {G : K ⥤ C} {t : cone G} (P : is_limit s) (Q : is_limit t) (e : J ≌ K) (w : e.functor ⋙ G ≅ F) : s.X ≅ t.X := let w' : e.inverse ⋙ F ≅ G := (iso_whisker_left e.inverse w).symm ≪≫ inv_fun_id_assoc e G in { hom := Q.lift ((cones.equivalence_of_reindexing e.symm w').functor.obj s), inv := P.lift ((cones.equivalence_of_reindexing e w).functor.obj t), hom_inv_id' := begin apply hom_ext P, intros j, dsimp, simp only [limits.cone.whisker_π, limits.cones.postcompose_obj_π, fac, whisker_left_app, assoc, id_comp, inv_fun_id_assoc_hom_app, fac_assoc, nat_trans.comp_app], rw [counit_app_functor, ←functor.comp_map, w.hom.naturality], simp, end, inv_hom_id' := by { apply hom_ext Q, tidy, }, } end equivalence /-- The universal property of a limit cone: a map `W ⟶ X` is the same as a cone on `F` with vertex `W`. -/ def hom_iso (h : is_limit t) (W : C) : ulift.{u₁} (W ⟶ t.X : Type v₃) ≅ (const J).obj W ⟶ F := { hom := λ f, (t.extend f.down).π, inv := λ π, ⟨h.lift { X := W, π := π }⟩, hom_inv_id' := by ext f; apply h.hom_ext; intro j; simp; dsimp; refl } @[simp] lemma hom_iso_hom (h : is_limit t) {W : C} (f : ulift.{u₁} (W ⟶ t.X)) : (is_limit.hom_iso h W).hom f = (t.extend f.down).π := rfl /-- The limit of `F` represents the functor taking `W` to the set of cones on `F` with vertex `W`. -/ def nat_iso (h : is_limit t) : yoneda.obj t.X ⋙ ulift_functor.{u₁} ≅ F.cones := nat_iso.of_components (λ W, is_limit.hom_iso h (unop W)) (by tidy). /-- Another, more explicit, formulation of the universal property of a limit cone. See also `hom_iso`. -/ def hom_iso' (h : is_limit t) (W : C) : ulift.{u₁} ((W ⟶ t.X) : Type v₃) ≅ { p : Π j, W ⟶ F.obj j // ∀ {j j'} (f : j ⟶ j'), p j ≫ F.map f = p j' } := h.hom_iso W ≪≫ { hom := λ π, ⟨λ j, π.app j, λ j j' f, by convert ←(π.naturality f).symm; apply id_comp⟩, inv := λ p, { app := λ j, p.1 j, naturality' := λ j j' f, begin dsimp, rw [id_comp], exact (p.2 f).symm end } } /-- If G : C → D is a faithful functor which sends t to a limit cone, then it suffices to check that the induced maps for the image of t can be lifted to maps of C. -/ def of_faithful {t : cone F} {D : Type u₄} [category.{v₄} D] (G : C ⥤ D) [faithful G] (ht : is_limit (G.map_cone t)) (lift : Π (s : cone F), s.X ⟶ t.X) (h : ∀ s, G.map (lift s) = ht.lift (G.map_cone s)) : is_limit t := { lift := lift, fac' := λ s j, by apply G.map_injective; rw [G.map_comp, h]; apply ht.fac, uniq' := λ s m w, begin apply G.map_injective, rw h, refine ht.uniq (G.map_cone s) _ (λ j, _), convert ←congr_arg (λ f, G.map f) (w j), apply G.map_comp end } /-- If `F` and `G` are naturally isomorphic, then `F.map_cone c` being a limit implies `G.map_cone c` is also a limit. -/ def map_cone_equiv {D : Type u₄} [category.{v₄} D] {K : J ⥤ C} {F G : C ⥤ D} (h : F ≅ G) {c : cone K} (t : is_limit (F.map_cone c)) : is_limit (G.map_cone c) := begin apply postcompose_inv_equiv (iso_whisker_left K h : _) (G.map_cone c) _, apply t.of_iso_limit (postcompose_whisker_left_map_cone h.symm c).symm, end /-- A cone is a limit cone exactly if there is a unique cone morphism from any other cone. -/ def iso_unique_cone_morphism {t : cone F} : is_limit t ≅ Π s, unique (s ⟶ t) := { hom := λ h s, { default := h.lift_cone_morphism s, uniq := λ _, h.uniq_cone_morphism }, inv := λ h, { lift := λ s, (h s).default.hom, uniq' := λ s f w, congr_arg cone_morphism.hom ((h s).uniq ⟨f, w⟩) } } namespace of_nat_iso variables {X : C} (h : yoneda.obj X ⋙ ulift_functor.{u₁} ≅ F.cones) /-- If `F.cones` is represented by `X`, each morphism `f : Y ⟶ X` gives a cone with cone point `Y`. -/ def cone_of_hom {Y : C} (f : Y ⟶ X) : cone F := { X := Y, π := h.hom.app (op Y) ⟨f⟩ } /-- If `F.cones` is represented by `X`, each cone `s` gives a morphism `s.X ⟶ X`. -/ def hom_of_cone (s : cone F) : s.X ⟶ X := (h.inv.app (op s.X) s.π).down @[simp] lemma cone_of_hom_of_cone (s : cone F) : cone_of_hom h (hom_of_cone h s) = s := begin dsimp [cone_of_hom, hom_of_cone], cases s, congr, dsimp, convert congr_fun (congr_fun (congr_arg nat_trans.app h.inv_hom_id) (op s_X)) s_π, exact ulift.up_down _ end @[simp] lemma hom_of_cone_of_hom {Y : C} (f : Y ⟶ X) : hom_of_cone h (cone_of_hom h f) = f := congr_arg ulift.down (congr_fun (congr_fun (congr_arg nat_trans.app h.hom_inv_id) (op Y)) ⟨f⟩ : _) /-- If `F.cones` is represented by `X`, the cone corresponding to the identity morphism on `X` will be a limit cone. -/ def limit_cone : cone F := cone_of_hom h (𝟙 X) /-- If `F.cones` is represented by `X`, the cone corresponding to a morphism `f : Y ⟶ X` is the limit cone extended by `f`. -/ lemma cone_of_hom_fac {Y : C} (f : Y ⟶ X) : cone_of_hom h f = (limit_cone h).extend f := begin dsimp [cone_of_hom, limit_cone, cone.extend], congr' with j, have t := congr_fun (h.hom.naturality f.op) ⟨𝟙 X⟩, dsimp at t, simp only [comp_id] at t, rw congr_fun (congr_arg nat_trans.app t) j, refl, end /-- If `F.cones` is represented by `X`, any cone is the extension of the limit cone by the corresponding morphism. -/ lemma cone_fac (s : cone F) : (limit_cone h).extend (hom_of_cone h s) = s := begin rw ←cone_of_hom_of_cone h s, conv_lhs { simp only [hom_of_cone_of_hom] }, apply (cone_of_hom_fac _ _).symm, end end of_nat_iso section open of_nat_iso /-- If `F.cones` is representable, then the cone corresponding to the identity morphism on the representing object is a limit cone. -/ def of_nat_iso {X : C} (h : yoneda.obj X ⋙ ulift_functor.{u₁} ≅ F.cones) : is_limit (limit_cone h) := { lift := λ s, hom_of_cone h s, fac' := λ s j, begin have h := cone_fac h s, cases s, injection h with h₁ h₂, simp only [heq_iff_eq] at h₂, conv_rhs { rw ← h₂ }, refl, end, uniq' := λ s m w, begin rw ←hom_of_cone_of_hom h m, congr, rw cone_of_hom_fac, dsimp [cone.extend], cases s, congr' with j, exact w j, end } end end is_limit /-- A cocone `t` on `F` is a colimit cocone if each cocone on `F` admits a unique cocone morphism from `t`. See <https://stacks.math.columbia.edu/tag/002F>. -/ @[nolint has_inhabited_instance] structure is_colimit (t : cocone F) := (desc : Π (s : cocone F), t.X ⟶ s.X) (fac' : ∀ (s : cocone F) (j : J), t.ι.app j ≫ desc s = s.ι.app j . obviously) (uniq' : ∀ (s : cocone F) (m : t.X ⟶ s.X) (w : ∀ j : J, t.ι.app j ≫ m = s.ι.app j), m = desc s . obviously) restate_axiom is_colimit.fac' attribute [simp,reassoc] is_colimit.fac restate_axiom is_colimit.uniq' namespace is_colimit instance subsingleton {t : cocone F} : subsingleton (is_colimit t) := ⟨by intros P Q; cases P; cases Q; congr; ext; solve_by_elim⟩ /-- Given a natural transformation `α : F ⟶ G`, we give a morphism from the cocone point of a colimit cocone over `F` to the cocone point of any cocone over `G`. -/ def map {F G : J ⥤ C} {s : cocone F} (P : is_colimit s) (t : cocone G) (α : F ⟶ G) : s.X ⟶ t.X := P.desc ((cocones.precompose α).obj t) @[simp, reassoc] lemma ι_map {F G : J ⥤ C} {c : cocone F} (hc : is_colimit c) (d : cocone G) (α : F ⟶ G) (j : J) : c.ι.app j ≫ is_colimit.map hc d α = α.app j ≫ d.ι.app j := fac _ _ _ @[simp] lemma desc_self {t : cocone F} (h : is_colimit t) : h.desc t = 𝟙 t.X := (h.uniq _ _ (λ j, comp_id _)).symm /- Repackaging the definition in terms of cocone morphisms. -/ /-- The universal morphism from a colimit cocone to any other cocone. -/ @[simps] def desc_cocone_morphism {t : cocone F} (h : is_colimit t) (s : cocone F) : t ⟶ s := { hom := h.desc s } lemma uniq_cocone_morphism {s t : cocone F} (h : is_colimit t) {f f' : t ⟶ s} : f = f' := have ∀ {g : t ⟶ s}, g = h.desc_cocone_morphism s, by intro g; ext; exact h.uniq _ _ g.w, this.trans this.symm /-- Restating the definition of a colimit cocone in terms of the ∃! operator. -/ lemma exists_unique {t : cocone F} (h : is_colimit t) (s : cocone F) : ∃! (d : t.X ⟶ s.X), ∀ j, t.ι.app j ≫ d = s.ι.app j := ⟨h.desc s, h.fac s, h.uniq s⟩ /-- Noncomputably make a colimit cocone from the existence of unique factorizations. -/ def of_exists_unique {t : cocone F} (ht : ∀ s : cocone F, ∃! d : t.X ⟶ s.X, ∀ j, t.ι.app j ≫ d = s.ι.app j) : is_colimit t := by { choose s hs hs' using ht, exact ⟨s, hs, hs'⟩ } /-- Alternative constructor for `is_colimit`, providing a morphism of cocones rather than a morphism between the cocone points and separately the factorisation condition. -/ @[simps] def mk_cocone_morphism {t : cocone F} (desc : Π (s : cocone F), t ⟶ s) (uniq' : ∀ (s : cocone F) (m : t ⟶ s), m = desc s) : is_colimit t := { desc := λ s, (desc s).hom, uniq' := λ s m w, have cocone_morphism.mk m w = desc s, by apply uniq', congr_arg cocone_morphism.hom this } /-- Colimit cocones on `F` are unique up to isomorphism. -/ @[simps] def unique_up_to_iso {s t : cocone F} (P : is_colimit s) (Q : is_colimit t) : s ≅ t := { hom := P.desc_cocone_morphism t, inv := Q.desc_cocone_morphism s, hom_inv_id' := P.uniq_cocone_morphism, inv_hom_id' := Q.uniq_cocone_morphism } /-- Any cocone morphism between colimit cocones is an isomorphism. -/ lemma hom_is_iso {s t : cocone F} (P : is_colimit s) (Q : is_colimit t) (f : s ⟶ t) : is_iso f := ⟨⟨Q.desc_cocone_morphism s, ⟨P.uniq_cocone_morphism, Q.uniq_cocone_morphism⟩⟩⟩ /-- Colimits of `F` are unique up to isomorphism. -/ def cocone_point_unique_up_to_iso {s t : cocone F} (P : is_colimit s) (Q : is_colimit t) : s.X ≅ t.X := (cocones.forget F).map_iso (unique_up_to_iso P Q) @[simp, reassoc] lemma comp_cocone_point_unique_up_to_iso_hom {s t : cocone F} (P : is_colimit s) (Q : is_colimit t) (j : J) : s.ι.app j ≫ (cocone_point_unique_up_to_iso P Q).hom = t.ι.app j := (unique_up_to_iso P Q).hom.w _ @[simp, reassoc] lemma comp_cocone_point_unique_up_to_iso_inv {s t : cocone F} (P : is_colimit s) (Q : is_colimit t) (j : J) : t.ι.app j ≫ (cocone_point_unique_up_to_iso P Q).inv = s.ι.app j := (unique_up_to_iso P Q).inv.w _ @[simp, reassoc] lemma cocone_point_unique_up_to_iso_hom_desc {r s t : cocone F} (P : is_colimit s) (Q : is_colimit t) : (cocone_point_unique_up_to_iso P Q).hom ≫ Q.desc r = P.desc r := P.uniq _ _ (by simp) @[simp, reassoc] lemma cocone_point_unique_up_to_iso_inv_desc {r s t : cocone F} (P : is_colimit s) (Q : is_colimit t) : (cocone_point_unique_up_to_iso P Q).inv ≫ P.desc r = Q.desc r := Q.uniq _ _ (by simp) /-- Transport evidence that a cocone is a colimit cocone across an isomorphism of cocones. -/ def of_iso_colimit {r t : cocone F} (P : is_colimit r) (i : r ≅ t) : is_colimit t := is_colimit.mk_cocone_morphism (λ s, i.inv ≫ P.desc_cocone_morphism s) (λ s m, by rw i.eq_inv_comp; apply P.uniq_cocone_morphism) @[simp] lemma of_iso_colimit_desc {r t : cocone F} (P : is_colimit r) (i : r ≅ t) (s) : (P.of_iso_colimit i).desc s = i.inv.hom ≫ P.desc s := rfl /-- Isomorphism of cocones preserves whether or not they are colimiting cocones. -/ def equiv_iso_colimit {r t : cocone F} (i : r ≅ t) : is_colimit r ≃ is_colimit t := { to_fun := λ h, h.of_iso_colimit i, inv_fun := λ h, h.of_iso_colimit i.symm, left_inv := by tidy, right_inv := by tidy } @[simp] lemma equiv_iso_colimit_apply {r t : cocone F} (i : r ≅ t) (P : is_colimit r) : equiv_iso_colimit i P = P.of_iso_colimit i := rfl @[simp] lemma equiv_iso_colimit_symm_apply {r t : cocone F} (i : r ≅ t) (P : is_colimit t) : (equiv_iso_colimit i).symm P = P.of_iso_colimit i.symm := rfl /-- If the canonical morphism to a cocone point from a colimiting cocone point is an iso, then the first cocone was colimiting also. -/ def of_point_iso {r t : cocone F} (P : is_colimit r) [i : is_iso (P.desc t)] : is_colimit t := of_iso_colimit P begin haveI : is_iso (P.desc_cocone_morphism t).hom := i, haveI : is_iso (P.desc_cocone_morphism t) := cocones.cocone_iso_of_hom_iso _, apply as_iso (P.desc_cocone_morphism t), end variables {t : cocone F} lemma hom_desc (h : is_colimit t) {W : C} (m : t.X ⟶ W) : m = h.desc { X := W, ι := { app := λ b, t.ι.app b ≫ m, naturality' := by intros; erw [←assoc, t.ι.naturality, comp_id, comp_id] } } := h.uniq { X := W, ι := { app := λ b, t.ι.app b ≫ m, naturality' := _ } } m (λ b, rfl) /-- Two morphisms out of a colimit are equal if their compositions with each cocone morphism are equal. -/ lemma hom_ext (h : is_colimit t) {W : C} {f f' : t.X ⟶ W} (w : ∀ j, t.ι.app j ≫ f = t.ι.app j ≫ f') : f = f' := by rw [h.hom_desc f, h.hom_desc f']; congr; exact funext w /-- Given a left adjoint functor between categories of cocones, the image of a colimit cocone is a colimit cocone. -/ def of_left_adjoint {D : Type u₄} [category.{v₄} D] {G : K ⥤ D} (h : cocone G ⥤ cocone F) [is_left_adjoint h] {c : cocone G} (t : is_colimit c) : is_colimit (h.obj c) := mk_cocone_morphism (λ s, ((adjunction.of_left_adjoint h).hom_equiv c s).symm (t.desc_cocone_morphism _)) (λ s m, (adjunction.hom_equiv_apply_eq _ _ _).1 t.uniq_cocone_morphism) /-- Given two functors which have equivalent categories of cocones, we can transport a colimiting cocone across the equivalence. -/ def of_cocone_equiv {D : Type u₄} [category.{v₄} D] {G : K ⥤ D} (h : cocone G ≌ cocone F) {c : cocone G} : is_colimit (h.functor.obj c) ≃ is_colimit c := { to_fun := λ P, of_iso_colimit (of_left_adjoint h.inverse P) (h.unit_iso.symm.app c), inv_fun := of_left_adjoint h.functor, left_inv := by tidy, right_inv := by tidy, } @[simp] lemma of_cocone_equiv_apply_desc {D : Type u₄} [category.{v₄} D] {G : K ⥤ D} (h : cocone G ≌ cocone F) {c : cocone G} (P : is_colimit (h.functor.obj c)) (s) : (of_cocone_equiv h P).desc s = (h.unit.app c).hom ≫ (h.inverse.map (P.desc_cocone_morphism (h.functor.obj s))).hom ≫ (h.unit_inv.app s).hom := rfl @[simp] lemma of_cocone_equiv_symm_apply_desc {D : Type u₄} [category.{v₄} D] {G : K ⥤ D} (h : cocone G ≌ cocone F) {c : cocone G} (P : is_colimit c) (s) : ((of_cocone_equiv h).symm P).desc s = (h.functor.map (P.desc_cocone_morphism (h.inverse.obj s))).hom ≫ (h.counit.app s).hom := rfl /-- A cocone precomposed with a natural isomorphism is a colimit cocone if and only if the original cocone is. -/ def precompose_hom_equiv {F G : J ⥤ C} (α : F ≅ G) (c : cocone G) : is_colimit ((cocones.precompose α.hom).obj c) ≃ is_colimit c := of_cocone_equiv (cocones.precompose_equivalence α) /-- A cocone precomposed with the inverse of a natural isomorphism is a colimit cocone if and only if the original cocone is. -/ def precompose_inv_equiv {F G : J ⥤ C} (α : F ≅ G) (c : cocone F) : is_colimit ((cocones.precompose α.inv).obj c) ≃ is_colimit c := precompose_hom_equiv α.symm c /-- Constructing an equivalence `is_colimit c ≃ is_colimit d` from a natural isomorphism between the underlying functors, and then an isomorphism between `c` transported along this and `d`. -/ def equiv_of_nat_iso_of_iso {F G : J ⥤ C} (α : F ≅ G) (c : cocone F) (d : cocone G) (w : (cocones.precompose α.inv).obj c ≅ d) : is_colimit c ≃ is_colimit d := (precompose_inv_equiv α _).symm.trans (equiv_iso_colimit w) /-- The cocone points of two colimit cocones for naturally isomorphic functors are themselves isomorphic. -/ @[simps] def cocone_points_iso_of_nat_iso {F G : J ⥤ C} {s : cocone F} {t : cocone G} (P : is_colimit s) (Q : is_colimit t) (w : F ≅ G) : s.X ≅ t.X := { hom := P.map t w.hom, inv := Q.map s w.inv, hom_inv_id' := P.hom_ext (by tidy), inv_hom_id' := Q.hom_ext (by tidy) } @[reassoc] lemma comp_cocone_points_iso_of_nat_iso_hom {F G : J ⥤ C} {s : cocone F} {t : cocone G} (P : is_colimit s) (Q : is_colimit t) (w : F ≅ G) (j : J) : s.ι.app j ≫ (cocone_points_iso_of_nat_iso P Q w).hom = w.hom.app j ≫ t.ι.app j := by simp @[reassoc] lemma comp_cocone_points_iso_of_nat_iso_inv {F G : J ⥤ C} {s : cocone F} {t : cocone G} (P : is_colimit s) (Q : is_colimit t) (w : F ≅ G) (j : J) : t.ι.app j ≫ (cocone_points_iso_of_nat_iso P Q w).inv = w.inv.app j ≫ s.ι.app j := by simp @[reassoc] lemma cocone_points_iso_of_nat_iso_hom_desc {F G : J ⥤ C} {s : cocone F} {r t : cocone G} (P : is_colimit s) (Q : is_colimit t) (w : F ≅ G) : (cocone_points_iso_of_nat_iso P Q w).hom ≫ Q.desc r = P.map _ w.hom := P.hom_ext (by simp) @[reassoc] lemma cocone_points_iso_of_nat_iso_inv_desc {F G : J ⥤ C} {s : cocone G} {r t : cocone F} (P : is_colimit t) (Q : is_colimit s) (w : F ≅ G) : (cocone_points_iso_of_nat_iso P Q w).inv ≫ P.desc r = Q.map _ w.inv := Q.hom_ext (by simp) section equivalence open category_theory.equivalence /-- If `s : cocone F` is a colimit cocone, so is `s` whiskered by an equivalence `e`. -/ def whisker_equivalence {s : cocone F} (P : is_colimit s) (e : K ≌ J) : is_colimit (s.whisker e.functor) := of_left_adjoint (cocones.whiskering_equivalence e).functor P /-- If `s : cocone F` whiskered by an equivalence `e` is a colimit cocone, so is `s`. -/ def of_whisker_equivalence {s : cocone F} (e : K ≌ J) (P : is_colimit (s.whisker e.functor)) : is_colimit s := equiv_iso_colimit ((cocones.whiskering_equivalence e).unit_iso.app s).symm (of_left_adjoint (cocones.whiskering_equivalence e).inverse P : _) /-- Given an equivalence of diagrams `e`, `s` is a colimit cocone iff `s.whisker e.functor` is. -/ def whisker_equivalence_equiv {s : cocone F} (e : K ≌ J) : is_colimit s ≃ is_colimit (s.whisker e.functor) := ⟨λ h, h.whisker_equivalence e, of_whisker_equivalence e, by tidy, by tidy⟩ /-- We can prove two cocone points `(s : cocone F).X` and `(t.cocone G).X` are isomorphic if * both cocones are colimit cocones * their indexing categories are equivalent via some `e : J ≌ K`, * the triangle of functors commutes up to a natural isomorphism: `e.functor ⋙ G ≅ F`. This is the most general form of uniqueness of cocone points, allowing relabelling of both the indexing category (up to equivalence) and the functor (up to natural isomorphism). -/ @[simps] def cocone_points_iso_of_equivalence {F : J ⥤ C} {s : cocone F} {G : K ⥤ C} {t : cocone G} (P : is_colimit s) (Q : is_colimit t) (e : J ≌ K) (w : e.functor ⋙ G ≅ F) : s.X ≅ t.X := let w' : e.inverse ⋙ F ≅ G := (iso_whisker_left e.inverse w).symm ≪≫ inv_fun_id_assoc e G in { hom := P.desc ((cocones.equivalence_of_reindexing e w).functor.obj t), inv := Q.desc ((cocones.equivalence_of_reindexing e.symm w').functor.obj s), hom_inv_id' := begin apply hom_ext P, intros j, dsimp, simp only [limits.cocone.whisker_ι, fac, inv_fun_id_assoc_inv_app, whisker_left_app, assoc, comp_id, limits.cocones.precompose_obj_ι, fac_assoc, nat_trans.comp_app], rw [counit_inv_app_functor, ←functor.comp_map, ←w.inv.naturality_assoc], dsimp, simp, end, inv_hom_id' := by { apply hom_ext Q, tidy, }, } end equivalence /-- The universal property of a colimit cocone: a map `X ⟶ W` is the same as a cocone on `F` with vertex `W`. -/ def hom_iso (h : is_colimit t) (W : C) : ulift.{u₁} (t.X ⟶ W : Type v₃) ≅ (F ⟶ (const J).obj W) := { hom := λ f, (t.extend f.down).ι, inv := λ ι, ⟨h.desc { X := W, ι := ι }⟩, hom_inv_id' := by ext f; apply h.hom_ext; intro j; simp; dsimp; refl } @[simp] lemma hom_iso_hom (h : is_colimit t) {W : C} (f : ulift (t.X ⟶ W)) : (is_colimit.hom_iso h W).hom f = (t.extend f.down).ι := rfl /-- The colimit of `F` represents the functor taking `W` to the set of cocones on `F` with vertex `W`. -/ def nat_iso (h : is_colimit t) : coyoneda.obj (op t.X) ⋙ ulift_functor.{u₁} ≅ F.cocones := nat_iso.of_components (is_colimit.hom_iso h) (by intros; ext; dsimp; rw ←assoc; refl) /-- Another, more explicit, formulation of the universal property of a colimit cocone. See also `hom_iso`. -/ def hom_iso' (h : is_colimit t) (W : C) : ulift.{u₁} ((t.X ⟶ W) : Type v₃) ≅ { p : Π j, F.obj j ⟶ W // ∀ {j j' : J} (f : j ⟶ j'), F.map f ≫ p j' = p j } := h.hom_iso W ≪≫ { hom := λ ι, ⟨λ j, ι.app j, λ j j' f, by convert ←(ι.naturality f); apply comp_id⟩, inv := λ p, { app := λ j, p.1 j, naturality' := λ j j' f, begin dsimp, rw [comp_id], exact (p.2 f) end } } /-- If G : C → D is a faithful functor which sends t to a colimit cocone, then it suffices to check that the induced maps for the image of t can be lifted to maps of C. -/ def of_faithful {t : cocone F} {D : Type u₄} [category.{v₄} D] (G : C ⥤ D) [faithful G] (ht : is_colimit (G.map_cocone t)) (desc : Π (s : cocone F), t.X ⟶ s.X) (h : ∀ s, G.map (desc s) = ht.desc (G.map_cocone s)) : is_colimit t := { desc := desc, fac' := λ s j, by apply G.map_injective; rw [G.map_comp, h]; apply ht.fac, uniq' := λ s m w, begin apply G.map_injective, rw h, refine ht.uniq (G.map_cocone s) _ (λ j, _), convert ←congr_arg (λ f, G.map f) (w j), apply G.map_comp end } /-- If `F` and `G` are naturally isomorphic, then `F.map_cone c` being a colimit implies `G.map_cone c` is also a colimit. -/ def map_cocone_equiv {D : Type u₄} [category.{v₄} D] {K : J ⥤ C} {F G : C ⥤ D} (h : F ≅ G) {c : cocone K} (t : is_colimit (F.map_cocone c)) : is_colimit (G.map_cocone c) := begin apply is_colimit.of_iso_colimit _ (precompose_whisker_left_map_cocone h c), apply (precompose_inv_equiv (iso_whisker_left K h : _) _).symm t, end /-- A cocone is a colimit cocone exactly if there is a unique cocone morphism from any other cocone. -/ def iso_unique_cocone_morphism {t : cocone F} : is_colimit t ≅ Π s, unique (t ⟶ s) := { hom := λ h s, { default := h.desc_cocone_morphism s, uniq := λ _, h.uniq_cocone_morphism }, inv := λ h, { desc := λ s, (h s).default.hom, uniq' := λ s f w, congr_arg cocone_morphism.hom ((h s).uniq ⟨f, w⟩) } } namespace of_nat_iso variables {X : C} (h : coyoneda.obj (op X) ⋙ ulift_functor.{u₁} ≅ F.cocones) /-- If `F.cocones` is corepresented by `X`, each morphism `f : X ⟶ Y` gives a cocone with cone point `Y`. -/ def cocone_of_hom {Y : C} (f : X ⟶ Y) : cocone F := { X := Y, ι := h.hom.app Y ⟨f⟩ } /-- If `F.cocones` is corepresented by `X`, each cocone `s` gives a morphism `X ⟶ s.X`. -/ def hom_of_cocone (s : cocone F) : X ⟶ s.X := (h.inv.app s.X s.ι).down @[simp] lemma cocone_of_hom_of_cocone (s : cocone F) : cocone_of_hom h (hom_of_cocone h s) = s := begin dsimp [cocone_of_hom, hom_of_cocone], cases s, congr, dsimp, convert congr_fun (congr_fun (congr_arg nat_trans.app h.inv_hom_id) s_X) s_ι, exact ulift.up_down _ end @[simp] lemma hom_of_cocone_of_hom {Y : C} (f : X ⟶ Y) : hom_of_cocone h (cocone_of_hom h f) = f := congr_arg ulift.down (congr_fun (congr_fun (congr_arg nat_trans.app h.hom_inv_id) Y) ⟨f⟩ : _) /-- If `F.cocones` is corepresented by `X`, the cocone corresponding to the identity morphism on `X` will be a colimit cocone. -/ def colimit_cocone : cocone F := cocone_of_hom h (𝟙 X) /-- If `F.cocones` is corepresented by `X`, the cocone corresponding to a morphism `f : Y ⟶ X` is the colimit cocone extended by `f`. -/ lemma cocone_of_hom_fac {Y : C} (f : X ⟶ Y) : cocone_of_hom h f = (colimit_cocone h).extend f := begin dsimp [cocone_of_hom, colimit_cocone, cocone.extend], congr' with j, have t := congr_fun (h.hom.naturality f) ⟨𝟙 X⟩, dsimp at t, simp only [id_comp] at t, rw congr_fun (congr_arg nat_trans.app t) j, refl, end /-- If `F.cocones` is corepresented by `X`, any cocone is the extension of the colimit cocone by the corresponding morphism. -/ lemma cocone_fac (s : cocone F) : (colimit_cocone h).extend (hom_of_cocone h s) = s := begin rw ←cocone_of_hom_of_cocone h s, conv_lhs { simp only [hom_of_cocone_of_hom] }, apply (cocone_of_hom_fac _ _).symm, end end of_nat_iso section open of_nat_iso /-- If `F.cocones` is corepresentable, then the cocone corresponding to the identity morphism on the representing object is a colimit cocone. -/ def of_nat_iso {X : C} (h : coyoneda.obj (op X) ⋙ ulift_functor.{u₁} ≅ F.cocones) : is_colimit (colimit_cocone h) := { desc := λ s, hom_of_cocone h s, fac' := λ s j, begin have h := cocone_fac h s, cases s, injection h with h₁ h₂, simp only [heq_iff_eq] at h₂, conv_rhs { rw ← h₂ }, refl, end, uniq' := λ s m w, begin rw ←hom_of_cocone_of_hom h m, congr, rw cocone_of_hom_fac, dsimp [cocone.extend], cases s, congr' with j, exact w j, end } end end is_colimit end category_theory.limits
e21e4352f9697d84fd33362690ccdc61c60672b4
ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5
/tests/compiler/print_error.lean
4e2e6b2005b29f78210154105eddb23b5ddbeb18
[ "Apache-2.0" ]
permissive
dupuisf/lean4
d082d13b01243e1de29ae680eefb476961221eef
6a39c65bd28eb0e28c3870188f348c8914502718
refs/heads/master
1,676,948,755,391
1,610,665,114,000
1,610,665,114,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
137
lean
#lang lean4 prelude import Init.System.IO def main : IO Unit := throw $ IO.Error.noFileOrDirectory "file.ext" 13 "this is some context"
4c4bfd72c6978642f10f9567973d64a8a9d89843
d29d82a0af640c937e499f6be79fc552eae0aa13
/src/field_theory/finite/polynomial.lean
1c25a562a4db45395b2491ab9e79dc381ee68272
[ "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
7,721
lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import field_theory.finite.basic import field_theory.mv_polynomial import data.mv_polynomial.expand import linear_algebra.basic import linear_algebra.finite_dimensional /-! ## Polynomials over finite fields -/ namespace mv_polynomial variables {σ : Type*} /-- A polynomial over the integers is divisible by `n : ℕ` if and only if it is zero over `zmod n`. -/ lemma C_dvd_iff_zmod (n : ℕ) (φ : mv_polynomial σ ℤ) : C (n:ℤ) ∣ φ ↔ map (int.cast_ring_hom (zmod n)) φ = 0 := C_dvd_iff_map_hom_eq_zero _ _ (char_p.int_cast_eq_zero_iff (zmod n) n) _ section frobenius variables {p : ℕ} [fact p.prime] lemma frobenius_zmod (f : mv_polynomial σ (zmod p)) : frobenius _ p f = expand p f := begin apply induction_on f, { intro a, rw [expand_C, frobenius_def, ← C_pow, zmod.pow_card], }, { simp only [alg_hom.map_add, ring_hom.map_add], intros _ _ hf hg, rw [hf, hg] }, { simp only [expand_X, ring_hom.map_mul, alg_hom.map_mul], intros _ _ hf, rw [hf, frobenius_def], }, end lemma expand_zmod (f : mv_polynomial σ (zmod p)) : expand p f = f ^ p := (frobenius_zmod _).symm end frobenius end mv_polynomial namespace mv_polynomial noncomputable theory open_locale big_operators classical open set linear_map submodule variables {K : Type*} {σ : Type*} variables [field K] [fintype K] [fintype σ] def indicator (a : σ → K) : mv_polynomial σ K := ∏ n, (1 - (X n - C (a n))^(fintype.card K - 1)) lemma eval_indicator_apply_eq_one (a : σ → K) : eval a (indicator a) = 1 := have 0 < fintype.card K - 1, begin rw [← finite_field.card_units, fintype.card_pos_iff], exact ⟨1⟩ end, by simp only [indicator, (finset.univ.prod_hom (eval a)).symm, ring_hom.map_sub, is_ring_hom.map_one (eval a), is_monoid_hom.map_pow (eval a), eval_X, eval_C, sub_self, zero_pow this, sub_zero, finset.prod_const_one] lemma eval_indicator_apply_eq_zero (a b : σ → K) (h : a ≠ b) : eval a (indicator b) = 0 := have ∃i, a i ≠ b i, by rwa [(≠), function.funext_iff, not_forall] at h, begin rcases this with ⟨i, hi⟩, simp only [indicator, (finset.univ.prod_hom (eval a)).symm, ring_hom.map_sub, is_ring_hom.map_one (eval a), is_monoid_hom.map_pow (eval a), eval_X, eval_C, sub_self, finset.prod_eq_zero_iff], refine ⟨i, finset.mem_univ _, _⟩, rw [finite_field.pow_card_sub_one_eq_one, sub_self], rwa [(≠), sub_eq_zero], end lemma degrees_indicator (c : σ → K) : degrees (indicator c) ≤ ∑ s : σ, (fintype.card K - 1) • {s} := begin rw [indicator], refine le_trans (degrees_prod _ _) (finset.sum_le_sum $ assume s hs, _), refine le_trans (degrees_sub _ _) _, rw [degrees_one, ← bot_eq_zero, bot_sup_eq], refine le_trans (degrees_pow _ _) (nsmul_le_nsmul_of_le_right _ _), refine le_trans (degrees_sub _ _) _, rw [degrees_C, ← bot_eq_zero, sup_bot_eq], exact degrees_X' _ end lemma indicator_mem_restrict_degree (c : σ → K) : indicator c ∈ restrict_degree σ K (fintype.card K - 1) := begin rw [mem_restrict_degree_iff_sup, indicator], assume n, refine le_trans (multiset.count_le_of_le _ $ degrees_indicator _) (le_of_eq _), rw [← finset.univ.sum_hom (multiset.count n)], simp only [is_add_monoid_hom.map_nsmul (multiset.count n), multiset.singleton_eq_singleton, nsmul_eq_mul, nat.cast_id], transitivity, refine finset.sum_eq_single n _ _, { assume b hb ne, rw [multiset.count_cons_of_ne ne.symm, multiset.count_zero, mul_zero] }, { assume h, exact (h $ finset.mem_univ _).elim }, { rw [multiset.count_cons_self, multiset.count_zero, mul_one] } end section variables (K σ) def evalₗ : mv_polynomial σ K →ₗ[K] (σ → K) → K := { to_fun := λ p e, eval e p, map_add' := λ p q, by { ext x, rw ring_hom.map_add, refl, }, map_smul' := λ a p, by { ext e, rw [smul_eq_C_mul, ring_hom.map_mul, eval_C], refl } } end lemma evalₗ_apply (p : mv_polynomial σ K) (e : σ → K) : evalₗ K σ p e = eval e p := rfl lemma map_restrict_dom_evalₗ : (restrict_degree σ K (fintype.card K - 1)).map (evalₗ K σ) = ⊤ := begin refine top_unique (set_like.le_def.2 $ assume e _, mem_map.2 _), refine ⟨∑ n : σ → K, e n • indicator n, _, _⟩, { exact sum_mem _ (assume c _, smul_mem _ _ (indicator_mem_restrict_degree _)) }, { ext n, simp only [linear_map.map_sum, @finset.sum_apply (σ → K) (λ_, K) _ _ _ _ _, pi.smul_apply, linear_map.map_smul], simp only [evalₗ_apply], transitivity, refine finset.sum_eq_single n _ _, { assume b _ h, rw [eval_indicator_apply_eq_zero _ _ h.symm, smul_zero] }, { assume h, exact (h $ finset.mem_univ n).elim }, { rw [eval_indicator_apply_eq_one, smul_eq_mul, mul_one] } } end end mv_polynomial namespace mv_polynomial open_locale classical open linear_map submodule universe u variables (σ : Type u) (K : Type u) [fintype σ] [field K] [fintype K] @[derive [add_comm_group, module K, inhabited]] def R : Type u := restrict_degree σ K (fintype.card K - 1) noncomputable instance decidable_restrict_degree (m : ℕ) : decidable_pred (∈ {n : σ →₀ ℕ | ∀i, n i ≤ m }) := by simp only [set.mem_set_of_eq]; apply_instance lemma dim_R : module.rank K (R σ K) = fintype.card (σ → K) := calc module.rank K (R σ K) = module.rank K (↥{s : σ →₀ ℕ | ∀ (n : σ), s n ≤ fintype.card K - 1} →₀ K) : linear_equiv.dim_eq (finsupp.supported_equiv_finsupp {s : σ →₀ ℕ | ∀n:σ, s n ≤ fintype.card K - 1 }) ... = cardinal.mk {s : σ →₀ ℕ | ∀ (n : σ), s n ≤ fintype.card K - 1} : by rw [finsupp.dim_eq, dim_of_field, mul_one] ... = cardinal.mk {s : σ → ℕ | ∀ (n : σ), s n < fintype.card K } : begin refine quotient.sound ⟨equiv.subtype_equiv finsupp.equiv_fun_on_fintype $ assume f, _⟩, refine forall_congr (assume n, nat.le_sub_right_iff_add_le _), exact fintype.card_pos_iff.2 ⟨0⟩ end ... = cardinal.mk (σ → {n // n < fintype.card K}) : quotient.sound ⟨@equiv.subtype_pi_equiv_pi σ (λ_, ℕ) (λs n, n < fintype.card K)⟩ ... = cardinal.mk (σ → fin (fintype.card K)) : quotient.sound ⟨equiv.arrow_congr (equiv.refl σ) (equiv.fin_equiv_subtype _).symm⟩ ... = cardinal.mk (σ → K) : quotient.sound ⟨equiv.arrow_congr (equiv.refl σ) (fintype.equiv_fin K).symm⟩ ... = fintype.card (σ → K) : cardinal.fintype_card _ instance : finite_dimensional K (R σ K) := is_noetherian.iff_dim_lt_omega.mpr (by simpa only [dim_R] using cardinal.nat_lt_omega (fintype.card (σ → K))) lemma finrank_R : finite_dimensional.finrank K (R σ K) = fintype.card (σ → K) := finite_dimensional.finrank_eq_of_dim_eq (dim_R σ K) def evalᵢ : R σ K →ₗ[K] (σ → K) → K := ((evalₗ K σ).comp (restrict_degree σ K (fintype.card K - 1)).subtype) lemma range_evalᵢ : (evalᵢ σ K).range = ⊤ := begin rw [evalᵢ, linear_map.range_comp, range_subtype], exact map_restrict_dom_evalₗ end lemma ker_evalₗ : (evalᵢ σ K).ker = ⊥ := begin refine (ker_eq_bot_iff_range_eq_top_of_finrank_eq_finrank _).mpr (range_evalᵢ _ _), rw [finite_dimensional.finrank_fintype_fun_eq_card, finrank_R] end lemma eq_zero_of_eval_eq_zero (p : mv_polynomial σ K) (h : ∀v:σ → K, eval v p = 0) (hp : p ∈ restrict_degree σ K (fintype.card K - 1)) : p = 0 := let p' : R σ K := ⟨p, hp⟩ in have p' ∈ (evalᵢ σ K).ker := by { rw [mem_ker], ext v, exact h v }, show p'.1 = (0 : R σ K).1, begin rw [ker_evalₗ, mem_bot] at this, rw [this] end end mv_polynomial
66f71c118e0fc576598c1c66c70e039cbc10d3bc
37a833c924892ee3ecb911484775a6d6ebb8984d
/src/category_theory/idempotent_completion.lean
752abc7adb32684526c002f197edd3e41327c4f1
[]
no_license
silky/lean-category-theory
28126e80564a1f99e9c322d86b3f7d750da0afa1
0f029a2364975f56ac727d31d867a18c95c22fd8
refs/heads/master
1,589,555,811,646
1,554,673,665,000
1,554,673,665,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
3,523
lean
-- Copyright (c) 2017 Scott Morrison. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Authors: Stephen Morgan, Scott Morrison import category_theory.equivalence namespace category_theory universes v₁ v₂ u₁ u₂ structure idempotent (C : Type u₁) [category.{v₁} C] := (X : C) (idem : X ⟶ X) (w' : idem ≫ idem = idem . obviously) restate_axiom idempotent.w' attribute [simp] idempotent.w -- search variables {C : Type u₁} [𝒞 : category.{v₁} C] include 𝒞 namespace idempotent structure morphism (P Q : idempotent.{v₁} C) := (hom : P.X ⟶ Q.X) (left' : P.idem ≫ hom = hom . obviously) (right' : hom ≫ Q.idem = hom . obviously) restate_axiom morphism.left' restate_axiom morphism.right' attribute [simp] morphism.left morphism.right -- search @[extensionality] lemma ext {P Q : idempotent C} (f g : morphism P Q) (w : f.hom = g.hom) : f = g := begin induction f, induction g, tidy end end idempotent instance idempotent_completion : category.{v₁} (idempotent C) := { hom := idempotent.morphism, id := λ P, ⟨ P.idem ⟩, comp := λ _ _ _ f g, { hom := f.hom ≫ g.hom, left' := by rw [←category.assoc, idempotent.morphism.left], right' := by rw [category.assoc, idempotent.morphism.right] } } namespace idempotent_completion @[simp] lemma id_hom (P : idempotent C) : ((𝟙 P) : idempotent.morphism P P).hom = P.idem := rfl @[simp] lemma comp_hom {P Q R : idempotent C} (f : P ⟶ Q) (g : Q ⟶ R) : (f ≫ g).hom = f.hom ≫ g.hom := rfl def to_completion (C : Type u₁) [𝒞 : category.{v₁} C] : C ⥤ (idempotent.{v₁} C) := { obj := λ P, { X := P, idem := 𝟙 P }, map := λ _ _ f, { hom := f } } @[simp] private lemma double_idempotent_morphism_left (P Q : idempotent (idempotent C)) (f : P ⟶ Q) : (P.idem).hom ≫ (f.hom).hom = (f.hom).hom := congr_arg idempotent.morphism.hom f.left @[simp] private lemma double_idempotent_morphism_right (P Q : idempotent (idempotent C)) (f : P ⟶ Q) : (f.hom).hom ≫ (Q.idem).hom = (f.hom).hom := congr_arg idempotent.morphism.hom f.right @[simp] private def idempotent_functor : (idempotent (idempotent C)) ⥤ (idempotent C) := { obj := λ P, ⟨ P.X.X, P.idem.hom, congr_arg idempotent.morphism.hom P.w ⟩, map := λ _ _ f, ⟨ f.hom.hom, by obviously ⟩ }. @[simp] private def idempotent_inverse : (idempotent C) ⥤ (idempotent (idempotent C)) := { obj := λ P, ⟨ P, ⟨ P.idem, by obviously ⟩, by obviously ⟩, map := λ _ _ f, ⟨ f, by obviously ⟩ }. @[simp] lemma idem_hom_idempotent (X : idempotent (idempotent C)) : X.idem.hom ≫ X.idem.hom = X.idem.hom := begin rw ←comp_hom, simp, end lemma idempotent_idempotent : equivalence (idempotent (idempotent C)) (idempotent C) := { functor := idempotent_functor, inverse := idempotent_inverse, fun_inv_id' := { hom := { app := λ X, { hom := { hom := X.idem.hom } } }, inv := { app := λ X, { hom := { hom := X.idem.hom } } } }, inv_fun_id' := { hom := { app := λ X, { hom := X.idem } }, inv := { app := λ X, { hom := X.idem } } } } variable {D : Type u₂} variable [𝒟 : category.{v₂} D] include 𝒟 def extend_to_completion (F : C ⥤ (idempotent D)) : (idempotent C) ⥤ (idempotent D) := { obj := λ P, { X := (F.obj P.X).X, idem := (F.map P.idem).hom, w' := begin rw [←comp_hom, ←functor.map_comp, idempotent.w], end }, map := λ _ _ f, { hom := (F.map f.hom).hom } } end idempotent_completion end category_theory
125b32db214d3b25dd9956a7de91a3bfc6c2d93b
491068d2ad28831e7dade8d6dff871c3e49d9431
/library/data/nat/fact.lean
8e5c4d43b972c0243f0bdcf21b0e50f91a84b919
[ "Apache-2.0" ]
permissive
davidmueller13/lean
65a3ed141b4088cd0a268e4de80eb6778b21a0e9
c626e2e3c6f3771e07c32e82ee5b9e030de5b050
refs/heads/master
1,611,278,313,401
1,444,021,177,000
1,444,021,177,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
1,423
lean
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura Factorial -/ import data.nat.div namespace nat definition fact : nat → nat | 0 := 1 | (succ n) := (succ n) * fact n lemma fact_zero : fact 0 = 1 := rfl lemma fact_one : fact 1 = 1 := rfl lemma fact_succ (n) : fact (succ n) = succ n * fact n := rfl lemma fact_pos : ∀ n, fact n > 0 | 0 := zero_lt_one | (succ n) := mul_pos !succ_pos (fact_pos n) lemma fact_ne_zero (n : ℕ) : fact n ≠ 0 := ne_of_gt !fact_pos lemma dvd_fact : ∀ {m n}, m > 0 → m ≤ n → m ∣ fact n | m 0 h₁ h₂ := absurd h₁ (not_lt_of_ge h₂) | m (succ n) h₁ h₂ := begin rewrite fact_succ, cases (eq_or_lt_of_le h₂) with he hl, {subst m, apply dvd_mul_right}, {have aux : m ∣ fact n, from dvd_fact h₁ (le_of_lt_succ hl), apply dvd_mul_of_dvd_right aux} end lemma fact_le {m n} : m ≤ n → fact m ≤ fact n := begin induction n with n ih, {intro h, have meq0 : m = 0, from eq_zero_of_le_zero h, subst m}, {intro m_le_succ_n, cases (eq_or_lt_of_le m_le_succ_n) with h₁ h₂, {subst m}, {transitivity (fact n), exact ih (le_of_lt_succ h₂), rewrite [fact_succ, -one_mul at {1}], exact mul_le_mul (succ_le_succ (zero_le n)) !le.refl}} end end nat
b13f7d5bc93f6c0ee2b8113af56ff09176b74a1f
9cb9db9d79fad57d80ca53543dc07efb7c4f3838
/src/locally_constant/Vhat.lean
4dbe3a0c65752c2faf100b7085a6b502b6d94616
[]
no_license
mr-infty/lean-liquid
3ff89d1f66244b434654c59bdbd6b77cb7de0109
a8db559073d2101173775ccbd85729d3a4f1ed4d
refs/heads/master
1,678,465,145,334
1,614,565,310,000
1,614,565,310,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
9,806
lean
import category_theory.currying import category_theory.abelian.additive_functor import topology.category.Profinite import topology.algebra.normed_group import topology.algebra.group_completion import topology.metric_space.completion import locally_constant.NormedGroup import normed_group.normed_with_aut noncomputable theory open_locale nnreal universe u namespace NormedGroup open uniform_space opposite category_theory /-- The completion of a normed group, as an endofunctor on `NormedGroup`. -/ @[simps] def Completion : NormedGroup.{u} ⥤ NormedGroup.{u} := { obj := λ V, NormedGroup.of (completion V), map := λ V W f, { to_fun := completion.map f, bound' := begin obtain ⟨C, C_pos, hC⟩ := f.bound, use C, intro v, apply completion.induction_on v; clear v, { refine is_closed_le _ _, { exact continuous_norm.comp completion.continuous_map }, { exact continuous_const.mul continuous_norm } }, { intro v, rw [completion.map_coe, completion.norm_coe, completion.norm_coe], { apply hC }, { exact f.uniform_continuous } } end, map_zero' := by { erw [completion.map_coe], { congr' 1, exact f.map_zero' }, exact normed_group_hom.uniform_continuous f }, map_add' := begin intros x y, apply completion.induction_on₂ x y; clear x y, { refine is_closed_eq _ _, { exact completion.continuous_map.comp continuous_add }, { apply continuous.add, { exact completion.continuous_map.comp continuous_fst }, { exact completion.continuous_map.comp continuous_snd } } }, { intros x y, rw [← completion.coe_add, completion.map_coe, completion.map_coe, completion.map_coe, ← completion.coe_add], { congr' 1, exact f.map_add' x y }, all_goals { exact normed_group_hom.uniform_continuous f } } end }, map_id' := λ V, by { ext1 v, show completion.map id v = v, rw completion.map_id, refl }, map_comp' := begin intros U V W f g, ext1 v, show completion.map (g ∘ f) v = _, rw ← completion.map_comp, { refl }, { exact normed_group_hom.uniform_continuous _ }, { exact normed_group_hom.uniform_continuous _ } end } instance Completion_complete_space {V : NormedGroup} : complete_space (Completion.obj V) := begin change complete_space (completion V), apply_instance end /-- The canonical morphism from a normed group `V` to its completion. -/ @[simps] def incl {V : NormedGroup} : V ⟶ Completion.obj V := { to_fun := λ v, (v : completion V), map_zero' := by simpa [completion.coe_eq], map_add' := completion.coe_add, bound' := ⟨1, λ v, by simp⟩ } @[simp] lemma norm_incl_eq {V : NormedGroup} {v : V} : ∥incl v∥ = ∥v∥ := by simp /-- Given a morphism of normed groups `V ⟶ W`, this defines the associated morphism from the completion of `V` to the completion of `W`. The difference from the definition obtained from the functoriality of completion is in that the map sending a morphism `f` to the associated morphism of completions is itself additive. -/ def Completion.map_hom (V W : NormedGroup.{u}) : (V ⟶ W) →+ (Completion.obj V ⟶ Completion.obj W) := add_monoid_hom.mk' (category_theory.functor.map Completion) $ begin intros f g, ext v, apply uniform_space.completion.induction_on v, { refine is_closed_eq (normed_group_hom.continuous _) _, apply continuous.add; apply normed_group_hom.continuous }, { clear v, intro v, simp only [normed_group_hom.coe_add, pi.add_apply, Completion_map_to_fun, normed_group_hom.coe_add], rw [uniform_space.completion.map_coe, uniform_space.completion.map_coe f.uniform_continuous, uniform_space.completion.map_coe g.uniform_continuous], { rw [pi.add_apply, uniform_space.completion.coe_add] }, { exact (f + g).uniform_continuous } } end @[simp] lemma Completion.map_zero (V W : NormedGroup) : Completion.map (0 : V ⟶ W) = 0 := (Completion.map_hom V W).map_zero instance : preadditive NormedGroup.{u} := { hom_group := λ P Q, infer_instance } instance : functor.additive Completion := { map_zero' := Completion.map_zero, map_add' := λ X Y, (Completion.map_hom _ _).map_add } /-- Given a morphism of normed groups `f : V → W` with `W` complete, this provides a lift of `f` to the completion of `V`. The lemmas `lift_unique` and `lift_comp_incl` provide the api for the universal property of the completion. -/ def Completion.lift {V W : NormedGroup} [complete_space W] (f : V ⟶ W) : Completion.obj V ⟶ W := { to_fun := completion.extension f, map_zero' := begin erw completion.extension_coe, { simp }, { exact normed_group_hom.uniform_continuous _ }, end, map_add' := begin intros x y, apply completion.induction_on₂ x y; clear x y, { refine is_closed_eq _ _, { refine continuous.comp _ _, exact completion.continuous_extension, exact continuous_add }, { refine continuous.add _ _, exact continuous.comp completion.continuous_extension continuous_fst, exact continuous.comp completion.continuous_extension continuous_snd } }, { intros x y, rw ← completion.coe_add, repeat {rw completion.extension_coe}, exact normed_group_hom.map_add _ _ _, all_goals {exact normed_group_hom.uniform_continuous _} } end, bound' := begin rcases f.bound with ⟨c,hc,h⟩, use c, intros v, apply completion.induction_on v; clear v, { refine is_closed_le _ _, refine continuous.comp continuous_norm completion.continuous_extension, refine continuous.mul continuous_const continuous_norm }, { intros a, rw completion.extension_coe, { change _ ≤ ↑c * ∥incl _∥, simpa using h a }, { exact normed_group_hom.uniform_continuous _ }} end } lemma lift_comp_incl {V W : NormedGroup} [complete_space W] (f : V ⟶ W) : incl ≫ (Completion.lift f) = f := begin ext, change completion.extension f x = _, refine completion.extension_coe _ _, exact normed_group_hom.uniform_continuous _, end lemma lift_unique {V W : NormedGroup} [complete_space W] (f : V ⟶ W) (g : Completion.obj V ⟶ W) : incl ≫ g = f → g = Completion.lift f := begin intros h, ext, apply completion.induction_on x; clear x, { refine is_closed_eq _ _, exact g.continuous, exact normed_group_hom.continuous _ }, { intros a, change (incl ≫ g) _ = (incl ≫ Completion.lift f) _, rw [lift_comp_incl, h] } end instance normed_with_aut_Completion (V : NormedGroup.{u}) (r : ℝ) [normed_with_aut r V] : normed_with_aut r (Completion.obj V) := { T := Completion.map_iso normed_with_aut.T, norm_T := begin rw ← function.funext_iff, refine abstract_completion.funext completion.cpkg _ _ _, { apply continuous_norm.comp _, exact completion.continuous_map }, { apply continuous_const.mul continuous_norm }, intro v, calc _ = _ : congr_arg norm (completion.map_coe _ _) ... = _ : _, { exact normed_group_hom.uniform_continuous _ }, { erw [completion.norm_coe, normed_with_aut.norm_T, completion.norm_coe] } end } @[simp] lemma Completion_T_inv_eq (V : NormedGroup.{u}) (r : ℝ) [normed_with_aut r V] : (normed_with_aut.T.hom : Completion.obj V ⟶ _) = Completion.map normed_with_aut.T.hom := rfl lemma T_hom_incl {V : NormedGroup} {r : ℝ} [normed_with_aut r V] : (incl : V ⟶ _) ≫ normed_with_aut.T.hom = normed_with_aut.T.hom ≫ incl := begin ext x, simp only [incl_to_fun, category_theory.coe_comp, Completion_T_inv_eq], change completion.map normed_with_aut.T.hom _ = _, rw completion.map_coe, exact normed_group_hom.uniform_continuous _, end lemma T_hom_eq {V : NormedGroup} {r : ℝ} [normed_with_aut r V] : normed_with_aut.T.hom = Completion.lift ((normed_with_aut.T.hom : V ⟶ V) ≫ incl) := lift_unique _ _ T_hom_incl /-- `LCC` (Locally Constant Completion) is the bifunctor that sends a normed abelian group `V` and a profinite space `S` to `V-hat(S)`. Here `V-hat(S)` is the completion (for the sup norm) of the locally constant functions `S → V`. -/ def LCC : NormedGroup ⥤ Profiniteᵒᵖ ⥤ NormedGroup := curry.obj ((uncurry.obj LocallyConstant) ⋙ Completion) lemma LCC_obj_map' (V : NormedGroup) {X Y : Profiniteᵒᵖ} (f : Y ⟶ X) : (LCC.obj V).map f = Completion.map ((LocallyConstant.obj V).map f) := begin delta LCC, simp only [curry.obj_obj_map, LocallyConstant_obj_map, functor.comp_map, uncurry.obj_map, nat_trans.id_app, functor.map_comp, functor.map_id, category_theory.functor.map_id], erw [← functor.map_comp, category.id_comp] end lemma LCC_obj_map (V : NormedGroup) {X Y : Profiniteᵒᵖ} (f : Y ⟶ X) (v : (LCC.obj V).obj Y) : (LCC.obj V).map f v = completion.map (locally_constant.comap f.unop) v := by { rw LCC_obj_map', refl } variables (S : Type*) [topological_space S] [compact_space S] @[simps] instance normed_with_aut_LocallyConstant (V : NormedGroup) (S : Profinite) (r : ℝ≥0) [normed_with_aut r V] [hr : fact (0 < r)] : normed_with_aut r ((LocallyConstant.obj V).obj (op S)) := { T := (LocallyConstant.map_iso normed_with_aut.T).app (op S), norm_T := begin rintro (f : locally_constant S V), show Sup _ = ↑r * Sup _, dsimp, simp only [normed_with_aut.norm_T], convert real.Sup_mul r _ hr, ext, simp only [exists_prop, set.mem_range, exists_exists_eq_and, set.mem_set_of_eq] end } instance normed_with_aut_LCC (V : NormedGroup) (S : Profinite) (r : ℝ≥0) [normed_with_aut r V] [hr : fact (0 < r)] : normed_with_aut r ((LCC.obj V).obj (op S)) := show normed_with_aut r (Completion.obj $ (LocallyConstant.obj V).obj (op S)), by apply_instance end NormedGroup #lint- only unused_arguments def_lemma doc_blame
65d32ccc95bdd073a3f50153311d7ee4618e480b
c3f2fcd060adfa2ca29f924839d2d925e8f2c685
/library/data/quotient/classical.lean
5f00ad1fda765772d40bdff30d25a7a813a5c535
[ "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
2,086
lean
-- Copyright (c) 2014 Floris van Doorn. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Author: Floris van Doorn import algebra.relation data.subtype logic.axioms.classical logic.axioms.hilbert logic.axioms.funext import .basic namespace quotient open relation nonempty subtype -- abstract quotient -- ----------------- definition prelim_map {A : Type} (R : A → A → Prop) (a : A) := -- TODO: it is interesting how the elaborator fails here -- epsilon (fun b, R a b) @epsilon _ (nonempty.intro a) (fun b, R a b) -- TODO: only needed R reflexive (or weaker: R a a) theorem prelim_map_rel {A : Type} {R : A → A → Prop} (H : is_equivalence R) (a : A) : R a (prelim_map R a) := have reflR : reflexive R, from is_equivalence.refl R, epsilon_spec (exists.intro a (reflR a)) -- TODO: only needed: R PER theorem prelim_map_congr {A : Type} {R : A → A → Prop} (H1 : is_equivalence R) {a b : A} (H2 : R a b) : prelim_map R a = prelim_map R b := have symmR : relation.symmetric R, from is_equivalence.symm R, have transR : relation.transitive R, from is_equivalence.trans R, have H3 : ∀c, R a c ↔ R b c, from take c, iff.intro (assume H4 : R a c, transR (symmR H2) H4) (assume H4 : R b c, transR H2 H4), have H4 : (fun c, R a c) = (fun c, R b c), from funext (take c, eq.of_iff (H3 c)), assert H5 : nonempty A, from nonempty.intro a, show epsilon (λc, R a c) = epsilon (λc, R b c), from congr_arg _ H4 definition quotient {A : Type} (R : A → A → Prop) : Type := image (prelim_map R) definition quotient_abs {A : Type} (R : A → A → Prop) : A → quotient R := fun_image (prelim_map R) definition quotient_elt_of {A : Type} (R : A → A → Prop) : quotient R → A := elt_of -- TODO: I had to make is_quotient transparent -- change this? theorem quotient_is_quotient {A : Type} (R : A → A → Prop) (H : is_equivalence R) : is_quotient R (quotient_abs R) (quotient_elt_of R) := representative_map_to_quotient_equiv H (prelim_map_rel H) (@prelim_map_congr _ _ H) end quotient
b3632898b6c6c706f1437469cc8bb8884f12306e
70f8755415fa7a17f87402cde4651e9f4db1b5bb
/src/pfunctor/basic.lean
39b12c75859361ed31d85286f4a9fe82c6201c82
[ "Apache-2.0" ]
permissive
shingarov/qpf
ab935dc2298db12c87ac011a2e4d2c27e0bdef4b
debe2eacb8cf46b21aba2eaf3f2e20940da0263b
refs/heads/master
1,653,705,576,607
1,570,136,035,000
1,570,136,035,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
5,552
lean
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Jeremy Avigad Polynomial functors. Also expresses the W-type construction as a polynomial functor. (For the M-type construction, see Mtype.lean.) -/ import tactic.interactive data.multiset universe u /- TODO (Jeremy): move this. -/ namespace functor variables {F : Type u → Type u} [functor F] def liftp {α : Type u} (p : α → Prop) : F α → Prop := λ x, ∃ u : F (subtype p), subtype.val <$> u = x def liftr {α β : Type u} (r : α → β → Prop) : F α → F β → Prop := λ x y, ∃ u : F {p : α × β // r p.fst p.snd}, (λ t : {p : α × β // r p.fst p.snd}, t.val.fst) <$> u = x ∧ (λ t : {p : α × β // r p.fst p.snd}, t.val.snd) <$> u = y def supp {α : Type u} (x : F α) : set α := { y : α | ∀ ⦃p⦄, liftp p x → p y } theorem of_mem_supp {α : Type u} {x : F α} {p : α → Prop} (h : liftp p x) : ∀ y ∈ supp x, p y := λ y hy, hy h end functor /- A polynomial functor `P` is given by a type `A` and a family `B` of types over `A`. `P` maps any type `α` to a new type `P.apply α`. An element of `P.apply α` is a pair `⟨a, f⟩`, where `a` is an element of a type `A` and `f : B a → α`. Think of `a` as the shape of the object and `f` as an index to the relevant elements of `α`. -/ structure pfunctor := (A : Type u) (B : A → Type u) namespace pfunctor variables (P : pfunctor) {α β : Type u} -- TODO: generalize to psigma? def apply (α : Type*) := Σ x : P.A, P.B x → α def map {α β : Type*} (f : α → β) : P.apply α → P.apply β := λ ⟨a, g⟩, ⟨a, f ∘ g⟩ instance : functor P.apply := {map := @map P} theorem map_eq {α β : Type*} (f : α → β) (a : P.A) (g : P.B a → α) : @functor.map P.apply _ _ _ f ⟨a, g⟩ = ⟨a, f ∘ g⟩ := rfl theorem id_map {α : Type*} : ∀ x : P.apply α, id <$> x = id x := λ ⟨a, b⟩, rfl theorem comp_map {α β γ : Type*} (f : α → β) (g : β → γ) : ∀ x : P.apply α, (g ∘ f) <$> x = g <$> (f <$> x) := λ ⟨a, b⟩, rfl instance : is_lawful_functor P.apply := {id_map := @id_map P, comp_map := @comp_map P} inductive W | mk (a : P.A) (f : P.B a → W) : W def W_dest : W P → P.apply (W P) | ⟨a, f⟩ := ⟨a, f⟩ def W_mk : P.apply (W P) → W P | ⟨a, f⟩ := ⟨a, f⟩ @[simp] theorem W_dest_W_mk (p : P.apply (W P)) : P.W_dest (P.W_mk p) = p := by cases p; reflexivity @[simp] theorem W_mk_W_dest (p : W P) : P.W_mk (P.W_dest p) = p := by cases p; reflexivity def Idx := Σ x : P.A, P.B x variables {P} def apply.iget [decidable_eq P.A] {α} [inhabited α] (x : P.apply α) (i : P.Idx) : α := if h : i.1 = x.1 then x.2 (cast (congr_arg _ h) i.2) else default _ @[simp] lemma fst_map {α β : Type u} (x : P.apply α) (f : α → β) : (f <$> x).1 = x.1 := by { cases x; refl } @[simp] lemma iget_map [decidable_eq P.A] {α β : Type u} [inhabited α] [inhabited β] (x : P.apply α) (f : α → β) (i : P.Idx) (h : i.1 = x.1) : (f <$> x).iget i = f (x.iget i) := by { simp [apply.iget], rw [dif_pos h,dif_pos]; cases x, refl, rw h, refl } end pfunctor /- Composition of polynomial functors. -/ namespace pfunctor /- def comp : pfunctor.{u} → pfunctor.{u} → pfunctor.{u} | ⟨A₂, B₂⟩ ⟨A₁, B₁⟩ := ⟨Σ a₂ : A₂, B₂ a₂ → A₁, λ ⟨a₂, a₁⟩, Σ u : B₂ a₂, B₁ (a₁ u)⟩ -/ def comp (P₂ P₁ : pfunctor.{u}) : pfunctor.{u} := ⟨ Σ a₂ : P₂.1, P₂.2 a₂ → P₁.1, λ a₂a₁, Σ u : P₂.2 a₂a₁.1, P₁.2 (a₂a₁.2 u) ⟩ def comp.mk (P₂ P₁ : pfunctor.{u}) {α : Type} (x : P₂.apply (P₁.apply α)) : (comp P₂ P₁).apply α := ⟨ ⟨ x.1, sigma.fst ∘ x.2 ⟩, λ a₂a₁, (x.2 a₂a₁.1).2 a₂a₁.2 ⟩ def comp.get (P₂ P₁ : pfunctor.{u}) {α : Type} (x : (comp P₂ P₁).apply α) : P₂.apply (P₁.apply α) := ⟨ x.1.1, λ a₂, ⟨x.1.2 a₂, λ a₁, x.2 ⟨a₂,a₁⟩ ⟩ ⟩ end pfunctor /- Lifting predicates and relations. -/ namespace pfunctor variables {P : pfunctor.{u}} open functor theorem liftp_iff {α : Type u} (p : α → Prop) (x : P.apply α) : liftp p x ↔ ∃ a f, x = ⟨a, f⟩ ∧ ∀ i, p (f i) := begin split, { rintros ⟨y, hy⟩, cases h : y with a f, refine ⟨a, λ i, (f i).val, _, λ i, (f i).property⟩, rw [←hy, h, map_eq] }, rintros ⟨a, f, xeq, pf⟩, use ⟨a, λ i, ⟨f i, pf i⟩⟩, rw [xeq], reflexivity end theorem liftr_iff {α : Type u} (r : α → α → Prop) (x y : P.apply α) : liftr r x y ↔ ∃ a f₀ f₁, x = ⟨a, f₀⟩ ∧ y = ⟨a, f₁⟩ ∧ ∀ i, r (f₀ i) (f₁ i) := begin split, { rintros ⟨u, xeq, yeq⟩, cases h : u with a f, use [a, λ i, (f i).val.fst, λ i, (f i).val.snd], split, { rw [←xeq, h], refl }, split, { rw [←yeq, h], refl }, intro i, exact (f i).property }, rintros ⟨a, f₀, f₁, xeq, yeq, h⟩, use ⟨a, λ i, ⟨(f₀ i, f₁ i), h i⟩⟩, dsimp, split, { rw [xeq], refl }, rw [yeq], refl end end pfunctor /- Facts about the general quotient needed to construct final coalgebras. TODO (Jeremy): move these somewhere. -/ namespace quot def factor {α : Type*} (r s: α → α → Prop) (h : ∀ x y, r x y → s x y) : quot r → quot s := quot.lift (quot.mk s) (λ x y rxy, quot.sound (h x y rxy)) def factor_mk_eq {α : Type*} (r s: α → α → Prop) (h : ∀ x y, r x y → s x y) : factor r s h ∘ quot.mk _= quot.mk _ := rfl end quot
5b5c2c26301f45238f25ff28f175f4fc878af4cd
302c785c90d40ad3d6be43d33bc6a558354cc2cf
/src/analysis/seminorm.lean
0397981b9c25729287e7b5b33cb85be2c620ea99
[ "Apache-2.0" ]
permissive
ilitzroth/mathlib
ea647e67f1fdfd19a0f7bdc5504e8acec6180011
5254ef14e3465f6504306132fe3ba9cec9ffff16
refs/heads/master
1,680,086,661,182
1,617,715,647,000
1,617,715,647,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
6,922
lean
/- Copyright (c) 2019 Jean Lo. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jean Lo -/ import algebra.pointwise import analysis.normed_space.basic /-! # Seminorms and Local Convexity This file introduces the following notions, defined for a vector space over a normed field: - the subset properties of being `absorbent` and `balanced`, - a `seminorm`, a function to the reals that is positive-semidefinite, absolutely homogeneous, and subadditive. We prove related properties. ## TODO Define and show equivalence of two notions of local convexity for a topological vector space over ℝ or ℂ: that it has a local base of balanced convex absorbent sets, and that it carries the initial topology induced by a family of seminorms. ## References * [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966] -/ /-! ### Subset Properties Absorbent and balanced sets in a vector space over a nondiscrete normed field. -/ section variables (𝕜 : Type*) [nondiscrete_normed_field 𝕜] {E : Type*} [add_comm_group E] [vector_space 𝕜 E] open set normed_field open_locale topological_space /-- A set `A` absorbs another set `B` if `B` is contained in scaling `A` by elements of sufficiently large norms. -/ def absorbs (A B : set E) := ∃ r > 0, ∀ a : 𝕜, r ≤ ∥a∥ → B ⊆ a • A /-- A set is absorbent if it absorbs every singleton. -/ def absorbent (A : set E) := ∀ x, ∃ r > 0, ∀ a : 𝕜, r ≤ ∥a∥ → x ∈ a • A /-- A set `A` is balanced if `a • A` is contained in `A` whenever `a` has norm no greater than one. -/ def balanced (A : set E) := ∀ a : 𝕜, ∥a∥ ≤ 1 → a • A ⊆ A variables {𝕜} (a : 𝕜) {A : set E} /-- A balanced set absorbs itself. -/ lemma balanced.absorbs_self (hA : balanced 𝕜 A) : absorbs 𝕜 A A := begin use [1, zero_lt_one], intros a ha x hx, rw mem_smul_set_iff_inv_smul_mem, { apply hA a⁻¹, { rw norm_inv, exact inv_le_one ha }, { rw mem_smul_set, use [x, hx] }}, { rw ←norm_pos_iff, calc 0 < 1 : zero_lt_one ... ≤ ∥a∥ : ha, } end /-! Properties of balanced and absorbing sets in a topological vector space: -/ variables [topological_space E] [has_continuous_smul 𝕜 E] /-- Every neighbourhood of the origin is absorbent. -/ lemma absorbent_nhds_zero (hA : A ∈ 𝓝 (0 : E)) : absorbent 𝕜 A := begin intro x, rcases mem_nhds_sets_iff.mp hA with ⟨w, hw₁, hw₂, hw₃⟩, have hc : continuous (λ t : 𝕜, t • x), from continuous_id.smul continuous_const, rcases metric.is_open_iff.mp (hw₂.preimage hc) 0 (by rwa [mem_preimage, zero_smul]) with ⟨r, hr₁, hr₂⟩, have hr₃, from inv_pos.mpr (half_pos hr₁), use [(r/2)⁻¹, hr₃], intros a ha₁, have ha₂ : 0 < ∥a∥, from calc 0 < _ : hr₃ ... ≤ _ : ha₁, have ha₃ : a ⁻¹ • x ∈ w, begin apply hr₂, rw [metric.mem_ball, dist_eq_norm, sub_zero, norm_inv], calc ∥a∥⁻¹ ≤ r/2 : (inv_le (half_pos hr₁) ha₂).mp ha₁ ... < r : half_lt_self hr₁, end, rw [mem_smul_set_iff_inv_smul_mem (norm_pos_iff.mp ha₂)], exact hw₁ ha₃, end /-- The union of `{0}` with the interior of a balanced set is balanced. -/ lemma balanced_zero_union_interior (hA : balanced 𝕜 A) : balanced 𝕜 ({(0 : E)} ∪ interior A) := begin intros a ha, by_cases a = 0, { rw [h, zero_smul_set], exacts [subset_union_left _ _, ⟨0, or.inl rfl⟩] }, { rw [←image_smul, image_union], apply union_subset_union, { rw [image_singleton, smul_zero] }, { calc a • interior A ⊆ interior (a • A) : (is_open_map_smul' h).image_interior_subset A ... ⊆ interior A : interior_mono (hA _ ha) } } end /-- The interior of a balanced set is balanced if it contains the origin. -/ lemma balanced.interior (hA : balanced 𝕜 A) (h : (0 : E) ∈ interior A) : balanced 𝕜 (interior A) := begin rw ←singleton_subset_iff at h, rw [←union_eq_self_of_subset_left h], exact balanced_zero_union_interior hA, end /-- The closure of a balanced set is balanced. -/ lemma balanced.closure (hA : balanced 𝕜 A) : balanced 𝕜 (closure A) := assume a ha, calc _ ⊆ closure (a • A) : image_closure_subset_closure_image (continuous_id.const_smul _) ... ⊆ _ : closure_mono (hA _ ha) end /-! ### Seminorms -/ /-- A seminorm on a vector space over a normed field is a function to the reals that is positive semidefinite, positive homogeneous, and subadditive. -/ structure seminorm (𝕜 : Type*) (E : Type*) [normed_field 𝕜] [add_comm_group E] [vector_space 𝕜 E] := (to_fun : E → ℝ) (smul' : ∀ (a : 𝕜) (x : E), to_fun (a • x) = ∥a∥ * to_fun x) (triangle' : ∀ x y : E, to_fun (x + y) ≤ to_fun x + to_fun y) variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜] {E : Type*} [add_comm_group E] [vector_space 𝕜 E] instance : inhabited (seminorm 𝕜 E) := ⟨{ to_fun := λ _, 0, smul' := λ _ _, (mul_zero _).symm, triangle' := λ x y, by rw add_zero }⟩ instance : has_coe_to_fun (seminorm 𝕜 E) := ⟨_, λ p, p.to_fun⟩ namespace seminorm variables (p : seminorm 𝕜 E) (c : 𝕜) (x y : E) (r : ℝ) protected lemma smul : p (c • x) = ∥c∥ * p x := p.smul' _ _ protected lemma triangle : p (x + y) ≤ p x + p y := p.triangle' _ _ @[simp] protected lemma zero : p 0 = 0 := calc p 0 = p ((0 : 𝕜) • 0) : by rw zero_smul ... = 0 : by rw [p.smul, norm_zero, zero_mul] @[simp] protected lemma neg : p (-x) = p x := calc p (-x) = p ((-1 : 𝕜) • x) : by rw neg_one_smul ... = p x : by rw [p.smul, norm_neg, norm_one, one_mul] lemma nonneg : 0 ≤ p x := have h: 0 ≤ 2 * p x, from calc 0 = p (x + (- x)) : by rw [add_neg_self, p.zero] ... ≤ p x + p (-x) : p.triangle _ _ ... = 2 * p x : by rw [p.neg, two_mul], nonneg_of_mul_nonneg_left h zero_lt_two lemma sub_rev : p (x - y) = p (y - x) := by rw [←neg_sub, p.neg] /-- The ball of radius `r` at `x` with respect to seminorm `p` is the set of elements `y` with `p (y - x) < `r`. -/ def ball (p : seminorm 𝕜 E) (x : E) (r : ℝ) := { y : E | p (y - x) < r } lemma mem_ball : y ∈ ball p x r ↔ p (y - x) < r := iff.rfl lemma mem_ball_zero : y ∈ ball p 0 r ↔ p y < r := by rw [mem_ball, sub_zero] lemma ball_zero_eq : ball p 0 r = { y : E | p y < r } := set.ext $ λ x,by { rw mem_ball_zero, exact iff.rfl } /-- Seminorm-balls at the origin are balanced. -/ lemma balanced_ball_zero : balanced 𝕜 (ball p 0 r) := begin rintro a ha x ⟨y, hy, hx⟩, rw [mem_ball_zero, ←hx, p.smul], calc _ ≤ p y : mul_le_of_le_one_left (p.nonneg _) ha ... < r : by rwa mem_ball_zero at hy, end -- TODO: convexity and absorbent/balanced sets in vector spaces over ℝ end seminorm -- TODO: the minkowski functional, topology induced by family of -- seminorms, local convexity.
2aaceb074dc84fc84d71b327c810a3527d37365f
ac2987d8c7832fb4a87edb6bee26141facbb6fa0
/Mathlib/SetNotation.lean
f987d25b411ceb22308ce902c9e94c7f15d5b819
[ "Apache-2.0" ]
permissive
AurelienSaue/mathlib4
52204b9bd9d207c922fe0cf3397166728bb6c2e2
84271fe0875bafdaa88ac41f1b5a7c18151bd0d5
refs/heads/master
1,689,156,096,545
1,629,378,840,000
1,629,378,840,000
389,648,603
0
0
Apache-2.0
1,627,307,284,000
1,627,307,284,000
null
UTF-8
Lean
false
false
983
lean
class Mem (α : outParam $ Type u) (γ : Type v) where mem : α → γ → Prop infix:50 " ∈ " => Mem.mem notation:50 x " ∉ " s => ¬ x ∈ s class Subset (α : Type u) where subset : α → α → Prop infix:50 " ⊆ " => Subset.subset class Union (α : Type u) where union : α → α → α infixl:65 " ∪ " => Union.union class Inter (α : Type u) where inter : α → α → α infixl:70 " ∩ " => Inter.inter class Sdiff (α : Type u) where sdiff : α → α → α infix:70 " \\ " => Sdiff.sdiff declare_syntax_cat binderterm -- notation for `a` or `a : A` or `a ∈ S` syntax ident : binderterm syntax ident " ∈ " term : binderterm syntax "∀ " binderterm ", " term : term syntax "∃ " binderterm ", " term : term macro_rules -- ∀ x ∈ s, p := ∀ x, x ∈ s → p | `(∀ $x:ident ∈ $s, $p) => `(∀ $x:ident, $x ∈ $s → $p) -- ∃ x ∈ s, p := ∃ x, x ∈ s ∧ p | `(∃ $x:ident ∈ $s, $p) => `(∃ $x:ident, $x ∈ $s ∧ $p)
d03648c3312fce1fe0374e2ef1afb7807538fee8
4727251e0cd73359b15b664c3170e5d754078599
/src/data/qpf/multivariate/constructions/quot.lean
d85cbbf011d4241fa0cc8e4db15c5ea9abd3ef90
[ "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,289
lean
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Simon Hudon -/ import data.qpf.multivariate.basic /-! # The quotient of QPF is itself a QPF The quotients are here defined using a surjective function and its right inverse. They are very similar to the `abs` and `repr` functions found in the definition of `mvqpf` -/ universes u open_locale mvfunctor namespace mvqpf variables {n : ℕ} variables {F : typevec.{u} n → Type u} section repr variables [mvfunctor F] [q : mvqpf F] variables {G : typevec.{u} n → Type u} [mvfunctor G] variable {FG_abs : Π {α}, F α → G α} variable {FG_repr : Π {α}, G α → F α} /-- If `F` is a QPF then `G` is a QPF as well. Can be used to construct `mvqpf` instances by transporting them across surjective functions -/ def quotient_qpf (FG_abs_repr : Π {α} (x : G α), FG_abs (FG_repr x) = x) (FG_abs_map : ∀ {α β} (f : α ⟹ β) (x : F α), FG_abs (f <$$> x) = f <$$> FG_abs x) : mvqpf G := { P := q.P, abs := λ α p, FG_abs (abs p), repr := λ α x, repr (FG_repr x), abs_repr := λ α x, by rw [abs_repr,FG_abs_repr], abs_map := λ α β f p, by rw [abs_map,FG_abs_map] } end repr section rel variables (R : ∀ ⦃α⦄, F α → F α → Prop) /-- Functorial quotient type -/ def quot1 (α : typevec n) := quot (@R α) instance quot1.inhabited {α : typevec n} [inhabited $ F α] : inhabited (quot1 R α) := ⟨ quot.mk _ default ⟩ variables [mvfunctor F] [q : mvqpf F] variables (Hfunc : ∀ ⦃α β⦄ (a b : F α) (f : α ⟹ β), R a b → R (f <$$> a) (f <$$> b)) /-- `map` of the `quot1` functor -/ def quot1.map ⦃α β⦄ (f : α ⟹ β) : quot1.{u} R α → quot1.{u} R β := quot.lift (λ x : F α, quot.mk _ (f <$$> x : F β)) $ λ a b h, quot.sound $ Hfunc a b _ h /-- `mvfunctor` instance for `quot1` with well-behaved `R` -/ def quot1.mvfunctor : mvfunctor (quot1 R) := { map := quot1.map R Hfunc } /-- `quot1` is a qpf -/ noncomputable def rel_quot : @mvqpf _ (quot1 R) (mvqpf.quot1.mvfunctor R Hfunc) := @quotient_qpf n F _ q _ (mvqpf.quot1.mvfunctor R Hfunc) (λ α x, quot.mk _ x) (λ α, quot.out) (λ α x, quot.out_eq _) (λ α β f x, rfl) end rel end mvqpf
9acd525e930d4b75ebfd4398d6aa6a822ab37283
968e2f50b755d3048175f176376eff7139e9df70
/examples/prop_logic_theory/unnamed_583.lean
2948aa6be39c00a103b47f41019ecc8d0fa07e79
[]
no_license
gihanmarasingha/mth1001_sphinx
190a003269ba5e54717b448302a27ca26e31d491
05126586cbf5786e521be1ea2ef5b4ba3c44e74a
refs/heads/master
1,672,913,933,677
1,604,516,583,000
1,604,516,583,000
309,245,750
1
0
null
null
null
null
UTF-8
Lean
false
false
309
lean
variables p q r : Prop -- BEGIN example (h₁ : p → q) (h₂ : q → r) (h₃ : p) : r := begin have h₄ : q, from h₁ h₃, -- We have `h₄ : q`, by implication elimination on `h₁` and `h₃`. show r, from h₂ h₄ -- We show `r` by implication elimination on `h₂` and `h₄`. end -- END
d6e823a23e1446c99568d764f301b4e438c556ac
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/group_theory/perm/sign.lean
e89ae7400e6c3545c5313dc98f2fe71e35d70df0
[ "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
31,327
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 group_theory.perm.support import group_theory.order_of_element import data.finset.fin import data.int.order.units /-! # Sign of a permutation The main definition of this file is `equiv.perm.sign`, associating a `ℤˣ` sign with a permutation. This file also contains miscellaneous lemmas about `equiv.perm` and `equiv.swap`, building on top of those in `data/equiv/basic` and other files in `group_theory/perm/*`. -/ universes u v open equiv function fintype finset open_locale big_operators variables {α : Type u} {β : Type v} -- An example on how to determine the order of an element of a finite group. example : order_of (-1 : ℤˣ) = 2 := order_of_eq_prime (int.units_sq _) dec_trivial namespace equiv.perm /-- `mod_swap i j` contains permutations up to swapping `i` and `j`. We use this to partition permutations in `matrix.det_zero_of_row_eq`, such that each partition sums up to `0`. -/ def mod_swap [decidable_eq α] (i j : α) : setoid (perm α) := ⟨λ σ τ, σ = τ ∨ σ = swap i j * τ, λ σ, or.inl (refl σ), λ σ τ h, or.cases_on h (λ h, or.inl h.symm) (λ h, or.inr (by rw [h, swap_mul_self_mul])), λ σ τ υ hστ hτυ, by cases hστ; cases hτυ; try {rw [hστ, hτυ, swap_mul_self_mul]}; simp [hστ, hτυ] ⟩ instance {α : Type*} [fintype α] [decidable_eq α] (i j : α) : decidable_rel (mod_swap i j).r := λ σ τ, or.decidable lemma perm_inv_on_of_perm_on_finset {s : finset α} {f : perm α} (h : ∀ x ∈ s, f x ∈ s) {y : α} (hy : y ∈ s) : f⁻¹ y ∈ s := begin have h0 : ∀ y ∈ s, ∃ x (hx : x ∈ s), y = (λ i (hi : i ∈ s), f i) x hx := finset.surj_on_of_inj_on_of_card_le (λ x hx, (λ i hi, f i) x hx) (λ a ha, h a ha) (λ a₁ a₂ ha₁ ha₂ heq, (equiv.apply_eq_iff_eq f).mp heq) rfl.ge, obtain ⟨y2, hy2, heq⟩ := h0 y hy, convert hy2, rw heq, simp only [inv_apply_self] end lemma perm_inv_maps_to_of_maps_to (f : perm α) {s : set α} [finite s] (h : set.maps_to f s s) : set.maps_to (f⁻¹ : _) s s := by casesI nonempty_fintype s; exact λ x hx, set.mem_to_finset.mp $ perm_inv_on_of_perm_on_finset (λ a ha, set.mem_to_finset.mpr (h (set.mem_to_finset.mp ha))) (set.mem_to_finset.mpr hx) @[simp] lemma perm_inv_maps_to_iff_maps_to {f : perm α} {s : set α} [finite s] : set.maps_to (f⁻¹ : _) s s ↔ set.maps_to f s s := ⟨perm_inv_maps_to_of_maps_to f⁻¹, perm_inv_maps_to_of_maps_to f⟩ lemma perm_inv_on_of_perm_on_finite {f : perm α} {p : α → Prop} [finite {x // p x}] (h : ∀ x, p x → p (f x)) {x : α} (hx : p x) : p (f⁻¹ x) := perm_inv_maps_to_of_maps_to f h hx /-- If the permutation `f` maps `{x // p x}` into itself, then this returns the permutation on `{x // p x}` induced by `f`. Note that the `h` hypothesis is weaker than for `equiv.perm.subtype_perm`. -/ abbreviation subtype_perm_of_fintype (f : perm α) {p : α → Prop} [fintype {x // p x}] (h : ∀ x, p x → p (f x)) : perm {x // p x} := f.subtype_perm (λ x, ⟨h x, λ h₂, f.inv_apply_self x ▸ perm_inv_on_of_perm_on_finite h h₂⟩) @[simp] lemma subtype_perm_of_fintype_apply (f : perm α) {p : α → Prop} [fintype {x // p x}] (h : ∀ x, p x → p (f x)) (x : {x // p x}) : subtype_perm_of_fintype f h x = ⟨f x, h x x.2⟩ := rfl @[simp] lemma subtype_perm_of_fintype_one (p : α → Prop) [fintype {x // p x}] (h : ∀ x, p x → p ((1 : perm α) x)) : @subtype_perm_of_fintype α 1 p _ h = 1 := equiv.ext $ λ ⟨_, _⟩, rfl lemma perm_maps_to_inl_iff_maps_to_inr {m n : Type*} [finite m] [finite n] (σ : perm (m ⊕ n)) : set.maps_to σ (set.range sum.inl) (set.range sum.inl) ↔ set.maps_to σ (set.range sum.inr) (set.range sum.inr) := begin casesI nonempty_fintype m, casesI nonempty_fintype n, split; id { intros h, classical, rw ←perm_inv_maps_to_iff_maps_to at h, intro x, cases hx : σ x with l r, }, { rintros ⟨a, rfl⟩, obtain ⟨y, hy⟩ := h ⟨l, rfl⟩, rw [←hx, σ.inv_apply_self] at hy, exact absurd hy sum.inl_ne_inr}, { rintros ⟨a, ha⟩, exact ⟨r, rfl⟩, }, { rintros ⟨a, ha⟩, exact ⟨l, rfl⟩, }, { rintros ⟨a, rfl⟩, obtain ⟨y, hy⟩ := h ⟨r, rfl⟩, rw [←hx, σ.inv_apply_self] at hy, exact absurd hy sum.inr_ne_inl}, end lemma mem_sum_congr_hom_range_of_perm_maps_to_inl {m n : Type*} [finite m] [finite n] {σ : perm (m ⊕ n)} (h : set.maps_to σ (set.range sum.inl) (set.range sum.inl)) : σ ∈ (sum_congr_hom m n).range := begin casesI nonempty_fintype m, casesI nonempty_fintype n, classical, have h1 : ∀ (x : m ⊕ n), (∃ (a : m), sum.inl a = x) → (∃ (a : m), sum.inl a = σ x), { rintros x ⟨a, ha⟩, apply h, rw ← ha, exact ⟨a, rfl⟩ }, have h3 : ∀ (x : m ⊕ n), (∃ (b : n), sum.inr b = x) → (∃ (b : n), sum.inr b = σ x), { rintros x ⟨b, hb⟩, apply (perm_maps_to_inl_iff_maps_to_inr σ).mp h, rw ← hb, exact ⟨b, rfl⟩ }, let σ₁' := subtype_perm_of_fintype σ h1, let σ₂' := subtype_perm_of_fintype σ h3, let σ₁ := perm_congr (equiv.of_injective _ sum.inl_injective).symm σ₁', let σ₂ := perm_congr (equiv.of_injective _ sum.inr_injective).symm σ₂', rw [monoid_hom.mem_range, prod.exists], use [σ₁, σ₂], rw [perm.sum_congr_hom_apply], ext, cases x with a b, { rw [equiv.sum_congr_apply, sum.map_inl, perm_congr_apply, equiv.symm_symm, apply_of_injective_symm sum.inl_injective], erw subtype_perm_apply, rw [of_injective_apply, subtype.coe_mk, subtype.coe_mk] }, { rw [equiv.sum_congr_apply, sum.map_inr, perm_congr_apply, equiv.symm_symm, apply_of_injective_symm sum.inr_injective], erw subtype_perm_apply, rw [of_injective_apply, subtype.coe_mk, subtype.coe_mk] } end lemma disjoint.order_of {σ τ : perm α} (hστ : disjoint σ τ) : order_of (σ * τ) = nat.lcm (order_of σ) (order_of τ) := begin have h : ∀ n : ℕ, (σ * τ) ^ n = 1 ↔ σ ^ n = 1 ∧ τ ^ n = 1 := λ n, by rw [hστ.commute.mul_pow, disjoint.mul_eq_one_iff (hστ.pow_disjoint_pow n n)], exact nat.dvd_antisymm hστ.commute.order_of_mul_dvd_lcm (nat.lcm_dvd (order_of_dvd_of_pow_eq_one ((h (order_of (σ * τ))).mp (pow_order_of_eq_one (σ * τ))).1) (order_of_dvd_of_pow_eq_one ((h (order_of (σ * τ))).mp (pow_order_of_eq_one (σ * τ))).2)), end lemma disjoint.extend_domain {α : Type*} {p : β → Prop} [decidable_pred p] (f : α ≃ subtype p) {σ τ : perm α} (h : disjoint σ τ) : disjoint (σ.extend_domain f) (τ.extend_domain f) := begin intro b, by_cases pb : p b, { refine (h (f.symm ⟨b, pb⟩)).imp _ _; { intro h, rw [extend_domain_apply_subtype _ _ pb, h, apply_symm_apply, subtype.coe_mk] } }, { left, rw [extend_domain_apply_not_subtype _ _ pb] } end variable [decidable_eq α] section fintype variable [fintype α] lemma support_pow_coprime {σ : perm α} {n : ℕ} (h : nat.coprime n (order_of σ)) : (σ ^ n).support = σ.support := begin obtain ⟨m, hm⟩ := exists_pow_eq_self_of_coprime h, exact le_antisymm (support_pow_le σ n) (le_trans (ge_of_eq (congr_arg support hm)) (support_pow_le (σ ^ n) m)), end end fintype /-- Given a list `l : list α` and a permutation `f : perm α` such that the nonfixed points of `f` are in `l`, recursively factors `f` as a product of transpositions. -/ def swap_factors_aux : Π (l : list α) (f : perm α), (∀ {x}, f x ≠ x → x ∈ l) → {l : list (perm α) // l.prod = f ∧ ∀ g ∈ l, is_swap g} | [] := λ f h, ⟨[], equiv.ext $ λ x, by { rw [list.prod_nil], exact (not_not.1 (mt h (list.not_mem_nil _))).symm }, by simp⟩ | (x :: l) := λ f h, if hfx : x = f x then swap_factors_aux l f (λ y hy, list.mem_of_ne_of_mem (λ h : y = x, by simpa [h, hfx.symm] using hy) (h hy)) else let m := swap_factors_aux l (swap x (f x) * f) (λ y hy, have f y ≠ y ∧ y ≠ x, from ne_and_ne_of_swap_mul_apply_ne_self hy, list.mem_of_ne_of_mem this.2 (h this.1)) in ⟨swap x (f x) :: m.1, by rw [list.prod_cons, m.2.1, ← mul_assoc, mul_def (swap x (f x)), swap_swap, ← one_def, one_mul], λ g hg, ((list.mem_cons_iff _ _ _).1 hg).elim (λ h, ⟨x, f x, hfx, h⟩) (m.2.2 _)⟩ /-- `swap_factors` represents a permutation as a product of a list of transpositions. The representation is non unique and depends on the linear order structure. For types without linear order `trunc_swap_factors` can be used. -/ def swap_factors [fintype α] [linear_order α] (f : perm α) : {l : list (perm α) // l.prod = f ∧ ∀ g ∈ l, is_swap g} := swap_factors_aux ((@univ α _).sort (≤)) f (λ _ _, (mem_sort _).2 (mem_univ _)) /-- This computably represents the fact that any permutation can be represented as the product of a list of transpositions. -/ def trunc_swap_factors [fintype α] (f : perm α) : trunc {l : list (perm α) // l.prod = f ∧ ∀ g ∈ l, is_swap g} := quotient.rec_on_subsingleton (@univ α _).1 (λ l h, trunc.mk (swap_factors_aux l f h)) (show ∀ x, f x ≠ x → x ∈ (@univ α _).1, from λ _ _, mem_univ _) /-- An induction principle for permutations. If `P` holds for the identity permutation, and is preserved under composition with a non-trivial swap, then `P` holds for all permutations. -/ @[elab_as_eliminator] lemma swap_induction_on [finite α] {P : perm α → Prop} (f : perm α) : P 1 → (∀ f x y, x ≠ y → P f → P (swap x y * f)) → P f := begin casesI nonempty_fintype α, cases (trunc_swap_factors f).out with l hl, induction l with g l ih generalizing f, { simp only [hl.left.symm, list.prod_nil, forall_true_iff] {contextual := tt} }, { assume h1 hmul_swap, rcases hl.2 g (by simp) with ⟨x, y, hxy⟩, rw [← hl.1, list.prod_cons, hxy.2], exact hmul_swap _ _ _ hxy.1 (ih _ ⟨rfl, λ v hv, hl.2 _ (list.mem_cons_of_mem _ hv)⟩ h1 hmul_swap) } end lemma closure_is_swap [finite α] : subgroup.closure {σ : perm α | is_swap σ} = ⊤ := begin casesI nonempty_fintype α, refine eq_top_iff.mpr (λ x hx, _), obtain ⟨h1, h2⟩ := subtype.mem (trunc_swap_factors x).out, rw ← h1, exact subgroup.list_prod_mem _ (λ y hy, subgroup.subset_closure (h2 y hy)), end /-- Like `swap_induction_on`, but with the composition on the right of `f`. An induction principle for permutations. If `P` holds for the identity permutation, and is preserved under composition with a non-trivial swap, then `P` holds for all permutations. -/ @[elab_as_eliminator] lemma swap_induction_on' [finite α] {P : perm α → Prop} (f : perm α) : P 1 → (∀ f x y, x ≠ y → P f → P (f * swap x y)) → P f := λ h1 IH, inv_inv f ▸ swap_induction_on f⁻¹ h1 (λ f, IH f⁻¹) lemma is_conj_swap {w x y z : α} (hwx : w ≠ x) (hyz : y ≠ z) : is_conj (swap w x) (swap y z) := is_conj_iff.2 (have h : ∀ {y z : α}, y ≠ z → w ≠ z → (swap w y * swap x z) * swap w x * (swap w y * swap x z)⁻¹ = swap y z := λ y z hyz hwz, by rw [mul_inv_rev, swap_inv, swap_inv, mul_assoc (swap w y), mul_assoc (swap w y), ← mul_assoc _ (swap x z), swap_mul_swap_mul_swap hwx hwz, ← mul_assoc, swap_mul_swap_mul_swap hwz.symm hyz.symm], if hwz : w = z then have hwy : w ≠ y, by cc, ⟨swap w z * swap x y, by rw [swap_comm y z, h hyz.symm hwy]⟩ else ⟨swap w y * swap x z, h hyz hwz⟩) /-- set of all pairs (⟨a, b⟩ : Σ a : fin n, fin n) such that b < a -/ def fin_pairs_lt (n : ℕ) : finset (Σ a : fin n, fin n) := (univ : finset (fin n)).sigma (λ a, (range a).attach_fin (λ m hm, (mem_range.1 hm).trans a.2)) lemma mem_fin_pairs_lt {n : ℕ} {a : Σ a : fin n, fin n} : a ∈ fin_pairs_lt n ↔ a.2 < a.1 := by simp only [fin_pairs_lt, fin.lt_iff_coe_lt_coe, true_and, mem_attach_fin, mem_range, mem_univ, mem_sigma] /-- `sign_aux σ` is the sign of a permutation on `fin n`, defined as the parity of the number of pairs `(x₁, x₂)` such that `x₂ < x₁` but `σ x₁ ≤ σ x₂` -/ def sign_aux {n : ℕ} (a : perm (fin n)) : ℤˣ := ∏ x in fin_pairs_lt n, if a x.1 ≤ a x.2 then -1 else 1 @[simp] lemma sign_aux_one (n : ℕ) : sign_aux (1 : perm (fin n)) = 1 := begin unfold sign_aux, conv { to_rhs, rw ← @finset.prod_const_one ℤˣ _ (fin_pairs_lt n) }, exact finset.prod_congr rfl (λ a ha, if_neg (mem_fin_pairs_lt.1 ha).not_le) end /-- `sign_bij_aux f ⟨a, b⟩` returns the pair consisting of `f a` and `f b` in decreasing order. -/ def sign_bij_aux {n : ℕ} (f : perm (fin n)) (a : Σ a : fin n, fin n) : Σ a : fin n, fin n := if hxa : f a.2 < f a.1 then ⟨f a.1, f a.2⟩ else ⟨f a.2, f a.1⟩ lemma sign_bij_aux_inj {n : ℕ} {f : perm (fin n)} : ∀ a b : Σ a : fin n, fin n, a ∈ fin_pairs_lt n → b ∈ fin_pairs_lt n → sign_bij_aux f a = sign_bij_aux f b → a = b := λ ⟨a₁, a₂⟩ ⟨b₁, b₂⟩ ha hb h, begin unfold sign_bij_aux at h, rw mem_fin_pairs_lt at *, have : ¬b₁ < b₂ := hb.le.not_lt, split_ifs at h; simp only [*, (equiv.injective f).eq_iff, eq_self_iff_true, and_self, heq_iff_eq] at *, end lemma sign_bij_aux_surj {n : ℕ} {f : perm (fin n)} : ∀ a ∈ fin_pairs_lt n, ∃ b ∈ fin_pairs_lt n, a = sign_bij_aux f b := λ ⟨a₁, a₂⟩ ha, if hxa : f⁻¹ a₂ < f⁻¹ a₁ then ⟨⟨f⁻¹ a₁, f⁻¹ a₂⟩, mem_fin_pairs_lt.2 hxa, by { dsimp [sign_bij_aux], rw [apply_inv_self, apply_inv_self, if_pos (mem_fin_pairs_lt.1 ha)] }⟩ else ⟨⟨f⁻¹ a₂, f⁻¹ a₁⟩, mem_fin_pairs_lt.2 $ (le_of_not_gt hxa).lt_of_ne $ λ h, by simpa [mem_fin_pairs_lt, (f⁻¹).injective h, lt_irrefl] using ha, by { dsimp [sign_bij_aux], rw [apply_inv_self, apply_inv_self, if_neg (mem_fin_pairs_lt.1 ha).le.not_lt] }⟩ lemma sign_bij_aux_mem {n : ℕ} {f : perm (fin n)} : ∀ a : Σ a : fin n, fin n, a ∈ fin_pairs_lt n → sign_bij_aux f a ∈ fin_pairs_lt n := λ ⟨a₁, a₂⟩ ha, begin unfold sign_bij_aux, split_ifs with h, { exact mem_fin_pairs_lt.2 h }, { exact mem_fin_pairs_lt.2 ((le_of_not_gt h).lt_of_ne (λ h, (mem_fin_pairs_lt.1 ha).ne (f.injective h.symm))) } end @[simp] lemma sign_aux_inv {n : ℕ} (f : perm (fin n)) : sign_aux f⁻¹ = sign_aux f := prod_bij (λ a ha, sign_bij_aux f⁻¹ a) sign_bij_aux_mem (λ ⟨a, b⟩ hab, if h : f⁻¹ b < f⁻¹ a then by rw [sign_bij_aux, dif_pos h, if_neg h.not_le, apply_inv_self, apply_inv_self, if_neg (mem_fin_pairs_lt.1 hab).not_le] else by rw [sign_bij_aux, if_pos (le_of_not_gt h), dif_neg h, apply_inv_self, apply_inv_self, if_pos (mem_fin_pairs_lt.1 hab).le]) sign_bij_aux_inj sign_bij_aux_surj lemma sign_aux_mul {n : ℕ} (f g : perm (fin n)) : sign_aux (f * g) = sign_aux f * sign_aux g := begin rw ← sign_aux_inv g, unfold sign_aux, rw ← prod_mul_distrib, refine prod_bij (λ a ha, sign_bij_aux g a) sign_bij_aux_mem _ sign_bij_aux_inj sign_bij_aux_surj, rintros ⟨a, b⟩ hab, rw [sign_bij_aux, mul_apply, mul_apply], rw mem_fin_pairs_lt at hab, by_cases h : g b < g a, { rw dif_pos h, simp only [not_le_of_gt hab, mul_one, perm.inv_apply_self, if_false] }, { rw [dif_neg h, inv_apply_self, inv_apply_self, if_pos hab.le], by_cases h₁ : f (g b) ≤ f (g a), { have : f (g b) ≠ f (g a), { rw [ne.def, f.injective.eq_iff, g.injective.eq_iff], exact ne_of_lt hab }, rw [if_pos h₁, if_neg (h₁.lt_of_ne this).not_le], refl }, { rw [if_neg h₁, if_pos (lt_of_not_ge h₁).le], refl } } end private lemma sign_aux_swap_zero_one' (n : ℕ) : sign_aux (swap (0 : fin (n + 2)) 1) = -1 := show _ = ∏ x : Σ a : fin (n + 2), fin (n + 2) in {(⟨1, 0⟩ : Σ a : fin (n + 2), fin (n + 2))}, if (equiv.swap 0 1) x.1 ≤ swap 0 1 x.2 then (-1 : ℤˣ) else 1, begin refine eq.symm (prod_subset (λ ⟨x₁, x₂⟩, by simp [mem_fin_pairs_lt, fin.one_pos] {contextual := tt}) (λ a ha₁ ha₂, _)), rcases a with ⟨a₁, a₂⟩, replace ha₁ : a₂ < a₁ := mem_fin_pairs_lt.1 ha₁, dsimp only, rcases a₁.zero_le.eq_or_lt with rfl|H, { exact absurd a₂.zero_le ha₁.not_le }, rcases a₂.zero_le.eq_or_lt with rfl|H', { simp only [and_true, eq_self_iff_true, heq_iff_eq, mem_singleton] at ha₂, have : 1 < a₁ := lt_of_le_of_ne (nat.succ_le_of_lt ha₁) (ne.symm ha₂), have h01 : equiv.swap (0 : fin (n + 2)) 1 0 = 1, by simp, -- TODO : fix properly norm_num [swap_apply_of_ne_of_ne (ne_of_gt H) ha₂, this.not_le, h01] }, { have le : 1 ≤ a₂ := nat.succ_le_of_lt H', have lt : 1 < a₁ := le.trans_lt ha₁, have h01 : equiv.swap (0 : fin (n + 2)) 1 1 = 0, by simp, -- TODO rcases le.eq_or_lt with rfl|lt', { norm_num [swap_apply_of_ne_of_ne H.ne' lt.ne', H.not_le, h01] }, { norm_num [swap_apply_of_ne_of_ne (ne_of_gt H) (ne_of_gt lt), swap_apply_of_ne_of_ne (ne_of_gt H') (ne_of_gt lt'), ha₁.not_le] } } end private lemma sign_aux_swap_zero_one {n : ℕ} (hn : 2 ≤ n) : sign_aux (swap (⟨0, lt_of_lt_of_le dec_trivial hn⟩ : fin n) ⟨1, lt_of_lt_of_le dec_trivial hn⟩) = -1 := begin rcases n with _|_|n, { norm_num at hn }, { norm_num at hn }, { exact sign_aux_swap_zero_one' n } end lemma sign_aux_swap : ∀ {n : ℕ} {x y : fin n} (hxy : x ≠ y), sign_aux (swap x y) = -1 | 0 := dec_trivial | 1 := dec_trivial | (n+2) := λ x y hxy, have h2n : 2 ≤ n + 2 := dec_trivial, by { rw [← is_conj_iff_eq, ← sign_aux_swap_zero_one h2n], exact (monoid_hom.mk' sign_aux sign_aux_mul).map_is_conj (is_conj_swap hxy dec_trivial) } /-- When the list `l : list α` contains all nonfixed points of the permutation `f : perm α`, `sign_aux2 l f` recursively calculates the sign of `f`. -/ def sign_aux2 : list α → perm α → ℤˣ | [] f := 1 | (x::l) f := if x = f x then sign_aux2 l f else -sign_aux2 l (swap x (f x) * f) lemma sign_aux_eq_sign_aux2 {n : ℕ} : ∀ (l : list α) (f : perm α) (e : α ≃ fin n) (h : ∀ x, f x ≠ x → x ∈ l), sign_aux ((e.symm.trans f).trans e) = sign_aux2 l f | [] f e h := have f = 1, from equiv.ext $ λ y, not_not.1 (mt (h y) (list.not_mem_nil _)), by rw [this, one_def, equiv.trans_refl, equiv.symm_trans_self, ← one_def, sign_aux_one, sign_aux2] | (x::l) f e h := begin rw sign_aux2, by_cases hfx : x = f x, { rw if_pos hfx, exact sign_aux_eq_sign_aux2 l f _ (λ y (hy : f y ≠ y), list.mem_of_ne_of_mem (λ h : y = x, by simpa [h, hfx.symm] using hy) (h y hy) ) }, { have hy : ∀ y : α, (swap x (f x) * f) y ≠ y → y ∈ l, from λ y hy, have f y ≠ y ∧ y ≠ x, from ne_and_ne_of_swap_mul_apply_ne_self hy, list.mem_of_ne_of_mem this.2 (h _ this.1), have : (e.symm.trans (swap x (f x) * f)).trans e = (swap (e x) (e (f x))) * (e.symm.trans f).trans e, by ext; simp [← equiv.symm_trans_swap_trans, mul_def], have hefx : e x ≠ e (f x), from mt e.injective.eq_iff.1 hfx, rw [if_neg hfx, ← sign_aux_eq_sign_aux2 _ _ e hy, this, sign_aux_mul, sign_aux_swap hefx], simp only [neg_neg, one_mul, neg_mul]} end /-- When the multiset `s : multiset α` contains all nonfixed points of the permutation `f : perm α`, `sign_aux2 f _` recursively calculates the sign of `f`. -/ def sign_aux3 [fintype α] (f : perm α) {s : multiset α} : (∀ x, x ∈ s) → ℤˣ := quotient.hrec_on s (λ l h, sign_aux2 l f) (trunc.induction_on (fintype.trunc_equiv_fin α) (λ e l₁ l₂ h, function.hfunext (show (∀ x, x ∈ l₁) = ∀ x, x ∈ l₂, by simp only [h.mem_iff]) (λ h₁ h₂ _, by rw [← sign_aux_eq_sign_aux2 _ _ e (λ _ _, h₁ _), ← sign_aux_eq_sign_aux2 _ _ e (λ _ _, h₂ _)]))) lemma sign_aux3_mul_and_swap [fintype α] (f g : perm α) (s : multiset α) (hs : ∀ x, x ∈ s) : sign_aux3 (f * g) hs = sign_aux3 f hs * sign_aux3 g hs ∧ ∀ x y, x ≠ y → sign_aux3 (swap x y) hs = -1 := let ⟨l, hl⟩ := quotient.exists_rep s in let e := equiv_fin α in begin clear _let_match, subst hl, show sign_aux2 l (f * g) = sign_aux2 l f * sign_aux2 l g ∧ ∀ x y, x ≠ y → sign_aux2 l (swap x y) = -1, have hfg : (e.symm.trans (f * g)).trans e = (e.symm.trans f).trans e * (e.symm.trans g).trans e, from equiv.ext (λ h, by simp [mul_apply]), split, { rw [← sign_aux_eq_sign_aux2 _ _ e (λ _ _, hs _), ← sign_aux_eq_sign_aux2 _ _ e (λ _ _, hs _), ← sign_aux_eq_sign_aux2 _ _ e (λ _ _, hs _), hfg, sign_aux_mul] }, { assume x y hxy, have hexy : e x ≠ e y, from mt e.injective.eq_iff.1 hxy, rw [← sign_aux_eq_sign_aux2 _ _ e (λ _ _, hs _), symm_trans_swap_trans, sign_aux_swap hexy] } end /-- `sign` of a permutation returns the signature or parity of a permutation, `1` for even permutations, `-1` for odd permutations. It is the unique surjective group homomorphism from `perm α` to the group with two elements.-/ def sign [fintype α] : perm α →* ℤˣ := monoid_hom.mk' (λ f, sign_aux3 f mem_univ) (λ f g, (sign_aux3_mul_and_swap f g _ mem_univ).1) section sign variable [fintype α] @[simp] lemma sign_mul (f g : perm α) : sign (f * g) = sign f * sign g := monoid_hom.map_mul sign f g @[simp] lemma sign_trans (f g : perm α) : sign (f.trans g) = sign g * sign f := by rw [←mul_def, sign_mul] @[simp] lemma sign_one : (sign (1 : perm α)) = 1 := monoid_hom.map_one sign @[simp] lemma sign_refl : sign (equiv.refl α) = 1 := monoid_hom.map_one sign @[simp] lemma sign_inv (f : perm α) : sign f⁻¹ = sign f := by rw [monoid_hom.map_inv sign f, int.units_inv_eq_self] @[simp] lemma sign_symm (e : perm α) : sign e.symm = sign e := sign_inv e lemma sign_swap {x y : α} (h : x ≠ y) : sign (swap x y) = -1 := (sign_aux3_mul_and_swap 1 1 _ mem_univ).2 x y h @[simp] lemma sign_swap' {x y : α} : (swap x y).sign = if x = y then 1 else -1 := if H : x = y then by simp [H, swap_self] else by simp [sign_swap H, H] lemma is_swap.sign_eq {f : perm α} (h : f.is_swap) : sign f = -1 := let ⟨x, y, hxy⟩ := h in hxy.2.symm ▸ sign_swap hxy.1 lemma sign_aux3_symm_trans_trans [decidable_eq β] [fintype β] (f : perm α) (e : α ≃ β) {s : multiset α} {t : multiset β} (hs : ∀ x, x ∈ s) (ht : ∀ x, x ∈ t) : sign_aux3 ((e.symm.trans f).trans e) ht = sign_aux3 f hs := quotient.induction_on₂ t s (λ l₁ l₂ h₁ h₂, show sign_aux2 _ _ = sign_aux2 _ _, from let n := equiv_fin β in by { rw [← sign_aux_eq_sign_aux2 _ _ n (λ _ _, h₁ _), ← sign_aux_eq_sign_aux2 _ _ (e.trans n) (λ _ _, h₂ _)], exact congr_arg sign_aux (equiv.ext (λ x, by simp only [equiv.coe_trans, apply_eq_iff_eq, symm_trans_apply])) }) ht hs @[simp] lemma sign_symm_trans_trans [decidable_eq β] [fintype β] (f : perm α) (e : α ≃ β) : sign ((e.symm.trans f).trans e) = sign f := sign_aux3_symm_trans_trans f e mem_univ mem_univ @[simp] lemma sign_trans_trans_symm [decidable_eq β] [fintype β] (f : perm β) (e : α ≃ β) : sign ((e.trans f).trans e.symm) = sign f := sign_symm_trans_trans f e.symm lemma sign_prod_list_swap {l : list (perm α)} (hl : ∀ g ∈ l, is_swap g) : sign l.prod = (-1) ^ l.length := have h₁ : l.map sign = list.repeat (-1) l.length := list.eq_repeat.2 ⟨by simp, λ u hu, let ⟨g, hg⟩ := list.mem_map.1 hu in hg.2 ▸ (hl _ hg.1).sign_eq⟩, by rw [← list.prod_repeat, ← h₁, list.prod_hom _ (@sign α _ _)] variable (α) lemma sign_surjective [nontrivial α] : function.surjective (sign : perm α → ℤˣ) := λ a, (int.units_eq_one_or a).elim (λ h, ⟨1, by simp [h]⟩) (λ h, let ⟨x, y, hxy⟩ := exists_pair_ne α in ⟨swap x y, by rw [sign_swap hxy, h]⟩ ) variable {α} lemma eq_sign_of_surjective_hom {s : perm α →* ℤˣ} (hs : surjective s) : s = sign := have ∀ {f}, is_swap f → s f = -1 := λ f ⟨x, y, hxy, hxy'⟩, hxy'.symm ▸ by_contradiction (λ h, have ∀ f, is_swap f → s f = 1 := λ f ⟨a, b, hab, hab'⟩, by { rw [← is_conj_iff_eq, ← or.resolve_right (int.units_eq_one_or _) h, hab'], exact s.map_is_conj (is_conj_swap hab hxy) }, let ⟨g, hg⟩ := hs (-1) in let ⟨l, hl⟩ := (trunc_swap_factors g).out in have ∀ a ∈ l.map s, a = (1 : ℤˣ) := λ a ha, let ⟨g, hg⟩ := list.mem_map.1 ha in hg.2 ▸ this _ (hl.2 _ hg.1), have s l.prod = 1, by rw [← l.prod_hom s, list.eq_repeat'.2 this, list.prod_repeat, one_pow], by { rw [hl.1, hg] at this, exact absurd this dec_trivial }), monoid_hom.ext $ λ f, let ⟨l, hl₁, hl₂⟩ := (trunc_swap_factors f).out in have hsl : ∀ a ∈ l.map s, a = (-1 : ℤˣ) := λ a ha, let ⟨g, hg⟩ := list.mem_map.1 ha in hg.2 ▸ this (hl₂ _ hg.1), by rw [← hl₁, ← l.prod_hom s, list.eq_repeat'.2 hsl, list.length_map, list.prod_repeat, sign_prod_list_swap hl₂] lemma sign_subtype_perm (f : perm α) {p : α → Prop} [decidable_pred p] (h₁ : ∀ x, p x ↔ p (f x)) (h₂ : ∀ x, f x ≠ x → p x) : sign (subtype_perm f h₁) = sign f := let l := (trunc_swap_factors (subtype_perm f h₁)).out in have hl' : ∀ g' ∈ l.1.map of_subtype, is_swap g' := λ g' hg', let ⟨g, hg⟩ := list.mem_map.1 hg' in hg.2 ▸ (l.2.2 _ hg.1).of_subtype_is_swap, have hl'₂ : (l.1.map of_subtype).prod = f, by rw [l.1.prod_hom of_subtype, l.2.1, of_subtype_subtype_perm _ h₂], by { conv { congr, rw ← l.2.1, skip, rw ← hl'₂ }, rw [sign_prod_list_swap l.2.2, sign_prod_list_swap hl', list.length_map] } lemma sign_eq_sign_of_equiv [decidable_eq β] [fintype β] (f : perm α) (g : perm β) (e : α ≃ β) (h : ∀ x, e (f x) = g (e x)) : sign f = sign g := have hg : g = (e.symm.trans f).trans e, from equiv.ext $ by simp [h], by rw [hg, sign_symm_trans_trans] lemma sign_bij [decidable_eq β] [fintype β] {f : perm α} {g : perm β} (i : Π x : α, f x ≠ x → β) (h : ∀ x hx hx', i (f x) hx' = g (i x hx)) (hi : ∀ x₁ x₂ hx₁ hx₂, i x₁ hx₁ = i x₂ hx₂ → x₁ = x₂) (hg : ∀ y, g y ≠ y → ∃ x hx, i x hx = y) : sign f = sign g := calc sign f = sign (@subtype_perm _ f (λ x, f x ≠ x) (by simp)) : (sign_subtype_perm _ _ (λ _, id)).symm ... = sign (@subtype_perm _ g (λ x, g x ≠ x) (by simp)) : sign_eq_sign_of_equiv _ _ (equiv.of_bijective (λ x : {x // f x ≠ x}, (⟨i x.1 x.2, have f (f x) ≠ f x, from mt (λ h, f.injective h) x.2, by { rw [← h _ x.2 this], exact mt (hi _ _ this x.2) x.2 }⟩ : {y // g y ≠ y})) ⟨λ ⟨x, hx⟩ ⟨y, hy⟩ h, subtype.eq (hi _ _ _ _ (subtype.mk.inj h)), λ ⟨y, hy⟩, let ⟨x, hfx, hx⟩ := hg y hy in ⟨⟨x, hfx⟩, subtype.eq hx⟩⟩) (λ ⟨x, _⟩, subtype.eq (h x _ _)) ... = sign g : sign_subtype_perm _ _ (λ _, id) /-- If we apply `prod_extend_right a (σ a)` for all `a : α` in turn, we get `prod_congr_right σ`. -/ lemma prod_prod_extend_right {α : Type*} [decidable_eq α] (σ : α → perm β) {l : list α} (hl : l.nodup) (mem_l : ∀ a, a ∈ l) : (l.map (λ a, prod_extend_right a (σ a))).prod = prod_congr_right σ := begin ext ⟨a, b⟩ : 1, -- We'll use induction on the list of elements, -- but we have to keep track of whether we already passed `a` in the list. suffices : (a ∈ l ∧ (l.map (λ a, prod_extend_right a (σ a))).prod (a, b) = (a, σ a b)) ∨ (a ∉ l ∧ (l.map (λ a, prod_extend_right a (σ a))).prod (a, b) = (a, b)), { obtain ⟨_, prod_eq⟩ := or.resolve_right this (not_and.mpr (λ h _, h (mem_l a))), rw [prod_eq, prod_congr_right_apply] }, clear mem_l, induction l with a' l ih, { refine or.inr ⟨list.not_mem_nil _, _⟩, rw [list.map_nil, list.prod_nil, one_apply] }, rw [list.map_cons, list.prod_cons, mul_apply], rcases ih (list.nodup_cons.mp hl).2 with ⟨mem_l, prod_eq⟩ | ⟨not_mem_l, prod_eq⟩; rw prod_eq, { refine or.inl ⟨list.mem_cons_of_mem _ mem_l, _⟩, rw prod_extend_right_apply_ne _ (λ (h : a = a'), (list.nodup_cons.mp hl).1 (h ▸ mem_l)) }, by_cases ha' : a = a', { rw ← ha' at *, refine or.inl ⟨l.mem_cons_self a, _⟩, rw prod_extend_right_apply_eq }, { refine or.inr ⟨λ h, not_or ha' not_mem_l ((list.mem_cons_iff _ _ _).mp h), _⟩, rw prod_extend_right_apply_ne _ ha' }, end section congr variables [decidable_eq β] [fintype β] @[simp] lemma sign_prod_extend_right (a : α) (σ : perm β) : (prod_extend_right a σ).sign = σ.sign := sign_bij (λ (ab : α × β) _, ab.snd) (λ ⟨a', b⟩ hab hab', by simp [eq_of_prod_extend_right_ne hab]) (λ ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ hab₁ hab₂ h, by simpa [eq_of_prod_extend_right_ne hab₁, eq_of_prod_extend_right_ne hab₂] using h) (λ y hy, ⟨(a, y), by simpa, by simp⟩) lemma sign_prod_congr_right (σ : α → perm β) : sign (prod_congr_right σ) = ∏ k, (σ k).sign := begin obtain ⟨l, hl, mem_l⟩ := finite.exists_univ_list α, have l_to_finset : l.to_finset = finset.univ, { apply eq_top_iff.mpr, intros b _, exact list.mem_to_finset.mpr (mem_l b) }, rw [← prod_prod_extend_right σ hl mem_l, sign.map_list_prod, list.map_map, ← l_to_finset, list.prod_to_finset _ hl], simp_rw ← λ a, sign_prod_extend_right a (σ a) end lemma sign_prod_congr_left (σ : α → perm β) : sign (prod_congr_left σ) = ∏ k, (σ k).sign := begin refine (sign_eq_sign_of_equiv _ _ (prod_comm β α) _).trans (sign_prod_congr_right σ), rintro ⟨b, α⟩, refl end @[simp] lemma sign_perm_congr (e : α ≃ β) (p : perm α) : (e.perm_congr p).sign = p.sign := sign_eq_sign_of_equiv _ _ e.symm (by simp) @[simp] lemma sign_sum_congr (σa : perm α) (σb : perm β) : (sum_congr σa σb).sign = σa.sign * σb.sign := begin suffices : (sum_congr σa (1 : perm β)).sign = σa.sign ∧ (sum_congr (1 : perm α) σb).sign = σb.sign, { rw [←this.1, ←this.2, ←sign_mul, sum_congr_mul, one_mul, mul_one], }, split, { apply σa.swap_induction_on _ (λ σa' a₁ a₂ ha ih, _), { simp }, { rw [←one_mul (1 : perm β), ←sum_congr_mul, sign_mul, sign_mul, ih, sum_congr_swap_one, sign_swap ha, sign_swap (sum.inl_injective.ne_iff.mpr ha)], }, }, { apply σb.swap_induction_on _ (λ σb' b₁ b₂ hb ih, _), { simp }, { rw [←one_mul (1 : perm α), ←sum_congr_mul, sign_mul, sign_mul, ih, sum_congr_one_swap, sign_swap hb, sign_swap (sum.inr_injective.ne_iff.mpr hb)], }, } end @[simp] lemma sign_subtype_congr {p : α → Prop} [decidable_pred p] (ep : perm {a // p a}) (en : perm {a // ¬ p a}) : (ep.subtype_congr en).sign = ep.sign * en.sign := by simp [subtype_congr] @[simp] lemma sign_extend_domain (e : perm α) {p : β → Prop} [decidable_pred p] (f : α ≃ subtype p) : equiv.perm.sign (e.extend_domain f) = equiv.perm.sign e := by simp only [equiv.perm.extend_domain, sign_subtype_congr, sign_perm_congr, sign_refl, mul_one] @[simp] lemma sign_of_subtype {p : α → Prop} [decidable_pred p] (f : equiv.perm (subtype p)) : equiv.perm.sign (f.of_subtype) = equiv.perm.sign f := sign_extend_domain f (equiv.refl (subtype p)) end congr end sign end equiv.perm
0ea98b7def06ff3caee982a3164f7b12fee11c2f
42c01158c2730cc6ac3e058c1339c18cb90366e2
/M1F/2017-18/Example_Sheet_01/Question_06/question6.lean
c97615b432702e2067d5fcfab2407942cdc87eea
[]
no_license
ChrisHughes24/xena
c80d94355d0c2ae8deddda9d01e6d31bc21c30ae
337a0d7c9f0e255e08d6d0a383e303c080c6ec0c
refs/heads/master
1,631,059,898,392
1,511,200,551,000
1,511,200,551,000
111,468,589
1
0
null
null
null
null
UTF-8
Lean
false
false
3,541
lean
-- ignore this part: we are building the notion of a set -- go to line 36 inductive zfc : Type | empty : zfc | insert : zfc → zfc → zfc instance : has_emptyc zfc := ⟨zfc.empty⟩ instance : has_insert zfc zfc := ⟨zfc.insert⟩ instance : has_zero zfc := ⟨{}⟩ instance : has_one zfc := ⟨{0}⟩ def succ (a : zfc) : zfc := has_insert.insert a a def zfc_add : zfc → zfc → zfc | m 0 := m | m (zfc.insert n p) := succ (zfc_add m n) instance : has_add zfc := ⟨zfc_add⟩ inductive member : zfc → zfc → Prop | left {a b c : zfc} : member a c → member a (has_insert.insert b c) | right {a b : zfc} : member a (has_insert.insert a b) instance : has_mem zfc zfc := ⟨member⟩ instance : has_subset zfc := ⟨(λ a b:zfc, (∀ z:zfc, z ∈ a → z ∈ b))⟩ infix `⊈`:50 := (λ a b, ¬(a ⊆ b)) infix `⊉`:50 := (λ a b, ¬(b ⊆ a)) axiom member.ext (a b : zfc) : (∀ x, x ∈ a ↔ x ∈ b) ↔ a=b export zfc export member -- start here /- USAGE: 1. ¬P is shorthand of (P → false). 2. A ∉ B is shorthand of ¬(A ∈ B), which is shorthand of (A ∈ B → false) per 1. 3. A ⊆ B is shorthand of (∀ z, z ∈ A → z ∈ B). 4. A ⊈ B is shorthand of ¬(A ⊆ B), and then use 1 and 3. 5. If the current goal is x ∈ {a,b,c,d,e}, then using "left" or "apply left" will make the goal x ∈ {a,b,c,d}. 6. If the current goal is x ∈ {a,b,c,d,x}, then using "right" or "apply right" or "exact right" will prove the goal. 7. If one wishes to disprove (i.e. derive false from) one of the current hypotheses of the form h : x ∈ {a,b,c,d,e}, using "cases h" will replace the current hypothesis with a_1 : x ∈ {a,b,c,d}, provided that x and e are not equal. When the set is empty, "cases h" will directly prove false. HINT: To prove a statement of the form "P → P", use "exact id". RECAP: 1. To prove a statement of the form "∀ z, P z", type "intro x" and then prove "P x". 2. To prove a statement of the form "P → Q", type "intro HP" and then prove "Q". 3. If the current goal is P ∨ Q, using "left" will reduce the goal to P. NOTE: Somehow the goal will become messy. I tried to fix it but it just wouldn't work. Try to work with simple cases where the goal still works, and then trust in the force when it doesn't. -/ definition A : zfc := {1,2,{1,2}} definition B : zfc := {1,2,A} -- prove one and delete the other for each part. theorem M1F_Sheet01_Q06a_is_true : (1:zfc) ∈ A := sorry theorem M1F_Sheet01_Q06a_is_false : (1:zfc) ∈ A := sorry theorem M1F_Sheet01_Q06b_is_true: ({1}:zfc) ∈ A := sorry theorem M1F_Sheet01_Q06b_is_false: ({1}:zfc) ∉ A := sorry theorem M1F_Sheet01_Q06c_is_true: ({1,2}:zfc) ∈ A := sorry theorem M1F_Sheet01_Q06c_is_false: ({1,2}:zfc) ∉ A := sorry -- goal generator becomes messy for (d) theorem M1F_Sheet01_Q06d_is_true: ({1,2}:zfc) ⊆ A := sorry theorem M1F_Sheet01_Q06d_is_false: ({1,2}:zfc) ⊆ A := sorry theorem M1F_Sheet01_Q06e_is_true: (1:zfc) ∈ B := sorry theorem M1F_Sheet01_Q06e_is_false: (1:zfc) ∉ B := sorry theorem M1F_Sheet01_Q06f_is_true: ({1}:zfc) ∈ B := sorry theorem M1F_Sheet01_Q06f_is_false: ({1}:zfc) ∉ B := sorry theorem M1F_Sheet01_Q06g_is_true: ({1,2}:zfc) ∈ B → (1:zfc) ∈ A := sorry theorem M1F_Sheet01_Q06g_is_false: ¬(({1,2}:zfc) ∈ B → (1:zfc) ∈ A) := sorry -- goal generator becomes messy for (h) theorem M1F_Sheet01_Q06h_is_true: ({1,2}:zfc) ⊆ B ∨ (1:zfc) ∉ A := sorry theorem M1F_Sheet01_Q06h_is_false: ¬(({1,2}:zfc) ⊆ B ∨ (1:zfc) ∉ A) := sorry
fd61f153ebbed1813760f40bd16d47a9ae8e0ce4
75db7e3219bba2fbf41bf5b905f34fcb3c6ca3f2
/hott/hit/quotient_functor.hlean
9cda7fa9b986911ae30a73a320f11d93bcf0e592
[ "Apache-2.0" ]
permissive
jroesch/lean
30ef0860fa905d35b9ad6f76de1a4f65c9af6871
3de4ec1a6ce9a960feb2a48eeea8b53246fa34f2
refs/heads/master
1,586,090,835,348
1,455,142,203,000
1,455,142,277,000
51,536,958
1
0
null
1,455,215,811,000
1,455,215,811,000
null
UTF-8
Lean
false
false
5,387
hlean
/- Copyright (c) 2015 Ulrik Buchholtz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ulrik Buchholtz Functoriality of quotients and a condition for when an equivalence is induced. -/ import types.sigma .quotient open eq is_equiv equiv prod prod.ops sigma sigma.ops namespace quotient section variables {A : Type} (R : A → A → Type) {B : Type} (Q : B → B → Type) (f : A → B) (k : Πa a' : A, R a a' → Q (f a) (f a')) include f k protected definition functor [reducible] : quotient R → quotient Q := quotient.elim (λa, class_of Q (f a)) (λa a' r, eq_of_rel Q (k a a' r)) variables [F : is_equiv f] [K : Πa a', is_equiv (k a a')] include F K protected definition functor_inv [reducible] : quotient Q → quotient R := quotient.elim (λb, class_of R (f⁻¹ b)) (λb b' q, eq_of_rel R ((k (f⁻¹ b) (f⁻¹ b'))⁻¹ ((right_inv f b)⁻¹ ▸ (right_inv f b')⁻¹ ▸ q))) protected definition is_equiv [instance] : is_equiv (quotient.functor R Q f k):= begin fapply adjointify _ (quotient.functor_inv R Q f k), { intro qb, induction qb with b b b' q, { apply ap (class_of Q), apply right_inv }, { apply eq_pathover, rewrite [ap_id,ap_compose' (quotient.elim _ _)], do 2 krewrite elim_eq_of_rel, rewrite (right_inv (k (f⁻¹ b) (f⁻¹ b'))), assert H1 : pathover (λz : B × B, Q z.1 z.2) ((right_inv f b)⁻¹ ▸ (right_inv f b')⁻¹ ▸ q) (prod_eq (right_inv f b) (right_inv f b')) q, { apply pathover_of_eq_tr, krewrite [prod_eq_inv,prod_eq_transport] }, assert H2 : square (ap (λx : (Σz : B × B, Q z.1 z.2), class_of Q x.1.1) (sigma_eq (prod_eq (right_inv f b) (right_inv f b')) H1)) (ap (λx : (Σz : B × B, Q z.1 z.2), class_of Q x.1.2) (sigma_eq (prod_eq (right_inv f b) (right_inv f b')) H1)) (eq_of_rel Q ((right_inv f b)⁻¹ ▸ (right_inv f b')⁻¹ ▸ q)) (eq_of_rel Q q), { exact natural_square (λw : (Σz : B × B, Q z.1 z.2), eq_of_rel Q w.2) (sigma_eq (prod_eq (right_inv f b) (right_inv f b')) H1) }, krewrite (ap_compose' (class_of Q)) at H2, krewrite (ap_compose' (λz : B × B, z.1)) at H2, rewrite sigma.ap_pr1 at H2, rewrite sigma_eq_pr1 at H2, krewrite prod.ap_pr1 at H2, krewrite prod_eq_pr1 at H2, krewrite (ap_compose' (class_of Q) (λx : (Σz : B × B, Q z.1 z.2), x.1.2)) at H2, krewrite (ap_compose' (λz : B × B, z.2)) at H2, rewrite sigma.ap_pr1 at H2, rewrite sigma_eq_pr1 at H2, krewrite prod.ap_pr2 at H2, krewrite prod_eq_pr2 at H2, apply H2 } }, { intro qa, induction qa with a a a' r, { apply ap (class_of R), apply left_inv }, { apply eq_pathover, rewrite [ap_id,(ap_compose' (quotient.elim _ _))], do 2 krewrite elim_eq_of_rel, assert H1 : pathover (λz : A × A, R z.1 z.2) ((left_inv f a)⁻¹ ▸ (left_inv f a')⁻¹ ▸ r) (prod_eq (left_inv f a) (left_inv f a')) r, { apply pathover_of_eq_tr, krewrite [prod_eq_inv,prod_eq_transport] }, assert H2 : square (ap (λx : (Σz : A × A, R z.1 z.2), class_of R x.1.1) (sigma_eq (prod_eq (left_inv f a) (left_inv f a')) H1)) (ap (λx : (Σz : A × A, R z.1 z.2), class_of R x.1.2) (sigma_eq (prod_eq (left_inv f a) (left_inv f a')) H1)) (eq_of_rel R ((left_inv f a)⁻¹ ▸ (left_inv f a')⁻¹ ▸ r)) (eq_of_rel R r), { exact natural_square (λw : (Σz : A × A, R z.1 z.2), eq_of_rel R w.2) (sigma_eq (prod_eq (left_inv f a) (left_inv f a')) H1) }, krewrite (ap_compose' (class_of R)) at H2, krewrite (ap_compose' (λz : A × A, z.1)) at H2, rewrite sigma.ap_pr1 at H2, rewrite sigma_eq_pr1 at H2, krewrite prod.ap_pr1 at H2, krewrite prod_eq_pr1 at H2, krewrite (ap_compose' (class_of R) (λx : (Σz : A × A, R z.1 z.2), x.1.2)) at H2, krewrite (ap_compose' (λz : A × A, z.2)) at H2, rewrite sigma.ap_pr1 at H2, rewrite sigma_eq_pr1 at H2, krewrite prod.ap_pr2 at H2, krewrite prod_eq_pr2 at H2, assert H3 : (k (f⁻¹ (f a)) (f⁻¹ (f a')))⁻¹ ((right_inv f (f a))⁻¹ ▸ (right_inv f (f a'))⁻¹ ▸ k a a' r) = (left_inv f a)⁻¹ ▸ (left_inv f a')⁻¹ ▸ r, { rewrite [adj f a,adj f a',ap_inv',ap_inv'], rewrite [-(tr_compose _ f (left_inv f a')⁻¹ (k a a' r)), -(tr_compose _ f (left_inv f a)⁻¹)], rewrite [-(fn_tr_eq_tr_fn (left_inv f a')⁻¹ (λx, k a x) r), -(fn_tr_eq_tr_fn (left_inv f a)⁻¹ (λx, k x (f⁻¹ (f a')))), left_inv (k _ _)] }, rewrite H3, apply H2 } } end end section open equiv.ops variables {A : Type} (R : A → A → Type) {B : Type} (Q : B → B → Type) (f : A ≃ B) (k : Πa a' : A, R a a' ≃ Q (f a) (f a')) include f k /- This could also be proved using ua, but then it wouldn't compute -/ protected definition equiv : quotient R ≃ quotient Q := equiv.mk (quotient.functor R Q f k) _ end end quotient
62c15ce8b009205bfaff452ac4b933018d56b2d1
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/linear_algebra/default.lean
7f29154ed7d9c05402ab9bc281b23d6879b88aa4
[]
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
140
lean
import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.linear_algebra.basic import Mathlib.PostPort namespace Mathlib
ac6ba1cc4c55d17aee848c22085f554f9731b4e4
32025d5c2d6e33ad3b6dd8a3c91e1e838066a7f7
/tests/lean/lvl1.lean
0228d2673f3320e784e4b8c6de205024d517153a
[ "Apache-2.0" ]
permissive
walterhu1015/lean4
b2c71b688975177402758924eaa513475ed6ce72
2214d81e84646a905d0b20b032c89caf89c737ad
refs/heads/master
1,671,342,096,906
1,599,695,985,000
1,599,695,985,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
1,333
lean
import Lean.Level namespace Lean namespace Level def mkMax (xs : Array Level) : Level := xs.foldlFrom mkLevelMax (xs.get! 0) 1 #eval toString $ normalize $ mkLevelSucc $ mkLevelSucc $ mkMax #[levelZero, mkLevelParam `w, mkLevelSucc (mkLevelSucc (mkLevelSucc (mkLevelParam `z))), levelOne, mkLevelSucc (mkLevelSucc (mkLevelParam `x)), levelZero, mkLevelParam `x, mkLevelParam `y, mkLevelParam `x, mkLevelParam `z, mkLevelSucc levelOne, mkLevelParam `w, mkLevelSucc (mkLevelParam `x)] #eval toString $ normalize $ mkLevelMax levelZero (mkLevelParam `x) #eval toString $ normalize $ mkLevelMax (mkLevelParam `x) levelZero #eval toString $ normalize $ mkLevelMax levelZero levelOne #eval toString $ normalize $ mkLevelSucc (mkLevelMax (mkLevelParam `x) (mkLevelParam `x)) #eval toString $ normalize $ mkLevelMax (mkLevelIMax (mkLevelParam `x) levelOne) (mkLevelMax (mkLevelSucc (mkLevelParam `x)) (mkLevelParam `x)) #eval toString $ normalize $ mkLevelIMax (mkLevelIMax (mkLevelParam `x) levelOne) (mkLevelMax (mkLevelSucc (mkLevelParam `x)) (mkLevelParam `x)) #eval toString $ #[levelZero, mkLevelSucc (mkLevelSucc (mkLevelParam `z)), levelOne, mkLevelSucc (mkLevelSucc (mkLevelParam `x)), levelZero, mkLevelParam `x, mkLevelParam `y, mkLevelParam `x, mkLevelParam `z, mkLevelSucc (mkLevelParam `x)].qsort normLt end Level end Lean
02b41a58e39b265e34622480a107ccd2dfd3c6f7
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/appParserIssue.lean
9b0c0b90060bc9d2a6c8f7498395f07646585091
[ "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
323
lean
def f (x : Nat) (g : Nat → Nat) := g x #check f 1 fun x => x -- should work #check f 1 (fun x => x) -- should work #check f 1 $ fun x => x -- should work syntax "foo" term:max term:max : term macro_rules | `(foo $x $y) => `(f $x $y) #check foo 1 (fun x => x) -- should work #check foo 1 fun x => x -- should work
022460fd7771319799f7d1c8b2a83349bab71bbd
bbecf0f1968d1fba4124103e4f6b55251d08e9c4
/src/topology/connected.lean
f129f71ba83883cb113670eb4ac93b8e747c0d0b
[ "Apache-2.0" ]
permissive
waynemunro/mathlib
e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552
065a70810b5480d584033f7bbf8e0409480c2118
refs/heads/master
1,693,417,182,397
1,634,644,781,000
1,634,644,781,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
46,087
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 topology.subset_properties /-! # Connected subsets of topological spaces In this file we define connected subsets of a topological spaces and various other properties and classes related to connectivity. ## Main definitions We define the following properties for sets in a topological space: * `is_connected`: a nonempty set that has no non-trivial open partition. See also the section below in the module doc. * `connected_component` is the connected component of an element in the space. * `is_totally_disconnected`: all of its connected components are singletons. * `is_totally_separated`: any two points can be separated by two disjoint opens that cover the set. For each of these definitions, we also have a class stating that the whole space satisfies that property: `connected_space`, `totally_disconnected_space`, `totally_separated_space`. ## On the definition of connected sets/spaces In informal mathematics, connected spaces are assumed to be nonempty. We formalise the predicate without that assumption as `is_preconnected`. In other words, the only difference is whether the empty space counts as connected. There are good reasons to consider the empty space to be “too simple to be simple” See also https://ncatlab.org/nlab/show/too+simple+to+be+simple, and in particular https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions. -/ open set function topological_space open_locale classical topological_space universes u v variables {α : Type u} {β : Type v} [topological_space α] {s t : set α} section preconnected /-- A preconnected set is one where there is no non-trivial open partition. -/ def is_preconnected (s : set α) : Prop := ∀ (u v : set α), is_open u → is_open v → s ⊆ u ∪ v → (s ∩ u).nonempty → (s ∩ v).nonempty → (s ∩ (u ∩ v)).nonempty /-- A connected set is one that is nonempty and where there is no non-trivial open partition. -/ def is_connected (s : set α) : Prop := s.nonempty ∧ is_preconnected s lemma is_connected.nonempty {s : set α} (h : is_connected s) : s.nonempty := h.1 lemma is_connected.is_preconnected {s : set α} (h : is_connected s) : is_preconnected s := h.2 theorem is_preirreducible.is_preconnected {s : set α} (H : is_preirreducible s) : is_preconnected s := λ _ _ hu hv _, H _ _ hu hv theorem is_irreducible.is_connected {s : set α} (H : is_irreducible s) : is_connected s := ⟨H.nonempty, H.is_preirreducible.is_preconnected⟩ theorem is_preconnected_empty : is_preconnected (∅ : set α) := is_preirreducible_empty.is_preconnected theorem is_connected_singleton {x} : is_connected ({x} : set α) := is_irreducible_singleton.is_connected theorem is_preconnected_singleton {x} : is_preconnected ({x} : set α) := is_connected_singleton.is_preconnected theorem set.subsingleton.is_preconnected {s : set α} (hs : s.subsingleton) : is_preconnected s := hs.induction_on is_preconnected_empty (λ x, is_preconnected_singleton) /-- If any point of a set is joined to a fixed point by a preconnected subset, then the original set is preconnected as well. -/ theorem is_preconnected_of_forall {s : set α} (x : α) (H : ∀ y ∈ s, ∃ t ⊆ s, x ∈ t ∧ y ∈ t ∧ is_preconnected t) : is_preconnected s := begin rintros u v hu hv hs ⟨z, zs, zu⟩ ⟨y, ys, yv⟩, have xs : x ∈ s, by { rcases H y ys with ⟨t, ts, xt, yt, ht⟩, exact ts xt }, wlog xu : x ∈ u := hs xs using [u v y z, v u z y], rcases H y ys with ⟨t, ts, xt, yt, ht⟩, have := ht u v hu hv(subset.trans ts hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩, exact this.imp (λ z hz, ⟨ts hz.1, hz.2⟩) end /-- If any two points of a set are contained in a preconnected subset, then the original set is preconnected as well. -/ theorem is_preconnected_of_forall_pair {s : set α} (H : ∀ x y ∈ s, ∃ t ⊆ s, x ∈ t ∧ y ∈ t ∧ is_preconnected t) : is_preconnected s := begin rcases eq_empty_or_nonempty s with (rfl|⟨x, hx⟩), exacts [is_preconnected_empty, is_preconnected_of_forall x (λ y, H x y hx)], end /-- A union of a family of preconnected sets with a common point is preconnected as well. -/ theorem is_preconnected_sUnion (x : α) (c : set (set α)) (H1 : ∀ s ∈ c, x ∈ s) (H2 : ∀ s ∈ c, is_preconnected s) : is_preconnected (⋃₀ c) := begin apply is_preconnected_of_forall x, rintros y ⟨s, sc, ys⟩, exact ⟨s, subset_sUnion_of_mem sc, H1 s sc, ys, H2 s sc⟩ end theorem is_preconnected_Union {ι : Sort*} {s : ι → set α} (h₁ : (⋂ i, s i).nonempty) (h₂ : ∀ i, is_preconnected (s i)) : is_preconnected (⋃ i, s i) := exists.elim h₁ $ λ f hf, is_preconnected_sUnion f _ hf (forall_range_iff.2 h₂) theorem is_preconnected.union (x : α) {s t : set α} (H1 : x ∈ s) (H2 : x ∈ t) (H3 : is_preconnected s) (H4 : is_preconnected t) : is_preconnected (s ∪ t) := sUnion_pair s t ▸ is_preconnected_sUnion x {s, t} (by rintro r (rfl | rfl | h); assumption) (by rintro r (rfl | rfl | h); assumption) theorem is_connected.union {s t : set α} (H : (s ∩ t).nonempty) (Hs : is_connected s) (Ht : is_connected t) : is_connected (s ∪ t) := begin rcases H with ⟨x, hx⟩, refine ⟨⟨x, mem_union_left t (mem_of_mem_inter_left hx)⟩, _⟩, exact is_preconnected.union x (mem_of_mem_inter_left hx) (mem_of_mem_inter_right hx) Hs.is_preconnected Ht.is_preconnected end /-- Theorem of bark and tree : if a set is within a (pre)connected set and its closure, then it is (pre)connected as well. -/ theorem is_preconnected.subset_closure {s : set α} {t : set α} (H : is_preconnected s) (Kst : s ⊆ t) (Ktcs : t ⊆ closure s) : is_preconnected t := λ u v hu hv htuv ⟨y, hyt, hyu⟩ ⟨z, hzt, hzv⟩, let ⟨p, hpu, hps⟩ := mem_closure_iff.1 (Ktcs hyt) u hu hyu, ⟨q, hqv, hqs⟩ := mem_closure_iff.1 (Ktcs hzt) v hv hzv, ⟨r, hrs, hruv⟩ := H u v hu hv (subset.trans Kst htuv) ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ in ⟨r, Kst hrs, hruv⟩ theorem is_connected.subset_closure {s : set α} {t : set α} (H : is_connected s) (Kst : s ⊆ t) (Ktcs : t ⊆ closure s): is_connected t := let hsne := H.left, ht := Kst, htne := nonempty.mono ht hsne in ⟨nonempty.mono Kst H.left, is_preconnected.subset_closure H.right Kst Ktcs ⟩ /-- The closure of a (pre)connected set is (pre)connected as well. -/ theorem is_preconnected.closure {s : set α} (H : is_preconnected s) : is_preconnected (closure s) := is_preconnected.subset_closure H subset_closure $ subset.refl $ closure s theorem is_connected.closure {s : set α} (H : is_connected s) : is_connected (closure s) := is_connected.subset_closure H subset_closure $ subset.refl $ closure s /-- The image of a (pre)connected set is (pre)connected as well. -/ theorem is_preconnected.image [topological_space β] {s : set α} (H : is_preconnected s) (f : α → β) (hf : continuous_on f s) : is_preconnected (f '' s) := begin -- Unfold/destruct definitions in hypotheses rintros u v hu hv huv ⟨_, ⟨x, xs, rfl⟩, xu⟩ ⟨_, ⟨y, ys, rfl⟩, yv⟩, rcases continuous_on_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩, rcases continuous_on_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩, -- Reformulate `huv : f '' s ⊆ u ∪ v` in terms of `u'` and `v'` replace huv : s ⊆ u' ∪ v', { rw [image_subset_iff, preimage_union] at huv, replace huv := subset_inter huv (subset.refl _), rw [inter_distrib_right, u'_eq, v'_eq, ← inter_distrib_right] at huv, exact (subset_inter_iff.1 huv).1 }, -- Now `s ⊆ u' ∪ v'`, so we can apply `‹is_preconnected s›` obtain ⟨z, hz⟩ : (s ∩ (u' ∩ v')).nonempty, { refine H u' v' hu' hv' huv ⟨x, _⟩ ⟨y, _⟩; rw inter_comm, exacts [u'_eq ▸ ⟨xu, xs⟩, v'_eq ▸ ⟨yv, ys⟩] }, rw [← inter_self s, inter_assoc, inter_left_comm s u', ← inter_assoc, inter_comm s, inter_comm s, ← u'_eq, ← v'_eq] at hz, exact ⟨f z, ⟨z, hz.1.2, rfl⟩, hz.1.1, hz.2.1⟩ end theorem is_connected.image [topological_space β] {s : set α} (H : is_connected s) (f : α → β) (hf : continuous_on f s) : is_connected (f '' s) := ⟨nonempty_image_iff.mpr H.nonempty, H.is_preconnected.image f hf⟩ theorem is_preconnected_closed_iff {s : set α} : is_preconnected s ↔ ∀ t t', is_closed t → is_closed t' → s ⊆ t ∪ t' → (s ∩ t).nonempty → (s ∩ t').nonempty → (s ∩ (t ∩ t')).nonempty := ⟨begin rintros h t t' ht ht' htt' ⟨x, xs, xt⟩ ⟨y, ys, yt'⟩, by_contradiction h', rw [← ne_empty_iff_nonempty, ne.def, not_not, ← subset_compl_iff_disjoint, compl_inter] at h', have xt' : x ∉ t', from (h' xs).elim (absurd xt) id, have yt : y ∉ t, from (h' ys).elim id (absurd yt'), have := ne_empty_iff_nonempty.2 (h tᶜ t'ᶜ (is_open_compl_iff.2 ht) (is_open_compl_iff.2 ht') h' ⟨y, ys, yt⟩ ⟨x, xs, xt'⟩), rw [ne.def, ← compl_union, ← subset_compl_iff_disjoint, compl_compl] at this, contradiction end, begin rintros h u v hu hv huv ⟨x, xs, xu⟩ ⟨y, ys, yv⟩, by_contradiction h', rw [← ne_empty_iff_nonempty, ne.def, not_not, ← subset_compl_iff_disjoint, compl_inter] at h', have xv : x ∉ v, from (h' xs).elim (absurd xu) id, have yu : y ∉ u, from (h' ys).elim id (absurd yv), have := ne_empty_iff_nonempty.2 (h uᶜ vᶜ (is_closed_compl_iff.2 hu) (is_closed_compl_iff.2 hv) h' ⟨y, ys, yu⟩ ⟨x, xs, xv⟩), rw [ne.def, ← compl_union, ← subset_compl_iff_disjoint, compl_compl] at this, contradiction end⟩ theorem is_preconnected.prod [topological_space β] {s : set α} {t : set β} (hs : is_preconnected s) (ht : is_preconnected t) : is_preconnected (s.prod t) := begin apply is_preconnected_of_forall_pair, rintro ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ ⟨ha₁, hb₁⟩ ⟨ha₂, hb₂⟩, refine ⟨prod.mk a₁ '' t ∪ flip prod.mk b₂ '' s, _, or.inl ⟨b₁, hb₁, rfl⟩, or.inr ⟨a₂, ha₂, rfl⟩, _⟩, { rintro _ (⟨y, hy, rfl⟩|⟨x, hx, rfl⟩), exacts [⟨ha₁, hy⟩, ⟨hx, hb₂⟩] }, { exact (ht.image _ (continuous.prod.mk _).continuous_on).union (a₁, b₂) ⟨b₂, hb₂, rfl⟩ ⟨a₁, ha₁, rfl⟩ (hs.image _ (continuous_id.prod_mk continuous_const).continuous_on) } end theorem is_connected.prod [topological_space β] {s : set α} {t : set β} (hs : is_connected s) (ht : is_connected t) : is_connected (s.prod t) := ⟨hs.1.prod ht.1, hs.2.prod ht.2⟩ theorem is_preconnected_univ_pi {ι : Type*} {π : ι → Type*} [Π i, topological_space (π i)] {s : Π i, set (π i)} (hs : ∀ i, is_preconnected (s i)) : is_preconnected (pi univ s) := begin rintros u v uo vo hsuv ⟨f, hfs, hfu⟩ ⟨g, hgs, hgv⟩, rcases exists_finset_piecewise_mem_of_mem_nhds (uo.mem_nhds hfu) g with ⟨I, hI⟩, induction I using finset.induction_on with i I hi ihI, { refine ⟨g, hgs, ⟨_, hgv⟩⟩, simpa using hI }, { rw [finset.piecewise_insert] at hI, have := I.piecewise_mem_set_pi hfs hgs, refine (hsuv this).elim ihI (λ h, _), set S := update (I.piecewise f g) i '' (s i), have hsub : S ⊆ pi univ s, { refine image_subset_iff.2 (λ z hz, _), rwa update_preimage_univ_pi, exact λ j hj, this j trivial }, have hconn : is_preconnected S, from (hs i).image _ (continuous_const.update i continuous_id).continuous_on, have hSu : (S ∩ u).nonempty, from ⟨_, mem_image_of_mem _ (hfs _ trivial), hI⟩, have hSv : (S ∩ v).nonempty, from ⟨_, ⟨_, this _ trivial, update_eq_self _ _⟩, h⟩, refine (hconn u v uo vo (hsub.trans hsuv) hSu hSv).mono _, exact inter_subset_inter_left _ hsub } end @[simp] theorem is_connected_univ_pi {ι : Type*} {π : ι → Type*} [Π i, topological_space (π i)] {s : Π i, set (π i)} : is_connected (pi univ s) ↔ ∀ i, is_connected (s i) := begin simp only [is_connected, ← univ_pi_nonempty_iff, forall_and_distrib, and.congr_right_iff], refine λ hne, ⟨λ hc i, _, is_preconnected_univ_pi⟩, rw [← eval_image_univ_pi hne], exact hc.image _ (continuous_apply _).continuous_on end /-- The connected component of a point is the maximal connected set that contains this point. -/ def connected_component (x : α) : set α := ⋃₀ { s : set α | is_preconnected s ∧ x ∈ s } /-- The connected component of a point inside a set. -/ def connected_component_in (F : set α) (x : F) : set α := coe '' (connected_component x) theorem mem_connected_component {x : α} : x ∈ connected_component x := mem_sUnion_of_mem (mem_singleton x) ⟨is_connected_singleton.is_preconnected, mem_singleton x⟩ theorem is_preconnected_connected_component {x : α} : is_preconnected (connected_component x) := is_preconnected_sUnion x _ (λ _, and.right) (λ _, and.left) theorem is_connected_connected_component {x : α} : is_connected (connected_component x) := ⟨⟨x, mem_connected_component⟩, is_preconnected_connected_component⟩ theorem is_preconnected.subset_connected_component {x : α} {s : set α} (H1 : is_preconnected s) (H2 : x ∈ s) : s ⊆ connected_component x := λ z hz, mem_sUnion_of_mem hz ⟨H1, H2⟩ theorem is_connected.subset_connected_component {x : α} {s : set α} (H1 : is_connected s) (H2 : x ∈ s) : s ⊆ connected_component x := H1.2.subset_connected_component H2 theorem connected_component_eq {x y : α} (h : y ∈ connected_component x) : connected_component x = connected_component y := eq_of_subset_of_subset (is_connected_connected_component.subset_connected_component h) (is_connected_connected_component.subset_connected_component (set.mem_of_mem_of_subset mem_connected_component (is_connected_connected_component.subset_connected_component h))) lemma connected_component_disjoint {x y : α} (h : connected_component x ≠ connected_component y) : disjoint (connected_component x) (connected_component y) := set.disjoint_left.2 (λ a h1 h2, h ((connected_component_eq h1).trans (connected_component_eq h2).symm)) theorem is_closed_connected_component {x : α} : is_closed (connected_component x) := closure_eq_iff_is_closed.1 $ subset.antisymm (is_connected_connected_component.closure.subset_connected_component (subset_closure mem_connected_component)) subset_closure lemma continuous.image_connected_component_subset {β : Type*} [topological_space β] {f : α → β} (h : continuous f) (a : α) : f '' connected_component a ⊆ connected_component (f a) := (is_connected_connected_component.image f h.continuous_on).subset_connected_component ((mem_image f (connected_component a) (f a)).2 ⟨a, mem_connected_component, rfl⟩) theorem irreducible_component_subset_connected_component {x : α} : irreducible_component x ⊆ connected_component x := is_irreducible_irreducible_component.is_connected.subset_connected_component mem_irreducible_component /-- A preconnected space is one where there is no non-trivial open partition. -/ class preconnected_space (α : Type u) [topological_space α] : Prop := (is_preconnected_univ : is_preconnected (univ : set α)) export preconnected_space (is_preconnected_univ) /-- A connected space is a nonempty one where there is no non-trivial open partition. -/ class connected_space (α : Type u) [topological_space α] extends preconnected_space α : Prop := (to_nonempty : nonempty α) attribute [instance, priority 50] connected_space.to_nonempty -- see Note [lower instance priority] lemma is_preconnected_range [topological_space β] [preconnected_space α] {f : α → β} (h : continuous f) : is_preconnected (range f) := @image_univ _ _ f ▸ is_preconnected_univ.image _ h.continuous_on lemma is_connected_range [topological_space β] [connected_space α] {f : α → β} (h : continuous f) : is_connected (range f) := ⟨range_nonempty f, is_preconnected_range h⟩ lemma dense_range.preconnected_space [topological_space β] [preconnected_space α] {f : α → β} (hf : dense_range f) (hc : continuous f) : preconnected_space β := ⟨hf.closure_eq ▸ (is_preconnected_range hc).closure⟩ lemma connected_space_iff_connected_component : connected_space α ↔ ∃ x : α, connected_component x = univ := begin split, { rintros ⟨h, ⟨x⟩⟩, exactI ⟨x, eq_univ_of_univ_subset $ is_preconnected_univ.subset_connected_component (mem_univ x)⟩ }, { rintros ⟨x, h⟩, haveI : preconnected_space α := ⟨by { rw ← h, exact is_preconnected_connected_component }⟩, exact ⟨⟨x⟩⟩ } end instance [topological_space β] [preconnected_space α] [preconnected_space β] : preconnected_space (α × β) := ⟨by { rw ← univ_prod_univ, exact is_preconnected_univ.prod is_preconnected_univ }⟩ instance [topological_space β] [connected_space α] [connected_space β] : connected_space (α × β) := ⟨prod.nonempty⟩ instance {ι : Type*} {π : ι → Type*} [∀ i, topological_space (π i)] [∀ i, preconnected_space (π i)] : preconnected_space (Π i, π i) := ⟨by { rw ← pi_univ univ, exact is_preconnected_univ_pi (λ i, is_preconnected_univ) }⟩ instance {ι : Type*} {π : ι → Type*} [∀ i, topological_space (π i)] [∀ i, connected_space (π i)] : connected_space (Π i, π i) := ⟨classical.nonempty_pi.2 $ λ i, by apply_instance⟩ @[priority 100] -- see Note [lower instance priority] instance preirreducible_space.preconnected_space (α : Type u) [topological_space α] [preirreducible_space α] : preconnected_space α := ⟨(preirreducible_space.is_preirreducible_univ α).is_preconnected⟩ @[priority 100] -- see Note [lower instance priority] instance irreducible_space.connected_space (α : Type u) [topological_space α] [irreducible_space α] : connected_space α := { to_nonempty := irreducible_space.to_nonempty α } theorem nonempty_inter [preconnected_space α] {s t : set α} : is_open s → is_open t → s ∪ t = univ → s.nonempty → t.nonempty → (s ∩ t).nonempty := by simpa only [univ_inter, univ_subset_iff] using @preconnected_space.is_preconnected_univ α _ _ s t theorem is_clopen_iff [preconnected_space α] {s : set α} : is_clopen s ↔ s = ∅ ∨ s = univ := ⟨λ hs, classical.by_contradiction $ λ h, have h1 : s ≠ ∅ ∧ sᶜ ≠ ∅, from ⟨mt or.inl h, mt (λ h2, or.inr $ (by rw [← compl_compl s, h2, compl_empty] : s = univ)) h⟩, let ⟨_, h2, h3⟩ := nonempty_inter hs.1 hs.2.is_open_compl (union_compl_self s) (ne_empty_iff_nonempty.1 h1.1) (ne_empty_iff_nonempty.1 h1.2) in h3 h2, by rintro (rfl | rfl); [exact is_clopen_empty, exact is_clopen_univ]⟩ lemma eq_univ_of_nonempty_clopen [preconnected_space α] {s : set α} (h : s.nonempty) (h' : is_clopen s) : s = univ := by { rw is_clopen_iff at h', finish [h.ne_empty] } lemma subtype.preconnected_space {s : set α} (h : is_preconnected s) : preconnected_space s := { is_preconnected_univ := begin intros u v hu hv hs hsu hsv, rw is_open_induced_iff at hu hv, rcases hu with ⟨u, hu, rfl⟩, rcases hv with ⟨v, hv, rfl⟩, rcases hsu with ⟨⟨x, hxs⟩, hxs', hxu⟩, rcases hsv with ⟨⟨y, hys⟩, hys', hyv⟩, rcases h u v hu hv _ ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩ with ⟨z, hzs, ⟨hzu, hzv⟩⟩, exact ⟨⟨z, hzs⟩, ⟨set.mem_univ _, ⟨hzu, hzv⟩⟩⟩, intros z hz, rcases hs (mem_univ ⟨z, hz⟩) with hzu|hzv, { left, assumption }, { right, assumption } end } lemma subtype.connected_space {s : set α} (h : is_connected s) : connected_space s := { is_preconnected_univ := (subtype.preconnected_space h.is_preconnected).is_preconnected_univ, to_nonempty := h.nonempty.to_subtype } lemma is_preconnected_iff_preconnected_space {s : set α} : is_preconnected s ↔ preconnected_space s := ⟨subtype.preconnected_space, begin introI, simpa using is_preconnected_univ.image (coe : s → α) continuous_subtype_coe.continuous_on end⟩ lemma is_connected_iff_connected_space {s : set α} : is_connected s ↔ connected_space s := ⟨subtype.connected_space, λ h, ⟨nonempty_subtype.mp h.2, is_preconnected_iff_preconnected_space.mpr h.1⟩⟩ /-- A set `s` is preconnected if and only if for every cover by two open sets that are disjoint on `s`, it is contained in one of the two covering sets. -/ lemma is_preconnected_iff_subset_of_disjoint {s : set α} : is_preconnected s ↔ ∀ (u v : set α) (hu : is_open u) (hv : is_open v) (hs : s ⊆ u ∪ v) (huv : s ∩ (u ∩ v) = ∅), s ⊆ u ∨ s ⊆ v := begin split; intro h, { intros u v hu hv hs huv, specialize h u v hu hv hs, contrapose! huv, rw ne_empty_iff_nonempty, simp [not_subset] at huv, rcases huv with ⟨⟨x, hxs, hxu⟩, ⟨y, hys, hyv⟩⟩, have hxv : x ∈ v := or_iff_not_imp_left.mp (hs hxs) hxu, have hyu : y ∈ u := or_iff_not_imp_right.mp (hs hys) hyv, exact h ⟨y, hys, hyu⟩ ⟨x, hxs, hxv⟩ }, { intros u v hu hv hs hsu hsv, rw ← ne_empty_iff_nonempty, intro H, specialize h u v hu hv hs H, contrapose H, apply ne_empty_iff_nonempty.mpr, cases h, { rcases hsv with ⟨x, hxs, hxv⟩, exact ⟨x, hxs, ⟨h hxs, hxv⟩⟩ }, { rcases hsu with ⟨x, hxs, hxu⟩, exact ⟨x, hxs, ⟨hxu, h hxs⟩⟩ } } end /-- A set `s` is connected if and only if for every cover by a finite collection of open sets that are pairwise disjoint on `s`, it is contained in one of the members of the collection. -/ lemma is_connected_iff_sUnion_disjoint_open {s : set α} : is_connected s ↔ ∀ (U : finset (set α)) (H : ∀ (u v : set α), u ∈ U → v ∈ U → (s ∩ (u ∩ v)).nonempty → u = v) (hU : ∀ u ∈ U, is_open u) (hs : s ⊆ ⋃₀ ↑U), ∃ u ∈ U, s ⊆ u := begin rw [is_connected, is_preconnected_iff_subset_of_disjoint], split; intro h, { intro U, apply finset.induction_on U, { rcases h.left, suffices : s ⊆ ∅ → false, { simpa }, intro, solve_by_elim }, { intros u U hu IH hs hU H, rw [finset.coe_insert, sUnion_insert] at H, cases h.2 u (⋃₀ ↑U) _ _ H _ with hsu hsU, { exact ⟨u, finset.mem_insert_self _ _, hsu⟩ }, { rcases IH _ _ hsU with ⟨v, hvU, hsv⟩, { exact ⟨v, finset.mem_insert_of_mem hvU, hsv⟩ }, { intros, apply hs; solve_by_elim [finset.mem_insert_of_mem] }, { intros, solve_by_elim [finset.mem_insert_of_mem] } }, { solve_by_elim [finset.mem_insert_self] }, { apply is_open_sUnion, intros, solve_by_elim [finset.mem_insert_of_mem] }, { apply eq_empty_of_subset_empty, rintro x ⟨hxs, hxu, hxU⟩, rw mem_sUnion at hxU, rcases hxU with ⟨v, hvU, hxv⟩, rcases hs u v (finset.mem_insert_self _ _) (finset.mem_insert_of_mem hvU) _ with rfl, { contradiction }, { exact ⟨x, hxs, hxu, hxv⟩ } } } }, { split, { rw ← ne_empty_iff_nonempty, by_contradiction hs, push_neg at hs, subst hs, simpa using h ∅ _ _ _; simp }, intros u v hu hv hs hsuv, rcases h {u, v} _ _ _ with ⟨t, ht, ht'⟩, { rw [finset.mem_insert, finset.mem_singleton] at ht, rcases ht with rfl|rfl; tauto }, { intros t₁ t₂ ht₁ ht₂ hst, rw ← ne_empty_iff_nonempty at hst, rw [finset.mem_insert, finset.mem_singleton] at ht₁ ht₂, rcases ht₁ with rfl|rfl; rcases ht₂ with rfl|rfl, all_goals { refl <|> contradiction <|> skip }, rw inter_comm t₁ at hst, contradiction }, { intro t, rw [finset.mem_insert, finset.mem_singleton], rintro (rfl|rfl); assumption }, { simpa using hs } } end /-- Preconnected sets are either contained in or disjoint to any given clopen set. -/ theorem subset_or_disjoint_of_clopen {α : Type*} [topological_space α] {s t : set α} (h : is_preconnected t) (h1 : is_clopen s) : s ∩ t = ∅ ∨ t ⊆ s := begin by_contradiction h2, have h3 : (s ∩ t).nonempty := ne_empty_iff_nonempty.mp (mt or.inl h2), have h4 : (t ∩ sᶜ).nonempty, { apply inter_compl_nonempty_iff.2, push_neg at h2, exact h2.2 }, rw [inter_comm] at h3, apply ne_empty_iff_nonempty.2 (h s sᶜ h1.1 (is_open_compl_iff.2 h1.2) _ h3 h4), { rw [inter_compl_self, inter_empty] }, { rw [union_compl_self], exact subset_univ t }, end /-- A set `s` is preconnected if and only if for every cover by two closed sets that are disjoint on `s`, it is contained in one of the two covering sets. -/ theorem is_preconnected_iff_subset_of_disjoint_closed {α : Type*} {s : set α} [topological_space α] : is_preconnected s ↔ ∀ (u v : set α) (hu : is_closed u) (hv : is_closed v) (hs : s ⊆ u ∪ v) (huv : s ∩ (u ∩ v) = ∅), s ⊆ u ∨ s ⊆ v := begin split; intro h, { intros u v hu hv hs huv, rw is_preconnected_closed_iff at h, specialize h u v hu hv hs, contrapose! huv, rw ne_empty_iff_nonempty, simp [not_subset] at huv, rcases huv with ⟨⟨x, hxs, hxu⟩, ⟨y, hys, hyv⟩⟩, have hxv : x ∈ v := or_iff_not_imp_left.mp (hs hxs) hxu, have hyu : y ∈ u := or_iff_not_imp_right.mp (hs hys) hyv, exact h ⟨y, hys, hyu⟩ ⟨x, hxs, hxv⟩ }, { rw is_preconnected_closed_iff, intros u v hu hv hs hsu hsv, rw ← ne_empty_iff_nonempty, intro H, specialize h u v hu hv hs H, contrapose H, apply ne_empty_iff_nonempty.mpr, cases h, { rcases hsv with ⟨x, hxs, hxv⟩, exact ⟨x, hxs, ⟨h hxs, hxv⟩⟩ }, { rcases hsu with ⟨x, hxs, hxu⟩, exact ⟨x, hxs, ⟨hxu, h hxs⟩⟩ } } end /-- A closed set `s` is preconnected if and only if for every cover by two closed sets that are disjoint, it is contained in one of the two covering sets. -/ theorem is_preconnected_iff_subset_of_fully_disjoint_closed {s : set α} (hs : is_closed s) : is_preconnected s ↔ ∀ (u v : set α) (hu : is_closed u) (hv : is_closed v) (hss : s ⊆ u ∪ v) (huv : u ∩ v = ∅), s ⊆ u ∨ s ⊆ v := begin split, { intros h u v hu hv hss huv, apply is_preconnected_iff_subset_of_disjoint_closed.1 h u v hu hv hss, rw huv, exact inter_empty s }, intro H, rw is_preconnected_iff_subset_of_disjoint_closed, intros u v hu hv hss huv, have H1 := H (u ∩ s) (v ∩ s), rw [subset_inter_iff, subset_inter_iff] at H1, simp only [subset.refl, and_true] at H1, apply H1 (is_closed.inter hu hs) (is_closed.inter hv hs), { rw ←inter_distrib_right, apply subset_inter_iff.2, exact ⟨hss, subset.refl s⟩ }, { rw [inter_comm v s, inter_assoc, ←inter_assoc s, inter_self s, inter_comm, inter_assoc, inter_comm v u, huv] } end /-- The connected component of a point is always a subset of the intersection of all its clopen neighbourhoods. -/ lemma connected_component_subset_Inter_clopen {x : α} : connected_component x ⊆ ⋂ Z : {Z : set α // is_clopen Z ∧ x ∈ Z}, Z := begin apply subset_Inter (λ Z, _), cases (subset_or_disjoint_of_clopen (@is_connected_connected_component _ _ x).2 Z.2.1), { exfalso, apply nonempty.ne_empty (nonempty_of_mem (mem_inter (@mem_connected_component _ _ x) Z.2.2)), rw inter_comm, exact h }, exact h, end /-- A clopen set is the union of its connected components. -/ lemma is_clopen.eq_union_connected_components {Z : set α} (h : is_clopen Z) : Z = (⋃ (x : α) (H : x ∈ Z), connected_component x) := eq_of_subset_of_subset (λ x xZ, mem_Union.2 ⟨x, mem_Union.2 ⟨xZ, mem_connected_component⟩⟩) (Union_subset $ λ x, Union_subset $ λ xZ, (by { apply subset.trans connected_component_subset_Inter_clopen (Inter_subset _ ⟨Z, ⟨h, xZ⟩⟩) })) /-- The preimage of a connected component is preconnected if the function has connected fibers and a subset is closed iff the preimage is. -/ lemma preimage_connected_component_connected {β : Type*} [topological_space β] {f : α → β} (connected_fibers : ∀ t : β, is_connected (f ⁻¹' {t})) (hcl : ∀ (T : set β), is_closed T ↔ is_closed (f ⁻¹' T)) (t : β) : is_connected (f ⁻¹' connected_component t) := begin -- The following proof is essentially https://stacks.math.columbia.edu/tag/0377 -- although the statement is slightly different have hf : surjective f := surjective.of_comp (λ t : β, (connected_fibers t).1), split, { cases hf t with s hs, use s, rw [mem_preimage, hs], exact mem_connected_component }, have hT : is_closed (f ⁻¹' connected_component t) := (hcl (connected_component t)).1 is_closed_connected_component, -- To show it's preconnected we decompose (f ⁻¹' connected_component t) as a subset of two -- closed disjoint sets in α. We want to show that it's a subset of either. rw is_preconnected_iff_subset_of_fully_disjoint_closed hT, intros u v hu hv huv uv_disj, -- To do this we decompose connected_component t into T₁ and T₂ -- we will show that connected_component t is a subset of either and hence -- (f ⁻¹' connected_component t) is a subset of u or v let T₁ := {t' ∈ connected_component t | f ⁻¹' {t'} ⊆ u}, let T₂ := {t' ∈ connected_component t | f ⁻¹' {t'} ⊆ v}, have fiber_decomp : ∀ t' ∈ connected_component t, f ⁻¹' {t'} ⊆ u ∨ f ⁻¹' {t'} ⊆ v, { intros t' ht', apply is_preconnected_iff_subset_of_disjoint_closed.1 (connected_fibers t').2 u v hu hv, { exact subset.trans (hf.preimage_subset_preimage_iff.2 (singleton_subset_iff.2 ht')) huv }, rw uv_disj, exact inter_empty _ }, have T₁_u : f ⁻¹' T₁ = (f ⁻¹' connected_component t) ∩ u, { apply eq_of_subset_of_subset, { rw ←bUnion_preimage_singleton, refine bUnion_subset (λ t' ht', subset_inter _ ht'.2), rw [hf.preimage_subset_preimage_iff, singleton_subset_iff], exact ht'.1 }, rintros a ⟨hat, hau⟩, constructor, { exact mem_preimage.1 hat }, dsimp only, cases fiber_decomp (f a) (mem_preimage.1 hat), { exact h }, { exfalso, rw ←not_nonempty_iff_eq_empty at uv_disj, exact uv_disj (nonempty_of_mem (mem_inter hau (h rfl))) } }, -- This proof is exactly the same as the above (modulo some symmetry) have T₂_v : f ⁻¹' T₂ = (f ⁻¹' connected_component t) ∩ v, { apply eq_of_subset_of_subset, { rw ←bUnion_preimage_singleton, refine bUnion_subset (λ t' ht', subset_inter _ ht'.2), rw [hf.preimage_subset_preimage_iff, singleton_subset_iff], exact ht'.1 }, rintros a ⟨hat, hav⟩, constructor, { exact mem_preimage.1 hat }, dsimp only, cases fiber_decomp (f a) (mem_preimage.1 hat), { exfalso, rw ←not_nonempty_iff_eq_empty at uv_disj, exact uv_disj (nonempty_of_mem (mem_inter (h rfl) hav)) }, { exact h } }, -- Now we show T₁, T₂ are closed, cover connected_component t and are disjoint. have hT₁ : is_closed T₁ := ((hcl T₁).2 (T₁_u.symm ▸ (is_closed.inter hT hu))), have hT₂ : is_closed T₂ := ((hcl T₂).2 (T₂_v.symm ▸ (is_closed.inter hT hv))), have T_decomp : connected_component t ⊆ T₁ ∪ T₂, { intros t' ht', rw mem_union t' T₁ T₂, cases fiber_decomp t' ht' with htu htv, { left, exact ⟨ht', htu⟩ }, right, exact ⟨ht', htv⟩ }, have T_disjoint : T₁ ∩ T₂ = ∅, { rw ←image_preimage_eq (T₁ ∩ T₂) hf, suffices : f ⁻¹' (T₁ ∩ T₂) = ∅, { rw this, exact image_empty _ }, rw [preimage_inter, T₁_u, T₂_v], rw inter_comm at uv_disj, conv { congr, rw [inter_assoc], congr, skip, rw [←inter_assoc, inter_comm, ←inter_assoc, uv_disj, empty_inter], }, exact inter_empty _ }, -- Now we do cases on whether (connected_component t) is a subset of T₁ or T₂ to show -- that the preimage is a subset of u or v. cases (is_preconnected_iff_subset_of_fully_disjoint_closed is_closed_connected_component).1 is_preconnected_connected_component T₁ T₂ hT₁ hT₂ T_decomp T_disjoint, { left, rw subset.antisymm_iff at T₁_u, suffices : f ⁻¹' connected_component t ⊆ f ⁻¹' T₁, { exact subset.trans (subset.trans this T₁_u.1) (inter_subset_right _ _) }, exact preimage_mono h }, right, rw subset.antisymm_iff at T₂_v, suffices : f ⁻¹' connected_component t ⊆ f ⁻¹' T₂, { exact subset.trans (subset.trans this T₂_v.1) (inter_subset_right _ _) }, exact preimage_mono h, end end preconnected section totally_disconnected /-- A set `s` is called totally disconnected if every subset `t ⊆ s` which is preconnected is a subsingleton, ie either empty or a singleton.-/ def is_totally_disconnected (s : set α) : Prop := ∀ t, t ⊆ s → is_preconnected t → t.subsingleton theorem is_totally_disconnected_empty : is_totally_disconnected (∅ : set α) := λ _ ht _ _ x_in _ _, (ht x_in).elim theorem is_totally_disconnected_singleton {x} : is_totally_disconnected ({x} : set α) := λ _ ht _, subsingleton.mono subsingleton_singleton ht /-- A space is totally disconnected if all of its connected components are singletons. -/ class totally_disconnected_space (α : Type u) [topological_space α] : Prop := (is_totally_disconnected_univ : is_totally_disconnected (univ : set α)) lemma is_preconnected.subsingleton [totally_disconnected_space α] {s : set α} (h : is_preconnected s) : s.subsingleton := totally_disconnected_space.is_totally_disconnected_univ s (subset_univ s) h instance pi.totally_disconnected_space {α : Type*} {β : α → Type*} [t₂ : Πa, topological_space (β a)] [∀a, totally_disconnected_space (β a)] : totally_disconnected_space (Π (a : α), β a) := ⟨λ t h1 h2, have this : ∀ a, is_preconnected ((λ x : Π a, β a, x a) '' t), from λ a, h2.image (λ x, x a) (continuous_apply a).continuous_on, λ x x_in y y_in, funext $ λ a, (this a).subsingleton ⟨x, x_in, rfl⟩ ⟨y, y_in, rfl⟩⟩ instance prod.totally_disconnected_space [topological_space β] [totally_disconnected_space α] [totally_disconnected_space β] : totally_disconnected_space (α × β) := ⟨λ t h1 h2, have H1 : is_preconnected (prod.fst '' t), from h2.image prod.fst continuous_fst.continuous_on, have H2 : is_preconnected (prod.snd '' t), from h2.image prod.snd continuous_snd.continuous_on, λ x hx y hy, prod.ext (H1.subsingleton ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩) (H2.subsingleton ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩)⟩ /-- A space is totally disconnected iff its connected components are subsingletons. -/ lemma totally_disconnected_space_iff_connected_component_subsingleton : totally_disconnected_space α ↔ ∀ x : α, (connected_component x).subsingleton := begin split, { intros h x, apply h.1, { exact subset_univ _ }, exact is_preconnected_connected_component }, intro h, constructor, intros s s_sub hs, rcases eq_empty_or_nonempty s with rfl | ⟨x, x_in⟩, { exact subsingleton_empty }, { exact (h x).mono (hs.subset_connected_component x_in) } end /-- A space is totally disconnected iff its connected components are singletons. -/ lemma totally_disconnected_space_iff_connected_component_singleton : totally_disconnected_space α ↔ ∀ x : α, connected_component x = {x} := begin rw totally_disconnected_space_iff_connected_component_subsingleton, apply forall_congr (λ x, _), rw set.subsingleton_iff_singleton, exact mem_connected_component end /-- The image of a connected component in a totally disconnected space is a singleton. -/ @[simp] lemma continuous.image_connected_component_eq_singleton {β : Type*} [topological_space β] [totally_disconnected_space β] {f : α → β} (h : continuous f) (a : α) : f '' connected_component a = {f a} := (set.subsingleton_iff_singleton $ mem_image_of_mem f mem_connected_component).mp (is_preconnected_connected_component.image f h.continuous_on).subsingleton lemma is_totally_disconnected_of_totally_disconnected_space [totally_disconnected_space α] (s : set α) : is_totally_disconnected s := λ t hts ht, totally_disconnected_space.is_totally_disconnected_univ _ t.subset_univ ht lemma is_totally_disconnected_of_image [topological_space β] {f : α → β} (hf : continuous_on f s) (hf' : injective f) (h : is_totally_disconnected (f '' s)) : is_totally_disconnected s := λ t hts ht x x_in y y_in, hf' $ h _ (image_subset f hts) (ht.image f $ hf.mono hts) (mem_image_of_mem f x_in) (mem_image_of_mem f y_in) lemma embedding.is_totally_disconnected [topological_space β] {f : α → β} (hf : embedding f) {s : set α} (h : is_totally_disconnected (f '' s)) : is_totally_disconnected s := is_totally_disconnected_of_image hf.continuous.continuous_on hf.inj h instance subtype.totally_disconnected_space {α : Type*} {p : α → Prop} [topological_space α] [totally_disconnected_space α] : totally_disconnected_space (subtype p) := ⟨embedding_subtype_coe.is_totally_disconnected (is_totally_disconnected_of_totally_disconnected_space _)⟩ end totally_disconnected section totally_separated /-- A set `s` is called totally separated if any two points of this set can be separated by two disjoint open sets covering `s`. -/ def is_totally_separated (s : set α) : Prop := ∀ x ∈ s, ∀ y ∈ s, x ≠ y → ∃ u v : set α, is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ s ⊆ u ∪ v ∧ u ∩ v = ∅ theorem is_totally_separated_empty : is_totally_separated (∅ : set α) := λ x, false.elim theorem is_totally_separated_singleton {x} : is_totally_separated ({x} : set α) := λ p hp q hq hpq, (hpq $ (eq_of_mem_singleton hp).symm ▸ (eq_of_mem_singleton hq).symm).elim theorem is_totally_disconnected_of_is_totally_separated {s : set α} (H : is_totally_separated s) : is_totally_disconnected s := begin intros t hts ht x x_in y y_in, by_contra h, obtain ⟨u : set α, v : set α, hu : is_open u, hv : is_open v, hxu : x ∈ u, hyv : y ∈ v, hs : s ⊆ u ∪ v, huv : u ∩ v = ∅⟩ := H x (hts x_in) y (hts y_in) h, have : (t ∩ u).nonempty → (t ∩ v).nonempty → (t ∩ (u ∩ v)).nonempty := ht _ _ hu hv (subset.trans hts hs), obtain ⟨z, hz : z ∈ t ∩ (u ∩ v)⟩ := this ⟨x, x_in, hxu⟩ ⟨y, y_in, hyv⟩, simpa [huv] using hz end alias is_totally_disconnected_of_is_totally_separated ← is_totally_separated.is_totally_disconnected /-- A space is totally separated if any two points can be separated by two disjoint open sets covering the whole space. -/ class totally_separated_space (α : Type u) [topological_space α] : Prop := (is_totally_separated_univ [] : is_totally_separated (univ : set α)) @[priority 100] -- see Note [lower instance priority] instance totally_separated_space.totally_disconnected_space (α : Type u) [topological_space α] [totally_separated_space α] : totally_disconnected_space α := ⟨is_totally_disconnected_of_is_totally_separated $ totally_separated_space.is_totally_separated_univ α⟩ @[priority 100] -- see Note [lower instance priority] instance totally_separated_space.of_discrete (α : Type*) [topological_space α] [discrete_topology α] : totally_separated_space α := ⟨λ a _ b _ h, ⟨{b}ᶜ, {b}, is_open_discrete _, is_open_discrete _, by simpa⟩⟩ lemma exists_clopen_of_totally_separated {α : Type*} [topological_space α] [totally_separated_space α] {x y : α} (hxy : x ≠ y) : ∃ (U : set α) (hU : is_clopen U), x ∈ U ∧ y ∈ Uᶜ := begin obtain ⟨U, V, hU, hV, Ux, Vy, f, disj⟩ := totally_separated_space.is_totally_separated_univ α x (set.mem_univ x) y (set.mem_univ y) hxy, have clopen_U := is_clopen_inter_of_disjoint_cover_clopen (is_clopen_univ) f hU hV disj, rw set.univ_inter _ at clopen_U, rw [←set.subset_compl_iff_disjoint, set.subset_compl_comm] at disj, exact ⟨U, clopen_U, Ux, disj Vy⟩, end end totally_separated section connected_component_setoid /-- The setoid of connected components of a topological space -/ def connected_component_setoid (α : Type*) [topological_space α] : setoid α := ⟨λ x y, connected_component x = connected_component y, ⟨λ x, by trivial, λ x y h1, h1.symm, λ x y z h1 h2, h1.trans h2⟩⟩ -- see Note [lower instance priority] local attribute [instance, priority 100] connected_component_setoid lemma connected_component_rel_iff {x y : α} : ⟦x⟧ = ⟦y⟧ ↔ connected_component x = connected_component y := ⟨λ h, quotient.exact h, λ h, quotient.sound h⟩ lemma connected_component_nrel_iff {x y : α} : ⟦x⟧ ≠ ⟦y⟧ ↔ connected_component x ≠ connected_component y := by { rw not_iff_not, exact connected_component_rel_iff } /-- The quotient of a space by its connected components -/ def connected_components (α : Type u) [topological_space α] := quotient (connected_component_setoid α) instance [inhabited α] : inhabited (connected_components α) := ⟨quotient.mk (default _)⟩ instance connected_components.topological_space : topological_space (connected_components α) := quotient.topological_space lemma continuous.image_eq_of_equiv {β : Type*} [topological_space β] [totally_disconnected_space β] {f : α → β} (h : continuous f) (a b : α) (hab : a ≈ b) : f a = f b := singleton_eq_singleton_iff.1 $ h.image_connected_component_eq_singleton a ▸ h.image_connected_component_eq_singleton b ▸ hab ▸ rfl /-- The lift to `connected_components α` of a continuous map from `α` to a totally disconnected space -/ def continuous.connected_components_lift {β : Type*} [topological_space β] [totally_disconnected_space β] {f : α → β} (h : continuous f) : connected_components α → β := quotient.lift f h.image_eq_of_equiv @[continuity] lemma continuous.connected_components_lift_continuous {β : Type*} [topological_space β] [totally_disconnected_space β] {f : α → β} (h : continuous f) : continuous h.connected_components_lift := continuous_quotient_lift h.image_eq_of_equiv h @[simp] lemma continuous.connected_components_lift_factors {β : Type*} [topological_space β] [totally_disconnected_space β] {f : α → β} (h : continuous f) : h.connected_components_lift ∘ quotient.mk = f := rfl lemma continuous.connected_components_lift_unique {β : Type*} [topological_space β] [totally_disconnected_space β] {f : α → β} (h : continuous f) (g : connected_components α → β) (hg : g ∘ quotient.mk = f) : g = h.connected_components_lift := by { subst hg, ext1 x, exact quotient.induction_on x (λ a, refl _) } lemma connected_components_lift_unique' {β : Type*} (g₁ : connected_components α → β) (g₂ : connected_components α → β) (hg : g₁ ∘ quotient.mk = g₂ ∘ quotient.mk ) : g₁ = g₂ := begin ext1 x, refine quotient.induction_on x (λ a, _), change (g₁ ∘ quotient.mk) a = (g₂ ∘ quotient.mk) a, rw hg, end /-- The preimage of a singleton in `connected_components` is the connected component of an element in the equivalence class. -/ lemma connected_components_preimage_singleton {t : α} : connected_component t = quotient.mk ⁻¹' {⟦t⟧} := begin apply set.eq_of_subset_of_subset; intros a ha, { have H : ⟦a⟧ = ⟦t⟧ := quotient.sound (connected_component_eq ha).symm, rw [mem_preimage, H], exact mem_singleton ⟦t⟧ }, rw [mem_preimage, mem_singleton_iff] at ha, have ha' : connected_component a = connected_component t := quotient.exact ha, rw ←ha', exact mem_connected_component, end /-- The preimage of the image of a set under the quotient map to `connected_components α` is the union of the connected components of the elements in it. -/ lemma connected_components_preimage_image (U : set α) : quotient.mk ⁻¹' (quotient.mk '' U) = ⋃ (x : α) (h : x ∈ U), connected_component x := begin apply set.eq_of_subset_of_subset, { rintros a ⟨b, hb, hab⟩, refine mem_Union.2 ⟨b, mem_Union.2 ⟨hb, _⟩⟩, rw connected_component_rel_iff.1 hab, exact mem_connected_component }, refine Union_subset (λ a, Union_subset (λ ha, _)), rw [connected_components_preimage_singleton, (surjective_quotient_mk _).preimage_subset_preimage_iff, singleton_subset_iff], exact ⟨a, ha, refl _⟩, end instance connected_components.totally_disconnected_space : totally_disconnected_space (connected_components α) := begin rw totally_disconnected_space_iff_connected_component_singleton, refine λ x, quotient.induction_on x (λ a, _), apply eq_of_subset_of_subset _ (singleton_subset_iff.2 mem_connected_component), rw subset_singleton_iff, refine λ x, quotient.induction_on x (λ b hb, _), rw [connected_component_rel_iff, connected_component_eq], suffices : is_preconnected (quotient.mk ⁻¹' connected_component ⟦a⟧), { apply mem_of_subset_of_mem (this.subset_connected_component hb), exact mem_preimage.2 mem_connected_component }, apply (@preimage_connected_component_connected _ _ _ _ _ _ _ _).2, { refine λ t, quotient.induction_on t (λ s, _), rw ←connected_components_preimage_singleton, exact is_connected_connected_component }, refine λ T, ⟨λ hT, hT.preimage continuous_quotient_mk, λ hT, _⟩, rwa [← is_open_compl_iff, ← preimage_compl, quotient_map_quotient_mk.is_open_preimage, is_open_compl_iff] at hT, end /-- Functoriality of `connected_components` -/ def continuous.connected_components_map {β : Type*} [topological_space β] {f : α → β} (h : continuous f) : connected_components α → connected_components β := continuous.connected_components_lift (continuous_quotient_mk.comp h) lemma continuous.connected_components_map_continuous {β : Type*} [topological_space β] {f : α → β} (h : continuous f) : continuous h.connected_components_map := continuous.connected_components_lift_continuous (continuous_quotient_mk.comp h) end connected_component_setoid
4abfaaa91e1da586460edba17545332578edae73
bdb33f8b7ea65f7705fc342a178508e2722eb851
/data/set/basic.lean
691553b839f9067b0d3d15adf474a1c8719cff39
[ "Apache-2.0" ]
permissive
rwbarton/mathlib
939ae09bf8d6eb1331fc2f7e067d39567e10e33d
c13c5ea701bb1eec057e0a242d9f480a079105e9
refs/heads/master
1,584,015,335,862
1,524,142,167,000
1,524,142,167,000
130,614,171
0
0
Apache-2.0
1,548,902,667,000
1,524,437,371,000
Lean
UTF-8
Lean
false
false
35,498
lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Jeremy Avigad, Leonardo de Moura -/ import tactic.finish data.sigma open function namespace set universes u v w x variables {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} {a : α} {s t : set α} instance : inhabited (set α) := ⟨∅⟩ theorem ext {a b : set α} (h : ∀ x, x ∈ a ↔ x ∈ b) : a = b := funext (assume x, propext (h x)) theorem set_eq_def (s t : set α) : s = t ↔ ∀ x, x ∈ s ↔ x ∈ t := ⟨begin intros h x, rw h end, set.ext⟩ @[trans] theorem mem_of_mem_of_subset {α : Type u} {x : α} {s t : set α} (hx : x ∈ s) (h : s ⊆ t) : x ∈ t := h hx /- mem and set_of -/ @[simp] theorem mem_set_of_eq {a : α} {p : α → Prop} : a ∈ {a | p a} = p a := rfl @[simp] theorem nmem_set_of_eq {a : α} {P : α → Prop} : a ∉ {a : α | P a} = ¬ P a := rfl @[simp] theorem set_of_mem_eq {s : set α} : {x | x ∈ s} = s := rfl theorem mem_def {a : α} {s : set α} : a ∈ s ↔ s a := iff.rfl instance decidable_mem (s : set α) [H : decidable_pred s] : ∀ a, decidable (a ∈ s) := H instance decidable_set_of (p : α → Prop) [H : decidable_pred p] : decidable_pred {a | p a} := H @[simp] theorem set_of_subset_set_of {p q : α → Prop} : {a | p a} ⊆ {a | q a} ↔ (∀a, p a → q a) := iff.rfl /- set coercion to a type -/ instance : has_coe_to_sort (set α) := ⟨_, λ s, {x // x ∈ s}⟩ @[simp] theorem set_coe_eq_subtype (s : set α) : coe_sort.{(u+1) (u+2)} s = {x // x ∈ s} := rfl @[simp] theorem set_coe.forall {s : set α} {p : s → Prop} : (∀ x : s, p x) ↔ (∀ x (h : x ∈ s), p ⟨x, h⟩) := subtype.forall @[simp] theorem set_coe.exists {s : set α} {p : s → Prop} : (∃ x : s, p x) ↔ (∃ x (h : x ∈ s), p ⟨x, h⟩) := subtype.exists @[simp] theorem set_coe_cast : ∀ {s t : set α} (H' : s = t) (H : @eq (Type u) s t) (x : s), cast H x = ⟨x.1, H' ▸ x.2⟩ | s _ rfl _ ⟨x, h⟩ := rfl /- subset -/ -- TODO(Jeremy): write a tactic to unfold specific instances of generic notation? theorem subset_def {s t : set α} : (s ⊆ t) = ∀ x, x ∈ s → x ∈ t := rfl theorem subset.refl (a : set α) : a ⊆ a := assume x, id @[trans] theorem subset.trans {a b c : set α} (ab : a ⊆ b) (bc : b ⊆ c) : a ⊆ c := assume x h, bc (ab h) @[trans] theorem mem_of_eq_of_mem {α : Type u} {x y : α} {s : set α} (hx : x = y) (h : y ∈ s) : x ∈ s := hx.symm ▸ h theorem subset.antisymm {a b : set α} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b := ext (λ x, iff.intro (λ ina, h₁ ina) (λ inb, h₂ inb)) theorem subset.antisymm_iff {a b : set α} : a = b ↔ a ⊆ b ∧ b ⊆ a := ⟨λ e, e ▸ ⟨subset.refl _, subset.refl _⟩, λ ⟨h₁, h₂⟩, subset.antisymm h₁ h₂⟩ -- an alterantive name theorem eq_of_subset_of_subset {a b : set α} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b := subset.antisymm h₁ h₂ theorem mem_of_subset_of_mem {s₁ s₂ : set α} {a : α} : s₁ ⊆ s₂ → a ∈ s₁ → a ∈ s₂ := assume h₁ h₂, h₁ h₂ theorem not_subset : (¬ s ⊆ t) ↔ ∃a, a ∈ s ∧ a ∉ t := by simp [subset_def, classical.not_forall] /- strict subset -/ /-- `s ⊂ t` means that `s` is a strict subset of `t`, that is, `s ⊆ t` but `s ≠ t`. -/ def strict_subset (s t : set α) := s ⊆ t ∧ s ≠ t instance : has_ssubset (set α) := ⟨strict_subset⟩ theorem ssubset_def : (s ⊂ t) = (s ⊆ t ∧ s ≠ t) := rfl lemma exists_of_ssubset {α : Type u} {s t : set α} (h : s ⊂ t) : (∃x∈t, x ∉ s) := classical.by_contradiction $ assume hn, have t ⊆ s, from assume a hat, classical.by_contradiction $ assume has, hn ⟨a, hat, has⟩, h.2 $ subset.antisymm h.1 this theorem not_mem_empty (x : α) : ¬ (x ∈ (∅ : set α)) := assume h : x ∈ ∅, h @[simp] theorem not_not_mem [decidable (a ∈ s)] : ¬ (a ∉ s) ↔ a ∈ s := not_not /- empty set -/ theorem empty_def : (∅ : set α) = {x | false} := rfl @[simp] theorem mem_empty_eq (x : α) : x ∈ (∅ : set α) = false := rfl @[simp] theorem set_of_false : {a : α | false} = ∅ := rfl theorem eq_empty_iff_forall_not_mem {s : set α} : s = ∅ ↔ ∀ x, x ∉ s := by simp [set_eq_def] theorem ne_empty_of_mem {s : set α} {x : α} (h : x ∈ s) : s ≠ ∅ := by { intro hs, rewrite hs at h, apply not_mem_empty _ h } @[simp] theorem empty_subset (s : set α) : ∅ ⊆ s := assume x, assume h, false.elim h theorem subset_empty_iff {s : set α} : s ⊆ ∅ ↔ s = ∅ := by simp [subset.antisymm_iff] theorem eq_empty_of_subset_empty {s : set α} : s ⊆ ∅ → s = ∅ := subset_empty_iff.1 theorem ne_empty_iff_exists_mem {s : set α} : s ≠ ∅ ↔ ∃ x, x ∈ s := by haveI := classical.prop_decidable; simp [eq_empty_iff_forall_not_mem] theorem exists_mem_of_ne_empty {s : set α} : s ≠ ∅ → ∃ x, x ∈ s := ne_empty_iff_exists_mem.1 -- TODO: remove when simplifier stops rewriting `a ≠ b` to `¬ a = b` theorem not_eq_empty_iff_exists {s : set α} : ¬ (s = ∅) ↔ ∃ x, x ∈ s := ne_empty_iff_exists_mem theorem subset_eq_empty {s t : set α} (h : t ⊆ s) (e : s = ∅) : t = ∅ := subset_empty_iff.1 $ e ▸ h theorem subset_ne_empty {s t : set α} (h : t ⊆ s) : t ≠ ∅ → s ≠ ∅ := mt (subset_eq_empty h) theorem ball_empty_iff {p : α → Prop} : (∀ x ∈ (∅ : set α), p x) ↔ true := by simp [iff_def] /- universal set -/ theorem univ_def : @univ α = {x | true} := rfl @[simp] theorem mem_univ (x : α) : x ∈ @univ α := trivial theorem empty_ne_univ [h : inhabited α] : (∅ : set α) ≠ univ := by simp [set_eq_def] @[simp] theorem subset_univ (s : set α) : s ⊆ univ := λ x H, trivial theorem univ_subset_iff {s : set α} : univ ⊆ s ↔ s = univ := by simp [subset.antisymm_iff] theorem eq_univ_of_univ_subset {s : set α} : univ ⊆ s → s = univ := univ_subset_iff.1 theorem eq_univ_iff_forall {s : set α} : s = univ ↔ ∀ x, x ∈ s := by simp [set_eq_def] theorem eq_univ_of_forall {s : set α} : (∀ x, x ∈ s) → s = univ := eq_univ_iff_forall.2 /- union -/ theorem union_def {s₁ s₂ : set α} : s₁ ∪ s₂ = {a | a ∈ s₁ ∨ a ∈ s₂} := rfl theorem mem_union_left {x : α} {a : set α} (b : set α) : x ∈ a → x ∈ a ∪ b := or.inl theorem mem_union_right {x : α} {b : set α} (a : set α) : x ∈ b → x ∈ a ∪ b := or.inr theorem mem_or_mem_of_mem_union {x : α} {a b : set α} (H : x ∈ a ∪ b) : x ∈ a ∨ x ∈ b := H theorem mem_union.elim {x : α} {a b : set α} {P : Prop} (H₁ : x ∈ a ∪ b) (H₂ : x ∈ a → P) (H₃ : x ∈ b → P) : P := or.elim H₁ H₂ H₃ theorem mem_union (x : α) (a b : set α) : x ∈ a ∪ b ↔ x ∈ a ∨ x ∈ b := iff.rfl @[simp] theorem mem_union_eq (x : α) (a b : set α) : x ∈ a ∪ b = (x ∈ a ∨ x ∈ b) := rfl @[simp] theorem union_self (a : set α) : a ∪ a = a := ext (assume x, or_self _) @[simp] theorem union_empty (a : set α) : a ∪ ∅ = a := ext (assume x, or_false _) @[simp] theorem empty_union (a : set α) : ∅ ∪ a = a := ext (assume x, false_or _) theorem union_comm (a b : set α) : a ∪ b = b ∪ a := ext (assume x, or.comm) theorem union_assoc (a b c : set α) : (a ∪ b) ∪ c = a ∪ (b ∪ c) := ext (assume x, or.assoc) instance union_is_assoc : is_associative (set α) (∪) := ⟨union_assoc⟩ instance union_is_comm : is_commutative (set α) (∪) := ⟨union_comm⟩ theorem union_left_comm (s₁ s₂ s₃ : set α) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) := by finish theorem union_right_comm (s₁ s₂ s₃ : set α) : (s₁ ∪ s₂) ∪ s₃ = (s₁ ∪ s₃) ∪ s₂ := by finish theorem union_eq_self_of_subset_left {s t : set α} (h : s ⊆ t) : s ∪ t = t := by finish [subset_def, set_eq_def, iff_def] theorem union_eq_self_of_subset_right {s t : set α} (h : t ⊆ s) : s ∪ t = s := by finish [subset_def, set_eq_def, iff_def] @[simp] theorem subset_union_left (s t : set α) : s ⊆ s ∪ t := λ x, or.inl @[simp] theorem subset_union_right (s t : set α) : t ⊆ s ∪ t := λ x, or.inr theorem union_subset {s t r : set α} (sr : s ⊆ r) (tr : t ⊆ r) : s ∪ t ⊆ r := by finish [subset_def, union_def] @[simp] theorem union_subset_iff {s t u : set α} : s ∪ t ⊆ u ↔ s ⊆ u ∧ t ⊆ u := by finish [iff_def, subset_def] theorem union_subset_union {s₁ s₂ t₁ t₂ : set α} (h₁ : s₁ ⊆ t₁) (h₂ : s₂ ⊆ t₂) : s₁ ∪ s₂ ⊆ t₁ ∪ t₂ := by finish [subset_def] @[simp] theorem union_empty_iff {s t : set α} : s ∪ t = ∅ ↔ s = ∅ ∧ t = ∅ := ⟨by finish [set_eq_def], by finish [set_eq_def]⟩ /- intersection -/ theorem inter_def {s₁ s₂ : set α} : s₁ ∩ s₂ = {a | a ∈ s₁ ∧ a ∈ s₂} := rfl theorem mem_inter_iff (x : α) (a b : set α) : x ∈ a ∩ b ↔ x ∈ a ∧ x ∈ b := iff.rfl @[simp] theorem mem_inter_eq (x : α) (a b : set α) : x ∈ a ∩ b = (x ∈ a ∧ x ∈ b) := rfl theorem mem_inter {x : α} {a b : set α} (ha : x ∈ a) (hb : x ∈ b) : x ∈ a ∩ b := ⟨ha, hb⟩ theorem mem_of_mem_inter_left {x : α} {a b : set α} (h : x ∈ a ∩ b) : x ∈ a := h.left theorem mem_of_mem_inter_right {x : α} {a b : set α} (h : x ∈ a ∩ b) : x ∈ b := h.right @[simp] theorem inter_self (a : set α) : a ∩ a = a := ext (assume x, and_self _) @[simp] theorem inter_empty (a : set α) : a ∩ ∅ = ∅ := ext (assume x, and_false _) @[simp] theorem empty_inter (a : set α) : ∅ ∩ a = ∅ := ext (assume x, false_and _) theorem inter_comm (a b : set α) : a ∩ b = b ∩ a := ext (assume x, and.comm) theorem inter_assoc (a b c : set α) : (a ∩ b) ∩ c = a ∩ (b ∩ c) := ext (assume x, and.assoc) instance inter_is_assoc : is_associative (set α) (∩) := ⟨inter_assoc⟩ instance inter_is_comm : is_commutative (set α) (∩) := ⟨inter_comm⟩ theorem inter_left_comm (s₁ s₂ s₃ : set α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) := by finish theorem inter_right_comm (s₁ s₂ s₃ : set α) : (s₁ ∩ s₂) ∩ s₃ = (s₁ ∩ s₃) ∩ s₂ := by finish @[simp] theorem inter_subset_left (s t : set α) : s ∩ t ⊆ s := λ x H, and.left H @[simp] theorem inter_subset_right (s t : set α) : s ∩ t ⊆ t := λ x H, and.right H theorem subset_inter {s t r : set α} (rs : r ⊆ s) (rt : r ⊆ t) : r ⊆ s ∩ t := by finish [subset_def, inter_def] @[simp] theorem subset_inter_iff {s t r : set α} : r ⊆ s ∩ t ↔ r ⊆ s ∧ r ⊆ t := ⟨λ h, ⟨subset.trans h (inter_subset_left _ _), subset.trans h (inter_subset_right _ _)⟩, λ ⟨h₁, h₂⟩, subset_inter h₁ h₂⟩ @[simp] theorem inter_univ (a : set α) : a ∩ univ = a := ext (assume x, and_true _) @[simp] theorem univ_inter (a : set α) : univ ∩ a = a := ext (assume x, true_and _) theorem inter_subset_inter_right {s t : set α} (u : set α) (H : s ⊆ t) : s ∩ u ⊆ t ∩ u := by finish [subset_def] theorem inter_subset_inter_left {s t : set α} (u : set α) (H : s ⊆ t) : u ∩ s ⊆ u ∩ t := by finish [subset_def] theorem inter_subset_inter {s₁ s₂ t₁ t₂ : set α} (h₁ : s₁ ⊆ t₁) (h₂ : s₂ ⊆ t₂) : s₁ ∩ s₂ ⊆ t₁ ∩ t₂ := by finish [subset_def] theorem inter_eq_self_of_subset_left {s t : set α} (h : s ⊆ t) : s ∩ t = s := by finish [subset_def, set_eq_def, iff_def] theorem inter_eq_self_of_subset_right {s t : set α} (h : t ⊆ s) : s ∩ t = t := by finish [subset_def, set_eq_def, iff_def] -- TODO(Mario): remove? theorem nonempty_of_inter_nonempty_right {s t : set α} (h : s ∩ t ≠ ∅) : t ≠ ∅ := by finish [set_eq_def, iff_def] theorem nonempty_of_inter_nonempty_left {s t : set α} (h : s ∩ t ≠ ∅) : s ≠ ∅ := by finish [set_eq_def, iff_def] /- distributivity laws -/ theorem inter_distrib_left (s t u : set α) : s ∩ (t ∪ u) = (s ∩ t) ∪ (s ∩ u) := ext (assume x, and_or_distrib_left) theorem inter_distrib_right (s t u : set α) : (s ∪ t) ∩ u = (s ∩ u) ∪ (t ∩ u) := ext (assume x, or_and_distrib_right) theorem union_distrib_left (s t u : set α) : s ∪ (t ∩ u) = (s ∪ t) ∩ (s ∪ u) := ext (assume x, or_and_distrib_left) theorem union_distrib_right (s t u : set α) : (s ∩ t) ∪ u = (s ∪ u) ∩ (t ∪ u) := ext (assume x, and_or_distrib_right) /- insert -/ theorem insert_def (x : α) (s : set α) : insert x s = { y | y = x ∨ y ∈ s } := rfl @[simp] theorem insert_of_has_insert (x : α) (s : set α) : has_insert.insert x s = insert x s := rfl @[simp] theorem subset_insert (x : α) (s : set α) : s ⊆ insert x s := assume y ys, or.inr ys theorem mem_insert (x : α) (s : set α) : x ∈ insert x s := or.inl rfl theorem mem_insert_of_mem {x : α} {s : set α} (y : α) : x ∈ s → x ∈ insert y s := or.inr theorem eq_or_mem_of_mem_insert {x a : α} {s : set α} : x ∈ insert a s → x = a ∨ x ∈ s := id theorem mem_of_mem_insert_of_ne {x a : α} {s : set α} (xin : x ∈ insert a s) : x ≠ a → x ∈ s := by finish [insert_def] @[simp] theorem mem_insert_iff {x a : α} {s : set α} : x ∈ insert a s ↔ (x = a ∨ x ∈ s) := iff.rfl @[simp] theorem insert_eq_of_mem {a : α} {s : set α} (h : a ∈ s) : insert a s = s := by finish [set_eq_def, iff_def] theorem insert_subset : insert a s ⊆ t ↔ (a ∈ t ∧ s ⊆ t) := by simp [subset_def, or_imp_distrib, forall_and_distrib] theorem insert_subset_insert (h : s ⊆ t) : insert a s ⊆ insert a t := assume a', or.imp_right (@h a') theorem ssubset_insert {s : set α} {a : α} (h : a ∉ s) : s ⊂ insert a s := by finish [ssubset_def, set_eq_def] theorem insert_comm (a b : α) (s : set α) : insert a (insert b s) = insert b (insert a s) := ext $ by simp [or.left_comm] theorem insert_union : insert a s ∪ t = insert a (s ∪ t) := set.ext $ assume a, by simp [or.comm, or.left_comm] @[simp] theorem union_insert : s ∪ insert a t = insert a (s ∪ t) := set.ext $ assume a, by simp [or.comm, or.left_comm] -- TODO(Jeremy): make this automatic theorem insert_ne_empty (a : α) (s : set α) : insert a s ≠ ∅ := by safe [set_eq_def, iff_def]; have h' := a_1 a; finish -- useful in proofs by induction theorem forall_of_forall_insert {P : α → Prop} {a : α} {s : set α} (h : ∀ x, x ∈ insert a s → P x) : ∀ x, x ∈ s → P x := by finish theorem forall_insert_of_forall {P : α → Prop} {a : α} {s : set α} (h : ∀ x, x ∈ s → P x) (ha : P a) : ∀ x, x ∈ insert a s → P x := by finish theorem ball_insert_iff {P : α → Prop} {a : α} {s : set α} : (∀ x ∈ insert a s, P x) ↔ P a ∧ (∀x ∈ s, P x) := by finish [iff_def] /- singletons -/ theorem singleton_def (a : α) : ({a} : set α) = insert a ∅ := rfl @[simp] theorem mem_singleton_iff {a b : α} : a ∈ ({b} : set α) ↔ a = b := by finish [singleton_def] -- TODO: again, annotation needed @[simp] theorem mem_singleton (a : α) : a ∈ ({a} : set α) := by finish theorem eq_of_mem_singleton {x y : α} (h : x ∈ ({y} : set α)) : x = y := by finish @[simp] theorem singleton_eq_singleton_iff {x y : α} : {x} = ({y} : set α) ↔ x = y := by finish [set_eq_def, iff_def] theorem mem_singleton_of_eq {x y : α} (H : x = y) : x ∈ ({y} : set α) := by finish theorem insert_eq (x : α) (s : set α) : insert x s = ({x} : set α) ∪ s := by finish [set_eq_def, or_comm] @[simp] theorem pair_eq_singleton (a : α) : ({a, a} : set α) = {a} := by finish @[simp] theorem singleton_ne_empty (a : α) : ({a} : set α) ≠ ∅ := insert_ne_empty _ _ @[simp] theorem singleton_subset_iff {a : α} {s : set α} : {a} ⊆ s ↔ a ∈ s := ⟨λh, h (by simp), λh b e, by simp at e; simp [*]⟩ theorem set_compr_eq_eq_singleton {a : α} : {b | b = a} = {a} := set.ext $ by simp theorem union_singleton : s ∪ {a} = insert a s := by simp [singleton_def] theorem singleton_inter_eq_empty : {a} ∩ s = ∅ ↔ a ∉ s := by simp [eq_empty_iff_forall_not_mem] theorem inter_singleton_eq_empty : s ∩ {a} = ∅ ↔ a ∉ s := by rw [inter_comm, singleton_inter_eq_empty] /- separation -/ theorem mem_sep {s : set α} {p : α → Prop} {x : α} (xs : x ∈ s) (px : p x) : x ∈ {x ∈ s | p x} := ⟨xs, px⟩ @[simp] theorem mem_sep_eq {s : set α} {p : α → Prop} {x : α} : x ∈ {x ∈ s | p x} = (x ∈ s ∧ p x) := rfl theorem mem_sep_iff {s : set α} {p : α → Prop} {x : α} : x ∈ {x ∈ s | p x} ↔ x ∈ s ∧ p x := iff.rfl theorem eq_sep_of_subset {s t : set α} (ssubt : s ⊆ t) : s = {x ∈ t | x ∈ s} := by finish [set_eq_def, iff_def, subset_def] theorem sep_subset (s : set α) (p : α → Prop) : {x ∈ s | p x} ⊆ s := assume x, and.left theorem forall_not_of_sep_empty {s : set α} {p : α → Prop} (h : {x ∈ s | p x} = ∅) : ∀ x ∈ s, ¬ p x := by finish [set_eq_def] /- complement -/ theorem mem_compl {s : set α} {x : α} (h : x ∉ s) : x ∈ -s := h theorem not_mem_of_mem_compl {s : set α} {x : α} (h : x ∈ -s) : x ∉ s := h @[simp] theorem mem_compl_eq (s : set α) (x : α) : x ∈ -s = (x ∉ s) := rfl theorem mem_compl_iff (s : set α) (x : α) : x ∈ -s ↔ x ∉ s := iff.rfl @[simp] theorem inter_compl_self (s : set α) : s ∩ -s = ∅ := by finish [set_eq_def] @[simp] theorem compl_inter_self (s : set α) : -s ∩ s = ∅ := by finish [set_eq_def] @[simp] theorem compl_empty : -(∅ : set α) = univ := by finish [set_eq_def] @[simp] theorem compl_union (s t : set α) : -(s ∪ t) = -s ∩ -t := by finish [set_eq_def] @[simp] theorem compl_compl (s : set α) : -(-s) = s := by finish [set_eq_def] -- ditto theorem compl_inter (s t : set α) : -(s ∩ t) = -s ∪ -t := by finish [set_eq_def] @[simp] theorem compl_univ : -(univ : set α) = ∅ := by finish [set_eq_def] theorem union_eq_compl_compl_inter_compl (s t : set α) : s ∪ t = -(-s ∩ -t) := by simp [compl_inter, compl_compl] theorem inter_eq_compl_compl_union_compl (s t : set α) : s ∩ t = -(-s ∪ -t) := by simp [compl_compl] @[simp] theorem union_compl_self (s : set α) : s ∪ -s = univ := by finish [set_eq_def] @[simp] theorem compl_union_self (s : set α) : -s ∪ s = univ := by finish [set_eq_def] theorem compl_comp_compl : compl ∘ compl = @id (set α) := funext compl_compl theorem compl_subset_comm {s t : set α} : -s ⊆ t ↔ -t ⊆ s := by haveI := classical.prop_decidable; exact forall_congr (λ a, not_imp_comm) theorem compl_subset_iff_union {s t : set α} : -s ⊆ t ↔ s ∪ t = univ := iff.symm $ eq_univ_iff_forall.trans $ forall_congr $ λ a, by haveI := classical.prop_decidable; exact or_iff_not_imp_left theorem subset_compl_comm {s t : set α} : s ⊆ -t ↔ t ⊆ -s := forall_congr $ λ a, imp_not_comm theorem subset_compl_iff_disjoint {s t : set α} : s ⊆ -t ↔ s ∩ t = ∅ := iff.trans (forall_congr $ λ a, and_imp.symm) subset_empty_iff /- set difference -/ theorem diff_eq (s t : set α) : s \ t = s ∩ -t := rfl theorem mem_diff {s t : set α} {x : α} (h1 : x ∈ s) (h2 : x ∉ t) : x ∈ s \ t := ⟨h1, h2⟩ theorem mem_of_mem_diff {s t : set α} {x : α} (h : x ∈ s \ t) : x ∈ s := h.left theorem not_mem_of_mem_diff {s t : set α} {x : α} (h : x ∈ s \ t) : x ∉ t := h.right theorem mem_diff_iff (s t : set α) (x : α) : x ∈ s \ t ↔ x ∈ s ∧ x ∉ t := iff.rfl @[simp] theorem mem_diff_eq (s t : set α) (x : α) : x ∈ s \ t = (x ∈ s ∧ x ∉ t) := rfl theorem union_diff_cancel {s t : set α} (h : s ⊆ t) : s ∪ (t \ s) = t := by finish [set_eq_def, iff_def, subset_def] theorem diff_subset (s t : set α) : s \ t ⊆ s := by finish [subset_def] theorem diff_subset_diff {s₁ s₂ t₁ t₂ : set α} : s₁ ⊆ s₂ → t₂ ⊆ t₁ → s₁ \ t₁ ⊆ s₂ \ t₂ := by finish [subset_def] theorem diff_right_antimono {s t u : set α} (h : t ⊆ u) : s \ u ⊆ s \ t := diff_subset_diff (subset.refl s) h theorem compl_eq_univ_diff (s : set α) : -s = univ \ s := by finish [set_eq_def] theorem diff_neq_empty {s t : set α} : s \ t = ∅ ↔ s ⊆ t := ⟨assume h x hx, classical.by_contradiction $ assume : x ∉ t, show x ∈ (∅ : set α), from h ▸ ⟨hx, this⟩, assume h, eq_empty_of_subset_empty $ assume x ⟨hx, hnx⟩, hnx $ h hx⟩ @[simp] theorem diff_empty {s : set α} : s \ ∅ = s := set.ext $ assume x, ⟨assume ⟨hx, _⟩, hx, assume h, ⟨h, not_false⟩⟩ theorem diff_diff {u : set α} : s \ t \ u = s \ (t ∪ u) := set.ext $ by simp [not_or_distrib, and.comm, and.left_comm] @[simp] theorem insert_sdiff (h : a ∈ t) : insert a s \ t = s \ t := set.ext $ by intro; constructor; simp [or_imp_distrib, h] {contextual := tt} /- powerset -/ theorem mem_powerset {x s : set α} (h : x ⊆ s) : x ∈ powerset s := h theorem subset_of_mem_powerset {x s : set α} (h : x ∈ powerset s) : x ⊆ s := h theorem mem_powerset_iff (x s : set α) : x ∈ powerset s ↔ x ⊆ s := iff.rfl /- inverse image -/ /-- The preimage of `s : set β` by `f : α → β`, written `f ⁻¹' s`, is the set of `x : α` such that `f x ∈ s`. -/ def preimage {α : Type u} {β : Type v} (f : α → β) (s : set β) : set α := {x | f x ∈ s} infix ` ⁻¹' `:80 := preimage section preimage variables {f : α → β} {g : β → γ} @[simp] theorem preimage_empty : f ⁻¹' ∅ = ∅ := rfl @[simp] theorem mem_preimage_eq {s : set β} {a : α} : (a ∈ f ⁻¹' s) = (f a ∈ s) := rfl theorem preimage_mono {s t : set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := assume x hx, h hx @[simp] theorem preimage_univ : f ⁻¹' univ = univ := rfl @[simp] theorem preimage_inter {s t : set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t := rfl @[simp] theorem preimage_union {s t : set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t := rfl @[simp] theorem preimage_compl {s : set β} : f ⁻¹' (- s) = - (f ⁻¹' s) := rfl @[simp] theorem preimage_diff (f : α → β) (s t : set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t := rfl @[simp] theorem preimage_set_of_eq {p : α → Prop} {f : β → α} : f ⁻¹' {a | p a} = {a | p (f a)} := rfl theorem preimage_id {s : set α} : id ⁻¹' s = s := rfl theorem preimage_comp {s : set γ} : (g ∘ f) ⁻¹' s = f ⁻¹' (g ⁻¹' s) := rfl theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : set (subtype p)} {t : set α} : s = subtype.val ⁻¹' t ↔ (∀x (h : p x), (⟨x, h⟩ : subtype p) ∈ s ↔ x ∈ t) := ⟨assume s_eq x h, by rw [s_eq]; simp, assume h, set.ext $ assume ⟨x, hx⟩, by simp [h]⟩ end preimage /- function image -/ section image infix ` '' `:80 := image /-- Two functions `f₁ f₂ : α → β` are equal on `s` if `f₁ x = f₂ x` for all `x ∈ a`. -/ @[reducible] def eq_on (f1 f2 : α → β) (a : set α) : Prop := ∀ x ∈ a, f1 x = f2 x -- TODO(Jeremy): use bounded exists in image theorem mem_image_iff_bex {f : α → β} {s : set α} {y : β} : y ∈ f '' s ↔ ∃ x (_ : x ∈ s), f x = y := bex_def.symm theorem mem_image_eq (f : α → β) (s : set α) (y: β) : y ∈ f '' s = ∃ x, x ∈ s ∧ f x = y := rfl @[simp] theorem mem_image (f : α → β) (s : set α) (y : β) : y ∈ f '' s ↔ ∃ x, x ∈ s ∧ f x = y := iff.rfl theorem mem_image_of_mem (f : α → β) {x : α} {a : set α} (h : x ∈ a) : f x ∈ f '' a := ⟨_, h, rfl⟩ theorem mem_image_of_injective {f : α → β} {a : α} {s : set α} (hf : injective f) : f a ∈ f '' s ↔ a ∈ s := iff.intro (assume ⟨b, hb, eq⟩, (hf eq) ▸ hb) (assume h, mem_image_of_mem _ h) theorem ball_image_of_ball {f : α → β} {s : set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) : ∀ y ∈ f '' s, p y := by finish [mem_image_eq] @[simp] theorem ball_image_iff {f : α → β} {s : set α} {p : β → Prop} : (∀ y ∈ f '' s, p y) ↔ (∀ x ∈ s, p (f x)) := iff.intro (assume h a ha, h _ $ mem_image_of_mem _ ha) (assume h b ⟨a, ha, eq⟩, eq ▸ h a ha) theorem mono_image {f : α → β} {s t : set α} (h : s ⊆ t) : f '' s ⊆ f '' t := assume x ⟨y, hy, y_eq⟩, y_eq ▸ mem_image_of_mem _ $ h hy theorem mem_image_elim {f : α → β} {s : set α} {C : β → Prop} (h : ∀ (x : α), x ∈ s → C (f x)) : ∀{y : β}, y ∈ f '' s → C y | ._ ⟨a, a_in, rfl⟩ := h a a_in theorem mem_image_elim_on {f : α → β} {s : set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s) (h : ∀ (x : α), x ∈ s → C (f x)) : C y := mem_image_elim h h_y theorem image_eq_image_of_eq_on {f₁ f₂ : α → β} {s : set α} (heq : eq_on f₁ f₂ s) : f₁ '' s = f₂ '' s := by safe [set_eq_def, iff_def, mem_image, eq_on] theorem image_comp (f : β → γ) (g : α → β) (a : set α) : (f ∘ g) '' a = f '' (g '' a) := subset.antisymm (ball_image_of_ball $ assume a ha, mem_image_of_mem _ $ mem_image_of_mem _ ha) (ball_image_of_ball $ ball_image_of_ball $ assume a ha, mem_image_of_mem _ ha) /- Proof is removed as it uses generated names TODO(Jeremy): make automatic, begin safe [set_eq_def, iff_def, mem_image, (∘)], have h' := h_2 (g a_2), finish end -/ theorem image_subset {a b : set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by finish [subset_def, mem_image_eq] theorem image_union (f : α → β) (s t : set α) : f '' (s ∪ t) = f '' s ∪ f '' t := by finish [set_eq_def, iff_def, mem_image_eq] @[simp] theorem image_empty (f : α → β) : f '' ∅ = ∅ := by finish [set_eq_def, mem_image_eq] theorem image_inter_on {f : α → β} {s t : set α} (h : ∀x∈t, ∀y∈s, f x = f y → x = y) : f '' s ∩ f '' t = f '' (s ∩ t) := subset.antisymm (assume b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩, have a₂ = a₁, from h _ ha₂ _ ha₁ (by simp *), ⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩) (subset_inter (mono_image $ inter_subset_left _ _) (mono_image $ inter_subset_right _ _)) theorem image_inter {f : α → β} {s t : set α} (H : injective f) : f '' s ∩ f '' t = f '' (s ∩ t) := image_inter_on (assume x _ y _ h, H h) theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : surjective f) : f '' univ = univ := eq_univ_of_forall $ by simp [image]; exact H @[simp] theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := set.ext $ λ x, by simp [image]; rw eq_comm theorem fix_set_compl (t : set α) : compl t = - t := rfl -- TODO(Jeremy): there is an issue with - t unfolding to compl t theorem mem_compl_image (t : set α) (S : set (set α)) : t ∈ compl '' S ↔ -t ∈ S := begin suffices : ∀ x, -x = t ↔ -t = x, {simp [fix_set_compl, this]}, intro x, split; { intro e, subst e, simp } end theorem image_id (s : set α) : id '' s = s := by finish [set_eq_def, iff_def, mem_image_eq] theorem compl_compl_image (S : set (set α)) : compl '' (compl '' S) = S := by rw [← image_comp, compl_comp_compl, image_id] theorem image_insert_eq {f : α → β} {a : α} {s : set α} : f '' (insert a s) = insert (f a) (f '' s) := ext $ by simp [and_or_distrib_left, exists_or_distrib, eq_comm, or_comm, and_comm] theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : left_inverse g f) (s : set α) : f '' s ⊆ g ⁻¹' s := λ b ⟨a, h, e⟩, e ▸ ((I a).symm ▸ h : g (f a) ∈ s) theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : left_inverse g f) (s : set β) : f ⁻¹' s ⊆ g '' s := λ b h, ⟨f b, h, I b⟩ theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : left_inverse g f) (h₂ : right_inverse g f) : image f = preimage g := funext $ λ s, subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s) theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : set α} (h₁ : left_inverse g f) (h₂ : right_inverse g f) : b ∈ f '' s ↔ g b ∈ s := by rw image_eq_preimage_of_inverse h₁ h₂; refl theorem image_compl_subset {f : α → β} {s : set α} (H : injective f) : f '' -s ⊆ -(f '' s) := subset_compl_iff_disjoint.2 $ by simp [image_inter H] theorem subset_image_compl {f : α → β} {s : set α} (H : surjective f) : -(f '' s) ⊆ f '' -s := compl_subset_iff_union.2 $ by rw ← image_union; simp [image_univ_of_surjective H] theorem image_compl_eq {f : α → β} {s : set α} (H : bijective f) : f '' -s = -(f '' s) := subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2) /- image and preimage are a Galois connection -/ theorem image_subset_iff {s : set α} {t : set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t := ball_image_iff theorem image_preimage_subset (f : α → β) (s : set β) : f '' (f ⁻¹' s) ⊆ s := image_subset_iff.2 (subset.refl _) theorem subset_preimage_image (f : α → β) (s : set α) : s ⊆ f ⁻¹' (f '' s) := λ x, mem_image_of_mem f theorem preimage_image_eq {f : α → β} (s : set α) (h : injective f) : f ⁻¹' (f '' s) = s := subset.antisymm (λ x ⟨y, hy, e⟩, h e ▸ hy) (subset_preimage_image f s) theorem image_preimage_eq {f : α → β} {s : set β} (h : surjective f) : f '' (f ⁻¹' s) = s := subset.antisymm (image_preimage_subset f s) (λ x hx, let ⟨y, e⟩ := h x in ⟨y, (e.symm ▸ hx : f y ∈ s), e⟩) theorem compl_image : image (@compl α) = preimage compl := image_eq_preimage_of_inverse compl_compl compl_compl theorem compl_image_set_of {α : Type u} {p : set α → Prop} : compl '' {x | p x} = {x | p (- x)} := congr_fun compl_image p theorem inter_preimage_subset (s : set α) (t : set β) (f : α → β) : s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := λ x h, ⟨mem_image_of_mem _ h.left, h.right⟩ theorem union_preimage_subset (s : set α) (t : set β) (f : α → β) : s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := λ x h, or.elim h (λ l, or.inl $ mem_image_of_mem _ l) (λ r, or.inr r) theorem subset_image_union (f : α → β) (s : set α) (t : set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t := image_subset_iff.2 (union_preimage_subset _ _ _) end image theorem univ_eq_true_false : univ = ({true, false} : set Prop) := eq.symm $ eq_univ_of_forall $ classical.cases (by simp) (by simp) section range variables {f : ι → α} open function /-- Range of a function. This function is more flexible than `f '' univ`, as the image requires that the domain is in Type and not an arbitrary Sort. -/ def range (f : ι → α) : set α := {x | ∃y, f y = x} @[simp] theorem mem_range {x : α} : x ∈ range f ↔ ∃ y, f y = x := iff.rfl theorem mem_range_self (i : ι) : f i ∈ range f := ⟨i, rfl⟩ theorem forall_range_iff {p : α → Prop} : (∀ a ∈ range f, p a) ↔ (∀ i, p (f i)) := ⟨assume h i, h (f i) (mem_range_self _), assume h a ⟨i, (hi : f i = a)⟩, hi ▸ h i⟩ theorem range_iff_surjective : range f = univ ↔ surjective f := eq_univ_iff_forall @[simp] theorem range_id : range (@id α) = univ := range_iff_surjective.2 surjective_id @[simp] theorem image_univ {ι : Type*} {f : ι → β} : f '' univ = range f := set.ext $ by simp [image, range] theorem range_comp {g : α → β} : range (g ∘ f) = g '' range f := subset.antisymm (forall_range_iff.mpr $ assume i, mem_image_of_mem g (mem_range_self _)) (ball_image_iff.mpr $ forall_range_iff.mpr mem_range_self) theorem range_subset_iff {ι : Type*} {f : ι → β} {s : set β} : range f ⊆ s ↔ ∀ y, f y ∈ s := forall_range_iff theorem image_preimage_eq_inter_range {f : α → β} {t : set β} : f '' preimage f t = t ∩ range f := set.ext $ assume x, ⟨assume ⟨x, hx, heq⟩, heq ▸ ⟨hx, mem_range_self _⟩, assume ⟨hx, ⟨y, h_eq⟩⟩, h_eq ▸ mem_image_of_mem f $ show y ∈ preimage f t, by simp [preimage, h_eq, hx]⟩ @[simp] theorem quot_mk_range_eq [setoid α] : range (λx : α, ⟦x⟧) = univ := range_iff_surjective.2 quot.exists_rep end range /-- The set `s` is pairwise `r` if `r x y` for all *distinct* `x y ∈ s`. -/ def pairwise_on (s : set α) (r : α → α → Prop) := ∀ x ∈ s, ∀ y ∈ s, x ≠ y → r x y end set namespace set section prod variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} variables {s s₁ s₂ : set α} {t t₁ t₂ : set β} /-- The cartesian product `prod s t` is the set of `(a, b)` such that `a ∈ s` and `b ∈ t`. -/ protected def prod (s : set α) (t : set β) : set (α × β) := {p | p.1 ∈ s ∧ p.2 ∈ t} theorem mem_prod_eq {p : α × β} : p ∈ set.prod s t = (p.1 ∈ s ∧ p.2 ∈ t) := rfl @[simp] theorem mem_prod {p : α × β} : p ∈ set.prod s t ↔ p.1 ∈ s ∧ p.2 ∈ t := iff.rfl @[simp] theorem prod_empty {s : set α} : set.prod s ∅ = (∅ : set (α × β)) := set.ext $ by simp [set.prod] @[simp] theorem empty_prod {t : set β} : set.prod ∅ t = (∅ : set (α × β)) := set.ext $ by simp [set.prod] theorem insert_prod {a : α} {s : set α} {t : set β} : set.prod (insert a s) t = (prod.mk a '' t) ∪ set.prod s t := set.ext begin simp [set.prod, image, iff_def, or_imp_distrib] {contextual := tt}; cc end theorem prod_insert {b : β} {s : set α} {t : set β} : set.prod s (insert b t) = ((λa, (a, b)) '' s) ∪ set.prod s t := set.ext begin simp [set.prod, image, iff_def, or_imp_distrib] {contextual := tt}; cc end theorem prod_preimage_eq {f : γ → α} {g : δ → β} : set.prod (preimage f s) (preimage g t) = preimage (λp, (f p.1, g p.2)) (set.prod s t) := rfl theorem prod_mono {s₁ s₂ : set α} {t₁ t₂ : set β} (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : set.prod s₁ t₁ ⊆ set.prod s₂ t₂ := assume x ⟨h₁, h₂⟩, ⟨hs h₁, ht h₂⟩ theorem prod_inter_prod : set.prod s₁ t₁ ∩ set.prod s₂ t₂ = set.prod (s₁ ∩ s₂) (t₁ ∩ t₂) := subset.antisymm (assume ⟨a, b⟩ ⟨⟨ha₁, hb₁⟩, ⟨ha₂, hb₂⟩⟩, ⟨⟨ha₁, ha₂⟩, ⟨hb₁, hb₂⟩⟩) (subset_inter (prod_mono (inter_subset_left _ _) (inter_subset_left _ _)) (prod_mono (inter_subset_right _ _) (inter_subset_right _ _))) theorem image_swap_prod : (λp:β×α, (p.2, p.1)) '' set.prod t s = set.prod s t := set.ext $ assume ⟨a, b⟩, by simp [mem_image_eq, set.prod, and_comm]; exact ⟨ assume ⟨b', a', ⟨h_a, h_b⟩, h⟩, by subst a'; subst b'; assumption, assume h, ⟨b, a, ⟨rfl, rfl⟩, h⟩⟩ theorem image_swap_eq_preimage_swap : image (@prod.swap α β) = preimage prod.swap := image_eq_preimage_of_inverse prod.swap_left_inverse prod.swap_right_inverse theorem prod_image_image_eq {m₁ : α → γ} {m₂ : β → δ} : set.prod (image m₁ s) (image m₂ t) = image (λp:α×β, (m₁ p.1, m₂ p.2)) (set.prod s t) := set.ext $ by simp [-exists_and_distrib_right, exists_and_distrib_right.symm, and.left_comm, and.assoc, and.comm] theorem prod_range_range_eq {α β γ δ} {m₁ : α → γ} {m₂ : β → δ} : set.prod (range m₁) (range m₂) = range (λp:α×β, (m₁ p.1, m₂ p.2)) := set.ext $ by simp [range] @[simp] theorem prod_singleton_singleton {a : α} {b : β} : set.prod {a} {b} = ({(a, b)} : set (α×β)) := set.ext $ by simp [set.prod] theorem prod_neq_empty_iff {s : set α} {t : set β} : set.prod s t ≠ ∅ ↔ (s ≠ ∅ ∧ t ≠ ∅) := by simp [not_eq_empty_iff_exists] @[simp] theorem prod_mk_mem_set_prod_eq {a : α} {b : β} {s : set α} {t : set β} : (a, b) ∈ set.prod s t = (a ∈ s ∧ b ∈ t) := rfl @[simp] theorem univ_prod_univ : set.prod univ univ = (univ : set (α×β)) := set.ext $ assume ⟨a, b⟩, by simp end prod end set
6ec843f5a2479a434214e373aa0fb71dbc06ab2d
4727251e0cd73359b15b664c3170e5d754078599
/src/ring_theory/integral_closure.lean
792ee40e4076ed01e7c68ea7496922ddb78346d5
[ "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
39,838
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 linear_algebra.finite_dimensional import ring_theory.adjoin.fg import ring_theory.polynomial.scale_roots import ring_theory.polynomial.tower import linear_algebra.matrix.determinant /-! # Integral closure of a subring. If A is an R-algebra then `a : A` is integral over R if it is a root of a monic polynomial with coefficients in R. Enough theory is developed to prove that integral elements form a sub-R-algebra of A. ## Main definitions Let `R` be a `comm_ring` and let `A` be an R-algebra. * `ring_hom.is_integral_elem (f : R →+* A) (x : A)` : `x` is integral with respect to the map `f`, * `is_integral (x : A)` : `x` is integral over `R`, i.e., is a root of a monic polynomial with coefficients in `R`. * `integral_closure R A` : the integral closure of `R` in `A`, regarded as a sub-`R`-algebra of `A`. -/ open_locale classical open_locale big_operators polynomial open polynomial submodule section ring variables {R S A : Type*} variables [comm_ring R] [ring A] [ring S] (f : R →+* S) /-- An element `x` of `A` is said to be integral over `R` with respect to `f` if it is a root of a monic polynomial `p : R[X]` evaluated under `f` -/ def ring_hom.is_integral_elem (f : R →+* A) (x : A) := ∃ p : R[X], monic p ∧ eval₂ f x p = 0 /-- A ring homomorphism `f : R →+* A` is said to be integral if every element `A` is integral with respect to the map `f` -/ def ring_hom.is_integral (f : R →+* A) := ∀ x : A, f.is_integral_elem x variables [algebra R A] (R) /-- An element `x` of an algebra `A` over a commutative ring `R` is said to be *integral*, if it is a root of some monic polynomial `p : R[X]`. Equivalently, the element is integral over `R` with respect to the induced `algebra_map` -/ def is_integral (x : A) : Prop := (algebra_map R A).is_integral_elem x variable (A) /-- An algebra is integral if every element of the extension is integral over the base ring -/ def algebra.is_integral : Prop := (algebra_map R A).is_integral variables {R A} lemma ring_hom.is_integral_map {x : R} : f.is_integral_elem (f x) := ⟨X - C x, monic_X_sub_C _, by simp⟩ theorem is_integral_algebra_map {x : R} : is_integral R (algebra_map R A x) := (algebra_map R A).is_integral_map theorem is_integral_of_noetherian (H : is_noetherian R A) (x : A) : is_integral R x := begin let leval : (R[X] →ₗ[R] A) := (aeval x).to_linear_map, let D : ℕ → submodule R A := λ n, (degree_le R n).map leval, let M := well_founded.min (is_noetherian_iff_well_founded.1 H) (set.range D) ⟨_, ⟨0, rfl⟩⟩, have HM : M ∈ set.range D := well_founded.min_mem _ _ _, cases HM with N HN, have HM : ¬M < D (N+1) := well_founded.not_lt_min (is_noetherian_iff_well_founded.1 H) (set.range D) _ ⟨N+1, rfl⟩, rw ← HN at HM, have HN2 : D (N+1) ≤ D N := classical.by_contradiction (λ H, HM (lt_of_le_not_le (map_mono (degree_le_mono (with_bot.coe_le_coe.2 (nat.le_succ N)))) H)), have HN3 : leval (X^(N+1)) ∈ D N, { exact HN2 (mem_map_of_mem (mem_degree_le.2 (degree_X_pow_le _))) }, rcases HN3 with ⟨p, hdp, hpe⟩, refine ⟨X^(N+1) - p, monic_X_pow_sub (mem_degree_le.1 hdp), _⟩, show leval (X ^ (N + 1) - p) = 0, rw [linear_map.map_sub, hpe, sub_self] end theorem is_integral_of_submodule_noetherian (S : subalgebra R A) (H : is_noetherian R S.to_submodule) (x : A) (hx : x ∈ S) : is_integral R x := begin suffices : is_integral R (show S, from ⟨x, hx⟩), { rcases this with ⟨p, hpm, hpx⟩, replace hpx := congr_arg S.val hpx, refine ⟨p, hpm, eq.trans _ hpx⟩, simp only [aeval_def, eval₂, sum_def], rw S.val.map_sum, refine finset.sum_congr rfl (λ n hn, _), rw [S.val.map_mul, S.val.map_pow, S.val.commutes, S.val_apply, subtype.coe_mk], }, refine is_integral_of_noetherian H ⟨x, hx⟩ end end ring section variables {R A B S : Type*} variables [comm_ring R] [comm_ring A] [comm_ring B] [comm_ring S] variables [algebra R A] [algebra R B] (f : R →+* S) theorem is_integral_alg_hom (f : A →ₐ[R] B) {x : A} (hx : is_integral R x) : is_integral R (f x) := let ⟨p, hp, hpx⟩ := hx in ⟨p, hp, by rw [← aeval_def, aeval_alg_hom_apply, aeval_def, hpx, f.map_zero]⟩ @[simp] theorem is_integral_alg_equiv (f : A ≃ₐ[R] B) {x : A} : is_integral R (f x) ↔ is_integral R x := ⟨λ h, by simpa using is_integral_alg_hom f.symm.to_alg_hom h, is_integral_alg_hom f.to_alg_hom⟩ theorem is_integral_of_is_scalar_tower [algebra A B] [is_scalar_tower R A B] (x : B) (hx : is_integral R x) : is_integral A x := let ⟨p, hp, hpx⟩ := hx in ⟨p.map $ algebra_map R A, hp.map _, by rw [← aeval_def, ← is_scalar_tower.aeval_apply, aeval_def, hpx]⟩ theorem is_integral_of_subring {x : A} (T : subring R) (hx : is_integral T x) : is_integral R x := is_integral_of_is_scalar_tower x hx lemma is_integral.algebra_map [algebra A B] [is_scalar_tower R A B] {x : A} (h : is_integral R x) : is_integral R (algebra_map A B x) := begin rcases h with ⟨f, hf, hx⟩, use [f, hf], rw [is_scalar_tower.algebra_map_eq R A B, ← hom_eval₂, hx, ring_hom.map_zero] end lemma is_integral_algebra_map_iff [algebra A B] [is_scalar_tower R A B] {x : A} (hAB : function.injective (algebra_map A B)) : is_integral R (algebra_map A B x) ↔ is_integral R x := begin refine ⟨_, λ h, h.algebra_map⟩, rintros ⟨f, hf, hx⟩, use [f, hf], exact is_scalar_tower.aeval_eq_zero_of_aeval_algebra_map_eq_zero R A B hAB hx, end theorem is_integral_iff_is_integral_closure_finite {r : A} : is_integral R r ↔ ∃ s : set R, s.finite ∧ is_integral (subring.closure s) r := begin split; intro hr, { rcases hr with ⟨p, hmp, hpr⟩, refine ⟨_, set.finite_mem_finset _, p.restriction, monic_restriction.2 hmp, _⟩, erw [← aeval_def, is_scalar_tower.aeval_apply _ R, map_restriction, aeval_def, hpr] }, rcases hr with ⟨s, hs, hsr⟩, exact is_integral_of_subring _ hsr end theorem fg_adjoin_singleton_of_integral (x : A) (hx : is_integral R x) : (algebra.adjoin R ({x} : set A)).to_submodule.fg := begin rcases hx with ⟨f, hfm, hfx⟩, existsi finset.image ((^) x) (finset.range (nat_degree f + 1)), apply le_antisymm, { rw span_le, intros s hs, rw finset.mem_coe at hs, rcases finset.mem_image.1 hs with ⟨k, hk, rfl⟩, clear hk, exact (algebra.adjoin R {x}).pow_mem (algebra.subset_adjoin (set.mem_singleton _)) k }, intros r hr, change r ∈ algebra.adjoin R ({x} : set A) at hr, rw algebra.adjoin_singleton_eq_range_aeval at hr, rcases (aeval x).mem_range.mp hr with ⟨p, rfl⟩, rw ← mod_by_monic_add_div p hfm, rw ← aeval_def at hfx, rw [alg_hom.map_add, alg_hom.map_mul, hfx, zero_mul, add_zero], have : degree (p %ₘ f) ≤ degree f := degree_mod_by_monic_le p hfm, generalize_hyp : p %ₘ f = q at this ⊢, rw [← sum_C_mul_X_eq q, aeval_def, eval₂_sum, sum_def], refine sum_mem (λ k hkq, _), rw [eval₂_mul, eval₂_C, eval₂_pow, eval₂_X, ← algebra.smul_def], refine smul_mem _ _ (subset_span _), rw finset.mem_coe, refine finset.mem_image.2 ⟨_, _, rfl⟩, rw [finset.mem_range, nat.lt_succ_iff], refine le_of_not_lt (λ hk, _), rw [degree_le_iff_coeff_zero] at this, rw [mem_support_iff] at hkq, apply hkq, apply this, exact lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 hk) end theorem fg_adjoin_of_finite {s : set A} (hfs : s.finite) (his : ∀ x ∈ s, is_integral R x) : (algebra.adjoin R s).to_submodule.fg := set.finite.induction_on hfs (λ _, ⟨{1}, submodule.ext $ λ x, by { erw [algebra.adjoin_empty, finset.coe_singleton, ← one_eq_span, one_eq_range, linear_map.mem_range, algebra.mem_bot], refl }⟩) (λ a s has hs ih his, by rw [← set.union_singleton, algebra.adjoin_union_coe_submodule]; exact fg.mul (ih $ λ i hi, his i $ set.mem_insert_of_mem a hi) (fg_adjoin_singleton_of_integral _ $ his a $ set.mem_insert a s)) his lemma is_noetherian_adjoin_finset [is_noetherian_ring R] (s : finset A) (hs : ∀ x ∈ s, is_integral R x) : is_noetherian R (algebra.adjoin R (↑s : set A)) := is_noetherian_of_fg_of_noetherian _ (fg_adjoin_of_finite s.finite_to_set hs) /-- If `S` is a sub-`R`-algebra of `A` and `S` is finitely-generated as an `R`-module, then all elements of `S` are integral over `R`. -/ theorem is_integral_of_mem_of_fg (S : subalgebra R A) (HS : S.to_submodule.fg) (x : A) (hx : x ∈ S) : is_integral R x := begin -- say `x ∈ S`. We want to prove that `x` is integral over `R`. -- Say `S` is generated as an `R`-module by the set `y`. cases HS with y hy, -- We can write `x` as `∑ rᵢ yᵢ` for `yᵢ ∈ Y`. obtain ⟨lx, hlx1, hlx2⟩ : ∃ (l : A →₀ R) (H : l ∈ finsupp.supported R R ↑y), (finsupp.total A A R id) l = x, { rwa [←(@finsupp.mem_span_image_iff_total A A R _ _ _ id ↑y x), set.image_id ↑y, hy] }, -- Note that `y ⊆ S`. have hyS : ∀ {p}, p ∈ y → p ∈ S := λ p hp, show p ∈ S.to_submodule, by { rw ← hy, exact subset_span hp }, -- Now `S` is a subalgebra so the product of two elements of `y` is also in `S`. have : ∀ (jk : (↑(y.product y) : set (A × A))), jk.1.1 * jk.1.2 ∈ S.to_submodule := λ jk, S.mul_mem (hyS (finset.mem_product.1 jk.2).1) (hyS (finset.mem_product.1 jk.2).2), rw [← hy, ← set.image_id ↑y] at this, simp only [finsupp.mem_span_image_iff_total] at this, -- Say `yᵢyⱼ = ∑rᵢⱼₖ yₖ` choose ly hly1 hly2, -- Now let `S₀` be the subring of `R` generated by the `rᵢ` and the `rᵢⱼₖ`. let S₀ : subring R := subring.closure ↑(lx.frange ∪ finset.bUnion finset.univ (finsupp.frange ∘ ly)), -- It suffices to prove that `x` is integral over `S₀`. refine is_integral_of_subring S₀ _, letI : comm_ring S₀ := subring_class.to_comm_ring S₀, letI : algebra S₀ A := algebra.of_subring S₀, -- Claim: the `S₀`-module span (in `A`) of the set `y ∪ {1}` is closed under -- multiplication (indeed, this is the motivation for the definition of `S₀`). have : span S₀ (insert 1 ↑y : set A) * span S₀ (insert 1 ↑y : set A) ≤ span S₀ (insert 1 ↑y : set A), { rw span_mul_span, refine span_le.2 (λ z hz, _), rcases set.mem_mul.1 hz with ⟨p, q, rfl | hp, hq, rfl⟩, { rw one_mul, exact subset_span hq }, rcases hq with rfl | hq, { rw mul_one, exact subset_span (or.inr hp) }, erw ← hly2 ⟨(p, q), finset.mem_product.2 ⟨hp, hq⟩⟩, rw [finsupp.total_apply, finsupp.sum], refine (span S₀ (insert 1 ↑y : set A)).sum_mem (λ t ht, _), have : ly ⟨(p, q), finset.mem_product.2 ⟨hp, hq⟩⟩ t ∈ S₀ := subring.subset_closure (finset.mem_union_right _ $ finset.mem_bUnion.2 ⟨⟨(p, q), finset.mem_product.2 ⟨hp, hq⟩⟩, finset.mem_univ _, finsupp.mem_frange.2 ⟨finsupp.mem_support_iff.1 ht, _, rfl⟩⟩), change (⟨_, this⟩ : S₀) • t ∈ _, exact smul_mem _ _ (subset_span $ or.inr $ hly1 _ ht) }, -- Hence this span is a subring. Call this subring `S₁`. let S₁ : subring A := { carrier := span S₀ (insert 1 ↑y : set A), one_mem' := subset_span $ or.inl rfl, mul_mem' := λ p q hp hq, this $ mul_mem_mul hp hq, zero_mem' := (span S₀ (insert 1 ↑y : set A)).zero_mem, add_mem' := λ _ _, (span S₀ (insert 1 ↑y : set A)).add_mem, neg_mem' := λ _, (span S₀ (insert 1 ↑y : set A)).neg_mem }, have : S₁ = (algebra.adjoin S₀ (↑y : set A)).to_subring, { ext z, suffices : z ∈ span ↥S₀ (insert 1 ↑y : set A) ↔ z ∈ (algebra.adjoin ↥S₀ (y : set A)).to_submodule, { simpa }, split; intro hz, { exact (span_le.2 (set.insert_subset.2 ⟨(algebra.adjoin S₀ ↑y).one_mem, algebra.subset_adjoin⟩)) hz }, { rw [subalgebra.mem_to_submodule, algebra.mem_adjoin_iff] at hz, suffices : subring.closure (set.range ⇑(algebra_map ↥S₀ A) ∪ ↑y) ≤ S₁, { exact this hz }, refine subring.closure_le.2 (set.union_subset _ (λ t ht, subset_span $ or.inr ht)), rw set.range_subset_iff, intro y, rw algebra.algebra_map_eq_smul_one, exact smul_mem _ y (subset_span (or.inl rfl)) } }, have foo : ∀ z, z ∈ S₁ ↔ z ∈ algebra.adjoin ↥S₀ (y : set A), simp [this], haveI : is_noetherian_ring ↥S₀ := is_noetherian_subring_closure _ (finset.finite_to_set _), refine is_integral_of_submodule_noetherian (algebra.adjoin S₀ ↑y) (is_noetherian_of_fg_of_noetherian _ ⟨insert 1 y, by { rw [finset.coe_insert], ext z, simp [S₁], convert foo z}⟩) _ _, rw [← hlx2, finsupp.total_apply, finsupp.sum], refine subalgebra.sum_mem _ (λ r hr, _), have : lx r ∈ S₀ := subring.subset_closure (finset.mem_union_left _ (finset.mem_image_of_mem _ hr)), change (⟨_, this⟩ : S₀) • r ∈ _, rw finsupp.mem_supported at hlx1, exact subalgebra.smul_mem _ (algebra.subset_adjoin $ hlx1 hr) _ end lemma ring_hom.is_integral_of_mem_closure {x y z : S} (hx : f.is_integral_elem x) (hy : f.is_integral_elem y) (hz : z ∈ subring.closure ({x, y} : set S)) : f.is_integral_elem z := begin letI : algebra R S := f.to_algebra, have := (fg_adjoin_singleton_of_integral x hx).mul (fg_adjoin_singleton_of_integral y hy), rw [← algebra.adjoin_union_coe_submodule, set.singleton_union] at this, exact is_integral_of_mem_of_fg (algebra.adjoin R {x, y}) this z (algebra.mem_adjoin_iff.2 $ subring.closure_mono (set.subset_union_right _ _) hz), end theorem is_integral_of_mem_closure {x y z : A} (hx : is_integral R x) (hy : is_integral R y) (hz : z ∈ subring.closure ({x, y} : set A)) : is_integral R z := (algebra_map R A).is_integral_of_mem_closure hx hy hz lemma ring_hom.is_integral_zero : f.is_integral_elem 0 := f.map_zero ▸ f.is_integral_map theorem is_integral_zero : is_integral R (0:A) := (algebra_map R A).is_integral_zero lemma ring_hom.is_integral_one : f.is_integral_elem 1 := f.map_one ▸ f.is_integral_map theorem is_integral_one : is_integral R (1:A) := (algebra_map R A).is_integral_one lemma ring_hom.is_integral_add {x y : S} (hx : f.is_integral_elem x) (hy : f.is_integral_elem y) : f.is_integral_elem (x + y) := f.is_integral_of_mem_closure hx hy $ subring.add_mem _ (subring.subset_closure (or.inl rfl)) (subring.subset_closure (or.inr rfl)) theorem is_integral_add {x y : A} (hx : is_integral R x) (hy : is_integral R y) : is_integral R (x + y) := (algebra_map R A).is_integral_add hx hy lemma ring_hom.is_integral_neg {x : S} (hx : f.is_integral_elem x) : f.is_integral_elem (-x) := f.is_integral_of_mem_closure hx hx (subring.neg_mem _ (subring.subset_closure (or.inl rfl))) theorem is_integral_neg {x : A} (hx : is_integral R x) : is_integral R (-x) := (algebra_map R A).is_integral_neg hx lemma ring_hom.is_integral_sub {x y : S} (hx : f.is_integral_elem x) (hy : f.is_integral_elem y) : f.is_integral_elem (x - y) := by simpa only [sub_eq_add_neg] using f.is_integral_add hx (f.is_integral_neg hy) theorem is_integral_sub {x y : A} (hx : is_integral R x) (hy : is_integral R y) : is_integral R (x - y) := (algebra_map R A).is_integral_sub hx hy lemma ring_hom.is_integral_mul {x y : S} (hx : f.is_integral_elem x) (hy : f.is_integral_elem y) : f.is_integral_elem (x * y) := f.is_integral_of_mem_closure hx hy (subring.mul_mem _ (subring.subset_closure (or.inl rfl)) (subring.subset_closure (or.inr rfl))) theorem is_integral_mul {x y : A} (hx : is_integral R x) (hy : is_integral R y) : is_integral R (x * y) := (algebra_map R A).is_integral_mul hx hy lemma is_integral_smul [algebra S A] [algebra R S] [is_scalar_tower R S A] {x : A} (r : R) (hx : is_integral S x) : is_integral S (r • x) := begin rw [algebra.smul_def, is_scalar_tower.algebra_map_apply R S A], exact is_integral_mul is_integral_algebra_map hx, end variables (R A) /-- The integral closure of R in an R-algebra A. -/ def integral_closure : subalgebra R A := { carrier := { r | is_integral R r }, zero_mem' := is_integral_zero, one_mem' := is_integral_one, add_mem' := λ _ _, is_integral_add, mul_mem' := λ _ _, is_integral_mul, algebra_map_mem' := λ x, is_integral_algebra_map } theorem mem_integral_closure_iff_mem_fg {r : A} : r ∈ integral_closure R A ↔ ∃ M : subalgebra R A, M.to_submodule.fg ∧ r ∈ M := ⟨λ hr, ⟨algebra.adjoin R {r}, fg_adjoin_singleton_of_integral _ hr, algebra.subset_adjoin rfl⟩, λ ⟨M, Hf, hrM⟩, is_integral_of_mem_of_fg M Hf _ hrM⟩ variables {R} {A} lemma adjoin_le_integral_closure {x : A} (hx : is_integral R x) : algebra.adjoin R {x} ≤ integral_closure R A := begin rw [algebra.adjoin_le_iff], simp only [set_like.mem_coe, set.singleton_subset_iff], exact hx end lemma le_integral_closure_iff_is_integral {S : subalgebra R A} : S ≤ integral_closure R A ↔ algebra.is_integral R S := set_like.forall.symm.trans (forall_congr (λ x, show is_integral R (algebra_map S A x) ↔ is_integral R x, from is_integral_algebra_map_iff subtype.coe_injective)) lemma is_integral_sup {S T : subalgebra R A} : algebra.is_integral R ↥(S ⊔ T) ↔ algebra.is_integral R S ∧ algebra.is_integral R T := by simp only [←le_integral_closure_iff_is_integral, sup_le_iff] /-- Mapping an integral closure along an `alg_equiv` gives the integral closure. -/ lemma integral_closure_map_alg_equiv (f : A ≃ₐ[R] B) : (integral_closure R A).map (f : A →ₐ[R] B) = integral_closure R B := begin ext y, rw subalgebra.mem_map, split, { rintros ⟨x, hx, rfl⟩, exact is_integral_alg_hom f hx }, { intro hy, use [f.symm y, is_integral_alg_hom (f.symm : B →ₐ[R] A) hy], simp } end lemma integral_closure.is_integral (x : integral_closure R A) : is_integral R x := let ⟨p, hpm, hpx⟩ := x.2 in ⟨p, hpm, subtype.eq $ by rwa [← aeval_def, subtype.val_eq_coe, ← subalgebra.val_apply, aeval_alg_hom_apply] at hpx⟩ lemma ring_hom.is_integral_of_is_integral_mul_unit (x y : S) (r : R) (hr : f r * y = 1) (hx : f.is_integral_elem (x * y)) : f.is_integral_elem x := begin obtain ⟨p, ⟨p_monic, hp⟩⟩ := hx, refine ⟨scale_roots p r, ⟨(monic_scale_roots_iff r).2 p_monic, _⟩⟩, convert scale_roots_eval₂_eq_zero f hp, rw [mul_comm x y, ← mul_assoc, hr, one_mul], end theorem is_integral_of_is_integral_mul_unit {x y : A} {r : R} (hr : algebra_map R A r * y = 1) (hx : is_integral R (x * y)) : is_integral R x := (algebra_map R A).is_integral_of_is_integral_mul_unit x y r hr hx /-- Generalization of `is_integral_of_mem_closure` bootstrapped up from that lemma -/ lemma is_integral_of_mem_closure' (G : set A) (hG : ∀ x ∈ G, is_integral R x) : ∀ x ∈ (subring.closure G), is_integral R x := λ x hx, subring.closure_induction hx hG is_integral_zero is_integral_one (λ _ _, is_integral_add) (λ _, is_integral_neg) (λ _ _, is_integral_mul) lemma is_integral_of_mem_closure'' {S : Type*} [comm_ring S] {f : R →+* S} (G : set S) (hG : ∀ x ∈ G, f.is_integral_elem x) : ∀ x ∈ (subring.closure G), f.is_integral_elem x := λ x hx, @is_integral_of_mem_closure' R S _ _ f.to_algebra G hG x hx lemma is_integral.pow {x : A} (h : is_integral R x) (n : ℕ) : is_integral R (x ^ n) := (integral_closure R A).pow_mem h n lemma is_integral.nsmul {x : A} (h : is_integral R x) (n : ℕ) : is_integral R (n • x) := (integral_closure R A).nsmul_mem h n lemma is_integral.zsmul {x : A} (h : is_integral R x) (n : ℤ) : is_integral R (n • x) := (integral_closure R A).zsmul_mem h n lemma is_integral.multiset_prod {s : multiset A} (h : ∀ x ∈ s, is_integral R x) : is_integral R s.prod := (integral_closure R A).multiset_prod_mem h lemma is_integral.multiset_sum {s : multiset A} (h : ∀ x ∈ s, is_integral R x) : is_integral R s.sum := (integral_closure R A).multiset_sum_mem h lemma is_integral.prod {α : Type*} {s : finset α} (f : α → A) (h : ∀ x ∈ s, is_integral R (f x)) : is_integral R (∏ x in s, f x) := (integral_closure R A).prod_mem h lemma is_integral.sum {α : Type*} {s : finset α} (f : α → A) (h : ∀ x ∈ s, is_integral R (f x)) : is_integral R (∑ x in s, f x) := (integral_closure R A).sum_mem h lemma is_integral.det {n : Type*} [fintype n] [decidable_eq n] {M : matrix n n A} (h : ∀ i j, is_integral R (M i j)) : is_integral R M.det := begin rw [matrix.det_apply], exact is_integral.sum _ (λ σ hσ, is_integral.zsmul (is_integral.prod _ (λ i hi, h _ _)) _) end section variables (p : R[X]) (x : S) /-- The monic polynomial whose roots are `p.leading_coeff * x` for roots `x` of `p`. -/ noncomputable def normalize_scale_roots (p : R[X]) : R[X] := ∑ i in p.support, monomial i (if i = p.nat_degree then 1 else p.coeff i * p.leading_coeff ^ (p.nat_degree - 1 - i)) lemma normalize_scale_roots_coeff_mul_leading_coeff_pow (i : ℕ) (hp : 1 ≤ nat_degree p) : (normalize_scale_roots p).coeff i * p.leading_coeff ^ i = p.coeff i * p.leading_coeff ^ (p.nat_degree - 1) := begin simp only [normalize_scale_roots, finset_sum_coeff, coeff_monomial, finset.sum_ite_eq', one_mul, zero_mul, mem_support_iff, ite_mul, ne.def, ite_not], split_ifs with h₁ h₂, { simp [h₁], }, { rw [h₂, leading_coeff, ← pow_succ, tsub_add_cancel_of_le hp], }, { rw [mul_assoc, ← pow_add, tsub_add_cancel_of_le], apply nat.le_pred_of_lt, rw lt_iff_le_and_ne, exact ⟨le_nat_degree_of_ne_zero h₁, h₂⟩, }, end lemma leading_coeff_smul_normalize_scale_roots (p : R[X]) : p.leading_coeff • normalize_scale_roots p = scale_roots p p.leading_coeff := begin ext, simp only [coeff_scale_roots, normalize_scale_roots, coeff_monomial, coeff_smul, finset.smul_sum, ne.def, finset.sum_ite_eq', finset_sum_coeff, smul_ite, smul_zero, mem_support_iff], split_ifs with h₁ h₂, { simp [*] }, { simp [*] }, { rw [algebra.id.smul_eq_mul, mul_comm, mul_assoc, ← pow_succ', tsub_right_comm, tsub_add_cancel_of_le], rw nat.succ_le_iff, exact tsub_pos_of_lt (lt_of_le_of_ne (le_nat_degree_of_ne_zero h₁) h₂) }, end lemma normalize_scale_roots_support : (normalize_scale_roots p).support ≤ p.support := begin intro x, contrapose, simp only [not_mem_support_iff, normalize_scale_roots, finset_sum_coeff, coeff_monomial, finset.sum_ite_eq', mem_support_iff, ne.def, not_not, ite_eq_right_iff], intros h₁ h₂, exact (h₂ h₁).rec _, end lemma normalize_scale_roots_degree : (normalize_scale_roots p).degree = p.degree := begin apply le_antisymm, { exact finset.sup_mono (normalize_scale_roots_support p) }, { rw [← degree_scale_roots, ← leading_coeff_smul_normalize_scale_roots], exact degree_smul_le _ _ } end lemma normalize_scale_roots_eval₂_leading_coeff_mul (h : 1 ≤ p.nat_degree) (f : R →+* S) (x : S) : (normalize_scale_roots p).eval₂ f (f p.leading_coeff * x) = f p.leading_coeff ^ (p.nat_degree - 1) * (p.eval₂ f x) := begin rw [eval₂_eq_sum_range, eval₂_eq_sum_range, finset.mul_sum], apply finset.sum_congr, { rw nat_degree_eq_of_degree_eq (normalize_scale_roots_degree p) }, intros n hn, rw [mul_pow, ← mul_assoc, ← f.map_pow, ← f.map_mul, normalize_scale_roots_coeff_mul_leading_coeff_pow _ _ h, f.map_mul, f.map_pow], ring, end lemma normalize_scale_roots_monic (h : p ≠ 0) : (normalize_scale_roots p).monic := begin delta monic leading_coeff, rw nat_degree_eq_of_degree_eq (normalize_scale_roots_degree p), suffices : p = 0 → (0 : R) = 1, { simpa [normalize_scale_roots, coeff_monomial] }, exact λ h', (h h').rec _, end /-- Given a `p : R[X]` and a `x : S` such that `p.eval₂ f x = 0`, `f p.leading_coeff * x` is integral. -/ lemma ring_hom.is_integral_elem_leading_coeff_mul (h : p.eval₂ f x = 0) : f.is_integral_elem (f p.leading_coeff * x) := begin by_cases h' : 1 ≤ p.nat_degree, { use normalize_scale_roots p, have : p ≠ 0 := λ h'', by { rw [h'', nat_degree_zero] at h', exact nat.not_succ_le_zero 0 h' }, use normalize_scale_roots_monic p this, rw [normalize_scale_roots_eval₂_leading_coeff_mul p h' f x, h, mul_zero] }, { by_cases hp : p.map f = 0, { apply_fun (λ q, coeff q p.nat_degree) at hp, rw [coeff_map, coeff_zero, coeff_nat_degree] at hp, rw [hp, zero_mul], exact f.is_integral_zero }, { rw [nat.one_le_iff_ne_zero, not_not] at h', rw [eq_C_of_nat_degree_eq_zero h', eval₂_C] at h, suffices : p.map f = 0, { exact (hp this).rec _ }, rw [eq_C_of_nat_degree_eq_zero h', map_C, h, C_eq_zero] } } end /-- Given a `p : R[X]` and a root `x : S`, then `p.leading_coeff • x : S` is integral over `R`. -/ lemma is_integral_leading_coeff_smul [algebra R S] (h : aeval x p = 0) : is_integral R (p.leading_coeff • x) := begin rw aeval_def at h, rw algebra.smul_def, exact (algebra_map R S).is_integral_elem_leading_coeff_mul p x h, end end end section is_integral_closure /-- `is_integral_closure A R B` is the characteristic predicate stating `A` is the integral closure of `R` in `B`, i.e. that an element of `B` is integral over `R` iff it is an element of (the image of) `A`. -/ class is_integral_closure (A R B : Type*) [comm_ring R] [comm_semiring A] [comm_ring B] [algebra R B] [algebra A B] : Prop := (algebra_map_injective [] : function.injective (algebra_map A B)) (is_integral_iff : ∀ {x : B}, is_integral R x ↔ ∃ y, algebra_map A B y = x) instance integral_closure.is_integral_closure (R A : Type*) [comm_ring R] [comm_ring A] [algebra R A] : is_integral_closure (integral_closure R A) R A := ⟨subtype.coe_injective, λ x, ⟨λ h, ⟨⟨x, h⟩, rfl⟩, by { rintro ⟨⟨_, h⟩, rfl⟩, exact h }⟩⟩ namespace is_integral_closure variables {R A B : Type*} [comm_ring R] [comm_ring A] [comm_ring B] variables [algebra R B] [algebra A B] [is_integral_closure A R B] variables (R) {A} (B) protected theorem is_integral [algebra R A] [is_scalar_tower R A B] (x : A) : is_integral R x := (is_integral_algebra_map_iff (algebra_map_injective A R B)).mp $ show is_integral R (algebra_map A B x), from is_integral_iff.mpr ⟨x, rfl⟩ theorem is_integral_algebra [algebra R A] [is_scalar_tower R A B] : algebra.is_integral R A := λ x, is_integral_closure.is_integral R B x variables {R} (A) {B} /-- If `x : B` is integral over `R`, then it is an element of the integral closure of `R` in `B`. -/ noncomputable def mk' (x : B) (hx : is_integral R x) : A := classical.some (is_integral_iff.mp hx) @[simp] lemma algebra_map_mk' (x : B) (hx : is_integral R x) : algebra_map A B (mk' A x hx) = x := classical.some_spec (is_integral_iff.mp hx) @[simp] lemma mk'_one (h : is_integral R (1 : B) := is_integral_one) : mk' A 1 h = 1 := algebra_map_injective A R B $ by rw [algebra_map_mk', ring_hom.map_one] @[simp] lemma mk'_zero (h : is_integral R (0 : B) := is_integral_zero) : mk' A 0 h = 0 := algebra_map_injective A R B $ by rw [algebra_map_mk', ring_hom.map_zero] @[simp] lemma mk'_add (x y : B) (hx : is_integral R x) (hy : is_integral R y) : mk' A (x + y) (is_integral_add hx hy) = mk' A x hx + mk' A y hy := algebra_map_injective A R B $ by simp only [algebra_map_mk', ring_hom.map_add] @[simp] lemma mk'_mul (x y : B) (hx : is_integral R x) (hy : is_integral R y) : mk' A (x * y) (is_integral_mul hx hy) = mk' A x hx * mk' A y hy := algebra_map_injective A R B $ by simp only [algebra_map_mk', ring_hom.map_mul] @[simp] lemma mk'_algebra_map [algebra R A] [is_scalar_tower R A B] (x : R) (h : is_integral R (algebra_map R B x) := is_integral_algebra_map) : is_integral_closure.mk' A (algebra_map R B x) h = algebra_map R A x := algebra_map_injective A R B $ by rw [algebra_map_mk', ← is_scalar_tower.algebra_map_apply] section lift variables {R} (A B) {S : Type*} [comm_ring S] [algebra R S] [algebra S B] [is_scalar_tower R S B] variables [algebra R A] [is_scalar_tower R A B] (h : algebra.is_integral R S) /-- If `B / S / R` is a tower of ring extensions where `S` is integral over `R`, then `S` maps (uniquely) into an integral closure `B / A / R`. -/ noncomputable def lift : S →ₐ[R] A := { to_fun := λ x, mk' A (algebra_map S B x) (is_integral.algebra_map (h x)), map_one' := by simp only [ring_hom.map_one, mk'_one], map_zero' := by simp only [ring_hom.map_zero, mk'_zero], map_add' := λ x y, by simp_rw [← mk'_add, ring_hom.map_add], map_mul' := λ x y, by simp_rw [← mk'_mul, ring_hom.map_mul], commutes' := λ x, by simp_rw [← is_scalar_tower.algebra_map_apply, mk'_algebra_map] } @[simp] lemma algebra_map_lift (x : S) : algebra_map A B (lift A B h x) = algebra_map S B x := algebra_map_mk' _ _ _ end lift section equiv variables (R A B) (A' : Type*) [comm_ring A'] [algebra A' B] [is_integral_closure A' R B] variables [algebra R A] [algebra R A'] [is_scalar_tower R A B] [is_scalar_tower R A' B] /-- Integral closures are all isomorphic to each other. -/ noncomputable def equiv : A ≃ₐ[R] A' := alg_equiv.of_alg_hom (lift _ B (is_integral_algebra R B)) (lift _ B (is_integral_algebra R B)) (by { ext x, apply algebra_map_injective A' R B, simp }) (by { ext x, apply algebra_map_injective A R B, simp }) @[simp] lemma algebra_map_equiv (x : A) : algebra_map A' B (equiv R A B A' x) = algebra_map A B x := algebra_map_lift _ _ _ _ end equiv end is_integral_closure end is_integral_closure section algebra open algebra variables {R A B S T : Type*} variables [comm_ring R] [comm_ring A] [comm_ring B] [comm_ring S] [comm_ring T] variables [algebra A B] [algebra R B] (f : R →+* S) (g : S →+* T) lemma is_integral_trans_aux (x : B) {p : A[X]} (pmonic : monic p) (hp : aeval x p = 0) : is_integral (adjoin R (↑(p.map $ algebra_map A B).frange : set B)) x := begin generalize hS : (↑(p.map $ algebra_map A B).frange : set B) = S, have coeffs_mem : ∀ i, (p.map $ algebra_map A B).coeff i ∈ adjoin R S, { intro i, by_cases hi : (p.map $ algebra_map A B).coeff i = 0, { rw hi, exact subalgebra.zero_mem _ }, rw ← hS, exact subset_adjoin (coeff_mem_frange _ _ hi) }, obtain ⟨q, hq⟩ : ∃ q : (adjoin R S)[X], q.map (algebra_map (adjoin R S) B) = (p.map $ algebra_map A B), { rw ← set.mem_range, exact (polynomial.mem_map_range _).2 (λ i, ⟨⟨_, coeffs_mem i⟩, rfl⟩) }, use q, split, { suffices h : (q.map (algebra_map (adjoin R S) B)).monic, { refine monic_of_injective _ h, exact subtype.val_injective }, { rw hq, exact pmonic.map _ } }, { convert hp using 1, replace hq := congr_arg (eval x) hq, convert hq using 1; symmetry; apply eval_map }, end variables [algebra R A] [is_scalar_tower R A B] /-- If A is an R-algebra all of whose elements are integral over R, and x is an element of an A-algebra that is integral over A, then x is integral over R.-/ lemma is_integral_trans (A_int : is_integral R A) (x : B) (hx : is_integral A x) : is_integral R x := begin rcases hx with ⟨p, pmonic, hp⟩, let S : set B := ↑(p.map $ algebra_map A B).frange, refine is_integral_of_mem_of_fg (adjoin R (S ∪ {x})) _ _ (subset_adjoin $ or.inr rfl), refine fg_trans (fg_adjoin_of_finite (finset.finite_to_set _) (λ x hx, _)) _, { rw [finset.mem_coe, frange, finset.mem_image] at hx, rcases hx with ⟨i, _, rfl⟩, rw coeff_map, exact is_integral_alg_hom (is_scalar_tower.to_alg_hom R A B) (A_int _) }, { apply fg_adjoin_singleton_of_integral, exact is_integral_trans_aux _ pmonic hp } end /-- If A is an R-algebra all of whose elements are integral over R, and B is an A-algebra all of whose elements are integral over A, then all elements of B are integral over R.-/ lemma algebra.is_integral_trans (hA : is_integral R A) (hB : is_integral A B) : is_integral R B := λ x, is_integral_trans hA x (hB x) lemma ring_hom.is_integral_trans (hf : f.is_integral) (hg : g.is_integral) : (g.comp f).is_integral := @algebra.is_integral_trans R S T _ _ _ g.to_algebra (g.comp f).to_algebra f.to_algebra (@is_scalar_tower.of_algebra_map_eq R S T _ _ _ f.to_algebra g.to_algebra (g.comp f).to_algebra (ring_hom.comp_apply g f)) hf hg lemma ring_hom.is_integral_of_surjective (hf : function.surjective f) : f.is_integral := λ x, (hf x).rec_on (λ y hy, (hy ▸ f.is_integral_map : f.is_integral_elem x)) lemma is_integral_of_surjective (h : function.surjective (algebra_map R A)) : is_integral R A := (algebra_map R A).is_integral_of_surjective h /-- If `R → A → B` is an algebra tower with `A → B` injective, then if the entire tower is an integral extension so is `R → A` -/ lemma is_integral_tower_bot_of_is_integral (H : function.injective (algebra_map A B)) {x : A} (h : is_integral R (algebra_map A B x)) : is_integral R x := begin rcases h with ⟨p, ⟨hp, hp'⟩⟩, refine ⟨p, ⟨hp, _⟩⟩, rw [is_scalar_tower.algebra_map_eq R A B, ← eval₂_map, eval₂_hom, ← ring_hom.map_zero (algebra_map A B)] at hp', rw [eval₂_eq_eval_map], exact H hp', end lemma ring_hom.is_integral_tower_bot_of_is_integral (hg : function.injective g) (hfg : (g.comp f).is_integral) : f.is_integral := λ x, @is_integral_tower_bot_of_is_integral R S T _ _ _ g.to_algebra (g.comp f).to_algebra f.to_algebra (@is_scalar_tower.of_algebra_map_eq R S T _ _ _ f.to_algebra g.to_algebra (g.comp f).to_algebra (ring_hom.comp_apply g f)) hg x (hfg (g x)) lemma is_integral_tower_bot_of_is_integral_field {R A B : Type*} [comm_ring R] [field A] [comm_ring B] [nontrivial B] [algebra R A] [algebra A B] [algebra R B] [is_scalar_tower R A B] {x : A} (h : is_integral R (algebra_map A B x)) : is_integral R x := is_integral_tower_bot_of_is_integral (algebra_map A B).injective h lemma ring_hom.is_integral_elem_of_is_integral_elem_comp {x : T} (h : (g.comp f).is_integral_elem x) : g.is_integral_elem x := let ⟨p, ⟨hp, hp'⟩⟩ := h in ⟨p.map f, hp.map f, by rwa ← eval₂_map at hp'⟩ lemma ring_hom.is_integral_tower_top_of_is_integral (h : (g.comp f).is_integral) : g.is_integral := λ x, ring_hom.is_integral_elem_of_is_integral_elem_comp f g (h x) /-- If `R → A → B` is an algebra tower, then if the entire tower is an integral extension so is `A → B`. -/ lemma is_integral_tower_top_of_is_integral {x : B} (h : is_integral R x) : is_integral A x := begin rcases h with ⟨p, ⟨hp, hp'⟩⟩, refine ⟨p.map (algebra_map R A), ⟨hp.map (algebra_map R A), _⟩⟩, rw [is_scalar_tower.algebra_map_eq R A B, ← eval₂_map] at hp', exact hp', end lemma ring_hom.is_integral_quotient_of_is_integral {I : ideal S} (hf : f.is_integral) : (ideal.quotient_map I f le_rfl).is_integral := begin rintros ⟨x⟩, obtain ⟨p, ⟨p_monic, hpx⟩⟩ := hf x, refine ⟨p.map (ideal.quotient.mk _), ⟨p_monic.map _, _⟩⟩, simpa only [hom_eval₂, eval₂_map] using congr_arg (ideal.quotient.mk I) hpx end lemma is_integral_quotient_of_is_integral {I : ideal A} (hRA : is_integral R A) : is_integral (R ⧸ I.comap (algebra_map R A)) (A ⧸ I) := (algebra_map R A).is_integral_quotient_of_is_integral hRA lemma is_integral_quotient_map_iff {I : ideal S} : (ideal.quotient_map I f le_rfl).is_integral ↔ ((ideal.quotient.mk I).comp f : R →+* S ⧸ I).is_integral := begin let g := ideal.quotient.mk (I.comap f), have := ideal.quotient_map_comp_mk le_rfl, refine ⟨λ h, _, λ h, ring_hom.is_integral_tower_top_of_is_integral g _ (this ▸ h)⟩, refine this ▸ ring_hom.is_integral_trans g (ideal.quotient_map I f le_rfl) _ h, exact ring_hom.is_integral_of_surjective g ideal.quotient.mk_surjective, end /-- If the integral extension `R → S` is injective, and `S` is a field, then `R` is also a field. -/ lemma is_field_of_is_integral_of_is_field {R S : Type*} [comm_ring R] [nontrivial R] [comm_ring S] [is_domain S] [algebra R S] (H : is_integral R S) (hRS : function.injective (algebra_map R S)) (hS : is_field S) : is_field R := begin refine ⟨⟨0, 1, zero_ne_one⟩, mul_comm, λ a ha, _⟩, -- Let `a_inv` be the inverse of `algebra_map R S a`, -- then we need to show that `a_inv` is of the form `algebra_map R S b`. obtain ⟨a_inv, ha_inv⟩ := hS.mul_inv_cancel (λ h, ha (hRS (trans h (ring_hom.map_zero _).symm))), -- Let `p : R[X]` be monic with root `a_inv`, -- and `q` be `p` with coefficients reversed (so `q(a) = q'(a) * a + 1`). -- We claim that `q(a) = 0`, so `-q'(a)` is the inverse of `a`. obtain ⟨p, p_monic, hp⟩ := H a_inv, use -∑ (i : ℕ) in finset.range p.nat_degree, (p.coeff i) * a ^ (p.nat_degree - i - 1), -- `q(a) = 0`, because multiplying everything with `a_inv^n` gives `p(a_inv) = 0`. -- TODO: this could be a lemma for `polynomial.reverse`. have hq : ∑ (i : ℕ) in finset.range (p.nat_degree + 1), (p.coeff i) * a ^ (p.nat_degree - i) = 0, { apply (injective_iff_map_eq_zero (algebra_map R S)).mp hRS, have a_inv_ne_zero : a_inv ≠ 0 := right_ne_zero_of_mul (mt ha_inv.symm.trans one_ne_zero), refine (mul_eq_zero.mp _).resolve_right (pow_ne_zero p.nat_degree a_inv_ne_zero), rw [eval₂_eq_sum_range] at hp, rw [ring_hom.map_sum, finset.sum_mul], refine (finset.sum_congr rfl (λ i hi, _)).trans hp, rw [ring_hom.map_mul, mul_assoc], congr, have : a_inv ^ p.nat_degree = a_inv ^ (p.nat_degree - i) * a_inv ^ i, { rw [← pow_add a_inv, tsub_add_cancel_of_le (nat.le_of_lt_succ (finset.mem_range.mp hi))] }, rw [ring_hom.map_pow, this, ← mul_assoc, ← mul_pow, ha_inv, one_pow, one_mul] }, -- Since `q(a) = 0` and `q(a) = q'(a) * a + 1`, we have `a * -q'(a) = 1`. -- TODO: we could use a lemma for `polynomial.div_X` here. rw [finset.sum_range_succ_comm, p_monic.coeff_nat_degree, one_mul, tsub_self, pow_zero, add_eq_zero_iff_eq_neg, eq_comm] at hq, rw [mul_comm, neg_mul, finset.sum_mul], convert hq using 2, refine finset.sum_congr rfl (λ i hi, _), have : 1 ≤ p.nat_degree - i := le_tsub_of_add_le_left (finset.mem_range.mp hi), rw [mul_assoc, ← pow_succ', tsub_add_cancel_of_le this] end lemma is_field_of_is_integral_of_is_field' {R S : Type*} [comm_ring R] [comm_ring S] [is_domain S] [algebra R S] (H : algebra.is_integral R S) (hR : is_field R) : is_field S := begin letI := hR.to_field, refine ⟨⟨0, 1, zero_ne_one⟩, mul_comm, λ x hx, _⟩, let A := algebra.adjoin R ({x} : set S), haveI : is_noetherian R A := is_noetherian_of_fg_of_noetherian A.to_submodule (fg_adjoin_singleton_of_integral x (H x)), haveI : module.finite R A := module.is_noetherian.finite R A, obtain ⟨y, hy⟩ := linear_map.surjective_of_injective (@lmul_left_injective R A _ _ _ _ ⟨x, subset_adjoin (set.mem_singleton x)⟩ (λ h, hx (subtype.ext_iff.mp h))) 1, exact ⟨y, subtype.ext_iff.mp hy⟩, end lemma is_integral.is_field_iff_is_field {R S : Type*} [comm_ring R] [nontrivial R] [comm_ring S] [is_domain S] [algebra R S] (H : algebra.is_integral R S) (hRS : function.injective (algebra_map R S)) : is_field R ↔ is_field S := ⟨is_field_of_is_integral_of_is_field' H, is_field_of_is_integral_of_is_field H hRS⟩ end algebra theorem integral_closure_idem {R : Type*} {A : Type*} [comm_ring R] [comm_ring A] [algebra R A] : integral_closure (integral_closure R A : set A) A = ⊥ := eq_bot_iff.2 $ λ x hx, algebra.mem_bot.2 ⟨⟨x, @is_integral_trans _ _ _ _ _ _ _ _ (integral_closure R A).algebra _ integral_closure.is_integral x hx⟩, rfl⟩ section is_domain variables {R S : Type*} [comm_ring R] [comm_ring S] [is_domain S] [algebra R S] instance : is_domain (integral_closure R S) := infer_instance end is_domain
77ec997217a799fc8270a6c8138c5cbe44e014c3
2a70b774d16dbdf5a533432ee0ebab6838df0948
/_target/deps/mathlib/src/measure_theory/interval_integral.lean
3f79f3759b9e9d42d17655831056ec8c103229a1
[ "Apache-2.0" ]
permissive
hjvromen/lewis
40b035973df7c77ebf927afab7878c76d05ff758
105b675f73630f028ad5d890897a51b3c1146fb0
refs/heads/master
1,677,944,636,343
1,676,555,301,000
1,676,555,301,000
327,553,599
0
0
null
null
null
null
UTF-8
Lean
false
false
74,389
lean
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Yury G. Kudryashov -/ import measure_theory.set_integral import measure_theory.lebesgue_measure import analysis.calculus.fderiv_measurable import analysis.calculus.mean_value /-! # Integral over an interval In this file we define `∫ x in a..b, f x ∂μ` to be `∫ x in Ioc a b, f x ∂μ` if `a ≤ b` and `-∫ x in Ioc b a, f x ∂μ` if `b ≤ a`. We prove a few simple properties and many versions of the first part of the [fundamental theorem of calculus](https://en.wikipedia.org/wiki/Fundamental_theorem_of_calculus). Recall that it states that the function `(u, v) ↦ ∫ x in u..v, f x` has derivative `(δu, δv) ↦ δv • f b - δu • f a` at `(a, b)` provided that `f` is continuous at `a` and `b`. ## Main statements ### FTC-1 for Lebesgue measure We prove several versions of FTC-1, all in the `interval_integral` namespace. Many of them follow the naming scheme `integral_has(_strict?)_(f?)deriv(_within?)_at(_of_tendsto_ae?)(_right|_left?)`. They formulate FTC in terms of `has(_strict?)_(f?)deriv(_within?)_at`. Let us explain the meaning of each part of the name: * `_strict` means that the theorem is about strict differentiability; * `f` means that the theorem is about differentiability in both endpoints; incompatible with `_right|_left`; * `_within` means that the theorem is about one-sided derivatives, see below for details; * `_of_tendsto_ae` means that instead of continuity the theorem assumes that `f` has a finite limit almost surely as `x` tends to `a` and/or `b`; * `_right` or `_left` mean that the theorem is about differentiability in the right (resp., left) endpoint. We also reformulate these theorems in terms of `(f?)deriv(_within?)`. These theorems are named `(f?)deriv(_within?)_integral(_of_tendsto_ae?)(_right|_left?)` with the same meaning of parts of the name. ### One-sided derivatives Theorem `integral_has_fderiv_within_at_of_tendsto_ae` states that `(u, v) ↦ ∫ x in u..v, f x` has a derivative `(δu, δv) ↦ δv • cb - δu • ca` within the set `s × t` at `(a, b)` provided that `f` tends to `ca` (resp., `cb`) almost surely at `la` (resp., `lb`), where possible values of `s`, `t`, and corresponding filters `la`, `lb` are given in the following table. | `s` | `la` | `t` | `lb` | | ------- | ---- | --- | ---- | | `Iic a` | `𝓝[Iic a] a` | `Iic b` | `𝓝[Iic b] b` | | `Ici a` | `𝓝[Ioi a] a` | `Ici b` | `𝓝[Ioi b] b` | | `{a}` | `⊥` | `{b}` | `⊥` | | `univ` | `𝓝 a` | `univ` | `𝓝 b` | We use a typeclass `FTC_filter` to make Lean automatically find `la`/`lb` based on `s`/`t`. This way we can formulate one theorem instead of `16` (or `8` if we leave only non-trivial ones not covered by `integral_has_deriv_within_at_of_tendsto_ae_(left|right)` and `integral_has_fderiv_at_of_tendsto_ae`). Similarly, `integral_has_deriv_within_at_of_tendsto_ae_right` works for both one-sided derivatives using the same typeclass to find an appropriate filter. ### FTC for a locally finite measure Before proving FTC for the Lebesgue measure, we prove a few statements that can be seen as FTC for any measure. The most general of them, `measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae`, states the following. Let `(la, la')` be an `FTC_filter` pair of filters around `a` (i.e., `FTC_filter a la la'`) and let `(lb, lb')` be an `FTC_filter` pair of filters around `b`. If `f` has finite limits `ca` and `cb` almost surely at `la'` and `lb'`, respectively, then `∫ x in va..vb, f x ∂μ - ∫ x in ua..ub, f x ∂μ = ∫ x in ub..vb, cb ∂μ - ∫ x in ua..va, ca ∂μ + o(∥∫ x in ua..va, (1:ℝ) ∂μ∥ + ∥∫ x in ub..vb, (1:ℝ) ∂μ∥)` as `ua` and `va` tend to `la` while `ub` and `vb` tend to `lb`. ## Implementation notes ### Avoiding `if`, `min`, and `max` In order to avoid `if`s in the definition, we define `interval_integrable f μ a b` as `integrable_on f (Ioc a b) μ ∧ integrable_on f (Ioc b a) μ`. For any `a`, `b` one of these intervals is empty and the other coincides with `Ioc (min a b) (max a b)`. Similarly, we define `∫ x in a..b, f x ∂μ` to be `∫ x in Ioc a b, f x ∂μ - ∫ x in Ioc b a, f x ∂μ`. Again, for any `a`, `b` one of these integrals is zero, and the other gives the expected result. This way some properties can be translated from integrals over sets without dealing with the cases `a ≤ b` and `b ≤ a` separately. ### Choice of the interval We use integral over `Ioc (min a b) (max a b)` instead of one of the other three possible intervals with the same endpoints for two reasons: * this way `∫ x in a..b, f x ∂μ + ∫ x in b..c, f x ∂μ = ∫ x in a..c, f x ∂μ` holds whenever `f` is integrable on each interval; in particular, it works even if the measure `μ` has an atom at `b`; this rules out `Ioo` and `Icc` intervals; * with this definition for a probability measure `μ`, the integral `∫ x in a..b, 1 ∂μ` equals the difference $F_μ(b)-F_μ(a)$, where $F_μ(a)=μ(-∞, a]$ is the [cumulative distribution function](https://en.wikipedia.org/wiki/Cumulative_distribution_function) of `μ`. ### `FTC_filter` class As explained above, many theorems in this file rely on the typeclass `FTC_filter (a : α) (l l' : filter α)` to avoid code duplication. This typeclass combines four assumptions: - `pure a ≤ l`; - `l' ≤ 𝓝 a`; - `l'` has a basis of measurable sets; - if `u n` and `v n` tend to `l`, then for any `s ∈ l'`, `Ioc (u n) (v n)` is eventually included in `s`. This typeclass has exactly four “real” instances: `(a, pure a, ⊥)`, `(a, 𝓝[Ici a] a, 𝓝[Ioi a] a)`, `(a, 𝓝[Iic a] a, 𝓝[Iic a] a)`, `(a, 𝓝 a, 𝓝 a)`, and two instances that are equal to the first and last “real” instances: `(a, 𝓝[{a}] a, ⊥)` and `(a, 𝓝[univ] a, 𝓝[univ] a)`. While the difference between `Ici a` and `Ioi a` doesn't matter for theorems about Lebesgue measure, it becomes important in the versions of FTC about any locally finite measure if this measure has an atom at one of the endpoints. ## Tags integral, fundamental theorem of calculus -/ noncomputable theory open topological_space (second_countable_topology) open measure_theory set classical filter open_locale classical topological_space filter variables {α β 𝕜 E F : Type*} [linear_order α] [measurable_space α] [measurable_space E] [normed_group E] /-! ### Integrability at an interval -/ /-- A function `f` is called *interval integrable* with respect to a measure `μ` on an unordered interval `a..b` if it is integrable on both intervals `(a, b]` and `(b, a]`. One of these intervals is always empty, so this property is equivalent to `f` being integrable on `(min a b, max a b]`. -/ def interval_integrable (f : α → E) (μ : measure α) (a b : α) := integrable_on f (Ioc a b) μ ∧ integrable_on f (Ioc b a) μ lemma measure_theory.integrable.interval_integrable {f : α → E} {μ : measure α} (hf : integrable f μ) {a b : α} : interval_integrable f μ a b := ⟨hf.integrable_on, hf.integrable_on⟩ namespace interval_integrable section variables {f : α → E} {a b c : α} {μ : measure α} @[symm] lemma symm (h : interval_integrable f μ a b) : interval_integrable f μ b a := h.symm @[refl] lemma refl : interval_integrable f μ a a := by split; simp @[trans] lemma trans (hab : interval_integrable f μ a b) (hbc : interval_integrable f μ b c) : interval_integrable f μ a c := ⟨(hab.1.union hbc.1).mono_set Ioc_subset_Ioc_union_Ioc, (hbc.2.union hab.2).mono_set Ioc_subset_Ioc_union_Ioc⟩ lemma neg [borel_space E] (h : interval_integrable f μ a b) : interval_integrable (-f) μ a b := ⟨h.1.neg, h.2.neg⟩ protected lemma ae_measurable (h : interval_integrable f μ a b) : ae_measurable f (μ.restrict (Ioc a b)):= h.1.ae_measurable protected lemma ae_measurable' (h : interval_integrable f μ a b) : ae_measurable f (μ.restrict (Ioc b a)):= h.2.ae_measurable end variables [borel_space E] {f g : α → E} {a b : α} {μ : measure α} lemma smul [normed_field 𝕜] [normed_space 𝕜 E] {f : α → E} {a b : α} {μ : measure α} (h : interval_integrable f μ a b) (r : 𝕜) : interval_integrable (r • f) μ a b := ⟨h.1.smul r, h.2.smul r⟩ lemma add [second_countable_topology E] (hf : interval_integrable f μ a b) (hg : interval_integrable g μ a b) : interval_integrable (f + g) μ a b := ⟨hf.1.add hg.1, hf.2.add hg.2⟩ lemma sub [second_countable_topology E] (hf : interval_integrable f μ a b) (hg : interval_integrable g μ a b) : interval_integrable (f - g) μ a b := ⟨hf.1.sub hg.1, hf.2.sub hg.2⟩ end interval_integrable section variables {μ : measure ℝ} [locally_finite_measure μ] lemma continuous_on.interval_integrable [borel_space E] {u : ℝ → E} {a b : ℝ} (hu : continuous_on u (interval a b)) : interval_integrable u μ a b := begin split, all_goals { refine measure_theory.integrable_on.mono_set _ Ioc_subset_Icc_self, refine continuous_on.integrable_on_compact compact_Icc (hu.mono _) }, exacts [Icc_subset_interval, Icc_subset_interval'] end lemma continuous_on.interval_integrable_of_Icc [borel_space E] {u : ℝ → E} {a b : ℝ} (h : a ≤ b) (hu : continuous_on u (Icc a b)) : interval_integrable u μ a b := continuous_on.interval_integrable ((interval_of_le h).symm ▸ hu) /-- A continuous function on `ℝ` is `interval_integrable` with respect to any locally finite measure `ν` on ℝ. -/ lemma continuous.interval_integrable [borel_space E] {u : ℝ → E} (hu : continuous u) (a b : ℝ) : interval_integrable u μ a b := hu.continuous_on.interval_integrable end /-- Let `l'` be a measurably generated filter; let `l` be a of filter such that each `s ∈ l'` eventually includes `Ioc u v` as both `u` and `v` tend to `l`. Let `μ` be a measure finite at `l'`. Suppose that `f : α → E` has a finite limit at `l' ⊓ μ.ae`. Then `f` is interval integrable on `u..v` provided that both `u` and `v` tend to `l`. Typeclass instances allow Lean to find `l'` based on `l` but not vice versa, so `apply tendsto.eventually_interval_integrable_ae` will generate goals `filter α` and `tendsto_Ixx_class Ioc ?m_1 l'`. -/ lemma filter.tendsto.eventually_interval_integrable_ae {f : α → E} {μ : measure α} {l l' : filter α} (hfm : measurable_at_filter f l' μ) [tendsto_Ixx_class Ioc l l'] [is_measurably_generated l'] (hμ : μ.finite_at_filter l') {c : E} (hf : tendsto f (l' ⊓ μ.ae) (𝓝 c)) {u v : β → α} {lt : filter β} (hu : tendsto u lt l) (hv : tendsto v lt l) : ∀ᶠ t in lt, interval_integrable f μ (u t) (v t) := have _ := (hf.integrable_at_filter_ae hfm hμ).eventually, ((hu.Ioc hv).eventually this).and $ (hv.Ioc hu).eventually this /-- Let `l'` be a measurably generated filter; let `l` be a of filter such that each `s ∈ l'` eventually includes `Ioc u v` as both `u` and `v` tend to `l`. Let `μ` be a measure finite at `l'`. Suppose that `f : α → E` has a finite limit at `l`. Then `f` is interval integrable on `u..v` provided that both `u` and `v` tend to `l`. Typeclass instances allow Lean to find `l'` based on `l` but not vice versa, so `apply tendsto.eventually_interval_integrable_ae` will generate goals `filter α` and `tendsto_Ixx_class Ioc ?m_1 l'`. -/ lemma filter.tendsto.eventually_interval_integrable {f : α → E} {μ : measure α} {l l' : filter α} (hfm : measurable_at_filter f l' μ) [tendsto_Ixx_class Ioc l l'] [is_measurably_generated l'] (hμ : μ.finite_at_filter l') {c : E} (hf : tendsto f l' (𝓝 c)) {u v : β → α} {lt : filter β} (hu : tendsto u lt l) (hv : tendsto v lt l) : ∀ᶠ t in lt, interval_integrable f μ (u t) (v t) := (hf.mono_left inf_le_left).eventually_interval_integrable_ae hfm hμ hu hv /-! ### Interval integral: definition and basic properties In this section we define `∫ x in a..b, f x ∂μ` as `∫ x in Ioc a b, f x ∂μ - ∫ x in Ioc b a, f x ∂μ` and prove some basic properties. -/ variables [second_countable_topology E] [complete_space E] [normed_space ℝ E] [borel_space E] /-- The interval integral `∫ x in a..b, f x ∂μ` is defined as `∫ x in Ioc a b, f x ∂μ - ∫ x in Ioc b a, f x ∂μ`. If `a ≤ b`, then it equals `∫ x in Ioc a b, f x ∂μ`, otherwise it equals `-∫ x in Ioc b a, f x ∂μ`. -/ def interval_integral (f : α → E) (a b : α) (μ : measure α) := ∫ x in Ioc a b, f x ∂μ - ∫ x in Ioc b a, f x ∂μ notation `∫` binders ` in ` a `..` b `, ` r:(scoped:60 f, f) ` ∂` μ:70 := interval_integral r a b μ notation `∫` binders ` in ` a `..` b `, ` r:(scoped:60 f, interval_integral f a b volume) := r namespace interval_integral section variables {a b c d : α} {f g : α → E} {μ : measure α} @[simp] lemma integral_zero : ∫ x in a..b, (0 : E) ∂μ = 0 := by simp [interval_integral] lemma integral_of_le (h : a ≤ b) : ∫ x in a..b, f x ∂μ = ∫ x in Ioc a b, f x ∂μ := by simp [interval_integral, h] @[simp] lemma integral_same : ∫ x in a..a, f x ∂μ = 0 := sub_self _ lemma integral_symm (a b) : ∫ x in b..a, f x ∂μ = -∫ x in a..b, f x ∂μ := by simp only [interval_integral, neg_sub] lemma integral_of_ge (h : b ≤ a) : ∫ x in a..b, f x ∂μ = -∫ x in Ioc b a, f x ∂μ := by simp only [integral_symm b, integral_of_le h] lemma integral_cases (f : α → E) (a b) : ∫ x in a..b, f x ∂μ ∈ ({∫ x in Ioc (min a b) (max a b), f x ∂μ, -∫ x in Ioc (min a b) (max a b), f x ∂μ} : set E) := (le_total a b).imp (λ h, by simp [h, integral_of_le]) (λ h, by simp [h, integral_of_ge]) lemma integral_non_ae_measurable {f : α → E} {a b} (h : a < b) (hf : ¬ ae_measurable f (μ.restrict (Ioc a b))) : ∫ x in a..b, f x ∂μ = 0 := by rw [integral_of_le h.le, integral_non_ae_measurable hf] lemma norm_integral_eq_norm_integral_Ioc : ∥∫ x in a..b, f x ∂μ∥ = ∥∫ x in Ioc (min a b) (max a b), f x ∂μ∥ := (integral_cases f a b).elim (congr_arg _) (λ h, (congr_arg _ h).trans (norm_neg _)) lemma norm_integral_le_integral_norm_Ioc : ∥∫ x in a..b, f x ∂μ∥ ≤ ∫ x in Ioc (min a b) (max a b), ∥f x∥ ∂μ := calc ∥∫ x in a..b, f x ∂μ∥ = ∥∫ x in Ioc (min a b) (max a b), f x ∂μ∥ : norm_integral_eq_norm_integral_Ioc ... ≤ ∫ x in Ioc (min a b) (max a b), ∥f x∥ ∂μ : norm_integral_le_integral_norm f lemma norm_integral_le_abs_integral_norm : ∥∫ x in a..b, f x ∂μ∥ ≤ abs (∫ x in a..b, ∥f x∥ ∂μ) := begin simp only [← real.norm_eq_abs, norm_integral_eq_norm_integral_Ioc], exact le_trans (norm_integral_le_integral_norm _) (le_abs_self _) end lemma norm_integral_le_of_norm_le_const_ae {a b C : ℝ} {f : ℝ → E} (h : ∀ᵐ x, x ∈ Ioc (min a b) (max a b) → ∥f x∥ ≤ C) : ∥∫ x in a..b, f x∥ ≤ C * abs (b - a) := begin rw [norm_integral_eq_norm_integral_Ioc], convert norm_set_integral_le_of_norm_le_const_ae'' _ is_measurable_Ioc h, { rw [real.volume_Ioc, max_sub_min_eq_abs, ennreal.to_real_of_real (abs_nonneg _)] }, { simp only [real.volume_Ioc, ennreal.of_real_lt_top] }, end lemma norm_integral_le_of_norm_le_const {a b C : ℝ} {f : ℝ → E} (h : ∀ x ∈ Ioc (min a b) (max a b), ∥f x∥ ≤ C) : ∥∫ x in a..b, f x∥ ≤ C * abs (b - a) := norm_integral_le_of_norm_le_const_ae $ eventually_of_forall h lemma integral_add (hf : interval_integrable f μ a b) (hg : interval_integrable g μ a b) : ∫ x in a..b, f x + g x ∂μ = ∫ x in a..b, f x ∂μ + ∫ x in a..b, g x ∂μ := by { simp only [interval_integral, integral_add hf.1 hg.1, integral_add hf.2 hg.2], abel } @[simp] lemma integral_neg : ∫ x in a..b, -f x ∂μ = -∫ x in a..b, f x ∂μ := by { simp only [interval_integral, integral_neg], abel } lemma integral_sub (hf : interval_integrable f μ a b) (hg : interval_integrable g μ a b) : ∫ x in a..b, f x - g x ∂μ = ∫ x in a..b, f x ∂μ - ∫ x in a..b, g x ∂μ := by simpa only [sub_eq_add_neg] using (integral_add hf hg.neg).trans (congr_arg _ integral_neg) lemma integral_smul (r : ℝ) : ∫ x in a..b, r • f x ∂μ = r • ∫ x in a..b, f x ∂μ := by simp only [interval_integral, integral_smul, smul_sub] lemma integral_const' (c : E) : ∫ x in a..b, c ∂μ = ((μ $ Ioc a b).to_real - (μ $ Ioc b a).to_real) • c := by simp only [interval_integral, set_integral_const, sub_smul] lemma integral_const {a b : ℝ} (c : E) : (∫ (x : ℝ) in a..b, c) = (b - a) • c := by simp only [integral_const', real.volume_Ioc, ennreal.to_real_of_real', ← neg_sub b, max_zero_sub_eq_self] lemma integral_smul_measure (c : ennreal) : ∫ x in a..b, f x ∂(c • μ) = c.to_real • ∫ x in a..b, f x ∂μ := by simp only [interval_integral, measure.restrict_smul, integral_smul_measure, smul_sub] lemma integral_comp_add_right (a b c : ℝ) (f : ℝ → E) (hfm : ae_measurable f) : ∫ x in a..b, f (x + c) = ∫ x in a+c..b+c, f x := have A : ae_measurable f (measure.map (λ x, x + c) volume), by rwa [real.map_volume_add_right], calc ∫ x in a..b, f (x + c) = ∫ x in a+c..b+c, f x ∂(measure.map (λ x, x + c) volume) : by simp only [interval_integral, set_integral_map is_measurable_Ioc A (measurable_add_right _), preimage_add_const_Ioc, add_sub_cancel] ... = ∫ x in a+c..b+c, f x : by rw [real.map_volume_add_right] lemma integral_comp_mul_right {c : ℝ} (hc : 0 < c) (a b : ℝ) (f : ℝ → E) (hfm : ae_measurable f) : ∫ x in a..b, f (x * c) = c⁻¹ • ∫ x in a*c..b*c, f x := begin have A : ae_measurable f (measure.map (λ (x : ℝ), x*c) volume), by { rw real.map_volume_mul_right (ne_of_gt hc), exact hfm.smul_measure _ }, conv_rhs { rw [← real.smul_map_volume_mul_right (ne_of_gt hc)] }, rw [integral_smul_measure], simp only [interval_integral, set_integral_map is_measurable_Ioc A (measurable_mul_right _), hc, preimage_mul_const_Ioc, mul_div_cancel _ (ne_of_gt hc), abs_of_pos, ennreal.to_real_of_real (le_of_lt hc), inv_smul_smul' (ne_of_gt hc)], end lemma integral_comp_neg (a b : ℝ) (f : ℝ → E) (hfm : ae_measurable f) : ∫ x in a..b, f (-x) = ∫ x in -b..-a, f x := begin have A : ae_measurable f (measure.map (λ (x : ℝ), -x) volume), by rwa real.map_volume_neg, conv_rhs { rw ← real.map_volume_neg }, simp only [interval_integral, set_integral_map is_measurable_Ioc A measurable_neg, neg_preimage, preimage_neg_Ioc, neg_neg, restrict_congr_set Ico_ae_eq_Ioc] end /-! ### Integral is an additive function of the interval In this section we prove that `∫ x in a..b, f x ∂μ + ∫ x in b..c, f x ∂μ = ∫ x in a..c, f x ∂μ` as well as a few other identities trivially equivalent to this one. We also prove that `∫ x in a..b, f x ∂μ = ∫ x, f x ∂μ` provided that `support f ⊆ Ioc a b`. -/ variables [topological_space α] [opens_measurable_space α] section order_closed_topology variables [order_closed_topology α] lemma integral_add_adjacent_intervals_cancel (hab : interval_integrable f μ a b) (hbc : interval_integrable f μ b c) : ∫ x in a..b, f x ∂μ + ∫ x in b..c, f x ∂μ + ∫ x in c..a, f x ∂μ = 0 := begin have hac := hab.trans hbc, simp only [interval_integral, ← add_sub_comm, sub_eq_zero], iterate 4 { rw ← integral_union }, { suffices : Ioc a b ∪ Ioc b c ∪ Ioc c a = Ioc b a ∪ Ioc c b ∪ Ioc a c, by rw this, rw [Ioc_union_Ioc_union_Ioc_cycle, union_right_comm, Ioc_union_Ioc_union_Ioc_cycle, min_left_comm, max_left_comm] }, all_goals { simp [*, is_measurable.union, is_measurable_Ioc, Ioc_disjoint_Ioc_same, Ioc_disjoint_Ioc_same.symm, hab.1, hab.2, hbc.1, hbc.2, hac.1, hac.2] } end lemma integral_add_adjacent_intervals (hab : interval_integrable f μ a b) (hbc : interval_integrable f μ b c) : ∫ x in a..b, f x ∂μ + ∫ x in b..c, f x ∂μ = ∫ x in a..c, f x ∂μ := by rw [← add_neg_eq_zero, ← integral_symm, integral_add_adjacent_intervals_cancel hab hbc] lemma integral_interval_sub_left (hab : interval_integrable f μ a b) (hac : interval_integrable f μ a c) : ∫ x in a..b, f x ∂μ - ∫ x in a..c, f x ∂μ = ∫ x in c..b, f x ∂μ := sub_eq_of_eq_add' $ eq.symm $ integral_add_adjacent_intervals hac (hac.symm.trans hab) lemma integral_interval_add_interval_comm (hab : interval_integrable f μ a b) (hcd : interval_integrable f μ c d) (hac : interval_integrable f μ a c) : ∫ x in a..b, f x ∂μ + ∫ x in c..d, f x ∂μ = ∫ x in a..d, f x ∂μ + ∫ x in c..b, f x ∂μ := by rw [← integral_add_adjacent_intervals hac hcd, add_assoc, add_left_comm, integral_add_adjacent_intervals hac (hac.symm.trans hab), add_comm] lemma integral_interval_sub_interval_comm (hab : interval_integrable f μ a b) (hcd : interval_integrable f μ c d) (hac : interval_integrable f μ a c) : ∫ x in a..b, f x ∂μ - ∫ x in c..d, f x ∂μ = ∫ x in a..c, f x ∂μ - ∫ x in b..d, f x ∂μ := by simp only [sub_eq_add_neg, ← integral_symm, integral_interval_add_interval_comm hab hcd.symm (hac.trans hcd)] lemma integral_interval_sub_interval_comm' (hab : interval_integrable f μ a b) (hcd : interval_integrable f μ c d) (hac : interval_integrable f μ a c) : ∫ x in a..b, f x ∂μ - ∫ x in c..d, f x ∂μ = ∫ x in d..b, f x ∂μ - ∫ x in c..a, f x ∂μ := by { rw [integral_interval_sub_interval_comm hab hcd hac, integral_symm b d, integral_symm a c, sub_neg_eq_add, sub_eq_neg_add], } lemma integral_Iic_sub_Iic (ha : integrable_on f (Iic a) μ) (hb : integrable_on f (Iic b) μ) : ∫ x in Iic b, f x ∂μ - ∫ x in Iic a, f x ∂μ = ∫ x in a..b, f x ∂μ := begin wlog hab : a ≤ b using [a b] tactic.skip, { rw [sub_eq_iff_eq_add', integral_of_le hab, ← integral_union (Iic_disjoint_Ioc (le_refl _)), Iic_union_Ioc_eq_Iic hab], exacts [is_measurable_Iic, is_measurable_Ioc, ha, hb.mono_set (λ _, and.right)] }, { intros ha hb, rw [integral_symm, ← this hb ha, neg_sub] } end /-- If `μ` is a finite measure then `∫ x in a..b, c ∂μ = (μ (Iic b) - μ (Iic a)) • c`. -/ lemma integral_const_of_cdf [finite_measure μ] (c : E) : ∫ x in a..b, c ∂μ = ((μ (Iic b)).to_real - (μ (Iic a)).to_real) • c := begin simp only [sub_smul, ← set_integral_const], refine (integral_Iic_sub_Iic _ _).symm; simp only [integrable_on_const, measure_lt_top, or_true] end lemma integral_eq_integral_of_support_subset {f : α → E} {a b} (h : function.support f ⊆ Ioc a b) : ∫ x in a..b, f x ∂μ = ∫ x, f x ∂μ := begin cases le_total a b with hab hab, { rw [integral_of_le hab, ← integral_indicator is_measurable_Ioc, indicator_eq_self.2 h]; apply_instance }, { rw [Ioc_eq_empty hab, subset_empty_iff, function.support_eq_empty_iff] at h, simp [h] } end end order_closed_topology end lemma integral_eq_zero_iff_of_le_of_nonneg_ae {f : ℝ → ℝ} {a b : ℝ} (hab : a ≤ b) (hf : 0 ≤ᵐ[volume.restrict (Ioc a b)] f) (hfi : interval_integrable f volume a b) : ∫ x in a..b, f x = 0 ↔ f =ᵐ[volume.restrict (Ioc a b)] 0 := by rw [integral_of_le hab, integral_eq_zero_iff_of_nonneg_ae hf hfi.1] lemma integral_eq_zero_iff_of_nonneg_ae {f : ℝ → ℝ} {a b : ℝ} (hf : 0 ≤ᵐ[volume.restrict (Ioc a b ∪ Ioc b a)] f) (hfi : interval_integrable f volume a b) : ∫ x in a..b, f x = 0 ↔ f =ᵐ[volume.restrict (Ioc a b ∪ Ioc b a)] 0 := begin cases le_total a b with hab hab; simp only [Ioc_eq_empty hab, empty_union, union_empty] at *, { exact integral_eq_zero_iff_of_le_of_nonneg_ae hab hf hfi }, { rw [integral_symm, neg_eq_zero], exact integral_eq_zero_iff_of_le_of_nonneg_ae hab hf hfi.symm } end lemma integral_pos_iff_support_of_nonneg_ae' {f : ℝ → ℝ} {a b : ℝ} (hf : 0 ≤ᵐ[volume.restrict (Ioc a b ∪ Ioc b a)] f) (hfi : interval_integrable f volume a b) : 0 < ∫ x in a..b, f x ↔ a < b ∧ 0 < volume (function.support f ∩ Ioc a b) := begin cases le_total a b with hab hab, { simp only [integral_of_le hab, Ioc_eq_empty hab, union_empty] at hf ⊢, symmetry, rw [set_integral_pos_iff_support_of_nonneg_ae hf hfi.1, and_iff_right_iff_imp], contrapose!, intro h, simp [Ioc_eq_empty h] }, { rw [Ioc_eq_empty hab, empty_union] at hf, simp [integral_of_ge hab, Ioc_eq_empty hab, integral_nonneg_of_ae hf] } end lemma integral_pos_iff_support_of_nonneg_ae {f : ℝ → ℝ} {a b : ℝ} (hf : 0 ≤ᵐ[volume] f) (hfi : interval_integrable f volume a b) : 0 < ∫ x in a..b, f x ↔ a < b ∧ 0 < volume (function.support f ∩ Ioc a b) := integral_pos_iff_support_of_nonneg_ae' (ae_mono measure.restrict_le_self hf) hfi /-! ### Fundamental theorem of calculus, part 1, for any measure In this section we prove a few lemmas that can be seen as versions of FTC-1 for interval integrals w.r.t. any measure. Many theorems are formulated for one or two pairs of filters related by `FTC_filter a l l'`. This typeclass has exactly four “real” instances: `(a, pure a, ⊥)`, `(a, 𝓝[Ici a] a, 𝓝[Ioi a] a)`, `(a, 𝓝[Iic a] a, 𝓝[Iic a] a)`, `(a, 𝓝 a, 𝓝 a)`, and two instances that are equal to the first and last “real” instances: `(a, 𝓝[{a}] a, ⊥)` and `(a, 𝓝[univ] a, 𝓝[univ] a)`. We use this approach to avoid repeating arguments in many very similar cases. Lean can automatically find both `a` and `l'` based on `l`. The most general theorem `measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae` can be seen as a generalization of lemma `integral_has_strict_fderiv_at` below which states strict differentiability of `∫ x in u..v, f x` in `(u, v)` at `(a, b)` for a measurable function `f` that is integrable on `a..b` and is continuous at `a` and `b`. The lemma is generalized in three directions: first, `measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae` deals with any locally finite measure `μ`; second, it works for one-sided limits/derivatives; third, it assumes only that `f` has finite limits almost surely at `a` and `b`. Namely, let `f` be a measurable function integrable on `a..b`. Let `(la, la')` be a pair of `FTC_filter`s around `a`; let `(lb, lb')` be a pair of `FTC_filter`s around `b`. Suppose that `f` has finite limits `ca` and `cb` at `la' ⊓ μ.ae` and `lb' ⊓ μ.ae`, respectively. Then `∫ x in va..vb, f x ∂μ - ∫ x in ua..ub, f x ∂μ = ∫ x in ub..vb, cb ∂μ - ∫ x in ua..va, ca ∂μ + o(∥∫ x in ua..va, (1:ℝ) ∂μ∥ + ∥∫ x in ub..vb, (1:ℝ) ∂μ∥)` as `ua` and `va` tend to `la` while `ub` and `vb` tend to `lb`. This theorem is formulated with integral of constants instead of measures in the right hand sides for two reasons: first, this way we avoid `min`/`max` in the statements; second, often it is possible to write better `simp` lemmas for these integrals, see `integral_const` and `integral_const_of_cdf`. In the next subsection we apply this theorem to prove various theorems about differentiability of the integral w.r.t. Lebesgue measure. -/ /-- An auxiliary typeclass for the Fundamental theorem of calculus, part 1. It is used to formulate theorems that work simultaneously for left and right one-sided derivatives of `∫ x in u..v, f x`. There are four instances: `(a, pure a, ⊥)`, `(a, 𝓝[Ici a], 𝓝[Ioi a])`, `(a, 𝓝[Iic a], 𝓝[Iic a])`, and `(a, 𝓝 a, 𝓝 a)`. -/ class FTC_filter {β : Type*} [linear_order β] [measurable_space β] [topological_space β] (a : out_param β) (outer : filter β) (inner : out_param $ filter β) extends tendsto_Ixx_class Ioc outer inner : Prop := (pure_le : pure a ≤ outer) (le_nhds : inner ≤ 𝓝 a) [meas_gen : is_measurably_generated inner] /- The `dangerous_instance` linter doesn't take `out_param`s into account, so it thinks that `FTC_filter.to_tendsto_Ixx_class` is dangerous. Disable this linter using `nolint`. -/ attribute [nolint dangerous_instance] FTC_filter.to_tendsto_Ixx_class namespace FTC_filter variables [linear_order β] [measurable_space β] [topological_space β] instance pure (a : β) : FTC_filter a (pure a) ⊥ := { pure_le := le_refl _, le_nhds := bot_le } instance nhds_within_singleton (a : β) : FTC_filter a (𝓝[{a}] a) ⊥ := by { rw [nhds_within, principal_singleton, inf_eq_right.2 (pure_le_nhds a)], apply_instance } lemma finite_at_inner {a : β} (l : filter β) {l'} [h : FTC_filter a l l'] {μ : measure β} [locally_finite_measure μ] : μ.finite_at_filter l' := (μ.finite_at_nhds a).filter_mono h.le_nhds variables [opens_measurable_space β] [order_topology β] instance nhds (a : β) : FTC_filter a (𝓝 a) (𝓝 a) := { pure_le := pure_le_nhds a, le_nhds := le_refl _ } instance nhds_univ (a : β) : FTC_filter a (𝓝[univ] a) (𝓝 a) := by { rw nhds_within_univ, apply_instance } instance nhds_left (a : β) : FTC_filter a (𝓝[Iic a] a) (𝓝[Iic a] a) := { pure_le := pure_le_nhds_within right_mem_Iic, le_nhds := inf_le_left } instance nhds_right (a : β) : FTC_filter a (𝓝[Ici a] a) (𝓝[Ioi a] a) := { pure_le := pure_le_nhds_within left_mem_Ici, le_nhds := inf_le_left } end FTC_filter open asymptotics section variables {f : α → E} {a b : α} {c ca cb : E} {l l' la la' lb lb' : filter α} {lt : filter β} {μ : measure α} {u v ua va ub vb : β → α} /-- Fundamental theorem of calculus-1, local version for any measure. Let filters `l` and `l'` be related by `tendsto_Ixx_class Ioc`. If `f` has a finite limit `c` at `l' ⊓ μ.ae`, where `μ` is a measure finite at `l'`, then `∫ x in u..v, f x ∂μ = ∫ x in u..v, c ∂μ + o(∫ x in u..v, 1 ∂μ)` as both `u` and `v` tend to `l`. See also `measure_integral_sub_linear_is_o_of_tendsto_ae` for a version assuming `[FTC_filter a l l']` and `[locally_finite_measure μ]`. If `l` is one of `𝓝[Ici a] a`, `𝓝[Iic a] a`, `𝓝 a`, then it's easier to apply the non-primed version. The primed version also works, e.g., for `l = l' = at_top`. We use integrals of constants instead of measures because this way it is easier to formulate a statement that works in both cases `u ≤ v` and `v ≤ u`. -/ lemma measure_integral_sub_linear_is_o_of_tendsto_ae' [is_measurably_generated l'] [tendsto_Ixx_class Ioc l l'] (hfm : measurable_at_filter f l' μ) (hf : tendsto f (l' ⊓ μ.ae) (𝓝 c)) (hl : μ.finite_at_filter l') (hu : tendsto u lt l) (hv : tendsto v lt l) : is_o (λ t, ∫ x in u t..v t, f x ∂μ - ∫ x in u t..v t, c ∂μ) (λ t, ∫ x in u t..v t, (1:ℝ) ∂μ) lt := begin have A := hf.integral_sub_linear_is_o_ae hfm hl (hu.Ioc hv), have B := hf.integral_sub_linear_is_o_ae hfm hl (hv.Ioc hu), simp only [integral_const'], convert (A.trans_le _).sub (B.trans_le _), { ext t, simp_rw [(∘), interval_integral, sub_smul], abel }, all_goals { intro t, cases le_total (u t) (v t) with huv huv; simp [huv] } end /-- Fundamental theorem of calculus-1, local version for any measure. Let filters `l` and `l'` be related by `tendsto_Ixx_class Ioc`. If `f` has a finite limit `c` at `l ⊓ μ.ae`, where `μ` is a measure finite at `l`, then `∫ x in u..v, f x ∂μ = μ (Ioc u v) • c + o(μ(Ioc u v))` as both `u` and `v` tend to `l` so that `u ≤ v`. See also `measure_integral_sub_linear_is_o_of_tendsto_ae_of_le` for a version assuming `[FTC_filter a l l']` and `[locally_finite_measure μ]`. If `l` is one of `𝓝[Ici a] a`, `𝓝[Iic a] a`, `𝓝 a`, then it's easier to apply the non-primed version. The primed version also works, e.g., for `l = l' = at_top`. -/ lemma measure_integral_sub_linear_is_o_of_tendsto_ae_of_le' [is_measurably_generated l'] [tendsto_Ixx_class Ioc l l'] (hfm : measurable_at_filter f l' μ) (hf : tendsto f (l' ⊓ μ.ae) (𝓝 c)) (hl : μ.finite_at_filter l') (hu : tendsto u lt l) (hv : tendsto v lt l) (huv : u ≤ᶠ[lt] v) : is_o (λ t, ∫ x in u t..v t, f x ∂μ - (μ (Ioc (u t) (v t))).to_real • c) (λ t, (μ $ Ioc (u t) (v t)).to_real) lt := (measure_integral_sub_linear_is_o_of_tendsto_ae' hfm hf hl hu hv).congr' (huv.mono $ λ x hx, by simp [integral_const', hx]) (huv.mono $ λ x hx, by simp [integral_const', hx]) /-- Fundamental theorem of calculus-1, local version for any measure. Let filters `l` and `l'` be related by `tendsto_Ixx_class Ioc`. If `f` has a finite limit `c` at `l ⊓ μ.ae`, where `μ` is a measure finite at `l`, then `∫ x in u..v, f x ∂μ = -μ (Ioc v u) • c + o(μ(Ioc v u))` as both `u` and `v` tend to `l` so that `v ≤ u`. See also `measure_integral_sub_linear_is_o_of_tendsto_ae_of_ge` for a version assuming `[FTC_filter a l l']` and `[locally_finite_measure μ]`. If `l` is one of `𝓝[Ici a] a`, `𝓝[Iic a] a`, `𝓝 a`, then it's easier to apply the non-primed version. The primed version also works, e.g., for `l = l' = at_top`. -/ lemma measure_integral_sub_linear_is_o_of_tendsto_ae_of_ge' [is_measurably_generated l'] [tendsto_Ixx_class Ioc l l'] (hfm : measurable_at_filter f l' μ) (hf : tendsto f (l' ⊓ μ.ae) (𝓝 c)) (hl : μ.finite_at_filter l') (hu : tendsto u lt l) (hv : tendsto v lt l) (huv : v ≤ᶠ[lt] u) : is_o (λ t, ∫ x in u t..v t, f x ∂μ + (μ (Ioc (v t) (u t))).to_real • c) (λ t, (μ $ Ioc (v t) (u t)).to_real) lt := (measure_integral_sub_linear_is_o_of_tendsto_ae_of_le' hfm hf hl hv hu huv).neg_left.congr_left $ λ t, by simp [integral_symm (u t), add_comm] variables [topological_space α] section variables [locally_finite_measure μ] [FTC_filter a l l'] include a local attribute [instance] FTC_filter.meas_gen /-- Fundamental theorem of calculus-1, local version for any measure. Let filters `l` and `l'` be related by `[FTC_filter a l l']`; let `μ` be a locally finite measure. If `f` has a finite limit `c` at `l' ⊓ μ.ae`, then `∫ x in u..v, f x ∂μ = ∫ x in u..v, c ∂μ + o(∫ x in u..v, 1 ∂μ)` as both `u` and `v` tend to `l`. See also `measure_integral_sub_linear_is_o_of_tendsto_ae'` for a version that also works, e.g., for `l = l' = at_top`. We use integrals of constants instead of measures because this way it is easier to formulate a statement that works in both cases `u ≤ v` and `v ≤ u`. -/ lemma measure_integral_sub_linear_is_o_of_tendsto_ae (hfm : measurable_at_filter f l' μ) (hf : tendsto f (l' ⊓ μ.ae) (𝓝 c)) (hu : tendsto u lt l) (hv : tendsto v lt l) : is_o (λ t, ∫ x in u t..v t, f x ∂μ - ∫ x in u t..v t, c ∂μ) (λ t, ∫ x in u t..v t, (1:ℝ) ∂μ) lt := measure_integral_sub_linear_is_o_of_tendsto_ae' hfm hf (FTC_filter.finite_at_inner l) hu hv /-- Fundamental theorem of calculus-1, local version for any measure. Let filters `l` and `l'` be related by `[FTC_filter a l l']`; let `μ` be a locally finite measure. If `f` has a finite limit `c` at `l' ⊓ μ.ae`, then `∫ x in u..v, f x ∂μ = μ (Ioc u v) • c + o(μ(Ioc u v))` as both `u` and `v` tend to `l`. See also `measure_integral_sub_linear_is_o_of_tendsto_ae_of_le'` for a version that also works, e.g., for `l = l' = at_top`. -/ lemma measure_integral_sub_linear_is_o_of_tendsto_ae_of_le (hfm : measurable_at_filter f l' μ) (hf : tendsto f (l' ⊓ μ.ae) (𝓝 c)) (hu : tendsto u lt l) (hv : tendsto v lt l) (huv : u ≤ᶠ[lt] v) : is_o (λ t, ∫ x in u t..v t, f x ∂μ - (μ (Ioc (u t) (v t))).to_real • c) (λ t, (μ $ Ioc (u t) (v t)).to_real) lt := measure_integral_sub_linear_is_o_of_tendsto_ae_of_le' hfm hf (FTC_filter.finite_at_inner l) hu hv huv /-- Fundamental theorem of calculus-1, local version for any measure. Let filters `l` and `l'` be related by `[FTC_filter a l l']`; let `μ` be a locally finite measure. If `f` has a finite limit `c` at `l' ⊓ μ.ae`, then `∫ x in u..v, f x ∂μ = -μ (Ioc v u) • c + o(μ(Ioc v u))` as both `u` and `v` tend to `l`. See also `measure_integral_sub_linear_is_o_of_tendsto_ae_of_ge'` for a version that also works, e.g., for `l = l' = at_top`. -/ lemma measure_integral_sub_linear_is_o_of_tendsto_ae_of_ge (hfm : measurable_at_filter f l' μ) (hf : tendsto f (l' ⊓ μ.ae) (𝓝 c)) (hu : tendsto u lt l) (hv : tendsto v lt l) (huv : v ≤ᶠ[lt] u) : is_o (λ t, ∫ x in u t..v t, f x ∂μ + (μ (Ioc (v t) (u t))).to_real • c) (λ t, (μ $ Ioc (v t) (u t)).to_real) lt := measure_integral_sub_linear_is_o_of_tendsto_ae_of_ge' hfm hf (FTC_filter.finite_at_inner l) hu hv huv end variables [order_topology α] [borel_space α] local attribute [instance] FTC_filter.meas_gen variables [FTC_filter a la la'] [FTC_filter b lb lb'] [locally_finite_measure μ] /-- Fundamental theorem of calculus-1, strict derivative in both limits for a locally finite measure. Let `f` be a measurable function integrable on `a..b`. Let `(la, la')` be a pair of `FTC_filter`s around `a`; let `(lb, lb')` be a pair of `FTC_filter`s around `b`. Suppose that `f` has finite limits `ca` and `cb` at `la' ⊓ μ.ae` and `lb' ⊓ μ.ae`, respectively. Then `∫ x in va..vb, f x ∂μ - ∫ x in ua..ub, f x ∂μ = ∫ x in ub..vb, cb ∂μ - ∫ x in ua..va, ca ∂μ + o(∥∫ x in ua..va, (1:ℝ) ∂μ∥ + ∥∫ x in ub..vb, (1:ℝ) ∂μ∥)` as `ua` and `va` tend to `la` while `ub` and `vb` tend to `lb`. -/ lemma measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae (hab : interval_integrable f μ a b) (hmeas_a : measurable_at_filter f la' μ) (hmeas_b : measurable_at_filter f lb' μ) (ha_lim : tendsto f (la' ⊓ μ.ae) (𝓝 ca)) (hb_lim : tendsto f (lb' ⊓ μ.ae) (𝓝 cb)) (hua : tendsto ua lt la) (hva : tendsto va lt la) (hub : tendsto ub lt lb) (hvb : tendsto vb lt lb) : is_o (λ t, (∫ x in va t..vb t, f x ∂μ) - (∫ x in ua t..ub t, f x ∂μ) - (∫ x in ub t..vb t, cb ∂μ - ∫ x in ua t..va t, ca ∂μ)) (λ t, ∥∫ x in ua t..va t, (1:ℝ) ∂μ∥ + ∥∫ x in ub t..vb t, (1:ℝ) ∂μ∥) lt := begin refine ((measure_integral_sub_linear_is_o_of_tendsto_ae hmeas_a ha_lim hua hva).neg_left.add_add (measure_integral_sub_linear_is_o_of_tendsto_ae hmeas_b hb_lim hub hvb)).congr' _ (eventually_eq.refl _ _), have A : ∀ᶠ t in lt, interval_integrable f μ (ua t) (va t) := ha_lim.eventually_interval_integrable_ae hmeas_a (FTC_filter.finite_at_inner la) hua hva, have A' : ∀ᶠ t in lt, interval_integrable f μ a (ua t) := ha_lim.eventually_interval_integrable_ae hmeas_a (FTC_filter.finite_at_inner la) (tendsto_const_pure.mono_right FTC_filter.pure_le) hua, have B : ∀ᶠ t in lt, interval_integrable f μ (ub t) (vb t) := hb_lim.eventually_interval_integrable_ae hmeas_b (FTC_filter.finite_at_inner lb) hub hvb, have B' : ∀ᶠ t in lt, interval_integrable f μ b (ub t) := hb_lim.eventually_interval_integrable_ae hmeas_b (FTC_filter.finite_at_inner lb) (tendsto_const_pure.mono_right FTC_filter.pure_le) hub, filter_upwards [A, A', B, B'], intros t ua_va a_ua ub_vb b_ub, rw [← integral_interval_sub_interval_comm'], { dsimp only [], abel }, exacts [ub_vb, ua_va, b_ub.symm.trans $ hab.symm.trans a_ua] end /-- Fundamental theorem of calculus-1, strict derivative in right endpoint for a locally finite measure. Let `f` be a measurable function integrable on `a..b`. Let `(lb, lb')` be a pair of `FTC_filter`s around `b`. Suppose that `f` has a finite limit `c` at `lb' ⊓ μ.ae`. Then `∫ x in a..v, f x ∂μ - ∫ x in a..u, f x ∂μ = ∫ x in u..v, c ∂μ + o(∫ x in u..v, (1:ℝ) ∂μ)` as `u` and `v` tend to `lb`. -/ lemma measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae_right (hab : interval_integrable f μ a b) (hmeas : measurable_at_filter f lb' μ) (hf : tendsto f (lb' ⊓ μ.ae) (𝓝 c)) (hu : tendsto u lt lb) (hv : tendsto v lt lb) : is_o (λ t, ∫ x in a..v t, f x ∂μ - ∫ x in a..u t, f x ∂μ - ∫ x in u t..v t, c ∂μ) (λ t, ∫ x in u t..v t, (1:ℝ) ∂μ) lt := by simpa using measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae hab measurable_at_bot hmeas ((tendsto_bot : tendsto _ ⊥ (𝓝 0)).mono_left inf_le_left) hf (tendsto_const_pure : tendsto _ _ (pure a)) tendsto_const_pure hu hv /-- Fundamental theorem of calculus-1, strict derivative in left endpoint for a locally finite measure. Let `f` be a measurable function integrable on `a..b`. Let `(la, la')` be a pair of `FTC_filter`s around `a`. Suppose that `f` has a finite limit `c` at `la' ⊓ μ.ae`. Then `∫ x in v..b, f x ∂μ - ∫ x in u..b, f x ∂μ = -∫ x in u..v, c ∂μ + o(∫ x in u..v, (1:ℝ) ∂μ)` as `u` and `v` tend to `la`. -/ lemma measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae_left (hab : interval_integrable f μ a b) (hmeas : measurable_at_filter f la' μ) (hf : tendsto f (la' ⊓ μ.ae) (𝓝 c)) (hu : tendsto u lt la) (hv : tendsto v lt la) : is_o (λ t, ∫ x in v t..b, f x ∂μ - ∫ x in u t..b, f x ∂μ + ∫ x in u t..v t, c ∂μ) (λ t, ∫ x in u t..v t, (1:ℝ) ∂μ) lt := by simpa using measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae hab hmeas measurable_at_bot hf ((tendsto_bot : tendsto _ ⊥ (𝓝 0)).mono_left inf_le_left) hu hv (tendsto_const_pure : tendsto _ _ (pure b)) tendsto_const_pure end /-! ### Fundamental theorem of calculus-1 for Lebesgue measure In this section we restate theorems from the previous section for Lebesgue measure. In particular, we prove that `∫ x in u..v, f x` is strictly differentiable in `(u, v)` at `(a, b)` provided that `f` is integrable on `a..b` and is continuous at `a` and `b`. -/ variables {f : ℝ → E} {c ca cb : E} {l l' la la' lb lb' : filter ℝ} {lt : filter β} {a b z : ℝ} {u v ua ub va vb : β → ℝ} [FTC_filter a la la'] [FTC_filter b lb lb'] /-! #### Auxiliary `is_o` statements In this section we prove several lemmas that can be interpreted as strict differentiability of `(u, v) ↦ ∫ x in u..v, f x ∂μ` in `u` and/or `v` at a filter. The statements use `is_o` because we have no definition of `has_strict_(f)deriv_at_filter` in the library. -/ /-- Fundamental theorem of calculus-1, local version. If `f` has a finite limit `c` almost surely at `l'`, where `(l, l')` is an `FTC_filter` pair around `a`, then `∫ x in u..v, f x ∂μ = (v - u) • c + o (v - u)` as both `u` and `v` tend to `l`. -/ lemma integral_sub_linear_is_o_of_tendsto_ae [FTC_filter a l l'] (hfm : measurable_at_filter f l') (hf : tendsto f (l' ⊓ volume.ae) (𝓝 c)) {u v : β → ℝ} (hu : tendsto u lt l) (hv : tendsto v lt l) : is_o (λ t, (∫ x in u t..v t, f x) - (v t - u t) • c) (v - u) lt := by simpa [integral_const] using measure_integral_sub_linear_is_o_of_tendsto_ae hfm hf hu hv /-- Fundamental theorem of calculus-1, strict differentiability at filter in both endpoints. If `f` is a measurable function integrable on `a..b`, `(la, la')` is an `FTC_filter` pair around `a`, and `(lb, lb')` is an `FTC_filter` pair around `b`, and `f` has finite limits `ca` and `cb` almost surely at `la'` and `lb'`, respectively, then `(∫ x in va..vb, f x) - ∫ x in ua..ub, f x = (vb - ub) • cb - (va - ua) • ca + o(∥va - ua∥ + ∥vb - ub∥)` as `ua` and `va` tend to `la` while `ub` and `vb` tend to `lb`. This lemma could've been formulated using `has_strict_fderiv_at_filter` if we had this definition. -/ lemma integral_sub_integral_sub_linear_is_o_of_tendsto_ae (hab : interval_integrable f volume a b) (hmeas_a : measurable_at_filter f la') (hmeas_b : measurable_at_filter f lb') (ha_lim : tendsto f (la' ⊓ volume.ae) (𝓝 ca)) (hb_lim : tendsto f (lb' ⊓ volume.ae) (𝓝 cb)) (hua : tendsto ua lt la) (hva : tendsto va lt la) (hub : tendsto ub lt lb) (hvb : tendsto vb lt lb) : is_o (λ t, (∫ x in va t..vb t, f x) - (∫ x in ua t..ub t, f x) - ((vb t - ub t) • cb - (va t - ua t) • ca)) (λ t, ∥va t - ua t∥ + ∥vb t - ub t∥) lt := by simpa [integral_const] using measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae hab hmeas_a hmeas_b ha_lim hb_lim hua hva hub hvb /-- Fundamental theorem of calculus-1, strict differentiability at filter in both endpoints. If `f` is a measurable function integrable on `a..b`, `(lb, lb')` is an `FTC_filter` pair around `b`, and `f` has a finite limit `c` almost surely at `lb'`, then `(∫ x in a..v, f x) - ∫ x in a..u, f x = (v - u) • c + o(∥v - u∥)` as `u` and `v` tend to `lb`. This lemma could've been formulated using `has_strict_deriv_at_filter` if we had this definition. -/ lemma integral_sub_integral_sub_linear_is_o_of_tendsto_ae_right (hab : interval_integrable f volume a b) (hmeas : measurable_at_filter f lb') (hf : tendsto f (lb' ⊓ volume.ae) (𝓝 c)) (hu : tendsto u lt lb) (hv : tendsto v lt lb) : is_o (λ t, (∫ x in a..v t, f x) - (∫ x in a..u t, f x) - (v t - u t) • c) (v - u) lt := by simpa only [integral_const, smul_eq_mul, mul_one] using measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae_right hab hmeas hf hu hv /-- Fundamental theorem of calculus-1, strict differentiability at filter in both endpoints. If `f` is a measurable function integrable on `a..b`, `(la, la')` is an `FTC_filter` pair around `a`, and `f` has a finite limit `c` almost surely at `la'`, then `(∫ x in v..b, f x) - ∫ x in u..b, f x = -(v - u) • c + o(∥v - u∥)` as `u` and `v` tend to `la`. This lemma could've been formulated using `has_strict_deriv_at_filter` if we had this definition. -/ lemma integral_sub_integral_sub_linear_is_o_of_tendsto_ae_left (hab : interval_integrable f volume a b) (hmeas : measurable_at_filter f la') (hf : tendsto f (la' ⊓ volume.ae) (𝓝 c)) (hu : tendsto u lt la) (hv : tendsto v lt la) : is_o (λ t, (∫ x in v t..b, f x) - (∫ x in u t..b, f x) + (v t - u t) • c) (v - u) lt := by simpa only [integral_const, smul_eq_mul, mul_one] using measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae_left hab hmeas hf hu hv open continuous_linear_map (fst snd smul_right sub_apply smul_right_apply coe_fst' coe_snd' map_sub) /-! #### Strict differentiability In this section we prove that for a measurable function `f` integrable on `a..b`, * `integral_has_strict_fderiv_at_of_tendsto_ae`: the function `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` at `(a, b)` in the sense of strict differentiability provided that `f` tends to `ca` and `cb` almost surely as `x` tendsto to `a` and `b`, respectively; * `integral_has_strict_fderiv_at`: the function `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • f b - u • f a` at `(a, b)` in the sense of strict differentiability provided that `f` is continuous at `a` and `b`; * `integral_has_strict_deriv_at_of_tendsto_ae_right`: the function `u ↦ ∫ x in a..u, f x` has derivative `c` at `b` in the sense of strict differentiability provided that `f` tends to `c` almost surely as `x` tends to `b`; * `integral_has_strict_deriv_at_right`: the function `u ↦ ∫ x in a..u, f x` has derivative `f b` at `b` in the sense of strict differentiability provided that `f` is continuous at `b`; * `integral_has_strict_deriv_at_of_tendsto_ae_left`: the function `u ↦ ∫ x in u..b, f x` has derivative `-c` at `a` in the sense of strict differentiability provided that `f` tends to `c` almost surely as `x` tends to `a`; * `integral_has_strict_deriv_at_left`: the function `u ↦ ∫ x in u..b, f x` has derivative `-f a` at `a` in the sense of strict differentiability provided that `f` is continuous at `a`. -/ /-- Fundamental theorem of calculus-1: if `f : ℝ → E` is integrable on `a..b` and `f x` has finite limits `ca` and `cb` almost surely as `x` tends to `a` and `b`, respectively, then `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` at `(a, b)` in the sense of strict differentiability. -/ lemma integral_has_strict_fderiv_at_of_tendsto_ae (hf : interval_integrable f volume a b) (hmeas_a : measurable_at_filter f (𝓝 a)) (hmeas_b : measurable_at_filter f (𝓝 b)) (ha : tendsto f (𝓝 a ⊓ volume.ae) (𝓝 ca)) (hb : tendsto f (𝓝 b ⊓ volume.ae) (𝓝 cb)) : has_strict_fderiv_at (λ p : ℝ × ℝ, ∫ x in p.1..p.2, f x) ((snd ℝ ℝ ℝ).smul_right cb - (fst ℝ ℝ ℝ).smul_right ca) (a, b) := begin have := integral_sub_integral_sub_linear_is_o_of_tendsto_ae hf hmeas_a hmeas_b ha hb ((continuous_fst.comp continuous_snd).tendsto ((a, b), (a, b))) ((continuous_fst.comp continuous_fst).tendsto ((a, b), (a, b))) ((continuous_snd.comp continuous_snd).tendsto ((a, b), (a, b))) ((continuous_snd.comp continuous_fst).tendsto ((a, b), (a, b))), refine (this.congr_left _).trans_is_O _, { intro x, simp [sub_smul] }, { exact is_O_fst_prod.norm_left.add is_O_snd_prod.norm_left } end /-- Fundamental theorem of calculus-1: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `a` and `b`, then `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` at `(a, b)` in the sense of strict differentiability. -/ lemma integral_has_strict_fderiv_at (hf : interval_integrable f volume a b) (hmeas_a : measurable_at_filter f (𝓝 a)) (hmeas_b : measurable_at_filter f (𝓝 b)) (ha : continuous_at f a) (hb : continuous_at f b) : has_strict_fderiv_at (λ p : ℝ × ℝ, ∫ x in p.1..p.2, f x) ((snd ℝ ℝ ℝ).smul_right (f b) - (fst ℝ ℝ ℝ).smul_right (f a)) (a, b) := integral_has_strict_fderiv_at_of_tendsto_ae hf hmeas_a hmeas_b (ha.mono_left inf_le_left) (hb.mono_left inf_le_left) /-- Fundamental theorem of calculus-1: if `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely at `b`, then `u ↦ ∫ x in a..u, f x` has derivative `c` at `b` in the sense of strict differentiability. -/ lemma integral_has_strict_deriv_at_of_tendsto_ae_right (hf : interval_integrable f volume a b) (hmeas : measurable_at_filter f (𝓝 b)) (hb : tendsto f (𝓝 b ⊓ volume.ae) (𝓝 c)) : has_strict_deriv_at (λ u, ∫ x in a..u, f x) c b := integral_sub_integral_sub_linear_is_o_of_tendsto_ae_right hf hmeas hb continuous_at_snd continuous_at_fst /-- Fundamental theorem of calculus-1: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `b`, then `u ↦ ∫ x in a..u, f x` has derivative `f b` at `b` in the sense of strict differentiability. -/ lemma integral_has_strict_deriv_at_right (hf : interval_integrable f volume a b) (hmeas : measurable_at_filter f (𝓝 b)) (hb : continuous_at f b) : has_strict_deriv_at (λ u, ∫ x in a..u, f x) (f b) b := integral_has_strict_deriv_at_of_tendsto_ae_right hf hmeas (hb.mono_left inf_le_left) /-- Fundamental theorem of calculus-1: if `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely at `a`, then `u ↦ ∫ x in u..b, f x` has derivative `-c` at `a` in the sense of strict differentiability. -/ lemma integral_has_strict_deriv_at_of_tendsto_ae_left (hf : interval_integrable f volume a b) (hmeas : measurable_at_filter f (𝓝 a)) (ha : tendsto f (𝓝 a ⊓ volume.ae) (𝓝 c)) : has_strict_deriv_at (λ u, ∫ x in u..b, f x) (-c) a := by simpa only [← integral_symm] using (integral_has_strict_deriv_at_of_tendsto_ae_right hf.symm hmeas ha).neg /-- Fundamental theorem of calculus-1: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `a`, then `u ↦ ∫ x in u..b, f x` has derivative `-f a` at `a` in the sense of strict differentiability. -/ lemma integral_has_strict_deriv_at_left (hf : interval_integrable f volume a b) (hmeas : measurable_at_filter f (𝓝 a)) (ha : continuous_at f a) : has_strict_deriv_at (λ u, ∫ x in u..b, f x) (-f a) a := by simpa only [← integral_symm] using (integral_has_strict_deriv_at_right hf.symm hmeas ha).neg /-! #### Fréchet differentiability In this subsection we restate results from the previous subsection in terms of `has_fderiv_at`, `has_deriv_at`, `fderiv`, and `deriv`. -/ /-- Fundamental theorem of calculus-1: if `f : ℝ → E` is integrable on `a..b` and `f x` has finite limits `ca` and `cb` almost surely as `x` tends to `a` and `b`, respectively, then `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` at `(a, b)`. -/ lemma integral_has_fderiv_at_of_tendsto_ae (hf : interval_integrable f volume a b) (hmeas_a : measurable_at_filter f (𝓝 a)) (hmeas_b : measurable_at_filter f (𝓝 b)) (ha : tendsto f (𝓝 a ⊓ volume.ae) (𝓝 ca)) (hb : tendsto f (𝓝 b ⊓ volume.ae) (𝓝 cb)) : has_fderiv_at (λ p : ℝ × ℝ, ∫ x in p.1..p.2, f x) ((snd ℝ ℝ ℝ).smul_right cb - (fst ℝ ℝ ℝ).smul_right ca) (a, b) := (integral_has_strict_fderiv_at_of_tendsto_ae hf hmeas_a hmeas_b ha hb).has_fderiv_at /-- Fundamental theorem of calculus-1: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `a` and `b`, then `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` at `(a, b)`. -/ lemma integral_has_fderiv_at (hf : interval_integrable f volume a b) (hmeas_a : measurable_at_filter f (𝓝 a)) (hmeas_b : measurable_at_filter f (𝓝 b)) (ha : continuous_at f a) (hb : continuous_at f b) : has_fderiv_at (λ p : ℝ × ℝ, ∫ x in p.1..p.2, f x) ((snd ℝ ℝ ℝ).smul_right (f b) - (fst ℝ ℝ ℝ).smul_right (f a)) (a, b) := (integral_has_strict_fderiv_at hf hmeas_a hmeas_b ha hb).has_fderiv_at /-- Fundamental theorem of calculus-1: if `f : ℝ → E` is integrable on `a..b` and `f x` has finite limits `ca` and `cb` almost surely as `x` tends to `a` and `b`, respectively, then `fderiv` derivative of `(u, v) ↦ ∫ x in u..v, f x` at `(a, b)` equals `(u, v) ↦ v • cb - u • ca`. -/ lemma fderiv_integral_of_tendsto_ae (hf : interval_integrable f volume a b) (hmeas_a : measurable_at_filter f (𝓝 a)) (hmeas_b : measurable_at_filter f (𝓝 b)) (ha : tendsto f (𝓝 a ⊓ volume.ae) (𝓝 ca)) (hb : tendsto f (𝓝 b ⊓ volume.ae) (𝓝 cb)) : fderiv ℝ (λ p : ℝ × ℝ, ∫ x in p.1..p.2, f x) (a, b) = (snd ℝ ℝ ℝ).smul_right cb - (fst ℝ ℝ ℝ).smul_right ca := (integral_has_fderiv_at_of_tendsto_ae hf hmeas_a hmeas_b ha hb).fderiv /-- Fundamental theorem of calculus-1: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `a` and `b`, then `fderiv` derivative of `(u, v) ↦ ∫ x in u..v, f x` at `(a, b)` equals `(u, v) ↦ v • cb - u • ca`. -/ lemma fderiv_integral (hf : interval_integrable f volume a b) (hmeas_a : measurable_at_filter f (𝓝 a)) (hmeas_b : measurable_at_filter f (𝓝 b)) (ha : continuous_at f a) (hb : continuous_at f b) : fderiv ℝ (λ p : ℝ × ℝ, ∫ x in p.1..p.2, f x) (a, b) = (snd ℝ ℝ ℝ).smul_right (f b) - (fst ℝ ℝ ℝ).smul_right (f a) := (integral_has_fderiv_at hf hmeas_a hmeas_b ha hb).fderiv /-- Fundamental theorem of calculus-1: if `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely at `b`, then `u ↦ ∫ x in a..u, f x` has derivative `c` at `b`. -/ lemma integral_has_deriv_at_of_tendsto_ae_right (hf : interval_integrable f volume a b) (hmeas : measurable_at_filter f (𝓝 b)) (hb : tendsto f (𝓝 b ⊓ volume.ae) (𝓝 c)) : has_deriv_at (λ u, ∫ x in a..u, f x) c b := (integral_has_strict_deriv_at_of_tendsto_ae_right hf hmeas hb).has_deriv_at /-- Fundamental theorem of calculus-1: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `b`, then `u ↦ ∫ x in a..u, f x` has derivative `f b` at `b`. -/ lemma integral_has_deriv_at_right (hf : interval_integrable f volume a b) (hmeas : measurable_at_filter f (𝓝 b)) (hb : continuous_at f b) : has_deriv_at (λ u, ∫ x in a..u, f x) (f b) b := (integral_has_strict_deriv_at_right hf hmeas hb).has_deriv_at /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f` has a finite limit `c` almost surely at `b`, then the derivative of `u ↦ ∫ x in a..u, f x` at `b` equals `c`. -/ lemma deriv_integral_of_tendsto_ae_right (hf : interval_integrable f volume a b) (hmeas : measurable_at_filter f (𝓝 b)) (hb : tendsto f (𝓝 b ⊓ volume.ae) (𝓝 c)) : deriv (λ u, ∫ x in a..u, f x) b = c := (integral_has_deriv_at_of_tendsto_ae_right hf hmeas hb).deriv /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `b`, then the derivative of `u ↦ ∫ x in a..u, f x` at `b` equals `f b`. -/ lemma deriv_integral_right (hf : interval_integrable f volume a b) (hmeas : measurable_at_filter f (𝓝 b)) (hb : continuous_at f b) : deriv (λ u, ∫ x in a..u, f x) b = f b := (integral_has_deriv_at_right hf hmeas hb).deriv /-- Fundamental theorem of calculus-1: if `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely at `a`, then `u ↦ ∫ x in u..b, f x` has derivative `-c` at `a`. -/ lemma integral_has_deriv_at_of_tendsto_ae_left (hf : interval_integrable f volume a b) (hmeas : measurable_at_filter f (𝓝 a)) (ha : tendsto f (𝓝 a ⊓ volume.ae) (𝓝 c)) : has_deriv_at (λ u, ∫ x in u..b, f x) (-c) a := (integral_has_strict_deriv_at_of_tendsto_ae_left hf hmeas ha).has_deriv_at /-- Fundamental theorem of calculus-1: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `a`, then `u ↦ ∫ x in u..b, f x` has derivative `-f a` at `a`. -/ lemma integral_has_deriv_at_left (hf : interval_integrable f volume a b) (hmeas : measurable_at_filter f (𝓝 a)) (ha : continuous_at f a) : has_deriv_at (λ u, ∫ x in u..b, f x) (-f a) a := (integral_has_strict_deriv_at_left hf hmeas ha).has_deriv_at /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f` has a finite limit `c` almost surely at `a`, then the derivative of `u ↦ ∫ x in u..b, f x` at `a` equals `-c`. -/ lemma deriv_integral_of_tendsto_ae_left (hf : interval_integrable f volume a b) (hmeas : measurable_at_filter f (𝓝 a)) (hb : tendsto f (𝓝 a ⊓ volume.ae) (𝓝 c)) : deriv (λ u, ∫ x in u..b, f x) a = -c := (integral_has_deriv_at_of_tendsto_ae_left hf hmeas hb).deriv /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `a`, then the derivative of `u ↦ ∫ x in u..b, f x` at `a` equals `-f a`. -/ lemma deriv_integral_left (hf : interval_integrable f volume a b) (hmeas : measurable_at_filter f (𝓝 a)) (hb : continuous_at f a) : deriv (λ u, ∫ x in u..b, f x) a = -f a := (integral_has_deriv_at_left hf hmeas hb).deriv /-! #### One-sided derivatives -/ /-- Let `f` be a measurable function integrable on `a..b`. The function `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` within `s × t` at `(a, b)`, where `s ∈ {Iic a, {a}, Ici a, univ}` and `t ∈ {Iic b, {b}, Ici b, univ}` provided that `f` tends to `ca` and `cb` almost surely at the filters `la` and `lb` from the following table. | `s` | `la` | `t` | `lb` | | ------- | ---- | --- | ---- | | `Iic a` | `𝓝[Iic a] a` | `Iic b` | `𝓝[Iic b] b` | | `Ici a` | `𝓝[Ioi a] a` | `Ici b` | `𝓝[Ioi b] b` | | `{a}` | `⊥` | `{b}` | `⊥` | | `univ` | `𝓝 a` | `univ` | `𝓝 b` | -/ lemma integral_has_fderiv_within_at_of_tendsto_ae (hf : interval_integrable f volume a b) {s t : set ℝ} [FTC_filter a (𝓝[s] a) la] [FTC_filter b (𝓝[t] b) lb] (hmeas_a : measurable_at_filter f la) (hmeas_b : measurable_at_filter f lb) (ha : tendsto f (la ⊓ volume.ae) (𝓝 ca)) (hb : tendsto f (lb ⊓ volume.ae) (𝓝 cb)) : has_fderiv_within_at (λ p : ℝ × ℝ, ∫ x in p.1..p.2, f x) ((snd ℝ ℝ ℝ).smul_right cb - (fst ℝ ℝ ℝ).smul_right ca) (s.prod t) (a, b) := begin rw [has_fderiv_within_at, nhds_within_prod_eq], have := integral_sub_integral_sub_linear_is_o_of_tendsto_ae hf hmeas_a hmeas_b ha hb (tendsto_const_pure.mono_right FTC_filter.pure_le : tendsto _ _ (𝓝[s] a)) tendsto_fst (tendsto_const_pure.mono_right FTC_filter.pure_le : tendsto _ _ (𝓝[t] b)) tendsto_snd, refine (this.congr_left _).trans_is_O _, { intro x, simp [sub_smul] }, { exact is_O_fst_prod.norm_left.add is_O_snd_prod.norm_left } end /-- Let `f` be a measurable function integrable on `a..b`. The function `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • f b - u • f a` within `s × t` at `(a, b)`, where `s ∈ {Iic a, {a}, Ici a, univ}` and `t ∈ {Iic b, {b}, Ici b, univ}` provided that `f` tends to `f a` and `f b` at the filters `la` and `lb` from the following table. In most cases this assumption is definitionally equal `continuous_at f _` or `continuous_within_at f _ _`. | `s` | `la` | `t` | `lb` | | ------- | ---- | --- | ---- | | `Iic a` | `𝓝[Iic a] a` | `Iic b` | `𝓝[Iic b] b` | | `Ici a` | `𝓝[Ioi a] a` | `Ici b` | `𝓝[Ioi b] b` | | `{a}` | `⊥` | `{b}` | `⊥` | | `univ` | `𝓝 a` | `univ` | `𝓝 b` | -/ lemma integral_has_fderiv_within_at (hf : interval_integrable f volume a b) (hmeas_a : measurable_at_filter f la) (hmeas_b : measurable_at_filter f lb) {s t : set ℝ} [FTC_filter a (𝓝[s] a) la] [FTC_filter b (𝓝[t] b) lb] (ha : tendsto f la (𝓝 $ f a)) (hb : tendsto f lb (𝓝 $ f b)) : has_fderiv_within_at (λ p : ℝ × ℝ, ∫ x in p.1..p.2, f x) ((snd ℝ ℝ ℝ).smul_right (f b) - (fst ℝ ℝ ℝ).smul_right (f a)) (s.prod t) (a, b) := integral_has_fderiv_within_at_of_tendsto_ae hf hmeas_a hmeas_b (ha.mono_left inf_le_left) (hb.mono_left inf_le_left) /-- An auxiliary tactic closing goals `unique_diff_within_at ℝ s a` where `s ∈ {Iic a, Ici a, univ}`. -/ meta def unique_diff_within_at_Ici_Iic_univ : tactic unit := `[apply_rules [unique_diff_on.unique_diff_within_at, unique_diff_on_Ici, unique_diff_on_Iic, left_mem_Ici, right_mem_Iic, unique_diff_within_at_univ]] /-- Let `f` be a measurable function integrable on `a..b`. Choose `s ∈ {Iic a, Ici a, univ}` and `t ∈ {Iic b, Ici b, univ}`. Suppose that `f` tends to `ca` and `cb` almost surely at the filters `la` and `lb` from the table below. Then `fderiv_within ℝ (λ p, ∫ x in p.1..p.2, f x) (s.prod t)` is equal to `(u, v) ↦ u • cb - v • ca`. | `s` | `la` | `t` | `lb` | | ------- | ---- | --- | ---- | | `Iic a` | `𝓝[Iic a] a` | `Iic b` | `𝓝[Iic b] b` | | `Ici a` | `𝓝[Ioi a] a` | `Ici b` | `𝓝[Ioi b] b` | | `univ` | `𝓝 a` | `univ` | `𝓝 b` | -/ lemma fderiv_within_integral_of_tendsto_ae (hf : interval_integrable f volume a b) (hmeas_a : measurable_at_filter f la) (hmeas_b : measurable_at_filter f lb) {s t : set ℝ} [FTC_filter a (𝓝[s] a) la] [FTC_filter b (𝓝[t] b) lb] (ha : tendsto f (la ⊓ volume.ae) (𝓝 ca)) (hb : tendsto f (lb ⊓ volume.ae) (𝓝 cb)) (hs : unique_diff_within_at ℝ s a . unique_diff_within_at_Ici_Iic_univ) (ht : unique_diff_within_at ℝ t b . unique_diff_within_at_Ici_Iic_univ) : fderiv_within ℝ (λ p : ℝ × ℝ, ∫ x in p.1..p.2, f x) (s.prod t) (a, b) = ((snd ℝ ℝ ℝ).smul_right cb - (fst ℝ ℝ ℝ).smul_right ca) := (integral_has_fderiv_within_at_of_tendsto_ae hf hmeas_a hmeas_b ha hb).fderiv_within $ hs.prod ht /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely as `x` tends to `b` from the right or from the left, then `u ↦ ∫ x in a..u, f x` has right (resp., left) derivative `c` at `b`. -/ lemma integral_has_deriv_within_at_of_tendsto_ae_right (hf : interval_integrable f volume a b) {s t : set ℝ} [FTC_filter b (𝓝[s] b) (𝓝[t] b)] (hmeas : measurable_at_filter f (𝓝[t] b)) (hb : tendsto f (𝓝[t] b ⊓ volume.ae) (𝓝 c)) : has_deriv_within_at (λ u, ∫ x in a..u, f x) c s b := integral_sub_integral_sub_linear_is_o_of_tendsto_ae_right hf hmeas hb (tendsto_const_pure.mono_right FTC_filter.pure_le) tendsto_id /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` is continuous from the left or from the right at `b`, then `u ↦ ∫ x in a..u, f x` has left (resp., right) derivative `f b` at `b`. -/ lemma integral_has_deriv_within_at_right (hf : interval_integrable f volume a b) {s t : set ℝ} [FTC_filter b (𝓝[s] b) (𝓝[t] b)] (hmeas : measurable_at_filter f (𝓝[t] b)) (hb : continuous_within_at f t b) : has_deriv_within_at (λ u, ∫ x in a..u, f x) (f b) s b := integral_has_deriv_within_at_of_tendsto_ae_right hf hmeas (hb.mono_left inf_le_left) /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely as `x` tends to `b` from the right or from the left, then the right (resp., left) derivative of `u ↦ ∫ x in a..u, f x` at `b` equals `c`. -/ lemma deriv_within_integral_of_tendsto_ae_right (hf : interval_integrable f volume a b) {s t : set ℝ} [FTC_filter b (𝓝[s] b) (𝓝[t] b)] (hmeas: measurable_at_filter f (𝓝[t] b)) (hb : tendsto f (𝓝[t] b ⊓ volume.ae) (𝓝 c)) (hs : unique_diff_within_at ℝ s b . unique_diff_within_at_Ici_Iic_univ) : deriv_within (λ u, ∫ x in a..u, f x) s b = c := (integral_has_deriv_within_at_of_tendsto_ae_right hf hmeas hb).deriv_within hs /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` is continuous on the right or on the left at `b`, then the right (resp., left) derivative of `u ↦ ∫ x in a..u, f x` at `b` equals `f b`. -/ lemma deriv_within_integral_right (hf : interval_integrable f volume a b) {s t : set ℝ} [FTC_filter b (𝓝[s] b) (𝓝[t] b)] (hmeas : measurable_at_filter f (𝓝[t] b)) (hb : continuous_within_at f t b) (hs : unique_diff_within_at ℝ s b . unique_diff_within_at_Ici_Iic_univ) : deriv_within (λ u, ∫ x in a..u, f x) s b = f b := (integral_has_deriv_within_at_right hf hmeas hb).deriv_within hs /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely as `x` tends to `a` from the right or from the left, then `u ↦ ∫ x in u..b, f x` has right (resp., left) derivative `-c` at `a`. -/ lemma integral_has_deriv_within_at_of_tendsto_ae_left (hf : interval_integrable f volume a b) {s t : set ℝ} [FTC_filter a (𝓝[s] a) (𝓝[t] a)] (hmeas : measurable_at_filter f (𝓝[t] a)) (ha : tendsto f (𝓝[t] a ⊓ volume.ae) (𝓝 c)) : has_deriv_within_at (λ u, ∫ x in u..b, f x) (-c) s a := by { simp only [integral_symm b], exact (integral_has_deriv_within_at_of_tendsto_ae_right hf.symm hmeas ha).neg } /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` is continuous from the left or from the right at `a`, then `u ↦ ∫ x in u..b, f x` has left (resp., right) derivative `-f a` at `a`. -/ lemma integral_has_deriv_within_at_left (hf : interval_integrable f volume a b) {s t : set ℝ} [FTC_filter a (𝓝[s] a) (𝓝[t] a)] (hmeas : measurable_at_filter f (𝓝[t] a)) (ha : continuous_within_at f t a) : has_deriv_within_at (λ u, ∫ x in u..b, f x) (-f a) s a := integral_has_deriv_within_at_of_tendsto_ae_left hf hmeas (ha.mono_left inf_le_left) /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely as `x` tends to `a` from the right or from the left, then the right (resp., left) derivative of `u ↦ ∫ x in u..b, f x` at `a` equals `-c`. -/ lemma deriv_within_integral_of_tendsto_ae_left (hf : interval_integrable f volume a b) {s t : set ℝ} [FTC_filter a (𝓝[s] a) (𝓝[t] a)] (hmeas : measurable_at_filter f (𝓝[t] a)) (ha : tendsto f (𝓝[t] a ⊓ volume.ae) (𝓝 c)) (hs : unique_diff_within_at ℝ s a . unique_diff_within_at_Ici_Iic_univ) : deriv_within (λ u, ∫ x in u..b, f x) s a = -c := (integral_has_deriv_within_at_of_tendsto_ae_left hf hmeas ha).deriv_within hs /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` is continuous on the right or on the left at `a`, then the right (resp., left) derivative of `u ↦ ∫ x in u..b, f x` at `a` equals `-f a`. -/ lemma deriv_within_integral_left (hf : interval_integrable f volume a b) {s t : set ℝ} [FTC_filter a (𝓝[s] a) (𝓝[t] a)] (hmeas : measurable_at_filter f (𝓝[t] a)) (ha : continuous_within_at f t a) (hs : unique_diff_within_at ℝ s a . unique_diff_within_at_Ici_Iic_univ) : deriv_within (λ u, ∫ x in u..b, f x) s a = -f a := (integral_has_deriv_within_at_left hf hmeas ha).deriv_within hs /-! ### Fundamental theorem of calculus, part 2 This section contains theorems pertaining to FTC-2 for interval integrals. -/ variables {f' : ℝ → E} /-- The integral of a continuous function is differentiable on a real set `s`. -/ theorem differentiable_on_integral_of_continuous {s : set ℝ} (hintg : ∀ x ∈ s, interval_integrable f volume a x) (hcont : continuous f) : differentiable_on ℝ (λ u, ∫ x in a..u, f x) s := λ y hy, (integral_has_deriv_at_right (hintg y hy) hcont.measurable.ae_measurable.measurable_at_filter hcont.continuous_at) .differentiable_at.differentiable_within_at /-- The integral of a continuous function is continuous on a real set `s`. This is true even without the assumption of continuity, but a proof of that fact does not yet exist in mathlib. -/ theorem continuous_on_integral_of_continuous {s : set ℝ} (hintg : ∀ x ∈ s, interval_integrable f volume a x) (hcont : continuous f) : continuous_on (λ u, ∫ x in a..u, f x) s := (differentiable_on_integral_of_continuous hintg hcont).continuous_on /-- Fundamental theorem of calculus-2: If `f : ℝ → E` is continuous on `[a, b]` and has a right derivative at `f' x` for all `x` in `[a, b)`, and `f'` is continuous on `[a, b]` and measurable, then `∫ y in a..b, f' y` equals `f b - f a`. -/ theorem integral_eq_sub_of_has_deriv_right_of_le (hab : a ≤ b) (hcont : continuous_on f (Icc a b)) (hderiv : ∀ x ∈ Ico a b, has_deriv_within_at f (f' x) (Ici x) x) (hcont' : continuous_on f' (Icc a b)) : ∫ y in a..b, f' y = f b - f a := begin have hmeas' : ae_measurable f' (volume.restrict (Icc a b)), from hcont'.ae_measurable is_measurable_Icc, refine eq_sub_of_add_eq (eq_of_has_deriv_right_eq (λ y hy, _) hderiv (λ y hy, _) hcont (by simp) _ (right_mem_Icc.2 hab)), { refine (integral_has_deriv_within_at_right _ _ _).add_const _, { refine (hcont'.mono _).interval_integrable, simp only [hy.left, Icc_subset_Icc_right hy.right.le, interval_of_le] }, { exact ⟨_, Icc_mem_nhds_within_Ioi hy, hmeas'⟩, }, { exact (hcont' _ (mem_Icc_of_Ico hy)).mono_of_mem (Icc_mem_nhds_within_Ioi hy) } }, { -- TODO: prove that integral of any integrable function is continuous, and use here letI : tendsto_Ixx_class Ioc (𝓟 (Icc a b)) (𝓟 (Ioc a b)) := tendsto_Ixx_class_principal.2 (λ x hx y hy, Ioc_subset_Ioc hx.1 hy.2), haveI : is_measurably_generated (𝓝[Ioc a b] y) := is_measurable_Ioc.nhds_within_is_measurably_generated y, letI : FTC_filter y (𝓝[Icc a b] y) (𝓝[Ioc a b] y) := ⟨pure_le_nhds_within hy, inf_le_left⟩, refine (integral_has_deriv_within_at_right _ _ _).continuous_within_at.add continuous_within_at_const, { exact (hcont'.mono $ Icc_subset_Icc_right hy.2).interval_integrable_of_Icc hy.1 }, { exact ⟨_, mem_sets_of_superset self_mem_nhds_within Ioc_subset_Icc_self, hmeas'⟩ }, { exact (hcont' y hy).mono Ioc_subset_Icc_self } } end /-- Fundamental theorem of calculus-2: If `f : ℝ → E` is continuous on `[a, b]` (where `a ≤ b`) and has a right derivative at `f' x` for all `x` in `[a, b)`, and `f'` is continuous on `[a, b]` and measurable, then `∫ y in a..b, f' y` equals `f b - f a`. -/ theorem integral_eq_sub_of_has_deriv_right (hcont : continuous_on f (interval a b)) (hderiv : ∀ x ∈ Ico (min a b) (max a b), has_deriv_within_at f (f' x) (Ici x) x) (hcont' : continuous_on f' (interval a b)) : ∫ y in a..b, f' y = f b - f a := begin cases le_total a b with hab hab, { simp only [interval_of_le, min_eq_left, max_eq_right, hab] at hcont hcont' hderiv, exact integral_eq_sub_of_has_deriv_right_of_le hab hcont hderiv hcont' }, { simp only [interval_of_ge, min_eq_right, max_eq_left, hab] at hcont hcont' hderiv, rw [integral_symm, integral_eq_sub_of_has_deriv_right_of_le hab hcont hderiv hcont', neg_sub] } end /-- Fundamental theorem of calculus-2: If `f : ℝ → E` is continuous on `[a, b]` and has a derivative at `f' x` for all `x` in `[a, b)`, and `f'` is continuous on `[a, b]` and measurable, then `∫ y in a..b, f' y` equals `f b - f a`. -/ theorem integral_eq_sub_of_has_deriv_at' (hcont : continuous_on f (interval a b)) (hderiv : ∀ x ∈ Ico (min a b) (max a b), has_deriv_at f (f' x) x) (hcont' : continuous_on f' (interval a b)) : ∫ y in a..b, f' y = f b - f a := integral_eq_sub_of_has_deriv_right hcont (λ x hx, (hderiv x hx).has_deriv_within_at) hcont' /-- Fundamental theorem of calculus-2: If `f : ℝ → E` has a derivative at `f' x` for all `x` in `[a, b)` and `f'` is continuous on `[a, b]` and measurable, then `∫ y in a..b, f' y` equals `f b - f a`. -/ theorem integral_eq_sub_of_has_deriv_at (hderiv : ∀ x ∈ interval a b, has_deriv_at f (f' x) x) (hcont' : continuous_on f' (interval a b)) : ∫ y in a..b, f' y = f b - f a := integral_eq_sub_of_has_deriv_at' (λ x hx, (hderiv x hx).continuous_at.continuous_within_at) (λ x hx, hderiv _ (mem_Icc_of_Ico hx)) hcont' /-- Fundamental theorem of calculus-2: If `f : ℝ → E` is differentiable at every `x` in `[a, b]` and its derivative is continuous on `[a, b]`, then `∫ y in a..b, deriv f y` equals `f b - f a`. -/ theorem integral_deriv_eq_sub (hderiv : ∀ x ∈ interval a b, differentiable_at ℝ f x) (hcont' : continuous_on (deriv f) (interval a b)) : ∫ y in a..b, deriv f y = f b - f a := integral_eq_sub_of_has_deriv_at (λ x hx, (hderiv x hx).has_deriv_at) hcont' end interval_integral
62d6093f5d979e9247aded8d35cf90d2b2868c76
54d7e71c3616d331b2ec3845d31deb08f3ff1dea
/tests/lean/run/quote1.lean
d13b11bf401c05aa8da430ecc065f0d546656057
[ "Apache-2.0" ]
permissive
pachugupta/lean
6f3305c4292288311cc4ab4550060b17d49ffb1d
0d02136a09ac4cf27b5c88361750e38e1f485a1a
refs/heads/master
1,611,110,653,606
1,493,130,117,000
1,493,167,649,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
304
lean
open tactic list meta definition foo (a : pexpr) : pexpr := `(%%a + %%a + %%a + b) example (a b : nat) : a = a := by do a ← get_local `a, t1 ← mk_app `add [a, a], t2 ← to_expr (foo (to_pexpr t1)), trace t2, r ← mk_app (`eq.refl) [a], exact r private def f := unit #check ``f
93b3ba257287b43f02b4a4c8902d1adcaaf132a1
35677d2df3f081738fa6b08138e03ee36bc33cad
/src/category_theory/limits/cones.lean
2563271c400421cbb7493c1c0f9064c85da652f8
[ "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
14,518
lean
/- Copyright (c) 2017 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Stephen Morgan, Scott Morrison, Floris van Doorn -/ import category_theory.const import category_theory.yoneda import category_theory.concrete_category.bundled_hom import category_theory.equivalence universes v u u' -- declare the `v`'s first; see `category_theory.category` for an explanation open category_theory -- There is an awkward difficulty with universes here. -- If we allowed `J` to be a small category in `Prop`, we'd run into trouble -- because `yoneda.obj (F : (J ⥤ C)ᵒᵖ)` will be a functor into `Sort (max v 1)`, -- not into `Sort v`. -- So we don't allow this case; it's not particularly useful anyway. variables {J : Type v} [small_category J] variables {C : Type u} [𝒞 : category.{v} C] include 𝒞 open category_theory open category_theory.category open category_theory.functor open opposite namespace category_theory namespace functor variables {J C} (F : J ⥤ C) /-- `F.cones` is the functor assigning to an object `X` the type of natural transformations from the constant functor with value `X` to `F`. An object representing this functor is a limit of `F`. -/ def cones : Cᵒᵖ ⥤ Type v := (const J).op ⋙ (yoneda.obj F) lemma cones_obj (X : Cᵒᵖ) : F.cones.obj X = ((const J).obj (unop X) ⟶ F) := rfl @[simp] lemma cones_map_app {X₁ X₂ : Cᵒᵖ} (f : X₁ ⟶ X₂) (t : F.cones.obj X₁) (j : J) : (F.cones.map f t).app j = f.unop ≫ t.app j := rfl /-- `F.cocones` is the functor assigning to an object `X` the type of natural transformations from `F` to the constant functor with value `X`. An object corepresenting this functor is a colimit of `F`. -/ def cocones : C ⥤ Type v := const J ⋙ coyoneda.obj (op F) lemma cocones_obj (X : C) : F.cocones.obj X = (F ⟶ (const J).obj X) := rfl @[simp] lemma cocones_map_app {X₁ X₂ : C} (f : X₁ ⟶ X₂) (t : F.cocones.obj X₁) (j : J) : (F.cocones.map f t).app j = t.app j ≫ f := rfl end functor section variables (J C) /-- Functorially associated to each functor `J ⥤ C`, we have the `C`-presheaf consisting of cones with a given cone point. -/ @[simps] def cones : (J ⥤ C) ⥤ (Cᵒᵖ ⥤ Type v) := { obj := functor.cones, map := λ F G f, whisker_left (const J).op (yoneda.map f) } /-- Contravariantly associated to each functor `J ⥤ C`, we have the `C`-copresheaf consisting of cocones with a given cocone point. -/ @[simps] def cocones : (J ⥤ C)ᵒᵖ ⥤ (C ⥤ Type v) := { obj := λ F, functor.cocones (unop F), map := λ F G f, whisker_left (const J) (coyoneda.map f) } end namespace limits /-- A `c : cone F` is: * an object `c.X` and * a natural transformation `c.π : c.X ⟶ F` from the constant `c.X` functor to `F`. `cone F` is equivalent, via `cone.equiv` below, to `Σ X, F.cones.obj X`. -/ structure cone (F : J ⥤ C) := (X : C) (π : (const J).obj X ⟶ F) @[simp] lemma cone.w {F : J ⥤ C} (c : cone F) {j j' : J} (f : j ⟶ j') : c.π.app j ≫ F.map f = c.π.app j' := by convert ←(c.π.naturality f).symm; apply id_comp /-- A `c : cocone F` is * an object `c.X` and * a natural transformation `c.ι : F ⟶ c.X` from `F` to the constant `c.X` functor. `cocone F` is equivalent, via `cone.equiv` below, to `Σ X, F.cocones.obj X`. -/ structure cocone (F : J ⥤ C) := (X : C) (ι : F ⟶ (const J).obj X) @[simp] lemma cocone.w {F : J ⥤ C} (c : cocone F) {j j' : J} (f : j ⟶ j') : F.map f ≫ c.ι.app j' = c.ι.app j := by convert ←(c.ι.naturality f); apply comp_id variables {F : J ⥤ C} namespace cone def equiv (F : J ⥤ C) : cone F ≅ Σ X, F.cones.obj X := { hom := λ c, ⟨op c.X, c.π⟩, inv := λ c, { X := unop c.1, π := c.2 }, hom_inv_id' := begin ext, cases x, refl, end, inv_hom_id' := begin ext, cases x, refl, end } @[simp] def extensions (c : cone F) : yoneda.obj c.X ⟶ F.cones := { app := λ X f, ((const J).map f) ≫ c.π } /-- A map to the vertex of a cone induces a cone by composition. -/ @[simp] def extend (c : cone F) {X : C} (f : X ⟶ c.X) : cone F := { X := X, π := c.extensions.app (op X) f } @[simp] lemma extend_π (c : cone F) {X : Cᵒᵖ} (f : unop X ⟶ c.X) : (extend c f).π = c.extensions.app X f := rfl @[simps] def whisker {K : Type v} [small_category K] (E : K ⥤ J) (c : cone F) : cone (E ⋙ F) := { X := c.X, π := whisker_left E c.π } -- We now prove a lemma about naturality of cones over functors into bundled categories. section omit 𝒞 variables {J' : Type u} [small_category J'] variables {C' : Type (u+1)} [large_category C'] [𝒞' : concrete_category C'] include 𝒞' local attribute [instance] concrete_category.has_coe_to_sort local attribute [instance] concrete_category.has_coe_to_fun /-- Naturality of a cone over functors to a concrete category. -/ @[simp] lemma naturality_concrete {G : J' ⥤ C'} (s : cone G) {j j' : J'} (f : j ⟶ j') (x : s.X) : (G.map f) ((s.π.app j) x) = (s.π.app j') x := begin convert congr_fun (congr_arg (λ k : s.X ⟶ G.obj j', (k : s.X → G.obj j')) (s.π.naturality f).symm) x; { dsimp, simp }, end end end cone namespace cocone def equiv (F : J ⥤ C) : cocone F ≅ Σ X, F.cocones.obj X := { hom := λ c, ⟨c.X, c.ι⟩, inv := λ c, { X := c.1, ι := c.2 }, hom_inv_id' := begin ext, cases x, refl, end, inv_hom_id' := begin ext, cases x, refl, end } @[simp] def extensions (c : cocone F) : coyoneda.obj (op c.X) ⟶ F.cocones := { app := λ X f, c.ι ≫ (const J).map f } /-- A map from the vertex of a cocone induces a cocone by composition. -/ @[simp] def extend (c : cocone F) {X : C} (f : c.X ⟶ X) : cocone F := { X := X, ι := c.extensions.app X f } @[simp] lemma extend_ι (c : cocone F) {X : C} (f : c.X ⟶ X) : (extend c f).ι = c.extensions.app X f := rfl @[simps] def whisker {K : Type v} [small_category K] (E : K ⥤ J) (c : cocone F) : cocone (E ⋙ F) := { X := c.X, ι := whisker_left E c.ι } -- We now prove a lemma about naturality of cocones over functors into bundled categories. section omit 𝒞 variables {J' : Type u} [small_category J'] variables {C' : Type (u+1)} [large_category C'] [𝒞' : concrete_category C'] include 𝒞' local attribute [instance] concrete_category.has_coe_to_sort local attribute [instance] concrete_category.has_coe_to_fun /-- Naturality of a cocone over functors into a concrete category. -/ @[simp] lemma naturality_concrete {G : J' ⥤ C'} (s : cocone G) {j j' : J'} (f : j ⟶ j') (x : G.obj j) : (s.ι.app j') ((G.map f) x) = (s.ι.app j) x := begin convert congr_fun (congr_arg (λ k : G.obj j ⟶ s.X, (k : G.obj j → s.X)) (s.ι.naturality f)) x; { dsimp, simp }, end end end cocone @[ext] structure cone_morphism (A B : cone F) := (hom : A.X ⟶ B.X) (w' : ∀ j : J, hom ≫ B.π.app j = A.π.app j . obviously) restate_axiom cone_morphism.w' attribute [simp] cone_morphism.w @[simps] instance cone.category : category.{v} (cone F) := { hom := λ A B, cone_morphism A B, comp := λ X Y Z f g, { hom := f.hom ≫ g.hom, w' := by intro j; rw [assoc, g.w, f.w] }, id := λ B, { hom := 𝟙 B.X } } namespace cones /-- To give an isomorphism between cones, it suffices to give an isomorphism between their vertices which commutes with the cone maps. -/ @[ext, simps] def ext {c c' : cone F} (φ : c.X ≅ c'.X) (w : ∀ j, c.π.app j = φ.hom ≫ c'.π.app j) : c ≅ c' := { hom := { hom := φ.hom }, inv := { hom := φ.inv, w' := λ j, φ.inv_comp_eq.mpr (w j) } } @[simps] def postcompose {G : J ⥤ C} (α : F ⟶ G) : cone F ⥤ cone G := { obj := λ c, { X := c.X, π := c.π ≫ α }, map := λ c₁ c₂ f, { hom := f.hom, w' := by intro; erw ← category.assoc; simp [-category.assoc] } } def postcompose_comp {G H : J ⥤ C} (α : F ⟶ G) (β : G ⟶ H) : postcompose (α ≫ β) ≅ postcompose α ⋙ postcompose β := by { fapply nat_iso.of_components, { intro s, fapply ext, refl, obviously }, obviously } def postcompose_id : postcompose (𝟙 F) ≅ 𝟭 (cone F) := by { fapply nat_iso.of_components, { intro s, fapply ext, refl, obviously }, obviously } def postcompose_equivalence {G : J ⥤ C} (α : F ≅ G) : cone F ≌ cone G := begin refine equivalence.mk (postcompose α.hom) (postcompose α.inv) _ _, { symmetry, refine (postcompose_comp _ _).symm.trans _, rw [iso.hom_inv_id], exact postcompose_id }, { refine (postcompose_comp _ _).symm.trans _, rw [iso.inv_hom_id], exact postcompose_id } end section variable (F) @[simps] def forget : cone F ⥤ C := { obj := λ t, t.X, map := λ s t f, f.hom } end section variables {D : Type u'} [𝒟 : category.{v} D] include 𝒟 @[simps] def functoriality (G : C ⥤ D) : cone F ⥤ cone (F ⋙ G) := { obj := λ A, { X := G.obj A.X, π := { app := λ j, G.map (A.π.app j), naturality' := by intros; erw ←G.map_comp; tidy } }, map := λ X Y f, { hom := G.map f.hom, w' := by intros; rw [←functor.map_comp, f.w] } } end end cones @[ext] structure cocone_morphism (A B : cocone F) := (hom : A.X ⟶ B.X) (w' : ∀ j : J, A.ι.app j ≫ hom = B.ι.app j . obviously) restate_axiom cocone_morphism.w' attribute [simp] cocone_morphism.w @[simps] instance cocone.category : category.{v} (cocone F) := { hom := λ A B, cocone_morphism A B, comp := λ _ _ _ f g, { hom := f.hom ≫ g.hom, w' := by intro j; rw [←assoc, f.w, g.w] }, id := λ B, { hom := 𝟙 B.X } } namespace cocones /-- To give an isomorphism between cocones, it suffices to give an isomorphism between their vertices which commutes with the cocone maps. -/ @[ext, simps] def ext {c c' : cocone F} (φ : c.X ≅ c'.X) (w : ∀ j, c.ι.app j ≫ φ.hom = c'.ι.app j) : c ≅ c' := { hom := { hom := φ.hom }, inv := { hom := φ.inv, w' := λ j, φ.comp_inv_eq.mpr (w j).symm } } @[simps] def precompose {G : J ⥤ C} (α : G ⟶ F) : cocone F ⥤ cocone G := { obj := λ c, { X := c.X, ι := α ≫ c.ι }, map := λ c₁ c₂ f, { hom := f.hom } } def precompose_comp {G H : J ⥤ C} (α : F ⟶ G) (β : G ⟶ H) : precompose (α ≫ β) ≅ precompose β ⋙ precompose α := by { fapply nat_iso.of_components, { intro s, fapply ext, refl, obviously }, obviously } def precompose_id : precompose (𝟙 F) ≅ 𝟭 (cocone F) := by { fapply nat_iso.of_components, { intro s, fapply ext, refl, obviously }, obviously } def precompose_equivalence {G : J ⥤ C} (α : G ≅ F) : cocone F ≌ cocone G := begin refine equivalence.mk (precompose α.hom) (precompose α.inv) _ _, { symmetry, refine (precompose_comp _ _).symm.trans _, rw [iso.inv_hom_id], exact precompose_id }, { refine (precompose_comp _ _).symm.trans _, rw [iso.hom_inv_id], exact precompose_id } end section variable (F) @[simps] def forget : cocone F ⥤ C := { obj := λ t, t.X, map := λ s t f, f.hom } end section variables {D : Type u'} [𝒟 : category.{v} D] include 𝒟 @[simps] def functoriality (G : C ⥤ D) : cocone F ⥤ cocone (F ⋙ G) := { obj := λ A, { X := G.obj A.X, ι := { app := λ j, G.map (A.ι.app j), naturality' := by intros; erw ←G.map_comp; tidy } }, map := λ _ _ f, { hom := G.map f.hom, w' := by intros; rw [←functor.map_comp, cocone_morphism.w] } } end end cocones end limits namespace functor variables {D : Type u'} [category.{v} D] variables {F : J ⥤ C} {G : J ⥤ C} (H : C ⥤ D) open category_theory.limits /-- The image of a cone in C under a functor G : C ⥤ D is a cone in D. -/ def map_cone (c : cone F) : cone (F ⋙ H) := (cones.functoriality H).obj c /-- The image of a cocone in C under a functor G : C ⥤ D is a cocone in D. -/ def map_cocone (c : cocone F) : cocone (F ⋙ H) := (cocones.functoriality H).obj c @[simp] lemma map_cone_X (c : cone F) : (H.map_cone c).X = H.obj c.X := rfl @[simp] lemma map_cocone_X (c : cocone F) : (H.map_cocone c).X = H.obj c.X := rfl def map_cone_inv [is_equivalence H] (c : cone (F ⋙ H)) : cone F := let t := (inv H).map_cone c in let α : (F ⋙ H) ⋙ inv H ⟶ F := ((whisker_left F is_equivalence.unit_iso.inv) : F ⋙ (H ⋙ inv H) ⟶ _) ≫ (functor.right_unitor _).hom in { X := t.X, π := ((category_theory.cones J C).map α).app (op t.X) t.π } @[simp] lemma map_cone_inv_X [is_equivalence H] (c : cone (F ⋙ H)) : (H.map_cone_inv c).X = (inv H).obj c.X := rfl def map_cone_morphism {c c' : cone F} (f : cone_morphism c c') : cone_morphism (H.map_cone c) (H.map_cone c') := (cones.functoriality H).map f def map_cocone_morphism {c c' : cocone F} (f : cocone_morphism c c') : cocone_morphism (H.map_cocone c) (H.map_cocone c') := (cocones.functoriality H).map f @[simp] lemma map_cone_π (c : cone F) (j : J) : (map_cone H c).π.app j = H.map (c.π.app j) := rfl @[simp] lemma map_cocone_ι (c : cocone F) (j : J) : (map_cocone H c).ι.app j = H.map (c.ι.app j) := rfl end functor end category_theory namespace category_theory.limits variables {F : J ⥤ Cᵒᵖ} -- Here and below we only automatically generate the `@[simp]` lemma for the `X` field, -- as we can be a simpler `rfl` lemma for the components of the natural transformation by hand. @[simps X] def cone_of_cocone_left_op (c : cocone F.left_op) : cone F := { X := op c.X, π := nat_trans.right_op (c.ι ≫ (const.op_obj_unop (op c.X)).hom) } @[simp] lemma cone_of_cocone_left_op_π_app (c : cocone F.left_op) (j) : (cone_of_cocone_left_op c).π.app j = (c.ι.app (op j)).op := by { dsimp [cone_of_cocone_left_op], simp } @[simps X] def cocone_left_op_of_cone (c : cone F) : cocone (F.left_op) := { X := unop c.X, ι := nat_trans.left_op c.π } @[simp] lemma cocone_left_op_of_cone_ι_app (c : cone F) (j) : (cocone_left_op_of_cone c).ι.app j = (c.π.app (unop j)).unop := by { dsimp [cocone_left_op_of_cone], simp } @[simps X] def cocone_of_cone_left_op (c : cone F.left_op) : cocone F := { X := op c.X, ι := nat_trans.right_op ((const.op_obj_unop (op c.X)).hom ≫ c.π) } @[simp] lemma cocone_of_cone_left_op_ι_app (c : cone F.left_op) (j) : (cocone_of_cone_left_op c).ι.app j = (c.π.app (op j)).op := by { dsimp [cocone_of_cone_left_op], simp } @[simps X] def cone_left_op_of_cocone (c : cocone F) : cone (F.left_op) := { X := unop c.X, π := nat_trans.left_op c.ι } @[simp] lemma cone_left_op_of_cocone_π_app (c : cocone F) (j) : (cone_left_op_of_cocone c).π.app j = (c.ι.app (unop j)).unop := by { dsimp [cone_left_op_of_cocone], simp } end category_theory.limits
fa19a96ae8b080a02435812375cd77065640d801
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/linear_algebra/multilinear/basis.lean
14f7477bac1da6f740f79f8912ffcddd0ea3a924
[ "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
2,345
lean
/- Copyright (c) 2021 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import linear_algebra.basis import linear_algebra.multilinear.basic /-! # Multilinear maps in relation to bases. > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file proves lemmas about the action of multilinear maps on basis vectors. ## TODO * Refactor the proofs in terms of bases of tensor products, once there is an equivalent of `basis.tensor_product` for `pi_tensor_product`. -/ open multilinear_map variables {R : Type*} {ι : Type*} {n : ℕ} {M : fin n → Type*} {M₂ : Type*} {M₃ : Type*} variables [comm_semiring R] [add_comm_monoid M₂] [add_comm_monoid M₃] [∀i, add_comm_monoid (M i)] variables [∀i, module R (M i)] [module R M₂] [module R M₃] /-- Two multilinear maps indexed by `fin n` are equal if they are equal when all arguments are basis vectors. -/ lemma basis.ext_multilinear_fin {f g : multilinear_map R M M₂} {ι₁ : fin n → Type*} (e : Π i, basis (ι₁ i) R (M i)) (h : ∀ (v : Π i, ι₁ i), f (λ i, e i (v i)) = g (λ i, e i (v i))) : f = g := begin unfreezingI { induction n with m hm }, { ext x, convert h fin_zero_elim }, { apply function.left_inverse.injective uncurry_curry_left, refine basis.ext (e 0) _, intro i, apply hm (fin.tail e), intro j, convert h (fin.cons i j), iterate 2 { rw curry_left_apply, congr' 1 with x, refine fin.cases rfl (λ x, _) x, dsimp [fin.tail], rw [fin.cons_succ, fin.cons_succ], } } end /-- Two multilinear maps indexed by a `fintype` are equal if they are equal when all arguments are basis vectors. Unlike `basis.ext_multilinear_fin`, this only uses a single basis; a dependently-typed version would still be true, but the proof would need a dependently-typed version of `dom_dom_congr`. -/ lemma basis.ext_multilinear [finite ι] {f g : multilinear_map R (λ i : ι, M₂) M₃} {ι₁ : Type*} (e : basis ι₁ R M₂) (h : ∀ v : ι → ι₁, f (λ i, e (v i)) = g (λ i, e (v i))) : f = g := by { casesI nonempty_fintype ι, exact (dom_dom_congr_eq_iff (fintype.equiv_fin ι) f g).mp (basis.ext_multilinear_fin (λ i, e) $ λ i, h (i ∘ _)) }
f31d9282773d63d96b30713cac9023fc904f2b4f
76df16d6c3760cb415f1294caee997cc4736e09b
/lean/src/interp/lang/defs.lean
dcabd170cff8f58f063287eb2dee1d247d914ceb
[ "MIT" ]
permissive
uw-unsat/leanette-popl22-artifact
70409d9cbd8921d794d27b7992bf1d9a4087e9fe
80fea2519e61b45a283fbf7903acdf6d5528dbe7
refs/heads/master
1,681,592,449,670
1,637,037,431,000
1,637,037,431,000
414,331,908
6
1
null
null
null
null
UTF-8
Lean
false
false
1,649
lean
import ...cs.lang namespace interp open lang open lang.result open lang.exp open lang.val section interp variables {D O : Type} (op : O → list (val D O) → lang.result D O) -- The concrete interpreter: -- `interpC` consumes a `fuel`, an program `e`, a concrete environment `ε`, and -- returns either -- - `none` if the interpretation runs out of `fuel` or references -- a variable out of scope. -- - `some` concrete result `r` def interpC : ℕ → exp D O → env D O → option (lang.result D O) | 0 _ _ := none | (fuel+1) e ε := match e with | bool b := some (ans (bool b)) | datum d := some (ans (datum d)) | lam x e_b := some (ans (clos x e_b ε)) | var x := match ε.nth x with | none := none | some v := some (ans v) end | app o as := match list.mmap (λ a, ε.nth a) as with | none := none | some vs := some $ op o vs end | call a_f a_a := match ε.nth a_f with | none := none | some v_f := match ε.nth a_a with | none := none | some v_a := match v_f with | clos x e_b ε_static := interpC fuel e_b (ε_static.update_nth x v_a) | _ := some err end end end | let0 x e_v e_b := match interpC fuel e_v ε with | none := none | some (halt b) := some (halt b) | some (ans v_v) := interpC fuel e_b (ε.update_nth x v_v) end | if0 a_c e_t e_e := match ε.nth a_c with | none := none | some (bool ff) := interpC fuel e_e ε | some _ := interpC fuel e_t ε end | error := some err | abort := some abt end end interp end interp
84a9d8bd540e4aedacc35cc600e3231bc37f4cf2
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/category_theory/groupoid/basic.lean
edcd548ec99a54386b64b193374efabff7585528
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
1,110
lean
/- Copyright (c) 2022 Rémi Bottinelli. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémi Bottinelli -/ import category_theory.groupoid import combinatorics.quiver.basic /-! > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file defines a few basic properties of groupoids. -/ namespace category_theory namespace groupoid variables (C : Type*) [groupoid C] section thin lemma is_thin_iff : quiver.is_thin C ↔ ∀ c : C, subsingleton (c ⟶ c) := begin refine ⟨λ h c, h c c, λ h c d, subsingleton.intro $ λ f g, _⟩, haveI := h d, calc f = f ≫ (inv g ≫ g) : by simp only [inv_eq_inv, is_iso.inv_hom_id, category.comp_id] ... = f ≫ (inv f ≫ g) : by congr ... = g : by simp only [inv_eq_inv, is_iso.hom_inv_id_assoc], end end thin section disconnected /-- A subgroupoid is totally disconnected if it only has loops. -/ def is_totally_disconnected := ∀ (c d : C), (c ⟶ d) → c = d end disconnected end groupoid end category_theory
6341e4d2dd60790e8ef831699d42bc4fae241c6b
618003631150032a5676f229d13a079ac875ff77
/test/library_search/ordered_ring.lean
4a9ce1c292da26a3c485bca6230401254be702b7
[ "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
449
lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import algebra.ordered_ring import init_.data.nat.lemmas /- Turn off trace messages so they don't pollute the test build: -/ set_option trace.silence_library_search true example {a b : ℕ} (h : b > 0) (w : a ≥ 1) : b ≤ a * b := by library_search -- exact (le_mul_iff_one_le_left h).mpr w
d49bd59fe95019f5c6c209b78a1ad0a123ce7020
12dabd587ce2621d9a4eff9f16e354d02e206c8e
/world10/level15.lean
d12ea12ed5a73a75da22b37d91faaf8d0831b062
[]
no_license
abdelq/natural-number-game
a1b5b8f1d52625a7addcefc97c966d3f06a48263
bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2
refs/heads/master
1,668,606,478,691
1,594,175,058,000
1,594,175,058,000
278,673,209
0
1
null
null
null
null
UTF-8
Lean
false
false
248
lean
lemma lt_aux_one (a b : mynat) : a ≤ b ∧ ¬ (b ≤ a) → succ a ≤ b := begin intro h, cases h with h1 h2, cases h1 with d hd, cases d, exfalso, apply h2, rw hd, rw add_zero, exact le_refl a, use d, rw hd, rw add_succ, rw succ_add, refl, end
33de919af690d504e57e1d9d09c880c2dc11b849
7da5ceac20aaab989eeb795a4be9639982e7b35a
/src/ring_theory/algebra2.lean
6ff5e5e21d73356338cb6c22cf9e3cc61b4334e2
[ "MIT" ]
permissive
formalabstracts/formalabstracts
46c2f1b3a172e62ca6ffeb46fbbdf1705718af49
b0173da1af45421239d44492eeecd54bf65ee0f6
refs/heads/master
1,606,896,370,374
1,572,988,776,000
1,572,988,776,000
96,763,004
165
28
null
1,555,709,319,000
1,499,680,948,000
Lean
UTF-8
Lean
false
false
11,038
lean
import ..basic ring_theory.algebra linear_algebra.tensor_product ring_theory.ideal_operations category_theory.concrete_category open set universes u v w /- move to ideal-/ namespace ideal namespace quotient variables {α : Type*} {β : Type*} [comm_ring α] [comm_ring β] {S : ideal α} {T : ideal β} {f : α → β} {H : ∀ {{a : α}}, a ∈ S → f a ∈ T} -- replace lift def lift' (S : ideal α) (f : α → β) [is_add_group_hom f] (H : ∀ (a : α), a ∈ S → f a = 0) : quotient S → β := λ x, quotient.lift_on' x f $ λ (a b) (h : _ ∈ _), eq_of_sub_eq_zero (by simpa only [is_add_group_hom.map_sub f] using H _ h) def map (S : ideal α) (T : ideal β) (f : α → β) [is_add_group_hom f] (H : ∀ {{a : α}}, a ∈ S → f a ∈ T) : quotient S → quotient T := begin haveI : is_add_group_hom ((mk T : β → quotient T) ∘ f) := is_add_group_hom.comp _ _, refine ideal.quotient.lift' S (mk T ∘ f) _, intros x hx, refine ideal.quotient.eq.2 _, rw [sub_zero], exact H hx end @[simp] lemma map_mk' [is_add_group_hom f] (x : α) : map S T f H (mk S x) = mk T (f x) := rfl instance map.is_ring_hom [is_ring_hom f] : is_ring_hom (map S T f H) := by dsimp [map]; exact omitted end quotient end ideal /- move to module -/ section module variables {R : Type u} {S : Type*} [ring R] variables {M : Type*} [add_comm_group M] variables [module R M] instance smul.is_add_group_hom {r : R} : is_add_group_hom (λ x : M, r • x) := by refine_struct {..}; simp [smul_add] def quotient_add_group.quotient.module {s : set M} [normal_add_subgroup s] (h : ∀(r : R) {x : M}, x ∈ s → r • x ∈ s) : module R (quotient_add_group.quotient s) := { smul := λ r, quotient_add_group.map _ _ (λ(x : M), r • x) (λ x h', h r h'), smul_add := omitted, add_smul := omitted, mul_smul := omitted, one_smul := omitted, zero_smul := omitted, smul_zero := omitted } end module variables {R : Type u} {S : Type*} [comm_ring R] [comm_ring S] variables {M : Type*} {N : Type*} {P : Type*} [ring M] [ring N] [ring P] variables {A : Type*} {B : Type*} {A' : Type*} {B' : Type*} {X : Type*} variables [comm_ring A] [comm_ring B] [comm_ring A'] [comm_ring B'] [comm_ring X] variables [algebra R M] [algebra R N] [algebra R P] variables [algebra R A] [algebra R B] [algebra R A'] [algebra R B'] [algebra R X] notation M ` ⊗[`:100 R `] ` N:100 := tensor_product R M N namespace algebra /-- A R-module is an R-algebra if scalar multiplication commutes with multiplication -/ def of_module {R : Type u} {A : Type v} [comm_ring R] [ring A] [m : module R A] (h : ∀(r : R) (x y : A), r • x * y = x * r • y) : algebra R A := { to_fun := λ r, r • 1, hom := ⟨one_smul R 1, by { intros, rw [h, one_mul, mul_smul] }, λ x y, add_smul x y 1⟩, commutes' := by { intros, rw [h, one_mul, ←h, mul_one] }, smul_def' := by { intros, rw [h, one_mul] }, ..m } /-- The codomain of a ring homomorphism viewed as an algebra over the domain -/ def induced_algebra (f : R → S) [is_ring_hom f] : Type* := S instance (f : R → S) [is_ring_hom f] : comm_ring (induced_algebra f) := _inst_2 instance (f : R → S) [is_ring_hom f] : algebra R (induced_algebra f) := algebra.of_ring_hom f (by apply_instance) end algebra open algebra namespace alg_hom /-- A ring homomorphism induces an algebra homomorphism -/ protected def of_ring_hom (f : R → S) [is_ring_hom f] : R →ₐ[R] induced_algebra f := { to_fun := f, hom := by apply_instance, commutes' := λ r, rfl } end alg_hom open algebra namespace tensor_product /- short-ciruiting some type class inference -/ protected def add_comm_group' : add_comm_group (M ⊗[R] N) := by apply_instance protected def module' : module R (M ⊗[R] N) := by apply_instance local attribute [instance, priority 2000] tensor_product.add_comm_group' tensor_product.module' linear_map.module protected def lmap_add_comm_group : add_comm_group (M ⊗[R] N →ₗ[R] M ⊗[R] N) := by apply_instance protected def lmap_module : module R (M ⊗[R] N →ₗ[R] M ⊗[R] N) := by apply_instance local attribute [instance, priority 2000] tensor_product.lmap_add_comm_group tensor_product.lmap_module /-- The multiplication on the tensor product of two R-algebras as a bilinear map -/ protected def mul : M ⊗[R] N →ₗ[R] M ⊗[R] N →ₗ[R] M ⊗[R] N := begin refine tensor_product.lift ⟨λ m, ⟨λ n, _, omitted, omitted⟩, omitted, omitted⟩, refine tensor_product.lift ⟨λ m', ⟨λ n', _, omitted, omitted⟩, omitted, omitted⟩, exact tmul R (m * m') (n * n') end /-- The ring structure on the tensor product of two R-algebras -/ instance : ring (M ⊗[R] N) := { mul := λ x y, tensor_product.mul.to_fun x y, mul_assoc := omitted, one := tmul R 1 1, one_mul := omitted, mul_one := omitted, left_distrib := omitted, right_distrib := omitted, ..tensor_product.add_comm_group M N } lemma mul_def (m m' : M) (n n' : N) : tmul R m n * tmul R m' n' = tmul R (m * m') (n * n') := rfl instance : comm_ring (A ⊗[R] B) := { mul_comm := omitted, ..tensor_product.ring } /-- The algebra structure on the tensor product of two R-algebras -/ instance : algebra R (M ⊗[R] N) := algebra.of_module omitted @[simp] lemma algebra_map_tensor (r : R) : algebra_map (M ⊗[R] N) r = r • 1 := rfl def tensor_inl : M →ₐ[R] M ⊗[R] N := { to_fun := λ m, tmul R m 1, hom := ⟨rfl, by { intros, rw [mul_def, one_mul] }, λ x y, add_tmul x y 1⟩, commutes' := λ r, omitted } def tensor_inr : N →ₐ[R] M ⊗[R] N := { to_fun := λ n, tmul R 1 n, hom := omitted, commutes' := omitted } def tensor_lift (f : A →ₐ[R] X) (g : B →ₐ[R] X) : A ⊗[R] B →ₐ[R] X := begin refine ⟨lift_aux _, _⟩, fapply linear_map.mk₂, exact (λ a b, f a * g b), all_goals {exact omitted} end def tensor_functor (f : A →ₐ[R] A') (g : B →ₐ[R] B') : A ⊗[R] B →ₐ[R] A' ⊗[R] B' := tensor_lift (tensor_inl.comp f) (tensor_inr.comp g) def tensor_lift_equiv : ((A →ₐ[R] X) × (B →ₐ[R] X)) ≃ (A ⊗[R] B →ₐ[R] X) := ⟨λ fg, tensor_lift fg.1 fg.2, λ f, ⟨f.comp tensor_inl, f.comp tensor_inr⟩, omitted, omitted⟩ end tensor_product namespace quotient def smul {I : ideal A} (r : R) : I.quotient → I.quotient := ideal.quotient.map _ _ (λ(x : A), r • x) (λ x h', by rw [smul_def]; exact I.mul_mem_left h') @[simp] lemma smul_mk {I : ideal A} (r : R) (x : A) : quotient.smul r (ideal.quotient.mk I x) = ideal.quotient.mk I (r • x) := by refl end quotient instance quotient.algebra (I : ideal A) : algebra R I.quotient := { smul := quotient.smul, smul_add := λ r x y, quotient.induction_on₂' x y $ λ a b, congr_arg (ideal.quotient.mk _) $ smul_add r a b, add_smul := λ r s x, quotient.induction_on' x $ λ a, congr_arg (ideal.quotient.mk _) $ add_smul r s a, mul_smul := λ r s x, quotient.induction_on' x $ λ a, congr_arg (ideal.quotient.mk _) $ mul_smul r s a, one_smul := λ x, quotient.induction_on' x $ λ a, congr_arg (ideal.quotient.mk _) $ by simp only [one_smul], zero_smul := λ x, quotient.induction_on' x $ λ a, congr_arg (ideal.quotient.mk _) $ by simp only [zero_smul], smul_zero := λ r, congr_arg (ideal.quotient.mk _) $ by simp only [smul_zero], to_fun := ideal.quotient.mk I ∘ algebra_map A, commutes' := λ r x, quotient.induction_on' x $ λ a, congr_arg (ideal.quotient.mk _) $ commutes r a, smul_def' := λ r x, quotient.induction_on' x $ λ a, congr_arg (ideal.quotient.mk _) $ smul_def r a } namespace algebra.quotient def mk (I : ideal A) : A →ₐ[R] I.quotient := { to_fun := ideal.quotient.mk I, hom := by apply_instance, commutes' := omitted } def lift {I : ideal A} (f : A →ₐ[R] B) (H : ∀ (a : A), a ∈ I → f a = 0) : I.quotient →ₐ[R] B := { to_fun := ideal.quotient.lift I f.to_fun H, hom := by apply_instance, commutes' := omitted } def functor {I : ideal A} {J : ideal B} (f : A →ₐ[R] B) (H : ∀ (a : A), a ∈ I → f a ∈ J) : I.quotient →ₐ[R] J.quotient := lift ((mk J).comp f) omitted end algebra.quotient namespace pi variable {I : Type u} -- The indexing type variable {f : I → Type v} -- The family of types already equiped with instances variables (x y : Π i, f i) (i : I) instance algebra (α) {r : comm_ring α} [∀ i, ring $ f i] [∀ i, algebra α $ f i] : algebra α (Π i : I, f i) := by { haveI : module α (Π i : I, f i) := infer_instance, exact algebra.of_module omitted } end pi namespace mv_polynomial variables {σ : Type*} [decidable_eq σ] [decidable_eq R] /-- (σ → A) → Hom[R-Alg](R[σ],A). Maybe this should replace aeval? -/ def aeval₂ (f : σ → A) : mv_polynomial σ R →ₐ[R] A := { to_fun := eval₂ (algebra_map A) f, hom := ⟨eval₂_one _ _, λ _ _, eval₂_mul _ _, λ _ _, eval₂_add _ _⟩, commutes' := λ r, eval₂_C _ _ _ } -- def alg_hom {σ τ : Type*} [decidable_eq σ] [decidable_eq τ] [decidable_eq R] : -- mv_polynomial σ R →ₐ[R] mv_polynomial τ R := -- sorry end mv_polynomial open mv_polynomial local attribute [instance, priority 0] classical.prop_decidable /-- An algebra `β` is finitely generated over a ring `α` if there is a finite subset `s` of `β` such that every element of `β` can be expressed as a polynomial in the elements of `s` with coefficients in `α` -/ def is_finitely_generated (α : Type u) [comm_ring α] (β : Type v) [comm_ring β] [algebra α β] : Prop := ∃(s : finset β), ∀(x : β), ∃(p : mv_polynomial {x // x ∈ s} α), p.eval₂ (algebra_map β) subtype.val = x def is_finitely_generated_base (α : Type u) [comm_ring α] : is_finitely_generated α α := ⟨∅, λ x, ⟨C x, eval₂_C _ _ _⟩⟩ /-- Every quotient algebra is finitely generated -/ lemma is_finitely_generated_quotient {α : Type u} [comm_ring α] {β : Type v} [comm_ring β] [algebra α β] [decidable_eq α] [decidable_eq β] (h : is_finitely_generated α β) (I : ideal β) : is_finitely_generated α (I.quotient) := omitted /-- The tensor product of two finitely generated algebras is finitely generated -/ lemma is_finitely_generated_tensor (hA : is_finitely_generated R A) (hB : is_finitely_generated R B) : is_finitely_generated R (A ⊗[R] B) := omitted /-- The type of algebras over a fixed commutative ring. -/ structure Algebra (R : Type u) [comm_ring R] : Type max u (v+1) := (β : Type v) (ring : ring β) (algebra : algebra R β) attribute [instance] Algebra.ring Algebra.algebra instance : has_coe_to_sort (Algebra.{u v} R) := { S := Type v, coe := Algebra.β } -- instance Algebra.ring' (x : Algebra R) : ring x := by apply_instance -- instance Algebra.algebra' (x : Algebra R) : algebra R x := by apply_instance open category_theory /-- The category of algebras over a fixed commutative ring. -/ instance Algebra.category : category (Algebra.{u v} R) := { hom := λ a b, a.β →ₐ[R] b.β, id := λ a, alg_hom.id R a, comp := λ a b c f g, alg_hom.comp g f }
c6dfcb90c363be623f213a6b5222c9c74b6195e3
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/measure_theory/function/strongly_measurable/inner.lean
07954268931251e37958f8fc5f707c255b5de7fe
[ "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,748
lean
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne, Sébastien Gouëzel -/ import measure_theory.function.strongly_measurable.basic import analysis.inner_product_space.basic /-! # Inner products of strongly measurable functions are strongly measurable. -/ variables {α : Type*} namespace measure_theory /-! ## Strongly measurable functions -/ namespace strongly_measurable protected lemma inner {𝕜 : Type*} {E : Type*} [is_R_or_C 𝕜] [inner_product_space 𝕜 E] {m : measurable_space α} {f g : α → E} (hf : strongly_measurable f) (hg : strongly_measurable g) : strongly_measurable (λ t, @inner 𝕜 _ _(f t) (g t)) := continuous.comp_strongly_measurable continuous_inner (hf.prod_mk hg) end strongly_measurable namespace ae_strongly_measurable variables {m : measurable_space α} {μ : measure α} {𝕜 : Type*} {E : Type*} [is_R_or_C 𝕜] [inner_product_space 𝕜 E] local notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ x y protected lemma re {f : α → 𝕜} (hf : ae_strongly_measurable f μ) : ae_strongly_measurable (λ x, is_R_or_C.re (f x)) μ := is_R_or_C.continuous_re.comp_ae_strongly_measurable hf protected lemma im {f : α → 𝕜} (hf : ae_strongly_measurable f μ) : ae_strongly_measurable (λ x, is_R_or_C.im (f x)) μ := is_R_or_C.continuous_im.comp_ae_strongly_measurable hf protected lemma inner {m : measurable_space α} {μ : measure α} {f g : α → E} (hf : ae_strongly_measurable f μ) (hg : ae_strongly_measurable g μ) : ae_strongly_measurable (λ x, ⟪f x, g x⟫) μ := continuous_inner.comp_ae_strongly_measurable (hf.prod_mk hg) end ae_strongly_measurable end measure_theory
4872966c444fd641e00d701265e90d967fdf0d3a
d9ed0fce1c218297bcba93e046cb4e79c83c3af8
/library/init/data/nat/lemmas.lean
41130779af9945533c0769841a1df53c9543c4a6
[ "Apache-2.0" ]
permissive
leodemoura/lean_clone
005c63aa892a6492f2d4741ee3c2cb07a6be9d7f
cc077554b584d39bab55c360bc12a6fe7957afe6
refs/heads/master
1,610,506,475,484
1,482,348,354,000
1,482,348,543,000
77,091,586
0
0
null
null
null
null
UTF-8
Lean
false
false
24,813
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, Jeremy Avigad -/ prelude import init.data.nat.basic init.meta init.algebra namespace nat protected lemma zero_add : ∀ n : ℕ, 0 + n = n | 0 := rfl | (n+1) := congr_arg succ (zero_add n) lemma succ_add : ∀ n m : ℕ, (succ n) + m = succ (n + m) | n 0 := rfl | n (m+1) := congr_arg succ (succ_add n m) lemma add_succ : ∀ n m : ℕ, n + succ m = succ (n + m) := λ n m, rfl lemma add_zero : ∀ n : ℕ, n + 0 = n := λ n, rfl lemma add_one_eq_succ : ∀ n : ℕ, n + 1 = succ n := λ n, rfl protected lemma add_comm : ∀ n m : ℕ, n + m = m + n | n 0 := eq.symm (nat.zero_add n) | n (m+1) := suffices succ (n + m) = succ (m + n), from eq.symm (succ_add m n) ▸ this, congr_arg succ (add_comm n m) protected lemma add_assoc : ∀ n m k : ℕ, (n + m) + k = n + (m + k) | n m 0 := rfl | n m (succ k) := by simp [add_succ, add_assoc n m k] protected lemma add_left_comm : ∀ (n m k : ℕ), n + (m + k) = m + (n + k) := left_comm nat.add nat.add_comm nat.add_assoc protected lemma add_left_cancel : ∀ {n m k : ℕ}, n + m = n + k → m = k | 0 m k := by ctx_simp [nat.zero_add] | (succ n) m k := λ h, have n+m = n+k, begin simp [succ_add] at h, injection h, assumption end, add_left_cancel this protected lemma add_right_cancel {n m k : ℕ} (h : n + m = k + m) : n = k := have m + n = m + k, begin rw [nat.add_comm n m, nat.add_comm k m] at h, assumption end, nat.add_left_cancel this lemma succ_ne_zero (n : ℕ) : succ n ≠ 0 := assume h, nat.no_confusion h lemma succ_ne_self : ∀ n : ℕ, succ n ≠ n | 0 h := absurd h (nat.succ_ne_zero 0) | (n+1) h := succ_ne_self n (nat.no_confusion h (λ h, h)) protected lemma one_ne_zero : 1 ≠ (0 : ℕ) := assume h, nat.no_confusion h protected lemma zero_ne_one : 0 ≠ (1 : ℕ) := assume h, nat.no_confusion h lemma eq_zero_of_add_eq_zero_right : ∀ {n m : ℕ}, n + m = 0 → n = 0 | 0 m := by ctx_simp [nat.zero_add] | (n+1) m := λ h, begin exfalso, rw [add_one_eq_succ, succ_add] at h, apply succ_ne_zero _ h end lemma eq_zero_of_add_eq_zero_left {n m : ℕ} (h : n + m = 0) : m = 0 := @eq_zero_of_add_eq_zero_right m n (nat.add_comm n m ▸ h) lemma pred_zero : pred 0 = 0 := rfl lemma pred_succ (n : ℕ) : pred (succ n) = n := rfl protected lemma mul_zero (n : ℕ) : n * 0 = 0 := rfl lemma mul_succ (n m : ℕ) : n * succ m = n * m + n := rfl protected theorem zero_mul : ∀ (n : ℕ), 0 * n = 0 | 0 := rfl | (succ n) := by rw [mul_succ, zero_mul] private meta def sort_add := `[simp [nat.add_assoc, nat.add_comm, nat.add_left_comm]] lemma succ_mul : ∀ (n m : ℕ), (succ n) * m = (n * m) + m | n 0 := rfl | n (succ m) := begin simp [mul_succ, add_succ, succ_mul n m], sort_add end protected lemma right_distrib : ∀ (n m k : ℕ), (n + m) * k = n * k + m * k | n m 0 := rfl | n m (succ k) := begin simp [mul_succ, right_distrib n m k], sort_add end protected lemma left_distrib : ∀ (n m k : ℕ), n * (m + k) = n * m + n * k | 0 m k := by simp [nat.zero_mul] | (succ n) m k := begin simp [succ_mul, left_distrib n m k], sort_add end protected lemma mul_comm : ∀ (n m : ℕ), n * m = m * n | n 0 := by rw [nat.zero_mul, nat.mul_zero] | n (succ m) := by simp [mul_succ, succ_mul, mul_comm n m] protected lemma mul_assoc : ∀ (n m k : ℕ), (n * m) * k = n * (m * k) | n m 0 := rfl | n m (succ k) := by simp [mul_succ, nat.left_distrib, mul_assoc n m k] protected lemma mul_one : ∀ (n : ℕ), n * 1 = n | 0 := rfl | (succ n) := by simp [succ_mul, mul_one n, add_one_eq_succ] protected lemma one_mul (n : ℕ) : 1 * n = n := by rw [nat.mul_comm, nat.mul_one] lemma eq_zero_or_eq_zero_of_mul_eq_zero : ∀ {n m : ℕ}, n * m = 0 → n = 0 ∨ m = 0 | 0 m := λ h, or.inl rfl | (succ n) m := begin rw succ_mul, intro h, exact or.inr (eq_zero_of_add_eq_zero_left h) end instance : comm_semiring nat := {add := nat.add, add_assoc := nat.add_assoc, zero := nat.zero, zero_add := nat.zero_add, add_zero := nat.add_zero, add_comm := nat.add_comm, mul := nat.mul, mul_assoc := nat.mul_assoc, one := nat.succ nat.zero, one_mul := nat.one_mul, mul_one := nat.mul_one, left_distrib := nat.left_distrib, right_distrib := nat.right_distrib, zero_mul := nat.zero_mul, mul_zero := nat.mul_zero, mul_comm := nat.mul_comm} /- properties of inequality -/ protected lemma le_of_eq {n m : ℕ} (p : n = m) : n ≤ m := p ▸ less_than.refl n lemma le_succ_iff_true (n : ℕ) : n ≤ succ n ↔ true := iff_true_intro (le_succ n) lemma pred_le_iff_true (n : ℕ) : pred n ≤ n ↔ true := iff_true_intro (pred_le n) lemma le_succ_of_le {n m : ℕ} (h : n ≤ m) : n ≤ succ m := nat.le_trans h (le_succ m) lemma le_of_succ_le {n m : ℕ} (h : succ n ≤ m) : n ≤ m := nat.le_trans (le_succ n) h protected lemma le_of_lt {n m : ℕ} (h : n < m) : n ≤ m := le_of_succ_le h lemma le_succ_of_pred_le {n m : ℕ} : pred n ≤ m → n ≤ succ m := nat.cases_on n less_than.step (λ a, succ_le_succ) lemma succ_le_zero_iff_false (n : ℕ) : succ n ≤ 0 ↔ false := iff_false_intro (not_succ_le_zero n) lemma succ_le_self_iff_false (n : ℕ) : succ n ≤ n ↔ false := iff_false_intro (not_succ_le_self n) lemma zero_le_iff_true (n : ℕ) : 0 ≤ n ↔ true := iff_true_intro (zero_le n) def lt.step {n m : ℕ} : n < m → n < succ m := less_than.step lemma zero_lt_succ_iff_true (n : ℕ) : 0 < succ n ↔ true := iff_true_intro (zero_lt_succ n) def succ_pos_iff_true := zero_lt_succ_iff_true protected lemma pos_of_ne_zero {n : nat} (h : n ≠ 0) : n > 0 := begin cases n, contradiction, apply succ_pos end protected lemma lt_trans {n m k : ℕ} (h₁ : n < m) : m < k → n < k := nat.le_trans (less_than.step h₁) protected lemma lt_of_le_of_lt {n m k : ℕ} (h₁ : n ≤ m) : m < k → n < k := nat.le_trans (succ_le_succ h₁) lemma lt_self_iff_false (n : ℕ) : n < n ↔ false := iff_false_intro (λ h, absurd h (nat.lt_irrefl n)) lemma self_lt_succ (n : ℕ) : n < succ n := nat.le_refl (succ n) def lt_succ_self := @self_lt_succ lemma self_lt_succ_iff_true (n : ℕ) : n < succ n ↔ true := iff_true_intro (self_lt_succ n) def lt_succ_self_iff_true := @self_lt_succ_iff_true def lt.base (n : ℕ) : n < succ n := nat.le_refl (succ n) lemma le_lt_antisymm {n m : ℕ} (h₁ : n ≤ m) (h₂ : m < n) : false := nat.lt_irrefl n (nat.lt_of_le_of_lt h₁ h₂) protected lemma le_antisymm {n m : ℕ} (h₁ : n ≤ m) : m ≤ n → n = m := less_than.cases_on h₁ (λ a, rfl) (λ a b c, absurd (nat.lt_of_le_of_lt b c) (nat.lt_irrefl n)) instance : weak_order ℕ := ⟨@nat.less_than, @nat.le_refl, @nat.le_trans, @nat.le_antisymm⟩ lemma lt_le_antisymm {n m : ℕ} (h₁ : n < m) (h₂ : m ≤ n) : false := le_lt_antisymm h₂ h₁ protected lemma nat.lt_asymm {n m : ℕ} (h₁ : n < m) : ¬ m < n := le_lt_antisymm (nat.le_of_lt h₁) lemma lt_zero_iff_false (a : ℕ) : a < 0 ↔ false := iff_false_intro (not_lt_zero a) protected lemma le_of_eq_or_lt {a b : ℕ} (h : a = b ∨ a < b) : a ≤ b := or.elim h nat.le_of_eq nat.le_of_lt lemma succ_lt_succ {a b : ℕ} : a < b → succ a < succ b := succ_le_succ lemma lt_of_succ_lt {a b : ℕ} : succ a < b → a < b := le_of_succ_le lemma lt_of_succ_lt_succ {a b : ℕ} : succ a < succ b → a < b := le_of_succ_le_succ protected lemma lt_or_ge : ∀ (a b : ℕ), a < b ∨ a ≥ b | a 0 := or.inr (zero_le a) | a (b+1) := match lt_or_ge a b with | or.inl h := or.inl (le_succ_of_le h) | or.inr h := match nat.eq_or_lt_of_le h with | or.inl h1 := or.inl (h1 ▸ self_lt_succ b) | or.inr h1 := or.inr h1 end end protected def {u} lt_ge_by_cases {a b : ℕ} {C : Type u} (h₁ : a < b → C) (h₂ : a ≥ b → C) : C := decidable.by_cases h₁ (λ h, h₂ (or.elim (nat.lt_or_ge a b) (λ a, absurd a h) (λ a, a))) protected def {u} lt_by_cases {a b : ℕ} {C : Type u} (h₁ : a < b → C) (h₂ : a = b → C) (h₃ : b < a → C) : C := nat.lt_ge_by_cases h₁ (λ h₁, nat.lt_ge_by_cases h₃ (λ h, h₂ (nat.le_antisymm h h₁))) protected lemma lt_trichotomy (a b : ℕ) : a < b ∨ a = b ∨ b < a := nat.lt_by_cases (λ h, or.inl h) (λ h, or.inr (or.inl h)) (λ h, or.inr (or.inr h)) protected lemma eq_or_lt_of_not_lt {a b : ℕ} (hnlt : ¬ a < b) : a = b ∨ b < a := or.elim (nat.lt_trichotomy a b) (λ hlt, absurd hlt hnlt) (λ h, h) lemma lt_of_succ_le {a b : ℕ} (h : succ a ≤ b) : a < b := h lemma succ_le_of_lt {a b : ℕ} (h : a < b) : succ a ≤ b := h lemma le_add_right : ∀ (n k : ℕ), n ≤ n + k | n 0 := nat.le_refl n | n (k+1) := le_succ_of_le (le_add_right n k) lemma le_add_left (n m : ℕ): n ≤ m + n := nat.add_comm n m ▸ le_add_right n m lemma le.dest : ∀ {n m : ℕ}, n ≤ m → ∃ k, n + k = m | n .n (less_than.refl .n) := ⟨0, rfl⟩ | n .(succ m) (@less_than.step .n m h) := match le.dest h with | ⟨w, hw⟩ := ⟨succ w, hw ▸ add_succ n w⟩ end lemma le.intro {n m k : ℕ} (h : n + k = m) : n ≤ m := h ▸ le_add_right n k protected lemma add_le_add_left {n m : ℕ} (h : n ≤ m) (k : ℕ) : k + n ≤ k + m := match le.dest h with | ⟨w, hw⟩ := @le.intro _ _ w begin rw [nat.add_assoc, hw] end end protected lemma add_le_add_right {n m : ℕ} (h : n ≤ m) (k : ℕ) : n + k ≤ m + k := begin rw [nat.add_comm n k, nat.add_comm m k], apply nat.add_le_add_left h end protected lemma le_of_add_le_add_left {k n m : ℕ} (h : k + n ≤ k + m) : n ≤ m := match le.dest h with | ⟨w, hw⟩ := @le.intro _ _ w begin dsimp at hw, rw [nat.add_assoc] at hw, apply nat.add_left_cancel hw end end protected lemma lt_of_le_and_ne {m n : ℕ} (h1 : m ≤ n) : m ≠ n → m < n := or.resolve_right (or.swap (nat.eq_or_lt_of_le h1)) protected theorem lt_of_add_lt_add_left {k n m : ℕ} (h : k + n < k + m) : n < m := let h' := nat.le_of_lt h in nat.lt_of_le_and_ne (nat.le_of_add_le_add_left h') (λ heq, nat.lt_irrefl (k + m) begin rw heq at h, assumption end) protected lemma add_lt_add_left {n m : ℕ} (h : n < m) (k : ℕ) : k + n < k + m := lt_of_succ_le (add_succ k n ▸ nat.add_le_add_left (succ_le_of_lt h) k) protected lemma add_lt_add_right {n m : ℕ} (h : n < m) (k : ℕ) : n + k < m + k := nat.add_comm k m ▸ nat.add_comm k n ▸ nat.add_lt_add_left h k protected lemma lt_add_of_pos_right {n k : ℕ} (h : k > 0) : n < n + k := nat.add_lt_add_left h n protected lemma zero_lt_one : 0 < (1:nat) := zero_lt_succ 0 def one_pos := nat.zero_lt_one protected lemma le_total {m n : ℕ} : m ≤ n ∨ n ≤ m := or.imp_left nat.le_of_lt (nat.lt_or_ge m n) protected lemma le_of_lt_or_eq {m n : ℕ} (h : m < n ∨ m = n) : m ≤ n := nat.le_of_eq_or_lt (or.swap h) protected lemma lt_or_eq_of_le {m n : ℕ} (h : m ≤ n) : m < n ∨ m = n := or.swap (nat.eq_or_lt_of_le h) protected lemma le_iff_lt_or_eq (m n : ℕ) : m ≤ n ↔ m < n ∨ m = n := iff.intro nat.lt_or_eq_of_le nat.le_of_lt_or_eq lemma mul_le_mul_left {n m : ℕ} (k : ℕ) (h : n ≤ m) : k * n ≤ k * m := match le.dest h with | ⟨l, hl⟩ := have k * n + k * l = k * m, by rw [-left_distrib, hl], le.intro this end lemma mul_le_mul_right {n m : ℕ} (k : ℕ) (h : n ≤ m) : n * k ≤ m * k := mul_comm k m ▸ mul_comm k n ▸ mul_le_mul_left k h protected lemma mul_lt_mul_of_pos_left {n m k : ℕ} (h : n < m) (hk : k > 0) : k * n < k * m := nat.lt_of_lt_of_le (nat.lt_add_of_pos_right hk) (mul_succ k n ▸ nat.mul_le_mul_left k (succ_le_of_lt h)) protected lemma mul_lt_mul_of_pos_right {n m k : ℕ} (h : n < m) (hk : k > 0) : n * k < m * k := mul_comm k m ▸ mul_comm k n ▸ nat.mul_lt_mul_of_pos_left h hk instance : decidable_linear_ordered_semiring nat := { nat.comm_semiring with add_left_cancel := @nat.add_left_cancel, add_right_cancel := @nat.add_right_cancel, lt := nat.lt, le := nat.le, le_refl := nat.le_refl, le_trans := @nat.le_trans, le_antisymm := @nat.le_antisymm, le_total := @nat.le_total, le_iff_lt_or_eq := @nat.le_iff_lt_or_eq, le_of_lt := @nat.le_of_lt, lt_irrefl := @nat.lt_irrefl, lt_of_lt_of_le := @nat.lt_of_lt_of_le, lt_of_le_of_lt := @nat.lt_of_le_of_lt, lt_of_add_lt_add_left := @nat.lt_of_add_lt_add_left, add_lt_add_left := @nat.add_lt_add_left, add_le_add_left := @nat.add_le_add_left, le_of_add_le_add_left := @nat.le_of_add_le_add_left, zero_lt_one := zero_lt_succ 0, mul_le_mul_of_nonneg_left := (take a b c h₁ h₂, nat.mul_le_mul_left c h₁), mul_le_mul_of_nonneg_right := (take a b c h₁ h₂, nat.mul_le_mul_right c h₁), mul_lt_mul_of_pos_left := @nat.mul_lt_mul_of_pos_left, mul_lt_mul_of_pos_right := @nat.mul_lt_mul_of_pos_right, decidable_lt := nat.decidable_lt, decidable_le := nat.decidable_le, decidable_eq := nat.decidable_eq } lemma le_of_lt_succ {m n : nat} : m < succ n → m ≤ n := le_of_succ_le_succ /- sub properties -/ lemma sub_eq_succ_sub_succ (a b : ℕ) : a - b = succ a - succ b := eq.symm (succ_sub_succ_eq_sub a b) lemma zero_sub_eq_zero : ∀ a : ℕ, 0 - a = 0 | 0 := rfl | (a+1) := congr_arg pred (zero_sub_eq_zero a) lemma zero_eq_zero_sub (a : ℕ) : 0 = 0 - a := eq.symm (zero_sub_eq_zero a) lemma sub_le_iff_true (a b : ℕ) : a - b ≤ a ↔ true := iff_true_intro (sub_le a b) lemma sub_lt_succ (a b : ℕ) : a - b < succ a := lt_succ_of_le (sub_le a b) lemma sub_lt_succ_iff_true (a b : ℕ) : a - b < succ a ↔ true := iff_true_intro (sub_lt_succ a b) /- bit0/bit1 properties -/ protected lemma bit0_succ_eq (n : ℕ) : bit0 (succ n) = succ (succ (bit0 n)) := show succ (succ n + n) = succ (succ (n + n)), from congr_arg succ (succ_add n n) protected lemma bit1_eq_succ_bit0 (n : ℕ) : bit1 n = succ (bit0 n) := rfl protected lemma bit1_succ_eq (n : ℕ) : bit1 (succ n) = succ (succ (bit1 n)) := eq.trans (nat.bit1_eq_succ_bit0 (succ n)) (congr_arg succ (nat.bit0_succ_eq n)) protected lemma bit0_ne_zero : ∀ {n : ℕ}, n ≠ 0 → bit0 n ≠ 0 | 0 h := absurd rfl h | (n+1) h := succ_ne_zero _ protected lemma bit1_ne_zero (n : ℕ) : bit1 n ≠ 0 := show succ (n + n) ≠ 0, from succ_ne_zero (n + n) protected lemma bit1_ne_one : ∀ {n : ℕ}, n ≠ 0 → bit1 n ≠ 1 | 0 h h1 := absurd rfl h | (n+1) h h1 := nat.no_confusion h1 (λ h2, absurd h2 (succ_ne_zero _)) protected lemma bit0_ne_one : ∀ n : ℕ, bit0 n ≠ 1 | 0 h := absurd h (ne.symm nat.one_ne_zero) | (n+1) h := have h1 : succ (succ (n + n)) = 1, from succ_add n n ▸ h, nat.no_confusion h1 (λ h2, absurd h2 (succ_ne_zero (n + n))) protected lemma add_self_ne_one : ∀ (n : ℕ), n + n ≠ 1 | 0 h := nat.no_confusion h | (n+1) h := have h1 : succ (succ (n + n)) = 1, from succ_add n n ▸ h, nat.no_confusion h1 (λ h2, absurd h2 (nat.succ_ne_zero (n + n))) protected lemma bit1_ne_bit0 : ∀ (n m : ℕ), bit1 n ≠ bit0 m | 0 m h := absurd h (ne.symm (nat.add_self_ne_one m)) | (n+1) 0 h := have h1 : succ (bit0 (succ n)) = 0, from h, absurd h1 (nat.succ_ne_zero _) | (n+1) (m+1) h := have h1 : succ (succ (bit1 n)) = succ (succ (bit0 m)), from nat.bit0_succ_eq m ▸ nat.bit1_succ_eq n ▸ h, have h2 : bit1 n = bit0 m, from nat.no_confusion h1 (λ h2', nat.no_confusion h2' (λ h2'', h2'')), absurd h2 (bit1_ne_bit0 n m) protected lemma bit0_ne_bit1 : ∀ (n m : ℕ), bit0 n ≠ bit1 m := λ n m : nat, ne.symm (nat.bit1_ne_bit0 m n) protected lemma bit0_inj : ∀ {n m : ℕ}, bit0 n = bit0 m → n = m | 0 0 h := rfl | 0 (m+1) h := by contradiction | (n+1) 0 h := by contradiction | (n+1) (m+1) h := have succ (succ (n + n)) = succ (succ (m + m)), begin unfold bit0 at h, simp [add_one_eq_succ, add_succ, succ_add] at h, exact h end, have n + n = m + m, begin repeat {injection this with this}, assumption end, have n = m, from bit0_inj this, by rw this protected lemma bit1_inj : ∀ {n m : ℕ}, bit1 n = bit1 m → n = m := λ n m h, have succ (bit0 n) = succ (bit0 m), begin simp [nat.bit1_eq_succ_bit0] at h, assumption end, have bit0 n = bit0 m, from begin injection this, assumption end, nat.bit0_inj this protected lemma bit0_ne {n m : ℕ} : n ≠ m → bit0 n ≠ bit0 m := λ h₁ h₂, absurd (nat.bit0_inj h₂) h₁ protected lemma bit1_ne {n m : ℕ} : n ≠ m → bit1 n ≠ bit1 m := λ h₁ h₂, absurd (nat.bit1_inj h₂) h₁ protected lemma zero_ne_bit0 {n : ℕ} : n ≠ 0 → 0 ≠ bit0 n := λ h, ne.symm (nat.bit0_ne_zero h) protected lemma zero_ne_bit1 (n : ℕ) : 0 ≠ bit1 n := ne.symm (nat.bit1_ne_zero n) protected lemma one_ne_bit0 (n : ℕ) : 1 ≠ bit0 n := ne.symm (nat.bit0_ne_one n) protected lemma one_ne_bit1 {n : ℕ} : n ≠ 0 → 1 ≠ bit1 n := λ h, ne.symm (nat.bit1_ne_one h) protected lemma zero_lt_bit1 (n : nat) : 0 < bit1 n := zero_lt_succ _ protected lemma zero_lt_bit0 : ∀ {n : nat}, n ≠ 0 → 0 < bit0 n | 0 h := by contradiction | (succ n) h := begin rw nat.bit0_succ_eq, apply zero_lt_succ end protected lemma one_lt_bit1 : ∀ {n : nat}, n ≠ 0 → 1 < bit1 n | 0 h := by contradiction | (succ n) h := begin rw nat.bit1_succ_eq, apply succ_lt_succ, apply zero_lt_succ end protected lemma one_lt_bit0 : ∀ {n : nat}, n ≠ 0 → 1 < bit0 n | 0 h := by contradiction | (succ n) h := begin rw nat.bit0_succ_eq, apply succ_lt_succ, apply zero_lt_succ end protected lemma bit0_lt {n m : nat} (h : n < m) : bit0 n < bit0 m := add_lt_add h h protected lemma bit1_lt {n m : nat} (h : n < m) : bit1 n < bit1 m := succ_lt_succ (add_lt_add h h) protected lemma bit0_lt_bit1 {n m : nat} (h : n ≤ m) : bit0 n < bit1 m := lt_succ_of_le (add_le_add h h) protected lemma bit1_lt_bit0 : ∀ {n m : nat}, n < m → bit1 n < bit0 m | n 0 h := absurd h (not_lt_zero _) | n (succ m) h := have n ≤ m, from le_of_lt_succ h, have succ (n + n) ≤ succ (m + m), from succ_le_succ (add_le_add this this), have succ (n + n) ≤ succ m + m, {rw succ_add, assumption}, show succ (n + n) < succ (succ m + m), from lt_succ_of_le this protected lemma one_le_bit1 (n : ℕ) : 1 ≤ bit1 n := show 1 ≤ succ (bit0 n), from succ_le_succ (zero_le (bit0 n)) protected lemma one_le_bit0 : ∀ (n : ℕ), n ≠ 0 → 1 ≤ bit0 n | 0 h := absurd rfl h | (n+1) h := suffices 1 ≤ succ (succ (bit0 n)), from eq.symm (nat.bit0_succ_eq n) ▸ this, succ_le_succ (zero_le (succ (bit0 n))) /- Extra instances to short-circuit type class resolution -/ instance : add_comm_monoid nat := by apply_instance instance : add_monoid nat := by apply_instance instance : monoid nat := by apply_instance instance : comm_monoid nat := by apply_instance instance : comm_semigroup nat := by apply_instance instance : semigroup nat := by apply_instance instance : add_comm_semigroup nat := by apply_instance instance : add_semigroup nat := by apply_instance /- subtraction -/ protected theorem sub_zero (n : ℕ) : n - 0 = n := rfl theorem sub_succ (n m : ℕ) : n - succ m = pred (n - m) := rfl protected theorem zero_sub : ∀ (n : ℕ), 0 - n = 0 | 0 := by rw nat.sub_zero | (succ n) := by rw [nat.sub_succ, zero_sub n, pred_zero] theorem succ_sub_succ (n m : ℕ) : succ n - succ m = n - m := succ_sub_succ_eq_sub n m protected theorem sub_self : ∀ (n : ℕ), n - n = 0 | 0 := by rw nat.sub_zero | (succ n) := by rw [succ_sub_succ, sub_self n] protected theorem add_sub_add_right : ∀ (n k m : ℕ), (n + k) - (m + k) = n - m | n 0 m := by rw [add_zero, add_zero] | n (succ k) m := by rw [add_succ, add_succ, succ_sub_succ, add_sub_add_right n k m] protected theorem add_sub_add_left (k n m : ℕ) : (k + n) - (k + m) = n - m := by rw [add_comm k n, add_comm k m, nat.add_sub_add_right] protected theorem add_sub_cancel (n m : ℕ) : n + m - m = n := suffices n + m - (0 + m) = n, from by rwa [zero_add] at this, by rw [nat.add_sub_add_right, nat.sub_zero] protected theorem add_sub_cancel_left (n m : ℕ) : n + m - n = m := show n + m - (n + 0) = m, from by rw [nat.add_sub_add_left, nat.sub_zero] protected theorem sub_sub : ∀ (n m k : ℕ), n - m - k = n - (m + k) | n m 0 := by rw [add_zero, nat.sub_zero] | n m (succ k) := by rw [add_succ, nat.sub_succ, nat.sub_succ, sub_sub n m k] theorem succ_sub_sub_succ (n m k : ℕ) : succ n - m - succ k = n - m - k := by rw [nat.sub_sub, nat.sub_sub, add_succ, succ_sub_succ] theorem sub_self_add (n m : ℕ) : n - (n + m) = 0 := show (n + 0) - (n + m) = 0, from by rw [nat.add_sub_add_left, nat.zero_sub] protected theorem sub.right_comm (m n k : ℕ) : m - n - k = m - k - n := by rw [nat.sub_sub, nat.sub_sub, add_comm] theorem sub_one (n : ℕ) : n - 1 = pred n := rfl theorem succ_sub_one (n : ℕ) : succ n - 1 = n := rfl theorem succ_pred_eq_of_pos : ∀ {n : ℕ}, n > 0 → succ (pred n) = n | 0 h := absurd h (lt_irrefl 0) | (succ k) h := rfl theorem mul_pred_left : ∀ (n m : ℕ), pred n * m = n * m - m | 0 m := by simp [nat.zero_sub, pred_zero, zero_mul] | (succ n) m := by rw [pred_succ, succ_mul, nat.add_sub_cancel] theorem mul_pred_right (n m : ℕ) : n * pred m = n * m - n := by rw [mul_comm, mul_pred_left, mul_comm] protected theorem mul_sub_right_distrib : ∀ (n m k : ℕ), (n - m) * k = n * k - m * k | n 0 k := by simp [nat.sub_zero] | n (succ m) k := by rw [nat.sub_succ, mul_pred_left, mul_sub_right_distrib, succ_mul, nat.sub_sub] protected theorem mul_sub_left_distrib (n m k : ℕ) : n * (m - k) = n * m - n * k := by rw [mul_comm, nat.mul_sub_right_distrib, mul_comm m n, mul_comm n k] protected theorem mul_self_sub_mul_self_eq (a b : nat) : a * a - b * b = (a + b) * (a - b) := by rw [nat.mul_sub_left_distrib, right_distrib, right_distrib, mul_comm b a, add_comm (a*a) (a*b), nat.add_sub_add_left] theorem succ_mul_succ_eq (a : nat) : succ a * succ a = a*a + a + a + 1 := begin rw [-add_one_eq_succ], simp [right_distrib, left_distrib] end theorem sub_eq_zero_of_le {n m : ℕ} (h : n ≤ m) : n - m = 0 := exists.elim (nat.le.dest h) (take k, assume hk : n + k = m, by rw [-hk, sub_self_add]) theorem succ_sub {m n : ℕ} (h : m ≥ n) : succ m - n = succ (m - n) := exists.elim (nat.le.dest h) (take k, assume hk : n + k = m, by rw [-hk, nat.add_sub_cancel_left, -add_succ, nat.add_sub_cancel_left]) theorem add_sub_of_le {n m : ℕ} (h : n ≤ m) : n + (m - n) = m := exists.elim (nat.le.dest h) (take k, assume hk : n + k = m, by rw [-hk, nat.add_sub_cancel_left]) protected theorem sub_add_cancel {n m : ℕ} (h : n ≥ m) : n - m + m = n := by rw [add_comm, add_sub_of_le h] protected theorem sub_pos_of_lt {m n : ℕ} (h : m < n) : n - m > 0 := have 0 + m < n - m + m, begin rw [zero_add, nat.sub_add_cancel (le_of_lt h)], exact h end, lt_of_add_lt_add_right this protected theorem add_sub_assoc {m k : ℕ} (h : k ≤ m) (n : ℕ) : n + m - k = n + (m - k) := exists.elim (nat.le.dest h) (take l, assume hl : k + l = m, by rw [-hl, nat.add_sub_cancel_left, add_comm k, -add_assoc, nat.add_sub_cancel]) lemma min_zero_left (a : ℕ) : min 0 a = 0 := min_eq_left (zero_le a) lemma min_zero_right (a : ℕ) : min a 0 = 0 := min_eq_right (zero_le a) -- Distribute succ over min lemma min_succ_succ (x y : ℕ) : min (succ x) (succ y) = succ (min x y) := have f : x ≤ y → min (succ x) (succ y) = succ (min x y), from λp, calc min (succ x) (succ y) = succ x : if_pos (succ_le_succ p) ... = succ (min x y) : congr_arg succ (eq.symm (if_pos p)), have g : ¬ (x ≤ y) → min (succ x) (succ y) = succ (min x y), from λp, calc min (succ x) (succ y) = succ y : if_neg (λeq, p (pred_le_pred eq)) ... = succ (min x y) : congr_arg succ (eq.symm (if_neg p)), decidable.by_cases f g lemma sub_eq_sub_min (n m : ℕ) : n - m = n - min n m := if h : n ≥ m then by rewrite [min_eq_right h] else by rewrite [sub_eq_zero_of_le (le_of_not_ge h), min_eq_left (le_of_not_ge h), nat.sub_self] lemma sub_add_min_cancel (n m : ℕ) : n - m + min n m = n := by rewrite [sub_eq_sub_min, nat.sub_add_cancel (min_le_left n m)] /- TODO(Leo): sub + inequalities -/ end nat
0382358f5809584d1173d223b278c14a8990845f
4b846d8dabdc64e7ea03552bad8f7fa74763fc67
/library/init/meta/smt/ematch.lean
6f2994a909c72cde99d226c453d6f3660205d38c
[ "Apache-2.0" ]
permissive
pacchiano/lean
9324b33f3ac3b5c5647285160f9f6ea8d0d767dc
fdadada3a970377a6df8afcd629a6f2eab6e84e8
refs/heads/master
1,611,357,380,399
1,489,870,101,000
1,489,870,101,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
7,198
lean
/- Copyright (c) 2017 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.smt.congruence_closure import init.meta.attribute init.meta.simp_tactic open tactic /- Heuristic instantiation lemma -/ meta constant hinst_lemma : Type meta constant hinst_lemmas : Type /- (mk_core m e as_simp), m is used to decide which definitions will be unfolded in patterns. If as_simp is tt, then this tactic will try to use the left-hand-side of the conclusion as a pattern. -/ meta constant hinst_lemma.mk_core : transparency → expr → bool → tactic hinst_lemma meta constant hinst_lemma.mk_from_decl_core : transparency → name → bool → tactic hinst_lemma meta constant hinst_lemma.pp : hinst_lemma → tactic format meta constant hinst_lemma.id : hinst_lemma → name meta instance : has_to_tactic_format hinst_lemma := ⟨hinst_lemma.pp⟩ meta def hinst_lemma.mk (h : expr) : tactic hinst_lemma := hinst_lemma.mk_core reducible h ff meta def hinst_lemma.mk_from_decl (h : name) : tactic hinst_lemma := hinst_lemma.mk_from_decl_core reducible h ff meta constant hinst_lemmas.mk : hinst_lemmas meta constant hinst_lemmas.add : hinst_lemmas → hinst_lemma → hinst_lemmas meta constant hinst_lemmas.fold {α : Type} : hinst_lemmas → α → (hinst_lemma → α → α) → α meta constant hinst_lemmas.merge : hinst_lemmas → hinst_lemmas → hinst_lemmas meta def mk_hinst_singleton : hinst_lemma → hinst_lemmas := hinst_lemmas.add hinst_lemmas.mk meta def hinst_lemmas.pp (s : hinst_lemmas) : tactic format := let tac := s^.fold (return format.nil) (λ h tac, do hpp ← h^.pp, r ← tac, if r^.is_nil then return hpp else return (r ++ to_fmt "," ++ format.line ++ hpp)) in do r ← tac, return $ format.cbrace (format.group r) meta instance : has_to_tactic_format hinst_lemmas := ⟨hinst_lemmas.pp⟩ open tactic private meta def add_lemma (m : transparency) (as_simp : bool) (h : name) (hs : hinst_lemmas) : tactic hinst_lemmas := do h ← hinst_lemma.mk_from_decl_core m h as_simp, return $ hs^.add h meta def to_hinst_lemmas_core (m : transparency) : bool → list name → hinst_lemmas → tactic hinst_lemmas | as_simp [] hs := return hs | as_simp (n::ns) hs := let add n := add_lemma m as_simp n hs >>= to_hinst_lemmas_core as_simp ns in do /- First check if n is the name of a function with equational lemmas associated with it -/ eqns ← tactic.get_eqn_lemmas_for tt n, match eqns with | [] := do /- n is not the name of a function definition or it does not have equational lemmas, then check if it is a lemma -/ add n | _ := do p ← is_prop_decl n, if p then add n /- n is a proposition -/ else do /- Add equational lemmas to resulting hinst_lemmas -/ new_hs ← to_hinst_lemmas_core tt eqns hs, to_hinst_lemmas_core as_simp ns new_hs end meta def mk_hinst_lemma_attr_core (attr_name : name) (as_simp : bool) : command := do let t := ```(caching_user_attribute hinst_lemmas), let b := if as_simp then ```(tt) else ```(ff), v ← to_expr ``({name := %%(quote attr_name), descr := "hinst_lemma attribute", mk_cache := λ ns, to_hinst_lemmas_core reducible %%b ns hinst_lemmas.mk, dependencies := [`reducibility] } : caching_user_attribute hinst_lemmas), add_decl (declaration.defn attr_name [] t v reducibility_hints.abbrev ff), attribute.register attr_name meta def mk_hinst_lemma_attrs_core (as_simp : bool) : list name → command | [] := skip | (n::ns) := (mk_hinst_lemma_attr_core n as_simp >> mk_hinst_lemma_attrs_core ns) <|> (do type ← infer_type (expr.const n []), let expected := ```(caching_user_attribute hinst_lemmas), (is_def_eq type expected <|> fail ("failed to create hinst_lemma attribute '" ++ n^.to_string ++ "', declaration already exists and has different type.")), mk_hinst_lemma_attrs_core ns) meta def merge_hinst_lemma_attrs (m : transparency) (as_simp : bool) : list name → hinst_lemmas → tactic hinst_lemmas | [] hs := return hs | (attr::attrs) hs := do ns ← attribute.get_instances attr, new_hs ← to_hinst_lemmas_core m as_simp ns hs, merge_hinst_lemma_attrs attrs new_hs /-- Create a new "cached" attribute (attr_name : caching_user_attribute hinst_lemmas). It also creates "cached" attributes for each attr_names and simp_attr_names if they have not been defined yet. Moreover, the hinst_lemmas for attr_name will be the union of the lemmas tagged with attr_name, attrs_name, and simp_attr_names. For the ones in simp_attr_names, we use the left-hand-side of the conclusion as the pattern. -/ meta def mk_hinst_lemma_attr_set (attr_name : name) (attr_names : list name) (simp_attr_names : list name) : command := do mk_hinst_lemma_attrs_core ff attr_names, mk_hinst_lemma_attrs_core tt simp_attr_names, let t := ```(caching_user_attribute hinst_lemmas), let l1 := quote attr_names, let l2 := quote simp_attr_names, v ← to_expr ``({name := %%(quote attr_name), descr := "hinst_lemma attribute set", mk_cache := λ ns, let aux1 : list name := %%l1, aux2 : list name := %%l2 in do { hs₁ ← to_hinst_lemmas_core reducible ff ns hinst_lemmas.mk, hs₂ ← merge_hinst_lemma_attrs reducible ff aux1 hs₁, merge_hinst_lemma_attrs reducible tt aux2 hs₂}, dependencies := [`reducibility] ++ %%l1 ++ %%l2 } : caching_user_attribute hinst_lemmas), add_decl (declaration.defn attr_name [] t v reducibility_hints.abbrev ff), attribute.register attr_name meta def get_hinst_lemmas_for_attr (attr_name : name) : tactic hinst_lemmas := do cnst ← return (expr.const attr_name []), attr ← eval_expr (caching_user_attribute hinst_lemmas) cnst, caching_user_attribute.get_cache attr structure ematch_config := (max_instances : nat := 10000) (max_generation : nat := 10) /- Ematching -/ meta constant ematch_state : Type meta constant ematch_state.mk : ematch_config → ematch_state meta constant ematch_state.internalize : ematch_state → expr → tactic ematch_state namespace tactic meta constant ematch_core : transparency → cc_state → ematch_state → hinst_lemma → expr → tactic (list (expr × expr) × cc_state × ematch_state) meta constant ematch_all_core : transparency → cc_state → ematch_state → hinst_lemma → bool → tactic (list (expr × expr) × cc_state × ematch_state) meta def ematch : cc_state → ematch_state → hinst_lemma → expr → tactic (list (expr × expr) × cc_state × ematch_state) := ematch_core reducible meta def ematch_all : cc_state → ematch_state → hinst_lemma → bool → tactic (list (expr × expr) × cc_state × ematch_state) := ematch_all_core reducible end tactic
400fb6f23b818d1f85f49fa8d2e2a05794b1640a
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
/tests/lean/run/t3.lean
cec25fd9db6271fbb76d66e64ba81e342b3b2adc
[ "Apache-2.0" ]
permissive
soonhokong/lean-osx
4a954262c780e404c1369d6c06516161d07fcb40
3670278342d2f4faa49d95b46d86642d7875b47c
refs/heads/master
1,611,410,334,552
1,474,425,686,000
1,474,425,686,000
12,043,103
5
1
null
null
null
null
UTF-8
Lean
false
false
359
lean
prelude constant int : Type.{1} constant nat : Type.{1} namespace int constant plus : int → int → int end int namespace nat constant plus : nat → nat → nat end nat open int nat constants a b : int check plus a b constant f : int → int → int constant g : nat → nat → int notation A `+`:65 B:65 := f A (g B B) constant n : nat check a + n
68f95693a1311562de05b002e3c63f9ea4f3687c
2eab05920d6eeb06665e1a6df77b3157354316ad
/src/group_theory/subgroup/basic.lean
37e094f8af23cda7b081985f96b12aa67e2b3b88
[ "Apache-2.0" ]
permissive
ayush1801/mathlib
78949b9f789f488148142221606bf15c02b960d2
ce164e28f262acbb3de6281b3b03660a9f744e3c
refs/heads/master
1,692,886,907,941
1,635,270,866,000
1,635,270,866,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
98,676
lean
/- Copyright (c) 2020 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import group_theory.submonoid.pointwise import group_theory.submonoid.membership import group_theory.submonoid.center import algebra.group.conj import order.atoms /-! # Subgroups This file defines multiplicative and additive subgroups as an extension of submonoids, in a bundled form (unbundled subgroups are in `deprecated/subgroups.lean`). We prove subgroups of a group form a complete lattice, and results about images and preimages of subgroups under group homomorphisms. The bundled subgroups use bundled monoid homomorphisms. There are also theorems about the subgroups generated by an element or a subset of a group, defined both inductively and as the infimum of the set of subgroups containing a given element/subset. Special thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration. ## Main definitions Notation used here: - `G N` are `group`s - `A` is an `add_group` - `H K` are `subgroup`s of `G` or `add_subgroup`s of `A` - `x` is an element of type `G` or type `A` - `f g : N →* G` are group homomorphisms - `s k` are sets of elements of type `G` Definitions in the file: * `subgroup G` : the type of subgroups of a group `G` * `add_subgroup A` : the type of subgroups of an additive group `A` * `complete_lattice (subgroup G)` : the subgroups of `G` form a complete lattice * `subgroup.closure k` : the minimal subgroup that includes the set `k` * `subgroup.subtype` : the natural group homomorphism from a subgroup of group `G` to `G` * `subgroup.gi` : `closure` forms a Galois insertion with the coercion to set * `subgroup.comap H f` : the preimage of a subgroup `H` along the group homomorphism `f` is also a subgroup * `subgroup.map f H` : the image of a subgroup `H` along the group homomorphism `f` is also a subgroup * `subgroup.prod H K` : the product of subgroups `H`, `K` of groups `G`, `N` respectively, `H × K` is a subgroup of `G × N` * `monoid_hom.range f` : the range of the group homomorphism `f` is a subgroup * `monoid_hom.ker f` : the kernel of a group homomorphism `f` is the subgroup of elements `x : G` such that `f x = 1` * `monoid_hom.eq_locus f g` : given group homomorphisms `f`, `g`, the elements of `G` such that `f x = g x` form a subgroup of `G` * `is_simple_group G` : a class indicating that a group has exactly two normal subgroups ## Implementation notes Subgroup inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as membership of a subgroup's underlying set. ## Tags subgroup, subgroups -/ open_locale big_operators pointwise variables {G : Type*} [group G] variables {A : Type*} [add_group A] set_option old_structure_cmd true /-- A subgroup of a group `G` is a subset containing 1, closed under multiplication and closed under multiplicative inverse. -/ structure subgroup (G : Type*) [group G] extends submonoid G := (inv_mem' {x} : x ∈ carrier → x⁻¹ ∈ carrier) /-- An additive subgroup of an additive group `G` is a subset containing 0, closed under addition and additive inverse. -/ structure add_subgroup (G : Type*) [add_group G] extends add_submonoid G:= (neg_mem' {x} : x ∈ carrier → -x ∈ carrier) attribute [to_additive] subgroup attribute [to_additive add_subgroup.to_add_submonoid] subgroup.to_submonoid /-- Reinterpret a `subgroup` as a `submonoid`. -/ add_decl_doc subgroup.to_submonoid /-- Reinterpret an `add_subgroup` as an `add_submonoid`. -/ add_decl_doc add_subgroup.to_add_submonoid namespace subgroup @[to_additive] instance : set_like (subgroup G) G := ⟨subgroup.carrier, λ p q h, by cases p; cases q; congr'⟩ @[simp, to_additive] lemma mem_carrier {s : subgroup G} {x : G} : x ∈ s.carrier ↔ x ∈ s := iff.rfl @[simp, to_additive] lemma mem_mk {s : set G} {x : G} (h_one) (h_mul) (h_inv) : x ∈ mk s h_one h_mul h_inv ↔ x ∈ s := iff.rfl @[simp, to_additive] lemma coe_set_mk {s : set G} (h_one) (h_mul) (h_inv) : (mk s h_one h_mul h_inv : set G) = s := rfl @[simp, to_additive] lemma mk_le_mk {s t : set G} (h_one) (h_mul) (h_inv) (h_one') (h_mul') (h_inv') : mk s h_one h_mul h_inv ≤ mk t h_one' h_mul' h_inv' ↔ s ⊆ t := iff.rfl /-- See Note [custom simps projection] -/ @[to_additive "See Note [custom simps projection]"] def simps.coe (S : subgroup G) : set G := S initialize_simps_projections subgroup (carrier → coe) initialize_simps_projections add_subgroup (carrier → coe) @[simp, to_additive] lemma coe_to_submonoid (K : subgroup G) : (K.to_submonoid : set G) = K := rfl @[simp, to_additive] lemma mem_to_submonoid (K : subgroup G) (x : G) : x ∈ K.to_submonoid ↔ x ∈ K := iff.rfl @[to_additive] instance (K : subgroup G) [d : decidable_pred (∈ K)] [fintype G] : fintype K := show fintype {g : G // g ∈ K}, from infer_instance @[to_additive] theorem to_submonoid_injective : function.injective (to_submonoid : subgroup G → submonoid G) := λ p q h, set_like.ext'_iff.2 (show _, from set_like.ext'_iff.1 h) @[simp, to_additive] theorem to_submonoid_eq {p q : subgroup G} : p.to_submonoid = q.to_submonoid ↔ p = q := to_submonoid_injective.eq_iff @[to_additive, mono] lemma to_submonoid_strict_mono : strict_mono (to_submonoid : subgroup G → submonoid G) := λ _ _, id attribute [mono] add_subgroup.to_add_submonoid_strict_mono @[to_additive, mono] lemma to_submonoid_mono : monotone (to_submonoid : subgroup G → submonoid G) := to_submonoid_strict_mono.monotone attribute [mono] add_subgroup.to_add_submonoid_mono @[simp, to_additive] lemma to_submonoid_le {p q : subgroup G} : p.to_submonoid ≤ q.to_submonoid ↔ p ≤ q := iff.rfl end subgroup /-! ### Conversion to/from `additive`/`multiplicative` -/ section mul_add /-- Supgroups of a group `G` are isomorphic to additive subgroups of `additive G`. -/ @[simps] def subgroup.to_add_subgroup : subgroup G ≃o add_subgroup (additive G) := { to_fun := λ S, { neg_mem' := S.inv_mem', ..S.to_submonoid.to_add_submonoid }, inv_fun := λ S, { inv_mem' := S.neg_mem', ..S.to_add_submonoid.to_submonoid' }, left_inv := λ x, by cases x; refl, right_inv := λ x, by cases x; refl, map_rel_iff' := λ a b, iff.rfl, } /-- Additive subgroup of an additive group `additive G` are isomorphic to subgroup of `G`. -/ abbreviation add_subgroup.to_subgroup' : add_subgroup (additive G) ≃o subgroup G := subgroup.to_add_subgroup.symm /-- Additive supgroups of an additive group `A` are isomorphic to subgroups of `multiplicative A`. -/ @[simps] def add_subgroup.to_subgroup : add_subgroup A ≃o subgroup (multiplicative A) := { to_fun := λ S, { inv_mem' := S.neg_mem', ..S.to_add_submonoid.to_submonoid }, inv_fun := λ S, { neg_mem' := S.inv_mem', ..S.to_submonoid.to_add_submonoid' }, left_inv := λ x, by cases x; refl, right_inv := λ x, by cases x; refl, map_rel_iff' := λ a b, iff.rfl, } /-- Subgroups of an additive group `multiplicative A` are isomorphic to additive subgroups of `A`. -/ abbreviation subgroup.to_add_subgroup' : subgroup (multiplicative A) ≃o add_subgroup A := add_subgroup.to_subgroup.symm end mul_add namespace subgroup variables (H K : subgroup G) /-- Copy of a subgroup with a new `carrier` equal to the old one. Useful to fix definitional equalities.-/ @[to_additive "Copy of an additive subgroup with a new `carrier` equal to the old one. Useful to fix definitional equalities"] protected def copy (K : subgroup G) (s : set G) (hs : s = K) : subgroup G := { carrier := s, one_mem' := hs.symm ▸ K.one_mem', mul_mem' := hs.symm ▸ K.mul_mem', inv_mem' := hs.symm ▸ K.inv_mem' } @[simp] lemma coe_copy (K : subgroup G) (s : set G) (hs : s = ↑K) : (K.copy s hs : set G) = s := rfl lemma copy_eq (K : subgroup G) (s : set G) (hs : s = ↑K) : K.copy s hs = K := set_like.coe_injective hs /-- Two subgroups are equal if they have the same elements. -/ @[ext, to_additive "Two `add_subgroup`s are equal if they have the same elements."] theorem ext {H K : subgroup G} (h : ∀ x, x ∈ H ↔ x ∈ K) : H = K := set_like.ext h /-- A subgroup contains the group's 1. -/ @[to_additive "An `add_subgroup` contains the group's 0."] theorem one_mem : (1 : G) ∈ H := H.one_mem' /-- A subgroup is closed under multiplication. -/ @[to_additive "An `add_subgroup` is closed under addition."] theorem mul_mem {x y : G} : x ∈ H → y ∈ H → x * y ∈ H := λ hx hy, H.mul_mem' hx hy /-- A subgroup is closed under inverse. -/ @[to_additive "An `add_subgroup` is closed under inverse."] theorem inv_mem {x : G} : x ∈ H → x⁻¹ ∈ H := λ hx, H.inv_mem' hx /-- A subgroup is closed under division. -/ @[to_additive "An `add_subgroup` is closed under subtraction."] theorem div_mem {x y : G} (hx : x ∈ H) (hy : y ∈ H) : x / y ∈ H := by simpa only [div_eq_mul_inv] using H.mul_mem' hx (H.inv_mem' hy) @[simp, to_additive] theorem inv_mem_iff {x : G} : x⁻¹ ∈ H ↔ x ∈ H := ⟨λ h, inv_inv x ▸ H.inv_mem h, H.inv_mem⟩ @[to_additive] lemma div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H := by rw [← H.inv_mem_iff, div_eq_mul_inv, div_eq_mul_inv, mul_inv_rev, inv_inv] @[simp, to_additive] theorem inv_coe_set : (H : set G)⁻¹ = H := by { ext, simp, } @[simp, to_additive] lemma exists_inv_mem_iff_exists_mem (K : subgroup G) {P : G → Prop} : (∃ (x : G), x ∈ K ∧ P x⁻¹) ↔ ∃ x ∈ K, P x := by split; { rintros ⟨x, x_in, hx⟩, exact ⟨x⁻¹, inv_mem K x_in, by simp [hx]⟩ } @[to_additive] lemma mul_mem_cancel_right {x y : G} (h : x ∈ H) : y * x ∈ H ↔ y ∈ H := ⟨λ hba, by simpa using H.mul_mem hba (H.inv_mem h), λ hb, H.mul_mem hb h⟩ @[to_additive] lemma mul_mem_cancel_left {x y : G} (h : x ∈ H) : x * y ∈ H ↔ y ∈ H := ⟨λ hab, by simpa using H.mul_mem (H.inv_mem h) hab, H.mul_mem h⟩ /-- Product of a list of elements in a subgroup is in the subgroup. -/ @[to_additive "Sum of a list of elements in an `add_subgroup` is in the `add_subgroup`."] lemma list_prod_mem {l : list G} : (∀ x ∈ l, x ∈ K) → l.prod ∈ K := K.to_submonoid.list_prod_mem /-- Product of a multiset of elements in a subgroup of a `comm_group` is in the subgroup. -/ @[to_additive "Sum of a multiset of elements in an `add_subgroup` of an `add_comm_group` is in the `add_subgroup`."] lemma multiset_prod_mem {G} [comm_group G] (K : subgroup G) (g : multiset G) : (∀ a ∈ g, a ∈ K) → g.prod ∈ K := K.to_submonoid.multiset_prod_mem g /-- Product of elements of a subgroup of a `comm_group` indexed by a `finset` is in the subgroup. -/ @[to_additive "Sum of elements in an `add_subgroup` of an `add_comm_group` indexed by a `finset` is in the `add_subgroup`."] lemma prod_mem {G : Type*} [comm_group G] (K : subgroup G) {ι : Type*} {t : finset ι} {f : ι → G} (h : ∀ c ∈ t, f c ∈ K) : ∏ c in t, f c ∈ K := K.to_submonoid.prod_mem h @[to_additive add_subgroup.nsmul_mem] lemma pow_mem {x : G} (hx : x ∈ K) : ∀ n : ℕ, x ^ n ∈ K := K.to_submonoid.pow_mem hx @[to_additive] lemma gpow_mem {x : G} (hx : x ∈ K) : ∀ n : ℤ, x ^ n ∈ K | (n : ℕ) := by { rw [gpow_coe_nat], exact pow_mem _ hx n } | -[1+ n] := by { rw [gpow_neg_succ_of_nat], exact K.inv_mem (K.pow_mem hx n.succ) } /-- Construct a subgroup from a nonempty set that is closed under division. -/ @[to_additive "Construct a subgroup from a nonempty set that is closed under subtraction"] def of_div (s : set G) (hsn : s.nonempty) (hs : ∀ x y ∈ s, x * y⁻¹ ∈ s) : subgroup G := have one_mem : (1 : G) ∈ s, from let ⟨x, hx⟩ := hsn in by simpa using hs x x hx hx, have inv_mem : ∀ x, x ∈ s → x⁻¹ ∈ s, from λ x hx, by simpa using hs 1 x one_mem hx, { carrier := s, one_mem' := one_mem, inv_mem' := inv_mem, mul_mem' := λ x y hx hy, by simpa using hs x y⁻¹ hx (inv_mem y hy) } /-- A subgroup of a group inherits a multiplication. -/ @[to_additive "An `add_subgroup` of an `add_group` inherits an addition."] instance has_mul : has_mul H := H.to_submonoid.has_mul /-- A subgroup of a group inherits a 1. -/ @[to_additive "An `add_subgroup` of an `add_group` inherits a zero."] instance has_one : has_one H := H.to_submonoid.has_one /-- A subgroup of a group inherits an inverse. -/ @[to_additive "A `add_subgroup` of a `add_group` inherits an inverse."] instance has_inv : has_inv H := ⟨λ a, ⟨a⁻¹, H.inv_mem a.2⟩⟩ /-- A subgroup of a group inherits a division -/ @[to_additive "An `add_subgroup` of an `add_group` inherits a subtraction."] instance has_div : has_div H := ⟨λ a b, ⟨a / b, H.div_mem a.2 b.2⟩⟩ @[simp, norm_cast, to_additive] lemma coe_mul (x y : H) : (↑(x * y) : G) = ↑x * ↑y := rfl @[simp, norm_cast, to_additive] lemma coe_one : ((1 : H) : G) = 1 := rfl @[simp, norm_cast, to_additive] lemma coe_inv (x : H) : ↑(x⁻¹ : H) = (x⁻¹ : G) := rfl @[simp, norm_cast, to_additive] lemma coe_div (x y : H) : (↑(x / y) : G) = ↑x / ↑y := rfl @[simp, norm_cast, to_additive] lemma coe_mk (x : G) (hx : x ∈ H) : ((⟨x, hx⟩ : H) : G) = x := rfl /-- A subgroup of a group inherits a group structure. -/ @[to_additive "An `add_subgroup` of an `add_group` inherits an `add_group` structure."] instance to_group {G : Type*} [group G] (H : subgroup G) : group H := subtype.coe_injective.group _ rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl) /-- A subgroup of a `comm_group` is a `comm_group`. -/ @[to_additive "An `add_subgroup` of an `add_comm_group` is an `add_comm_group`."] instance to_comm_group {G : Type*} [comm_group G] (H : subgroup G) : comm_group H := subtype.coe_injective.comm_group _ rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl) /-- A subgroup of an `ordered_comm_group` is an `ordered_comm_group`. -/ @[to_additive "An `add_subgroup` of an `add_ordered_comm_group` is an `add_ordered_comm_group`."] instance to_ordered_comm_group {G : Type*} [ordered_comm_group G] (H : subgroup G) : ordered_comm_group H := subtype.coe_injective.ordered_comm_group _ rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl) /-- A subgroup of a `linear_ordered_comm_group` is a `linear_ordered_comm_group`. -/ @[to_additive "An `add_subgroup` of a `linear_ordered_add_comm_group` is a `linear_ordered_add_comm_group`."] instance to_linear_ordered_comm_group {G : Type*} [linear_ordered_comm_group G] (H : subgroup G) : linear_ordered_comm_group H := subtype.coe_injective.linear_ordered_comm_group _ rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl) /-- The natural group hom from a subgroup of group `G` to `G`. -/ @[to_additive "The natural group hom from an `add_subgroup` of `add_group` `G` to `G`."] def subtype : H →* G := ⟨coe, rfl, λ _ _, rfl⟩ @[simp, to_additive] theorem coe_subtype : ⇑H.subtype = coe := rfl @[simp, norm_cast] lemma coe_pow (x : H) (n : ℕ) : ((x ^ n : H) : G) = x ^ n := coe_subtype H ▸ monoid_hom.map_pow _ _ _ @[simp, norm_cast] lemma coe_gpow (x : H) (n : ℤ) : ((x ^ n : H) : G) = x ^ n := coe_subtype H ▸ monoid_hom.map_gpow _ _ _ /-- The inclusion homomorphism from a subgroup `H` contained in `K` to `K`. -/ @[to_additive "The inclusion homomorphism from a additive subgroup `H` contained in `K` to `K`."] def inclusion {H K : subgroup G} (h : H ≤ K) : H →* K := monoid_hom.mk' (λ x, ⟨x, h x.prop⟩) (λ ⟨a, ha⟩ ⟨b, hb⟩, rfl) @[simp, to_additive] lemma coe_inclusion {H K : subgroup G} {h : H ≤ K} (a : H) : (inclusion h a : G) = a := by { cases a, simp only [inclusion, coe_mk, monoid_hom.mk'_apply] } @[simp, to_additive] lemma subtype_comp_inclusion {H K : subgroup G} (hH : H ≤ K) : K.subtype.comp (inclusion hH) = H.subtype := by { ext, simp } /-- The subgroup `G` of the group `G`. -/ @[to_additive "The `add_subgroup G` of the `add_group G`."] instance : has_top (subgroup G) := ⟨{ inv_mem' := λ _ _, set.mem_univ _ , .. (⊤ : submonoid G) }⟩ /-- The trivial subgroup `{1}` of an group `G`. -/ @[to_additive "The trivial `add_subgroup` `{0}` of an `add_group` `G`."] instance : has_bot (subgroup G) := ⟨{ inv_mem' := λ _, by simp *, .. (⊥ : submonoid G) }⟩ @[to_additive] instance : inhabited (subgroup G) := ⟨⊥⟩ @[simp, to_additive] lemma mem_bot {x : G} : x ∈ (⊥ : subgroup G) ↔ x = 1 := iff.rfl @[simp, to_additive] lemma mem_top (x : G) : x ∈ (⊤ : subgroup G) := set.mem_univ x @[simp, to_additive] lemma coe_top : ((⊤ : subgroup G) : set G) = set.univ := rfl @[simp, to_additive] lemma coe_bot : ((⊥ : subgroup G) : set G) = {1} := rfl @[to_additive] instance : unique (⊥ : subgroup G) := ⟨⟨1⟩, λ g, subtype.ext g.2⟩ @[to_additive] lemma eq_bot_iff_forall : H = ⊥ ↔ ∀ x ∈ H, x = (1 : G) := begin rw set_like.ext'_iff, simp only [coe_bot, set.eq_singleton_iff_unique_mem, set_like.mem_coe, H.one_mem, true_and], end @[to_additive] lemma eq_bot_of_subsingleton [subsingleton H] : H = ⊥ := begin rw subgroup.eq_bot_iff_forall, intros y hy, rw [← subgroup.coe_mk H y hy, subsingleton.elim (⟨y, hy⟩ : H) 1, subgroup.coe_one], end @[to_additive] instance fintype_bot : fintype (⊥ : subgroup G) := ⟨{1}, by {rintro ⟨x, ⟨hx⟩⟩, exact finset.mem_singleton_self _}⟩ /- curly brackets `{}` are used here instead of instance brackets `[]` because the instance in a goal is often not the same as the one inferred by type class inference. -/ @[simp, to_additive] lemma card_bot {_ : fintype ↥(⊥ : subgroup G)} : fintype.card (⊥ : subgroup G) = 1 := fintype.card_eq_one_iff.2 ⟨⟨(1 : G), set.mem_singleton 1⟩, λ ⟨y, hy⟩, subtype.eq $ subgroup.mem_bot.1 hy⟩ @[to_additive] lemma eq_top_of_card_eq [fintype H] [fintype G] (h : fintype.card H = fintype.card G) : H = ⊤ := begin haveI : fintype (H : set G) := ‹fintype H›, rw [set_like.ext'_iff, coe_top, ← finset.coe_univ, ← (H : set G).coe_to_finset, finset.coe_inj, ← finset.card_eq_iff_eq_univ, ← h, set.to_finset_card], congr end @[to_additive] lemma eq_top_of_le_card [fintype H] [fintype G] (h : fintype.card G ≤ fintype.card H) : H = ⊤ := eq_top_of_card_eq H (le_antisymm (fintype.card_le_of_injective coe subtype.coe_injective) h) @[to_additive] lemma eq_bot_of_card_le [fintype H] (h : fintype.card H ≤ 1) : H = ⊥ := let _ := fintype.card_le_one_iff_subsingleton.mp h in by exactI eq_bot_of_subsingleton H @[to_additive] lemma eq_bot_of_card_eq [fintype H] (h : fintype.card H = 1) : H = ⊥ := H.eq_bot_of_card_le (le_of_eq h) @[to_additive] lemma nontrivial_iff_exists_ne_one (H : subgroup G) : nontrivial H ↔ ∃ x ∈ H, x ≠ (1:G) := subtype.nontrivial_iff_exists_ne (λ x, x ∈ H) (1 : H) /-- A subgroup is either the trivial subgroup or nontrivial. -/ @[to_additive] lemma bot_or_nontrivial (H : subgroup G) : H = ⊥ ∨ nontrivial H := begin classical, by_cases h : ∀ x ∈ H, x = (1 : G), { left, exact H.eq_bot_iff_forall.mpr h }, { right, simp only [not_forall] at h, simpa only [nontrivial_iff_exists_ne_one] } end /-- A subgroup is either the trivial subgroup or contains a nonzero element. -/ @[to_additive] lemma bot_or_exists_ne_one (H : subgroup G) : H = ⊥ ∨ ∃ x ∈ H, x ≠ (1:G) := begin convert H.bot_or_nontrivial, rw nontrivial_iff_exists_ne_one end @[to_additive] lemma card_le_one_iff_eq_bot [fintype H] : fintype.card H ≤ 1 ↔ H = ⊥ := ⟨λ h, (eq_bot_iff_forall _).2 (λ x hx, by simpa [subtype.ext_iff] using fintype.card_le_one_iff.1 h ⟨x, hx⟩ 1), λ h, by simp [h]⟩ @[to_additive] lemma one_lt_card_iff_ne_bot [fintype H] : 1 < fintype.card H ↔ H ≠ ⊥ := lt_iff_not_ge'.trans (not_iff_not.mpr H.card_le_one_iff_eq_bot) /-- The inf of two subgroups is their intersection. -/ @[to_additive "The inf of two `add_subgroups`s is their intersection."] instance : has_inf (subgroup G) := ⟨λ H₁ H₂, { inv_mem' := λ _ ⟨hx, hx'⟩, ⟨H₁.inv_mem hx, H₂.inv_mem hx'⟩, .. H₁.to_submonoid ⊓ H₂.to_submonoid }⟩ @[simp, to_additive] lemma coe_inf (p p' : subgroup G) : ((p ⊓ p' : subgroup G) : set G) = p ∩ p' := rfl @[simp, to_additive] lemma mem_inf {p p' : subgroup G} {x : G} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := iff.rfl @[to_additive] instance : has_Inf (subgroup G) := ⟨λ s, { inv_mem' := λ x hx, set.mem_bInter $ λ i h, i.inv_mem (by apply set.mem_bInter_iff.1 hx i h), .. (⨅ S ∈ s, subgroup.to_submonoid S).copy (⋂ S ∈ s, ↑S) (by simp) }⟩ @[simp, norm_cast, to_additive] lemma coe_Inf (H : set (subgroup G)) : ((Inf H : subgroup G) : set G) = ⋂ s ∈ H, ↑s := rfl @[simp, to_additive] lemma mem_Inf {S : set (subgroup G)} {x : G} : x ∈ Inf S ↔ ∀ p ∈ S, x ∈ p := set.mem_bInter_iff @[to_additive] lemma mem_infi {ι : Sort*} {S : ι → subgroup G} {x : G} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [infi, mem_Inf, set.forall_range_iff] @[simp, norm_cast, to_additive] lemma coe_infi {ι : Sort*} {S : ι → subgroup G} : (↑(⨅ i, S i) : set G) = ⋂ i, S i := by simp only [infi, coe_Inf, set.bInter_range] /-- Subgroups of a group form a complete lattice. -/ @[to_additive "The `add_subgroup`s of an `add_group` form a complete lattice."] instance : complete_lattice (subgroup G) := { bot := (⊥), bot_le := λ S x hx, (mem_bot.1 hx).symm ▸ S.one_mem, top := (⊤), le_top := λ S x hx, mem_top x, inf := (⊓), le_inf := λ a b c ha hb x hx, ⟨ha hx, hb hx⟩, inf_le_left := λ a b x, and.left, inf_le_right := λ a b x, and.right, .. complete_lattice_of_Inf (subgroup G) $ λ s, is_glb.of_image (λ H K, show (H : set G) ≤ K ↔ H ≤ K, from set_like.coe_subset_coe) is_glb_binfi } @[to_additive] lemma mem_sup_left {S T : subgroup G} : ∀ {x : G}, x ∈ S → x ∈ S ⊔ T := show S ≤ S ⊔ T, from le_sup_left @[to_additive] lemma mem_sup_right {S T : subgroup G} : ∀ {x : G}, x ∈ T → x ∈ S ⊔ T := show T ≤ S ⊔ T, from le_sup_right @[to_additive] lemma mem_supr_of_mem {ι : Type*} {S : ι → subgroup G} (i : ι) : ∀ {x : G}, x ∈ S i → x ∈ supr S := show S i ≤ supr S, from le_supr _ _ @[to_additive] lemma mem_Sup_of_mem {S : set (subgroup G)} {s : subgroup G} (hs : s ∈ S) : ∀ {x : G}, x ∈ s → x ∈ Sup S := show s ≤ Sup S, from le_Sup hs @[simp, to_additive] lemma subsingleton_iff : subsingleton (subgroup G) ↔ subsingleton G := ⟨ λ h, by exactI ⟨λ x y, have ∀ i : G, i = 1 := λ i, mem_bot.mp $ subsingleton.elim (⊤ : subgroup G) ⊥ ▸ mem_top i, (this x).trans (this y).symm⟩, λ h, by exactI ⟨λ x y, subgroup.ext $ λ i, subsingleton.elim 1 i ▸ by simp [subgroup.one_mem]⟩⟩ @[simp, to_additive] lemma nontrivial_iff : nontrivial (subgroup G) ↔ nontrivial G := not_iff_not.mp ( (not_nontrivial_iff_subsingleton.trans subsingleton_iff).trans not_nontrivial_iff_subsingleton.symm) @[to_additive] instance [subsingleton G] : unique (subgroup G) := ⟨⟨⊥⟩, λ a, @subsingleton.elim _ (subsingleton_iff.mpr ‹_›) a _⟩ @[to_additive] instance [nontrivial G] : nontrivial (subgroup G) := nontrivial_iff.mpr ‹_› @[to_additive] lemma eq_top_iff' : H = ⊤ ↔ ∀ x : G, x ∈ H := eq_top_iff.trans ⟨λ h m, h $ mem_top m, λ h m _, h m⟩ /-- The `subgroup` generated by a set. -/ @[to_additive "The `add_subgroup` generated by a set"] def closure (k : set G) : subgroup G := Inf {K | k ⊆ K} variable {k : set G} @[to_additive] lemma mem_closure {x : G} : x ∈ closure k ↔ ∀ K : subgroup G, k ⊆ K → x ∈ K := mem_Inf /-- The subgroup generated by a set includes the set. -/ @[simp, to_additive "The `add_subgroup` generated by a set includes the set."] lemma subset_closure : k ⊆ closure k := λ x hx, mem_closure.2 $ λ K hK, hK hx @[to_additive] lemma not_mem_of_not_mem_closure {P : G} (hP : P ∉ closure k) : P ∉ k := λ h, hP (subset_closure h) open set /-- A subgroup `K` includes `closure k` if and only if it includes `k`. -/ @[simp, to_additive "An additive subgroup `K` includes `closure k` if and only if it includes `k`"] lemma closure_le : closure k ≤ K ↔ k ⊆ K := ⟨subset.trans subset_closure, λ h, Inf_le h⟩ @[to_additive] lemma closure_eq_of_le (h₁ : k ⊆ K) (h₂ : K ≤ closure k) : closure k = K := le_antisymm ((closure_le $ K).2 h₁) h₂ /-- An induction principle for closure membership. If `p` holds for `1` and all elements of `k`, and is preserved under multiplication and inverse, then `p` holds for all elements of the closure of `k`. -/ @[elab_as_eliminator, to_additive "An induction principle for additive closure membership. If `p` holds for `0` and all elements of `k`, and is preserved under addition and inverses, then `p` holds for all elements of the additive closure of `k`."] lemma closure_induction {p : G → Prop} {x} (h : x ∈ closure k) (Hk : ∀ x ∈ k, p x) (H1 : p 1) (Hmul : ∀ x y, p x → p y → p (x * y)) (Hinv : ∀ x, p x → p x⁻¹) : p x := (@closure_le _ _ ⟨p, H1, Hmul, Hinv⟩ _).2 Hk h /-- An induction principle on elements of the subtype `subgroup.closure`. If `p` holds for `1` and all elements of `k`, and is preserved under multiplication and inverse, then `p` holds for all elements `x : closure k`. The difference with `subgroup.closure_induction` is that this acts on the subtype. -/ @[elab_as_eliminator, to_additive "An induction principle on elements of the subtype `add_subgroup.closure`. If `p` holds for `0` and all elements of `k`, and is preserved under addition and negation, then `p` holds for all elements `x : closure k`. The difference with `add_subgroup.closure_induction` is that this acts on the subtype."] lemma closure_induction' (k : set G) {p : closure k → Prop} (Hk : ∀ x (h : x ∈ k), p ⟨x, subset_closure h⟩) (H1 : p 1) (Hmul : ∀ x y, p x → p y → p (x * y)) (Hinv : ∀ x, p x → p x⁻¹) (x : closure k) : p x := subtype.rec_on x $ λ x hx, begin refine exists.elim _ (λ (hx : x ∈ closure k) (hc : p ⟨x, hx⟩), hc), exact closure_induction hx (λ x hx, ⟨subset_closure hx, Hk x hx⟩) ⟨one_mem _, H1⟩ (λ x y hx hy, exists.elim hx $ λ hx' hx, exists.elim hy $ λ hy' hy, ⟨mul_mem _ hx' hy', Hmul _ _ hx hy⟩) (λ x hx, exists.elim hx $ λ hx' hx, ⟨inv_mem _ hx', Hinv _ hx⟩), end variable (G) /-- `closure` forms a Galois insertion with the coercion to set. -/ @[to_additive "`closure` forms a Galois insertion with the coercion to set."] protected def gi : galois_insertion (@closure G _) coe := { choice := λ s _, closure s, gc := λ s t, @closure_le _ _ t s, le_l_u := λ s, subset_closure, choice_eq := λ s h, rfl } variable {G} /-- Subgroup closure of a set is monotone in its argument: if `h ⊆ k`, then `closure h ≤ closure k`. -/ @[to_additive "Additive subgroup closure of a set is monotone in its argument: if `h ⊆ k`, then `closure h ≤ closure k`"] lemma closure_mono ⦃h k : set G⦄ (h' : h ⊆ k) : closure h ≤ closure k := (subgroup.gi G).gc.monotone_l h' /-- Closure of a subgroup `K` equals `K`. -/ @[simp, to_additive "Additive closure of an additive subgroup `K` equals `K`"] lemma closure_eq : closure (K : set G) = K := (subgroup.gi G).l_u_eq K @[simp, to_additive] lemma closure_empty : closure (∅ : set G) = ⊥ := (subgroup.gi G).gc.l_bot @[simp, to_additive] lemma closure_univ : closure (univ : set G) = ⊤ := @coe_top G _ ▸ closure_eq ⊤ @[to_additive] lemma closure_union (s t : set G) : closure (s ∪ t) = closure s ⊔ closure t := (subgroup.gi G).gc.l_sup @[to_additive] lemma closure_Union {ι} (s : ι → set G) : closure (⋃ i, s i) = ⨆ i, closure (s i) := (subgroup.gi G).gc.l_supr @[to_additive] lemma closure_eq_bot_iff (G : Type*) [group G] (S : set G) : closure S = ⊥ ↔ S ⊆ {1} := by { rw [← le_bot_iff], exact closure_le _} /-- The subgroup generated by an element of a group equals the set of integer number powers of the element. -/ lemma mem_closure_singleton {x y : G} : y ∈ closure ({x} : set G) ↔ ∃ n : ℤ, x ^ n = y := begin refine ⟨λ hy, closure_induction hy _ _ _ _, λ ⟨n, hn⟩, hn ▸ gpow_mem _ (subset_closure $ mem_singleton x) n⟩, { intros y hy, rw [eq_of_mem_singleton hy], exact ⟨1, gpow_one x⟩ }, { exact ⟨0, gpow_zero x⟩ }, { rintros _ _ ⟨n, rfl⟩ ⟨m, rfl⟩, exact ⟨n + m, gpow_add x n m⟩ }, rintros _ ⟨n, rfl⟩, exact ⟨-n, gpow_neg x n⟩ end lemma closure_singleton_one : closure ({1} : set G) = ⊥ := by simp [eq_bot_iff_forall, mem_closure_singleton] @[simp, to_additive] lemma inv_subset_closure (S : set G) : S⁻¹ ⊆ closure S := begin intros s hs, rw [set_like.mem_coe, ←subgroup.inv_mem_iff], exact subset_closure (mem_inv.mp hs), end @[simp, to_additive] lemma closure_inv (S : set G) : closure S⁻¹ = closure S := begin refine le_antisymm ((subgroup.closure_le _).2 _) ((subgroup.closure_le _).2 _), { exact inv_subset_closure S }, { simpa only [set.inv_inv] using inv_subset_closure S⁻¹ }, end @[to_additive] lemma closure_to_submonoid (S : set G) : (closure S).to_submonoid = submonoid.closure (S ∪ S⁻¹) := begin refine le_antisymm _ (submonoid.closure_le.2 _), { intros x hx, refine closure_induction hx (λ x hx, submonoid.closure_mono (subset_union_left S S⁻¹) (submonoid.subset_closure hx)) (submonoid.one_mem _) (λ x y hx hy, submonoid.mul_mem _ hx hy) (λ x hx, _), rwa [←submonoid.mem_closure_inv, set.union_inv, set.inv_inv, set.union_comm] }, { simp only [true_and, coe_to_submonoid, union_subset_iff, subset_closure, inv_subset_closure] } end /-- An induction principle for closure membership. If `p` holds for `1` and all elements of `k` and their inverse, and is preserved under multiplication, then `p` holds for all elements of the closure of `k`. -/ @[to_additive "An induction principle for additive closure membership. If `p` holds for `0` and all elements of `k` and their negation, and is preserved under addition, then `p` holds for all elements of the additive closure of `k`."] lemma closure_induction'' {p : G → Prop} {x} (h : x ∈ closure k) (Hk : ∀ x ∈ k, p x) (Hk_inv : ∀ x ∈ k, p x⁻¹) (H1 : p 1) (Hmul : ∀ x y, p x → p y → p (x * y)) : p x := begin rw [← mem_to_submonoid, closure_to_submonoid k] at h, refine submonoid.closure_induction h (λ x hx, _) H1 (λ x y hx hy, Hmul x y hx hy), { rw [mem_union, mem_inv] at hx, cases hx with mem invmem, { exact Hk x mem }, { rw [← inv_inv x], exact Hk_inv _ invmem } }, end @[to_additive] lemma mem_supr_of_directed {ι} [hι : nonempty ι] {K : ι → subgroup G} (hK : directed (≤) K) {x : G} : x ∈ (supr K : subgroup G) ↔ ∃ i, x ∈ K i := begin refine ⟨_, λ ⟨i, hi⟩, (set_like.le_def.1 $ le_supr K i) hi⟩, suffices : x ∈ closure (⋃ i, (K i : set G)) → ∃ i, x ∈ K i, by simpa only [closure_Union, closure_eq (K _)] using this, refine (λ hx, closure_induction hx (λ _, mem_Union.1) _ _ _), { exact hι.elim (λ i, ⟨i, (K i).one_mem⟩) }, { rintros x y ⟨i, hi⟩ ⟨j, hj⟩, rcases hK i j with ⟨k, hki, hkj⟩, exact ⟨k, (K k).mul_mem (hki hi) (hkj hj)⟩ }, rintros _ ⟨i, hi⟩, exact ⟨i, inv_mem (K i) hi⟩ end @[to_additive] lemma coe_supr_of_directed {ι} [nonempty ι] {S : ι → subgroup G} (hS : directed (≤) S) : ((⨆ i, S i : subgroup G) : set G) = ⋃ i, ↑(S i) := set.ext $ λ x, by simp [mem_supr_of_directed hS] @[to_additive] lemma mem_Sup_of_directed_on {K : set (subgroup G)} (Kne : K.nonempty) (hK : directed_on (≤) K) {x : G} : x ∈ Sup K ↔ ∃ s ∈ K, x ∈ s := begin haveI : nonempty K := Kne.to_subtype, simp only [Sup_eq_supr', mem_supr_of_directed hK.directed_coe, set_coe.exists, subtype.coe_mk] end variables {N : Type*} [group N] {P : Type*} [group P] /-- The preimage of a subgroup along a monoid homomorphism is a subgroup. -/ @[to_additive "The preimage of an `add_subgroup` along an `add_monoid` homomorphism is an `add_subgroup`."] def comap {N : Type*} [group N] (f : G →* N) (H : subgroup N) : subgroup G := { carrier := (f ⁻¹' H), inv_mem' := λ a ha, show f a⁻¹ ∈ H, by rw f.map_inv; exact H.inv_mem ha, .. H.to_submonoid.comap f } @[simp, to_additive] lemma coe_comap (K : subgroup N) (f : G →* N) : (K.comap f : set G) = f ⁻¹' K := rfl @[simp, to_additive] lemma mem_comap {K : subgroup N} {f : G →* N} {x : G} : x ∈ K.comap f ↔ f x ∈ K := iff.rfl @[to_additive] lemma comap_mono {f : G →* N} {K K' : subgroup N} : K ≤ K' → comap f K ≤ comap f K' := preimage_mono @[to_additive] lemma comap_comap (K : subgroup P) (g : N →* P) (f : G →* N) : (K.comap g).comap f = K.comap (g.comp f) := rfl /-- The image of a subgroup along a monoid homomorphism is a subgroup. -/ @[to_additive "The image of an `add_subgroup` along an `add_monoid` homomorphism is an `add_subgroup`."] def map (f : G →* N) (H : subgroup G) : subgroup N := { carrier := (f '' H), inv_mem' := by { rintros _ ⟨x, hx, rfl⟩, exact ⟨x⁻¹, H.inv_mem hx, f.map_inv x⟩ }, .. H.to_submonoid.map f } @[simp, to_additive] lemma coe_map (f : G →* N) (K : subgroup G) : (K.map f : set N) = f '' K := rfl @[simp, to_additive] lemma mem_map {f : G →* N} {K : subgroup G} {y : N} : y ∈ K.map f ↔ ∃ x ∈ K, f x = y := mem_image_iff_bex @[to_additive] lemma mem_map_of_mem (f : G →* N) {K : subgroup G} {x : G} (hx : x ∈ K) : f x ∈ K.map f := mem_image_of_mem f hx @[to_additive] lemma apply_coe_mem_map (f : G →* N) (K : subgroup G) (x : K) : f x ∈ K.map f := mem_map_of_mem f x.prop @[to_additive] lemma map_mono {f : G →* N} {K K' : subgroup G} : K ≤ K' → map f K ≤ map f K' := image_subset _ @[simp, to_additive] lemma map_id : K.map (monoid_hom.id G) = K := set_like.coe_injective $ image_id _ @[to_additive] lemma map_map (g : N →* P) (f : G →* N) : (K.map f).map g = K.map (g.comp f) := set_like.coe_injective $ image_image _ _ _ @[to_additive] lemma mem_map_equiv {f : G ≃* N} {K : subgroup G} {x : N} : x ∈ K.map f.to_monoid_hom ↔ f.symm x ∈ K := @set.mem_image_equiv _ _ ↑K f.to_equiv x @[to_additive] lemma mem_map_iff_mem {f : G →* N} (hf : function.injective f) {K : subgroup G} {x : G} : f x ∈ K.map f ↔ x ∈ K := hf.mem_set_image @[to_additive] lemma map_equiv_eq_comap_symm (f : G ≃* N) (K : subgroup G) : K.map f.to_monoid_hom = K.comap f.symm.to_monoid_hom := set_like.coe_injective (f.to_equiv.image_eq_preimage K) @[to_additive] lemma comap_equiv_eq_map_symm (f : N ≃* G) (K : subgroup G) : K.comap f.to_monoid_hom = K.map f.symm.to_monoid_hom := (map_equiv_eq_comap_symm f.symm K).symm @[to_additive] lemma map_le_iff_le_comap {f : G →* N} {K : subgroup G} {H : subgroup N} : K.map f ≤ H ↔ K ≤ H.comap f := image_subset_iff @[to_additive] lemma gc_map_comap (f : G →* N) : galois_connection (map f) (comap f) := λ _ _, map_le_iff_le_comap @[to_additive] lemma map_sup (H K : subgroup G) (f : G →* N) : (H ⊔ K).map f = H.map f ⊔ K.map f := (gc_map_comap f).l_sup @[to_additive] lemma map_supr {ι : Sort*} (f : G →* N) (s : ι → subgroup G) : (supr s).map f = ⨆ i, (s i).map f := (gc_map_comap f).l_supr @[to_additive] lemma comap_sup_comap_le (H K : subgroup N) (f : G →* N) : comap f H ⊔ comap f K ≤ comap f (H ⊔ K) := monotone.le_map_sup (λ _ _, comap_mono) H K @[to_additive] lemma supr_comap_le {ι : Sort*} (f : G →* N) (s : ι → subgroup N) : (⨆ i, (s i).comap f) ≤ (supr s).comap f := monotone.le_map_supr (λ _ _, comap_mono) @[to_additive] lemma comap_inf (H K : subgroup N) (f : G →* N) : (H ⊓ K).comap f = H.comap f ⊓ K.comap f := (gc_map_comap f).u_inf @[to_additive] lemma comap_infi {ι : Sort*} (f : G →* N) (s : ι → subgroup N) : (infi s).comap f = ⨅ i, (s i).comap f := (gc_map_comap f).u_infi @[to_additive] lemma map_inf_le (H K : subgroup G) (f : G →* N) : map f (H ⊓ K) ≤ map f H ⊓ map f K := le_inf (map_mono inf_le_left) (map_mono inf_le_right) @[to_additive] lemma map_inf_eq (H K : subgroup G) (f : G →* N) (hf : function.injective f) : map f (H ⊓ K) = map f H ⊓ map f K := begin rw ← set_like.coe_set_eq, simp [set.image_inter hf], end @[simp, to_additive] lemma map_bot (f : G →* N) : (⊥ : subgroup G).map f = ⊥ := (gc_map_comap f).l_bot @[simp, to_additive] lemma comap_top (f : G →* N) : (⊤ : subgroup N).comap f = ⊤ := (gc_map_comap f).u_top @[simp, to_additive] lemma comap_subtype_inf_left {H K : subgroup G} : comap H.subtype (H ⊓ K) = comap H.subtype K := ext $ λ x, and_iff_right_of_imp (λ _, x.prop) @[simp, to_additive] lemma comap_subtype_inf_right {H K : subgroup G} : comap K.subtype (H ⊓ K) = comap K.subtype H := ext $ λ x, and_iff_left_of_imp (λ _, x.prop) /-- If `H ≤ K`, then `H` as a subgroup of `K` is isomorphic to `H`. -/ @[to_additive "If `H ≤ K`, then `H` as a subgroup of `K` is isomorphic to `H`.", simps] def comap_subtype_equiv_of_le {G : Type*} [group G] {H K : subgroup G} (h : H ≤ K) : H.comap K.subtype ≃* H := { to_fun := λ g, ⟨g.1, g.2⟩, inv_fun := λ g, ⟨⟨g.1, h g.2⟩, g.2⟩, left_inv := λ g, subtype.ext (subtype.ext rfl), right_inv := λ g, subtype.ext rfl, map_mul' := λ g h, rfl } /-- For any subgroups `H` and `K`, view `H ⊓ K` as a subgroup of `K`. -/ @[to_additive "For any subgroups `H` and `K`, view `H ⊓ K` as a subgroup of `K`."] def subgroup_of (H K : subgroup G) : subgroup K := H.comap K.subtype @[to_additive] lemma coe_subgroup_of (H K : subgroup G) : (H.subgroup_of K : set K) = K.subtype ⁻¹' H := rfl @[to_additive] lemma mem_subgroup_of {H K : subgroup G} {h : K} : h ∈ H.subgroup_of K ↔ (h : G) ∈ H := iff.rfl @[to_additive] lemma subgroup_of_map_subtype (H K : subgroup G) : (H.subgroup_of K).map K.subtype = H ⊓ K := set_like.ext' begin convert set.image_preimage_eq_inter_range, simp only [subtype.range_coe_subtype, coe_subtype, coe_inf], refl, end @[simp, to_additive] lemma bot_subgroup_of : (⊥ : subgroup G).subgroup_of H = ⊥ := eq.symm (subgroup.ext (λ g, subtype.ext_iff)) @[simp, to_additive] lemma top_subgroup_of : (⊤ : subgroup G).subgroup_of H = ⊤ := rfl @[to_additive] lemma subgroup_of_bot_eq_bot : H.subgroup_of ⊥ = ⊥ := subsingleton.elim _ _ @[to_additive] lemma subgroup_of_bot_eq_top : H.subgroup_of ⊥ = ⊤ := subsingleton.elim _ _ @[simp, to_additive] lemma subgroup_of_self : H.subgroup_of H = ⊤ := top_le_iff.mp (λ g hg, g.2) /-- Given `subgroup`s `H`, `K` of groups `G`, `N` respectively, `H × K` as a subgroup of `G × N`. -/ @[to_additive prod "Given `add_subgroup`s `H`, `K` of `add_group`s `A`, `B` respectively, `H × K` as an `add_subgroup` of `A × B`."] def prod (H : subgroup G) (K : subgroup N) : subgroup (G × N) := { inv_mem' := λ _ hx, ⟨H.inv_mem' hx.1, K.inv_mem' hx.2⟩, .. submonoid.prod H.to_submonoid K.to_submonoid} @[to_additive coe_prod] lemma coe_prod (H : subgroup G) (K : subgroup N) : (H.prod K : set (G × N)) = (H : set G).prod (K : set N) := rfl @[to_additive mem_prod] lemma mem_prod {H : subgroup G} {K : subgroup N} {p : G × N} : p ∈ H.prod K ↔ p.1 ∈ H ∧ p.2 ∈ K := iff.rfl @[to_additive prod_mono] lemma prod_mono : ((≤) ⇒ (≤) ⇒ (≤)) (@prod G _ N _) (@prod G _ N _) := λ s s' hs t t' ht, set.prod_mono hs ht @[to_additive prod_mono_right] lemma prod_mono_right (K : subgroup G) : monotone (λ t : subgroup N, K.prod t) := prod_mono (le_refl K) @[to_additive prod_mono_left] lemma prod_mono_left (H : subgroup N) : monotone (λ K : subgroup G, K.prod H) := λ s₁ s₂ hs, prod_mono hs (le_refl H) @[to_additive prod_top] lemma prod_top (K : subgroup G) : K.prod (⊤ : subgroup N) = K.comap (monoid_hom.fst G N) := ext $ λ x, by simp [mem_prod, monoid_hom.coe_fst] @[to_additive top_prod] lemma top_prod (H : subgroup N) : (⊤ : subgroup G).prod H = H.comap (monoid_hom.snd G N) := ext $ λ x, by simp [mem_prod, monoid_hom.coe_snd] @[simp, to_additive top_prod_top] lemma top_prod_top : (⊤ : subgroup G).prod (⊤ : subgroup N) = ⊤ := (top_prod _).trans $ comap_top _ @[to_additive] lemma bot_prod_bot : (⊥ : subgroup G).prod (⊥ : subgroup N) = ⊥ := set_like.coe_injective $ by simp [coe_prod, prod.one_eq_mk] /-- Product of subgroups is isomorphic to their product as groups. -/ @[to_additive prod_equiv "Product of additive subgroups is isomorphic to their product as additive groups"] def prod_equiv (H : subgroup G) (K : subgroup N) : H.prod K ≃* H × K := { map_mul' := λ x y, rfl, .. equiv.set.prod ↑H ↑K } /-- A subgroup is normal if whenever `n ∈ H`, then `g * n * g⁻¹ ∈ H` for every `g : G` -/ structure normal : Prop := (conj_mem : ∀ n, n ∈ H → ∀ g : G, g * n * g⁻¹ ∈ H) attribute [class] normal end subgroup namespace add_subgroup /-- An add_subgroup is normal if whenever `n ∈ H`, then `g + n - g ∈ H` for every `g : G` -/ structure normal (H : add_subgroup A) : Prop := (conj_mem [] : ∀ n, n ∈ H → ∀ g : A, g + n + -g ∈ H) attribute [to_additive add_subgroup.normal] subgroup.normal attribute [class] normal end add_subgroup namespace subgroup variables {H K : subgroup G} @[priority 100, to_additive] instance normal_of_comm {G : Type*} [comm_group G] (H : subgroup G) : H.normal := ⟨by simp [mul_comm, mul_left_comm]⟩ namespace normal variable (nH : H.normal) @[to_additive] lemma mem_comm {a b : G} (h : a * b ∈ H) : b * a ∈ H := have a⁻¹ * (a * b) * a⁻¹⁻¹ ∈ H, from nH.conj_mem (a * b) h a⁻¹, by simpa @[to_additive] lemma mem_comm_iff {a b : G} : a * b ∈ H ↔ b * a ∈ H := ⟨nH.mem_comm, nH.mem_comm⟩ end normal variables (H) /-- A subgroup is characteristic if it is fixed by all automorphisms. Several equivalent conditions are provided by lemmas of the form `characteristic.iff...` -/ structure characteristic : Prop := (fixed : ∀ ϕ : G ≃* G, H.comap ϕ.to_monoid_hom = H) attribute [class] characteristic @[priority 100] instance normal_of_characteristic [h : H.characteristic] : H.normal := ⟨λ a ha b, (set_like.ext_iff.mp (h.fixed (mul_aut.conj b)) a).mpr ha⟩ end subgroup namespace add_subgroup variables (H : add_subgroup A) /-- A add_subgroup is characteristic if it is fixed by all automorphisms. Several equivalent conditions are provided by lemmas of the form `characteristic.iff...` -/ structure characteristic : Prop := (fixed : ∀ ϕ : A ≃+ A, H.comap ϕ.to_add_monoid_hom = H) attribute [to_additive add_subgroup.characteristic] subgroup.characteristic attribute [class] characteristic @[priority 100] instance normal_of_characteristic [h : H.characteristic] : H.normal := ⟨λ a ha b, (set_like.ext_iff.mp (h.fixed (add_aut.conj b)) a).mpr ha⟩ end add_subgroup namespace subgroup variables {H K : subgroup G} @[to_additive] lemma characteristic_iff_comap_eq : H.characteristic ↔ ∀ ϕ : G ≃* G, H.comap ϕ.to_monoid_hom = H := ⟨characteristic.fixed, characteristic.mk⟩ @[to_additive] lemma characteristic_iff_comap_le : H.characteristic ↔ ∀ ϕ : G ≃* G, H.comap ϕ.to_monoid_hom ≤ H := characteristic_iff_comap_eq.trans ⟨λ h ϕ, le_of_eq (h ϕ), λ h ϕ, le_antisymm (h ϕ) (λ g hg, h ϕ.symm ((congr_arg (∈ H) (ϕ.symm_apply_apply g)).mpr hg))⟩ @[to_additive] lemma characteristic_iff_le_comap : H.characteristic ↔ ∀ ϕ : G ≃* G, H ≤ H.comap ϕ.to_monoid_hom := characteristic_iff_comap_eq.trans ⟨λ h ϕ, ge_of_eq (h ϕ), λ h ϕ, le_antisymm (λ g hg, (congr_arg (∈ H) (ϕ.symm_apply_apply g)).mp (h ϕ.symm hg)) (h ϕ)⟩ @[to_additive] lemma characteristic_iff_map_eq : H.characteristic ↔ ∀ ϕ : G ≃* G, H.map ϕ.to_monoid_hom = H := begin simp_rw map_equiv_eq_comap_symm, exact characteristic_iff_comap_eq.trans ⟨λ h ϕ, h ϕ.symm, λ h ϕ, h ϕ.symm⟩, end @[to_additive] lemma characteristic_iff_map_le : H.characteristic ↔ ∀ ϕ : G ≃* G, H.map ϕ.to_monoid_hom ≤ H := begin simp_rw map_equiv_eq_comap_symm, exact characteristic_iff_comap_le.trans ⟨λ h ϕ, h ϕ.symm, λ h ϕ, h ϕ.symm⟩, end @[to_additive] lemma characteristic_iff_le_map : H.characteristic ↔ ∀ ϕ : G ≃* G, H ≤ H.map ϕ.to_monoid_hom := begin simp_rw map_equiv_eq_comap_symm, exact characteristic_iff_le_comap.trans ⟨λ h ϕ, h ϕ.symm, λ h ϕ, h ϕ.symm⟩, end @[to_additive] instance bot_characteristic : characteristic (⊥ : subgroup G) := characteristic_iff_le_map.mpr (λ ϕ, bot_le) @[to_additive] instance top_characteristic : characteristic (⊤ : subgroup G) := characteristic_iff_map_le.mpr (λ ϕ, le_top) variable (G) /-- The center of a group `G` is the set of elements that commute with everything in `G` -/ @[to_additive "The center of an additive group `G` is the set of elements that commute with everything in `G`"] def center : subgroup G := { carrier := set.center G, inv_mem' := λ a, set.inv_mem_center, .. submonoid.center G } @[to_additive] lemma coe_center : ↑(center G) = set.center G := rfl @[simp, to_additive] lemma center_to_submonoid : (center G).to_submonoid = submonoid.center G := rfl variable {G} @[to_additive] lemma mem_center_iff {z : G} : z ∈ center G ↔ ∀ g, g * z = z * g := iff.rfl instance decidable_mem_center [decidable_eq G] [fintype G] : decidable_pred (∈ center G) := λ _, decidable_of_iff' _ mem_center_iff @[to_additive] instance center_characteristic : (center G).characteristic := begin refine characteristic_iff_comap_le.mpr (λ ϕ g hg h, _), rw [←ϕ.injective.eq_iff, ϕ.map_mul, ϕ.map_mul], exact hg (ϕ h), end variables {G} (H) /-- The `normalizer` of `H` is the largest subgroup of `G` inside which `H` is normal. -/ @[to_additive "The `normalizer` of `H` is the largest subgroup of `G` inside which `H` is normal."] def normalizer : subgroup G := { carrier := {g : G | ∀ n, n ∈ H ↔ g * n * g⁻¹ ∈ H}, one_mem' := by simp, mul_mem' := λ a b (ha : ∀ n, n ∈ H ↔ a * n * a⁻¹ ∈ H) (hb : ∀ n, n ∈ H ↔ b * n * b⁻¹ ∈ H) n, by { rw [hb, ha], simp [mul_assoc] }, inv_mem' := λ a (ha : ∀ n, n ∈ H ↔ a * n * a⁻¹ ∈ H) n, by { rw [ha (a⁻¹ * n * a⁻¹⁻¹)], simp [mul_assoc] } } -- variant for sets. -- TODO should this replace `normalizer`? /-- The `set_normalizer` of `S` is the subgroup of `G` whose elements satisfy `g*S*g⁻¹=S` -/ @[to_additive "The `set_normalizer` of `S` is the subgroup of `G` whose elements satisfy `g+S-g=S`."] def set_normalizer (S : set G) : subgroup G := { carrier := {g : G | ∀ n, n ∈ S ↔ g * n * g⁻¹ ∈ S}, one_mem' := by simp, mul_mem' := λ a b (ha : ∀ n, n ∈ S ↔ a * n * a⁻¹ ∈ S) (hb : ∀ n, n ∈ S ↔ b * n * b⁻¹ ∈ S) n, by { rw [hb, ha], simp [mul_assoc] }, inv_mem' := λ a (ha : ∀ n, n ∈ S ↔ a * n * a⁻¹ ∈ S) n, by { rw [ha (a⁻¹ * n * a⁻¹⁻¹)], simp [mul_assoc] } } lemma mem_normalizer_fintype {S : set G} [fintype S] {x : G} (h : ∀ n, n ∈ S → x * n * x⁻¹ ∈ S) : x ∈ subgroup.set_normalizer S := by haveI := classical.prop_decidable; haveI := set.fintype_image S (λ n, x * n * x⁻¹); exact λ n, ⟨h n, λ h₁, have heq : (λ n, x * n * x⁻¹) '' S = S := set.eq_of_subset_of_card_le (λ n ⟨y, hy⟩, hy.2 ▸ h y hy.1) (by rw set.card_image_of_injective S conj_injective), have x * n * x⁻¹ ∈ (λ n, x * n * x⁻¹) '' S := heq.symm ▸ h₁, let ⟨y, hy⟩ := this in conj_injective hy.2 ▸ hy.1⟩ variable {H} @[to_additive] lemma mem_normalizer_iff {g : G} : g ∈ normalizer H ↔ ∀ n, n ∈ H ↔ g * n * g⁻¹ ∈ H := iff.rfl @[to_additive] lemma le_normalizer : H ≤ normalizer H := λ x xH n, by rw [H.mul_mem_cancel_right (H.inv_mem xH), H.mul_mem_cancel_left xH] @[priority 100, to_additive] instance normal_in_normalizer : (H.comap H.normalizer.subtype).normal := ⟨λ x xH g, by simpa using (g.2 x).1 xH⟩ @[to_additive] lemma normalizer_eq_top : H.normalizer = ⊤ ↔ H.normal := eq_top_iff.trans ⟨λ h, ⟨λ a ha b, (h (mem_top b) a).mp ha⟩, λ h a ha b, ⟨λ hb, h.conj_mem b hb a, λ hb, by rwa [h.mem_comm_iff, inv_mul_cancel_left] at hb⟩⟩ open_locale classical @[to_additive] lemma le_normalizer_of_normal [hK : (H.comap K.subtype).normal] (HK : H ≤ K) : K ≤ H.normalizer := λ x hx y, ⟨λ yH, hK.conj_mem ⟨y, HK yH⟩ yH ⟨x, hx⟩, λ yH, by simpa [mem_comap, mul_assoc] using hK.conj_mem ⟨x * y * x⁻¹, HK yH⟩ yH ⟨x⁻¹, K.inv_mem hx⟩⟩ variables {N : Type*} [group N] /-- The preimage of the normalizer is contained in the normalizer of the preimage. -/ @[to_additive "The preimage of the normalizer is contained in the normalizer of the preimage."] lemma le_normalizer_comap (f : N →* G) : H.normalizer.comap f ≤ (H.comap f).normalizer := λ x, begin simp only [mem_normalizer_iff, mem_comap], assume h n, simp [h (f n)] end /-- The image of the normalizer is contained in the normalizer of the image. -/ @[to_additive "The image of the normalizer is contained in the normalizer of the image."] lemma le_normalizer_map (f : G →* N) : H.normalizer.map f ≤ (H.map f).normalizer := λ _, begin simp only [and_imp, exists_prop, mem_map, exists_imp_distrib, mem_normalizer_iff], rintros x hx rfl n, split, { rintros ⟨y, hy, rfl⟩, use [x * y * x⁻¹, (hx y).1 hy], simp }, { rintros ⟨y, hyH, hy⟩, use [x⁻¹ * y * x], rw [hx], simp [hy, hyH, mul_assoc] } end variable (H) /-- Commutivity of a subgroup -/ structure is_commutative : Prop := (is_comm : _root_.is_commutative H (*)) attribute [class] is_commutative /-- Commutivity of an additive subgroup -/ structure _root_.add_subgroup.is_commutative (H : add_subgroup A) : Prop := (is_comm : _root_.is_commutative H (+)) attribute [to_additive add_subgroup.is_commutative] subgroup.is_commutative attribute [class] add_subgroup.is_commutative /-- A commutative subgroup is commutative -/ @[to_additive] instance is_commutative.comm_group [h : H.is_commutative] : comm_group H := { mul_comm := h.is_comm.comm, .. H.to_group } instance center.is_commutative : (center G).is_commutative := ⟨⟨λ a b, subtype.ext (b.2 a)⟩⟩ end subgroup namespace group variables {s : set G} /-- Given a set `s`, `conjugates_of_set s` is the set of all conjugates of the elements of `s`. -/ def conjugates_of_set (s : set G) : set G := ⋃ a ∈ s, conjugates_of a lemma mem_conjugates_of_set_iff {x : G} : x ∈ conjugates_of_set s ↔ ∃ a ∈ s, is_conj a x := set.mem_bUnion_iff theorem subset_conjugates_of_set : s ⊆ conjugates_of_set s := λ (x : G) (h : x ∈ s), mem_conjugates_of_set_iff.2 ⟨x, h, is_conj.refl _⟩ theorem conjugates_of_set_mono {s t : set G} (h : s ⊆ t) : conjugates_of_set s ⊆ conjugates_of_set t := set.bUnion_subset_bUnion_left h lemma conjugates_subset_normal {N : subgroup G} [tn : N.normal] {a : G} (h : a ∈ N) : conjugates_of a ⊆ N := by { rintros a hc, obtain ⟨c, rfl⟩ := is_conj_iff.1 hc, exact tn.conj_mem a h c } theorem conjugates_of_set_subset {s : set G} {N : subgroup G} [N.normal] (h : s ⊆ N) : conjugates_of_set s ⊆ N := set.bUnion_subset (λ x H, conjugates_subset_normal (h H)) /-- The set of conjugates of `s` is closed under conjugation. -/ lemma conj_mem_conjugates_of_set {x c : G} : x ∈ conjugates_of_set s → (c * x * c⁻¹ ∈ conjugates_of_set s) := λ H, begin rcases (mem_conjugates_of_set_iff.1 H) with ⟨a,h₁,h₂⟩, exact mem_conjugates_of_set_iff.2 ⟨a, h₁, h₂.trans (is_conj_iff.2 ⟨c,rfl⟩)⟩, end end group namespace subgroup open group variable {s : set G} /-- The normal closure of a set `s` is the subgroup closure of all the conjugates of elements of `s`. It is the smallest normal subgroup containing `s`. -/ def normal_closure (s : set G) : subgroup G := closure (conjugates_of_set s) theorem conjugates_of_set_subset_normal_closure : conjugates_of_set s ⊆ normal_closure s := subset_closure theorem subset_normal_closure : s ⊆ normal_closure s := set.subset.trans subset_conjugates_of_set conjugates_of_set_subset_normal_closure theorem le_normal_closure {H : subgroup G} : H ≤ normal_closure ↑H := λ _ h, subset_normal_closure h /-- The normal closure of `s` is a normal subgroup. -/ instance normal_closure_normal : (normal_closure s).normal := ⟨λ n h g, begin refine subgroup.closure_induction h (λ x hx, _) _ (λ x y ihx ihy, _) (λ x ihx, _), { exact (conjugates_of_set_subset_normal_closure (conj_mem_conjugates_of_set hx)) }, { simpa using (normal_closure s).one_mem }, { rw ← conj_mul, exact mul_mem _ ihx ihy }, { rw ← conj_inv, exact inv_mem _ ihx } end⟩ /-- The normal closure of `s` is the smallest normal subgroup containing `s`. -/ theorem normal_closure_le_normal {N : subgroup G} [N.normal] (h : s ⊆ N) : normal_closure s ≤ N := begin assume a w, refine closure_induction w (λ x hx, _) _ (λ x y ihx ihy, _) (λ x ihx, _), { exact (conjugates_of_set_subset h hx) }, { exact subgroup.one_mem _ }, { exact subgroup.mul_mem _ ihx ihy }, { exact subgroup.inv_mem _ ihx } end lemma normal_closure_subset_iff {N : subgroup G} [N.normal] : s ⊆ N ↔ normal_closure s ≤ N := ⟨normal_closure_le_normal, set.subset.trans (subset_normal_closure)⟩ theorem normal_closure_mono {s t : set G} (h : s ⊆ t) : normal_closure s ≤ normal_closure t := normal_closure_le_normal (set.subset.trans h subset_normal_closure) theorem normal_closure_eq_infi : normal_closure s = ⨅ (N : subgroup G) (_ : normal N) (hs : s ⊆ N), N := le_antisymm (le_infi (λ N, le_infi (λ hN, by exactI le_infi (normal_closure_le_normal)))) (infi_le_of_le (normal_closure s) (infi_le_of_le (by apply_instance) (infi_le_of_le subset_normal_closure (le_refl _)))) @[simp] theorem normal_closure_eq_self (H : subgroup G) [H.normal] : normal_closure ↑H = H := le_antisymm (normal_closure_le_normal rfl.subset) (le_normal_closure) @[simp] theorem normal_closure_idempotent : normal_closure ↑(normal_closure s) = normal_closure s := normal_closure_eq_self _ theorem closure_le_normal_closure {s : set G} : closure s ≤ normal_closure s := by simp only [subset_normal_closure, closure_le] @[simp] theorem normal_closure_closure_eq_normal_closure {s : set G} : normal_closure ↑(closure s) = normal_closure s := le_antisymm (normal_closure_le_normal closure_le_normal_closure) (normal_closure_mono subset_closure) /-- The normal core of a subgroup `H` is the largest normal subgroup of `G` contained in `H`, as shown by `subgroup.normal_core_eq_supr`. -/ def normal_core (H : subgroup G) : subgroup G := { carrier := {a : G | ∀ b : G, b * a * b⁻¹ ∈ H}, one_mem' := λ a, by rw [mul_one, mul_inv_self]; exact H.one_mem, inv_mem' := λ a h b, (congr_arg (∈ H) conj_inv).mp (H.inv_mem (h b)), mul_mem' := λ a b ha hb c, (congr_arg (∈ H) conj_mul).mp (H.mul_mem (ha c) (hb c)) } lemma normal_core_le (H : subgroup G) : H.normal_core ≤ H := λ a h, by { rw [←mul_one a, ←one_inv, ←one_mul a], exact h 1 } instance normal_core_normal (H : subgroup G) : H.normal_core.normal := ⟨λ a h b c, by rw [mul_assoc, mul_assoc, ←mul_inv_rev, ←mul_assoc, ←mul_assoc]; exact h (c * b)⟩ lemma normal_le_normal_core {H : subgroup G} {N : subgroup G} [hN : N.normal] : N ≤ H.normal_core ↔ N ≤ H := ⟨ge_trans H.normal_core_le, λ h_le n hn g, h_le (hN.conj_mem n hn g)⟩ lemma normal_core_mono {H K : subgroup G} (h : H ≤ K) : H.normal_core ≤ K.normal_core := normal_le_normal_core.mpr (H.normal_core_le.trans h) lemma normal_core_eq_supr (H : subgroup G) : H.normal_core = ⨆ (N : subgroup G) (_ : normal N) (hs : N ≤ H), N := le_antisymm (le_supr_of_le H.normal_core (le_supr_of_le H.normal_core_normal (le_supr_of_le H.normal_core_le le_rfl))) (supr_le (λ N, supr_le (λ hN, supr_le (by exactI normal_le_normal_core.mpr)))) @[simp] lemma normal_core_eq_self (H : subgroup G) [H.normal] : H.normal_core = H := le_antisymm H.normal_core_le (normal_le_normal_core.mpr le_rfl) @[simp] theorem normal_core_idempotent (H : subgroup G) : H.normal_core.normal_core = H.normal_core := H.normal_core.normal_core_eq_self end subgroup namespace add_subgroup open set /-- The `add_subgroup` generated by an element of an `add_group` equals the set of natural number multiples of the element. -/ lemma mem_closure_singleton {x y : A} : y ∈ closure ({x} : set A) ↔ ∃ n : ℤ, n • x = y := begin refine ⟨λ hy, closure_induction hy _ _ _ _, λ ⟨n, hn⟩, hn ▸ gsmul_mem _ (subset_closure $ mem_singleton x) n⟩, { intros y hy, rw [eq_of_mem_singleton hy], exact ⟨1, one_gsmul x⟩ }, { exact ⟨0, zero_gsmul x⟩ }, { rintros _ _ ⟨n, rfl⟩ ⟨m, rfl⟩, exact ⟨n + m, add_gsmul x n m⟩ }, { rintros _ ⟨n, rfl⟩, refine ⟨-n, neg_gsmul x n⟩ } end lemma closure_singleton_zero : closure ({0} : set A) = ⊥ := by simp [eq_bot_iff_forall, mem_closure_singleton] variable (H : add_subgroup A) @[simp] lemma coe_smul (x : H) (n : ℕ) : ((n • x : H) : A) = n • x := coe_subtype H ▸ add_monoid_hom.map_nsmul _ _ _ @[simp] lemma coe_gsmul (x : H) (n : ℤ) : ((n • x : H) : A) = n • x := coe_subtype H ▸ add_monoid_hom.map_gsmul _ _ _ attribute [to_additive add_subgroup.coe_smul] subgroup.coe_pow attribute [to_additive add_subgroup.coe_gsmul] subgroup.coe_gpow end add_subgroup namespace monoid_hom variables {N : Type*} {P : Type*} [group N] [group P] (K : subgroup G) open subgroup /-- The range of a monoid homomorphism from a group is a subgroup. -/ @[to_additive "The range of an `add_monoid_hom` from an `add_group` is an `add_subgroup`."] def range (f : G →* N) : subgroup N := subgroup.copy ((⊤ : subgroup G).map f) (set.range f) (by simp [set.ext_iff]) @[to_additive] instance decidable_mem_range (f : G →* N) [fintype G] [decidable_eq N] : decidable_pred (∈ f.range) := λ x, fintype.decidable_exists_fintype @[simp, to_additive] lemma coe_range (f : G →* N) : (f.range : set N) = set.range f := rfl @[simp, to_additive] lemma mem_range {f : G →* N} {y : N} : y ∈ f.range ↔ ∃ x, f x = y := iff.rfl @[to_additive] lemma range_eq_map (f : G →* N) : f.range = (⊤ : subgroup G).map f := by ext; simp /-- The canonical surjective group homomorphism `G →* f(G)` induced by a group homomorphism `G →* N`. -/ @[to_additive "The canonical surjective `add_group` homomorphism `G →+ f(G)` induced by a group homomorphism `G →+ N`."] def range_restrict (f : G →* N) : G →* f.range := monoid_hom.mk' (λ g, ⟨f g, ⟨g, rfl⟩⟩) $ λ a b, by {ext, exact f.map_mul' _ _} @[simp, to_additive] lemma coe_range_restrict (f : G →* N) (g : G) : (f.range_restrict g : N) = f g := rfl @[to_additive] lemma range_restrict_surjective (f : G →* N) : function.surjective f.range_restrict := λ ⟨_, g, rfl⟩, ⟨g, rfl⟩ @[to_additive] lemma map_range (g : N →* P) (f : G →* N) : f.range.map g = (g.comp f).range := by rw [range_eq_map, range_eq_map]; exact (⊤ : subgroup G).map_map g f @[to_additive] lemma range_top_iff_surjective {N} [group N] {f : G →* N} : f.range = (⊤ : subgroup N) ↔ function.surjective f := set_like.ext'_iff.trans $ iff.trans (by rw [coe_range, coe_top]) set.range_iff_surjective /-- The range of a surjective monoid homomorphism is the whole of the codomain. -/ @[to_additive "The range of a surjective `add_monoid` homomorphism is the whole of the codomain."] lemma range_top_of_surjective {N} [group N] (f : G →* N) (hf : function.surjective f) : f.range = (⊤ : subgroup N) := range_top_iff_surjective.2 hf @[simp, to_additive] lemma _root_.subgroup.subtype_range (H : subgroup G) : H.subtype.range = H := by { rw [range_eq_map, ← set_like.coe_set_eq, coe_map, subgroup.coe_subtype], ext, simp } @[simp, to_additive] lemma _root_.subgroup.inclusion_range {H K : subgroup G} (h_le : H ≤ K) : (inclusion h_le).range = H.subgroup_of K := subgroup.ext (λ g, set.ext_iff.mp (set.range_inclusion h_le) g) /-- Restriction of a group hom to a subgroup of the domain. -/ @[to_additive "Restriction of an `add_group` hom to an `add_subgroup` of the domain."] def restrict (f : G →* N) (H : subgroup G) : H →* N := f.comp H.subtype @[simp, to_additive] lemma restrict_apply {H : subgroup G} (f : G →* N) (x : H) : f.restrict H x = f (x : G) := rfl /-- Restriction of a group hom to a subgroup of the codomain. -/ @[to_additive "Restriction of an `add_group` hom to an `add_subgroup` of the codomain."] def cod_restrict (f : G →* N) (S : subgroup N) (h : ∀ x, f x ∈ S) : G →* S := { to_fun := λ n, ⟨f n, h n⟩, map_one' := subtype.eq f.map_one, map_mul' := λ x y, subtype.eq (f.map_mul x y) } @[simp, to_additive] lemma cod_restrict_apply {G : Type*} [group G] {N : Type*} [group N] (f : G →* N) (S : subgroup N) (h : ∀ (x : G), f x ∈ S) {x : G} : f.cod_restrict S h x = ⟨f x, h x⟩ := rfl @[to_additive] lemma subgroup_of_range_eq_of_le {G₁ G₂ : Type*} [group G₁] [group G₂] {K : subgroup G₂} (f : G₁ →* G₂) (h : f.range ≤ K) : f.range.subgroup_of K = (f.cod_restrict K (λ x, h ⟨x, rfl⟩)).range := begin ext k, refine exists_congr _, simp [subtype.ext_iff], end /-- Computable alternative to `monoid_hom.of_injective`. -/ def of_left_inverse {f : G →* N} {g : N →* G} (h : function.left_inverse g f) : G ≃* f.range := { to_fun := f.range_restrict, inv_fun := g ∘ f.range.subtype, left_inv := h, right_inv := by { rintros ⟨x, y, rfl⟩, apply subtype.ext, rw [coe_range_restrict, function.comp_apply, subgroup.coe_subtype, subtype.coe_mk, h] }, .. f.range_restrict } @[simp] lemma of_left_inverse_apply {f : G →* N} {g : N →* G} (h : function.left_inverse g f) (x : G) : ↑(of_left_inverse h x) = f x := rfl @[simp] lemma of_left_inverse_symm_apply {f : G →* N} {g : N →* G} (h : function.left_inverse g f) (x : f.range) : (of_left_inverse h).symm x = g x := rfl /-- The range of an injective group homomorphism is isomorphic to its domain. -/ noncomputable def of_injective {f : G →* N} (hf : function.injective f) : G ≃* f.range := (mul_equiv.of_bijective (f.cod_restrict f.range (λ x, ⟨x, rfl⟩)) ⟨λ x y h, hf (subtype.ext_iff.mp h), by { rintros ⟨x, y, rfl⟩, exact ⟨y, rfl⟩ }⟩) lemma of_injective_apply {f : G →* N} (hf : function.injective f) {x : G} : ↑(of_injective hf x) = f x := rfl section ker variables {M : Type*} [mul_one_class M] /-- The multiplicative kernel of a monoid homomorphism is the subgroup of elements `x : G` such that `f x = 1` -/ @[to_additive "The additive kernel of an `add_monoid` homomorphism is the `add_subgroup` of elements such that `f x = 0`"] def ker (f : G →* M) : subgroup G := { inv_mem' := λ x (hx : f x = 1), calc f x⁻¹ = f x * f x⁻¹ : by rw [hx, one_mul] ... = f (x * x⁻¹) : by rw [f.map_mul] ... = f 1 : by rw [mul_right_inv] ... = 1 : f.map_one, ..f.mker } @[to_additive] lemma mem_ker (f : G →* M) {x : G} : x ∈ f.ker ↔ f x = 1 := iff.rfl @[to_additive] lemma coe_ker (f : G →* M) : (f.ker : set G) = (f : G → M) ⁻¹' {1} := rfl @[to_additive] lemma eq_iff (f : G →* N) {x y : G} : f x = f y ↔ y⁻¹ * x ∈ f.ker := by rw [f.mem_ker, f.map_mul, f.map_inv, inv_mul_eq_one, eq_comm] @[to_additive] instance decidable_mem_ker [decidable_eq M] (f : G →* M) : decidable_pred (∈ f.ker) := λ x, decidable_of_iff (f x = 1) f.mem_ker @[to_additive] lemma comap_ker (g : N →* P) (f : G →* N) : g.ker.comap f = (g.comp f).ker := rfl @[simp, to_additive] lemma comap_bot (f : G →* N) : (⊥ : subgroup N).comap f = f.ker := rfl @[to_additive] lemma range_restrict_ker (f : G →* N) : ker (range_restrict f) = ker f := begin ext, change (⟨f x, _⟩ : range f) = ⟨1, _⟩ ↔ f x = 1, simp only [], end @[simp, to_additive] lemma ker_one : (1 : G →* M).ker = ⊤ := by { ext, simp [mem_ker] } @[to_additive] lemma ker_eq_bot_iff (f : G →* N) : f.ker = ⊥ ↔ function.injective f := begin split, { intros h x y hxy, rwa [←mul_inv_eq_one, ←map_inv, ←map_mul, ←mem_ker, h, mem_bot, mul_inv_eq_one] at hxy }, { exact λ h, le_bot_iff.mp (λ x hx, h (hx.trans f.map_one.symm)) }, end @[simp, to_additive] lemma _root_.subgroup.ker_subtype (H : subgroup G) : H.subtype.ker = ⊥ := H.subtype.ker_eq_bot_iff.mpr subtype.coe_injective @[simp, to_additive] lemma _root_.subgroup.ker_inclusion {H K : subgroup G} (h : H ≤ K) : (inclusion h).ker = ⊥ := (inclusion h).ker_eq_bot_iff.mpr (set.inclusion_injective h) @[to_additive] lemma prod_map_comap_prod {G' : Type*} {N' : Type*} [group G'] [group N'] (f : G →* N) (g : G' →* N') (S : subgroup N) (S' : subgroup N') : (S.prod S').comap (prod_map f g) = (S.comap f).prod (S'.comap g) := set_like.coe_injective $ set.preimage_prod_map_prod f g _ _ @[to_additive] lemma ker_prod_map {G' : Type*} {N' : Type*} [group G'] [group N'] (f : G →* N) (g : G' →* N') : (prod_map f g).ker = f.ker.prod g.ker := by rw [←comap_bot, ←comap_bot, ←comap_bot, ←prod_map_comap_prod, bot_prod_bot] end ker /-- The subgroup of elements `x : G` such that `f x = g x` -/ @[to_additive "The additive subgroup of elements `x : G` such that `f x = g x`"] def eq_locus (f g : G →* N) : subgroup G := { inv_mem' := λ x (hx : f x = g x), show f x⁻¹ = g x⁻¹, by rw [f.map_inv, g.map_inv, hx], .. eq_mlocus f g} /-- If two monoid homomorphisms are equal on a set, then they are equal on its subgroup closure. -/ @[to_additive] lemma eq_on_closure {f g : G →* N} {s : set G} (h : set.eq_on f g s) : set.eq_on f g (closure s) := show closure s ≤ f.eq_locus g, from (closure_le _).2 h @[to_additive] lemma eq_of_eq_on_top {f g : G →* N} (h : set.eq_on f g (⊤ : subgroup G)) : f = g := ext $ λ x, h trivial @[to_additive] lemma eq_of_eq_on_dense {s : set G} (hs : closure s = ⊤) {f g : G →* N} (h : s.eq_on f g) : f = g := eq_of_eq_on_top $ hs ▸ eq_on_closure h @[to_additive] lemma gclosure_preimage_le (f : G →* N) (s : set N) : closure (f ⁻¹' s) ≤ (closure s).comap f := (closure_le _).2 $ λ x hx, by rw [set_like.mem_coe, mem_comap]; exact subset_closure hx /-- The image under a monoid homomorphism of the subgroup generated by a set equals the subgroup generated by the image of the set. -/ @[to_additive "The image under an `add_monoid` hom of the `add_subgroup` generated by a set equals the `add_subgroup` generated by the image of the set."] lemma map_closure (f : G →* N) (s : set G) : (closure s).map f = closure (f '' s) := le_antisymm (map_le_iff_le_comap.2 $ le_trans (closure_mono $ set.subset_preimage_image f s) (gclosure_preimage_le _ _)) ((closure_le _).2 $ set.image_subset _ subset_closure) -- this instance can't go just after the definition of `mrange` because `fintype` is -- not imported at that stage /-- The range of a finite monoid under a monoid homomorphism is finite. Note: this instance can form a diamond with `subtype.fintype` in the presence of `fintype N`. -/ @[to_additive "The range of a finite additive monoid under an additive monoid homomorphism is finite. Note: this instance can form a diamond with `subtype.fintype` or `subgroup.fintype` in the presence of `fintype N`."] instance fintype_mrange {M N : Type*} [monoid M] [monoid N] [fintype M] [decidable_eq N] (f : M →* N) : fintype (mrange f) := set.fintype_range f /-- The range of a finite group under a group homomorphism is finite. Note: this instance can form a diamond with `subtype.fintype` or `subgroup.fintype` in the presence of `fintype N`. -/ @[to_additive "The range of a finite additive group under an additive group homomorphism is finite. Note: this instance can form a diamond with `subtype.fintype` or `subgroup.fintype` in the presence of `fintype N`."] instance fintype_range [fintype G] [decidable_eq N] (f : G →* N) : fintype (range f) := set.fintype_range f end monoid_hom namespace subgroup variables {N : Type*} [group N] (H : subgroup G) @[to_additive] lemma map_eq_bot_iff {f : G →* N} : H.map f = ⊥ ↔ H ≤ f.ker := begin rw eq_bot_iff, split, { exact λ h x hx, h ⟨x, hx, rfl⟩ }, { intros h x hx, obtain ⟨y, hy, rfl⟩ := hx, exact h hy }, end @[to_additive] lemma map_eq_bot_iff_of_injective {f : G →* N} (hf : function.injective f) : H.map f = ⊥ ↔ H = ⊥ := by rw [map_eq_bot_iff, f.ker_eq_bot_iff.mpr hf, le_bot_iff] end subgroup namespace subgroup open monoid_hom variables {N : Type*} [group N] (f : G →* N) @[to_additive] lemma map_le_range (H : subgroup G) : map f H ≤ f.range := (range_eq_map f).symm ▸ map_mono le_top @[to_additive] lemma map_subtype_le {H : subgroup G} (K : subgroup H) : K.map H.subtype ≤ H := (K.map_le_range H.subtype).trans (le_of_eq H.subtype_range) @[to_additive] lemma ker_le_comap (H : subgroup N) : f.ker ≤ comap f H := (comap_bot f) ▸ comap_mono bot_le @[to_additive] lemma map_comap_le (H : subgroup N) : map f (comap f H) ≤ H := (gc_map_comap f).l_u_le _ @[to_additive] lemma le_comap_map (H : subgroup G) : H ≤ comap f (map f H) := (gc_map_comap f).le_u_l _ @[to_additive] lemma map_comap_eq (H : subgroup N) : map f (comap f H) = f.range ⊓ H := set_like.ext' begin convert set.image_preimage_eq_inter_range, simp [set.inter_comm], end @[to_additive] lemma comap_map_eq (H : subgroup G) : comap f (map f H) = H ⊔ f.ker := begin refine le_antisymm _ (sup_le (le_comap_map _ _) (ker_le_comap _ _)), intros x hx, simp only [exists_prop, mem_map, mem_comap] at hx, rcases hx with ⟨y, hy, hy'⟩, have : y⁻¹ * x ∈ f.ker, { rw mem_ker, simp [hy'] }, convert mul_mem _ (mem_sup_left hy) (mem_sup_right this), simp, end @[to_additive] lemma map_comap_eq_self {f : G →* N} {H : subgroup N} (h : H ≤ f.range) : map f (comap f H) = H := by rwa [map_comap_eq, inf_eq_right] @[to_additive] lemma map_comap_eq_self_of_surjective {f : G →* N} (h : function.surjective f) (H : subgroup N) : map f (comap f H) = H := map_comap_eq_self ((range_top_of_surjective _ h).symm ▸ le_top) @[to_additive] lemma comap_injective {f : G →* N} (h : function.surjective f) : function.injective (comap f) := λ K L hKL, by { apply_fun map f at hKL, simpa [map_comap_eq_self_of_surjective h] using hKL } @[to_additive] lemma comap_map_eq_self {f : G →* N} {H : subgroup G} (h : f.ker ≤ H) : comap f (map f H) = H := by rwa [comap_map_eq, sup_eq_left] @[to_additive] lemma comap_map_eq_self_of_injective {f : G →* N} (h : function.injective f) (H : subgroup G) : comap f (map f H) = H := comap_map_eq_self (((ker_eq_bot_iff _).mpr h).symm ▸ bot_le) @[to_additive] lemma map_injective {f : G →* N} (h : function.injective f) : function.injective (map f) := λ K L hKL, by { apply_fun comap f at hKL, simpa [comap_map_eq_self_of_injective h] using hKL } @[to_additive] lemma map_eq_comap_of_inverse {f : G →* N} {g : N →* G} (hl : function.left_inverse g f) (hr : function.right_inverse g f) (H : subgroup G) : map f H = comap g H := set_like.ext' $ by rw [coe_map, coe_comap, set.image_eq_preimage_of_inverse hl hr] /-- Given `f(A) = f(B)`, `ker f ≤ A`, and `ker f ≤ B`, deduce that `A = B` -/ @[to_additive] lemma map_injective_of_ker_le {H K : subgroup G} (hH : f.ker ≤ H) (hK : f.ker ≤ K) (hf : map f H = map f K) : H = K := begin apply_fun comap f at hf, rwa [comap_map_eq, comap_map_eq, sup_of_le_left hH, sup_of_le_left hK] at hf, end @[to_additive] lemma comap_sup_eq_of_le_range {H K : subgroup N} (hH : H ≤ f.range) (hK : K ≤ f.range) : comap f H ⊔ comap f K = comap f (H ⊔ K) := map_injective_of_ker_le f ((ker_le_comap f H).trans le_sup_left) (ker_le_comap f (H ⊔ K)) (by rw [map_comap_eq, map_sup, map_comap_eq, map_comap_eq, inf_eq_right.mpr hH, inf_eq_right.mpr hK, inf_eq_right.mpr (sup_le hH hK)]) @[to_additive] lemma comap_sup_eq (H K : subgroup N) (hf : function.surjective f) : comap f H ⊔ comap f K = comap f (H ⊔ K) := comap_sup_eq_of_le_range f (le_top.trans (ge_of_eq (f.range_top_of_surjective hf))) (le_top.trans (ge_of_eq (f.range_top_of_surjective hf))) @[to_additive] lemma sup_subgroup_of_eq {H K L : subgroup G} (hH : H ≤ L) (hK : K ≤ L) : H.subgroup_of L ⊔ K.subgroup_of L = (H ⊔ K).subgroup_of L := comap_sup_eq_of_le_range L.subtype (hH.trans (ge_of_eq L.subtype_range)) (hK.trans (ge_of_eq L.subtype_range)) /-- A subgroup is isomorphic to its image under an injective function -/ @[to_additive "An additive subgroup is isomorphic to its image under an injective function"] noncomputable def equiv_map_of_injective (H : subgroup G) (f : G →* N) (hf : function.injective f) : H ≃* H.map f := { map_mul' := λ _ _, subtype.ext (f.map_mul _ _), ..equiv.set.image f H hf } @[simp, to_additive] lemma coe_equiv_map_of_injective_apply (H : subgroup G) (f : G →* N) (hf : function.injective f) (h : H) : (equiv_map_of_injective H f hf h : N) = f h := rfl /-- The preimage of the normalizer is equal to the normalizer of the preimage of a surjective function. -/ @[to_additive "The preimage of the normalizer is equal to the normalizer of the preimage of a surjective function."] lemma comap_normalizer_eq_of_surjective (H : subgroup G) {f : N →* G} (hf : function.surjective f) : H.normalizer.comap f = (H.comap f).normalizer := le_antisymm (le_normalizer_comap f) begin assume x hx, simp only [mem_comap, mem_normalizer_iff] at *, assume n, rcases hf n with ⟨y, rfl⟩, simp [hx y] end /-- The image of the normalizer is equal to the normalizer of the image of an isomorphism. -/ @[to_additive "The image of the normalizer is equal to the normalizer of the image of an isomorphism."] lemma map_equiv_normalizer_eq (H : subgroup G) (f : G ≃* N) : H.normalizer.map f.to_monoid_hom = (H.map f.to_monoid_hom).normalizer := begin ext x, simp only [mem_normalizer_iff, mem_map_equiv], rw [f.to_equiv.forall_congr], simp end /-- The image of the normalizer is equal to the normalizer of the image of a bijective function. -/ @[to_additive "The image of the normalizer is equal to the normalizer of the image of a bijective function."] lemma map_normalizer_eq_of_bijective (H : subgroup G) {f : G →* N} (hf : function.bijective f) : H.normalizer.map f = (H.map f).normalizer := map_equiv_normalizer_eq H (mul_equiv.of_bijective f hf) end subgroup namespace monoid_hom variables {G₁ G₂ G₃ : Type*} [group G₁] [group G₂] [group G₃] variables (f : G₁ →* G₂) (f_inv : G₂ → G₁) /-- Auxiliary definition used to define `lift_of_right_inverse` -/ @[to_additive "Auxiliary definition used to define `lift_of_right_inverse`"] def lift_of_right_inverse_aux (hf : function.right_inverse f_inv f) (g : G₁ →* G₃) (hg : f.ker ≤ g.ker) : G₂ →* G₃ := { to_fun := λ b, g (f_inv b), map_one' := hg (hf 1), map_mul' := begin intros x y, rw [← g.map_mul, ← mul_inv_eq_one, ← g.map_inv, ← g.map_mul, ← g.mem_ker], apply hg, rw [f.mem_ker, f.map_mul, f.map_inv, mul_inv_eq_one, f.map_mul], simp only [hf _], end } @[simp, to_additive] lemma lift_of_right_inverse_aux_comp_apply (hf : function.right_inverse f_inv f) (g : G₁ →* G₃) (hg : f.ker ≤ g.ker) (x : G₁) : (f.lift_of_right_inverse_aux f_inv hf g hg) (f x) = g x := begin dsimp [lift_of_right_inverse_aux], rw [← mul_inv_eq_one, ← g.map_inv, ← g.map_mul, ← g.mem_ker], apply hg, rw [f.mem_ker, f.map_mul, f.map_inv, mul_inv_eq_one], simp only [hf _], end /-- `lift_of_right_inverse f hf g hg` is the unique group homomorphism `φ` * such that `φ.comp f = g` (`monoid_hom.lift_of_right_inverse_comp`), * where `f : G₁ →+* G₂` has a right_inverse `f_inv` (`hf`), * and `g : G₂ →+* G₃` satisfies `hg : f.ker ≤ g.ker`. See `monoid_hom.eq_lift_of_right_inverse` for the uniqueness lemma. ``` G₁. | \ f | \ g | \ v \⌟ G₂----> G₃ ∃!φ ``` -/ @[to_additive "`lift_of_right_inverse f f_inv hf g hg` is the unique additive group homomorphism `φ` * such that `φ.comp f = g` (`add_monoid_hom.lift_of_right_inverse_comp`), * where `f : G₁ →+ G₂` has a right_inverse `f_inv` (`hf`), * and `g : G₂ →+ G₃` satisfies `hg : f.ker ≤ g.ker`. See `add_monoid_hom.eq_lift_of_right_inverse` for the uniqueness lemma. ``` G₁. | \\ f | \\ g | \\ v \\⌟ G₂----> G₃ ∃!φ ```"] def lift_of_right_inverse (hf : function.right_inverse f_inv f) : {g : G₁ →* G₃ // f.ker ≤ g.ker} ≃ (G₂ →* G₃) := { to_fun := λ g, f.lift_of_right_inverse_aux f_inv hf g.1 g.2, inv_fun := λ φ, ⟨φ.comp f, λ x hx, (mem_ker _).mpr $ by simp [(mem_ker _).mp hx]⟩, left_inv := λ g, by { ext, simp only [comp_apply, lift_of_right_inverse_aux_comp_apply, subtype.coe_mk, subtype.val_eq_coe], }, right_inv := λ φ, by { ext b, simp [lift_of_right_inverse_aux, hf b], } } /-- A non-computable version of `monoid_hom.lift_of_right_inverse` for when no computable right inverse is available, that uses `function.surj_inv`. -/ @[simp, to_additive "A non-computable version of `add_monoid_hom.lift_of_right_inverse` for when no computable right inverse is available."] noncomputable abbreviation lift_of_surjective (hf : function.surjective f) : {g : G₁ →* G₃ // f.ker ≤ g.ker} ≃ (G₂ →* G₃) := f.lift_of_right_inverse (function.surj_inv hf) (function.right_inverse_surj_inv hf) @[simp, to_additive] lemma lift_of_right_inverse_comp_apply (hf : function.right_inverse f_inv f) (g : {g : G₁ →* G₃ // f.ker ≤ g.ker}) (x : G₁) : (f.lift_of_right_inverse f_inv hf g) (f x) = g x := f.lift_of_right_inverse_aux_comp_apply f_inv hf g.1 g.2 x @[simp, to_additive] lemma lift_of_right_inverse_comp (hf : function.right_inverse f_inv f) (g : {g : G₁ →* G₃ // f.ker ≤ g.ker}) : (f.lift_of_right_inverse f_inv hf g).comp f = g := monoid_hom.ext $ f.lift_of_right_inverse_comp_apply f_inv hf g @[to_additive] lemma eq_lift_of_right_inverse (hf : function.right_inverse f_inv f) (g : G₁ →* G₃) (hg : f.ker ≤ g.ker) (h : G₂ →* G₃) (hh : h.comp f = g) : h = (f.lift_of_right_inverse f_inv hf ⟨g, hg⟩) := begin simp_rw ←hh, exact ((f.lift_of_right_inverse f_inv hf).apply_symm_apply _).symm, end end monoid_hom variables {N : Type*} [group N] -- Here `H.normal` is an explicit argument so we can use dot notation with `comap`. @[to_additive] lemma subgroup.normal.comap {H : subgroup N} (hH : H.normal) (f : G →* N) : (H.comap f).normal := ⟨λ _, by simp [subgroup.mem_comap, hH.conj_mem] {contextual := tt}⟩ @[priority 100, to_additive] instance subgroup.normal_comap {H : subgroup N} [nH : H.normal] (f : G →* N) : (H.comap f).normal := nH.comap _ @[priority 100, to_additive] instance monoid_hom.normal_ker (f : G →* N) : f.ker.normal := by { rw [←f.comap_bot], apply_instance } @[priority 100, to_additive] instance subgroup.normal_inf (H N : subgroup G) [hN : N.normal] : ((H ⊓ N).comap H.subtype).normal := ⟨λ x hx g, begin simp only [subgroup.mem_inf, coe_subtype, subgroup.mem_comap] at hx, simp only [subgroup.coe_mul, subgroup.mem_inf, coe_subtype, subgroup.coe_inv, subgroup.mem_comap], exact ⟨H.mul_mem (H.mul_mem g.2 hx.1) (H.inv_mem g.2), hN.1 x hx.2 g⟩, end⟩ namespace subgroup /-- The subgroup generated by an element. -/ def gpowers (g : G) : subgroup G := subgroup.copy (gpowers_hom G g).range (set.range ((^) g : ℤ → G)) rfl @[simp] lemma mem_gpowers (g : G) : g ∈ gpowers g := ⟨1, gpow_one _⟩ lemma gpowers_eq_closure (g : G) : gpowers g = closure {g} := by { ext, exact mem_closure_singleton.symm } @[simp] lemma range_gpowers_hom (g : G) : (gpowers_hom G g).range = gpowers g := rfl lemma gpowers_subset {a : G} {K : subgroup G} (h : a ∈ K) : gpowers a ≤ K := λ x hx, match x, hx with _, ⟨i, rfl⟩ := K.gpow_mem h i end lemma mem_gpowers_iff {g h : G} : h ∈ gpowers g ↔ ∃ (k : ℤ), g ^ k = h := iff.rfl @[simp] lemma forall_gpowers {x : G} {p : gpowers x → Prop} : (∀ g, p g) ↔ ∀ m : ℤ, p ⟨x ^ m, m, rfl⟩ := set.forall_subtype_range_iff @[simp] lemma exists_gpowers {x : G} {p : gpowers x → Prop} : (∃ g, p g) ↔ ∃ m : ℤ, p ⟨x ^ m, m, rfl⟩ := set.exists_subtype_range_iff lemma forall_mem_gpowers {x : G} {p : G → Prop} : (∀ g ∈ gpowers x, p g) ↔ ∀ m : ℤ, p (x ^ m) := set.forall_range_iff lemma exists_mem_gpowers {x : G} {p : G → Prop} : (∃ g ∈ gpowers x, p g) ↔ ∃ m : ℤ, p (x ^ m) := set.exists_range_iff end subgroup namespace add_subgroup /-- The subgroup generated by an element. -/ def gmultiples (a : A) : add_subgroup A := add_subgroup.copy (gmultiples_hom A a).range (set.range ((• a) : ℤ → A)) rfl @[simp] lemma range_gmultiples_hom (a : A) : (gmultiples_hom A a).range = gmultiples a := rfl lemma gmultiples_subset {a : A} {B : add_subgroup A} (h : a ∈ B) : gmultiples a ≤ B := @subgroup.gpowers_subset (multiplicative A) _ _ (B.to_subgroup) h attribute [to_additive add_subgroup.gmultiples] subgroup.gpowers attribute [to_additive add_subgroup.mem_gmultiples] subgroup.mem_gpowers attribute [to_additive add_subgroup.gmultiples_eq_closure] subgroup.gpowers_eq_closure attribute [to_additive add_subgroup.range_gmultiples_hom] subgroup.range_gpowers_hom attribute [to_additive add_subgroup.gmultiples_subset] subgroup.gpowers_subset attribute [to_additive add_subgroup.mem_gmultiples_iff] subgroup.mem_gpowers_iff attribute [to_additive add_subgroup.forall_gmultiples] subgroup.forall_gpowers attribute [to_additive add_subgroup.forall_mem_gmultiples] subgroup.forall_mem_gpowers attribute [to_additive add_subgroup.exists_gmultiples] subgroup.exists_gpowers attribute [to_additive add_subgroup.exists_mem_gmultiples] subgroup.exists_mem_gpowers end add_subgroup lemma int.mem_gmultiples_iff {a b : ℤ} : b ∈ add_subgroup.gmultiples a ↔ a ∣ b := exists_congr (λ k, by rw [mul_comm, eq_comm, ← smul_eq_mul]) lemma of_mul_image_gpowers_eq_gmultiples_of_mul { x : G } : additive.of_mul '' ((subgroup.gpowers x) : set G) = add_subgroup.gmultiples (additive.of_mul x) := begin ext y, split, { rintro ⟨z, ⟨m, hm⟩, hz2⟩, use m, simp only, rwa [← of_mul_gpow, hm] }, { rintros ⟨n, hn⟩, refine ⟨x ^ n, ⟨n, rfl⟩, _⟩, rwa of_mul_gpow } end lemma of_add_image_gmultiples_eq_gpowers_of_add {x : A} : multiplicative.of_add '' ((add_subgroup.gmultiples x) : set A) = subgroup.gpowers (multiplicative.of_add x) := begin symmetry, rw equiv.eq_image_iff_symm_image_eq, exact of_mul_image_gpowers_eq_gmultiples_of_mul, end namespace mul_equiv variables {H K : subgroup G} /-- Makes the identity isomorphism from a proof two subgroups of a multiplicative group are equal. -/ @[to_additive "Makes the identity additive isomorphism from a proof two subgroups of an additive group are equal."] def subgroup_congr (h : H = K) : H ≃* K := { map_mul' := λ _ _, rfl, ..equiv.set_congr $ congr_arg _ h } /-- A `mul_equiv` `φ` between two groups `G` and `G'` induces a `mul_equiv` between a subgroup `H ≤ G` and the subgroup `φ(H) ≤ G'`. -/ @[to_additive "An `add_equiv` `φ` between two additive groups `G` and `G'` induces an `add_equiv` between a subgroup `H ≤ G` and the subgroup `φ(H) ≤ G'`. "] def subgroup_equiv_map {G'} [group G'] (e : G ≃* G') (H : subgroup G) : H ≃* H.map e.to_monoid_hom := e.submonoid_equiv_map H.to_submonoid end mul_equiv -- TODO : ↥(⊤ : subgroup H) ≃* H ? namespace subgroup variables {C : Type*} [comm_group C] {s t : subgroup C} {x : C} @[to_additive] lemma mem_sup : x ∈ s ⊔ t ↔ ∃ (y ∈ s) (z ∈ t), y * z = x := ⟨λ h, begin rw [← closure_eq s, ← closure_eq t, ← closure_union] at h, apply closure_induction h, { rintro y (h | h), { exact ⟨y, h, 1, t.one_mem, by simp⟩ }, { exact ⟨1, s.one_mem, y, h, by simp⟩ } }, { exact ⟨1, s.one_mem, 1, ⟨t.one_mem, mul_one 1⟩⟩ }, { rintro _ _ ⟨y₁, hy₁, z₁, hz₁, rfl⟩ ⟨y₂, hy₂, z₂, hz₂, rfl⟩, exact ⟨_, mul_mem _ hy₁ hy₂, _, mul_mem _ hz₁ hz₂, by simp [mul_assoc]; cc⟩ }, { rintro _ ⟨y, hy, z, hz, rfl⟩, exact ⟨_, inv_mem _ hy, _, inv_mem _ hz, mul_comm z y ▸ (mul_inv_rev z y).symm⟩ } end, by rintro ⟨y, hy, z, hz, rfl⟩; exact mul_mem _ ((le_sup_left : s ≤ s ⊔ t) hy) ((le_sup_right : t ≤ s ⊔ t) hz)⟩ @[to_additive] lemma mem_sup' : x ∈ s ⊔ t ↔ ∃ (y : s) (z : t), (y:C) * z = x := mem_sup.trans $ by simp only [set_like.exists, coe_mk] @[to_additive] instance : is_modular_lattice (subgroup C) := ⟨λ 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 ← inv_mul_cancel_left b c, apply z.mul_mem (z.inv_mem (xz hb)) haz, end⟩ end subgroup section variables (G) (A) /-- A `group` is simple when it has exactly two normal `subgroup`s. -/ class is_simple_group extends nontrivial G : Prop := (eq_bot_or_eq_top_of_normal : ∀ H : subgroup G, H.normal → H = ⊥ ∨ H = ⊤) /-- An `add_group` is simple when it has exactly two normal `add_subgroup`s. -/ class is_simple_add_group extends nontrivial A : Prop := (eq_bot_or_eq_top_of_normal : ∀ H : add_subgroup A, H.normal → H = ⊥ ∨ H = ⊤) attribute [to_additive] is_simple_group variables {G} {A} @[to_additive] lemma subgroup.normal.eq_bot_or_eq_top [is_simple_group G] {H : subgroup G} (Hn : H.normal) : H = ⊥ ∨ H = ⊤ := is_simple_group.eq_bot_or_eq_top_of_normal H Hn namespace is_simple_group @[to_additive] instance {C : Type*} [comm_group C] [is_simple_group C] : is_simple_lattice (subgroup C) := ⟨λ H, H.normal_of_comm.eq_bot_or_eq_top⟩ open _root_.subgroup @[to_additive] lemma is_simple_group_of_surjective {H : Type*} [group H] [is_simple_group G] [nontrivial H] (f : G →* H) (hf : function.surjective f) : is_simple_group H := ⟨nontrivial.exists_pair_ne, λ H iH, begin refine ((iH.comap f).eq_bot_or_eq_top).imp (λ h, _) (λ h, _), { rw [←map_bot f, ←h, map_comap_eq_self_of_surjective hf] }, { rw [←comap_top f] at h, exact comap_injective hf h } end⟩ end is_simple_group end namespace subgroup section pointwise @[to_additive] lemma closure_mul_le (S T : set G) : closure (S * T) ≤ closure S ⊔ closure T := Inf_le $ λ x ⟨s, t, hs, ht, hx⟩, hx ▸ (closure S ⊔ closure T).mul_mem (set_like.le_def.mp le_sup_left $ subset_closure hs) (set_like.le_def.mp le_sup_right $ subset_closure ht) @[to_additive] lemma sup_eq_closure (H K : subgroup G) : H ⊔ K = closure (H * K) := le_antisymm (sup_le (λ h hh, subset_closure ⟨h, 1, hh, K.one_mem, mul_one h⟩) (λ k hk, subset_closure ⟨1, k, H.one_mem, hk, one_mul k⟩)) (by conv_rhs { rw [← closure_eq H, ← closure_eq K] }; apply closure_mul_le) @[to_additive] private def mul_normal_aux (H N : subgroup G) [hN : N.normal] : subgroup G := { carrier := (H : set G) * N, one_mem' := ⟨1, 1, H.one_mem, N.one_mem, by rw mul_one⟩, mul_mem' := λ a b ⟨h, n, hh, hn, ha⟩ ⟨h', n', hh', hn', hb⟩, ⟨h * h', h'⁻¹ * n * h' * n', H.mul_mem hh hh', N.mul_mem (by simpa using hN.conj_mem _ hn h'⁻¹) hn', by simp [← ha, ← hb, mul_assoc]⟩, inv_mem' := λ x ⟨h, n, hh, hn, hx⟩, ⟨h⁻¹, h * n⁻¹ * h⁻¹, H.inv_mem hh, hN.conj_mem _ (N.inv_mem hn) h, by rw [mul_assoc h, inv_mul_cancel_left, ← hx, mul_inv_rev]⟩ } /-- The carrier of `H ⊔ N` is just `↑H * ↑N` (pointwise set product) when `N` is normal. -/ @[to_additive "The carrier of `H ⊔ N` is just `↑H + ↑N` (pointwise set addition) when `N` is normal."] lemma mul_normal (H N : subgroup G) [N.normal] : (↑(H ⊔ N) : set G) = H * N := set.subset.antisymm (show H ⊔ N ≤ mul_normal_aux H N, by { rw sup_eq_closure, apply Inf_le _, dsimp, refl }) ((sup_eq_closure H N).symm ▸ subset_closure) @[to_additive] private def normal_mul_aux (N H : subgroup G) [hN : N.normal] : subgroup G := { carrier := (N : set G) * H, one_mem' := ⟨1, 1, N.one_mem, H.one_mem, by rw mul_one⟩, mul_mem' := λ a b ⟨n, h, hn, hh, ha⟩ ⟨n', h', hn', hh', hb⟩, ⟨n * (h * n' * h⁻¹), h * h', N.mul_mem hn (hN.conj_mem _ hn' _), H.mul_mem hh hh', by simp [← ha, ← hb, mul_assoc]⟩, inv_mem' := λ x ⟨n, h, hn, hh, hx⟩, ⟨h⁻¹ * n⁻¹ * h, h⁻¹, by simpa using hN.conj_mem _ (N.inv_mem hn) h⁻¹, H.inv_mem hh, by rw [mul_inv_cancel_right, ← mul_inv_rev, hx]⟩ } /-- The carrier of `N ⊔ H` is just `↑N * ↑H` (pointwise set product) when `N` is normal. -/ @[to_additive "The carrier of `N ⊔ H` is just `↑N + ↑H` (pointwise set addition) when `N` is normal."] lemma normal_mul (N H : subgroup G) [N.normal] : (↑(N ⊔ H) : set G) = N * H := set.subset.antisymm (show N ⊔ H ≤ normal_mul_aux N H, by { rw sup_eq_closure, apply Inf_le _, dsimp, refl }) ((sup_eq_closure N H).symm ▸ subset_closure) @[to_additive] lemma mul_inf_assoc (A B C : subgroup G) (h : A ≤ C) : (A : set G) * ↑(B ⊓ C) = (A * B) ⊓ C := begin ext, simp only [coe_inf, set.inf_eq_inter, set.mem_mul, set.mem_inter_iff], split, { rintros ⟨y, z, hy, ⟨hzB, hzC⟩, rfl⟩, refine ⟨_, mul_mem C (h hy) hzC⟩, exact ⟨y, z, hy, hzB, rfl⟩ }, rintros ⟨⟨y, z, hy, hz, rfl⟩, hyz⟩, refine ⟨y, z, hy, ⟨hz, _⟩, rfl⟩, suffices : y⁻¹ * (y * z) ∈ C, { simpa }, exact mul_mem C (inv_mem C (h hy)) hyz end @[to_additive] lemma inf_mul_assoc (A B C : subgroup G) (h : C ≤ A) : ((A ⊓ B : subgroup G) : set G) * C = A ⊓ (B * C) := begin ext, simp only [coe_inf, set.inf_eq_inter, set.mem_mul, set.mem_inter_iff], split, { rintros ⟨y, z, ⟨hyA, hyB⟩, hz, rfl⟩, refine ⟨mul_mem A hyA (h hz), _⟩, exact ⟨y, z, hyB, hz, rfl⟩ }, rintros ⟨hyz, y, z, hy, hz, rfl⟩, refine ⟨y, z, ⟨_, hy⟩, hz, rfl⟩, suffices : (y * z) * z⁻¹ ∈ A, { simpa }, exact mul_mem A hyz (inv_mem A (h hz)) end end pointwise section subgroup_normal @[to_additive] lemma normal_subgroup_of_iff {H K : subgroup G} (hHK : H ≤ K) : (H.subgroup_of K).normal ↔ ∀ h k, h ∈ H → k ∈ K → k * h * k⁻¹ ∈ H := ⟨λ hN h k hH hK, hN.conj_mem ⟨h, hHK hH⟩ hH ⟨k, hK⟩, λ hN, { conj_mem := λ h hm k, (hN h.1 k.1 hm k.2) }⟩ @[to_additive] instance prod_subgroup_of_prod_normal {H₁ K₁ : subgroup G} {H₂ K₂ : subgroup N} [h₁ : (H₁.subgroup_of K₁).normal] [h₂ : (H₂.subgroup_of K₂).normal] : ((H₁.prod H₂).subgroup_of (K₁.prod K₂)).normal := { conj_mem := λ n hgHK g, ⟨h₁.conj_mem ⟨(n : G × N).fst, (mem_prod.mp n.2).1⟩ hgHK.1 ⟨(g : G × N).fst, (mem_prod.mp g.2).1⟩, h₂.conj_mem ⟨(n : G × N).snd, (mem_prod.mp n.2).2⟩ hgHK.2 ⟨(g : G × N).snd, (mem_prod.mp g.2).2⟩⟩ } @[to_additive] instance prod_normal (H : subgroup G) (K : subgroup N) [hH : H.normal] [hK : K.normal] : (H.prod K).normal := { conj_mem := λ n hg g, ⟨hH.conj_mem n.fst (subgroup.mem_prod.mp hg).1 g.fst, hK.conj_mem n.snd (subgroup.mem_prod.mp hg).2 g.snd⟩ } @[to_additive] lemma inf_subgroup_of_inf_normal_of_right (A B' B : subgroup G) (hB : B' ≤ B) [hN : (B'.subgroup_of B).normal] : ((A ⊓ B').subgroup_of (A ⊓ B)).normal := { conj_mem := λ n hn g, ⟨mul_mem A (mul_mem A (mem_inf.1 g.2).1 (mem_inf.1 n.2).1) (inv_mem A (mem_inf.1 g.2).1), (normal_subgroup_of_iff hB).mp hN n g hn.2 (mem_inf.mp g.2).2⟩ } @[to_additive] lemma inf_subgroup_of_inf_normal_of_left {A' A : subgroup G} (B : subgroup G) (hA : A' ≤ A) [hN : (A'.subgroup_of A).normal] : ((A' ⊓ B).subgroup_of (A ⊓ B)).normal := { conj_mem := λ n hn g, ⟨(normal_subgroup_of_iff hA).mp hN n g hn.1 (mem_inf.mp g.2).1, mul_mem B (mul_mem B (mem_inf.1 g.2).2 (mem_inf.1 n.2).2) (inv_mem B (mem_inf.1 g.2).2)⟩ } instance sup_normal (H K : subgroup G) [hH : H.normal] [hK : K.normal] : (H ⊔ K).normal := { conj_mem := λ n hmem g, begin change n ∈ ↑(H ⊔ K) at hmem, change g * n * g⁻¹ ∈ ↑(H ⊔ K), rw [normal_mul, set.mem_mul] at *, rcases hmem with ⟨h, k, hh, hk, rfl⟩, refine ⟨g * h * g⁻¹, g * k * g⁻¹, hH.conj_mem h hh g, hK.conj_mem k hk g, _⟩, simp end } @[to_additive] instance normal_inf_normal (H K : subgroup G) [hH : H.normal] [hK : K.normal] : (H ⊓ K).normal := { conj_mem := λ n hmem g, by { rw mem_inf at *, exact ⟨hH.conj_mem n hmem.1 g, hK.conj_mem n hmem.2 g⟩ } } @[to_additive] lemma subgroup_of_sup (A A' B : subgroup G) (hA : A ≤ B) (hA' : A' ≤ B) : (A ⊔ A').subgroup_of B = A.subgroup_of B ⊔ A'.subgroup_of B := begin refine map_injective_of_ker_le B.subtype (ker_le_comap _ _) (le_trans (ker_le_comap B.subtype _) le_sup_left) _, { simp only [subgroup_of, map_comap_eq, map_sup, subtype_range], rw [inf_of_le_right (sup_le hA hA'), inf_of_le_right hA', inf_of_le_right hA] }, end @[to_additive] lemma subgroup_normal.mem_comm {H K : subgroup G} (hK : H ≤ K) [hN : (H.subgroup_of K).normal] {a b : G} (hb : b ∈ K) (h : a * b ∈ H) : b * a ∈ H := begin have := (normal_subgroup_of_iff hK).mp hN (a * b) b h hb, rwa [mul_assoc, mul_assoc, mul_right_inv, mul_one] at this, end end subgroup_normal end subgroup namespace is_conj open subgroup lemma normal_closure_eq_top_of {N : subgroup G} [hn : N.normal] {g g' : G} {hg : g ∈ N} {hg' : g' ∈ N} (hc : is_conj g g') (ht : normal_closure ({⟨g, hg⟩} : set N) = ⊤) : normal_closure ({⟨g', hg'⟩} : set N) = ⊤ := begin obtain ⟨c, rfl⟩ := is_conj_iff.1 hc, have h : ∀ x : N, (mul_aut.conj c) x ∈ N, { rintro ⟨x, hx⟩, exact hn.conj_mem _ hx c }, have hs : function.surjective (((mul_aut.conj c).to_monoid_hom.restrict N).cod_restrict _ h), { rintro ⟨x, hx⟩, refine ⟨⟨c⁻¹ * x * c, _⟩, _⟩, { have h := hn.conj_mem _ hx c⁻¹, rwa [inv_inv] at h }, simp only [monoid_hom.cod_restrict_apply, mul_equiv.coe_to_monoid_hom, mul_aut.conj_apply, coe_mk, monoid_hom.restrict_apply, subtype.mk_eq_mk, ← mul_assoc, mul_inv_self, one_mul], rw [mul_assoc, mul_inv_self, mul_one] }, have ht' := map_mono (eq_top_iff.1 ht), rw [← monoid_hom.range_eq_map, monoid_hom.range_top_of_surjective _ hs] at ht', refine eq_top_iff.2 (le_trans ht' (map_le_iff_le_comap.2 (normal_closure_le_normal _))), rw [set.singleton_subset_iff, set_like.mem_coe], simp only [monoid_hom.cod_restrict_apply, mul_equiv.coe_to_monoid_hom, mul_aut.conj_apply, coe_mk, monoid_hom.restrict_apply, mem_comap], exact subset_normal_closure (set.mem_singleton _), end end is_conj /-! ### Actions by `subgroup`s These are just copies of the definitions about `submonoid` starting from `submonoid.mul_action`. -/ section actions namespace subgroup variables {α β : Type*} /-- The action by a subgroup is the action by the underlying group. -/ @[to_additive /-"The additive action by an add_subgroup is the action by the underlying add_group. "-/] instance [mul_action G α] (S : subgroup G) : mul_action S α := S.to_submonoid.mul_action @[to_additive] lemma smul_def [mul_action G α] {S : subgroup G} (g : S) (m : α) : g • m = (g : G) • m := rfl @[to_additive] instance smul_comm_class_left [mul_action G β] [has_scalar α β] [smul_comm_class G α β] (S : subgroup G) : smul_comm_class S α β := S.to_submonoid.smul_comm_class_left @[to_additive] instance smul_comm_class_right [has_scalar α β] [mul_action G β] [smul_comm_class α G β] (S : subgroup G) : smul_comm_class α S β := S.to_submonoid.smul_comm_class_right /-- Note that this provides `is_scalar_tower S G G` which is needed by `smul_mul_assoc`. -/ instance [has_scalar α β] [mul_action G α] [mul_action G β] [is_scalar_tower G α β] (S : subgroup G) : is_scalar_tower S α β := S.to_submonoid.is_scalar_tower instance [mul_action G α] [has_faithful_scalar G α] (S : subgroup G) : has_faithful_scalar S α := S.to_submonoid.has_faithful_scalar /-- The action by a subgroup is the action by the underlying group. -/ instance [add_monoid α] [distrib_mul_action G α] (S : subgroup G) : distrib_mul_action S α := S.to_submonoid.distrib_mul_action /-- The action by a subgroup is the action by the underlying group. -/ instance [monoid α] [mul_distrib_mul_action G α] (S : subgroup G) : mul_distrib_mul_action S α := S.to_submonoid.mul_distrib_mul_action end subgroup end actions /-! ### Saturated subgroups -/ section saturated namespace subgroup /-- A subgroup `H` of `G` is *saturated* if for all `n : ℕ` and `g : G` with `g^n ∈ H` we have `n = 0` or `g ∈ H`. -/ @[to_additive "An additive subgroup `H` of `G` is *saturated* if for all `n : ℕ` and `g : G` with `n•g ∈ H` we have `n = 0` or `g ∈ H`."] def saturated (H : subgroup G) : Prop := ∀ ⦃n g⦄, npow n g ∈ H → n = 0 ∨ g ∈ H @[to_additive] lemma saturated_iff_npow {H : subgroup G} : saturated H ↔ (∀ (n : ℕ) (g : G), g^n ∈ H → n = 0 ∨ g ∈ H) := iff.rfl @[to_additive] lemma saturated_iff_gpow {H : subgroup G} : saturated H ↔ (∀ (n : ℤ) (g : G), g^n ∈ H → n = 0 ∨ g ∈ H) := begin split, { rintros hH ⟨n⟩ g hgn, { simp only [int.coe_nat_eq_zero, int.of_nat_eq_coe, gpow_coe_nat] at hgn ⊢, exact hH hgn }, { suffices : g ^ (n+1) ∈ H, { refine (hH this).imp _ id, simp only [forall_false_left, nat.succ_ne_zero], }, simpa only [inv_mem_iff, gpow_neg_succ_of_nat] using hgn, } }, { intros h n g hgn, specialize h n g, simp only [int.coe_nat_eq_zero, gpow_coe_nat] at h, apply h hgn } end end subgroup namespace add_subgroup lemma ker_saturated {A₁ A₂ : Type*} [add_comm_group A₁] [add_comm_group A₂] [no_zero_smul_divisors ℕ A₂] (f : A₁ →+ A₂) : (f.ker).saturated := begin intros n g hg, simpa only [f.mem_ker, nsmul_eq_smul, f.map_nsmul, smul_eq_zero] using hg end end add_subgroup end saturated
ddec9ff2f8679ac9e3f6be88440261246813fefb
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/measure_theory/covering/one_dim.lean
851314e77b0cac8aefd70c4437690ed882b36757
[ "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
2,447
lean
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import measure_theory.covering.density_theorem import measure_theory.measure.lebesgue.eq_haar /-! # Covering theorems for Lebesgue measure in one dimension > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. We have a general theory of covering theorems for doubling measures, developed notably in `density_theorems.lean`. In this file, we expand the API for this theory in one dimension, by showing that intervals belong to the relevant Vitali family. -/ open set measure_theory is_unif_loc_doubling_measure filter open_locale topology namespace real lemma Icc_mem_vitali_family_at_right {x y : ℝ} (hxy : x < y) : Icc x y ∈ (vitali_family (volume : measure ℝ) 1).sets_at x := begin rw Icc_eq_closed_ball, refine closed_ball_mem_vitali_family_of_dist_le_mul _ _ (by linarith), rw [dist_comm, real.dist_eq, abs_of_nonneg]; linarith, end lemma tendsto_Icc_vitali_family_right (x : ℝ) : tendsto (λ y, Icc x y) (𝓝[>] x) ((vitali_family (volume : measure ℝ) 1).filter_at x) := begin refine (vitali_family.tendsto_filter_at_iff _).2 ⟨_, _⟩, { filter_upwards [self_mem_nhds_within] with y hy using Icc_mem_vitali_family_at_right hy }, { assume ε εpos, have : x ∈ Ico x (x + ε) := ⟨le_refl _, by linarith⟩, filter_upwards [Icc_mem_nhds_within_Ioi this] with y hy, rw closed_ball_eq_Icc, exact Icc_subset_Icc (by linarith) hy.2 } end lemma Icc_mem_vitali_family_at_left {x y : ℝ} (hxy : x < y) : Icc x y ∈ (vitali_family (volume : measure ℝ) 1).sets_at y := begin rw Icc_eq_closed_ball, refine closed_ball_mem_vitali_family_of_dist_le_mul _ _ (by linarith), rw [real.dist_eq, abs_of_nonneg]; linarith, end lemma tendsto_Icc_vitali_family_left (x : ℝ) : tendsto (λ y, Icc y x) (𝓝[<] x) ((vitali_family (volume : measure ℝ) 1).filter_at x) := begin refine (vitali_family.tendsto_filter_at_iff _).2 ⟨_, _⟩, { filter_upwards [self_mem_nhds_within] with y hy using Icc_mem_vitali_family_at_left hy }, { assume ε εpos, have : x ∈ Ioc (x - ε) x := ⟨by linarith, le_refl _⟩, filter_upwards [Icc_mem_nhds_within_Iio this] with y hy, rw closed_ball_eq_Icc, exact Icc_subset_Icc hy.1 (by linarith) } end end real
0968098e282f998ceb46106f0ff5cceb643cea81
a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940
/stage0/src/Lean/Data/Lsp/LanguageFeatures.lean
d5c02a452dff191fc85ebfe526d5724b9544ee51
[ "Apache-2.0" ]
permissive
WojciechKarpiel/lean4
7f89706b8e3c1f942b83a2c91a3a00b05da0e65b
f6e1314fa08293dea66a329e05b6c196a0189163
refs/heads/master
1,686,633,402,214
1,625,821,189,000
1,625,821,258,000
384,640,886
0
0
Apache-2.0
1,625,903,617,000
1,625,903,026,000
null
UTF-8
Lean
false
false
5,701
lean
/- Copyright (c) 2020 Wojciech Nawrocki. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Wojciech Nawrocki -/ import Lean.Data.Json import Lean.Data.Lsp.Basic namespace Lean namespace Lsp open Json structure CompletionOptions where triggerCharacters? : Option (Array String) := none allCommitCharacters? : Option (Array String) := none resolveProvider : Bool := false deriving FromJson, ToJson structure CompletionItem where label : String detail? : Option String documentation? : Option MarkupContent /- kind? : CompletionItemKind tags? : CompletionItemTag[] deprecated? : boolean preselect? : boolean sortText? : string filterText? : string insertText? : string insertTextFormat? : InsertTextFormat insertTextMode? : InsertTextMode textEdit? : TextEdit | InsertReplaceEdit additionalTextEdits? : TextEdit[] commitCharacters? : string[] command? : Command data? : any -/ deriving FromJson, ToJson, Inhabited structure CompletionList where isIncomplete : Bool items : Array CompletionItem deriving FromJson, ToJson structure CompletionParams extends TextDocumentPositionParams where -- context? : CompletionContext deriving FromJson, ToJson structure Hover where /- NOTE we should also accept MarkedString/MarkedString[] here but they are deprecated, so maybe can get away without. -/ contents : MarkupContent range? : Option Range := none deriving ToJson, FromJson structure HoverParams extends TextDocumentPositionParams deriving FromJson, ToJson structure DeclarationParams extends TextDocumentPositionParams deriving FromJson, ToJson structure DefinitionParams extends TextDocumentPositionParams deriving FromJson, ToJson structure TypeDefinitionParams extends TextDocumentPositionParams deriving FromJson, ToJson structure DocumentHighlightParams extends TextDocumentPositionParams deriving FromJson, ToJson inductive DocumentHighlightKind where | text | read | write instance : ToJson DocumentHighlightKind where toJson | DocumentHighlightKind.text => 1 | DocumentHighlightKind.read => 2 | DocumentHighlightKind.write => 3 structure DocumentHighlight where range : Range kind? : Option DocumentHighlightKind := none deriving ToJson abbrev DocumentHighlightResult := Array DocumentHighlight structure DocumentSymbolParams where textDocument : TextDocumentIdentifier deriving FromJson, ToJson inductive SymbolKind where | file | module | «namespace» | package | «class» | method | property | field | constructor | enum | interface | function | «variable» | «constant» | string | number | boolean | array | object | key | null | enumMember | struct | event | operator | typeParameter instance : ToJson SymbolKind where toJson | SymbolKind.file => 1 | SymbolKind.module => 2 | SymbolKind.namespace => 3 | SymbolKind.package => 4 | SymbolKind.class => 5 | SymbolKind.method => 6 | SymbolKind.property => 7 | SymbolKind.field => 8 | SymbolKind.constructor => 9 | SymbolKind.enum => 10 | SymbolKind.interface => 11 | SymbolKind.function => 12 | SymbolKind.variable => 13 | SymbolKind.constant => 14 | SymbolKind.string => 15 | SymbolKind.number => 16 | SymbolKind.boolean => 17 | SymbolKind.array => 18 | SymbolKind.object => 19 | SymbolKind.key => 20 | SymbolKind.null => 21 | SymbolKind.enumMember => 22 | SymbolKind.struct => 23 | SymbolKind.event => 24 | SymbolKind.operator => 25 | SymbolKind.typeParameter => 26 structure DocumentSymbolAux (Self : Type) where name : String detail? : Option String := none kind : SymbolKind -- tags? : Array SymbolTag range : Range selectionRange : Range children? : Option (Array Self) := none deriving ToJson inductive DocumentSymbol where | mk (sym : DocumentSymbolAux DocumentSymbol) partial instance : ToJson DocumentSymbol where toJson := let rec go | DocumentSymbol.mk sym => have : ToJson DocumentSymbol := ⟨go⟩ toJson sym go structure DocumentSymbolResult where syms : Array DocumentSymbol instance : ToJson DocumentSymbolResult where toJson dsr := toJson dsr.syms inductive SemanticTokenType where | keyword | «variable» | property /- | «namespace» | type | «class» | enum | interface | struct | typeParameter | parameter | enumMember | event | function | method | «macro» | modifier | comment | string | number | regexp | operator -/ def SemanticTokenType.names : Array String := #["keyword", "variable", "property"] -- must be the correct index in `names` def SemanticTokenType.toNat : SemanticTokenType → Nat | keyword => 0 | «variable» => 1 | property => 2 /- inductive SemanticTokenModifier where | declaration | definition | readonly | static | deprecated | abstract | async | modification | documentation | defaultLibrary -/ structure SemanticTokensLegend where tokenTypes : Array String tokenModifiers : Array String deriving FromJson, ToJson structure SemanticTokensOptions where legend : SemanticTokensLegend range : Bool full : Bool /- | { delta?: boolean; } -/ deriving FromJson, ToJson structure SemanticTokensParams where textDocument : TextDocumentIdentifier deriving FromJson, ToJson structure SemanticTokensRangeParams where textDocument : TextDocumentIdentifier range : Range deriving FromJson, ToJson structure SemanticTokens where -- resultId?: string; data : Array Nat deriving FromJson, ToJson end Lsp end Lean
9560646e426bfd45c00baebd0caa019932a6c4e3
bbecf0f1968d1fba4124103e4f6b55251d08e9c4
/src/algebra/big_operators/finprod.lean
bb7054f915206737674307af19c58e591292117d
[ "Apache-2.0" ]
permissive
waynemunro/mathlib
e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552
065a70810b5480d584033f7bbf8e0409480c2118
refs/heads/master
1,693,417,182,397
1,634,644,781,000
1,634,644,781,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
38,818
lean
/- Copyright (c) 2020 Kexing Ying and Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Kevin Buzzard, Yury Kudryashov -/ import algebra.big_operators.order import algebra.indicator_function import data.set.pairwise /-! # Finite products and sums over types and sets We define products and sums over types and subsets of types, with no finiteness hypotheses. All infinite products and sums are defined to be junk values (i.e. one or zero). This approach is sometimes easier to use than `finset.sum`, when issues arise with `finset` and `fintype` being data. ## Main definitions We use the following variables: * `α`, `β` - types with no structure; * `s`, `t` - sets * `M`, `N` - additive or multiplicative commutative monoids * `f`, `g` - functions Definitions in this file: * `finsum f : M` : the sum of `f x` as `x` ranges over the support of `f`, if it's finite. Zero otherwise. * `finprod f : M` : the product of `f x` as `x` ranges over the multiplicative support of `f`, if it's finite. One otherwise. ## Notation * `∑ᶠ i, f i` and `∑ᶠ i : α, f i` for `finsum f` * `∏ᶠ i, f i` and `∏ᶠ i : α, f i` for `finprod f` This notation works for functions `f : p → M`, where `p : Prop`, so the following works: * `∑ᶠ i ∈ s, f i`, where `f : α → M`, `s : set α` : sum over the set `s`; * `∑ᶠ n < 5, f n`, where `f : ℕ → M` : same as `f 0 + f 1 + f 2 + f 3 + f 4`; * `∏ᶠ (n >= -2) (hn : n < 3), f n`, where `f : ℤ → M` : same as `f (-2) * f (-1) * f 0 * f 1 * f 2`. ## Implementation notes `finsum` and `finprod` is "yet another way of doing finite sums and products in Lean". However experiments in the wild (e.g. with matroids) indicate that it is a helpful approach in settings where the user is not interested in computability and wants to do reasoning without running into typeclass diamonds caused by the constructive finiteness used in definitions such as `finset` and `fintype`. By sticking solely to `set.finite` we avoid these problems. We are aware that there are other solutions but for beginner mathematicians this approach is easier in practice. Another application is the construction of a partition of unity from a collection of “bump” function. In this case the finite set depends on the point and it's convenient to have a definition that does not mention the set explicitly. The first arguments in all definitions and lemmas is the codomain of the function of the big operator. This is necessary for the heuristic in `@[to_additive]`. See the documentation of `to_additive.attr` for more information. ## Todo We did not add `is_finite (X : Type) : Prop`, because it is simply `nonempty (fintype X)`. There is work on `fincard` in the pipeline, which returns the cardinality of `X` if it is finite, and 0 otherwise. ## Tags finsum, finprod, finite sum, finite product -/ open function set /-! ### Definition and relation to `finset.sum` and `finset.prod` -/ section sort variables {M N : Type*} {α β ι : Sort*} [comm_monoid M] [comm_monoid N] open_locale big_operators section /- Note: we use classical logic only for these definitions, to ensure that we do not write lemmas with `classical.dec` in their statement. -/ open_locale classical /-- Sum of `f x` as `x` ranges over the elements of the support of `f`, if it's finite. Zero otherwise. -/ @[irreducible] noncomputable def finsum {M α} [add_comm_monoid M] (f : α → M) : M := if h : finite (support (f ∘ plift.down)) then ∑ i in h.to_finset, f i.down else 0 /-- Product of `f x` as `x` ranges over the elements of the multiplicative support of `f`, if it's finite. One otherwise. -/ @[irreducible, to_additive] noncomputable def finprod (f : α → M) : M := if h : finite (mul_support (f ∘ plift.down)) then ∏ i in h.to_finset, f i.down else 1 end localized "notation `∑ᶠ` binders `, ` r:(scoped:67 f, finsum f) := r" in big_operators localized "notation `∏ᶠ` binders `, ` r:(scoped:67 f, finprod f) := r" in big_operators @[to_additive] lemma finprod_eq_prod_plift_of_mul_support_to_finset_subset {f : α → M} (hf : finite (mul_support (f ∘ plift.down))) {s : finset (plift α)} (hs : hf.to_finset ⊆ s) : ∏ᶠ i, f i = ∏ i in s, f i.down := begin rw [finprod, dif_pos], refine finset.prod_subset hs (λ x hx hxf, _), rwa [hf.mem_to_finset, nmem_mul_support] at hxf end @[to_additive] lemma finprod_eq_prod_plift_of_mul_support_subset {f : α → M} {s : finset (plift α)} (hs : mul_support (f ∘ plift.down) ⊆ s) : ∏ᶠ i, f i = ∏ i in s, f i.down := finprod_eq_prod_plift_of_mul_support_to_finset_subset (s.finite_to_set.subset hs) $ λ x hx, by { rw finite.mem_to_finset at hx, exact hs hx } @[simp, to_additive] lemma finprod_one : ∏ᶠ i : α, (1 : M) = 1 := begin have : mul_support (λ x : plift α, (λ _, 1 : α → M) x.down) ⊆ (∅ : finset (plift α)), from λ x h, h rfl, rw [finprod_eq_prod_plift_of_mul_support_subset this, finset.prod_empty] end @[to_additive] lemma finprod_of_is_empty [is_empty α] (f : α → M) : ∏ᶠ i, f i = 1 := by { rw ← finprod_one, congr } @[simp, to_additive] lemma finprod_false (f : false → M) : ∏ᶠ i, f i = 1 := finprod_of_is_empty _ @[to_additive] lemma finprod_eq_single (f : α → M) (a : α) (ha : ∀ x ≠ a, f x = 1) : ∏ᶠ x, f x = f a := begin have : mul_support (f ∘ plift.down) ⊆ ({plift.up a} : finset (plift α)), { intro x, contrapose, simpa [plift.eq_up_iff_down_eq] using ha x.down }, rw [finprod_eq_prod_plift_of_mul_support_subset this, finset.prod_singleton], end @[to_additive] lemma finprod_unique [unique α] (f : α → M) : ∏ᶠ i, f i = f (default α) := finprod_eq_single f (default α) $ λ x hx, (hx $ unique.eq_default _).elim @[simp, to_additive] lemma finprod_true (f : true → M) : ∏ᶠ i, f i = f trivial := @finprod_unique M true _ ⟨⟨trivial⟩, λ _, rfl⟩ f @[to_additive] lemma finprod_eq_dif {p : Prop} [decidable p] (f : p → M) : ∏ᶠ i, f i = if h : p then f h else 1 := begin split_ifs, { haveI : unique p := ⟨⟨h⟩, λ _, rfl⟩, exact finprod_unique f }, { haveI : is_empty p := ⟨h⟩, exact finprod_of_is_empty f } end @[to_additive] lemma finprod_eq_if {p : Prop} [decidable p] {x : M} : ∏ᶠ i : p, x = if p then x else 1 := finprod_eq_dif (λ _, x) @[to_additive] lemma finprod_congr {f g : α → M} (h : ∀ x, f x = g x) : finprod f = finprod g := congr_arg _ $ funext h @[congr, to_additive] lemma finprod_congr_Prop {p q : Prop} {f : p → M} {g : q → M} (hpq : p = q) (hfg : ∀ h : q, f (hpq.mpr h) = g h) : finprod f = finprod g := by { subst q, exact finprod_congr hfg } attribute [congr] finsum_congr_Prop /-- To prove a property of a finite product, it suffices to prove that the property is multiplicative and holds on multipliers. -/ @[to_additive] lemma finprod_induction {f : α → M} (p : M → Prop) (hp₀ : p 1) (hp₁ : ∀ x y, p x → p y → p (x * y)) (hp₂ : ∀ i, p (f i)) : p (∏ᶠ i, f i) := begin rw finprod, split_ifs, exacts [finset.prod_induction _ _ hp₁ hp₀ (λ i hi, hp₂ _), hp₀] end /-- To prove a property of a finite sum, it suffices to prove that the property is additive and holds on summands. -/ add_decl_doc finsum_induction lemma finprod_nonneg {R : Type*} [ordered_comm_semiring R] {f : α → R} (hf : ∀ x, 0 ≤ f x) : 0 ≤ ∏ᶠ x, f x := finprod_induction (λ x, 0 ≤ x) zero_le_one (λ x y, mul_nonneg) hf @[to_additive finsum_nonneg] lemma one_le_finprod' {M : Type*} [ordered_comm_monoid M] {f : α → M} (hf : ∀ i, 1 ≤ f i) : 1 ≤ ∏ᶠ i, f i := finprod_induction _ le_rfl (λ _ _, one_le_mul) hf @[to_additive] lemma monoid_hom.map_finprod_plift (f : M →* N) (g : α → M) (h : finite (mul_support $ g ∘ plift.down)) : f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) := begin rw [finprod_eq_prod_plift_of_mul_support_subset h.coe_to_finset.ge, finprod_eq_prod_plift_of_mul_support_subset, f.map_prod], rw [h.coe_to_finset], exact mul_support_comp_subset f.map_one (g ∘ plift.down) end @[to_additive] lemma monoid_hom.map_finprod_Prop {p : Prop} (f : M →* N) (g : p → M) : f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) := f.map_finprod_plift g (finite.of_fintype _) @[to_additive] lemma monoid_hom.map_finprod_of_preimage_one (f : M →* N) (hf : ∀ x, f x = 1 → x = 1) (g : α → M) : f (∏ᶠ i, g i) = ∏ᶠ i, f (g i) := begin by_cases hg : (mul_support $ g ∘ plift.down).finite, { exact f.map_finprod_plift g hg }, rw [finprod, dif_neg, f.map_one, finprod, dif_neg], exacts [infinite.mono (λ x hx, mt (hf (g x.down)) hx) hg, hg] end @[to_additive] lemma monoid_hom.map_finprod_of_injective (g : M →* N) (hg : injective g) (f : α → M) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) := g.map_finprod_of_preimage_one (λ x, (hg.eq_iff' g.map_one).mp) f @[to_additive] lemma mul_equiv.map_finprod (g : M ≃* N) (f : α → M) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) := g.to_monoid_hom.map_finprod_of_injective g.injective f lemma finsum_smul {R M : Type*} [ring R] [add_comm_group M] [module R M] [no_zero_smul_divisors R M] (f : ι → R) (x : M) : (∑ᶠ i, f i) • x = (∑ᶠ i, (f i) • x) := begin rcases eq_or_ne x 0 with rfl|hx, { simp }, exact ((smul_add_hom R M).flip x).map_finsum_of_injective (smul_left_injective R hx) _ end lemma smul_finsum {R M : Type*} [ring R] [add_comm_group M] [module R M] [no_zero_smul_divisors R M] (c : R) (f : ι → M) : c • (∑ᶠ i, f i) = (∑ᶠ i, c • f i) := begin rcases eq_or_ne c 0 with rfl|hc, { simp }, exact (smul_add_hom R M c).map_finsum_of_injective (smul_right_injective M hc) _ end @[to_additive] lemma finprod_inv_distrib {G : Type*} [comm_group G] (f : α → G) : ∏ᶠ x, (f x)⁻¹ = (∏ᶠ x, f x)⁻¹ := ((mul_equiv.inv G).map_finprod f).symm end sort section type variables {α β ι M N : Type*} [comm_monoid M] [comm_monoid N] open_locale big_operators @[to_additive] lemma finprod_eq_mul_indicator_apply (s : set α) (f : α → M) (a : α) : ∏ᶠ (h : a ∈ s), f a = mul_indicator s f a := by convert finprod_eq_if @[simp, to_additive] lemma finprod_mem_mul_support (f : α → M) (a : α) : ∏ᶠ (h : f a ≠ 1), f a = f a := by rw [← mem_mul_support, finprod_eq_mul_indicator_apply, mul_indicator_mul_support] @[to_additive] lemma finprod_mem_def (s : set α) (f : α → M) : ∏ᶠ a ∈ s, f a = ∏ᶠ a, mul_indicator s f a := finprod_congr $ finprod_eq_mul_indicator_apply s f @[to_additive] lemma finprod_eq_prod_of_mul_support_subset (f : α → M) {s : finset α} (h : mul_support f ⊆ s) : ∏ᶠ i, f i = ∏ i in s, f i := begin have A : mul_support (f ∘ plift.down) = equiv.plift.symm '' mul_support f, { rw mul_support_comp_eq_preimage, exact (equiv.plift.symm.image_eq_preimage _).symm }, have : mul_support (f ∘ plift.down) ⊆ s.map equiv.plift.symm.to_embedding, { rw [A, finset.coe_map], exact image_subset _ h }, rw [finprod_eq_prod_plift_of_mul_support_subset this], simp end @[to_additive] lemma finprod_eq_prod_of_mul_support_to_finset_subset (f : α → M) (hf : finite (mul_support f)) {s : finset α} (h : hf.to_finset ⊆ s) : ∏ᶠ i, f i = ∏ i in s, f i := finprod_eq_prod_of_mul_support_subset _ $ λ x hx, h $ hf.mem_to_finset.2 hx @[to_additive] lemma finprod_def (f : α → M) [decidable (mul_support f).finite] : ∏ᶠ i : α, f i = if h : (mul_support f).finite then ∏ i in h.to_finset, f i else 1 := begin split_ifs, { exact finprod_eq_prod_of_mul_support_to_finset_subset _ h (finset.subset.refl _) }, { rw [finprod, dif_neg], rw [mul_support_comp_eq_preimage], exact mt (λ hf, hf.of_preimage equiv.plift.surjective) h} end @[to_additive] lemma finprod_of_infinite_mul_support {f : α → M} (hf : (mul_support f).infinite) : ∏ᶠ i, f i = 1 := by { classical, rw [finprod_def, dif_neg hf] } @[to_additive] lemma finprod_eq_prod (f : α → M) (hf : (mul_support f).finite) : ∏ᶠ i : α, f i = ∏ i in hf.to_finset, f i := by { classical, rw [finprod_def, dif_pos hf] } @[to_additive] lemma finprod_eq_prod_of_fintype [fintype α] (f : α → M) : ∏ᶠ i : α, f i = ∏ i, f i := finprod_eq_prod_of_mul_support_to_finset_subset _ (finite.of_fintype _) $ finset.subset_univ _ @[to_additive] lemma finprod_cond_eq_prod_of_cond_iff (f : α → M) {p : α → Prop} {t : finset α} (h : ∀ {x}, f x ≠ 1 → (p x ↔ x ∈ t)) : ∏ᶠ i (hi : p i), f i = ∏ i in t, f i := begin set s := {x | p x}, have : mul_support (s.mul_indicator f) ⊆ t, { rw [set.mul_support_mul_indicator], intros x hx, exact (h hx.2).1 hx.1 }, erw [finprod_mem_def, finprod_eq_prod_of_mul_support_subset _ this], refine finset.prod_congr rfl (λ x hx, mul_indicator_apply_eq_self.2 $ λ hxs, _), contrapose! hxs, exact (h hxs).2 hx end @[to_additive] lemma finprod_mem_eq_prod_of_inter_mul_support_eq (f : α → M) {s : set α} {t : finset α} (h : s ∩ mul_support f = t ∩ mul_support f) : ∏ᶠ i ∈ s, f i = ∏ i in t, f i := finprod_cond_eq_prod_of_cond_iff _ $ by simpa [set.ext_iff] using h @[to_additive] lemma finprod_mem_eq_prod_of_subset (f : α → M) {s : set α} {t : finset α} (h₁ : s ∩ mul_support f ⊆ t) (h₂ : ↑t ⊆ s) : ∏ᶠ i ∈ s, f i = ∏ i in t, f i := finprod_cond_eq_prod_of_cond_iff _ $ λ x hx, ⟨λ h, h₁ ⟨h, hx⟩, λ h, h₂ h⟩ @[to_additive] lemma finprod_mem_eq_prod (f : α → M) {s : set α} (hf : (s ∩ mul_support f).finite) : ∏ᶠ i ∈ s, f i = ∏ i in hf.to_finset, f i := finprod_mem_eq_prod_of_inter_mul_support_eq _ $ by simp [inter_assoc] @[to_additive] lemma finprod_mem_eq_prod_filter (f : α → M) (s : set α) [decidable_pred (∈ s)] (hf : (mul_support f).finite) : ∏ᶠ i ∈ s, f i = ∏ i in finset.filter (∈ s) hf.to_finset, f i := finprod_mem_eq_prod_of_inter_mul_support_eq _ $ by simp [inter_comm, inter_left_comm] @[to_additive] lemma finprod_mem_eq_to_finset_prod (f : α → M) (s : set α) [fintype s] : ∏ᶠ i ∈ s, f i = ∏ i in s.to_finset, f i := finprod_mem_eq_prod_of_inter_mul_support_eq _ $ by rw [coe_to_finset] @[to_additive] lemma finprod_mem_eq_finite_to_finset_prod (f : α → M) {s : set α} (hs : s.finite) : ∏ᶠ i ∈ s, f i = ∏ i in hs.to_finset, f i := finprod_mem_eq_prod_of_inter_mul_support_eq _ $ by rw [hs.coe_to_finset] @[to_additive] lemma finprod_mem_finset_eq_prod (f : α → M) (s : finset α) : ∏ᶠ i ∈ s, f i = ∏ i in s, f i := finprod_mem_eq_prod_of_inter_mul_support_eq _ rfl @[to_additive] lemma finprod_mem_coe_finset (f : α → M) (s : finset α) : ∏ᶠ i ∈ (s : set α), f i = ∏ i in s, f i := finprod_mem_eq_prod_of_inter_mul_support_eq _ rfl @[to_additive] lemma finprod_mem_eq_one_of_infinite {f : α → M} {s : set α} (hs : (s ∩ mul_support f).infinite) : ∏ᶠ i ∈ s, f i = 1 := begin rw finprod_mem_def, apply finprod_of_infinite_mul_support, rwa [← mul_support_mul_indicator] at hs end @[to_additive] lemma finprod_mem_inter_mul_support (f : α → M) (s : set α) : ∏ᶠ i ∈ (s ∩ mul_support f), f i = ∏ᶠ i ∈ s, f i := by rw [finprod_mem_def, finprod_mem_def, mul_indicator_inter_mul_support] @[to_additive] lemma finprod_mem_inter_mul_support_eq (f : α → M) (s t : set α) (h : s ∩ mul_support f = t ∩ mul_support f) : ∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_inter_mul_support, h, finprod_mem_inter_mul_support] @[to_additive] lemma finprod_mem_inter_mul_support_eq' (f : α → M) (s t : set α) (h : ∀ x ∈ mul_support f, x ∈ s ↔ x ∈ t) : ∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, f i := begin apply finprod_mem_inter_mul_support_eq, ext x, exact and_congr_left (h x) end @[to_additive] lemma finprod_mem_univ (f : α → M) : ∏ᶠ i ∈ @set.univ α, f i = ∏ᶠ i : α, f i := finprod_congr $ λ i, finprod_true _ variables {f g : α → M} {a b : α} {s t : set α} @[to_additive] lemma finprod_mem_congr (h₀ : s = t) (h₁ : ∀ x ∈ t, f x = g x) : ∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, g i := h₀.symm ▸ (finprod_congr $ λ i, finprod_congr_Prop rfl (h₁ i)) /-! ### Distributivity w.r.t. addition, subtraction, and (scalar) multiplication -/ /-- If the multiplicative supports of `f` and `g` are finite, then the product of `f i * g i` equals the product of `f i` multiplied by the product over `g i`. -/ @[to_additive] lemma finprod_mul_distrib (hf : (mul_support f).finite) (hg : (mul_support g).finite) : ∏ᶠ i, (f i * g i) = (∏ᶠ i, f i) * ∏ᶠ i, g i := begin classical, rw [finprod_eq_prod_of_mul_support_to_finset_subset _ hf (finset.subset_union_left _ _), finprod_eq_prod_of_mul_support_to_finset_subset _ hg (finset.subset_union_right _ _), ← finset.prod_mul_distrib], refine finprod_eq_prod_of_mul_support_subset _ _, simp [mul_support_mul] end /-- A more general version of `finprod_mem_mul_distrib` that requires `s ∩ mul_support f` and `s ∩ mul_support g` instead of `s` to be finite. -/ @[to_additive] lemma finprod_mem_mul_distrib' (hf : (s ∩ mul_support f).finite) (hg : (s ∩ mul_support g).finite) : ∏ᶠ i ∈ s, (f i * g i) = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ s, g i := begin rw [← mul_support_mul_indicator] at hf hg, simp only [finprod_mem_def, mul_indicator_mul, finprod_mul_distrib hf hg] end /-- The product of constant one over any set equals one. -/ @[to_additive] lemma finprod_mem_one (s : set α) : ∏ᶠ i ∈ s, (1 : M) = 1 := by simp /-- If a function `f` equals one on a set `s`, then the product of `f i` over `i ∈ s` equals one. -/ @[to_additive] lemma finprod_mem_of_eq_on_one (hf : eq_on f 1 s) : ∏ᶠ i ∈ s, f i = 1 := by { rw ← finprod_mem_one s, exact finprod_mem_congr rfl hf } /-- If the product of `f i` over `i ∈ s` is not equal to one, then there is some `x ∈ s` such that `f x ≠ 1`. -/ @[to_additive] lemma exists_ne_one_of_finprod_mem_ne_one (h : ∏ᶠ i ∈ s, f i ≠ 1) : ∃ x ∈ s, f x ≠ 1 := begin by_contra h', push_neg at h', exact h (finprod_mem_of_eq_on_one h') end /-- Given a finite set `s`, the product of `f i * g i` over `i ∈ s` equals the product of `f i` over `i ∈ s` times the product of `g i` over `i ∈ s`. -/ @[to_additive] lemma finprod_mem_mul_distrib (hs : s.finite) : ∏ᶠ i ∈ s, (f i * g i) = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ s, g i := finprod_mem_mul_distrib' (hs.inter_of_left _) (hs.inter_of_left _) @[to_additive] lemma monoid_hom.map_finprod {f : α → M} (g : M →* N) (hf : (mul_support f).finite) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) := g.map_finprod_plift f $ hf.preimage $ equiv.plift.injective.inj_on _ /-- A more general version of `monoid_hom.map_finprod_mem` that requires `s ∩ mul_support f` and instead of `s` to be finite. -/ @[to_additive] lemma monoid_hom.map_finprod_mem' {f : α → M} (g : M →* N) (h₀ : (s ∩ mul_support f).finite) : g (∏ᶠ j ∈ s, f j) = ∏ᶠ i ∈ s, (g (f i)) := begin rw [g.map_finprod], { simp only [g.map_finprod_Prop] }, { simpa only [finprod_eq_mul_indicator_apply, mul_support_mul_indicator] } end /-- Given a monoid homomorphism `g : M →* N`, and a function `f : α → M`, the value of `g` at the product of `f i` over `i ∈ s` equals the product of `(g ∘ f) i` over `s`. -/ @[to_additive] lemma monoid_hom.map_finprod_mem (f : α → M) (g : M →* N) (hs : s.finite) : g (∏ᶠ j ∈ s, f j) = ∏ᶠ i ∈ s, g (f i) := g.map_finprod_mem' (hs.inter_of_left _) /-! ### `∏ᶠ x ∈ s, f x` and set operations -/ /-- The product of any function over an empty set is one. -/ @[to_additive] lemma finprod_mem_empty : ∏ᶠ i ∈ (∅ : set α), f i = 1 := by simp /-- A set `s` is not empty if the product of some function over `s` is not equal to one. -/ @[to_additive] lemma nonempty_of_finprod_mem_ne_one (h : ∏ᶠ i ∈ s, f i ≠ 1) : s.nonempty := ne_empty_iff_nonempty.1 $ λ h', h $ h'.symm ▸ finprod_mem_empty /-- Given finite sets `s` and `t`, the product of `f i` over `i ∈ s ∪ t` times the product of `f i` over `i ∈ s ∩ t` equals the product of `f i` over `i ∈ s` times the product of `f i` over `i ∈ t`. -/ @[to_additive] lemma finprod_mem_union_inter (hs : s.finite) (ht : t.finite) : (∏ᶠ i ∈ s ∪ t, f i) * ∏ᶠ i ∈ s ∩ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := begin lift s to finset α using hs, lift t to finset α using ht, classical, rw [← finset.coe_union, ← finset.coe_inter], simp only [finprod_mem_coe_finset, finset.prod_union_inter] end /-- A more general version of `finprod_mem_union_inter` that requires `s ∩ mul_support f` and `t ∩ mul_support f` instead of `s` and `t` to be finite. -/ @[to_additive] lemma finprod_mem_union_inter' (hs : (s ∩ mul_support f).finite) (ht : (t ∩ mul_support f).finite) : (∏ᶠ i ∈ s ∪ t, f i) * ∏ᶠ i ∈ s ∩ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := begin rw [← finprod_mem_inter_mul_support f s, ← finprod_mem_inter_mul_support f t, ← finprod_mem_union_inter hs ht, ← union_inter_distrib_right, finprod_mem_inter_mul_support, ← finprod_mem_inter_mul_support f (s ∩ t)], congr' 2, rw [inter_left_comm, inter_assoc, inter_assoc, inter_self, inter_left_comm] end /-- A more general version of `finprod_mem_union` that requires `s ∩ mul_support f` and `t ∩ mul_support f` instead of `s` and `t` to be finite. -/ @[to_additive] lemma finprod_mem_union' (hst : disjoint s t) (hs : (s ∩ mul_support f).finite) (ht : (t ∩ mul_support f).finite) : ∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_union_inter' hs ht, disjoint_iff_inter_eq_empty.1 hst, finprod_mem_empty, mul_one] /-- Given two finite disjoint sets `s` and `t`, the product of `f i` over `i ∈ s ∪ t` equals the product of `f i` over `i ∈ s` times the product of `f i` over `i ∈ t`. -/ @[to_additive] lemma finprod_mem_union (hst : disjoint s t) (hs : s.finite) (ht : t.finite) : ∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := finprod_mem_union' hst (hs.inter_of_left _) (ht.inter_of_left _) /-- A more general version of `finprod_mem_union'` that requires `s ∩ mul_support f` and `t ∩ mul_support f` instead of `s` and `t` to be disjoint -/ @[to_additive] lemma finprod_mem_union'' (hst : disjoint (s ∩ mul_support f) (t ∩ mul_support f)) (hs : (s ∩ mul_support f).finite) (ht : (t ∩ mul_support f).finite) : ∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_inter_mul_support f s, ← finprod_mem_inter_mul_support f t, ← finprod_mem_union hst hs ht, ← union_inter_distrib_right, finprod_mem_inter_mul_support] /-- The product of `f i` over `i ∈ {a}` equals `f a`. -/ @[to_additive] lemma finprod_mem_singleton : ∏ᶠ i ∈ ({a} : set α), f i = f a := by rw [← finset.coe_singleton, finprod_mem_coe_finset, finset.prod_singleton] @[simp, to_additive] lemma finprod_cond_eq_left : ∏ᶠ i = a, f i = f a := finprod_mem_singleton @[simp, to_additive] lemma finprod_cond_eq_right : ∏ᶠ i (hi : a = i), f i = f a := by simp [@eq_comm _ a] /-- A more general version of `finprod_mem_insert` that requires `s ∩ mul_support f` instead of `s` to be finite. -/ @[to_additive] lemma finprod_mem_insert' (f : α → M) (h : a ∉ s) (hs : (s ∩ mul_support f).finite) : ∏ᶠ i ∈ insert a s, f i = f a * ∏ᶠ i ∈ s, f i := begin rw [insert_eq, finprod_mem_union' _ _ hs, finprod_mem_singleton], { rwa disjoint_singleton_left }, { exact (finite_singleton a).inter_of_left _ } end /-- Given a finite set `s` and an element `a ∉ s`, the product of `f i` over `i ∈ insert a s` equals `f a` times the product of `f i` over `i ∈ s`. -/ @[to_additive] lemma finprod_mem_insert (f : α → M) (h : a ∉ s) (hs : s.finite) : ∏ᶠ i ∈ insert a s, f i = f a * ∏ᶠ i ∈ s, f i := finprod_mem_insert' f h $ hs.inter_of_left _ /-- If `f a = 1` for all `a ∉ s`, then the product of `f i` over `i ∈ insert a s` equals the product of `f i` over `i ∈ s`. -/ @[to_additive] lemma finprod_mem_insert_of_eq_one_if_not_mem (h : a ∉ s → f a = 1) : ∏ᶠ i ∈ (insert a s), f i = ∏ᶠ i ∈ s, f i := begin refine finprod_mem_inter_mul_support_eq' _ _ _ (λ x hx, ⟨_, or.inr⟩), rintro (rfl|hxs), exacts [not_imp_comm.1 h hx, hxs] end /-- If `f a = 1`, then the product of `f i` over `i ∈ insert a s` equals the product of `f i` over `i ∈ s`. -/ @[to_additive] lemma finprod_mem_insert_one (h : f a = 1) : ∏ᶠ i ∈ (insert a s), f i = ∏ᶠ i ∈ s, f i := finprod_mem_insert_of_eq_one_if_not_mem (λ _, h) /-- If the multiplicative support of `f` is finite, then for every `x` in the domain of `f`, `f x` divides `finprod f`. -/ lemma finprod_mem_dvd {f : α → N} (a : α) (hf : finite (mul_support f)) : f a ∣ finprod f := begin by_cases ha : a ∈ mul_support f, { rw finprod_eq_prod_of_mul_support_to_finset_subset f hf (set.subset.refl _), exact finset.dvd_prod_of_mem f ((finite.mem_to_finset hf).mpr ha) }, { rw nmem_mul_support.mp ha, exact one_dvd (finprod f) } end /-- The product of `f i` over `i ∈ {a, b}`, `a ≠ b`, is equal to `f a * f b`. -/ @[to_additive] lemma finprod_mem_pair (h : a ≠ b) : ∏ᶠ i ∈ ({a, b} : set α), f i = f a * f b := by { rw [finprod_mem_insert, finprod_mem_singleton], exacts [h, finite_singleton b] } /-- The product of `f y` over `y ∈ g '' s` equals the product of `f (g i)` over `s` provided that `g` is injective on `s ∩ mul_support (f ∘ g)`. -/ @[to_additive] lemma finprod_mem_image' {s : set β} {g : β → α} (hg : set.inj_on g (s ∩ mul_support (f ∘ g))) : ∏ᶠ i ∈ (g '' s), f i = ∏ᶠ j ∈ s, f (g j) := begin classical, by_cases hs : finite (s ∩ mul_support (f ∘ g)), { have hg : ∀ (x ∈ hs.to_finset) (y ∈ hs.to_finset), g x = g y → x = y, by simpa only [hs.mem_to_finset], rw [finprod_mem_eq_prod _ hs, ← finset.prod_image hg], refine finprod_mem_eq_prod_of_inter_mul_support_eq f _, rw [finset.coe_image, hs.coe_to_finset, ← image_inter_mul_support_eq, inter_assoc, inter_self] }, { rw [finprod_mem_eq_one_of_infinite hs, finprod_mem_eq_one_of_infinite], rwa [image_inter_mul_support_eq, infinite_image_iff hg] } end /-- The product of `f y` over `y ∈ g '' s` equals the product of `f (g i)` over `s` provided that `g` is injective on `s`. -/ @[to_additive] lemma finprod_mem_image {β} {s : set β} {g : β → α} (hg : set.inj_on g s) : ∏ᶠ i ∈ (g '' s), f i = ∏ᶠ j ∈ s, f (g j) := finprod_mem_image' $ hg.mono $ inter_subset_left _ _ /-- The product of `f y` over `y ∈ set.range g` equals the product of `f (g i)` over all `i` provided that `g` is injective on `mul_support (f ∘ g)`. -/ @[to_additive] lemma finprod_mem_range' {g : β → α} (hg : set.inj_on g (mul_support (f ∘ g))) : ∏ᶠ i ∈ range g, f i = ∏ᶠ j, f (g j) := begin rw [← image_univ, finprod_mem_image', finprod_mem_univ], rwa univ_inter end /-- The product of `f y` over `y ∈ set.range g` equals the product of `f (g i)` over all `i` provided that `g` is injective. -/ @[to_additive] lemma finprod_mem_range {g : β → α} (hg : injective g) : ∏ᶠ i ∈ range g, f i = ∏ᶠ j, f (g j) := finprod_mem_range' (hg.inj_on _) /-- The product of `f i` over `s : set α` is equal to the product of `g j` over `t : set β` if there exists a function `e : α → β` such that `e` is bijective from `s` to `t` and for all `x` in `s` we have `f x = g (e x)`. -/ @[to_additive] lemma finprod_mem_eq_of_bij_on {s : set α} {t : set β} {f : α → M} {g : β → M} (e : α → β) (he₀ : set.bij_on e s t) (he₁ : ∀ x ∈ s, f x = g (e x)) : ∏ᶠ i ∈ s, f i = ∏ᶠ j ∈ t, g j := begin rw [← set.bij_on.image_eq he₀, finprod_mem_image he₀.2.1], exact finprod_mem_congr rfl he₁ end @[to_additive] lemma finprod_set_coe_eq_finprod_mem (s : set α) : ∏ᶠ j : s, f j = ∏ᶠ i ∈ s, f i := begin rw [← finprod_mem_range, subtype.range_coe], exact subtype.coe_injective end @[to_additive] lemma finprod_subtype_eq_finprod_cond (p : α → Prop) : ∏ᶠ j : subtype p, f j = ∏ᶠ i (hi : p i), f i := finprod_set_coe_eq_finprod_mem {i | p i} @[to_additive] lemma finprod_mem_inter_mul_diff' (t : set α) (h : (s ∩ mul_support f).finite) : (∏ᶠ i ∈ s ∩ t, f i) * ∏ᶠ i ∈ s \ t, f i = ∏ᶠ i ∈ s, f i := begin rw [← finprod_mem_union', inter_union_diff], exacts [λ x hx, hx.2.2 hx.1.2, h.subset (λ x hx, ⟨hx.1.1, hx.2⟩), h.subset (λ x hx, ⟨hx.1.1, hx.2⟩)], end @[to_additive] lemma finprod_mem_inter_mul_diff (t : set α) (h : s.finite) : (∏ᶠ i ∈ s ∩ t, f i) * ∏ᶠ i ∈ s \ t, f i = ∏ᶠ i ∈ s, f i := finprod_mem_inter_mul_diff' _ $ h.inter_of_left _ /-- A more general version of `finprod_mem_mul_diff` that requires `t ∩ mul_support f` instead of `t` to be finite. -/ @[to_additive] lemma finprod_mem_mul_diff' (hst : s ⊆ t) (ht : (t ∩ mul_support f).finite) : (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t \ s, f i = ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_inter_mul_diff' _ ht, inter_eq_self_of_subset_right hst] /-- Given a finite set `t` and a subset `s` of `t`, the product of `f i` over `i ∈ s` times the product of `f i` over `t \ s` equals the product of `f i` over `i ∈ t`. -/ @[to_additive] lemma finprod_mem_mul_diff (hst : s ⊆ t) (ht : t.finite) : (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t \ s, f i = ∏ᶠ i ∈ t, f i := finprod_mem_mul_diff' hst (ht.inter_of_left _) /-- Given a family of pairwise disjoint finite sets `t i` indexed by a finite type, the product of `f a` over the union `⋃ i, t i` is equal to the product over all indexes `i` of the products of `f a` over `a ∈ t i`. -/ @[to_additive] lemma finprod_mem_Union [fintype ι] {t : ι → set α} (h : pairwise (disjoint on t)) (ht : ∀ i, (t i).finite) : ∏ᶠ a ∈ (⋃ i : ι, t i), f a = ∏ᶠ i, (∏ᶠ a ∈ t i, f a) := begin lift t to ι → finset α using ht, classical, rw [← bUnion_univ, ← finset.coe_univ, ← finset.coe_bUnion, finprod_mem_coe_finset, finset.prod_bUnion], { simp only [finprod_mem_coe_finset, finprod_eq_prod_of_fintype] }, { exact λ x _ y _ hxy, finset.disjoint_iff_disjoint_coe.2 (h x y hxy) } end /-- Given a family of sets `t : ι → set α`, a finite set `I` in the index type such that all sets `t i`, `i ∈ I`, are finite, if all `t i`, `i ∈ I`, are pairwise disjoint, then the product of `f a` over `a ∈ ⋃ i ∈ I, t i` is equal to the product over `i ∈ I` of the products of `f a` over `a ∈ t i`. -/ @[to_additive] lemma finprod_mem_bUnion {I : set ι} {t : ι → set α} (h : pairwise_on I (disjoint on t)) (hI : I.finite) (ht : ∀ i ∈ I, (t i).finite) : ∏ᶠ a ∈ ⋃ x ∈ I, t x, f a = ∏ᶠ i ∈ I, ∏ᶠ j ∈ t i, f j := begin haveI := hI.fintype, rw [← Union_subtype, finprod_mem_Union, ← finprod_set_coe_eq_finprod_mem], exacts [λ x y hxy, h x x.2 y y.2 (subtype.coe_injective.ne hxy), λ b, ht b b.2] end /-- If `t` is a finite set of pairwise disjoint finite sets, then the product of `f a` over `a ∈ ⋃₀ t` is the product over `s ∈ t` of the products of `f a` over `a ∈ s`. -/ @[to_additive] lemma finprod_mem_sUnion {t : set (set α)} (h : pairwise_on t disjoint) (ht₀ : t.finite) (ht₁ : ∀ x ∈ t, set.finite x): ∏ᶠ a ∈ ⋃₀ t, f a = ∏ᶠ s ∈ t, ∏ᶠ a ∈ s, f a := by rw [set.sUnion_eq_bUnion, finprod_mem_bUnion h ht₀ ht₁] /-- If `s : set α` and `t : set β` are finite sets, then the product over `s` commutes with the product over `t`. -/ @[to_additive] lemma finprod_mem_comm {s : set α} {t : set β} (f : α → β → M) (hs : s.finite) (ht : t.finite) : ∏ᶠ i ∈ s, ∏ᶠ j ∈ t, f i j = ∏ᶠ j ∈ t, ∏ᶠ i ∈ s, f i j := begin lift s to finset α using hs, lift t to finset β using ht, simp only [finprod_mem_coe_finset], exact finset.prod_comm end /-- To prove a property of a finite product, it suffices to prove that the property is multiplicative and holds on multipliers. -/ @[to_additive] lemma finprod_mem_induction (p : M → Prop) (hp₀ : p 1) (hp₁ : ∀ x y, p x → p y → p (x * y)) (hp₂ : ∀ x ∈ s, p $ f x) : p (∏ᶠ i ∈ s, f i) := finprod_induction _ hp₀ hp₁ $ λ x, finprod_induction _ hp₀ hp₁ $ hp₂ x lemma finprod_cond_nonneg {R : Type*} [ordered_comm_semiring R] {p : α → Prop} {f : α → R} (hf : ∀ x, p x → 0 ≤ f x) : 0 ≤ ∏ᶠ x (h : p x), f x := finprod_nonneg $ λ x, finprod_nonneg $ hf x @[to_additive] lemma single_le_finprod {M : Type*} [ordered_comm_monoid M] (i : α) {f : α → M} (hf : finite (mul_support f)) (h : ∀ j, 1 ≤ f j) : f i ≤ ∏ᶠ j, f j := by classical; calc f i ≤ ∏ j in insert i hf.to_finset, f j : finset.single_le_prod' (λ j hj, h j) (finset.mem_insert_self _ _) ... = ∏ᶠ j, f j : (finprod_eq_prod_of_mul_support_to_finset_subset _ hf (finset.subset_insert _ _)).symm lemma finprod_eq_zero {M₀ : Type*} [comm_monoid_with_zero M₀] (f : α → M₀) (x : α) (hx : f x = 0) (hf : finite (mul_support f)) : ∏ᶠ x, f x = 0 := begin nontriviality, rw [finprod_eq_prod f hf], refine finset.prod_eq_zero (hf.mem_to_finset.2 _) hx, simp [hx] end @[to_additive] lemma finprod_prod_comm (s : finset β) (f : α → β → M) (h : ∀ b ∈ s, (mul_support (λ a, f a b)).finite) : ∏ᶠ a : α, ∏ b in s, f a b = ∏ b in s, ∏ᶠ a : α, f a b := begin have hU : mul_support (λ a, ∏ b in s, f a b) ⊆ (s.finite_to_set.bUnion (λ b hb, h b (finset.mem_coe.1 hb))).to_finset, { rw finite.coe_to_finset, intros x hx, simp only [exists_prop, mem_Union, ne.def, mem_mul_support, finset.mem_coe], contrapose! hx, rw [mem_mul_support, not_not, finset.prod_congr rfl hx, finset.prod_const_one] }, rw [finprod_eq_prod_of_mul_support_subset _ hU, finset.prod_comm], refine finset.prod_congr rfl (λ b hb, (finprod_eq_prod_of_mul_support_subset _ _).symm), intros a ha, simp only [finite.coe_to_finset, mem_Union], exact ⟨b, hb, ha⟩ end @[to_additive] lemma prod_finprod_comm (s : finset α) (f : α → β → M) (h : ∀ a ∈ s, (mul_support (f a)).finite) : ∏ a in s, ∏ᶠ b : β, f a b = ∏ᶠ b : β, ∏ a in s, f a b := (finprod_prod_comm s (λ b a, f a b) h).symm lemma mul_finsum {R : Type*} [semiring R] (f : α → R) (r : R) (h : (function.support f).finite) : r * ∑ᶠ a : α, f a = ∑ᶠ a : α, r * f a := (add_monoid_hom.mul_left r).map_finsum h lemma finsum_mul {R : Type*} [semiring R] (f : α → R) (r : R) (h : (function.support f).finite) : (∑ᶠ a : α, f a) * r = ∑ᶠ a : α, f a * r := (add_monoid_hom.mul_right r).map_finsum h @[to_additive] lemma finset.mul_support_of_fiberwise_prod_subset_image [decidable_eq β] (s : finset α) (f : α → M) (g : α → β) : mul_support (λ b, (s.filter (λ a, g a = b)).prod f) ⊆ s.image g := begin simp only [finset.coe_image, set.mem_image, finset.mem_coe, function.support_subset_iff], intros b h, suffices : (s.filter (λ (a : α), g a = b)).nonempty, { simpa only [s.fiber_nonempty_iff_mem_image g b, finset.mem_image, exists_prop], }, exact finset.nonempty_of_prod_ne_one h, end /-- Note that `b ∈ (s.filter (λ ab, prod.fst ab = a)).image prod.snd` iff `(a, b) ∈ s` so we can simplify the right hand side of this lemma. However the form stated here is more useful for iterating this lemma, e.g., if we have `f : α × β × γ → M`. -/ @[to_additive] lemma finprod_mem_finset_product' [decidable_eq α] [decidable_eq β] (s : finset (α × β)) (f : α × β → M) : ∏ᶠ ab (h : ab ∈ s), f ab = ∏ᶠ a b (h : b ∈ (s.filter (λ ab, prod.fst ab = a)).image prod.snd), f (a, b) := begin have : ∀ a, ∏ (i : β) in (s.filter (λ ab, prod.fst ab = a)).image prod.snd, f (a, i) = (finset.filter (λ ab, prod.fst ab = a) s).prod f, { intros a, apply finset.prod_bij (λ b _, (a, b)); finish, }, rw finprod_mem_finset_eq_prod, simp_rw [finprod_mem_finset_eq_prod, this], rw [finprod_eq_prod_of_mul_support_subset _ (s.mul_support_of_fiberwise_prod_subset_image f prod.fst), ← finset.prod_fiberwise_of_maps_to _ f], finish, end /-- See also `finprod_mem_finset_product'`. -/ @[to_additive] lemma finprod_mem_finset_product (s : finset (α × β)) (f : α × β → M) : ∏ᶠ ab (h : ab ∈ s), f ab = ∏ᶠ a b (h : (a, b) ∈ s), f (a, b) := by { classical, rw finprod_mem_finset_product', simp, } @[to_additive] lemma finprod_mem_finset_product₃ {γ : Type*} (s : finset (α × β × γ)) (f : α × β × γ → M) : ∏ᶠ abc (h : abc ∈ s), f abc = ∏ᶠ a b c (h : (a, b, c) ∈ s), f (a, b, c) := by { classical, rw finprod_mem_finset_product', simp_rw finprod_mem_finset_product', simp, } @[to_additive] lemma finprod_curry (f : α × β → M) (hf : (mul_support f).finite) : ∏ᶠ ab, f ab = ∏ᶠ a b, f (a, b) := begin have h₁ : ∀ a, ∏ᶠ (h : a ∈ hf.to_finset), f a = f a, { simp, }, have h₂ : ∏ᶠ a, f a = ∏ᶠ a (h : a ∈ hf.to_finset), f a, { simp, }, simp_rw [h₂, finprod_mem_finset_product, h₁], end @[to_additive] lemma finprod_curry₃ {γ : Type*} (f : α × β × γ → M) (h : (mul_support f).finite) : ∏ᶠ abc, f abc = ∏ᶠ a b c, f (a, b, c) := by { rw finprod_curry f h, congr, ext a, rw finprod_curry, simp [h], } @[to_additive] lemma finprod_dmem {s : set α} [decidable_pred (∈ s)] (f : (Π (a : α), a ∈ s → M)) : ∏ᶠ (a : α) (h : a ∈ s), f a h = ∏ᶠ (a : α) (h : a ∈ s), if h' : a ∈ s then f a h' else 1 := finprod_congr (λ a, finprod_congr (λ ha, (dif_pos ha).symm)) @[to_additive] lemma finprod_emb_domain' {f : α → β} (hf : function.injective f) [decidable_pred (∈ set.range f)] (g : α → M) : ∏ᶠ (b : β), (if h : b ∈ set.range f then g (classical.some h) else 1) = ∏ᶠ (a : α), g a := begin simp_rw [← finprod_eq_dif], rw [finprod_dmem, finprod_mem_range hf, finprod_congr (λ a, _)], rw [dif_pos (set.mem_range_self a), hf (classical.some_spec (set.mem_range_self a))] end @[to_additive] lemma finprod_emb_domain (f : α ↪ β) [decidable_pred (∈ set.range f)] (g : α → M) : ∏ᶠ (b : β), (if h : b ∈ set.range f then g (classical.some h) else 1) = ∏ᶠ (a : α), g a := finprod_emb_domain' f.injective g end type
b07e72394e00e8c3c84b1664e3ccb3b70c7f4ea5
e0f9ba56b7fedc16ef8697f6caeef5898b435143
/test/mk_iff_of_inductive.lean
6404716a242a1d04e089ecc3d32a7f874371b3c0
[ "Apache-2.0" ]
permissive
anrddh/mathlib
6a374da53c7e3a35cb0298b0cd67824efef362b4
a4266a01d2dcb10de19369307c986d038c7bb6a6
refs/heads/master
1,656,710,827,909
1,589,560,456,000
1,589,560,456,000
264,271,800
0
0
Apache-2.0
1,589,568,062,000
1,589,568,061,000
null
UTF-8
Lean
false
false
723
lean
import tactic.mk_iff_of_inductive_prop import data.list data.list.perm data.multiset mk_iff_of_inductive_prop list.chain test.chain_iff mk_iff_of_inductive_prop false test.false_iff mk_iff_of_inductive_prop true test.true_iff mk_iff_of_inductive_prop nonempty test.non_empty_iff mk_iff_of_inductive_prop and test.and_iff mk_iff_of_inductive_prop or test.or_iff mk_iff_of_inductive_prop eq test.eq_iff mk_iff_of_inductive_prop heq test.heq_iff mk_iff_of_inductive_prop list.perm test.perm_iff mk_iff_of_inductive_prop list.pairwise test.pairwise_iff inductive test.is_true (p : Prop) : Prop | triviality : p → test.is_true mk_iff_of_inductive_prop test.is_true test.is_true_iff
584896455789e915fff64dcccf7e0d779c220787
9dc8cecdf3c4634764a18254e94d43da07142918
/src/measure_theory/group/action.lean
3e2e8da96d5ff52760371b52f7a4ca1d897246d3
[ "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
8,454
lean
/- Copyright (c) 2021 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import measure_theory.group.measurable_equiv import measure_theory.measure.regular import dynamics.ergodic.measure_preserving import dynamics.minimal /-! # Measures invariant under group actions A measure `μ : measure α` is said to be *invariant* under an action of a group `G` if scalar multiplication by `c : G` is a measure preserving map for all `c`. In this file we define a typeclass for measures invariant under action of an (additive or multiplicative) group and prove some basic properties of such measures. -/ open_locale ennreal nnreal pointwise topological_space open measure_theory measure_theory.measure set function namespace measure_theory variables {G M α : Type*} /-- A measure `μ : measure α` is invariant under an additive action of `M` on `α` if for any measurable set `s : set α` and `c : M`, the measure of its preimage under `λ x, c +ᵥ x` is equal to the measure of `s`. -/ class vadd_invariant_measure (M α : Type*) [has_vadd M α] {_ : measurable_space α} (μ : measure α) : Prop := (measure_preimage_vadd [] : ∀ (c : M) ⦃s : set α⦄, measurable_set s → μ ((λ x, c +ᵥ x) ⁻¹' s) = μ s) /-- A measure `μ : measure α` is invariant under a multiplicative action of `M` on `α` if for any measurable set `s : set α` and `c : M`, the measure of its preimage under `λ x, c • x` is equal to the measure of `s`. -/ @[to_additive] class smul_invariant_measure (M α : Type*) [has_smul M α] {_ : measurable_space α} (μ : measure α) : Prop := (measure_preimage_smul [] : ∀ (c : M) ⦃s : set α⦄, measurable_set s → μ ((λ x, c • x) ⁻¹' s) = μ s) namespace smul_invariant_measure @[to_additive] instance zero [measurable_space α] [has_smul M α] : smul_invariant_measure M α 0 := ⟨λ _ _ _, rfl⟩ variables [has_smul M α] {m : measurable_space α} {μ ν : measure α} @[to_additive] instance add [smul_invariant_measure M α μ] [smul_invariant_measure M α ν] : smul_invariant_measure M α (μ + ν) := ⟨λ c s hs, show _ + _ = _ + _, from congr_arg2 (+) (measure_preimage_smul μ c hs) (measure_preimage_smul ν c hs)⟩ @[to_additive] instance smul [smul_invariant_measure M α μ] (c : ℝ≥0∞) : smul_invariant_measure M α (c • μ) := ⟨λ a s hs, show c • _ = c • _, from congr_arg ((•) c) (measure_preimage_smul μ a hs)⟩ @[to_additive] instance smul_nnreal [smul_invariant_measure M α μ] (c : ℝ≥0) : smul_invariant_measure M α (c • μ) := smul_invariant_measure.smul c end smul_invariant_measure variables (G) {m : measurable_space α} [group G] [mul_action G α] [measurable_space G] [has_measurable_smul G α] (c : G) (μ : measure α) /-- Equivalent definitions of a measure invariant under a multiplicative action of a group. - 0: `smul_invariant_measure G α μ`; - 1: for every `c : G` and a measurable set `s`, the measure of the preimage of `s` under scalar multiplication by `c` is equal to the measure of `s`; - 2: for every `c : G` and a measurable set `s`, the measure of the image `c • s` of `s` under scalar multiplication by `c` is equal to the measure of `s`; - 3, 4: properties 2, 3 for any set, including non-measurable ones; - 5: for any `c : G`, scalar multiplication by `c` maps `μ` to `μ`; - 6: for any `c : G`, scalar multiplication by `c` is a measure preserving map. -/ @[to_additive] lemma smul_invariant_measure_tfae : tfae [smul_invariant_measure G α μ, ∀ (c : G) s, measurable_set s → μ (((•) c) ⁻¹' s) = μ s, ∀ (c : G) s, measurable_set s → μ (c • s) = μ s, ∀ (c : G) s, μ (((•) c) ⁻¹' s) = μ s, ∀ (c : G) s, μ (c • s) = μ s, ∀ c : G, measure.map ((•) c) μ = μ, ∀ c : G, measure_preserving ((•) c) μ μ] := begin tfae_have : 1 ↔ 2, from ⟨λ h, h.1, λ h, ⟨h⟩⟩, tfae_have : 2 → 6, from λ H c, ext (λ s hs, by rw [map_apply (measurable_const_smul c) hs, H _ _ hs]), tfae_have : 6 → 7, from λ H c, ⟨measurable_const_smul c, H c⟩, tfae_have : 7 → 4, from λ H c, (H c).measure_preimage_emb (measurable_embedding_const_smul c), tfae_have : 4 → 5, from λ H c s, by { rw [← preimage_smul_inv], apply H }, tfae_have : 5 → 3, from λ H c s hs, H c s, tfae_have : 3 → 2, { intros H c s hs, rw preimage_smul, exact H c⁻¹ s hs }, tfae_finish end /-- Equivalent definitions of a measure invariant under an additive action of a group. - 0: `vadd_invariant_measure G α μ`; - 1: for every `c : G` and a measurable set `s`, the measure of the preimage of `s` under vector addition `(+ᵥ) c` is equal to the measure of `s`; - 2: for every `c : G` and a measurable set `s`, the measure of the image `c +ᵥ s` of `s` under vector addition `(+ᵥ) c` is equal to the measure of `s`; - 3, 4: properties 2, 3 for any set, including non-measurable ones; - 5: for any `c : G`, vector addition of `c` maps `μ` to `μ`; - 6: for any `c : G`, vector addition of `c` is a measure preserving map. -/ add_decl_doc vadd_invariant_measure_tfae variables {G} [smul_invariant_measure G α μ] @[to_additive] lemma measure_preserving_smul : measure_preserving ((•) c) μ μ := ((smul_invariant_measure_tfae G μ).out 0 6).mp ‹_› c @[simp, to_additive] lemma map_smul : map ((•) c) μ = μ := (measure_preserving_smul c μ).map_eq @[simp, to_additive] lemma measure_preimage_smul (s : set α) : μ ((•) c ⁻¹' s) = μ s := ((smul_invariant_measure_tfae G μ).out 0 3).mp ‹_› c s @[simp, to_additive] lemma measure_smul_set (s : set α) : μ (c • s) = μ s := ((smul_invariant_measure_tfae G μ).out 0 4).mp ‹_› c s variable {μ} @[to_additive] lemma null_measurable_set.smul {s} (hs : null_measurable_set s μ) (c : G) : null_measurable_set (c • s) μ := by simpa only [← preimage_smul_inv] using hs.preimage (measure_preserving_smul _ _).quasi_measure_preserving section is_minimal variables (G) [topological_space α] [has_continuous_const_smul G α] [mul_action.is_minimal G α] {K U : set α} /-- If measure `μ` is invariant under a group action and is nonzero on a compact set `K`, then it is positive on any nonempty open set. In case of a regular measure, one can assume `μ ≠ 0` instead of `μ K ≠ 0`, see `measure_theory.measure_is_open_pos_of_smul_invariant_of_ne_zero`. -/ @[to_additive] lemma measure_is_open_pos_of_smul_invariant_of_compact_ne_zero (hK : is_compact K) (hμK : μ K ≠ 0) (hU : is_open U) (hne : U.nonempty) : 0 < μ U := let ⟨t, ht⟩ := hK.exists_finite_cover_smul G hU hne in pos_iff_ne_zero.2 $ λ hμU, hμK $ measure_mono_null ht $ (measure_bUnion_null_iff t.countable_to_set).2 $ λ _ _, by rwa measure_smul_set /-- If measure `μ` is invariant under an additive group action and is nonzero on a compact set `K`, then it is positive on any nonempty open set. In case of a regular measure, one can assume `μ ≠ 0` instead of `μ K ≠ 0`, see `measure_theory.measure_is_open_pos_of_vadd_invariant_of_ne_zero`. -/ add_decl_doc measure_is_open_pos_of_vadd_invariant_of_compact_ne_zero @[to_additive] lemma is_locally_finite_measure_of_smul_invariant (hU : is_open U) (hne : U.nonempty) (hμU : μ U ≠ ∞) : is_locally_finite_measure μ := ⟨λ x, let ⟨g, hg⟩ := hU.exists_smul_mem G x hne in ⟨(•) g ⁻¹' U, (hU.preimage (continuous_id.const_smul _)).mem_nhds hg, ne.lt_top $ by rwa [measure_preimage_smul]⟩⟩ variables [measure.regular μ] @[to_additive] lemma measure_is_open_pos_of_smul_invariant_of_ne_zero (hμ : μ ≠ 0) (hU : is_open U) (hne : U.nonempty) : 0 < μ U := let ⟨K, hK, hμK⟩ := regular.exists_compact_not_null.mpr hμ in measure_is_open_pos_of_smul_invariant_of_compact_ne_zero G hK hμK hU hne @[to_additive] lemma measure_pos_iff_nonempty_of_smul_invariant (hμ : μ ≠ 0) (hU : is_open U) : 0 < μ U ↔ U.nonempty := ⟨λ h, nonempty_of_measure_ne_zero h.ne', measure_is_open_pos_of_smul_invariant_of_ne_zero G hμ hU⟩ include G @[to_additive] lemma measure_eq_zero_iff_eq_empty_of_smul_invariant (hμ : μ ≠ 0) (hU : is_open U) : μ U = 0 ↔ U = ∅ := by rw [← not_iff_not, ← ne.def, ← pos_iff_ne_zero, measure_pos_iff_nonempty_of_smul_invariant G hμ hU, ← ne_empty_iff_nonempty] end is_minimal end measure_theory
6a16dc4441c4b053ef6e249790f4500714c8b80b
a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940
/stage0/src/Lean/Server/FileWorker/RequestHandling.lean
69206d0a00023a9820fa939164106db67cc5e7ba
[ "Apache-2.0" ]
permissive
WojciechKarpiel/lean4
7f89706b8e3c1f942b83a2c91a3a00b05da0e65b
f6e1314fa08293dea66a329e05b6c196a0189163
refs/heads/master
1,686,633,402,214
1,625,821,189,000
1,625,821,258,000
384,640,886
0
0
Apache-2.0
1,625,903,617,000
1,625,903,026,000
null
UTF-8
Lean
false
false
15,896
lean
/- Copyright (c) 2021 Wojciech Nawrocki. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Wojciech Nawrocki, Marc Huisinga -/ import Lean.DeclarationRange import Lean.Data.Json import Lean.Data.Lsp import Lean.Server.FileWorker.Utils import Lean.Server.Requests import Lean.Server.Completion namespace Lean.Server.FileWorker open Lsp open Requests open RequestM open Snapshots partial def handleCompletion (p : CompletionParams) : RequestM (RequestTask CompletionList) := do let doc ← readDoc let text := doc.meta.text let pos := text.lspPosToUtf8Pos p.position -- dbg_trace ">> handleCompletion invoked {pos}" -- NOTE: use `>=` since the cursor can be *after* the input withWaitFindSnap doc (fun s => s.endPos >= pos) (notFoundX := pure { items := #[], isIncomplete := true }) fun snap => do for infoTree in snap.cmdState.infoState.trees do -- for (ctx, info) in infoTree.getCompletionInfos do -- dbg_trace "{← info.format ctx}" if let some r ← Completion.find? doc.meta.text pos infoTree then return r return { items := #[ ], isIncomplete := true } open Elab in partial def handleHover (p : HoverParams) : RequestM (RequestTask (Option Hover)) := do let doc ← readDoc let text := doc.meta.text let mkHover (s : String) (f : String.Pos) (t : String.Pos) : Hover := { contents := { kind := MarkupKind.markdown value := s } range? := some { start := text.utf8PosToLspPos f «end» := text.utf8PosToLspPos t } } let hoverPos := text.lspPosToUtf8Pos p.position withWaitFindSnap doc (fun s => s.endPos > hoverPos) (notFoundX := pure none) fun snap => do for t in snap.cmdState.infoState.trees do if let some (ci, i) := t.hoverableInfoAt? hoverPos then if let some hoverFmt ← i.fmtHover? ci then return some <| mkHover (toString hoverFmt) i.pos?.get! i.tailPos?.get! return none open Elab in partial def handleDefinition (goToType? : Bool) (p : TextDocumentPositionParams) : RequestM (RequestTask (Array LocationLink)) := do let rc ← read let doc ← readDoc let text := doc.meta.text let hoverPos := text.lspPosToUtf8Pos p.position let locationLinksFromDecl i n := do let mod? ← findModuleOf? n let modUri? ← match mod? with | some modName => let modFname? ← rc.srcSearchPath.findWithExt "lean" modName pure <| modFname?.map toFileUri | none => pure <| some doc.meta.uri let ranges? ← findDeclarationRanges? n if let (some ranges, some modUri) := (ranges?, modUri?) then let declRangeToLspRange (r : DeclarationRange) : Lsp.Range := { start := ⟨r.pos.line - 1, r.charUtf16⟩ «end» := ⟨r.endPos.line - 1, r.endCharUtf16⟩ } let ll : LocationLink := { originSelectionRange? := (·.toLspRange text) <$> i.range? targetUri := modUri targetRange := declRangeToLspRange ranges.range targetSelectionRange := declRangeToLspRange ranges.selectionRange } return #[ll] return #[] withWaitFindSnap doc (fun s => s.endPos > hoverPos) (notFoundX := pure #[]) fun snap => do for t in snap.cmdState.infoState.trees do if let some (ci, i) := t.hoverableInfoAt? hoverPos then if let Info.ofTermInfo ti := i then let mut expr := ti.expr if goToType? then expr ← ci.runMetaM i.lctx do Meta.instantiateMVars (← Meta.inferType expr) if let some n := expr.constName? then return ← ci.runMetaM i.lctx <| locationLinksFromDecl i n if let some ei := i.toElabInfo? then if ci.env.contains ei.elaborator then return ← ci.runMetaM i.lctx <| locationLinksFromDecl i ei.elaborator if ci.env.contains ei.stx.getKind then return ← ci.runMetaM i.lctx <| locationLinksFromDecl i ei.stx.getKind return #[] open Elab in partial def handlePlainGoal (p : PlainGoalParams) : RequestM (RequestTask (Option PlainGoal)) := do let doc ← readDoc let text := doc.meta.text let hoverPos := text.lspPosToUtf8Pos p.position -- NOTE: use `>=` since the cursor can be *after* the input withWaitFindSnap doc (fun s => s.endPos >= hoverPos) (notFoundX := return none) fun snap => do for t in snap.cmdState.infoState.trees do if let rs@(_ :: _) := t.goalsAt? doc.meta.text hoverPos then let goals ← List.join <$> rs.mapM fun { ctxInfo := ci, tacticInfo := ti, useAfter := useAfter } => let ci := if useAfter then { ci with mctx := ti.mctxAfter } else { ci with mctx := ti.mctxBefore } let goals := if useAfter then ti.goalsAfter else ti.goalsBefore ci.runMetaM {} <| goals.mapM (fun g => Meta.withPPInaccessibleNames (Meta.ppGoal g)) let md := if goals.isEmpty then "no goals" else let goals := goals.map fun goal => s!"```lean {goal} ```" String.intercalate "\n---\n" goals return some { goals := goals.map toString |>.toArray, rendered := md } return none open Elab in partial def handlePlainTermGoal (p : PlainTermGoalParams) : RequestM (RequestTask (Option PlainTermGoal)) := do let doc ← readDoc let text := doc.meta.text let hoverPos := text.lspPosToUtf8Pos p.position withWaitFindSnap doc (fun s => s.endPos > hoverPos) (notFoundX := pure none) fun snap => do for t in snap.cmdState.infoState.trees do if let some (ci, i@(Info.ofTermInfo ti)) := t.termGoalAt? hoverPos then let goal ← ci.runMetaM i.lctx <| open Meta in do let ty ← instantiateMVars <| ti.expectedType?.getD (← inferType ti.expr) withPPInaccessibleNames <| Meta.ppGoal (← mkFreshExprMVar ty).mvarId! let range := if let some r := i.range? then r.toLspRange text else ⟨p.position, p.position⟩ return some { goal := toString goal, range } return none partial def handleDocumentHighlight (p : DocumentHighlightParams) : RequestM (RequestTask (Array DocumentHighlight)) := do let doc ← readDoc let text := doc.meta.text let pos := text.lspPosToUtf8Pos p.position let rec highlightReturn? (doRange? : Option Range) : Syntax → Option DocumentHighlight | stx@`(doElem|return%$i $e) => do if let some range := i.getRange? then if range.contains pos then return some { range := doRange?.getD (range.toLspRange text), kind? := DocumentHighlightKind.text } highlightReturn? doRange? e | `(do%$i $elems) => highlightReturn? (i.getRange?.get!.toLspRange text) elems | stx => stx.getArgs.findSome? (highlightReturn? doRange?) withWaitFindSnap doc (fun s => s.endPos > pos) (notFoundX := pure #[]) fun snap => do if let some hi := highlightReturn? none snap.stx then return #[hi] return #[] section -- TODO https://github.com/leanprover/lean4/issues/529 open Parser.Command partial def handleDocumentSymbol (p : DocumentSymbolParams) : RequestM (RequestTask DocumentSymbolResult) := do let doc ← readDoc asTask do let ⟨cmdSnaps, e?⟩ ← doc.cmdSnaps.updateFinishedPrefix let mut stxs := cmdSnaps.finishedPrefix.map Snapshot.stx match e? with | some ElabTaskError.aborted => throw RequestError.fileChanged | some (ElabTaskError.ioError e) => throwThe IO.Error e | _ => () let lastSnap := cmdSnaps.finishedPrefix.getLastD doc.headerSnap stxs := stxs ++ (← parseAhead doc.meta.text.source lastSnap).toList let (syms, _) := toDocumentSymbols doc.meta.text stxs return { syms := syms.toArray } where toDocumentSymbols (text : FileMap) | [] => ([], []) | stx::stxs => match stx with | `(namespace $id) => sectionLikeToDocumentSymbols text stx stxs (id.getId.toString) SymbolKind.namespace id | `(section $(id)?) => sectionLikeToDocumentSymbols text stx stxs ((·.getId.toString) <$> id |>.getD "<section>") SymbolKind.namespace (id.getD stx) | `(end $(id)?) => ([], stx::stxs) | _ => do let (syms, stxs') := toDocumentSymbols text stxs unless stx.isOfKind ``Lean.Parser.Command.declaration do return (syms, stxs') if let some stxRange := stx.getRange? then let (name, selection) := match stx with | `($dm:declModifiers $ak:attrKind instance $[$np:namedPrio]? $[$id:ident$[.{$ls,*}]?]? $sig:declSig $val) => ((·.getId.toString) <$> id |>.getD s!"instance {sig.reprint.getD ""}", id.getD sig) | _ => match stx[1][1] with | `(declId|$id:ident$[.{$ls,*}]?) => (id.getId.toString, id) | _ => (stx[1][0].isIdOrAtom?.getD "<unknown>", stx[1][0]) if let some selRange := selection.getRange? then return (DocumentSymbol.mk { name := name kind := SymbolKind.method range := stxRange.toLspRange text selectionRange := selRange.toLspRange text } :: syms, stxs') return (syms, stxs') sectionLikeToDocumentSymbols (text : FileMap) (stx : Syntax) (stxs : List Syntax) (name : String) (kind : SymbolKind) (selection : Syntax) := let (syms, stxs') := toDocumentSymbols text stxs -- discard `end` let (syms', stxs'') := toDocumentSymbols text (stxs'.drop 1) let endStx := match stxs' with | endStx::_ => endStx | [] => (stx::stxs').getLast! -- we can assume that commands always have at least one position (see `parseCommand`) let range := (mkNullNode #[stx, endStx]).getRange?.get!.toLspRange text (DocumentSymbol.mk { name kind range selectionRange := selection.getRange? |>.map (·.toLspRange text) |>.getD range children? := syms.toArray } :: syms', stxs'') end def noHighlightKinds : Array SyntaxNodeKind := #[ -- usually have special highlighting by the client ``Lean.Parser.Term.sorry, ``Lean.Parser.Term.type, ``Lean.Parser.Term.prop, -- not really keywords `antiquotName, ``Lean.Parser.Command.docComment] structure SemanticTokensContext where beginPos : String.Pos endPos : String.Pos text : FileMap infoState : Elab.InfoState structure SemanticTokensState where data : Array Nat lastLspPos : Lsp.Position partial def handleSemanticTokens (beginPos endPos : String.Pos) : RequestM (RequestTask SemanticTokens) := do let doc ← readDoc let text := doc.meta.text let t ← doc.cmdSnaps.waitAll (·.beginPos < endPos) mapTask t fun (snaps, _) => StateT.run' (s := { data := #[], lastLspPos := ⟨0, 0⟩ : SemanticTokensState }) do for s in snaps do if s.endPos <= beginPos then continue ReaderT.run (r := SemanticTokensContext.mk beginPos endPos text s.cmdState.infoState) <| go s.stx return { data := (← get).data } where go (stx : Syntax) := do match stx with | `($e.$id:ident) => go e; addToken id SemanticTokenType.property -- indistinguishable from next pattern --| `(level|$id:ident) => addToken id SemanticTokenType.variable | `($id:ident) => highlightId id | _ => if !noHighlightKinds.contains stx.getKind then highlightKeyword stx if stx.isOfKind choiceKind then go stx[0] else stx.getArgs.forM go highlightId (stx : Syntax) : ReaderT SemanticTokensContext (StateT SemanticTokensState RequestM) _ := do if let some range := stx.getRange? then for t in (← read).infoState.trees do for ti in t.deepestNodes (fun | _, i@(Elab.Info.ofTermInfo ti), _ => match i.pos? with | some ipos => if range.contains ipos then some ti else none | _ => none | _, _, _ => none) do match ti.expr with | Expr.fvar .. => addToken ti.stx SemanticTokenType.variable | _ => if ti.stx.getPos?.get! > range.start then addToken ti.stx SemanticTokenType.property highlightKeyword stx := do if let Syntax.atom info val := stx then if val.bsize > 0 && val[0].isAlpha then addToken stx SemanticTokenType.keyword addToken stx type := do let ⟨beginPos, endPos, text, _⟩ ← read if let (some pos, some tailPos) := (stx.getPos?, stx.getTailPos?) then if beginPos <= pos && pos < endPos then let lspPos := (← get).lastLspPos let lspPos' := text.utf8PosToLspPos pos let deltaLine := lspPos'.line - lspPos.line let deltaStart := lspPos'.character - (if lspPos'.line == lspPos.line then lspPos.character else 0) let length := (text.utf8PosToLspPos tailPos).character - lspPos'.character let tokenType := type.toNat let tokenModifiers := 0 modify fun st => { data := st.data ++ #[deltaLine, deltaStart, length, tokenType, tokenModifiers] lastLspPos := lspPos' } def handleSemanticTokensFull (p : SemanticTokensParams) : RequestM (RequestTask SemanticTokens) := do handleSemanticTokens 0 (1 <<< 16) def handleSemanticTokensRange (p : SemanticTokensRangeParams) : RequestM (RequestTask SemanticTokens) := do let doc ← readDoc let text := doc.meta.text let beginPos := text.lspPosToUtf8Pos p.range.start let endPos := text.lspPosToUtf8Pos p.range.end handleSemanticTokens beginPos endPos partial def handleWaitForDiagnostics (p : WaitForDiagnosticsParams) : RequestM (RequestTask WaitForDiagnostics) := do let rec waitLoop : RequestM EditableDocument := do let doc ← readDoc if p.version ≤ doc.meta.version then return doc else IO.sleep 50 waitLoop let t ← RequestM.asTask waitLoop RequestM.bindTask t fun doc? => do let doc ← doc? let t₁ ← doc.cmdSnaps.waitAll return t₁.map fun _ => pure WaitForDiagnostics.mk builtin_initialize registerLspRequestHandler "textDocument/waitForDiagnostics" WaitForDiagnosticsParams WaitForDiagnostics handleWaitForDiagnostics registerLspRequestHandler "textDocument/completion" CompletionParams CompletionList handleCompletion registerLspRequestHandler "textDocument/hover" HoverParams (Option Hover) handleHover registerLspRequestHandler "textDocument/declaration" TextDocumentPositionParams (Array LocationLink) (handleDefinition (goToType? := false)) registerLspRequestHandler "textDocument/definition" TextDocumentPositionParams (Array LocationLink) (handleDefinition (goToType? := false)) registerLspRequestHandler "textDocument/typeDefinition" TextDocumentPositionParams (Array LocationLink) (handleDefinition (goToType? := true)) registerLspRequestHandler "textDocument/documentHighlight" DocumentHighlightParams DocumentHighlightResult handleDocumentHighlight registerLspRequestHandler "textDocument/documentSymbol" DocumentSymbolParams DocumentSymbolResult handleDocumentSymbol registerLspRequestHandler "textDocument/semanticTokens/full" SemanticTokensParams SemanticTokens handleSemanticTokensFull registerLspRequestHandler "textDocument/semanticTokens/range" SemanticTokensRangeParams SemanticTokens handleSemanticTokensRange registerLspRequestHandler "$/lean/plainGoal" PlainGoalParams (Option PlainGoal) handlePlainGoal registerLspRequestHandler "$/lean/plainTermGoal" PlainTermGoalParams (Option PlainTermGoal) handlePlainTermGoal end Lean.Server.FileWorker
6b530ff57f33e6839ca10ee9591cb6df77af3a3c
b7f22e51856f4989b970961f794f1c435f9b8f78
/library/algebra/monotone.lean
79e0378c2172b4590d8645daf7f4ab5e9d867882
[ "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
20,688
lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Jeremy Avigad Weak and strict order preserving maps. TODO: we will probably eventually want versions restricted to smaller domains, "nondecreasing_on" etc. Maybe we can do this with subtypes. -/ import .order open eq eq.ops function variables {A B C : Type} section variables [weak_order A] [weak_order B] [weak_order C] definition nondecreasing (f : A → B) : Prop := ∀ ⦃a₁ a₂⦄, a₁ ≤ a₂ → f a₁ ≤ f a₂ definition nonincreasing (f : A → B) : Prop := ∀ ⦃a₁ a₂⦄, a₁ ≤ a₂ → f a₁ ≥ f a₂ theorem nondecreasing_id : nondecreasing (@id A) := take a₁ a₂, assume H, H theorem nondecreasing_comp_nondec_nondec {g : B → C} {f : A → B} (Hg : nondecreasing g) (Hf : nondecreasing f) : nondecreasing (g ∘ f) := take a₁ a₂, assume H, Hg (Hf H) theorem nondecreasing_comp_noninc_noninc {g : B → C} {f : A → B} (Hg : nonincreasing g) (Hf : nonincreasing f) : nondecreasing (g ∘ f) := take a₁ a₂, assume H, Hg (Hf H) theorem nonincreasing_comp_noninc_nondec {g : B → C} {f : A → B} (Hg : nonincreasing g) (Hf : nondecreasing f) : nonincreasing (g ∘ f) := take a₁ a₂, assume H, Hg (Hf H) theorem nonincreasing_comp_nondec_noninc {g : B → C} {f : A → B} (Hg : nondecreasing g) (Hf : nonincreasing f) : nonincreasing (g ∘ f) := take a₁ a₂, assume H, Hg (Hf H) end section variables [strict_order A] [strict_order B] [strict_order C] definition strictly_increasing (f : A → B) : Prop := ∀ ⦃a₁ a₂⦄, a₁ < a₂ → f a₁ < f a₂ definition strictly_decreasing (f : A → B) : Prop := ∀ ⦃a₁ a₂⦄, a₁ < a₂ → f a₁ > f a₂ theorem strictly_increasing_id : strictly_increasing (@id A) := take a₁ a₂, assume H, H theorem strictly_increasing_comp_inc_inc {g : B → C} {f : A → B} (Hg : strictly_increasing g) (Hf : strictly_increasing f) : strictly_increasing (g ∘ f) := take a₁ a₂, assume H, Hg (Hf H) theorem strictly_increasing_comp_dec_dec {g : B → C} {f : A → B} (Hg : strictly_decreasing g) (Hf : strictly_decreasing f) : strictly_increasing (g ∘ f) := take a₁ a₂, assume H, Hg (Hf H) theorem strictly_decreasing_comp_inc_dec {g : B → C} {f : A → B} (Hg : strictly_increasing g) (Hf : strictly_decreasing f) : strictly_decreasing (g ∘ f) := take a₁ a₂, assume H, Hg (Hf H) theorem strictly_decreasing_comp_dec_inc {g : B → C} {f : A → B} (Hg : strictly_decreasing g) (Hf : strictly_increasing f) : strictly_decreasing (g ∘ f) := take a₁ a₂, assume H, Hg (Hf H) end section variables [strong_order_pair A] [strong_order_pair B] theorem nondecreasing_of_strictly_increasing {f : A → B} (H : strictly_increasing f) : nondecreasing f := take a₁ a₂, suppose a₁ ≤ a₂, show f a₁ ≤ f a₂, from or.elim (lt_or_eq_of_le this) (suppose a₁ < a₂, le_of_lt (H this)) (suppose a₁ = a₂, le_of_eq (congr_arg f this)) theorem nonincreasing_of_strictly_decreasing {f : A → B} (H : strictly_decreasing f) : nonincreasing f := take a₁ a₂, suppose a₁ ≤ a₂, show f a₁ ≥ f a₂, from or.elim (lt_or_eq_of_le this) (suppose a₁ < a₂, le_of_lt (H this)) (suppose a₁ = a₂, le_of_eq (congr_arg f this⁻¹)) end section variables [linear_strong_order_pair A] [linear_strong_order_pair B] [linear_strong_order_pair C] theorem lt_of_strictly_increasing {f : A → B} {a₁ a₂ : A} (H : strictly_increasing f) (H' : f a₁ < f a₂) : a₁ < a₂ := lt_of_not_ge (suppose a₂ ≤ a₁, have f a₂ ≤ f a₁, from nondecreasing_of_strictly_increasing H this, show false, from not_le_of_gt H' this) theorem lt_iff_of_strictly_increasing {f : A → B} (a₁ a₂ : A) (H : strictly_increasing f) : f a₁ < f a₂ ↔ a₁ < a₂ := iff.intro (lt_of_strictly_increasing H) (@H a₁ a₂) theorem le_of_strictly_increasing {f : A → B} {a₁ a₂ : A} (H : strictly_increasing f) (H' : f a₁ ≤ f a₂) : a₁ ≤ a₂ := le_of_not_gt (suppose a₂ < a₁, not_le_of_gt (H this) H') theorem le_iff_of_strictly_increasing {f : A → B} (a₁ a₂ : A) (H : strictly_increasing f) : f a₁ ≤ f a₂ ↔ a₁ ≤ a₂ := iff.intro (le_of_strictly_increasing H) (λ H', nondecreasing_of_strictly_increasing H H') theorem lt_of_strictly_decreasing {f : A → B} {a₁ a₂ : A} (H : strictly_decreasing f) (H' : f a₁ > f a₂) : a₁ < a₂ := lt_of_not_ge (suppose a₂ ≤ a₁, have f a₂ ≥ f a₁, from nonincreasing_of_strictly_decreasing H this, show false, from not_le_of_gt H' this) theorem gt_iff_of_strictly_decreasing {f : A → B} (a₁ a₂ : A) (H : strictly_decreasing f) : f a₁ > f a₂ ↔ a₁ < a₂ := iff.intro (lt_of_strictly_decreasing H) (@H a₁ a₂) theorem le_of_strictly_decreasing {f : A → B} {a₁ a₂ : A} (H : strictly_decreasing f) (H' : f a₁ ≥ f a₂) : a₁ ≤ a₂ := le_of_not_gt (suppose a₂ < a₁, not_le_of_gt (H this) H') theorem ge_iff_of_strictly_decreasing {f : A → B} (a₁ a₂ : A) (H : strictly_decreasing f) : f a₁ ≥ f a₂ ↔ a₁ ≤ a₂ := iff.intro (le_of_strictly_decreasing H) (λ H', nonincreasing_of_strictly_decreasing H H') theorem strictly_increasing_of_left_inverse {g : B → A} {f : A → B} (H : left_inverse g f) (H' : strictly_increasing g) : strictly_increasing f := take a₁ a₂, suppose a₁ < a₂, have g (f a₁) < g (f a₂), by rewrite *H; apply this, lt_of_strictly_increasing H' this theorem strictly_decreasing_of_left_inverse {g : B → A} {f : A → B} (H : left_inverse g f) (H' : strictly_decreasing g) : strictly_decreasing f := take b₁ b₂, suppose b₁ < b₂, have g (f b₁) < g (f b₂), by rewrite *H; apply this, lt_of_strictly_decreasing H' this theorem nondecreasing_of_left_inverse {g : B → A} {f : A → B} (H : left_inverse g f) (H' : strictly_increasing g) : nondecreasing f := take a₁ a₂, suppose a₁ ≤ a₂, have g (f a₁) ≤ g (f a₂), by rewrite *H; apply this, le_of_strictly_increasing H' this theorem nonincreasing_of_left_inverse {g : B → A} {f : A → B} (H : left_inverse g f) (H' : strictly_decreasing g) : nonincreasing f := take b₁ b₂, suppose b₁ ≤ b₂, have g (f b₁) ≤ g (f b₂), by rewrite *H; apply this, le_of_strictly_decreasing H' this end /- composition rules for strict orders -/ section variables [strict_order A] [strict_order B] [strict_order C] theorem strictly_increasing_of_strictly_increasing_comp_right {g : B → C} {f : A → B} {h : C → B} (H₁ : left_inverse h g) (H₂ : strictly_increasing h) (H₃ : strictly_increasing (g ∘ f)) : strictly_increasing f := take a₁ a₂, suppose a₁ < a₂, have h (g (f a₁)) < h (g (f a₂)), from H₂ (H₃ this), show f a₁ < f a₂, by rewrite *H₁ at this; apply this theorem strictly_decreasing_of_strictly_increasing_comp_right {g : B → C} {f : A → B} {h : C → B} (H₁ : left_inverse h g) (H₂ : strictly_decreasing h) (H₃ : strictly_increasing (g ∘ f)) : strictly_decreasing f := take a₁ a₂, suppose a₁ < a₂, have h (g (f a₁)) > h (g (f a₂)), from H₂ (H₃ this), show f a₁ > f a₂, by rewrite *H₁ at this; apply this theorem strictly_decreasing_of_strictly_decreasing_comp_right {g : B → C} {f : A → B} {h : C → B} (H₁ : left_inverse h g) (H₂ : strictly_increasing h) (H₃ : strictly_decreasing (g ∘ f)) : strictly_decreasing f := take a₁ a₂, suppose a₁ < a₂, have h (g (f a₁)) > h (g (f a₂)), from H₂ (H₃ this), show f a₁ > f a₂, by rewrite *H₁ at this; apply this theorem strictly_increasing_of_strictly_decreasing_comp_right {g : B → C} {f : A → B} {h : C → B} (H₁ : left_inverse h g) (H₂ : strictly_decreasing h) (H₃ : strictly_decreasing (g ∘ f)) : strictly_increasing f := take a₁ a₂, suppose a₁ < a₂, have h (g (f a₁)) < h (g (f a₂)), from H₂ (H₃ this), show f a₁ < f a₂, by rewrite *H₁ at this; apply this theorem strictly_increasing_of_strictly_decreasing_comp_left {g : B → C} {f : A → B} {h : B → A} (H₁ : left_inverse f h) (H₂ : strictly_decreasing h) (H₃ : strictly_decreasing (g ∘ f)) : strictly_increasing g := take a₁ a₂, suppose a₁ < a₂, have g (f (h a₁)) < g (f (h a₂)), from H₃ (H₂ this), show g a₁ < g a₂, by rewrite *H₁ at this; apply this theorem strictly_decreasing_of_strictly_decreasing_comp_left {g : B → C} {f : A → B} {h : B → A} (H₁ : left_inverse f h) (H₂ : strictly_increasing h) (H₃ : strictly_decreasing (g ∘ f)) : strictly_decreasing g := take a₁ a₂, suppose a₁ < a₂, have g (f (h a₁)) > g (f (h a₂)), from H₃ (H₂ this), show g a₁ > g a₂, by rewrite *H₁ at this; apply this theorem strictly_increasing_of_strictly_increasing_comp_left {g : B → C} {f : A → B} {h : B → A} (H₁ : left_inverse f h) (H₂ : strictly_increasing h) (H₃ : strictly_increasing (g ∘ f)) : strictly_increasing g := take a₁ a₂, suppose a₁ < a₂, have g (f (h a₁)) < g (f (h a₂)), from H₃ (H₂ this), show g a₁ < g a₂, by rewrite *H₁ at this; apply this theorem strictly_decreasing_of_strictly_increasing_comp_left {g : B → C} {f : A → B} {h : B → A} (H₁ : left_inverse f h) (H₂ : strictly_decreasing h) (H₃ : strictly_increasing (g ∘ f)) : strictly_decreasing g := take a₁ a₂, suppose a₁ < a₂, have g (f (h a₁)) > g (f (h a₂)), from H₃ (H₂ this), show g a₁ > g a₂, by rewrite *H₁ at this; apply this end section variables [strict_order A] [linear_strong_order_pair B] [linear_strong_order_pair C] theorem strictly_increasing_comp_iff_strictly_increasing_right {g : B → C} {f : A → B} {h : C → B} (H₁ : left_inverse h g) (H₂ : strictly_increasing h) : strictly_increasing (g ∘ f) ↔ strictly_increasing f := have H₃ : strictly_increasing g, from strictly_increasing_of_left_inverse H₁ H₂, iff.intro (strictly_increasing_of_strictly_increasing_comp_right H₁ H₂) (strictly_increasing_comp_inc_inc H₃) theorem strictly_increasing_comp_iff_strictly_decreasing_right {g : B → C} {f : A → B} {h : C → B} (H₁ : left_inverse h g) (H₂ : strictly_decreasing h) : strictly_increasing (g ∘ f) ↔ strictly_decreasing f := have H₃ : strictly_decreasing g, from strictly_decreasing_of_left_inverse H₁ H₂, iff.intro (strictly_decreasing_of_strictly_increasing_comp_right H₁ H₂) (strictly_increasing_comp_dec_dec H₃) theorem strictly_decreasing_comp_iff_strictly_decreasing_right {g : B → C} {f : A → B} {h : C → B} (H₁ : left_inverse h g) (H₂ : strictly_increasing h) : strictly_decreasing (g ∘ f) ↔ strictly_decreasing f := have H₃ : strictly_increasing g, from strictly_increasing_of_left_inverse H₁ H₂, iff.intro (strictly_decreasing_of_strictly_decreasing_comp_right H₁ H₂) (strictly_decreasing_comp_inc_dec H₃) theorem strictly_decreasing_comp_iff_strictly_increasing_right {g : B → C} {f : A → B} {h : C → B} (H₁ : left_inverse h g) (H₂ : strictly_decreasing h) : strictly_decreasing (g ∘ f) ↔ strictly_increasing f := have H₃ : strictly_decreasing g, from strictly_decreasing_of_left_inverse H₁ H₂, iff.intro (strictly_increasing_of_strictly_decreasing_comp_right H₁ H₂) (strictly_decreasing_comp_dec_inc H₃) end section variables [linear_strong_order_pair A] [linear_strong_order_pair B] [strict_order C] theorem strictly_increasing_comp_iff_strinctly_increasing_left {g : B → C} {f : A → B} {h : B → A} (H₁ : left_inverse f h) (H₂ : strictly_increasing f) : strictly_increasing (g ∘ f) ↔ strictly_increasing g := have H₃ : strictly_increasing h, from strictly_increasing_of_left_inverse H₁ H₂, iff.intro (strictly_increasing_of_strictly_increasing_comp_left H₁ H₃) (λ H, strictly_increasing_comp_inc_inc H H₂) theorem strictly_increasing_comp_iff_strictly_decreasing_left {g : B → C} {f : A → B} {h : B → A} (H₁ : left_inverse f h) (H₂ : strictly_decreasing f) : strictly_increasing (g ∘ f) ↔ strictly_decreasing g := have H₃ : strictly_decreasing h, from strictly_decreasing_of_left_inverse H₁ H₂, iff.intro (strictly_decreasing_of_strictly_increasing_comp_left H₁ H₃) (λ H, strictly_increasing_comp_dec_dec H H₂) theorem strictly_decreasing_comp_iff_strictly_increasing_left {g : B → C} {f : A → B} {h : B → A} (H₁ : left_inverse f h) (H₂ : strictly_decreasing f) : strictly_decreasing (g ∘ f) ↔ strictly_increasing g := have H₃ : strictly_decreasing h, from strictly_decreasing_of_left_inverse H₁ H₂, iff.intro (strictly_increasing_of_strictly_decreasing_comp_left H₁ H₃) (λ H, strictly_decreasing_comp_inc_dec H H₂) theorem strictly_decreasing_comp_iff_strictly_decreasing_left {g : B → C} {f : A → B} {h : B → A} (H₁ : left_inverse f h) (H₂ : strictly_increasing f) : strictly_decreasing (g ∘ f) ↔ strictly_decreasing g := have H₃ : strictly_increasing h, from strictly_increasing_of_left_inverse H₁ H₂, iff.intro (strictly_decreasing_of_strictly_decreasing_comp_left H₁ H₃) (λ H, strictly_decreasing_comp_dec_inc H H₂) end /- composition rules for weak orders -/ section variables [weak_order A] [weak_order B] [weak_order C] theorem nondecreasing_of_nondecreasing_comp_right {g : B → C} {f : A → B} {h : C → B} (H₁ : left_inverse h g) (H₂ : nondecreasing h) (H₃ : nondecreasing (g ∘ f)) : nondecreasing f := take a₁ a₂, suppose a₁ ≤ a₂, have h (g (f a₁)) ≤ h (g (f a₂)), from H₂ (H₃ this), show f a₁ ≤ f a₂, by rewrite *H₁ at this; apply this theorem nonincreasing_of_nondecreasing_comp_right {g : B → C} {f : A → B} {h : C → B} (H₁ : left_inverse h g) (H₂ : nonincreasing h) (H₃ : nondecreasing (g ∘ f)) : nonincreasing f := take a₁ a₂, suppose a₁ ≤ a₂, have h (g (f a₁)) ≥ h (g (f a₂)), from H₂ (H₃ this), show f a₁ ≥ f a₂, by rewrite *H₁ at this; apply this theorem nonincreasing_of_nonincreasing_comp_right {g : B → C} {f : A → B} {h : C → B} (H₁ : left_inverse h g) (H₂ : nondecreasing h) (H₃ : nonincreasing (g ∘ f)) : nonincreasing f := take a₁ a₂, suppose a₁ ≤ a₂, have h (g (f a₁)) ≥ h (g (f a₂)), from H₂ (H₃ this), show f a₁ ≥ f a₂, by rewrite *H₁ at this; apply this theorem nondecreasing_of_nonincreasing_comp_right {g : B → C} {f : A → B} {h : C → B} (H₁ : left_inverse h g) (H₂ : nonincreasing h) (H₃ : nonincreasing (g ∘ f)) : nondecreasing f := take a₁ a₂, suppose a₁ ≤ a₂, have h (g (f a₁)) ≤ h (g (f a₂)), from H₂ (H₃ this), show f a₁ ≤ f a₂, by rewrite *H₁ at this; apply this theorem nondecreasing_of_nondecreasing_comp_left {g : B → C} {f : A → B} {h : B → A} (H₁ : left_inverse f h) (H₂ : nondecreasing h) (H₃ : nondecreasing (g ∘ f)) : nondecreasing g := take a₁ a₂, suppose a₁ ≤ a₂, have g (f (h a₁)) ≤ g (f (h a₂)), from H₃ (H₂ this), show g a₁ ≤ g a₂, by rewrite *H₁ at this; apply this theorem nonincreasing_of_nondecreasing_comp_left {g : B → C} {f : A → B} {h : B → A} (H₁ : left_inverse f h) (H₂ : nonincreasing h) (H₃ : nondecreasing (g ∘ f)) : nonincreasing g := take a₁ a₂, suppose a₁ ≤ a₂, have g (f (h a₁)) ≥ g (f (h a₂)), from H₃ (H₂ this), show g a₁ ≥ g a₂, by rewrite *H₁ at this; apply this theorem nondecreasing_of_nonincreasing_comp_left {g : B → C} {f : A → B} {h : B → A} (H₁ : left_inverse f h) (H₂ : nonincreasing h) (H₃ : nonincreasing (g ∘ f)) : nondecreasing g := take a₁ a₂, suppose a₁ ≤ a₂, have g (f (h a₁)) ≤ g (f (h a₂)), from H₃ (H₂ this), show g a₁ ≤ g a₂, by rewrite *H₁ at this; apply this theorem nonincreasing_of_nonincreasing_comp_left {g : B → C} {f : A → B} {h : B → A} (H₁ : left_inverse f h) (H₂ : nondecreasing h) (H₃ : nonincreasing (g ∘ f)) : nonincreasing g := take a₁ a₂, suppose a₁ ≤ a₂, have g (f (h a₁)) ≥ g (f (h a₂)), from H₃ (H₂ this), show g a₁ ≥ g a₂, by rewrite *H₁ at this; apply this end section variables [weak_order A] [linear_strong_order_pair B] [linear_strong_order_pair C] theorem nondecreasing_comp_iff_nondecreasing_right {g : B → C} {f : A → B} {h : C → B} (H₁ : left_inverse h g) (H₂ : strictly_increasing h) : nondecreasing (g ∘ f) ↔ nondecreasing f := have H₃ : nondecreasing g, from nondecreasing_of_left_inverse H₁ H₂, iff.intro (nondecreasing_of_nondecreasing_comp_right H₁ (nondecreasing_of_strictly_increasing H₂)) (nondecreasing_comp_nondec_nondec H₃) theorem nondecreasing_comp_iff_nonincreasing_right {g : B → C} {f : A → B} {h : C → B} (H₁ : left_inverse h g) (H₂ : strictly_decreasing h) : nondecreasing (g ∘ f) ↔ nonincreasing f := have H₃ : nonincreasing g, from nonincreasing_of_left_inverse H₁ H₂, iff.intro (nonincreasing_of_nondecreasing_comp_right H₁ (nonincreasing_of_strictly_decreasing H₂)) (nondecreasing_comp_noninc_noninc H₃) theorem nonincreasing_comp_iff_nonincreasing_right {g : B → C} {f : A → B} {h : C → B} (H₁ : left_inverse h g) (H₂ : strictly_increasing h) : nonincreasing (g ∘ f) ↔ nonincreasing f := have H₃ : nondecreasing g, from nondecreasing_of_left_inverse H₁ H₂, iff.intro (nonincreasing_of_nonincreasing_comp_right H₁ (nondecreasing_of_strictly_increasing H₂)) (nonincreasing_comp_nondec_noninc H₃) theorem nonincreasing_comp_iff_nondecreasing_right {g : B → C} {f : A → B} {h : C → B} (H₁ : left_inverse h g) (H₂ : strictly_decreasing h) : nonincreasing (g ∘ f) ↔ nondecreasing f := have H₃ : nonincreasing g, from nonincreasing_of_left_inverse H₁ H₂, iff.intro (nondecreasing_of_nonincreasing_comp_right H₁ (nonincreasing_of_strictly_decreasing H₂)) (nonincreasing_comp_noninc_nondec H₃) end section variables [linear_strong_order_pair A] [linear_strong_order_pair B] [weak_order C] theorem nondecreasing_comp_iff_nondecreasing_left {g : B → C} {f : A → B} {h : B → A} (H₁ : left_inverse f h) (H₂ : strictly_increasing f) : nondecreasing (g ∘ f) ↔ nondecreasing g := have H₃ : nondecreasing h, from nondecreasing_of_left_inverse H₁ H₂, iff.intro (nondecreasing_of_nondecreasing_comp_left H₁ H₃) (λ H, nondecreasing_comp_nondec_nondec H (nondecreasing_of_strictly_increasing H₂)) theorem nondecreasing_comp_iff_nonincreasing_left {g : B → C} {f : A → B} {h : B → A} (H₁ : left_inverse f h) (H₂ : strictly_decreasing f) : nondecreasing (g ∘ f) ↔ nonincreasing g := have H₃ : nonincreasing h, from nonincreasing_of_left_inverse H₁ H₂, iff.intro (nonincreasing_of_nondecreasing_comp_left H₁ H₃) (λ H, nondecreasing_comp_noninc_noninc H (nonincreasing_of_strictly_decreasing H₂)) theorem nonincreasing_comp_iff_nondecreasing_left {g : B → C} {f : A → B} {h : B → A} (H₁ : left_inverse f h) (H₂ : strictly_decreasing f) : nonincreasing (g ∘ f) ↔ nondecreasing g := have H₃ : nonincreasing h, from nonincreasing_of_left_inverse H₁ H₂, iff.intro (nondecreasing_of_nonincreasing_comp_left H₁ H₃) (λ H, nonincreasing_comp_nondec_noninc H (nonincreasing_of_strictly_decreasing H₂)) theorem nonincreasing_comp_iff_nonincreasing_left {g : B → C} {f : A → B} {h : B → A} (H₁ : left_inverse f h) (H₂ : strictly_increasing f) : nonincreasing (g ∘ f) ↔ nonincreasing g := have H₃ : nondecreasing h, from nondecreasing_of_left_inverse H₁ H₂, iff.intro (nonincreasing_of_nonincreasing_comp_left H₁ H₃) (λ H, nonincreasing_comp_noninc_nondec H (nondecreasing_of_strictly_increasing H₂)) end
69f8bbd2a43de729a66be82a940d681ab3a23790
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/analysis/normed_space/multilinear_auto.lean
297e27084ac44093b8390dee8f58ea27a1b23544
[]
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
69,593
lean
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.analysis.normed_space.operator_norm import Mathlib.topology.algebra.multilinear import Mathlib.PostPort universes u v w₁ w₂ wG u_1 w namespace Mathlib /-! # Operator norm on the space of continuous multilinear maps When `f` is a continuous multilinear map in finitely many variables, we define its norm `∥f∥` as the smallest number such that `∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥` for all `m`. We show that it is indeed a norm, and prove its basic properties. ## Main results Let `f` be a multilinear map in finitely many variables. * `exists_bound_of_continuous` asserts that, if `f` is continuous, then there exists `C > 0` with `∥f m∥ ≤ C * ∏ i, ∥m i∥` for all `m`. * `continuous_of_bound`, conversely, asserts that this bound implies continuity. * `mk_continuous` constructs the associated continuous multilinear map. Let `f` be a continuous multilinear map in finitely many variables. * `∥f∥` is its norm, i.e., the smallest number such that `∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥` for all `m`. * `le_op_norm f m` asserts the fundamental inequality `∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥`. * `norm_image_sub_le f m₁ m₂` gives a control of the difference `f m₁ - f m₂` in terms of `∥f∥` and `∥m₁ - m₂∥`. We also register isomorphisms corresponding to currying or uncurrying variables, transforming a continuous multilinear function `f` in `n+1` variables into a continuous linear function taking values in continuous multilinear functions in `n` variables, and also into a continuous multilinear function in `n` variables taking values in continuous linear functions. These operations are called `f.curry_left` and `f.curry_right` respectively (with inverses `f.uncurry_left` and `f.uncurry_right`). They induce continuous linear equivalences between spaces of continuous multilinear functions in `n+1` variables and spaces of continuous linear functions into continuous multilinear functions in `n` variables (resp. continuous multilinear functions in `n` variables taking values in continuous linear functions), called respectively `continuous_multilinear_curry_left_equiv` and `continuous_multilinear_curry_right_equiv`. ## Implementation notes We mostly follow the API (and the proofs) of `operator_norm.lean`, with the additional complexity that we should deal with multilinear maps in several variables. The currying/uncurrying constructions are based on those in `multilinear.lean`. From the mathematical point of view, all the results follow from the results on operator norm in one variable, by applying them to one variable after the other through currying. However, this is only well defined when there is an order on the variables (for instance on `fin n`) although the final result is independent of the order. While everything could be done following this approach, it turns out that direct proofs are easier and more efficient. -/ /-! ### Continuity properties of multilinear maps We relate continuity of multilinear maps to the inequality `∥f m∥ ≤ C * ∏ i, ∥m i∥`, in both directions. Along the way, we prove useful bounds on the difference `∥f m₁ - f m₂∥`. -/ namespace multilinear_map /-- If a multilinear map in finitely many variables on normed spaces satisfies the inequality `∥f m∥ ≤ C * ∏ i, ∥m i∥` on a shell `ε i / ∥c i∥ < ∥m i∥ < ε i` for some positive numbers `ε i` and elements `c i : 𝕜`, `1 < ∥c i∥`, then it satisfies this inequality for all `m`. -/ theorem bound_of_shell {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : multilinear_map 𝕜 E₁ E₂) {ε : ι → ℝ} {C : ℝ} (hε : ∀ (i : ι), 0 < ε i) {c : ι → 𝕜} (hc : ∀ (i : ι), 1 < norm (c i)) (hf : ∀ (m : (i : ι) → E₁ i), (∀ (i : ι), ε i / norm (c i) ≤ norm (m i)) → (∀ (i : ι), norm (m i) < ε i) → norm (coe_fn f m) ≤ C * finset.prod finset.univ fun (i : ι) => norm (m i)) (m : (i : ι) → E₁ i) : norm (coe_fn f m) ≤ C * finset.prod finset.univ fun (i : ι) => norm (m i) := sorry /-- If a multilinear map in finitely many variables on normed spaces is continuous, then it satisfies the inequality `∥f m∥ ≤ C * ∏ i, ∥m i∥`, for some `C` which can be chosen to be positive. -/ theorem exists_bound_of_continuous {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : multilinear_map 𝕜 E₁ E₂) (hf : continuous ⇑f) : ∃ (C : ℝ), 0 < C ∧ ∀ (m : (i : ι) → E₁ i), norm (coe_fn f m) ≤ C * finset.prod finset.univ fun (i : ι) => norm (m i) := sorry /-- If `f` satisfies a boundedness property around `0`, one can deduce a bound on `f m₁ - f m₂` using the multilinearity. Here, we give a precise but hard to use version. See `norm_image_sub_le_of_bound` for a less precise but more usable version. The bound reads `∥f m - f m'∥ ≤ C * ∥m 1 - m' 1∥ * max ∥m 2∥ ∥m' 2∥ * max ∥m 3∥ ∥m' 3∥ * ... * max ∥m n∥ ∥m' n∥ + ...`, where the other terms in the sum are the same products where `1` is replaced by any `i`. -/ theorem norm_image_sub_le_of_bound' {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : multilinear_map 𝕜 E₁ E₂) {C : ℝ} (hC : 0 ≤ C) (H : ∀ (m : (i : ι) → E₁ i), norm (coe_fn f m) ≤ C * finset.prod finset.univ fun (i : ι) => norm (m i)) (m₁ : (i : ι) → E₁ i) (m₂ : (i : ι) → E₁ i) : norm (coe_fn f m₁ - coe_fn f m₂) ≤ C * finset.sum finset.univ fun (i : ι) => finset.prod finset.univ fun (j : ι) => ite (j = i) (norm (m₁ i - m₂ i)) (max (norm (m₁ j)) (norm (m₂ j))) := sorry /-- If `f` satisfies a boundedness property around `0`, one can deduce a bound on `f m₁ - f m₂` using the multilinearity. Here, we give a usable but not very precise version. See `norm_image_sub_le_of_bound'` for a more precise but less usable version. The bound is `∥f m - f m'∥ ≤ C * card ι * ∥m - m'∥ * (max ∥m∥ ∥m'∥) ^ (card ι - 1)`. -/ theorem norm_image_sub_le_of_bound {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : multilinear_map 𝕜 E₁ E₂) {C : ℝ} (hC : 0 ≤ C) (H : ∀ (m : (i : ι) → E₁ i), norm (coe_fn f m) ≤ C * finset.prod finset.univ fun (i : ι) => norm (m i)) (m₁ : (i : ι) → E₁ i) (m₂ : (i : ι) → E₁ i) : norm (coe_fn f m₁ - coe_fn f m₂) ≤ C * ↑(fintype.card ι) * max (norm m₁) (norm m₂) ^ (fintype.card ι - 1) * norm (m₁ - m₂) := sorry /-- If a multilinear map satisfies an inequality `∥f m∥ ≤ C * ∏ i, ∥m i∥`, then it is continuous. -/ theorem continuous_of_bound {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : multilinear_map 𝕜 E₁ E₂) (C : ℝ) (H : ∀ (m : (i : ι) → E₁ i), norm (coe_fn f m) ≤ C * finset.prod finset.univ fun (i : ι) => norm (m i)) : continuous ⇑f := sorry /-- Constructing a continuous multilinear map from a multilinear map satisfying a boundedness condition. -/ def mk_continuous {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : multilinear_map 𝕜 E₁ E₂) (C : ℝ) (H : ∀ (m : (i : ι) → E₁ i), norm (coe_fn f m) ≤ C * finset.prod finset.univ fun (i : ι) => norm (m i)) : continuous_multilinear_map 𝕜 E₁ E₂ := continuous_multilinear_map.mk (mk (to_fun f) sorry sorry) sorry @[simp] theorem coe_mk_continuous {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : multilinear_map 𝕜 E₁ E₂) (C : ℝ) (H : ∀ (m : (i : ι) → E₁ i), norm (coe_fn f m) ≤ C * finset.prod finset.univ fun (i : ι) => norm (m i)) : ⇑(mk_continuous f C H) = ⇑f := rfl /-- Given a multilinear map in `n` variables, if one restricts it to `k` variables putting `z` on the other coordinates, then the resulting restricted function satisfies an inequality `∥f.restr v∥ ≤ C * ∥z∥^(n-k) * Π ∥v i∥` if the original function satisfies `∥f v∥ ≤ C * Π ∥v i∥`. -/ theorem restr_norm_le {𝕜 : Type u} {G : Type wG} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] {k : ℕ} {n : ℕ} (f : multilinear_map 𝕜 (fun (i : fin n) => G) E₂) (s : finset (fin n)) (hk : finset.card s = k) (z : G) {C : ℝ} (H : ∀ (m : (i : fin n) → (fun (i : fin n) => G) i), norm (coe_fn f m) ≤ C * finset.prod finset.univ fun (i : fin n) => norm (m i)) (v : fin k → G) : norm (coe_fn (restr f s hk z) v) ≤ C * norm z ^ (n - k) * finset.prod finset.univ fun (i : fin k) => norm (v i) := sorry end multilinear_map /-! ### Continuous multilinear maps We define the norm `∥f∥` of a continuous multilinear map `f` in finitely many variables as the smallest number such that `∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥` for all `m`. We show that this defines a normed space structure on `continuous_multilinear_map 𝕜 E₁ E₂`. -/ namespace continuous_multilinear_map theorem bound {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E₁ E₂) : ∃ (C : ℝ), 0 < C ∧ ∀ (m : (i : ι) → E₁ i), norm (coe_fn f m) ≤ C * finset.prod finset.univ fun (i : ι) => norm (m i) := multilinear_map.exists_bound_of_continuous (to_multilinear_map f) (cont f) /-- The operator norm of a continuous multilinear map is the inf of all its bounds. -/ def op_norm {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E₁ E₂) : ℝ := Inf (set_of fun (c : ℝ) => 0 ≤ c ∧ ∀ (m : (i : ι) → E₁ i), norm (coe_fn f m) ≤ c * finset.prod finset.univ fun (i : ι) => norm (m i)) protected instance has_op_norm {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] : has_norm (continuous_multilinear_map 𝕜 E₁ E₂) := has_norm.mk op_norm theorem norm_def {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E₁ E₂) : norm f = Inf (set_of fun (c : ℝ) => 0 ≤ c ∧ ∀ (m : (i : ι) → E₁ i), norm (coe_fn f m) ≤ c * finset.prod finset.univ fun (i : ι) => norm (m i)) := rfl -- So that invocations of `real.Inf_le` make sense: we show that the set of -- bounds is nonempty and bounded below. theorem bounds_nonempty {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] {f : continuous_multilinear_map 𝕜 E₁ E₂} : ∃ (c : ℝ), c ∈ set_of fun (c : ℝ) => 0 ≤ c ∧ ∀ (m : (i : ι) → E₁ i), norm (coe_fn f m) ≤ c * finset.prod finset.univ fun (i : ι) => norm (m i) := sorry theorem bounds_bdd_below {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] {f : continuous_multilinear_map 𝕜 E₁ E₂} : bdd_below (set_of fun (c : ℝ) => 0 ≤ c ∧ ∀ (m : (i : ι) → E₁ i), norm (coe_fn f m) ≤ c * finset.prod finset.univ fun (i : ι) => norm (m i)) := sorry theorem op_norm_nonneg {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E₁ E₂) : 0 ≤ norm f := sorry /-- The fundamental property of the operator norm of a continuous multilinear map: `∥f m∥` is bounded by `∥f∥` times the product of the `∥m i∥`. -/ theorem le_op_norm {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E₁ E₂) (m : (i : ι) → E₁ i) : norm (coe_fn f m) ≤ norm f * finset.prod finset.univ fun (i : ι) => norm (m i) := sorry theorem ratio_le_op_norm {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E₁ E₂) (m : (i : ι) → E₁ i) : (norm (coe_fn f m) / finset.prod finset.univ fun (i : ι) => norm (m i)) ≤ norm f := sorry /-- The image of the unit ball under a continuous multilinear map is bounded. -/ theorem unit_le_op_norm {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E₁ E₂) (m : (i : ι) → E₁ i) (h : norm m ≤ 1) : norm (coe_fn f m) ≤ norm f := sorry /-- If one controls the norm of every `f x`, then one controls the norm of `f`. -/ theorem op_norm_le_bound {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E₁ E₂) {M : ℝ} (hMp : 0 ≤ M) (hM : ∀ (m : (i : ι) → E₁ i), norm (coe_fn f m) ≤ M * finset.prod finset.univ fun (i : ι) => norm (m i)) : norm f ≤ M := sorry /-- The operator norm satisfies the triangle inequality. -/ theorem op_norm_add_le {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E₁ E₂) (g : continuous_multilinear_map 𝕜 E₁ E₂) : norm (f + g) ≤ norm f + norm g := sorry /-- A continuous linear map is zero iff its norm vanishes. -/ theorem op_norm_zero_iff {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E₁ E₂) : norm f = 0 ↔ f = 0 := sorry theorem op_norm_smul_le {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E₁ E₂) {𝕜' : Type u_1} [nondiscrete_normed_field 𝕜'] [normed_algebra 𝕜' 𝕜] [normed_space 𝕜' E₂] [is_scalar_tower 𝕜' 𝕜 E₂] (c : 𝕜') : norm (c • f) ≤ norm c * norm f := sorry theorem op_norm_neg {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E₁ E₂) : norm (-f) = norm f := sorry /-- Continuous multilinear maps themselves form a normed space with respect to the operator norm. -/ protected instance to_normed_group {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] : normed_group (continuous_multilinear_map 𝕜 E₁ E₂) := normed_group.of_core (continuous_multilinear_map 𝕜 E₁ E₂) sorry protected instance to_normed_space {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] {𝕜' : Type u_1} [nondiscrete_normed_field 𝕜'] [normed_algebra 𝕜' 𝕜] [normed_space 𝕜' E₂] [is_scalar_tower 𝕜' 𝕜 E₂] : normed_space 𝕜' (continuous_multilinear_map 𝕜 E₁ E₂) := normed_space.mk sorry @[simp] theorem norm_restrict_scalars {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E₁ E₂) {𝕜' : Type u_1} [nondiscrete_normed_field 𝕜'] [normed_algebra 𝕜' 𝕜] [normed_space 𝕜' E₂] [is_scalar_tower 𝕜' 𝕜 E₂] [(i : ι) → normed_space 𝕜' (E₁ i)] [∀ (i : ι), is_scalar_tower 𝕜' 𝕜 (E₁ i)] : norm (restrict_scalars 𝕜' f) = norm f := sorry /-- `continuous_multilinear_map.restrict_scalars` as a `continuous_multilinear_map`. -/ def restrict_scalars_linear {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (𝕜' : Type u_1) [nondiscrete_normed_field 𝕜'] [normed_algebra 𝕜' 𝕜] [normed_space 𝕜' E₂] [is_scalar_tower 𝕜' 𝕜 E₂] [(i : ι) → normed_space 𝕜' (E₁ i)] [∀ (i : ι), is_scalar_tower 𝕜' 𝕜 (E₁ i)] : continuous_linear_map 𝕜' (continuous_multilinear_map 𝕜 E₁ E₂) (continuous_multilinear_map 𝕜' E₁ E₂) := linear_map.mk_continuous (linear_map.mk (restrict_scalars 𝕜') sorry sorry) 1 sorry theorem continuous_restrict_scalars {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] {𝕜' : Type u_1} [nondiscrete_normed_field 𝕜'] [normed_algebra 𝕜' 𝕜] [normed_space 𝕜' E₂] [is_scalar_tower 𝕜' 𝕜 E₂] [(i : ι) → normed_space 𝕜' (E₁ i)] [∀ (i : ι), is_scalar_tower 𝕜' 𝕜 (E₁ i)] : continuous (restrict_scalars 𝕜') := continuous_linear_map.continuous (restrict_scalars_linear 𝕜') /-- The difference `f m₁ - f m₂` is controlled in terms of `∥f∥` and `∥m₁ - m₂∥`, precise version. For a less precise but more usable version, see `norm_image_sub_le`. The bound reads `∥f m - f m'∥ ≤ ∥f∥ * ∥m 1 - m' 1∥ * max ∥m 2∥ ∥m' 2∥ * max ∥m 3∥ ∥m' 3∥ * ... * max ∥m n∥ ∥m' n∥ + ...`, where the other terms in the sum are the same products where `1` is replaced by any `i`.-/ theorem norm_image_sub_le' {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E₁ E₂) (m₁ : (i : ι) → E₁ i) (m₂ : (i : ι) → E₁ i) : norm (coe_fn f m₁ - coe_fn f m₂) ≤ norm f * finset.sum finset.univ fun (i : ι) => finset.prod finset.univ fun (j : ι) => ite (j = i) (norm (m₁ i - m₂ i)) (max (norm (m₁ j)) (norm (m₂ j))) := multilinear_map.norm_image_sub_le_of_bound' (to_multilinear_map f) (norm_nonneg f) (le_op_norm f) m₁ m₂ /-- The difference `f m₁ - f m₂` is controlled in terms of `∥f∥` and `∥m₁ - m₂∥`, less precise version. For a more precise but less usable version, see `norm_image_sub_le'`. The bound is `∥f m - f m'∥ ≤ ∥f∥ * card ι * ∥m - m'∥ * (max ∥m∥ ∥m'∥) ^ (card ι - 1)`.-/ theorem norm_image_sub_le {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E₁ E₂) (m₁ : (i : ι) → E₁ i) (m₂ : (i : ι) → E₁ i) : norm (coe_fn f m₁ - coe_fn f m₂) ≤ norm f * ↑(fintype.card ι) * max (norm m₁) (norm m₂) ^ (fintype.card ι - 1) * norm (m₁ - m₂) := multilinear_map.norm_image_sub_le_of_bound (to_multilinear_map f) (norm_nonneg f) (le_op_norm f) m₁ m₂ /-- Applying a multilinear map to a vector is continuous in both coordinates. -/ theorem continuous_eval {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] : continuous fun (p : continuous_multilinear_map 𝕜 E₁ E₂ × ((i : ι) → E₁ i)) => coe_fn (prod.fst p) (prod.snd p) := sorry theorem continuous_eval_left {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (m : (i : ι) → E₁ i) : continuous fun (p : continuous_multilinear_map 𝕜 E₁ E₂) => coe_fn p m := continuous.comp continuous_eval (continuous.prod_mk continuous_id continuous_const) theorem has_sum_eval {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] {α : Type u_1} {p : α → continuous_multilinear_map 𝕜 E₁ E₂} {q : continuous_multilinear_map 𝕜 E₁ E₂} (h : has_sum p q) (m : (i : ι) → E₁ i) : has_sum (fun (a : α) => coe_fn (p a) m) (coe_fn q m) := sorry /-- If the target space is complete, the space of continuous multilinear maps with its norm is also complete. The proof is essentially the same as for the space of continuous linear maps (modulo the addition of `finset.prod` where needed. The duplication could be avoided by deducing the linear case from the multilinear case via a currying isomorphism. However, this would mess up imports, and it is more satisfactory to have the simplest case as a standalone proof. -/ protected instance complete_space {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] [complete_space E₂] : complete_space (continuous_multilinear_map 𝕜 E₁ E₂) := sorry end continuous_multilinear_map /-- If a continuous multilinear map is constructed from a multilinear map via the constructor `mk_continuous`, then its norm is bounded by the bound given to the constructor if it is nonnegative. -/ theorem multilinear_map.mk_continuous_norm_le {𝕜 : Type u} {ι : Type v} {E₁ : ι → Type w₁} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [(i : ι) → normed_group (E₁ i)] [normed_group E₂] [(i : ι) → normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂] (f : multilinear_map 𝕜 E₁ E₂) {C : ℝ} (hC : 0 ≤ C) (H : ∀ (m : (i : ι) → E₁ i), norm (coe_fn f m) ≤ C * finset.prod finset.univ fun (i : ι) => norm (m i)) : norm (multilinear_map.mk_continuous f C H) ≤ C := continuous_multilinear_map.op_norm_le_bound (multilinear_map.mk_continuous f C H) hC fun (m : (i : ι) → E₁ i) => H m namespace continuous_multilinear_map /-- Given a continuous multilinear map `f` on `n` variables (parameterized by `fin n`) and a subset `s` of `k` of these variables, one gets a new continuous 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 {𝕜 : Type u} {G : Type wG} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] {k : ℕ} {n : ℕ} (f : continuous_multilinear_map 𝕜 (fun (i : fin n) => G) E₂) (s : finset (fin n)) (hk : finset.card s = k) (z : G) : continuous_multilinear_map 𝕜 (fun (i : fin k) => G) E₂ := multilinear_map.mk_continuous (multilinear_map.restr (to_multilinear_map f) s hk z) (norm f * norm z ^ (n - k)) sorry theorem norm_restr {𝕜 : Type u} {G : Type wG} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] {k : ℕ} {n : ℕ} (f : continuous_multilinear_map 𝕜 (fun (i : fin n) => G) E₂) (s : finset (fin n)) (hk : finset.card s = k) (z : G) : norm (restr f s hk z) ≤ norm f * norm z ^ (n - k) := multilinear_map.mk_continuous_norm_le (multilinear_map.restr (to_multilinear_map f) s hk z) (mul_nonneg (norm_nonneg f) (pow_nonneg (norm_nonneg z) (n - k))) (restr._proof_1 f s hk z) /-- The continuous multilinear map on `A^ι`, where `A` is a normed commutative algebra over `𝕜`, associating to `m` the product of all the `m i`. See also `continuous_multilinear_map.mk_pi_algebra_fin`. -/ protected def mk_pi_algebra (𝕜 : Type u) (ι : Type v) [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] (A : Type u_1) [normed_comm_ring A] [normed_algebra 𝕜 A] : continuous_multilinear_map 𝕜 (fun (i : ι) => A) A := multilinear_map.mk_continuous (multilinear_map.mk_pi_algebra 𝕜 ι A) (ite (Nonempty ι) 1 (norm 1)) sorry @[simp] theorem mk_pi_algebra_apply {𝕜 : Type u} {ι : Type v} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] {A : Type u_1} [normed_comm_ring A] [normed_algebra 𝕜 A] (m : ι → A) : coe_fn (continuous_multilinear_map.mk_pi_algebra 𝕜 ι A) m = finset.prod finset.univ fun (i : ι) => m i := rfl theorem norm_mk_pi_algebra_le {𝕜 : Type u} {ι : Type v} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] {A : Type u_1} [normed_comm_ring A] [normed_algebra 𝕜 A] [Nonempty ι] : norm (continuous_multilinear_map.mk_pi_algebra 𝕜 ι A) ≤ 1 := sorry theorem norm_mk_pi_algebra_of_empty {𝕜 : Type u} {ι : Type v} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] {A : Type u_1} [normed_comm_ring A] [normed_algebra 𝕜 A] (h : ¬Nonempty ι) : norm (continuous_multilinear_map.mk_pi_algebra 𝕜 ι A) = norm 1 := sorry @[simp] theorem norm_mk_pi_algebra {𝕜 : Type u} {ι : Type v} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] {A : Type u_1} [normed_comm_ring A] [normed_algebra 𝕜 A] [norm_one_class A] : norm (continuous_multilinear_map.mk_pi_algebra 𝕜 ι A) = 1 := sorry /-- The continuous multilinear map on `A^n`, where `A` is a normed algebra over `𝕜`, associating to `m` the product of all the `m i`. See also: `multilinear_map.mk_pi_algebra`. -/ protected def mk_pi_algebra_fin (𝕜 : Type u) (n : ℕ) [nondiscrete_normed_field 𝕜] (A : Type u_1) [normed_ring A] [normed_algebra 𝕜 A] : continuous_multilinear_map 𝕜 (fun (i : fin n) => A) A := multilinear_map.mk_continuous (multilinear_map.mk_pi_algebra_fin 𝕜 n A) (nat.cases_on n (norm 1) fun (_x : ℕ) => 1) sorry @[simp] theorem mk_pi_algebra_fin_apply {𝕜 : Type u} {n : ℕ} [nondiscrete_normed_field 𝕜] {A : Type u_1} [normed_ring A] [normed_algebra 𝕜 A] (m : fin n → A) : coe_fn (continuous_multilinear_map.mk_pi_algebra_fin 𝕜 n A) m = list.prod (list.of_fn m) := rfl theorem norm_mk_pi_algebra_fin_succ_le {𝕜 : Type u} {n : ℕ} [nondiscrete_normed_field 𝕜] {A : Type u_1} [normed_ring A] [normed_algebra 𝕜 A] : norm (continuous_multilinear_map.mk_pi_algebra_fin 𝕜 (Nat.succ n) A) ≤ 1 := multilinear_map.mk_continuous_norm_le (multilinear_map.mk_pi_algebra_fin 𝕜 (Nat.succ n) A) zero_le_one (mk_pi_algebra_fin._proof_1 𝕜 (Nat.succ n) A) theorem norm_mk_pi_algebra_fin_le_of_pos {𝕜 : Type u} {n : ℕ} [nondiscrete_normed_field 𝕜] {A : Type u_1} [normed_ring A] [normed_algebra 𝕜 A] (hn : 0 < n) : norm (continuous_multilinear_map.mk_pi_algebra_fin 𝕜 n A) ≤ 1 := nat.cases_on n (fun (hn : 0 < 0) => false.elim (has_lt.lt.false hn)) (fun (n : ℕ) (hn : 0 < Nat.succ n) => norm_mk_pi_algebra_fin_succ_le) hn theorem norm_mk_pi_algebra_fin_zero {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {A : Type u_1} [normed_ring A] [normed_algebra 𝕜 A] : norm (continuous_multilinear_map.mk_pi_algebra_fin 𝕜 0 A) = norm 1 := sorry theorem norm_mk_pi_algebra_fin {𝕜 : Type u} {n : ℕ} [nondiscrete_normed_field 𝕜] {A : Type u_1} [normed_ring A] [normed_algebra 𝕜 A] [norm_one_class A] : norm (continuous_multilinear_map.mk_pi_algebra_fin 𝕜 n A) = 1 := sorry /-- The canonical continuous multilinear map on `𝕜^ι`, associating to `m` the product of all the `m i` (multiplied by a fixed reference element `z` in the target module) -/ protected def mk_pi_field (𝕜 : Type u) (ι : Type v) {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [normed_group E₂] [normed_space 𝕜 E₂] (z : E₂) : continuous_multilinear_map 𝕜 (fun (i : ι) => 𝕜) E₂ := multilinear_map.mk_continuous (multilinear_map.mk_pi_ring 𝕜 ι z) (norm z) sorry @[simp] theorem mk_pi_field_apply {𝕜 : Type u} {ι : Type v} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [normed_group E₂] [normed_space 𝕜 E₂] (z : E₂) (m : ι → 𝕜) : coe_fn (continuous_multilinear_map.mk_pi_field 𝕜 ι z) m = (finset.prod finset.univ fun (i : ι) => m i) • z := rfl theorem mk_pi_field_apply_one_eq_self {𝕜 : Type u} {ι : Type v} {E₂ : Type w₂} [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [normed_group E₂] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 (fun (i : ι) => 𝕜) E₂) : continuous_multilinear_map.mk_pi_field 𝕜 ι (coe_fn f fun (i : ι) => 1) = f := to_multilinear_map_inj (multilinear_map.mk_pi_ring_apply_one_eq_self (to_multilinear_map f)) /-- Continuous multilinear maps on `𝕜^n` with values in `E₂` are in bijection with `E₂`, as such a continuous multilinear map is completely determined by its value on the constant vector made of ones. We register this bijection as a linear equivalence in `continuous_multilinear_map.pi_field_equiv_aux`. The continuous linear equivalence is `continuous_multilinear_map.pi_field_equiv`. -/ protected def pi_field_equiv_aux (𝕜 : Type u) (ι : Type v) (E₂ : Type w₂) [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [normed_group E₂] [normed_space 𝕜 E₂] : linear_equiv 𝕜 E₂ (continuous_multilinear_map 𝕜 (fun (i : ι) => 𝕜) E₂) := linear_equiv.mk (fun (z : E₂) => continuous_multilinear_map.mk_pi_field 𝕜 ι z) sorry sorry (fun (f : continuous_multilinear_map 𝕜 (fun (i : ι) => 𝕜) E₂) => coe_fn f fun (i : ι) => 1) sorry sorry /-- Continuous multilinear maps on `𝕜^n` with values in `E₂` are in bijection with `E₂`, as such a continuous multilinear map is completely determined by its value on the constant vector made of ones. We register this bijection as a continuous linear equivalence in `continuous_multilinear_map.pi_field_equiv`. -/ protected def pi_field_equiv (𝕜 : Type u) (ι : Type v) (E₂ : Type w₂) [DecidableEq ι] [fintype ι] [nondiscrete_normed_field 𝕜] [normed_group E₂] [normed_space 𝕜 E₂] : continuous_linear_equiv 𝕜 E₂ (continuous_multilinear_map 𝕜 (fun (i : ι) => 𝕜) E₂) := continuous_linear_equiv.mk (linear_equiv.mk (linear_equiv.to_fun (continuous_multilinear_map.pi_field_equiv_aux 𝕜 ι E₂)) sorry sorry (linear_equiv.inv_fun (continuous_multilinear_map.pi_field_equiv_aux 𝕜 ι E₂)) sorry sorry) end continuous_multilinear_map /-! ### Currying We associate to a continuous multilinear map in `n+1` variables (i.e., based on `fin n.succ`) two curried functions, named `f.curry_left` (which is a continuous linear map on `E 0` taking values in continuous multilinear maps in `n` variables) and `f.curry_right` (which is a continuous multilinear map in `n` variables taking values in continuous linear maps on `E (last n)`). The inverse operations are called `uncurry_left` and `uncurry_right`. We also register continuous linear equiv versions of these correspondences, in `continuous_multilinear_curry_left_equiv` and `continuous_multilinear_curry_right_equiv`. -/ theorem continuous_linear_map.norm_map_tail_le {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_linear_map 𝕜 (E 0) (continuous_multilinear_map 𝕜 (fun (i : fin n) => E (fin.succ i)) E₂)) (m : (i : fin (Nat.succ n)) → E i) : norm (coe_fn (coe_fn f (m 0)) (fin.tail m)) ≤ norm f * finset.prod finset.univ fun (i : fin (Nat.succ n)) => norm (m i) := sorry theorem continuous_multilinear_map.norm_map_init_le {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 (fun (i : fin n) => E (coe_fn fin.cast_succ i)) (continuous_linear_map 𝕜 (E (fin.last n)) E₂)) (m : (i : fin (Nat.succ n)) → E i) : norm (coe_fn (coe_fn f (fin.init m)) (m (fin.last n))) ≤ norm f * finset.prod finset.univ fun (i : fin (Nat.succ n)) => norm (m i) := sorry theorem continuous_multilinear_map.norm_map_cons_le {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E E₂) (x : E 0) (m : (i : fin n) → E (fin.succ i)) : norm (coe_fn f (fin.cons x m)) ≤ norm f * norm x * finset.prod finset.univ fun (i : fin n) => norm (m i) := sorry theorem continuous_multilinear_map.norm_map_snoc_le {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E E₂) (m : (i : fin n) → E (coe_fn fin.cast_succ i)) (x : E (fin.last n)) : norm (coe_fn f (fin.snoc m x)) ≤ (norm f * finset.prod finset.univ fun (i : fin n) => norm (m i)) * norm x := sorry /-! #### Left currying -/ /-- Given a continuous linear map `f` from `E 0` to continuous multilinear maps on `n` variables, construct the corresponding continuous multilinear map on `n+1` variables obtained by concatenating the variables, given by `m ↦ f (m 0) (tail m)`-/ def continuous_linear_map.uncurry_left {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_linear_map 𝕜 (E 0) (continuous_multilinear_map 𝕜 (fun (i : fin n) => E (fin.succ i)) E₂)) : continuous_multilinear_map 𝕜 E E₂ := multilinear_map.mk_continuous (linear_map.uncurry_left (linear_map.comp continuous_multilinear_map.to_multilinear_map_linear (continuous_linear_map.to_linear_map f))) (norm f) sorry @[simp] theorem continuous_linear_map.uncurry_left_apply {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_linear_map 𝕜 (E 0) (continuous_multilinear_map 𝕜 (fun (i : fin n) => E (fin.succ i)) E₂)) (m : (i : fin (Nat.succ n)) → E i) : coe_fn (continuous_linear_map.uncurry_left f) m = coe_fn (coe_fn f (m 0)) (fin.tail m) := rfl /-- Given a continuous multilinear map `f` in `n+1` variables, split the first variable to obtain a continuous linear map into continuous multilinear maps in `n` variables, given by `x ↦ (m ↦ f (cons x m))`. -/ def continuous_multilinear_map.curry_left {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E E₂) : continuous_linear_map 𝕜 (E 0) (continuous_multilinear_map 𝕜 (fun (i : fin n) => E (fin.succ i)) E₂) := linear_map.mk_continuous (linear_map.mk (fun (x : E 0) => multilinear_map.mk_continuous (coe_fn (multilinear_map.curry_left (continuous_multilinear_map.to_multilinear_map f)) x) (norm f * norm x) sorry) sorry sorry) (norm f) sorry @[simp] theorem continuous_multilinear_map.curry_left_apply {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E E₂) (x : E 0) (m : (i : fin n) → E (fin.succ i)) : coe_fn (coe_fn (continuous_multilinear_map.curry_left f) x) m = coe_fn f (fin.cons x m) := rfl @[simp] theorem continuous_linear_map.curry_uncurry_left {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_linear_map 𝕜 (E 0) (continuous_multilinear_map 𝕜 (fun (i : fin n) => E (fin.succ i)) E₂)) : continuous_multilinear_map.curry_left (continuous_linear_map.uncurry_left f) = f := sorry @[simp] theorem continuous_multilinear_map.uncurry_curry_left {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E E₂) : continuous_linear_map.uncurry_left (continuous_multilinear_map.curry_left f) = f := sorry @[simp] theorem continuous_multilinear_map.curry_left_norm {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E E₂) : norm (continuous_multilinear_map.curry_left f) = norm f := sorry @[simp] theorem continuous_linear_map.uncurry_left_norm {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_linear_map 𝕜 (E 0) (continuous_multilinear_map 𝕜 (fun (i : fin n) => E (fin.succ i)) E₂)) : norm (continuous_linear_map.uncurry_left f) = norm f := sorry /-- The space of continuous multilinear maps on `Π(i : fin (n+1)), E i` is canonically isomorphic to the space of continuous linear maps from `E 0` to the space of continuous multilinear maps on `Π(i : fin n), E i.succ `, by separating the first variable. We register this isomorphism as a linear isomorphism in `continuous_multilinear_curry_left_equiv_aux 𝕜 E E₂`. The algebraic version (without continuity assumption on the maps) is `multilinear_curry_left_equiv 𝕜 E E₂`, and the topological isomorphism (registering additionally that the isomorphism is continuous) is `continuous_multilinear_curry_left_equiv 𝕜 E E₂`. 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 continuous_multilinear_curry_left_equiv_aux (𝕜 : Type u) {n : ℕ} (E : fin (Nat.succ n) → Type w) (E₂ : Type w₂) [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] : linear_equiv 𝕜 (continuous_linear_map 𝕜 (E 0) (continuous_multilinear_map 𝕜 (fun (i : fin n) => E (fin.succ i)) E₂)) (continuous_multilinear_map 𝕜 E E₂) := linear_equiv.mk continuous_linear_map.uncurry_left sorry sorry continuous_multilinear_map.curry_left continuous_linear_map.curry_uncurry_left sorry /-- The space of continuous multilinear maps on `Π(i : fin (n+1)), E i` is canonically isomorphic to the space of continuous linear maps from `E 0` to the space of continuous multilinear maps on `Π(i : fin n), E i.succ `, by separating the first variable. We register this isomorphism in `continuous_multilinear_curry_left_equiv 𝕜 E E₂`. The algebraic version (without topology) is given in `multilinear_curry_left_equiv 𝕜 E E₂`. The direct and inverse maps are given by `f.uncurry_left` and `f.curry_left`. Use these unless you need the full framework of continuous linear equivs. -/ def continuous_multilinear_curry_left_equiv (𝕜 : Type u) {n : ℕ} (E : fin (Nat.succ n) → Type w) (E₂ : Type w₂) [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] : continuous_linear_equiv 𝕜 (continuous_linear_map 𝕜 (E 0) (continuous_multilinear_map 𝕜 (fun (i : fin n) => E (fin.succ i)) E₂)) (continuous_multilinear_map 𝕜 E E₂) := continuous_linear_equiv.mk (linear_equiv.mk (linear_equiv.to_fun (continuous_multilinear_curry_left_equiv_aux 𝕜 E E₂)) sorry sorry (linear_equiv.inv_fun (continuous_multilinear_curry_left_equiv_aux 𝕜 E E₂)) sorry sorry) @[simp] theorem continuous_multilinear_curry_left_equiv_apply {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_linear_map 𝕜 (E 0) (continuous_multilinear_map 𝕜 (fun (i : fin n) => E (fin.succ i)) E₂)) (v : (i : fin (Nat.succ n)) → E i) : coe_fn (coe_fn (continuous_multilinear_curry_left_equiv 𝕜 E E₂) f) v = coe_fn (coe_fn f (v 0)) (fin.tail v) := rfl @[simp] theorem continuous_multilinear_curry_left_equiv_symm_apply {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E E₂) (x : E 0) (v : (i : fin n) → E (fin.succ i)) : coe_fn (coe_fn (coe_fn (continuous_linear_equiv.symm (continuous_multilinear_curry_left_equiv 𝕜 E E₂)) f) x) v = coe_fn f (fin.cons x v) := rfl /-! #### Right currying -/ /-- Given a continuous linear map `f` from continuous multilinear maps on `n` variables to continuous linear maps on `E 0`, construct the corresponding continuous multilinear map on `n+1` variables obtained by concatenating the variables, given by `m ↦ f (init m) (m (last n))`. -/ def continuous_multilinear_map.uncurry_right {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 (fun (i : fin n) => E (coe_fn fin.cast_succ i)) (continuous_linear_map 𝕜 (E (fin.last n)) E₂)) : continuous_multilinear_map 𝕜 E E₂ := let f' : multilinear_map 𝕜 (fun (i : fin n) => E (coe_fn fin.cast_succ i)) (linear_map 𝕜 (E (fin.last n)) E₂) := multilinear_map.mk (fun (m : (i : fin n) → E (coe_fn fin.cast_succ i)) => continuous_linear_map.to_linear_map (coe_fn f m)) sorry sorry; multilinear_map.mk_continuous (multilinear_map.uncurry_right f') (norm f) sorry @[simp] theorem continuous_multilinear_map.uncurry_right_apply {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 (fun (i : fin n) => E (coe_fn fin.cast_succ i)) (continuous_linear_map 𝕜 (E (fin.last n)) E₂)) (m : (i : fin (Nat.succ n)) → E i) : coe_fn (continuous_multilinear_map.uncurry_right f) m = coe_fn (coe_fn f (fin.init m)) (m (fin.last n)) := rfl /-- Given a continuous multilinear map `f` in `n+1` variables, split the last variable to obtain a continuous multilinear map in `n` variables into continuous linear maps, given by `m ↦ (x ↦ f (snoc m x))`. -/ def continuous_multilinear_map.curry_right {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E E₂) : continuous_multilinear_map 𝕜 (fun (i : fin n) => E (coe_fn fin.cast_succ i)) (continuous_linear_map 𝕜 (E (fin.last n)) E₂) := let f' : multilinear_map 𝕜 (fun (i : fin n) => E (coe_fn fin.cast_succ i)) (continuous_linear_map 𝕜 (E (fin.last n)) E₂) := multilinear_map.mk (fun (m : (i : fin n) → E (coe_fn fin.cast_succ i)) => linear_map.mk_continuous (coe_fn (multilinear_map.curry_right (continuous_multilinear_map.to_multilinear_map f)) m) (norm f * finset.prod finset.univ fun (i : fin n) => norm (m i)) sorry) sorry sorry; multilinear_map.mk_continuous f' (norm f) sorry @[simp] theorem continuous_multilinear_map.curry_right_apply {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E E₂) (m : (i : fin n) → E (coe_fn fin.cast_succ i)) (x : E (fin.last n)) : coe_fn (coe_fn (continuous_multilinear_map.curry_right f) m) x = coe_fn f (fin.snoc m x) := rfl @[simp] theorem continuous_multilinear_map.curry_uncurry_right {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 (fun (i : fin n) => E (coe_fn fin.cast_succ i)) (continuous_linear_map 𝕜 (E (fin.last n)) E₂)) : continuous_multilinear_map.curry_right (continuous_multilinear_map.uncurry_right f) = f := sorry @[simp] theorem continuous_multilinear_map.uncurry_curry_right {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E E₂) : continuous_multilinear_map.uncurry_right (continuous_multilinear_map.curry_right f) = f := sorry @[simp] theorem continuous_multilinear_map.curry_right_norm {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E E₂) : norm (continuous_multilinear_map.curry_right f) = norm f := sorry @[simp] theorem continuous_multilinear_map.uncurry_right_norm {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 (fun (i : fin n) => E (coe_fn fin.cast_succ i)) (continuous_linear_map 𝕜 (E (fin.last n)) E₂)) : norm (continuous_multilinear_map.uncurry_right f) = norm f := sorry /-- The space of continuous multilinear maps on `Π(i : fin (n+1)), E i` is canonically isomorphic to the space of continuous multilinear maps on `Π(i : fin n), E i.cast_succ` with values in the space of continuous linear maps on `E (last n)`, by separating the last variable. We register this isomorphism as a linear equiv in `continuous_multilinear_curry_right_equiv_aux 𝕜 E E₂`. The algebraic version (without continuity assumption on the maps) is `multilinear_curry_right_equiv 𝕜 E E₂`, and the topological isomorphism (registering additionally that the isomorphism is continuous) is `continuous_multilinear_curry_right_equiv 𝕜 E E₂`. 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 continuous_multilinear_curry_right_equiv_aux (𝕜 : Type u) {n : ℕ} (E : fin (Nat.succ n) → Type w) (E₂ : Type w₂) [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] : linear_equiv 𝕜 (continuous_multilinear_map 𝕜 (fun (i : fin n) => E (coe_fn fin.cast_succ i)) (continuous_linear_map 𝕜 (E (fin.last n)) E₂)) (continuous_multilinear_map 𝕜 E E₂) := linear_equiv.mk continuous_multilinear_map.uncurry_right sorry sorry continuous_multilinear_map.curry_right continuous_multilinear_map.curry_uncurry_right sorry /-- The space of continuous multilinear maps on `Π(i : fin (n+1)), E i` is canonically isomorphic to the space of continuous multilinear maps on `Π(i : fin n), E i.cast_succ` with values in the space of continuous linear maps on `E (last n)`, by separating the last variable. We register this isomorphism as a continuous linear equiv in `continuous_multilinear_curry_right_equiv 𝕜 E E₂`. The algebraic version (without topology) is given in `multilinear_curry_right_equiv 𝕜 E E₂`. The direct and inverse maps are given by `f.uncurry_right` and `f.curry_right`. Use these unless you need the full framework of continuous linear equivs. -/ def continuous_multilinear_curry_right_equiv (𝕜 : Type u) {n : ℕ} (E : fin (Nat.succ n) → Type w) (E₂ : Type w₂) [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] : continuous_linear_equiv 𝕜 (continuous_multilinear_map 𝕜 (fun (i : fin n) => E (coe_fn fin.cast_succ i)) (continuous_linear_map 𝕜 (E (fin.last n)) E₂)) (continuous_multilinear_map 𝕜 E E₂) := continuous_linear_equiv.mk (linear_equiv.mk (linear_equiv.to_fun (continuous_multilinear_curry_right_equiv_aux 𝕜 E E₂)) sorry sorry (linear_equiv.inv_fun (continuous_multilinear_curry_right_equiv_aux 𝕜 E E₂)) sorry sorry) /-- The space of continuous multilinear maps on `Π(i : fin (n+1)), G` is canonically isomorphic to the space of continuous multilinear maps on `Π(i : fin n), G` with values in the space of continuous linear maps on `G`, by separating the last variable. We register this isomorphism as a continuous linear equiv in `continuous_multilinear_curry_right_equiv' 𝕜 n G E₂`. For a version allowing dependent types, see `continuous_multilinear_curry_right_equiv`. When there are no dependent types, use the primed version as it helps Lean a lot for unification. The direct and inverse maps are given by `f.uncurry_right` and `f.curry_right`. Use these unless you need the full framework of continuous linear equivs. -/ def continuous_multilinear_curry_right_equiv' (𝕜 : Type u) (n : ℕ) (G : Type wG) (E₂ : Type w₂) [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] : continuous_linear_equiv 𝕜 (continuous_multilinear_map 𝕜 (fun (i : fin n) => G) (continuous_linear_map 𝕜 G E₂)) (continuous_multilinear_map 𝕜 (fun (i : fin (Nat.succ n)) => G) E₂) := continuous_multilinear_curry_right_equiv 𝕜 (fun (i : fin (Nat.succ n)) => G) E₂ @[simp] theorem continuous_multilinear_curry_right_equiv_apply {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 (fun (i : fin n) => E (coe_fn fin.cast_succ i)) (continuous_linear_map 𝕜 (E (fin.last n)) E₂)) (v : (i : fin (Nat.succ n)) → E i) : coe_fn (coe_fn (continuous_multilinear_curry_right_equiv 𝕜 E E₂) f) v = coe_fn (coe_fn f (fin.init v)) (v (fin.last n)) := rfl @[simp] theorem continuous_multilinear_curry_right_equiv_symm_apply {𝕜 : Type u} {n : ℕ} {E : fin (Nat.succ n) → Type w} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [(i : fin (Nat.succ n)) → normed_group (E i)] [normed_group E₂] [(i : fin (Nat.succ n)) → normed_space 𝕜 (E i)] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 E E₂) (v : (i : fin n) → E (coe_fn fin.cast_succ i)) (x : E (fin.last n)) : coe_fn (coe_fn (coe_fn (continuous_linear_equiv.symm (continuous_multilinear_curry_right_equiv 𝕜 E E₂)) f) v) x = coe_fn f (fin.snoc v x) := rfl @[simp] theorem continuous_multilinear_curry_right_equiv_apply' {𝕜 : Type u} {n : ℕ} {G : Type wG} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 (fun (i : fin n) => G) (continuous_linear_map 𝕜 G E₂)) (v : fin (Nat.succ n) → G) : coe_fn (coe_fn (continuous_multilinear_curry_right_equiv' 𝕜 n G E₂) f) v = coe_fn (coe_fn f (fin.init v)) (v (fin.last n)) := rfl @[simp] theorem continuous_multilinear_curry_right_equiv_symm_apply' {𝕜 : Type u} {n : ℕ} {G : Type wG} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 (fun (i : fin (Nat.succ n)) => G) E₂) (v : fin n → G) (x : G) : coe_fn (coe_fn (coe_fn (continuous_linear_equiv.symm (continuous_multilinear_curry_right_equiv' 𝕜 n G E₂)) f) v) x = coe_fn f (fin.snoc v x) := rfl /-! #### Currying with `0` variables The space of multilinear maps with `0` variables is trivial: such a multilinear map is just an arbitrary constant (note that multilinear maps in `0` variables need not map `0` to `0`!). Therefore, the space of continuous multilinear maps on `(fin 0) → G` with values in `E₂` is isomorphic (and even isometric) to `E₂`. As this is the zeroth step in the construction of iterated derivatives, we register this isomorphism. -/ /-- Associating to a continuous multilinear map in `0` variables the unique value it takes. -/ def continuous_multilinear_map.uncurry0 {𝕜 : Type u} {G : Type wG} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 (fun (i : fin 0) => G) E₂) : E₂ := coe_fn f 0 /-- Associating to an element `x` of a vector space `E₂` the continuous multilinear map in `0` variables taking the (unique) value `x` -/ def continuous_multilinear_map.curry0 (𝕜 : Type u) (G : Type wG) {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] (x : E₂) : continuous_multilinear_map 𝕜 (fun (i : fin 0) => G) E₂ := continuous_multilinear_map.mk (multilinear_map.mk (fun (m : fin 0 → G) => x) sorry sorry) sorry @[simp] theorem continuous_multilinear_map.curry0_apply (𝕜 : Type u) {G : Type wG} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] (x : E₂) (m : fin 0 → G) : coe_fn (continuous_multilinear_map.curry0 𝕜 G x) m = x := rfl @[simp] theorem continuous_multilinear_map.uncurry0_apply {𝕜 : Type u} {G : Type wG} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 (fun (i : fin 0) => G) E₂) : continuous_multilinear_map.uncurry0 f = coe_fn f 0 := rfl @[simp] theorem continuous_multilinear_map.apply_zero_curry0 {𝕜 : Type u} {G : Type wG} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 (fun (i : fin 0) => G) E₂) {x : fin 0 → G} : continuous_multilinear_map.curry0 𝕜 G (coe_fn f x) = f := sorry theorem continuous_multilinear_map.uncurry0_curry0 {𝕜 : Type u} {G : Type wG} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 (fun (i : fin 0) => G) E₂) : continuous_multilinear_map.curry0 𝕜 G (continuous_multilinear_map.uncurry0 f) = f := sorry @[simp] theorem continuous_multilinear_map.curry0_uncurry0 (𝕜 : Type u) (G : Type wG) {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] (x : E₂) : continuous_multilinear_map.uncurry0 (continuous_multilinear_map.curry0 𝕜 G x) = x := rfl @[simp] theorem continuous_multilinear_map.uncurry0_norm (𝕜 : Type u) (G : Type wG) {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] (x : E₂) : norm (continuous_multilinear_map.curry0 𝕜 G x) = norm x := sorry @[simp] theorem continuous_multilinear_map.fin0_apply_norm {𝕜 : Type u} {G : Type wG} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 (fun (i : fin 0) => G) E₂) {x : fin 0 → G} : norm (coe_fn f x) = norm f := sorry theorem continuous_multilinear_map.curry0_norm {𝕜 : Type u} {G : Type wG} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 (fun (i : fin 0) => G) E₂) : norm (continuous_multilinear_map.uncurry0 f) = norm f := sorry /-- The linear isomorphism between elements of a normed space, and continuous multilinear maps in `0` variables with values in this normed space. The continuous version is given in `continuous_multilinear_curry_fin0`. The direct and inverse maps are `uncurry0` and `curry0`. Use these unless you need the full framework of linear equivs. -/ def continuous_multilinear_curry_fin0_aux (𝕜 : Type u) (G : Type wG) (E₂ : Type w₂) [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] : linear_equiv 𝕜 (continuous_multilinear_map 𝕜 (fun (i : fin 0) => G) E₂) E₂ := linear_equiv.mk (fun (f : continuous_multilinear_map 𝕜 (fun (i : fin 0) => G) E₂) => continuous_multilinear_map.uncurry0 f) sorry sorry (fun (f : E₂) => continuous_multilinear_map.curry0 𝕜 G f) continuous_multilinear_map.uncurry0_curry0 (continuous_multilinear_map.curry0_uncurry0 𝕜 G) /-- The continuous linear isomorphism between elements of a normed space, and continuous multilinear maps in `0` variables with values in this normed space. The direct and inverse maps are `uncurry0` and `curry0`. Use these unless you need the full framework of continuous linear equivs. -/ def continuous_multilinear_curry_fin0 (𝕜 : Type u) (G : Type wG) (E₂ : Type w₂) [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] : continuous_linear_equiv 𝕜 (continuous_multilinear_map 𝕜 (fun (i : fin 0) => G) E₂) E₂ := continuous_linear_equiv.mk (linear_equiv.mk (linear_equiv.to_fun (continuous_multilinear_curry_fin0_aux 𝕜 G E₂)) sorry sorry (linear_equiv.inv_fun (continuous_multilinear_curry_fin0_aux 𝕜 G E₂)) sorry sorry) @[simp] theorem continuous_multilinear_curry_fin0_apply {𝕜 : Type u} {G : Type wG} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 (fun (i : fin 0) => G) E₂) : coe_fn (continuous_multilinear_curry_fin0 𝕜 G E₂) f = coe_fn f 0 := rfl @[simp] theorem continuous_multilinear_curry_fin0_symm_apply {𝕜 : Type u} {G : Type wG} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] (x : E₂) (v : fin 0 → G) : coe_fn (coe_fn (continuous_linear_equiv.symm (continuous_multilinear_curry_fin0 𝕜 G E₂)) x) v = x := rfl /-! #### With 1 variable -/ /-- Continuous multilinear maps from `G^1` to `E₂` are isomorphic with continuous linear maps from `G` to `E₂`. -/ def continuous_multilinear_curry_fin1 (𝕜 : Type u) (G : Type wG) (E₂ : Type w₂) [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] : continuous_linear_equiv 𝕜 (continuous_multilinear_map 𝕜 (fun (i : fin 1) => G) E₂) (continuous_linear_map 𝕜 G E₂) := continuous_linear_equiv.trans (continuous_linear_equiv.symm (continuous_multilinear_curry_right_equiv 𝕜 (fun (i : fin 1) => G) E₂)) (continuous_multilinear_curry_fin0 𝕜 G (continuous_linear_map 𝕜 G E₂)) @[simp] theorem continuous_multilinear_curry_fin1_apply {𝕜 : Type u} {G : Type wG} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] (f : continuous_multilinear_map 𝕜 (fun (i : fin 1) => G) E₂) (x : G) : coe_fn (coe_fn (continuous_multilinear_curry_fin1 𝕜 G E₂) f) x = coe_fn f (fin.snoc 0 x) := rfl @[simp] theorem continuous_multilinear_curry_fin1_symm_apply {𝕜 : Type u} {G : Type wG} {E₂ : Type w₂} [nondiscrete_normed_field 𝕜] [normed_group G] [normed_group E₂] [normed_space 𝕜 G] [normed_space 𝕜 E₂] (f : continuous_linear_map 𝕜 G E₂) (v : fin 1 → G) : coe_fn (coe_fn (continuous_linear_equiv.symm (continuous_multilinear_curry_fin1 𝕜 G E₂)) f) v = coe_fn f (v 0) := rfl end Mathlib
d12521a5d6c71bab317c461a345728872ab38435
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/model_theory/fraisse.lean
2f372ad156a27b60f36167cbf4bda9414b7f2bab
[ "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
13,617
lean
/- Copyright (c) 2022 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import model_theory.finitely_generated import model_theory.direct_limit import model_theory.bundled /-! # Fraïssé Classes and Fraïssé Limits > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file pertains to the ages of countable first-order structures. The age of a structure is the class of all finitely-generated structures that embed into it. Of particular interest are Fraïssé classes, which are exactly the ages of countable ultrahomogeneous structures. To each is associated a unique (up to nonunique isomorphism) Fraïssé limit - the countable ultrahomogeneous structure with that age. ## Main Definitions * `first_order.language.age` is the class of finitely-generated structures that embed into a particular structure. * A class `K` has the `first_order.language.hereditary` when all finitely-generated structures that embed into structures in `K` are also in `K`. * A class `K` has the `first_order.language.joint_embedding` when for every `M`, `N` in `K`, there is another structure in `K` into which both `M` and `N` embed. * A class `K` has the `first_order.language.amalgamation` when for any pair of embeddings of a structure `M` in `K` into other structures in `K`, those two structures can be embedded into a fourth structure in `K` such that the resulting square of embeddings commutes. * `first_order.language.is_fraisse` indicates that a class is nonempty, isomorphism-invariant, essentially countable, and satisfies the hereditary, joint embedding, and amalgamation properties. * `first_order.language.is_fraisse_limit` indicates that a structure is a Fraïssé limit for a given class. ## Main Results * We show that the age of any structure is isomorphism-invariant and satisfies the hereditary and joint-embedding properties. * `first_order.language.age.countable_quotient` shows that the age of any countable structure is essentially countable. * `first_order.language.exists_countable_is_age_of_iff` gives necessary and sufficient conditions for a class to be the age of a countable structure in a language with countably many functions. ## Implementation Notes * Classes of structures are formalized with `set (bundled L.Structure)`. * Some results pertain to countable limit structures, others to countably-generated limit structures. In the case of a language with countably many function symbols, these are equivalent. ## References - [W. Hodges, *A Shorter Model Theory*][Hodges97] - [K. Tent, M. Ziegler, *A Course in Model Theory*][Tent_Ziegler] ## TODO * Show existence and uniqueness of Fraïssé limits -/ universes u v w w' open_locale first_order open set category_theory namespace first_order namespace language open Structure substructure variables (L : language.{u v}) /-! ### The Age of a Structure and Fraïssé Classes-/ /-- The age of a structure `M` is the class of finitely-generated structures that embed into it. -/ def age (M : Type w) [L.Structure M] : set (bundled.{w} L.Structure) := { N | Structure.fg L N ∧ nonempty (N ↪[L] M) } variables {L} (K : set (bundled.{w} L.Structure)) /-- A class `K` has the hereditary property when all finitely-generated structures that embed into structures in `K` are also in `K`. -/ def hereditary : Prop := ∀ (M : bundled.{w} L.Structure), M ∈ K → L.age M ⊆ K /-- A class `K` has the joint embedding property when for every `M`, `N` in `K`, there is another structure in `K` into which both `M` and `N` embed. -/ def joint_embedding : Prop := directed_on (λ M N : bundled.{w} L.Structure, nonempty (M ↪[L] N)) K /-- A class `K` has the amalgamation property when for any pair of embeddings of a structure `M` in `K` into other structures in `K`, those two structures can be embedded into a fourth structure in `K` such that the resulting square of embeddings commutes. -/ def amalgamation : Prop := ∀ (M N P : bundled.{w} L.Structure) (MN : M ↪[L] N) (MP : M ↪[L] P), M ∈ K → N ∈ K → P ∈ K → ∃ (Q : bundled.{w} L.Structure) (NQ : N ↪[L] Q) (PQ : P ↪[L] Q), Q ∈ K ∧ NQ.comp MN = PQ.comp MP /-- A Fraïssé class is a nonempty, isomorphism-invariant, essentially countable class of structures satisfying the hereditary, joint embedding, and amalgamation properties. -/ class is_fraisse : Prop := (is_nonempty : K.nonempty) (fg : ∀ M : bundled.{w} L.Structure, M ∈ K → Structure.fg L M) (is_equiv_invariant : ∀ (M N : bundled.{w} L.Structure), nonempty (M ≃[L] N) → (M ∈ K ↔ N ∈ K)) (is_essentially_countable : (quotient.mk '' K).countable) (hereditary : hereditary K) (joint_embedding : joint_embedding K) (amalgamation : amalgamation K) variables {K} (L) (M : Type w) [L.Structure M] lemma age.is_equiv_invariant (N P : bundled.{w} L.Structure) (h : nonempty (N ≃[L] P)) : N ∈ L.age M ↔ P ∈ L.age M := and_congr h.some.fg_iff ⟨nonempty.map (λ x, embedding.comp x h.some.symm.to_embedding), nonempty.map (λ x, embedding.comp x h.some.to_embedding)⟩ variables {L} {M} {N : Type w} [L.Structure N] lemma embedding.age_subset_age (MN : M ↪[L] N) : L.age M ⊆ L.age N := λ _, and.imp_right (nonempty.map MN.comp) lemma equiv.age_eq_age (MN : M ≃[L] N) : L.age M = L.age N := le_antisymm MN.to_embedding.age_subset_age MN.symm.to_embedding.age_subset_age lemma Structure.fg.mem_age_of_equiv {M N : bundled L.Structure} (h : Structure.fg L M) (MN : nonempty (M ≃[L] N)) : N ∈ L.age M := ⟨MN.some.fg_iff.1 h, ⟨MN.some.symm.to_embedding⟩⟩ lemma hereditary.is_equiv_invariant_of_fg (h : hereditary K) (fg : ∀ (M : bundled.{w} L.Structure), M ∈ K → Structure.fg L M) (M N : bundled.{w} L.Structure) (hn : nonempty (M ≃[L] N)) : M ∈ K ↔ N ∈ K := ⟨λ MK, h M MK ((fg M MK).mem_age_of_equiv hn), λ NK, h N NK ((fg N NK).mem_age_of_equiv ⟨hn.some.symm⟩)⟩ variable (M) lemma age.nonempty : (L.age M).nonempty := ⟨bundled.of (substructure.closure L (∅ : set M)), (fg_iff_Structure_fg _).1 (fg_closure set.finite_empty), ⟨substructure.subtype _⟩⟩ lemma age.hereditary : hereditary (L.age M) := λ N hN P hP, hN.2.some.age_subset_age hP lemma age.joint_embedding : joint_embedding (L.age M) := λ N hN P hP, ⟨bundled.of ↥(hN.2.some.to_hom.range ⊔ hP.2.some.to_hom.range), ⟨(fg_iff_Structure_fg _).1 ((hN.1.range hN.2.some.to_hom).sup (hP.1.range hP.2.some.to_hom)), ⟨subtype _⟩⟩, ⟨embedding.comp (inclusion le_sup_left) hN.2.some.equiv_range.to_embedding⟩, ⟨embedding.comp (inclusion le_sup_right) hP.2.some.equiv_range.to_embedding⟩⟩ /-- The age of a countable structure is essentially countable (has countably many isomorphism classes). -/ lemma age.countable_quotient [h : countable M] : (quotient.mk '' L.age M).countable := begin classical, refine (congr_arg _ (set.ext $ forall_quotient_iff.2 $ λ N, _)).mp (countable_range $ λ s : finset M, ⟦⟨closure L (s : set M), infer_instance⟩⟧), simp only [mem_image, mem_range, mem_set_of_eq, quotient.eq], split, { rintro ⟨s, hs⟩, use bundled.of ↥(closure L (s : set M)), exact ⟨⟨(fg_iff_Structure_fg _).1 (fg_closure s.finite_to_set), ⟨subtype _⟩⟩, hs⟩ }, { rintro ⟨P, ⟨⟨s, hs⟩, ⟨PM⟩⟩, hP2⟩, refine ⟨s.image PM, setoid.trans _ hP2⟩, rw [← embedding.coe_to_hom, finset.coe_image, closure_image PM.to_hom, hs, ← hom.range_eq_map], exact ⟨PM.equiv_range.symm⟩ } end /-- The age of a direct limit of structures is the union of the ages of the structures. -/ @[simp] theorem age_direct_limit {ι : Type w} [preorder ι] [is_directed ι (≤)] [nonempty ι] (G : ι → Type (max w w')) [Π i, L.Structure (G i)] (f : Π i j, i ≤ j → G i ↪[L] G j) [directed_system G (λ i j h, f i j h)] : L.age (direct_limit G f) = ⋃ (i : ι), L.age (G i) := begin classical, ext M, simp only [mem_Union], split, { rintro ⟨Mfg, ⟨e⟩⟩, obtain ⟨s, hs⟩ := Mfg.range e.to_hom, let out := @quotient.out _ (direct_limit.setoid G f), obtain ⟨i, hi⟩ := finset.exists_le (s.image (sigma.fst ∘ out)), have e' := ((direct_limit.of L ι G f i).equiv_range.symm.to_embedding), refine ⟨i, Mfg, ⟨e'.comp ((substructure.inclusion _).comp e.equiv_range.to_embedding)⟩⟩, rw [← hs, closure_le], intros x hx, refine ⟨f (out x).1 i (hi (out x).1 (finset.mem_image_of_mem _ hx)) (out x).2, _⟩, rw [embedding.coe_to_hom, direct_limit.of_apply, quotient.mk_eq_iff_out, direct_limit.equiv_iff G f _ (hi (out x).1 (finset.mem_image_of_mem _ hx)), directed_system.map_self], refl }, { rintro ⟨i, Mfg, ⟨e⟩⟩, exact ⟨Mfg, ⟨embedding.comp (direct_limit.of L ι G f i) e⟩⟩ } end /-- Sufficient conditions for a class to be the age of a countably-generated structure. -/ theorem exists_cg_is_age_of (hn : K.nonempty) (h : ∀ (M N : bundled.{w} L.Structure), nonempty (M ≃[L] N) → (M ∈ K ↔ N ∈ K)) (hc : (quotient.mk '' K).countable) (fg : ∀ (M : bundled.{w} L.Structure), M ∈ K → Structure.fg L M) (hp : hereditary K) (jep : joint_embedding K) : ∃ (M : bundled.{w} L.Structure), Structure.cg L M ∧ L.age M = K := begin obtain ⟨F, hF⟩ := hc.exists_eq_range (hn.image _), simp only [set.ext_iff, forall_quotient_iff, mem_image, mem_range, quotient.eq] at hF, simp_rw [quotient.eq_mk_iff_out] at hF, have hF' : ∀ n : ℕ, (F n).out ∈ K, { intro n, obtain ⟨P, hP1, hP2⟩ := (hF (F n).out).2 ⟨n, setoid.refl _⟩, exact (h _ _ hP2).1 hP1 }, choose P hPK hP hFP using (λ (N : K) (n : ℕ), jep N N.2 (F (n + 1)).out (hF' _)), let G : ℕ → K := @nat.rec (λ _, K) (⟨(F 0).out, hF' 0⟩) (λ n N, ⟨P N n, hPK N n⟩), let f : Π (i j), i ≤ j → G i ↪[L] G j := directed_system.nat_le_rec (λ n, (hP _ n).some), refine ⟨bundled.of (direct_limit (λ n, G n) f), direct_limit.cg _ (λ n, (fg _ (G n).2).cg), (age_direct_limit _ _).trans (subset_antisymm (Union_subset (λ n N hN, hp (G n) (G n).2 hN)) (λ N KN, _))⟩, obtain ⟨n, ⟨e⟩⟩ := (hF N).1 ⟨N, KN, setoid.refl _⟩, refine mem_Union_of_mem n ⟨fg _ KN, ⟨embedding.comp _ e.symm.to_embedding⟩⟩, cases n, { exact embedding.refl _ _ }, { exact (hFP _ n).some } end theorem exists_countable_is_age_of_iff [countable (Σl, L.functions l)] : (∃ (M : bundled.{w} L.Structure), countable M ∧ L.age M = K) ↔ K.nonempty ∧ (∀ (M N : bundled.{w} L.Structure), nonempty (M ≃[L] N) → (M ∈ K ↔ N ∈ K)) ∧ (quotient.mk '' K).countable ∧ (∀ (M : bundled.{w} L.Structure), M ∈ K → Structure.fg L M) ∧ hereditary K ∧ joint_embedding K := begin split, { rintros ⟨M, h1, h2, rfl⟩, resetI, refine ⟨age.nonempty M, age.is_equiv_invariant L M, age.countable_quotient M, λ N hN, hN.1, age.hereditary M, age.joint_embedding M⟩, }, { rintros ⟨Kn, eqinv, cq, hfg, hp, jep⟩, obtain ⟨M, hM, rfl⟩ := exists_cg_is_age_of Kn eqinv cq hfg hp jep, exact ⟨M, Structure.cg_iff_countable.1 hM, rfl⟩ } end variables {K} (L) (M) /-- A structure `M` is ultrahomogeneous if every embedding of a finitely generated substructure into `M` extends to an automorphism of `M`. -/ def is_ultrahomogeneous : Prop := ∀ (S : L.substructure M) (hs : S.fg) (f : S ↪[L] M), ∃ (g : M ≃[L] M), f = g.to_embedding.comp S.subtype variables {L} (K) /-- A structure `M` is a Fraïssé limit for a class `K` if it is countably generated, ultrahomogeneous, and has age `K`. -/ @[protect_proj] structure is_fraisse_limit [countable (Σl, L.functions l)] [countable M] : Prop := (ultrahomogeneous : is_ultrahomogeneous L M) (age : L.age M = K) variables {L} {M} lemma is_ultrahomogeneous.amalgamation_age (h : L.is_ultrahomogeneous M) : amalgamation (L.age M) := begin rintros N P Q NP NQ ⟨Nfg, ⟨NM⟩⟩ ⟨Pfg, ⟨PM⟩⟩ ⟨Qfg, ⟨QM⟩⟩, obtain ⟨g, hg⟩ := h ((PM.comp NP).to_hom.range) (Nfg.range _) ((QM.comp NQ).comp (PM.comp NP).equiv_range.symm.to_embedding), let s := (g.to_hom.comp PM.to_hom).range ⊔ QM.to_hom.range, refine ⟨bundled.of s, embedding.comp (substructure.inclusion le_sup_left) ((g.to_embedding.comp PM).equiv_range).to_embedding, embedding.comp (substructure.inclusion le_sup_right) QM.equiv_range.to_embedding, ⟨(fg_iff_Structure_fg _).1 (fg.sup (Pfg.range _) (Qfg.range _)), ⟨substructure.subtype _⟩⟩, _⟩, ext n, have hgn := (embedding.ext_iff.1 hg) ((PM.comp NP).equiv_range n), simp only [embedding.comp_apply, equiv.coe_to_embedding, equiv.symm_apply_apply, substructure.coe_subtype, embedding.equiv_range_apply] at hgn, simp only [embedding.comp_apply, equiv.coe_to_embedding, substructure.coe_inclusion, set.coe_inclusion, embedding.equiv_range_apply, hgn], end lemma is_ultrahomogeneous.age_is_fraisse [countable M] (h : L.is_ultrahomogeneous M) : is_fraisse (L.age M) := ⟨age.nonempty M, λ _ hN, hN.1, age.is_equiv_invariant L M, age.countable_quotient M, age.hereditary M, age.joint_embedding M, h.amalgamation_age⟩ namespace is_fraisse_limit /-- If a class has a Fraïssé limit, it must be Fraïssé. -/ theorem is_fraisse [countable (Σl, L.functions l)] [countable M] (h : is_fraisse_limit K M) : is_fraisse K := (congr rfl h.age).mp h.ultrahomogeneous.age_is_fraisse end is_fraisse_limit end language end first_order
4ec2225b679c173566148fdf8fd7d65c0da26951
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
/library/init/nat.lean
3888f8aa160b4b763755a68a6941fa36d3b5cde1
[ "Apache-2.0" ]
permissive
soonhokong/lean-osx
4a954262c780e404c1369d6c06516161d07fcb40
3670278342d2f4faa49d95b46d86642d7875b47c
refs/heads/master
1,611,410,334,552
1,474,425,686,000
1,474,425,686,000
12,043,103
5
1
null
null
null
null
UTF-8
Lean
false
false
12,747
lean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Leonardo de Moura -/ prelude import init.relation init.num notation `ℕ` := nat namespace nat protected theorem zero_add : ∀ n : ℕ, 0 + n = n | 0 := rfl | (n+1) := congr_arg succ (zero_add n) theorem succ_add : ∀ n m : ℕ, (succ n) + m = succ (n + m) | n 0 := rfl | n (m+1) := congr_arg succ (succ_add n m) protected theorem add_comm : ∀ n m : ℕ, n + m = m + n | n 0 := eq.symm (nat.zero_add n) | n (m+1) := suffices succ (n + m) = succ (m + n), from eq.symm (succ_add m n) ▸ this, congr_arg succ (add_comm n m) protected theorem bit0_succ_eq (n : ℕ) : bit0 (succ n) = succ (succ (bit0 n)) := show succ (succ n + n) = succ (succ (n + n)), from succ_add n n ▸ rfl protected theorem bit1_eq_succ_bit0 (n : ℕ) : bit1 n = succ (bit0 n) := rfl protected theorem bit1_succ_eq (n : ℕ) : bit1 (succ n) = succ (succ (bit1 n)) := eq.trans (nat.bit1_eq_succ_bit0 (succ n)) (congr_arg succ (nat.bit0_succ_eq n)) theorem succ_ne_zero (n : ℕ) : succ n ≠ 0 := assume h, nat.no_confusion h theorem succ_ne_self : ∀ n : ℕ, succ n ≠ n | 0 h := absurd h (nat.succ_ne_zero 0) | (n+1) h := succ_ne_self n (nat.no_confusion h (λ h, h)) protected theorem one_ne_zero : 1 ≠ (0 : ℕ) := assume h, nat.no_confusion h protected theorem bit0_ne_zero : ∀ n : ℕ, n ≠ 0 → bit0 n ≠ 0 | 0 h := absurd rfl h | (n+1) h := nat.succ_ne_zero _ protected theorem bit1_ne_zero (n : ℕ) : bit1 n ≠ 0 := show succ (n + n) ≠ 0, from succ_ne_zero (n + n) protected theorem bit1_ne_one : ∀ n : ℕ, n ≠ 0 → bit1 n ≠ 1 | 0 h h1 := absurd rfl h | (n+1) h h1 := nat.no_confusion h1 (λ h2, absurd h2 (nat.succ_ne_zero _)) protected theorem bit0_ne_one : ∀ n : ℕ, bit0 n ≠ 1 | 0 h := absurd h (ne.symm nat.one_ne_zero) | (n+1) h := have h1 : succ (succ (n + n)) = 1, from succ_add n n ▸ h, nat.no_confusion h1 (λ h2, absurd h2 (succ_ne_zero (n + n))) protected theorem add_self_ne_one : ∀ (n : ℕ), n + n ≠ 1 | 0 h := nat.no_confusion h | (n+1) h := have h1 : succ (succ (n + n)) = 1, from succ_add n n ▸ h, nat.no_confusion h1 (λ h2, absurd h2 (nat.succ_ne_zero (n + n))) protected theorem bit1_ne_bit0 : ∀ (n m : ℕ), bit1 n ≠ bit0 m | 0 m h := absurd h (ne.symm (nat.add_self_ne_one m)) | (n+1) 0 h := have h1 : succ (bit0 (succ n)) = 0, from h, absurd h1 (nat.succ_ne_zero _) | (n+1) (m+1) h := have h1 : succ (succ (bit1 n)) = succ (succ (bit0 m)), from nat.bit0_succ_eq m ▸ nat.bit1_succ_eq n ▸ h, have h2 : bit1 n = bit0 m, from nat.no_confusion h1 (λ h2', nat.no_confusion h2' (λ h2'', h2'')), absurd h2 (bit1_ne_bit0 n m) inductive le (a : ℕ) : ℕ → Prop | nat_refl : le a -- use nat_refl to avoid overloading le.refl | step : Π {b}, le b → le (succ b) attribute [instance, priority nat.prio] definition nat_has_le : has_le ℕ := ⟨nat.le⟩ attribute [refl] protected definition le_refl : ∀ a : ℕ, a ≤ a := le.nat_refl attribute [reducible] protected definition lt (n m : ℕ) := succ n ≤ m attribute [instance, priority nat.prio] definition nat_has_lt : has_lt ℕ := ⟨nat.lt⟩ definition pred : ℕ → ℕ | 0 := 0 | (a+1) := a protected definition sub : ℕ → ℕ → ℕ | a 0 := a | a (b+1) := pred (sub a b) protected definition mul (a b : ℕ) : ℕ := nat.rec_on b zero (λ b₁ r, r + a) attribute [instance, priority nat.prio] definition nat_has_sub : has_sub ℕ := ⟨nat.sub⟩ attribute [instance, priority nat.prio] definition nat_has_mul : has_mul ℕ := ⟨nat.mul⟩ attribute [instance, priority nat.prio] protected definition has_decidable_eq : ∀ x y : ℕ, decidable (x = y) | zero zero := is_true rfl | (succ x) zero := is_false (λ h, nat.no_confusion h) | zero (succ y) := is_false (λ h, nat.no_confusion h) | (succ x) (succ y) := match has_decidable_eq x y with | is_true xeqy := is_true (xeqy ▸ eq.refl (succ x)) | is_false xney := is_false (λ h, nat.no_confusion h (λ xeqy, absurd xeqy xney)) end /- properties of inequality -/ protected theorem le_of_eq {n m : ℕ} (p : n = m) : n ≤ m := p ▸ le.nat_refl n theorem le_succ (n : ℕ) : n ≤ succ n := le.step (nat.le_refl n) theorem pred_le : ∀ (n : ℕ), pred n ≤ n | 0 := le.nat_refl 0 | (succ a) := le.step (le.nat_refl a) attribute [simp] theorem le_succ_iff_true (n : ℕ) : n ≤ succ n ↔ true := iff_true_intro (le_succ n) attribute [simp] theorem pred_le_iff_true (n : ℕ) : pred n ≤ n ↔ true := iff_true_intro (pred_le n) protected theorem le_trans {n m k : ℕ} (H1 : n ≤ m) : m ≤ k → n ≤ k := le.rec H1 (λp H2, le.step) theorem le_succ_of_le {n m : ℕ} (H : n ≤ m) : n ≤ succ m := nat.le_trans H (le_succ m) theorem le_of_succ_le {n m : ℕ} (H : succ n ≤ m) : n ≤ m := nat.le_trans (le_succ n) H protected theorem le_of_lt {n m : ℕ} (H : n < m) : n ≤ m := le_of_succ_le H theorem succ_le_succ {n m : ℕ} : n ≤ m → succ n ≤ succ m := λ H, le.rec (nat.le_refl (succ n)) (λ a b, le.step) H theorem pred_le_pred {n m : ℕ} : n ≤ m → pred n ≤ pred m := λ H, le.rec (nat.le_refl (pred n)) (λ n, nat.rec (λ a b, b) (λ a b c, le.step) n) H theorem le_of_succ_le_succ {n m : ℕ} : succ n ≤ succ m → n ≤ m := pred_le_pred theorem le_succ_of_pred_le {n m : ℕ} : pred n ≤ m → n ≤ succ m := nat.cases_on n le.step (λa, succ_le_succ) theorem not_succ_le_zero : ∀ (n : ℕ), succ n ≤ 0 → false . theorem succ_le_zero_iff_false (n : ℕ) : succ n ≤ 0 ↔ false := iff_false_intro (not_succ_le_zero n) theorem not_succ_le_self : ∀ n : ℕ, ¬succ n ≤ n := λ n, nat.rec (not_succ_le_zero 0) (λa b c, b (le_of_succ_le_succ c)) n attribute [simp] theorem succ_le_self_iff_false (n : ℕ) : succ n ≤ n ↔ false := iff_false_intro (not_succ_le_self n) theorem zero_le : ∀ (n : ℕ), 0 ≤ n | 0 := nat.le_refl 0 | (n+1) := le.step (zero_le n) attribute [simp] theorem zero_le_iff_true (n : ℕ) : 0 ≤ n ↔ true := iff_true_intro (zero_le n) protected theorem one_le_bit1 (n : ℕ) : 1 ≤ bit1 n := show 1 ≤ succ (bit0 n), from succ_le_succ (zero_le (bit0 n)) protected theorem one_le_bit0 : ∀ (n : ℕ), n ≠ 0 → 1 ≤ bit0 n | 0 h := absurd rfl h | (n+1) h := suffices 1 ≤ succ (succ (bit0 n)), from eq.symm (nat.bit0_succ_eq n) ▸ this, succ_le_succ (zero_le (succ (bit0 n))) definition lt.step {n m : ℕ} : n < m → n < succ m := le.step theorem zero_lt_succ (n : ℕ) : 0 < succ n := succ_le_succ (zero_le n) attribute [simp] theorem zero_lt_succ_iff_true (n : ℕ) : 0 < succ n ↔ true := iff_true_intro (zero_lt_succ n) protected theorem lt_trans {n m k : ℕ} (H1 : n < m) : m < k → n < k := nat.le_trans (le.step H1) protected theorem lt_of_le_of_lt {n m k : ℕ} (H1 : n ≤ m) : m < k → n < k := nat.le_trans (succ_le_succ H1) protected theorem lt_of_lt_of_le {n m k : ℕ} : n < m → m ≤ k → n < k := nat.le_trans protected theorem lt_irrefl (n : ℕ) : ¬n < n := not_succ_le_self n theorem lt_self_iff_false (n : ℕ) : n < n ↔ false := iff_false_intro (λ H, absurd H (nat.lt_irrefl n)) theorem self_lt_succ (n : ℕ) : n < succ n := nat.le_refl (succ n) attribute [simp] theorem self_lt_succ_iff_true (n : ℕ) : n < succ n ↔ true := iff_true_intro (self_lt_succ n) definition lt.base (n : ℕ) : n < succ n := nat.le_refl (succ n) theorem le_lt_antisymm {n m : ℕ} (H1 : n ≤ m) (H2 : m < n) : false := nat.lt_irrefl n (nat.lt_of_le_of_lt H1 H2) protected theorem le_antisymm {n m : ℕ} (H1 : n ≤ m) : m ≤ n → n = m := le.cases_on H1 (λa, rfl) (λa b c, absurd (nat.lt_of_le_of_lt b c) (nat.lt_irrefl n)) theorem lt_le_antisymm {n m : ℕ} (H1 : n < m) (H2 : m ≤ n) : false := le_lt_antisymm H2 H1 protected theorem nat.lt_asymm {n m : ℕ} (H1 : n < m) : ¬ m < n := le_lt_antisymm (nat.le_of_lt H1) theorem not_lt_zero (a : ℕ) : ¬ a < 0 := not_succ_le_zero a attribute [simp] theorem lt_zero_iff_false (a : ℕ) : a < 0 ↔ false := iff_false_intro (not_lt_zero a) protected theorem eq_or_lt_of_le {a b : ℕ} (H : a ≤ b) : a = b ∨ a < b := le.cases_on H (or.inl rfl) (λn h, or.inr (succ_le_succ h)) protected theorem le_of_eq_or_lt {a b : ℕ} (H : a = b ∨ a < b) : a ≤ b := or.elim H nat.le_of_eq nat.le_of_lt theorem succ_lt_succ {a b : ℕ} : a < b → succ a < succ b := succ_le_succ theorem lt_of_succ_lt {a b : ℕ} : succ a < b → a < b := le_of_succ_le theorem lt_of_succ_lt_succ {a b : ℕ} : succ a < succ b → a < b := le_of_succ_le_succ attribute [instance, priority nat.prio] protected definition decidable_le : ∀ a b : nat, decidable (a ≤ b) | 0 b := is_true (zero_le b) | (a+1) 0 := is_false (not_succ_le_zero a) | (a+1) (b+1) := match decidable_le a b with | is_true H := is_true (succ_le_succ H) | is_false H := is_false (λa, H (le_of_succ_le_succ a)) end attribute [instance, priority nat.prio] protected definition decidable_lt : ∀ a b : nat, decidable (a < b) := λ a b, nat.decidable_le (succ a) b protected theorem lt_or_ge : ∀ (a b : ℕ), a < b ∨ a ≥ b | a 0 := or.inr (zero_le a) | a (b+1) := match lt_or_ge a b with | or.inl h := or.inl (le_succ_of_le h) | or.inr h := match nat.eq_or_lt_of_le h with | or.inl h1 := or.inl (h1 ▸ self_lt_succ b) | or.inr h1 := or.inr h1 end end protected definition {u} lt_ge_by_cases {a b : ℕ} {P : Type u} (H1 : a < b → P) (H2 : a ≥ b → P) : P := decidable.by_cases H1 (λh, H2 (or.elim (nat.lt_or_ge a b) (λa, absurd a h) (λa, a))) protected definition {u} lt_by_cases {a b : ℕ} {P : Type u} (H1 : a < b → P) (H2 : a = b → P) (H3 : b < a → P) : P := nat.lt_ge_by_cases H1 (λh₁, nat.lt_ge_by_cases H3 (λh₂, H2 (nat.le_antisymm h₂ h₁))) protected theorem lt_trichotomy (a b : ℕ) : a < b ∨ a = b ∨ b < a := nat.lt_by_cases (λH, or.inl H) (λH, or.inr (or.inl H)) (λH, or.inr (or.inr H)) protected theorem eq_or_lt_of_not_lt {a b : ℕ} (hnlt : ¬ a < b) : a = b ∨ b < a := or.elim (nat.lt_trichotomy a b) (λ hlt, absurd hlt hnlt) (λ h, h) theorem lt_succ_of_le {a b : ℕ} : a ≤ b → a < succ b := succ_le_succ theorem lt_of_succ_le {a b : ℕ} (h : succ a ≤ b) : a < b := h theorem succ_le_of_lt {a b : ℕ} (h : a < b) : succ a ≤ b := h attribute [simp] theorem succ_sub_succ_eq_sub (a b : ℕ) : succ a - succ b = a - b := nat.rec_on b (show succ a - succ zero = a - zero, from (eq.refl (succ a - succ zero))) (λ b, congr_arg pred) theorem sub_eq_succ_sub_succ (a b : ℕ) : a - b = succ a - succ b := eq.symm (succ_sub_succ_eq_sub a b) attribute [simp] theorem zero_sub_eq_zero : ∀ a : ℕ, 0 - a = 0 | 0 := rfl | (a+1) := congr_arg pred (zero_sub_eq_zero a) theorem zero_eq_zero_sub (a : ℕ) : 0 = 0 - a := eq.symm (zero_sub_eq_zero a) theorem sub_le (a b : ℕ) : a - b ≤ a := nat.rec_on b (nat.le_refl (a - 0)) (λ b₁, nat.le_trans (pred_le (a - b₁))) attribute [simp] theorem sub_le_iff_true (a b : ℕ) : a - b ≤ a ↔ true := iff_true_intro (sub_le a b) theorem sub_lt : ∀ {a b : ℕ}, 0 < a → 0 < b → a - b < a | 0 b h1 h2 := absurd h1 (nat.lt_irrefl 0) | (a+1) 0 h1 h2 := absurd h2 (nat.lt_irrefl 0) | (a+1) (b+1) h1 h2 := eq.symm (succ_sub_succ_eq_sub a b) ▸ show a - b < succ a, from lt_succ_of_le (sub_le a b) theorem sub_lt_succ (a b : ℕ) : a - b < succ a := lt_succ_of_le (sub_le a b) attribute [simp] theorem sub_lt_succ_iff_true (a b : ℕ) : a - b < succ a ↔ true := iff_true_intro (sub_lt_succ a b) theorem le_add_right : ∀ (n k : ℕ), n ≤ n + k | n 0 := nat.le_refl n | n (k+1) := le_succ_of_le (le_add_right n k) theorem le_add_left (n m : ℕ): n ≤ m + n := nat.add_comm n m ▸ le_add_right n m definition {u} repeat {A : Type u} (f : nat → A → A) : nat → A → A | 0 a := a | (succ n) a := f n (repeat n a) attribute [instance] protected definition is_inhabited : inhabited nat := ⟨nat.zero⟩ end nat
87a42ef722bd562fd6f92d8507e09b631380d63a
e61a235b8468b03aee0120bf26ec615c045005d2
/stage0/src/Init/Lean/Meta/AppBuilder.lean
e1855a547534991cefb944ce08febd59a5a17267
[ "Apache-2.0" ]
permissive
SCKelemen/lean4
140dc63a80539f7c61c8e43e1c174d8500ec3230
e10507e6615ddbef73d67b0b6c7f1e4cecdd82bc
refs/heads/master
1,660,973,595,917
1,590,278,033,000
1,590,278,033,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
10,957
lean
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ prelude import Init.Lean.Util.Recognizers import Init.Lean.Meta.SynthInstance namespace Lean namespace Meta /-- Given `e` s.t. `inferType e` is definitionally equal to `expectedType`, return term `@id expectedType e`. -/ def mkExpectedTypeHint (e : Expr) (expectedType : Expr) : MetaM Expr := do u ← getLevel expectedType; pure $ mkApp2 (mkConst `id [u]) expectedType e def mkEq (a b : Expr) : MetaM Expr := do aType ← inferType a; u ← getLevel aType; pure $ mkApp3 (mkConst `Eq [u]) aType a b def mkHEq (a b : Expr) : MetaM Expr := do aType ← inferType a; bType ← inferType b; u ← getLevel aType; pure $ mkApp4 (mkConst `HEq [u]) aType a bType b def mkEqRefl (a : Expr) : MetaM Expr := do aType ← inferType a; u ← getLevel aType; pure $ mkApp2 (mkConst `Eq.refl [u]) aType a def mkHEqRefl (a : Expr) : MetaM Expr := do aType ← inferType a; u ← getLevel aType; pure $ mkApp2 (mkConst `HEq.refl [u]) aType a private def infer (h : Expr) : MetaM Expr := do hType ← inferType h; whnfD hType def mkEqSymm (h : Expr) : MetaM Expr := if h.isAppOf `Eq.refl then pure h else do hType ← infer h; match hType.eq? with | some (α, a, b) => do u ← getLevel α; pure $ mkApp4 (mkConst `Eq.symm [u]) α a b h | none => throwEx $ Exception.appBuilder `Eq.symm "equality proof expected" #[h] def mkEqTrans (h₁ h₂ : Expr) : MetaM Expr := if h₁.isAppOf `Eq.refl then pure h₂ else if h₂.isAppOf `Eq.refl then pure h₁ else do hType₁ ← infer h₁; hType₂ ← infer h₂; match hType₁.eq?, hType₂.eq? with | some (α, a, b), some (_, _, c) => do u ← getLevel α; pure $ mkApp6 (mkConst `Eq.trans [u]) α a b c h₁ h₂ | _, _ => throwEx $ Exception.appBuilder `Eq.trans "equality proof expected" #[h₁, h₂] def mkHEqSymm (h : Expr) : MetaM Expr := if h.isAppOf `HEq.refl then pure h else do hType ← infer h; match hType.heq? with | some (α, a, β, b) => do u ← getLevel α; pure $ mkApp5 (mkConst `HEq.symm [u]) α β a b h | none => throwEx $ Exception.appBuilder `HEq.symm "heterogeneous equality proof expected" #[h] def mkHEqTrans (h₁ h₂ : Expr) : MetaM Expr := if h₁.isAppOf `HEq.refl then pure h₂ else if h₂.isAppOf `HEq.refl then pure h₁ else do hType₁ ← infer h₁; hType₂ ← infer h₂; match hType₁.heq?, hType₂.heq? with | some (α, a, β, b), some (_, _, γ, c) => do u ← getLevel α; pure $ mkApp8 (mkConst `HEq.trans [u]) α β γ a b c h₁ h₂ | _, _ => throwEx $ Exception.appBuilder `HEq.trans "heterogeneous equality proof expected" #[h₁, h₂] def mkEqOfHEq (h : Expr) : MetaM Expr := do hType ← infer h; match hType.heq? with | some (α, a, β, b) => do unlessM (isDefEq α β) $ throwEx $ Exception.appBuilder `eqOfHEq "heterogeneous equality types are not definitionally equal" #[α, β]; u ← getLevel α; pure $ mkApp4 (mkConst `eqOfHEq [u]) α a b h | _ => throwEx $ Exception.appBuilder `HEq.trans "heterogeneous equality proof expected" #[h] def mkCongrArg (f h : Expr) : MetaM Expr := do hType ← infer h; fType ← infer f; match fType.arrow?, hType.eq? with | some (α, β), some (_, a, b) => do u ← getLevel α; v ← getLevel β; pure $ mkApp6 (mkConst `congrArg [u, v]) α β a b f h | none, _ => throwEx $ Exception.appBuilder `congrArg "non-dependent function expected" #[f, h] | _, none => throwEx $ Exception.appBuilder `congrArg "equality proof expected" #[f, h] def mkCongrFun (h a : Expr) : MetaM Expr := do hType ← infer h; match hType.eq? with | some (ρ, f, g) => do ρ ← whnfD ρ; match ρ with | Expr.forallE n α β _ => do let β' := Lean.mkLambda n BinderInfo.default α β; u ← getLevel α; v ← getLevel (mkApp β' a); pure $ mkApp6 (mkConst `congrFun [u, v]) α β' f g h a | _ => throwEx $ Exception.appBuilder `congrFun "equality proof between functions expected" #[h, a] | _ => throwEx $ Exception.appBuilder `congrFun "equality proof expected" #[h, a] def mkCongr (h₁ h₂ : Expr) : MetaM Expr := do hType₁ ← infer h₁; hType₂ ← infer h₂; match hType₁.eq?, hType₂.eq? with | some (ρ, f, g), some (α, a, b) => do ρ ← whnfD ρ; match ρ.arrow? with | some (_, β) => do u ← getLevel α; v ← getLevel β; pure $ mkApp8 (mkConst `congr [u, v]) α β f g a b h₁ h₂ | _ => throwEx $ Exception.appBuilder `congr "non-dependent function expected" #[h₁, h₂] | _, _ => throwEx $ Exception.appBuilder `congr "equality proof expected" #[h₁, h₂] private def mkAppMFinal (methodName : Name) (f : Expr) (args : Array Expr) (instMVars : Array MVarId) : MetaM Expr := do instMVars.forM $ fun mvarId => do { mvarDecl ← getMVarDecl mvarId; mvarVal ← synthInstance mvarDecl.type; assignExprMVar mvarId mvarVal }; result ← instantiateMVars (mkAppN f args); whenM (hasAssignableMVar result) $ throwEx $ Exception.appBuilder methodName "result contains metavariables" #[result]; pure result private partial def mkAppMAux (f : Expr) (xs : Array Expr) : Nat → Array Expr → Nat → Array MVarId → Expr → MetaM Expr | i, args, j, instMVars, Expr.forallE n d b c => do let d := d.instantiateRevRange j args.size args; match c.binderInfo with | BinderInfo.implicit => do mvar ← mkFreshExprMVar d n; mkAppMAux i (args.push mvar) j instMVars b | BinderInfo.instImplicit => do mvar ← mkFreshExprMVar d n MetavarKind.synthetic; mkAppMAux i (args.push mvar) j (instMVars.push mvar.mvarId!) b | _ => if h : i < xs.size then do let x := xs.get ⟨i, h⟩; xType ← inferType x; condM (isDefEq d xType) (mkAppMAux (i+1) (args.push x) j instMVars b) (throwEx $ Exception.appTypeMismatch (mkAppN f args) x) else mkAppMFinal `mkAppM f args instMVars | i, args, j, instMVars, type => do let type := type.instantiateRevRange j args.size args; type ← whnfD type; if type.isForall then mkAppMAux i args args.size instMVars type else if i == xs.size then mkAppMFinal `mkAppM f args instMVars else throwEx $ Exception.appBuilder `mkAppM "too many explicit arguments provided" (#[f] ++ xs) private def mkFun (constName : Name) : MetaM (Expr × Expr) := do cinfo ← getConstInfo constName; us ← cinfo.lparams.mapM $ fun _ => mkFreshLevelMVar; let f := mkConst constName us; let fType := cinfo.instantiateTypeLevelParams us; pure (f, fType) def mkAppM (constName : Name) (xs : Array Expr) : MetaM Expr := traceCtx `Meta.appBuilder $ withNewMCtxDepth $ do (f, fType) ← mkFun constName; mkAppMAux f xs 0 #[] 0 #[] fType private partial def mkAppOptMAux (f : Expr) (xs : Array (Option Expr)) : Nat → Array Expr → Nat → Array MVarId → Expr → MetaM Expr | i, args, j, instMVars, Expr.forallE n d b c => do let d := d.instantiateRevRange j args.size args; if h : i < xs.size then do match xs.get ⟨i, h⟩ with | none => match c.binderInfo with | BinderInfo.instImplicit => do mvar ← mkFreshExprMVar d n MetavarKind.synthetic; mkAppOptMAux (i+1) (args.push mvar) j (instMVars.push mvar.mvarId!) b | _ => do mvar ← mkFreshExprMVar d n; mkAppOptMAux (i+1) (args.push mvar) j instMVars b | some x => do xType ← inferType x; condM (isDefEq d xType) (mkAppOptMAux (i+1) (args.push x) j instMVars b) (throwEx $ Exception.appTypeMismatch (mkAppN f args) x) else mkAppMFinal `mkAppOptM f args instMVars | i, args, j, instMVars, type => do let type := type.instantiateRevRange j args.size args; type ← whnfD type; if type.isForall then mkAppOptMAux i args args.size instMVars type else if i == xs.size then mkAppMFinal `mkAppOptM f args instMVars else do let xs : Array Expr := xs.foldl (fun r x? => match x? with | none => r | some x => r.push x) #[]; throwEx $ Exception.appBuilder `mkAppOptM "too many arguments provided" (#[f] ++ xs) /-- Similar to `mkAppM`, but it allows us to specify which arguments are provided explicitly using `Option` type. Example: Given `HasPure.pure {m : Type u → Type v} [HasPure m] {α : Type u} (a : α) : m α`, ``` mkAppOptM `HasPure.pure #[m, none, none, a] ``` returns a `HasPure.pure` application if the instance `HasPure m` can be synthesized, and the universes match. Note that, ``` mkAppM `HasPure.pure #[a] ``` fails because the only explicit argument `(a : α)` is not sufficient for inferring the remaining arguments, we would need the expected type. -/ def mkAppOptM (constName : Name) (xs : Array (Option Expr)) : MetaM Expr := traceCtx `Meta.appBuilder $ withNewMCtxDepth $ do (f, fType) ← mkFun constName; mkAppOptMAux f xs 0 #[] 0 #[] fType def mkEqNDRec (motive h1 h2 : Expr) : MetaM Expr := if h2.isAppOf `Eq.refl then pure h1 else do h2Type ← infer h2; match h2Type.eq? with | none => throwEx $ Exception.appBuilder `Eq.ndrec "equality proof expected" #[h2] | some (α, a, b) => do u2 ← getLevel α; motiveType ← infer motive; match motiveType with | Expr.forallE _ _ (Expr.sort u1 _) _ => pure $ mkAppN (mkConst `Eq.ndrec [u1, u2]) #[α, a, motive, h1, b, h2] | _ => throwEx $ Exception.appBuilder `Eq.ndrec "invalid motive" #[motive] def mkEqRec (motive h1 h2 : Expr) : MetaM Expr := if h2.isAppOf `Eq.refl then pure h1 else do h2Type ← infer h2; match h2Type.eq? with | none => throwEx $ Exception.appBuilder `Eq.rec "equality proof expected" #[h2] | some (α, a, b) => do u2 ← getLevel α; motiveType ← infer motive; match motiveType with | Expr.forallE _ _ (Expr.forallE _ _ (Expr.sort u1 _) _) _ => pure $ mkAppN (mkConst `Eq.rec [u1, u2]) #[α, a, motive, h1, b, h2] | _ => throwEx $ Exception.appBuilder `Eq.rec "invalid motive" #[motive] def mkEqMP (eqProof pr : Expr) : MetaM Expr := mkAppM `Eq.mp #[eqProof, pr] def mkEqMPR (eqProof pr : Expr) : MetaM Expr := mkAppM `Eq.mpr #[eqProof, pr] def mkNoConfusion (target : Expr) (h : Expr) : MetaM Expr := do type ← inferType h; type ← whnf type; match type.eq? with | none => throwEx $ Exception.appBuilder `noConfusion "equality expected" #[h] | some (α, a, b) => do α ← whnf α; env ← getEnv; let f := α.getAppFn; matchConst env f (fun _ => throwEx $ Exception.appBuilder `noConfusion "inductive type expected" #[α]) $ fun cinfo us => match cinfo with | ConstantInfo.inductInfo v => do u ← getLevel target; pure $ mkAppN (mkConst (mkNameStr v.name "noConfusion") (u :: us)) (α.getAppArgs ++ #[target, a, b, h]) | _ => throwEx $ Exception.appBuilder `noConfusion "inductive type expected" #[α] def mkPure (m : Expr) (e : Expr) : MetaM Expr := do mkAppOptM `HasPure.pure #[m, none, none, e] end Meta end Lean
92a9d50862581574a0971950e0613ad7e3b3b030
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/ring_theory/ideal/operations_auto.lean
13c83e56069fddf1518efab2feb32474234ce109
[]
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
46,114
lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.nat.choose.sum import Mathlib.data.equiv.ring import Mathlib.algebra.algebra.operations import Mathlib.ring_theory.ideal.basic import Mathlib.algebra.algebra.tower import Mathlib.PostPort universes u v w x u_1 u_2 u_3 u_4 namespace Mathlib /-! # More operations on modules and ideals -/ namespace submodule protected instance has_scalar' {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] : has_scalar (ideal R) (submodule R M) := has_scalar.mk fun (I : ideal R) (N : submodule R M) => supr fun (r : ↥I) => map (subtype.val r • linear_map.id) N /-- `N.annihilator` is the ideal of all elements `r : R` such that `r • N = 0`. -/ def annihilator {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] (N : submodule R M) : ideal R := linear_map.ker (linear_map.lsmul R ↥N) /-- `N.colon P` is the ideal of all elements `r : R` such that `r • P ⊆ N`. -/ def colon {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] (N : submodule R M) (P : submodule R M) : ideal R := annihilator (map (mkq N) P) theorem mem_annihilator {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] {N : submodule R M} {r : R} : r ∈ annihilator N ↔ ∀ (n : M), n ∈ N → r • n = 0 := sorry theorem mem_annihilator' {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] {N : submodule R M} {r : R} : r ∈ annihilator N ↔ N ≤ comap (r • linear_map.id) ⊥ := iff.trans mem_annihilator { mp := fun (H : ∀ (n : M), n ∈ N → r • n = 0) (n : M) (hn : n ∈ N) => iff.mpr (mem_bot R) (H n hn), mpr := fun (H : N ≤ comap (r • linear_map.id) ⊥) (n : M) (hn : n ∈ N) => iff.mp (mem_bot R) (H hn) } theorem annihilator_bot {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] : annihilator ⊥ = ⊤ := iff.mpr (ideal.eq_top_iff_one (annihilator ⊥)) (iff.mpr mem_annihilator' bot_le) theorem annihilator_eq_top_iff {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] {N : submodule R M} : annihilator N = ⊤ ↔ N = ⊥ := sorry theorem annihilator_mono {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] {N : submodule R M} {P : submodule R M} (h : N ≤ P) : annihilator P ≤ annihilator N := fun (r : R) (hrp : r ∈ annihilator P) => iff.mpr mem_annihilator fun (n : M) (hn : n ∈ N) => iff.mp mem_annihilator hrp n (h hn) theorem annihilator_supr {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] (ι : Sort w) (f : ι → submodule R M) : annihilator (supr fun (i : ι) => f i) = infi fun (i : ι) => annihilator (f i) := sorry theorem mem_colon {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] {N : submodule R M} {P : submodule R M} {r : R} : r ∈ colon N P ↔ ∀ (p : M), p ∈ P → r • p ∈ N := sorry theorem mem_colon' {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] {N : submodule R M} {P : submodule R M} {r : R} : r ∈ colon N P ↔ P ≤ comap (r • linear_map.id) N := mem_colon theorem colon_mono {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] {N₁ : submodule R M} {N₂ : submodule R M} {P₁ : submodule R M} {P₂ : submodule R M} (hn : N₁ ≤ N₂) (hp : P₁ ≤ P₂) : colon N₁ P₂ ≤ colon N₂ P₁ := fun (r : R) (hrnp : r ∈ colon N₁ P₂) => iff.mpr mem_colon fun (p₁ : M) (hp₁ : p₁ ∈ P₁) => hn (iff.mp mem_colon hrnp p₁ (hp hp₁)) theorem infi_colon_supr {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] (ι₁ : Sort w) (f : ι₁ → submodule R M) (ι₂ : Sort x) (g : ι₂ → submodule R M) : colon (infi fun (i : ι₁) => f i) (supr fun (j : ι₂) => g j) = infi fun (i : ι₁) => infi fun (j : ι₂) => colon (f i) (g j) := sorry theorem smul_mem_smul {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] {I : ideal R} {N : submodule R M} {r : R} {n : M} (hr : r ∈ I) (hn : n ∈ N) : r • n ∈ I • N := le_supr (fun (r : ↥I) => map (subtype.val r • linear_map.id) N) { val := r, property := hr } (r • n) (Exists.intro n { left := hn, right := rfl }) theorem smul_le {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] {I : ideal R} {N : submodule R M} {P : submodule R M} : I • N ≤ P ↔ ∀ (r : R), r ∈ I → ∀ (n : M), n ∈ N → r • n ∈ P := sorry theorem smul_induction_on {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] {I : ideal R} {N : submodule R M} {p : M → Prop} {x : M} (H : x ∈ I • N) (Hb : ∀ (r : R), r ∈ I → ∀ (n : M), n ∈ N → p (r • n)) (H0 : p 0) (H1 : ∀ (x y : M), p x → p y → p (x + y)) (H2 : ∀ (c : R) (n : M), p n → p (c • n)) : p x := iff.mpr smul_le Hb x H theorem mem_smul_span_singleton {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] {I : ideal R} {m : M} {x : M} : x ∈ I • span R (singleton m) ↔ ∃ (y : R), ∃ (H : y ∈ I), y • m = x := sorry theorem smul_le_right {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] {I : ideal R} {N : submodule R M} : I • N ≤ N := iff.mpr smul_le fun (r : R) (hr : r ∈ I) (n : M) => smul_mem N r theorem smul_mono {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] {I : ideal R} {J : ideal R} {N : submodule R M} {P : submodule R M} (hij : I ≤ J) (hnp : N ≤ P) : I • N ≤ J • P := iff.mpr smul_le fun (r : R) (hr : r ∈ I) (n : M) (hn : n ∈ N) => smul_mem_smul (hij hr) (hnp hn) theorem smul_mono_left {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] {I : ideal R} {J : ideal R} {N : submodule R M} (h : I ≤ J) : I • N ≤ J • N := smul_mono h (le_refl N) theorem smul_mono_right {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] {I : ideal R} {N : submodule R M} {P : submodule R M} (h : N ≤ P) : I • N ≤ I • P := smul_mono (le_refl I) h @[simp] theorem smul_bot {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] (I : ideal R) : I • ⊥ = ⊥ := sorry @[simp] theorem bot_smul {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] (N : submodule R M) : ⊥ • N = ⊥ := sorry @[simp] theorem top_smul {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] (N : submodule R M) : ⊤ • N = N := le_antisymm smul_le_right fun (r : M) (hri : r ∈ N) => one_smul R r ▸ smul_mem_smul mem_top hri theorem smul_sup {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] (I : ideal R) (N : submodule R M) (P : submodule R M) : I • (N ⊔ P) = I • N ⊔ I • P := sorry theorem sup_smul {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] (I : ideal R) (J : ideal R) (N : submodule R M) : (I ⊔ J) • N = I • N ⊔ J • N := sorry protected theorem smul_assoc {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] (I : ideal R) (J : ideal R) (N : submodule R M) : (I • J) • N = I • J • N := sorry theorem span_smul_span {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] (S : set R) (T : set M) : ideal.span S • span R T = span R (set.Union fun (s : R) => set.Union fun (H : s ∈ S) => set.Union fun (t : M) => set.Union fun (H : t ∈ T) => singleton (s • t)) := sorry theorem map_smul'' {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] (I : ideal R) (N : submodule R M) {M' : Type w} [add_comm_group M'] [module R M'] (f : linear_map R M M') : map f (I • N) = I • map f N := sorry end submodule namespace ideal theorem exists_sub_one_mem_and_mem {R : Type u} [comm_ring R] {ι : Type v} (s : finset ι) {f : ι → ideal R} (hf : ∀ (i : ι), i ∈ s → ∀ (j : ι), j ∈ s → i ≠ j → f i ⊔ f j = ⊤) (i : ι) (his : i ∈ s) : ∃ (r : R), r - 1 ∈ f i ∧ ∀ (j : ι), j ∈ s → j ≠ i → r ∈ f j := sorry theorem exists_sub_mem {R : Type u} [comm_ring R] {ι : Type v} [fintype ι] {f : ι → ideal R} (hf : ∀ (i j : ι), i ≠ j → f i ⊔ f j = ⊤) (g : ι → R) : ∃ (r : R), ∀ (i : ι), r - g i ∈ f i := sorry /-- The homomorphism from `R/(⋂ i, f i)` to `∏ i, (R / f i)` featured in the Chinese Remainder Theorem. It is bijective if the ideals `f i` are comaximal. -/ def quotient_inf_to_pi_quotient {R : Type u} [comm_ring R] {ι : Type v} (f : ι → ideal R) : quotient (infi fun (i : ι) => f i) →+* (i : ι) → quotient (f i) := quotient.lift (infi fun (i : ι) => f i) (eq.mpr sorry (pi.ring_hom fun (i : ι) => quotient.mk (f i))) sorry theorem quotient_inf_to_pi_quotient_bijective {R : Type u} [comm_ring R] {ι : Type v} [fintype ι] {f : ι → ideal R} (hf : ∀ (i j : ι), i ≠ j → f i ⊔ f j = ⊤) : function.bijective ⇑(quotient_inf_to_pi_quotient f) := sorry /-- Chinese Remainder Theorem. Eisenbud Ex.2.6. Similar to Atiyah-Macdonald 1.10 and Stacks 00DT -/ def quotient_inf_ring_equiv_pi_quotient {R : Type u} [comm_ring R] {ι : Type v} [fintype ι] (f : ι → ideal R) (hf : ∀ (i j : ι), i ≠ j → f i ⊔ f j = ⊤) : quotient (infi fun (i : ι) => f i) ≃+* ((i : ι) → quotient (f i)) := ring_equiv.mk (equiv.to_fun (equiv.of_bijective ⇑(quotient_inf_to_pi_quotient fun (i : ι) => f i) sorry)) (equiv.inv_fun (equiv.of_bijective ⇑(quotient_inf_to_pi_quotient fun (i : ι) => f i) sorry)) sorry sorry sorry sorry protected instance has_mul {R : Type u} [comm_ring R] : Mul (ideal R) := { mul := has_scalar.smul } theorem mul_mem_mul {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} {r : R} {s : R} (hr : r ∈ I) (hs : s ∈ J) : r * s ∈ I * J := submodule.smul_mem_smul hr hs theorem mul_mem_mul_rev {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} {r : R} {s : R} (hr : r ∈ I) (hs : s ∈ J) : s * r ∈ I * J := mul_comm r s ▸ mul_mem_mul hr hs theorem mul_le {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} {K : ideal R} : I * J ≤ K ↔ ∀ (r : R), r ∈ I → ∀ (s : R), s ∈ J → r * s ∈ K := submodule.smul_le theorem mul_le_left {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} : I * J ≤ J := iff.mpr mul_le fun (r : R) (hr : r ∈ I) (s : R) => mul_mem_left J r theorem mul_le_right {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} : I * J ≤ I := iff.mpr mul_le fun (r : R) (hr : r ∈ I) (s : R) (hs : s ∈ J) => mul_mem_right I s hr @[simp] theorem sup_mul_right_self {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} : I ⊔ I * J = I := iff.mpr sup_eq_left mul_le_right @[simp] theorem sup_mul_left_self {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} : I ⊔ J * I = I := iff.mpr sup_eq_left mul_le_left @[simp] theorem mul_right_self_sup {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} : I * J ⊔ I = I := iff.mpr sup_eq_right mul_le_right @[simp] theorem mul_left_self_sup {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} : J * I ⊔ I = I := iff.mpr sup_eq_right mul_le_left protected theorem mul_comm {R : Type u} [comm_ring R] (I : ideal R) (J : ideal R) : I * J = J * I := le_antisymm (iff.mpr mul_le fun (r : R) (hrI : r ∈ I) (s : R) (hsJ : s ∈ J) => mul_mem_mul_rev hsJ hrI) (iff.mpr mul_le fun (r : R) (hrJ : r ∈ J) (s : R) (hsI : s ∈ I) => mul_mem_mul_rev hsI hrJ) protected theorem mul_assoc {R : Type u} [comm_ring R] (I : ideal R) (J : ideal R) (K : ideal R) : I * J * K = I * (J * K) := submodule.smul_assoc I J K theorem span_mul_span {R : Type u} [comm_ring R] (S : set R) (T : set R) : span S * span T = span (set.Union fun (s : R) => set.Union fun (H : s ∈ S) => set.Union fun (t : R) => set.Union fun (H : t ∈ T) => singleton (s * t)) := submodule.span_smul_span S T theorem span_mul_span' {R : Type u} [comm_ring R] (S : set R) (T : set R) : span S * span T = span (S * T) := sorry theorem span_singleton_mul_span_singleton {R : Type u} [comm_ring R] (r : R) (s : R) : span (singleton r) * span (singleton s) = span (singleton (r * s)) := sorry theorem mul_le_inf {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} : I * J ≤ I ⊓ J := iff.mpr mul_le fun (r : R) (hri : r ∈ I) (s : R) (hsj : s ∈ J) => { left := mul_mem_right I s hri, right := mul_mem_left J r hsj } theorem prod_le_inf {R : Type u} {ι : Type u_1} [comm_ring R] {s : finset ι} {f : ι → ideal R} : finset.prod s f ≤ finset.inf s f := sorry theorem mul_eq_inf_of_coprime {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} (h : I ⊔ J = ⊤) : I * J = I ⊓ J := sorry theorem mul_bot {R : Type u} [comm_ring R] (I : ideal R) : I * ⊥ = ⊥ := submodule.smul_bot I theorem bot_mul {R : Type u} [comm_ring R] (I : ideal R) : ⊥ * I = ⊥ := submodule.bot_smul I theorem mul_top {R : Type u} [comm_ring R] (I : ideal R) : I * ⊤ = I := ideal.mul_comm ⊤ I ▸ submodule.top_smul I theorem top_mul {R : Type u} [comm_ring R] (I : ideal R) : ⊤ * I = I := submodule.top_smul I theorem mul_mono {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} {K : ideal R} {L : ideal R} (hik : I ≤ K) (hjl : J ≤ L) : I * J ≤ K * L := submodule.smul_mono hik hjl theorem mul_mono_left {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} {K : ideal R} (h : I ≤ J) : I * K ≤ J * K := submodule.smul_mono_left h theorem mul_mono_right {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} {K : ideal R} (h : J ≤ K) : I * J ≤ I * K := submodule.smul_mono_right h theorem mul_sup {R : Type u} [comm_ring R] (I : ideal R) (J : ideal R) (K : ideal R) : I * (J ⊔ K) = I * J ⊔ I * K := submodule.smul_sup I J K theorem sup_mul {R : Type u} [comm_ring R] (I : ideal R) (J : ideal R) (K : ideal R) : (I ⊔ J) * K = I * K ⊔ J * K := submodule.sup_smul I J K theorem pow_le_pow {R : Type u} [comm_ring R] {I : ideal R} {m : ℕ} {n : ℕ} (h : m ≤ n) : I ^ n ≤ I ^ m := sorry theorem mul_eq_bot {R : Type u_1} [integral_domain R] {I : ideal R} {J : ideal R} : I * J = ⊥ ↔ I = ⊥ ∨ J = ⊥ := sorry /-- The radical of an ideal `I` consists of the elements `r` such that `r^n ∈ I` for some `n`. -/ def radical {R : Type u} [comm_ring R] (I : ideal R) : ideal R := submodule.mk (set_of fun (r : R) => ∃ (n : ℕ), r ^ n ∈ I) sorry sorry sorry theorem le_radical {R : Type u} [comm_ring R] {I : ideal R} : I ≤ radical I := fun (r : R) (hri : r ∈ I) => Exists.intro 1 (Eq.symm (pow_one r) ▸ hri) theorem radical_top (R : Type u) [comm_ring R] : radical ⊤ = ⊤ := iff.mpr (eq_top_iff_one (radical ⊤)) (Exists.intro 0 submodule.mem_top) theorem radical_mono {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} (H : I ≤ J) : radical I ≤ radical J := sorry @[simp] theorem radical_idem {R : Type u} [comm_ring R] (I : ideal R) : radical (radical I) = radical I := sorry theorem radical_eq_top {R : Type u} [comm_ring R] {I : ideal R} : radical I = ⊤ ↔ I = ⊤ := sorry theorem is_prime.radical {R : Type u} [comm_ring R] {I : ideal R} (H : is_prime I) : radical I = I := sorry theorem radical_sup {R : Type u} [comm_ring R] (I : ideal R) (J : ideal R) : radical (I ⊔ J) = radical (radical I ⊔ radical J) := sorry theorem radical_inf {R : Type u} [comm_ring R] (I : ideal R) (J : ideal R) : radical (I ⊓ J) = radical I ⊓ radical J := sorry theorem radical_mul {R : Type u} [comm_ring R] (I : ideal R) (J : ideal R) : radical (I * J) = radical I ⊓ radical J := sorry theorem is_prime.radical_le_iff {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} (hj : is_prime J) : radical I ≤ J ↔ I ≤ J := sorry theorem radical_eq_Inf {R : Type u} [comm_ring R] (I : ideal R) : radical I = Inf (set_of fun (J : ideal R) => I ≤ J ∧ is_prime J) := sorry @[simp] theorem radical_bot_of_integral_domain {R : Type u} [integral_domain R] : radical ⊥ = ⊥ := iff.mpr eq_bot_iff fun (x : R) (hx : x ∈ radical ⊥) => Exists.rec_on hx fun (n : ℕ) (hn : x ^ n ∈ ⊥) => pow_eq_zero hn protected instance comm_semiring {R : Type u} [comm_ring R] : comm_semiring (ideal R) := submodule.comm_semiring @[simp] theorem add_eq_sup {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} : I + J = I ⊔ J := rfl @[simp] theorem zero_eq_bot {R : Type u} [comm_ring R] : 0 = ⊥ := rfl @[simp] theorem one_eq_top {R : Type u} [comm_ring R] : 1 = ⊤ := sorry theorem top_pow (R : Type u) [comm_ring R] (n : ℕ) : ⊤ ^ n = ⊤ := sorry theorem radical_pow {R : Type u} [comm_ring R] (I : ideal R) (n : ℕ) (H : n > 0) : radical (I ^ n) = radical I := sorry theorem is_prime.mul_le {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} {P : ideal R} (hp : is_prime P) : I * J ≤ P ↔ I ≤ P ∨ J ≤ P := sorry theorem is_prime.inf_le {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} {P : ideal R} (hp : is_prime P) : I ⊓ J ≤ P ↔ I ≤ P ∨ J ≤ P := { mp := fun (h : I ⊓ J ≤ P) => iff.mp (is_prime.mul_le hp) (le_trans mul_le_inf h), mpr := fun (h : I ≤ P ∨ J ≤ P) => or.cases_on h (le_trans inf_le_left) (le_trans inf_le_right) } theorem is_prime.prod_le {R : Type u} {ι : Type u_1} [comm_ring R] {s : finset ι} {f : ι → ideal R} {P : ideal R} (hp : is_prime P) (hne : finset.nonempty s) : finset.prod s f ≤ P ↔ ∃ (i : ι), ∃ (H : i ∈ s), f i ≤ P := sorry theorem is_prime.inf_le' {R : Type u} {ι : Type u_1} [comm_ring R] {s : finset ι} {f : ι → ideal R} {P : ideal R} (hp : is_prime P) (hsne : finset.nonempty s) : finset.inf s f ≤ P ↔ ∃ (i : ι), ∃ (H : i ∈ s), f i ≤ P := sorry theorem subset_union {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} {K : ideal R} : ↑I ⊆ ↑J ∪ ↑K ↔ I ≤ J ∨ I ≤ K := sorry theorem subset_union_prime' {R : Type u} {ι : Type u_1} [comm_ring R] {s : finset ι} {f : ι → ideal R} {a : ι} {b : ι} (hp : ∀ (i : ι), i ∈ s → is_prime (f i)) {I : ideal R} : (↑I ⊆ ↑(f a) ∪ ↑(f b) ∪ set.Union fun (i : ι) => set.Union fun (H : i ∈ ↑s) => ↑(f i)) ↔ I ≤ f a ∨ I ≤ f b ∨ ∃ (i : ι), ∃ (H : i ∈ s), I ≤ f i := sorry /-- Prime avoidance. Atiyah-Macdonald 1.11, Eisenbud 3.3, Stacks 00DS, Matsumura Ex.1.6. -/ theorem subset_union_prime {R : Type u} {ι : Type u_1} [comm_ring R] {s : finset ι} {f : ι → ideal R} (a : ι) (b : ι) (hp : ∀ (i : ι), i ∈ s → i ≠ a → i ≠ b → is_prime (f i)) {I : ideal R} : (↑I ⊆ set.Union fun (i : ι) => set.Union fun (H : i ∈ ↑s) => ↑(f i)) ↔ ∃ (i : ι), ∃ (H : i ∈ s), I ≤ f i := sorry /-- `I.map f` is the span of the image of the ideal `I` under `f`, which may be bigger than the image itself. -/ def map {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (I : ideal R) : ideal S := span (⇑f '' ↑I) /-- `I.comap f` is the preimage of `I` under `f`. -/ def comap {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (I : ideal S) : ideal R := submodule.mk (⇑f ⁻¹' ↑I) sorry sorry sorry theorem map_mono {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] {f : R →+* S} {I : ideal R} {J : ideal R} (h : I ≤ J) : map f I ≤ map f J := span_mono (set.image_subset (⇑f) h) theorem mem_map_of_mem {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] {f : R →+* S} {I : ideal R} {x : R} (h : x ∈ I) : coe_fn f x ∈ map f I := subset_span (Exists.intro x { left := h, right := rfl }) theorem map_le_iff_le_comap {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] {f : R →+* S} {I : ideal R} {K : ideal S} : map f I ≤ K ↔ I ≤ comap f K := iff.trans span_le set.image_subset_iff @[simp] theorem mem_comap {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] {f : R →+* S} {K : ideal S} {x : R} : x ∈ comap f K ↔ coe_fn f x ∈ K := iff.rfl theorem comap_mono {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] {f : R →+* S} {K : ideal S} {L : ideal S} (h : K ≤ L) : comap f K ≤ comap f L := set.preimage_mono fun (x : R) (hx : x ∈ ↑(comap f K)) => h hx theorem comap_ne_top {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) {K : ideal S} (hK : K ≠ ⊤) : comap f K ≠ ⊤ := iff.mpr (ne_top_iff_one (comap f K)) (eq.mpr (id (Eq._oldrec (Eq.refl (¬1 ∈ comap f K)) (propext mem_comap))) (eq.mpr (id (Eq._oldrec (Eq.refl (¬coe_fn f 1 ∈ K)) (ring_hom.map_one f))) (iff.mp (ne_top_iff_one K) hK))) theorem is_prime.comap {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) {K : ideal S} [hK : is_prime K] : is_prime (comap f K) := sorry theorem map_top {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) : map f ⊤ = ⊤ := iff.mpr (eq_top_iff_one (map f ⊤)) (subset_span (Exists.intro 1 { left := trivial, right := ring_hom.map_one f })) theorem map_mul {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (I : ideal R) (J : ideal R) : map f (I * J) = map f I * map f J := sorry theorem gc_map_comap {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) : galois_connection (map f) (comap f) := fun (I : ideal R) (J : ideal S) => map_le_iff_le_comap @[simp] theorem comap_id {R : Type u} [comm_ring R] (I : ideal R) : comap (ring_hom.id R) I = I := ext fun (_x : R) => iff.rfl @[simp] theorem map_id {R : Type u} [comm_ring R] (I : ideal R) : map (ring_hom.id R) I = I := galois_connection.l_unique (gc_map_comap (ring_hom.id R)) galois_connection.id comap_id theorem comap_comap {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] {T : Type u_1} [comm_ring T] {I : ideal T} (f : R →+* S) (g : S →+* T) : comap f (comap g I) = comap (ring_hom.comp g f) I := rfl theorem map_map {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] {T : Type u_1} [comm_ring T] {I : ideal R} (f : R →+* S) (g : S →+* T) : map g (map f I) = map (ring_hom.comp g f) I := galois_connection.l_unique (galois_connection.compose (map f) (comap f) (map g) (comap g) (gc_map_comap f) (gc_map_comap g)) (gc_map_comap (ring_hom.comp g f)) fun (_x : ideal T) => comap_comap f g theorem map_le_of_le_comap {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] {f : R →+* S} {I : ideal R} {K : ideal S} : I ≤ comap f K → map f I ≤ K := galois_connection.l_le (gc_map_comap f) theorem le_comap_of_map_le {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] {f : R →+* S} {I : ideal R} {K : ideal S} : map f I ≤ K → I ≤ comap f K := galois_connection.le_u (gc_map_comap f) theorem le_comap_map {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] {f : R →+* S} {I : ideal R} : I ≤ comap f (map f I) := galois_connection.le_u_l (gc_map_comap f) I theorem map_comap_le {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] {f : R →+* S} {K : ideal S} : map f (comap f K) ≤ K := galois_connection.l_u_le (gc_map_comap f) K @[simp] theorem comap_top {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] {f : R →+* S} : comap f ⊤ = ⊤ := galois_connection.u_top (gc_map_comap f) @[simp] theorem comap_eq_top_iff {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] {f : R →+* S} {I : ideal S} : comap f I = ⊤ ↔ I = ⊤ := sorry @[simp] theorem map_bot {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] {f : R →+* S} : map f ⊥ = ⊥ := galois_connection.l_bot (gc_map_comap f) @[simp] theorem map_comap_map {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (I : ideal R) : map f (comap f (map f I)) = map f I := congr_fun (galois_connection.l_u_l_eq_l (gc_map_comap f)) I @[simp] theorem comap_map_comap {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (K : ideal S) : comap f (map f (comap f K)) = comap f K := congr_fun (galois_connection.u_l_u_eq_u (gc_map_comap f)) K theorem map_sup {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (I : ideal R) (J : ideal R) : map f (I ⊔ J) = map f I ⊔ map f J := galois_connection.l_sup (gc_map_comap f) theorem comap_inf {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (K : ideal S) (L : ideal S) : comap f (K ⊓ L) = comap f K ⊓ comap f L := rfl theorem map_supr {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) {ι : Sort u_1} (K : ι → ideal R) : map f (supr K) = supr fun (i : ι) => map f (K i) := galois_connection.l_supr (gc_map_comap f) theorem comap_infi {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) {ι : Sort u_1} (K : ι → ideal S) : comap f (infi K) = infi fun (i : ι) => comap f (K i) := galois_connection.u_infi (gc_map_comap f) theorem map_Sup {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (s : set (ideal R)) : map f (Sup s) = supr fun (I : ideal R) => supr fun (H : I ∈ s) => map f I := galois_connection.l_Sup (gc_map_comap f) theorem comap_Inf {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (s : set (ideal S)) : comap f (Inf s) = infi fun (I : ideal S) => infi fun (H : I ∈ s) => comap f I := galois_connection.u_Inf (gc_map_comap f) theorem comap_Inf' {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (s : set (ideal S)) : comap f (Inf s) = infi fun (I : ideal R) => infi fun (H : I ∈ comap f '' s) => I := sorry theorem comap_radical {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (K : ideal S) : comap f (radical K) = radical (comap f K) := sorry theorem comap_is_prime {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (K : ideal S) [H : is_prime K] : is_prime (comap f K) := sorry @[simp] theorem map_quotient_self {R : Type u} [comm_ring R] (I : ideal R) : map (quotient.mk I) I = ⊥ := iff.mpr eq_bot_iff (iff.mpr map_le_iff_le_comap fun (x : R) (hx : x ∈ I) => iff.mpr (submodule.mem_bot (quotient I)) (iff.mpr quotient.eq_zero_iff_mem hx)) theorem map_inf_le {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) {I : ideal R} {J : ideal R} : map f (I ⊓ J) ≤ map f I ⊓ map f J := monotone.map_inf_le (galois_connection.monotone_l (gc_map_comap f)) I J theorem map_radical_le {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) {I : ideal R} : map f (radical I) ≤ radical (map f I) := sorry theorem le_comap_sup {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) {K : ideal S} {L : ideal S} : comap f K ⊔ comap f L ≤ comap f (K ⊔ L) := monotone.le_map_sup (galois_connection.monotone_u (gc_map_comap f)) K L theorem le_comap_mul {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) {K : ideal S} {L : ideal S} : comap f K * comap f L ≤ comap f (K * L) := iff.mp map_le_iff_le_comap (Eq.symm (map_mul f (comap f K) (comap f L)) ▸ mul_mono (iff.mpr map_le_iff_le_comap (le_refl (comap f K))) (iff.mpr map_le_iff_le_comap (le_refl (comap f L)))) theorem map_comap_of_surjective {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (hf : function.surjective ⇑f) (I : ideal S) : map f (comap f I) = I := sorry /-- `map` and `comap` are adjoint, and the composition `map f ∘ comap f` is the identity -/ def gi_map_comap {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (hf : function.surjective ⇑f) : galois_insertion (map f) (comap f) := galois_insertion.monotone_intro sorry sorry sorry (map_comap_of_surjective f hf) theorem map_surjective_of_surjective {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (hf : function.surjective ⇑f) : function.surjective (map f) := galois_insertion.l_surjective (gi_map_comap f hf) theorem comap_injective_of_surjective {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (hf : function.surjective ⇑f) : function.injective (comap f) := galois_insertion.u_injective (gi_map_comap f hf) theorem map_sup_comap_of_surjective {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (hf : function.surjective ⇑f) (I : ideal S) (J : ideal S) : map f (comap f I ⊔ comap f J) = I ⊔ J := galois_insertion.l_sup_u (gi_map_comap f hf) I J theorem map_supr_comap_of_surjective {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) {ι : Sort u_1} (hf : function.surjective ⇑f) (K : ι → ideal S) : map f (supr fun (i : ι) => comap f (K i)) = supr K := galois_insertion.l_supr_u (gi_map_comap f hf) fun (i : ι) => K i theorem map_inf_comap_of_surjective {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (hf : function.surjective ⇑f) (I : ideal S) (J : ideal S) : map f (comap f I ⊓ comap f J) = I ⊓ J := galois_insertion.l_inf_u (gi_map_comap f hf) I J theorem map_infi_comap_of_surjective {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) {ι : Sort u_1} (hf : function.surjective ⇑f) (K : ι → ideal S) : map f (infi fun (i : ι) => comap f (K i)) = infi K := galois_insertion.l_infi_u (gi_map_comap f hf) fun (i : ι) => K i theorem mem_image_of_mem_map_of_surjective {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (hf : function.surjective ⇑f) {I : ideal R} {y : S} (H : y ∈ map f I) : y ∈ ⇑f '' ↑I := sorry theorem mem_map_iff_of_surjective {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (hf : function.surjective ⇑f) {I : ideal R} {y : S} : y ∈ map f I ↔ ∃ (x : R), x ∈ I ∧ coe_fn f x = y := sorry theorem comap_map_of_surjective {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (hf : function.surjective ⇑f) (I : ideal R) : comap f (map f I) = I ⊔ comap f ⊥ := sorry theorem le_map_of_comap_le_of_surjective {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) {I : ideal R} {K : ideal S} (hf : function.surjective ⇑f) : comap f K ≤ I → K ≤ map f I := fun (h : comap f K ≤ I) => map_comap_of_surjective f hf K ▸ map_mono h /-- Correspondence theorem -/ def rel_iso_of_surjective {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (hf : function.surjective ⇑f) : ideal S ≃o Subtype fun (p : ideal R) => comap f ⊥ ≤ p := rel_iso.mk (equiv.mk (fun (J : ideal S) => { val := comap f J, property := sorry }) (fun (I : Subtype fun (p : ideal R) => comap f ⊥ ≤ p) => map f (subtype.val I)) sorry sorry) sorry /-- The map on ideals induced by a surjective map preserves inclusion. -/ def order_embedding_of_surjective {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (hf : function.surjective ⇑f) : ideal S ↪o ideal R := rel_embedding.trans (rel_iso.to_rel_embedding (rel_iso_of_surjective f hf)) (subtype.rel_embedding LessEq fun (p : ideal R) => comap f ⊥ ≤ p) theorem map_eq_top_or_is_maximal_of_surjective {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) {I : ideal R} (hf : function.surjective ⇑f) (H : is_maximal I) : map f I = ⊤ ∨ is_maximal (map f I) := sorry theorem comap_is_maximal_of_surjective {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) {K : ideal S} (hf : function.surjective ⇑f) [H : is_maximal K] : is_maximal (comap f K) := sorry theorem mem_quotient_iff_mem {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} (hIJ : I ≤ J) {x : R} : coe_fn (quotient.mk I) x ∈ map (quotient.mk I) J ↔ x ∈ J := sorry theorem comap_bot_le_of_injective {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) {I : ideal R} (hf : function.injective ⇑f) : comap f ⊥ ≤ I := sorry /-- Special case of the correspondence theorem for isomorphic rings -/ def rel_iso_of_bijective {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) (hf : function.bijective ⇑f) : ideal S ≃o ideal R := rel_iso.mk (equiv.mk (comap f) (map f) sorry sorry) sorry theorem comap_le_iff_le_map {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) {I : ideal R} {K : ideal S} (hf : function.bijective ⇑f) : comap f K ≤ I ↔ K ≤ map f I := { mp := fun (h : comap f K ≤ I) => le_map_of_comap_le_of_surjective f (and.right hf) h, mpr := fun (h : K ≤ map f I) => equiv.right_inv (rel_iso.to_equiv (rel_iso_of_bijective f hf)) I ▸ comap_mono h } theorem map.is_maximal {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) {I : ideal R} (hf : function.bijective ⇑f) (H : is_maximal I) : is_maximal (map f I) := sorry theorem ring_equiv.bot_maximal_iff {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (e : R ≃+* S) : is_maximal ⊥ ↔ is_maximal ⊥ := sorry /-- A proper ideal `I` is primary iff `xy ∈ I` implies `x ∈ I` or `y ∈ radical I`. -/ def is_primary {R : Type u} [comm_ring R] (I : ideal R) := I ≠ ⊤ ∧ ∀ {x y : R}, x * y ∈ I → x ∈ I ∨ y ∈ radical I theorem is_primary.to_is_prime {R : Type u} [comm_ring R] (I : ideal R) (hi : is_prime I) : is_primary I := { left := and.left hi, right := fun (x y : R) (hxy : x * y ∈ I) => or.imp id (fun (hyi : y ∈ I) => le_radical hyi) (and.right hi x y hxy) } theorem mem_radical_of_pow_mem {R : Type u} [comm_ring R] {I : ideal R} {x : R} {m : ℕ} (hx : x ^ m ∈ radical I) : x ∈ radical I := radical_idem I ▸ Exists.intro m hx theorem is_prime_radical {R : Type u} [comm_ring R] {I : ideal R} (hi : is_primary I) : is_prime (radical I) := sorry theorem is_primary_inf {R : Type u} [comm_ring R] {I : ideal R} {J : ideal R} (hi : is_primary I) (hj : is_primary J) (hij : radical I = radical J) : is_primary (I ⊓ J) := sorry end ideal namespace ring_hom /-- Kernel of a ring homomorphism as an ideal of the domain. -/ def ker {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) : ideal R := ideal.comap f ⊥ /-- An element is in the kernel if and only if it maps to zero.-/ theorem mem_ker {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) {r : R} : r ∈ ker f ↔ coe_fn f r = 0 := sorry theorem ker_eq {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) : ↑(ker f) = is_add_group_hom.ker ⇑f := rfl theorem ker_eq_comap_bot {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) : ker f = ideal.comap f ⊥ := rfl theorem injective_iff_ker_eq_bot {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) : function.injective ⇑f ↔ ker f = ⊥ := eq.mpr (id (Eq._oldrec (Eq.refl (function.injective ⇑f ↔ ker f = ⊥)) (propext submodule.ext'_iff))) (eq.mpr (id (Eq._oldrec (Eq.refl (function.injective ⇑f ↔ ↑(ker f) = ↑⊥)) (ker_eq f))) (is_add_group_hom.injective_iff_trivial_ker ⇑f)) theorem ker_eq_bot_iff_eq_zero {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R →+* S) : ker f = ⊥ ↔ ∀ (x : R), coe_fn f x = 0 → x = 0 := eq.mpr (id (Eq._oldrec (Eq.refl (ker f = ⊥ ↔ ∀ (x : R), coe_fn f x = 0 → x = 0)) (propext submodule.ext'_iff))) (eq.mpr (id (Eq._oldrec (Eq.refl (↑(ker f) = ↑⊥ ↔ ∀ (x : R), coe_fn f x = 0 → x = 0)) (ker_eq f))) (is_add_group_hom.trivial_ker_iff_eq_zero ⇑f)) /-- If the target is not the zero ring, then one is not in the kernel.-/ theorem not_one_mem_ker {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] [nontrivial S] (f : R →+* S) : ¬1 ∈ ker f := eq.mpr (id (Eq._oldrec (Eq.refl (¬1 ∈ ker f)) (propext (mem_ker f)))) (eq.mpr (id (Eq._oldrec (Eq.refl (¬coe_fn f 1 = 0)) (map_one f))) one_ne_zero) @[simp] theorem ker_coe_equiv {R : Type u} {S : Type v} [comm_ring R] [comm_ring S] (f : R ≃+* S) : ker ↑f = ⊥ := eq.mpr (id (propext (iff.symm (injective_iff_ker_eq_bot ↑f)))) (eq.mp (Eq.refl (function.injective ⇑f)) (ring_equiv.injective f)) /-- The kernel of a homomorphism to an integral domain is a prime ideal.-/ theorem ker_is_prime {R : Type u} {S : Type v} [comm_ring R] [integral_domain S] (f : R →+* S) : ideal.is_prime (ker f) := sorry end ring_hom namespace ideal theorem map_eq_bot_iff_le_ker {R : Type u_1} {S : Type u_2} [comm_ring R] [comm_ring S] {I : ideal R} (f : R →+* S) : map f I = ⊥ ↔ I ≤ ring_hom.ker f := sorry @[simp] theorem mk_ker {R : Type u_1} [comm_ring R] {I : ideal R} : ring_hom.ker (quotient.mk I) = I := sorry theorem ker_le_comap {R : Type u_1} {S : Type u_2} [comm_ring R] [comm_ring S] {K : ideal S} (f : R →+* S) : ring_hom.ker f ≤ comap f K := fun (x : R) (hx : x ∈ ring_hom.ker f) => iff.mpr mem_comap (Eq.symm (iff.mp (ring_hom.mem_ker f) hx) ▸ ideal.zero_mem K) theorem map_Inf {R : Type u_1} {S : Type u_2} [comm_ring R] [comm_ring S] {A : set (ideal R)} {f : R →+* S} (hf : function.surjective ⇑f) : (∀ (J : ideal R), J ∈ A → ring_hom.ker f ≤ J) → map f (Inf A) = Inf (map f '' A) := sorry theorem map_is_prime_of_surjective {R : Type u_1} {S : Type u_2} [comm_ring R] [comm_ring S] {f : R →+* S} (hf : function.surjective ⇑f) {I : ideal R} [H : is_prime I] (hk : ring_hom.ker f ≤ I) : is_prime (map f I) := sorry theorem map_is_prime_of_equiv {R : Type u_1} {S : Type u_2} [comm_ring R] [comm_ring S] (f : R ≃+* S) {I : ideal R} [is_prime I] : is_prime (map (↑f) I) := sorry theorem map_radical_of_surjective {R : Type u_1} {S : Type u_2} [comm_ring R] [comm_ring S] {f : R →+* S} (hf : function.surjective ⇑f) {I : ideal R} (h : ring_hom.ker f ≤ I) : map f (radical I) = radical (map f I) := sorry @[simp] theorem bot_quotient_is_maximal_iff {R : Type u_1} [comm_ring R] (I : ideal R) : is_maximal ⊥ ↔ is_maximal I := { mp := fun (hI : is_maximal ⊥) => mk_ker ▸ comap_is_maximal_of_surjective (quotient.mk I) quotient.mk_surjective, mpr := fun (hI : is_maximal I) => bot_is_maximal } /-- The `R`-algebra structure on `A/I` for an `R`-algebra `A` -/ protected instance quotient.algebra (R : Type u_1) [comm_ring R] {A : Type u_3} [comm_ring A] [algebra R A] {I : ideal A} : algebra R (quotient I) := ring_hom.to_algebra (ring_hom.comp (quotient.mk I) (algebra_map R A)) /-- The canonical morphism `A →ₐ[R] I.quotient` as morphism of `R`-algebras, for `I` an ideal of `A`, where `A` is an `R`-algebra. -/ def quotient.mkₐ (R : Type u_1) [comm_ring R] {A : Type u_3} [comm_ring A] [algebra R A] (I : ideal A) : alg_hom R A (quotient I) := alg_hom.mk (fun (a : A) => submodule.quotient.mk a) sorry sorry sorry sorry sorry theorem quotient.alg_map_eq (R : Type u_1) [comm_ring R] {A : Type u_3} [comm_ring A] [algebra R A] (I : ideal A) : algebra_map R (quotient I) = ring_hom.comp (algebra_map A (quotient I)) (algebra_map R A) := sorry protected instance quotient.is_scalar_tower (R : Type u_1) [comm_ring R] {A : Type u_3} [comm_ring A] [algebra R A] {I : ideal A} : is_scalar_tower R A (quotient I) := is_scalar_tower.of_algebra_map_eq' (quotient.alg_map_eq R I) theorem quotient.mkₐ_to_ring_hom (R : Type u_1) [comm_ring R] {A : Type u_3} [comm_ring A] [algebra R A] (I : ideal A) : alg_hom.to_ring_hom (quotient.mkₐ R I) = quotient.mk I := rfl @[simp] theorem quotient.mkₐ_eq_mk (R : Type u_1) [comm_ring R] {A : Type u_3} [comm_ring A] [algebra R A] (I : ideal A) : ⇑(quotient.mkₐ R I) = ⇑(quotient.mk I) := rfl /-- The canonical morphism `A →ₐ[R] I.quotient` is surjective. -/ theorem quotient.mkₐ_surjective (R : Type u_1) [comm_ring R] {A : Type u_3} [comm_ring A] [algebra R A] (I : ideal A) : function.surjective ⇑(quotient.mkₐ R I) := surjective_quot_mk setoid.r /-- The kernel of `A →ₐ[R] I.quotient` is `I`. -/ @[simp] theorem quotient.mkₐ_ker (R : Type u_1) [comm_ring R] {A : Type u_3} [comm_ring A] [algebra R A] (I : ideal A) : ring_hom.ker (alg_hom.to_ring_hom (quotient.mkₐ R I)) = I := mk_ker /-- The ring hom `R/J →+* S/I` induced by a ring hom `f : R →+* S` with `J ≤ f⁻¹(I)` -/ def quotient_map {R : Type u_1} {S : Type u_2} [comm_ring R] [comm_ring S] {I : ideal R} (J : ideal S) (f : R →+* S) (hIJ : I ≤ comap f J) : quotient I →+* quotient J := quotient.lift I (ring_hom.comp (quotient.mk J) f) sorry @[simp] theorem quotient_map_mk {R : Type u_1} {S : Type u_2} [comm_ring R] [comm_ring S] {J : ideal R} {I : ideal S} {f : R →+* S} {H : J ≤ comap f I} {x : R} : coe_fn (quotient_map I f H) (coe_fn (quotient.mk J) x) = coe_fn (quotient.mk I) (coe_fn f x) := quotient.lift_mk J (ring_hom.comp (quotient.mk I) f) (quotient_map._proof_1 I f H) theorem quotient_map_comp_mk {R : Type u_1} {S : Type u_2} [comm_ring R] [comm_ring S] {J : ideal R} {I : ideal S} {f : R →+* S} (H : J ≤ comap f I) : ring_hom.comp (quotient_map I f H) (quotient.mk J) = ring_hom.comp (quotient.mk I) f := sorry /-- `H` and `h` are kept as seperate hypothesis since H is used in constructing the quotient map -/ theorem quotient_map_injective' {R : Type u_1} {S : Type u_2} [comm_ring R] [comm_ring S] {J : ideal R} {I : ideal S} {f : R →+* S} {H : J ≤ comap f I} (h : comap f I ≤ J) : function.injective ⇑(quotient_map I f H) := sorry /-- If we take `J = I.comap f` then `quotient_map` is injective automatically. -/ theorem quotient_map_injective {R : Type u_1} {S : Type u_2} [comm_ring R] [comm_ring S] {I : ideal S} {f : R →+* S} : function.injective ⇑(quotient_map I f le_rfl) := quotient_map_injective' le_rfl theorem quotient_map_surjective {R : Type u_1} {S : Type u_2} [comm_ring R] [comm_ring S] {J : ideal R} {I : ideal S} {f : R →+* S} {H : J ≤ comap f I} (hf : function.surjective ⇑f) : function.surjective ⇑(quotient_map I f H) := sorry /-- Commutativity of a square is preserved when taking quotients by an ideal. -/ theorem comp_quotient_map_eq_of_comp_eq {R : Type u_1} {S : Type u_2} [comm_ring R] [comm_ring S] {R' : Type u_3} {S' : Type u_4} [comm_ring R'] [comm_ring S'] {f : R →+* S} {f' : R' →+* S'} {g : R →+* R'} {g' : S →+* S'} (hfg : ring_hom.comp f' g = ring_hom.comp g' f) (I : ideal S') : ring_hom.comp (quotient_map I g' le_rfl) (quotient_map (comap g' I) f le_rfl) = ring_hom.comp (quotient_map I f' le_rfl) (quotient_map (comap f' I) g (le_of_eq (trans (comap_comap f g') (hfg ▸ comap_comap g f')))) := sorry protected instance quotient_algebra {R : Type u_1} {S : Type u_2} [comm_ring R] [comm_ring S] {J : ideal S} [algebra R S] : algebra (quotient (comap (algebra_map R S) J)) (quotient J) := ring_hom.to_algebra (quotient_map J (algebra_map R S) sorry) theorem algebra_map_quotient_injective {R : Type u_1} {S : Type u_2} [comm_ring R] [comm_ring S] {J : ideal S} [algebra R S] : function.injective ⇑(algebra_map (quotient (comap (algebra_map R S) J)) (quotient J)) := sorry end ideal namespace submodule -- It is even a semialgebra. But those aren't in mathlib yet. protected instance semimodule_submodule {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] : semimodule (ideal R) (submodule R M) := semimodule.mk sup_smul bot_smul end submodule namespace ring_hom /-- `lift_of_surjective f hf g hg` is the unique ring homomorphism `φ` * such that `φ.comp f = g` (`lift_of_surjective_comp`), * where `f : A →+* B` is surjective (`hf`), * and `g : B →+* C` satisfies `hg : f.ker ≤ g.ker`. See `lift_of_surjective_eq` for the uniqueness lemma. ``` A . | \ f | \ g | \ v \⌟ B ----> C ∃!φ ``` -/ def lift_of_surjective {A : Type u_1} {B : Type u_2} {C : Type u_3} [comm_ring A] [comm_ring B] [comm_ring C] (f : A →+* B) (hf : function.surjective ⇑f) (g : A →+* C) (hg : ker f ≤ ker g) : B →+* C := mk (fun (b : B) => coe_fn g (classical.some (hf b))) sorry sorry sorry sorry @[simp] theorem lift_of_surjective_comp_apply {A : Type u_1} {B : Type u_2} {C : Type u_3} [comm_ring A] [comm_ring B] [comm_ring C] (f : A →+* B) (hf : function.surjective ⇑f) (g : A →+* C) (hg : ker f ≤ ker g) (a : A) : coe_fn (lift_of_surjective f hf g hg) (coe_fn f a) = coe_fn g a := add_monoid_hom.lift_of_surjective_comp_apply (to_add_monoid_hom f) hf (to_add_monoid_hom g) hg a @[simp] theorem lift_of_surjective_comp {A : Type u_1} {B : Type u_2} {C : Type u_3} [comm_ring A] [comm_ring B] [comm_ring C] (f : A →+* B) (hf : function.surjective ⇑f) (g : A →+* C) (hg : ker f ≤ ker g) : comp (lift_of_surjective f hf g hg) f = g := sorry theorem eq_lift_of_surjective {A : Type u_1} {B : Type u_2} {C : Type u_3} [comm_ring A] [comm_ring B] [comm_ring C] (f : A →+* B) (hf : function.surjective ⇑f) (g : A →+* C) (hg : ker f ≤ ker g) (h : B →+* C) (hh : comp h f = g) : h = lift_of_surjective f hf g hg := sorry end Mathlib
6224205fae6cc946af3465d3cb70301833574b14
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/topology/bornology/hom.lean
021cac114f084ed3d0b83752d8fb1bcec594a460
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
5,359
lean
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import topology.bornology.basic /-! # Locally bounded maps > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file defines locally bounded maps between bornologies. We use the `fun_like` design, so each type of morphisms has a companion typeclass which is meant to be satisfied by itself and all stricter types. ## Types of morphisms * `locally_bounded_map`: Locally bounded maps. Maps which preserve boundedness. ## Typeclasses * `locally_bounded_map_class` -/ open bornology filter function set variables {F α β γ δ : Type*} /-- The type of bounded maps from `α` to `β`, the maps which send a bounded set to a bounded set. -/ structure locally_bounded_map (α β : Type*) [bornology α] [bornology β] := (to_fun : α → β) (comap_cobounded_le' : (cobounded β).comap to_fun ≤ cobounded α) section set_option old_structure_cmd true /-- `locally_bounded_map_class F α β` states that `F` is a type of bounded maps. You should extend this class when you extend `locally_bounded_map`. -/ class locally_bounded_map_class (F : Type*) (α β : out_param $ Type*) [bornology α] [bornology β] extends fun_like F α (λ _, β) := (comap_cobounded_le (f : F) : (cobounded β).comap f ≤ cobounded α) end export locally_bounded_map_class (comap_cobounded_le) lemma is_bounded.image [bornology α] [bornology β] [locally_bounded_map_class F α β] {f : F} {s : set α} (hs : is_bounded s) : is_bounded (f '' s) := comap_cobounded_le_iff.1 (comap_cobounded_le f) hs instance [bornology α] [bornology β] [locally_bounded_map_class F α β] : has_coe_t F (locally_bounded_map α β) := ⟨λ f, ⟨f, comap_cobounded_le f⟩⟩ namespace locally_bounded_map variables [bornology α] [bornology β] [bornology γ] [bornology δ] instance : locally_bounded_map_class (locally_bounded_map α β) α β := { coe := λ f, f.to_fun, coe_injective' := λ f g h, by { cases f, cases g, congr' }, comap_cobounded_le := λ f, f.comap_cobounded_le' } /-- Helper instance for when there's too many metavariables to apply `fun_like.has_coe_to_fun` directly. -/ instance : has_coe_to_fun (locally_bounded_map α β) (λ _, α → β) := fun_like.has_coe_to_fun @[simp] lemma to_fun_eq_coe {f : locally_bounded_map α β} : f.to_fun = (f : α → β) := rfl @[ext] lemma ext {f g : locally_bounded_map α β} (h : ∀ a, f a = g a) : f = g := fun_like.ext f g h /-- Copy of a `locally_bounded_map` with a new `to_fun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : locally_bounded_map α β) (f' : α → β) (h : f' = f) : locally_bounded_map α β := ⟨f', h.symm ▸ f.comap_cobounded_le'⟩ @[simp] lemma coe_copy (f : locally_bounded_map α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl lemma copy_eq (f : locally_bounded_map α β) (f' : α → β) (h : f' = f) : f.copy f' h = f := fun_like.ext' h /-- Construct a `locally_bounded_map` from the fact that the function maps bounded sets to bounded sets. -/ def of_map_bounded (f : α → β) (h) : locally_bounded_map α β := ⟨f, comap_cobounded_le_iff.2 h⟩ @[simp] lemma coe_of_map_bounded (f : α → β) {h} : ⇑(of_map_bounded f h) = f := rfl @[simp] lemma of_map_bounded_apply (f : α → β) {h} (a : α) : of_map_bounded f h a = f a := rfl variables (α) /-- `id` as a `locally_bounded_map`. -/ protected def id : locally_bounded_map α α := ⟨id, comap_id.le⟩ instance : inhabited (locally_bounded_map α α) := ⟨locally_bounded_map.id α⟩ @[simp] lemma coe_id : ⇑(locally_bounded_map.id α) = id := rfl variables {α} @[simp] lemma id_apply (a : α) : locally_bounded_map.id α a = a := rfl /-- Composition of `locally_bounded_map`s as a `locally_bounded_map`. -/ def comp (f : locally_bounded_map β γ) (g : locally_bounded_map α β) : locally_bounded_map α γ := { to_fun := f ∘ g, comap_cobounded_le' := comap_comap.ge.trans $ (comap_mono f.comap_cobounded_le').trans g.comap_cobounded_le' } @[simp] lemma coe_comp (f : locally_bounded_map β γ) (g : locally_bounded_map α β) : ⇑(f.comp g) = f ∘ g := rfl @[simp] lemma comp_apply (f : locally_bounded_map β γ) (g : locally_bounded_map α β) (a : α) : f.comp g a = f (g a) := rfl @[simp] lemma comp_assoc (f : locally_bounded_map γ δ) (g : locally_bounded_map β γ) (h : locally_bounded_map α β) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] lemma comp_id (f : locally_bounded_map α β) : f.comp (locally_bounded_map.id α) = f := ext $ λ a, rfl @[simp] lemma id_comp (f : locally_bounded_map α β) : (locally_bounded_map.id β).comp f = f := ext $ λ a, rfl lemma cancel_right {g₁ g₂ : locally_bounded_map β γ} {f : locally_bounded_map α β} (hf : surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨λ h, ext $ hf.forall.2 $ fun_like.ext_iff.1 h, congr_arg _⟩ lemma cancel_left {g : locally_bounded_map β γ} {f₁ f₂ : locally_bounded_map α β} (hg : injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨λ h, ext $ λ a, hg $ by rw [←comp_apply, h, comp_apply], congr_arg _⟩ end locally_bounded_map
dc26f84486b488296ee52db4aa3ceb254420d018
b2e508d02500f1512e1618150413e6be69d9db10
/src/data/equiv/denumerable.lean
3a320844798d07087bebc52db149314ee62e0a38
[ "Apache-2.0" ]
permissive
callum-sutton/mathlib
c3788f90216e9cd43eeffcb9f8c9f959b3b01771
afd623825a3ac6bfbcc675a9b023edad3f069e89
refs/heads/master
1,591,371,888,053
1,560,990,690,000
1,560,990,690,000
192,476,045
0
0
Apache-2.0
1,568,941,843,000
1,560,837,965,000
Lean
UTF-8
Lean
false
false
8,754
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Mario Carneiro Denumerable (countably infinite) types, as a typeclass extending encodable. This is used to provide explicit encode/decode functions from nat, where the functions are known inverses of each other. -/ import data.equiv.encodable data.sigma data.fintype data.list.min_max open nat /-- A denumerable type is one which is (constructively) bijective with ℕ. Although we already have a name for this property, namely `α ≃ ℕ`, we are here interested in using it as a typeclass. -/ class denumerable (α : Type*) extends encodable α := (decode_inv : ∀ n, ∃ a ∈ decode n, encode a = n) namespace denumerable section variables {α : Type*} {β : Type*} [denumerable α] [denumerable β] open encodable @[simp] theorem decode_is_some (α) [denumerable α] (n : ℕ) : (decode α n).is_some := option.is_some_iff_exists.2 $ (decode_inv α n).imp $ λ a, Exists.fst def of_nat (α) [f : denumerable α] (n : ℕ) : α := option.get (decode_is_some α n) @[simp] theorem decode_eq_of_nat (α) [denumerable α] (n : ℕ) : decode α n = some (of_nat α n) := option.eq_some_of_is_some _ @[simp] theorem of_nat_of_decode {n b} (h : decode α n = some b) : of_nat α n = b := option.some.inj $ (decode_eq_of_nat _ _).symm.trans h @[simp] theorem encode_of_nat (n) : encode (of_nat α n) = n := let ⟨a, h, e⟩ := decode_inv α n in by rwa [of_nat_of_decode h] @[simp] theorem of_nat_encode (a) : of_nat α (encode a) = a := of_nat_of_decode (encodek _) def eqv (α) [denumerable α] : α ≃ ℕ := ⟨encode, of_nat α, of_nat_encode, encode_of_nat⟩ def mk' {α} (e : α ≃ ℕ) : denumerable α := { encode := e, decode := some ∘ e.symm, encodek := λ a, congr_arg some (e.symm_apply_apply _), decode_inv := λ n, ⟨_, rfl, e.apply_symm_apply _⟩ } def of_equiv (α) {β} [denumerable α] (e : β ≃ α) : denumerable β := { decode_inv := λ n, by simp, ..encodable.of_equiv _ e } @[simp] theorem of_equiv_of_nat (α) {β} [denumerable α] (e : β ≃ α) (n) : @of_nat β (of_equiv _ e) n = e.symm (of_nat α n) := by apply of_nat_of_decode; show option.map _ _ = _; simp def equiv₂ (α β) [denumerable α] [denumerable β] : α ≃ β := (eqv α).trans (eqv β).symm instance nat : denumerable nat := ⟨λ n, ⟨_, rfl, rfl⟩⟩ @[simp] theorem of_nat_nat (n) : of_nat ℕ n = n := rfl instance option : denumerable (option α) := ⟨λ n, by cases n; simp⟩ instance sum : denumerable (α ⊕ β) := ⟨λ n, begin suffices : ∃ a ∈ @decode_sum α β _ _ n, encode_sum a = bit (bodd n) (div2 n), {simpa [bit_decomp]}, simp [decode_sum]; cases bodd n; simp [decode_sum, bit, encode_sum] end⟩ section sigma variables {γ : α → Type*} [∀ a, denumerable (γ a)] instance sigma : denumerable (sigma γ) := ⟨λ n, by simp [decode_sigma]; exact ⟨_, _, ⟨rfl, heq.rfl⟩, by simp⟩⟩ @[simp] theorem sigma_of_nat_val (n : ℕ) : of_nat (sigma γ) n = ⟨of_nat α (unpair n).1, of_nat (γ _) (unpair n).2⟩ := option.some.inj $ by rw [← decode_eq_of_nat, decode_sigma_val]; simp; refl end sigma instance prod : denumerable (α × β) := of_equiv _ (equiv.sigma_equiv_prod α β).symm @[simp] theorem prod_of_nat_val (n : ℕ) : of_nat (α × β) n = (of_nat α (unpair n).1, of_nat β (unpair n).2) := by simp; refl @[simp] theorem prod_nat_of_nat : of_nat (ℕ × ℕ) = unpair := by funext; simp instance int : denumerable ℤ := of_equiv _ equiv.int_equiv_nat instance ulift : denumerable (ulift α) := of_equiv _ equiv.ulift instance plift : denumerable (plift α) := of_equiv _ equiv.plift def pair : (α × α) ≃ α := equiv₂ _ _ end end denumerable namespace nat.subtype open function encodable lattice variables {s : set ℕ} [decidable_pred s] [infinite s] lemma exists_succ (x : s) : ∃ n, x.1 + n + 1 ∈ s := classical.by_contradiction $ λ h, have ∀ (a : ℕ) (ha : a ∈ s), a < x.val.succ, from λ a ha, lt_of_not_ge (λ hax, h ⟨a - (x.1 + 1), by rwa [add_right_comm, nat.add_sub_cancel' hax]⟩), infinite.not_fintype ⟨(((multiset.range x.1.succ).filter (∈ s)).pmap (λ (y : ℕ) (hy : y ∈ s), subtype.mk y hy) (by simp [-multiset.range_succ])).to_finset, by simpa [subtype.ext, multiset.mem_filter, -multiset.range_succ]⟩ def succ (x : s) : s := have h : ∃ m, x.1 + m + 1 ∈ s, from exists_succ x, ⟨x.1 + nat.find h + 1, nat.find_spec h⟩ lemma succ_le_of_lt {x y : s} (h : y < x) : succ y ≤ x := have hx : ∃ m, y.1 + m + 1 ∈ s, from exists_succ _, let ⟨k, hk⟩ := nat.exists_eq_add_of_lt h in have nat.find hx ≤ k, from nat.find_min' _ (hk ▸ x.2), show y.1 + nat.find hx + 1 ≤ x.1, by rw hk; exact add_le_add_right (add_le_add_left this _) _ lemma le_succ_of_forall_lt_le {x y : s} (h : ∀ z < x, z ≤ y) : x ≤ succ y := have hx : ∃ m, y.1 + m + 1 ∈ s, from exists_succ _, show x.1 ≤ y.1 + nat.find hx + 1, from le_of_not_gt $ λ hxy, have y.1 + nat.find hx + 1 ≤ y.1 := h ⟨_, nat.find_spec hx⟩ hxy, not_lt_of_le this $ calc y.1 ≤ y.1 + nat.find hx : le_add_of_nonneg_right (nat.zero_le _) ... < y.1 + nat.find hx + 1 : nat.lt_succ_self _ lemma lt_succ_self (x : s) : x < succ x := calc x.1 ≤ x.1 + _ : le_add_right (le_refl _) ... < succ x : nat.lt_succ_self (x.1 + _) lemma lt_succ_iff_le {x y : s} : x < succ y ↔ x ≤ y := ⟨λ h, le_of_not_gt (λ h', not_le_of_gt h (succ_le_of_lt h')), λ h, lt_of_le_of_lt h (lt_succ_self _)⟩ def of_nat (s : set ℕ) [decidable_pred s] [infinite s] : ℕ → s | 0 := ⊥ | (n+1) := succ (of_nat n) lemma of_nat_surjective_aux : ∀ {x : ℕ} (hx : x ∈ s), ∃ n, of_nat s n = ⟨x, hx⟩ | x := λ hx, let t : list s := ((list.range x).filter (λ y, y ∈ s)).pmap (λ (y : ℕ) (hy : y ∈ s), ⟨y, hy⟩) (by simp) in have hmt : ∀ {y : s}, y ∈ t ↔ y < ⟨x, hx⟩, by simp [list.mem_filter, subtype.ext, t]; intros; refl, if ht : t = [] then ⟨0, le_antisymm (@bot_le s _ _) (le_of_not_gt (λ h, list.not_mem_nil ⊥ $ by rw [← ht, hmt]; exact h))⟩ else by letI : inhabited s := ⟨⊥⟩; exact have wf : (list.maximum t).1 < x, by simpa [hmt] using list.mem_maximum ht, let ⟨a, ha⟩ := of_nat_surjective_aux (list.maximum t).2 in ⟨a + 1, le_antisymm (by rw of_nat; exact succ_le_of_lt (by rw ha; exact wf)) $ by rw of_nat; exact le_succ_of_forall_lt_le (λ z hz, by rw ha; exact list.le_maximum_of_mem (hmt.2 hz))⟩ lemma of_nat_surjective : surjective (of_nat s) := λ ⟨x, hx⟩, of_nat_surjective_aux hx private def to_fun_aux (x : s) : ℕ := (list.range x).countp s private lemma to_fun_aux_eq (x : s) : to_fun_aux x = ((finset.range x).filter s).card := by rw [to_fun_aux, list.countp_eq_length_filter]; refl open finset private lemma right_inverse_aux : ∀ n, to_fun_aux (of_nat s n) = n | 0 := begin rw [to_fun_aux_eq, card_eq_zero, eq_empty_iff_forall_not_mem], assume n, rw [mem_filter, of_nat, mem_range], assume h, exact not_lt_of_le bot_le (show (⟨n, h.2⟩ : s) < ⊥, from h.1) end | (n+1) := have ih : to_fun_aux (of_nat s n) = n, from right_inverse_aux n, have h₁ : (of_nat s n : ℕ) ∉ (range (of_nat s n)).filter s, by simp, have h₂ : (range (succ (of_nat s n))).filter s = insert (of_nat s n) ((range (of_nat s n)).filter s), begin simp only [finset.ext, mem_insert, mem_range, mem_filter], assume m, exact ⟨λ h, by simp only [h.2, and_true]; exact or.symm (lt_or_eq_of_le ((@lt_succ_iff_le _ _ _ ⟨m, h.2⟩ _).1 h.1)), λ h, h.elim (λ h, h.symm ▸ ⟨lt_succ_self _, subtype.property _⟩) (λ h, ⟨lt_of_le_of_lt (le_of_lt h.1) (lt_succ_self _), h.2⟩)⟩ end, begin clear_aux_decl, simp only [to_fun_aux_eq, of_nat, range_succ] at *, conv {to_rhs, rw [← ih, ← card_insert_of_not_mem h₁, ← h₂] }, end def denumerable (s : set ℕ) [decidable_pred s] [infinite s] : denumerable s := denumerable.of_equiv ℕ { to_fun := to_fun_aux, inv_fun := of_nat s, left_inv := left_inverse_of_surjective_of_right_inverse of_nat_surjective right_inverse_aux, right_inv := right_inverse_aux } end nat.subtype namespace denumerable open encodable def of_encodable_of_infinite (α : Type*) [encodable α] [infinite α] : denumerable α := begin letI := @decidable_range_encode α _; letI : infinite (set.range (@encode α _)) := infinite.of_injective _ (equiv.set.range _ encode_injective).injective, letI := nat.subtype.denumerable (set.range (@encode α _)), exact denumerable.of_equiv (set.range (@encode α _)) (equiv_range_encode α) end end denumerable
96dd521bd3441178089a687215593f546c5d6e7e
54ce0561cebde424526f41d45f490ed56be2bd0c
/src/game/ch3_Set_Theory/5_Cartesian_Products.lean
9eb9744e48e665bb9dbafa442e1092d4855d9721
[]
no_license
melembroucarlitos/Tao_Analysis-LEAN
cf7b3298d317891a09e4bf21cfe7c7ffcb57b9a9
3f4fc7e090d96b6cef64896492fba4bef124794b
refs/heads/master
1,692,952,385,694
1,636,287,522,000
1,636,287,522,000
400,630,166
3
0
null
1,635,910,807,000
1,630,096,823,000
Lean
UTF-8
Lean
false
false
169
lean
-- Level name : Cartesian Products /- # Hey yall ## This is just to a placeholder to make sure all is working these are some words and these are some other words -/
082d88b79ce197d94d1e6ca80a68f3068900a039
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/run/461a.lean
2032ca404d64d16997781b86caf8ab500788ac89
[ "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
298
lean
structure FooS where x : Nat y : Nat h : x = y := by rfl #print FooS.mk def f1 (x : Nat) : FooS := { x := x, y := x } structure BooS where x : Nat y : Nat h (aux1 : True) (aux2 : x > 2) : x = y := by { intros; rfl } #print BooS.mk def f2 (x : Nat) : BooS := { x := x, y := x }
0d42424eb0a60c324dce6bdc25a6b2d8549c74ea
4efff1f47634ff19e2f786deadd394270a59ecd2
/src/algebra/category/Group/colimits.lean
fc815e2bd8813216aa89f3cbba855ae76dd8bb1a
[ "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
9,170
lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import algebra.category.Group.preadditive import group_theory.quotient_group import category_theory.limits.limits import category_theory.limits.concrete_category import category_theory.limits.shapes.kernels import category_theory.limits.shapes.concrete_category /-! # The category of additive commutative groups has all colimits. This file uses a "pre-automated" approach, just as for `Mon/colimits.lean`. It is a very uniform approach, that conceivably could be synthesised directly by a tactic that analyses the shape of `add_comm_group` and `monoid_hom`. TODO: In fact, in `AddCommGroup` there is a much nicer model of colimits as quotients of finitely supported functions, and we really should implement this as well (or instead). -/ universes u v open category_theory open category_theory.limits -- [ROBOT VOICE]: -- You should pretend for now that this file was automatically generated. -- It follows the same template as colimits in Mon. namespace AddCommGroup.colimits /-! We build the colimit of a diagram in `AddCommGroup` by constructing the free group on the disjoint union of all the abelian groups in the diagram, then taking the quotient by the abelian group laws within each abelian group, and the identifications given by the morphisms in the diagram. -/ variables {J : Type v} [small_category J] (F : J ⥤ AddCommGroup.{v}) /-- An inductive type representing all group expressions (without relations) on a collection of types indexed by the objects of `J`. -/ inductive prequotient -- There's always `of` | of : Π (j : J) (x : F.obj j), prequotient -- Then one generator for each operation | zero : prequotient | neg : prequotient → prequotient | add : prequotient → prequotient → prequotient instance : inhabited (prequotient F) := ⟨prequotient.zero⟩ open prequotient /-- The relation on `prequotient` saying when two expressions are equal because of the abelian group laws, or because one element is mapped to another by a morphism in the diagram. -/ inductive relation : prequotient F → prequotient F → Prop -- Make it an equivalence relation: | refl : Π (x), relation x x | symm : Π (x y) (h : relation x y), relation y x | trans : Π (x y z) (h : relation x y) (k : relation y z), relation x z -- There's always a `map` relation | map : Π (j j' : J) (f : j ⟶ j') (x : F.obj j), relation (of j' (F.map f x)) (of j x) -- Then one relation per operation, describing the interaction with `of` | zero : Π (j), relation (of j 0) zero | neg : Π (j) (x : F.obj j), relation (of j (-x)) (neg (of j x)) | add : Π (j) (x y : F.obj j), relation (of j (x + y)) (add (of j x) (of j y)) -- Then one relation per argument of each operation | neg_1 : Π (x x') (r : relation x x'), relation (neg x) (neg x') | add_1 : Π (x x' y) (r : relation x x'), relation (add x y) (add x' y) | add_2 : Π (x y y') (r : relation y y'), relation (add x y) (add x y') -- And one relation per axiom | zero_add : Π (x), relation (add zero x) x | add_zero : Π (x), relation (add x zero) x | add_left_neg : Π (x), relation (add (neg x) x) zero | add_comm : Π (x y), relation (add x y) (add y x) | add_assoc : Π (x y z), relation (add (add x y) z) (add x (add y z)) /-- The setoid corresponding to group expressions modulo abelian group relations and identifications. -/ def colimit_setoid : setoid (prequotient F) := { r := relation F, iseqv := ⟨relation.refl, relation.symm, relation.trans⟩ } attribute [instance] colimit_setoid /-- The underlying type of the colimit of a diagram in `AddCommGroup`. -/ @[derive inhabited] def colimit_type : Type v := quotient (colimit_setoid F) instance : add_comm_group (colimit_type F) := { zero := begin exact quot.mk _ zero end, neg := begin fapply @quot.lift, { intro x, exact quot.mk _ (neg x) }, { intros x x' r, apply quot.sound, exact relation.neg_1 _ _ r }, end, add := begin fapply @quot.lift _ _ ((colimit_type F) → (colimit_type F)), { intro x, fapply @quot.lift, { intro y, exact quot.mk _ (add x y) }, { intros y y' r, apply quot.sound, exact relation.add_2 _ _ _ r } }, { intros x x' r, funext y, induction y, dsimp, apply quot.sound, { exact relation.add_1 _ _ _ r }, { refl } }, end, zero_add := λ x, begin induction x, dsimp, apply quot.sound, apply relation.zero_add, refl, end, add_zero := λ x, begin induction x, dsimp, apply quot.sound, apply relation.add_zero, refl, end, add_left_neg := λ x, begin induction x, dsimp, apply quot.sound, apply relation.add_left_neg, refl, end, add_comm := λ x y, begin induction x, induction y, dsimp, apply quot.sound, apply relation.add_comm, refl, refl, end, add_assoc := λ x y z, begin induction x, induction y, induction z, dsimp, apply quot.sound, apply relation.add_assoc, refl, refl, refl, end, } @[simp] lemma quot_zero : quot.mk setoid.r zero = (0 : colimit_type F) := rfl @[simp] lemma quot_neg (x) : quot.mk setoid.r (neg x) = (-(quot.mk setoid.r x) : colimit_type F) := rfl @[simp] lemma quot_add (x y) : quot.mk setoid.r (add x y) = ((quot.mk setoid.r x) + (quot.mk setoid.r y) : colimit_type F) := rfl /-- The bundled abelian group giving the colimit of a diagram. -/ def colimit : AddCommGroup := AddCommGroup.of (colimit_type F) /-- The function from a given abelian group in the diagram to the colimit abelian group. -/ def cocone_fun (j : J) (x : F.obj j) : colimit_type F := quot.mk _ (of j x) /-- The group homomorphism from a given abelian group in the diagram to the colimit abelian group. -/ def cocone_morphism (j : J) : F.obj j ⟶ colimit F := { to_fun := cocone_fun F j, map_zero' := by apply quot.sound; apply relation.zero, map_add' := by intros; apply quot.sound; apply relation.add } @[simp] lemma cocone_naturality {j j' : J} (f : j ⟶ j') : F.map f ≫ (cocone_morphism F j') = cocone_morphism F j := begin ext, apply quot.sound, apply relation.map, end @[simp] lemma cocone_naturality_components (j j' : J) (f : j ⟶ j') (x : F.obj j): (cocone_morphism F j') (F.map f x) = (cocone_morphism F j) x := by { rw ←cocone_naturality F f, refl } /-- The cocone over the proposed colimit abelian group. -/ def colimit_cocone : cocone F := { X := colimit F, ι := { app := cocone_morphism F } }. /-- The function from the free abelian group on the diagram to the cone point of any other cocone. -/ @[simp] def desc_fun_lift (s : cocone F) : prequotient F → s.X | (of j x) := (s.ι.app j) x | zero := 0 | (neg x) := -(desc_fun_lift x) | (add x y) := desc_fun_lift x + desc_fun_lift y /-- The function from the colimit abelian group to the cone point of any other cocone. -/ def desc_fun (s : cocone F) : colimit_type F → s.X := begin fapply quot.lift, { exact desc_fun_lift F s }, { intros x y r, induction r; try { dsimp }, -- refl { refl }, -- symm { exact r_ih.symm }, -- trans { exact eq.trans r_ih_h r_ih_k }, -- map { simp, }, -- zero { simp, }, -- neg { simp, }, -- add { simp, }, -- neg_1 { rw r_ih, }, -- add_1 { rw r_ih, }, -- add_2 { rw r_ih, }, -- zero_add { rw zero_add, }, -- add_zero { rw add_zero, }, -- add_left_neg { rw add_left_neg, }, -- add_comm { rw add_comm, }, -- add_assoc { rw add_assoc, }, } end /-- The group homomorphism from the colimit abelian group to the cone point of any other cocone. -/ def desc_morphism (s : cocone F) : colimit F ⟶ s.X := { to_fun := desc_fun F s, map_zero' := rfl, map_add' := λ x y, by { induction x; induction y; refl }, } /-- Evidence that the proposed colimit is the colimit. -/ def colimit_is_colimit : is_colimit (colimit_cocone F) := { desc := λ s, desc_morphism F s, uniq' := λ s m w, begin ext, induction x, induction x, { have w' := congr_fun (congr_arg (λ f : F.obj x_j ⟶ s.X, (f : F.obj x_j → s.X)) (w x_j)) x_x, erw w', refl, }, { simp *, }, { simp *, }, { simp *, }, refl end }. instance has_colimits_AddCommGroup : has_colimits AddCommGroup := { has_colimits_of_shape := λ J 𝒥, { has_colimit := λ F, by exactI { cocone := colimit_cocone F, is_colimit := colimit_is_colimit F } } } end AddCommGroup.colimits namespace AddCommGroup open quotient_add_group /-- The categorical cokernel of a morphism in `AddCommGroup` agrees with the usual group-theoretical quotient. -/ def cokernel_iso_quotient {G H : AddCommGroup} (f : G ⟶ H) : cokernel f ≅ AddCommGroup.of (quotient (add_monoid_hom.range f)) := { hom := cokernel.desc f (mk' _) (by { ext, apply quotient.sound, fsplit, exact -x, simp, }), inv := add_monoid_hom.of (quotient_add_group.lift _ (cokernel.π f) (by tidy)), } end AddCommGroup
0b370ec0a5fb54402bc05d837ad21eb2dc789b29
05f637fa14ac28031cb1ea92086a0f4eb23ff2b1
/tests/lean/conv.lean
3438cf8db2083af012ae73858edf47a9e42a2a7a
[ "Apache-2.0" ]
permissive
codyroux/lean0.1
1ce92751d664aacff0529e139083304a7bbc8a71
0dc6fb974aa85ed6f305a2f4b10a53a44ee5f0ef
refs/heads/master
1,610,830,535,062
1,402,150,480,000
1,402,150,480,000
19,588,851
2
0
null
null
null
null
UTF-8
Lean
false
false
512
lean
import Int. definition id (A : Type) : (Type U) := A. variable p : (Int -> Int) -> Bool. check fun (x : id Int), x. variable f : (id Int) -> (id Int). check p f. definition c (A : (Type 3)) : (Type 3) := (Type 1). variable g : (c (Type 2)) -> Bool. variable a : (c (Type 1)). check g a. definition c2 {T : Type} (A : (Type 3)) (a : T) : (Type 3) := (Type 1) variable b : Int check @c2 variable g2 : (c2 (Type 2) b) -> Bool check g2 variable a2 : (c2 (Type 1) b). check g2 a2 check fun x : (c2 (Type 1) b), g2 x
79ac86563fb3a556c3544cbf2dbb5fff8d28e10c
4727251e0cd73359b15b664c3170e5d754078599
/src/algebra/order/lattice_group.lean
ee56e6beaf7504aed387f597cd955dcda7318478
[ "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
18,890
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.group_power.basic -- Needed for squares import algebra.order.group import tactic.nth_rewrite /-! # Lattice ordered groups Lattice ordered groups were introduced by [Birkhoff][birkhoff1942]. They form the algebraic underpinnings of vector lattices, Banach lattices, AL-space, AM-space etc. This file develops the basic theory, concentrating on the commutative case. ## Main statements - `pos_div_neg`: Every element `a` of a lattice ordered commutative group has a decomposition `a⁺-a⁻` into the difference of the positive and negative component. - `pos_inf_neg_eq_one`: The positive and negative components are coprime. - `abs_triangle`: The absolute value operation satisfies the triangle inequality. It is shown that the inf and sup operations are related to the absolute value operation by a number of equations and inequalities. ## Notations - `a⁺ = a ⊔ 0`: The *positive component* of an element `a` of a lattice ordered commutative group - `a⁻ = (-a) ⊔ 0`: The *negative component* of an element `a` of a lattice ordered commutative group * `|a| = a⊔(-a)`: The *absolute value* of an element `a` of a lattice ordered commutative group ## Implementation notes A lattice ordered commutative group is a type `α` satisfying: * `[lattice α]` * `[comm_group α]` * `[covariant_class α α (*) (≤)]` The remainder of the file establishes basic properties of lattice ordered commutative groups. A number of these results also hold in the non-commutative case ([Birkhoff][birkhoff1942], [Fuchs][fuchs1963]) but we have not developed that here, since we are primarily interested in vector lattices. ## References * [Birkhoff, Lattice-ordered Groups][birkhoff1942] * [Bourbaki, Algebra II][bourbaki1981] * [Fuchs, Partially Ordered Algebraic Systems][fuchs1963] * [Zaanen, Lectures on "Riesz Spaces"][zaanen1966] * [Banasiak, Banach Lattices in Applications][banasiak] ## Tags lattice, ordered, group -/ universe u -- A linearly ordered additive commutative group is a lattice ordered commutative group @[priority 100, to_additive] -- see Note [lower instance priority] instance linear_ordered_comm_group.to_covariant_class (α : Type u) [linear_ordered_comm_group α] : covariant_class α α (*) (≤) := { elim := λ a b c bc, linear_ordered_comm_group.mul_le_mul_left _ _ bc a } variables {α : Type u} [lattice α] [comm_group α] -- Special case of Bourbaki A.VI.9 (1) -- c + (a ⊔ b) = (c + a) ⊔ (c + b) @[to_additive] lemma mul_sup [covariant_class α α (*) (≤)] (a b c : α) : c * (a ⊔ b) = (c * a) ⊔ (c * b) := begin refine le_antisymm _ (by simp), rw [← mul_le_mul_iff_left (c⁻¹), ← mul_assoc, inv_mul_self, one_mul], exact sup_le (by simp) (by simp), end @[to_additive] lemma mul_inf [covariant_class α α (*) (≤)] (a b c : α) : c * (a ⊓ b) = (c * a) ⊓ (c * b) := begin refine le_antisymm (by simp) _, rw [← mul_le_mul_iff_left (c⁻¹), ← mul_assoc, inv_mul_self, one_mul], exact le_inf (by simp) (by simp), end -- Special case of Bourbaki A.VI.9 (2) -- -(a ⊔ b)=(-a) ⊓ (-b) @[to_additive] lemma inv_sup_eq_inv_inf_inv [covariant_class α α (*) (≤)] (a b : α) : (a ⊔ b)⁻¹ = a⁻¹ ⊓ b⁻¹ := begin apply le_antisymm, { refine le_inf _ _, { rw inv_le_inv_iff, exact le_sup_left, }, { rw inv_le_inv_iff, exact le_sup_right, } }, { rw [← inv_le_inv_iff, inv_inv], refine sup_le _ _, { rw ← inv_le_inv_iff, simp, }, { rw ← inv_le_inv_iff, simp, } } end -- -(a ⊓ b) = -a ⊔ -b @[to_additive] lemma inv_inf_eq_sup_inv [covariant_class α α (*) (≤)] (a b : α) : (a ⊓ b)⁻¹ = a⁻¹ ⊔ b⁻¹ := by rw [← inv_inv (a⁻¹ ⊔ b⁻¹), inv_sup_eq_inv_inf_inv a⁻¹ b⁻¹, inv_inv, inv_inv] -- Bourbaki A.VI.10 Prop 7 -- a ⊓ b + (a ⊔ b) = a + b @[to_additive] lemma inf_mul_sup [covariant_class α α (*) (≤)] (a b : α) : (a ⊓ b) * (a ⊔ b) = a * b := calc (a ⊓ b) * (a ⊔ b) = (a ⊓ b) * ((a * b) * (b⁻¹ ⊔ a⁻¹)) : by { rw mul_sup b⁻¹ a⁻¹ (a * b), simp, } ... = (a ⊓ b) * ((a * b) * (a ⊓ b)⁻¹) : by rw [inv_inf_eq_sup_inv, sup_comm] ... = a * b : by rw [mul_comm, inv_mul_cancel_right] namespace lattice_ordered_comm_group /-- Let `α` be a lattice ordered commutative group with identity `1`. For an element `a` of type `α`, the element `a ⊔ 1` is said to be the *positive component* of `a`, denoted `a⁺`. -/ @[to_additive /-" Let `α` be a lattice ordered commutative group with identity `0`. For an element `a` of type `α`, the element `a ⊔ 0` is said to be the *positive component* of `a`, denoted `a⁺`. "-/, priority 100] -- see Note [lower instance priority] instance has_one_lattice_has_pos_part : has_pos_part (α) := ⟨λ a, a ⊔ 1⟩ @[to_additive pos_part_def] lemma m_pos_part_def (a : α) : a⁺ = a ⊔ 1 := rfl /-- Let `α` be a lattice ordered commutative group with identity `1`. For an element `a` of type `α`, the element `(-a) ⊔ 1` is said to be the *negative component* of `a`, denoted `a⁻`. -/ @[to_additive /-" Let `α` be a lattice ordered commutative group with identity `0`. For an element `a` of type `α`, the element `(-a) ⊔ 0` is said to be the *negative component* of `a`, denoted `a⁻`. "-/, priority 100] -- see Note [lower instance priority] instance has_one_lattice_has_neg_part : has_neg_part (α) := ⟨λ a, a⁻¹ ⊔ 1⟩ @[to_additive neg_part_def] lemma m_neg_part_def (a : α) : a⁻ = a⁻¹ ⊔ 1 := rfl @[simp, to_additive] lemma pos_one : (1 : α)⁺ = 1 := sup_idem @[simp, to_additive] lemma neg_one : (1 : α)⁻ = 1 := by rw [m_neg_part_def, inv_one, sup_idem] -- a⁻ = -(a ⊓ 0) @[to_additive] lemma neg_eq_inv_inf_one [covariant_class α α (*) (≤)] (a : α) : a⁻ = (a ⊓ 1)⁻¹ := by rw [m_neg_part_def, ← inv_inj, inv_sup_eq_inv_inf_inv, inv_inv, inv_inv, inv_one] @[to_additive le_abs] lemma le_mabs (a : α) : a ≤ |a| := le_sup_left @[to_additive] -- -a ≤ |a| lemma inv_le_abs (a : α) : a⁻¹ ≤ |a| := le_sup_right -- 0 ≤ a⁺ @[to_additive pos_nonneg] lemma one_le_pos (a : α) : 1 ≤ a⁺ := le_sup_right -- 0 ≤ a⁻ @[to_additive neg_nonneg] lemma one_le_neg (a : α) : 1 ≤ a⁻ := le_sup_right @[to_additive] -- pos_nonpos_iff lemma pos_le_one_iff {a : α} : a⁺ ≤ 1 ↔ a ≤ 1 := by { rw [m_pos_part_def, sup_le_iff], simp, } @[to_additive] -- neg_nonpos_iff lemma neg_le_one_iff {a : α} : a⁻ ≤ 1 ↔ a⁻¹ ≤ 1 := by { rw [m_neg_part_def, sup_le_iff], simp, } @[to_additive] lemma pos_eq_one_iff {a : α} : a⁺ = 1 ↔ a ≤ 1 := by { rw le_antisymm_iff, simp only [one_le_pos, and_true], exact pos_le_one_iff, } @[to_additive] lemma neg_eq_one_iff' {a : α} : a⁻ = 1 ↔ a⁻¹ ≤ 1 := by { rw le_antisymm_iff, simp only [one_le_neg, and_true], rw neg_le_one_iff, } @[to_additive] lemma neg_eq_one_iff [covariant_class α α has_mul.mul has_le.le] {a : α} : a⁻ = 1 ↔ 1 ≤ a := by { rw le_antisymm_iff, simp only [one_le_neg, and_true], rw [neg_le_one_iff, inv_le_one'], } @[to_additive le_pos] lemma m_le_pos (a : α) : a ≤ a⁺ := le_sup_left -- -a ≤ a⁻ @[to_additive] lemma inv_le_neg (a : α) : a⁻¹ ≤ a⁻ := le_sup_left -- Bourbaki A.VI.12 -- a⁻ = (-a)⁺ @[to_additive] lemma neg_eq_pos_inv (a : α) : a⁻ = (a⁻¹)⁺ := rfl -- a⁺ = (-a)⁻ @[to_additive] lemma pos_eq_neg_inv (a : α) : a⁺ = (a⁻¹)⁻ := by simp [neg_eq_pos_inv] -- We use this in Bourbaki A.VI.12 Prop 9 a) -- c + (a ⊓ b) = (c + a) ⊓ (c + b) @[to_additive] lemma mul_inf_eq_mul_inf_mul [covariant_class α α (*) (≤)] (a b c : α) : c * (a ⊓ b) = (c * a) ⊓ (c * b) := begin refine le_antisymm (by simp) _, rw [← mul_le_mul_iff_left c⁻¹, ← mul_assoc, inv_mul_self, one_mul, le_inf_iff], simp, end -- Bourbaki A.VI.12 Prop 9 a) -- a = a⁺ - a⁻ @[simp, to_additive] lemma pos_div_neg [covariant_class α α (*) (≤)] (a : α) : a⁺ / a⁻ = a := begin symmetry, rw div_eq_mul_inv, apply eq_mul_inv_of_mul_eq, rw [m_neg_part_def, mul_sup, mul_one, mul_right_inv, sup_comm, m_pos_part_def], end -- Bourbaki A.VI.12 Prop 9 a) -- a⁺ ⊓ a⁻ = 0 (`a⁺` and `a⁻` are co-prime, and, since they are positive, disjoint) @[to_additive] lemma pos_inf_neg_eq_one [covariant_class α α (*) (≤)] (a : α) : a⁺ ⊓ a⁻ = 1 := by rw [←mul_right_inj (a⁻)⁻¹, mul_inf_eq_mul_inf_mul, mul_one, mul_left_inv, mul_comm, ← div_eq_mul_inv, pos_div_neg, neg_eq_inv_inf_one, inv_inv] -- Bourbaki A.VI.12 (with a and b swapped) -- a⊔b = b + (a - b)⁺ @[to_additive] lemma sup_eq_mul_pos_div [covariant_class α α (*) (≤)] (a b : α) : a ⊔ b = b * (a / b)⁺ := calc a ⊔ b = (b * (a / b)) ⊔ (b * 1) : by rw [mul_one b, div_eq_mul_inv, mul_comm a, mul_inv_cancel_left] ... = b * ((a / b) ⊔ 1) : by rw ← mul_sup (a / b) 1 b -- Bourbaki A.VI.12 (with a and b swapped) -- a⊓b = a - (a - b)⁺ @[to_additive] lemma inf_eq_div_pos_div [covariant_class α α (*) (≤)] (a b : α) : a ⊓ b = a / (a / b)⁺ := calc a ⊓ b = (a * 1) ⊓ (a * (b / a)) : by { rw [mul_one a, div_eq_mul_inv, mul_comm b, mul_inv_cancel_left], } ... = a * (1 ⊓ (b / a)) : by rw ← mul_inf_eq_mul_inf_mul 1 (b / a) a ... = a * ((b / a) ⊓ 1) : by rw inf_comm ... = a * ((a / b)⁻¹ ⊓ 1) : by { rw div_eq_mul_inv, nth_rewrite 0 ← inv_inv b, rw [← mul_inv, mul_comm b⁻¹, ← div_eq_mul_inv], } ... = a * ((a / b)⁻¹ ⊓ 1⁻¹) : by rw inv_one ... = a / ((a / b) ⊔ 1) : by rw [← inv_sup_eq_inv_inf_inv, ← div_eq_mul_inv] -- Bourbaki A.VI.12 Prop 9 c) @[to_additive le_iff_pos_le_neg_ge] lemma m_le_iff_pos_le_neg_ge [covariant_class α α (*) (≤)] (a b : α) : a ≤ b ↔ a⁺ ≤ b⁺ ∧ b⁻ ≤ a⁻ := begin split; intro h, { split, { exact sup_le (h.trans (m_le_pos b)) (one_le_pos b), }, { rw ← inv_le_inv_iff at h, exact sup_le (h.trans (inv_le_neg a)) (one_le_neg a), } }, { rw [← pos_div_neg a, ← pos_div_neg b], exact div_le_div'' h.1 h.2, } end @[to_additive neg_abs] lemma m_neg_abs [covariant_class α α (*) (≤)] (a : α) : |a|⁻ = 1 := begin refine le_antisymm _ _, { rw ← pos_inf_neg_eq_one a, apply le_inf, { rw pos_eq_neg_inv, exact ((m_le_iff_pos_le_neg_ge _ _).mp (inv_le_abs a)).right, }, { exact and.right (iff.elim_left (m_le_iff_pos_le_neg_ge _ _) (le_mabs a)), } }, { exact one_le_neg _, } end @[to_additive pos_abs] lemma m_pos_abs [covariant_class α α (*) (≤)] (a : α) : |a|⁺ = |a| := begin nth_rewrite 1 ← pos_div_neg (|a|), rw div_eq_mul_inv, symmetry, rw [mul_right_eq_self, inv_eq_one], exact m_neg_abs a, end @[to_additive abs_nonneg] lemma one_le_abs [covariant_class α α (*) (≤)] (a : α) : 1 ≤ |a| := by { rw ← m_pos_abs, exact one_le_pos _, } -- The proof from Bourbaki A.VI.12 Prop 9 d) -- |a| = a⁺ - a⁻ @[to_additive] lemma pos_mul_neg [covariant_class α α (*) (≤)] (a : α) : |a| = a⁺ * a⁻ := begin refine le_antisymm _ _, { refine sup_le _ _, { nth_rewrite 0 ← mul_one a, exact mul_le_mul' (m_le_pos a) (one_le_neg a) }, { nth_rewrite 0 ← one_mul (a⁻¹), exact mul_le_mul' (one_le_pos a) (inv_le_neg a) } }, { rw [← inf_mul_sup, pos_inf_neg_eq_one, one_mul, ← m_pos_abs a], apply sup_le, { exact ((m_le_iff_pos_le_neg_ge _ _).mp (le_mabs a)).left, }, { rw neg_eq_pos_inv, exact ((m_le_iff_pos_le_neg_ge _ _).mp (inv_le_abs a)).left, }, } end -- a ⊔ b - (a ⊓ b) = |b - a| @[to_additive] lemma sup_div_inf_eq_abs_div [covariant_class α α (*) (≤)] (a b : α) : (a ⊔ b) / (a ⊓ b) = |b / a| := begin rw [sup_eq_mul_pos_div, inf_comm, inf_eq_div_pos_div, div_eq_mul_inv], nth_rewrite 1 div_eq_mul_inv, rw [mul_inv_rev, inv_inv, mul_comm, ← mul_assoc, inv_mul_cancel_right, pos_eq_neg_inv (a / b)], nth_rewrite 1 div_eq_mul_inv, rw [mul_inv_rev, ← div_eq_mul_inv, inv_inv, ← pos_mul_neg], end -- 2•(a ⊔ b) = a + b + |b - a| @[to_additive two_sup_eq_add_add_abs_sub] lemma sup_sq_eq_mul_mul_abs_div [covariant_class α α (*) (≤)] (a b : α) : (a ⊔ b)^2 = a * b * |b / a| := by rw [← inf_mul_sup a b, ← sup_div_inf_eq_abs_div, div_eq_mul_inv, ← mul_assoc, mul_comm, mul_assoc, ← pow_two, inv_mul_cancel_left] -- 2•(a ⊓ b) = a + b - |b - a| @[to_additive two_inf_eq_add_sub_abs_sub] lemma inf_sq_eq_mul_div_abs_div [covariant_class α α (*) (≤)] (a b : α) : (a ⊓ b)^2 = a * b / |b / a| := by rw [← inf_mul_sup a b, ← sup_div_inf_eq_abs_div, div_eq_mul_inv, div_eq_mul_inv, mul_inv_rev, inv_inv, mul_assoc, mul_inv_cancel_comm_assoc, ← pow_two] /-- Every lattice ordered commutative group is a distributive lattice -/ @[to_additive "Every lattice ordered commutative additive group is a distributive lattice" ] def lattice_ordered_comm_group_to_distrib_lattice (α : Type u) [s: lattice α] [comm_group α] [covariant_class α α (*) (≤)] : distrib_lattice α := { le_sup_inf := begin intros, rw [← mul_le_mul_iff_left (x ⊓ (y ⊓ z)), inf_mul_sup x (y ⊓ z), ← inv_mul_le_iff_le_mul, le_inf_iff], split, { rw [inv_mul_le_iff_le_mul, ← inf_mul_sup x y], apply mul_le_mul', { apply inf_le_inf_left, apply inf_le_left, }, { apply inf_le_left, } }, { rw [inv_mul_le_iff_le_mul, ← inf_mul_sup x z], apply mul_le_mul', { apply inf_le_inf_left, apply inf_le_right, }, { apply inf_le_right, }, } end, ..s } -- See, e.g. Zaanen, Lectures on Riesz Spaces -- 3rd lecture -- |a ⊔ c - (b ⊔ c)| + |a ⊓ c-b ⊓ c| = |a - b| @[to_additive] theorem abs_div_sup_mul_abs_div_inf [covariant_class α α (*) (≤)] (a b c : α) : |(a ⊔ c) / (b ⊔ c)| * |(a ⊓ c) / (b ⊓ c)| = |a / b| := begin letI : distrib_lattice α := lattice_ordered_comm_group_to_distrib_lattice α, calc |(a ⊔ c) / (b ⊔ c)| * |(a ⊓ c) / (b ⊓ c)| = ((b ⊔ c ⊔ (a ⊔ c)) / ((b ⊔ c) ⊓ (a ⊔ c))) * |(a ⊓ c) / (b ⊓ c)| : by rw sup_div_inf_eq_abs_div ... = (b ⊔ c ⊔ (a ⊔ c)) / ((b ⊔ c) ⊓ (a ⊔ c)) * (((b ⊓ c) ⊔ (a ⊓ c)) / ((b ⊓ c) ⊓ (a ⊓ c))) : by rw sup_div_inf_eq_abs_div (b ⊓ c) (a ⊓ c) ... = (b ⊔ a ⊔ c) / ((b ⊓ a) ⊔ c) * (((b ⊔ a) ⊓ c) / (b ⊓ a ⊓ c)) : by { rw [← sup_inf_right, ← inf_sup_right, sup_assoc], nth_rewrite 1 sup_comm, rw [sup_right_idem, sup_assoc, inf_assoc], nth_rewrite 3 inf_comm, rw [inf_right_idem, inf_assoc], } ... = (b ⊔ a ⊔ c) * ((b ⊔ a) ⊓ c) /(((b ⊓ a) ⊔ c) * (b ⊓ a ⊓ c)) : by rw div_mul_div_comm ... = (b ⊔ a) * c / ((b ⊓ a) * c) : by rw [mul_comm, inf_mul_sup, mul_comm (b ⊓ a ⊔ c), inf_mul_sup] ... = (b ⊔ a) / (b ⊓ a) : by rw [div_eq_mul_inv, mul_inv_rev, mul_assoc, mul_inv_cancel_left, ← div_eq_mul_inv] ... = |a / b| : by rw sup_div_inf_eq_abs_div end /-- If `a` is positive, then it is equal to its positive component `a⁺`. -/ -- pos_of_nonneg @[to_additive "If `a` is positive, then it is equal to its positive component `a⁺`."] lemma pos_of_one_le (a : α) (h : 1 ≤ a) : a⁺ = a := by { rw m_pos_part_def, exact sup_of_le_left h, } -- 0 ≤ a implies a⁺ = a @[to_additive] -- pos_of_nonpos lemma pos_of_le_one (a : α) (h : a ≤ 1) : a⁺ = 1 := pos_eq_one_iff.mpr h @[to_additive neg_of_inv_nonneg] lemma neg_of_one_le_inv (a : α) (h : 1 ≤ a⁻¹) : a⁻ = a⁻¹ := by { rw neg_eq_pos_inv, exact pos_of_one_le _ h, } @[to_additive] -- neg_of_neg_nonpos lemma neg_of_inv_le_one (a : α) (h : a⁻¹ ≤ 1) : a⁻ = 1 := neg_eq_one_iff'.mpr h @[to_additive] -- neg_of_nonpos lemma neg_of_le_one [covariant_class α α (*) (≤)] (a : α) (h : a ≤ 1) : a⁻ = a⁻¹ := by { refine neg_of_one_le_inv _ _, rw one_le_inv', exact h, } @[to_additive] -- neg_of_nonneg' lemma neg_of_one_le [covariant_class α α (*) (≤)] (a : α) (h : 1 ≤ a) : a⁻ = 1 := neg_eq_one_iff.mpr h -- 0 ≤ a implies |a| = a @[to_additive abs_of_nonneg] lemma mabs_of_one_le [covariant_class α α (*) (≤)] (a : α) (h : 1 ≤ a) : |a| = a := begin unfold has_abs.abs, rw [sup_eq_mul_pos_div, div_eq_mul_inv, inv_inv, ← pow_two, inv_mul_eq_iff_eq_mul, ← pow_two, pos_of_one_le], rw pow_two, apply one_le_mul h h, end /-- The unary operation of taking the absolute value is idempotent. -/ @[simp, to_additive abs_abs "The unary operation of taking the absolute value is idempotent."] lemma mabs_mabs [covariant_class α α (*) (≤)] (a : α) : | |a| | = |a| := mabs_of_one_le _ (one_le_abs _) @[to_additive abs_sup_sub_sup_le_abs] lemma mabs_sup_div_sup_le_mabs [covariant_class α α (*) (≤)] (a b c : α) : |(a ⊔ c) / (b ⊔ c)| ≤ |a / b| := begin apply le_of_mul_le_of_one_le_left, { rw abs_div_sup_mul_abs_div_inf, }, { exact one_le_abs _, }, end @[to_additive abs_inf_sub_inf_le_abs] lemma mabs_inf_div_inf_le_mabs [covariant_class α α (*) (≤)] (a b c : α) : |(a ⊓ c) / (b ⊓ c)| ≤ |a / b| := begin apply le_of_mul_le_of_one_le_right, { rw abs_div_sup_mul_abs_div_inf, }, { exact one_le_abs _, }, end -- Commutative case, Zaanen, 3rd lecture -- For the non-commutative case, see Birkhoff Theorem 19 (27) -- |(a ⊔ c) - (b ⊔ c)| ⊔ |(a ⊓ c) - (b ⊓ c)| ≤ |a - b| @[to_additive Birkhoff_inequalities] theorem m_Birkhoff_inequalities [covariant_class α α (*) (≤)] (a b c : α) : |(a ⊔ c) / (b ⊔ c)| ⊔ |(a ⊓ c) / (b ⊓ c)| ≤ |a / b| := sup_le (mabs_sup_div_sup_le_mabs a b c) (mabs_inf_div_inf_le_mabs a b c) -- Banasiak Proposition 2.12, Zaanen 2nd lecture /-- The absolute value satisfies the triangle inequality. -/ @[to_additive abs_add_le] lemma mabs_mul_le [covariant_class α α (*) (≤)] (a b : α) : |a * b| ≤ |a| * |b| := begin apply sup_le, { exact mul_le_mul' (le_mabs a) (le_mabs b), }, { rw mul_inv, exact mul_le_mul' (inv_le_abs _) (inv_le_abs _), } end -- |a - b| = |b - a| @[to_additive] lemma abs_inv_comm (a b : α) : |a/b| = |b/a| := begin unfold has_abs.abs, rw [inv_div a b, ← inv_inv (a / b), inv_div, sup_comm], end -- | |a| - |b| | ≤ |a - b| @[to_additive] lemma abs_abs_div_abs_le [covariant_class α α (*) (≤)] (a b : α) : | |a| / |b| | ≤ |a / b| := begin unfold has_abs.abs, rw sup_le_iff, split, { apply div_le_iff_le_mul.2, convert mabs_mul_le (a/b) b, { rw div_mul_cancel', }, { rw div_mul_cancel', }, { exact covariant_swap_mul_le_of_covariant_mul_le α, } }, { rw [div_eq_mul_inv, mul_inv_rev, inv_inv, mul_inv_le_iff_le_mul, ← abs_eq_sup_inv (a / b), abs_inv_comm], convert mabs_mul_le (b/a) a, { rw div_mul_cancel', }, {rw div_mul_cancel', } }, end end lattice_ordered_comm_group
a0e73c29700dd4f3b7565a22f8413e19049007be
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/group_theory/double_coset.lean
f7a35dcafbaee65819335c4f5fbce1d80a1080cf
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
7,717
lean
/- Copyright (c) 2021 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck -/ import data.setoid.basic import group_theory.subgroup.basic import group_theory.coset import group_theory.subgroup.pointwise import data.set.basic import tactic.group /-! # Double cosets > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file defines double cosets for two subgroups `H K` of a group `G` and the quotient of `G` by the double coset relation, i.e. `H \ G / K`. We also prove that `G` can be writen as a disjoint union of the double cosets and that if one of `H` or `K` is the trivial group (i.e. `⊥` ) then this is the usual left or right quotient of a group by a subgroup. ## Main definitions * `rel`: The double coset relation defined by two subgroups `H K` of `G`. * `double_coset.quotient`: The quotient of `G` by the double coset relation, i.e, ``H \ G / K`. -/ variables {G : Type*} [group G] {α : Type*} [has_mul α] (J: subgroup G) (g : G) namespace doset open_locale pointwise /--The double_coset as an element of `set α` corresponding to `s a t` -/ def _root_.doset (a : α) (s t : set α) : set α := s * {a} * t lemma mem_doset {s t : set α} {a b : α} : b ∈ doset a s t ↔ ∃ (x ∈ s) (y ∈ t), b = x * a * y := ⟨λ ⟨_, y, ⟨x, _, hx, rfl, rfl⟩, hy, h⟩, ⟨x, hx, y, hy, h.symm⟩, λ ⟨x, hx, y, hy, h⟩, ⟨x * a, y, ⟨x, a, hx, rfl, rfl⟩, hy, h.symm⟩⟩ lemma mem_doset_self (H K : subgroup G) (a : G) : a ∈ doset a H K := mem_doset.mpr ⟨1, H.one_mem, 1, K.one_mem, (one_mul a).symm.trans (mul_one (1 * a)).symm⟩ lemma doset_eq_of_mem {H K : subgroup G} {a b : G} (hb : b ∈ doset a H K) : doset b H K = doset a H K := begin obtain ⟨_, k, ⟨h, a, hh, (rfl : _ = _), rfl⟩, hk, rfl⟩ := hb, rw [doset, doset, ←set.singleton_mul_singleton, ←set.singleton_mul_singleton, mul_assoc, mul_assoc, subgroup.singleton_mul_subgroup hk, ←mul_assoc, ←mul_assoc, subgroup.subgroup_mul_singleton hh], end lemma mem_doset_of_not_disjoint {H K : subgroup G} {a b : G} (h : ¬ disjoint (doset a H K) (doset b H K)) : b ∈ doset a H K := begin rw set.not_disjoint_iff at h, simp only [mem_doset] at *, obtain ⟨x, ⟨l, hl, r, hr, hrx⟩, y, hy, ⟨r', hr', rfl⟩⟩ := h, refine ⟨y⁻¹ * l, H.mul_mem (H.inv_mem hy) (hl), r * r'⁻¹, K.mul_mem hr (K.inv_mem hr'), _⟩, rwa [mul_assoc, mul_assoc, eq_inv_mul_iff_mul_eq, ←mul_assoc, ←mul_assoc, eq_mul_inv_iff_mul_eq], end lemma eq_of_not_disjoint {H K : subgroup G} {a b : G} (h: ¬ disjoint (doset a H K) (doset b H K)) : doset a H K = doset b H K := begin rw disjoint.comm at h, have ha : a ∈ doset b H K := mem_doset_of_not_disjoint h, apply doset_eq_of_mem ha, end /-- The setoid defined by the double_coset relation -/ def setoid (H K : set G) : setoid G := setoid.ker (λ x, doset x H K) /-- Quotient of `G` by the double coset relation, i.e. `H \ G / K` -/ def quotient (H K : set G) : Type* := quotient (setoid H K) lemma rel_iff {H K : subgroup G} {x y : G} : (setoid ↑H ↑K).rel x y ↔ ∃ (a ∈ H) (b ∈ K), y = a * x * b := iff.trans ⟨λ hxy, (congr_arg _ hxy).mpr (mem_doset_self H K y), λ hxy, (doset_eq_of_mem hxy).symm⟩ mem_doset lemma bot_rel_eq_left_rel (H : subgroup G) : (setoid ↑(⊥ : subgroup G) ↑H).rel = (quotient_group.left_rel H).rel := begin ext a b, rw [rel_iff, setoid.rel, quotient_group.left_rel_apply], split, { rintros ⟨a, (rfl : a = 1), b, hb, rfl⟩, change a⁻¹ * (1 * a * b) ∈ H, rwa [one_mul, inv_mul_cancel_left] }, { rintro (h : a⁻¹ * b ∈ H), exact ⟨1, rfl, a⁻¹ * b, h, by rw [one_mul, mul_inv_cancel_left]⟩ }, end lemma rel_bot_eq_right_group_rel (H : subgroup G) : (setoid ↑H ↑(⊥ : subgroup G)).rel = (quotient_group.right_rel H).rel := begin ext a b, rw [rel_iff, setoid.rel, quotient_group.right_rel_apply], split, { rintros ⟨b, hb, a, (rfl : a = 1), rfl⟩, change b * a * 1 * a⁻¹ ∈ H, rwa [mul_one, mul_inv_cancel_right] }, { rintro (h : b * a⁻¹ ∈ H), exact ⟨b * a⁻¹, h, 1, rfl, by rw [mul_one, inv_mul_cancel_right]⟩ }, end /--Create a doset out of an element of `H \ G / K`-/ def quot_to_doset (H K : subgroup G) (q : quotient ↑H ↑K) : set G := (doset q.out' H K) /--Map from `G` to `H \ G / K`-/ abbreviation mk (H K : subgroup G) (a : G) : quotient ↑H ↑K := quotient.mk' a instance (H K : subgroup G) : inhabited (quotient ↑H ↑K) := ⟨mk H K (1 : G)⟩ lemma eq (H K : subgroup G) (a b : G) : mk H K a = mk H K b ↔ ∃ (h ∈ H) (k ∈ K), b = h * a * k := by { rw quotient.eq', apply rel_iff, } lemma out_eq' (H K : subgroup G) (q : quotient ↑H ↑K) : mk H K q.out' = q := quotient.out_eq' q lemma mk_out'_eq_mul (H K : subgroup G) (g : G) : ∃ (h k : G), (h ∈ H) ∧ (k ∈ K) ∧ (mk H K g : quotient ↑H ↑K).out' = h * g * k := begin have := eq H K (mk H K g : quotient ↑H ↑K).out' g, rw out_eq' at this, obtain ⟨h, h_h, k, hk, T⟩ := this.1 rfl, refine ⟨h⁻¹, k⁻¹, (H.inv_mem h_h), K.inv_mem hk, eq_mul_inv_of_mul_eq (eq_inv_mul_of_mul_eq _)⟩, rw [← mul_assoc, ← T] end lemma mk_eq_of_doset_eq {H K : subgroup G} {a b : G} (h : doset a H K = doset b H K) : mk H K a = mk H K b := begin rw eq, exact mem_doset.mp (h.symm ▸ mem_doset_self H K b) end lemma disjoint_out' {H K : subgroup G} {a b : quotient H.1 K} : a ≠ b → disjoint (doset a.out' H K) (doset b.out' H K) := begin contrapose!, intro h, simpa [out_eq'] using mk_eq_of_doset_eq (eq_of_not_disjoint h), end lemma union_quot_to_doset (H K : subgroup G) : (⋃ q, quot_to_doset H K q) = set.univ := begin ext x, simp only [set.mem_Union, quot_to_doset, mem_doset, set_like.mem_coe, exists_prop, set.mem_univ, iff_true], use mk H K x, obtain ⟨h, k, h3, h4, h5⟩ := mk_out'_eq_mul H K x, refine ⟨h⁻¹, H.inv_mem h3, k⁻¹, K.inv_mem h4, _⟩, simp only [h5, subgroup.coe_mk, ←mul_assoc, one_mul, mul_left_inv, mul_inv_cancel_right], end lemma doset_union_right_coset (H K : subgroup G) (a : G) : (⋃ (k : K), right_coset ↑H (a * k)) = doset a H K := begin ext x, simp only [mem_right_coset_iff, exists_prop, mul_inv_rev, set.mem_Union, mem_doset, subgroup.mem_carrier, set_like.mem_coe], split, {rintro ⟨y, h_h⟩, refine ⟨x * (y⁻¹ * a⁻¹), h_h, y, y.2, _⟩, simp only [← mul_assoc, subgroup.coe_mk, inv_mul_cancel_right]}, {rintros ⟨x, hx, y, hy, hxy⟩, refine ⟨⟨y,hy⟩,_⟩, simp only [hxy, ←mul_assoc, hx, mul_inv_cancel_right, subgroup.coe_mk]}, end lemma doset_union_left_coset (H K : subgroup G) (a : G) : (⋃ (h : H), left_coset (h * a : G) K) = doset a H K := begin ext x, simp only [mem_left_coset_iff, mul_inv_rev, set.mem_Union, mem_doset], split, { rintro ⟨y, h_h⟩, refine ⟨y, y.2, a⁻¹ * y⁻¹ * x, h_h, _⟩, simp only [←mul_assoc, one_mul, mul_right_inv, mul_inv_cancel_right]}, { rintros ⟨x, hx, y, hy, hxy⟩, refine ⟨⟨x, hx⟩, _⟩, simp only [hxy, ←mul_assoc, hy, one_mul, mul_left_inv, subgroup.coe_mk, inv_mul_cancel_right]}, end lemma left_bot_eq_left_quot (H : subgroup G) : quotient (⊥ : subgroup G).1 H = (G ⧸ H) := begin unfold quotient, congr, ext, simp_rw ← bot_rel_eq_left_rel H, refl, end lemma right_bot_eq_right_quot (H : subgroup G) : quotient H.1 (⊥ : subgroup G) = _root_.quotient (quotient_group.right_rel H) := begin unfold quotient, congr, ext, simp_rw ← rel_bot_eq_right_group_rel H, refl, end end doset
b216101f7c7e6b2cccb5e6330377f1a5331c42dd
842b7df4a999c5c50bbd215b8617dd705e43c2e1
/nat_num_game/src/Advanced_Addition_World/adv_add_wrld11.lean
b6c4472c6f51390ba2fd470b3300c3b91fa581b4
[]
no_license
Samyak-Surti/LeanCode
1c245631f74b00057d20483c8ac75916e8643b14
944eac3e5f43e2614ed246083b97fbdf24181d83
refs/heads/master
1,669,023,730,828
1,595,534,784,000
1,595,534,784,000
282,037,186
0
0
null
null
null
null
UTF-8
Lean
false
false
191
lean
lemma add_right_eq_zero {a b : ℕ} : a + b = 0 → a = 0 := begin intro H, cases a with d, refl, rw nat.succ_add at H, exfalso, apply nat.succ_ne_zero (d + b) H, end
11601cdf83f39c9dc09758a0b6a4ec21c184bcc7
70146ae0f22e89882c6c6fe6db4b2f0122ccbfe2
/BalanceCar.lean
5001b0425c48b368cf5c8bac0c4e779a2a0a229a
[]
no_license
zeta1999/lean4-balance-car
333b1e797d1c7724a908cd942d7c0e6c928a39f8
1fe9c469c37bbd74cf2de1f3175e64344a6d1786
refs/heads/main
1,679,429,742,377
1,616,018,798,000
1,616,018,798,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
18,743
lean
-- The control portion of the code is more-or-less a functional port of balance car code -- that was distributed with the balance car kit we purchased on Amazon: -- Yahboom Coding Robot Car Balance Robot Electronics Programmable Kit for Adult Support C Language (UNO R3 Include) -- It appears an _updated_ version of that code has since been posted by the company on Github here: -- https://github.com/YahboomTechnology/Arduino-Balance-Car -- This code resembles other similar balance car project code that can be found on the web, e.g.: -- https://create.arduino.cc/projecthub/gunjalsuyog/phpoc-arduino-self-balancing-robot-with-bt-web-control-0afab9 import Lean.Data.Json namespace Float instance : Coe Int Float := ⟨Float.ofInt⟩ @[macroInline] def constrain (n low high : Float) : Float := if n < low then low else if n > high then high else n def pi : Float := 3.141592653589793238462643 @[extern "fabs"] constant abs : Float → Float end Float /-- Common baud rates for serial ports. -/ inductive BaudRate | bps1200 | bps2400 | bps4800 | bps9600 | bps19200 | bps38400 | bps57600 | bps115200 namespace BaudRate /-- Converts a BaudRate into the uint16 value it is defined as in C (i.e., see the C `speed_t` type and associated C macros). -/ def toUInt16 : BaudRate → UInt16 | bps1200 => 9 -- 0000011 | bps2400 => 11 -- 0000013 | bps4800 => 12 -- 0000014 | bps9600 => 13 -- 0000015 | bps19200 => 14 -- 0000016 | bps38400 => 15 -- 0000017 | bps57600 => 4097 -- 0010001 | bps115200 => 4098 -- 0010002 def ofNat? : Nat → Option BaudRate | 1200 => some bps1200 | 2400 => some bps2400 | 4800 => some bps4800 | 9600 => some bps9600 | 19200 => some bps19200 | 38400 => some bps38400 | 57600 => some bps57600 | 115200 => some bps115200 | _ => none end BaudRate -- Arduino related constants def pin1 : UInt8 := 1 def pin2 : UInt8 := 2 def pin3 : UInt8 := 3 def pin4 : UInt8 := 4 def pinPWMA : UInt8 := 5 def pinPWMB : UInt8 := 6 -- Some car-related constants def qAngle : Float := 0.001 def qGyro : Float := 0.005 def rAngle : Float := 0.5 def p0 : Float := 0.0 -- Angle balance point def c0 : Float := 1 def k1 : Float := 0.05 def angle0 : Float := 0 -- Mechanical balance angle def sampleIntervalMs : Float := 5 -- was timeChange def dt : Float := sampleIntervalMs * 0.001 def kp : Float := 38.0 def kd : Float := 0.58 def kpTurn : Float := 28.0 def kdTurn : Float := 0.29 def kpSpeed : Float := 3.1 def kiSpeed : Float := 0.05 def kdSpeed : Float := 0.0 structure Controller where forward : Int -- Forward variable reverse : Int -- Back variable turnLeft : Bool -- Turn left sign turnRight : Bool -- Turn right sign spinLeft : Bool -- Rotate left sign spinRight : Bool -- Right rotation sign -- See also https://github.com/TKJElectronics/KalmanFilter/blob/master/Kalman.cpp -- for a... cleaner setup than the one we're mirroring at the moment structure BalanceCar where ctrl : Controller countLeft : Int countRight : Int pulseLeft : Int pulseRight : Int stopLeft : Int stopRight : Int angleOut : Float pwm1 : Float pwm2 : Float speedFilter : Float positions : Float resetPosition : Bool turnSpinDelay : Nat turnMax : Int turnMin : Int turnOut : Float speedPI : Float -- calculated by `updateSpeedPI` turnSpin : Float -- calculated by `updateTurnSpin` speedPIDelay : Nat gyroX : Float gyroY : Float gyroZ : Float (angle angle6 qBias angleDot : Float) p00 : Float p01 : Float p10 : Float p11 : Float -- ^ Posteriori estimate covariance matrix for the Kalman filter, -- represented as a pair of matrix rows (where each row is also a pair) pDot0 : Float pDot1 : Float pDot2 : Float pDot3 : Float def Controller.initial : Controller := ⟨0,0,false,false,false,false⟩ namespace BalanceCar -- Kalman Filter def kFilter (car : BalanceCar) (angleM gyroM : Float) : BalanceCar := do let mut car := car car := {car with angle := car.angle + (gyroM - car.qBias) * dt} let angleErr : Float := angleM - car.angle car := {car with pDot0 := qAngle - car.p01 - car.p10} car := {car with pDot1 := - car.p11} car := {car with pDot2 := - car.p11} car := {car with pDot3 := qGyro} car := {car with p00 := car.p00 + car.pDot0 * dt} car := {car with p01 := car.p01 + car.pDot1 * dt} car := {car with p10 := car.p10 + car.pDot2 * dt} car := {car with p11 := car.p11 + car.pDot3 * dt} let PCt_0 : Float := c0 * car.p00 let PCt_1 : Float := c0 * car.p10 let E : Float := rAngle + c0 * PCt_0 let K_0 : Float := PCt_0 / E let K_1 : Float := PCt_1 / E let t_1 : Float := c0 * car.p01 car := {car with p00 := car.p00 - K_0 * PCt_0} car := {car with p01 := car.p01 - K_0 * t_1} car := {car with p10 := car.p10 - K_1 * PCt_0} car := {car with p11 := car.p11 - K_1 * t_1} car := {car with angle := car.angle + K_0 * angleErr} -- optimal angle car := {car with qBias := car.qBias + K_1 * angleErr} car := {car with angleDot := gyroM - car.qBias} car def angleTest (car : BalanceCar) (ax ay az gx gy gz : Int) : BalanceCar := do let mut car := car let angle := (Float.atan2 ay az) * 57.3 car := {car with gyroX := ((Float.ofInt gx) - 128.1) / 131.0} car := car.kFilter angle car.gyroX let gz : Int := if (gz > 32768) then gz - 65536 else gz let angleAx : Float := (Float.atan2 ax az) * 180.0 / Float.pi car := {car with gyroY := Float.div (-gy) 131.0} car := {car with gyroZ := Float.div (-gz) 131.0} car := {car with angle6 := k1 * angleAx + (1 - k1) * (car.angle6 + car.gyroY * dt)} car -- 50ms speed loop control delay def speedPIDelayCount : Nat := 10 -- every 10ms, enter rotation control def turnSpinDelayCount : Nat := 2 def initial : BalanceCar := { ctrl := Controller.initial, countLeft := 0, countRight := 0, pulseLeft := 0, pulseRight := 0, stopLeft := 0, stopRight := 0, angleOut := 0, pwm1 := 0, pwm2 := 0, speedFilter := 0, positions := 0, turnSpinDelay := turnSpinDelayCount, turnMax := 0, turnMin := 0, turnOut := 0, resetPosition := false, speedPI := 0, turnSpin := 0, speedPIDelay := speedPIDelayCount, gyroX := 0, gyroY := 0, gyroZ := 0, angle := 0, angle6 := 0, qBias := 0, angleDot := 0, p00 := 1, p01 := 0, p10 := 0, p11 := 1, pDot0 := 0, pDot1 := 0, pDot2 := 0, pDot3 := 0 } -- Update cars speed PI (Proportional Integral) def updateSpeedPI (car : BalanceCar) : BalanceCar := do let mut car := car let speeds : Float := Float.ofInt (car.pulseLeft + car.pulseRight) car := {car with pulseLeft := 0, pulseRight := 0} car := {car with speedFilter := car.speedFilter * 0.7 + speeds * 0.3} car := {car with positions := car.positions + car.speedFilter + car.ctrl.forward + car.ctrl.reverse} car := {car with positions := Float.constrain car.positions (-3550) 3550} car := {car with speedPI := kiSpeed * (p0 - car.positions) + kpSpeed * (p0 - car.speedFilter)} car := {car with positions := if car.resetPosition then 0 else car.positions} car def updateTurnSpin (car : BalanceCar) : BalanceCar := do let mut car := car let mut turnSpeed : Float := 0 let mut rotationRatio : Float := 0 if (car.ctrl.turnLeft || car.ctrl.turnRight || car.ctrl.spinLeft || car.ctrl.spinRight) then do -- Judge the current speed before rotating to enhance the adaptability of the car. turnSpeed := Float.ofInt (car.pulseRight + car.pulseLeft) if (turnSpeed < 0) then do turnSpeed := -turnSpeed if (car.ctrl.turnLeft || car.ctrl.turnRight) then do car := {car with turnMax := 3} car := {car with turnMin := -3} if (car.ctrl.spinLeft || car.ctrl.spinRight) then do car := {car with turnMax := 10} car := {car with turnMin := -10} rotationRatio := Float.constrain (5.0 / turnSpeed) 0.5 5.0 else do rotationRatio := 0.5 if (car.ctrl.turnLeft || car.ctrl.spinLeft) then do car := {car with turnOut := car.turnOut + rotationRatio} else if (car.ctrl.turnRight|| car.ctrl.spinRight) then do car := {car with turnOut := car.turnOut - rotationRatio} else do car := {car with turnOut := 0} car := {car with turnOut := Float.constrain car.turnOut car.turnMin car.turnMax} car := {car with turnSpin := (- car.turnOut) * kpTurn - car.gyroZ * kdTurn} car -- speedoutput and rotationoutput are values on the BalanceCar (speedPI and turnSpin) def pwma (car : BalanceCar) : BalanceCar := do let mut car := car -- Left motor PWM output value car := {car with pwm1 := Float.constrain ((- car.angleOut) - car.speedPI - car.turnSpin) (-255) 255} -- Right motor PWM output value car := {car with pwm2 := Float.constrain ((- car.angleOut) - car.speedPI + car.turnSpin) (-255) 255} if car.angle > 30.0 || car.angle < (Float.neg 30.0) then do -- If the angle is too large, stop the motor car := {car with pwm1 := 0} car := {car with pwm2 := 0} if (car.angle6 > 10 || car.angle6 < -10) && !car.ctrl.turnLeft && !car.ctrl.turnRight && !car.ctrl.spinLeft && !car.ctrl.spinRight && car.ctrl.forward == 0 && car.ctrl.reverse == 0 then if car.stopLeft + car.stopRight > 1500 || car.stopLeft + car.stopRight < -3500 then do car := {car with pwm1 := 0} car := {car with pwm2 := 0} car := {car with resetPosition := true} else do car := {car with stopLeft := 0} car := {car with stopRight := 0} car := {car with resetPosition := false} car def countPulse (car : BalanceCar) : BalanceCar := do let mut car := car let mut pulseLeft := car.countLeft let mut pulseRight := car.countRight car := {car with countLeft := 0, countRight := 0} if (car.pwm1 < 0.0) && (car.pwm2 < 0.0) then do -- Judgment of the direction of movement of the trolley. -- When moving backwards (PWM means the motor voltage is negative), -- the number of pulses is negative. pulseRight := -pulseRight pulseLeft := -pulseLeft else if (car.pwm1 < 0.0) && (car.pwm2 > 0.0) then do -- Judgment of the direction of movement of the trolley. -- When moving forward (PWM, that is, the motor voltage is -- positive), the number of pulses is negative. pulseLeft := -pulseLeft else if (car.pwm1 > 0.0) && (car.pwm2 < 0.0) then do -- Judgment of the direction of movement of the trolley. -- Rotate left, the number of right pulses is negative, -- and the number of left pulses is positive. pulseRight := -pulseRight car := {car with stopLeft := car.stopLeft + pulseLeft} car := {car with stopRight := car.stopRight + pulseRight} car := {car with pulseLeft := car.pulseLeft + pulseLeft} car := {car with pulseRight := car.pulseRight + pulseRight} car -- Interrupt triggered every 5ms to steer car via the two motors def update (car : BalanceCar) (ax ay az gx gy gz : Int) : BalanceCar := do let mut car : BalanceCar := car car := countPulse car car := car.angleTest ax ay az gx gy gz car := {car with angleOut := kp * (car.angle + angle0) + kd * car.gyroX} car := {car with turnSpinDelay := car.turnSpinDelay - 1} if car.turnSpinDelay == 0 then do car := car.updateTurnSpin car := {car with turnSpinDelay := turnSpinDelayCount} car := {car with speedPIDelay := car.speedPIDelay - 1} if car.speedPIDelay == 0 then do car := car.updateSpeedPI car := {car with speedPIDelay := speedPIDelayCount} car := car.pwma pure car end BalanceCar inductive Cmd | forward | reverse | turnLeft | turnRight | spinLeft | spinRight | stop open Cmd def commandCar (car : BalanceCar) : Cmd → BalanceCar | forward => {car with ctrl := {car.ctrl with forward := 700}} | reverse => {car with ctrl := {car.ctrl with reverse := -700}} | turnLeft => {car with ctrl := {car.ctrl with turnLeft := true}} | turnRight => {car with ctrl := {car.ctrl with turnRight := true}} | spinLeft => {car with ctrl := {car.ctrl with spinLeft := true}} | spinRight => {car with ctrl := {car.ctrl with spinRight := true}} | stop => {car with ctrl := Controller.initial} -- Function declaraions for C-implemented I/O functions @[extern "lean_initialize_serial_port"] constant initializeSerialPort (portPath : @& String) (baudRate : UInt16) : IO Unit @[extern "lean_start_car"] constant startCar : IO Unit @[extern "lean_drive_car"] constant driveCar (mode1 mode2 : Bool) (value1 value2 : Float) : IO Unit @[extern "lean_rx_int16_as_int"] constant rxInt16AsInt : IO Int @[extern "lean_rx_long_as_int"] constant rxLongAsInt : IO Int @[extern "lean_wait_for_header"] constant waitForHeader : IO Unit partial -- intended to loop indefinitely and is therefore partial def controlLoop (car : BalanceCar) : IO Unit := do waitForHeader let l ← rxLongAsInt let r ← rxLongAsInt let ax ← rxInt16AsInt let ay ← rxInt16AsInt let az ← rxInt16AsInt let gx ← rxInt16AsInt let gy ← rxInt16AsInt let gz ← rxInt16AsInt let mut car := {car with countLeft := l, countRight := r} car := car.update ax ay az gx gy gz let (mode1, pwm1) := if car.pwm1 >= 0.0 then (true, car.pwm1) else (false, (-car.pwm1)) let (mode2, pwm2) := if car.pwm2 >= 0.0 then (true, car.pwm2) else (false, (-car.pwm2)) driveCar mode1 mode2 pwm1 pwm2 controlLoop car private def printSupportedBaudRates : IO Unit := IO.println " Supported baud rates: 1200, 2400, 4800, 9600, 19200, 38400, 57600, or 115200." -- - - - - - - - - - - - - - - - - - - - - - - - - -- Debugging/Simulation Code -- - - - - - - - - - - - - - - - - - - - - - - - - structure DebugSample where iteration : Int countLeft : Int countRight : Int ax : Int ay : Int az : Int gx : Int gy : Int gz : Int pwm1 : Float pwm2 : Float namespace DebugSample open Lean def parseInt (lineNum : Nat) (str : String) : IO Int := match Json.parse str with | Except.ok js => match js.getInt? with | none => throw $ IO.userError s!"Expected an Int on line {toString lineNum} but got {str}" | some n => pure n | Except.error e => throw $ IO.userError s!"Expected an Int on line {toString lineNum} but got {str}" def parseFloat (lineNum : Nat) (str : String) : IO Float := match str.split (λ x => x == '.') with | [lhs,rhs] => do let n ← if lhs == "0" then do let rhs' := rhs.dropWhile (λ c => c == '0') if rhs' == "" then pure 0 else parseInt lineNum rhs' else if lhs == "-0" then do let rhs' := rhs.dropWhile (λ c => c == '0') if rhs' == "" then pure 0 else parseInt lineNum ("-"++rhs') else parseInt lineNum (lhs ++ rhs) let len := rhs.length pure $ (Float.ofInt n) / (Float.ofNat (10 ^ len)) | _ => throw $ IO.userError s!"Expected a simple decimal literal on line {toString lineNum} but got {str}" end DebugSample section open DebugSample -- Parses in a raw data file---containing accelerometer measurement data -- and computed pwm values---to compare against the Lean port's -- calculations. def parseSamples (dataFile : String) : IO (Array DebugSample) := do IO.println s!"Parsing samples from {dataFile}" let mut lastIter := -1 let mut samples := #[] let lines ← IO.FS.lines dataFile for l in lines, lNum in [0:lines.size] do match (l.split Char.isWhitespace).filter (λ s => s != "") with | [i,l,r,ax,ay,az,gx,gy,gz,pmw1,pmw2] => do let i := ← parseInt lNum i let l ← parseInt lNum l let r ← parseInt lNum r let ax ← parseInt lNum ax let ay ← parseInt lNum ay let az ← parseInt lNum az let gx ← parseInt lNum gx let gy ← parseInt lNum gy let gz ← parseInt lNum gz let pwm1 ← parseFloat lNum pmw1 let pwm2 ← parseFloat lNum pmw2 if i != (lastIter + 1) then throw $ IO.userError s!"expected iteration {toString (lastIter+1)} but got {toString i}" lastIter := i let s := {iteration := i, countLeft := l, countRight := r, ax := ax, ay := ay, az := az, gx := gx, gy := gy, gz := gz, pwm1 := pwm1, pwm2 := pwm2} samples := samples.push s | _ => throw $ IO.userError s!"expected 11 space separated numbers but got {l}" pure samples end -- A control loop that compares our Lean implementation to values reported from -- the BalanceCar using the original C/Arduino code. def debugControlLoop (initCar : BalanceCar) (samples : Array DebugSample) : IO Unit := do let ε := 2.5 IO.println s!"Running simulation on {toString samples.size} samples (i.e., {toString (samples.size / 200)} seconds of data)..." let mut car := initCar for s in samples do car := {car with countLeft := s.countLeft, countRight := s.countRight} car := car.update s.ax s.ay s.az s.gx s.gy s.gz if Float.abs (s.pwm1 - car.pwm1) > ε then throw $ IO.userError s!"[iteration {toString s.iteration}] Expected pwm1 approx. {toString s.pwm1} but got {toString car.pwm1}" if Float.abs (s.pwm2 - car.pwm2) > ε then throw $ IO.userError s!"[iteration {toString s.iteration}] Expected pwm2 approx. {toString s.pwm2} but got {toString car.pwm2}" IO.println s!"All calculated PWM values were within {toString ε} of their expected value!" def debugMain (args : List String) : IO Unit := do if args == [] then do throw $ IO.userError "Expected one or more data files as command line arguments." for dataFile in args do IO.println s!"Data file `{dataFile}`" debugControlLoop BalanceCar.initial (← parseSamples dataFile) def debugMode := false def main (args : List String) : IO Unit := if debugMode then debugMain args else do let invalidBaudRate : String → IO Unit := λ rate => do IO.println $ "Invalid baude rate: " ++ rate IO.println "Supported baud rates: 1200, 2400, 4800, 9600, 19200, 38400, 57600, or 115200." match args with | [port, rate] => match String.toNat? rate with | some n => match BaudRate.ofNat? n with | some bps => do initializeSerialPort port bps.toUInt16 startCar controlLoop BalanceCar.initial | none => invalidBaudRate rate | none => invalidBaudRate rate | _ => do IO.println "usage: `balance-car PORT BAUDRATE`" IO.println "e.g., `balance-car /dev/ttyS0 115200`" IO.println "Supported baud rates: 1200, 2400, 4800, 9600, 19200, 38400, 57600, or 115200."
df309d7f88507a296d17bf940fe345ea39b6be18
2eab05920d6eeb06665e1a6df77b3157354316ad
/src/field_theory/splitting_field.lean
61d7a28a2b0ff9970031cc278fab64c2474e1d83
[ "Apache-2.0" ]
permissive
ayush1801/mathlib
78949b9f789f488148142221606bf15c02b960d2
ce164e28f262acbb3de6281b3b03660a9f744e3c
refs/heads/master
1,692,886,907,941
1,635,270,866,000
1,635,270,866,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
37,503
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 ring_theory.adjoin_root import ring_theory.algebra_tower import ring_theory.algebraic import ring_theory.polynomial import field_theory.minpoly import linear_algebra.finite_dimensional import tactic.field_simp import algebra.polynomial.big_operators /-! # Splitting fields This file introduces the notion of a splitting field of a polynomial and provides an embedding from a splitting field to any field that splits the polynomial. A polynomial `f : polynomial K` splits over a field extension `L` of `K` if it is zero or all of its irreducible factors over `L` have degree `1`. A field extension of `K` of a polynomial `f : polynomial K` is called a splitting field if it is the smallest field extension of `K` such that `f` splits. ## Main definitions * `polynomial.splits i f`: A predicate on a field homomorphism `i : K → L` and a polynomial `f` saying that `f` is zero or all of its irreducible factors over `L` have degree `1`. * `polynomial.splitting_field f`: A fixed splitting field of the polynomial `f`. * `polynomial.is_splitting_field`: A predicate on a field to be a splitting field of a polynomial `f`. ## Main statements * `polynomial.C_leading_coeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its degree, it can be written as the product of its leading coefficient with `∏ (X - a)` where `a` ranges through its roots. * `lift_of_splits`: If `K` and `L` are field extensions of a field `F` and for some finite subset `S` of `K`, the minimal polynomial of every `x ∈ K` splits as a polynomial with coefficients in `L`, then `algebra.adjoin F S` embeds into `L`. * `polynomial.is_splitting_field.lift`: An embedding of a splitting field of the polynomial `f` into another field such that `f` splits. * `polynomial.is_splitting_field.alg_equiv`: Every splitting field of a polynomial `f` is isomorpic to `splitting_field f` and thus, being a splitting field is unique up to isomorphism. -/ noncomputable theory open_locale classical big_operators universes u v w variables {F : Type u} {K : Type v} {L : Type w} namespace polynomial variables [field K] [field L] [field F] open polynomial section splits variables (i : K →+* L) /-- A polynomial `splits` iff it is zero or all of its irreducible factors have `degree` 1. -/ def splits (f : polynomial K) : Prop := f = 0 ∨ ∀ {g : polynomial L}, irreducible g → g ∣ f.map i → degree g = 1 @[simp] lemma splits_zero : splits i (0 : polynomial K) := or.inl rfl @[simp] lemma splits_C (a : K) : splits i (C a) := if ha : a = 0 then ha.symm ▸ (@C_0 K _).symm ▸ splits_zero i else have hia : i a ≠ 0, from mt ((i.injective_iff).1 i.injective _) ha, or.inr $ λ g hg ⟨p, hp⟩, absurd hg.1 (not_not.2 (is_unit_iff_degree_eq_zero.2 $ by have := congr_arg degree hp; simp [degree_C hia, @eq_comm (with_bot ℕ) 0, nat.with_bot.add_eq_zero_iff] at this; clear _fun_match; tauto)) lemma splits_of_degree_eq_one {f : polynomial K} (hf : degree f = 1) : splits i f := or.inr $ λ g hg ⟨p, hp⟩, by have := congr_arg degree hp; simp [nat.with_bot.add_eq_one_iff, hf, @eq_comm (with_bot ℕ) 1, mt is_unit_iff_degree_eq_zero.2 hg.1] at this; clear _fun_match; tauto lemma splits_of_degree_le_one {f : polynomial K} (hf : degree f ≤ 1) : splits i f := begin cases h : degree f with n, { rw [degree_eq_bot.1 h]; exact splits_zero i }, { cases n with n, { rw [eq_C_of_degree_le_zero (trans_rel_right (≤) h (le_refl _))]; exact splits_C _ _ }, { have hn : n = 0, { rw h at hf, cases n, { refl }, { exact absurd hf dec_trivial } }, exact splits_of_degree_eq_one _ (by rw [h, hn]; refl) } } end lemma splits_of_nat_degree_le_one {f : polynomial K} (hf : nat_degree f ≤ 1) : splits i f := splits_of_degree_le_one i (degree_le_of_nat_degree_le hf) lemma splits_of_nat_degree_eq_one {f : polynomial K} (hf : nat_degree f = 1) : splits i f := splits_of_nat_degree_le_one i (le_of_eq hf) lemma splits_mul {f g : polynomial K} (hf : splits i f) (hg : splits i g) : splits i (f * g) := if h : f * g = 0 then by simp [h] else or.inr $ λ p hp hpf, ((principal_ideal_ring.irreducible_iff_prime.1 hp).2.2 _ _ (show p ∣ map i f * map i g, by convert hpf; rw polynomial.map_mul)).elim (hf.resolve_left (λ hf, by simpa [hf] using h) hp) (hg.resolve_left (λ hg, by simpa [hg] using h) hp) lemma splits_of_splits_mul {f g : polynomial K} (hfg : f * g ≠ 0) (h : splits i (f * g)) : splits i f ∧ splits i g := ⟨or.inr $ λ g hgi hg, or.resolve_left h hfg hgi (by rw map_mul; exact hg.trans (dvd_mul_right _ _)), or.inr $ λ g hgi hg, or.resolve_left h hfg hgi (by rw map_mul; exact hg.trans (dvd_mul_left _ _))⟩ lemma splits_of_splits_of_dvd {f g : polynomial K} (hf0 : f ≠ 0) (hf : splits i f) (hgf : g ∣ f) : splits i g := by { obtain ⟨f, rfl⟩ := hgf, exact (splits_of_splits_mul i hf0 hf).1 } lemma splits_of_splits_gcd_left {f g : polynomial K} (hf0 : f ≠ 0) (hf : splits i f) : splits i (euclidean_domain.gcd f g) := polynomial.splits_of_splits_of_dvd i hf0 hf (euclidean_domain.gcd_dvd_left f g) lemma splits_of_splits_gcd_right {f g : polynomial K} (hg0 : g ≠ 0) (hg : splits i g) : splits i (euclidean_domain.gcd f g) := polynomial.splits_of_splits_of_dvd i hg0 hg (euclidean_domain.gcd_dvd_right f g) lemma splits_map_iff (j : L →+* F) {f : polynomial K} : splits j (f.map i) ↔ splits (j.comp i) f := by simp [splits, polynomial.map_map] theorem splits_one : splits i 1 := splits_C i 1 theorem splits_of_is_unit {u : polynomial K} (hu : is_unit u) : u.splits i := splits_of_splits_of_dvd i one_ne_zero (splits_one _) $ is_unit_iff_dvd_one.1 hu theorem splits_X_sub_C {x : K} : (X - C x).splits i := splits_of_degree_eq_one _ $ degree_X_sub_C x theorem splits_X : X.splits i := splits_of_degree_eq_one _ $ degree_X theorem splits_id_iff_splits {f : polynomial K} : (f.map i).splits (ring_hom.id L) ↔ f.splits i := by rw [splits_map_iff, ring_hom.id_comp] theorem splits_mul_iff {f g : polynomial K} (hf : f ≠ 0) (hg : g ≠ 0) : (f * g).splits i ↔ f.splits i ∧ g.splits i := ⟨splits_of_splits_mul i (mul_ne_zero hf hg), λ ⟨hfs, hgs⟩, splits_mul i hfs hgs⟩ theorem splits_prod {ι : Type u} {s : ι → polynomial K} {t : finset ι} : (∀ j ∈ t, (s j).splits i) → (∏ x in t, s x).splits i := begin refine finset.induction_on t (λ _, splits_one i) (λ a t hat ih ht, _), rw finset.forall_mem_insert at ht, rw finset.prod_insert hat, exact splits_mul i ht.1 (ih ht.2) end lemma splits_pow {f : polynomial K} (hf : f.splits i) (n : ℕ) : (f ^ n).splits i := begin rw [←finset.card_range n, ←finset.prod_const], exact splits_prod i (λ j hj, hf), end lemma splits_X_pow (n : ℕ) : (X ^ n).splits i := splits_pow i (splits_X i) n theorem splits_prod_iff {ι : Type u} {s : ι → polynomial K} {t : finset ι} : (∀ j ∈ t, s j ≠ 0) → ((∏ x in t, s x).splits i ↔ ∀ j ∈ t, (s j).splits i) := begin refine finset.induction_on t (λ _, ⟨λ _ _ h, h.elim, λ _, splits_one i⟩) (λ a t hat ih ht, _), rw finset.forall_mem_insert at ht ⊢, rw [finset.prod_insert hat, splits_mul_iff i ht.1 (finset.prod_ne_zero_iff.2 ht.2), ih ht.2] end lemma degree_eq_one_of_irreducible_of_splits {p : polynomial L} (h_nz : p ≠ 0) (hp : irreducible p) (hp_splits : splits (ring_hom.id L) p) : p.degree = 1 := begin rcases hp_splits, { contradiction }, { apply hp_splits hp, simp } end lemma exists_root_of_splits {f : polynomial K} (hs : splits i f) (hf0 : degree f ≠ 0) : ∃ x, eval₂ i x f = 0 := if hf0 : f = 0 then ⟨37, by simp [hf0]⟩ else let ⟨g, hg⟩ := wf_dvd_monoid.exists_irreducible_factor (show ¬ is_unit (f.map i), from mt is_unit_iff_degree_eq_zero.1 (by rwa degree_map)) (map_ne_zero hf0) in let ⟨x, hx⟩ := exists_root_of_degree_eq_one (hs.resolve_left hf0 hg.1 hg.2) in let ⟨i, hi⟩ := hg.2 in ⟨x, by rw [← eval_map, hi, eval_mul, show _ = _, from hx, zero_mul]⟩ lemma exists_multiset_of_splits {f : polynomial K} : splits i f → ∃ (s : multiset L), f.map i = C (i f.leading_coeff) * (s.map (λ a : L, (X : polynomial L) - C a)).prod := suffices splits (ring_hom.id _) (f.map i) → ∃ s : multiset L, f.map i = (C (f.map i).leading_coeff) * (s.map (λ a : L, (X : polynomial L) - C a)).prod, by rwa [splits_map_iff, leading_coeff_map i] at this, wf_dvd_monoid.induction_on_irreducible (f.map i) (λ _, ⟨{37}, by simp [i.map_zero]⟩) (λ u hu _, ⟨0, by conv_lhs { rw eq_C_of_degree_eq_zero (is_unit_iff_degree_eq_zero.1 hu) }; simp [leading_coeff, nat_degree_eq_of_degree_eq_some (is_unit_iff_degree_eq_zero.1 hu)]⟩) (λ f p hf0 hp ih hfs, have hpf0 : p * f ≠ 0, from mul_ne_zero hp.ne_zero hf0, let ⟨s, hs⟩ := ih (splits_of_splits_mul _ hpf0 hfs).2 in ⟨-(p * norm_unit p).coeff 0 ::ₘ s, have hp1 : degree p = 1, from hfs.resolve_left hpf0 hp (by simp), begin rw [multiset.map_cons, multiset.prod_cons, leading_coeff_mul, C_mul, mul_assoc, mul_left_comm (C f.leading_coeff), ← hs, ← mul_assoc, mul_left_inj' hf0], conv_lhs {rw eq_X_add_C_of_degree_eq_one hp1}, simp only [mul_add, coe_norm_unit_of_ne_zero hp.ne_zero, mul_comm p, coeff_neg, C_neg, sub_eq_add_neg, neg_neg, coeff_C_mul, (mul_assoc _ _ _).symm, C_mul.symm, mul_inv_cancel (show p.leading_coeff ≠ 0, from mt leading_coeff_eq_zero.1 hp.ne_zero), one_mul], end⟩) /-- Pick a root of a polynomial that splits. -/ def root_of_splits {f : polynomial K} (hf : f.splits i) (hfd : f.degree ≠ 0) : L := classical.some $ exists_root_of_splits i hf hfd theorem map_root_of_splits {f : polynomial K} (hf : f.splits i) (hfd) : f.eval₂ i (root_of_splits i hf hfd) = 0 := classical.some_spec $ exists_root_of_splits i hf hfd theorem roots_map {f : polynomial K} (hf : f.splits $ ring_hom.id K) : (f.map i).roots = (f.roots).map i := if hf0 : f = 0 then by rw [hf0, map_zero, roots_zero, roots_zero, multiset.map_zero] else have hmf0 : f.map i ≠ 0 := map_ne_zero hf0, let ⟨m, hm⟩ := exists_multiset_of_splits _ hf in have h1 : (0 : polynomial K) ∉ m.map (λ r, X - C r), from zero_nmem_multiset_map_X_sub_C _ _, have h2 : (0 : polynomial L) ∉ m.map (λ r, X - C (i r)), from zero_nmem_multiset_map_X_sub_C _ _, begin rw map_id at hm, rw hm at hf0 hmf0 ⊢, rw map_mul at hmf0 ⊢, rw [roots_mul hf0, roots_mul hmf0, map_C, roots_C, zero_add, roots_C, zero_add, map_multiset_prod, multiset.map_map], simp_rw [(∘), map_sub, map_X, map_C], rw [roots_multiset_prod _ h2, multiset.bind_map, roots_multiset_prod _ h1, multiset.bind_map], simp_rw roots_X_sub_C, rw [multiset.bind_singleton, multiset.bind_singleton, multiset.map_id'] end lemma eq_prod_roots_of_splits {p : polynomial K} {i : K →+* L} (hsplit : splits i p) : p.map i = C (i p.leading_coeff) * ((p.map i).roots.map (λ a, X - C a)).prod := begin by_cases p_eq_zero : p = 0, { rw [p_eq_zero, map_zero, leading_coeff_zero, i.map_zero, C.map_zero, zero_mul] }, obtain ⟨s, hs⟩ := exists_multiset_of_splits i hsplit, have map_ne_zero : p.map i ≠ 0 := map_ne_zero (p_eq_zero), have prod_ne_zero : C (i p.leading_coeff) * (multiset.map (λ a, X - C a) s).prod ≠ 0 := by rwa hs at map_ne_zero, have zero_nmem : (0 : polynomial L) ∉ s.map (λ a, X - C a), from zero_nmem_multiset_map_X_sub_C _ _, have map_bind_roots_eq : (s.map (λ a, X - C a)).bind (λ a, a.roots) = s, { refine multiset.induction_on s (by rw [multiset.map_zero, multiset.zero_bind]) _, intros a s ih, rw [multiset.map_cons, multiset.cons_bind, ih, roots_X_sub_C, multiset.singleton_add] }, rw [hs, roots_mul prod_ne_zero, roots_C, zero_add, roots_multiset_prod _ zero_nmem, map_bind_roots_eq] end lemma eq_prod_roots_of_splits_id {p : polynomial K} (hsplit : splits (ring_hom.id K) p) : p = C (p.leading_coeff) * (p.roots.map (λ a, X - C a)).prod := by simpa using eq_prod_roots_of_splits hsplit lemma eq_prod_roots_of_monic_of_splits_id {p : polynomial K} (m : monic p) (hsplit : splits (ring_hom.id K) p) : p = (p.roots.map (λ a, X - C a)).prod := begin convert eq_prod_roots_of_splits_id hsplit, simp [m], end lemma eq_X_sub_C_of_splits_of_single_root {x : K} {h : polynomial K} (h_splits : splits i h) (h_roots : (h.map i).roots = {i x}) : h = (C (leading_coeff h)) * (X - C x) := begin apply polynomial.map_injective _ i.injective, rw [eq_prod_roots_of_splits h_splits, h_roots], simp, end lemma nat_degree_eq_card_roots {p : polynomial K} {i : K →+* L} (hsplit : splits i p) : p.nat_degree = (p.map i).roots.card := begin by_cases p_eq_zero : p = 0, { rw [p_eq_zero, nat_degree_zero, map_zero, roots_zero, multiset.card_zero] }, have map_ne_zero : p.map i ≠ 0 := map_ne_zero (p_eq_zero), rw eq_prod_roots_of_splits hsplit at map_ne_zero, conv_lhs { rw [← nat_degree_map i, eq_prod_roots_of_splits hsplit] }, have : (0 : polynomial L) ∉ (map i p).roots.map (λ a, X - C a), from zero_nmem_multiset_map_X_sub_C _ _, simp [nat_degree_mul (left_ne_zero_of_mul map_ne_zero) (right_ne_zero_of_mul map_ne_zero), nat_degree_multiset_prod _ this] end lemma degree_eq_card_roots {p : polynomial K} {i : K →+* L} (p_ne_zero : p ≠ 0) (hsplit : splits i p) : p.degree = (p.map i).roots.card := by rw [degree_eq_nat_degree p_ne_zero, nat_degree_eq_card_roots hsplit] section UFD local attribute [instance, priority 10] principal_ideal_ring.to_unique_factorization_monoid local infix ` ~ᵤ ` : 50 := associated open unique_factorization_monoid associates lemma splits_of_exists_multiset {f : polynomial K} {s : multiset L} (hs : f.map i = C (i f.leading_coeff) * (s.map (λ a : L, (X : polynomial L) - C a)).prod) : splits i f := if hf0 : f = 0 then or.inl hf0 else or.inr $ λ p hp hdp, have ht : multiset.rel associated (normalized_factors (f.map i)) (s.map (λ a : L, (X : polynomial L) - C a)) := factors_unique (λ p hp, irreducible_of_normalized_factor _ hp) (λ p' m, begin obtain ⟨a,m,rfl⟩ := multiset.mem_map.1 m, exact irreducible_of_degree_eq_one (degree_X_sub_C _), end) (associated.symm $ calc _ ~ᵤ f.map i : ⟨(units.map C.to_monoid_hom : units L →* units (polynomial L)) (units.mk0 (f.map i).leading_coeff (mt leading_coeff_eq_zero.1 (map_ne_zero hf0))), by conv_rhs { rw [hs, ← leading_coeff_map i, mul_comm] }; refl⟩ ... ~ᵤ _ : (unique_factorization_monoid.normalized_factors_prod (by simpa using hf0)).symm), let ⟨q, hq, hpq⟩ := exists_mem_normalized_factors_of_dvd (by simpa) hp hdp in let ⟨q', hq', hqq'⟩ := multiset.exists_mem_of_rel_of_mem ht hq in let ⟨a, ha⟩ := multiset.mem_map.1 hq' in by rw [← degree_X_sub_C a, ha.2]; exact degree_eq_degree_of_associated (hpq.trans hqq') lemma splits_of_splits_id {f : polynomial K} : splits (ring_hom.id _) f → splits i f := unique_factorization_monoid.induction_on_prime f (λ _, splits_zero _) (λ _ hu _, splits_of_degree_le_one _ ((is_unit_iff_degree_eq_zero.1 hu).symm ▸ dec_trivial)) (λ a p ha0 hp ih hfi, splits_mul _ (splits_of_degree_eq_one _ ((splits_of_splits_mul _ (mul_ne_zero hp.1 ha0) hfi).1.resolve_left hp.1 hp.irreducible (by rw map_id))) (ih (splits_of_splits_mul _ (mul_ne_zero hp.1 ha0) hfi).2)) end UFD lemma splits_iff_exists_multiset {f : polynomial K} : splits i f ↔ ∃ (s : multiset L), f.map i = C (i f.leading_coeff) * (s.map (λ a : L, (X : polynomial L) - C a)).prod := ⟨exists_multiset_of_splits i, λ ⟨s, hs⟩, splits_of_exists_multiset i hs⟩ lemma splits_comp_of_splits (j : L →+* F) {f : polynomial K} (h : splits i f) : splits (j.comp i) f := begin change i with ((ring_hom.id _).comp i) at h, rw [← splits_map_iff], rw [← splits_map_iff i] at h, exact splits_of_splits_id _ h end /-- A monic polynomial `p` that has as many roots as its degree can be written `p = ∏(X - a)`, for `a` in `p.roots`. -/ lemma prod_multiset_X_sub_C_of_monic_of_roots_card_eq {p : polynomial K} (hmonic : p.monic) (hroots : p.roots.card = p.nat_degree) : (multiset.map (λ (a : K), X - C a) p.roots).prod = p := begin have hprodmonic : (multiset.map (λ (a : K), X - C a) p.roots).prod.monic, { simp only [prod_multiset_root_eq_finset_root (ne_zero_of_monic hmonic), monic_prod_of_monic, monic_X_sub_C, monic_pow, forall_true_iff] }, have hdegree : (multiset.map (λ (a : K), X - C a) p.roots).prod.nat_degree = p.nat_degree, { rw [← hroots, nat_degree_multiset_prod _ (zero_nmem_multiset_map_X_sub_C _ (λ a : K, a))], simp only [eq_self_iff_true, mul_one, nat.cast_id, nsmul_eq_mul, multiset.sum_repeat, multiset.map_const,nat_degree_X_sub_C, function.comp, multiset.map_map] }, obtain ⟨q, hq⟩ := prod_multiset_X_sub_C_dvd p, have qzero : q ≠ 0, { rintro rfl, apply hmonic.ne_zero, simpa only [mul_zero] using hq }, have degp : p.nat_degree = (multiset.map (λ (a : K), X - C a) p.roots).prod.nat_degree + q.nat_degree, { nth_rewrite 0 [hq], simp only [nat_degree_mul (ne_zero_of_monic hprodmonic) qzero] }, have degq : q.nat_degree = 0, { rw hdegree at degp, exact (add_right_inj p.nat_degree).mp (tactic.ring_exp.add_pf_sum_z degp rfl).symm }, obtain ⟨u, hu⟩ := is_unit_iff_degree_eq_zero.2 ((degree_eq_iff_nat_degree_eq qzero).2 degq), have hassoc : associated (multiset.map (λ (a : K), X - C a) p.roots).prod p, { rw associated, use u, rw [hu, ← hq] }, exact eq_of_monic_of_associated hprodmonic hmonic hassoc end /-- A polynomial `p` that has as many roots as its degree can be written `p = p.leading_coeff * ∏(X - a)`, for `a` in `p.roots`. -/ lemma C_leading_coeff_mul_prod_multiset_X_sub_C {p : polynomial K} (hroots : p.roots.card = p.nat_degree) : (C p.leading_coeff) * (multiset.map (λ (a : K), X - C a) p.roots).prod = p := begin by_cases hzero : p = 0, { rw [hzero, leading_coeff_zero, ring_hom.map_zero, zero_mul], }, { have hcoeff : p.leading_coeff ≠ 0, { intro h, exact hzero (leading_coeff_eq_zero.1 h) }, have hrootsnorm : (normalize p).roots.card = (normalize p).nat_degree, { rw [roots_normalize, normalize_apply, nat_degree_mul hzero (units.ne_zero _), hroots, coe_norm_unit, nat_degree_C, add_zero], }, have hprod := prod_multiset_X_sub_C_of_monic_of_roots_card_eq (monic_normalize hzero) hrootsnorm, rw [roots_normalize, normalize_apply, coe_norm_unit_of_ne_zero hzero] at hprod, calc (C p.leading_coeff) * (multiset.map (λ (a : K), X - C a) p.roots).prod = p * C ((p.leading_coeff)⁻¹ * p.leading_coeff) : by rw [hprod, mul_comm, mul_assoc, ← C_mul] ... = p * C 1 : by field_simp ... = p : by simp only [mul_one, ring_hom.map_one], }, end /-- A polynomial splits if and only if it has as many roots as its degree. -/ lemma splits_iff_card_roots {p : polynomial K} : splits (ring_hom.id K) p ↔ p.roots.card = p.nat_degree := begin split, { intro H, rw [nat_degree_eq_card_roots H, map_id] }, { intro hroots, apply (splits_iff_exists_multiset (ring_hom.id K)).2, use p.roots, simp only [ring_hom.id_apply, map_id], exact (C_leading_coeff_mul_prod_multiset_X_sub_C hroots).symm }, end end splits end polynomial section embeddings variables (F) [field F] /-- If `p` is the minimal polynomial of `a` over `F` then `F[a] ≃ₐ[F] F[x]/(p)` -/ def alg_equiv.adjoin_singleton_equiv_adjoin_root_minpoly {R : Type*} [comm_ring R] [algebra F R] (x : R) : algebra.adjoin F ({x} : set R) ≃ₐ[F] adjoin_root (minpoly F x) := alg_equiv.symm $ alg_equiv.of_bijective (alg_hom.cod_restrict (adjoin_root.lift_hom _ x $ minpoly.aeval F x) _ (λ p, adjoin_root.induction_on _ p $ λ p, (algebra.adjoin_singleton_eq_range_aeval F x).symm ▸ (polynomial.aeval _).mem_range.mpr ⟨p, rfl⟩)) ⟨(alg_hom.injective_cod_restrict _ _ _).2 $ (alg_hom.injective_iff _).2 $ λ p, adjoin_root.induction_on _ p $ λ p hp, ideal.quotient.eq_zero_iff_mem.2 $ ideal.mem_span_singleton.2 $ minpoly.dvd F x hp, λ y, let ⟨p, hp⟩ := (set_like.ext_iff.1 (algebra.adjoin_singleton_eq_range_aeval F x) (y : R)).1 y.2 in ⟨adjoin_root.mk _ p, subtype.eq hp⟩⟩ open finset /-- If a `subalgebra` is finite_dimensional as a submodule then it is `finite_dimensional`. -/ lemma finite_dimensional.of_subalgebra_to_submodule {K V : Type*} [field K] [ring V] [algebra K V] {s : subalgebra K V} (h : finite_dimensional K s.to_submodule) : finite_dimensional K s := h /-- If `K` and `L` are field extensions of `F` and we have `s : finset K` such that the minimal polynomial of each `x ∈ s` splits in `L` then `algebra.adjoin F s` embeds in `L`. -/ theorem lift_of_splits {F K L : Type*} [field F] [field K] [field L] [algebra F K] [algebra F L] (s : finset K) : (∀ x ∈ s, is_integral F x ∧ polynomial.splits (algebra_map F L) (minpoly F x)) → nonempty (algebra.adjoin F (↑s : set K) →ₐ[F] L) := begin refine finset.induction_on s (λ H, _) (λ a s has ih H, _), { rw [coe_empty, algebra.adjoin_empty], exact ⟨(algebra.of_id F L).comp (algebra.bot_equiv F K)⟩ }, rw forall_mem_insert at H, rcases H with ⟨⟨H1, H2⟩, H3⟩, cases ih H3 with f, choose H3 H4 using H3, rw [coe_insert, set.insert_eq, set.union_comm, algebra.adjoin_union_eq_under], letI := (f : algebra.adjoin F (↑s : set K) →+* L).to_algebra, haveI : finite_dimensional F (algebra.adjoin F (↑s : set K)) := ( (submodule.fg_iff_finite_dimensional _).1 (fg_adjoin_of_finite (set.finite_mem_finset s) H3)).of_subalgebra_to_submodule, letI := field_of_finite_dimensional F (algebra.adjoin F (↑s : set K)), have H5 : is_integral (algebra.adjoin F (↑s : set K)) a := is_integral_of_is_scalar_tower a H1, have H6 : (minpoly (algebra.adjoin F (↑s : set K)) a).splits (algebra_map (algebra.adjoin F (↑s : set K)) L), { refine polynomial.splits_of_splits_of_dvd _ (polynomial.map_ne_zero $ minpoly.ne_zero H1 : polynomial.map (algebra_map _ _) _ ≠ 0) ((polynomial.splits_map_iff _ _).2 _) (minpoly.dvd _ _ _), { rw ← is_scalar_tower.algebra_map_eq, exact H2 }, { rw [← is_scalar_tower.aeval_apply, minpoly.aeval] } }, obtain ⟨y, hy⟩ := polynomial.exists_root_of_splits _ H6 (ne_of_lt (minpoly.degree_pos H5)).symm, refine ⟨subalgebra.of_under _ _ _⟩, refine (adjoin_root.lift_hom (minpoly (algebra.adjoin F (↑s : set K)) a) y hy).comp _, exact alg_equiv.adjoin_singleton_equiv_adjoin_root_minpoly (algebra.adjoin F (↑s : set K)) a end end embeddings namespace polynomial variables [field K] [field L] [field F] open polynomial section splitting_field /-- Non-computably choose an irreducible factor from a polynomial. -/ def factor (f : polynomial K) : polynomial K := if H : ∃ g, irreducible g ∧ g ∣ f then classical.some H else X instance irreducible_factor (f : polynomial K) : irreducible (factor f) := begin rw factor, split_ifs with H, { exact (classical.some_spec H).1 }, { exact irreducible_X } end theorem factor_dvd_of_not_is_unit {f : polynomial K} (hf1 : ¬is_unit f) : factor f ∣ f := begin by_cases hf2 : f = 0, { rw hf2, exact dvd_zero _ }, rw [factor, dif_pos (wf_dvd_monoid.exists_irreducible_factor hf1 hf2)], exact (classical.some_spec $ wf_dvd_monoid.exists_irreducible_factor hf1 hf2).2 end theorem factor_dvd_of_degree_ne_zero {f : polynomial K} (hf : f.degree ≠ 0) : factor f ∣ f := factor_dvd_of_not_is_unit (mt degree_eq_zero_of_is_unit hf) theorem factor_dvd_of_nat_degree_ne_zero {f : polynomial K} (hf : f.nat_degree ≠ 0) : factor f ∣ f := factor_dvd_of_degree_ne_zero (mt nat_degree_eq_of_degree_eq_some hf) /-- Divide a polynomial f by X - C r where r is a root of f in a bigger field extension. -/ def remove_factor (f : polynomial K) : polynomial (adjoin_root $ factor f) := map (adjoin_root.of f.factor) f /ₘ (X - C (adjoin_root.root f.factor)) theorem X_sub_C_mul_remove_factor (f : polynomial K) (hf : f.nat_degree ≠ 0) : (X - C (adjoin_root.root f.factor)) * f.remove_factor = map (adjoin_root.of f.factor) f := let ⟨g, hg⟩ := factor_dvd_of_nat_degree_ne_zero hf in mul_div_by_monic_eq_iff_is_root.2 $ by rw [is_root.def, eval_map, hg, eval₂_mul, ← hg, adjoin_root.eval₂_root, zero_mul] theorem nat_degree_remove_factor (f : polynomial K) : f.remove_factor.nat_degree = f.nat_degree - 1 := by rw [remove_factor, nat_degree_div_by_monic _ (monic_X_sub_C _), nat_degree_map, nat_degree_X_sub_C] theorem nat_degree_remove_factor' {f : polynomial K} {n : ℕ} (hfn : f.nat_degree = n+1) : f.remove_factor.nat_degree = n := by rw [nat_degree_remove_factor, hfn, n.add_sub_cancel] /-- Auxiliary construction to a splitting field of a polynomial. Uses induction on the degree. -/ def splitting_field_aux (n : ℕ) : Π {K : Type u} [field K], by exactI Π (f : polynomial K), f.nat_degree = n → Type u := nat.rec_on n (λ K _ _ _, K) $ λ n ih K _ f hf, by exactI ih f.remove_factor (nat_degree_remove_factor' hf) namespace splitting_field_aux theorem succ (n : ℕ) (f : polynomial K) (hfn : f.nat_degree = n + 1) : splitting_field_aux (n+1) f hfn = splitting_field_aux n f.remove_factor (nat_degree_remove_factor' hfn) := rfl instance field (n : ℕ) : Π {K : Type u} [field K], by exactI Π {f : polynomial K} (hfn : f.nat_degree = n), field (splitting_field_aux n f hfn) := nat.rec_on n (λ K _ _ _, ‹field K›) $ λ n ih K _ f hf, ih _ instance inhabited {n : ℕ} {f : polynomial K} (hfn : f.nat_degree = n) : inhabited (splitting_field_aux n f hfn) := ⟨37⟩ instance algebra (n : ℕ) : Π {K : Type u} [field K], by exactI Π {f : polynomial K} (hfn : f.nat_degree = n), algebra K (splitting_field_aux n f hfn) := nat.rec_on n (λ K _ _ _, by exactI algebra.id K) $ λ n ih K _ f hfn, by exactI @@restrict_scalars.algebra _ _ _ _ _ (ih _) _ _ instance algebra' {n : ℕ} {f : polynomial K} (hfn : f.nat_degree = n + 1) : algebra (adjoin_root f.factor) (splitting_field_aux _ _ hfn) := splitting_field_aux.algebra n _ instance algebra'' {n : ℕ} {f : polynomial K} (hfn : f.nat_degree = n + 1) : algebra K (splitting_field_aux n f.remove_factor (nat_degree_remove_factor' hfn)) := splitting_field_aux.algebra (n+1) hfn instance algebra''' {n : ℕ} {f : polynomial K} (hfn : f.nat_degree = n + 1) : algebra (adjoin_root f.factor) (splitting_field_aux n f.remove_factor (nat_degree_remove_factor' hfn)) := splitting_field_aux.algebra n _ instance scalar_tower {n : ℕ} {f : polynomial K} (hfn : f.nat_degree = n + 1) : is_scalar_tower K (adjoin_root f.factor) (splitting_field_aux _ _ hfn) := is_scalar_tower.of_algebra_map_eq $ λ x, rfl instance scalar_tower' {n : ℕ} {f : polynomial K} (hfn : f.nat_degree = n + 1) : is_scalar_tower K (adjoin_root f.factor) (splitting_field_aux n f.remove_factor (nat_degree_remove_factor' hfn)) := is_scalar_tower.of_algebra_map_eq $ λ x, rfl theorem algebra_map_succ (n : ℕ) (f : polynomial K) (hfn : f.nat_degree = n + 1) : by exact algebra_map K (splitting_field_aux _ _ hfn) = (algebra_map (adjoin_root f.factor) (splitting_field_aux n f.remove_factor (nat_degree_remove_factor' hfn))).comp (adjoin_root.of f.factor) := rfl protected theorem splits (n : ℕ) : ∀ {K : Type u} [field K], by exactI ∀ (f : polynomial K) (hfn : f.nat_degree = n), splits (algebra_map K $ splitting_field_aux n f hfn) f := nat.rec_on n (λ K _ _ hf, by exactI splits_of_degree_le_one _ (le_trans degree_le_nat_degree $ hf.symm ▸ with_bot.coe_le_coe.2 zero_le_one)) $ λ n ih K _ f hf, by { resetI, rw [← splits_id_iff_splits, algebra_map_succ, ← map_map, splits_id_iff_splits, ← X_sub_C_mul_remove_factor f (λ h, by { rw h at hf, cases hf })], exact splits_mul _ (splits_X_sub_C _) (ih _ _) } theorem exists_lift (n : ℕ) : ∀ {K : Type u} [field K], by exactI ∀ (f : polynomial K) (hfn : f.nat_degree = n) {L : Type*} [field L], by exactI ∀ (j : K →+* L) (hf : splits j f), ∃ k : splitting_field_aux n f hfn →+* L, k.comp (algebra_map _ _) = j := nat.rec_on n (λ K _ _ _ L _ j _, by exactI ⟨j, j.comp_id⟩) $ λ n ih K _ f hf L _ j hj, by exactI have hndf : f.nat_degree ≠ 0, by { intro h, rw h at hf, cases hf }, have hfn0 : f ≠ 0, by { intro h, rw h at hndf, exact hndf rfl }, let ⟨r, hr⟩ := exists_root_of_splits _ (splits_of_splits_of_dvd j hfn0 hj (factor_dvd_of_nat_degree_ne_zero hndf)) (mt is_unit_iff_degree_eq_zero.2 f.irreducible_factor.1) in have hmf0 : map (adjoin_root.of f.factor) f ≠ 0, from map_ne_zero hfn0, have hsf : splits (adjoin_root.lift j r hr) f.remove_factor, by { rw ← X_sub_C_mul_remove_factor _ hndf at hmf0, refine (splits_of_splits_mul _ hmf0 _).2, rwa [X_sub_C_mul_remove_factor _ hndf, ← splits_id_iff_splits, map_map, adjoin_root.lift_comp_of, splits_id_iff_splits] }, let ⟨k, hk⟩ := ih f.remove_factor (nat_degree_remove_factor' hf) (adjoin_root.lift j r hr) hsf in ⟨k, by rw [algebra_map_succ, ← ring_hom.comp_assoc, hk, adjoin_root.lift_comp_of]⟩ theorem adjoin_roots (n : ℕ) : ∀ {K : Type u} [field K], by exactI ∀ (f : polynomial K) (hfn : f.nat_degree = n), algebra.adjoin K (↑(f.map $ algebra_map K $ splitting_field_aux n f hfn).roots.to_finset : set (splitting_field_aux n f hfn)) = ⊤ := nat.rec_on n (λ K _ f hf, by exactI algebra.eq_top_iff.2 (λ x, subalgebra.range_le _ ⟨x, rfl⟩)) $ λ n ih K _ f hfn, by exactI have hndf : f.nat_degree ≠ 0, by { intro h, rw h at hfn, cases hfn }, have hfn0 : f ≠ 0, by { intro h, rw h at hndf, exact hndf rfl }, have hmf0 : map (algebra_map K (splitting_field_aux n.succ f hfn)) f ≠ 0 := map_ne_zero hfn0, by { rw [algebra_map_succ, ← map_map, ← X_sub_C_mul_remove_factor _ hndf, map_mul] at hmf0 ⊢, rw [roots_mul hmf0, map_sub, map_X, map_C, roots_X_sub_C, multiset.to_finset_add, finset.coe_union, multiset.to_finset_singleton, finset.coe_singleton, algebra.adjoin_union_eq_under, ← set.image_singleton, algebra.adjoin_algebra_map K (adjoin_root f.factor) (splitting_field_aux n f.remove_factor (nat_degree_remove_factor' hfn)), adjoin_root.adjoin_root_eq_top, algebra.map_top, is_scalar_tower.range_under_adjoin K (adjoin_root f.factor) (splitting_field_aux n f.remove_factor (nat_degree_remove_factor' hfn)), ih, subalgebra.restrict_scalars_top] } end splitting_field_aux /-- A splitting field of a polynomial. -/ def splitting_field (f : polynomial K) := splitting_field_aux _ f rfl namespace splitting_field variables (f : polynomial K) instance : field (splitting_field f) := splitting_field_aux.field _ _ instance inhabited : inhabited (splitting_field f) := ⟨37⟩ instance : algebra K (splitting_field f) := splitting_field_aux.algebra _ _ protected theorem splits : splits (algebra_map K (splitting_field f)) f := splitting_field_aux.splits _ _ _ variables [algebra K L] (hb : splits (algebra_map K L) f) /-- Embeds the splitting field into any other field that splits the polynomial. -/ def lift : splitting_field f →ₐ[K] L := { commutes' := λ r, by { have := classical.some_spec (splitting_field_aux.exists_lift _ _ _ _ hb), exact ring_hom.ext_iff.1 this r }, .. classical.some (splitting_field_aux.exists_lift _ _ _ _ hb) } theorem adjoin_roots : algebra.adjoin K (↑(f.map (algebra_map K $ splitting_field f)).roots.to_finset : set (splitting_field f)) = ⊤ := splitting_field_aux.adjoin_roots _ _ _ theorem adjoin_root_set : algebra.adjoin K (f.root_set f.splitting_field) = ⊤ := adjoin_roots f end splitting_field variables (K L) [algebra K L] /-- Typeclass characterising splitting fields. -/ class is_splitting_field (f : polynomial K) : Prop := (splits [] : splits (algebra_map K L) f) (adjoin_roots [] : algebra.adjoin K (↑(f.map (algebra_map K L)).roots.to_finset : set L) = ⊤) namespace is_splitting_field variables {K} instance splitting_field (f : polynomial K) : is_splitting_field K (splitting_field f) f := ⟨splitting_field.splits f, splitting_field.adjoin_roots f⟩ section scalar_tower variables {K L F} [algebra F K] [algebra F L] [is_scalar_tower F K L] variables {K} instance map (f : polynomial F) [is_splitting_field F L f] : is_splitting_field K L (f.map $ algebra_map F K) := ⟨by { rw [splits_map_iff, ← is_scalar_tower.algebra_map_eq], exact splits L f }, subalgebra.restrict_scalars_injective F $ by { rw [map_map, ← is_scalar_tower.algebra_map_eq, subalgebra.restrict_scalars_top, eq_top_iff, ← adjoin_roots L f, algebra.adjoin_le_iff], exact λ x hx, @algebra.subset_adjoin K _ _ _ _ _ _ hx }⟩ variables {K} (L) theorem splits_iff (f : polynomial K) [is_splitting_field K L f] : polynomial.splits (ring_hom.id K) f ↔ (⊤ : subalgebra K L) = ⊥ := ⟨λ h, eq_bot_iff.2 $ adjoin_roots L f ▸ (roots_map (algebra_map K L) h).symm ▸ algebra.adjoin_le_iff.2 (λ y hy, let ⟨x, hxs, hxy⟩ := finset.mem_image.1 (by rwa multiset.to_finset_map at hy) in hxy ▸ set_like.mem_coe.2 $ subalgebra.algebra_map_mem _ _), λ h, @ring_equiv.to_ring_hom_refl K _ ▸ ring_equiv.trans_symm (ring_equiv.of_bijective _ $ algebra.bijective_algebra_map_iff.2 h) ▸ by { rw ring_equiv.to_ring_hom_trans, exact splits_comp_of_splits _ _ (splits L f) }⟩ theorem mul (f g : polynomial F) (hf : f ≠ 0) (hg : g ≠ 0) [is_splitting_field F K f] [is_splitting_field K L (g.map $ algebra_map F K)] : is_splitting_field F L (f * g) := ⟨(is_scalar_tower.algebra_map_eq F K L).symm ▸ splits_mul _ (splits_comp_of_splits _ _ (splits K f)) ((splits_map_iff _ _).1 (splits L $ g.map $ algebra_map F K)), by rw [map_mul, roots_mul (mul_ne_zero (map_ne_zero hf : f.map (algebra_map F L) ≠ 0) (map_ne_zero hg)), multiset.to_finset_add, finset.coe_union, algebra.adjoin_union_eq_under, is_scalar_tower.algebra_map_eq F K L, ← map_map, roots_map (algebra_map K L) ((splits_id_iff_splits $ algebra_map F K).2 $ splits K f), multiset.to_finset_map, finset.coe_image, algebra.adjoin_algebra_map, adjoin_roots, algebra.map_top, is_scalar_tower.range_under_adjoin, ← map_map, adjoin_roots, subalgebra.restrict_scalars_top]⟩ end scalar_tower /-- Splitting field of `f` embeds into any field that splits `f`. -/ def lift [algebra K F] (f : polynomial K) [is_splitting_field K L f] (hf : polynomial.splits (algebra_map K F) f) : L →ₐ[K] F := if hf0 : f = 0 then (algebra.of_id K F).comp $ (algebra.bot_equiv K L : (⊥ : subalgebra K L) →ₐ[K] K).comp $ by { rw ← (splits_iff L f).1 (show f.splits (ring_hom.id K), from hf0.symm ▸ splits_zero _), exact algebra.to_top } else alg_hom.comp (by { rw ← adjoin_roots L f, exact classical.choice (lift_of_splits _ $ λ y hy, have aeval y f = 0, from (eval₂_eq_eval_map _).trans $ (mem_roots $ by exact map_ne_zero hf0).1 (multiset.mem_to_finset.mp hy), ⟨(is_algebraic_iff_is_integral _).1 ⟨f, hf0, this⟩, splits_of_splits_of_dvd _ hf0 hf $ minpoly.dvd _ _ this⟩) }) algebra.to_top theorem finite_dimensional (f : polynomial K) [is_splitting_field K L f] : finite_dimensional K L := ⟨@algebra.top_to_submodule K L _ _ _ ▸ adjoin_roots L f ▸ fg_adjoin_of_finite (set.finite_mem_finset _) (λ y hy, if hf : f = 0 then by { rw [hf, map_zero, roots_zero] at hy, cases hy } else (is_algebraic_iff_is_integral _).1 ⟨f, hf, (eval₂_eq_eval_map _).trans $ (mem_roots $ by exact map_ne_zero hf).1 (multiset.mem_to_finset.mp hy)⟩)⟩ instance (f : polynomial K) : _root_.finite_dimensional K f.splitting_field := finite_dimensional f.splitting_field f /-- Any splitting field is isomorphic to `splitting_field f`. -/ def alg_equiv (f : polynomial K) [is_splitting_field K L f] : L ≃ₐ[K] splitting_field f := begin refine alg_equiv.of_bijective (lift L f $ splits (splitting_field f) f) ⟨ring_hom.injective (lift L f $ splits (splitting_field f) f).to_ring_hom, _⟩, haveI := finite_dimensional (splitting_field f) f, haveI := finite_dimensional L f, have : finite_dimensional.finrank K L = finite_dimensional.finrank K (splitting_field f) := le_antisymm (linear_map.finrank_le_finrank_of_injective (show function.injective (lift L f $ splits (splitting_field f) f).to_linear_map, from ring_hom.injective (lift L f $ splits (splitting_field f) f : L →+* f.splitting_field))) (linear_map.finrank_le_finrank_of_injective (show function.injective (lift (splitting_field f) f $ splits L f).to_linear_map, from ring_hom.injective (lift (splitting_field f) f $ splits L f : f.splitting_field →+* L))), change function.surjective (lift L f $ splits (splitting_field f) f).to_linear_map, refine (linear_map.injective_iff_surjective_of_finrank_eq_finrank this).1 _, exact ring_hom.injective (lift L f $ splits (splitting_field f) f : L →+* f.splitting_field) end end is_splitting_field end splitting_field end polynomial
2a1674ce0d2f4cd5d8665a9d16f5e14827643640
cbcb0199842f03e7606d4e43666573fc15dd07a5
/src/topology/algebra/group.lean
e7b3fea9524987c298102b03ed94298bfaa1f4bd
[ "Apache-2.0" ]
permissive
truonghoangle/mathlib
a6a7c14b3767ec71156239d8ea97f6921fe79627
673bae584febcd830c2c9256eb7e7a81e27ed303
refs/heads/master
1,590,347,998,944
1,559,728,860,000
1,559,728,860,000
187,431,971
0
0
null
1,558,238,525,000
1,558,238,525,000
null
UTF-8
Lean
false
false
13,631
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot Theory of topological groups. -/ import data.equiv.algebra import group_theory.quotient_group import topology.algebra.monoid topology.order open classical set lattice filter topological_space local attribute [instance] classical.prop_decidable universes u v w variables {α : Type u} {β : Type v} {γ : Type w} section topological_group /-- A topological group is a group in which the multiplication and inversion operations are continuous. -/ class topological_group (α : Type*) [topological_space α] [group α] extends topological_monoid α : Prop := (continuous_inv : continuous (λa:α, a⁻¹)) /-- A topological (additive) group is a group in which the addition and negation operations are continuous. -/ class topological_add_group (α : Type u) [topological_space α] [add_group α] extends topological_add_monoid α : Prop := (continuous_neg : continuous (λa:α, -a)) attribute [to_additive topological_add_group] topological_group attribute [to_additive topological_add_group.mk] topological_group.mk attribute [to_additive topological_add_group.continuous_neg] topological_group.continuous_inv attribute [to_additive topological_add_group.to_topological_add_monoid] topological_group.to_topological_monoid variables [topological_space α] [group α] @[to_additive continuous_neg'] lemma continuous_inv' [topological_group α] : continuous (λx:α, x⁻¹) := topological_group.continuous_inv α @[to_additive continuous_neg] lemma continuous_inv [topological_group α] [topological_space β] {f : β → α} (hf : continuous f) : continuous (λx, (f x)⁻¹) := continuous_inv'.comp hf @[to_additive tendsto_neg] lemma tendsto_inv [topological_group α] {f : β → α} {x : filter β} {a : α} (hf : tendsto f x (nhds a)) : tendsto (λx, (f x)⁻¹) x (nhds a⁻¹) := hf.comp (continuous_iff_continuous_at.mp (topological_group.continuous_inv α) a) @[to_additive prod.topological_add_group] instance [topological_group α] [topological_space β] [group β] [topological_group β] : topological_group (α × β) := { continuous_inv := continuous.prod_mk (continuous_inv continuous_fst) (continuous_inv continuous_snd) } attribute [instance] prod.topological_add_group protected def homeomorph.mul_left [topological_group α] (a : α) : α ≃ₜ α := { continuous_to_fun := continuous_mul continuous_const continuous_id, continuous_inv_fun := continuous_mul continuous_const continuous_id, .. equiv.mul_left a } attribute [to_additive homeomorph.add_left._proof_1] homeomorph.mul_left._proof_1 attribute [to_additive homeomorph.add_left._proof_2] homeomorph.mul_left._proof_2 attribute [to_additive homeomorph.add_left._proof_3] homeomorph.mul_left._proof_3 attribute [to_additive homeomorph.add_left._proof_4] homeomorph.mul_left._proof_4 attribute [to_additive homeomorph.add_left] homeomorph.mul_left @[to_additive is_open_map_add_left] lemma is_open_map_mul_left [topological_group α] (a : α) : is_open_map (λ x, a * x) := (homeomorph.mul_left a).is_open_map protected def homeomorph.mul_right {α : Type*} [topological_space α] [group α] [topological_group α] (a : α) : α ≃ₜ α := { continuous_to_fun := continuous_mul continuous_id continuous_const, continuous_inv_fun := continuous_mul continuous_id continuous_const, .. equiv.mul_right a } attribute [to_additive homeomorph.add_right._proof_1] homeomorph.mul_right._proof_1 attribute [to_additive homeomorph.add_right._proof_2] homeomorph.mul_right._proof_2 attribute [to_additive homeomorph.add_right._proof_3] homeomorph.mul_right._proof_3 attribute [to_additive homeomorph.add_right._proof_4] homeomorph.mul_right._proof_4 attribute [to_additive homeomorph.add_right] homeomorph.mul_right @[to_additive is_open_map_add_right] lemma is_open_map_mul_right [topological_group α] (a : α) : is_open_map (λ x, x * a) := (homeomorph.mul_right a).is_open_map protected def homeomorph.inv (α : Type*) [topological_space α] [group α] [topological_group α] : α ≃ₜ α := { continuous_to_fun := continuous_inv', continuous_inv_fun := continuous_inv', .. equiv.inv α } attribute [to_additive homeomorph.neg._proof_1] homeomorph.inv._proof_1 attribute [to_additive homeomorph.neg._proof_2] homeomorph.inv._proof_2 attribute [to_additive homeomorph.neg] homeomorph.inv @[to_additive exists_nhds_half] lemma exists_nhds_split [topological_group α] {s : set α} (hs : s ∈ nhds (1 : α)) : ∃ V ∈ nhds (1 : α), ∀ v w ∈ V, v * w ∈ s := begin have : ((λa:α×α, a.1 * a.2) ⁻¹' s) ∈ nhds ((1, 1) : α × α) := tendsto_mul' (by simpa using hs), rw nhds_prod_eq at this, rcases mem_prod_iff.1 this with ⟨V₁, H₁, V₂, H₂, H⟩, exact ⟨V₁ ∩ V₂, inter_mem_sets H₁ H₂, assume v w ⟨hv, _⟩ ⟨_, hw⟩, @H (v, w) ⟨hv, hw⟩⟩ end @[to_additive exists_nhds_half_neg] lemma exists_nhds_split_inv [topological_group α] {s : set α} (hs : s ∈ nhds (1 : α)) : ∃ V ∈ nhds (1 : α), ∀ v w ∈ V, v * w⁻¹ ∈ s := begin have : tendsto (λa:α×α, a.1 * (a.2)⁻¹) ((nhds (1:α)).prod (nhds (1:α))) (nhds 1), { simpa using tendsto_mul (@tendsto_fst α α (nhds 1) (nhds 1)) (tendsto_inv tendsto_snd) }, have : ((λa:α×α, a.1 * (a.2)⁻¹) ⁻¹' s) ∈ (nhds (1:α)).prod (nhds (1:α)) := this (by simpa using hs), rcases mem_prod_iff.1 this with ⟨V₁, H₁, V₂, H₂, H⟩, exact ⟨V₁ ∩ V₂, inter_mem_sets H₁ H₂, assume v w ⟨hv, _⟩ ⟨_, hw⟩, @H (v, w) ⟨hv, hw⟩⟩ end @[to_additive exists_nhds_quarter] lemma exists_nhds_split4 [topological_group α] {u : set α} (hu : u ∈ nhds (1 : α)) : ∃ V ∈ nhds (1 : α), ∀ {v w s t}, v ∈ V → w ∈ V → s ∈ V → t ∈ V → v * w * s * t ∈ u := begin rcases exists_nhds_split hu with ⟨W, W_nhd, h⟩, rcases exists_nhds_split 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 [mul_assoc] using h _ _ (h' v w v_in w_in) (h' s t s_in t_in) end section variable (α) @[to_additive nhds_zero_symm] lemma nhds_one_symm [topological_group α] : comap (λr:α, r⁻¹) (nhds (1 : α)) = nhds (1 : α) := begin have lim : tendsto (λr:α, r⁻¹) (nhds 1) (nhds 1), { simpa using tendsto_inv (@tendsto_id α (nhds 1)) }, refine comap_eq_of_inverse _ _ lim lim, { funext x, simp }, end end @[to_additive nhds_translation_add_neg] lemma nhds_translation_mul_inv [topological_group α] (x : α) : comap (λy:α, y * x⁻¹) (nhds 1) = nhds x := begin refine comap_eq_of_inverse (λy:α, y * x) _ _ _, { funext x; simp }, { suffices : tendsto (λy:α, y * x⁻¹) (nhds x) (nhds (x * x⁻¹)), { simpa }, exact tendsto_mul tendsto_id tendsto_const_nhds }, { suffices : tendsto (λy:α, y * x) (nhds 1) (nhds (1 * x)), { simpa }, exact tendsto_mul tendsto_id tendsto_const_nhds } end @[to_additive topological_add_group.ext] lemma topological_group.ext {G : Type*} [group G] {t t' : topological_space G} (tg : @topological_group G t _) (tg' : @topological_group G t' _) (h : @nhds G t 1 = @nhds G t' 1) : t = t' := eq_of_nhds_eq_nhds $ λ x, by rw [← @nhds_translation_mul_inv G t _ _ x , ← @nhds_translation_mul_inv G t' _ _ x , ← h] end topological_group section quotient_topological_group variables [topological_space α] [group α] [topological_group α] (N : set α) [normal_subgroup N] @[to_additive quotient_add_group.quotient.topological_space] instance : topological_space (quotient_group.quotient N) := by dunfold quotient_group.quotient; apply_instance attribute [instance] quotient_add_group.quotient.topological_space open quotient_group @[to_additive quotient_add_group_saturate] lemma quotient_group_saturate (s : set α) : (coe : α → quotient N) ⁻¹' ((coe : α → quotient N) '' s) = (⋃ x : N, (λ y, y*x.1) '' s) := begin ext x, simp only [mem_preimage_eq, mem_image, mem_Union, quotient_group.eq], split, { exact assume ⟨a, a_in, h⟩, ⟨⟨_, h⟩, a, a_in, mul_inv_cancel_left _ _⟩ }, { exact assume ⟨⟨i, hi⟩, a, ha, eq⟩, ⟨a, ha, by simp only [eq.symm, (mul_assoc _ _ _).symm, inv_mul_cancel_left, hi]⟩ } end @[to_additive quotient_add_group.open_coe] lemma quotient_group.open_coe : is_open_map (coe : α → quotient N) := begin intros s s_op, change is_open ((coe : α → quotient N) ⁻¹' (coe '' s)), rw quotient_group_saturate N s, apply is_open_Union, rintro ⟨n, _⟩, exact is_open_map_mul_right n s s_op end @[to_additive topological_add_group_quotient] instance topological_group_quotient : topological_group (quotient N) := { continuous_mul := begin have cont : continuous ((coe : α → quotient N) ∘ (λ (p : α × α), p.fst * p.snd)) := continuous_quot_mk.comp continuous_mul', have quot : quotient_map (λ p : α × α, ((p.1:quotient N), (p.2:quotient N))), { apply is_open_map.to_quotient_map, { exact is_open_map.prod (quotient_group.open_coe N) (quotient_group.open_coe N) }, { apply continuous.prod_mk, { exact continuous_quot_mk.comp continuous_fst }, { exact continuous_quot_mk.comp continuous_snd } }, { rintro ⟨⟨x⟩, ⟨y⟩⟩, exact ⟨(x, y), rfl⟩ } }, exact (quotient_map.continuous_iff quot).2 cont, end, continuous_inv := begin apply continuous_quotient_lift, change continuous ((coe : α → quotient N) ∘ (λ (a : α), a⁻¹)), exact continuous_quot_mk.comp continuous_inv' end } attribute [instance] topological_add_group_quotient end quotient_topological_group section topological_add_group variables [topological_space α] [add_group α] lemma continuous_sub [topological_add_group α] [topological_space β] {f : β → α} {g : β → α} (hf : continuous f) (hg : continuous g) : continuous (λx, f x - g x) := by simp; exact continuous_add hf (continuous_neg hg) lemma continuous_sub' [topological_add_group α] : continuous (λp:α×α, p.1 - p.2) := continuous_sub continuous_fst continuous_snd lemma tendsto_sub [topological_add_group α] {f : β → α} {g : β → α} {x : filter β} {a b : α} (hf : tendsto f x (nhds a)) (hg : tendsto g x (nhds b)) : tendsto (λx, f x - g x) x (nhds (a - b)) := by simp; exact tendsto_add hf (tendsto_neg hg) lemma nhds_translation [topological_add_group α] (x : α) : comap (λy:α, y - x) (nhds 0) = nhds x := nhds_translation_add_neg x end topological_add_group /-- additive group with a neighbourhood around 0. Only used to construct a topology and uniform space. This is currently only available for commutative groups, but it can be extended to non-commutative groups too. -/ class add_group_with_zero_nhd (α : Type u) extends add_comm_group α := (Z : filter α) (zero_Z {} : pure 0 ≤ Z) (sub_Z {} : tendsto (λp:α×α, p.1 - p.2) (Z.prod Z) Z) namespace add_group_with_zero_nhd variables (α) [add_group_with_zero_nhd α] local notation `Z` := add_group_with_zero_nhd.Z instance : topological_space α := topological_space.mk_of_nhds $ λa, map (λx, x + a) (Z α) variables {α} lemma neg_Z : tendsto (λa:α, - a) (Z α) (Z α) := have tendsto (λa, (0:α)) (Z α) (Z α), by refine le_trans (assume h, _) zero_Z; simp [univ_mem_sets'] {contextual := tt}, have tendsto (λa:α, 0 - a) (Z α) (Z α), from (tendsto.prod_mk this tendsto_id).comp sub_Z, by simpa lemma add_Z : tendsto (λp:α×α, p.1 + p.2) ((Z α).prod (Z α)) (Z α) := suffices tendsto (λp:α×α, p.1 - -p.2) ((Z α).prod (Z α)) (Z α), by simpa, (tendsto.prod_mk tendsto_fst (tendsto_snd.comp neg_Z)).comp sub_Z lemma exists_Z_half {s : set α} (hs : s ∈ Z α) : ∃ V ∈ Z α, ∀ v w ∈ V, v + w ∈ s := begin have : ((λa:α×α, a.1 + a.2) ⁻¹' s) ∈ (Z α).prod (Z α) := add_Z (by simpa using hs), rcases mem_prod_iff.1 this with ⟨V₁, H₁, V₂, H₂, H⟩, exact ⟨V₁ ∩ V₂, inter_mem_sets H₁ H₂, assume v w ⟨hv, _⟩ ⟨_, hw⟩, @H (v, w) ⟨hv, hw⟩⟩ end lemma nhds_eq (a : α) : nhds a = map (λx, x + a) (Z α) := topological_space.nhds_mk_of_nhds _ _ (assume a, calc pure a = map (λx, x + a) (pure 0) : by simp ... ≤ _ : map_mono zero_Z) (assume b s hs, let ⟨t, ht, eqt⟩ := exists_Z_half hs in have t0 : (0:α) ∈ t, by simpa using zero_Z ht, begin refine ⟨(λx:α, x + b) '' t, image_mem_map ht, _, _⟩, { refine set.image_subset_iff.2 (assume b hbt, _), simpa using eqt 0 b t0 hbt }, { rintros _ ⟨c, hb, rfl⟩, refine (Z α).sets_of_superset ht (assume x hxt, _), simpa using eqt _ _ hxt hb } end) lemma nhds_zero_eq_Z : nhds 0 = Z α := by simp [nhds_eq]; exact filter.map_id instance : topological_add_monoid α := ⟨ continuous_iff_continuous_at.2 $ assume ⟨a, b⟩, begin rw [continuous_at, nhds_prod_eq, nhds_eq, nhds_eq, nhds_eq, filter.prod_map_map_eq, tendsto_map'_iff], suffices : tendsto ((λx:α, (a + b) + x) ∘ (λp:α×α,p.1 + p.2)) (filter.prod (Z α) (Z α)) (map (λx:α, (a + b) + x) (Z α)), { simpa [(∘)] }, exact add_Z.comp tendsto_map end⟩ instance : topological_add_group α := ⟨continuous_iff_continuous_at.2 $ assume a, begin rw [continuous_at, nhds_eq, nhds_eq, tendsto_map'_iff], suffices : tendsto ((λx:α, x - a) ∘ (λx:α, -x)) (Z α) (map (λx:α, x - a) (Z α)), { simpa [(∘)] }, exact neg_Z.comp tendsto_map end⟩ end add_group_with_zero_nhd
4b26f6a0300aa0ff2d94f8da4eccbf03f14c19ed
d642a6b1261b2cbe691e53561ac777b924751b63
/src/meta/expr.lean
dabec7d15947762e8dd8b3ecb63636fd5da86521
[ "Apache-2.0" ]
permissive
cipher1024/mathlib
fee56b9954e969721715e45fea8bcb95f9dc03fe
d077887141000fefa5a264e30fa57520e9f03522
refs/heads/master
1,651,806,490,504
1,573,508,694,000
1,573,508,694,000
107,216,176
0
0
Apache-2.0
1,647,363,136,000
1,508,213,014,000
Lean
UTF-8
Lean
false
false
26,176
lean
/- Copyright (c) 2019 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Simon Hudon, Scott Morrison, Keeley Hoek, Robert Y. Lewis -/ import data.string.defs /-! # Additional operations on expr and related types This file defines basic operations on the types expr, name, declaration, level, environment. This file is mostly for non-tactics. Tactics should generally be placed in `tactic.core`. ## Tags expr, name, declaration, level, environment, meta, metaprogramming, tactic -/ namespace binder_info instance : inhabited binder_info := ⟨ binder_info.default ⟩ /-- The brackets corresponding to a given binder_info. -/ def brackets : binder_info → string × string | binder_info.implicit := ("{", "}") | binder_info.strict_implicit := ("{{", "}}") | binder_info.inst_implicit := ("[", "]") | _ := ("(", ")") end binder_info namespace name /-- Find the largest prefix `n` of a `name` such that `f n ≠ none`, then replace this prefix with the value of `f n`. -/ def map_prefix (f : name → option name) : name → name | anonymous := anonymous | (mk_string s n') := (f (mk_string s n')).get_or_else (mk_string s $ map_prefix n') | (mk_numeral d n') := (f (mk_numeral d n')).get_or_else (mk_numeral d $ map_prefix n') /-- If `nm` is a simple name (having only one string component) starting with `_`, then `deinternalize_field nm` removes the underscore. Otherwise, it does nothing. -/ meta def deinternalize_field : name → name | (mk_string s name.anonymous) := let i := s.mk_iterator in if i.curr = '_' then i.next.next_to_string else s | n := n /-- `get_nth_prefix nm n` removes the last `n` components from `nm` -/ meta def get_nth_prefix : name → ℕ → name | nm 0 := nm | nm (n + 1) := get_nth_prefix nm.get_prefix n /-- Auxilliary definition for `pop_nth_prefix` -/ private meta def pop_nth_prefix_aux : name → ℕ → name × ℕ | anonymous n := (anonymous, 1) | nm n := let (pfx, height) := pop_nth_prefix_aux nm.get_prefix n in if height ≤ n then (anonymous, height + 1) else (nm.update_prefix pfx, height + 1) /-- Pops the top `n` prefixes from the given name. -/ meta def pop_nth_prefix (nm : name) (n : ℕ) : name := prod.fst $ pop_nth_prefix_aux nm n /-- Pop the prefix of a name -/ meta def pop_prefix (n : name) : name := pop_nth_prefix n 1 /-- Auxilliary definition for `from_components` -/ private def from_components_aux : name → list string → name | n [] := n | n (s :: rest) := from_components_aux (name.mk_string s n) rest /-- Build a name from components. For example `from_components ["foo","bar"]` becomes ``` `foo.bar``` -/ def from_components : list string → name := from_components_aux name.anonymous /-- `name`s can contain numeral pieces, which are not legal names when typed/passed directly to the parser. We turn an arbitrary name into a legal identifier name by turning the numbers to strings. -/ meta def sanitize_name : name → name | name.anonymous := name.anonymous | (name.mk_string s p) := name.mk_string s $ sanitize_name p | (name.mk_numeral s p) := name.mk_string sformat!"n{s}" $ sanitize_name p /-- Append a string to the last component of a name -/ def append_suffix : name → string → name | (mk_string s n) s' := mk_string (s ++ s') n | n _ := n /-- The first component of a name, turning a number to a string -/ meta def head : name → string | (mk_string s anonymous) := s | (mk_string s p) := head p | (mk_numeral n p) := head p | anonymous := "[anonymous]" /-- Tests whether the first component of a name is `"_private"` -/ meta def is_private (n : name) : bool := n.head = "_private" /-- Get the last component of a name, and convert it to a string. -/ meta def last : name → string | (mk_string s _) := s | (mk_numeral n _) := repr n | anonymous := "[anonymous]" /-- Returns the number of characters used to print all the string components of a name, including periods between name segments. Ignores numerical parts of a name. -/ meta def length : name → ℕ | (mk_string s anonymous) := s.length | (mk_string s p) := s.length + 1 + p.length | (mk_numeral n p) := p.length | anonymous := "[anonymous]".length /-- Checks whether `nm` has a prefix (including itself) such that P is true -/ def has_prefix (P : name → bool) : name → bool | anonymous := ff | (mk_string s nm) := P (mk_string s nm) ∨ has_prefix nm | (mk_numeral s nm) := P (mk_numeral s nm) ∨ has_prefix nm /-- Appends `'` to the end of a name. -/ meta def add_prime : name → name | (name.mk_string s p) := name.mk_string (s ++ "'") p | n := (name.mk_string "x'" n) def last_string : name → string | anonymous := "[anonymous]" | (mk_string s _) := s | (mk_numeral _ n) := last_string n end name namespace level /-- Tests whether a universe level is non-zero for all assignments of its variables -/ meta def nonzero : level → bool | (succ _) := tt | (max l₁ l₂) := l₁.nonzero || l₂.nonzero | (imax _ l₂) := l₂.nonzero | _ := ff end level /-- The type of binders containing a name, the binding info and the binding type -/ @[derive decidable_eq] meta structure binder := (name : name) (info : binder_info) (type : expr) namespace binder /-- Turn a binder into a string. Uses expr.to_string for the type. -/ protected meta def to_string (b : binder) : string := let (l, r) := b.info.brackets in l ++ b.name.to_string ++ " : " ++ b.type.to_string ++ r open tactic meta instance : inhabited binder := ⟨⟨default _, default _, default _⟩⟩ meta instance : has_to_string binder := ⟨ binder.to_string ⟩ meta instance : has_to_format binder := ⟨ λ b, b.to_string ⟩ meta instance : has_to_tactic_format binder := ⟨ λ b, let (l, r) := b.info.brackets in (λ e, l ++ b.name.to_string ++ " : " ++ e ++ r) <$> pp b.type ⟩ end binder /- converting between expressions and numerals -/ /-- `nat.mk_numeral n` embeds `n` as a numeral expression inside a type with 0, 1, and +. `type`: an expression representing the target type. This must live in Type 0. `has_zero`, `has_one`, `has_add`: expressions of the type `has_zero %%type`, etc. -/ meta def nat.mk_numeral (type has_zero has_one has_add : expr) : ℕ → expr := let z : expr := `(@has_zero.zero.{0} %%type %%has_zero), o : expr := `(@has_one.one.{0} %%type %%has_one) in nat.binary_rec z (λ b n e, if n = 0 then o else if b then `(@bit1.{0} %%type %%has_one %%has_add %%e) else `(@bit0.{0} %%type %%has_add %%e)) /-- `int.mk_numeral z` embeds `z` as a numeral expression inside a type with 0, 1, +, and -. `type`: an expression representing the target type. This must live in Type 0. `has_zero`, `has_one`, `has_add`, `has_neg`: expressions of the type `has_zero %%type`, etc. -/ meta def int.mk_numeral (type has_zero has_one has_add has_neg : expr) : ℤ → expr | (int.of_nat n) := n.mk_numeral type has_zero has_one has_add | -[1+n] := let ne := (n+1).mk_numeral type has_zero has_one has_add in `(@has_neg.neg.{0} %%type %%has_neg %%ne) namespace expr /-- Turns an expression into a positive natural number, assuming it is only built up from `has_one.one`, `bit0` and `bit1`. -/ protected meta def to_pos_nat : expr → option ℕ | `(has_one.one _) := some 1 | `(bit0 %%e) := bit0 <$> e.to_pos_nat | `(bit1 %%e) := bit1 <$> e.to_pos_nat | _ := none /-- Turns an expression into a natural number, assuming it is only built up from `has_one.one`, `bit0`, `bit1` and `has_zero.zero`. -/ protected meta def to_nat : expr → option ℕ | `(has_zero.zero _) := some 0 | e := e.to_pos_nat /-- Turns an expression into a integer, assuming it is only built up from `has_one.one`, `bit0`, `bit1`, `has_zero.zero` and a optionally a single `has_neg.neg` as head. -/ protected meta def to_int : expr → option ℤ | `(has_neg.neg %%e) := do n ← e.to_nat, some (-n) | e := coe <$> e.to_nat end expr namespace expr open tactic /-- `replace_with e s s'` replaces ocurrences of `s` with `s'` in `e`. -/ meta def replace_with (e : expr) (s : expr) (s' : expr) : expr := e.replace $ λc d, if c = s then some (s'.lift_vars 0 d) else none /-- Apply a function to each constant (inductive type, defined function etc) in an expression. -/ protected meta def apply_replacement_fun (f : name → name) (e : expr) : expr := e.replace $ λ e d, match e with | expr.const n ls := some $ expr.const (f n) ls | _ := none end /-- Tests whether an expression is a meta-variable. -/ meta def is_mvar : expr → bool | (mvar _ _ _) := tt | _ := ff /-- Tests whether an expression is a sort. -/ meta def is_sort : expr → bool | (sort _) := tt | e := ff /-- If `e` is a local constant, `to_implicit e` changes the binder info of `e` to `implicit`. See also `to_implicit_binder`, which also changes lambdas and pis. -/ meta def to_implicit : expr → expr | (expr.local_const uniq n bi t) := expr.local_const uniq n binder_info.implicit t | e := e -- TODO: rename /-- If `e` is a local constant, lamda, or pi expression, `to_implicit_binder e` changes the binder info of `e` to `implicit`. See also `to_implicit`, which only changes local constants. -/ meta def to_implicit_binder : expr → expr | (local_const n₁ n₂ _ d) := local_const n₁ n₂ binder_info.implicit d | (lam n _ d b) := lam n binder_info.implicit d b | (pi n _ d b) := pi n binder_info.implicit d b | e := e /-- Returns a list of all local constants in an expression (without duplicates). -/ meta def list_local_consts (e : expr) : list expr := e.fold [] (λ e' _ es, if e'.is_local_constant then insert e' es else es) /-- Returns a name_set of all constants in an expression. -/ meta def list_constant (e : expr) : name_set := e.fold mk_name_set (λ e' _ es, if e'.is_constant then es.insert e'.const_name else es) /-- Returns a list of all meta-variables in an expression (without duplicates). -/ meta def list_meta_vars (e : expr) : list expr := e.fold [] (λ e' _ es, if e'.is_mvar then insert e' es else es) /-- Returns a name_set of all constants in an expression starting with a certain prefix. -/ meta def list_names_with_prefix (pre : name) (e : expr) : name_set := e.fold mk_name_set $ λ e' _ l, match e' with | expr.const n _ := if n.get_prefix = pre then l.insert n else l | _ := l end /-- Returns true if `e` contains a name `n` where `p n` is true. Returns `true` if `p name.anonymous` is true -/ meta def contains_constant (e : expr) (p : name → Prop) [decidable_pred p] : bool := e.fold ff (λ e' _ b, if p (e'.const_name) then tt else b) /-- is_num_eq n1 n2 returns true if n1 and n2 are both numerals with the same numeral structure, ignoring differences in type and type class arguments. -/ meta def is_num_eq : expr → expr → bool | `(@has_zero.zero _ _) `(@has_zero.zero _ _) := tt | `(@has_one.one _ _) `(@has_one.one _ _) := tt | `(bit0 %%a) `(bit0 %%b) := a.is_num_eq b | `(bit1 %%a) `(bit1 %%b) := a.is_num_eq b | `(-%%a) `(-%%b) := a.is_num_eq b | `(%%a/%%a') `(%%b/%%b') := a.is_num_eq b | _ _ := ff /-- Simplifies the expression `t` with the specified options. The result is `(new_e, pr)` with the new expression `new_e` and a proof `pr : e = new_e`. -/ meta def simp (t : expr) (cfg : simp_config := {}) (discharger : tactic unit := failed) (no_defaults := ff) (attr_names : list name := []) (hs : list simp_arg_type := []) : tactic (expr × expr) := do (s, to_unfold) ← mk_simp_set no_defaults attr_names hs, simplify s to_unfold t cfg `eq discharger /-- Definitionally simplifies the expression `t` with the specified options. The result is the simplified expression. -/ meta def dsimp (t : expr) (cfg : dsimp_config := {}) (no_defaults := ff) (attr_names : list name := []) (hs : list simp_arg_type := []) : tactic expr := do (s, to_unfold) ← mk_simp_set no_defaults attr_names hs, s.dsimplify to_unfold t cfg /-- Auxilliary definition for `expr.pi_arity` -/ meta def pi_arity_aux : ℕ → expr → ℕ | n (pi _ _ _ b) := pi_arity_aux (n + 1) b | n e := n /-- The arity of a pi-type. Does not perform any reduction of the expression. In one application this was ~30 times quicker than `tactic.get_pi_arity`. -/ meta def pi_arity : expr → ℕ := pi_arity_aux 0 /-- Get the names of the bound variables by a sequence of pis or lambdas. -/ meta def binding_names : expr → list name | (pi n _ _ e) := n :: e.binding_names | (lam n _ _ e) := n :: e.binding_names | e := [] /-- head-reduce a single let expression -/ meta def reduce_let : expr → expr | (elet _ _ v b) := b.instantiate_var v | e := e /-- head-reduce all let expressions -/ meta def reduce_lets : expr → expr | (elet _ _ v b) := reduce_lets $ b.instantiate_var v | e := e /-- Instantiate lambdas in the second argument by expressions from the first. -/ meta def instantiate_lambdas : list expr → expr → expr | (e'::es) (lam n bi t e) := instantiate_lambdas es (e.instantiate_var e') | _ e := e /-- `instantiate_lambdas_or_apps es e` instantiates lambdas in `e` by expressions from `es`. If the length of `es` is larger than the number of lambdas in `e`, then the term is applied to the remaining terms. Also reduces head let-expressions in `e`, including those after instantiating all lambdas. -/ meta def instantiate_lambdas_or_apps : list expr → expr → expr | (v::es) (lam n bi t b) := instantiate_lambdas_or_apps es $ b.instantiate_var v | es (elet _ _ v b) := instantiate_lambdas_or_apps es $ b.instantiate_var v | es e := mk_app e es /- Note [open expressions]: Some declarations work with open expressions, i.e. an expr that has free variables. Terms will free variables are not well-typed, and one should not use them in tactics like `infer_type` or `unify`. You can still do syntactic analysis/manipulation on them. The reason for working with open types is for performance: instantiating variables requires iterating through the expression. In one performance test `pi_binders` was more than 6x quicker than `mk_local_pis` (when applied to the type of all imported declarations 100x). -/ /-- Get the codomain/target of a pi-type. This definition doesn't Instantiate bound variables, and therefore produces a term that is open.-/ meta def pi_codomain : expr → expr -- see note [open expressions] | (pi n bi d b) := pi_codomain b | e := e /-- Auxilliary defintion for `pi_binders`. -/ -- see note [open expressions] meta def pi_binders_aux : list binder → expr → list binder × expr | es (pi n bi d b) := pi_binders_aux (⟨n, bi, d⟩::es) b | es e := (es, e) /-- Get the binders and codomain of a pi-type. This definition doesn't Instantiate bound variables, and therefore produces a term that is open. The.tactic `get_pi_binders` in `tactic.core` does the same, but also instantiates the free variables -/ meta def pi_binders (e : expr) : list binder × expr := -- see note [open expressions] let (es, e) := pi_binders_aux [] e in (es.reverse, e) /-- Auxilliary defintion for `get_app_fn_args`. -/ meta def get_app_fn_args_aux : list expr → expr → expr × list expr | r (app f a) := get_app_fn_args_aux (a::r) f | r e := (e, r) /-- A combination of `get_app_fn` and `get_app_args`: lists both the function and its arguments of an application -/ meta def get_app_fn_args : expr → expr × list expr := get_app_fn_args_aux [] /-- `drop_pis es e` instantiates the pis in `e` with the expressions from `es`. -/ meta def drop_pis : list expr → expr → tactic expr | (list.cons v vs) (pi n bi d b) := do t ← infer_type v, guard (t =ₐ d), drop_pis vs (b.instantiate_var v) | [] e := return e | _ _ := failed /-- `mk_op_lst op empty [x1, x2, ...]` is defined as `op x1 (op x2 ...)`. Returns `empty` if the list is empty. -/ meta def mk_op_lst (op : expr) (empty : expr) : list expr → expr | [] := empty | [e] := e | (e :: es) := op e $ mk_op_lst es /-- `mk_and_lst [x1, x2, ...]` is defined as `x1 ∧ (x2 ∧ ...)`, or `true` if the list is empty. -/ meta def mk_and_lst : list expr → expr := mk_op_lst `(and) `(true) /-- `mk_or_lst [x1, x2, ...]` is defined as `x1 ∨ (x2 ∨ ...)`, or `false` if the list is empty. -/ meta def mk_or_lst : list expr → expr := mk_op_lst `(or) `(false) /-- `local_binding_info e` returns the binding info of `e` if `e` is a local constant. Otherwise returns `binder_info.default`. -/ meta def local_binding_info : expr → binder_info | (expr.local_const _ _ bi _) := bi | _ := binder_info.default -- TODO: delete meta abbreviation local_binder_info := local_binding_info /-- `is_default_local e` tests whether `e` is a local constant with binder info `binder_info.default` -/ meta def is_default_local : expr → bool | (expr.local_const _ _ binder_info.default _) := tt | _ := ff end expr namespace environment /-- Tests whether a name is declared in the current file. Fixes an error in `in_current_file` which returns `tt` for the four names `quot, quot.mk, quot.lift, quot.ind` -/ meta def in_current_file' (env : environment) (n : name) : bool := env.in_current_file n && (n ∉ [``quot, ``quot.mk, ``quot.lift, ``quot.ind]) /-- Tests whether `n` is an inductive type with one constructor without indices. If so, returns the number of paramaters and the name of the constructor. Otherwise, returns `none`. -/ meta def is_structure_like (env : environment) (n : name) : option (nat × name) := do guardb (env.is_inductive n), d ← (env.get n).to_option, [intro] ← pure (env.constructors_of n) | none, guard (env.inductive_num_indices n = 0), some (env.inductive_num_params n, intro) /-- Tests whether `n` is a structure. It will first test whether `n` is structure-like and then test that the first projection is defined in the environment and is a projection. -/ meta def is_structure (env : environment) (n : name) : bool := option.is_some $ do (nparams, intro) ← env.is_structure_like n, di ← (env.get intro).to_option, expr.pi x _ _ _ ← nparams.iterate (λ e : option expr, do expr.pi _ _ _ body ← e | none, some body) (some di.type) | none, env.is_projection (n ++ x.deinternalize_field) /-- Get all projections of the structure `n`. Returns `none` if `n` is not structure-like. If `n` is not a structure, but is structure-like, this does not check whether the names are existing declarations. -/ meta def get_projections (env : environment) (n : name) : option (list name) := do (nparams, intro) ← env.is_structure_like n, di ← (env.get intro).to_option, tgt ← nparams.iterate (λ e : option expr, do expr.pi _ _ _ body ← e | none, some body) (some di.type) | none, return $ tgt.binding_names.map (λ x, n ++ x.deinternalize_field) /-- Tests whether `nm` is a generalized inductive type that is not a normal inductive type. Note that `is_ginductive` returns `tt` even on regular inductive types. This returns `tt` if `nm` is (part of a) mutually defined inductive type or a nested inductive type. -/ meta def is_ginductive' (e : environment) (nm : name) : bool := e.is_ginductive nm ∧ ¬ e.is_inductive nm /-- For all declarations `d` where `f d = some x` this adds `x` to the returned list. -/ meta def decl_filter_map {α : Type} (e : environment) (f : declaration → option α) : list α := e.fold [] $ λ d l, match f d with | some r := r :: l | none := l end /-- Maps `f` to all declarations in the environment. -/ meta def decl_map {α : Type} (e : environment) (f : declaration → α) : list α := e.decl_filter_map $ λ d, some (f d) /-- Lists all declarations in the environment -/ meta def get_decls (e : environment) : list declaration := e.decl_map id /-- Lists all trusted (non-meta) declarations in the environment -/ meta def get_trusted_decls (e : environment) : list declaration := e.decl_filter_map (λ d, if d.is_trusted then some d else none) /-- Lists the name of all declarations in the environment -/ meta def get_decl_names (e : environment) : list name := e.decl_map declaration.to_name /-- Fold a monad over all declarations in the environment. -/ meta def mfold {α : Type} {m : Type → Type} [monad m] (e : environment) (x : α) (fn : declaration → α → m α) : m α := e.fold (return x) (λ d t, t >>= fn d) /-- Filters all declarations in the environment. -/ meta def mfilter (e : environment) (test : declaration → tactic bool) : tactic (list declaration) := e.mfold [] $ λ d ds, do b ← test d, return $ if b then d::ds else ds /-- Checks whether `s` is a prefix of the file where `n` is declared. This is used to check whether `n` is declared in mathlib, where `s` is the mathlib directory. -/ meta def is_prefix_of_file (e : environment) (s : string) (n : name) : bool := s.is_prefix_of $ (e.decl_olean n).get_or_else "" end environment namespace expr /- In this section we define the tactic `is_eta_expansion` which checks whether an expression is an eta-expansion of a structure. (not to be confused with eta-expanion for `λ`). -/ open tactic /-- `is_eta_expansion_of args univs l` checks whether for all elements `(nm, pr)` in `l` we have `pr = nm.{univs} args`. Used in `is_eta_expansion`, where `l` consists of the projections and the fields of the value we want to eta-reduce. -/ meta def is_eta_expansion_of (args : list expr) (univs : list level) (l : list (name × expr)) : bool := l.all $ λ⟨proj, val⟩, val = (const proj univs).mk_app args /-- `is_eta_expansion_test l` checks whether there is a list of expresions `args` such that for all elements `(nm, pr)` in `l` we have `pr = nm args`. If so, returns the last element of `args`. Used in `is_eta_expansion`, where `l` consists of the projections and the fields of the value we want to eta-reduce. -/ meta def is_eta_expansion_test : list (name × expr) → option expr | [] := none | (⟨proj, val⟩::l) := match val.get_app_fn with | (const nm univs : expr) := if nm = proj then let args := val.get_app_args in let e := args.ilast in if is_eta_expansion_of args univs l then some e else none else none | _ := none end /-- `is_eta_expansion_aux val l` checks whether `val` can be eta-reduced to an expression `e`. Here `l` is intended to consists of the projections and the fields of `val`. This tactic calls `is_eta_expansion_test l`, but first removes all proofs from the list `l` and afterward checks whether the retulting expression `e` unifies with `val`. This last check is necessary, because `val` and `e` might have different types. -/ meta def is_eta_expansion_aux (val : expr) (l : list (name × expr)) : tactic (option expr) := do l' ← l.mfilter (λ⟨proj, val⟩, bnot <$> is_proof val), match is_eta_expansion_test l' with | some e := option.map (λ _, e) <$> try_core (unify e val) | none := return none end /-- `is_eta_expansion val` checks whether there is an expression `e` such that `val` is the eta-expansion of `e`. With eta-expansion we here mean the eta-expansion of a structure, not of a function. For example, the eta-expansion of `x : α × β` is `⟨x.1, x.2⟩`. This assumes that `val` is a fully-applied application of the constructor of a structure. This is useful to reduce expressions generated by the notation `{ field_1 := _, ..other_structure }` If `other_structure` is itself a field of the structure, then the elaborator will insert an eta-expanded version of `other_structure`. -/ meta def is_eta_expansion (val : expr) : tactic (option expr) := do e ← get_env, type ← infer_type val, projs ← e.get_projections type.get_app_fn.const_name, let args := (val.get_app_args).drop type.get_app_args.length, is_eta_expansion_aux val (projs.zip args) end expr namespace declaration open tactic protected meta def update_with_fun (f : name → name) (tgt : name) (decl : declaration) : declaration := let decl := decl.update_name $ tgt in let decl := decl.update_type $ decl.type.apply_replacement_fun f in decl.update_value $ decl.value.apply_replacement_fun f /-- Checks whether the declaration is declared in the current file. This is a simple wrapper around `environment.in_current_file'` Use `environment.in_current_file'` instead if performance matters. -/ meta def in_current_file (d : declaration) : tactic bool := do e ← get_env, return $ e.in_current_file' d.to_name /-- Checks whether a declaration is a theorem -/ meta def is_theorem : declaration → bool | (thm _ _ _ _) := tt | _ := ff /-- Checks whether a declaration is a constant -/ meta def is_constant : declaration → bool | (cnst _ _ _ _) := tt | _ := ff /-- Checks whether a declaration is a axiom -/ meta def is_axiom : declaration → bool | (ax _ _ _) := tt | _ := ff /-- Checks whether a declaration is automatically generated in the environment. There is no cheap way to check whether a declaration in the namespace of a generalized inductive type is automatically generated, so for now we say that all of them are automatically generated. -/ meta def is_auto_generated (e : environment) (d : declaration) : bool := e.is_constructor d.to_name ∨ (e.is_projection d.to_name).is_some ∨ (e.is_constructor d.to_name.get_prefix ∧ d.to_name.last ∈ ["inj", "inj_eq", "sizeof_spec", "inj_arrow"]) ∨ (e.is_inductive d.to_name.get_prefix ∧ d.to_name.last ∈ ["below", "binduction_on", "brec_on", "cases_on", "dcases_on", "drec_on", "drec", "rec", "rec_on", "no_confusion", "no_confusion_type", "sizeof", "ibelow", "has_sizeof_inst"]) ∨ d.to_name.has_prefix (λ nm, e.is_ginductive' nm) /-- Returns the list of universe levels of a declaration. -/ meta def univ_levels (d : declaration) : list level := d.univ_params.map level.param end declaration
fb84359e0399870f713d32252a3d8e538e0eea0d
63abd62053d479eae5abf4951554e1064a4c45b4
/src/algebra/big_operators/finsupp.lean
ac144b4c7695fa6e7812b1e9f367208a59b05928
[ "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
1,245
lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import algebra.big_operators.pi import data.finsupp /-! # Big operators for finsupps This file contains theorems relevant to big operators in finitely supported functions. -/ universes u v w u₁ v₁ w₁ open_locale big_operators variables {α : Type u} {ι : Type v} {β : Type w} [add_comm_monoid β] variables {s : finset α} {f : α → (ι →₀ β)} (i : ι) theorem finset.sum_apply' : (∑ k in s, f k) i = ∑ k in s, f k i := (s.sum_hom $ finsupp.eval_add_hom i).symm variables {γ : Type u₁} {δ : Type v₁} [add_comm_monoid δ] variables (g : ι →₀ β) (k : ι → β → γ → δ) (x : γ) theorem finsupp.sum_apply' : g.sum k x = g.sum (λ i b, k i b x) := finset.sum_apply _ _ _ variables {ε : Type w₁} [add_comm_monoid ε] variables {t : ι → β → ε} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y) include h0 h1 open_locale classical theorem finsupp.sum_sum_index' : (∑ x in s, f x).sum t = ∑ x in s, (f x).sum t := finset.induction_on s rfl $ λ a s has ih, by simp_rw [finset.sum_insert has, finsupp.sum_add_index h0 h1, ih]
249fca363fbc6a8c18ae9468adba2aefb19ab496
38ee9024fb5974f555fb578fcf5a5a7b71e669b5
/Mathlib/Tactic/Core.lean
904b65953b623ce248d049733308e3c09954079d
[ "Apache-2.0" ]
permissive
denayd/mathlib4
750e0dcd106554640a1ac701e51517501a574715
7f40a5c514066801ab3c6d431e9f405baa9b9c58
refs/heads/master
1,693,743,991,894
1,636,618,048,000
1,636,618,048,000
373,926,241
0
0
null
null
null
null
UTF-8
Lean
false
false
899
lean
/- Copyright (c) 2021 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Aurélien Saue -/ import Lean.Expr namespace Lean.Parser.Tactic -- syntax simpArg := simpStar <|> simpErase <|> simpLemma def simpArg := simpStar.binary `orelse (simpErase.binary `orelse simpLemma) end Lean.Parser.Tactic namespace Lean.Expr private def getAppFnArgsAux : Expr → Array Expr → Nat → Name × Array Expr | app f a _, as, i => getAppFnArgsAux f (as.set! i a) (i-1) | const n _ _, as, i => (n, as) | _, as, _ => (Name.anonymous, as) def getAppFnArgs (e : Expr) : Name × Array Expr := let nargs := e.getAppNumArgs getAppFnArgsAux e (mkArray nargs arbitrary) (nargs-1) def natLit! : Expr → Nat | lit (Literal.natVal v) _ => v | _ => panic! "nat literal expected" end Expr
f51e240b3f8bd6ab9af6f524914c8ffd392445c7
968e2f50b755d3048175f176376eff7139e9df70
/examples/prop_logic_theory/unnamed_2495.lean
428841cc4f9259c66937d8b4853cbf81a37e0f9f
[]
no_license
gihanmarasingha/mth1001_sphinx
190a003269ba5e54717b448302a27ca26e31d491
05126586cbf5786e521be1ea2ef5b4ba3c44e74a
refs/heads/master
1,672,913,933,677
1,604,516,583,000
1,604,516,583,000
309,245,750
1
0
null
null
null
null
UTF-8
Lean
false
false
826
lean
variables {p q : Prop} -- BEGIN local attribute [instance] classical.prop_decidable theorem not_or_not_of_not_and : ¬(p ∧ q) → ¬p ∨ ¬q := begin assume h₁ : ¬(p ∧ q), -- Assume `h₁ : ¬(p ∧ q)`. It suffices to prove `¬p ∨ ¬q`. -- Via proof by cases, it suffices to prove we can derive `¬p ∨ ¬q` 1. assuming `h₂ : p` and 2. assuming `h₂ : ¬p`. by_cases h₂ : p, { right, -- Assume `h₂ : p`. By right or introduction, it suffices to prove `¬q`. assume h₃ : q, -- Assume `h₃ : q`. By negation introduction, it suffices to prove `false`. apply h₁, -- By false introduction on `h₁`, it suffices to prove `p ∧ q`. exact ⟨h₂, h₃⟩, }, -- This follows by and introduction on `h₂` and `h₃`. { sorry }, end -- END
6cd3fd2aaffe393615370e1015d94f9cbbee0ce7
957a80ea22c5abb4f4670b250d55534d9db99108
/tests/lean/mk_constructor_fresh_names.lean
2e699043731f065b20328a666e5bbed35a5f5045
[ "Apache-2.0" ]
permissive
GaloisInc/lean
aa1e64d604051e602fcf4610061314b9a37ab8cd
f1ec117a24459b59c6ff9e56a1d09d9e9e60a6c0
refs/heads/master
1,592,202,909,807
1,504,624,387,000
1,504,624,387,000
75,319,626
2
1
Apache-2.0
1,539,290,164,000
1,480,616,104,000
C++
UTF-8
Lean
false
false
519
lean
open tactic example (fst fst_1 : nat) : fst = fst := by do ns ← mk_constructors_fresh_names `prod, trace ns, -- [[fst_2, snd]] constructor example (a : nat) : a = a := by do ns ← mk_constructors_fresh_names `acc, trace ns, -- [[x, a_1] constructor inductive Foo | mk₁ (a b c : nat) : Foo | mk₂ (d e : bool) : Foo | mk₃ (f g : Foo) : Foo example (a d d_1 e : bool) : a = a := by do ns ← mk_constructors_fresh_names `Foo, trace ns, -- [[a_1, b, c], [d_2, e_1], [f, g]] constructor