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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
91e88babe3c0dc77775cadfb80a82ef5da2be328 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/algebra/group_ring_action/basic.lean | 539cca73b344f90f020421b0e56ada6a0a5653c0 | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 2,973 | 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.ring.equiv
import algebra.field.defs
import group_theory.group_action.group
/-!
# Group action on rings
This file defines the typeclass of monoid acting on semirings `mul_semiring_action M R`,
and the corresponding typeclass of invariant subrings.
Note that `algebra` does not satisfy the axioms of `mul_semiring_action`.
## Implementation notes
There is no separate typeclass for group acting on rings, group acting on fields, etc.
They are all grouped under `mul_semiring_action`.
## Tags
group action, invariant subring
-/
universes u v
/-- Typeclass for multiplicative actions by monoids on semirings.
This combines `distrib_mul_action` with `mul_distrib_mul_action`. -/
class mul_semiring_action (M : Type u) (R : Type v) [monoid M] [semiring R]
extends distrib_mul_action M R :=
(smul_one : ∀ (g : M), (g • 1 : R) = 1)
(smul_mul : ∀ (g : M) (x y : R), g • (x * y) = (g • x) * (g • y))
section semiring
variables (M N G : Type*) [monoid M] [monoid N] [group G]
variables (A R S F : Type v) [add_monoid A] [semiring R] [comm_semiring S] [division_ring F]
-- note we could not use `extends` since these typeclasses are made with `old_structure_cmd`
@[priority 100]
instance mul_semiring_action.to_mul_distrib_mul_action [h : mul_semiring_action M R] :
mul_distrib_mul_action M R :=
{ ..h }
/-- Each element of the monoid defines a semiring homomorphism. -/
@[simps]
def mul_semiring_action.to_ring_hom [mul_semiring_action M R] (x : M) : R →+* R :=
{ .. mul_distrib_mul_action.to_monoid_hom R x,
.. distrib_mul_action.to_add_monoid_hom R x }
theorem to_ring_hom_injective [mul_semiring_action M R] [has_faithful_smul M R] :
function.injective (mul_semiring_action.to_ring_hom M R) :=
λ m₁ m₂ h, eq_of_smul_eq_smul $ λ r, ring_hom.ext_iff.1 h r
/-- Each element of the group defines a semiring isomorphism. -/
@[simps]
def mul_semiring_action.to_ring_equiv [mul_semiring_action G R] (x : G) : R ≃+* R :=
{ .. distrib_mul_action.to_add_equiv R x,
.. mul_semiring_action.to_ring_hom G R x }
section
variables {M N}
/-- Compose a `mul_semiring_action` with a `monoid_hom`, with action `f r' • m`.
See note [reducible non-instances]. -/
@[reducible] def mul_semiring_action.comp_hom (f : N →* M) [mul_semiring_action M R] :
mul_semiring_action N R :=
{ smul := has_smul.comp.smul f,
..distrib_mul_action.comp_hom R f,
..mul_distrib_mul_action.comp_hom R f }
end
section simp_lemmas
variables {M G A R F}
attribute [simp] smul_one smul_mul' smul_zero smul_add
/-- Note that `smul_inv'` refers to the group case, and `smul_inv` has an additional inverse
on `x`. -/
@[simp] lemma smul_inv'' [mul_semiring_action M F] (x : M) (m : F) : x • m⁻¹ = (x • m)⁻¹ :=
map_inv₀ (mul_semiring_action.to_ring_hom M F x) _
end simp_lemmas
end semiring
|
e9e762fc16a6cc941a44ff77f7a87a9dcdb30a96 | 54f4ad05b219d444b709f56c2f619dd87d14ec29 | /my_project/src/lovelib.lean | 8c327e0e000fc684e41c96f5c96c46e4c6883f79 | [] | no_license | yizhou7/learning-lean | 8efcf838c7276e235a81bd291f467fa43ce56e0a | 91fb366c624df6e56e19555b2e482ce767cd8224 | refs/heads/master | 1,675,649,087,737 | 1,609,022,281,000 | 1,609,022,281,000 | 272,072,779 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,789 | lean | import algebra
import data.real.basic
import logic.basic
import order
import tactic.explode
import tactic.find
import tactic.linarith
import tactic.rcases
import tactic.rewrite
import tactic.ring_exp
import tactic.tidy
import tactic.where
/-! # LoVe Library
This files contains a few extensions on top of Lean's core libraries and
`mathlib`. -/
namespace LoVe
/-! ## Structured Proofs -/
notation `fix ` binders `, ` r:(scoped f, f) := r
/-! ## Logical Connectives -/
attribute [pattern] or.intro_left or.intro_right
meta def tactic.dec_trivial := `[exact dec_trivial]
lemma not_def (a : Prop) :
¬ a ↔ a → false :=
by refl
@[simp] lemma not_not_iff (a : Prop) [decidable a] :
¬¬ a ↔ a :=
by by_cases a; simp [h]
@[simp] lemma and_imp_distrib (a b c : Prop) :
(a ∧ b → c) ↔ (a → b → c) :=
iff.intro
(assume h ha hb, h ⟨ha, hb⟩)
(assume h ⟨ha, hb⟩, h ha hb)
@[simp] lemma or_imp_distrib {a b c : Prop} :
a ∨ b → c ↔ (a → c) ∧ (b → c) :=
iff.intro
(assume h,
⟨assume ha, h (or.intro_left _ ha), assume hb, h (or.intro_right _ hb)⟩)
(assume ⟨ha, hb⟩ h, match h with or.inl h := ha h | or.inr h := hb h end)
@[simp] lemma exists_imp_distrib {α : Sort*} {p : α → Prop} {a : Prop} :
((∃x, p x) → a) ↔ (∀x, p x → a) :=
iff.intro
(assume h hp ha, h ⟨hp, ha⟩)
(assume h ⟨hp, ha⟩, h hp ha)
lemma and_exists {α : Sort*} {p : α → Prop} {a : Prop} :
(a ∧ (∃x, p x)) ↔ (∃x, a ∧ p x) :=
iff.intro
(assume ⟨ha, x, hp⟩, ⟨x, ha, hp⟩)
(assume ⟨x, ha, hp⟩, ⟨ha, x, hp⟩)
@[simp] lemma exists_false {α : Sort*} :
(∃x : α, false) ↔ false :=
iff.intro (assume ⟨a, f⟩, f) (assume h, h.elim)
/-! ## Natural Numbers -/
attribute [simp] nat.add
/-! ## Integers -/
@[simp] lemma int.neg_comp_neg :
int.neg ∘ int.neg = id :=
begin
apply funext,
apply neg_neg
end
/-! ## Reflexive Transitive Closure -/
namespace rtc
inductive star {α : Sort*} (r : α → α → Prop) (a : α) : α → Prop
| refl {} : star a
| tail {b c} : star b → r b c → star c
attribute [refl] star.refl
namespace star
variables {α : Sort*} {r : α → α → Prop} {a b c d : α}
@[trans] lemma trans (hab : star r a b) (hbc : star r b c) :
star r a c :=
begin
induction hbc,
case star.refl {
assumption },
case star.tail : c d hbc hcd hac {
exact hac.tail hcd }
end
lemma single (hab : r a b) :
star r a b :=
refl.tail hab
lemma head (hab : r a b) (hbc : star r b c) :
star r a c :=
begin
induction hbc,
case star.refl {
exact refl.tail hab },
case star.tail : c d hbc hcd hac {
exact hac.tail hcd }
end
lemma head_induction_on {α : Sort*} {r : α → α → Prop} {b : α}
{P : ∀a : α, star r a b → Prop} {a : α} (h : star r a b)
(refl : P b refl)
(head : ∀{a c} (h' : r a c) (h : star r c b), P c h → P a (h.head h')) :
P a h :=
begin
induction h generalizing P,
case star.refl {
exact refl },
case star.tail : b c hab hbc ih {
apply ih,
show P b _, from
head hbc _ refl,
show ∀a a', r a a' → star r a' b → P a' _ → P a _, from
assume a a' hab hbc, head hab _ }
end
lemma trans_induction_on {α : Sort*} {r : α → α → Prop}
{p : ∀{a b : α}, star r a b → Prop} {a b : α} (h : star r a b)
(ih₁ : ∀a, @p a a refl) (ih₂ : ∀{a b} (h : r a b), p (single h))
(ih₃ : ∀{a b c} (h₁ : star r a b) (h₂ : star r b c), p h₁ →
p h₂ → p (h₁.trans h₂)) :
p h :=
begin
induction h,
case star.refl {
exact ih₁ a },
case star.tail : b c hab hbc ih {
exact ih₃ hab (single hbc) ih (ih₂ hbc) }
end
lemma lift {β : Sort*} {s : β → β → Prop} (f : α → β)
(h : ∀a b, r a b → s (f a) (f b)) (hab : star r a b) :
star s (f a) (f b) :=
hab.trans_induction_on
(assume a, refl)
(assume a b, single ∘ h _ _)
(assume a b c _ _, trans)
lemma mono {p : α → α → Prop} :
(∀a b, r a b → p a b) → star r a b → star p a b :=
lift id
lemma star_star_eq :
star (star r) = star r :=
funext
(assume a,
funext
(assume b,
propext (iff.intro
(assume h,
begin
induction h,
{ refl },
{ transitivity;
assumption }
end)
(star.mono (assume a b,
single)))))
end star
end rtc
export rtc
/-! ## States -/
def state :=
string → ℕ
def state.update (name : string) (val : ℕ) (s : state) : state :=
λname', if name' = name then val else s name'
notation s `{` name ` ↦ ` val `}` := state.update name val s
instance : has_emptyc state :=
{ emptyc := λ_, 0 }
@[simp] lemma update_apply (name : string) (val : ℕ) (s : state) :
s{name ↦ val} name = val :=
if_pos rfl
@[simp] lemma update_apply_ne (name name' : string) (val : ℕ) (s : state)
(h : name' ≠ name . tactic.dec_trivial) :
s{name ↦ val} name' = s name' :=
if_neg h
@[simp] lemma update_override (name : string) (val₁ val₂ : ℕ) (s : state) :
s{name ↦ val₂}{name ↦ val₁} = s{name ↦ val₁} :=
begin
apply funext,
intro name',
by_cases name' = name;
simp [h]
end
@[simp] lemma update_swap (name₁ name₂ : string) (val₁ val₂ : ℕ) (s : state)
(h : name₁ ≠ name₂ . tactic.dec_trivial) :
s{name₂ ↦ val₂}{name₁ ↦ val₁} = s{name₁ ↦ val₁}{name₂ ↦ val₂} :=
begin
apply funext,
intro name',
by_cases name' = name₁;
by_cases name' = name₂;
simp * at *
end
@[simp] lemma update_id (name : string) (s : state) :
s{name ↦ s name} = s :=
begin
apply funext,
intro name',
by_cases name' = name;
simp * at *
end
example (s : state) :
s{"a" ↦ 0}{"a" ↦ 2} = s{"a" ↦ 2} :=
by simp
example (s : state) :
s{"a" ↦ 0}{"b" ↦ 2} = s{"b" ↦ 2}{"a" ↦ 0} :=
by simp
example (s : state) :
s{"a" ↦ s "a"}{"b" ↦ 0} = s{"b" ↦ 0} :=
by simp
/-! ## Relations -/
def Id {α : Type} : set (α × α) :=
{ab | prod.snd ab = prod.fst ab}
@[simp] lemma mem_Id {α : Type} (a b : α) :
(a, b) ∈ @Id α ↔ b = a :=
by refl
def comp {α : Type} (r₁ r₂ : set (α × α)) : set (α × α) :=
{ac | ∃b, (prod.fst ac, b) ∈ r₁ ∧ (b, prod.snd ac) ∈ r₂}
infixl ` ◯ ` : 90 := comp
@[simp] lemma mem_comp {α : Type} (r₁ r₂ : set (α × α))
(a b : α) :
(a, b) ∈ r₁ ◯ r₂ ↔ (∃c, (a, c) ∈ r₁ ∧ (c, b) ∈ r₂) :=
by refl
def restrict {α : Type} (r : set (α × α)) (p : α → Prop) :
set (α × α) :=
{ab | p (prod.fst ab) ∧ ab ∈ r}
infixl ` ⇃ ` : 90 := restrict
@[simp] lemma mem_restrict {α : Type} (r : set (α × α))
(p : α → Prop) (a b : α) :
(a, b) ∈ r ⇃ p ↔ p a ∧ (a, b) ∈ r :=
by refl
end LoVe
|
1205e21c849b7bad5dce654809b724fefda4f01b | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/consume.lean | e8d6b5d6eebd5e8ed397b62cfb74918baf8ef6e8 | [
"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 | 123 | lean | definition pr2 {A : Type} (a b : A) := a
#check pr2
#check pr2
#check pr2
#check @pr2
#check @pr2
#check @@pr2
#check pr2
|
23f6ea209c67e86b85fb8387e30361985349005a | b7f22e51856f4989b970961f794f1c435f9b8f78 | /hott/init/path.hlean | c7114d9b66b7419780e3ace7ab77847cfd81a79f | [
"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 | 30,528 | hlean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Jakob von Raumer, Floris van Doorn
Ported from Coq HoTT
-/
prelude
import .function .tactic
open function eq
/- Path equality -/
namespace eq
variables {A B C : Type} {P : A → Type} {a a' x y z t : A} {b b' : B}
--notation a = b := eq a b
notation x = y `:>`:50 A:49 := @eq A x y
definition idp [reducible] [constructor] {a : A} := refl a
definition idpath [reducible] [constructor] (a : A) := refl a
-- unbased path induction
definition rec' [reducible] [unfold 6] {P : Π (a b : A), (a = b) → Type}
(H : Π (a : A), P a a idp) {a b : A} (p : a = b) : P a b p :=
eq.rec (H a) p
definition rec_on' [reducible] [unfold 5] {P : Π (a b : A), (a = b) → Type}
{a b : A} (p : a = b) (H : Π (a : A), P a a idp) : P a b p :=
eq.rec (H a) p
/- Concatenation and inverse -/
definition concat [trans] [unfold 6] (p : x = y) (q : y = z) : x = z :=
by induction q; exact p
definition inverse [symm] [unfold 4] (p : x = y) : y = x :=
by induction p; reflexivity
infix ⬝ := concat
postfix ⁻¹ := inverse
--a second notation for the inverse, which is not overloaded
postfix [parsing_only] `⁻¹ᵖ`:std.prec.max_plus := inverse
/- The 1-dimensional groupoid structure -/
-- The identity path is a right unit.
definition con_idp [unfold_full] (p : x = y) : p ⬝ idp = p :=
idp
-- The identity path is a left unit.
definition idp_con [unfold 4] (p : x = y) : idp ⬝ p = p :=
by induction p; reflexivity
-- Concatenation is associative.
definition con.assoc' (p : x = y) (q : y = z) (r : z = t) :
p ⬝ (q ⬝ r) = (p ⬝ q) ⬝ r :=
by induction r; reflexivity
definition con.assoc (p : x = y) (q : y = z) (r : z = t) :
(p ⬝ q) ⬝ r = p ⬝ (q ⬝ r) :=
by induction r; reflexivity
definition con.assoc5 {a₁ a₂ a₃ a₄ a₅ a₆ : A}
(p₁ : a₁ = a₂) (p₂ : a₂ = a₃) (p₃ : a₃ = a₄) (p₄ : a₄ = a₅) (p₅ : a₅ = a₆) :
p₁ ⬝ (p₂ ⬝ p₃ ⬝ p₄) ⬝ p₅ = (p₁ ⬝ p₂) ⬝ p₃ ⬝ (p₄ ⬝ p₅) :=
by induction p₅; induction p₄; induction p₃; reflexivity
-- The left inverse law.
definition con.right_inv [unfold 4] (p : x = y) : p ⬝ p⁻¹ = idp :=
by induction p; reflexivity
-- The right inverse law.
definition con.left_inv [unfold 4] (p : x = y) : p⁻¹ ⬝ p = idp :=
by induction p; reflexivity
/- Several auxiliary theorems about canceling inverses across associativity. These are somewhat
redundant, following from earlier theorems. -/
definition inv_con_cancel_left (p : x = y) (q : y = z) : p⁻¹ ⬝ (p ⬝ q) = q :=
by induction q; induction p; reflexivity
definition con_inv_cancel_left (p : x = y) (q : x = z) : p ⬝ (p⁻¹ ⬝ q) = q :=
by induction q; induction p; reflexivity
definition con_inv_cancel_right (p : x = y) (q : y = z) : (p ⬝ q) ⬝ q⁻¹ = p :=
by induction q; reflexivity
definition inv_con_cancel_right (p : x = z) (q : y = z) : (p ⬝ q⁻¹) ⬝ q = p :=
by induction q; reflexivity
-- Inverse distributes over concatenation
definition con_inv (p : x = y) (q : y = z) : (p ⬝ q)⁻¹ = q⁻¹ ⬝ p⁻¹ :=
by induction q; induction p; reflexivity
definition inv_con_inv_left (p : y = x) (q : y = z) : (p⁻¹ ⬝ q)⁻¹ = q⁻¹ ⬝ p :=
by induction q; induction p; reflexivity
definition inv_con_inv_right (p : x = y) (q : z = y) : (p ⬝ q⁻¹)⁻¹ = q ⬝ p⁻¹ :=
by induction q; induction p; reflexivity
definition inv_con_inv_inv (p : y = x) (q : z = y) : (p⁻¹ ⬝ q⁻¹)⁻¹ = q ⬝ p :=
by induction q; induction p; reflexivity
-- Inverse is an involution.
definition inv_inv [unfold 4] (p : x = y) : p⁻¹⁻¹ = p :=
by induction p; reflexivity
-- auxiliary definition used by 'cases' tactic
definition elim_inv_inv [unfold 5] {A : Type} {a b : A} {C : a = b → Type}
(H₁ : a = b) (H₂ : C (H₁⁻¹⁻¹)) : C H₁ :=
eq.rec_on (inv_inv H₁) H₂
/- Theorems for moving things around in equations -/
definition con_eq_of_eq_inv_con {p : x = z} {q : y = z} {r : y = x} :
p = r⁻¹ ⬝ q → r ⬝ p = q :=
begin
induction r, intro h, exact !idp_con ⬝ h ⬝ !idp_con
end
definition con_eq_of_eq_con_inv [unfold 5] {p : x = z} {q : y = z} {r : y = x} :
r = q ⬝ p⁻¹ → r ⬝ p = q :=
by induction p; exact id
definition inv_con_eq_of_eq_con {p : x = z} {q : y = z} {r : x = y} :
p = r ⬝ q → r⁻¹ ⬝ p = q :=
by induction r; intro h; exact !idp_con ⬝ h ⬝ !idp_con
definition con_inv_eq_of_eq_con [unfold 5] {p : z = x} {q : y = z} {r : y = x} :
r = q ⬝ p → r ⬝ p⁻¹ = q :=
by induction p; exact id
definition eq_con_of_inv_con_eq {p : x = z} {q : y = z} {r : y = x} :
r⁻¹ ⬝ q = p → q = r ⬝ p :=
by induction r; intro h; exact !idp_con⁻¹ ⬝ h ⬝ !idp_con⁻¹
definition eq_con_of_con_inv_eq [unfold 5] {p : x = z} {q : y = z} {r : y = x} :
q ⬝ p⁻¹ = r → q = r ⬝ p :=
by induction p; exact id
definition eq_inv_con_of_con_eq {p : x = z} {q : y = z} {r : x = y} :
r ⬝ q = p → q = r⁻¹ ⬝ p :=
by induction r; intro h; exact !idp_con⁻¹ ⬝ h ⬝ !idp_con⁻¹
definition eq_con_inv_of_con_eq [unfold 5] {p : z = x} {q : y = z} {r : y = x} :
q ⬝ p = r → q = r ⬝ p⁻¹ :=
by induction p; exact id
definition eq_of_con_inv_eq_idp [unfold 5] {p q : x = y} : p ⬝ q⁻¹ = idp → p = q :=
by induction q; exact id
definition eq_of_inv_con_eq_idp {p q : x = y} : q⁻¹ ⬝ p = idp → p = q :=
by induction q; intro h; exact !idp_con⁻¹ ⬝ h
definition eq_inv_of_con_eq_idp' [unfold 5] {p : x = y} {q : y = x} : p ⬝ q = idp → p = q⁻¹ :=
by induction q; exact id
definition eq_inv_of_con_eq_idp {p : x = y} {q : y = x} : q ⬝ p = idp → p = q⁻¹ :=
by induction q; intro h; exact !idp_con⁻¹ ⬝ h
definition eq_of_idp_eq_inv_con {p q : x = y} : idp = p⁻¹ ⬝ q → p = q :=
by induction p; intro h; exact h ⬝ !idp_con
definition eq_of_idp_eq_con_inv [unfold 4] {p q : x = y} : idp = q ⬝ p⁻¹ → p = q :=
by induction p; exact id
definition inv_eq_of_idp_eq_con [unfold 4] {p : x = y} {q : y = x} : idp = q ⬝ p → p⁻¹ = q :=
by induction p; exact id
definition inv_eq_of_idp_eq_con' {p : x = y} {q : y = x} : idp = p ⬝ q → p⁻¹ = q :=
by induction p; intro h; exact h ⬝ !idp_con
definition con_inv_eq_idp [unfold 6] {p q : x = y} (r : p = q) : p ⬝ q⁻¹ = idp :=
by cases r; apply con.right_inv
definition inv_con_eq_idp [unfold 6] {p q : x = y} (r : p = q) : q⁻¹ ⬝ p = idp :=
by cases r; apply con.left_inv
definition con_eq_idp {p : x = y} {q : y = x} (r : p = q⁻¹) : p ⬝ q = idp :=
by cases q; exact r
definition idp_eq_inv_con {p q : x = y} (r : p = q) : idp = p⁻¹ ⬝ q :=
by cases r; exact !con.left_inv⁻¹
definition idp_eq_con_inv {p q : x = y} (r : p = q) : idp = q ⬝ p⁻¹ :=
by cases r; exact !con.right_inv⁻¹
definition idp_eq_con {p : x = y} {q : y = x} (r : p⁻¹ = q) : idp = q ⬝ p :=
by cases p; exact r
definition eq_idp_of_con_right {p : x = x} {q : x = y} (r : p ⬝ q = q) : p = idp :=
by cases q; exact r
definition eq_idp_of_con_left {p : x = x} {q : y = x} (r : q ⬝ p = q) : p = idp :=
by cases q; exact (idp_con p)⁻¹ ⬝ r
definition idp_eq_of_con_right {p : x = x} {q : x = y} (r : q = p ⬝ q) : idp = p :=
by cases q; exact r
definition idp_eq_of_con_left {p : x = x} {q : y = x} (r : q = q ⬝ p) : idp = p :=
by cases q; exact r ⬝ idp_con p
/- Transport -/
definition transport [subst] [reducible] [unfold 5] (P : A → Type) {x y : A} (p : x = y)
(u : P x) : P y :=
by induction p; exact u
-- This idiom makes the operation right associative.
infixr ` ▸ ` := transport _
definition cast [reducible] [unfold 3] {A B : Type} (p : A = B) (a : A) : B :=
p ▸ a
definition cast_def [reducible] [unfold_full] {A B : Type} (p : A = B) (a : A)
: cast p a = p ▸ a :=
idp
definition tr_rev [reducible] [unfold 6] (P : A → Type) {x y : A} (p : x = y) (u : P y) : P x :=
p⁻¹ ▸ u
definition ap [unfold 6] ⦃A B : Type⦄ (f : A → B) {x y:A} (p : x = y) : f x = f y :=
by induction p; reflexivity
abbreviation ap01 [parsing_only] := ap
definition homotopy [reducible] (f g : Πx, P x) : Type :=
Πx : A, f x = g x
infix ~ := homotopy
protected definition homotopy.refl [refl] [reducible] [unfold_full] (f : Πx, P x) : f ~ f :=
λ x, idp
protected definition homotopy.symm [symm] [reducible] [unfold_full] {f g : Πx, P x} (H : f ~ g)
: g ~ f :=
λ x, (H x)⁻¹
protected definition homotopy.trans [trans] [reducible] [unfold_full] {f g h : Πx, P x}
(H1 : f ~ g) (H2 : g ~ h) : f ~ h :=
λ x, H1 x ⬝ H2 x
definition hwhisker_left [unfold_full] (g : B → C) {f f' : A → B} (H : f ~ f') :
g ∘ f ~ g ∘ f' :=
λa, ap g (H a)
definition hwhisker_right [unfold_full] (f : A → B) {g g' : B → C} (H : g ~ g') :
g ∘ f ~ g' ∘ f :=
λa, H (f a)
definition homotopy_of_eq {f g : Πx, P x} (H1 : f = g) : f ~ g :=
H1 ▸ homotopy.refl f
definition apd10 [unfold 5] {f g : Πx, P x} (H : f = g) : f ~ g :=
λx, by induction H; reflexivity
--the next theorem is useful if you want to write "apply (apd10' a)"
definition apd10' [unfold 6] {f g : Πx, P x} (a : A) (H : f = g) : f a = g a :=
by induction H; reflexivity
--apd10 is also ap evaluation
definition apd10_eq_ap_eval {f g : Πx, P x} (H : f = g) (a : A)
: apd10 H a = ap (λs : Πx, P x, s a) H :=
by induction H; reflexivity
definition ap10 [reducible] [unfold 5] {f g : A → B} (H : f = g) : f ~ g := apd10 H
definition ap11 {f g : A → B} (H : f = g) {x y : A} (p : x = y) : f x = g y :=
by induction H; exact ap f p
-- [apd] is defined in init.pathover using pathover instead of an equality with transport.
definition apdt [unfold 6] (f : Πa, P a) {x y : A} (p : x = y) : p ▸ f x = f y :=
by induction p; reflexivity
definition ap011 [unfold 9] (f : A → B → C) (Ha : a = a') (Hb : b = b') : f a b = f a' b' :=
by cases Ha; exact ap (f a) Hb
/- More theorems for moving things around in equations -/
definition tr_eq_of_eq_inv_tr {P : A → Type} {x y : A} {p : x = y} {u : P x} {v : P y} :
u = p⁻¹ ▸ v → p ▸ u = v :=
by induction p; exact id
definition inv_tr_eq_of_eq_tr {P : A → Type} {x y : A} {p : y = x} {u : P x} {v : P y} :
u = p ▸ v → p⁻¹ ▸ u = v :=
by induction p; exact id
definition eq_inv_tr_of_tr_eq {P : A → Type} {x y : A} {p : x = y} {u : P x} {v : P y} :
p ▸ u = v → u = p⁻¹ ▸ v :=
by induction p; exact id
definition eq_tr_of_inv_tr_eq {P : A → Type} {x y : A} {p : y = x} {u : P x} {v : P y} :
p⁻¹ ▸ u = v → u = p ▸ v :=
by induction p; exact id
/- Transporting along the diagonal of a type family -/
definition tr_diag_eq_tr_tr {A : Type} (P : A → A → Type) {x y : A} (p : x = y) (a : P x x) :
transport (λ x, P x x) p a = transport (λ x, P _ x) p (transport (λ x, P x _) p a) :=
by induction p; reflexivity
/- Functoriality of functions -/
-- Here we prove that functions behave like functors between groupoids, and that [ap] itself is
-- functorial.
-- Functions take identity paths to identity paths
definition ap_idp [unfold_full] (x : A) (f : A → B) : ap f idp = idp :> (f x = f x) := idp
-- Functions commute with concatenation.
definition ap_con [unfold 8] (f : A → B) {x y z : A} (p : x = y) (q : y = z) :
ap f (p ⬝ q) = ap f p ⬝ ap f q :=
by induction q; reflexivity
definition con_ap_con_eq_con_ap_con_ap (f : A → B) {w x y z : A} (r : f w = f x)
(p : x = y) (q : y = z) : r ⬝ ap f (p ⬝ q) = (r ⬝ ap f p) ⬝ ap f q :=
by induction q; induction p; reflexivity
definition ap_con_con_eq_ap_con_ap_con (f : A → B) {w x y z : A} (p : x = y) (q : y = z)
(r : f z = f w) : ap f (p ⬝ q) ⬝ r = ap f p ⬝ (ap f q ⬝ r) :=
by induction q; induction p; apply con.assoc
-- Functions commute with path inverses.
definition ap_inv' [unfold 6] (f : A → B) {x y : A} (p : x = y) : (ap f p)⁻¹ = ap f p⁻¹ :=
by induction p; reflexivity
definition ap_inv [unfold 6] (f : A → B) {x y : A} (p : x = y) : ap f p⁻¹ = (ap f p)⁻¹ :=
by induction p; reflexivity
-- [ap] itself is functorial in the first argument.
definition ap_id [unfold 4] (p : x = y) : ap id p = p :=
by induction p; reflexivity
definition ap_compose [unfold 8] (g : B → C) (f : A → B) {x y : A} (p : x = y) :
ap (g ∘ f) p = ap g (ap f p) :=
by induction p; reflexivity
-- Sometimes we don't have the actual function [compose].
definition ap_compose' [unfold 8] (g : B → C) (f : A → B) {x y : A} (p : x = y) :
ap (λa, g (f a)) p = ap g (ap f p) :=
by induction p; reflexivity
-- The action of constant maps.
definition ap_constant [unfold 5] (p : x = y) (z : B) : ap (λu, z) p = idp :=
by induction p; reflexivity
-- Naturality of [ap].
-- see also natural_square in cubical.square
definition ap_con_eq_con_ap {f g : A → B} (p : f ~ g) {x y : A} (q : x = y) :
ap f q ⬝ p y = p x ⬝ ap g q :=
by induction q; apply idp_con
-- Naturality of [ap] at identity.
definition ap_con_eq_con {f : A → A} (p : Πx, f x = x) {x y : A} (q : x = y) :
ap f q ⬝ p y = p x ⬝ q :=
by induction q; apply idp_con
definition con_ap_eq_con {f : A → A} (p : Πx, x = f x) {x y : A} (q : x = y) :
p x ⬝ ap f q = q ⬝ p y :=
by induction q; exact !idp_con⁻¹
-- Naturality of [ap] with constant function
definition ap_con_eq {f : A → B} {b : B} (p : Πx, f x = b) {x y : A} (q : x = y) :
ap f q ⬝ p y = p x :=
by induction q; apply idp_con
-- Naturality with other paths hanging around.
definition con_ap_con_con_eq_con_con_ap_con {f g : A → B} (p : f ~ g) {x y : A} (q : x = y)
{w z : B} (r : w = f x) (s : g y = z) :
(r ⬝ ap f q) ⬝ (p y ⬝ s) = (r ⬝ p x) ⬝ (ap g q ⬝ s) :=
by induction s; induction q; reflexivity
definition con_ap_con_eq_con_con_ap {f g : A → B} (p : f ~ g) {x y : A} (q : x = y)
{w : B} (r : w = f x) :
(r ⬝ ap f q) ⬝ p y = (r ⬝ p x) ⬝ ap g q :=
by induction q; reflexivity
-- TODO: try this using the simplifier, and compare proofs
definition ap_con_con_eq_con_ap_con {f g : A → B} (p : f ~ g) {x y : A} (q : x = y)
{z : B} (s : g y = z) :
ap f q ⬝ (p y ⬝ s) = p x ⬝ (ap g q ⬝ s) :=
begin
induction s,
induction q,
apply idp_con
end
definition con_ap_con_con_eq_con_con_con {f : A → A} (p : f ~ id) {x y : A} (q : x = y)
{w z : A} (r : w = f x) (s : y = z) :
(r ⬝ ap f q) ⬝ (p y ⬝ s) = (r ⬝ p x) ⬝ (q ⬝ s) :=
by induction s; induction q; reflexivity
definition con_con_ap_con_eq_con_con_con {g : A → A} (p : id ~ g) {x y : A} (q : x = y)
{w z : A} (r : w = x) (s : g y = z) :
(r ⬝ p x) ⬝ (ap g q ⬝ s) = (r ⬝ q) ⬝ (p y ⬝ s) :=
by induction s; induction q; reflexivity
definition con_ap_con_eq_con_con {f : A → A} (p : f ~ id) {x y : A} (q : x = y)
{w : A} (r : w = f x) :
(r ⬝ ap f q) ⬝ p y = (r ⬝ p x) ⬝ q :=
by induction q; reflexivity
definition ap_con_con_eq_con_con {f : A → A} (p : f ~ id) {x y : A} (q : x = y)
{z : A} (s : y = z) :
ap f q ⬝ (p y ⬝ s) = p x ⬝ (q ⬝ s) :=
by induction s; induction q; apply idp_con
definition con_con_ap_eq_con_con {g : A → A} (p : id ~ g) {x y : A} (q : x = y)
{w : A} (r : w = x) :
(r ⬝ p x) ⬝ ap g q = (r ⬝ q) ⬝ p y :=
begin cases q, exact idp end
definition con_ap_con_eq_con_con' {g : A → A} (p : id ~ g) {x y : A} (q : x = y)
{z : A} (s : g y = z) :
p x ⬝ (ap g q ⬝ s) = q ⬝ (p y ⬝ s) :=
by induction s; induction q; exact !idp_con⁻¹
/- Action of [apd10] and [ap10] on paths -/
-- Application of paths between functions preserves the groupoid structure
definition apd10_idp (f : Πx, P x) (x : A) : apd10 (refl f) x = idp := idp
definition apd10_con {f f' f'' : Πx, P x} (h : f = f') (h' : f' = f'') (x : A) :
apd10 (h ⬝ h') x = apd10 h x ⬝ apd10 h' x :=
by induction h; induction h'; reflexivity
definition apd10_inv {f g : Πx : A, P x} (h : f = g) (x : A) :
apd10 h⁻¹ x = (apd10 h x)⁻¹ :=
by induction h; reflexivity
definition ap10_idp {f : A → B} (x : A) : ap10 (refl f) x = idp := idp
definition ap10_con {f f' f'' : A → B} (h : f = f') (h' : f' = f'') (x : A) :
ap10 (h ⬝ h') x = ap10 h x ⬝ ap10 h' x := apd10_con h h' x
definition ap10_inv {f g : A → B} (h : f = g) (x : A) : ap10 h⁻¹ x = (ap10 h x)⁻¹ :=
apd10_inv h x
-- [ap10] also behaves nicely on paths produced by [ap]
definition ap_ap10 (f g : A → B) (h : B → C) (p : f = g) (a : A) :
ap h (ap10 p a) = ap10 (ap (λ f', h ∘ f') p) a:=
by induction p; reflexivity
/- Transport and the groupoid structure of paths -/
definition idp_tr {P : A → Type} {x : A} (u : P x) : idp ▸ u = u := idp
definition con_tr [unfold 7] {P : A → Type} {x y z : A} (p : x = y) (q : y = z) (u : P x) :
p ⬝ q ▸ u = q ▸ p ▸ u :=
by induction q; reflexivity
definition tr_inv_tr {P : A → Type} {x y : A} (p : x = y) (z : P y) :
p ▸ p⁻¹ ▸ z = z :=
(con_tr p⁻¹ p z)⁻¹ ⬝ ap (λr, transport P r z) (con.left_inv p)
definition inv_tr_tr {P : A → Type} {x y : A} (p : x = y) (z : P x) :
p⁻¹ ▸ p ▸ z = z :=
(con_tr p p⁻¹ z)⁻¹ ⬝ ap (λr, transport P r z) (con.right_inv p)
definition cast_cast_inv {A : Type} {P : A → Type} {x y : A} (p : x = y) (z : P y) :
cast (ap P p) (cast (ap P p⁻¹) z) = z :=
by induction p; reflexivity
definition cast_inv_cast {A : Type} {P : A → Type} {x y : A} (p : x = y) (z : P x) :
cast (ap P p⁻¹) (cast (ap P p) z) = z :=
by induction p; reflexivity
definition con_con_tr {P : A → Type}
{x y z w : A} (p : x = y) (q : y = z) (r : z = w) (u : P x) :
ap (λe, e ▸ u) (con.assoc' p q r) ⬝ (con_tr (p ⬝ q) r u) ⬝
ap (transport P r) (con_tr p q u)
= (con_tr p (q ⬝ r) u) ⬝ (con_tr q r (p ▸ u))
:> ((p ⬝ (q ⬝ r)) ▸ u = r ▸ q ▸ p ▸ u) :=
by induction r; induction q; induction p; reflexivity
-- Here is another coherence lemma for transport.
definition tr_inv_tr_lemma {P : A → Type} {x y : A} (p : x = y) (z : P x) :
tr_inv_tr p (transport P p z) = ap (transport P p) (inv_tr_tr p z) :=
by induction p; reflexivity
/- some properties for apdt -/
definition apdt_idp (x : A) (f : Πx, P x) : apdt f idp = idp :> (f x = f x) := idp
definition apdt_con (f : Πx, P x) {x y z : A} (p : x = y) (q : y = z)
: apdt f (p ⬝ q) = con_tr p q (f x) ⬝ ap (transport P q) (apdt f p) ⬝ apdt f q :=
by cases p; cases q; apply idp
definition apdt_inv (f : Πx, P x) {x y : A} (p : x = y)
: apdt f p⁻¹ = (eq_inv_tr_of_tr_eq (apdt f p))⁻¹ :=
by cases p; apply idp
-- Dependent transport in a doubly dependent type.
-- This is a special case of transporto in init.pathover
definition transportD [unfold 6] {P : A → Type} (Q : Πa, P a → Type)
{a a' : A} (p : a = a') (b : P a) (z : Q a b) : Q a' (p ▸ b) :=
by induction p; exact z
-- In Coq the variables P, Q and b are explicit, but in Lean we can probably have them implicit
-- using the following notation
notation p ` ▸D `:65 x:64 := transportD _ p _ x
-- transporting over 2 one-dimensional paths
-- This is a special case of transporto in init.pathover
definition transport11 {A B : Type} (P : A → B → Type) {a a' : A} {b b' : B}
(p : a = a') (q : b = b') (z : P a b) : P a' b' :=
transport (P a') q (p ▸ z)
-- Transporting along higher-dimensional paths
definition transport2 [unfold 7] (P : A → Type) {x y : A} {p q : x = y} (r : p = q) (z : P x) :
p ▸ z = q ▸ z :=
ap (λp', p' ▸ z) r
notation p ` ▸2 `:65 x:64 := transport2 _ p _ x
-- An alternative definition.
definition tr2_eq_ap10 (Q : A → Type) {x y : A} {p q : x = y} (r : p = q) (z : Q x) :
transport2 Q r z = ap10 (ap (transport Q) r) z :=
by induction r; reflexivity
definition tr2_con {P : A → Type} {x y : A} {p1 p2 p3 : x = y}
(r1 : p1 = p2) (r2 : p2 = p3) (z : P x) :
transport2 P (r1 ⬝ r2) z = transport2 P r1 z ⬝ transport2 P r2 z :=
by induction r1; induction r2; reflexivity
definition tr2_inv (Q : A → Type) {x y : A} {p q : x = y} (r : p = q) (z : Q x) :
transport2 Q r⁻¹ z = (transport2 Q r z)⁻¹ :=
by induction r; reflexivity
definition transportD2 [unfold 7] {B C : A → Type} (D : Π(a:A), B a → C a → Type)
{x1 x2 : A} (p : x1 = x2) (y : B x1) (z : C x1) (w : D x1 y z) : D x2 (p ▸ y) (p ▸ z) :=
by induction p; exact w
notation p ` ▸D2 `:65 x:64 := transportD2 _ p _ _ x
definition ap_tr_con_tr2 (P : A → Type) {x y : A} {p q : x = y} {z w : P x} (r : p = q)
(s : z = w) :
ap (transport P p) s ⬝ transport2 P r w = transport2 P r z ⬝ ap (transport P q) s :=
by induction r; exact !idp_con⁻¹
definition fn_tr_eq_tr_fn {P Q : A → Type} {x y : A} (p : x = y) (f : Πx, P x → Q x) (z : P x) :
f y (p ▸ z) = p ▸ f x z :=
by induction p; reflexivity
definition fn_cast_eq_cast_fn {A : Type} {P Q : A → Type} {x y : A} (p : x = y)
(f : Πx, P x → Q x) (z : P x) : f y (cast (ap P p) z) = cast (ap Q p) (f x z) :=
by induction p; reflexivity
/- Transporting in particular fibrations -/
/-
From the Coq HoTT library:
One frequently needs lemmas showing that transport in a certain dependent type is equal to some
more explicitly defined operation, defined according to the structure of that dependent type.
For most dependent types, we prove these lemmas in the appropriate file in the types/
subdirectory. Here we consider only the most basic cases.
-/
-- Transporting in a constant fibration.
definition tr_constant (p : x = y) (z : B) : transport (λx, B) p z = z :=
by induction p; reflexivity
definition tr2_constant {p q : x = y} (r : p = q) (z : B) :
tr_constant p z = transport2 (λu, B) r z ⬝ tr_constant q z :=
by induction r; exact !idp_con⁻¹
-- Transporting in a pulled back fibration.
definition tr_compose (P : B → Type) (f : A → B) (p : x = y) (z : P (f x)) :
transport (P ∘ f) p z = transport P (ap f p) z :=
by induction p; reflexivity
definition ap_precompose (f : A → B) (g g' : B → C) (p : g = g') :
ap (λh, h ∘ f) p = transport (λh : B → C, g ∘ f = h ∘ f) p idp :=
by induction p; reflexivity
definition apd10_ap_precompose (f : A → B) (g g' : B → C) (p : g = g') :
apd10 (ap (λh : B → C, h ∘ f) p) = λa, apd10 p (f a) :=
by induction p; reflexivity
definition apd10_ap_precompose_dependent {C : B → Type}
(f : A → B) {g g' : Πb : B, C b} (p : g = g')
: apd10 (ap (λ(h : (Πb : B, C b))(a : A), h (f a)) p) = λa, apd10 p (f a) :=
by induction p; reflexivity
definition apd10_ap_postcompose (f : B → C) (g g' : A → B) (p : g = g') :
apd10 (ap (λh : A → B, f ∘ h) p) = λa, ap f (apd10 p a) :=
by induction p; reflexivity
-- A special case of [tr_compose] which seems to come up a lot.
definition tr_eq_cast_ap {P : A → Type} {x y} (p : x = y) (u : P x) : p ▸ u = cast (ap P p) u :=
by induction p; reflexivity
definition tr_eq_cast_ap_fn {P : A → Type} {x y} (p : x = y) : transport P p = cast (ap P p) :=
by induction p; reflexivity
/- The behavior of [ap] and [apdt] -/
-- In a constant fibration, [apdt] reduces to [ap], modulo [transport_const].
definition apdt_eq_tr_constant_con_ap (f : A → B) (p : x = y) :
apdt f p = tr_constant p (f x) ⬝ ap f p :=
by induction p; reflexivity
/- The 2-dimensional groupoid structure -/
-- Horizontal composition of 2-dimensional paths.
definition concat2 [unfold 9 10] {p p' : x = y} {q q' : y = z} (h : p = p') (h' : q = q')
: p ⬝ q = p' ⬝ q' :=
ap011 concat h h'
-- 2-dimensional path inversion
definition inverse2 [unfold 6] {p q : x = y} (h : p = q) : p⁻¹ = q⁻¹ :=
ap inverse h
infixl ` ◾ `:75 := concat2
postfix [parsing_only] `⁻²`:(max+10) := inverse2 --this notation is abusive, should we use it?
/- Whiskering -/
definition whisker_left [unfold 8] (p : x = y) {q r : y = z} (h : q = r) : p ⬝ q = p ⬝ r :=
idp ◾ h
definition whisker_right [unfold 7] {p q : x = y} (h : p = q) (r : y = z) : p ⬝ r = q ⬝ r :=
h ◾ idp
-- Unwhiskering, a.k.a. cancelling
definition cancel_left {x y z : A} (p : x = y) {q r : y = z} : (p ⬝ q = p ⬝ r) → (q = r) :=
λs, !inv_con_cancel_left⁻¹ ⬝ whisker_left p⁻¹ s ⬝ !inv_con_cancel_left
definition cancel_right {x y z : A} {p q : x = y} (r : y = z) : (p ⬝ r = q ⬝ r) → (p = q) :=
λs, !con_inv_cancel_right⁻¹ ⬝ whisker_right s r⁻¹ ⬝ !con_inv_cancel_right
-- Whiskering and identity paths.
definition whisker_right_idp {p q : x = y} (h : p = q) :
whisker_right h idp = h :=
by induction h; induction p; reflexivity
definition whisker_right_idp_left [unfold_full] (p : x = y) (q : y = z) :
whisker_right idp q = idp :> (p ⬝ q = p ⬝ q) :=
idp
definition whisker_left_idp_right [unfold_full] (p : x = y) (q : y = z) :
whisker_left p idp = idp :> (p ⬝ q = p ⬝ q) :=
idp
definition whisker_left_idp {p q : x = y} (h : p = q) :
(idp_con p)⁻¹ ⬝ whisker_left idp h ⬝ idp_con q = h :=
by induction h; induction p; reflexivity
definition whisker_left_idp2 {A : Type} {a : A} (p : idp = idp :> a = a) :
whisker_left idp p = p :=
begin
refine _ ⬝ whisker_left_idp p,
exact !idp_con⁻¹
end
definition con2_idp [unfold_full] {p q : x = y} (h : p = q) :
h ◾ idp = whisker_right h idp :> (p ⬝ idp = q ⬝ idp) :=
idp
definition idp_con2 [unfold_full] {p q : x = y} (h : p = q) :
idp ◾ h = whisker_left idp h :> (idp ⬝ p = idp ⬝ q) :=
idp
definition inv2_con2 {p p' : x = y} (h : p = p')
: h⁻² ◾ h = con.left_inv p ⬝ (con.left_inv p')⁻¹ :=
by induction h; induction p; reflexivity
-- The interchange law for concatenation.
definition con2_con_con2 {p p' p'' : x = y} {q q' q'' : y = z}
(a : p = p') (b : p' = p'') (c : q = q') (d : q' = q'') :
(a ◾ c) ⬝ (b ◾ d) = (a ⬝ b) ◾ (c ⬝ d) :=
by induction d; induction c; induction b;induction a; reflexivity
definition con2_eq_rl {A : Type} {x y z : A} {p p' : x = y} {q q' : y = z}
(a : p = p') (b : q = q') : a ◾ b = whisker_right a q ⬝ whisker_left p' b :=
by induction b; induction a; reflexivity
definition con2_eq_lf {A : Type} {x y z : A} {p p' : x = y} {q q' : y = z}
(a : p = p') (b : q = q') : a ◾ b = whisker_left p b ⬝ whisker_right a q' :=
by induction b; induction a; reflexivity
definition whisker_right_con_whisker_left {x y z : A} {p p' : x = y} {q q' : y = z}
(a : p = p') (b : q = q') :
(whisker_right a q) ⬝ (whisker_left p' b) = (whisker_left p b) ⬝ (whisker_right a q') :=
by induction b; induction a; reflexivity
-- Structure corresponding to the coherence equations of a bicategory.
-- The "pentagonator": the 3-cell witnessing the associativity pentagon.
definition pentagon {v w x y z : A} (p : v = w) (q : w = x) (r : x = y) (s : y = z) :
whisker_left p (con.assoc' q r s)
⬝ con.assoc' p (q ⬝ r) s
⬝ whisker_right (con.assoc' p q r) s
= con.assoc' p q (r ⬝ s) ⬝ con.assoc' (p ⬝ q) r s :=
by induction s;induction r;induction q;induction p;reflexivity
-- The 3-cell witnessing the left unit triangle.
definition triangulator (p : x = y) (q : y = z) :
con.assoc' p idp q ⬝ whisker_right (con_idp p) q = whisker_left p (idp_con q) :=
by induction q; induction p; reflexivity
definition eckmann_hilton (p q : idp = idp :> a = a) : p ⬝ q = q ⬝ p :=
begin
refine (whisker_right_idp p ◾ whisker_left_idp2 q)⁻¹ ⬝ _,
refine !whisker_right_con_whisker_left ⬝ _,
refine !whisker_left_idp2 ◾ !whisker_right_idp
end
definition con_eq_con2 (p q : idp = idp :> a = a) : p ⬝ q = p ◾ q :=
begin
refine (whisker_right_idp p ◾ whisker_left_idp2 q)⁻¹ ⬝ _,
exact !con2_eq_rl⁻¹
end
definition inv_eq_inv2 (p : idp = idp :> a = a) : p⁻¹ = p⁻² :=
begin
apply eq.cancel_right p,
refine !con.left_inv ⬝ _,
refine _ ⬝ !con_eq_con2⁻¹,
exact !inv2_con2⁻¹,
end
-- The action of functions on 2-dimensional paths
definition ap02 [unfold 8] [reducible] (f : A → B) {x y : A} {p q : x = y} (r : p = q)
: ap f p = ap f q :=
ap (ap f) r
definition ap02_con (f : A → B) {x y : A} {p p' p'' : x = y} (r : p = p') (r' : p' = p'') :
ap02 f (r ⬝ r') = ap02 f r ⬝ ap02 f r' :=
by induction r; induction r'; reflexivity
definition ap02_con2 (f : A → B) {x y z : A} {p p' : x = y} {q q' :y = z} (r : p = p')
(s : q = q') :
ap02 f (r ◾ s) = ap_con f p q
⬝ (ap02 f r ◾ ap02 f s)
⬝ (ap_con f p' q')⁻¹ :=
by induction r; induction s; induction q; induction p; reflexivity
definition apdt02 [unfold 8] {p q : x = y} (f : Π x, P x) (r : p = q) :
apdt f p = transport2 P r (f x) ⬝ apdt f q :=
by induction r; exact !idp_con⁻¹
-- And now for a lemma whose statement is much longer than its proof.
definition apdt02_con {P : A → Type} (f : Π x:A, P x) {x y : A}
{p1 p2 p3 : x = y} (r1 : p1 = p2) (r2 : p2 = p3) :
apdt02 f (r1 ⬝ r2) = apdt02 f r1
⬝ whisker_left (transport2 P r1 (f x)) (apdt02 f r2)
⬝ con.assoc' _ _ _
⬝ (whisker_right (tr2_con r1 r2 (f x))⁻¹ (apdt f p3)) :=
by induction r2; induction r1; induction p1; reflexivity
end eq
/-
an auxillary namespace for concatenation and inversion for homotopies. We put this is a separate
namespace because ⁻¹ʰ is also used as the inverse of a homomorphism
-/
open eq
namespace homotopy
infix ` ⬝h `:75 := homotopy.trans
postfix `⁻¹ʰ`:(max+1) := homotopy.symm
end homotopy
|
e9bf4e48e0e9e97b7b4c62bfc8d74b125c389f95 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/finally.lean | b46ffef2d1afc7999c0f66f27286c727c41ea038 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | leanprover/lean4 | 4bdf9790294964627eb9be79f5e8f6157780b4cc | f1f9dc0f2f531af3312398999d8b8303fa5f096b | refs/heads/master | 1,693,360,665,786 | 1,693,350,868,000 | 1,693,350,868,000 | 129,571,436 | 2,827 | 311 | Apache-2.0 | 1,694,716,156,000 | 1,523,760,560,000 | Lean | UTF-8 | Lean | false | false | 1,855 | lean | def checkM (b : IO Bool) : IO Unit :=
unless (← b) do throw $ IO.userError "failed"
abbrev M := ExceptT String $ StateRefT Nat IO
def f1 : M Nat :=
throw "error 1"
def f2 : M Nat :=
throwThe IO.Error $ IO.userError "error 2"
def tst1 : M Nat := do
try
try f1 finally set 100; IO.println "finisher executed"
catch _ =>
get
def checkE {α ε : Type} [BEq α] (x : IO (Except ε α)) (expected : α) : IO Unit := do
let r ← x;
match r with
| Except.ok a => unless a == expected do throw $ IO.userError "unexpected result"
| Except.error _ => throw $ IO.userError "unexpected error"
#eval (tst1.run).run' 0
#eval checkE ((tst1.run).run' 0) 100
def tst2 : M Nat :=
tryCatchThe IO.Error
(tryFinally f2 (do set 100; IO.println "finisher executed"))
(fun _ => get)
#eval (tst2.run).run' 0
#eval checkE ((tst2.run).run' 0) 100
def tst3 : M Nat :=
tryCatchThe IO.Error
(tryFinally
(tryFinally f1 (do set 100; IO.println "inner finisher executed"; discard $ f2; pure ()))
(do modify Nat.succ; IO.println "outer finisher executed"))
(fun _ => get)
#eval (tst3.run).run' 0
#eval checkE ((tst3.run).run' 0) 101
def tst4 : M Nat := do
let a ← tryFinally
(tryFinally (pure 42) (do set 100; IO.println "inner finisher executed"; pure ()))
(do modify Nat.succ; IO.println "outer finisher executed");
let s ← get;
pure (a + s)
#eval (tst4.run).run' 0
#eval checkE ((tst4.run).run' 0) 143
def tst5 : M Nat := do
let (a, _) ← tryFinally' (pure 42) (fun a? => do IO.println ("finalizer received: " ++ toString a?));
pure a
#eval (tst5.run).run' 0
def tst6 : M Nat := do
let (a, _) ← tryFinally' f2 (fun a? => do IO.println ("finalizer received: " ++ toString a?));
pure a
def tst7 : IO Unit :=
tryCatchThe IO.Error (do discard $ (tst6.run).run' 0; pure ()) (fun _ => IO.println "failed as expected")
#eval tst7
|
8660eb2c706211cf714466bdc372904cf4e677dc | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /src/Lean/Elab/AuxDiscr.lean | c07326fac386abdcaf56db148729ba9b8b434022 | [
"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 | 1,130 | lean | /-
Copyright (c) 2022 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
namespace Lean
/--
Create an auxiliary identifier for storing non-atomic discriminants.
This kind of free variable is cleared before elaborating a `match` alternative rhs.
-/
def mkAuxDiscr [Monad m] [MonadQuotation m] : m Ident :=
`(_discr)
/--
Create an auxiliary identifier for expanding notation such as `fun (a, b) => ...`.
This kind of free variable is cleared before elaborating a `match` alternative rhs.
-/
def mkAuxFunDiscr [Monad m] [MonadQuotation m] : m Ident :=
`(_fun_discr)
/-- Return true iff `n` is an auxiliary variable created by `expandNonAtomicDiscrs?` -/
def isAuxDiscrName (n : Name) : Bool :=
n.hasMacroScopes && n.eraseMacroScopes == `_discr
/--
Return true iff `n` is an auxiliary variable created by notation such as `fun (a, b) => ...`.
They are cleared before eliminating the `match` alternatives RHS -/
def isAuxFunDiscrName (n : Name) : Bool :=
n.hasMacroScopes && n.eraseMacroScopes == `_fun_discr
end Lean
|
93ba4b00c71bb1b6eb0366767a7ae879b3e84677 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/analysis/complex/isometry.lean | 7718c6c229a3beacd455fa478380beba8d9a070f | [
"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 | 6,716 | lean | /-
Copyright (c) 2021 François Sunatori. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: François Sunatori
-/
import analysis.complex.circle
import linear_algebra.determinant
import linear_algebra.general_linear_group
/-!
# Isometries of the Complex Plane
The lemma `linear_isometry_complex` states the classification of isometries in the complex plane.
Specifically, isometries with rotations but without translation.
The proof involves:
1. creating a linear isometry `g` with two fixed points, `g(0) = 0`, `g(1) = 1`
2. applying `linear_isometry_complex_aux` to `g`
The proof of `linear_isometry_complex_aux` is separated in the following parts:
1. show that the real parts match up: `linear_isometry.re_apply_eq_re`
2. show that I maps to either I or -I
3. every z is a linear combination of a + b * I
## References
* [Isometries of the Complex Plane](http://helmut.knaust.info/mediawiki/images/b/b5/Iso.pdf)
-/
noncomputable theory
open complex
open_locale complex_conjugate
local notation (name := complex.abs) `|` x `|` := complex.abs x
/-- An element of the unit circle defines a `linear_isometry_equiv` from `ℂ` to itself, by
rotation. -/
def rotation : circle →* (ℂ ≃ₗᵢ[ℝ] ℂ) :=
{ to_fun := λ a,
{ norm_map' := λ x, show |a * x| = |x|, by rw [map_mul, abs_coe_circle, one_mul],
..distrib_mul_action.to_linear_equiv ℝ ℂ a },
map_one' := linear_isometry_equiv.ext $ one_smul _,
map_mul' := λ _ _, linear_isometry_equiv.ext $ mul_smul _ _ }
@[simp] lemma rotation_apply (a : circle) (z : ℂ) : rotation a z = a * z := rfl
@[simp] lemma rotation_symm (a : circle) : (rotation a).symm = rotation a⁻¹ :=
linear_isometry_equiv.ext $ λ x, rfl
@[simp] lemma rotation_trans (a b : circle) :
(rotation a).trans (rotation b) = rotation (b * a) :=
by { ext1, simp }
lemma rotation_ne_conj_lie (a : circle) : rotation a ≠ conj_lie :=
begin
intro h,
have h1 : rotation a 1 = conj 1 := linear_isometry_equiv.congr_fun h 1,
have hI : rotation a I = conj I := linear_isometry_equiv.congr_fun h I,
rw [rotation_apply, ring_hom.map_one, mul_one] at h1,
rw [rotation_apply, conj_I, ← neg_one_mul, mul_left_inj' I_ne_zero, h1, eq_neg_self_iff] at hI,
exact one_ne_zero hI,
end
/-- Takes an element of `ℂ ≃ₗᵢ[ℝ] ℂ` and checks if it is a rotation, returns an element of the
unit circle. -/
@[simps]
def rotation_of (e : ℂ ≃ₗᵢ[ℝ] ℂ) : circle :=
⟨(e 1) / complex.abs (e 1), by simp⟩
@[simp]
lemma rotation_of_rotation (a : circle) : rotation_of (rotation a) = a :=
subtype.ext $ by simp
lemma rotation_injective : function.injective rotation :=
function.left_inverse.injective rotation_of_rotation
lemma linear_isometry.re_apply_eq_re_of_add_conj_eq (f : ℂ →ₗᵢ[ℝ] ℂ)
(h₃ : ∀ z, z + conj z = f z + conj (f z)) (z : ℂ) : (f z).re = z.re :=
by simpa [ext_iff, add_re, add_im, conj_re, conj_im, ←two_mul,
(show (2 : ℝ) ≠ 0, by simp [two_ne_zero])] using (h₃ z).symm
lemma linear_isometry.im_apply_eq_im_or_neg_of_re_apply_eq_re {f : ℂ →ₗᵢ[ℝ] ℂ}
(h₂ : ∀ z, (f z).re = z.re) (z : ℂ) :
(f z).im = z.im ∨ (f z).im = -z.im :=
begin
have h₁ := f.norm_map z,
simp only [complex.abs_def, norm_eq_abs] at h₁,
rwa [real.sqrt_inj (norm_sq_nonneg _) (norm_sq_nonneg _), norm_sq_apply (f z), norm_sq_apply z,
h₂, add_left_cancel_iff, mul_self_eq_mul_self_iff] at h₁,
end
lemma linear_isometry.im_apply_eq_im {f : ℂ →ₗᵢ[ℝ] ℂ} (h : f 1 = 1) (z : ℂ) :
z + conj z = f z + conj (f z) :=
begin
have : ‖f z - 1‖ = ‖z - 1‖ := by rw [← f.norm_map (z - 1), f.map_sub, h],
apply_fun λ x, x ^ 2 at this,
simp only [norm_eq_abs, ←norm_sq_eq_abs] at this,
rw [←of_real_inj, ←mul_conj, ←mul_conj] at this,
rw [ring_hom.map_sub, ring_hom.map_sub] at this,
simp only [sub_mul, mul_sub, one_mul, mul_one] at this,
rw [mul_conj, norm_sq_eq_abs, ←norm_eq_abs, linear_isometry.norm_map] at this,
rw [mul_conj, norm_sq_eq_abs, ←norm_eq_abs] at this,
simp only [sub_sub, sub_right_inj, mul_one, of_real_pow, ring_hom.map_one, norm_eq_abs] at this,
simp only [add_sub, sub_left_inj] at this,
rw [add_comm, ←this, add_comm],
end
lemma linear_isometry.re_apply_eq_re {f : ℂ →ₗᵢ[ℝ] ℂ} (h : f 1 = 1) (z : ℂ) : (f z).re = z.re :=
begin
apply linear_isometry.re_apply_eq_re_of_add_conj_eq,
intro z,
apply linear_isometry.im_apply_eq_im h,
end
lemma linear_isometry_complex_aux {f : ℂ ≃ₗᵢ[ℝ] ℂ} (h : f 1 = 1) :
f = linear_isometry_equiv.refl ℝ ℂ ∨ f = conj_lie :=
begin
have h0 : f I = I ∨ f I = -I,
{ have : |f I| = 1 := by simpa using f.norm_map complex.I,
simp only [ext_iff, ←and_or_distrib_left, neg_re, I_re, neg_im, neg_zero],
split,
{ rw ←I_re,
exact @linear_isometry.re_apply_eq_re f.to_linear_isometry h I, },
{ apply @linear_isometry.im_apply_eq_im_or_neg_of_re_apply_eq_re f.to_linear_isometry,
intro z, rw @linear_isometry.re_apply_eq_re f.to_linear_isometry h } },
refine h0.imp (λ h' : f I = I, _) (λ h' : f I = -I, _);
{ apply linear_isometry_equiv.to_linear_equiv_injective,
apply complex.basis_one_I.ext',
intros i,
fin_cases i; simp [h, h'] }
end
lemma linear_isometry_complex (f : ℂ ≃ₗᵢ[ℝ] ℂ) :
∃ a : circle, f = rotation a ∨ f = conj_lie.trans (rotation a) :=
begin
let a : circle := ⟨f 1, by simpa using f.norm_map 1⟩,
use a,
have : (f.trans (rotation a).symm) 1 = 1,
{ simpa using rotation_apply a⁻¹ (f 1) },
refine (linear_isometry_complex_aux this).imp (λ h₁, _) (λ h₂, _),
{ simpa using eq_mul_of_inv_mul_eq h₁ },
{ exact eq_mul_of_inv_mul_eq h₂ }
end
/-- The matrix representation of `rotation a` is equal to the conformal matrix
`!![re a, -im a; im a, re a]`. -/
lemma to_matrix_rotation (a : circle) :
linear_map.to_matrix basis_one_I basis_one_I (rotation a).to_linear_equiv =
matrix.plane_conformal_matrix (re a) (im a) (by simp [pow_two, ←norm_sq_apply]) :=
begin
ext i j,
simp [linear_map.to_matrix_apply],
fin_cases i; fin_cases j; simp
end
/-- The determinant of `rotation` (as a linear map) is equal to `1`. -/
@[simp] lemma det_rotation (a : circle) : ((rotation a).to_linear_equiv : ℂ →ₗ[ℝ] ℂ).det = 1 :=
begin
rw [←linear_map.det_to_matrix basis_one_I, to_matrix_rotation, matrix.det_fin_two],
simp [←norm_sq_apply]
end
/-- The determinant of `rotation` (as a linear equiv) is equal to `1`. -/
@[simp] lemma linear_equiv_det_rotation (a : circle) : (rotation a).to_linear_equiv.det = 1 :=
by rw [←units.eq_iff, linear_equiv.coe_det, det_rotation, units.coe_one]
|
641681f00fdb130c2e13d4a95e7db2c6fbe97ca8 | 74d9d5f45c6ce5c4f2faf215c04a68eab55fe525 | /src/homeos.lean | c5e77def239c37feaa495e6150f3ce8dea1bfc74 | [] | no_license | joshpoll/differential_geometry | 290bb8a934ca3b3b6b707d810e6d4b941710b710 | 57e00a7e37b7c4c73c847429171ff63d3a48def5 | refs/heads/master | 1,584,551,626,391 | 1,527,747,643,000 | 1,527,747,643,000 | 135,014,993 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,816 | lean | -- From Patrick Massot
import analysis.topology.topological_space
import analysis.topology.continuity
open set function
local notation f`⁻¹` := f.symm
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
[topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
theorem equiv.left_inverse (f : equiv α β) : left_inverse f⁻¹ f := f.left_inv
theorem equiv.right_inverse (f : equiv α β) : function.right_inverse f⁻¹ f := f.right_inv
lemma equiv.image_eq_preimage {α β} (e : α ≃ β) (s : set α) : e '' s = e.symm ⁻¹' s :=
ext $ assume x, mem_image_iff_of_inverse e.left_inv e.right_inv
lemma equiv.subset_image {α β} (e : α ≃ β) (s : set α) (t : set β) : t ⊆ e '' s ↔ e.symm '' t ⊆ s :=
by rw [image_subset_iff, e.image_eq_preimage]
lemma equiv.symm_image_image (f : equiv α β) (s : set α) : f.symm '' (f '' s) = s :=
by rw [←image_comp] ; simpa using image_id s
lemma equiv.image_compl (f : equiv α β) (s : set α) :
f '' -s = -(f '' s) :=
image_compl_eq f.bijective
structure homeo (α β) [topological_space α] [topological_space β] extends equiv α β :=
(fun_con : continuous to_fun)
(inv_con : continuous inv_fun)
instance : has_coe_to_fun (homeo α β) := ⟨_, λ f, f.to_fun⟩
theorem homeo.bijective (f : homeo α β) : bijective f := f.to_equiv.bijective
def homeo.comp : homeo α β → homeo β γ → homeo α γ
| ⟨e1@⟨f₁, g₁, _, _⟩, f₁_con, g₁_con⟩ ⟨e2@⟨f₂, g₂, _, _⟩, f₂_con, g₂_con⟩ :=
⟨e1.trans e2,
continuous.comp f₁_con f₂_con,
continuous.comp g₂_con g₁_con⟩
def homeo.symm (h : homeo α β) : homeo β α :=
{ fun_con := h.inv_con, inv_con := h.fun_con, .. h.to_equiv.symm }
lemma homeo.subset_image (e : homeo α β) (s : set α) (t : set β) : t ⊆ e '' s ↔ e.symm '' t ⊆ s :=
equiv.subset_image _ _ _
lemma homeo.symm_image_image (f : homeo α β) (s : set α) : f.symm '' (f '' s) = s :=
equiv.symm_image_image _ _
lemma homeo.image_closure (f : homeo α β) (s : set α) : f '' closure s = closure (f '' s) :=
subset.antisymm
(image_closure_subset_closure_image f.fun_con)
((homeo.subset_image _ _ _).2 $
calc f.symm '' closure (f '' s) ⊆ closure (f.symm '' (f '' s)) :
image_closure_subset_closure_image f.inv_con
... = closure s : by rw f.symm_image_image s)
lemma homeo.image_compl (f : homeo α β) (s : set α) : f '' -s = -(f '' s) :=
equiv.image_compl _ _
--instance : has_inv (homeo α α) := ⟨λ f, f.symm⟩
local notation f`⁻¹` := f.symm
local notation f ∘ g := homeo.comp g f
theorem homeo.left_inverse (f : homeo α β) : left_inverse f⁻¹ f := f.left_inv
theorem homeo.right_inverse (f : homeo α β) : function.right_inverse f⁻¹ f := f.right_inv
@[simp] lemma homeo.comp_val (f : homeo α β) (g : homeo β γ) (x) : homeo.comp f g x = g (f x) :=
by cases f with e₁; cases g with e₂; cases e₁; cases e₂; refl
def homeo.id (α) [topological_space α] : homeo α α :=
{ fun_con := continuous_id, inv_con := continuous_id, .. equiv.refl α }
@[simp]
lemma home.id_apply : (homeo.id α : α → α) = id := rfl
@[simp] lemma homeo.id_val (x : α) : (homeo.id α) x = x := rfl
@[extensionality]
theorem homeo.ext {f g : homeo α β} (H : ∀ x, f x = g x) : f = g :=
by cases f; cases g; congr;
exact equiv.eq_of_to_fun_eq (funext H)
lemma id_circ_f (f : homeo α β) : (homeo.id β) ∘ f = f :=
homeo.ext $ by simp
lemma f_circ_id (f : homeo α β) : f ∘ (homeo.id α) = f :=
homeo.ext $ by simp
lemma homeo_comp_assoc (f: homeo α β) (g : homeo β γ) (h : homeo γ δ) : (h ∘ g) ∘ f = h ∘ (g ∘ f) :=
homeo.ext $ by simp
lemma homeo.mul_left_inv (f: homeo α β) : f ∘ f⁻¹ = homeo.id β :=
homeo.ext
begin
suffices : ∀ (x : β), f (f⁻¹ x) = x,
simp [this],
intro,
cases f,
rw homeo.symm,
apply equiv.apply_inverse_apply,
end
lemma homeo.symm_comp (h : homeo α β) : h⁻¹ ∘ h = homeo.id α :=
begin
apply homeo.ext,
simp,
intros,
cases h with f f_con f_inv_con,
rw homeo.symm,
apply equiv.apply_inverse_apply,
end
universe u
instance aut (α : Type u) [topological_space α] : group (homeo α α) :=
{ mul := (∘),
mul_assoc := λ a b c, homeo.ext $ by simp,
one := homeo.id α,
one_mul := id_circ_f,
mul_one := f_circ_id,
inv := homeo.symm,
mul_left_inv := homeo.symm_comp }
@[simp] theorem aut_mul_val (f g : homeo α α) (x) : (f * g) x = f (g x) :=
homeo.comp_val _ _ _
@[simp] theorem perm_mul_val (f g : equiv.perm α) (x) : (f * g) x = f (g x) :=
equiv.trans_apply _ _ _
@[simp] theorem perm_one_val (x) : (1 : equiv.perm α) x = x := rfl
@[simp] theorem aut_one_val (x) : (1 : homeo α α) x = x := rfl
theorem aut_inv (f : homeo α α) : f⁻¹ = f.symm := rfl
|
b239af9314f150a9967c85611fd6fb7d6f343ff9 | 37a833c924892ee3ecb911484775a6d6ebb8984d | /src/category_theory/presheaves/V_pre.lean | de7445836cbbb5da1027f11eeb7220c0e216f339 | [] | 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 | 809 | lean | import ring_theory.ideals
import category_theory.presheaves.stalk
import category_theory.presheaves.map
import category_theory.examples.TopRing
import category_theory.sigma_category
open category_theory
open category_theory.limits
open category_theory.examples
universes u v
namespace category_theory.presheaves
-- TODO we should use filtered/directed colimits here, anyway
instance : has_colimits.{u+1 u} CommRing := sorry
def stalks_local (F : Presheaf.{u+1 u} TopRing) : Prop :=
Π x : F, is_local_ring (((TopRing.forget_to_CommRing).map_presheaf.obj F).stalk_at x)
def V_pre_pre := { F : Presheaf.{u+1 u} TopRing | stalks_local F }
example : category.{u+1 u} V_pre_pre := by unfold V_pre_pre; apply_instance
-- category_theory.sigma_category.{u+1 u} stalks_local.{u}
end category_theory.presheaves |
698ab1e782617b0a8e9b16e13ffa0c7920635c41 | 92b50235facfbc08dfe7f334827d47281471333b | /hott/init/pathover.hlean | d3ead5838a8363dcc5ae8848c7d863551a0dc4ac | [
"Apache-2.0"
] | permissive | htzh/lean | 24f6ed7510ab637379ec31af406d12584d31792c | d70c79f4e30aafecdfc4a60b5d3512199200ab6e | refs/heads/master | 1,607,677,731,270 | 1,437,089,952,000 | 1,437,089,952,000 | 37,078,816 | 0 | 0 | null | 1,433,780,956,000 | 1,433,780,955,000 | null | UTF-8 | Lean | false | false | 9,136 | hlean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Floris van Doorn
Basic theorems about pathovers
-/
prelude
import .path .equiv
open equiv is_equiv equiv.ops
variables {A A' : Type} {B : A → Type} {C : Πa, B a → Type}
{a a₂ a₃ a₄ : A} {p p' : a = a₂} {p₂ : a₂ = a₃} {p₃ : a₃ = a₄}
{b b' : B a} {b₂ b₂' : B a₂} {b₃ : B a₃} {b₄ : B a₄}
{c : C a b} {c₂ : C a₂ b₂}
namespace eq
inductive pathover.{l} (B : A → Type.{l}) (b : B a) : Π{a₂ : A}, a = a₂ → B a₂ → Type.{l} :=
idpatho : pathover B b (refl a) b
notation b `=[`:50 p:0 `]`:0 b₂:50 := pathover _ b p b₂
definition idpo [reducible] [constructor] : b =[refl a] b :=
pathover.idpatho b
/- equivalences with equality using transport -/
definition pathover_of_tr_eq (r : p ▸ b = b₂) : b =[p] b₂ :=
by cases p; cases r; exact idpo
definition pathover_of_eq_tr (r : b = p⁻¹ ▸ b₂) : b =[p] b₂ :=
by cases p; cases r; exact idpo
definition tr_eq_of_pathover [unfold 8] (r : b =[p] b₂) : p ▸ b = b₂ :=
by cases r; exact idp
definition eq_tr_of_pathover [unfold 8] (r : b =[p] b₂) : b = p⁻¹ ▸ b₂ :=
by cases r; exact idp
definition pathover_equiv_tr_eq [constructor] (p : a = a₂) (b : B a) (b₂ : B a₂)
: (b =[p] b₂) ≃ (p ▸ b = b₂) :=
begin
fapply equiv.MK,
{ exact tr_eq_of_pathover},
{ exact pathover_of_tr_eq},
{ intro r, cases p, cases r, apply idp},
{ intro r, cases r, apply idp},
end
definition pathover_equiv_eq_tr [constructor] (p : a = a₂) (b : B a) (b₂ : B a₂)
: (b =[p] b₂) ≃ (b = p⁻¹ ▸ b₂) :=
begin
fapply equiv.MK,
{ exact eq_tr_of_pathover},
{ exact pathover_of_eq_tr},
{ intro r, cases p, cases r, apply idp},
{ intro r, cases r, apply idp},
end
definition pathover_tr [unfold 5] (p : a = a₂) (b : B a) : b =[p] p ▸ b :=
by cases p;exact idpo
definition tr_pathover [unfold 5] (p : a = a₂) (b : B a₂) : p⁻¹ ▸ b =[p] b :=
pathover_of_eq_tr idp
definition concato [unfold 12] (r : b =[p] b₂) (r₂ : b₂ =[p₂] b₃) : b =[p ⬝ p₂] b₃ :=
pathover.rec_on r₂ r
definition inverseo [unfold 8] (r : b =[p] b₂) : b₂ =[p⁻¹] b :=
pathover.rec_on r idpo
definition apdo [unfold 6] (f : Πa, B a) (p : a = a₂) : f a =[p] f a₂ :=
eq.rec_on p idpo
definition oap [unfold 6] {C : A → Type} (f : Πa, B a → C a) (p : a = a₂) : f a =[p] f a₂ :=
eq.rec_on p idpo
definition concato_eq [unfold 10] (r : b =[p] b₂) (q : b₂ = b₂') : b =[p] b₂' :=
eq.rec_on q r
definition eq_concato [unfold 9] (q : b = b') (r : b' =[p] b₂) : b =[p] b₂ :=
by induction q;exact r
-- infix `⬝` := concato
infix `⬝o`:75 := concato
infix `⬝op`:75 := concato_eq
infix `⬝po`:75 := eq_concato
-- postfix `⁻¹` := inverseo
postfix `⁻¹ᵒ`:(max+10) := inverseo
/- Some of the theorems analogous to theorems for = in init.path -/
definition cono_idpo (r : b =[p] b₂) : r ⬝o idpo =[con_idp p] r :=
pathover.rec_on r idpo
definition idpo_cono (r : b =[p] b₂) : idpo ⬝o r =[idp_con p] r :=
pathover.rec_on r idpo
definition cono.assoc' (r : b =[p] b₂) (r₂ : b₂ =[p₂] b₃) (r₃ : b₃ =[p₃] b₄) :
r ⬝o (r₂ ⬝o r₃) =[!con.assoc'] (r ⬝o r₂) ⬝o r₃ :=
pathover.rec_on r₃ (pathover.rec_on r₂ (pathover.rec_on r idpo))
definition cono.assoc (r : b =[p] b₂) (r₂ : b₂ =[p₂] b₃) (r₃ : b₃ =[p₃] b₄) :
(r ⬝o r₂) ⬝o r₃ =[!con.assoc] r ⬝o (r₂ ⬝o r₃) :=
pathover.rec_on r₃ (pathover.rec_on r₂ (pathover.rec_on r idpo))
definition cono.right_inv (r : b =[p] b₂) : r ⬝o r⁻¹ᵒ =[!con.right_inv] idpo :=
pathover.rec_on r idpo
definition cono.left_inv (r : b =[p] b₂) : r⁻¹ᵒ ⬝o r =[!con.left_inv] idpo :=
pathover.rec_on r idpo
definition eq_of_pathover {a' a₂' : A'} (q : a' =[p] a₂') : a' = a₂' :=
by cases q;reflexivity
definition pathover_of_eq {a' a₂' : A'} (q : a' = a₂') : a' =[p] a₂' :=
by cases p;cases q;exact idpo
definition pathover_constant [constructor] (p : a = a₂) (a' a₂' : A') : a' =[p] a₂' ≃ a' = a₂' :=
begin
fapply equiv.MK,
{ exact eq_of_pathover},
{ exact pathover_of_eq},
{ intro r, cases p, cases r, exact idp},
{ intro r, cases r, exact idp},
end
definition eq_of_pathover_idp [unfold 6] {b' : B a} (q : b =[idpath a] b') : b = b' :=
tr_eq_of_pathover q
--should B be explicit in the next two definitions?
definition pathover_idp_of_eq [unfold 6] {b' : B a} (q : b = b') : b =[idpath a] b' :=
eq.rec_on q idpo
definition pathover_idp [constructor] (b : B a) (b' : B a) : b =[idpath a] b' ≃ b = b' :=
equiv.MK eq_of_pathover_idp
(pathover_idp_of_eq)
(to_right_inv !pathover_equiv_tr_eq)
(to_left_inv !pathover_equiv_tr_eq)
-- definition pathover_idp (b : B a) (b' : B a) : b =[idpath a] b' ≃ b = b' :=
-- pathover_equiv_tr_eq idp b b'
-- definition eq_of_pathover_idp [reducible] {b' : B a} (q : b =[idpath a] b') : b = b' :=
-- to_fun !pathover_idp q
-- definition pathover_idp_of_eq [reducible] {b' : B a} (q : b = b') : b =[idpath a] b' :=
-- to_inv !pathover_idp q
definition idp_rec_on [recursor] {P : Π⦃b₂ : B a⦄, b =[idpath a] b₂ → Type}
{b₂ : B a} (r : b =[idpath a] b₂) (H : P idpo) : P r :=
have H2 : P (pathover_idp_of_eq (eq_of_pathover_idp r)), from
eq.rec_on (eq_of_pathover_idp r) H,
proof left_inv !pathover_idp r ▸ H2 qed
definition rec_on_right [recursor] {P : Π⦃b₂ : B a₂⦄, b =[p] b₂ → Type}
{b₂ : B a₂} (r : b =[p] b₂) (H : P !pathover_tr) : P r :=
by cases r; exact H
definition rec_on_left [recursor] {P : Π⦃b : B a⦄, b =[p] b₂ → Type}
{b : B a} (r : b =[p] b₂) (H : P !tr_pathover) : P r :=
by cases r; exact H
--pathover with fibration B' ∘ f
definition pathover_ap [unfold 10] (B' : A' → Type) (f : A → A') {p : a = a₂}
{b : B' (f a)} {b₂ : B' (f a₂)} (q : b =[p] b₂) : b =[ap f p] b₂ :=
by cases q; exact idpo
definition pathover_of_pathover_ap (B' : A' → Type) (f : A → A') {p : a = a₂}
{b : B' (f a)} {b₂ : B' (f a₂)} (q : b =[ap f p] b₂) : b =[p] b₂ :=
by cases p; apply (idp_rec_on q); apply idpo
definition pathover_compose (B' : A' → Type) (f : A → A') (p : a = a₂)
(b : B' (f a)) (b₂ : B' (f a₂)) : b =[p] b₂ ≃ b =[ap f p] b₂ :=
begin
fapply equiv.MK,
{ apply pathover_ap},
{ apply pathover_of_pathover_ap},
{ intro q, cases p, esimp, apply (idp_rec_on q), apply idp},
{ intro q, cases q, exact idp},
end
definition apdo_con (f : Πa, B a) (p : a = a₂) (q : a₂ = a₃)
: apdo f (p ⬝ q) = apdo f p ⬝o apdo f q :=
by cases p; cases q; exact idp
definition apdo_inv (f : Πa, B a) (p : a = a₂) : apdo f p⁻¹ = (apdo f p)⁻¹ᵒ :=
by cases p; exact idp
definition apdo_eq_pathover_of_eq_ap (f : A → A') (p : a = a₂) :
apdo f p = pathover_of_eq (ap f p) :=
eq.rec_on p idp
definition pathover_of_pathover_tr (q : b =[p ⬝ p₂] p₂ ▸ b₂) : b =[p] b₂ :=
by cases p₂;exact q
definition pathover_tr_of_pathover {p : a = a₃} (q : b =[p ⬝ p₂⁻¹] b₂) : b =[p] p₂ ▸ b₂ :=
by cases p₂;exact q
definition pathover_tr_of_eq (q : b = b') : b =[p] p ▸ b' :=
by cases q;apply pathover_tr
definition tr_pathover_of_eq (q : b₂ = b₂') : p⁻¹ ▸ b₂ =[p] b₂' :=
by cases q;apply tr_pathover
definition apo011 (f : Πa, B a → A') (Ha : a = a₂) (Hb : b =[Ha] b₂)
: f a b = f a₂ b₂ :=
by cases Hb; exact idp
definition apo0111 (f : Πa b, C a b → A') (Ha : a = a₂) (Hb : b =[Ha] b₂)
(Hc : c =[apo011 C Ha Hb] c₂) : f a b c = f a₂ b₂ c₂ :=
by cases Hb; apply (idp_rec_on Hc); apply idp
definition apo11 {f : Πb, C a b} {g : Πb₂, C a₂ b₂} (r : f =[p] g)
{b : B a} {b₂ : B a₂} (q : b =[p] b₂) : f b =[apo011 C p q] g b₂ :=
by cases r; apply (idp_rec_on q); exact idpo
definition apo10 {f : Πb, C a b} {g : Πb₂, C a₂ b₂} (r : f =[p] g)
{b : B a} : f b =[apo011 C p !pathover_tr] g (p ▸ b) :=
by cases r; exact idpo
definition cono.right_inv_eq (q : b = b')
: concato_eq (pathover_idp_of_eq q) q⁻¹ = (idpo : b =[refl a] b) :=
by induction q;constructor
definition cono.right_inv_eq' (q : b = b')
: eq_concato q (pathover_idp_of_eq q⁻¹) = (idpo : b =[refl a] b) :=
by induction q;constructor
definition cono.left_inv_eq (q : b = b')
: concato_eq (pathover_idp_of_eq q⁻¹) q = (idpo : b' =[refl a] b') :=
by induction q;constructor
definition cono.left_inv_eq' (q : b = b')
: eq_concato q⁻¹ (pathover_idp_of_eq q) = (idpo : b' =[refl a] b') :=
by induction q;constructor
definition change_path (q : p = p') (r : b =[p] b₂) : b =[p'] b₂ :=
by induction q;exact r
end eq
|
7c37818c9a70bcfeea5a417daac54d486f9e9adf | 35677d2df3f081738fa6b08138e03ee36bc33cad | /src/ring_theory/multiplicity.lean | 236e86e8e6d4c8876846292bbc961b52dcad8718 | [
"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 | 17,375 | lean | /-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import algebra.associated data.int.gcd algebra.big_operators
import tactic.converter.interactive
variables {α : Type*}
open nat roption
theorem nat.find_le {p q : ℕ → Prop} [decidable_pred p] [decidable_pred q]
(h : ∀ n, q n → p n) (hp : ∃ n, p n) (hq : ∃ n, q n) :
nat.find hp ≤ nat.find hq :=
nat.find_min' _ ((h _) (nat.find_spec hq))
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as an `enat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [comm_semiring α] [decidable_rel ((∣) : α → α → Prop)] (a b : α) : enat :=
⟨∃ n : ℕ, ¬a ^ (n + 1) ∣ b, λ h, nat.find h⟩
namespace multiplicity
section comm_semiring
variables [comm_semiring α]
@[reducible] def finite (a b : α) : Prop := ∃ n : ℕ, ¬a ^ (n + 1) ∣ b
lemma finite_iff_dom [decidable_rel ((∣) : α → α → Prop)] {a b : α} :
finite a b ↔ (multiplicity a b).dom := iff.rfl
lemma finite_def {a b : α} : finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b := iff.rfl
@[move_cast]
theorem int.coe_nat_multiplicity (a b : ℕ) :
multiplicity a b = multiplicity (a : ℤ) (b : ℤ) :=
begin
apply roption.ext',
{ repeat {rw [← finite_iff_dom, finite_def]},
norm_cast, simp },
{ intros h1 h2,
apply _root_.le_antisymm; { apply nat.find_le, norm_cast, simp }}
end
lemma not_finite_iff_forall {a b : α} : (¬ finite a b) ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨λ h n, nat.cases_on n (one_dvd _) (by simpa [finite, classical.not_not] using h),
by simp [finite, multiplicity, classical.not_not]; tauto⟩
lemma not_unit_of_finite {a b : α} (h : finite a b) : ¬is_unit a :=
let ⟨n, hn⟩ := h in mt (is_unit_iff_forall_dvd.1 ∘ is_unit_pow (n + 1)) $
λ h, hn (h b)
lemma ne_zero_of_finite {a b : α} (h : finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h in λ hb, by simpa [hb] using hn
lemma finite_of_finite_mul_left {a b c : α} : finite a (b * c) → finite a c :=
λ ⟨n, hn⟩, ⟨n, λ h, hn (dvd.trans h (by simp [_root_.mul_pow]))⟩
lemma finite_of_finite_mul_right {a b c : α} : finite a (b * c) → finite a b :=
by rw mul_comm; exact finite_of_finite_mul_left
variable [decidable_rel ((∣) : α → α → Prop)]
lemma pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} : (k : enat) ≤ multiplicity a b → a ^ k ∣ b :=
nat.cases_on k (λ _, one_dvd _)
(λ k ⟨h₁, h₂⟩, by_contradiction (λ hk, (nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk)))
lemma pow_multiplicity_dvd {a b : α} (h : finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw enat.coe_get)
lemma is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b :=
λ h, have finite a b, from enat.dom_of_le_some (le_of_lt hm),
by rw [← enat.coe_get (finite_iff_dom.1 this), enat.coe_lt_coe] at hm;
exact nat.find_spec this (dvd.trans (pow_dvd_pow _ hm) h)
lemma is_greatest' {a b : α} {m : ℕ} (h : finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← enat.coe_lt_coe, enat.coe_get] at hm)
lemma unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : enat) = multiplicity a b :=
le_antisymm (le_of_not_gt (λ hk', is_greatest hk' hk)) $
have finite a b, from ⟨k, hsucc⟩,
by rw [← enat.coe_get (finite_iff_dom.1 this), enat.coe_le_coe];
exact nat.find_min' _ hsucc
lemma unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬ a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ :=
by rw [← enat.coe_inj, enat.coe_get, unique hk hsucc]
lemma le_multiplicity_of_pow_dvd {a b : α}
{k : ℕ} (hk : a ^ k ∣ b) : (k : enat) ≤ multiplicity a b :=
le_of_not_gt $ λ hk', is_greatest hk' hk
lemma pow_dvd_iff_le_multiplicity {a b : α}
{k : ℕ} : a ^ k ∣ b ↔ (k : enat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
lemma multiplicity_lt_iff_neg_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : enat) ↔ ¬ a ^ k ∣ b :=
by { rw [pow_dvd_iff_le_multiplicity, not_le] }
lemma eq_some_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : enat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b :=
⟨λ h, let ⟨h₁, h₂⟩ := eq_some_iff.1 h in
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest
(by conv_lhs {rw ← enat.coe_get h₁ }; rw [enat.coe_lt_coe]; exact lt_succ_self _)⟩,
λ h, eq_some_iff.2 ⟨⟨n, h.2⟩, eq.symm $ unique' h.1 h.2⟩⟩
lemma eq_top_iff {a b : α} :
multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨λ h n, nat.cases_on n (one_dvd _)
(λ n, by_contradiction (not_exists.1 (eq_none_iff'.1 h) n : _)),
λ h, eq_none_iff.2 (λ n ⟨⟨_, h₁⟩, _⟩, h₁ (h _))⟩
@[simp] protected lemma zero (a : α) : multiplicity a 0 = ⊤ :=
roption.eq_none_iff.2 (λ n ⟨⟨k, hk⟩, _⟩, hk (dvd_zero _))
lemma one_right {a : α} (ha : ¬is_unit a) : multiplicity a 1 = 0 :=
eq_some_iff.2 ⟨dvd_refl _, mt is_unit_iff_dvd_one.2 $ by simpa⟩
@[simp] lemma get_one_right {a : α} (ha : finite a 1) : get (multiplicity a 1) ha = 0 :=
get_eq_iff_eq_some.2 (eq_some_iff.2 ⟨dvd_refl _,
by simpa [is_unit_iff_dvd_one.symm] using not_unit_of_finite ha⟩)
@[simp] lemma multiplicity_unit {a : α} (b : α) (ha : is_unit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 (λ _, is_unit_iff_forall_dvd.1 (is_unit_pow _ ha) _)
@[simp] lemma one_left (b : α) : multiplicity 1 b = ⊤ := by simp [eq_top_iff]
lemma multiplicity_eq_zero_of_not_dvd {a b : α} (ha : ¬a ∣ b) : multiplicity a b = 0 :=
eq_some_iff.2 (by simpa)
lemma eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬ finite a b :=
roption.eq_none_iff'
open_locale classical
lemma multiplicity_le_multiplicity_iff {a b c d : α} : multiplicity a b ≤ multiplicity c d ↔
(∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d) :=
⟨λ h n hab, (pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h)),
λ h, if hab : finite a b
then by rw [← enat.coe_get (finite_iff_dom.1 hab)]; exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else
have ∀ n : ℕ, c ^ n ∣ d, from λ n, h n (not_finite_iff_forall.1 hab _),
by rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2
(not_finite_iff_forall.2 this)]⟩
lemma min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(λ h, by rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact λ n hn, dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
(λ h, by rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact λ n hn, dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn)
lemma dvd_of_multiplicity_pos {a b : α} (h : (0 : enat) < multiplicity a b) : a ∣ b :=
by rw [← _root_.pow_one a]; exact pow_dvd_of_le_multiplicity (enat.pos_iff_one_le.1 h)
lemma finite_nat_iff {a b : ℕ} : finite a b ↔ (a ≠ 1 ∧ 0 < b) :=
begin
rw [← not_iff_not, not_finite_iff_forall, not_and_distrib, ne.def,
not_not, not_lt, nat.le_zero_iff],
exact ⟨λ h, or_iff_not_imp_right.2 (λ hb,
have ha : a ≠ 0, from λ ha, by simpa [ha] using h 1,
by_contradiction (λ ha1 : a ≠ 1,
have ha_gt_one : 1 < a, from
have ∀ a : ℕ, a ≤ 1 → a ≠ 0 → a ≠ 1 → false, from dec_trivial,
lt_of_not_ge (λ ha', this a ha' ha ha1),
not_lt_of_ge (le_of_dvd (nat.pos_of_ne_zero hb) (h b))
(by simp only [nat.pow_eq_pow]; exact lt_pow_self ha_gt_one b))),
λ h, by cases h; simp *⟩
end
lemma finite_int_iff_nat_abs_finite {a b : ℤ} : finite a b ↔ finite a.nat_abs b.nat_abs :=
begin
rw [finite_def, finite_def],
conv in (a ^ _ ∣ b)
{ rw [← int.nat_abs_dvd_abs_iff, int.nat_abs_pow, ← pow_eq_pow] }
end
lemma finite_int_iff {a b : ℤ} : finite a b ↔ (a.nat_abs ≠ 1 ∧ b ≠ 0) :=
begin
have := int.nat_abs_eq a,
have := @int.nat_abs_ne_zero_of_ne_zero b,
rw [finite_int_iff_nat_abs_finite, finite_nat_iff, nat.pos_iff_ne_zero],
split; finish
end
instance decidable_nat : decidable_rel (λ a b : ℕ, (multiplicity a b).dom) :=
λ a b, decidable_of_iff _ finite_nat_iff.symm
instance decidable_int : decidable_rel (λ a b : ℤ, (multiplicity a b).dom) :=
λ a b, decidable_of_iff _ finite_int_iff.symm
end comm_semiring
section comm_ring
variables [comm_ring α] [decidable_rel ((∣) : α → α → Prop)]
open_locale classical
@[simp] protected lemma neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
roption.ext' (by simp only [multiplicity]; conv in (_ ∣ - _) {rw dvd_neg})
(λ h₁ h₂, enat.coe_inj.1 (by rw [enat.coe_get]; exact
eq.symm (unique ((dvd_neg _ _).2 (pow_multiplicity_dvd _))
(mt (dvd_neg _ _).1 (is_greatest' _ (lt_succ_self _))))))
lemma multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b :=
begin
apply le_antisymm,
{ apply enat.le_of_lt_add_one,
cases enat.ne_top_iff.mp (enat.ne_top_of_lt h) with k hk,
rw [hk], rw_mod_cast [multiplicity_lt_iff_neg_dvd], intro h_dvd,
rw [← dvd_add_iff_right] at h_dvd,
apply multiplicity.is_greatest _ h_dvd, rw [hk], apply_mod_cast nat.lt_succ_self,
rw [pow_dvd_iff_le_multiplicity, enat.coe_add, ← hk], exact enat.add_one_le_of_lt h },
{ convert min_le_multiplicity_add, rw [min_eq_right (le_of_lt h)] }
end
lemma multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b :=
by { rw [sub_eq_add_neg, multiplicity_add_of_gt]; rwa [multiplicity.neg] }
lemma multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) :=
begin
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with hab|hab|hab,
{ rw [add_comm, multiplicity_add_of_gt hab, min_eq_left], exact le_of_lt hab },
{ contradiction },
{ rw [multiplicity_add_of_gt hab, min_eq_right], exact le_of_lt hab},
end
end comm_ring
section integral_domain
variables [integral_domain α]
lemma finite_mul_aux {p : α} (hp : prime p) : ∀ {n m : ℕ} {a b : α},
¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n m := λ a b ha hb ⟨s, hs⟩,
have p ∣ a * b, from ⟨p ^ (n + m) * s,
by simp [hs, _root_.pow_add, mul_comm, mul_assoc, mul_left_comm]⟩,
(hp.2.2 a b this).elim
(λ ⟨x, hx⟩, have hn0 : 0 < n,
from nat.pos_of_ne_zero (λ hn0, by clear _fun_match _fun_match; simpa [hx, hn0] using ha),
have wf : (n - 1) < n, from nat.sub_lt_self hn0 dec_trivial,
have hpx : ¬ p ^ (n - 1 + 1) ∣ x,
from λ ⟨y, hy⟩, ha (hx.symm ▸ ⟨y, (domain.mul_left_inj hp.1).1
$ by rw [nat.sub_add_cancel hn0] at hy;
simp [hy, _root_.pow_add, mul_comm, mul_assoc, mul_left_comm]⟩),
have 1 ≤ n + m, from le_trans hn0 (le_add_right n m),
finite_mul_aux hpx hb ⟨s, (domain.mul_left_inj hp.1).1 begin
rw [← nat.sub_add_comm hn0, nat.sub_add_cancel this],
clear _fun_match _fun_match finite_mul_aux,
simp [*, mul_comm, mul_assoc, mul_left_comm, _root_.pow_add] at *
end⟩)
(λ ⟨x, hx⟩, have hm0 : 0 < m,
from nat.pos_of_ne_zero (λ hm0, by clear _fun_match _fun_match; simpa [hx, hm0] using hb),
have wf : (m - 1) < m, from nat.sub_lt_self hm0 dec_trivial,
have hpx : ¬ p ^ (m - 1 + 1) ∣ x,
from λ ⟨y, hy⟩, hb (hx.symm ▸ ⟨y, (domain.mul_left_inj hp.1).1
$ by rw [nat.sub_add_cancel hm0] at hy;
simp [hy, _root_.pow_add, mul_comm, mul_assoc, mul_left_comm]⟩),
finite_mul_aux ha hpx ⟨s, (domain.mul_left_inj hp.1).1 begin
rw [add_assoc, nat.sub_add_cancel hm0],
clear _fun_match _fun_match finite_mul_aux,
simp [*, mul_comm, mul_assoc, mul_left_comm, _root_.pow_add] at *
end⟩)
lemma finite_mul {p a b : α} (hp : prime p) : finite p a → finite p b → finite p (a * b) :=
λ ⟨n, hn⟩ ⟨m, hm⟩, ⟨n + m, finite_mul_aux hp hn hm⟩
lemma finite_mul_iff {p a b : α} (hp : prime p) : finite p (a * b) ↔ finite p a ∧ finite p b :=
⟨λ h, ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩,
λ h, finite_mul hp h.1 h.2⟩
lemma finite_pow {p a : α} (hp : prime p) : Π {k : ℕ} (ha : finite p a), finite p (a ^ k)
| 0 ha := ⟨0, by simp [mt is_unit_iff_dvd_one.2 hp.2.1]⟩
| (k+1) ha := by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow ha)
variable [decidable_rel ((∣) : α → α → Prop)]
@[simp] lemma multiplicity_self {a : α} (ha : ¬is_unit a) (ha0 : a ≠ 0) :
multiplicity a a = 1 :=
eq_some_iff.2 ⟨by simp, λ ⟨b, hb⟩, ha (is_unit_iff_dvd_one.2
⟨b, (domain.mul_left_inj ha0).1 $ by clear _fun_match;
simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩
@[simp] lemma get_multiplicity_self {a : α} (ha : finite a a) :
get (multiplicity a a) ha = 1 :=
roption.get_eq_iff_eq_some.2 (eq_some_iff.2
⟨by simp, λ ⟨b, hb⟩,
by rw [← mul_one a, _root_.pow_add, _root_.pow_one, mul_assoc, mul_assoc,
domain.mul_left_inj (ne_zero_of_finite ha)] at hb;
exact mt is_unit_iff_dvd_one.2 (not_unit_of_finite ha)
⟨b, by clear _fun_match; simp * at *⟩⟩)
protected lemma mul' {p a b : α} (hp : prime p)
(h : (multiplicity p (a * b)).dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a, from pow_multiplicity_dvd _,
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b, from pow_multiplicity_dvd _,
have hpoweq : p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2,
by simp [_root_.pow_add],
have hdiv : p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣ a * b,
by rw [hpoweq]; apply mul_dvd_mul; assumption,
have hsucc : ¬p ^ ((get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) + 1) ∣ a * b,
from λ h, not_or (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp (by convert hdiva)
(by convert hdivb) h),
by rw [← enat.coe_inj, enat.coe_get, eq_some_iff];
exact ⟨hdiv, hsucc⟩
open_locale classical
protected lemma mul {p a b : α} (hp : prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : finite p a ∧ finite p b then
by rw [← enat.coe_get (finite_iff_dom.1 h.1), ← enat.coe_get (finite_iff_dom.1 h.2),
← enat.coe_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)),
← enat.coe_add, enat.coe_inj, multiplicity.mul' hp]; refl
else begin
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)],
cases not_and_distrib.1 h with h h;
simp [eq_top_iff_not_finite.2 h]
end
lemma finset.prod {β : Type*} {p : α} (hp : prime p) (s : finset β) (f : β → α) :
multiplicity p (s.prod f) = s.sum (λ x, multiplicity p (f x)) :=
begin
classical,
induction s using finset.induction with a s has ih h,
{ simp only [finset.sum_empty, finset.prod_empty],
convert one_right hp.not_unit },
{ simp [has, ← ih],
convert multiplicity.mul hp }
end
protected lemma pow' {p a : α} (hp : prime p) (ha : finite p a) : ∀ {k : ℕ},
get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha
| 0 := by dsimp [_root_.pow_zero]; simp [one_right hp.not_unit]; refl
| (k+1) := by dsimp only [_root_.pow_succ];
erw [multiplicity.mul' hp, pow', add_mul, one_mul, add_comm]
lemma pow {p a : α} (hp : prime p) : ∀ {k : ℕ},
multiplicity p (a ^ k) = add_monoid.smul k (multiplicity p a)
| 0 := by simp [one_right hp.not_unit]
| (succ k) := by simp [_root_.pow_succ, succ_smul, pow, multiplicity.mul hp]
lemma multiplicity_pow_self {p : α} (h0 : p ≠ 0) (hu : ¬ is_unit p) (n : ℕ) :
multiplicity p (p ^ n) = n :=
by { rw [eq_some_iff], use dvd_refl _, rw [pow_dvd_pow_iff h0 hu], apply nat.not_succ_le_self }
lemma multiplicity_pow_self_of_prime {p : α} (hp : prime p) (n : ℕ) :
multiplicity p (p ^ n) = n :=
multiplicity_pow_self hp.ne_zero hp.not_unit n
end integral_domain
end multiplicity
section nat
open multiplicity
lemma multiplicity_eq_zero_of_coprime {p a b : ℕ} (hp : p ≠ 1)
(hle : multiplicity p a ≤ multiplicity p b)
(hab : nat.coprime a b) : multiplicity p a = 0 :=
begin
rw [multiplicity_le_multiplicity_iff] at hle,
rw [← le_zero_iff_eq, ← not_lt, enat.pos_iff_one_le, ← enat.coe_one,
← pow_dvd_iff_le_multiplicity],
assume h,
have := nat.dvd_gcd h (hle _ h),
rw [coprime.gcd_eq_one hab, nat.dvd_one, _root_.pow_one] at this,
exact hp this
end
end nat
|
7bc0fd5b1ef47489796ba3017b1da35febc94ad4 | 367134ba5a65885e863bdc4507601606690974c1 | /test/matrix.lean | fc890016b2f9ba5266bde5f689931960df4e98aa | [
"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 | 3,174 | lean | import data.matrix.notation
import linear_algebra.determinant
import group_theory.perm.fin
import tactic.norm_swap
variables {α β : Type} [semiring α] [ring β]
namespace matrix
open_locale matrix
example {a a' b b' c c' d d' : α} :
![![a, b], ![c, d]] + ![![a', b'], ![c', d']] = ![![a + a', b + b'], ![c + c', d + d']] :=
by simp
example {a a' b b' c c' d d' : β} :
![![a, b], ![c, d]] - ![![a', b'], ![c', d']] = ![![a - a', b - b'], ![c - c', d - d']] :=
by simp
example {a a' b b' c c' d d' : α} :
![![a, b], ![c, d]] ⬝ ![![a', b'], ![c', d']] =
![![a * a' + b * c', a * b' + b * d'], ![c * a' + d * c', c * b' + d * d']] :=
by simp
example {a b c d x y : α} :
mul_vec ![![a, b], ![c, d]] ![x, y] = ![a * x + b * y, c * x + d * y] :=
by simp
example {a b c d : α} : minor ![![a, b], ![c, d]] ![1, 0] ![0] = ![![c], ![a]] :=
by { ext, simp }
example {a b c : α} : ![a, b, c] 0 = a := by simp
example {a b c : α} : ![a, b, c] 1 = b := by simp
example {a b c : α} : ![a, b, c] 2 = c := by simp
example {a b c d : α} : ![a, b, c, d] 0 = a := by simp
example {a b c d : α} : ![a, b, c, d] 1 = b := by simp
example {a b c d : α} : ![a, b, c, d] 2 = c := by simp
example {a b c d : α} : ![a, b, c, d] 3 = d := by simp
example {a b c d : α} : ![a, b, c, d] 42 = c := by simp
example {a b c d e : α} : ![a, b, c, d, e] 0 = a := by simp
example {a b c d e : α} : ![a, b, c, d, e] 1 = b := by simp
example {a b c d e : α} : ![a, b, c, d, e] 2 = c := by simp
example {a b c d e : α} : ![a, b, c, d, e] 3 = d := by simp
example {a b c d e : α} : ![a, b, c, d, e] 4 = e := by simp
example {a b c d e : α} : ![a, b, c, d, e] 5 = a := by simp
example {a b c d e : α} : ![a, b, c, d, e] 6 = b := by simp
example {a b c d e : α} : ![a, b, c, d, e] 7 = c := by simp
example {a b c d e : α} : ![a, b, c, d, e] 8 = d := by simp
example {a b c d e : α} : ![a, b, c, d, e] 9 = e := by simp
example {a b c d e : α} : ![a, b, c, d, e] 123 = d := by simp
example {a b c d e : α} : ![a, b, c, d, e] 123456789 = e := by simp
example {a b c d e f g h : α} : ![a, b, c, d, e, f, g, h] 5 = f := by simp
example {a b c d e f g h : α} : ![a, b, c, d, e, f, g, h] 7 = h := by simp
example {a b c d e f g h : α} : ![a, b, c, d, e, f, g, h] 37 = f := by simp
example {a b c d e f g h : α} : ![a, b, c, d, e, f, g, h] 99 = d := by simp
example {α : Type*} [comm_ring α] {a b c d : α} :
matrix.det ![![a, b], ![c, d]] = a * d - b * c :=
begin
-- TODO: can we make this require less steering?
simp [matrix.det, finset.univ_perm_fin_succ, ←finset.univ_product_univ, finset.sum_product,
fin.sum_univ_succ, fin.prod_univ_succ],
ring
end
example {α : Type*} [comm_ring α] (A : matrix (fin 3) (fin 3) α) {a b c d e f g h i : α} :
matrix.det ![![a, b, c], ![d, e, f], ![g, h, i]] =
a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g :=
begin
-- We utilize the `norm_swap` plugin for `norm_num` to reduce swap terms
norm_num [matrix.det, finset.univ_perm_fin_succ, ←finset.univ_product_univ,
finset.sum_product, fin.sum_univ_succ, fin.prod_univ_succ],
ring
end
end matrix
|
b54a3d877cd61e5e90e699c22e82ed3444f913c4 | 2ee768fce4d0783536570385ee340d97e2411436 | /src/v_prop.lean | 1590a5bb5b06cfa5583b33681f2fb6b509965f07 | [] | no_license | agjftucker/exists-unique | 835cf0c0ec622d49dbceb84be37db62e6ab8a6d0 | 1fba6035a08347f424c765d8a1c56b1a15c8abbe | refs/heads/master | 1,683,445,592,336 | 1,622,649,822,000 | 1,622,649,822,000 | 309,485,697 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,910 | lean | import v_def
local prefix `𝒫`:100 := fun {α : Type} (s : finset α), {t // t ≤ s}
variables {𝒩 : Type} {T : with_top ℝ} {ψ ψ' : ∀ (B : finset 𝒩), Tt T → X 𝒩 → 𝒫 B}
lemma V_empty_eq_univ (t : Tt T) : V ψ ∅ t = set.univ :=
begin
apply set.eq_univ_of_forall,
intro y,
apply finset.empty_subset,
end
variables [decidable_eq 𝒩] {ℋ : well_behaved_soln 𝒩 T}
lemma ssubsets_nonempty {A : finset 𝒩} {t : Tt T} {y : X 𝒩} : y ∉ V ψ A t → A.ssubsets.nonempty :=
begin
intro hy,
use ∅,
apply finset.empty_mem_ssubsets,
rw finset.nonempty_iff_ne_empty,
intro he,
apply hy,
rw [he, V_empty_eq_univ],
trivial,
end
lemma v_eq_of_ψ_eq_on_ssubsets (A : finset 𝒩) :
(∀ B < A, ψ B = ψ' B) → (∀ B < A, v ℋ ψ B = v ℋ ψ' B) :=
begin
induction A using finset.strong_induction with A ih,
intros hψ B hB,
conv_lhs { rw [v, finset.strong_induction_eq, ←v], },
conv_rhs { rw [v, finset.strong_induction_eq, ←v], },
congr,
{ exact hψ B hB, },
{ specialize ih B hB (fun C hC, hψ C (trans hC hB)),
funext C hC,
exact ih C hC, },
end
lemma v_match : ∀ A t y, v ℋ ψ A t y = v ℋ ψ (ψ A t y) t y :=
begin
intros A t y,
cases dec_em (y ∈ V ψ A t) with hy hy,
{ rw le_antisymm (ψ A t y).prop hy, },
{ funext i,
conv_lhs
{ rw [v, finset.strong_induction_eq, ←v],
change ite (i ∈ A) (ℋ (fun s x _, v ℋ ψ (ψ A s x) s x i) t y) 0, },
split_ifs with hi,
{ apply ℋ.matching_on_complement,
exact hy, },
conv_rhs
{ rw [v, finset.strong_induction_eq, ←v],
change ite (i ∈ ↑(ψ A t y)) (ℋ (fun s x _, v ℋ ψ (ψ (ψ A t y) s x) s x i) t y) 0,
rw if_neg (fun h, hi ((ψ A t y).prop h)), }, },
end
lemma v_eq_ite (A : finset 𝒩) (t : Tt T) (y : X 𝒩) (i : 𝒩) : v ℋ ψ A t y i =
ite (i ∈ A) (ℋ (fun s x (h : x ∉ V ψ A s), v ℋ ψ A s x i) t y) 0 :=
begin
conv_lhs
{ rw [v, finset.strong_induction_eq],
change ite (i ∈ A) (ℋ (fun s x (h : x ∉ V ψ A s), v ℋ ψ (ψ A s x) s x i) t y) 0, },
simp_rw ←v_match,
end
lemma v_nonneg (A : finset 𝒩) : 0 ≤ v ℋ ψ A :=
begin
induction A using finset.strong_induction with A ih,
rw [v, finset.strong_induction_eq, ←v],
intros t y i,
change 0 ≤ ite (i ∈ A) (ℋ (fun s x _, v ℋ ψ (ψ A s x) s x i) t y) 0,
split_ifs with hi,
{ apply ℋ.positivity_preserving,
intros s x h,
apply ih,
use [(ψ A s x).prop, h], },
{ exact refl 0, },
end
lemma pos_op {A B : finset 𝒩} (hle : B ≤ A) :
(∀ s x, x ∉ V ψ A s ∩ V ψ B s → v ℋ ψ B s x ≤ v ℋ ψ A s x) → v ℋ ψ B ≤ v ℋ ψ A :=
begin
intros hc t y i,
let vA := λ s x (h : x ∉ V ψ A s), v ℋ ψ (ψ A s x) s x i,
let vB := λ s x (h : x ∉ V ψ B s), v ℋ ψ (ψ B s x) s x i,
conv_lhs
{ rw [v, finset.strong_induction_eq, ←v],
change ite (i ∈ B) (ℋ vB t y) 0, },
split_ifs with hi,
{ conv_rhs
{ rw [v, finset.strong_induction_eq, ←v],
change ite (i ∈ A) (ℋ vA t y) 0, },
rw if_pos (hle hi),
revert t y,
change ℋ vB ≤ ℋ vA,
have hB : ℋ vB = ℋ (λ s x (h : x ∉ V ψ A s ∩ V ψ B s), ℋ vB s x),
{ apply ℋ.compatible_on_subsets,
intro s,
exact set.inter_subset_right _ _, },
have hA : ℋ vA = ℋ (λ s x (h : x ∉ V ψ A s ∩ V ψ B s), ℋ vA s x),
{ apply ℋ.compatible_on_subsets,
intro s,
exact set.inter_subset_left _ _, },
rw [hB, hA],
apply ℋ.mono_wrt_val_on_compl,
intros t y h,
specialize hc t y h i,
conv_lhs at hc
{ rw [v, finset.strong_induction_eq],
change ite (i ∈ B) (ℋ vB t y) 0, },
conv_rhs at hc
{ rw [v, finset.strong_induction_eq],
change ite (i ∈ A) (ℋ vA t y) 0, },
rw [if_pos hi, if_pos (hle hi)] at hc,
exact hc, },
{ apply v_nonneg, },
end
|
5b09fda15beed43d48a7ba2a4f2d78b7a9c8ff0b | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/Lean/Meta/DecLevel.lean | 3cc5fe3c9135474d76c8136c05e2ff36f9b72810 | [
"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 | 2,704 | 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.Meta.Basic
import Lean.Meta.InferType
namespace Lean.Meta
structure DecLevelContext where
/--
If `true`, then `decAux? ?m` returns a fresh metavariable `?n` s.t.
`?m := ?n+1`.
-/
canAssignMVars : Bool := true
private partial def decAux? : Level → ReaderT DecLevelContext MetaM (Option Level)
| Level.zero => return none
| Level.param _ => return none
| Level.mvar mvarId => do
match (← getLevelMVarAssignment? mvarId) with
| some u => decAux? u
| none =>
if (← mvarId.isReadOnly) || !(← read).canAssignMVars then
return none
else
let u ← mkFreshLevelMVar
trace[Meta.isLevelDefEq.step] "decAux?, {mkLevelMVar mvarId} := {mkLevelSucc u}"
assignLevelMVar mvarId (mkLevelSucc u)
return u
| Level.succ u => return u
| u =>
let processMax (u v : Level) : ReaderT DecLevelContext MetaM (Option Level) := do
/- Remark: this code uses the fact that `max (u+1) (v+1) = (max u v)+1`.
`decAux? (max (u+1) (v+1)) := max (decAux? (u+1)) (decAux? (v+1))`
However, we must *not* assign metavariables in the recursive calls since
`max ?u 1` is not equivalent to `max ?v 0` where `?v` is a fresh metavariable, and `?u := ?v+1`
-/
withReader (fun _ => { canAssignMVars := false }) do
match (← decAux? u) with
| none => return none
| some u => do
match (← decAux? v) with
| none => return none
| some v => return mkLevelMax' u v
match u with
| Level.max u v => processMax u v
/- Remark: If `decAux? v` returns `some ...`, then `imax u v` is equivalent to `max u v`. -/
| Level.imax u v => processMax u v
| _ => unreachable!
def decLevel? (u : Level) : MetaM (Option Level) := do
let mctx ← getMCtx
match (← decAux? u |>.run {}) with
| some v => return some v
| none => do
modify fun s => { s with mctx := mctx }
return none
def decLevel (u : Level) : MetaM Level := do
match (← decLevel? u) with
| some u => return u
| none => throwError "invalid universe level, {u} is not greater than 0"
/-- This method is useful for inferring universe level parameters for function that take arguments such as `{α : Type u}`.
Recall that `Type u` is `Sort (u+1)` in Lean. Thus, given `α`, we must infer its universe level,
and then decrement 1 to obtain `u`. -/
def getDecLevel (type : Expr) : MetaM Level := do
decLevel (← getLevel type)
end Lean.Meta
|
2391d8fcbfaa3dcde68419c201a3c9a1e64b8642 | 6214e13b31733dc9aeb4833db6a6466005763162 | /src/progress.lean | fc34386f253229e3801827181b4e6e9210a17c57 | [] | no_license | joshua0pang/esverify-theory | 272a250445f3aeea49a7e72d1ab58c2da6618bbe | 8565b123c87b0113f83553d7732cd6696c9b5807 | refs/heads/master | 1,585,873,849,081 | 1,527,304,393,000 | 1,527,304,393,000 | 154,901,199 | 1 | 0 | null | 1,540,593,067,000 | 1,540,593,067,000 | null | UTF-8 | Lean | false | false | 15,190 | lean | import .definitions3 .logic
lemma exp.progress {R: spec} {P: prop} {Q: propctx} {e: exp} {σ: env}:
(⊩ σ: P) → (FV R.to_prop ⊆ FV P) → (σ ⊨ R.to_prop.to_vc) → (R ⋀ P ⊩ e: Q) →
is_dvalue (R, σ, e) ∨ ∃s', (R, σ, e) ⟹ s' :=
assume env_verified: (⊩ σ : P),
assume fv_R: FV R.to_prop ⊆ FV P,
assume R_valid: (σ ⊨ R.to_prop.to_vc),
assume e_verified: (R ⋀ P ⊩ e : Q),
have R_closed: closed_subst σ R.to_prop, from (
assume z: var,
assume : z ∈ FV R.to_prop,
have z ∈ FV P, from set.mem_of_subset_of_mem fv_R this,
show z ∈ σ.dom, from (free_iff_contains env_verified).symm ▸ this
),
show is_dvalue (R, σ, e) ∨ ∃s', (R, σ, e) ⟹ s', by begin
cases e_verified,
case exp.dvcgen.tru x e' { from
let s: dstack := (R, σ, lett x = true in e') in
have s ⟹ (R, σ[x↦value.true], e'), from dstep.tru,
have ∃s', s ⟹ s', from exists.intro (R, σ[x↦value.true], e') this,
show is_dvalue s ∨ ∃s', s ⟹ s', from or.inr this
},
case exp.dvcgen.fals x e' { from
let s: dstack := (R, σ, letf x = false in e') in
have s ⟹ (R, σ[x↦value.false], e'), from dstep.fals,
have ∃s', s ⟹ s', from exists.intro (R, σ[x↦value.false], e') this,
show is_dvalue s ∨ ∃s', s ⟹ s', from or.inr this
},
case exp.dvcgen.num x n e' { from
let s: dstack := (R, σ, letn x = n in e') in
have s ⟹ (R, σ[x↦value.num n], e'), from dstep.num,
have ∃s', s ⟹ s', from exists.intro (R, σ[x↦value.num n], e') this,
show is_dvalue s ∨ ∃s', s ⟹ s', from or.inr this
},
case exp.dvcgen.func f x R' S' e₁ e₂ { from
let s: dstack := (R, σ, letf f[x] req R' ens S' {e₁} in e₂) in
have s ⟹ (R, σ[f↦value.func f x R' S' e₁ σ], e₂), from dstep.closure,
have ∃s', s ⟹ s', from exists.intro (R, σ[f↦value.func f x R' S' e₁ σ], e₂) this,
show is_dvalue s ∨ ∃s', s ⟹ s', from or.inr this
},
case exp.dvcgen.unop op x y e' Q' x_free_in_P _ e'_verified vc_valid { from
let s: dstack := (R, σ, letop y = op[x] in e') in
let ⟨v, env_has_x⟩ := (val_of_free_in_pre_env env_verified fv_R x_free_in_P) in
have closed_subst σ (prop.pre₁ op x), from (
assume z: var,
assume : z ∈ FV (prop.pre₁ op x),
have free_in_term z x, from free_in_prop.pre₁.inv this,
have z = x, from free_in_term.var.inv this,
show z ∈ σ, from this.symm ▸ env.contains_apply_equiv.right.mp (exists.intro v env_has_x)
),
have h1: σ ⊨ (prop.pre₁ op x).to_vc, from consequent_of_pre_P env_verified R_closed R_valid this vc_valid,
have (prop.pre₁ op x).to_vc = vc.pre₁ op x, by unfold prop.to_vc,
have h2: ⊨ vc.subst_env σ (vc.pre₁ op x), from this ▸ h1,
have vc.subst_env σ (vc.pre₁ op x) = vc.pre₁ op (term.subst_env σ x), from vc.subst_env.pre₁,
have ⊨ vc.pre₁ op (term.subst_env σ x), from this ▸ h2,
have x_from_env: term.subst_env σ x = v, from (term.subst_env.var.right v).mp env_has_x,
have ⊨ vc.pre₁ op v, from x_from_env ▸ this,
have option.is_some (unop.apply op v), from valid.pre₁ this,
have (∃v', unop.apply op v = some v'), from option.is_some_iff_exists.mp this,
let ⟨v', op_v_is_v'⟩ := this in
have s ⟹ (R, σ[y↦v'], e'), from dstep.unop env_has_x op_v_is_v',
have ∃s', s ⟹ s', from exists.intro (R, σ[y↦v'], e') this,
show is_dvalue s ∨ ∃s', s ⟹ s', from or.inr this
},
case exp.dvcgen.binop op x y z e' Q' x_free_in_P y_free_in_P _ e'_verified vc_valid { from
let s: dstack := (R, σ, letop2 z = op[x,y] in e') in
let ⟨vx, env_has_x⟩ := (val_of_free_in_pre_env env_verified fv_R x_free_in_P) in
let ⟨vy, env_has_y⟩ := (val_of_free_in_pre_env env_verified fv_R y_free_in_P) in
have closed_subst σ (prop.pre₂ op x y), from (
assume z: var,
assume : z ∈ FV (prop.pre₂ op x y),
or.elim (free_in_prop.pre₂.inv this) (
assume : free_in_term z x,
have z = x, from free_in_term.var.inv this,
show z ∈ σ, from this.symm ▸ env.contains_apply_equiv.right.mp (exists.intro vx env_has_x)
) (
assume : free_in_term z y,
have z = y, from free_in_term.var.inv this,
show z ∈ σ, from this.symm ▸ env.contains_apply_equiv.right.mp (exists.intro vy env_has_y)
)
),
have h1: σ ⊨ (prop.pre₂ op x y).to_vc, from consequent_of_pre_P env_verified R_closed R_valid this vc_valid,
have (prop.pre₂ op x y).to_vc = vc.pre₂ op x y, by unfold prop.to_vc,
have h2: ⊨ vc.subst_env σ (vc.pre₂ op x y), from this ▸ h1,
have vc.subst_env σ (vc.pre₂ op x y) = vc.pre₂ op (term.subst_env σ x) (term.subst_env σ y),
from vc.subst_env.pre₂,
have h3: ⊨ vc.pre₂ op (term.subst_env σ x) (term.subst_env σ y), from this ▸ h2,
have term.subst_env σ x = vx, from (term.subst_env.var.right vx).mp env_has_x,
have h4: ⊨ vc.pre₂ op vx (term.subst_env σ y), from this ▸ h3,
have term.subst_env σ y = vy, from (term.subst_env.var.right vy).mp env_has_y,
have ⊨ vc.pre₂ op vx vy, from this ▸ h4,
have option.is_some (binop.apply op vx vy), from valid.pre₂ this,
have (∃v', binop.apply op vx vy = some v'), from option.is_some_iff_exists.mp this,
let ⟨v', op_v_is_v'⟩ := this in
have s ⟹ (R, σ[z↦v'], e'), from dstep.binop env_has_x env_has_y op_v_is_v',
have ∃s', s ⟹ s', from exists.intro (R, σ[z↦v'], e') this,
show is_dvalue s ∨ ∃s', s ⟹ s', from or.inr this
},
case exp.dvcgen.app y f x e' Q' f_free_in_P x_free_in_P _ e'_verified vc_valid { from
let s: dstack := (R, σ, letapp y = f [x] in e') in
let ⟨vf, env_f_is_vf⟩ := (val_of_free_in_pre_env env_verified fv_R f_free_in_P) in
have env_has_f: f ∈ σ, from env.contains_apply_equiv.right.mp (exists.intro vf env_f_is_vf),
let ⟨vx, env_x_is_vx⟩ := (val_of_free_in_pre_env env_verified fv_R x_free_in_P) in
have env_has_x: x ∈ σ, from env.contains_apply_equiv.right.mp (exists.intro vx env_x_is_vx),
have closed_subst σ (↑(term.unop unop.isFunc f) ⋀ prop.pre f x), from (
assume z: var,
assume : z ∈ FV (↑(term.unop unop.isFunc f) ⋀ prop.pre f x),
or.elim (free_in_prop.and.inv this) (
assume : free_in_prop z (term.unop unop.isFunc f),
have free_in_term z (term.unop unop.isFunc f), from free_in_prop.term.inv this,
have free_in_term z f, from free_in_term.unop.inv this,
have z = f, from free_in_term.var.inv this,
show z ∈ σ, from this.symm ▸ env_has_f
) (
assume : z ∈ FV (prop.pre f x),
or.elim (free_in_prop.pre.inv this) (
assume : free_in_term z f,
have z = f, from free_in_term.var.inv this,
show z ∈ σ, from this.symm ▸ env_has_f
) (
assume : free_in_term z x,
have z = x, from free_in_term.var.inv this,
show z ∈ σ, from this.symm ▸ env_has_x
)
)
),
have h1: σ ⊨ (↑(term.unop unop.isFunc f) ⋀ prop.pre f x).to_vc,
from consequent_of_pre_P_call env_verified R_closed R_valid env_has_x this vc_valid,
have (prop.and (prop.term (term.unop unop.isFunc f)) (prop.pre f x)).to_vc
= ((prop.term (term.unop unop.isFunc f)).to_vc ⋀ (prop.pre f x).to_vc),
by unfold prop.to_vc,
have σ ⊨ ((prop.term (term.unop unop.isFunc f)).to_vc ⋀ (prop.pre f x).to_vc), from this ▸ h1,
have h2: ⊨ vc.subst_env σ ((prop.term (term.unop unop.isFunc f)).to_vc ⋀ (prop.pre f x).to_vc), from this,
have vc.subst_env σ ((prop.term (term.unop unop.isFunc f)).to_vc ⋀ (prop.pre f x).to_vc)
= (vc.subst_env σ ((prop.term (term.unop unop.isFunc f)).to_vc) ⋀ vc.subst_env σ ((prop.pre f x).to_vc)),
from vc.subst_env.and,
have ⊨ (vc.subst_env σ ((prop.term (term.unop unop.isFunc f)).to_vc) ⋀
vc.subst_env σ ((prop.pre f x).to_vc)),
from this ▸ h2,
have h5: σ ⊨ (prop.term (term.unop unop.isFunc f)).to_vc, from (valid.and.mpr this).left,
have (prop.term (term.unop unop.isFunc f)).to_vc = vc.term (term.unop unop.isFunc f),
by unfold prop.to_vc,
have h6: σ ⊨ vc.term (term.unop unop.isFunc f), from this ▸ h5,
have vc.subst_env σ (vc.term (term.unop unop.isFunc f)) = vc.term (term.subst_env σ (term.unop unop.isFunc f)),
from vc.subst_env.term,
have h7: ⊨ vc.term (term.subst_env σ (term.unop unop.isFunc f)), from this ▸ h6,
have term.subst_env σ (term.unop unop.isFunc f) = term.unop unop.isFunc (term.subst_env σ f),
from term.subst_env.unop,
have h8: ⊨ vc.term (term.unop unop.isFunc (term.subst_env σ f)), from this ▸ h7,
have term.subst_env σ f = vf, from (term.subst_env.var.right vf).mp env_f_is_vf,
have ⊨ term.unop unop.isFunc vf, from this ▸ h8,
have ⊨ (value.true ≡ term.unop unop.isFunc vf), from valid.eq.true.mp this,
have unop.apply unop.isFunc vf = some value.true, from valid.unop.mpr this,
have ∃(g gx: var) (gR gS: spec) (ge: exp) (gσ: env), vf = value.func g gx gR gS ge gσ,
from unop.isFunc.inv this,
let ⟨g, gx, gR, gS, ge, gσ, vf_is_g⟩ := this in
have some_vf_is_g: some vf = ↑(value.func g gx gR gS ge gσ), from some.inj.inv vf_is_g,
have σ f = value.func g gx gR gS ge gσ, from eq.trans env_f_is_vf some_vf_is_g,
let s': dstack := dstack.cons (gR, gσ[g↦value.func g gx gR gS ge gσ][gx↦vx], ge) R σ y f x e' in
have s ⟹ s', from dstep.app this env_x_is_vx,
have ∃s', s ⟹ s', from exists.intro s' this,
show is_dvalue s ∨ ∃s', s ⟹ s', from or.inr this
},
case exp.dvcgen.ite x e₂ e₁ Q₁ Q₂ x_free_in_P _ _ vc_valid { from
let s: dstack := (R, σ, exp.ite x e₁ e₂) in
let ⟨v, env_has_x⟩ := (val_of_free_in_pre_env env_verified fv_R x_free_in_P) in
have closed_subst σ (prop.term (term.unop unop.isBool x)), from (
assume z: var,
assume : z ∈ FV (prop.term (term.unop unop.isBool x)),
have free_in_term z (term.unop unop.isBool x), from free_in_prop.term.inv this,
have free_in_term z x, from free_in_term.unop.inv this,
have z = x, from free_in_term.var.inv this,
show z ∈ σ, from this.symm ▸ env.contains_apply_equiv.right.mp (exists.intro v env_has_x)
),
have h1: σ ⊨ (prop.term (term.unop unop.isBool x)).to_vc,
from consequent_of_pre_P env_verified R_closed R_valid this vc_valid,
have (prop.term (term.unop unop.isBool x)).to_vc = vc.term (term.unop unop.isBool x),
by unfold prop.to_vc,
have h2: σ ⊨ vc.term (term.unop unop.isBool x), from this ▸ h1,
have vc.subst_env σ (vc.term (term.unop unop.isBool x)) = vc.term (term.subst_env σ (term.unop unop.isBool x)),
from vc.subst_env.term,
have h3: ⊨ vc.term (term.subst_env σ (term.unop unop.isBool x)), from this ▸ h2,
have term.subst_env σ (term.unop unop.isBool x) = term.unop unop.isBool (term.subst_env σ x),
from term.subst_env.unop,
have h4: ⊨ vc.term (term.unop unop.isBool (term.subst_env σ x)), from this ▸ h3,
have term.subst_env σ x = v, from (term.subst_env.var.right v).mp env_has_x,
have ⊨ term.unop unop.isBool v, from this ▸ h4,
have ⊨ (value.true ≡ term.unop unop.isBool v), from valid.eq.true.mp this,
have unop.apply unop.isBool v = some value.true, from valid.unop.mpr this,
have (v = value.true) ∨ (v = value.false), from unop.isBool.inv this,
or.elim this (
assume : v = value.true,
have some v = some value.true, from some.inj.inv this,
have σ x = value.true, from eq.trans env_has_x this,
have s ⟹ (R, σ, e₁), from dstep.ite_true this,
have ∃s', s ⟹ s', from exists.intro (R, σ, e₁) this,
show is_dvalue s ∨ ∃s', s ⟹ s', from or.inr this
) (
assume : v = value.false,
have some v = some value.false, from some.inj.inv this,
have σ x = value.false, from eq.trans env_has_x this,
have s ⟹ (R, σ, e₂), from dstep.ite_false this,
have ∃s', s ⟹ s', from exists.intro (R, σ, e₂) this,
show is_dvalue s ∨ ∃s', s ⟹ s', from or.inr this
)
},
case exp.dvcgen.return x x_free_in_P { from
let s: dstack := (R, σ, exp.return x) in
have s_is_return: s = (R, σ, exp.return x), from rfl,
let ⟨v, env_has_x⟩ := (val_of_free_in_pre_env env_verified fv_R x_free_in_P) in
have is_value_s: is_dvalue s
= (∃(R': spec) (σ': env) (x': var) (v: value), s = (R', σ', exp.return x') ∧ (σ' x' = v)),
by unfold is_dvalue,
have (∃(R': spec) (σ': env) (x': var) (v: value), s = (R', σ', exp.return x') ∧ (σ' x' = v)),
from exists.intro R (exists.intro σ (exists.intro x (exists.intro v ⟨s_is_return, env_has_x⟩))),
have is_dvalue s, from is_value_s ▸ this,
show is_dvalue s ∨ ∃s', s ⟹ s', from or.inl this
}
end
theorem progress {s: dstack} {Q: propctx}: (⊩ₛ s : Q) → is_dvalue s ∨ ∃s', s ⟹ s'
:=
assume s_verified: ⊩ₛ s : Q,
begin
induction s_verified,
case stack.dvcgen.top σ e R P Q env_verified fv_R R_valid e_verified { from
show is_dvalue (R, σ, e) ∨ ∃s', (R, σ, e) ⟹ s', from exp.progress env_verified fv_R R_valid e_verified
},
case stack.dvcgen.cons P P' P'' s' σ σ' f g x y fx R R' S' e₁ e₂ vₓ Q Q' Q''
s'_verified y_not_in_σ σ_verified σ'_verified σ''_verified fv_R R_valid g_is_func
x_is_v e₁_verified cont Q''_dom Q''_fv pre_vc steps ih { from
let s := dstack.cons s' R σ y g x e₁ in
have s_cons: s = (dstack.cons s' R σ y g x e₁), from rfl,
or.elim ih
( -- step return
assume s'_is_value: is_dvalue s',
let ⟨R₂, σ₂, z, v, ⟨s'_return, env2_has_z⟩⟩ := s'_is_value in
have s_return_cons: s = dstack.cons (R₂, σ₂, exp.return z) R σ y g x e₁,
from s'_return ▸ s_cons,
have s ⟹ (R, σ[y↦v], e₁),
from s_return_cons.symm ▸ (dstep.return env2_has_z g_is_func x_is_v),
have ∃s', s ⟹ s',
from exists.intro (R, σ[y↦v], e₁) this,
show is_dvalue s ∨ ∃s', s ⟹ s', from or.inr this
)
( -- step ctx
assume s'_can_step: ∃s'', s' ⟹ s'',
let ⟨s'', s'_steps⟩ := s'_can_step in
have s ⟹ dstack.cons s'' R σ y g x e₁, from dstep.ctx s'_steps,
have ∃s', s ⟹ s', from exists.intro (dstack.cons s'' R σ y g x e₁) this,
show is_dvalue s ∨ ∃s', s ⟹ s', from or.inr this
)
}
end
|
851d41e93a6fed1b48959f958a1ee60d4af64944 | 80cc5bf14c8ea85ff340d1d747a127dcadeb966f | /src/linear_algebra/bilinear_form.lean | e2144232457edc3ddd0f5debd43004789914c2cd | [
"Apache-2.0"
] | permissive | lacker/mathlib | f2439c743c4f8eb413ec589430c82d0f73b2d539 | ddf7563ac69d42cfa4a1bfe41db1fed521bd795f | refs/heads/master | 1,671,948,326,773 | 1,601,479,268,000 | 1,601,479,268,000 | 298,686,743 | 0 | 0 | Apache-2.0 | 1,601,070,794,000 | 1,601,070,794,000 | null | UTF-8 | Lean | false | false | 28,134 | lean | /-
Copyright (c) 2018 Andreas Swerdlow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Andreas Swerdlow
-/
import linear_algebra.matrix
import linear_algebra.tensor_product
import linear_algebra.nonsingular_inverse
/-!
# Bilinear form
This file defines a bilinear form over a module. Basic ideas
such as orthogonality are also introduced, as well as reflexivive,
symmetric and alternating bilinear forms. Adjoints of linear maps
with respect to a bilinear form are also introduced.
A bilinear form on an R-module M, is a function from M x M to R,
that is linear in both arguments
## Notations
Given any term B of type bilin_form, due to a coercion, can use
the notation B x y to refer to the function field, ie. B x y = B.bilin x y.
## References
* <https://en.wikipedia.org/wiki/Bilinear_form>
## Tags
Bilinear form,
-/
open_locale big_operators
universes u v w
/-- A bilinear form over a module -/
structure bilin_form (R : Type u) (M : Type v) [ring R] [add_comm_group M] [module R M] :=
(bilin : M → M → R)
(bilin_add_left : ∀ (x y z : M), bilin (x + y) z = bilin x z + bilin y z)
(bilin_smul_left : ∀ (a : R) (x y : M), bilin (a • x) y = a * (bilin x y))
(bilin_add_right : ∀ (x y z : M), bilin x (y + z) = bilin x y + bilin x z)
(bilin_smul_right : ∀ (a : R) (x y : M), bilin x (a • y) = a * (bilin x y))
/-- A map with two arguments that is linear in both is a bilinear form -/
def linear_map.to_bilin {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M]
(f : M →ₗ[R] M →ₗ[R] R) : bilin_form R M :=
{ bilin := λ x y, f x y,
bilin_add_left := λ x y z, (linear_map.map_add f x y).symm ▸ linear_map.add_apply (f x) (f y) z,
bilin_smul_left := λ a x y, by {rw linear_map.map_smul, rw linear_map.smul_apply, rw smul_eq_mul},
bilin_add_right := λ x y z, linear_map.map_add (f x) y z,
bilin_smul_right := λ a x y, linear_map.map_smul (f x) a y }
namespace bilin_form
variables {R : Type u} {M : Type v} [ring R] [add_comm_group M] [module R M] {B : bilin_form R M}
instance : has_coe_to_fun (bilin_form R M) :=
⟨_, λ B, B.bilin⟩
@[simp] lemma coe_fn_mk (f : M → M → R) (h₁ h₂ h₃ h₄) :
(bilin_form.mk f h₁ h₂ h₃ h₄ : M → M → R) = f :=
rfl
lemma coe_fn_congr : Π {x x' y y' : M}, x = x' → y = y' → B x y = B x' y'
| _ _ _ _ rfl rfl := rfl
lemma add_left (x y z : M) : B (x + y) z = B x z + B y z := bilin_add_left B x y z
lemma smul_left (a : R) (x y : M) : B (a • x) y = a * (B x y) := bilin_smul_left B a x y
lemma add_right (x y z : M) : B x (y + z) = B x y + B x z := bilin_add_right B x y z
lemma smul_right (a : R) (x y : M) : B x (a • y) = a * (B x y) := bilin_smul_right B a x y
lemma zero_left (x : M) :
B 0 x = 0 := by {rw [←@zero_smul R _ _ _ _ (0 : M), smul_left, zero_mul]}
lemma zero_right (x : M) :
B x 0 = 0 := by rw [←@zero_smul _ _ _ _ _ (0 : M), smul_right, zero_mul]
lemma neg_left (x y : M) :
B (-x) y = -(B x y) := by rw [←@neg_one_smul R _ _, smul_left, neg_one_mul]
lemma neg_right (x y : M) :
B x (-y) = -(B x y) := by rw [←@neg_one_smul R _ _, smul_right, neg_one_mul]
lemma sub_left (x y z : M) :
B (x - y) z = B x z - B y z := by rw [sub_eq_add_neg, add_left, neg_left]; refl
lemma sub_right (x y z : M) :
B x (y - z) = B x y - B x z := by rw [sub_eq_add_neg, add_right, neg_right]; refl
variable {D : bilin_form R M}
@[ext] lemma ext (H : ∀ (x y : M), B x y = D x y) : B = D := by {cases B, cases D, congr, funext, exact H _ _}
instance : add_comm_group (bilin_form R M) :=
{ add := λ B D, { bilin := λ x y, B x y + D x y,
bilin_add_left := λ x y z, by {rw add_left, rw add_left, ac_refl},
bilin_smul_left := λ a x y, by {rw [smul_left, smul_left, mul_add]},
bilin_add_right := λ x y z, by {rw add_right, rw add_right, ac_refl},
bilin_smul_right := λ a x y, by {rw [smul_right, smul_right, mul_add]} },
add_assoc := by {intros, ext, unfold coe_fn has_coe_to_fun.coe bilin coe_fn has_coe_to_fun.coe bilin, rw add_assoc},
zero := { bilin := λ x y, 0,
bilin_add_left := λ x y z, (add_zero 0).symm,
bilin_smul_left := λ a x y, (mul_zero a).symm,
bilin_add_right := λ x y z, (zero_add 0).symm,
bilin_smul_right := λ a x y, (mul_zero a).symm },
zero_add := by {intros, ext, unfold coe_fn has_coe_to_fun.coe bilin, rw zero_add},
add_zero := by {intros, ext, unfold coe_fn has_coe_to_fun.coe bilin, rw add_zero},
neg := λ B, { bilin := λ x y, - (B.1 x y),
bilin_add_left := λ x y z, by rw [bilin_add_left, neg_add],
bilin_smul_left := λ a x y, by rw [bilin_smul_left, mul_neg_eq_neg_mul_symm],
bilin_add_right := λ x y z, by rw [bilin_add_right, neg_add],
bilin_smul_right := λ a x y, by rw [bilin_smul_right, mul_neg_eq_neg_mul_symm] },
add_left_neg := by {intros, ext, unfold coe_fn has_coe_to_fun.coe bilin, rw neg_add_self},
add_comm := by {intros, ext, unfold coe_fn has_coe_to_fun.coe bilin, rw add_comm} }
lemma add_apply (x y : M) : (B + D) x y = B x y + D x y := rfl
lemma neg_apply (x y : M) : (-B) x y = -(B x y) := rfl
instance : inhabited (bilin_form R M) := ⟨0⟩
section
variables {R₂ : Type*} [comm_ring R₂] [module R₂ M] (F : bilin_form R₂ M) (f : M → M)
instance to_module : module R₂ (bilin_form R₂ M) :=
{ smul := λ c B,
{ bilin := λ x y, c * B x y,
bilin_add_left := λ x y z,
by {unfold coe_fn has_coe_to_fun.coe bilin, rw [bilin_add_left, left_distrib]},
bilin_smul_left := λ a x y, by {unfold coe_fn has_coe_to_fun.coe bilin,
rw [bilin_smul_left, ←mul_assoc, mul_comm c, mul_assoc]},
bilin_add_right := λ x y z, by {unfold coe_fn has_coe_to_fun.coe bilin,
rw [bilin_add_right, left_distrib]},
bilin_smul_right := λ a x y, by {unfold coe_fn has_coe_to_fun.coe bilin,
rw [bilin_smul_right, ←mul_assoc, mul_comm c, mul_assoc]} },
smul_add := λ c B D, by {ext, unfold coe_fn has_coe_to_fun.coe bilin, rw left_distrib},
add_smul := λ c B D, by {ext, unfold coe_fn has_coe_to_fun.coe bilin, rw right_distrib},
mul_smul := λ a c D, by {ext, unfold coe_fn has_coe_to_fun.coe bilin, rw mul_assoc},
one_smul := λ B, by {ext, unfold coe_fn has_coe_to_fun.coe bilin, rw one_mul},
zero_smul := λ B, by {ext, unfold coe_fn has_coe_to_fun.coe bilin, rw zero_mul},
smul_zero := λ B, by {ext, unfold coe_fn has_coe_to_fun.coe bilin, rw mul_zero} }
lemma smul_apply (a : R₂) (x y : M) : (a • F) x y = a • (F x y) := rfl
/-- `B.to_linear_map` applies B on the left argument, then the right. -/
def to_linear_map : M →ₗ[R₂] M →ₗ[R₂] R₂ :=
linear_map.mk₂ R₂ F.1 (bilin_add_left F) (bilin_smul_left F) (bilin_add_right F) (bilin_smul_right F)
/-- Bilinear forms are equivalent to maps with two arguments that is linear in both. -/
def bilin_linear_map_equiv : (bilin_form R₂ M) ≃ₗ[R₂] (M →ₗ[R₂] M →ₗ[R₂] R₂) :=
{ to_fun := to_linear_map,
map_add' := λ B D, rfl,
map_smul' := λ a B, rfl,
inv_fun := linear_map.to_bilin,
left_inv := λ B, by {ext, refl},
right_inv := λ B, by {ext, refl} }
@[norm_cast]
lemma coe_fn_to_linear_map (x : M) : ⇑(F.to_linear_map x) = F x := rfl
lemma map_sum_left {α} (B : bilin_form R₂ M) (t : finset α) (g : α → M) (w : M) :
B (∑ i in t, g i) w = ∑ i in t, B (g i) w :=
show B.to_linear_map (∑ i in t, g i) w = ∑ i in t, B.to_linear_map (g i) w,
by rw [B.to_linear_map.map_sum, linear_map.coe_fn_sum, finset.sum_apply]
lemma map_sum_right {α} (B : bilin_form R₂ M) (t : finset α) (g : α → M) (v : M) :
B v (∑ i in t, g i) = ∑ i in t, B v (g i) :=
(B.to_linear_map v).map_sum
end
section comp
variables {N : Type w} [add_comm_group N] [module R N]
/-- Apply a linear map on the left and right argument of a bilinear form. -/
def comp (B : bilin_form R N) (l r : M →ₗ[R] N) : bilin_form R M :=
{ bilin := λ x y, B (l x) (r y),
bilin_add_left := λ x y z, by simp [add_left],
bilin_smul_left := λ x y z, by simp [smul_left],
bilin_add_right := λ x y z, by simp [add_right],
bilin_smul_right := λ x y z, by simp [smul_right] }
/-- Apply a linear map to the left argument of a bilinear form. -/
def comp_left (B : bilin_form R M) (f : M →ₗ[R] M) : bilin_form R M :=
B.comp f linear_map.id
/-- Apply a linear map to the right argument of a bilinear form. -/
def comp_right (B : bilin_form R M) (f : M →ₗ[R] M) : bilin_form R M :=
B.comp linear_map.id f
@[simp] lemma comp_left_comp_right (B : bilin_form R M) (l r : M →ₗ[R] M) :
(B.comp_left l).comp_right r = B.comp l r := rfl
@[simp] lemma comp_right_comp_left (B : bilin_form R M) (l r : M →ₗ[R] M) :
(B.comp_right r).comp_left l = B.comp l r := rfl
@[simp] lemma comp_apply (B : bilin_form R N) (l r : M →ₗ[R] N) (v w) :
B.comp l r v w = B (l v) (r w) := rfl
@[simp] lemma comp_left_apply (B : bilin_form R M) (f : M →ₗ[R] M) (v w) :
B.comp_left f v w = B (f v) w := rfl
@[simp] lemma comp_right_apply (B : bilin_form R M) (f : M →ₗ[R] M) (v w) :
B.comp_right f v w = B v (f w) := rfl
lemma comp_injective (B₁ B₂ : bilin_form R N) (l r : M →ₗ[R] N)
(hₗ : function.surjective l) (hᵣ : function.surjective r) :
B₁.comp l r = B₂.comp l r ↔ B₁ = B₂ :=
begin
split; intros h,
{ -- B₁.comp l r = B₂.comp l r → B₁ = B₂
ext,
cases hₗ x with x' hx, subst hx,
cases hᵣ y with y' hy, subst hy,
rw [←comp_apply, ←comp_apply, h], },
{ -- B₁ = B₂ → B₁.comp l r = B₂.comp l r
subst h, },
end
end comp
section lin_mul_lin
variables {R₂ : Type*} [comm_ring R₂] [module R₂ M] {N : Type w} [add_comm_group N] [module R₂ N]
/-- `lin_mul_lin f g` is the bilinear form mapping `x` and `y` to `f x * g y` -/
def lin_mul_lin (f g : M →ₗ[R₂] R₂) : bilin_form R₂ M :=
{ bilin := λ x y, f x * g y,
bilin_add_left := λ x y z, by simp [add_mul],
bilin_smul_left := λ x y z, by simp [mul_assoc],
bilin_add_right := λ x y z, by simp [mul_add],
bilin_smul_right := λ x y z, by simp [mul_left_comm] }
variables {f g : M →ₗ[R₂] R₂}
@[simp] lemma lin_mul_lin_apply (x y) : lin_mul_lin f g x y = f x * g y := rfl
@[simp] lemma lin_mul_lin_comp (l r : N →ₗ[R₂] M) :
(lin_mul_lin f g).comp l r = lin_mul_lin (f.comp l) (g.comp r) :=
rfl
@[simp] lemma lin_mul_lin_comp_left (l : M →ₗ[R₂] M) :
(lin_mul_lin f g).comp_left l = lin_mul_lin (f.comp l) g :=
rfl
@[simp] lemma lin_mul_lin_comp_right (r : M →ₗ[R₂] M) :
(lin_mul_lin f g).comp_right r = lin_mul_lin f (g.comp r) :=
rfl
end lin_mul_lin
/-- The proposition that two elements of a bilinear form space are orthogonal -/
def is_ortho (B : bilin_form R M) (x y : M) : Prop :=
B x y = 0
lemma ortho_zero (x : M) :
is_ortho B (0 : M) x := zero_left x
section
variables {R₃ : Type*} [domain R₃] [module R₃ M] {G : bilin_form R₃ M}
theorem ortho_smul_left {x y : M} {a : R₃} (ha : a ≠ 0) :
(is_ortho G x y) ↔ (is_ortho G (a • x) y) :=
begin
dunfold is_ortho,
split; intro H,
{ rw [smul_left, H, mul_zero] },
{ rw [smul_left, mul_eq_zero] at H,
cases H,
{ trivial },
{ exact H }}
end
theorem ortho_smul_right {x y : M} {a : R₃} (ha : a ≠ 0) :
(is_ortho G x y) ↔ (is_ortho G x (a • y)) :=
begin
dunfold is_ortho,
split; intro H,
{ rw [smul_right, H, mul_zero] },
{ rw [smul_right, mul_eq_zero] at H,
cases H,
{ trivial },
{ exact H }}
end
end
end bilin_form
section matrix
variables {R : Type u} [comm_ring R]
variables {n o : Type*} [fintype n] [fintype o]
open bilin_form finset matrix
open_locale matrix
/-- The linear map from `matrix n n R` to bilinear forms on `n → R`. -/
def matrix.to_bilin_formₗ : matrix n n R →ₗ[R] bilin_form R (n → R) :=
{ to_fun := λ M,
{ bilin := λ v w, (row v ⬝ M ⬝ col w) ⟨⟩ ⟨⟩,
bilin_add_left := λ x y z, by simp [matrix.add_mul],
bilin_smul_left := λ a x y, by simp,
bilin_add_right := λ x y z, by simp [matrix.mul_add],
bilin_smul_right := λ a x y, by simp },
map_add' := λ f g, by { ext, simp [bilin_form.add_apply, matrix.mul_add, matrix.add_mul] },
map_smul' := λ f g, by { ext, simp [bilin_form.smul_apply] } }
/-- The map from `matrix n n R` to bilinear forms on `n → R`. -/
def matrix.to_bilin_form : matrix n n R → bilin_form R (n → R) :=
matrix.to_bilin_formₗ.to_fun
lemma matrix.to_bilin_form_apply (M : matrix n n R) (v w : n → R) :
(M.to_bilin_form : (n → R) → (n → R) → R) v w = (row v ⬝ M ⬝ col w) ⟨⟩ ⟨⟩ := rfl
variables [decidable_eq n] [decidable_eq o]
/-- The linear map from bilinear forms on `n → R` to `matrix n n R`. -/
def bilin_form.to_matrixₗ : bilin_form R (n → R) →ₗ[R] matrix n n R :=
{ to_fun := λ B i j, B (λ n, if n = i then 1 else 0) (λ n, if n = j then 1 else 0),
map_add' := λ f g, rfl,
map_smul' := λ f g, rfl }
/-- The map from bilinear forms on `n → R` to `matrix n n R`. -/
def bilin_form.to_matrix : bilin_form R (n → R) → matrix n n R :=
bilin_form.to_matrixₗ.to_fun
lemma bilin_form.to_matrix_apply (B : bilin_form R (n → R)) (i j : n) :
B.to_matrix i j = B (λ n, if n = i then 1 else 0) (λ n, if n = j then 1 else 0) := rfl
lemma bilin_form.to_matrix_smul (B : bilin_form R (n → R)) (x : R) :
(x • B).to_matrix = x • B.to_matrix :=
by { ext, refl }
open bilin_form
lemma bilin_form.to_matrix_comp (B : bilin_form R (n → R)) (l r : (o → R) →ₗ[R] (n → R)) :
(B.comp l r).to_matrix = l.to_matrixᵀ ⬝ B.to_matrix ⬝ r.to_matrix :=
begin
ext i j,
simp only [to_matrix_apply, comp_apply, mul_apply, sum_mul],
have sum_smul_eq : Π (f : (o → R) →ₗ[R] (n → R)) (i : o),
f (λ n, ite (n = i) 1 0) = ∑ k, f.to_matrix k i • λ n, ite (n = k) (1 : R) 0,
{ intros f i,
ext j,
change f (λ n, ite (n = i) 1 0) j = (∑ k, λ n, f.to_matrix k i * ite (n = k) (1 : R) 0) j,
simp [linear_map.to_matrix, linear_map.to_matrixₗ, eq_comm] },
simp_rw [sum_smul_eq, map_sum_right, map_sum_left, smul_right, mul_comm, smul_left],
refl
end
lemma bilin_form.to_matrix_comp_left (B : bilin_form R (n → R)) (f : (n → R) →ₗ[R] (n → R)) :
(B.comp_left f).to_matrix = f.to_matrixᵀ ⬝ B.to_matrix :=
by simp [comp_left, bilin_form.to_matrix_comp]
lemma bilin_form.to_matrix_comp_right (B : bilin_form R (n → R)) (f : (n → R) →ₗ[R] (n → R)) :
(B.comp_right f).to_matrix = B.to_matrix ⬝ f.to_matrix :=
by simp [comp_right, bilin_form.to_matrix_comp]
lemma bilin_form.mul_to_matrix_mul (B : bilin_form R (n → R)) (M : matrix o n R) (N : matrix n o R) :
M ⬝ B.to_matrix ⬝ N = (B.comp (Mᵀ.to_lin) (N.to_lin)).to_matrix :=
by { ext, simp [B.to_matrix_comp (Mᵀ.to_lin) (N.to_lin), to_lin_to_matrix] }
lemma bilin_form.mul_to_matrix (B : bilin_form R (n → R)) (M : matrix n n R) :
M ⬝ B.to_matrix = (B.comp_left (Mᵀ.to_lin)).to_matrix :=
by { ext, simp [B.to_matrix_comp_left (Mᵀ.to_lin), to_lin_to_matrix] }
lemma bilin_form.to_matrix_mul (B : bilin_form R (n → R)) (M : matrix n n R) :
B.to_matrix ⬝ M = (B.comp_right (M.to_lin)).to_matrix :=
by { ext, simp [B.to_matrix_comp_right (M.to_lin), to_lin_to_matrix] }
@[simp] lemma to_matrix_to_bilin_form (B : bilin_form R (n → R)) :
B.to_matrix.to_bilin_form = B :=
begin
ext,
rw [matrix.to_bilin_form_apply, B.mul_to_matrix_mul, bilin_form.to_matrix_apply, comp_apply],
{ apply coe_fn_congr; ext; simp [mul_vec], },
{ apply_instance, },
end
@[simp] lemma to_bilin_form_to_matrix (M : matrix n n R) :
M.to_bilin_form.to_matrix = M :=
by { ext, simp [bilin_form.to_matrix_apply, matrix.to_bilin_form_apply, mul_apply], }
/-- Bilinear forms are linearly equivalent to matrices. -/
def bilin_form_equiv_matrix : bilin_form R (n → R) ≃ₗ[R] matrix n n R :=
{ inv_fun := matrix.to_bilin_form,
left_inv := to_matrix_to_bilin_form,
right_inv := to_bilin_form_to_matrix,
..bilin_form.to_matrixₗ }
lemma matrix.to_bilin_form_comp {n o : Type w} [fintype n] [fintype o]
(M : matrix n n R) (P Q : matrix n o R) :
M.to_bilin_form.comp P.to_lin Q.to_lin = (Pᵀ ⬝ M ⬝ Q).to_bilin_form :=
by { classical, rw [←to_matrix_to_bilin_form (Pᵀ ⬝ M ⬝ Q).to_bilin_form,
←to_matrix_to_bilin_form (M.to_bilin_form.comp P.to_lin Q.to_lin), bilin_form.to_matrix_comp,
to_bilin_form_to_matrix, to_bilin_form_to_matrix, to_lin_to_matrix, to_lin_to_matrix], }
end matrix
namespace refl_bilin_form
open refl_bilin_form bilin_form
variables {R : Type*} {M : Type*} [ring R] [add_comm_group M] [module R M] {B : bilin_form R M}
/-- The proposition that a bilinear form is reflexive -/
def is_refl (B : bilin_form R M) : Prop := ∀ (x y : M), B x y = 0 → B y x = 0
variable (H : is_refl B)
lemma eq_zero : ∀ {x y : M}, B x y = 0 → B y x = 0 := λ x y, H x y
lemma ortho_sym {x y : M} :
is_ortho B x y ↔ is_ortho B y x := ⟨eq_zero H, eq_zero H⟩
end refl_bilin_form
namespace sym_bilin_form
open sym_bilin_form bilin_form
variables {R : Type*} {M : Type*} [ring R] [add_comm_group M] [module R M] {B : bilin_form R M}
/-- The proposition that a bilinear form is symmetric -/
def is_sym (B : bilin_form R M) : Prop := ∀ (x y : M), B x y = B y x
variable (H : is_sym B)
lemma sym (x y : M) : B x y = B y x := H x y
lemma is_refl : refl_bilin_form.is_refl B := λ x y H1, H x y ▸ H1
lemma ortho_sym {x y : M} :
is_ortho B x y ↔ is_ortho B y x := refl_bilin_form.ortho_sym (is_refl H)
end sym_bilin_form
namespace alt_bilin_form
open alt_bilin_form bilin_form
variables {R : Type*} {M : Type*} [ring R] [add_comm_group M] [module R M] {B : bilin_form R M}
/-- The proposition that a bilinear form is alternating -/
def is_alt (B : bilin_form R M) : Prop := ∀ (x : M), B x x = 0
variable (H : is_alt B)
include H
lemma self_eq_zero (x : M) : B x x = 0 := H x
lemma neg (x y : M) :
- B x y = B y x :=
begin
have H1 : B (x + y) (x + y) = 0,
{ exact self_eq_zero H (x + y) },
rw [add_left, add_right, add_right,
self_eq_zero H, self_eq_zero H, ring.zero_add,
ring.add_zero, add_eq_zero_iff_neg_eq] at H1,
exact H1,
end
end alt_bilin_form
namespace bilin_form
section linear_adjoints
variables {R : Type u} [comm_ring R]
variables {M : Type v} [add_comm_group M] [module R M]
variables {M₂ : Type w} [add_comm_group M₂] [module R M₂]
variables (B B' : bilin_form R M) (B₂ : bilin_form R M₂)
variables (f f' : M →ₗ[R] M₂) (g g' : M₂ →ₗ[R] M)
/-- Given a pair of modules equipped with bilinear forms, this is the condition for a pair of
maps between them to be mutually adjoint. -/
def is_adjoint_pair := ∀ ⦃x y⦄, B₂ (f x) y = B x (g y)
variables {B B' B₂ f f' g g'}
lemma is_adjoint_pair.eq (h : is_adjoint_pair B B₂ f g) :
∀ {x y}, B₂ (f x) y = B x (g y) := h
lemma is_adjoint_pair_iff_comp_left_eq_comp_right (f g : module.End R M) :
is_adjoint_pair B B' f g ↔ B'.comp_left f = B.comp_right g :=
begin
split; intros h,
{ ext x y, rw [comp_left_apply, comp_right_apply], apply h, },
{ intros x y, rw [←comp_left_apply, ←comp_right_apply], rw h, },
end
lemma is_adjoint_pair_zero : is_adjoint_pair B B₂ 0 0 :=
λ x y, by simp only [bilin_form.zero_left, bilin_form.zero_right, linear_map.zero_apply]
lemma is_adjoint_pair_id : is_adjoint_pair B B 1 1 := λ x y, rfl
lemma is_adjoint_pair.add (h : is_adjoint_pair B B₂ f g) (h' : is_adjoint_pair B B₂ f' g') :
is_adjoint_pair B B₂ (f + f') (g + g') :=
λ x y, by rw [linear_map.add_apply, linear_map.add_apply, add_left, add_right, h, h']
lemma is_adjoint_pair.sub (h : is_adjoint_pair B B₂ f g) (h' : is_adjoint_pair B B₂ f' g') :
is_adjoint_pair B B₂ (f - f') (g - g') :=
λ x y, by rw [linear_map.sub_apply, linear_map.sub_apply, sub_left, sub_right, h, h']
lemma is_adjoint_pair.smul (c : R) (h : is_adjoint_pair B B₂ f g) :
is_adjoint_pair B B₂ (c • f) (c • g) :=
λ x y, by rw [linear_map.smul_apply, linear_map.smul_apply, smul_left, smul_right, h]
lemma is_adjoint_pair.comp {M₃ : Type v} [add_comm_group M₃] [module R M₃] {B₃ : bilin_form R M₃}
{f' : M₂ →ₗ[R] M₃} {g' : M₃ →ₗ[R] M₂}
(h : is_adjoint_pair B B₂ f g) (h' : is_adjoint_pair B₂ B₃ f' g') :
is_adjoint_pair B B₃ (f'.comp f) (g.comp g') :=
λ x y, by rw [linear_map.comp_apply, linear_map.comp_apply, h', h]
lemma is_adjoint_pair.mul
{f g f' g' : module.End R M} (h : is_adjoint_pair B B f g) (h' : is_adjoint_pair B B f' g') :
is_adjoint_pair B B (f * f') (g' * g) :=
λ x y, by rw [linear_map.mul_app, linear_map.mul_app, h, h']
variables (B B' B₂)
/-- The condition for an endomorphism to be "self-adjoint" with respect to a pair of bilinear forms
on the underlying module. In the case that these two forms are identical, this is the usual concept
of self adjointness. In the case that one of the forms is the negation of the other, this is the
usual concept of skew adjointness. -/
def is_pair_self_adjoint (f : module.End R M) := is_adjoint_pair B B' f f
/-- The set of pair-self-adjoint endomorphisms are a submodule of the type of all endomorphisms. -/
def is_pair_self_adjoint_submodule : submodule R (module.End R M) :=
{ carrier := { f | is_pair_self_adjoint B B' f },
zero_mem' := is_adjoint_pair_zero,
add_mem' := λ f g hf hg, hf.add hg,
smul_mem' := λ c f h, h.smul c, }
@[simp] lemma mem_is_pair_self_adjoint_submodule (f : module.End R M) :
f ∈ is_pair_self_adjoint_submodule B B' ↔ is_pair_self_adjoint B B' f :=
by refl
lemma is_pair_self_adjoint_equiv (e : M₂ ≃ₗ[R] M) (f : module.End R M) :
is_pair_self_adjoint B B' f ↔
is_pair_self_adjoint (B.comp ↑e ↑e) (B'.comp ↑e ↑e) (e.symm.conj f) :=
begin
have hₗ : (B'.comp ↑e ↑e).comp_left (e.symm.conj f) = (B'.comp_left f).comp ↑e ↑e :=
by { ext, simp [linear_equiv.symm_conj_apply], },
have hᵣ : (B.comp ↑e ↑e).comp_right (e.symm.conj f) = (B.comp_right f).comp ↑e ↑e :=
by { ext, simp [linear_equiv.conj_apply], },
have he : function.surjective (⇑(↑e : M₂ →ₗ[R] M) : M₂ → M) := e.surjective,
show bilin_form.is_adjoint_pair _ _ _ _ ↔ bilin_form.is_adjoint_pair _ _ _ _,
rw [is_adjoint_pair_iff_comp_left_eq_comp_right, is_adjoint_pair_iff_comp_left_eq_comp_right,
hᵣ, hₗ, comp_injective _ _ ↑e ↑e he he],
end
/-- An endomorphism of a module is self-adjoint with respect to a bilinear form if it serves as an
adjoint for itself. -/
def is_self_adjoint (f : module.End R M) := is_adjoint_pair B B f f
/-- An endomorphism of a module is skew-adjoint with respect to a bilinear form if its negation
serves as an adjoint. -/
def is_skew_adjoint (f : module.End R M) := is_adjoint_pair B B f (-f)
lemma is_skew_adjoint_iff_neg_self_adjoint (f : module.End R M) :
B.is_skew_adjoint f ↔ is_adjoint_pair (-B) B f f :=
show (∀ x y, B (f x) y = B x ((-f) y)) ↔ ∀ x y, B (f x) y = (-B) x (f y),
by simp only [linear_map.neg_apply, bilin_form.neg_apply, bilin_form.neg_right]
/-- The set of self-adjoint endomorphisms of a module with bilinear form is a submodule. (In fact
it is a Jordan subalgebra.) -/
def self_adjoint_submodule := is_pair_self_adjoint_submodule B B
@[simp] lemma mem_self_adjoint_submodule (f : module.End R M) :
f ∈ B.self_adjoint_submodule ↔ B.is_self_adjoint f := iff.rfl
/-- The set of skew-adjoint endomorphisms of a module with bilinear form is a submodule. (In fact
it is a Lie subalgebra.) -/
def skew_adjoint_submodule := is_pair_self_adjoint_submodule (-B) B
@[simp] lemma mem_skew_adjoint_submodule (f : module.End R M) :
f ∈ B.skew_adjoint_submodule ↔ B.is_skew_adjoint f :=
by { rw is_skew_adjoint_iff_neg_self_adjoint, exact iff.rfl, }
end linear_adjoints
end bilin_form
section matrix_adjoints
open_locale matrix
variables {R : Type u} [comm_ring R]
variables {n : Type w} [fintype n]
variables (J J₂ A B : matrix n n R)
/-- The condition for the square matrices `A`, `B` to be an adjoint pair with respect to the square
matrices `J`, `J₂`. -/
def matrix.is_adjoint_pair := Aᵀ ⬝ J₂ = J ⬝ B
/-- The condition for a square matrix `A` to be self-adjoint with respect to the square matrix
`J`. -/
def matrix.is_self_adjoint := matrix.is_adjoint_pair J J A A
/-- The condition for a square matrix `A` to be skew-adjoint with respect to the square matrix
`J`. -/
def matrix.is_skew_adjoint := matrix.is_adjoint_pair J J A (-A)
@[simp] lemma matrix_is_adjoint_pair_bilin_form :
bilin_form.is_adjoint_pair J.to_bilin_form J₂.to_bilin_form A.to_lin B.to_lin ↔
matrix.is_adjoint_pair J J₂ A B:=
begin
classical,
rw bilin_form.is_adjoint_pair_iff_comp_left_eq_comp_right,
have h : ∀ (B B' : bilin_form R (n → R)), B = B' ↔ B.to_matrix = B'.to_matrix := λ B B', by {
split; intros h, { rw h, }, { rw [←to_matrix_to_bilin_form B, h, to_matrix_to_bilin_form B'], }, },
rw [h, J₂.to_bilin_form.to_matrix_comp_left A.to_lin, J.to_bilin_form.to_matrix_comp_right B.to_lin,
to_lin_to_matrix, to_lin_to_matrix, to_bilin_form_to_matrix, to_bilin_form_to_matrix],
refl,
end
lemma matrix.is_adjoint_pair_equiv [decidable_eq n] (P : matrix n n R) (h : is_unit P) :
(Pᵀ ⬝ J ⬝ P).is_adjoint_pair (Pᵀ ⬝ J ⬝ P) A B ↔ J.is_adjoint_pair J (P ⬝ A ⬝ P⁻¹) (P ⬝ B ⬝ P⁻¹) :=
have h' : is_unit P.det := P.is_unit_iff_is_unit_det.mp h,
begin
let u := P.nonsing_inv_unit h',
let v := Pᵀ.nonsing_inv_unit (P.is_unit_det_transpose h'),
let x := Aᵀ * Pᵀ * J,
let y := J * P * B,
suffices : x * ↑u = ↑v * y ↔ ↑v⁻¹ * x = y * ↑u⁻¹,
{ dunfold matrix.is_adjoint_pair,
repeat { rw matrix.transpose_mul, },
simp only [←matrix.mul_eq_mul, ←mul_assoc, P.transpose_nonsing_inv h'],
conv_lhs { to_rhs, rw [mul_assoc, mul_assoc], congr, skip, rw ←mul_assoc, },
conv_rhs { rw [mul_assoc, mul_assoc], conv { to_lhs, congr, skip, rw ←mul_assoc }, },
exact this, },
rw units.eq_mul_inv_iff_mul_eq, conv_rhs { rw mul_assoc, }, rw v.inv_mul_eq_iff_eq_mul,
end
variables [decidable_eq n]
/-- The submodule of pair-self-adjoint matrices with respect to bilinear forms corresponding to
given matrices `J`, `J₂`. -/
def pair_self_adjoint_matrices_submodule : submodule R (matrix n n R) :=
(bilin_form.is_pair_self_adjoint_submodule J.to_bilin_form J₂.to_bilin_form).map
(@linear_equiv_matrix' n n _ _ R _ _)
@[simp] lemma mem_pair_self_adjoint_matrices_submodule :
A ∈ (pair_self_adjoint_matrices_submodule J J₂) ↔ matrix.is_adjoint_pair J J₂ A A :=
begin
simp only [pair_self_adjoint_matrices_submodule,linear_equiv.coe_coe, linear_equiv_matrix'_apply,
submodule.mem_map, bilin_form.mem_is_pair_self_adjoint_submodule],
split,
{ rintros ⟨f, hf, hA⟩, have hf' : f = A.to_lin := by rw [←hA, to_matrix_to_lin], rw hf' at hf,
rw ←matrix_is_adjoint_pair_bilin_form, exact hf, },
{ intros h, refine ⟨A.to_lin, _, to_lin_to_matrix⟩,
exact (matrix_is_adjoint_pair_bilin_form _ _ _ _).mpr h, },
end
/-- The submodule of self-adjoint matrices with respect to the bilinear form corresponding to
the matrix `J`. -/
def self_adjoint_matrices_submodule : submodule R (matrix n n R) :=
pair_self_adjoint_matrices_submodule J J
@[simp] lemma mem_self_adjoint_matrices_submodule :
A ∈ self_adjoint_matrices_submodule J ↔ J.is_self_adjoint A :=
by { erw mem_pair_self_adjoint_matrices_submodule, refl, }
/-- The submodule of skew-adjoint matrices with respect to the bilinear form corresponding to
the matrix `J`. -/
def skew_adjoint_matrices_submodule : submodule R (matrix n n R) :=
pair_self_adjoint_matrices_submodule (-J) J
@[simp] lemma mem_skew_adjoint_matrices_submodule :
A ∈ skew_adjoint_matrices_submodule J ↔ J.is_skew_adjoint A :=
begin
erw mem_pair_self_adjoint_matrices_submodule,
simp [matrix.is_skew_adjoint, matrix.is_adjoint_pair],
end
end matrix_adjoints
|
64d71a7b27aca2004d975888dcf5a86c31a38ae8 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/probability/process/adapted.lean | 21b1047306077e3fbf110f363fee518687eec05b | [
"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 | 8,930 | lean | /-
Copyright (c) 2021 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying, Rémy Degenne
-/
import probability.process.filtration
import topology.instances.discrete
/-!
# Adapted and progressively measurable processes
This file defines some standard definition from the theory of stochastic processes including
filtrations and stopping times. These definitions are used to model the amount of information
at a specific time and are the first step in formalizing stochastic processes.
## Main definitions
* `measure_theory.adapted`: a sequence of functions `u` is said to be adapted to a
filtration `f` if at each point in time `i`, `u i` is `f i`-strongly measurable
* `measure_theory.prog_measurable`: a sequence of functions `u` is said to be progressively
measurable with respect to a filtration `f` if at each point in time `i`, `u` restricted to
`set.Iic i × Ω` is strongly measurable with respect to the product `measurable_space` structure
where the σ-algebra used for `Ω` is `f i`.
## Main results
* `adapted.prog_measurable_of_continuous`: a continuous adapted process is progressively measurable.
## Tags
adapted, progressively measurable
-/
open filter order topological_space
open_locale classical measure_theory nnreal ennreal topological_space big_operators
namespace measure_theory
variables {Ω β ι : Type*} {m : measurable_space Ω} [topological_space β] [preorder ι]
{u v : ι → Ω → β} {f : filtration ι m}
/-- A sequence of functions `u` is adapted to a filtration `f` if for all `i`,
`u i` is `f i`-measurable. -/
def adapted (f : filtration ι m) (u : ι → Ω → β) : Prop :=
∀ i : ι, strongly_measurable[f i] (u i)
namespace adapted
@[protected, to_additive] lemma mul [has_mul β] [has_continuous_mul β]
(hu : adapted f u) (hv : adapted f v) :
adapted f (u * v) :=
λ i, (hu i).mul (hv i)
@[protected, to_additive] lemma div [has_div β] [has_continuous_div β]
(hu : adapted f u) (hv : adapted f v) :
adapted f (u / v) :=
λ i, (hu i).div (hv i)
@[protected, to_additive] lemma inv [group β] [topological_group β] (hu : adapted f u) :
adapted f u⁻¹ :=
λ i, (hu i).inv
@[protected] lemma smul [has_smul ℝ β] [has_continuous_smul ℝ β] (c : ℝ) (hu : adapted f u) :
adapted f (c • u) :=
λ i, (hu i).const_smul c
@[protected] lemma strongly_measurable {i : ι} (hf : adapted f u) :
strongly_measurable[m] (u i) :=
(hf i).mono (f.le i)
lemma strongly_measurable_le {i j : ι} (hf : adapted f u) (hij : i ≤ j) :
strongly_measurable[f j] (u i) :=
(hf i).mono (f.mono hij)
end adapted
lemma adapted_const (f : filtration ι m) (x : β) : adapted f (λ _ _, x) :=
λ i, strongly_measurable_const
variable (β)
lemma adapted_zero [has_zero β] (f : filtration ι m) : adapted f (0 : ι → Ω → β) :=
λ i, @strongly_measurable_zero Ω β (f i) _ _
variable {β}
lemma filtration.adapted_natural [metrizable_space β] [mβ : measurable_space β] [borel_space β]
{u : ι → Ω → β} (hum : ∀ i, strongly_measurable[m] (u i)) :
adapted (filtration.natural u hum) u :=
begin
assume i,
refine strongly_measurable.mono _ (le_supr₂_of_le i (le_refl i) le_rfl),
rw strongly_measurable_iff_measurable_separable,
exact ⟨measurable_iff_comap_le.2 le_rfl, (hum i).is_separable_range⟩
end
/-- Progressively measurable process. A sequence of functions `u` is said to be progressively
measurable with respect to a filtration `f` if at each point in time `i`, `u` restricted to
`set.Iic i × Ω` is measurable with respect to the product `measurable_space` structure where the
σ-algebra used for `Ω` is `f i`.
The usual definition uses the interval `[0,i]`, which we replace by `set.Iic i`. We recover the
usual definition for index types `ℝ≥0` or `ℕ`. -/
def prog_measurable [measurable_space ι] (f : filtration ι m) (u : ι → Ω → β) : Prop :=
∀ i, strongly_measurable[subtype.measurable_space.prod (f i)] (λ p : set.Iic i × Ω, u p.1 p.2)
lemma prog_measurable_const [measurable_space ι] (f : filtration ι m) (b : β) :
prog_measurable f ((λ _ _, b) : ι → Ω → β) :=
λ i, @strongly_measurable_const _ _ (subtype.measurable_space.prod (f i)) _ _
namespace prog_measurable
variables [measurable_space ι]
protected lemma adapted (h : prog_measurable f u) : adapted f u :=
begin
intro i,
have : u i = (λ p : set.Iic i × Ω, u p.1 p.2) ∘ (λ x, (⟨i, set.mem_Iic.mpr le_rfl⟩, x)) := rfl,
rw this,
exact (h i).comp_measurable measurable_prod_mk_left,
end
protected lemma comp {t : ι → Ω → ι} [topological_space ι] [borel_space ι] [metrizable_space ι]
(h : prog_measurable f u) (ht : prog_measurable f t)
(ht_le : ∀ i ω, t i ω ≤ i) :
prog_measurable f (λ i ω, u (t i ω) ω) :=
begin
intro i,
have : (λ p : ↥(set.Iic i) × Ω, u (t (p.fst : ι) p.snd) p.snd)
= (λ p : ↥(set.Iic i) × Ω, u (p.fst : ι) p.snd) ∘ (λ p : ↥(set.Iic i) × Ω,
(⟨t (p.fst : ι) p.snd, set.mem_Iic.mpr ((ht_le _ _).trans p.fst.prop)⟩, p.snd)) := rfl,
rw this,
exact (h i).comp_measurable ((ht i).measurable.subtype_mk.prod_mk measurable_snd),
end
section arithmetic
@[to_additive] protected lemma mul [has_mul β] [has_continuous_mul β]
(hu : prog_measurable f u) (hv : prog_measurable f v) :
prog_measurable f (λ i ω, u i ω * v i ω) :=
λ i, (hu i).mul (hv i)
@[to_additive] protected lemma finset_prod' {γ} [comm_monoid β] [has_continuous_mul β]
{U : γ → ι → Ω → β} {s : finset γ} (h : ∀ c ∈ s, prog_measurable f (U c)) :
prog_measurable f (∏ c in s, U c) :=
finset.prod_induction U (prog_measurable f) (λ _ _, prog_measurable.mul)
(prog_measurable_const _ 1) h
@[to_additive] protected lemma finset_prod {γ} [comm_monoid β] [has_continuous_mul β]
{U : γ → ι → Ω → β} {s : finset γ} (h : ∀ c ∈ s, prog_measurable f (U c)) :
prog_measurable f (λ i a, ∏ c in s, U c i a) :=
by { convert prog_measurable.finset_prod' h, ext i a, simp only [finset.prod_apply], }
@[to_additive] protected lemma inv [group β] [topological_group β] (hu : prog_measurable f u) :
prog_measurable f (λ i ω, (u i ω)⁻¹) :=
λ i, (hu i).inv
@[to_additive] protected lemma div [group β] [topological_group β]
(hu : prog_measurable f u) (hv : prog_measurable f v) :
prog_measurable f (λ i ω, u i ω / v i ω) :=
λ i, (hu i).div (hv i)
end arithmetic
end prog_measurable
lemma prog_measurable_of_tendsto' {γ} [measurable_space ι] [pseudo_metrizable_space β]
(fltr : filter γ) [fltr.ne_bot] [fltr.is_countably_generated] {U : γ → ι → Ω → β}
(h : ∀ l, prog_measurable f (U l)) (h_tendsto : tendsto U fltr (𝓝 u)) :
prog_measurable f u :=
begin
assume i,
apply @strongly_measurable_of_tendsto (set.Iic i × Ω) β γ (measurable_space.prod _ (f i))
_ _ fltr _ _ _ _ (λ l, h l i),
rw tendsto_pi_nhds at h_tendsto ⊢,
intro x,
specialize h_tendsto x.fst,
rw tendsto_nhds at h_tendsto ⊢,
exact λ s hs h_mem, h_tendsto {g | g x.snd ∈ s} (hs.preimage (continuous_apply x.snd)) h_mem,
end
lemma prog_measurable_of_tendsto [measurable_space ι] [pseudo_metrizable_space β]
{U : ℕ → ι → Ω → β}
(h : ∀ l, prog_measurable f (U l)) (h_tendsto : tendsto U at_top (𝓝 u)) :
prog_measurable f u :=
prog_measurable_of_tendsto' at_top h h_tendsto
/-- A continuous and adapted process is progressively measurable. -/
theorem adapted.prog_measurable_of_continuous
[topological_space ι] [metrizable_space ι] [second_countable_topology ι]
[measurable_space ι] [opens_measurable_space ι]
[pseudo_metrizable_space β]
(h : adapted f u) (hu_cont : ∀ ω, continuous (λ i, u i ω)) :
prog_measurable f u :=
λ i, @strongly_measurable_uncurry_of_continuous_of_strongly_measurable _ _ (set.Iic i) _ _ _ _ _ _ _
(f i) _ (λ ω, (hu_cont ω).comp continuous_induced_dom) (λ j, (h j).mono (f.mono j.prop))
/-- For filtrations indexed by a discrete order, `adapted` and `prog_measurable` are equivalent.
This lemma provides `adapted f u → prog_measurable f u`.
See `prog_measurable.adapted` for the reverse direction, which is true more generally. -/
lemma adapted.prog_measurable_of_discrete [topological_space ι] [discrete_topology ι]
[second_countable_topology ι] [measurable_space ι] [opens_measurable_space ι]
[pseudo_metrizable_space β]
(h : adapted f u) :
prog_measurable f u :=
h.prog_measurable_of_continuous (λ _, continuous_of_discrete_topology)
-- this dot notation will make more sense once we have a more general definition for predictable
lemma predictable.adapted {f : filtration ℕ m} {u : ℕ → Ω → β}
(hu : adapted f (λ n, u (n + 1))) (hu0 : strongly_measurable[f 0] (u 0)) :
adapted f u :=
λ n, match n with
| 0 := hu0
| n + 1 := (hu n).mono (f.mono n.le_succ)
end
end measure_theory
|
ce1d02526aa1e41a9df75bbdf361a79db38bd125 | 37da0369b6c03e380e057bf680d81e6c9fdf9219 | /hott/eq2.hlean | 8bbf07af56585ca23e2642ef5f7aac32c9a38f76 | [
"Apache-2.0"
] | permissive | kodyvajjha/lean2 | 72b120d95c3a1d77f54433fa90c9810e14a931a4 | 227fcad22ab2bc27bb7471be7911075d101ba3f9 | refs/heads/master | 1,627,157,512,295 | 1,501,855,676,000 | 1,504,809,427,000 | 109,317,326 | 0 | 0 | null | 1,509,839,253,000 | 1,509,655,713,000 | C++ | UTF-8 | Lean | false | false | 12,039 | hlean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Floris van Doorn
Theorems about 2-dimensional paths
-/
import .cubical.square .function
open function is_equiv equiv
namespace eq
variables {A B C : Type} {f : A → B} {a a' a₁ a₂ a₃ a₄ : A} {b b' : B}
theorem ap_is_constant_eq (p : Πx, f x = b) (q : a = a') :
ap_is_constant p q =
eq_con_inv_of_con_eq ((eq_of_square (square_of_pathover (apd p q)))⁻¹ ⬝
whisker_left (p a) (ap_constant q b)) :=
begin
induction q, esimp, generalize (p a), intro p, cases p, apply idpath idp
end
definition ap_inv2 {p q : a = a'} (r : p = q)
: square (ap (ap f) (inverse2 r))
(inverse2 (ap (ap f) r))
(ap_inv f p)
(ap_inv f q) :=
by induction r;exact hrfl
definition ap_con2 {p₁ q₁ : a₁ = a₂} {p₂ q₂ : a₂ = a₃} (r₁ : p₁ = q₁) (r₂ : p₂ = q₂)
: square (ap (ap f) (r₁ ◾ r₂))
(ap (ap f) r₁ ◾ ap (ap f) r₂)
(ap_con f p₁ p₂)
(ap_con f q₁ q₂) :=
by induction r₂;induction r₁;exact hrfl
theorem ap_con_right_inv_sq {A B : Type} {a1 a2 : A} (f : A → B) (p : a1 = a2) :
square (ap (ap f) (con.right_inv p))
(con.right_inv (ap f p))
(ap_con f p p⁻¹ ⬝ whisker_left _ (ap_inv f p))
idp :=
by cases p;apply hrefl
theorem ap_con_left_inv_sq {A B : Type} {a1 a2 : A} (f : A → B) (p : a1 = a2) :
square (ap (ap f) (con.left_inv p))
(con.left_inv (ap f p))
(ap_con f p⁻¹ p ⬝ whisker_right _ (ap_inv f p))
idp :=
by cases p;apply vrefl
definition ap02_compose {A B C : Type} (g : B → C) (f : A → B) {a a' : A}
{p₁ p₂ : a = a'} (q : p₁ = p₂) :
square (ap_compose g f p₁) (ap_compose g f p₂) (ap02 (g ∘ f) q) (ap02 g (ap02 f q)) :=
by induction q; exact vrfl
definition ap02_id {A : Type} {a a' : A}
{p₁ p₂ : a = a'} (q : p₁ = p₂) :
square (ap_id p₁) (ap_id p₂) (ap02 id q) q :=
by induction q; exact vrfl
theorem ap_ap_is_constant {A B C : Type} (g : B → C) {f : A → B} {b : B}
(p : Πx, f x = b) {x y : A} (q : x = y) :
square (ap (ap g) (ap_is_constant p q))
(ap_is_constant (λa, ap g (p a)) q)
(ap_compose g f q)⁻¹
(!ap_con ⬝ whisker_left _ !ap_inv) :=
begin
induction q, esimp, generalize (p x), intro p, cases p, apply ids
-- induction q, rewrite [↑ap_compose,ap_inv], apply hinverse, apply ap_con_right_inv_sq,
end
theorem ap_ap_compose {A B C D : Type} (h : C → D) (g : B → C) (f : A → B)
{x y : A} (p : x = y) :
square (ap_compose (h ∘ g) f p)
(ap (ap h) (ap_compose g f p))
(ap_compose h (g ∘ f) p)
(ap_compose h g (ap f p)) :=
by induction p;exact ids
theorem ap_compose_inv {A B C : Type} (g : B → C) (f : A → B)
{x y : A} (p : x = y) :
square (ap_compose g f p⁻¹)
(inverse2 (ap_compose g f p) ⬝ (ap_inv g (ap f p))⁻¹)
(ap_inv (g ∘ f) p)
(ap (ap g) (ap_inv f p)) :=
by induction p;exact ids
theorem ap_compose_con (g : B → C) (f : A → B) (p : a₁ = a₂) (q : a₂ = a₃) :
square (ap_compose g f (p ⬝ q))
(ap_compose g f p ◾ ap_compose g f q ⬝ (ap_con g (ap f p) (ap f q))⁻¹)
(ap_con (g ∘ f) p q)
(ap (ap g) (ap_con f p q)) :=
by induction q;induction p;exact ids
theorem ap_compose_natural {A B C : Type} (g : B → C) (f : A → B)
{x y : A} {p q : x = y} (r : p = q) :
square (ap (ap (g ∘ f)) r)
(ap (ap g ∘ ap f) r)
(ap_compose g f p)
(ap_compose g f q) :=
natural_square_tr (ap_compose g f) r
theorem whisker_right_eq_of_con_inv_eq_idp {p q : a₁ = a₂} (r : p ⬝ q⁻¹ = idp) :
whisker_right q⁻¹ (eq_of_con_inv_eq_idp r) ⬝ con.right_inv q = r :=
by induction q; esimp at r; cases r; reflexivity
theorem ap_eq_of_con_inv_eq_idp (f : A → B) {p q : a₁ = a₂} (r : p ⬝ q⁻¹ = idp)
: ap02 f (eq_of_con_inv_eq_idp r) =
eq_of_con_inv_eq_idp (whisker_left _ !ap_inv⁻¹ ⬝ !ap_con⁻¹ ⬝ ap02 f r)
:=
by induction q;esimp at *;cases r;reflexivity
theorem eq_of_con_inv_eq_idp_con2 {p p' q q' : a₁ = a₂} (r : p = p') (s : q = q')
(t : p' ⬝ q'⁻¹ = idp)
: eq_of_con_inv_eq_idp (r ◾ inverse2 s ⬝ t) = r ⬝ eq_of_con_inv_eq_idp t ⬝ s⁻¹ :=
by induction s;induction r;induction q;reflexivity
definition naturality_apd_eq {A : Type} {B : A → Type} {a a₂ : A} {f g : Πa, B a}
(H : f ~ g) (p : a = a₂)
: apd f p = concato_eq (eq_concato (H a) (apd g p)) (H a₂)⁻¹ :=
begin
induction p, esimp,
generalizes [H a, g a], intro ga Ha, induction Ha,
reflexivity
end
theorem con_tr_idp {P : A → Type} {x y : A} (q : x = y) (u : P x) :
con_tr idp q u = ap (λp, p ▸ u) (idp_con q) :=
by induction q;reflexivity
definition eq_transport_Fl_idp_left {A B : Type} {a : A} {b : B} (f : A → B) (q : f a = b)
: eq_transport_Fl idp q = !idp_con⁻¹ :=
by induction q; reflexivity
definition whisker_left_idp_con_eq_assoc
{A : Type} {a₁ a₂ a₃ : A} (p : a₁ = a₂) (q : a₂ = a₃)
: whisker_left p (idp_con q)⁻¹ = con.assoc p idp q :=
by induction q; reflexivity
definition whisker_left_inverse2 {A : Type} {a : A} {p : a = a} (q : p = idp)
: whisker_left p q⁻² ⬝ q = con.right_inv p :=
by cases q; reflexivity
definition cast_fn_cast_square {A : Type} {B C : A → Type} (f : Π⦃a⦄, B a → C a) {a₁ a₂ : A}
(p : a₁ = a₂) (q : a₂ = a₁) (r : p ⬝ q = idp) (b : B a₁) :
cast (ap C q) (f (cast (ap B p) b)) = f b :=
have q⁻¹ = p, from inv_eq_of_idp_eq_con r⁻¹,
begin induction this, induction q, reflexivity end
definition ap011_ap_square_right {A B C : Type} (f : A → B → C) {a a' : A} (p : a = a')
{b₁ b₂ b₃ : B} {q₁₂ : b₁ = b₂} {q₂₃ : b₂ = b₃} {q₁₃ : b₁ = b₃} (r : q₁₂ ⬝ q₂₃ = q₁₃) :
square (ap011 f p q₁₂) (ap (λx, f x b₃) p) (ap (f a) q₁₃) (ap (f a') q₂₃) :=
by induction r; induction q₂₃; induction q₁₂; induction p; exact ids
definition ap011_ap_square_left {A B C : Type} (f : B → A → C) {a a' : A} (p : a = a')
{b₁ b₂ b₃ : B} {q₁₂ : b₁ = b₂} {q₂₃ : b₂ = b₃} {q₁₃ : b₁ = b₃} (r : q₁₂ ⬝ q₂₃ = q₁₃) :
square (ap011 f q₁₂ p) (ap (f b₃) p) (ap (λx, f x a) q₁₃) (ap (λx, f x a') q₂₃) :=
by induction r; induction q₂₃; induction q₁₂; induction p; exact ids
definition con2_assoc {A : Type} {x y z t : A} {p p' : x = y} {q q' : y = z} {r r' : z = t}
(h : p = p') (h' : q = q') (h'' : r = r') :
square ((h ◾ h') ◾ h'') (h ◾ (h' ◾ h'')) (con.assoc p q r) (con.assoc p' q' r') :=
by induction h; induction h'; induction h''; exact hrfl
definition con_left_inv_idp {A : Type} {x : A} {p : x = x} (q : p = idp)
: con.left_inv p = q⁻² ◾ q :=
by cases q; reflexivity
definition eckmann_hilton_con2 {A : Type} {x : A} {p p' q q': idp = idp :> x = x}
(h : p = p') (h' : q = q') : square (h ◾ h') (h' ◾ h) (eckmann_hilton p q) (eckmann_hilton p' q') :=
by induction h; induction h'; exact hrfl
definition ap_con_fn {A B : Type} {a a' : A} {b : B} (g h : A → b = b) (p : a = a') :
ap (λa, g a ⬝ h a) p = ap g p ◾ ap h p :=
by induction p; reflexivity
definition ap_eq_ap011 {A B C X : Type} (f : A → B → C) (g : X → A) (h : X → B) {x x' : X}
(p : x = x') : ap (λx, f (g x) (h x)) p = ap011 f (ap g p) (ap h p) :=
by induction p; reflexivity
definition ap_is_weakly_constant {A B : Type} {f : A → B}
(h : is_weakly_constant f) {a a' : A} (p : a = a') : ap f p = (h a a)⁻¹ ⬝ h a a' :=
by induction p; exact !con.left_inv⁻¹
definition ap_is_constant_idp {A B : Type} {f : A → B} {b : B} (p : Πa, f a = b) {a : A} (q : a = a)
(r : q = idp) : ap_is_constant p q = ap02 f r ⬝ (con.right_inv (p a))⁻¹ :=
by cases r; exact !idp_con⁻¹
definition con_right_inv_natural {A : Type} {a a' : A} {p p' : a = a'} (q : p = p') :
con.right_inv p = q ◾ q⁻² ⬝ con.right_inv p' :=
by induction q; induction p; reflexivity
definition whisker_right_ap {A B : Type} {a a' : A}{b₁ b₂ b₃ : B} (q : b₂ = b₃) (f : A → b₁ = b₂)
(p : a = a') : whisker_right q (ap f p) = ap (λa, f a ⬝ q) p :=
by induction p; reflexivity
definition ap02_ap_constant {A B C : Type} {a a' : A} (f : B → C) (b : B) (p : a = a') :
square (ap_constant p (f b)) (ap02 f (ap_constant p b)) (ap_compose f (λx, b) p) idp :=
by induction p; exact ids
definition ap_constant_compose {A B C : Type} {a a' : A} (c : C) (f : A → B) (p : a = a') :
square (ap_constant p c) (ap_constant (ap f p) c) (ap_compose (λx, c) f p) idp :=
by induction p; exact ids
definition ap02_constant {A B : Type} {a a' : A} (b : B) {p p' : a = a'}
(q : p = p') : square (ap_constant p b) (ap_constant p' b) (ap02 (λx, b) q) idp :=
by induction q; exact vrfl
section hsquare
variables {A₀₀ A₂₀ A₄₀ A₀₂ A₂₂ A₄₂ A₀₄ A₂₄ A₄₄ : Type}
{f₁₀ : A₀₀ → A₂₀} {f₃₀ : A₂₀ → A₄₀}
{f₀₁ : A₀₀ → A₀₂} {f₂₁ : A₂₀ → A₂₂} {f₄₁ : A₄₀ → A₄₂}
{f₁₂ : A₀₂ → A₂₂} {f₃₂ : A₂₂ → A₄₂}
{f₀₃ : A₀₂ → A₀₄} {f₂₃ : A₂₂ → A₂₄} {f₄₃ : A₄₂ → A₄₄}
{f₁₄ : A₀₄ → A₂₄} {f₃₄ : A₂₄ → A₄₄}
definition hsquare [reducible] (f₁₀ : A₀₀ → A₂₀) (f₁₂ : A₀₂ → A₂₂)
(f₀₁ : A₀₀ → A₀₂) (f₂₁ : A₂₀ → A₂₂) : Type :=
f₂₁ ∘ f₁₀ ~ f₁₂ ∘ f₀₁
definition hsquare_of_homotopy (p : f₂₁ ∘ f₁₀ ~ f₁₂ ∘ f₀₁) : hsquare f₁₀ f₁₂ f₀₁ f₂₁ :=
p
definition homotopy_of_hsquare (p : hsquare f₁₀ f₁₂ f₀₁ f₂₁) : f₂₁ ∘ f₁₀ ~ f₁₂ ∘ f₀₁ :=
p
definition homotopy_top_of_hsquare {f₂₁ : A₂₀ ≃ A₂₂} (p : hsquare f₁₀ f₁₂ f₀₁ f₂₁) :
f₁₀ ~ f₂₁⁻¹ ∘ f₁₂ ∘ f₀₁ :=
homotopy_inv_of_homotopy_post _ _ _ p
definition homotopy_top_of_hsquare' [is_equiv f₂₁] (p : hsquare f₁₀ f₁₂ f₀₁ f₂₁) :
f₁₀ ~ f₂₁⁻¹ ∘ f₁₂ ∘ f₀₁ :=
homotopy_inv_of_homotopy_post _ _ _ p
definition hhconcat (p : hsquare f₁₀ f₁₂ f₀₁ f₂₁) (q : hsquare f₃₀ f₃₂ f₂₁ f₄₁) :
hsquare (f₃₀ ∘ f₁₀) (f₃₂ ∘ f₁₂) f₀₁ f₄₁ :=
hwhisker_right f₁₀ q ⬝hty hwhisker_left f₃₂ p
definition hvconcat (p : hsquare f₁₀ f₁₂ f₀₁ f₂₁) (q : hsquare f₁₂ f₁₄ f₀₃ f₂₃) :
hsquare f₁₀ f₁₄ (f₀₃ ∘ f₀₁) (f₂₃ ∘ f₂₁) :=
hwhisker_left f₂₃ p ⬝hty hwhisker_right f₀₁ q
definition hhinverse {f₁₀ : A₀₀ ≃ A₂₀} {f₁₂ : A₀₂ ≃ A₂₂} (p : hsquare f₁₀ f₁₂ f₀₁ f₂₁) :
hsquare f₁₀⁻¹ᵉ f₁₂⁻¹ᵉ f₂₁ f₀₁ :=
λb, eq_inv_of_eq ((p (f₁₀⁻¹ᵉ b))⁻¹ ⬝ ap f₂₁ (to_right_inv f₁₀ b))
definition hvinverse {f₀₁ : A₀₀ ≃ A₀₂} {f₂₁ : A₂₀ ≃ A₂₂} (p : hsquare f₁₀ f₁₂ f₀₁ f₂₁) :
hsquare f₁₂ f₁₀ f₀₁⁻¹ᵉ f₂₁⁻¹ᵉ :=
λa, inv_eq_of_eq (p (f₀₁⁻¹ᵉ a) ⬝ ap f₁₂ (to_right_inv f₀₁ a))⁻¹
infix ` ⬝htyh `:73 := hhconcat
infix ` ⬝htyv `:73 := hvconcat
postfix `⁻¹ʰᵗʸʰ`:(max+1) := hhinverse
postfix `⁻¹ʰᵗʸᵛ`:(max+1) := hvinverse
end hsquare
end eq
|
61cd32b6c66c814fe6546f563810411c3eaf9a02 | ab8267ccbb4efcc212537904eac8db218951dcf2 | /prenex.lean | f158c3c231465cc5e600cd2611db23e8b648b5d6 | [
"Apache-2.0"
] | permissive | minchaowu/auto- | 3b954c91de72b239884cc7d5e234dcd75ca0e1a2 | 7079dcad4e38b2addb8a1e01781547db67fd278e | refs/heads/master | 1,610,417,081,627 | 1,484,174,338,000 | 1,484,174,338,000 | 78,468,738 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,221 | lean | open classical tactic expr list
section prop_equivalence
local attribute [instance] prop_decidable
variables {a b : Prop}
theorem not_not_iff (a : Prop) : ¬¬a ↔ a :=
iff.intro classical.by_contradiction not_not_intro
theorem implies_iff_not_or (a b : Prop) : (a → b) ↔ (¬ a ∨ b) :=
iff.intro
(λ h, if ha : a then or.inr (h ha) else or.inl ha)
(λ h, or.elim h (λ hna ha, absurd ha hna) (λ hb ha, hb))
theorem not_and_of_not_or_not (h : ¬ a ∨ ¬ b) : ¬ (a ∧ b) :=
assume ⟨ha, hb⟩, or.elim h (assume hna, hna ha) (assume hnb, hnb hb)
theorem not_or_not_of_not_and (h : ¬ (a ∧ b)) : ¬ a ∨ ¬ b :=
if ha : a then
or.inr (show ¬ b, from assume hb, h ⟨ha, hb⟩)
else
or.inl ha
theorem not_and_iff (a b : Prop) : ¬ (a ∧ b) ↔ ¬a ∨ ¬b :=
iff.intro not_or_not_of_not_and not_and_of_not_or_not
theorem not_or_of_not_and_not (h : ¬ a ∧ ¬ b) : ¬ (a ∨ b) :=
assume h₁, or.elim h₁ (assume ha, h^.left ha) (assume hb, h^.right hb)
theorem not_and_not_of_not_or (h : ¬ (a ∨ b)) : ¬ a ∧ ¬ b :=
and.intro (assume ha, h (or.inl ha)) (assume hb, h (or.inr hb))
theorem not_or_iff (a b : Prop) : ¬ (a ∨ b) ↔ ¬ a ∧ ¬ b :=
iff.intro not_and_not_of_not_or not_or_of_not_and_not
theorem iff_eq (a b : Prop) : (a ↔ b) = ((a → b) ∧ (b → a)) := rfl
check and.comm
check or.comm
end prop_equivalence
section prenex_equivalence
variables {A : Type}
variables {p : Prop}
variables {q : A → Prop}
variable [inhabited A]
theorem forall_not_of_not_exists : (¬ ∃ x, q x) → ∀ x, ¬ q x :=
λ h x hqx, h (exists.intro x hqx)
theorem exists_not_of_not_forall : (¬ ∀ x, q x) → ∃ x, ¬ q x :=
λ h, by_contradiction
(λ neg, have ∀ x, ¬ ¬ q x, from forall_not_of_not_exists neg,
have ∀ x, q x, from λ x, iff.elim_left (not_not_iff (q x)) (this x),
show _, from h this)
theorem forall_p_iff_p : (∀ x : A, p) ↔ p :=
iff.intro (λ h, h (default A)) (λ h x, h)
theorem exists_p_iff_p : (∃ x : A, p) ↔ p :=
iff.intro (λ h, exists.elim h (λ x hx, hx)) (λ h, exists.intro (default A) h)
theorem forall_of_forall_and_left : (∀ x, q x) ∧ p ↔ ∀ x, q x ∧ p :=
iff.intro (λ h x, and.intro (h^.left x) h^.right)
(λ h, and.intro (λ x, (h x)^.left) (h (default A))^.right)
theorem forall_of_forall_and_right : p ∧ (∀ x, q x) ↔ ∀ x, q x ∧ p :=
iff.trans and.comm forall_of_forall_and_left
theorem forall_of_forall_or_left : (∀ x, q x) ∨ p ↔ ∀ x, q x ∨ p :=
iff.intro (λ h x, or.elim h (λ l, or.inl (l x)) (λ r, or.inr r))
(λ h, or.elim (em p) (λ l, or.inr l) (λ r, or.inl (λ x, or.resolve_right (h x) r)))
theorem forall_of_forall_or_right : p ∨ (∀ x, q x) ↔ ∀ x, q x ∨ p :=
iff.trans or.comm forall_of_forall_or_left
theorem exists_of_exists_and_left : (∃ x, q x) ∧ p ↔ ∃ x, q x ∧ p :=
iff.intro (λ h, exists.elim h^.left (λ x hx, exists.intro x (and.intro hx h^.right)) )
(λ h, exists.elim h (λ x hx, and.intro (exists.intro x hx^.left) hx^.right))
theorem exists_of_exists_and_right : p ∧ (∃ x, q x) ↔ ∃ x, q x ∧ p :=
iff.trans and.comm exists_of_exists_and_left
theorem exists_of_exists_or_left : (∃ x, q x) ∨ p ↔ ∃ x, q x ∨ p :=
iff.intro (λ h, or.elim h (λ l, exists.elim l (λ x hx, exists.intro x (or.inl hx)))
(λ r, exists.intro (default A) (or.inr r)))
(λ h, exists.elim h (λ x hx, or.elim hx (λ l, or.inl (exists.intro x l)) (λ r, or.inr r)))
theorem exists_of_exists_or_right : p ∨ (∃ x, q x) ↔ ∃ x, q x ∨ p :=
iff.trans or.comm exists_of_exists_or_left
end prenex_equivalence
meta def nnf_lemmas : list name := [``forall_not_of_not_exists, ``exists_not_of_not_forall,
``iff_eq, ``implies_iff_not_or, ``not_and_iff, ``not_or_iff,
``not_not_iff, ``not_true_iff, ``not_false_iff]
meta def normalize_hyp (lemmas : list expr) (hyp : expr) : tactic unit :=
do try (simp_at_using lemmas hyp)
meta def nnf_hyps : tactic unit :=
do hyps ← local_context,
lemmas ← monad.mapm mk_const nnf_lemmas,
monad.for' hyps (normalize_hyp lemmas)
meta def pnf_lemmas : list name := [``forall_p_iff_p, ``exists_p_iff_p, ``forall_of_forall_and_left,
``forall_of_forall_and_right, ``forall_of_forall_or_left,
``forall_of_forall_or_right, ``exists_of_exists_and_left,
``exists_of_exists_and_right, ``exists_of_exists_or_left, ``exists_of_exists_or_right]
meta def pnf_hyps : tactic unit :=
do hyps ← local_context,
pnf_lemmas ← monad.mapm mk_const pnf_lemmas,
monad.for' hyps (normalize_hyp pnf_lemmas)
example (p q r : Prop) (h₁ : ¬ (p ↔ (q ∧ ¬ r))) (h₂ : ¬ (p → (q → ¬ r))) : true :=
by do nnf_hyps,
trace_state,
triv
-- TODO: think about the order of applying simp rules.
example (A : Type) (p : Prop) (q : A → Prop) (h₁ : ¬ p → ((∀ x, q x) → p)) [inhabited A] : true :=
by do nnf_hyps,
trace_state,
pnf_hyps,
trace_state,
triv
print simplify
|
64a4d735b063ac3a0622aeb5c27f73e0102b3c21 | e00ea76a720126cf9f6d732ad6216b5b824d20a7 | /src/category_theory/isomorphism.lean | c4118397c81fe3a80d52a474beec006340767295 | [
"Apache-2.0"
] | permissive | vaibhavkarve/mathlib | a574aaf68c0a431a47fa82ce0637f0f769826bfe | 17f8340912468f49bdc30acdb9a9fa02eeb0473a | refs/heads/master | 1,621,263,802,637 | 1,585,399,588,000 | 1,585,399,588,000 | 250,833,447 | 0 | 0 | Apache-2.0 | 1,585,410,341,000 | 1,585,410,341,000 | null | UTF-8 | Lean | false | false | 10,624 | lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Tim Baumann, Stephen Morgan, Scott Morrison, Floris van Doorn
-/
import category_theory.functor
import tactic.reassoc_axiom
/-!
# Isomorphisms
This file defines isomorphisms between objects of a category.
## Main definitions
- `structure iso` : a bundled isomorphism between two objects of a category;
- `class is_iso` : an unbundled version of `iso`; note that `is_iso f` is usually *not* a `Prop`,
because it holds the inverse morphism;
- `as_iso` : convert from `is_iso` to `iso`;
- `of_iso` : convert from `iso` to `is_iso`;
- standard operations on isomorphisms (composition, inverse etc)
## Notations
- `X ≅ Y` : same as `iso X Y`;
- `α ≪≫ β` : composition of two isomorphisms; it is called `iso.trans`
## Tags
category, category theory, isomorphism
-/
universes v u -- declare the `v`'s first; see `category_theory.category` for an explanation
namespace category_theory
open category
/-- An isomorphism (a.k.a. an invertible morphism) between two objects of a category.
The inverse morphism is bundled.
See also `category_theory.core` for the category with the same objects and isomorphisms playing
the role of morphisms. -/
structure iso {C : Type u} [category.{v} C] (X Y : C) :=
(hom : X ⟶ Y)
(inv : Y ⟶ X)
(hom_inv_id' : hom ≫ inv = 𝟙 X . obviously)
(inv_hom_id' : inv ≫ hom = 𝟙 Y . obviously)
restate_axiom iso.hom_inv_id'
restate_axiom iso.inv_hom_id'
attribute [simp, reassoc] iso.hom_inv_id iso.inv_hom_id
infixr ` ≅ `:10 := iso -- type as \cong or \iso
variables {C : Type u} [𝒞 : category.{v} C]
include 𝒞
variables {X Y Z : C}
namespace iso
@[ext] lemma ext ⦃α β : X ≅ Y⦄ (w : α.hom = β.hom) : α = β :=
suffices α.inv = β.inv, by cases α; cases β; cc,
calc α.inv
= α.inv ≫ (β.hom ≫ β.inv) : by rw [iso.hom_inv_id, category.comp_id]
... = (α.inv ≫ α.hom) ≫ β.inv : by rw [category.assoc, ←w]
... = β.inv : by rw [iso.inv_hom_id, category.id_comp]
/-- Inverse isomorphism. -/
@[symm] def symm (I : X ≅ Y) : Y ≅ X :=
{ hom := I.inv,
inv := I.hom,
hom_inv_id' := I.inv_hom_id',
inv_hom_id' := I.hom_inv_id' }
@[simp] lemma symm_hom (α : X ≅ Y) : α.symm.hom = α.inv := rfl
@[simp] lemma symm_inv (α : X ≅ Y) : α.symm.inv = α.hom := rfl
@[simp] lemma symm_mk {X Y : C} (hom : X ⟶ Y) (inv : Y ⟶ X) (hom_inv_id) (inv_hom_id) :
iso.symm {hom := hom, inv := inv, hom_inv_id' := hom_inv_id, inv_hom_id' := inv_hom_id} =
{hom := inv, inv := hom, hom_inv_id' := inv_hom_id, inv_hom_id' := hom_inv_id} := rfl
@[simp] lemma symm_symm_eq {X Y : C} (α : X ≅ Y) : α.symm.symm = α :=
by cases α; refl
@[simp] lemma symm_eq_iff {X Y : C} {α β : X ≅ Y} : α.symm = β.symm ↔ α = β :=
⟨λ h, symm_symm_eq α ▸ symm_symm_eq β ▸ congr_arg symm h, congr_arg symm⟩
/-- Identity isomorphism. -/
@[refl, simps] def refl (X : C) : X ≅ X :=
{ hom := 𝟙 X,
inv := 𝟙 X }
@[simp] lemma refl_symm (X : C) : (iso.refl X).symm = iso.refl X := rfl
/-- Composition of two isomorphisms -/
@[trans, simps] def trans (α : X ≅ Y) (β : Y ≅ Z) : X ≅ Z :=
{ hom := α.hom ≫ β.hom,
inv := β.inv ≫ α.inv }
infixr ` ≪≫ `:80 := iso.trans -- type as `\ll \gg`.
@[simp] lemma trans_mk {X Y Z : C}
(hom : X ⟶ Y) (inv : Y ⟶ X) (hom_inv_id) (inv_hom_id)
(hom' : Y ⟶ Z) (inv' : Z ⟶ Y) (hom_inv_id') (inv_hom_id') (hom_inv_id'') (inv_hom_id'') :
iso.trans
{hom := hom, inv := inv, hom_inv_id' := hom_inv_id, inv_hom_id' := inv_hom_id}
{hom := hom', inv := inv', hom_inv_id' := hom_inv_id', inv_hom_id' := inv_hom_id'} =
{hom := hom ≫ hom', inv := inv' ≫ inv, hom_inv_id' := hom_inv_id'', inv_hom_id' := inv_hom_id''} :=
rfl
@[simp] lemma trans_symm (α : X ≅ Y) (β : Y ≅ Z) : (α ≪≫ β).symm = β.symm ≪≫ α.symm := rfl
@[simp] lemma trans_assoc {Z' : C} (α : X ≅ Y) (β : Y ≅ Z) (γ : Z ≅ Z') :
(α ≪≫ β) ≪≫ γ = α ≪≫ β ≪≫ γ :=
by ext; simp only [trans_hom, category.assoc]
@[simp] lemma refl_trans (α : X ≅ Y) : (iso.refl X) ≪≫ α = α := by ext; apply category.id_comp
@[simp] lemma trans_refl (α : X ≅ Y) : α ≪≫ (iso.refl Y) = α := by ext; apply category.comp_id
@[simp] lemma symm_self_id (α : X ≅ Y) : α.symm ≪≫ α = iso.refl Y := ext α.inv_hom_id
@[simp] lemma self_symm_id (α : X ≅ Y) : α ≪≫ α.symm = iso.refl X := ext α.hom_inv_id
@[simp] lemma symm_self_id_assoc (α : X ≅ Y) (β : Y ≅ Z) : α.symm ≪≫ α ≪≫ β = β :=
by rw [← trans_assoc, symm_self_id, refl_trans]
@[simp] lemma self_symm_id_assoc (α : X ≅ Y) (β : X ≅ Z) : α ≪≫ α.symm ≪≫ β = β :=
by rw [← trans_assoc, self_symm_id, refl_trans]
lemma inv_comp_eq (α : X ≅ Y) {f : X ⟶ Z} {g : Y ⟶ Z} : α.inv ≫ f = g ↔ f = α.hom ≫ g :=
⟨λ H, by simp [H.symm], λ H, by simp [H]⟩
lemma eq_inv_comp (α : X ≅ Y) {f : X ⟶ Z} {g : Y ⟶ Z} : g = α.inv ≫ f ↔ α.hom ≫ g = f :=
(inv_comp_eq α.symm).symm
lemma comp_inv_eq (α : X ≅ Y) {f : Z ⟶ Y} {g : Z ⟶ X} : f ≫ α.inv = g ↔ f = g ≫ α.hom :=
⟨λ H, by simp [H.symm], λ H, by simp [H]⟩
lemma eq_comp_inv (α : X ≅ Y) {f : Z ⟶ Y} {g : Z ⟶ X} : g = f ≫ α.inv ↔ g ≫ α.hom = f :=
(comp_inv_eq α.symm).symm
lemma inv_eq_inv (f g : X ≅ Y) : f.inv = g.inv ↔ f.hom = g.hom :=
have ∀{X Y : C} (f g : X ≅ Y), f.hom = g.hom → f.inv = g.inv, from λ X Y f g h, by rw [ext h],
⟨this f.symm g.symm, this f g⟩
lemma hom_comp_eq_id (α : X ≅ Y) {f : Y ⟶ X} : α.hom ≫ f = 𝟙 X ↔ f = α.inv :=
by rw [←eq_inv_comp, comp_id]
lemma comp_hom_eq_id (α : X ≅ Y) {f : Y ⟶ X} : f ≫ α.hom = 𝟙 Y ↔ f = α.inv :=
by rw [←eq_comp_inv, id_comp]
lemma hom_eq_inv (α : X ≅ Y) (β : Y ≅ X) : α.hom = β.inv ↔ β.hom = α.inv :=
by { erw [inv_eq_inv α.symm β, eq_comm], refl }
end iso
/-- `is_iso` typeclass expressing that a morphism is invertible.
This contains the data of the inverse, but is a subsingleton type. -/
class is_iso (f : X ⟶ Y) :=
(inv : Y ⟶ X)
(hom_inv_id' : f ≫ inv = 𝟙 X . obviously)
(inv_hom_id' : inv ≫ f = 𝟙 Y . obviously)
export is_iso (inv)
/-- Reinterpret a morphism `f` with an `is_iso f` instance as an `iso`. -/
def as_iso (f : X ⟶ Y) [h : is_iso f] : X ≅ Y := { hom := f, ..h }
@[simp] lemma as_iso_hom (f : X ⟶ Y) [is_iso f] : (as_iso f).hom = f := rfl
@[simp] lemma as_iso_inv (f : X ⟶ Y) [is_iso f] : (as_iso f).inv = inv f := rfl
namespace is_iso
@[simp] lemma hom_inv_id (f : X ⟶ Y) [is_iso f] : f ≫ inv f = 𝟙 X :=
is_iso.hom_inv_id' f
@[simp] lemma inv_hom_id (f : X ⟶ Y) [is_iso f] : inv f ≫ f = 𝟙 Y :=
is_iso.inv_hom_id' f
@[simp] lemma hom_inv_id_assoc {Z} (f : X ⟶ Y) [is_iso f] (g : X ⟶ Z) :
f ≫ inv f ≫ g = g :=
(as_iso f).hom_inv_id_assoc g
@[simp] lemma inv_hom_id_assoc {Z} (f : X ⟶ Y) [is_iso f] (g : Y ⟶ Z) :
inv f ≫ f ≫ g = g :=
(as_iso f).inv_hom_id_assoc g
instance (X : C) : is_iso (𝟙 X) :=
{ inv := 𝟙 X }
instance of_iso (f : X ≅ Y) : is_iso f.hom :=
{ .. f }
instance of_iso_inverse (f : X ≅ Y) : is_iso f.inv :=
is_iso.of_iso f.symm
variables {f g : X ⟶ Y} {h : Y ⟶ Z}
instance inv_is_iso [is_iso f] : is_iso (inv f) :=
is_iso.of_iso_inverse (as_iso f)
instance comp_is_iso [is_iso f] [is_iso h] : is_iso (f ≫ h) :=
is_iso.of_iso $ (as_iso f) ≪≫ (as_iso h)
@[simp] lemma inv_id : inv (𝟙 X) = 𝟙 X := rfl
@[simp] lemma inv_comp [is_iso f] [is_iso h] : inv (f ≫ h) = inv h ≫ inv f := rfl
@[simp] lemma inv_inv [is_iso f] : inv (inv f) = f := rfl
@[simp] lemma iso.inv_inv (f : X ≅ Y) : inv (f.inv) = f.hom := rfl
@[simp] lemma iso.inv_hom (f : X ≅ Y) : inv (f.hom) = f.inv := rfl
@[priority 100] -- see Note [lower instance priority]
instance epi_of_iso (f : X ⟶ Y) [is_iso f] : epi f :=
{ left_cancellation := λ Z g h w,
-- This is an interesting test case for better rewrite automation.
by rw [← is_iso.inv_hom_id_assoc f g, w, is_iso.inv_hom_id_assoc f h] }
@[priority 100] -- see Note [lower instance priority]
instance mono_of_iso (f : X ⟶ Y) [is_iso f] : mono f :=
{ right_cancellation := λ Z g h w,
by rw [←category.comp_id C g, ←category.comp_id C h, ←is_iso.hom_inv_id f, ←category.assoc, w, ←category.assoc] }
end is_iso
open is_iso
lemma eq_of_inv_eq_inv {f g : X ⟶ Y} [is_iso f] [is_iso g] (p : inv f = inv g) : f = g :=
begin
apply (cancel_epi (inv f)).1,
erw [inv_hom_id, p, inv_hom_id],
end
instance (f : X ⟶ Y) : subsingleton (is_iso f) :=
⟨λ a b,
suffices a.inv = b.inv, by cases a; cases b; congr; exact this,
show (@as_iso C _ _ _ f a).inv = (@as_iso C _ _ _ f b).inv,
by congr' 1; ext; refl⟩
lemma is_iso.inv_eq_inv {f g : X ⟶ Y} [is_iso f] [is_iso g] : inv f = inv g ↔ f = g :=
iso.inv_eq_inv (as_iso f) (as_iso g)
namespace functor
universes u₁ v₁ u₂ v₂
variables {D : Type u₂}
variables [𝒟 : category.{v₂} D]
include 𝒟
/-- A functor `F : C ⥤ D` sends isomorphisms `i : X ≅ Y` to isomorphisms `F.obj X ≅ F.obj Y` -/
def map_iso (F : C ⥤ D) {X Y : C} (i : X ≅ Y) : F.obj X ≅ F.obj Y :=
{ hom := F.map i.hom,
inv := F.map i.inv,
hom_inv_id' := by rw [←map_comp, iso.hom_inv_id, ←map_id],
inv_hom_id' := by rw [←map_comp, iso.inv_hom_id, ←map_id] }
@[simp] lemma map_iso_hom (F : C ⥤ D) {X Y : C} (i : X ≅ Y) : (F.map_iso i).hom = F.map i.hom := rfl
@[simp] lemma map_iso_inv (F : C ⥤ D) {X Y : C} (i : X ≅ Y) : (F.map_iso i).inv = F.map i.inv := rfl
@[simp] lemma map_iso_symm (F : C ⥤ D) {X Y : C} (i : X ≅ Y) :
F.map_iso i.symm = (F.map_iso i).symm :=
rfl
@[simp] lemma map_iso_trans (F : C ⥤ D) {X Y Z : C} (i : X ≅ Y) (j : Y ≅ Z) :
F.map_iso (i ≪≫ j) = (F.map_iso i) ≪≫ (F.map_iso j) :=
by ext; apply functor.map_comp
@[simp] lemma map_iso_refl (F : C ⥤ D) (X : C) : F.map_iso (iso.refl X) = iso.refl (F.obj X) :=
iso.ext $ F.map_id X
instance map_is_iso (F : C ⥤ D) (f : X ⟶ Y) [is_iso f] : is_iso (F.map f) :=
is_iso.of_iso $ F.map_iso (as_iso f)
@[simp] lemma map_inv (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) [is_iso f] :
F.map (inv f) = inv (F.map f) :=
rfl
lemma map_hom_inv (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) [is_iso f] :
F.map f ≫ F.map (inv f) = 𝟙 (F.obj X) :=
by simp
lemma map_inv_hom (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) [is_iso f] :
F.map (inv f) ≫ F.map f = 𝟙 (F.obj Y) :=
by simp
end functor
end category_theory
|
b41b89bc5f0f975d6a00cb8b188db207a4cee143 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/data/real/hyperreal.lean | de5b5d7c49da388c70d3d965e3e233ffe3b4635a | [
"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 | 36,957 | lean | /-
Copyright (c) 2019 Abhimanyu Pallavi Sudhir. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Abhimanyu Pallavi Sudhir
-/
import order.filter.filter_product
import analysis.specific_limits.basic
/-!
# Construction of the hyperreal numbers as an ultraproduct of real sequences.
-/
open filter filter.germ
open_locale topological_space classical
/-- Hyperreal numbers on the ultrafilter extending the cofinite filter -/
@[derive [linear_ordered_field, inhabited]]
def hyperreal : Type := germ (hyperfilter ℕ : filter ℕ) ℝ
namespace hyperreal
notation `ℝ*` := hyperreal
noncomputable instance : has_coe_t ℝ ℝ* := ⟨λ x, (↑x : germ _ _)⟩
@[simp, norm_cast]
lemma coe_eq_coe {x y : ℝ} : (x : ℝ*) = y ↔ x = y :=
germ.const_inj
@[simp, norm_cast] lemma coe_eq_zero {x : ℝ} : (x : ℝ*) = 0 ↔ x = 0 := coe_eq_coe
@[simp, norm_cast] lemma coe_eq_one {x : ℝ} : (x : ℝ*) = 1 ↔ x = 1 := coe_eq_coe
@[simp, norm_cast] lemma coe_one : ↑(1 : ℝ) = (1 : ℝ*) := rfl
@[simp, norm_cast] lemma coe_zero : ↑(0 : ℝ) = (0 : ℝ*) := rfl
@[simp, norm_cast] lemma coe_inv (x : ℝ) : ↑(x⁻¹) = (x⁻¹ : ℝ*) := rfl
@[simp, norm_cast] lemma coe_neg (x : ℝ) : ↑(-x) = (-x : ℝ*) := rfl
@[simp, norm_cast] lemma coe_add (x y : ℝ) : ↑(x + y) = (x + y : ℝ*) := rfl
@[simp, norm_cast] lemma coe_bit0 (x : ℝ) : ↑(bit0 x) = (bit0 x : ℝ*) := rfl
@[simp, norm_cast] lemma coe_bit1 (x : ℝ) : ↑(bit1 x) = (bit1 x : ℝ*) := rfl
@[simp, norm_cast] lemma coe_mul (x y : ℝ) : ↑(x * y) = (x * y : ℝ*) := rfl
@[simp, norm_cast] lemma coe_div (x y : ℝ) : ↑(x / y) = (x / y : ℝ*) := rfl
@[simp, norm_cast] lemma coe_sub (x y : ℝ) : ↑(x - y) = (x - y : ℝ*) := rfl
@[simp, norm_cast] lemma coe_lt_coe {x y : ℝ} : (x : ℝ*) < y ↔ x < y := germ.const_lt
@[simp, norm_cast] lemma coe_pos {x : ℝ} : 0 < (x : ℝ*) ↔ 0 < x :=
coe_lt_coe
@[simp, norm_cast] lemma coe_le_coe {x y : ℝ} : (x : ℝ*) ≤ y ↔ x ≤ y := germ.const_le_iff
@[simp, norm_cast] lemma coe_abs (x : ℝ) : ((|x| : ℝ) : ℝ*) = |x| :=
begin
convert const_abs x,
apply linear_order.to_lattice_eq_filter_germ_lattice,
end
@[simp, norm_cast] lemma coe_max (x y : ℝ) : ((max x y : ℝ) : ℝ*) = max x y := germ.const_max _ _
@[simp, norm_cast] lemma coe_min (x y : ℝ) : ((min x y : ℝ) : ℝ*) = min x y := germ.const_min _ _
/-- Construct a hyperreal number from a sequence of real numbers. -/
noncomputable def of_seq (f : ℕ → ℝ) : ℝ* := (↑f : germ (hyperfilter ℕ : filter ℕ) ℝ)
/-- A sample infinitesimal hyperreal-/
noncomputable def epsilon : ℝ* := of_seq $ λ n, n⁻¹
/-- A sample infinite hyperreal-/
noncomputable def omega : ℝ* := of_seq coe
localized "notation (name := hyperreal.epsilon) `ε` := hyperreal.epsilon" in hyperreal
localized "notation (name := hyperreal.omega) `ω` := hyperreal.omega" in hyperreal
lemma epsilon_eq_inv_omega : ε = ω⁻¹ := rfl
lemma inv_epsilon_eq_omega : ε⁻¹ = ω := @inv_inv _ _ ω
lemma epsilon_pos : 0 < ε :=
suffices ∀ᶠ i in hyperfilter ℕ, (0 : ℝ) < (i : ℕ)⁻¹, by rwa lt_def,
have h0' : {n : ℕ | ¬ 0 < n} = {0} :=
by simp only [not_lt, (set.set_of_eq_eq_singleton).symm]; ext; exact le_bot_iff,
begin
simp only [inv_pos, nat.cast_pos],
exact mem_hyperfilter_of_finite_compl (by convert set.finite_singleton _),
end
lemma epsilon_ne_zero : ε ≠ 0 := ne_of_gt epsilon_pos
lemma omega_pos : 0 < ω := by rw ←inv_epsilon_eq_omega; exact inv_pos.2 epsilon_pos
lemma omega_ne_zero : ω ≠ 0 := ne_of_gt omega_pos
theorem epsilon_mul_omega : ε * ω = 1 := @inv_mul_cancel _ _ ω omega_ne_zero
lemma lt_of_tendsto_zero_of_pos {f : ℕ → ℝ} (hf : tendsto f at_top (𝓝 0)) :
∀ {r : ℝ}, 0 < r → of_seq f < (r : ℝ*) :=
begin
simp only [metric.tendsto_at_top, real.dist_eq, sub_zero, lt_def] at hf ⊢,
intros r hr, cases hf r hr with N hf',
have hs : {i : ℕ | f i < r}ᶜ ⊆ {i : ℕ | i ≤ N} :=
λ i hi1, le_of_lt (by simp only [lt_iff_not_ge];
exact λ hi2, hi1 (lt_of_le_of_lt (le_abs_self _) (hf' i hi2)) : i < N),
exact mem_hyperfilter_of_finite_compl
((set.finite_le_nat N).subset hs)
end
lemma neg_lt_of_tendsto_zero_of_pos {f : ℕ → ℝ} (hf : tendsto f at_top (𝓝 0)) :
∀ {r : ℝ}, 0 < r → (-r : ℝ*) < of_seq f :=
λ r hr, have hg : _ := hf.neg,
neg_lt_of_neg_lt (by rw [neg_zero] at hg; exact lt_of_tendsto_zero_of_pos hg hr)
lemma gt_of_tendsto_zero_of_neg {f : ℕ → ℝ} (hf : tendsto f at_top (𝓝 0)) :
∀ {r : ℝ}, r < 0 → (r : ℝ*) < of_seq f :=
λ r hr, by rw [←neg_neg r, coe_neg];
exact neg_lt_of_tendsto_zero_of_pos hf (neg_pos.mpr hr)
lemma epsilon_lt_pos (x : ℝ) : 0 < x → ε < x :=
lt_of_tendsto_zero_of_pos tendsto_inverse_at_top_nhds_0_nat
/-- Standard part predicate -/
def is_st (x : ℝ*) (r : ℝ) := ∀ δ : ℝ, 0 < δ → (r - δ : ℝ*) < x ∧ x < r + δ
/-- Standard part function: like a "round" to ℝ instead of ℤ -/
noncomputable def st : ℝ* → ℝ :=
λ x, if h : ∃ r, is_st x r then classical.some h else 0
/-- A hyperreal number is infinitesimal if its standard part is 0 -/
def infinitesimal (x : ℝ*) := is_st x 0
/-- A hyperreal number is positive infinite if it is larger than all real numbers -/
def infinite_pos (x : ℝ*) := ∀ r : ℝ, ↑r < x
/-- A hyperreal number is negative infinite if it is smaller than all real numbers -/
def infinite_neg (x : ℝ*) := ∀ r : ℝ, x < r
/-- A hyperreal number is infinite if it is infinite positive or infinite negative -/
def infinite (x : ℝ*) := infinite_pos x ∨ infinite_neg x
/-!
### Some facts about `st`
-/
private lemma is_st_unique' (x : ℝ*) (r s : ℝ) (hr : is_st x r) (hs : is_st x s) (hrs : r < s) :
false :=
have hrs' : _ := half_pos $ sub_pos_of_lt hrs,
have hr' : _ := (hr _ hrs').2,
have hs' : _ := (hs _ hrs').1,
have h : s - ((s - r) / 2) = r + (s - r) / 2 := by linarith,
begin
norm_cast at *,
rw h at hs',
exact not_lt_of_lt hs' hr'
end
theorem is_st_unique {x : ℝ*} {r s : ℝ} (hr : is_st x r) (hs : is_st x s) : r = s :=
begin
rcases lt_trichotomy r s with h | h | h,
{ exact false.elim (is_st_unique' x r s hr hs h) },
{ exact h },
{ exact false.elim (is_st_unique' x s r hs hr h) }
end
theorem not_infinite_of_exists_st {x : ℝ*} : (∃ r : ℝ, is_st x r) → ¬ infinite x :=
λ he hi, Exists.dcases_on he $ λ r hr, hi.elim
(λ hip, not_lt_of_lt (hr 2 zero_lt_two).2 (hip $ r + 2))
(λ hin, not_lt_of_lt (hr 2 zero_lt_two).1 (hin $ r - 2))
theorem is_st_Sup {x : ℝ*} (hni : ¬ infinite x) : is_st x (Sup {y : ℝ | (y : ℝ*) < x}) :=
let S : set ℝ := {y : ℝ | (y : ℝ*) < x} in
let R : _ := Sup S in
have hnile : _ := not_forall.mp (not_or_distrib.mp hni).1,
have hnige : _ := not_forall.mp (not_or_distrib.mp hni).2,
Exists.dcases_on hnile $ Exists.dcases_on hnige $ λ r₁ hr₁ r₂ hr₂,
have HR₁ : S.nonempty :=
⟨r₁ - 1, lt_of_lt_of_le (coe_lt_coe.2 $ sub_one_lt _) (not_lt.mp hr₁) ⟩,
have HR₂ : bdd_above S :=
⟨ r₂, λ y hy, le_of_lt (coe_lt_coe.1 (lt_of_lt_of_le hy (not_lt.mp hr₂))) ⟩,
λ δ hδ,
⟨ lt_of_not_le $ λ c,
have hc : ∀ y ∈ S, y ≤ R - δ := λ y hy, coe_le_coe.1 $ le_of_lt $ lt_of_lt_of_le hy c,
not_lt_of_le (cSup_le HR₁ hc) $ sub_lt_self R hδ,
lt_of_not_le $ λ c,
have hc : ↑(R + δ / 2) < x :=
lt_of_lt_of_le (add_lt_add_left (coe_lt_coe.2 (half_lt_self hδ)) R) c,
not_lt_of_le (le_cSup HR₂ hc) $ (lt_add_iff_pos_right _).mpr $ half_pos hδ⟩
theorem exists_st_of_not_infinite {x : ℝ*} (hni : ¬ infinite x) : ∃ r : ℝ, is_st x r :=
⟨Sup {y : ℝ | (y : ℝ*) < x}, is_st_Sup hni⟩
theorem st_eq_Sup {x : ℝ*} : st x = Sup {y : ℝ | (y : ℝ*) < x} :=
begin
unfold st, split_ifs,
{ exact is_st_unique (classical.some_spec h) (is_st_Sup (not_infinite_of_exists_st h)) },
{ cases not_imp_comm.mp exists_st_of_not_infinite h with H H,
{ rw (set.ext (λ i, ⟨λ hi, set.mem_univ i, λ hi, H i⟩) : {y : ℝ | (y : ℝ*) < x} = set.univ),
exact real.Sup_univ.symm },
{ rw (set.ext (λ i, ⟨λ hi, false.elim (not_lt_of_lt (H i) hi),
λ hi, false.elim (set.not_mem_empty i hi)⟩) : {y : ℝ | (y : ℝ*) < x} = ∅),
exact real.Sup_empty.symm } }
end
theorem exists_st_iff_not_infinite {x : ℝ*} : (∃ r : ℝ, is_st x r) ↔ ¬ infinite x :=
⟨ not_infinite_of_exists_st, exists_st_of_not_infinite ⟩
theorem infinite_iff_not_exists_st {x : ℝ*} : infinite x ↔ ¬ ∃ r : ℝ, is_st x r :=
iff_not_comm.mp exists_st_iff_not_infinite
theorem st_infinite {x : ℝ*} (hi : infinite x) : st x = 0 :=
begin
unfold st, split_ifs,
{ exact false.elim ((infinite_iff_not_exists_st.mp hi) h) },
{ refl }
end
lemma st_of_is_st {x : ℝ*} {r : ℝ} (hxr : is_st x r) : st x = r :=
begin
unfold st, split_ifs,
{ exact is_st_unique (classical.some_spec h) hxr },
{ exact false.elim (h ⟨r, hxr⟩) }
end
lemma is_st_st_of_is_st {x : ℝ*} {r : ℝ} (hxr : is_st x r) : is_st x (st x) :=
by rwa [st_of_is_st hxr]
lemma is_st_st_of_exists_st {x : ℝ*} (hx : ∃ r : ℝ, is_st x r) : is_st x (st x) :=
Exists.dcases_on hx (λ r, is_st_st_of_is_st)
lemma is_st_st {x : ℝ*} (hx : st x ≠ 0) : is_st x (st x) :=
begin
unfold st, split_ifs,
{ exact classical.some_spec h },
{ exact false.elim (hx (by unfold st; split_ifs; refl)) }
end
lemma is_st_st' {x : ℝ*} (hx : ¬ infinite x) : is_st x (st x) :=
is_st_st_of_exists_st $ exists_st_of_not_infinite hx
lemma is_st_refl_real (r : ℝ) : is_st r r :=
λ δ hδ, ⟨ sub_lt_self _ (coe_lt_coe.2 hδ), (lt_add_of_pos_right _ (coe_lt_coe.2 hδ)) ⟩
lemma st_id_real (r : ℝ) : st r = r := st_of_is_st (is_st_refl_real r)
lemma eq_of_is_st_real {r s : ℝ} : is_st r s → r = s := is_st_unique (is_st_refl_real r)
lemma is_st_real_iff_eq {r s : ℝ} : is_st r s ↔ r = s :=
⟨eq_of_is_st_real, λ hrs, by rw [hrs]; exact is_st_refl_real s⟩
lemma is_st_symm_real {r s : ℝ} : is_st r s ↔ is_st s r :=
by rw [is_st_real_iff_eq, is_st_real_iff_eq, eq_comm]
lemma is_st_trans_real {r s t : ℝ} : is_st r s → is_st s t → is_st r t :=
by rw [is_st_real_iff_eq, is_st_real_iff_eq, is_st_real_iff_eq]; exact eq.trans
lemma is_st_inj_real {r₁ r₂ s : ℝ} (h1 : is_st r₁ s) (h2 : is_st r₂ s) : r₁ = r₂ :=
eq.trans (eq_of_is_st_real h1) (eq_of_is_st_real h2).symm
lemma is_st_iff_abs_sub_lt_delta {x : ℝ*} {r : ℝ} :
is_st x r ↔ ∀ (δ : ℝ), 0 < δ → |x - r| < δ :=
by simp only [abs_sub_lt_iff, sub_lt_iff_lt_add, is_st, and_comm, add_comm]
lemma is_st_add {x y : ℝ*} {r s : ℝ} : is_st x r → is_st y s → is_st (x + y) (r + s) :=
λ hxr hys d hd,
have hxr' : _ := hxr (d / 2) (half_pos hd),
have hys' : _ := hys (d / 2) (half_pos hd),
⟨by convert add_lt_add hxr'.1 hys'.1 using 1; norm_cast; linarith,
by convert add_lt_add hxr'.2 hys'.2 using 1; norm_cast; linarith⟩
lemma is_st_neg {x : ℝ*} {r : ℝ} (hxr : is_st x r) : is_st (-x) (-r) :=
λ d hd, show -(r : ℝ*) - d < -x ∧ -x < -r + d, by cases (hxr d hd); split; linarith
lemma is_st_sub {x y : ℝ*} {r s : ℝ} : is_st x r → is_st y s → is_st (x - y) (r - s) :=
λ hxr hys, by rw [sub_eq_add_neg, sub_eq_add_neg]; exact is_st_add hxr (is_st_neg hys)
/- (st x < st y) → (x < y) → (x ≤ y) → (st x ≤ st y) -/
lemma lt_of_is_st_lt {x y : ℝ*} {r s : ℝ} (hxr : is_st x r) (hys : is_st y s) :
r < s → x < y :=
λ hrs, have hrs' : 0 < (s - r) / 2 := half_pos (sub_pos.mpr hrs),
have hxr' : _ := (hxr _ hrs').2, have hys' : _ := (hys _ hrs').1,
have H1 : r + ((s - r) / 2) = (r + s) / 2 := by linarith,
have H2 : s - ((s - r) / 2) = (r + s) / 2 := by linarith,
begin
norm_cast at *,
rw H1 at hxr',
rw H2 at hys',
exact lt_trans hxr' hys'
end
lemma is_st_le_of_le {x y : ℝ*} {r s : ℝ} (hrx : is_st x r) (hsy : is_st y s) :
x ≤ y → r ≤ s := by rw [←not_lt, ←not_lt, not_imp_not]; exact lt_of_is_st_lt hsy hrx
lemma st_le_of_le {x y : ℝ*} (hix : ¬ infinite x) (hiy : ¬ infinite y) :
x ≤ y → st x ≤ st y :=
have hx' : _ := is_st_st' hix, have hy' : _ := is_st_st' hiy,
is_st_le_of_le hx' hy'
lemma lt_of_st_lt {x y : ℝ*} (hix : ¬ infinite x) (hiy : ¬ infinite y) :
st x < st y → x < y :=
have hx' : _ := is_st_st' hix, have hy' : _ := is_st_st' hiy,
lt_of_is_st_lt hx' hy'
/-!
### Basic lemmas about infinite
-/
lemma infinite_pos_def {x : ℝ*} : infinite_pos x ↔ ∀ r : ℝ, ↑r < x := by rw iff_eq_eq; refl
lemma infinite_neg_def {x : ℝ*} : infinite_neg x ↔ ∀ r : ℝ, x < r := by rw iff_eq_eq; refl
lemma ne_zero_of_infinite {x : ℝ*} : infinite x → x ≠ 0 :=
λ hI h0, or.cases_on hI
(λ hip, lt_irrefl (0 : ℝ*) ((by rwa ←h0 : infinite_pos 0) 0))
(λ hin, lt_irrefl (0 : ℝ*) ((by rwa ←h0 : infinite_neg 0) 0))
lemma not_infinite_zero : ¬ infinite 0 := λ hI, ne_zero_of_infinite hI rfl
lemma pos_of_infinite_pos {x : ℝ*} : infinite_pos x → 0 < x := λ hip, hip 0
lemma neg_of_infinite_neg {x : ℝ*} : infinite_neg x → x < 0 := λ hin, hin 0
lemma not_infinite_pos_of_infinite_neg {x : ℝ*} : infinite_neg x → ¬ infinite_pos x :=
λ hn hp, not_lt_of_lt (hn 1) (hp 1)
lemma not_infinite_neg_of_infinite_pos {x : ℝ*} : infinite_pos x → ¬ infinite_neg x :=
imp_not_comm.mp not_infinite_pos_of_infinite_neg
lemma infinite_neg_neg_of_infinite_pos {x : ℝ*} : infinite_pos x → infinite_neg (-x) :=
λ hp r, neg_lt.mp (hp (-r))
lemma infinite_pos_neg_of_infinite_neg {x : ℝ*} : infinite_neg x → infinite_pos (-x) :=
λ hp r, lt_neg.mp (hp (-r))
lemma infinite_pos_iff_infinite_neg_neg {x : ℝ*} : infinite_pos x ↔ infinite_neg (-x) :=
⟨ infinite_neg_neg_of_infinite_pos, λ hin, neg_neg x ▸ infinite_pos_neg_of_infinite_neg hin ⟩
lemma infinite_neg_iff_infinite_pos_neg {x : ℝ*} : infinite_neg x ↔ infinite_pos (-x) :=
⟨ infinite_pos_neg_of_infinite_neg, λ hin, neg_neg x ▸ infinite_neg_neg_of_infinite_pos hin ⟩
lemma infinite_iff_infinite_neg {x : ℝ*} : infinite x ↔ infinite (-x) :=
⟨ λ hi, or.cases_on hi
(λ hip, or.inr (infinite_neg_neg_of_infinite_pos hip))
(λ hin, or.inl (infinite_pos_neg_of_infinite_neg hin)),
λ hi, or.cases_on hi
(λ hipn, or.inr (infinite_neg_iff_infinite_pos_neg.mpr hipn))
(λ hinp, or.inl (infinite_pos_iff_infinite_neg_neg.mpr hinp))⟩
lemma not_infinite_of_infinitesimal {x : ℝ*} : infinitesimal x → ¬ infinite x :=
λ hi hI, have hi' : _ := (hi 2 zero_lt_two), or.dcases_on hI
(λ hip, have hip' : _ := hip 2, not_lt_of_lt hip' (by convert hi'.2; exact (zero_add 2).symm))
(λ hin, have hin' : _ := hin (-2), not_lt_of_lt hin' (by convert hi'.1; exact (zero_sub 2).symm))
lemma not_infinitesimal_of_infinite {x : ℝ*} : infinite x → ¬ infinitesimal x :=
imp_not_comm.mp not_infinite_of_infinitesimal
lemma not_infinitesimal_of_infinite_pos {x : ℝ*} : infinite_pos x → ¬ infinitesimal x :=
λ hp, not_infinitesimal_of_infinite (or.inl hp)
lemma not_infinitesimal_of_infinite_neg {x : ℝ*} : infinite_neg x → ¬ infinitesimal x :=
λ hn, not_infinitesimal_of_infinite (or.inr hn)
lemma infinite_pos_iff_infinite_and_pos {x : ℝ*} : infinite_pos x ↔ (infinite x ∧ 0 < x) :=
⟨ λ hip, ⟨or.inl hip, hip 0⟩,
λ ⟨hi, hp⟩, hi.cases_on (λ hip, hip) (λ hin, false.elim (not_lt_of_lt hp (hin 0))) ⟩
lemma infinite_neg_iff_infinite_and_neg {x : ℝ*} : infinite_neg x ↔ (infinite x ∧ x < 0) :=
⟨ λ hip, ⟨or.inr hip, hip 0⟩,
λ ⟨hi, hp⟩, hi.cases_on (λ hin, false.elim (not_lt_of_lt hp (hin 0))) (λ hip, hip) ⟩
lemma infinite_pos_iff_infinite_of_pos {x : ℝ*} (hp : 0 < x) : infinite_pos x ↔ infinite x :=
by rw [infinite_pos_iff_infinite_and_pos]; exact ⟨λ hI, hI.1, λ hI, ⟨hI, hp⟩⟩
lemma infinite_pos_iff_infinite_of_nonneg {x : ℝ*} (hp : 0 ≤ x) : infinite_pos x ↔ infinite x :=
or.cases_on (lt_or_eq_of_le hp) (infinite_pos_iff_infinite_of_pos)
(λ h, by rw h.symm; exact
⟨λ hIP, false.elim (not_infinite_zero (or.inl hIP)), λ hI, false.elim (not_infinite_zero hI)⟩)
lemma infinite_neg_iff_infinite_of_neg {x : ℝ*} (hn : x < 0) : infinite_neg x ↔ infinite x :=
by rw [infinite_neg_iff_infinite_and_neg]; exact ⟨λ hI, hI.1, λ hI, ⟨hI, hn⟩⟩
lemma infinite_pos_abs_iff_infinite_abs {x : ℝ*} : infinite_pos (|x|) ↔ infinite (|x|) :=
infinite_pos_iff_infinite_of_nonneg (abs_nonneg _)
lemma infinite_iff_infinite_pos_abs {x : ℝ*} : infinite x ↔ infinite_pos (|x|) :=
⟨ λ hi d, or.cases_on hi
(λ hip, by rw [abs_of_pos (hip 0)]; exact hip d)
(λ hin, by rw [abs_of_neg (hin 0)]; exact lt_neg.mp (hin (-d))),
λ hipa, by { rcases (lt_trichotomy x 0) with h | h | h,
{ exact or.inr (infinite_neg_iff_infinite_pos_neg.mpr (by rwa abs_of_neg h at hipa)) },
{ exact false.elim (ne_zero_of_infinite (or.inl (by rw [h]; rwa [h, abs_zero] at hipa)) h) },
{ exact or.inl (by rwa abs_of_pos h at hipa) } } ⟩
lemma infinite_iff_infinite_abs {x : ℝ*} : infinite x ↔ infinite (|x|) :=
by rw [←infinite_pos_iff_infinite_of_nonneg (abs_nonneg _), infinite_iff_infinite_pos_abs]
lemma infinite_iff_abs_lt_abs {x : ℝ*} : infinite x ↔ ∀ r : ℝ, (|r| : ℝ*) < |x| :=
⟨ λ hI r, (coe_abs r) ▸ infinite_iff_infinite_pos_abs.mp hI (|r|),
λ hR, or.cases_on (max_choice x (-x))
(λ h, or.inl $ λ r, lt_of_le_of_lt (le_abs_self _) (h ▸ (hR r)))
(λ h, or.inr $ λ r, neg_lt_neg_iff.mp $ lt_of_le_of_lt (neg_le_abs_self _) (h ▸ (hR r)))⟩
lemma infinite_pos_add_not_infinite_neg {x y : ℝ*} :
infinite_pos x → ¬ infinite_neg y → infinite_pos (x + y) :=
begin
intros hip hnin r,
cases not_forall.mp hnin with r₂ hr₂,
convert add_lt_add_of_lt_of_le (hip (r + -r₂)) (not_lt.mp hr₂) using 1,
simp
end
lemma not_infinite_neg_add_infinite_pos {x y : ℝ*} :
¬ infinite_neg x → infinite_pos y → infinite_pos (x + y) :=
λ hx hy, by rw [add_comm]; exact infinite_pos_add_not_infinite_neg hy hx
lemma infinite_neg_add_not_infinite_pos {x y : ℝ*} :
infinite_neg x → ¬ infinite_pos y → infinite_neg (x + y) :=
by rw [@infinite_neg_iff_infinite_pos_neg x, @infinite_pos_iff_infinite_neg_neg y,
@infinite_neg_iff_infinite_pos_neg (x + y), neg_add];
exact infinite_pos_add_not_infinite_neg
lemma not_infinite_pos_add_infinite_neg {x y : ℝ*} :
¬ infinite_pos x → infinite_neg y → infinite_neg (x + y) :=
λ hx hy, by rw [add_comm]; exact infinite_neg_add_not_infinite_pos hy hx
lemma infinite_pos_add_infinite_pos {x y : ℝ*} :
infinite_pos x → infinite_pos y → infinite_pos (x + y) :=
λ hx hy, infinite_pos_add_not_infinite_neg hx (not_infinite_neg_of_infinite_pos hy)
lemma infinite_neg_add_infinite_neg {x y : ℝ*} :
infinite_neg x → infinite_neg y → infinite_neg (x + y) :=
λ hx hy, infinite_neg_add_not_infinite_pos hx (not_infinite_pos_of_infinite_neg hy)
lemma infinite_pos_add_not_infinite {x y : ℝ*} :
infinite_pos x → ¬ infinite y → infinite_pos (x + y) :=
λ hx hy, infinite_pos_add_not_infinite_neg hx (not_or_distrib.mp hy).2
lemma infinite_neg_add_not_infinite {x y : ℝ*} :
infinite_neg x → ¬ infinite y → infinite_neg (x + y) :=
λ hx hy, infinite_neg_add_not_infinite_pos hx (not_or_distrib.mp hy).1
theorem infinite_pos_of_tendsto_top {f : ℕ → ℝ} (hf : tendsto f at_top at_top) :
infinite_pos (of_seq f) :=
λ r, have hf' : _ := tendsto_at_top_at_top.mp hf,
Exists.cases_on (hf' (r + 1)) $ λ i hi,
have hi' : ∀ (a : ℕ), f a < (r + 1) → a < i :=
λ a, by rw [←not_le, ←not_le]; exact not_imp_not.mpr (hi a),
have hS : {a : ℕ | r < f a}ᶜ ⊆ {a : ℕ | a ≤ i} :=
by simp only [set.compl_set_of, not_lt];
exact λ a har, le_of_lt (hi' a (lt_of_le_of_lt har (lt_add_one _))),
germ.coe_lt.2 $ mem_hyperfilter_of_finite_compl $
(set.finite_le_nat _).subset hS
theorem infinite_neg_of_tendsto_bot {f : ℕ → ℝ} (hf : tendsto f at_top at_bot) :
infinite_neg (of_seq f) :=
λ r, have hf' : _ := tendsto_at_top_at_bot.mp hf,
Exists.cases_on (hf' (r - 1)) $ λ i hi,
have hi' : ∀ (a : ℕ), r - 1 < f a → a < i :=
λ a, by rw [←not_le, ←not_le]; exact not_imp_not.mpr (hi a),
have hS : {a : ℕ | f a < r}ᶜ ⊆ {a : ℕ | a ≤ i} :=
by simp only [set.compl_set_of, not_lt];
exact λ a har, le_of_lt (hi' a (lt_of_lt_of_le (sub_one_lt _) har)),
germ.coe_lt.2 $ mem_hyperfilter_of_finite_compl $
(set.finite_le_nat _).subset hS
lemma not_infinite_neg {x : ℝ*} : ¬ infinite x → ¬ infinite (-x) :=
not_imp_not.mpr infinite_iff_infinite_neg.mpr
lemma not_infinite_add {x y : ℝ*} (hx : ¬ infinite x) (hy : ¬ infinite y) :
¬ infinite (x + y) :=
have hx' : _ := exists_st_of_not_infinite hx, have hy' : _ := exists_st_of_not_infinite hy,
Exists.cases_on hx' $ Exists.cases_on hy' $
λ r hr s hs, not_infinite_of_exists_st $ ⟨s + r, is_st_add hs hr⟩
theorem not_infinite_iff_exist_lt_gt {x : ℝ*} : ¬ infinite x ↔ ∃ r s : ℝ, (r : ℝ*) < x ∧ x < s :=
⟨ λ hni,
Exists.dcases_on (not_forall.mp (not_or_distrib.mp hni).1) $
Exists.dcases_on (not_forall.mp (not_or_distrib.mp hni).2) $ λ r hr s hs,
by rw [not_lt] at hr hs; exact ⟨r - 1, s + 1,
⟨ lt_of_lt_of_le (by rw sub_eq_add_neg; norm_num) hr,
lt_of_le_of_lt hs (by norm_num)⟩ ⟩,
λ hrs, Exists.dcases_on hrs $ λ r hr, Exists.dcases_on hr $ λ s hs,
not_or_distrib.mpr ⟨not_forall.mpr ⟨s, lt_asymm (hs.2)⟩, not_forall.mpr ⟨r, lt_asymm (hs.1) ⟩⟩⟩
theorem not_infinite_real (r : ℝ) : ¬ infinite r := by rw not_infinite_iff_exist_lt_gt; exact
⟨ r - 1, r + 1, coe_lt_coe.2 $ sub_one_lt r, coe_lt_coe.2 $ lt_add_one r⟩
theorem not_real_of_infinite {x : ℝ*} : infinite x → ∀ r : ℝ, x ≠ r :=
λ hi r hr, not_infinite_real r $ @eq.subst _ infinite _ _ hr hi
/-!
### Facts about `st` that require some infinite machinery
-/
private lemma is_st_mul' {x y : ℝ*} {r s : ℝ} (hxr : is_st x r) (hys : is_st y s) (hs : s ≠ 0) :
is_st (x * y) (r * s) :=
have hxr' : _ := is_st_iff_abs_sub_lt_delta.mp hxr,
have hys' : _ := is_st_iff_abs_sub_lt_delta.mp hys,
have h : _ := not_infinite_iff_exist_lt_gt.mp $ not_imp_not.mpr infinite_iff_infinite_abs.mpr $
not_infinite_of_exists_st ⟨r, hxr⟩,
Exists.cases_on h $ λ u h', Exists.cases_on h' $ λ t ⟨hu, ht⟩,
is_st_iff_abs_sub_lt_delta.mpr $ λ d hd,
calc |x * y - r * s|
= |x * (y - s) + (x - r) * s| :
by rw [mul_sub, sub_mul, add_sub, sub_add_cancel]
... ≤ |x * (y - s)| + |(x - r) * s| : abs_add _ _
... ≤ |x| * |y - s| + |x - r| * |s| : by simp only [abs_mul]
... ≤ |x| * ((d / t) / 2 : ℝ) + ((d / |s|) / 2 : ℝ) * |s| : add_le_add
(mul_le_mul_of_nonneg_left (le_of_lt $ hys' _ $ half_pos $ div_pos hd $
coe_pos.1 $ lt_of_le_of_lt (abs_nonneg x) ht) $ abs_nonneg _)
(mul_le_mul_of_nonneg_right (le_of_lt $ hxr' _ $ half_pos $ div_pos hd $
abs_pos.2 hs) $ abs_nonneg _)
... = (d / 2 * (|x| / t) + d / 2 : ℝ*) : by
{ push_cast [-filter.germ.const_div], -- TODO: Why wasn't `hyperreal.coe_div` used?
have : (|s| : ℝ*) ≠ 0, by simpa,
have : (2 : ℝ*) ≠ 0 := two_ne_zero,
field_simp [*, add_mul, mul_add, mul_assoc, mul_comm, mul_left_comm] }
... < (d / 2 * 1 + d / 2 : ℝ*) :
add_lt_add_right (mul_lt_mul_of_pos_left
((div_lt_one $ lt_of_le_of_lt (abs_nonneg x) ht).mpr ht) $
half_pos $ coe_pos.2 hd) _
... = (d : ℝ*) : by rw [mul_one, add_halves]
lemma is_st_mul {x y : ℝ*} {r s : ℝ} (hxr : is_st x r) (hys : is_st y s) :
is_st (x * y) (r * s) :=
have h : _ := not_infinite_iff_exist_lt_gt.mp $
not_imp_not.mpr infinite_iff_infinite_abs.mpr $ not_infinite_of_exists_st ⟨r, hxr⟩,
Exists.cases_on h $ λ u h', Exists.cases_on h' $ λ t ⟨hu, ht⟩,
begin
by_cases hs : s = 0,
{ apply is_st_iff_abs_sub_lt_delta.mpr, intros d hd,
have hys' : _ := is_st_iff_abs_sub_lt_delta.mp hys (d / t)
(div_pos hd (coe_pos.1 (lt_of_le_of_lt (abs_nonneg x) ht))),
rw [hs, coe_zero, sub_zero] at hys',
rw [hs, mul_zero, coe_zero, sub_zero, abs_mul, mul_comm,
←div_mul_cancel (d : ℝ*) (ne_of_gt (lt_of_le_of_lt (abs_nonneg x) ht)),
←coe_div],
exact mul_lt_mul'' hys' ht (abs_nonneg _) (abs_nonneg _) },
exact is_st_mul' hxr hys hs,
end
--AN INFINITE LEMMA THAT REQUIRES SOME MORE ST MACHINERY
lemma not_infinite_mul {x y : ℝ*} (hx : ¬ infinite x) (hy : ¬ infinite y) :
¬ infinite (x * y) :=
have hx' : _ := exists_st_of_not_infinite hx, have hy' : _ := exists_st_of_not_infinite hy,
Exists.cases_on hx' $ Exists.cases_on hy' $ λ r hr s hs, not_infinite_of_exists_st $
⟨s * r, is_st_mul hs hr⟩
---
lemma st_add {x y : ℝ*} (hx : ¬infinite x) (hy : ¬infinite y) : st (x + y) = st x + st y :=
have hx' : _ := is_st_st' hx,
have hy' : _ := is_st_st' hy,
have hxy : _ := is_st_st' (not_infinite_add hx hy),
have hxy' : _ := is_st_add hx' hy',
is_st_unique hxy hxy'
lemma st_neg (x : ℝ*) : st (-x) = - st x :=
if h : infinite x
then by rw [st_infinite h, st_infinite (infinite_iff_infinite_neg.mp h), neg_zero]
else is_st_unique (is_st_st' (not_infinite_neg h)) (is_st_neg (is_st_st' h))
lemma st_mul {x y : ℝ*} (hx : ¬infinite x) (hy : ¬infinite y) : st (x * y) = (st x) * (st y) :=
have hx' : _ := is_st_st' hx,
have hy' : _ := is_st_st' hy,
have hxy : _ := is_st_st' (not_infinite_mul hx hy),
have hxy' : _ := is_st_mul hx' hy',
is_st_unique hxy hxy'
/-!
### Basic lemmas about infinitesimal
-/
theorem infinitesimal_def {x : ℝ*} :
infinitesimal x ↔ (∀ r : ℝ, 0 < r → -(r : ℝ*) < x ∧ x < r) :=
⟨ λ hi r hr, by { convert (hi r hr); simp },
λ hi d hd, by { convert (hi d hd); simp } ⟩
theorem lt_of_pos_of_infinitesimal {x : ℝ*} : infinitesimal x → ∀ r : ℝ, 0 < r → x < r :=
λ hi r hr, ((infinitesimal_def.mp hi) r hr).2
theorem lt_neg_of_pos_of_infinitesimal {x : ℝ*} : infinitesimal x → ∀ r : ℝ, 0 < r → -↑r < x :=
λ hi r hr, ((infinitesimal_def.mp hi) r hr).1
theorem gt_of_neg_of_infinitesimal {x : ℝ*} : infinitesimal x → ∀ r : ℝ, r < 0 → ↑r < x :=
λ hi r hr, by convert ((infinitesimal_def.mp hi) (-r) (neg_pos.mpr hr)).1;
exact (neg_neg ↑r).symm
theorem abs_lt_real_iff_infinitesimal {x : ℝ*} :
infinitesimal x ↔ ∀ r : ℝ, r ≠ 0 → |x| < |r| :=
⟨ λ hi r hr, abs_lt.mpr (by rw ←coe_abs;
exact infinitesimal_def.mp hi (|r|) (abs_pos.2 hr)),
λ hR, infinitesimal_def.mpr $ λ r hr, abs_lt.mp $
(abs_of_pos $ coe_pos.2 hr) ▸ hR r $ ne_of_gt hr ⟩
lemma infinitesimal_zero : infinitesimal 0 := is_st_refl_real 0
lemma zero_of_infinitesimal_real {r : ℝ} : infinitesimal r → r = 0 := eq_of_is_st_real
lemma zero_iff_infinitesimal_real {r : ℝ} : infinitesimal r ↔ r = 0 :=
⟨zero_of_infinitesimal_real, λ hr, by rw hr; exact infinitesimal_zero⟩
lemma infinitesimal_add {x y : ℝ*} (hx : infinitesimal x) (hy : infinitesimal y) :
infinitesimal (x + y) :=
by simpa only [add_zero] using is_st_add hx hy
lemma infinitesimal_neg {x : ℝ*} (hx : infinitesimal x) : infinitesimal (-x) :=
by simpa only [neg_zero] using is_st_neg hx
lemma infinitesimal_neg_iff {x : ℝ*} : infinitesimal x ↔ infinitesimal (-x) :=
⟨infinitesimal_neg, λ h, (neg_neg x) ▸ @infinitesimal_neg (-x) h⟩
lemma infinitesimal_mul {x y : ℝ*} (hx : infinitesimal x) (hy : infinitesimal y) :
infinitesimal (x * y) :=
by simpa only [mul_zero] using is_st_mul hx hy
theorem infinitesimal_of_tendsto_zero {f : ℕ → ℝ} :
tendsto f at_top (𝓝 0) → infinitesimal (of_seq f) :=
λ hf d hd, by rw [sub_eq_add_neg, ←coe_neg, ←coe_add, ←coe_add, zero_add, zero_add];
exact ⟨neg_lt_of_tendsto_zero_of_pos hf hd, lt_of_tendsto_zero_of_pos hf hd⟩
theorem infinitesimal_epsilon : infinitesimal ε :=
infinitesimal_of_tendsto_zero tendsto_inverse_at_top_nhds_0_nat
lemma not_real_of_infinitesimal_ne_zero (x : ℝ*) :
infinitesimal x → x ≠ 0 → ∀ r : ℝ, x ≠ r :=
λ hi hx r hr, hx $ hr.trans $ coe_eq_zero.2 $
is_st_unique (hr.symm ▸ is_st_refl_real r : is_st x r) hi
theorem infinitesimal_sub_is_st {x : ℝ*} {r : ℝ} (hxr : is_st x r) : infinitesimal (x - r) :=
show is_st (x - r) 0,
by { rw [sub_eq_add_neg, ← add_neg_self r], exact is_st_add hxr (is_st_refl_real (-r)) }
theorem infinitesimal_sub_st {x : ℝ*} (hx : ¬infinite x) : infinitesimal (x - st x) :=
infinitesimal_sub_is_st $ is_st_st' hx
lemma infinite_pos_iff_infinitesimal_inv_pos {x : ℝ*} :
infinite_pos x ↔ (infinitesimal x⁻¹ ∧ 0 < x⁻¹) :=
⟨ λ hip, ⟨ infinitesimal_def.mpr $ λ r hr,
⟨ lt_trans (coe_lt_coe.2 (neg_neg_of_pos hr)) (inv_pos.2 (hip 0)),
(inv_lt (coe_lt_coe.2 hr) (hip 0)).mp (by convert hip r⁻¹) ⟩,
inv_pos.2 $ hip 0 ⟩,
λ ⟨hi, hp⟩ r, @classical.by_cases (r = 0) (↑r < x) (λ h, eq.substr h (inv_pos.mp hp)) $
λ h, lt_of_le_of_lt (coe_le_coe.2 (le_abs_self r))
((inv_lt_inv (inv_pos.mp hp) (coe_lt_coe.2 (abs_pos.2 h))).mp
((infinitesimal_def.mp hi) ((|r|)⁻¹) (inv_pos.2 (abs_pos.2 h))).2) ⟩
lemma infinite_neg_iff_infinitesimal_inv_neg {x : ℝ*} :
infinite_neg x ↔ (infinitesimal x⁻¹ ∧ x⁻¹ < 0) :=
⟨ λ hin, have hin' : _ := infinite_pos_iff_infinitesimal_inv_pos.mp
(infinite_pos_neg_of_infinite_neg hin),
by rwa [infinitesimal_neg_iff, ←neg_pos, neg_inv],
λ hin, by rwa [←neg_pos, infinitesimal_neg_iff, neg_inv,
←infinite_pos_iff_infinitesimal_inv_pos, ←infinite_neg_iff_infinite_pos_neg] at hin ⟩
theorem infinitesimal_inv_of_infinite {x : ℝ*} : infinite x → infinitesimal x⁻¹ :=
λ hi, or.cases_on hi
(λ hip, (infinite_pos_iff_infinitesimal_inv_pos.mp hip).1)
(λ hin, (infinite_neg_iff_infinitesimal_inv_neg.mp hin).1)
theorem infinite_of_infinitesimal_inv {x : ℝ*} (h0 : x ≠ 0) (hi : infinitesimal x⁻¹ ) :
infinite x :=
begin
cases (lt_or_gt_of_ne h0) with hn hp,
{ exact or.inr (infinite_neg_iff_infinitesimal_inv_neg.mpr ⟨hi, inv_lt_zero.mpr hn⟩) },
{ exact or.inl (infinite_pos_iff_infinitesimal_inv_pos.mpr ⟨hi, inv_pos.mpr hp⟩) }
end
theorem infinite_iff_infinitesimal_inv {x : ℝ*} (h0 : x ≠ 0) : infinite x ↔ infinitesimal x⁻¹ :=
⟨ infinitesimal_inv_of_infinite, infinite_of_infinitesimal_inv h0 ⟩
lemma infinitesimal_pos_iff_infinite_pos_inv {x : ℝ*} :
infinite_pos x⁻¹ ↔ (infinitesimal x ∧ 0 < x) :=
by convert infinite_pos_iff_infinitesimal_inv_pos; simp only [inv_inv]
lemma infinitesimal_neg_iff_infinite_neg_inv {x : ℝ*} :
infinite_neg x⁻¹ ↔ (infinitesimal x ∧ x < 0) :=
by convert infinite_neg_iff_infinitesimal_inv_neg; simp only [inv_inv]
theorem infinitesimal_iff_infinite_inv {x : ℝ*} (h : x ≠ 0) : infinitesimal x ↔ infinite x⁻¹ :=
by convert (infinite_iff_infinitesimal_inv (inv_ne_zero h)).symm; simp only [inv_inv]
/-!
### `st` stuff that requires infinitesimal machinery
-/
theorem is_st_of_tendsto {f : ℕ → ℝ} {r : ℝ} (hf : tendsto f at_top (𝓝 r)) :
is_st (of_seq f) r :=
have hg : tendsto (λ n, f n - r) at_top (𝓝 0) :=
(sub_self r) ▸ (hf.sub tendsto_const_nhds),
by rw [←(zero_add r), ←(sub_add_cancel f (λ n, r))];
exact is_st_add (infinitesimal_of_tendsto_zero hg) (is_st_refl_real r)
lemma is_st_inv {x : ℝ*} {r : ℝ} (hi : ¬ infinitesimal x) : is_st x r → is_st x⁻¹ r⁻¹ :=
λ hxr, have h : x ≠ 0 := (λ h, hi (h.symm ▸ infinitesimal_zero)),
have H : _ := exists_st_of_not_infinite $ not_imp_not.mpr (infinitesimal_iff_infinite_inv h).mpr hi,
Exists.cases_on H $ λ s hs,
have H' : is_st 1 (r * s) := mul_inv_cancel h ▸ is_st_mul hxr hs,
have H'' : s = r⁻¹ := one_div r ▸ eq_one_div_of_mul_eq_one_right (eq_of_is_st_real H').symm,
H'' ▸ hs
lemma st_inv (x : ℝ*) : st x⁻¹ = (st x)⁻¹ :=
begin
by_cases h0 : x = 0,
rw [h0, inv_zero, ←coe_zero, st_id_real, inv_zero],
by_cases h1 : infinitesimal x,
rw [st_infinite ((infinitesimal_iff_infinite_inv h0).mp h1), st_of_is_st h1, inv_zero],
by_cases h2 : infinite x,
rw [st_of_is_st (infinitesimal_inv_of_infinite h2), st_infinite h2, inv_zero],
exact st_of_is_st (is_st_inv h1 (is_st_st' h2)),
end
/-!
### Infinite stuff that requires infinitesimal machinery
-/
lemma infinite_pos_omega : infinite_pos ω :=
infinite_pos_iff_infinitesimal_inv_pos.mpr ⟨infinitesimal_epsilon, epsilon_pos⟩
lemma infinite_omega : infinite ω :=
(infinite_iff_infinitesimal_inv omega_ne_zero).mpr infinitesimal_epsilon
lemma infinite_pos_mul_of_infinite_pos_not_infinitesimal_pos {x y : ℝ*} :
infinite_pos x → ¬ infinitesimal y → 0 < y → infinite_pos (x * y) :=
λ hx hy₁ hy₂ r, have hy₁' : _ := not_forall.mp (by rw infinitesimal_def at hy₁; exact hy₁),
Exists.dcases_on hy₁' $ λ r₁ hy₁'',
have hyr : _ := by rw [not_imp, ←abs_lt, not_lt, abs_of_pos hy₂] at hy₁''; exact hy₁'',
by rw [←div_mul_cancel r (ne_of_gt hyr.1), coe_mul];
exact mul_lt_mul (hx (r / r₁)) hyr.2 (coe_lt_coe.2 hyr.1) (le_of_lt (hx 0))
lemma infinite_pos_mul_of_not_infinitesimal_pos_infinite_pos {x y : ℝ*} :
¬ infinitesimal x → 0 < x → infinite_pos y → infinite_pos (x * y) :=
λ hx hp hy, by rw mul_comm; exact infinite_pos_mul_of_infinite_pos_not_infinitesimal_pos hy hx hp
lemma infinite_pos_mul_of_infinite_neg_not_infinitesimal_neg {x y : ℝ*} :
infinite_neg x → ¬ infinitesimal y → y < 0 → infinite_pos (x * y) :=
by rw [infinite_neg_iff_infinite_pos_neg, ←neg_pos, ←neg_mul_neg, infinitesimal_neg_iff];
exact infinite_pos_mul_of_infinite_pos_not_infinitesimal_pos
lemma infinite_pos_mul_of_not_infinitesimal_neg_infinite_neg {x y : ℝ*} :
¬ infinitesimal x → x < 0 → infinite_neg y → infinite_pos (x * y) :=
λ hx hp hy, by rw mul_comm; exact infinite_pos_mul_of_infinite_neg_not_infinitesimal_neg hy hx hp
lemma infinite_neg_mul_of_infinite_pos_not_infinitesimal_neg {x y : ℝ*} :
infinite_pos x → ¬ infinitesimal y → y < 0 → infinite_neg (x * y) :=
by rw [infinite_neg_iff_infinite_pos_neg, ←neg_pos, neg_mul_eq_mul_neg, infinitesimal_neg_iff];
exact infinite_pos_mul_of_infinite_pos_not_infinitesimal_pos
lemma infinite_neg_mul_of_not_infinitesimal_neg_infinite_pos {x y : ℝ*} :
¬ infinitesimal x → x < 0 → infinite_pos y → infinite_neg (x * y) :=
λ hx hp hy, by rw mul_comm; exact infinite_neg_mul_of_infinite_pos_not_infinitesimal_neg hy hx hp
lemma infinite_neg_mul_of_infinite_neg_not_infinitesimal_pos {x y : ℝ*} :
infinite_neg x → ¬ infinitesimal y → 0 < y → infinite_neg (x * y) :=
by rw [infinite_neg_iff_infinite_pos_neg, infinite_neg_iff_infinite_pos_neg, neg_mul_eq_neg_mul];
exact infinite_pos_mul_of_infinite_pos_not_infinitesimal_pos
lemma infinite_neg_mul_of_not_infinitesimal_pos_infinite_neg {x y : ℝ*} :
¬ infinitesimal x → 0 < x → infinite_neg y → infinite_neg (x * y) :=
λ hx hp hy, by rw mul_comm; exact infinite_neg_mul_of_infinite_neg_not_infinitesimal_pos hy hx hp
lemma infinite_pos_mul_infinite_pos {x y : ℝ*} :
infinite_pos x → infinite_pos y → infinite_pos (x * y) :=
λ hx hy, infinite_pos_mul_of_infinite_pos_not_infinitesimal_pos
hx (not_infinitesimal_of_infinite_pos hy) (hy 0)
lemma infinite_neg_mul_infinite_neg {x y : ℝ*} :
infinite_neg x → infinite_neg y → infinite_pos (x * y) :=
λ hx hy, infinite_pos_mul_of_infinite_neg_not_infinitesimal_neg
hx (not_infinitesimal_of_infinite_neg hy) (hy 0)
lemma infinite_pos_mul_infinite_neg {x y : ℝ*} :
infinite_pos x → infinite_neg y → infinite_neg (x * y) :=
λ hx hy, infinite_neg_mul_of_infinite_pos_not_infinitesimal_neg
hx (not_infinitesimal_of_infinite_neg hy) (hy 0)
lemma infinite_neg_mul_infinite_pos {x y : ℝ*} :
infinite_neg x → infinite_pos y → infinite_neg (x * y) :=
λ hx hy, infinite_neg_mul_of_infinite_neg_not_infinitesimal_pos
hx (not_infinitesimal_of_infinite_pos hy) (hy 0)
lemma infinite_mul_of_infinite_not_infinitesimal {x y : ℝ*} :
infinite x → ¬ infinitesimal y → infinite (x * y) :=
λ hx hy, have h0 : y < 0 ∨ 0 < y := lt_or_gt_of_ne (λ H0, hy (eq.substr H0 (is_st_refl_real 0))),
or.dcases_on hx
(or.dcases_on h0
(λ H0 Hx, or.inr (infinite_neg_mul_of_infinite_pos_not_infinitesimal_neg Hx hy H0))
(λ H0 Hx, or.inl (infinite_pos_mul_of_infinite_pos_not_infinitesimal_pos Hx hy H0)))
(or.dcases_on h0
(λ H0 Hx, or.inl (infinite_pos_mul_of_infinite_neg_not_infinitesimal_neg Hx hy H0))
(λ H0 Hx, or.inr (infinite_neg_mul_of_infinite_neg_not_infinitesimal_pos Hx hy H0)))
lemma infinite_mul_of_not_infinitesimal_infinite {x y : ℝ*} :
¬ infinitesimal x → infinite y → infinite (x * y) :=
λ hx hy, by rw [mul_comm]; exact infinite_mul_of_infinite_not_infinitesimal hy hx
lemma infinite_mul_infinite {x y : ℝ*} : infinite x → infinite y → infinite (x * y) :=
λ hx hy, infinite_mul_of_infinite_not_infinitesimal hx (not_infinitesimal_of_infinite hy)
end hyperreal
|
811f60e232fe499cd893e7dbdbb9045920038faf | e953c38599905267210b87fb5d82dcc3e52a4214 | /library/data/set/finite.lean | 0a080695f8d91bda4bde8739625a242520c396aa | [
"Apache-2.0"
] | permissive | c-cube/lean | 563c1020bff98441c4f8ba60111fef6f6b46e31b | 0fb52a9a139f720be418dafac35104468e293b66 | refs/heads/master | 1,610,753,294,113 | 1,440,451,356,000 | 1,440,499,588,000 | 41,748,334 | 0 | 0 | null | 1,441,122,656,000 | 1,441,122,656,000 | null | UTF-8 | Lean | false | false | 7,190 | lean | /-
Copyright (c) 2015 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
The notion of "finiteness" for sets. This approach is not computational: for example, just because
an element s : set A satsifies finite s doesn't mean that we can compute the cardinality. For
a computational representation, use the finset type.
-/
import data.set.function data.finset.to_set
open nat classical
variable {A : Type}
namespace set
definition finite [class] (s : set A) : Prop := ∃ (s' : finset A), s = finset.to_set s'
theorem finite_finset [instance] (s : finset A) : finite (finset.to_set s) :=
exists.intro s rfl
/- to finset: casts every set to a finite set -/
noncomputable definition to_finset (s : set A) : finset A :=
if fins : finite s then some fins else finset.empty
theorem to_finset_of_not_finite {s : set A} (nfins : ¬ finite s) : to_finset s = (#finset ∅) :=
by rewrite [↑to_finset, dif_neg nfins]
theorem to_set_to_finset (s : set A) [fins : finite s] : finset.to_set (to_finset s) = s :=
by rewrite [↑to_finset, dif_pos fins]; exact eq.symm (some_spec fins)
theorem mem_to_finset_eq (a : A) (s : set A) [fins : finite s] :
(#finset a ∈ to_finset s) = (a ∈ s) :=
by rewrite [-to_set_to_finset at {2}]
theorem to_set_to_finset_of_not_finite {s : set A} (nfins : ¬ finite s) :
finset.to_set (to_finset s) = ∅ :=
by rewrite [to_finset_of_not_finite nfins]
theorem to_finset_to_set (s : finset A) : to_finset (finset.to_set s) = s :=
by rewrite [finset.eq_eq_to_set_eq, to_set_to_finset (finset.to_set s)]
theorem to_finset_eq_of_to_set_eq {s : set A} {t : finset A} (H : finset.to_set t = s) :
to_finset s = t :=
finset.eq_of_to_set_eq_to_set (by subst [s]; rewrite to_finset_to_set)
/- finiteness -/
theorem finite_of_to_set_to_finset_eq {s : set A} (H : finset.to_set (to_finset s) = s) :
finite s :=
by rewrite -H; apply finite_finset
theorem finite_empty [instance] : finite (∅ : set A) :=
by rewrite [-finset.to_set_empty]; apply finite_finset
theorem to_finset_empty : to_finset (∅ : set A) = (#finset ∅) :=
to_finset_eq_of_to_set_eq !finset.to_set_empty
theorem finite_insert [instance] (a : A) (s : set A) [fins : finite s] : finite (insert a s) :=
exists.intro (finset.insert a (to_finset s))
(by rewrite [finset.to_set_insert, to_set_to_finset])
theorem to_finset_insert (a : A) (s : set A) [fins : finite s] :
to_finset (insert a s) = finset.insert a (to_finset s) :=
by apply to_finset_eq_of_to_set_eq; rewrite [finset.to_set_insert, to_set_to_finset]
example : finite '{1, 2, 3} := _
theorem finite_union [instance] (s t : set A) [fins : finite s] [fint : finite t] :
finite (s ∪ t) :=
exists.intro (#finset to_finset s ∪ to_finset t)
(by rewrite [finset.to_set_union, *to_set_to_finset])
theorem to_finset_union (s t : set A) [fins : finite s] [fint : finite t] :
to_finset (s ∪ t) = (#finset to_finset s ∪ to_finset t) :=
by apply to_finset_eq_of_to_set_eq; rewrite [finset.to_set_union, *to_set_to_finset]
theorem finite_inter [instance] (s t : set A) [fins : finite s] [fint : finite t] :
finite (s ∩ t) :=
exists.intro (#finset to_finset s ∩ to_finset t)
(by rewrite [finset.to_set_inter, *to_set_to_finset])
theorem to_finset_inter (s t : set A) [fins : finite s] [fint : finite t] :
to_finset (s ∩ t) = (#finset to_finset s ∩ to_finset t) :=
by apply to_finset_eq_of_to_set_eq; rewrite [finset.to_set_inter, *to_set_to_finset]
theorem finite_sep [instance] (s : set A) (p : A → Prop) [h : decidable_pred p]
[fins : finite s] :
finite {x ∈ s | p x} :=
exists.intro (finset.sep p (to_finset s))
(by rewrite [finset.to_set_sep, *to_set_to_finset])
theorem to_finset_sep (s : set A) (p : A → Prop) [h : decidable_pred p] [fins : finite s] :
to_finset {x ∈ s | p x} = (#finset {x ∈ to_finset s | p x}) :=
by apply to_finset_eq_of_to_set_eq; rewrite [finset.to_set_sep, to_set_to_finset]
theorem finite_image [instance] {B : Type} [h : decidable_eq B] (f : A → B) (s : set A)
[fins : finite s] :
finite (f '[s]) :=
exists.intro (finset.image f (to_finset s))
(by rewrite [finset.to_set_image, *to_set_to_finset])
theorem to_finset_image {B : Type} [h : decidable_eq B] (f : A → B) (s : set A)
[fins : finite s] :
to_finset (f '[s]) = (#finset f '[to_finset s]) :=
by apply to_finset_eq_of_to_set_eq; rewrite [finset.to_set_image, to_set_to_finset]
theorem finite_diff [instance] (s t : set A) [fins : finite s] : finite (s \ t) :=
!finite_sep
theorem to_finset_diff (s t : set A) [fins : finite s] [fint : finite t] :
to_finset (s \ t) = (#finset to_finset s \ to_finset t) :=
by apply to_finset_eq_of_to_set_eq; rewrite [finset.to_set_diff, *to_set_to_finset]
theorem finite_subset {s t : set A} [fint : finite t] (ssubt : s ⊆ t) : finite s :=
by rewrite (eq_sep_of_subset ssubt); apply finite_sep
theorem to_finset_subset_to_finset_eq (s t : set A) [fins : finite s] [fint : finite t] :
(#finset to_finset s ⊆ to_finset t) = (s ⊆ t) :=
by rewrite [finset.subset_eq_to_set_subset, *to_set_to_finset]
theorem finite_of_finite_insert {s : set A} {a : A} (finias : finite (insert a s)) : finite s :=
finite_subset (subset_insert a s)
theorem finite_upto [instance] (n : ℕ) : finite {i | i < n} :=
by rewrite [-finset.to_set_upto n]; apply finite_finset
theorem to_finset_upto (n : ℕ) : to_finset {i | i < n} = finset.upto n :=
by apply (to_finset_eq_of_to_set_eq !finset.to_set_upto)
theorem finite_powerset (s : set A) [fins : finite s] : finite 𝒫 s :=
assert H : 𝒫 s = finset.to_set '[finset.to_set (#finset 𝒫 (to_finset s))],
from ext (take t, iff.intro
(suppose t ∈ 𝒫 s,
assert t ⊆ s, from this,
assert finite t, from finite_subset this,
have (#finset to_finset t ∈ 𝒫 (to_finset s)),
by rewrite [finset.mem_powerset_iff_subset, to_finset_subset_to_finset_eq]; apply `t ⊆ s`,
mem_image this (by rewrite to_set_to_finset))
(assume H',
obtain t' [(tmem : (#finset t' ∈ 𝒫 (to_finset s))) (teq : finset.to_set t' = t)],
from H',
show t ⊆ s,
begin
rewrite [-teq, finset.mem_powerset_iff_subset at tmem, -to_set_to_finset s],
rewrite -finset.subset_eq_to_set_subset, assumption
end)),
by rewrite H; apply finite_image
/- induction for finite sets -/
theorem induction_finite [recursor 6] {P : set A → Prop}
(H1 : P ∅)
(H2 : ∀ ⦃a : A⦄, ∀ {s : set A} [fins : finite s], a ∉ s → P s → P (insert a s)) :
∀ (s : set A) [fins : finite s], P s :=
begin
intro s fins,
rewrite [-to_set_to_finset s],
generalize to_finset s,
intro s',
induction s' using finset.induction with a s' nains ih,
{rewrite finset.to_set_empty, apply H1},
rewrite [finset.to_set_insert],
apply H2,
{rewrite -finset.mem_eq_mem_to_set, assumption},
exact ih
end
theorem induction_on_finite {P : set A → Prop} (s : set A) [fins : finite s]
(H1 : P ∅)
(H2 : ∀ ⦃a : A⦄, ∀ {s : set A} [fins : finite s], a ∉ s → P s → P (insert a s)) :
P s :=
induction_finite H1 H2 s
end set
|
08953c67051a6f61f030ad15355ae341925e3874 | 947b78d97130d56365ae2ec264df196ce769371a | /tests/lean/run/def3.lean | ac41679e8e8ca1647a52613803441afa1d20cc61 | [
"Apache-2.0"
] | permissive | shyamalschandra/lean4 | 27044812be8698f0c79147615b1d5090b9f4b037 | 6e7a883b21eaf62831e8111b251dc9b18f40e604 | refs/heads/master | 1,671,417,126,371 | 1,601,859,995,000 | 1,601,860,020,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 101 | lean | new_frontend
abbrev N := Nat
def f : N → Nat
| 0 => 1
| n+1 => n
theorem ex1 : f 0 = 1 :=
rfl
|
5c1cddf3a020a0ba4e6b8084007371ebb77e701b | c0ddb2cf190d518bc0f2f0ee221dd22b1172888f | /mguaypaq/insertion_sort.lean | c390b3cebb0e639a12c501a825630918354f29d1 | [] | no_license | mguaypaq/haskell-math | 3b314552878517806b3151aa36aae422f383fad1 | 1ce7f3067eb8966fe7e7e4bffdf073b1f815fc04 | refs/heads/master | 1,607,775,289,122 | 1,582,435,358,000 | 1,582,435,358,000 | 234,125,578 | 0 | 0 | null | 1,579,106,398,000 | 1,579,106,397,000 | null | UTF-8 | Lean | false | false | 3,879 | lean | -- Every nonempty list of distinct strictly positive integers
-- has a member at least as large as the length of the list.
----------------------------------------------------------------
-- The proposition that a list has distinct elements.
def list.distinct : list nat -> Prop
| [] := true
| (head :: tail) := (head ∉ tail) ∧ tail.distinct
-- The proposition that a list only has positive elements.
def list.positive : list nat -> Prop
| [] := true
| (head :: tail) := (head > 0) ∧ tail.positive
-- The theorem statement.
def goal : Prop := forall (L : list nat),
¬L.empty ∧ L.distinct ∧ L.positive ->
exists (n : nat), (n ∈ L) ∧ (n ≥ L.length)
----------------------------------------------------------------
inductive chain : nat -> nat -> Type
| nil : chain 0 0
| cons : forall {a b len : nat},
(a > b) -> (chain b len) -> (chain a (len+1))
namespace chain
lemma max_ge_len : forall {a len}, (chain a len) -> (a ≥ len)
| _ _ nil := (nat.less_than_or_equal.refl 0)
| a _ (cons h tail) := (nat.lt_of_le_of_lt (max_ge_len tail) h)
def member (n : nat) : forall {a len}, (chain a len) -> Prop
| _ _ nil := false
| a _ (cons _ tail) := (n = a) ∨ (member tail)
instance {a len} : has_mem nat (chain a len) := ⟨fun n C, member n C⟩
lemma max_ge_mem {n : nat} : forall {a len} {C : chain a len}, (n ∈ C) -> (a ≥ n)
| _ _ nil := false.elim
| a _ (@cons _ b _ a_gt_b C) := (or.rec nat.le_of_eq
(fun h, nat.le_trans (max_ge_mem h) (nat.le_of_lt a_gt_b)))
end chain
----------------------------------------------------------------
def insertion_helper (head : nat) :
forall {a len} (C : chain a len),
(head ∉ C) ∧ (head > 0) ->
Σ' {a'} (C' : chain a' (len+1)),
(forall (n : nat), (n ∈ C') ↔ ((n = head) ∨ (n ∈ C)))
| _ _ chain.nil ⟨_, h_positive⟩ :=
⟨_, (chain.cons h_positive chain.nil), (fun n, iff.refl _)⟩
| a (len+1) (@chain.cons _ b _ a_gt_b C) ⟨h_nonmember, h_positive⟩ :=
if head_vs_a : head > a
then ⟨_, (chain.cons head_vs_a (chain.cons a_gt_b C)),
(fun n, iff.refl _)⟩
else let
a_gt_head : a > head :=
(or.resolve_right (nat.lt_trichotomy head a)
(or.rec (h_nonmember ∘ or.inl) head_vs_a)),
⟨b', C', head_or_C⟩ :=
insertion_helper C ⟨h_nonmember ∘ or.inr, h_positive⟩,
a_gt_b' : a > b' :=
(or.rec_on ((head_or_C b').mp (let (chain.cons _ _) := C' in or.inl rfl))
(fun (h : b' = head), eq.substr h a_gt_head)
(fun (h : b' ∈ C), nat.lt_of_le_of_lt (chain.max_ge_mem h) a_gt_b))
in ⟨_, (chain.cons (a_gt_b') C'),
(fun n, iff.intro
(or.rec
(or.inr ∘ or.inl)
((or.imp_right or.inr) ∘ (head_or_C n).mp))
(or.rec
(or.inr ∘ (head_or_C n).mpr ∘ or.inl)
(or.imp_right ((head_or_C n).mpr ∘ or.inr))))⟩
def insertion_sort :
forall (L : list nat), L.distinct ∧ L.positive ->
Σ' (a : nat) (C : chain a L.length),
(forall (n : nat), (n ∈ C) ↔ (n ∈ L))
| [] _ := ⟨0, chain.nil, (fun n, iff.refl _)⟩
| (head :: tail) ⟨h_distinct, h_positive⟩ :=
let
⟨_, C, h_permuted⟩ := insertion_sort tail
⟨h_distinct.right, h_positive.right⟩,
⟨_, C', head_or_C⟩ := insertion_helper head C
⟨(h_distinct.left ∘ (h_permuted head).mp), h_positive.left⟩
in ⟨_, C',
(fun n, iff.intro
((or.imp_right (h_permuted n).mp) ∘ (head_or_C n).mp)
((head_or_C n).mpr ∘ (or.imp_right (h_permuted n).mpr)))⟩
----------------------------------------------------------------
theorem proof : goal
| [] ⟨h, _⟩ := false.elim (h rfl)
| (head :: tail) ⟨_, h⟩ :=
let ⟨a, C, h_permuted⟩ := insertion_sort (head :: tail) h
in ⟨a,
((h_permuted a).mp (let (chain.cons _ _) := C in or.inl rfl)),
(chain.max_ge_len C)⟩
|
c15efbea18baa19dd04ced494f2c70ee6b67c376 | 9dd3f3912f7321eb58ee9aa8f21778ad6221f87c | /library/init/data/basic.lean | 58e83b0185288df51b77bdd51cac0af040eb265b | [
"Apache-2.0"
] | permissive | bre7k30/lean | de893411bcfa7b3c5572e61b9e1c52951b310aa4 | 5a924699d076dab1bd5af23a8f910b433e598d7a | refs/heads/master | 1,610,900,145,817 | 1,488,006,845,000 | 1,488,006,845,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 583 | 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.setoid init.data.quot init.data.bool.basic init.data.unit
import init.data.nat.basic init.data.prod init.data.sum.basic
import init.data.num.basic init.data.sigma.basic init.data.subtype.basic
import init.data.fin.basic init.data.list.basic init.data.char.basic
import init.data.string.basic init.data.option.basic init.data.set
import init.data.unsigned init.data.ordering init.data.to_string
|
f7a93c3917ffb02d36966e6b5e0ce6e853e1ef90 | e0f9ba56b7fedc16ef8697f6caeef5898b435143 | /src/control/applicative.lean | f05497b6d434ef68d335f26063813b3bb6fa58da | [
"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 | 5,417 | lean | /-
Copyright (c) 2017 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Simon Hudon
Instances for identity and composition functors
-/
import control.functor
universe variables u v w
section lemmas
open function
variables {F : Type u → Type v}
variables [applicative F] [is_lawful_applicative F]
variables {α β γ σ : Type u}
attribute [functor_norm] seq_assoc pure_seq_eq_map map_pure seq_map_assoc map_seq
lemma applicative.map_seq_map (f : α → β → γ) (g : σ → β) (x : F α) (y : F σ) :
(f <$> x) <*> (g <$> y) = (flip (∘) g ∘ f) <$> x <*> y :=
by simp [flip] with functor_norm
lemma applicative.pure_seq_eq_map' (f : α → β) :
(<*>) (pure f : F (α → β)) = (<$>) f :=
by ext; simp with functor_norm
theorem applicative.ext {F} : ∀ {A1 : applicative F} {A2 : applicative F}
[@is_lawful_applicative F A1] [@is_lawful_applicative F A2]
(H1 : ∀ {α : Type u} (x : α),
@has_pure.pure _ A1.to_has_pure _ x = @has_pure.pure _ A2.to_has_pure _ x)
(H2 : ∀ {α β : Type u} (f : F (α → β)) (x : F α),
@has_seq.seq _ A1.to_has_seq _ _ f x = @has_seq.seq _ A2.to_has_seq _ _ f x),
A1 = A2
| {to_functor := F1, seq := s1, pure := p1, seq_left := sl1, seq_right := sr1}
{to_functor := F2, seq := s2, pure := p2, seq_left := sl2, seq_right := sr2} L1 L2 H1 H2 :=
begin
have : @p1 = @p2, {funext α x, apply H1}, subst this,
have : @s1 = @s2, {funext α β f x, apply H2}, subst this,
cases L1, cases L2,
have : F1 = F2,
{ resetI, apply functor.ext, intros,
exact (L1_pure_seq_eq_map _ _).symm.trans (L2_pure_seq_eq_map _ _) },
subst this,
congr; funext α β x y,
{ exact (L1_seq_left_eq _ _).trans (L2_seq_left_eq _ _).symm },
{ exact (L1_seq_right_eq _ _).trans (L2_seq_right_eq _ _).symm }
end
end lemmas
instance : is_comm_applicative id :=
by refine { .. }; intros; refl
namespace comp
open function (hiding comp)
open functor
variables {F : Type u → Type w} {G : Type v → Type u}
variables [applicative F] [applicative G]
protected def seq {α β : Type v} : comp F G (α → β) → comp F G α → comp F G β
| (comp.mk f) (comp.mk x) := comp.mk $ (<*>) <$> f <*> x
instance : has_pure (comp F G) :=
⟨λ _ x, comp.mk $ pure $ pure x⟩
instance : has_seq (comp F G) :=
⟨λ _ _ f x, comp.seq f x⟩
@[simp] protected lemma run_pure {α : Type v} :
∀ x : α, (pure x : comp F G α).run = pure (pure x)
| _ := rfl
@[simp] protected lemma run_seq {α β : Type v} (f : comp F G (α → β)) (x : comp F G α) :
(f <*> x).run = (<*>) <$> f.run <*> x.run := rfl
instance : applicative (comp F G) :=
{ map := @comp.map F G _ _,
seq := @comp.seq F G _ _,
..comp.has_pure }
variables [is_lawful_applicative F] [is_lawful_applicative G]
variables {α β γ : Type v}
lemma map_pure (f : α → β) (x : α) : (f <$> pure x : comp F G β) = pure (f x) :=
comp.ext $ by simp
lemma seq_pure (f : comp F G (α → β)) (x : α) :
f <*> pure x = (λ g : α → β, g x) <$> f :=
comp.ext $ by simp [(∘)] with functor_norm
lemma seq_assoc (x : comp F G α) (f : comp F G (α → β)) (g : comp F G (β → γ)) :
g <*> (f <*> x) = (@function.comp α β γ <$> g) <*> f <*> x :=
comp.ext $ by simp [(∘)] with functor_norm
lemma pure_seq_eq_map (f : α → β) (x : comp F G α) :
pure f <*> x = f <$> x :=
comp.ext $ by simp [applicative.pure_seq_eq_map'] with functor_norm
instance : is_lawful_applicative (comp F G) :=
{ pure_seq_eq_map := @comp.pure_seq_eq_map F G _ _ _ _,
map_pure := @comp.map_pure F G _ _ _ _,
seq_pure := @comp.seq_pure F G _ _ _ _,
seq_assoc := @comp.seq_assoc F G _ _ _ _ }
theorem applicative_id_comp {F} [AF : applicative F] [LF : is_lawful_applicative F] :
@comp.applicative id F _ _ = AF :=
@applicative.ext F _ _ (@comp.is_lawful_applicative id F _ _ _ _) _
(λ α x, rfl) (λ α β f x, rfl)
theorem applicative_comp_id {F} [AF : applicative F] [LF : is_lawful_applicative F] :
@comp.applicative F id _ _ = AF :=
@applicative.ext F _ _ (@comp.is_lawful_applicative F id _ _ _ _) _
(λ α x, rfl) (λ α β f x, show id <$> f <*> x = f <*> x, by rw id_map)
open is_comm_applicative
instance {f : Type u → Type w} {g : Type v → Type u}
[applicative f] [applicative g]
[is_comm_applicative f] [is_comm_applicative g] :
is_comm_applicative (comp f g) :=
by { refine { .. @comp.is_lawful_applicative f g _ _ _ _, .. },
intros, casesm* comp _ _ _, simp! [map,has_seq.seq] with functor_norm,
rw [commutative_map],
simp [comp.mk,flip,(∘)] with functor_norm,
congr, funext, rw [commutative_map], congr }
end comp
open functor
@[functor_norm]
lemma comp.seq_mk {α β : Type w}
{f : Type u → Type v} {g : Type w → Type u}
[applicative f] [applicative g]
(h : f (g (α → β))) (x : f (g α)) :
comp.mk h <*> comp.mk x = comp.mk (has_seq.seq <$> h <*> x) := rfl
instance {α} [has_one α] [has_mul α] : applicative (const α) :=
{ pure := λ β x, (1 : α),
seq := λ β γ f x, (f * x : α) }
instance {α} [monoid α] : is_lawful_applicative (const α) :=
by refine { .. }; intros; simp [mul_assoc]
instance {α} [has_zero α] [has_add α] : applicative (add_const α) :=
{ pure := λ β x, (0 : α),
seq := λ β γ f x, (f + x : α) }
instance {α} [add_monoid α] : is_lawful_applicative (add_const α) :=
by refine { .. }; intros; simp
|
b7aa06c1b3c2f3087579b2c0c0a87fc24ab577dd | 4fa161becb8ce7378a709f5992a594764699e268 | /src/order/basic.lean | 142c2c1483b7fd362b40c131e515e6f14669d869 | [
"Apache-2.0"
] | permissive | laughinggas/mathlib | e4aa4565ae34e46e834434284cb26bd9d67bc373 | 86dcd5cda7a5017c8b3c8876c89a510a19d49aad | refs/heads/master | 1,669,496,232,688 | 1,592,831,995,000 | 1,592,831,995,000 | 274,155,979 | 0 | 0 | Apache-2.0 | 1,592,835,190,000 | 1,592,835,189,000 | null | UTF-8 | Lean | false | false | 17,916 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Mario Carneiro
-/
import data.set.basic
open function
/-!
# Basic definitions about `≤` and `<`
## Definitions
### Predicates on functions
- `monotone f`: a function between two types equipped with `≤` is monotone
if `a ≤ b` implies `f a ≤ f b`.
- `strict_mono f` : a function between two types equipped with `<` is strictly monotone
if `a < b` implies `f a < f b`.
- `order_dual α` : a type tag reversing the meaning of all inequalities.
### Transfering orders
- `order.preimage`, `preorder.lift`: transfer a (pre)order on `β` to an order on `α`
using a function `f : α → β`.
- `partial_order.lift`, `linear_order.lift`, `decidable_linear_order.lift`:
transfer a partial (resp., linear, decidable linear) order on `β` to a partial
(resp., linear, decidable linear) order on `α` using an injective function `f`.
### Extra classes
- `no_top_order`, `no_bot_order`: an order without a maximal/minimal element.
- `densely_ordered`: an order with no gaps, i.e. for any two elements `a<b` there exists
`c`, `a<c<b`.
## Main theorems
- `monotone_of_monotone_nat`: if `f : ℕ → α` and `f n ≤ f (n + 1)` for all `n`, then
`f` is monotone;
- `strict_mono.nat`: if `f : ℕ → α` and `f n < f (n + 1)` for all `n`, then f is strictly monotone.
## TODO
- expand module docs
- automatic construction of dual definitions / theorems
## Tags
preorder, order, partial order, linear order, monotone, strictly monotone
-/
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w} {r : α → α → Prop}
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem ge_of_eq [preorder α] {a b : α} : a = b → a ≥ b :=
λ h, h ▸ le_refl a
theorem preorder.ext {α} {A B : preorder α}
(H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B :=
begin
resetI, cases A, cases B, congr,
{ funext x y, exact propext (H x y) },
{ funext x y,
dsimp [(≤)] at A_lt_iff_le_not_le B_lt_iff_le_not_le H,
simp [A_lt_iff_le_not_le, B_lt_iff_le_not_le, H] },
end
theorem partial_order.ext {α} {A B : partial_order α}
(H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B :=
by haveI this := preorder.ext H;
cases A; cases B; injection this; congr'
theorem linear_order.ext {α} {A B : linear_order α}
(H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B :=
by haveI this := partial_order.ext H;
cases A; cases B; injection this; congr'
/-- Given an order `R` on `β` and a function `f : α → β`,
the preimage order on `α` is defined by `x ≤ y ↔ f x ≤ f y`.
It is the unique order on `α` making `f` an order embedding
(assuming `f` is injective). -/
@[simp] def order.preimage {α β} (f : α → β) (s : β → β → Prop) (x y : α) := s (f x) (f y)
infix ` ⁻¹'o `:80 := order.preimage
/-- The preimage of a decidable order is decidable. -/
instance order.preimage.decidable {α β} (f : α → β) (s : β → β → Prop) [H : decidable_rel s] :
decidable_rel (f ⁻¹'o s) :=
λ x y, H _ _
section monotone
variables [preorder α] [preorder β] [preorder γ]
/-- A function between preorders is monotone if
`a ≤ b` implies `f a ≤ f b`. -/
def monotone (f : α → β) := ∀⦃a b⦄, a ≤ b → f a ≤ f b
theorem monotone_id : @monotone α α _ _ id := assume x y h, h
theorem monotone_const {b : β} : monotone (λ(a:α), b) := assume x y h, le_refl b
protected theorem monotone.comp {g : β → γ} {f : α → β} (m_g : monotone g) (m_f : monotone f) :
monotone (g ∘ f) :=
assume a b h, m_g (m_f h)
protected theorem monotone.iterate {f : α → α} (hf : monotone f) (n : ℕ) : monotone (f^[n]) :=
nat.rec_on n monotone_id (λ n ihn, ihn.comp hf)
lemma monotone_of_monotone_nat {f : ℕ → α} (hf : ∀n, f n ≤ f (n + 1)) :
monotone f | n m h :=
begin
induction h,
{ refl },
{ transitivity, assumption, exact hf _ }
end
lemma reflect_lt {α β} [linear_order α] [preorder β] {f : α → β} (hf : monotone f)
{x x' : α} (h : f x < f x') : x < x' :=
by { rw [← not_le], intro h', apply not_le_of_lt h, exact hf h' }
end monotone
/-- A function `f` is strictly monotone if `a < b` implies `f a < f b`. -/
def strict_mono [has_lt α] [has_lt β] (f : α → β) : Prop :=
∀ ⦃a b⦄, a < b → f a < f b
lemma strict_mono_id [has_lt α] : strict_mono (id : α → α) := λ a b, id
namespace strict_mono
open ordering function
lemma comp [has_lt α] [has_lt β] [has_lt γ] {g : β → γ} {f : α → β}
(hg : strict_mono g) (hf : strict_mono f) :
strict_mono (g ∘ f) :=
λ a b h, hg (hf h)
protected theorem iterate [has_lt α] {f : α → α} (hf : strict_mono f) (n : ℕ) :
strict_mono (f^[n]) :=
nat.rec_on n strict_mono_id (λ n ihn, ihn.comp hf)
lemma id_le {φ : ℕ → ℕ} (h : strict_mono φ) : ∀ n, n ≤ φ n :=
λ n, nat.rec_on n (nat.zero_le _) (λ n hn, nat.succ_le_of_lt (lt_of_le_of_lt hn $ h $ nat.lt_succ_self n))
section
variables [linear_order α] [preorder β] {f : α → β}
lemma lt_iff_lt (H : strict_mono f) {a b} :
f a < f b ↔ a < b :=
⟨λ h, ((lt_trichotomy b a)
.resolve_left $ λ h', lt_asymm h $ H h')
.resolve_left $ λ e, ne_of_gt h $ congr_arg _ e, @H _ _⟩
lemma injective (H : strict_mono f) : injective f
| a b e := ((lt_trichotomy a b)
.resolve_left $ λ h, ne_of_lt (H h) e)
.resolve_right $ λ h, ne_of_gt (H h) e
theorem compares (H : strict_mono f) {a b} :
∀ {o}, compares o (f a) (f b) ↔ compares o a b
| lt := H.lt_iff_lt
| eq := ⟨λ h, H.injective h, congr_arg _⟩
| gt := H.lt_iff_lt
lemma le_iff_le (H : strict_mono f) {a b} :
f a ≤ f b ↔ a ≤ b :=
⟨λ h, le_of_not_gt $ λ h', not_le_of_lt (H h') h,
λ h, (lt_or_eq_of_le h).elim (λ h', le_of_lt (H h')) (λ h', h' ▸ le_refl _)⟩
end
protected lemma nat {β} [preorder β] {f : ℕ → β} (h : ∀n, f n < f (n+1)) : strict_mono f :=
by { intros n m hnm, induction hnm with m' hnm' ih, apply h, exact lt.trans ih (h _) }
-- `preorder α` isn't strong enough: if the preorder on α is an equivalence relation,
-- then `strict_mono f` is vacuously true.
lemma monotone [partial_order α] [preorder β] {f : α → β} (H : strict_mono f) : monotone f :=
λ a b h, (lt_or_eq_of_le h).rec (le_of_lt ∘ (@H _ _)) (by rintro rfl; refl)
end strict_mono
section
open function
variables [partial_order α] [partial_order β] {f : α → β}
lemma strict_mono_of_monotone_of_injective (h₁ : monotone f) (h₂ : injective f) :
strict_mono f :=
λ a b h,
begin
rw lt_iff_le_and_ne at ⊢ h,
exact ⟨h₁ h.1, λ e, h.2 (h₂ e)⟩
end
end
/-- Type tag for a set with dual order: `≤` means `≥` and `<` means `>`. -/
def order_dual (α : Type*) := α
namespace order_dual
instance (α : Type*) [h : nonempty α] : nonempty (order_dual α) := h
instance (α : Type*) [has_le α] : has_le (order_dual α) := ⟨λx y:α, y ≤ x⟩
instance (α : Type*) [has_lt α] : has_lt (order_dual α) := ⟨λx y:α, y < x⟩
-- `dual_le` and `dual_lt` should not be simp lemmas:
-- they cause a loop since `α` and `order_dual α` are definitionally equal
lemma dual_le [has_le α] {a b : α} :
@has_le.le (order_dual α) _ a b ↔ @has_le.le α _ b a := iff.rfl
lemma dual_lt [has_lt α] {a b : α} :
@has_lt.lt (order_dual α) _ a b ↔ @has_lt.lt α _ b a := iff.rfl
instance (α : Type*) [preorder α] : preorder (order_dual α) :=
{ le_refl := le_refl,
le_trans := assume a b c hab hbc, le_trans hbc hab,
lt_iff_le_not_le := λ _ _, lt_iff_le_not_le,
.. order_dual.has_le α,
.. order_dual.has_lt α }
instance (α : Type*) [partial_order α] : partial_order (order_dual α) :=
{ le_antisymm := assume a b hab hba, @le_antisymm α _ a b hba hab, .. order_dual.preorder α }
instance (α : Type*) [linear_order α] : linear_order (order_dual α) :=
{ le_total := assume a b:α, le_total b a, .. order_dual.partial_order α }
instance (α : Type*) [decidable_linear_order α] : decidable_linear_order (order_dual α) :=
{ decidable_le := show decidable_rel (λa b:α, b ≤ a), by apply_instance,
decidable_lt := show decidable_rel (λa b:α, b < a), by apply_instance,
.. order_dual.linear_order α }
instance : Π [inhabited α], inhabited (order_dual α) := id
end order_dual
/- order instances on the function space -/
instance pi.preorder {ι : Type u} {α : ι → Type v} [∀i, preorder (α i)] : preorder (Πi, α i) :=
{ le := λx y, ∀i, x i ≤ y i,
le_refl := assume a i, le_refl (a i),
le_trans := assume a b c h₁ h₂ i, le_trans (h₁ i) (h₂ i) }
instance pi.partial_order {ι : Type u} {α : ι → Type v} [∀i, partial_order (α i)] :
partial_order (Πi, α i) :=
{ le_antisymm := λf g h1 h2, funext (λb, le_antisymm (h1 b) (h2 b)),
..pi.preorder }
theorem comp_le_comp_left_of_monotone [preorder α] [preorder β]
{f : β → α} {g h : γ → β} (m_f : monotone f) (le_gh : g ≤ h) :
has_le.le.{max w u} (f ∘ g) (f ∘ h) :=
assume x, m_f (le_gh x)
section monotone
variables [preorder α] [preorder γ]
protected theorem monotone.order_dual {f : α → γ} (hf : monotone f) :
@monotone (order_dual α) (order_dual γ) _ _ f :=
λ x y hxy, hf hxy
theorem monotone_lam {f : α → β → γ} (m : ∀b, monotone (λa, f a b)) : monotone f :=
assume a a' h b, m b h
theorem monotone_app (f : β → α → γ) (b : β) (m : monotone (λa b, f b a)) : monotone (f b) :=
assume a a' h, m h b
end monotone
theorem strict_mono.order_dual [has_lt α] [has_lt β] {f : α → β} (hf : strict_mono f) :
@strict_mono (order_dual α) (order_dual β) _ _ f :=
λ x y hxy, hf hxy
/-- Transfer a `preorder` on `β` to a `preorder` on `α` using a function `f : α → β`. -/
def preorder.lift {α β} [preorder β] (f : α → β) : preorder α :=
{ le := λx y, f x ≤ f y,
le_refl := λ a, le_refl _,
le_trans := λ a b c, le_trans,
lt := λx y, f x < f y,
lt_iff_le_not_le := λ a b, lt_iff_le_not_le }
/-- Transfer a `partial_order` on `β` to a `partial_order` on `α` using an injective
function `f : α → β`. -/
def partial_order.lift {α β} [partial_order β] (f : α → β) (inj : injective f) :
partial_order α :=
{ le_antisymm := λ a b h₁ h₂, inj (le_antisymm h₁ h₂), .. preorder.lift f }
/-- Transfer a `linear_order` on `β` to a `linear_order` on `α` using an injective
function `f : α → β`. -/
def linear_order.lift {α β} [linear_order β] (f : α → β) (inj : injective f) :
linear_order α :=
{ le_total := λx y, le_total (f x) (f y), .. partial_order.lift f inj }
/-- Transfer a `decidable_linear_order` on `β` to a `decidable_linear_order` on `α` using
an injective function `f : α → β`. -/
def decidable_linear_order.lift {α β} [decidable_linear_order β] (f : α → β) (inj : injective f) :
decidable_linear_order α :=
{ decidable_le := λ x y, show decidable (f x ≤ f y), by apply_instance,
decidable_lt := λ x y, show decidable (f x < f y), by apply_instance,
decidable_eq := λ x y, decidable_of_iff _ ⟨@inj x y, congr_arg f⟩,
.. linear_order.lift f inj }
instance subtype.preorder {α} [preorder α] (p : α → Prop) : preorder (subtype p) :=
preorder.lift subtype.val
instance subtype.partial_order {α} [partial_order α] (p : α → Prop) :
partial_order (subtype p) :=
partial_order.lift subtype.val subtype.val_injective
instance subtype.linear_order {α} [linear_order α] (p : α → Prop) : linear_order (subtype p) :=
linear_order.lift subtype.val subtype.val_injective
instance subtype.decidable_linear_order {α} [decidable_linear_order α] (p : α → Prop) :
decidable_linear_order (subtype p) :=
decidable_linear_order.lift subtype.val subtype.val_injective
instance prod.has_le (α : Type u) (β : Type v) [has_le α] [has_le β] : has_le (α × β) :=
⟨λp q, p.1 ≤ q.1 ∧ p.2 ≤ q.2⟩
instance prod.preorder (α : Type u) (β : Type v) [preorder α] [preorder β] : preorder (α × β) :=
{ le_refl := assume ⟨a, b⟩, ⟨le_refl a, le_refl b⟩,
le_trans := assume ⟨a, b⟩ ⟨c, d⟩ ⟨e, f⟩ ⟨hac, hbd⟩ ⟨hce, hdf⟩,
⟨le_trans hac hce, le_trans hbd hdf⟩,
.. prod.has_le α β }
/-- The pointwise partial order on a product.
(The lexicographic ordering is defined in order/lexicographic.lean, and the instances are
available via the type synonym `lex α β = α × β`.) -/
instance prod.partial_order (α : Type u) (β : Type v) [partial_order α] [partial_order β] :
partial_order (α × β) :=
{ le_antisymm := assume ⟨a, b⟩ ⟨c, d⟩ ⟨hac, hbd⟩ ⟨hca, hdb⟩,
prod.ext (le_antisymm hac hca) (le_antisymm hbd hdb),
.. prod.preorder α β }
/-!
### Additional order classes
-/
/-- order without a top element; somtimes called cofinal -/
class no_top_order (α : Type u) [preorder α] : Prop :=
(no_top : ∀a:α, ∃a', a < a')
lemma no_top [preorder α] [no_top_order α] : ∀a:α, ∃a', a < a' :=
no_top_order.no_top
/-- order without a bottom element; somtimes called coinitial or dense -/
class no_bot_order (α : Type u) [preorder α] : Prop :=
(no_bot : ∀a:α, ∃a', a' < a)
lemma no_bot [preorder α] [no_bot_order α] : ∀a:α, ∃a', a' < a :=
no_bot_order.no_bot
instance order_dual.no_top_order (α : Type u) [preorder α] [no_bot_order α] :
no_top_order (order_dual α) :=
⟨λ a, @no_bot α _ _ a⟩
instance order_dual.no_bot_order (α : Type u) [preorder α] [no_top_order α] :
no_bot_order (order_dual α) :=
⟨λ a, @no_top α _ _ a⟩
/-- An order is dense if there is an element between any pair of distinct elements. -/
class densely_ordered (α : Type u) [preorder α] : Prop :=
(dense : ∀a₁ a₂:α, a₁ < a₂ → ∃a, a₁ < a ∧ a < a₂)
lemma dense [preorder α] [densely_ordered α] : ∀{a₁ a₂:α}, a₁ < a₂ → ∃a, a₁ < a ∧ a < a₂ :=
densely_ordered.dense
instance order_dual.densely_ordered (α : Type u) [preorder α] [densely_ordered α] :
densely_ordered (order_dual α) :=
⟨λ a₁ a₂ ha, (@dense α _ _ _ _ ha).imp $ λ a, and.symm⟩
lemma le_of_forall_le_of_dense [linear_order α] [densely_ordered α] {a₁ a₂ : α}
(h : ∀a₃>a₂, a₁ ≤ a₃) :
a₁ ≤ a₂ :=
le_of_not_gt $ assume ha,
let ⟨a, ha₁, ha₂⟩ := dense ha in
lt_irrefl a $ lt_of_lt_of_le ‹a < a₁› (h _ ‹a₂ < a›)
lemma eq_of_le_of_forall_le_of_dense [linear_order α] [densely_ordered α] {a₁ a₂ : α}
(h₁ : a₂ ≤ a₁) (h₂ : ∀a₃>a₂, a₁ ≤ a₃) : a₁ = a₂ :=
le_antisymm (le_of_forall_le_of_dense h₂) h₁
lemma le_of_forall_ge_of_dense [linear_order α] [densely_ordered α] {a₁ a₂ : α}
(h : ∀a₃<a₁, a₂ ≥ a₃) :
a₁ ≤ a₂ :=
le_of_not_gt $ assume ha,
let ⟨a, ha₁, ha₂⟩ := dense ha in
lt_irrefl a $ lt_of_le_of_lt (h _ ‹a < a₁›) ‹a₂ < a›
lemma eq_of_le_of_forall_ge_of_dense [linear_order α] [densely_ordered α] {a₁ a₂ : α}
(h₁ : a₂ ≤ a₁) (h₂ : ∀a₃<a₁, a₂ ≥ a₃) : a₁ = a₂ :=
le_antisymm (le_of_forall_ge_of_dense h₂) h₁
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma dense_or_discrete [linear_order α] (a₁ a₂ : α) :
(∃a, a₁ < a ∧ a < a₂) ∨ ((∀a>a₁, a ≥ a₂) ∧ (∀a<a₂, a ≤ a₁)) :=
classical.or_iff_not_imp_left.2 $ assume h,
⟨assume a ha₁, le_of_not_gt $ assume ha₂, h ⟨a, ha₁, ha₂⟩,
assume a ha₂, le_of_not_gt $ assume ha₁, h ⟨a, ha₁, ha₂⟩⟩
variables {s : β → β → Prop} {t : γ → γ → Prop}
/-- Any `linear_order` is a noncomputable `decidable_linear_order`. This is not marked
as an instance to avoid a loop. -/
noncomputable def classical.DLO (α) [LO : linear_order α] : decidable_linear_order α :=
{ decidable_le := classical.dec_rel _, ..LO }
variable (r)
local infix ` ≼ ` : 50 := r
/-- A family of elements of α is directed (with respect to a relation `≼` on α)
if there is a member of the family `≼`-above any pair in the family. -/
def directed {ι : Sort v} (f : ι → α) := ∀x y, ∃z, f x ≼ f z ∧ f y ≼ f z
/-- A subset of α is directed if there is an element of the set `≼`-above any
pair of elements in the set. -/
def directed_on (s : set α) := ∀ (x ∈ s) (y ∈ s), ∃z ∈ s, x ≼ z ∧ y ≼ z
theorem directed_on_iff_directed {s} : @directed_on α r s ↔ directed r (coe : s → α) :=
by simp [directed, directed_on]; refine ball_congr (λ x hx, by simp; refl)
theorem directed_on_image {s} {f : β → α} :
directed_on r (f '' s) ↔ directed_on (f ⁻¹'o r) s :=
by simp only [directed_on, set.ball_image_iff, set.bex_image_iff, order.preimage]
theorem directed_on.mono {s : set α} (h : directed_on r s)
{r' : α → α → Prop} (H : ∀ {a b}, r a b → r' a b) :
directed_on r' s :=
λ x hx y hy, let ⟨z, zs, xz, yz⟩ := h x hx y hy in ⟨z, zs, H xz, H yz⟩
theorem directed_comp {ι} (f : ι → β) (g : β → α) :
directed r (g ∘ f) ↔ directed (g ⁻¹'o r) f := iff.rfl
variable {r}
theorem directed.mono {s : α → α → Prop} {ι} {f : ι → α}
(H : ∀ a b, r a b → s a b) (h : directed r f) : directed s f :=
λ a b, let ⟨c, h₁, h₂⟩ := h a b in ⟨c, H _ _ h₁, H _ _ h₂⟩
theorem directed.mono_comp {ι} {rb : β → β → Prop} {g : α → β} {f : ι → α}
(hg : ∀ ⦃x y⦄, x ≼ y → rb (g x) (g y)) (hf : directed r f) :
directed rb (g ∘ f) :=
(directed_comp rb f g).2 $ hf.mono hg
section prio
set_option default_priority 100 -- see Note [default priority]
/-- A `preorder` is a `directed_order` if for any two elements `i`, `j`
there is an element `k` such that `i ≤ k` and `j ≤ k`. -/
class directed_order (α : Type u) extends preorder α :=
(directed : ∀ i j : α, ∃ k, i ≤ k ∧ j ≤ k)
end prio
|
3123792f868ec9a775f551f263704a87a1d240d1 | 3984ab8555ab1e1084e22ef652544acdfc231f27 | /src/v0.1/cfr.lean | c1ebea64221908b5b677427ef74a5f6d2160f124 | [] | no_license | mrakgr/CFR-in-Lean | a35c7a478795cc794cc0caff3199cf28c8ee5448 | 720a3260297bcc158e08833d38964450dcaad2eb | refs/heads/master | 1,598,515,917,940 | 1,572,612,355,000 | 1,572,612,355,000 | 217,296,108 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,765 | lean | import helpers
def regret_match {n : nat} (a : array n rat) :=
let sum := a.foldl 0 (fun a s, max a 0 + s) in
if sum = 0 then have v : rat, from 1 / n, array.init n (fun _, v)
else a.map (fun a, max a 0 / sum)
structure Node {𝔸 : Type*} (actions : Σ (n : nat), fin n → 𝔸) := mk ::
(strategy_sum : array actions.1 rat)
(regret_sum : array actions.1 rat)
def Infosets {ℍ : Type*} {𝔸 : ℍ → Type*} [decidable_eq ℍ] (ha : HistoryToActions ℍ 𝔸)
:= buffer (Σ (h : ℍ), Node $ ha h)
def Node_from_actions {𝔸 : Type*} (actions : Actions 𝔸) :=
{Node .
strategy_sum := array.init actions.1 (fun _, 0),
regret_sum := array.init actions.1 (fun _, 0)
}
-- Note: It bothers me a little that `h` and `h'` are not the same thing.
-- It is all because of the way the red black tree does comparison, but for this
-- particular use case, the keys should hold equal.
def response {ℍ : Type*} {𝔸 : ℍ → Type*} [decidable_eq ℍ]
(ha : HistoryToActions ℍ 𝔸)
(is_updateable : bool) (one_probability two_probability : rat) (h : ℍ)
(next : 𝔸 h → rat → state (Infosets ha) rat)
: state (Infosets ha) rat := ⟨ fun infosets,
let (i, node , infosets) := memoize infosets (fun h, Node_from_actions $ ha h) h in
let action_probability := regret_match node.regret_sum in
let ⟨ action_utility, infosets ⟩ :=
actions_map_foldl2 (ha h).2 action_probability
infosets (fun action action_probability infosets,
if action_probability = 0 ∧ two_probability = 0 then (0, infosets) -- the pruning optimization
else (next action (one_probability * action_probability)).run infosets
) in
let action_utility_weighted_sum :=
@nat.foldl.fin (fun i, rat) (ha h).1 0
(fun i s, s + action_utility.read i * action_probability.read i) in
let infosets :=
match is_updateable with
| tt :=
let add (f : ℚ → ℚ) (a b : array (ha h).1 ℚ) := array.map₂ (fun s x, s + f x) a b in
infosets.write' i ⟨ h, {
strategy_sum := add (fun action_probability, one_probability * action_probability) node.strategy_sum action_probability,
regret_sum := add (fun action_utility, two_probability * (action_utility - action_utility_weighted_sum)) node.regret_sum action_utility
}⟩
| ff := infosets
end in
(-action_utility_weighted_sum, infosets)
⟩
def chance {ℍ Δ : Type*} {𝔸 : ℍ → Type*} [decidable_eq ℍ]
(ha : HistoryToActions ℍ 𝔸)
(dice : Σ n, fin n → rat × Δ)
(one_probability : rat)
(next : Δ → rat → state (Infosets ha) rat)
: state (Infosets ha) rat := ⟨ fun infosets,
actions_foldl dice ((0 : rat), infosets) (
fun ⟨ dice_probability, dice⟩ ⟨ util_sum, infosets ⟩ ,
let (util, infosets) := (next dice (one_probability * dice_probability)).run infosets in
(util_sum + util * dice_probability, infosets)
)
⟩
def chance_uniform {ℍ Δ : Type*} {𝔸 : ℍ → Type*} [decidable_eq ℍ]
(ha : HistoryToActions ℍ 𝔸)
(dice : Actions Δ)
(one_probability : rat)
(next : Δ → rat → state (Infosets ha) rat)
: state (Infosets ha) rat :=
let dice_probability := 1 / dice.1 in
chance ha ⟨ dice.1 , fun i, ⟨ dice_probability, dice.2 i ⟩ ⟩ one_probability next
def terminal {ℍ : Type*} {𝔸 : ℍ → Type*} [decidable_eq ℍ]
(ha : HistoryToActions ℍ 𝔸)
(reward : rat)
: state (Infosets ha) rat := pure reward |
cb482e094a18da72fa764f979b3b8a91d23b264a | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/algebra/ring/default.lean | 2457a19007fc9a01852e3301de9c666490e88da5 | [] | 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 | 288 | lean | /-
Copyright (c) 2020 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.ring.basic
import Mathlib.PostPort
namespace Mathlib
|
7375e6d8cab7634ad19f0f65467bb4a0b9597ba6 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/evalWithMVar.lean | 04d4a7131bb0355d9c96c70e84b38b006dde8af9 | [
"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 | 251 | lean |
def c {α} : Sum α Nat :=
Sum.inr 10
def Sum.someRight {α β} (s : Sum α β) : Option β :=
match s with
| Sum.inl _ => none
| Sum.inr b => some b
#check Sum.someRight c
#eval Sum.someRight c
#check Sum.someRight (s := c)
#check c.someRight
|
dd02b47d81a5ed6b56f623ceab98cd5dea7d61e0 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/analysis/box_integral/partition/measure.lean | eaa177011ee6b41245cf4586161256c15bdf9dd2 | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,733 | lean | /-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import analysis.box_integral.partition.additive
import measure_theory.measure.lebesgue
/-!
# Box-additive functions defined by measures
In this file we prove a few simple facts about rectangular boxes, partitions, and measures:
- given a box `I : box ι`, its coercion to `set (ι → ℝ)` and `I.Icc` are measurable sets;
- if `μ` is a locally finite measure, then `(I : set (ι → ℝ))` and `I.Icc` have finite measure;
- if `μ` is a locally finite measure, then `λ J, (μ J).to_real` is a box additive function.
For the last statement, we both prove it as a proposition and define a bundled
`box_integral.box_additive` function.
### Tags
rectangular box, measure
-/
open set
noncomputable theory
open_locale ennreal big_operators classical box_integral
variables {ι : Type*}
namespace box_integral
open measure_theory
namespace box
variables (I : box ι)
lemma measurable_set_coe [fintype ι] (I : box ι) : measurable_set (I : set (ι → ℝ)) :=
begin
rw [coe_eq_pi],
haveI := fintype.encodable ι,
exact measurable_set.univ_pi (λ i, measurable_set_Ioc)
end
lemma measurable_set_Icc [fintype ι] (I : box ι) : measurable_set I.Icc := measurable_set_Icc
lemma measure_Icc_lt_top (μ : measure (ι → ℝ)) [is_locally_finite_measure μ] : μ I.Icc < ∞ :=
show μ (Icc I.lower I.upper) < ∞, from I.is_compact_Icc.measure_lt_top
lemma measure_coe_lt_top (μ : measure (ι → ℝ)) [is_locally_finite_measure μ] : μ I < ∞ :=
(measure_mono $ coe_subset_Icc).trans_lt (I.measure_Icc_lt_top μ)
end box
lemma prepartition.measure_Union_to_real [fintype ι] {I : box ι} (π : prepartition I)
(μ : measure (ι → ℝ)) [is_locally_finite_measure μ] :
(μ π.Union).to_real = ∑ J in π.boxes, (μ J).to_real :=
begin
erw [← ennreal.to_real_sum, π.Union_def, measure_bUnion_finset π.pairwise_disjoint],
exacts [λ J hJ, J.measurable_set_coe, λ J hJ, (J.measure_coe_lt_top μ).ne]
end
end box_integral
open box_integral box_integral.box
variables [fintype ι]
namespace measure_theory
namespace measure
/-- If `μ` is a locally finite measure on `ℝⁿ`, then `λ J, (μ J).to_real` is a box-additive
function. -/
@[simps] def to_box_additive (μ : measure (ι → ℝ)) [is_locally_finite_measure μ] :
ι →ᵇᵃ[⊤] ℝ :=
{ to_fun := λ J, (μ J).to_real,
sum_partition_boxes' := λ J hJ π hπ, by rw [← π.measure_Union_to_real, hπ.Union_eq] }
end measure
end measure_theory
namespace box_integral
open measure_theory
namespace box
@[simp] lemma volume_apply (I : box ι) :
(volume : measure (ι → ℝ)).to_box_additive I = ∏ i, (I.upper i - I.lower i) :=
by rw [measure.to_box_additive_apply, coe_eq_pi, real.volume_pi_Ioc_to_real I.lower_le_upper]
lemma volume_face_mul {n} (i : fin (n + 1)) (I : box (fin (n + 1))) :
(∏ j, ((I.face i).upper j - (I.face i).lower j)) * (I.upper i - I.lower i) =
∏ j, (I.upper j - I.lower j) :=
by simp only [face_lower, face_upper, (∘), fin.prod_univ_succ_above _ i, mul_comm]
end box
namespace box_additive_map
/-- Box-additive map sending each box `I` to the continuous linear endomorphism
`x ↦ (volume I).to_real • x`. -/
protected def volume {E : Type*} [normed_group E] [normed_space ℝ E] :
ι →ᵇᵃ (E →L[ℝ] E) :=
(volume : measure (ι → ℝ)).to_box_additive.to_smul
lemma volume_apply {E : Type*} [normed_group E] [normed_space ℝ E] (I : box ι) (x : E) :
box_additive_map.volume I x = (∏ j, (I.upper j - I.lower j)) • x :=
congr_arg2 (•) I.volume_apply rfl
end box_additive_map
end box_integral
|
7507d7644a950c530238fa06ff5a1fd4d64441c6 | a4673261e60b025e2c8c825dfa4ab9108246c32e | /stage0/src/Lean/Parser/Term.lean | 79b4050782d4a9f686430e120e203fc8f00c3ed1 | [
"Apache-2.0"
] | permissive | jcommelin/lean4 | c02dec0cc32c4bccab009285475f265f17d73228 | 2909313475588cc20ac0436e55548a4502050d0a | refs/heads/master | 1,674,129,550,893 | 1,606,415,348,000 | 1,606,415,348,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,860 | 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, Sebastian Ullrich
-/
import Lean.Parser.Basic
import Lean.Parser.Level
namespace Lean
namespace Parser
builtin_initialize
registerBuiltinParserAttribute `builtinTacticParser `tactic (leadingIdentAsSymbol := true)
registerBuiltinDynamicParserAttribute `tacticParser `tactic
@[inline] def tacticParser (rbp : Nat := 0) : Parser :=
categoryParser `tactic rbp
namespace Tactic
def tacticSeq1Indented : Parser :=
parser! many1Indent (group (ppLine >> tacticParser >> optional ";"))
def tacticSeqBracketed : Parser :=
parser! "{" >> many (group (ppLine >> tacticParser >> optional ";")) >> ppDedent (ppLine >> "}")
def tacticSeq :=
nodeWithAntiquot "tacticSeq" `Lean.Parser.Tactic.tacticSeq $ tacticSeqBracketed <|> tacticSeq1Indented
/- Raw sequence for quotation and grouping -/
def seq1 :=
node `Lean.Parser.Tactic.seq1 $ sepBy1 tacticParser ";\n" true
end Tactic
def darrow : Parser := " => "
namespace Term
/- Built-in parsers -/
@[builtinTermParser] def byTactic := parser!:leadPrec "by " >> Tactic.tacticSeq
def optSemicolon (p : Parser) : Parser := ppDedent $ optional ";" >> ppLine >> p
-- `checkPrec` necessary for the pretty printer
@[builtinTermParser] def ident := checkPrec maxPrec >> Parser.ident
@[builtinTermParser] def num : Parser := checkPrec maxPrec >> numLit
@[builtinTermParser] def str : Parser := checkPrec maxPrec >> strLit
@[builtinTermParser] def char : Parser := checkPrec maxPrec >> charLit
@[builtinTermParser] def type := parser! "Type" >> optional (checkWsBefore "" >> checkPrec leadPrec >> levelParser maxPrec)
@[builtinTermParser] def sort := parser! "Sort" >> optional (checkWsBefore "" >> checkPrec leadPrec >> levelParser maxPrec)
@[builtinTermParser] def prop := parser! "Prop"
@[builtinTermParser] def hole := parser! "_"
@[builtinTermParser] def syntheticHole := parser! "?" >> (ident <|> hole)
@[builtinTermParser] def «sorry» := parser! "sorry"
@[builtinTermParser] def cdot := parser! "·" <|> "."
@[builtinTermParser] def emptyC := parser! "∅" <|> ("{" >> "}")
def typeAscription := parser! " : " >> termParser
def tupleTail := parser! ", " >> sepBy1 termParser ", "
def parenSpecial : Parser := optional (tupleTail <|> typeAscription)
@[builtinTermParser] def paren := parser! "(" >> ppDedent (withoutPosition (withoutForbidden (optional (termParser >> parenSpecial)))) >> ")"
@[builtinTermParser] def anonymousCtor := parser! "⟨" >> sepBy termParser ", " >> "⟩"
def optIdent : Parser := optional (atomic (ident >> " : "))
def fromTerm := parser! " from " >> termParser
def haveAssign := parser! " := " >> termParser
def haveDecl := optIdent >> termParser >> (haveAssign <|> fromTerm <|> byTactic)
@[builtinTermParser] def «have» := parser!:leadPrec withPosition ("have " >> haveDecl) >> optSemicolon termParser
def sufficesDecl := optIdent >> termParser >> (fromTerm <|> byTactic)
@[builtinTermParser] def «suffices» := parser!:leadPrec withPosition ("suffices " >> sufficesDecl) >> optSemicolon termParser
@[builtinTermParser] def «show» := parser!:leadPrec "show " >> termParser >> (fromTerm <|> byTactic)
def structInstArrayRef := parser! "[" >> termParser >>"]"
def structInstLVal := (ident <|> fieldIdx <|> structInstArrayRef) >> many (group ("." >> (ident <|> fieldIdx)) <|> structInstArrayRef)
def structInstField := ppGroup $ parser! structInstLVal >> " := " >> termParser
@[builtinTermParser] def structInst := parser! "{" >> ppHardSpace >> optional (atomic (termParser >> " with "))
>> manyIndent (group (structInstField >> optional ", "))
>> optional ".."
>> optional (" : " >> termParser) >> " }"
def typeSpec := parser! " : " >> termParser
def optType : Parser := optional typeSpec
@[builtinTermParser] def explicit := parser! "@" >> termParser maxPrec
@[builtinTermParser] def inaccessible := parser! ".(" >> termParser >> ")"
def binderIdent : Parser := ident <|> hole
def binderType (requireType := false) : Parser := if requireType then group (" : " >> termParser) else optional (" : " >> termParser)
def binderTactic := parser! atomic (" := " >> " by ") >> Tactic.tacticSeq
def binderDefault := parser! " := " >> termParser
def explicitBinder (requireType := false) := ppGroup $ parser! "(" >> many1 binderIdent >> binderType requireType >> optional (binderTactic <|> binderDefault) >> ")"
def implicitBinder (requireType := false) := ppGroup $ parser! "{" >> many1 binderIdent >> binderType requireType >> "}"
def instBinder := ppGroup $ parser! "[" >> optIdent >> termParser >> "]"
def bracketedBinder (requireType := false) := explicitBinder requireType <|> implicitBinder requireType <|> instBinder
/-
It is feasible to support dependent arrows such as `{α} → α → α` without sacrificing the quality of the error messages for the longer case.
`{α} → α → α` would be short for `{α : Type} → α → α`
Here is the encoding:
```
def implicitShortBinder := node `Lean.Parser.Term.implicitBinder $ "{" >> many1 binderIdent >> pushNone >> "}"
def depArrowShortPrefix := try (implicitShortBinder >> unicodeSymbol " → " " -> ")
def depArrowLongPrefix := bracketedBinder true >> unicodeSymbol " → " " -> "
def depArrowPrefix := depArrowShortPrefix <|> depArrowLongPrefix
@[builtinTermParser] def depArrow := parser! depArrowPrefix >> termParser
```
Note that no changes in the elaborator are needed.
We decided to not use it because terms such as `{α} → α → α` may look too cryptic.
Note that we did not add a `explicitShortBinder` parser since `(α) → α → α` is really cryptic as a short for `(α : Type) → α → α`.
-/
@[builtinTermParser] def depArrow := parser!:25 bracketedBinder true >> unicodeSymbol " → " " -> " >> termParser
def simpleBinder := parser! many1 binderIdent >> optType
@[builtinTermParser]
def «forall» := parser!:leadPrec unicodeSymbol "∀ " "forall" >> many1 (ppSpace >> (simpleBinder <|> bracketedBinder)) >> ", " >> termParser
def matchAlt : Parser :=
nodeWithAntiquot "matchAlt" `Lean.Parser.Term.matchAlt $
sepBy1 termParser ", " >> darrow >> termParser
def matchAlts (optionalFirstBar := true) : Parser :=
parser! ppDedent $ withPosition $
ppLine >> (if optionalFirstBar then optional "| " else "| ") >>
sepBy1 (ppIndent matchAlt) (ppLine >> checkColGe "alternatives must be indented" >> "| ")
def matchDiscr := parser! optional (atomic (ident >> checkNoWsBefore "no space before ':'" >> ":")) >> termParser
@[builtinTermParser] def «match» := parser!:leadPrec "match " >> sepBy1 matchDiscr ", " >> optType >> " with " >> matchAlts
@[builtinTermParser] def «nomatch» := parser!:leadPrec "nomatch " >> termParser
def funImplicitBinder := atomic (lookahead ("{" >> many1 binderIdent >> (" : " <|> "}"))) >> implicitBinder
def funSimpleBinder := atomic (lookahead (many1 binderIdent >> " : ")) >> simpleBinder
def funBinder : Parser := funImplicitBinder <|> instBinder <|> funSimpleBinder <|> termParser maxPrec
-- NOTE: we use `nodeWithAntiquot` to ensure that `fun $b => ...` remains a `term` antiquotation
def basicFun : Parser := nodeWithAntiquot "basicFun" `Lean.Parser.Term.basicFun (many1 (ppSpace >> funBinder) >> darrow >> termParser)
@[builtinTermParser] def «fun» := parser!:maxPrec unicodeSymbol "λ" "fun" >> (basicFun <|> matchAlts false)
def optExprPrecedence := optional (atomic ":" >> termParser maxPrec)
@[builtinTermParser] def «parser!» := parser!:leadPrec "parser! " >> optExprPrecedence >> termParser
@[builtinTermParser] def «tparser!» := parser!:leadPrec "tparser! " >> optExprPrecedence >> termParser
@[builtinTermParser] def borrowed := parser! "@&" >> termParser leadPrec
@[builtinTermParser] def quotedName := parser! nameLit
-- NOTE: syntax quotations are defined in Init.Lean.Parser.Command
@[builtinTermParser] def «match_syntax» := parser!:leadPrec "match_syntax" >> termParser >> " with " >> matchAlts
def simpleBinderWithoutType := node `Lean.Parser.Term.simpleBinder (many1 binderIdent >> pushNone)
/- Remark: we use `checkWsBefore` to ensure `let x[i] := e; b` is not parsed as `let x [i] := e; b` where `[i]` is an `instBinder`. -/
def letIdLhs : Parser := ident >> checkWsBefore "expected space before binders" >> many (ppSpace >> (simpleBinderWithoutType <|> bracketedBinder)) >> optType
def letIdDecl := node `Lean.Parser.Term.letIdDecl $ atomic (letIdLhs >> " := ") >> termParser
def letPatDecl := node `Lean.Parser.Term.letPatDecl $ atomic (termParser >> pushNone >> optType >> " := ") >> termParser
def letEqnsDecl := node `Lean.Parser.Term.letEqnsDecl $ letIdLhs >> matchAlts false
-- Remark: we use `nodeWithAntiquot` here to make sure anonymous antiquotations (e.g., `$x`) are not `letDecl`
def letDecl := nodeWithAntiquot "letDecl" `Lean.Parser.Term.letDecl (notFollowedBy (nonReservedSymbol "rec") "rec" >> (letIdDecl <|> letPatDecl <|> letEqnsDecl))
@[builtinTermParser] def «let» := parser!:leadPrec withPosition ("let " >> letDecl) >> optSemicolon termParser
@[builtinTermParser] def «let!» := parser!:leadPrec withPosition ("let! " >> letDecl) >> optSemicolon termParser
@[builtinTermParser] def «let*» := parser!:leadPrec withPosition ("let* " >> letDecl) >> optSemicolon termParser
def attrArg : Parser := ident <|> strLit <|> numLit
-- use `rawIdent` because of attribute names such as `instance`
def attrInstance := ppGroup $ parser! rawIdent >> many (ppSpace >> attrArg)
def attributes := parser! "@[" >> sepBy1 attrInstance ", " >> "]"
def letRecDecls := sepBy1 (group (optional «attributes» >> letDecl)) ", "
@[builtinTermParser]
def «letrec» := parser!:leadPrec withPosition (group ("let " >> nonReservedSymbol "rec ") >> letRecDecls) >> optSemicolon termParser
@[runBuiltinParserAttributeHooks]
def whereDecls := parser! "where " >> many1Indent (group (optional «attributes» >> letDecl >> optional ";"))
@[runBuiltinParserAttributeHooks]
def matchAltsWhereDecls := parser! matchAlts false >> optional whereDecls
@[builtinTermParser] def nativeRefl := parser! "nativeRefl! " >> termParser maxPrec
@[builtinTermParser] def nativeDecide := parser! "nativeDecide!"
@[builtinTermParser] def decide := parser! "decide!"
@[builtinTermParser] def typeOf := parser! "typeOf! " >> termParser maxPrec
@[builtinTermParser] def ensureTypeOf := parser! "ensureTypeOf! " >> termParser maxPrec >> strLit >> termParser
@[builtinTermParser] def ensureExpectedType := parser! "ensureExpectedType! " >> strLit >> termParser maxPrec
@[builtinTermParser] def not := parser! "¬" >> termParser 40
@[builtinTermParser] def bnot := parser! "!" >> termParser 40
-- symbol precedence should be higher, but must match the one of `sub` below
@[builtinTermParser] def uminus := parser!:65 "-" >> termParser 100
def namedArgument := parser! atomic ("(" >> ident >> " := ") >> termParser >> ")"
def ellipsis := parser! ".."
@[builtinTermParser] def app := tparser!:(maxPrec-1) many1 $
checkWsBefore "expected space" >>
checkColGt "expected to be indented" >>
(namedArgument <|> ellipsis <|> termParser maxPrec)
@[builtinTermParser] def proj := tparser! checkNoWsBefore >> "." >> (fieldIdx <|> ident)
@[builtinTermParser] def arrayRef := tparser! checkNoWsBefore >> "[" >> termParser >>"]"
@[builtinTermParser] def arrow := tparser! checkPrec 25 >> unicodeSymbol " → " " -> " >> termParser 25
def isIdent (stx : Syntax) : Bool :=
-- antiquotations should also be allowed where an identifier is expected
stx.isAntiquot || stx.isIdent
@[builtinTermParser] def explicitUniv : TrailingParser := tparser! checkStackTop isIdent "expected preceding identifier" >> checkNoWsBefore "no space before '.{'" >> ".{" >> sepBy1 levelParser ", " >> "}"
@[builtinTermParser] def namedPattern : TrailingParser := tparser! checkStackTop isIdent "expected preceding identifier" >> checkNoWsBefore "no space before '@'" >> "@" >> termParser maxPrec
@[builtinTermParser] def pipeProj := tparser!:0 " |>. " >> (fieldIdx <|> ident)
@[builtinTermParser] def subst := tparser!:75 " ▸ " >> sepBy1 (termParser 75) " ▸ "
@[builtinTermParser] def funBinder.quot : Parser := parser! "`(funBinder|" >> toggleInsideQuot funBinder >> ")"
@[builtinTermParser] def panic := parser!:leadPrec "panic! " >> termParser
@[builtinTermParser] def unreachable := parser!:leadPrec "unreachable!"
@[builtinTermParser] def dbgTrace := parser!:leadPrec withPosition ("dbgTrace! " >> ((interpolatedStr termParser) <|> termParser)) >> optSemicolon termParser
@[builtinTermParser] def assert := parser!:leadPrec withPosition ("assert! " >> termParser) >> optSemicolon termParser
def macroArg := termParser maxPrec
def macroDollarArg := parser! "$" >> termParser 0
def macroLastArg := macroDollarArg <|> macroArg
-- Macro for avoiding exponentially big terms when using `STWorld`
@[builtinTermParser] def stateRefT := parser! "StateRefT" >> macroArg >> macroLastArg
end Term
@[builtinTermParser 1] def Tactic.quot : Parser := parser! "`(tactic|" >> toggleInsideQuot tacticParser >> ")"
@[builtinTermParser] def Tactic.quotSeq : Parser := parser! "`(tactic|" >> toggleInsideQuot Tactic.seq1 >> ")"
@[builtinTermParser] def Level.quot : Parser := parser! "`(level|" >> toggleInsideQuot levelParser >> ")"
builtin_initialize
registerParserAlias! "letDecl" Term.letDecl
registerParserAlias! "haveDecl" Term.haveDecl
registerParserAlias! "sufficesDecl" Term.sufficesDecl
registerParserAlias! "letRecDecls" Term.letRecDecls
registerParserAlias! "hole" Term.hole
registerParserAlias! "syntheticHole" Term.syntheticHole
registerParserAlias! "matchDiscr" Term.matchDiscr
end Parser
end Lean
|
a0b6c8ff4a40f429667f7b7294905fe8715f8a49 | 649957717d58c43b5d8d200da34bf374293fe739 | /src/data/rat/denumerable.lean | 57bf6b06c392502015c0850859e27d588188ede5 | [
"Apache-2.0"
] | permissive | Vtec234/mathlib | b50c7b21edea438df7497e5ed6a45f61527f0370 | fb1848bbbfce46152f58e219dc0712f3289d2b20 | refs/heads/master | 1,592,463,095,113 | 1,562,737,749,000 | 1,562,737,749,000 | 196,202,858 | 0 | 0 | Apache-2.0 | 1,562,762,338,000 | 1,562,762,337,000 | null | UTF-8 | Lean | false | false | 1,061 | lean | /-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Chris Hughes
-/
import data.rat.basic set_theory.cardinal
namespace rat
open denumerable
instance : infinite ℚ :=
infinite.of_injective (coe : ℕ → ℚ) nat.cast_injective
private def denumerable_aux : ℚ ≃ { x : ℤ × ℕ // 0 < x.2 ∧ x.1.nat_abs.coprime x.2 } :=
{ to_fun := λ x, ⟨⟨x.1, x.2⟩, x.3, x.4⟩,
inv_fun := λ x, ⟨x.1.1, x.1.2, x.2.1, x.2.2⟩,
left_inv := λ ⟨_, _, _, _⟩, rfl,
right_inv := λ ⟨⟨_, _⟩, _, _⟩, rfl }
instance : denumerable ℚ :=
begin
let T := { x : ℤ × ℕ // 0 < x.2 ∧ x.1.nat_abs.coprime x.2 },
letI : infinite T := infinite.of_injective _ denumerable_aux.injective,
letI : encodable T := encodable.subtype,
letI : denumerable T := of_encodable_of_infinite T,
exact denumerable.of_equiv T denumerable_aux
end
end rat
namespace cardinal
lemma mk_rat : cardinal.mk ℚ = omega :=
denumerable_iff.mp ⟨by apply_instance⟩
end cardinal
|
a4226735d4d4bc08f48a25c8f9649c051930ce91 | a46270e2f76a375564f3b3e9c1bf7b635edc1f2c | /4.6.5.lean | 9ea4ba61ba79967e488d7b872f04713fb1623859 | [
"CC0-1.0"
] | permissive | wudcscheme/lean-exercise | 88ea2506714eac343de2a294d1132ee8ee6d3a20 | 5b23b9be3d361fff5e981d5be3a0a1175504b9f6 | refs/heads/master | 1,678,958,930,293 | 1,583,197,205,000 | 1,583,197,205,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,727 | lean | open classical
variables (α : Type) (p q : α → Prop)
variable a : α
variable r : Prop
example : (∃ x : α, r) → r :=
assume h: (∃ x: α, r),
match h with ⟨w, hr⟩ := hr end
example : r → (∃ x : α, r) :=
assume hr: r,
⟨a, hr⟩
example : (∃ x, p x ∧ r) ↔ (∃ x, p x) ∧ r := ⟨
assume h: (∃ x, p x ∧ r),
let ⟨w, c⟩ := h in ⟨
⟨w, c.left⟩,
c.right
⟩,
assume h: (∃ x, p x) ∧ r,
let ⟨w, pw⟩ := h.left in ⟨w, pw, h.right⟩
⟩
example : (∃ x, p x ∨ q x) ↔ (∃ x, p x) ∨ (∃ x, q x) := ⟨
assume h: (∃ x, p x ∨ q x),
let ⟨w, dw⟩ := h in
show (∃ x, p x) ∨ (∃ x, q x), from or.elim dw (
λ hpw: p w, or.inl ⟨w, hpw⟩
) (
λ hqw: q w, or.inr ⟨w, hqw⟩
),
assume h: (∃ x, p x) ∨ (∃ x, q x),
show (∃ x, p x ∨ q x), from or.elim h (
λ hpx, let ⟨w, pw⟩ := hpx in ⟨w, or.inl pw⟩
) (
λ hqx, let ⟨w, qw⟩ := hqx in ⟨w, or.inr qw⟩
)
⟩
example : (∀ x, p x) ↔ ¬ (∃ x, ¬ p x) := ⟨
assume h: (∀ x, p x),
show ¬ (∃ x, ¬ p x), from (
assume hnpx: ∃ x, (p x -> false),
let ⟨w, hnpw⟩ := hnpx in
have pw: p w, from h w,
show false, from hnpw pw
),
assume h: ¬ (∃ x, ¬ p x),
show ∀ x, p x, from
assume y: α,
show p y, from by_contradiction (
assume h1: ¬ p y,
have h2: (∃ x, ¬ p x), from ⟨y, h1⟩,
h h2
)
⟩
example : (∃ x, p x) ↔ ¬ (∀ x, ¬ p x) := ⟨
assume h: ∃ x, p x,
show ¬ (∀ x, ¬ p x), from (
let ⟨w, hpw⟩ := h in
λ hnpx: ∀ x, ¬ p x, hnpx w hpw
),
assume h: ¬ (∀ x, ¬ p x),
show ∃ x, p x, from by_contradiction (
assume h1: ¬ (∃ x, p x),
have h2: ∀ x, ¬ p x, from (
assume y: α,
show p y -> false, from
assume hpy: p y,
have hpx: ∃ x, p x, from ⟨y, hpy⟩,
h1 hpx
),
h h2
)
⟩
example : (¬ ∃ x, p x) ↔ (∀ x, ¬ p x) := ⟨
assume h: ¬ ∃ x, p x,
show ∀ x, ¬ p x, from (
assume y: α,
show p y -> false, from
assume hpy: p y,
h ⟨y, hpy⟩
),
assume h: ∀ x, ¬ p x,
show ¬ ∃ x, p x, from (
assume hpx: ∃ x, p x,
let ⟨w, hpw⟩ := hpx in
h w hpw
),
⟩
example : (¬ ∀ x, p x) ↔ (∃ x, ¬ p x) := ⟨
assume h: ¬ ∀ x, p x,
show ∃ x, ¬ p x, from by_contradiction (
assume h1: ¬ ∃ x, ¬ p x,
have hpx: ∀ x, p x, from (
assume y: α,
show p y, from by_contradiction (
assume hnpy: ¬ p y,
h1 ⟨y, hnpy⟩
)
),
h hpx
),
assume h: ∃ x, ¬ p x,
show ¬ ∀ x, p x, from (
let ⟨w, hnpw⟩ := h in
assume h1: ∀ x, p x,
have hpw: p w, from h1 w,
show false, from hnpw hpw
),
⟩
example : (∀ x, p x → r) ↔ (∃ x, p x) → r := ⟨
assume h: ∀ x, p x → r,
show (∃ x, p x) → r, from (
assume h1: ∃ x, p x,
let ⟨y, hpy⟩ := h1 in
have h2: p y -> r, from h y,
show r, from h2 hpy
),
assume h: (∃ x, p x) → r,
show ∀ x, p x -> r, from (
assume y: α,
show p y -> r, from (
assume hpy: p y,
have hpx: ∃ x, p x, from ⟨y, hpy⟩,
show r, from h hpx
)
),
⟩
example : (∃ x, p x → r) ↔ (∀ x, p x) → r := ⟨
assume h: ∃ x, p x → r,
show (∀ x, p x) → r, from (
assume hpx: ∀ x, p x,
let ⟨w, hw⟩ := h in
have hpw: p w, from hpx w,
hw hpw
),
assume h: (∀ x, p x) → r,
show ∃ x, p x → r, from by_cases (
assume hp: ∀ x, p x,
have hr: r, from h hp,
have himp: p a -> r, from λ _, hr,
⟨a, himp⟩
) (
assume hnp: ¬ ∀ x, p x,
have hnp': ∃ x, ¬ p x, from by_contradiction (
assume h1: ¬ ∃ x, ¬ p x,
have hpx: ∀ x, p x, from (
assume y: α,
show p y, from by_contradiction (
assume hnpy: ¬ p y,
h1 ⟨y, hnpy⟩
)
),
hnp hpx
),
let ⟨w, hnpw⟩ := hnp' in
⟨w, λ hpx, absurd hpx hnpw⟩
),
⟩
example : (∃ x, r → p x) ↔ (r → ∃ x, p x) := ⟨
assume h: ∃ x, r → p x,
show r → ∃ x, p x, from (
assume hr: r,
let ⟨w, himp⟩ := h in
have hpw: p w, from himp hr,
⟨w, hpw⟩
),
assume h: r → ∃ x, p x,
show ∃ x, r → p x, from by_cases (
assume hr: r,
let ⟨w, hpw⟩ := h hr in
⟨w, λ _, hpw⟩
) (
assume hnr: ¬ r,
⟨a, λ hr: r, absurd hr hnr⟩
),
⟩
|
ab543f5a0e3934db261d3b9efe67a32acf7f0e59 | 77c5b91fae1b966ddd1db969ba37b6f0e4901e88 | /src/data/nat/modeq.lean | 6bd6fe2e85b00a11e87513b90b6ae88a8343dccc | [
"Apache-2.0"
] | permissive | dexmagic/mathlib | ff48eefc56e2412429b31d4fddd41a976eb287ce | 7a5d15a955a92a90e1d398b2281916b9c41270b2 | refs/heads/master | 1,693,481,322,046 | 1,633,360,193,000 | 1,633,360,193,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 15,690 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.int.gcd
import data.list.rotate
import tactic.abel
/-!
# Congruences modulo a natural number
This file defines the equivalence relation `a ≡ b [MOD n]` on the natural numbers,
and proves basic properties about it such as the Chinese Remainder Theorem
`modeq_and_modeq_iff_modeq_mul`.
## Notations
`a ≡ b [MOD n]` is notation for `nat.modeq n a b`, which is defined to mean `a % n = b % n`.
## Tags
modeq, congruence, mod, MOD, modulo
-/
namespace nat
/-- Modular equality. `n.modeq a b`, or `a ≡ b [MOD n]`, means that `a - b` is a multiple of `n`. -/
@[derive decidable]
def modeq (n a b : ℕ) := a % n = b % n
notation a ` ≡ `:50 b ` [MOD `:50 n `]`:0 := modeq n a b
variables {m n a b c d : ℕ}
namespace modeq
@[refl] protected theorem refl (a : ℕ) : a ≡ a [MOD n] := @rfl _ _
protected theorem rfl : a ≡ a [MOD n] := modeq.refl _
@[symm] protected theorem symm : a ≡ b [MOD n] → b ≡ a [MOD n] := eq.symm
@[trans] protected theorem trans : a ≡ b [MOD n] → b ≡ c [MOD n] → a ≡ c [MOD n] := eq.trans
protected theorem comm : a ≡ b [MOD n] ↔ b ≡ a [MOD n] := ⟨modeq.symm, modeq.symm⟩
end modeq
theorem modeq_zero_iff_dvd : a ≡ 0 [MOD n] ↔ n ∣ a :=
by rw [modeq, zero_mod, dvd_iff_mod_eq_zero]
lemma _root_.has_dvd.dvd.modeq_zero_nat (h : n ∣ a) : a ≡ 0 [MOD n] := modeq_zero_iff_dvd.2 h
lemma _root_.has_dvd.dvd.zero_modeq_nat (h : n ∣ a) : 0 ≡ a [MOD n] := h.modeq_zero_nat.symm
theorem modeq_iff_dvd : a ≡ b [MOD n] ↔ (n:ℤ) ∣ b - a :=
by rw [modeq, eq_comm, ← int.coe_nat_inj', int.coe_nat_mod, int.coe_nat_mod,
int.mod_eq_mod_iff_mod_sub_eq_zero, int.dvd_iff_mod_eq_zero]
protected theorem modeq.dvd : a ≡ b [MOD n] → (n:ℤ) ∣ b - a := modeq_iff_dvd.1
theorem modeq_of_dvd : (n:ℤ) ∣ b - a → a ≡ b [MOD n] := modeq_iff_dvd.2
/-- A variant of `modeq_iff_dvd` with `nat` divisibility -/
theorem modeq_iff_dvd' (h : a ≤ b) : a ≡ b [MOD n] ↔ n ∣ b - a :=
by rw [modeq_iff_dvd, ←int.coe_nat_dvd, int.coe_nat_sub h]
theorem mod_modeq (a n) : a % n ≡ a [MOD n] := mod_mod _ _
namespace modeq
protected theorem modeq_of_dvd (d : m ∣ n) (h : a ≡ b [MOD n]) : a ≡ b [MOD m] :=
modeq_of_dvd ((int.coe_nat_dvd.2 d).trans h.dvd)
protected theorem mul_left' (c : ℕ) (h : a ≡ b [MOD n]) : c * a ≡ c * b [MOD (c * n)] :=
by unfold modeq at *; rw [mul_mod_mul_left, mul_mod_mul_left, h]
protected theorem mul_left (c : ℕ) (h : a ≡ b [MOD n]) : c * a ≡ c * b [MOD n] :=
(h.mul_left' _ ).modeq_of_dvd (dvd_mul_left _ _)
protected theorem mul_right' (c : ℕ) (h : a ≡ b [MOD n]) : a * c ≡ b * c [MOD (n * c)] :=
by rw [mul_comm a, mul_comm b, mul_comm n]; exact h.mul_left' c
protected theorem mul_right (c : ℕ) (h : a ≡ b [MOD n]) : a * c ≡ b * c [MOD n] :=
by rw [mul_comm a, mul_comm b]; exact h.mul_left c
protected theorem mul (h₁ : a ≡ b [MOD n]) (h₂ : c ≡ d [MOD n]) : a * c ≡ b * d [MOD n] :=
(h₂.mul_left _ ).trans (h₁.mul_right _)
protected theorem pow (m : ℕ) (h : a ≡ b [MOD n]) : a ^ m ≡ b ^ m [MOD n] :=
begin
induction m with d hd, {refl},
rw [pow_succ, pow_succ],
exact h.mul hd,
end
protected theorem add (h₁ : a ≡ b [MOD n]) (h₂ : c ≡ d [MOD n]) : a + c ≡ b + d [MOD n] :=
begin
rw [modeq_iff_dvd, int.coe_nat_add, int.coe_nat_add, add_sub_comm],
exact dvd_add h₁.dvd h₂.dvd,
end
protected theorem add_left (c : ℕ) (h : a ≡ b [MOD n]) : c + a ≡ c + b [MOD n] :=
modeq.rfl.add h
protected theorem add_right (c : ℕ) (h : a ≡ b [MOD n]) : a + c ≡ b + c [MOD n] :=
h.add modeq.rfl
protected theorem add_left_cancel (h₁ : a ≡ b [MOD n]) (h₂ : a + c ≡ b + d [MOD n]) :
c ≡ d [MOD n] :=
begin
simp only [modeq_iff_dvd, int.coe_nat_add] at *,
rw add_sub_comm at h₂,
convert _root_.dvd_sub h₂ h₁ using 1,
rw add_sub_cancel',
end
protected theorem add_left_cancel' (c : ℕ) (h : c + a ≡ c + b [MOD n]) : a ≡ b [MOD n] :=
modeq.rfl.add_left_cancel h
protected theorem add_right_cancel (h₁ : c ≡ d [MOD n]) (h₂ : a + c ≡ b + d [MOD n]) :
a ≡ b [MOD n] :=
by { rw [add_comm a, add_comm b] at h₂, exact h₁.add_left_cancel h₂ }
protected theorem add_right_cancel' (c : ℕ) (h : a + c ≡ b + c [MOD n]) : a ≡ b [MOD n] :=
modeq.rfl.add_right_cancel h
theorem of_modeq_mul_left (m : ℕ) (h : a ≡ b [MOD m * n]) : a ≡ b [MOD n] :=
by { rw [modeq_iff_dvd] at *, exact (dvd_mul_left (n : ℤ) (m : ℤ)).trans h }
theorem of_modeq_mul_right (m : ℕ) : a ≡ b [MOD n * m] → a ≡ b [MOD n] :=
mul_comm m n ▸ of_modeq_mul_left _
end modeq
theorem modeq_one : a ≡ b [MOD 1] := modeq_of_dvd (one_dvd _)
lemma modeq_sub (h : b ≤ a) : a ≡ b [MOD a - b] :=
(modeq_of_dvd $ by rw [int.coe_nat_sub h]).symm
@[simp] lemma modeq_zero_iff {a b : ℕ} : a ≡ b [MOD 0] ↔ a = b :=
by rw [nat.modeq, nat.mod_zero, nat.mod_zero]
@[simp] lemma add_modeq_left {a n : ℕ} : n + a ≡ a [MOD n] :=
by rw [nat.modeq, nat.add_mod_left]
@[simp] lemma add_modeq_right {a n : ℕ} : a + n ≡ a [MOD n] :=
by rw [nat.modeq, nat.add_mod_right]
local attribute [semireducible] int.nonneg
/-- The natural number less than `lcm n m` congruent to `a` mod `n` and `b` mod `m` -/
def chinese_remainder' (h : a ≡ b [MOD gcd n m]) : {k // k ≡ a [MOD n] ∧ k ≡ b [MOD m]} :=
if hn : n = 0 then ⟨a, begin rw [hn, gcd_zero_left] at h, split, refl, exact h end⟩ else
if hm : m = 0 then ⟨b, begin rw [hm, gcd_zero_right] at h, split, exact h.symm, refl end⟩ else
⟨let (c, d) := xgcd n m in int.to_nat (((n * c * b + m * d * a) / gcd n m) % lcm n m), begin
rw xgcd_val,
dsimp [chinese_remainder'._match_1],
rw [modeq_iff_dvd, modeq_iff_dvd,
int.to_nat_of_nonneg (int.mod_nonneg _ (int.coe_nat_ne_zero.2 (lcm_ne_zero hn hm)))],
have hnonzero : (gcd n m : ℤ) ≠ 0 := begin
norm_cast,
rw [nat.gcd_eq_zero_iff, not_and],
exact λ _, hm,
end,
have hcoedvd : ∀ t, (gcd n m : ℤ) ∣ t * (b - a) := λ t, h.dvd.mul_left _,
have := gcd_eq_gcd_ab n m,
split; rw [int.mod_def, ← sub_add]; refine dvd_add _ (dvd_mul_of_dvd_left _ _); try {norm_cast},
{ rw ← sub_eq_iff_eq_add' at this,
rw [← this, sub_mul, ← add_sub_assoc, add_comm, add_sub_assoc, ← mul_sub,
int.add_div_of_dvd_left, int.mul_div_cancel_left _ hnonzero,
int.mul_div_assoc _ h.dvd, ← sub_sub, sub_self, zero_sub, dvd_neg, mul_assoc],
exact dvd_mul_right _ _,
norm_cast, exact dvd_mul_right _ _, },
{ exact dvd_lcm_left n m, },
{ rw ← sub_eq_iff_eq_add at this,
rw [← this, sub_mul, sub_add, ← mul_sub, int.sub_div_of_dvd, int.mul_div_cancel_left _ hnonzero,
int.mul_div_assoc _ h.dvd, ← sub_add, sub_self, zero_add, mul_assoc],
exact dvd_mul_right _ _,
exact hcoedvd _ },
{ exact dvd_lcm_right n m, },
end⟩
/-- The natural number less than `n*m` congruent to `a` mod `n` and `b` mod `m` -/
def chinese_remainder (co : coprime n m) (a b : ℕ) : {k // k ≡ a [MOD n] ∧ k ≡ b [MOD m]} :=
chinese_remainder' (by convert modeq_one)
lemma modeq_and_modeq_iff_modeq_mul {a b m n : ℕ} (hmn : coprime m n) :
a ≡ b [MOD m] ∧ a ≡ b [MOD n] ↔ (a ≡ b [MOD m * n]) :=
⟨λ h, begin
rw [nat.modeq_iff_dvd, nat.modeq_iff_dvd, ← int.dvd_nat_abs,
int.coe_nat_dvd, ← int.dvd_nat_abs, int.coe_nat_dvd] at h,
rw [nat.modeq_iff_dvd, ← int.dvd_nat_abs, int.coe_nat_dvd],
exact hmn.mul_dvd_of_dvd_of_dvd h.1 h.2
end,
λ h, ⟨h.of_modeq_mul_right _, h.of_modeq_mul_left _⟩⟩
lemma coprime_of_mul_modeq_one (b : ℕ) {a n : ℕ} (h : a * b ≡ 1 [MOD n]) : coprime a n :=
nat.coprime_of_dvd' (λ k kp ⟨ka, hka⟩ ⟨kb, hkb⟩, int.coe_nat_dvd.1 begin
rw [hka, hkb, modeq_iff_dvd] at h,
cases h with z hz,
rw [sub_eq_iff_eq_add] at hz,
rw [hz, int.coe_nat_mul, mul_assoc, mul_assoc, int.coe_nat_mul, ← mul_add],
exact dvd_mul_right _ _,
end)
@[simp] lemma mod_mul_right_mod (a b c : ℕ) : a % (b * c) % b = a % b :=
(mod_modeq _ _).of_modeq_mul_right _
@[simp] lemma mod_mul_left_mod (a b c : ℕ) : a % (b * c) % c = a % c :=
(mod_modeq _ _).of_modeq_mul_left _
lemma div_mod_eq_mod_mul_div (a b c : ℕ) : a / b % c = a % (b * c) / b :=
if hb0 : b = 0 then by simp [hb0]
else by rw [← @add_right_cancel_iff _ _ (c * (a / b / c)), mod_add_div, nat.div_div_eq_div_mul,
← nat.mul_right_inj (nat.pos_of_ne_zero hb0),← @add_left_cancel_iff _ _ (a % b), mod_add_div,
mul_add, ← @add_left_cancel_iff _ _ (a % (b * c) % b), add_left_comm,
← add_assoc (a % (b * c) % b), mod_add_div, ← mul_assoc, mod_add_div, mod_mul_right_mod]
lemma add_mod_add_ite (a b c : ℕ) :
(a + b) % c + (if c ≤ a % c + b % c then c else 0) = a % c + b % c :=
have (a + b) % c = (a % c + b % c) % c,
from ((mod_modeq _ _).add $ mod_modeq _ _).symm,
if hc0 : c = 0 then by simp [hc0]
else
begin
rw this,
split_ifs,
{ have h2 : (a % c + b % c) / c < 2,
from nat.div_lt_of_lt_mul (by rw mul_two;
exact add_lt_add (nat.mod_lt _ (nat.pos_of_ne_zero hc0))
(nat.mod_lt _ (nat.pos_of_ne_zero hc0))),
have h0 : 0 < (a % c + b % c) / c, from nat.div_pos h (nat.pos_of_ne_zero hc0),
rw [← @add_right_cancel_iff _ _ (c * ((a % c + b % c) / c)), add_comm _ c, add_assoc,
mod_add_div, le_antisymm (le_of_lt_succ h2) h0, mul_one, add_comm] },
{ rw [nat.mod_eq_of_lt (lt_of_not_ge h), add_zero] }
end
lemma add_mod_of_add_mod_lt {a b c : ℕ} (hc : a % c + b % c < c) :
(a + b) % c = a % c + b % c :=
by rw [← add_mod_add_ite, if_neg (not_le_of_lt hc), add_zero]
lemma add_mod_add_of_le_add_mod {a b c : ℕ} (hc : c ≤ a % c + b % c) :
(a + b) % c + c = a % c + b % c :=
by rw [← add_mod_add_ite, if_pos hc]
lemma add_div {a b c : ℕ} (hc0 : 0 < c) : (a + b) / c = a / c + b / c +
if c ≤ a % c + b % c then 1 else 0 :=
begin
rw [← nat.mul_right_inj hc0, ← @add_left_cancel_iff _ _ ((a + b) % c + a % c + b % c)],
suffices : (a + b) % c + c * ((a + b) / c) + a % c + b % c =
a % c + c * (a / c) + (b % c + c * (b / c)) + c * (if c ≤ a % c + b % c then 1 else 0) +
(a + b) % c,
{ simpa only [mul_add, add_comm, add_left_comm, add_assoc] },
rw [mod_add_div, mod_add_div, mod_add_div, mul_ite, add_assoc, add_assoc],
conv_lhs { rw ← add_mod_add_ite },
simp, ac_refl
end
lemma add_div_eq_of_add_mod_lt {a b c : ℕ} (hc : a % c + b % c < c) :
(a + b) / c = a / c + b / c :=
if hc0 : c = 0 then by simp [hc0]
else by rw [add_div (nat.pos_of_ne_zero hc0), if_neg (not_le_of_lt hc), add_zero]
protected lemma add_div_of_dvd_right {a b c : ℕ} (hca : c ∣ a) :
(a + b) / c = a / c + b / c :=
if h : c = 0 then by simp [h] else add_div_eq_of_add_mod_lt begin
rw [nat.mod_eq_zero_of_dvd hca, zero_add],
exact nat.mod_lt _ (pos_iff_ne_zero.mpr h),
end
protected lemma add_div_of_dvd_left {a b c : ℕ} (hca : c ∣ b) :
(a + b) / c = a / c + b / c :=
by rwa [add_comm, nat.add_div_of_dvd_right, add_comm]
lemma add_div_eq_of_le_mod_add_mod {a b c : ℕ} (hc : c ≤ a % c + b % c) (hc0 : 0 < c) :
(a + b) / c = a / c + b / c + 1 :=
by rw [add_div hc0, if_pos hc]
lemma add_div_le_add_div (a b c : ℕ) : a / c + b / c ≤ (a + b) / c :=
if hc0 : c = 0 then by simp [hc0]
else by rw [nat.add_div (nat.pos_of_ne_zero hc0)]; exact nat.le_add_right _ _
lemma le_mod_add_mod_of_dvd_add_of_not_dvd {a b c : ℕ} (h : c ∣ a + b) (ha : ¬ c ∣ a) :
c ≤ a % c + b % c :=
by_contradiction $ λ hc,
have (a + b) % c = a % c + b % c, from add_mod_of_add_mod_lt (lt_of_not_ge hc),
by simp [dvd_iff_mod_eq_zero, *] at *
lemma odd_mul_odd {n m : ℕ} : n % 2 = 1 → m % 2 = 1 → (n * m) % 2 = 1 :=
by simpa [nat.modeq] using @modeq.mul 2 n 1 m 1
lemma odd_mul_odd_div_two {m n : ℕ} (hm1 : m % 2 = 1) (hn1 : n % 2 = 1) :
(m * n) / 2 = m * (n / 2) + m / 2 :=
have hm0 : 0 < m := nat.pos_of_ne_zero (λ h, by simp * at *),
have hn0 : 0 < n := nat.pos_of_ne_zero (λ h, by simp * at *),
(nat.mul_right_inj (show 0 < 2, from dec_trivial)).1 $
by rw [mul_add, two_mul_odd_div_two hm1, mul_left_comm, two_mul_odd_div_two hn1,
two_mul_odd_div_two (nat.odd_mul_odd hm1 hn1), nat.mul_sub_left_distrib, mul_one,
← nat.add_sub_assoc hm0, nat.sub_add_cancel (le_mul_of_one_le_right (nat.zero_le _) hn0)]
lemma odd_of_mod_four_eq_one {n : ℕ} : n % 4 = 1 → n % 2 = 1 :=
by simpa [modeq, show 2 * 2 = 4, by norm_num] using @modeq.of_modeq_mul_left 2 n 1 2
lemma odd_of_mod_four_eq_three {n : ℕ} : n % 4 = 3 → n % 2 = 1 :=
by simpa [modeq, show 2 * 2 = 4, by norm_num, show 3 % 4 = 3, by norm_num]
using @modeq.of_modeq_mul_left 2 n 3 2
end nat
namespace list
variable {α : Type*}
lemma nth_rotate : ∀ {l : list α} {n m : ℕ} (hml : m < l.length),
(l.rotate n).nth m = l.nth ((m + n) % l.length)
| [] n m hml := (nat.not_lt_zero _ hml).elim
| l 0 m hml := by simp [nat.mod_eq_of_lt hml]
| (a::l) (n+1) m hml :=
have h₃ : m < list.length (l ++ [a]), by simpa using hml,
(lt_or_eq_of_le (nat.le_of_lt_succ $ nat.mod_lt (m + n)
(lt_of_le_of_lt (nat.zero_le _) hml))).elim
(λ hml',
have h₁ : (m + (n + 1)) % ((a :: l : list α).length) =
(m + n) % ((a :: l : list α).length) + 1,
from calc (m + (n + 1)) % (l.length + 1) =
((m + n) % (l.length + 1) + 1) % (l.length + 1) :
add_assoc m n 1 ▸ nat.modeq.add_right 1 (nat.mod_mod _ _).symm
... = (m + n) % (l.length + 1) + 1 : nat.mod_eq_of_lt (nat.succ_lt_succ hml'),
have h₂ : (m + n) % (l ++ [a]).length < l.length, by simpa [nat.add_one] using hml',
by rw [list.rotate_cons_succ, nth_rotate h₃, list.nth_append h₂, h₁, list.nth]; simp)
(λ hml',
have h₁ : (m + (n + 1)) % (l.length + 1) = 0,
from calc (m + (n + 1)) % (l.length + 1) = (l.length + 1) % (l.length + 1) :
add_assoc m n 1 ▸ nat.modeq.add_right 1
(hml'.trans (nat.mod_eq_of_lt (nat.lt_succ_self _)).symm)
... = 0 : by simp,
by rw [list.length, list.rotate_cons_succ, nth_rotate h₃, list.length_append,
list.length_cons, list.length, zero_add, hml', h₁, list.nth_concat_length]; refl)
lemma rotate_eq_self_iff_eq_repeat [hα : nonempty α] : ∀ {l : list α},
(∀ n, l.rotate n = l) ↔ ∃ a, l = list.repeat a l.length
| [] := ⟨λ h, nonempty.elim hα (λ a, ⟨a, by simp⟩), by simp⟩
| (a::l) :=
⟨λ h, ⟨a, list.ext_le (by simp) $ λ n hn h₁,
begin
rw [← option.some_inj, ← list.nth_le_nth],
conv {to_lhs, rw ← h ((list.length (a :: l)) - n)},
rw [nth_rotate hn, nat.add_sub_cancel' (le_of_lt hn),
nat.mod_self, nth_le_repeat], refl
end⟩,
λ ⟨a, ha⟩ n, ha.symm ▸ list.ext_le (by simp)
(λ m hm h,
have hm' : (m + n) % (list.repeat a (list.length (a :: l))).length < list.length (a :: l),
by rw list.length_repeat; exact nat.mod_lt _ (nat.succ_pos _),
by rw [nth_le_repeat, ← option.some_inj, ← list.nth_le_nth, nth_rotate h, list.nth_le_nth,
nth_le_repeat]; simp * at *)⟩
lemma rotate_repeat (a : α) (n : ℕ) (k : ℕ) :
(list.repeat a n).rotate k = list.repeat a n :=
let h : nonempty α := ⟨a⟩ in by exactI rotate_eq_self_iff_eq_repeat.mpr ⟨a, by rw length_repeat⟩ k
lemma rotate_one_eq_self_iff_eq_repeat [nonempty α] {l : list α} :
l.rotate 1 = l ↔ ∃ a : α, l = list.repeat a l.length :=
⟨λ h, rotate_eq_self_iff_eq_repeat.mp (λ n, nat.rec l.rotate_zero
(λ n hn, by rwa [nat.succ_eq_add_one, ←l.rotate_rotate, hn]) n),
λ h, rotate_eq_self_iff_eq_repeat.mpr h 1⟩
end list
|
d94a1aa35904eee955d4f879ec265652430a24af | ae9f8bf05de0928a4374adc7d6b36af3411d3400 | /src/formal_ml/probability_space.lean | 54085388460231869f584107918336d0173d1c55 | [
"Apache-2.0"
] | permissive | NeoTim/formal-ml | bc42cf6beba9cd2ed56c1cd054ab4eb5402ed445 | c9cbad2837104160a9832a29245471468748bb8d | refs/heads/master | 1,671,549,160,900 | 1,601,362,989,000 | 1,601,362,989,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 50,807 | lean | /-
Copyright 2020 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-/
import measure_theory.measurable_space
import measure_theory.measure_space
import measure_theory.outer_measure
import measure_theory.lebesgue_measure
import measure_theory.integration
import measure_theory.borel_space
import data.set.countable
import formal_ml.nnreal
import formal_ml.sum
import formal_ml.measurable_space
import formal_ml.classical
class probability_space (α: Type*) extends measure_theory.measure_space α :=
(univ_one:volume.measure_of (set.univ) = 1)
instance probability_space.to_measurable_space (α:Type*) [probability_space α]:measurable_space α :=
measure_theory.measure_space.to_measurable_space
/-
In measure theory (and specifically, in probability theory), not all sets of outcomes have
probabilities that can be measured. We represent those that can be measured as measurable
sets.
-/
def measurable_set {α:Type*} (M:measurable_space α):Type* := subtype (M.is_measurable')
def measurable_set.mk {α:Type*} {M:measurable_space α} {S:set α} (H:is_measurable S):measurable_set M := ⟨S, H⟩
lemma measurable_set_val_eq_coe {Ω:Type*} {P:measurable_space Ω}
(X:measurable_set P):X.val =
(@coe (subtype (@is_measurable Ω _)) (set Ω) _ X) :=
begin
refl
end
/-
A measurable set on a measurable space that has a probability measure is called an event.
-/
def event {Ω:Type*} (M:probability_space Ω):Type* := measurable_set (probability_space.to_measurable_space Ω)
lemma event_val_eq_coe {Ω:Type*} {P:probability_space Ω}
(X:event P):X.val =
(@coe (subtype (@is_measurable Ω _)) (set Ω) _ X) :=
begin
refl
end
lemma event.eq {Ω:Type*} {P:probability_space Ω} (A B:event P):
A.val = B.val → A = B :=
begin
intro A1,
apply subtype.eq,
exact A1
end
def event_mem {Ω:Type*} [P:probability_space Ω] (a:Ω) (E:event P):Prop :=
a∈ E.val
instance {Ω:Type*} [P:probability_space Ω]:has_mem Ω (event P) := {
mem := event_mem
}
lemma prob_le_1 {Ω:Type*} {P:probability_space Ω} (S:set Ω):
P.volume.measure_of S ≤ 1 :=
begin
have A1:P.volume.measure_of set.univ = 1,
{
apply P.univ_one,
},
have A2:S ⊆ set.univ,
{
simp,
},
have A3:P.volume.measure_of S ≤ P.volume.measure_of set.univ,
{
apply P.volume.mono,
apply A2,
},
rw A1 at A3,
exact A3,
end
/-
There are a lot of long proofs here, but this one seems particularly roundabout.
-/
lemma prob_not_infinite {Ω:Type*} {P:probability_space Ω} (S:set Ω):
(P.volume.measure_of S) ≠ ⊤ :=
begin
have A1:P.volume.measure_of S ≤ 1,
{
apply prob_le_1,
},
intro A2,
rw A2 at A1,
have A3:(1:ennreal)=⊤,
{
apply complete_linear_order.le_antisymm,
{
apply (ennreal.complete_linear_order.le_top),
},
{
apply A1,
}
},
have A4:(1:ennreal) ≠ (⊤:ennreal),
{
apply ennreal.one_ne_top,
},
rw A3 at A4,
apply A4,
refl,
end
lemma prob_nnreal {Ω:Type*} {P:probability_space Ω} (S:set Ω):
↑((P.volume.measure_of S).to_nnreal) = P.volume.measure_of S :=
begin
apply ennreal.coe_to_nnreal,
apply prob_not_infinite,
end
def event_prob {Ω:Type*} {P:probability_space Ω} (E:event P):nnreal :=
(P.volume.measure_of E.val).to_nnreal
notation `Pr[`E`]` := event_prob E
lemma event_prob_def {Ω:Type*} {p:probability_space Ω} (E:event p):
↑(Pr[E]) = (p.volume.measure_of E.val):=
begin
unfold event_prob,
apply prob_nnreal,
end
lemma to_nnreal_almost_monotonic (a b:ennreal):(a≠ ⊤)→(b≠⊤)→(a ≤ b)→ (a.to_nnreal ≤ b.to_nnreal) :=
begin
intros A1 A2 A3,
have A4:↑(a.to_nnreal)=a,
{
apply ennreal.coe_to_nnreal,
apply A1,
},
have A5:↑(b.to_nnreal)=b,
{
apply ennreal.coe_to_nnreal,
apply A2,
},
rw ← A4 at A3,
rw ← A5 at A3,
simp at A3,
apply A3,
end
lemma to_ennreal_monotonic (a b:nnreal):(a ≤ b)→ ((a:ennreal) ≤ (b:ennreal)) :=
begin
intro A1,
simp,
apply A1,
end
-- See ennreal.add_eq_top
lemma add_finite (a b:ennreal):(a≠ ⊤) → (b≠ ⊤) → (a + b≠ ⊤) :=
begin
intros A1 A2 A3,
rw ennreal.add_eq_top at A3,
cases A3,
{
apply A1,
apply A3,
},
{
apply A2,
apply A3,
}
end
lemma event_prob_mono1 {Ω:Type*} {p:probability_space Ω} (E F:event p):
p.volume.measure_of E.val ≤ p.volume.measure_of F.val →
Pr[E] ≤ Pr[F] :=
begin
unfold event_prob,
intro A1,
apply to_nnreal_almost_monotonic,
apply prob_not_infinite,
apply prob_not_infinite,
apply A1,
end
lemma event_prob_mono2 {Ω:Type*} {p:probability_space Ω} (E F:event p):
(E.val ⊆ F.val) →
Pr[E] ≤ Pr[F] :=
begin
intro A1,
apply event_prob_mono1,
apply p.volume.mono,
apply A1,
end
def event_univ {Ω:Type*} {p:probability_space Ω}:event p := {
val := set.univ,
property := is_measurable.univ,
}
lemma event_univ_val_def {Ω:Type*} {p:probability_space Ω}:
(@event_univ Ω p).val = set.univ :=
begin
unfold event_univ,
end
lemma Pr_event_univ {Ω:Type*} {p:probability_space Ω}:
Pr[@event_univ Ω p] = 1 :=
begin
have A1:↑(Pr[@event_univ Ω p]) = (1:ennreal),
{
rw event_prob_def,
apply p.univ_one,
},
simp at A1,
apply A1
end
lemma Pr_event_le_1 {Ω:Type*} {p:probability_space Ω} {E:event p}:
Pr[E] ≤ 1 :=
begin
have A1:Pr[E] ≤ Pr[@event_univ Ω p],
{
apply event_prob_mono2,
rw event_univ_val_def,
rw set.subset_def,
intros x A1A,
simp,
},
rw Pr_event_univ at A1,
apply A1,
end
def measurable_set_empty {Ω:Type*} {p:measurable_space Ω}:measurable_set p := {
val := ∅,
property := is_measurable.empty,
}
instance has_emptyc_measurable_set {Ω:Type*} {M:measurable_space Ω}:has_emptyc (measurable_set M) := ⟨ @measurable_set_empty Ω M ⟩
def event_empty {Ω:Type*} {p:probability_space Ω}:event p :=
@measurable_set_empty Ω (probability_space.to_measurable_space Ω)
instance has_emptyc_event {Ω:Type*} {P:probability_space Ω}:has_emptyc (event P) :=
⟨ @event_empty Ω P ⟩
lemma has_emptyc_emptyc_event {Ω:Type*} {P:probability_space Ω}:
∅ = (@event_empty Ω P) := rfl
lemma event_empty_val_def {Ω:Type*} {p:probability_space Ω}:
(@event_empty Ω p).val = ∅ := rfl
lemma event_empty_val_def2 {Ω:Type*} {p:probability_space Ω}:
(@has_emptyc.emptyc (event p) _).val = ∅ := rfl
lemma Pr_event_empty {Ω:Type*} {p:probability_space Ω}:
Pr[@event_empty Ω p] = 0 :=
begin
have A1:↑(Pr[@event_empty Ω p]) = (0:ennreal),
{
rw event_prob_def,
apply p.volume.empty,
},
simp at A1,
apply A1
end
/-Since Pr[E] is a nnreal, this establishes that the probability is in the interval [0,1] -/
lemma event_prob_le_1 {Ω:Type*} {p:probability_space Ω} {E:event p}:
Pr[E] ≤ 1 :=
begin
have A1:Pr[@event_univ Ω p] = 1,
{
apply Pr_event_univ,
},
rw ← A1,
apply event_prob_mono2,
rw event_univ_val_def,
simp,
end
def event_const {Ω:Type*} {p:probability_space Ω} (P:Prop):event p := {
val := {ω:Ω|P},
property := is_measurable.const P,
}
lemma event_const_val_def {Ω:Type*} {p:probability_space Ω} (P:Prop):
(@event_const _ p P).val={ω:Ω|P} := rfl
lemma event_const_true_eq_univ {Ω:Type*} {p:probability_space Ω} (P:Prop):P →
(@event_const _ p P)=event_univ :=
begin
intro A1,
apply event.eq,
rw event_univ_val_def,
rw event_const_val_def,
ext ω,split;intro A2,
{
simp,
},
{
simp,
exact A1,
}
end
lemma event_const_false_eq_empty {Ω:Type*} {p:probability_space Ω} (P:Prop):¬P →
(@event_const _ p P)=event_empty :=
begin
intro A1,
apply event.eq,
rw event_empty_val_def,
rw event_const_val_def,
ext ω,split;intro A2,
{
simp,
apply A1,
apply A2,
},
{
simp,
exfalso,
apply A2,
}
end
lemma Pr_event_const_true {Ω:Type*} {p:probability_space Ω} (P:Prop):P →
Pr[(@event_const _ p P)]=1 :=
begin
intro A1,
rw event_const_true_eq_univ,
apply Pr_event_univ,
exact A1,
end
lemma Pr_event_const_false {Ω:Type*} {p:probability_space Ω} (P:Prop):¬P →
Pr[(@event_const _ p P)]=0 :=
begin
intro A1,
rw event_const_false_eq_empty,
apply Pr_event_empty,
exact A1,
end
--The and of two events.
def measurable_inter {Ω:Type*} {p:measurable_space Ω} (A B:measurable_set p):measurable_set p := {
val:=A.val ∩ B.val,
property := is_measurable.inter A.property B.property,
}
lemma measurable_inter_val_def {Ω:Type*} {p:measurable_space Ω} (A B:measurable_set p):
(measurable_inter A B).val= A.val ∩ B.val := rfl
instance measurable_set_has_inter {Ω:Type*} {p:measurable_space Ω}:has_inter (measurable_set p) := {
inter := @measurable_inter Ω p,
}
lemma measurable_inter_val_def2 {Ω:Type*} {p:measurable_space Ω} (A B:measurable_set p):
(A ∩ B).val= A.val ∩ B.val := rfl
def eand {Ω:Type*} {p:probability_space Ω} (A B:event p):event p :=
measurable_inter A B
/-{
val:=A.val ∩ B.val,
property := is_measurable.inter A.property B.property,
}-/
infixr `∧ₑ`:100 := eand
lemma eand_val_def {Ω:Type*} {p:probability_space Ω} (A B:event p):
(A ∧ₑ B).val = A.val ∩ B.val :=
begin
refl,
end
lemma eand_comm {Ω:Type*} {p:probability_space Ω} (A B:event p):
(A ∧ₑ B) = (B ∧ₑ A) :=
begin
apply event.eq,
rw eand_val_def,
rw eand_val_def,
apply set.inter_comm,
end
lemma eand_eq_self_of_subset_left {Ω:Type*} {p:probability_space Ω} (A B:event p):
(A.val ⊆ B.val) →
(A ∧ₑ B) = A :=
begin
intro A1,
apply event.eq,
rw eand_val_def,
apply set.inter_eq_self_of_subset_left,
exact A1,
end
lemma eand_eq_self_of_subset_right {Ω:Type*} {p:probability_space Ω} (A B:event p):
(B.val ⊆ A.val) →
(A ∧ₑ B) = B :=
begin
intro A1,
rw eand_comm,
apply eand_eq_self_of_subset_left,
exact A1,
end
lemma Pr_eand_le_left {Ω:Type*} {p:probability_space Ω} (A B:event p):
Pr[A ∧ₑ B]≤ Pr[A] :=
begin
apply event_prob_mono2,
rw eand_val_def,
apply set.inter_subset_left,
end
lemma Pr_eand_le_right {Ω:Type*} {p:probability_space Ω} (A B:event p):
Pr[A ∧ₑ B]≤ Pr[B] :=
begin
rw eand_comm,
apply Pr_eand_le_left,
end
lemma Pr_eand_le_min {Ω:Type*} {p:probability_space Ω} (A B:event p):
Pr[A ∧ₑ B]≤ min Pr[A] Pr[B] :=
begin
apply le_min,
{
apply Pr_eand_le_left,
},
{
apply Pr_eand_le_right,
}
end
def measurable_union {Ω:Type*} {p:measurable_space Ω} (A B:measurable_set p):measurable_set p := {
val:=A.val ∪ B.val,
property := is_measurable.union A.property B.property,
}
lemma measurable_union_val_def {Ω:Type*} {p:measurable_space Ω} (A B:measurable_set p):
(measurable_union A B).val=A.val ∪ B.val := rfl
instance measurable_set_has_union {Ω:Type*} {p:measurable_space Ω}:has_union (measurable_set p) := {
union := @measurable_union Ω p,
}
lemma measurable_union_val_def2 {Ω:Type*} {p:measurable_space Ω} (A B:measurable_set p):
(A ∪ B).val = A.val ∪ B.val := rfl
def eor {Ω:Type*} {p:probability_space Ω} (A B:event p):event p := measurable_union A B
/-{
val:=A.val ∪ B.val,
property := is_measurable.union A.property B.property,
}-/
infixr `∨ₑ`:100 := eor
lemma eor_val_def {Ω:Type*} {p:probability_space Ω} (A B:event p):
(A ∨ₑ B).val = A.val ∪ B.val :=
begin
refl,
end
lemma eor_comm {Ω:Type*} {p:probability_space Ω} (A B:event p):
(A ∨ₑ B) = (B ∨ₑ A) :=
begin
apply event.eq,
rw eor_val_def,
rw eor_val_def,
apply set.union_comm,
end
lemma Pr_le_eor_left {Ω:Type*} {p:probability_space Ω} (A B:event p):
Pr[A] ≤ Pr[A ∨ₑ B] :=
begin
apply event_prob_mono2,
rw eor_val_def,
apply set.subset_union_left,
end
lemma Pr_le_eor_right {Ω:Type*} {p:probability_space Ω} (A B:event p):
Pr[B] ≤ Pr[A ∨ₑ B] :=
begin
rw eor_comm,
apply Pr_le_eor_left,
end
lemma Pr_le_eor_sum {Ω:Type*} {p:probability_space Ω} (A B:event p):
Pr[A ∨ₑ B]≤ Pr[A] + Pr[B] :=
begin
have A1:↑(Pr[A ∨ₑ B])≤ (Pr[A]:ennreal) + (Pr[B]:ennreal),
{
rw event_prob_def,
rw event_prob_def,
rw event_prob_def,
rw eor_val_def,
apply measure_theory.outer_measure.union,
},
have A2:↑(Pr[A ∨ₑ B])≤ ((Pr[A] + Pr[B]):ennreal) → Pr[A ∨ₑ B]≤ Pr[A] + Pr[B],
{
apply to_nnreal_almost_monotonic,
{
rw event_prob_def,
apply prob_not_infinite,
},
{
apply add_finite,
rw event_prob_def,
apply prob_not_infinite,
rw event_prob_def,
apply prob_not_infinite,
}
},
apply A2,
apply A1,
end
lemma Pr_disjoint_eor {Ω:Type*} {p:probability_space Ω} (A B:event p):
disjoint A.val B.val →
Pr[A ∨ₑ B] = Pr[A] + Pr[B] :=
begin
intro A1,
have A2:↑(Pr[A ∨ₑ B])= (Pr[A]:ennreal) + (Pr[B]:ennreal),
{
rw event_prob_def,
rw event_prob_def,
rw event_prob_def,
rw eor_val_def,
apply measure_theory.measure_union,
apply A1,
apply A.property,
apply B.property,
},
have A3:((Pr[A ∨ₑ B]):ennreal).to_nnreal= ((Pr[A]:ennreal) + (Pr[B]:ennreal)).to_nnreal,
{
rw A2,
},
simp at A3,
apply A3,
end
def enot {Ω:Type*} {p:probability_space Ω} (A:event p):event p := {
val:=(A).valᶜ,
property := is_measurable.compl A.property,
}
prefix `¬ₑ` :100 := enot
lemma enot_val_def {Ω:Type*} {p:probability_space Ω} (A:event p):
(¬ₑ A).val = (A.val)ᶜ :=
begin
refl,
end
/-
Double negation elimination. However, it is hard to avoid in measure theory.
-/
lemma enot_enot_eq_self {Ω:Type*} {p:probability_space Ω} (A:event p):
(¬ₑ (¬ₑ A)) = (A) :=
begin
apply event.eq,
rw enot_val_def,
rw enot_val_def,
ext ω,
have A1:decidable (ω ∈ A.val),
{
apply classical.prop_decidable,
},
split;intro A2,
{
cases A1,
{
exfalso,
apply A2,
apply A1,
},
{
exact A1,
}
},
{
intro A3,
apply A3,
exact A2,
}
end
lemma em_event {Ω:Type*} {p:probability_space Ω} (A:event p):
A ∨ₑ (¬ₑ A)=event_univ :=
begin
apply event.eq,
rw event_univ_val_def,
rw eor_val_def,
rw enot_val_def,
rw set.union_compl_self,
end
lemma Pr_add_enot_eq_1 {Ω:Type*} {p:probability_space Ω} (A:event p):
Pr[A] + Pr[¬ₑ A] = 1 :=
begin
have A1:disjoint (A.val) (enot A).val,
{
unfold disjoint,
rw enot_val_def,
simp,
},
have A2:A∨ₑ (¬ₑ A) = event_univ,
{
apply em_event,
},
have A3:Pr[A∨ₑ (¬ₑ A)] = Pr[event_univ],
{
rw A2,
},
rw Pr_event_univ at A3,
rw Pr_disjoint_eor at A3,
apply A3,
apply A1,
end
lemma Pr_one_minus_eq_not {Ω:Type*} {p:probability_space Ω} (A:event p):
1 - Pr[A] = Pr[¬ₑ A] :=
begin
apply nnreal_add_sub_left,
apply Pr_add_enot_eq_1,
end
lemma Pr_one_minus_not_eq {Ω:Type*} {p:probability_space Ω} (A:event p):
1 - Pr[enot A] = Pr[A] :=
begin
apply nnreal_add_sub_right,
apply Pr_add_enot_eq_1,
end
lemma em_event_cond {Ω:Type*} {p:probability_space Ω} (A B:event p):
(A ∧ₑ B) ∨ₑ (A ∧ₑ ¬ₑ B) = A :=
begin
apply event.eq,
rw eor_val_def,
rw eand_val_def,
rw eand_val_def,
apply set.inter_union_compl,
end
lemma Pr_em {Ω:Type*} {p:probability_space Ω} (A B:event p):
Pr[A ∧ₑ B] + Pr[A ∧ₑ ¬ₑ B] = Pr[A] :=
begin
rw ← Pr_disjoint_eor,
{ --Pr[(A∧ₑ B)∨ₑ A∧ₑ ¬ₑ B] = Pr[A]
rw em_event_cond,
},
{ --disjoint ((A∧ₑ B).val) ((A∧ₑ ¬ₑ B).val)
rw eand_val_def,
rw eand_val_def,
rw enot_val_def,
apply set.disjoint_inter_compl,
}
end
lemma Pr_diff {Ω:Type*} {p:probability_space Ω} (A B:event p):
A.val ⊆ B.val →
Pr[B ∧ₑ ¬ₑ A] = Pr[B] - Pr[A] :=
begin
intro A1,
have A2:Pr[B ∧ₑ A] + Pr[B ∧ₑ ¬ₑ A] = Pr[B],
{
apply Pr_em,
},
have A3:B ∧ₑ A = A,
{
apply eand_eq_self_of_subset_right,
apply A1,
},
rw A3 at A2,
symmetry,
apply nnreal_add_sub_left,
exact A2,
end
def event_eqv {Ω:Type*} {p:probability_space Ω} (A B:event p):event p :=
(A ∧ₑ B) ∨ₑ ((¬ₑ A) ∧ₑ (¬ₑ B))
infixr `=ₑ`:100 := event_eqv
lemma event_eqv_def {Ω:Type*} {p:probability_space Ω} (A B:event p):
(A =ₑ B) = ((A ∧ₑ B) ∨ₑ ((¬ₑ A) ∧ₑ (¬ₑ B))) := rfl
/-
-- Should prove this.
lemma Pr_eor_eq_minus_eand {Ω:Type*} [ Ω] {p:probability_space Ω} (A B:event p):
Pr[A ∨ₑ B] = Pr[A] + Pr[B] - Pr[A ∧ₑ B]
-/
def eall {Ω β:Type*} {p:probability_space Ω} [encodable β] (A:β → event p):event p := {
val:=(⋂ b:β, (A b).val),
property := is_measurable.Inter (λ b:β, (A b).property),
}
lemma eall_val_def {Ω β:Type*} {p:probability_space Ω} [encodable β] (A:β → event p):
(eall A).val = (⋂ b:β, (A b).val) := rfl
def eall_prop {Ω β:Type*} {p:probability_space Ω} [E:encodable β]
(P:β → Prop) [D:decidable_pred P]
(A:β → event p):event p := @eall _ _ _ (@encodable.subtype β P E D) (λ (b:(subtype P)), A (b.val) )
def to_set_of_sets {Ω:Type*} {p:probability_space Ω} (A:set (event p)):set (set Ω) :=
(set.image (λ a:event p, a.val) A)
lemma all_measurable_to_set_of_sets {Ω:Type*} {p:probability_space Ω} (A:set (event p))
(a∈ (to_set_of_sets A)):is_measurable a :=
begin
unfold to_set_of_sets at H,
simp at H,
cases H with x H,
cases H with A1 A2,
subst a,
exact x.property,
end
lemma countable_to_set_of_sets {Ω:Type*} {p:probability_space Ω} {A:set (event p)}:
(set.countable A)→ (set.countable (to_set_of_sets A)) :=
begin
unfold to_set_of_sets,
intro A1,
apply set.countable.image,
apply A1,
end
def eall_set {Ω:Type*} {p:probability_space Ω} (A:set (event p)) (cA:set.countable A):event p:=
{
val:=set.sInter (to_set_of_sets A),
property:=is_measurable.sInter (countable_to_set_of_sets cA) (all_measurable_to_set_of_sets A),
}
def eall_finset_val {Ω β:Type*} {p:probability_space Ω} (S:finset β)
(A:β → event p):set Ω := ⋂ s∈ S, (A s).val
lemma eall_finset_val_measurable {Ω β:Type*} {p:probability_space Ω} (S:finset β)
(A:β → event p):is_measurable (eall_finset_val S A) :=
begin
unfold eall_finset_val,
apply finset_inter_measurable,
intros,
apply (A t).property,
end
--
def eall_finset {Ω β:Type*} {p:probability_space Ω}
(S:finset β)
(A:β → event p):event p := {
val:=eall_finset_val S A,
property:=eall_finset_val_measurable S A,
}
lemma eall_finset_val_def {Ω β:Type*} {p:probability_space Ω}
(S:finset β) (A:β → event p):(eall_finset S A).val = ⋂ s∈ S, (A s).val := rfl
--If we could state forall for events, that would be great!
--notation `∀r` binders `, ` r:(scoped f, eall_finset f) := r
def eall_fintype {Ω β:Type*} {p:probability_space Ω}
(F:fintype β) (A:β → event p):event p := eall_finset F.elems A
lemma eall_fintype_val_def {Ω β:Type*} {p:probability_space Ω}
(F:fintype β) (A:β → event p):(eall_fintype F A).val = ⋂ (s:β), (A s).val :=
begin
unfold eall_fintype,
rw eall_finset_val_def,
{
ext,split;intro A1;simp at A1;simp,
{
intro i,
apply A1,
apply F.complete,
},
{
intros i A2,
apply A1,
}
}
end
def measurable_Union {Ω β:Type*} {p:measurable_space Ω} [encodable β] (A:β → measurable_set p):
measurable_set p := {
val:=(⋃ b:β, (A b).val),
property := is_measurable.Union (λ b:β, (A b).property),
}
lemma measurable_Union_val_def {Ω β:Type*} {p:measurable_space Ω} [E:encodable β]
(A:β → measurable_set p):
(@measurable_Union Ω β p E A).val = (⋃ b:β, (A b).val) := rfl
def eany {Ω β:Type*} {p:probability_space Ω} [encodable β] (A:β → event p):event p :=
measurable_Union A
lemma measurable_Union_eq_any {Ω β:Type*}
{p:probability_space Ω} [E:encodable β] (A:β → event p):
measurable_Union A = eany A := rfl
lemma sum_subst {β:Type*} [encodable β] {f g:β → ennreal}:(f = g) →
(tsum f) = (tsum g) :=
begin
intro A1,
rw A1,
end
lemma Pr_measurable_Union_sum_dummy {Ω β:Type*} [M:probability_space Ω]
--{m:measure_theory.measure Ω}
[E:encodable β]
(A:β → set Ω):(∀ (i j:β), i ≠ j →
(A i ∩ A j = ∅))→
(∀ i, is_measurable (A i)) →
((@measure_theory.measure_space.volume Ω (probability_space.to_measure_space)) (⋃ (n:β), A n)) =
(∑' (i:β), (@measure_theory.measure_space.volume Ω (probability_space.to_measure_space)) (A i)) :=
begin
intros A1 A3,
rw measure_theory.measure_Union,
{
intros i j A2,
simp,
--have A3 := A1 i j A2,
unfold disjoint function.on_fun,
simp,
rw subset_empty_iff,
apply A1 i j A2,
},
{
apply A3,
},
end
lemma measure_eq_measure {Ω:Type*} [P:probability_space Ω] {S:set Ω}:
measure_theory.measure_space.volume.to_outer_measure.measure_of S =
(@measure_theory.measure_space.volume Ω (probability_space.to_measure_space)) S := rfl
lemma eany_val_def {Ω β:Type*} {p:probability_space Ω} [encodable β]
(A:β → event p):(eany A).val=(⋃ b:β, (A b).val) := rfl
def eany_finset_val {Ω β:Type*} {p:probability_space Ω} (S:finset β)
(A:β → event p):set Ω := ⋃ s∈ S, (A s).val
lemma eany_finset_val_measurable {Ω β:Type*} {p:probability_space Ω} (S:finset β)
(A:β → event p):is_measurable (eany_finset_val S A) :=
begin
unfold eany_finset_val,
apply finset_union_measurable,
intros,
apply (A t).property,
end
def eany_finset {Ω β:Type*} {p:probability_space Ω}
(S:finset β)
(A:β → event p):event p := {
val:=eany_finset_val S A,
property:=eany_finset_val_measurable S A,
}
lemma eany_finset_val_def {Ω β:Type*} {p:probability_space Ω} (S:finset β)
(A:β → event p):(eany_finset S A).val = ⋃ s∈ S, (A s).val := rfl
/-lemma eany_finset_insert_val {Ω β:Type*} {p:probability_space Ω} [decidable_eq β] (S:finset β) {a:β}
(A:β → event p):
-- (⋃ s∈ (insert a S), (A s).val) =
-- ((A a).val ) ∪ (⋃ s∈ S,(A s).val) :=
(eany_finset (insert a S) A).val = ((A a).val ) ∪ (⋃ s∈ S,(A s).val) :=
begin
simp,
end-/
def eany_fintype {Ω β:Type*} {p:probability_space Ω}
(F:fintype β) (A:β → event p):event p := eany_finset F.elems A
lemma eany_finset_empty {Ω β:Type*} {p:probability_space Ω}
(A:β → event p):eany_finset ∅ A = event_empty :=
begin
apply event.eq,
rw eany_finset_val_def,
rw event_empty_val_def,
simp,
end
lemma eany_finset_insert {Ω β:Type*} [D:decidable_eq β] {p:probability_space Ω}
{S:finset β} {A:β → event p} {a:β}:
eany_finset (insert a S) A = (A a) ∨ₑ eany_finset S A :=
begin
apply event.eq,
rw eany_finset_val_def,
rw eor_val_def,
rw eany_finset_val_def,
ext ω,split;intros A2;simp;simp at A2;apply A2,
end
lemma eany_finset_bound {Ω β:Type*} [D:decidable_eq β]
{p:probability_space Ω}
(S:finset β) (A:β → event p):Pr[eany_finset S A] ≤ finset.sum S (λ a:β, Pr[A a]) :=
begin
apply finset.induction_on S,
{
simp,
rw eany_finset_empty,
apply Pr_event_empty,
},
{
intros a S2 A1 A2,
rw finset.sum_insert A1,
rw eany_finset_insert,
apply le_trans,
apply Pr_le_eor_sum,
apply add_le_add_left,
apply A2,
}
end
lemma eany_fintype_bound {Ω β:Type*} [D:decidable_eq β] {p:probability_space Ω}
(F:fintype β) (A:β → event p):Pr[eany_fintype F A] ≤ ∑' a:β, Pr[A a] :=
begin
unfold eany_fintype,
rw tsum_fintype,
apply eany_finset_bound,
end
lemma eany_fintype_bound2 {Ω β:Type*} {p:probability_space Ω}
(F:fintype β) (A:β → event p) (k:nnreal):
(∀ a:β, Pr[A a]≤ k) →
Pr[eany_fintype F A] ≤ (fintype.card β) * k :=
begin
intro A1,
have A2:decidable_eq β := classical.decidable_eq β,
apply le_trans,
apply @eany_fintype_bound Ω β A2,
rw tsum_fintype,
unfold fintype.card,
apply @finset_sum_le_const β A2,
intros s A3,
apply A1,
end
def independent_event_pair {Ω:Type*} {p:probability_space Ω} (A B:event p):Prop :=
--(event_prob (eand A B)) = (event_prob A) * (event_prob B)
Pr[ A ∧ₑ B] = Pr[A] * Pr[B]
def independent_events {Ω β:Type*} {p:probability_space Ω} [fintype β]
(A:β → event p):Prop :=
∀ (S:finset β), (finset.prod S (λ b, Pr[A b])) = Pr[eall_finset S A]
def events_IID {Ω β:Type*} {p:probability_space Ω} [fintype β]
(A:β → event p):Prop :=
independent_events A ∧ (∀ x y:β, Pr[A x] = Pr[A y])
lemma events_IID_pow {α : Type*} {p : probability_space α} {β : Type*}
[F:fintype β] [I:inhabited β] (A:β → event p) (S:finset β):
events_IID A → Pr[eall_finset S A] = Pr[A I.default]^(S.card) :=
begin
intros A1,
unfold events_IID at A1,
cases A1 with A2 A3,
unfold independent_events at A2,
have A4:(finset.prod S (λ b, Pr[A b])) = Pr[eall_finset S A],
{
apply A2,
},
rw ← A4,
have A5:(λ (b : β), Pr[A b]) = (λ (b:β), Pr[A (inhabited.default β)]),
{
ext b,
rw A3,
},
rw A5,
apply finset.prod_const,
end
def measurable_fun {α:Type*} {β:Type*} (Mα:measurable_space α) (Mβ:measurable_space β):Type*
:= subtype (@measurable α β _ _)
def random_variable {α:Type*} (p:probability_space α) {β:Type*}
(Mβ:measurable_space β):Type* := measurable_fun (probability_space.to_measurable_space α) Mβ
infixr ` →ₘ `:80 := measurable_fun
infixr ` →ᵣ `:80 := random_variable
lemma random_variable_val_eq_coe {Ω α:Type*} {P:probability_space Ω} {M:measurable_space α}
(X:P →ᵣ M):X.val =
(@coe (subtype (@measurable Ω α _ _)) (Ω → α) _ X) :=
begin
refl
end
lemma measurable_set_preimageh {α:Type*} {β:Type*} [Mα:measurable_space α] [Mβ:measurable_space β]
(f:measurable_fun Mα Mβ) (S:measurable_set Mβ):is_measurable (set.preimage (f.val) (S.val)) :=
begin
apply measurable_elim,
apply f.property,
apply S.property
end
def measurable_set_preimage {α:Type*} {β:Type*} [Mα:measurable_space α] [Mβ:measurable_space β]
(f:measurable_fun Mα Mβ) (S:measurable_set Mβ):measurable_set Mα := {
val:= (set.preimage (f.val) (S.val)),
property:=measurable_set_preimageh f S,
}
def rv_event {α:Type*} {p:probability_space α} {β:Type*}
[Mβ:measurable_space β] (X:random_variable p Mβ) (S:measurable_set Mβ):event p :=
measurable_set_preimage X S
infixr ` ∈ᵣ `:80 := rv_event
lemma rv_event_val_def {α:Type*} {p : probability_space α} {β : Type*}
[Mβ : measurable_space β] (X:p →ᵣ Mβ) (S:measurable_set Mβ):(X ∈ᵣ S).val = {a:α|X.val a ∈ S.val} :=
begin
refl
end
lemma rv_event_empty {α:Type*} {p:probability_space α} {β:Type*}
[Mβ:measurable_space β] (X:random_variable p Mβ):X ∈ᵣ ∅ = ∅ :=
begin
apply event.eq,
rw rv_event_val_def,
rw event_empty_val_def2,
ext ω;split;intros A1,
{
exfalso,
simp at A1,
apply A1,
},
{
exfalso,
apply A1,
},
end
lemma rv_event_measurable_union {α:Type*} {p:probability_space α} {β:Type*}
[Mβ:measurable_space β] (X:random_variable p Mβ)
{A B:measurable_set Mβ}:X ∈ᵣ (measurable_union A B) = (X ∈ᵣ A) ∨ₑ (X∈ᵣ B) :=
begin
apply event.eq,
repeat {rw rv_event_val_def},
rw eor_val_def,
repeat {rw rv_event_val_def},
rw measurable_union_val_def,
ext ω;split;intros A1;simp;simp at A1;apply A1
end
lemma rv_event_val_def' {α:Type*} {p : probability_space α} {β : Type*}
[Mβ : measurable_space β] (X:p →ᵣ Mβ) (S:measurable_set Mβ) {ω:α}:
(ω ∈ ((X ∈ᵣ S)))↔ (X.val ω ∈ S.val) :=
begin
refl
end
lemma set.mem_Prop_def {α:Type*} {P:α → Prop} {a:α}:
(a ∈ {a':α|P a'} )= P a := rfl
lemma rv_event_measurable_Union {α:Type*} {p:probability_space α} {β:Type*}
[Mβ:measurable_space β] {γ:Type*} [E:encodable γ] (X:random_variable p Mβ)
{f:γ → measurable_set Mβ}:X ∈ᵣ (measurable_Union f) =
measurable_Union (λ i, X ∈ᵣ (f i)) :=
begin
apply event.eq,
ext ω,
rw rv_event_val_def,
rw measurable_Union_val_def,
rw measurable_Union_val_def,
split;intro A1,
{
rw set.mem_Prop_def at A1,
rw set.mem_Union,
rw set.mem_Union at A1,
cases A1 with i A1,
apply exists.intro i,
rw @rv_event_val_def α p β Mβ X (f i),
rw set.mem_Prop_def,
apply A1,
},
{
rw set.mem_Prop_def,
rw set.mem_Union,
rw set.mem_Union at A1,
cases A1 with i A1,
rw @rv_event_val_def α p β Mβ X (f i) at A1,
apply exists.intro i,
apply A1,
},
end
instance measurable_set_has_compl {α:Type*} [M:measurable_space α]:has_compl (@measurable_set α M) := {
compl := λ E, ⟨ E.valᶜ, is_measurable.compl E.property⟩,
}
instance measurable_set_subtype_has_neg {α:Type*} [M:measurable_space α]:has_neg (subtype (@is_measurable α M)) := {
neg := λ E, ⟨ E.valᶜ, is_measurable.compl E.property⟩,
}
lemma measurable_set_neg_def {α:Type*} [M:measurable_space α] {E:@measurable_set α M}:
Eᶜ = ⟨ E.valᶜ, is_measurable.compl E.property⟩ :=rfl
lemma measurable_set_compl_val_def {α:Type*} [M:measurable_space α] {E:@measurable_set α M}:
(Eᶜ).val = (E.val)ᶜ :=rfl
instance event_has_compl {α:Type*} [M:probability_space α]:has_compl (@event α M) := {
compl := λ E, ⟨E.valᶜ, is_measurable.compl E.property⟩,
}
lemma event_neg_def {α:Type*} [M:probability_space α] {E:@event α M}:
Eᶜ = ⟨ E.valᶜ, is_measurable.compl E.property⟩ :=rfl
lemma event_neg_val_def {α:Type*} [M:probability_space α] {E:@event α M}:
(Eᶜ).val = (E.val)ᶜ := rfl
lemma event_simp_def {α:Type*} [p:probability_space α] {X:set α} {H:is_measurable X}:
(subtype.mk X H).val = X := rfl
lemma measurable_set_simp_def {α:Type*} [p:measurable_space α] {X:set α} {H:is_measurable X}:
(subtype.mk X H).val = X := rfl
lemma pr_comp_event {Ω:Type*} {p:probability_space Ω} {X:p →ᵣ borel real}
{E:@measurable_set ℝ (borel ℝ)}:
(X ∈ᵣ (Eᶜ)) = (X ∈ᵣ E)ᶜ :=
begin
apply event.eq,
rw event_neg_def,
rw rv_event_val_def,
rw @event_simp_def Ω p ,
rw rv_event_val_def,
rw measurable_set_neg_def,
rw @measurable_set_simp_def ℝ (borel ℝ),
ext ω,
simp,
end
lemma rv_event_compl {Ω:Type*} {MΩ:probability_space Ω} {β:Type*} [Mβ:measurable_space β]
(X:MΩ →ᵣ Mβ) (S:measurable_set Mβ):(X ∈ᵣ (Sᶜ)) = (rv_event X S)ᶜ :=
begin
apply event.eq,
rw event_neg_val_def,
rw rv_event_val_def,
rw measurable_set_compl_val_def,
rw rv_event_val_def,
simp,
refl,
end
lemma neg_eq_not {Ω:Type*} {p:probability_space Ω} (A:event p):
Aᶜ = ¬ₑ A :=
begin
apply event.eq,
rw event_neg_val_def,
rw enot_val_def,
end
def random_variable_identical {α:Type*} {p:probability_space α} {β:Type*}
[Mβ:measurable_space β] (X Y:random_variable p Mβ):Prop :=
∀ (S:measurable_set Mβ), Pr[X ∈ᵣ S] = Pr[Y ∈ᵣ S]
def random_variable_independent_pair {α:Type*} {p:probability_space α} {β:Type*}
[Mβ:measurable_space β] {γ:Type*} [Mγ:measurable_space γ] (X:p →ᵣ Mβ)
(Y:p →ᵣ Mγ):Prop :=
∀ (S:measurable_set Mβ) (T:measurable_set Mγ), independent_event_pair (X ∈ᵣ S) (Y ∈ᵣ T)
def random_variable_independent {α:Type*} {p:probability_space α} {β:Type*}
[fintype β]
{γ:β → Type*} [Mγ:Π b, measurable_space (γ b)] (X:Π b, random_variable p (Mγ b)):Prop :=
∀ (S:Π b, measurable_set (Mγ b)), independent_events (λ b:β, ((X b) ∈ᵣ (S b)))
def random_variables_IID {α:Type*} {p:probability_space α} {β:Type*}
[fintype β]
{γ:Type*} [Mγ:measurable_space γ] (X:β → random_variable p Mγ):Prop :=
random_variable_independent X ∧
∀ (i j:β), random_variable_identical (X i) (X j)
/- There are a lot of types where everything is measurable. This is equivalent to ⊤. -/
class top_measurable (α:Type*) extends measurable_space α :=
(all_measurable:∀ S:set α,is_measurable S)
instance bool_top_measurable:top_measurable bool := {
all_measurable:=@measurable_space.is_measurable_top bool,
..bool.measurable_space
}
instance int_top_measurable:top_measurable ℤ := {
all_measurable:=@measurable_space.is_measurable_top ℤ,
..int.measurable_space
}
/-
In a top measurable space (e.g. bool, ℕ, ℤ, et cetera),
everything is measurable. So, we can make an event from everything.
-/
def measurable_set_top {β:Type*} [M:top_measurable β] (S:set β):
(@measurable_set β M.to_measurable_space) := {
val := S,
property := top_measurable.all_measurable S,
}
def rv_top_event {α:Type*} {p:probability_space α}
{β:Type*} [Mβ:top_measurable β]
(X:random_variable p Mβ.to_measurable_space) (S:set β):event p :=
rv_event X (measurable_set_top S)
--To apply this directly to a set, it has to be top measurable.
infixr ` ∈t `:80 := rv_top_event
lemma rv_top_event_val_def {α:Type*} {p:probability_space α}
{β:Type*} [Mβ:top_measurable β]
(X:random_variable p Mβ.to_measurable_space) (S:set β):
(rv_top_event X S).val = {a:α|X.val a ∈ S} := rfl
lemma compose_measurable_fun_measurable2 {α β γ:Type*}
[Mα:measurable_space α] [Mβ:measurable_space β] [Mγ:measurable_space γ]
(X:measurable_fun Mβ Mγ) (Y:measurable_fun Mα Mβ):measurable (X.val ∘ Y.val) :=
begin
apply measurable_intro,
intros,
have A1:(X.val ∘ Y.val ⁻¹' B)=(Y.val ⁻¹' (X.val ⁻¹' B)),
{
refl,
},
rw A1,
apply measurable_elim Y.val _ Y.property,
apply measurable_elim X.val _ X.property,
apply a
end
def compose_measurable_fun {α β γ:Type*}
{Mα:measurable_space α} {Mβ:measurable_space β} {Mγ:measurable_space γ}
(X:measurable_fun Mβ Mγ) (Y:measurable_fun Mα Mβ):(measurable_fun Mα Mγ) := {
val := X.val ∘ Y.val,
property := compose_measurable_fun_measurable2 X Y
}
infixr ` ∘m `:80 := compose_measurable_fun
lemma compose_measurable_fun_val_def {Ω : Type*} {β : Type*} {γ : Type*}
[MΩ : measurable_space Ω] [Mβ : measurable_space β]
[Mγ : measurable_space γ] (Y:Mβ →ₘ Mγ) (X:MΩ →ₘ Mβ):
(Y ∘m X).val = (λ ω:Ω, Y.val (X.val ω)) :=
begin
refl
end
def rv_compose {α : Type*} {β : Type*} {γ : Type*}
{p : probability_space α} {Mβ : measurable_space β}
{Mγ : measurable_space γ} (X:measurable_fun Mβ Mγ) (Y:random_variable p Mβ):random_variable p Mγ :=
compose_measurable_fun X Y
infixr ` ∘r `:80 := rv_compose
lemma rv_compose_val_def {Ω : Type*} {β : Type*} {γ : Type*}
[Mβ : measurable_space β]
[Mγ : measurable_space γ] {p : probability_space Ω} (Y:Mβ →ₘ Mγ) (X:p →ᵣ Mβ):
(Y ∘r X).val = (λ ω:Ω, Y.val (X.val ω)) :=
begin
refl
end
def prod_space {α β:Type*} (Mα:measurable_space α) (Mβ:measurable_space β):=(@prod.measurable_space α β Mα Mβ)
infixr ` ×ₘ `:80 := prod_space
def mf_fst {α β:Type*}
{Mα:measurable_space α} {Mβ:measurable_space β}:measurable_fun
(Mα ×ₘ Mβ) Mα := {
val:= (λ x:(α × β), x.fst),
property := fst_measurable,
}
def mf_snd {α β:Type*}
{Mα:measurable_space α} {Mβ:measurable_space β}:measurable_fun (prod_space Mα Mβ) Mβ := {
val:= (λ x:(α × β), x.snd),
property := snd_measurable,
}
/-
{Ω : Type u_1} [_inst_1 : measurable_space Ω] {β : Type u_2} [_inst_2 : measurable_space β] (c : β),
measurable (λ (ω : Ω), c)
-/
def const_measurable_fun {Ω : Type*} [MΩ : measurable_space Ω] {β : Type*}
[Mβ : measurable_space β] (c : β):MΩ →ₘ Mβ := {
val := (λ (ω : Ω), c),
property := const_measurable c,
}
lemma const_measurable_fun_val_def {Ω : Type*} [MΩ : measurable_space Ω] {β : Type*}
[Mβ : measurable_space β] (c : β):(const_measurable_fun c).val = (λ (ω : Ω), c) := rfl
def const_random_variable {Ω : Type*} {P:probability_space Ω}
{β : Type*}
[Mβ : measurable_space β] (c : β):P →ᵣ Mβ := const_measurable_fun c
def prod_measurable_fun
{α β γ:Type*}
{Mα:measurable_space α} {Mβ:measurable_space β} {Mγ:measurable_space γ}
(X:measurable_fun Mα Mβ) (Y:measurable_fun Mα Mγ):measurable_fun Mα (Mβ ×ₘ Mγ) := {
val := (λ a:α, prod.mk (X.val a) (Y.val a)),
property := measurable_fun_product_measurable X.val Y.val X.property Y.property,
}
lemma prod_measurable_fun_val_def {Ω : Type*} {β : Type*} {γ : Type*} {MΩ : measurable_space Ω}
{Mβ : measurable_space β} {Mγ : measurable_space γ} {X:MΩ →ₘ Mβ}
{Y:MΩ →ₘ Mγ}: (prod_measurable_fun X Y).val = λ ω:Ω, prod.mk (X.val ω) (Y.val ω) :=
begin
refl
end
def prod_random_variable
{α β γ:Type*}
{P:probability_space α} {Mβ:measurable_space β} {Mγ:measurable_space γ}
(X:random_variable P Mβ) (Y:random_variable P Mγ):random_variable P (Mβ ×ₘ Mγ) :=
prod_measurable_fun X Y
infixr ` ×ᵣ `:80 := prod_random_variable
lemma prod_random_variable_val_def {Ω : Type*} {β : Type*} {γ : Type*}
{P : probability_space Ω} {Mβ : measurable_space β} {Mγ : measurable_space γ} {X:P →ᵣ Mβ}
{Y:P →ᵣ Mγ}: (X ×ᵣ Y).val = λ ω:Ω, prod.mk (X.val ω) (Y.val ω) :=
begin
refl
end
def prod_measurable_set {β : Type*} {γ : Type*}
{Mβ : measurable_space β}
{Mγ : measurable_space γ}
(X:measurable_set Mβ) (Y:measurable_set Mγ):measurable_set (Mβ ×ₘ Mγ) := {
val := (set.prod X.val Y.val),
property := is_measurable_prod' X.property Y.property
}
lemma prod_measurable_set_val_def {β : Type*} {γ : Type*}
{Mβ : measurable_space β}
{Mγ : measurable_space γ}
(X:measurable_set Mβ) (Y:measurable_set Mγ):
(prod_measurable_set X Y).val = set.prod X.val Y.val := rfl
class has_measurable_equality {α:Type*} (M:measurable_space α):Prop := (is_measurable_eq:is_measurable {p:α × α|p.fst = p.snd})
def measurable_set_eq {α:Type*} {M:measurable_space α} [E:has_measurable_equality M]
:measurable_set (M ×ₘ M) := measurable_set.mk E.is_measurable_eq
lemma measurable_set_eq_val {α:Type*} {M:measurable_space α} [E:has_measurable_equality M]:
(@measurable_set_eq α M E).val = {p:α × α|p.fst = p.snd} := rfl
def measurable_set_ne {α:Type*} {M:measurable_space α} [E:has_measurable_equality M]
:measurable_set (M ×ₘ M) := measurable_set.mk (is_measurable.compl E.is_measurable_eq)
lemma measurable_set_ne_val {α:Type*} {M:measurable_space α} [E:has_measurable_equality M]:
(@measurable_set_ne α M E).val = {p:α × α|p.fst ≠ p.snd} := rfl
lemma diagonal_eq {α:Type*}:{p:α × α|p.fst = p.snd}=⋃ (a:α), set.prod {a} {a} :=
begin
ext,split;intros A1A;simp;simp at A1A,
{
apply exists.intro x.fst,
ext;simp,
rw A1A,
},
{
cases A1A with i A1A,
cases A1A,
simp,
},
end
instance measurable_set_eq_top_measurable {α:Type*} (E:encodable α) (M:top_measurable α):has_measurable_equality (M.to_measurable_space) := {
is_measurable_eq := begin
rw diagonal_eq,
apply is_measurable.Union,
intros a,
apply is_measurable_prod',
repeat {apply M.all_measurable},
end
}
instance measurable_set_eq_bool:has_measurable_equality bool.measurable_space := {
is_measurable_eq := begin
rw diagonal_eq,
apply is_measurable.Union,
intros a,
apply is_measurable_prod',
repeat {apply measurable_space.is_measurable_top},
end
}
instance measurable_set_eq_int:has_measurable_equality int.measurable_space := {
is_measurable_eq := begin
rw diagonal_eq,
apply is_measurable.Union,
intros a,
apply is_measurable_prod',
repeat {apply measurable_space.is_measurable_top},
end
}
def random_variable_eq {Ω:Type*} {P:probability_space Ω} {α:Type*} [M:measurable_space α]
[E:has_measurable_equality M] (X Y:P →ᵣ M):event P :=
(X ×ᵣ Y) ∈ᵣ (measurable_set_eq)
infixr ` =ᵣ `:100 := random_variable_eq
lemma rv_eq_val_def {α:Type*} {p : probability_space α} {β : Type*}
[Mβ :measurable_space β] [has_measurable_equality Mβ] (X Y:p →ᵣ Mβ):
(X =ᵣ Y).val = {a:α| X.val a = Y.val a} :=
begin
unfold random_variable_eq,
rw rv_event_val_def,
rw prod_random_variable_val_def,
rw measurable_set_eq_val,
simp,
end
def random_variable_ne {Ω:Type*} {P:probability_space Ω} {α:Type*} [M:measurable_space α]
[E:has_measurable_equality M] (X Y:P →ᵣ M):event P :=
¬ₑ (X =ᵣ Y)
infixr ` ≠ᵣ `:100 := random_variable_ne
lemma rv_ne_val_def {α:Type*} {p : probability_space α} {β : Type*}
[Mβ :measurable_space β] [has_measurable_equality Mβ] (X Y:p →ᵣ Mβ):
(X ≠ᵣ Y).val = {a:α| X.val a ≠ Y.val a} :=
begin
unfold random_variable_ne,
rw enot_val_def,
rw rv_eq_val_def,
simp,
ext a,split;intros A1;simp;simp at A1;apply A1,
end
lemma union_func_eq_sUnion_image {α β:Type*}
[Tβ:measurable_space β] {A:set α} {f:α → set β}:
(⋃ a∈ A, f a)=set.sUnion (@set.image α (set β) f A) :=
begin
simp,
end
lemma is_measurable_countable_union_func {α β:Type*}
[Tβ:measurable_space β] {A:set α} {f:α → set β}:
set.countable A →
(∀ a∈ A, is_measurable (f a)) →
is_measurable (⋃ a∈ A, f a) :=
begin
intros A1 A2,
rw union_func_eq_sUnion_image,
apply is_measurable.sUnion,
{
apply set.countable.image,
apply A1,
},
intros t A4,
cases A4 with a A5,
cases A5 with A6 A7,
subst t,
apply A2,
apply A6,
end
-- cf set.prod_singleton_singleton
lemma singleton_prod {α β:Type*} {ab:α × β}:{ab} = (@set.prod α β {ab.fst} {ab.snd}) :=
begin
simp,
end
lemma top_measurable_prodh {α β:Type*} [encodable α] [encodable β]
[Tα:top_measurable α] [Tβ:top_measurable β] (U:set (α × β)):
is_measurable U :=
begin
have A2:encodable (α × β):= encodable.prod,
have A3:set.countable U := set.countable_encodable U,
have A4:(⋃ a∈U,{a}) = U,
{
simp
},
rw ← A4,
apply is_measurable_countable_union_func A3,
intros ab A5,
rw singleton_prod,
apply is_measurable.prod,
{
apply top_measurable.all_measurable,
},
{
apply top_measurable.all_measurable,
},
end
instance top_measurable_prod {α β:Type*} [encodable α] [encodable β]
[Tα:top_measurable α] [Tβ:top_measurable β]:top_measurable (α × β) := {
all_measurable := top_measurable_prodh,
}
def if_measurable_fun
{α β:Type*}
{Mα:measurable_space α} {Mβ:measurable_space β}
(E:measurable_set Mα) (D:decidable_pred E.val)
(X:measurable_fun Mα Mβ) (Y:measurable_fun Mα Mβ):measurable_fun Mα Mβ :={
val := λ a:α, if (E.val a) then (X.val a) else (Y.val a),
property := measurable.if E.property X.property Y.property,
}
def if_random_variable
{α β:Type*}
{P:probability_space α} {Mβ:measurable_space β}
(E:event P) (D:decidable_pred E.val)
(X:random_variable P Mβ) (Y:random_variable P Mβ):random_variable P Mβ :=
if_measurable_fun E D X Y
lemma rv_event_IID {α : Type*} {p : probability_space α} {β : Type*}
[fintype β] {γ : Type*} [Mγ : measurable_space γ] (X:β → p →ᵣ Mγ) (S:measurable_set Mγ):
random_variables_IID X → events_IID (λ b:β, (X b) ∈ᵣ S) :=
begin
intro A1,
unfold random_variables_IID at A1,
cases A1 with A2 A3,
unfold random_variable_independent at A2,
unfold random_variable_identical at A3,
split,
{
apply A2,
},
{
intros i j,
simp,
apply A3,
}
end
lemma measurable_set_preimage_val_def {α:Type*} {β:Type*} [Mα:measurable_space α] [Mβ:measurable_space β]
(f:measurable_fun Mα Mβ) (S:measurable_set Mβ):
(measurable_set_preimage f S).val = (set.preimage (f.val) (S.val)) := rfl
lemma compose_measurable_fun_measurable_set {Ω : Type*} {β : Type*} {γ : Type*}
[MΩ : measurable_space Ω] [Mβ : measurable_space β]
[Mγ : measurable_space γ] (Y:Mβ →ₘ Mγ) (X:MΩ →ₘ Mβ) (S:measurable_set Mγ):
measurable_set_preimage (Y ∘m X) S = measurable_set_preimage X (measurable_set_preimage Y S) :=
begin
apply subtype.eq,
rw measurable_set_preimage_val_def,
rw measurable_set_preimage_val_def,
rw measurable_set_preimage_val_def,
rw compose_measurable_fun_val_def,
refl,
end
lemma rv_compose_measurable_set {α : Type*} {β : Type*} {γ : Type*}
{p : probability_space α} {Mβ : measurable_space β}
{Mγ : measurable_space γ} (X:measurable_fun Mβ Mγ) (Y:random_variable p Mβ) (S:measurable_set Mγ):
(X ∘r Y) ∈ᵣ S = (Y ∈ᵣ (measurable_set_preimage X S)) :=
begin
apply compose_measurable_fun_measurable_set,
end
lemma compose_independent {α:Type*} {p:probability_space α} {β:Type*}
[fintype β]
{γ:Type*} [Mγ:measurable_space γ]
{κ:Type*} [Mκ:measurable_space κ] (X:β → random_variable p Mγ) (Y:Mγ →ₘ Mκ):
random_variable_independent X → random_variable_independent (λ b:β, Y ∘r (X b)) :=
begin
unfold random_variable_independent,
intros A1 S T,
unfold independent_events,
have A2:(λ (b : β), Pr[(Y ∘r X b) ∈ᵣ S b]) =
(λ (b : β), Pr[(X b) ∈ᵣ (measurable_set_preimage Y (S b))]),
{
ext b,
rw rv_compose_measurable_set,
},
rw A2,
have A3:(λ (b : β), (Y ∘r X b) ∈ᵣ S b) =
(λ (b : β), (X b) ∈ᵣ (measurable_set_preimage Y (S b))),
{
ext b,
rw rv_compose_measurable_set,
},
rw A3,
apply A1,
end
lemma compose_identical {α:Type*} {p:probability_space α}
{γ:Type*} [Mγ:measurable_space γ]
{κ:Type*} [Mκ:measurable_space κ] (X₁ X₂:random_variable p Mγ) (Y:Mγ →ₘ Mκ):
random_variable_identical X₁ X₂ → random_variable_identical (Y ∘r X₁) (Y ∘r X₂) :=
begin
unfold random_variable_identical,
intro A1,
intros S,
rw rv_compose_measurable_set,
rw rv_compose_measurable_set,
apply A1,
end
lemma compose_IID {α:Type*} {p:probability_space α} {β:Type*}
[fintype β]
{γ:Type*} [Mγ:measurable_space γ]
{κ:Type*} [Mκ:measurable_space κ] (X:β → random_variable p Mγ) (Y:Mγ →ₘ Mκ):
random_variables_IID X → random_variables_IID (λ b:β, Y ∘r (X b)) :=
begin
unfold random_variables_IID,
intro A1,
cases A1 with A2 A3,
split,
{
apply compose_independent,
apply A2,
},
{
intros i j,
apply compose_identical,
apply A3,
}
end
--For Pr_disjoint_summable below.
lemma union_disjoint {Ω β:Type*} {p:probability_space Ω} [E:encodable β]
[D:decidable_eq β]
(A:β → event p) {S:finset β} {a:β}:(pairwise (disjoint on λ (i : β), (A i).val)) →
(a ∉ S) →
disjoint (A a).val (⋃ (b:β) (H:b∈ S), (A b).val) :=
begin
intros A1 A2,
rw set.disjoint_right,
intros ω A4 A3,
simp at A4,
cases A4 with i A4,
have A5:a ≠ i,
{
intro A5A,
apply A2,
rw A5A,
apply A4.left,
},
have A7 := A1 a i A5,
unfold function.on_fun at A7,
have A8 := set.disjoint_iff_inter_eq_empty.mp A7,
have A9:ω ∈ (A a).val ∩ (A i).val,
{
simp,
apply and.intro A3 (A4.right),
},
rw A8 at A9,
apply A9
end
lemma Pr_sum_disjoint_eq {Ω β:Type*} {p:probability_space Ω} [E:encodable β]
[D:decidable_eq β]
(A:β → event p) {S:finset β}:(pairwise (disjoint on λ (i : β), (A i).val)) →
Pr[eany_finset S A] =
finset.sum S (λ (b:β), Pr[A b]) :=
begin
intro A1,
apply finset.induction_on S,
{
simp,
rw ← ennreal.coe_eq_coe,
rw event_prob_def,
rw eany_finset_val_def,
simp,
},
{
intros a T A2 A3,
rw ← ennreal.coe_eq_coe,
rw event_prob_def,
rw finset.sum_insert,
rw ennreal.coe_add,
rw event_prob_def,
rw eany_finset_val_def,
rw finset.Union_insert',
have A4:measure_theory.measure_space.volume ((A a).val ∪ ⋃ (x : β) (H : x ∈ T), (A x).val) =
measure_theory.measure_space.volume ((A a).val) +
measure_theory.measure_space.volume (⋃ (x : β) (H : x ∈ T), (A x).val),
{
apply measure_theory.measure_union,
apply union_disjoint,
apply A1,
apply A2,
apply (A a).property,
apply finset_union_measurable,
intros b A4A,
apply (A b).property,
},
rw measure_eq_measure,
rw A4,
rw ← A3,
rw event_prob_def,
rw eany_finset_val_def,
rw measure_eq_measure,
rw measure_eq_measure,
apply A2
},
end
lemma Pr_sum_disjoint_bounded {Ω β:Type*} {p:probability_space Ω} [E:encodable β] [decidable_eq β]
(A:β → event p) {S:finset β}:(pairwise (disjoint on λ (i : β), (A i).val)) →
finset.sum S (λ (b:β), Pr[A b]) ≤ 1 :=
begin
intro A1,
rw ← Pr_sum_disjoint_eq,
apply Pr_event_le_1,
apply A1,
end
lemma Pr_disjoint_summable {Ω β:Type*} {p:probability_space Ω} [E:encodable β] [decidable_eq β]
(A:β → event p):(pairwise (disjoint on λ (i : β), (A i).val)) →
summable (λ (b:β), Pr[A b]) :=
begin
intro A1,
apply summable_bounded_nnreal,
{
intro S,
apply Pr_sum_disjoint_bounded,
apply A1,
},
end
lemma Pr_eany_sum {Ω β:Type*} {p:probability_space Ω} [E:encodable β] [decidable_eq β]
(A:β → event p):(pairwise (disjoint on λ (i : β), (A i).val)) →
Pr[eany A] = ∑' (b:β), Pr[A b] :=
begin
intro B1,
rw ← measurable_Union_eq_any,
rw ← with_top.coe_eq_coe,
rw event_prob_def,
rw measurable_Union_val_def,
rw ennreal.coe_tsum,
have A1:(λ (b:β), ↑Pr[A b]) = (λ (b:β), (measure_theory.measure_space.volume
(A b).val)),
{
ext b,
rw event_prob_def,
rw measure_eq_measure,
},
rw measure_eq_measure,
rw measure_theory.measure_Union,
rw sum_subst,
rw A1,
apply B1,
{
intro i,
apply (A i).property,
},
{
apply Pr_disjoint_summable,
apply B1,
},
end
lemma mem_prod_random_variable_prod_measurable_set
{α β γ:Type*}
{P:probability_space α} {Mβ:measurable_space β} {Mγ:measurable_space γ}
(X:random_variable P Mβ) (Y:random_variable P Mγ)
(S:measurable_set Mβ) (T:measurable_set Mγ):
(X ×ᵣ Y) ∈ᵣ (prod_measurable_set S T) =
(X ∈ᵣ S) ∧ₑ (Y∈ᵣ T) :=
begin
apply event.eq,
rw rv_event_val_def,
rw eand_val_def,
rw rv_event_val_def,
rw rv_event_val_def,
rw prod_random_variable_val_def,
rw prod_measurable_set_val_def,
ext a,
simp,
end
|
7d3c6754ec65ccc5afc6ffecd1da2a5e4864ed40 | dd4e652c749fea9ac77e404005cb3470e5f75469 | /src/string.lean | 2af8245ac07ef151689363e672a135241912a444 | [] | no_license | skbaek/cvx | e32822ad5943541539966a37dee162b0a5495f55 | c50c790c9116f9fac8dfe742903a62bdd7292c15 | refs/heads/master | 1,623,803,010,339 | 1,618,058,958,000 | 1,618,058,958,000 | 176,293,135 | 3 | 2 | null | null | null | null | UTF-8 | Lean | false | false | 256 | lean | namespace string
def resize_core : nat → list char → list char
| 0 _ := []
| k [] := list.repeat ' ' k
| (k+1) (c::cs) := c::(resize_core k cs)
def resize (k : nat) (s : string) : string :=
⟨resize_core k s.data⟩
end string |
9c1db62413e6de06b1852af6bd631c73fb63afca | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/data/bundle.lean | 30eb9875bdb20be193eb1c5ceeb4314aa6ddf652 | [
"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 | 5,134 | lean | /-
Copyright © 2021 Nicolò Cavalleri. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nicolò Cavalleri
-/
import tactic.basic
import algebra.module.basic
/-!
# Bundle
Basic data structure to implement fiber bundles, vector bundles (maybe fibrations?), etc. This file
should contain all possible results that do not involve any topology.
We represent a bundle `E` over a base space `B` as a dependent type `E : B → Type*`.
We provide a type synonym of `Σ x, E x` as `bundle.total_space E`, to be able to endow it with
a topology which is not the disjoint union topology `sigma.topological_space`. In general, the
constructions of fiber bundles we will make will be of this form.
## Main Definitions
* `bundle.total_space` the total space of a bundle.
* `bundle.total_space.proj` the projection from the total space to the base space.
* `bundle.total_space_mk` the constructor for the total space.
## References
- https://en.wikipedia.org/wiki/Bundle_(mathematics)
-/
namespace bundle
variables {B : Type*} (E : B → Type*)
/--
`bundle.total_space E` is the total space of the bundle `Σ x, E x`.
This type synonym is used to avoid conflicts with general sigma types.
-/
def total_space := Σ x, E x
instance [inhabited B] [inhabited (E default)] :
inhabited (total_space E) := ⟨⟨default, default⟩⟩
variables {E}
/-- `bundle.total_space.proj` is the canonical projection `bundle.total_space E → B` from the
total space to the base space. -/
@[simp, reducible] def total_space.proj : total_space E → B := sigma.fst
/-- Constructor for the total space of a bundle. -/
@[simp, reducible] def total_space_mk (b : B) (a : E b) :
bundle.total_space E := ⟨b, a⟩
lemma total_space.proj_mk {x : B} {y : E x} : (total_space_mk x y).proj = x :=
rfl
lemma sigma_mk_eq_total_space_mk {x : B} {y : E x} : sigma.mk x y = total_space_mk x y :=
rfl
lemma total_space.mk_cast {x x' : B} (h : x = x') (b : E x) :
total_space_mk x' (cast (congr_arg E h) b) = total_space_mk x b :=
by { subst h, refl }
lemma total_space.eta (z : total_space E) :
total_space_mk z.proj z.2 = z :=
sigma.eta z
instance {x : B} : has_coe_t (E x) (total_space E) := ⟨total_space_mk x⟩
@[simp] lemma coe_fst (x : B) (v : E x) : (v : total_space E).fst = x := rfl
@[simp] lemma coe_snd {x : B} {y : E x} : (y : total_space E).snd = y := rfl
lemma to_total_space_coe {x : B} (v : E x) : (v : total_space E) = total_space_mk x v := rfl
-- notation for the direct sum of two bundles over the same base
notation E₁ ` ×ᵇ `:100 E₂ := λ x, E₁ x × E₂ x
/-- `bundle.trivial B F` is the trivial bundle over `B` of fiber `F`. -/
def trivial (B : Type*) (F : Type*) : B → Type* := function.const B F
instance {F : Type*} [inhabited F] {b : B} : inhabited (bundle.trivial B F b) := ⟨(default : F)⟩
/-- The trivial bundle, unlike other bundles, has a canonical projection on the fiber. -/
def trivial.proj_snd (B : Type*) (F : Type*) : total_space (bundle.trivial B F) → F := sigma.snd
section pullback
variable {B' : Type*}
/-- The pullback of a bundle `E` over a base `B` under a map `f : B' → B`, denoted by `pullback f E`
or `f *ᵖ E`, is the bundle over `B'` whose fiber over `b'` is `E (f b')`. -/
@[nolint has_nonempty_instance] def pullback (f : B' → B) (E : B → Type*) := λ x, E (f x)
notation f ` *ᵖ ` E := pullback f E
/-- Natural embedding of the total space of `f *ᵖ E` into `B' × total_space E`. -/
@[simp] def pullback_total_space_embedding (f : B' → B) :
total_space (f *ᵖ E) → B' × total_space E :=
λ z, (z.proj, total_space_mk (f z.proj) z.2)
/-- The base map `f : B' → B` lifts to a canonical map on the total spaces. -/
def pullback.lift (f : B' → B) : total_space (f *ᵖ E) → total_space E :=
λ z, total_space_mk (f z.proj) z.2
@[simp] lemma pullback.proj_lift (f : B' → B) (x : total_space (f *ᵖ E)) :
(pullback.lift f x).proj = f x.1 :=
rfl
@[simp] lemma pullback.lift_mk (f : B' → B) (x : B') (y : E (f x)) :
pullback.lift f (total_space_mk x y) = total_space_mk (f x) y :=
rfl
lemma pullback_total_space_embedding_snd (f : B' → B) (x : total_space (f *ᵖ E)) :
(pullback_total_space_embedding f x).2 = pullback.lift f x :=
rfl
end pullback
section fiber_structures
variable [∀ x, add_comm_monoid (E x)]
@[simp] lemma coe_snd_map_apply (x : B) (v w : E x) :
(↑(v + w) : total_space E).snd = (v : total_space E).snd + (w : total_space E).snd := rfl
variables (R : Type*) [semiring R] [∀ x, module R (E x)]
@[simp] lemma coe_snd_map_smul (x : B) (r : R) (v : E x) :
(↑(r • v) : total_space E).snd = r • (v : total_space E).snd := rfl
end fiber_structures
section trivial_instances
variables {F : Type*} {R : Type*} [semiring R] (b : B)
instance [add_comm_monoid F] : add_comm_monoid (bundle.trivial B F b) := ‹add_comm_monoid F›
instance [add_comm_group F] : add_comm_group (bundle.trivial B F b) := ‹add_comm_group F›
instance [add_comm_monoid F] [module R F] : module R (bundle.trivial B F b) := ‹module R F›
end trivial_instances
end bundle
|
9da3268d38b82f4474765ac33feb4fcce9b92b01 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/ring_theory/free_comm_ring.lean | a6b8ee2fced5e18e246be370695090a5d40d31b6 | [
"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 | 14,500 | lean | /-
Copyright (c) 2019 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Johan Commelin
-/
import data.equiv.functor
import data.mv_polynomial.equiv
import data.mv_polynomial.comm_ring
import ring_theory.free_ring
import deprecated.ring
/-!
# Free commutative rings
The theory of the free commutative ring generated by a type `α`.
It is isomorphic to the polynomial ring over ℤ with variables
in `α`
## Main definitions
* `free_comm_ring α` : the free commutative ring on a type α
* `lift (f : α → R)` : the ring hom `free_comm_ring α →+* R` induced by functoriality from `f`.
* `map (f : α → β)` : the ring hom `free_comm_ring α →*+ free_comm_ring β` induced by
functoriality from f.
## Main results
`free_comm_ring` has functorial properties (it is an adjoint to the forgetful functor).
In this file we have:
* `of : α → free_comm_ring α`
* `lift (f : α → R) : free_comm_ring α →+* R`
* `map (f : α → β) : free_comm_ring α →+* free_comm_ring β`
* `free_comm_ring_equiv_mv_polynomial_int : free_comm_ring α ≃+* mv_polynomial α ℤ` :
`free_comm_ring α` is isomorphic to a polynomial ring.
## Implementation notes
`free_comm_ring α` is implemented not using `mv_polynomial` but
directly as the free abelian group on `multiset α`, the type
of monomials in this free commutative ring.
## Tags
free commutative ring, free ring
-/
noncomputable theory
open_locale classical
universes u v
variables (α : Type u)
/-- `free_comm_ring α` is the free commutative ring on the type `α`. -/
@[derive [comm_ring, inhabited]]
def free_comm_ring (α : Type u) : Type u :=
free_abelian_group $ multiplicative $ multiset α
namespace free_comm_ring
variables {α}
/-- The canonical map from `α` to the free commutative ring on `α`. -/
def of (x : α) : free_comm_ring α :=
free_abelian_group.of $ multiplicative.of_add ({x} : multiset α)
lemma of_injective : function.injective (of : α → free_comm_ring α) :=
free_abelian_group.of_injective.comp (λ x y,
(multiset.coe_eq_coe.trans list.singleton_perm_singleton).mp)
@[elab_as_eliminator] protected lemma induction_on
{C : free_comm_ring α → Prop} (z : free_comm_ring α)
(hn1 : C (-1)) (hb : ∀ b, C (of b))
(ha : ∀ x y, C x → C y → C (x + y))
(hm : ∀ x y, C x → C y → C (x * y)) : C z :=
have hn : ∀ x, C x → C (-x), from λ x ih, neg_one_mul x ▸ hm _ _ hn1 ih,
have h1 : C 1, from neg_neg (1 : free_comm_ring α) ▸ hn _ hn1,
free_abelian_group.induction_on z
(add_left_neg (1 : free_comm_ring α) ▸ ha _ _ hn1 h1)
(λ m, multiset.induction_on m h1 $ λ a m ih, hm _ _ (hb a) ih)
(λ m ih, hn _ ih)
ha
section lift
variables {R : Type v} [comm_ring R] (f : α → R)
/-- A helper to implement `lift`. This is essentially `free_comm_monoid.lift`, but this does not
currently exist. -/
private def lift_to_multiset : (α → R) ≃ (multiplicative (multiset α) →* R) :=
{ to_fun := λ f,
{ to_fun := λ s, (s.to_add.map f).prod,
map_mul' := λ x y, calc _ = multiset.prod ((multiset.map f x) + (multiset.map f y)) :
by {congr' 1, exact multiset.map_add _ _ _}
... = _ : multiset.prod_add _ _,
map_one' := rfl},
inv_fun := λ F x, F (multiplicative.of_add ({x} : multiset α)),
left_inv := λ f, funext $ λ x, show (multiset.map f {x}).prod = _, by simp,
right_inv := λ F, monoid_hom.ext $ λ x,
let F' := F.to_additive'', x' := x.to_add in show (multiset.map (λ a, F' {a}) x').sum = F' x',
begin
rw [←multiset.map_map, ←add_monoid_hom.map_multiset_sum],
exact F.congr_arg (multiset.sum_map_singleton x'),
end }
/-- Lift a map `α → R` to a additive group homomorphism `free_comm_ring α → R`.
For a version producing a bundled homomorphism, see `lift_hom`. -/
def lift : (α → R) ≃ (free_comm_ring α →+* R) :=
equiv.trans lift_to_multiset free_abelian_group.lift_monoid
@[simp] lemma lift_of (x : α) : lift f (of x) = f x :=
(free_abelian_group.lift.of _ _).trans $ mul_one _
@[simp] lemma lift_comp_of (f : free_comm_ring α →+* R) : lift (f ∘ of) = f :=
ring_hom.ext $ λ x, free_comm_ring.induction_on x
(by rw [ring_hom.map_neg, ring_hom.map_one, f.map_neg, f.map_one])
(lift_of _)
(λ x y ihx ihy, by rw [ring_hom.map_add, f.map_add, ihx, ihy])
(λ x y ihx ihy, by rw [ring_hom.map_mul, f.map_mul, ihx, ihy])
@[ext]
lemma hom_ext ⦃f g : free_comm_ring α →+* R⦄ (h : ∀ x, f (of x) = g (of x)) :
f = g :=
lift.symm.injective (funext h)
end lift
variables {β : Type v} (f : α → β)
/-- A map `f : α → β` produces a ring homomorphism `free_comm_ring α →+* free_comm_ring β`. -/
def map : free_comm_ring α →+* free_comm_ring β :=
lift $ of ∘ f
@[simp]
lemma map_of (x : α) : map f (of x) = of (f x) := lift_of _ _
/-- `is_supported x s` means that all monomials showing up in `x` have variables in `s`. -/
def is_supported (x : free_comm_ring α) (s : set α) : Prop :=
x ∈ subring.closure (of '' s)
section is_supported
variables {x y : free_comm_ring α} {s t : set α}
theorem is_supported_upwards (hs : is_supported x s) (hst : s ⊆ t) :
is_supported x t :=
subring.closure_mono (set.monotone_image hst) hs
theorem is_supported_add (hxs : is_supported x s) (hys : is_supported y s) :
is_supported (x + y) s :=
subring.add_mem _ hxs hys
theorem is_supported_neg (hxs : is_supported x s) :
is_supported (-x) s :=
subring.neg_mem _ hxs
theorem is_supported_sub (hxs : is_supported x s) (hys : is_supported y s) :
is_supported (x - y) s :=
subring.sub_mem _ hxs hys
theorem is_supported_mul (hxs : is_supported x s) (hys : is_supported y s) :
is_supported (x * y) s :=
subring.mul_mem _ hxs hys
theorem is_supported_zero : is_supported 0 s :=
subring.zero_mem _
theorem is_supported_one : is_supported 1 s :=
subring.one_mem _
theorem is_supported_int {i : ℤ} {s : set α} : is_supported ↑i s :=
int.induction_on i is_supported_zero
(λ i hi, by rw [int.cast_add, int.cast_one]; exact is_supported_add hi is_supported_one)
(λ i hi, by rw [int.cast_sub, int.cast_one]; exact is_supported_sub hi is_supported_one)
end is_supported
/-- The restriction map from `free_comm_ring α` to `free_comm_ring s` where `s : set α`, defined
by sending all variables not in `s` to zero. -/
def restriction (s : set α) [decidable_pred (∈ s)] : free_comm_ring α →+* free_comm_ring s :=
lift (λ p, if H : p ∈ s then of (⟨p, H⟩ : s) else 0)
section restriction
variables (s : set α) [decidable_pred (∈ s)] (x y : free_comm_ring α)
@[simp] lemma restriction_of (p) :
restriction s (of p) = if H : p ∈ s then of ⟨p, H⟩ else 0 := lift_of _ _
end restriction
theorem is_supported_of {p} {s : set α} : is_supported (of p) s ↔ p ∈ s :=
suffices is_supported (of p) s → p ∈ s, from ⟨this, λ hps, subring.subset_closure ⟨p, hps, rfl⟩⟩,
assume hps : is_supported (of p) s, begin
haveI := classical.dec_pred s,
have : ∀ x, is_supported x s →
∃ (n : ℤ), lift (λ a, if a ∈ s then (0 : polynomial ℤ) else polynomial.X) x = n,
{ intros x hx, refine subring.in_closure.rec_on hx _ _ _ _,
{ use 1, rw [ring_hom.map_one], norm_cast },
{ use -1, rw [ring_hom.map_neg, ring_hom.map_one], norm_cast },
{ rintros _ ⟨z, hzs, rfl⟩ _ _, use 0, rw [ring_hom.map_mul, lift_of, if_pos hzs, zero_mul],
norm_cast },
{ rintros x y ⟨q, hq⟩ ⟨r, hr⟩, refine ⟨q+r, _⟩, rw [ring_hom.map_add, hq, hr], norm_cast } },
specialize this (of p) hps, rw [lift_of] at this, split_ifs at this, { exact h },
exfalso, apply ne.symm int.zero_ne_one,
rcases this with ⟨w, H⟩, rw ←polynomial.C_eq_int_cast at H,
have : polynomial.X.coeff 1 = (polynomial.C ↑w).coeff 1, by rw H,
rwa [polynomial.coeff_C, if_neg (one_ne_zero : 1 ≠ 0), polynomial.coeff_X, if_pos rfl] at this
end
theorem map_subtype_val_restriction {x} (s : set α) [decidable_pred (∈ s)]
(hxs : is_supported x s) :
map (subtype.val : s → α) (restriction s x) = x :=
begin
refine subring.in_closure.rec_on hxs _ _ _ _,
{ rw ring_hom.map_one, refl },
{ rw [ring_hom.map_neg, ring_hom.map_neg, ring_hom.map_one], refl },
{ rintros _ ⟨p, hps, rfl⟩ n ih,
rw [ring_hom.map_mul, restriction_of, dif_pos hps, ring_hom.map_mul, map_of, ih] },
{ intros x y ihx ihy, rw [ring_hom.map_add, ring_hom.map_add, ihx, ihy] }
end
theorem exists_finite_support (x : free_comm_ring α) :
∃ s : set α, set.finite s ∧ is_supported x s :=
free_comm_ring.induction_on x
⟨∅, set.finite_empty, is_supported_neg is_supported_one⟩
(λ p, ⟨{p}, set.finite_singleton p, is_supported_of.2 $ set.mem_singleton _⟩)
(λ x y ⟨s, hfs, hxs⟩ ⟨t, hft, hxt⟩, ⟨s ∪ t, hfs.union hft, is_supported_add
(is_supported_upwards hxs $ set.subset_union_left s t)
(is_supported_upwards hxt $ set.subset_union_right s t)⟩)
(λ x y ⟨s, hfs, hxs⟩ ⟨t, hft, hxt⟩, ⟨s ∪ t, hfs.union hft, is_supported_mul
(is_supported_upwards hxs $ set.subset_union_left s t)
(is_supported_upwards hxt $ set.subset_union_right s t)⟩)
theorem exists_finset_support (x : free_comm_ring α) : ∃ s : finset α, is_supported x ↑s :=
let ⟨s, hfs, hxs⟩ := exists_finite_support x in ⟨hfs.to_finset, by rwa set.finite.coe_to_finset⟩
end free_comm_ring
namespace free_ring
open function
variable (α)
/-- The canonical ring homomorphism from the free ring generated by `α` to the free commutative ring
generated by `α`. -/
def to_free_comm_ring {α} : free_ring α →+* free_comm_ring α :=
free_ring.lift free_comm_ring.of
instance : has_coe (free_ring α) (free_comm_ring α) := ⟨to_free_comm_ring⟩
/-- The natural map `free_ring α → free_comm_ring α`, as a `ring_hom`. -/
def coe_ring_hom : free_ring α →+* free_comm_ring α := to_free_comm_ring
@[simp, norm_cast] protected lemma coe_zero : ↑(0 : free_ring α) = (0 : free_comm_ring α) := rfl
@[simp, norm_cast] protected lemma coe_one : ↑(1 : free_ring α) = (1 : free_comm_ring α) := rfl
variable {α}
@[simp] protected lemma coe_of (a : α) : ↑(free_ring.of a) = free_comm_ring.of a :=
free_ring.lift_of _ _
@[simp, norm_cast] protected lemma coe_neg (x : free_ring α) : ↑(-x) = -(x : free_comm_ring α) :=
(free_ring.lift _).map_neg _
@[simp, norm_cast] protected lemma coe_add (x y : free_ring α) :
↑(x + y) = (x : free_comm_ring α) + y :=
(free_ring.lift _).map_add _ _
@[simp, norm_cast] protected lemma coe_sub (x y : free_ring α) :
↑(x - y) = (x : free_comm_ring α) - y :=
(free_ring.lift _).map_sub _ _
@[simp, norm_cast] protected lemma coe_mul (x y : free_ring α) :
↑(x * y) = (x : free_comm_ring α) * y :=
(free_ring.lift _).map_mul _ _
variable (α)
protected lemma coe_surjective : surjective (coe : free_ring α → free_comm_ring α) :=
λ x,
begin
apply free_comm_ring.induction_on x,
{ use -1, refl },
{ intro x, use free_ring.of x, refl },
{ rintros _ _ ⟨x, rfl⟩ ⟨y, rfl⟩, use x + y, exact (free_ring.lift _).map_add _ _ },
{ rintros _ _ ⟨x, rfl⟩ ⟨y, rfl⟩, use x * y, exact (free_ring.lift _).map_mul _ _ }
end
lemma coe_eq :
(coe : free_ring α → free_comm_ring α) =
@functor.map free_abelian_group _ _ _ (λ (l : list α), (l : multiset α)) :=
funext $ λ x, free_abelian_group.lift.unique _ _ $ λ L,
by { simp_rw [free_abelian_group.lift.of, (∘)], exact free_monoid.rec_on L rfl
(λ hd tl ih, by { rw [(free_monoid.lift _).map_mul, free_monoid.lift_eval_of, ih], refl }) }
-- FIXME This was in `deprecated.ring`, but only used here.
-- It would be good to inline it into the next construction.
/-- Interpret an equivalence `f : R ≃ S` as a ring equivalence `R ≃+* S`. -/
def of' {R S : Type*} [ring R] [ring S] (e : R ≃ S) (he : is_ring_hom e) : R ≃+* S :=
{ .. e,
.. monoid_hom.of he.to_is_semiring_hom.to_is_monoid_hom,
.. add_monoid_hom.of he.to_is_semiring_hom.to_is_add_monoid_hom }
/-- If α has size at most 1 then the natural map from the free ring on `α` to the
free commutative ring on `α` is an isomorphism of rings. -/
def subsingleton_equiv_free_comm_ring [subsingleton α] :
free_ring α ≃+* free_comm_ring α :=
@of' (free_ring α) (free_comm_ring α) _ _
(functor.map_equiv free_abelian_group (multiset.subsingleton_equiv α)) $
begin
delta functor.map_equiv,
rw congr_arg is_ring_hom _,
work_on_goal 2 { symmetry, exact coe_eq α },
exact (coe_ring_hom _).to_is_ring_hom,
end
instance [subsingleton α] : comm_ring (free_ring α) :=
{ mul_comm := λ x y,
by { rw [← (subsingleton_equiv_free_comm_ring α).symm_apply_apply (y * x),
((subsingleton_equiv_free_comm_ring α)).map_mul,
mul_comm,
← ((subsingleton_equiv_free_comm_ring α)).map_mul,
(subsingleton_equiv_free_comm_ring α).symm_apply_apply], },
.. free_ring.ring α }
end free_ring
/-- The free commutative ring on `α` is isomorphic to the polynomial ring over ℤ with
variables in `α` -/
def free_comm_ring_equiv_mv_polynomial_int :
free_comm_ring α ≃+* mv_polynomial α ℤ :=
ring_equiv.of_hom_inv
(free_comm_ring.lift $ λ a, mv_polynomial.X a)
(mv_polynomial.eval₂_hom (int.cast_ring_hom (free_comm_ring α)) free_comm_ring.of)
(by { ext, simp })
(by ext; simp )
/-- The free commutative ring on the empty type is isomorphic to `ℤ`. -/
def free_comm_ring_pempty_equiv_int : free_comm_ring pempty.{u+1} ≃+* ℤ :=
ring_equiv.trans (free_comm_ring_equiv_mv_polynomial_int _)
(mv_polynomial.is_empty_ring_equiv _ pempty)
/-- The free commutative ring on a type with one term is isomorphic to `ℤ[X]`. -/
def free_comm_ring_punit_equiv_polynomial_int : free_comm_ring punit.{u+1} ≃+* polynomial ℤ :=
(free_comm_ring_equiv_mv_polynomial_int _).trans (mv_polynomial.punit_alg_equiv ℤ).to_ring_equiv
open free_ring
/-- The free ring on the empty type is isomorphic to `ℤ`. -/
def free_ring_pempty_equiv_int : free_ring pempty.{u+1} ≃+* ℤ :=
ring_equiv.trans (subsingleton_equiv_free_comm_ring _) free_comm_ring_pempty_equiv_int
/-- The free ring on a type with one term is isomorphic to `ℤ[X]`. -/
def free_ring_punit_equiv_polynomial_int : free_ring punit.{u+1} ≃+* polynomial ℤ :=
ring_equiv.trans (subsingleton_equiv_free_comm_ring _) free_comm_ring_punit_equiv_polynomial_int
|
160c69d4ca5a339441cf2c209f42cd8ab0a488b7 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /hott/homotopy/EM.hlean | d17c0a906f524796d093bbdbfdd1425710981b6e | [
"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 | 11,783 | hlean | /-
Copyright (c) 2016 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
Eilenberg MacLane spaces
-/
import hit.groupoid_quotient .hopf .freudenthal .homotopy_group
open algebra pointed nat eq category group algebra is_trunc iso pointed unit trunc equiv is_conn
function is_equiv
namespace EM
open groupoid_quotient
variables {G : Group}
definition EM1 (G : Group) : Type :=
groupoid_quotient (Groupoid_of_Group G)
definition pEM1 [constructor] (G : Group) : Type* :=
pointed.MK (EM1 G) (elt star)
definition base : EM1 G := elt star
definition pth : G → base = base := pth
definition resp_mul (g h : G) : pth (g * h) = pth g ⬝ pth h := resp_comp h g
definition resp_one : pth (1 : G) = idp :=
resp_id star
definition resp_inv (g : G) : pth (g⁻¹) = (pth g)⁻¹ :=
resp_inv g
local attribute pointed.MK pointed.carrier pEM1 EM1 [reducible]
protected definition rec {P : EM1 G → Type} [H : Π(x : EM1 G), is_trunc 1 (P x)]
(Pb : P base) (Pp : Π(g : G), Pb =[pth g] Pb)
(Pmul : Π(g h : G), change_path (resp_mul g h) (Pp (g * h)) = Pp g ⬝o Pp h) (x : EM1 G) : P x :=
begin
induction x,
{ induction g, exact Pb},
{ induction a, induction b, exact Pp f},
{ induction a, induction b, induction c, exact Pmul f g}
end
protected definition rec_on {P : EM1 G → Type} [H : Π(x : EM1 G), is_trunc 1 (P x)]
(x : EM1 G) (Pb : P base) (Pp : Π(g : G), Pb =[pth g] Pb)
(Pmul : Π(g h : G), change_path (resp_mul g h) (Pp (g * h)) = Pp g ⬝o Pp h) : P x :=
EM.rec Pb Pp Pmul x
protected definition set_rec {P : EM1 G → Type} [H : Π(x : EM1 G), is_set (P x)]
(Pb : P base) (Pp : Π(g : G), Pb =[pth g] Pb) (x : EM1 G) : P x :=
EM.rec Pb Pp !center x
protected definition prop_rec {P : EM1 G → Type} [H : Π(x : EM1 G), is_prop (P x)]
(Pb : P base) (x : EM1 G) : P x :=
EM.rec Pb !center !center x
definition rec_pth {P : EM1 G → Type} [H : Π(x : EM1 G), is_trunc 1 (P x)]
{Pb : P base} {Pp : Π(g : G), Pb =[pth g] Pb}
(Pmul : Π(g h : G), change_path (resp_mul g h) (Pp (g * h)) = Pp g ⬝o Pp h)
(g : G) : apd (EM.rec Pb Pp Pmul) (pth g) = Pp g :=
proof !rec_pth qed
protected definition elim {P : Type} [is_trunc 1 P] (Pb : P) (Pp : Π(g : G), Pb = Pb)
(Pmul : Π(g h : G), Pp (g * h) = Pp g ⬝ Pp h) (x : EM1 G) : P :=
begin
induction x,
{ exact Pb},
{ exact Pp f},
{ exact Pmul f g}
end
protected definition elim_on [reducible] {P : Type} [is_trunc 1 P] (x : EM1 G)
(Pb : P) (Pp : G → Pb = Pb) (Pmul : Π(g h : G), Pp (g * h) = Pp g ⬝ Pp h) : P :=
EM.elim Pb Pp Pmul x
protected definition set_elim [reducible] {P : Type} [is_set P] (Pb : P) (Pp : G → Pb = Pb)
(x : EM1 G) : P :=
EM.elim Pb Pp !center x
protected definition prop_elim [reducible] {P : Type} [is_prop P] (Pb : P) (x : EM1 G) : P :=
EM.elim Pb !center !center x
definition elim_pth {P : Type} [is_trunc 1 P] {Pb : P} {Pp : G → Pb = Pb}
(Pmul : Π(g h : G), Pp (g * h) = Pp g ⬝ Pp h) (g : G) : ap (EM.elim Pb Pp Pmul) (pth g) = Pp g :=
proof !elim_pth qed
protected definition elim_set.{u} (Pb : Set.{u}) (Pp : Π(g : G), Pb ≃ Pb)
(Pmul : Π(g h : G) (x : Pb), Pp (g * h) x = Pp h (Pp g x)) (x : EM1 G) : Set.{u} :=
groupoid_quotient.elim_set (λu, Pb) (λu v, Pp) (λu v w g h, proof Pmul h g qed) x
theorem elim_set_pth {Pb : Set} {Pp : Π(g : G), Pb ≃ Pb}
(Pmul : Π(g h : G) (x : Pb), Pp (g * h) x = Pp h (Pp g x)) (g : G) :
transport (EM.elim_set Pb Pp Pmul) (pth g) = Pp g :=
!elim_set_pth
end EM
attribute EM.base [constructor]
attribute EM.rec EM.elim [unfold 7] [recursor 7]
attribute EM.rec_on EM.elim_on [unfold 4]
attribute EM.set_rec EM.set_elim [unfold 6]
attribute EM.prop_rec EM.prop_elim EM.elim_set [unfold 5]
namespace EM
open groupoid_quotient
variables (G : Group)
definition base_eq_base_equiv [constructor] : (base = base :> pEM1 G) ≃ G :=
!elt_eq_elt_equiv
definition fundamental_group_pEM1 : π₁ (pEM1 G) ≃g G :=
begin
fapply isomorphism_of_equiv,
{ exact trunc_equiv_trunc 0 !base_eq_base_equiv ⬝e trunc_equiv 0 G},
{ intros g h, induction g with p, induction h with q,
exact encode_con p q}
end
proposition is_trunc_pEM1 [instance] : is_trunc 1 (pEM1 G) :=
!is_trunc_groupoid_quotient
proposition is_trunc_EM1 [instance] : is_trunc 1 (EM1 G) :=
!is_trunc_groupoid_quotient
proposition is_conn_EM1 [instance] : is_conn 0 (EM1 G) :=
by apply @is_conn_groupoid_quotient; esimp; exact _
proposition is_conn_pEM1 [instance] : is_conn 0 (pEM1 G) :=
is_conn_EM1 G
variable {G}
definition EM1_map [unfold 7] {X : Type*} (e : Ω X ≃ G)
(r : Πp q, e (p ⬝ q) = e p * e q) [is_conn 0 X] [is_trunc 1 X] : EM1 G → X :=
begin
intro x, induction x using EM.elim,
{ exact Point X},
{ exact e⁻¹ᵉ g},
{ exact inv_preserve_binary e concat mul r g h}
end
end EM
open hopf susp
namespace EM
-- The K(G,n+1):
variables {G : CommGroup} (n : ℕ)
definition EM1_mul [unfold 2 3] (x x' : EM1 G) : EM1 G :=
begin
induction x,
{ exact x'},
{ induction x' using EM.set_rec,
{ exact pth g},
{ exact abstract begin apply loop_pathover, apply square_of_eq,
refine !resp_mul⁻¹ ⬝ _ ⬝ !resp_mul,
exact ap pth !mul.comm end end}},
{ refine EM.prop_rec _ x', apply resp_mul}
end
variable (G)
definition EM1_mul_one (x : EM1 G) : EM1_mul x base = x :=
begin
induction x using EM.set_rec,
{ reflexivity},
{ apply eq_pathover_id_right, apply hdeg_square, refine EM.elim_pth _ g}
end
definition h_space_EM1 [constructor] [instance] : h_space (pEM1 G) :=
begin
fapply h_space.mk,
{ exact EM1_mul},
{ exact base},
{ intro x', reflexivity},
{ apply EM1_mul_one}
end
/- K(G, n+1) -/
definition EMadd1 (n : ℕ) : Type* :=
ptrunc (n+1) (iterate_psusp n (pEM1 G))
definition loop_EM2 : Ω[1] (EMadd1 G 1) ≃* pEM1 G :=
begin
apply hopf.delooping, reflexivity
end
definition homotopy_group_EM2 : πg[1+1] (EMadd1 G 1) ≃g G :=
begin
refine ghomotopy_group_succ_in _ 0 ⬝g _,
refine homotopy_group_isomorphism_of_pequiv 0 (loop_EM2 G) ⬝g _,
apply fundamental_group_pEM1
end
definition homotopy_group_EMadd1 (n : ℕ) : πg[n+1] (EMadd1 G n) ≃g G :=
begin
cases n with n,
{ refine homotopy_group_isomorphism_of_pequiv 0 _ ⬝g fundamental_group_pEM1 G,
apply ptrunc_pequiv, apply is_trunc_pEM1},
induction n with n IH,
{ apply homotopy_group_EM2 G},
refine _ ⬝g IH,
refine !ghomotopy_group_ptrunc ⬝g _ ⬝g !ghomotopy_group_ptrunc⁻¹ᵍ,
apply iterate_psusp_stability_isomorphism,
rexact add_mul_le_mul_add n 1 1
end
section
local attribute EMadd1 [reducible]
definition is_conn_EMadd1 [instance] (n : ℕ) : is_conn n (EMadd1 G n) := _
definition is_trunc_EMadd1 [instance] (n : ℕ) : is_trunc (n+1) (EMadd1 G n) :=
_
end
/- K(G, n) -/
definition EM (G : CommGroup) : ℕ → Type*
| 0 := pType_of_Group G
| (k+1) := EMadd1 G k
namespace ops
abbreviation K := @EM
end ops
open ops
definition homotopy_group_EM (n : ℕ) : π[n] (EM G n) ≃* pType_of_Group G :=
begin
cases n with n,
{ rexact ptrunc_pequiv 0 (pType_of_Group G) _},
{ apply pequiv_of_isomorphism (homotopy_group_EMadd1 G n)}
end
definition ghomotopy_group_EM (n : ℕ) : πg[n+1] (EM G (n+1)) ≃g G :=
homotopy_group_EMadd1 G n
definition is_conn_EM [instance] (n : ℕ) : is_conn (n.-1) (EM G n) :=
begin
cases n with n,
{ apply is_conn_minus_one, apply tr, unfold [EM], exact 1},
{ apply is_conn_EMadd1}
end
definition is_conn_EM_succ [instance] (n : ℕ) : is_conn n (EM G (succ n)) :=
is_conn_EM G (succ n)
definition is_trunc_EM [instance] (n : ℕ) : is_trunc n (EM G n) :=
begin
cases n with n,
{ unfold [EM], apply semigroup.is_set_carrier},
{ apply is_trunc_EMadd1}
end
/- Uniqueness of K(G, 1) -/
variable {H : Group}
definition pEM1_pmap [constructor] {X : Type*} (e : Ω X ≃ H)
(r : Πp q, e (p ⬝ q) = e p * e q) [is_conn 0 X] [is_trunc 1 X] : pEM1 H →* X :=
begin
apply pmap.mk (EM1_map e r),
reflexivity,
end
variable (H)
definition loop_pEM1 [constructor] : Ω (pEM1 H) ≃* pType_of_Group H :=
pequiv_of_equiv (base_eq_base_equiv H) idp
variable {H}
definition loop_pEM1_pmap {X : Type*} (e : Ω X ≃ H)
(r : Πp q, e (p ⬝ q) = e p * e q) [is_conn 0 X] [is_trunc 1 X] :
Ω→(pEM1_pmap e r) ~ e⁻¹ᵉ ∘ base_eq_base_equiv H :=
begin
apply homotopy_of_inv_homotopy_pre (base_eq_base_equiv H),
intro g, exact !idp_con ⬝ !elim_pth
end
open trunc_index
definition pEM1_pequiv'.{u} {G : Group.{u}} {X : pType.{u}} (e : Ω X ≃ G)
(r : Πp q, e (p ⬝ q) = e p * e q) [is_conn 0 X] [is_trunc 1 X] : pEM1 G ≃* X :=
begin
apply pequiv_of_pmap (pEM1_pmap e r),
apply whitehead_principle_pointed 1,
intro k, cases k with k,
{ apply @is_equiv_of_is_contr,
all_goals (esimp; exact _)},
{ cases k with k,
{ apply is_equiv_trunc_functor, esimp,
apply is_equiv.homotopy_closed, rotate 1,
{ symmetry, exact loop_pEM1_pmap _ _},
apply is_equiv_compose, apply to_is_equiv},
{ apply @is_equiv_of_is_contr,
do 2 exact trivial_homotopy_group_of_is_trunc _ (succ_lt_succ !zero_lt_succ)}}
end
definition pEM1_pequiv.{u} {G : Group.{u}} {X : pType.{u}} (e : π₁ X ≃g G)
[is_conn 0 X] [is_trunc 1 X] : pEM1 G ≃* X :=
begin
apply pEM1_pequiv' (!trunc_equiv⁻¹ᵉ ⬝e equiv_of_isomorphism e),
intro p q, esimp, exact to_respect_mul e (tr p) (tr q)
end
definition pEM1_pequiv_type {X : Type*} [is_conn 0 X] [is_trunc 1 X] : pEM1 (π₁ X) ≃* X :=
pEM1_pequiv !isomorphism.refl
definition EM_pequiv_1.{u} {G : CommGroup.{u}} {X : pType.{u}} (e : π₁ X ≃g G)
[is_conn 0 X] [is_trunc 1 X] : EM G 1 ≃* X :=
begin
refine _ ⬝e* pEM1_pequiv e,
apply ptrunc_pequiv,
apply is_trunc_pEM1
end
variable (G)
definition EMadd1_pequiv_pEM1 : EMadd1 G 0 ≃* pEM1 G :=
begin apply ptrunc_pequiv, apply is_trunc_pEM1 end
definition EM1add1_pequiv_0.{u} {G : CommGroup.{u}} {X : pType.{u}}
(e : π₁ X ≃g G) [is_conn 0 X] [is_trunc 1 X] : EMadd1 G 0 ≃* X :=
EMadd1_pequiv_pEM1 G ⬝e* pEM1_pequiv e
definition KG1_pequiv.{u} {X Y : pType.{u}} (e : π₁ X ≃g π₁ Y)
[is_conn 0 X] [is_trunc 1 X] [is_conn 0 Y] [is_trunc 1 Y] : X ≃* Y :=
(pEM1_pequiv e)⁻¹ᵉ* ⬝e* pEM1_pequiv !isomorphism.refl
open circle int
definition EM_pequiv_circle : K agℤ 1 ≃* S¹* :=
!EMadd1_pequiv_pEM1 ⬝e* pEM1_pequiv fundamental_group_of_circle
/- loops of EM-spaces -/
variable {G}
definition loop_EMadd1 (n : ℕ) : Ω (EMadd1 G (succ n)) ≃* EMadd1 G n :=
begin
cases n with n,
{ symmetry, apply EM1add1_pequiv_0, rexact homotopy_group_EMadd1 G 1,
-- apply is_conn_loop, apply is_conn_EMadd1,
apply is_trunc_loop, apply is_trunc_EMadd1},
{ refine loop_ptrunc_pequiv _ _ ⬝e* _,
rewrite [add_one, succ_sub_two],
have succ n + 1 ≤ 2 * succ n, from add_mul_le_mul_add n 1 1,
symmetry, refine freudenthal_pequiv _ this, }
end
variable (G)
definition loop_EM (n : ℕ) : Ω (K G (succ n)) ≃* K G n :=
begin
cases n with n,
{ refine _ ⬝e* pequiv_of_isomorphism (fundamental_group_pEM1 G),
refine loop_pequiv_loop (EMadd1_pequiv_pEM1 G) ⬝e* _,
symmetry, apply ptrunc_pequiv, exact _},
{ apply loop_EMadd1}
end
end EM
|
9ed9c58dac6bbe5a559f4d53e609b8457f5f76dc | 4727251e0cd73359b15b664c3170e5d754078599 | /src/data/list/of_fn.lean | 6e1e9563a30fdba7470ced1a77235d11b22bbc3c | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 4,088 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.fin.basic
import data.list.basic
/-!
# Lists from functions
Theorems and lemmas for dealing with `list.of_fn`, which converts a function on `fin n` to a list
of length `n`.
## Main Definitions
The main definitions pertain to lists generated using `of_fn`
- `list.length_of_fn`, which tells us the length of such a list
- `list.nth_of_fn`, which tells us the nth element of such a list
- `list.array_eq_of_fn`, which interprets the list form of an array as such a list.
-/
universes u
variables {α : Type u}
open nat
namespace list
lemma length_of_fn_aux {n} (f : fin n → α) :
∀ m h l, length (of_fn_aux f m h l) = length l + m
| 0 h l := rfl
| (succ m) h l := (length_of_fn_aux m _ _).trans (succ_add _ _)
/-- The length of a list converted from a function is the size of the domain. -/
@[simp] theorem length_of_fn {n} (f : fin n → α) : length (of_fn f) = n :=
(length_of_fn_aux f _ _ _).trans (zero_add _)
lemma nth_of_fn_aux {n} (f : fin n → α) (i) :
∀ m h l,
(∀ i, nth l i = of_fn_nth_val f (i + m)) →
nth (of_fn_aux f m h l) i = of_fn_nth_val f i
| 0 h l H := H i
| (succ m) h l H := nth_of_fn_aux m _ _ begin
intro j, cases j with j,
{ simp only [nth, of_fn_nth_val, zero_add, dif_pos (show m < n, from h)] },
{ simp only [nth, H, add_succ, succ_add] }
end
/-- The `n`th element of a list -/
@[simp] theorem nth_of_fn {n} (f : fin n → α) (i) :
nth (of_fn f) i = of_fn_nth_val f i :=
nth_of_fn_aux f _ _ _ _ $ λ i,
by simp only [of_fn_nth_val, dif_neg (not_lt.2 (nat.le_add_left n i))]; refl
theorem nth_le_of_fn {n} (f : fin n → α) (i : fin n) :
nth_le (of_fn f) i ((length_of_fn f).symm ▸ i.2) = f i :=
option.some.inj $ by rw [← nth_le_nth];
simp only [list.nth_of_fn, of_fn_nth_val, fin.eta, dif_pos i.is_lt]
@[simp] theorem nth_le_of_fn' {n} (f : fin n → α) {i : ℕ} (h : i < (of_fn f).length) :
nth_le (of_fn f) i h = f ⟨i, ((length_of_fn f) ▸ h)⟩ :=
nth_le_of_fn f ⟨i, ((length_of_fn f) ▸ h)⟩
@[simp] lemma map_of_fn {β : Type*} {n : ℕ} (f : fin n → α) (g : α → β) :
map g (of_fn f) = of_fn (g ∘ f) :=
ext_le (by simp) (λ i h h', by simp)
/-- Arrays converted to lists are the same as `of_fn` on the indexing function of the array. -/
theorem array_eq_of_fn {n} (a : array n α) : a.to_list = of_fn a.read :=
suffices ∀ {m h l}, d_array.rev_iterate_aux a
(λ i, cons) m h l = of_fn_aux (d_array.read a) m h l, from this,
begin
intros, induction m with m IH generalizing l, {refl},
simp only [d_array.rev_iterate_aux, of_fn_aux, IH]
end
/-- `of_fn` on an empty domain is the empty list. -/
@[simp] theorem of_fn_zero (f : fin 0 → α) : of_fn f = [] := rfl
@[simp] theorem of_fn_succ {n} (f : fin (succ n) → α) :
of_fn f = f 0 :: of_fn (λ i, f i.succ) :=
suffices ∀ {m h l}, of_fn_aux f (succ m) (succ_le_succ h) l =
f 0 :: of_fn_aux (λ i, f i.succ) m h l, from this,
begin
intros, induction m with m IH generalizing l, {refl},
rw [of_fn_aux, IH], refl
end
theorem of_fn_nth_le : ∀ l : list α, of_fn (λ i, nth_le l i i.2) = l
| [] := rfl
| (a::l) := by { rw of_fn_succ, congr, simp only [fin.coe_succ], exact of_fn_nth_le l }
-- not registered as a simp lemma, as otherwise it fires before `forall_mem_of_fn_iff` which
-- is much more useful
lemma mem_of_fn {n} (f : fin n → α) (a : α) :
a ∈ of_fn f ↔ a ∈ set.range f :=
begin
simp only [mem_iff_nth_le, set.mem_range, nth_le_of_fn'],
exact ⟨λ ⟨i, hi, h⟩, ⟨_, h⟩, λ ⟨i, hi⟩, ⟨i.1, (length_of_fn f).symm ▸ i.2, by simpa using hi⟩⟩
end
@[simp] lemma forall_mem_of_fn_iff {n : ℕ} {f : fin n → α} {P : α → Prop} :
(∀ i ∈ of_fn f, P i) ↔ ∀ j : fin n, P (f j) :=
by simp only [mem_of_fn, set.forall_range_iff]
@[simp] lemma of_fn_const (n : ℕ) (c : α) :
of_fn (λ i : fin n, c) = repeat c n :=
nat.rec_on n (by simp) $ λ n ihn, by simp [ihn]
end list
|
18198986bcaaf243559b94ceee66b16878defe48 | 57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d | /stage0/src/Init/Data/Float.lean | 9664fedc4a3875ae4bc89614a8a3788a6c2fbf66 | [
"Apache-2.0"
] | permissive | collares/lean4 | 861a9269c4592bce49b71059e232ff0bfe4594cc | 52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee | refs/heads/master | 1,691,419,031,324 | 1,618,678,138,000 | 1,618,678,138,000 | 358,989,750 | 0 | 0 | Apache-2.0 | 1,618,696,333,000 | 1,618,696,333,000 | null | UTF-8 | Lean | false | false | 4,558 | lean | /-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Core
import Init.Data.Int.Basic
import Init.Data.ToString.Basic
structure FloatSpec where
float : Type
val : float
lt : float → float → Prop
le : float → float → Prop
decLt : DecidableRel lt
decLe : DecidableRel le
-- Just show FloatSpec is inhabited.
constant floatSpec : FloatSpec := {
float := Unit,
val := (),
lt := fun _ _ => True,
le := fun _ _ => True,
decLt := fun _ _ => inferInstanceAs (Decidable True),
decLe := fun _ _ => inferInstanceAs (Decidable True)
}
structure Float where
val : floatSpec.float
instance : Inhabited Float := ⟨{ val := floatSpec.val }⟩
@[extern "lean_float_of_nat"] constant Float.ofNat : (@& Nat) → Float
@[extern c inline "#1 + #2"] constant Float.add : Float → Float → Float
@[extern c inline "#1 - #2"] constant Float.sub : Float → Float → Float
@[extern c inline "#1 * #2"] constant Float.mul : Float → Float → Float
@[extern c inline "#1 / #2"] constant Float.div : Float → Float → Float
@[extern c inline "(- #1)"] constant Float.neg : Float → Float
def Float.ofInt : Int → Float
| Int.ofNat n => Float.ofNat n
| Int.negSucc n => Float.neg (Float.ofNat (Nat.succ n))
set_option bootstrap.genMatcherCode false
def Float.lt : Float → Float → Prop := fun a b =>
match a, b with
| ⟨a⟩, ⟨b⟩ => floatSpec.lt a b
def Float.le : Float → Float → Prop := fun a b =>
floatSpec.le a.val b.val
instance : OfNat Float n := ⟨Float.ofNat n⟩
instance : Add Float := ⟨Float.add⟩
instance : Sub Float := ⟨Float.sub⟩
instance : Mul Float := ⟨Float.mul⟩
instance : Div Float := ⟨Float.div⟩
instance : Neg Float := ⟨Float.neg⟩
instance : HasLess Float := ⟨Float.lt⟩
instance : HasLessEq Float := ⟨Float.le⟩
@[extern c inline "#1 == #2"] constant Float.beq (a b : Float) : Bool
instance : BEq Float := ⟨Float.beq⟩
@[extern c inline "#1 < #2"] constant Float.decLt (a b : Float) : Decidable (a < b) :=
match a, b with
| ⟨a⟩, ⟨b⟩ => floatSpec.decLt a b
@[extern c inline "#1 <= #2"] constant Float.decLe (a b : Float) : Decidable (a ≤ b) :=
match a, b with
| ⟨a⟩, ⟨b⟩ => floatSpec.decLe a b
instance floatDecLt (a b : Float) : Decidable (a < b) := Float.decLt a b
instance floatDecLe (a b : Float) : Decidable (a ≤ b) := Float.decLe a b
@[extern "lean_float_to_string"] constant Float.toString : Float → String
@[extern c inline "(uint8_t)#1"] constant Float.toUInt8 : Float → UInt8
@[extern c inline "(uint16_t)#1"] constant Float.toUInt16 : Float → UInt16
@[extern c inline "(uint32_t)#1"] constant Float.toUInt32 : Float → UInt32
@[extern c inline "(uint64_t)#1"] constant Float.toUInt64 : Float → UInt64
@[extern c inline "(size_t)#1"] constant Float.toUSize : Float → USize
instance : ToString Float where
toString := Float.toString
instance : Repr Float where
reprPrec n _ := Float.toString n
instance : ReprAtom Float := ⟨⟩
abbrev Nat.toFloat (n : Nat) : Float :=
Float.ofNat n
@[extern "sin"] constant Float.sin : Float → Float
@[extern "cos"] constant Float.cos : Float → Float
@[extern "tan"] constant Float.tan : Float → Float
@[extern "asin"] constant Float.asin : Float → Float
@[extern "acos"] constant Float.acos : Float → Float
@[extern "atan"] constant Float.atan : Float → Float
@[extern "atan2"] constant Float.atan2 : Float → Float → Float
@[extern "sinh"] constant Float.sinh : Float → Float
@[extern "cosh"] constant Float.cosh : Float → Float
@[extern "tanh"] constant Float.tanh : Float → Float
@[extern "asinh"] constant Float.asinh : Float → Float
@[extern "acosh"] constant Float.acosh : Float → Float
@[extern "atanh"] constant Float.atanh : Float → Float
@[extern "exp"] constant Float.exp : Float → Float
@[extern "exp2"] constant Float.exp2 : Float → Float
@[extern "log"] constant Float.log : Float → Float
@[extern "log2"] constant Float.log2 : Float → Float
@[extern "log10"] constant Float.log10 : Float → Float
@[extern "pow"] constant Float.pow : Float → Float → Float
@[extern "sqrt"] constant Float.sqrt : Float → Float
@[extern "cbrt"] constant Float.cbrt : Float → Float
instance : Pow Float := ⟨Float.pow⟩
@[extern "lean_float_of_scientific"] constant Float.ofScientific (m : Nat) (s : Bool) (e : Nat) : Float
|
cc0f3abe755fee02645aa928252c12566dfeae4a | e514e8b939af519a1d5e9b30a850769d058df4e9 | /src/tactic/rewrite_search/core/engine.lean | 28b2b572947e594323224be728b62ec08d2ffcfa | [] | no_license | semorrison/lean-rewrite-search | dca317c5a52e170fb6ffc87c5ab767afb5e3e51a | e804b8f2753366b8957be839908230ee73f9e89f | refs/heads/master | 1,624,051,754,485 | 1,614,160,817,000 | 1,614,160,817,000 | 162,660,605 | 0 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 11,410 | lean | import tactic.rewrite_search.discovery.collect
import lib.string
import .types
import .debug
import .backtrack
import .explain
universe u
namespace tactic.rewrite_search
variables {α β γ δ : Type} (i : inst α β γ δ) (g : search_state α β γ δ) (m : metric α β γ δ)
private meta def chop : list char → list string → list string
| [] l := l
| (c :: rest) l := chop rest $ list.join $ l.map $ string.split_on c
meta def tokenise_expr (e : expr) : tactic (string × list string) := do
pp ← to_string <$> tactic.pp e,
pure (pp, chop [' '/-, '(', ')'-/] [pp])
namespace search_state
meta def unmark_all_visited : tactic (search_state α β γ δ) := do
return { g with vertices := g.vertices.map $ λ v, {v with visited := ff} }
meta def reset_estimate (init : init_bound_fn α β γ δ) (de : dist_estimate γ) : tactic (dist_estimate γ) := do
(vl, vr) ← g.get_estimate_verts de,
return de
meta def reset_all_estimates (init : init_bound_fn α β γ δ) : tactic (search_state α β γ δ) := do
new_estimates ← g.estimates.mmap $ g.reset_estimate init,
return { g with estimates := new_estimates }
private meta def register_tokens_aux (s : side) : table token → list string → table token × list table_ref
| tokens [] := (tokens, [])
| tokens (tstr :: rest) := do
let (tokens, t) := find_or_create_token tokens s tstr,
let (tokens, l) := register_tokens_aux tokens rest,
(tokens, t.id :: l)
meta def register_tokens (s : side) (strs : list string) : search_state α β γ δ × list table_ref :=
let (new_tokens, refs) := register_tokens_aux s g.tokens strs in
({g with tokens := new_tokens}, refs)
private meta def find_vertex_aux (pp : string) : list vertex → option vertex
| [] := none
| (a :: rest) := if a.pp = pp then some a else find_vertex_aux rest
-- Find the vertex with the given (e : expr), or return the null verterx if not
-- found.
meta def find_vertex (e : expr) : tactic (option vertex) := do
pp ← to_string <$> tactic.pp e,
return (g.vertices.find_key pp)
-- Forcibly add a new vertex to the vertex table. You probably actually want to call
-- add_vertex, which will check that we haven't seen the vertex before first.
meta def alloc_vertex (e : expr) (root : bool) (s : side) : tactic (search_state α β γ δ × vertex) :=
do (pp, tokens) ← tokenise_expr e,
let (g, token_refs) := g.register_tokens s tokens,
let v : vertex := vertex.create g.vertices.next_id e pp token_refs root s,
return ({ g with vertices := g.vertices.alloc v }, v)
-- Look up the given vertex associated to (e : expr), or create it if it is
-- not already present.
meta def add_vertex_aux (e : expr) (root : bool) (s : side) : tactic (search_state α β γ δ × vertex) :=
do maybe_v ← g.find_vertex e,
match maybe_v with
| none := do
(g, v) ← g.alloc_vertex e root s,
g.tracer_vertex_added v,
return (g, v)
| (some v) := return (g, v)
end
meta def add_vertex (e : expr) (s : side) :=
g.add_vertex_aux e ff s
meta def add_root_vertex (e : expr) (s : side) :=
g.add_vertex_aux e tt s
meta def register_solved (e : edge) : search_state α β γ δ :=
{ g with solving_edge := some e }
meta def add_adj (v : vertex) (e : edge) : search_state α β γ δ × vertex :=
g.set_vertex { v with adj := v.adj.alloc e }
meta def publish_parent (f t : vertex) (e : edge) : search_state α β γ δ × vertex :=
if t.root then
(g, t)
else
match t.parent with
| some parent := (g, t)
| none := g.set_vertex { t with parent := some e }
end
meta def mark_vertex_visited (v : vertex) : tactic (search_state α β γ δ × vertex) := do
return $ g.set_vertex { v with visited := tt }
meta def add_edge (f t : vertex) (proof : tactic expr) (how : how) : tactic (search_state α β γ δ × vertex × vertex × edge) :=
do let new_edge : edge := ⟨ f.id, t.id, proof, how ⟩,
g.tracer_edge_added new_edge,
let (g, f) := g.add_adj f new_edge,
let (g, t) := g.add_adj t new_edge,
let (g, t) := g.publish_parent f t new_edge,
if ¬(vertex.same_side f t) then
return (g.register_solved new_edge, f, t, new_edge)
else
return (g, f, t, new_edge)
meta def commit_rewrite (f : vertex) (r : rewrite) : tactic (search_state α β γ δ × vertex × (vertex × edge)) := do
(g, v) ← g.add_vertex r.e f.s,
(g, f, v, e) ← g.add_edge f v r.prf r.how,
return (g, f, (v, e))
meta def reveal_more_rewrites (v : vertex) : tactic (search_state α β γ δ × vertex × option rewrite) := do
(rw_prog, new_rws) ← discover_more_rewrites g.rs v.exp g.rwall_conf v.s v.rw_prog,
(g, v) ← pure $ g.set_vertex {v with rw_prog := rw_prog, rws := v.rws.alloc_list new_rws},
return (g, v, new_rws.nth 0)
-- TODO implement a table-backed queue?
meta def reveal_more_adjs (o : vertex) : tactic (search_state α β γ δ × vertex × option (vertex × edge)) := do
(g, o, rw) ← match o.rws.at_ref o.rw_front with
| none := g.reveal_more_rewrites o
| some rw := pure (g, o, some rw)
end,
match rw with
| none := return (g, o, none)
| some rw := do
(g, o, (v, e)) ← g.commit_rewrite o rw,
(g, o) ← pure $ g.set_vertex {o with rw_front := o.rw_front.next},
return (g, o, some (v, e))
end
meta def visit_vertex (v : vertex) : tactic (search_state α β γ δ × rewriterator) :=
do
(g, v) ← if ¬v.visited then do
g.tracer_visited v,
g.mark_vertex_visited v
else
pure (g, v),
return ⟨g, ⟨v.id, table_ref.first⟩⟩
meta def improve_estimate_over (threshold : dnum) (de : dist_estimate γ) : tactic (search_state α β γ δ × dist_estimate γ) := do
(vl, vr) ← g.get_estimate_verts de,
let new_bnd := m.improve_estimate_over g threshold vl vr de.bnd,
let new_de := {de with bnd := new_bnd},
return ({g with estimates := g.estimates.update new_de}, new_de)
meta def alloc_estimate (p : pair) : tactic (search_state α β γ δ × table_ref) := do
(vl, vr) ← g.lookup_pair p,
let ref := g.estimates.next_id,
let new_estimates := g.estimates.alloc ⟨p, ref, m.init_bound g vl vr⟩,
return ({g with estimates := new_estimates}, ref)
/-- Check if `eq.refl _` suffices to prove the two sides are equal. -/
meta def try_unify (p : pair) : tactic (search_state α β γ δ × bool) := do
(lhs, rhs) ← g.lookup_pair p,
prf ← tactic.try_core $ tactic.attempt_refl lhs.exp rhs.exp,
match prf with
| none := return (g, ff)
| some prf := do
(g, _) ← g.add_edge lhs rhs (pure prf) how.defeq,
return (g, tt)
end
-- Currently, we guarentee that if the boolean we return is true, then there
-- is at least new rewrite possible in the environment which was not accessible
-- before. This follows here since it is (currently) guaranteed that each
-- element of `discovery.more_candidates` has an application *somewhere*.
meta def be_desperate (goals : list pair) : tactic (search_state α β γ δ × bool) :=
if g.stats.num_discovers ≥ g.conf.max_discovers then
return (g, ff)
else do
let g := g.mutate_stats {g.stats with num_discovers := g.stats.num_discovers + 1},
let verts := (goals.map sided_pair.to_list).join,
exprs ← list.erase_dup <$> (verts.mmap $ λ v, vertex.exp <$> g.vertices.get v),
(prog, new_cands) ← discovery.collect_more g.conf g.rs g.prog exprs,
let g := {g with prog := prog, rs := g.rs.append new_cands},
g ← if new_cands.length = 0 then pure g else g.unmark_all_visited,
return (g, new_cands.length > 0)
end search_state
namespace rewriterator
private meta def advance (it : rewriterator) : rewriterator := {it with front := it.front.next}
meta def next (it : rewriterator) (g : search_state α β γ δ) : tactic (search_state α β γ δ × rewriterator × option (vertex × edge)) := do
o ← g.vertices.get it.orig,
match o.adj.at_ref it.front with
| some e := do
v ← g.vertices.get e.t,
return (g, advance it, some (v, e))
| none := do
(g, o, ret) ← g.reveal_more_adjs o,
match ret with
| some (v, e) := return (g, advance it, some (v, e))
| none := return (g, it, none)
end
end
meta def exhaust : rewriterator → search_state α β γ δ → tactic (search_state α β γ δ × rewriterator × list (vertex × edge))
| it g := do
(g, it, ret) ← it.next g,
match ret with
| none := return (g, it, [])
| some (v, e) := do
(g, it, rest) ← exhaust it g,
return (g, it, ((v, e) :: rest))
end
end rewriterator
namespace search_state
meta def exhaust_vertex (v : vertex) : tactic (search_state α β γ δ) := do
(g, it) ← g.visit_vertex v,
(g, it) ← it.exhaust g,
return g
meta def exhaust_all_visited_aux : search_state α β γ δ → list vertex → tactic (search_state α β γ δ)
| g [] := return g
| g (v :: rest) := do
g ← g.exhaust_vertex v,
exhaust_all_visited_aux g rest
meta def exhaust_all_visited : tactic (search_state α β γ δ) :=
g.exhaust_all_visited_aux g.vertices.to_list
-- Find a vertex we haven't visited, and visit it. The bool is true if there might
-- be other unvisited vertices.
meta def exhaust_one_unvisited : list vertex → tactic (search_state α β γ δ × bool)
| [] := return (g, ff)
| (v :: rest) :=
if v.visited then
exhaust_one_unvisited rest
else do
g ← g.exhaust_vertex v,
return (g, tt)
meta def exhaust_all_unvisited : search_state α β γ δ → tactic (search_state α β γ δ)
| g := do
(g, more_left) ← g.exhaust_one_unvisited g.vertices.to_list,
if more_left then g.exhaust_all_unvisited else return g
meta def exhaust_all : tactic (search_state α β γ δ) := do
g ← g.exhaust_all_visited,
g ← g.exhaust_all_unvisited,
return g
end search_state
namespace inst
meta def mutate : inst α β γ δ :=
{ i with g := g }
meta def step_once (itr : ℕ) : tactic (inst α β γ δ × status) :=
match i.g.solving_edge with
| some e := return (i, status.done e)
| none := do
if itr > i.g.conf.max_iterations then
return (i, status.abort "max iterations reached!")
else do
g ← i.metric.update i.g itr,
(g, s) ← i.strategy.step g i.metric itr,
return (i.mutate g, s)
end
meta def finish_search (e : edge) : tactic (inst α β γ δ × search_result) := do
-- This must be called before i.g.exhaust_all
(proof, units) ← backtrack.build_proof i e,
i ← if i.g.conf.exhaustive then do
g ← i.g.exhaust_all,
pure $ i.mutate g
else
pure i,
return (i, search_result.success proof units)
meta def search_until_solved_aux : inst α β γ δ → ℕ → tactic (inst α β γ δ × search_result)
| i itr := do
(i, s) ← i.step_once itr,
match s with
| status.continue := search_until_solved_aux i (itr + 1)
| status.repeat := search_until_solved_aux i itr
| status.abort r := return (i, search_result.failure ("aborted: " ++ r))
| status.done e := i.finish_search e
end
meta def search_until_solved : tactic (inst α β γ δ × search_result) := do
if i.g.conf.trace_rules then (do
rs ← i.g.rs.mmap pp_rule,
tactic.trace $ "rewrite_search using:\n---\n" ++ (string.intercalate "\n" rs) ++ "\n---"
) else tactic.skip,
i.search_until_solved_aux 0
meta def explain (proof : expr) (steps : list proof_unit) : tactic string :=
explain_search_result i.g.conf i.g.rs proof steps
end inst
end tactic.rewrite_search
|
30e0bd1d3e77a330e5728e9e97c06fffc1f58b7d | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/ring_theory/noetherian.lean | a0067dc2d6d6f95ccb888b5f7687fb666fdd6597 | [
"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 | 22,602 | lean | /-
Copyright (c) 2018 Mario Carneiro, Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kevin Buzzard
-/
import algebra.algebra.subalgebra.basic
import algebra.algebra.tower
import algebra.ring.idempotents
import group_theory.finiteness
import linear_algebra.linear_independent
import order.compactly_generated
import order.order_iso_nat
import ring_theory.finiteness
import ring_theory.nilpotent
/-!
# Noetherian rings and modules
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
The following are equivalent for a module M over a ring R:
1. Every increasing chain of submodules M₁ ⊆ M₂ ⊆ M₃ ⊆ ⋯ eventually stabilises.
2. Every submodule is finitely generated.
A module satisfying these equivalent conditions is said to be a *Noetherian* R-module.
A ring is a *Noetherian ring* if it is Noetherian as a module over itself.
(Note that we do not assume yet that our rings are commutative,
so perhaps this should be called "left Noetherian".
To avoid cumbersome names once we specialize to the commutative case,
we don't make this explicit in the declaration names.)
## Main definitions
Let `R` be a ring and let `M` and `P` be `R`-modules. Let `N` be an `R`-submodule of `M`.
* `is_noetherian R M` is the proposition that `M` is a Noetherian `R`-module. It is a class,
implemented as the predicate that all `R`-submodules of `M` are finitely generated.
## Main statements
* `is_noetherian_iff_well_founded` is the theorem that an R-module M is Noetherian iff
`>` is well-founded on `submodule R M`.
Note that the Hilbert basis theorem, that if a commutative ring R is Noetherian then so is R[X],
is proved in `ring_theory.polynomial`.
## References
* [M. F. Atiyah and I. G. Macdonald, *Introduction to commutative algebra*][atiyah-macdonald]
* [samuel1967]
## Tags
Noetherian, noetherian, Noetherian ring, Noetherian module, noetherian ring, noetherian module
-/
open set
open_locale big_operators pointwise
/--
`is_noetherian R M` is the proposition that `M` is a Noetherian `R`-module,
implemented as the predicate that all `R`-submodules of `M` are finitely generated.
-/
class is_noetherian (R M) [semiring R] [add_comm_monoid M] [module R M] : Prop :=
(noetherian : ∀ (s : submodule R M), s.fg)
section
variables {R : Type*} {M : Type*} {P : Type*}
variables [semiring R] [add_comm_monoid M] [add_comm_monoid P]
variables [module R M] [module R P]
open is_noetherian
include R
/-- An R-module is Noetherian iff all its submodules are finitely-generated. -/
lemma is_noetherian_def : is_noetherian R M ↔ ∀ (s : submodule R M), s.fg :=
⟨λ h, h.noetherian, is_noetherian.mk⟩
theorem is_noetherian_submodule {N : submodule R M} :
is_noetherian R N ↔ ∀ s : submodule R M, s ≤ N → s.fg :=
begin
refine ⟨λ ⟨hn⟩, λ s hs, have s ≤ N.subtype.range, from (N.range_subtype).symm ▸ hs,
submodule.map_comap_eq_self this ▸ (hn _).map _, λ h, ⟨λ s, _⟩⟩,
have f := (submodule.equiv_map_of_injective N.subtype subtype.val_injective s).symm,
have h₁ := h (s.map N.subtype) (submodule.map_subtype_le N s),
have h₂ : (⊤ : submodule R (s.map N.subtype)).map f = ⊤ := by simp,
have h₃ := ((submodule.fg_top _).2 h₁).map (↑f : _ →ₗ[R] s),
exact (submodule.fg_top _).1 (h₂ ▸ h₃),
end
theorem is_noetherian_submodule_left {N : submodule R M} :
is_noetherian R N ↔ ∀ s : submodule R M, (N ⊓ s).fg :=
is_noetherian_submodule.trans
⟨λ H s, H _ inf_le_left, λ H s hs, (inf_of_le_right hs) ▸ H _⟩
theorem is_noetherian_submodule_right {N : submodule R M} :
is_noetherian R N ↔ ∀ s : submodule R M, (s ⊓ N).fg :=
is_noetherian_submodule.trans
⟨λ H s, H _ inf_le_right, λ H s hs, (inf_of_le_left hs) ▸ H _⟩
instance is_noetherian_submodule' [is_noetherian R M] (N : submodule R M) : is_noetherian R N :=
is_noetherian_submodule.2 $ λ _ _, is_noetherian.noetherian _
lemma is_noetherian_of_le {s t : submodule R M} [ht : is_noetherian R t]
(h : s ≤ t) : is_noetherian R s :=
is_noetherian_submodule.mpr (λ s' hs', is_noetherian_submodule.mp ht _ (le_trans hs' h))
variable (M)
theorem is_noetherian_of_surjective (f : M →ₗ[R] P) (hf : f.range = ⊤)
[is_noetherian R M] : is_noetherian R P :=
⟨λ s, have (s.comap f).map f = s, from submodule.map_comap_eq_self $ hf.symm ▸ le_top,
this ▸ (noetherian _).map _⟩
variable {M}
theorem is_noetherian_of_linear_equiv (f : M ≃ₗ[R] P)
[is_noetherian R M] : is_noetherian R P :=
is_noetherian_of_surjective _ f.to_linear_map f.range
lemma is_noetherian_top_iff :
is_noetherian R (⊤ : submodule R M) ↔ is_noetherian R M :=
begin
unfreezingI { split; assume h },
{ exact is_noetherian_of_linear_equiv (linear_equiv.of_top (⊤ : submodule R M) rfl) },
{ exact is_noetherian_of_linear_equiv (linear_equiv.of_top (⊤ : submodule R M) rfl).symm },
end
lemma is_noetherian_of_injective [is_noetherian R P] (f : M →ₗ[R] P) (hf : function.injective f) :
is_noetherian R M :=
is_noetherian_of_linear_equiv (linear_equiv.of_injective f hf).symm
lemma fg_of_injective [is_noetherian R P] {N : submodule R M} (f : M →ₗ[R] P)
(hf : function.injective f) : N.fg :=
@@is_noetherian.noetherian _ _ _ (is_noetherian_of_injective f hf) N
end
namespace module
variables {R M N : Type*}
variables [semiring R] [add_comm_monoid M] [add_comm_monoid N] [module R M] [module R N]
variables (R M)
@[priority 100] -- see Note [lower instance priority]
instance is_noetherian.finite [is_noetherian R M] : finite R M :=
⟨is_noetherian.noetherian ⊤⟩
variables {R M}
lemma finite.of_injective [is_noetherian R N] (f : M →ₗ[R] N)
(hf : function.injective f) : finite R M :=
⟨fg_of_injective f hf⟩
end module
section
variables {R : Type*} {M : Type*} {P : Type*}
variables [ring R] [add_comm_group M] [add_comm_group P]
variables [module R M] [module R P]
open is_noetherian
include R
lemma is_noetherian_of_ker_bot [is_noetherian R P] (f : M →ₗ[R] P) (hf : f.ker = ⊥) :
is_noetherian R M :=
is_noetherian_of_linear_equiv (linear_equiv.of_injective f $ linear_map.ker_eq_bot.mp hf).symm
lemma fg_of_ker_bot [is_noetherian R P] {N : submodule R M} (f : M →ₗ[R] P) (hf : f.ker = ⊥) :
N.fg :=
@@is_noetherian.noetherian _ _ _ (is_noetherian_of_ker_bot f hf) N
instance is_noetherian_prod [is_noetherian R M]
[is_noetherian R P] : is_noetherian R (M × P) :=
⟨λ s, submodule.fg_of_fg_map_of_fg_inf_ker (linear_map.snd R M P) (noetherian _) $
have s ⊓ linear_map.ker (linear_map.snd R M P) ≤ linear_map.range (linear_map.inl R M P),
from λ x ⟨hx1, hx2⟩, ⟨x.1, prod.ext rfl $ eq.symm $ linear_map.mem_ker.1 hx2⟩,
submodule.map_comap_eq_self this ▸ (noetherian _).map _⟩
instance is_noetherian_pi {R ι : Type*} {M : ι → Type*} [ring R]
[Π i, add_comm_group (M i)] [Π i, module R (M i)] [finite ι]
[∀ i, is_noetherian R (M i)] : is_noetherian R (Π i, M i) :=
begin
casesI nonempty_fintype ι,
haveI := classical.dec_eq ι,
suffices on_finset : ∀ s : finset ι, is_noetherian R (Π i : s, M i),
{ let coe_e := equiv.subtype_univ_equiv finset.mem_univ,
letI : is_noetherian R (Π i : finset.univ, M (coe_e i)) := on_finset finset.univ,
exact is_noetherian_of_linear_equiv (linear_equiv.Pi_congr_left R M coe_e), },
intro s,
induction s using finset.induction with a s has ih,
{ exact ⟨λ s, by convert submodule.fg_bot⟩ },
refine @is_noetherian_of_linear_equiv _ _ _ _ _ _ _ _
_ (@is_noetherian_prod _ (M a) _ _ _ _ _ _ _ ih),
fconstructor,
{ exact λ f i, or.by_cases (finset.mem_insert.1 i.2)
(λ h : i.1 = a, show M i.1, from (eq.rec_on h.symm f.1))
(λ h : i.1 ∈ s, show M i.1, from f.2 ⟨i.1, h⟩) },
{ intros f g, ext i, unfold or.by_cases, cases i with i hi,
rcases finset.mem_insert.1 hi with rfl | h,
{ change _ = _ + _, simp only [dif_pos], refl },
{ change _ = _ + _, have : ¬i = a, { rintro rfl, exact has h },
simp only [dif_neg this, dif_pos h], refl } },
{ intros c f, ext i, unfold or.by_cases, cases i with i hi,
rcases finset.mem_insert.1 hi with rfl | h,
{ change _ = c • _, simp only [dif_pos], refl },
{ change _ = c • _, have : ¬i = a, { rintro rfl, exact has h },
simp only [dif_neg this, dif_pos h], refl } },
{ exact λ f, (f ⟨a, finset.mem_insert_self _ _⟩, λ i, f ⟨i.1, finset.mem_insert_of_mem i.2⟩) },
{ intro f, apply prod.ext,
{ simp only [or.by_cases, dif_pos] },
{ ext ⟨i, his⟩,
have : ¬i = a, { rintro rfl, exact has his },
simp only [or.by_cases, this, not_false_iff, dif_neg] } },
{ intro f, ext ⟨i, hi⟩,
rcases finset.mem_insert.1 hi with rfl | h,
{ simp only [or.by_cases, dif_pos], },
{ have : ¬i = a, { rintro rfl, exact has h },
simp only [or.by_cases, dif_neg this, dif_pos h], } }
end
/-- A version of `is_noetherian_pi` for non-dependent functions. We need this instance because
sometimes Lean fails to apply the dependent version in non-dependent settings (e.g., it fails to
prove that `ι → ℝ` is finite dimensional over `ℝ`). -/
instance is_noetherian_pi' {R ι M : Type*} [ring R] [add_comm_group M] [module R M] [finite ι]
[is_noetherian R M] : is_noetherian R (ι → M) :=
is_noetherian_pi
end
open is_noetherian submodule function
section
universe w
variables {R M P : Type*} {N : Type w} [semiring R] [add_comm_monoid M] [module R M]
[add_comm_monoid N] [module R N] [add_comm_monoid P] [module R P]
theorem is_noetherian_iff_well_founded :
is_noetherian R M ↔ well_founded ((>) : submodule R M → submodule R M → Prop) :=
begin
rw (complete_lattice.well_founded_characterisations $ submodule R M).out 0 3,
exact ⟨λ ⟨h⟩, λ k, (fg_iff_compact k).mp (h k), λ h, ⟨λ k, (fg_iff_compact k).mpr (h k)⟩⟩,
end
lemma is_noetherian_iff_fg_well_founded :
is_noetherian R M ↔ well_founded
((>) : { N : submodule R M // N.fg } → { N : submodule R M // N.fg } → Prop) :=
begin
let α := { N : submodule R M // N.fg },
split,
{ introI H,
let f : α ↪o submodule R M := order_embedding.subtype _,
exact order_embedding.well_founded f.dual (is_noetherian_iff_well_founded.mp H) },
{ intro H,
constructor,
intro N,
obtain ⟨⟨N₀, h₁⟩, e : N₀ ≤ N, h₂⟩ := well_founded.has_min
H { N' : α | N'.1 ≤ N } ⟨⟨⊥, submodule.fg_bot⟩, bot_le⟩,
convert h₁,
refine (e.antisymm _).symm,
by_contra h₃,
obtain ⟨x, hx₁ : x ∈ N, hx₂ : x ∉ N₀⟩ := set.not_subset.mp h₃,
apply hx₂,
have := eq_of_le_of_not_lt _ (h₂ ⟨(R ∙ x) ⊔ N₀, _⟩ _),
{ injection this with eq,
rw eq,
exact (le_sup_left : (R ∙ x) ≤ (R ∙ x) ⊔ N₀) (submodule.mem_span_singleton_self _) },
{ exact submodule.fg.sup ⟨{x}, by rw [finset.coe_singleton]⟩ h₁ },
{ show N₀ ≤ (R ∙ x) ⊔ N₀, from le_sup_right },
{ exact sup_le ((submodule.span_singleton_le_iff_mem _ _).mpr hx₁) e } }
end
variables (R M)
lemma well_founded_submodule_gt (R M) [semiring R] [add_comm_monoid M] [module R M] :
∀ [is_noetherian R M], well_founded ((>) : submodule R M → submodule R M → Prop) :=
is_noetherian_iff_well_founded.mp
variables {R M}
/-- A module is Noetherian iff every nonempty set of submodules has a maximal submodule among them.
-/
theorem set_has_maximal_iff_noetherian :
(∀ a : set $ submodule R M, a.nonempty → ∃ M' ∈ a, ∀ I ∈ a, ¬ M' < I) ↔ is_noetherian R M :=
by rw [is_noetherian_iff_well_founded, well_founded.well_founded_iff_has_min]
/-- A module is Noetherian iff every increasing chain of submodules stabilizes. -/
theorem monotone_stabilizes_iff_noetherian :
(∀ (f : ℕ →o submodule R M), ∃ n, ∀ m, n ≤ m → f n = f m) ↔ is_noetherian R M :=
by rw [is_noetherian_iff_well_founded, well_founded.monotone_chain_condition]
/-- If `∀ I > J, P I` implies `P J`, then `P` holds for all submodules. -/
lemma is_noetherian.induction [is_noetherian R M] {P : submodule R M → Prop}
(hgt : ∀ I, (∀ J > I, P J) → P I) (I : submodule R M) : P I :=
well_founded.recursion (well_founded_submodule_gt R M) I hgt
end
section
universe w
variables {R M P : Type*} {N : Type w} [ring R] [add_comm_group M] [module R M]
[add_comm_group N] [module R N] [add_comm_group P] [module R P]
lemma finite_of_linear_independent [nontrivial R] [is_noetherian R M]
{s : set M} (hs : linear_independent R (coe : s → M)) : s.finite :=
begin
refine classical.by_contradiction (λ hf, (rel_embedding.well_founded_iff_no_descending_seq.1
(well_founded_submodule_gt R M)).elim' _),
have f : ℕ ↪ s, from set.infinite.nat_embedding s hf,
have : ∀ n, (coe ∘ f) '' {m | m ≤ n} ⊆ s,
{ rintros n x ⟨y, hy₁, rfl⟩, exact (f y).2 },
have : ∀ a b : ℕ, a ≤ b ↔
span R ((coe ∘ f) '' {m | m ≤ a}) ≤ span R ((coe ∘ f) '' {m | m ≤ b}),
{ assume a b,
rw [span_le_span_iff hs (this a) (this b),
set.image_subset_image_iff (subtype.coe_injective.comp f.injective),
set.subset_def],
exact ⟨λ hab x (hxa : x ≤ a), le_trans hxa hab, λ hx, hx a (le_refl a)⟩ },
exact ⟨⟨λ n, span R ((coe ∘ f) '' {m | m ≤ n}),
λ x y, by simp [le_antisymm_iff, (this _ _).symm] {contextual := tt}⟩,
by dsimp [gt]; simp only [lt_iff_le_not_le, (this _ _).symm]; tauto⟩
end
/-- If the first and final modules in a short exact sequence are noetherian,
then the middle module is also noetherian. -/
theorem is_noetherian_of_range_eq_ker
[is_noetherian R M] [is_noetherian R P]
(f : M →ₗ[R] N) (g : N →ₗ[R] P)
(hf : function.injective f)
(hg : function.surjective g)
(h : f.range = g.ker) :
is_noetherian R N :=
is_noetherian_iff_well_founded.2 $
well_founded_gt_exact_sequence
(well_founded_submodule_gt R M)
(well_founded_submodule_gt R P)
f.range
(submodule.map f)
(submodule.comap f)
(submodule.comap g)
(submodule.map g)
(submodule.gci_map_comap hf)
(submodule.gi_map_comap hg)
(by simp [submodule.map_comap_eq, inf_comm])
(by simp [submodule.comap_map_eq, h])
/--
For any endomorphism of a Noetherian module, there is some nontrivial iterate
with disjoint kernel and range.
-/
theorem is_noetherian.exists_endomorphism_iterate_ker_inf_range_eq_bot
[I : is_noetherian R M] (f : M →ₗ[R] M) : ∃ n : ℕ, n ≠ 0 ∧ (f ^ n).ker ⊓ (f ^ n).range = ⊥ :=
begin
obtain ⟨n, w⟩ := monotone_stabilizes_iff_noetherian.mpr I
(f.iterate_ker.comp ⟨λ n, n+1, λ n m w, by linarith⟩),
specialize w (2 * n + 1) (by linarith only),
dsimp at w,
refine ⟨n+1, nat.succ_ne_zero _, _⟩,
rw eq_bot_iff,
rintros - ⟨h, ⟨y, rfl⟩⟩,
rw [mem_bot, ←linear_map.mem_ker, w],
erw linear_map.mem_ker at h ⊢,
change ((f ^ (n + 1)) * (f ^ (n + 1))) y = 0 at h,
rw ←pow_add at h,
convert h using 3,
ring
end
/-- Any surjective endomorphism of a Noetherian module is injective. -/
theorem is_noetherian.injective_of_surjective_endomorphism [is_noetherian R M]
(f : M →ₗ[R] M) (s : surjective f) : injective f :=
begin
obtain ⟨n, ne, w⟩ := is_noetherian.exists_endomorphism_iterate_ker_inf_range_eq_bot f,
rw [linear_map.range_eq_top.mpr (linear_map.iterate_surjective s n), inf_top_eq,
linear_map.ker_eq_bot] at w,
exact linear_map.injective_of_iterate_injective ne w,
end
/-- Any surjective endomorphism of a Noetherian module is bijective. -/
theorem is_noetherian.bijective_of_surjective_endomorphism [is_noetherian R M]
(f : M →ₗ[R] M) (s : surjective f) : bijective f :=
⟨is_noetherian.injective_of_surjective_endomorphism f s, s⟩
/--
A sequence `f` of submodules of a noetherian module,
with `f (n+1)` disjoint from the supremum of `f 0`, ..., `f n`,
is eventually zero.
-/
lemma is_noetherian.disjoint_partial_sups_eventually_bot [I : is_noetherian R M]
(f : ℕ → submodule R M) (h : ∀ n, disjoint (partial_sups f n) (f (n+1))) :
∃ n : ℕ, ∀ m, n ≤ m → f m = ⊥ :=
begin
-- A little off-by-one cleanup first:
suffices t : ∃ n : ℕ, ∀ m, n ≤ m → f (m+1) = ⊥,
{ obtain ⟨n, w⟩ := t,
use n+1,
rintros (_|m) p,
{ cases p, },
{ apply w,
exact nat.succ_le_succ_iff.mp p }, },
obtain ⟨n, w⟩ := monotone_stabilizes_iff_noetherian.mpr I (partial_sups f),
exact ⟨n, λ m p, (h m).eq_bot_of_ge $ sup_eq_left.1 $ (w (m + 1) $ le_add_right p).symm.trans $
w m p⟩
end
/--
If `M ⊕ N` embeds into `M`, for `M` noetherian over `R`, then `N` is trivial.
-/
noncomputable def is_noetherian.equiv_punit_of_prod_injective [is_noetherian R M]
(f : M × N →ₗ[R] M) (i : injective f) : N ≃ₗ[R] punit.{w+1} :=
begin
apply nonempty.some,
obtain ⟨n, w⟩ := is_noetherian.disjoint_partial_sups_eventually_bot (f.tailing i)
(f.tailings_disjoint_tailing i),
specialize w n (le_refl n),
apply nonempty.intro,
refine (f.tailing_linear_equiv i n).symm ≪≫ₗ _,
rw w,
exact submodule.bot_equiv_punit,
end
end
/--
A (semi)ring is Noetherian if it is Noetherian as a module over itself,
i.e. all its ideals are finitely generated.
-/
@[reducible] def is_noetherian_ring (R) [semiring R] := is_noetherian R R
theorem is_noetherian_ring_iff {R} [semiring R] : is_noetherian_ring R ↔ is_noetherian R R :=
iff.rfl
/-- A ring is Noetherian if and only if all its ideals are finitely-generated. -/
lemma is_noetherian_ring_iff_ideal_fg (R : Type*) [semiring R] :
is_noetherian_ring R ↔ ∀ I : ideal R, I.fg :=
is_noetherian_ring_iff.trans is_noetherian_def
@[priority 80] -- see Note [lower instance priority]
instance is_noetherian_of_finite (R M) [finite M] [semiring R] [add_comm_monoid M] [module R M] :
is_noetherian R M :=
⟨λ s, ⟨(s : set M).to_finite.to_finset, by rw [set.finite.coe_to_finset, submodule.span_eq]⟩⟩
/-- Modules over the trivial ring are Noetherian. -/
@[priority 100] -- see Note [lower instance priority]
instance is_noetherian_of_subsingleton (R M) [subsingleton R] [semiring R] [add_comm_monoid M]
[module R M] : is_noetherian R M :=
by { haveI := module.subsingleton R M, exact is_noetherian_of_finite R M }
theorem is_noetherian_of_submodule_of_noetherian (R M) [semiring R] [add_comm_monoid M] [module R M]
(N : submodule R M) (h : is_noetherian R M) : is_noetherian R N :=
begin
rw is_noetherian_iff_well_founded at h ⊢,
exact order_embedding.well_founded (submodule.map_subtype.order_embedding N).dual h,
end
instance submodule.quotient.is_noetherian {R} [ring R] {M} [add_comm_group M] [module R M]
(N : submodule R M) [h : is_noetherian R M] : is_noetherian R (M ⧸ N) :=
begin
rw is_noetherian_iff_well_founded at h ⊢,
exact order_embedding.well_founded (submodule.comap_mkq.order_embedding N).dual h,
end
/-- If `M / S / R` is a scalar tower, and `M / R` is Noetherian, then `M / S` is
also noetherian. -/
theorem is_noetherian_of_tower (R) {S M} [semiring R] [semiring S]
[add_comm_monoid M] [has_smul R S] [module S M] [module R M] [is_scalar_tower R S M]
(h : is_noetherian R M) : is_noetherian S M :=
begin
rw is_noetherian_iff_well_founded at h ⊢,
refine (submodule.restrict_scalars_embedding R S M).dual.well_founded h
end
theorem is_noetherian_of_fg_of_noetherian {R M} [ring R] [add_comm_group M] [module R M]
(N : submodule R M) [is_noetherian_ring R] (hN : N.fg) : is_noetherian R N :=
let ⟨s, hs⟩ := hN in
begin
haveI := classical.dec_eq M,
haveI := classical.dec_eq R,
letI : is_noetherian R R := by apply_instance,
have : ∀ x ∈ s, x ∈ N, from λ x hx, hs ▸ submodule.subset_span hx,
refine @@is_noetherian_of_surjective ((↑s : set M) → R) _ _ _ (pi.module _ _ _)
_ _ _ is_noetherian_pi,
{ fapply linear_map.mk,
{ exact λ f, ⟨∑ i in s.attach, f i • i.1, N.sum_mem (λ c _, N.smul_mem _ $ this _ c.2)⟩ },
{ intros f g, apply subtype.eq,
change ∑ i in s.attach, (f i + g i) • _ = _,
simp only [add_smul, finset.sum_add_distrib], refl },
{ intros c f, apply subtype.eq,
change ∑ i in s.attach, (c • f i) • _ = _,
simp only [smul_eq_mul, mul_smul],
exact finset.smul_sum.symm } },
rw linear_map.range_eq_top,
rintro ⟨n, hn⟩, change n ∈ N at hn,
rw [← hs, ← set.image_id ↑s, finsupp.mem_span_image_iff_total] at hn,
rcases hn with ⟨l, hl1, hl2⟩,
refine ⟨λ x, l x, subtype.ext _⟩,
change ∑ i in s.attach, l i • (i : M) = n,
rw [@finset.sum_attach M M s _ (λ i, l i • i), ← hl2,
finsupp.total_apply, finsupp.sum, eq_comm],
refine finset.sum_subset hl1 (λ x _ hx, _),
rw [finsupp.not_mem_support_iff.1 hx, zero_smul]
end
lemma is_noetherian_of_fg_of_noetherian' {R M} [ring R] [add_comm_group M] [module R M]
[is_noetherian_ring R] (h : (⊤ : submodule R M).fg) : is_noetherian R M :=
have is_noetherian R (⊤ : submodule R M), from is_noetherian_of_fg_of_noetherian _ h,
by exactI is_noetherian_of_linear_equiv (linear_equiv.of_top (⊤ : submodule R M) rfl)
/-- In a module over a noetherian ring, the submodule generated by finitely many vectors is
noetherian. -/
theorem is_noetherian_span_of_finite (R) {M} [ring R] [add_comm_group M] [module R M]
[is_noetherian_ring R] {A : set M} (hA : A.finite) : is_noetherian R (submodule.span R A) :=
is_noetherian_of_fg_of_noetherian _ (submodule.fg_def.mpr ⟨A, hA, rfl⟩)
theorem is_noetherian_ring_of_surjective (R) [ring R] (S) [ring S]
(f : R →+* S) (hf : function.surjective f)
[H : is_noetherian_ring R] : is_noetherian_ring S :=
begin
rw [is_noetherian_ring_iff, is_noetherian_iff_well_founded] at H ⊢,
exact order_embedding.well_founded (ideal.order_embedding_of_surjective f hf).dual H,
end
instance is_noetherian_ring_range {R} [ring R] {S} [ring S] (f : R →+* S)
[is_noetherian_ring R] : is_noetherian_ring f.range :=
is_noetherian_ring_of_surjective R f.range f.range_restrict
f.range_restrict_surjective
theorem is_noetherian_ring_of_ring_equiv (R) [ring R] {S} [ring S]
(f : R ≃+* S) [is_noetherian_ring R] : is_noetherian_ring S :=
is_noetherian_ring_of_surjective R S f.to_ring_hom f.to_equiv.surjective
lemma is_noetherian_ring.is_nilpotent_nilradical (R : Type*) [comm_ring R] [is_noetherian_ring R] :
is_nilpotent (nilradical R) :=
begin
obtain ⟨n, hn⟩ := ideal.exists_radical_pow_le_of_fg (⊥ : ideal R) (is_noetherian.noetherian _),
exact ⟨n, eq_bot_iff.mpr hn⟩
end
|
0f4a5416b04f2681f2ab01cf4c8ebb0e3ab5baeb | d1a52c3f208fa42c41df8278c3d280f075eb020c | /tests/lean/substBadMotive.lean | 30ccdfae5b00596b0fe0d34fac9fdf45be3f07cb | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | cipher1024/lean4 | 6e1f98bb58e7a92b28f5364eb38a14c8d0aae393 | 69114d3b50806264ef35b57394391c3e738a9822 | refs/heads/master | 1,642,227,983,603 | 1,642,011,696,000 | 1,642,011,696,000 | 228,607,691 | 0 | 0 | Apache-2.0 | 1,576,584,269,000 | 1,576,584,268,000 | null | UTF-8 | Lean | false | false | 1,606 | lean | namespace Ex1
variable (a : Nat) (i : Fin a) (h : 1 = a)
example : i < a := h ▸ i.2 -- `▸` uses `subst` here
end Ex1
namespace Ex2
def heapifyDown' (a : Array α) (i : Fin a.size) : Array α := sorry
def heapifyDown (a : Array α) (i : Fin a.size) : Array α :=
heapifyDown' a ⟨i.1, a.size_swap i i ▸ i.2⟩ -- Error, failed to compute motive, `subst` is not applicable here
end Ex2
namespace Ex3
def heapifyDown (a : Array α) (i : Fin a.size) : Array α :=
have : i < i := sorry
heapifyDown a ⟨i.1, a.size_swap i i ▸ i.2⟩ -- Error, failed to compute motive, `subst` is not applicable here
termination_by measure fun ⟨_, a, i⟩ => i.1
decreasing_by assumption
end Ex3
namespace Ex4
def heapifyDown (lt : α → α → Bool) (a : Array α) (i : Fin a.size) : Array α :=
let left := 2 * i.1 + 1
let right := left + 1
have left_le : i ≤ left := sorry
have right_le : i ≤ right := sorry
have i_le : i ≤ i := Nat.le_refl _
have j : {j : Fin a.size // i ≤ j} := if h : left < a.size then
if lt (a.get i) (a.get ⟨left, h⟩) then ⟨⟨left, h⟩, left_le⟩ else ⟨i, i_le⟩ else ⟨i, i_le⟩
have j := if h : right < a.size then
if lt (a.get j) (a.get ⟨right, h⟩) then ⟨⟨right, h⟩, right_le⟩ else j else j
if h : i ≠ j then
let a' := a.swap i j
have : a'.size - j < a.size - i := sorry
heapifyDown lt a' ⟨j.1.1, a.size_swap i j ▸ j.1.2⟩ -- Error, failed to compute motive, `subst` is not applicable here
else
a
termination_by measure fun ⟨_, _, a, i⟩ => a.size - i.1
decreasing_by assumption
end Ex4
|
92529c1b2d6fbcdf22b68d3141213915f272bce2 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/algebra/big_operators/finprod.lean | 4e2771dd7af7e89879242d272e8de45b7685fec9 | [
"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 | 48,485 | 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
/-!
# 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.
We did not add `is_finite (X : Type) : Prop`, because it is simply `nonempty (fintype X)`.
## 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 the factors. -/
@[to_additive "To prove a property of a finite sum, it suffices to prove that the property is
additive and holds on the summands."]
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
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
lemma finprod_inv_distrib₀ {G : Type*} [comm_group_with_zero 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_eq_finset_prod_of_mul_support_subset
(f : α → M) {s : finset α} (h : mul_support f ⊆ (s : set α)) :
∏ᶠ i, f i = ∏ i in s, f i :=
begin
have h' : (s.finite_to_set.subset h).to_finset ⊆ s,
{ simpa [← finset.coe_subset, set.coe_to_finset], },
exact finprod_eq_prod_of_mul_support_to_finset_subset _ _ h',
end
@[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_cond_ne (f : α → M) (a : α) [decidable_eq α]
(hf : finite (mul_support f)) : (∏ᶠ i ≠ a, f i) = ∏ i in hf.to_finset.erase a, f i :=
begin
apply finprod_cond_eq_prod_of_cond_iff,
intros x hx,
rw [finset.mem_erase, finite.mem_to_finset, mem_mul_support],
exact ⟨λ h, and.intro h hx, λ h, h.1⟩
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_eq_one_of_forall_eq_one {f : α → M} {s : set α} (h : ∀ x ∈ s, f x = 1) :
∏ᶠ i ∈ s, f i = 1 :=
by simp [h] {contextual := tt}
@[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))
@[to_additive]
lemma finprod_eq_one_of_forall_eq_one {f : α → M} (h : ∀ x, f x = 1) :
∏ᶠ i, f i = 1 :=
by simp [h] {contextual := tt}
/-!
### 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 of `g i`. -/
@[to_additive "If the additive supports of `f` and `g` are finite, then the sum of `f i + g i`
equals the sum of `f i` plus the sum of `g i`."]
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
/-- If the multiplicative supports of `f` and `g` are finite, then the product of `f i / g i`
equals the product of `f i` divided by the product of `g i`. -/
@[to_additive "If the additive supports of `f` and `g` are finite, then the sum of `f i - g i`
equals the sum of `f i` minus the sum of `g i`."]
lemma finprod_div_distrib {G : Type*} [comm_group G] {f g : α → G} (hf : (mul_support f).finite)
(hg : (mul_support g).finite) :
∏ᶠ i, f i / g i = (∏ᶠ i, f i) / ∏ᶠ i, g i :=
by simp only [div_eq_mul_inv, finprod_mul_distrib hf ((mul_support_inv g).symm.rec hg),
finprod_inv_distrib]
lemma finprod_div_distrib₀ {G : Type*} [comm_group_with_zero G] {f g : α → G}
(hf : (mul_support f).finite) (hg : (mul_support g).finite) :
∏ᶠ i, f i / g i = (∏ᶠ i, f i) / ∏ᶠ i, g i :=
by simp only [div_eq_mul_inv, finprod_mul_distrib hf ((mul_support_inv₀ g).symm.rec hg),
finprod_inv_distrib₀]
/-- A more general version of `finprod_mem_mul_distrib` that only requires `s ∩ mul_support f` and
`s ∩ mul_support g` rather than `s` to be finite. -/
@[to_additive "A more general version of `finsum_mem_add_distrib` that only requires `s ∩ support f`
and `s ∩ support g` rather than `s` to be finite."]
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 the constant function `1` over any set equals `1`. -/
@[to_additive "The product of the constant function `0` over any set equals `0`."]
lemma finprod_mem_one (s : set α) : ∏ᶠ i ∈ s, (1 : M) = 1 := by simp
/-- If a function `f` equals `1` on a set `s`, then the product of `f i` over `i ∈ s` equals `1`. -/
@[to_additive "If a function `f` equals `0` on a set `s`, then the product of `f i` over `i ∈ s`
equals `0`."]
lemma finprod_mem_of_eq_on_one (hf : s.eq_on f 1) : ∏ᶠ 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 `1`, then there is some `x ∈ s` such that
`f x ≠ 1`. -/
@[to_additive "If the product of `f i` over `i ∈ s` is not equal to `0`, then there is some `x ∈ s`
such that `f x ≠ 0`."]
lemma exists_ne_one_of_finprod_mem_ne_one (h : ∏ᶠ i ∈ s, f i ≠ 1) : ∃ x ∈ s, f x ≠ 1 :=
begin
by_contra' 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 "Given a finite set `s`, the sum of `f i + g i` over `i ∈ s` equals the sum of `f i`
over `i ∈ s` plus the sum of `g i` over `i ∈ s`."]
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 _
@[to_additive] lemma finprod_pow (hf : (mul_support f).finite) (n : ℕ) :
(∏ᶠ i, f i) ^ n = ∏ᶠ i, f i ^ n :=
(pow_monoid_hom n).map_finprod hf
/-- A more general version of `monoid_hom.map_finprod_mem` that requires `s ∩ mul_support f` rather
than `s` to be finite. -/
@[to_additive "A more general version of `add_monoid_hom.map_finsum_mem` that requires
`s ∩ support f` rather than `s` to be finite."]
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 "Given an additive monoid homomorphism `g : M →* N` and a function `f : α → M`, the
value of `g` at the sum of `f i` over `i ∈ s` equals the sum of `g (f i)` over `s`."]
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 _)
@[to_additive] lemma mul_equiv.map_finprod_mem (g : M ≃* N) (f : α → M) {s : set α}
(hs : s.finite) : g (∏ᶠ i ∈ s, f i) = ∏ᶠ i ∈ s, g (f i) :=
g.to_monoid_hom.map_finprod_mem f hs
@[to_additive] lemma finprod_mem_inv_distrib {G : Type*} [comm_group G] (f : α → G)
(hs : s.finite) : ∏ᶠ x ∈ s, (f x)⁻¹ = (∏ᶠ x ∈ s, f x)⁻¹ :=
((mul_equiv.inv G).map_finprod_mem f hs).symm
lemma finprod_mem_inv_distrib₀ {G : Type*} [comm_group_with_zero G] (f : α → G)
(hs : s.finite) : ∏ᶠ x ∈ s, (f x)⁻¹ = (∏ᶠ x ∈ s, f x)⁻¹ :=
((mul_equiv.inv₀ G).map_finprod_mem f hs).symm
/-- Given a finite set `s`, the product of `f i / g i` over `i ∈ s` equals the product of `f i`
over `i ∈ s` divided by the product of `g i` over `i ∈ s`. -/
@[to_additive "Given a finite set `s`, the sum of `f i / g i` over `i ∈ s` equals the sum of `f i`
over `i ∈ s` minus the sum of `g i` over `i ∈ s`."]
lemma finprod_mem_div_distrib {G : Type*} [comm_group G] (f g : α → G) (hs : s.finite) :
∏ᶠ i ∈ s, f i / g i = (∏ᶠ i ∈ s, f i) / ∏ᶠ i ∈ s, g i :=
by simp only [div_eq_mul_inv, finprod_mem_mul_distrib hs, finprod_mem_inv_distrib g hs]
lemma finprod_mem_div_distrib₀ {G : Type*} [comm_group_with_zero G] (f g : α → G)
(hs : s.finite) : ∏ᶠ i ∈ s, f i / g i = (∏ᶠ i ∈ s, f i) / ∏ᶠ i ∈ s, g i :=
by simp only [div_eq_mul_inv, finprod_mem_mul_distrib hs, finprod_mem_inv_distrib₀ g hs]
/-!
### `∏ᶠ x ∈ s, f x` and set operations
-/
/-- The product of any function over an empty set is `1`. -/
@[to_additive "The sum of any function over an empty set is `0`."]
lemma finprod_mem_empty : ∏ᶠ i ∈ (∅ : set α), f i = 1 := by simp
/-- A set `s` is nonempty if the product of some function over `s` is not equal to `1`. -/
@[to_additive "A set `s` is nonempty if the sum of some function over `s` is not equal to `0`."]
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 "Given finite sets `s` and `t`, the sum of `f i` over `i ∈ s ∪ t` plus the sum of
`f i` over `i ∈ s ∩ t` equals the sum of `f i` over `i ∈ s` plus the sum of `f i` over `i ∈ t`."]
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` rather than `s` and `t` to be finite. -/
@[to_additive "A more general version of `finsum_mem_union_inter` that requires `s ∩ support f` and
`t ∩ support f` rather than `s` and `t` to be finite."] 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` rather than `s` and `t` to be finite. -/
@[to_additive "A more general version of `finsum_mem_union` that requires `s ∩ support f` and
`t ∩ support f` rather than `s` and `t` to be finite."]
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 "Given two finite disjoint sets `s` and `t`, the sum of `f i` over `i ∈ s ∪ t` equals
the sum of `f i` over `i ∈ s` plus the sum of `f i` over `i ∈ t`."]
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` rather than `s` and `t` to be disjoint -/
@[to_additive "A more general version of `finsum_mem_union'` that requires `s ∩ support f` and
`t ∩ support f` rather than `s` and `t` to be disjoint"]
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 "The sum of `f i` over `i ∈ {a}` equals `f a`."]
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` rather than `s`
to be finite. -/
@[to_additive "A more general version of `finsum_mem_insert` that requires `s ∩ support f` rather
than `s` to be finite."]
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 "Given a finite set `s` and an element `a ∉ s`, the sum of `f i` over `i ∈ insert a s`
equals `f a` plus the sum of `f i` over `i ∈ s`."]
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` when `a ∉ s`, then the product of `f i` over `i ∈ insert a s` equals the product of
`f i` over `i ∈ s`. -/
@[to_additive "If `f a = 0` when `a ∉ s`, then the sum of `f i` over `i ∈ insert a s` equals the sum
of `f i` over `i ∈ s`."]
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 "If `f a = 0`, then the sum of `f i` over `i ∈ insert a s` equals the sum of `f i`
over `i ∈ s`."]
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 : (mul_support f).finite) : 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 "The sum of `f i` over `i ∈ {a, b}`, `a ≠ b`, is equal to `f a + f b`."]
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 "The sum of `f y` over `y ∈ g '' s` equals the sum of `f (g i)` over `s` provided that
`g` is injective on `s ∩ support (f ∘ g)`."]
lemma finprod_mem_image' {s : set β} {g : β → α} (hg : (s ∩ mul_support (f ∘ g)).inj_on 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 "The sum of `f y` over `y ∈ g '' s` equals the sum of `f (g i)` over `s` provided that
`g` is injective on `s`."]
lemma finprod_mem_image {s : set β} {g : β → α} (hg : s.inj_on g) :
∏ᶠ 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 "The sum of `f y` over `y ∈ set.range g` equals the sum of `f (g i)` over all `i`
provided that `g` is injective on `support (f ∘ g)`."]
lemma finprod_mem_range' {g : β → α} (hg : (mul_support (f ∘ g)).inj_on 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 "The sum of `f y` over `y ∈ set.range g` equals the sum of `f (g i)` over all `i`
provided that `g` is injective."]
lemma finprod_mem_range {g : β → α} (hg : injective g) : ∏ᶠ i ∈ range g, f i = ∏ᶠ j, f (g j) :=
finprod_mem_range' (hg.inj_on _)
/-- See also `finset.prod_bij`. -/
@[to_additive "See also `finset.sum_bij`."]
lemma finprod_mem_eq_of_bij_on {s : set α} {t : set β} {f : α → M} {g : β → M} (e : α → β)
(he₀ : s.bij_on e 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
/-- See `finprod_comp`, `fintype.prod_bijective` and `finset.prod_bij`. -/
@[to_additive "See `finsum_comp`, `fintype.sum_bijective` and `finset.sum_bij`."]
lemma finprod_eq_of_bijective {f : α → M} {g : β → M} (e : α → β) (he₀ : bijective e)
(he₁ : ∀ x, f x = g (e x)) :
∏ᶠ i, f i = ∏ᶠ j, g j :=
begin
rw [← finprod_mem_univ f, ← finprod_mem_univ g],
exact finprod_mem_eq_of_bij_on _ (bijective_iff_bij_on_univ.mp he₀) (λ x _, he₁ x),
end
/-- See also `finprod_eq_of_bijective`, `fintype.prod_bijective` and `finset.prod_bij`. -/
@[to_additive "See also `finsum_eq_of_bijective`, `fintype.sum_bijective` and `finset.sum_bij`."]
lemma finprod_comp {g : β → M} (e : α → β) (he₀ : function.bijective e) :
∏ᶠ i, g (e i) = ∏ᶠ j, g j := finprod_eq_of_bijective e he₀ (λ x, rfl)
@[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` rather than
`t` to be finite. -/
@[to_additive "A more general version of `finsum_mem_add_diff` that requires `t ∩ support f` rather
than `t` to be finite."]
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 "Given a finite set `t` and a subset `s` of `t`, the sum of `f i` over `i ∈ s` plus
the sum of `f i` over `t \\ s` equals the sum of `f i` over `i ∈ t`."]
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 "Given a family of pairwise disjoint finite sets `t i` indexed by a finite type, the
sum of `f a` over the union `⋃ i, t i` is equal to the sum over all indexes `i` of the sums of `f a`
over `a ∈ t i`."]
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 "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 sum of
`f a` over `a ∈ ⋃ i ∈ I, t i` is equal to the sum over `i ∈ I` of the sums of `f a` over
`a ∈ t i`."]
lemma finprod_mem_bUnion {I : set ι} {t : ι → set α} (h : I.pairwise_disjoint 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 [bUnion_eq_Union, finprod_mem_Union, ← finprod_set_coe_eq_finprod_mem],
exacts [λ x y hxy, h x.2 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 "If `t` is a finite set of pairwise disjoint finite sets, then the sum of `f a` over
`a ∈ ⋃₀ t` is the sum over `s ∈ t` of the sums of `f a` over `a ∈ s`."]
lemma finprod_mem_sUnion {t : set (set α)} (h : t.pairwise_disjoint id) (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, exact finprod_mem_bUnion h ht₀ ht₁ }
@[to_additive] lemma mul_finprod_cond_ne (a : α) (hf : finite (mul_support f)) :
f a * (∏ᶠ i ≠ a, f i) = ∏ᶠ i, f i :=
begin
classical,
rw [finprod_eq_prod _ hf],
have h : ∀ x : α, f x ≠ 1 → (x ≠ a ↔ x ∈ hf.to_finset \ {a}),
{ intros x hx,
rw [finset.mem_sdiff, finset.mem_singleton, finite.mem_to_finset, mem_mul_support],
exact ⟨λ h, and.intro hx h, λ h, h.2⟩,},
rw [finprod_cond_eq_prod_of_cond_iff f h, finset.sdiff_singleton_eq_erase],
by_cases ha : a ∈ mul_support f,
{ apply finset.mul_prod_erase _ _ ((finite.mem_to_finset _ ).mpr ha), },
{ rw [mem_mul_support, not_not] at ha,
rw [ha, one_mul],
apply finset.prod_erase _ ha, }
end
/-- If `s : set α` and `t : set β` are finite sets, then taking the product over `s` commutes with
taking the product over `t`. -/
@[to_additive "If `s : set α` and `t : set β` are finite sets, then summing over `s` commutes with
summing over `t`."]
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 factors. -/
@[to_additive "To prove a property of a finite sum, it suffices to prove that the property is
additive and holds on summands."] 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 : (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 : (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 "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`."]
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,
{ refine (λ a, finset.prod_bij (λ b _, (a, b)) _ _ _ _); -- `finish` closes these goals
try { simp, done },
suffices : ∀ a' b, (a', b) ∈ s → a' = a → (a, b) ∈ s ∧ a' = a, by simpa,
rintros a' b hp rfl,
exact ⟨hp, rfl⟩ },
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` could close the goal here
simp only [finset.mem_image, prod.mk.eta],
exact λ x hx, ⟨x, hx, rfl⟩,
end
/-- See also `finprod_mem_finset_product'`. -/
@[to_additive "See also `finsum_mem_finset_product'`."]
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 : 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
|
1c32be2d7c9c5dd90590ad1253ab456f2d18622e | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/algebra/star/module.lean | ca4b31001dbc4d61194dab2ba1e376aa47a23bfb | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,389 | lean | /-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Frédéric Dupuis
-/
import algebra.star.basic
import data.equiv.module
/-!
# The star operation, bundled as a star-linear equiv
We define `star_linear_equiv`, which is the star operation bundled as a star-linear map.
It is defined on a star algebra `A` over the base ring `R`.
## TODO
- Define `star_linear_equiv` for noncommutative `R`. We only the commutative case for now since,
in the noncommutative case, the ring hom needs to reverse the order of multiplication. This
requires a ring hom of type `R →+* Rᵒᵖ`, which is very undesirable in the commutative case.
One way out would be to define a new typeclass `is_op R S` and have an instance `is_op R R`
for commutative `R`.
- Also note that such a definition involving `Rᵒᵖ` or `is_op R S` would require adding
the appropriate `ring_hom_inv_pair` instances to be able to define the semilinear
equivalence.
-/
/-- If `A` is a module over a commutative `R` with compatible actions,
then `star` is a semilinear equivalence. -/
@[simps]
def star_linear_equiv (R : Type*) {A : Type*}
[comm_ring R] [star_ring R] [semiring A] [star_ring A] [module R A] [star_module R A] :
A ≃ₗ⋆[R] A :=
{ to_fun := star,
map_smul' := star_smul,
.. star_add_equiv }
|
930abfe06f19a7e6fb1bd174de9ace0227da5f1d | 874a8d2247ab9a4516052498f80da2e32d0e3a48 | /IVT_attempt.lean | 3cb0caffa73bbddd981626d5fb20fe9f47e54457 | [] | no_license | AlexKontorovich/Spring2020Math492 | 378b36c643ee029f5ab91c1677889baa591f5e85 | 659108c5d864ff5c75b9b3b13b847aa5cff4348a | refs/heads/master | 1,610,780,595,457 | 1,588,174,859,000 | 1,588,174,859,000 | 243,017,788 | 0 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 1,698 | lean | import
data.real.basic
data.set.basic
order.basic
topology.algebra.continuous_functions
analysis.normed_space.basic
topology.metric_space.lipschitz
tactic.tfae
order.liminf_limsup
order.complete_lattice
data.set.intervals
topology.algebra.group
order.conditionally_complete_lattice
order.complete_lattice
order.lattice
order.bounds
tactic.finish
data.nat.enat
topology.algebra.ordered
namespace lattice
lemma cSup_is_bigger {f : ℝ → ℝ} (Hf : continuous f)
{a b : ℝ} (Hab : a < b) (K := {x : ℝ | x>=a ∧ x<b ∧ f x < 0})
(c:= Sup K) (Hbdd: bdd_above K) (Hne: a ∈ K) :
a <= Sup K := conditionally_complete_lattice.le_cSup K a Hbdd Hne
lemma cSup_is_smaller {f : ℝ → ℝ} (Hf : continuous f)
{a b : ℝ} (Hab : a < b) (K := {x : ℝ | x>=a ∧ x<b ∧ f x < 0})
(c:= Sup K) (Hbdd: b ∈ upper_bounds K) (Hne: K.nonempty) :
Sup K <= b := conditionally_complete_lattice.cSup_le K b Hne Hbdd
lemma continuous_implies {f : ℝ → ℝ} (Hf : continuous f)
{a b : ℝ} (Hab : a < b) (K := {x : ℝ | x>a ∧ x<b ∧ f x < 0})
(c:= Sup K):
f c = 0
:=
--having trouble proving this
sorry
theorem intermediate_value {f : ℝ → ℝ} (Hf : continuous f)
{a b : ℝ} (Hab : a < b)
(Hav : f a < 0) (Hbv : f b > 0) :
∃ c, a < c ∧ c < b ∧ f c = 0 :=
begin
let K := {x : ℝ | x>=a ∧ x<b ∧ f x < 0},
have Hbdd: bdd_above K, use b,
have Hne: K.nonempty, use a,
let c := Sup K,
have Hac: a < c, apply cSup_is_bigger,
--not sure how to use apply syntax, keep getting errors
have Hbc: c < b, apply cSup_is_smaller,
--same here
have c:ℝ, exact c,
have Hc: f c = 0, from continuous_implies,
end |
c8f1aaf79730f6c55937d0e9b1f539ea56935514 | ed27983dd289b3bcad416f0b1927105d6ef19db8 | /src/inClassNotes/dihedral_group.lean | 3f9895c6b1b3e5ad3426d6da6a5648903920ae58 | [] | no_license | liuxin-James/complogic-s21 | 0d55b76dbe25024473d31d98b5b83655c365f811 | 13e03e0114626643b44015c654151fb651603486 | refs/heads/master | 1,681,109,264,463 | 1,618,848,261,000 | 1,618,848,261,000 | 337,599,491 | 0 | 0 | null | 1,613,141,619,000 | 1,612,925,555,000 | null | UTF-8 | Lean | false | false | 1,329 | lean | import algebra
#check monoid
namespace hidden
inductive Action_D4 : Type
| R0
| R90
| R180
| R270
| H
| V
| D
| D'
open Action_D4
#check Action_D4
def comp: Action_D4 → Action_D4 → Action_D4
| R0 b := b
| b R0 := b
| R90 R90 := R180
| R90 R180 := R270
| R90 R270 := R0
| R90 H:= D'
| R90 V:= D
| R90 D:= H
| R90 D':= V
| R180 R90:= R270
| R180 R180:= R0
| R180 R270:= R90
| R180 H:= V
| R180 V:= H
| R180 D:= D'
| R180 D':= D
| R270 R90:= R0
| R270 R180:= R90
| R270 R270:= R180
| R270 H:= D
| R270 V:= D'
| R270 D:= V
| R270 D':= H
| H R90:= D
| H R180:= V
| H R270:= D'
| H H:= R0
| H V:= R180
| H D:= R90
| H D':= R270
| V R90:= D'
| V R180:= H
| V R270:= D
| V H:= R180
| V V:= R0
| V D:= R270
| V D':= R90
| D R90:= V
| D R180:= D'
| D R270:= H
| D H:= R270
| D V:= R90
| D D:= R0
| D D':= R180
| D' R90:= H
| D' R180:= D
| D' R270:= V
| D' H:= R90
| D' V:= R270
| D' D:= R180
| D' D':= R0
#reduce comp R0 D
universe u
def fold {α: Type u}: α → (α → α → α) → list α → α
| a f [] := a
| a f (h::t) := f h (fold a f t)
def comp_list (a: list Action_D4): Action_D4:= fold R0 comp a
#reduce comp_list [R0,R180,R180,R90]
#reduce comp_list [R90,H]
end hidden
def band_tactic: bool → bool → bool :=
begin
assume x y,
cases x,
cases y,
exact ff,
exact ff,
exact tt,
end
#eval band_tactic tt ff
|
a3b9b3abca2dae518eb743e8b79c9de796e3889d | 4727251e0cd73359b15b664c3170e5d754078599 | /src/measure_theory/decomposition/lebesgue.lean | c474ed9d9fde2040852fca017c72b0a8427f3533 | [
"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 | 65,112 | lean | /-
Copyright (c) 2021 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import measure_theory.measure.complex
import measure_theory.measure.sub
import measure_theory.decomposition.jordan
import measure_theory.measure.with_density_vector_measure
import measure_theory.function.ae_eq_of_integral
/-!
# Lebesgue decomposition
This file proves the Lebesgue decomposition theorem. The Lebesgue decomposition theorem states that,
given two σ-finite measures `μ` and `ν`, there exists a σ-finite measure `ξ` and a measurable
function `f` such that `μ = ξ + fν` and `ξ` is mutually singular with respect to `ν`.
The Lebesgue decomposition provides the Radon-Nikodym theorem readily.
## Main definitions
* `measure_theory.measure.have_lebesgue_decomposition` : A pair of measures `μ` and `ν` is said
to `have_lebesgue_decomposition` if there exist a measure `ξ` and a measurable function `f`,
such that `ξ` is mutually singular with respect to `ν` and `μ = ξ + ν.with_density f`
* `measure_theory.measure.singular_part` : If a pair of measures `have_lebesgue_decomposition`,
then `singular_part` chooses the measure from `have_lebesgue_decomposition`, otherwise it
returns the zero measure.
* `measure_theory.measure.rn_deriv`: If a pair of measures
`have_lebesgue_decomposition`, then `rn_deriv` chooses the measurable function from
`have_lebesgue_decomposition`, otherwise it returns the zero function.
* `measure_theory.signed_measure.have_lebesgue_decomposition` : A signed measure `s` and a
measure `μ` is said to `have_lebesgue_decomposition` if both the positive part and negative
part of `s` `have_lebesgue_decomposition` with respect to `μ`.
* `measure_theory.signed_measure.singular_part` : The singular part between a signed measure `s`
and a measure `μ` is simply the singular part of the positive part of `s` with respect to `μ`
minus the singular part of the negative part of `s` with respect to `μ`.
* `measure_theory.signed_measure.rn_deriv` : The Radon-Nikodym derivative of a signed
measure `s` with respect to a measure `μ` is the Radon-Nikodym derivative of the positive part of
`s` with respect to `μ` minus the Radon-Nikodym derivative of the negative part of `s` with
respect to `μ`.
## Main results
* `measure_theory.measure.have_lebesgue_decomposition_of_sigma_finite` :
the Lebesgue decomposition theorem.
* `measure_theory.measure.eq_singular_part` : Given measures `μ` and `ν`, if `s` is a measure
mutually singular to `ν` and `f` is a measurable function such that `μ = s + fν`, then
`s = μ.singular_part ν`.
* `measure_theory.measure.eq_rn_deriv` : Given measures `μ` and `ν`, if `s` is a
measure mutually singular to `ν` and `f` is a measurable function such that `μ = s + fν`,
then `f = μ.rn_deriv ν`.
* `measure_theory.signed_measure.singular_part_add_with_density_rn_deriv_eq` :
the Lebesgue decomposition theorem between a signed measure and a σ-finite positive measure.
# Tags
Lebesgue decomposition theorem
-/
noncomputable theory
open_locale classical measure_theory nnreal ennreal
open set
variables {α β : Type*} {m : measurable_space α} {μ ν : measure_theory.measure α}
include m
namespace measure_theory
namespace measure
/-- A pair of measures `μ` and `ν` is said to `have_lebesgue_decomposition` if there exists a
measure `ξ` and a measurable function `f`, such that `ξ` is mutually singular with respect to
`ν` and `μ = ξ + ν.with_density f`. -/
class have_lebesgue_decomposition (μ ν : measure α) : Prop :=
(lebesgue_decomposition :
∃ (p : measure α × (α → ℝ≥0∞)), measurable p.2 ∧ p.1 ⊥ₘ ν ∧ μ = p.1 + ν.with_density p.2)
/-- If a pair of measures `have_lebesgue_decomposition`, then `singular_part` chooses the
measure from `have_lebesgue_decomposition`, otherwise it returns the zero measure. For sigma-finite
measures, `μ = μ.singular_part ν + ν.with_density (μ.rn_deriv ν)`. -/
@[irreducible]
def singular_part (μ ν : measure α) : measure α :=
if h : have_lebesgue_decomposition μ ν then (classical.some h.lebesgue_decomposition).1 else 0
/-- If a pair of measures `have_lebesgue_decomposition`, then `rn_deriv` chooses the
measurable function from `have_lebesgue_decomposition`, otherwise it returns the zero function.
For sigma-finite measures, `μ = μ.singular_part ν + ν.with_density (μ.rn_deriv ν)`.-/
@[irreducible]
def rn_deriv (μ ν : measure α) : α → ℝ≥0∞ :=
if h : have_lebesgue_decomposition μ ν then (classical.some h.lebesgue_decomposition).2 else 0
lemma have_lebesgue_decomposition_spec (μ ν : measure α)
[h : have_lebesgue_decomposition μ ν] :
measurable (μ.rn_deriv ν) ∧ (μ.singular_part ν) ⊥ₘ ν ∧
μ = (μ.singular_part ν) + ν.with_density (μ.rn_deriv ν) :=
begin
rw [singular_part, rn_deriv, dif_pos h, dif_pos h],
exact classical.some_spec h.lebesgue_decomposition,
end
lemma have_lebesgue_decomposition_add (μ ν : measure α)
[have_lebesgue_decomposition μ ν] :
μ = (μ.singular_part ν) + ν.with_density (μ.rn_deriv ν) :=
(have_lebesgue_decomposition_spec μ ν).2.2
instance have_lebesgue_decomposition_smul
(μ ν : measure α) [have_lebesgue_decomposition μ ν] (r : ℝ≥0) :
(r • μ).have_lebesgue_decomposition ν :=
{ lebesgue_decomposition :=
begin
obtain ⟨hmeas, hsing, hadd⟩ := have_lebesgue_decomposition_spec μ ν,
refine ⟨⟨r • μ.singular_part ν, r • μ.rn_deriv ν⟩, _, hsing.smul _, _⟩,
{ change measurable ((r : ℝ≥0∞) • _), -- cannot remove this line
exact hmeas.const_smul _ },
{ change _ = (r : ℝ≥0∞) • _ + ν.with_density ((r : ℝ≥0∞) • _),
rw [with_density_smul _ hmeas, ← smul_add, ← hadd],
refl }
end }
@[measurability]
lemma measurable_rn_deriv (μ ν : measure α) :
measurable $ μ.rn_deriv ν :=
begin
by_cases h : have_lebesgue_decomposition μ ν,
{ exactI (have_lebesgue_decomposition_spec μ ν).1 },
{ rw [rn_deriv, dif_neg h],
exact measurable_zero }
end
lemma mutually_singular_singular_part (μ ν : measure α) :
μ.singular_part ν ⊥ₘ ν :=
begin
by_cases h : have_lebesgue_decomposition μ ν,
{ exactI (have_lebesgue_decomposition_spec μ ν).2.1 },
{ rw [singular_part, dif_neg h],
exact mutually_singular.zero_left }
end
lemma singular_part_le (μ ν : measure α) : μ.singular_part ν ≤ μ :=
begin
by_cases hl : have_lebesgue_decomposition μ ν,
{ casesI (have_lebesgue_decomposition_spec μ ν).2 with _ h,
conv_rhs { rw h },
exact measure.le_add_right le_rfl },
{ rw [singular_part, dif_neg hl],
exact measure.zero_le μ }
end
lemma with_density_rn_deriv_le (μ ν : measure α) :
ν.with_density (μ.rn_deriv ν) ≤ μ :=
begin
by_cases hl : have_lebesgue_decomposition μ ν,
{ casesI (have_lebesgue_decomposition_spec μ ν).2 with _ h,
conv_rhs { rw h },
exact measure.le_add_left le_rfl },
{ rw [rn_deriv, dif_neg hl, with_density_zero],
exact measure.zero_le μ }
end
instance [is_finite_measure μ] : is_finite_measure (μ.singular_part ν) :=
is_finite_measure_of_le μ $ singular_part_le μ ν
instance [sigma_finite μ] : sigma_finite (μ.singular_part ν) :=
sigma_finite_of_le μ $ singular_part_le μ ν
instance [topological_space α] [is_locally_finite_measure μ] :
is_locally_finite_measure (μ.singular_part ν) :=
is_locally_finite_measure_of_le $ singular_part_le μ ν
instance [is_finite_measure μ] : is_finite_measure (ν.with_density $ μ.rn_deriv ν) :=
is_finite_measure_of_le μ $ with_density_rn_deriv_le μ ν
instance [sigma_finite μ] : sigma_finite (ν.with_density $ μ.rn_deriv ν) :=
sigma_finite_of_le μ $ with_density_rn_deriv_le μ ν
instance [topological_space α] [is_locally_finite_measure μ] :
is_locally_finite_measure (ν.with_density $ μ.rn_deriv ν) :=
is_locally_finite_measure_of_le $ with_density_rn_deriv_le μ ν
lemma lintegral_rn_deriv_lt_top_of_measure_ne_top
{μ : measure α} (ν : measure α) {s : set α} (hs : μ s ≠ ∞) :
∫⁻ x in s, μ.rn_deriv ν x ∂ν < ∞ :=
begin
by_cases hl : have_lebesgue_decomposition μ ν,
{ haveI := hl,
obtain ⟨-, -, hadd⟩ := have_lebesgue_decomposition_spec μ ν,
suffices : ∫⁻ x in to_measurable μ s, μ.rn_deriv ν x ∂ν < ∞,
from lt_of_le_of_lt (lintegral_mono_set (subset_to_measurable _ _)) this,
rw [← with_density_apply _ (measurable_set_to_measurable _ _)],
refine lt_of_le_of_lt
(le_add_left le_rfl : _ ≤ μ.singular_part ν (to_measurable μ s) +
ν.with_density (μ.rn_deriv ν) (to_measurable μ s)) _,
rw [← measure.add_apply, ← hadd, measure_to_measurable],
exact hs.lt_top },
{ erw [measure.rn_deriv, dif_neg hl, lintegral_zero],
exact with_top.zero_lt_top },
end
lemma lintegral_rn_deriv_lt_top
(μ ν : measure α) [is_finite_measure μ] :
∫⁻ x, μ.rn_deriv ν x ∂ν < ∞ :=
begin
rw [← set_lintegral_univ],
exact lintegral_rn_deriv_lt_top_of_measure_ne_top _ (measure_lt_top _ _).ne,
end
/-- The Radon-Nikodym derivative of a sigma-finite measure `μ` with respect to another
measure `ν` is `ν`-almost everywhere finite. -/
theorem rn_deriv_lt_top (μ ν : measure α) [sigma_finite μ] :
∀ᵐ x ∂ν, μ.rn_deriv ν x < ∞ :=
begin
suffices : ∀ n, ∀ᵐ x ∂ν, x ∈ spanning_sets μ n → μ.rn_deriv ν x < ∞,
{ filter_upwards [ae_all_iff.2 this] with _ hx using hx _ (mem_spanning_sets_index _ _), },
assume n,
rw ← ae_restrict_iff' (measurable_spanning_sets _ _),
apply ae_lt_top (measurable_rn_deriv _ _),
refine (lintegral_rn_deriv_lt_top_of_measure_ne_top _ _).ne,
exact (measure_spanning_sets_lt_top _ _).ne
end
/-- Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a
measurable function such that `μ = s + fν`, then `s = μ.singular_part μ`.
This theorem provides the uniqueness of the `singular_part` in the Lebesgue decomposition theorem,
while `measure_theory.measure.eq_rn_deriv` provides the uniqueness of the
`rn_deriv`. -/
theorem eq_singular_part {s : measure α} {f : α → ℝ≥0∞} (hf : measurable f)
(hs : s ⊥ₘ ν) (hadd : μ = s + ν.with_density f) :
s = μ.singular_part ν :=
begin
haveI : have_lebesgue_decomposition μ ν := ⟨⟨⟨s, f⟩, hf, hs, hadd⟩⟩,
obtain ⟨hmeas, hsing, hadd'⟩ := have_lebesgue_decomposition_spec μ ν,
obtain ⟨⟨S, hS₁, hS₂, hS₃⟩, ⟨T, hT₁, hT₂, hT₃⟩⟩ := ⟨hs, hsing⟩,
rw hadd' at hadd,
have hνinter : ν (S ∩ T)ᶜ = 0,
{ rw compl_inter,
refine nonpos_iff_eq_zero.1 (le_trans (measure_union_le _ _) _),
rw [hT₃, hS₃, add_zero],
exact le_rfl },
have heq : s.restrict (S ∩ T)ᶜ = (μ.singular_part ν).restrict (S ∩ T)ᶜ,
{ ext1 A hA,
have hf : ν.with_density f (A ∩ (S ∩ T)ᶜ) = 0,
{ refine with_density_absolutely_continuous ν _ _,
rw ← nonpos_iff_eq_zero,
exact hνinter ▸ measure_mono (inter_subset_right _ _) },
have hrn : ν.with_density (μ.rn_deriv ν) (A ∩ (S ∩ T)ᶜ) = 0,
{ refine with_density_absolutely_continuous ν _ _,
rw ← nonpos_iff_eq_zero,
exact hνinter ▸ measure_mono (inter_subset_right _ _) },
rw [restrict_apply hA, restrict_apply hA, ← add_zero (s (A ∩ (S ∩ T)ᶜ)), ← hf,
← add_apply, ← hadd, add_apply, hrn, add_zero] },
have heq' : ∀ A : set α, measurable_set A → s A = s.restrict (S ∩ T)ᶜ A,
{ intros A hA,
have hsinter : s (A ∩ (S ∩ T)) = 0,
{ rw ← nonpos_iff_eq_zero,
exact hS₂ ▸ measure_mono ((inter_subset_right _ _).trans (inter_subset_left _ _)) },
rw [restrict_apply hA, ← diff_eq, ae_disjoint.measure_diff_left hsinter] },
ext1 A hA,
have hμinter : μ.singular_part ν (A ∩ (S ∩ T)) = 0,
{ rw ← nonpos_iff_eq_zero,
exact hT₂ ▸ measure_mono ((inter_subset_right _ _).trans (inter_subset_right _ _)) },
rw [heq' A hA, heq, restrict_apply hA, ← diff_eq, ae_disjoint.measure_diff_left hμinter]
end
lemma singular_part_zero (ν : measure α) : (0 : measure α).singular_part ν = 0 :=
begin
refine (eq_singular_part measurable_zero mutually_singular.zero_left _).symm,
rw [zero_add, with_density_zero],
end
lemma singular_part_smul (μ ν : measure α) (r : ℝ≥0) :
(r • μ).singular_part ν = r • (μ.singular_part ν) :=
begin
by_cases hr : r = 0,
{ rw [hr, zero_smul, zero_smul, singular_part_zero] },
by_cases hl : have_lebesgue_decomposition μ ν,
{ haveI := hl,
refine (eq_singular_part ((measurable_rn_deriv μ ν).const_smul (r : ℝ≥0∞))
(mutually_singular.smul r (have_lebesgue_decomposition_spec _ _).2.1) _).symm,
rw [with_density_smul _ (measurable_rn_deriv _ _), ← smul_add,
← have_lebesgue_decomposition_add μ ν, ennreal.smul_def] },
{ rw [singular_part, singular_part, dif_neg hl, dif_neg, smul_zero],
refine λ hl', hl _,
rw ← inv_smul_smul₀ hr μ,
exact @measure.have_lebesgue_decomposition_smul _ _ _ _ hl' _ }
end
lemma singular_part_add (μ₁ μ₂ ν : measure α)
[have_lebesgue_decomposition μ₁ ν] [have_lebesgue_decomposition μ₂ ν] :
(μ₁ + μ₂).singular_part ν = μ₁.singular_part ν + μ₂.singular_part ν :=
begin
refine (eq_singular_part
((measurable_rn_deriv μ₁ ν).add (measurable_rn_deriv μ₂ ν))
((have_lebesgue_decomposition_spec _ _).2.1.add_left (have_lebesgue_decomposition_spec _ _).2.1)
_).symm,
erw with_density_add (measurable_rn_deriv μ₁ ν) (measurable_rn_deriv μ₂ ν),
conv_rhs { rw [add_assoc, add_comm (μ₂.singular_part ν), ← add_assoc, ← add_assoc] },
rw [← have_lebesgue_decomposition_add μ₁ ν, add_assoc,
add_comm (ν.with_density (μ₂.rn_deriv ν)),
← have_lebesgue_decomposition_add μ₂ ν]
end
lemma singular_part_with_density (ν : measure α) {f : α → ℝ≥0∞} (hf : measurable f) :
(ν.with_density f).singular_part ν = 0 :=
begin
have : ν.with_density f = 0 + ν.with_density f, by rw zero_add,
exact (eq_singular_part hf mutually_singular.zero_left this).symm,
end
/-- Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a
measurable function such that `μ = s + fν`, then `f = μ.rn_deriv ν`.
This theorem provides the uniqueness of the `rn_deriv` in the Lebesgue decomposition
theorem, while `measure_theory.measure.eq_singular_part` provides the uniqueness of the
`singular_part`. Here, the uniqueness is given in terms of the measures, while the uniqueness in
terms of the functions is given in `eq_rn_deriv`. -/
theorem eq_with_density_rn_deriv {s : measure α} {f : α → ℝ≥0∞} (hf : measurable f)
(hs : s ⊥ₘ ν) (hadd : μ = s + ν.with_density f) :
ν.with_density f = ν.with_density (μ.rn_deriv ν) :=
begin
haveI : have_lebesgue_decomposition μ ν := ⟨⟨⟨s, f⟩, hf, hs, hadd⟩⟩,
obtain ⟨hmeas, hsing, hadd'⟩ := have_lebesgue_decomposition_spec μ ν,
obtain ⟨⟨S, hS₁, hS₂, hS₃⟩, ⟨T, hT₁, hT₂, hT₃⟩⟩ := ⟨hs, hsing⟩,
rw hadd' at hadd,
have hνinter : ν (S ∩ T)ᶜ = 0,
{ rw compl_inter,
refine nonpos_iff_eq_zero.1 (le_trans (measure_union_le _ _) _),
rw [hT₃, hS₃, add_zero],
exact le_rfl },
have heq : (ν.with_density f).restrict (S ∩ T) =
(ν.with_density (μ.rn_deriv ν)).restrict (S ∩ T),
{ ext1 A hA,
have hs : s (A ∩ (S ∩ T)) = 0,
{ rw ← nonpos_iff_eq_zero,
exact hS₂ ▸ measure_mono ((inter_subset_right _ _).trans (inter_subset_left _ _)) },
have hsing : μ.singular_part ν (A ∩ (S ∩ T)) = 0,
{ rw ← nonpos_iff_eq_zero,
exact hT₂ ▸ measure_mono
((inter_subset_right _ _).trans (inter_subset_right _ _)) },
rw [restrict_apply hA, restrict_apply hA, ← add_zero (ν.with_density f (A ∩ (S ∩ T))),
← hs, ← add_apply, add_comm, ← hadd, add_apply, hsing, zero_add] },
have heq' : ∀ A : set α, measurable_set A →
ν.with_density f A = (ν.with_density f).restrict (S ∩ T) A,
{ intros A hA,
have hνfinter : ν.with_density f (A ∩ (S ∩ T)ᶜ) = 0,
{ rw ← nonpos_iff_eq_zero,
exact with_density_absolutely_continuous ν f hνinter ▸
measure_mono (inter_subset_right _ _) },
rw [restrict_apply hA, ← add_zero (ν.with_density f (A ∩ (S ∩ T))), ← hνfinter,
← diff_eq, measure_inter_add_diff _ (hS₁.inter hT₁)] },
ext1 A hA,
have hνrn : ν.with_density (μ.rn_deriv ν) (A ∩ (S ∩ T)ᶜ) = 0,
{ rw ← nonpos_iff_eq_zero,
exact with_density_absolutely_continuous ν (μ.rn_deriv ν) hνinter ▸
measure_mono (inter_subset_right _ _) },
rw [heq' A hA, heq, ← add_zero ((ν.with_density (μ.rn_deriv ν)).restrict (S ∩ T) A),
← hνrn, restrict_apply hA, ← diff_eq, measure_inter_add_diff _ (hS₁.inter hT₁)]
end
/-- Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a
measurable function such that `μ = s + fν`, then `f = μ.rn_deriv ν`.
This theorem provides the uniqueness of the `rn_deriv` in the Lebesgue decomposition
theorem, while `measure_theory.measure.eq_singular_part` provides the uniqueness of the
`singular_part`. Here, the uniqueness is given in terms of the functions, while the uniqueness in
terms of the functions is given in `eq_with_density_rn_deriv`. -/
theorem eq_rn_deriv [sigma_finite ν] {s : measure α} {f : α → ℝ≥0∞} (hf : measurable f)
(hs : s ⊥ₘ ν) (hadd : μ = s + ν.with_density f) :
f =ᵐ[ν] μ.rn_deriv ν :=
begin
refine ae_eq_of_forall_set_lintegral_eq_of_sigma_finite hf (measurable_rn_deriv μ ν) _,
assume a ha h'a,
calc ∫⁻ (x : α) in a, f x ∂ν = ν.with_density f a : (with_density_apply f ha).symm
... = ν.with_density (μ.rn_deriv ν) a : by rw eq_with_density_rn_deriv hf hs hadd
... = ∫⁻ (x : α) in a, μ.rn_deriv ν x ∂ν : with_density_apply _ ha
end
/-- The Radon-Nikodym derivative of `f ν` with respect to `ν` is `f`. -/
theorem rn_deriv_with_density (ν : measure α) [sigma_finite ν] {f : α → ℝ≥0∞} (hf : measurable f) :
(ν.with_density f).rn_deriv ν =ᵐ[ν] f :=
begin
have : ν.with_density f = 0 + ν.with_density f, by rw zero_add,
exact (eq_rn_deriv hf mutually_singular.zero_left this).symm,
end
/-- The Radon-Nikodym derivative of the restriction of a measure to a measurable set is the
indicator function of this set. -/
theorem rn_deriv_restrict (ν : measure α) [sigma_finite ν] {s : set α} (hs : measurable_set s) :
(ν.restrict s).rn_deriv ν =ᵐ[ν] s.indicator 1 :=
begin
rw ← with_density_indicator_one hs,
exact rn_deriv_with_density _ (measurable_one.indicator hs)
end
open vector_measure signed_measure
/-- If two finite measures `μ` and `ν` are not mutually singular, there exists some `ε > 0` and
a measurable set `E`, such that `ν(E) > 0` and `E` is positive with respect to `μ - εν`.
This lemma is useful for the Lebesgue decomposition theorem. -/
lemma exists_positive_of_not_mutually_singular
(μ ν : measure α) [is_finite_measure μ] [is_finite_measure ν] (h : ¬ μ ⊥ₘ ν) :
∃ ε : ℝ≥0, 0 < ε ∧ ∃ E : set α, measurable_set E ∧ 0 < ν E ∧
0 ≤[E] μ.to_signed_measure - (ε • ν).to_signed_measure :=
begin
-- for all `n : ℕ`, obtain the Hahn decomposition for `μ - (1 / n) ν`
have : ∀ n : ℕ, ∃ i : set α, measurable_set i ∧
0 ≤[i] (μ.to_signed_measure - ((1 / (n + 1) : ℝ≥0) • ν).to_signed_measure) ∧
(μ.to_signed_measure - ((1 / (n + 1) : ℝ≥0) • ν).to_signed_measure) ≤[iᶜ] 0,
{ intro, exact exists_compl_positive_negative _ },
choose f hf₁ hf₂ hf₃ using this,
-- set `A` to be the intersection of all the negative parts of obtained Hahn decompositions
-- and we show that `μ A = 0`
set A := ⋂ n, (f n)ᶜ with hA₁,
have hAmeas : measurable_set A,
{ exact measurable_set.Inter (λ n, (hf₁ n).compl) },
have hA₂ : ∀ n : ℕ, (μ.to_signed_measure - ((1 / (n + 1) : ℝ≥0) • ν).to_signed_measure) ≤[A] 0,
{ intro n, exact restrict_le_restrict_subset _ _ (hf₁ n).compl (hf₃ n) (Inter_subset _ _) },
have hA₃ : ∀ n : ℕ, μ A ≤ (1 / (n + 1) : ℝ≥0) * ν A,
{ intro n,
have := nonpos_of_restrict_le_zero _ (hA₂ n),
rwa [to_signed_measure_sub_apply hAmeas, sub_nonpos, ennreal.to_real_le_to_real] at this,
exacts [ne_of_lt (measure_lt_top _ _), ne_of_lt (measure_lt_top _ _)] },
have hμ : μ A = 0,
{ lift μ A to ℝ≥0 using ne_of_lt (measure_lt_top _ _) with μA,
lift ν A to ℝ≥0 using ne_of_lt (measure_lt_top _ _) with νA,
rw ennreal.coe_eq_zero,
by_cases hb : 0 < νA,
{ suffices : ∀ b, 0 < b → μA ≤ b,
{ by_contra,
have h' := this (μA / 2) (nnreal.half_pos (zero_lt_iff.2 h)),
rw ← @not_not (μA ≤ μA / 2) at h',
exact h' (not_le.2 (nnreal.half_lt_self h)) },
intros c hc,
have : ∃ n : ℕ, 1 / (n + 1 : ℝ) < c * νA⁻¹, refine exists_nat_one_div_lt _,
{ refine mul_pos hc _,
rw _root_.inv_pos, exact hb },
rcases this with ⟨n, hn⟩,
have hb₁ : (0 : ℝ) < νA⁻¹, { rw _root_.inv_pos, exact hb },
have h' : 1 / (↑n + 1) * νA < c,
{ rw [← nnreal.coe_lt_coe, ← mul_lt_mul_right hb₁, nnreal.coe_mul, mul_assoc,
← nnreal.coe_inv, ← nnreal.coe_mul, _root_.mul_inv_cancel, ← nnreal.coe_mul,
mul_one, nnreal.coe_inv],
{ convert hn, simp },
{ exact ne.symm (ne_of_lt hb) } },
refine le_trans _ (le_of_lt h'),
rw [← ennreal.coe_le_coe, ennreal.coe_mul],
exact hA₃ n },
{ rw [not_lt, le_zero_iff] at hb,
specialize hA₃ 0,
simp [hb, le_zero_iff] at hA₃,
assumption } },
-- since `μ` and `ν` are not mutually singular, `μ A = 0` implies `ν Aᶜ > 0`
rw mutually_singular at h, push_neg at h,
have := h _ hAmeas hμ,
simp_rw [hA₁, compl_Inter, compl_compl] at this,
-- as `Aᶜ = ⋃ n, f n`, `ν Aᶜ > 0` implies there exists some `n` such that `ν (f n) > 0`
obtain ⟨n, hn⟩ := exists_measure_pos_of_not_measure_Union_null this,
-- thus, choosing `f n` as the set `E` suffices
exact ⟨1 / (n + 1), by simp, f n, hf₁ n, hn, hf₂ n⟩,
end
namespace lebesgue_decomposition
/-- Given two measures `μ` and `ν`, `measurable_le μ ν` is the set of measurable
functions `f`, such that, for all measurable sets `A`, `∫⁻ x in A, f x ∂μ ≤ ν A`.
This is useful for the Lebesgue decomposition theorem. -/
def measurable_le (μ ν : measure α) : set (α → ℝ≥0∞) :=
{ f | measurable f ∧ ∀ (A : set α) (hA : measurable_set A), ∫⁻ x in A, f x ∂μ ≤ ν A }
lemma zero_mem_measurable_le : (0 : α → ℝ≥0∞) ∈ measurable_le μ ν :=
⟨measurable_zero, λ A hA, by simp⟩
lemma max_measurable_le (f g : α → ℝ≥0∞)
(hf : f ∈ measurable_le μ ν) (hg : g ∈ measurable_le μ ν) (A : set α) (hA : measurable_set A) :
∫⁻ a in A, max (f a) (g a) ∂μ ≤
∫⁻ a in A ∩ { a | f a ≤ g a }, g a ∂μ + ∫⁻ a in A ∩ { a | g a < f a }, f a ∂μ :=
begin
rw [← lintegral_indicator _ hA, ← lintegral_indicator f,
← lintegral_indicator g, ← lintegral_add],
{ refine lintegral_mono (λ a, _),
by_cases haA : a ∈ A,
{ by_cases f a ≤ g a,
{ simp only,
rw [indicator_of_mem haA, indicator_of_mem, indicator_of_not_mem, add_zero],
simp only [le_refl, max_le_iff, and_true, h],
{ rintro ⟨_, hc⟩, exact false.elim ((not_lt.2 h) hc) },
{ exact ⟨haA, h⟩ } },
{ simp only,
rw [indicator_of_mem haA, indicator_of_mem _ f,
indicator_of_not_mem, zero_add],
simp only [true_and, le_refl, max_le_iff, le_of_lt (not_le.1 h)],
{ rintro ⟨_, hc⟩, exact false.elim (h hc) },
{ exact ⟨haA, not_le.1 h⟩ } } },
{ simp [indicator_of_not_mem haA] } },
{ exact measurable.indicator hg.1 (hA.inter (measurable_set_le hf.1 hg.1)) },
{ exact measurable.indicator hf.1 (hA.inter (measurable_set_lt hg.1 hf.1)) },
{ exact hA.inter (measurable_set_le hf.1 hg.1) },
{ exact hA.inter (measurable_set_lt hg.1 hf.1) },
end
lemma sup_mem_measurable_le {f g : α → ℝ≥0∞}
(hf : f ∈ measurable_le μ ν) (hg : g ∈ measurable_le μ ν) :
(λ a, f a ⊔ g a) ∈ measurable_le μ ν :=
begin
simp_rw ennreal.sup_eq_max,
refine ⟨measurable.max hf.1 hg.1, λ A hA, _⟩,
have h₁ := hA.inter (measurable_set_le hf.1 hg.1),
have h₂ := hA.inter (measurable_set_lt hg.1 hf.1),
refine le_trans (max_measurable_le f g hf hg A hA) _,
refine (add_le_add (hg.2 _ h₁) (hf.2 _ h₂)).trans_eq _,
{ simp only [← not_le, ← compl_set_of, ← diff_eq],
exact measure_inter_add_diff _ (measurable_set_le hf.1 hg.1) }
end
lemma supr_succ_eq_sup {α} (f : ℕ → α → ℝ≥0∞) (m : ℕ) (a : α) :
(⨆ (k : ℕ) (hk : k ≤ m + 1), f k a) = f m.succ a ⊔ ⨆ (k : ℕ) (hk : k ≤ m), f k a :=
begin
ext x,
simp only [option.mem_def, ennreal.some_eq_coe],
split; intro h; rw ← h, symmetry,
all_goals
{ set c := (⨆ (k : ℕ) (hk : k ≤ m + 1), f k a) with hc,
set d := (f m.succ a ⊔ ⨆ (k : ℕ) (hk : k ≤ m), f k a) with hd,
rw [@le_antisymm_iff ℝ≥0∞, hc, hd], -- Specifying the type is weirdly necessary
refine ⟨_, _⟩,
{ refine supr₂_le (λ n hn, _),
rcases nat.of_le_succ hn with (h | h),
{ exact le_sup_of_le_right (le_supr₂ n h) },
{ exact h ▸ le_sup_left } },
{ refine sup_le _ (bsupr_mono $ λ n hn, hn.trans m.le_succ),
convert @le_supr₂ _ _ (λ i, i ≤ m + 1) _ _ m.succ le_rfl,
refl } }
end
lemma supr_mem_measurable_le
(f : ℕ → α → ℝ≥0∞) (hf : ∀ n, f n ∈ measurable_le μ ν) (n : ℕ) :
(λ x, ⨆ k (hk : k ≤ n), f k x) ∈ measurable_le μ ν :=
begin
induction n with m hm,
{ refine ⟨_, _⟩,
{ simp [(hf 0).1] },
{ intros A hA, simp [(hf 0).2 A hA] } },
{ have : (λ (a : α), ⨆ (k : ℕ) (hk : k ≤ m + 1), f k a) =
(λ a, f m.succ a ⊔ ⨆ (k : ℕ) (hk : k ≤ m), f k a),
{ exact funext (λ _, supr_succ_eq_sup _ _ _) },
refine ⟨measurable_supr (λ n, measurable.supr_Prop _ (hf n).1), λ A hA, _⟩,
rw this, exact (sup_mem_measurable_le (hf m.succ) hm).2 A hA }
end
lemma supr_mem_measurable_le'
(f : ℕ → α → ℝ≥0∞) (hf : ∀ n, f n ∈ measurable_le μ ν) (n : ℕ) :
(⨆ k (hk : k ≤ n), f k) ∈ measurable_le μ ν :=
begin
convert supr_mem_measurable_le f hf n,
ext, simp
end
section supr_lemmas --TODO: these statements should be moved elsewhere
omit m
lemma supr_monotone {α : Type*} (f : ℕ → α → ℝ≥0∞) :
monotone (λ n x, ⨆ k (hk : k ≤ n), f k x) :=
λ n m hnm x, bsupr_mono $ λ i, ge_trans hnm
lemma supr_monotone' {α : Type*} (f : ℕ → α → ℝ≥0∞) (x : α) :
monotone (λ n, ⨆ k (hk : k ≤ n), f k x) :=
λ n m hnm, supr_monotone f hnm x
lemma supr_le_le {α : Type*} (f : ℕ → α → ℝ≥0∞) (n k : ℕ) (hk : k ≤ n) :
f k ≤ λ x, ⨆ k (hk : k ≤ n), f k x :=
λ x, le_supr₂ k hk
end supr_lemmas
/-- `measurable_le_eval μ ν` is the set of `∫⁻ x, f x ∂μ` for all `f ∈ measurable_le μ ν`. -/
def measurable_le_eval (μ ν : measure α) : set ℝ≥0∞ :=
(λ f : α → ℝ≥0∞, ∫⁻ x, f x ∂μ) '' measurable_le μ ν
end lebesgue_decomposition
open lebesgue_decomposition
/-- Any pair of finite measures `μ` and `ν`, `have_lebesgue_decomposition`. That is to say,
there exist a measure `ξ` and a measurable function `f`, such that `ξ` is mutually singular
with respect to `ν` and `μ = ξ + ν.with_density f`.
This is not an instance since this is also shown for the more general σ-finite measures with
`measure_theory.measure.have_lebesgue_decomposition_of_sigma_finite`. -/
theorem have_lebesgue_decomposition_of_finite_measure [is_finite_measure μ] [is_finite_measure ν] :
have_lebesgue_decomposition μ ν :=
⟨begin
have h := @exists_seq_tendsto_Sup _ _ _ _ _ (measurable_le_eval ν μ)
⟨0, 0, zero_mem_measurable_le, by simp⟩ (order_top.bdd_above _),
choose g hmono hg₂ f hf₁ hf₂ using h,
-- we set `ξ` to be the supremum of an increasing sequence of functions obtained from above
set ξ := ⨆ n k (hk : k ≤ n), f k with hξ,
-- we see that `ξ` has the largest integral among all functions in `measurable_le`
have hξ₁ : Sup (measurable_le_eval ν μ) = ∫⁻ a, ξ a ∂ν,
{ have := @lintegral_tendsto_of_tendsto_of_monotone _ _ ν
(λ n, ⨆ k (hk : k ≤ n), f k) (⨆ n k (hk : k ≤ n), f k) _ _ _,
{ refine tendsto_nhds_unique _ this,
refine tendsto_of_tendsto_of_tendsto_of_le_of_le hg₂ tendsto_const_nhds _ _,
{ intro n, rw ← hf₂ n,
apply lintegral_mono,
simp only [supr_apply, supr_le_le f n n le_rfl] },
{ intro n,
exact le_Sup ⟨⨆ (k : ℕ) (hk : k ≤ n), f k, supr_mem_measurable_le' _ hf₁ _, rfl⟩ } },
{ intro n,
refine measurable.ae_measurable _,
convert (supr_mem_measurable_le _ hf₁ n).1,
ext, simp },
{ refine filter.eventually_of_forall (λ a, _),
simp [supr_monotone' f _] },
{ refine filter.eventually_of_forall (λ a, _),
simp [tendsto_at_top_supr (supr_monotone' f a)] } },
have hξm : measurable ξ,
{ convert measurable_supr (λ n, (supr_mem_measurable_le _ hf₁ n).1),
ext, simp [hξ] },
-- `ξ` is the `f` in the theorem statement and we set `μ₁` to be `μ - ν.with_density ξ`
-- since we need `μ₁ + ν.with_density ξ = μ`
set μ₁ := μ - ν.with_density ξ with hμ₁,
have hle : ν.with_density ξ ≤ μ,
{ intros B hB,
rw [hξ, with_density_apply _ hB],
simp_rw [supr_apply],
rw lintegral_supr (λ i, (supr_mem_measurable_le _ hf₁ i).1) (supr_monotone _),
exact supr_le (λ i, (supr_mem_measurable_le _ hf₁ i).2 B hB) },
haveI : is_finite_measure (ν.with_density ξ),
{ refine is_finite_measure_with_density _,
have hle' := hle univ measurable_set.univ,
rw [with_density_apply _ measurable_set.univ, measure.restrict_univ] at hle',
exact ne_top_of_le_ne_top (measure_ne_top _ _) hle' },
refine ⟨⟨μ₁, ξ⟩, hξm, _, _⟩,
{ by_contra,
-- if they are not mutually singular, then from `exists_positive_of_not_mutually_singular`,
-- there exists some `ε > 0` and a measurable set `E`, such that `μ(E) > 0` and `E` is
-- positive with respect to `ν - εμ`
obtain ⟨ε, hε₁, E, hE₁, hE₂, hE₃⟩ := exists_positive_of_not_mutually_singular μ₁ ν h,
simp_rw hμ₁ at hE₃,
have hξle : ∀ A, measurable_set A → ∫⁻ a in A, ξ a ∂ν ≤ μ A,
{ intros A hA, rw hξ,
simp_rw [supr_apply],
rw lintegral_supr (λ n, (supr_mem_measurable_le _ hf₁ n).1) (supr_monotone _),
exact supr_le (λ n, (supr_mem_measurable_le _ hf₁ n).2 A hA) },
-- since `E` is positive, we have `∫⁻ a in A ∩ E, ε + ξ a ∂ν ≤ μ (A ∩ E)` for all `A`
have hε₂ : ∀ A : set α, measurable_set A → ∫⁻ a in A ∩ E, ε + ξ a ∂ν ≤ μ (A ∩ E),
{ intros A hA,
have := subset_le_of_restrict_le_restrict _ _ hE₁ hE₃ (inter_subset_right A E),
rwa [zero_apply, to_signed_measure_sub_apply (hA.inter hE₁),
measure.sub_apply (hA.inter hE₁) hle,
ennreal.to_real_sub_of_le _ (ne_of_lt (measure_lt_top _ _)), sub_nonneg,
le_sub_iff_add_le, ← ennreal.to_real_add, ennreal.to_real_le_to_real,
measure.coe_smul, pi.smul_apply, with_density_apply _ (hA.inter hE₁),
show ε • ν (A ∩ E) = (ε : ℝ≥0∞) * ν (A ∩ E), by refl,
← set_lintegral_const, ← lintegral_add measurable_const hξm] at this,
{ rw [ne.def, ennreal.add_eq_top, not_or_distrib],
exact ⟨ne_of_lt (measure_lt_top _ _), ne_of_lt (measure_lt_top _ _)⟩ },
{ exact ne_of_lt (measure_lt_top _ _) },
{ exact ne_of_lt (measure_lt_top _ _) },
{ exact ne_of_lt (measure_lt_top _ _) },
{ rw with_density_apply _ (hA.inter hE₁),
exact hξle (A ∩ E) (hA.inter hE₁) },
{ apply_instance } },
-- from this, we can show `ξ + ε * E.indicator` is a function in `measurable_le` with
-- integral greater than `ξ`
have hξε : ξ + E.indicator (λ _, ε) ∈ measurable_le ν μ,
{ refine ⟨measurable.add hξm (measurable.indicator measurable_const hE₁), λ A hA, _⟩,
have : ∫⁻ a in A, (ξ + E.indicator (λ _, ε)) a ∂ν =
∫⁻ a in A ∩ E, ε + ξ a ∂ν + ∫⁻ a in A ∩ Eᶜ, ξ a ∂ν,
{ rw [lintegral_add measurable_const hξm, add_assoc,
← lintegral_union (hA.inter hE₁) (hA.inter hE₁.compl)
(disjoint.mono (inter_subset_right _ _) (inter_subset_right _ _)
disjoint_compl_right), inter_union_compl],
simp_rw [pi.add_apply],
rw [lintegral_add hξm (measurable.indicator measurable_const hE₁), add_comm],
refine congr_fun (congr_arg has_add.add _) _,
rw [set_lintegral_const, lintegral_indicator _ hE₁, set_lintegral_const,
measure.restrict_apply hE₁, inter_comm] },
rw [this, ← measure_inter_add_diff A hE₁],
exact add_le_add (hε₂ A hA) (hξle (A \ E) (hA.diff hE₁)) },
have : ∫⁻ a, ξ a + E.indicator (λ _, ε) a ∂ν ≤ Sup (measurable_le_eval ν μ) :=
le_Sup ⟨ξ + E.indicator (λ _, ε), hξε, rfl⟩,
-- but this contradicts the maximality of `∫⁻ x, ξ x ∂ν`
refine not_lt.2 this _,
rw [hξ₁, lintegral_add hξm (measurable.indicator (measurable_const) hE₁),
lintegral_indicator _ hE₁, set_lintegral_const],
refine ennreal.lt_add_right _ (ennreal.mul_pos_iff.2 ⟨ennreal.coe_pos.2 hε₁, hE₂⟩).ne',
have := measure_ne_top (ν.with_density ξ) univ,
rwa [with_density_apply _ measurable_set.univ, measure.restrict_univ] at this },
-- since `ν.with_density ξ ≤ μ`, it is clear that `μ = μ₁ + ν.with_density ξ`
{ rw hμ₁, ext1 A hA,
rw [measure.coe_add, pi.add_apply, measure.sub_apply hA hle,
add_comm, add_tsub_cancel_of_le (hle A hA)] },
end⟩
local attribute [instance] have_lebesgue_decomposition_of_finite_measure
instance {S : μ.finite_spanning_sets_in {s : set α | measurable_set s}} (n : ℕ) :
is_finite_measure (μ.restrict $ S.set n) :=
⟨by { rw [restrict_apply measurable_set.univ, univ_inter], exact S.finite _ }⟩
/-- **The Lebesgue decomposition theorem**: Any pair of σ-finite measures `μ` and `ν`
`have_lebesgue_decomposition`. That is to say, there exist a measure `ξ` and a measurable function
`f`, such that `ξ` is mutually singular with respect to `ν` and `μ = ξ + ν.with_density f` -/
@[priority 100] -- see Note [lower instance priority]
instance have_lebesgue_decomposition_of_sigma_finite
(μ ν : measure α) [sigma_finite μ] [sigma_finite ν] :
have_lebesgue_decomposition μ ν :=
⟨begin
-- Since `μ` and `ν` are both σ-finite, there exists a sequence of pairwise disjoint spanning
-- sets which are finite with respect to both `μ` and `ν`
obtain ⟨S, T, h₁, h₂⟩ := exists_eq_disjoint_finite_spanning_sets_in μ ν,
have h₃ : pairwise (disjoint on T.set) := h₁ ▸ h₂,
-- We define `μn` and `νn` as sequences of measures such that `μn n = μ ∩ S n` and
-- `νn n = ν ∩ S n` where `S` is the aforementioned finite spanning set sequence.
-- Since `S` is spanning, it is clear that `sum μn = μ` and `sum νn = ν`
set μn : ℕ → measure α := λ n, μ.restrict (S.set n) with hμn,
have hμ : μ = sum μn,
{ rw [hμn, ← restrict_Union h₂ S.set_mem, S.spanning, restrict_univ] },
set νn : ℕ → measure α := λ n, ν.restrict (T.set n) with hνn,
have hν : ν = sum νn,
{ rw [hνn, ← restrict_Union h₃ T.set_mem, T.spanning, restrict_univ] },
-- As `S` is finite with respect to both `μ` and `ν`, it is clear that `μn n` and `νn n` are
-- finite measures for all `n : ℕ`. Thus, we may apply the finite Lebesgue decomposition theorem
-- to `μn n` and `νn n`. We define `ξ` as the sum of the singular part of the Lebesgue
-- decompositions of `μn n` and `νn n`, and `f` as the sum of the Radon-Nikodym derviatives of
-- `μn n` and `νn n` restricted on `S n`
set ξ := sum (λ n, singular_part (μn n) (νn n)) with hξ,
set f := ∑' n, (S.set n).indicator (rn_deriv (μn n) (νn n)) with hf,
-- I claim `ξ` and `f` form a Lebesgue decomposition of `μ` and `ν`
refine ⟨⟨ξ, f⟩, _, _, _⟩,
{ exact measurable.ennreal_tsum' (λ n, measurable.indicator
(measurable_rn_deriv (μn n) (νn n)) (S.set_mem n)) },
-- We show that `ξ` is mutually singular with respect to `ν`
{ choose A hA₁ hA₂ hA₃ using λ n, mutually_singular_singular_part (μn n) (νn n),
simp only [hξ],
-- We use the set `B := ⋃ j, (S.set j) ∩ A j` where `A n` is the set provided as
-- `singular_part (μn n) (νn n) ⊥ₘ νn n`
refine ⟨⋃ j, (S.set j) ∩ A j,
measurable_set.Union (λ n, (S.set_mem n).inter (hA₁ n)), _, _⟩,
-- `ξ B = 0` since `ξ B = ∑ i j, singular_part (μn j) (νn j) (S.set i ∩ A i)`
-- `= ∑ i, singular_part (μn i) (νn i) (S.set i ∩ A i)`
-- `≤ ∑ i, singular_part (μn i) (νn i) (A i) = 0`
-- where the second equality follows as `singular_part (μn j) (νn j) (S.set i ∩ A i)` vanishes
-- for all `i ≠ j`
{ rw [measure_Union],
{ have : ∀ i, (sum (λ n, (μn n).singular_part (νn n))) (S.set i ∩ A i) =
(μn i).singular_part (νn i) (S.set i ∩ A i),
{ intro i, rw [sum_apply _ ((S.set_mem i).inter (hA₁ i)), tsum_eq_single i],
{ intros j hij,
rw [hμn, ← nonpos_iff_eq_zero],
refine le_trans ((singular_part_le _ _) _ ((S.set_mem i).inter (hA₁ i))) (le_of_eq _),
rw [restrict_apply ((S.set_mem i).inter (hA₁ i)), inter_comm, ← inter_assoc],
have : disjoint (S.set j) (S.set i) := h₂ j i hij,
rw disjoint_iff_inter_eq_empty at this,
rw [this, empty_inter, measure_empty] },
{ apply_instance } },
simp_rw [this, tsum_eq_zero_iff ennreal.summable],
intro n, exact measure_mono_null (inter_subset_right _ _) (hA₂ n) },
{ exact h₂.mono (λ i j, disjoint.mono inf_le_left inf_le_left) },
{ exact λ n, (S.set_mem n).inter (hA₁ n) } },
-- We will now show `ν Bᶜ = 0`. This follows since `Bᶜ = ⋃ n, S.set n ∩ (A n)ᶜ` and thus,
-- `ν Bᶜ = ∑ i, ν (S.set i ∩ (A i)ᶜ) = ∑ i, (νn i) (A i)ᶜ = 0`
{ have hcompl : is_compl (⋃ n, (S.set n ∩ A n)) (⋃ n, S.set n ∩ (A n)ᶜ),
{ split,
{ rintro x ⟨hx₁, hx₂⟩, rw mem_Union at hx₁ hx₂,
obtain ⟨⟨i, hi₁, hi₂⟩, ⟨j, hj₁, hj₂⟩⟩ := ⟨hx₁, hx₂⟩,
have : i = j,
{ by_contra hij, exact h₂ i j hij ⟨hi₁, hj₁⟩ },
exact hj₂ (this ▸ hi₂) },
{ intros x hx,
simp only [mem_Union, sup_eq_union, mem_inter_eq,
mem_union_eq, mem_compl_eq, or_iff_not_imp_left],
intro h, push_neg at h,
rw [top_eq_univ, ← S.spanning, mem_Union] at hx,
obtain ⟨i, hi⟩ := hx,
exact ⟨i, hi, h i hi⟩ } },
rw [hcompl.compl_eq, measure_Union, tsum_eq_zero_iff ennreal.summable],
{ intro n, rw [inter_comm, ← restrict_apply (hA₁ n).compl, ← hA₃ n, hνn, h₁] },
{ exact h₂.mono (λ i j, disjoint.mono inf_le_left inf_le_left) },
{ exact λ n, (S.set_mem n).inter (hA₁ n).compl } } },
-- Finally, it remains to show `μ = ξ + ν.with_density f`. Since `μ = sum μn`, and
-- `ξ + ν.with_density f = ∑ n, singular_part (μn n) (νn n)`
-- `+ ν.with_density (rn_deriv (μn n) (νn n)) ∩ (S.set n)`,
-- it suffices to show that the individual summands are equal. This follows by the
-- Lebesgue decomposition properties on the individual `μn n` and `νn n`
{ simp only [hξ, hf, hμ],
rw [with_density_tsum _, sum_add_sum],
{ refine sum_congr (λ n, _),
conv_lhs { rw have_lebesgue_decomposition_add (μn n) (νn n) },
suffices heq : (νn n).with_density ((μn n).rn_deriv (νn n)) =
ν.with_density ((S.set n).indicator ((μn n).rn_deriv (νn n))),
{ rw heq },
rw [hν, with_density_indicator (S.set_mem n), restrict_sum _ (S.set_mem n)],
suffices hsumeq : sum (λ (i : ℕ), (νn i).restrict (S.set n)) = νn n,
{ rw hsumeq },
ext1 s hs,
rw [sum_apply _ hs, tsum_eq_single n, hνn, h₁,
restrict_restrict (T.set_mem n), inter_self],
{ intros m hm,
rw [hνn, h₁, restrict_restrict (T.set_mem n),
disjoint_iff_inter_eq_empty.1 (h₃ n m hm.symm), restrict_empty,
coe_zero, pi.zero_apply] },
{ apply_instance } },
{ exact λ n, measurable.indicator (measurable_rn_deriv _ _) (S.set_mem n) } },
end⟩
end measure
namespace signed_measure
open measure
/-- A signed measure `s` is said to `have_lebesgue_decomposition` with respect to a measure `μ`
if the positive part and the negative part of `s` both `have_lebesgue_decomposition` with
respect to `μ`. -/
class have_lebesgue_decomposition (s : signed_measure α) (μ : measure α) : Prop :=
(pos_part : s.to_jordan_decomposition.pos_part.have_lebesgue_decomposition μ)
(neg_part : s.to_jordan_decomposition.neg_part.have_lebesgue_decomposition μ)
attribute [instance] have_lebesgue_decomposition.pos_part
attribute [instance] have_lebesgue_decomposition.neg_part
lemma not_have_lebesgue_decomposition_iff (s : signed_measure α)
(μ : measure α) :
¬ s.have_lebesgue_decomposition μ ↔
¬ s.to_jordan_decomposition.pos_part.have_lebesgue_decomposition μ ∨
¬ s.to_jordan_decomposition.neg_part.have_lebesgue_decomposition μ :=
⟨λ h, not_or_of_imp (λ hp hn, h ⟨hp, hn⟩), λ h hl, (not_and_distrib.2 h) ⟨hl.1, hl.2⟩⟩
-- `infer_instance` directly does not work
@[priority 100] -- see Note [lower instance priority]
instance have_lebesgue_decomposition_of_sigma_finite
(s : signed_measure α) (μ : measure α) [sigma_finite μ] :
s.have_lebesgue_decomposition μ :=
{ pos_part := infer_instance,
neg_part := infer_instance }
instance have_lebesgue_decomposition_neg
(s : signed_measure α) (μ : measure α) [s.have_lebesgue_decomposition μ] :
(-s).have_lebesgue_decomposition μ :=
{ pos_part :=
by { rw [to_jordan_decomposition_neg, jordan_decomposition.neg_pos_part],
apply_instance },
neg_part :=
by { rw [to_jordan_decomposition_neg, jordan_decomposition.neg_neg_part],
apply_instance } }
instance have_lebesgue_decomposition_smul
(s : signed_measure α) (μ : measure α) [s.have_lebesgue_decomposition μ] (r : ℝ≥0) :
(r • s).have_lebesgue_decomposition μ :=
{ pos_part :=
by { rw [to_jordan_decomposition_smul, jordan_decomposition.smul_pos_part],
apply_instance },
neg_part :=
by { rw [to_jordan_decomposition_smul, jordan_decomposition.smul_neg_part],
apply_instance } }
instance have_lebesgue_decomposition_smul_real
(s : signed_measure α) (μ : measure α) [s.have_lebesgue_decomposition μ] (r : ℝ) :
(r • s).have_lebesgue_decomposition μ :=
begin
by_cases hr : 0 ≤ r,
{ lift r to ℝ≥0 using hr,
exact s.have_lebesgue_decomposition_smul μ _ },
{ rw not_le at hr,
refine
{ pos_part :=
by { rw [to_jordan_decomposition_smul_real,
jordan_decomposition.real_smul_pos_part_neg _ _ hr],
apply_instance },
neg_part :=
by { rw [to_jordan_decomposition_smul_real,
jordan_decomposition.real_smul_neg_part_neg _ _ hr],
apply_instance } } }
end
/-- Given a signed measure `s` and a measure `μ`, `s.singular_part μ` is the signed measure
such that `s.singular_part μ + μ.with_densityᵥ (s.rn_deriv μ) = s` and
`s.singular_part μ` is mutually singular with respect to `μ`. -/
def singular_part (s : signed_measure α) (μ : measure α) : signed_measure α :=
(s.to_jordan_decomposition.pos_part.singular_part μ).to_signed_measure -
(s.to_jordan_decomposition.neg_part.singular_part μ).to_signed_measure
section
lemma singular_part_mutually_singular (s : signed_measure α) (μ : measure α) :
s.to_jordan_decomposition.pos_part.singular_part μ ⊥ₘ
s.to_jordan_decomposition.neg_part.singular_part μ :=
begin
by_cases hl : s.have_lebesgue_decomposition μ,
{ haveI := hl,
obtain ⟨i, hi, hpos, hneg⟩ := s.to_jordan_decomposition.mutually_singular,
rw s.to_jordan_decomposition.pos_part.have_lebesgue_decomposition_add μ at hpos,
rw s.to_jordan_decomposition.neg_part.have_lebesgue_decomposition_add μ at hneg,
rw [add_apply, add_eq_zero_iff] at hpos hneg,
exact ⟨i, hi, hpos.1, hneg.1⟩ },
{ rw not_have_lebesgue_decomposition_iff at hl,
cases hl with hp hn,
{ rw [measure.singular_part, dif_neg hp],
exact mutually_singular.zero_left },
{ rw [measure.singular_part, measure.singular_part, dif_neg hn],
exact mutually_singular.zero_right } }
end
lemma singular_part_total_variation (s : signed_measure α) (μ : measure α) :
(s.singular_part μ).total_variation =
s.to_jordan_decomposition.pos_part.singular_part μ +
s.to_jordan_decomposition.neg_part.singular_part μ :=
begin
have : (s.singular_part μ).to_jordan_decomposition =
⟨s.to_jordan_decomposition.pos_part.singular_part μ,
s.to_jordan_decomposition.neg_part.singular_part μ, singular_part_mutually_singular s μ⟩,
{ refine jordan_decomposition.to_signed_measure_injective _,
rw to_signed_measure_to_jordan_decomposition,
refl },
{ rw [total_variation, this] },
end
lemma mutually_singular_singular_part (s : signed_measure α) (μ : measure α) :
singular_part s μ ⊥ᵥ μ.to_ennreal_vector_measure :=
begin
rw [mutually_singular_ennreal_iff, singular_part_total_variation],
change _ ⊥ₘ vector_measure.equiv_measure.to_fun (vector_measure.equiv_measure.inv_fun μ),
rw vector_measure.equiv_measure.right_inv μ,
exact (mutually_singular_singular_part _ _).add_left (mutually_singular_singular_part _ _)
end
end
/-- The Radon-Nikodym derivative between a signed measure and a positive measure.
`rn_deriv s μ` satisfies `μ.with_densityᵥ (s.rn_deriv μ) = s`
if and only if `s` is absolutely continuous with respect to `μ` and this fact is known as
`measure_theory.signed_measure.absolutely_continuous_iff_with_density_rn_deriv_eq`
and can be found in `measure_theory.decomposition.radon_nikodym`. -/
def rn_deriv (s : signed_measure α) (μ : measure α) : α → ℝ := λ x,
(s.to_jordan_decomposition.pos_part.rn_deriv μ x).to_real -
(s.to_jordan_decomposition.neg_part.rn_deriv μ x).to_real
variables {s t : signed_measure α}
@[measurability]
lemma measurable_rn_deriv (s : signed_measure α) (μ : measure α) :
measurable (rn_deriv s μ) :=
begin
rw [rn_deriv],
measurability,
end
lemma integrable_rn_deriv (s : signed_measure α) (μ : measure α) :
integrable (rn_deriv s μ) μ :=
begin
refine integrable.sub _ _;
{ split,
{ apply measurable.ae_strongly_measurable, measurability },
exact has_finite_integral_to_real_of_lintegral_ne_top
(lintegral_rn_deriv_lt_top _ μ).ne }
end
variables (s μ)
/-- **The Lebesgue Decomposition theorem between a signed measure and a measure**:
Given a signed measure `s` and a σ-finite measure `μ`, there exist a signed measure `t` and a
measurable and integrable function `f`, such that `t` is mutually singular with respect to `μ`
and `s = t + μ.with_densityᵥ f`. In this case `t = s.singular_part μ` and
`f = s.rn_deriv μ`. -/
theorem singular_part_add_with_density_rn_deriv_eq
[s.have_lebesgue_decomposition μ] :
s.singular_part μ + μ.with_densityᵥ (s.rn_deriv μ) = s :=
begin
conv_rhs { rw [← to_signed_measure_to_jordan_decomposition s,
jordan_decomposition.to_signed_measure] },
rw [singular_part, rn_deriv, with_densityᵥ_sub'
(integrable_to_real_of_lintegral_ne_top _ _) (integrable_to_real_of_lintegral_ne_top _ _),
with_densityᵥ_to_real, with_densityᵥ_to_real, sub_eq_add_neg, sub_eq_add_neg,
add_comm (s.to_jordan_decomposition.pos_part.singular_part μ).to_signed_measure, ← add_assoc,
add_assoc (-(s.to_jordan_decomposition.neg_part.singular_part μ).to_signed_measure),
← to_signed_measure_add, add_comm, ← add_assoc, ← neg_add, ← to_signed_measure_add,
add_comm, ← sub_eq_add_neg],
convert rfl, -- `convert rfl` much faster than `congr`
{ exact (s.to_jordan_decomposition.pos_part.have_lebesgue_decomposition_add μ) },
{ rw add_comm,
exact (s.to_jordan_decomposition.neg_part.have_lebesgue_decomposition_add μ) },
all_goals { exact (lintegral_rn_deriv_lt_top _ _).ne <|> measurability }
end
variables {s μ}
lemma jordan_decomposition_add_with_density_mutually_singular
{f : α → ℝ} (hf : measurable f) (htμ : t ⊥ᵥ μ.to_ennreal_vector_measure) :
t.to_jordan_decomposition.pos_part + μ.with_density (λ (x : α), ennreal.of_real (f x)) ⊥ₘ
t.to_jordan_decomposition.neg_part + μ.with_density (λ (x : α), ennreal.of_real (-f x)) :=
begin
rw [mutually_singular_ennreal_iff, total_variation_mutually_singular_iff] at htμ,
change _ ⊥ₘ vector_measure.equiv_measure.to_fun (vector_measure.equiv_measure.inv_fun μ) ∧
_ ⊥ₘ vector_measure.equiv_measure.to_fun (vector_measure.equiv_measure.inv_fun μ) at htμ,
rw [vector_measure.equiv_measure.right_inv] at htμ,
exact ((jordan_decomposition.mutually_singular _).add_right
(htμ.1.mono_ac (refl _) (with_density_absolutely_continuous _ _))).add_left
((htμ.2.symm.mono_ac (with_density_absolutely_continuous _ _) (refl _)).add_right
(with_density_of_real_mutually_singular hf))
end
lemma to_jordan_decomposition_eq_of_eq_add_with_density
{f : α → ℝ} (hf : measurable f) (hfi : integrable f μ)
(htμ : t ⊥ᵥ μ.to_ennreal_vector_measure) (hadd : s = t + μ.with_densityᵥ f) :
s.to_jordan_decomposition = @jordan_decomposition.mk α _
(t.to_jordan_decomposition.pos_part + μ.with_density (λ x, ennreal.of_real (f x)))
(t.to_jordan_decomposition.neg_part + μ.with_density (λ x, ennreal.of_real (- f x)))
(by { haveI := is_finite_measure_with_density_of_real hfi.2, apply_instance })
(by { haveI := is_finite_measure_with_density_of_real hfi.neg.2, apply_instance })
(jordan_decomposition_add_with_density_mutually_singular hf htμ) :=
begin
haveI := is_finite_measure_with_density_of_real hfi.2,
haveI := is_finite_measure_with_density_of_real hfi.neg.2,
refine to_jordan_decomposition_eq _,
simp_rw [jordan_decomposition.to_signed_measure, hadd],
ext i hi,
rw [vector_measure.sub_apply, to_signed_measure_apply_measurable hi,
to_signed_measure_apply_measurable hi, add_apply, add_apply,
ennreal.to_real_add, ennreal.to_real_add, add_sub_add_comm,
← to_signed_measure_apply_measurable hi, ← to_signed_measure_apply_measurable hi,
← vector_measure.sub_apply, ← jordan_decomposition.to_signed_measure,
to_signed_measure_to_jordan_decomposition, vector_measure.add_apply,
← to_signed_measure_apply_measurable hi, ← to_signed_measure_apply_measurable hi,
with_densityᵥ_eq_with_density_pos_part_sub_with_density_neg_part hfi,
vector_measure.sub_apply];
exact (measure_lt_top _ _).ne
end
private lemma have_lebesgue_decomposition_mk' (μ : measure α)
{f : α → ℝ} (hf : measurable f) (hfi : integrable f μ)
(htμ : t ⊥ᵥ μ.to_ennreal_vector_measure) (hadd : s = t + μ.with_densityᵥ f) :
s.have_lebesgue_decomposition μ :=
begin
have htμ' := htμ,
rw mutually_singular_ennreal_iff at htμ,
change _ ⊥ₘ vector_measure.equiv_measure.to_fun (vector_measure.equiv_measure.inv_fun μ) at htμ,
rw [vector_measure.equiv_measure.right_inv, total_variation_mutually_singular_iff] at htμ,
refine
{ pos_part :=
by { use ⟨t.to_jordan_decomposition.pos_part, λ x, ennreal.of_real (f x)⟩,
refine ⟨hf.ennreal_of_real, htμ.1, _⟩,
rw to_jordan_decomposition_eq_of_eq_add_with_density hf hfi htμ' hadd },
neg_part :=
by { use ⟨t.to_jordan_decomposition.neg_part, λ x, ennreal.of_real (-f x)⟩,
refine ⟨hf.neg.ennreal_of_real, htμ.2, _⟩,
rw to_jordan_decomposition_eq_of_eq_add_with_density hf hfi htμ' hadd } }
end
lemma have_lebesgue_decomposition_mk (μ : measure α) {f : α → ℝ} (hf : measurable f)
(htμ : t ⊥ᵥ μ.to_ennreal_vector_measure) (hadd : s = t + μ.with_densityᵥ f) :
s.have_lebesgue_decomposition μ :=
begin
by_cases hfi : integrable f μ,
{ exact have_lebesgue_decomposition_mk' μ hf hfi htμ hadd },
{ rw [with_densityᵥ, dif_neg hfi, add_zero] at hadd,
refine have_lebesgue_decomposition_mk' μ measurable_zero (integrable_zero _ _ μ) htμ _,
rwa [with_densityᵥ_zero, add_zero] }
end
private theorem eq_singular_part'
(t : signed_measure α) {f : α → ℝ} (hf : measurable f) (hfi : integrable f μ)
(htμ : t ⊥ᵥ μ.to_ennreal_vector_measure) (hadd : s = t + μ.with_densityᵥ f) :
t = s.singular_part μ :=
begin
have htμ' := htμ,
rw [mutually_singular_ennreal_iff, total_variation_mutually_singular_iff] at htμ,
change _ ⊥ₘ vector_measure.equiv_measure.to_fun (vector_measure.equiv_measure.inv_fun μ) ∧
_ ⊥ₘ vector_measure.equiv_measure.to_fun (vector_measure.equiv_measure.inv_fun μ) at htμ,
rw [vector_measure.equiv_measure.right_inv] at htμ,
{ rw [singular_part, ← t.to_signed_measure_to_jordan_decomposition,
jordan_decomposition.to_signed_measure],
congr,
{ have hfpos : measurable (λ x, ennreal.of_real (f x)), { measurability },
refine eq_singular_part hfpos htμ.1 _,
rw to_jordan_decomposition_eq_of_eq_add_with_density hf hfi htμ' hadd },
{ have hfneg : measurable (λ x, ennreal.of_real (-f x)), { measurability },
refine eq_singular_part hfneg htμ.2 _,
rw to_jordan_decomposition_eq_of_eq_add_with_density hf hfi htμ' hadd } },
end
/-- Given a measure `μ`, signed measures `s` and `t`, and a function `f` such that `t` is
mutually singular with respect to `μ` and `s = t + μ.with_densityᵥ f`, we have
`t = singular_part s μ`, i.e. `t` is the singular part of the Lebesgue decomposition between
`s` and `μ`. -/
theorem eq_singular_part (t : signed_measure α) (f : α → ℝ)
(htμ : t ⊥ᵥ μ.to_ennreal_vector_measure) (hadd : s = t + μ.with_densityᵥ f) :
t = s.singular_part μ :=
begin
by_cases hfi : integrable f μ,
{ refine eq_singular_part' t hfi.1.measurable_mk (hfi.congr hfi.1.ae_eq_mk) htμ _,
convert hadd using 2,
exact with_densityᵥ_eq.congr_ae hfi.1.ae_eq_mk.symm },
{ rw [with_densityᵥ, dif_neg hfi, add_zero] at hadd,
refine eq_singular_part' t measurable_zero (integrable_zero _ _ μ) htμ _,
rwa [with_densityᵥ_zero, add_zero] }
end
lemma singular_part_zero (μ : measure α) : (0 : signed_measure α).singular_part μ = 0 :=
begin
refine (eq_singular_part 0 0
vector_measure.mutually_singular.zero_left _).symm,
rw [zero_add, with_densityᵥ_zero],
end
lemma singular_part_neg (s : signed_measure α) (μ : measure α) :
(-s).singular_part μ = - s.singular_part μ :=
begin
have h₁ : ((-s).to_jordan_decomposition.pos_part.singular_part μ).to_signed_measure =
(s.to_jordan_decomposition.neg_part.singular_part μ).to_signed_measure,
{ refine to_signed_measure_congr _,
rw [to_jordan_decomposition_neg, jordan_decomposition.neg_pos_part] },
have h₂ : ((-s).to_jordan_decomposition.neg_part.singular_part μ).to_signed_measure =
(s.to_jordan_decomposition.pos_part.singular_part μ).to_signed_measure,
{ refine to_signed_measure_congr _,
rw [to_jordan_decomposition_neg, jordan_decomposition.neg_neg_part] },
rw [singular_part, singular_part, neg_sub, h₁, h₂],
end
lemma singular_part_smul_nnreal (s : signed_measure α) (μ : measure α) (r : ℝ≥0) :
(r • s).singular_part μ = r • s.singular_part μ :=
begin
rw [singular_part, singular_part, smul_sub, ← to_signed_measure_smul, ← to_signed_measure_smul],
conv_lhs { congr, congr,
rw [to_jordan_decomposition_smul, jordan_decomposition.smul_pos_part,
singular_part_smul], skip, congr,
rw [to_jordan_decomposition_smul, jordan_decomposition.smul_neg_part,
singular_part_smul] }
end
lemma singular_part_smul (s : signed_measure α) (μ : measure α) (r : ℝ) :
(r • s).singular_part μ = r • s.singular_part μ :=
begin
by_cases hr : 0 ≤ r,
{ lift r to ℝ≥0 using hr,
exact singular_part_smul_nnreal s μ r },
{ rw [singular_part, singular_part],
conv_lhs { congr, congr,
rw [to_jordan_decomposition_smul_real,
jordan_decomposition.real_smul_pos_part_neg _ _ (not_le.1 hr), singular_part_smul],
skip, congr,
rw [to_jordan_decomposition_smul_real,
jordan_decomposition.real_smul_neg_part_neg _ _ (not_le.1 hr), singular_part_smul] },
rw [to_signed_measure_smul, to_signed_measure_smul, ← neg_sub, ← smul_sub],
change -(((-r).to_nnreal : ℝ) • _) = _,
rw [← neg_smul, real.coe_to_nnreal _ (le_of_lt (neg_pos.mpr (not_le.1 hr))), neg_neg] }
end
lemma singular_part_add (s t : signed_measure α) (μ : measure α)
[s.have_lebesgue_decomposition μ] [t.have_lebesgue_decomposition μ] :
(s + t).singular_part μ = s.singular_part μ + t.singular_part μ :=
begin
refine (eq_singular_part _ (s.rn_deriv μ + t.rn_deriv μ)
((mutually_singular_singular_part s μ).add_left (mutually_singular_singular_part t μ)) _).symm,
erw [with_densityᵥ_add (integrable_rn_deriv s μ) (integrable_rn_deriv t μ)],
rw [add_assoc, add_comm (t.singular_part μ), add_assoc, add_comm _ (t.singular_part μ),
singular_part_add_with_density_rn_deriv_eq, ← add_assoc,
singular_part_add_with_density_rn_deriv_eq],
end
lemma singular_part_sub (s t : signed_measure α) (μ : measure α)
[s.have_lebesgue_decomposition μ] [t.have_lebesgue_decomposition μ] :
(s - t).singular_part μ = s.singular_part μ - t.singular_part μ :=
by { rw [sub_eq_add_neg, sub_eq_add_neg, singular_part_add, singular_part_neg] }
/-- Given a measure `μ`, signed measures `s` and `t`, and a function `f` such that `t` is
mutually singular with respect to `μ` and `s = t + μ.with_densityᵥ f`, we have
`f = rn_deriv s μ`, i.e. `f` is the Radon-Nikodym derivative of `s` and `μ`. -/
theorem eq_rn_deriv (t : signed_measure α) (f : α → ℝ) (hfi : integrable f μ)
(htμ : t ⊥ᵥ μ.to_ennreal_vector_measure) (hadd : s = t + μ.with_densityᵥ f) :
f =ᵐ[μ] s.rn_deriv μ :=
begin
set f' := hfi.1.mk f,
have hadd' : s = t + μ.with_densityᵥ f',
{ convert hadd using 2,
exact with_densityᵥ_eq.congr_ae hfi.1.ae_eq_mk.symm },
haveI := have_lebesgue_decomposition_mk μ hfi.1.measurable_mk htμ hadd',
refine (integrable.ae_eq_of_with_densityᵥ_eq (integrable_rn_deriv _ _) hfi _).symm,
rw [← add_right_inj t, ← hadd, eq_singular_part _ f htμ hadd,
singular_part_add_with_density_rn_deriv_eq],
end
lemma rn_deriv_neg (s : signed_measure α) (μ : measure α) [s.have_lebesgue_decomposition μ] :
(-s).rn_deriv μ =ᵐ[μ] - s.rn_deriv μ :=
begin
refine integrable.ae_eq_of_with_densityᵥ_eq
(integrable_rn_deriv _ _) (integrable_rn_deriv _ _).neg _,
rw [with_densityᵥ_neg, ← add_right_inj ((-s).singular_part μ),
singular_part_add_with_density_rn_deriv_eq, singular_part_neg, ← neg_add,
singular_part_add_with_density_rn_deriv_eq]
end
lemma rn_deriv_smul (s : signed_measure α) (μ : measure α) [s.have_lebesgue_decomposition μ]
(r : ℝ) :
(r • s).rn_deriv μ =ᵐ[μ] r • s.rn_deriv μ :=
begin
refine integrable.ae_eq_of_with_densityᵥ_eq
(integrable_rn_deriv _ _) ((integrable_rn_deriv _ _).smul r) _,
change _ = μ.with_densityᵥ ((r : ℝ) • s.rn_deriv μ),
rw [with_densityᵥ_smul (rn_deriv s μ) (r : ℝ),
← add_right_inj ((r • s).singular_part μ),
singular_part_add_with_density_rn_deriv_eq, singular_part_smul],
change _ = _ + r • _,
rw [← smul_add, singular_part_add_with_density_rn_deriv_eq],
end
lemma rn_deriv_add (s t : signed_measure α) (μ : measure α)
[s.have_lebesgue_decomposition μ] [t.have_lebesgue_decomposition μ]
[(s + t).have_lebesgue_decomposition μ] :
(s + t).rn_deriv μ =ᵐ[μ] s.rn_deriv μ + t.rn_deriv μ :=
begin
refine integrable.ae_eq_of_with_densityᵥ_eq
(integrable_rn_deriv _ _)
((integrable_rn_deriv _ _).add (integrable_rn_deriv _ _)) _,
rw [← add_right_inj ((s + t).singular_part μ),
singular_part_add_with_density_rn_deriv_eq,
with_densityᵥ_add (integrable_rn_deriv _ _) (integrable_rn_deriv _ _),
singular_part_add, add_assoc, add_comm (t.singular_part μ), add_assoc,
add_comm _ (t.singular_part μ), singular_part_add_with_density_rn_deriv_eq,
← add_assoc, singular_part_add_with_density_rn_deriv_eq],
end
lemma rn_deriv_sub (s t : signed_measure α) (μ : measure α)
[s.have_lebesgue_decomposition μ] [t.have_lebesgue_decomposition μ]
[hst : (s - t).have_lebesgue_decomposition μ] :
(s - t).rn_deriv μ =ᵐ[μ] s.rn_deriv μ - t.rn_deriv μ :=
begin
rw sub_eq_add_neg at hst,
rw [sub_eq_add_neg, sub_eq_add_neg],
exactI ae_eq_trans (rn_deriv_add _ _ _)
(filter.eventually_eq.add (ae_eq_refl _) (rn_deriv_neg _ _)),
end
end signed_measure
namespace complex_measure
/-- A complex measure is said to `have_lebesgue_decomposition` with respect to a positive measure
if both its real and imaginary part `have_lebesgue_decomposition` with respect to that measure. -/
class have_lebesgue_decomposition (c : complex_measure α) (μ : measure α) : Prop :=
(re_part : c.re.have_lebesgue_decomposition μ)
(im_part : c.im.have_lebesgue_decomposition μ)
attribute [instance] have_lebesgue_decomposition.re_part
attribute [instance] have_lebesgue_decomposition.im_part
/-- The singular part between a complex measure `c` and a positive measure `μ` is the complex
measure satisfying `c.singular_part μ + μ.with_densityᵥ (c.rn_deriv μ) = c`. This property is given
by `measure_theory.complex_measure.singular_part_add_with_density_rn_deriv_eq`. -/
def singular_part (c : complex_measure α) (μ : measure α) : complex_measure α :=
(c.re.singular_part μ).to_complex_measure (c.im.singular_part μ)
/-- The Radon-Nikodym derivative between a complex measure and a positive measure. -/
def rn_deriv (c : complex_measure α) (μ : measure α) : α → ℂ :=
λ x, ⟨c.re.rn_deriv μ x, c.im.rn_deriv μ x⟩
variable {c : complex_measure α}
lemma integrable_rn_deriv (c : complex_measure α) (μ : measure α) :
integrable (c.rn_deriv μ) μ :=
begin
rw [← mem_ℒp_one_iff_integrable, ← mem_ℒp_re_im_iff],
exact ⟨mem_ℒp_one_iff_integrable.2 (signed_measure.integrable_rn_deriv _ _),
mem_ℒp_one_iff_integrable.2 (signed_measure.integrable_rn_deriv _ _)⟩
end
theorem singular_part_add_with_density_rn_deriv_eq [c.have_lebesgue_decomposition μ] :
c.singular_part μ + μ.with_densityᵥ (c.rn_deriv μ) = c :=
begin
conv_rhs { rw [← c.to_complex_measure_to_signed_measure] },
ext i hi : 1,
rw [vector_measure.add_apply, signed_measure.to_complex_measure_apply],
ext,
{ rw [complex.add_re, with_densityᵥ_apply (c.integrable_rn_deriv μ) hi,
←is_R_or_C.re_eq_complex_re, ←integral_re (c.integrable_rn_deriv μ).integrable_on,
is_R_or_C.re_eq_complex_re, ← with_densityᵥ_apply _ hi],
{ change (c.re.singular_part μ + μ.with_densityᵥ (c.re.rn_deriv μ)) i = _,
rw c.re.singular_part_add_with_density_rn_deriv_eq μ },
{ exact (signed_measure.integrable_rn_deriv _ _) } },
{ rw [complex.add_im, with_densityᵥ_apply (c.integrable_rn_deriv μ) hi,
←is_R_or_C.im_eq_complex_im, ←integral_im (c.integrable_rn_deriv μ).integrable_on,
is_R_or_C.im_eq_complex_im, ← with_densityᵥ_apply _ hi],
{ change (c.im.singular_part μ + μ.with_densityᵥ (c.im.rn_deriv μ)) i = _,
rw c.im.singular_part_add_with_density_rn_deriv_eq μ },
{ exact (signed_measure.integrable_rn_deriv _ _) } },
end
end complex_measure
end measure_theory
|
288f8e34244f61b66201ce80879e00cc7d9ea244 | 843cffbd2a25fd01677509247a92e9e8b33bec48 | /equiv_rel_challenge.lean | b552936de5044a6ed2483e149b8f281f56216e12 | [] | no_license | AlexandruBosinta/MyLeanPlayground | 9a78eba4a5c7a2b82edf84e1794a966f53f06c4f | 5dc50a590d784bfc27e7fb37b6361a6dcc1b2790 | refs/heads/master | 1,586,230,010,351 | 1,542,487,422,000 | 1,542,487,422,000 | 158,016,626 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 503 | lean | definition cong_mod_n (n a b : ℤ) := ∃ k : ℤ, n * k = a - b
theorem cong_mod_n_equiv : ∀ (n : ℕ), equivalence (cong_mod_n n) := λ n,
⟨λ a, ⟨0, by rw [mul_zero, sub_eq_add_neg, add_neg_self]⟩, λ x y h, exists.elim h
(λ a cong, ⟨-a, by rw [←neg_mul_eq_mul_neg, cong, neg_sub]⟩), λ x y z hxy hyz, exists.elim hxy
(λ k congxy, exists.elim hyz (λ t congyz, ⟨k+t, by rw [mul_add, congxy, congyz,
sub_eq_add_neg y z, ←add_assoc, sub_add_cancel, sub_eq_add_neg]⟩))⟩ |
dfa62402109b50e56a8ed47288ddd5202b28d88a | d1a52c3f208fa42c41df8278c3d280f075eb020c | /tests/lean/run/isDefEqIssue.lean | 1a7c9e97269915ca0d6bb8c84f343982575c8708 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | cipher1024/lean4 | 6e1f98bb58e7a92b28f5364eb38a14c8d0aae393 | 69114d3b50806264ef35b57394391c3e738a9822 | refs/heads/master | 1,642,227,983,603 | 1,642,011,696,000 | 1,642,011,696,000 | 228,607,691 | 0 | 0 | Apache-2.0 | 1,576,584,269,000 | 1,576,584,268,000 | null | UTF-8 | Lean | false | false | 192 | lean | constant getA (s : String) : Array String := #[]
private def resolveLValAux (s : String) (i : Nat) : Nat :=
let s1 := s
let as := getA s1
if h : i < as.size then
i - 1
else
i
|
9bfa6bf7973f4621bf84b5923d99c108f29fb223 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/repeat_tac.lean | 19008f635b54a59baf2819c6e759f6419d00c95f | [
"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 | 150 | lean | example (p q r s : Prop) : p → q → r → s → (p ∧ q) ∧ (r ∧ s ∧ p) ∧ (p ∧ r ∧ q) :=
by intros; repeat { constructor }; assumption
|
a632c0c9504b244458b3b215befb93c60335c6db | 78630e908e9624a892e24ebdd21260720d29cf55 | /src/logic_propositional/prop_14.lean | 4c48f8632c2f5f30cd0e54d4356f58622e20d853 | [
"CC0-1.0"
] | permissive | tomasz-lisowski/lean-logic-examples | 84e612466776be0a16c23a0439ff8ef6114ddbe1 | 2b2ccd467b49c3989bf6c92ec0358a8d6ee68c5d | refs/heads/master | 1,683,334,199,431 | 1,621,938,305,000 | 1,621,938,305,000 | 365,041,573 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 358 | lean | namespace prop_14
variables A B C : Prop
theorem prop_14 : ((A → C) ∨ (B → C)) → ((A ∧ B) → C) :=
assume h1: ((A → C) ∨ (B → C)),
assume h2: A ∧ B,
have h3: A, from and.left h2,
have h4: B, from and.right h2,
show C, from or.elim h1
(assume h5: A → C,
h5 h3)
(assume h6: B → C,
h6 h4)
-- end namespace
end prop_14 |
115cce1594a69cb49f6830789d3ec81c1017d977 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/vmo1.lean | 256f8e4dfc4999513bfd0e39f3a5b859e10f863d | [
"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 | 136 | lean | meta def cheese : string := "edam"
meta def fromage : string := "comte"
#eval cheese
attribute [vm_override fromage] cheese
#eval cheese |
164e3937fc8a1e0b45076792c7e1c2460f53962a | 4efff1f47634ff19e2f786deadd394270a59ecd2 | /src/analysis/normed_space/finite_dimension.lean | 5904e6ee3c44fc505a20bffe8487fe10f86d22d5 | [
"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 | 12,222 | lean | /-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import analysis.normed_space.operator_norm
import linear_algebra.finite_dimensional
import tactic.omega
/-!
# Finite dimensional normed spaces over complete fields
Over a complete nondiscrete field, in finite dimension, all norms are equivalent and all linear maps
are continuous. Moreover, a finite-dimensional subspace is always complete and closed.
## Main results:
* `linear_map.continuous_of_finite_dimensional` : a linear map on a finite-dimensional space over a
complete field is continuous.
* `finite_dimensional.complete` : a finite-dimensional space over a complete field is complete. This
is not registered as an instance, as the field would be an unknown metavariable in typeclass
resolution.
* `submodule.closed_of_finite_dimensional` : a finite-dimensional subspace over a complete field is
closed
* `finite_dimensional.proper` : a finite-dimensional space over a proper field is proper. This
is not registered as an instance, as the field would be an unknown metavariable in typeclass
resolution. It is however registered as an instance for `𝕜 = ℝ` and `𝕜 = ℂ`. As properness
implies completeness, there is no need to also register `finite_dimensional.complete` on `ℝ` or
`ℂ`.
## Implementation notes
The fact that all norms are equivalent is not written explicitly, as it would mean having two norms
on a single space, which is not the way type classes work. However, if one has a
finite-dimensional vector space `E` with a norm, and a copy `E'` of this type with another norm,
then the identities from `E` to `E'` and from `E'`to `E` are continuous thanks to
`linear_map.continuous_of_finite_dimensional`. This gives the desired norm equivalence.
-/
universes u v w x
open set finite_dimensional
open_locale classical big_operators
/-- A linear map on `ι → 𝕜` (where `ι` is a fintype) is continuous -/
lemma linear_map.continuous_on_pi {ι : Type w} [fintype ι] {𝕜 : Type u} [normed_field 𝕜]
{E : Type v} [add_comm_group E] [vector_space 𝕜 E] [topological_space E]
[topological_add_group E] [topological_vector_space 𝕜 E] (f : (ι → 𝕜) →ₗ[𝕜] E) : continuous f :=
begin
-- for the proof, write `f` in the standard basis, and use that each coordinate is a continuous
-- function.
have : (f : (ι → 𝕜) → E) =
(λx, ∑ i : ι, x i • (f (λj, if i = j then 1 else 0))),
by { ext x, exact f.pi_apply_eq_sum_univ x },
rw this,
refine continuous_finset_sum _ (λi hi, _),
exact (continuous_apply i).smul continuous_const
end
section complete_field
variables {𝕜 : Type u} [nondiscrete_normed_field 𝕜]
{E : Type v} [normed_group E] [normed_space 𝕜 E]
{F : Type w} [normed_group F] [normed_space 𝕜 F]
{F' : Type x} [add_comm_group F'] [vector_space 𝕜 F'] [topological_space F']
[topological_add_group F'] [topological_vector_space 𝕜 F']
[complete_space 𝕜]
/-- In finite dimension over a complete field, the canonical identification (in terms of a basis)
with `𝕜^n` together with its sup norm is continuous. This is the nontrivial part in the fact that
all norms are equivalent in finite dimension.
This statement is superceded by the fact that every linear map on a finite-dimensional space is
continuous, in `linear_map.continuous_of_finite_dimensional`. -/
lemma continuous_equiv_fun_basis {ι : Type v} [fintype ι] (ξ : ι → E) (hξ : is_basis 𝕜 ξ) :
continuous hξ.equiv_fun :=
begin
unfreezingI { induction hn : fintype.card ι with n IH generalizing ι E },
{ apply linear_map.continuous_of_bound _ 0 (λx, _),
have : hξ.equiv_fun x = 0,
by { ext i, exact (fintype.card_eq_zero_iff.1 hn i).elim },
change ∥hξ.equiv_fun x∥ ≤ 0 * ∥x∥,
rw this,
simp [norm_nonneg] },
{ haveI : finite_dimensional 𝕜 E := of_finite_basis hξ,
-- first step: thanks to the inductive assumption, any n-dimensional subspace is equivalent
-- to a standard space of dimension n, hence it is complete and therefore closed.
have H₁ : ∀s : submodule 𝕜 E, findim 𝕜 s = n → is_closed (s : set E),
{ assume s s_dim,
rcases exists_is_basis_finite 𝕜 s with ⟨b, b_basis, b_finite⟩,
letI : fintype b := finite.fintype b_finite,
have U : uniform_embedding b_basis.equiv_fun.symm.to_equiv,
{ have : fintype.card b = n,
by { rw ← s_dim, exact (findim_eq_card_basis b_basis).symm },
have : continuous b_basis.equiv_fun := IH (subtype.val : b → s) b_basis this,
exact b_basis.equiv_fun.symm.uniform_embedding (linear_map.continuous_on_pi _) this },
have : is_complete (s : set E),
from complete_space_coe_iff_is_complete.1 ((complete_space_congr U).1 (by apply_instance)),
exact this.is_closed },
-- second step: any linear form is continuous, as its kernel is closed by the first step
have H₂ : ∀f : E →ₗ[𝕜] 𝕜, continuous f,
{ assume f,
have : findim 𝕜 f.ker = n ∨ findim 𝕜 f.ker = n.succ,
{ have Z := f.findim_range_add_findim_ker,
rw [findim_eq_card_basis hξ, hn] at Z,
have : findim 𝕜 f.range = 0 ∨ findim 𝕜 f.range = 1,
{ have I : ∀(k : ℕ), k ≤ 1 ↔ k = 0 ∨ k = 1, by omega manual,
have : findim 𝕜 f.range ≤ findim 𝕜 𝕜 := submodule.findim_le _,
rwa [findim_of_field, I] at this },
cases this,
{ rw this at Z,
right,
simpa using Z },
{ left,
rw [this, add_comm, nat.add_one] at Z,
exact nat.succ.inj Z } },
have : is_closed (f.ker : set E),
{ cases this,
{ exact H₁ _ this },
{ have : f.ker = ⊤,
by { apply eq_top_of_findim_eq, rw [findim_eq_card_basis hξ, hn, this] },
simp [this] } },
exact linear_map.continuous_iff_is_closed_ker.2 this },
-- third step: applying the continuity to the linear form corresponding to a coefficient in the
-- basis decomposition, deduce that all such coefficients are controlled in terms of the norm
have : ∀i:ι, ∃C, 0 ≤ C ∧ ∀(x:E), ∥hξ.equiv_fun x i∥ ≤ C * ∥x∥,
{ assume i,
let f : E →ₗ[𝕜] 𝕜 := (linear_map.proj i).comp hξ.equiv_fun,
let f' : E →L[𝕜] 𝕜 := { cont := H₂ f, ..f },
exact ⟨∥f'∥, norm_nonneg _, λx, continuous_linear_map.le_op_norm f' x⟩ },
-- fourth step: combine the bound on each coefficient to get a global bound and the continuity
choose C0 hC0 using this,
let C := ∑ i, C0 i,
have C_nonneg : 0 ≤ C := finset.sum_nonneg (λi hi, (hC0 i).1),
have C0_le : ∀i, C0 i ≤ C :=
λi, finset.single_le_sum (λj hj, (hC0 j).1) (finset.mem_univ _),
apply linear_map.continuous_of_bound _ C (λx, _),
rw pi_norm_le_iff,
{ exact λi, le_trans ((hC0 i).2 x) (mul_le_mul_of_nonneg_right (C0_le i) (norm_nonneg _)) },
{ exact mul_nonneg C_nonneg (norm_nonneg _) } }
end
/-- Any linear map on a finite dimensional space over a complete field is continuous. -/
theorem linear_map.continuous_of_finite_dimensional [finite_dimensional 𝕜 E] (f : E →ₗ[𝕜] F') :
continuous f :=
begin
-- for the proof, go to a model vector space `b → 𝕜` thanks to `continuous_equiv_fun_basis`, and
-- argue that all linear maps there are continuous.
rcases exists_is_basis_finite 𝕜 E with ⟨b, b_basis, b_finite⟩,
letI : fintype b := finite.fintype b_finite,
have A : continuous b_basis.equiv_fun :=
continuous_equiv_fun_basis _ b_basis,
have B : continuous (f.comp (b_basis.equiv_fun.symm : (b → 𝕜) →ₗ[𝕜] E)) :=
linear_map.continuous_on_pi _,
have : continuous ((f.comp (b_basis.equiv_fun.symm : (b → 𝕜) →ₗ[𝕜] E))
∘ b_basis.equiv_fun) := B.comp A,
convert this,
ext x,
dsimp,
rw linear_equiv.symm_apply_apply
end
/-- The continuous linear map induced by a linear map on a finite dimensional space -/
def linear_map.to_continuous_linear_map [finite_dimensional 𝕜 E] (f : E →ₗ[𝕜] F') : E →L[𝕜] F' :=
{ cont := f.continuous_of_finite_dimensional, ..f }
/-- The continuous linear equivalence induced by a linear equivalence on a finite dimensional space. -/
def linear_equiv.to_continuous_linear_equiv [finite_dimensional 𝕜 E] (e : E ≃ₗ[𝕜] F) : E ≃L[𝕜] F :=
{ continuous_to_fun := e.to_linear_map.continuous_of_finite_dimensional,
continuous_inv_fun := begin
haveI : finite_dimensional 𝕜 F := e.finite_dimensional,
exact e.symm.to_linear_map.continuous_of_finite_dimensional
end,
..e }
/-- Any finite-dimensional vector space over a complete field is complete.
We do not register this as an instance to avoid an instance loop when trying to prove the
completeness of `𝕜`, and the search for `𝕜` as an unknown metavariable. Declare the instance
explicitly when needed. -/
variables (𝕜 E)
lemma finite_dimensional.complete [finite_dimensional 𝕜 E] : complete_space E :=
begin
rcases exists_is_basis_finite 𝕜 E with ⟨b, b_basis, b_finite⟩,
letI : fintype b := finite.fintype b_finite,
have : uniform_embedding b_basis.equiv_fun.symm :=
linear_equiv.uniform_embedding _ (linear_map.continuous_of_finite_dimensional _)
(linear_map.continuous_of_finite_dimensional _),
change uniform_embedding b_basis.equiv_fun.symm.to_equiv at this,
exact (complete_space_congr this).1 (by apply_instance)
end
variables {𝕜 E}
/-- A finite-dimensional subspace is complete. -/
lemma submodule.complete_of_finite_dimensional (s : submodule 𝕜 E) [finite_dimensional 𝕜 s] :
is_complete (s : set E) :=
complete_space_coe_iff_is_complete.1 (finite_dimensional.complete 𝕜 s)
/-- A finite-dimensional subspace is closed. -/
lemma submodule.closed_of_finite_dimensional (s : submodule 𝕜 E) [finite_dimensional 𝕜 s] :
is_closed (s : set E) :=
s.complete_of_finite_dimensional.is_closed
lemma continuous_linear_map.exists_right_inverse_of_surjective [finite_dimensional 𝕜 F]
(f : E →L[𝕜] F) (hf : f.range = ⊤) :
∃ g : F →L[𝕜] E, f.comp g = continuous_linear_map.id 𝕜 F :=
let ⟨g, hg⟩ := (f : E →ₗ[𝕜] F).exists_right_inverse_of_surjective hf in
⟨g.to_continuous_linear_map, continuous_linear_map.ext $ linear_map.ext_iff.1 hg⟩
end complete_field
section proper_field
variables (𝕜 : Type u) [nondiscrete_normed_field 𝕜]
(E : Type v) [normed_group E] [normed_space 𝕜 E] [proper_space 𝕜]
/-- Any finite-dimensional vector space over a proper field is proper.
We do not register this as an instance to avoid an instance loop when trying to prove the
properness of `𝕜`, and the search for `𝕜` as an unknown metavariable. Declare the instance
explicitly when needed. -/
lemma finite_dimensional.proper [finite_dimensional 𝕜 E] : proper_space E :=
begin
rcases exists_is_basis_finite 𝕜 E with ⟨b, b_basis, b_finite⟩,
letI : fintype b := finite.fintype b_finite,
let e := b_basis.equiv_fun,
let f : E →L[𝕜] (b → 𝕜) :=
{ cont := linear_map.continuous_of_finite_dimensional _, ..e.to_linear_map },
refine metric.proper_image_of_proper e.symm
(linear_map.continuous_of_finite_dimensional _) _ (∥f∥) (λx y, _),
{ exact equiv.range_eq_univ e.symm.to_equiv },
{ have A : e (e.symm x) = x := linear_equiv.apply_symm_apply _ _,
have B : e (e.symm y) = y := linear_equiv.apply_symm_apply _ _,
conv_lhs { rw [← A, ← B] },
change dist (f (e.symm x)) (f (e.symm y)) ≤ ∥f∥ * dist (e.symm x) (e.symm y),
unfreezingI { exact f.lipschitz.dist_le_mul _ _ } }
end
end proper_field
/- Over the real numbers, we can register the previous statement as an instance as it will not
cause problems in instance resolution since the properness of `ℝ` is already known. -/
instance finite_dimensional.proper_real
(E : Type u) [normed_group E] [normed_space ℝ E] [finite_dimensional ℝ E] : proper_space E :=
finite_dimensional.proper ℝ E
attribute [instance, priority 900] finite_dimensional.proper_real
|
d945ca9a3c89eec865748eb597901f2c8a3e726d | 86f6f4f8d827a196a32bfc646234b73328aeb306 | /examples/logic/unnamed_1211.lean | 67521edac490e59fbfc8b44ecf859be1744a8be4 | [] | no_license | jamescheuk91/mathematics_in_lean | 09f1f87d2b0dce53464ff0cbe592c568ff59cf5e | 4452499264e2975bca2f42565c0925506ba5dda3 | refs/heads/master | 1,679,716,410,967 | 1,613,957,947,000 | 1,613,957,947,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 103 | lean | import data.real.basic
-- BEGIN
example (x : ℝ) (h : ∀ ε > 0, x ≤ ε) : x ≤ 0 :=
sorry
-- END |
04511e4d1a33e840b9fec334c7f36d76af377021 | caa1512363b76923d0e9cdb716122a5c26c3c6bc | /src/eigenvectors/linear_combination.lean | 24e0116d42aa7a19b28b20fb8e4ba7a13b2e6b77 | [] | no_license | apurvanakade/cvx | deb20e425ce478159a98e1ffc0d37f9c88a89280 | b47784831339df5a3e45f5cddd84edc545f95808 | refs/heads/master | 1,687,403,288,536 | 1,555,930,740,000 | 1,555,930,740,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 11,112 | lean | /-
Linear combinations with duplicates
-/
import linear_algebra.basic
noncomputable theory
open classical function lattice
local attribute [instance] prop_decidable
/-- linear combinations over an indexed family -/
@[reducible] def lc (ι : Type*) (α : Type*) (β : Type*) [has_zero α] (v : ι → β) := ι →₀ α
namespace lc
variables {ι : Type*} {ι' : Type*} {ι'' : Type*} {α : Type*}
{β : Type*} {β' : Type*} {β'' : Type*} {γ : Type*}
{v : ι → β} {v' : ι' → β'} {v'' : ι'' → β''}
variables [ring α] [add_comm_group β] [add_comm_group β'] [add_comm_group β''] [add_comm_group γ]
variables [module α β] [module α β'] [module α β''] [module α γ]
open submodule linear_map
def vsupport (l : lc ι α β v) : multiset β := l.support.val.map v
instance : add_comm_group (lc ι α β v) := finsupp.add_comm_group
instance : has_scalar α (lc ι α β v) := finsupp.to_has_scalar
instance : module α (lc ι α β v) := finsupp.to_module ι α
variables (α) (β) (v)
def supported (s : set ι) : submodule α (lc ι α β v) :=
{ carrier := {l | ↑l.support ⊆ s},
zero := by simp,
add := λ l₁ l₂ h₁ h₂, set.subset.trans (finset.coe_subset.2 finsupp.support_add)
(by simpa using set.union_subset h₁ h₂),
smul := λ a l h, set.subset.trans (finset.coe_subset.2 finsupp.support_smul)
(by simpa using h) }
variables {α} {β} {v}
theorem mem_supported {s : set ι} {l : lc ι α β v} :
l ∈ supported α β v s ↔ ↑l.support ⊆ s := iff.rfl
theorem mem_supported' {s : set ι} {l : lc ι α β v} :
l ∈ supported α β v s ↔ ∀ x ∉ s, l x = 0 :=
by simp [mem_supported, set.subset_def, not_imp_comm]
variables (β) (v)
theorem single_mem_supported {s : set ι} (a : α) {b : ι} (h : b ∈ s) :
finsupp.single b a ∈ supported α β v s :=
set.subset.trans finsupp.support_single_subset (set.singleton_subset_iff.2 h)
variables {β} {v}
theorem supported_eq_span_single (s : set ι) :
lc.supported α β v s = span α ((λ i, finsupp.single i (1 : α)) '' s) :=
begin
refine (span_eq_of_le _ _ (le_def'.2 $ λ l hl, _)).symm,
{ rintro _ ⟨l, hl, rfl⟩, exact single_mem_supported β v (1:α) hl },
{ rw ← l.sum_single,
refine sum_mem _ (λ i il, _),
convert @smul_mem α (lc ι α β v) _ _ _ _ (finsupp.single i (1 : α)) (l i) _,
{ simp },
apply subset_span,
apply set.mem_image_of_mem _ (hl il) }
end
variables (α) (β) (v)
def restrict_dom (s : set ι) : lc ι α β v →ₗ supported α β v s :=
linear_map.cod_restrict _
{ to_fun := finsupp.filter (∈ s),
add := λ l₁ l₂, finsupp.filter_add,
smul := λ a l, finsupp.filter_smul }
(λ l, mem_supported'.2 $ λ x, finsupp.filter_apply_neg (∈ s) l)
variables {α} {β} {v}
@[simp] theorem restrict_dom_apply (s : set ι) (l : lc ι α β v) :
↑((restrict_dom α β v s : lc ι α β v →ₗ supported α β v s) l) = finsupp.filter (∈ s) l := rfl
theorem restrict_dom_comp_subtype (s : set ι) :
(restrict_dom α β v s).comp (submodule.subtype _) = linear_map.id :=
by ext l; apply subtype.coe_ext.2; simp; ext a;
by_cases a ∈ s; simp [h]; exact (mem_supported'.1 l.2 _ h).symm
theorem range_restrict_dom (s : set ι) : (restrict_dom α β v s).range = ⊤ :=
begin
have := linear_map.range_comp (submodule.subtype _) (restrict_dom α β v s),
rw [restrict_dom_comp_subtype, linear_map.range_id] at this,
exact eq_top_mono (submodule.map_mono le_top) this.symm
end
theorem supported_mono {s t : set ι} (st : s ⊆ t) :
supported α β v s ≤ supported α β v t :=
λ l h, set.subset.trans h st
@[simp] theorem supported_empty : supported α β v (∅ : set ι) = ⊥ :=
eq_bot_iff.2 $ λ l h, (submodule.mem_bot α).2 $
by ext; simp [*, mem_supported'] at *
@[simp] theorem supported_univ : supported α β v (set.univ : set ι) = ⊤ :=
eq_top_iff.2 $ λ l _, set.subset_univ _
theorem supported_Union {δ : Type*} (s : δ → set ι) :
supported α β v (⋃ i, s i) = ⨆ i, supported α β v (s i) :=
begin
refine le_antisymm _ (supr_le $ λ i, supported_mono $ set.subset_Union _ _),
suffices : ((submodule.subtype _).comp (restrict_dom α β v (⋃ i, s i))).range ≤ ⨆ i, supported α β v (s i),
{ rwa [range_comp, range_restrict_dom, map_top, range_subtype] at this },
rw [range_le_iff_comap, eq_top_iff],
rintro l ⟨⟩, rw mem_coe,
apply finsupp.induction l, {exact zero_mem _},
refine λ x a l hl a0, add_mem _ _,
by_cases (∃ i, x ∈ s i); simp [h],
cases h with i hi,
exact le_supr (λ i, supported α β v (s i)) i (single_mem_supported β v _ hi)
end
theorem supported_union (s t : set ι) :
supported α β v (s ∪ t) = supported α β v s ⊔ supported α β v t :=
by erw [set.union_eq_Union, supported_Union, supr_bool_eq]; refl
theorem supported_Inter {δ : Type*} (s : δ → set ι) :
supported α β v (⋂ i, s i) = ⨅ i, supported α β v (s i) :=
begin
refine le_antisymm (le_infi $ λ i, supported_mono $ set.Inter_subset _ _) _,
simp [le_def, infi_coe, set.subset_def],
exact λ l, set.subset_Inter
end
def apply (i : ι) : lc ι α β v →ₗ α :=
⟨λ l, l i, λ _ _, finsupp.add_apply, λ _ _, finsupp.smul_apply⟩
@[simp] theorem apply_apply (i : ι) (l : lc ι α β v) :
(lc.apply i : lc ι α β v →ₗ α) l = l i := rfl
protected def lsum (f : ι → α →ₗ[α] γ) : lc ι α β v →ₗ[α] γ :=
⟨λ d, d.sum (λ i, f i),
assume d₁ d₂, by simp [finsupp.sum_add_index],
assume a d, by simp [finsupp.sum_smul_index, finsupp.smul_sum,
-smul_eq_mul, smul_eq_mul.symm]⟩
@[simp] theorem lsum_apply (f : ι → α →ₗ γ) (l : lc ι α β v) :
(lc.lsum f : lc ι α β v →ₗ γ) l = l.sum (λ b, f b) := rfl
section
variables (ι α β v)
protected def total : lc ι α β v →ₗ β := lc.lsum (λ i, linear_map.id.smul_right (v i))
end
theorem total_apply (l : lc ι α β v) :
lc.total ι α β v l = l.sum (λ i a, a • v i) := rfl
@[simp] theorem total_single (a : α) (i : ι) :
lc.total ι α β v (finsupp.single i a) = a • (v i) :=
by simp [total_apply, finsupp.sum_single_index]
theorem total_range (h : surjective v) : (lc.total ι α β v).range = ⊤ :=
begin
apply range_eq_top.2,
intros x,
apply exists.elim (h x),
exact λ i hi, ⟨finsupp.single i 1, by simp [hi]⟩
end
variables (α) (v) (v')
protected def map (f : ι → ι') : lc ι α β v →ₗ[α] lc ι' α β' v' :=
{ to_fun := finsupp.map_domain f,
add := λ l₁ l₂, finsupp.map_domain_add,
smul := λ a l, finsupp.map_domain_smul _ _ }
variables {α} {v} {v'}
@[simp] theorem map_apply (f : ι → ι') (l : lc ι α β v) :
(lc.map α v v' f : _ →ₗ _) l = finsupp.map_domain f l := rfl
@[simp] theorem map_id : (lc.map α v v id : lc ι α β v →ₗ[α] lc ι α β v) = linear_map.id :=
linear_map.ext $ λ l, finsupp.map_domain_id
theorem map_comp (f : ι → ι') (g : ι' → ι'') :
lc.map α v v'' (g ∘ f) = (lc.map α v' v'' g).comp (lc.map α v v' f) :=
linear_map.ext $ λ l, finsupp.map_domain_comp
theorem supported_comap_map (f : ι → ι') (s : set ι') :
supported α β v (f ⁻¹' s) ≤ (supported α β' v' s).comap (lc.map α v v' f) :=
λ l (hl : ↑l.support ⊆ f ⁻¹' s),
show ↑(finsupp.map_domain f l).support ⊆ s, begin
rw [← set.image_subset_iff, ← finset.coe_image] at hl,
exact set.subset.trans finsupp.map_domain_support hl
end
theorem map_supported [inhabited ι] (f : ι → ι') (s : set ι) :
(supported α β v s).map (lc.map α v v' f) = supported α β' v' (f '' s) :=
begin
refine le_antisymm (map_le_iff_le_comap.2 $
le_trans (supported_mono $ set.subset_preimage_image _ _)
(supported_comap_map _ _)) _,
intros l hl, haveI : inhabited β := ⟨0⟩,
refine ⟨(lc.map α v' v (inv_fun_on f s) : lc ι' α β' v' →ₗ lc ι α β v) l, λ x hx, _, _⟩,
{ rcases finset.mem_image.1 (finsupp.map_domain_support hx) with ⟨c, hc, rfl⟩,
exact inv_fun_on_mem (by simpa using hl hc) },
{ rw [← linear_map.comp_apply, ← map_comp],
refine (finsupp.map_domain_congr $ λ c hc, _).trans finsupp.map_domain_id,
exact inv_fun_on_eq (by simpa using hl hc) }
end
theorem map_disjoint_ker (f : ι → ι') {s : set ι}
(H : ∀ a b ∈ s, f a = f b → a = b) :
disjoint (supported α β v s) (lc.map α v v' f).ker :=
begin
rintro l ⟨h₁, h₂⟩,
rw [mem_coe, mem_ker, map_apply, finsupp.map_domain] at h₂,
simp, ext x,
by_cases xs : x ∈ s,
{ have : finsupp.sum l (λ a, finsupp.single (f a)) (f x) = 0, {rw h₂, refl},
rw [finsupp.sum_apply, finsupp.sum, finset.sum_eq_single x] at this,
{ simpa [finsupp.single_apply] },
{ intros y hy xy, simp [mt (H _ _ (h₁ hy) xs) xy] },
{ simp {contextual := tt} } },
{ by_contra h, exact xs (h₁ $ finsupp.mem_support_iff.2 h) }
end
theorem map_total (f : ι → ι') (g : β →ₗ[α] β') (h : ∀ i, g (v i) = v' (f i)):
(lc.total ι' α β' v').comp (lc.map α v v' f) = g.comp (lc.total ι α β v) :=
by ext l; simp [total_apply, finsupp.sum_map_domain_index, add_smul, h]
end lc
namespace lc
variables {ι : Type*} {α : Type*} {β : Type*} {v : ι → β}
[discrete_field α] [add_comm_group β] [vector_space α β]
instance : vector_space α (lc ι α β v) := { .. lc.module }
end lc
section module
variables {ι : Type*} {α : Type*} {β : Type*} {γ : Type*} {v : ι → β}
[ring α] [add_comm_group β] [add_comm_group γ]
variables [module α β] [module α γ]
variables {a b : α} {s t : set ι} {x y : β}
include α
open submodule
theorem span_eq_map_lc : span α (v '' s) = (lc.supported α β v s).map (lc.total ι α β v) :=
begin
apply span_eq_of_le,
{ intros x hx,
rw set.mem_image at hx,
apply exists.elim hx,
intros i hi,
exact ⟨_, lc.single_mem_supported β v 1 hi.1, by simp [hi.2]⟩ },
{ refine map_le_iff_le_comap.2 (λ z hz, _),
have : ∀i, z i • v i ∈ span α (v '' s),
{ intro c, by_cases c ∈ s,
{ exact smul_mem _ _ (subset_span (set.mem_image_of_mem _ h)) },
{ simp [lc.mem_supported'.1 hz _ h] } },
refine sum_mem _ _, simp [this] }
end
theorem mem_span_iff_lc :
x ∈ span α (v '' s) ↔ ∃ l ∈ lc.supported α β v s, lc.total ι α β v l = x :=
by rw span_eq_map_lc; simp
variables (α) (β) (v)
def lc.total_on (s : set ι) : lc.supported α β v s →ₗ span α (v '' s) :=
linear_map.cod_restrict _ ((lc.total ι α _ v).comp (submodule.subtype _)) $
λ ⟨l, hl⟩, mem_span_iff_lc.2 ⟨l, hl, rfl⟩
variables {α} {β} {v}
theorem lc.total_on_range (s : set ι) : (lc.total_on α β v s).range = ⊤ :=
by rw [lc.total_on, linear_map.range, linear_map.map_cod_restrict, ← linear_map.range_le_iff_comap,
range_subtype, map_top, linear_map.range_comp, range_subtype]; exact le_of_eq span_eq_map_lc
lemma linear_eq_on (s : set β) {f g : β →ₗ[α] γ} (H : ∀x∈s, f x = g x) {x} (h : x ∈ span α s) : f x = g x :=
by apply span_induction h H; simp {contextual := tt}
end module
|
00a18c75d48b743729983577c92fcc407d67ce21 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/multiConstantError.lean | 42aeda8a0d9f316d5339edc8c574450bbea74be4 | [
"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 | 49 | lean | opaque a b c : Nat
opaque a α β : β → Bool
|
23005d7a41a377b6f7e7a5aab8624f41870e4163 | 626e312b5c1cb2d88fca108f5933076012633192 | /src/topology/instances/ennreal.lean | bdab0192891ea10f6b8bd3a6c18f532751077788 | [
"Apache-2.0"
] | permissive | Bioye97/mathlib | 9db2f9ee54418d29dd06996279ba9dc874fd6beb | 782a20a27ee83b523f801ff34efb1a9557085019 | refs/heads/master | 1,690,305,956,488 | 1,631,067,774,000 | 1,631,067,774,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 54,925 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import topology.instances.nnreal
import topology.algebra.ordered.liminf_limsup
/-!
# Extended non-negative reals
-/
noncomputable theory
open classical set filter metric
open_locale classical topological_space ennreal nnreal big_operators filter
variables {α : Type*} {β : Type*} {γ : Type*}
namespace ennreal
variables {a b c d : ℝ≥0∞} {r p q : ℝ≥0}
variables {x y z : ℝ≥0∞} {ε ε₁ ε₂ : ℝ≥0∞} {s : set ℝ≥0∞}
section topological_space
open topological_space
/-- Topology on `ℝ≥0∞`.
Note: this is different from the `emetric_space` topology. The `emetric_space` topology has
`is_open {⊤}`, while this topology doesn't have singleton elements. -/
instance : topological_space ℝ≥0∞ := preorder.topology ℝ≥0∞
instance : order_topology ℝ≥0∞ := ⟨rfl⟩
instance : t2_space ℝ≥0∞ := by apply_instance -- short-circuit type class inference
instance : second_countable_topology ℝ≥0∞ :=
⟨⟨⋃q ≥ (0:ℚ), {{a : ℝ≥0∞ | a < real.to_nnreal q}, {a : ℝ≥0∞ | ↑(real.to_nnreal q) < a}},
(countable_encodable _).bUnion $ assume a ha, (countable_singleton _).insert _,
le_antisymm
(le_generate_from $ by simp [or_imp_distrib, is_open_lt', is_open_gt'] {contextual := tt})
(le_generate_from $ λ s h, begin
rcases h with ⟨a, hs | hs⟩;
[ rw show s = ⋃q∈{q:ℚ | 0 ≤ q ∧ a < real.to_nnreal q}, {b | ↑(real.to_nnreal q) < b},
from set.ext (assume b, by simp [hs, @ennreal.lt_iff_exists_rat_btwn a b, and_assoc]),
rw show s = ⋃q∈{q:ℚ | 0 ≤ q ∧ ↑(real.to_nnreal q) < a}, {b | b < ↑(real.to_nnreal q)},
from set.ext (assume b,
by simp [hs, @ennreal.lt_iff_exists_rat_btwn b a, and_comm, and_assoc])];
{ apply is_open_Union, intro q,
apply is_open_Union, intro hq,
exact generate_open.basic _ (mem_bUnion hq.1 $ by simp) }
end)⟩⟩
lemma embedding_coe : embedding (coe : ℝ≥0 → ℝ≥0∞) :=
⟨⟨begin
refine le_antisymm _ _,
{ rw [@order_topology.topology_eq_generate_intervals ℝ≥0∞ _,
← coinduced_le_iff_le_induced],
refine le_generate_from (assume s ha, _),
rcases ha with ⟨a, rfl | rfl⟩,
show is_open {b : ℝ≥0 | a < ↑b},
{ cases a; simp [none_eq_top, some_eq_coe, is_open_lt'] },
show is_open {b : ℝ≥0 | ↑b < a},
{ cases a; simp [none_eq_top, some_eq_coe, is_open_gt', is_open_const] } },
{ rw [@order_topology.topology_eq_generate_intervals ℝ≥0 _],
refine le_generate_from (assume s ha, _),
rcases ha with ⟨a, rfl | rfl⟩,
exact ⟨Ioi a, is_open_Ioi, by simp [Ioi]⟩,
exact ⟨Iio a, is_open_Iio, by simp [Iio]⟩ }
end⟩,
assume a b, coe_eq_coe.1⟩
lemma is_open_ne_top : is_open {a : ℝ≥0∞ | a ≠ ⊤} := is_open_ne
lemma is_open_Ico_zero : is_open (Ico 0 b) := by { rw ennreal.Ico_eq_Iio, exact is_open_Iio}
lemma open_embedding_coe : open_embedding (coe : ℝ≥0 → ℝ≥0∞) :=
⟨embedding_coe, by { convert is_open_ne_top, ext (x|_); simp [none_eq_top, some_eq_coe] }⟩
lemma coe_range_mem_nhds : range (coe : ℝ≥0 → ℝ≥0∞) ∈ 𝓝 (r : ℝ≥0∞) :=
is_open.mem_nhds open_embedding_coe.open_range $ mem_range_self _
@[norm_cast] lemma tendsto_coe {f : filter α} {m : α → ℝ≥0} {a : ℝ≥0} :
tendsto (λa, (m a : ℝ≥0∞)) f (𝓝 ↑a) ↔ tendsto m f (𝓝 a) :=
embedding_coe.tendsto_nhds_iff.symm
lemma continuous_coe : continuous (coe : ℝ≥0 → ℝ≥0∞) :=
embedding_coe.continuous
lemma continuous_coe_iff {α} [topological_space α] {f : α → ℝ≥0} :
continuous (λa, (f a : ℝ≥0∞)) ↔ continuous f :=
embedding_coe.continuous_iff.symm
lemma nhds_coe {r : ℝ≥0} : 𝓝 (r : ℝ≥0∞) = (𝓝 r).map coe :=
(open_embedding_coe.map_nhds_eq r).symm
lemma tendsto_nhds_coe_iff {α : Type*} {l : filter α} {x : ℝ≥0} {f : ℝ≥0∞ → α} :
tendsto f (𝓝 ↑x) l ↔ tendsto (f ∘ coe : ℝ≥0 → α) (𝓝 x) l :=
show _ ≤ _ ↔ _ ≤ _, by rw [nhds_coe, filter.map_map]
lemma continuous_at_coe_iff {α : Type*} [topological_space α] {x : ℝ≥0} {f : ℝ≥0∞ → α} :
continuous_at f (↑x) ↔ continuous_at (f ∘ coe : ℝ≥0 → α) x :=
tendsto_nhds_coe_iff
lemma nhds_coe_coe {r p : ℝ≥0} :
𝓝 ((r : ℝ≥0∞), (p : ℝ≥0∞)) = (𝓝 (r, p)).map (λp:ℝ≥0×ℝ≥0, (p.1, p.2)) :=
((open_embedding_coe.prod open_embedding_coe).map_nhds_eq (r, p)).symm
lemma continuous_of_real : continuous ennreal.of_real :=
(continuous_coe_iff.2 continuous_id).comp nnreal.continuous_of_real
lemma tendsto_of_real {f : filter α} {m : α → ℝ} {a : ℝ} (h : tendsto m f (𝓝 a)) :
tendsto (λa, ennreal.of_real (m a)) f (𝓝 (ennreal.of_real a)) :=
tendsto.comp (continuous.tendsto continuous_of_real _) h
lemma tendsto_to_nnreal {a : ℝ≥0∞} (ha : a ≠ ⊤) :
tendsto ennreal.to_nnreal (𝓝 a) (𝓝 a.to_nnreal) :=
begin
lift a to ℝ≥0 using ha,
rw [nhds_coe, tendsto_map'_iff],
exact tendsto_id
end
lemma continuous_on_to_nnreal : continuous_on ennreal.to_nnreal {a | a ≠ ∞} :=
λ a ha, continuous_at.continuous_within_at (tendsto_to_nnreal ha)
lemma tendsto_to_real {a : ℝ≥0∞} (ha : a ≠ ⊤) : tendsto ennreal.to_real (𝓝 a) (𝓝 a.to_real) :=
nnreal.tendsto_coe.2 $ tendsto_to_nnreal ha
/-- The set of finite `ℝ≥0∞` numbers is homeomorphic to `ℝ≥0`. -/
def ne_top_homeomorph_nnreal : {a | a ≠ ∞} ≃ₜ ℝ≥0 :=
{ continuous_to_fun := continuous_on_iff_continuous_restrict.1 continuous_on_to_nnreal,
continuous_inv_fun := continuous_subtype_mk _ continuous_coe,
.. ne_top_equiv_nnreal }
/-- The set of finite `ℝ≥0∞` numbers is homeomorphic to `ℝ≥0`. -/
def lt_top_homeomorph_nnreal : {a | a < ∞} ≃ₜ ℝ≥0 :=
by refine (homeomorph.set_congr $ set.ext $ λ x, _).trans ne_top_homeomorph_nnreal;
simp only [mem_set_of_eq, lt_top_iff_ne_top]
lemma nhds_top : 𝓝 ∞ = ⨅ a ≠ ∞, 𝓟 (Ioi a) :=
nhds_top_order.trans $ by simp [lt_top_iff_ne_top, Ioi]
lemma nhds_top' : 𝓝 ∞ = ⨅ r : ℝ≥0, 𝓟 (Ioi r) :=
nhds_top.trans $ infi_ne_top _
lemma nhds_top_basis : (𝓝 ∞).has_basis (λ a, a < ∞) (λ a, Ioi a) := nhds_top_basis
lemma tendsto_nhds_top_iff_nnreal {m : α → ℝ≥0∞} {f : filter α} :
tendsto m f (𝓝 ⊤) ↔ ∀ x : ℝ≥0, ∀ᶠ a in f, ↑x < m a :=
by simp only [nhds_top', tendsto_infi, tendsto_principal, mem_Ioi]
lemma tendsto_nhds_top_iff_nat {m : α → ℝ≥0∞} {f : filter α} :
tendsto m f (𝓝 ⊤) ↔ ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a :=
tendsto_nhds_top_iff_nnreal.trans ⟨λ h n, by simpa only [ennreal.coe_nat] using h n,
λ h x, let ⟨n, hn⟩ := exists_nat_gt x in
(h n).mono (λ y, lt_trans $ by rwa [← ennreal.coe_nat, coe_lt_coe])⟩
lemma tendsto_nhds_top {m : α → ℝ≥0∞} {f : filter α}
(h : ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a) : tendsto m f (𝓝 ⊤) :=
tendsto_nhds_top_iff_nat.2 h
lemma tendsto_nat_nhds_top : tendsto (λ n : ℕ, ↑n) at_top (𝓝 ∞) :=
tendsto_nhds_top $ λ n, mem_at_top_sets.2
⟨n+1, λ m hm, ennreal.coe_nat_lt_coe_nat.2 $ nat.lt_of_succ_le hm⟩
@[simp, norm_cast] lemma tendsto_coe_nhds_top {f : α → ℝ≥0} {l : filter α} :
tendsto (λ x, (f x : ℝ≥0∞)) l (𝓝 ∞) ↔ tendsto f l at_top :=
by rw [tendsto_nhds_top_iff_nnreal, at_top_basis_Ioi.tendsto_right_iff];
[simp, apply_instance, apply_instance]
lemma nhds_zero : 𝓝 (0 : ℝ≥0∞) = ⨅a ≠ 0, 𝓟 (Iio a) :=
nhds_bot_order.trans $ by simp [bot_lt_iff_ne_bot, Iio]
lemma nhds_zero_basis : (𝓝 (0 : ℝ≥0∞)).has_basis (λ a : ℝ≥0∞, 0 < a) (λ a, Iio a) := nhds_bot_basis
lemma nhds_zero_basis_Iic : (𝓝 (0 : ℝ≥0∞)).has_basis (λ a : ℝ≥0∞, 0 < a) Iic := nhds_bot_basis_Iic
@[instance] lemma nhds_within_Ioi_coe_ne_bot {r : ℝ≥0} : (𝓝[Ioi r] (r : ℝ≥0∞)).ne_bot :=
nhds_within_Ioi_self_ne_bot' ennreal.coe_lt_top
@[instance] lemma nhds_within_Ioi_zero_ne_bot : (𝓝[Ioi 0] (0 : ℝ≥0∞)).ne_bot :=
nhds_within_Ioi_coe_ne_bot
-- using Icc because
-- • don't have 'Ioo (x - ε) (x + ε) ∈ 𝓝 x' unless x > 0
-- • (x - y ≤ ε ↔ x ≤ ε + y) is true, while (x - y < ε ↔ x < ε + y) is not
lemma Icc_mem_nhds : x ≠ ⊤ → 0 < ε → Icc (x - ε) (x + ε) ∈ 𝓝 x :=
begin
assume xt ε0, rw _root_.mem_nhds_iff,
by_cases x0 : x = 0,
{ use Iio (x + ε),
have : Iio (x + ε) ⊆ Icc (x - ε) (x + ε), assume a, rw x0, simpa using le_of_lt,
use this, exact ⟨is_open_Iio, mem_Iio_self_add xt ε0⟩ },
{ use Ioo (x - ε) (x + ε), use Ioo_subset_Icc_self,
exact ⟨is_open_Ioo, mem_Ioo_self_sub_add xt x0 ε0 ε0 ⟩ }
end
lemma nhds_of_ne_top : x ≠ ⊤ → 𝓝 x = ⨅ε > 0, 𝓟 (Icc (x - ε) (x + ε)) :=
begin
assume xt, refine le_antisymm _ _,
-- first direction
simp only [le_infi_iff, le_principal_iff], assume ε ε0, exact Icc_mem_nhds xt ε0,
-- second direction
rw nhds_generate_from, refine le_infi (assume s, le_infi $ assume hs, _),
simp only [mem_set_of_eq] at hs, rcases hs with ⟨xs, ⟨a, ha⟩⟩,
cases ha,
{ rw ha at *,
rcases exists_between xs with ⟨b, ⟨ab, bx⟩⟩,
have xb_pos : x - b > 0 := zero_lt_sub_iff_lt.2 bx,
have xxb : x - (x - b) = b := sub_sub_cancel (by rwa lt_top_iff_ne_top) (le_of_lt bx),
refine infi_le_of_le (x - b) (infi_le_of_le xb_pos _),
simp only [mem_principal, le_principal_iff],
assume y, rintros ⟨h₁, h₂⟩, rw xxb at h₁, calc a < b : ab ... ≤ y : h₁ },
{ rw ha at *,
rcases exists_between xs with ⟨b, ⟨xb, ba⟩⟩,
have bx_pos : b - x > 0 := zero_lt_sub_iff_lt.2 xb,
have xbx : x + (b - x) = b := add_sub_cancel_of_le (le_of_lt xb),
refine infi_le_of_le (b - x) (infi_le_of_le bx_pos _),
simp only [mem_principal, le_principal_iff],
assume y, rintros ⟨h₁, h₂⟩, rw xbx at h₂, calc y ≤ b : h₂ ... < a : ba },
end
/-- Characterization of neighborhoods for `ℝ≥0∞` numbers. See also `tendsto_order`
for a version with strict inequalities. -/
protected theorem tendsto_nhds {f : filter α} {u : α → ℝ≥0∞} {a : ℝ≥0∞} (ha : a ≠ ⊤) :
tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∀ᶠ x in f, (u x) ∈ Icc (a - ε) (a + ε) :=
by simp only [nhds_of_ne_top ha, tendsto_infi, tendsto_principal, mem_Icc]
protected lemma tendsto_at_top [nonempty β] [semilattice_sup β] {f : β → ℝ≥0∞} {a : ℝ≥0∞}
(ha : a ≠ ⊤) : tendsto f at_top (𝓝 a) ↔ ∀ε>0, ∃N, ∀n≥N, (f n) ∈ Icc (a - ε) (a + ε) :=
by simp only [ennreal.tendsto_nhds ha, mem_at_top_sets, mem_set_of_eq, filter.eventually]
instance : has_continuous_add ℝ≥0∞ :=
begin
refine ⟨continuous_iff_continuous_at.2 _⟩,
rintro ⟨(_|a), b⟩,
{ exact tendsto_nhds_top_mono' continuous_at_fst (λ p, le_add_right le_rfl) },
rcases b with (_|b),
{ exact tendsto_nhds_top_mono' continuous_at_snd (λ p, le_add_left le_rfl) },
simp only [continuous_at, some_eq_coe, nhds_coe_coe, ← coe_add, tendsto_map'_iff, (∘),
tendsto_coe, tendsto_add]
end
protected lemma tendsto_at_top_zero [hβ : nonempty β] [semilattice_sup β] {f : β → ℝ≥0∞} :
filter.at_top.tendsto f (𝓝 0) ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, f n ≤ ε :=
begin
rw ennreal.tendsto_at_top zero_ne_top,
{ simp_rw [set.mem_Icc, zero_add, zero_sub, zero_le _, true_and], },
{ exact hβ, },
end
protected lemma tendsto_mul (ha : a ≠ 0 ∨ b ≠ ⊤) (hb : b ≠ 0 ∨ a ≠ ⊤) :
tendsto (λp:ℝ≥0∞×ℝ≥0∞, p.1 * p.2) (𝓝 (a, b)) (𝓝 (a * b)) :=
have ht : ∀b:ℝ≥0∞, b ≠ 0 → tendsto (λp:ℝ≥0∞×ℝ≥0∞, p.1 * p.2) (𝓝 ((⊤:ℝ≥0∞), b)) (𝓝 ⊤),
begin
refine assume b hb, tendsto_nhds_top_iff_nnreal.2 $ assume n, _,
rcases lt_iff_exists_nnreal_btwn.1 (pos_iff_ne_zero.2 hb) with ⟨ε, hε, hεb⟩,
replace hε : 0 < ε, from coe_pos.1 hε,
filter_upwards [prod_is_open.mem_nhds (lt_mem_nhds $ @coe_lt_top (n / ε)) (lt_mem_nhds hεb)],
rintros ⟨a₁, a₂⟩ ⟨h₁, h₂⟩,
dsimp at h₁ h₂ ⊢,
rw [← div_mul_cancel n hε.ne', coe_mul],
exact mul_lt_mul h₁ h₂
end,
begin
cases a, {simp [none_eq_top] at hb, simp [none_eq_top, ht b hb, top_mul, hb] },
cases b, {
simp [none_eq_top] at ha,
simp [*, nhds_swap (a : ℝ≥0∞) ⊤, none_eq_top, some_eq_coe, top_mul, tendsto_map'_iff, (∘),
mul_comm] },
simp [some_eq_coe, nhds_coe_coe, tendsto_map'_iff, (∘)],
simp only [coe_mul.symm, tendsto_coe, tendsto_mul]
end
protected lemma tendsto.mul {f : filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞}
(hma : tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ⊤) (hmb : tendsto mb f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ⊤) :
tendsto (λa, ma a * mb a) f (𝓝 (a * b)) :=
show tendsto ((λp:ℝ≥0∞×ℝ≥0∞, p.1 * p.2) ∘ (λa, (ma a, mb a))) f (𝓝 (a * b)), from
tendsto.comp (ennreal.tendsto_mul ha hb) (hma.prod_mk_nhds hmb)
protected lemma tendsto.const_mul {f : filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞}
(hm : tendsto m f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ⊤) : tendsto (λb, a * m b) f (𝓝 (a * b)) :=
by_cases
(assume : a = 0, by simp [this, tendsto_const_nhds])
(assume ha : a ≠ 0, ennreal.tendsto.mul tendsto_const_nhds (or.inl ha) hm hb)
protected lemma tendsto.mul_const {f : filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞}
(hm : tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ⊤) : tendsto (λx, m x * b) f (𝓝 (a * b)) :=
by simpa only [mul_comm] using ennreal.tendsto.const_mul hm ha
lemma tendsto_finset_prod_of_ne_top {ι : Type*} {f : ι → α → ℝ≥0∞} {x : filter α} {a : ι → ℝ≥0∞}
(s : finset ι) (h : ∀ i ∈ s, tendsto (f i) x (𝓝 (a i))) (h' : ∀ i ∈ s, a i ≠ ∞):
tendsto (λ b, ∏ c in s, f c b) x (𝓝 (∏ c in s, a c)) :=
begin
induction s using finset.induction with a s has IH, { simp [tendsto_const_nhds] },
simp only [finset.prod_insert has],
apply tendsto.mul (h _ (finset.mem_insert_self _ _)),
{ right,
exact (prod_lt_top (λ i hi, lt_top_iff_ne_top.2 (h' _ (finset.mem_insert_of_mem hi)))).ne },
{ exact IH (λ i hi, h _ (finset.mem_insert_of_mem hi))
(λ i hi, h' _ (finset.mem_insert_of_mem hi)) },
{ exact or.inr (h' _ (finset.mem_insert_self _ _)) }
end
protected lemma continuous_at_const_mul {a b : ℝ≥0∞} (h : a ≠ ⊤ ∨ b ≠ 0) :
continuous_at ((*) a) b :=
tendsto.const_mul tendsto_id h.symm
protected lemma continuous_at_mul_const {a b : ℝ≥0∞} (h : a ≠ ⊤ ∨ b ≠ 0) :
continuous_at (λ x, x * a) b :=
tendsto.mul_const tendsto_id h.symm
protected lemma continuous_const_mul {a : ℝ≥0∞} (ha : a ≠ ⊤) : continuous ((*) a) :=
continuous_iff_continuous_at.2 $ λ x, ennreal.continuous_at_const_mul (or.inl ha)
protected lemma continuous_mul_const {a : ℝ≥0∞} (ha : a ≠ ⊤) : continuous (λ x, x * a) :=
continuous_iff_continuous_at.2 $ λ x, ennreal.continuous_at_mul_const (or.inl ha)
lemma le_of_forall_lt_one_mul_le {x y : ℝ≥0∞} (h : ∀ a < 1, a * x ≤ y) : x ≤ y :=
begin
have : tendsto (* x) (𝓝[Iio 1] 1) (𝓝 (1 * x)) :=
(ennreal.continuous_at_mul_const (or.inr one_ne_zero)).mono_left inf_le_left,
rw one_mul at this,
haveI : (𝓝[Iio 1] (1 : ℝ≥0∞)).ne_bot := nhds_within_Iio_self_ne_bot' ennreal.zero_lt_one,
exact le_of_tendsto this (eventually_nhds_within_iff.2 $ eventually_of_forall h)
end
lemma infi_mul_left' {ι} {f : ι → ℝ≥0∞} {a : ℝ≥0∞}
(h : a = ⊤ → (⨅ i, f i) = 0 → ∃ i, f i = 0) (h0 : a = 0 → nonempty ι) :
(⨅ i, a * f i) = a * ⨅ i, f i :=
begin
by_cases H : a = ⊤ ∧ (⨅ i, f i) = 0,
{ rcases h H.1 H.2 with ⟨i, hi⟩,
rw [H.2, mul_zero, ← bot_eq_zero, infi_eq_bot],
exact λ b hb, ⟨i, by rwa [hi, mul_zero, ← bot_eq_zero]⟩ },
{ rw not_and_distrib at H,
casesI is_empty_or_nonempty ι,
{ rw [infi_of_empty, infi_of_empty, mul_top, if_neg],
exact mt h0 (not_nonempty_iff.2 ‹_›) },
{ exact (map_infi_of_continuous_at_of_monotone' (ennreal.continuous_at_const_mul H)
ennreal.mul_left_mono).symm } }
end
lemma infi_mul_left {ι} [nonempty ι] {f : ι → ℝ≥0∞} {a : ℝ≥0∞}
(h : a = ⊤ → (⨅ i, f i) = 0 → ∃ i, f i = 0) :
(⨅ i, a * f i) = a * ⨅ i, f i :=
infi_mul_left' h (λ _, ‹nonempty ι›)
lemma infi_mul_right' {ι} {f : ι → ℝ≥0∞} {a : ℝ≥0∞}
(h : a = ⊤ → (⨅ i, f i) = 0 → ∃ i, f i = 0) (h0 : a = 0 → nonempty ι) :
(⨅ i, f i * a) = (⨅ i, f i) * a :=
by simpa only [mul_comm a] using infi_mul_left' h h0
lemma infi_mul_right {ι} [nonempty ι] {f : ι → ℝ≥0∞} {a : ℝ≥0∞}
(h : a = ⊤ → (⨅ i, f i) = 0 → ∃ i, f i = 0) :
(⨅ i, f i * a) = (⨅ i, f i) * a :=
infi_mul_right' h (λ _, ‹nonempty ι›)
protected lemma continuous_inv : continuous (has_inv.inv : ℝ≥0∞ → ℝ≥0∞) :=
continuous_iff_continuous_at.2 $ λ a, tendsto_order.2
⟨begin
assume b hb,
simp only [@ennreal.lt_inv_iff_lt_inv b],
exact gt_mem_nhds (ennreal.lt_inv_iff_lt_inv.1 hb),
end,
begin
assume b hb,
simp only [gt_iff_lt, @ennreal.inv_lt_iff_inv_lt _ b],
exact lt_mem_nhds (ennreal.inv_lt_iff_inv_lt.1 hb)
end⟩
@[simp] protected lemma tendsto_inv_iff {f : filter α} {m : α → ℝ≥0∞} {a : ℝ≥0∞} :
tendsto (λ x, (m x)⁻¹) f (𝓝 a⁻¹) ↔ tendsto m f (𝓝 a) :=
⟨λ h, by simpa only [function.comp, ennreal.inv_inv]
using (ennreal.continuous_inv.tendsto a⁻¹).comp h,
(ennreal.continuous_inv.tendsto a).comp⟩
protected lemma tendsto.div {f : filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞}
(hma : tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) (hmb : tendsto mb f (𝓝 b)) (hb : b ≠ ⊤ ∨ a ≠ ⊤) :
tendsto (λa, ma a / mb a) f (𝓝 (a / b)) :=
by { apply tendsto.mul hma _ (ennreal.tendsto_inv_iff.2 hmb) _; simp [ha, hb] }
protected lemma tendsto.const_div {f : filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞}
(hm : tendsto m f (𝓝 b)) (hb : b ≠ ⊤ ∨ a ≠ ⊤) : tendsto (λb, a / m b) f (𝓝 (a / b)) :=
by { apply tendsto.const_mul (ennreal.tendsto_inv_iff.2 hm), simp [hb] }
protected lemma tendsto.div_const {f : filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞}
(hm : tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) : tendsto (λx, m x / b) f (𝓝 (a / b)) :=
by { apply tendsto.mul_const hm, simp [ha] }
protected lemma tendsto_inv_nat_nhds_zero : tendsto (λ n : ℕ, (n : ℝ≥0∞)⁻¹) at_top (𝓝 0) :=
ennreal.inv_top ▸ ennreal.tendsto_inv_iff.2 tendsto_nat_nhds_top
lemma bsupr_add {ι} {s : set ι} (hs : s.nonempty) {f : ι → ℝ≥0∞} :
(⨆ i ∈ s, f i) + a = ⨆ i ∈ s, f i + a :=
begin
simp only [← Sup_image], symmetry,
rw [image_comp (+ a)],
refine is_lub.Sup_eq ((is_lub_Sup $ f '' s).is_lub_of_tendsto _ (hs.image _) _),
exacts [λ x _ y _ hxy, add_le_add hxy le_rfl,
tendsto.add (tendsto_id' inf_le_left) tendsto_const_nhds]
end
lemma Sup_add {s : set ℝ≥0∞} (hs : s.nonempty) : Sup s + a = ⨆b∈s, b + a :=
by rw [Sup_eq_supr, bsupr_add hs]
lemma supr_add {ι : Sort*} {s : ι → ℝ≥0∞} [h : nonempty ι] : supr s + a = ⨆b, s b + a :=
let ⟨x⟩ := h in
calc supr s + a = Sup (range s) + a : by rw Sup_range
... = (⨆b∈range s, b + a) : Sup_add ⟨s x, x, rfl⟩
... = _ : supr_range
lemma add_supr {ι : Sort*} {s : ι → ℝ≥0∞} [h : nonempty ι] : a + supr s = ⨆b, a + s b :=
by rw [add_comm, supr_add]; simp [add_comm]
lemma supr_add_supr {ι : Sort*} {f g : ι → ℝ≥0∞} (h : ∀i j, ∃k, f i + g j ≤ f k + g k) :
supr f + supr g = (⨆ a, f a + g a) :=
begin
by_cases hι : nonempty ι,
{ letI := hι,
refine le_antisymm _ (supr_le $ λ a, add_le_add (le_supr _ _) (le_supr _ _)),
simpa [add_supr, supr_add] using
λ i j:ι, show f i + g j ≤ ⨆ a, f a + g a, from
let ⟨k, hk⟩ := h i j in le_supr_of_le k hk },
{ have : ∀f:ι → ℝ≥0∞, (⨆i, f i) = 0 := λ f, supr_eq_zero.mpr (λ i, (hι ⟨i⟩).elim),
rw [this, this, this, zero_add] }
end
lemma supr_add_supr_of_monotone {ι : Sort*} [semilattice_sup ι]
{f g : ι → ℝ≥0∞} (hf : monotone f) (hg : monotone g) :
supr f + supr g = (⨆ a, f a + g a) :=
supr_add_supr $ assume i j, ⟨i ⊔ j, add_le_add (hf $ le_sup_left) (hg $ le_sup_right)⟩
lemma finset_sum_supr_nat {α} {ι} [semilattice_sup ι] {s : finset α} {f : α → ι → ℝ≥0∞}
(hf : ∀a, monotone (f a)) :
∑ a in s, supr (f a) = (⨆ n, ∑ a in s, f a n) :=
begin
refine finset.induction_on s _ _,
{ simp, },
{ assume a s has ih,
simp only [finset.sum_insert has],
rw [ih, supr_add_supr_of_monotone (hf a)],
assume i j h,
exact (finset.sum_le_sum $ assume a ha, hf a h) }
end
lemma mul_Sup {s : set ℝ≥0∞} {a : ℝ≥0∞} : a * Sup s = ⨆i∈s, a * i :=
begin
by_cases hs : ∀x∈s, x = (0:ℝ≥0∞),
{ have h₁ : Sup s = 0 := (bot_unique $ Sup_le $ assume a ha, (hs a ha).symm ▸ le_refl 0),
have h₂ : (⨆i ∈ s, a * i) = 0 :=
(bot_unique $ supr_le $ assume a, supr_le $ assume ha, by simp [hs a ha]),
rw [h₁, h₂, mul_zero] },
{ simp only [not_forall] at hs,
rcases hs with ⟨x, hx, hx0⟩,
have s₁ : Sup s ≠ 0 :=
pos_iff_ne_zero.1 (lt_of_lt_of_le (pos_iff_ne_zero.2 hx0) (le_Sup hx)),
have : Sup ((λb, a * b) '' s) = a * Sup s :=
is_lub.Sup_eq ((is_lub_Sup s).is_lub_of_tendsto
(assume x _ y _ h, mul_le_mul_left' h _)
⟨x, hx⟩
(ennreal.tendsto.const_mul (tendsto_id' inf_le_left) (or.inl s₁))),
rw [this.symm, Sup_image] }
end
lemma mul_supr {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : a * supr f = ⨆i, a * f i :=
by rw [← Sup_range, mul_Sup, supr_range]
lemma supr_mul {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : supr f * a = ⨆i, f i * a :=
by rw [mul_comm, mul_supr]; congr; funext; rw [mul_comm]
lemma supr_div {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : supr f / a = ⨆i, f i / a :=
supr_mul
protected lemma tendsto_coe_sub : ∀{b:ℝ≥0∞}, tendsto (λb:ℝ≥0∞, ↑r - b) (𝓝 b) (𝓝 (↑r - b)) :=
begin
refine (forall_ennreal.2 $ and.intro (assume a, _) _),
{ simp [@nhds_coe a, tendsto_map'_iff, (∘), tendsto_coe, coe_sub.symm],
exact tendsto_const_nhds.sub tendsto_id },
simp,
exact (tendsto.congr' (mem_of_superset (lt_mem_nhds $ @coe_lt_top r) $
by simp [le_of_lt] {contextual := tt})) tendsto_const_nhds
end
lemma sub_supr {ι : Sort*} [nonempty ι] {b : ι → ℝ≥0∞} (hr : a < ⊤) :
a - (⨆i, b i) = (⨅i, a - b i) :=
let ⟨r, eq, _⟩ := lt_iff_exists_coe.mp hr in
have Inf ((λb, ↑r - b) '' range b) = ↑r - (⨆i, b i),
from is_glb.Inf_eq $ is_lub_supr.is_glb_of_tendsto
(assume x _ y _, sub_le_sub (le_refl _))
(range_nonempty _)
(ennreal.tendsto_coe_sub.comp (tendsto_id' inf_le_left)),
by rw [eq, ←this]; simp [Inf_image, infi_range, -mem_range]; exact le_refl _
end topological_space
section tsum
variables {f g : α → ℝ≥0∞}
@[norm_cast] protected lemma has_sum_coe {f : α → ℝ≥0} {r : ℝ≥0} :
has_sum (λa, (f a : ℝ≥0∞)) ↑r ↔ has_sum f r :=
have (λs:finset α, ∑ a in s, ↑(f a)) = (coe : ℝ≥0 → ℝ≥0∞) ∘ (λs:finset α, ∑ a in s, f a),
from funext $ assume s, ennreal.coe_finset_sum.symm,
by unfold has_sum; rw [this, tendsto_coe]
protected lemma tsum_coe_eq {f : α → ℝ≥0} (h : has_sum f r) : ∑'a, (f a : ℝ≥0∞) = r :=
(ennreal.has_sum_coe.2 h).tsum_eq
protected lemma coe_tsum {f : α → ℝ≥0} : summable f → ↑(tsum f) = ∑'a, (f a : ℝ≥0∞)
| ⟨r, hr⟩ := by rw [hr.tsum_eq, ennreal.tsum_coe_eq hr]
protected lemma has_sum : has_sum f (⨆s:finset α, ∑ a in s, f a) :=
tendsto_at_top_supr $ λ s t, finset.sum_le_sum_of_subset
@[simp] protected lemma summable : summable f := ⟨_, ennreal.has_sum⟩
lemma tsum_coe_ne_top_iff_summable {f : β → ℝ≥0} :
∑' b, (f b:ℝ≥0∞) ≠ ∞ ↔ summable f :=
begin
refine ⟨λ h, _, λ h, ennreal.coe_tsum h ▸ ennreal.coe_ne_top⟩,
lift (∑' b, (f b:ℝ≥0∞)) to ℝ≥0 using h with a ha,
refine ⟨a, ennreal.has_sum_coe.1 _⟩,
rw ha,
exact ennreal.summable.has_sum
end
protected lemma tsum_eq_supr_sum : ∑'a, f a = (⨆s:finset α, ∑ a in s, f a) :=
ennreal.has_sum.tsum_eq
protected lemma tsum_eq_supr_sum' {ι : Type*} (s : ι → finset α) (hs : ∀ t, ∃ i, t ⊆ s i) :
∑' a, f a = ⨆ i, ∑ a in s i, f a :=
begin
rw [ennreal.tsum_eq_supr_sum],
symmetry,
change (⨆i:ι, (λ t : finset α, ∑ a in t, f a) (s i)) = ⨆s:finset α, ∑ a in s, f a,
exact (finset.sum_mono_set f).supr_comp_eq hs
end
protected lemma tsum_sigma {β : α → Type*} (f : Πa, β a → ℝ≥0∞) :
∑'p:Σa, β a, f p.1 p.2 = ∑'a b, f a b :=
tsum_sigma' (assume b, ennreal.summable) ennreal.summable
protected lemma tsum_sigma' {β : α → Type*} (f : (Σ a, β a) → ℝ≥0∞) :
∑'p:(Σa, β a), f p = ∑'a b, f ⟨a, b⟩ :=
tsum_sigma' (assume b, ennreal.summable) ennreal.summable
protected lemma tsum_prod {f : α → β → ℝ≥0∞} : ∑'p:α×β, f p.1 p.2 = ∑'a, ∑'b, f a b :=
tsum_prod' ennreal.summable $ λ _, ennreal.summable
protected lemma tsum_comm {f : α → β → ℝ≥0∞} : ∑'a, ∑'b, f a b = ∑'b, ∑'a, f a b :=
tsum_comm' ennreal.summable (λ _, ennreal.summable) (λ _, ennreal.summable)
protected lemma tsum_add : ∑'a, (f a + g a) = (∑'a, f a) + (∑'a, g a) :=
tsum_add ennreal.summable ennreal.summable
protected lemma tsum_le_tsum (h : ∀a, f a ≤ g a) : ∑'a, f a ≤ ∑'a, g a :=
tsum_le_tsum h ennreal.summable ennreal.summable
protected lemma sum_le_tsum {f : α → ℝ≥0∞} (s : finset α) : ∑ x in s, f x ≤ ∑' x, f x :=
sum_le_tsum s (λ x hx, zero_le _) ennreal.summable
protected lemma tsum_eq_supr_nat' {f : ℕ → ℝ≥0∞} {N : ℕ → ℕ} (hN : tendsto N at_top at_top) :
∑'i:ℕ, f i = (⨆i:ℕ, ∑ a in finset.range (N i), f a) :=
ennreal.tsum_eq_supr_sum' _ $ λ t,
let ⟨n, hn⟩ := t.exists_nat_subset_range,
⟨k, _, hk⟩ := exists_le_of_tendsto_at_top hN 0 n in
⟨k, finset.subset.trans hn (finset.range_mono hk)⟩
protected lemma tsum_eq_supr_nat {f : ℕ → ℝ≥0∞} :
∑'i:ℕ, f i = (⨆i:ℕ, ∑ a in finset.range i, f a) :=
ennreal.tsum_eq_supr_sum' _ finset.exists_nat_subset_range
protected lemma tsum_eq_liminf_sum_nat {f : ℕ → ℝ≥0∞} :
∑' i, f i = filter.at_top.liminf (λ n, ∑ i in finset.range n, f i) :=
begin
rw [ennreal.tsum_eq_supr_nat, filter.liminf_eq_supr_infi_of_nat],
congr,
refine funext (λ n, le_antisymm _ _),
{ refine le_binfi (λ i hi, finset.sum_le_sum_of_subset_of_nonneg _ (λ _ _ _, zero_le _)),
simpa only [finset.range_subset, add_le_add_iff_right] using hi, },
{ refine le_trans (infi_le _ n) _,
simp [le_refl n, le_refl ((finset.range n).sum f)], },
end
protected lemma le_tsum (a : α) : f a ≤ ∑'a, f a :=
le_tsum' ennreal.summable a
protected lemma tsum_eq_top_of_eq_top : (∃ a, f a = ∞) → ∑' a, f a = ∞
| ⟨a, ha⟩ := top_unique $ ha ▸ ennreal.le_tsum a
@[simp] protected lemma tsum_top [nonempty α] : ∑' a : α, ∞ = ∞ :=
let ⟨a⟩ := ‹nonempty α› in ennreal.tsum_eq_top_of_eq_top ⟨a, rfl⟩
protected lemma ne_top_of_tsum_ne_top (h : ∑' a, f a ≠ ∞) (a : α) : f a ≠ ∞ :=
λ ha, h $ ennreal.tsum_eq_top_of_eq_top ⟨a, ha⟩
protected lemma tsum_mul_left : ∑'i, a * f i = a * ∑'i, f i :=
if h : ∀i, f i = 0 then by simp [h] else
let ⟨i, (hi : f i ≠ 0)⟩ := not_forall.mp h in
have sum_ne_0 : ∑'i, f i ≠ 0, from ne_of_gt $
calc 0 < f i : lt_of_le_of_ne (zero_le _) hi.symm
... ≤ ∑'i, f i : ennreal.le_tsum _,
have tendsto (λs:finset α, ∑ j in s, a * f j) at_top (𝓝 (a * ∑'i, f i)),
by rw [← show (*) a ∘ (λs:finset α, ∑ j in s, f j) = λs, ∑ j in s, a * f j,
from funext $ λ s, finset.mul_sum];
exact ennreal.tendsto.const_mul ennreal.summable.has_sum (or.inl sum_ne_0),
has_sum.tsum_eq this
protected lemma tsum_mul_right : (∑'i, f i * a) = (∑'i, f i) * a :=
by simp [mul_comm, ennreal.tsum_mul_left]
@[simp] lemma tsum_supr_eq {α : Type*} (a : α) {f : α → ℝ≥0∞} :
∑'b:α, (⨆ (h : a = b), f b) = f a :=
le_antisymm
(by rw [ennreal.tsum_eq_supr_sum]; exact supr_le (assume s,
calc (∑ b in s, ⨆ (h : a = b), f b) ≤ ∑ b in {a}, ⨆ (h : a = b), f b :
finset.sum_le_sum_of_ne_zero $ assume b _ hb,
suffices a = b, by simpa using this.symm,
classical.by_contradiction $ assume h,
by simpa [h] using hb
... = f a : by simp))
(calc f a ≤ (⨆ (h : a = a), f a) : le_supr (λh:a=a, f a) rfl
... ≤ (∑'b:α, ⨆ (h : a = b), f b) : ennreal.le_tsum _)
lemma has_sum_iff_tendsto_nat {f : ℕ → ℝ≥0∞} (r : ℝ≥0∞) :
has_sum f r ↔ tendsto (λn:ℕ, ∑ i in finset.range n, f i) at_top (𝓝 r) :=
begin
refine ⟨has_sum.tendsto_sum_nat, assume h, _⟩,
rw [← supr_eq_of_tendsto _ h, ← ennreal.tsum_eq_supr_nat],
{ exact ennreal.summable.has_sum },
{ exact assume s t hst, finset.sum_le_sum_of_subset (finset.range_subset.2 hst) }
end
lemma tendsto_nat_tsum (f : ℕ → ℝ≥0∞) :
tendsto (λn:ℕ, ∑ i in finset.range n, f i) at_top (𝓝 (∑' n, f n)) :=
by { rw ← has_sum_iff_tendsto_nat, exact ennreal.summable.has_sum }
lemma to_nnreal_apply_of_tsum_ne_top {α : Type*} {f : α → ℝ≥0∞} (hf : ∑' i, f i ≠ ∞) (x : α) :
(((ennreal.to_nnreal ∘ f) x : ℝ≥0) : ℝ≥0∞) = f x :=
coe_to_nnreal $ ennreal.ne_top_of_tsum_ne_top hf _
lemma summable_to_nnreal_of_tsum_ne_top {α : Type*} {f : α → ℝ≥0∞} (hf : ∑' i, f i ≠ ∞) :
summable (ennreal.to_nnreal ∘ f) :=
by simpa only [←tsum_coe_ne_top_iff_summable, to_nnreal_apply_of_tsum_ne_top hf] using hf
lemma tendsto_cofinite_zero_of_tsum_lt_top {α} {f : α → ℝ≥0∞} (hf : ∑' x, f x < ∞) :
tendsto f cofinite (𝓝 0) :=
begin
have f_ne_top : ∀ n, f n ≠ ∞, from ennreal.ne_top_of_tsum_ne_top hf.ne,
have h_f_coe : f = λ n, ((f n).to_nnreal : ennreal),
from funext (λ n, (coe_to_nnreal (f_ne_top n)).symm),
rw [h_f_coe, ←@coe_zero, tendsto_coe],
exact nnreal.tendsto_cofinite_zero_of_summable (summable_to_nnreal_of_tsum_ne_top hf.ne),
end
lemma tendsto_at_top_zero_of_tsum_lt_top {f : ℕ → ℝ≥0∞} (hf : ∑' x, f x < ∞) :
tendsto f at_top (𝓝 0) :=
by { rw ←nat.cofinite_eq_at_top, exact tendsto_cofinite_zero_of_tsum_lt_top hf }
protected lemma tsum_apply {ι α : Type*} {f : ι → α → ℝ≥0∞} {x : α} :
(∑' i, f i) x = ∑' i, f i x :=
tsum_apply $ pi.summable.mpr $ λ _, ennreal.summable
lemma tsum_sub {f : ℕ → ℝ≥0∞} {g : ℕ → ℝ≥0∞} (h₁ : ∑' i, g i < ∞) (h₂ : g ≤ f) :
∑' i, (f i - g i) = (∑' i, f i) - (∑' i, g i) :=
begin
have h₃: ∑' i, (f i - g i) = ∑' i, (f i - g i + g i) - ∑' i, g i,
{ rw [ennreal.tsum_add, add_sub_self h₁]},
have h₄:(λ i, (f i - g i) + (g i)) = f,
{ ext n, rw ennreal.sub_add_cancel_of_le (h₂ n)},
rw h₄ at h₃, apply h₃,
end
end tsum
lemma tendsto_to_real_iff {ι} {fi : filter ι} {f : ι → ℝ≥0∞} (hf : ∀ i, f i ≠ ∞) {x : ℝ≥0∞}
(hx : x ≠ ∞) :
fi.tendsto (λ n, (f n).to_real) (𝓝 x.to_real) ↔ fi.tendsto f (𝓝 x) :=
begin
refine ⟨λ h, _, λ h, tendsto.comp (ennreal.tendsto_to_real hx) h⟩,
have h_eq : f = (λ n, ennreal.of_real (f n).to_real),
by { ext1 n, rw ennreal.of_real_to_real (hf n), },
rw [h_eq, ← ennreal.of_real_to_real hx],
exact ennreal.tendsto_of_real h,
end
lemma tsum_coe_ne_top_iff_summable_coe {f : α → ℝ≥0} :
∑' a, (f a : ℝ≥0∞) ≠ ∞ ↔ summable (λ a, (f a : ℝ)) :=
begin
rw nnreal.summable_coe,
exact tsum_coe_ne_top_iff_summable,
end
lemma tsum_coe_eq_top_iff_not_summable_coe {f : α → ℝ≥0} :
∑' a, (f a : ℝ≥0∞) = ∞ ↔ ¬ summable (λ a, (f a : ℝ)) :=
begin
rw [← @not_not (∑' a, ↑(f a) = ⊤)],
exact not_congr tsum_coe_ne_top_iff_summable_coe
end
lemma summable_to_real {f : α → ℝ≥0∞} (hsum : ∑' x, f x ≠ ∞) :
summable (λ x, (f x).to_real) :=
begin
lift f to α → ℝ≥0 using ennreal.ne_top_of_tsum_ne_top hsum,
rwa ennreal.tsum_coe_ne_top_iff_summable_coe at hsum,
end
end ennreal
namespace nnreal
open_locale nnreal
lemma tsum_eq_to_nnreal_tsum {f : β → ℝ≥0} :
(∑' b, f b) = (∑' b, (f b : ℝ≥0∞)).to_nnreal :=
begin
by_cases h : summable f,
{ rw [← ennreal.coe_tsum h, ennreal.to_nnreal_coe] },
{ have A := tsum_eq_zero_of_not_summable h,
simp only [← ennreal.tsum_coe_ne_top_iff_summable, not_not] at h,
simp only [h, ennreal.top_to_nnreal, A] }
end
/-- Comparison test of convergence of `ℝ≥0`-valued series. -/
lemma exists_le_has_sum_of_le {f g : β → ℝ≥0} {r : ℝ≥0}
(hgf : ∀b, g b ≤ f b) (hfr : has_sum f r) : ∃p≤r, has_sum g p :=
have ∑'b, (g b : ℝ≥0∞) ≤ r,
begin
refine has_sum_le (assume b, _) ennreal.summable.has_sum (ennreal.has_sum_coe.2 hfr),
exact ennreal.coe_le_coe.2 (hgf _)
end,
let ⟨p, eq, hpr⟩ := ennreal.le_coe_iff.1 this in
⟨p, hpr, ennreal.has_sum_coe.1 $ eq ▸ ennreal.summable.has_sum⟩
/-- Comparison test of convergence of `ℝ≥0`-valued series. -/
lemma summable_of_le {f g : β → ℝ≥0} (hgf : ∀b, g b ≤ f b) : summable f → summable g
| ⟨r, hfr⟩ := let ⟨p, _, hp⟩ := exists_le_has_sum_of_le hgf hfr in hp.summable
/-- A series of non-negative real numbers converges to `r` in the sense of `has_sum` if and only if
the sequence of partial sum converges to `r`. -/
lemma has_sum_iff_tendsto_nat {f : ℕ → ℝ≥0} {r : ℝ≥0} :
has_sum f r ↔ tendsto (λn:ℕ, ∑ i in finset.range n, f i) at_top (𝓝 r) :=
begin
rw [← ennreal.has_sum_coe, ennreal.has_sum_iff_tendsto_nat],
simp only [ennreal.coe_finset_sum.symm],
exact ennreal.tendsto_coe
end
lemma not_summable_iff_tendsto_nat_at_top {f : ℕ → ℝ≥0} :
¬ summable f ↔ tendsto (λ n : ℕ, ∑ i in finset.range n, f i) at_top at_top :=
begin
split,
{ intros h,
refine ((tendsto_of_monotone _).resolve_right h).comp _,
exacts [finset.sum_mono_set _, tendsto_finset_range] },
{ rintros hnat ⟨r, hr⟩,
exact not_tendsto_nhds_of_tendsto_at_top hnat _ (has_sum_iff_tendsto_nat.1 hr) }
end
lemma summable_iff_not_tendsto_nat_at_top {f : ℕ → ℝ≥0} :
summable f ↔ ¬ tendsto (λ n : ℕ, ∑ i in finset.range n, f i) at_top at_top :=
by rw [← not_iff_not, not_not, not_summable_iff_tendsto_nat_at_top]
lemma summable_of_sum_range_le {f : ℕ → ℝ≥0} {c : ℝ≥0}
(h : ∀ n, ∑ i in finset.range n, f i ≤ c) : summable f :=
begin
apply summable_iff_not_tendsto_nat_at_top.2 (λ H, _),
rcases exists_lt_of_tendsto_at_top H 0 c with ⟨n, -, hn⟩,
exact lt_irrefl _ (hn.trans_le (h n)),
end
lemma tsum_le_of_sum_range_le {f : ℕ → ℝ≥0} {c : ℝ≥0}
(h : ∀ n, ∑ i in finset.range n, f i ≤ c) : ∑' n, f n ≤ c :=
le_of_tendsto' (has_sum_iff_tendsto_nat.1 (summable_of_sum_range_le h).has_sum) h
lemma tsum_comp_le_tsum_of_inj {β : Type*} {f : α → ℝ≥0} (hf : summable f)
{i : β → α} (hi : function.injective i) : ∑' x, f (i x) ≤ ∑' x, f x :=
tsum_le_tsum_of_inj i hi (λ c hc, zero_le _) (λ b, le_refl _) (summable_comp_injective hf hi) hf
lemma summable_sigma {β : Π x : α, Type*} {f : (Σ x, β x) → ℝ≥0} :
summable f ↔ (∀ x, summable (λ y, f ⟨x, y⟩)) ∧ summable (λ x, ∑' y, f ⟨x, y⟩) :=
begin
split,
{ simp only [← nnreal.summable_coe, nnreal.coe_tsum],
exact λ h, ⟨h.sigma_factor, h.sigma⟩ },
{ rintro ⟨h₁, h₂⟩,
simpa only [← ennreal.tsum_coe_ne_top_iff_summable, ennreal.tsum_sigma', ennreal.coe_tsum, h₁]
using h₂ }
end
lemma indicator_summable {f : α → ℝ≥0} (hf : summable f) (s : set α) :
summable (s.indicator f) :=
begin
refine nnreal.summable_of_le (λ a, le_trans (le_of_eq (s.indicator_apply f a)) _) hf,
split_ifs,
exact le_refl (f a),
exact zero_le_coe,
end
lemma tsum_indicator_ne_zero {f : α → ℝ≥0} (hf : summable f) {s : set α} (h : ∃ a ∈ s, f a ≠ 0) :
∑' x, (s.indicator f) x ≠ 0 :=
λ h', let ⟨a, ha, hap⟩ := h in
hap (trans (set.indicator_apply_eq_self.mpr (absurd ha)).symm
(((tsum_eq_zero_iff (indicator_summable hf s)).1 h') a))
open finset
/-- For `f : ℕ → ℝ≥0`, then `∑' k, f (k + i)` tends to zero. This does not require a summability
assumption on `f`, as otherwise all sums are zero. -/
lemma tendsto_sum_nat_add (f : ℕ → ℝ≥0) : tendsto (λ i, ∑' k, f (k + i)) at_top (𝓝 0) :=
begin
rw ← tendsto_coe,
convert tendsto_sum_nat_add (λ i, (f i : ℝ)),
norm_cast,
end
lemma has_sum_lt {f g : α → ℝ≥0} {sf sg : ℝ≥0} {i : α} (h : ∀ (a : α), f a ≤ g a) (hi : f i < g i)
(hf : has_sum f sf) (hg : has_sum g sg) : sf < sg :=
begin
have A : ∀ (a : α), (f a : ℝ) ≤ g a := λ a, nnreal.coe_le_coe.2 (h a),
have : (sf : ℝ) < sg :=
has_sum_lt A (nnreal.coe_lt_coe.2 hi) (has_sum_coe.2 hf) (has_sum_coe.2 hg),
exact nnreal.coe_lt_coe.1 this
end
@[mono] lemma has_sum_strict_mono
{f g : α → ℝ≥0} {sf sg : ℝ≥0} (hf : has_sum f sf) (hg : has_sum g sg) (h : f < g) : sf < sg :=
let ⟨hle, i, hi⟩ := pi.lt_def.mp h in has_sum_lt hle hi hf hg
lemma tsum_lt_tsum {f g : α → ℝ≥0} {i : α} (h : ∀ (a : α), f a ≤ g a) (hi : f i < g i)
(hg : summable g) : ∑' n, f n < ∑' n, g n :=
has_sum_lt h hi (summable_of_le h hg).has_sum hg.has_sum
@[mono] lemma tsum_strict_mono {f g : α → ℝ≥0} (hg : summable g) (h : f < g) :
∑' n, f n < ∑' n, g n :=
let ⟨hle, i, hi⟩ := pi.lt_def.mp h in tsum_lt_tsum hle hi hg
lemma tsum_pos {g : α → ℝ≥0} (hg : summable g) (i : α) (hi : 0 < g i) :
0 < ∑' b, g b :=
by { rw ← tsum_zero, exact tsum_lt_tsum (λ a, zero_le _) hi hg }
end nnreal
namespace ennreal
lemma tsum_to_real_eq
{f : α → ℝ≥0∞} (hf : ∀ a, f a ≠ ∞) :
(∑' a, f a).to_real = ∑' a, (f a).to_real :=
begin
lift f to α → ℝ≥0 using hf,
have : (∑' (a : α), (f a : ℝ≥0∞)).to_real =
((∑' (a : α), (f a : ℝ≥0∞)).to_nnreal : ℝ≥0∞).to_real,
{ rw [ennreal.coe_to_real], refl },
rw [this, ← nnreal.tsum_eq_to_nnreal_tsum, ennreal.coe_to_real],
exact nnreal.coe_tsum
end
lemma tendsto_sum_nat_add (f : ℕ → ℝ≥0∞) (hf : ∑' i, f i ≠ ∞) :
tendsto (λ i, ∑' k, f (k + i)) at_top (𝓝 0) :=
begin
lift f to ℕ → ℝ≥0 using ennreal.ne_top_of_tsum_ne_top hf,
replace hf : summable f := tsum_coe_ne_top_iff_summable.1 hf,
simp only [← ennreal.coe_tsum, nnreal.summable_nat_add _ hf, ← ennreal.coe_zero],
exact_mod_cast nnreal.tendsto_sum_nat_add f
end
end ennreal
lemma tsum_comp_le_tsum_of_inj {β : Type*} {f : α → ℝ} (hf : summable f) (hn : ∀ a, 0 ≤ f a)
{i : β → α} (hi : function.injective i) : tsum (f ∘ i) ≤ tsum f :=
begin
lift f to α → ℝ≥0 using hn,
rw nnreal.summable_coe at hf,
simpa only [(∘), ← nnreal.coe_tsum] using nnreal.tsum_comp_le_tsum_of_inj hf hi
end
/-- Comparison test of convergence of series of non-negative real numbers. -/
lemma summable_of_nonneg_of_le {f g : β → ℝ}
(hg : ∀b, 0 ≤ g b) (hgf : ∀b, g b ≤ f b) (hf : summable f) : summable g :=
begin
lift f to β → ℝ≥0 using λ b, (hg b).trans (hgf b),
lift g to β → ℝ≥0 using hg,
rw nnreal.summable_coe at hf ⊢,
exact nnreal.summable_of_le (λ b, nnreal.coe_le_coe.1 (hgf b)) hf
end
/-- A series of non-negative real numbers converges to `r` in the sense of `has_sum` if and only if
the sequence of partial sum converges to `r`. -/
lemma has_sum_iff_tendsto_nat_of_nonneg {f : ℕ → ℝ} (hf : ∀i, 0 ≤ f i) (r : ℝ) :
has_sum f r ↔ tendsto (λ n : ℕ, ∑ i in finset.range n, f i) at_top (𝓝 r) :=
begin
lift f to ℕ → ℝ≥0 using hf,
simp only [has_sum, ← nnreal.coe_sum, nnreal.tendsto_coe'],
exact exists_congr (λ hr, nnreal.has_sum_iff_tendsto_nat)
end
lemma ennreal.of_real_tsum_of_nonneg {f : α → ℝ} (hf_nonneg : ∀ n, 0 ≤ f n) (hf : summable f) :
ennreal.of_real (∑' n, f n) = ∑' n, ennreal.of_real (f n) :=
by simp_rw [ennreal.of_real, ennreal.tsum_coe_eq (nnreal.has_sum_of_real_of_nonneg hf_nonneg hf)]
lemma not_summable_iff_tendsto_nat_at_top_of_nonneg {f : ℕ → ℝ} (hf : ∀ n, 0 ≤ f n) :
¬ summable f ↔ tendsto (λ n : ℕ, ∑ i in finset.range n, f i) at_top at_top :=
begin
lift f to ℕ → ℝ≥0 using hf,
exact_mod_cast nnreal.not_summable_iff_tendsto_nat_at_top
end
lemma summable_iff_not_tendsto_nat_at_top_of_nonneg {f : ℕ → ℝ} (hf : ∀ n, 0 ≤ f n) :
summable f ↔ ¬ tendsto (λ n : ℕ, ∑ i in finset.range n, f i) at_top at_top :=
by rw [← not_iff_not, not_not, not_summable_iff_tendsto_nat_at_top_of_nonneg hf]
lemma summable_sigma_of_nonneg {β : Π x : α, Type*} {f : (Σ x, β x) → ℝ} (hf : ∀ x, 0 ≤ f x) :
summable f ↔ (∀ x, summable (λ y, f ⟨x, y⟩)) ∧ summable (λ x, ∑' y, f ⟨x, y⟩) :=
by { lift f to (Σ x, β x) → ℝ≥0 using hf, exact_mod_cast nnreal.summable_sigma }
lemma summable_of_sum_le {ι : Type*} {f : ι → ℝ} {c : ℝ} (hf : 0 ≤ f)
(h : ∀ u : finset ι, ∑ x in u, f x ≤ c) :
summable f :=
⟨ ⨆ u : finset ι, ∑ x in u, f x,
tendsto_at_top_csupr (finset.sum_mono_set_of_nonneg hf) ⟨c, λ y ⟨u, hu⟩, hu ▸ h u⟩ ⟩
lemma summable_of_sum_range_le {f : ℕ → ℝ} {c : ℝ} (hf : ∀ n, 0 ≤ f n)
(h : ∀ n, ∑ i in finset.range n, f i ≤ c) : summable f :=
begin
apply (summable_iff_not_tendsto_nat_at_top_of_nonneg hf).2 (λ H, _),
rcases exists_lt_of_tendsto_at_top H 0 c with ⟨n, -, hn⟩,
exact lt_irrefl _ (hn.trans_le (h n)),
end
lemma tsum_le_of_sum_range_le {f : ℕ → ℝ} {c : ℝ} (hf : ∀ n, 0 ≤ f n)
(h : ∀ n, ∑ i in finset.range n, f i ≤ c) : ∑' n, f n ≤ c :=
le_of_tendsto' ((has_sum_iff_tendsto_nat_of_nonneg hf _).1
(summable_of_sum_range_le hf h).has_sum) h
/-- If a sequence `f` with non-negative terms is dominated by a sequence `g` with summable
series and at least one term of `f` is strictly smaller than the corresponding term in `g`,
then the series of `f` is strictly smaller than the series of `g`. -/
lemma tsum_lt_tsum_of_nonneg {i : ℕ} {f g : ℕ → ℝ}
(h0 : ∀ (b : ℕ), 0 ≤ f b) (h : ∀ (b : ℕ), f b ≤ g b) (hi : f i < g i) (hg : summable g) :
∑' n, f n < ∑' n, g n :=
tsum_lt_tsum h hi (summable_of_nonneg_of_le h0 h hg) hg
section
variables [emetric_space β]
open ennreal filter emetric
/-- In an emetric ball, the distance between points is everywhere finite -/
lemma edist_ne_top_of_mem_ball {a : β} {r : ℝ≥0∞} (x y : ball a r) : edist x.1 y.1 ≠ ⊤ :=
lt_top_iff_ne_top.1 $
calc edist x y ≤ edist a x + edist a y : edist_triangle_left x.1 y.1 a
... < r + r : by rw [edist_comm a x, edist_comm a y]; exact add_lt_add x.2 y.2
... ≤ ⊤ : le_top
/-- Each ball in an extended metric space gives us a metric space, as the edist
is everywhere finite. -/
def metric_space_emetric_ball (a : β) (r : ℝ≥0∞) : metric_space (ball a r) :=
emetric_space.to_metric_space edist_ne_top_of_mem_ball
local attribute [instance] metric_space_emetric_ball
lemma nhds_eq_nhds_emetric_ball (a x : β) (r : ℝ≥0∞) (h : x ∈ ball a r) :
𝓝 x = map (coe : ball a r → β) (𝓝 ⟨x, h⟩) :=
(map_nhds_subtype_coe_eq _ $ is_open.mem_nhds emetric.is_open_ball h).symm
end
section
variable [pseudo_emetric_space α]
open emetric
lemma tendsto_iff_edist_tendsto_0 {l : filter β} {f : β → α} {y : α} :
tendsto f l (𝓝 y) ↔ tendsto (λ x, edist (f x) y) l (𝓝 0) :=
by simp only [emetric.nhds_basis_eball.tendsto_right_iff, emetric.mem_ball,
@tendsto_order ℝ≥0∞ β _ _, forall_prop_of_false ennreal.not_lt_zero, forall_const, true_and]
/-- Yet another metric characterization of Cauchy sequences on integers. This one is often the
most efficient. -/
lemma emetric.cauchy_seq_iff_le_tendsto_0 [nonempty β] [semilattice_sup β] {s : β → α} :
cauchy_seq s ↔ (∃ (b: β → ℝ≥0∞), (∀ n m N : β, N ≤ n → N ≤ m → edist (s n) (s m) ≤ b N)
∧ (tendsto b at_top (𝓝 0))) :=
⟨begin
assume hs,
rw emetric.cauchy_seq_iff at hs,
/- `s` is Cauchy sequence. The sequence `b` will be constructed by taking
the supremum of the distances between `s n` and `s m` for `n m ≥ N`-/
let b := λN, Sup ((λ(p : β × β), edist (s p.1) (s p.2))''{p | p.1 ≥ N ∧ p.2 ≥ N}),
--Prove that it bounds the distances of points in the Cauchy sequence
have C : ∀ n m N, N ≤ n → N ≤ m → edist (s n) (s m) ≤ b N,
{ refine λm n N hm hn, le_Sup _,
use (prod.mk m n),
simp only [and_true, eq_self_iff_true, set.mem_set_of_eq],
exact ⟨hm, hn⟩ },
--Prove that it tends to `0`, by using the Cauchy property of `s`
have D : tendsto b at_top (𝓝 0),
{ refine tendsto_order.2 ⟨λa ha, absurd ha (ennreal.not_lt_zero), λε εpos, _⟩,
rcases exists_between εpos with ⟨δ, δpos, δlt⟩,
rcases hs δ δpos with ⟨N, hN⟩,
refine filter.mem_at_top_sets.2 ⟨N, λn hn, _⟩,
have : b n ≤ δ := Sup_le begin
simp only [and_imp, set.mem_image, set.mem_set_of_eq, exists_imp_distrib, prod.exists],
intros d p q hp hq hd,
rw ← hd,
exact le_of_lt (hN p q (le_trans hn hp) (le_trans hn hq))
end,
simpa using lt_of_le_of_lt this δlt },
-- Conclude
exact ⟨b, ⟨C, D⟩⟩
end,
begin
rintros ⟨b, ⟨b_bound, b_lim⟩⟩,
/-b : ℕ → ℝ, b_bound : ∀ (n m N : ℕ), N ≤ n → N ≤ m → edist (s n) (s m) ≤ b N,
b_lim : tendsto b at_top (𝓝 0)-/
refine emetric.cauchy_seq_iff.2 (λε εpos, _),
have : ∀ᶠ n in at_top, b n < ε := (tendsto_order.1 b_lim ).2 _ εpos,
rcases filter.mem_at_top_sets.1 this with ⟨N, hN⟩,
exact ⟨N, λm n hm hn, calc
edist (s m) (s n) ≤ b N : b_bound m n N hm hn
... < ε : (hN _ (le_refl N)) ⟩
end⟩
lemma continuous_of_le_add_edist {f : α → ℝ≥0∞} (C : ℝ≥0∞)
(hC : C ≠ ⊤) (h : ∀x y, f x ≤ f y + C * edist x y) : continuous f :=
begin
refine continuous_iff_continuous_at.2 (λx, tendsto_order.2 ⟨_, _⟩),
show ∀e, e < f x → ∀ᶠ y in 𝓝 x, e < f y,
{ assume e he,
let ε := min (f x - e) 1,
have : ε < ⊤ := lt_of_le_of_lt (min_le_right _ _) (by simp [lt_top_iff_ne_top]),
have : 0 < ε := by simp [ε, hC, he, ennreal.zero_lt_one],
have : 0 < C⁻¹ * (ε/2) := bot_lt_iff_ne_bot.2 (by simp [hC, (ne_of_lt this).symm, mul_eq_zero]),
have I : C * (C⁻¹ * (ε/2)) < ε,
{ by_cases C_zero : C = 0,
{ simp [C_zero, ‹0 < ε›] },
{ calc C * (C⁻¹ * (ε/2)) = (C * C⁻¹) * (ε/2) : by simp [mul_assoc]
... = ε/2 : by simp [ennreal.mul_inv_cancel C_zero hC]
... < ε : ennreal.half_lt_self (‹0 < ε›.ne') (‹ε < ⊤›.ne) }},
have : ball x (C⁻¹ * (ε/2)) ⊆ {y : α | e < f y},
{ rintros y hy,
by_cases htop : f y = ⊤,
{ simp [htop, lt_top_iff_ne_top, ne_top_of_lt he] },
{ simp at hy,
have : e + ε < f y + ε := calc
e + ε ≤ e + (f x - e) : add_le_add_left (min_le_left _ _) _
... = f x : by simp [le_of_lt he]
... ≤ f y + C * edist x y : h x y
... = f y + C * edist y x : by simp [edist_comm]
... ≤ f y + C * (C⁻¹ * (ε/2)) :
add_le_add_left (mul_le_mul_left' (le_of_lt hy) _) _
... < f y + ε : (ennreal.add_lt_add_iff_left (lt_top_iff_ne_top.2 htop)).2 I,
show e < f y, from
(ennreal.add_lt_add_iff_right ‹ε < ⊤›).1 this }},
apply filter.mem_of_superset (ball_mem_nhds _ (‹0 < C⁻¹ * (ε/2)›)) this },
show ∀e, f x < e → ∀ᶠ y in 𝓝 x, f y < e,
{ assume e he,
let ε := min (e - f x) 1,
have : ε < ⊤ := lt_of_le_of_lt (min_le_right _ _) (by simp [lt_top_iff_ne_top]),
have : 0 < ε := by simp [ε, he, ennreal.zero_lt_one],
have : 0 < C⁻¹ * (ε/2) := bot_lt_iff_ne_bot.2 (by simp [hC, (ne_of_lt this).symm, mul_eq_zero]),
have I : C * (C⁻¹ * (ε/2)) < ε,
{ by_cases C_zero : C = 0,
simp [C_zero, ‹0 < ε›],
calc C * (C⁻¹ * (ε/2)) = (C * C⁻¹) * (ε/2) : by simp [mul_assoc]
... = ε/2 : by simp [ennreal.mul_inv_cancel C_zero hC]
... < ε : ennreal.half_lt_self (‹0 < ε›.ne') (‹ε < ⊤›.ne) },
have : ball x (C⁻¹ * (ε/2)) ⊆ {y : α | f y < e},
{ rintros y hy,
have htop : f x ≠ ⊤ := ne_top_of_lt he,
show f y < e, from calc
f y ≤ f x + C * edist y x : h y x
... ≤ f x + C * (C⁻¹ * (ε/2)) :
add_le_add_left (mul_le_mul_left' (le_of_lt hy) _) _
... < f x + ε : (ennreal.add_lt_add_iff_left (lt_top_iff_ne_top.2 htop)).2 I
... ≤ f x + (e - f x) : add_le_add_left (min_le_left _ _) _
... = e : by simp [le_of_lt he] },
apply filter.mem_of_superset (ball_mem_nhds _ (‹0 < C⁻¹ * (ε/2)›)) this },
end
theorem continuous_edist : continuous (λp:α×α, edist p.1 p.2) :=
begin
apply continuous_of_le_add_edist 2 (by norm_num),
rintros ⟨x, y⟩ ⟨x', y'⟩,
calc edist x y ≤ edist x x' + edist x' y' + edist y' y : edist_triangle4 _ _ _ _
... = edist x' y' + (edist x x' + edist y y') : by simp [edist_comm]; cc
... ≤ edist x' y' + (edist (x, y) (x', y') + edist (x, y) (x', y')) :
add_le_add_left (add_le_add (le_max_left _ _) (le_max_right _ _)) _
... = edist x' y' + 2 * edist (x, y) (x', y') : by rw [← mul_two, mul_comm]
end
theorem continuous.edist [topological_space β] {f g : β → α}
(hf : continuous f) (hg : continuous g) : continuous (λb, edist (f b) (g b)) :=
continuous_edist.comp (hf.prod_mk hg : _)
theorem filter.tendsto.edist {f g : β → α} {x : filter β} {a b : α}
(hf : tendsto f x (𝓝 a)) (hg : tendsto g x (𝓝 b)) :
tendsto (λx, edist (f x) (g x)) x (𝓝 (edist a b)) :=
(continuous_edist.tendsto (a, b)).comp (hf.prod_mk_nhds hg)
lemma cauchy_seq_of_edist_le_of_tsum_ne_top {f : ℕ → α} (d : ℕ → ℝ≥0∞)
(hf : ∀ n, edist (f n) (f n.succ) ≤ d n) (hd : tsum d ≠ ∞) :
cauchy_seq f :=
begin
lift d to (ℕ → nnreal) using (λ i, ennreal.ne_top_of_tsum_ne_top hd i),
rw ennreal.tsum_coe_ne_top_iff_summable at hd,
exact cauchy_seq_of_edist_le_of_summable d hf hd
end
lemma emetric.is_closed_ball {a : α} {r : ℝ≥0∞} : is_closed (closed_ball a r) :=
is_closed_le (continuous_id.edist continuous_const) continuous_const
@[simp] lemma emetric.diam_closure (s : set α) : diam (closure s) = diam s :=
begin
refine le_antisymm (diam_le $ λ x hx y hy, _) (diam_mono subset_closure),
have : edist x y ∈ closure (Iic (diam s)),
from map_mem_closure2 (@continuous_edist α _) hx hy (λ _ _, edist_le_diam_of_mem),
rwa closure_Iic at this
end
@[simp] lemma metric.diam_closure {α : Type*} [pseudo_metric_space α] (s : set α) :
metric.diam (closure s) = diam s :=
by simp only [metric.diam, emetric.diam_closure]
namespace real
/-- For a bounded set `s : set ℝ`, its `emetric.diam` is equal to `Sup s - Inf s` reinterpreted as
`ℝ≥0∞`. -/
lemma ediam_eq {s : set ℝ} (h : bounded s) :
emetric.diam s = ennreal.of_real (Sup s - Inf s) :=
begin
rcases eq_empty_or_nonempty s with rfl|hne, { simp },
refine le_antisymm (metric.ediam_le_of_forall_dist_le $ λ x hx y hy, _) _,
{ have := real.subset_Icc_Inf_Sup_of_bounded h,
exact real.dist_le_of_mem_Icc (this hx) (this hy) },
{ apply ennreal.of_real_le_of_le_to_real,
rw [← metric.diam, ← metric.diam_closure],
have h' := real.bounded_iff_bdd_below_bdd_above.1 h,
calc Sup s - Inf s ≤ dist (Sup s) (Inf s) : le_abs_self _
... ≤ diam (closure s) :
dist_le_diam_of_mem h.closure (cSup_mem_closure hne h'.2) (cInf_mem_closure hne h'.1) }
end
/-- For a bounded set `s : set ℝ`, its `metric.diam` is equal to `Sup s - Inf s`. -/
lemma diam_eq {s : set ℝ} (h : bounded s) : metric.diam s = Sup s - Inf s :=
begin
rw [metric.diam, real.ediam_eq h, ennreal.to_real_of_real],
rw real.bounded_iff_bdd_below_bdd_above at h,
exact sub_nonneg.2 (real.Inf_le_Sup s h.1 h.2)
end
@[simp] lemma ediam_Ioo (a b : ℝ) :
emetric.diam (Ioo a b) = ennreal.of_real (b - a) :=
begin
rcases le_or_lt b a with h|h,
{ simp [h] },
{ rw [real.ediam_eq (bounded_Ioo _ _), cSup_Ioo h, cInf_Ioo h] },
end
@[simp] lemma ediam_Icc (a b : ℝ) :
emetric.diam (Icc a b) = ennreal.of_real (b - a) :=
begin
rcases le_or_lt a b with h|h,
{ rw [real.ediam_eq (bounded_Icc _ _), cSup_Icc h, cInf_Icc h] },
{ simp [h, h.le] }
end
@[simp] lemma ediam_Ico (a b : ℝ) :
emetric.diam (Ico a b) = ennreal.of_real (b - a) :=
le_antisymm (ediam_Icc a b ▸ diam_mono Ico_subset_Icc_self)
(ediam_Ioo a b ▸ diam_mono Ioo_subset_Ico_self)
@[simp] lemma ediam_Ioc (a b : ℝ) :
emetric.diam (Ioc a b) = ennreal.of_real (b - a) :=
le_antisymm (ediam_Icc a b ▸ diam_mono Ioc_subset_Icc_self)
(ediam_Ioo a b ▸ diam_mono Ioo_subset_Ioc_self)
end real
/-- If `edist (f n) (f (n+1))` is bounded above by a function `d : ℕ → ℝ≥0∞`,
then the distance from `f n` to the limit is bounded by `∑'_{k=n}^∞ d k`. -/
lemma edist_le_tsum_of_edist_le_of_tendsto {f : ℕ → α} (d : ℕ → ℝ≥0∞)
(hf : ∀ n, edist (f n) (f n.succ) ≤ d n)
{a : α} (ha : tendsto f at_top (𝓝 a)) (n : ℕ) :
edist (f n) a ≤ ∑' m, d (n + m) :=
begin
refine le_of_tendsto (tendsto_const_nhds.edist ha)
(mem_at_top_sets.2 ⟨n, λ m hnm, _⟩),
refine le_trans (edist_le_Ico_sum_of_edist_le hnm (λ k _ _, hf k)) _,
rw [finset.sum_Ico_eq_sum_range],
exact sum_le_tsum _ (λ _ _, zero_le _) ennreal.summable
end
/-- If `edist (f n) (f (n+1))` is bounded above by a function `d : ℕ → ℝ≥0∞`,
then the distance from `f 0` to the limit is bounded by `∑'_{k=0}^∞ d k`. -/
lemma edist_le_tsum_of_edist_le_of_tendsto₀ {f : ℕ → α} (d : ℕ → ℝ≥0∞)
(hf : ∀ n, edist (f n) (f n.succ) ≤ d n)
{a : α} (ha : tendsto f at_top (𝓝 a)) :
edist (f 0) a ≤ ∑' m, d m :=
by simpa using edist_le_tsum_of_edist_le_of_tendsto d hf ha 0
end --section
|
a7a034cc4ef9498878d175466b6d238200be7a6a | 367134ba5a65885e863bdc4507601606690974c1 | /src/algebra/lie/ideal_operations.lean | 4c84ac9b87e211da9543b458ca30748c6ad0b202 | [
"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 | 11,307 | lean | /-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import algebra.lie.submodule
/-!
# Ideal operations for Lie algebras
Given a Lie module `M` over a Lie algebra `L`, there is a natural action of the Lie ideals of `L`
on the Lie submodules of `M`. In the special case that `M = L` with the adjoint action, this
provides a pairing of Lie ideals which is especially important. For example, it can be used to
define solvability / nilpotency of a Lie algebra via the derived / lower-central series.
## Main definitions
* `lie_submodule.has_bracket`
* `lie_submodule.lie_ideal_oper_eq_linear_span`
* `lie_ideal.map_bracket_le`
* `lie_ideal.comap_bracket_le`
## Notation
Given a Lie module `M` over a Lie algebra `L`, together with a Lie submodule `N ⊆ M` and a Lie
ideal `I ⊆ L`, we introduce the notation `⁅I, N⁆` for the Lie submodule of `M` corresponding to
the action defined in this file.
## Tags
lie algebra, ideal operation
-/
universes u v w w₁ w₂
namespace lie_submodule
variables {R : Type u} {L : Type v} {M : Type w}
variables [comm_ring R] [lie_ring L] [lie_algebra R L] [add_comm_group M] [module R M]
variables [lie_ring_module L M] [lie_module R L M]
variables (N N' : lie_submodule R L M) (I J : lie_ideal R L)
section lie_ideal_operations
/-- Given a Lie module `M` over a Lie algebra `L`, the set of Lie ideals of `L` acts on the set
of submodules of `M`. -/
instance has_bracket : has_bracket (lie_ideal R L) (lie_submodule R L M) :=
⟨λ I N, lie_span R L { m | ∃ (x : I) (n : N), ⁅(x : L), (n : M)⁆ = m }⟩
lemma lie_ideal_oper_eq_span :
⁅I, N⁆ = lie_span R L { m | ∃ (x : I) (n : N), ⁅(x : L), (n : M)⁆ = m } := rfl
lemma lie_ideal_oper_eq_linear_span :
(↑⁅I, N⁆ : submodule R M) = submodule.span R { m | ∃ (x : I) (n : N), ⁅(x : L), (n : M)⁆ = m } :=
begin
apply le_antisymm,
{ let s := {m : M | ∃ (x : ↥I) (n : ↥N), ⁅(x : L), (n : M)⁆ = m},
have aux : ∀ (y : L) (m' ∈ submodule.span R s), ⁅y, m'⁆ ∈ submodule.span R s,
{ intros y m' hm', apply submodule.span_induction hm',
{ rintros m'' ⟨x, n, hm''⟩, rw [← hm'', leibniz_lie],
refine submodule.add_mem _ _ _; apply submodule.subset_span,
{ use [⟨⁅y, ↑x⁆, I.lie_mem x.property⟩, n], refl, },
{ use [x, ⟨⁅y, ↑n⁆, N.lie_mem n.property⟩], refl, }, },
{ simp only [lie_zero, submodule.zero_mem], },
{ intros m₁ m₂ hm₁ hm₂, rw lie_add, exact submodule.add_mem _ hm₁ hm₂, },
{ intros t m'' hm'', rw lie_smul, exact submodule.smul_mem _ t hm'', }, },
change _ ≤ ↑({ lie_mem := aux, ..submodule.span R s } : lie_submodule R L M),
rw [coe_submodule_le_coe_submodule, lie_ideal_oper_eq_span, lie_span_le],
exact submodule.subset_span, },
{ rw lie_ideal_oper_eq_span, apply submodule_span_le_lie_span, },
end
lemma lie_mem_lie (x : I) (m : N) : ⁅(x : L), (m : M)⁆ ∈ ⁅I, N⁆ :=
by { rw lie_ideal_oper_eq_span, apply subset_lie_span, use [x, m], }
lemma lie_comm : ⁅I, J⁆ = ⁅J, I⁆ :=
begin
suffices : ∀ (I J : lie_ideal R L), ⁅I, J⁆ ≤ ⁅J, I⁆, { exact le_antisymm (this I J) (this J I), },
clear I J, intros I J,
rw [lie_ideal_oper_eq_span, lie_span_le], rintros x ⟨y, z, h⟩, rw ← h,
rw [← lie_skew, ← lie_neg, ← submodule.coe_neg],
apply lie_mem_lie,
end
lemma lie_le_right : ⁅I, N⁆ ≤ N :=
begin
rw [lie_ideal_oper_eq_span, lie_span_le], rintros m ⟨x, n, hn⟩, rw ← hn,
exact N.lie_mem n.property,
end
lemma lie_le_left : ⁅I, J⁆ ≤ I :=
by { rw lie_comm, exact lie_le_right I J, }
lemma lie_le_inf : ⁅I, J⁆ ≤ I ⊓ J :=
by { rw le_inf_iff, exact ⟨lie_le_left I J, lie_le_right J I⟩, }
@[simp] lemma lie_bot : ⁅I, (⊥ : lie_submodule R L M)⁆ = ⊥ :=
by { rw eq_bot_iff, apply lie_le_right, }
@[simp] lemma bot_lie : ⁅(⊥ : lie_ideal R L), N⁆ = ⊥ :=
begin
suffices : ⁅(⊥ : lie_ideal R L), N⁆ ≤ ⊥, { exact le_bot_iff.mp this, },
rw [lie_ideal_oper_eq_span, lie_span_le], rintros m ⟨⟨x, hx⟩, n, hn⟩, rw ← hn,
change x ∈ (⊥ : lie_ideal R L) at hx, rw mem_bot at hx, simp [hx],
end
lemma mono_lie (h₁ : I ≤ J) (h₂ : N ≤ N') : ⁅I, N⁆ ≤ ⁅J, N'⁆ :=
begin
intros m h,
rw [lie_ideal_oper_eq_span, mem_lie_span] at h, rw [lie_ideal_oper_eq_span, mem_lie_span],
intros N hN, apply h, rintros m' ⟨⟨x, hx⟩, ⟨n, hn⟩, hm⟩, rw ← hm, apply hN,
use [⟨x, h₁ hx⟩, ⟨n, h₂ hn⟩], refl,
end
lemma mono_lie_left (h : I ≤ J) : ⁅I, N⁆ ≤ ⁅J, N⁆ := mono_lie _ _ _ _ h (le_refl N)
lemma mono_lie_right (h : N ≤ N') : ⁅I, N⁆ ≤ ⁅I, N'⁆ := mono_lie _ _ _ _ (le_refl I) h
@[simp] lemma lie_sup : ⁅I, N ⊔ N'⁆ = ⁅I, N⁆ ⊔ ⁅I, N'⁆ :=
begin
have h : ⁅I, N⁆ ⊔ ⁅I, N'⁆ ≤ ⁅I, N ⊔ N'⁆,
{ rw sup_le_iff, split; apply mono_lie_right; [exact le_sup_left, exact le_sup_right], },
suffices : ⁅I, N ⊔ N'⁆ ≤ ⁅I, N⁆ ⊔ ⁅I, N'⁆, { exact le_antisymm this h, }, clear h,
rw [lie_ideal_oper_eq_span, lie_span_le], rintros m ⟨x, ⟨n, hn⟩, h⟩, erw lie_submodule.mem_sup,
erw lie_submodule.mem_sup at hn, rcases hn with ⟨n₁, hn₁, n₂, hn₂, hn'⟩,
use ⁅(x : L), (⟨n₁, hn₁⟩ : N)⁆, split, { apply lie_mem_lie, },
use ⁅(x : L), (⟨n₂, hn₂⟩ : N')⁆, split, { apply lie_mem_lie, },
simp [← h, ← hn'],
end
@[simp] lemma sup_lie : ⁅I ⊔ J, N⁆ = ⁅I, N⁆ ⊔ ⁅J, N⁆ :=
begin
have h : ⁅I, N⁆ ⊔ ⁅J, N⁆ ≤ ⁅I ⊔ J, N⁆,
{ rw sup_le_iff, split; apply mono_lie_left; [exact le_sup_left, exact le_sup_right], },
suffices : ⁅I ⊔ J, N⁆ ≤ ⁅I, N⁆ ⊔ ⁅J, N⁆, { exact le_antisymm this h, }, clear h,
rw [lie_ideal_oper_eq_span, lie_span_le], rintros m ⟨⟨x, hx⟩, n, h⟩, erw lie_submodule.mem_sup,
erw lie_submodule.mem_sup at hx, rcases hx with ⟨x₁, hx₁, x₂, hx₂, hx'⟩,
use ⁅((⟨x₁, hx₁⟩ : I) : L), (n : N)⁆, split, { apply lie_mem_lie, },
use ⁅((⟨x₂, hx₂⟩ : J) : L), (n : N)⁆, split, { apply lie_mem_lie, },
simp [← h, ← hx'],
end
@[simp] lemma lie_inf : ⁅I, N ⊓ N'⁆ ≤ ⁅I, N⁆ ⊓ ⁅I, N'⁆ :=
by { rw le_inf_iff, split; apply mono_lie_right; [exact inf_le_left, exact inf_le_right], }
@[simp] lemma inf_lie : ⁅I ⊓ J, N⁆ ≤ ⁅I, N⁆ ⊓ ⁅J, N⁆ :=
by { rw le_inf_iff, split; apply mono_lie_left; [exact inf_le_left, exact inf_le_right], }
end lie_ideal_operations
end lie_submodule
namespace lie_ideal
open lie_algebra
variables {R : Type u} {L : Type v} {L' : Type w₂}
variables [comm_ring R] [lie_ring L] [lie_algebra R L] [lie_ring L'] [lie_algebra R L']
variables (f : L →ₗ⁅R⁆ L') (I : lie_ideal R L) (J : lie_ideal R L')
/-- Note that the inequality can be strict; e.g., the inclusion of an Abelian subalgebra of a
simple algebra. -/
lemma map_bracket_le {I₁ I₂ : lie_ideal R L} : map f ⁅I₁, I₂⁆ ≤ ⁅map f I₁, map f I₂⁆ :=
begin
rw map_le_iff_le_comap, erw lie_submodule.lie_span_le,
intros x hx, obtain ⟨⟨y₁, hy₁⟩, ⟨y₂, hy₂⟩, hx⟩ := hx, rw ← hx,
let fy₁ : ↥(map f I₁) := ⟨f y₁, mem_map hy₁⟩,
let fy₂ : ↥(map f I₂) := ⟨f y₂, mem_map hy₂⟩,
change _ ∈ comap f ⁅map f I₁, map f I₂⁆,
simp only [submodule.coe_mk, mem_comap, lie_hom.map_lie],
exact lie_submodule.lie_mem_lie _ _ fy₁ fy₂,
end
lemma map_bracket_eq {I₁ I₂ : lie_ideal R L} (h : function.surjective f) :
map f ⁅I₁, I₂⁆ = ⁅map f I₁, map f I₂⁆ :=
begin
suffices : ⁅map f I₁, map f I₂⁆ ≤ map f ⁅I₁, I₂⁆, { exact le_antisymm (map_bracket_le f) this, },
rw [← lie_submodule.coe_submodule_le_coe_submodule, coe_map_of_surjective h,
lie_submodule.lie_ideal_oper_eq_linear_span,
lie_submodule.lie_ideal_oper_eq_linear_span, submodule.map_span],
apply submodule.span_mono,
rintros x ⟨⟨z₁, h₁⟩, ⟨z₂, h₂⟩, rfl⟩,
obtain ⟨y₁, rfl⟩ := mem_map_of_surjective h h₁,
obtain ⟨y₂, rfl⟩ := mem_map_of_surjective h h₂,
use [⁅(y₁ : L), (y₂ : L)⁆, y₁, y₂],
apply f.map_lie,
end
lemma comap_bracket_le {J₁ J₂ : lie_ideal R L'} : ⁅comap f J₁, comap f J₂⁆ ≤ comap f ⁅J₁, J₂⁆ :=
begin
rw ← map_le_iff_le_comap,
exact le_trans (map_bracket_le f) (lie_submodule.mono_lie _ _ _ _ map_comap_le map_comap_le),
end
variables {f}
lemma map_comap_incl {I₁ I₂ : lie_ideal R L} : map I₁.incl (comap I₁.incl I₂) = I₁ ⊓ I₂ :=
by { conv_rhs { rw ← I₁.incl_ideal_range, }, rw ← map_comap_eq, exact I₁.incl_is_ideal_morphism, }
lemma comap_bracket_eq {J₁ J₂ : lie_ideal R L'} (h : f.is_ideal_morphism) :
comap f ⁅f.ideal_range ⊓ J₁, f.ideal_range ⊓ J₂⁆ = ⁅comap f J₁, comap f J₂⁆ ⊔ f.ker :=
begin
rw [← lie_submodule.coe_to_submodule_eq_iff, comap_coe_submodule,
lie_submodule.sup_coe_to_submodule, f.ker_coe_submodule, ← linear_map.comap_map_eq,
lie_submodule.lie_ideal_oper_eq_linear_span, lie_submodule.lie_ideal_oper_eq_linear_span,
submodule.map_span],
congr, simp only [lie_hom.coe_to_linear_map, set.mem_set_of_eq], ext y,
split,
{ rintros ⟨⟨x₁, hx₁⟩, ⟨x₂, hx₂⟩, hy⟩, rw ← hy,
erw [lie_submodule.mem_inf, f.mem_ideal_range_iff h] at hx₁ hx₂,
obtain ⟨⟨z₁, hz₁⟩, hz₁'⟩ := hx₁, rw ← hz₁ at hz₁',
obtain ⟨⟨z₂, hz₂⟩, hz₂'⟩ := hx₂, rw ← hz₂ at hz₂',
use [⁅z₁, z₂⁆, ⟨z₁, hz₁'⟩, ⟨z₂, hz₂'⟩, rfl],
simp only [hz₁, hz₂, submodule.coe_mk, lie_hom.map_lie], },
{ rintros ⟨x, ⟨⟨z₁, hz₁⟩, ⟨z₂, hz₂⟩, hx⟩, hy⟩, rw [← hy, ← hx],
have hz₁' : f z₁ ∈ f.ideal_range ⊓ J₁,
{ rw lie_submodule.mem_inf, exact ⟨f.mem_ideal_range, hz₁⟩, },
have hz₂' : f z₂ ∈ f.ideal_range ⊓ J₂,
{ rw lie_submodule.mem_inf, exact ⟨f.mem_ideal_range, hz₂⟩, },
use [⟨f z₁, hz₁'⟩, ⟨f z₂, hz₂'⟩], simp only [submodule.coe_mk, lie_hom.map_lie], },
end
lemma map_comap_bracket_eq {J₁ J₂ : lie_ideal R L'} (h : f.is_ideal_morphism) :
map f ⁅comap f J₁, comap f J₂⁆ = ⁅f.ideal_range ⊓ J₁, f.ideal_range ⊓ J₂⁆ :=
by { rw [← map_sup_ker_eq_map, ← comap_bracket_eq h, map_comap_eq h, inf_eq_right],
exact le_trans (lie_submodule.lie_le_left _ _) inf_le_left, }
lemma comap_bracket_incl {I₁ I₂ : lie_ideal R L} :
⁅comap I.incl I₁, comap I.incl I₂⁆ = comap I.incl ⁅I ⊓ I₁, I ⊓ I₂⁆ :=
begin
conv_rhs { congr, skip, rw ← I.incl_ideal_range, }, rw comap_bracket_eq,
simp only [ker_incl, sup_bot_eq], exact I.incl_is_ideal_morphism,
end
/-- This is a very useful result; it allows us to use the fact that inclusion distributes over the
Lie bracket operation on ideals, subject to the conditions shown. -/
lemma comap_bracket_incl_of_le {I₁ I₂ : lie_ideal R L} (h₁ : I₁ ≤ I) (h₂ : I₂ ≤ I) :
⁅comap I.incl I₁, comap I.incl I₂⁆ = comap I.incl ⁅I₁, I₂⁆ :=
by { rw comap_bracket_incl, rw ← inf_eq_right at h₁ h₂, rw [h₁, h₂], }
end lie_ideal
|
962728f23eb788f2ff69563a2ec7ff28a7415c95 | 46125763b4dbf50619e8846a1371029346f4c3db | /src/data/set/countable.lean | 26b62d263714161cec046c099f3465d0ae181e4a | [
"Apache-2.0"
] | permissive | thjread/mathlib | a9d97612cedc2c3101060737233df15abcdb9eb1 | 7cffe2520a5518bba19227a107078d83fa725ddc | refs/heads/master | 1,615,637,696,376 | 1,583,953,063,000 | 1,583,953,063,000 | 246,680,271 | 0 | 0 | Apache-2.0 | 1,583,960,875,000 | 1,583,960,875,000 | null | UTF-8 | Lean | false | false | 8,080 | 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
Countable sets.
-/
import data.equiv.list data.set.finite logic.function data.set.function
noncomputable theory
open function set encodable
open classical (hiding some)
open_locale classical
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
namespace set
/-- Countable sets
A set is countable if there exists an encoding of the set into the natural numbers.
An encoding is an injection with a partial inverse, which can be viewed as a
constructive analogue of countability. (For the most part, theorems about
`countable` will be classical and `encodable` will be constructive.)
-/
def countable (s : set α) : Prop := nonempty (encodable s)
lemma countable_iff_exists_injective {s : set α} :
countable s ↔ ∃f:s → ℕ, injective f :=
⟨λ ⟨h⟩, by exactI ⟨encode, encode_injective⟩,
λ ⟨f, h⟩, ⟨⟨f, partial_inv f, partial_inv_left h⟩⟩⟩
lemma countable_iff_exists_inj_on {s : set α} :
countable s ↔ ∃ f : α → ℕ, inj_on f s :=
countable_iff_exists_injective.trans
⟨λ ⟨f, hf⟩, ⟨λ a, if h : a ∈ s then f ⟨a, h⟩ else 0,
λ a b as bs h, congr_arg subtype.val $
hf $ by simpa [as, bs] using h⟩,
λ ⟨f, hf⟩, ⟨_, inj_on_iff_injective.1 hf⟩⟩
lemma countable_iff_exists_surjective [ne : nonempty α] {s : set α} :
countable s ↔ ∃f:ℕ → α, s ⊆ range f :=
⟨λ ⟨h⟩, by inhabit α; exactI ⟨λ n, ((decode s n).map subtype.val).iget,
λ a as, ⟨encode (⟨a, as⟩ : s), by simp [encodek]⟩⟩,
λ ⟨f, hf⟩, ⟨⟨
λ x, inv_fun f x.1,
λ n, if h : f n ∈ s then some ⟨f n, h⟩ else none,
λ ⟨x, hx⟩, begin
have := inv_fun_eq (hf hx), dsimp at this ⊢,
simp [this, hx]
end⟩⟩⟩
/--
A non-empty set is countable iff there exists a surjection from the
natural numbers onto the subtype induced by the set.
-/
lemma countable_iff_exists_surjective_to_subtype {s : set α} (hs : s.nonempty) :
countable s ↔ ∃ f : ℕ → s, surjective f :=
have inhabited s, from ⟨classical.choice hs.to_subtype⟩,
have countable s → ∃ f : ℕ → s, surjective f, from assume ⟨h⟩,
by exactI ⟨λ n, (decode s n).iget, λ a, ⟨encode a, by simp [encodek]⟩⟩,
have (∃ f : ℕ → s, surjective f) → countable s, from assume ⟨f, fsurj⟩,
⟨⟨inv_fun f, option.some ∘ f,
by intro h; simp [(inv_fun_eq (fsurj h) : f (inv_fun f h) = h)]⟩⟩,
by split; assumption
def countable.to_encodable {s : set α} : countable s → encodable s :=
classical.choice
lemma countable_encodable' (s : set α) [H : encodable s] : countable s :=
⟨H⟩
lemma countable_encodable [encodable α] (s : set α) : countable s :=
⟨by apply_instance⟩
lemma exists_surjective_of_countable {s : set α} (hs : s.nonempty) (hc : countable s) :
∃f:ℕ → α, s = range f :=
begin
rcases hs with ⟨x, hx⟩,
letI : encodable s := countable.to_encodable hc,
letI : inhabited s := ⟨⟨x, hx⟩⟩,
have : countable (univ : set s) := countable_encodable _,
rcases countable_iff_exists_surjective.1 this with ⟨g, hg⟩,
have : range g = univ := univ_subset_iff.1 hg,
use subtype.val ∘ g,
rw [range_comp, this],
simp
end
@[simp] lemma countable_empty : countable (∅ : set α) :=
⟨⟨λ x, x.2.elim, λ n, none, λ x, x.2.elim⟩⟩
@[simp] lemma countable_singleton (a : α) : countable ({a} : set α) :=
⟨of_equiv _ (equiv.set.singleton a)⟩
lemma countable_subset {s₁ s₂ : set α} (h : s₁ ⊆ s₂) : countable s₂ → countable s₁
| ⟨H⟩ := ⟨@of_inj _ _ H _ (embedding_of_subset h).2⟩
lemma countable_image {s : set α} (f : α → β) (hs : countable s) : countable (f '' s) :=
let f' : s → f '' s := λ⟨a, ha⟩, ⟨f a, mem_image_of_mem f ha⟩ in
have hf' : surjective f', from assume ⟨b, a, ha, hab⟩, ⟨⟨a, ha⟩, subtype.eq hab⟩,
⟨@encodable.of_inj _ _ hs.to_encodable (surj_inv hf') (injective_surj_inv hf')⟩
lemma countable_range [encodable α] (f : α → β) : countable (range f) :=
by rw ← image_univ; exact countable_image _ (countable_encodable _)
lemma countable_of_injective_of_countable_image {s : set α} {f : α → β}
(hf : inj_on f s) (hs : countable (f '' s)) : countable s :=
let ⟨g, hg⟩ := countable_iff_exists_inj_on.1 hs in
countable_iff_exists_inj_on.2 ⟨g ∘ f, hg.comp hf (maps_to_image _ _)⟩
lemma countable_Union {t : α → set β} [encodable α] (ht : ∀a, countable (t a)) :
countable (⋃a, t a) :=
by haveI := (λ a, (ht a).to_encodable);
rw Union_eq_range_sigma; apply countable_range
lemma countable_bUnion {s : set α} {t : α → set β} (hs : countable s) (ht : ∀a∈s, countable (t a)) :
countable (⋃a∈s, t a) :=
begin
rw bUnion_eq_Union,
haveI := hs.to_encodable,
exact countable_Union (by simpa using ht)
end
lemma countable_sUnion {s : set (set α)} (hs : countable s) (h : ∀a∈s, countable a) :
countable (⋃₀ s) :=
by rw sUnion_eq_bUnion; exact countable_bUnion hs h
lemma countable_Union_Prop {p : Prop} {t : p → set β} (ht : ∀h:p, countable (t h)) :
countable (⋃h:p, t h) :=
by by_cases p; simp [h, ht]
lemma countable_union {s₁ s₂ : set α} (h₁ : countable s₁) (h₂ : countable s₂) : countable (s₁ ∪ s₂) :=
by rw union_eq_Union; exact
countable_Union (bool.forall_bool.2 ⟨h₂, h₁⟩)
lemma countable_insert {s : set α} {a : α} (h : countable s) : countable (insert a s) :=
by rw [set.insert_eq]; from countable_union (countable_singleton _) h
lemma countable_finite {s : set α} : finite s → countable s
| ⟨h⟩ := nonempty_of_trunc (by exactI trunc_encodable_of_fintype s)
lemma countable_set_of_finite_subset {s : set α} : countable s →
countable {t | finite t ∧ t ⊆ s} | ⟨h⟩ :=
begin
resetI,
refine countable_subset _ (countable_range
(λ t : finset s, {a | ∃ h:a ∈ s, subtype.mk a h ∈ t})),
rintro t ⟨⟨ht⟩, ts⟩,
refine ⟨finset.univ.map (embedding_of_subset ts),
set.ext $ λ a, _⟩,
simp, split,
{ rintro ⟨as, b, bt, e⟩,
cases congr_arg subtype.val e, exact bt },
{ exact λ h, ⟨ts h, _, h, rfl⟩ }
end
lemma countable_pi {π : α → Type*} [fintype α] {s : Πa, set (π a)} (hs : ∀a, countable (s a)) :
countable {f : Πa, π a | ∀a, f a ∈ s a} :=
countable_subset
(show {f : Πa, π a | ∀a, f a ∈ s a} ⊆ range (λf : Πa, s a, λa, (f a).1), from
assume f hf, ⟨λa, ⟨f a, hf a⟩, funext $ assume a, rfl⟩) $
have trunc (encodable (Π (a : α), s a)), from
@encodable.fintype_pi α _ _ _ (assume a, (hs a).to_encodable),
trunc.induction_on this $ assume h,
@countable_range _ _ h _
lemma countable_prod {s : set α} {t : set β} (hs : countable s) (ht : countable t) :
countable (set.prod s t) :=
begin
haveI : encodable s := hs.to_encodable,
haveI : encodable t := ht.to_encodable,
haveI : encodable (s × t) := by apply_instance,
have : range (λp, ⟨p.1, p.2⟩ : s × t → α × β) = set.prod s t,
{ ext z,
rcases z with ⟨x, y⟩,
simp only [exists_prop, set.mem_range, set_coe.exists, prod.mk.inj_iff,
set.prod_mk_mem_set_prod_eq, subtype.coe_mk, prod.exists],
split,
{ rintros ⟨x', x's, y', y't, x'x, y'y⟩,
simp [x'x.symm, y'y.symm, x's, y't] },
{ rintros ⟨xs, yt⟩,
exact ⟨x, xs, y, yt, rfl, rfl⟩ }},
rw ← this,
exact countable_range _
end
section enumerate
/-- Enumerate elements in a countable set.-/
def enumerate_countable {s : set α} (h : countable s) (default : α) : ℕ → α :=
assume n, match @encodable.decode s (h.to_encodable) n with
| (some y) := y
| (none) := default
end
lemma subset_range_enumerate {s : set α} (h : countable s) (default : α) :
s ⊆ range (enumerate_countable h default) :=
assume x hx,
⟨@encodable.encode s h.to_encodable ⟨x, hx⟩,
by simp [enumerate_countable, encodable.encodek]⟩
end enumerate
end set
|
6b0f4374d8d52bcd1ef860e064a90d3e7b1c38f3 | 57fdc8de88f5ea3bfde4325e6ecd13f93a274ab5 | /analysis/topology/topological_space.lean | 19ea74ba50cc5f5e253190fd8566de28af95c446 | [
"Apache-2.0"
] | permissive | louisanu/mathlib | 11f56f2d40dc792bc05ee2f78ea37d73e98ecbfe | 2bd5e2159d20a8f20d04fc4d382e65eea775ed39 | refs/heads/master | 1,617,706,993,439 | 1,523,163,654,000 | 1,523,163,654,000 | 124,519,997 | 0 | 0 | Apache-2.0 | 1,520,588,283,000 | 1,520,588,283,000 | null | UTF-8 | Lean | false | false | 50,473 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
Theory of topological spaces.
Parts of the formalization is based on the books:
N. Bourbaki: General Topology
I. M. James: Topologies and Uniformities
A major difference is that this formalization is heavily based on the filter library.
-/
import order.filter data.set.countable tactic
open set filter lattice classical
local attribute [instance] prop_decidable
universes u v w
structure topological_space (α : Type u) :=
(is_open : set α → Prop)
(is_open_univ : is_open univ)
(is_open_inter : ∀s t, is_open s → is_open t → is_open (s ∩ t))
(is_open_sUnion : ∀s, (∀t∈s, is_open t) → is_open (⋃₀ s))
attribute [class] topological_space
section topological_space
variables {α : Type u} {β : Type v} {ι : Sort w} {a a₁ a₂ : α} {s s₁ s₂ : set α} {p p₁ p₂ : α → Prop}
lemma topological_space_eq : ∀ {f g : topological_space α}, f.is_open = g.is_open → f = g
| ⟨a, _, _, _⟩ ⟨b, _, _, _⟩ rfl := rfl
section
variables [t : topological_space α]
include t
/-- `is_open s` means that `s` is open in the ambient topological space on `α` -/
def is_open (s : set α) : Prop := topological_space.is_open t s
@[simp]
lemma is_open_univ : is_open (univ : set α) := topological_space.is_open_univ t
lemma is_open_inter (h₁ : is_open s₁) (h₂ : is_open s₂) : is_open (s₁ ∩ s₂) :=
topological_space.is_open_inter t s₁ s₂ h₁ h₂
lemma is_open_sUnion {s : set (set α)} (h : ∀t ∈ s, is_open t) : is_open (⋃₀ s) :=
topological_space.is_open_sUnion t s h
end
variables [topological_space α]
lemma is_open_union (h₁ : is_open s₁) (h₂ : is_open s₂) : is_open (s₁ ∪ s₂) :=
have (⋃₀ {s₁, s₂}) = (s₁ ∪ s₂), by simp [union_comm],
this ▸ is_open_sUnion $ show ∀(t : set α), t ∈ ({s₁, s₂} : set (set α)) → is_open t,
by finish
lemma is_open_Union {f : ι → set α} (h : ∀i, is_open (f i)) : is_open (⋃i, f i) :=
is_open_sUnion $ assume t ⟨i, (heq : t = f i)⟩, heq.symm ▸ h i
@[simp] lemma is_open_empty : is_open (∅ : set α) :=
have is_open (⋃₀ ∅ : set α), from is_open_sUnion (assume a, false.elim),
by simp at this; assumption
lemma is_open_sInter {s : set (set α)} (hs : finite s) : (∀t ∈ s, is_open t) → is_open (⋂₀ s) :=
finite.induction_on hs (by simp) $ λ a s has hs ih h, begin
suffices : is_open (a ∩ ⋂₀ s), { simpa },
exact is_open_inter (h _ $ mem_insert _ _) (ih $ assume t ht, h _ $ mem_insert_of_mem _ ht)
end
lemma is_open_const {p : Prop} : is_open {a : α | p} :=
by_cases
(assume : p, begin simp [*]; exact is_open_univ end)
(assume : ¬ p, begin simp [*]; exact is_open_empty end)
lemma is_open_and : is_open {a | p₁ a} → is_open {a | p₂ a} → is_open {a | p₁ a ∧ p₂ a} :=
is_open_inter
/-- A set is closed if its complement is open -/
def is_closed (s : set α) : Prop := is_open (-s)
@[simp] lemma is_closed_empty : is_closed (∅ : set α) := by simp [is_closed]
@[simp] lemma is_closed_univ : is_closed (univ : set α) := by simp [is_closed]
lemma is_closed_union : is_closed s₁ → is_closed s₂ → is_closed (s₁ ∪ s₂) :=
by simp [is_closed]; exact is_open_inter
lemma is_closed_sInter {s : set (set α)} : (∀t ∈ s, is_closed t) → is_closed (⋂₀ s) :=
by simp [is_closed, compl_sInter]; exact assume h, is_open_Union $ assume t, is_open_Union $ assume ht, h t ht
lemma is_closed_Inter {f : ι → set α} (h : ∀i, is_closed (f i)) : is_closed (⋂i, f i ) :=
is_closed_sInter $ assume t ⟨i, (heq : t = f i)⟩, heq.symm ▸ h i
@[simp] lemma is_open_compl_iff {s : set α} : is_open (-s) ↔ is_closed s := iff.rfl
@[simp] lemma is_closed_compl_iff {s : set α} : is_closed (-s) ↔ is_open s :=
by rw [←is_open_compl_iff, compl_compl]
lemma is_open_diff {s t : set α} (h₁ : is_open s) (h₂ : is_closed t) : is_open (s - t) :=
is_open_inter h₁ $ is_open_compl_iff.mpr h₂
lemma is_closed_inter (h₁ : is_closed s₁) (h₂ : is_closed s₂) : is_closed (s₁ ∩ s₂) :=
by rw [is_closed, compl_inter]; exact is_open_union h₁ h₂
lemma is_closed_Union {s : set β} {f : β → set α} (hs : finite s) :
(∀i∈s, is_closed (f i)) → is_closed (⋃i∈s, f i) :=
finite.induction_on hs
(by simp)
(by simp [or_imp_distrib, is_closed_union, forall_and_distrib] {contextual := tt})
lemma is_closed_imp [topological_space α] {p q : α → Prop}
(hp : is_open {x | p x}) (hq : is_closed {x | q x}) : is_closed {x | p x → q x} :=
have {x | p x → q x} = (- {x | p x}) ∪ {x | q x}, from set.ext $ by finish,
by rw [this]; exact is_closed_union (is_closed_compl_iff.mpr hp) hq
lemma is_open_neg : is_closed {a | p a} → is_open {a | ¬ p a} :=
is_open_compl_iff.mpr
/-- The interior of a set `s` is the largest open subset of `s`. -/
def interior (s : set α) : set α := ⋃₀ {t | is_open t ∧ t ⊆ s}
lemma mem_interior {s : set α} {x : α} :
x ∈ interior s ↔ ∃ t ⊆ s, is_open t ∧ x ∈ t :=
by simp [interior, and_comm, and.left_comm]
@[simp] lemma is_open_interior {s : set α} : is_open (interior s) :=
is_open_sUnion $ assume t ⟨h₁, h₂⟩, h₁
lemma interior_subset {s : set α} : interior s ⊆ s :=
sUnion_subset $ assume t ⟨h₁, h₂⟩, h₂
lemma interior_maximal {s t : set α} (h₁ : t ⊆ s) (h₂ : is_open t) : t ⊆ interior s :=
subset_sUnion_of_mem ⟨h₂, h₁⟩
lemma interior_eq_of_open {s : set α} (h : is_open s) : interior s = s :=
subset.antisymm interior_subset (interior_maximal (subset.refl s) h)
lemma interior_eq_iff_open {s : set α} : interior s = s ↔ is_open s :=
⟨assume h, h ▸ is_open_interior, interior_eq_of_open⟩
lemma subset_interior_iff_open {s : set α} : s ⊆ interior s ↔ is_open s :=
by simp [interior_eq_iff_open.symm, subset.antisymm_iff, interior_subset]
lemma subset_interior_iff_subset_of_open {s t : set α} (h₁ : is_open s) :
s ⊆ interior t ↔ s ⊆ t :=
⟨assume h, subset.trans h interior_subset, assume h₂, interior_maximal h₂ h₁⟩
lemma interior_mono {s t : set α} (h : s ⊆ t) : interior s ⊆ interior t :=
interior_maximal (subset.trans interior_subset h) is_open_interior
@[simp] lemma interior_empty : interior (∅ : set α) = ∅ :=
interior_eq_of_open is_open_empty
@[simp] lemma interior_univ : interior (univ : set α) = univ :=
interior_eq_of_open is_open_univ
@[simp] lemma interior_interior {s : set α} : interior (interior s) = interior s :=
interior_eq_of_open is_open_interior
@[simp] lemma interior_inter {s t : set α} : interior (s ∩ t) = interior s ∩ interior t :=
subset.antisymm
(subset_inter (interior_mono $ inter_subset_left s t) (interior_mono $ inter_subset_right s t))
(interior_maximal (inter_subset_inter interior_subset interior_subset) $ by simp [is_open_inter])
lemma interior_union_is_closed_of_interior_empty {s t : set α} (h₁ : is_closed s) (h₂ : interior t = ∅) :
interior (s ∪ t) = interior s :=
have interior (s ∪ t) ⊆ s, from
assume x ⟨u, ⟨(hu₁ : is_open u), (hu₂ : u ⊆ s ∪ t)⟩, (hx₁ : x ∈ u)⟩,
classical.by_contradiction $ assume hx₂ : x ∉ s,
have u - s ⊆ t,
from assume x ⟨h₁, h₂⟩, or.resolve_left (hu₂ h₁) h₂,
have u - s ⊆ interior t,
by simp [subset_interior_iff_subset_of_open, this, is_open_diff hu₁ h₁],
have u - s ⊆ ∅,
by rw [h₂] at this; assumption,
this ⟨hx₁, hx₂⟩,
subset.antisymm
(interior_maximal this is_open_interior)
(interior_mono $ subset_union_left _ _)
lemma is_open_iff_forall_mem_open : is_open s ↔ ∀ x ∈ s, ∃ t ⊆ s, is_open t ∧ x ∈ t :=
by rw ← subset_interior_iff_open; simp [subset_def, mem_interior]
/-- The closure of `s` is the smallest closed set containing `s`. -/
def closure (s : set α) : set α := ⋂₀ {t | is_closed t ∧ s ⊆ t}
@[simp] lemma is_closed_closure {s : set α} : is_closed (closure s) :=
is_closed_sInter $ assume t ⟨h₁, h₂⟩, h₁
lemma subset_closure {s : set α} : s ⊆ closure s :=
subset_sInter $ assume t ⟨h₁, h₂⟩, h₂
lemma closure_minimal {s t : set α} (h₁ : s ⊆ t) (h₂ : is_closed t) : closure s ⊆ t :=
sInter_subset_of_mem ⟨h₂, h₁⟩
lemma closure_eq_of_is_closed {s : set α} (h : is_closed s) : closure s = s :=
subset.antisymm (closure_minimal (subset.refl s) h) subset_closure
lemma closure_eq_iff_is_closed {s : set α} : closure s = s ↔ is_closed s :=
⟨assume h, h ▸ is_closed_closure, closure_eq_of_is_closed⟩
lemma closure_subset_iff_subset_of_is_closed {s t : set α} (h₁ : is_closed t) :
closure s ⊆ t ↔ s ⊆ t :=
⟨subset.trans subset_closure, assume h, closure_minimal h h₁⟩
lemma closure_mono {s t : set α} (h : s ⊆ t) : closure s ⊆ closure t :=
closure_minimal (subset.trans h subset_closure) is_closed_closure
@[simp] lemma closure_empty : closure (∅ : set α) = ∅ :=
closure_eq_of_is_closed is_closed_empty
@[simp] lemma closure_univ : closure (univ : set α) = univ :=
closure_eq_of_is_closed is_closed_univ
@[simp] lemma closure_closure {s : set α} : closure (closure s) = closure s :=
closure_eq_of_is_closed is_closed_closure
@[simp] lemma closure_union {s t : set α} : closure (s ∪ t) = closure s ∪ closure t :=
subset.antisymm
(closure_minimal (union_subset_union subset_closure subset_closure) $ by simp [is_closed_union])
(union_subset (closure_mono $ subset_union_left _ _) (closure_mono $ subset_union_right _ _))
lemma interior_subset_closure {s : set α} : interior s ⊆ closure s :=
subset.trans interior_subset subset_closure
lemma closure_eq_compl_interior_compl {s : set α} : closure s = - interior (- s) :=
begin
simp [interior, closure],
rw [compl_sUnion, compl_image_set_of],
simp [compl_subset_compl_iff_subset]
end
@[simp] lemma interior_compl_eq {s : set α} : interior (- s) = - closure s :=
by simp [closure_eq_compl_interior_compl]
@[simp] lemma closure_compl_eq {s : set α} : closure (- s) = - interior s :=
by simp [closure_eq_compl_interior_compl]
lemma closure_compl {s : set α} : closure (-s) = - interior s :=
subset.antisymm
(by simp [closure_subset_iff_subset_of_is_closed, compl_subset_compl_iff_subset, subset.refl])
begin
rw [←compl_subset_compl_iff_subset, compl_compl, subset_interior_iff_subset_of_open,
←compl_subset_compl_iff_subset, compl_compl],
exact subset_closure,
exact is_open_compl_iff.mpr is_closed_closure
end
lemma interior_compl {s : set α} : interior (-s) = - closure s :=
calc interior (- s) = - - interior (- s) : by simp
... = - closure (- (- s)) : by rw [closure_compl]
... = - closure s : by simp
theorem mem_closure_iff {s : set α} {a : α} : a ∈ closure s ↔ ∀ o, is_open o → a ∈ o → o ∩ s ≠ ∅ :=
⟨λ h o oo ao os,
have s ⊆ -o, from λ x xs xo, @ne_empty_of_mem α (o∩s) x ⟨xo, xs⟩ os,
closure_minimal this (is_closed_compl_iff.2 oo) h ao,
λ H c ⟨h₁, h₂⟩, classical.by_contradiction $ λ nc,
let ⟨x, hc, hs⟩ := exists_mem_of_ne_empty (H _ h₁ nc) in hc (h₂ hs)⟩
/-- The frontier of a set is the set of points between the closure and interior. -/
def frontier (s : set α) : set α := closure s \ interior s
lemma frontier_eq_closure_inter_closure {s : set α} :
frontier s = closure s ∩ closure (- s) :=
by rw [closure_compl, frontier, sdiff_eq]
/-- neighbourhood filter -/
def nhds (a : α) : filter α := (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, principal s)
lemma tendsto_nhds {m : β → α} {f : filter β} (h : ∀s, a ∈ s → is_open s → m ⁻¹' s ∈ f.sets) :
tendsto m f (nhds a) :=
show map m f ≤ (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, principal s),
from le_infi $ assume s, le_infi $ assume ⟨ha, hs⟩, le_principal_iff.mpr $ h s ha hs
lemma tendsto_const_nhds {a : α} {f : filter β} : tendsto (λb:β, a) f (nhds a) :=
tendsto_nhds $ assume s ha hs, univ_mem_sets' $ assume _, ha
lemma nhds_sets {a : α} : (nhds a).sets = {s | ∃t⊆s, is_open t ∧ a ∈ t} :=
calc (nhds a).sets = (⋃s∈{s : set α| a ∈ s ∧ is_open s}, (principal s).sets) : infi_sets_eq'
(assume x ⟨hx₁, hx₂⟩ y ⟨hy₁, hy₂⟩,
⟨x ∩ y, ⟨⟨hx₁, hy₁⟩, is_open_inter hx₂ hy₂⟩, by simp⟩)
⟨univ, by simp⟩
... = {s | ∃t⊆s, is_open t ∧ a ∈ t} :
le_antisymm
(supr_le $ assume i, supr_le $ assume ⟨hi₁, hi₂⟩ t ht, ⟨i, ht, hi₂, hi₁⟩)
(assume t ⟨i, hi₁, hi₂, hi₃⟩, by simp; exact ⟨i, ⟨hi₃, hi₂⟩, hi₁⟩)
lemma map_nhds {a : α} {f : α → β} :
map f (nhds a) = (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, principal (image f s)) :=
calc map f (nhds a) = (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, map f (principal s)) :
map_binfi_eq
(assume x ⟨hx₁, hx₂⟩ y ⟨hy₁, hy₂⟩,
⟨x ∩ y, ⟨⟨hx₁, hy₁⟩, is_open_inter hx₂ hy₂⟩, by simp⟩)
⟨univ, by simp⟩
... = _ : by simp
lemma mem_nhds_sets_iff {a : α} {s : set α} :
s ∈ (nhds a).sets ↔ ∃t⊆s, is_open t ∧ a ∈ t :=
by simp [nhds_sets]
lemma mem_of_nhds {a : α} {s : set α} : s ∈ (nhds a).sets → a ∈ s :=
by simp [mem_nhds_sets_iff]; exact assume t ht _ hs, ht hs
lemma mem_nhds_sets {a : α} {s : set α} (hs : is_open s) (ha : a ∈ s) :
s ∈ (nhds a).sets :=
by simp [nhds_sets]; exact ⟨s, subset.refl _, hs, ha⟩
lemma return_le_nhds : return ≤ (nhds : α → filter α) :=
assume a, le_infi $ assume s, le_infi $ assume ⟨h₁, _⟩, principal_mono.mpr $ by simp [h₁]
@[simp] lemma nhds_neq_bot {a : α} : nhds a ≠ ⊥ :=
assume : nhds a = ⊥,
have return a = (⊥ : filter α),
from lattice.bot_unique $ this ▸ return_le_nhds a,
pure_neq_bot this
lemma interior_eq_nhds {s : set α} : interior s = {a | nhds a ≤ principal s} :=
set.ext $ by simp [mem_interior, nhds_sets]
lemma mem_interior_iff_mem_nhds {s : set α} {a : α} :
a ∈ interior s ↔ s ∈ (nhds a).sets :=
by simp [interior_eq_nhds]
lemma is_open_iff_nhds {s : set α} : is_open s ↔ ∀a∈s, nhds a ≤ principal s :=
calc is_open s ↔ interior s = s : by rw [interior_eq_iff_open]
... ↔ s ⊆ interior s : ⟨assume h, by simp [*, subset.refl], subset.antisymm interior_subset⟩
... ↔ (∀a∈s, nhds a ≤ principal s) : by rw [interior_eq_nhds]; refl
lemma is_open_iff_mem_nhds {s : set α} : is_open s ↔ ∀a∈s, s ∈ (nhds a).sets :=
by simpa using @is_open_iff_nhds α _ _
lemma closure_eq_nhds {s : set α} : closure s = {a | nhds a ⊓ principal s ≠ ⊥} :=
calc closure s = - interior (- s) : closure_eq_compl_interior_compl
... = {a | ¬ nhds a ≤ principal (-s)} : by rw [interior_eq_nhds]; refl
... = {a | nhds a ⊓ principal s ≠ ⊥} : set.ext $ assume a, not_congr
(inf_eq_bot_iff_le_compl
(show principal s ⊔ principal (-s) = ⊤, by simp [principal_univ])
(by simp)).symm
theorem mem_closure_iff_nhds {s : set α} {a : α} : a ∈ closure s ↔ ∀ t ∈ (nhds a).sets, t ∩ s ≠ ∅ :=
mem_closure_iff.trans
⟨λ H t ht, subset_ne_empty
(inter_subset_inter_right _ interior_subset)
(H _ is_open_interior (mem_interior_iff_mem_nhds.2 ht)),
λ H o oo ao, H _ (mem_nhds_sets oo ao)⟩
lemma is_closed_iff_nhds {s : set α} : is_closed s ↔ ∀a, nhds a ⊓ principal s ≠ ⊥ → a ∈ s :=
calc is_closed s ↔ closure s = s : by rw [closure_eq_iff_is_closed]
... ↔ closure s ⊆ s : ⟨assume h, by simp [*, subset.refl], assume h, subset.antisymm h subset_closure⟩
... ↔ (∀a, nhds a ⊓ principal s ≠ ⊥ → a ∈ s) : by rw [closure_eq_nhds]; refl
lemma closure_inter_open {s t : set α} (h : is_open s) : s ∩ closure t ⊆ closure (s ∩ t) :=
assume a ⟨hs, ht⟩,
have s ∈ (nhds a).sets, from mem_nhds_sets h hs,
have nhds a ⊓ principal s = nhds a, from inf_of_le_left $ by simp [this],
have nhds a ⊓ principal (s ∩ t) ≠ ⊥,
from calc nhds a ⊓ principal (s ∩ t) = nhds a ⊓ (principal s ⊓ principal t) : by simp
... = nhds a ⊓ principal t : by rw [←inf_assoc, this]
... ≠ ⊥ : by rw [closure_eq_nhds] at ht; assumption,
by rw [closure_eq_nhds]; assumption
lemma closure_diff {s t : set α} : closure s - closure t ⊆ closure (s - t) :=
calc closure s \ closure t = (- closure t) ∩ closure s : by simp [diff_eq, inter_comm]
... ⊆ closure (- closure t ∩ s) : closure_inter_open $ is_open_compl_iff.mpr $ is_closed_closure
... = closure (s \ closure t) : by simp [diff_eq, inter_comm]
... ⊆ closure (s \ t) : closure_mono $ diff_subset_diff (subset.refl s) subset_closure
lemma mem_of_closed_of_tendsto {f : β → α} {b : filter β} {a : α} {s : set α}
(hb : b ≠ ⊥) (hf : tendsto f b (nhds a)) (hs : is_closed s) (h : f ⁻¹' s ∈ b.sets) : a ∈ s :=
have b.map f ≤ nhds a ⊓ principal s,
from le_trans (le_inf (le_refl _) (le_principal_iff.mpr h)) (inf_le_inf hf (le_refl _)),
is_closed_iff_nhds.mp hs a $ neq_bot_of_le_neq_bot (map_ne_bot hb) this
lemma mem_closure_of_tendsto {f : β → α} {x : filter β} {a : α} {s : set α}
(hf : tendsto f x (nhds a)) (hs : is_closed s) (h : x ⊓ principal (f ⁻¹' s) ≠ ⊥) : a ∈ s :=
is_closed_iff_nhds.mp hs _ $ neq_bot_of_le_neq_bot (@map_ne_bot _ _ _ f h) $
le_inf (le_trans (map_mono $ inf_le_left) hf) $
le_trans (map_mono $ inf_le_right_of_le $ by simp; exact subset.refl _) (@map_vmap_le _ _ _ f)
/- locally finite family [General Topology (Bourbaki, 1995)] -/
section locally_finite
/-- A family of sets in `set α` is locally finite if at every point `x:α`,
there is a neighborhood of `x` which meets only finitely many sets in the family -/
def locally_finite (f : β → set α) :=
∀x:α, ∃t∈(nhds x).sets, finite {i | f i ∩ t ≠ ∅ }
lemma locally_finite_of_finite {f : β → set α} (h : finite (univ : set β)) : locally_finite f :=
assume x, ⟨univ, univ_mem_sets, finite_subset h $ by simp⟩
lemma locally_finite_subset
{f₁ f₂ : β → set α} (hf₂ : locally_finite f₂) (hf : ∀b, f₁ b ⊆ f₂ b) : locally_finite f₁ :=
assume a,
let ⟨t, ht₁, ht₂⟩ := hf₂ a in
⟨t, ht₁, finite_subset ht₂ $ assume i hi,
neq_bot_of_le_neq_bot hi $ inter_subset_inter (hf i) $ subset.refl _⟩
lemma is_closed_Union_of_locally_finite {f : β → set α}
(h₁ : locally_finite f) (h₂ : ∀i, is_closed (f i)) : is_closed (⋃i, f i) :=
is_open_iff_nhds.mpr $ assume a, assume h : a ∉ (⋃i, f i),
have ∀i, a ∈ -f i,
from assume i hi, by simp at h; exact h i hi,
have ∀i, - f i ∈ (nhds a).sets,
by rw [nhds_sets]; exact assume i, ⟨- f i, subset.refl _, h₂ i, this i⟩,
let ⟨t, h_sets, (h_fin : finite {i | f i ∩ t ≠ ∅ })⟩ := h₁ a in
calc nhds a ≤ principal (t ∩ (⋂ i∈{i | f i ∩ t ≠ ∅ }, - f i)) :
begin
rw [le_principal_iff],
apply @filter.inter_mem_sets _ (nhds a) _ _ h_sets,
apply @filter.Inter_mem_sets _ (nhds a) _ _ _ h_fin,
exact assume i h, this i
end
... ≤ principal (- ⋃i, f i) :
begin
simp only [principal_mono, subset_def, mem_compl_eq, mem_inter_eq,
mem_Inter_eq, mem_set_of_eq, mem_Union_eq, and_imp, not_exists,
not_eq_empty_iff_exists, exists_imp_distrib, (≠)],
exact assume x xt ht i xfi, ht i x xfi xt xfi
end
end locally_finite
/- compact sets -/
section compact
/-- A set `s` is compact if every filter that contains `s` also meets every
neighborhood of some `a ∈ s`. -/
def compact (s : set α) := ∀f, f ≠ ⊥ → f ≤ principal s → ∃a∈s, f ⊓ nhds a ≠ ⊥
lemma compact_of_is_closed_subset {s t : set α}
(hs : compact s) (ht : is_closed t) (h : t ⊆ s) : compact t :=
assume f hnf hsf,
let ⟨a, hsa, (ha : f ⊓ nhds a ≠ ⊥)⟩ := hs f hnf (le_trans hsf $ by simp [h]) in
have ∀a, principal t ⊓ nhds a ≠ ⊥ → a ∈ t,
by intro a; rw [inf_comm]; rw [is_closed_iff_nhds] at ht; exact ht a,
have a ∈ t,
from this a $ neq_bot_of_le_neq_bot ha $ inf_le_inf hsf (le_refl _),
⟨a, this, ha⟩
lemma compact_adherence_nhdset {s t : set α} {f : filter α}
(hs : compact s) (hf₂ : f ≤ principal s) (ht₁ : is_open t) (ht₂ : ∀a∈s, nhds a ⊓ f ≠ ⊥ → a ∈ t) :
t ∈ f.sets :=
classical.by_cases mem_sets_of_neq_bot $
assume : f ⊓ principal (- t) ≠ ⊥,
let ⟨a, ha, (hfa : f ⊓ principal (-t) ⊓ nhds a ≠ ⊥)⟩ := hs _ this $ inf_le_left_of_le hf₂ in
have a ∈ t,
from ht₂ a ha $ neq_bot_of_le_neq_bot hfa $ le_inf inf_le_right $ inf_le_left_of_le inf_le_left,
have nhds a ⊓ principal (-t) ≠ ⊥,
from neq_bot_of_le_neq_bot hfa $ le_inf inf_le_right $ inf_le_left_of_le inf_le_right,
have ∀s∈(nhds a ⊓ principal (-t)).sets, s ≠ ∅,
from forall_sets_neq_empty_iff_neq_bot.mpr this,
have false,
from this _ ⟨t, mem_nhds_sets ht₁ ‹a ∈ t›, -t, subset.refl _, subset.refl _⟩ (by simp),
by contradiction
lemma compact_iff_ultrafilter_le_nhds {s : set α} :
compact s ↔ (∀f, ultrafilter f → f ≤ principal s → ∃a∈s, f ≤ nhds a) :=
⟨assume hs : compact s, assume f hf hfs,
let ⟨a, ha, h⟩ := hs _ hf.left hfs in
⟨a, ha, le_of_ultrafilter hf h⟩,
assume hs : (∀f, ultrafilter f → f ≤ principal s → ∃a∈s, f ≤ nhds a),
assume f hf hfs,
let ⟨a, ha, (h : ultrafilter_of f ≤ nhds a)⟩ :=
hs (ultrafilter_of f) (ultrafilter_ultrafilter_of hf) (le_trans ultrafilter_of_le hfs) in
have ultrafilter_of f ⊓ nhds a ≠ ⊥,
by simp [inf_of_le_left, h]; exact (ultrafilter_ultrafilter_of hf).left,
⟨a, ha, neq_bot_of_le_neq_bot this (inf_le_inf ultrafilter_of_le (le_refl _))⟩⟩
lemma compact_elim_finite_subcover {s : set α} {c : set (set α)}
(hs : compact s) (hc₁ : ∀t∈c, is_open t) (hc₂ : s ⊆ ⋃₀ c) : ∃c'⊆c, finite c' ∧ s ⊆ ⋃₀ c' :=
classical.by_contradiction $ assume h,
have h : ∀{c'}, c' ⊆ c → finite c' → ¬ s ⊆ ⋃₀ c',
from assume c' h₁ h₂ h₃, h ⟨c', h₁, h₂, h₃⟩,
let
f : filter α := (⨅c':{c' : set (set α) // c' ⊆ c ∧ finite c'}, principal (s - ⋃₀ c')),
⟨a, ha⟩ := @exists_mem_of_ne_empty α s
(assume h', h (empty_subset _) finite_empty $ h'.symm ▸ empty_subset _)
in
have f ≠ ⊥, from infi_neq_bot_of_directed ⟨a⟩
(assume ⟨c₁, hc₁, hc'₁⟩ ⟨c₂, hc₂, hc'₂⟩, ⟨⟨c₁ ∪ c₂, union_subset hc₁ hc₂, finite_union hc'₁ hc'₂⟩,
principal_mono.mpr $ diff_right_antimono $ sUnion_mono $ subset_union_left _ _,
principal_mono.mpr $ diff_right_antimono $ sUnion_mono $ subset_union_right _ _⟩)
(assume ⟨c', hc'₁, hc'₂⟩, show principal (s \ _) ≠ ⊥, by simp [diff_neq_empty]; exact h hc'₁ hc'₂),
have f ≤ principal s, from infi_le_of_le ⟨∅, empty_subset _, finite_empty⟩ $
show principal (s \ ⋃₀∅) ≤ principal s, by simp; exact subset.refl s,
let
⟨a, ha, (h : f ⊓ nhds a ≠ ⊥)⟩ := hs f ‹f ≠ ⊥› this,
⟨t, ht₁, (ht₂ : a ∈ t)⟩ := hc₂ ha
in
have f ≤ principal (-t),
from infi_le_of_le ⟨{t}, by simp [ht₁], finite_insert _ finite_empty⟩ $
principal_mono.mpr $
show s - ⋃₀{t} ⊆ - t, begin simp; exact assume x ⟨_, hnt⟩, hnt end,
have is_closed (- t), from is_open_compl_iff.mp $ by simp; exact hc₁ t ht₁,
have a ∈ - t, from is_closed_iff_nhds.mp this _ $ neq_bot_of_le_neq_bot h $
le_inf inf_le_right (inf_le_left_of_le ‹f ≤ principal (- t)›),
this ‹a ∈ t›
lemma compact_elim_finite_subcover_image {s : set α} {b : set β} {c : β → set α}
(hs : compact s) (hc₁ : ∀i∈b, is_open (c i)) (hc₂ : s ⊆ ⋃i∈b, c i) :
∃b'⊆b, finite b' ∧ s ⊆ ⋃i∈b', c i :=
if h : b = ∅ then ⟨∅, by simp, by simp, h ▸ hc₂⟩ else
let ⟨i, hi⟩ := exists_mem_of_ne_empty h in
have hc'₁ : ∀i∈c '' b, is_open i, from assume i ⟨j, hj, h⟩, h ▸ hc₁ _ hj,
have hc'₂ : s ⊆ ⋃₀ (c '' b), by simpa,
let ⟨d, hd₁, hd₂, hd₃⟩ := compact_elim_finite_subcover hs hc'₁ hc'₂ in
have ∀x : d, ∃i, i ∈ b ∧ c i = x, from assume ⟨x, hx⟩, hd₁ hx,
let ⟨f', hf⟩ := axiom_of_choice this,
f := λx:set α, (if h : x ∈ d then f' ⟨x, h⟩ else i : β) in
have ∀(x : α) (i : set α), i ∈ d → x ∈ i → (∃ (i : β), i ∈ f '' d ∧ x ∈ c i),
from assume x i hid hxi, ⟨f i, mem_image_of_mem f hid,
by simpa [f, hid, (hf ⟨_, hid⟩).2] using hxi⟩,
⟨f '' d,
assume i ⟨j, hj, h⟩,
h ▸ by simpa [f, hj] using (hf ⟨_, hj⟩).1,
finite_image f hd₂,
subset.trans hd₃ $ by simpa [subset_def]⟩
lemma compact_of_finite_subcover {s : set α}
(h : ∀c, (∀t∈c, is_open t) → s ⊆ ⋃₀ c → ∃c'⊆c, finite c' ∧ s ⊆ ⋃₀ c') : compact s :=
assume f hfn hfs, classical.by_contradiction $ assume : ¬ (∃x∈s, f ⊓ nhds x ≠ ⊥),
have hf : ∀x∈s, nhds x ⊓ f = ⊥,
by simpa [not_and, inf_comm],
have ¬ ∃x∈s, ∀t∈f.sets, x ∈ closure t,
from assume ⟨x, hxs, hx⟩,
have ∅ ∈ (nhds x ⊓ f).sets, by rw [empty_in_sets_eq_bot, hf x hxs],
let ⟨t₁, ht₁, t₂, ht₂, ht⟩ := by rw [mem_inf_sets] at this; exact this in
have ∅ ∈ (nhds x ⊓ principal t₂).sets,
from (nhds x ⊓ principal t₂).upwards_sets (inter_mem_inf_sets ht₁ (subset.refl t₂)) ht,
have nhds x ⊓ principal t₂ = ⊥,
by rwa [empty_in_sets_eq_bot] at this,
by simp [closure_eq_nhds] at hx; exact hx t₂ ht₂ this,
have ∀x∈s, ∃t∈f.sets, x ∉ closure t, by simpa [_root_.not_forall],
let c := (λt, - closure t) '' f.sets, ⟨c', hcc', hcf, hsc'⟩ := h c
(assume t ⟨s, hs, h⟩, h ▸ is_closed_closure) (by simpa [subset_def]) in
let ⟨b, hb⟩ := axiom_of_choice $
show ∀s:c', ∃t, t ∈ f.sets ∧ - closure t = s,
from assume ⟨x, hx⟩, hcc' hx in
have (⋂s∈c', if h : s ∈ c' then b ⟨s, h⟩ else univ) ∈ f.sets,
from Inter_mem_sets hcf $ assume t ht, by rw [dif_pos ht]; exact (hb ⟨t, ht⟩).left,
have s ∩ (⋂s∈c', if h : s ∈ c' then b ⟨s, h⟩ else univ) ∈ f.sets,
from inter_mem_sets (by simp at hfs; assumption) this,
have ∅ ∈ f.sets,
from f.upwards_sets this $ assume x ⟨hxs, hxi⟩,
let ⟨t, htc', hxt⟩ := (show ∃t ∈ c', x ∈ t, by simpa using hsc' hxs) in
have -closure (b ⟨t, htc'⟩) = t, from (hb _).right,
have x ∈ - t,
from this ▸ (calc x ∈ b ⟨t, htc'⟩ : by simp at hxi; have h := hxi t htc'; rwa [dif_pos htc'] at h
... ⊆ closure (b ⟨t, htc'⟩) : subset_closure
... ⊆ - - closure (b ⟨t, htc'⟩) : by simp; exact subset.refl _),
show false, from this hxt,
hfn $ by rwa [empty_in_sets_eq_bot] at this
lemma compact_iff_finite_subcover {s : set α} :
compact s ↔ (∀c, (∀t∈c, is_open t) → s ⊆ ⋃₀ c → ∃c'⊆c, finite c' ∧ s ⊆ ⋃₀ c') :=
⟨assume hc c, compact_elim_finite_subcover hc, compact_of_finite_subcover⟩
lemma compact_empty : compact (∅ : set α) :=
assume f hnf hsf, not.elim hnf $
by simpa [empty_in_sets_eq_bot] using hsf
lemma compact_singleton {a : α} : compact ({a} : set α) :=
compact_of_finite_subcover $ assume c hc₁ hc₂,
let ⟨i, hic, hai⟩ := (show ∃i ∈ c, a ∈ i, by simpa using hc₂) in
⟨{i}, by simp [hic], finite_singleton _, by simp [hai]⟩
end compact
/- separation axioms -/
section separation
/-- A T₁ space, also known as a Fréchet space, is a topological space
where for every pair `x ≠ y`, there is an open set containing `x` and not `y`.
Equivalently, every singleton set is closed. -/
class t1_space (α : Type u) [topological_space α] :=
(t1 : ∀x, is_closed ({x} : set α))
lemma is_closed_singleton [t1_space α] {x : α} : is_closed ({x} : set α) :=
t1_space.t1 x
lemma compl_singleton_mem_nhds [t1_space α] {x y : α} (h : y ≠ x) : - {x} ∈ (nhds y).sets :=
mem_nhds_sets is_closed_singleton $ by simp; exact h
@[simp] lemma closure_singleton [topological_space α] [t1_space α] {a : α} :
closure ({a} : set α) = {a} :=
closure_eq_of_is_closed is_closed_singleton
/-- A T₂ space, also known as a Hausdorff space, is one in which for every
`x ≠ y` there exists disjoint open sets around `x` and `y`. This is
the most widely used of the separation axioms. -/
class t2_space (α : Type u) [topological_space α] :=
(t2 : ∀x y, x ≠ y → ∃u v : set α, is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅)
lemma t2_separation [t2_space α] {x y : α} (h : x ≠ y) :
∃u v : set α, is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅ :=
t2_space.t2 x y h
instance t2_space.t1_space [topological_space α] [t2_space α] : t1_space α :=
⟨assume x,
have ∀y, y ≠ x ↔ ∃ (i : set α), (x ∉ i ∧ is_open i) ∧ y ∈ i,
from assume y, ⟨assume h',
let ⟨u, v, hu, hv, hy, hx, h⟩ := t2_separation h' in
have x ∉ u,
from assume : x ∈ u,
have x ∈ u ∩ v, from ⟨this, hx⟩,
by rwa [h] at this,
⟨u, ⟨this, hu⟩, hy⟩,
assume ⟨s, ⟨hx, hs⟩, hy⟩ h, hx $ h ▸ hy⟩,
have (-{x} : set α) = (⋃s∈{s : set α | x ∉ s ∧ is_open s}, s),
by apply set.ext; simpa,
show is_open (- {x}),
by rw [this]; exact (is_open_Union $ assume s, is_open_Union $ assume ⟨_, hs⟩, hs)⟩
lemma eq_of_nhds_neq_bot [ht : t2_space α] {x y : α} (h : nhds x ⊓ nhds y ≠ ⊥) : x = y :=
classical.by_contradiction $ assume : x ≠ y,
let ⟨u, v, hu, hv, hx, hy, huv⟩ := t2_space.t2 x y this in
have u ∩ v ∈ (nhds x ⊓ nhds y).sets,
from inter_mem_inf_sets (mem_nhds_sets hu hx) (mem_nhds_sets hv hy),
h $ empty_in_sets_eq_bot.mp $ huv ▸ this
@[simp] lemma nhds_eq_nhds_iff {a b : α} [t2_space α] : nhds a = nhds b ↔ a = b :=
⟨assume h, eq_of_nhds_neq_bot $ by simp [h], assume h, h ▸ rfl⟩
@[simp] lemma nhds_le_nhds_iff {a b : α} [t2_space α] : nhds a ≤ nhds b ↔ a = b :=
⟨assume h, eq_of_nhds_neq_bot $ by simp [inf_of_le_left h], assume h, h ▸ le_refl _⟩
lemma tendsto_nhds_unique [t2_space α] {f : β → α} {l : filter β} {a b : α}
(hl : l ≠ ⊥) (ha : tendsto f l (nhds a)) (hb : tendsto f l (nhds b)) : a = b :=
eq_of_nhds_neq_bot $ neq_bot_of_le_neq_bot (map_ne_bot hl) $ le_inf ha hb
end separation
section regularity
/-- A T₃ space, also known as a regular space (although this condition sometimes
omits T₂), is one in which for every closed `C` and `x ∉ C`, there exist
disjoint open sets containing `x` and `C` respectively. -/
class regular_space (α : Type u) [topological_space α] extends t2_space α :=
(regular : ∀{s:set α} {a}, is_closed s → a ∉ s → ∃t, is_open t ∧ s ⊆ t ∧ nhds a ⊓ principal t = ⊥)
lemma nhds_is_closed [regular_space α] {a : α} {s : set α} (h : s ∈ (nhds a).sets) :
∃t∈(nhds a).sets, t ⊆ s ∧ is_closed t :=
let ⟨s', h₁, h₂, h₃⟩ := mem_nhds_sets_iff.mp h in
have ∃t, is_open t ∧ -s' ⊆ t ∧ nhds a ⊓ principal t = ⊥,
from regular_space.regular (is_closed_compl_iff.mpr h₂) (not_not_intro h₃),
let ⟨t, ht₁, ht₂, ht₃⟩ := this in
⟨-t,
mem_sets_of_neq_bot $ by simp; exact ht₃,
subset.trans (compl_subset_comm.1 ht₂) h₁,
is_closed_compl_iff.mpr ht₁⟩
end regularity
/- generating sets -/
end topological_space
namespace topological_space
variables {α : Type u}
/-- The least topology containing a collection of basic sets. -/
inductive generate_open (g : set (set α)) : set α → Prop
| basic : ∀s∈g, generate_open s
| univ : generate_open univ
| inter : ∀s t, generate_open s → generate_open t → generate_open (s ∩ t)
| sUnion : ∀k, (∀s∈k, generate_open s) → generate_open (⋃₀ k)
/-- The smallest topological space containing the collection `g` of basic sets -/
def generate_from (g : set (set α)) : topological_space α :=
{ is_open := generate_open g,
is_open_univ := generate_open.univ g,
is_open_inter := generate_open.inter,
is_open_sUnion := generate_open.sUnion }
lemma nhds_generate_from {g : set (set α)} {a : α} :
@nhds α (generate_from g) a = (⨅s∈{s | a ∈ s ∧ s ∈ g}, principal s) :=
le_antisymm
(infi_le_infi $ assume s, infi_le_infi_const $ assume ⟨as, sg⟩, ⟨as, generate_open.basic _ sg⟩)
(le_infi $ assume s, le_infi $ assume ⟨as, hs⟩,
have ∀s, generate_open g s → a ∈ s → (⨅s∈{s | a ∈ s ∧ s ∈ g}, principal s) ≤ principal s,
begin
intros s hs,
induction hs,
case generate_open.basic : s hs
{ exact assume as, infi_le_of_le s $ infi_le _ ⟨as, hs⟩ },
case generate_open.univ
{ rw [principal_univ],
exact assume _, le_top },
case generate_open.inter : s t hs' ht' hs ht
{ exact assume ⟨has, hat⟩, calc _ ≤ principal s ⊓ principal t : le_inf (hs has) (ht hat)
... = _ : by simp },
case generate_open.sUnion : k hk' hk
{ exact λ ⟨t, htk, hat⟩, calc _ ≤ principal t : hk t htk hat
... ≤ _ : begin simp; exact subset_sUnion_of_mem htk end }
end,
this s hs as)
end topological_space
/- constructions using the complete lattice structure -/
section constructions
variables {α : Type u} {β : Type v}
instance : partial_order (topological_space α) :=
{ le := λt s, t.is_open ≤ s.is_open,
le_antisymm := assume t s h₁ h₂, topological_space_eq $ le_antisymm h₁ h₂,
le_refl := assume t, le_refl t.is_open,
le_trans := assume a b c h₁ h₂, @le_trans _ _ a.is_open b.is_open c.is_open h₁ h₂ }
instance : has_Inf (topological_space α) := ⟨λ tt,
{ is_open := λs, ∀t∈tt, topological_space.is_open t s,
is_open_univ := assume t h, t.is_open_univ,
is_open_inter := assume s₁ s₂ h₁ h₂ t ht, t.is_open_inter s₁ s₂ (h₁ t ht) (h₂ t ht),
is_open_sUnion := assume s h t ht, t.is_open_sUnion _ $ assume s' hss', h _ hss' _ ht }⟩
private lemma Inf_le {tt : set (topological_space α)} {t : topological_space α} (h : t ∈ tt) :
Inf tt ≤ t :=
assume s hs, hs t h
private lemma le_Inf {tt : set (topological_space α)} {t : topological_space α} (h : ∀t'∈tt, t ≤ t') :
t ≤ Inf tt :=
assume s hs t' ht', h t' ht' s hs
/-- Given `f : α → β` and a topology on `β`, the induced topology on `α` is the collection of
sets that are preimages of some open set in `β`. This is the coarsest topology that
makes `f` continuous. -/
def topological_space.induced {α : Type u} {β : Type v} (f : α → β) (t : topological_space β) :
topological_space α :=
{ is_open := λs, ∃s', t.is_open s' ∧ s = f ⁻¹' s',
is_open_univ := ⟨univ, by simp; exact t.is_open_univ⟩,
is_open_inter := assume s₁ s₂ ⟨s'₁, hs₁, eq₁⟩ ⟨s'₂, hs₂, eq₂⟩,
⟨s'₁ ∩ s'₂, by simp [eq₁, eq₂]; exact t.is_open_inter _ _ hs₁ hs₂⟩,
is_open_sUnion := assume s h,
begin
simp [classical.skolem] at h,
cases h with f hf,
apply exists.intro (⋃(x : set α) (h : x ∈ s), f x h),
simp [sUnion_eq_Union, (λx h, (hf x h).right.symm)],
exact (@is_open_Union β _ t _ $ assume i,
show is_open (⋃h, f i h), from @is_open_Union β _ t _ $ assume h, (hf i h).left)
end }
lemma is_closed_induced_iff [t : topological_space β] {s : set α} {f : α → β} :
@is_closed α (t.induced f) s ↔ (∃t, is_closed t ∧ s = f ⁻¹' t) :=
⟨assume ⟨t, ht, heq⟩, ⟨-t, by simp; assumption, by simp [preimage_compl, heq.symm]⟩,
assume ⟨t, ht, heq⟩, ⟨-t, ht, by simp [preimage_compl, heq.symm]⟩⟩
/-- Given `f : α → β` and a topology on `α`, the coinduced topology on `β` is defined
such that `s:set β` is open if the preimage of `s` is open. This is the finest topology that
makes `f` continuous. -/
def topological_space.coinduced {α : Type u} {β : Type v} (f : α → β) (t : topological_space α) :
topological_space β :=
{ is_open := λs, t.is_open (f ⁻¹' s),
is_open_univ := by simp; exact t.is_open_univ,
is_open_inter := assume s₁ s₂ h₁ h₂, by simp; exact t.is_open_inter _ _ h₁ h₂,
is_open_sUnion := assume s h, by rw [preimage_sUnion]; exact (@is_open_Union _ _ t _ $ assume i,
show is_open (⋃ (H : i ∈ s), f ⁻¹' i), from
@is_open_Union _ _ t _ $ assume hi, h i hi) }
instance : has_inf (topological_space α) := ⟨λ t₁ t₂,
{ is_open := λs, t₁.is_open s ∧ t₂.is_open s,
is_open_univ := ⟨t₁.is_open_univ, t₂.is_open_univ⟩,
is_open_inter := assume s₁ s₂ ⟨h₁₁, h₁₂⟩ ⟨h₂₁, h₂₂⟩, ⟨t₁.is_open_inter s₁ s₂ h₁₁ h₂₁, t₂.is_open_inter s₁ s₂ h₁₂ h₂₂⟩,
is_open_sUnion := assume s h, ⟨t₁.is_open_sUnion _ $ assume t ht, (h t ht).left, t₂.is_open_sUnion _ $ assume t ht, (h t ht).right⟩ }⟩
instance : has_top (topological_space α) :=
⟨{is_open := λs, true,
is_open_univ := trivial,
is_open_inter := assume a b ha hb, trivial,
is_open_sUnion := assume s h, trivial }⟩
instance {α : Type u} : complete_lattice (topological_space α) :=
{ sup := λa b, Inf {x | a ≤ x ∧ b ≤ x},
le_sup_left := assume a b, le_Inf $ assume x, assume h : a ≤ x ∧ b ≤ x, h.left,
le_sup_right := assume a b, le_Inf $ assume x, assume h : a ≤ x ∧ b ≤ x, h.right,
sup_le := assume a b c h₁ h₂, Inf_le $ show c ∈ {x | a ≤ x ∧ b ≤ x}, from ⟨h₁, h₂⟩,
inf := (⊓),
le_inf := assume a b h h₁ h₂ s hs, ⟨h₁ s hs, h₂ s hs⟩,
inf_le_left := assume a b s ⟨h₁, h₂⟩, h₁,
inf_le_right := assume a b s ⟨h₁, h₂⟩, h₂,
top := ⊤,
le_top := assume a t ht, trivial,
bot := Inf univ,
bot_le := assume a, Inf_le $ mem_univ a,
Sup := λtt, Inf {t | ∀t'∈tt, t' ≤ t},
le_Sup := assume s f h, le_Inf $ assume t ht, ht _ h,
Sup_le := assume s f h, Inf_le $ assume t ht, h _ ht,
Inf := Inf,
le_Inf := assume s a, le_Inf,
Inf_le := assume s a, Inf_le,
..topological_space.partial_order }
instance inhabited_topological_space {α : Type u} : inhabited (topological_space α) :=
⟨⊤⟩
lemma t2_space_top : @t2_space α ⊤ :=
{ t2 := assume x y hxy, ⟨{x}, {y}, trivial, trivial, mem_insert _ _, mem_insert _ _,
eq_empty_iff_forall_not_mem.2 $ by intros z hz; simp at hz; cc⟩ }
lemma le_of_nhds_le_nhds {t₁ t₂ : topological_space α} (h : ∀x, @nhds α t₂ x ≤ @nhds α t₁ x) :
t₁ ≤ t₂ :=
assume s, show @is_open α t₁ s → @is_open α t₂ s,
begin simp [is_open_iff_nhds]; exact assume hs a ha, h _ $ hs _ ha end
lemma eq_of_nhds_eq_nhds {t₁ t₂ : topological_space α} (h : ∀x, @nhds α t₂ x = @nhds α t₁ x) :
t₁ = t₂ :=
le_antisymm
(le_of_nhds_le_nhds $ assume x, le_of_eq $ h x)
(le_of_nhds_le_nhds $ assume x, le_of_eq $ (h x).symm)
lemma induced_le_iff_le_coinduced {f : α → β } {tα : topological_space α} {tβ : topological_space β} :
tβ.induced f ≤ tα ↔ tβ ≤ tα.coinduced f :=
iff.intro
(assume h s hs, show tα.is_open (f ⁻¹' s), from h _ ⟨s, hs, rfl⟩)
(assume h s ⟨t, ht, hst⟩, hst.symm ▸ h _ ht)
instance : topological_space empty := ⊤
instance : topological_space unit := ⊤
instance : topological_space bool := ⊤
instance : topological_space ℕ := ⊤
instance : topological_space ℤ := ⊤
instance sierpinski_space : topological_space Prop :=
topological_space.generate_from {{true}}
instance {p : α → Prop} [t : topological_space α] : topological_space (subtype p) :=
topological_space.induced subtype.val t
instance [t₁ : topological_space α] [t₂ : topological_space β] : topological_space (α × β) :=
topological_space.induced prod.fst t₁ ⊔ topological_space.induced prod.snd t₂
instance [t₁ : topological_space α] [t₂ : topological_space β] : topological_space (α ⊕ β) :=
topological_space.coinduced sum.inl t₁ ⊓ topological_space.coinduced sum.inr t₂
instance {β : α → Type v} [t₂ : Πa, topological_space (β a)] : topological_space (sigma β) :=
⨅a, topological_space.coinduced (sigma.mk a) (t₂ a)
instance Pi.topological_space {β : α → Type v} [t₂ : Πa, topological_space (β a)] : topological_space (Πa, β a) :=
⨆a, topological_space.induced (λf, f a) (t₂ a)
section
open topological_space
lemma generate_from_le {t : topological_space α} { g : set (set α) } (h : ∀s∈g, is_open s) :
generate_from g ≤ t :=
assume s (hs : generate_open g s), generate_open.rec_on hs h
is_open_univ
(assume s t _ _ hs ht, is_open_inter hs ht)
(assume k _ hk, is_open_sUnion hk)
lemma supr_eq_generate_from {ι : Sort w} { g : ι → topological_space α } :
supr g = generate_from (⋃i, {s | (g i).is_open s}) :=
le_antisymm
(supr_le $ assume i s is_open_s,
generate_open.basic _ $ by simp; exact ⟨i, is_open_s⟩)
(generate_from_le $ assume s,
begin
simp,
exact assume i is_open_s,
have g i ≤ supr g, from le_supr _ _,
this s is_open_s
end)
lemma sup_eq_generate_from { g₁ g₂ : topological_space α } :
g₁ ⊔ g₂ = generate_from {s | g₁.is_open s ∨ g₂.is_open s} :=
le_antisymm
(sup_le (assume s, generate_open.basic _ ∘ or.inl) (assume s, generate_open.basic _ ∘ or.inr))
(generate_from_le $ assume s hs,
have h₁ : g₁ ≤ g₁ ⊔ g₂, from le_sup_left,
have h₂ : g₂ ≤ g₁ ⊔ g₂, from le_sup_right,
or.rec_on hs (h₁ s) (h₂ s))
lemma nhds_mono {t₁ t₂ : topological_space α} {a : α} (h : t₁ ≤ t₂) : @nhds α t₂ a ≤ @nhds α t₁ a :=
infi_le_infi $ assume s, infi_le_infi2 $ assume ⟨ha, hs⟩, ⟨⟨ha, h _ hs⟩, le_refl _⟩
lemma nhds_supr {ι : Sort w} {t : ι → topological_space α} {a : α} :
@nhds α (supr t) a = (⨅i, @nhds α (t i) a) :=
le_antisymm
(le_infi $ assume i, nhds_mono $ le_supr _ _)
begin
rw [supr_eq_generate_from, nhds_generate_from],
exact (le_infi $ assume s, le_infi $ assume ⟨hs, hi⟩,
begin
simp at hi, cases hi with i hi,
exact (infi_le_of_le i $ le_principal_iff.mpr $ @mem_nhds_sets α (t i) _ _ hi hs)
end)
end
lemma nhds_sup {t₁ t₂ : topological_space α} {a : α} :
@nhds α (t₁ ⊔ t₂) a = @nhds α t₁ a ⊓ @nhds α t₂ a :=
calc @nhds α (t₁ ⊔ t₂) a = @nhds α (⨆b:bool, cond b t₁ t₂) a : by rw [supr_bool_eq]
... = (⨅b, @nhds α (cond b t₁ t₂) a) : begin rw [nhds_supr] end
... = @nhds α t₁ a ⊓ @nhds α t₂ a : by rw [infi_bool_eq]
end
end constructions
namespace topological_space
/- countability axioms
For our applications we are interested that there exists a countable basis, but we do not need the
concrete basis itself. This allows us to declare these type classes as `Prop` to use them as mixins.
-/
variables {α : Type u} [t : topological_space α]
include t
/-- A topological basis is one that satisfies the necessary conditions so that
it suffices to take unions of the basis sets to get a topology (without taking
finite intersections as well). -/
def is_topological_basis (s : set (set α)) : Prop :=
(∀t₁∈s, ∀t₂∈s, ∀ x ∈ t₁ ∩ t₂, ∃ t₃∈s, x ∈ t₃ ∧ t₃ ⊆ t₁ ∩ t₂) ∧
(⋃₀ s) = univ ∧
t = generate_from s
lemma is_topological_basis_of_subbasis {s : set (set α)} (hs : t = generate_from s) :
is_topological_basis ((λf, ⋂₀ f) '' {f:set (set α) | finite f ∧ f ⊆ s ∧ ⋂₀ f ≠ ∅}) :=
let b' := (λf, ⋂₀ f) '' {f:set (set α) | finite f ∧ f ⊆ s ∧ ⋂₀ f ≠ ∅} in
⟨assume s₁ ⟨t₁, ⟨hft₁, ht₁b, ht₁⟩, eq₁⟩ s₂ ⟨t₂, ⟨hft₂, ht₂b, ht₂⟩, eq₂⟩,
have ie : ⋂₀(t₁ ∪ t₂) = ⋂₀ t₁ ∩ ⋂₀ t₂, from Inf_union,
eq₁ ▸ eq₂ ▸ assume x h,
⟨_, ⟨t₁ ∪ t₂, ⟨finite_union hft₁ hft₂, union_subset ht₁b ht₂b,
by simpa [ie] using ne_empty_of_mem h⟩, ie⟩, h, subset.refl _⟩,
eq_univ_iff_forall.2 $ assume a, ⟨univ, ⟨∅, by simp; exact (@empty_ne_univ _ ⟨a⟩).symm⟩, mem_univ _⟩,
have generate_from s = generate_from b',
from le_antisymm
(generate_from_le $ assume s hs,
by_cases
(assume : s = ∅, by rw [this]; apply @is_open_empty _ _)
(assume : s ≠ ∅, generate_open.basic _ ⟨{s}, by simp [this, hs]⟩))
(generate_from_le $ assume u ⟨t, ⟨hft, htb, ne⟩, eq⟩,
eq ▸ @is_open_sInter _ (generate_from s) _ hft (assume s hs, generate_open.basic _ $ htb hs)),
this ▸ hs⟩
lemma is_topological_basis_of_open_of_nhds {s : set (set α)}
(h_open : ∀ u ∈ s, _root_.is_open u)
(h_nhds : ∀(a:α) (u : set α), a ∈ u → _root_.is_open u → ∃v ∈ s, a ∈ v ∧ v ⊆ u) :
is_topological_basis s :=
⟨assume t₁ ht₁ t₂ ht₂ x ⟨xt₁, xt₂⟩,
h_nhds x (t₁ ∩ t₂) ⟨xt₁, xt₂⟩
(is_open_inter _ _ _ (h_open _ ht₁) (h_open _ ht₂)),
eq_univ_iff_forall.2 $ assume a,
let ⟨u, h₁, h₂, _⟩ := h_nhds a univ trivial (is_open_univ _) in
⟨u, h₁, h₂⟩,
le_antisymm
(assume u hu,
(@is_open_iff_nhds α (generate_from _) _).mpr $ assume a hau,
let ⟨v, hvs, hav, hvu⟩ := h_nhds a u hau hu in
by rw nhds_generate_from; exact infi_le_of_le v (infi_le_of_le ⟨hav, hvs⟩ $ by simp [hvu]))
(generate_from_le h_open)⟩
lemma mem_nhds_of_is_topological_basis {a : α} {s : set α} {b : set (set α)}
(hb : is_topological_basis b) : s ∈ (nhds a).sets ↔ ∃t∈b, a ∈ t ∧ t ⊆ s :=
begin
rw [hb.2.2, nhds_generate_from, infi_sets_eq'],
{ simpa [and_comm, and.left_comm] },
{ exact assume s ⟨hs₁, hs₂⟩ t ⟨ht₁, ht₂⟩,
have a ∈ s ∩ t, from ⟨hs₁, ht₁⟩,
let ⟨u, hu₁, hu₂, hu₃⟩ := hb.1 _ hs₂ _ ht₂ _ this in
⟨u, ⟨hu₂, hu₁⟩, by simpa using hu₃⟩ },
{ suffices : a ∈ (⋃₀ b), { simpa [and_comm] },
{ rw [hb.2.1], trivial } }
end
variables (α)
/-- A separable space is one with a countable dense subset. -/
class separable_space : Prop :=
(exists_countable_closure_eq_univ : ∃s:set α, countable s ∧ closure s = univ)
/-- A first-countable space is one in which every point has a
countable neighborhood basis. -/
class first_countable_topology : Prop :=
(nhds_generated_countable : ∀a:α, ∃s:set (set α), countable s ∧ nhds a = (⨅t∈s, principal t))
/-- A second-countable space is one with a countable basis. -/
class second_countable_topology : Prop :=
(is_open_generated_countable : ∃b:set (set α), countable b ∧ t = topological_space.generate_from b)
instance second_countable_topology.to_first_countable_topology
[second_countable_topology α] : first_countable_topology α :=
let ⟨b, hb, eq⟩ := second_countable_topology.is_open_generated_countable α in
⟨assume a, ⟨{s | a ∈ s ∧ s ∈ b},
countable_subset (assume x ⟨_, hx⟩, hx) hb, by rw [eq, nhds_generate_from]⟩⟩
lemma is_open_generated_countable_inter [second_countable_topology α] :
∃b:set (set α), countable b ∧ ∅ ∉ b ∧ is_topological_basis b :=
let ⟨b, hb₁, hb₂⟩ := second_countable_topology.is_open_generated_countable α in
let b' := (λs, ⋂₀ s) '' {s:set (set α) | finite s ∧ s ⊆ b ∧ ⋂₀ s ≠ ∅} in
⟨b',
countable_image $ countable_subset (by simp {contextual:=tt}) (countable_set_of_finite_subset hb₁),
assume ⟨s, ⟨_, _, hn⟩, hp⟩, hn hp,
is_topological_basis_of_subbasis hb₂⟩
instance second_countable_topology.to_separable_space
[second_countable_topology α] : separable_space α :=
let ⟨b, hb₁, hb₂, hb₃, hb₄, eq⟩ := is_open_generated_countable_inter α in
have nhds_eq : ∀a, nhds a = (⨅ s : {s : set α // a ∈ s ∧ s ∈ b}, principal s.val),
by intro a; rw [eq, nhds_generate_from]; simp [infi_subtype],
have ∀s∈b, ∃a, a ∈ s, from assume s hs, exists_mem_of_ne_empty $ assume eq, hb₂ $ eq ▸ hs,
have ∃f:∀s∈b, α, ∀s h, f s h ∈ s, by simp only [skolem] at this; exact this,
let ⟨f, hf⟩ := this in
⟨⟨(⋃s∈b, ⋃h:s∈b, {f s h}),
countable_bUnion hb₁ (by simp [countable_Union_Prop]),
set.ext $ assume a,
have a ∈ (⋃₀ b), by rw [hb₄]; exact trivial,
let ⟨t, ht₁, ht₂⟩ := this in
have w : {s : set α // a ∈ s ∧ s ∈ b}, from ⟨t, ht₂, ht₁⟩,
suffices (⨅ (x : {s // a ∈ s ∧ s ∈ b}), principal (x.val ∩ ⋃s (h₁ h₂ : s ∈ b), {f s h₂})) ≠ ⊥,
by simpa [closure_eq_nhds, nhds_eq, infi_inf w],
infi_neq_bot_of_directed ⟨a⟩
(assume ⟨s₁, has₁, hs₁⟩ ⟨s₂, has₂, hs₂⟩,
have a ∈ s₁ ∩ s₂, from ⟨has₁, has₂⟩,
let ⟨s₃, hs₃, has₃, hs⟩ := hb₃ _ hs₁ _ hs₂ _ this in
⟨⟨s₃, has₃, hs₃⟩, begin
simp only [le_principal_iff, mem_principal_sets],
simp at hs, split; apply inter_subset_inter_right; simp [hs]
end⟩)
(assume ⟨s, has, hs⟩,
have s ∩ (⋃ (s : set α) (H h : s ∈ b), {f s h}) ≠ ∅,
from ne_empty_of_mem ⟨hf _ hs, mem_bUnion hs $ (mem_Union_eq _ _).mpr ⟨hs, by simp⟩⟩,
by simp [this]) ⟩⟩
end topological_space
section limit
variables {α : Type u} [inhabited α] [topological_space α]
open classical
/-- If `f` is a filter, then `lim f` is a limit of the filter, if it exists. -/
noncomputable def lim (f : filter α) : α := epsilon $ λa, f ≤ nhds a
lemma lim_spec {f : filter α} (h : ∃a, f ≤ nhds a) : f ≤ nhds (lim f) := epsilon_spec h
variables [t2_space α] {f : filter α}
lemma lim_eq {a : α} (hf : f ≠ ⊥) (h : f ≤ nhds a) : lim f = a :=
eq_of_nhds_neq_bot $ neq_bot_of_le_neq_bot hf $ le_inf (lim_spec ⟨_, h⟩) h
@[simp] lemma lim_nhds_eq {a : α} : lim (nhds a) = a :=
lim_eq nhds_neq_bot (le_refl _)
@[simp] lemma lim_nhds_eq_of_closure {a : α} {s : set α} (h : a ∈ closure s) :
lim (nhds a ⊓ principal s) = a :=
lim_eq begin rw [closure_eq_nhds] at h, exact h end inf_le_left
end limit
|
dc267467a8cf20bebe724b2cdd21eb0397719b4f | 4727251e0cd73359b15b664c3170e5d754078599 | /src/set_theory/cardinal/finite.lean | 31afa0177383ebe19bf2767edd5dda8bd46315a1 | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 1,327 | lean | /-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import set_theory.cardinal.basic
/-!
# Finite Cardinality Functions
## Main Definitions
* `nat.card α` is the cardinality of `α` as a natural number.
If `α` is infinite, `nat.card α = 0`.
* `enat.card α` is the cardinality of `α` as an extended natural number.
If `α` is infinite, `enat.card α = ⊤`.
-/
open cardinal
noncomputable theory
variable {α : Type*}
namespace nat
/-- `nat.card α` is the cardinality of `α` as a natural number.
If `α` is infinite, `nat.card α = 0`. -/
protected def card (α : Type*) : ℕ := (mk α).to_nat
@[simp]
lemma card_eq_fintype_card [fintype α] : nat.card α = fintype.card α := mk_to_nat_eq_card
@[simp]
lemma card_eq_zero_of_infinite [infinite α] : nat.card α = 0 := mk_to_nat_of_infinite
end nat
namespace enat
/-- `enat.card α` is the cardinality of `α` as an extended natural number.
If `α` is infinite, `enat.card α = ⊤`. -/
def card (α : Type*) : enat := (mk α).to_enat
@[simp]
lemma card_eq_coe_fintype_card [fintype α] : card α = fintype.card α := mk_to_enat_eq_coe_card
@[simp]
lemma card_eq_top_of_infinite [infinite α] : card α = ⊤ := mk_to_enat_of_infinite
end enat
|
dc0fc3148e9673aa5b237966873bbdf86d11caff | efa51dd2edbbbbd6c34bd0ce436415eb405832e7 | /20150803_CADE/examples/ex5.lean | bfa6e974a645f8ecb48343441193677d5c622b43 | [
"Apache-2.0"
] | permissive | leanprover/presentations | dd031a05bcb12c8855676c77e52ed84246bd889a | 3ce2d132d299409f1de269fa8e95afa1333d644e | refs/heads/master | 1,688,703,388,796 | 1,686,838,383,000 | 1,687,465,742,000 | 29,750,158 | 12 | 9 | Apache-2.0 | 1,540,211,670,000 | 1,422,042,683,000 | Lean | UTF-8 | Lean | false | false | 585 | lean | open nat
inductive list (A : Type) :=
| nil {} : list A
| cons : A → list A → list A
open list
infixr `::` := cons
check 1 :: 2 :: nil
variable {A : Type}
definition append : list A → list A → list A
| nil ys := ys
| (x::xs) ys := x :: append xs ys
infix `++` := append
eval (1::nil) ++ (2::3::nil)
theorem nil_append (l : list A) : nil ++ l = l :=
rfl
theorem append_nil : ∀ (l : list A), l ++ nil = l
| nil := rfl
| (x::xs) := calc
x::xs ++ nil = x :: (xs ++ nil) : rfl
... = x :: xs : append_nil
check append_nil (2::3::nil)
|
2c7c5456e98b889c881585e87ca4a6f3a9518941 | 88fb7558b0636ec6b181f2a548ac11ad3919f8a5 | /tests/lean/quote_error_pos.lean | d4810fe782ef30beb917f6b5987f7dd136e219a3 | [
"Apache-2.0"
] | permissive | moritayasuaki/lean | 9f666c323cb6fa1f31ac597d777914aed41e3b7a | ae96ebf6ee953088c235ff7ae0e8c95066ba8001 | refs/heads/master | 1,611,135,440,814 | 1,493,852,869,000 | 1,493,852,869,000 | 90,269,903 | 0 | 0 | null | 1,493,906,291,000 | 1,493,906,291,000 | null | UTF-8 | Lean | false | false | 362 | lean | open tactic
meta def apply_zero_add (a : pexpr) : tactic unit :=
to_expr `(zero_add %%a) >>= exact
example (a : nat) : 0 + a = a :=
begin
apply_zero_add `(tt), -- Error should be here
end
meta def apply_zero_add2 (a : pexpr) : tactic unit :=
`[apply zero_add %%a]
example (a : nat) : 0 + a = a :=
begin
apply_zero_add2 `(tt), -- Error should be here
end
|
ce94368f46259101f4c3abd3281c248796d0bb2c | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/ring_theory/noetherian_auto.lean | 1a520403790234ea8067924cb6bb6c06a2074a5d | [] | 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 | 16,320 | lean | /-
Copyright (c) 2018 Mario Carneiro and Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kevin Buzzard
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebraic_geometry.prime_spectrum
import Mathlib.data.multiset.finset_ops
import Mathlib.linear_algebra.linear_independent
import Mathlib.order.order_iso_nat
import Mathlib.order.compactly_generated
import Mathlib.ring_theory.ideal.operations
import Mathlib.PostPort
universes u_1 u_2 u_3 l
namespace Mathlib
/-!
# Noetherian rings and modules
The following are equivalent for a module M over a ring R:
1. Every increasing chain of submodule M₁ ⊆ M₂ ⊆ M₃ ⊆ ⋯ eventually stabilises.
2. Every submodule is finitely generated.
A module satisfying these equivalent conditions is said to be a *Noetherian* R-module.
A ring is a *Noetherian ring* if it is Noetherian as a module over itself.
## Main definitions
Let `R` be a ring and let `M` and `P` be `R`-modules. Let `N` be an `R`-submodule of `M`.
* `fg N : Prop` is the assertion that `N` is finitely generated as an `R`-module.
* `is_noetherian R M` is the proposition that `M` is a Noetherian `R`-module. It is a class,
implemented as the predicate that all `R`-submodules of `M` are finitely generated.
## Main statements
* `exists_sub_one_mem_and_smul_eq_zero_of_fg_of_le_smul` is Nakayama's lemma, in the following form:
if N is a finitely generated submodule of an ambient R-module M and I is an ideal of R
such that N ⊆ IN, then there exists r ∈ 1 + I such that rN = 0.
* `is_noetherian_iff_well_founded` is the theorem that an R-module M is Noetherian iff
`>` is well-founded on `submodule R M`.
Note that the Hilbert basis theorem, that if a commutative ring R is Noetherian then so is R[X],
is proved in `ring_theory.polynomial`.
## References
* [M. F. Atiyah and I. G. Macdonald, *Introduction to commutative algebra*][atiyah-macdonald]
* [samuel]
## Tags
Noetherian, noetherian, Noetherian ring, Noetherian module, noetherian ring, noetherian module
-/
namespace submodule
/-- A submodule of `M` is finitely generated if it is the span of a finite subset of `M`. -/
def fg {R : Type u_1} {M : Type u_2} [semiring R] [add_comm_monoid M] [semimodule R M]
(N : submodule R M) :=
∃ (S : finset M), span R ↑S = N
theorem fg_def {R : Type u_1} {M : Type u_2} [semiring R] [add_comm_monoid M] [semimodule R M]
{N : submodule R M} : fg N ↔ ∃ (S : set M), set.finite S ∧ span R S = N :=
sorry
/-- Nakayama's Lemma. Atiyah-Macdonald 2.5, Eisenbud 4.7, Matsumura 2.2, Stacks 00DV -/
theorem exists_sub_one_mem_and_smul_eq_zero_of_fg_of_le_smul {R : Type u_1} [comm_ring R]
{M : Type u_2} [add_comm_group M] [module R M] (I : ideal R) (N : submodule R M) (hn : fg N)
(hin : N ≤ I • N) : ∃ (r : R), r - 1 ∈ I ∧ ∀ (n : M), n ∈ N → r • n = 0 :=
sorry
theorem fg_bot {R : Type u_1} {M : Type u_2} [semiring R] [add_comm_monoid M] [semimodule R M] :
fg ⊥ :=
Exists.intro ∅
(eq.mpr (id (Eq._oldrec (Eq.refl (span R ↑∅ = ⊥)) finset.coe_empty))
(eq.mpr (id (Eq._oldrec (Eq.refl (span R ∅ = ⊥)) span_empty)) (Eq.refl ⊥)))
theorem fg_sup {R : Type u_1} {M : Type u_2} [semiring R] [add_comm_monoid M] [semimodule R M]
{N₁ : submodule R M} {N₂ : submodule R M} (hN₁ : fg N₁) (hN₂ : fg N₂) : fg (N₁ ⊔ N₂) :=
sorry
theorem fg_map {R : Type u_1} {M : Type u_2} [semiring R] [add_comm_monoid M] [semimodule R M]
{P : Type u_3} [add_comm_monoid P] [semimodule R P] {f : linear_map R M P} {N : submodule R M}
(hs : fg N) : fg (map f N) :=
sorry
theorem fg_of_fg_map {R : Type u_1} {M : Type u_2} {P : Type u_3} [ring R] [add_comm_group M]
[module R M] [add_comm_group P] [module R P] (f : linear_map R M P) (hf : linear_map.ker f = ⊥)
{N : submodule R M} (hfn : fg (map f N)) : fg N :=
sorry
theorem fg_top {R : Type u_1} {M : Type u_2} [ring R] [add_comm_group M] [module R M]
(N : submodule R M) : fg ⊤ ↔ fg N :=
sorry
theorem fg_of_linear_equiv {R : Type u_1} {M : Type u_2} [semiring R] [add_comm_monoid M]
[semimodule R M] {P : Type u_3} [add_comm_monoid P] [semimodule R P] (e : linear_equiv R M P)
(h : fg ⊤) : fg ⊤ :=
linear_equiv.range (linear_equiv.symm e) ▸ map_top ↑(linear_equiv.symm e) ▸ fg_map h
theorem fg_prod {R : Type u_1} {M : Type u_2} [semiring R] [add_comm_monoid M] [semimodule R M]
{P : Type u_3} [add_comm_monoid P] [semimodule R P] {sb : submodule R M} {sc : submodule R P}
(hsb : fg sb) (hsc : fg sc) : fg (prod sb sc) :=
sorry
/-- If 0 → M' → M → M'' → 0 is exact and M' and M'' are
finitely generated then so is M. -/
theorem fg_of_fg_map_of_fg_inf_ker {R : Type u_1} {M : Type u_2} {P : Type u_3} [ring R]
[add_comm_group M] [module R M] [add_comm_group P] [module R P] (f : linear_map R M P)
{s : submodule R M} (hs1 : fg (map f s)) (hs2 : fg (s ⊓ linear_map.ker f)) : fg s :=
sorry
theorem singleton_span_is_compact_element {R : Type u_1} {M : Type u_2} [semiring R]
[add_comm_monoid M] [semimodule R M] (x : M) :
complete_lattice.is_compact_element (span R (singleton x)) :=
sorry
/-- Finitely generated submodules are precisely compact elements in the submodule lattice -/
theorem fg_iff_compact {R : Type u_1} {M : Type u_2} [semiring R] [add_comm_monoid M]
[semimodule R M] (s : submodule R M) : fg s ↔ complete_lattice.is_compact_element s :=
sorry
end submodule
/--
`is_noetherian R M` is the proposition that `M` is a Noetherian `R`-module,
implemented as the predicate that all `R`-submodules of `M` are finitely generated.
-/
class is_noetherian (R : Type u_1) (M : Type u_2) [semiring R] [add_comm_monoid M] [semimodule R M]
where
noetherian : ∀ (s : submodule R M), submodule.fg s
theorem is_noetherian_submodule {R : Type u_1} {M : Type u_2} [ring R] [add_comm_group M]
[module R M] {N : submodule R M} :
is_noetherian R ↥N ↔ ∀ (s : submodule R M), s ≤ N → submodule.fg s :=
sorry
theorem is_noetherian_submodule_left {R : Type u_1} {M : Type u_2} [ring R] [add_comm_group M]
[module R M] {N : submodule R M} :
is_noetherian R ↥N ↔ ∀ (s : submodule R M), submodule.fg (N ⊓ s) :=
sorry
theorem is_noetherian_submodule_right {R : Type u_1} {M : Type u_2} [ring R] [add_comm_group M]
[module R M] {N : submodule R M} :
is_noetherian R ↥N ↔ ∀ (s : submodule R M), submodule.fg (s ⊓ N) :=
sorry
protected instance is_noetherian_submodule' {R : Type u_1} {M : Type u_2} [ring R]
[add_comm_group M] [module R M] [is_noetherian R M] (N : submodule R M) : is_noetherian R ↥N :=
iff.mpr is_noetherian_submodule
fun (_x : submodule R M) (_x_1 : _x ≤ N) => is_noetherian.noetherian _x
theorem is_noetherian_of_surjective {R : Type u_1} (M : Type u_2) {P : Type u_3} [ring R]
[add_comm_group M] [add_comm_group P] [module R M] [module R P] (f : linear_map R M P)
(hf : linear_map.range f = ⊤) [is_noetherian R M] : is_noetherian R P :=
sorry
theorem is_noetherian_of_linear_equiv {R : Type u_1} {M : Type u_2} {P : Type u_3} [ring R]
[add_comm_group M] [add_comm_group P] [module R M] [module R P] (f : linear_equiv R M P)
[is_noetherian R M] : is_noetherian R P :=
is_noetherian_of_surjective M (linear_equiv.to_linear_map f) (linear_equiv.range f)
theorem is_noetherian_of_injective {R : Type u_1} {M : Type u_2} {P : Type u_3} [ring R]
[add_comm_group M] [add_comm_group P] [module R M] [module R P] [is_noetherian R P]
(f : linear_map R M P) (hf : linear_map.ker f = ⊥) : is_noetherian R M :=
is_noetherian_of_linear_equiv (linear_equiv.symm (linear_equiv.of_injective f hf))
theorem fg_of_injective {R : Type u_1} {M : Type u_2} {P : Type u_3} [ring R] [add_comm_group M]
[add_comm_group P] [module R M] [module R P] [is_noetherian R P] {N : submodule R M}
(f : linear_map R M P) (hf : linear_map.ker f = ⊥) : submodule.fg N :=
is_noetherian.noetherian N
protected instance is_noetherian_prod {R : Type u_1} {M : Type u_2} {P : Type u_3} [ring R]
[add_comm_group M] [add_comm_group P] [module R M] [module R P] [is_noetherian R M]
[is_noetherian R P] : is_noetherian R (M × P) :=
is_noetherian.mk
fun (s : submodule R (M × P)) =>
submodule.fg_of_fg_map_of_fg_inf_ker (linear_map.snd R M P)
(is_noetherian.noetherian (submodule.map (linear_map.snd R M P) s))
((fun
(this :
s ⊓ linear_map.ker (linear_map.snd R M P) ≤ linear_map.range (linear_map.inl R M P)) =>
linear_map.map_comap_eq_self this ▸
submodule.fg_map
(is_noetherian.noetherian
(submodule.comap (linear_map.inl R M P)
(s ⊓ linear_map.ker (linear_map.snd R M P)))))
fun (x : M × P) (_x : x ∈ s ⊓ linear_map.ker (linear_map.snd R M P)) => sorry)
protected instance is_noetherian_pi {R : Type u_1} {ι : Type u_2} {M : ι → Type u_3} [ring R]
[(i : ι) → add_comm_group (M i)] [(i : ι) → module R (M i)] [fintype ι]
[∀ (i : ι), is_noetherian R (M i)] : is_noetherian R ((i : ι) → M i) :=
sorry
theorem is_noetherian_iff_well_founded {R : Type u_1} {M : Type u_2} [ring R] [add_comm_group M]
[module R M] : is_noetherian R M ↔ well_founded gt :=
sorry
theorem well_founded_submodule_gt (R : Type u_1) (M : Type u_2) [ring R] [add_comm_group M]
[module R M] [is_noetherian R M] : well_founded gt :=
iff.mp is_noetherian_iff_well_founded
theorem finite_of_linear_independent {R : Type u_1} {M : Type u_2} [comm_ring R] [nontrivial R]
[add_comm_group M] [module R M] [is_noetherian R M] {s : set M}
(hs : linear_independent R coe) : set.finite s :=
sorry
/-- A module is Noetherian iff every nonempty set of submodules has a maximal submodule among them. -/
theorem set_has_maximal_iff_noetherian {R : Type u_1} {M : Type u_2} [ring R] [add_comm_group M]
[module R M] :
(∀ (a : set (submodule R M)),
set.nonempty a →
∃ (M' : submodule R M),
∃ (H : M' ∈ a), ∀ (I : submodule R M), I ∈ a → M' ≤ I → I = M') ↔
is_noetherian R M :=
sorry
/-- If `∀ I > J, P I` implies `P J`, then `P` holds for all submodules. -/
theorem is_noetherian.induction {R : Type u_1} {M : Type u_2} [ring R] [add_comm_group M]
[module R M] [is_noetherian R M] {P : submodule R M → Prop}
(hgt : ∀ (I : submodule R M), (∀ (J : submodule R M), J > I → P J) → P I) (I : submodule R M) :
P I :=
well_founded.recursion (well_founded_submodule_gt R M) I hgt
/--
A ring is Noetherian if it is Noetherian as a module over itself,
i.e. all its ideals are finitely generated.
-/
def is_noetherian_ring (R : Type u_1) [ring R] := is_noetherian R R
protected instance is_noetherian_ring.to_is_noetherian {R : Type u_1} [ring R]
[is_noetherian_ring R] : is_noetherian R R :=
id
protected instance ring.is_noetherian_of_fintype (R : Type u_1) (M : Type u_2) [fintype M] [ring R]
[add_comm_group M] [module R M] : is_noetherian R M :=
let _inst : (p : Prop) → Decidable p := classical.dec;
is_noetherian.mk
fun (s : submodule R M) =>
Exists.intro (set.to_finset ↑s)
(eq.mpr
(id
(Eq._oldrec (Eq.refl (submodule.span R ↑(set.to_finset ↑s) = s))
(set.coe_to_finset ↑s)))
(eq.mpr (id (Eq._oldrec (Eq.refl (submodule.span R ↑s = s)) (submodule.span_eq s)))
(Eq.refl s)))
theorem ring.is_noetherian_of_zero_eq_one {R : Type u_1} [ring R] (h01 : 0 = 1) :
is_noetherian_ring R :=
ring.is_noetherian_of_fintype R R
theorem is_noetherian_of_submodule_of_noetherian (R : Type u_1) (M : Type u_2) [ring R]
[add_comm_group M] [module R M] (N : submodule R M) (h : is_noetherian R M) :
is_noetherian R ↥N :=
eq.mpr (id (Eq._oldrec (Eq.refl (is_noetherian R ↥N)) (propext is_noetherian_iff_well_founded)))
(order_embedding.well_founded (order_embedding.dual (submodule.map_subtype.order_embedding N))
(eq.mp (Eq._oldrec (Eq.refl (is_noetherian R M)) (propext is_noetherian_iff_well_founded)) h))
theorem is_noetherian_of_quotient_of_noetherian (R : Type u_1) [ring R] (M : Type u_2)
[add_comm_group M] [module R M] (N : submodule R M) (h : is_noetherian R M) :
is_noetherian R (submodule.quotient N) :=
eq.mpr
(id
(Eq._oldrec (Eq.refl (is_noetherian R (submodule.quotient N)))
(propext is_noetherian_iff_well_founded)))
(order_embedding.well_founded (order_embedding.dual (submodule.comap_mkq.order_embedding N))
(eq.mp (Eq._oldrec (Eq.refl (is_noetherian R M)) (propext is_noetherian_iff_well_founded)) h))
theorem is_noetherian_of_fg_of_noetherian {R : Type u_1} {M : Type u_2} [ring R] [add_comm_group M]
[module R M] (N : submodule R M) [is_noetherian_ring R] (hN : submodule.fg N) :
is_noetherian R ↥N :=
sorry
theorem is_noetherian_of_fg_of_noetherian' {R : Type u_1} {M : Type u_2} [ring R] [add_comm_group M]
[module R M] [is_noetherian_ring R] (h : submodule.fg ⊤) : is_noetherian R M :=
(fun (this : is_noetherian R ↥⊤) => is_noetherian_of_linear_equiv (linear_equiv.of_top ⊤ rfl))
(is_noetherian_of_fg_of_noetherian ⊤ h)
/-- In a module over a noetherian ring, the submodule generated by finitely many vectors is
noetherian. -/
theorem is_noetherian_span_of_finite (R : Type u_1) {M : Type u_2} [ring R] [add_comm_group M]
[module R M] [is_noetherian_ring R] {A : set M} (hA : set.finite A) :
is_noetherian R ↥(submodule.span R A) :=
is_noetherian_of_fg_of_noetherian (submodule.span R A)
(iff.mpr submodule.fg_def (Exists.intro A { left := hA, right := rfl }))
theorem is_noetherian_ring_of_surjective (R : Type u_1) [comm_ring R] (S : Type u_2) [comm_ring S]
(f : R →+* S) (hf : function.surjective ⇑f) [H : is_noetherian_ring R] : is_noetherian_ring S :=
sorry
protected instance is_noetherian_ring_set_range {R : Type u_1} [comm_ring R] {S : Type u_2}
[comm_ring S] (f : R →+* S) [is_noetherian_ring R] : is_noetherian_ring ↥(set.range ⇑f) :=
is_noetherian_ring_of_surjective R (↥(set.range ⇑f))
(ring_hom.cod_restrict f (set.range ⇑f) set.mem_range_self) set.surjective_onto_range
protected instance is_noetherian_ring_range {R : Type u_1} [comm_ring R] {S : Type u_2}
[comm_ring S] (f : R →+* S) [is_noetherian_ring R] : is_noetherian_ring ↥(ring_hom.range f) :=
is_noetherian_ring_of_surjective R (↥(ring_hom.range f))
(ring_hom.cod_restrict' f (ring_hom.range f) (ring_hom.mem_range_self f))
(ring_hom.surjective_onto_range f)
theorem is_noetherian_ring_of_ring_equiv (R : Type u_1) [comm_ring R] {S : Type u_2} [comm_ring S]
(f : R ≃+* S) [is_noetherian_ring R] : is_noetherian_ring S :=
is_noetherian_ring_of_surjective R S (ring_equiv.to_ring_hom f)
(equiv.surjective (ring_equiv.to_equiv f))
namespace submodule
theorem fg_mul {R : Type u_1} {A : Type u_2} [comm_ring R] [ring A] [algebra R A]
(M : submodule R A) (N : submodule R A) (hm : fg M) (hn : fg N) : fg (M * N) :=
sorry
theorem fg_pow {R : Type u_1} {A : Type u_2} [comm_ring R] [ring A] [algebra R A]
(M : submodule R A) (h : fg M) (n : ℕ) : fg (M ^ n) :=
sorry
end submodule
/--In a noetherian ring, every ideal contains a product of prime ideals
([samuel, § 3.3, Lemma 3])-/
theorem exists_prime_spectrum_prod_le {R : Type u_1} [comm_ring R] [is_noetherian_ring R]
(I : ideal R) : ∃ (Z : multiset (prime_spectrum R)), multiset.prod (multiset.map coe Z) ≤ I :=
sorry
/--In a noetherian integral domain which is not a field, every non-zero ideal contains a non-zero
product of prime ideals; in a field, the whole ring is a non-zero ideal containing only 0 as product
or prime ideals ([samuel, § 3.3, Lemma 3])
-/
theorem exists_prime_spectrum_prod_le_and_ne_bot_of_domain {A : Type u_2} [integral_domain A]
[is_noetherian_ring A] (h_fA : ¬is_field A) {I : ideal A} (h_nzI : I ≠ ⊥) :
∃ (Z : multiset (prime_spectrum A)),
multiset.prod (multiset.map coe Z) ≤ I ∧ multiset.prod (multiset.map coe Z) ≠ ⊥ :=
sorry
end Mathlib |
8ba57b7b7c2e289d1ff3678e2b68815f4f64748b | 3d2a7f1582fe5bae4d0bdc2fe86e997521239a65 | /spatial-reasoning/spatial-reasoning-problem-12.lean | cebd9865211d3b334edff32a9a2a18bfd5f76e6c | [] | no_license | own-pt/common-sense-lean | e4fa643ae010459de3d1bf673be7cbc7062563c9 | f672210aecb4172f5bae265e43e6867397e13b1c | refs/heads/master | 1,622,065,660,261 | 1,589,487,533,000 | 1,589,487,533,000 | 254,167,782 | 3 | 2 | null | 1,589,487,535,000 | 1,586,370,214,000 | Lean | UTF-8 | Lean | false | false | 215 | lean | /- Spatial Reasoning Problem 12 -/
/- It can be found at: SpatialQs.txt -/
/- (12) Jane is standing in front of John.
A van is parked in front of John.
John cannot see Jane.
Is the van in front of Jane?-/
|
90abfa7a4f4e8edccb382262292633d791a7b470 | 947b78d97130d56365ae2ec264df196ce769371a | /src/Lean/Meta/Match/MVarRenaming.lean | c7f5647ea3ee9bd6ec200a6e9535b00828430171 | [
"Apache-2.0"
] | permissive | shyamalschandra/lean4 | 27044812be8698f0c79147615b1d5090b9f4b037 | 6e7a883b21eaf62831e8111b251dc9b18f40e604 | refs/heads/master | 1,671,417,126,371 | 1,601,859,995,000 | 1,601,860,020,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,024 | lean | /-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Util.ReplaceExpr
namespace Lean
namespace Meta
/- A mapping from MVarId to MVarId -/
structure MVarRenaming :=
(map : NameMap MVarId := {})
def MVarRenaming.isEmpty (s : MVarRenaming) : Bool :=
s.map.isEmpty
def MVarRenaming.find? (s : MVarRenaming) (mvarId : MVarId) : Option MVarId :=
s.map.find? mvarId
def MVarRenaming.find! (s : MVarRenaming) (mvarId : MVarId) : MVarId :=
(s.find? mvarId).get!
def MVarRenaming.insert (s : MVarRenaming) (mvarId mvarId' : MVarId) : MVarRenaming :=
{ s with map := s.map.insert mvarId mvarId' }
def MVarRenaming.apply (s : MVarRenaming) (e : Expr) : Expr :=
if !e.hasMVar then e
else if s.map.isEmpty then e
else e.replace $ fun e => match e with
| Expr.mvar mvarId _ => match s.map.find? mvarId with
| none => e
| some newMVarId => mkMVar newMVarId
| _ => none
end Meta
end Lean
|
9a3e103d99fb7248500c2f796209af96159b85ce | 80cc5bf14c8ea85ff340d1d747a127dcadeb966f | /src/topology/algebra/group.lean | db1f0b8046b37b1f736763013256b6081017eecf | [
"Apache-2.0"
] | permissive | lacker/mathlib | f2439c743c4f8eb413ec589430c82d0f73b2d539 | ddf7563ac69d42cfa4a1bfe41db1fed521bd795f | refs/heads/master | 1,671,948,326,773 | 1,601,479,268,000 | 1,601,479,268,000 | 298,686,743 | 0 | 0 | Apache-2.0 | 1,601,070,794,000 | 1,601,070,794,000 | null | UTF-8 | Lean | false | false | 20,386 | 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 order.filter.pointwise
import group_theory.quotient_group
import topology.algebra.monoid
import topology.homeomorph
open classical set filter topological_space
open_locale classical topological_space filter
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
section topological_group
/-- 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 has_continuous_add α : Prop :=
(continuous_neg : continuous (λa:α, -a))
/-- A topological group is a group in which the multiplication and inversion operations are
continuous. -/
@[to_additive]
class topological_group (α : Type*) [topological_space α] [group α]
extends has_continuous_mul α : Prop :=
(continuous_inv : continuous (λa:α, a⁻¹))
variables [topological_space α] [group α]
@[to_additive]
lemma continuous_inv [topological_group α] : continuous (λx:α, x⁻¹) :=
topological_group.continuous_inv
@[to_additive, continuity]
lemma continuous.inv [topological_group α] [topological_space β] {f : β → α}
(hf : continuous f) : continuous (λx, (f x)⁻¹) :=
continuous_inv.comp hf
attribute [continuity] continuous.neg
@[to_additive]
lemma continuous_on_inv [topological_group α] {s : set α} : continuous_on (λx:α, x⁻¹) s :=
continuous_inv.continuous_on
@[to_additive]
lemma continuous_on.inv [topological_group α] [topological_space β] {f : β → α} {s : set β}
(hf : continuous_on f s) : continuous_on (λx, (f x)⁻¹) s :=
continuous_inv.comp_continuous_on hf
@[to_additive]
lemma tendsto_inv {α : Type*} [group α]
[topological_space α] [topological_group α] (a : α) :
tendsto (λ x, x⁻¹) (nhds a) (nhds (a⁻¹)) :=
continuous_inv.tendsto a
/-- If a function converges to a value in a multiplicative topological group, then its inverse
converges to the inverse of this value. For the version in normed fields assuming additionally
that the limit is nonzero, use `tendsto.inv'`. -/
@[to_additive]
lemma filter.tendsto.inv [topological_group α] {f : β → α} {x : filter β} {a : α}
(hf : tendsto f x (𝓝 a)) : tendsto (λx, (f x)⁻¹) x (𝓝 a⁻¹) :=
tendsto.comp (continuous_iff_continuous_at.mp topological_group.continuous_inv a) hf
@[to_additive]
lemma continuous_at.inv [topological_group α] [topological_space β] {f : β → α} {x : β}
(hf : continuous_at f x) : continuous_at (λx, (f x)⁻¹) x :=
hf.inv
@[to_additive]
lemma continuous_within_at.inv [topological_group α] [topological_space β] {f : β → α}
{s : set β} {x : β} (hf : continuous_within_at f s x) :
continuous_within_at (λx, (f x)⁻¹) s x :=
hf.inv
@[to_additive]
instance [topological_group α] [topological_space β] [group β] [topological_group β] :
topological_group (α × β) :=
{ continuous_inv := continuous_fst.inv.prod_mk continuous_snd.inv }
attribute [instance] prod.topological_add_group
@[to_additive]
protected def homeomorph.mul_left [topological_group α] (a : α) : α ≃ₜ α :=
{ continuous_to_fun := continuous_const.mul continuous_id,
continuous_inv_fun := continuous_const.mul continuous_id,
.. equiv.mul_left a }
@[to_additive]
lemma is_open_map_mul_left [topological_group α] (a : α) : is_open_map (λ x, a * x) :=
(homeomorph.mul_left a).is_open_map
@[to_additive]
lemma is_closed_map_mul_left [topological_group α] (a : α) : is_closed_map (λ x, a * x) :=
(homeomorph.mul_left a).is_closed_map
@[to_additive]
protected def homeomorph.mul_right
{α : Type*} [topological_space α] [group α] [topological_group α] (a : α) :
α ≃ₜ α :=
{ continuous_to_fun := continuous_id.mul continuous_const,
continuous_inv_fun := continuous_id.mul continuous_const,
.. equiv.mul_right a }
@[to_additive]
lemma is_open_map_mul_right [topological_group α] (a : α) : is_open_map (λ x, x * a) :=
(homeomorph.mul_right a).is_open_map
@[to_additive]
lemma is_closed_map_mul_right [topological_group α] (a : α) : is_closed_map (λ x, x * a) :=
(homeomorph.mul_right a).is_closed_map
@[to_additive]
protected def homeomorph.inv (α : Type*) [topological_space α] [group α] [topological_group α] :
α ≃ₜ α :=
{ continuous_to_fun := continuous_inv,
continuous_inv_fun := continuous_inv,
.. equiv.inv α }
@[to_additive exists_nhds_half]
lemma exists_nhds_split [topological_group α] {s : set α} (hs : s ∈ 𝓝 (1 : α)) :
∃ V ∈ 𝓝 (1 : α), ∀ v w ∈ V, v * w ∈ s :=
begin
have : ((λa:α×α, a.1 * a.2) ⁻¹' s) ∈ 𝓝 ((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 ∈ 𝓝 (1 : α)) :
∃ V ∈ 𝓝 (1 : α), ∀ (v ∈ V) (w ∈ V), v * w⁻¹ ∈ s :=
begin
have : tendsto (λa:α×α, a.1 * (a.2)⁻¹) (𝓝 (1:α) ×ᶠ 𝓝 (1:α)) (𝓝 1),
{ simpa using (@tendsto_fst α α (𝓝 1) (𝓝 1)).mul tendsto_snd.inv },
have : ((λa:α×α, a.1 * (a.2)⁻¹) ⁻¹' s) ∈ 𝓝 (1:α) ×ᶠ 𝓝 (1:α) :=
this (by simpa using hs),
rcases mem_prod_self_iff.1 this with ⟨V, H, H'⟩,
exact ⟨V, H, prod_subset_iff.1 H'⟩
end
@[to_additive exists_nhds_quarter]
lemma exists_nhds_split4 [topological_group α] {u : set α} (hu : u ∈ 𝓝 (1 : α)) :
∃ V ∈ 𝓝 (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]
lemma nhds_one_symm [topological_group α] : comap (λr:α, r⁻¹) (𝓝 (1 : α)) = 𝓝 (1 : α) :=
begin
have lim : tendsto (λr:α, r⁻¹) (𝓝 1) (𝓝 1),
{ simpa using (@tendsto_id α (𝓝 1)).inv },
refine comap_eq_of_inverse _ _ lim lim,
{ funext x, simp },
end
end
@[to_additive]
lemma nhds_translation_mul_inv [topological_group α] (x : α) :
comap (λy:α, y * x⁻¹) (𝓝 1) = 𝓝 x :=
begin
refine comap_eq_of_inverse (λy:α, y * x) _ _ _,
{ funext x; simp },
{ suffices : tendsto (λy:α, y * x⁻¹) (𝓝 x) (𝓝 (x * x⁻¹)), { simpa },
exact tendsto_id.mul tendsto_const_nhds },
{ suffices : tendsto (λy:α, y * x) (𝓝 1) (𝓝 (1 * x)), { simpa },
exact tendsto_id.mul tendsto_const_nhds }
end
@[to_additive]
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 : subgroup α) (n : N.normal)
@[to_additive]
instance {α : Type u} [group α] [topological_space α] (N : subgroup α) :
topological_space (quotient_group.quotient N) :=
by dunfold quotient_group.quotient; apply_instance
open quotient_group
@[to_additive]
lemma quotient_group_saturate {α : Type u} [group α] (N : subgroup α) (s : set α) :
(coe : α → quotient N) ⁻¹' ((coe : α → quotient N) '' s) = (⋃ x : N, (λ y, y*x.1) '' s) :=
begin
ext x,
simp only [mem_preimage, 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], exact hi }⟩ }
end
@[to_additive]
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]
instance topological_group_quotient (n : N.normal) : 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) },
{ exact (continuous_quot_mk.comp continuous_fst).prod_mk
(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 α]
@[continuity] lemma continuous.sub [topological_add_group α] [topological_space β] {f : β → α} {g : β → α}
(hf : continuous f) (hg : continuous g) : continuous (λx, f x - g x) :=
by simp [sub_eq_add_neg]; exact hf.add hg.neg
lemma continuous_sub [topological_add_group α] : continuous (λp:α×α, p.1 - p.2) :=
continuous_fst.sub continuous_snd
lemma continuous_on.sub [topological_add_group α] [topological_space β] {f : β → α} {g : β → α} {s : set β}
(hf : continuous_on f s) (hg : continuous_on g s) : continuous_on (λx, f x - g x) s :=
continuous_sub.comp_continuous_on (hf.prod hg)
lemma filter.tendsto.sub [topological_add_group α] {f : β → α} {g : β → α} {x : filter β} {a b : α}
(hf : tendsto f x (𝓝 a)) (hg : tendsto g x (𝓝 b)) : tendsto (λx, f x - g x) x (𝓝 (a - b)) :=
by simp [sub_eq_add_neg]; exact hf.add hg.neg
lemma nhds_translation [topological_add_group α] (x : α) : comap (λy:α, y - x) (𝓝 0) = 𝓝 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 ×ᶠ Z) Z)
namespace add_group_with_zero_nhd
variables (α) [add_group_with_zero_nhd α]
local notation `Z` := add_group_with_zero_nhd.Z
@[priority 100] -- see Note [lower instance priority]
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
sub_Z.comp (tendsto.prod_mk this tendsto_id),
by simpa
lemma add_Z : tendsto (λp:α×α, p.1 + p.2) (Z α ×ᶠ Z α) (Z α) :=
suffices tendsto (λp:α×α, p.1 - -p.2) (Z α ×ᶠ Z α) (Z α),
by simpa [sub_eq_add_neg],
sub_Z.comp (tendsto.prod_mk tendsto_fst (neg_Z.comp tendsto_snd))
lemma exists_Z_half {s : set α} (hs : s ∈ Z α) : ∃ V ∈ Z α, ∀ (v ∈ V) (w ∈ V), v + w ∈ s :=
begin
have : ((λa:α×α, a.1 + a.2) ⁻¹' s) ∈ Z α ×ᶠ Z α := add_Z (by simpa using hs),
rcases mem_prod_self_iff.1 this with ⟨V, H, H'⟩,
exact ⟨V, H, prod_subset_iff.1 H'⟩
end
lemma nhds_eq (a : α) : 𝓝 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 t0 b hbt },
{ rintros _ ⟨c, hb, rfl⟩,
refine (Z α).sets_of_superset ht (assume x hxt, _),
simpa [add_assoc] using eqt _ hxt _ hb }
end)
lemma nhds_zero_eq_Z : 𝓝 0 = Z α := by simp [nhds_eq]; exact filter.map_id
@[priority 100] -- see Note [lower instance priority]
instance : has_continuous_add α :=
⟨ 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)) (Z α ×ᶠ Z α)
(map (λx:α, (a + b) + x) (Z α)),
{ simpa [(∘), add_comm, add_left_comm] },
exact tendsto_map.comp add_Z
end ⟩
@[priority 100] -- see Note [lower instance priority]
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 [(∘), add_comm, sub_eq_add_neg] using this },
exact tendsto_map.comp neg_Z
end⟩
end add_group_with_zero_nhd
section filter_mul
section
variables [topological_space α] [group α] [topological_group α]
@[to_additive]
lemma is_open_mul_left {s t : set α} : is_open t → is_open (s * t) := λ ht,
begin
have : ∀a, is_open ((λ (x : α), a * x) '' t),
assume a, apply is_open_map_mul_left, exact ht,
rw ← Union_mul_left_image,
exact is_open_Union (λa, is_open_Union $ λha, this _),
end
@[to_additive]
lemma is_open_mul_right {s t : set α} : is_open s → is_open (s * t) := λ hs,
begin
have : ∀a, is_open ((λ (x : α), x * a) '' s),
assume a, apply is_open_map_mul_right, exact hs,
rw ← Union_mul_right_image,
exact is_open_Union (λa, is_open_Union $ λha, this _),
end
variables (α)
lemma topological_group.t1_space (h : @is_closed α _ {1}) : t1_space α :=
⟨assume x, by { convert is_closed_map_mul_right x _ h, simp }⟩
lemma topological_group.regular_space [t1_space α] : regular_space α :=
⟨assume s a hs ha,
let f := λ p : α × α, p.1 * (p.2)⁻¹ in
have hf : continuous f :=
continuous_mul.comp (continuous_fst.prod_mk (continuous_inv.comp continuous_snd)),
-- a ∈ -s implies f (a, 1) ∈ -s, and so (a, 1) ∈ f⁻¹' (-s);
-- and so can find t₁ t₂ open such that a ∈ t₁ × t₂ ⊆ f⁻¹' (-s)
let ⟨t₁, t₂, ht₁, ht₂, a_mem_t₁, one_mem_t₂, t_subset⟩ :=
is_open_prod_iff.1 (hf _ (is_open_compl_iff.2 hs)) a (1:α) (by simpa [f]) in
begin
use s * t₂,
use is_open_mul_left ht₂,
use λ x hx, ⟨x, 1, hx, one_mem_t₂, mul_one _⟩,
apply inf_principal_eq_bot,
rw mem_nhds_sets_iff,
refine ⟨t₁, _, ht₁, a_mem_t₁⟩,
rintros x hx ⟨y, z, hy, hz, yz⟩,
have : x * z⁻¹ ∈ sᶜ := (prod_subset_iff.1 t_subset) x hx z hz,
have : x * z⁻¹ ∈ s, rw ← yz, simpa,
contradiction
end⟩
local attribute [instance] topological_group.regular_space
lemma topological_group.t2_space [t1_space α] : t2_space α := regular_space.t2_space α
end
section
/-! Some results about an open set containing the product of two sets in a topological group. -/
variables [topological_space α] [group α] [topological_group α]
/-- Given a open neighborhood `U` of `1` there is a open neighborhood `V` of `1`
such that `VV ⊆ U`. -/
@[to_additive "Given a open neighborhood `U` of `0` there is a open neighborhood `V` of `0`
such that `V + V ⊆ U`."]
lemma one_open_separated_mul {U : set α} (h1U : is_open U) (h2U : (1 : α) ∈ U) :
∃ V : set α, is_open V ∧ (1 : α) ∈ V ∧ V * V ⊆ U :=
begin
rcases exists_nhds_square (continuous_mul U h1U) (by simp only [mem_preimage, one_mul, h2U] :
((1 : α), (1 : α)) ∈ (λ p : α × α, p.1 * p.2) ⁻¹' U) with ⟨V, h1V, h2V, h3V⟩,
refine ⟨V, h1V, h2V, _⟩,
rwa [← image_subset_iff, image_mul_prod] at h3V
end
/-- Given a compact set `K` inside an open set `U`, there is a open neighborhood `V` of `1`
such that `KV ⊆ U`. -/
@[to_additive "Given a compact set `K` inside an open set `U`, there is a open neighborhood `V` of `0`
such that `K + V ⊆ U`."]
lemma compact_open_separated_mul {K U : set α} (hK : is_compact K) (hU : is_open U) (hKU : K ⊆ U) :
∃ V : set α, is_open V ∧ (1 : α) ∈ V ∧ K * V ⊆ U :=
begin
let W : α → set α := λ x, (λ y, x * y) ⁻¹' U,
have h1W : ∀ x, is_open (W x) := λ x, continuous_mul_left x U hU,
have h2W : ∀ x ∈ K, (1 : α) ∈ W x := λ x hx, by simp only [mem_preimage, mul_one, hKU hx],
choose V hV using λ x : K, one_open_separated_mul (h1W x) (h2W x.1 x.2),
let X : K → set α := λ x, (λ y, (x : α)⁻¹ * y) ⁻¹' (V x),
cases hK.elim_finite_subcover X (λ x, continuous_mul_left x⁻¹ (V x) (hV x).1) _ with t ht, swap,
{ intros x hx, rw [mem_Union], use ⟨x, hx⟩, rw [mem_preimage], convert (hV _).2.1,
simp only [mul_left_inv, subtype.coe_mk] },
refine ⟨⋂ x ∈ t, V x, is_open_bInter (finite_mem_finset _) (λ x hx, (hV x).1), _, _⟩,
{ simp only [mem_Inter], intros x hx, exact (hV x).2.1 },
rintro _ ⟨x, y, hx, hy, rfl⟩, simp only [mem_Inter] at hy,
have := ht hx, simp only [mem_Union, mem_preimage] at this, rcases this with ⟨z, h1z, h2z⟩,
have : (z : α)⁻¹ * x * y ∈ W z := (hV z).2.2 (mul_mem_mul h2z (hy z h1z)),
rw [mem_preimage] at this, convert this using 1, simp only [mul_assoc, mul_inv_cancel_left]
end
/-- A compact set is covered by finitely many left multiplicative translates of a set
with non-empty interior. -/
@[to_additive "A compact set is covered by finitely many left additive translates of a set
with non-empty interior."]
lemma compact_covered_by_mul_left_translates {K V : set α} (hK : is_compact K)
(hV : (interior V).nonempty) : ∃ t : finset α, K ⊆ ⋃ g ∈ t, (λ h, g * h) ⁻¹' V :=
begin
cases hV with g₀ hg₀,
rcases is_compact.elim_finite_subcover hK (λ x : α, interior $ (λ h, x * h) ⁻¹' V) _ _ with ⟨t, ht⟩,
{ refine ⟨t, subset.trans ht _⟩,
apply Union_subset_Union, intro g, apply Union_subset_Union, intro hg, apply interior_subset },
{ intro g, apply is_open_interior },
{ intros g hg, rw [mem_Union], use g₀ * g⁻¹,
apply preimage_interior_subset_interior_preimage, exact continuous_const.mul continuous_id,
rwa [mem_preimage, inv_mul_cancel_right] }
end
end
section
variables [topological_space α] [comm_group α] [topological_group α]
@[to_additive]
lemma nhds_mul (x y : α) : 𝓝 (x * y) = 𝓝 x * 𝓝 y :=
filter_eq $ set.ext $ assume s,
begin
rw [← nhds_translation_mul_inv x, ← nhds_translation_mul_inv y, ← nhds_translation_mul_inv (x*y)],
split,
{ rintros ⟨t, ht, ts⟩,
rcases exists_nhds_split ht with ⟨V, V_mem, h⟩,
refine ⟨(λa, a * x⁻¹) ⁻¹' V, (λa, a * y⁻¹) ⁻¹' V,
⟨V, V_mem, subset.refl _⟩, ⟨V, V_mem, subset.refl _⟩, _⟩,
rintros a ⟨v, w, v_mem, w_mem, rfl⟩,
apply ts,
simpa [mul_comm, mul_assoc, mul_left_comm] using h (v * x⁻¹) (w * y⁻¹) v_mem w_mem },
{ rintros ⟨a, c, ⟨b, hb, ba⟩, ⟨d, hd, dc⟩, ac⟩,
refine ⟨b ∩ d, inter_mem_sets hb hd, assume v, _⟩,
simp only [preimage_subset_iff, mul_inv_rev, mem_preimage] at *,
rintros ⟨vb, vd⟩,
refine ac ⟨v * y⁻¹, y, _, _, _⟩,
{ rw ← mul_assoc _ _ _ at vb, exact ba _ vb },
{ apply dc y, rw mul_right_inv, exact mem_of_nhds hd },
{ simp only [inv_mul_cancel_right] } }
end
@[to_additive]
lemma nhds_is_mul_hom : is_mul_hom (λx:α, 𝓝 x) := ⟨λ_ _, nhds_mul _ _⟩
end
end filter_mul
|
ccdeb0bbea254990381eed82d3ae7a84bee44a6a | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/analysis/special_functions/complex/arg.lean | ce2eb9bd195aaa59785b80a3a40aff6bea34faad | [
"Apache-2.0"
] | permissive | ramonfmir/mathlib | c5dc8b33155473fab97c38bd3aa6723dc289beaa | 14c52e990c17f5a00c0cc9e09847af16fabbed25 | refs/heads/master | 1,661,979,343,526 | 1,660,830,384,000 | 1,660,830,384,000 | 182,072,989 | 0 | 0 | null | 1,555,585,876,000 | 1,555,585,876,000 | null | UTF-8 | Lean | false | false | 25,317 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import algebra.order.to_interval_mod
import analysis.special_functions.trigonometric.angle
import analysis.special_functions.trigonometric.inverse
/-!
# The argument of a complex number.
We define `arg : ℂ → ℝ`, returing a real number in the range (-π, π],
such that for `x ≠ 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,
while `arg 0` defaults to `0`
-/
noncomputable theory
namespace complex
open_locale complex_conjugate real topological_space
open filter set
/-- `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 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]
lemma cos_arg {x : ℂ} (hx : x ≠ 0) : real.cos (arg x) = x.re / x.abs :=
begin
have habs : 0 < abs x := abs_pos.2 hx,
have him : |im x / abs x| ≤ 1,
{ rw [_root_.abs_div, abs_abs], exact div_le_one_of_le x.abs_im_le_abs x.abs_nonneg },
rw abs_le at him,
rw arg, split_ifs with h₁ h₂ h₂,
{ rw [real.cos_arcsin]; field_simp [real.sqrt_sq, habs.le, *] },
{ rw [real.cos_add_pi, real.cos_arcsin],
{ field_simp [real.sqrt_div (sq_nonneg _), real.sqrt_sq_eq_abs,
_root_.abs_of_neg (not_le.1 h₁), *] },
{ simpa [neg_div] using him.2 },
{ simpa [neg_div, neg_le] using him.1 } },
{ rw [real.cos_sub_pi, real.cos_arcsin],
{ field_simp [real.sqrt_div (sq_nonneg _), real.sqrt_sq_eq_abs,
_root_.abs_of_neg (not_le.1 h₁), *] },
{ simpa [neg_div] using him.2 },
{ simpa [neg_div, neg_le] using him.1 } }
end
@[simp] lemma abs_mul_exp_arg_mul_I (x : ℂ) : ↑(abs x) * exp (arg x * I) = x :=
begin
rcases eq_or_ne x 0 with (rfl|hx),
{ simp },
{ have : abs x ≠ 0 := abs_ne_zero.2 hx,
ext; field_simp [sin_arg, cos_arg hx, this, mul_comm (abs x)] }
end
@[simp] lemma abs_mul_cos_add_sin_mul_I (x : ℂ) :
(abs x * (cos (arg x) + sin (arg x) * I) : ℂ) = x :=
by rw [← exp_mul_I, abs_mul_exp_arg_mul_I]
lemma abs_eq_one_iff (z : ℂ) : abs z = 1 ↔ ∃ θ : ℝ, exp (θ * I) = z :=
begin
refine ⟨λ hz, ⟨arg z, _⟩, _⟩,
{ calc exp (arg z * I) = abs z * exp (arg z * I) : by rw [hz, of_real_one, one_mul]
... = z : abs_mul_exp_arg_mul_I z },
{ rintro ⟨θ, rfl⟩,
exact complex.abs_exp_of_real_mul_I θ },
end
@[simp] lemma range_exp_mul_I : range (λ x : ℝ, exp (x * I)) = metric.sphere 0 1 :=
by { ext x, simp only [mem_sphere_zero_iff_norm, norm_eq_abs, abs_eq_one_iff, mem_range] }
lemma arg_mul_cos_add_sin_mul_I {r : ℝ} (hr : 0 < r) {θ : ℝ} (hθ : θ ∈ Ioc (-π) π) :
arg (r * (cos θ + sin θ * I)) = θ :=
begin
have hπ := real.pi_pos,
simp only [arg, abs_mul, abs_cos_add_sin_mul_I, abs_of_nonneg hr.le, mul_one],
simp only [of_real_mul_re, of_real_mul_im, neg_im, ← of_real_cos, ← of_real_sin,
← mk_eq_add_mul_I, neg_div, mul_div_cancel_left _ hr.ne',
mul_nonneg_iff_right_nonneg_of_pos hr],
by_cases h₁ : θ ∈ Icc (-(π / 2)) (π / 2),
{ rw if_pos, exacts [real.arcsin_sin' h₁, real.cos_nonneg_of_mem_Icc h₁] },
{ rw [mem_Icc, not_and_distrib, not_le, not_le] at h₁, cases h₁,
{ replace hθ := hθ.1,
have hcos : real.cos θ < 0,
{ rw [← neg_pos, ← real.cos_add_pi], refine real.cos_pos_of_mem_Ioo ⟨_, _⟩; linarith },
have hsin : real.sin θ < 0 := real.sin_neg_of_neg_of_neg_pi_lt (by linarith) hθ,
rw [if_neg, if_neg, ← real.sin_add_pi, real.arcsin_sin, add_sub_cancel];
[linarith, linarith, exact hsin.not_le, exact hcos.not_le] },
{ replace hθ := hθ.2,
have hcos : real.cos θ < 0 := real.cos_neg_of_pi_div_two_lt_of_lt h₁ (by linarith),
have hsin : 0 ≤ real.sin θ := real.sin_nonneg_of_mem_Icc ⟨by linarith, hθ⟩,
rw [if_neg, if_pos, ← real.sin_sub_pi, real.arcsin_sin, sub_add_cancel];
[linarith, linarith, exact hsin, exact hcos.not_le] } }
end
lemma arg_cos_add_sin_mul_I {θ : ℝ} (hθ : θ ∈ Ioc (-π) π) :
arg (cos θ + sin θ * I) = θ :=
by rw [← one_mul (_ + _), ← of_real_one, arg_mul_cos_add_sin_mul_I zero_lt_one hθ]
@[simp] lemma arg_zero : arg 0 = 0 := by simp [arg, le_refl]
lemma ext_abs_arg {x y : ℂ} (h₁ : x.abs = y.abs) (h₂ : x.arg = y.arg) : x = y :=
by rw [← abs_mul_exp_arg_mul_I x, ← abs_mul_exp_arg_mul_I y, h₁, h₂]
lemma ext_abs_arg_iff {x y : ℂ} : x = y ↔ abs x = abs y ∧ arg x = arg y :=
⟨λ h, h ▸ ⟨rfl, rfl⟩, and_imp.2 ext_abs_arg⟩
lemma arg_mem_Ioc (z : ℂ) : arg z ∈ Ioc (-π) π :=
begin
have hπ : 0 < π := real.pi_pos,
rcases eq_or_ne z 0 with (rfl|hz), simp [hπ, hπ.le],
rcases exists_unique_add_zsmul_mem_Ioc real.two_pi_pos (arg z) (-π) with ⟨N, hN, -⟩,
rw [two_mul, neg_add_cancel_left, ← two_mul, zsmul_eq_mul] at hN,
rw [← abs_mul_cos_add_sin_mul_I z, ← cos_add_int_mul_two_pi _ N,
← sin_add_int_mul_two_pi _ N],
simp only [← of_real_one, ← of_real_bit0, ← of_real_mul, ← of_real_add, ← of_real_int_cast],
rwa [arg_mul_cos_add_sin_mul_I (abs_pos.2 hz) hN]
end
@[simp] lemma range_arg : range arg = Ioc (-π) π :=
(range_subset_iff.2 arg_mem_Ioc).antisymm (λ x hx, ⟨_, arg_cos_add_sin_mul_I hx⟩)
lemma arg_le_pi (x : ℂ) : arg x ≤ π :=
(arg_mem_Ioc x).2
lemma neg_pi_lt_arg (x : ℂ) : -π < arg x :=
(arg_mem_Ioc x).1
@[simp] lemma arg_nonneg_iff {z : ℂ} : 0 ≤ arg z ↔ 0 ≤ z.im :=
begin
rcases eq_or_ne z 0 with (rfl|h₀), { simp },
calc 0 ≤ arg z ↔ 0 ≤ real.sin (arg z) :
⟨λ h, real.sin_nonneg_of_mem_Icc ⟨h, arg_le_pi z⟩,
by { contrapose!, intro h, exact real.sin_neg_of_neg_of_neg_pi_lt h (neg_pi_lt_arg _) }⟩
... ↔ _ : by rw [sin_arg, le_div_iff (abs_pos.2 h₀), zero_mul]
end
@[simp] lemma arg_neg_iff {z : ℂ} : arg z < 0 ↔ z.im < 0 :=
lt_iff_lt_of_le_iff_le arg_nonneg_iff
lemma arg_real_mul (x : ℂ) {r : ℝ} (hr : 0 < r) : arg (r * x) = arg x :=
begin
rcases eq_or_ne x 0 with (rfl|hx), { rw mul_zero },
conv_lhs { rw [← abs_mul_cos_add_sin_mul_I x, ← mul_assoc, ← of_real_mul,
arg_mul_cos_add_sin_mul_I (mul_pos hr (abs_pos.2 hx)) x.arg_mem_Ioc] }
end
lemma arg_eq_arg_iff {x y : ℂ} (hx : x ≠ 0) (hy : y ≠ 0) :
arg x = arg y ↔ (abs y / abs x : ℂ) * x = y :=
begin
simp only [ext_abs_arg_iff, abs_mul, abs_div, abs_of_real, abs_abs,
div_mul_cancel _ (abs_ne_zero.2 hx), eq_self_iff_true, true_and],
rw [← of_real_div, arg_real_mul],
exact div_pos (abs_pos.2 hy) (abs_pos.2 hx)
end
@[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]
@[simp] 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 _ (abs_ne_zero.2 h)]
end
lemma arg_of_real_of_nonneg {x : ℝ} (hx : 0 ≤ x) : arg x = 0 :=
by simp [arg, hx]
lemma arg_eq_zero_iff {z : ℂ} : arg z = 0 ↔ 0 ≤ z.re ∧ z.im = 0 :=
begin
refine ⟨λ h, _, _⟩,
{ rw [←abs_mul_cos_add_sin_mul_I z, h],
simp [abs_nonneg] },
{ cases z with x y,
rintro ⟨h, rfl : y = 0⟩,
exact arg_of_real_of_nonneg h }
end
lemma arg_eq_pi_iff {z : ℂ} : arg z = π ↔ z.re < 0 ∧ z.im = 0 :=
begin
by_cases h₀ : z = 0, { simp [h₀, lt_irrefl, real.pi_ne_zero.symm] },
split,
{ intro h, rw [← abs_mul_cos_add_sin_mul_I z, h], simp [h₀] },
{ cases z with x y, rintro ⟨h : x < 0, rfl : y = 0⟩,
rw [← arg_neg_one, ← arg_real_mul (-1) (neg_pos.2 h)], simp [← of_real_def] }
end
lemma arg_lt_pi_iff {z : ℂ} : arg z < π ↔ 0 ≤ z.re ∨ z.im ≠ 0 :=
by rw [(arg_le_pi z).lt_iff_ne, not_iff_comm, not_or_distrib, not_le, not_not, arg_eq_pi_iff]
lemma arg_of_real_of_neg {x : ℝ} (hx : x < 0) : arg x = π :=
arg_eq_pi_iff.2 ⟨hx, rfl⟩
lemma arg_eq_pi_div_two_iff {z : ℂ} : arg z = π / 2 ↔ z.re = 0 ∧ 0 < z.im :=
begin
by_cases h₀ : z = 0, { simp [h₀, lt_irrefl, real.pi_div_two_pos.ne] },
split,
{ intro h, rw [← abs_mul_cos_add_sin_mul_I z, h], simp [h₀] },
{ cases z with x y, rintro ⟨rfl : x = 0, hy : 0 < y⟩,
rw [← arg_I, ← arg_real_mul I hy, of_real_mul', I_re, I_im, mul_zero, mul_one] }
end
lemma arg_eq_neg_pi_div_two_iff {z : ℂ} : arg z = - (π / 2) ↔ z.re = 0 ∧ z.im < 0 :=
begin
by_cases h₀ : z = 0, { simp [h₀, lt_irrefl, real.pi_ne_zero] },
split,
{ intro h, rw [← abs_mul_cos_add_sin_mul_I z, h], simp [h₀] },
{ cases z with x y, rintro ⟨rfl : x = 0, hy : y < 0⟩,
rw [← arg_neg_I, ← arg_real_mul (-I) (neg_pos.2 hy), mk_eq_add_mul_I],
simp }
end
lemma arg_of_re_nonneg {x : ℂ} (hx : 0 ≤ x.re) : arg x = real.arcsin (x.im / x.abs) :=
if_pos hx
lemma arg_of_re_neg_of_im_nonneg {x : ℂ} (hx_re : x.re < 0) (hx_im : 0 ≤ x.im) :
arg x = real.arcsin ((-x).im / x.abs) + π :=
by simp only [arg, hx_re.not_le, hx_im, if_true, if_false]
lemma arg_of_re_neg_of_im_neg {x : ℂ} (hx_re : x.re < 0) (hx_im : x.im < 0) :
arg x = real.arcsin ((-x).im / x.abs) - π :=
by simp only [arg, hx_re.not_le, hx_im.not_le, if_false]
lemma arg_of_im_nonneg_of_ne_zero {z : ℂ} (h₁ : 0 ≤ z.im) (h₂ : z ≠ 0) :
arg z = real.arccos (z.re / abs z) :=
by rw [← cos_arg h₂, real.arccos_cos (arg_nonneg_iff.2 h₁) (arg_le_pi _)]
lemma arg_of_im_pos {z : ℂ} (hz : 0 < z.im) : arg z = real.arccos (z.re / abs z) :=
arg_of_im_nonneg_of_ne_zero hz.le (λ h, hz.ne' $ h.symm ▸ rfl)
lemma arg_of_im_neg {z : ℂ} (hz : z.im < 0) : arg z = -real.arccos (z.re / abs z) :=
begin
have h₀ : z ≠ 0, from mt (congr_arg im) hz.ne,
rw [← cos_arg h₀, ← real.cos_neg, real.arccos_cos, neg_neg],
exacts [neg_nonneg.2 (arg_neg_iff.2 hz).le, neg_le.2 (neg_pi_lt_arg z).le]
end
lemma arg_conj (x : ℂ) : arg (conj x) = if arg x = π then π else -arg x :=
begin
simp_rw [arg_eq_pi_iff, arg, neg_im, conj_im, conj_re, abs_conj, neg_div, neg_neg,
real.arcsin_neg, apply_ite has_neg.neg, neg_add, neg_sub, neg_neg, ←sub_eq_add_neg,
sub_neg_eq_add, add_comm π],
rcases lt_trichotomy x.re 0 with (hr|hr|hr); rcases lt_trichotomy x.im 0 with (hi|hi|hi),
{ simp [hr, hr.not_le, hi.le, hi.ne, not_le.2 hi] },
{ simp [hr, hr.not_le, hi] },
{ simp [hr, hr.not_le, hi.ne.symm, hi.le, not_le.2 hi] },
{ simp [hr] },
{ simp [hr] },
{ simp [hr] },
{ simp [hr, hr.le, hi.ne] },
{ simp [hr, hr.le, hr.le.not_lt] },
{ simp [hr, hr.le, hr.le.not_lt] },
end
lemma arg_inv (x : ℂ) : arg x⁻¹ = if arg x = π then π else -arg x :=
begin
rw [←arg_conj, inv_def, mul_comm],
by_cases hx : x = 0,
{ simp [hx] },
{ exact arg_real_mul (conj x) (by simp [hx]) }
end
lemma arg_le_pi_div_two_iff {z : ℂ} : arg z ≤ π / 2 ↔ 0 ≤ re z ∨ im z < 0 :=
begin
cases le_or_lt 0 (re z) with hre hre,
{ simp only [hre, arg_of_re_nonneg hre, real.arcsin_le_pi_div_two, true_or] },
simp only [hre.not_le, false_or],
cases le_or_lt 0 (im z) with him him,
{ simp only [him.not_lt],
rw [iff_false, not_le, arg_of_re_neg_of_im_nonneg hre him, ← sub_lt_iff_lt_add, half_sub,
real.neg_pi_div_two_lt_arcsin, neg_im, neg_div, neg_lt_neg_iff, div_lt_one, ←
_root_.abs_of_nonneg him, abs_im_lt_abs],
exacts [hre.ne, abs_pos.2 $ ne_of_apply_ne re hre.ne] },
{ simp only [him],
rw [iff_true, arg_of_re_neg_of_im_neg hre him],
exact (sub_le_self _ real.pi_pos.le).trans (real.arcsin_le_pi_div_two _) }
end
lemma neg_pi_div_two_le_arg_iff {z : ℂ} : -(π / 2) ≤ arg z ↔ 0 ≤ re z ∨ 0 ≤ im z :=
begin
cases le_or_lt 0 (re z) with hre hre,
{ simp only [hre, arg_of_re_nonneg hre, real.neg_pi_div_two_le_arcsin, true_or] },
simp only [hre.not_le, false_or],
cases le_or_lt 0 (im z) with him him,
{ simp only [him],
rw [iff_true, arg_of_re_neg_of_im_nonneg hre him],
exact (real.neg_pi_div_two_le_arcsin _).trans (le_add_of_nonneg_right real.pi_pos.le) },
{ simp only [him.not_le],
rw [iff_false, not_le, arg_of_re_neg_of_im_neg hre him, sub_lt_iff_lt_add', ← sub_eq_add_neg,
sub_half, real.arcsin_lt_pi_div_two, div_lt_one, neg_im, ← abs_of_neg him, abs_im_lt_abs],
exacts [hre.ne, abs_pos.2 $ ne_of_apply_ne re hre.ne] }
end
@[simp] lemma abs_arg_le_pi_div_two_iff {z : ℂ} : |arg z| ≤ π / 2 ↔ 0 ≤ re z :=
by rw [abs_le, arg_le_pi_div_two_iff, neg_pi_div_two_le_arg_iff, ← or_and_distrib_left, ← not_le,
and_not_self, or_false]
@[simp] lemma arg_conj_coe_angle (x : ℂ) : (arg (conj x) : real.angle) = -arg x :=
begin
by_cases h : arg x = π;
simp [arg_conj, h]
end
@[simp] lemma arg_inv_coe_angle (x : ℂ) : (arg x⁻¹ : real.angle) = -arg x :=
begin
by_cases h : arg x = π;
simp [arg_inv, h]
end
lemma arg_neg_eq_arg_sub_pi_of_im_pos {x : ℂ} (hi : 0 < x.im) : arg (-x) = arg x - π :=
begin
rw [arg_of_im_pos hi, arg_of_im_neg (show (-x).im < 0, from left.neg_neg_iff.2 hi)],
simp [neg_div, real.arccos_neg]
end
lemma arg_neg_eq_arg_add_pi_of_im_neg {x : ℂ} (hi : x.im < 0) : arg (-x) = arg x + π :=
begin
rw [arg_of_im_neg hi, arg_of_im_pos (show 0 < (-x).im, from left.neg_pos_iff.2 hi)],
simp [neg_div, real.arccos_neg, add_comm, ←sub_eq_add_neg]
end
lemma arg_neg_eq_arg_sub_pi_iff {x : ℂ} :
arg (-x) = arg x - π ↔ (0 < x.im ∨ x.im = 0 ∧ x.re < 0) :=
begin
rcases lt_trichotomy x.im 0 with (hi|hi|hi),
{ simp [hi, hi.ne, hi.not_lt, arg_neg_eq_arg_add_pi_of_im_neg, sub_eq_add_neg,
←add_eq_zero_iff_eq_neg, real.pi_ne_zero] },
{ rw (ext rfl hi : x = x.re),
rcases lt_trichotomy x.re 0 with (hr|hr|hr),
{ rw [arg_of_real_of_neg hr, ←of_real_neg, arg_of_real_of_nonneg (left.neg_pos_iff.2 hr).le],
simp [hr] },
{ simp [hr, hi, real.pi_ne_zero] },
{ rw [arg_of_real_of_nonneg hr.le, ←of_real_neg, arg_of_real_of_neg (left.neg_neg_iff.2 hr)],
simp [hr.not_lt, ←add_eq_zero_iff_eq_neg, real.pi_ne_zero] } },
{ simp [hi, arg_neg_eq_arg_sub_pi_of_im_pos] }
end
lemma arg_neg_eq_arg_add_pi_iff {x : ℂ} :
arg (-x) = arg x + π ↔ (x.im < 0 ∨ x.im = 0 ∧ 0 < x.re) :=
begin
rcases lt_trichotomy x.im 0 with (hi|hi|hi),
{ simp [hi, arg_neg_eq_arg_add_pi_of_im_neg] },
{ rw (ext rfl hi : x = x.re),
rcases lt_trichotomy x.re 0 with (hr|hr|hr),
{ rw [arg_of_real_of_neg hr, ←of_real_neg, arg_of_real_of_nonneg (left.neg_pos_iff.2 hr).le],
simp [hr.not_lt, ←two_mul, real.pi_ne_zero] },
{ simp [hr, hi, real.pi_ne_zero.symm] },
{ rw [arg_of_real_of_nonneg hr.le, ←of_real_neg, arg_of_real_of_neg (left.neg_neg_iff.2 hr)],
simp [hr] } },
{ simp [hi, hi.ne.symm, hi.not_lt, arg_neg_eq_arg_sub_pi_of_im_pos, sub_eq_add_neg,
←add_eq_zero_iff_neg_eq, real.pi_ne_zero] }
end
lemma arg_neg_coe_angle {x : ℂ} (hx : x ≠ 0) : (arg (-x) : real.angle) = arg x + π :=
begin
rcases lt_trichotomy x.im 0 with (hi|hi|hi),
{ rw [arg_neg_eq_arg_add_pi_of_im_neg hi, real.angle.coe_add] },
{ rw (ext rfl hi : x = x.re),
rcases lt_trichotomy x.re 0 with (hr|hr|hr),
{ rw [arg_of_real_of_neg hr, ←of_real_neg, arg_of_real_of_nonneg (left.neg_pos_iff.2 hr).le,
←real.angle.coe_add, ←two_mul, real.angle.coe_two_pi, real.angle.coe_zero] },
{ exact false.elim (hx (ext hr hi)) },
{ rw [arg_of_real_of_nonneg hr.le, ←of_real_neg, arg_of_real_of_neg (left.neg_neg_iff.2 hr),
real.angle.coe_zero, zero_add] } },
{ rw [arg_neg_eq_arg_sub_pi_of_im_pos hi, real.angle.coe_sub,
real.angle.sub_coe_pi_eq_add_coe_pi] }
end
lemma arg_mul_cos_add_sin_mul_I_eq_to_Ioc_mod {r : ℝ} (hr : 0 < r) (θ : ℝ) :
arg (r * (cos θ + sin θ * I)) = to_Ioc_mod (-π) real.two_pi_pos θ :=
begin
have hi : to_Ioc_mod (-π) real.two_pi_pos θ ∈ Ioc (-π) π,
{ convert to_Ioc_mod_mem_Ioc _ real.two_pi_pos _,
ring },
convert arg_mul_cos_add_sin_mul_I hr hi using 3,
simp [to_Ioc_mod, cos_add_int_mul_two_pi, sin_add_int_mul_two_pi]
end
lemma arg_cos_add_sin_mul_I_eq_to_Ioc_mod (θ : ℝ) :
arg (cos θ + sin θ * I) = to_Ioc_mod (-π) real.two_pi_pos θ :=
by rw [←one_mul (_ + _), ←of_real_one, arg_mul_cos_add_sin_mul_I_eq_to_Ioc_mod zero_lt_one]
lemma arg_mul_cos_add_sin_mul_I_sub {r : ℝ} (hr : 0 < r) (θ : ℝ) :
arg (r * (cos θ + sin θ * I)) - θ = 2 * π * ⌊(π - θ) / (2 * π)⌋ :=
begin
rw [arg_mul_cos_add_sin_mul_I_eq_to_Ioc_mod hr, to_Ioc_mod_sub_self, to_Ioc_div_eq_floor,
zsmul_eq_mul],
ring_nf
end
lemma arg_cos_add_sin_mul_I_sub (θ : ℝ) :
arg (cos θ + sin θ * I) - θ = 2 * π * ⌊(π - θ) / (2 * π)⌋ :=
by rw [←one_mul (_ + _), ←of_real_one, arg_mul_cos_add_sin_mul_I_sub zero_lt_one]
lemma arg_mul_cos_add_sin_mul_I_coe_angle {r : ℝ} (hr : 0 < r) (θ : real.angle) :
(arg (r * (real.angle.cos θ + real.angle.sin θ * I)) : real.angle) = θ :=
begin
induction θ using real.angle.induction_on,
rw [real.angle.cos_coe, real.angle.sin_coe, real.angle.angle_eq_iff_two_pi_dvd_sub],
use ⌊(π - θ) / (2 * π)⌋,
exact_mod_cast arg_mul_cos_add_sin_mul_I_sub hr θ
end
lemma arg_cos_add_sin_mul_I_coe_angle (θ : real.angle) :
(arg (real.angle.cos θ + real.angle.sin θ * I) : real.angle) = θ :=
by rw [←one_mul (_ + _), ←of_real_one, arg_mul_cos_add_sin_mul_I_coe_angle zero_lt_one]
lemma arg_mul_coe_angle {x y : ℂ} (hx : x ≠ 0) (hy : y ≠ 0) :
(arg (x * y) : real.angle) = arg x + arg y :=
begin
convert arg_mul_cos_add_sin_mul_I_coe_angle (mul_pos (abs_pos.2 hx) (abs_pos.2 hy))
(arg x + arg y : real.angle) using 3,
simp_rw [←real.angle.coe_add, real.angle.sin_coe, real.angle.cos_coe, of_real_cos,
of_real_sin, cos_add_sin_I, of_real_add, add_mul, exp_add, of_real_mul],
rw [mul_assoc, mul_comm (exp _), ←mul_assoc (abs y : ℂ), abs_mul_exp_arg_mul_I, mul_comm y,
←mul_assoc, abs_mul_exp_arg_mul_I]
end
lemma arg_div_coe_angle {x y : ℂ} (hx : x ≠ 0) (hy : y ≠ 0) :
(arg (x / y) : real.angle) = arg x - arg y :=
by rw [div_eq_mul_inv, arg_mul_coe_angle hx (inv_ne_zero hy), arg_inv_coe_angle, sub_eq_add_neg]
@[simp] lemma arg_coe_angle_eq_iff {x y : ℂ} : (arg x : real.angle) = arg y ↔ arg x = arg y :=
begin
split,
{ intro h,
rw real.angle.angle_eq_iff_two_pi_dvd_sub at h,
rcases h with ⟨k, hk⟩,
rw ←sub_eq_zero,
have ha : -(2 * π) < arg x - arg y,
{ linarith only [neg_pi_lt_arg x, arg_le_pi y] },
have hb : arg x - arg y < 2 * π,
{ linarith only [arg_le_pi x, neg_pi_lt_arg y] },
rw [hk, neg_lt, neg_mul_eq_mul_neg, mul_lt_iff_lt_one_right real.two_pi_pos, neg_lt,
←int.cast_one, ←int.cast_neg, int.cast_lt] at ha,
rw [hk, mul_lt_iff_lt_one_right real.two_pi_pos, ←int.cast_one, int.cast_lt] at hb,
have hk' : k = 0,
{ linarith only [ha, hb] },
rw hk' at hk,
simpa using hk },
{ intro h,
rw h }
end
section continuity
variables {x z : ℂ}
lemma arg_eq_nhds_of_re_pos (hx : 0 < x.re) : arg =ᶠ[𝓝 x] λ x, real.arcsin (x.im / x.abs) :=
((continuous_re.tendsto _).eventually (lt_mem_nhds hx)).mono $ λ y hy, arg_of_re_nonneg hy.le
lemma arg_eq_nhds_of_re_neg_of_im_pos (hx_re : x.re < 0) (hx_im : 0 < x.im) :
arg =ᶠ[𝓝 x] λ x, real.arcsin ((-x).im / x.abs) + π :=
begin
suffices h_forall_nhds : ∀ᶠ (y : ℂ) in (𝓝 x), y.re < 0 ∧ 0 < y.im,
from h_forall_nhds.mono (λ y hy, arg_of_re_neg_of_im_nonneg hy.1 hy.2.le),
refine is_open.eventually_mem _ (⟨hx_re, hx_im⟩ : x.re < 0 ∧ 0 < x.im),
exact is_open.and (is_open_lt continuous_re continuous_zero)
(is_open_lt continuous_zero continuous_im),
end
lemma arg_eq_nhds_of_re_neg_of_im_neg (hx_re : x.re < 0) (hx_im : x.im < 0) :
arg =ᶠ[𝓝 x] λ x, real.arcsin ((-x).im / x.abs) - π :=
begin
suffices h_forall_nhds : ∀ᶠ (y : ℂ) in (𝓝 x), y.re < 0 ∧ y.im < 0,
from h_forall_nhds.mono (λ y hy, arg_of_re_neg_of_im_neg hy.1 hy.2),
refine is_open.eventually_mem _ (⟨hx_re, hx_im⟩ : x.re < 0 ∧ x.im < 0),
exact is_open.and (is_open_lt continuous_re continuous_zero)
(is_open_lt continuous_im continuous_zero),
end
lemma arg_eq_nhds_of_im_pos (hz : 0 < im z) :
arg =ᶠ[𝓝 z] λ x, real.arccos (x.re / abs x) :=
((continuous_im.tendsto _).eventually (lt_mem_nhds hz)).mono $ λ x, arg_of_im_pos
lemma arg_eq_nhds_of_im_neg (hz : im z < 0) :
arg =ᶠ[𝓝 z] λ x, -real.arccos (x.re / abs x) :=
((continuous_im.tendsto _).eventually (gt_mem_nhds hz)).mono $ λ x, arg_of_im_neg
lemma continuous_at_arg (h : 0 < x.re ∨ x.im ≠ 0) : continuous_at arg x :=
begin
have h₀ : abs x ≠ 0, { rw abs_ne_zero, rintro rfl, simpa using h },
rw [← lt_or_lt_iff_ne] at h,
rcases h with (hx_re|hx_im|hx_im),
exacts [(real.continuous_at_arcsin.comp (continuous_im.continuous_at.div
continuous_abs.continuous_at h₀)).congr (arg_eq_nhds_of_re_pos hx_re).symm,
(real.continuous_arccos.continuous_at.comp (continuous_re.continuous_at.div
continuous_abs.continuous_at h₀)).neg.congr (arg_eq_nhds_of_im_neg hx_im).symm,
(real.continuous_arccos.continuous_at.comp (continuous_re.continuous_at.div
continuous_abs.continuous_at h₀)).congr (arg_eq_nhds_of_im_pos hx_im).symm]
end
lemma tendsto_arg_nhds_within_im_neg_of_re_neg_of_im_zero
{z : ℂ} (hre : z.re < 0) (him : z.im = 0) :
tendsto arg (𝓝[{z : ℂ | z.im < 0}] z) (𝓝 (-π)) :=
begin
suffices H :
tendsto (λ x : ℂ, real.arcsin ((-x).im / x.abs) - π) (𝓝[{z : ℂ | z.im < 0}] z) (𝓝 (-π)),
{ refine H.congr' _,
have : ∀ᶠ x : ℂ in 𝓝 z, x.re < 0, from continuous_re.tendsto z (gt_mem_nhds hre),
filter_upwards [self_mem_nhds_within, mem_nhds_within_of_mem_nhds this] with _ him hre,
rw [arg, if_neg hre.not_le, if_neg him.not_le], },
convert (real.continuous_at_arcsin.comp_continuous_within_at
((continuous_im.continuous_at.comp_continuous_within_at continuous_within_at_neg).div
continuous_abs.continuous_within_at _)).sub tendsto_const_nhds,
{ simp [him] },
{ lift z to ℝ using him, simpa using hre.ne }
end
lemma continuous_within_at_arg_of_re_neg_of_im_zero
{z : ℂ} (hre : z.re < 0) (him : z.im = 0) :
continuous_within_at arg {z : ℂ | 0 ≤ z.im} z :=
begin
have : arg =ᶠ[𝓝[{z : ℂ | 0 ≤ z.im}] z] λ x, real.arcsin ((-x).im / x.abs) + π,
{ have : ∀ᶠ x : ℂ in 𝓝 z, x.re < 0, from continuous_re.tendsto z (gt_mem_nhds hre),
filter_upwards [self_mem_nhds_within, mem_nhds_within_of_mem_nhds this] with _ him hre,
rw [arg, if_neg hre.not_le, if_pos him] },
refine continuous_within_at.congr_of_eventually_eq _ this _,
{ refine (real.continuous_at_arcsin.comp_continuous_within_at
((continuous_im.continuous_at.comp_continuous_within_at continuous_within_at_neg).div
continuous_abs.continuous_within_at _)).add tendsto_const_nhds,
lift z to ℝ using him, simpa using hre.ne },
{ rw [arg, if_neg hre.not_le, if_pos him.ge] }
end
lemma tendsto_arg_nhds_within_im_nonneg_of_re_neg_of_im_zero
{z : ℂ} (hre : z.re < 0) (him : z.im = 0) :
tendsto arg (𝓝[{z : ℂ | 0 ≤ z.im}] z) (𝓝 π) :=
by simpa only [arg_eq_pi_iff.2 ⟨hre, him⟩]
using (continuous_within_at_arg_of_re_neg_of_im_zero hre him).tendsto
lemma continuous_at_arg_coe_angle (h : x ≠ 0) : continuous_at (coe ∘ arg : ℂ → real.angle) x :=
begin
by_cases hs : 0 < x.re ∨ x.im ≠ 0,
{ exact real.angle.continuous_coe.continuous_at.comp (continuous_at_arg hs) },
{ rw [←function.comp.right_id (coe ∘ arg),
(function.funext_iff.2 (λ _, (neg_neg _).symm) :
(id : ℂ → ℂ) = has_neg.neg ∘ has_neg.neg), ←function.comp.assoc],
refine continuous_at.comp _ continuous_neg.continuous_at,
suffices : continuous_at (function.update ((coe ∘ arg) ∘ has_neg.neg : ℂ → real.angle) 0 π)
(-x), by rwa continuous_at_update_of_ne (neg_ne_zero.2 h) at this,
have ha : function.update ((coe ∘ arg) ∘ has_neg.neg : ℂ → real.angle) 0 π =
λ z, (arg z : real.angle) + π,
{ rw function.update_eq_iff,
exact ⟨by simp, λ z hz, arg_neg_coe_angle hz⟩ },
rw ha,
push_neg at hs,
refine (real.angle.continuous_coe.continuous_at.comp (continuous_at_arg (or.inl _))).add
continuous_at_const,
rw [neg_re, neg_pos],
exact hs.1.lt_of_ne (λ h0, h (ext_iff.2 ⟨h0, hs.2⟩)) }
end
end continuity
end complex
|
e2e635503ac871ce1457b38303d7d688e4e1ec87 | b2e508d02500f1512e1618150413e6be69d9db10 | /src/data/fintype.lean | c6d9898285c33c2af3d8096ae54472c009c0fc7a | [
"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 | 30,849 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
Finite types.
-/
import data.finset algebra.big_operators data.array.lemmas
universes u v
variables {α : Type*} {β : Type*} {γ : Type*}
/-- `fintype α` means that `α` is finite, i.e. there are only
finitely many distinct elements of type `α`. The evidence of this
is a finset `elems` (a list up to permutation without duplicates),
together with a proof that everything of type `α` is in the list. -/
class fintype (α : Type*) :=
(elems : finset α)
(complete : ∀ x : α, x ∈ elems)
namespace finset
variable [fintype α]
/-- `univ` is the universal finite set of type `finset α` implied from
the assumption `fintype α`. -/
def univ : finset α := fintype.elems α
@[simp] theorem mem_univ (x : α) : x ∈ (univ : finset α) :=
fintype.complete x
@[simp] theorem mem_univ_val : ∀ x, x ∈ (univ : finset α).1 := mem_univ
@[simp] lemma coe_univ : ↑(univ : finset α) = (set.univ : set α) :=
by ext; simp
theorem subset_univ (s : finset α) : s ⊆ univ := λ a _, mem_univ a
theorem eq_univ_iff_forall {s : finset α} : s = univ ↔ ∀ x, x ∈ s :=
by simp [ext]
end finset
open finset function
namespace fintype
instance decidable_pi_fintype {α} {β : α → Type*} [fintype α] [∀a, decidable_eq (β a)] :
decidable_eq (Πa, β a) :=
assume f g, decidable_of_iff (∀ a ∈ fintype.elems α, f a = g a)
(by simp [function.funext_iff, fintype.complete])
instance decidable_forall_fintype [fintype α] {p : α → Prop} [decidable_pred p] :
decidable (∀ a, p a) :=
decidable_of_iff (∀ a ∈ @univ α _, p a) (by simp)
instance decidable_exists_fintype [fintype α] {p : α → Prop} [decidable_pred p] :
decidable (∃ a, p a) :=
decidable_of_iff (∃ a ∈ @univ α _, p a) (by simp)
instance decidable_eq_equiv_fintype [fintype α] [decidable_eq β] :
decidable_eq (α ≃ β) :=
λ a b, decidable_of_iff (a.1 = b.1) ⟨λ h, equiv.ext _ _ (congr_fun h), congr_arg _⟩
instance decidable_injective_fintype [fintype α] [decidable_eq α] [decidable_eq β] :
decidable_pred (injective : (α → β) → Prop) := λ x, by unfold injective; apply_instance
instance decidable_surjective_fintype [fintype α] [decidable_eq α] [fintype β] [decidable_eq β] :
decidable_pred (surjective : (α → β) → Prop) := λ x, by unfold surjective; apply_instance
instance decidable_bijective_fintype [fintype α] [decidable_eq α] [fintype β] [decidable_eq β] :
decidable_pred (bijective : (α → β) → Prop) := λ x, by unfold bijective; apply_instance
instance decidable_left_inverse_fintype [fintype α] [decidable_eq α] (f : α → β) (g : β → α) :
decidable (function.right_inverse f g) :=
show decidable (∀ x, g (f x) = x), by apply_instance
instance decidable_right_inverse_fintype [fintype β] [decidable_eq β] (f : α → β) (g : β → α) :
decidable (function.left_inverse f g) :=
show decidable (∀ x, f (g x) = x), by apply_instance
/-- Construct a proof of `fintype α` from a universal multiset -/
def of_multiset [decidable_eq α] (s : multiset α)
(H : ∀ x : α, x ∈ s) : fintype α :=
⟨s.to_finset, by simpa using H⟩
/-- Construct a proof of `fintype α` from a universal list -/
def of_list [decidable_eq α] (l : list α)
(H : ∀ x : α, x ∈ l) : fintype α :=
⟨l.to_finset, by simpa using H⟩
theorem exists_univ_list (α) [fintype α] :
∃ l : list α, l.nodup ∧ ∀ x : α, x ∈ l :=
let ⟨l, e⟩ := quotient.exists_rep (@univ α _).1 in
by have := and.intro univ.2 mem_univ_val;
exact ⟨_, by rwa ← e at this⟩
/-- `card α` is the number of elements in `α`, defined when `α` is a fintype. -/
def card (α) [fintype α] : ℕ := (@univ α _).card
/-- There is (computably) a bijection between `α` and `fin n` where
`n = card α`. Since it is not unique, and depends on which permutation
of the universe list is used, the bijection is wrapped in `trunc` to
preserve computability. -/
def equiv_fin (α) [fintype α] [decidable_eq α] : trunc (α ≃ fin (card α)) :=
by unfold card finset.card; exact
quot.rec_on_subsingleton (@univ α _).1
(λ l (h : ∀ x:α, x ∈ l) (nd : l.nodup), trunc.mk
⟨λ a, ⟨_, list.index_of_lt_length.2 (h a)⟩,
λ i, l.nth_le i.1 i.2,
λ a, by simp,
λ ⟨i, h⟩, fin.eq_of_veq $ list.nodup_iff_nth_le_inj.1 nd _ _
(list.index_of_lt_length.2 (list.nth_le_mem _ _ _)) h $ by simp⟩)
mem_univ_val univ.2
theorem exists_equiv_fin (α) [fintype α] : ∃ n, nonempty (α ≃ fin n) :=
by haveI := classical.dec_eq α; exact ⟨card α, nonempty_of_trunc (equiv_fin α)⟩
instance (α : Type*) : subsingleton (fintype α) :=
⟨λ ⟨s₁, h₁⟩ ⟨s₂, h₂⟩, by congr; simp [finset.ext, h₁, h₂]⟩
protected def subtype {p : α → Prop} (s : finset α)
(H : ∀ x : α, x ∈ s ↔ p x) : fintype {x // p x} :=
⟨⟨multiset.pmap subtype.mk s.1 (λ x, (H x).1),
multiset.nodup_pmap (λ a _ b _, congr_arg subtype.val) s.2⟩,
λ ⟨x, px⟩, multiset.mem_pmap.2 ⟨x, (H x).2 px, rfl⟩⟩
theorem subtype_card {p : α → Prop} (s : finset α)
(H : ∀ x : α, x ∈ s ↔ p x) :
@card {x // p x} (fintype.subtype s H) = s.card :=
multiset.card_pmap _ _ _
theorem card_of_subtype {p : α → Prop} (s : finset α)
(H : ∀ x : α, x ∈ s ↔ p x) [fintype {x // p x}] :
card {x // p x} = s.card :=
by rw ← subtype_card s H; congr
/-- If `f : α → β` is a bijection and `α` is a fintype, then `β` is also a fintype. -/
def of_bijective [fintype α] (f : α → β) (H : function.bijective f) : fintype β :=
⟨univ.map ⟨f, H.1⟩,
λ b, let ⟨a, e⟩ := H.2 b in e ▸ mem_map_of_mem _ (mem_univ _)⟩
/-- If `f : α → β` is a surjection and `α` is a fintype, then `β` is also a fintype. -/
def of_surjective [fintype α] [decidable_eq β] (f : α → β) (H : function.surjective f) : fintype β :=
⟨univ.image f, λ b, let ⟨a, e⟩ := H b in e ▸ mem_image_of_mem _ (mem_univ _)⟩
noncomputable def of_injective [fintype β] (f : α → β) (H : function.injective f) : fintype α :=
by letI := classical.dec; exact
if hα : nonempty α then by letI := classical.inhabited_of_nonempty hα;
exact of_surjective (inv_fun f) (inv_fun_surjective H)
else ⟨∅, λ x, (hα ⟨x⟩).elim⟩
/-- If `f : α ≃ β` and `α` is a fintype, then `β` is also a fintype. -/
def of_equiv (α : Type*) [fintype α] (f : α ≃ β) : fintype β := of_bijective _ f.bijective
theorem of_equiv_card [fintype α] (f : α ≃ β) :
@card β (of_equiv α f) = card α :=
multiset.card_map _ _
theorem card_congr {α β} [fintype α] [fintype β] (f : α ≃ β) : card α = card β :=
by rw ← of_equiv_card f; congr
theorem card_eq {α β} [F : fintype α] [G : fintype β] : card α = card β ↔ nonempty (α ≃ β) :=
⟨λ e, match F, G, e with ⟨⟨s, nd⟩, h⟩, ⟨⟨s', nd'⟩, h'⟩, e' := begin
change multiset.card s = multiset.card s' at e',
revert nd nd' h h' e',
refine quotient.induction_on₂ s s' (λ l₁ l₂
(nd₁ : l₁.nodup) (nd₂ : l₂.nodup)
(h₁ : ∀ x, x ∈ l₁) (h₂ : ∀ x, x ∈ l₂)
(e' : l₁.length = l₂.length), _),
haveI := classical.dec_eq α,
refine ⟨equiv.of_bijective ⟨_, _⟩⟩,
{ refine λ a, l₂.nth_le (l₁.index_of a) _,
rw ← e', exact list.index_of_lt_length.2 (h₁ a) },
{ intros a b h, simpa [h₁] using congr_arg l₁.nth
(list.nodup_iff_nth_le_inj.1 nd₂ _ _ _ _ h) },
{ have := classical.dec_eq β,
refine λ b, ⟨l₁.nth_le (l₂.index_of b) _, _⟩,
{ rw e', exact list.index_of_lt_length.2 (h₂ b) },
{ simp [nd₁] } }
end end, λ ⟨f⟩, card_congr f⟩
def of_subsingleton (a : α) [subsingleton α] : fintype α :=
⟨finset.singleton a, λ b, finset.mem_singleton.2 (subsingleton.elim _ _)⟩
@[simp] theorem fintype.univ_of_subsingleton (a : α) [subsingleton α] :
@univ _ (of_subsingleton a) = finset.singleton a := rfl
@[simp] theorem fintype.card_of_subsingleton (a : α) [subsingleton α] :
@fintype.card _ (of_subsingleton a) = 1 := rfl
end fintype
lemma finset.card_univ [fintype α] : (finset.univ : finset α).card = fintype.card α :=
rfl
lemma finset.card_univ_diff [fintype α] [decidable_eq α] (s : finset α) :
(finset.univ \ s).card = fintype.card α - s.card :=
finset.card_sdiff (subset_univ s)
instance (n : ℕ) : fintype (fin n) :=
⟨⟨list.pmap fin.mk (list.range n) (λ a, list.mem_range.1),
list.nodup_pmap (λ a _ b _, congr_arg fin.val) (list.nodup_range _)⟩,
λ ⟨m, h⟩, list.mem_pmap.2 ⟨m, list.mem_range.2 h, rfl⟩⟩
@[simp] theorem fintype.card_fin (n : ℕ) : fintype.card (fin n) = n :=
by rw [fin.fintype]; simp [fintype.card, card, univ]
instance : fintype empty := ⟨∅, empty.rec _⟩
@[simp] theorem fintype.univ_empty : @univ empty _ = ∅ := rfl
@[simp] theorem fintype.card_empty : fintype.card empty = 0 := rfl
instance : fintype pempty := ⟨∅, pempty.rec _⟩
@[simp] theorem fintype.univ_pempty : @univ pempty _ = ∅ := rfl
@[simp] theorem fintype.card_pempty : fintype.card pempty = 0 := rfl
instance : fintype unit := fintype.of_subsingleton ()
@[simp] theorem fintype.univ_unit : @univ unit _ = {()} := rfl
@[simp] theorem fintype.card_unit : fintype.card unit = 1 := rfl
instance : fintype punit := fintype.of_subsingleton punit.star
@[simp] theorem fintype.univ_punit : @univ punit _ = {punit.star} := rfl
@[simp] theorem fintype.card_punit : fintype.card punit = 1 := rfl
instance : fintype bool := ⟨⟨tt::ff::0, by simp⟩, λ x, by cases x; simp⟩
@[simp] theorem fintype.univ_bool : @univ bool _ = {ff, tt} := rfl
instance units_int.fintype : fintype (units ℤ) :=
⟨{1, -1}, λ x, by cases int.units_eq_one_or x; simp *⟩
instance additive.fintype : Π [fintype α], fintype (additive α) := id
instance multiplicative.fintype : Π [fintype α], fintype (multiplicative α) := id
@[simp] theorem fintype.card_units_int : fintype.card (units ℤ) = 2 := rfl
@[simp] theorem fintype.card_bool : fintype.card bool = 2 := rfl
def finset.insert_none (s : finset α) : finset (option α) :=
⟨none :: s.1.map some, multiset.nodup_cons.2
⟨by simp, multiset.nodup_map (λ a b, option.some.inj) s.2⟩⟩
@[simp] theorem finset.mem_insert_none {s : finset α} : ∀ {o : option α},
o ∈ s.insert_none ↔ ∀ a ∈ o, a ∈ s
| none := iff_of_true (multiset.mem_cons_self _ _) (λ a h, by cases h)
| (some a) := multiset.mem_cons.trans $ by simp; refl
theorem finset.some_mem_insert_none {s : finset α} {a : α} :
some a ∈ s.insert_none ↔ a ∈ s := by simp
instance {α : Type*} [fintype α] : fintype (option α) :=
⟨univ.insert_none, λ a, by simp⟩
@[simp] theorem fintype.card_option {α : Type*} [fintype α] :
fintype.card (option α) = fintype.card α + 1 :=
(multiset.card_cons _ _).trans (by rw multiset.card_map; refl)
instance {α : Type*} (β : α → Type*)
[fintype α] [∀ a, fintype (β a)] : fintype (sigma β) :=
⟨univ.sigma (λ _, univ), λ ⟨a, b⟩, by simp⟩
@[simp] theorem fintype.card_sigma {α : Type*} (β : α → Type*)
[fintype α] [∀ a, fintype (β a)] :
fintype.card (sigma β) = univ.sum (λ a, fintype.card (β a)) :=
card_sigma _ _
instance (α β : Type*) [fintype α] [fintype β] : fintype (α × β) :=
⟨univ.product univ, λ ⟨a, b⟩, by simp⟩
@[simp] theorem fintype.card_prod (α β : Type*) [fintype α] [fintype β] :
fintype.card (α × β) = fintype.card α * fintype.card β :=
card_product _ _
def fintype.fintype_prod_left {α β} [decidable_eq α] [fintype (α × β)] [nonempty β] : fintype α :=
⟨(fintype.elems (α × β)).image prod.fst,
assume a, let ⟨b⟩ := ‹nonempty β› in by simp; exact ⟨b, fintype.complete _⟩⟩
def fintype.fintype_prod_right {α β} [decidable_eq β] [fintype (α × β)] [nonempty α] : fintype β :=
⟨(fintype.elems (α × β)).image prod.snd,
assume b, let ⟨a⟩ := ‹nonempty α› in by simp; exact ⟨a, fintype.complete _⟩⟩
instance (α : Type*) [fintype α] : fintype (ulift α) :=
fintype.of_equiv _ equiv.ulift.symm
@[simp] theorem fintype.card_ulift (α : Type*) [fintype α] :
fintype.card (ulift α) = fintype.card α :=
fintype.of_equiv_card _
instance (α : Type u) (β : Type v) [fintype α] [fintype β] : fintype (α ⊕ β) :=
@fintype.of_equiv _ _ (@sigma.fintype _
(λ b, cond b (ulift α) (ulift.{(max u v) v} β)) _
(λ b, by cases b; apply ulift.fintype))
((equiv.sum_equiv_sigma_bool _ _).symm.trans
(equiv.sum_congr equiv.ulift equiv.ulift))
@[simp] theorem fintype.card_sum (α β : Type*) [fintype α] [fintype β] :
fintype.card (α ⊕ β) = fintype.card α + fintype.card β :=
by rw [sum.fintype, fintype.of_equiv_card]; simp
lemma fintype.card_le_of_injective [fintype α] [fintype β] (f : α → β)
(hf : function.injective f) : fintype.card α ≤ fintype.card β :=
by haveI := classical.prop_decidable; exact
finset.card_le_card_of_inj_on f (λ _ _, finset.mem_univ _) (λ _ _ _ _ h, hf h)
lemma fintype.card_eq_one_iff [fintype α] : fintype.card α = 1 ↔ (∃ x : α, ∀ y, y = x) :=
by rw [← fintype.card_unit, fintype.card_eq]; exact
⟨λ ⟨a⟩, ⟨a.symm (), λ y, a.injective (subsingleton.elim _ _)⟩,
λ ⟨x, hx⟩, ⟨⟨λ _, (), λ _, x, λ _, (hx _).trans (hx _).symm,
λ _, subsingleton.elim _ _⟩⟩⟩
lemma fintype.card_eq_zero_iff [fintype α] : fintype.card α = 0 ↔ (α → false) :=
⟨λ h a, have e : α ≃ empty := classical.choice (fintype.card_eq.1 (by simp [h])), (e a).elim,
λ h, have e : α ≃ empty := ⟨λ a, (h a).elim, λ a, a.elim, λ a, (h a).elim, λ a, a.elim⟩,
by simp [fintype.card_congr e]⟩
lemma fintype.card_pos_iff [fintype α] : 0 < fintype.card α ↔ nonempty α :=
⟨λ h, classical.by_contradiction (λ h₁,
have fintype.card α = 0 := fintype.card_eq_zero_iff.2 (λ a, h₁ ⟨a⟩),
lt_irrefl 0 $ by rwa this at h),
λ ⟨a⟩, nat.pos_of_ne_zero (mt fintype.card_eq_zero_iff.1 (λ h, h a))⟩
lemma fintype.card_le_one_iff [fintype α] : fintype.card α ≤ 1 ↔ (∀ a b : α, a = b) :=
let n := fintype.card α in
have hn : n = fintype.card α := rfl,
match n, hn with
| 0 := λ ha, ⟨λ h, λ a, (fintype.card_eq_zero_iff.1 ha.symm a).elim, λ _, ha ▸ nat.le_succ _⟩
| 1 := λ ha, ⟨λ h, λ a b, let ⟨x, hx⟩ := fintype.card_eq_one_iff.1 ha.symm in
by rw [hx a, hx b],
λ _, ha ▸ le_refl _⟩
| (n+2) := λ ha, ⟨λ h, by rw ← ha at h; exact absurd h dec_trivial,
(λ h, fintype.card_unit ▸ fintype.card_le_of_injective (λ _, ())
(λ _ _ _, h _ _))⟩
end
lemma fintype.exists_ne_of_card_gt_one [fintype α] (h : fintype.card α > 1) (a : α) :
∃ b : α, b ≠ a :=
let ⟨b, hb⟩ := classical.not_forall.1 (mt fintype.card_le_one_iff.2 (not_le_of_gt h)) in
let ⟨c, hc⟩ := classical.not_forall.1 hb in
by haveI := classical.dec_eq α; exact
if hba : b = a then ⟨c, by cc⟩ else ⟨b, hba⟩
lemma fintype.injective_iff_surjective [fintype α] {f : α → α} : injective f ↔ surjective f :=
by haveI := classical.prop_decidable; exact
have ∀ {f : α → α}, injective f → surjective f,
from λ f hinj x,
have h₁ : image f univ = univ := eq_of_subset_of_card_le (subset_univ _)
((card_image_of_injective univ hinj).symm ▸ le_refl _),
have h₂ : x ∈ image f univ := h₁.symm ▸ mem_univ _,
exists_of_bex (mem_image.1 h₂),
⟨this,
λ hsurj, injective_of_has_left_inverse
⟨surj_inv hsurj, left_inverse_of_surjective_of_right_inverse
(this (injective_surj_inv _)) (right_inverse_surj_inv _)⟩⟩
lemma fintype.injective_iff_bijective [fintype α] {f : α → α} : injective f ↔ bijective f :=
by simp [bijective, fintype.injective_iff_surjective]
lemma fintype.surjective_iff_bijective [fintype α] {f : α → α} : surjective f ↔ bijective f :=
by simp [bijective, fintype.injective_iff_surjective]
lemma fintype.injective_iff_surjective_of_equiv [fintype α] {f : α → β} (e : α ≃ β) :
injective f ↔ surjective f :=
have injective (e.symm ∘ f) ↔ surjective (e.symm ∘ f), from fintype.injective_iff_surjective,
⟨λ hinj, by simpa [function.comp] using
surjective_comp e.surjective (this.1 (injective_comp e.symm.injective hinj)),
λ hsurj, by simpa [function.comp] using
injective_comp e.injective (this.2 (surjective_comp e.symm.surjective hsurj))⟩
instance list.subtype.fintype [decidable_eq α] (l : list α) : fintype {x // x ∈ l} :=
fintype.of_list l.attach l.mem_attach
instance multiset.subtype.fintype [decidable_eq α] (s : multiset α) : fintype {x // x ∈ s} :=
fintype.of_multiset s.attach s.mem_attach
instance finset.subtype.fintype (s : finset α) : fintype {x // x ∈ s} :=
⟨s.attach, s.mem_attach⟩
instance finset_coe.fintype (s : finset α) : fintype (↑s : set α) :=
finset.subtype.fintype s
@[simp] lemma fintype.card_coe (s : finset α) :
fintype.card (↑s : set α) = s.card := card_attach
instance plift.fintype (p : Prop) [decidable p] : fintype (plift p) :=
⟨if h : p then finset.singleton ⟨h⟩ else ∅, λ ⟨h⟩, by simp [h]⟩
instance Prop.fintype : fintype Prop :=
⟨⟨true::false::0, by simp [true_ne_false]⟩,
classical.cases (by simp) (by simp)⟩
def set_fintype {α} [fintype α] (s : set α) [decidable_pred s] : fintype s :=
fintype.subtype (univ.filter (∈ s)) (by simp)
instance pi.fintype {α : Type*} {β : α → Type*}
[fintype α] [decidable_eq α] [∀a, fintype (β a)] : fintype (Πa, β a) :=
@fintype.of_equiv _ _
⟨univ.pi $ λa:α, @univ (β a) _,
λ f, finset.mem_pi.2 $ λ a ha, mem_univ _⟩
⟨λ f a, f a (mem_univ _), λ f a _, f a, λ f, rfl, λ f, rfl⟩
@[simp] lemma fintype.card_pi {β : α → Type*} [fintype α] [decidable_eq α]
[f : Π a, fintype (β a)] : fintype.card (Π a, β a) = univ.prod (λ a, fintype.card (β a)) :=
by letI f' : fintype (Πa∈univ, β a) :=
⟨(univ.pi $ λa, univ), assume f, finset.mem_pi.2 $ assume a ha, mem_univ _⟩;
exact calc fintype.card (Π a, β a) = fintype.card (Π a ∈ univ, β a) : fintype.card_congr
⟨λ f a ha, f a, λ f a, f a (mem_univ a), λ _, rfl, λ _, rfl⟩
... = univ.prod (λ a, fintype.card (β a)) : finset.card_pi _ _
@[simp] lemma fintype.card_fun [fintype α] [decidable_eq α] [fintype β] :
fintype.card (α → β) = fintype.card β ^ fintype.card α :=
by rw [fintype.card_pi, finset.prod_const, nat.pow_eq_pow]; refl
instance d_array.fintype {n : ℕ} {α : fin n → Type*}
[∀n, fintype (α n)] : fintype (d_array n α) :=
fintype.of_equiv _ (equiv.d_array_equiv_fin _).symm
instance array.fintype {n : ℕ} {α : Type*} [fintype α] : fintype (array n α) :=
d_array.fintype
instance vector.fintype {α : Type*} [fintype α] {n : ℕ} : fintype (vector α n) :=
fintype.of_equiv _ (equiv.vector_equiv_fin _ _).symm
@[simp] lemma card_vector [fintype α] (n : ℕ) :
fintype.card (vector α n) = fintype.card α ^ n :=
by rw fintype.of_equiv_card; simp
instance quotient.fintype [fintype α] (s : setoid α)
[decidable_rel ((≈) : α → α → Prop)] : fintype (quotient s) :=
fintype.of_surjective quotient.mk (λ x, quotient.induction_on x (λ x, ⟨x, rfl⟩))
instance finset.fintype [fintype α] : fintype (finset α) :=
⟨univ.powerset, λ x, finset.mem_powerset.2 (finset.subset_univ _)⟩
instance subtype.fintype [fintype α] (p : α → Prop) [decidable_pred p] : fintype {x // p x} :=
set_fintype _
instance set.fintype [fintype α] [decidable_eq α] : fintype (set α) :=
pi.fintype
instance pfun_fintype (p : Prop) [decidable p] (α : p → Type*)
[Π hp, fintype (α hp)] : fintype (Π hp : p, α hp) :=
if hp : p then fintype.of_equiv (α hp) ⟨λ a _, a, λ f, f hp, λ _, rfl, λ _, rfl⟩
else ⟨singleton (λ h, (hp h).elim), by simp [hp, function.funext_iff]⟩
def quotient.fin_choice_aux {ι : Type*} [decidable_eq ι]
{α : ι → Type*} [S : ∀ i, setoid (α i)] :
∀ (l : list ι), (∀ i ∈ l, quotient (S i)) → @quotient (Π i ∈ l, α i) (by apply_instance)
| [] f := ⟦λ i, false.elim⟧
| (i::l) f := begin
refine quotient.lift_on₂ (f i (list.mem_cons_self _ _))
(quotient.fin_choice_aux l (λ j h, f j (list.mem_cons_of_mem _ h)))
_ _,
exact λ a l, ⟦λ j h,
if e : j = i then by rw e; exact a else
l _ (h.resolve_left e)⟧,
refine λ a₁ l₁ a₂ l₂ h₁ h₂, quotient.sound (λ j h, _),
by_cases e : j = i; simp [e],
{ subst j, exact h₁ },
{ exact h₂ _ _ }
end
theorem quotient.fin_choice_aux_eq {ι : Type*} [decidable_eq ι]
{α : ι → Type*} [S : ∀ i, setoid (α i)] :
∀ (l : list ι) (f : ∀ i ∈ l, α i), quotient.fin_choice_aux l (λ i h, ⟦f i h⟧) = ⟦f⟧
| [] f := quotient.sound (λ i h, h.elim)
| (i::l) f := begin
simp [quotient.fin_choice_aux, quotient.fin_choice_aux_eq l],
refine quotient.sound (λ j h, _),
by_cases e : j = i; simp [e],
subst j, refl
end
def quotient.fin_choice {ι : Type*} [fintype ι] [decidable_eq ι]
{α : ι → Type*} [S : ∀ i, setoid (α i)]
(f : ∀ i, quotient (S i)) : @quotient (Π i, α i) (by apply_instance) :=
quotient.lift_on (@quotient.rec_on _ _ (λ l : multiset ι,
@quotient (Π i ∈ l, α i) (by apply_instance))
finset.univ.1
(λ l, quotient.fin_choice_aux l (λ i _, f i))
(λ a b h, begin
have := λ a, quotient.fin_choice_aux_eq a (λ i h, quotient.out (f i)),
simp [quotient.out_eq] at this,
simp [this],
let g := λ a:multiset ι, ⟦λ (i : ι) (h : i ∈ a), quotient.out (f i)⟧,
refine eq_of_heq ((eq_rec_heq _ _).trans (_ : g a == g b)),
congr' 1, exact quotient.sound h,
end))
(λ f, ⟦λ i, f i (finset.mem_univ _)⟧)
(λ a b h, quotient.sound $ λ i, h _ _)
theorem quotient.fin_choice_eq {ι : Type*} [fintype ι] [decidable_eq ι]
{α : ι → Type*} [∀ i, setoid (α i)]
(f : ∀ i, α i) : quotient.fin_choice (λ i, ⟦f i⟧) = ⟦f⟧ :=
begin
let q, swap, change quotient.lift_on q _ _ = _,
have : q = ⟦λ i h, f i⟧,
{ dsimp [q],
exact quotient.induction_on
(@finset.univ ι _).1 (λ l, quotient.fin_choice_aux_eq _ _) },
simp [this], exact setoid.refl _
end
@[simp, to_additive finset.sum_attach_univ]
lemma finset.prod_attach_univ [fintype α] [comm_monoid β] (f : {a : α // a ∈ @univ α _} → β) :
univ.attach.prod (λ x, f x) = univ.prod (λ x, f ⟨x, (mem_univ _)⟩) :=
prod_bij (λ x _, x.1) (λ _ _, mem_univ _) (λ _ _ , by simp) (by simp) (λ b _, ⟨⟨b, mem_univ _⟩, by simp⟩)
section equiv
open list equiv equiv.perm
variables [decidable_eq α] [decidable_eq β]
def perms_of_list : list α → list (perm α)
| [] := [1]
| (a :: l) := perms_of_list l ++ l.bind (λ b, (perms_of_list l).map (λ f, swap a b * f))
lemma length_perms_of_list : ∀ l : list α, length (perms_of_list l) = l.length.fact
| [] := rfl
| (a :: l) := by rw [length_cons, nat.fact_succ];
simp [perms_of_list, length_bind, length_perms_of_list, function.comp, nat.succ_mul]
lemma mem_perms_of_list_of_mem : ∀ {l : list α} {f : perm α} (h : ∀ x, f x ≠ x → x ∈ l), f ∈ perms_of_list l
| [] f h := list.mem_singleton.2 $ equiv.ext _ _$ λ x, by simp [imp_false, *] at *
| (a::l) f h :=
if hfa : f a = a
then
mem_append_left _ $ mem_perms_of_list_of_mem
(λ x hx, mem_of_ne_of_mem (λ h, by rw h at hx; exact hx hfa) (h x hx))
else
have hfa' : f (f a) ≠ f a, from mt (λ h, f.injective h) hfa,
have ∀ (x : α), (swap a (f a) * f) x ≠ x → x ∈ l,
from λ x hx, have hxa : x ≠ a, from λ h, by simpa [h, mul_apply] using hx,
have hfxa : f x ≠ f a, from mt (λ h, f.injective h) hxa,
list.mem_of_ne_of_mem hxa
(h x (λ h, by simp [h, mul_apply, swap_apply_def] at hx; split_ifs at hx; cc)),
suffices f ∈ perms_of_list l ∨ ∃ (b : α), b ∈ l ∧ ∃ g : perm α, g ∈ perms_of_list l ∧ swap a b * g = f,
by simpa [perms_of_list],
(@or_iff_not_imp_left _ _ (classical.prop_decidable _)).2
(λ hfl, ⟨f a,
if hffa : f (f a) = a then mem_of_ne_of_mem hfa (h _ (mt (λ h, f.injective h) hfa))
else this _ $ by simp [mul_apply, swap_apply_def]; split_ifs; cc,
⟨swap a (f a) * f, mem_perms_of_list_of_mem this,
by rw [← mul_assoc, mul_def (swap a (f a)) (swap a (f a)), swap_swap, ← equiv.perm.one_def, one_mul]⟩⟩)
lemma mem_of_mem_perms_of_list : ∀ {l : list α} {f : perm α}, f ∈ perms_of_list l → ∀ {x}, f x ≠ x → x ∈ l
| [] f h := have f = 1 := by simpa [perms_of_list] using h, by rw this; simp
| (a::l) f h :=
(mem_append.1 h).elim
(λ h x hx, mem_cons_of_mem _ (mem_of_mem_perms_of_list h hx))
(λ h x hx,
let ⟨y, hy, hy'⟩ := list.mem_bind.1 h in
let ⟨g, hg₁, hg₂⟩ := list.mem_map.1 hy' in
if hxa : x = a then by simp [hxa]
else if hxy : x = y then mem_cons_of_mem _ $ by rwa hxy
else mem_cons_of_mem _ $
mem_of_mem_perms_of_list hg₁ $
by rw [eq_inv_mul_iff_mul_eq.2 hg₂, mul_apply, swap_inv, swap_apply_def];
split_ifs; cc)
lemma mem_perms_of_list_iff {l : list α} {f : perm α} : f ∈ perms_of_list l ↔ ∀ {x}, f x ≠ x → x ∈ l :=
⟨mem_of_mem_perms_of_list, mem_perms_of_list_of_mem⟩
lemma nodup_perms_of_list : ∀ {l : list α} (hl : l.nodup), (perms_of_list l).nodup
| [] hl := by simp [perms_of_list]
| (a::l) hl :=
have hl' : l.nodup, from nodup_of_nodup_cons hl,
have hln' : (perms_of_list l).nodup, from nodup_perms_of_list hl',
have hmeml : ∀ {f : perm α}, f ∈ perms_of_list l → f a = a,
from λ f hf, not_not.1 (mt (mem_of_mem_perms_of_list hf) (nodup_cons.1 hl).1),
by rw [perms_of_list, list.nodup_append, list.nodup_bind, pairwise_iff_nth_le]; exact
⟨hln', ⟨λ _ _, nodup_map (λ _ _, (mul_left_inj _).1) hln',
λ i j hj hij x hx₁ hx₂,
let ⟨f, hf⟩ := list.mem_map.1 hx₁ in
let ⟨g, hg⟩ := list.mem_map.1 hx₂ in
have hix : x a = nth_le l i (lt_trans hij hj),
by rw [← hf.2, mul_apply, hmeml hf.1, swap_apply_left],
have hiy : x a = nth_le l j hj,
by rw [← hg.2, mul_apply, hmeml hg.1, swap_apply_left],
absurd (hf.2.trans (hg.2.symm)) $
λ h, ne_of_lt hij $ nodup_iff_nth_le_inj.1 hl' i j (lt_trans hij hj) hj $
by rw [← hix, hiy]⟩,
λ f hf₁ hf₂,
let ⟨x, hx, hx'⟩ := list.mem_bind.1 hf₂ in
let ⟨g, hg⟩ := list.mem_map.1 hx' in
have hgxa : g⁻¹ x = a, from f.injective $
by rw [hmeml hf₁, ← hg.2]; simp,
have hxa : x ≠ a, from λ h, (list.nodup_cons.1 hl).1 (h ▸ hx),
(list.nodup_cons.1 hl).1 $
hgxa ▸ mem_of_mem_perms_of_list hg.1 (by rwa [apply_inv_self, hgxa])⟩
def perms_of_finset (s : finset α) : finset (perm α) :=
quotient.hrec_on s.1 (λ l hl, ⟨perms_of_list l, nodup_perms_of_list hl⟩)
(λ a b hab, hfunext (congr_arg _ (quotient.sound hab))
(λ ha hb _, heq_of_eq $ finset.ext.2 $
by simp [mem_perms_of_list_iff,mem_of_perm hab]))
s.2
lemma mem_perms_of_finset_iff : ∀ {s : finset α} {f : perm α},
f ∈ perms_of_finset s ↔ ∀ {x}, f x ≠ x → x ∈ s :=
by rintros ⟨⟨l⟩, hs⟩ f; exact mem_perms_of_list_iff
lemma card_perms_of_finset : ∀ (s : finset α),
(perms_of_finset s).card = s.card.fact :=
by rintros ⟨⟨l⟩, hs⟩; exact length_perms_of_list l
def fintype_perm [fintype α] : fintype (perm α) :=
⟨perms_of_finset (@finset.univ α _), by simp [mem_perms_of_finset_iff]⟩
instance [fintype α] [fintype β] : fintype (α ≃ β) :=
if h : fintype.card β = fintype.card α
then trunc.rec_on_subsingleton (fintype.equiv_fin α)
(λ eα, trunc.rec_on_subsingleton (fintype.equiv_fin β)
(λ eβ, @fintype.of_equiv _ (perm α) fintype_perm
(equiv_congr (equiv.refl α) (eα.trans (eq.rec_on h eβ.symm)) : (α ≃ α) ≃ (α ≃ β))))
else ⟨∅, λ x, false.elim (h (fintype.card_eq.2 ⟨x.symm⟩))⟩
lemma fintype.card_perm [fintype α] : fintype.card (perm α) = (fintype.card α).fact :=
subsingleton.elim (@fintype_perm α _ _) (@equiv.fintype α α _ _ _ _) ▸
card_perms_of_finset _
lemma fintype.card_equiv [fintype α] [fintype β] (e : α ≃ β) :
fintype.card (α ≃ β) = (fintype.card α).fact :=
fintype.card_congr (equiv_congr (equiv.refl α) e) ▸ fintype.card_perm
end equiv
namespace fintype
section choose
open fintype
open equiv
variables [fintype α] [decidable_eq α] (p : α → Prop) [decidable_pred p]
def choose_x (hp : ∃! a : α, p a) : {a // p a} :=
⟨finset.choose p univ (by simp; exact hp), finset.choose_property _ _ _⟩
def choose (hp : ∃! a, p a) : α := choose_x p hp
lemma choose_spec (hp : ∃! a, p a) : p (choose p hp) :=
(choose_x p hp).property
end choose
section bijection_inverse
open function
variables [fintype α] [decidable_eq α]
variables [fintype β] [decidable_eq β]
variables {f : α → β}
/-- `
`bij_inv f` is the unique inverse to a bijection `f`. This acts
as a computable alternative to `function.inv_fun`. -/
def bij_inv (f_bij : bijective f) (b : β) : α :=
fintype.choose (λ a, f a = b)
begin
rcases f_bij.right b with ⟨a', fa_eq_b⟩,
rw ← fa_eq_b,
exact ⟨a', ⟨rfl, (λ a h, f_bij.left h)⟩⟩
end
lemma left_inverse_bij_inv (f_bij : bijective f) : left_inverse (bij_inv f_bij) f :=
λ a, f_bij.left (choose_spec (λ a', f a' = f a) _)
lemma right_inverse_bij_inv (f_bij : bijective f) : right_inverse (bij_inv f_bij) f :=
λ b, choose_spec (λ a', f a' = b) _
lemma bijective_bij_inv (f_bij : bijective f) : bijective (bij_inv f_bij) :=
⟨injective_of_left_inverse (right_inverse_bij_inv _),
surjective_of_has_right_inverse ⟨f, left_inverse_bij_inv _⟩⟩
end bijection_inverse
end fintype
class infinite (α : Type*) : Prop :=
(not_fintype : fintype α → false)
namespace infinite
lemma exists_not_mem_finset [infinite α] (s : finset α) : ∃ x, x ∉ s :=
classical.not_forall.1 $ λ h, not_fintype ⟨s, h⟩
instance nonempty (α : Type*) [infinite α] : nonempty α :=
nonempty_of_exists (exists_not_mem_finset (∅ : finset α))
lemma of_injective [infinite β] (f : β → α) (hf : injective f) : infinite α :=
⟨λ I, by exactI not_fintype (fintype.of_injective f hf)⟩
lemma of_surjective [infinite β] (f : α → β) (hf : surjective f) : infinite α :=
⟨λ I, by classical; exactI not_fintype (fintype.of_surjective f hf)⟩
end infinite
instance nat.infinite : infinite ℕ :=
⟨λ ⟨s, hs⟩, not_le_of_gt (nat.lt_succ_self (s.sum id)) $
@finset.single_le_sum _ _ _ id _ _ (λ _ _, nat.zero_le _) _ (hs _)⟩
instance int.infinite : infinite ℤ :=
infinite.of_injective int.of_nat (λ _ _, int.of_nat_inj)
|
b8832bc8d80a393e641221e1ac388aa68202b88e | 4efff1f47634ff19e2f786deadd394270a59ecd2 | /src/category_theory/limits/preserves/basic.lean | 82dc5430cca2f7973eb9c805fe92a7645b510ac6 | [
"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 | 16,093 | lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Reid Barton, Bhavik Mehta
-/
import category_theory.limits.limits
/-!
# Preservation and reflection of (co)limits.
There are various distinct notions of "preserving limits". The one we
aim to capture here is: A functor F : C → D "preserves limits" if it
sends every limit cone in C to a limit cone in D. Informally, F
preserves all the limits which exist in C.
Note that:
* Of course, we do not want to require F to *strictly* take chosen
limit cones of C to chosen limit cones of D. Indeed, the above
definition makes no reference to a choice of limit cones so it makes
sense without any conditions on C or D.
* Some diagrams in C may have no limit. In this case, there is no
condition on the behavior of F on such diagrams. There are other
notions (such as "flat functor") which impose conditions also on
diagrams in C with no limits, but these are not considered here.
In order to be able to express the property of preserving limits of a
certain form, we say that a functor F preserves the limit of a
diagram K if F sends every limit cone on K to a limit cone. This is
vacuously satisfied when K does not admit a limit, which is consistent
with the above definition of "preserves limits".
-/
open category_theory
namespace category_theory.limits
universes v u₁ u₂ u₃ -- declare the `v`'s first; see `category_theory.category` for an explanation
variables {C : Type u₁} [category.{v} C]
variables {D : Type u₂} [category.{v} D]
variables {J : Type v} [small_category J] {K : J ⥤ C}
/--
A functor `F` preserves limits of shape `K` (written as `preserves_limit K F`)
if `F` maps any limit cone over `K` to a limit cone.
-/
class preserves_limit (K : J ⥤ C) (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(preserves : Π {c : cone K}, is_limit c → is_limit (F.map_cone c))
/--
A functor `F` preserves colimits of shape `K` (written as `preserves_colimit K F`)
if `F` maps any colimit cocone over `K` to a colimit cocone.
-/
class preserves_colimit (K : J ⥤ C) (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(preserves : Π {c : cocone K}, is_colimit c → is_colimit (F.map_cocone c))
/-- A functor which preserves limits preserves chosen limits up to isomorphism. -/
def preserves_limit_iso (K : J ⥤ C) [has_limit K] (F : C ⥤ D) [has_limit (K ⋙ F)] [preserves_limit K F] :
F.obj (limit K) ≅ limit (K ⋙ F) :=
is_limit.cone_point_unique_up_to_iso (preserves_limit.preserves (limit.is_limit K)) (limit.is_limit (K ⋙ F))
/-- A functor which preserves colimits preserves chosen colimits up to isomorphism. -/
def preserves_colimit_iso (K : J ⥤ C) [has_colimit K] (F : C ⥤ D) [has_colimit (K ⋙ F)] [preserves_colimit K F] :
F.obj (colimit K) ≅ colimit (K ⋙ F) :=
is_colimit.cocone_point_unique_up_to_iso (preserves_colimit.preserves (colimit.is_colimit K)) (colimit.is_colimit (K ⋙ F))
class preserves_limits_of_shape (J : Type v) [small_category J] (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(preserves_limit : Π {K : J ⥤ C}, preserves_limit K F)
class preserves_colimits_of_shape (J : Type v) [small_category J] (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(preserves_colimit : Π {K : J ⥤ C}, preserves_colimit K F)
class preserves_limits (F : C ⥤ D) : Type (max u₁ u₂ (v+1)) :=
(preserves_limits_of_shape : Π {J : Type v} [𝒥 : small_category J], by exactI preserves_limits_of_shape J F)
class preserves_colimits (F : C ⥤ D) : Type (max u₁ u₂ (v+1)) :=
(preserves_colimits_of_shape : Π {J : Type v} [𝒥 : small_category J], by exactI preserves_colimits_of_shape J F)
attribute [instance, priority 100] -- see Note [lower instance priority]
preserves_limits_of_shape.preserves_limit preserves_limits.preserves_limits_of_shape
preserves_colimits_of_shape.preserves_colimit preserves_colimits.preserves_colimits_of_shape
instance preserves_limit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : subsingleton (preserves_limit K F) :=
by split; rintros ⟨a⟩ ⟨b⟩; congr
instance preserves_colimit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : subsingleton (preserves_colimit K F) :=
by split; rintros ⟨a⟩ ⟨b⟩; congr
instance preserves_limits_of_shape_subsingleton (J : Type v) [small_category J] (F : C ⥤ D) :
subsingleton (preserves_limits_of_shape J F) :=
by { split, intros, cases a, cases b, congr }
instance preserves_colimits_of_shape_subsingleton (J : Type v) [small_category J] (F : C ⥤ D) :
subsingleton (preserves_colimits_of_shape J F) :=
by { split, intros, cases a, cases b, congr }
instance preserves_limits_subsingleton (F : C ⥤ D) : subsingleton (preserves_limits F) :=
by { split, intros, cases a, cases b, cc }
instance preserves_colimits_subsingleton (F : C ⥤ D) : subsingleton (preserves_colimits F) :=
by { split, intros, cases a, cases b, cc }
instance id_preserves_limits : preserves_limits (𝟭 C) :=
{ preserves_limits_of_shape := λ J 𝒥,
{ preserves_limit := λ K, by exactI ⟨λ c h,
⟨λ s, h.lift ⟨s.X, λ j, s.π.app j, λ j j' f, s.π.naturality f⟩,
by cases K; rcases c with ⟨_, _, _⟩; intros s j; cases s; exact h.fac _ j,
by cases K; rcases c with ⟨_, _, _⟩; intros s m w; rcases s with ⟨_, _, _⟩; exact h.uniq _ m w⟩⟩ } }
instance id_preserves_colimits : preserves_colimits (𝟭 C) :=
{ preserves_colimits_of_shape := λ J 𝒥,
{ preserves_colimit := λ K, by exactI ⟨λ c h,
⟨λ s, h.desc ⟨s.X, λ j, s.ι.app j, λ j j' f, s.ι.naturality f⟩,
by cases K; rcases c with ⟨_, _, _⟩; intros s j; cases s; exact h.fac _ j,
by cases K; rcases c with ⟨_, _, _⟩; intros s m w; rcases s with ⟨_, _, _⟩; exact h.uniq _ m w⟩⟩ } }
section
variables {E : Type u₃} [ℰ : category.{v} E]
variables (F : C ⥤ D) (G : D ⥤ E)
local attribute [elab_simple] preserves_limit.preserves preserves_colimit.preserves
instance comp_preserves_limit [preserves_limit K F] [preserves_limit (K ⋙ F) G] :
preserves_limit K (F ⋙ G) :=
⟨λ c h, preserves_limit.preserves (preserves_limit.preserves h)⟩
instance comp_preserves_colimit [preserves_colimit K F] [preserves_colimit (K ⋙ F) G] :
preserves_colimit K (F ⋙ G) :=
⟨λ c h, preserves_colimit.preserves (preserves_colimit.preserves h)⟩
end
/-- If F preserves one limit cone for the diagram K,
then it preserves any limit cone for K. -/
def preserves_limit_of_preserves_limit_cone {F : C ⥤ D} {t : cone K}
(h : is_limit t) (hF : is_limit (F.map_cone t)) : preserves_limit K F :=
⟨λ t' h', is_limit.of_iso_limit hF (functor.map_iso _ (is_limit.unique_up_to_iso h h'))⟩
/-- Transfer preservation of limits along a natural isomorphism in the shape. -/
def preserves_limit_of_iso {K₁ K₂ : J ⥤ C} (F : C ⥤ D) (h : K₁ ≅ K₂) [preserves_limit K₁ F] :
preserves_limit K₂ F :=
{ preserves := λ c t,
begin
have t' := is_limit.of_right_adjoint (cones.postcompose_equivalence h).inverse t,
let hF := iso_whisker_right h F,
have := is_limit.of_right_adjoint (cones.postcompose_equivalence hF).functor
(preserves_limit.preserves t'),
apply is_limit.of_iso_limit this,
refine cones.ext (iso.refl _) (λ j, _),
dsimp,
rw [← F.map_comp],
simp,
end }
/-- If F preserves one colimit cocone for the diagram K,
then it preserves any colimit cocone for K. -/
def preserves_colimit_of_preserves_colimit_cocone {F : C ⥤ D} {t : cocone K}
(h : is_colimit t) (hF : is_colimit (F.map_cocone t)) : preserves_colimit K F :=
⟨λ t' h', is_colimit.of_iso_colimit hF (functor.map_iso _ (is_colimit.unique_up_to_iso h h'))⟩
/-- Transfer preservation of colimits along a natural isomorphism in the shape. -/
def preserves_colimit_of_iso {K₁ K₂ : J ⥤ C} (F : C ⥤ D) (h : K₁ ≅ K₂) [preserves_colimit K₁ F] :
preserves_colimit K₂ F :=
{ preserves := λ c t,
begin
have t' := is_colimit.of_left_adjoint (cocones.precompose_equivalence h).functor t,
let hF := iso_whisker_right h F,
have := is_colimit.of_left_adjoint (cocones.precompose_equivalence hF).inverse
(preserves_colimit.preserves t'),
apply is_colimit.of_iso_colimit this,
refine cocones.ext (iso.refl _) (λ j, _),
dsimp,
rw [← F.map_comp],
simp,
end }
/--
A functor `F : C ⥤ D` reflects limits for `K : J ⥤ C` if
whenever the image of a cone over `K` under `F` is a limit cone in `D`,
the cone was already a limit cone in `C`.
Note that we do not assume a priori that `D` actually has any limits.
-/
class reflects_limit (K : J ⥤ C) (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(reflects : Π {c : cone K}, is_limit (F.map_cone c) → is_limit c)
/--
A functor `F : C ⥤ D` reflects colimits for `K : J ⥤ C` if
whenever the image of a cocone over `K` under `F` is a colimit cocone in `D`,
the cocone was already a colimit cocone in `C`.
Note that we do not assume a priori that `D` actually has any colimits.
-/
class reflects_colimit (K : J ⥤ C) (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(reflects : Π {c : cocone K}, is_colimit (F.map_cocone c) → is_colimit c)
/--
A functor `F : C ⥤ D` reflects limits of shape `J` if
whenever the image of a cone over some `K : J ⥤ C` under `F` is a limit cone in `D`,
the cone was already a limit cone in `C`.
Note that we do not assume a priori that `D` actually has any limits.
-/
class reflects_limits_of_shape (J : Type v) [small_category J] (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(reflects_limit : Π {K : J ⥤ C}, reflects_limit K F)
/--
A functor `F : C ⥤ D` reflects colimits of shape `J` if
whenever the image of a cocone over some `K : J ⥤ C` under `F` is a colimit cocone in `D`,
the cocone was already a colimit cocone in `C`.
Note that we do not assume a priori that `D` actually has any colimits.
-/
class reflects_colimits_of_shape (J : Type v) [small_category J] (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(reflects_colimit : Π {K : J ⥤ C}, reflects_colimit K F)
/--
A functor `F : C ⥤ D` reflects limits if
whenever the image of a cone over some `K : J ⥤ C` under `F` is a limit cone in `D`,
the cone was already a limit cone in `C`.
Note that we do not assume a priori that `D` actually has any limits.
-/
class reflects_limits (F : C ⥤ D) : Type (max u₁ u₂ (v+1)) :=
(reflects_limits_of_shape : Π {J : Type v} {𝒥 : small_category J}, by exactI reflects_limits_of_shape J F)
/--
A functor `F : C ⥤ D` reflects colimits if
whenever the image of a cocone over some `K : J ⥤ C` under `F` is a colimit cocone in `D`,
the cocone was already a colimit cocone in `C`.
Note that we do not assume a priori that `D` actually has any colimits.
-/
class reflects_colimits (F : C ⥤ D) : Type (max u₁ u₂ (v+1)) :=
(reflects_colimits_of_shape : Π {J : Type v} {𝒥 : small_category J}, by exactI reflects_colimits_of_shape J F)
instance reflects_limit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : subsingleton (reflects_limit K F) :=
by split; rintros ⟨a⟩ ⟨b⟩; congr
instance reflects_colimit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : subsingleton (reflects_colimit K F) :=
by split; rintros ⟨a⟩ ⟨b⟩; congr
instance reflects_limits_of_shape_subsingleton (J : Type v) [small_category J] (F : C ⥤ D) :
subsingleton (reflects_limits_of_shape J F) :=
by { split, intros, cases a, cases b, congr }
instance reflects_colimits_of_shape_subsingleton (J : Type v) [small_category J] (F : C ⥤ D) :
subsingleton (reflects_colimits_of_shape J F) :=
by { split, intros, cases a, cases b, congr }
instance reflects_limits_subsingleton (F : C ⥤ D) : subsingleton (reflects_limits F) :=
by { split, intros, cases a, cases b, cc }
instance reflects_colimits_subsingleton (F : C ⥤ D) : subsingleton (reflects_colimits F) :=
by { split, intros, cases a, cases b, cc }
@[priority 100] -- see Note [lower instance priority]
instance reflects_limit_of_reflects_limits_of_shape (K : J ⥤ C) (F : C ⥤ D)
[H : reflects_limits_of_shape J F] : reflects_limit K F :=
reflects_limits_of_shape.reflects_limit
@[priority 100] -- see Note [lower instance priority]
instance reflects_colimit_of_reflects_colimits_of_shape (K : J ⥤ C) (F : C ⥤ D)
[H : reflects_colimits_of_shape J F] : reflects_colimit K F :=
reflects_colimits_of_shape.reflects_colimit
@[priority 100] -- see Note [lower instance priority]
instance reflects_limits_of_shape_of_reflects_limits (F : C ⥤ D)
[H : reflects_limits F] : reflects_limits_of_shape J F :=
reflects_limits.reflects_limits_of_shape
@[priority 100] -- see Note [lower instance priority]
instance reflects_colimits_of_shape_of_reflects_colimits (F : C ⥤ D)
[H : reflects_colimits F] : reflects_colimits_of_shape J F :=
reflects_colimits.reflects_colimits_of_shape
instance id_reflects_limits : reflects_limits (𝟭 C) :=
{ reflects_limits_of_shape := λ J 𝒥,
{ reflects_limit := λ K, by exactI ⟨λ c h,
⟨λ s, h.lift ⟨s.X, λ j, s.π.app j, λ j j' f, s.π.naturality f⟩,
by cases K; rcases c with ⟨_, _, _⟩; intros s j; cases s; exact h.fac _ j,
by cases K; rcases c with ⟨_, _, _⟩; intros s m w; rcases s with ⟨_, _, _⟩; exact h.uniq _ m w⟩⟩ } }
instance id_reflects_colimits : reflects_colimits (𝟭 C) :=
{ reflects_colimits_of_shape := λ J 𝒥,
{ reflects_colimit := λ K, by exactI ⟨λ c h,
⟨λ s, h.desc ⟨s.X, λ j, s.ι.app j, λ j j' f, s.ι.naturality f⟩,
by cases K; rcases c with ⟨_, _, _⟩; intros s j; cases s; exact h.fac _ j,
by cases K; rcases c with ⟨_, _, _⟩; intros s m w; rcases s with ⟨_, _, _⟩; exact h.uniq _ m w⟩⟩ } }
section
variables {E : Type u₃} [ℰ : category.{v} E]
variables (F : C ⥤ D) (G : D ⥤ E)
instance comp_reflects_limit [reflects_limit K F] [reflects_limit (K ⋙ F) G] :
reflects_limit K (F ⋙ G) :=
⟨λ c h, reflects_limit.reflects (reflects_limit.reflects h)⟩
instance comp_reflects_colimit [reflects_colimit K F] [reflects_colimit (K ⋙ F) G] :
reflects_colimit K (F ⋙ G) :=
⟨λ c h, reflects_colimit.reflects (reflects_colimit.reflects h)⟩
/-- If `F ⋙ G` preserves limits for `K`, and `G` reflects limits for `K ⋙ F`,
then `F` preserves limits for `K`. -/
def preserves_limit_of_reflects_of_preserves [preserves_limit K (F ⋙ G)]
[reflects_limit (K ⋙ F) G] : preserves_limit K F :=
⟨λ c h,
begin
apply @reflects_limit.reflects _ _ _ _ _ _ _ G,
change limits.is_limit ((F ⋙ G).map_cone c),
exact preserves_limit.preserves h
end⟩
/-- If `F ⋙ G` preserves colimits for `K`, and `G` reflects colimits for `K ⋙ F`,
then `F` preserves colimits for `K`. -/
def preserves_colimit_of_reflects_of_preserves [preserves_colimit K (F ⋙ G)]
[reflects_colimit (K ⋙ F) G] : preserves_colimit K F :=
⟨λ c h,
begin
apply @reflects_colimit.reflects _ _ _ _ _ _ _ G,
change limits.is_colimit ((F ⋙ G).map_cocone c),
exact preserves_colimit.preserves h
end⟩
end
variable (F : C ⥤ D)
/-- A fully faithful functor reflects limits. -/
def fully_faithful_reflects_limits [full F] [faithful F] : reflects_limits F :=
{ reflects_limits_of_shape := λ J 𝒥₁, by exactI
{ reflects_limit := λ K,
{ reflects := λ c t,
is_limit.mk_cone_morphism (λ s, (cones.functoriality K F).preimage (t.lift_cone_morphism _)) $
begin
apply (λ s m, (cones.functoriality K F).map_injective _),
rw [functor.image_preimage],
apply t.uniq_cone_morphism,
end } } }
/-- A fully faithful functor reflects colimits. -/
def fully_faithful_reflects_colimits [full F] [faithful F] : reflects_colimits F :=
{ reflects_colimits_of_shape := λ J 𝒥₁, by exactI
{ reflects_colimit := λ K,
{ reflects := λ c t,
is_colimit.mk_cocone_morphism (λ s, (cocones.functoriality K F).preimage (t.desc_cocone_morphism _)) $
begin
apply (λ s m, (cocones.functoriality K F).map_injective _),
rw [functor.image_preimage],
apply t.uniq_cocone_morphism,
end } } }
end category_theory.limits
|
86f10cbe5c8d5569aa14cbd9359d2af47432e2c3 | 367134ba5a65885e863bdc4507601606690974c1 | /test/monotonicity/test_cases.lean | e17a5e5f3b7d9319fc5a96fe44847c0fc3b1cc62 | [
"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 | 3,124 | lean | /-
Copyright (c) 2019 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Simon Hudon
-/
import tactic.monotonicity.interactive
open list tactic tactic.interactive
meta class elaborable (α : Type) (β : out_param Type) :=
(elaborate : α → tactic β)
export elaborable (elaborate)
meta instance : elaborable pexpr expr :=
⟨ to_expr ⟩
meta instance elaborable_list {α α'} [elaborable α α'] : elaborable (list α) (list α') :=
⟨ mmap elaborate ⟩
meta def mono_function.elaborate : mono_function ff → tactic mono_function
| (mono_function.non_assoc x y z) :=
mono_function.non_assoc <$> elaborate x
<*> elaborate y
<*> elaborate z
| (mono_function.assoc x y z) :=
mono_function.assoc <$> elaborate x
<*> traverse elaborate y
<*> traverse elaborate z
| (mono_function.assoc_comm x y) :=
mono_function.assoc_comm <$> elaborate x
<*> elaborate y
meta instance elaborable_mono_function : elaborable (mono_function ff) mono_function :=
⟨ mono_function.elaborate ⟩
meta instance prod_elaborable {α α' β β' : Type} [elaborable α α'] [elaborable β β']
: elaborable (α × β) (α' × β') :=
⟨ λ i, prod.rec_on i (λ x y, prod.mk <$> elaborate x <*> elaborate y) ⟩
meta def parse_mono_function' (l r : pexpr) :=
do l' ← to_expr l,
r' ← to_expr r,
parse_ac_mono_function { mono_cfg . } l' r'
run_cmd
do xs ← mmap to_expr [``(1),``(2),``(3)],
ys ← mmap to_expr [``(1),``(2),``(4)],
x ← match_prefix { unify := ff } xs ys,
p ← elaborate ([``(1),``(2)] , [``(3)], [``(4)]),
guard $ x = p
run_cmd
do xs ← mmap to_expr [``(1),``(2),``(3),``(6),``(7)],
ys ← mmap to_expr [``(1),``(2),``(4),``(5),``(6),``(7)],
x ← match_assoc { unify := ff } xs ys,
p ← elaborate ([``(1), ``(2)], [``(3)], ([``(4), ``(5)], [``(6), ``(7)])),
guard (x = p)
run_cmd
do x ← to_expr ``(7 + 3 : ℕ) >>= check_ac,
x ← pp x.2.2.1,
let y := "(some (is_left_id.left_id, (is_right_id.right_id, 0)))",
guard (x.to_string = y) <|> fail ("guard: " ++ x.to_string)
meta def test_pp {α} [has_to_tactic_format α] (tag : format) (expected : string) (prog : tactic α) :
tactic unit :=
do r ← prog,
pp_r ← pp r,
guard (pp_r.to_string = expected) <|> fail format!"test_pp: {tag}"
run_cmd
do test_pp "test1"
"(3 + 6, (4 + 5, ([], has_add.add _ 2 + 1)))"
(parse_mono_function' ``(1 + 3 + 2 + 6) ``(4 + 2 + 1 + 5)),
test_pp "test2"
"([1] ++ [3] ++ [2] ++ [6], ([4] ++ [2] ++ [1] ++ [5], ([], append none _ none)))"
(parse_mono_function' ``([1] ++ [3] ++ [2] ++ [6]) ``([4] ++ [2] ++ ([1] ++ [5]))),
test_pp "test3"
"([3] ++ [2], ([5] ++ [4], ([], append (some [1]) _ (some [2]))))"
(parse_mono_function' ``([1] ++ [3] ++ [2] ++ [2]) ``([1] ++ [5] ++ ([4] ++ [2])))
@[mono]
lemma test {α : Type*} [preorder α] : monotone (id : α → α) :=
λ x y h, h
example : id 0 ≤ id 1 :=
begin
mono,
simp,
end
|
9b4a04b8807dcfaa027e7c4b98f9fcfc4412cb3f | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/analysis/p_series_auto.lean | 9c537efb4f824213f49c759406d718708d8bf079 | [] | 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 | 6,098 | 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 Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.analysis.special_functions.pow
import Mathlib.PostPort
universes u_1
namespace Mathlib
/-!
# Convergence of `p`-series
In this file we prove that the series `∑' k in ℕ, 1 / k ^ p` converges if and only if `p > 1`.
The proof is based on the
[Cauchy condensation test](https://en.wikipedia.org/wiki/Cauchy_condensation_test): `∑ k, f k`
converges if and only if so does `∑ k, 2 ^ k f (2 ^ k)`. We prove this test in
`nnreal.summable_condensed_iff` and `summable_condensed_iff_of_nonneg`, then use it to prove
`summable_one_div_rpow`. After this transformation, a `p`-series turns into a geometric series.
## TODO
It should be easy to generalize arguments to Schlömilch's generalization of the Cauchy condensation
test once we need it.
## Tags
p-series, Cauchy condensation test
-/
/-!
### Cauchy condensation test
In this section we prove the Cauchy condensation test: for `f : ℕ → ℝ≥0` or `f : ℕ → ℝ`,
`∑ k, f k` converges if and only if so does `∑ k, 2 ^ k f (2 ^ k)`. Instead of giving a monolithic
proof, we split it into a series of lemmas with explicit estimates of partial sums of each series in
terms of the partial sums of the other series.
-/
namespace finset
theorem le_sum_condensed' {M : Type u_1} [ordered_add_comm_monoid M] {f : ℕ → M}
(hf : ∀ {m n : ℕ}, 0 < m → m ≤ n → f n ≤ f m) (n : ℕ) :
(finset.sum (Ico 1 (bit0 1 ^ n)) fun (k : ℕ) => f k) ≤
finset.sum (range n) fun (k : ℕ) => bit0 1 ^ k •ℕ f (bit0 1 ^ k) :=
sorry
theorem le_sum_condensed {M : Type u_1} [ordered_add_comm_monoid M] {f : ℕ → M}
(hf : ∀ {m n : ℕ}, 0 < m → m ≤ n → f n ≤ f m) (n : ℕ) :
(finset.sum (range (bit0 1 ^ n)) fun (k : ℕ) => f k) ≤
f 0 + finset.sum (range n) fun (k : ℕ) => bit0 1 ^ k •ℕ f (bit0 1 ^ k) :=
sorry
theorem sum_condensed_le' {M : Type u_1} [ordered_add_comm_monoid M] {f : ℕ → M}
(hf : ∀ {m n : ℕ}, 1 < m → m ≤ n → f n ≤ f m) (n : ℕ) :
(finset.sum (range n) fun (k : ℕ) => bit0 1 ^ k •ℕ f (bit0 1 ^ (k + 1))) ≤
finset.sum (Ico (bit0 1) (bit0 1 ^ n + 1)) fun (k : ℕ) => f k :=
sorry
theorem sum_condensed_le {M : Type u_1} [ordered_add_comm_monoid M] {f : ℕ → M}
(hf : ∀ {m n : ℕ}, 1 < m → m ≤ n → f n ≤ f m) (n : ℕ) :
(finset.sum (range (n + 1)) fun (k : ℕ) => bit0 1 ^ k •ℕ f (bit0 1 ^ k)) ≤
f 1 + bit0 1 •ℕ finset.sum (Ico (bit0 1) (bit0 1 ^ n + 1)) fun (k : ℕ) => f k :=
sorry
end finset
namespace ennreal
theorem le_tsum_condensed {f : ℕ → ennreal} (hf : ∀ {m n : ℕ}, 0 < m → m ≤ n → f n ≤ f m) :
(tsum fun (k : ℕ) => f k) ≤ f 0 + tsum fun (k : ℕ) => bit0 1 ^ k * f (bit0 1 ^ k) :=
sorry
theorem tsum_condensed_le {f : ℕ → ennreal} (hf : ∀ {m n : ℕ}, 1 < m → m ≤ n → f n ≤ f m) :
(tsum fun (k : ℕ) => bit0 1 ^ k * f (bit0 1 ^ k)) ≤ f 1 + bit0 1 * tsum fun (k : ℕ) => f k :=
sorry
end ennreal
namespace nnreal
/-- Cauchy condensation test for a series of `nnreal` version. -/
theorem summable_condensed_iff {f : ℕ → nnreal} (hf : ∀ {m n : ℕ}, 0 < m → m ≤ n → f n ≤ f m) :
(summable fun (k : ℕ) => bit0 1 ^ k * f (bit0 1 ^ k)) ↔ summable f :=
sorry
end nnreal
/-- Cauchy condensation test for series of nonnegative real numbers. -/
theorem summable_condensed_iff_of_nonneg {f : ℕ → ℝ} (h_nonneg : ∀ (n : ℕ), 0 ≤ f n)
(h_mono : ∀ {m n : ℕ}, 0 < m → m ≤ n → f n ≤ f m) :
(summable fun (k : ℕ) => bit0 1 ^ k * f (bit0 1 ^ k)) ↔ summable f :=
sorry
/-!
### Convergence of the `p`-series
In this section we prove that for a real number `p`, the series `∑' n : ℕ, 1 / (n ^ p)` converges if
and only if `1 < p`. There are many different proofs of this fact. The proof in this file uses the
Cauchy condensation test we formalized above. This test implies that `∑ n, 1 / (n ^ p)` converges if
and only if `∑ n, 2 ^ n / ((2 ^ n) ^ p)` converges, and the latter series is a geometric series with
common ratio `2 ^ {1 - p}`. -/
/-- Test for congergence of the `p`-series: the real-valued series `∑' n : ℕ, (n ^ p)⁻¹` converges
if and only if `1 < p`. -/
@[simp] theorem real.summable_nat_rpow_inv {p : ℝ} : (summable fun (n : ℕ) => ↑n ^ p⁻¹) ↔ 1 < p :=
sorry
/-- Test for congergence of the `p`-series: the real-valued series `∑' n : ℕ, 1 / n ^ p` converges
if and only if `1 < p`. -/
theorem real.summable_one_div_nat_rpow {p : ℝ} : (summable fun (n : ℕ) => 1 / ↑n ^ p) ↔ 1 < p :=
sorry
/-- Test for congergence of the `p`-series: the real-valued series `∑' n : ℕ, (n ^ p)⁻¹` converges
if and only if `1 < p`. -/
@[simp] theorem real.summable_nat_pow_inv {p : ℕ} : (summable fun (n : ℕ) => ↑n ^ p⁻¹) ↔ 1 < p :=
sorry
/-- Test for congergence of the `p`-series: the real-valued series `∑' n : ℕ, 1 / n ^ p` converges
if and only if `1 < p`. -/
theorem real.summable_one_div_nat_pow {p : ℕ} : (summable fun (n : ℕ) => 1 / ↑n ^ p) ↔ 1 < p :=
sorry
/-- Harmonic series is not unconditionally summable. -/
theorem real.not_summable_nat_cast_inv : ¬summable fun (n : ℕ) => ↑n⁻¹ := sorry
/-- Harmonic series is not unconditionally summable. -/
theorem real.not_summable_one_div_nat_cast : ¬summable fun (n : ℕ) => 1 / ↑n := sorry
/-- Harmonic series diverges. -/
theorem real.tendsto_sum_range_one_div_nat_succ_at_top :
filter.tendsto (fun (n : ℕ) => finset.sum (finset.range n) fun (i : ℕ) => 1 / (↑i + 1))
filter.at_top filter.at_top :=
sorry
@[simp] theorem nnreal.summable_one_rpow_inv {p : ℝ} : (summable fun (n : ℕ) => ↑n ^ p⁻¹) ↔ 1 < p :=
sorry
theorem nnreal.summable_one_div_rpow {p : ℝ} : (summable fun (n : ℕ) => 1 / ↑n ^ p) ↔ 1 < p := sorry
end Mathlib |
26c53527cb1eda6196d4cd9fcc6139ecd95f92de | 037dba89703a79cd4a4aec5e959818147f97635d | /src/2019/questions/sheet2.lean | a3e61986419e149d88d3585926dff54e30a8ff57 | [] | no_license | ImperialCollegeLondon/M40001_lean | 3a6a09298da395ab51bc220a535035d45bbe919b | 62a76fa92654c855af2b2fc2bef8e60acd16ccec | refs/heads/master | 1,666,750,403,259 | 1,665,771,117,000 | 1,665,771,117,000 | 209,141,835 | 115 | 12 | null | 1,640,270,596,000 | 1,568,749,174,000 | Lean | UTF-8 | Lean | false | false | 3,513 | lean | /- Math40001 : Introduction to university mathematics.
Problem Sheet 2, October 2019.
This is a Lean file. It can be read with the Lean theorem prover.
You can work on this file online at
https://tinyurl.com/Lean-M40001-Example-Sheet-2
or you can install Lean and its maths library following the
instructions at
https://github.com/leanprover-community/mathlib#installation
There are advantages to installing Lean on your own computer
(for example it's faster), but it's more hassle than
just using it online.
In the below, delete "sorry" and replace it with some
tactics which prove the result.
-/
import data.real.basic -- need real numbers for Q5
-- Q1 prove that ∩ is symmetric
lemma question1 (Ω : Type) (X Y : set Ω) : X ∩ Y = Y ∩ X :=
begin
sorry
end
-- Q2 we define the set U
def U : set ℕ := {1, 2, 3, 4, 5}
/- and then five of the questions still make sense
in type theory, and the other three don't.
What I'm saying is that b,f,g would continue to be
wrong even if you changed the numbers around, because
the questions do not even typecheck: U only contains
numbers, and b, f, g are asking if a non-number is
in U.
For the remaining five questions, if you think they're
false then change `_true` to `_false` and add a ¬ in front.
-/
lemma question2a_true : 1 ∈ U :=
begin
sorry
end
lemma question2c_true : {1} ⊆ U :=
begin
sorry
end
lemma question2d_true : {1, 2} ⊆ U :=
begin
sorry
end
lemma question2e_true : {1, 2, 1} ⊆ U :=
begin
sorry
end
lemma question2h_true : U ⊇ U :=
begin
sorry
end
-- question 3 defs
def A := {x : ℝ | x ^ 2 < 3}
def B := {x : ℝ | ∃ n : ℤ, x = n ∧ x ^ 2 < 3}
def C := {x : ℝ | x ^ 3 < 3}
-- like Q2, change _true to _false and put a ¬ in front
-- of the goal if you think it's false.
lemma question3a_true : (1 : ℝ)/2 ∈ A ∩ B :=
begin
sorry
end
lemma question3b_true : (1 : ℝ)/2 ∈ A ∪ B :=
begin
sorry
end
lemma question3c_true : A ⊆ C :=
begin
sorry
end
lemma question3d_true : B ⊆ C :=
begin
sorry
end
lemma question3e_true : C ⊆ A ∪ B :=
begin
sorry
end
lemma question3f_true : (A ∩ B) ∪ C = (A ∪ B) ∩ C :=
begin
sorry
end
-- Q4 set-up
variables (X Y : Type)
variable (P : X → Prop)
variable (Q : X → Prop)
variable (R : X → Y → Prop)
-- for Q4 you're going to have to change the right hand
-- side of the ↔ in the statement
-- of the lemma to the answer you think is correct.
lemma question4a : ¬ (∀ x : X, P x ∧ ¬ Q x) ↔ true := -- change `true`!
begin
sorry
end
lemma question4b : ¬ (∃ x : X, (¬ P x) ∧ Q x) ↔ true := -- change `true`!
begin
sorry
end
lemma question4c : ¬ (∀ x : X, ∃ y : Y, R x y) ↔ true := -- change `true`!
begin
sorry
end
example (f : ℝ → ℝ) (x : ℝ) :
¬ (∀ ε : ℝ, ε > 0 → ∃ δ : ℝ, δ > 0 → ∀ y : ℝ, abs (y - x) < δ → abs (f y -f x) < ε )
↔ -- change next line
true :=
begin
sorry
end
-- change _true to _false in 5a, 5b if you think the opposite is true.
lemma question5a_true : ∀ x : ℝ, ∃ y : ℝ, x + y = 2 :=
begin
sorry
end
lemma question5b_true : ∃ y : ℝ, ∀ x : ℝ, x + y = 2 :=
begin
sorry
end
-- similarly for Q6 -- change _true to _false and add in a negation if you
-- want to prove that the proposition in the question is false.
lemma question6a_true : ∃ x ∈ (∅ : set ℕ), 2 + 2 = 5 :=
begin
sorry
end
lemma question6b_true : ∀ x ∈ (∅ : set ℕ), 2 + 2 = 5 :=
begin
sorry
end
|
a28077c096fcb16474ff871e104e6b2e7f7cea34 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/fail/non_meta_rec_fn.lean | dcdbf0ff24191a08212361a307aac1d0c475dc7a | [
"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 | 109 | lean | lemma main : false :=
begin
have helper : true → false := λ ⟨⟩, _fun_match _x,
exact helper ⟨⟩
end |
aff406750fd257ef2c3eedf13dd4c164e14c431c | 592ee40978ac7604005a4e0d35bbc4b467389241 | /Library/generated/mathscheme-lean/MedialMagma.lean | c63c3eff44480648c626fcdcceeb29bc35a1d837 | [] | no_license | ysharoda/Deriving-Definitions | 3e149e6641fae440badd35ac110a0bd705a49ad2 | dfecb27572022de3d4aa702cae8db19957523a59 | refs/heads/master | 1,679,127,857,700 | 1,615,939,007,000 | 1,615,939,007,000 | 229,785,731 | 4 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,875 | lean | import init.data.nat.basic
import init.data.fin.basic
import data.vector
import .Prelude
open Staged
open nat
open fin
open vector
section MedialMagma
structure MedialMagma (A : Type) : Type :=
(op : (A → (A → A)))
(mediates : (∀ {w x y z : A} , (op (op x y) (op z w)) = (op (op x z) (op y w))))
open MedialMagma
structure Sig (AS : Type) : Type :=
(opS : (AS → (AS → AS)))
structure Product (A : Type) : Type :=
(opP : ((Prod A A) → ((Prod A A) → (Prod A A))))
(mediatesP : (∀ {wP xP yP zP : (Prod A A)} , (opP (opP xP yP) (opP zP wP)) = (opP (opP xP zP) (opP yP wP))))
structure Hom {A1 : Type} {A2 : Type} (Me1 : (MedialMagma A1)) (Me2 : (MedialMagma A2)) : Type :=
(hom : (A1 → A2))
(pres_op : (∀ {x1 x2 : A1} , (hom ((op Me1) x1 x2)) = ((op Me2) (hom x1) (hom x2))))
structure RelInterp {A1 : Type} {A2 : Type} (Me1 : (MedialMagma A1)) (Me2 : (MedialMagma A2)) : Type 1 :=
(interp : (A1 → (A2 → Type)))
(interp_op : (∀ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) → ((interp x2 y2) → (interp ((op Me1) x1 x2) ((op Me2) y1 y2))))))
inductive MedialMagmaTerm : Type
| opL : (MedialMagmaTerm → (MedialMagmaTerm → MedialMagmaTerm))
open MedialMagmaTerm
inductive ClMedialMagmaTerm (A : Type) : Type
| sing : (A → ClMedialMagmaTerm)
| opCl : (ClMedialMagmaTerm → (ClMedialMagmaTerm → ClMedialMagmaTerm))
open ClMedialMagmaTerm
inductive OpMedialMagmaTerm (n : ℕ) : Type
| v : ((fin n) → OpMedialMagmaTerm)
| opOL : (OpMedialMagmaTerm → (OpMedialMagmaTerm → OpMedialMagmaTerm))
open OpMedialMagmaTerm
inductive OpMedialMagmaTerm2 (n : ℕ) (A : Type) : Type
| v2 : ((fin n) → OpMedialMagmaTerm2)
| sing2 : (A → OpMedialMagmaTerm2)
| opOL2 : (OpMedialMagmaTerm2 → (OpMedialMagmaTerm2 → OpMedialMagmaTerm2))
open OpMedialMagmaTerm2
def simplifyCl {A : Type} : ((ClMedialMagmaTerm A) → (ClMedialMagmaTerm A))
| (opCl x1 x2) := (opCl (simplifyCl x1) (simplifyCl x2))
| (sing x1) := (sing x1)
def simplifyOpB {n : ℕ} : ((OpMedialMagmaTerm n) → (OpMedialMagmaTerm n))
| (opOL x1 x2) := (opOL (simplifyOpB x1) (simplifyOpB x2))
| (v x1) := (v x1)
def simplifyOp {n : ℕ} {A : Type} : ((OpMedialMagmaTerm2 n A) → (OpMedialMagmaTerm2 n A))
| (opOL2 x1 x2) := (opOL2 (simplifyOp x1) (simplifyOp x2))
| (v2 x1) := (v2 x1)
| (sing2 x1) := (sing2 x1)
def evalB {A : Type} : ((MedialMagma A) → (MedialMagmaTerm → A))
| Me (opL x1 x2) := ((op Me) (evalB Me x1) (evalB Me x2))
def evalCl {A : Type} : ((MedialMagma A) → ((ClMedialMagmaTerm A) → A))
| Me (sing x1) := x1
| Me (opCl x1 x2) := ((op Me) (evalCl Me x1) (evalCl Me x2))
def evalOpB {A : Type} {n : ℕ} : ((MedialMagma A) → ((vector A n) → ((OpMedialMagmaTerm n) → A)))
| Me vars (v x1) := (nth vars x1)
| Me vars (opOL x1 x2) := ((op Me) (evalOpB Me vars x1) (evalOpB Me vars x2))
def evalOp {A : Type} {n : ℕ} : ((MedialMagma A) → ((vector A n) → ((OpMedialMagmaTerm2 n A) → A)))
| Me vars (v2 x1) := (nth vars x1)
| Me vars (sing2 x1) := x1
| Me vars (opOL2 x1 x2) := ((op Me) (evalOp Me vars x1) (evalOp Me vars x2))
def inductionB {P : (MedialMagmaTerm → Type)} : ((∀ (x1 x2 : MedialMagmaTerm) , ((P x1) → ((P x2) → (P (opL x1 x2))))) → (∀ (x : MedialMagmaTerm) , (P x)))
| popl (opL x1 x2) := (popl _ _ (inductionB popl x1) (inductionB popl x2))
def inductionCl {A : Type} {P : ((ClMedialMagmaTerm A) → Type)} : ((∀ (x1 : A) , (P (sing x1))) → ((∀ (x1 x2 : (ClMedialMagmaTerm A)) , ((P x1) → ((P x2) → (P (opCl x1 x2))))) → (∀ (x : (ClMedialMagmaTerm A)) , (P x))))
| psing popcl (sing x1) := (psing x1)
| psing popcl (opCl x1 x2) := (popcl _ _ (inductionCl psing popcl x1) (inductionCl psing popcl x2))
def inductionOpB {n : ℕ} {P : ((OpMedialMagmaTerm n) → Type)} : ((∀ (fin : (fin n)) , (P (v fin))) → ((∀ (x1 x2 : (OpMedialMagmaTerm n)) , ((P x1) → ((P x2) → (P (opOL x1 x2))))) → (∀ (x : (OpMedialMagmaTerm n)) , (P x))))
| pv popol (v x1) := (pv x1)
| pv popol (opOL x1 x2) := (popol _ _ (inductionOpB pv popol x1) (inductionOpB pv popol x2))
def inductionOp {n : ℕ} {A : Type} {P : ((OpMedialMagmaTerm2 n A) → Type)} : ((∀ (fin : (fin n)) , (P (v2 fin))) → ((∀ (x1 : A) , (P (sing2 x1))) → ((∀ (x1 x2 : (OpMedialMagmaTerm2 n A)) , ((P x1) → ((P x2) → (P (opOL2 x1 x2))))) → (∀ (x : (OpMedialMagmaTerm2 n A)) , (P x)))))
| pv2 psing2 popol2 (v2 x1) := (pv2 x1)
| pv2 psing2 popol2 (sing2 x1) := (psing2 x1)
| pv2 psing2 popol2 (opOL2 x1 x2) := (popol2 _ _ (inductionOp pv2 psing2 popol2 x1) (inductionOp pv2 psing2 popol2 x2))
def stageB : (MedialMagmaTerm → (Staged MedialMagmaTerm))
| (opL x1 x2) := (stage2 opL (codeLift2 opL) (stageB x1) (stageB x2))
def stageCl {A : Type} : ((ClMedialMagmaTerm A) → (Staged (ClMedialMagmaTerm A)))
| (sing x1) := (Now (sing x1))
| (opCl x1 x2) := (stage2 opCl (codeLift2 opCl) (stageCl x1) (stageCl x2))
def stageOpB {n : ℕ} : ((OpMedialMagmaTerm n) → (Staged (OpMedialMagmaTerm n)))
| (v x1) := (const (code (v x1)))
| (opOL x1 x2) := (stage2 opOL (codeLift2 opOL) (stageOpB x1) (stageOpB x2))
def stageOp {n : ℕ} {A : Type} : ((OpMedialMagmaTerm2 n A) → (Staged (OpMedialMagmaTerm2 n A)))
| (sing2 x1) := (Now (sing2 x1))
| (v2 x1) := (const (code (v2 x1)))
| (opOL2 x1 x2) := (stage2 opOL2 (codeLift2 opOL2) (stageOp x1) (stageOp x2))
structure StagedRepr (A : Type) (Repr : (Type → Type)) : Type :=
(opT : ((Repr A) → ((Repr A) → (Repr A))))
end MedialMagma |
a2ab71a2c7d14ae6bd8b9163923c9fec884bb7fb | 6dc0c8ce7a76229dd81e73ed4474f15f88a9e294 | /tests/lean/run/rational.lean | 9855253fdcd67797984ee1a765b8655ca9c894b9 | [
"Apache-2.0"
] | permissive | williamdemeo/lean4 | 72161c58fe65c3ad955d6a3050bb7d37c04c0d54 | 6d00fcf1d6d873e195f9220c668ef9c58e9c4a35 | refs/heads/master | 1,678,305,356,877 | 1,614,708,995,000 | 1,614,708,995,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 586 | lean | structure Rat where
num : Int
den : Nat
pos : den > 0
instance (n : Nat) : OfNat Rat n where
ofNat := {
num := n
den := 1
pos := decide!
}
instance : Add Rat where
add a b := {
num := a.num * b.den + b.num * a.den
den := a.den * b.den
pos := sorry
}
instance : Coe Int Rat where
coe n := {
num := n
den := 1
pos := decide!
}
def f1 (x : Rat) (n : Nat) : Rat :=
x + n + 1
def f2 (x : Rat) (n : Nat) : Rat :=
1 + x + n
def f3 (x : Rat) (n : Nat) : Rat :=
1 + n + x + 2
def f4 (x : Rat) (n : Nat) : Rat :=
n + 1 + x + n
|
f09088cdd914a1a832680d61dd8b319adafa5332 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/analysis/quaternion.lean | edf0e50c73d874d3aa38cdb56708f8ed2a84f987 | [
"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 | 3,366 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import algebra.quaternion
import analysis.inner_product_space.basic
/-!
# Quaternions as a normed algebra
In this file we define the following structures on the space `ℍ := ℍ[ℝ]` of quaternions:
* inner product space;
* normed ring;
* normed space over `ℝ`.
## Notation
The following notation is available with `open_locale quaternion`:
* `ℍ` : quaternions
## Tags
quaternion, normed ring, normed space, normed algebra
-/
localized "notation `ℍ` := quaternion ℝ" in quaternion
open_locale real_inner_product_space
noncomputable theory
namespace quaternion
instance : has_inner ℝ ℍ := ⟨λ a b, (a * b.conj).re⟩
lemma inner_self (a : ℍ) : ⟪a, a⟫ = norm_sq a := rfl
lemma inner_def (a b : ℍ) : ⟪a, b⟫ = (a * b.conj).re := rfl
instance : inner_product_space ℝ ℍ :=
inner_product_space.of_core
{ inner := has_inner.inner,
conj_sym := λ x y, by simp [inner_def, mul_comm],
nonneg_re := λ x, norm_sq_nonneg,
definite := λ x, norm_sq_eq_zero.1,
add_left := λ x y z, by simp only [inner_def, add_mul, add_re],
smul_left := λ x y r, by simp [inner_def] }
lemma norm_sq_eq_norm_sq (a : ℍ) : norm_sq a = ∥a∥ * ∥a∥ :=
by rw [← inner_self, real_inner_self_eq_norm_mul_norm]
instance : norm_one_class ℍ :=
⟨by rw [norm_eq_sqrt_real_inner, inner_self, norm_sq.map_one, real.sqrt_one]⟩
@[simp] lemma norm_mul (a b : ℍ) : ∥a * b∥ = ∥a∥ * ∥b∥ :=
begin
simp only [norm_eq_sqrt_real_inner, inner_self, norm_sq.map_mul],
exact real.sqrt_mul norm_sq_nonneg _
end
@[simp, norm_cast] lemma norm_coe (a : ℝ) : ∥(a : ℍ)∥ = ∥a∥ :=
by rw [norm_eq_sqrt_real_inner, inner_self, norm_sq_coe, real.sqrt_sq_eq_abs, real.norm_eq_abs]
noncomputable instance : normed_ring ℍ :=
{ dist_eq := λ _ _, rfl,
norm_mul := λ a b, (norm_mul a b).le }
noncomputable instance : normed_algebra ℝ ℍ :=
{ norm_algebra_map_eq := norm_coe,
to_algebra := quaternion.algebra }
instance : has_coe ℂ ℍ := ⟨λ z, ⟨z.re, z.im, 0, 0⟩⟩
@[simp, norm_cast] lemma coe_complex_re (z : ℂ) : (z : ℍ).re = z.re := rfl
@[simp, norm_cast] lemma coe_complex_im_i (z : ℂ) : (z : ℍ).im_i = z.im := rfl
@[simp, norm_cast] lemma coe_complex_im_j (z : ℂ) : (z : ℍ).im_j = 0 := rfl
@[simp, norm_cast] lemma coe_complex_im_k (z : ℂ) : (z : ℍ).im_k = 0 := rfl
@[simp, norm_cast] lemma coe_complex_add (z w : ℂ) : ↑(z + w) = (z + w : ℍ) := by ext; simp
@[simp, norm_cast] lemma coe_complex_mul (z w : ℂ) : ↑(z * w) = (z * w : ℍ) := by ext; simp
@[simp, norm_cast] lemma coe_complex_zero : ((0 : ℂ) : ℍ) = 0 := rfl
@[simp, norm_cast] lemma coe_complex_one : ((1 : ℂ) : ℍ) = 1 := rfl
@[simp, norm_cast] lemma coe_real_complex_mul (r : ℝ) (z : ℂ) : (r • z : ℍ) = ↑r * ↑z :=
by ext; simp
@[simp, norm_cast] lemma coe_complex_coe (r : ℝ) : ((r : ℂ) : ℍ) = r := rfl
/-- Coercion `ℂ →ₐ[ℝ] ℍ` as an algebra homomorphism. -/
def of_complex : ℂ →ₐ[ℝ] ℍ :=
{ to_fun := coe,
map_one' := rfl,
map_zero' := rfl,
map_add' := coe_complex_add,
map_mul' := coe_complex_mul,
commutes' := λ x, rfl }
@[simp] lemma coe_of_complex : ⇑of_complex = coe := rfl
end quaternion
|
990637c896fe71ed662c6f2dee5ca5dac19bf799 | 22e97a5d648fc451e25a06c668dc03ac7ed7bc25 | /src/data/equiv/ring.lean | 5557539ed8c45bbd5c1aca170be37d05dec0a241 | [
"Apache-2.0"
] | permissive | keeferrowan/mathlib | f2818da875dbc7780830d09bd4c526b0764a4e50 | aad2dfc40e8e6a7e258287a7c1580318e865817e | refs/heads/master | 1,661,736,426,952 | 1,590,438,032,000 | 1,590,438,032,000 | 266,892,663 | 0 | 0 | Apache-2.0 | 1,590,445,835,000 | 1,590,445,835,000 | null | UTF-8 | Lean | false | false | 9,533 | lean | /-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Callum Sutton, Yury Kudryashov
-/
import data.equiv.mul_add
import algebra.field
import deprecated.ring
/-!
# (Semi)ring equivs
In this file we define extension of `equiv` called `ring_equiv`, which is a datatype representing an
isomorphism of `semiring`s, `ring`s, `division_ring`s, or `field`s. We also introduce the
corresponding group of automorphisms `ring_aut`.
## Notations
The extended equiv have coercions to functions, and the coercion is the canonical notation when
treating the isomorphism as maps.
## Implementation notes
The fields for `ring_equiv` now avoid the unbundled `is_mul_hom` and `is_add_hom`, as these are
deprecated.
Definition of multiplication in the groups of automorphisms agrees with function composition,
multiplication in `equiv.perm`, and multiplication in `category_theory.End`, not with
`category_theory.comp`.
## Tags
equiv, mul_equiv, add_equiv, ring_equiv, mul_aut, add_aut, ring_aut
-/
variables {R : Type*} {S : Type*} {S' : Type*}
set_option old_structure_cmd true
/- (semi)ring equivalence. -/
structure ring_equiv (R S : Type*) [has_mul R] [has_add R] [has_mul S] [has_add S]
extends R ≃ S, R ≃* S, R ≃+ S
infix ` ≃+* `:25 := ring_equiv
namespace ring_equiv
section basic
variables [has_mul R] [has_add R] [has_mul S] [has_add S] [has_mul S'] [has_add S']
instance : has_coe_to_fun (R ≃+* S) := ⟨_, ring_equiv.to_fun⟩
instance has_coe_to_mul_equiv : has_coe (R ≃+* S) (R ≃* S) := ⟨ring_equiv.to_mul_equiv⟩
instance has_coe_to_add_equiv : has_coe (R ≃+* S) (R ≃+ S) := ⟨ring_equiv.to_add_equiv⟩
@[norm_cast] lemma coe_mul_equiv (f : R ≃+* S) (a : R) :
(f : R ≃* S) a = f a := rfl
@[norm_cast] lemma coe_add_equiv (f : R ≃+* S) (a : R) :
(f : R ≃+ S) a = f a := rfl
variable (R)
/-- The identity map is a ring isomorphism. -/
@[refl] protected def refl : R ≃+* R := { .. mul_equiv.refl R, .. add_equiv.refl R }
variables {R}
/-- The inverse of a ring isomorphism is a ring isomorphism. -/
@[symm] protected def symm (e : R ≃+* S) : S ≃+* R :=
{ .. e.to_mul_equiv.symm, .. e.to_add_equiv.symm }
/-- Transitivity of `ring_equiv`. -/
@[trans] protected def trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') : R ≃+* S' :=
{ .. (e₁.to_mul_equiv.trans e₂.to_mul_equiv), .. (e₁.to_add_equiv.trans e₂.to_add_equiv) }
@[simp] lemma apply_symm_apply (e : R ≃+* S) : ∀ x, e (e.symm x) = x := e.to_equiv.apply_symm_apply
@[simp] lemma symm_apply_apply (e : R ≃+* S) : ∀ x, e.symm (e x) = x := e.to_equiv.symm_apply_apply
lemma image_eq_preimage (e : R ≃+* S) (s : set R) : e '' s = e.symm ⁻¹' s :=
e.to_equiv.image_eq_preimage s
end basic
section
variables [semiring R] [semiring S] (f : R ≃+* S) (x y : R)
/-- A ring isomorphism preserves multiplication. -/
@[simp] lemma map_mul : f (x * y) = f x * f y := f.map_mul' x y
/-- A ring isomorphism sends one to one. -/
@[simp] lemma map_one : f 1 = 1 := (f : R ≃* S).map_one
/-- A ring isomorphism preserves addition. -/
@[simp] lemma map_add : f (x + y) = f x + f y := f.map_add' x y
/-- A ring isomorphism sends zero to zero. -/
@[simp] lemma map_zero : f 0 = 0 := (f : R ≃+ S).map_zero
variable {x}
@[simp] lemma map_eq_one_iff : f x = 1 ↔ x = 1 := (f : R ≃* S).map_eq_one_iff
@[simp] lemma map_eq_zero_iff : f x = 0 ↔ x = 0 := (f : R ≃+ S).map_eq_zero_iff
lemma map_ne_one_iff : f x ≠ 1 ↔ x ≠ 1 := (f : R ≃* S).map_ne_one_iff
lemma map_ne_zero_iff : f x ≠ 0 ↔ x ≠ 0 := (f : R ≃+ S).map_ne_zero_iff
end
section
variables [ring R] [ring S] (f : R ≃+* S) (x y : R)
@[simp] lemma map_neg : f (-x) = -f x := (f : R ≃+ S).map_neg x
@[simp] lemma map_sub : f (x - y) = f x - f y := (f : R ≃+ S).map_sub x y
@[simp] lemma map_neg_one : f (-1) = -1 := f.map_one ▸ f.map_neg 1
end
section semiring_hom
variables [semiring R] [semiring S]
/-- Reinterpret a ring equivalence as a ring homomorphism. -/
def to_ring_hom (e : R ≃+* S) : R →+* S :=
{ .. e.to_mul_equiv.to_monoid_hom, .. e.to_add_equiv.to_add_monoid_hom }
/-- Reinterpret a ring equivalence as a monoid homomorphism. -/
abbreviation to_monoid_hom (e : R ≃+* S) : R →* S := e.to_ring_hom.to_monoid_hom
/-- Reinterpret a ring equivalence as an `add_monoid` homomorphism. -/
abbreviation to_add_monoid_hom (e : R ≃+* S) : R →+ S := e.to_ring_hom.to_add_monoid_hom
/-- Interpret an equivalence `f : R ≃ S` as a ring equivalence `R ≃+* S`. -/
def of (e : R ≃ S) [is_semiring_hom e] : R ≃+* S :=
{ .. e, .. monoid_hom.of e, .. add_monoid_hom.of e }
instance (e : R ≃+* S) : is_semiring_hom e := e.to_ring_hom.is_semiring_hom
@[simp]
lemma to_ring_hom_apply_symm_to_ring_hom_apply {R S} [semiring R] [semiring S] (e : R ≃+* S) :
∀ (y : S), e.to_ring_hom (e.symm.to_ring_hom y) = y :=
e.to_equiv.apply_symm_apply
@[simp]
lemma symm_to_ring_hom_apply_to_ring_hom_apply {R S} [semiring R] [semiring S] (e : R ≃+* S) :
∀ (x : R), e.symm.to_ring_hom (e.to_ring_hom x) = x :=
equiv.symm_apply_apply (e.to_equiv)
end semiring_hom
end ring_equiv
namespace mul_equiv
/-- Gives an `is_semiring_hom` instance from a `mul_equiv` of semirings that preserves addition. -/
protected lemma to_semiring_hom {R : Type*} {S : Type*} [semiring R] [semiring S]
(h : R ≃* S) (H : ∀ x y : R, h (x + y) = h x + h y) : is_semiring_hom h :=
⟨add_equiv.map_zero $ add_equiv.mk' h.to_equiv H, h.map_one, H, h.5⟩
/-- Gives a `ring_equiv` from a `mul_equiv` preserving addition.-/
def to_ring_equiv {R : Type*} {S : Type*} [has_add R] [has_add S] [has_mul R] [has_mul S]
(h : R ≃* S) (H : ∀ x y : R, h (x + y) = h x + h y) : R ≃+* S :=
{..h.to_equiv, ..h, ..add_equiv.mk' h.to_equiv H }
end mul_equiv
namespace add_equiv
/-- Gives an `is_semiring_hom` instance from a `mul_equiv` of semirings that preserves addition. -/
protected lemma to_semiring_hom {R : Type*} {S : Type*} [semiring R] [semiring S]
(h : R ≃+ S) (H : ∀ x y : R, h (x * y) = h x * h y) : is_semiring_hom h :=
⟨h.map_zero, mul_equiv.map_one $ mul_equiv.mk' h.to_equiv H, h.5, H⟩
end add_equiv
namespace ring_equiv
section ring_hom
variables [ring R] [ring S]
/-- Interpret an equivalence `f : R ≃ S` as a ring equivalence `R ≃+* S`. -/
def of' (e : R ≃ S) [is_ring_hom e] : R ≃+* S :=
{ .. e, .. monoid_hom.of e, .. add_monoid_hom.of e }
instance (e : R ≃+* S) : is_ring_hom e := e.to_ring_hom.is_ring_hom
end ring_hom
/-- Two ring isomorphisms agree if they are defined by the
same underlying function. -/
@[ext] lemma ext {R S : Type*} [has_mul R] [has_add R] [has_mul S] [has_add S]
{f g : R ≃+* S} (h : ∀ x, f x = g x) : f = g :=
begin
have h₁ : f.to_equiv = g.to_equiv := equiv.ext h,
cases f, cases g, congr,
{ exact (funext h) },
{ exact congr_arg equiv.inv_fun h₁ }
end
/-- If two rings are isomorphic, and the second is an integral domain, then so is the first. -/
protected lemma is_integral_domain {A : Type*} (B : Type*) [ring A] [ring B]
(hB : is_integral_domain B) (e : A ≃+* B) : is_integral_domain A :=
{ mul_comm := λ x y, have e.symm (e x * e y) = e.symm (e y * e x), by rw hB.mul_comm, by simpa,
eq_zero_or_eq_zero_of_mul_eq_zero := λ x y hxy,
have e x * e y = 0, by rw [← e.map_mul, hxy, e.map_zero],
(hB.eq_zero_or_eq_zero_of_mul_eq_zero _ _ this).imp (λ hx, by simpa using congr_arg e.symm hx)
(λ hy, by simpa using congr_arg e.symm hy),
zero_ne_one := λ H, hB.zero_ne_one $ by rw [← e.map_zero, ← e.map_one, H] }
/-- If two rings are isomorphic, and the second is an integral domain, then so is the first. -/
protected def integral_domain {A : Type*} (B : Type*) [ring A] [integral_domain B]
(e : A ≃+* B) : integral_domain A :=
{ .. (‹_› : ring A), .. e.is_integral_domain B (integral_domain.to_is_integral_domain B) }
end ring_equiv
/-- The group of ring automorphisms. -/
@[reducible] def ring_aut (R : Type*) [has_mul R] [has_add R] := ring_equiv R R
namespace ring_aut
variables (R) [has_mul R] [has_add R]
/--
The group operation on automorphisms of a ring is defined by
λ g h, ring_equiv.trans h g.
This means that multiplication agrees with composition, (g*h)(x) = g (h x) .
-/
instance : group (ring_aut R) :=
by refine_struct
{ mul := λ g h, ring_equiv.trans h g,
one := ring_equiv.refl R,
inv := ring_equiv.symm };
intros; ext; try { refl }; apply equiv.left_inv
instance : inhabited (ring_aut R) := ⟨1⟩
/-- Monoid homomorphism from ring automorphisms to additive automorphisms. -/
def to_add_aut : ring_aut R →* add_aut R :=
by refine_struct { to_fun := ring_equiv.to_add_equiv }; intros; refl
/-- Monoid homomorphism from ring automorphisms to multiplicative automorphisms. -/
def to_mul_aut : ring_aut R →* mul_aut R :=
by refine_struct { to_fun := ring_equiv.to_mul_equiv }; intros; refl
/-- Monoid homomorphism from ring automorphisms to permutations. -/
def to_perm : ring_aut R →* equiv.perm R :=
by refine_struct { to_fun := ring_equiv.to_equiv }; intros; refl
end ring_aut
namespace equiv
variables (K : Type*) [division_ring K]
def units_equiv_ne_zero : units K ≃ {a : K | a ≠ 0} :=
⟨λ a, ⟨a.1, units.ne_zero _⟩, λ a, units.mk0 _ a.2, λ ⟨_, _, _, _⟩, units.ext rfl, λ ⟨_, _⟩, rfl⟩
variable {K}
@[simp]
lemma coe_units_equiv_ne_zero (a : units K) :
((units_equiv_ne_zero K a) : K) = a := rfl
end equiv
|
39517098e37d536be3d1f5ae0dc7430c926b0f7a | b7f22e51856f4989b970961f794f1c435f9b8f78 | /library/data/hlist.lean | 71543d8455fca2fa4e1272a974bea52c9ddc51b0 | [
"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 | 2,706 | lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
Heterogeneous lists
-/
import data.list logic.cast
open list
inductive hlist {A : Type} (B : A → Type) : list A → Type :=
| nil {} : hlist B []
| cons : ∀ {a : A}, B a → ∀ {l : list A}, hlist B l → hlist B (a::l)
namespace hlist
variables {A : Type} {B : A → Type}
definition head : Π {a l}, hlist B (a :: l) → B a
| a l (cons b h) := b
lemma head_cons : ∀ {a l} (b : B a) (h : hlist B l), head (cons b h) = b :=
by intros; reflexivity
definition tail : Π {a l}, hlist B (a :: l) → hlist B l
| a l (cons b h) := h
lemma tail_cons : ∀ {a l} (b : B a) (h : hlist B l), tail (cons b h) = h :=
by intros; reflexivity
lemma eta_cons : ∀ {a l} (h : hlist B (a::l)), h = cons (head h) (tail h) :=
begin intros, cases h, esimp end
lemma eta_nil : ∀ (h : hlist B []), h = nil :=
begin intros, cases h, esimp end
definition append : Π {l₁ l₂}, hlist B l₁ → hlist B l₂ → hlist B (l₁++l₂)
| ⌞[]⌟ l₂ nil h₂ := h₂
| ⌞a::l₁⌟ l₂ (cons b h₁) h₂ := cons b (append h₁ h₂)
lemma append_nil_left : ∀ {l} (h : hlist B l), append nil h = h :=
by intros; reflexivity
open eq.ops
lemma eq_rec_on_cons : ∀ {a₁ a₂ l₁ l₂} (b : B a₁) (h : hlist B l₁) (e : a₁::l₁ = a₂::l₂),
e ▹ cons b h = cons (head_eq_of_cons_eq e ▹ b) (tail_eq_of_cons_eq e ▹ h) :=
begin
intros, injection e with e₁ e₂, revert e, subst a₂, subst l₂, intro e, esimp
end
lemma append_nil_right : ∀ {l} (h : hlist B l), append h nil = (list.append_nil_right l)⁻¹ ▹ h
| [] nil := by esimp
| (a::l) (cons b h) :=
begin
unfold append, rewrite [append_nil_right h], xrewrite eq_rec_on_cons
end
lemma append_nil_right_heq {l} (h : hlist B l) : append h nil == h :=
by rewrite append_nil_right; apply eq_rec_heq
section get
variables [decA : decidable_eq A]
include decA
definition get {a : A} : ∀ {l : list A}, hlist B l → a ∈ l → B a
| [] nil e := absurd e !not_mem_nil
| (t::l) (cons b h) e :=
or.by_cases (eq_or_mem_of_mem_cons e)
(suppose a = t, by subst t; exact b)
(suppose a ∈ l, get h this)
end get
section map
variable {C : A → Type}
variable (f : Π ⦃a⦄, B a → C a)
definition map : ∀ {l}, hlist B l → hlist C l
| ⌞[]⌟ nil := nil
| ⌞a::l⌟ (cons b h) := cons (f b) (map h)
lemma map_nil : map f nil = nil :=
rfl
lemma map_cons : ∀ {a l} (b : B a) (h : hlist B l), map f (cons b h) = cons (f b) (map f h) :=
by intros; reflexivity
end map
end hlist
|
460f6bacf1e6b737248deb01a266120182d6eda1 | 82b86ba2ae0d5aed0f01f49c46db5afec0eb2bd7 | /tests/lean/run/letrecInProofs.lean | 066f8fa600e6b78b46766f15665bdd9171a5036e | [
"Apache-2.0"
] | permissive | banksonian/lean4 | 3a2e6b0f1eb63aa56ff95b8d07b2f851072d54dc | 78da6b3aa2840693eea354a41e89fc5b212a5011 | refs/heads/master | 1,673,703,624,165 | 1,605,123,551,000 | 1,605,123,551,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,727 | lean | import Lean
inductive Tree
| leaf : Tree
| node : Tree → Tree → Tree
abbrev notSubtree (x : Tree) (t : Tree) : Prop :=
Tree.ibelow (motive := fun z => x ≠ z) t
infix:50 "≮" => notSubtree
theorem Tree.acyclic (x t : Tree) : x = t → x ≮ t := by
let rec right (x s : Tree) (b : Tree) (h : x ≮ b) : node s x ≠ b ∧ node s x ≮ b := by
match b, h with
| leaf, h =>
apply And.intro _ trivial
intro h; injection h
| node l r, h =>
have ihl : x ≮ l → node s x ≠ l ∧ node s x ≮ l from right x s l
have ihr : x ≮ r → node s x ≠ r ∧ node s x ≮ r from right x s r
have hl : x ≠ l ∧ x ≮ l from h.1
have hr : x ≠ r ∧ x ≮ r from h.2.1
have ihl : node s x ≠ l ∧ node s x ≮ l from ihl hl.2
have ihr : node s x ≠ r ∧ node s x ≮ r from ihr hr.2
apply And.intro
focus
intro h
injection h with _ h
exact absurd h hr.1
done
focus
apply And.intro
apply ihl
apply And.intro _ trivial
apply ihr
let rec left (x t : Tree) (b : Tree) (h : x ≮ b) : node x t ≠ b ∧ node x t ≮ b := by
match b, h with
| leaf, h =>
apply And.intro _ trivial
intro h; injection h
| node l r, h =>
have ihl : x ≮ l → node x t ≠ l ∧ node x t ≮ l from left x t l
have ihr : x ≮ r → node x t ≠ r ∧ node x t ≮ r from left x t r
have hl : x ≠ l ∧ x ≮ l from h.1
have hr : x ≠ r ∧ x ≮ r from h.2.1
have ihl : node x t ≠ l ∧ node x t ≮ l from ihl hl.2
have ihr : node x t ≠ r ∧ node x t ≮ r from ihr hr.2
apply And.intro
focus
intro h
injection h with h _
exact absurd h hl.1
done
focus
apply And.intro
apply ihl
apply And.intro _ trivial
apply ihr
let rec aux : (x : Tree) → x ≮ x
| leaf => trivial
| node l r => by
have ih₁ : l ≮ l from aux l
have ih₂ : r ≮ r from aux r
show (node l r ≠ l ∧ node l r ≮ l) ∧ (node l r ≠ r ∧ node l r ≮ r) ∧ True
apply And.intro
focus
apply left
assumption
apply And.intro _ trivial
focus
apply right
assumption
intro h
subst h
apply aux
open Tree
theorem ex1 (x : Tree) : x ≠ node leaf (node x leaf) := by
intro h
exact absurd rfl $ Tree.acyclic _ _ h $.2.1.2.1.1
theorem ex2 (x : Tree) : x ≠ node x leaf := by
intro h
exact absurd rfl $ Tree.acyclic _ _ h $.1.1
theorem ex3 (x y : Tree) : x ≠ node y x := by
intro h
exact absurd rfl $ Tree.acyclic _ _ h $.2.1.1
|
13fda084411601c1cd96a957231a38cc719a57d2 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/ring_theory/polynomial/selmer.lean | f8ba5e77ea676df2a12c32686cb9d65cbd9e3a57 | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 3,441 | lean | /-
Copyright (c) 2022 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import data.polynomial.unit_trinomial
import tactic.linear_combination
/-!
# Irreducibility of Selmer Polynomials
This file proves irreducibility of the Selmer polynomials `X ^ n - X - 1`.
## Main results
- `polynomial.selmer_irreducible`: The Selmer polynomials `X ^ n - X - 1` are irreducible.
TODO: Show that the Selmer polynomials have full Galois group.
-/
namespace polynomial
open_locale polynomial
variables {n : ℕ}
lemma X_pow_sub_X_sub_one_irreducible_aux (z : ℂ) : ¬ (z ^ n = z + 1 ∧ z ^ n + z ^ 2 = 0) :=
begin
rintros ⟨h1, h2⟩,
replace h3 : z ^ 3 = 1,
{ linear_combination (1 - z - z ^ 2 - z ^ n) * h1 + (z ^ n - 2) * h2 }, -- thanks polyrith!
have key : z ^ n = 1 ∨ z ^ n = z ∨ z ^ n = z ^ 2,
{ rw [←nat.mod_add_div n 3, pow_add, pow_mul, h3, one_pow, mul_one],
have : n % 3 < 3 := nat.mod_lt n zero_lt_three,
interval_cases n % 3; simp only [h, pow_zero, pow_one, eq_self_iff_true, or_true, true_or] },
have z_ne_zero : z ≠ 0 :=
λ h, zero_ne_one ((zero_pow zero_lt_three).symm.trans (show (0 : ℂ) ^ 3 = 1, from h ▸ h3)),
rcases key with key | key | key,
{ exact z_ne_zero (by rwa [key, self_eq_add_left] at h1) },
{ exact one_ne_zero (by rwa [key, self_eq_add_right] at h1) },
{ exact z_ne_zero (pow_eq_zero (by rwa [key, add_self_eq_zero] at h2)) },
end
lemma X_pow_sub_X_sub_one_irreducible (hn1 : n ≠ 1) : irreducible (X ^ n - X - 1 : ℤ[X]) :=
begin
by_cases hn0 : n = 0,
{ rw [hn0, pow_zero, sub_sub, add_comm, ←sub_sub, sub_self, zero_sub],
exact associated.irreducible ⟨-1, mul_neg_one X⟩ irreducible_X },
have hn : 1 < n := nat.one_lt_iff_ne_zero_and_ne_one.mpr ⟨hn0, hn1⟩,
have hp : (X ^ n - X - 1 : ℤ[X]) = trinomial 0 1 n (-1) (-1) 1 :=
by simp only [trinomial, C_neg, C_1]; ring,
rw hp,
apply is_unit_trinomial.irreducible_of_coprime' ⟨0, 1, n, zero_lt_one, hn, -1, -1, 1, rfl⟩,
rintros z ⟨h1, h2⟩,
apply X_pow_sub_X_sub_one_irreducible_aux z,
rw [trinomial_mirror zero_lt_one hn (-1 : ℤˣ).ne_zero (1 : ℤˣ).ne_zero] at h2,
simp_rw [trinomial, aeval_add, aeval_mul, aeval_X_pow, aeval_C] at h1 h2,
simp_rw [units.coe_neg, units.coe_one, map_neg, map_one] at h1 h2,
replace h1 : z ^ n = z + 1 := by linear_combination h1,
replace h2 := mul_eq_zero_of_left h2 z,
rw [add_mul, add_mul, add_zero, mul_assoc (-1 : ℂ), ←pow_succ', nat.sub_add_cancel hn.le] at h2,
rw h1 at h2 ⊢,
exact ⟨rfl, by linear_combination -h2⟩,
end
lemma X_pow_sub_X_sub_one_irreducible_rat (hn1 : n ≠ 1) : irreducible (X ^ n - X - 1 : ℚ[X]) :=
begin
by_cases hn0 : n = 0,
{ rw [hn0, pow_zero, sub_sub, add_comm, ←sub_sub, sub_self, zero_sub],
exact associated.irreducible ⟨-1, mul_neg_one X⟩ irreducible_X },
have hp : (X ^ n - X - 1 : ℤ[X]) = trinomial 0 1 n (-1) (-1) 1 :=
by simp only [trinomial, C_neg, C_1]; ring,
have hn : 1 < n := nat.one_lt_iff_ne_zero_and_ne_one.mpr ⟨hn0, hn1⟩,
have h := (is_primitive.int.irreducible_iff_irreducible_map_cast _).mp
(X_pow_sub_X_sub_one_irreducible hn1),
{ rwa [polynomial.map_sub, polynomial.map_sub, polynomial.map_pow, polynomial.map_one,
polynomial.map_X] at h },
{ exact hp.symm ▸ (trinomial_monic zero_lt_one hn).is_primitive },
end
end polynomial
|
7ab62e68fb1c46af5223161c4c0038bed3412e13 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/decEq.lean | aa2ed2d1a6d88bc82fb8629be41d1c1d3d689330 | [
"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 | 457 | lean | inductive Vec (α : Type u) : Nat → Type u
| nil : Vec α 0
| cons : α → {n : Nat} → Vec α n → Vec α (n+1)
deriving DecidableEq
inductive Test (α : Type)
| mk₀
| mk₁ : (n : Nat) → (α × α) → List α → Vec α n → Test α
| mk₂ : Test α → α → Test α
deriving DecidableEq
def t1 [DecidableEq α] : DecidableEq (Vec α n) :=
inferInstance
def t2 [DecidableEq α] : DecidableEq (Test α) :=
inferInstance
|
e9c0208c749e638759ec6ff4031162200b41e325 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/algebra/euclidean_domain/basic.lean | 026e3911720ba5a1a847fbb306c712c409510a0d | [
"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 | 10,205 | lean | /-
Copyright (c) 2018 Louis Carlin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Louis Carlin, Mario Carneiro
-/
import algebra.euclidean_domain.defs
import algebra.ring.divisibility
import algebra.ring.regular
import algebra.group_with_zero.divisibility
import algebra.ring.basic
/-!
# Lemmas about Euclidean domains
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
## Main statements
* `gcd_eq_gcd_ab`: states Bézout's lemma for Euclidean domains.
-/
universe u
namespace euclidean_domain
variable {R : Type u}
variables [euclidean_domain R]
local infix ` ≺ `:50 := euclidean_domain.r
lemma mul_div_cancel_left {a : R} (b) (a0 : a ≠ 0) : a * b / a = b :=
eq.symm $ eq_of_sub_eq_zero $ classical.by_contradiction $ λ h,
begin
have := mul_left_not_lt a h,
rw [mul_sub, sub_eq_iff_eq_add'.2 (div_add_mod (a*b) a).symm] at this,
exact this (mod_lt _ a0)
end
lemma mul_div_cancel (a) {b : R} (b0 : b ≠ 0) : a * b / b = a :=
by { rw mul_comm, exact mul_div_cancel_left a b0 }
@[simp] lemma mod_eq_zero {a b : R} : a % b = 0 ↔ b ∣ a :=
⟨λ h, by { rw [← div_add_mod a b, h, add_zero], exact dvd_mul_right _ _ },
λ ⟨c, e⟩, begin
rw [e, ← add_left_cancel_iff, div_add_mod, add_zero],
haveI := classical.dec,
by_cases b0 : b = 0,
{ simp only [b0, zero_mul] },
{ rw [mul_div_cancel_left _ b0] }
end⟩
@[simp] lemma mod_self (a : R) : a % a = 0 :=
mod_eq_zero.2 dvd_rfl
lemma dvd_mod_iff {a b c : R} (h : c ∣ b) : c ∣ a % b ↔ c ∣ a :=
by rw [←dvd_add_right (h.mul_right _), div_add_mod]
@[simp] lemma mod_one (a : R) : a % 1 = 0 :=
mod_eq_zero.2 (one_dvd _)
@[simp] lemma zero_mod (b : R) : 0 % b = 0 :=
mod_eq_zero.2 (dvd_zero _)
@[simp, priority 900] lemma zero_div {a : R} : 0 / a = 0 :=
classical.by_cases
(λ a0 : a = 0, a0.symm ▸ div_zero 0)
(λ a0, by simpa only [zero_mul] using mul_div_cancel 0 a0)
@[simp, priority 900] lemma div_self {a : R} (a0 : a ≠ 0) : a / a = 1 :=
by simpa only [one_mul] using mul_div_cancel 1 a0
lemma eq_div_of_mul_eq_left {a b c : R} (hb : b ≠ 0) (h : a * b = c) : a = c / b :=
by rw [← h, mul_div_cancel _ hb]
lemma eq_div_of_mul_eq_right {a b c : R} (ha : a ≠ 0) (h : a * b = c) : b = c / a :=
by rw [← h, mul_div_cancel_left _ ha]
theorem mul_div_assoc (x : R) {y z : R} (h : z ∣ y) : x * y / z = x * (y / z) :=
begin
classical, by_cases hz : z = 0,
{ subst hz, rw [div_zero, div_zero, mul_zero] },
rcases h with ⟨p, rfl⟩,
rw [mul_div_cancel_left _ hz, mul_left_comm, mul_div_cancel_left _ hz]
end
protected lemma mul_div_cancel' {a b : R} (hb : b ≠ 0) (hab : b ∣ a) : b * (a / b) = a :=
by rw [←mul_div_assoc _ hab, mul_div_cancel_left _ hb]
@[simp, priority 900] -- This generalizes `int.div_one`, see note [simp-normal form]
lemma div_one (p : R) : p / 1 = p :=
(euclidean_domain.eq_div_of_mul_eq_left (one_ne_zero' R) (mul_one p)).symm
lemma div_dvd_of_dvd {p q : R} (hpq : q ∣ p) :
p / q ∣ p :=
begin
by_cases hq : q = 0,
{ rw [hq, zero_dvd_iff] at hpq,
rw hpq,
exact dvd_zero _ },
use q,
rw [mul_comm, ← euclidean_domain.mul_div_assoc _ hpq, mul_comm,
euclidean_domain.mul_div_cancel _ hq]
end
lemma dvd_div_of_mul_dvd {a b c : R} (h : a * b ∣ c) : b ∣ c / a :=
begin
rcases eq_or_ne a 0 with rfl | ha,
{ simp only [div_zero, dvd_zero] },
rcases h with ⟨d, rfl⟩,
refine ⟨d, _⟩,
rw [mul_assoc, mul_div_cancel_left _ ha]
end
section gcd
variable [decidable_eq R]
@[simp] theorem gcd_zero_right (a : R) : gcd a 0 = a :=
by { rw gcd, split_ifs; simp only [h, zero_mod, gcd_zero_left] }
theorem gcd_val (a b : R) : gcd a b = gcd (b % a) a :=
by { rw gcd, split_ifs; [simp only [h, mod_zero, gcd_zero_right], refl]}
theorem gcd_dvd (a b : R) : gcd a b ∣ a ∧ gcd a b ∣ b :=
gcd.induction a b
(λ b, by { rw gcd_zero_left, exact ⟨dvd_zero _, dvd_rfl⟩ })
(λ a b aneq ⟨IH₁, IH₂⟩, by { rw gcd_val,
exact ⟨IH₂, (dvd_mod_iff IH₂).1 IH₁⟩ })
theorem gcd_dvd_left (a b : R) : gcd a b ∣ a := (gcd_dvd a b).left
theorem gcd_dvd_right (a b : R) : gcd a b ∣ b := (gcd_dvd a b).right
protected theorem gcd_eq_zero_iff {a b : R} :
gcd a b = 0 ↔ a = 0 ∧ b = 0 :=
⟨λ h, by simpa [h] using gcd_dvd a b,
by { rintro ⟨rfl, rfl⟩, exact gcd_zero_right _ }⟩
theorem dvd_gcd {a b c : R} : c ∣ a → c ∣ b → c ∣ gcd a b :=
gcd.induction a b
(λ _ _ H, by simpa only [gcd_zero_left] using H)
(λ a b a0 IH ca cb, by { rw gcd_val,
exact IH ((dvd_mod_iff ca).2 cb) ca })
theorem gcd_eq_left {a b : R} : gcd a b = a ↔ a ∣ b :=
⟨λ h, by {rw ← h, apply gcd_dvd_right },
λ h, by rw [gcd_val, mod_eq_zero.2 h, gcd_zero_left]⟩
@[simp] theorem gcd_one_left (a : R) : gcd 1 a = 1 :=
gcd_eq_left.2 (one_dvd _)
@[simp] theorem gcd_self (a : R) : gcd a a = a :=
gcd_eq_left.2 dvd_rfl
@[simp] theorem xgcd_aux_fst (x y : R) : ∀ s t s' t',
(xgcd_aux x s t y s' t').1 = gcd x y :=
gcd.induction x y (by { intros, rw [xgcd_zero_left, gcd_zero_left] })
(λ x y h IH s t s' t', by { simp only [xgcd_aux_rec h, if_neg h, IH], rw ← gcd_val })
theorem xgcd_aux_val (x y : R) : xgcd_aux x 1 0 y 0 1 = (gcd x y, xgcd x y) :=
by rw [xgcd, ← xgcd_aux_fst x y 1 0 0 1, prod.mk.eta]
private def P (a b : R) : R × R × R → Prop | (r, s, t) := (r : R) = a * s + b * t
theorem xgcd_aux_P (a b : R) {r r' : R} : ∀ {s t s' t'}, P a b (r, s, t) →
P a b (r', s', t') → P a b (xgcd_aux r s t r' s' t') :=
gcd.induction r r' (by { intros, simpa only [xgcd_zero_left] }) $ λ x y h IH s t s' t' p p', begin
rw [xgcd_aux_rec h], refine IH _ p, unfold P at p p' ⊢,
rw [mul_sub, mul_sub, add_sub, sub_add_eq_add_sub, ← p', sub_sub,
mul_comm _ s, ← mul_assoc, mul_comm _ t, ← mul_assoc, ← add_mul, ← p,
mod_eq_sub_mul_div]
end
/-- An explicit version of **Bézout's lemma** for Euclidean domains. -/
theorem gcd_eq_gcd_ab (a b : R) : (gcd a b : R) = a * gcd_a a b + b * gcd_b a b :=
by { have := @xgcd_aux_P _ _ _ a b a b 1 0 0 1
(by rw [P, mul_one, mul_zero, add_zero]) (by rw [P, mul_one, mul_zero, zero_add]),
rwa [xgcd_aux_val, xgcd_val] at this }
@[priority 70] -- see Note [lower instance priority]
instance (R : Type*) [e : euclidean_domain R] : no_zero_divisors R :=
by { haveI := classical.dec_eq R, exact
{ eq_zero_or_eq_zero_of_mul_eq_zero :=
λ a b h, (or_iff_not_and_not.2 $ λ h0,
h0.1 $ by rw [← mul_div_cancel a h0.2, h, zero_div]) }}
@[priority 70] -- see Note [lower instance priority]
instance (R : Type*) [e : euclidean_domain R] : is_domain R :=
{ .. e, .. no_zero_divisors.to_is_domain R }
end gcd
section lcm
variables [decidable_eq R]
theorem dvd_lcm_left (x y : R) : x ∣ lcm x y :=
classical.by_cases
(assume hxy : gcd x y = 0, by { rw [lcm, hxy, div_zero], exact dvd_zero _ })
(λ hxy, let ⟨z, hz⟩ := (gcd_dvd x y).2 in ⟨z, eq.symm $ eq_div_of_mul_eq_left hxy $
by rw [mul_right_comm, mul_assoc, ← hz]⟩)
theorem dvd_lcm_right (x y : R) : y ∣ lcm x y :=
classical.by_cases
(assume hxy : gcd x y = 0, by { rw [lcm, hxy, div_zero], exact dvd_zero _ })
(λ hxy, let ⟨z, hz⟩ := (gcd_dvd x y).1 in ⟨z, eq.symm $ eq_div_of_mul_eq_right hxy $
by rw [← mul_assoc, mul_right_comm, ← hz]⟩)
theorem lcm_dvd {x y z : R} (hxz : x ∣ z) (hyz : y ∣ z) : lcm x y ∣ z :=
begin
rw lcm, by_cases hxy : gcd x y = 0,
{ rw [hxy, div_zero], rw euclidean_domain.gcd_eq_zero_iff at hxy, rwa hxy.1 at hxz },
rcases gcd_dvd x y with ⟨⟨r, hr⟩, ⟨s, hs⟩⟩,
suffices : x * y ∣ z * gcd x y,
{ cases this with p hp, use p,
generalize_hyp : gcd x y = g at hxy hs hp ⊢, subst hs,
rw [mul_left_comm, mul_div_cancel_left _ hxy, ← mul_left_inj' hxy, hp],
rw [← mul_assoc], simp only [mul_right_comm] },
rw [gcd_eq_gcd_ab, mul_add], apply dvd_add,
{ rw mul_left_comm, exact mul_dvd_mul_left _ (hyz.mul_right _) },
{ rw [mul_left_comm, mul_comm], exact mul_dvd_mul_left _ (hxz.mul_right _) }
end
@[simp] lemma lcm_dvd_iff {x y z : R} : lcm x y ∣ z ↔ x ∣ z ∧ y ∣ z :=
⟨λ hz, ⟨(dvd_lcm_left _ _).trans hz, (dvd_lcm_right _ _).trans hz⟩,
λ ⟨hxz, hyz⟩, lcm_dvd hxz hyz⟩
@[simp] lemma lcm_zero_left (x : R) : lcm 0 x = 0 :=
by rw [lcm, zero_mul, zero_div]
@[simp] lemma lcm_zero_right (x : R) : lcm x 0 = 0 :=
by rw [lcm, mul_zero, zero_div]
@[simp] lemma lcm_eq_zero_iff {x y : R} : lcm x y = 0 ↔ x = 0 ∨ y = 0 :=
begin
split,
{ intro hxy, rw [lcm, mul_div_assoc _ (gcd_dvd_right _ _), mul_eq_zero] at hxy,
apply or_of_or_of_imp_right hxy, intro hy,
by_cases hgxy : gcd x y = 0,
{ rw euclidean_domain.gcd_eq_zero_iff at hgxy, exact hgxy.2 },
{ rcases gcd_dvd x y with ⟨⟨r, hr⟩, ⟨s, hs⟩⟩,
generalize_hyp : gcd x y = g at hr hs hy hgxy ⊢, subst hs,
rw [mul_div_cancel_left _ hgxy] at hy, rw [hy, mul_zero] } },
rintro (hx | hy),
{ rw [hx, lcm_zero_left] },
{ rw [hy, lcm_zero_right] }
end
@[simp] lemma gcd_mul_lcm (x y : R) : gcd x y * lcm x y = x * y :=
begin
rw lcm, by_cases h : gcd x y = 0,
{ rw [h, zero_mul], rw euclidean_domain.gcd_eq_zero_iff at h, rw [h.1, zero_mul] },
rcases gcd_dvd x y with ⟨⟨r, hr⟩, ⟨s, hs⟩⟩,
generalize_hyp : gcd x y = g at h hr ⊢, subst hr,
rw [mul_assoc, mul_div_cancel_left _ h]
end
end lcm
section div
lemma mul_div_mul_cancel {a b c : R} (ha : a ≠ 0) (hcb : c ∣ b) :
a * b / (a * c) = b / c :=
begin
by_cases hc : c = 0, { simp [hc] },
refine eq_div_of_mul_eq_right hc (mul_left_cancel₀ ha _),
rw [← mul_assoc, ← mul_div_assoc _ (mul_dvd_mul_left a hcb),
mul_div_cancel_left _ (mul_ne_zero ha hc)]
end
lemma mul_div_mul_comm_of_dvd_dvd {a b c d : R} (hac : c ∣ a) (hbd : d ∣ b) :
a * b / (c * d) = a / c * (b / d) :=
begin
rcases eq_or_ne c 0 with rfl | hc0, { simp },
rcases eq_or_ne d 0 with rfl | hd0, { simp },
obtain ⟨k1, rfl⟩ := hac,
obtain ⟨k2, rfl⟩ := hbd,
rw [mul_div_cancel_left _ hc0, mul_div_cancel_left _ hd0, mul_mul_mul_comm,
mul_div_cancel_left _ (mul_ne_zero hc0 hd0)],
end
end div
end euclidean_domain
|
346ff280e3471f451e244f5f16ae2dad15cbf559 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/data/bool.lean | 8448a50c3fd7dcad02b5f0c674db330662d195e6 | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,977 | lean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad
-/
/-!
# booleans
This file proves various trivial lemmas about booleans and their
relation to decidable propositions.
## Notations
This file introduces the notation `!b` for `bnot b`, the boolean "not".
## Tags
bool, boolean, De Morgan
-/
prefix `!`:90 := bnot
namespace bool
-- TODO: duplicate of a lemma in core
theorem coe_sort_tt : coe_sort.{1 1} tt = true := coe_sort_tt
-- TODO: duplicate of a lemma in core
theorem coe_sort_ff : coe_sort.{1 1} ff = false := coe_sort_ff
-- TODO: duplicate of a lemma in core
theorem to_bool_true {h} : @to_bool true h = tt :=
to_bool_true_eq_tt h
-- TODO: duplicate of a lemma in core
theorem to_bool_false {h} : @to_bool false h = ff :=
to_bool_false_eq_ff h
@[simp] theorem to_bool_coe (b:bool) {h} : @to_bool b h = b :=
(show _ = to_bool b, by congr).trans (by cases b; refl)
theorem coe_to_bool (p : Prop) [decidable p] : to_bool p ↔ p := to_bool_iff _
@[simp] lemma of_to_bool_iff {p : Prop} [decidable p] : to_bool p ↔ p :=
⟨of_to_bool_true, _root_.to_bool_true⟩
@[simp] lemma tt_eq_to_bool_iff {p : Prop} [decidable p] : tt = to_bool p ↔ p :=
eq_comm.trans of_to_bool_iff
@[simp] lemma ff_eq_to_bool_iff {p : Prop} [decidable p] : ff = to_bool p ↔ ¬ p :=
eq_comm.trans (to_bool_ff_iff _)
@[simp] theorem to_bool_not (p : Prop) [decidable p] : to_bool (¬ p) = bnot (to_bool p) :=
by by_cases p; simp *
@[simp] theorem to_bool_and (p q : Prop) [decidable p] [decidable q] :
to_bool (p ∧ q) = p && q :=
by by_cases p; by_cases q; simp *
@[simp] theorem to_bool_or (p q : Prop) [decidable p] [decidable q] :
to_bool (p ∨ q) = p || q :=
by by_cases p; by_cases q; simp *
@[simp] theorem to_bool_eq {p q : Prop} [decidable p] [decidable q] :
to_bool p = to_bool q ↔ (p ↔ q) :=
⟨λ h, (coe_to_bool p).symm.trans $ by simp [h], to_bool_congr⟩
lemma not_ff : ¬ ff := by simp
@[simp] theorem default_bool : default bool = ff := rfl
theorem dichotomy (b : bool) : b = ff ∨ b = tt :=
by cases b; simp
@[simp] theorem forall_bool {p : bool → Prop} : (∀ b, p b) ↔ p ff ∧ p tt :=
⟨λ h, by simp [h], λ ⟨h₁, h₂⟩ b, by cases b; assumption⟩
@[simp] theorem exists_bool {p : bool → Prop} : (∃ b, p b) ↔ p ff ∨ p tt :=
⟨λ ⟨b, h⟩, by cases b; [exact or.inl h, exact or.inr h],
λ h, by cases h; exact ⟨_, h⟩⟩
/-- If `p b` is decidable for all `b : bool`, then `∀ b, p b` is decidable -/
instance decidable_forall_bool {p : bool → Prop} [∀ b, decidable (p b)] : decidable (∀ b, p b) :=
decidable_of_decidable_of_iff and.decidable forall_bool.symm
/-- If `p b` is decidable for all `b : bool`, then `∃ b, p b` is decidable -/
instance decidable_exists_bool {p : bool → Prop} [∀ b, decidable (p b)] : decidable (∃ b, p b) :=
decidable_of_decidable_of_iff or.decidable exists_bool.symm
@[simp] theorem cond_ff {α} (t e : α) : cond ff t e = e := rfl
@[simp] theorem cond_tt {α} (t e : α) : cond tt t e = t := rfl
@[simp] theorem cond_to_bool {α} (p : Prop) [decidable p] (t e : α) :
cond (to_bool p) t e = if p then t else e :=
by by_cases p; simp *
@[simp] theorem cond_bnot {α} (b : bool) (t e : α) : cond (!b) t e = cond b e t :=
by cases b; refl
theorem coe_bool_iff : ∀ {a b : bool}, (a ↔ b) ↔ a = b := dec_trivial
theorem eq_tt_of_ne_ff : ∀ {a : bool}, a ≠ ff → a = tt := dec_trivial
theorem eq_ff_of_ne_tt : ∀ {a : bool}, a ≠ tt → a = ff := dec_trivial
theorem bor_comm : ∀ a b, a || b = b || a := dec_trivial
@[simp] theorem bor_assoc : ∀ a b c, (a || b) || c = a || (b || c) := dec_trivial
theorem bor_left_comm : ∀ a b c, a || (b || c) = b || (a || c) := dec_trivial
theorem bor_inl {a b : bool} (H : a) : a || b :=
by simp [H]
theorem bor_inr {a b : bool} (H : b) : a || b :=
by simp [H]
theorem band_comm : ∀ a b, a && b = b && a := dec_trivial
@[simp] theorem band_assoc : ∀ a b c, (a && b) && c = a && (b && c) := dec_trivial
theorem band_left_comm : ∀ a b c, a && (b && c) = b && (a && c) := dec_trivial
theorem band_elim_left : ∀ {a b : bool}, a && b → a := dec_trivial
theorem band_intro : ∀ {a b : bool}, a → b → a && b := dec_trivial
theorem band_elim_right : ∀ {a b : bool}, a && b → b := dec_trivial
@[simp] theorem bnot_false : bnot ff = tt := rfl
@[simp] theorem bnot_true : bnot tt = ff := rfl
@[simp] theorem bnot_iff_not : ∀ {b : bool}, !b ↔ ¬b := dec_trivial
theorem eq_tt_of_bnot_eq_ff : ∀ {a : bool}, bnot a = ff → a = tt := dec_trivial
theorem eq_ff_of_bnot_eq_tt : ∀ {a : bool}, bnot a = tt → a = ff := dec_trivial
theorem bxor_comm : ∀ a b, bxor a b = bxor b a := dec_trivial
@[simp] theorem bxor_assoc : ∀ a b c, bxor (bxor a b) c = bxor a (bxor b c) := dec_trivial
theorem bxor_left_comm : ∀ a b c, bxor a (bxor b c) = bxor b (bxor a c) := dec_trivial
@[simp] theorem bxor_bnot_left : ∀ a, bxor (!a) a = tt := dec_trivial
@[simp] theorem bxor_bnot_right : ∀ a, bxor a (!a) = tt := dec_trivial
@[simp] theorem bxor_bnot_bnot : ∀ a b, bxor (!a) (!b) = bxor a b := dec_trivial
@[simp] theorem bxor_ff_left : ∀ a, bxor ff a = a := dec_trivial
@[simp] theorem bxor_ff_right : ∀ a, bxor a ff = a := dec_trivial
lemma bxor_iff_ne : ∀ {x y : bool}, bxor x y = tt ↔ x ≠ y := dec_trivial
/-! ### De Morgan's laws for booleans-/
@[simp] lemma bnot_band : ∀ (a b : bool), !(a && b) = !a || !b := dec_trivial
@[simp] lemma bnot_bor : ∀ (a b : bool), !(a || b) = !a && !b := dec_trivial
lemma bnot_inj : ∀ {a b : bool}, !a = !b → a = b := dec_trivial
instance : linear_order bool :=
{ le := λ a b, a = ff ∨ b = tt,
le_refl := dec_trivial,
le_trans := dec_trivial,
le_antisymm := dec_trivial,
le_total := dec_trivial,
decidable_le := infer_instance,
decidable_eq := infer_instance,
decidable_lt := infer_instance,
max := bor,
max_def := by { funext x y, revert x y, exact dec_trivial },
min := band,
min_def := by { funext x y, revert x y, exact dec_trivial } }
@[simp] lemma ff_le {x : bool} : ff ≤ x := or.intro_left _ rfl
@[simp] lemma le_tt {x : bool} : x ≤ tt := or.intro_right _ rfl
lemma lt_iff : ∀ {x y : bool}, x < y ↔ x = ff ∧ y = tt := dec_trivial
@[simp] lemma ff_lt_tt : ff < tt := lt_iff.2 ⟨rfl, rfl⟩
lemma le_iff_imp : ∀ {x y : bool}, x ≤ y ↔ (x → y) := dec_trivial
lemma band_le_left : ∀ x y : bool, x && y ≤ x := dec_trivial
lemma band_le_right : ∀ x y : bool, x && y ≤ y := dec_trivial
lemma le_band : ∀ {x y z : bool}, x ≤ y → x ≤ z → x ≤ y && z := dec_trivial
lemma left_le_bor : ∀ x y : bool, x ≤ x || y := dec_trivial
lemma right_le_bor : ∀ x y : bool, y ≤ x || y := dec_trivial
lemma bor_le : ∀ {x y z}, x ≤ z → y ≤ z → x || y ≤ z := dec_trivial
/-- convert a `bool` to a `ℕ`, `false -> 0`, `true -> 1` -/
def to_nat (b : bool) : ℕ :=
cond b 1 0
/-- convert a `ℕ` to a `bool`, `0 -> false`, everything else -> `true` -/
def of_nat (n : ℕ) : bool :=
to_bool (n ≠ 0)
lemma of_nat_le_of_nat {n m : ℕ} (h : n ≤ m) : of_nat n ≤ of_nat m :=
begin
simp [of_nat];
cases nat.decidable_eq n 0;
cases nat.decidable_eq m 0;
simp only [to_bool],
{ subst m, have h := le_antisymm h (nat.zero_le _),
contradiction },
{ left, refl }
end
lemma to_nat_le_to_nat {b₀ b₁ : bool} (h : b₀ ≤ b₁) : to_nat b₀ ≤ to_nat b₁ :=
by cases h; subst h; [cases b₁, cases b₀]; simp [to_nat,nat.zero_le]
lemma of_nat_to_nat (b : bool) : of_nat (to_nat b) = b :=
by cases b; simp only [of_nat,to_nat]; exact dec_trivial
@[simp] lemma injective_iff {α : Sort*} {f : bool → α} : function.injective f ↔ f ff ≠ f tt :=
⟨λ Hinj Heq, ff_ne_tt (Hinj Heq),
λ H x y hxy, by { cases x; cases y, exacts [rfl, (H hxy).elim, (H hxy.symm).elim, rfl] }⟩
end bool
|
aed0122f6f1bfeb6eae24e62fc6dab9892caa915 | 94096349332b0a0e223a22a3917c8f253cd39235 | /src/game/world1/level4.lean | 159eecbe7f1c119ff11649f7702dd475e83b1fe2 | [] | no_license | robertylewis/natural_number_game | 26156e10ef7b45248549915cc4d1ab3d8c3afc85 | b210c05cd627242f791db1ee3f365ee7829674c9 | refs/heads/master | 1,598,964,725,038 | 1,572,602,236,000 | 1,572,602,236,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,144 | lean | import mynat.add -- definition of addition
namespace mynat -- hide
/-
# World 1 : Tutorial world
## Level 4: addition
We have a new import -- the definition of addition.
Peano defined addition `a + b` by induction on `b`, or,
more precisely, by *recursion* on `b`. He first explained how to add 0 to a number:
this is the base case.
* `add_zero (a : mynat) : a + 0 = a`
We will call this theorem `add_zero`. **Note the name of this theorem**.
Mathematicians sometimes call it "Lemma 2.1" or "Hypothesis P6" or something. But
computer scientists call it `add_zero` because it tells you
what the answer to "$x$ add zero" is. It's a *much* better name than "Lemma 2.1".
Even better, we can use the rewrite tactic with `add_zero`.
If you ever see `x + 0` in your goal, `rw add_zero` should simplify it to `x`.
This is because `add_zero` is a proof that `x + 0 = x` (more precisely,
`add_zero x` is a proof that `x + 0 = x` but Lean can figure out the `x` from the context).
Now here's the inductive step. If you know how to add `d` to `a`, then
Peano tells you how to add `succ(d)` to `a`. It looks like this:
* `add_succ (a d : mynat) : a + succ(d) = succ (a + d)`
What's going on here is that we assume `a + d` is already
defined, and we define `a + succ(d)` to be the number after it.
**Note the name of this theorem too** -- `add_succ` tells you
how to add a successor to something. If you ever see `... + succ ...`
in your goal, you should be able to use `rw add_succ,` to make
progress. Here is a simple example where we shall see both. Let's prove
that $x$ add the number after $0$ is the number after $x$.
Delete `sorry` (don't forget you can widen this box if you can't see the sorry).
Observe that the goal mentions `... + succ ...`. So type
`rw add_succ,`
and hit enter; see the goal change. **Don't forget the commma**.
Do you see that the goal now mentions ` ... + 0 ...`? So type
`rw add_zero,`
and then observe that you can close the goal with
`refl,`
and you're done. You might want to review this proof now; at
three lines long it is our current record. Click on a line in the proof
and then use the arrow keys to move your cursor
around (try going up and down first), and you can see what
Lean is thinking on each line of the proof. The goal changes
just before each comma. That's why commas are important.
FAQ. Question: why has the top left hand box gone blank?
Answer: Maybe you tried a tactic which didn't work. Or maybe you're
in the middle of typing a tactic. Try deleting up to the last
comma, or adding a new comma. Look at the
error message. What line is the first error on? Perhaps
Lean thinks you're in the middle of writing a tactic that you
think you finished. Did you perhaps forget a comma somewhere?
When you're happy, let's move onto world 2, addition world, and
learn about proof by induction. Click on "next world" in the top right.
-/
/- Lemma : no-side-bar
For all natural numbers $a$, we have
$$a + \operatorname{succ}(0) = \operatorname{succ}(a)$.
-/
lemma add_succ_zero (a : mynat) : a + succ(0) = succ(a) :=
begin [less_leaky]
rw add_succ,
rw add_zero,
refl,
end
end mynat |
767ffcbe6463b0058ea343205c7dcdbf4aa9a42a | ce6917c5bacabee346655160b74a307b4a5ab620 | /src/ch3/ex0402.lean | 1f683c0f132ec6af306d82c54d35497117db43d3 | [] | no_license | Ailrun/Theorem_Proving_in_Lean | ae6a23f3c54d62d401314d6a771e8ff8b4132db2 | 2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68 | refs/heads/master | 1,609,838,270,467 | 1,586,846,743,000 | 1,586,846,743,000 | 240,967,761 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 158 | lean | variables p q : Prop
example (h : p ∧ q) : q ∧ p :=
have hp : p, from and.left h,
suffices hq : q, from and.intro hq hp,
show q, from and.right h
|
1d342e52a3e4574d4a746c3f26bddaf3ef0b3712 | 88fb7558b0636ec6b181f2a548ac11ad3919f8a5 | /library/init/data/nat/lemmas.lean | 61982643a7895c717ea920a6e8cf5edf3ad06a22 | [
"Apache-2.0"
] | permissive | moritayasuaki/lean | 9f666c323cb6fa1f31ac597d777914aed41e3b7a | ae96ebf6ee953088c235ff7ae0e8c95066ba8001 | refs/heads/master | 1,611,135,440,814 | 1,493,852,869,000 | 1,493,852,869,000 | 90,269,903 | 0 | 0 | null | 1,493,906,291,000 | 1,493,906,291,000 | null | UTF-8 | Lean | false | false | 36,916 | 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.data.nat.div init.data.nat.pow init.meta init.algebra.functions
namespace nat
attribute [pre_smt] nat_zero_eq_zero
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
protected lemma add_zero : ∀ n : ℕ, n + 0 = n :=
λ n, rfl
lemma add_one_eq_succ : ∀ n : ℕ, n + 1 = succ n :=
λ n, rfl
lemma succ_eq_add_one : ∀ n : ℕ, succ n = n + 1 :=
λ 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 simp [nat.zero_add] {contextual := tt}
| (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
instance : zero_ne_one_class ℕ :=
{ zero := 0, one := 1, zero_ne_one := nat.zero_ne_one }
lemma eq_zero_of_add_eq_zero_right : ∀ {n m : ℕ}, n + m = 0 → n = 0
| 0 m := by 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)
@[simp]
lemma pred_zero : pred 0 = 0 :=
rfl
@[simp]
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_or_equal.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_or_equal.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_or_equal.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_or_equal.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_or_equal.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_or_equal, @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 : Sort 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 : Sort 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 ._ (less_than_or_equal.refl ._) := ⟨0, rfl⟩
| n ._ (@less_than_or_equal.step ._ 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 le_of_add_le_add_right {k n m : ℕ} : n + k ≤ m + k → n ≤ m :=
begin
rw [nat.add_comm _ k,nat.add_comm _ k],
apply nat.le_of_add_le_add_left
end
protected lemma add_le_add_iff_le_right (k n m : ℕ) : n + k ≤ m + k ↔ n ≤ m :=
⟨ nat.le_of_add_le_add_right , take h, nat.add_le_add_right h _ ⟩
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)
protected theorem sub_le_sub_right {n m : ℕ} (h : n ≤ m) : ∀ k, n - k ≤ m - k
| 0 := h
| (succ z) := pred_le_pred (sub_le_sub_right z)
/- 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
instance : distrib nat := by apply_instance
instance : semiring nat := by apply_instance
instance : ordered_semiring nat := by apply_instance
/- subtraction -/
@[simp]
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]
/- TODO(Leo): remove the following ematch annotations as soon as we have
arithmetic theory in the smt_stactic -/
@[ematch_lhs]
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]
@[ematch_lhs]
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]
@[ematch_lhs]
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]
@[ematch_lhs]
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 le_of_le_of_sub_le_sub_right {n m k : ℕ}
(h₀ : k ≤ m)
(h₁ : n - k ≤ m - k)
: n ≤ m :=
begin
revert k m,
induction n with n ; intros k m h₀ h₁,
{ apply zero_le },
{ cases k with k,
{ apply h₁ },
cases m with m,
{ cases not_succ_le_zero _ h₀ },
{ simp [succ_sub_succ] at h₁,
apply succ_le_succ,
apply ih_1 _ h₁,
apply le_of_succ_le_succ h₀ }, }
end
protected theorem sub_le_sub_right_iff (n m k : ℕ)
(h : k ≤ m)
: n - k ≤ m - k ↔ n ≤ m :=
⟨ le_of_le_of_sub_le_sub_right h , assume h, nat.sub_le_sub_right h k ⟩
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]
theorem add_le_to_le_sub (x : ℕ) {y k : ℕ}
(h : k ≤ y)
: x + k ≤ y ↔ x ≤ y - k :=
by rw [-nat.add_sub_cancel x k,nat.sub_le_sub_right_iff _ _ _ h,nat.add_sub_cancel]
lemma sub_lt_of_pos_le (a b : ℕ) (h₀ : 0 < a) (h₁ : a ≤ b)
: b - a < b :=
begin
apply sub_lt _ h₀,
apply lt_of_lt_of_le h₀ h₁
end
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])
protected theorem le_of_sub_eq_zero : ∀{n m : ℕ}, n - m = 0 → n ≤ m
| n 0 H := begin rw [nat.sub_zero] at H, simp [H] end
| 0 (m+1) H := zero_le _
| (n+1) (m+1) H := add_le_add_right
(le_of_sub_eq_zero begin simp [nat.add_sub_add_right] at H, exact H end) _
protected theorem sub_eq_zero_iff_le {n m : ℕ} : n - m = 0 ↔ n ≤ m :=
⟨nat.le_of_sub_eq_zero, nat.sub_eq_zero_of_le⟩
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])
protected lemma sub_eq_iff_eq_add {a b c : ℕ} (ab : b ≤ a) : a - b = c ↔ a = c + b :=
⟨take c_eq, begin rw [c_eq.symm, nat.sub_add_cancel ab] end,
take a_eq, begin rw [a_eq, nat.add_sub_cancel] end⟩
protected lemma lt_of_sub_eq_succ {m n l : ℕ} (H : m - n = nat.succ l) : n < m :=
lt_of_not_ge
(take (H' : n ≥ m), begin simp [nat.sub_eq_zero_of_le H'] at H, contradiction end)
@[simp] lemma min_zero_left (a : ℕ) : min 0 a = 0 :=
min_eq_left (zero_le a)
@[simp] lemma min_zero_right (a : ℕ) : min a 0 = 0 :=
min_eq_right (zero_le a)
theorem zero_min (a : ℕ) : min 0 a = 0 :=
min_zero_left a
theorem min_zero (a : ℕ) : min a 0 = 0 :=
min_zero_right 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]
@[simp]
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)]
lemma pred_inj : ∀ {a b : nat}, a > 0 → b > 0 → nat.pred a = nat.pred b → a = b
| (succ a) (succ b) ha hb h := have a = b, from h, by rw this
| (succ a) 0 ha hb h := absurd hb (lt_irrefl _)
| 0 (succ b) ha hb h := absurd ha (lt_irrefl _)
| 0 0 ha hb h := rfl
/- TODO(Leo): sub + inequalities -/
protected def {u} strong_rec_on {p : nat → Sort u} (n : nat) (h : ∀ n, (∀ m, m < n → p m) → p n) : p n :=
suffices ∀ n m, m < n → p m, from this (succ n) n (lt_succ_self _),
begin
intros n, induction n with n ih,
{intros m h₁, exact absurd h₁ (not_lt_zero _)},
{intros m h₁,
apply or.by_cases (lt_or_eq_of_le (le_of_lt_succ h₁)),
{intros, apply ih, assumption},
{intros, subst m, apply h _ ih}}
end
protected lemma strong_induction_on {p : nat → Prop} (n : nat) (h : ∀ n, (∀ m, m < n → p m) → p n) : p n :=
nat.strong_rec_on n h
protected lemma case_strong_induction_on {p : nat → Prop} (a : nat)
(hz : p 0)
(hi : ∀ n, (∀ m, m ≤ n → p m) → p (succ n)) : p a :=
nat.strong_induction_on a $ λ n,
match n with
| 0 := λ _, hz
| (n+1) := λ h₁, hi n (λ m h₂, h₁ _ (lt_succ_of_le h₂))
end
/- mod -/
lemma mod_def (x y : nat) : x % y = if 0 < y ∧ y ≤ x then (x - y) % y else x :=
by note h := mod_def_aux x y; rwa [dif_eq_if] at h
lemma mod_zero (a : nat) : a % 0 = a :=
begin
rw mod_def,
assert h : ¬ (0 < 0 ∧ 0 ≤ a),
simp [lt_irrefl],
simp [if_neg, h]
end
lemma mod_eq_of_lt {a b : nat} (h : a < b) : a % b = a :=
begin
rw mod_def,
assert h' : ¬(0 < b ∧ b ≤ a),
simp [not_le_of_gt h],
simp [if_neg, h']
end
lemma zero_mod (b : nat) : 0 % b = 0 :=
begin
rw mod_def,
assert h : ¬(0 < b ∧ b ≤ 0),
{intro hn, cases hn with l r, exact absurd (lt_of_lt_of_le l r) (lt_irrefl 0)},
simp [if_neg, h]
end
lemma mod_eq_sub_mod {a b : nat} (h₁ : b > 0) (h₂ : a ≥ b) : a % b = (a - b) % b :=
by rw [mod_def, if_pos (and.intro h₁ h₂)]
lemma mod_lt (x : nat) {y : nat} (h : y > 0) : x % y < y :=
begin
induction x using nat.case_strong_induction_on with x ih,
{rw zero_mod, assumption},
{apply or.elim (decidable.em (succ x < y)),
{intro h₁, rwa [mod_eq_of_lt h₁]},
{intro h₁,
assert h₁ : succ x % y = (succ x - y) % y, {exact mod_eq_sub_mod h (le_of_not_gt h₁)},
assert this : succ x - y ≤ x, {exact le_of_lt_succ (sub_lt (succ_pos x) h)},
assert h₂ : (succ x - y) % y < y, {exact ih _ this},
rwa -h₁ at h₂}}
end
lemma eq_zero_of_le_zero : ∀ {n : nat}, n ≤ 0 → n = 0
| 0 h := rfl
| (n+1) h := absurd (zero_lt_succ n) (not_lt_of_ge h)
lemma mod_one (n : ℕ) : n % 1 = 0 :=
have n % 1 < 1, from (mod_lt n) (succ_pos 0),
eq_zero_of_le_zero (le_of_lt_succ this)
lemma mod_two_eq_zero_or_one (n : ℕ)
: n % 2 = 0 ∨ n % 2 = 1 :=
begin
assert h : ((n % 2 < 1) ∨ (n % 2 = 1)),
{ apply lt_or_eq_of_le,
apply nat.le_of_succ_le_succ,
apply @nat.mod_lt n 2 (nat.le_succ _) },
cases h with h h,
{ left,
apply nat.le_antisymm ,
{ apply nat.le_of_succ_le_succ h },
{ apply nat.zero_le } },
{ right,
apply h }
end
lemma cond_to_bool_mod_two (x : ℕ) [d : decidable (x % 2 = 1)]
: cond (@to_bool (x % 2 = 1) d) 1 0 = x % 2 :=
begin
cases d with h h
; unfold decidable.to_bool cond,
{ cases mod_two_eq_zero_or_one x with h' h',
rw h', cases h h' },
{ rw h },
end
lemma sub_mul_mod (x k n : ℕ)
(h₀ : 0 < n)
(h₁ : n*k ≤ x)
: (x - n*k) % n = x % n :=
begin
induction k with k,
{ simp },
{ assert h₂ : n * k ≤ x,
{ rw [mul_succ] at h₁,
apply nat.le_trans _ h₁,
apply le_add_right _ n },
assert h₄ : x - n * k ≥ n,
{ apply @nat.le_of_add_le_add_right (n*k),
rw [nat.sub_add_cancel h₂],
simp [mul_succ] at h₁, simp [h₁] },
rw [mul_succ,-nat.sub_sub,-mod_eq_sub_mod h₀ h₄,ih_1 h₂] }
end
/- div & mod -/
lemma div_def (x y : nat) : x / y = if 0 < y ∧ y ≤ x then (x - y) / y + 1 else 0 :=
by note h := div_def_aux x y; rwa dif_eq_if at h
lemma mod_add_div (m k : ℕ)
: m % k + k * (m / k) = m :=
begin
apply nat.strong_induction_on m,
clear m,
intros m IH,
cases decidable.em (0 < k ∧ k ≤ m) with h h',
-- 0 < k ∧ k ≤ m
{ assert h' : m - k < m,
{ apply nat.sub_lt _ h.left,
apply lt_of_lt_of_le h.left h.right },
rw [div_def, mod_def, if_pos h, if_pos h],
simp [left_distrib,IH _ h'],
rw [-nat.add_sub_assoc h.right,nat.add_sub_cancel_left] },
-- ¬ (0 < k ∧ k ≤ m)
{ rw [div_def, mod_def, if_neg h', if_neg h'], simp },
end
/- div -/
protected lemma div_one (n : ℕ) : n / 1 = n :=
have n % 1 + 1 * (n / 1) = n, from mod_add_div _ _,
by simp [mod_one] at this; assumption
protected lemma div_zero (n : ℕ) : n / 0 = 0 :=
begin rw [div_def], simp [lt_irrefl] end
protected lemma div_le_of_le_mul {m n : ℕ} : ∀ {k}, m ≤ k * n → m / k ≤ n
| 0 h := by simp [nat.div_zero]; apply zero_le
| (succ k) h :=
suffices succ k * (m / succ k) ≤ succ k * n, from le_of_mul_le_mul_left this (zero_lt_succ _),
calc
succ k * (m / succ k) ≤ m % succ k + succ k * (m / succ k) : le_add_left _ _
... = m : by rw mod_add_div
... ≤ succ k * n : h
protected lemma div_le_self : ∀ (m n : ℕ), m / n ≤ m
| m 0 := by simp [nat.div_zero]; apply zero_le
| m (succ n) :=
have m ≤ succ n * m, from calc
m = 1 * m : by simp
... ≤ succ n * m : mul_le_mul_right _ (succ_le_succ (zero_le _)),
nat.div_le_of_le_mul this
lemma div_eq_sub_div {a b : nat} (h₁ : b > 0) (h₂ : a ≥ b)
: a / b = (a - b) / b + 1 :=
begin
rw [div_def a,if_pos],
split ; assumption
end
lemma sub_mul_div (x n p : ℕ)
(h₀ : 0 < n)
(h₁ : n*p ≤ x)
: (x - n*p) / n = x / n - p :=
begin
induction p with p,
{ simp },
{ assert h₂ : n*p ≤ x,
{ transitivity,
{ apply nat.mul_le_mul_left, apply le_succ },
{ apply h₁ } },
assert h₃ : x - n * p ≥ n,
{ apply le_of_add_le_add_right,
rw [nat.sub_add_cancel h₂,add_comm],
rw [mul_succ] at h₁,
apply h₁ },
rw [sub_succ,-ih_1 h₂],
rw [@div_eq_sub_div (x - n*p) _ h₀ h₃],
simp [add_one_eq_succ,pred_succ,mul_succ,nat.sub_sub] }
end
lemma div_eq_of_lt {a b : ℕ} (h₀ : a < b)
: a / b = 0 :=
begin
rw [div_def a,if_neg],
intro h₁,
apply not_le_of_gt h₀ h₁.right
end
-- this is a Galois connection
-- f x ≤ y ↔ x ≤ g y
-- with
-- f x = x * k
-- g y = y / k
theorem le_div_iff_mul_le (x y : ℕ) {k : ℕ}
(Hk : k > 0)
: x ≤ y / k ↔ x * k ≤ y :=
begin
-- Hk is needed because, despite div being made total, y / 0 := 0
-- x * 0 ≤ y ↔ x ≤ y / 0
-- ↔ 0 ≤ y ↔ x ≤ 0
-- ↔ true ↔ x = 0
-- ↔ x = 0
revert x,
apply nat.strong_induction_on y _,
clear y,
intros y IH x,
cases lt_or_ge y k with h h,
-- base case: y < k
{ rw [div_eq_of_lt h],
cases x with x,
{ simp [zero_mul,zero_le_iff_true] },
{ simp [succ_mul,succ_le_zero_iff_false],
apply not_le_of_gt,
apply lt_of_lt_of_le h,
apply le_add_right } },
-- step: k ≤ y
{ rw [div_eq_sub_div Hk h],
cases x with x,
{ simp [zero_mul,zero_le_iff_true] },
{ assert Hlt : y - k < y,
{ apply sub_lt_of_pos_le ; assumption },
rw [ -add_one_eq_succ
, nat.add_le_add_iff_le_right
, IH (y - k) Hlt x
, add_one_eq_succ
, succ_mul, add_le_to_le_sub _ h ]
} }
end
theorem div_lt_iff_lt_mul (x y : ℕ) {k : ℕ}
(Hk : k > 0)
: x / k < y ↔ x < y * k :=
begin
simp [lt_iff_not_ge],
apply not_iff_not_of_iff,
apply le_div_iff_mul_le _ _ Hk
end
/- pow -/
lemma pos_pow_of_pos {b : ℕ} : ∀ (n : ℕ) (h : 0 < b), 0 < b^n
| 0 _ := nat.le_refl _
| (succ n) h :=
begin
rw -mul_zero 0,
apply mul_lt_mul (pos_pow_of_pos _ h) h,
apply nat.le_refl,
apply zero_le
end
/- mod / div / pow -/
theorem mod_pow_succ {b : ℕ} (b_pos : b > 0) (w m : ℕ)
: m % (b^succ w) = b * (m/b % b^w) + m % b :=
begin
apply nat.strong_induction_on m,
clear m,
intros p IH,
cases lt_or_ge p (b^succ w) with h₁ h₁,
-- base case: p < b^succ w
{ assert h₂ : p / b < b^w,
{ apply (div_lt_iff_lt_mul p _ b_pos).mpr,
simp at h₁, simp [h₁] },
rw [mod_eq_of_lt h₁,mod_eq_of_lt h₂], simp [mod_add_div], },
-- step: p ≥ b^succ w
{ assert h₄ : ∀ {x}, b^x > 0,
{ intro x, apply pos_pow_of_pos _ b_pos },
assert h₂ : p - b^succ w < p,
{ apply sub_lt_of_pos_le _ _ h₄ h₁ },
assert h₅ : b * b^w ≤ p,
{ simp at h₁, simp [h₁] },
rw [mod_eq_sub_mod h₄ h₁,IH _ h₂,pow_succ],
apply congr, apply congr_arg,
{ assert h₃ : p / b ≥ b^w,
{ apply (le_div_iff_mul_le _ p b_pos).mpr, simp [h₅] },
simp [nat.sub_mul_div _ _ _ b_pos h₅,mod_eq_sub_mod h₄ h₃] },
{ simp [nat.sub_mul_mod p (b^w) _ b_pos h₅] } }
end
end nat
|
62ca25984f2adcd9d7de9a2fc3daca35ad53a2ac | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/ring_theory/algebraic.lean | 46567de090a3e881b298b394667f2097c9300899 | [
"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 | 17,650 | lean | /-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import linear_algebra.finite_dimensional
import ring_theory.integral_closure
import data.polynomial.integral_normalization
/-!
# Algebraic elements and algebraic extensions
An element of an R-algebra is algebraic over R if it is the root of a nonzero polynomial.
An R-algebra is algebraic over R if and only if all its elements are algebraic over R.
The main result in this file proves transitivity of algebraicity:
a tower of algebraic field extensions is algebraic.
-/
universes u v w
open_locale classical polynomial
open polynomial
section
variables (R : Type u) {A : Type v} [comm_ring R] [ring A] [algebra R A]
/-- An element of an R-algebra is algebraic over R if it is a root of a nonzero polynomial
with coefficients in R. -/
def is_algebraic (x : A) : Prop :=
∃ p : R[X], p ≠ 0 ∧ aeval x p = 0
/-- An element of an R-algebra is transcendental over R if it is not algebraic over R. -/
def transcendental (x : A) : Prop := ¬ is_algebraic R x
lemma is_transcendental_of_subsingleton [subsingleton R] (x : A) : transcendental R x :=
λ ⟨p, h, _⟩, h $ subsingleton.elim p 0
variables {R}
/-- A subalgebra is algebraic if all its elements are algebraic. -/
def subalgebra.is_algebraic (S : subalgebra R A) : Prop := ∀ x ∈ S, is_algebraic R x
variables (R A)
/-- An algebra is algebraic if all its elements are algebraic. -/
def algebra.is_algebraic : Prop := ∀ x : A, is_algebraic R x
variables {R A}
/-- A subalgebra is algebraic if and only if it is algebraic as an algebra. -/
lemma subalgebra.is_algebraic_iff (S : subalgebra R A) :
S.is_algebraic ↔ @algebra.is_algebraic R S _ _ S.algebra :=
begin
delta algebra.is_algebraic subalgebra.is_algebraic,
rw subtype.forall',
refine forall_congr (λ x, exists_congr (λ p, and_congr iff.rfl _)),
have h : function.injective S.val := subtype.val_injective,
conv_rhs { rw [← h.eq_iff, alg_hom.map_zero] },
rw [← aeval_alg_hom_apply, S.val_apply]
end
/-- An algebra is algebraic if and only if it is algebraic as a subalgebra. -/
lemma algebra.is_algebraic_iff : algebra.is_algebraic R A ↔ (⊤ : subalgebra R A).is_algebraic :=
begin
delta algebra.is_algebraic subalgebra.is_algebraic,
simp only [algebra.mem_top, forall_prop_of_true, iff_self],
end
lemma is_algebraic_iff_not_injective {x : A} : is_algebraic R x ↔
¬ function.injective (polynomial.aeval x : R[X] →ₐ[R] A) :=
by simp only [is_algebraic, injective_iff_map_eq_zero, not_forall, and.comm, exists_prop]
end
section zero_ne_one
variables (R : Type u) {S : Type*} {A : Type v} [comm_ring R]
variables [comm_ring S] [ring A] [algebra R A] [algebra R S] [algebra S A]
variables [is_scalar_tower R S A]
/-- An integral element of an algebra is algebraic.-/
lemma is_integral.is_algebraic [nontrivial R] {x : A} : is_integral R x → is_algebraic R x :=
λ ⟨p, hp, hpx⟩, ⟨p, hp.ne_zero, hpx⟩
variables {R}
lemma is_algebraic_zero [nontrivial R] : is_algebraic R (0 : A) :=
⟨_, X_ne_zero, aeval_X 0⟩
/-- An element of `R` is algebraic, when viewed as an element of the `R`-algebra `A`. -/
lemma is_algebraic_algebra_map [nontrivial R] (x : R) : is_algebraic R (algebra_map R A x) :=
⟨_, X_sub_C_ne_zero x, by rw [_root_.map_sub, aeval_X, aeval_C, sub_self]⟩
lemma is_algebraic_one [nontrivial R] : is_algebraic R (1 : A) :=
by { rw ←_root_.map_one _, exact is_algebraic_algebra_map 1 }
lemma is_algebraic_nat [nontrivial R] (n : ℕ) : is_algebraic R (n : A) :=
by { rw ←map_nat_cast _, exact is_algebraic_algebra_map n }
lemma is_algebraic_int [nontrivial R] (n : ℤ) : is_algebraic R (n : A) :=
by { rw ←_root_.map_int_cast (algebra_map R A), exact is_algebraic_algebra_map n }
lemma is_algebraic_rat (R : Type u) {A : Type v} [division_ring A] [field R] [algebra R A] (n : ℚ) :
is_algebraic R (n : A) :=
by { rw ←map_rat_cast (algebra_map R A), exact is_algebraic_algebra_map n }
lemma is_algebraic_of_mem_root_set {R : Type u} {A : Type v} [field R] [field A] [algebra R A]
{p : R[X]} {x : A} (hx : x ∈ p.root_set A) : is_algebraic R x :=
⟨p, ne_zero_of_mem_root_set hx, aeval_eq_zero_of_mem_root_set hx⟩
open is_scalar_tower
lemma is_algebraic_algebra_map_of_is_algebraic {a : S} :
is_algebraic R a → is_algebraic R (algebra_map S A a) :=
λ ⟨f, hf₁, hf₂⟩, ⟨f, hf₁, by rw [aeval_algebra_map_apply, hf₂, map_zero]⟩
/-- This is slightly more general than `is_algebraic_algebra_map_of_is_algebraic` in that it
allows noncommutative intermediate rings `A`. -/
lemma is_algebraic_alg_hom_of_is_algebraic {B} [ring B] [algebra R B]
(f : A →ₐ[R] B) {a : A} (h : is_algebraic R a) : is_algebraic R (f a) :=
let ⟨p, hp, ha⟩ := h in ⟨p, hp, by rw [aeval_alg_hom, f.comp_apply, ha, map_zero]⟩
/-- Transfer `algebra.is_algebraic` across an `alg_equiv`. -/
lemma _root_.alg_equiv.is_algebraic {B} [ring B] [algebra R B] (e : A ≃ₐ[R] B)
(h : algebra.is_algebraic R A) : algebra.is_algebraic R B :=
λ b, by convert ← is_algebraic_alg_hom_of_is_algebraic e.to_alg_hom (h _); apply e.apply_symm_apply
lemma _root_.alg_equiv.is_algebraic_iff {B} [ring B] [algebra R B] (e : A ≃ₐ[R] B) :
algebra.is_algebraic R A ↔ algebra.is_algebraic R B := ⟨e.is_algebraic, e.symm.is_algebraic⟩
lemma is_algebraic_algebra_map_iff {a : S} (h : function.injective (algebra_map S A)) :
is_algebraic R (algebra_map S A a) ↔ is_algebraic R a :=
⟨λ ⟨p, hp0, hp⟩, ⟨p, hp0, h (by rwa [map_zero, ← aeval_algebra_map_apply])⟩,
is_algebraic_algebra_map_of_is_algebraic⟩
lemma is_algebraic_of_pow {r : A} {n : ℕ} (hn : 0 < n) (ht : is_algebraic R (r ^ n)) :
is_algebraic R r :=
begin
obtain ⟨p, p_nonzero, hp⟩ := ht,
refine ⟨polynomial.expand _ n p, _, _⟩,
{ rwa polynomial.expand_ne_zero hn },
{ rwa polynomial.expand_aeval n p r },
end
lemma transcendental.pow {r : A} (ht : transcendental R r) {n : ℕ} (hn : 0 < n) :
transcendental R (r ^ n) :=
λ ht', ht $ is_algebraic_of_pow hn ht'
end zero_ne_one
section field
variables {K : Type u} {A : Type v} [field K] [ring A] [algebra K A]
/-- An element of an algebra over a field is algebraic if and only if it is integral.-/
lemma is_algebraic_iff_is_integral {x : A} :
is_algebraic K x ↔ is_integral K x :=
begin
refine ⟨_, is_integral.is_algebraic K⟩,
rintro ⟨p, hp, hpx⟩,
refine ⟨_, monic_mul_leading_coeff_inv hp, _⟩,
rw [← aeval_def, alg_hom.map_mul, hpx, zero_mul],
end
protected lemma algebra.is_algebraic_iff_is_integral :
algebra.is_algebraic K A ↔ algebra.is_integral K A :=
⟨λ h x, is_algebraic_iff_is_integral.mp (h x),
λ h x, is_algebraic_iff_is_integral.mpr (h x)⟩
end field
namespace algebra
variables {K : Type*} {L : Type*} {R : Type*} {S : Type*} {A : Type*}
variables [field K] [field L] [comm_ring R] [comm_ring S] [comm_ring A]
variables [algebra K L] [algebra L A] [algebra K A] [is_scalar_tower K L A]
variables [algebra R S] [algebra S A] [algebra R A] [is_scalar_tower R S A]
/-- If L is an algebraic field extension of K and A is an algebraic algebra over L,
then A is algebraic over K. -/
lemma is_algebraic_trans (L_alg : is_algebraic K L) (A_alg : is_algebraic L A) :
is_algebraic K A :=
begin
simp only [is_algebraic, is_algebraic_iff_is_integral] at L_alg A_alg ⊢,
exact is_integral_trans L_alg A_alg,
end
variables (K L)
/-- If x is algebraic over R, then x is algebraic over S when S is an extension of R,
and the map from `R` to `S` is injective. -/
lemma _root_.is_algebraic_of_larger_base_of_injective (hinj : function.injective (algebra_map R S))
{x : A} (A_alg : _root_.is_algebraic R x) : _root_.is_algebraic S x :=
let ⟨p, hp₁, hp₂⟩ := A_alg in
⟨p.map (algebra_map _ _),
by rwa [ne.def, ← degree_eq_bot, degree_map_eq_of_injective hinj, degree_eq_bot],
by simpa⟩
/-- If A is an algebraic algebra over R, then A is algebraic over S when S is an extension of R,
and the map from `R` to `S` is injective. -/
lemma is_algebraic_of_larger_base_of_injective (hinj : function.injective (algebra_map R S))
(A_alg : is_algebraic R A) : is_algebraic S A :=
λ x, is_algebraic_of_larger_base_of_injective hinj (A_alg x)
/-- If x is a algebraic over K, then x is algebraic over L when L is an extension of K -/
lemma _root_.is_algebraic_of_larger_base {x : A} (A_alg : _root_.is_algebraic K x) :
_root_.is_algebraic L x :=
_root_.is_algebraic_of_larger_base_of_injective (algebra_map K L).injective A_alg
/-- If A is an algebraic algebra over K, then A is algebraic over L when L is an extension of K -/
lemma is_algebraic_of_larger_base (A_alg : is_algebraic K A) : is_algebraic L A :=
is_algebraic_of_larger_base_of_injective (algebra_map K L).injective A_alg
variables (K L)
/-- A field extension is integral if it is finite. -/
lemma is_integral_of_finite [finite_dimensional K L] : algebra.is_integral K L :=
λ x, is_integral_of_submodule_noetherian ⊤
(is_noetherian.iff_fg.2 infer_instance) x algebra.mem_top
/-- A field extension is algebraic if it is finite. -/
lemma is_algebraic_of_finite [finite : finite_dimensional K L] : is_algebraic K L :=
algebra.is_algebraic_iff_is_integral.mpr (is_integral_of_finite K L)
variables {K L}
theorem is_algebraic.alg_hom_bijective
(ha : algebra.is_algebraic K L) (f : L →ₐ[K] L) : function.bijective f :=
begin
refine ⟨f.to_ring_hom.injective, λ b, _⟩,
obtain ⟨p, hp, he⟩ := ha b,
let f' : p.root_set L → p.root_set L :=
set.maps_to.restrict f _ _ (root_set_maps_to (map_ne_zero hp) f),
have : function.surjective f' := finite.injective_iff_surjective.1
(λ _ _ h, subtype.eq $ f.to_ring_hom.injective $ subtype.ext_iff.1 h),
obtain ⟨a, ha⟩ := this ⟨b, (mem_root_set_iff hp b).2 he⟩,
exact ⟨a, subtype.ext_iff.1 ha⟩,
end
theorem _root_.alg_hom.bijective [finite_dimensional K L] (ϕ : L →ₐ[K] L) : function.bijective ϕ :=
(algebra.is_algebraic_of_finite K L).alg_hom_bijective ϕ
variables (K L)
/-- Bijection between algebra equivalences and algebra homomorphisms -/
@[simps] noncomputable
def is_algebraic.alg_equiv_equiv_alg_hom
(ha : algebra.is_algebraic K L) : (L ≃ₐ[K] L) ≃* (L →ₐ[K] L) :=
{ to_fun := λ ϕ, ϕ.to_alg_hom,
inv_fun := λ ϕ, alg_equiv.of_bijective ϕ (ha.alg_hom_bijective ϕ),
left_inv := λ _, by {ext, refl},
right_inv := λ _, by {ext, refl},
map_mul' := λ _ _, rfl }
/-- Bijection between algebra equivalences and algebra homomorphisms -/
@[reducible] noncomputable def _root_.alg_equiv_equiv_alg_hom [finite_dimensional K L] :
(L ≃ₐ[K] L) ≃* (L →ₐ[K] L) := (algebra.is_algebraic_of_finite K L).alg_equiv_equiv_alg_hom K L
end algebra
variables {R S : Type*} [comm_ring R] [is_domain R] [comm_ring S]
lemma exists_integral_multiple [algebra R S] {z : S} (hz : is_algebraic R z)
(inj : ∀ x, algebra_map R S x = 0 → x = 0) :
∃ (x : integral_closure R S) (y ≠ (0 : R)),
z * algebra_map R S y = x :=
begin
rcases hz with ⟨p, p_ne_zero, px⟩,
set a := p.leading_coeff with a_def,
have a_ne_zero : a ≠ 0 := mt polynomial.leading_coeff_eq_zero.mp p_ne_zero,
have y_integral : is_integral R (algebra_map R S a) := is_integral_algebra_map,
have x_integral : is_integral R (z * algebra_map R S a) :=
⟨p.integral_normalization,
monic_integral_normalization p_ne_zero,
integral_normalization_aeval_eq_zero px inj⟩,
exact ⟨⟨_, x_integral⟩, a, a_ne_zero, rfl⟩
end
/-- A fraction `(a : S) / (b : S)` can be reduced to `(c : S) / (d : R)`,
if `S` is the integral closure of `R` in an algebraic extension `L` of `R`. -/
lemma is_integral_closure.exists_smul_eq_mul {L : Type*} [field L]
[algebra R S] [algebra S L] [algebra R L] [is_scalar_tower R S L] [is_integral_closure S R L]
(h : algebra.is_algebraic R L) (inj : function.injective (algebra_map R L))
(a : S) {b : S} (hb : b ≠ 0) : ∃ (c : S) (d ≠ (0 : R)), d • a = b * c :=
begin
obtain ⟨c, d, d_ne, hx⟩ := exists_integral_multiple
(h (algebra_map _ L a / algebra_map _ L b))
((injective_iff_map_eq_zero _).mp inj),
refine ⟨is_integral_closure.mk' S (c : L) c.2, d, d_ne,
is_integral_closure.algebra_map_injective S R L _⟩,
simp only [algebra.smul_def, ring_hom.map_mul, is_integral_closure.algebra_map_mk', ← hx,
← is_scalar_tower.algebra_map_apply],
rw [← mul_assoc _ (_ / _), mul_div_cancel' (algebra_map S L a), mul_comm],
exact mt ((injective_iff_map_eq_zero _).mp (is_integral_closure.algebra_map_injective S R L) _) hb
end
section field
variables {K L : Type*} [field K] [field L] [algebra K L] (A : subalgebra K L)
lemma inv_eq_of_aeval_div_X_ne_zero {x : L} {p : K[X]}
(aeval_ne : aeval x (div_X p) ≠ 0) :
x⁻¹ = aeval x (div_X p) / (aeval x p - algebra_map _ _ (p.coeff 0)) :=
begin
rw [inv_eq_iff_inv_eq, inv_div, div_eq_iff, sub_eq_iff_eq_add, mul_comm],
conv_lhs { rw ← div_X_mul_X_add p },
rw [alg_hom.map_add, alg_hom.map_mul, aeval_X, aeval_C],
exact aeval_ne
end
lemma inv_eq_of_root_of_coeff_zero_ne_zero {x : L} {p : K[X]}
(aeval_eq : aeval x p = 0) (coeff_zero_ne : p.coeff 0 ≠ 0) :
x⁻¹ = - (aeval x (div_X p) / algebra_map _ _ (p.coeff 0)) :=
begin
convert inv_eq_of_aeval_div_X_ne_zero (mt (λ h, (algebra_map K L).injective _) coeff_zero_ne),
{ rw [aeval_eq, zero_sub, div_neg] },
rw ring_hom.map_zero,
convert aeval_eq,
conv_rhs { rw ← div_X_mul_X_add p },
rw [alg_hom.map_add, alg_hom.map_mul, h, zero_mul, zero_add, aeval_C]
end
lemma subalgebra.inv_mem_of_root_of_coeff_zero_ne_zero {x : A} {p : K[X]}
(aeval_eq : aeval x p = 0) (coeff_zero_ne : p.coeff 0 ≠ 0) : (x⁻¹ : L) ∈ A :=
begin
suffices : (x⁻¹ : L) = (-p.coeff 0)⁻¹ • aeval x (div_X p),
{ rw [this], exact A.smul_mem (aeval x _).2 _ },
have : aeval (x : L) p = 0, by rw [subalgebra.aeval_coe, aeval_eq, subalgebra.coe_zero],
rw [inv_eq_of_root_of_coeff_zero_ne_zero this coeff_zero_ne, div_eq_inv_mul,
algebra.smul_def, map_inv₀, map_neg, inv_neg, neg_mul, subalgebra.aeval_coe]
end
lemma subalgebra.inv_mem_of_algebraic {x : A} (hx : is_algebraic K (x : L)) : (x⁻¹ : L) ∈ A :=
begin
obtain ⟨p, ne_zero, aeval_eq⟩ := hx,
rw [subalgebra.aeval_coe, subalgebra.coe_eq_zero] at aeval_eq,
revert ne_zero aeval_eq,
refine p.rec_on_horner _ _ _,
{ intro h,
contradiction },
{ intros p a hp ha ih ne_zero aeval_eq,
refine A.inv_mem_of_root_of_coeff_zero_ne_zero aeval_eq _,
rwa [coeff_add, hp, zero_add, coeff_C, if_pos rfl] },
{ intros p hp ih ne_zero aeval_eq,
rw [alg_hom.map_mul, aeval_X, mul_eq_zero] at aeval_eq,
cases aeval_eq with aeval_eq x_eq,
{ exact ih hp aeval_eq },
{ rw [x_eq, subalgebra.coe_zero, inv_zero],
exact A.zero_mem } }
end
/-- In an algebraic extension L/K, an intermediate subalgebra is a field. -/
lemma subalgebra.is_field_of_algebraic (hKL : algebra.is_algebraic K L) : is_field A :=
{ mul_inv_cancel := λ a ha, ⟨
⟨a⁻¹, A.inv_mem_of_algebraic (hKL a)⟩,
subtype.ext (mul_inv_cancel (mt (subalgebra.coe_eq_zero _).mp ha))⟩,
.. show nontrivial A, by apply_instance,
.. subalgebra.to_comm_ring A }
end field
section pi
variables (R' : Type u) (S' : Type v) (T' : Type w)
/-- This is not an instance as it forms a diamond with `pi.has_smul`.
See the `instance_diamonds` test for details. -/
def polynomial.has_smul_pi [semiring R'] [has_smul R' S'] :
has_smul (R'[X]) (R' → S') :=
⟨λ p f x, eval x p • f x⟩
/-- This is not an instance as it forms a diamond with `pi.has_smul`.
See the `instance_diamonds` test for details. -/
noncomputable def polynomial.has_smul_pi' [comm_semiring R'] [semiring S'] [algebra R' S']
[has_smul S' T'] :
has_smul (R'[X]) (S' → T') :=
⟨λ p f x, aeval x p • f x⟩
variables {R} {S}
local attribute [instance] polynomial.has_smul_pi polynomial.has_smul_pi'
@[simp] lemma polynomial_smul_apply [semiring R'] [has_smul R' S']
(p : R'[X]) (f : R' → S') (x : R') :
(p • f) x = eval x p • f x := rfl
@[simp] lemma polynomial_smul_apply' [comm_semiring R'] [semiring S'] [algebra R' S']
[has_smul S' T'] (p : R'[X]) (f : S' → T') (x : S') :
(p • f) x = aeval x p • f x := rfl
variables [comm_semiring R'] [comm_semiring S'] [comm_semiring T'] [algebra R' S'] [algebra S' T']
/-- This is not an instance for the same reasons as `polynomial.has_smul_pi'`. -/
noncomputable def polynomial.algebra_pi :
algebra (R'[X]) (S' → T') :=
{ to_fun := λ p z, algebra_map S' T' (aeval z p),
map_one' := funext $ λ z, by simp only [polynomial.aeval_one, pi.one_apply, map_one],
map_mul' := λ f g, funext $ λ z, by simp only [pi.mul_apply, map_mul],
map_zero' := funext $ λ z, by simp only [polynomial.aeval_zero, pi.zero_apply, map_zero],
map_add' := λ f g, funext $ λ z, by simp only [polynomial.aeval_add, pi.add_apply, map_add],
commutes' := λ p f, funext $ λ z, mul_comm _ _,
smul_def' := λ p f, funext $ λ z, by
simp only [algebra.algebra_map_eq_smul_one, polynomial_smul_apply', one_mul,
pi.mul_apply, algebra.smul_mul_assoc],
..polynomial.has_smul_pi' R' S' T' }
local attribute [instance] polynomial.algebra_pi
@[simp] lemma polynomial.algebra_map_pi_eq_aeval :
(algebra_map (R'[X]) (S' → T') : R'[X] → (S' → T')) =
λ p z, algebra_map _ _ (aeval z p) := rfl
@[simp] lemma polynomial.algebra_map_pi_self_eq_eval :
(algebra_map (R'[X]) (R' → R') : R'[X] → (R' → R')) = λ p z, eval z p := rfl
end pi
|
7d6a54f8f2739d92932b296e8dca7d4747d49025 | 9b9a16fa2cb737daee6b2785474678b6fa91d6d4 | /src/category_theory/fully_faithful.lean | 07aaf23bc1b37c7b046d0066617956d10f4156da | [
"Apache-2.0"
] | permissive | johoelzl/mathlib | 253f46daa30b644d011e8e119025b01ad69735c4 | 592e3c7a2dfbd5826919b4605559d35d4d75938f | refs/heads/master | 1,625,657,216,488 | 1,551,374,946,000 | 1,551,374,946,000 | 98,915,829 | 0 | 0 | Apache-2.0 | 1,522,917,267,000 | 1,501,524,499,000 | Lean | UTF-8 | Lean | false | false | 2,820 | 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 category_theory.isomorphism
universes v₁ v₂ v₃ u₁ u₂ u₃ -- declare the `v`'s first; see `category_theory.category` for an explanation
namespace category_theory
variables {C : Type u₁} [𝒞 : category.{v₁} C] {D : Type u₂} [𝒟 : category.{v₂} D]
include 𝒞 𝒟
class full (F : C ⥤ D) :=
(preimage : ∀ {X Y : C} (f : (F.obj X) ⟶ (F.obj Y)), X ⟶ Y)
(witness' : ∀ {X Y : C} (f : (F.obj X) ⟶ (F.obj Y)), F.map (preimage f) = f . obviously)
restate_axiom full.witness'
attribute [simp] full.witness
class faithful (F : C ⥤ D) : Prop :=
(injectivity' : ∀ {X Y : C} {f g : X ⟶ Y} (p : F.map f = F.map g), f = g . obviously)
restate_axiom faithful.injectivity'
namespace functor
def injectivity (F : C ⥤ D) [faithful F] {X Y : C} {f g : X ⟶ Y} (p : F.map f = F.map g) : f = g :=
faithful.injectivity F p
def preimage (F : C ⥤ D) [full F] {X Y : C} (f : F.obj X ⟶ F.obj Y) : X ⟶ Y :=
full.preimage.{v₁ v₂} f
@[simp] lemma image_preimage (F : C ⥤ D) [full F] {X Y : C} (f : F.obj X ⟶ F.obj Y) :
F.map (preimage F f) = f :=
by unfold preimage; obviously
end functor
section
variables {F : C ⥤ D} [full F] [faithful F] {X Y : C}
def preimage_iso (f : (F.obj X) ≅ (F.obj Y)) : X ≅ Y :=
{ hom := F.preimage f.hom,
inv := F.preimage f.inv,
hom_inv_id' := begin apply @faithful.injectivity _ _ _ _ F, obviously, end,
inv_hom_id' := begin apply @faithful.injectivity _ _ _ _ F, obviously, end, }
@[simp] lemma preimage_iso_hom (f : (F.obj X) ≅ (F.obj Y)) :
(preimage_iso f).hom = F.preimage f.hom := rfl
@[simp] lemma preimage_iso_inv (f : (F.obj X) ≅ (F.obj Y)) :
(preimage_iso f).inv = F.preimage (f.inv) := rfl
end
class fully_faithful (F : C ⥤ D) extends (full F), (faithful F).
@[simp] lemma preimage_id (F : C ⥤ D) [fully_faithful F] (X : C) : F.preimage (𝟙 (F.obj X)) = 𝟙 X :=
F.injectivity (by simp)
end category_theory
namespace category_theory
variables {C : Type u₁} [𝒞 : category.{v₁} C]
include 𝒞
instance full.id : full (functor.id C) :=
{ preimage := λ _ _ f, f }
instance : faithful (functor.id C) := by obviously
instance : fully_faithful (functor.id C) := { ((by apply_instance) : full (functor.id C)) with }
variables {D : Type u₂} [𝒟 : category.{v₂} D] {E : Type u₃} [ℰ : category.{v₃} E]
include 𝒟 ℰ
variables (F : C ⥤ D) (G : D ⥤ E)
instance faithful.comp [faithful F] [faithful G] : faithful (F ⋙ G) :=
{ injectivity' := λ _ _ _ _ p, F.injectivity (G.injectivity p) }
instance full.comp [full F] [full G] : full (F ⋙ G) :=
{ preimage := λ _ _ f, F.preimage (G.preimage f) }
end category_theory
|
cacaff552a31069453b191e252e1caecb36e5950 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/data/qpf/multivariate/constructions/comp.lean | 696059a149783a2d5ed0133089e40bfeef2e73f6 | [] | 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 | 4,128 | 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.basic
import Mathlib.data.qpf.multivariate.basic
import Mathlib.PostPort
universes u u_1
namespace Mathlib
/-!
# The composition of QPFs is itself a QPF
We define composition between one `n`-ary functor and `n` `m`-ary functors
and show that it preserves the QPF structure
-/
namespace mvqpf
/-- Composition of an `n`-ary functor with `n` `m`-ary
functors gives us one `m`-ary functor -/
def comp {n : ℕ} {m : ℕ} (F : typevec n → Type u_1) (G : fin2 n → typevec m → Type u) (v : typevec m) :=
F fun (i : fin2 n) => G i v
namespace comp
protected instance inhabited {n : ℕ} {m : ℕ} {F : typevec n → Type u_1} {G : fin2 n → typevec m → Type u} {α : typevec m} [I : Inhabited (F fun (i : fin2 n) => G i α)] : Inhabited (comp F G α) :=
I
/-- Constructor for functor composition -/
protected def mk {n : ℕ} {m : ℕ} {F : typevec n → Type u_1} {G : fin2 n → typevec m → Type u} {α : typevec m} (x : F fun (i : fin2 n) => G i α) : comp F G α :=
x
/-- Destructor for functor composition -/
protected def get {n : ℕ} {m : ℕ} {F : typevec n → Type u_1} {G : fin2 n → typevec m → Type u} {α : typevec m} (x : comp F G α) : F fun (i : fin2 n) => G i α :=
x
@[simp] protected theorem mk_get {n : ℕ} {m : ℕ} {F : typevec n → Type u_1} {G : fin2 n → typevec m → Type u} {α : typevec m} (x : comp F G α) : comp.mk (comp.get x) = x :=
rfl
@[simp] protected theorem get_mk {n : ℕ} {m : ℕ} {F : typevec n → Type u_1} {G : fin2 n → typevec m → Type u} {α : typevec m} (x : F fun (i : fin2 n) => G i α) : comp.get (comp.mk x) = x :=
rfl
/-- map operation defined on a vector of functors -/
protected def map' {n : ℕ} {m : ℕ} {G : fin2 n → typevec m → Type u} [fG : (i : fin2 n) → mvfunctor (G i)] {α : typevec m} {β : typevec m} (f : typevec.arrow α β) : typevec.arrow (fun (i : fin2 n) => G i α) fun (i : fin2 n) => G i β :=
fun (i : fin2 n) => mvfunctor.map f
/-- The composition of functors is itself functorial -/
protected def map {n : ℕ} {m : ℕ} {F : typevec n → Type u_1} [fF : mvfunctor F] {G : fin2 n → typevec m → Type u} [fG : (i : fin2 n) → mvfunctor (G i)] {α : typevec m} {β : typevec m} (f : typevec.arrow α β) : comp F G α → comp F G β :=
mvfunctor.map fun (i : fin2 n) => mvfunctor.map f
protected instance mvfunctor {n : ℕ} {m : ℕ} {F : typevec n → Type u_1} [fF : mvfunctor F] {G : fin2 n → typevec m → Type u} [fG : (i : fin2 n) → mvfunctor (G i)] : mvfunctor (comp F G) :=
mvfunctor.mk fun (α β : typevec m) => comp.map
theorem map_mk {n : ℕ} {m : ℕ} {F : typevec n → Type u_1} [fF : mvfunctor F] {G : fin2 n → typevec m → Type u} [fG : (i : fin2 n) → mvfunctor (G i)] {α : typevec m} {β : typevec m} (f : typevec.arrow α β) (x : F fun (i : fin2 n) => G i α) : mvfunctor.map f (comp.mk x) = comp.mk (mvfunctor.map (fun (i : fin2 n) (x : G i α) => mvfunctor.map f x) x) :=
rfl
theorem get_map {n : ℕ} {m : ℕ} {F : typevec n → Type u_1} [fF : mvfunctor F] {G : fin2 n → typevec m → Type u} [fG : (i : fin2 n) → mvfunctor (G i)] {α : typevec m} {β : typevec m} (f : typevec.arrow α β) (x : comp F G α) : comp.get (mvfunctor.map f x) = mvfunctor.map (fun (i : fin2 n) (x : G i α) => mvfunctor.map f x) (comp.get x) :=
rfl
protected instance mvqpf {n : ℕ} {m : ℕ} {F : typevec n → Type u_1} [fF : mvfunctor F] [q : mvqpf F] {G : fin2 n → typevec m → Type u} [fG : (i : fin2 n) → mvfunctor (G i)] [q' : (i : fin2 n) → mvqpf (G i)] : mvqpf (comp F G) :=
mk (mvpfunctor.comp (P F) fun (i : fin2 n) => P (G i))
(fun (α : typevec m) => comp.mk ∘ (mvfunctor.map fun (i : fin2 n) => abs) ∘ abs ∘ mvpfunctor.comp.get)
(fun (α : typevec m) => mvpfunctor.comp.mk ∘ repr ∘ (mvfunctor.map fun (i : fin2 n) => repr) ∘ comp.get) sorry sorry
|
71cdbca7aeaa0dfde17ceb5a810b1ef4e4801349 | 78630e908e9624a892e24ebdd21260720d29cf55 | /src/logic_first_order/fol_07.lean | f7117ee24309bb1f2c2abf26b2c3869616f2efe4 | [
"CC0-1.0"
] | permissive | tomasz-lisowski/lean-logic-examples | 84e612466776be0a16c23a0439ff8ef6114ddbe1 | 2b2ccd467b49c3989bf6c92ec0358a8d6ee68c5d | refs/heads/master | 1,683,334,199,431 | 1,621,938,305,000 | 1,621,938,305,000 | 365,041,573 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 281 | lean | namespace fol_07
variable A : Type
variable R : A → A → Prop
variable hxy : ∀ x y, R x y ∨ R y x
include hxy
theorem fol_07 : ∀ x, R x x :=
assume s,
have h1: R s s ∨ R s s, from hxy s s,
or.elim h1
(assume h2: R s s,
h2)
(assume h3: R s s,
h3)
end fol_07 |
606970a8f22ecdbbb77ccefae6536c34c9bf146b | 5fbbd711f9bfc21ee168f46a4be146603ece8835 | /lean/natural_number_game/function/5.lean | 1780e404acaf86e9f57c97eebae4e13eeb531b05 | [
"LicenseRef-scancode-warranty-disclaimer"
] | no_license | goedel-gang/maths | 22596f71e3fde9c088e59931f128a3b5efb73a2c | a20a6f6a8ce800427afd595c598a5ad43da1408d | refs/heads/master | 1,623,055,941,960 | 1,621,599,441,000 | 1,621,599,441,000 | 169,335,840 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 77 | lean | example (P Q : Type) : P → (Q → P) :=
begin
intros p q,
exact p,
end
|
b535c5ad4767672252419646bbdc3aa8b889c146 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/computability/partrec.lean | db8f468cf94473f8dea84bdd2967ea6a46af910f | [
"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 | 29,044 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import computability.primrec
import data.nat.psub
import data.pfun
/-!
# The partial recursive functions
The partial recursive functions are defined similarly to the primitive
recursive functions, but now all functions are partial, implemented
using the `roption` monad, and there is an additional operation, called
μ-recursion, which performs unbounded minimization.
## References
* [Mario Carneiro, *Formalizing computability theory via partial recursive functions*][carneiro2019]
-/
open encodable denumerable roption
local attribute [-simp] not_forall
namespace nat
section rfind
parameter (p : ℕ →. bool)
private def lbp (m n : ℕ) : Prop := m = n + 1 ∧ ∀ k ≤ n, ff ∈ p k
parameter (H : ∃ n, tt ∈ p n ∧ ∀ k < n, (p k).dom)
private def wf_lbp : well_founded lbp :=
⟨let ⟨n, pn⟩ := H in begin
suffices : ∀m k, n ≤ k + m → acc (lbp p) k,
{ from λ a, this _ _ (nat.le_add_left _ _) },
intros m k kn,
induction m with m IH generalizing k;
refine ⟨_, λ y r, _⟩; rcases r with ⟨rfl, a⟩,
{ injection mem_unique pn.1 (a _ kn) },
{ exact IH _ (by rw nat.add_right_comm; exact kn) }
end⟩
def rfind_x : {n // tt ∈ p n ∧ ∀m < n, ff ∈ p m} :=
suffices ∀ k, (∀n < k, ff ∈ p n) → {n // tt ∈ p n ∧ ∀m < n, ff ∈ p m},
from this 0 (λ n, (nat.not_lt_zero _).elim),
@well_founded.fix _ _ lbp wf_lbp begin
intros m IH al,
have pm : (p m).dom,
{ rcases H with ⟨n, h₁, h₂⟩,
rcases lt_trichotomy m n with h₃|h₃|h₃,
{ exact h₂ _ h₃ },
{ rw h₃, exact h₁.fst },
{ injection mem_unique h₁ (al _ h₃) } },
cases e : (p m).get pm,
{ suffices,
exact IH _ ⟨rfl, this⟩ (λ n h, this _ (le_of_lt_succ h)),
intros n h, cases h.lt_or_eq_dec with h h,
{ exact al _ h },
{ rw h, exact ⟨_, e⟩ } },
{ exact ⟨m, ⟨_, e⟩, al⟩ }
end
end rfind
def rfind (p : ℕ →. bool) : roption ℕ :=
⟨_, λ h, (rfind_x p h).1⟩
theorem rfind_spec {p : ℕ →. bool} {n : ℕ} (h : n ∈ rfind p) : tt ∈ p n :=
h.snd ▸ (rfind_x p h.fst).2.1
theorem rfind_min {p : ℕ →. bool} {n : ℕ} (h : n ∈ rfind p) :
∀ {m : ℕ}, m < n → ff ∈ p m :=
h.snd ▸ (rfind_x p h.fst).2.2
@[simp] theorem rfind_dom {p : ℕ →. bool} :
(rfind p).dom ↔ ∃ n, tt ∈ p n ∧ ∀ {m : ℕ}, m < n → (p m).dom :=
iff.rfl
theorem rfind_dom' {p : ℕ →. bool} :
(rfind p).dom ↔ ∃ n, tt ∈ p n ∧ ∀ {m : ℕ}, m ≤ n → (p m).dom :=
exists_congr $ λ n, and_congr_right $ λ pn,
⟨λ H m h, (decidable.eq_or_lt_of_le h).elim (λ e, e.symm ▸ pn.fst) (H _),
λ H m h, H (le_of_lt h)⟩
@[simp] theorem mem_rfind {p : ℕ →. bool} {n : ℕ} :
n ∈ rfind p ↔ tt ∈ p n ∧ ∀ {m : ℕ}, m < n → ff ∈ p m :=
⟨λ h, ⟨rfind_spec h, @rfind_min _ _ h⟩,
λ ⟨h₁, h₂⟩, let ⟨m, hm⟩ := dom_iff_mem.1 $
(@rfind_dom p).2 ⟨_, h₁, λ m mn, (h₂ mn).fst⟩ in
begin
rcases lt_trichotomy m n with h|h|h,
{ injection mem_unique (h₂ h) (rfind_spec hm) },
{ rwa ← h },
{ injection mem_unique h₁ (rfind_min hm h) },
end⟩
theorem rfind_min' {p : ℕ → bool} {m : ℕ} (pm : p m) :
∃ n ∈ rfind p, n ≤ m :=
have tt ∈ (p : ℕ →. bool) m, from ⟨trivial, pm⟩,
let ⟨n, hn⟩ := dom_iff_mem.1 $
(@rfind_dom p).2 ⟨m, this, λ k h, ⟨⟩⟩ in
⟨n, hn, not_lt.1 $ λ h,
by injection mem_unique this (rfind_min hn h)⟩
theorem rfind_zero_none
(p : ℕ →. bool) (p0 : p 0 = none) : rfind p = none :=
eq_none_iff.2 $ λ a h,
let ⟨n, h₁, h₂⟩ := rfind_dom'.1 h.fst in
(p0 ▸ h₂ (zero_le _) : (@roption.none bool).dom)
def rfind_opt {α} (f : ℕ → option α) : roption α :=
(rfind (λ n, (f n).is_some)).bind (λ n, f n)
theorem rfind_opt_spec {α} {f : ℕ → option α} {a}
(h : a ∈ rfind_opt f) : ∃ n, a ∈ f n :=
let ⟨n, h₁, h₂⟩ := mem_bind_iff.1 h in ⟨n, mem_coe.1 h₂⟩
theorem rfind_opt_dom {α} {f : ℕ → option α} :
(rfind_opt f).dom ↔ ∃ n a, a ∈ f n :=
⟨λ h, (rfind_opt_spec ⟨h, rfl⟩).imp (λ n h, ⟨_, h⟩),
λ h, begin
have h' : ∃ n, (f n).is_some :=
h.imp (λ n, option.is_some_iff_exists.2),
have s := nat.find_spec h',
have fd : (rfind (λ n, (f n).is_some)).dom :=
⟨nat.find h', by simpa using s.symm, λ _ _, trivial⟩,
refine ⟨fd, _⟩,
have := rfind_spec (get_mem fd),
simp at this ⊢,
cases option.is_some_iff_exists.1 this.symm with a e,
rw e, trivial
end⟩
theorem rfind_opt_mono {α} {f : ℕ → option α}
(H : ∀ {a m n}, m ≤ n → a ∈ f m → a ∈ f n)
{a} : a ∈ rfind_opt f ↔ ∃ n, a ∈ f n :=
⟨rfind_opt_spec, λ ⟨n, h⟩, begin
have h' := rfind_opt_dom.2 ⟨_, _, h⟩,
cases rfind_opt_spec ⟨h', rfl⟩ with k hk,
have := (H (le_max_left _ _) h).symm.trans
(H (le_max_right _ _) hk),
simp at this, simp [this, get_mem]
end⟩
inductive partrec : (ℕ →. ℕ) → Prop
| zero : partrec (pure 0)
| succ : partrec succ
| left : partrec ↑(λ n : ℕ, n.unpair.1)
| right : partrec ↑(λ n : ℕ, n.unpair.2)
| pair {f g} : partrec f → partrec g → partrec (λ n, mkpair <$> f n <*> g n)
| comp {f g} : partrec f → partrec g → partrec (λ n, g n >>= f)
| prec {f g} : partrec f → partrec g → partrec (unpaired (λ a n,
n.elim (f a) (λ y IH, do i ← IH, g (mkpair a (mkpair y i)))))
| rfind {f} : partrec f → partrec (λ a,
rfind (λ n, (λ m, m = 0) <$> f (mkpair a n)))
namespace partrec
theorem of_eq {f g : ℕ →. ℕ} (hf : partrec f) (H : ∀ n, f n = g n) : partrec g :=
(funext H : f = g) ▸ hf
theorem of_eq_tot {f : ℕ →. ℕ} {g : ℕ → ℕ}
(hf : partrec f) (H : ∀ n, g n ∈ f n) : partrec g :=
hf.of_eq (λ n, eq_some_iff.2 (H n))
theorem of_primrec {f : ℕ → ℕ} (hf : primrec f) : partrec f :=
begin
induction hf,
case nat.primrec.zero { exact zero },
case nat.primrec.succ { exact succ },
case nat.primrec.left { exact left },
case nat.primrec.right { exact right },
case nat.primrec.pair : f g hf hg pf pg {
refine (pf.pair pg).of_eq_tot (λ n, _),
simp [has_seq.seq] },
case nat.primrec.comp : f g hf hg pf pg {
refine (pf.comp pg).of_eq_tot (λ n, _),
simp },
case nat.primrec.prec : f g hf hg pf pg {
refine (pf.prec pg).of_eq_tot (λ n, _),
simp,
induction n.unpair.2 with m IH, {simp},
simp, exact ⟨_, IH, rfl⟩ },
end
protected theorem some : partrec some := of_primrec primrec.id
theorem none : partrec (λ n, none) :=
(of_primrec (nat.primrec.const 1)).rfind.of_eq $
λ n, eq_none_iff.2 $ λ a ⟨h, e⟩, by simpa using h
theorem prec' {f g h}
(hf : partrec f) (hg : partrec g) (hh : partrec h) :
partrec (λ a, (f a).bind (λ n, n.elim (g a)
(λ y IH, do i ← IH, h (mkpair a (mkpair y i))))) :=
((prec hg hh).comp (pair partrec.some hf)).of_eq $
λ a, ext $ λ s, by simp [(<*>)]; exact
⟨λ ⟨n, h₁, h₂⟩, ⟨_, ⟨_, h₁, rfl⟩, by simpa using h₂⟩,
λ ⟨_, ⟨n, h₁, rfl⟩, h₂⟩, ⟨_, h₁, by simpa using h₂⟩⟩
theorem ppred : partrec (λ n, ppred n) :=
have primrec₂ (λ n m, if n = nat.succ m then 0 else 1),
from (primrec.ite
(@@primrec_rel.comp _ _ _ _ _ _ _ primrec.eq
primrec.fst
(_root_.primrec.succ.comp primrec.snd))
(_root_.primrec.const 0) (_root_.primrec.const 1)).to₂,
(of_primrec (primrec₂.unpaired'.2 this)).rfind.of_eq $
λ n, begin
cases n; simp,
{ exact eq_none_iff.2 (λ a ⟨⟨m, h, _⟩, _⟩,
by simpa [show 0 ≠ m.succ, by intro h; injection h] using h) },
{ refine eq_some_iff.2 _,
simp, intros m h, simp [ne_of_gt h] }
end
end partrec
end nat
def partrec {α σ} [primcodable α] [primcodable σ]
(f : α →. σ) := nat.partrec (λ n,
roption.bind (decode α n) (λ a, (f a).map encode))
def partrec₂ {α β σ} [primcodable α] [primcodable β] [primcodable σ]
(f : α → β →. σ) := partrec (λ p : α × β, f p.1 p.2)
def computable {α σ} [primcodable α] [primcodable σ] (f : α → σ) := partrec (f : α →. σ)
def computable₂ {α β σ} [primcodable α] [primcodable β] [primcodable σ]
(f : α → β → σ) := computable (λ p : α × β, f p.1 p.2)
theorem primrec.to_comp {α σ} [primcodable α] [primcodable σ]
{f : α → σ} (hf : primrec f) : computable f :=
(nat.partrec.ppred.comp (nat.partrec.of_primrec hf)).of_eq $
λ n, by simp; cases decode α n; simp
theorem primrec₂.to_comp {α β σ} [primcodable α] [primcodable β] [primcodable σ]
{f : α → β → σ} (hf : primrec₂ f) : computable₂ f := hf.to_comp
theorem computable.part {α σ} [primcodable α] [primcodable σ]
{f : α → σ} (hf : computable f) : partrec (f : α →. σ) := hf
theorem computable₂.part {α β σ} [primcodable α] [primcodable β] [primcodable σ]
{f : α → β → σ} (hf : computable₂ f) : partrec₂ (λ a, (f a : β →. σ)) := hf
namespace computable
variables {α : Type*} {β : Type*} {γ : Type*} {σ : Type*}
variables [primcodable α] [primcodable β] [primcodable γ] [primcodable σ]
theorem of_eq {f g : α → σ} (hf : computable f) (H : ∀ n, f n = g n) : computable g :=
(funext H : f = g) ▸ hf
theorem const (s : σ) : computable (λ a : α, s) :=
(primrec.const _).to_comp
theorem of_option {f : α → option β}
(hf : computable f) : partrec (λ a, (f a : roption β)) :=
(nat.partrec.ppred.comp hf).of_eq $ λ n, begin
cases decode α n with a; simp,
cases f a with b; simp
end
theorem to₂ {f : α × β → σ} (hf : computable f) : computable₂ (λ a b, f (a, b)) :=
hf.of_eq $ λ ⟨a, b⟩, rfl
protected theorem id : computable (@id α) := primrec.id.to_comp
theorem fst : computable (@prod.fst α β) := primrec.fst.to_comp
theorem snd : computable (@prod.snd α β) := primrec.snd.to_comp
theorem pair {f : α → β} {g : α → γ}
(hf : computable f) (hg : computable g) : computable (λ a, (f a, g a)) :=
(hf.pair hg).of_eq $
λ n, by cases decode α n; simp [(<*>)]
theorem unpair : computable nat.unpair := primrec.unpair.to_comp
theorem succ : computable nat.succ := primrec.succ.to_comp
theorem pred : computable nat.pred := primrec.pred.to_comp
theorem nat_bodd : computable nat.bodd := primrec.nat_bodd.to_comp
theorem nat_div2 : computable nat.div2 := primrec.nat_div2.to_comp
theorem sum_inl : computable (@sum.inl α β) := primrec.sum_inl.to_comp
theorem sum_inr : computable (@sum.inr α β) := primrec.sum_inr.to_comp
theorem list_cons : computable₂ (@list.cons α) := primrec.list_cons.to_comp
theorem list_reverse : computable (@list.reverse α) := primrec.list_reverse.to_comp
theorem list_nth : computable₂ (@list.nth α) := primrec.list_nth.to_comp
theorem list_append : computable₂ ((++) : list α → list α → list α) := primrec.list_append.to_comp
theorem list_concat : computable₂ (λ l (a:α), l ++ [a]) := primrec.list_concat.to_comp
theorem list_length : computable (@list.length α) := primrec.list_length.to_comp
theorem vector_cons {n} : computable₂ (@vector.cons α n) := primrec.vector_cons.to_comp
theorem vector_to_list {n} : computable (@vector.to_list α n) := primrec.vector_to_list.to_comp
theorem vector_length {n} : computable (@vector.length α n) := primrec.vector_length.to_comp
theorem vector_head {n} : computable (@vector.head α n) := primrec.vector_head.to_comp
theorem vector_tail {n} : computable (@vector.tail α n) := primrec.vector_tail.to_comp
theorem vector_nth {n} : computable₂ (@vector.nth α n) := primrec.vector_nth.to_comp
theorem vector_nth' {n} : computable (@vector.nth α n) := primrec.vector_nth'.to_comp
theorem vector_of_fn' {n} : computable (@vector.of_fn α n) := primrec.vector_of_fn'.to_comp
theorem fin_app {n} : computable₂ (@id (fin n → σ)) := primrec.fin_app.to_comp
protected theorem encode : computable (@encode α _) :=
primrec.encode.to_comp
protected theorem decode : computable (decode α) :=
primrec.decode.to_comp
protected theorem of_nat (α) [denumerable α] : computable (of_nat α) :=
(primrec.of_nat _).to_comp
theorem encode_iff {f : α → σ} : computable (λ a, encode (f a)) ↔ computable f :=
iff.rfl
theorem option_some : computable (@option.some α) :=
primrec.option_some.to_comp
end computable
namespace partrec
variables {α : Type*} {β : Type*} {γ : Type*} {σ : Type*}
variables [primcodable α] [primcodable β] [primcodable γ] [primcodable σ]
open computable
theorem of_eq {f g : α →. σ} (hf : partrec f) (H : ∀ n, f n = g n) : partrec g :=
(funext H : f = g) ▸ hf
theorem of_eq_tot {f : α →. σ} {g : α → σ}
(hf : partrec f) (H : ∀ n, g n ∈ f n) : computable g :=
hf.of_eq (λ a, eq_some_iff.2 (H a))
theorem none : partrec (λ a : α, @roption.none σ) :=
nat.partrec.none.of_eq $ λ n, by cases decode α n; simp
protected theorem some : partrec (@roption.some α) := computable.id
theorem _root_.decidable.partrec.const' (s : roption σ) [decidable s.dom] : partrec (λ a : α, s) :=
(of_option (const (to_option s))).of_eq (λ a, of_to_option s)
theorem const' (s : roption σ) : partrec (λ a : α, s) :=
by haveI := classical.dec s.dom; exact decidable.partrec.const' s
protected theorem bind {f : α →. β} {g : α → β →. σ}
(hf : partrec f) (hg : partrec₂ g) : partrec (λ a, (f a).bind (g a)) :=
(hg.comp (nat.partrec.some.pair hf)).of_eq $
λ n, by simp [(<*>)]; cases e : decode α n with a;
simp [e, encodek]
theorem map {f : α →. β} {g : α → β → σ}
(hf : partrec f) (hg : computable₂ g) : partrec (λ a, (f a).map (g a)) :=
by simpa [bind_some_eq_map] using
@@partrec.bind _ _ _ (λ a b, roption.some (g a b)) hf hg
theorem to₂ {f : α × β →. σ} (hf : partrec f) : partrec₂ (λ a b, f (a, b)) :=
hf.of_eq $ λ ⟨a, b⟩, rfl
theorem nat_elim
{f : α → ℕ} {g : α →. σ} {h : α → ℕ × σ →. σ}
(hf : computable f) (hg : partrec g) (hh : partrec₂ h) :
partrec (λ a, (f a).elim (g a) (λ y IH, IH.bind (λ i, h a (y, i)))) :=
(nat.partrec.prec' hf hg hh).of_eq $ λ n, begin
cases e : decode α n with a; simp [e],
induction f a with m IH; simp,
rw [IH, bind_map],
congr, funext s,
simp [encodek]
end
theorem comp {f : β →. σ} {g : α → β}
(hf : partrec f) (hg : computable g) : partrec (λ a, f (g a)) :=
(hf.comp hg).of_eq $
λ n, by simp; cases e : decode α n with a;
simp [e, encodek]
theorem nat_iff {f : ℕ →. ℕ} : partrec f ↔ nat.partrec f :=
by simp [partrec, map_id']
theorem map_encode_iff {f : α →. σ} : partrec (λ a, (f a).map encode) ↔ partrec f :=
iff.rfl
end partrec
namespace partrec₂
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {σ : Type*}
variables [primcodable α] [primcodable β] [primcodable γ] [primcodable δ] [primcodable σ]
theorem unpaired {f : ℕ → ℕ →. α} : partrec (nat.unpaired f) ↔ partrec₂ f :=
⟨λ h, by simpa using h.comp primrec₂.mkpair.to_comp,
λ h, h.comp primrec.unpair.to_comp⟩
theorem unpaired' {f : ℕ → ℕ →. ℕ} : nat.partrec (nat.unpaired f) ↔ partrec₂ f :=
partrec.nat_iff.symm.trans unpaired
theorem comp
{f : β → γ →. σ} {g : α → β} {h : α → γ}
(hf : partrec₂ f) (hg : computable g) (hh : computable h) :
partrec (λ a, f (g a) (h a)) := hf.comp (hg.pair hh)
theorem comp₂
{f : γ → δ →. σ} {g : α → β → γ} {h : α → β → δ}
(hf : partrec₂ f) (hg : computable₂ g) (hh : computable₂ h) :
partrec₂ (λ a b, f (g a b) (h a b)) := hf.comp hg hh
end partrec₂
namespace computable
variables {α : Type*} {β : Type*} {γ : Type*} {σ : Type*}
variables [primcodable α] [primcodable β] [primcodable γ] [primcodable σ]
theorem comp {f : β → σ} {g : α → β}
(hf : computable f) (hg : computable g) :
computable (λ a, f (g a)) := hf.comp hg
theorem comp₂ {f : γ → σ} {g : α → β → γ}
(hf : computable f) (hg : computable₂ g) :
computable₂ (λ a b, f (g a b)) := hf.comp hg
end computable
namespace computable₂
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {σ : Type*}
variables [primcodable α] [primcodable β] [primcodable γ] [primcodable δ] [primcodable σ]
theorem comp
{f : β → γ → σ} {g : α → β} {h : α → γ}
(hf : computable₂ f) (hg : computable g) (hh : computable h) :
computable (λ a, f (g a) (h a)) := hf.comp (hg.pair hh)
theorem comp₂
{f : γ → δ → σ} {g : α → β → γ} {h : α → β → δ}
(hf : computable₂ f) (hg : computable₂ g) (hh : computable₂ h) :
computable₂ (λ a b, f (g a b) (h a b)) := hf.comp hg hh
end computable₂
namespace partrec
variables {α : Type*} {β : Type*} {γ : Type*} {σ : Type*}
variables [primcodable α] [primcodable β] [primcodable γ] [primcodable σ]
open computable
theorem rfind {p : α → ℕ →. bool} (hp : partrec₂ p) :
partrec (λ a, nat.rfind (p a)) :=
(nat.partrec.rfind $ hp.map
((primrec.dom_bool (λ b, cond b 0 1))
.comp primrec.snd).to₂.to_comp).of_eq $
λ n, begin
cases e : decode α n with a;
simp [e, nat.rfind_zero_none, map_id'],
congr, funext n,
simp [roption.map_map, (∘)],
apply map_id' (λ b, _),
cases b; refl
end
theorem rfind_opt {f : α → ℕ → option σ} (hf : computable₂ f) :
partrec (λ a, nat.rfind_opt (f a)) :=
(rfind (primrec.option_is_some.to_comp.comp hf).part.to₂).bind
(of_option hf)
theorem nat_cases_right
{f : α → ℕ} {g : α → σ} {h : α → ℕ →. σ}
(hf : computable f) (hg : computable g) (hh : partrec₂ h) :
partrec (λ a, (f a).cases (some (g a)) (h a)) :=
(nat_elim hf hg (hh.comp fst (pred.comp $ hf.comp fst)).to₂).of_eq $
λ a, begin
simp, cases f a; simp,
refine ext (λ b, ⟨λ H, _, λ H, _⟩),
{ rcases mem_bind_iff.1 H with ⟨c, h₁, h₂⟩, exact h₂ },
{ have : ∀ m, (nat.elim (roption.some (g a))
(λ y IH, IH.bind (λ _, h a n)) m).dom,
{ intro, induction m; simp [*, H.fst] },
exact ⟨⟨this n, H.fst⟩, H.snd⟩ }
end
theorem bind_decode₂_iff {f : α →. σ} : partrec f ↔
nat.partrec (λ n, roption.bind (decode₂ α n) (λ a, (f a).map encode)) :=
⟨λ hf, nat_iff.1 $ (of_option primrec.decode₂.to_comp).bind $
(map hf (computable.encode.comp snd).to₂).comp snd,
λ h, map_encode_iff.1 $ by simpa [encodek₂]
using (nat_iff.2 h).comp (@computable.encode α _)⟩
theorem vector_m_of_fn : ∀ {n} {f : fin n → α →. σ}, (∀ i, partrec (f i)) →
partrec (λ (a : α), vector.m_of_fn (λ i, f i a))
| 0 f hf := const _
| (n+1) f hf := by simp [vector.m_of_fn]; exact
(hf 0).bind (partrec.bind ((vector_m_of_fn (λ i, hf i.succ)).comp fst)
(primrec.vector_cons.to_comp.comp (snd.comp fst) snd))
end partrec
@[simp] theorem vector.m_of_fn_roption_some {α n} : ∀ (f : fin n → α),
vector.m_of_fn (λ i, roption.some (f i)) = roption.some (vector.of_fn f) :=
vector.m_of_fn_pure
namespace computable
variables {α : Type*} {β : Type*} {γ : Type*} {σ : Type*}
variables [primcodable α] [primcodable β] [primcodable γ] [primcodable σ]
theorem option_some_iff {f : α → σ} : computable (λ a, some (f a)) ↔ computable f :=
⟨λ h, encode_iff.1 $ primrec.pred.to_comp.comp $ encode_iff.2 h,
option_some.comp⟩
theorem bind_decode_iff {f : α → β → option σ} : computable₂ (λ a n,
(decode β n).bind (f a)) ↔ computable₂ f :=
⟨λ hf, nat.partrec.of_eq
(((partrec.nat_iff.2 (nat.partrec.ppred.comp $
nat.partrec.of_primrec $ primcodable.prim β)).comp snd).bind
(computable.comp hf fst).to₂.part) $
λ n, by simp;
cases decode α n.unpair.1; simp;
cases decode β n.unpair.2; simp,
λ hf, begin
have : partrec (λ a : α × ℕ, (encode (decode β a.2)).cases
(some option.none) (λ n, roption.map (f a.1) (decode β n))) :=
partrec.nat_cases_right (primrec.encdec.to_comp.comp snd)
(const none) ((of_option (computable.decode.comp snd)).map
(hf.comp (fst.comp $ fst.comp fst) snd).to₂),
refine this.of_eq (λ a, _),
simp, cases decode β a.2; simp [encodek]
end⟩
theorem map_decode_iff {f : α → β → σ} : computable₂ (λ a n,
(decode β n).map (f a)) ↔ computable₂ f :=
bind_decode_iff.trans option_some_iff
theorem nat_elim
{f : α → ℕ} {g : α → σ} {h : α → ℕ × σ → σ}
(hf : computable f) (hg : computable g) (hh : computable₂ h) :
computable (λ a, (f a).elim (g a) (λ y IH, h a (y, IH))) :=
(partrec.nat_elim hf hg hh.part).of_eq $
λ a, by simp; induction f a; simp *
theorem nat_cases {f : α → ℕ} {g : α → σ} {h : α → ℕ → σ}
(hf : computable f) (hg : computable g) (hh : computable₂ h) :
computable (λ a, (f a).cases (g a) (h a)) :=
nat_elim hf hg (hh.comp fst $ fst.comp snd).to₂
theorem cond {c : α → bool} {f : α → σ} {g : α → σ}
(hc : computable c) (hf : computable f) (hg : computable g) :
computable (λ a, cond (c a) (f a) (g a)) :=
(nat_cases (encode_iff.2 hc) hg (hf.comp fst).to₂).of_eq $
λ a, by cases c a; refl
theorem option_cases {o : α → option β} {f : α → σ} {g : α → β → σ}
(ho : computable o) (hf : computable f) (hg : computable₂ g) :
@computable _ σ _ _ (λ a, option.cases_on (o a) (f a) (g a)) :=
option_some_iff.1 $
(nat_cases (encode_iff.2 ho) (option_some_iff.2 hf)
(map_decode_iff.2 hg)).of_eq $
λ a, by cases o a; simp [encodek]; refl
theorem option_bind {f : α → option β} {g : α → β → option σ}
(hf : computable f) (hg : computable₂ g) :
computable (λ a, (f a).bind (g a)) :=
(option_cases hf (const option.none) hg).of_eq $
λ a, by cases f a; refl
theorem option_map {f : α → option β} {g : α → β → σ}
(hf : computable f) (hg : computable₂ g) : computable (λ a, (f a).map (g a)) :=
option_bind hf (option_some.comp₂ hg)
theorem option_get_or_else {f : α → option β} {g : α → β}
(hf : computable f) (hg : computable g) :
computable (λ a, (f a).get_or_else (g a)) :=
(computable.option_cases hf hg (show computable₂ (λ a b, b), from computable.snd)).of_eq $
λ a, by cases f a; refl
theorem subtype_mk {f : α → β} {p : β → Prop} [decidable_pred p] {h : ∀ a, p (f a)}
(hp : primrec_pred p) (hf : computable f) :
@computable _ _ _ (primcodable.subtype hp) (λ a, (⟨f a, h a⟩ : subtype p)) :=
hf
theorem sum_cases
{f : α → β ⊕ γ} {g : α → β → σ} {h : α → γ → σ}
(hf : computable f) (hg : computable₂ g) (hh : computable₂ h) :
@computable _ σ _ _ (λ a, sum.cases_on (f a) (g a) (h a)) :=
option_some_iff.1 $
(cond (nat_bodd.comp $ encode_iff.2 hf)
(option_map (computable.decode.comp $ nat_div2.comp $ encode_iff.2 hf) hh)
(option_map (computable.decode.comp $ nat_div2.comp $ encode_iff.2 hf) hg)).of_eq $
λ a, by cases f a with b c;
simp [nat.div2_bit, nat.bodd_bit, encodek]; refl
theorem nat_strong_rec
(f : α → ℕ → σ) {g : α → list σ → option σ} (hg : computable₂ g)
(H : ∀ a n, g a ((list.range n).map (f a)) = some (f a n)) : computable₂ f :=
suffices computable₂ (λ a n, (list.range n).map (f a)), from
option_some_iff.1 $
(list_nth.comp (this.comp fst (succ.comp snd)) snd).to₂.of_eq $
λ a, by simp [list.nth_range (nat.lt_succ_self a.2)]; refl,
option_some_iff.1 $
(nat_elim snd (const (option.some [])) (to₂ $
option_bind (snd.comp snd) $ to₂ $
option_map
(hg.comp (fst.comp $ fst.comp fst) snd)
(to₂ $ list_concat.comp (snd.comp fst) snd))).of_eq $
λ a, begin
simp, induction a.2 with n IH, {refl},
simp [IH, H, list.range_succ]
end
theorem list_of_fn : ∀ {n} {f : fin n → α → σ},
(∀ i, computable (f i)) → computable (λ a, list.of_fn (λ i, f i a))
| 0 f hf := const []
| (n+1) f hf := by simp [list.of_fn_succ]; exact
list_cons.comp (hf 0) (list_of_fn (λ i, hf i.succ))
theorem vector_of_fn {n} {f : fin n → α → σ}
(hf : ∀ i, computable (f i)) : computable (λ a, vector.of_fn (λ i, f i a)) :=
(partrec.vector_m_of_fn hf).of_eq $ λ a, by simp
end computable
namespace partrec
variables {α : Type*} {β : Type*} {γ : Type*} {σ : Type*}
variables [primcodable α] [primcodable β] [primcodable γ] [primcodable σ]
open computable
theorem option_some_iff {f : α →. σ} :
partrec (λ a, (f a).map option.some) ↔ partrec f :=
⟨λ h, (nat.partrec.ppred.comp h).of_eq $
λ n, by simp [roption.bind_assoc, bind_some_eq_map],
λ hf, hf.map (option_some.comp snd).to₂⟩
theorem option_cases_right {o : α → option β} {f : α → σ} {g : α → β →. σ}
(ho : computable o) (hf : computable f) (hg : partrec₂ g) :
@partrec _ σ _ _ (λ a, option.cases_on (o a) (some (f a)) (g a)) :=
have partrec (λ (a : α), nat.cases (roption.some (f a))
(λ n, roption.bind (decode β n) (g a)) (encode (o a))) :=
nat_cases_right (encode_iff.2 ho) hf.part $
((@computable.decode β _).comp snd).of_option.bind
(hg.comp (fst.comp fst) snd).to₂,
this.of_eq $ λ a, by cases o a with b; simp [encodek]
theorem sum_cases_right {f : α → β ⊕ γ} {g : α → β → σ} {h : α → γ →. σ}
(hf : computable f) (hg : computable₂ g) (hh : partrec₂ h) :
@partrec _ σ _ _ (λ a, sum.cases_on (f a) (λ b, some (g a b)) (h a)) :=
have partrec (λ a, (option.cases_on
(sum.cases_on (f a) (λ b, option.none) option.some : option γ)
(some (sum.cases_on (f a) (λ b, some (g a b))
(λ c, option.none)))
(λ c, (h a c).map option.some) : roption (option σ))) :=
option_cases_right
(sum_cases hf (const option.none).to₂ (option_some.comp snd).to₂)
(sum_cases hf (option_some.comp hg) (const option.none).to₂)
(option_some_iff.2 hh),
option_some_iff.1 $ this.of_eq $ λ a, by cases f a; simp
theorem sum_cases_left {f : α → β ⊕ γ} {g : α → β →. σ} {h : α → γ → σ}
(hf : computable f) (hg : partrec₂ g) (hh : computable₂ h) :
@partrec _ σ _ _ (λ a, sum.cases_on (f a) (g a) (λ c, some (h a c))) :=
(sum_cases_right (sum_cases hf
(sum_inr.comp snd).to₂ (sum_inl.comp snd).to₂) hh hg).of_eq $
λ a, by cases f a; simp
lemma fix_aux {α σ} (f : α →. σ ⊕ α) (a : α) (b : σ) :
let F : α → ℕ →. σ ⊕ α := λ a n,
n.elim (some (sum.inr a)) $ λ y IH, IH.bind $ λ s,
sum.cases_on s (λ _, roption.some s) f in
(∃ (n : ℕ), ((∃ (b' : σ), sum.inl b' ∈ F a n) ∧
∀ {m : ℕ}, m < n → (∃ (b : α), sum.inr b ∈ F a m)) ∧
sum.inl b ∈ F a n) ↔ b ∈ pfun.fix f a :=
begin
intro, refine ⟨λ h, _, λ h, _⟩,
{ rcases h with ⟨n, ⟨_x, h₁⟩, h₂⟩,
have : ∀ m a' (_: sum.inr a' ∈ F a m)
(_: b ∈ pfun.fix f a'), b ∈ pfun.fix f a,
{ intros m a' am ba,
induction m with m IH generalizing a'; simp [F] at am,
{ rwa ← am },
rcases am with ⟨a₂, am₂, fa₂⟩,
exact IH _ am₂ (pfun.mem_fix_iff.2 (or.inr ⟨_, fa₂, ba⟩)) },
cases n; simp [F] at h₂, {cases h₂},
rcases h₂ with h₂ | ⟨a', am', fa'⟩,
{ cases h₁ (nat.lt_succ_self _) with a' h,
injection mem_unique h h₂ },
{ exact this _ _ am' (pfun.mem_fix_iff.2 (or.inl fa')) } },
{ suffices : ∀ a' (_: b ∈ pfun.fix f a') k (_: sum.inr a' ∈ F a k),
∃ n, sum.inl b ∈ F a n ∧
∀ (m < n) (_ : k ≤ m), ∃ a₂, sum.inr a₂ ∈ F a m,
{ rcases this _ h 0 (by simp [F]) with ⟨n, hn₁, hn₂⟩,
exact ⟨_, ⟨⟨_, hn₁⟩, λ m mn, hn₂ m mn (nat.zero_le _)⟩, hn₁⟩ },
intros a₁ h₁,
apply pfun.fix_induction h₁, intros a₂ h₂ IH k hk,
rcases pfun.mem_fix_iff.1 h₂ with h₂ | ⟨a₃, am₃, fa₃⟩,
{ refine ⟨k.succ, _, λ m mk km, ⟨a₂, _⟩⟩,
{ simp [F], exact or.inr ⟨_, hk, h₂⟩ },
{ rwa le_antisymm (nat.le_of_lt_succ mk) km } },
{ rcases IH _ fa₃ am₃ k.succ _ with ⟨n, hn₁, hn₂⟩,
{ refine ⟨n, hn₁, λ m mn km, _⟩,
cases km.lt_or_eq_dec with km km,
{ exact hn₂ _ mn km },
{ exact km ▸ ⟨_, hk⟩ } },
{ simp [F], exact ⟨_, hk, am₃⟩ } } }
end
theorem fix {f : α →. σ ⊕ α} (hf : partrec f) : partrec (pfun.fix f) :=
let F : α → ℕ →. σ ⊕ α := λ a n,
n.elim (some (sum.inr a)) $ λ y IH, IH.bind $ λ s,
sum.cases_on s (λ _, roption.some s) f in
have hF : partrec₂ F :=
partrec.nat_elim snd (sum_inr.comp fst).part
(sum_cases_right (snd.comp snd)
(snd.comp $ snd.comp fst).to₂
(hf.comp snd).to₂).to₂,
let p := λ a n, @roption.map _ bool
(λ s, sum.cases_on s (λ_, tt) (λ _, ff)) (F a n) in
have hp : partrec₂ p := hF.map ((sum_cases computable.id
(const tt).to₂ (const ff).to₂).comp snd).to₂,
(hp.rfind.bind (hF.bind
(sum_cases_right snd snd.to₂ none.to₂).to₂).to₂).of_eq $
λ a, ext $ λ b, by simp; apply fix_aux f
end partrec
|
240d216671c5de8791a2cfbd6314722fa5a1198f | 7b681d6cc18477cf6b60470d9782923d3ea63915 | /W3-Inductive.lean | d0974af1ae4a17ccb49e8f0e108d85804b4593f0 | [] | no_license | osoulim/LEAN | a7458f597abbe5c36ebbb3f36eab29a4c60f5140 | 5e0dc240e86e392fdab4b2ffdcc3174c0cce7b66 | refs/heads/master | 1,591,850,481,195 | 1,561,547,647,000 | 1,561,547,647,000 | 193,852,039 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 470 | lean | inductive List (α : Type) : Type
| nil : List
| cons : α -> List -> List
notation `[]` := List.nil _
notation a ` :: ` l := List.cons a l
def map {α β} ( f: α -> β ) : List α -> List β
| [] := []
| (a :: l) := f a :: map l
def length {α} : List α -> ℕ
| [] := 0
| (a :: l) := length l + 1
inductive Props: Type
| atom : Props
| and : Props -> Props -> Props
| or : Props -> Props -> Props
| arrow: Props -> Props -> Props
| not: Props -> Props
|
3b807d1b5117bc1cd6819891850bbf9341a0368c | b0d97c09d47e3b0a68128c64cad26ab132d23108 | /src/analytic.lean | a2a96e356394a797c4061375a7682f06f51b62c7 | [] | no_license | jmvlangen/RIP-seminar | 2ad32c1c6fceb59ac7ae3b2251baf08f4c0c0caa | ed6771404dd4bcec298de2dfdc89d5e9cfd331bb | refs/heads/master | 1,585,865,817,237 | 1,546,865,823,000 | 1,546,865,823,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,656 | lean | import algebra.field algebra.ring
import analysis.normed_space analysis.ennreal
import analysis.topology.infinite_sum
import analysis.complex
/--
- A formal power series over a ring R is a formal expression of the form
-
- ∑ᵢ aᵢ zⁱ
-
- where i ∈ ℕ and aᵢ ∈ R. Thus, the data necessary to specify a formal power
- series is a sequence in R. The point of writing them as series is that this
- specifies natural operations on them.
-/
def formal_power_series (R : Type*) : Type* := ℕ → R
namespace formal_power_series
-- TODO: introduce some notation, figure out how to avoid conflicts with notation for
-- infinite sums and convergent power series.
/--
- Just like for polynomials, it is easy to define a 'formal derivative' for
- formal power series.
-/
def formal_derivative {R : Type*} [ring R] : formal_power_series R → formal_power_series R := sorry
variable {R : Type*}
variables [normed_ring R]
open lattice topological_space
/--
- A predicate that indicates if the formal power series s converges at a point x ∈ R.
-/
def converges_at_to (s : formal_power_series R) (x : R) (y : R) : Prop :=
is_sum (λ n : ℕ , s n * x ^ n) y -- is_sum means absolute convergence of the series at x
def converges_to_at (s : formal_power_series R) (y : R) (x : R) : Prop :=
is_sum (λ n : ℕ , s n * x ^ n) y -- is_sum means absolute convergence of the series at x
def converges_at (s : formal_power_series R) (x : R) : Prop :=
has_sum (λ n : ℕ , s n * x ^ n) -- has_sum means absolute convergence of the series at x
/--
- The supremum of {r : ℝ | ∀ x, ∥x∥ < r → converges s x}.
-/
noncomputable def convergence_radius (s : formal_power_series R) (x₀ : R) : ennreal :=
Sup {r : ennreal | ∀ x : R, ↑(nnnorm (x - x₀)) < r → converges_at (x - x₀) s}
/--
- A power series is the function associated with a formal power series by taking infinite sums. I may or may not converge.
-/
noncomputable def at_point (s : formal_power_series R) (x : R) :=
∑ n : ℕ , s n * x ^ n
-- noncomputable instance : has_coe_to_fun (formal_power_series R) :=
-- ⟨λ _, R → R,
-- λ s x, s.at_point x⟩
end formal_power_series
variable {R : Type*}
variables [normed_ring R]
open lattice topological_space
/--
- A function f defined on an open subset of R is analytic if it can
- locally be written as a convergent power series.
-
- This definition is not done yet.
-/
def is_analytic_at (x₀ : R) (f : R → R) : Prop :=
∃ (s : formal_power_series R) (r > 0), ∀ x : R, norm(x - x₀) < r → s.converges_at_to (x - x₀) (f x)
#print is_analytic_at.
def is_analytic_on (U : set R) (f : R → R) : Prop :=
∀ x ∈ U, is_analytic_at x f
-- class is_analytic (U : opens R) (f : U → R) : Prop :=
-- (prop : ∀ x ∈ U, ∃ (s : formal_power_series R) (x₀ : R), convergence_radius s x₀ > 0 ∧ ↑(nnnorm (x - x₀)) < convergence_radius s x₀ ∧ some (f ⟨x, ‹x ∈ U›⟩) = power_series s (x - x₀) )
structure analytic_function (U : opens R) :=
(to_fun : U → R)
(is_analytic := is_analytic U to_fun)
/--
- An analytic function on U can be coerced to a function U → R.
-/
instance (U : opens R) : has_coe_to_fun $ analytic_function U := ⟨λ _, U → R, λ f, f.to_fun⟩
/--
- The formal derivative on formal power series restricts and corestricts
- to convergent power series, hence it is defined for analytic functions.
-/
def derivative (U : opens ℝ) : analytic_function U → analytic_function U := sorry
instance : normed_field ℂ := sorry
theorem one_div_z_analytic : is_analytic ⟨{z : ℂ | z ≠ 0}, sorry⟩ (λ z, (1:ℂ)/z) := sorry
|
a4804ec7ee7bc2021402e30d8d0aacec31b20538 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/topology/metric_space/infsep.lean | 3de55c17a31e9efadb96ceb708a7f589df823a59 | [
"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 | 19,165 | lean | /-
Copyright (c) 2022 Wrenna Robson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Wrenna Robson
-/
import topology.metric_space.basic
/-!
# Infimum separation
This file defines the extended infimum separation of a set. This is approximately dual to the
diameter of a set, but where the extended diameter of a set is the supremum of the extended distance
between elements of the set, the extended infimum separation is the infimum of the (extended)
distance between *distinct* elements in the set.
We also define the infimum separation as the cast of the extended infimum separation to the reals.
This is the infimum of the distance between distinct elements of the set when in a pseudometric
space.
All lemmas and definitions are in the `set` namespace to give access to dot notation.
## Main definitions
* `set.einfsep`: Extended infimum separation of a set.
* `set.infsep`: Infimum separation of a set (when in a pseudometric space).
!-/
variables {α β : Type*}
namespace set
section einfsep
open_locale ennreal
open function
/-- The "extended infimum separation" of a set with an edist function. -/
noncomputable def einfsep [has_edist α] (s : set α) : ℝ≥0∞ :=
⨅ (x ∈ s) (y ∈ s) (hxy : x ≠ y), edist x y
section has_edist
variables [has_edist α] {x y : α} {s t : set α}
lemma le_einfsep_iff {d} : d ≤ s.einfsep ↔ ∀ (x y ∈ s) (hxy : x ≠ y), d ≤ edist x y :=
by simp_rw [einfsep, le_infi_iff]
theorem einfsep_zero :
s.einfsep = 0 ↔ ∀ C (hC : 0 < C), ∃ (x y ∈ s) (hxy : x ≠ y), edist x y < C :=
by simp_rw [einfsep, ← bot_eq_zero, infi_eq_bot, infi_lt_iff]
theorem einfsep_pos :
0 < s.einfsep ↔ ∃ C (hC : 0 < C), ∀ (x y ∈ s) (hxy : x ≠ y), C ≤ edist x y :=
by { rw [pos_iff_ne_zero, ne.def, einfsep_zero], simp only [not_forall, not_exists, not_lt] }
lemma einfsep_top : s.einfsep = ∞ ↔ ∀ (x y ∈ s) (hxy : x ≠ y), edist x y = ∞ :=
by simp_rw [einfsep, infi_eq_top]
lemma einfsep_lt_top : s.einfsep < ∞ ↔ ∃ (x y ∈ s) (hxy : x ≠ y), edist x y < ∞ :=
by simp_rw [einfsep, infi_lt_iff]
lemma einfsep_ne_top : s.einfsep ≠ ∞ ↔ ∃ (x y ∈ s) (hxy : x ≠ y), edist x y ≠ ∞ :=
by simp_rw [←lt_top_iff_ne_top, einfsep_lt_top]
lemma einfsep_lt_iff {d} : s.einfsep < d ↔ ∃ (x y ∈ s) (h : x ≠ y), edist x y < d :=
by simp_rw [einfsep, infi_lt_iff]
lemma nontrivial_of_einfsep_lt_top (hs : s.einfsep < ∞) : s.nontrivial :=
by { rcases einfsep_lt_top.1 hs with ⟨_, hx, _, hy, hxy, _⟩, exact ⟨_, hx, _, hy, hxy⟩ }
lemma nontrivial_of_einfsep_ne_top (hs : s.einfsep ≠ ∞) : s.nontrivial :=
nontrivial_of_einfsep_lt_top (lt_top_iff_ne_top.mpr hs)
lemma subsingleton.einfsep (hs : s.subsingleton) : s.einfsep = ∞ :=
by { rw einfsep_top, exact λ _ hx _ hy hxy, (hxy $ hs hx hy).elim }
lemma le_einfsep_image_iff {d} {f : β → α} {s : set β} :
d ≤ einfsep (f '' s) ↔ ∀ x y ∈ s, f x ≠ f y → d ≤ edist (f x) (f y) :=
by simp_rw [le_einfsep_iff, ball_image_iff]
lemma le_edist_of_le_einfsep {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y)
(hd : d ≤ s.einfsep) : d ≤ edist x y := le_einfsep_iff.1 hd x hx y hy hxy
lemma einfsep_le_edist_of_mem {x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y) :
s.einfsep ≤ edist x y := le_edist_of_le_einfsep hx hy hxy le_rfl
lemma einfsep_le_of_mem_of_edist_le {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y)
(hxy' : edist x y ≤ d) : s.einfsep ≤ d := le_trans (einfsep_le_edist_of_mem hx hy hxy) hxy'
lemma le_einfsep {d} (h : ∀ (x y ∈ s) (hxy : x ≠ y), d ≤ edist x y) :
d ≤ s.einfsep := le_einfsep_iff.2 h
@[simp] lemma einfsep_empty : (∅ : set α).einfsep = ∞ := subsingleton_empty.einfsep
@[simp] lemma einfsep_singleton : ({x} : set α).einfsep = ∞ := subsingleton_singleton.einfsep
lemma einfsep_Union_mem_option {ι : Type*} (o : option ι) (s : ι → set α) :
(⋃ i ∈ o, s i).einfsep = ⨅ i ∈ o, (s i).einfsep := by cases o; simp
lemma einfsep_anti (hst : s ⊆ t) : t.einfsep ≤ s.einfsep :=
le_einfsep $ λ x hx y hy, einfsep_le_edist_of_mem (hst hx) (hst hy)
lemma einfsep_insert_le : (insert x s).einfsep ≤ ⨅ (y ∈ s) (hxy : x ≠ y), edist x y :=
begin
simp_rw le_infi_iff,
refine λ _ hy hxy, einfsep_le_edist_of_mem (mem_insert _ _) (mem_insert_of_mem _ hy) hxy
end
lemma le_einfsep_pair : edist x y ⊓ edist y x ≤ ({x, y} : set α).einfsep :=
begin
simp_rw [le_einfsep_iff, inf_le_iff, mem_insert_iff, mem_singleton_iff],
rintros a (rfl | rfl) b (rfl | rfl) hab; finish
end
lemma einfsep_pair_le_left (hxy : x ≠ y) : ({x, y} : set α).einfsep ≤ edist x y :=
einfsep_le_edist_of_mem (mem_insert _ _) (mem_insert_of_mem _ (mem_singleton _)) hxy
lemma einfsep_pair_le_right (hxy : x ≠ y) : ({x, y} : set α).einfsep ≤ edist y x :=
by rw pair_comm; exact einfsep_pair_le_left hxy.symm
lemma einfsep_pair_eq_inf (hxy : x ≠ y) : ({x, y} : set α).einfsep = (edist x y) ⊓ (edist y x) :=
le_antisymm (le_inf (einfsep_pair_le_left hxy) (einfsep_pair_le_right hxy)) le_einfsep_pair
lemma einfsep_eq_infi : s.einfsep = ⨅ d : s.off_diag, (uncurry edist) (d : α × α) :=
begin
refine eq_of_forall_le_iff (λ _, _),
simp_rw [le_einfsep_iff, le_infi_iff, imp_forall_iff, set_coe.forall, subtype.coe_mk,
mem_off_diag, prod.forall, uncurry_apply_pair, and_imp]
end
lemma einfsep_of_fintype [decidable_eq α] [fintype s] :
s.einfsep = s.off_diag.to_finset.inf (uncurry edist) :=
begin
refine eq_of_forall_le_iff (λ _, _),
simp_rw [le_einfsep_iff, imp_forall_iff, finset.le_inf_iff, mem_to_finset, mem_off_diag,
prod.forall, uncurry_apply_pair, and_imp]
end
lemma finite.einfsep (hs : s.finite) :
s.einfsep = hs.off_diag.to_finset.inf (uncurry edist) :=
begin
refine eq_of_forall_le_iff (λ _, _),
simp_rw [le_einfsep_iff, imp_forall_iff, finset.le_inf_iff, finite.mem_to_finset, mem_off_diag,
prod.forall, uncurry_apply_pair, and_imp]
end
lemma finset.coe_einfsep [decidable_eq α] {s : finset α} :
(s : set α).einfsep = s.off_diag.inf (uncurry edist) :=
by simp_rw [einfsep_of_fintype, ← finset.coe_off_diag, finset.to_finset_coe]
lemma nontrivial.einfsep_exists_of_finite [finite s] (hs : s.nontrivial) :
∃ (x y ∈ s) (hxy : x ≠ y), s.einfsep = edist x y :=
begin
classical,
casesI nonempty_fintype s,
simp_rw einfsep_of_fintype,
rcases @finset.exists_mem_eq_inf _ _ _ _ (s.off_diag.to_finset) (by simpa) (uncurry edist)
with ⟨_, hxy, hed⟩,
simp_rw mem_to_finset at hxy,
refine ⟨w.fst, hxy.1, w.snd, hxy.2.1, hxy.2.2, hed⟩
end
lemma finite.einfsep_exists_of_nontrivial (hsf : s.finite) (hs : s.nontrivial) :
∃ (x y ∈ s) (hxy : x ≠ y), s.einfsep = edist x y :=
by { letI := hsf.fintype, exact hs.einfsep_exists_of_finite }
end has_edist
section pseudo_emetric_space
variables [pseudo_emetric_space α] {x y z : α} {s t : set α}
lemma einfsep_pair (hxy : x ≠ y) : ({x, y} : set α).einfsep = edist x y :=
begin
nth_rewrite 0 [← min_self (edist x y)],
convert einfsep_pair_eq_inf hxy using 2,
rw edist_comm
end
lemma einfsep_insert :
einfsep (insert x s) = (⨅ (y ∈ s) (hxy : x ≠ y), edist x y) ⊓ (s.einfsep) :=
begin
refine le_antisymm (le_min einfsep_insert_le (einfsep_anti (subset_insert _ _))) _,
simp_rw [le_einfsep_iff, inf_le_iff, mem_insert_iff],
rintros y (rfl | hy) z (rfl | hz) hyz,
{ exact false.elim (hyz rfl) },
{ exact or.inl (infi_le_of_le _ (infi₂_le hz hyz)) },
{ rw edist_comm, exact or.inl (infi_le_of_le _ (infi₂_le hy hyz.symm)) },
{ exact or.inr (einfsep_le_edist_of_mem hy hz hyz) }
end
lemma einfsep_triple (hxy : x ≠ y) (hyz : y ≠ z) (hxz : x ≠ z) :
einfsep ({x, y, z} : set α) = edist x y ⊓ edist x z ⊓ edist y z :=
by simp_rw [einfsep_insert, infi_insert, infi_singleton, einfsep_singleton,
inf_top_eq, cinfi_pos hxy, cinfi_pos hyz, cinfi_pos hxz]
lemma le_einfsep_pi_of_le {π : β → Type*} [fintype β] [∀ b, pseudo_emetric_space (π b)]
{s : Π (b : β), set (π b)} {c : ℝ≥0∞} (h : ∀ b, c ≤ einfsep (s b) ) :
c ≤ einfsep (set.pi univ s) :=
begin
refine le_einfsep (λ x hx y hy hxy, _),
rw mem_univ_pi at hx hy,
rcases function.ne_iff.mp hxy with ⟨i, hi⟩,
exact le_trans (le_einfsep_iff.1 (h i) _ (hx _) _ (hy _) hi) (edist_le_pi_edist _ _ i)
end
end pseudo_emetric_space
section pseudo_metric_space
variables [pseudo_metric_space α] {s : set α}
theorem subsingleton_of_einfsep_eq_top (hs : s.einfsep = ∞) : s.subsingleton :=
begin
rw einfsep_top at hs,
exact λ _ hx _ hy, of_not_not (λ hxy, edist_ne_top _ _ (hs _ hx _ hy hxy))
end
theorem einfsep_eq_top_iff : s.einfsep = ∞ ↔ s.subsingleton :=
⟨subsingleton_of_einfsep_eq_top, subsingleton.einfsep⟩
theorem nontrivial.einfsep_ne_top (hs : s.nontrivial) : s.einfsep ≠ ∞ :=
by { contrapose! hs, rw not_nontrivial_iff, exact subsingleton_of_einfsep_eq_top hs }
theorem nontrivial.einfsep_lt_top (hs : s.nontrivial) : s.einfsep < ∞ :=
by { rw lt_top_iff_ne_top, exact hs.einfsep_ne_top }
theorem einfsep_lt_top_iff : s.einfsep < ∞ ↔ s.nontrivial :=
⟨nontrivial_of_einfsep_lt_top, nontrivial.einfsep_lt_top⟩
theorem einfsep_ne_top_iff : s.einfsep ≠ ∞ ↔ s.nontrivial :=
⟨nontrivial_of_einfsep_ne_top, nontrivial.einfsep_ne_top⟩
lemma le_einfsep_of_forall_dist_le {d} (h : ∀ (x y ∈ s) (hxy : x ≠ y), d ≤ dist x y) :
ennreal.of_real d ≤ s.einfsep :=
le_einfsep $
λ x hx y hy hxy, (edist_dist x y).symm ▸ ennreal.of_real_le_of_real (h x hx y hy hxy)
end pseudo_metric_space
section emetric_space
variables [emetric_space α] {x y z : α} {s t : set α} {C : ℝ≥0∞} {sC : set ℝ≥0∞}
lemma einfsep_pos_of_finite [finite s] : 0 < s.einfsep :=
begin
casesI nonempty_fintype s,
by_cases hs : s.nontrivial,
{ rcases hs.einfsep_exists_of_finite with ⟨x, hx, y, hy, hxy, hxy'⟩,
exact hxy'.symm ▸ edist_pos.2 hxy },
{ rw not_nontrivial_iff at hs,
exact hs.einfsep.symm ▸ with_top.zero_lt_top }
end
lemma relatively_discrete_of_finite [finite s] :
∃ C (hC : 0 < C), ∀ (x y ∈ s) (hxy : x ≠ y), C ≤ edist x y :=
by { rw ← einfsep_pos, exact einfsep_pos_of_finite }
lemma finite.einfsep_pos (hs : s.finite) : 0 < s.einfsep :=
by { letI := hs.fintype, exact einfsep_pos_of_finite }
lemma finite.relatively_discrete (hs : s.finite) :
∃ C (hC : 0 < C), ∀ (x y ∈ s) (hxy : x ≠ y), C ≤ edist x y :=
by { letI := hs.fintype, exact relatively_discrete_of_finite }
end emetric_space
end einfsep
section infsep
open_locale ennreal
open set function
/-- The "infimum separation" of a set with an edist function. -/
noncomputable def infsep [has_edist α] (s : set α) : ℝ := ennreal.to_real (s.einfsep)
section has_edist
variables [has_edist α] {x y : α} {s : set α}
lemma infsep_zero : s.infsep = 0 ↔ s.einfsep = 0 ∨ s.einfsep = ∞ :=
by rw [infsep, ennreal.to_real_eq_zero_iff]
lemma infsep_nonneg : 0 ≤ s.infsep := ennreal.to_real_nonneg
lemma infsep_pos : 0 < s.infsep ↔ 0 < s.einfsep ∧ s.einfsep < ∞ :=
by simp_rw [infsep, ennreal.to_real_pos_iff]
lemma subsingleton.infsep_zero (hs : s.subsingleton) : s.infsep = 0 :=
by { rw [infsep_zero, hs.einfsep], right, refl }
lemma nontrivial_of_infsep_pos (hs : 0 < s.infsep) : s.nontrivial :=
by { contrapose hs, rw not_nontrivial_iff at hs, exact hs.infsep_zero ▸ lt_irrefl _ }
lemma infsep_empty : (∅ : set α).infsep = 0 :=
subsingleton_empty.infsep_zero
lemma infsep_singleton : ({x} : set α).infsep = 0 :=
subsingleton_singleton.infsep_zero
lemma infsep_pair_le_to_real_inf (hxy : x ≠ y) :
({x, y} : set α).infsep ≤ (edist x y ⊓ edist y x).to_real :=
by simp_rw [infsep, einfsep_pair_eq_inf hxy]
end has_edist
section pseudo_emetric_space
variables [pseudo_emetric_space α] {x y : α} {s : set α}
lemma infsep_pair_eq_to_real : ({x, y} : set α).infsep = (edist x y).to_real :=
begin
by_cases hxy : x = y,
{ rw hxy, simp only [infsep_singleton, pair_eq_singleton, edist_self, ennreal.zero_to_real] },
{ rw [infsep, einfsep_pair hxy] }
end
end pseudo_emetric_space
section pseudo_metric_space
variables [pseudo_metric_space α] {x y z: α} {s t : set α}
lemma nontrivial.le_infsep_iff {d} (hs : s.nontrivial) :
d ≤ s.infsep ↔ ∀ (x y ∈ s) (hxy : x ≠ y), d ≤ dist x y :=
by simp_rw [infsep, ← ennreal.of_real_le_iff_le_to_real (hs.einfsep_ne_top), le_einfsep_iff,
edist_dist, ennreal.of_real_le_of_real_iff (dist_nonneg)]
lemma nontrivial.infsep_lt_iff {d} (hs : s.nontrivial) :
s.infsep < d ↔ ∃ (x y ∈ s) (hxy : x ≠ y), dist x y < d :=
by { rw ← not_iff_not, push_neg, exact hs.le_infsep_iff }
lemma nontrivial.le_infsep {d} (hs : s.nontrivial) (h : ∀ (x y ∈ s) (hxy : x ≠ y), d ≤ dist x y) :
d ≤ s.infsep := hs.le_infsep_iff.2 h
lemma le_edist_of_le_infsep {d x} (hx : x ∈ s) {y} (hy : y ∈ s)
(hxy : x ≠ y) (hd : d ≤ s.infsep) : d ≤ dist x y :=
begin
by_cases hs : s.nontrivial,
{ exact hs.le_infsep_iff.1 hd x hx y hy hxy },
{ rw not_nontrivial_iff at hs,
rw hs.infsep_zero at hd,
exact le_trans hd dist_nonneg }
end
lemma infsep_le_dist_of_mem (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) : s.infsep ≤ dist x y :=
le_edist_of_le_infsep hx hy hxy le_rfl
lemma infsep_le_of_mem_of_edist_le {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y)
(hxy' : dist x y ≤ d) : s.infsep ≤ d := le_trans (infsep_le_dist_of_mem hx hy hxy) hxy'
lemma infsep_pair : ({x, y} : set α).infsep = dist x y :=
by { rw [infsep_pair_eq_to_real, edist_dist], exact ennreal.to_real_of_real (dist_nonneg) }
lemma infsep_triple (hxy : x ≠ y) (hyz : y ≠ z) (hxz : x ≠ z) :
({x, y, z} : set α).infsep = dist x y ⊓ dist x z ⊓ dist y z :=
by simp only [infsep, einfsep_triple hxy hyz hxz, ennreal.to_real_inf, edist_ne_top x y,
edist_ne_top x z, edist_ne_top y z, dist_edist, ne.def, inf_eq_top_iff,
and_self, not_false_iff]
lemma nontrivial.infsep_anti (hs : s.nontrivial) (hst : s ⊆ t) : t.infsep ≤ s.infsep :=
ennreal.to_real_mono hs.einfsep_ne_top (einfsep_anti hst)
lemma infsep_eq_infi [decidable s.nontrivial] :
s.infsep = if s.nontrivial then ⨅ d : s.off_diag, (uncurry dist) (d : α × α) else 0 :=
begin
split_ifs with hs,
{ have hb : bdd_below (uncurry dist '' s.off_diag),
{ refine ⟨0, λ d h, _⟩,
simp_rw [mem_image, prod.exists, uncurry_apply_pair] at h,
rcases h with ⟨_, _, _, rfl⟩,
exact dist_nonneg },
refine eq_of_forall_le_iff (λ _, _),
simp_rw [hs.le_infsep_iff, le_cinfi_set_iff (off_diag_nonempty.mpr hs) hb, imp_forall_iff,
mem_off_diag, prod.forall, uncurry_apply_pair, and_imp] },
{ exact ((not_nontrivial_iff).mp hs).infsep_zero }
end
lemma nontrivial.infsep_eq_infi (hs : s.nontrivial)
: s.infsep = ⨅ d : s.off_diag, (uncurry dist) (d : α × α) :=
by { classical, rw [infsep_eq_infi, if_pos hs] }
lemma infsep_of_fintype [decidable s.nontrivial] [decidable_eq α] [fintype s] :
s.infsep = if hs : s.nontrivial then s.off_diag.to_finset.inf' (by simpa) (uncurry dist) else 0 :=
begin
split_ifs with hs,
{ refine eq_of_forall_le_iff (λ _, _),
simp_rw [hs.le_infsep_iff, imp_forall_iff, finset.le_inf'_iff, mem_to_finset, mem_off_diag,
prod.forall, uncurry_apply_pair, and_imp] },
{ rw not_nontrivial_iff at hs, exact hs.infsep_zero }
end
lemma nontrivial.infsep_of_fintype [decidable_eq α] [fintype s] (hs : s.nontrivial) :
s.infsep = s.off_diag.to_finset.inf' (by simpa) (uncurry dist) :=
by { classical, rw [infsep_of_fintype, dif_pos hs] }
lemma finite.infsep [decidable s.nontrivial] (hsf : s.finite) :
s.infsep = if hs : s.nontrivial then hsf.off_diag.to_finset.inf' (by simpa) (uncurry dist)
else 0 :=
begin
split_ifs with hs,
{ refine eq_of_forall_le_iff (λ _, _),
simp_rw [hs.le_infsep_iff, imp_forall_iff, finset.le_inf'_iff, finite.mem_to_finset,
mem_off_diag, prod.forall, uncurry_apply_pair, and_imp] },
{ rw not_nontrivial_iff at hs, exact hs.infsep_zero }
end
lemma finite.infsep_of_nontrivial (hsf : s.finite) (hs : s.nontrivial) :
s.infsep = hsf.off_diag.to_finset.inf' (by simpa) (uncurry dist) :=
by { classical, simp_rw [hsf.infsep, dif_pos hs] }
lemma _root_.finset.coe_infsep [decidable_eq α] (s : finset α) :
(s : set α).infsep = if hs : s.off_diag.nonempty then s.off_diag.inf' hs (uncurry dist)
else 0 :=
begin
have H : (s : set α).nontrivial ↔ s.off_diag.nonempty,
by rwa [← set.off_diag_nonempty, ← finset.coe_off_diag, finset.coe_nonempty],
split_ifs with hs,
{ simp_rw [(H.mpr hs).infsep_of_fintype, ← finset.coe_off_diag, finset.to_finset_coe] },
{ exact ((not_nontrivial_iff).mp (H.mp.mt hs)).infsep_zero }
end
lemma _root_.finset.coe_infsep_of_off_diag_nonempty [decidable_eq α] {s : finset α}
(hs : s.off_diag.nonempty) : (s : set α).infsep = s.off_diag.inf' hs (uncurry dist) :=
by rw [finset.coe_infsep, dif_pos hs]
lemma _root_.finset.coe_infsep_of_off_diag_empty [decidable_eq α] {s : finset α}
(hs : s.off_diag = ∅) : (s : set α).infsep = 0 :=
by { rw ← finset.not_nonempty_iff_eq_empty at hs, rw [finset.coe_infsep, dif_neg hs] }
lemma nontrivial.infsep_exists_of_finite [finite s] (hs : s.nontrivial) :
∃ (x y ∈ s) (hxy : x ≠ y), s.infsep = dist x y :=
begin
classical,
casesI nonempty_fintype s,
simp_rw hs.infsep_of_fintype,
rcases @finset.exists_mem_eq_inf' _ _ _ (s.off_diag.to_finset) (by simpa) (uncurry dist)
with ⟨_, hxy, hed⟩,
simp_rw mem_to_finset at hxy,
exact ⟨w.fst, hxy.1, w.snd, hxy.2.1, hxy.2.2, hed⟩
end
lemma finite.infsep_exists_of_nontrivial (hsf : s.finite) (hs : s.nontrivial) :
∃ (x y ∈ s) (hxy : x ≠ y), s.infsep = dist x y :=
by { letI := hsf.fintype, exact hs.infsep_exists_of_finite }
end pseudo_metric_space
section metric_space
variables [metric_space α] {s : set α}
lemma infsep_zero_iff_subsingleton_of_finite [finite s] :
s.infsep = 0 ↔ s.subsingleton :=
begin
rw [infsep_zero, einfsep_eq_top_iff, or_iff_right_iff_imp],
exact λ H, (einfsep_pos_of_finite.ne' H).elim
end
lemma infsep_pos_iff_nontrivial_of_finite [finite s] :
0 < s.infsep ↔ s.nontrivial :=
begin
rw [infsep_pos, einfsep_lt_top_iff, and_iff_right_iff_imp],
exact λ _, einfsep_pos_of_finite
end
lemma finite.infsep_zero_iff_subsingleton (hs : s.finite) :
s.infsep = 0 ↔ s.subsingleton :=
by { letI := hs.fintype, exact infsep_zero_iff_subsingleton_of_finite }
lemma finite.infsep_pos_iff_nontrivial (hs : s.finite) :
0 < s.infsep ↔ s.nontrivial :=
by { letI := hs.fintype, exact infsep_pos_iff_nontrivial_of_finite }
lemma _root_.finset.infsep_zero_iff_subsingleton (s : finset α) :
(s : set α).infsep = 0 ↔ (s : set α).subsingleton := infsep_zero_iff_subsingleton_of_finite
lemma _root_.finset.infsep_pos_iff_nontrivial (s : finset α) :
0 < (s : set α).infsep ↔ (s : set α).nontrivial := infsep_pos_iff_nontrivial_of_finite
end metric_space
end infsep
end set
|
508ceb2fa502f93b31af591b757ada894e17b02a | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/combinatorics/simple_graph/strongly_regular.lean | 5f8a7113bd96a7f43f03504d447be4199c8a68be | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 7,034 | lean | /-
Copyright (c) 2021 Alena Gusakov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alena Gusakov
-/
import combinatorics.simple_graph.basic
import data.set.finite
/-!
# Strongly regular graphs
## Main definitions
* `G.is_SRG_with n k ℓ μ` (see `simple_graph.is_SRG_with`) is a structure for
a `simple_graph` satisfying the following conditions:
* The cardinality of the vertex set is `n`
* `G` is a regular graph with degree `k`
* The number of common neighbors between any two adjacent vertices in `G` is `ℓ`
* The number of common neighbors between any two nonadjacent vertices in `G` is `μ`
## TODO
- Prove that the parameters of a strongly regular graph
obey the relation `(n - k - 1) * μ = k * (k - ℓ - 1)`
- Prove that if `I` is the identity matrix and `J` is the all-one matrix,
then the adj matrix `A` of SRG obeys relation `A^2 = kI + ℓA + μ(J - I - A)`
-/
open finset
universes u
namespace simple_graph
variables {V : Type u}
variables [fintype V] [decidable_eq V]
variables (G : simple_graph V) [decidable_rel G.adj]
/--
A graph is strongly regular with parameters `n k ℓ μ` if
* its vertex set has cardinality `n`
* it is regular with degree `k`
* every pair of adjacent vertices has `ℓ` common neighbors
* every pair of nonadjacent vertices has `μ` common neighbors
-/
structure is_SRG_with (n k ℓ μ : ℕ) : Prop :=
(card : fintype.card V = n)
(regular : G.is_regular_of_degree k)
(of_adj : ∀ (v w : V), G.adj v w → fintype.card (G.common_neighbors v w) = ℓ)
(of_not_adj : ∀ (v w : V), v ≠ w → ¬G.adj v w → fintype.card (G.common_neighbors v w) = μ)
variables {G} {n k ℓ μ : ℕ}
/-- Empty graphs are strongly regular. Note that `ℓ` can take any value
for empty graphs, since there are no pairs of adjacent vertices. -/
lemma bot_strongly_regular :
(⊥ : simple_graph V).is_SRG_with (fintype.card V) 0 ℓ 0 :=
{ card := rfl,
regular := bot_degree,
of_adj := λ v w h, h.elim,
of_not_adj := λ v w h, begin
simp only [card_eq_zero, filter_congr_decidable, fintype.card_of_finset, forall_true_left,
not_false_iff, bot_adj],
ext,
simp [mem_common_neighbors],
end }
/-- Complete graphs are strongly regular. Note that `μ` can take any value
for complete graphs, since there are no distinct pairs of non-adjacent vertices. -/
lemma is_SRG_with.top :
(⊤ : simple_graph V).is_SRG_with (fintype.card V) (fintype.card V - 1) (fintype.card V - 2) μ :=
{ card := rfl,
regular := is_regular_of_degree.top,
of_adj := λ v w h, begin
rw card_common_neighbors_top,
exact h,
end,
of_not_adj := λ v w h h', false.elim $ by simpa using h }
lemma is_SRG_with.card_neighbor_finset_union_eq {v w : V} (h : G.is_SRG_with n k ℓ μ) :
(G.neighbor_finset v ∪ G.neighbor_finset w).card =
2 * k - fintype.card (G.common_neighbors v w) :=
begin
apply @nat.add_right_cancel _ (fintype.card (G.common_neighbors v w)),
rw [nat.sub_add_cancel, ← set.to_finset_card],
{ simp [neighbor_finset, common_neighbors, set.to_finset_inter, finset.card_union_add_card_inter,
h.regular.degree_eq, two_mul], },
{ apply le_trans (card_common_neighbors_le_degree_left _ _ _),
simp [h.regular.degree_eq, two_mul], },
end
/-- Assuming `G` is strongly regular, `2*(k + 1) - m` in `G` is the number of vertices that are
adjacent to either `v` or `w` when `¬G.adj v w`. So it's the cardinality of
`G.neighbor_set v ∪ G.neighbor_set w`. -/
lemma is_SRG_with.card_neighbor_finset_union_of_not_adj {v w : V} (h : G.is_SRG_with n k ℓ μ)
(hne : v ≠ w) (ha : ¬G.adj v w) :
(G.neighbor_finset v ∪ G.neighbor_finset w).card = 2 * k - μ :=
begin
rw ← h.of_not_adj v w hne ha,
apply h.card_neighbor_finset_union_eq,
end
lemma is_SRG_with.card_neighbor_finset_union_of_adj {v w : V} (h : G.is_SRG_with n k ℓ μ)
(ha : G.adj v w) :
(G.neighbor_finset v ∪ G.neighbor_finset w).card = 2 * k - ℓ :=
begin
rw ← h.of_adj v w ha,
apply h.card_neighbor_finset_union_eq,
end
lemma compl_neighbor_finset_sdiff_inter_eq {v w : V} :
(G.neighbor_finset v)ᶜ \ {v} ∩ ((G.neighbor_finset w)ᶜ \ {w}) =
(G.neighbor_finset v)ᶜ ∩ (G.neighbor_finset w)ᶜ \ ({w} ∪ {v}) :=
by { ext, rw ← not_iff_not, simp [imp_iff_not_or, or_assoc, or_comm, or.left_comm], }
lemma sdiff_compl_neighbor_finset_inter_eq {v w : V} (h : G.adj v w) :
(G.neighbor_finset v)ᶜ ∩ (G.neighbor_finset w)ᶜ \ ({w} ∪ {v}) =
(G.neighbor_finset v)ᶜ ∩ (G.neighbor_finset w)ᶜ :=
begin
ext,
simp only [and_imp, mem_union, mem_sdiff, mem_compl, and_iff_left_iff_imp,
mem_neighbor_finset, mem_inter, mem_singleton],
rintros hnv hnw (rfl|rfl),
{ exact hnv h, },
{ apply hnw, rwa adj_comm, },
end
lemma is_SRG_with.compl_is_regular (h : G.is_SRG_with n k ℓ μ) :
Gᶜ.is_regular_of_degree (n - k - 1) :=
begin
rw [← h.card, nat.sub_sub, add_comm, ←nat.sub_sub],
exact h.regular.compl,
end
lemma is_SRG_with.card_common_neighbors_eq_of_adj_compl (h : G.is_SRG_with n k ℓ μ)
{v w : V} (ha : Gᶜ.adj v w) :
fintype.card ↥(Gᶜ.common_neighbors v w) = n - (2 * k - μ) - 2 :=
begin
simp only [←set.to_finset_card, common_neighbors, set.to_finset_inter, neighbor_set_compl,
set.to_finset_diff, set.to_finset_singleton, set.to_finset_compl, ←neighbor_finset_def],
simp_rw compl_neighbor_finset_sdiff_inter_eq,
have hne : v ≠ w := ne_of_adj _ ha,
rw compl_adj at ha,
rw [card_sdiff, ← insert_eq, card_insert_of_not_mem, card_singleton, ← finset.compl_union],
{ change (1 + 1) with 2,
rw [card_compl, h.card_neighbor_finset_union_of_not_adj hne ha.2, ← h.card], },
{ simp only [hne.symm, not_false_iff, mem_singleton], },
{ intro u,
simp only [mem_union, mem_compl, mem_neighbor_finset, mem_inter, mem_singleton],
rintro (rfl|rfl);
simpa [adj_comm] using ha.2, },
end
lemma is_SRG_with.card_common_neighbors_eq_of_not_adj_compl (h : G.is_SRG_with n k ℓ μ)
{v w : V} (hn : v ≠ w) (hna : ¬Gᶜ.adj v w) :
fintype.card ↥(Gᶜ.common_neighbors v w) = n - (2 * k - ℓ) :=
begin
simp only [←set.to_finset_card, common_neighbors, set.to_finset_inter, neighbor_set_compl,
set.to_finset_diff, set.to_finset_singleton, set.to_finset_compl, ←neighbor_finset_def],
simp only [not_and, not_not, compl_adj] at hna,
have h2' := hna hn,
simp_rw [compl_neighbor_finset_sdiff_inter_eq, sdiff_compl_neighbor_finset_inter_eq h2'],
rwa [← finset.compl_union, card_compl, h.card_neighbor_finset_union_of_adj, ← h.card],
end
/-- The complement of a strongly regular graph is strongly regular. -/
lemma is_SRG_with.compl (h : G.is_SRG_with n k ℓ μ) :
Gᶜ.is_SRG_with n (n - k - 1) (n - (2 * k - μ) - 2) (n - (2 * k - ℓ)) :=
{ card := h.card,
regular := h.compl_is_regular,
of_adj := λ v w ha, h.card_common_neighbors_eq_of_adj_compl ha,
of_not_adj := λ v w hn hna, h.card_common_neighbors_eq_of_not_adj_compl hn hna, }
end simple_graph
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.