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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3e80d8c0e82e6d4c9fdc71f1082cf604df5f8108
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/data/enat/lattice.lean
|
887e933c7a73ce42c0c715bd2de713b7e0297236
|
[
"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
| 502
|
lean
|
/-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import data.nat.lattice
import data.enat.basic
/-!
# Extended natural numbers form a complete linear order
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This instance is not in `data.enat.basic` to avoid dependency on `finset`s.
-/
attribute [derive complete_linear_order] enat
|
80e0864c3775c2f8d65755e2b56c2e2e5fe3316a
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/category_theory/natural_isomorphism.lean
|
c3f7d795d66638469cb2bfb65ca8b3f4162f4567
|
[
"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,129
|
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.category
import category_theory.isomorphism
/-!
# Natural isomorphisms
For the most part, natural isomorphisms are just another sort of isomorphism.
We provide some special support for extracting components:
* if `α : F ≅ G`, then `a.app X : F.obj X ≅ G.obj X`,
and building natural isomorphisms from components:
*
```
nat_iso.of_components
(app : ∀ X : C, F.obj X ≅ G.obj X)
(naturality : ∀ {X Y : C} (f : X ⟶ Y), F.map f ≫ (app Y).hom = (app X).hom ≫ G.map f) :
F ≅ G
```
only needing to check naturality in one direction.
## Implementation
Note that `nat_iso` is a namespace without a corresponding definition;
we put some declarations that are specifically about natural isomorphisms in the `iso`
namespace so that they are available using dot notation.
-/
open category_theory
-- declare the `v`'s first; see `category_theory.category` for an explanation
universes v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄
namespace category_theory
open nat_trans
variables {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₂} D]
{E : Type u₃} [category.{v₃} E]
namespace iso
/-- The application of a natural isomorphism to an object. We put this definition in a different
namespace, so that we can use `α.app` -/
@[simps] def app {F G : C ⥤ D} (α : F ≅ G) (X : C) : F.obj X ≅ G.obj X :=
{ hom := α.hom.app X,
inv := α.inv.app X,
hom_inv_id' := begin rw [← comp_app, iso.hom_inv_id], refl end,
inv_hom_id' := begin rw [← comp_app, iso.inv_hom_id], refl end }
@[simp, reassoc]
lemma hom_inv_id_app {F G : C ⥤ D} (α : F ≅ G) (X : C) :
α.hom.app X ≫ α.inv.app X = 𝟙 (F.obj X) :=
congr_fun (congr_arg nat_trans.app α.hom_inv_id) X
@[simp, reassoc]
lemma inv_hom_id_app {F G : C ⥤ D} (α : F ≅ G) (X : C) :
α.inv.app X ≫ α.hom.app X = 𝟙 (G.obj X) :=
congr_fun (congr_arg nat_trans.app α.inv_hom_id) X
end iso
namespace nat_iso
open category_theory.category category_theory.functor
@[simp] lemma trans_app {F G H : C ⥤ D} (α : F ≅ G) (β : G ≅ H) (X : C) :
(α ≪≫ β).app X = α.app X ≪≫ β.app X := rfl
lemma app_hom {F G : C ⥤ D} (α : F ≅ G) (X : C) : (α.app X).hom = α.hom.app X := rfl
lemma app_inv {F G : C ⥤ D} (α : F ≅ G) (X : C) : (α.app X).inv = α.inv.app X := rfl
variables {F G : C ⥤ D}
instance hom_app_is_iso (α : F ≅ G) (X : C) : is_iso (α.hom.app X) :=
⟨⟨α.inv.app X,
⟨by rw [←comp_app, iso.hom_inv_id, ←id_app], by rw [←comp_app, iso.inv_hom_id, ←id_app]⟩⟩⟩
instance inv_app_is_iso (α : F ≅ G) (X : C) : is_iso (α.inv.app X) :=
⟨⟨α.hom.app X,
⟨by rw [←comp_app, iso.inv_hom_id, ←id_app], by rw [←comp_app, iso.hom_inv_id, ←id_app]⟩⟩⟩
section
/-!
Unfortunately we need a separate set of cancellation lemmas for components of natural isomorphisms,
because the `simp` normal form is `α.hom.app X`, rather than `α.app.hom X`.
(With the later, the morphism would be visibly part of an isomorphism, so general lemmas about
isomorphisms would apply.)
In the future, we should consider a redesign that changes this simp norm form,
but for now it breaks too many proofs.
-/
variables (α : F ≅ G)
@[simp] lemma cancel_nat_iso_hom_left {X : C} {Z : D} (g g' : G.obj X ⟶ Z) :
α.hom.app X ≫ g = α.hom.app X ≫ g' ↔ g = g' :=
by simp only [cancel_epi]
@[simp] lemma cancel_nat_iso_inv_left {X : C} {Z : D} (g g' : F.obj X ⟶ Z) :
α.inv.app X ≫ g = α.inv.app X ≫ g' ↔ g = g' :=
by simp only [cancel_epi]
@[simp] lemma cancel_nat_iso_hom_right {X : D} {Y : C} (f f' : X ⟶ F.obj Y) :
f ≫ α.hom.app Y = f' ≫ α.hom.app Y ↔ f = f' :=
by simp only [cancel_mono]
@[simp] lemma cancel_nat_iso_inv_right {X : D} {Y : C} (f f' : X ⟶ G.obj Y) :
f ≫ α.inv.app Y = f' ≫ α.inv.app Y ↔ f = f' :=
by simp only [cancel_mono]
@[simp] lemma cancel_nat_iso_hom_right_assoc {W X X' : D} {Y : C}
(f : W ⟶ X) (g : X ⟶ F.obj Y) (f' : W ⟶ X') (g' : X' ⟶ F.obj Y) :
f ≫ g ≫ α.hom.app Y = f' ≫ g' ≫ α.hom.app Y ↔ f ≫ g = f' ≫ g' :=
by simp only [←category.assoc, cancel_mono]
@[simp] lemma cancel_nat_iso_inv_right_assoc {W X X' : D} {Y : C}
(f : W ⟶ X) (g : X ⟶ G.obj Y) (f' : W ⟶ X') (g' : X' ⟶ G.obj Y) :
f ≫ g ≫ α.inv.app Y = f' ≫ g' ≫ α.inv.app Y ↔ f ≫ g = f' ≫ g' :=
by simp only [←category.assoc, cancel_mono]
@[simp] lemma inv_inv_app {F G : C ⥤ D} (e : F ≅ G) (X : C) :
inv (e.inv.app X) = e.hom.app X := by { ext, simp }
end
variables {X Y : C}
lemma naturality_1 (α : F ≅ G) (f : X ⟶ Y) :
α.inv.app X ≫ F.map f ≫ α.hom.app Y = G.map f :=
by simp
lemma naturality_2 (α : F ≅ G) (f : X ⟶ Y) :
α.hom.app X ≫ G.map f ≫ α.inv.app Y = F.map f :=
by simp
lemma naturality_1' (α : F ⟶ G) (f : X ⟶ Y) [is_iso (α.app X)] :
inv (α.app X) ≫ F.map f ≫ α.app Y = G.map f :=
by simp
@[simp, reassoc] lemma naturality_2' (α : F ⟶ G) (f : X ⟶ Y) [is_iso (α.app Y)] :
α.app X ≫ G.map f ≫ inv (α.app Y) = F.map f :=
by rw [←category.assoc, ←naturality, category.assoc, is_iso.hom_inv_id, category.comp_id]
/--
The components of a natural isomorphism are isomorphisms.
-/
instance is_iso_app_of_is_iso (α : F ⟶ G) [is_iso α] (X) : is_iso (α.app X) :=
⟨⟨(inv α).app X,
⟨congr_fun (congr_arg nat_trans.app (is_iso.hom_inv_id α)) X,
congr_fun (congr_arg nat_trans.app (is_iso.inv_hom_id α)) X⟩⟩⟩
@[simp] lemma is_iso_inv_app (α : F ⟶ G) [is_iso α] (X) : (inv α).app X = inv (α.app X) :=
by { ext, rw ←nat_trans.comp_app, simp, }
@[simp] lemma inv_map_inv_app (F : C ⥤ D ⥤ E) {X Y : C} (e : X ≅ Y) (Z : D) :
inv ((F.map e.inv).app Z) = (F.map e.hom).app Z :=
by { ext, simp, }
/--
Construct a natural isomorphism between functors by giving object level isomorphisms,
and checking naturality only in the forward direction.
-/
@[simps] def of_components (app : ∀ X : C, F.obj X ≅ G.obj X)
(naturality : ∀ {X Y : C} (f : X ⟶ Y), F.map f ≫ (app Y).hom = (app X).hom ≫ G.map f) :
F ≅ G :=
{ hom := { app := λ X, (app X).hom },
inv :=
{ app := λ X, (app X).inv,
naturality' := λ X Y f,
begin
have h := congr_arg (λ f, (app X).inv ≫ (f ≫ (app Y).inv)) (naturality f).symm,
simp only [iso.inv_hom_id_assoc, iso.hom_inv_id, assoc, comp_id, cancel_mono] at h,
exact h
end }, }
@[simp] lemma of_components.app (app' : ∀ X : C, F.obj X ≅ G.obj X) (naturality) (X) :
(of_components app' naturality).app X = app' X :=
by tidy
/--
A natural transformation is an isomorphism if all its components are isomorphisms.
-/
-- Making this an instance would cause a typeclass inference loop with `is_iso_app_of_is_iso`.
lemma is_iso_of_is_iso_app (α : F ⟶ G) [∀ X : C, is_iso (α.app X)] : is_iso α :=
⟨(is_iso.of_iso (of_components (λ X, as_iso (α.app X)) (by tidy))).1⟩
/-- Horizontal composition of natural isomorphisms. -/
@[simps]
def hcomp {F G : C ⥤ D} {H I : D ⥤ E} (α : F ≅ G) (β : H ≅ I) : F ⋙ H ≅ G ⋙ I :=
begin
refine ⟨α.hom ◫ β.hom, α.inv ◫ β.inv, _, _⟩,
{ ext, rw [←nat_trans.exchange], simp, refl },
ext, rw [←nat_trans.exchange], simp, refl
end
lemma is_iso_map_iff {F₁ F₂ : C ⥤ D} (e : F₁ ≅ F₂) {X Y : C} (f : X ⟶ Y) :
is_iso (F₁.map f) ↔ is_iso (F₂.map f) :=
begin
revert F₁ F₂,
suffices : ∀ {F₁ F₂ : C ⥤ D} (e : F₁ ≅ F₂) (hf : is_iso (F₁.map f)), is_iso (F₂.map f),
{ exact λ F₁ F₂ e, ⟨this e, this e.symm⟩, },
introsI F₁ F₂ e hf,
refine is_iso.mk ⟨e.inv.app Y ≫ inv (F₁.map f) ≫ e.hom.app X, _, _⟩,
{ simp only [nat_trans.naturality_assoc, is_iso.hom_inv_id_assoc, iso.inv_hom_id_app], },
{ simp only [assoc, ← e.hom.naturality, is_iso.inv_hom_id_assoc, iso.inv_hom_id_app], },
end
end nat_iso
end category_theory
|
c58084ed3b98307637e5173239370cd46e9f92b0
|
6dc0c8ce7a76229dd81e73ed4474f15f88a9e294
|
/src/Lean/Parser/Extension.lean
|
83554712ef34a512c3c459eb892bed836ac555e6
|
[
"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
| 26,249
|
lean
|
/-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Sebastian Ullrich
-/
import Lean.ScopedEnvExtension
import Lean.Parser.Basic
import Lean.Parser.StrInterpolation
import Lean.KeyedDeclsAttribute
/-! Extensible parsing via attributes -/
namespace Lean
namespace Parser
builtin_initialize builtinTokenTable : IO.Ref TokenTable ← IO.mkRef {}
/- Global table with all SyntaxNodeKind's -/
builtin_initialize builtinSyntaxNodeKindSetRef : IO.Ref SyntaxNodeKindSet ← IO.mkRef {}
def registerBuiltinNodeKind (k : SyntaxNodeKind) : IO Unit :=
builtinSyntaxNodeKindSetRef.modify fun s => s.insert k
builtin_initialize
registerBuiltinNodeKind choiceKind
registerBuiltinNodeKind identKind
registerBuiltinNodeKind strLitKind
registerBuiltinNodeKind numLitKind
registerBuiltinNodeKind scientificLitKind
registerBuiltinNodeKind charLitKind
registerBuiltinNodeKind nameLitKind
builtin_initialize builtinParserCategoriesRef : IO.Ref ParserCategories ← IO.mkRef {}
private def throwParserCategoryAlreadyDefined {α} (catName : Name) : ExceptT String Id α :=
throw s!"parser category '{catName}' has already been defined"
private def addParserCategoryCore (categories : ParserCategories) (catName : Name) (initial : ParserCategory) : Except String ParserCategories :=
if categories.contains catName then
throwParserCategoryAlreadyDefined catName
else
pure $ categories.insert catName initial
/-- All builtin parser categories are Pratt's parsers -/
private def addBuiltinParserCategory (catName : Name) (behavior : LeadingIdentBehavior) : IO Unit := do
let categories ← builtinParserCategoriesRef.get
let categories ← IO.ofExcept $ addParserCategoryCore categories catName { tables := {}, behavior := behavior}
builtinParserCategoriesRef.set categories
namespace ParserExtension
inductive OLeanEntry where
| token (val : Token) : OLeanEntry
| kind (val : SyntaxNodeKind) : OLeanEntry
| category (catName : Name) (behavior : LeadingIdentBehavior)
| parser (catName : Name) (declName : Name) (prio : Nat) : OLeanEntry
deriving Inhabited
inductive Entry where
| token (val : Token) : Entry
| kind (val : SyntaxNodeKind) : Entry
| category (catName : Name) (behavior : LeadingIdentBehavior)
| parser (catName : Name) (declName : Name) (leading : Bool) (p : Parser) (prio : Nat) : Entry
deriving Inhabited
def Entry.toOLeanEntry : Entry → OLeanEntry
| token v => OLeanEntry.token v
| kind v => OLeanEntry.kind v
| category c b => OLeanEntry.category c b
| parser c d _ _ prio => OLeanEntry.parser c d prio
structure State where
tokens : TokenTable := {}
kinds : SyntaxNodeKindSet := {}
categories : ParserCategories := {}
deriving Inhabited
end ParserExtension
open ParserExtension in
abbrev ParserExtension := ScopedEnvExtension OLeanEntry Entry State
private def ParserExtension.mkInitial : IO ParserExtension.State := do
let tokens ← builtinTokenTable.get
let kinds ← builtinSyntaxNodeKindSetRef.get
let categories ← builtinParserCategoriesRef.get
pure { tokens := tokens, kinds := kinds, categories := categories }
private def addTokenConfig (tokens : TokenTable) (tk : Token) : Except String TokenTable := do
if tk == "" then throw "invalid empty symbol"
else match tokens.find? tk with
| none => pure $ tokens.insert tk tk
| some _ => pure tokens
def throwUnknownParserCategory {α} (catName : Name) : ExceptT String Id α :=
throw s!"unknown parser category '{catName}'"
abbrev getCategory (categories : ParserCategories) (catName : Name) : Option ParserCategory :=
categories.find? catName
def addLeadingParser (categories : ParserCategories) (catName : Name) (parserName : Name) (p : Parser) (prio : Nat) : Except String ParserCategories :=
match getCategory categories catName with
| none =>
throwUnknownParserCategory catName
| some cat =>
let addTokens (tks : List Token) : Except String ParserCategories :=
let tks := tks.map $ fun tk => Name.mkSimple tk
let tables := tks.eraseDups.foldl (fun (tables : PrattParsingTables) tk => { tables with leadingTable := tables.leadingTable.insert tk (p, prio) }) cat.tables
pure $ categories.insert catName { cat with tables := tables }
match p.info.firstTokens with
| FirstTokens.tokens tks => addTokens tks
| FirstTokens.optTokens tks => addTokens tks
| _ =>
let tables := { cat.tables with leadingParsers := (p, prio) :: cat.tables.leadingParsers }
pure $ categories.insert catName { cat with tables := tables }
private def addTrailingParserAux (tables : PrattParsingTables) (p : TrailingParser) (prio : Nat) : PrattParsingTables :=
let addTokens (tks : List Token) : PrattParsingTables :=
let tks := tks.map fun tk => Name.mkSimple tk
tks.eraseDups.foldl (fun (tables : PrattParsingTables) tk => { tables with trailingTable := tables.trailingTable.insert tk (p, prio) }) tables
match p.info.firstTokens with
| FirstTokens.tokens tks => addTokens tks
| FirstTokens.optTokens tks => addTokens tks
| _ => { tables with trailingParsers := (p, prio) :: tables.trailingParsers }
def addTrailingParser (categories : ParserCategories) (catName : Name) (p : TrailingParser) (prio : Nat) : Except String ParserCategories :=
match getCategory categories catName with
| none => throwUnknownParserCategory catName
| some cat => pure $ categories.insert catName { cat with tables := addTrailingParserAux cat.tables p prio }
def addParser (categories : ParserCategories) (catName : Name) (declName : Name) (leading : Bool) (p : Parser) (prio : Nat) : Except String ParserCategories :=
match leading, p with
| true, p => addLeadingParser categories catName declName p prio
| false, p => addTrailingParser categories catName p prio
def addParserTokens (tokenTable : TokenTable) (info : ParserInfo) : Except String TokenTable :=
let newTokens := info.collectTokens []
newTokens.foldlM addTokenConfig tokenTable
private def updateBuiltinTokens (info : ParserInfo) (declName : Name) : IO Unit := do
let tokenTable ← builtinTokenTable.swap {}
match addParserTokens tokenTable info with
| Except.ok tokenTable => builtinTokenTable.set tokenTable
| Except.error msg => throw (IO.userError s!"invalid builtin parser '{declName}', {msg}")
def addBuiltinParser (catName : Name) (declName : Name) (leading : Bool) (p : Parser) (prio : Nat) : IO Unit := do
let p := evalInsideQuot declName p
let categories ← builtinParserCategoriesRef.get
let categories ← IO.ofExcept $ addParser categories catName declName leading p prio
builtinParserCategoriesRef.set categories
builtinSyntaxNodeKindSetRef.modify p.info.collectKinds
updateBuiltinTokens p.info declName
def addBuiltinLeadingParser (catName : Name) (declName : Name) (p : Parser) (prio : Nat) : IO Unit :=
addBuiltinParser catName declName true p prio
def addBuiltinTrailingParser (catName : Name) (declName : Name) (p : TrailingParser) (prio : Nat) : IO Unit :=
addBuiltinParser catName declName false p prio
def ParserExtension.addEntryImpl (s : State) (e : Entry) : State :=
match e with
| Entry.token tk =>
match addTokenConfig s.tokens tk with
| Except.ok tokens => { s with tokens := tokens }
| _ => unreachable!
| Entry.kind k =>
{ s with kinds := s.kinds.insert k }
| Entry.category catName behavior =>
if s.categories.contains catName then s
else { s with
categories := s.categories.insert catName { tables := {}, behavior := behavior } }
| Entry.parser catName declName leading parser prio =>
match addParser s.categories catName declName leading parser prio with
| Except.ok categories => { s with categories := categories }
| _ => unreachable!
unsafe def mkParserOfConstantUnsafe
(categories : ParserCategories) (constName : Name) (compileParserDescr : ParserDescr → ImportM Parser) : ImportM (Bool × Parser) := do
let env := (← read).env
let opts := (← read).opts
match env.find? constName with
| none => throw ↑s!"unknow constant '{constName}'"
| some info =>
match info.type with
| Expr.const `Lean.Parser.TrailingParser _ _ =>
let p ← IO.ofExcept $ env.evalConst Parser opts constName
pure ⟨false, p⟩
| Expr.const `Lean.Parser.Parser _ _ =>
let p ← IO.ofExcept $ env.evalConst Parser opts constName
pure ⟨true, p⟩
| Expr.const `Lean.ParserDescr _ _ =>
let d ← IO.ofExcept $ env.evalConst ParserDescr opts constName
let p ← compileParserDescr d
pure ⟨true, p⟩
| Expr.const `Lean.TrailingParserDescr _ _ =>
let d ← IO.ofExcept $ env.evalConst TrailingParserDescr opts constName
let p ← compileParserDescr d
pure ⟨false, p⟩
| _ => throw ↑s!"unexpected parser type at '{constName}' (`ParserDescr`, `TrailingParserDescr`, `Parser` or `TrailingParser` expected"
@[implementedBy mkParserOfConstantUnsafe]
constant mkParserOfConstantAux
(categories : ParserCategories) (constName : Name) (compileParserDescr : ParserDescr → ImportM Parser) : ImportM (Bool × Parser)
/- Parser aliases for making `ParserDescr` extensible -/
inductive AliasValue (α : Type) where
| const (p : α)
| unary (p : α → α)
| binary (p : α → α → α)
abbrev AliasTable (α) := NameMap (AliasValue α)
def registerAliasCore {α} (mapRef : IO.Ref (AliasTable α)) (aliasName : Name) (value : AliasValue α) : IO Unit := do
unless (← IO.initializing) do throw ↑"aliases can only be registered during initialization"
if (← mapRef.get).contains aliasName then
throw ↑s!"alias '{aliasName}' has already been declared"
mapRef.modify (·.insert aliasName value)
def getAlias {α} (mapRef : IO.Ref (AliasTable α)) (aliasName : Name) : IO (Option (AliasValue α)) := do
return (← mapRef.get).find? aliasName
def getConstAlias {α} (mapRef : IO.Ref (AliasTable α)) (aliasName : Name) : IO α := do
match (← getAlias mapRef aliasName) with
| some (AliasValue.const v) => pure v
| some (AliasValue.unary _) => throw ↑s!"parser '{aliasName}' is not a constant, it takes one argument"
| some (AliasValue.binary _) => throw ↑s!"parser '{aliasName}' is not a constant, it takes two arguments"
| none => throw ↑s!"parser '{aliasName}' was not found"
def getUnaryAlias {α} (mapRef : IO.Ref (AliasTable α)) (aliasName : Name) : IO (α → α) := do
match (← getAlias mapRef aliasName) with
| some (AliasValue.unary v) => pure v
| some _ => throw ↑s!"parser '{aliasName}' does not take one argument"
| none => throw ↑s!"parser '{aliasName}' was not found"
def getBinaryAlias {α} (mapRef : IO.Ref (AliasTable α)) (aliasName : Name) : IO (α → α → α) := do
match (← getAlias mapRef aliasName) with
| some (AliasValue.binary v) => pure v
| some _ => throw ↑s!"parser '{aliasName}' does not take two arguments"
| none => throw ↑s!"parser '{aliasName}' was not found"
abbrev ParserAliasValue := AliasValue Parser
builtin_initialize parserAliasesRef : IO.Ref (NameMap ParserAliasValue) ← IO.mkRef {}
-- Later, we define macro registerParserAlias! which registers a parser, formatter and parenthesizer
def registerAlias (aliasName : Name) (p : ParserAliasValue) : IO Unit := do
registerAliasCore parserAliasesRef aliasName p
instance : Coe Parser ParserAliasValue := { coe := AliasValue.const }
instance : Coe (Parser → Parser) ParserAliasValue := { coe := AliasValue.unary }
instance : Coe (Parser → Parser → Parser) ParserAliasValue := { coe := AliasValue.binary }
def isParserAlias (aliasName : Name) : IO Bool := do
match (← getAlias parserAliasesRef aliasName) with
| some _ => pure true
| _ => pure false
def ensureUnaryParserAlias (aliasName : Name) : IO Unit :=
discard $ getUnaryAlias parserAliasesRef aliasName
def ensureBinaryParserAlias (aliasName : Name) : IO Unit :=
discard $ getBinaryAlias parserAliasesRef aliasName
def ensureConstantParserAlias (aliasName : Name) : IO Unit :=
discard $ getConstAlias parserAliasesRef aliasName
partial def compileParserDescr (categories : ParserCategories) (d : ParserDescr) : ImportM Parser :=
let rec visit : ParserDescr → ImportM Parser
| ParserDescr.const n => getConstAlias parserAliasesRef n
| ParserDescr.unary n d => return (← getUnaryAlias parserAliasesRef n) (← visit d)
| ParserDescr.binary n d₁ d₂ => return (← getBinaryAlias parserAliasesRef n) (← visit d₁) (← visit d₂)
| ParserDescr.node k prec d => return leadingNode k prec (← visit d)
| ParserDescr.nodeWithAntiquot n k d => return nodeWithAntiquot n k (← visit d) (anonymous := true)
| ParserDescr.sepBy p sep psep trail => return sepBy (← visit p) sep (← visit psep) trail
| ParserDescr.sepBy1 p sep psep trail => return sepBy1 (← visit p) sep (← visit psep) trail
| ParserDescr.trailingNode k prec d => return trailingNode k prec (← visit d)
| ParserDescr.symbol tk => return symbol tk
| ParserDescr.nonReservedSymbol tk includeIdent => return nonReservedSymbol tk includeIdent
| ParserDescr.parser constName => do
let (_, p) ← mkParserOfConstantAux categories constName visit;
pure p
| ParserDescr.cat catName prec =>
match getCategory categories catName with
| some _ => pure $ categoryParser catName prec
| none => IO.ofExcept $ throwUnknownParserCategory catName
visit d
def mkParserOfConstant (categories : ParserCategories) (constName : Name) : ImportM (Bool × Parser) :=
mkParserOfConstantAux categories constName (compileParserDescr categories)
structure ParserAttributeHook where
/- Called after a parser attribute is applied to a declaration. -/
postAdd (catName : Name) (declName : Name) (builtin : Bool) : AttrM Unit
builtin_initialize parserAttributeHooks : IO.Ref (List ParserAttributeHook) ← IO.mkRef {}
def registerParserAttributeHook (hook : ParserAttributeHook) : IO Unit := do
parserAttributeHooks.modify fun hooks => hook::hooks
def runParserAttributeHooks (catName : Name) (declName : Name) (builtin : Bool) : AttrM Unit := do
let hooks ← parserAttributeHooks.get
hooks.forM fun hook => hook.postAdd catName declName builtin
builtin_initialize
registerBuiltinAttribute {
name := `runBuiltinParserAttributeHooks,
descr := "explicitly run hooks normally activated by builtin parser attributes",
add := fun decl stx persistent => do
Attribute.Builtin.ensureNoArgs stx
runParserAttributeHooks Name.anonymous decl (builtin := true)
}
builtin_initialize
registerBuiltinAttribute {
name := `runParserAttributeHooks,
descr := "explicitly run hooks normally activated by parser attributes",
add := fun decl stx persistent => do
Attribute.Builtin.ensureNoArgs stx
runParserAttributeHooks Name.anonymous decl (builtin := false)
}
private def ParserExtension.OLeanEntry.toEntry (s : State) : OLeanEntry → ImportM Entry
| token tk => return Entry.token tk
| kind k => return Entry.kind k
| category c l => return Entry.category c l
| parser catName declName prio => do
let (leading, p) ← mkParserOfConstant s.categories declName
Entry.parser catName declName leading p prio
builtin_initialize parserExtension : ParserExtension ←
registerScopedEnvExtension {
name := `parserExt
mkInitial := ParserExtension.mkInitial
addEntry := ParserExtension.addEntryImpl
toOLeanEntry := ParserExtension.Entry.toOLeanEntry
ofOLeanEntry := ParserExtension.OLeanEntry.toEntry
}
def isParserCategory (env : Environment) (catName : Name) : Bool :=
(parserExtension.getState env).categories.contains catName
def addParserCategory (env : Environment) (catName : Name) (behavior : LeadingIdentBehavior) : Except String Environment := do
if isParserCategory env catName then
throwParserCategoryAlreadyDefined catName
else
return parserExtension.addEntry env <| ParserExtension.Entry.category catName behavior
def leadingIdentBehavior (env : Environment) (catName : Name) : LeadingIdentBehavior :=
match getCategory (parserExtension.getState env).categories catName with
| none => LeadingIdentBehavior.default
| some cat => cat.behavior
def mkCategoryAntiquotParser (kind : Name) : Parser :=
mkAntiquot kind.toString none
-- helper decl to work around inlining issue https://github.com/leanprover/lean4/commit/3f6de2af06dd9a25f62294129f64bc05a29ea912#r41340377
@[inline] private def mkCategoryAntiquotParserFn (kind : Name) : ParserFn :=
(mkCategoryAntiquotParser kind).fn
def categoryParserFnImpl (catName : Name) : ParserFn := fun ctx s =>
let catName := if catName == `syntax then `stx else catName -- temporary Hack
let categories := (parserExtension.getState ctx.env).categories
match getCategory categories catName with
| some cat =>
prattParser catName cat.tables cat.behavior (mkCategoryAntiquotParserFn catName) ctx s
| none => s.mkUnexpectedError ("unknown parser category '" ++ toString catName ++ "'")
@[builtinInit] def setCategoryParserFnRef : IO Unit :=
categoryParserFnRef.set categoryParserFnImpl
def addToken (tk : Token) (kind : AttributeKind) : AttrM Unit := do
-- Recall that `ParserExtension.addEntry` is pure, and assumes `addTokenConfig` does not fail.
-- So, we must run it here to handle exception.
discard <| ofExcept <| addTokenConfig (parserExtension.getState (← getEnv)).tokens tk
parserExtension.add (ParserExtension.Entry.token tk) kind
def addSyntaxNodeKind (env : Environment) (k : SyntaxNodeKind) : Environment :=
parserExtension.addEntry env <| ParserExtension.Entry.kind k
def isValidSyntaxNodeKind (env : Environment) (k : SyntaxNodeKind) : Bool :=
let kinds := (parserExtension.getState env).kinds
kinds.contains k
def getSyntaxNodeKinds (env : Environment) : List SyntaxNodeKind := do
let kinds := (parserExtension.getState env).kinds
kinds.foldl (fun ks k _ => k::ks) []
def getTokenTable (env : Environment) : TokenTable :=
(parserExtension.getState env).tokens
def mkInputContext (input : String) (fileName : String) : InputContext := {
input := input,
fileName := fileName,
fileMap := input.toFileMap
}
def mkParserContext (ictx : InputContext) (pmctx : ParserModuleContext) : ParserContext := {
prec := 0,
toInputContext := ictx,
toParserModuleContext := pmctx,
tokens := getTokenTable pmctx.env
}
def mkParserState (input : String) : ParserState :=
{ cache := initCacheForInput input }
/- convenience function for testing -/
def runParserCategory (env : Environment) (catName : Name) (input : String) (fileName := "<input>") : Except String Syntax :=
let c := mkParserContext (mkInputContext input fileName) { env := env, options := {} }
let s := mkParserState input
let s := whitespace c s
let s := categoryParserFnImpl catName c s
if s.hasError then
Except.error (s.toErrorMsg c)
else if input.atEnd s.pos then
Except.ok s.stxStack.back
else
Except.error ((s.mkError "end of input").toErrorMsg c)
def declareBuiltinParser (env : Environment) (addFnName : Name) (catName : Name) (declName : Name) (prio : Nat) : IO Environment :=
let name := `_regBuiltinParser ++ declName
let type := mkApp (mkConst `IO) (mkConst `Unit)
let val := mkAppN (mkConst addFnName) #[toExpr catName, toExpr declName, mkConst declName, mkNatLit prio]
let decl := Declaration.defnDecl { name := name, levelParams := [], type := type, value := val, hints := ReducibilityHints.opaque,
safety := DefinitionSafety.safe }
match env.addAndCompile {} decl with
-- TODO: pretty print error
| Except.error _ => throw (IO.userError ("failed to emit registration code for builtin parser '" ++ toString declName ++ "'"))
| Except.ok env => IO.ofExcept (setBuiltinInitAttr env name)
def declareLeadingBuiltinParser (env : Environment) (catName : Name) (declName : Name) (prio : Nat) : IO Environment := -- TODO: use CoreM?
declareBuiltinParser env `Lean.Parser.addBuiltinLeadingParser catName declName prio
def declareTrailingBuiltinParser (env : Environment) (catName : Name) (declName : Name) (prio : Nat) : IO Environment := -- TODO: use CoreM?
declareBuiltinParser env `Lean.Parser.addBuiltinTrailingParser catName declName prio
def getParserPriority (args : Syntax) : Except String Nat :=
match args.getNumArgs with
| 0 => pure 0
| 1 => match (args.getArg 0).isNatLit? with
| some prio => pure prio
| none => throw "invalid parser attribute, numeral expected"
| _ => throw "invalid parser attribute, no argument or numeral expected"
private def BuiltinParserAttribute.add (attrName : Name) (catName : Name)
(declName : Name) (stx : Syntax) (kind : AttributeKind) : AttrM Unit := do
let prio ← Attribute.Builtin.getPrio stx
unless kind == AttributeKind.global do throwError! "invalid attribute '{attrName}', must be global"
let decl ← getConstInfo declName
let env ← getEnv
match decl.type with
| Expr.const `Lean.Parser.TrailingParser _ _ => do
let env ← declareTrailingBuiltinParser env catName declName prio
setEnv env
| Expr.const `Lean.Parser.Parser _ _ => do
let env ← declareLeadingBuiltinParser env catName declName prio
setEnv env
| _ => throwError! "unexpected parser type at '{declName}' (`Parser` or `TrailingParser` expected)"
runParserAttributeHooks catName declName (builtin := true)
/-
The parsing tables for builtin parsers are "stored" in the extracted source code.
-/
def registerBuiltinParserAttribute (attrName : Name) (catName : Name) (behavior := LeadingIdentBehavior.default) : IO Unit := do
addBuiltinParserCategory catName behavior
registerBuiltinAttribute {
name := attrName,
descr := "Builtin parser",
add := fun declName stx kind => liftM $ BuiltinParserAttribute.add attrName catName declName stx kind,
applicationTime := AttributeApplicationTime.afterCompilation
}
private def ParserAttribute.add (attrName : Name) (catName : Name) (declName : Name) (stx : Syntax) (attrKind : AttributeKind) : AttrM Unit := do
let prio ← Attribute.Builtin.getPrio stx
let env ← getEnv
let opts ← getOptions
let categories := (parserExtension.getState env).categories
let p ← mkParserOfConstant categories declName
let leading := p.1
let parser := p.2
let tokens := parser.info.collectTokens []
tokens.forM fun token => do
try
addToken token attrKind
catch
| Exception.error ref msg => throwError! "invalid parser '{declName}', {msg}"
| ex => throw ex
let kinds := parser.info.collectKinds {}
kinds.forM fun kind _ => modifyEnv fun env => addSyntaxNodeKind env kind
let entry := ParserExtension.Entry.parser catName declName leading parser prio
match addParser categories catName declName leading parser prio with
| Except.error ex => throwError ex
| Except.ok _ => parserExtension.add entry attrKind
runParserAttributeHooks catName declName (builtin := false)
def mkParserAttributeImpl (attrName : Name) (catName : Name) : AttributeImpl where
name := attrName
descr := "parser"
add declName stx attrKind := ParserAttribute.add attrName catName declName stx attrKind
applicationTime := AttributeApplicationTime.afterCompilation
/- A builtin parser attribute that can be extended by users. -/
def registerBuiltinDynamicParserAttribute (attrName : Name) (catName : Name) : IO Unit := do
registerBuiltinAttribute (mkParserAttributeImpl attrName catName)
@[builtinInit] private def registerParserAttributeImplBuilder : IO Unit :=
registerAttributeImplBuilder `parserAttr fun args =>
match args with
| [DataValue.ofName attrName, DataValue.ofName catName] => pure $ mkParserAttributeImpl attrName catName
| _ => throw "invalid parser attribute implementation builder arguments"
def registerParserCategory (env : Environment) (attrName : Name) (catName : Name) (behavior := LeadingIdentBehavior.default) : IO Environment := do
let env ← IO.ofExcept $ addParserCategory env catName behavior
registerAttributeOfBuilder env `parserAttr [DataValue.ofName attrName, DataValue.ofName catName]
-- declare `termParser` here since it is used everywhere via antiquotations
builtin_initialize registerBuiltinParserAttribute `builtinTermParser `term
builtin_initialize registerBuiltinDynamicParserAttribute `termParser `term
-- declare `commandParser` to break cyclic dependency
builtin_initialize registerBuiltinParserAttribute `builtinCommandParser `command
builtin_initialize registerBuiltinDynamicParserAttribute `commandParser `command
@[inline] def commandParser (rbp : Nat := 0) : Parser :=
categoryParser `command rbp
def notFollowedByCategoryTokenFn (catName : Name) : ParserFn := fun ctx s =>
let categories := (parserExtension.getState ctx.env).categories
match getCategory categories catName with
| none => s.mkUnexpectedError s!"unknown parser category '{catName}'"
| some cat =>
let (s, stx) := peekToken ctx s
match stx with
| some (Syntax.atom _ sym) =>
if ctx.insideQuot && sym == "$" then s
else match cat.tables.leadingTable.find? (Name.mkSimple sym) with
| some _ => s.mkUnexpectedError (toString catName)
| _ => s
| _ => s
@[inline] def notFollowedByCategoryToken (catName : Name) : Parser := {
fn := notFollowedByCategoryTokenFn catName
}
abbrev notFollowedByCommandToken : Parser :=
notFollowedByCategoryToken `command
abbrev notFollowedByTermToken : Parser :=
notFollowedByCategoryToken `term
end Parser
end Lean
|
14b78163bd218c36599fe7183aece2a24c83e2ec
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/geometry/manifold/algebra/lie_group.lean
|
f9a3408b9f97e5a8e98f589d7c570f60f9ae1570
|
[
"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
| 6,026
|
lean
|
/-
Copyright © 2020 Nicolò Cavalleri. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nicolò Cavalleri
-/
import geometry.manifold.algebra.monoid
/-!
# Lie groups
A Lie group is a group that is also a smooth manifold, in which the group operations of
multiplication and inversion are smooth maps. Smoothness of the group multiplication means that
multiplication is a smooth mapping of the product manifold `G` × `G` into `G`.
Note that, since a manifold here is not second-countable and Hausdorff a Lie group here is not
guaranteed to be second-countable (even though it can be proved it is Hausdorff). Note also that Lie
groups here are not necessarily finite dimensional.
## Main definitions and statements
* `lie_add_group I G` : a Lie additive group where `G` is a manifold on the model with corners `I`.
* `lie_group I G` : a Lie multiplicative group where `G` is a manifold on the model with
corners `I`.
* `normed_space_lie_add_group` : a normed vector space over a nondiscrete normed field
is an additive Lie group.
## Implementation notes
A priori, a Lie group here is a manifold with corners.
The definition of Lie group cannot require `I : model_with_corners 𝕜 E E` with the same space as the
model space and as the model vector space, as one might hope, beause in the product situation,
the model space is `model_prod E E'` and the model vector space is `E × E'`, which are not the same,
so the definition does not apply. Hence the definition should be more general, allowing
`I : model_with_corners 𝕜 E H`.
-/
noncomputable theory
open_locale manifold
/-- A Lie (additive) group is a group and a smooth manifold at the same time in which
the addition and negation operations are smooth. -/
-- See note [Design choices about smooth algebraic structures]
@[ancestor has_smooth_add]
class lie_add_group {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{H : Type*} [topological_space H]
{E : Type*} [normed_group E] [normed_space 𝕜 E] (I : model_with_corners 𝕜 E H)
(G : Type*) [add_group G] [topological_space G] [charted_space H G]
extends has_smooth_add I G : Prop :=
(smooth_neg : smooth I I (λ a:G, -a))
/-- A Lie group is a group and a smooth manifold at the same time in which
the multiplication and inverse operations are smooth. -/
-- See note [Design choices about smooth algebraic structures]
@[ancestor has_smooth_mul, to_additive]
class lie_group {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{H : Type*} [topological_space H]
{E : Type*} [normed_group E] [normed_space 𝕜 E] (I : model_with_corners 𝕜 E H)
(G : Type*) [group G] [topological_space G] [charted_space H G]
extends has_smooth_mul I G : Prop :=
(smooth_inv : smooth I I (λ a:G, a⁻¹))
section lie_group
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{H : Type*} [topological_space H]
{E : Type*} [normed_group E] [normed_space 𝕜 E] {I : model_with_corners 𝕜 E H}
{F : Type*} [normed_group F] [normed_space 𝕜 F] {J : model_with_corners 𝕜 F F}
{G : Type*} [topological_space G] [charted_space H G] [group G] [lie_group I G]
{E' : Type*} [normed_group E'] [normed_space 𝕜 E']
{H' : Type*} [topological_space H'] {I' : model_with_corners 𝕜 E' H'}
{M : Type*} [topological_space M] [charted_space H' M]
{E'' : Type*} [normed_group E''] [normed_space 𝕜 E'']
{H'' : Type*} [topological_space H''] {I'' : model_with_corners 𝕜 E'' H''}
{M' : Type*} [topological_space M'] [charted_space H'' M']
section
variable (I)
@[to_additive]
lemma smooth_inv : smooth I I (λ x : G, x⁻¹) :=
lie_group.smooth_inv
/-- A Lie group is a topological group. This is not an instance for technical reasons,
see note [Design choices about smooth algebraic structures]. -/
@[to_additive
"An additive Lie group is an additive topological group. This is not an instance for technical
reasons, see note [Design choices about smooth algebraic structures]."]
lemma topological_group_of_lie_group : topological_group G :=
{ continuous_inv := (smooth_inv I).continuous,
.. has_continuous_mul_of_smooth I }
end
@[to_additive]
lemma smooth.inv {f : M → G}
(hf : smooth I' I f) : smooth I' I (λx, (f x)⁻¹) :=
(smooth_inv I).comp hf
@[to_additive]
lemma smooth_on.inv {f : M → G} {s : set M}
(hf : smooth_on I' I f s) : smooth_on I' I (λx, (f x)⁻¹) s :=
(smooth_inv I).comp_smooth_on hf
@[to_additive]
lemma smooth.div {f g : M → G}
(hf : smooth I' I f) (hg : smooth I' I g) : smooth I' I (f / g) :=
by { rw div_eq_mul_inv, exact ((smooth_mul I).comp (hf.prod_mk hg.inv) : _), }
@[to_additive]
lemma smooth_on.div {f g : M → G} {s : set M}
(hf : smooth_on I' I f s) (hg : smooth_on I' I g s) : smooth_on I' I (f / g) s :=
by { rw div_eq_mul_inv, exact ((smooth_mul I).comp_smooth_on (hf.prod_mk hg.inv) : _), }
end lie_group
section prod_lie_group
/- Instance of product group -/
@[to_additive]
instance {𝕜 : Type*} [nondiscrete_normed_field 𝕜] {H : Type*} [topological_space H]
{E : Type*} [normed_group E] [normed_space 𝕜 E] {I : model_with_corners 𝕜 E H}
{G : Type*} [topological_space G] [charted_space H G] [group G] [lie_group I G]
{E' : Type*} [normed_group E'] [normed_space 𝕜 E']
{H' : Type*} [topological_space H'] {I' : model_with_corners 𝕜 E' H'}
{G' : Type*} [topological_space G'] [charted_space H' G']
[group G'] [lie_group I' G'] :
lie_group (I.prod I') (G×G') :=
{ smooth_inv := smooth_fst.inv.prod_mk smooth_snd.inv,
..has_smooth_mul.prod _ _ _ _ }
end prod_lie_group
/-! ### Normed spaces are Lie groups -/
instance normed_space_lie_add_group {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E] :
lie_add_group (𝓘(𝕜, E)) E :=
{ smooth_add := smooth_iff.2 ⟨continuous_add, λ x y, cont_diff_add.cont_diff_on⟩,
smooth_neg := smooth_iff.2 ⟨continuous_neg, λ x y, cont_diff_neg.cont_diff_on⟩,
.. model_space_smooth }
|
d871269c3ab73e12c6734eeaffba5453fe38c42e
|
12dabd587ce2621d9a4eff9f16e354d02e206c8e
|
/world10/level05.lean
|
96096f58bc7945654c4def5c866666859c1e4c53
|
[] |
no_license
|
abdelq/natural-number-game
|
a1b5b8f1d52625a7addcefc97c966d3f06a48263
|
bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2
|
refs/heads/master
| 1,668,606,478,691
| 1,594,175,058,000
| 1,594,175,058,000
| 278,673,209
| 0
| 1
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 175
|
lean
|
theorem le_trans (a b c : mynat) (hab : a ≤ b) (hbc : b ≤ c) : a ≤ c :=
begin
cases hab,
cases hbc,
use (hab_w + hbc_w),
rw ← add_assoc,
rw hbc_h,
rw hab_h,
refl,
end
|
060f1ec6be5b46b15338906b9ee5465d79b4b460
|
437dc96105f48409c3981d46fb48e57c9ac3a3e4
|
/src/tactic/norm_cast.lean
|
d891d9556febf826e3f6132b375c272445ae7ab4
|
[
"Apache-2.0"
] |
permissive
|
dan-c-k/mathlib
|
08efec79bd7481ee6da9cc44c24a653bff4fbe0d
|
96efc220f6225bc7a5ed8349900391a33a38cc56
|
refs/heads/master
| 1,658,082,847,093
| 1,589,013,201,000
| 1,589,013,201,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 25,154
|
lean
|
/-
Copyright (c) 2019 Paul-Nicolas Madelaine. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Paul-Nicolas Madelaine, Robert Y. Lewis
Normalizing casts inside expressions.
-/
import tactic.converter.interactive
import tactic.hint
/-!
# A tactic for normalizing casts inside expressions
This tactic normalizes casts inside expressions.
It can be thought of as a call to the simplifier with a specific set of lemmas to
move casts upwards in the expression.
It has special handling of numerals and a simple heuristic to help moving
casts "past" binary operators.
Contrary to simp, it should be safe to use as a non-terminating tactic.
The algorithm implemented here is described in the paper
<https://lean-forward.github.io/norm_cast/norm_cast.pdf>.
## Important definitions
* `tactic.interactive.norm_cast`
* `tactic.interactive.push_cast`
* `tactic.interactive.exact_mod_cast`
* `tactic.interactive.apply_mod_cast`
* `tactic.interactive.rw_mod_cast`
* `tactic.interactive.assumption_mod_cast`
-/
setup_tactic_parser
namespace tactic
/--
Runs `mk_instance` with a time limit.
This is a work around to the fact that in some cases
mk_instance times out instead of failing,
for example: `has_lift_t ℤ ℕ`
`mk_instance_fast` is used when we assume the type class search
should end instantly.
-/
meta def mk_instance_fast (e : expr) (timeout := 1000) : tactic expr :=
try_for timeout (mk_instance e)
end tactic
namespace norm_cast
open tactic expr
declare_trace norm_cast
/--
Output a trace message if `trace.norm_cast` is enabled.
-/
meta def trace_norm_cast {α} [has_to_tactic_format α] (msg : string) (a : α) : tactic unit :=
when_tracing `norm_cast $ do
a ← pp a,
trace ("[norm_cast] " ++ msg ++ a : format)
mk_simp_attribute push_cast "The `push_cast` simp attribute uses `norm_cast` lemmas
to move casts toward the leaf nodes of the expression."
/--
`label` is a type used to classify `norm_cast` lemmas.
* elim lemma: LHS has 0 head coes and ≥ 1 internal coe
* move lemma: LHS has 1 head coe and 0 internal coes, RHS has 0 head coes and ≥ 1 internal coes
* squash lemma: LHS has ≥ 1 head coes and 0 internal coes, RHS has fewer head coes
-/
@[derive [decidable_eq, has_reflect, inhabited]]
inductive label
| elim : label
| move : label
| squash : label
namespace label
/-- Convert `label` into `string`. -/
protected def to_string : label → string
| elim := "elim"
| move := "move"
| squash := "squash"
instance : has_to_string label := ⟨label.to_string⟩
instance : has_repr label := ⟨label.to_string⟩
meta instance : has_to_format label := ⟨λ l, l.to_string⟩
/-- Convert `string` into `label`. -/
def of_string : string -> option label
| "elim" := some elim
| "move" := some move
| "squash" := some squash
| _ := none
end label
open label
/-- Count how many coercions are at the top of the expression. -/
meta def count_head_coes : expr → ℕ
| `(coe %%e) := count_head_coes e + 1
| `(coe_sort %%e) := count_head_coes e + 1
| `(coe_fn %%e) := count_head_coes e + 1
| _ := 0
/-- Count how many coercions are inside the expression, including the top ones. -/
meta def count_coes : expr → tactic ℕ
| `(coe %%e) := (+1) <$> count_coes e
| `(coe_sort %%e) := (+1) <$> count_coes e
| `(coe_fn %%e) := (+1) <$> count_coes e
| (app `(coe_fn %%e) x) := (+) <$> count_coes x <*> (+1) <$> count_coes e
| (expr.lam n bi t e) := do
l ← mk_local' n bi t,
count_coes $ e.instantiate_var l
| e := do
as ← e.get_simp_args,
list.sum <$> as.mmap count_coes
/-- Count how many coercions are inside the expression, excluding the top ones. -/
private meta def count_internal_coes (e : expr) : tactic ℕ := do
ncoes ← count_coes e,
pure $ ncoes - count_head_coes e
/--
Classifies a declaration of type `ty` as a `norm_cast` rule.
-/
meta def classify_type (ty : expr) : tactic label := do
(_, ty) ← mk_local_pis ty,
(lhs, rhs) ← match ty with
| `(%%lhs = %%rhs) := pure (lhs, rhs)
| `(%%lhs ↔ %%rhs) := pure (lhs, rhs)
| _ := fail "norm_cast: lemma must be = or ↔"
end,
lhs_coes ← count_coes lhs,
when (lhs_coes = 0) $ fail "norm_cast: badly shaped lemma, lhs must contain at least one coe",
let lhs_head_coes := count_head_coes lhs,
lhs_internal_coes ← count_internal_coes lhs,
let rhs_head_coes := count_head_coes rhs,
rhs_internal_coes ← count_internal_coes rhs,
if lhs_head_coes = 0 then
return elim
else if lhs_head_coes = 1 then do
when (rhs_head_coes ≠ 0) $ fail "norm_cast: badly shaped lemma, rhs can't start with coe",
if rhs_internal_coes = 0 then
return squash
else
return move
else if rhs_head_coes < lhs_head_coes then do
return squash
else do
fail "norm_cast: badly shaped shaped squash lemma, rhs must have fewer head coes than lhs"
/-- The cache for `norm_cast` attribute stores three `simp_lemma` objects. -/
meta structure norm_cast_cache :=
(up : simp_lemmas)
(down : simp_lemmas)
(squash : simp_lemmas)
/-- Empty `norm_cast_cache`. -/
meta def empty_cache : norm_cast_cache :=
{ up := simp_lemmas.mk,
down := simp_lemmas.mk,
squash := simp_lemmas.mk, }
meta instance : inhabited norm_cast_cache := ⟨empty_cache⟩
/-- `add_elim cache e` adds `e` as an `elim` lemma to `cache`. -/
meta def add_elim (cache : norm_cast_cache) (e : expr) : tactic norm_cast_cache :=
do
new_up ← simp_lemmas.add cache.up e,
return
{ up := new_up,
down := cache.down,
squash := cache.squash, }
/-- `add_move cache e` adds `e` as a `move` lemma to `cache`. -/
meta def add_move (cache : norm_cast_cache) (e : expr) : tactic norm_cast_cache :=
do
ty ← infer_type e,
new_up ← cache.up.add e tt,
new_down ← simp_lemmas.add cache.down e,
return {
up := new_up,
down := new_down,
squash := cache.squash, }
/-- `add_squash cache e` adds `e` as an `squash` lemma to `cache`. -/
meta def add_squash (cache : norm_cast_cache) (e : expr) : tactic norm_cast_cache :=
do
new_squash ← simp_lemmas.add cache.squash e,
new_down ← simp_lemmas.add cache.down e,
return {
up := cache.up,
down := new_down,
squash := new_squash, }
/--
The type of the `norm_cast` attribute.
The optional label is used to overwrite the classifier.
-/
meta def norm_cast_attr_ty : Type := user_attribute norm_cast_cache (option label)
/-- Efficient getter for the `@[norm_cast]` attribute parameter that does not call `eval_expr`. -/
meta def get_label_param (attr : norm_cast_attr_ty) (decl : name) : tactic (option label) := do
p ← attr.get_param_untyped decl,
match p with
| `(none) := pure none
| `(some label.elim) := pure label.elim
| `(some label.move) := pure label.move
| `(some label.squash) := pure label.squash
| _ := fail p
end
/--
`add_lemma cache decl` infers the proper `norm_cast` attribute for `decl` and adds it to `cache`.
-/
meta def add_lemma (attr : norm_cast_attr_ty) (cache : norm_cast_cache) (decl : name) :
tactic norm_cast_cache :=
do
e ← mk_const decl,
param ← get_label_param attr decl,
l ← param <|> (infer_type e >>= classify_type),
match l with
| elim := add_elim cache e
| move := add_move cache e
| squash := add_squash cache e
end
-- special lemmas to handle the ≥, > and ≠ operators
private lemma ge_from_le {α} [has_le α] : ∀ (x y : α), x ≥ y ↔ y ≤ x := λ _ _, iff.rfl
private lemma gt_from_lt {α} [has_lt α] : ∀ (x y : α), x > y ↔ y < x := λ _ _, iff.rfl
private lemma ne_from_not_eq {α} : ∀ (x y : α), x ≠ y ↔ ¬(x = y) := λ _ _, iff.rfl
/--
`mk_cache names` creates a `norm_cast_cache`. It infers the proper `norm_cast` attributes
for names in `names`, and collects the lemmas attributed with specific `norm_cast` attributes.
-/
meta def mk_cache (attr : thunk norm_cast_attr_ty) (names : list name) :
tactic norm_cast_cache := do
-- names has the declarations in reverse order
cache ← names.mfoldr (λ name cache, add_lemma (attr ()) cache name) empty_cache,
--some special lemmas to handle binary relations
let up := cache.up,
up ← up.add_simp ``ge_from_le,
up ← up.add_simp ``gt_from_lt,
up ← up.add_simp ``ne_from_not_eq,
let down := cache.down,
down ← down.add_simp ``coe_coe,
pure { up := up, down := down, squash := cache.squash }
/--
The `norm_cast` attribute.
-/
@[user_attribute] meta def norm_cast_attr : user_attribute norm_cast_cache (option label) :=
{ name := `norm_cast,
descr := "attribute for norm_cast",
parser :=
(do some l ← (label.of_string ∘ to_string) <$> ident, return l)
<|> return none,
after_set := some (λ decl prio persistent, do
param ← get_label_param norm_cast_attr decl,
match param with
| some l :=
when (l ≠ elim) $ simp_attr.push_cast.set decl () tt
| none := do
e ← mk_const decl,
ty ← infer_type e,
l ← classify_type ty,
norm_cast_attr.set decl l persistent prio
end),
before_unset := some $ λ _ _, tactic.skip,
cache_cfg := { mk_cache := mk_cache norm_cast_attr, dependencies := [] } }
/-- Classify a declaration as a `norm_cast` rule. -/
meta def make_guess (decl : name) : tactic label :=
do
e ← mk_const decl,
ty ← infer_type e,
classify_type ty
/--
Gets the `norm_cast` classification label for a declaration. Applies the
override specified on the attribute, if necessary.
-/
meta def get_label (decl : name) : tactic label :=
do
param ← get_label_param norm_cast_attr decl,
param <|> make_guess decl
end norm_cast
namespace tactic.interactive
open norm_cast
/--
`push_cast` rewrites the expression to move casts toward the leaf nodes.
For example, `↑(a + b)` will be written to `↑a + ↑b`.
Equivalent to `simp only with push_cast`.
Can also be used at hypotheses.
-/
meta def push_cast (l : parse location): tactic unit :=
tactic.interactive.simp none tt [] [`push_cast] l
end tactic.interactive
namespace norm_cast
open tactic expr
/-- Prove `a = b` using the given simp set. -/
meta def prove_eq_using (s : simp_lemmas) (a b : expr) : tactic expr := do
(a', a_a') ← simplify s [] a {fail_if_unchanged := ff},
(b', b_b') ← simplify s [] b {fail_if_unchanged := ff},
on_exception (trace_norm_cast "failed: " (to_expr ``(%%a' = %%b') >>= pp)) $
is_def_eq a' b' reducible,
b'_b ← mk_eq_symm b_b',
mk_eq_trans a_a' b'_b
/-- Prove `a = b` by simplifying using move and squash lemmas. -/
meta def prove_eq_using_down (a b : expr) : tactic expr := do
cache ← norm_cast_attr.get_cache,
trace_norm_cast "proving: " (to_expr ``(%%a = %%b) >>= pp),
prove_eq_using cache.down a b
/--
This is the main heuristic used alongside the elim and move lemmas.
The goal is to help casts move past operators by adding intermediate casts.
An expression of the shape: op (↑(x : α) : γ) (↑(y : β) : γ)
is rewritten to: op (↑(↑(x : α) : β) : γ) (↑(y : β) : γ)
when (↑(↑(x : α) : β) : γ) = (↑(x : α) : γ) can be proven with a squash lemma
-/
meta def splitting_procedure : expr → tactic (expr × expr)
| (app (app op x) y) :=
(do
`(@coe %%α %%δ %%coe1 %%xx) ← return x,
`(@coe %%β %%γ %%coe2 %%yy) ← return y,
success_if_fail $ is_def_eq α β,
is_def_eq δ γ,
(do
coe3 ← mk_app `has_lift_t [α, β] >>= mk_instance_fast,
new_x ← to_expr ``(@coe %%β %%δ %%coe2 (@coe %%α %%β %%coe3 %%xx)),
let new_e := app (app op new_x) y,
eq_x ← prove_eq_using_down x new_x,
pr ← mk_congr_arg op eq_x,
pr ← mk_congr_fun pr y,
return (new_e, pr)
) <|> (do
coe3 ← mk_app `has_lift_t [β, α] >>= mk_instance_fast,
new_y ← to_expr ``(@coe %%α %%δ %%coe1 (@coe %%β %%α %%coe3 %%yy)),
let new_e := app (app op x) new_y,
eq_y ← prove_eq_using_down y new_y,
pr ← mk_congr_arg (app op x) eq_y,
return (new_e, pr)
)
) <|> (do
`(@coe %%α %%β %%coe1 %%xx) ← return x,
`(@has_one.one %%β %%h1) ← return y,
h2 ← to_expr ``(has_one %%α) >>= mk_instance_fast,
new_y ← to_expr ``(@coe %%α %%β %%coe1 (@has_one.one %%α %%h2)),
eq_y ← prove_eq_using_down y new_y,
let new_e := app (app op x) new_y,
pr ← mk_congr_arg (app op x) eq_y,
return (new_e, pr)
) <|> (do
`(@coe %%α %%β %%coe1 %%xx) ← return x,
`(@has_zero.zero %%β %%h1) ← return y,
h2 ← to_expr ``(has_zero %%α) >>= mk_instance_fast,
new_y ← to_expr ``(@coe %%α %%β %%coe1 (@has_zero.zero %%α %%h2)),
eq_y ← prove_eq_using_down y new_y,
let new_e := app (app op x) new_y,
pr ← mk_congr_arg (app op x) eq_y,
return (new_e, pr)
) <|> (do
`(@has_one.one %%β %%h1) ← return x,
`(@coe %%α %%β %%coe1 %%xx) ← return y,
h1 ← to_expr ``(has_one %%α) >>= mk_instance_fast,
new_x ← to_expr ``(@coe %%α %%β %%coe1 (@has_one.one %%α %%h1)),
eq_x ← prove_eq_using_down x new_x,
let new_e := app (app op new_x) y,
pr ← mk_congr_arg (lam `x binder_info.default β (app (app op (var 0)) y)) eq_x,
return (new_e, pr)
) <|> (do
`(@has_zero.zero %%β %%h1) ← return x,
`(@coe %%α %%β %%coe1 %%xx) ← return y,
h1 ← to_expr ``(has_zero %%α) >>= mk_instance_fast,
new_x ← to_expr ``(@coe %%α %%β %%coe1 (@has_zero.zero %%α %%h1)),
eq_x ← prove_eq_using_down x new_x,
let new_e := app (app op new_x) y,
pr ← mk_congr_arg (lam `x binder_info.default β (app (app op (var 0)) y)) eq_x,
return (new_e, pr)
)
| _ := failed
/--
Discharging function used during simplification in the "squash" step.
TODO: norm_cast takes a list of expressions to use as lemmas for the discharger
TODO: a tactic to print the results the discharger fails to proove
-/
private meta def prove : tactic unit :=
assumption
/--
Core rewriting function used in the "squash" step, which moves casts upwards
and eliminates them.
It tries to rewrite an expression using the elim and move lemmas.
On failure, it calls the splitting procedure heuristic.
-/
meta def upward_and_elim (s : simp_lemmas) (e : expr) : tactic (expr × expr) :=
(do
r ← mcond (is_prop e) (return `iff) (return `eq),
(new_e, pr) ← s.rewrite e prove r,
pr ← match r with
| `iff := mk_app `propext [pr]
| _ := return pr
end,
return (new_e, pr)
) <|> splitting_procedure e
/-!
The following auxiliary functions are used to handle numerals.
-/
/--
If possible, rewrite `(n : α)` to `((n : ℕ) : α)` where `n` is a numeral and `α ≠ ℕ`.
Returns a pair of the new expression and proof that they are equal.
-/
meta def numeral_to_coe (e : expr) : tactic (expr × expr) :=
do
α ← infer_type e,
success_if_fail $ is_def_eq α `(ℕ),
n ← e.to_nat,
h1 ← mk_app `has_lift_t [`(ℕ), α] >>= mk_instance_fast,
let new_e : expr := reflect n,
new_e ← to_expr ``(@coe ℕ %%α %%h1 %%new_e),
pr ← prove_eq_using_down e new_e,
return (new_e, pr)
/--
If possible, rewrite `((n : ℕ) : α)` to `(n : α)` where `n` is a numeral.
Returns a pair of the new expression and proof that they are equal.
-/
meta def coe_to_numeral (e : expr) : tactic (expr × expr) :=
do
`(@coe ℕ %%α %%h1 %%e') ← return e,
n ← e'.to_nat,
-- replace e' by normalized numeral
is_def_eq (reflect n) e' reducible,
let e := e.app_fn (reflect n),
new_e ← expr.of_nat α n,
pr ← prove_eq_using_down e new_e,
return (new_e, pr)
/-- A local variant on `simplify_top_down`. -/
private meta def simplify_top_down' {α} (a : α) (pre : α → expr → tactic (α × expr × expr))
(e : expr) (cfg : simp_config := {}) : tactic (α × expr × expr) :=
ext_simplify_core a cfg simp_lemmas.mk (λ _, failed)
(λ a _ _ _ e, do
(new_a, new_e, pr) ← pre a e,
guard (¬ new_e =ₐ e),
return (new_a, new_e, some pr, ff))
(λ _ _ _ _ _, failed)
`eq e
/--
The core simplification routine of `norm_cast`.
-/
meta def derive (e : expr) : tactic (expr × expr) :=
do
cache ← norm_cast_attr.get_cache,
e ← instantiate_mvars e,
let cfg : simp_config := {
zeta := ff,
beta := ff,
eta := ff,
proj := ff,
iota := ff,
iota_eqn := ff,
fail_if_unchanged := ff },
let e0 := e,
-- step 1: pre-processing of numerals
((), e1, pr1) ← simplify_top_down' () (λ _ e, prod.mk () <$> numeral_to_coe e) e0 cfg,
trace_norm_cast "after numeral_to_coe: " e1,
-- step 2: casts are moved upwards and eliminated
((), e2, pr2) ← simplify_bottom_up () (λ _ e, prod.mk () <$> upward_and_elim cache.up e) e1 cfg,
trace_norm_cast "after upward_and_elim: " e2,
-- step 3: casts are squashed
(e3, pr3) ← simplify cache.squash [] e2 cfg,
trace_norm_cast "after squashing: " e3,
-- step 4: post-processing of numerals
((), e4, pr4) ← simplify_top_down' () (λ _ e, prod.mk () <$> coe_to_numeral e) e3 cfg,
trace_norm_cast "after coe_to_numeral: " e4,
let new_e := e4,
guard (¬ new_e =ₐ e),
pr ← mk_eq_trans pr1 pr2,
pr ← mk_eq_trans pr pr3,
pr ← mk_eq_trans pr pr4,
return (new_e, pr)
end norm_cast
namespace tactic
open expr norm_cast
/-- `aux_mod_cast e` runs `norm_cast` on `e` and returns the result. If `include_goal` is true, it
also normalizes the goal. -/
meta def aux_mod_cast (e : expr) (include_goal : bool := tt) : tactic expr :=
match e with
| local_const _ lc _ _ := do
e ← get_local lc,
replace_at derive [e] include_goal,
get_local lc
| e := do
t ← infer_type e,
e ← assertv `this t e,
replace_at derive [e] include_goal,
get_local `this
end
/-- `exact_mod_cast e` runs `norm_cast` on the goal and `e`, and tries to use `e` to close the goal. -/
meta def exact_mod_cast (e : expr) : tactic unit :=
decorate_error "exact_mod_cast failed:" $ do
new_e ← aux_mod_cast e,
exact new_e
/-- `apply_mod_cast e` runs `norm_cast` on the goal and `e`, and tries to apply `e`. -/
meta def apply_mod_cast (e : expr) : tactic (list (name × expr)) :=
decorate_error "apply_mod_cast failed:" $ do
new_e ← aux_mod_cast e,
apply new_e
/-- `assumption_mod_cast` runs `norm_cast` on the goal. For each local hypothesis `h`, it also
normalizes `h` and tries to use that to close the goal. -/
meta def assumption_mod_cast : tactic unit :=
decorate_error "assumption_mod_cast failed:" $ do
let cfg : simp_config := {
fail_if_unchanged := ff,
canonize_instances := ff,
canonize_proofs := ff,
proj := ff
},
replace_at derive [] tt,
ctx ← local_context,
try_lst $ ctx.map (λ h, aux_mod_cast h ff >>= tactic.exact)
end tactic
namespace tactic.interactive
open tactic norm_cast
/--
Normalize casts at the given locations by moving them "upwards".
As opposed to simp, norm_cast can be used without necessarily closing the goal.
-/
meta def norm_cast (loc : parse location) : tactic unit :=
do
ns ← loc.get_locals,
tt ← replace_at derive ns loc.include_goal | fail "norm_cast failed to simplify",
when loc.include_goal $ try tactic.reflexivity,
when loc.include_goal $ try tactic.triv,
when (¬ ns.empty) $ try tactic.contradiction
/--
Rewrite with the given rules and normalize casts between steps.
-/
meta def rw_mod_cast (rs : parse rw_rules) (loc : parse location) : tactic unit :=
decorate_error "rw_mod_cast failed:" $ do
let cfg_norm : simp_config := {},
let cfg_rw : rewrite_cfg := {},
ns ← loc.get_locals,
monad.mapm' (λ r : rw_rule, do
save_info r.pos,
replace_at derive ns loc.include_goal,
rw ⟨[r], none⟩ loc {}
) rs.rules,
replace_at derive ns loc.include_goal,
skip
/--
Normalize the goal and the given expression, then close the goal with exact.
-/
meta def exact_mod_cast (e : parse texpr) : tactic unit :=
do
e ← i_to_expr e <|> do {
ty ← target,
e ← i_to_expr_strict ``(%%e : %%ty),
pty ← pp ty, ptgt ← pp e,
fail ("exact_mod_cast failed, expression type not directly " ++
"inferrable. Try:\n\nexact_mod_cast ...\nshow " ++
to_fmt pty ++ ",\nfrom " ++ ptgt : format)
},
tactic.exact_mod_cast e
/--
Normalize the goal and the given expression, then apply the expression to the goal.
-/
meta def apply_mod_cast (e : parse texpr) : tactic unit :=
do
e ← i_to_expr_for_apply e,
concat_tags $ tactic.apply_mod_cast e
/--
Normalize the goal and every expression in the local context, then close the goal with assumption.
-/
meta def assumption_mod_cast : tactic unit :=
tactic.assumption_mod_cast
end tactic.interactive
namespace conv.interactive
open conv
open norm_cast (derive)
/-- the converter version of `norm_cast' -/
meta def norm_cast : conv unit := replace_lhs derive
end conv.interactive
-- TODO: move this elsewhere?
@[norm_cast] lemma ite_cast {α β} [has_lift_t α β]
{c : Prop} [decidable c] {a b : α} :
↑(ite c a b) = ite c (↑a : β) (↑b : β) :=
by by_cases h : c; simp [h]
add_hint_tactic "norm_cast at *"
/--
The `norm_cast` family of tactics is used to normalize casts inside expressions.
It is basically a simp tactic with a specific set of lemmas to move casts
upwards in the expression.
Therefore it can be used more safely as a non-terminating tactic.
It also has special handling of numerals.
For instance, given an assumption
```lean
a b : ℤ
h : ↑a + ↑b < (10 : ℚ)
```
writing `norm_cast at h` will turn `h` into
```lean
h : a + b < 10
```
You can also use `exact_mod_cast`, `apply_mod_cast`, `rw_mod_cast`
or `assumption_mod_cast`.
Writing `exact_mod_cast h` and `apply_mod_cast h` will normalize the goal and
`h` before using `exact h` or `apply h`.
Writing `assumption_mod_cast` will normalize the goal and for every
expression `h` in the context it will try to normalize `h` and use
`exact h`.
`rw_mod_cast` acts like the `rw` tactic but it applies `norm_cast` between steps.
`push_cast` rewrites the expression to move casts toward the leaf nodes.
This uses `norm_cast` lemmas in the forward direction.
For example, `↑(a + b)` will be written to `↑a + ↑b`.
It is equivalent to `simp only with push_cast`, and can also be used at hypotheses
with `push_cast at h`.
The implementation and behavior of the `norm_cast` family is described in detail at
<https://lean-forward.github.io/norm_cast/norm_cast.pdf>.
-/
add_tactic_doc
{ name := "norm_cast",
category := doc_category.tactic,
decl_names := [``tactic.interactive.norm_cast, ``tactic.interactive.rw_mod_cast,
``tactic.interactive.apply_mod_cast, ``tactic.interactive.assumption_mod_cast,
``tactic.interactive.exact_mod_cast, ``tactic.interactive.push_cast],
tags := ["coercions", "simplification"] }
/--
The `norm_cast` attribute should be given to lemmas that describe the
behaviour of a coercion in regard to an operator, a relation, or a particular
function.
It only concerns equality or iff lemmas involving `↑`, `⇑` and `↥`, describing the behavior of
the coercion functions.
It does not apply to the explicit functions that define the coercions.
Examples:
```lean
@[norm_cast] theorem coe_nat_inj' {m n : ℕ} : (↑m : ℤ) = ↑n ↔ m = n
@[norm_cast] theorem coe_int_denom (n : ℤ) : (n : ℚ).denom = 1
@[norm_cast] theorem cast_id : ∀ n : ℚ, ↑n = n
@[norm_cast] theorem coe_nat_add (m n : ℕ) : (↑(m + n) : ℤ) = ↑m + ↑n
@[norm_cast] theorem cast_sub [add_group α] [has_one α] {m n} (h : m ≤ n) :
((n - m : ℕ) : α) = n - m
@[norm_cast] theorem coe_nat_bit0 (n : ℕ) : (↑(bit0 n) : ℤ) = bit0 ↑n
@[norm_cast] theorem cast_coe_nat (n : ℕ) : ((n : ℤ) : α) = n
@[norm_cast] theorem cast_one : ((1 : ℚ) : α) = 1
```
Lemmas tagged with `@[norm_cast]` are classified into three categories: `move`, `elim`, and `squash`.
They are classified roughly as follows:
* elim lemma: LHS has 0 head coes and ≥ 1 internal coe
* move lemma: LHS has 1 head coe and 0 internal coes, RHS has 0 head coes and ≥ 1 internal coes
* squash lemma: LHS has ≥ 1 head coes and 0 internal coes, RHS has fewer head coes
`norm_cast` uses `move` and `elim` lemmas to factor coercions toward the root of an expression
and to cancel them from both sides of an equation or relation. It uses `squash` lemmas to clean
up the result.
Occasionally you may want to override the automatic classification.
You can do this by giving an optional `elim`, `move`, or `squash` parameter to the attribute.
```lean
@[simp, norm_cast elim] lemma nat_cast_re (n : ℕ) : (n : ℂ).re = n :=
by rw [← of_real_nat_cast, of_real_re]
```
Don't do this unless you understand what you are doing.
A full description of the tactic, and the use of each lemma category, can be found at
<https://lean-forward.github.io/norm_cast/norm_cast.pdf>.
-/
add_tactic_doc
{ name := "norm_cast attributes",
category := doc_category.attr,
decl_names := [``norm_cast.norm_cast_attr],
tags := ["coercions", "simplification"] }
-- Lemmas defined in core.
attribute [norm_cast]
int.nat_abs_of_nat
int.coe_nat_sub
int.coe_nat_mul
int.coe_nat_zero
int.coe_nat_one
int.coe_nat_add
-- Lemmas about nat.succ need to get a low priority, so that they are tried last.
-- This is because `nat.succ _` matches `1`, `3`, `x+1`, etc.
-- Rewriting would then produce really wrong terms.
attribute [norm_cast, priority 500] int.coe_nat_succ
|
db2fdcd9aafbec37b70df4d8308bfe9f423d2af7
|
a8c03ed21a1bd6fc45901943b79dd6574ea3f0c2
|
/splitting.lean
|
1eb50df74249831c6e3df61bd296fec17ab06632
|
[] |
no_license
|
gebner/resolution.lean
|
716c355fbb5204e5c4d0c5a7f3f3cc825892a2bf
|
c6fafe06fba1cfad73db68f2aa474b29fe892a2b
|
refs/heads/master
| 1,601,111,444,528
| 1,475,256,701,000
| 1,475,256,701,000
| 67,711,151
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,744
|
lean
|
import prover_state
open monad
meta def extract_assertions : clause → resolution_prover (clause × list expr) | c :=
if c↣num_lits = 0 then return (c, [])
else if c↣num_quants ≠ 0 then do
qf : clause × list expr ← ↑(c↣open_constn c↣num_quants),
qf_wo_as ← extract_assertions qf↣1,
return (qf_wo_as↣1↣close_constn qf↣2, qf_wo_as↣2)
else do
hd ← return $ c↣get_lit 0,
hyp_opt ← get_sat_hyp_core hd↣formula hd↣is_neg,
match hyp_opt with
| some h := do
wo_as ← extract_assertions (c↣inst h),
return (wo_as↣1, h :: wo_as↣2)
| _ := do
op : clause × expr ← ↑c↣open_const,
op_wo_as ← extract_assertions op↣1,
return (op_wo_as↣1↣close_const op↣2, op_wo_as↣2)
end
meta def splitting_inf : inference := take given,
if given↣c↣num_lits ≤ 1 then return () else do
forM given↣c↣get_lits (λl,
if l↣formula↣has_var ∨ l↣formula↣is_not↣is_some then
return ()
else
mk_sat_var l↣formula l↣is_neg),
with_ass ← extract_assertions given↣c,
if with_ass↣2↣length > 0 then do
add_inferred with_ass↣1 [given],
remove_redundant given↣id []
else
return ()
meta def splitting_pre : resolution_prover unit :=
preprocessing_rule $ take news, do flip filterM news $ take new, do
ass ← collect_ass_hyps new,
if new↣num_quants = 0 ∧ new↣num_lits > 1 then do
add_sat_clause $ new↣close_constn ass,
return ff
else if new↣num_quants = 0 ∧ new↣num_lits = 1 then do
hd ← return $ new↣get_lit 0,
hyp ← get_sat_hyp_core hd↣formula hd↣is_neg,
if hyp↣is_some then do
add_sat_clause $ new↣close_constn ass,
return ff
else
return tt
else
return tt
|
3d8b28ba1a662eb8243051932b18bba76c2b8d50
|
dd0f5513e11c52db157d2fcc8456d9401a6cd9da
|
/08_Building_Theories_and_Proofs.org.6.lean
|
e993a16ef2b68304e96fe0ce6cf40ac1f9d06433
|
[] |
no_license
|
cjmazey/lean-tutorial
|
ba559a49f82aa6c5848b9bf17b7389bf7f4ba645
|
381f61c9fcac56d01d959ae0fa6e376f2c4e3b34
|
refs/heads/master
| 1,610,286,098,832
| 1,447,124,923,000
| 1,447,124,923,000
| 43,082,433
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 630
|
lean
|
import standard
structure Semigroup : Type :=
(carrier : Type)
(mul : carrier → carrier → carrier)
(mul_assoc : ∀ a b c : carrier, mul (mul a b) c = mul a (mul b c))
notation a `*` b := Semigroup.mul _ a b
attribute Semigroup.carrier [coercion]
structure morphism (S1 S2 : Semigroup) : Type :=
(mor : S1 → S2)
(resp_mul : ∀ a b : S1, mor (a * b) = (mor a) * (mor b))
-- BEGIN
attribute morphism.mor [coercion]
example (S1 S2 : Semigroup) (f : morphism S1 S2) (a : S1) :
f (a * a * a) = f a * f a * f a :=
calc
f (a * a * a) = f (a * a) * f a : morphism.resp_mul f
... = f a * f a * f a : morphism.resp_mul f
-- END
|
eb8fad0dc26c4c43729520117d05092af017ae95
|
618003631150032a5676f229d13a079ac875ff77
|
/src/category_theory/limits/types.lean
|
7d03057dbdfe2a1105ed8cd5d16113f020c72311
|
[
"Apache-2.0"
] |
permissive
|
awainverse/mathlib
|
939b68c8486df66cfda64d327ad3d9165248c777
|
ea76bd8f3ca0a8bf0a166a06a475b10663dec44a
|
refs/heads/master
| 1,659,592,962,036
| 1,590,987,592,000
| 1,590,987,592,000
| 268,436,019
| 1
| 0
|
Apache-2.0
| 1,590,990,500,000
| 1,590,990,500,000
| null |
UTF-8
|
Lean
| false
| false
| 5,359
|
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
-/
import category_theory.limits.shapes.images
universes v u -- declare the `v`'s first; see `category_theory.category` for an explanation
open category_theory
open category_theory.limits
namespace category_theory.limits.types
variables {J : Type u} [small_category J]
/-- (internal implementation) the limit cone of a functor, implemented as flat sections of a pi type -/
def limit_ (F : J ⥤ Type u) : cone F :=
{ X := F.sections,
π := { app := λ j u, u.val j } }
local attribute [elab_simple] congr_fun
/-- (internal implementation) the fact that the proposed limit cone is the limit -/
def limit_is_limit_ (F : J ⥤ Type u) : is_limit (limit_ F) :=
{ lift := λ s v, ⟨λ j, s.π.app j v, λ j j' f, congr_fun (cone.w s f) _⟩,
uniq' :=
begin
intros, ext x, apply subtype.eq, ext j,
exact congr_fun (w j) x
end }
instance : has_limits.{u} (Type u) :=
{ has_limits_of_shape := λ J 𝒥,
{ has_limit := λ F, by exactI { cone := limit_ F, is_limit := limit_is_limit_ F } } }
@[simp] lemma types_limit (F : J ⥤ Type u) :
limits.limit F = {u : Π j, F.obj j // ∀ {j j'} f, F.map f (u j) = u j'} := rfl
@[simp] lemma types_limit_π (F : J ⥤ Type u) (j : J) (g : limit F) :
limit.π F j g = g.val j := rfl
@[simp] lemma types_limit_pre
(F : J ⥤ Type u) {K : Type u} [𝒦 : small_category K] (E : K ⥤ J) (g : limit F) :
limit.pre F E g = (⟨λ k, g.val (E.obj k), by obviously⟩ : limit (E ⋙ F)) := rfl
@[simp] lemma types_limit_map {F G : J ⥤ Type u} (α : F ⟶ G) (g : limit F) :
(lim.map α : limit F → limit G) g =
(⟨λ j, (α.app j) (g.val j), λ j j' f,
by {rw ←functor_to_types.naturality, dsimp, rw ←(g.property f)}⟩ : limit G) := rfl
@[simp] lemma types_limit_lift (F : J ⥤ Type u) (c : cone F) (x : c.X) :
limit.lift F c x = (⟨λ j, c.π.app j x, λ j j' f, congr_fun (cone.w c f) x⟩ : limit F) :=
rfl
/-- (internal implementation) the limit cone of a functor, implemented as a quotient of a sigma type -/
def colimit_ (F : J ⥤ Type u) : cocone F :=
{ X := @quot (Σ j, F.obj j) (λ p p', ∃ f : p.1 ⟶ p'.1, p'.2 = F.map f p.2),
ι :=
{ app := λ j x, quot.mk _ ⟨j, x⟩,
naturality' := λ j j' f, funext $ λ x, eq.symm (quot.sound ⟨f, rfl⟩) } }
local attribute [elab_with_expected_type] quot.lift
/-- (internal implementation) the fact that the proposed colimit cocone is the colimit -/
def colimit_is_colimit_ (F : J ⥤ Type u) : is_colimit (colimit_ F) :=
{ desc := λ s, quot.lift (λ (p : Σ j, F.obj j), s.ι.app p.1 p.2)
(assume ⟨j, x⟩ ⟨j', x'⟩ ⟨f, hf⟩, by rw hf; exact (congr_fun (cocone.w s f) x).symm) }
instance : has_colimits.{u} (Type u) :=
{ has_colimits_of_shape := λ J 𝒥,
{ has_colimit := λ F, by exactI { cocone := colimit_ F, is_colimit := colimit_is_colimit_ F } } }
@[simp] lemma types_colimit (F : J ⥤ Type u) :
limits.colimit F = @quot (Σ j, F.obj j) (λ p p', ∃ f : p.1 ⟶ p'.1, p'.2 = F.map f p.2) := rfl
@[simp] lemma types_colimit_ι (F : J ⥤ Type u) (j : J) :
colimit.ι F j = λ x, quot.mk _ ⟨j, x⟩ := rfl
@[simp] lemma types_colimit_pre
(F : J ⥤ Type u) {K : Type u} [𝒦 : small_category K] (E : K ⥤ J) :
colimit.pre F E =
quot.lift (λ p, quot.mk _ ⟨E.obj p.1, p.2⟩) (λ p p' ⟨f, h⟩, quot.sound ⟨E.map f, h⟩) := rfl
@[simp] lemma types_colimit_map {F G : J ⥤ Type u} (α : F ⟶ G) :
(colim.map α : colimit F → colimit G) =
quot.lift
(λ p, quot.mk _ ⟨p.1, (α.app p.1) p.2⟩)
(λ p p' ⟨f, h⟩, quot.sound ⟨f, by rw h; exact functor_to_types.naturality _ _ α f _⟩) := rfl
@[simp] lemma types_colimit_desc (F : J ⥤ Type u) (c : cocone F) :
colimit.desc F c =
quot.lift
(λ p, c.ι.app p.1 p.2)
(λ p p' ⟨f, h⟩, by rw h; exact (functor_to_types.naturality _ _ c.ι f _).symm) := rfl
variables {α β : Type u} (f : α ⟶ β)
section -- implementation of `has_image`
/-- the image of a morphism in Type is just `set.range f` -/
def image : Type u := set.range f
instance [inhabited α] : inhabited (image f) :=
{ default := ⟨f (default α), ⟨_, rfl⟩⟩ }
/-- the inclusion of `image f` into the target -/
def image.ι : image f ⟶ β := subtype.val
instance : mono (image.ι f) :=
(mono_iff_injective _).2 subtype.val_injective
variables {f}
/-- the universal property for the image factorisation -/
noncomputable def image.lift (F' : mono_factorisation f) : image f ⟶ F'.I :=
(λ x, F'.e (classical.indefinite_description _ x.2).1 : image f → F'.I)
lemma image.lift_fac (F' : mono_factorisation f) : image.lift F' ≫ F'.m = image.ι f :=
begin
ext x,
change (F'.e ≫ F'.m) _ = _,
rw [F'.fac, (classical.indefinite_description _ x.2).2],
refl,
end
end
/-- the factorisation of any morphism in AddCommGroup through a mono. -/
def mono_factorisation : mono_factorisation f :=
{ I := image f,
m := image.ι f,
e := set.range_factorization f }
noncomputable instance : has_image f :=
{ F := mono_factorisation f,
is_image :=
{ lift := image.lift,
lift_fac' := image.lift_fac } }
noncomputable instance : has_images.{u} (Type u) :=
{ has_image := infer_instance }
end category_theory.limits.types
|
0ba4ae4e5ec033cdbf1c1b99b126b20e7469aeb8
|
6bbefddc5d215af92ee0f41cafc343d0802aa6c8
|
/02-hundred-squares.lean
|
9f10d10555b32d7cf169a51f0bf533414a75d55a
|
[
"Unlicense"
] |
permissive
|
bradheintz/lean-ex
|
0dcfab24e31abd9394247353f4e7dfd06655b2e1
|
37419b8d014ba3ba416e2252809a89a1604a1330
|
refs/heads/master
| 1,645,696,373,325
| 1,503,243,879,000
| 1,503,243,879,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 347
|
lean
|
import system.io
variable [io.interface]
open io nat
/-
print square of every integer from n to 0
-/
def print_squares : ℕ → io unit
| 0 := return ()
| (succ n) := print_squares n >>
put_str (nat.to_string n ++ "^2 = " ++ nat.to_string (n * n)
++ "\n")
#eval print_squares 32
#print axioms print_squares
|
12cefe91c0c131b2c7aaef74a6946d9f07871034
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/measure_theory/function/ae_eq_of_integral.lean
|
b847808f2a0ceda7b7aec3119387c0b8ee72718e
|
[
"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
| 29,195
|
lean
|
/-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import analysis.normed_space.dual
import measure_theory.function.strongly_measurable.lp
import measure_theory.integral.set_integral
/-! # From equality of integrals to equality of functions
This file provides various statements of the general form "if two functions have the same integral
on all sets, then they are equal almost everywhere".
The different lemmas use various hypotheses on the class of functions, on the target space or on the
possible finiteness of the measure.
## Main statements
All results listed below apply to two functions `f, g`, together with two main hypotheses,
* `f` and `g` are integrable on all measurable sets with finite measure,
* for all measurable sets `s` with finite measure, `∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ`.
The conclusion is then `f =ᵐ[μ] g`. The main lemmas are:
* `ae_eq_of_forall_set_integral_eq_of_sigma_finite`: case of a sigma-finite measure.
* `ae_fin_strongly_measurable.ae_eq_of_forall_set_integral_eq`: for functions which are
`ae_fin_strongly_measurable`.
* `Lp.ae_eq_of_forall_set_integral_eq`: for elements of `Lp`, for `0 < p < ∞`.
* `integrable.ae_eq_of_forall_set_integral_eq`: for integrable functions.
For each of these results, we also provide a lemma about the equality of one function and 0. For
example, `Lp.ae_eq_zero_of_forall_set_integral_eq_zero`.
We also register the corresponding lemma for integrals of `ℝ≥0∞`-valued functions, in
`ae_eq_of_forall_set_lintegral_eq_of_sigma_finite`.
Generally useful lemmas which are not related to integrals:
* `ae_eq_zero_of_forall_inner`: if for all constants `c`, `λ x, inner c (f x) =ᵐ[μ] 0` then
`f =ᵐ[μ] 0`.
* `ae_eq_zero_of_forall_dual`: if for all constants `c` in the dual space, `λ x, c (f x) =ᵐ[μ] 0`
then `f =ᵐ[μ] 0`.
-/
open measure_theory topological_space normed_space filter
open_locale ennreal nnreal measure_theory
namespace measure_theory
section ae_eq_of_forall
variables {α E 𝕜 : Type*} {m : measurable_space α} {μ : measure α} [is_R_or_C 𝕜]
lemma ae_eq_zero_of_forall_inner [inner_product_space 𝕜 E] [second_countable_topology E]
{f : α → E} (hf : ∀ c : E, (λ x, (inner c (f x) : 𝕜)) =ᵐ[μ] 0) :
f =ᵐ[μ] 0 :=
begin
let s := dense_seq E,
have hs : dense_range s := dense_range_dense_seq E,
have hf' : ∀ᵐ x ∂μ, ∀ n : ℕ, inner (s n) (f x) = (0 : 𝕜), from ae_all_iff.mpr (λ n, hf (s n)),
refine hf'.mono (λ x hx, _),
rw [pi.zero_apply, ← inner_self_eq_zero],
have h_closed : is_closed {c : E | inner c (f x) = (0 : 𝕜)},
from is_closed_eq (continuous_id.inner continuous_const) continuous_const,
exact @is_closed_property ℕ E _ s (λ c, inner c (f x) = (0 : 𝕜)) hs h_closed (λ n, hx n) _,
end
local notation `⟪`x`, `y`⟫` := y x
variables (𝕜)
lemma ae_eq_zero_of_forall_dual_of_is_separable [normed_add_comm_group E] [normed_space 𝕜 E]
{t : set E} (ht : topological_space.is_separable t)
{f : α → E} (hf : ∀ c : dual 𝕜 E, (λ x, ⟪f x, c⟫) =ᵐ[μ] 0) (h't : ∀ᵐ x ∂μ, f x ∈ t) :
f =ᵐ[μ] 0 :=
begin
rcases ht with ⟨d, d_count, hd⟩,
haveI : encodable d := d_count.to_encodable,
have : ∀ (x : d), ∃ g : E →L[𝕜] 𝕜, ‖g‖ ≤ 1 ∧ g x = ‖(x : E)‖ := λ x, exists_dual_vector'' 𝕜 x,
choose s hs using this,
have A : ∀ (a : E), a ∈ t → (∀ x, ⟪a, s x⟫ = (0 : 𝕜)) → a = 0,
{ assume a hat ha,
contrapose! ha,
have a_pos : 0 < ‖a‖, by simp only [ha, norm_pos_iff, ne.def, not_false_iff],
have a_mem : a ∈ closure d := hd hat,
obtain ⟨x, hx⟩ : ∃ (x : d), dist a x < ‖a‖ / 2,
{ rcases metric.mem_closure_iff.1 a_mem (‖a‖/2) (half_pos a_pos) with ⟨x, h'x, hx⟩,
exact ⟨⟨x, h'x⟩, hx⟩ },
use x,
have I : ‖a‖/2 < ‖(x : E)‖,
{ have : ‖a‖ ≤ ‖(x : E)‖ + ‖a - x‖ := norm_le_insert' _ _,
have : ‖a - x‖ < ‖a‖/2, by rwa dist_eq_norm at hx,
linarith },
assume h,
apply lt_irrefl (‖s x x‖),
calc ‖s x x‖ = ‖s x (x - a)‖ : by simp only [h, sub_zero, continuous_linear_map.map_sub]
... ≤ 1 * ‖(x : E) - a‖ : continuous_linear_map.le_of_op_norm_le _ (hs x).1 _
... < ‖a‖ / 2 : by { rw [one_mul], rwa dist_eq_norm' at hx }
... < ‖(x : E)‖ : I
... = ‖s x x‖ : by rw [(hs x).2, is_R_or_C.norm_coe_norm] },
have hfs : ∀ (y : d), ∀ᵐ x ∂μ, ⟪f x, s y⟫ = (0 : 𝕜), from λ y, hf (s y),
have hf' : ∀ᵐ x ∂μ, ∀ (y : d), ⟪f x, s y⟫ = (0 : 𝕜), by rwa ae_all_iff,
filter_upwards [hf', h't] with x hx h'x,
exact A (f x) h'x hx,
end
lemma ae_eq_zero_of_forall_dual [normed_add_comm_group E] [normed_space 𝕜 E]
[second_countable_topology E] {f : α → E} (hf : ∀ c : dual 𝕜 E, (λ x, ⟪f x, c⟫) =ᵐ[μ] 0) :
f =ᵐ[μ] 0 :=
ae_eq_zero_of_forall_dual_of_is_separable 𝕜 (is_separable_of_separable_space (set.univ : set E)) hf
(eventually_of_forall (λ x, set.mem_univ _))
variables {𝕜}
end ae_eq_of_forall
variables {α E : Type*}
{m m0 : measurable_space α} {μ : measure α} {s t : set α}
[normed_add_comm_group E] [normed_space ℝ E]
[complete_space E]
{p : ℝ≥0∞}
section ae_eq_of_forall_set_integral_eq
lemma ae_const_le_iff_forall_lt_measure_zero {β} [linear_order β] [topological_space β]
[order_topology β] [first_countable_topology β] (f : α → β) (c : β) :
(∀ᵐ x ∂μ, c ≤ f x) ↔ ∀ b < c, μ {x | f x ≤ b} = 0 :=
begin
rw ae_iff,
push_neg,
split,
{ assume h b hb,
exact measure_mono_null (λ y hy, (lt_of_le_of_lt hy hb : _)) h },
assume hc,
by_cases h : ∀ b, c ≤ b,
{ have : {a : α | f a < c} = ∅,
{ apply set.eq_empty_iff_forall_not_mem.2 (λ x hx, _),
exact (lt_irrefl _ (lt_of_lt_of_le hx (h (f x)))).elim },
simp [this] },
by_cases H : ¬ (is_lub (set.Iio c) c),
{ have : c ∈ upper_bounds (set.Iio c) := λ y hy, le_of_lt hy,
obtain ⟨b, b_up, bc⟩ : ∃ (b : β), b ∈ upper_bounds (set.Iio c) ∧ b < c,
by simpa [is_lub, is_least, this, lower_bounds] using H,
exact measure_mono_null (λ x hx, b_up hx) (hc b bc) },
push_neg at H h,
obtain ⟨u, u_mono, u_lt, u_lim, -⟩ : ∃ (u : ℕ → β), strict_mono u ∧ (∀ (n : ℕ), u n < c)
∧ tendsto u at_top (nhds c) ∧ ∀ (n : ℕ), u n ∈ set.Iio c :=
H.exists_seq_strict_mono_tendsto_of_not_mem (lt_irrefl c) h,
have h_Union : {x | f x < c} = ⋃ (n : ℕ), {x | f x ≤ u n},
{ ext1 x,
simp_rw [set.mem_Union, set.mem_set_of_eq],
split; intro h,
{ obtain ⟨n, hn⟩ := ((tendsto_order.1 u_lim).1 _ h).exists, exact ⟨n, hn.le⟩ },
{ obtain ⟨n, hn⟩ := h, exact hn.trans_lt (u_lt _), }, },
rw [h_Union, measure_Union_null_iff],
assume n,
exact hc _ (u_lt n),
end
section ennreal
open_locale topological_space
lemma ae_le_of_forall_set_lintegral_le_of_sigma_finite [sigma_finite μ]
{f g : α → ℝ≥0∞} (hf : measurable f) (hg : measurable g)
(h : ∀ s, measurable_set s → μ s < ∞ → ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ) :
f ≤ᵐ[μ] g :=
begin
have A : ∀ (ε N : ℝ≥0) (p : ℕ), 0 < ε →
μ ({x | g x + ε ≤ f x ∧ g x ≤ N} ∩ spanning_sets μ p) = 0,
{ assume ε N p εpos,
let s := {x | g x + ε ≤ f x ∧ g x ≤ N} ∩ spanning_sets μ p,
have s_meas : measurable_set s,
{ have A : measurable_set {x | g x + ε ≤ f x} := measurable_set_le (hg.add measurable_const) hf,
have B : measurable_set {x | g x ≤ N} := measurable_set_le hg measurable_const,
exact (A.inter B).inter (measurable_spanning_sets μ p) },
have s_lt_top : μ s < ∞ :=
(measure_mono (set.inter_subset_right _ _)).trans_lt (measure_spanning_sets_lt_top μ p),
have A : ∫⁻ x in s, g x ∂μ + ε * μ s ≤ ∫⁻ x in s, g x ∂μ + 0 := calc
∫⁻ x in s, g x ∂μ + ε * μ s = ∫⁻ x in s, g x ∂μ + ∫⁻ x in s, ε ∂μ :
by simp only [lintegral_const, set.univ_inter, measurable_set.univ, measure.restrict_apply]
... = ∫⁻ x in s, (g x + ε) ∂μ : (lintegral_add_right _ measurable_const).symm
... ≤ ∫⁻ x in s, f x ∂μ : set_lintegral_mono (hg.add measurable_const) hf (λ x hx, hx.1.1)
... ≤ ∫⁻ x in s, g x ∂μ + 0 : by { rw [add_zero], exact h s s_meas s_lt_top },
have B : ∫⁻ x in s, g x ∂μ ≠ ∞,
{ apply ne_of_lt,
calc ∫⁻ x in s, g x ∂μ ≤ ∫⁻ x in s, N ∂μ :
set_lintegral_mono hg measurable_const (λ x hx, hx.1.2)
... = N * μ s :
by simp only [lintegral_const, set.univ_inter, measurable_set.univ, measure.restrict_apply]
... < ∞ : by simp only [lt_top_iff_ne_top, s_lt_top.ne, and_false,
ennreal.coe_ne_top, with_top.mul_eq_top_iff, ne.def, not_false_iff, false_and, or_self] },
have : (ε : ℝ≥0∞) * μ s ≤ 0 := ennreal.le_of_add_le_add_left B A,
simpa only [ennreal.coe_eq_zero, nonpos_iff_eq_zero, mul_eq_zero, εpos.ne', false_or] },
obtain ⟨u, u_mono, u_pos, u_lim⟩ : ∃ (u : ℕ → ℝ≥0), strict_anti u ∧ (∀ n, 0 < u n) ∧
tendsto u at_top (nhds 0) := exists_seq_strict_anti_tendsto (0 : ℝ≥0),
let s := λ (n : ℕ), {x | g x + u n ≤ f x ∧ g x ≤ (n : ℝ≥0)} ∩ spanning_sets μ n,
have μs : ∀ n, μ (s n) = 0 := λ n, A _ _ _ (u_pos n),
have B : {x | f x ≤ g x}ᶜ ⊆ ⋃ n, s n,
{ assume x hx,
simp at hx,
have L1 : ∀ᶠ n in at_top, g x + u n ≤ f x,
{ have : tendsto (λ n, g x + u n) at_top (𝓝 (g x + (0 : ℝ≥0))) :=
tendsto_const_nhds.add (ennreal.tendsto_coe.2 u_lim),
simp at this,
exact eventually_le_of_tendsto_lt hx this },
have L2 : ∀ᶠ (n : ℕ) in (at_top : filter ℕ), g x ≤ (n : ℝ≥0),
{ have : tendsto (λ (n : ℕ), ((n : ℝ≥0) : ℝ≥0∞)) at_top (𝓝 ∞),
{ simp only [ennreal.coe_nat],
exact ennreal.tendsto_nat_nhds_top },
exact eventually_ge_of_tendsto_gt (hx.trans_le le_top) this },
apply set.mem_Union.2,
exact ((L1.and L2).and (eventually_mem_spanning_sets μ x)).exists },
refine le_antisymm _ bot_le,
calc μ {x : α | (λ (x : α), f x ≤ g x) x}ᶜ ≤ μ (⋃ n, s n) : measure_mono B
... ≤ ∑' n, μ (s n) : measure_Union_le _
... = 0 : by simp only [μs, tsum_zero]
end
lemma ae_eq_of_forall_set_lintegral_eq_of_sigma_finite [sigma_finite μ]
{f g : α → ℝ≥0∞} (hf : measurable f) (hg : measurable g)
(h : ∀ s, measurable_set s → μ s < ∞ → ∫⁻ x in s, f x ∂μ = ∫⁻ x in s, g x ∂μ) :
f =ᵐ[μ] g :=
begin
have A : f ≤ᵐ[μ] g :=
ae_le_of_forall_set_lintegral_le_of_sigma_finite hf hg (λ s hs h's, le_of_eq (h s hs h's)),
have B : g ≤ᵐ[μ] f :=
ae_le_of_forall_set_lintegral_le_of_sigma_finite hg hf (λ s hs h's, ge_of_eq (h s hs h's)),
filter_upwards [A, B] with x using le_antisymm,
end
end ennreal
section real
variables {f : α → ℝ}
/-- Don't use this lemma. Use `ae_nonneg_of_forall_set_integral_nonneg`. -/
lemma ae_nonneg_of_forall_set_integral_nonneg_of_strongly_measurable
(hfm : strongly_measurable f)
(hf : integrable f μ) (hf_zero : ∀ s, measurable_set s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) :
0 ≤ᵐ[μ] f :=
begin
simp_rw [eventually_le, pi.zero_apply],
rw ae_const_le_iff_forall_lt_measure_zero,
intros b hb_neg,
let s := {x | f x ≤ b},
have hs : measurable_set s, from hfm.measurable_set_le strongly_measurable_const,
have mus : μ s < ∞,
{ let c : ℝ≥0 := ⟨|b|, abs_nonneg _⟩,
have c_pos : (c : ℝ≥0∞) ≠ 0, by simpa using hb_neg.ne,
calc μ s ≤ μ {x | (c : ℝ≥0∞) ≤ ‖f x‖₊} :
begin
apply measure_mono,
assume x hx,
simp only [set.mem_set_of_eq] at hx,
simpa only [nnnorm, abs_of_neg hb_neg, abs_of_neg (hx.trans_lt hb_neg), real.norm_eq_abs,
subtype.mk_le_mk, neg_le_neg_iff, set.mem_set_of_eq, ennreal.coe_le_coe] using hx,
end
... ≤ (∫⁻ x, ‖f x‖₊ ∂μ) / c :
meas_ge_le_lintegral_div hfm.ae_measurable.ennnorm c_pos ennreal.coe_ne_top
... < ∞ : ennreal.div_lt_top (ne_of_lt hf.2) c_pos },
have h_int_gt : ∫ x in s, f x ∂μ ≤ b * (μ s).to_real,
{ have h_const_le : ∫ x in s, f x ∂μ ≤ ∫ x in s, b ∂μ,
{ refine set_integral_mono_ae_restrict hf.integrable_on
(integrable_on_const.mpr (or.inr mus)) _,
rw [eventually_le, ae_restrict_iff hs],
exact eventually_of_forall (λ x hxs, hxs), },
rwa [set_integral_const, smul_eq_mul, mul_comm] at h_const_le, },
by_contra,
refine (lt_self_iff_false (∫ x in s, f x ∂μ)).mp (h_int_gt.trans_lt _),
refine (mul_neg_iff.mpr (or.inr ⟨hb_neg, _⟩)).trans_le _,
swap, { simp_rw measure.restrict_restrict hs, exact hf_zero s hs mus, },
refine (ennreal.to_real_nonneg).lt_of_ne (λ h_eq, h _),
cases (ennreal.to_real_eq_zero_iff _).mp h_eq.symm with hμs_eq_zero hμs_eq_top,
{ exact hμs_eq_zero, },
{ exact absurd hμs_eq_top mus.ne, },
end
lemma ae_nonneg_of_forall_set_integral_nonneg (hf : integrable f μ)
(hf_zero : ∀ s, measurable_set s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) :
0 ≤ᵐ[μ] f :=
begin
rcases hf.1 with ⟨f', hf'_meas, hf_ae⟩,
have hf'_integrable : integrable f' μ, from integrable.congr hf hf_ae,
have hf'_zero : ∀ s, measurable_set s → μ s < ∞ → 0 ≤ ∫ x in s, f' x ∂μ,
{ intros s hs h's,
rw set_integral_congr_ae hs (hf_ae.mono (λ x hx hxs, hx.symm)),
exact hf_zero s hs h's, },
exact (ae_nonneg_of_forall_set_integral_nonneg_of_strongly_measurable hf'_meas
hf'_integrable hf'_zero).trans hf_ae.symm.le,
end
lemma ae_le_of_forall_set_integral_le {f g : α → ℝ} (hf : integrable f μ) (hg : integrable g μ)
(hf_le : ∀ s, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ ≤ ∫ x in s, g x ∂μ) :
f ≤ᵐ[μ] g :=
begin
rw ← eventually_sub_nonneg,
refine ae_nonneg_of_forall_set_integral_nonneg (hg.sub hf) (λ s hs, _),
rw [integral_sub' hg.integrable_on hf.integrable_on, sub_nonneg],
exact hf_le s hs
end
lemma ae_nonneg_restrict_of_forall_set_integral_nonneg_inter {f : α → ℝ} {t : set α}
(hf : integrable_on f t μ)
(hf_zero : ∀ s, measurable_set s → μ (s ∩ t) < ∞ → 0 ≤ ∫ x in (s ∩ t), f x ∂μ) :
0 ≤ᵐ[μ.restrict t] f :=
begin
refine ae_nonneg_of_forall_set_integral_nonneg hf (λ s hs h's, _),
simp_rw measure.restrict_restrict hs,
apply hf_zero s hs,
rwa measure.restrict_apply hs at h's,
end
lemma ae_nonneg_of_forall_set_integral_nonneg_of_sigma_finite [sigma_finite μ] {f : α → ℝ}
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hf_zero : ∀ s, measurable_set s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) :
0 ≤ᵐ[μ] f :=
begin
apply ae_of_forall_measure_lt_top_ae_restrict,
assume t t_meas t_lt_top,
apply ae_nonneg_restrict_of_forall_set_integral_nonneg_inter
(hf_int_finite t t_meas t_lt_top),
assume s s_meas hs,
exact hf_zero _ (s_meas.inter t_meas)
(lt_of_le_of_lt (measure_mono (set.inter_subset_right _ _)) t_lt_top)
end
lemma ae_fin_strongly_measurable.ae_nonneg_of_forall_set_integral_nonneg {f : α → ℝ}
(hf : ae_fin_strongly_measurable f μ)
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hf_zero : ∀ s, measurable_set s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) :
0 ≤ᵐ[μ] f :=
begin
let t := hf.sigma_finite_set,
suffices : 0 ≤ᵐ[μ.restrict t] f,
from ae_of_ae_restrict_of_ae_restrict_compl _ this hf.ae_eq_zero_compl.symm.le,
haveI : sigma_finite (μ.restrict t) := hf.sigma_finite_restrict,
refine ae_nonneg_of_forall_set_integral_nonneg_of_sigma_finite (λ s hs hμts, _)
(λ s hs hμts, _),
{ rw [integrable_on, measure.restrict_restrict hs],
rw measure.restrict_apply hs at hμts,
exact hf_int_finite (s ∩ t) (hs.inter hf.measurable_set) hμts, },
{ rw measure.restrict_restrict hs,
rw measure.restrict_apply hs at hμts,
exact hf_zero (s ∩ t) (hs.inter hf.measurable_set) hμts, },
end
lemma ae_nonneg_restrict_of_forall_set_integral_nonneg {f : α → ℝ}
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hf_zero : ∀ s, measurable_set s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ)
{t : set α} (ht : measurable_set t) (hμt : μ t ≠ ∞) :
0 ≤ᵐ[μ.restrict t] f :=
begin
refine ae_nonneg_restrict_of_forall_set_integral_nonneg_inter
(hf_int_finite t ht (lt_top_iff_ne_top.mpr hμt)) (λ s hs h's, _),
refine (hf_zero (s ∩ t) (hs.inter ht) _),
exact (measure_mono (set.inter_subset_right s t)).trans_lt (lt_top_iff_ne_top.mpr hμt),
end
lemma ae_eq_zero_restrict_of_forall_set_integral_eq_zero_real {f : α → ℝ}
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hf_zero : ∀ s, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = 0)
{t : set α} (ht : measurable_set t) (hμt : μ t ≠ ∞) :
f =ᵐ[μ.restrict t] 0 :=
begin
suffices h_and : f ≤ᵐ[μ.restrict t] 0 ∧ 0 ≤ᵐ[μ.restrict t] f,
from h_and.1.mp (h_and.2.mono (λ x hx1 hx2, le_antisymm hx2 hx1)),
refine ⟨_, ae_nonneg_restrict_of_forall_set_integral_nonneg hf_int_finite
(λ s hs hμs, (hf_zero s hs hμs).symm.le) ht hμt⟩,
suffices h_neg : 0 ≤ᵐ[μ.restrict t] -f,
{ refine h_neg.mono (λ x hx, _),
rw pi.neg_apply at hx,
simpa using hx, },
refine ae_nonneg_restrict_of_forall_set_integral_nonneg
(λ s hs hμs, (hf_int_finite s hs hμs).neg) (λ s hs hμs, _) ht hμt,
simp_rw pi.neg_apply,
rw [integral_neg, neg_nonneg],
exact (hf_zero s hs hμs).le,
end
end real
lemma ae_eq_zero_restrict_of_forall_set_integral_eq_zero {f : α → E}
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hf_zero : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = 0)
{t : set α} (ht : measurable_set t) (hμt : μ t ≠ ∞) :
f =ᵐ[μ.restrict t] 0 :=
begin
rcases (hf_int_finite t ht hμt.lt_top).ae_strongly_measurable.is_separable_ae_range
with ⟨u, u_sep, hu⟩,
refine ae_eq_zero_of_forall_dual_of_is_separable ℝ u_sep (λ c, _) hu,
refine ae_eq_zero_restrict_of_forall_set_integral_eq_zero_real _ _ ht hμt,
{ assume s hs hμs,
exact continuous_linear_map.integrable_comp c (hf_int_finite s hs hμs) },
{ assume s hs hμs,
rw [continuous_linear_map.integral_comp_comm c (hf_int_finite s hs hμs), hf_zero s hs hμs],
exact continuous_linear_map.map_zero _ }
end
lemma ae_eq_restrict_of_forall_set_integral_eq {f g : α → E}
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hg_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on g s μ)
(hfg_zero : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ)
{t : set α} (ht : measurable_set t) (hμt : μ t ≠ ∞) :
f =ᵐ[μ.restrict t] g :=
begin
rw ← sub_ae_eq_zero,
have hfg' : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, (f - g) x ∂μ = 0,
{ intros s hs hμs,
rw integral_sub' (hf_int_finite s hs hμs) (hg_int_finite s hs hμs),
exact sub_eq_zero.mpr (hfg_zero s hs hμs), },
have hfg_int : ∀ s, measurable_set s → μ s < ∞ → integrable_on (f-g) s μ,
from λ s hs hμs, (hf_int_finite s hs hμs).sub (hg_int_finite s hs hμs),
exact ae_eq_zero_restrict_of_forall_set_integral_eq_zero hfg_int hfg' ht hμt,
end
lemma ae_eq_zero_of_forall_set_integral_eq_of_sigma_finite [sigma_finite μ] {f : α → E}
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hf_zero : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = 0) :
f =ᵐ[μ] 0 :=
begin
let S := spanning_sets μ,
rw [← @measure.restrict_univ _ _ μ, ← Union_spanning_sets μ, eventually_eq, ae_iff,
measure.restrict_apply' (measurable_set.Union (measurable_spanning_sets μ))],
rw [set.inter_Union, measure_Union_null_iff],
intro n,
have h_meas_n : measurable_set (S n), from (measurable_spanning_sets μ n),
have hμn : μ (S n) < ∞, from measure_spanning_sets_lt_top μ n,
rw ← measure.restrict_apply' h_meas_n,
exact ae_eq_zero_restrict_of_forall_set_integral_eq_zero hf_int_finite hf_zero h_meas_n hμn.ne,
end
lemma ae_eq_of_forall_set_integral_eq_of_sigma_finite [sigma_finite μ] {f g : α → E}
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hg_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on g s μ)
(hfg_eq : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ) :
f =ᵐ[μ] g :=
begin
rw ← sub_ae_eq_zero,
have hfg : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, (f - g) x ∂μ = 0,
{ intros s hs hμs,
rw [integral_sub' (hf_int_finite s hs hμs) (hg_int_finite s hs hμs),
sub_eq_zero.mpr (hfg_eq s hs hμs)], },
have hfg_int : ∀ s, measurable_set s → μ s < ∞ → integrable_on (f-g) s μ,
from λ s hs hμs, (hf_int_finite s hs hμs).sub (hg_int_finite s hs hμs),
exact ae_eq_zero_of_forall_set_integral_eq_of_sigma_finite hfg_int hfg,
end
lemma ae_fin_strongly_measurable.ae_eq_zero_of_forall_set_integral_eq_zero {f : α → E}
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hf_zero : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = 0)
(hf : ae_fin_strongly_measurable f μ) :
f =ᵐ[μ] 0 :=
begin
let t := hf.sigma_finite_set,
suffices : f =ᵐ[μ.restrict t] 0,
from ae_of_ae_restrict_of_ae_restrict_compl _ this hf.ae_eq_zero_compl,
haveI : sigma_finite (μ.restrict t) := hf.sigma_finite_restrict,
refine ae_eq_zero_of_forall_set_integral_eq_of_sigma_finite _ _,
{ intros s hs hμs,
rw [integrable_on, measure.restrict_restrict hs],
rw [measure.restrict_apply hs] at hμs,
exact hf_int_finite _ (hs.inter hf.measurable_set) hμs, },
{ intros s hs hμs,
rw [measure.restrict_restrict hs],
rw [measure.restrict_apply hs] at hμs,
exact hf_zero _ (hs.inter hf.measurable_set) hμs, },
end
lemma ae_fin_strongly_measurable.ae_eq_of_forall_set_integral_eq {f g : α → E}
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hg_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on g s μ)
(hfg_eq : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ)
(hf : ae_fin_strongly_measurable f μ) (hg : ae_fin_strongly_measurable g μ) :
f =ᵐ[μ] g :=
begin
rw ← sub_ae_eq_zero,
have hfg : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, (f - g) x ∂μ = 0,
{ intros s hs hμs,
rw [integral_sub' (hf_int_finite s hs hμs) (hg_int_finite s hs hμs),
sub_eq_zero.mpr (hfg_eq s hs hμs)], },
have hfg_int : ∀ s, measurable_set s → μ s < ∞ → integrable_on (f-g) s μ,
from λ s hs hμs, (hf_int_finite s hs hμs).sub (hg_int_finite s hs hμs),
exact (hf.sub hg).ae_eq_zero_of_forall_set_integral_eq_zero hfg_int hfg,
end
lemma Lp.ae_eq_zero_of_forall_set_integral_eq_zero
(f : Lp E p μ) (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞)
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hf_zero : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = 0) :
f =ᵐ[μ] 0 :=
ae_fin_strongly_measurable.ae_eq_zero_of_forall_set_integral_eq_zero hf_int_finite hf_zero
(Lp.fin_strongly_measurable _ hp_ne_zero hp_ne_top).ae_fin_strongly_measurable
lemma Lp.ae_eq_of_forall_set_integral_eq (f g : Lp E p μ) (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞)
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hg_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on g s μ)
(hfg : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ) :
f =ᵐ[μ] g :=
ae_fin_strongly_measurable.ae_eq_of_forall_set_integral_eq hf_int_finite hg_int_finite hfg
(Lp.fin_strongly_measurable _ hp_ne_zero hp_ne_top).ae_fin_strongly_measurable
(Lp.fin_strongly_measurable _ hp_ne_zero hp_ne_top).ae_fin_strongly_measurable
lemma ae_eq_zero_of_forall_set_integral_eq_of_fin_strongly_measurable_trim (hm : m ≤ m0)
{f : α → E} (hf_int_finite : ∀ s, measurable_set[m] s → μ s < ∞ → integrable_on f s μ)
(hf_zero : ∀ s : set α, measurable_set[m] s → μ s < ∞ → ∫ x in s, f x ∂μ = 0)
(hf : fin_strongly_measurable f (μ.trim hm)) :
f =ᵐ[μ] 0 :=
begin
obtain ⟨t, ht_meas, htf_zero, htμ⟩ := hf.exists_set_sigma_finite,
haveI : sigma_finite ((μ.restrict t).trim hm) := by rwa restrict_trim hm μ ht_meas at htμ,
have htf_zero : f =ᵐ[μ.restrict tᶜ] 0,
{ rw [eventually_eq, ae_restrict_iff' (measurable_set.compl (hm _ ht_meas))],
exact eventually_of_forall htf_zero, },
have hf_meas_m : strongly_measurable[m] f, from hf.strongly_measurable,
suffices : f =ᵐ[μ.restrict t] 0,
from ae_of_ae_restrict_of_ae_restrict_compl _ this htf_zero,
refine measure_eq_zero_of_trim_eq_zero hm _,
refine ae_eq_zero_of_forall_set_integral_eq_of_sigma_finite _ _,
{ intros s hs hμs,
rw [integrable_on, restrict_trim hm (μ.restrict t) hs, measure.restrict_restrict (hm s hs)],
rw [← restrict_trim hm μ ht_meas, measure.restrict_apply hs,
trim_measurable_set_eq hm (hs.inter ht_meas)] at hμs,
refine integrable.trim hm _ hf_meas_m,
exact hf_int_finite _ (hs.inter ht_meas) hμs, },
{ intros s hs hμs,
rw [restrict_trim hm (μ.restrict t) hs, measure.restrict_restrict (hm s hs)],
rw [← restrict_trim hm μ ht_meas, measure.restrict_apply hs,
trim_measurable_set_eq hm (hs.inter ht_meas)] at hμs,
rw ← integral_trim hm hf_meas_m,
exact hf_zero _ (hs.inter ht_meas) hμs, },
end
lemma integrable.ae_eq_zero_of_forall_set_integral_eq_zero {f : α → E} (hf : integrable f μ)
(hf_zero : ∀ s, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = 0) :
f =ᵐ[μ] 0 :=
begin
have hf_Lp : mem_ℒp f 1 μ, from mem_ℒp_one_iff_integrable.mpr hf,
let f_Lp := hf_Lp.to_Lp f,
have hf_f_Lp : f =ᵐ[μ] f_Lp, from (mem_ℒp.coe_fn_to_Lp hf_Lp).symm,
refine hf_f_Lp.trans _,
refine Lp.ae_eq_zero_of_forall_set_integral_eq_zero f_Lp one_ne_zero ennreal.coe_ne_top _ _,
{ exact λ s hs hμs, integrable.integrable_on (L1.integrable_coe_fn _), },
{ intros s hs hμs,
rw integral_congr_ae (ae_restrict_of_ae hf_f_Lp.symm),
exact hf_zero s hs hμs, },
end
lemma integrable.ae_eq_of_forall_set_integral_eq (f g : α → E)
(hf : integrable f μ) (hg : integrable g μ)
(hfg : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ) :
f =ᵐ[μ] g :=
begin
rw ← sub_ae_eq_zero,
have hfg' : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, (f - g) x ∂μ = 0,
{ intros s hs hμs,
rw integral_sub' hf.integrable_on hg.integrable_on,
exact sub_eq_zero.mpr (hfg s hs hμs), },
exact integrable.ae_eq_zero_of_forall_set_integral_eq_zero (hf.sub hg) hfg',
end
end ae_eq_of_forall_set_integral_eq
section lintegral
lemma ae_measurable.ae_eq_of_forall_set_lintegral_eq {f g : α → ℝ≥0∞}
(hf : ae_measurable f μ) (hg : ae_measurable g μ)
(hfi : ∫⁻ x, f x ∂μ ≠ ∞) (hgi : ∫⁻ x, g x ∂μ ≠ ∞)
(hfg : ∀ ⦃s⦄, measurable_set s → μ s < ∞ → ∫⁻ x in s, f x ∂μ = ∫⁻ x in s, g x ∂μ) :
f =ᵐ[μ] g :=
begin
refine ennreal.eventually_eq_of_to_real_eventually_eq
(ae_lt_top' hf hfi).ne_of_lt (ae_lt_top' hg hgi).ne_of_lt
(integrable.ae_eq_of_forall_set_integral_eq _ _
(integrable_to_real_of_lintegral_ne_top hf hfi)
(integrable_to_real_of_lintegral_ne_top hg hgi) (λ s hs hs', _)),
rw [integral_eq_lintegral_of_nonneg_ae, integral_eq_lintegral_of_nonneg_ae],
{ congr' 1,
rw [lintegral_congr_ae (of_real_to_real_ae_eq _),
lintegral_congr_ae (of_real_to_real_ae_eq _)],
{ exact hfg hs hs' },
{ refine (ae_lt_top' hg.restrict (ne_of_lt (lt_of_le_of_lt _ hgi.lt_top))),
exact @set_lintegral_univ α _ μ g ▸ lintegral_mono_set (set.subset_univ _) },
{ refine (ae_lt_top' hf.restrict (ne_of_lt (lt_of_le_of_lt _ hfi.lt_top))),
exact @set_lintegral_univ α _ μ f ▸ lintegral_mono_set (set.subset_univ _) } },
-- putting the proofs where they are used is extremely slow
exacts
[ ae_of_all _ (λ x, ennreal.to_real_nonneg), hg.ennreal_to_real.restrict.ae_strongly_measurable,
ae_of_all _ (λ x, ennreal.to_real_nonneg), hf.ennreal_to_real.restrict.ae_strongly_measurable]
end
end lintegral
end measure_theory
|
936ae998267a1a199e8cf84f4ab0db1dfd6ce1c3
|
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
|
/tests/lean/bad_inaccessible2.lean
|
f288ddeb146837ed389e12d54b3a62547745e47f
|
[
"Apache-2.0"
] |
permissive
|
soonhokong/lean-osx
|
4a954262c780e404c1369d6c06516161d07fcb40
|
3670278342d2f4faa49d95b46d86642d7875b47c
|
refs/heads/master
| 1,611,410,334,552
| 1,474,425,686,000
| 1,474,425,686,000
| 12,043,103
| 5
| 1
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,110
|
lean
|
universe variables u
inductive vec (A : Type u) : nat → Type (max 1 u)
| nil {} : vec 0
| cons : Π {n}, A → vec n → vec (n+1)
open vec
variables {A : Type u}
variables f : A → A → A
/- The following definition fails because the pattern variables are
introduced in the following order:
a va n b vb
However, the type of va must be (vec A n). That is, it depends
on a variable introduced after va.
The error message is confusing.
Alternatives:
1- Ignore the problem since this is a very obscure use of inaccessible terms.
2- Reorder variables based on their occurrence in inaccessible terms.
If we do that, the variables in the pattern will be ordered as:
n a va b vb
and this example will work. This is not fully satisfactor since
we can create another declaration where this heuristic is not the right
solution.
3- Produce a better error message.
-/
definition map_head : ∀ {n}, vec A n → vec A n → vec A n
| .0 nil nil := nil
| .(n+1) (@cons .A .n a va) (@cons .A n b vb) := cons (f a b) va
|
6dc1231de1d10009dc1eb3eab2593e55b37428f6
|
dd0f5513e11c52db157d2fcc8456d9401a6cd9da
|
/02_Dependent_Type_Theory.org.15.lean
|
8e6c03020660a0453e4d03fb776687b6de539575
|
[] |
no_license
|
cjmazey/lean-tutorial
|
ba559a49f82aa6c5848b9bf17b7389bf7f4ba645
|
381f61c9fcac56d01d959ae0fa6e376f2c4e3b34
|
refs/heads/master
| 1,610,286,098,832
| 1,447,124,923,000
| 1,447,124,923,000
| 43,082,433
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 386
|
lean
|
/- page 19 -/
import standard
constants A B C : Type
constants (a : A) (f : A → B) (g : B → C) (h : A → A)
definition gfa : C := g (f a)
check gfa -- C
print gfa -- g (f a)
-- We can omit the type when Lean can figure it out.
definition gfa' := g (f a)
print gfa'
definition gfha := g (f (h a))
print gfha
definition g_comp_f : A → C := λ x, g (f x)
print g_comp_f
|
1e271b2845b66510f4d81246b15a40424322afac
|
05f637fa14ac28031cb1ea92086a0f4eb23ff2b1
|
/tests/lean/simp.lean
|
24819fa8c919c0ce03816047cf65320a77b6024a
|
[
"Apache-2.0"
] |
permissive
|
codyroux/lean0.1
|
1ce92751d664aacff0529e139083304a7bbc8a71
|
0dc6fb974aa85ed6f305a2f4b10a53a44ee5f0ef
|
refs/heads/master
| 1,610,830,535,062
| 1,402,150,480,000
| 1,402,150,480,000
| 19,588,851
| 2
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 613
|
lean
|
variable f : Nat → Nat
variable g : Nat → Nat → Nat
rewrite_set fgrules
axiom Axf1 : ∀ x, f (f x) = x
add_rewrite Axf1 : fgrules
axiom Axfg : ∀ x, g x x = x
add_rewrite Axfg : fgrules
variables a b : Nat
print rewrite_set fgrules
(*
local t = parse_lean('g a (f (f a))')
print(simplify(t, {'fgrules'}))
*)
disable_rewrite Axfg : fgrules
(*
local t = parse_lean('g a (f (f a))')
print(simplify(t, {'fgrules'}))
*)
enable_rewrite Axfg : fgrules
(*
local t = parse_lean('g a (f (f a))')
print(simplify(t, {'fgrules'}))
*)
(*
local t = parse_lean('g a (f (f a))')
print(simplify(t, 'fgrules'))
*)
|
d1e69728b58220ddc6f5ba6b969883b36f3422a4
|
63abd62053d479eae5abf4951554e1064a4c45b4
|
/src/control/uliftable.lean
|
93f557cd31b4d5fdfec46c771132690b45717b57
|
[
"Apache-2.0"
] |
permissive
|
Lix0120/mathlib
|
0020745240315ed0e517cbf32e738d8f9811dd80
|
e14c37827456fc6707f31b4d1d16f1f3a3205e91
|
refs/heads/master
| 1,673,102,855,024
| 1,604,151,044,000
| 1,604,151,044,000
| 308,930,245
| 0
| 0
|
Apache-2.0
| 1,604,164,710,000
| 1,604,163,547,000
| null |
UTF-8
|
Lean
| false
| false
| 5,579
|
lean
|
/-
Copyright (c) 2020 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author(s): Simon Hudon
-/
import control.monad.basic
import control.monad.cont
import control.monad.writer
import data.equiv.basic
import tactic.interactive
/-!
# Universe lifting for type families
Some functors such as `option` and `list` are universe polymorphic. Unlike
type polymorphism where `option α` is a function application and reasoning and
generalizations that apply to functions can be used, `option.{u}` and `option.{v}`
are not one function applied to two universe names but one polymorphic definition
instantiated twice. This means that whatever works on `option.{u}` is hard
to transport over to `option.{v}`. `uliftable` is an attempt at improving the situation.
`uliftable option.{u} option.{v}` gives us a generic and composable way to use
`option.{u}` in a context that requires `option.{v}`. It is often used in tandem with
`ulift` but the two are purposefully decoupled.
## Main definitions
* `uliftable` class
## Tags
universe polymorphism functor
-/
universes u₀ u₁ v₀ v₁ v₂ w w₀ w₁
/-- Given a universe polymorphic type family `M.{u} : Type u₁ → Type
u₂`, this class convert between instantiations, from
`M.{u} : Type u₁ → Type u₂` to `M.{v} : Type v₁ → Type v₂` and back -/
class uliftable (f : Type u₀ → Type u₁) (g : Type v₀ → Type v₁) :=
(congr [] {α β} : α ≃ β → f α ≃ g β)
namespace uliftable
/-- The most common practical use `uliftable` (together with `up`), this function takes `x : M.{u} α` and lifts it
to M.{max u v} (ulift.{v} α) -/
@[reducible]
def up {f : Type u₀ → Type u₁} {g : Type (max u₀ v₀) → Type v₁} [uliftable f g]
{α} : f α → g (ulift α) :=
(uliftable.congr f g equiv.ulift.symm).to_fun
/-- The most common practical use of `uliftable` (together with `up`), this function takes `x : M.{max u v} (ulift.{v} α)`
and lowers it to `M.{u} α` -/
@[reducible]
def down {f : Type u₀ → Type u₁} {g : Type (max u₀ v₀) → Type v₁} [uliftable f g]
{α} : g (ulift α) → f α :=
(uliftable.congr f g equiv.ulift.symm).inv_fun
/-- convenient shortcut to avoid manipulating `ulift` -/
def adapt_up (F : Type v₀ → Type v₁) (G : Type (max v₀ u₀) → Type u₁)
[uliftable F G] [monad G] {α β}
(x : F α) (f : α → G β) : G β :=
up x >>= f ∘ ulift.down
/-- convenient shortcut to avoid manipulating `ulift` -/
def adapt_down {F : Type (max u₀ v₀) → Type u₁} {G : Type v₀ → Type v₁}
[L : uliftable G F] [monad F] {α β}
(x : F α) (f : α → G β) : G β :=
@down.{v₀ v₁ (max u₀ v₀)} G F L β $ x >>= @up.{v₀ v₁ (max u₀ v₀)} G F L β ∘ f
/-- map function that moves up universes -/
def up_map {F : Type u₀ → Type u₁} {G : Type.{max u₀ v₀} → Type v₁} [inst : uliftable F G] [functor G]
{α β} (f : α → β) (x : F α) : G β :=
functor.map (f ∘ ulift.down) (up x)
/-- map function that moves down universes -/
def down_map {F : Type.{max u₀ v₀} → Type u₁} {G : Type → Type v₁} [inst : uliftable G F] [functor F]
{α β} (f : α → β) (x : F α) : G β :=
down (functor.map (ulift.up ∘ f) x : F (ulift β))
@[simp]
lemma up_down {f : Type u₀ → Type u₁} {g : Type (max u₀ v₀) → Type v₁} [uliftable f g]
{α} (x : g (ulift α)) : up (down x : f α) = x :=
(uliftable.congr f g equiv.ulift.symm).right_inv _
@[simp]
lemma down_up {f : Type u₀ → Type u₁} {g : Type (max u₀ v₀) → Type v₁} [uliftable f g]
{α} (x : f α) : down (up x : g _) = x :=
(uliftable.congr f g equiv.ulift.symm).left_inv _
end uliftable
open ulift
instance : uliftable id id :=
{ congr := λ α β F, F }
/-- for specific state types, this function helps to create a uliftable instance -/
def state_t.uliftable' {s : Type u₀} {s' : Type u₁}
{m : Type u₀ → Type v₀} {m' : Type u₁ → Type v₁}
[uliftable m m']
(F : s ≃ s') :
uliftable (state_t s m) (state_t s' m') :=
{ congr :=
λ α β G, state_t.equiv $ equiv.Pi_congr F $
λ _, uliftable.congr _ _ $ equiv.prod_congr G F }
instance {s m m'}
[uliftable m m'] :
uliftable (state_t s m) (state_t (ulift s) m') :=
state_t.uliftable' equiv.ulift.symm
/-- for specific reader monads, this function helps to create a uliftable instance -/
def reader_t.uliftable' {s s' m m'}
[uliftable m m']
(F : s ≃ s') :
uliftable (reader_t s m) (reader_t s' m') :=
{ congr :=
λ α β G, reader_t.equiv $ equiv.Pi_congr F $
λ _, uliftable.congr _ _ G }
instance {s m m'} [uliftable m m'] : uliftable (reader_t s m) (reader_t (ulift s) m') :=
reader_t.uliftable' equiv.ulift.symm
/-- for specific continuation passing monads, this function helps to create a uliftable instance -/
def cont_t.uliftable' {r r' m m'}
[uliftable m m']
(F : r ≃ r') :
uliftable (cont_t r m) (cont_t r' m') :=
{ congr :=
λ α β, cont_t.equiv (uliftable.congr _ _ F) }
instance {s m m'} [uliftable m m'] : uliftable (cont_t s m) (cont_t (ulift s) m') :=
cont_t.uliftable' equiv.ulift.symm
/-- for specific writer monads, this function helps to create a uliftable instance -/
def writer_t.uliftable' {w w' m m'}
[uliftable m m']
(F : w ≃ w') :
uliftable (writer_t w m) (writer_t w' m') :=
{ congr :=
λ α β G, writer_t.equiv $ uliftable.congr _ _ $ equiv.prod_congr G F }
instance {s m m'} [uliftable m m'] : uliftable (writer_t s m) (writer_t (ulift s) m') :=
writer_t.uliftable' equiv.ulift.symm
|
bc72283b592c7dfc3a49d1630a95243620f33c65
|
88fb7558b0636ec6b181f2a548ac11ad3919f8a5
|
/tests/lean/run/noncomputable_example.lean
|
fad39ea5009639498db757f19e5545bcd248210b
|
[
"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
| 196
|
lean
|
open classical psum
universe variable u
noncomputable example (A : Type u) (h : (A → false) → false) : A :=
match type_decidable A with
| (inl ha) := ha
| (inr hna) := false.rec _ (h hna)
end
|
2ee37b0beb574b3fc7d84202f7b91ec7201e6d21
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/linear_algebra/clifford_algebra/even_equiv.lean
|
c16e72cfe02b9dc339538eef332ac46665ddc85e
|
[
"Apache-2.0"
] |
permissive
|
alreadydone/mathlib
|
dc0be621c6c8208c581f5170a8216c5ba6721927
|
c982179ec21091d3e102d8a5d9f5fe06c8fafb73
|
refs/heads/master
| 1,685,523,275,196
| 1,670,184,141,000
| 1,670,184,141,000
| 287,574,545
| 0
| 0
|
Apache-2.0
| 1,670,290,714,000
| 1,597,421,623,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 11,299
|
lean
|
/-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import linear_algebra.clifford_algebra.conjugation
import linear_algebra.clifford_algebra.even
import linear_algebra.quadratic_form.prod
/-!
# Isomorphisms with the even subalgebra of a Clifford algebra
This file provides some notable isomorphisms regarding the even subalgebra, `clifford_algebra.even`.
## Main definitions
* `clifford_algebra.equiv_even`: Every Clifford algebra is isomorphic as an algebra to the even
subalgebra of a Clifford algebra with one more dimension.
* `clifford_algebra.even_equiv.Q'`: The quadratic form used by this "one-up" algebra.
* `clifford_algebra.to_even`: The simp-normal form of the forward direction of this isomorphism.
* `clifford_algebra.of_even`: The simp-normal form of the reverse direction of this isomorphism.
* `clifford_algebra.even_equiv_even_neg`: Every even subalgebra is isomorphic to the even subalgebra
of the Clifford algebra with negated quadratic form.
* `clifford_algebra.even_to_neg`: The simp-normal form of each direction of this isomorphism.
## Main results
* `clifford_algebra.coe_to_even_reverse_involute`: the behavior of `clifford_algebra.to_even` on the
"Clifford conjugate", that is `clifford_algebra.reverse` composed with
`clifford_algebra.involute`.
-/
namespace clifford_algebra
variables {R M : Type*} [comm_ring R] [add_comm_group M] [module R M]
variables (Q : quadratic_form R M)
/-! ### Constructions needed for `clifford_algebra.equiv_even` -/
namespace equiv_even
/-- The quadratic form on the augmented vector space `M × R` sending `v + r•e0` to `Q v - r^2`. -/
@[reducible]
def Q' : quadratic_form R (M × R) := (Q.prod $ -@quadratic_form.sq R _)
lemma Q'_apply (m : M × R) : Q' Q m = Q m.1 - m.2 * m.2 := (sub_eq_add_neg _ _).symm
/-- The unit vector in the new dimension -/
def e0 : clifford_algebra (Q' Q) := ι (Q' Q) (0, 1)
/-- The embedding from the existing vector space -/
def v : M →ₗ[R] clifford_algebra (Q' Q) := (ι (Q' Q)) ∘ₗ linear_map.inl _ _ _
lemma ι_eq_v_add_smul_e0 (m : M) (r : R) : ι (Q' Q) (m, r) = v Q m + r • e0 Q :=
by rw [e0, v, linear_map.comp_apply, linear_map.inl_apply, ←linear_map.map_smul, prod.smul_mk,
smul_zero, smul_eq_mul, mul_one, ←linear_map.map_add, prod.mk_add_mk, zero_add, add_zero]
lemma e0_mul_e0 : e0 Q * e0 Q = -1 :=
(ι_sq_scalar _ _).trans $ by simp
lemma v_sq_scalar (m : M) : v Q m * v Q m = algebra_map _ _ (Q m) :=
(ι_sq_scalar _ _).trans $ by simp
lemma neg_e0_mul_v (m : M) : -(e0 Q * v Q m) = v Q m * e0 Q :=
begin
refine neg_eq_of_add_eq_zero_right ((ι_mul_ι_add_swap _ _).trans _),
dsimp [quadratic_form.polar],
simp only [add_zero, mul_zero, mul_one, zero_add, neg_zero, quadratic_form.map_zero,
add_sub_cancel, sub_self, map_zero, zero_sub],
end
lemma neg_v_mul_e0 (m : M) : -(v Q m * e0 Q) = e0 Q * v Q m :=
begin
rw neg_eq_iff_neg_eq,
exact neg_e0_mul_v _ m
end
@[simp] lemma e0_mul_v_mul_e0 (m : M) : e0 Q * v Q m * e0 Q = v Q m :=
by rw [←neg_v_mul_e0, ←neg_mul, mul_assoc, e0_mul_e0, mul_neg_one, neg_neg]
@[simp] lemma reverse_v (m : M) : reverse (v Q m) = v Q m := reverse_ι _
@[simp] lemma involute_v (m : M) : involute (v Q m) = -v Q m := involute_ι _
@[simp] lemma reverse_e0 : reverse (e0 Q) = e0 Q := reverse_ι _
@[simp] lemma involute_e0 : involute (e0 Q) = -e0 Q := involute_ι _
end equiv_even
open equiv_even
/-- The embedding from the smaller algebra into the new larger one. -/
def to_even : clifford_algebra Q →ₐ[R] clifford_algebra.even (Q' Q) :=
begin
refine clifford_algebra.lift Q ⟨_, λ m, _⟩,
{ refine linear_map.cod_restrict _ _ (λ m, submodule.mem_supr_of_mem ⟨2, rfl⟩ _),
exact (linear_map.mul_left R $ e0 Q).comp (v Q),
rw [subtype.coe_mk, pow_two],
exact submodule.mul_mem_mul (linear_map.mem_range_self _ _) (linear_map.mem_range_self _ _), },
{ ext1,
dsimp only [subalgebra.coe_mul, linear_map.cod_restrict_apply, linear_map.comp_apply,
linear_map.mul_left_apply, linear_map.inl_apply, subalgebra.coe_algebra_map],
rw [←mul_assoc, e0_mul_v_mul_e0, v_sq_scalar] }
end
@[simp]
lemma to_even_ι (m : M) : (to_even Q (ι Q m) : clifford_algebra (Q' Q)) = e0 Q * v Q m :=
begin
rw [to_even, clifford_algebra.lift_ι_apply, linear_map.cod_restrict_apply],
refl,
end
/-- The embedding from the even subalgebra with an extra dimension into the original algebra. -/
def of_even : clifford_algebra.even (Q' Q) →ₐ[R] clifford_algebra Q :=
begin
/-
Recall that we need:
* `f ⟨0,1⟩ ⟨x,0⟩ = ι x`
* `f ⟨x,0⟩ ⟨0,1⟩ = -ι x`
* `f ⟨x,0⟩ ⟨y,0⟩ = ι x * ι y`
* `f ⟨0,1⟩ ⟨0,1⟩ = -1`
-/
let f : (M × R) →ₗ[R] (M × R) →ₗ[R] clifford_algebra Q :=
((algebra.lmul R (clifford_algebra Q)).to_linear_map.comp
$ ((ι Q).comp (linear_map.fst _ _ _)) +
(algebra.linear_map R _).comp (linear_map.snd _ _ _)).compl₂
(((ι Q).comp (linear_map.fst _ _ _)) - (algebra.linear_map R _).comp (linear_map.snd _ _ _)),
have f_apply :
∀ x y, f x y = (ι Q x.1 + algebra_map R _ x.2) * (ι Q y.1 - algebra_map R _ y.2) :=
λ x y, rfl,
have hc : ∀ (r : R) (x : clifford_algebra Q), commute (algebra_map _ _ r) x := algebra.commutes,
have hm : ∀ m : M × R,
ι Q m.1 * ι Q m.1 - algebra_map R _ m.2 * algebra_map R _ m.2 = algebra_map R _ (Q' Q m),
{ intro m,
rw [ι_sq_scalar, ←ring_hom.map_mul, ←ring_hom.map_sub,
sub_eq_add_neg, Q'_apply, sub_eq_add_neg] },
refine even.lift (Q' Q) ⟨f, _, _⟩; simp_rw [f_apply],
{ intro m,
rw [←(hc _ _).symm.mul_self_sub_mul_self_eq, hm] },
{ intros m₁ m₂ m₃,
rw [←mul_smul_comm, ←mul_assoc, mul_assoc(_ + _), ←(hc _ _).symm.mul_self_sub_mul_self_eq',
algebra.smul_def, ←mul_assoc, hm] },
end
lemma of_even_ι (x y : M × R) :
of_even Q ((even.ι _).bilin x y) =
(ι Q x.1 + algebra_map R _ x.2) * (ι Q y.1 - algebra_map R _ y.2) :=
even.lift_ι _ _ _ _
lemma to_even_comp_of_even : (to_even Q).comp (of_even Q) = alg_hom.id R _ :=
even.alg_hom_ext (Q' Q) $ even_hom.ext _ _ $ linear_map.ext $ λ m₁, linear_map.ext $ λ m₂,
subtype.ext $
let ⟨m₁, r₁⟩ := m₁, ⟨m₂, r₂⟩ := m₂ in
calc ↑(to_even Q (of_even Q ((even.ι (Q' Q)).bilin (m₁, r₁) (m₂, r₂))))
= (e0 Q * v Q m₁ + algebra_map R _ r₁) * (e0 Q * v Q m₂ - algebra_map R _ r₂) :
by rw [of_even_ι, alg_hom.map_mul, alg_hom.map_add, alg_hom.map_sub, alg_hom.commutes,
alg_hom.commutes, subalgebra.coe_mul, subalgebra.coe_add, subalgebra.coe_sub,
to_even_ι, to_even_ι, subalgebra.coe_algebra_map, subalgebra.coe_algebra_map]
... = e0 Q * v Q m₁ * (e0 Q * v Q m₂) + r₁ • e0 Q * v Q m₂ - r₂ • e0 Q * v Q m₁
- algebra_map R _ (r₁ * r₂) :
by rw [mul_sub, add_mul, add_mul, ←algebra.commutes, ←algebra.smul_def, ←map_mul,
←algebra.smul_def, sub_add_eq_sub_sub, smul_mul_assoc, smul_mul_assoc]
... = v Q m₁ * v Q m₂ + r₁ • e0 Q * v Q m₂ + v Q m₁ * r₂ • e0 Q + (r₁ • e0 Q) * r₂ • e0 Q :
have h1 : e0 Q * v Q m₁ * (e0 Q * v Q m₂) = v Q m₁ * v Q m₂,
by rw [←mul_assoc, e0_mul_v_mul_e0],
have h2 : -(r₂ • e0 Q * v Q m₁) = v Q m₁ * r₂ • e0 Q,
by rw [mul_smul_comm, smul_mul_assoc, ←smul_neg, neg_e0_mul_v],
have h3 : - algebra_map R _ (r₁ * r₂) = (r₁ • e0 Q) * r₂ • e0 Q,
by rw [algebra.algebra_map_eq_smul_one, smul_mul_smul, e0_mul_e0, smul_neg],
by rw [sub_eq_add_neg, sub_eq_add_neg, h1, h2, h3]
... = ι _ (m₁, r₁) * ι _ (m₂, r₂) :
by rw [ι_eq_v_add_smul_e0, ι_eq_v_add_smul_e0, mul_add, add_mul, add_mul, add_assoc]
lemma of_even_comp_to_even :
(of_even Q).comp (to_even Q) = alg_hom.id R _ :=
clifford_algebra.hom_ext $ linear_map.ext $ λ m,
calc of_even Q (to_even Q (ι Q m))
= of_even Q ⟨_, (to_even Q (ι Q m)).prop⟩ : by rw subtype.coe_eta
... = (ι Q 0 + algebra_map R _ 1) * (ι Q m - algebra_map R _ 0) : begin
simp_rw to_even_ι,
exact of_even_ι Q _ _,
end
... = ι Q m : by rw [map_one, map_zero, map_zero, sub_zero, zero_add, one_mul]
/-- Any clifford algebra is isomorphic to the even subalgebra of a clifford algebra with an extra
dimension (that is, with vector space `M × R`), with a quadratic form evaluating to `-1` on that new
basis vector. -/
@[simps]
def equiv_even : clifford_algebra Q ≃ₐ[R] clifford_algebra.even (Q' Q) :=
alg_equiv.of_alg_hom
(to_even Q)
(of_even Q)
(to_even_comp_of_even Q)
(of_even_comp_to_even Q)
/-- The representation of the clifford conjugate (i.e. the reverse of the involute) in the even
subalgebra is just the reverse of the representation. -/
lemma coe_to_even_reverse_involute (x : clifford_algebra Q) :
↑(to_even Q (reverse (involute x))) = reverse (to_even Q x : clifford_algebra (Q' Q)) :=
begin
induction x using clifford_algebra.induction,
case h_grade0 : r { simp only [alg_hom.commutes, subalgebra.coe_algebra_map, reverse.commutes] },
case h_grade1 : m
{ simp only [involute_ι, subalgebra.coe_neg, to_even_ι, reverse.map_mul,
reverse_v, reverse_e0, reverse_ι, neg_e0_mul_v, map_neg] },
case h_mul : x y hx hy { simp only [map_mul, subalgebra.coe_mul, reverse.map_mul, hx, hy] },
case h_add : x y hx hy { simp only [map_add, subalgebra.coe_add, hx, hy] },
end
/-! ### Constructions needed for `clifford_algebra.even_equiv_even_neg` -/
/-- One direction of `clifford_algebra.even_equiv_even_neg` -/
def even_to_neg (Q' : quadratic_form R M) (h : Q' = -Q) :
clifford_algebra.even Q →ₐ[R] clifford_algebra.even Q' :=
even.lift Q
{ bilin := -(even.ι Q' : _).bilin,
contract := λ m, by simp_rw [linear_map.neg_apply, even_hom.contract, h,
quadratic_form.neg_apply, map_neg, neg_neg],
contract_mid := λ m₁ m₂ m₃,
by simp_rw [linear_map.neg_apply, neg_mul_neg, even_hom.contract_mid, h,
quadratic_form.neg_apply, smul_neg, neg_smul] }
@[simp] lemma even_to_neg_ι (Q' : quadratic_form R M) (h : Q' = -Q) (m₁ m₂ : M) :
even_to_neg Q Q' h ((even.ι Q).bilin m₁ m₂) = -(even.ι Q').bilin m₁ m₂ :=
even.lift_ι _ _ m₁ m₂
lemma even_to_neg_comp_even_to_neg (Q' : quadratic_form R M)
(h : Q' = -Q) (h' : Q = -Q') :
(even_to_neg Q' Q h').comp (even_to_neg Q Q' h) = alg_hom.id R _ :=
begin
ext m₁ m₂ : 4,
dsimp only [even_hom.compr₂_bilin, linear_map.compr₂_apply, alg_hom.to_linear_map_apply,
alg_hom.comp_apply, alg_hom.id_apply],
rw [even_to_neg_ι, map_neg, even_to_neg_ι, neg_neg]
end
/-- The even subalgebras of the algebras with quadratic form `Q` and `-Q` are isomorphic.
Stated another way, `𝒞ℓ⁺(p,q,r)` and `𝒞ℓ⁺(q,p,r)` are isomorphic. -/
@[simps]
def even_equiv_even_neg : clifford_algebra.even Q ≃ₐ[R] clifford_algebra.even (-Q) :=
alg_equiv.of_alg_hom
(even_to_neg Q _ rfl)
(even_to_neg (-Q) _ (neg_neg _).symm)
(even_to_neg_comp_even_to_neg _ _ _ _)
(even_to_neg_comp_even_to_neg _ _ _ _)
end clifford_algebra
|
2124ad524bb7ab1a7d7ce8b198656e09b19798f1
|
57c233acf9386e610d99ed20ef139c5f97504ba3
|
/src/topology/tactic.lean
|
fc9e47d7b13576ff253cd0a432d6b5fff97a585d
|
[
"Apache-2.0"
] |
permissive
|
robertylewis/mathlib
|
3d16e3e6daf5ddde182473e03a1b601d2810952c
|
1d13f5b932f5e40a8308e3840f96fc882fae01f0
|
refs/heads/master
| 1,651,379,945,369
| 1,644,276,960,000
| 1,644,276,960,000
| 98,875,504
| 0
| 0
|
Apache-2.0
| 1,644,253,514,000
| 1,501,495,700,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 4,068
|
lean
|
/-
Copyright (c) 2020 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton
-/
import tactic.auto_cases
import tactic.tidy
import tactic.with_local_reducibility
import tactic.show_term
import topology.basic
/-!
# Tactics for topology
Currently we have one domain-specific tactic for topology: `continuity`.
-/
/-!
### `continuity` tactic
Automatically solve goals of the form `continuous f`.
Mark lemmas with `@[continuity]` to add them to the set of lemmas
used by `continuity`.
-/
/-- User attribute used to mark tactics used by `continuity`. -/
@[user_attribute]
meta def continuity : user_attribute :=
{ name := `continuity,
descr := "lemmas usable to prove continuity" }
-- Mark some continuity lemmas already defined in `topology.basic`
attribute [continuity]
continuous_id
continuous_const
-- As we will be using `apply_rules` with `md := semireducible`,
-- we need another version of `continuous_id`.
@[continuity] lemma continuous_id' {α : Type*} [topological_space α] : continuous (λ a : α, a) :=
continuous_id
namespace tactic
/--
Tactic to apply `continuous.comp` when appropriate.
Applying `continuous.comp` is not always a good idea, so we have some
extra logic here to try to avoid bad cases.
* If the function we're trying to prove continuous is actually
constant, and that constant is a function application `f z`, then
continuous.comp would produce new goals `continuous f`, `continuous
(λ _, z)`, which is silly. We avoid this by failing if we could
apply continuous_const.
* continuous.comp will always succeed on `continuous (λ x, f x)` and
produce new goals `continuous (λ x, x)`, `continuous f`. We detect
this by failing if a new goal can be closed by applying
continuous_id.
-/
meta def apply_continuous.comp : tactic unit :=
`[fail_if_success { exact continuous_const };
refine continuous.comp _ _;
fail_if_success { exact continuous_id }]
/-- List of tactics used by `continuity` internally. -/
meta def continuity_tactics (md : transparency := reducible) : list (tactic string) :=
[
intros1 >>= λ ns, pure ("intros " ++ (" ".intercalate (ns.map (λ e, e.to_string)))),
apply_rules [``(continuity)] 50 { md := md }
>> pure "apply_rules continuity",
apply_continuous.comp >> pure "refine continuous.comp _ _"
]
namespace interactive
setup_tactic_parser
/--
Solve goals of the form `continuous f`. `continuity?` reports back the proof term it found.
-/
meta def continuity
(bang : parse $ optional (tk "!")) (trace : parse $ optional (tk "?")) (cfg : tidy.cfg := {}) :
tactic unit :=
let md := if bang.is_some then semireducible else reducible,
continuity_core := tactic.tidy { tactics := continuity_tactics md, ..cfg },
trace_fn := if trace.is_some then show_term else id in
trace_fn continuity_core
/-- Version of `continuity` for use with auto_param. -/
meta def continuity' : tactic unit := continuity none none {}
/--
`continuity` solves goals of the form `continuous f` by applying lemmas tagged with the
`continuity` user attribute.
```
example {X Y : Type*} [topological_space X] [topological_space Y]
(f₁ f₂ : X → Y) (hf₁ : continuous f₁) (hf₂ : continuous f₂)
(g : Y → ℝ) (hg : continuous g) : continuous (λ x, (max (g (f₁ x)) (g (f₂ x))) + 1) :=
by continuity
```
will discharge the goal, generating a proof term like
`((continuous.comp hg hf₁).max (continuous.comp hg hf₂)).add continuous_const`
You can also use `continuity!`, which applies lemmas with `{ md := semireducible }`.
The default behaviour is more conservative, and only unfolds `reducible` definitions
when attempting to match lemmas with the goal.
`continuity?` reports back the proof term it found.
-/
add_tactic_doc
{ name := "continuity / continuity'",
category := doc_category.tactic,
decl_names := [`tactic.interactive.continuity, `tactic.interactive.continuity'],
tags := ["lemma application"] }
end interactive
end tactic
|
308557b71861bf9cc6954b9203a7f6ae18143ae8
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/group_theory/group_action/option.lean
|
9afd75f5ee9cc3eaf2a18b6003ca5cec6dcf6b22
|
[
"Apache-2.0"
] |
permissive
|
leanprover-community/mathlib
|
56a2cadd17ac88caf4ece0a775932fa26327ba0e
|
442a83d738cb208d3600056c489be16900ba701d
|
refs/heads/master
| 1,693,584,102,358
| 1,693,471,902,000
| 1,693,471,902,000
| 97,922,418
| 1,595
| 352
|
Apache-2.0
| 1,694,693,445,000
| 1,500,624,130,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 2,127
|
lean
|
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import group_theory.group_action.defs
/-!
# Option instances for additive and multiplicative actions
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file defines instances for additive and multiplicative actions on `option` type. Scalar
multiplication is defined by `a • some b = some (a • b)` and `a • none = none`.
## See also
* `group_theory.group_action.pi`
* `group_theory.group_action.prod`
* `group_theory.group_action.sigma`
* `group_theory.group_action.sum`
-/
variables {M N α : Type*}
namespace option
section has_smul
variables [has_smul M α] [has_smul N α] (a : M) (b : α) (x : option α)
@[to_additive option.has_vadd] instance : has_smul M (option α) := ⟨λ a, option.map $ (•) a⟩
@[to_additive] lemma smul_def : a • x = x.map ((•) a) := rfl
@[simp, to_additive] lemma smul_none : a • (none : option α) = none := rfl
@[simp, to_additive] lemma smul_some : a • some b = some (a • b) := rfl
@[to_additive] instance [has_smul M N] [is_scalar_tower M N α] : is_scalar_tower M N (option α) :=
⟨λ a b x, by { cases x, exacts [rfl, congr_arg some (smul_assoc _ _ _)] }⟩
@[to_additive] instance [smul_comm_class M N α] : smul_comm_class M N (option α) :=
⟨λ a b, function.commute.option_map $ smul_comm _ _⟩
@[to_additive]
instance [has_smul Mᵐᵒᵖ α] [is_central_scalar M α] : is_central_scalar M (option α) :=
⟨λ a x, by { cases x, exacts [rfl, congr_arg some (op_smul_eq_smul _ _)] }⟩
@[to_additive] instance [has_faithful_smul M α] : has_faithful_smul M (option α) :=
⟨λ x y h, eq_of_smul_eq_smul $ λ b : α, by injection h (some b)⟩
end has_smul
instance [monoid M] [mul_action M α] : mul_action M (option α) :=
{ smul := (•),
one_smul := λ b, by { cases b, exacts [rfl, congr_arg some (one_smul _ _)] },
mul_smul := λ a₁ a₂ b, by { cases b, exacts [rfl, congr_arg some (mul_smul _ _ _)] } }
end option
|
59c49042a81ef5643e318a1e3dc12df097c7d1d7
|
60bf3fa4185ec5075eaea4384181bfbc7e1dc319
|
/src/game/sup_inf/lub_rationals.lean
|
4212ddd1b99b185909b13a3799a6deec28baa618
|
[
"Apache-2.0"
] |
permissive
|
anrddh/real-number-game
|
660f1127d03a78fd35986c771d65c3132c5f4025
|
c708c4e02ec306c657e1ea67862177490db041b0
|
refs/heads/master
| 1,668,214,277,092
| 1,593,105,075,000
| 1,593,105,075,000
| 264,269,218
| 0
| 0
| null | 1,589,567,264,000
| 1,589,567,264,000
| null |
UTF-8
|
Lean
| false
| false
| 940
|
lean
|
import data.real.basic
namespace xena -- hide
/-
# Chapter 3 : Sup and Inf
## Level 11
-/
definition is_upper_bound (S : set ℝ) (x : ℝ) := ∀ s ∈ S, s ≤ x
definition is_lub' (S : set ℝ) (x : ℝ) := is_upper_bound S x ∧
∀ y : ℝ, is_upper_bound S y → x ≤ y
definition has_lub (S : set ℝ) := ∃ x, is_lub' S x
def embedded_rationals : set ℝ := {x : ℝ | ∃ y : ℚ, x = ↑y}
/- Lemma
The set of rational numbers does not have a supremum
-/
lemma not_lub_rationals : ∀ b : ℝ, ¬ (is_lub (embedded_rationals) b) :=
begin
intros b Hlub,
have Hbub : b ∈ upper_bounds embedded_rationals := Hlub.left,
have H : b < (b+1) := calc b = b+0 : (add_zero _).symm
... < b+1 : add_lt_add_left zero_lt_one _,
cases (exists_rat_btwn H) with q Hq,
have Hqin : ↑q ∈ embedded_rationals := ⟨q,rfl⟩,
have Hwrong2 := Hbub Hqin,
exact not_lt.2 Hwrong2 (Hq.left),
end
end xena -- hide
|
c33d277f7a92fd4120e8786e1d30491c1fda88a6
|
64874bd1010548c7f5a6e3e8902efa63baaff785
|
/library/data/num.lean
|
01f68a9bb9e551a28f8950719abfcd330baa7a7b
|
[
"Apache-2.0"
] |
permissive
|
tjiaqi/lean
|
4634d729795c164664d10d093f3545287c76628f
|
d0ce4cf62f4246b0600c07e074d86e51f2195e30
|
refs/heads/master
| 1,622,323,796,480
| 1,422,643,069,000
| 1,422,643,069,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 2,059
|
lean
|
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: data.num
Author: Leonardo de Moura
-/
import logic.eq
open bool
namespace pos_num
theorem succ_not_is_one (a : pos_num) : is_one (succ a) = ff :=
induction_on a rfl (take n iH, rfl) (take n iH, rfl)
theorem pred.succ (a : pos_num) : pred (succ a) = a :=
rec_on a
rfl
(take (n : pos_num) (iH : pred (succ n) = n),
calc
pred (succ (bit1 n)) = cond (is_one (succ n)) one (bit1 (pred (succ n))) : rfl
... = cond ff one (bit1 (pred (succ n))) : succ_not_is_one
... = bit1 (pred (succ n)) : rfl
... = bit1 n : iH)
(take (n : pos_num) (iH : pred (succ n) = n), rfl)
section
variables (a b : pos_num)
theorem add.one_one : one + one = bit0 one :=
rfl
theorem add.one_bit0 : one + (bit0 a) = bit1 a :=
rfl
theorem add.one_bit1 : one + (bit1 a) = succ (bit1 a) :=
rfl
theorem add.bit0_one : (bit0 a) + one = bit1 a :=
rfl
theorem add.bit1_one : (bit1 a) + one = succ (bit1 a) :=
rfl
theorem add.bit0_bit0 : (bit0 a) + (bit0 b) = bit0 (a + b) :=
rfl
theorem add.bit0_bit1 : (bit0 a) + (bit1 b) = bit1 (a + b) :=
rfl
theorem add.bit1_bit0 : (bit1 a) + (bit0 b) = bit1 (a + b) :=
rfl
theorem add.bit1_bit1 : (bit1 a) + (bit1 b) = succ (bit1 (a + b)) :=
rfl
end
theorem mul.one_left (a : pos_num) : one * a = a :=
rfl
theorem mul.one_right (a : pos_num) : a * one = a :=
induction_on a
rfl
(take (n : pos_num) (iH : n * one = n),
calc bit1 n * one = bit0 (n * one) + one : rfl
... = bit0 n + one : iH
... = bit1 n : add.bit0_one)
(take (n : pos_num) (iH : n * one = n),
calc bit0 n * one = bit0 (n * one) : rfl
... = bit0 n : iH)
end pos_num
|
91a0a1ef37d894c399e9896e2f7907d967ee7bb8
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/category_theory/bicategory/coherence.lean
|
9cf7ea46cddf73fe2aee7f4540f02648b92918ca
|
[
"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
| 9,235
|
lean
|
/-
Copyright (c) 2022 Yuma Mizuno. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yuma Mizuno, Junyan Xu
-/
import category_theory.path_category
import category_theory.functor.fully_faithful
import category_theory.bicategory.free
import category_theory.bicategory.locally_discrete
/-!
# The coherence theorem for bicategories
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In this file, we prove the coherence theorem for bicategories, stated in the following form: the
free bicategory over any quiver is locally thin.
The proof is almost the same as the proof of the coherence theorem for monoidal categories that
has been previously formalized in mathlib, which is based on the proof described by Ilya Beylin
and Peter Dybjer. The idea is to view a path on a quiver as a normal form of a 1-morphism in the
free bicategory on the same quiver. A normalization procedure is then described by
`normalize : pseudofunctor (free_bicategory B) (locally_discrete (paths B))`, which is a
pseudofunctor from the free bicategory to the locally discrete bicategory on the path category.
It turns out that this pseudofunctor is locally an equivalence of categories, and the coherence
theorem follows immediately from this fact.
## Main statements
* `locally_thin` : the free bicategory is locally thin, that is, there is at most one
2-morphism between two fixed 1-morphisms.
## References
* [Ilya Beylin and Peter Dybjer, Extracting a proof of coherence for monoidal categories from a
proof of normalization for monoids][beylin1996]
-/
open quiver (path) quiver.path
namespace category_theory
open bicategory category
open_locale bicategory
universes v u
namespace free_bicategory
variables {B : Type u} [quiver.{v+1} B]
/-- Auxiliary definition for `inclusion_path`. -/
@[simp]
def inclusion_path_aux {a : B} : ∀ {b : B}, path a b → hom a b
| _ nil := hom.id a
| _ (cons p f) := (inclusion_path_aux p).comp (hom.of f)
/--
The discrete category on the paths includes into the category of 1-morphisms in the free
bicategory.
-/
def inclusion_path (a b : B) : discrete (path.{v+1} a b) ⥤ hom a b :=
discrete.functor inclusion_path_aux
/--
The inclusion from the locally discrete bicategory on the path category into the free bicategory
as a prelax functor. This will be promoted to a pseudofunctor after proving the coherence theorem.
See `inclusion`.
-/
def preinclusion (B : Type u) [quiver.{v+1} B] :
prelax_functor (locally_discrete (paths B)) (free_bicategory B) :=
{ obj := id,
map := λ a b, (inclusion_path a b).obj,
map₂ := λ a b f g η, (inclusion_path a b).map η }
@[simp]
lemma preinclusion_obj (a : B) :
(preinclusion B).obj a = a :=
rfl
@[simp]
lemma preinclusion_map₂ {a b : B} (f g : discrete (path.{v+1} a b)) (η : f ⟶ g) :
(preinclusion B).map₂ η = eq_to_hom (congr_arg _ (discrete.ext _ _ (discrete.eq_of_hom η))) :=
begin
rcases η with ⟨⟨⟩⟩,
cases discrete.ext _ _ η,
exact (inclusion_path a b).map_id _
end
/--
The normalization of the composition of `p : path a b` and `f : hom b c`.
`p` will eventually be taken to be `nil` and we then get the normalization
of `f` alone, but the auxiliary `p` is necessary for Lean to accept the definition of
`normalize_iso` and the `whisker_left` case of `normalize_aux_congr` and `normalize_naturality`.
-/
@[simp]
def normalize_aux {a : B} : ∀ {b c : B}, path a b → hom b c → path a c
| _ _ p (hom.of f) := p.cons f
| _ _ p (hom.id b) := p
| _ _ p (hom.comp f g) := normalize_aux (normalize_aux p f) g
/-
We may define
```
def normalize_aux' : ∀ {a b : B}, hom a b → path a b
| _ _ (hom.of f) := f.to_path
| _ _ (hom.id b) := nil
| _ _ (hom.comp f g) := (normalize_aux' f).comp (normalize_aux' g)
```
and define `normalize_aux p f` to be `p.comp (normalize_aux' f)` and this will be
equal to the above definition, but the equality proof requires `comp_assoc`, and it
thus lacks the correct definitional property to make the definition of `normalize_iso`
typecheck.
```
example {a b c : B} (p : path a b) (f : hom b c) :
normalize_aux p f = p.comp (normalize_aux' f) :=
by { induction f, refl, refl,
case comp : _ _ _ _ _ ihf ihg { rw [normalize_aux, ihf, ihg], apply comp_assoc } }
```
-/
/--
A 2-isomorphism between a partially-normalized 1-morphism in the free bicategory to the
fully-normalized 1-morphism.
-/
@[simp]
def normalize_iso {a : B} : ∀ {b c : B} (p : path a b) (f : hom b c),
(preinclusion B).map ⟨p⟩ ≫ f ≅ (preinclusion B).map ⟨normalize_aux p f⟩
| _ _ p (hom.of f) := iso.refl _
| _ _ p (hom.id b) := ρ_ _
| _ _ p (hom.comp f g) := (α_ _ _ _).symm ≪≫
whisker_right_iso (normalize_iso p f) g ≪≫ normalize_iso (normalize_aux p f) g
/--
Given a 2-morphism between `f` and `g` in the free bicategory, we have the equality
`normalize_aux p f = normalize_aux p g`.
-/
lemma normalize_aux_congr {a b c : B} (p : path a b) {f g : hom b c} (η : f ⟶ g) :
normalize_aux p f = normalize_aux p g :=
begin
rcases η,
apply @congr_fun _ _ (λ p, normalize_aux p f),
clear p,
induction η,
case vcomp { apply eq.trans; assumption },
/- p ≠ nil required! See the docstring of `normalize_aux`. -/
case whisker_left : _ _ _ _ _ _ _ ih { funext, apply congr_fun ih },
case whisker_right : _ _ _ _ _ _ _ ih { funext, apply congr_arg2 _ (congr_fun ih p) rfl },
all_goals { funext, refl }
end
/-- The 2-isomorphism `normalize_iso p f` is natural in `f`. -/
lemma normalize_naturality {a b c : B} (p : path a b) {f g : hom b c} (η : f ⟶ g) :
(preinclusion B).map ⟨p⟩ ◁ η ≫ (normalize_iso p g).hom =
(normalize_iso p f).hom ≫
(preinclusion B).map₂ (eq_to_hom (discrete.ext _ _ (normalize_aux_congr p η))) :=
begin
rcases η, induction η,
case id : { simp },
case vcomp : _ _ _ _ _ _ _ ihf ihg
{ rw [mk_vcomp, bicategory.whisker_left_comp],
slice_lhs 2 3 { rw ihg },
slice_lhs 1 2 { rw ihf },
simp },
case whisker_left : _ _ _ _ _ _ _ ih
/- p ≠ nil required! See the docstring of `normalize_aux`. -/
{ dsimp, simp_rw [associator_inv_naturality_right_assoc, whisker_exchange_assoc, ih, assoc] },
case whisker_right : _ _ _ _ _ h η ih
{ dsimp,
rw [associator_inv_naturality_middle_assoc, ←comp_whisker_right_assoc, ih, comp_whisker_right],
have := dcongr_arg (λ x, (normalize_iso x h).hom) (normalize_aux_congr p (quot.mk _ η)),
dsimp at this, simp [this] },
all_goals { dsimp, dsimp [id_def, comp_def], simp }
end
@[simp]
lemma normalize_aux_nil_comp {a b c : B} (f : hom a b) (g : hom b c) :
normalize_aux nil (f.comp g) = (normalize_aux nil f).comp (normalize_aux nil g) :=
begin
induction g generalizing a,
case id { refl },
case of { refl },
case comp : _ _ _ g _ ihf ihg { erw [ihg (f.comp g), ihf f, ihg g, comp_assoc] }
end
/-- The normalization pseudofunctor for the free bicategory on a quiver `B`. -/
def normalize (B : Type u) [quiver.{v+1} B] :
pseudofunctor (free_bicategory B) (locally_discrete (paths B)) :=
{ obj := id,
map := λ a b f, ⟨normalize_aux nil f⟩,
map₂ := λ a b f g η, eq_to_hom $ discrete.ext _ _ $ normalize_aux_congr nil η,
map_id := λ a, eq_to_iso $ discrete.ext _ _ rfl,
map_comp := λ a b c f g, eq_to_iso $ discrete.ext _ _ $ normalize_aux_nil_comp f g }
/-- Auxiliary definition for `normalize_equiv`. -/
def normalize_unit_iso (a b : free_bicategory B) :
𝟭 (a ⟶ b) ≅ (normalize B).map_functor a b ⋙ inclusion_path a b :=
nat_iso.of_components (λ f, (λ_ f).symm ≪≫ normalize_iso nil f)
begin
intros f g η,
erw [left_unitor_inv_naturality_assoc, assoc],
congr' 1,
exact normalize_naturality nil η
end
/-- Normalization as an equivalence of categories. -/
def normalize_equiv (a b : B) : hom a b ≌ discrete (path.{v+1} a b) :=
equivalence.mk ((normalize _).map_functor a b) (inclusion_path a b)
(normalize_unit_iso a b)
(discrete.nat_iso (λ f, eq_to_iso (by { induction f; induction f; tidy })))
/-- The coherence theorem for bicategories. -/
instance locally_thin {a b : free_bicategory B} : quiver.is_thin (a ⟶ b) :=
λ _ _, ⟨λ η θ, (normalize_equiv a b).functor.map_injective (subsingleton.elim _ _)⟩
/-- Auxiliary definition for `inclusion`. -/
def inclusion_map_comp_aux {a b : B} : ∀ {c : B} (f : path a b) (g : path b c),
(preinclusion _).map (⟨f⟩ ≫ ⟨g⟩) ≅ (preinclusion _).map ⟨f⟩ ≫ (preinclusion _).map ⟨g⟩
| _ f nil := (ρ_ ((preinclusion _).map ⟨f⟩)).symm
| _ f (cons g₁ g₂) := whisker_right_iso (inclusion_map_comp_aux f g₁) (hom.of g₂) ≪≫ α_ _ _ _
/--
The inclusion pseudofunctor from the locally discrete bicategory on the path category into the
free bicategory.
-/
def inclusion (B : Type u) [quiver.{v+1} B] :
pseudofunctor (locally_discrete (paths B)) (free_bicategory B) :=
{ map_id := λ a, iso.refl (𝟙 a),
map_comp := λ a b c f g, inclusion_map_comp_aux f.as g.as,
-- All the conditions for 2-morphisms are trivial thanks to the coherence theorem!
.. preinclusion B }
end free_bicategory
end category_theory
|
7c572118623f44c5b76c5a6dbfdae75a411d3f53
|
11d98f23718b57e0a9dd4c0889d2c1e37ced2afa
|
/lean/effects.lean
|
c46a07f73e23c7c0d23d36d0df41addd0a0add07
|
[] |
no_license
|
ulidtko/exe
|
401805a37bba87e16b78f1ff923fffef383e31fa
|
2a326f233895bc46ae48c559da3ded1b0481232f
|
refs/heads/master
| 1,611,519,189,455
| 1,452,174,370,000
| 1,452,174,409,000
| 49,207,131
| 0
| 0
| null | 1,452,174,448,000
| 1,452,174,447,000
| null |
UTF-8
|
Lean
| false
| false
| 626
|
lean
|
import data.nat data.bool data.prod data.list data.sum data.stream
data.unit data.uprod data.tuple data.option
namespace effects open nat bool prod sum list classical option stream
record eff (x: Type) := (carrier : x)
record io (x: Type) extends eff x := (get: unit → eff x) (put: x → eff x)
record exception (x: Type) extends eff x := (raise: x → eff x)
record comm (x: Type) extends eff x := (recv: unit → eff x) (send: x → eff x)
definition unpure (x: Type) := Type → x → eff x
print unpure
end effects
|
88088c51a1ef6d17f1803cafbdff07b9be600c85
|
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
|
/src/group_theory/perm/support.lean
|
f7a3eac9fe4dc17c82741a50cc1ae3f5947f2d86
|
[
"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
| 20,231
|
lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Aaron Anderson, Yakov Pechersky
-/
import data.finset.sort
import data.fintype.basic
import group_theory.perm.basic
/-!
# Support of a permutation
## Main definitions
In the following, `f g : equiv.perm α`.
* `equiv.perm.disjoint`: two permutations `f` and `g` are `disjoint` if every element is fixed
either by `f`, or by `g`.
Equivalently, `f` and `g` are `disjoint` iff their `support` are disjoint.
* `equiv.perm.is_swap`: `f = swap x y` for `x ≠ y`.
* `equiv.perm.support`: the elements `x : α` that are not fixed by `f`.
-/
open equiv finset
namespace equiv.perm
variables {α : Type*}
section disjoint
/-- Two permutations `f` and `g` are `disjoint` if their supports are disjoint, i.e.,
every element is fixed either by `f`, or by `g`. -/
def disjoint (f g : perm α) := ∀ x, f x = x ∨ g x = x
variables {f g h : perm α}
@[symm] lemma disjoint.symm : disjoint f g → disjoint g f :=
by simp only [disjoint, or.comm, imp_self]
lemma disjoint.symmetric : symmetric (@disjoint α) :=
λ _ _, disjoint.symm
lemma disjoint_comm : disjoint f g ↔ disjoint g f :=
⟨disjoint.symm, disjoint.symm⟩
lemma disjoint.commute (h : disjoint f g) : commute f g :=
equiv.ext $ λ x, (h x).elim
(λ hf, (h (g x)).elim (λ hg, by simp [mul_apply, hf, hg])
(λ hg, by simp [mul_apply, hf, g.injective hg]))
(λ hg, (h (f x)).elim (λ hf, by simp [mul_apply, f.injective hf, hg])
(λ hf, by simp [mul_apply, hf, hg]))
@[simp] lemma disjoint_one_left (f : perm α) : disjoint 1 f := λ _, or.inl rfl
@[simp] lemma disjoint_one_right (f : perm α) : disjoint f 1 := λ _, or.inr rfl
lemma disjoint_iff_eq_or_eq : disjoint f g ↔ ∀ (x : α), f x = x ∨ g x = x := iff.rfl
@[simp] lemma disjoint_refl_iff : disjoint f f ↔ f = 1 :=
begin
refine ⟨λ h, _, λ h, h.symm ▸ disjoint_one_left 1⟩,
ext x,
cases h x with hx hx;
simp [hx]
end
lemma disjoint.inv_left (h : disjoint f g) : disjoint f⁻¹ g :=
begin
intro x,
rw [inv_eq_iff_eq, eq_comm],
exact h x
end
lemma disjoint.inv_right (h : disjoint f g) : disjoint f g⁻¹ :=
h.symm.inv_left.symm
@[simp] lemma disjoint_inv_left_iff : disjoint f⁻¹ g ↔ disjoint f g :=
begin
refine ⟨λ h, _, disjoint.inv_left⟩,
convert h.inv_left,
exact (inv_inv _).symm
end
@[simp] lemma disjoint_inv_right_iff : disjoint f g⁻¹ ↔ disjoint f g :=
by rw [disjoint_comm, disjoint_inv_left_iff, disjoint_comm]
lemma disjoint.mul_left (H1 : disjoint f h) (H2 : disjoint g h) :
disjoint (f * g) h :=
λ x, by cases H1 x; cases H2 x; simp *
lemma disjoint.mul_right (H1 : disjoint f g) (H2 : disjoint f h) :
disjoint f (g * h) :=
by { rw disjoint_comm, exact H1.symm.mul_left H2.symm }
lemma disjoint_prod_right (l : list (perm α))
(h : ∀ g ∈ l, disjoint f g) : disjoint f l.prod :=
begin
induction l with g l ih,
{ exact disjoint_one_right _ },
{ rw list.prod_cons,
exact (h _ (list.mem_cons_self _ _)).mul_right (ih (λ g hg, h g (list.mem_cons_of_mem _ hg))) }
end
lemma disjoint_prod_perm {l₁ l₂ : list (perm α)} (hl : l₁.pairwise disjoint)
(hp : l₁ ~ l₂) : l₁.prod = l₂.prod :=
hp.prod_eq' $ hl.imp $ λ f g, disjoint.commute
lemma nodup_of_pairwise_disjoint {l : list (perm α)} (h1 : (1 : perm α) ∉ l)
(h2 : l.pairwise disjoint) : l.nodup :=
begin
refine list.pairwise.imp_of_mem _ h2,
rintros σ - h_mem - h_disjoint rfl,
suffices : σ = 1,
{ rw this at h_mem,
exact h1 h_mem },
exact ext (λ a, (or_self _).mp (h_disjoint a)),
end
lemma pow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) :
∀ n : ℕ, (f ^ n) x = x
| 0 := rfl
| (n+1) := by rw [pow_succ', mul_apply, hfx, pow_apply_eq_self_of_apply_eq_self]
lemma zpow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) :
∀ n : ℤ, (f ^ n) x = x
| (n : ℕ) := pow_apply_eq_self_of_apply_eq_self hfx n
| -[1+ n] := by rw [zpow_neg_succ_of_nat, inv_eq_iff_eq, pow_apply_eq_self_of_apply_eq_self hfx]
lemma pow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) :
∀ n : ℕ, (f ^ n) x = x ∨ (f ^ n) x = f x
| 0 := or.inl rfl
| (n+1) := (pow_apply_eq_of_apply_apply_eq_self n).elim
(λ h, or.inr (by rw [pow_succ, mul_apply, h]))
(λ h, or.inl (by rw [pow_succ, mul_apply, h, hffx]))
lemma zpow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) :
∀ i : ℤ, (f ^ i) x = x ∨ (f ^ i) x = f x
| (n : ℕ) := pow_apply_eq_of_apply_apply_eq_self hffx n
| -[1+ n] := by { rw [zpow_neg_succ_of_nat, inv_eq_iff_eq, ← f.injective.eq_iff, ← mul_apply,
← pow_succ, eq_comm, inv_eq_iff_eq, ← mul_apply, ← pow_succ', @eq_comm _ x, or.comm],
exact pow_apply_eq_of_apply_apply_eq_self hffx _ }
lemma disjoint.mul_apply_eq_iff {σ τ : perm α} (hστ : disjoint σ τ) {a : α} :
(σ * τ) a = a ↔ σ a = a ∧ τ a = a :=
begin
refine ⟨λ h, _, λ h, by rw [mul_apply, h.2, h.1]⟩,
cases hστ a with hσ hτ,
{ exact ⟨hσ, σ.injective (h.trans hσ.symm)⟩ },
{ exact ⟨(congr_arg σ hτ).symm.trans h, hτ⟩ },
end
lemma disjoint.mul_eq_one_iff {σ τ : perm α} (hστ : disjoint σ τ) :
σ * τ = 1 ↔ σ = 1 ∧ τ = 1 :=
by simp_rw [ext_iff, one_apply, hστ.mul_apply_eq_iff, forall_and_distrib]
lemma disjoint.zpow_disjoint_zpow {σ τ : perm α} (hστ : disjoint σ τ) (m n : ℤ) :
disjoint (σ ^ m) (τ ^ n) :=
λ x, or.imp (λ h, zpow_apply_eq_self_of_apply_eq_self h m)
(λ h, zpow_apply_eq_self_of_apply_eq_self h n) (hστ x)
lemma disjoint.pow_disjoint_pow {σ τ : perm α} (hστ : disjoint σ τ) (m n : ℕ) :
disjoint (σ ^ m) (τ ^ n) :=
hστ.zpow_disjoint_zpow m n
end disjoint
section is_swap
variable [decidable_eq α]
/-- `f.is_swap` indicates that the permutation `f` is a transposition of two elements. -/
def is_swap (f : perm α) : Prop := ∃ x y, x ≠ y ∧ f = swap x y
lemma is_swap.of_subtype_is_swap {p : α → Prop} [decidable_pred p]
{f : perm (subtype p)} (h : f.is_swap) : (of_subtype f).is_swap :=
let ⟨⟨x, hx⟩, ⟨y, hy⟩, hxy⟩ := h in
⟨x, y, by { simp only [ne.def] at hxy, exact hxy.1 },
equiv.ext $ λ z, begin
rw [hxy.2, of_subtype],
simp only [swap_apply_def, coe_fn_mk, swap_inv, subtype.mk_eq_mk, monoid_hom.coe_mk],
split_ifs;
rw subtype.coe_mk <|> cc,
end⟩
lemma ne_and_ne_of_swap_mul_apply_ne_self {f : perm α} {x y : α}
(hy : (swap x (f x) * f) y ≠ y) : f y ≠ y ∧ y ≠ x :=
begin
simp only [swap_apply_def, mul_apply, f.injective.eq_iff] at *,
by_cases h : f y = x,
{ split; intro; simp only [*, if_true, eq_self_iff_true, not_true, ne.def] at * },
{ split_ifs at hy; cc }
end
end is_swap
section support
section set
variables (p q : perm α)
lemma set_support_inv_eq :
{x | p⁻¹ x ≠ x} = {x | p x ≠ x} :=
begin
ext x,
simp only [set.mem_set_of_eq, ne.def],
rw [inv_def, symm_apply_eq, eq_comm]
end
lemma set_support_apply_mem {p : perm α} {a : α} :
p a ∈ {x | p x ≠ x} ↔ a ∈ {x | p x ≠ x} :=
by simp
lemma set_support_zpow_subset (n : ℤ) :
{x | (p ^ n) x ≠ x} ⊆ {x | p x ≠ x} :=
begin
intros x,
simp only [set.mem_set_of_eq, ne.def],
intros hx H,
simpa [zpow_apply_eq_self_of_apply_eq_self H] using hx
end
lemma set_support_mul_subset :
{x | (p * q) x ≠ x} ⊆ {x | p x ≠ x} ∪ {x | q x ≠ x} :=
begin
intro x,
simp only [perm.coe_mul, function.comp_app, ne.def, set.mem_union_eq, set.mem_set_of_eq],
by_cases hq : q x = x;
simp [hq]
end
end set
variables [decidable_eq α] [fintype α] {f g : perm α}
/-- The `finset` of nonfixed points of a permutation. -/
def support (f : perm α) : finset α := univ.filter (λ x, f x ≠ x)
@[simp] lemma mem_support {x : α} : x ∈ f.support ↔ f x ≠ x :=
by rw [support, mem_filter, and_iff_right (mem_univ x)]
lemma not_mem_support {x : α} : x ∉ f.support ↔ f x = x := by simp
lemma coe_support_eq_set_support (f : perm α) :
(f.support : set α) = {x | f x ≠ x} :=
by { ext, simp }
@[simp] lemma support_eq_empty_iff {σ : perm α} : σ.support = ∅ ↔ σ = 1 :=
by simp_rw [finset.ext_iff, mem_support, finset.not_mem_empty, iff_false, not_not,
equiv.perm.ext_iff, one_apply]
@[simp] lemma support_one : (1 : perm α).support = ∅ :=
by rw support_eq_empty_iff
@[simp] lemma support_refl : support (equiv.refl α) = ∅ := support_one
lemma support_congr (h : f.support ⊆ g.support)
(h' : ∀ x ∈ g.support, f x = g x) : f = g :=
begin
ext x,
by_cases hx : x ∈ g.support,
{ exact h' x hx },
{ rw [not_mem_support.mp hx, ←not_mem_support],
exact λ H, hx (h H) }
end
lemma support_mul_le (f g : perm α) :
(f * g).support ≤ f.support ⊔ g.support :=
λ x, begin
rw [sup_eq_union, mem_union, mem_support, mem_support,
mem_support, mul_apply, ←not_and_distrib, not_imp_not],
rintro ⟨hf, hg⟩,
rw [hg, hf]
end
lemma exists_mem_support_of_mem_support_prod {l : list (perm α)} {x : α}
(hx : x ∈ l.prod.support) :
∃ f : perm α, f ∈ l ∧ x ∈ f.support :=
begin
contrapose! hx,
simp_rw [mem_support, not_not] at hx ⊢,
induction l with f l ih generalizing hx,
{ refl },
{ rw [list.prod_cons, mul_apply, ih (λ g hg, hx g (or.inr hg)), hx f (or.inl rfl)] },
end
lemma support_pow_le (σ : perm α) (n : ℕ) :
(σ ^ n).support ≤ σ.support :=
λ x h1, mem_support.mpr (λ h2, mem_support.mp h1 (pow_apply_eq_self_of_apply_eq_self h2 n))
@[simp] lemma support_inv (σ : perm α) : support (σ⁻¹) = σ.support :=
by simp_rw [finset.ext_iff, mem_support, not_iff_not,
(inv_eq_iff_eq).trans eq_comm, iff_self, imp_true_iff]
@[simp]
lemma apply_mem_support {x : α} :
f x ∈ f.support ↔ x ∈ f.support :=
by rw [mem_support, mem_support, ne.def, ne.def, not_iff_not, apply_eq_iff_eq]
@[simp]
lemma pow_apply_mem_support {n : ℕ} {x : α} :
(f ^ n) x ∈ f.support ↔ x ∈ f.support :=
begin
induction n with n ih,
{ refl },
rw [pow_succ, perm.mul_apply, apply_mem_support, ih]
end
@[simp]
lemma zpow_apply_mem_support {n : ℤ} {x : α} :
(f ^ n) x ∈ f.support ↔ x ∈ f.support :=
begin
cases n,
{ rw [int.of_nat_eq_coe, zpow_coe_nat, pow_apply_mem_support] },
{ rw [zpow_neg_succ_of_nat, ← support_inv, ← inv_pow, pow_apply_mem_support] }
end
lemma pow_eq_on_of_mem_support (h : ∀ (x ∈ f.support ∩ g.support), f x = g x)
(k : ℕ) : ∀ (x ∈ f.support ∩ g.support), (f ^ k) x = (g ^ k) x :=
begin
induction k with k hk,
{ simp },
{ intros x hx,
rw [pow_succ', mul_apply, pow_succ', mul_apply, h _ hx, hk],
rwa [mem_inter, apply_mem_support, ←h _ hx, apply_mem_support, ←mem_inter] }
end
lemma disjoint_iff_disjoint_support :
disjoint f g ↔ _root_.disjoint f.support g.support :=
by simp [disjoint_iff_eq_or_eq, disjoint_iff, finset.ext_iff, not_and_distrib]
lemma disjoint.disjoint_support (h : disjoint f g) :
_root_.disjoint f.support g.support :=
disjoint_iff_disjoint_support.1 h
lemma disjoint.support_mul (h : disjoint f g) :
(f * g).support = f.support ∪ g.support :=
begin
refine le_antisymm (support_mul_le _ _) (λ a, _),
rw [mem_union, mem_support, mem_support, mem_support, mul_apply, ←not_and_distrib, not_imp_not],
exact (h a).elim (λ hf h, ⟨hf, f.apply_eq_iff_eq.mp (h.trans hf.symm)⟩)
(λ hg h, ⟨(congr_arg f hg).symm.trans h, hg⟩),
end
lemma support_prod_of_pairwise_disjoint (l : list (perm α)) (h : l.pairwise disjoint) :
l.prod.support = (l.map support).foldr (⊔) ⊥ :=
begin
induction l with hd tl hl,
{ simp },
{ rw [list.pairwise_cons] at h,
have : disjoint hd tl.prod := disjoint_prod_right _ h.left,
simp [this.support_mul, hl h.right] }
end
lemma support_prod_le (l : list (perm α)) :
l.prod.support ≤ (l.map support).foldr (⊔) ⊥ :=
begin
induction l with hd tl hl,
{ simp },
{ rw [list.prod_cons, list.map_cons, list.foldr_cons],
refine (support_mul_le hd tl.prod).trans _,
exact sup_le_sup (le_refl _) hl }
end
lemma support_zpow_le (σ : perm α) (n : ℤ) :
(σ ^ n).support ≤ σ.support :=
λ x h1, mem_support.mpr (λ h2, mem_support.mp h1 (zpow_apply_eq_self_of_apply_eq_self h2 n))
@[simp] lemma support_swap {x y : α} (h : x ≠ y) : support (swap x y) = {x, y} :=
begin
ext z,
by_cases hx : z = x;
by_cases hy : z = y,
any_goals { simpa [hx, hy] using h.symm },
{ simp [swap_apply_of_ne_of_ne, hx, hy] }
end
lemma support_swap_iff (x y : α) :
support (swap x y) = {x, y} ↔ x ≠ y :=
begin
refine ⟨λ h H, _, support_swap⟩,
subst H,
simp only [swap_self, support_refl, insert_singleton_self_eq] at h,
have : x ∈ ∅,
{ rw h,
exact mem_singleton.mpr rfl },
simpa
end
lemma support_swap_mul_swap {x y z : α} (h : list.nodup [x, y, z]) :
support (swap x y * swap y z) = {x, y, z} :=
begin
simp only [list.not_mem_nil, and_true, list.mem_cons_iff, not_false_iff, list.nodup_cons,
list.mem_singleton, and_self, list.nodup_nil] at h,
push_neg at h,
apply le_antisymm,
{ convert support_mul_le _ _,
rw [support_swap h.left.left, support_swap h.right],
ext,
simp [or.comm, or.left_comm] },
{ intro,
simp only [mem_insert, mem_singleton],
rintro (rfl | rfl | rfl | _);
simp [swap_apply_of_ne_of_ne, h.left.left, h.left.left.symm, h.left.right, h.left.right.symm,
h.right.symm] }
end
lemma support_swap_mul_ge_support_diff (f : perm α) (x y : α) :
f.support \ {x, y} ≤ (swap x y * f).support :=
begin
intro,
simp only [and_imp, perm.coe_mul, function.comp_app, ne.def, mem_support, mem_insert, mem_sdiff,
mem_singleton],
push_neg,
rintro ha ⟨hx, hy⟩ H,
rw [swap_apply_eq_iff, swap_apply_of_ne_of_ne hx hy] at H,
exact ha H
end
lemma support_swap_mul_eq (f : perm α) (x : α) (h : f (f x) ≠ x) :
(swap x (f x) * f).support = f.support \ {x} :=
begin
by_cases hx : f x = x,
{ simp [hx, sdiff_singleton_eq_erase, not_mem_support.mpr hx, erase_eq_of_not_mem] },
ext z,
by_cases hzx : z = x,
{ simp [hzx] },
by_cases hzf : z = f x,
{ simp [hzf, hx, h, swap_apply_of_ne_of_ne], },
by_cases hzfx : f z = x,
{ simp [ne.symm hzx, hzx, ne.symm hzf, hzfx] },
{ simp [ne.symm hzx, hzx, ne.symm hzf, hzfx, f.injective.ne hzx, swap_apply_of_ne_of_ne] }
end
lemma mem_support_swap_mul_imp_mem_support_ne {x y : α}
(hy : y ∈ support (swap x (f x) * f)) : y ∈ support f ∧ y ≠ x :=
begin
simp only [mem_support, swap_apply_def, mul_apply, f.injective.eq_iff] at *,
by_cases h : f y = x,
{ split; intro; simp only [*, if_true, eq_self_iff_true, not_true, ne.def] at * },
{ split_ifs at hy; cc }
end
lemma disjoint.mem_imp (h : disjoint f g) {x : α} (hx : x ∈ f.support) :
x ∉ g.support :=
λ H, h.disjoint_support (mem_inter_of_mem hx H)
lemma eq_on_support_mem_disjoint {l : list (perm α)} (h : f ∈ l) (hl : l.pairwise disjoint) :
∀ (x ∈ f.support), f x = l.prod x :=
begin
induction l with hd tl IH,
{ simpa using h },
{ intros x hx,
rw list.pairwise_cons at hl,
rw list.mem_cons_iff at h,
rcases h with rfl|h,
{ rw [list.prod_cons, mul_apply, not_mem_support.mp
((disjoint_prod_right tl hl.left).mem_imp hx)] },
{ rw [list.prod_cons, mul_apply, ←IH h hl.right _ hx, eq_comm, ←not_mem_support],
refine (hl.left _ h).symm.mem_imp _,
simpa using hx } }
end
lemma disjoint.mono {x y : perm α} (h : disjoint f g)
(hf : x.support ≤ f.support) (hg : y.support ≤ g.support) :
disjoint x y :=
begin
rw disjoint_iff_disjoint_support at h ⊢,
intros a ha,
exact h (mem_inter_of_mem (hf (mem_of_mem_inter_left ha)) (hg (mem_of_mem_inter_right ha)))
end
lemma support_le_prod_of_mem {l : list (perm α)} (h : f ∈ l) (hl : l.pairwise disjoint) :
f.support ≤ l.prod.support :=
begin
intros x hx,
rwa [mem_support, ←eq_on_support_mem_disjoint h hl _ hx, ←mem_support],
end
section extend_domain
variables {β : Type*} [decidable_eq β] [fintype β] {p : β → Prop} [decidable_pred p]
@[simp]
lemma support_extend_domain (f : α ≃ subtype p) {g : perm α} :
support (g.extend_domain f) = g.support.map f.as_embedding :=
begin
ext b,
simp only [exists_prop, function.embedding.coe_fn_mk, to_embedding_apply, mem_map, ne.def,
function.embedding.trans_apply, mem_support],
by_cases pb : p b,
{ rw [extend_domain_apply_subtype _ _ pb],
split,
{ rintro h,
refine ⟨f.symm ⟨b, pb⟩, _, by simp⟩,
contrapose! h,
simp [h] },
{ rintro ⟨a, ha, hb⟩,
contrapose! ha,
obtain rfl : a = f.symm ⟨b, pb⟩,
{ rw eq_symm_apply,
exact subtype.coe_injective hb },
rw eq_symm_apply,
exact subtype.coe_injective ha } },
{ rw [extend_domain_apply_not_subtype _ _ pb],
simp only [not_exists, false_iff, not_and, eq_self_iff_true, not_true],
rintros a ha rfl,
exact pb (subtype.prop _) }
end
lemma card_support_extend_domain (f : α ≃ subtype p) {g : perm α} :
(g.extend_domain f).support.card = g.support.card :=
by simp
end extend_domain
section card
@[simp]
lemma card_support_eq_zero {f : perm α} :
f.support.card = 0 ↔ f = 1 :=
by rw [finset.card_eq_zero, support_eq_empty_iff]
lemma one_lt_card_support_of_ne_one {f : perm α} (h : f ≠ 1) :
1 < f.support.card :=
begin
simp_rw [one_lt_card_iff, mem_support, ←not_or_distrib],
contrapose! h,
ext a,
specialize h (f a) a,
rwa [apply_eq_iff_eq, or_self, or_self] at h,
end
lemma card_support_ne_one (f : perm α) : f.support.card ≠ 1 :=
begin
by_cases h : f = 1,
{ exact ne_of_eq_of_ne (card_support_eq_zero.mpr h) zero_ne_one },
{ exact ne_of_gt (one_lt_card_support_of_ne_one h) },
end
@[simp] lemma card_support_le_one {f : perm α} : f.support.card ≤ 1 ↔ f = 1 :=
by rw [le_iff_lt_or_eq, nat.lt_succ_iff, nat.le_zero_iff, card_support_eq_zero,
or_iff_not_imp_right, imp_iff_right f.card_support_ne_one]
lemma two_le_card_support_of_ne_one {f : perm α} (h : f ≠ 1) :
2 ≤ f.support.card :=
one_lt_card_support_of_ne_one h
lemma card_support_swap_mul {f : perm α} {x : α}
(hx : f x ≠ x) : (swap x (f x) * f).support.card < f.support.card :=
finset.card_lt_card
⟨λ z hz, (mem_support_swap_mul_imp_mem_support_ne hz).left,
λ h, absurd (h (mem_support.2 hx)) (mt mem_support.1 (by simp))⟩
lemma card_support_swap {x y : α} (hxy : x ≠ y) : (swap x y).support.card = 2 :=
show (swap x y).support.card = finset.card ⟨x ::ₘ y ::ₘ 0, by simp [hxy]⟩,
from congr_arg card $ by simp [support_swap hxy, *, finset.ext_iff]
@[simp]
lemma card_support_eq_two {f : perm α} : f.support.card = 2 ↔ is_swap f :=
begin
split; intro h,
{ obtain ⟨x, t, hmem, hins, ht⟩ := card_eq_succ.1 h,
obtain ⟨y, rfl⟩ := card_eq_one.1 ht,
rw mem_singleton at hmem,
refine ⟨x, y, hmem, _⟩,
ext a,
have key : ∀ b, f b ≠ b ↔ _ := λ b, by rw [←mem_support, ←hins, mem_insert, mem_singleton],
by_cases ha : f a = a,
{ have ha' := not_or_distrib.mp (mt (key a).mpr (not_not.mpr ha)),
rw [ha, swap_apply_of_ne_of_ne ha'.1 ha'.2] },
{ have ha' := (key (f a)).mp (mt f.apply_eq_iff_eq.mp ha),
obtain rfl | rfl := ((key a).mp ha),
{ rw [or.resolve_left ha' ha, swap_apply_left] },
{ rw [or.resolve_right ha' ha, swap_apply_right] } } },
{ obtain ⟨x, y, hxy, rfl⟩ := h,
exact card_support_swap hxy }
end
lemma disjoint.card_support_mul (h : disjoint f g) :
(f * g).support.card = f.support.card + g.support.card :=
begin
rw ←finset.card_disjoint_union,
{ congr,
ext,
simp [h.support_mul] },
{ simpa using h.disjoint_support }
end
lemma card_support_prod_list_of_pairwise_disjoint {l : list (perm α)}
(h : l.pairwise disjoint) :
l.prod.support.card = (l.map (finset.card ∘ support)).sum :=
begin
induction l with a t ih,
{ exact card_support_eq_zero.mpr rfl, },
{ obtain ⟨ha, ht⟩ := list.pairwise_cons.1 h,
rw [list.prod_cons, list.map_cons, list.sum_cons, ←ih ht],
exact (disjoint_prod_right _ ha).card_support_mul }
end
end card
end support
end equiv.perm
|
ea6e34956eafdf8c745bf8cb38b0b6ac5875ce40
|
36cfb52a5926b96dc8a44d3b71d2f14a21ef8574
|
/sort.lean
|
a2196b4ba2c96373d77d6568e3ac30ae53e5da98
|
[] |
no_license
|
minchaowu/relevance_filter
|
b46e3cc166b8225b19fac61b8f9911eeecdd42d8
|
3ae59d297ed5a07bd14749112e520b74209f10fd
|
refs/heads/master
| 1,631,071,413,821
| 1,507,745,131,000
| 1,507,745,131,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 2,724
|
lean
|
/-
Sorting on arrays.
-/
section quicksort
variables {α : Type} [inhabited α]
(op : α → α → bool)
local infix `<` := op
variable [has_to_format α]
meta def swap {n : ℕ} (A : array α n) (i j : ℕ) : array α n :=
let tmp_j := A.read' j,
tmp_i := A.read' i in
(A.write' j tmp_i).write' i tmp_j
meta def partition_aux (hi : ℕ) (pivot : α) {n : ℕ} : Π (A : array α n) (i j : ℕ), ℕ × array α n
| A i j :=
if j = hi then (i, A) else
let tmp_j := A.read' j in
if bnot (tmp_j < pivot) then partition_aux A i (j+1) else
let tmp_i := A.read' i,
A' := (A.write' j tmp_i).write' i tmp_j in
partition_aux A' (i+1) (j+1)
--else
-- partition_aux A i (j+1)
meta def partition {n : ℕ} (A : array α n) (lo hi : ℕ) : ℕ × array α n :=
let pivot := A.read' hi,
i := lo,
(i', A') := partition_aux op hi pivot A i lo,
A'' := if A'.read' hi < A'.read' i' then swap A' i' hi else A' in
(i', A'')
meta def quicksort_aux {n : ℕ} : Π (A : array α n) (lo hi : ℕ), array α n
| A lo hi :=
if bnot (nat.lt lo hi) then A else
let (p, A') := partition op A lo hi in
quicksort_aux (quicksort_aux A' lo (p-1)) (p+1) hi
meta def quicksort {n : ℕ} (A : array α n) : array α n :=
quicksort_aux op A 0 (n-1)
meta def partial_quicksort_aux {n : ℕ} : Π (A : array α n) (lo hi k : ℕ), array α n
| A lo hi k :=
if nat.lt lo hi then
let (p, A') := partition op A lo hi,
A'' := partial_quicksort_aux A' lo (p-1) k in
if nat.lt p (k-1) then partial_quicksort_aux A'' (p+1) hi k else A''
else A
meta def partial_quicksort {n : ℕ} (A : array α n) (k : ℕ) : array α n :=
partial_quicksort_aux op A 0 (n-1) k
end quicksort
-- super inefficient, for comparison
section mergesort
meta def merge {α : Type} [decidable_linear_order α] [inhabited α] [has_to_format α] {m n}
(lhs : array α m) (rhs : array α n) : array α (m + n) :=
let bgn := mk_array (m+n) (default α),
pr := bgn.iterate (0, 0, bgn)
(λ i a interm, match interm with
| (ln, rn, arr) :=
if (rn ≥ n) || ((ln < m) && (lhs.read' ln ≤ rhs.read' rn)) then
(ln+1, rn, arr.write i (lhs.read' ln))
else (ln, rn+1, arr.write i (rhs.read' rn))
end) in
pr.2.2
meta def merge_sort {α : Type} [decidable_linear_order α] [inhabited α] [has_to_format α] : Π {n}, array α n → array α n
| 0 a := a
| 1 a := a
| (n+2) a :=
let lhs := merge_sort (a.slice 0 (n/2 + 1) undefined undefined),
rhs := merge_sort (a.slice (n/2 + 1) (n+2) undefined undefined) in
unchecked_cast $ merge lhs rhs
end mergesort
|
176cee64a1affec74e5ff2b54a07b4a4975dcd86
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/algebra/module/ulift.lean
|
c75da83edbf521b417493bf70ae204db26423a66
|
[
"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,372
|
lean
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import algebra.ring.ulift
import algebra.module.equiv
/-!
# `ulift` instances for module and multiplicative actions
This file defines instances for module, mul_action and related structures on `ulift` types.
(Recall `ulift α` is just a "copy" of a type `α` in a higher universe.)
We also provide `ulift.module_equiv : ulift M ≃ₗ[R] M`.
-/
namespace ulift
universes u v w
variable {R : Type u}
variable {M : Type v}
variable {N : Type w}
instance has_scalar_left [has_scalar R M] :
has_scalar (ulift R) M :=
⟨λ s x, s.down • x⟩
@[simp] lemma smul_down [has_scalar R M] (s : ulift R) (x : M) : (s • x) = s.down • x := rfl
@[simp]
lemma smul_down' [has_scalar R M] (s : R) (x : ulift M) :
(s • x).down = s • x.down :=
rfl
instance is_scalar_tower [has_scalar R M] [has_scalar M N] [has_scalar R N]
[is_scalar_tower R M N] : is_scalar_tower (ulift R) M N :=
⟨λ x y z, show (x.down • y) • z = x.down • y • z, from smul_assoc _ _ _⟩
instance is_scalar_tower' [has_scalar R M] [has_scalar M N] [has_scalar R N]
[is_scalar_tower R M N] : is_scalar_tower R (ulift M) N :=
⟨λ x y z, show (x • y.down) • z = x • y.down • z, from smul_assoc _ _ _⟩
instance is_scalar_tower'' [has_scalar R M] [has_scalar M N] [has_scalar R N]
[is_scalar_tower R M N] : is_scalar_tower R M (ulift N) :=
⟨λ x y z, show up ((x • y) • z.down) = ⟨x • y • z.down⟩, by rw smul_assoc⟩
instance [has_scalar R M] [has_scalar Rᵐᵒᵖ M] [is_central_scalar R M] :
is_central_scalar R (ulift M) :=
⟨λ r m, congr_arg up $ op_smul_eq_smul r m.down⟩
instance mul_action [monoid R] [mul_action R M] : mul_action (ulift R) M :=
{ smul := (•),
mul_smul := λ _ _, mul_smul _ _,
one_smul := one_smul _ }
instance mul_action' [monoid R] [mul_action R M] :
mul_action R (ulift M) :=
{ smul := (•),
mul_smul := λ r s f, by { cases f, ext, simp [mul_smul], },
one_smul := λ f, by { ext, simp [one_smul], } }
instance distrib_mul_action [monoid R] [add_monoid M] [distrib_mul_action R M] :
distrib_mul_action (ulift R) M :=
{ smul_zero := λ _, smul_zero _,
smul_add := λ _, smul_add _ }
instance distrib_mul_action' [monoid R] [add_monoid M] [distrib_mul_action R M] :
distrib_mul_action R (ulift M) :=
{ smul_zero := λ c, by { ext, simp [smul_zero], },
smul_add := λ c f g, by { ext, simp [smul_add], },
..ulift.mul_action' }
instance mul_distrib_mul_action [monoid R] [monoid M] [mul_distrib_mul_action R M] :
mul_distrib_mul_action (ulift R) M :=
{ smul_one := λ _, smul_one _,
smul_mul := λ _, smul_mul' _ }
instance mul_distrib_mul_action' [monoid R] [monoid M] [mul_distrib_mul_action R M] :
mul_distrib_mul_action R (ulift M) :=
{ smul_one := λ _, by { ext, simp [smul_one], },
smul_mul := λ c f g, by { ext, simp [smul_mul'], },
..ulift.mul_action' }
instance smul_with_zero [has_zero R] [has_zero M] [smul_with_zero R M] :
smul_with_zero (ulift R) M :=
{ smul_zero := λ _, smul_zero' _ _,
zero_smul := zero_smul _,
..ulift.has_scalar_left }
instance smul_with_zero' [has_zero R] [has_zero M] [smul_with_zero R M] :
smul_with_zero R (ulift M) :=
{ smul_zero := λ _, ulift.ext _ _ $ smul_zero' _ _,
zero_smul := λ _, ulift.ext _ _ $ zero_smul _ _ }
instance mul_action_with_zero [monoid_with_zero R] [has_zero M] [mul_action_with_zero R M] :
mul_action_with_zero (ulift R) M :=
{ ..ulift.smul_with_zero }
instance mul_action_with_zero' [monoid_with_zero R] [has_zero M] [mul_action_with_zero R M] :
mul_action_with_zero R (ulift M) :=
{ ..ulift.smul_with_zero' }
instance module [semiring R] [add_comm_monoid M] [module R M] : module (ulift R) M :=
{ add_smul := λ _ _, add_smul _ _,
..ulift.smul_with_zero }
instance module' [semiring R] [add_comm_monoid M] [module R M] : module R (ulift M) :=
{ add_smul := λ _ _ _, ulift.ext _ _ $ add_smul _ _ _,
..ulift.smul_with_zero' }
/--
The `R`-linear equivalence between `ulift M` and `M`.
-/
def module_equiv [semiring R] [add_comm_monoid M] [module R M] : ulift M ≃ₗ[R] M :=
{ to_fun := ulift.down,
inv_fun := ulift.up,
map_smul' := λ r x, rfl,
map_add' := λ x y, rfl,
left_inv := by tidy,
right_inv := by tidy, }
end ulift
|
751891fde7e8846a07c4a7be128a3fa614efae9f
|
969dbdfed67fda40a6f5a2b4f8c4a3c7dc01e0fb
|
/src/topology/algebra/group.lean
|
8910c2c5a400793db0e0522548e9160660e9f90c
|
[
"Apache-2.0"
] |
permissive
|
SAAluthwela/mathlib
|
62044349d72dd63983a8500214736aa7779634d3
|
83a4b8b990907291421de54a78988c024dc8a552
|
refs/heads/master
| 1,679,433,873,417
| 1,615,998,031,000
| 1,615,998,031,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 28,141
|
lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot
-/
import order.filter.pointwise
import group_theory.quotient_group
import topology.algebra.monoid
import topology.homeomorph
/-!
# Theory of topological groups
This file defines the following typeclasses:
* `topological_group`, `topological_add_group`: multiplicative and additive topological groups,
i.e., groups with continuous `(*)` and `(⁻¹)` / `(+)` and `(-)`;
* `has_continuous_sub G` means that `G` has a continuous subtraction operation.
There is an instance deducing `has_continuous_sub` from `topological_group` but we use a separate
typeclass because, e.g., `ℕ` and `ℝ≥0` have continuous subtraction but are not additive groups.
We also define `homeomorph` versions of several `equiv`s: `homeomorph.mul_left`,
`homeomorph.mul_right`, `homeomorph.inv`, and prove a few facts about neighbourhood filters in
groups.
## Tags
topological space, group, topological group
-/
open classical set filter topological_space function
open_locale classical topological_space filter
universes u v w x
variables {α : Type u} {β : Type v} {G : Type w} {H : Type x}
section continuous_mul_group
/-!
### Groups with continuous multiplication
In this section we prove a few statements about groups with continuous `(*)`.
-/
variables [topological_space G] [group G] [has_continuous_mul G]
/-- Multiplication from the left in a topological group as a homeomorphism. -/
@[to_additive "Addition from the left in a topological additive group as a homeomorphism."]
protected def homeomorph.mul_left (a : G) : G ≃ₜ G :=
{ continuous_to_fun := continuous_const.mul continuous_id,
continuous_inv_fun := continuous_const.mul continuous_id,
.. equiv.mul_left a }
@[simp, to_additive]
lemma homeomorph.coe_mul_left (a : G) : ⇑(homeomorph.mul_left a) = (*) a := rfl
@[to_additive]
lemma homeomorph.mul_left_symm (a : G) : (homeomorph.mul_left a).symm = homeomorph.mul_left a⁻¹ :=
by { ext, refl }
@[to_additive]
lemma is_open_map_mul_left (a : G) : is_open_map (λ x, a * x) :=
(homeomorph.mul_left a).is_open_map
@[to_additive]
lemma is_closed_map_mul_left (a : G) : is_closed_map (λ x, a * x) :=
(homeomorph.mul_left a).is_closed_map
/-- Multiplication from the right in a topological group as a homeomorphism. -/
@[to_additive "Addition from the right in a topological additive group as a homeomorphism."]
protected def homeomorph.mul_right (a : G) :
G ≃ₜ G :=
{ 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 (a : G) : is_open_map (λ x, x * a) :=
(homeomorph.mul_right a).is_open_map
@[to_additive]
lemma is_closed_map_mul_right (a : G) : is_closed_map (λ x, x * a) :=
(homeomorph.mul_right a).is_closed_map
@[to_additive]
lemma is_open_map_div_right (a : G) : is_open_map (λ x, x / a) :=
by simpa only [div_eq_mul_inv] using is_open_map_mul_right (a⁻¹)
@[to_additive]
lemma is_closed_map_div_right (a : G) : is_closed_map (λ x, x / a) :=
by simpa only [div_eq_mul_inv] using is_closed_map_mul_right (a⁻¹)
@[to_additive]
lemma discrete_topology_of_open_singleton_one (h : is_open ({1} : set G)) : discrete_topology G :=
begin
rw ← singletons_open_iff_discrete,
intro g,
suffices : {g} = (λ (x : G), g⁻¹ * x) ⁻¹' {1},
{ rw this, exact (continuous_mul_left (g⁻¹)).is_open_preimage _ h, },
simp only [mul_one, set.preimage_mul_left_singleton, eq_self_iff_true,
inv_inv, set.singleton_eq_singleton_iff],
end
end continuous_mul_group
section topological_group
/-!
### Topological groups
A topological group is a group in which the multiplication and inversion operations are
continuous. Topological additive groups are defined in the same way. Equivalently, we can require
that the division operation `λ x y, x * y⁻¹` (resp., subtraction) is continuous.
-/
/-- A topological (additive) group is a group in which the addition and negation operations are
continuous. -/
class topological_add_group (G : Type u) [topological_space G] [add_group G]
extends has_continuous_add G : Prop :=
(continuous_neg : continuous (λa:G, -a))
/-- A topological group is a group in which the multiplication and inversion operations are
continuous. -/
@[to_additive]
class topological_group (G : Type*) [topological_space G] [group G]
extends has_continuous_mul G : Prop :=
(continuous_inv : continuous (has_inv.inv : G → G))
variables [topological_space G] [group G] [topological_group G]
export topological_group (continuous_inv)
export topological_add_group (continuous_neg)
@[to_additive]
lemma continuous_on_inv {s : set G} : continuous_on has_inv.inv s :=
continuous_inv.continuous_on
@[to_additive]
lemma continuous_within_at_inv {s : set G} {x : G} : continuous_within_at has_inv.inv s x :=
continuous_inv.continuous_within_at
@[to_additive]
lemma continuous_at_inv {x : G} : continuous_at has_inv.inv x :=
continuous_inv.continuous_at
@[to_additive]
lemma tendsto_inv (a : G) : tendsto has_inv.inv (𝓝 a) (𝓝 (a⁻¹)) :=
continuous_at_inv
/-- 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 {f : α → G} {l : filter α} {y : G} (h : tendsto f l (𝓝 y)) :
tendsto (λ x, (f x)⁻¹) l (𝓝 y⁻¹) :=
(continuous_inv.tendsto y).comp h
variables [topological_space α] {f : α → G} {s : set α} {x : α}
@[continuity, to_additive]
lemma continuous.inv (hf : continuous f) : continuous (λx, (f x)⁻¹) :=
continuous_inv.comp hf
attribute [continuity] continuous.neg -- TODO
@[to_additive]
lemma continuous_on.inv (hf : continuous_on f s) : continuous_on (λx, (f x)⁻¹) s :=
continuous_inv.comp_continuous_on hf
@[to_additive]
lemma continuous_within_at.inv (hf : continuous_within_at f s x) :
continuous_within_at (λ x, (f x)⁻¹) s x :=
hf.inv
@[instance, to_additive]
instance [topological_space H] [group H] [topological_group H] :
topological_group (G × H) :=
{ continuous_inv := continuous_inv.prod_map continuous_inv }
variable (G)
/-- Inversion in a topological group as a homeomorphism. -/
@[to_additive "Negation in a topological group as a homeomorphism."]
protected def homeomorph.inv : G ≃ₜ G :=
{ continuous_to_fun := continuous_inv,
continuous_inv_fun := continuous_inv,
.. equiv.inv G }
@[to_additive]
lemma nhds_one_symm : comap has_inv.inv (𝓝 (1 : G)) = 𝓝 (1 : G) :=
((homeomorph.inv G).comap_nhds_eq _).trans (congr_arg nhds one_inv)
/-- The map `(x, y) ↦ (x, xy)` as a homeomorphism. This is a shear mapping. -/
@[to_additive "The map `(x, y) ↦ (x, x + y)` as a homeomorphism.
This is a shear mapping."]
protected def homeomorph.shear_mul_right : G × G ≃ₜ G × G :=
{ continuous_to_fun := continuous_fst.prod_mk continuous_mul,
continuous_inv_fun := continuous_fst.prod_mk $ continuous_fst.inv.mul continuous_snd,
.. equiv.prod_shear (equiv.refl _) equiv.mul_left }
@[simp, to_additive]
lemma homeomorph.shear_mul_right_coe :
⇑(homeomorph.shear_mul_right G) = λ z : G × G, (z.1, z.1 * z.2) :=
rfl
@[simp, to_additive]
lemma homeomorph.shear_mul_right_symm_coe :
⇑(homeomorph.shear_mul_right G).symm = λ z : G × G, (z.1, z.1⁻¹ * z.2) :=
rfl
variable {G}
@[to_additive]
lemma inv_closure (s : set G) : (closure s)⁻¹ = closure s⁻¹ :=
(homeomorph.inv G).preimage_closure s
/-- The (topological-space) closure of a subgroup of a space `M` with `has_continuous_mul` is
itself a subgroup. -/
@[to_additive "The (topological-space) closure of an additive subgroup of a space `M` with
`has_continuous_add` is itself an additive subgroup."]
def subgroup.topological_closure (s : subgroup G) : subgroup G :=
{ carrier := closure (s : set G),
inv_mem' := λ g m, by simpa [←mem_inv, inv_closure] using m,
..s.to_submonoid.topological_closure }
@[to_additive]
instance subgroup.topological_closure_topological_group (s : subgroup G) :
topological_group (s.topological_closure) :=
{ continuous_inv :=
begin
apply continuous_induced_rng,
change continuous (λ p : s.topological_closure, (p : G)⁻¹),
continuity,
end
..s.to_submonoid.topological_closure_has_continuous_mul}
lemma subgroup.subgroup_topological_closure (s : subgroup G) :
s ≤ s.topological_closure :=
subset_closure
lemma subgroup.is_closed_topological_closure (s : subgroup G) :
is_closed (s.topological_closure : set G) :=
by convert is_closed_closure
lemma subgroup.topological_closure_minimal
(s : subgroup G) {t : subgroup G} (h : s ≤ t) (ht : is_closed (t : set G)) :
s.topological_closure ≤ t :=
closure_minimal h ht
@[to_additive exists_nhds_half_neg]
lemma exists_nhds_split_inv {s : set G} (hs : s ∈ 𝓝 (1 : G)) :
∃ V ∈ 𝓝 (1 : G), ∀ (v ∈ V) (w ∈ V), v / w ∈ s :=
have ((λp : G × G, p.1 * p.2⁻¹) ⁻¹' s) ∈ 𝓝 ((1, 1) : G × G),
from continuous_at_fst.mul continuous_at_snd.inv (by simpa),
by simpa only [div_eq_mul_inv, nhds_prod_eq, mem_prod_self_iff, prod_subset_iff, mem_preimage]
using this
@[to_additive]
lemma nhds_translation_mul_inv (x : G) : comap (λ y : G, y * x⁻¹) (𝓝 1) = 𝓝 x :=
((homeomorph.mul_right x⁻¹).comap_nhds_eq 1).trans $ show 𝓝 (1 * x⁻¹⁻¹) = 𝓝 x, by simp
@[simp, to_additive] lemma map_mul_left_nhds (x y : G) : map ((*) x) (𝓝 y) = 𝓝 (x * y) :=
(homeomorph.mul_left x).map_nhds_eq y
@[to_additive] lemma map_mul_left_nhds_one (x : G) : map ((*) x) (𝓝 1) = 𝓝 x := by simp
@[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]
@[to_additive]
lemma topological_group.of_nhds_aux {G : Type*} [group G] [topological_space G]
(hinv : tendsto (λ (x : G), x⁻¹) (𝓝 1) (𝓝 1))
(hleft : ∀ (x₀ : G), 𝓝 x₀ = map (λ (x : G), x₀ * x) (𝓝 1))
(hconj : ∀ (x₀ : G), map (λ (x : G), x₀ * x * x₀⁻¹) (𝓝 1) ≤ 𝓝 1) : continuous (λ x : G, x⁻¹) :=
begin
rw continuous_iff_continuous_at,
rintros x₀,
have key : (λ x, (x₀*x)⁻¹) = (λ x, x₀⁻¹*x) ∘ (λ x, x₀*x*x₀⁻¹) ∘ (λ x, x⁻¹),
by {ext ; simp[mul_assoc] },
calc map (λ x, x⁻¹) (𝓝 x₀)
= map (λ x, x⁻¹) (map (λ x, x₀*x) $ 𝓝 1) : by rw hleft
... = map (λ x, (x₀*x)⁻¹) (𝓝 1) : by rw filter.map_map
... = map (((λ x, x₀⁻¹*x) ∘ (λ x, x₀*x*x₀⁻¹)) ∘ (λ x, x⁻¹)) (𝓝 1) : by rw key
... = map ((λ x, x₀⁻¹*x) ∘ (λ x, x₀*x*x₀⁻¹)) _ : by rw ← filter.map_map
... ≤ map ((λ x, x₀⁻¹ * x) ∘ λ x, x₀ * x * x₀⁻¹) (𝓝 1) : map_mono hinv
... = map (λ x, x₀⁻¹ * x) (map (λ x, x₀ * x * x₀⁻¹) (𝓝 1)) : filter.map_map
... ≤ map (λ x, x₀⁻¹ * x) (𝓝 1) : map_mono (hconj x₀)
... = 𝓝 x₀⁻¹ : (hleft _).symm
end
@[to_additive]
lemma topological_group.of_nhds_one' {G : Type*} [group G] [topological_space G]
(hmul : tendsto (uncurry ((*) : G → G → G)) ((𝓝 1) ×ᶠ 𝓝 1) (𝓝 1))
(hinv : tendsto (λ x : G, x⁻¹) (𝓝 1) (𝓝 1))
(hleft : ∀ x₀ : G, 𝓝 x₀ = map (λ x, x₀*x) (𝓝 1))
(hright : ∀ x₀ : G, 𝓝 x₀ = map (λ x, x*x₀) (𝓝 1)) : topological_group G :=
begin
refine { continuous_mul := (has_continuous_mul.of_nhds_one hmul hleft hright).continuous_mul,
continuous_inv := topological_group.of_nhds_aux hinv hleft _ },
intros x₀,
suffices : map (λ (x : G), x₀ * x * x₀⁻¹) (𝓝 1) = 𝓝 1, by simp [this, le_refl],
rw [show (λ x, x₀ * x * x₀⁻¹) = (λ x, x₀ * x) ∘ λ x, x*x₀⁻¹, by {ext, simp [mul_assoc] },
← filter.map_map, ← hright, hleft x₀⁻¹, filter.map_map],
convert map_id,
ext,
simp
end
@[to_additive]
lemma topological_group.of_nhds_one {G : Type u} [group G] [topological_space G]
(hmul : tendsto (uncurry ((*) : G → G → G)) ((𝓝 1) ×ᶠ 𝓝 1) (𝓝 1))
(hinv : tendsto (λ x : G, x⁻¹) (𝓝 1) (𝓝 1))
(hleft : ∀ x₀ : G, 𝓝 x₀ = map (λ x, x₀*x) (𝓝 1))
(hconj : ∀ x₀ : G, tendsto (λ x, x₀*x*x₀⁻¹) (𝓝 1) (𝓝 1)) : topological_group G :=
{ continuous_mul := begin
rw continuous_iff_continuous_at,
rintros ⟨x₀, y₀⟩,
have key : (λ (p : G × G), x₀ * p.1 * (y₀ * p.2)) =
((λ x, x₀*y₀*x) ∘ (uncurry (*)) ∘ (prod.map (λ x, y₀⁻¹*x*y₀) id)),
by { ext, simp [uncurry, prod.map, mul_assoc] },
specialize hconj y₀⁻¹, rw inv_inv at hconj,
calc map (λ (p : G × G), p.1 * p.2) (𝓝 (x₀, y₀))
= map (λ (p : G × G), p.1 * p.2) ((𝓝 x₀) ×ᶠ 𝓝 y₀)
: by rw nhds_prod_eq
... = map (λ (p : G × G), x₀ * p.1 * (y₀ * p.2)) ((𝓝 1) ×ᶠ (𝓝 1))
: by rw [hleft x₀, hleft y₀, prod_map_map_eq, filter.map_map]
... = map (((λ x, x₀*y₀*x) ∘ (uncurry (*))) ∘ (prod.map (λ x, y₀⁻¹*x*y₀) id))((𝓝 1) ×ᶠ (𝓝 1))
: by rw key
... = map ((λ x, x₀*y₀*x) ∘ (uncurry (*))) ((map (λ x, y₀⁻¹*x*y₀) $ 𝓝 1) ×ᶠ (𝓝 1))
: by rw [← filter.map_map, ← prod_map_map_eq', map_id]
... ≤ map ((λ x, x₀*y₀*x) ∘ (uncurry (*))) ((𝓝 1) ×ᶠ (𝓝 1))
: map_mono (filter.prod_mono hconj $ le_refl _)
... = map (λ x, x₀*y₀*x) (map (uncurry (*)) ((𝓝 1) ×ᶠ (𝓝 1))) : by rw filter.map_map
... ≤ map (λ x, x₀*y₀*x) (𝓝 1) : map_mono hmul
... = 𝓝 (x₀*y₀) : (hleft _).symm
end,
continuous_inv := topological_group.of_nhds_aux hinv hleft hconj}
@[to_additive]
lemma topological_group.of_comm_of_nhds_one {G : Type*} [comm_group G] [topological_space G]
(hmul : tendsto (uncurry ((*) : G → G → G)) ((𝓝 1) ×ᶠ 𝓝 1) (𝓝 1))
(hinv : tendsto (λ x : G, x⁻¹) (𝓝 1) (𝓝 1))
(hleft : ∀ x₀ : G, 𝓝 x₀ = map (λ x, x₀*x) (𝓝 1)) : topological_group G :=
topological_group.of_nhds_one hmul hinv hleft (by simpa using tendsto_id)
end topological_group
section quotient_topological_group
variables [topological_space G] [group G] [topological_group G] (N : subgroup G) (n : N.normal)
@[to_additive]
instance {G : Type*} [group G] [topological_space G] (N : subgroup G) :
topological_space (quotient_group.quotient N) :=
quotient.topological_space
open quotient_group
@[to_additive]
lemma quotient_group.is_open_map_coe : is_open_map (coe : G → quotient N) :=
begin
intros s s_op,
change is_open ((coe : G → quotient N) ⁻¹' (coe '' s)),
rw quotient_group.preimage_image_coe N s,
exact is_open_Union (λ n, is_open_map_mul_right n s s_op)
end
@[to_additive]
instance topological_group_quotient [N.normal] : topological_group (quotient N) :=
{ continuous_mul := begin
have cont : continuous ((coe : G → quotient N) ∘ (λ (p : G × G), p.fst * p.snd)) :=
continuous_quot_mk.comp continuous_mul,
have quot : quotient_map (λ p : G × G, ((p.1:quotient N), (p.2:quotient N))),
{ apply is_open_map.to_quotient_map,
{ exact (quotient_group.is_open_map_coe N).prod (quotient_group.is_open_map_coe N) },
{ exact continuous_quot_mk.prod_map continuous_quot_mk },
{ exact (surjective_quot_mk _).prod_map (surjective_quot_mk _) } },
exact (quotient_map.continuous_iff quot).2 cont,
end,
continuous_inv := begin
have : continuous ((coe : G → quotient N) ∘ (λ (a : G), a⁻¹)) :=
continuous_quot_mk.comp continuous_inv,
convert continuous_quotient_lift _ this,
end }
attribute [instance] topological_add_group_quotient
end quotient_topological_group
/-- A typeclass saying that `λ p : G × G, p.1 - p.2` is a continuous function. This property
automatically holds for topological additive groups but it also holds, e.g., for `ℝ≥0`. -/
class has_continuous_sub (G : Type*) [topological_space G] [has_sub G] : Prop :=
(continuous_sub : continuous (λ p : G × G, p.1 - p.2))
@[priority 100] -- see Note [lower instance priority]
instance topological_add_group.to_has_continuous_sub [topological_space G] [add_group G]
[topological_add_group G] :
has_continuous_sub G :=
⟨by { simp only [sub_eq_add_neg], exact continuous_fst.add continuous_snd.neg }⟩
export has_continuous_sub (continuous_sub)
section has_continuous_sub
variables [topological_space G] [has_sub G] [has_continuous_sub G]
lemma filter.tendsto.sub {f g : α → G} {l : filter α} {a b : G} (hf : tendsto f l (𝓝 a))
(hg : tendsto g l (𝓝 b)) :
tendsto (λx, f x - g x) l (𝓝 (a - b)) :=
(continuous_sub.tendsto (a, b)).comp (hf.prod_mk_nhds hg)
variables [topological_space α] {f g : α → G} {s : set α} {x : α}
@[continuity] lemma continuous.sub (hf : continuous f) (hg : continuous g) :
continuous (λ x, f x - g x) :=
continuous_sub.comp (hf.prod_mk hg : _)
lemma continuous_within_at.sub (hf : continuous_within_at f s x) (hg : continuous_within_at g s x) :
continuous_within_at (λ x, f x - g x) s x :=
hf.sub hg
lemma continuous_on.sub (hf : continuous_on f s) (hg : continuous_on g s) :
continuous_on (λx, f x - g x) s :=
λ x hx, (hf x hx).sub (hg x hx)
end has_continuous_sub
lemma nhds_translation [topological_space G] [add_group G] [topological_add_group G] (x : G) :
comap (λy:G, y - x) (𝓝 0) = 𝓝 x :=
by simpa only [sub_eq_add_neg] using nhds_translation_add_neg x
/-- 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 (G : Type u) extends add_comm_group G :=
(Z [] : filter G)
(zero_Z : pure 0 ≤ Z)
(sub_Z : tendsto (λp:G×G, p.1 - p.2) (Z ×ᶠ Z) Z)
namespace add_group_with_zero_nhd
variables (G) [add_group_with_zero_nhd G]
local notation `Z` := add_group_with_zero_nhd.Z
@[priority 100] -- see Note [lower instance priority]
instance : topological_space G :=
topological_space.mk_of_nhds $ λa, map (λx, x + a) (Z G)
variables {G}
lemma neg_Z : tendsto (λa:G, - a) (Z G) (Z G) :=
have tendsto (λa, (0:G)) (Z G) (Z G),
by refine le_trans (assume h, _) zero_Z; simp [univ_mem_sets'] {contextual := tt},
have tendsto (λa:G, 0 - a) (Z G) (Z G), from
sub_Z.comp (tendsto.prod_mk this tendsto_id),
by simpa
lemma add_Z : tendsto (λp:G×G, p.1 + p.2) (Z G ×ᶠ Z G) (Z G) :=
suffices tendsto (λp:G×G, p.1 - -p.2) (Z G ×ᶠ Z G) (Z G),
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 G} (hs : s ∈ Z G) : ∃ V ∈ Z G, ∀ (v ∈ V) (w ∈ V), v + w ∈ s :=
begin
have : ((λa:G×G, a.1 + a.2) ⁻¹' s) ∈ Z G ×ᶠ Z G := 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 : G) : 𝓝 a = map (λx, x + a) (Z G) :=
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:G) ∈ t, by simpa using zero_Z ht,
begin
refine ⟨(λx:G, 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 G).sets_of_superset ht (assume x hxt, _),
simpa [add_assoc] using eqt _ hxt _ hb }
end)
lemma nhds_zero_eq_Z : 𝓝 0 = Z G := by simp [nhds_eq]; exact filter.map_id
@[priority 100] -- see Note [lower instance priority]
instance : has_continuous_add G :=
⟨ 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:G, (a + b) + x) ∘ (λp:G×G,p.1 + p.2)) (Z G ×ᶠ Z G)
(map (λx:G, (a + b) + x) (Z G)),
{ simpa [(∘), add_comm, add_left_comm] },
exact tendsto_map.comp add_Z
end ⟩
@[priority 100] -- see Note [lower instance priority]
instance : topological_add_group G :=
⟨continuous_iff_continuous_at.2 $ assume a,
begin
rw [continuous_at, nhds_eq, nhds_eq, tendsto_map'_iff],
suffices : tendsto ((λx:G, x - a) ∘ (λx:G, -x)) (Z G) (map (λx:G, x - a) (Z G)),
{ 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 G] [group G] [topological_group G]
@[to_additive]
lemma is_open.mul_left {s t : set G} : is_open t → is_open (s * t) := λ ht,
begin
have : ∀a, is_open ((λ (x : G), a * x) '' t) :=
assume a, is_open_map_mul_left a t 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 G} : is_open s → is_open (s * t) := λ hs,
begin
have : ∀a, is_open ((λ (x : G), 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 (G)
lemma topological_group.t1_space (h : @is_closed G _ {1}) : t1_space G :=
⟨assume x, by { convert is_closed_map_mul_right x _ h, simp }⟩
lemma topological_group.regular_space [t1_space G] : regular_space G :=
⟨assume s a hs ha,
let f := λ p : G × G, p.1 * (p.2)⁻¹ in
have hf : continuous f := continuous_fst.mul continuous_snd.inv,
-- 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 ((is_open_compl_iff.2 hs).preimage hf) a (1:G) (by simpa [f]) in
begin
use [s * t₂, ht₂.mul_left, λ x hx, ⟨x, 1, hx, one_mem_t₂, mul_one _⟩],
rw [nhds_within, inf_principal_eq_bot, 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 G] : t2_space G := regular_space.t2_space G
end
section
/-! Some results about an open set containing the product of two sets in a topological group. -/
variables [topological_space G] [group G] [topological_group G]
/-- 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 G} (hK : is_compact K) (hU : is_open U) (hKU : K ⊆ U) :
∃ V : set G, is_open V ∧ (1 : G) ∈ V ∧ K * V ⊆ U :=
begin
let W : G → set G := λ x, (λ y, x * y) ⁻¹' U,
have h1W : ∀ x, is_open (W x) := λ x, hU.preimage (continuous_mul_left x),
have h2W : ∀ x ∈ K, (1 : G) ∈ W x := λ x hx, by simp only [mem_preimage, mul_one, hKU hx],
choose V hV using λ x : K, exists_open_nhds_one_mul_subset (mem_nhds_sets (h1W x) (h2W x.1 x.2)),
let X : K → set G := λ x, (λ y, (x : G)⁻¹ * y) ⁻¹' (V x),
obtain ⟨t, ht⟩ : ∃ t : finset ↥K, K ⊆ ⋃ i ∈ t, X i,
{ refine hK.elim_finite_subcover X (λ x, (hV x).1.preimage (continuous_mul_left x⁻¹)) _,
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 : G)⁻¹ * 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 G} (hK : is_compact K)
(hV : (interior V).nonempty) : ∃ t : finset G, K ⊆ ⋃ g ∈ t, (λ h, g * h) ⁻¹' V :=
begin
obtain ⟨t, ht⟩ : ∃ t : finset G, K ⊆ ⋃ x ∈ t, interior (((*) x) ⁻¹' V),
{ refine hK.elim_finite_subcover (λ x, interior $ ((*) x) ⁻¹' V) (λ x, is_open_interior) _,
cases hV with g₀ hg₀,
refine λ g hg, mem_Union.2 ⟨g₀ * g⁻¹, _⟩,
refine preimage_interior_subset_interior_preimage (continuous_const.mul continuous_id) _,
rwa [mem_preimage, inv_mul_cancel_right] },
exact ⟨t, subset.trans ht $ bUnion_subset_bUnion_right $ λ g hg, interior_subset⟩
end
/-- Every locally compact separable topological group is σ-compact.
Note: this is not true if we drop the topological group hypothesis. -/
@[priority 100] instance separable_locally_compact_group.sigma_compact_space
[separable_space G] [locally_compact_space G] : sigma_compact_space G :=
begin
obtain ⟨L, hLc, hL1⟩ := exists_compact_mem_nhds (1 : G),
refine ⟨⟨λ n, (λ x, x * dense_seq G n) ⁻¹' L, _, _⟩⟩,
{ intro n, exact (homeomorph.mul_right _).compact_preimage.mpr hLc },
{ refine Union_eq_univ_iff.2 (λ x, _),
obtain ⟨_, ⟨n, rfl⟩, hn⟩ : (range (dense_seq G) ∩ (λ y, x * y) ⁻¹' L).nonempty,
{ rw [← (homeomorph.mul_left x).apply_symm_apply 1] at hL1,
exact (dense_range_dense_seq G).inter_nhds_nonempty
((homeomorph.mul_left x).continuous.continuous_at $ hL1) },
exact ⟨n, hn⟩ }
end
end
section
variables [topological_space G] [comm_group G] [topological_group G]
@[to_additive]
lemma nhds_mul (x y : G) : 𝓝 (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_one_split ht with ⟨V, V1, h⟩,
refine ⟨(λa, a * x⁻¹) ⁻¹' V, (λa, a * y⁻¹) ⁻¹' V,
⟨V, V1, subset.refl _⟩, ⟨V, V1, 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⁻¹) v_mem (w * y⁻¹) 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:G, 𝓝 x) := ⟨λ_ _, nhds_mul _ _⟩
end
end filter_mul
instance additive.topological_add_group {G} [h : topological_space G]
[group G] [topological_group G] : @topological_add_group (additive G) h _ :=
{ continuous_neg := @continuous_inv G _ _ _ }
instance multiplicative.topological_group {G} [h : topological_space G]
[add_group G] [topological_add_group G] : @topological_group (multiplicative G) h _ :=
{ continuous_inv := @continuous_neg G _ _ _ }
|
eaa3484573558a044038b337f339414f7dcceaa0
|
3dc4623269159d02a444fe898d33e8c7e7e9461b
|
/.github/workflows/geo/src/limits.lean
|
71655057cd726af1fd2375d86d40e4b343f810ec
|
[] |
no_license
|
Or7ando/lean
|
cc003e6c41048eae7c34aa6bada51c9e9add9e66
|
d41169cf4e416a0d42092fb6bdc14131cee9dd15
|
refs/heads/master
| 1,650,600,589,722
| 1,587,262,906,000
| 1,587,262,906,000
| 255,387,160
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 438
|
lean
|
import category_theory.limits.shapes
open category_theory category_theory.category category_theory.limits
universes u v
variables {C : Type u} [𝒞 : category.{v} C]
variables {J : Type v} [small_category J]
include 𝒞
@[simp] lemma limit.lift_self_id (F : J ⥤ C) [has_limit F] :
limit.lift F (limit.cone F) = 𝟙 (limit F) :=
begin
symmetry, refine is_limit.uniq _ _ _ _,
intro j, erw [id_comp _ (limit.π F j)], refl,
end
|
c4c83a4edfaf032a4751b48b758eaf04ea3e1789
|
01f6b345a06ece970e589d4bbc68ee8b9b2cf58a
|
/src/ring_seminorm.lean
|
bd8d44e7bdffc9406a97fba20954f473a9ae9e41
|
[] |
no_license
|
mariainesdff/norm_extensions_journal_submission
|
6077acb98a7200de4553e653d81d54fb5d2314c8
|
d396130660935464fbc683f9aaf37fff8a890baa
|
refs/heads/master
| 1,686,685,693,347
| 1,684,065,115,000
| 1,684,065,115,000
| 603,823,641
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 19,168
|
lean
|
/-
Copyright (c) 2023 María Inés de Frutos-Fernández. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: María Inés de Frutos-Fernández
-/
import analysis.normed.ring.seminorm
import analysis.seminorm
/-!
# Nonarchimedean ring seminorms and algebra norms
In this file, we define some properties of functions (power-multiplicative, extends,
nonarchimedean) which will be of special interest to us when applied to ring seminorms or
additive group seminorms.
We prove several properties of nonarchimedean functions.
We also define algebra norms and multiplicative algebra norms.
## Main Definitions
* `is_pow_mul` : `f : R → ℝ` is power-multiplicative if for all `r ∈ R` and all positive `n ∈ ℕ`,
`f (r ^ n) = (f r) ^ n`.
* `function_extends` : given an `α`-algebra `β`, a function `f : β → ℝ` extends a function
`g : α → ℝ` if `∀ x : α, f (algebra_map α β x) = g x`.
* `is_nonarchimedean`: a function `f : R → ℝ≥0` is nonarchimedean if it satisfies the strong
triangle inequality `f (r + s) ≤ max (f r) (f s)` for all `r s : R`.
* `algebra_norm` : an algebra norm on an `R`-algebra norm `S` is a ring norm on `S` compatible with
the action of `R`.
* `mul_algebra_norm` : amultiplicative algebra norm on an `R`-algebra norm `S` is a multiplicative
ring norm on `S` compatible with the action of `R`.
## Main Results
* `is_nonarchimedean_multiset_image_add` : given a nonarchimedean additive group seminorm `f` on
`α`, a function `g : β → α` and a multiset `s : multiset β`, we can always find `b : β`, belonging
to `s` if `s` is nonempty, such that `f (t.sum g) ≤ f (g b)` .
## Tags
norm, nonarchimedean, pow_mul, power-multiplicative, algebra norm
-/
set_option old_structure_cmd true
open metric
namespace nat
lemma one_div_cast_pos {n : ℕ} (hn : n ≠ 0) : 0 < 1/(n : ℝ) :=
begin
rw [one_div, inv_pos, cast_pos],
exact nat.pos_of_ne_zero hn,
end
lemma one_div_cast_nonneg (n : ℕ): 0 ≤ 1/(n : ℝ) :=
begin
by_cases hn : n = 0,
{ rw [hn, cast_zero, div_zero] },
{ refine le_of_lt (one_div_cast_pos hn), }
end
lemma one_div_cast_ne_zero {n : ℕ} (hn : n ≠ 0) : 1/(n : ℝ) ≠ 0 :=
ne_of_gt (one_div_cast_pos hn)
end nat
/-- A function `f : R → ℝ` is power-multiplicative if for all `r ∈ R` and all positive `n ∈ ℕ`,
`f (r ^ n) = (f r) ^ n`. -/
def is_pow_mul {R : Type*} [ring R] (f : R → ℝ) :=
∀ (a : R) {n : ℕ} (hn : 1 ≤ n), f (a^n) = (f a) ^ n
/-- Given an `α`-algebra `β`, a function `f : β → ℝ` extends a function `g : α → ℝ` if
`∀ x : α, f (algebra_map α β x) = g x`. -/
def function_extends {α : Type*} [comm_ring α] (g : α → ℝ) {β : Type*} [ring β] [algebra α β]
(f : β → ℝ) : Prop :=
∀ x : α, f (algebra_map α β x) = g x
/-- A function `f : R → ℝ≥0` is nonarchimedean if it satisfies the strong triangle inequality
`f (r + s) ≤ max (f r) (f s)` for all `r s : R`. -/
def is_nonarchimedean {R : Type*} [add_group R] (f : R → ℝ) : Prop :=
∀ r s, f (r + s) ≤ max (f r) (f s)
/-- A nonarchimedean function satisfies the triangle inequality. -/
lemma add_le_of_is_nonarchimedean {α : Type*} [add_comm_group α] {f : α → ℝ} (hf : ∀ x : α, 0 ≤ f x)
(hna : is_nonarchimedean f) (a b : α) : f (a + b) ≤ f a + f b :=
begin
apply le_trans (hna _ _),
rw [max_le_iff, le_add_iff_nonneg_right, le_add_iff_nonneg_left],
exact ⟨hf _, hf _⟩,
end
/-- If `f` is a nonarchimedean additive group seminorm on `α`, then for every `n : ℕ` and `a : α`,
we have `f (n • a) ≤ (f a)`. -/
lemma is_nonarchimedean_nsmul {F α : Type*} [add_comm_group α] [add_group_seminorm_class F α]
{f : F} (hna : is_nonarchimedean f) (n : ℕ) (a : α) : f (n • a) ≤ (f a) :=
begin
induction n with n hn,
{ rw [zero_smul, (map_zero _)], exact map_nonneg _ _ },
{ have : n.succ • a = (n + 1) • a := rfl,
rw [this, add_smul, one_smul],
exact le_trans (hna _ _) (max_le_iff.mpr ⟨hn, le_refl _⟩) }
end
/-- If `f` is a nonarchimedean additive group seminorm on `α`, then for every `n : ℕ` and `a : α`,
we have `f (n * a) ≤ (f a)`. -/
lemma is_nonarchimedean_nmul {F α : Type*} [ring α] [add_group_seminorm_class F α] {f : F}
(hna : is_nonarchimedean f) (n : ℕ) (a : α) : f (n * a) ≤ (f a) :=
begin
rw ← nsmul_eq_mul,
exact is_nonarchimedean_nsmul hna _ _,
end
/-- If `f` is a nonarchimedean additive group seminorm on `α` and `x y : α` are such that
`f y ≠ f x`, then `f (x + y) = max (f x) (f y)`. -/
lemma is_nonarchimedean_add_eq_max_of_ne {F α : Type*} [ring α] [add_group_seminorm_class F α]
{f : F} (hna : is_nonarchimedean f) {x y : α} (hne : f y ≠ f x) :
f (x + y) = max (f x) (f y) :=
begin
wlog hle := le_total (f y) (f x) using [x y],
have hlt : f y < f x, from lt_of_le_of_ne hle hne,
have : f x ≤ max (f (x + y)) (f y), from calc
f x = f (x + y + (-y)) : by rw [add_neg_cancel_right]
... ≤ max (f (x + y)) (f (-y)) : hna _ _
... = max (f (x + y)) (f y) : by rw map_neg_eq_map f y,
have hnge : f y ≤ f (x + y),
{ apply le_of_not_gt,
intro hgt,
rw max_eq_right_of_lt hgt at this,
apply not_lt_of_ge this,
assumption },
have : f x ≤ f (x + y), by rwa [max_eq_left hnge] at this,
apply le_antisymm,
{ exact hna _ _ },
{ rw max_eq_left_of_lt hlt,
assumption },
rw [add_comm, max_comm], exact this (ne.symm hne),
end
open_locale classical
/-- Given a nonarchimedean additive group seminorm `f` on `α`, a function `g : β → α` and a finset
`t : finset β`, we can always find `b : β`, belonging to `t` if `t` is nonempty, such that
`f (t.sum g) ≤ f (g b)` . -/
lemma is_nonarchimedean_finset_image_add {F α : Type*} [ring α] [add_group_seminorm_class F α]
{f : F} (hna : is_nonarchimedean f) {β : Type*} [hβ : nonempty β] (g : β → α) (t : finset β) :
∃ (b : β) (hb : t.nonempty → b ∈ t), f (t.sum g) ≤ f (g b) :=
begin
apply finset.induction_on t,
{ rw [finset.sum_empty],
refine ⟨hβ.some, by simp only [finset.not_nonempty_empty, is_empty.forall_iff], _⟩,
rw map_zero f, exact map_nonneg f _ },
{ rintros a s has ⟨M, hMs, hM⟩,
rw [finset.sum_insert has],
by_cases hMa : f (g M) ≤ f (g a),
{ refine ⟨a, _, le_trans (hna _ _) (max_le_iff.mpr (⟨le_refl _,le_trans hM hMa⟩))⟩,
simp only [finset.nonempty_coe_sort, finset.insert_nonempty, finset.mem_insert,
eq_self_iff_true, true_or, forall_true_left] },
{ rw not_le at hMa,
by_cases hs : s.nonempty,
{ refine ⟨M, _, le_trans (hna _ _)
(max_le_iff.mpr ⟨le_of_lt hMa, hM⟩)⟩,
simp only [finset.nonempty_coe_sort, finset.insert_nonempty, finset.mem_insert,
forall_true_left],
exact or.intro_right _ (hMs hs) },
{ use a,
split,
{ simp only [finset.insert_nonempty, finset.mem_insert, eq_self_iff_true, true_or,
forall_true_left] },
have h0 : f (s.sum g) = 0,
{ rw [finset.not_nonempty_iff_eq_empty.mp hs, finset.sum_empty, map_zero] },
apply le_trans (hna _ _),
rw h0,
exact max_le_iff.mpr ⟨le_refl _, map_nonneg _ _⟩ }}}
end
/-- Given a nonarchimedean additive group seminorm `f` on `α`, a function `g : β → α` and a
multiset `s : multiset β`, we can always find `b : β`, belonging to `s` if `s` is nonempty,
such that `f (t.sum g) ≤ f (g b)` . -/
lemma is_nonarchimedean_multiset_image_add {F α : Type*} [ring α] [add_group_seminorm_class F α]
{f : F} (hna : is_nonarchimedean f) {β : Type*} [hβ : nonempty β] (g : β → α) (s : multiset β) :
∃ (b : β) (hb : 0 < s.card → b ∈ s), f ((multiset.map g s).sum) ≤ f (g b) :=
begin
apply multiset.induction_on s,
{ rw [multiset.map_zero, multiset.sum_zero, multiset.card_zero, map_zero f],
refine ⟨hβ.some, by simp only [not_lt_zero', is_empty.forall_iff], map_nonneg _ _⟩ },
{ rintros a t ⟨M, hMs, hM⟩,
by_cases hMa : f (g M) ≤ f (g a),
{ refine ⟨a, _, _⟩,
{ simp only [multiset.card_cons, nat.succ_pos', multiset.mem_cons_self, forall_true_left] },
{ rw [multiset.map_cons, multiset.sum_cons],
exact le_trans (hna _ _) (max_le_iff.mpr (⟨le_refl _,le_trans hM hMa⟩)), }},
{ rw not_le at hMa,
by_cases ht : 0 < t.card,
{ refine ⟨M, _, _⟩,
{ simp only [multiset.card_cons, nat.succ_pos', multiset.mem_cons, forall_true_left],
exact or.intro_right _ (hMs ht) },
rw [multiset.map_cons, multiset.sum_cons],
exact le_trans (hna _ _) (max_le_iff.mpr ⟨le_of_lt hMa, hM⟩) },
{ refine ⟨a, _, _⟩,
{ simp only [multiset.card_cons, nat.succ_pos', multiset.mem_cons_self, forall_true_left] },
{ have h0 : f (multiset.map g t).sum = 0,
{ simp only [not_lt, le_zero_iff, multiset.card_eq_zero] at ht,
rw [ht, multiset.map_zero, multiset.sum_zero, map_zero f] },
rw [multiset.map_cons, multiset.sum_cons],
apply le_trans (hna _ _),
rw h0,
exact max_le_iff.mpr ⟨le_refl _, map_nonneg _ _⟩ }}}}
end
/-- Given a nonarchimedean additive group seminorm `f` on `α`, a number `n : ℕ` and a function
`g : ℕ → α`, there exists `m : ℕ` such that `f ((finset.range n).sum g) ≤ f (g m)`.
If `0 < n`, this `m` satisfies `m < n`. -/
lemma is_nonarchimedean_finset_range_add_le {F α : Type*} [ring α] [add_group_seminorm_class F α]
{f : F} (hna : is_nonarchimedean f) (n : ℕ) (g : ℕ → α) : ∃ (m : ℕ) (hm : 0 < n → m < n),
f ((finset.range n).sum g) ≤ f (g m) :=
begin
obtain ⟨m, hm, h⟩ := is_nonarchimedean_finset_image_add hna g (finset.range n),
rw [finset.nonempty_range_iff, ← zero_lt_iff, finset.mem_range] at hm,
exact ⟨m, hm, h⟩,
end
/-- If `f` is a nonarchimedean additive group seminorm on a commutative ring `α`, `n : ℕ`, and
`a b : α`, then we can find `m : ℕ` such that `m ≤ n` and
`f ((a + b) ^ n) ≤ (f (a ^ m)) * (f (b ^ (n - m)))`. -/
lemma is_nonarchimedean_add_pow {F α : Type*} [comm_ring α] [ring_seminorm_class F α] {f : F}
(hna : is_nonarchimedean f) (n : ℕ) (a b : α) :
∃ (m : ℕ) (hm : m ∈ list.range(n + 1)), f ((a + b) ^ n) ≤ (f (a ^ m)) * (f (b ^ (n - m))) :=
begin
obtain ⟨m, hm_lt, hM⟩ := is_nonarchimedean_finset_image_add hna
(λ (m : ℕ), a ^ m * b ^ (n - m) * ↑(n.choose m)) (finset.range (n + 1)),
simp only [finset.nonempty_range_iff, ne.def, nat.succ_ne_zero, not_false_iff, finset.mem_range,
if_true, forall_true_left] at hm_lt,
refine ⟨m, list.mem_range.mpr hm_lt, _⟩,
simp only [← add_pow] at hM,
rw mul_comm at hM,
exact le_trans hM (le_trans (is_nonarchimedean_nmul hna _ _) (map_mul_le_mul _ _ _)),
end
/-- If `f` is a ring seminorm on `a`, then `∀ {n : ℕ}, n ≠ 0 → f (a ^ n) ≤ f a ^ n`. -/
lemma map_pow_le_pow {F α : Type*} [ring α] [ring_seminorm_class F α] (f : F) (a : α) :
∀ {n : ℕ}, n ≠ 0 → f (a ^ n) ≤ f a ^ n
| 0 h := absurd rfl h
| 1 h := by simp only [pow_one]
| (n + 2) h := by simp only [pow_succ _ (n + 1)]; exact le_trans (map_mul_le_mul f a _)
(mul_le_mul_of_nonneg_left (map_pow_le_pow n.succ_ne_zero) (map_nonneg f a))
/-- If `f` is a ring seminorm on `a` with `f 1 ≤ `, then `∀ (n : ℕ), f (a ^ n) ≤ f a ^ n`. -/
lemma map_pow_le_pow' {F α : Type*} [ring α] [ring_seminorm_class F α] {f : F} (hf1 : f 1 ≤ 1)
(a : α) : ∀ (n : ℕ), f (a ^ n) ≤ f a ^ n
| 0 := by simp only [pow_zero, hf1]
| (n + 1) := by simp only [pow_succ _ n]; exact le_trans (map_mul_le_mul f a _)
(mul_le_mul_of_nonneg_left (map_pow_le_pow' n) (map_nonneg f a))
/-- An algebra norm on an `R`-algebra norm `S` is a ring norm on `S` compatible with the
action of `R`. -/
structure algebra_norm (R : Type*) [semi_normed_comm_ring R] (S : Type*) [ring S]
[algebra R S] extends seminorm R S, ring_norm S
attribute [nolint doc_blame] algebra_norm.to_seminorm algebra_norm.to_ring_norm
instance (K : Type*) [normed_field K] : inhabited (algebra_norm K K) :=
⟨{ to_fun := norm,
map_zero' := norm_zero,
add_le' := norm_add_le,
neg' := norm_neg,
smul' := norm_mul,
mul_le' := norm_mul_le,
eq_zero_of_map_eq_zero' := λ x, norm_eq_zero.mp}⟩
/-- `algebra_norm_class F α` states that `F` is a type of algebra norms on the ring `β`.
You should extend this class when you extend `algebra_norm`. -/
class algebra_norm_class (F : Type*) (R : out_param $ Type*) [semi_normed_comm_ring R]
(S : out_param $ Type*) [ring S] [algebra R S]
extends seminorm_class F R S, ring_norm_class F S
-- `R` is an `out_param`, so this is a false positive.
attribute [nolint dangerous_instance] algebra_norm_class.to_ring_norm_class
namespace algebra_norm
variables {R : Type*} [semi_normed_comm_ring R] {S : Type*} [ring S] [algebra R S]
{f : algebra_norm R S}
/-- The ring_seminorm underlying an algebra norm. -/
def to_ring_seminorm (f : algebra_norm R S) : ring_seminorm S :=
f.to_ring_norm.to_ring_seminorm
instance algebra_norm_class : algebra_norm_class (algebra_norm R S) R S :=
{ coe := λ f, f.to_fun,
coe_injective' := λ f f' h,
begin
simp only [ring_norm.to_fun_eq_coe, fun_like.coe_fn_eq] at h,
cases f; cases f'; congr',
end,
map_zero := λ f, f.map_zero',
map_add_le_add := λ f, f.add_le',
map_mul_le_mul := λ f, f.mul_le',
map_neg_eq_map := λ f, f.neg',
eq_zero_of_map_eq_zero := λ f, f.eq_zero_of_map_eq_zero',
map_smul_eq_mul := λ f, f.smul' }
/-- Helper instance for when there's too many metavariables to apply `fun_like.has_coe_to_fun`. -/
instance : has_coe_to_fun (algebra_norm R S) (λ _, S → ℝ) := fun_like.has_coe_to_fun
@[simp] lemma to_fun_eq_coe (p : algebra_norm R S) : p.to_fun = p := rfl
@[ext] lemma ext {p q : algebra_norm R S} : (∀ x, p x = q x) → p = q := fun_like.ext p q
/-- An `R`-algebra norm such that `f 1 = 1` extends the norm on `R`. -/
lemma extends_norm' {f : algebra_norm R S} (hf1 : f 1 = 1) (a : R) : f (a • 1) = ‖ a ‖ :=
by rw [← mul_one ‖ a ‖ , ← hf1]; exact f.smul' _ _
/-- An `R`-algebra norm such that `f 1 = 1` extends the norm on `R`. -/
lemma extends_norm {f : algebra_norm R S} (hf1 : f 1 = 1) (a : R) :
f (algebra_map R S a) = ‖ a ‖ :=
by rw algebra.algebra_map_eq_smul_one; exact extends_norm' hf1 _
end algebra_norm
/-- A multiplicative algebra norm on an `R`-algebra norm `S` is a multiplicative ring norm on `S`
compatible with the action of `R`. -/
structure mul_algebra_norm (R : Type*) [semi_normed_comm_ring R] (S : Type*) [ring S]
[algebra R S] extends seminorm R S, mul_ring_norm S
attribute [nolint doc_blame] mul_algebra_norm.to_seminorm mul_algebra_norm.to_mul_ring_norm
instance (K : Type*) [normed_field K] : inhabited (mul_algebra_norm K K) :=
⟨{ to_fun := norm,
map_zero' := norm_zero,
add_le' := norm_add_le,
neg' := norm_neg,
smul' := norm_mul,
map_one' := norm_one,
map_mul' := norm_mul,
eq_zero_of_map_eq_zero' := λ x, norm_eq_zero.mp}⟩
/-- `algebra_norm_class F α` states that `F` is a type of algebra norms on the ring `β`.
You should extend this class when you extend `algebra_norm`. -/
class mul_algebra_norm_class (F : Type*) (R : out_param $ Type*) [semi_normed_comm_ring R]
(S : out_param $ Type*) [ring S] [algebra R S]
extends seminorm_class F R S, mul_ring_norm_class F S
-- `R` is an `out_param`, so this is a false positive.
attribute [nolint dangerous_instance] mul_algebra_norm_class.to_mul_ring_norm_class
namespace mul_algebra_norm
variables {R S : out_param $ Type*} [semi_normed_comm_ring R] [ring S] [algebra R S]
{f : algebra_norm R S}
instance mul_algebra_norm_class : mul_algebra_norm_class (mul_algebra_norm R S) R S :=
{ coe := λ f, f.to_fun,
coe_injective' := λ f f' h,
begin
simp only [ring_norm.to_fun_eq_coe, fun_like.coe_fn_eq] at h,
cases f; cases f'; congr',
end,
map_zero := λ f, f.map_zero',
map_add_le_add := λ f, f.add_le',
map_one := λ f, f.map_one',
map_mul := λ f, f.map_mul',
map_neg_eq_map := λ f, f.neg',
eq_zero_of_map_eq_zero := λ f, f.eq_zero_of_map_eq_zero',
map_smul_eq_mul := λ f, f.smul' }
/-- Helper instance for when there's too many metavariables to apply `fun_like.has_coe_to_fun`. -/
instance : has_coe_to_fun (mul_algebra_norm R S) (λ _, S → ℝ) := fun_like.has_coe_to_fun
@[simp] lemma to_fun_eq_coe (p : mul_algebra_norm R S) : p.to_fun = p := rfl
@[ext] lemma ext {p q : mul_algebra_norm R S} : (∀ x, p x = q x) → p = q := fun_like.ext p q
/-- A multiplicative `R`-algebra norm extends the norm on `R`. -/
lemma extends_norm' (f : mul_algebra_norm R S) (a : R) : f (a • 1) = ‖ a ‖ :=
by rw [← mul_one ‖ a ‖, ← f.map_one', ← f.smul']; refl
/-- A multiplicative `R`-algebra norm extends the norm on `R`. -/
lemma extends_norm (f : mul_algebra_norm R S) (a : R) :
f (algebra_map R S a) = ‖ a ‖ :=
by rw algebra.algebra_map_eq_smul_one; exact extends_norm' _ _
end mul_algebra_norm
namespace mul_ring_norm
variables {R : Type*} [non_assoc_ring R]
/-- The ring norm underlying a multiplicative ring norm. -/
def to_ring_norm (f : mul_ring_norm R) : ring_norm R :=
{ to_fun := f,
map_zero' := f.map_zero',
add_le' := f.add_le',
neg' := f.neg',
mul_le' := λ x y, le_of_eq (f.map_mul' x y),
eq_zero_of_map_eq_zero' := f.eq_zero_of_map_eq_zero' }
/-- A multiplicative ring norm is power-multiplicative. -/
lemma is_pow_mul {A : Type*} [ring A] (f : mul_ring_norm A) : is_pow_mul f := λ x n hn,
begin
induction n with n ih,
{ exfalso, linarith },
{ by_cases hn1 : 1 ≤ n,
{ rw [pow_succ, pow_succ, map_mul, ih hn1] },
{ rw [not_le, nat.lt_one_iff] at hn1,
rw [hn1, pow_one, pow_one], }}
end
end mul_ring_norm
/-- The seminorm on a `semi_normed_ring`, as a `ring_seminorm`. -/
def seminormed_ring.to_ring_seminorm (R : Type*) [semi_normed_ring R] :
ring_seminorm R :=
{ to_fun := norm,
map_zero' := norm_zero,
add_le' := norm_add_le,
mul_le' := norm_mul_le,
neg' := norm_neg, }
/-- The norm on a `normed_ring`, as a `ring_norm`. -/
@[simps] def normed_ring.to_ring_norm (R : Type*) [normed_ring R] :
ring_norm R :=
{ to_fun := norm,
map_zero' := norm_zero,
add_le' := norm_add_le,
mul_le' := norm_mul_le,
neg' := norm_neg,
eq_zero_of_map_eq_zero' := λ x hx, by { rw ← norm_eq_zero, exact hx }}
@[simp] lemma normed_ring.to_ring_norm_apply (R : Type*) [normed_ring R] (x : R):
(normed_ring.to_ring_norm R) x = ‖ x ‖ := rfl
/-- The norm on a `normed_field`, as a `mul_ring_norm`. -/
def normed_field.to_mul_ring_norm (R : Type*) [normed_field R] :
mul_ring_norm R :=
{ to_fun := norm,
map_zero' := norm_zero,
map_one' := norm_one,
add_le' := norm_add_le,
map_mul' := norm_mul,
neg' := norm_neg,
eq_zero_of_map_eq_zero' := λ x hx, by { rw ← norm_eq_zero, exact hx }}
|
58f1ef33b3502d38de22d1dd427f2bb09aa34f94
|
07c6143268cfb72beccd1cc35735d424ebcb187b
|
/src/data/zmod/basic.lean
|
643904952168dfc6c6d6f751239f41383179b359
|
[
"Apache-2.0"
] |
permissive
|
khoek/mathlib
|
bc49a842910af13a3c372748310e86467d1dc766
|
aa55f8b50354b3e11ba64792dcb06cccb2d8ee28
|
refs/heads/master
| 1,588,232,063,837
| 1,587,304,803,000
| 1,587,304,803,000
| 176,688,517
| 0
| 0
|
Apache-2.0
| 1,553,070,585,000
| 1,553,070,585,000
| null |
UTF-8
|
Lean
| false
| false
| 21,640
|
lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Chris Hughes
-/
import data.int.modeq data.int.gcd data.fintype.basic data.pnat.basic tactic.ring
/-!
# Integers mod `n`
Definition of the integers mod n, and the field structure on the integers mod p.
There are two types defined, `zmod n`, which is for integers modulo a positive nat `n : ℕ+`.
`zmodp` is the type of integers modulo a prime number, for which a field structure is defined.
## Definitions
* `val` is inherited from `fin` and returns the least natural number in the equivalence class
* `val_min_abs` returns the integer closest to zero in the equivalence class.
* A coercion `cast` is defined from `zmod n` into any semiring. This is a semiring hom if the ring has
characteristic dividing `n`
## Implementation notes
`zmod` and `zmodp` are implemented as different types so that the field instance for `zmodp` can be
synthesized. This leads to a lot of code duplication and most of the functions and theorems for
`zmod` are restated for `zmodp`
-/
open nat nat.modeq int
def zmod (n : ℕ+) := fin n
namespace zmod
instance (n : ℕ+) : has_neg (zmod n) :=
⟨λ a, ⟨nat_mod (-(a.1 : ℤ)) n,
have h : (n : ℤ) ≠ 0 := int.coe_nat_ne_zero_iff_pos.2 n.pos,
have h₁ : ((n : ℕ) : ℤ) = abs n := (abs_of_nonneg (int.coe_nat_nonneg n)).symm,
by rw [← int.coe_nat_lt, nat_mod, to_nat_of_nonneg (int.mod_nonneg _ h), h₁];
exact int.mod_lt _ h⟩⟩
instance (n : ℕ+) : add_comm_semigroup (zmod n) :=
{ add_assoc := λ ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩, fin.eq_of_veq
(show ((a + b) % n + c) ≡ (a + (b + c) % n) [MOD n],
from calc ((a + b) % n + c) ≡ a + b + c [MOD n] : modeq_add (nat.mod_mod _ _) rfl
... ≡ a + (b + c) [MOD n] : by rw add_assoc
... ≡ (a + (b + c) % n) [MOD n] : modeq_add rfl (nat.mod_mod _ _).symm),
add_comm := λ ⟨a, _⟩ ⟨b, _⟩, fin.eq_of_veq (show (a + b) % n = (b + a) % n, by rw add_comm),
..fin.has_add }
instance (n : ℕ+) : comm_semigroup (zmod n) :=
{ mul_assoc := λ ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩, fin.eq_of_veq
(calc ((a * b) % n * c) ≡ a * b * c [MOD n] : modeq_mul (nat.mod_mod _ _) rfl
... ≡ a * (b * c) [MOD n] : by rw mul_assoc
... ≡ a * (b * c % n) [MOD n] : modeq_mul rfl (nat.mod_mod _ _).symm),
mul_comm := λ ⟨a, _⟩ ⟨b, _⟩, fin.eq_of_veq (show (a * b) % n = (b * a) % n, by rw mul_comm),
..fin.has_mul }
instance (n : ℕ+) : has_one (zmod n) := ⟨⟨(1 % n), nat.mod_lt _ n.pos⟩⟩
instance (n : ℕ+) : has_zero (zmod n) := ⟨⟨0, n.pos⟩⟩
instance (n : ℕ+) : inhabited (zmod n) := ⟨0⟩
instance zmod_one.subsingleton : subsingleton (zmod 1) :=
⟨λ a b, fin.eq_of_veq (by rw [eq_zero_of_le_zero (le_of_lt_succ a.2),
eq_zero_of_le_zero (le_of_lt_succ b.2)])⟩
lemma add_val {n : ℕ+} : ∀ a b : zmod n, (a + b).val = (a.val + b.val) % n
| ⟨_, _⟩ ⟨_, _⟩ := rfl
lemma mul_val {n : ℕ+} : ∀ a b : zmod n, (a * b).val = (a.val * b.val) % n
| ⟨_, _⟩ ⟨_, _⟩ := rfl
lemma one_val {n : ℕ+} : (1 : zmod n).val = 1 % n := rfl
@[simp] lemma zero_val (n : ℕ+) : (0 : zmod n).val = 0 := rfl
private lemma one_mul_aux (n : ℕ+) (a : zmod n) : (1 : zmod n) * a = a :=
begin
cases n with n hn,
cases n with n,
{ exact (lt_irrefl _ hn).elim },
{ cases n with n,
{ exact @subsingleton.elim (zmod 1) _ _ _ },
{ have h₁ : a.1 % n.succ.succ = a.1 := nat.mod_eq_of_lt a.2,
have h₂ : 1 % n.succ.succ = 1 := nat.mod_eq_of_lt dec_trivial,
refine fin.eq_of_veq _,
simp [mul_val, one_val, h₁, h₂] } }
end
private lemma left_distrib_aux (n : ℕ+) : ∀ a b c : zmod n, a * (b + c) = a * b + a * c :=
λ ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩, fin.eq_of_veq
(calc a * ((b + c) % n) ≡ a * (b + c) [MOD n] : modeq_mul rfl (nat.mod_mod _ _)
... ≡ a * b + a * c [MOD n] : by rw mul_add
... ≡ (a * b) % n + (a * c) % n [MOD n] : modeq_add (nat.mod_mod _ _).symm (nat.mod_mod _ _).symm)
instance (n : ℕ+) : comm_ring (zmod n) :=
{ zero_add := λ ⟨a, ha⟩, fin.eq_of_veq (show (0 + a) % n = a, by rw zero_add; exact nat.mod_eq_of_lt ha),
add_zero := λ ⟨a, ha⟩, fin.eq_of_veq (nat.mod_eq_of_lt ha),
add_left_neg :=
λ ⟨a, ha⟩, fin.eq_of_veq (show (((-a : ℤ) % n).to_nat + a) % n = 0,
from int.coe_nat_inj
begin
have hn : (n : ℤ) ≠ 0 := (ne_of_lt (int.coe_nat_lt.2 n.pos)).symm,
rw [int.coe_nat_mod, int.coe_nat_add, to_nat_of_nonneg (int.mod_nonneg _ hn), add_comm],
simp,
end),
one_mul := one_mul_aux n,
mul_one := λ a, by rw mul_comm; exact one_mul_aux n a,
left_distrib := left_distrib_aux n,
right_distrib := λ a b c, by rw [mul_comm, left_distrib_aux, mul_comm _ b, mul_comm]; refl,
..zmod.has_zero n,
..zmod.has_one n,
..zmod.has_neg n,
..zmod.add_comm_semigroup n,
..zmod.comm_semigroup n }
lemma val_cast_nat {n : ℕ+} (a : ℕ) : (a : zmod n).val = a % n :=
begin
induction a with a ih,
{ rw [nat.zero_mod]; refl },
{ rw [succ_eq_add_one, nat.cast_add, add_val, ih],
show (a % n + ((0 + (1 % n)) % n)) % n = (a + 1) % n,
rw [zero_add, nat.mod_mod],
exact nat.modeq.modeq_add (nat.mod_mod a n) (nat.mod_mod 1 n) }
end
lemma neg_val' {m : pnat} (n : zmod m) : (-n).val = (m - n.val) % m :=
have ((-n).val + n.val) % m = (m - n.val + n.val) % m,
by { rw [←add_val, add_left_neg, nat.sub_add_cancel (le_of_lt n.is_lt), nat.mod_self], refl },
(nat.mod_eq_of_lt (fin.is_lt _)).symm.trans (nat.modeq.modeq_add_cancel_right rfl this)
lemma neg_val {m : pnat} (n : zmod m) : (-n).val = if n = 0 then 0 else m - n.val :=
begin
rw neg_val',
by_cases h : n = 0; simp [h],
cases n with n nlt; cases n; dsimp, { contradiction },
rw nat.mod_eq_of_lt,
apply nat.sub_lt m.2 (nat.succ_pos _),
end
lemma mk_eq_cast {n : ℕ+} {a : ℕ} (h : a < n) : (⟨a, h⟩ : zmod n) = (a : zmod n) :=
fin.eq_of_veq (by rw [val_cast_nat, nat.mod_eq_of_lt h])
@[simp] lemma cast_self_eq_zero {n : ℕ+} : ((n : ℕ) : zmod n) = 0 :=
fin.eq_of_veq (show (n : zmod n).val = 0, by simp [val_cast_nat])
lemma val_cast_of_lt {n : ℕ+} {a : ℕ} (h : a < n) : (a : zmod n).val = a :=
by rw [val_cast_nat, nat.mod_eq_of_lt h]
@[simp] lemma cast_mod_nat (n : ℕ+) (a : ℕ) : ((a % n : ℕ) : zmod n) = a :=
by conv {to_rhs, rw ← nat.mod_add_div a n}; simp
@[simp, priority 980]
lemma cast_mod_nat' {n : ℕ} (hn : 0 < n) (a : ℕ) : ((a % n : ℕ) : zmod ⟨n, hn⟩) = a :=
cast_mod_nat ⟨n, hn⟩ a
@[simp] lemma cast_val {n : ℕ+} (a : zmod n) : (a.val : zmod n) = a :=
by cases a; simp [mk_eq_cast]
@[simp] lemma cast_mod_int (n : ℕ+) (a : ℤ) : ((a % (n : ℕ) : ℤ) : zmod n) = a :=
by conv {to_rhs, rw ← int.mod_add_div a n}; simp
@[simp, priority 980]
lemma cast_mod_int' {n : ℕ} (hn : 0 < n) (a : ℤ) :
((a % (n : ℕ) : ℤ) : zmod ⟨n, hn⟩) = a := cast_mod_int ⟨n, hn⟩ a
lemma val_cast_int {n : ℕ+} (a : ℤ) : (a : zmod n).val = (a % (n : ℕ)).nat_abs :=
have h : nat_abs (a % (n : ℕ)) < n := int.coe_nat_lt.1 begin
rw [nat_abs_of_nonneg (mod_nonneg _ (int.coe_nat_ne_zero_iff_pos.2 n.pos))],
conv {to_rhs, rw ← abs_of_nonneg (int.coe_nat_nonneg n)},
exact int.mod_lt _ (int.coe_nat_ne_zero_iff_pos.2 n.pos)
end,
int.coe_nat_inj $
by conv {to_lhs, rw [← cast_mod_int n a,
← nat_abs_of_nonneg (mod_nonneg _ (int.coe_nat_ne_zero_iff_pos.2 n.pos)),
int.cast_coe_nat, val_cast_of_lt h] }
lemma coe_val_cast_int {n : ℕ+} (a : ℤ) : ((a : zmod n).val : ℤ) = a % (n : ℕ) :=
by rw [val_cast_int, int.nat_abs_of_nonneg (mod_nonneg _ (int.coe_nat_ne_zero_iff_pos.2 n.pos))]
lemma eq_iff_modeq_nat {n : ℕ+} {a b : ℕ} : (a : zmod n) = b ↔ a ≡ b [MOD n] :=
⟨λ h, by have := fin.veq_of_eq h;
rwa [val_cast_nat, val_cast_nat] at this,
λ h, fin.eq_of_veq $ by rwa [val_cast_nat, val_cast_nat]⟩
lemma eq_iff_modeq_nat' {n : ℕ} (hn : 0 < n) {a b : ℕ} : (a : zmod ⟨n, hn⟩) = b ↔ a ≡ b [MOD n] :=
eq_iff_modeq_nat
lemma eq_iff_modeq_int {n : ℕ+} {a b : ℤ} : (a : zmod n) = b ↔ a ≡ b [ZMOD (n : ℕ)] :=
⟨λ h, by have := fin.veq_of_eq h;
rwa [val_cast_int, val_cast_int, ← int.coe_nat_eq_coe_nat_iff,
nat_abs_of_nonneg (int.mod_nonneg _ (int.coe_nat_ne_zero_iff_pos.2 n.pos)),
nat_abs_of_nonneg (int.mod_nonneg _ (int.coe_nat_ne_zero_iff_pos.2 n.pos))] at this,
λ h : a % (n : ℕ) = b % (n : ℕ),
by rw [← cast_mod_int n a, ← cast_mod_int n b, h]⟩
lemma eq_iff_modeq_int' {n : ℕ} (hn : 0 < n) {a b : ℤ} :
(a : zmod ⟨n, hn⟩) = b ↔ a ≡ b [ZMOD (n : ℕ)] := eq_iff_modeq_int
lemma eq_zero_iff_dvd_nat {n : ℕ+} {a : ℕ} : (a : zmod n) = 0 ↔ (n : ℕ) ∣ a :=
by rw [← @nat.cast_zero (zmod n), eq_iff_modeq_nat, nat.modeq.modeq_zero_iff]
lemma eq_zero_iff_dvd_int {n : ℕ+} {a : ℤ} : (a : zmod n) = 0 ↔ ((n : ℕ) : ℤ) ∣ a :=
by rw [← @int.cast_zero (zmod n), eq_iff_modeq_int, int.modeq.modeq_zero_iff]
instance (n : ℕ+) : fintype (zmod n) := fin.fintype _
instance decidable_eq (n : ℕ+) : decidable_eq (zmod n) := fin.decidable_eq _
instance (n : ℕ+) : has_repr (zmod n) := fin.has_repr _
lemma card_zmod (n : ℕ+) : fintype.card (zmod n) = n := fintype.card_fin n
instance : subsingleton (units (zmod 2)) :=
⟨λ x y, begin
cases x with x xi,
cases y with y yi,
revert x y xi yi,
exact dec_trivial
end⟩
lemma le_div_two_iff_lt_neg {n : ℕ+} (hn : (n : ℕ) % 2 = 1)
{x : zmod n} (hx0 : x ≠ 0) : x.1 ≤ (n / 2 : ℕ) ↔ (n / 2 : ℕ) < (-x).1 :=
have hn2 : (n : ℕ) / 2 < n := nat.div_lt_of_lt_mul ((lt_mul_iff_one_lt_left n.pos).2 dec_trivial),
have hn2' : (n : ℕ) - n / 2 = n / 2 + 1,
by conv {to_lhs, congr, rw [← succ_sub_one n, succ_sub n.pos]};
rw [← two_mul_odd_div_two hn, two_mul, ← succ_add, nat.add_sub_cancel],
have hxn : (n : ℕ) - x.val < n,
begin
rw [nat.sub_lt_iff (le_of_lt x.2) (le_refl _), nat.sub_self],
rw ← zmod.cast_val x at hx0,
exact nat.pos_of_ne_zero (λ h, by simpa [h] using hx0)
end,
by conv {to_rhs, rw [← nat.succ_le_iff, succ_eq_add_one, ← hn2', ← zero_add (- x), ← zmod.cast_self_eq_zero,
← sub_eq_add_neg, ← zmod.cast_val x, ← nat.cast_sub (le_of_lt x.2),
zmod.val_cast_nat, mod_eq_of_lt hxn, nat.sub_le_sub_left_iff (le_of_lt x.2)] }
lemma ne_neg_self {n : ℕ+} (hn1 : (n : ℕ) % 2 = 1) {a : zmod n} (ha : a ≠ 0) : a ≠ -a :=
λ h, have a.val ≤ n / 2 ↔ (n : ℕ) / 2 < (-a).val := le_div_two_iff_lt_neg hn1 ha,
by rwa [← h, ← not_lt, not_iff_self] at this
@[simp] lemma cast_mul_right_val_cast {n m : ℕ+} (a : ℕ) :
((a : zmod (m * n)).val : zmod m) = (a : zmod m) :=
zmod.eq_iff_modeq_nat.2 (by rw zmod.val_cast_nat;
exact nat.modeq.modeq_of_modeq_mul_right _ (nat.mod_mod _ _))
@[simp] lemma cast_mul_left_val_cast {n m : ℕ+} (a : ℕ) :
((a : zmod (n * m)).val : zmod m) = (a : zmod m) :=
zmod.eq_iff_modeq_nat.2 (by rw zmod.val_cast_nat;
exact nat.modeq.modeq_of_modeq_mul_left _ (nat.mod_mod _ _))
lemma cast_val_cast_of_dvd {n m : ℕ+} (h : (m : ℕ) ∣ n) (a : ℕ) :
((a : zmod n).val : zmod m) = (a : zmod m) :=
let ⟨k , hk⟩ := h in
zmod.eq_iff_modeq_nat.2 (nat.modeq.modeq_of_modeq_mul_right k
(by rw [← hk, zmod.val_cast_nat]; exact nat.mod_mod _ _))
/-- `unit_of_coprime` makes an element of `units (zmod n)` given
a natural number `x` and a proof that `x` is coprime to `n` -/
def unit_of_coprime {n : ℕ+} (x : ℕ) (h : nat.coprime x n) : units (zmod n) :=
have (x * gcd_a x ↑n : zmod n) = 1,
by rw [← int.cast_coe_nat, ← int.cast_one, ← int.cast_mul,
zmod.eq_iff_modeq_int, ← int.coe_nat_one, ← (show nat.gcd _ _ = _, from h)];
simpa using int.modeq.gcd_a_modeq x n,
⟨x, gcd_a x n, this, by simpa [mul_comm] using this⟩
@[simp] lemma cast_unit_of_coprime {n : ℕ+} (x : ℕ) (h : nat.coprime x n) :
(unit_of_coprime x h : zmod n) = x := rfl
def units_equiv_coprime {n : ℕ+} : units (zmod n) ≃ {x : zmod n // nat.coprime x.1 n} :=
{ to_fun := λ x, ⟨x, nat.modeq.coprime_of_mul_modeq_one (x⁻¹).1.1 begin
have := units.ext_iff.1 (mul_right_inv x),
rwa [← zmod.cast_val ((1 : units (zmod n)) : zmod n), units.coe_one, zmod.one_val,
← zmod.cast_val ((x * x⁻¹ : units (zmod n)) : zmod n),
units.coe_mul, zmod.mul_val, zmod.cast_mod_nat, zmod.cast_mod_nat,
zmod.eq_iff_modeq_nat] at this
end⟩,
inv_fun := λ x, unit_of_coprime x.1.1 x.2,
left_inv := λ ⟨_, _, _, _⟩, units.ext (by simp),
right_inv := λ ⟨_, _⟩, by simp }
/-- `val_min_abs x` returns the integer in the same equivalence class as `x` that is closest to `0`,
The result will be in the interval `(-n/2, n/2]` -/
def val_min_abs {n : ℕ+} (x : zmod n) : ℤ :=
if x.val ≤ n / 2 then x.val else x.val - n
@[simp] lemma coe_val_min_abs {n : ℕ+} (x : zmod n) :
(x.val_min_abs : zmod n) = x :=
by simp [zmod.val_min_abs]; split_ifs; simp [sub_eq_add_neg]
lemma nat_abs_val_min_abs_le {n : ℕ+} (x : zmod n) : x.val_min_abs.nat_abs ≤ n / 2 :=
have (x.val - n : ℤ) ≤ 0, from sub_nonpos.2 $ int.coe_nat_le.2 $ le_of_lt x.2,
begin
rw zmod.val_min_abs,
split_ifs with h,
{ exact h },
{ rw [← int.coe_nat_le, int.of_nat_nat_abs_of_nonpos this, neg_sub],
conv_lhs { congr, rw [coe_coe, ← nat.mod_add_div n 2, int.coe_nat_add, int.coe_nat_mul,
int.coe_nat_bit0, int.coe_nat_one] },
rw ← sub_nonneg,
suffices : (0 : ℤ) ≤ x.val - ((n % 2 : ℕ) + (n / 2 : ℕ)),
{ exact le_trans this (le_of_eq $ by ring) },
exact sub_nonneg.2 (by rw [← int.coe_nat_add, int.coe_nat_le];
exact calc (n : ℕ) % 2 + n / 2 ≤ 1 + n / 2 :
add_le_add (nat.le_of_lt_succ (nat.mod_lt _ dec_trivial)) (le_refl _)
... ≤ x.val : by rw add_comm; exact nat.succ_le_of_lt (lt_of_not_ge h)) }
end
@[simp] lemma val_min_abs_zero {n : ℕ+} : (0 : zmod n).val_min_abs = 0 :=
by simp [zmod.val_min_abs]
@[simp] lemma val_min_abs_eq_zero {n : ℕ+} (x : zmod n) :
x.val_min_abs = 0 ↔ x = 0 :=
⟨λ h, begin
dsimp [zmod.val_min_abs] at h,
split_ifs at h,
{ exact fin.eq_of_veq (by simp * at *) },
{ exact absurd h (mt sub_eq_zero.1 (ne_of_lt $ int.coe_nat_lt.2 x.2)) }
end, λ hx0, hx0.symm ▸ zmod.val_min_abs_zero⟩
lemma cast_nat_abs_val_min_abs {n : ℕ+} (a : zmod n) :
(a.val_min_abs.nat_abs : zmod n) = if a.val ≤ (n : ℕ) / 2 then a else -a :=
have (a.val : ℤ) + -n ≤ 0, by erw [sub_nonpos, int.coe_nat_le]; exact le_of_lt a.2,
begin
dsimp [zmod.val_min_abs],
split_ifs,
{ simp },
{ erw [← int.cast_coe_nat, int.of_nat_nat_abs_of_nonpos this],
simp }
end
@[simp] lemma nat_abs_val_min_abs_neg {n : ℕ+} (a : zmod n) :
(-a).val_min_abs.nat_abs = a.val_min_abs.nat_abs :=
if haa : -a = a then by rw [haa]
else
have hpa : (n : ℕ) - a.val ≤ n / 2 ↔ (n : ℕ) / 2 < a.val,
from suffices (((n : ℕ) % 2) + 2 * (n / 2)) - a.val ≤ (n : ℕ) / 2 ↔ (n : ℕ) / 2 < a.val,
by rwa [nat.mod_add_div] at this,
begin
rw [nat.sub_le_iff, two_mul, ← add_assoc, nat.add_sub_cancel],
cases (n : ℕ).mod_two_eq_zero_or_one with hn0 hn1,
{ split,
{ exact λ h, lt_of_le_of_ne (le_trans (nat.le_add_left _ _) h)
begin
assume hna,
rw [← zmod.cast_val a, ← hna, neg_eq_iff_add_eq_zero, ← nat.cast_add,
zmod.eq_zero_iff_dvd_nat, ← two_mul, ← zero_add (2 * _), ← hn0,
nat.mod_add_div] at haa,
exact haa (dvd_refl _)
end },
{ rw [hn0, zero_add], exact le_of_lt } },
{ rw [hn1, add_comm, nat.succ_le_iff] }
end,
have ha0 : ¬ a = 0, from λ ha0, by simp * at *,
begin
dsimp [zmod.val_min_abs],
rw [← not_le] at hpa,
simp only [if_neg ha0, zmod.neg_val, hpa, int.coe_nat_sub (le_of_lt a.2)],
split_ifs,
{ simp [sub_eq_add_neg] },
{ rw [← int.nat_abs_neg], simp }
end
lemma val_eq_ite_val_min_abs {n : ℕ+} (a : zmod n) :
(a.val : ℤ) = a.val_min_abs + if a.val ≤ n / 2 then 0 else n :=
by simp [zmod.val_min_abs]; split_ifs; simp
lemma neg_eq_self_mod_two : ∀ (a : zmod 2), -a = a := dec_trivial
@[simp] lemma nat_abs_mod_two (a : ℤ) : (a.nat_abs : zmod 2) = a :=
by cases a; simp [zmod.neg_eq_self_mod_two]
section
variables {α : Type*} [has_zero α] [has_one α] [has_add α] {n : ℕ+}
def cast : zmod n → α := nat.cast ∘ fin.val
end
end zmod
def zmodp (p : ℕ) (hp : prime p) : Type := zmod ⟨p, hp.pos⟩
namespace zmodp
variables {p : ℕ} (hp : prime p)
instance : comm_ring (zmodp p hp) := zmod.comm_ring ⟨p, hp.pos⟩
instance : inhabited (zmodp p hp) := ⟨0⟩
instance {p : ℕ} (hp : prime p) : has_inv (zmodp p hp) :=
⟨λ a, gcd_a a.1 p⟩
lemma add_val : ∀ a b : zmodp p hp, (a + b).val = (a.val + b.val) % p
| ⟨_, _⟩ ⟨_, _⟩ := rfl
lemma mul_val : ∀ a b : zmodp p hp, (a * b).val = (a.val * b.val) % p
| ⟨_, _⟩ ⟨_, _⟩ := rfl
@[simp] lemma one_val : (1 : zmodp p hp).val = 1 :=
nat.mod_eq_of_lt hp.one_lt
@[simp] lemma zero_val : (0 : zmodp p hp).val = 0 := rfl
lemma val_cast_nat (a : ℕ) : (a : zmodp p hp).val = a % p :=
@zmod.val_cast_nat ⟨p, hp.pos⟩ _
lemma mk_eq_cast {a : ℕ} (h : a < p) : (⟨a, h⟩ : zmodp p hp) = (a : zmodp p hp) :=
@zmod.mk_eq_cast ⟨p, hp.pos⟩ _ _
@[simp] lemma cast_self_eq_zero: (p : zmodp p hp) = 0 :=
fin.eq_of_veq $ by simp [val_cast_nat]
lemma val_cast_of_lt {a : ℕ} (h : a < p) : (a : zmodp p hp).val = a :=
@zmod.val_cast_of_lt ⟨p, hp.pos⟩ _ h
@[simp] lemma cast_mod_nat (a : ℕ) : ((a % p : ℕ) : zmodp p hp) = a :=
@zmod.cast_mod_nat ⟨p, hp.pos⟩ _
@[simp] lemma cast_val (a : zmodp p hp) : (a.val : zmodp p hp) = a :=
@zmod.cast_val ⟨p, hp.pos⟩ _
@[simp] lemma cast_mod_int (a : ℤ) : ((a % p : ℤ) : zmodp p hp) = a :=
@zmod.cast_mod_int ⟨p, hp.pos⟩ _
lemma val_cast_int (a : ℤ) : (a : zmodp p hp).val = (a % p).nat_abs :=
@zmod.val_cast_int ⟨p, hp.pos⟩ _
lemma coe_val_cast_int (a : ℤ) : ((a : zmodp p hp).val : ℤ) = a % (p : ℕ) :=
@zmod.coe_val_cast_int ⟨p, hp.pos⟩ _
lemma eq_iff_modeq_nat {a b : ℕ} : (a : zmodp p hp) = b ↔ a ≡ b [MOD p] :=
@zmod.eq_iff_modeq_nat ⟨p, hp.pos⟩ _ _
lemma eq_iff_modeq_int {a b : ℤ} : (a : zmodp p hp) = b ↔ a ≡ b [ZMOD p] :=
@zmod.eq_iff_modeq_int ⟨p, hp.pos⟩ _ _
lemma eq_zero_iff_dvd_nat (a : ℕ) : (a : zmodp p hp) = 0 ↔ p ∣ a :=
@zmod.eq_zero_iff_dvd_nat ⟨p, hp.pos⟩ _
lemma eq_zero_iff_dvd_int (a : ℤ) : (a : zmodp p hp) = 0 ↔ (p : ℤ) ∣ a :=
@zmod.eq_zero_iff_dvd_int ⟨p, hp.pos⟩ _
instance : fintype (zmodp p hp) := @zmod.fintype ⟨p, hp.pos⟩
instance decidable_eq : decidable_eq (zmodp p hp) := fin.decidable_eq _
instance X (h : prime 2) : subsingleton (units (zmodp 2 h)) :=
zmod.subsingleton
instance : has_repr (zmodp p hp) := fin.has_repr _
@[simp] lemma card_zmodp : fintype.card (zmodp p hp) = p :=
@zmod.card_zmod ⟨p, hp.pos⟩
lemma le_div_two_iff_lt_neg {p : ℕ} (hp : prime p) (hp1 : p % 2 = 1)
{x : zmodp p hp} (hx0 : x ≠ 0) : x.1 ≤ (p / 2 : ℕ) ↔ (p / 2 : ℕ) < (-x).1 :=
@zmod.le_div_two_iff_lt_neg ⟨p, hp.pos⟩ hp1 _ hx0
lemma ne_neg_self (hp1 : p % 2 = 1) {a : zmodp p hp} (ha : a ≠ 0) : a ≠ -a :=
@zmod.ne_neg_self ⟨p, hp.pos⟩ hp1 _ ha
variable {hp}
/-- `val_min_abs x` returns the integer in the same equivalence class as `x` that is closest to `0`,
The result will be in the interval `(-n/2, n/2]` -/
def val_min_abs (x : zmodp p hp) : ℤ := zmod.val_min_abs x
@[simp] lemma coe_val_min_abs (x : zmodp p hp) :
(x.val_min_abs : zmodp p hp) = x :=
zmod.coe_val_min_abs x
lemma nat_abs_val_min_abs_le (x : zmodp p hp) : x.val_min_abs.nat_abs ≤ p / 2 :=
zmod.nat_abs_val_min_abs_le x
@[simp] lemma val_min_abs_zero : (0 : zmodp p hp).val_min_abs = 0 :=
zmod.val_min_abs_zero
@[simp] lemma val_min_abs_eq_zero (x : zmodp p hp) : x.val_min_abs = 0 ↔ x = 0 :=
zmod.val_min_abs_eq_zero x
lemma cast_nat_abs_val_min_abs (a : zmodp p hp) :
(a.val_min_abs.nat_abs : zmodp p hp) = if a.val ≤ p / 2 then a else -a :=
zmod.cast_nat_abs_val_min_abs a
@[simp] lemma nat_abs_val_min_abs_neg (a : zmodp p hp) :
(-a).val_min_abs.nat_abs = a.val_min_abs.nat_abs :=
zmod.nat_abs_val_min_abs_neg _
lemma val_eq_ite_val_min_abs (a : zmodp p hp) :
(a.val : ℤ) = a.val_min_abs + if a.val ≤ p / 2 then 0 else p :=
zmod.val_eq_ite_val_min_abs _
variable (hp)
lemma prime_ne_zero {q : ℕ} (hq : prime q) (hpq : p ≠ q) : (q : zmodp p hp) ≠ 0 :=
by rwa [← nat.cast_zero, ne.def, zmodp.eq_iff_modeq_nat, nat.modeq.modeq_zero_iff,
← hp.coprime_iff_not_dvd, coprime_primes hp hq]
lemma mul_inv_eq_gcd (a : ℕ) : (a : zmodp p hp) * a⁻¹ = nat.gcd a p :=
by rw [← int.cast_coe_nat (nat.gcd _ _), nat.gcd_comm, nat.gcd_rec, ← (eq_iff_modeq_int _).2 (int.modeq.gcd_a_modeq _ _)];
simp [has_inv.inv, val_cast_nat]
private lemma mul_inv_cancel_aux : ∀ a : zmodp p hp, a ≠ 0 → a * a⁻¹ = 1 :=
λ ⟨a, hap⟩ ha0, begin
rw [mk_eq_cast, ne.def, ← @nat.cast_zero (zmodp p hp), eq_iff_modeq_nat, modeq_zero_iff] at ha0,
have : nat.gcd p a = 1 := (prime.coprime_iff_not_dvd hp).2 ha0,
rw [mk_eq_cast _ hap, mul_inv_eq_gcd, nat.gcd_comm],
simp [nat.gcd_comm, this]
end
instance : field (zmodp p hp) :=
{ zero_ne_one := fin.ne_of_vne $ show 0 ≠ 1 % p,
by rw nat.mod_eq_of_lt hp.one_lt;
exact zero_ne_one,
mul_inv_cancel := mul_inv_cancel_aux hp,
inv_zero := show (gcd_a 0 p : zmodp p hp) = 0,
by unfold gcd_a xgcd xgcd_aux; refl,
..zmodp.comm_ring hp,
..zmodp.has_inv hp }
end zmodp
|
39d905529bd3e4c78705075a6819b16a452f5750
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/algebra/category/fgModule/limits.lean
|
6c02caa86c10039dd142afa9c06105f5c80e32c2
|
[
"Apache-2.0"
] |
permissive
|
leanprover-community/mathlib
|
56a2cadd17ac88caf4ece0a775932fa26327ba0e
|
442a83d738cb208d3600056c489be16900ba701d
|
refs/heads/master
| 1,693,584,102,358
| 1,693,471,902,000
| 1,693,471,902,000
| 97,922,418
| 1,595
| 352
|
Apache-2.0
| 1,694,693,445,000
| 1,500,624,130,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 3,031
|
lean
|
/-
Copyright (c) 2022 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import algebra.category.fgModule.basic
import algebra.category.Module.limits
import algebra.category.Module.products
import algebra.category.Module.epi_mono
import category_theory.limits.creates
import category_theory.limits.shapes.finite_limits
import category_theory.limits.constructions.limits_of_products_and_equalizers
/-!
# `forget₂ (fgModule K) (Module K)` creates all finite limits.
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
And hence `fgModule K` has all finite limits.
## Future work
After generalising `fgModule` to allow the ring and the module to live in different universes,
generalize this construction so we can take limits over smaller diagrams,
as is done for the other algebraic categories.
Analogous constructions for Noetherian modules.
-/
noncomputable theory
universes v u
open category_theory
open category_theory.limits
namespace fgModule
variables {J : Type} [small_category J] [fin_category J]
variables {k : Type v} [field k]
instance {J : Type} [fintype J] (Z : J → Module.{v} k) [∀ j, finite_dimensional k (Z j)] :
finite_dimensional k (∏ λ j, Z j : Module.{v} k) :=
begin
haveI : finite_dimensional k (Module.of k (Π j, Z j)), { dsimp, apply_instance, },
exact finite_dimensional.of_injective
(Module.pi_iso_pi _).hom
((Module.mono_iff_injective _).1 (by apply_instance)),
end
/-- Finite limits of finite dimensional vectors spaces are finite dimensional,
because we can realise them as subobjects of a finite product. -/
instance (F : J ⥤ fgModule k) :
finite_dimensional k (limit (F ⋙ forget₂ (fgModule k) (Module.{v} k)) : Module.{v} k) :=
begin
haveI : ∀ j, finite_dimensional k ((F ⋙ forget₂ (fgModule k) (Module.{v} k)).obj j),
{ intro j, change finite_dimensional k (F.obj j).obj, apply_instance, },
exact finite_dimensional.of_injective
(limit_subobject_product (F ⋙ forget₂ (fgModule k) (Module.{v} k)))
((Module.mono_iff_injective _).1 (by apply_instance)),
end
/-- The forgetful functor from `fgModule k` to `Module k` creates all finite limits. -/
def forget₂_creates_limit (F : J ⥤ fgModule k) :
creates_limit F (forget₂ (fgModule k) (Module.{v} k)) :=
creates_limit_of_fully_faithful_of_iso
⟨(limit (F ⋙ forget₂ (fgModule k) (Module.{v} k)) : Module.{v} k), by apply_instance⟩
(iso.refl _)
instance : creates_limits_of_shape J (forget₂ (fgModule k) (Module.{v} k)) :=
{ creates_limit := λ F, forget₂_creates_limit F, }
instance : has_finite_limits (fgModule k) :=
{ out := λ J _ _, by exactI
has_limits_of_shape_of_has_limits_of_shape_creates_limits_of_shape
(forget₂ (fgModule k) (Module.{v} k)), }
instance : preserves_finite_limits (forget₂ (fgModule k) (Module.{v} k)) :=
{ preserves_finite_limits := λ J _ _, by exactI infer_instance, }
end fgModule
|
f8d524d261703f6dcfb512da6431fec609f7feb8
|
d1a52c3f208fa42c41df8278c3d280f075eb020c
|
/tests/lean/run/isDefEqCheckAssignmentBug.lean
|
8d33cc220a5882993d2de9793e88871ab9a5870e
|
[
"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
| 828
|
lean
|
import Lean
open Lean
open Lean.Meta
def f (x : Type) := x
def tst : MetaM Unit := do
let m1 ← mkFreshExprMVar none
withLocalDeclD `x m1 fun x => do
trace[Meta.debug] "{x} : {← inferType x}"
trace[Meta.debug] "{m1} : {← inferType m1}"
let m2 ← mkFreshExprMVar (mkSort levelOne)
let t ← mkAppM ``f #[m2]
trace[Meta.debug] "{m2} : {← inferType m2}"
unless (← fullApproxDefEq <| isDefEq m1 t) do -- m1 := f m3 -- where `m3` has a smaller scope than `m2`
throwError "isDefEq failed"
trace[Meta.debug] "{m2} : {← inferType m2}"
trace[Meta.debug] "{m1} : {← inferType m1}"
let e ← mkForallFVars #[x] m2 -- `forall (x : f ?m2), ?m2`
trace[Meta.debug] "{e} : {← e}"
return ()
set_option trace.Meta.isDefEq true
set_option trace.Meta.debug true
#eval tst
|
4f89c768fa4e359fbd2cc3ce2285c8fa48f160d6
|
9ad8d18fbe5f120c22b5e035bc240f711d2cbd7e
|
/src/combinatorics/fibonacci.lean
|
05e3e81b570885c1326784021f871e342c9f94fb
|
[] |
no_license
|
agusakov/lean_lib
|
c0e9cc29fc7d2518004e224376adeb5e69b5cc1a
|
f88d162da2f990b87c4d34f5f46bbca2bbc5948e
|
refs/heads/master
| 1,642,141,461,087
| 1,557,395,798,000
| 1,557,395,798,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 5,151
|
lean
|
/-
Copyright (c) 2019 Neil Strickland. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Neil Strickland
This file defines Fibonacci numbers and their reductions mod `n`.
It was intended to make computation efficient, but does not
succeed very well. Some better approaches were discussed on
Zulip by Mario and Kenny; they should be incorporated here.
-/
import data.real.basic data.fintype algebra.big_operators data.nat.modeq
import tactic.find tactic.squeeze tactic.norm_num tactic.ring
namespace combinatorics
/- This is the basic definition of fibonacci numbers. It
is not good for efficient evaluation.
-/
def fibonacci : ℕ → ℕ
| 0 := 0
| 1 := 1
| (n + 2) := (fibonacci n) + (fibonacci (n + 1))
/- We now do a more efficient version, and prove that it is
consistent with the original one.
-/
def fibonacci_step : ℕ × ℕ → ℕ × ℕ :=
λ ⟨a,b⟩, ⟨b, a + b⟩
def fibonacci_pair : ℕ → ℕ × ℕ
| 0 := ⟨0,1⟩
| (n + 1) := fibonacci_step (fibonacci_pair n)
lemma fibonacci_pair_spec : ∀ n ,
fibonacci_pair n = ⟨fibonacci n,fibonacci n.succ⟩
| 0 := rfl
| (nat.succ n) := begin
rw[fibonacci_pair,fibonacci_pair_spec n,fibonacci_step,fibonacci],
ext,refl,refl,
end
lemma fibonacci_from_pair (n : ℕ) :
fibonacci n = (fibonacci_pair n).fst :=
by rw[fibonacci_pair_spec n].
/- We now prove a fact about the fibonacci numbers mod 2.
Later we will generalise this for an arbitrary modulus.
-/
lemma fibonacci_bodd_step (n : ℕ) :
(fibonacci (n + 3)).bodd = (fibonacci n).bodd :=
begin
rw[fibonacci,fibonacci,nat.bodd_add,nat.bodd_add],
cases (fibonacci (n + 1)).bodd;
cases (fibonacci n).bodd;
refl,
end
lemma fibonacci_bodd : ∀ n, (fibonacci n).bodd = bnot (n % 3 = 0)
| 0 := rfl
| 1 := rfl
| 2 := rfl
| (n + 3) := begin
rw[fibonacci_bodd_step n,fibonacci_bodd n],congr,
end
/-
We now do a more general theory of modular periodicity
of fibonacci numbers. For computational efficiency, we
give an inductive definition of modular fibonacci numbers
that does not require us to calculate the non-modular ones.
We then prove that it is consistent with the original
definition.
-/
def pair_mod (p : ℕ) : ℕ × ℕ → ℕ × ℕ :=
λ ⟨a,b⟩, ⟨a % p,b % p⟩
lemma pair_mod_mod (p : ℕ) : ∀ (c : ℕ × ℕ),
pair_mod p (pair_mod p c) = pair_mod p c :=
λ ⟨a,b⟩, by {simp[pair_mod,nat.mod_mod],}
def fibonacci_pair_mod (p : ℕ) : ℕ → ℕ × ℕ
| 0 := pair_mod p ⟨0,1⟩
| (n + 1) := pair_mod p (fibonacci_step (fibonacci_pair_mod n))
lemma fibonacci_pair_mod_mod (p : ℕ) : ∀ n,
pair_mod p (fibonacci_pair_mod p n) = fibonacci_pair_mod p n
| 0 := by {rw[fibonacci_pair_mod,pair_mod_mod],}
| (n + 1) := by {rw[fibonacci_pair_mod,pair_mod_mod],}
lemma mod_step_mod (p : ℕ) : ∀ (c : ℕ × ℕ),
pair_mod p (fibonacci_step c) =
pair_mod p (fibonacci_step (pair_mod p c)) :=
λ ⟨a,b⟩, begin
change (⟨b % p,(a + b) % p⟩ : ℕ × ℕ) =
⟨b % p % p,(a % p + b % p) % p⟩,
have e0 : b % p % p = b % p := nat.mod_mod b p,
have e1 : (a % p + b % p) % p = (a + b) % p :=
nat.modeq.modeq_add (nat.mod_mod a p) (nat.mod_mod b p),
rw[e0,e1],
end
lemma fibonacci_pair_mod_spec (p : ℕ) : ∀ n,
fibonacci_pair_mod p n = pair_mod p (fibonacci_pair n)
| 0 := rfl
| (n + 1) := begin
rw[fibonacci_pair_mod,fibonacci_pair,fibonacci_pair_mod_spec n],
rw[← mod_step_mod],
end
lemma fibonacci_mod_spec (p : ℕ) (n : ℕ) :
(fibonacci_pair_mod p n).fst = (fibonacci n) % p :=
begin
rw[fibonacci_pair_mod_spec,fibonacci_pair_spec,pair_mod],
refl,
end
lemma fibonacci_pair_period₀ {p : ℕ} {d : ℕ}
(h : fibonacci_pair_mod p d = pair_mod p ⟨0,1⟩) :
∀ n, fibonacci_pair_mod p (n + d) = fibonacci_pair_mod p n
| 0 := by {rw[zero_add,h,fibonacci_pair_mod],}
| (n + 1) := by {
rw[add_assoc,add_comm 1 d,← add_assoc],
rw[fibonacci_pair_mod,fibonacci_pair_mod],
rw[fibonacci_pair_period₀ n],
}
lemma fibonacci_pair_period₁ {p : ℕ} {d : ℕ}
(h : fibonacci_pair_mod p d = pair_mod p ⟨0,1⟩) (m : ℕ) :
∀ n, fibonacci_pair_mod p (m + d * n) = fibonacci_pair_mod p m
| 0 := by {rw[mul_zero,add_zero]}
| (n + 1) := by {
have : m + d * (n + 1) = (m + d * n) + d := by ring,
rw[this,fibonacci_pair_period₀ h,fibonacci_pair_period₁],
}
lemma fibonacci_pair_period {p : ℕ} {d : ℕ}
(h : fibonacci_pair_mod p d = pair_mod p ⟨0,1⟩) (n : ℕ) :
fibonacci_pair_mod p n = fibonacci_pair_mod p (n % d) :=
calc
fibonacci_pair_mod p n = fibonacci_pair_mod p (n % d + d * (n / d)) :
congr_arg (fibonacci_pair_mod p) (nat.mod_add_div n d).symm
... = fibonacci_pair_mod p (n % d) : fibonacci_pair_period₁ h (n % d) (n / d)
lemma fibonacci_period {p : ℕ} {d : ℕ}
(h : fibonacci_pair_mod p d = pair_mod p ⟨0,1⟩) (n : ℕ) :
(fibonacci n) ≡ (fibonacci (n % d)) [MOD p] :=
begin
rw[nat.modeq,← fibonacci_mod_spec,← fibonacci_mod_spec],
rw[fibonacci_pair_period],
exact h,
end
/-
Prove the identity
(fibonacci n) = (choose n 0) + (choose n-1 1) + (choose n-2 2) + ...
-/
end combinatorics
|
0b4cd14c439bc500d53f0d4f4d03e4ff953690b6
|
b7f22e51856f4989b970961f794f1c435f9b8f78
|
/hott/hit/quotient.hlean
|
3f49a44b04f4a98a95d53a9833553e975611afe7
|
[
"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
| 8,554
|
hlean
|
/-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
Quotients. This is a quotient without truncation for an arbitrary type-valued binary relation.
See also .set_quotient
-/
/-
The hit quotient is primitive, declared in init.hit.
The constructors are, given {A : Type} (R : A → A → Type),
* class_of : A → quotient R (A implicit, R explicit)
* eq_of_rel : Π{a a' : A}, R a a' → class_of a = class_of a' (R explicit)
-/
import arity cubical.squareover types.arrow cubical.pathover2 types.pointed
open eq equiv sigma sigma.ops pi is_trunc pointed
namespace quotient
variables {A : Type} {R : A → A → Type}
protected definition elim {P : Type} (Pc : A → P) (Pp : Π⦃a a' : A⦄ (H : R a a'), Pc a = Pc a')
(x : quotient R) : P :=
quotient.rec Pc (λa a' H, pathover_of_eq _ (Pp H)) x
protected definition elim_on [reducible] {P : Type} (x : quotient R)
(Pc : A → P) (Pp : Π⦃a a' : A⦄ (H : R a a'), Pc a = Pc a') : P :=
quotient.elim Pc Pp x
theorem elim_eq_of_rel {P : Type} (Pc : A → P)
(Pp : Π⦃a a' : A⦄ (H : R a a'), Pc a = Pc a') {a a' : A} (H : R a a')
: ap (quotient.elim Pc Pp) (eq_of_rel R H) = Pp H :=
begin
apply eq_of_fn_eq_fn_inv !(pathover_constant (eq_of_rel R H)),
rewrite [▸*,-apd_eq_pathover_of_eq_ap,↑quotient.elim,rec_eq_of_rel],
end
protected definition rec_prop {A : Type} {R : A → A → Type} {P : quotient R → Type}
[H : Πx, is_prop (P x)] (Pc : Π(a : A), P (class_of R a)) (x : quotient R) : P x :=
quotient.rec Pc (λa a' H, !is_prop.elimo) x
protected definition elim_prop {P : Type} [H : is_prop P] (Pc : A → P) (x : quotient R) : P :=
quotient.elim Pc (λa a' H, !is_prop.elim) x
protected definition elim_type (Pc : A → Type)
(Pp : Π⦃a a' : A⦄ (H : R a a'), Pc a ≃ Pc a') : quotient R → Type :=
quotient.elim Pc (λa a' H, ua (Pp H))
protected definition elim_type_on [reducible] (x : quotient R) (Pc : A → Type)
(Pp : Π⦃a a' : A⦄ (H : R a a'), Pc a ≃ Pc a') : Type :=
quotient.elim_type Pc Pp x
theorem elim_type_eq_of_rel_fn (Pc : A → Type)
(Pp : Π⦃a a' : A⦄ (H : R a a'), Pc a ≃ Pc a') {a a' : A} (H : R a a')
: transport (quotient.elim_type Pc Pp) (eq_of_rel R H) = to_fun (Pp H) :=
by rewrite [tr_eq_cast_ap_fn, ↑quotient.elim_type, elim_eq_of_rel]; apply cast_ua_fn
-- rename to elim_type_eq_of_rel_fn_inv
theorem elim_type_eq_of_rel_inv (Pc : A → Type)
(Pp : Π⦃a a' : A⦄ (H : R a a'), Pc a ≃ Pc a') {a a' : A} (H : R a a')
: transport (quotient.elim_type Pc Pp) (eq_of_rel R H)⁻¹ = to_inv (Pp H) :=
by rewrite [tr_eq_cast_ap_fn, ↑quotient.elim_type, ap_inv, elim_eq_of_rel]; apply cast_ua_inv_fn
-- remove '
theorem elim_type_eq_of_rel_inv' (Pc : A → Type)
(Pp : Π⦃a a' : A⦄ (H : R a a'), Pc a ≃ Pc a') {a a' : A} (H : R a a') (x : Pc a')
: transport (quotient.elim_type Pc Pp) (eq_of_rel R H)⁻¹ x = to_inv (Pp H) x :=
ap10 (elim_type_eq_of_rel_inv Pc Pp H) x
theorem elim_type_eq_of_rel.{u} (Pc : A → Type.{u})
(Pp : Π⦃a a' : A⦄ (H : R a a'), Pc a ≃ Pc a') {a a' : A} (H : R a a') (p : Pc a)
: transport (quotient.elim_type Pc Pp) (eq_of_rel R H) p = to_fun (Pp H) p :=
ap10 (elim_type_eq_of_rel_fn Pc Pp H) p
definition elim_type_eq_of_rel' (Pc : A → Type)
(Pp : Π⦃a a' : A⦄ (H : R a a'), Pc a ≃ Pc a') {a a' : A} (H : R a a') (p : Pc a)
: pathover (quotient.elim_type Pc Pp) p (eq_of_rel R H) (to_fun (Pp H) p) :=
pathover_of_tr_eq (elim_type_eq_of_rel Pc Pp H p)
definition elim_type_uncurried (H : Σ(Pc : A → Type), Π⦃a a' : A⦄ (H : R a a'), Pc a ≃ Pc a')
: quotient R → Type :=
quotient.elim_type H.1 H.2
end quotient
attribute quotient.rec [recursor]
attribute quotient.elim [unfold 6] [recursor 6]
attribute quotient.elim_type [unfold 5]
attribute quotient.elim_on [unfold 4]
attribute quotient.elim_type_on [unfold 3]
namespace quotient
section
variables {A : Type} (R : A → A → Type)
/- The dependent universal property -/
definition quotient_pi_equiv (C : quotient R → Type) : (Πx, C x) ≃
(Σ(f : Π(a : A), C (class_of R a)), Π⦃a a' : A⦄ (H : R a a'), f a =[eq_of_rel R H] f a') :=
begin
fapply equiv.MK,
{ intro f, exact ⟨λa, f (class_of R a), λa a' H, apd f (eq_of_rel R H)⟩},
{ intro v x, induction v with i p, induction x,
exact (i a),
exact (p H)},
{ intro v, induction v with i p, esimp,
apply ap (sigma.mk i), apply eq_of_homotopy3, intro a a' H, apply rec_eq_of_rel},
{ intro f, apply eq_of_homotopy, intro x, induction x: esimp,
apply eq_pathover_dep, esimp, rewrite rec_eq_of_rel, exact hrflo},
end
end
definition pquotient [constructor] {A : Type*} (R : A → A → Type) : Type* :=
pType.mk (quotient R) (class_of R pt)
/- the flattening lemma -/
namespace flattening
section
parameters {A : Type} (R : A → A → Type) (C : A → Type) (f : Π⦃a a'⦄, R a a' → C a ≃ C a')
include f
variables {a a' : A} {r : R a a'}
local abbreviation P [unfold 5] := quotient.elim_type C f
definition flattening_type : Type := Σa, C a
local abbreviation X := flattening_type
inductive flattening_rel : X → X → Type :=
| mk : Π⦃a a' : A⦄ (r : R a a') (c : C a), flattening_rel ⟨a, c⟩ ⟨a', f r c⟩
definition Ppt [constructor] (c : C a) : sigma P :=
⟨class_of R a, c⟩
definition Peq (r : R a a') (c : C a) : Ppt c = Ppt (f r c) :=
begin
fapply sigma_eq: esimp,
{ apply eq_of_rel R r},
{ refine elim_type_eq_of_rel' C f r c}
end
definition rec {Q : sigma P → Type} (Qpt : Π{a : A} (x : C a), Q (Ppt x))
(Qeq : Π⦃a a' : A⦄ (r : R a a') (c : C a), Qpt c =[Peq r c] Qpt (f r c))
(v : sigma P) : Q v :=
begin
induction v with q p,
induction q,
{ exact Qpt p},
{ apply pi_pathover_left', esimp, intro c,
refine _ ⬝op apdt Qpt (elim_type_eq_of_rel C f H c)⁻¹ᵖ,
refine _ ⬝op (tr_compose Q Ppt _ _)⁻¹ ,
rewrite ap_inv,
refine pathover_cancel_right _ !tr_pathover⁻¹ᵒ,
refine change_path _ (Qeq H c),
symmetry, rewrite [↑[Ppt, Peq]],
refine whisker_left _ !ap_dpair ⬝ _,
refine !dpair_eq_dpair_con⁻¹ ⬝ _, esimp,
apply ap (dpair_eq_dpair _),
esimp [elim_type_eq_of_rel',pathover_idp_of_eq],
exact !pathover_of_tr_eq_eq_concato⁻¹},
end
definition elim {Q : Type} (Qpt : Π{a : A}, C a → Q)
(Qeq : Π⦃a a' : A⦄ (r : R a a') (c : C a), Qpt c = Qpt (f r c))
(v : sigma P) : Q :=
begin
induction v with q p,
induction q,
{ exact Qpt p},
{ apply arrow_pathover_constant_right, esimp,
intro c, exact Qeq H c ⬝ ap Qpt (elim_type_eq_of_rel C f H c)⁻¹},
end
theorem elim_Peq {Q : Type} (Qpt : Π{a : A}, C a → Q)
(Qeq : Π⦃a a' : A⦄ (r : R a a') (c : C a), Qpt c = Qpt (f r c)) {a a' : A} (r : R a a')
(c : C a) : ap (elim @Qpt Qeq) (Peq r c) = Qeq r c :=
begin
refine !ap_dpair_eq_dpair ⬝ _,
refine !apd011_eq_apo11_apd ⬝ _,
rewrite [rec_eq_of_rel, ▸*],
refine !apo11_arrow_pathover_constant_right ⬝ _,
rewrite [↑elim_type_eq_of_rel', to_right_inv !pathover_equiv_tr_eq, ap_inv],
apply inv_con_cancel_right
end
open flattening_rel
definition flattening_lemma : sigma P ≃ quotient flattening_rel :=
begin
fapply equiv.MK,
{ refine elim _ _,
{ intro a c, exact class_of _ ⟨a, c⟩},
{ intro a a' r c, apply eq_of_rel, constructor}},
{ intro q, induction q with x x x' H,
{ exact Ppt x.2},
{ induction H, esimp, apply Peq}},
{ intro q, induction q with x x x' H: esimp,
{ induction x with a c, reflexivity},
{ induction H, esimp, apply eq_pathover, apply hdeg_square,
refine ap_compose (elim _ _) (quotient.elim _ _) _ ⬝ _,
rewrite [elim_eq_of_rel, ap_id, ▸*],
apply elim_Peq}},
{ refine rec (λa x, idp) _, intros,
apply eq_pathover, apply hdeg_square,
refine ap_compose (quotient.elim _ _) (elim _ _) _ ⬝ _,
rewrite [elim_Peq, ap_id, ▸*],
apply elim_eq_of_rel}
end
end
end flattening
end quotient
|
c69392008608c630442537018ba3ae4a617cbac2
|
2a70b774d16dbdf5a533432ee0ebab6838df0948
|
/_target/deps/mathlib/src/data/pnat/basic.lean
|
87856d143cd1b473d4712545bbf0f3ffb22957ac
|
[
"Apache-2.0"
] |
permissive
|
hjvromen/lewis
|
40b035973df7c77ebf927afab7878c76d05ff758
|
105b675f73630f028ad5d890897a51b3c1146fb0
|
refs/heads/master
| 1,677,944,636,343
| 1,676,555,301,000
| 1,676,555,301,000
| 327,553,599
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 14,154
|
lean
|
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro, Neil Strickland
-/
import data.nat.basic
/-!
# The positive natural numbers
This file defines the type `ℕ+` or `pnat`, the subtype of natural numbers that are positive.
-/
/-- `ℕ+` is the type of positive natural numbers. It is defined as a subtype,
and the VM representation of `ℕ+` is the same as `ℕ` because the proof
is not stored. -/
def pnat := {n : ℕ // 0 < n}
notation `ℕ+` := pnat
instance coe_pnat_nat : has_coe ℕ+ ℕ := ⟨subtype.val⟩
instance : has_repr ℕ+ := ⟨λ n, repr n.1⟩
/-- Predecessor of a `ℕ+`, as a `ℕ`. -/
def pnat.nat_pred (i : ℕ+) : ℕ := i - 1
namespace nat
/-- Convert a natural number to a positive natural number. The
positivity assumption is inferred by `dec_trivial`. -/
def to_pnat (n : ℕ) (h : 0 < n . tactic.exact_dec_trivial) : ℕ+ := ⟨n, h⟩
/-- Write a successor as an element of `ℕ+`. -/
def succ_pnat (n : ℕ) : ℕ+ := ⟨succ n, succ_pos n⟩
@[simp] theorem succ_pnat_coe (n : ℕ) : (succ_pnat n : ℕ) = succ n := rfl
theorem succ_pnat_inj {n m : ℕ} : succ_pnat n = succ_pnat m → n = m :=
λ h, by { let h' := congr_arg (coe : ℕ+ → ℕ) h, exact nat.succ.inj h' }
/-- Convert a natural number to a pnat. `n+1` is mapped to itself,
and `0` becomes `1`. -/
def to_pnat' (n : ℕ) : ℕ+ := succ_pnat (pred n)
@[simp] theorem to_pnat'_coe : ∀ (n : ℕ),
((to_pnat' n) : ℕ) = ite (0 < n) n 1
| 0 := rfl
| (m + 1) := by {rw [if_pos (succ_pos m)], refl}
end nat
namespace pnat
open nat
/-- We now define a long list of structures on ℕ+ induced by
similar structures on ℕ. Most of these behave in a completely
obvious way, but there are a few things to be said about
subtraction, division and powers.
-/
instance : decidable_eq ℕ+ := λ (a b : ℕ+), by apply_instance
instance : linear_order ℕ+ :=
subtype.linear_order _
@[simp] lemma mk_le_mk (n k : ℕ) (hn : 0 < n) (hk : 0 < k) :
(⟨n, hn⟩ : ℕ+) ≤ ⟨k, hk⟩ ↔ n ≤ k := iff.rfl
@[simp] lemma mk_lt_mk (n k : ℕ) (hn : 0 < n) (hk : 0 < k) :
(⟨n, hn⟩ : ℕ+) < ⟨k, hk⟩ ↔ n < k := iff.rfl
@[simp, norm_cast] lemma coe_le_coe (n k : ℕ+) : (n:ℕ) ≤ k ↔ n ≤ k := iff.rfl
@[simp, norm_cast] lemma coe_lt_coe (n k : ℕ+) : (n:ℕ) < k ↔ n < k := iff.rfl
@[simp] theorem pos (n : ℕ+) : 0 < (n : ℕ) := n.2
theorem eq {m n : ℕ+} : (m : ℕ) = n → m = n := subtype.eq
@[simp] lemma coe_inj {m n : ℕ+} : (m : ℕ) = n ↔ m = n := set_coe.ext_iff
@[simp] theorem mk_coe (n h) : ((⟨n, h⟩ : ℕ+) : ℕ) = n := rfl
instance : add_comm_semigroup ℕ+ :=
{ add := λ a b, ⟨(a + b : ℕ), add_pos a.pos b.pos⟩,
add_comm := λ a b, subtype.eq (add_comm a b),
add_assoc := λ a b c, subtype.eq (add_assoc a b c) }
@[simp] theorem add_coe (m n : ℕ+) : ((m + n : ℕ+) : ℕ) = m + n := rfl
instance coe_add_hom : is_add_hom (coe : ℕ+ → ℕ) := ⟨add_coe⟩
instance : add_left_cancel_semigroup ℕ+ :=
{ add_left_cancel := λ a b c h, by {
replace h := congr_arg (coe : ℕ+ → ℕ) h,
rw [add_coe, add_coe] at h,
exact eq ((add_right_inj (a : ℕ)).mp h)},
.. (pnat.add_comm_semigroup) }
instance : add_right_cancel_semigroup ℕ+ :=
{ add_right_cancel := λ a b c h, by {
replace h := congr_arg (coe : ℕ+ → ℕ) h,
rw [add_coe, add_coe] at h,
exact eq ((add_left_inj (b : ℕ)).mp h)},
.. (pnat.add_comm_semigroup) }
@[simp] theorem ne_zero (n : ℕ+) : (n : ℕ) ≠ 0 := ne_of_gt n.2
theorem to_pnat'_coe {n : ℕ} : 0 < n → (n.to_pnat' : ℕ) = n := succ_pred_eq_of_pos
@[simp] theorem coe_to_pnat' (n : ℕ+) : (n : ℕ).to_pnat' = n := eq (to_pnat'_coe n.pos)
instance : comm_monoid ℕ+ :=
{ mul := λ m n, ⟨m.1 * n.1, mul_pos m.2 n.2⟩,
mul_assoc := λ a b c, subtype.eq (mul_assoc _ _ _),
one := succ_pnat 0,
one_mul := λ a, subtype.eq (one_mul _),
mul_one := λ a, subtype.eq (mul_one _),
mul_comm := λ a b, subtype.eq (mul_comm _ _) }
theorem lt_add_one_iff : ∀ {a b : ℕ+}, a < b + 1 ↔ a ≤ b :=
λ a b, nat.lt_add_one_iff
theorem add_one_le_iff : ∀ {a b : ℕ+}, a + 1 ≤ b ↔ a < b :=
λ a b, nat.add_one_le_iff
@[simp] lemma one_le (n : ℕ+) : (1 : ℕ+) ≤ n := n.2
instance : order_bot ℕ+ :=
{ bot := 1,
bot_le := λ a, a.property,
..(by apply_instance : partial_order ℕ+) }
@[simp] lemma bot_eq_zero : (⊥ : ℕ+) = 1 := rfl
instance : inhabited ℕ+ := ⟨1⟩
-- Some lemmas that rewrite `pnat.mk n h`, for `n` an explicit numeral, into explicit numerals.
@[simp] lemma mk_one {h} : (⟨1, h⟩ : ℕ+) = (1 : ℕ+) := rfl
@[simp] lemma mk_bit0 (n) {h} : (⟨bit0 n, h⟩ : ℕ+) = (bit0 ⟨n, pos_of_bit0_pos h⟩ : ℕ+) := rfl
@[simp] lemma mk_bit1 (n) {h} {k} : (⟨bit1 n, h⟩ : ℕ+) = (bit1 ⟨n, k⟩ : ℕ+) := rfl
-- Some lemmas that rewrite inequalities between explicit numerals in `pnat`
-- into the corresponding inequalities in `nat`.
-- TODO: perhaps this should not be attempted by `simp`,
-- and instead we should expect `norm_num` to take care of these directly?
-- TODO: these lemmas are perhaps incomplete:
-- * 1 is not represented as a bit0 or bit1
-- * strict inequalities?
@[simp] lemma bit0_le_bit0 (n m : ℕ+) : (bit0 n) ≤ (bit0 m) ↔ (bit0 (n : ℕ)) ≤ (bit0 (m : ℕ)) :=
iff.rfl
@[simp] lemma bit0_le_bit1 (n m : ℕ+) : (bit0 n) ≤ (bit1 m) ↔ (bit0 (n : ℕ)) ≤ (bit1 (m : ℕ)) :=
iff.rfl
@[simp] lemma bit1_le_bit0 (n m : ℕ+) : (bit1 n) ≤ (bit0 m) ↔ (bit1 (n : ℕ)) ≤ (bit0 (m : ℕ)) :=
iff.rfl
@[simp] lemma bit1_le_bit1 (n m : ℕ+) : (bit1 n) ≤ (bit1 m) ↔ (bit1 (n : ℕ)) ≤ (bit1 (m : ℕ)) :=
iff.rfl
@[simp] theorem one_coe : ((1 : ℕ+) : ℕ) = 1 := rfl
@[simp] theorem mul_coe (m n : ℕ+) : ((m * n : ℕ+) : ℕ) = m * n := rfl
instance coe_mul_hom : is_monoid_hom (coe : ℕ+ → ℕ) :=
{map_one := one_coe, map_mul := mul_coe}
@[simp]
lemma coe_eq_one_iff {m : ℕ+} :
(m : ℕ) = 1 ↔ m = 1 := by { split; intro h; try { apply pnat.eq}; rw h; simp }
@[simp] lemma coe_bit0 (a : ℕ+) : ((bit0 a : ℕ+) : ℕ) = bit0 (a : ℕ) := rfl
@[simp] lemma coe_bit1 (a : ℕ+) : ((bit1 a : ℕ+) : ℕ) = bit1 (a : ℕ) := rfl
@[simp] theorem pow_coe (m : ℕ+) (n : ℕ) : ((m ^ n : ℕ+) : ℕ) = (m : ℕ) ^ n :=
by induction n with n ih;
[refl, rw [pow_succ', pow_succ, mul_coe, mul_comm, ih]]
instance : left_cancel_semigroup ℕ+ :=
{ mul_left_cancel := λ a b c h, by {
replace h := congr_arg (coe : ℕ+ → ℕ) h,
exact eq ((nat.mul_right_inj a.pos).mp h)},
.. (pnat.comm_monoid) }
instance : right_cancel_semigroup ℕ+ :=
{ mul_right_cancel := λ a b c h, by {
replace h := congr_arg (coe : ℕ+ → ℕ) h,
exact eq ((nat.mul_left_inj b.pos).mp h)},
.. (pnat.comm_monoid) }
instance : ordered_cancel_comm_monoid ℕ+ :=
{ mul_le_mul_left := by { intros, apply nat.mul_le_mul_left, assumption },
le_of_mul_le_mul_left := by { intros a b c h, apply nat.le_of_mul_le_mul_left h a.property, },
.. (pnat.left_cancel_semigroup),
.. (pnat.right_cancel_semigroup),
.. (pnat.linear_order),
.. (pnat.comm_monoid)}
instance : distrib ℕ+ :=
{ left_distrib := λ a b c, eq (mul_add a b c),
right_distrib := λ a b c, eq (add_mul a b c),
..(pnat.add_comm_semigroup), ..(pnat.comm_monoid) }
/-- Subtraction a - b is defined in the obvious way when
a > b, and by a - b = 1 if a ≤ b.
-/
instance : has_sub ℕ+ := ⟨λ a b, to_pnat' (a - b : ℕ)⟩
theorem sub_coe (a b : ℕ+) : ((a - b : ℕ+) : ℕ) = ite (b < a) (a - b : ℕ) 1 :=
begin
change ((to_pnat' ((a : ℕ) - (b : ℕ)) : ℕ)) =
ite ((a : ℕ) > (b : ℕ)) ((a : ℕ) - (b : ℕ)) 1,
split_ifs with h,
{ exact to_pnat'_coe (nat.sub_pos_of_lt h) },
{ rw [nat.sub_eq_zero_iff_le.mpr (le_of_not_gt h)], refl }
end
theorem add_sub_of_lt {a b : ℕ+} : a < b → a + (b - a) = b :=
λ h, eq $ by { rw [add_coe, sub_coe, if_pos h],
exact nat.add_sub_of_le (le_of_lt h) }
instance : has_well_founded ℕ+ := ⟨(<), measure_wf coe⟩
/-- Strong induction on `pnat`. -/
lemma strong_induction_on {p : pnat → Prop} : ∀ (n : pnat) (h : ∀ k, (∀ m, m < k → p m) → p k), p n
| n := λ IH, IH _ (λ a h, strong_induction_on a IH)
using_well_founded { dec_tac := `[assumption] }
/-- If `(n : pnat)` is different from `1`, then it is the successor of some `(k : pnat)`. -/
lemma exists_eq_succ_of_ne_one : ∀ {n : pnat} (h1 : n ≠ 1), ∃ (k : pnat), n = k + 1
| ⟨1, _⟩ h1 := false.elim $ h1 rfl
| ⟨n+2, _⟩ _ := ⟨⟨n+1, by simp⟩, rfl⟩
lemma case_strong_induction_on {p : pnat → Prop} (a : pnat) (hz : p 1)
(hi : ∀ n, (∀ m, m ≤ n → p m) → p (n + 1)) : p a :=
begin
apply strong_induction_on a,
intros k hk,
by_cases h1 : k = 1, { rwa h1 },
obtain ⟨b, rfl⟩ := exists_eq_succ_of_ne_one h1,
simp only [lt_add_one_iff] at hk,
exact hi b hk
end
/-- We define `m % k` and `m / k` in the same way as for `ℕ`
except that when `m = n * k` we take `m % k = k` and
`m / k = n - 1`. This ensures that `m % k` is always positive
and `m = (m % k) + k * (m / k)` in all cases. Later we
define a function `div_exact` which gives the usual `m / k`
in the case where `k` divides `m`.
-/
def mod_div_aux : ℕ+ → ℕ → ℕ → ℕ+ × ℕ
| k 0 q := ⟨k, q.pred⟩
| k (r + 1) q := ⟨⟨r + 1, nat.succ_pos r⟩, q⟩
lemma mod_div_aux_spec : ∀ (k : ℕ+) (r q : ℕ) (h : ¬ (r = 0 ∧ q = 0)),
(((mod_div_aux k r q).1 : ℕ) + k * (mod_div_aux k r q).2 = (r + k * q))
| k 0 0 h := (h ⟨rfl, rfl⟩).elim
| k 0 (q + 1) h := by {
change (k : ℕ) + (k : ℕ) * (q + 1).pred = 0 + (k : ℕ) * (q + 1),
rw [nat.pred_succ, nat.mul_succ, zero_add, add_comm]}
| k (r + 1) q h := rfl
/-- `mod_div m k = (m % k, m / k)`.
We define `m % k` and `m / k` in the same way as for `ℕ`
except that when `m = n * k` we take `m % k = k` and
`m / k = n - 1`. This ensures that `m % k` is always positive
and `m = (m % k) + k * (m / k)` in all cases. Later we
define a function `div_exact` which gives the usual `m / k`
in the case where `k` divides `m`.
-/
def mod_div (m k : ℕ+) : ℕ+ × ℕ := mod_div_aux k ((m : ℕ) % (k : ℕ)) ((m : ℕ) / (k : ℕ))
/-- We define `m % k` in the same way as for `ℕ`
except that when `m = n * k` we take `m % k = k` This ensures that `m % k` is always positive.
-/
def mod (m k : ℕ+) : ℕ+ := (mod_div m k).1
/-- We define `m / k` in the same way as for `ℕ` except that when `m = n * k` we take
`m / k = n - 1`. This ensures that `m = (m % k) + k * (m / k)` in all cases. Later we
define a function `div_exact` which gives the usual `m / k` in the case where `k` divides `m`.
-/
def div (m k : ℕ+) : ℕ := (mod_div m k).2
theorem mod_add_div (m k : ℕ+) : (m : ℕ) = (mod m k) + k * (div m k) :=
begin
let h₀ := nat.mod_add_div (m : ℕ) (k : ℕ),
have : ¬ ((m : ℕ) % (k : ℕ) = 0 ∧ (m : ℕ) / (k : ℕ) = 0),
by { rintro ⟨hr, hq⟩, rw [hr, hq, mul_zero, zero_add] at h₀,
exact (m.ne_zero h₀.symm).elim },
have := mod_div_aux_spec k ((m : ℕ) % (k : ℕ)) ((m : ℕ) / (k : ℕ)) this,
exact (this.trans h₀).symm,
end
theorem mod_coe (m k : ℕ+) :
((mod m k) : ℕ) = ite ((m : ℕ) % (k : ℕ) = 0) (k : ℕ) ((m : ℕ) % (k : ℕ)) :=
begin
dsimp [mod, mod_div],
cases (m : ℕ) % (k : ℕ),
{ rw [if_pos rfl], refl },
{ rw [if_neg n.succ_ne_zero], refl }
end
theorem div_coe (m k : ℕ+) :
((div m k) : ℕ) = ite ((m : ℕ) % (k : ℕ) = 0) ((m : ℕ) / (k : ℕ)).pred ((m : ℕ) / (k : ℕ)) :=
begin
dsimp [div, mod_div],
cases (m : ℕ) % (k : ℕ),
{ rw [if_pos rfl], refl },
{ rw [if_neg n.succ_ne_zero], refl }
end
theorem mod_le (m k : ℕ+) : mod m k ≤ m ∧ mod m k ≤ k :=
begin
change ((mod m k) : ℕ) ≤ (m : ℕ) ∧ ((mod m k) : ℕ) ≤ (k : ℕ),
rw [mod_coe], split_ifs,
{ have hm : (m : ℕ) > 0 := m.pos,
rw [← nat.mod_add_div (m : ℕ) (k : ℕ), h, zero_add] at hm ⊢,
by_cases h' : ((m : ℕ) / (k : ℕ)) = 0,
{ rw [h', mul_zero] at hm, exact (lt_irrefl _ hm).elim},
{ let h' := nat.mul_le_mul_left (k : ℕ)
(nat.succ_le_of_lt (nat.pos_of_ne_zero h')),
rw [mul_one] at h', exact ⟨h', le_refl (k : ℕ)⟩ } },
{ exact ⟨nat.mod_le (m : ℕ) (k : ℕ), le_of_lt (nat.mod_lt (m : ℕ) k.pos)⟩ }
end
theorem dvd_iff {k m : ℕ+} : k ∣ m ↔ (k : ℕ) ∣ (m : ℕ) :=
begin
split; intro h, rcases h with ⟨_, rfl⟩, apply dvd_mul_right,
rcases h with ⟨a, h⟩, cases a, { contrapose h, apply ne_zero, },
use a.succ, apply nat.succ_pos, rw [← coe_inj, h, mul_coe, mk_coe],
end
theorem dvd_iff' {k m : ℕ+} : k ∣ m ↔ mod m k = k :=
begin
rw dvd_iff,
rw [nat.dvd_iff_mod_eq_zero], split,
{ intro h, apply eq, rw [mod_coe, if_pos h] },
{ intro h, by_cases h' : (m : ℕ) % (k : ℕ) = 0,
{ exact h'},
{ replace h : ((mod m k) : ℕ) = (k : ℕ) := congr_arg _ h,
rw [mod_coe, if_neg h'] at h,
exact (ne_of_lt (nat.mod_lt (m : ℕ) k.pos) h).elim } }
end
lemma le_of_dvd {m n : ℕ+} : m ∣ n → m ≤ n :=
by { rw dvd_iff', intro h, rw ← h, apply (mod_le n m).left }
/-- If `h : k | m`, then `k * (div_exact m k) = m`. Note that this is not equal to `m / k`. -/
def div_exact (m k : ℕ+) : ℕ+ :=
⟨(div m k).succ, nat.succ_pos _⟩
theorem mul_div_exact {m k : ℕ+} (h : k ∣ m) : k * (div_exact m k) = m :=
begin
apply eq, rw [mul_coe],
change (k : ℕ) * (div m k).succ = m,
rw [mod_add_div m k, dvd_iff'.mp h, nat.mul_succ, add_comm],
end
theorem dvd_antisymm {m n : ℕ+} : m ∣ n → n ∣ m → m = n :=
λ hmn hnm, le_antisymm (le_of_dvd hmn) (le_of_dvd hnm)
theorem dvd_one_iff (n : ℕ+) : n ∣ 1 ↔ n = 1 :=
⟨λ h, dvd_antisymm h (one_dvd n), λ h, h.symm ▸ (dvd_refl 1)⟩
lemma pos_of_div_pos {n : ℕ+} {a : ℕ} (h : a ∣ n) : 0 < a :=
begin
apply pos_iff_ne_zero.2,
intro hzero,
rw hzero at h,
exact pnat.ne_zero n (eq_zero_of_zero_dvd h)
end
end pnat
|
59d6aa16342cbd28d8a0807129f7cf0ea9b4db81
|
618003631150032a5676f229d13a079ac875ff77
|
/src/measure_theory/category/Meas.lean
|
168195aea5b831779af6391ed539347d0fb4d2a0
|
[
"Apache-2.0"
] |
permissive
|
awainverse/mathlib
|
939b68c8486df66cfda64d327ad3d9165248c777
|
ea76bd8f3ca0a8bf0a166a06a475b10663dec44a
|
refs/heads/master
| 1,659,592,962,036
| 1,590,987,592,000
| 1,590,987,592,000
| 268,436,019
| 1
| 0
|
Apache-2.0
| 1,590,990,500,000
| 1,590,990,500,000
| null |
UTF-8
|
Lean
| false
| false
| 4,031
|
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
-/
import topology.category.Top.basic
import measure_theory.giry_monad
import category_theory.monad.algebra
/-
* Meas, the category of measurable spaces
Measurable spaces and measurable functions form a (concrete) category Meas.
Measure : Meas ⥤ Meas is the functor which sends a measurable space X
to the space of measures on X; it is a monad (the "Giry monad").
Borel : Top ⥤ Meas sends a topological space X to X equipped with the
σ-algebra of Borel sets (the σ-algebra generated by the open subsets of X).
## Tags
measurable space, giry monad, borel
-/
noncomputable theory
open category_theory measure_theory
universes u v
@[reducible] def Meas : Type (u+1) := bundled measurable_space
namespace Meas
instance (X : Meas) : measurable_space X := X.str
/-- Construct a bundled `Meas` from the underlying type and the typeclass. -/
def of (α : Type u) [measurable_space α] : Meas := ⟨α⟩
instance unbundled_hom : unbundled_hom @measurable := ⟨@measurable_id, @measurable.comp⟩
/-- `Measure X` is the measurable space of measures over the measurable space `X`. It is the
weakest measurable space, s.t. λμ, μ s is measurable for all measurable sets `s` in `X`. An
important purpose is to assign a monadic structure on it, the Giry monad. In the Giry monad,
the pure values are the Dirac measure, and the bind operation maps to the integral:
`(μ >>= ν) s = ∫ x. (ν x) s dμ`.
In probability theory, the `Meas`-morphisms `X → Prob X` are (sub-)Markov kernels (here `Prob` is
the restriction of `Measure` to (sub-)probability space.)
-/
def Measure : Meas ⥤ Meas :=
{ obj := λX, ⟨@measure_theory.measure X.1 X.2⟩,
map := λX Y f, ⟨measure.map f, measure.measurable_map f f.2⟩,
map_id' := assume ⟨α, I⟩, subtype.eq $ funext $ assume μ, @measure.map_id α I μ,
map_comp':=
assume X Y Z ⟨f, hf⟩ ⟨g, hg⟩, subtype.eq $ funext $ assume μ, (measure.map_map hg hf).symm }
/-- The Giry monad, i.e. the monadic structure associated with `Measure`. -/
instance : category_theory.monad Measure.{u} :=
{ η :=
{ app := λX, ⟨@measure.dirac X.1 X.2, measure.measurable_dirac⟩,
naturality' :=
assume X Y ⟨f, hf⟩, subtype.eq $ funext $ assume a, (measure.map_dirac hf a).symm },
μ :=
{ app := λX, ⟨@measure.join X.1 X.2, measure.measurable_join⟩,
naturality' :=
assume X Y ⟨f, hf⟩, subtype.eq $ funext $ assume μ, measure.join_map_map hf μ },
assoc' := assume ⟨α, I⟩, subtype.eq $ funext $ assume μ, @measure.join_map_join α I μ,
left_unit' := assume ⟨α, I⟩, subtype.eq $ funext $ assume μ, @measure.join_dirac α I μ,
right_unit' := assume ⟨α, I⟩, subtype.eq $ funext $ assume μ, @measure.join_map_dirac α I μ }
/-- An example for an algebra on `Measure`: the nonnegative Lebesgue integral is a hom, behaving
nicely under the monad operations. -/
def Integral : monad.algebra Measure :=
{ A := Meas.of ennreal ,
a := ⟨ λm:measure ennreal, m.integral id, measure.measurable_integral _ measurable_id ⟩,
unit' := subtype.eq $ funext $ assume r:ennreal, measure.integral_dirac _ measurable_id,
assoc' := subtype.eq $ funext $ assume μ : measure (measure ennreal),
show μ.join.integral id = measure.integral (μ.map (λm:measure ennreal, m.integral id)) id, from
begin
rw [measure.integral_join measurable_id, measure.integral_map measurable_id],
refl,
exact measure.measurable_integral _ measurable_id
end }
end Meas
instance Top.has_forget_to_Meas : has_forget₂ Top.{u} Meas.{u} :=
bundled_hom.mk_has_forget₂
borel
(λ X Y f, ⟨f.1, f.2.borel_measurable⟩)
(by intros; refl)
/-- The Borel functor, the canonical embedding of topological spaces into measurable spaces. -/
@[reducible] def Borel : Top.{u} ⥤ Meas.{u} := forget₂ Top.{u} Meas.{u}
|
4a06466253610062da9b1c7ddf133a8f83eddda3
|
1446f520c1db37e157b631385707cc28a17a595e
|
/stage0/src/Init/Lean/Util.lean
|
3b439978df83f88de43dae1ea8531c24ef56cd29
|
[
"Apache-2.0"
] |
permissive
|
bdbabiak/lean4
|
cab06b8a2606d99a168dd279efdd404edb4e825a
|
3f4d0d78b2ce3ef541cb643bbe21496bd6b057ac
|
refs/heads/master
| 1,615,045,275,530
| 1,583,793,696,000
| 1,583,793,696,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 640
|
lean
|
/-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Lean.Util.CollectFVars
import Init.Lean.Util.CollectLevelParams
import Init.Lean.Util.CollectMVars
import Init.Lean.Util.FindMVar
import Init.Lean.Util.MonadCache
import Init.Lean.Util.PPExt
import Init.Lean.Util.PPGoal
import Init.Lean.Util.Path
import Init.Lean.Util.Profile
import Init.Lean.Util.RecDepth
import Init.Lean.Util.Sorry
import Init.Lean.Util.Trace
import Init.Lean.Util.WHNF
import Init.Lean.Util.FindExpr
import Init.Lean.Util.ReplaceExpr
|
7263e9a7d146d3124bdcb4a39c328c4952d7dacc
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/src/Lean/Elab/RecAppSyntax.lean
|
f482029aad75a39c99328460808a134c231da916
|
[
"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
| 829
|
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.Expr
namespace Lean
private def recAppKey := `_recApp
/--
We store the syntax at recursive applications to be able to generate better error messages
when performing well-founded and structural recursion.
-/
def mkRecAppWithSyntax (e : Expr) (stx : Syntax) : Expr :=
mkMData (KVMap.empty.insert recAppKey (DataValue.ofSyntax stx)) e
/--
Retrieve (if available) the syntax object attached to a recursive application.
-/
def getRecAppSyntax? (e : Expr) : Option Syntax :=
match e with
| Expr.mdata d _ =>
match d.find recAppKey with
| some (DataValue.ofSyntax stx) => some stx
| _ => none
| _ => none
end Lean
|
d3b66b8f81aad0457d28350858803efe72fda76c
|
2a73ce8bc0731b170b40e8c9faca9b49d34ba5c6
|
/weak_convergence_of_measures.lean
|
eed91da296b79134e79b19174882b2571de61572
|
[] |
no_license
|
kkytola/lean-questions
|
f383016b7870432807d8f4ced256f7506a59b0ff
|
9a7ded8036534575b682e28ddfed4c2f1089959d
|
refs/heads/main
| 1,692,989,428,439
| 1,634,665,853,000
| 1,634,665,853,000
| 353,850,251
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 30,078
|
lean
|
/-
Copyright (c) 2021 Kalle Kytölä. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kalle Kytölä
-/
import tactic
import weak_dual
import measure_theory.integral.bochner
noncomputable theory
open measure_theory
open set
open filter
open_locale topological_space bounded_continuous_function ennreal nnreal
section finite_measures
/-!
### Finite measures
In this section, we define the `Type` of finite measures on a given measurable space. This type
will be equipped with the topology of weak convergence of measures when the measurable space is
a topological space equipped with its Borel sigma-algebra.
-/
variables {α : Type} [measurable_space α]
/-- Finite measures are defined as the subtype of measures that have the property of being finite
measures (i.e., their total mass is finite). -/
def finite_measures (α : Type*) [measurable_space α] : Type :=
{ μ : measure α // finite_measure μ }
namespace finite_measures
instance has_zero {α : Type*} [measurable_space α] :
has_zero (finite_measures α) :=
⟨{ val := 0,
property := measure_theory.finite_measure_zero, }⟩
instance finite_measure_add {α : Type*} [measurable_space α]
(μ ν : measure α) [finite_measure μ] [finite_measure ν] :
finite_measure (μ + ν) :=
{ measure_univ_lt_top := begin
simp only [measure.coe_add, pi.add_apply, ennreal.add_lt_top],
exact ⟨measure_lt_top μ univ, measure_lt_top ν univ⟩,
end, }
instance {α : Type*} [measurable_space α] : has_add (finite_measures α) :=
{ add := (λ (μ ν : finite_measures α),
{ val := μ.val + ν.val,
property := @finite_measures.finite_measure_add _ _ _ _ μ.prop ν.prop, }), }
instance : inhabited (finite_measures α) := { default := 0 }
/-- A finite measure can be interpreted as a measure. -/
def to_measure (μ : finite_measures α) : (measure_theory.measure α) := subtype.val μ
instance to_measure.finite_measure (μ : finite_measures α) :
finite_measure μ.to_measure := μ.prop
instance (α : Type*) [measurable_space α] :
has_coe_to_fun (finite_measures α) := ⟨(λ _, set α → ℝ≥0),
(λ μ, (λ s, (μ.val.measure_of s).to_nnreal))⟩
lemma to_fun_eq_to_measure_to_nnreal (ν : finite_measures α) :
(ν : set α → ℝ≥0) = λ s, (ν.to_measure s).to_nnreal := rfl
lemma to_measure_eq_val (ν : finite_measures α) : ν.to_measure = ν.val := rfl
lemma to_measure_injective :
function.injective (@finite_measures.to_measure α ‹measurable_space α›) :=
by { intros μ ν, exact subtype.eq, }
lemma to_measure_zero :
(@finite_measures.to_measure α ‹measurable_space α›) 0 = 0 := rfl
lemma to_measure_add (μ ν : finite_measures α) :
μ.to_measure + ν.to_measure = (μ + ν).to_measure := rfl
/-- The (total) mass of a finite measure `μ` is `μ univ`, i.e., the cast to `nnreal` of
`μ.to_measure univ`. -/
def mass {α : Type*} [measurable_space α] (μ : finite_measures α) : ℝ≥0 := μ univ
lemma mass_def {α : Type*} [measurable_space α] {μ : finite_measures α} :
μ.mass = μ univ := rfl
@[simp] lemma mass_ennreal {α : Type*} [measurable_space α]
{μ : finite_measures α} : (μ.mass : ℝ≥0∞) = μ.to_measure univ :=
begin
apply ennreal.coe_to_nnreal,
exact ennreal.lt_top_iff_ne_top.mp (μ.prop).measure_univ_lt_top,
end
instance {α : Type*} [measurable_space α] :
add_comm_monoid (finite_measures α) :=
(@finite_measures.to_measure_injective α ‹measurable_space α›).add_comm_monoid
(@finite_measures.to_measure α ‹measurable_space α›)
finite_measures.to_measure_zero finite_measures.to_measure_add
--TODO: Make `finite_measures α` an `ℝ≥0`-module, so that it makes sense (later)
-- to define a continuous linear map `finite_measures α → weak_dual ℝ≥0 (α →ᵇ ℝ≥0)`.
--instance finite_measures.module : module ℝ≥0 (finite_measures α) := sorry
end finite_measures -- end namespace
end finite_measures -- end section
section probability_measures
/-!
### Probability measures
In this section, we define the `Type` of probability measures on a given measurable space. This
type will be equipped with the topology of weak convergence of measures when the measurable space
is a topological space equipped with its Borel sigma-algebra.
There is a coercion (embedding) to finite measures on the same space.
-/
variables {α : Type} [measurable_space α]
/-- Probability measures are defined as the subtype of measures that have the property of being
probability measures (i.e., their total mass is one). -/
def probability_measures (α : Type) [measurable_space α] : Type :=
{μ : measure α // probability_measure μ}
namespace probability_measures
instance [inhabited α] : inhabited (probability_measures α) :=
⟨{ val := measure_theory.measure.dirac (default α),
property := measure_theory.measure.dirac.probability_measure, }⟩
/-- A probability measure can be interpreted as a measure. -/
def to_measure (μ : probability_measures α) : (measure_theory.measure α) := μ.val
instance to_measure.probability_measure (μ : probability_measures α) :
probability_measure μ.to_measure := μ.prop
instance (α : Type*) [measurable_space α] :
has_coe_to_fun (probability_measures α) := ⟨(λ _, set α → ℝ≥0),
(λ μ, (λ s, (μ.val.measure_of s).to_nnreal))⟩
lemma to_fun_eq_to_measure_to_nnreal (ν : probability_measures α) :
(ν : set α → ℝ≥0) = λ s, (ν.to_measure s).to_nnreal := rfl
@[simp]
lemma to_fun_univ (ν : probability_measures α) : ν univ = 1 :=
begin
rw [to_fun_eq_to_measure_to_nnreal, ←ennreal.one_to_nnreal],
exact congr_arg ennreal.to_nnreal ν.prop.measure_univ,
end
lemma to_measure_eq_val (ν : probability_measures α) : ν.to_measure = ν.val := rfl
lemma to_measure_injective :
function.injective (@probability_measures.to_measure α ‹measurable_space α›) :=
by { intros μ ν, exact subtype.eq, }
instance has_coe_to_finite_measures (α : Type*) [measurable_space α] :
has_coe (probability_measures α) (finite_measures α) :=
{ coe := λ μ , { val := μ.val,
property := begin
have key : (1 : ennreal) < ⊤ := ennreal.one_lt_top,
rw [←μ.prop.measure_univ] at key,
exact ⟨key⟩,
end, }}
/-- A probability measure can be interpreted as a finite measure. -/
def to_finite_measure (μ : probability_measures α) : (finite_measures α) := μ
@[simp]
lemma to_finite_measure_to_measure_eq_to_measure (ν : probability_measures α) :
(ν.to_finite_measure).to_measure = ν.to_measure := rfl
lemma to_finite_measure_to_measure_eq_val (ν : probability_measures α) :
(ν.to_finite_measure).to_measure = ν.val := rfl
@[simp]
lemma to_finite_measure_to_fun_eq_to_fun (ν : probability_measures α) :
(ν.to_finite_measure : set α → ℝ≥0) = (ν : set α → ℝ≥0) := rfl
@[simp]
lemma to_finite_measure_mass (μ : probability_measures α) :
μ.to_finite_measure.mass = 1 :=
begin
unfold finite_measures.mass,
rw [←μ.to_fun_univ, to_finite_measure_to_fun_eq_to_fun],
end
end probability_measures -- end namespace
end probability_measures -- end section
section various_lemmas
-- NOTE: Eh, what is the right way to do this `nnreal_mul_ennreal_to_nnreal`?
-- If this deserves to be added, then perhaps in `data.real.ennreal`?
-- It seems like a typical coercion issue to me, although it is only used once here.
lemma nnreal_mul_ennreal_to_nnreal (c : ℝ≥0) (z : ℝ≥0∞) :
c * z.to_nnreal = ((c : ℝ≥0∞) * z).to_nnreal :=
begin
by_cases z_infty : z = ⊤,
{ rw z_infty,
simp only [ennreal.top_to_nnreal, ennreal.to_nnreal_mul_top, mul_zero], },
{ have z_lt_top : z < ⊤ := ennreal.lt_top_iff_ne_top.mpr z_infty,
simp only [ennreal.to_nnreal_mul, ennreal.to_nnreal_coe], },
end
-- NOTE: I have been almost wondering why the following is not the definition of
-- boundedness. I have not found it in the library, but believe it should be there.
-- Is `topology.continuous_function.bounded` the appropriate place? The proof needs golf, though.
lemma bounded_continuous_function.radius_bounded {α β : Type*}
[topological_space α] [metric_space β] (f : α →ᵇ β) (z : β):
∃ (c : ℝ), ∀ (a : α), dist z (f(a)) ≤ c :=
begin
cases f.bounded with c hc ,
by_cases is_empty α,
{ use 0, intros a, exfalso, exact is_empty_iff.mp h a, },
cases not_is_empty_iff.mp h with a₀,
use (dist z (f(a₀))) + c,
intros a,
have le : ∀ (y : ℝ), y + (dist (f(a₀)) (f(a))) ≤ y + c := λ y, add_le_add rfl.ge (hc a₀ a),
exact (dist_triangle z (f(a₀)) (f(a))).trans (le _),
end
-- NOTE: The following is a "special case" of the above. I think it is also worthwhile, although
-- it is not needed in this file. If it should be added, what is the right place?
lemma bounded_continuous_function.norm_bounded {α β : Type*}
[topological_space α] [normed_group β] (f : α →ᵇ β) :
∃ (c : ℝ), ∀ x, ∥ f x ∥ ≤ c :=
begin
have norm_eq_dist : ∀ (z : β), ∥ z ∥ = dist 0 z := λ z, congr_fun (dist_zero_left).symm z,
simp_rw [norm_eq_dist],
exact bounded_continuous_function.radius_bounded f 0,
end
-- NOTE: The following is another "special case". While special, I think it may be worthwhile.
-- If so, what is the right place? How to golf?
lemma bounded_continuous_function.nnreal.upper_bound {α : Type*} [topological_space α]
(f : α →ᵇ ℝ≥0) : ∃ (c : nnreal), (∀ x, f(x) ≤ c) :=
begin
have val_eq_dist_nnreal : ∀ (z : ℝ≥0), (z : ℝ) = dist 0 z,
{ intros z,
simp only [nnreal.dist_eq, nnreal.coe_zero, zero_sub, nnreal.abs_eq, abs_neg], },
cases bounded_continuous_function.radius_bounded f 0 with c hc,
simp_rw ←val_eq_dist_nnreal at hc,
use (max c 0).to_nnreal,
intros x,
apply (@real.le_to_nnreal_iff_coe_le (f x) _ (le_max_right c 0)).mpr,
apply (hc x).trans (le_max_left c 0),
end
-- NOTE: This one is not actually needed in the current version with nonnegative test functions.
-- It will be needed later. If this doesn't exist yet, then after golfing the proof, this might
-- be appropriate in `measure_theory.function.L1_space` (not in
-- `topology.continuous_function.bounded` because of imports?).
lemma bounded_continuous_function.integrable {α β: Type}
[topological_space α] [measurable_space α] [opens_measurable_space α]
[normed_group β] [measurable_space β] [borel_space β]
(μ : measure α) [finite_measure μ] (f : α →ᵇ β) : integrable f μ :=
begin
set f' := ennreal.of_real ∘ norm ∘ f with hf' ,
suffices : lintegral μ f' < ⊤ ,
{ have ae_mble : @ae_measurable α β ‹measurable_space β› ‹measurable_space α› f μ
:= continuous.ae_measurable f.continuous μ,
exact ⟨ ae_mble , (has_finite_integral_iff_norm f).mpr this ⟩, } ,
have bdd : ∀ (x : α), f' x ≤ ennreal.of_real (∥ f ∥) ,
{ intros x,
exact ennreal.of_real_le_of_real (bounded_continuous_function.norm_coe_le_norm f x), },
have integr_bdd := @lintegral_mono α _ μ _ _ bdd,
set c' := ennreal.of_real (∥ f ∥) with hc',
have const_integr : lintegral μ (λ x , c') = c' * (μ(univ)) := by rw lintegral_const,
have total : c' * (μ(univ)) < ⊤,
{ apply ennreal.mul_lt_top ennreal.of_real_lt_top
(‹finite_measure μ›).measure_univ_lt_top, },
rw ← const_integr at total,
exact lt_of_le_of_lt integr_bdd total,
end
-- NOTE: I believe this is useful, but what is the right place?
-- `measure_theory.function.L1_space`? `topology.continuous_function.bounded`?
lemma bounded_continuous_function.coe_nnreal_comp_measurable {α : Type*} [topological_space α]
[measurable_space α] [opens_measurable_space α] (f : α →ᵇ ℝ≥0) :
measurable ((coe : ℝ≥0 → ℝ≥0∞) ∘ f) :=
measurable.comp measurable_coe_nnreal_ennreal (continuous.measurable f.continuous)
-- NOTE: The following is probably too special for anywhere else, but is a useful standalone
-- lemma here.
lemma lintegral_lt_top_of_bounded_continuous_to_nnreal {α : Type*} [topological_space α]
[measurable_space α] (μ : measure α) [μ_fin : finite_measure μ] (f : α →ᵇ ℝ≥0) :
lintegral μ ((coe : ℝ≥0 → ℝ≥0∞) ∘ f) < ⊤ :=
begin
cases bounded_continuous_function.nnreal.upper_bound f with c hc,
have le' : (coe : ℝ≥0 → ℝ≥0∞) ∘ f ≤ (λ (x : α), c),
by { intros x, simp only [hc, ennreal.coe_le_coe], },
apply lt_of_le_of_lt (@lintegral_mono _ _ μ _ _ le'),
rw lintegral_const,
exact ennreal.mul_lt_top ennreal.coe_lt_top μ_fin.measure_univ_lt_top,
end
-- TODO: What to do with this? Hmm... I've ended up using it quite regularly in the definitions
-- of certain topologies.
lemma tendsto_induced_iff {α β γ : Type*} {F : filter γ} [topological_space β]
{f : α → β} {xs : γ → α} {x : α} :
tendsto xs F (@nhds α (topological_space.induced f infer_instance) x) ↔
tendsto (λ i, f(xs(i))) F (𝓝 (f(x))) :=
begin
split,
{ intros conv_induced,
have f_cont := @continuous_induced_dom α β f infer_instance,
have key := @continuous.tendsto α β
(topological_space.induced f infer_instance) infer_instance f f_cont,
exact tendsto.comp (key x) conv_induced, },
{ intros conv_image,
rw nhds_induced,
exact map_le_iff_le_comap.mp conv_image, },
end
end various_lemmas
section weak_convergence_of_measures
/-!
### The topology of weak convergence of measures
In this section, we define the topology of weak convergence on the set of Borel probability
measures and on the set of finite Borel measures on a topological space.
-/
/- NOTE / TODO:
The pairing of measures with test functions are called `test_against_nn` since the test functions
are taken to be `ℝ≥0`-valued in the definition of the topology (this allows us to use the Lebesgue
integral `lintegral`, but requires some coercions). It seems natural to later add `test_against`
for pairings via Bochner integrals (`integral`) with (bounded continuous) functions with values
in an arbitrary Banach spaces, especially with values in `ℝ` and `ℂ`. -/
variables {α : Type} [measurable_space α] [topological_space α]
/-- The pairing of a (Borel) probability measure `μ` with a nonnegative bounded continuous
function is obtained by (Lebesgue) integrating the (test) function against the measure. This
is `probability_measures.test_against'`. -/
abbreviation probability_measures.test_against_nn
(μ : probability_measures α) (f : α →ᵇ nnreal) : ℝ≥0 :=
(lintegral μ.to_measure ((coe : ℝ≥0 → ℝ≥0∞) ∘ f)).to_nnreal
lemma probability_measures.test_against_nn_def (μ : probability_measures α) {f : α →ᵇ nnreal} :
μ.test_against_nn f = (lintegral μ.to_measure ((coe : ℝ≥0 → ℝ≥0∞) ∘ f)).to_nnreal := by refl
/-- The pairing of a finite (Borel) measure `μ` with a nonnegative bounded continuous
function is obtained by (Lebesgue) integrating the (test) function against the measure. This
is `finite_measures.test_against'`. -/
abbreviation finite_measures.test_against_nn
(μ : finite_measures α) (f : α →ᵇ nnreal) : ℝ≥0 :=
(lintegral μ.to_measure ((coe : ℝ≥0 → ℝ≥0∞) ∘ f)).to_nnreal
lemma finite_measures.test_against_nn_def (μ : finite_measures α) {f : α →ᵇ nnreal} :
μ.test_against_nn f = (lintegral μ.to_measure ((coe : ℝ≥0 → ℝ≥0∞) ∘ f)).to_nnreal := by refl
lemma finite_measures.test_against_nn_coe_eq {μ : finite_measures α} {f : α →ᵇ nnreal} :
(μ.test_against_nn f : ℝ≥0∞) = lintegral μ.to_measure ((coe : ℝ≥0 → ℝ≥0∞) ∘ f) :=
begin
have key_lt := lintegral_lt_top_of_bounded_continuous_to_nnreal μ.to_measure f,
exact ennreal.coe_to_nnreal (ennreal.lt_top_iff_ne_top.mp key_lt),
end
lemma probability_measures.test_against_nn_coe_eq {μ : probability_measures α} {f : α →ᵇ nnreal} :
(μ.test_against_nn f : ℝ≥0∞) = lintegral μ.to_measure ((coe : ℝ≥0 → ℝ≥0∞) ∘ f) :=
begin
have key_lt := lintegral_lt_top_of_bounded_continuous_to_nnreal μ.to_measure f,
exact ennreal.coe_to_nnreal (ennreal.lt_top_iff_ne_top.mp key_lt),
end
@[simp]
lemma probability_measures.to_finite_measure_test_against_nn_eq_test_against_nn (α : Type*)
[measurable_space α] [topological_space α] {μ : probability_measures α} {f : α →ᵇ nnreal} :
μ.to_finite_measure.test_against_nn f = μ.test_against_nn f := rfl
lemma finite_measures.test_against_nn_const (μ : finite_measures α) (c : ℝ≥0) :
μ.test_against_nn (bounded_continuous_function.const α c) = c * μ.mass :=
begin
rw finite_measures.test_against_nn_def,
have eq : (coe : ℝ≥0 → ℝ≥0∞) ∘ (bounded_continuous_function.const α c) = (λ x, (c : ennreal)),
by refl,
rw [eq, lintegral_const, ennreal.to_nnreal_mul],
simp only [mul_eq_mul_left_iff, ennreal.to_nnreal_coe, finite_measures.mass_def],
left,
refl,
end
lemma probability_measures.test_against_nn_const (μ : probability_measures α) (c : ℝ≥0) :
μ.test_against_nn (bounded_continuous_function.const α c) = c :=
begin
have key := finite_measures.test_against_nn_const μ.to_finite_measure c,
simp only [mul_one, probability_measures.to_finite_measure_mass] at key,
exact key,
end
lemma finite_measures.test_against_nn_mono (μ : finite_measures α)
{f g : α →ᵇ ℝ≥0} (f_le_g : (f : α → ℝ≥0) ≤ g) :
μ.test_against_nn f ≤ μ.test_against_nn g :=
begin
repeat { rw finite_measures.test_against_nn_def, },
apply ennreal.coe_le_coe.mp,
repeat { rw ennreal.coe_to_nnreal, },
{ apply lintegral_mono,
intros x,
apply ennreal.coe_mono,
exact f_le_g x, },
repeat { apply ennreal.lt_top_iff_ne_top.mp,
apply lintegral_lt_top_of_bounded_continuous_to_nnreal, },
end
lemma probability_measures.test_against_nn_mono (μ : probability_measures α)
{f g : α →ᵇ ℝ≥0} (f_le_g : (f : α → ℝ≥0) ≤ g) :
μ.test_against_nn f ≤ μ.test_against_nn g :=
begin
have key := finite_measures.test_against_nn_mono μ.to_finite_measure f_le_g,
simp only [probability_measures.to_finite_measure_test_against_nn_eq_test_against_nn] at key,
exact key,
end
lemma continuous_bounded_nn_add_comp_coe {β : Type*} [topological_space β] {f₁ f₂ : β →ᵇ ℝ≥0} :
(coe : ℝ≥0 → ℝ≥0∞) ∘ (f₁ + f₂) = ( ((coe : ℝ≥0 → ℝ≥0∞) ∘ f₁) + ((coe : ℝ≥0 → ℝ≥0∞) ∘ f₂)) :=
by { funext x, simp only [ennreal.coe_add, pi.add_apply, function.comp_app], }
lemma continuous_bounded_nn_smul_comp_coe {β : Type*} [topological_space β] {c : ℝ≥0}
{f : β →ᵇ ℝ≥0} :
(coe : ℝ≥0 → ℝ≥0∞) ∘ (c • f) = c • ( ((coe : ℝ≥0 → ℝ≥0∞) ∘ f)) :=
begin
funext x,
simpa only [algebra.id.smul_eq_mul, function.comp_app, pi.smul_apply, ennreal.coe_mul],
end
lemma continuous_bounded_nn_smul_eq {β : Type*} [topological_space β] {c : ℝ≥0} {f : β →ᵇ ℝ≥0} :
(c • (f : β → ℝ≥0)) = ((c • f) : β →ᵇ ℝ≥0) := by refl
lemma continuous_bounded_nn_smul_comp_coe' {β : Type*} [topological_space β] {c : ℝ≥0} {f : β →ᵇ ℝ≥0} :
(coe : ℝ≥0 → ℝ≥0∞) ∘ (c • f) = c • ( ((coe : ℝ≥0 → ℝ≥0∞) ∘ f)) :=
begin
funext x,
simpa only [algebra.id.smul_eq_mul, function.comp_app, pi.smul_apply, ennreal.coe_mul],
end
variables [opens_measurable_space α] -- [borel_space α]
lemma finite_measures.test_against_nn_add (μ : finite_measures α) (f₁ f₂ : α →ᵇ ℝ≥0) :
μ.test_against_nn (f₁ + f₂) = μ.test_against_nn f₁ + μ.test_against_nn f₂ :=
begin
rw ← ennreal.to_nnreal_add
(lintegral_lt_top_of_bounded_continuous_to_nnreal μ.to_measure f₁)
(lintegral_lt_top_of_bounded_continuous_to_nnreal μ.to_measure f₂),
rw ← @lintegral_add _ _ μ.to_measure _ _
f₁.coe_nnreal_comp_measurable f₂.coe_nnreal_comp_measurable,
refl,
end
lemma finite_measures.test_against_nn_smul (μ : finite_measures α) (c : ℝ≥0) (f : α →ᵇ ℝ≥0) :
μ.test_against_nn (c • f) = c * μ.test_against_nn f :=
begin
have key_smul := @lintegral_mul_const _ _ μ.to_measure c _ f.coe_nnreal_comp_measurable,
simp_rw mul_comm at key_smul,
repeat { rw finite_measures.test_against_nn_def, },
rw [nnreal_mul_ennreal_to_nnreal, ←key_smul],
rw [←continuous_bounded_nn_smul_eq, @continuous_bounded_nn_smul_comp_coe _ _ c f],
refl,
end
/-- Integration against a finite_measure defines a linear map from nonnegative bounded continuous
functions to nonnegative real numbers. -/
def finite_measures.test_against_nn_linear_map (μ : finite_measures α) :
linear_map ℝ≥0 (α →ᵇ ℝ≥0) ℝ≥0 :=
{ to_fun := μ.test_against_nn,
map_add' := finite_measures.test_against_nn_add μ,
map_smul' := finite_measures.test_against_nn_smul μ, }
lemma nnreal.le_add_dist (a b : ℝ≥0) : a ≤ b + (dist a b).to_nnreal :=
begin
suffices : (a : ℝ) ≤ (b : ℝ) + (dist a b),
{ have coe_eq : (coe : ℝ≥0 → ℝ) (b + (dist a b).to_nnreal) = (b : ℝ) + dist a b,
{ rw nnreal.coe_add,
simp only [real.coe_to_nnreal', max_eq_left_iff, add_right_inj],
exact dist_nonneg, },
rw ←coe_eq at this,
apply nnreal.coe_le_coe.mp this, },
have key : abs (a-b : ℝ) ≤ (dist a b) := by refl,
linarith [le_of_abs_le key],
end
lemma finite_measures.lipschitz_estimate (μ : finite_measures α) (f g : α →ᵇ ℝ≥0) :
μ.test_against_nn f ≤ μ.test_against_nn g + (dist f g).to_nnreal * μ.mass :=
begin
have coe_eq : ennreal.of_real (dist f g) = ((dist f g).to_nnreal : ℝ≥0∞) := by refl,
rw ←finite_measures.test_against_nn_const μ (dist f g).to_nnreal,
rw ←finite_measures.test_against_nn_add,
repeat { rw finite_measures.test_against_nn_def, },
apply ennreal.coe_le_coe.mp,
repeat { rw ennreal.coe_to_nnreal, },
{ apply lintegral_mono,
have le_dist : ∀ x, dist (f x) (g x) ≤ (dist f g)
:= bounded_continuous_function.dist_coe_le_dist,
have le' : ∀ x, f(x) ≤ g(x) + (dist f g).to_nnreal,
{ intros x,
apply (nnreal.le_add_dist (f x) (g x)).trans,
rw add_le_add_iff_left,
exact real.to_nnreal_mono (le_dist x), },
have le : ∀ x, (f(x) : ℝ≥0∞) ≤ (g(x) : ℝ≥0∞) + ennreal.of_real (dist f g),
{ intros x,
rw [coe_eq, ←ennreal.coe_add],
exact ennreal.coe_mono (le' x), },
exact le, },
repeat { apply ennreal.lt_top_iff_ne_top.mp,
apply lintegral_lt_top_of_bounded_continuous_to_nnreal, },
end
lemma finite_measures.test_against_nn_lipschitz (μ : finite_measures α) :
lipschitz_with μ.mass μ.test_against_nn :=
begin
rw lipschitz_with_iff_dist_le_mul,
intros f₁ f₂,
suffices : abs (μ.test_against_nn f₁ - μ.test_against_nn f₂ : ℝ) ≤ μ.mass * (dist f₁ f₂),
{ rwa nnreal.dist_eq, },
apply (@abs_le ℝ _ _ _ _ _).mpr,
split,
{ have key' := μ.lipschitz_estimate f₂ f₁,
rw mul_comm at key',
suffices : ↑(μ.test_against_nn f₂) ≤ ↑(μ.test_against_nn f₁) + ↑(μ.mass) * dist f₁ f₂,
{ linarith, },
have key := nnreal.coe_mono key',
rwa [nnreal.coe_add, nnreal.coe_mul, real.coe_to_nnreal, dist_comm] at key,
exact dist_nonneg, },
{ have key' := μ.lipschitz_estimate f₁ f₂,
rw mul_comm at key',
suffices : ↑(μ.test_against_nn f₁) ≤ ↑(μ.test_against_nn f₂) + ↑(μ.mass) * dist f₁ f₂,
{ linarith, },
have key := nnreal.coe_mono key',
rwa [nnreal.coe_add, nnreal.coe_mul, real.coe_to_nnreal] at key,
exact dist_nonneg, },
end
lemma probability_measures.test_against_nn_lipschitz (μ : probability_measures α) :
lipschitz_with 1 μ.test_against_nn :=
begin
have key := μ.to_finite_measure.test_against_nn_lipschitz,
rwa μ.to_finite_measure_mass at key,
end
/-- A finite measure can be interpreted as an element of the (weak) dual of nonnegative
bounded continuous functions, the duality pairing being integration. -/
def finite_measures.to_weak_dual_of_bcnn (μ : finite_measures α) :
weak_dual ℝ≥0 (α →ᵇ ℝ≥0) :=
{ to_fun := μ.test_against_nn,
map_add' := finite_measures.test_against_nn_add μ,
map_smul' := finite_measures.test_against_nn_smul μ,
cont := μ.test_against_nn_lipschitz.continuous, }
/-
--TODO: Need `ℝ≥0`-module structure on `finite_measures α`.
-- Currently only `add_comm_monoid` is implemented.
def finite_measures.to_weak_dual_of_bounded_continuous_nn :
finite_measures α →L[ℝ≥0] weak_dual ℝ≥0 (α →ᵇ ℝ≥0) := sorry
-/
/-- A probability measure can be interpreted as an element of the (weak) dual of nonnegative
bounded continuous functions (random variables), the duality pairing being integration (expected
value). -/
def probability_measures.to_weak_dual_of_bcnn (μ : probability_measures α) :
weak_dual ℝ≥0 (α →ᵇ ℝ≥0) :=
{ to_fun := μ.test_against_nn,
map_add' := μ.to_finite_measure.test_against_nn_add,
map_smul' := μ.to_finite_measure.test_against_nn_smul,
cont := μ.test_against_nn_lipschitz.continuous, }
lemma finite_measures.test_against_eq_to_weak_dual_test (μ : finite_measures α) :
(μ.to_weak_dual_of_bcnn : (α →ᵇ ℝ≥0) → ℝ≥0) = μ.test_against_nn := by refl
lemma probability_measures.test_against_eq_to_weak_dual_test (μ : probability_measures α) :
(μ.to_weak_dual_of_bcnn : (α →ᵇ ℝ≥0) → ℝ≥0) = μ.test_against_nn := by refl
/-- The topology of weak convergence on `finite_measures α` is inherited (induced) from the weak-*
topology on `weak_dual ℝ≥0 (α →ᵇ ℝ≥0)` via the function `finite_measures.to_weak_dual_of_bcnn`. -/
instance : topological_space (finite_measures α) :=
topological_space.induced
(λ (μ : finite_measures α), μ.to_weak_dual_of_bcnn) infer_instance
/-- The topology of weak convergence on `probability_measures α`. This is inherited (induced) from
the weak-* topology on `weak_dual ℝ≥0 (α →ᵇ ℝ≥0)` via the function
`probability_measures.to_weak_dual_of_bcnn`. -/
instance : topological_space (probability_measures α) :=
topological_space.induced
(λ (μ : probability_measures α), μ.to_weak_dual_of_bcnn) infer_instance
/- Integration of (nonnegative bounded continuous) test functions against finite Borel measures
depends continuously on the measure. -/
lemma finite_measures.to_weak_dual_continuous :
continuous (@finite_measures.to_weak_dual_of_bcnn α _ _ _) :=
continuous_induced_dom
/- Integration of (nonnegative bounded continuous) test functions against Borel probability
measures depends continuously on the measure. -/
lemma probability_measures.to_weak_dual_continuous :
continuous (@probability_measures.to_weak_dual_of_bcnn α _ _ _) :=
continuous_induced_dom
/- The canonical mapping from probability measures to finite measures is an embedding. -/
lemma probability_measures.coe_embedding (α : Type*)
[measurable_space α] [topological_space α] [opens_measurable_space α] :
embedding (coe : probability_measures α → finite_measures α) :=
{ induced := begin
have key := @induced_compose (probability_measures α) (finite_measures α) _ _ coe
(@finite_measures.to_weak_dual_of_bcnn α _ _ _),
exact key.symm,
end,
inj := begin
intros μ ν h,
apply subtype.eq,
rw [←μ.to_finite_measure_to_measure_eq_val, ←ν.to_finite_measure_to_measure_eq_val],
apply congr_arg _ h,
end, }
lemma probability_measures.tendsto_nhds_iff_to_finite_measures_tendsto_nhds {δ : Type*}
(F : filter δ) {μs : δ → probability_measures α} {μ₀ : probability_measures α} :
tendsto μs F (𝓝 μ₀) ↔ tendsto (coe ∘ μs) F (𝓝 (μ₀.to_finite_measure)) :=
embedding.tendsto_nhds_iff (probability_measures.coe_embedding α)
lemma finite_measures.tendsto_iff_weak_star_tendsto {γ : Type*} {F : filter γ}
{μs : γ → finite_measures α} {μ : finite_measures α} :
tendsto μs F (𝓝 μ) ↔
tendsto (λ i, (μs(i)).to_weak_dual_of_bcnn)
F (𝓝 μ.to_weak_dual_of_bcnn) :=
by apply tendsto_induced_iff
theorem finite_measures.tendsto_iff_forall_test_against_nn_tendsto {γ : Type*} {F : filter γ}
{μs : γ → finite_measures α} {μ : finite_measures α} :
tendsto μs F (𝓝 μ) ↔
∀ (f : α →ᵇ ℝ≥0),
tendsto (λ i, (μs(i)).to_weak_dual_of_bcnn f)
F (𝓝 (μ.to_weak_dual_of_bcnn f)) :=
by rw [finite_measures.tendsto_iff_weak_star_tendsto,
weak_dual.tendsto_iff_forall_test_tendsto]
theorem finite_measures.tendsto_iff_forall_lintegral_tendsto {γ : Type*} {F : filter γ}
{μs : γ → finite_measures α} {μ : finite_measures α} :
tendsto μs F (𝓝 μ) ↔
∀ (f : α →ᵇ ℝ≥0),
tendsto (λ i, lintegral (μs(i)).to_measure (coe ∘ f)) F (𝓝 (lintegral μ.to_measure (coe ∘ f))) :=
begin
rw finite_measures.tendsto_iff_forall_test_against_nn_tendsto,
simp_rw finite_measures.test_against_eq_to_weak_dual_test,
simp_rw ←finite_measures.test_against_nn_coe_eq,
simp_rw ennreal.tendsto_coe,
end
/-- The usual definition of weak convergence of probability measures is given in terms of sequences
of probability measures: it is the requirement that the integrals of all continuous bounded
functions against members of the sequence converge. This version is a characterization using
nonnegative bounded continuous functions. -/
theorem probability_measures.tendsto_iff_forall_lintegral_tendsto {γ : Type*} {F : filter γ}
{μs : γ → probability_measures α} {μ : probability_measures α} :
tendsto μs F (𝓝 μ) ↔
∀ (f : α →ᵇ ℝ≥0),
tendsto (λ i, lintegral (μs(i)).to_measure (coe ∘ f)) F (𝓝 (lintegral μ.to_measure (coe ∘ f))) :=
begin
rw [probability_measures.tendsto_nhds_iff_to_finite_measures_tendsto_nhds,
finite_measures.tendsto_iff_forall_lintegral_tendsto],
refl,
end
end weak_convergence_of_measures
|
a0eb8a288f05ef2a65ffda5045ce9d312639c734
|
e5169dbb8b1bea3ec2a32737442bc91a4a94b46a
|
/library/data/set/basic.lean
|
3c2710ac4016cc1ddade9ad39bea4fce38a28b68
|
[
"Apache-2.0"
] |
permissive
|
pazthor/lean
|
733b775e3123f6bbd2c4f7ccb5b560b467b76800
|
c923120db54276a22a75b12c69765765608a8e76
|
refs/heads/master
| 1,610,703,744,289
| 1,448,419,395,000
| 1,448,419,703,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 13,649
|
lean
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad, Leonardo de Moura
-/
import logic.connectives logic.identities algebra.binary
open eq.ops binary
definition set (X : Type) := X → Prop
namespace set
variable {X : Type}
/- membership and subset -/
definition mem (x : X) (a : set X) := a x
infix ∈ := mem
notation a ∉ b := ¬ mem a b
theorem ext {a b : set X} (H : ∀x, x ∈ a ↔ x ∈ b) : a = b :=
funext (take x, propext (H x))
definition subset (a b : set X) := ∀⦃x⦄, x ∈ a → x ∈ b
infix ⊆ := subset
definition superset (s t : set X) : Prop := t ⊆ s
infix ⊇ := superset
theorem subset.refl (a : set X) : a ⊆ a := take x, assume H, H
theorem subset.trans {a b c : set X} (subab : a ⊆ b) (subbc : b ⊆ c) : a ⊆ c :=
take x, assume ax, subbc (subab ax)
theorem subset.antisymm {a b : set X} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b :=
ext (λ x, iff.intro (λ ina, h₁ ina) (λ inb, h₂ inb))
-- an alterantive name
theorem eq_of_subset_of_subset {a b : set X} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b :=
subset.antisymm h₁ h₂
theorem mem_of_subset_of_mem {s₁ s₂ : set X} {a : X} : s₁ ⊆ s₂ → a ∈ s₁ → a ∈ s₂ :=
assume h₁ h₂, h₁ _ h₂
/- strict subset -/
definition strict_subset (a b : set X) := a ⊆ b ∧ a ≠ b
infix ` ⊂ `:50 := strict_subset
theorem strict_subset.irrefl (a : set X) : ¬ a ⊂ a :=
assume h, absurd rfl (and.elim_right h)
/- bounded quantification -/
abbreviation bounded_forall (a : set X) (P : X → Prop) := ∀⦃x⦄, x ∈ a → P x
notation `forallb` binders `∈` a `, ` r:(scoped:1 P, P) := bounded_forall a r
notation `∀₀` binders `∈` a `, ` r:(scoped:1 P, P) := bounded_forall a r
abbreviation bounded_exists (a : set X) (P : X → Prop) := ∃⦃x⦄, x ∈ a ∧ P x
notation `existsb` binders `∈` a `, ` r:(scoped:1 P, P) := bounded_exists a r
notation `∃₀` binders `∈` a `, ` r:(scoped:1 P, P) := bounded_exists a r
theorem bounded_exists.intro {P : X → Prop} {s : set X} {x : X} (xs : x ∈ s) (Px : P x) :
∃₀ x ∈ s, P x :=
exists.intro x (and.intro xs Px)
/- empty set -/
definition empty : set X := λx, false
notation `∅` := empty
theorem not_mem_empty (x : X) : ¬ (x ∈ ∅) :=
assume H : x ∈ ∅, H
theorem mem_empty_eq (x : X) : x ∈ ∅ = false := rfl
theorem eq_empty_of_forall_not_mem {s : set X} (H : ∀ x, x ∉ s) : s = ∅ :=
ext (take x, iff.intro
(assume xs, absurd xs (H x))
(assume xe, absurd xe !not_mem_empty))
theorem empty_subset (s : set X) : ∅ ⊆ s :=
take x, assume H, false.elim H
theorem eq_empty_of_subset_empty {s : set X} (H : s ⊆ ∅) : s = ∅ :=
subset.antisymm H (empty_subset s)
theorem subset_empty_iff (s : set X) : s ⊆ ∅ ↔ s = ∅ :=
iff.intro eq_empty_of_subset_empty (take xeq, by rewrite xeq; apply subset.refl ∅)
/- universal set -/
definition univ : set X := λx, true
theorem mem_univ (x : X) : x ∈ univ := trivial
theorem mem_univ_iff (x : X) : x ∈ univ ↔ true := !iff.refl
theorem mem_univ_eq (x : X) : x ∈ univ = true := rfl
theorem empty_ne_univ [h : inhabited X] : (empty : set X) ≠ univ :=
assume H : empty = univ,
absurd (mem_univ (inhabited.value h)) (eq.rec_on H (not_mem_empty _))
theorem subset_univ (s : set X) : s ⊆ univ := λ x H, trivial
theorem eq_univ_of_univ_subset {s : set X} (H : univ ⊆ s) : s = univ :=
eq_of_subset_of_subset (subset_univ s) H
theorem eq_univ_of_forall {s : set X} (H : ∀ x, x ∈ s) : s = univ :=
ext (take x, iff.intro (assume H', trivial) (assume H', H x))
/- union -/
definition union (a b : set X) : set X := λx, x ∈ a ∨ x ∈ b
notation a ∪ b := union a b
theorem mem_union_left {x : X} {a : set X} (b : set X) : x ∈ a → x ∈ a ∪ b :=
assume h, or.inl h
theorem mem_union_right {x : X} {b : set X} (a : set X) : x ∈ b → x ∈ a ∪ b :=
assume h, or.inr h
theorem mem_unionl {x : X} {a b : set X} : x ∈ a → x ∈ a ∪ b :=
assume h, or.inl h
theorem mem_unionr {x : X} {a b : set X} : x ∈ b → x ∈ a ∪ b :=
assume h, or.inr h
theorem mem_or_mem_of_mem_union {x : X} {a b : set X} (H : x ∈ a ∪ b) : x ∈ a ∨ x ∈ b := H
theorem mem_union.elim {x : X} {a b : set X} {P : Prop}
(H₁ : x ∈ a ∪ b) (H₂ : x ∈ a → P) (H₃ : x ∈ b → P) : P :=
or.elim H₁ H₂ H₃
theorem mem_union_iff (x : X) (a b : set X) : x ∈ a ∪ b ↔ x ∈ a ∨ x ∈ b := !iff.refl
theorem mem_union_eq (x : X) (a b : set X) : x ∈ a ∪ b = (x ∈ a ∨ x ∈ b) := rfl
theorem union_self (a : set X) : a ∪ a = a :=
ext (take x, !or_self)
theorem union_empty (a : set X) : a ∪ ∅ = a :=
ext (take x, !or_false)
theorem empty_union (a : set X) : ∅ ∪ a = a :=
ext (take x, !false_or)
theorem union.comm (a b : set X) : a ∪ b = b ∪ a :=
ext (take x, or.comm)
theorem union.assoc (a b c : set X) : (a ∪ b) ∪ c = a ∪ (b ∪ c) :=
ext (take x, or.assoc)
theorem union.left_comm (s₁ s₂ s₃ : set X) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) :=
!left_comm union.comm union.assoc s₁ s₂ s₃
theorem union.right_comm (s₁ s₂ s₃ : set X) : (s₁ ∪ s₂) ∪ s₃ = (s₁ ∪ s₃) ∪ s₂ :=
!right_comm union.comm union.assoc s₁ s₂ s₃
theorem subset_union_left (s t : set X) : s ⊆ s ∪ t := λ x H, or.inl H
theorem subset_union_right (s t : set X) : t ⊆ s ∪ t := λ x H, or.inr H
theorem union_subset {s t r : set X} (sr : s ⊆ r) (tr : t ⊆ r) : s ∪ t ⊆ r :=
λ x xst, or.elim xst (λ xs, sr xs) (λ xt, tr xt)
/- intersection -/
definition inter (a b : set X) : set X := λx, x ∈ a ∧ x ∈ b
notation a ∩ b := inter a b
theorem mem_inter_iff (x : X) (a b : set X) : x ∈ a ∩ b ↔ x ∈ a ∧ x ∈ b := !iff.refl
theorem mem_inter_eq (x : X) (a b : set X) : x ∈ a ∩ b = (x ∈ a ∧ x ∈ b) := rfl
theorem mem_inter {x : X} {a b : set X} (Ha : x ∈ a) (Hb : x ∈ b) : x ∈ a ∩ b :=
and.intro Ha Hb
theorem mem_of_mem_inter_left {x : X} {a b : set X} (H : x ∈ a ∩ b) : x ∈ a :=
and.left H
theorem mem_of_mem_inter_right {x : X} {a b : set X} (H : x ∈ a ∩ b) : x ∈ b :=
and.right H
theorem inter_self (a : set X) : a ∩ a = a :=
ext (take x, !and_self)
theorem inter_empty (a : set X) : a ∩ ∅ = ∅ :=
ext (take x, !and_false)
theorem empty_inter (a : set X) : ∅ ∩ a = ∅ :=
ext (take x, !false_and)
theorem inter.comm (a b : set X) : a ∩ b = b ∩ a :=
ext (take x, !and.comm)
theorem inter.assoc (a b c : set X) : (a ∩ b) ∩ c = a ∩ (b ∩ c) :=
ext (take x, !and.assoc)
theorem inter.left_comm (s₁ s₂ s₃ : set X) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) :=
!left_comm inter.comm inter.assoc s₁ s₂ s₃
theorem inter.right_comm (s₁ s₂ s₃ : set X) : (s₁ ∩ s₂) ∩ s₃ = (s₁ ∩ s₃) ∩ s₂ :=
!right_comm inter.comm inter.assoc s₁ s₂ s₃
theorem inter_univ (a : set X) : a ∩ univ = a :=
ext (take x, !and_true)
theorem univ_inter (a : set X) : univ ∩ a = a :=
ext (take x, !true_and)
theorem inter_subset_left (s t : set X) : s ∩ t ⊆ s := λ x H, and.left H
theorem inter_subset_right (s t : set X) : s ∩ t ⊆ t := λ x H, and.right H
theorem subset_inter {s t r : set X} (rs : r ⊆ s) (rt : r ⊆ t) : r ⊆ s ∩ t :=
λ x xr, and.intro (rs xr) (rt xr)
/- distributivity laws -/
theorem inter.distrib_left (s t u : set X) : s ∩ (t ∪ u) = (s ∩ t) ∪ (s ∩ u) :=
ext (take x, !and.left_distrib)
theorem inter.distrib_right (s t u : set X) : (s ∪ t) ∩ u = (s ∩ u) ∪ (t ∩ u) :=
ext (take x, !and.right_distrib)
theorem union.distrib_left (s t u : set X) : s ∪ (t ∩ u) = (s ∪ t) ∩ (s ∪ u) :=
ext (take x, !or.left_distrib)
theorem union.distrib_right (s t u : set X) : (s ∩ t) ∪ u = (s ∪ u) ∩ (t ∪ u) :=
ext (take x, !or.right_distrib)
/- set-builder notation -/
-- {x : X | P}
definition set_of (P : X → Prop) : set X := P
notation `{` binder ` | ` r:(scoped:1 P, set_of P) `}` := r
-- {x ∈ s | P}
definition sep (P : X → Prop) (s : set X) : set X := λx, x ∈ s ∧ P x
notation `{` binder ` ∈ ` s ` | ` r:(scoped:1 p, sep p s) `}` := r
/- insert -/
definition insert (x : X) (a : set X) : set X := {y : X | y = x ∨ y ∈ a}
-- '{x, y, z}
notation `'{`:max a:(foldr `, ` (x b, insert x b) ∅) `}`:0 := a
theorem subset_insert (x : X) (a : set X) : a ⊆ insert x a :=
take y, assume ys, or.inr ys
theorem mem_insert (x : X) (s : set X) : x ∈ insert x s :=
or.inl rfl
theorem mem_insert_of_mem {x : X} {s : set X} (y : X) : x ∈ s → x ∈ insert y s :=
assume h, or.inr h
theorem eq_or_mem_of_mem_insert {x a : X} {s : set X} : x ∈ insert a s → x = a ∨ x ∈ s :=
assume h, h
theorem mem_of_mem_insert_of_ne {x a : X} {s : set X} (xin : x ∈ insert a s) : x ≠ a → x ∈ s :=
or_resolve_right (eq_or_mem_of_mem_insert xin)
theorem mem_insert_eq (x a : X) (s : set X) : x ∈ insert a s = (x = a ∨ x ∈ s) :=
propext (iff.intro !eq_or_mem_of_mem_insert
(or.rec (λH', (eq.substr H' !mem_insert)) !mem_insert_of_mem))
theorem insert_eq_of_mem {a : X} {s : set X} (H : a ∈ s) : insert a s = s :=
ext (λ x, eq.substr (mem_insert_eq x a s)
(or_iff_right_of_imp (λH1, eq.substr H1 H)))
theorem insert.comm (x y : X) (s : set X) : insert x (insert y s) = insert y (insert x s) :=
ext (take a, by rewrite [*mem_insert_eq, propext !or.left_comm])
/- singleton -/
theorem mem_singleton_iff (a b : X) : a ∈ '{b} ↔ a = b :=
iff.intro
(assume ainb, or.elim ainb (λ aeqb, aeqb) (λ f, false.elim f))
(assume aeqb, or.inl aeqb)
theorem mem_singleton (a : X) : a ∈ '{a} := !mem_insert
theorem eq_of_mem_singleton {x y : X} : x ∈ insert y ∅ → x = y :=
assume h, or.elim (eq_or_mem_of_mem_insert h)
(suppose x = y, this)
(suppose x ∈ ∅, absurd this !not_mem_empty)
/- separation -/
theorem mem_sep {s : set X} {P : X → Prop} {x : X} (xs : x ∈ s) (Px : P x) : x ∈ {x ∈ s | P x} :=
and.intro xs Px
theorem eq_sep_of_subset {s t : set X} (ssubt : s ⊆ t) : s = {x ∈ t | x ∈ s} :=
ext (take x, iff.intro
(suppose x ∈ s, and.intro (ssubt this) this)
(suppose x ∈ {x ∈ t | x ∈ s}, and.right this))
theorem mem_sep_iff {s : set X} {P : X → Prop} {x : X} : x ∈ {x ∈ s | P x} ↔ x ∈ s ∧ P x :=
!iff.refl
theorem sep_subset (s : set X) (P : X → Prop) : {x ∈ s | P x} ⊆ s :=
take x, assume H, and.left H
/- complement -/
definition complement (s : set X) : set X := {x | x ∉ s}
prefix `-` := complement
theorem mem_comp {s : set X} {x : X} (H : x ∉ s) : x ∈ -s := H
theorem not_mem_of_mem_comp {s : set X} {x : X} (H : x ∈ -s) : x ∉ s := H
theorem mem_comp_iff (s : set X) (x : X) : x ∈ -s ↔ x ∉ s := !iff.refl
theorem inter_comp_self (s : set X) : s ∩ -s = ∅ :=
ext (take x, !and_not_self_iff)
theorem comp_inter_self (s : set X) : -s ∩ s = ∅ :=
ext (take x, !not_and_self_iff)
/- some classical identities -/
section
open classical
theorem union_eq_comp_comp_inter_comp (s t : set X) : s ∪ t = -(-s ∩ -t) :=
ext (take x, !or_iff_not_and_not)
theorem inter_eq_comp_comp_union_comp (s t : set X) : s ∩ t = -(-s ∪ -t) :=
ext (take x, !and_iff_not_or_not)
theorem union_comp_self (s : set X) : s ∪ -s = univ :=
ext (take x, !or_not_self_iff)
theorem comp_union_self (s : set X) : -s ∪ s = univ :=
ext (take x, !not_or_self_iff)
end
/- set difference -/
definition diff (s t : set X) : set X := {x ∈ s | x ∉ t}
infix `\`:70 := diff
theorem mem_diff {s t : set X} {x : X} (H1 : x ∈ s) (H2 : x ∉ t) : x ∈ s \ t :=
and.intro H1 H2
theorem mem_of_mem_diff {s t : set X} {x : X} (H : x ∈ s \ t) : x ∈ s :=
and.left H
theorem not_mem_of_mem_diff {s t : set X} {x : X} (H : x ∈ s \ t) : x ∉ t :=
and.right H
theorem mem_diff_iff (s t : set X) (x : X) : x ∈ s \ t ↔ x ∈ s ∧ x ∉ t := !iff.refl
theorem mem_diff_eq (s t : set X) (x : X) : x ∈ s \ t = (x ∈ s ∧ x ∉ t) := rfl
theorem diff_eq (s t : set X) : s \ t = s ∩ -t := rfl
theorem union_diff_cancel {s t : set X} [dec : Π x, decidable (x ∈ s)] (H : s ⊆ t) : s ∪ (t \ s) = t :=
ext (take x, iff.intro
(assume H1 : x ∈ s ∪ (t \ s), or.elim H1 (assume H2, !H H2) (assume H2, and.left H2))
(assume H1 : x ∈ t,
decidable.by_cases
(suppose x ∈ s, or.inl this)
(suppose x ∉ s, or.inr (and.intro H1 this))))
theorem diff_subset (s t : set X) : s \ t ⊆ s := inter_subset_left s _
/- powerset -/
definition powerset (s : set X) : set (set X) := {x : set X | x ⊆ s}
prefix `𝒫`:100 := powerset
theorem mem_powerset {x s : set X} (H : x ⊆ s) : x ∈ 𝒫 s := H
theorem subset_of_mem_powerset {x s : set X} (H : x ∈ 𝒫 s) : x ⊆ s := H
theorem mem_powerset_iff (x s : set X) : x ∈ 𝒫 s ↔ x ⊆ s := !iff.refl
/- large unions -/
section
variables {I : Type}
variable a : set I
variable b : I → set X
variable C : set (set X)
definition Inter : set X := {x : X | ∀i, x ∈ b i}
definition bInter : set X := {x : X | ∀₀ i ∈ a, x ∈ b i}
definition sInter : set X := {x : X | ∀₀ c ∈ C, x ∈ c}
definition Union : set X := {x : X | ∃i, x ∈ b i}
definition bUnion : set X := {x : X | ∃₀ i ∈ a, x ∈ b i}
definition sUnion : set X := {x : X | ∃₀ c ∈ C, x ∈ c}
-- TODO: need notation for these
theorem Union_subset {b : I → set X} {c : set X} (H : ∀ i, b i ⊆ c) : Union b ⊆ c :=
take x,
suppose x ∈ Union b,
obtain i (Hi : x ∈ b i), from this,
show x ∈ c, from H i Hi
end
end set
|
26534129cc0a64e99979b449320ba5122ffe4956
|
86f6f4f8d827a196a32bfc646234b73328aeb306
|
/examples/basics/unnamed_1037.lean
|
4d6cec6ded407368955885e5f55affa53d0ae181
|
[] |
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
| 612
|
lean
|
import data.real.basic
-- BEGIN
example (x y z : ℝ) (h₀ : x ≤ y) (h₁ : y ≤ z) : x ≤ z :=
begin
apply le_trans,
{ apply h₀ },
apply h₁
end
example (x y z : ℝ) (h₀ : x ≤ y) (h₁ : y ≤ z) : x ≤ z :=
begin
apply le_trans h₀,
apply h₁
end
example (x y z : ℝ) (h₀ : x ≤ y) (h₁ : y ≤ z) : x ≤ z :=
by exact le_trans h₀ h₁
example (x y z : ℝ) (h₀ : x ≤ y) (h₁ : y ≤ z) : x ≤ z :=
le_trans h₀ h₁
example (x : ℝ) : x ≤ x :=
by apply le_refl
example (x : ℝ) : x ≤ x :=
by exact le_refl x
example (x : ℝ) : x ≤ x :=
le_refl x
-- END
|
c37834ed04b5bd5b5a054a07a4e7dce039025465
|
75db7e3219bba2fbf41bf5b905f34fcb3c6ca3f2
|
/tests/lean/run/new_obtain4.lean
|
0af8bac43ef3a98de762f6af6e4511ac95277248
|
[
"Apache-2.0"
] |
permissive
|
jroesch/lean
|
30ef0860fa905d35b9ad6f76de1a4f65c9af6871
|
3de4ec1a6ce9a960feb2a48eeea8b53246fa34f2
|
refs/heads/master
| 1,586,090,835,348
| 1,455,142,203,000
| 1,455,142,277,000
| 51,536,958
| 1
| 0
| null | 1,455,215,811,000
| 1,455,215,811,000
| null |
UTF-8
|
Lean
| false
| false
| 447
|
lean
|
import data.set
open set function eq.ops
variables {X Y Z : Type}
lemma image_compose (f : Y → X) (g : X → Y) (a : set X) : (f ∘ g) ' a = f ' (g ' a) :=
ext (take z,
iff.intro
(assume Hz,
obtain x Hx₁ Hx₂, from Hz,
by repeat (apply mem_image | assumption | reflexivity))
(assume Hz,
obtain y [x Hz₁ Hz₂] Hy₂, from Hz,
by repeat (apply mem_image | assumption | esimp [compose] | rewrite Hz₂)))
|
4f5403d341d85c87e990261c4e32ef274371e05b
|
d9ed0fce1c218297bcba93e046cb4e79c83c3af8
|
/library/init/category/functor.lean
|
d87680fc6d0ca9d9265ab114edb2e53d48395933
|
[
"Apache-2.0"
] |
permissive
|
leodemoura/lean_clone
|
005c63aa892a6492f2d4741ee3c2cb07a6be9d7f
|
cc077554b584d39bab55c360bc12a6fe7957afe6
|
refs/heads/master
| 1,610,506,475,484
| 1,482,348,354,000
| 1,482,348,543,000
| 77,091,586
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 464
|
lean
|
/-
Copyright (c) Luke Nelson and Jared Roesch. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Luke Nelson and Jared Roesch
-/
prelude
universe variables u v
class functor (f : Type u → Type v) : Type (max u+1 v) :=
(map : Π {a b : Type u}, (a → b) → f a → f b)
@[inline] def fmap {f : Type u → Type v} [functor f] {a b : Type u} : (a → b) → f a → f b :=
functor.map
infixr ` <$> `:100 := fmap
|
41db0b1640b5ef188e3ff1e0ad0dc9562227626c
|
80cc5bf14c8ea85ff340d1d747a127dcadeb966f
|
/src/topology/bases.lean
|
1eb02bb44a141c3dd80efa9b8850877559bbfdb1
|
[
"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
| 13,344
|
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
Bases of topologies. Countability axioms.
-/
import topology.continuous_on
open set filter classical
open_locale topological_space filter
noncomputable theory
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.
-/
universe u
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).nonempty}) :=
let b' := (λf, ⋂₀ f) '' {f:set (set α) | finite f ∧ f ⊆ s ∧ (⋂₀ f).nonempty} 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₂, ⟨hft₁.union hft₂, union_subset ht₁b ht₂b,
ie.symm ▸ ⟨_, h⟩⟩, ie⟩, h, subset.refl _⟩,
eq_univ_iff_forall.2 $ assume a, ⟨univ, ⟨∅, ⟨finite_empty, empty_subset _,
by rw sInter_empty; exact ⟨a, mem_univ a⟩⟩, sInter_empty⟩, mem_univ _⟩,
have generate_from s = generate_from b',
from le_antisymm
(le_generate_from $ assume u ⟨t, ⟨hft, htb, ne⟩, eq⟩,
eq ▸ @is_open_sInter _ (generate_from s) _ hft (assume s hs, generate_open.basic _ $ htb hs))
(le_generate_from $ assume s hs,
s.eq_empty_or_nonempty.elim
(assume : s = ∅, by rw [this]; apply @is_open_empty _ _)
(assume : s.nonempty, generate_open.basic _ ⟨{s}, ⟨finite_singleton s, singleton_subset_iff.2 hs,
by rwa sInter_singleton⟩, sInter_singleton s⟩)),
this ▸ hs⟩
lemma is_topological_basis_of_open_of_nhds {s : set (set α)}
(h_open : ∀ u ∈ s, is_open u)
(h_nhds : ∀(a:α) (u : set α), a ∈ u → 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
(le_generate_from h_open)
(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⟩ $ le_principal_iff.2 hvu))⟩
lemma mem_nhds_of_is_topological_basis {a : α} {s : set α} {b : set (set α)}
(hb : is_topological_basis b) : s ∈ 𝓝 a ↔ ∃t∈b, a ∈ t ∧ t ⊆ s :=
begin
change s ∈ (𝓝 a).sets ↔ ∃t∈b, a ∈ t ∧ t ⊆ s,
rw [hb.2.2, nhds_generate_from, binfi_sets_eq],
{ simp only [mem_bUnion_iff, exists_prop, mem_set_of_eq, and_assoc, and.left_comm], refl },
{ 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₁⟩, le_principal_iff.2 (subset.trans hu₃ (inter_subset_left _ _)),
le_principal_iff.2 (subset.trans hu₃ (inter_subset_right _ _))⟩ },
{ rcases eq_univ_iff_forall.1 hb.2.1 a with ⟨i, h1, h2⟩,
exact ⟨i, h2, h1⟩ }
end
lemma is_open_of_is_topological_basis {s : set α} {b : set (set α)}
(hb : is_topological_basis b) (hs : s ∈ b) : is_open s :=
is_open_iff_mem_nhds.2 $ λ a as,
(mem_nhds_of_is_topological_basis hb).2 ⟨s, hs, as, subset.refl _⟩
lemma mem_basis_subset_of_mem_open {b : set (set α)}
(hb : is_topological_basis b) {a:α} {u : set α} (au : a ∈ u)
(ou : is_open u) : ∃v ∈ b, a ∈ v ∧ v ⊆ u :=
(mem_nhds_of_is_topological_basis hb).1 $ mem_nhds_sets ou au
lemma sUnion_basis_of_is_open {B : set (set α)}
(hB : is_topological_basis B) {u : set α} (ou : is_open u) :
∃ S ⊆ B, u = ⋃₀ S :=
⟨{s ∈ B | s ⊆ u}, λ s h, h.1, set.ext $ λ a,
⟨λ ha, let ⟨b, hb, ab, bu⟩ := mem_basis_subset_of_mem_open hB ha ou in
⟨b, ⟨hb, bu⟩, ab⟩,
λ ⟨b, ⟨hb, bu⟩, ab⟩, bu ab⟩⟩
lemma Union_basis_of_is_open {B : set (set α)}
(hB : is_topological_basis B) {u : set α} (ou : is_open u) :
∃ (β : Type u) (f : β → set α), u = (⋃ i, f i) ∧ ∀ i, f i ∈ B :=
let ⟨S, sb, su⟩ := sUnion_basis_of_is_open hB ou in
⟨S, subtype.val, su.trans set.sUnion_eq_Union, λ ⟨b, h⟩, sb h⟩
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)
lemma exists_dense_seq [separable_space α] [nonempty α] : ∃ u : ℕ → α, closure (range u) = univ :=
begin
obtain ⟨s : set α, hs, s_dense⟩ := @separable_space.exists_countable_closure_eq_univ α _ _,
cases countable_iff_exists_surjective.mp hs with u hu,
use u,
apply eq_univ_of_univ_subset,
simpa [s_dense] using closure_mono hu
end
/-- A sequence dense in a non-empty separable topological space. -/
def dense_seq [separable_space α] [nonempty α] : ℕ → α := classical.some (exists_dense_seq α)
@[simp] lemma dense_seq_dense [separable_space α] [nonempty α] :
closure (range $ dense_seq α) = univ := classical.some_spec (exists_dense_seq α)
/-- A first-countable space is one in which every point has a
countable neighborhood basis. -/
class first_countable_topology : Prop :=
(nhds_generated_countable : ∀a:α, (𝓝 a).is_countably_generated)
namespace first_countable_topology
variable {α}
lemma tendsto_subseq [first_countable_topology α] {u : ℕ → α} {x : α} (hx : map_cluster_pt x at_top u) :
∃ (ψ : ℕ → ℕ), (strict_mono ψ) ∧ (tendsto (u ∘ ψ) at_top (𝓝 x)) :=
(nhds_generated_countable x).subseq_tendsto hx
end first_countable_topology
variables {α}
lemma is_countably_generated_nhds [first_countable_topology α] (x : α) :
is_countably_generated (𝓝 x) :=
first_countable_topology.nhds_generated_countable x
lemma is_countably_generated_nhds_within [first_countable_topology α] (x : α) (s : set α) :
is_countably_generated (𝓝[s] x) :=
(is_countably_generated_nhds x).inf_principal s
variable (α)
/-- 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)
@[priority 100] -- see Note [lower instance priority]
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
⟨begin
intros,
rw [eq, nhds_generate_from],
exact is_countably_generated_binfi_principal (hb.mono (assume x, and.right)),
end⟩
lemma second_countable_topology_induced (β)
[t : topological_space β] [second_countable_topology β] (f : α → β) :
@second_countable_topology α (t.induced f) :=
begin
rcases second_countable_topology.is_open_generated_countable β with ⟨b, hb, eq⟩,
refine { is_open_generated_countable := ⟨preimage f '' b, hb.image _, _⟩ },
rw [eq, induced_generate_from_eq]
end
instance subtype.second_countable_topology
(s : set α) [second_countable_topology α] : second_countable_topology s :=
second_countable_topology_induced s α coe
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).nonempty} in
⟨b',
((countable_set_of_finite_subset hb₁).mono
(by { simp only [← and_assoc], apply inter_subset_left })).image _,
assume ⟨s, ⟨_, _, hn⟩, hp⟩, absurd hn (not_nonempty_iff_eq_empty.2 hp),
is_topological_basis_of_subbasis hb₂⟩
/- TODO: more fine grained instances for first_countable_topology, separable_space, t2_space, ... -/
instance {β : Type*} [topological_space β]
[second_countable_topology α] [second_countable_topology β] : second_countable_topology (α × β) :=
⟨let ⟨a, ha₁, ha₂, ha₃, ha₄, ha₅⟩ := is_open_generated_countable_inter α in
let ⟨b, hb₁, hb₂, hb₃, hb₄, hb₅⟩ := is_open_generated_countable_inter β in
⟨{g | ∃u∈a, ∃v∈b, g = set.prod u v},
have {g | ∃u∈a, ∃v∈b, g = set.prod u v} = (⋃u∈a, ⋃v∈b, {set.prod u v}),
by apply set.ext; simp,
by rw [this]; exact (ha₁.bUnion $ assume u hu, hb₁.bUnion $ by simp),
by rw [ha₅, hb₅, prod_generate_from_generate_from_eq ha₄ hb₄]⟩⟩
instance second_countable_topology_fintype {ι : Type*} {π : ι → Type*}
[fintype ι] [t : ∀a, topological_space (π a)] [sc : ∀a, second_countable_topology (π a)] :
second_countable_topology (∀a, π a) :=
have ∀i, ∃b : set (set (π i)), countable b ∧ ∅ ∉ b ∧ is_topological_basis b, from
assume a, @is_open_generated_countable_inter (π a) _ (sc a),
let ⟨g, hg⟩ := classical.axiom_of_choice this in
have t = (λa, generate_from (g a)), from funext $ assume a, (hg a).2.2.2.2,
begin
constructor,
refine ⟨pi univ '' pi univ g, countable.image _ _, _⟩,
{ suffices : countable {f : Πa, set (π a) | ∀a, f a ∈ g a}, { simpa [pi] },
exact countable_pi (assume i, (hg i).1), },
rw [this, pi_generate_from_eq_fintype],
{ congr' 1 with f, simp [pi, eq_comm] },
exact assume a, (hg a).2.2.2.1
end
@[priority 100] -- see Note [lower instance priority]
instance second_countable_topology.to_separable_space
[second_countable_topology α] : separable_space α :=
begin
rcases is_open_generated_countable_inter α with ⟨b, hbc, hbne, hb, hbU, eq⟩,
set S : α → set (set α) := λ a, {s : set α | a ∈ s ∧ s ∈ b},
have nhds_eq : ∀a, 𝓝 a = (⨅ s ∈ S a, 𝓟 s),
{ intro a, rw [eq, nhds_generate_from] },
have : ∀ s ∈ b, set.nonempty s :=
assume s hs, ne_empty_iff_nonempty.1 $ λ eq, absurd hs (eq.symm ▸ hbne),
choose f hf,
refine ⟨⟨⋃ s ∈ b, {f s ‹_›}, hbc.bUnion (λ _ _, countable_singleton _), _⟩⟩,
refine eq_univ_of_forall (λ a, _),
suffices : (⨅ s ∈ S a, 𝓟 (s ∩ ⋃ t ∈ b, {f t ‹_›})).ne_bot,
{ obtain ⟨t, htb, hta⟩ : a ∈ ⋃₀ b, { simp only [hbU] },
have A : ∃ s, s ∈ S a := ⟨t, hta, htb⟩,
simpa only [← inf_principal, mem_closure_iff_cluster_pt,
cluster_pt, nhds_eq, binfi_inf A] using this },
rw [infi_subtype'],
haveI : nonempty α := ⟨a⟩,
refine infi_ne_bot_of_directed _ _,
{ rintros ⟨s₁, has₁, hs₁⟩ ⟨s₂, has₂, hs₂⟩,
obtain ⟨t, htb, hta, ht⟩ : ∃ t ∈ b, a ∈ t ∧ t ⊆ s₁ ∩ s₂,
from hb _ hs₁ _ hs₂ a ⟨has₁, has₂⟩,
refine ⟨⟨t, hta, htb⟩, _⟩,
simp only [subset_inter_iff] at ht,
simp only [principal_mono, subtype.coe_mk, (≥)],
exact ⟨inter_subset_inter_left _ ht.1, inter_subset_inter_left _ ht.2⟩ },
rintros ⟨s, hsa, hsb⟩,
suffices : (s ∩ ⋃ t ∈ b, {f t ‹_›}).nonempty, { simpa [principal_ne_bot_iff] },
refine ⟨_, hf _ hsb, _⟩,
simp only [mem_Union],
exact ⟨s, hsb, rfl⟩
end
variables {α}
lemma is_open_Union_countable [second_countable_topology α]
{ι} (s : ι → set α) (H : ∀ i, is_open (s i)) :
∃ T : set ι, countable T ∧ (⋃ i ∈ T, s i) = ⋃ i, s i :=
let ⟨B, cB, _, bB⟩ := is_open_generated_countable_inter α in
begin
let B' := {b ∈ B | ∃ i, b ⊆ s i},
choose f hf using λ b:B', b.2.2,
haveI : encodable B' := (cB.mono (sep_subset _ _)).to_encodable,
refine ⟨_, countable_range f,
subset.antisymm (bUnion_subset_Union _ _) (sUnion_subset _)⟩,
rintro _ ⟨i, rfl⟩ x xs,
rcases mem_basis_subset_of_mem_open bB xs (H _) with ⟨b, hb, xb, bs⟩,
exact ⟨_, ⟨_, rfl⟩, _, ⟨⟨⟨_, hb, _, bs⟩, rfl⟩, rfl⟩, hf _ (by exact xb)⟩
end
lemma is_open_sUnion_countable [second_countable_topology α]
(S : set (set α)) (H : ∀ s ∈ S, is_open s) :
∃ T : set (set α), countable T ∧ T ⊆ S ∧ ⋃₀ T = ⋃₀ S :=
let ⟨T, cT, hT⟩ := is_open_Union_countable (λ s:S, s.1) (λ s, H s.1 s.2) in
⟨subtype.val '' T, cT.image _,
image_subset_iff.2 $ λ ⟨x, xs⟩ xt, xs,
by rwa [sUnion_image, sUnion_eq_Union]⟩
end topological_space
|
89c2b9b19de256bff77bc302b3e81cedb7827ef3
|
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
|
/stage0/src/Lean/DeclarationRange.lean
|
1a8e7e369ce5fb49608ef2030f424dc181c3c8e3
|
[
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"
] |
permissive
|
EdAyers/lean4
|
57ac632d6b0789cb91fab2170e8c9e40441221bd
|
37ba0df5841bde51dbc2329da81ac23d4f6a4de4
|
refs/heads/master
| 1,676,463,245,298
| 1,660,619,433,000
| 1,660,619,433,000
| 183,433,437
| 1
| 0
|
Apache-2.0
| 1,657,612,672,000
| 1,556,196,574,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 2,510
|
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.MonadEnv
import Lean.AuxRecursor
import Lean.ToExpr
namespace Lean
/-- Store position information for declarations. -/
structure DeclarationRange where
pos : Position
/-- A precomputed UTF-16 `character` field as in `Lean.Lsp.Position`. We need to store this
because LSP clients want us to report the range in terms of UTF-16, but converting a Unicode
codepoint stored in `Lean.Position` to UTF-16 requires loading and mapping the target source
file, which is IO-heavy. -/
charUtf16 : Nat
endPos : Position
/-- See `charUtf16`. -/
endCharUtf16 : Nat
deriving Inhabited, DecidableEq, Repr
instance : ToExpr DeclarationRange where
toExpr r := mkAppN (mkConst ``DeclarationRange.mk) #[toExpr r.pos, toExpr r.charUtf16, toExpr r.endPos, toExpr r.endCharUtf16]
toTypeExpr := mkConst ``DeclarationRange
structure DeclarationRanges where
range : DeclarationRange
selectionRange : DeclarationRange
deriving Inhabited, Repr
instance : ToExpr DeclarationRanges where
toExpr r := mkAppN (mkConst ``DeclarationRanges.mk) #[toExpr r.range, toExpr r.selectionRange]
toTypeExpr := mkConst ``DeclarationRanges
builtin_initialize builtinDeclRanges : IO.Ref (NameMap DeclarationRanges) ← IO.mkRef {}
builtin_initialize declRangeExt : MapDeclarationExtension DeclarationRanges ← mkMapDeclarationExtension `declranges
def addBuiltinDeclarationRanges (declName : Name) (declRanges : DeclarationRanges) : IO Unit :=
builtinDeclRanges.modify (·.insert declName declRanges)
def addDeclarationRanges [MonadEnv m] (declName : Name) (declRanges : DeclarationRanges) : m Unit :=
modifyEnv fun env => declRangeExt.insert env declName declRanges
def findDeclarationRangesCore? [Monad m] [MonadEnv m] (declName : Name) : m (Option DeclarationRanges) :=
return declRangeExt.find? (← getEnv) declName
def findDeclarationRanges? [Monad m] [MonadEnv m] [MonadLiftT IO m] (declName : Name) : m (Option DeclarationRanges) := do
let env ← getEnv
let ranges ← if isAuxRecursor env declName || isNoConfusion env declName || (← isRec declName) then
findDeclarationRangesCore? declName.getPrefix
else
findDeclarationRangesCore? declName
match ranges with
| none => return (← builtinDeclRanges.get (m := IO)).find? declName
| some _ => return ranges
end Lean
|
c99e3e5351b0840d2cce5a2e9fe63a70f4422a33
|
a975e2962782fb953969766cc7133ba18aaa60c9
|
/src/alc.lean
|
e5ce602f4a022379627d58fa9d08f12a79b37fb8
|
[] |
no_license
|
leodemoura/alc-lean
|
f3d3efa0f11b0a663ea74c74c10085212ba52295
|
6e3fce980ec3bb95aeda667062da86a45036fce9
|
refs/heads/master
| 1,678,082,711,848
| 1,612,907,314,000
| 1,612,907,314,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 2,873
|
lean
|
import data.set
open set
namespace ALC
inductive Role (AtomicRole : Type) : Type
| Atomic : AtomicRole → Role
inductive Concept (AtomicConcept AtomicRole : Type) : Type
| TopConcept : Concept
| BottomConcept : Concept
| Atomic : AtomicConcept → Concept
| Negation : Concept → Concept
| Intersection : Concept → Concept → Concept
| Union : Concept → Concept → Concept
| Some : Role AtomicRole → Concept → Concept
| Every : Role AtomicRole → Concept → Concept
open Concept Role
-- notation `⊤` := Concept.TopConcept -- \top
-- notation `⊥` := Concept.BottomConcept -- \bot
-- prefix `¬` := Concept.Negation -- \neg
-- infix `⊓` :51 := Concept.Intersection -- \sqcap
-- infix `⊔` :51 := Concept.Union -- \sqcup
-- notation `Some` R . C := Concept.Ex R C
-- notation `Only` R . C := Concept.Al R C
-- interpretation structure
structure Interpretation (AtomicConcept AtomicRole : Type) :=
mk :: (δ : Type)
(atom_C : AtomicConcept → set δ)
(atom_R : AtomicRole → set (δ × δ))
variables {AtomicConcept AtomicRole : Type}
-- role interpretation
definition r_interp {I : Interpretation AtomicConcept AtomicRole} :
Role AtomicRole → set (I.δ × I.δ)
| (Role.Atomic R) := I.atom_R R
-- concept interpretation
definition interp {I : Interpretation AtomicConcept AtomicRole} :
Concept AtomicConcept AtomicRole → set I.δ
| TopConcept := univ
| BottomConcept := ∅
| (Atomic C) := I.atom_C C
| (Negation C) := compl (interp C)
| (Intersection C1 C2) := (interp C1) ∩ (interp C2)
| (Union C1 C2) := (interp C1) ∪ (interp C2)
| (Some R C) := { a: I.δ | ∃ b : I.δ,
(a, b) ∈ (@r_interp _ _ I R) ∧ b ∈ (interp C) }
| (Every R C) := { a: I.δ | ∀ b : I.δ,
(a, b) ∈ (@r_interp _ _ I R) → b ∈ (interp C) }
end ALC
namespace test
open ALC
open ALC.Concept
inductive ac : Type
| man : ac
| woman : ac
inductive ar : Type
| hasChild : ar
open ac
open ar
def ic : ac → set ℕ
| man := ({2,4} : set ℕ)
| woman := ({1,3} : set ℕ)
def ir : ar → set (ℕ × ℕ)
| hasChild := ({(1,2),(4,3)} : set (ℕ × ℕ))
def i := Interpretation.mk ℕ ic ir
#check Concept.Atomic man
-- ∀ hasChild.man (the concept of all things such that all its fillers
-- for the role 'hasChild' are of type 'man')
#reduce @interp ac ar i (Every (Role.Atomic hasChild) (Concept.Atomic man))
#reduce interp (Every (Role.Atomic hasChild) (Concept.Atomic man))
end test
/- References:
- DL Prime: https://arxiv.org/abs/1201.4089v3
-/
|
aaf3a33d2acad351c22765d984b2986e7cea8101
|
4efff1f47634ff19e2f786deadd394270a59ecd2
|
/src/analysis/specific_limits.lean
|
72b1360fa1665d57d8b192794b6381753900ef59
|
[
"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
| 30,200
|
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
A collection of specific limit computations.
-/
import analysis.normed_space.basic
import algebra.geom_sum
import topology.instances.ennreal
import tactic.ring_exp
noncomputable theory
open_locale classical topological_space
open classical function filter finset metric
open_locale big_operators
variables {α : Type*} {β : Type*} {ι : Type*}
lemma tendsto_norm_at_top_at_top : tendsto (norm : ℝ → ℝ) at_top at_top :=
tendsto_abs_at_top_at_top
/-- If a function tends to infinity along a filter, then this function multiplied by a positive
constant (on the left) also tends to infinity. The archimedean assumption is convenient to get a
statement that works on `ℕ`, `ℤ` and `ℝ`, although not necessary (a version in ordered fields is
given in `tendsto_at_top_mul_left'`). -/
lemma tendsto_at_top_mul_left [decidable_linear_ordered_semiring α] [archimedean α]
{l : filter β} {r : α} (hr : 0 < r) {f : β → α} (hf : tendsto f l at_top) :
tendsto (λx, r * f x) l at_top :=
begin
apply (tendsto_at_top _ _).2 (λb, _),
obtain ⟨n : ℕ, hn : 1 ≤ n •ℕ r⟩ := archimedean.arch 1 hr,
have hn' : 1 ≤ r * n, by rwa nsmul_eq_mul' at hn,
filter_upwards [(tendsto_at_top _ _).1 hf (n * max b 0)],
assume x hx,
calc b ≤ 1 * max b 0 : by { rw [one_mul], exact le_max_left _ _ }
... ≤ (r * n) * max b 0 : mul_le_mul_of_nonneg_right hn' (le_max_right _ _)
... = r * (n * max b 0) : by rw [mul_assoc]
... ≤ r * f x : mul_le_mul_of_nonneg_left hx (le_of_lt hr)
end
/-- If a function tends to infinity along a filter, then this function multiplied by a positive
constant (on the right) also tends to infinity. The archimedean assumption is convenient to get a
statement that works on `ℕ`, `ℤ` and `ℝ`, although not necessary (a version in ordered fields is
given in `tendsto_at_top_mul_right'`). -/
lemma tendsto_at_top_mul_right [decidable_linear_ordered_semiring α] [archimedean α]
{l : filter β} {r : α} (hr : 0 < r) {f : β → α} (hf : tendsto f l at_top) :
tendsto (λx, f x * r) l at_top :=
begin
apply (tendsto_at_top _ _).2 (λb, _),
obtain ⟨n : ℕ, hn : 1 ≤ n •ℕ r⟩ := archimedean.arch 1 hr,
have hn' : 1 ≤ (n : α) * r, by rwa nsmul_eq_mul at hn,
filter_upwards [(tendsto_at_top _ _).1 hf (max b 0 * n)],
assume x hx,
calc b ≤ max b 0 * 1 : by { rw [mul_one], exact le_max_left _ _ }
... ≤ max b 0 * (n * r) : mul_le_mul_of_nonneg_left hn' (le_max_right _ _)
... = (max b 0 * n) * r : by rw [mul_assoc]
... ≤ f x * r : mul_le_mul_of_nonneg_right hx (le_of_lt hr)
end
/-- If a function tends to infinity along a filter, then this function multiplied by a positive
constant (on the left) also tends to infinity. For a version working in `ℕ` or `ℤ`, use
`tendsto_at_top_mul_left` instead. -/
lemma tendsto_at_top_mul_left' [linear_ordered_field α]
{l : filter β} {r : α} (hr : 0 < r) {f : β → α} (hf : tendsto f l at_top) :
tendsto (λx, r * f x) l at_top :=
begin
apply (tendsto_at_top _ _).2 (λb, _),
filter_upwards [(tendsto_at_top _ _).1 hf (b/r)],
assume x hx,
simpa [div_le_iff' hr] using hx
end
/-- If a function tends to infinity along a filter, then this function multiplied by a positive
constant (on the right) also tends to infinity. For a version working in `ℕ` or `ℤ`, use
`tendsto_at_top_mul_right` instead. -/
lemma tendsto_at_top_mul_right' [linear_ordered_field α]
{l : filter β} {r : α} (hr : 0 < r) {f : β → α} (hf : tendsto f l at_top) :
tendsto (λx, f x * r) l at_top :=
by simpa [mul_comm] using tendsto_at_top_mul_left' hr hf
/-- If a function tends to infinity along a filter, then this function divided by a positive
constant also tends to infinity. -/
lemma tendsto_at_top_div [linear_ordered_field α]
{l : filter β} {r : α} (hr : 0 < r) {f : β → α} (hf : tendsto f l at_top) :
tendsto (λx, f x / r) l at_top :=
tendsto_at_top_mul_right' (inv_pos.2 hr) hf
/-- The function `x ↦ x⁻¹` tends to `+∞` on the right of `0`. -/
lemma tendsto_inv_zero_at_top [discrete_linear_ordered_field α] [topological_space α]
[order_topology α] : tendsto (λx:α, x⁻¹) (𝓝[set.Ioi (0:α)] 0) at_top :=
begin
apply (tendsto_at_top _ _).2 (λb, _),
refine mem_nhds_within_Ioi_iff_exists_Ioo_subset.2 ⟨(max b 1)⁻¹, by simp [zero_lt_one], λx hx, _⟩,
calc b ≤ max b 1 : le_max_left _ _
... ≤ x⁻¹ : begin
apply (le_inv _ hx.1).2 (le_of_lt hx.2),
exact lt_of_lt_of_le zero_lt_one (le_max_right _ _)
end
end
/-- The function `r ↦ r⁻¹` tends to `0` on the right as `r → +∞`. -/
lemma tendsto_inv_at_top_zero' [discrete_linear_ordered_field α] [topological_space α]
[order_topology α] : tendsto (λr:α, r⁻¹) at_top (𝓝[set.Ioi (0:α)] 0) :=
begin
assume s hs,
rw mem_nhds_within_Ioi_iff_exists_Ioc_subset at hs,
rcases hs with ⟨C, C0, hC⟩,
change 0 < C at C0,
refine filter.mem_map.2 (mem_sets_of_superset (mem_at_top C⁻¹) (λ x hx, hC _)),
have : 0 < x, from lt_of_lt_of_le (inv_pos.2 C0) hx,
exact ⟨inv_pos.2 this, (inv_le C0 this).1 hx⟩
end
lemma tendsto_inv_at_top_zero [discrete_linear_ordered_field α] [topological_space α]
[order_topology α] : tendsto (λr:α, r⁻¹) at_top (𝓝 0) :=
tendsto_inv_at_top_zero'.mono_right inf_le_left
lemma summable_of_absolute_convergence_real {f : ℕ → ℝ} :
(∃r, tendsto (λn, (∑ i in range n, abs (f i))) at_top (𝓝 r)) → summable f
| ⟨r, hr⟩ :=
begin
refine summable_of_summable_norm ⟨r, (has_sum_iff_tendsto_nat_of_nonneg _ _).2 _⟩,
exact assume i, norm_nonneg _,
simpa only using hr
end
lemma tendsto_inverse_at_top_nhds_0_nat : tendsto (λ n : ℕ, (n : ℝ)⁻¹) at_top (𝓝 0) :=
tendsto_inv_at_top_zero.comp (tendsto_coe_nat_real_at_top_iff.2 tendsto_id)
lemma tendsto_const_div_at_top_nhds_0_nat (C : ℝ) : tendsto (λ n : ℕ, C / n) at_top (𝓝 0) :=
by simpa only [mul_zero] using tendsto_const_nhds.mul tendsto_inverse_at_top_nhds_0_nat
lemma nnreal.tendsto_inverse_at_top_nhds_0_nat : tendsto (λ n : ℕ, (n : nnreal)⁻¹) at_top (𝓝 0) :=
by { rw ← nnreal.tendsto_coe, convert tendsto_inverse_at_top_nhds_0_nat, simp }
lemma nnreal.tendsto_const_div_at_top_nhds_0_nat (C : nnreal) :
tendsto (λ n : ℕ, C / n) at_top (𝓝 0) :=
by simpa using tendsto_const_nhds.mul nnreal.tendsto_inverse_at_top_nhds_0_nat
lemma tendsto_one_div_add_at_top_nhds_0_nat :
tendsto (λ n : ℕ, 1 / ((n : ℝ) + 1)) at_top (𝓝 0) :=
suffices tendsto (λ n : ℕ, 1 / (↑(n + 1) : ℝ)) at_top (𝓝 0), by simpa,
(tendsto_add_at_top_iff_nat 1).2 (tendsto_const_div_at_top_nhds_0_nat 1)
/-! ### Powers -/
lemma tendsto_add_one_pow_at_top_at_top_of_pos [linear_ordered_semiring α] [archimedean α] {r : α}
(h : 0 < r) :
tendsto (λ n:ℕ, (r + 1)^n) at_top at_top :=
tendsto_at_top_at_top_of_monotone' (λ n m, pow_le_pow (le_add_of_nonneg_left (le_of_lt h))) $
not_bdd_above_iff.2 $ λ x, set.exists_range_iff.2 $ add_one_pow_unbounded_of_pos _ h
lemma tendsto_pow_at_top_at_top_of_one_lt [linear_ordered_ring α] [archimedean α]
{r : α} (h : 1 < r) :
tendsto (λn:ℕ, r ^ n) at_top at_top :=
sub_add_cancel r 1 ▸ tendsto_add_one_pow_at_top_at_top_of_pos (sub_pos.2 h)
lemma nat.tendsto_pow_at_top_at_top_of_one_lt {m : ℕ} (h : 1 < m) :
tendsto (λn:ℕ, m ^ n) at_top at_top :=
begin
simp only [← nat.pow_eq_pow],
exact nat.sub_add_cancel (le_of_lt h) ▸
tendsto_add_one_pow_at_top_at_top_of_pos (nat.sub_pos_of_lt h)
end
lemma lim_norm_zero' {𝕜 : Type*} [normed_group 𝕜] :
tendsto (norm : 𝕜 → ℝ) (𝓝[{x | x ≠ 0}] 0) (𝓝[set.Ioi 0] 0) :=
lim_norm_zero.inf $ tendsto_principal_principal.2 $ λ x hx, norm_pos_iff.2 hx
lemma normed_field.tendsto_norm_inverse_nhds_within_0_at_top {𝕜 : Type*} [normed_field 𝕜] :
tendsto (λ x:𝕜, ∥x⁻¹∥) (𝓝[{x | x ≠ 0}] 0) at_top :=
(tendsto_inv_zero_at_top.comp lim_norm_zero').congr $ λ x, (normed_field.norm_inv x).symm
lemma tendsto_pow_at_top_nhds_0_of_lt_1 {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) :
tendsto (λn:ℕ, r^n) at_top (𝓝 0) :=
by_cases
(assume : r = 0, (tendsto_add_at_top_iff_nat 1).mp $ by simp [pow_succ, this, tendsto_const_nhds])
(assume : r ≠ 0,
have tendsto (λn, (r⁻¹ ^ n)⁻¹) at_top (𝓝 0),
from tendsto_inv_at_top_zero.comp
(tendsto_pow_at_top_at_top_of_one_lt $ one_lt_inv (lt_of_le_of_ne h₁ this.symm) h₂),
tendsto.congr' (univ_mem_sets' $ by simp *) this)
lemma geom_lt {u : ℕ → ℝ} {k : ℝ} (hk : 0 < k) {n : ℕ} (h : ∀ m ≤ n, k*u m < u (m + 1)) :
k^(n + 1) *u 0 < u (n + 1) :=
begin
induction n with n ih,
{ simpa using h 0 (le_refl _) },
have : (∀ (m : ℕ), m ≤ n → k * u m < u (m + 1)),
intros m hm, apply h, exact nat.le_succ_of_le hm,
specialize ih this,
change k ^ (n + 2) * u 0 < u (n + 2),
replace h : k * u (n + 1) < u (n + 2) := h (n+1) (le_refl _),
calc k ^ (n + 2) * u 0 = k*(k ^ (n + 1) * u 0) : by ring_exp
... < k*(u (n + 1)) : mul_lt_mul_of_pos_left ih hk
... < u (n + 2) : h,
end
/-- If a sequence `v` of real numbers satisfies `k*v n < v (n+1)` with `1 < k`,
then it goes to +∞. -/
lemma tendsto_at_top_of_geom_lt {v : ℕ → ℝ} {k : ℝ} (h₀ : 0 < v 0) (hk : 1 < k)
(hu : ∀ n, k*v n < v (n+1)) : tendsto v at_top at_top :=
begin
apply tendsto_at_top_mono,
show ∀ n, k^n*v 0 ≤ v n,
{ intro n,
induction n with n ih,
{ simp },
calc
k ^ (n + 1) * v 0 = k*(k^n*v 0) : by ring_exp
... ≤ k*v n : mul_le_mul_of_nonneg_left ih (by linarith)
... ≤ v (n + 1) : le_of_lt (hu n) },
apply tendsto_at_top_mul_right h₀,
exact tendsto_pow_at_top_at_top_of_one_lt hk,
end
lemma nnreal.tendsto_pow_at_top_nhds_0_of_lt_1 {r : nnreal} (hr : r < 1) :
tendsto (λ n:ℕ, r^n) at_top (𝓝 0) :=
nnreal.tendsto_coe.1 $ by simp only [nnreal.coe_pow, nnreal.coe_zero,
tendsto_pow_at_top_nhds_0_of_lt_1 r.coe_nonneg hr]
lemma ennreal.tendsto_pow_at_top_nhds_0_of_lt_1 {r : ennreal} (hr : r < 1) :
tendsto (λ n:ℕ, r^n) at_top (𝓝 0) :=
begin
rcases ennreal.lt_iff_exists_coe.1 hr with ⟨r, rfl, hr'⟩,
rw [← ennreal.coe_zero],
norm_cast at *,
apply nnreal.tendsto_pow_at_top_nhds_0_of_lt_1 hr
end
/-- In a normed ring, the powers of an element x with `∥x∥ < 1` tend to zero. -/
lemma tendsto_pow_at_top_nhds_0_of_norm_lt_1 {R : Type*} [normed_ring R] {x : R}
(h : ∥x∥ < 1) : tendsto (λ (n : ℕ), x ^ n) at_top (𝓝 0) :=
begin
apply squeeze_zero_norm' (eventually_norm_pow_le x),
exact tendsto_pow_at_top_nhds_0_of_lt_1 (norm_nonneg _) h,
end
lemma tendsto_pow_at_top_nhds_0_of_abs_lt_1 {r : ℝ} (h : abs r < 1) :
tendsto (λn:ℕ, r^n) at_top (𝓝 0) :=
tendsto_pow_at_top_nhds_0_of_norm_lt_1 h
/-! ### Geometric series-/
section geometric
lemma has_sum_geometric_of_lt_1 {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) :
has_sum (λn:ℕ, r ^ n) (1 - r)⁻¹ :=
have r ≠ 1, from ne_of_lt h₂,
have r + -1 ≠ 0,
by rw [←sub_eq_add_neg, ne, sub_eq_iff_eq_add]; simp; assumption,
have tendsto (λn, (r ^ n - 1) * (r - 1)⁻¹) at_top (𝓝 ((0 - 1) * (r - 1)⁻¹)),
from ((tendsto_pow_at_top_nhds_0_of_lt_1 h₁ h₂).sub tendsto_const_nhds).mul tendsto_const_nhds,
have (λ n, (∑ i in range n, r ^ i)) = (λ n, geom_series r n) := rfl,
(has_sum_iff_tendsto_nat_of_nonneg (pow_nonneg h₁) _).mpr $
by simp [neg_inv, geom_sum, div_eq_mul_inv, *] at *
lemma summable_geometric_of_lt_1 {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) : summable (λn:ℕ, r ^ n) :=
⟨_, has_sum_geometric_of_lt_1 h₁ h₂⟩
lemma tsum_geometric_of_lt_1 {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) : (∑'n:ℕ, r ^ n) = (1 - r)⁻¹ :=
(has_sum_geometric_of_lt_1 h₁ h₂).tsum_eq
lemma has_sum_geometric_two : has_sum (λn:ℕ, ((1:ℝ)/2) ^ n) 2 :=
by convert has_sum_geometric_of_lt_1 _ _; norm_num
lemma summable_geometric_two : summable (λn:ℕ, ((1:ℝ)/2) ^ n) :=
⟨_, has_sum_geometric_two⟩
lemma tsum_geometric_two : (∑'n:ℕ, ((1:ℝ)/2) ^ n) = 2 :=
has_sum_geometric_two.tsum_eq
lemma sum_geometric_two_le (n : ℕ) : ∑ (i : ℕ) in range n, (1 / (2 : ℝ)) ^ i ≤ 2 :=
begin
have : ∀ i, 0 ≤ (1 / (2 : ℝ)) ^ i,
{ intro i, apply pow_nonneg, norm_num },
convert sum_le_tsum (range n) (λ i _, this i) summable_geometric_two,
exact tsum_geometric_two.symm
end
lemma has_sum_geometric_two' (a : ℝ) : has_sum (λn:ℕ, (a / 2) / 2 ^ n) a :=
begin
convert has_sum.mul_left (a / 2) (has_sum_geometric_of_lt_1
(le_of_lt one_half_pos) one_half_lt_one),
{ funext n, simp, refl, },
{ norm_num }
end
lemma summable_geometric_two' (a : ℝ) : summable (λ n:ℕ, (a / 2) / 2 ^ n) :=
⟨a, has_sum_geometric_two' a⟩
lemma tsum_geometric_two' (a : ℝ) : (∑' n:ℕ, (a / 2) / 2^n) = a :=
(has_sum_geometric_two' a).tsum_eq
lemma nnreal.has_sum_geometric {r : nnreal} (hr : r < 1) :
has_sum (λ n : ℕ, r ^ n) (1 - r)⁻¹ :=
begin
apply nnreal.has_sum_coe.1,
push_cast,
rw [nnreal.coe_sub (le_of_lt hr)],
exact has_sum_geometric_of_lt_1 r.coe_nonneg hr
end
lemma nnreal.summable_geometric {r : nnreal} (hr : r < 1) : summable (λn:ℕ, r ^ n) :=
⟨_, nnreal.has_sum_geometric hr⟩
lemma tsum_geometric_nnreal {r : nnreal} (hr : r < 1) : (∑'n:ℕ, r ^ n) = (1 - r)⁻¹ :=
(nnreal.has_sum_geometric hr).tsum_eq
/-- The series `pow r` converges to `(1-r)⁻¹`. For `r < 1` the RHS is a finite number,
and for `1 ≤ r` the RHS equals `∞`. -/
lemma ennreal.tsum_geometric (r : ennreal) : (∑'n:ℕ, r ^ n) = (1 - r)⁻¹ :=
begin
cases lt_or_le r 1 with hr hr,
{ rcases ennreal.lt_iff_exists_coe.1 hr with ⟨r, rfl, hr'⟩,
norm_cast at *,
convert ennreal.tsum_coe_eq (nnreal.has_sum_geometric hr),
rw [ennreal.coe_inv $ ne_of_gt $ nnreal.sub_pos.2 hr] },
{ rw [ennreal.sub_eq_zero_of_le hr, ennreal.inv_zero, ennreal.tsum_eq_supr_nat, supr_eq_top],
refine λ a ha, (ennreal.exists_nat_gt (lt_top_iff_ne_top.1 ha)).imp
(λ n hn, lt_of_lt_of_le hn _),
have : ∀ k:ℕ, 1 ≤ r^k, by simpa using canonically_ordered_semiring.pow_le_pow_of_le_left hr,
calc (n:ennreal) = (∑ i in range n, 1) : by rw [sum_const, nsmul_one, card_range]
... ≤ ∑ i in range n, r ^ i : sum_le_sum (λ k _, this k) }
end
variables {K : Type*} [normed_field K] {ξ : K}
lemma has_sum_geometric_of_norm_lt_1 (h : ∥ξ∥ < 1) : has_sum (λn:ℕ, ξ ^ n) (1 - ξ)⁻¹ :=
begin
have xi_ne_one : ξ ≠ 1, by { contrapose! h, simp [h] },
have A : tendsto (λn, (ξ ^ n - 1) * (ξ - 1)⁻¹) at_top (𝓝 ((0 - 1) * (ξ - 1)⁻¹)),
from ((tendsto_pow_at_top_nhds_0_of_norm_lt_1 h).sub tendsto_const_nhds).mul tendsto_const_nhds,
have B : (λ n, (∑ i in range n, ξ ^ i)) = (λ n, geom_series ξ n) := rfl,
rw [has_sum_iff_tendsto_nat_of_summable_norm, B],
{ simpa [geom_sum, xi_ne_one, neg_inv] using A },
{ simp [normed_field.norm_pow, summable_geometric_of_lt_1 (norm_nonneg _) h] }
end
lemma summable_geometric_of_norm_lt_1 (h : ∥ξ∥ < 1) : summable (λn:ℕ, ξ ^ n) :=
⟨_, has_sum_geometric_of_norm_lt_1 h⟩
lemma tsum_geometric_of_norm_lt_1 (h : ∥ξ∥ < 1) : (∑'n:ℕ, ξ ^ n) = (1 - ξ)⁻¹ :=
(has_sum_geometric_of_norm_lt_1 h).tsum_eq
lemma has_sum_geometric_of_abs_lt_1 {r : ℝ} (h : abs r < 1) : has_sum (λn:ℕ, r ^ n) (1 - r)⁻¹ :=
has_sum_geometric_of_norm_lt_1 h
lemma summable_geometric_of_abs_lt_1 {r : ℝ} (h : abs r < 1) : summable (λn:ℕ, r ^ n) :=
summable_geometric_of_norm_lt_1 h
lemma tsum_geometric_of_abs_lt_1 {r : ℝ} (h : abs r < 1) : (∑'n:ℕ, r ^ n) = (1 - r)⁻¹ :=
tsum_geometric_of_norm_lt_1 h
end geometric
/-!
### Sequences with geometrically decaying distance in metric spaces
In this paragraph, we discuss sequences in metric spaces or emetric spaces for which the distance
between two consecutive terms decays geometrically. We show that such sequences are Cauchy
sequences, and bound their distances to the limit. We also discuss series with geometrically
decaying terms.
-/
section edist_le_geometric
variables [emetric_space α] (r C : ennreal) (hr : r < 1) (hC : C ≠ ⊤) {f : ℕ → α}
(hu : ∀n, edist (f n) (f (n+1)) ≤ C * r^n)
include hr hC hu
/-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, `C ≠ ∞`, `r < 1`,
then `f` is a Cauchy sequence.-/
lemma cauchy_seq_of_edist_le_geometric : cauchy_seq f :=
begin
refine cauchy_seq_of_edist_le_of_tsum_ne_top _ hu _,
rw [ennreal.tsum_mul_left, ennreal.tsum_geometric],
refine ennreal.mul_ne_top hC (ennreal.inv_ne_top.2 _),
exact ne_of_gt (ennreal.zero_lt_sub_iff_lt.2 hr)
end
omit hr hC
/-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, then the distance from
`f n` to the limit of `f` is bounded above by `C * r^n / (1 - r)`. -/
lemma edist_le_of_edist_le_geometric_of_tendsto {a : α} (ha : tendsto f at_top (𝓝 a)) (n : ℕ) :
edist (f n) a ≤ (C * r^n) / (1 - r) :=
begin
convert edist_le_tsum_of_edist_le_of_tendsto _ hu ha _,
simp only [pow_add, ennreal.tsum_mul_left, ennreal.tsum_geometric, ennreal.div_def, mul_assoc]
end
/-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, then the distance from
`f 0` to the limit of `f` is bounded above by `C / (1 - r)`. -/
lemma edist_le_of_edist_le_geometric_of_tendsto₀ {a : α} (ha : tendsto f at_top (𝓝 a)) :
edist (f 0) a ≤ C / (1 - r) :=
by simpa only [pow_zero, mul_one] using edist_le_of_edist_le_geometric_of_tendsto r C hu ha 0
end edist_le_geometric
section edist_le_geometric_two
variables [emetric_space α] (C : ennreal) (hC : C ≠ ⊤) {f : ℕ → α}
(hu : ∀n, edist (f n) (f (n+1)) ≤ C / 2^n) {a : α} (ha : tendsto f at_top (𝓝 a))
include hC hu
/-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then `f` is a Cauchy sequence.-/
lemma cauchy_seq_of_edist_le_geometric_two : cauchy_seq f :=
begin
simp only [ennreal.div_def, ennreal.inv_pow] at hu,
refine cauchy_seq_of_edist_le_geometric 2⁻¹ C _ hC hu,
simp [ennreal.one_lt_two]
end
omit hC
include ha
/-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then the distance from
`f n` to the limit of `f` is bounded above by `2 * C * 2^-n`. -/
lemma edist_le_of_edist_le_geometric_two_of_tendsto (n : ℕ) :
edist (f n) a ≤ 2 * C / 2^n :=
begin
simp only [ennreal.div_def, ennreal.inv_pow] at hu,
rw [ennreal.div_def, mul_assoc, mul_comm, ennreal.inv_pow],
convert edist_le_of_edist_le_geometric_of_tendsto 2⁻¹ C hu ha n,
rw [ennreal.one_sub_inv_two, ennreal.inv_inv]
end
/-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then the distance from
`f 0` to the limit of `f` is bounded above by `2 * C`. -/
lemma edist_le_of_edist_le_geometric_two_of_tendsto₀: edist (f 0) a ≤ 2 * C :=
by simpa only [pow_zero, ennreal.div_def, ennreal.inv_one, mul_one]
using edist_le_of_edist_le_geometric_two_of_tendsto C hu ha 0
end edist_le_geometric_two
section le_geometric
variables [metric_space α] {r C : ℝ} (hr : r < 1) {f : ℕ → α}
(hu : ∀n, dist (f n) (f (n+1)) ≤ C * r^n)
include hr hu
lemma aux_has_sum_of_le_geometric : has_sum (λ n : ℕ, C * r^n) (C / (1 - r)) :=
begin
have h0 : 0 ≤ C,
by simpa using le_trans dist_nonneg (hu 0),
rcases eq_or_lt_of_le h0 with rfl | Cpos,
{ simp [has_sum_zero] },
{ have rnonneg: r ≥ 0, from nonneg_of_mul_nonneg_left
(by simpa only [pow_one] using le_trans dist_nonneg (hu 1)) Cpos,
refine has_sum.mul_left C _,
by simpa using has_sum_geometric_of_lt_1 rnonneg hr }
end
variables (r C)
/-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then `f` is a Cauchy sequence.
Note that this lemma does not assume `0 ≤ C` or `0 ≤ r`. -/
lemma cauchy_seq_of_le_geometric : cauchy_seq f :=
cauchy_seq_of_dist_le_of_summable _ hu ⟨_, aux_has_sum_of_le_geometric hr hu⟩
/-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then the distance from
`f n` to the limit of `f` is bounded above by `C * r^n / (1 - r)`. -/
lemma dist_le_of_le_geometric_of_tendsto₀ {a : α} (ha : tendsto f at_top (𝓝 a)) :
dist (f 0) a ≤ C / (1 - r) :=
(aux_has_sum_of_le_geometric hr hu).tsum_eq ▸
dist_le_tsum_of_dist_le_of_tendsto₀ _ hu ⟨_, aux_has_sum_of_le_geometric hr hu⟩ ha
/-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then the distance from
`f 0` to the limit of `f` is bounded above by `C / (1 - r)`. -/
lemma dist_le_of_le_geometric_of_tendsto {a : α} (ha : tendsto f at_top (𝓝 a)) (n : ℕ) :
dist (f n) a ≤ (C * r^n) / (1 - r) :=
begin
have := aux_has_sum_of_le_geometric hr hu,
convert dist_le_tsum_of_dist_le_of_tendsto _ hu ⟨_, this⟩ ha n,
simp only [pow_add, mul_left_comm C, mul_div_right_comm],
rw [mul_comm],
exact (this.mul_left _).tsum_eq.symm
end
omit hr hu
variable (hu₂ : ∀ n, dist (f n) (f (n+1)) ≤ (C / 2) / 2^n)
/-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then `f` is a Cauchy sequence. -/
lemma cauchy_seq_of_le_geometric_two : cauchy_seq f :=
cauchy_seq_of_dist_le_of_summable _ hu₂ $ ⟨_, has_sum_geometric_two' C⟩
/-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then the distance from
`f 0` to the limit of `f` is bounded above by `C`. -/
lemma dist_le_of_le_geometric_two_of_tendsto₀ {a : α} (ha : tendsto f at_top (𝓝 a)) :
dist (f 0) a ≤ C :=
(tsum_geometric_two' C) ▸ dist_le_tsum_of_dist_le_of_tendsto₀ _ hu₂ (summable_geometric_two' C) ha
include hu₂
/-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then the distance from
`f n` to the limit of `f` is bounded above by `C / 2^n`. -/
lemma dist_le_of_le_geometric_two_of_tendsto {a : α} (ha : tendsto f at_top (𝓝 a)) (n : ℕ) :
dist (f n) a ≤ C / 2^n :=
begin
convert dist_le_tsum_of_dist_le_of_tendsto _ hu₂ (summable_geometric_two' C) ha n,
simp only [add_comm n, pow_add, (div_div_eq_div_mul _ _ _).symm],
symmetry,
exact ((has_sum_geometric_two' C).mul_right _).tsum_eq
end
end le_geometric
section summable_le_geometric
variables [normed_group α] {r C : ℝ} {f : ℕ → α}
lemma dist_partial_sum_le_of_le_geometric (hf : ∀n, ∥f n∥ ≤ C * r^n) (n : ℕ) :
dist (∑ i in range n, f i) (∑ i in range (n+1), f i) ≤ C * r ^ n :=
begin
rw [sum_range_succ, dist_eq_norm, ← norm_neg],
convert hf n,
rw [neg_sub, add_sub_cancel]
end
/-- If `∥f n∥ ≤ C * r ^ n` for all `n : ℕ` and some `r < 1`, then the partial sums of `f` form a
Cauchy sequence. This lemma does not assume `0 ≤ r` or `0 ≤ C`. -/
lemma cauchy_seq_finset_of_geometric_bound (hr : r < 1) (hf : ∀n, ∥f n∥ ≤ C * r^n) :
cauchy_seq (λ s : finset (ℕ), ∑ x in s, f x) :=
cauchy_seq_finset_of_norm_bounded _
(aux_has_sum_of_le_geometric hr (dist_partial_sum_le_of_le_geometric hf)).summable hf
/-- If `∥f n∥ ≤ C * r ^ n` for all `n : ℕ` and some `r < 1`, then the partial sums of `f` are within
distance `C * r ^ n / (1 - r)` of the sum of the series. This lemma does not assume `0 ≤ r` or
`0 ≤ C`. -/
lemma norm_sub_le_of_geometric_bound_of_has_sum (hr : r < 1) (hf : ∀n, ∥f n∥ ≤ C * r^n)
{a : α} (ha : has_sum f a) (n : ℕ) :
∥(∑ x in finset.range n, f x) - a∥ ≤ (C * r ^ n) / (1 - r) :=
begin
rw ← dist_eq_norm,
apply dist_le_of_le_geometric_of_tendsto r C hr (dist_partial_sum_le_of_le_geometric hf),
exact ha.tendsto_sum_nat
end
end summable_le_geometric
section normed_ring_geometric
variables {R : Type*} [normed_ring R] [complete_space R]
open normed_space
/-- A geometric series in a complete normed ring is summable.
Proved above (same name, different namespace) for not-necessarily-complete normed fields. -/
lemma normed_ring.summable_geometric_of_norm_lt_1
(x : R) (h : ∥x∥ < 1) : summable (λ (n:ℕ), x ^ n) :=
begin
have h1 : summable (λ (n:ℕ), ∥x∥ ^ n) := summable_geometric_of_lt_1 (norm_nonneg _) h,
refine summable_of_norm_bounded_eventually _ h1 _,
rw nat.cofinite_eq_at_top,
exact eventually_norm_pow_le x,
end
/-- Bound for the sum of a geometric series in a normed ring. This formula does not assume that the
normed ring satisfies the axiom `∥1∥ = 1`. -/
lemma normed_ring.tsum_geometric_of_norm_lt_1
(x : R) (h : ∥x∥ < 1) : ∥(∑' (n:ℕ), x ^ n)∥ ≤ ∥(1:R)∥ - 1 + (1 - ∥x∥)⁻¹ :=
begin
rw tsum_eq_zero_add (normed_ring.summable_geometric_of_norm_lt_1 x h),
simp only [pow_zero],
refine le_trans (norm_add_le _ _) _,
have : ∥(∑' (b : ℕ), (λ n, x ^ (n + 1)) b)∥ ≤ (1 - ∥x∥)⁻¹ - 1,
{ refine tsum_of_norm_bounded _ (λ b, norm_pow_le _ (nat.succ_pos b)),
convert (has_sum_nat_add_iff' 1).mpr (has_sum_geometric_of_lt_1 (norm_nonneg x) h),
simp },
linarith
end
lemma geom_series_mul_neg (x : R) (h : ∥x∥ < 1) :
(∑' (i:ℕ), x ^ i) * (1 - x) = 1 :=
begin
have := has_sum_of_bounded_monoid_hom_of_summable
(normed_ring.summable_geometric_of_norm_lt_1 x h) (∥1 - x∥)
(mul_right_bound (1 - x)),
refine tendsto_nhds_unique this.tendsto_sum_nat _,
have : tendsto (λ (n : ℕ), 1 - x ^ n) at_top (nhds 1),
{ simpa using tendsto_const_nhds.sub
(tendsto_pow_at_top_nhds_0_of_norm_lt_1 h) },
convert ← this,
ext n,
rw [←geom_sum_mul_neg, geom_series_def, finset.sum_mul],
simp,
end
lemma mul_neg_geom_series (x : R) (h : ∥x∥ < 1) :
(1 - x) * (∑' (i:ℕ), x ^ i) = 1 :=
begin
have := has_sum_of_bounded_monoid_hom_of_summable
(normed_ring.summable_geometric_of_norm_lt_1 x h) (∥1 - x∥)
(mul_left_bound (1 - x)),
refine tendsto_nhds_unique this.tendsto_sum_nat _,
have : tendsto (λ (n : ℕ), 1 - x ^ n) at_top (nhds 1),
{ simpa using tendsto_const_nhds.sub
(tendsto_pow_at_top_nhds_0_of_norm_lt_1 h) },
convert ← this,
ext n,
rw [←mul_neg_geom_sum, geom_series_def, finset.mul_sum],
simp,
end
end normed_ring_geometric
/-! ### Positive sequences with small sums on encodable types -/
/-- For any positive `ε`, define on an encodable type a positive sequence with sum less than `ε` -/
def pos_sum_of_encodable {ε : ℝ} (hε : 0 < ε)
(ι) [encodable ι] : {ε' : ι → ℝ // (∀ i, 0 < ε' i) ∧ ∃ c, has_sum ε' c ∧ c ≤ ε} :=
begin
let f := λ n, (ε / 2) / 2 ^ n,
have hf : has_sum f ε := has_sum_geometric_two' _,
have f0 : ∀ n, 0 < f n := λ n, div_pos (half_pos hε) (pow_pos two_pos _),
refine ⟨f ∘ encodable.encode, λ i, f0 _, _⟩,
rcases hf.summable.comp_injective (@encodable.encode_injective ι _) with ⟨c, hg⟩,
refine ⟨c, hg, has_sum_le_inj _ (@encodable.encode_injective ι _) _ _ hg hf⟩,
{ assume i _, exact le_of_lt (f0 _) },
{ assume n, exact le_refl _ }
end
namespace nnreal
theorem exists_pos_sum_of_encodable {ε : nnreal} (hε : 0 < ε) (ι) [encodable ι] :
∃ ε' : ι → nnreal, (∀ i, 0 < ε' i) ∧ ∃c, has_sum ε' c ∧ c < ε :=
let ⟨a, a0, aε⟩ := dense hε in
let ⟨ε', hε', c, hc, hcε⟩ := pos_sum_of_encodable a0 ι in
⟨ λi, ⟨ε' i, le_of_lt $ hε' i⟩, assume i, nnreal.coe_lt_coe.2 $ hε' i,
⟨c, has_sum_le (assume i, le_of_lt $ hε' i) has_sum_zero hc ⟩, nnreal.has_sum_coe.1 hc,
lt_of_le_of_lt (nnreal.coe_le_coe.1 hcε) aε ⟩
end nnreal
namespace ennreal
theorem exists_pos_sum_of_encodable {ε : ennreal} (hε : 0 < ε) (ι) [encodable ι] :
∃ ε' : ι → nnreal, (∀ i, 0 < ε' i) ∧ (∑' i, (ε' i : ennreal)) < ε :=
begin
rcases dense hε with ⟨r, h0r, hrε⟩,
rcases lt_iff_exists_coe.1 hrε with ⟨x, rfl, hx⟩,
rcases nnreal.exists_pos_sum_of_encodable (coe_lt_coe.1 h0r) ι with ⟨ε', hp, c, hc, hcr⟩,
exact ⟨ε', hp, (ennreal.tsum_coe_eq hc).symm ▸ lt_trans (coe_lt_coe.2 hcr) hrε⟩
end
end ennreal
/-!
### Harmonic series
Here we define the harmonic series and prove some basic lemmas about it,
leading to a proof of its divergence to +∞ -/
/-- The harmonic series `1 + 1/2 + 1/3 + ... + 1/n`-/
def harmonic_series (n : ℕ) : ℝ :=
∑ i in range n, 1/(i+1 : ℝ)
lemma mono_harmonic : monotone harmonic_series :=
begin
intros p q hpq,
apply sum_le_sum_of_subset_of_nonneg,
rwa range_subset,
intros x h _,
exact le_of_lt nat.one_div_pos_of_nat,
end
lemma half_le_harmonic_double_sub_harmonic (n : ℕ) (hn : 0 < n) :
1/2 ≤ harmonic_series (2*n) - harmonic_series n :=
begin
suffices : harmonic_series n + 1 / 2 ≤ harmonic_series (n + n),
{ rw two_mul,
linarith },
have : harmonic_series n + ∑ k in Ico n (n + n), 1/(k + 1 : ℝ) = harmonic_series (n + n) :=
sum_range_add_sum_Ico _ (show n ≤ n+n, by linarith),
rw [← this, add_le_add_iff_left],
have : ∑ k in Ico n (n + n), 1/(n+n : ℝ) = 1/2,
{ have : (n : ℝ) + n ≠ 0,
{ norm_cast, linarith },
rw [sum_const, Ico.card],
field_simp [this],
ring },
rw ← this,
apply sum_le_sum,
intros x hx,
rw one_div_le_one_div,
{ exact_mod_cast nat.succ_le_of_lt (Ico.mem.mp hx).2 },
{ norm_cast, linarith },
{ exact_mod_cast nat.zero_lt_succ x }
end
lemma self_div_two_le_harmonic_two_pow (n : ℕ) : (n / 2 : ℝ) ≤ harmonic_series (2^n) :=
begin
induction n with n hn,
unfold harmonic_series,
simp only [one_div, nat.cast_zero, zero_div, nat.cast_succ, sum_singleton,
inv_one, zero_add, nat.pow_zero, range_one, zero_le_one],
have : harmonic_series (2^n) + 1 / 2 ≤ harmonic_series (2^(n+1)),
{ have := half_le_harmonic_double_sub_harmonic (2^n) (by {apply nat.pow_pos, linarith}),
rw [nat.mul_comm, ← nat.pow_succ] at this,
linarith },
apply le_trans _ this,
rw (show (n.succ / 2 : ℝ) = (n/2 : ℝ) + (1/2), by field_simp),
linarith,
end
/-- The harmonic series diverges to +∞ -/
theorem harmonic_tendsto_at_top : tendsto harmonic_series at_top at_top :=
begin
suffices : tendsto (λ n : ℕ, harmonic_series (2^n)) at_top at_top, by
{ exact tendsto_at_top_of_monotone_of_subseq mono_harmonic this },
apply tendsto_at_top_mono self_div_two_le_harmonic_two_pow,
apply tendsto_at_top_div,
norm_num,
exact tendsto_coe_nat_real_at_top_at_top
end
|
e21611189b05dff0e3a4d5ca5307d49e85cc5179
|
6329dd15b8fd567a4737f2dacd02bd0e8c4b3ae4
|
/src/game/world1/level9.lean
|
4fa87841f604bc69e6094ab2e6f984d0375cd581
|
[
"Apache-2.0"
] |
permissive
|
agusakov/mathematics_in_lean_game
|
76e455a688a8826b05160c16c0490b9e3d39f071
|
ad45fd42148f2203b973537adec7e8a48677ba2a
|
refs/heads/master
| 1,666,147,402,274
| 1,592,119,137,000
| 1,592,119,137,000
| 272,111,226
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 564
|
lean
|
import data.real.basic --imports the real numbers
import tactic.maths_in_lean_game -- hide
namespace calculating -- hide
/- Theorem : sub_self
-/
/-
#Calculating
## Level 9: Practice
For this problem, you can use the theorem `sub_self`,
where `sub_self a` is the identity `a - a = 0`.
-/
/- Lemma : no-side-bar
For all natural numbers $a$, we have
$$a + \operatorname{succ}(0) = \operatorname{succ}(a).$$
-/
lemma example9 (a b c d : ℝ) (hyp : c = b * a - d) (hyp' : d = a * b) : c = 0 :=
begin [maths_in_lean_game]
sorry
end
end calculating -- hide
|
a9ac52920d1f27304286b366babf2bd912d7e462
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/data/list/erase_dup.lean
|
38a4a9619905ca37ee78f27b4ffb0df379c825fc
|
[
"Apache-2.0"
] |
permissive
|
jjgarzella/mathlib
|
96a345378c4e0bf26cf604aed84f90329e4896a2
|
395d8716c3ad03747059d482090e2bb97db612c8
|
refs/heads/master
| 1,686,480,124,379
| 1,625,163,323,000
| 1,625,163,323,000
| 281,190,421
| 2
| 0
|
Apache-2.0
| 1,595,268,170,000
| 1,595,268,169,000
| null |
UTF-8
|
Lean
| false
| false
| 2,545
|
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.list.nodup
/-!
# Erasure of duplicates in a list
This file proves basic results about `list.erase_dup` (definition in `data.list.defs`).
`erase_dup l` returns `l` without its duplicates. It keeps the earliest (that is, rightmost)
occurrence of each.
## Tags
duplicate, multiplicity, nodup, `nub`
-/
universes u
namespace list
variables {α : Type u} [decidable_eq α]
@[simp] theorem erase_dup_nil : erase_dup [] = ([] : list α) := rfl
theorem erase_dup_cons_of_mem' {a : α} {l : list α} (h : a ∈ erase_dup l) :
erase_dup (a :: l) = erase_dup l :=
pw_filter_cons_of_neg $ by simpa only [forall_mem_ne] using h
theorem erase_dup_cons_of_not_mem' {a : α} {l : list α} (h : a ∉ erase_dup l) :
erase_dup (a :: l) = a :: erase_dup l :=
pw_filter_cons_of_pos $ by simpa only [forall_mem_ne] using h
@[simp] theorem mem_erase_dup {a : α} {l : list α} : a ∈ erase_dup l ↔ a ∈ l :=
by simpa only [erase_dup, forall_mem_ne, not_not] using not_congr (@forall_mem_pw_filter α (≠) _
(λ x y z xz, not_and_distrib.1 $ mt (and.rec eq.trans) xz) a l)
@[simp] theorem erase_dup_cons_of_mem {a : α} {l : list α} (h : a ∈ l) :
erase_dup (a :: l) = erase_dup l :=
erase_dup_cons_of_mem' $ mem_erase_dup.2 h
@[simp] theorem erase_dup_cons_of_not_mem {a : α} {l : list α} (h : a ∉ l) :
erase_dup (a :: l) = a :: erase_dup l :=
erase_dup_cons_of_not_mem' $ mt mem_erase_dup.1 h
theorem erase_dup_sublist : ∀ (l : list α), erase_dup l <+ l := pw_filter_sublist
theorem erase_dup_subset : ∀ (l : list α), erase_dup l ⊆ l := pw_filter_subset
theorem subset_erase_dup (l : list α) : l ⊆ erase_dup l :=
λ a, mem_erase_dup.2
theorem nodup_erase_dup : ∀ l : list α, nodup (erase_dup l) := pairwise_pw_filter
theorem erase_dup_eq_self {l : list α} : erase_dup l = l ↔ nodup l := pw_filter_eq_self
@[simp] theorem erase_dup_idempotent {l : list α} : erase_dup (erase_dup l) = erase_dup l :=
pw_filter_idempotent
theorem erase_dup_append (l₁ l₂ : list α) : erase_dup (l₁ ++ l₂) = l₁ ∪ erase_dup l₂ :=
begin
induction l₁ with a l₁ IH, {refl}, rw [cons_union, ← IH],
show erase_dup (a :: (l₁ ++ l₂)) = insert a (erase_dup (l₁ ++ l₂)),
by_cases a ∈ erase_dup (l₁ ++ l₂);
[ rw [erase_dup_cons_of_mem' h, insert_of_mem h],
rw [erase_dup_cons_of_not_mem' h, insert_of_not_mem h]]
end
end list
|
26fbe08e304ff7637b68fd3c9ba53df5c0b27cdd
|
e0f9ba56b7fedc16ef8697f6caeef5898b435143
|
/src/topology/homeomorph.lean
|
e9947077d9d8712b4c20225cfe7e0491f04672f6
|
[
"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
| 7,203
|
lean
|
/-
Copyright (c) 2019 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Sébastien Gouëzel, Zhouhang Zhou, Reid Barton
-/
import topology.dense_embedding
open set
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
/-- α and β are homeomorph, also called topological isomoph -/
structure homeomorph (α : Type*) (β : Type*) [topological_space α] [topological_space β]
extends α ≃ β :=
(continuous_to_fun : continuous to_fun)
(continuous_inv_fun : continuous inv_fun)
infix ` ≃ₜ `:25 := homeomorph
namespace homeomorph
variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
instance : has_coe_to_fun (α ≃ₜ β) := ⟨λ_, α → β, λe, e.to_equiv⟩
lemma coe_eq_to_equiv (h : α ≃ₜ β) (a : α) : h a = h.to_equiv a := rfl
/-- Identity map is a homeomorphism. -/
protected def refl (α : Type*) [topological_space α] : α ≃ₜ α :=
{ continuous_to_fun := continuous_id, continuous_inv_fun := continuous_id, .. equiv.refl α }
/-- Composition of two homeomorphisms. -/
protected def trans (h₁ : α ≃ₜ β) (h₂ : β ≃ₜ γ) : α ≃ₜ γ :=
{ continuous_to_fun := h₂.continuous_to_fun.comp h₁.continuous_to_fun,
continuous_inv_fun := h₁.continuous_inv_fun.comp h₂.continuous_inv_fun,
.. equiv.trans h₁.to_equiv h₂.to_equiv }
/-- Inverse of a homeomorphism. -/
protected def symm (h : α ≃ₜ β) : β ≃ₜ α :=
{ continuous_to_fun := h.continuous_inv_fun,
continuous_inv_fun := h.continuous_to_fun,
.. h.to_equiv.symm }
protected lemma continuous (h : α ≃ₜ β) : continuous h := h.continuous_to_fun
lemma symm_comp_self (h : α ≃ₜ β) : ⇑h.symm ∘ ⇑h = id :=
funext $ assume a, h.to_equiv.left_inv a
lemma self_comp_symm (h : α ≃ₜ β) : ⇑h ∘ ⇑h.symm = id :=
funext $ assume a, h.to_equiv.right_inv a
lemma range_coe (h : α ≃ₜ β) : range h = univ :=
eq_univ_of_forall $ assume b, ⟨h.symm b, congr_fun h.self_comp_symm b⟩
lemma image_symm (h : α ≃ₜ β) : image h.symm = preimage h :=
funext h.symm.to_equiv.image_eq_preimage
lemma preimage_symm (h : α ≃ₜ β) : preimage h.symm = image h :=
(funext h.to_equiv.image_eq_preimage).symm
lemma induced_eq
{α : Type*} {β : Type*} [tα : topological_space α] [tβ : topological_space β] (h : α ≃ₜ β) :
tβ.induced h = tα :=
le_antisymm
(calc topological_space.induced ⇑h tβ ≤ _ : induced_mono (coinduced_le_iff_le_induced.1 h.symm.continuous)
... ≤ tα : by rw [induced_compose, symm_comp_self, induced_id] ; exact le_refl _)
(coinduced_le_iff_le_induced.1 h.continuous)
lemma coinduced_eq
{α : Type*} {β : Type*} [tα : topological_space α] [tβ : topological_space β] (h : α ≃ₜ β) :
tα.coinduced h = tβ :=
le_antisymm
h.continuous
begin
have : (tβ.coinduced h.symm).coinduced h ≤ tα.coinduced h := coinduced_mono h.symm.continuous,
rwa [coinduced_compose, self_comp_symm, coinduced_id] at this,
end
protected lemma embedding (h : α ≃ₜ β) : embedding h :=
⟨⟨h.induced_eq.symm⟩, h.to_equiv.injective⟩
lemma compact_image {s : set α} (h : α ≃ₜ β) : compact (h '' s) ↔ compact s :=
h.embedding.compact_iff_compact_image.symm
lemma compact_preimage {s : set β} (h : α ≃ₜ β) : compact (h ⁻¹' s) ↔ compact s :=
by rw ← image_symm; exact h.symm.compact_image
protected lemma dense_embedding (h : α ≃ₜ β) : dense_embedding h :=
{ dense := assume a, by rw [h.range_coe, closure_univ]; trivial,
inj := h.to_equiv.injective,
induced := (induced_iff_nhds_eq _).2 (assume a, by rw [← nhds_induced, h.induced_eq]) }
protected lemma is_open_map (h : α ≃ₜ β) : is_open_map h :=
begin
assume s,
rw ← h.preimage_symm,
exact h.symm.continuous s
end
protected lemma is_closed_map (h : α ≃ₜ β) : is_closed_map h :=
begin
assume s,
rw ← h.preimage_symm,
exact continuous_iff_is_closed.1 (h.symm.continuous) _
end
/-- If an bijective map `e : α ≃ β` is continuous and open, then it is a homeomorphism. -/
def homeomorph_of_continuous_open (e : α ≃ β) (h₁ : continuous e) (h₂ : is_open_map e) :
α ≃ₜ β :=
{ continuous_to_fun := h₁,
continuous_inv_fun := begin
intros s hs,
convert ← h₂ s hs using 1,
apply e.image_eq_preimage
end,
.. e }
lemma comp_continuous_on_iff (h : α ≃ₜ β) (f : γ → α) (s : set γ) :
continuous_on (h ∘ f) s ↔ continuous_on f s :=
begin
split,
{ assume H,
have : continuous_on (h.symm ∘ (h ∘ f)) s :=
h.symm.continuous.comp_continuous_on H,
rwa [← function.comp.assoc h.symm h f, symm_comp_self h] at this },
{ exact λ H, h.continuous.comp_continuous_on H }
end
lemma comp_continuous_iff (h : α ≃ₜ β) (f : γ → α) :
continuous (h ∘ f) ↔ continuous f :=
by simp [continuous_iff_continuous_on_univ, comp_continuous_on_iff]
protected lemma quotient_map (h : α ≃ₜ β) : quotient_map h :=
⟨h.to_equiv.surjective, h.coinduced_eq.symm⟩
/-- If two sets are equal, then they are homeomorphic. -/
def set_congr {s t : set α} (h : s = t) : s ≃ₜ t :=
{ continuous_to_fun := continuous_subtype_mk _ continuous_subtype_val,
continuous_inv_fun := continuous_subtype_mk _ continuous_subtype_val,
.. equiv.set_congr h }
/-- Product of two homeomorphisms. -/
def prod_congr (h₁ : α ≃ₜ β) (h₂ : γ ≃ₜ δ) : α × γ ≃ₜ β × δ :=
{ continuous_to_fun :=
continuous.prod_mk (h₁.continuous.comp continuous_fst) (h₂.continuous.comp continuous_snd),
continuous_inv_fun :=
continuous.prod_mk (h₁.symm.continuous.comp continuous_fst) (h₂.symm.continuous.comp continuous_snd),
.. h₁.to_equiv.prod_congr h₂.to_equiv }
section
variables (α β γ)
/-- `α × β` is homeomorphic to `β × α`. -/
def prod_comm : α × β ≃ₜ β × α :=
{ continuous_to_fun := continuous.prod_mk continuous_snd continuous_fst,
continuous_inv_fun := continuous.prod_mk continuous_snd continuous_fst,
.. equiv.prod_comm α β }
/-- `(α × β) × γ` is homeomorphic to `α × (β × γ)`. -/
def prod_assoc : (α × β) × γ ≃ₜ α × (β × γ) :=
{ continuous_to_fun :=
continuous.prod_mk (continuous_fst.comp continuous_fst)
(continuous.prod_mk (continuous_snd.comp continuous_fst) continuous_snd),
continuous_inv_fun := continuous.prod_mk
(continuous.prod_mk continuous_fst (continuous_fst.comp continuous_snd))
(continuous_snd.comp continuous_snd),
.. equiv.prod_assoc α β γ }
end
section distrib
variables {ι : Type*} {σ : ι → Type*} [Π i, topological_space (σ i)]
/-- `(Σ i, σ i) × β` is homeomorphic to `Σ i, (σ i × β)`. -/
def sigma_prod_distrib : ((Σ i, σ i) × β) ≃ₜ (Σ i, (σ i × β)) :=
homeomorph.symm $
homeomorph_of_continuous_open (equiv.sigma_prod_distrib σ β).symm
(continuous_sigma $ λ i,
continuous.prod_mk (continuous_sigma_mk.comp continuous_fst) continuous_snd)
(is_open_map_sigma $ λ i,
(open_embedding.prod open_embedding_sigma_mk open_embedding_id).is_open_map)
end distrib
end homeomorph
|
b3e1e449664e36b4460ea7c76b88cd84e72d8308
|
4950bf76e5ae40ba9f8491647d0b6f228ddce173
|
/src/measure_theory/lp_space.lean
|
96e32d70d2eb6a8f130aecb9b0fef2a3eccae5f7
|
[
"Apache-2.0"
] |
permissive
|
ntzwq/mathlib
|
ca50b21079b0a7c6781c34b62199a396dd00cee2
|
36eec1a98f22df82eaccd354a758ef8576af2a7f
|
refs/heads/master
| 1,675,193,391,478
| 1,607,822,996,000
| 1,607,822,996,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 5,655
|
lean
|
/-
Copyright (c) 2020 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Rémy Degenne.
-/
import measure_theory.l1_space
import analysis.mean_inequalities
/-!
# ℒp space
This file describes properties of measurable functions with finite seminorm `(∫ ∥f a∥^p ∂μ) ^ (1/p)`
for `p:ℝ` with `1 ≤ p`.
## Main definitions
* `mem_ℒp f p μ` : the function `f` has finite p-seminorm for measure `μ`, for `p:ℝ` such that
`hp1 : 1 ≤ p`,
## Notation
* `snorm f p μ` : `(∫ ∥f a∥^p ∂μ) ^ (1/p)` for `f : α → F`, where `α` is a measurable space and
`F` is a normed group.
-/
open measure_theory
noncomputable theory
namespace ℒp_space
variables {α E F : Type*} [measurable_space α] {μ : measure α}
[measurable_space E] [normed_group E]
[normed_group F]
{p : ℝ}
section ℒp_space_definition
/-- The property that `f:α→E` is measurable and `∫ ∥f a∥^p ∂μ` is finite -/
def mem_ℒp (f : α → E) (p : ℝ) (μ : measure α) : Prop :=
measurable f ∧ ∫⁻ a, (nnnorm (f a)) ^ p ∂μ < ⊤
/-- `(∫ ∥f a∥^p ∂μ) ^ (1/p)`, which is a seminorm on the space of measurable functions for which
this quantity is finite -/
def snorm (f : α → F) (p : ℝ) (μ : measure α) : ennreal := (∫⁻ a, (nnnorm (f a))^p ∂μ) ^ (1/p)
lemma lintegral_rpow_nnnorm_eq_rpow_snorm {f : α → F} (hp0_lt : 0 < p) :
∫⁻ a, (nnnorm (f a)) ^ p ∂μ = (snorm f p μ) ^ p :=
begin
rw [snorm, ←ennreal.rpow_mul, one_div, inv_mul_cancel, ennreal.rpow_one],
exact (ne_of_lt hp0_lt).symm,
end
end ℒp_space_definition
lemma mem_ℒp_one_iff_integrable {f : α → E} : mem_ℒp f 1 μ ↔ integrable f μ :=
by simp only [integrable, has_finite_integral, mem_ℒp, ennreal.rpow_one, nnreal.coe_one]
section top
lemma mem_ℒp.snorm_lt_top {f : α → E} (hp0 : 0 ≤ p) (hfp : mem_ℒp f p μ) : snorm f p μ < ⊤ :=
begin
refine ennreal.rpow_lt_top_of_nonneg _ (ne_of_lt hfp.right),
rw [one_div, inv_nonneg],
exact hp0,
end
lemma mem_ℒp.snorm_ne_top {f : α → E} (hp0 : 0 ≤ p) (hfp : mem_ℒp f p μ) : snorm f p μ ≠ ⊤ :=
ne_of_lt (hfp.snorm_lt_top hp0)
lemma lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top {f : α → F} (hp0_lt : 0 < p)
(hfp : snorm f p μ < ⊤) :
∫⁻ a, (nnnorm (f a)) ^ p ∂μ < ⊤ :=
begin
rw lintegral_rpow_nnnorm_eq_rpow_snorm hp0_lt,
exact ennreal.rpow_lt_top_of_nonneg (le_of_lt hp0_lt) (ne_of_lt hfp),
end
lemma mem_ℒp_of_snorm_lt_top {f : α → E} (hp0_lt : 0 < p) (hfm : measurable f)
(hfp : snorm f p μ < ⊤) :
mem_ℒp f p μ :=
⟨hfm, lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp0_lt hfp⟩
end top
section zero
lemma zero_mem_ℒp (hp0_lt : 0 < p) : mem_ℒp (0 : α → E) p μ :=
⟨measurable_zero, by simp [hp0_lt]⟩
@[simp] lemma snorm_zero (hp0_lt : 0 < p) : snorm (0 : α → F) p μ = 0 :=
by simp [snorm, hp0_lt]
end zero
@[simp] lemma snorm_neg {f : α → F} : snorm (-f) p μ = snorm f p μ :=
by simp [snorm]
section borel_space
variable [borel_space E]
lemma mem_ℒp.neg {f : α → E} (hf : mem_ℒp f p μ) : mem_ℒp (-f) p μ :=
⟨measurable.neg hf.1, by simp [hf.right]⟩
variable [topological_space.second_countable_topology E]
lemma mem_ℒp.add {f g : α → E} (hf : mem_ℒp f p μ) (hg : mem_ℒp g p μ) (hp1 : 1 ≤ p) :
mem_ℒp (f+g) p μ :=
begin
have hp0_lt : 0 < p, from lt_of_lt_of_le zero_lt_one hp1,
have hp0 : 0 ≤ p, from le_of_lt hp0_lt,
split,
{ exact measurable.add hf.1 hg.1, },
simp_rw [pi.add_apply, ennreal.coe_rpow_of_nonneg _ hp0],
-- step 1: use nnnorm_add_le
calc ∫⁻ (a : α), ↑(nnnorm (f a + g a) ^ p) ∂μ ≤ ∫⁻ a, ↑((nnnorm (f a) + nnnorm (g a)) ^ p) ∂ μ :
begin
refine lintegral_mono_nnreal (λ a, _),
exact nnreal.rpow_le_rpow (nnnorm_add_le (f a) (g a)) (le_of_lt hp0_lt)
end
-- step 2: use convexity of rpow
... ≤ ∫⁻ a, ↑((2:nnreal)^(p-1) * (nnnorm (f a)) ^ p + (2:nnreal)^(p-1) * (nnnorm (g a)) ^ p) ∂ μ :
begin
refine lintegral_mono_nnreal (λ a, _),
have h_zero_lt_half_rpow : (0 : nnreal) < (1 / 2) ^ p,
{ rw [←nnreal.zero_rpow (ne_of_lt hp0_lt).symm, nnreal.rpow_lt_rpow_iff hp0_lt],
simp [zero_lt_one], },
have h_rw : (1 / 2) ^ p * (2:nnreal) ^ (p - 1) = 1 / 2,
{ rw [nnreal.rpow_sub two_ne_zero, nnreal.div_rpow, nnreal.one_rpow, nnreal.rpow_one,
←mul_div_assoc, one_div, inv_mul_cancel],
simp [two_ne_zero], },
rw [←mul_le_mul_left h_zero_lt_half_rpow, mul_add, ← mul_assoc, ← mul_assoc, h_rw,
←nnreal.mul_rpow, mul_add],
refine nnreal.rpow_arith_mean_le_arith_mean2_rpow (1/2 : nnreal) (1/2 : nnreal)
(nnnorm (f a)) (nnnorm (g a)) _ hp1,
rw [nnreal.div_add_div_same, one_add_one_eq_two, nnreal.div_self two_ne_zero]
end
-- step 3: use hypotheses hf and hg
... < ⊤ :
begin
simp_rw [ennreal.coe_add, ennreal.coe_mul, ←ennreal.coe_rpow_of_nonneg _ hp0],
rw [lintegral_add, lintegral_const_mul, lintegral_const_mul, ennreal.add_lt_top],
{ simp [ennreal.mul_lt_top_iff, hf.2, hg.2] },
-- finish by proving the measurability of all functions involved
{ exact hg.left.nnnorm.ennreal_coe.ennreal_rpow_const, },
{ exact hf.left.nnnorm.ennreal_coe.ennreal_rpow_const, },
{ exact (ennreal.continuous_const_mul (by simp)).measurable.comp
hf.left.nnnorm.ennreal_coe.ennreal_rpow_const, },
{ exact (ennreal.continuous_const_mul (by simp)).measurable.comp
hg.left.nnnorm.ennreal_coe.ennreal_rpow_const },
end
end
end borel_space
end ℒp_space
|
a94697075d3896341e0a6eb3dc046dbe0948a87b
|
1437b3495ef9020d5413178aa33c0a625f15f15f
|
/data/equiv/algebra.lean
|
4ccd6ffa21e83b0cdf570e2c4165c9ed3b337f6c
|
[
"Apache-2.0"
] |
permissive
|
jean002/mathlib
|
c66bbb2d9fdc9c03ae07f869acac7ddbfce67a30
|
dc6c38a765799c99c4d9c8d5207d9e6c9e0e2cfd
|
refs/heads/master
| 1,587,027,806,375
| 1,547,306,358,000
| 1,547,306,358,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 2,875
|
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
-/
import data.equiv.basic algebra.field
universes u v w
namespace equiv
variables {α : Type u} [group α]
protected def mul_left (a : α) : α ≃ α :=
{ to_fun := λx, a * x,
inv_fun := λx, a⁻¹ * x,
left_inv := assume x, show a⁻¹ * (a * x) = x, from inv_mul_cancel_left a x,
right_inv := assume x, show a * (a⁻¹ * x) = x, from mul_inv_cancel_left a x }
attribute [to_additive equiv.add_left._proof_1] equiv.mul_left._proof_1
attribute [to_additive equiv.add_left._proof_2] equiv.mul_left._proof_2
attribute [to_additive equiv.add_left] equiv.mul_left
protected def mul_right (a : α) : α ≃ α :=
{ to_fun := λx, x * a,
inv_fun := λx, x * a⁻¹,
left_inv := assume x, show (x * a) * a⁻¹ = x, from mul_inv_cancel_right x a,
right_inv := assume x, show (x * a⁻¹) * a = x, from inv_mul_cancel_right x a }
attribute [to_additive equiv.add_right._proof_1] equiv.mul_right._proof_1
attribute [to_additive equiv.add_right._proof_2] equiv.mul_right._proof_2
attribute [to_additive equiv.add_right] equiv.mul_right
protected def inv (α) [group α] : α ≃ α :=
{ to_fun := λa, a⁻¹,
inv_fun := λa, a⁻¹,
left_inv := assume a, inv_inv a,
right_inv := assume a, inv_inv a }
attribute [to_additive equiv.neg._proof_1] equiv.inv._proof_1
attribute [to_additive equiv.neg._proof_2] equiv.inv._proof_2
attribute [to_additive equiv.neg] equiv.inv
def units_equiv_ne_zero (α : Type*) [field α] : units α ≃ {a : α | a ≠ 0} :=
⟨λ a, ⟨a.1, units.ne_zero _⟩, λ a, units.mk0 _ a.2, λ ⟨_, _, _, _⟩, units.ext rfl, λ ⟨_, _⟩, rfl⟩
@[simp] lemma coe_units_equiv_ne_zero [field α] (a : units α) :
((units_equiv_ne_zero α a) : α) = a := rfl
end equiv
structure ring_equiv (α β : Type*) [ring α] [ring β] extends α ≃ β :=
(hom : is_ring_hom to_fun)
infix ` ≃r `:50 := ring_equiv
namespace ring_equiv
variables {α : Type u} {β : Type v} {γ : Type w}
variables [ring α] [ring β] [ring γ]
instance {e : α ≃r β} : is_ring_hom e.to_equiv := hom _
protected def refl (α : Type*) [ring α] : α ≃r α :=
{ hom := is_ring_hom.id, .. equiv.refl α }
protected def symm {α β : Type*} [ring α] [ring β] (e : α ≃r β) : β ≃r α :=
{ hom := ⟨(equiv.symm_apply_eq _).2 e.hom.1.symm,
λ x y, (equiv.symm_apply_eq _).2 $ show _ = e.to_equiv.to_fun _, by rw [e.2.2, e.1.4, e.1.4],
λ x y, (equiv.symm_apply_eq _).2 $ show _ = e.to_equiv.to_fun _, by rw [e.2.3, e.1.4, e.1.4]⟩,
.. e.to_equiv.symm }
protected def trans {α β γ : Type*} [ring α] [ring β] [ring γ]
(e₁ : α ≃r β) (e₂ : β ≃r γ) : α ≃r γ :=
{ hom := is_ring_hom.comp _ _, .. e₁.1.trans e₂.1 }
end ring_equiv
|
b88a12890c6ce171ba46d3f7b945c1fbe0877e5d
|
8e2026ac8a0660b5a490dfb895599fb445bb77a0
|
/library/init/algebra/group.lean
|
991816c2c7a88c4a2ae14546b689a3d1435040d4
|
[
"Apache-2.0"
] |
permissive
|
pcmoritz/lean
|
6a8575115a724af933678d829b4f791a0cb55beb
|
35eba0107e4cc8a52778259bb5392300267bfc29
|
refs/heads/master
| 1,607,896,326,092
| 1,490,752,175,000
| 1,490,752,175,000
| 86,612,290
| 0
| 0
| null | 1,490,809,641,000
| 1,490,809,641,000
| null |
UTF-8
|
Lean
| false
| false
| 15,728
|
lean
|
/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
prelude
import init.logic init.algebra.ac init.meta init.meta.decl_cmds init.meta.smt.rsimp
/- Make sure instances defined in this file have lower priority than the ones
defined for concrete structures -/
set_option default_priority 100
universe u
variables {α : Type u}
class semigroup (α : Type u) extends has_mul α :=
(mul_assoc : ∀ a b c : α, a * b * c = a * (b * c))
class comm_semigroup (α : Type u) extends semigroup α :=
(mul_comm : ∀ a b : α, a * b = b * a)
class left_cancel_semigroup (α : Type u) extends semigroup α :=
(mul_left_cancel : ∀ a b c : α, a * b = a * c → b = c)
class right_cancel_semigroup (α : Type u) extends semigroup α :=
(mul_right_cancel : ∀ a b c : α, a * b = c * b → a = c)
class monoid (α : Type u) extends semigroup α, has_one α :=
(one_mul : ∀ a : α, 1 * a = a) (mul_one : ∀ a : α, a * 1 = a)
class comm_monoid (α : Type u) extends monoid α, comm_semigroup α
class group (α : Type u) extends monoid α, has_inv α :=
(mul_left_inv : ∀ a : α, a⁻¹ * a = 1)
class comm_group (α : Type u) extends group α, comm_monoid α
@[simp] lemma mul_assoc [semigroup α] : ∀ a b c : α, a * b * c = a * (b * c) :=
semigroup.mul_assoc
instance semigroup_to_is_associative [semigroup α] : is_associative α mul :=
⟨mul_assoc⟩
@[simp] lemma mul_comm [comm_semigroup α] : ∀ a b : α, a * b = b * a :=
comm_semigroup.mul_comm
instance comm_semigroup_to_is_commutative [comm_semigroup α] : is_commutative α mul :=
⟨mul_comm⟩
@[simp] lemma mul_left_comm [comm_semigroup α] : ∀ a b c : α, a * (b * c) = b * (a * c) :=
left_comm mul mul_comm mul_assoc
lemma mul_left_cancel [left_cancel_semigroup α] {a b c : α} : a * b = a * c → b = c :=
left_cancel_semigroup.mul_left_cancel a b c
lemma mul_right_cancel [right_cancel_semigroup α] {a b c : α} : a * b = c * b → a = c :=
right_cancel_semigroup.mul_right_cancel a b c
lemma mul_left_cancel_iff [left_cancel_semigroup α] {a b c : α} : a * b = a * c ↔ b = c :=
⟨mul_left_cancel, congr_arg _⟩
lemma mul_right_cancel_iff [right_cancel_semigroup α] {a b c : α} : b * a = c * a ↔ b = c :=
⟨mul_right_cancel, congr_arg _⟩
@[simp] lemma one_mul [monoid α] : ∀ a : α, 1 * a = a :=
monoid.one_mul
@[simp] lemma mul_one [monoid α] : ∀ a : α, a * 1 = a :=
monoid.mul_one
@[simp] lemma mul_left_inv [group α] : ∀ a : α, a⁻¹ * a = 1 :=
group.mul_left_inv
def inv_mul_self := @mul_left_inv
@[simp] lemma inv_mul_cancel_left [group α] (a b : α) : a⁻¹ * (a * b) = b :=
by rw [-mul_assoc, mul_left_inv, one_mul]
@[simp] lemma inv_mul_cancel_right [group α] (a b : α) : a * b⁻¹ * b = a :=
by simp
@[simp] lemma inv_eq_of_mul_eq_one [group α] {a b : α} (h : a * b = 1) : a⁻¹ = b :=
by rw [-mul_one a⁻¹, -h, -mul_assoc, mul_left_inv, one_mul]
@[simp] lemma one_inv [group α] : 1⁻¹ = (1 : α) :=
inv_eq_of_mul_eq_one (one_mul 1)
@[simp] lemma inv_inv [group α] (a : α) : (a⁻¹)⁻¹ = a :=
inv_eq_of_mul_eq_one (mul_left_inv a)
@[simp] lemma mul_right_inv [group α] (a : α) : a * a⁻¹ = 1 :=
have a⁻¹⁻¹ * a⁻¹ = 1, by rw mul_left_inv,
by rwa [inv_inv] at this
def mul_inv_self := @mul_right_inv
lemma inv_inj [group α] {a b : α} (h : a⁻¹ = b⁻¹) : a = b :=
have a = a⁻¹⁻¹, by simp,
begin rw this, simp [h] end
lemma group.mul_left_cancel [group α] {a b c : α} (h : a * b = a * c) : b = c :=
have a⁻¹ * (a * b) = b, by simp,
begin simp [h] at this, rw this end
lemma group.mul_right_cancel [group α] {a b c : α} (h : a * b = c * b) : a = c :=
have a * b * b⁻¹ = a, by simp,
begin simp [h] at this, rw this end
instance group.to_left_cancel_semigroup [s : group α] : left_cancel_semigroup α :=
{ s with mul_left_cancel := @group.mul_left_cancel α s }
instance group.to_right_cancel_semigroup [s : group α] : right_cancel_semigroup α :=
{ s with mul_right_cancel := @group.mul_right_cancel α s }
lemma mul_inv_cancel_left [group α] (a b : α) : a * (a⁻¹ * b) = b :=
by rw [-mul_assoc, mul_right_inv, one_mul]
lemma mul_inv_cancel_right [group α] (a b : α) : a * b * b⁻¹ = a :=
by rw [mul_assoc, mul_right_inv, mul_one]
@[simp] lemma mul_inv_rev [group α] (a b : α) : (a * b)⁻¹ = b⁻¹ * a⁻¹ :=
inv_eq_of_mul_eq_one begin rw [mul_assoc, -mul_assoc b, mul_right_inv, one_mul, mul_right_inv] end
lemma eq_inv_of_eq_inv [group α] {a b : α} (h : a = b⁻¹) : b = a⁻¹ :=
by simp [h]
lemma eq_inv_of_mul_eq_one [group α] {a b : α} (h : a * b = 1) : a = b⁻¹ :=
have a⁻¹ = b, from inv_eq_of_mul_eq_one h,
by simp [this.symm]
lemma eq_mul_inv_of_mul_eq [group α] {a b c : α} (h : a * c = b) : a = b * c⁻¹ :=
by simp [h.symm]
lemma eq_inv_mul_of_mul_eq [group α] {a b c : α} (h : b * a = c) : a = b⁻¹ * c :=
by simp [h.symm]
lemma inv_mul_eq_of_eq_mul [group α] {a b c : α} (h : b = a * c) : a⁻¹ * b = c :=
by simp [h]
lemma mul_inv_eq_of_eq_mul [group α] {a b c : α} (h : a = c * b) : a * b⁻¹ = c :=
by simp [h]
lemma eq_mul_of_mul_inv_eq [group α] {a b c : α} (h : a * c⁻¹ = b) : a = b * c :=
by simp [h.symm]
lemma eq_mul_of_inv_mul_eq [group α] {a b c : α} (h : b⁻¹ * a = c) : a = b * c :=
by simp [h.symm, mul_inv_cancel_left]
lemma mul_eq_of_eq_inv_mul [group α] {a b c : α} (h : b = a⁻¹ * c) : a * b = c :=
by rw [h, mul_inv_cancel_left]
lemma mul_eq_of_eq_mul_inv [group α] {a b c : α} (h : a = c * b⁻¹) : a * b = c :=
by simp [h]
lemma mul_inv [comm_group α] (a b : α) : (a * b)⁻¹ = a⁻¹ * b⁻¹ :=
by rw [mul_inv_rev, mul_comm]
/- αdditive "sister" structures.
Example, add_semigroup mirrors semigroup.
These structures exist just to help automation.
In an alternative design, we could have the binary operation as an
extra argument for semigroup, monoid, group, etc. However, the lemmas
would be hard to index since they would not contain any constant.
For example, mul_assoc would be
lemma mul_assoc {α : Type u} {op : α → α → α} [semigroup α op] :
∀ a b c : α, op (op a b) c = op a (op b c) :=
semigroup.mul_assoc
The simplifier cannot effectively use this lemma since the pattern for
the left-hand-side would be
?op (?op ?a ?b) ?c
Remark: we use a tactic for transporting theorems from the multiplicative fragment
to the additive one.
-/
class add_semigroup (α : Type u) extends has_add α :=
(add_assoc : ∀ a b c : α, a + b + c = a + (b + c))
class add_comm_semigroup (α : Type u) extends add_semigroup α :=
(add_comm : ∀ a b : α, a + b = b + a)
class add_left_cancel_semigroup (α : Type u) extends add_semigroup α :=
(add_left_cancel : ∀ a b c : α, a + b = a + c → b = c)
class add_right_cancel_semigroup (α : Type u) extends add_semigroup α :=
(add_right_cancel : ∀ a b c : α, a + b = c + b → a = c)
class add_monoid (α : Type u) extends add_semigroup α, has_zero α :=
(zero_add : ∀ a : α, 0 + a = a) (add_zero : ∀ a : α, a + 0 = a)
class add_comm_monoid (α : Type u) extends add_monoid α, add_comm_semigroup α
class add_group (α : Type u) extends add_monoid α, has_neg α :=
(add_left_neg : ∀ a : α, -a + a = 0)
class add_comm_group (α : Type u) extends add_group α, add_comm_monoid α
open tactic
meta def transport_with_dict (dict : name_map name) (src : name) (tgt : name) : command :=
copy_decl_using dict src tgt
>> copy_attribute `reducible src tt tgt
>> copy_attribute `simp src tt tgt
>> copy_attribute `instance src tt tgt
meta def multiplicative_to_additive_pairs : list (name × name) :=
[/- map operations -/
(`mul, `add), (`one, `zero), (`inv, `neg),
(`has_mul, `has_add), (`has_one, `has_zero), (`has_inv, `has_neg),
/- map constructors -/
(`has_mul.mk, `has_add.mk), (`has_one, `has_zero.mk), (`has_inv, `has_neg.mk),
/- map structures -/
(`semigroup, `add_semigroup),
(`monoid, `add_monoid),
(`group, `add_group),
(`comm_semigroup, `add_comm_semigroup),
(`comm_monoid, `add_comm_monoid),
(`comm_group, `add_comm_group),
(`left_cancel_semigroup, `add_left_cancel_semigroup),
(`right_cancel_semigroup, `add_right_cancel_semigroup),
(`left_cancel_semigroup.mk, `add_left_cancel_semigroup.mk),
(`right_cancel_semigroup.mk, `add_right_cancel_semigroup.mk),
/- map instances -/
(`semigroup.to_has_mul, `add_semigroup.to_has_add),
(`monoid.to_has_one, `add_monoid.to_has_zero),
(`group.to_has_inv, `add_group.to_has_neg),
(`comm_semigroup.to_semigroup, `add_comm_semigroup.to_add_semigroup),
(`monoid.to_semigroup, `add_monoid.to_add_semigroup),
(`comm_monoid.to_monoid, `add_comm_monoid.to_add_monoid),
(`comm_monoid.to_comm_semigroup, `add_comm_monoid.to_add_comm_semigroup),
(`group.to_monoid, `add_group.to_add_monoid),
(`comm_group.to_group, `add_comm_group.to_add_group),
(`comm_group.to_comm_monoid, `add_comm_group.to_add_comm_monoid),
(`left_cancel_semigroup.to_semigroup, `add_left_cancel_semigroup.to_add_semigroup),
(`right_cancel_semigroup.to_semigroup, `add_right_cancel_semigroup.to_add_semigroup),
/- map projections -/
(`semigroup.mul_assoc, `add_semigroup.add_assoc),
(`comm_semigroup.mul_comm, `add_comm_semigroup.add_comm),
(`left_cancel_semigroup.mul_left_cancel, `add_left_cancel_semigroup.add_left_cancel),
(`right_cancel_semigroup.mul_right_cancel, `add_right_cancel_semigroup.add_right_cancel),
(`monoid.one_mul, `add_monoid.zero_add),
(`monoid.mul_one, `add_monoid.add_zero),
(`group.mul_left_inv, `add_group.add_left_neg),
(`group.mul, `add_group.add),
(`group.mul_assoc, `add_group.add_assoc),
/- map lemmas -/
(`mul_assoc, `add_assoc),
(`mul_comm, `add_comm),
(`mul_left_comm, `add_left_comm),
(`one_mul, `zero_add),
(`mul_one, `add_zero),
(`mul_left_inv, `add_left_neg),
(`mul_left_cancel, `add_left_cancel),
(`mul_right_cancel, `add_right_cancel),
(`mul_left_cancel_iff, `add_left_cancel_iff),
(`mul_right_cancel_iff, `add_right_cancel_iff),
(`inv_mul_cancel_left, `neg_add_cancel_left),
(`inv_mul_cancel_right, `neg_add_cancel_right),
(`eq_inv_mul_of_mul_eq, `eq_neg_add_of_add_eq),
(`inv_eq_of_mul_eq_one, `neg_eq_of_add_eq_zero),
(`inv_inv, `neg_neg),
(`mul_right_inv, `add_right_neg),
(`mul_inv_cancel_left, `add_neg_cancel_left),
(`mul_inv_cancel_right, `add_neg_cancel_right),
(`mul_inv_rev, `neg_add_rev),
(`mul_inv, `neg_add),
(`inv_inj, `neg_inj),
(`group.mul_left_cancel, `add_group.add_left_cancel),
(`group.mul_right_cancel, `add_group.add_right_cancel),
(`group.to_left_cancel_semigroup, `add_group.to_left_cancel_add_semigroup),
(`group.to_right_cancel_semigroup, `add_group.to_right_cancel_add_semigroup),
(`eq_inv_of_eq_inv, `eq_neg_of_eq_neg),
(`eq_inv_of_mul_eq_one, `eq_neg_of_add_eq_zero),
(`eq_mul_inv_of_mul_eq, `eq_add_neg_of_add_eq),
(`inv_mul_eq_of_eq_mul, `neg_add_eq_of_eq_add),
(`mul_inv_eq_of_eq_mul, `add_neg_eq_of_eq_add),
(`eq_mul_of_mul_inv_eq, `eq_add_of_add_neg_eq),
(`eq_mul_of_inv_mul_eq, `eq_add_of_neg_add_eq),
(`mul_eq_of_eq_inv_mul, `add_eq_of_eq_neg_add),
(`mul_eq_of_eq_mul_inv, `add_eq_of_eq_add_neg),
(`one_inv, `neg_zero)
]
/- Transport multiplicative to additive -/
meta def transport_multiplicative_to_additive : command :=
let dict := rb_map.of_list multiplicative_to_additive_pairs in
multiplicative_to_additive_pairs.foldl (λ t ⟨src, tgt⟩, do
env ← get_env,
if (env.get tgt).to_bool = ff
then t >> transport_with_dict dict src tgt
else t)
skip
run_cmd transport_multiplicative_to_additive
instance add_semigroup_to_is_eq_associative [add_semigroup α] : is_associative α add :=
⟨add_assoc⟩
instance add_comm_semigroup_to_is_eq_commutative [add_comm_semigroup α] : is_commutative α add :=
⟨add_comm⟩
def neg_add_self := @add_left_neg
def add_neg_self := @add_right_neg
def eq_of_add_eq_add_left := @add_left_cancel
def eq_of_add_eq_add_right := @add_right_cancel
@[reducible] protected def algebra.sub [add_group α] (a b : α) : α :=
a + -b
instance add_group_has_sub [add_group α] : has_sub α :=
⟨algebra.sub⟩
@[simp] lemma sub_eq_add_neg [add_group α] (a b : α) : a - b = a + -b :=
rfl
lemma sub_self [add_group α] (a : α) : a - a = 0 :=
add_right_neg a
lemma sub_add_cancel [add_group α] (a b : α) : a - b + b = a :=
neg_add_cancel_right a b
lemma add_sub_cancel [add_group α] (a b : α) : a + b - b = a :=
add_neg_cancel_right a b
lemma add_sub_assoc [add_group α] (a b c : α) : a + b - c = a + (b - c) :=
by rw [sub_eq_add_neg, add_assoc, -sub_eq_add_neg]
lemma eq_of_sub_eq_zero [add_group α] {a b : α} (h : a - b = 0) : a = b :=
have 0 + b = b, by rw zero_add,
have (a - b) + b = b, by rwa h,
by rwa [sub_eq_add_neg, neg_add_cancel_right] at this
lemma sub_eq_zero_of_eq [add_group α] {a b : α} (h : a = b) : a - b = 0 :=
by rw [h, sub_self]
lemma zero_sub [add_group α] (a : α) : 0 - a = -a :=
zero_add (-a)
lemma sub_zero [add_group α] (a : α) : a - 0 = a :=
by rw [sub_eq_add_neg, neg_zero, add_zero]
lemma sub_ne_zero_of_ne [add_group α] {a b : α} (h : a ≠ b) : a - b ≠ 0 :=
begin
intro hab,
apply h,
apply eq_of_sub_eq_zero hab
end
lemma sub_neg_eq_add [add_group α] (a b : α) : a - (-b) = a + b :=
by rw [sub_eq_add_neg, neg_neg]
lemma neg_sub [add_group α] (a b : α) : -(a - b) = b - a :=
neg_eq_of_add_eq_zero (by rw [sub_eq_add_neg, sub_eq_add_neg, add_assoc, neg_add_cancel_left, add_right_neg])
lemma add_sub [add_group α] (a b c : α) : a + (b - c) = a + b - c :=
by simp
lemma sub_add_eq_sub_sub_swap [add_group α] (a b c : α) : a - (b + c) = a - c - b :=
by simp
lemma eq_sub_of_add_eq [add_group α] {a b c : α} (h : a + c = b) : a = b - c :=
by simp [h.symm]
lemma sub_eq_of_eq_add [add_group α] {a b c : α} (h : a = c + b) : a - b = c :=
by simp [h]
lemma eq_add_of_sub_eq [add_group α] {a b c : α} (h : a - c = b) : a = b + c :=
by simp [h.symm]
lemma add_eq_of_eq_sub [add_group α] {a b c : α} (h : a = c - b) : a + b = c :=
by simp [h]
lemma sub_add_eq_sub_sub [add_comm_group α] (a b c : α) : a - (b + c) = a - b - c :=
by simp
lemma neg_add_eq_sub [add_comm_group α] (a b : α) : -a + b = b - a :=
by simp
lemma sub_add_eq_add_sub [add_comm_group α] (a b c : α) : a - b + c = a + c - b :=
by simp
lemma sub_sub [add_comm_group α] (a b c : α) : a - b - c = a - (b + c) :=
by simp
lemma add_sub_add_left_eq_sub [add_comm_group α] (a b c : α) : (c + a) - (c + b) = a - b :=
by simp
lemma eq_sub_of_add_eq' [add_comm_group α] {a b c : α} (h : c + a = b) : a = b - c :=
by simp [h.symm]
lemma sub_eq_of_eq_add' [add_comm_group α] {a b c : α} (h : a = b + c) : a - b = c :=
by simp [h]
lemma eq_add_of_sub_eq' [add_comm_group α] {a b c : α} (h : a - b = c) : a = b + c :=
by simp [h.symm]
lemma add_eq_of_eq_sub' [add_comm_group α] {a b c : α} (h : b = c - a) : a + b = c :=
begin simp [h], rw [add_comm c, add_neg_cancel_left] end
lemma sub_sub_self [add_comm_group α] (a b : α) : a - (a - b) = b :=
begin simp, rw [add_comm b, add_neg_cancel_left] end
lemma add_sub_comm [add_comm_group α] (a b c d : α) : a + b - (c + d) = (a - c) + (b - d) :=
by simp
lemma sub_eq_sub_add_sub [add_comm_group α] (a b c : α) : a - b = c - b + (a - c) :=
by simp
lemma neg_neg_sub_neg [add_comm_group α] (a b : α) : - (-a - -b) = a - b :=
by simp
/- The following lemmas generate too many instances for rsimp -/
attribute [no_rsimp]
mul_assoc mul_comm mul_left_comm
add_assoc add_comm add_left_comm
|
74ae6677c046db0857445f809051aece31f0e194
|
57c233acf9386e610d99ed20ef139c5f97504ba3
|
/src/geometry/euclidean/circumcenter.lean
|
b44646ccc308e60e675e8aecf1d21c57d2a95401
|
[
"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
| 38,244
|
lean
|
/-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import geometry.euclidean.basic
import linear_algebra.affine_space.finite_dimensional
import tactic.derive_fintype
/-!
# Circumcenter and circumradius
This file proves some lemmas on points equidistant from a set of
points, and defines the circumradius and circumcenter of a simplex.
There are also some definitions for use in calculations where it is
convenient to work with affine combinations of vertices together with
the circumcenter.
## Main definitions
* `circumcenter` and `circumradius` are the circumcenter and
circumradius of a simplex.
## References
* https://en.wikipedia.org/wiki/Circumscribed_circle
-/
noncomputable theory
open_locale big_operators
open_locale classical
open_locale real
open_locale real_inner_product_space
namespace euclidean_geometry
open inner_product_geometry
variables {V : Type*} {P : Type*} [inner_product_space ℝ V] [metric_space P]
[normed_add_torsor V P]
include V
open affine_subspace
/-- `p` is equidistant from two points in `s` if and only if its
`orthogonal_projection` is. -/
lemma dist_eq_iff_dist_orthogonal_projection_eq {s : affine_subspace ℝ P} [nonempty s]
[complete_space s.direction] {p1 p2 : P} (p3 : P) (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) :
dist p1 p3 = dist p2 p3 ↔
dist p1 (orthogonal_projection s p3) = dist p2 (orthogonal_projection s p3) :=
begin
rw [←mul_self_inj_of_nonneg dist_nonneg dist_nonneg,
←mul_self_inj_of_nonneg dist_nonneg dist_nonneg,
dist_sq_eq_dist_orthogonal_projection_sq_add_dist_orthogonal_projection_sq
p3 hp1,
dist_sq_eq_dist_orthogonal_projection_sq_add_dist_orthogonal_projection_sq
p3 hp2],
simp
end
/-- `p` is equidistant from a set of points in `s` if and only if its
`orthogonal_projection` is. -/
lemma dist_set_eq_iff_dist_orthogonal_projection_eq {s : affine_subspace ℝ P} [nonempty s]
[complete_space s.direction] {ps : set P} (hps : ps ⊆ s) (p : P) :
set.pairwise ps (λ p1 p2, dist p1 p = dist p2 p) ↔
(set.pairwise ps (λ p1 p2, dist p1 (orthogonal_projection s p) =
dist p2 (orthogonal_projection s p))) :=
⟨λ h p1 hp1 p2 hp2 hne,
(dist_eq_iff_dist_orthogonal_projection_eq p (hps hp1) (hps hp2)).1 (h hp1 hp2 hne),
λ h p1 hp1 p2 hp2 hne,
(dist_eq_iff_dist_orthogonal_projection_eq p (hps hp1) (hps hp2)).2 (h hp1 hp2 hne)⟩
/-- There exists `r` such that `p` has distance `r` from all the
points of a set of points in `s` if and only if there exists (possibly
different) `r` such that its `orthogonal_projection` has that distance
from all the points in that set. -/
lemma exists_dist_eq_iff_exists_dist_orthogonal_projection_eq {s : affine_subspace ℝ P} [nonempty s]
[complete_space s.direction] {ps : set P} (hps : ps ⊆ s) (p : P) :
(∃ r, ∀ p1 ∈ ps, dist p1 p = r) ↔
∃ r, ∀ p1 ∈ ps, dist p1 ↑(orthogonal_projection s p) = r :=
begin
have h := dist_set_eq_iff_dist_orthogonal_projection_eq hps p,
simp_rw set.pairwise_eq_iff_exists_eq at h,
exact h
end
/-- The induction step for the existence and uniqueness of the
circumcenter. Given a nonempty set of points in a nonempty affine
subspace whose direction is complete, such that there is a unique
(circumcenter, circumradius) pair for those points in that subspace,
and a point `p` not in that subspace, there is a unique (circumcenter,
circumradius) pair for the set with `p` added, in the span of the
subspace with `p` added. -/
lemma exists_unique_dist_eq_of_insert {s : affine_subspace ℝ P}
[complete_space s.direction] {ps : set P} (hnps : ps.nonempty) {p : P}
(hps : ps ⊆ s) (hp : p ∉ s)
(hu : ∃! cccr : (P × ℝ), cccr.fst ∈ s ∧ ∀ p1 ∈ ps, dist p1 cccr.fst = cccr.snd) :
∃! cccr₂ : (P × ℝ), cccr₂.fst ∈ affine_span ℝ (insert p (s : set P)) ∧
∀ p1 ∈ insert p ps, dist p1 cccr₂.fst = cccr₂.snd :=
begin
haveI : nonempty s := set.nonempty.to_subtype (hnps.mono hps),
rcases hu with ⟨⟨cc, cr⟩, ⟨hcc, hcr⟩, hcccru⟩,
simp only [prod.fst, prod.snd] at hcc hcr hcccru,
let x := dist cc (orthogonal_projection s p),
let y := dist p (orthogonal_projection s p),
have hy0 : y ≠ 0 := dist_orthogonal_projection_ne_zero_of_not_mem hp,
let ycc₂ := (x * x + y * y - cr * cr) / (2 * y),
let cc₂ := (ycc₂ / y) • (p -ᵥ orthogonal_projection s p : V) +ᵥ cc,
let cr₂ := real.sqrt (cr * cr + ycc₂ * ycc₂),
use (cc₂, cr₂),
simp only [prod.fst, prod.snd],
have hpo : p = (1 : ℝ) • (p -ᵥ orthogonal_projection s p : V) +ᵥ orthogonal_projection s p,
{ simp },
split,
{ split,
{ refine vadd_mem_of_mem_direction _ (mem_affine_span ℝ (set.mem_insert_of_mem _ hcc)),
rw direction_affine_span,
exact submodule.smul_mem _ _
(vsub_mem_vector_span ℝ (set.mem_insert _ _)
(set.mem_insert_of_mem _ (orthogonal_projection_mem _))) },
{ intros p1 hp1,
rw [←mul_self_inj_of_nonneg dist_nonneg (real.sqrt_nonneg _),
real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _))],
cases hp1,
{ rw hp1,
rw [hpo,
dist_sq_smul_orthogonal_vadd_smul_orthogonal_vadd
(orthogonal_projection_mem p) hcc _ _
(vsub_orthogonal_projection_mem_direction_orthogonal s p),
←dist_eq_norm_vsub V p, dist_comm _ cc],
field_simp [hy0],
ring },
{ rw [dist_sq_eq_dist_orthogonal_projection_sq_add_dist_orthogonal_projection_sq
_ (hps hp1),
orthogonal_projection_vadd_smul_vsub_orthogonal_projection _ _ hcc, subtype.coe_mk,
hcr _ hp1, dist_eq_norm_vsub V cc₂ cc, vadd_vsub, norm_smul, ←dist_eq_norm_vsub V,
real.norm_eq_abs, abs_div, abs_of_nonneg dist_nonneg, div_mul_cancel _ hy0,
abs_mul_abs_self] } } },
{ rintros ⟨cc₃, cr₃⟩ ⟨hcc₃, hcr₃⟩,
simp only [prod.fst, prod.snd] at hcc₃ hcr₃,
obtain ⟨t₃, cc₃', hcc₃', hcc₃''⟩ :
∃ (r : ℝ) (p0 : P) (hp0 : p0 ∈ s), cc₃ = r • (p -ᵥ ↑((orthogonal_projection s) p)) +ᵥ p0,
{ rwa mem_affine_span_insert_iff (orthogonal_projection_mem p) at hcc₃ },
have hcr₃' : ∃ r, ∀ p1 ∈ ps, dist p1 cc₃ = r :=
⟨cr₃, λ p1 hp1, hcr₃ p1 (set.mem_insert_of_mem _ hp1)⟩,
rw [exists_dist_eq_iff_exists_dist_orthogonal_projection_eq hps cc₃, hcc₃'',
orthogonal_projection_vadd_smul_vsub_orthogonal_projection _ _ hcc₃'] at hcr₃',
cases hcr₃' with cr₃' hcr₃',
have hu := hcccru (cc₃', cr₃'),
simp only [prod.fst, prod.snd] at hu,
replace hu := hu ⟨hcc₃', hcr₃'⟩,
rw prod.ext_iff at hu,
simp only [prod.fst, prod.snd] at hu,
cases hu with hucc hucr,
substs hucc hucr,
have hcr₃val : cr₃ = real.sqrt (cr₃' * cr₃' + (t₃ * y) * (t₃ * y)),
{ cases hnps with p0 hp0,
have h' : ↑(⟨cc₃', hcc₃'⟩ : s) = cc₃' := rfl,
rw [←hcr₃ p0 (set.mem_insert_of_mem _ hp0), hcc₃'',
←mul_self_inj_of_nonneg dist_nonneg (real.sqrt_nonneg _),
real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)),
dist_sq_eq_dist_orthogonal_projection_sq_add_dist_orthogonal_projection_sq
_ (hps hp0),
orthogonal_projection_vadd_smul_vsub_orthogonal_projection _ _ hcc₃', h', hcr p0 hp0,
dist_eq_norm_vsub V _ cc₃', vadd_vsub, norm_smul, ←dist_eq_norm_vsub V p,
real.norm_eq_abs, ←mul_assoc, mul_comm _ (|t₃|), ←mul_assoc, abs_mul_abs_self],
ring },
replace hcr₃ := hcr₃ p (set.mem_insert _ _),
rw [hpo, hcc₃'', hcr₃val, ←mul_self_inj_of_nonneg dist_nonneg (real.sqrt_nonneg _),
dist_sq_smul_orthogonal_vadd_smul_orthogonal_vadd
(orthogonal_projection_mem p) hcc₃' _ _
(vsub_orthogonal_projection_mem_direction_orthogonal s p),
dist_comm, ←dist_eq_norm_vsub V p,
real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _))] at hcr₃,
change x * x + _ * (y * y) = _ at hcr₃,
rw [(show x * x + (1 - t₃) * (1 - t₃) * (y * y) =
x * x + y * y - 2 * y * (t₃ * y) + t₃ * y * (t₃ * y), by ring), add_left_inj] at hcr₃,
have ht₃ : t₃ = ycc₂ / y,
{ field_simp [←hcr₃, hy0],
ring },
subst ht₃,
change cc₃ = cc₂ at hcc₃'',
congr',
rw hcr₃val,
congr' 2,
field_simp [hy0],
ring }
end
/-- Given a finite nonempty affinely independent family of points,
there is a unique (circumcenter, circumradius) pair for those points
in the affine subspace they span. -/
lemma _root_.affine_independent.exists_unique_dist_eq {ι : Type*} [hne : nonempty ι] [fintype ι]
{p : ι → P} (ha : affine_independent ℝ p) :
∃! cccr : (P × ℝ), cccr.fst ∈ affine_span ℝ (set.range p) ∧
∀ i, dist (p i) cccr.fst = cccr.snd :=
begin
unfreezingI { induction hn : fintype.card ι with m hm generalizing ι },
{ exfalso,
have h := fintype.card_pos_iff.2 hne,
rw hn at h,
exact lt_irrefl 0 h },
{ cases m,
{ rw fintype.card_eq_one_iff at hn,
cases hn with i hi,
haveI : unique ι := ⟨⟨i⟩, hi⟩,
use (p i, 0),
simp only [prod.fst, prod.snd, set.range_unique, affine_subspace.mem_affine_span_singleton],
split,
{ simp_rw [hi default],
use rfl,
intro i1,
rw hi i1,
exact dist_self _ },
{ rintros ⟨cc, cr⟩,
simp only [prod.fst, prod.snd],
rintros ⟨rfl, hdist⟩,
rw hi default,
congr',
rw ←hdist default,
exact dist_self _ } },
{ have i := hne.some,
let ι2 := {x // x ≠ i},
have hc : fintype.card ι2 = m + 1,
{ rw fintype.card_of_subtype (finset.univ.filter (λ x, x ≠ i)),
{ rw finset.filter_not,
simp_rw eq_comm,
rw [finset.filter_eq, if_pos (finset.mem_univ _),
finset.card_sdiff (finset.subset_univ _), finset.card_singleton, finset.card_univ,
hn],
simp },
{ simp } },
haveI : nonempty ι2 := fintype.card_pos_iff.1 (hc.symm ▸ nat.zero_lt_succ _),
have ha2 : affine_independent ℝ (λ i2 : ι2, p i2) := ha.subtype _,
replace hm := hm ha2 hc,
have hr : set.range p = insert (p i) (set.range (λ i2 : ι2, p i2)),
{ change _ = insert _ (set.range (λ i2 : {x | x ≠ i}, p i2)),
rw [←set.image_eq_range, ←set.image_univ, ←set.image_insert_eq],
congr' with j,
simp [classical.em] },
change ∃! (cccr : P × ℝ), (_ ∧ ∀ i2, (λ q, dist q cccr.fst = cccr.snd) (p i2)),
conv { congr, funext, conv { congr, skip, rw ←set.forall_range_iff } },
dsimp only,
rw hr,
change ∃! (cccr : P × ℝ), (_ ∧ ∀ (i2 : ι2), (λ q, dist q cccr.fst = cccr.snd) (p i2)) at hm,
conv at hm { congr, funext, conv { congr, skip, rw ←set.forall_range_iff } },
rw ←affine_span_insert_affine_span,
refine exists_unique_dist_eq_of_insert
(set.range_nonempty _)
(subset_span_points ℝ _)
_
hm,
convert ha.not_mem_affine_span_diff i set.univ,
change set.range (λ i2 : {x | x ≠ i}, p i2) = _,
rw ←set.image_eq_range,
congr' with j, simp, refl } }
end
end euclidean_geometry
namespace affine
namespace simplex
open finset affine_subspace euclidean_geometry
variables {V : Type*} {P : Type*} [inner_product_space ℝ V] [metric_space P]
[normed_add_torsor V P]
include V
/-- The pair (circumcenter, circumradius) of a simplex. -/
def circumcenter_circumradius {n : ℕ} (s : simplex ℝ P n) : (P × ℝ) :=
s.independent.exists_unique_dist_eq.some
/-- The property satisfied by the (circumcenter, circumradius) pair. -/
lemma circumcenter_circumradius_unique_dist_eq {n : ℕ} (s : simplex ℝ P n) :
(s.circumcenter_circumradius.fst ∈ affine_span ℝ (set.range s.points) ∧
∀ i, dist (s.points i) s.circumcenter_circumradius.fst = s.circumcenter_circumradius.snd) ∧
(∀ cccr : (P × ℝ), (cccr.fst ∈ affine_span ℝ (set.range s.points) ∧
∀ i, dist (s.points i) cccr.fst = cccr.snd) → cccr = s.circumcenter_circumradius) :=
s.independent.exists_unique_dist_eq.some_spec
/-- The circumcenter of a simplex. -/
def circumcenter {n : ℕ} (s : simplex ℝ P n) : P :=
s.circumcenter_circumradius.fst
/-- The circumradius of a simplex. -/
def circumradius {n : ℕ} (s : simplex ℝ P n) : ℝ :=
s.circumcenter_circumradius.snd
/-- The circumcenter lies in the affine span. -/
lemma circumcenter_mem_affine_span {n : ℕ} (s : simplex ℝ P n) :
s.circumcenter ∈ affine_span ℝ (set.range s.points) :=
s.circumcenter_circumradius_unique_dist_eq.1.1
/-- All points have distance from the circumcenter equal to the
circumradius. -/
@[simp] lemma dist_circumcenter_eq_circumradius {n : ℕ} (s : simplex ℝ P n) :
∀ i, dist (s.points i) s.circumcenter = s.circumradius :=
s.circumcenter_circumradius_unique_dist_eq.1.2
/-- All points have distance to the circumcenter equal to the
circumradius. -/
@[simp] lemma dist_circumcenter_eq_circumradius' {n : ℕ} (s : simplex ℝ P n) :
∀ i, dist s.circumcenter (s.points i) = s.circumradius :=
begin
intro i,
rw dist_comm,
exact dist_circumcenter_eq_circumradius _ _
end
/-- Given a point in the affine span from which all the points are
equidistant, that point is the circumcenter. -/
lemma eq_circumcenter_of_dist_eq {n : ℕ} (s : simplex ℝ P n) {p : P}
(hp : p ∈ affine_span ℝ (set.range s.points)) {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) :
p = s.circumcenter :=
begin
have h := s.circumcenter_circumradius_unique_dist_eq.2 (p, r),
simp only [hp, hr, forall_const, eq_self_iff_true, and_self, prod.ext_iff] at h,
exact h.1
end
/-- Given a point in the affine span from which all the points are
equidistant, that distance is the circumradius. -/
lemma eq_circumradius_of_dist_eq {n : ℕ} (s : simplex ℝ P n) {p : P}
(hp : p ∈ affine_span ℝ (set.range s.points)) {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) :
r = s.circumradius :=
begin
have h := s.circumcenter_circumradius_unique_dist_eq.2 (p, r),
simp only [hp, hr, forall_const, eq_self_iff_true, and_self, prod.ext_iff] at h,
exact h.2
end
/-- The circumradius is non-negative. -/
lemma circumradius_nonneg {n : ℕ} (s : simplex ℝ P n) : 0 ≤ s.circumradius :=
s.dist_circumcenter_eq_circumradius 0 ▸ dist_nonneg
/-- The circumradius of a simplex with at least two points is
positive. -/
lemma circumradius_pos {n : ℕ} (s : simplex ℝ P (n + 1)) : 0 < s.circumradius :=
begin
refine lt_of_le_of_ne s.circumradius_nonneg _,
intro h,
have hr := s.dist_circumcenter_eq_circumradius,
simp_rw [←h, dist_eq_zero] at hr,
have h01 := s.independent.injective.ne (dec_trivial : (0 : fin (n + 2)) ≠ 1),
simpa [hr] using h01
end
/-- The circumcenter of a 0-simplex equals its unique point. -/
lemma circumcenter_eq_point (s : simplex ℝ P 0) (i : fin 1) :
s.circumcenter = s.points i :=
begin
have h := s.circumcenter_mem_affine_span,
rw [set.range_unique, mem_affine_span_singleton] at h,
rw h,
congr
end
/-- The circumcenter of a 1-simplex equals its centroid. -/
lemma circumcenter_eq_centroid (s : simplex ℝ P 1) :
s.circumcenter = finset.univ.centroid ℝ s.points :=
begin
have hr : set.pairwise set.univ
(λ i j : fin 2, dist (s.points i) (finset.univ.centroid ℝ s.points) =
dist (s.points j) (finset.univ.centroid ℝ s.points)),
{ intros i hi j hj hij,
rw [finset.centroid_insert_singleton_fin, dist_eq_norm_vsub V (s.points i),
dist_eq_norm_vsub V (s.points j), vsub_vadd_eq_vsub_sub, vsub_vadd_eq_vsub_sub,
←one_smul ℝ (s.points i -ᵥ s.points 0), ←one_smul ℝ (s.points j -ᵥ s.points 0)],
fin_cases i; fin_cases j; simp [-one_smul, ←sub_smul]; norm_num },
rw set.pairwise_eq_iff_exists_eq at hr,
cases hr with r hr,
exact (s.eq_circumcenter_of_dist_eq
(centroid_mem_affine_span_of_card_eq_add_one ℝ _ (finset.card_fin 2))
(λ i, hr i (set.mem_univ _))).symm
end
/-- If there exists a distance that a point has from all vertices of a
simplex, the orthogonal projection of that point onto the subspace
spanned by that simplex is its circumcenter. -/
lemma orthogonal_projection_eq_circumcenter_of_exists_dist_eq {n : ℕ} (s : simplex ℝ P n)
{p : P} (hr : ∃ r, ∀ i, dist (s.points i) p = r) :
↑(orthogonal_projection (affine_span ℝ (set.range s.points)) p) = s.circumcenter :=
begin
change ∃ r : ℝ, ∀ i, (λ x, dist x p = r) (s.points i) at hr,
conv at hr { congr, funext, rw ←set.forall_range_iff },
rw exists_dist_eq_iff_exists_dist_orthogonal_projection_eq (subset_affine_span ℝ _) p at hr,
cases hr with r hr,
exact s.eq_circumcenter_of_dist_eq
(orthogonal_projection_mem p) (λ i, hr _ (set.mem_range_self i)),
end
/-- If a point has the same distance from all vertices of a simplex,
the orthogonal projection of that point onto the subspace spanned by
that simplex is its circumcenter. -/
lemma orthogonal_projection_eq_circumcenter_of_dist_eq {n : ℕ} (s : simplex ℝ P n) {p : P}
{r : ℝ} (hr : ∀ i, dist (s.points i) p = r) :
↑(orthogonal_projection (affine_span ℝ (set.range s.points)) p) = s.circumcenter :=
s.orthogonal_projection_eq_circumcenter_of_exists_dist_eq ⟨r, hr⟩
/-- The orthogonal projection of the circumcenter onto a face is the
circumcenter of that face. -/
lemma orthogonal_projection_circumcenter {n : ℕ} (s : simplex ℝ P n) {fs : finset (fin (n + 1))}
{m : ℕ} (h : fs.card = m + 1) :
↑(orthogonal_projection (affine_span ℝ (set.range (s.face h).points)) s.circumcenter) =
(s.face h).circumcenter :=
begin
have hr : ∃ r, ∀ i, dist ((s.face h).points i) s.circumcenter = r,
{ use s.circumradius,
simp [face_points] },
exact orthogonal_projection_eq_circumcenter_of_exists_dist_eq _ hr
end
/-- Two simplices with the same points have the same circumcenter. -/
lemma circumcenter_eq_of_range_eq {n : ℕ} {s₁ s₂ : simplex ℝ P n}
(h : set.range s₁.points = set.range s₂.points) : s₁.circumcenter = s₂.circumcenter :=
begin
have hs : s₁.circumcenter ∈ affine_span ℝ (set.range s₂.points) :=
h ▸ s₁.circumcenter_mem_affine_span,
have hr : ∀ i, dist (s₂.points i) s₁.circumcenter = s₁.circumradius,
{ intro i,
have hi : s₂.points i ∈ set.range s₂.points := set.mem_range_self _,
rw [←h, set.mem_range] at hi,
rcases hi with ⟨j, hj⟩,
rw [←hj, s₁.dist_circumcenter_eq_circumradius j] },
exact s₂.eq_circumcenter_of_dist_eq hs hr
end
omit V
/-- An index type for the vertices of a simplex plus its circumcenter.
This is for use in calculations where it is convenient to work with
affine combinations of vertices together with the circumcenter. (An
equivalent form sometimes used in the literature is placing the
circumcenter at the origin and working with vectors for the vertices.) -/
@[derive fintype]
inductive points_with_circumcenter_index (n : ℕ)
| point_index : fin (n + 1) → points_with_circumcenter_index
| circumcenter_index : points_with_circumcenter_index
open points_with_circumcenter_index
instance points_with_circumcenter_index_inhabited (n : ℕ) :
inhabited (points_with_circumcenter_index n) :=
⟨circumcenter_index⟩
/-- `point_index` as an embedding. -/
def point_index_embedding (n : ℕ) : fin (n + 1) ↪ points_with_circumcenter_index n :=
⟨λ i, point_index i, λ _ _ h, by injection h⟩
/-- The sum of a function over `points_with_circumcenter_index`. -/
lemma sum_points_with_circumcenter {α : Type*} [add_comm_monoid α] {n : ℕ}
(f : points_with_circumcenter_index n → α) :
∑ i, f i = (∑ (i : fin (n + 1)), f (point_index i)) + f circumcenter_index :=
begin
have h : univ = insert circumcenter_index (univ.map (point_index_embedding n)),
{ ext x,
refine ⟨λ h, _, λ _, mem_univ _⟩,
cases x with i,
{ exact mem_insert_of_mem (mem_map_of_mem _ (mem_univ i)) },
{ exact mem_insert_self _ _ } },
change _ = ∑ i, f (point_index_embedding n i) + _,
rw [add_comm, h, ←sum_map, sum_insert],
simp_rw [finset.mem_map, not_exists],
intros x hx h,
injection h
end
include V
/-- The vertices of a simplex plus its circumcenter. -/
def points_with_circumcenter {n : ℕ} (s : simplex ℝ P n) : points_with_circumcenter_index n → P
| (point_index i) := s.points i
| circumcenter_index := s.circumcenter
/-- `points_with_circumcenter`, applied to a `point_index` value,
equals `points` applied to that value. -/
@[simp] lemma points_with_circumcenter_point {n : ℕ} (s : simplex ℝ P n) (i : fin (n + 1)) :
s.points_with_circumcenter (point_index i) = s.points i :=
rfl
/-- `points_with_circumcenter`, applied to `circumcenter_index`, equals the
circumcenter. -/
@[simp] lemma points_with_circumcenter_eq_circumcenter {n : ℕ} (s : simplex ℝ P n) :
s.points_with_circumcenter circumcenter_index = s.circumcenter :=
rfl
omit V
/-- The weights for a single vertex of a simplex, in terms of
`points_with_circumcenter`. -/
def point_weights_with_circumcenter {n : ℕ} (i : fin (n + 1)) : points_with_circumcenter_index n → ℝ
| (point_index j) := if j = i then 1 else 0
| circumcenter_index := 0
/-- `point_weights_with_circumcenter` sums to 1. -/
@[simp] lemma sum_point_weights_with_circumcenter {n : ℕ} (i : fin (n + 1)) :
∑ j, point_weights_with_circumcenter i j = 1 :=
begin
convert sum_ite_eq' univ (point_index i) (function.const _ (1 : ℝ)),
{ ext j,
cases j ; simp [point_weights_with_circumcenter] },
{ simp }
end
include V
/-- A single vertex, in terms of `points_with_circumcenter`. -/
lemma point_eq_affine_combination_of_points_with_circumcenter {n : ℕ} (s : simplex ℝ P n)
(i : fin (n + 1)) :
s.points i =
(univ : finset (points_with_circumcenter_index n)).affine_combination
s.points_with_circumcenter (point_weights_with_circumcenter i) :=
begin
rw ←points_with_circumcenter_point,
symmetry,
refine affine_combination_of_eq_one_of_eq_zero _ _ _
(mem_univ _)
(by simp [point_weights_with_circumcenter])
_,
intros i hi hn,
cases i,
{ have h : i_1 ≠ i := λ h, hn (h ▸ rfl),
simp [point_weights_with_circumcenter, h] },
{ refl }
end
omit V
/-- The weights for the centroid of some vertices of a simplex, in
terms of `points_with_circumcenter`. -/
def centroid_weights_with_circumcenter {n : ℕ} (fs : finset (fin (n + 1)))
: points_with_circumcenter_index n → ℝ
| (point_index i) := if i ∈ fs then ((card fs : ℝ) ⁻¹) else 0
| circumcenter_index := 0
/-- `centroid_weights_with_circumcenter` sums to 1, if the `finset` is
nonempty. -/
@[simp] lemma sum_centroid_weights_with_circumcenter {n : ℕ} {fs : finset (fin (n + 1))}
(h : fs.nonempty) :
∑ i, centroid_weights_with_circumcenter fs i = 1 :=
begin
simp_rw [sum_points_with_circumcenter, centroid_weights_with_circumcenter, add_zero,
←fs.sum_centroid_weights_eq_one_of_nonempty ℝ h,
set.sum_indicator_subset _ fs.subset_univ],
rcongr
end
include V
/-- The centroid of some vertices of a simplex, in terms of
`points_with_circumcenter`. -/
lemma centroid_eq_affine_combination_of_points_with_circumcenter {n : ℕ} (s : simplex ℝ P n)
(fs : finset (fin (n + 1))) :
fs.centroid ℝ s.points =
(univ : finset (points_with_circumcenter_index n)).affine_combination
s.points_with_circumcenter (centroid_weights_with_circumcenter fs) :=
begin
simp_rw [centroid_def, affine_combination_apply,
weighted_vsub_of_point_apply, sum_points_with_circumcenter,
centroid_weights_with_circumcenter, points_with_circumcenter_point, zero_smul,
add_zero, centroid_weights,
set.sum_indicator_subset_of_eq_zero
(function.const (fin (n + 1)) ((card fs : ℝ)⁻¹))
(λ i wi, wi • (s.points i -ᵥ classical.choice add_torsor.nonempty))
fs.subset_univ
(λ i, zero_smul ℝ _),
set.indicator_apply],
congr, funext, congr' 2
end
omit V
/-- The weights for the circumcenter of a simplex, in terms of
`points_with_circumcenter`. -/
def circumcenter_weights_with_circumcenter (n : ℕ) : points_with_circumcenter_index n → ℝ
| (point_index i) := 0
| circumcenter_index := 1
/-- `circumcenter_weights_with_circumcenter` sums to 1. -/
@[simp] lemma sum_circumcenter_weights_with_circumcenter (n : ℕ) :
∑ i, circumcenter_weights_with_circumcenter n i = 1 :=
begin
convert sum_ite_eq' univ circumcenter_index (function.const _ (1 : ℝ)),
{ ext ⟨j⟩ ; simp [circumcenter_weights_with_circumcenter] },
{ simp }
end
include V
/-- The circumcenter of a simplex, in terms of
`points_with_circumcenter`. -/
lemma circumcenter_eq_affine_combination_of_points_with_circumcenter {n : ℕ}
(s : simplex ℝ P n) :
s.circumcenter = (univ : finset (points_with_circumcenter_index n)).affine_combination
s.points_with_circumcenter (circumcenter_weights_with_circumcenter n) :=
begin
rw ←points_with_circumcenter_eq_circumcenter,
symmetry,
refine affine_combination_of_eq_one_of_eq_zero _ _ _ (mem_univ _) rfl _,
rintros ⟨i⟩ hi hn ; tauto
end
omit V
/-- The weights for the reflection of the circumcenter in an edge of a
simplex. This definition is only valid with `i₁ ≠ i₂`. -/
def reflection_circumcenter_weights_with_circumcenter {n : ℕ} (i₁ i₂ : fin (n + 1)) :
points_with_circumcenter_index n → ℝ
| (point_index i) := if i = i₁ ∨ i = i₂ then 1 else 0
| circumcenter_index := -1
/-- `reflection_circumcenter_weights_with_circumcenter` sums to 1. -/
@[simp] lemma sum_reflection_circumcenter_weights_with_circumcenter {n : ℕ} {i₁ i₂ : fin (n + 1)}
(h : i₁ ≠ i₂) : ∑ i, reflection_circumcenter_weights_with_circumcenter i₁ i₂ i = 1 :=
begin
simp_rw [sum_points_with_circumcenter, reflection_circumcenter_weights_with_circumcenter,
sum_ite, sum_const, filter_or, filter_eq'],
rw card_union_eq,
{ simp },
{ simpa only [if_true, mem_univ, disjoint_singleton] using h }
end
include V
/-- The reflection of the circumcenter of a simplex in an edge, in
terms of `points_with_circumcenter`. -/
lemma reflection_circumcenter_eq_affine_combination_of_points_with_circumcenter {n : ℕ}
(s : simplex ℝ P n) {i₁ i₂ : fin (n + 1)} (h : i₁ ≠ i₂) :
reflection (affine_span ℝ (s.points '' {i₁, i₂})) s.circumcenter =
(univ : finset (points_with_circumcenter_index n)).affine_combination
s.points_with_circumcenter (reflection_circumcenter_weights_with_circumcenter i₁ i₂) :=
begin
have hc : card ({i₁, i₂} : finset (fin (n + 1))) = 2,
{ simp [h] },
have h_faces : ↑(orthogonal_projection (affine_span ℝ (s.points '' {i₁, i₂})) s.circumcenter)
= ↑(orthogonal_projection (affine_span ℝ (set.range (s.face hc).points)) s.circumcenter),
{ apply eq_orthogonal_projection_of_eq_subspace,
simp },
rw [euclidean_geometry.reflection_apply, h_faces, s.orthogonal_projection_circumcenter hc,
circumcenter_eq_centroid, s.face_centroid_eq_centroid hc,
centroid_eq_affine_combination_of_points_with_circumcenter,
circumcenter_eq_affine_combination_of_points_with_circumcenter, ←@vsub_eq_zero_iff_eq V,
affine_combination_vsub, weighted_vsub_vadd_affine_combination, affine_combination_vsub,
weighted_vsub_apply, sum_points_with_circumcenter],
simp_rw [pi.sub_apply, pi.add_apply, pi.sub_apply, sub_smul, add_smul, sub_smul,
centroid_weights_with_circumcenter, circumcenter_weights_with_circumcenter,
reflection_circumcenter_weights_with_circumcenter, ite_smul, zero_smul, sub_zero,
apply_ite2 (+), add_zero, ←add_smul, hc, zero_sub, neg_smul, sub_self, add_zero],
convert sum_const_zero,
norm_num
end
end simplex
end affine
namespace euclidean_geometry
open affine affine_subspace finite_dimensional
variables {V : Type*} {P : Type*} [inner_product_space ℝ V] [metric_space P]
[normed_add_torsor V P]
include V
/-- Given a nonempty affine subspace, whose direction is complete,
that contains a set of points, those points are cospherical if and
only if they are equidistant from some point in that subspace. -/
lemma cospherical_iff_exists_mem_of_complete {s : affine_subspace ℝ P} {ps : set P} (h : ps ⊆ s)
[nonempty s] [complete_space s.direction] :
cospherical ps ↔ ∃ (center ∈ s) (radius : ℝ), ∀ p ∈ ps, dist p center = radius :=
begin
split,
{ rintro ⟨c, hcr⟩,
rw exists_dist_eq_iff_exists_dist_orthogonal_projection_eq h c at hcr,
exact ⟨orthogonal_projection s c, orthogonal_projection_mem _, hcr⟩ },
{ exact λ ⟨c, hc, hd⟩, ⟨c, hd⟩ }
end
/-- Given a nonempty affine subspace, whose direction is
finite-dimensional, that contains a set of points, those points are
cospherical if and only if they are equidistant from some point in
that subspace. -/
lemma cospherical_iff_exists_mem_of_finite_dimensional {s : affine_subspace ℝ P} {ps : set P}
(h : ps ⊆ s) [nonempty s] [finite_dimensional ℝ s.direction] :
cospherical ps ↔ ∃ (center ∈ s) (radius : ℝ), ∀ p ∈ ps, dist p center = radius :=
cospherical_iff_exists_mem_of_complete h
/-- All n-simplices among cospherical points in an n-dimensional
subspace have the same circumradius. -/
lemma exists_circumradius_eq_of_cospherical_subset {s : affine_subspace ℝ P} {ps : set P}
(h : ps ⊆ s) [nonempty s] {n : ℕ} [finite_dimensional ℝ s.direction]
(hd : finrank ℝ s.direction = n) (hc : cospherical ps) :
∃ r : ℝ, ∀ sx : simplex ℝ P n, set.range sx.points ⊆ ps → sx.circumradius = r :=
begin
rw cospherical_iff_exists_mem_of_finite_dimensional h at hc,
rcases hc with ⟨c, hc, r, hcr⟩,
use r,
intros sx hsxps,
have hsx : affine_span ℝ (set.range sx.points) = s,
{ refine sx.independent.affine_span_eq_of_le_of_card_eq_finrank_add_one
(span_points_subset_coe_of_subset_coe (hsxps.trans h)) _,
simp [hd] },
have hc : c ∈ affine_span ℝ (set.range sx.points) := hsx.symm ▸ hc,
exact (sx.eq_circumradius_of_dist_eq
hc
(λ i, hcr (sx.points i) (hsxps (set.mem_range_self i)))).symm
end
/-- Two n-simplices among cospherical points in an n-dimensional
subspace have the same circumradius. -/
lemma circumradius_eq_of_cospherical_subset {s : affine_subspace ℝ P} {ps : set P}
(h : ps ⊆ s) [nonempty s] {n : ℕ} [finite_dimensional ℝ s.direction]
(hd : finrank ℝ s.direction = n) (hc : cospherical ps) {sx₁ sx₂ : simplex ℝ P n}
(hsx₁ : set.range sx₁.points ⊆ ps) (hsx₂ : set.range sx₂.points ⊆ ps) :
sx₁.circumradius = sx₂.circumradius :=
begin
rcases exists_circumradius_eq_of_cospherical_subset h hd hc with ⟨r, hr⟩,
rw [hr sx₁ hsx₁, hr sx₂ hsx₂]
end
/-- All n-simplices among cospherical points in n-space have the same
circumradius. -/
lemma exists_circumradius_eq_of_cospherical {ps : set P} {n : ℕ} [finite_dimensional ℝ V]
(hd : finrank ℝ V = n) (hc : cospherical ps) :
∃ r : ℝ, ∀ sx : simplex ℝ P n, set.range sx.points ⊆ ps → sx.circumradius = r :=
begin
haveI : nonempty (⊤ : affine_subspace ℝ P) := set.univ.nonempty,
rw [←finrank_top, ←direction_top ℝ V P] at hd,
refine exists_circumradius_eq_of_cospherical_subset _ hd hc,
exact set.subset_univ _
end
/-- Two n-simplices among cospherical points in n-space have the same
circumradius. -/
lemma circumradius_eq_of_cospherical {ps : set P} {n : ℕ} [finite_dimensional ℝ V]
(hd : finrank ℝ V = n) (hc : cospherical ps) {sx₁ sx₂ : simplex ℝ P n}
(hsx₁ : set.range sx₁.points ⊆ ps) (hsx₂ : set.range sx₂.points ⊆ ps) :
sx₁.circumradius = sx₂.circumradius :=
begin
rcases exists_circumradius_eq_of_cospherical hd hc with ⟨r, hr⟩,
rw [hr sx₁ hsx₁, hr sx₂ hsx₂]
end
/-- All n-simplices among cospherical points in an n-dimensional
subspace have the same circumcenter. -/
lemma exists_circumcenter_eq_of_cospherical_subset {s : affine_subspace ℝ P} {ps : set P}
(h : ps ⊆ s) [nonempty s] {n : ℕ} [finite_dimensional ℝ s.direction]
(hd : finrank ℝ s.direction = n) (hc : cospherical ps) :
∃ c : P, ∀ sx : simplex ℝ P n, set.range sx.points ⊆ ps → sx.circumcenter = c :=
begin
rw cospherical_iff_exists_mem_of_finite_dimensional h at hc,
rcases hc with ⟨c, hc, r, hcr⟩,
use c,
intros sx hsxps,
have hsx : affine_span ℝ (set.range sx.points) = s,
{ refine sx.independent.affine_span_eq_of_le_of_card_eq_finrank_add_one
(span_points_subset_coe_of_subset_coe (hsxps.trans h)) _,
simp [hd] },
have hc : c ∈ affine_span ℝ (set.range sx.points) := hsx.symm ▸ hc,
exact (sx.eq_circumcenter_of_dist_eq
hc
(λ i, hcr (sx.points i) (hsxps (set.mem_range_self i)))).symm
end
/-- Two n-simplices among cospherical points in an n-dimensional
subspace have the same circumcenter. -/
lemma circumcenter_eq_of_cospherical_subset {s : affine_subspace ℝ P} {ps : set P}
(h : ps ⊆ s) [nonempty s] {n : ℕ} [finite_dimensional ℝ s.direction]
(hd : finrank ℝ s.direction = n) (hc : cospherical ps) {sx₁ sx₂ : simplex ℝ P n}
(hsx₁ : set.range sx₁.points ⊆ ps) (hsx₂ : set.range sx₂.points ⊆ ps) :
sx₁.circumcenter = sx₂.circumcenter :=
begin
rcases exists_circumcenter_eq_of_cospherical_subset h hd hc with ⟨r, hr⟩,
rw [hr sx₁ hsx₁, hr sx₂ hsx₂]
end
/-- All n-simplices among cospherical points in n-space have the same
circumcenter. -/
lemma exists_circumcenter_eq_of_cospherical {ps : set P} {n : ℕ} [finite_dimensional ℝ V]
(hd : finrank ℝ V = n) (hc : cospherical ps) :
∃ c : P, ∀ sx : simplex ℝ P n, set.range sx.points ⊆ ps → sx.circumcenter = c :=
begin
haveI : nonempty (⊤ : affine_subspace ℝ P) := set.univ.nonempty,
rw [←finrank_top, ←direction_top ℝ V P] at hd,
refine exists_circumcenter_eq_of_cospherical_subset _ hd hc,
exact set.subset_univ _
end
/-- Two n-simplices among cospherical points in n-space have the same
circumcenter. -/
lemma circumcenter_eq_of_cospherical {ps : set P} {n : ℕ} [finite_dimensional ℝ V]
(hd : finrank ℝ V = n) (hc : cospherical ps) {sx₁ sx₂ : simplex ℝ P n}
(hsx₁ : set.range sx₁.points ⊆ ps) (hsx₂ : set.range sx₂.points ⊆ ps) :
sx₁.circumcenter = sx₂.circumcenter :=
begin
rcases exists_circumcenter_eq_of_cospherical hd hc with ⟨r, hr⟩,
rw [hr sx₁ hsx₁, hr sx₂ hsx₂]
end
/-- Suppose all distances from `p₁` and `p₂` to the points of a
simplex are equal, and that `p₁` and `p₂` lie in the affine span of
`p` with the vertices of that simplex. Then `p₁` and `p₂` are equal
or reflections of each other in the affine span of the vertices of the
simplex. -/
lemma eq_or_eq_reflection_of_dist_eq {n : ℕ} {s : simplex ℝ P n} {p p₁ p₂ : P} {r : ℝ}
(hp₁ : p₁ ∈ affine_span ℝ (insert p (set.range s.points)))
(hp₂ : p₂ ∈ affine_span ℝ (insert p (set.range s.points)))
(h₁ : ∀ i, dist (s.points i) p₁ = r) (h₂ : ∀ i, dist (s.points i) p₂ = r) :
p₁ = p₂ ∨ p₁ = reflection (affine_span ℝ (set.range s.points)) p₂ :=
begin
let span_s := affine_span ℝ (set.range s.points),
have h₁' := s.orthogonal_projection_eq_circumcenter_of_dist_eq h₁,
have h₂' := s.orthogonal_projection_eq_circumcenter_of_dist_eq h₂,
rw [←affine_span_insert_affine_span,
mem_affine_span_insert_iff (orthogonal_projection_mem p)] at hp₁ hp₂,
obtain ⟨r₁, p₁o, hp₁o, hp₁⟩ := hp₁,
obtain ⟨r₂, p₂o, hp₂o, hp₂⟩ := hp₂,
obtain rfl : ↑(orthogonal_projection span_s p₁) = p₁o,
{ have := orthogonal_projection_vadd_smul_vsub_orthogonal_projection _ _ hp₁o,
rw ← hp₁ at this,
rw this,
refl },
rw h₁' at hp₁,
obtain rfl : ↑(orthogonal_projection span_s p₂) = p₂o,
{ have := orthogonal_projection_vadd_smul_vsub_orthogonal_projection _ _ hp₂o,
rw ← hp₂ at this,
rw this,
refl },
rw h₂' at hp₂,
have h : s.points 0 ∈ span_s := mem_affine_span ℝ (set.mem_range_self _),
have hd₁ : dist p₁ s.circumcenter * dist p₁ s.circumcenter =
r * r - s.circumradius * s.circumradius,
{ rw [dist_comm, ←h₁ 0,
dist_sq_eq_dist_orthogonal_projection_sq_add_dist_orthogonal_projection_sq p₁ h],
simp only [h₁', dist_comm p₁, add_sub_cancel', simplex.dist_circumcenter_eq_circumradius] },
have hd₂ : dist p₂ s.circumcenter * dist p₂ s.circumcenter =
r * r - s.circumradius * s.circumradius,
{ rw [dist_comm, ←h₂ 0,
dist_sq_eq_dist_orthogonal_projection_sq_add_dist_orthogonal_projection_sq p₂ h],
simp only [h₂', dist_comm p₂, add_sub_cancel', simplex.dist_circumcenter_eq_circumradius] },
rw [←hd₂, hp₁, hp₂, dist_eq_norm_vsub V _ s.circumcenter,
dist_eq_norm_vsub V _ s.circumcenter, vadd_vsub, vadd_vsub, ←real_inner_self_eq_norm_mul_norm,
←real_inner_self_eq_norm_mul_norm, real_inner_smul_left, real_inner_smul_left,
real_inner_smul_right, real_inner_smul_right, ←mul_assoc, ←mul_assoc] at hd₁,
by_cases hp : p = orthogonal_projection span_s p,
{ rw [hp₁, hp₂, ←hp],
simp only [true_or, eq_self_iff_true, smul_zero, vsub_self] },
{ have hz : ⟪p -ᵥ orthogonal_projection span_s p, p -ᵥ orthogonal_projection span_s p⟫ ≠ 0,
by simpa only [ne.def, vsub_eq_zero_iff_eq, inner_self_eq_zero] using hp,
rw [mul_left_inj' hz, mul_self_eq_mul_self_iff] at hd₁,
rw [hp₁, hp₂],
cases hd₁,
{ left,
rw hd₁ },
{ right,
rw [hd₁,
reflection_vadd_smul_vsub_orthogonal_projection p r₂ s.circumcenter_mem_affine_span,
neg_smul] } }
end
end euclidean_geometry
|
6db79011d55b51b4401676284d716113bec1fb06
|
c777c32c8e484e195053731103c5e52af26a25d1
|
/src/measure_theory/integral/set_to_l1.lean
|
4b2fece04f2c5a72a2aa13cfc93f078aebaee408
|
[
"Apache-2.0"
] |
permissive
|
kbuzzard/mathlib
|
2ff9e85dfe2a46f4b291927f983afec17e946eb8
|
58537299e922f9c77df76cb613910914a479c1f7
|
refs/heads/master
| 1,685,313,702,744
| 1,683,974,212,000
| 1,683,974,212,000
| 128,185,277
| 1
| 0
| null | 1,522,920,600,000
| 1,522,920,600,000
| null |
UTF-8
|
Lean
| false
| false
| 88,218
|
lean
|
/-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne
-/
import measure_theory.function.simple_func_dense_lp
/-!
# Extension of a linear function from indicators to L1
Let `T : set α → E →L[ℝ] F` be additive for measurable sets with finite measure, in the sense that
for `s, t` two such sets, `s ∩ t = ∅ → T (s ∪ t) = T s + T t`. `T` is akin to a bilinear map on
`set α × E`, or a linear map on indicator functions.
This file constructs an extension of `T` to integrable simple functions, which are finite sums of
indicators of measurable sets with finite measure, then to integrable functions, which are limits of
integrable simple functions.
The main result is a continuous linear map `(α →₁[μ] E) →L[ℝ] F`. This extension process is used to
define the Bochner integral in the `measure_theory.integral.bochner` file and the conditional
expectation of an integrable function in `measure_theory.function.conditional_expectation`.
## Main Definitions
- `fin_meas_additive μ T`: the property that `T` is additive on measurable sets with finite measure.
For two such sets, `s ∩ t = ∅ → T (s ∪ t) = T s + T t`.
- `dominated_fin_meas_additive μ T C`: `fin_meas_additive μ T ∧ ∀ s, ‖T s‖ ≤ C * (μ s).to_real`.
This is the property needed to perform the extension from indicators to L1.
- `set_to_L1 (hT : dominated_fin_meas_additive μ T C) : (α →₁[μ] E) →L[ℝ] F`: the extension of `T`
from indicators to L1.
- `set_to_fun μ T (hT : dominated_fin_meas_additive μ T C) (f : α → E) : F`: a version of the
extension which applies to functions (with value 0 if the function is not integrable).
## Properties
For most properties of `set_to_fun`, we provide two lemmas. One version uses hypotheses valid on
all sets, like `T = T'`, and a second version which uses a primed name uses hypotheses on
measurable sets with finite measure, like `∀ s, measurable_set s → μ s < ∞ → T s = T' s`.
The lemmas listed here don't show all hypotheses. Refer to the actual lemmas for details.
Linearity:
- `set_to_fun_zero_left : set_to_fun μ 0 hT f = 0`
- `set_to_fun_add_left : set_to_fun μ (T + T') _ f = set_to_fun μ T hT f + set_to_fun μ T' hT' f`
- `set_to_fun_smul_left : set_to_fun μ (λ s, c • (T s)) (hT.smul c) f = c • set_to_fun μ T hT f`
- `set_to_fun_zero : set_to_fun μ T hT (0 : α → E) = 0`
- `set_to_fun_neg : set_to_fun μ T hT (-f) = - set_to_fun μ T hT f`
If `f` and `g` are integrable:
- `set_to_fun_add : set_to_fun μ T hT (f + g) = set_to_fun μ T hT f + set_to_fun μ T hT g`
- `set_to_fun_sub : set_to_fun μ T hT (f - g) = set_to_fun μ T hT f - set_to_fun μ T hT g`
If `T` is verifies `∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x`:
- `set_to_fun_smul : set_to_fun μ T hT (c • f) = c • set_to_fun μ T hT f`
Other:
- `set_to_fun_congr_ae (h : f =ᵐ[μ] g) : set_to_fun μ T hT f = set_to_fun μ T hT g`
- `set_to_fun_measure_zero (h : μ = 0) : set_to_fun μ T hT f = 0`
If the space is a `normed_lattice_add_comm_group` and `T` is such that `0 ≤ T s x` for `0 ≤ x`, we
also prove order-related properties:
- `set_to_fun_mono_left (h : ∀ s x, T s x ≤ T' s x) : set_to_fun μ T hT f ≤ set_to_fun μ T' hT' f`
- `set_to_fun_nonneg (hf : 0 ≤ᵐ[μ] f) : 0 ≤ set_to_fun μ T hT f`
- `set_to_fun_mono (hfg : f ≤ᵐ[μ] g) : set_to_fun μ T hT f ≤ set_to_fun μ T hT g`
## Implementation notes
The starting object `T : set α → E →L[ℝ] F` matters only through its restriction on measurable sets
with finite measure. Its value on other sets is ignored.
-/
noncomputable theory
open_locale classical topology big_operators nnreal ennreal measure_theory pointwise
open set filter topological_space ennreal emetric
namespace measure_theory
variables {α E F F' G 𝕜 : Type*} {p : ℝ≥0∞}
[normed_add_comm_group E] [normed_space ℝ E]
[normed_add_comm_group F] [normed_space ℝ F]
[normed_add_comm_group F'] [normed_space ℝ F']
[normed_add_comm_group G]
{m : measurable_space α} {μ : measure α}
local infixr ` →ₛ `:25 := simple_func
open finset
section fin_meas_additive
/-- A set function is `fin_meas_additive` if its value on the union of two disjoint measurable
sets with finite measure is the sum of its values on each set. -/
def fin_meas_additive {β} [add_monoid β] {m : measurable_space α}
(μ : measure α) (T : set α → β) : Prop :=
∀ s t, measurable_set s → measurable_set t → μ s ≠ ∞ → μ t ≠ ∞ → s ∩ t = ∅ → T (s ∪ t) = T s + T t
namespace fin_meas_additive
variables {β : Type*} [add_comm_monoid β] {T T' : set α → β}
lemma zero : fin_meas_additive μ (0 : set α → β) := λ s t hs ht hμs hμt hst, by simp
lemma add (hT : fin_meas_additive μ T) (hT' : fin_meas_additive μ T') :
fin_meas_additive μ (T + T') :=
begin
intros s t hs ht hμs hμt hst,
simp only [hT s t hs ht hμs hμt hst, hT' s t hs ht hμs hμt hst, pi.add_apply],
abel,
end
lemma smul [monoid 𝕜] [distrib_mul_action 𝕜 β] (hT : fin_meas_additive μ T) (c : 𝕜) :
fin_meas_additive μ (λ s, c • (T s)) :=
λ s t hs ht hμs hμt hst, by simp [hT s t hs ht hμs hμt hst]
lemma of_eq_top_imp_eq_top {μ' : measure α}
(h : ∀ s, measurable_set s → μ s = ∞ → μ' s = ∞) (hT : fin_meas_additive μ T) :
fin_meas_additive μ' T :=
λ s t hs ht hμ's hμ't hst, hT s t hs ht (mt (h s hs) hμ's) (mt (h t ht) hμ't) hst
lemma of_smul_measure (c : ℝ≥0∞) (hc_ne_top : c ≠ ∞) (hT : fin_meas_additive (c • μ) T) :
fin_meas_additive μ T :=
begin
refine of_eq_top_imp_eq_top (λ s hs hμs, _) hT,
rw [measure.smul_apply, smul_eq_mul, with_top.mul_eq_top_iff] at hμs,
simp only [hc_ne_top, or_false, ne.def, false_and] at hμs,
exact hμs.2,
end
lemma smul_measure (c : ℝ≥0∞) (hc_ne_zero : c ≠ 0) (hT : fin_meas_additive μ T) :
fin_meas_additive (c • μ) T :=
begin
refine of_eq_top_imp_eq_top (λ s hs hμs, _) hT,
rw [measure.smul_apply, smul_eq_mul, with_top.mul_eq_top_iff],
simp only [hc_ne_zero, true_and, ne.def, not_false_iff],
exact or.inl hμs,
end
lemma smul_measure_iff (c : ℝ≥0∞) (hc_ne_zero : c ≠ 0) (hc_ne_top : c ≠ ∞) :
fin_meas_additive (c • μ) T ↔ fin_meas_additive μ T :=
⟨λ hT, of_smul_measure c hc_ne_top hT, λ hT, smul_measure c hc_ne_zero hT⟩
lemma map_empty_eq_zero {β} [add_cancel_monoid β] {T : set α → β} (hT : fin_meas_additive μ T) :
T ∅ = 0 :=
begin
have h_empty : μ ∅ ≠ ∞, from (measure_empty.le.trans_lt ennreal.coe_lt_top).ne,
specialize hT ∅ ∅ measurable_set.empty measurable_set.empty h_empty h_empty
(set.inter_empty ∅),
rw set.union_empty at hT,
nth_rewrite 0 ← add_zero (T ∅) at hT,
exact (add_left_cancel hT).symm,
end
lemma map_Union_fin_meas_set_eq_sum (T : set α → β) (T_empty : T ∅ = 0)
(h_add : fin_meas_additive μ T)
{ι} (S : ι → set α) (sι : finset ι) (hS_meas : ∀ i, measurable_set (S i))
(hSp : ∀ i ∈ sι, μ (S i) ≠ ∞) (h_disj : ∀ i j ∈ sι, i ≠ j → disjoint (S i) (S j)) :
T (⋃ i ∈ sι, S i) = ∑ i in sι, T (S i) :=
begin
revert hSp h_disj,
refine finset.induction_on sι _ _,
{ simp only [finset.not_mem_empty, is_empty.forall_iff, Union_false, Union_empty, sum_empty,
forall_2_true_iff, implies_true_iff, forall_true_left, not_false_iff, T_empty], },
intros a s has h hps h_disj,
rw [finset.sum_insert has, ← h],
swap, { exact λ i hi, hps i (finset.mem_insert_of_mem hi), },
swap, { exact λ i hi j hj hij,
h_disj i (finset.mem_insert_of_mem hi) j (finset.mem_insert_of_mem hj) hij, },
rw ← h_add (S a) (⋃ i ∈ s, S i) (hS_meas a) (measurable_set_bUnion _ (λ i _, hS_meas i))
(hps a (finset.mem_insert_self a s)),
{ congr, convert finset.supr_insert a s S, },
{ exact ((measure_bUnion_finset_le _ _).trans_lt $
ennreal.sum_lt_top $ λ i hi, hps i $ finset.mem_insert_of_mem hi).ne, },
{ simp_rw set.inter_Union,
refine Union_eq_empty.mpr (λ i, Union_eq_empty.mpr (λ hi, _)),
rw ← set.disjoint_iff_inter_eq_empty,
refine h_disj a (finset.mem_insert_self a s) i (finset.mem_insert_of_mem hi) (λ hai, _),
rw ← hai at hi,
exact has hi, },
end
end fin_meas_additive
/-- A `fin_meas_additive` set function whose norm on every set is less than the measure of the
set (up to a multiplicative constant). -/
def dominated_fin_meas_additive {β} [seminormed_add_comm_group β] {m : measurable_space α}
(μ : measure α) (T : set α → β) (C : ℝ) : Prop :=
fin_meas_additive μ T ∧ ∀ s, measurable_set s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).to_real
namespace dominated_fin_meas_additive
variables {β : Type*} [seminormed_add_comm_group β] {T T' : set α → β} {C C' : ℝ}
lemma zero {m : measurable_space α} (μ : measure α) (hC : 0 ≤ C) :
dominated_fin_meas_additive μ (0 : set α → β) C :=
begin
refine ⟨fin_meas_additive.zero, λ s hs hμs, _⟩,
rw [pi.zero_apply, norm_zero],
exact mul_nonneg hC to_real_nonneg,
end
lemma eq_zero_of_measure_zero {β : Type*} [normed_add_comm_group β] {T : set α → β} {C : ℝ}
(hT : dominated_fin_meas_additive μ T C) {s : set α}
(hs : measurable_set s) (hs_zero : μ s = 0) :
T s = 0 :=
begin
refine norm_eq_zero.mp _,
refine ((hT.2 s hs (by simp [hs_zero])).trans (le_of_eq _)).antisymm (norm_nonneg _),
rw [hs_zero, ennreal.zero_to_real, mul_zero],
end
lemma eq_zero {β : Type*} [normed_add_comm_group β] {T : set α → β} {C : ℝ}
{m : measurable_space α} (hT : dominated_fin_meas_additive (0 : measure α) T C)
{s : set α} (hs : measurable_set s) :
T s = 0 :=
eq_zero_of_measure_zero hT hs (by simp only [measure.coe_zero, pi.zero_apply])
lemma add (hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C') :
dominated_fin_meas_additive μ (T + T') (C + C') :=
begin
refine ⟨hT.1.add hT'.1, λ s hs hμs, _⟩,
rw [pi.add_apply, add_mul],
exact (norm_add_le _ _).trans (add_le_add (hT.2 s hs hμs) (hT'.2 s hs hμs)),
end
lemma smul [normed_field 𝕜] [normed_space 𝕜 β] (hT : dominated_fin_meas_additive μ T C)
(c : 𝕜) :
dominated_fin_meas_additive μ (λ s, c • (T s)) (‖c‖ * C) :=
begin
refine ⟨hT.1.smul c, λ s hs hμs, _⟩,
dsimp only,
rw [norm_smul, mul_assoc],
exact mul_le_mul le_rfl (hT.2 s hs hμs) (norm_nonneg _) (norm_nonneg _),
end
lemma of_measure_le {μ' : measure α} (h : μ ≤ μ') (hT : dominated_fin_meas_additive μ T C)
(hC : 0 ≤ C) :
dominated_fin_meas_additive μ' T C :=
begin
have h' : ∀ s, measurable_set s → μ s = ∞ → μ' s = ∞,
{ intros s hs hμs, rw [eq_top_iff, ← hμs], exact h s hs, },
refine ⟨hT.1.of_eq_top_imp_eq_top h', λ s hs hμ's, _⟩,
have hμs : μ s < ∞, from (h s hs).trans_lt hμ's,
refine (hT.2 s hs hμs).trans (mul_le_mul le_rfl _ ennreal.to_real_nonneg hC),
rw to_real_le_to_real hμs.ne hμ's.ne,
exact h s hs,
end
lemma add_measure_right {m : measurable_space α}
(μ ν : measure α) (hT : dominated_fin_meas_additive μ T C) (hC : 0 ≤ C) :
dominated_fin_meas_additive (μ + ν) T C :=
of_measure_le (measure.le_add_right le_rfl) hT hC
lemma add_measure_left {m : measurable_space α}
(μ ν : measure α) (hT : dominated_fin_meas_additive ν T C) (hC : 0 ≤ C) :
dominated_fin_meas_additive (μ + ν) T C :=
of_measure_le (measure.le_add_left le_rfl) hT hC
lemma of_smul_measure (c : ℝ≥0∞) (hc_ne_top : c ≠ ∞)
(hT : dominated_fin_meas_additive (c • μ) T C) :
dominated_fin_meas_additive μ T (c.to_real * C) :=
begin
have h : ∀ s, measurable_set s → c • μ s = ∞ → μ s = ∞,
{ intros s hs hcμs,
simp only [hc_ne_top, algebra.id.smul_eq_mul, with_top.mul_eq_top_iff, or_false, ne.def,
false_and] at hcμs,
exact hcμs.2, },
refine ⟨hT.1.of_eq_top_imp_eq_top h, λ s hs hμs, _⟩,
have hcμs : c • μ s ≠ ∞, from mt (h s hs) hμs.ne,
rw smul_eq_mul at hcμs,
simp_rw [dominated_fin_meas_additive, measure.smul_apply, smul_eq_mul, to_real_mul] at hT,
refine (hT.2 s hs hcμs.lt_top).trans (le_of_eq _),
ring,
end
lemma of_measure_le_smul {μ' : measure α} (c : ℝ≥0∞) (hc : c ≠ ∞) (h : μ ≤ c • μ')
(hT : dominated_fin_meas_additive μ T C) (hC : 0 ≤ C) :
dominated_fin_meas_additive μ' T (c.to_real * C) :=
(hT.of_measure_le h hC).of_smul_measure c hc
end dominated_fin_meas_additive
end fin_meas_additive
namespace simple_func
/-- Extend `set α → (F →L[ℝ] F')` to `(α →ₛ F) → F'`. -/
def set_to_simple_func {m : measurable_space α} (T : set α → F →L[ℝ] F') (f : α →ₛ F) : F' :=
∑ x in f.range, T (f ⁻¹' {x}) x
@[simp] lemma set_to_simple_func_zero {m : measurable_space α} (f : α →ₛ F) :
set_to_simple_func (0 : set α → F →L[ℝ] F') f = 0 :=
by simp [set_to_simple_func]
lemma set_to_simple_func_zero' {T : set α → E →L[ℝ] F'}
(h_zero : ∀ s, measurable_set s → μ s < ∞ → T s = 0) (f : α →ₛ E) (hf : integrable f μ) :
set_to_simple_func T f = 0 :=
begin
simp_rw set_to_simple_func,
refine sum_eq_zero (λ x hx, _),
by_cases hx0 : x = 0,
{ simp [hx0], },
rw [h_zero (f ⁻¹' ({x} : set E)) (measurable_set_fiber _ _)
(measure_preimage_lt_top_of_integrable f hf hx0),
continuous_linear_map.zero_apply],
end
@[simp] lemma set_to_simple_func_zero_apply {m : measurable_space α} (T : set α → F →L[ℝ] F') :
set_to_simple_func T (0 : α →ₛ F) = 0 :=
by casesI is_empty_or_nonempty α; simp [set_to_simple_func]
lemma set_to_simple_func_eq_sum_filter {m : measurable_space α}
(T : set α → F →L[ℝ] F') (f : α →ₛ F) :
set_to_simple_func T f = ∑ x in f.range.filter (λ x, x ≠ 0), (T (f ⁻¹' {x})) x :=
begin
symmetry,
refine sum_filter_of_ne (λ x hx, mt (λ hx0, _)),
rw hx0,
exact continuous_linear_map.map_zero _,
end
lemma map_set_to_simple_func (T : set α → F →L[ℝ] F') (h_add : fin_meas_additive μ T)
{f : α →ₛ G} (hf : integrable f μ) {g : G → F} (hg : g 0 = 0) :
(f.map g).set_to_simple_func T = ∑ x in f.range, T (f ⁻¹' {x}) (g x) :=
begin
have T_empty : T ∅ = 0, from h_add.map_empty_eq_zero,
have hfp : ∀ x ∈ f.range, x ≠ 0 → μ (f ⁻¹' {x}) ≠ ∞,
from λ x hx hx0, (measure_preimage_lt_top_of_integrable f hf hx0).ne,
simp only [set_to_simple_func, range_map],
refine finset.sum_image' _ (assume b hb, _),
rcases mem_range.1 hb with ⟨a, rfl⟩,
by_cases h0 : g (f a) = 0,
{ simp_rw h0,
rw [continuous_linear_map.map_zero, finset.sum_eq_zero (λ x hx, _)],
rw mem_filter at hx,
rw [hx.2, continuous_linear_map.map_zero], },
have h_left_eq : T ((map g f) ⁻¹' {g (f a)}) (g (f a))
= T (f ⁻¹' ↑(f.range.filter (λ b, g b = g (f a)))) (g (f a)),
{ congr, rw map_preimage_singleton, },
rw h_left_eq,
have h_left_eq' : T (f ⁻¹' ↑(filter (λ (b : G), g b = g (f a)) f.range)) (g (f a))
= T (⋃ y ∈ (filter (λ (b : G), g b = g (f a)) f.range), f ⁻¹' {y}) (g (f a)),
{ congr, rw ← finset.set_bUnion_preimage_singleton, },
rw h_left_eq',
rw h_add.map_Union_fin_meas_set_eq_sum T T_empty,
{ simp only [filter_congr_decidable, sum_apply, continuous_linear_map.coe_sum'],
refine finset.sum_congr rfl (λ x hx, _),
rw mem_filter at hx,
rw hx.2, },
{ exact λ i, measurable_set_fiber _ _, },
{ intros i hi,
rw mem_filter at hi,
refine hfp i hi.1 (λ hi0, _),
rw [hi0, hg] at hi,
exact h0 hi.2.symm, },
{ intros i j hi hj hij,
rw set.disjoint_iff,
intros x hx,
rw [set.mem_inter_iff, set.mem_preimage, set.mem_preimage, set.mem_singleton_iff,
set.mem_singleton_iff] at hx,
rw [← hx.1, ← hx.2] at hij,
exact absurd rfl hij, },
end
lemma set_to_simple_func_congr' (T : set α → E →L[ℝ] F) (h_add : fin_meas_additive μ T)
{f g : α →ₛ E} (hf : integrable f μ) (hg : integrable g μ)
(h : ∀ x y, x ≠ y → T ((f ⁻¹' {x}) ∩ (g ⁻¹' {y})) = 0) :
f.set_to_simple_func T = g.set_to_simple_func T :=
show ((pair f g).map prod.fst).set_to_simple_func T
= ((pair f g).map prod.snd).set_to_simple_func T, from
begin
have h_pair : integrable (f.pair g) μ, from integrable_pair hf hg,
rw map_set_to_simple_func T h_add h_pair prod.fst_zero,
rw map_set_to_simple_func T h_add h_pair prod.snd_zero,
refine finset.sum_congr rfl (λ p hp, _),
rcases mem_range.1 hp with ⟨a, rfl⟩,
by_cases eq : f a = g a,
{ dsimp only [pair_apply], rw eq },
{ have : T ((pair f g) ⁻¹' {(f a, g a)}) = 0,
{ have h_eq : T (⇑(f.pair g) ⁻¹' {(f a, g a)}) = T ((f ⁻¹' {f a}) ∩ (g ⁻¹' {g a})),
{ congr, rw pair_preimage_singleton f g, },
rw h_eq,
exact h (f a) (g a) eq, },
simp only [this, continuous_linear_map.zero_apply, pair_apply], },
end
lemma set_to_simple_func_congr (T : set α → (E →L[ℝ] F))
(h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0) (h_add : fin_meas_additive μ T)
{f g : α →ₛ E} (hf : integrable f μ) (h : f =ᵐ[μ] g) :
f.set_to_simple_func T = g.set_to_simple_func T :=
begin
refine set_to_simple_func_congr' T h_add hf ((integrable_congr h).mp hf) _,
refine λ x y hxy, h_zero _ ((measurable_set_fiber f x).inter (measurable_set_fiber g y)) _,
rw [eventually_eq, ae_iff] at h,
refine measure_mono_null (λ z, _) h,
simp_rw [set.mem_inter_iff, set.mem_set_of_eq, set.mem_preimage, set.mem_singleton_iff],
intro h,
rwa [h.1, h.2],
end
lemma set_to_simple_func_congr_left (T T' : set α → E →L[ℝ] F)
(h : ∀ s, measurable_set s → μ s < ∞ → T s = T' s) (f : α →ₛ E) (hf : integrable f μ) :
set_to_simple_func T f = set_to_simple_func T' f :=
begin
simp_rw set_to_simple_func,
refine sum_congr rfl (λ x hx, _),
by_cases hx0 : x = 0,
{ simp [hx0], },
{ rw h (f ⁻¹' {x}) (simple_func.measurable_set_fiber _ _)
(simple_func.measure_preimage_lt_top_of_integrable _ hf hx0), },
end
lemma set_to_simple_func_add_left {m : measurable_space α} (T T' : set α → F →L[ℝ] F')
{f : α →ₛ F} :
set_to_simple_func (T + T') f = set_to_simple_func T f + set_to_simple_func T' f :=
begin
simp_rw [set_to_simple_func, pi.add_apply],
push_cast,
simp_rw [pi.add_apply, sum_add_distrib],
end
lemma set_to_simple_func_add_left' (T T' T'' : set α → E →L[ℝ] F)
(h_add : ∀ s, measurable_set s → μ s < ∞ → T'' s = T s + T' s) {f : α →ₛ E}
(hf : integrable f μ) :
set_to_simple_func (T'') f = set_to_simple_func T f + set_to_simple_func T' f :=
begin
simp_rw [set_to_simple_func_eq_sum_filter],
suffices : ∀ x ∈ filter (λ (x : E), x ≠ 0) f.range,
T'' (f ⁻¹' {x}) = T (f ⁻¹' {x}) + T' (f ⁻¹' {x}),
{ rw ← sum_add_distrib,
refine finset.sum_congr rfl (λ x hx, _),
rw this x hx,
push_cast,
rw pi.add_apply, },
intros x hx,
refine h_add (f ⁻¹' {x}) (measurable_set_preimage _ _)
(measure_preimage_lt_top_of_integrable _ hf _),
rw mem_filter at hx,
exact hx.2,
end
lemma set_to_simple_func_smul_left {m : measurable_space α}
(T : set α → F →L[ℝ] F') (c : ℝ) (f : α →ₛ F) :
set_to_simple_func (λ s, c • (T s)) f = c • set_to_simple_func T f :=
by simp_rw [set_to_simple_func, continuous_linear_map.smul_apply, smul_sum]
lemma set_to_simple_func_smul_left'
(T T' : set α → E →L[ℝ] F') (c : ℝ) (h_smul : ∀ s, measurable_set s → μ s < ∞ → T' s = c • (T s))
{f : α →ₛ E} (hf : integrable f μ) :
set_to_simple_func T' f = c • set_to_simple_func T f :=
begin
simp_rw [set_to_simple_func_eq_sum_filter],
suffices : ∀ x ∈ filter (λ (x : E), x ≠ 0) f.range, T' (f ⁻¹' {x}) = c • (T (f ⁻¹' {x})),
{ rw smul_sum,
refine finset.sum_congr rfl (λ x hx, _),
rw this x hx,
refl, },
intros x hx,
refine h_smul (f ⁻¹' {x}) (measurable_set_preimage _ _)
(measure_preimage_lt_top_of_integrable _ hf _),
rw mem_filter at hx,
exact hx.2,
end
lemma set_to_simple_func_add (T : set α → E →L[ℝ] F) (h_add : fin_meas_additive μ T)
{f g : α →ₛ E} (hf : integrable f μ) (hg : integrable g μ) :
set_to_simple_func T (f + g) = set_to_simple_func T f + set_to_simple_func T g :=
have hp_pair : integrable (f.pair g) μ, from integrable_pair hf hg,
calc set_to_simple_func T (f + g) = ∑ x in (pair f g).range,
T ((pair f g) ⁻¹' {x}) (x.fst + x.snd) :
by { rw [add_eq_map₂, map_set_to_simple_func T h_add hp_pair], simp, }
... = ∑ x in (pair f g).range, (T ((pair f g) ⁻¹' {x}) x.fst + T ((pair f g) ⁻¹' {x}) x.snd) :
finset.sum_congr rfl $ assume a ha, continuous_linear_map.map_add _ _ _
... = ∑ x in (pair f g).range, T ((pair f g) ⁻¹' {x}) x.fst +
∑ x in (pair f g).range, T ((pair f g) ⁻¹' {x}) x.snd :
by rw finset.sum_add_distrib
... = ((pair f g).map prod.fst).set_to_simple_func T
+ ((pair f g).map prod.snd).set_to_simple_func T :
by rw [map_set_to_simple_func T h_add hp_pair prod.snd_zero,
map_set_to_simple_func T h_add hp_pair prod.fst_zero]
lemma set_to_simple_func_neg (T : set α → E →L[ℝ] F) (h_add : fin_meas_additive μ T)
{f : α →ₛ E} (hf : integrable f μ) :
set_to_simple_func T (-f) = - set_to_simple_func T f :=
calc set_to_simple_func T (-f) = set_to_simple_func T (f.map (has_neg.neg)) : rfl
... = - set_to_simple_func T f :
begin
rw [map_set_to_simple_func T h_add hf neg_zero, set_to_simple_func,
← sum_neg_distrib],
exact finset.sum_congr rfl (λ x h, continuous_linear_map.map_neg _ _),
end
lemma set_to_simple_func_sub (T : set α → E →L[ℝ] F) (h_add : fin_meas_additive μ T)
{f g : α →ₛ E} (hf : integrable f μ) (hg : integrable g μ) :
set_to_simple_func T (f - g) = set_to_simple_func T f - set_to_simple_func T g :=
begin
rw [sub_eq_add_neg, set_to_simple_func_add T h_add hf,
set_to_simple_func_neg T h_add hg, sub_eq_add_neg],
rw integrable_iff at hg ⊢,
intros x hx_ne,
change μ ((has_neg.neg ∘ g) ⁻¹' {x}) < ∞,
rw [preimage_comp, neg_preimage, set.neg_singleton],
refine hg (-x) _,
simp [hx_ne],
end
lemma set_to_simple_func_smul_real (T : set α → E →L[ℝ] F) (h_add : fin_meas_additive μ T)
(c : ℝ) {f : α →ₛ E} (hf : integrable f μ) :
set_to_simple_func T (c • f) = c • set_to_simple_func T f :=
calc set_to_simple_func T (c • f) = ∑ x in f.range, T (f ⁻¹' {x}) (c • x) :
by { rw [smul_eq_map c f, map_set_to_simple_func T h_add hf], rw smul_zero, }
... = ∑ x in f.range, c • (T (f ⁻¹' {x}) x) :
finset.sum_congr rfl $ λ b hb, by { rw continuous_linear_map.map_smul (T (f ⁻¹' {b})) c b, }
... = c • set_to_simple_func T f :
by simp only [set_to_simple_func, smul_sum, smul_smul, mul_comm]
lemma set_to_simple_func_smul {E} [normed_add_comm_group E] [normed_field 𝕜]
[normed_space 𝕜 E] [normed_space ℝ E] [normed_space 𝕜 F] (T : set α → E →L[ℝ] F)
(h_add : fin_meas_additive μ T) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x)
(c : 𝕜) {f : α →ₛ E} (hf : integrable f μ) :
set_to_simple_func T (c • f) = c • set_to_simple_func T f :=
calc set_to_simple_func T (c • f) = ∑ x in f.range, T (f ⁻¹' {x}) (c • x) :
by { rw [smul_eq_map c f, map_set_to_simple_func T h_add hf],
rw smul_zero, }
... = ∑ x in f.range, c • (T (f ⁻¹' {x}) x) : finset.sum_congr rfl $ λ b hb, by { rw h_smul, }
... = c • set_to_simple_func T f : by simp only [set_to_simple_func, smul_sum, smul_smul, mul_comm]
section order
variables {G' G'' : Type*} [normed_lattice_add_comm_group G''] [normed_space ℝ G'']
[normed_lattice_add_comm_group G'] [normed_space ℝ G']
lemma set_to_simple_func_mono_left {m : measurable_space α}
(T T' : set α → F →L[ℝ] G'') (hTT' : ∀ s x, T s x ≤ T' s x) (f : α →ₛ F) :
set_to_simple_func T f ≤ set_to_simple_func T' f :=
by { simp_rw set_to_simple_func, exact sum_le_sum (λ i hi, hTT' _ i), }
lemma set_to_simple_func_mono_left'
(T T' : set α → E →L[ℝ] G'') (hTT' : ∀ s, measurable_set s → μ s < ∞ → ∀ x, T s x ≤ T' s x)
(f : α →ₛ E) (hf : integrable f μ) :
set_to_simple_func T f ≤ set_to_simple_func T' f :=
begin
refine sum_le_sum (λ i hi, _),
by_cases h0 : i = 0,
{ simp [h0], },
{ exact hTT' _ (measurable_set_fiber _ _) (measure_preimage_lt_top_of_integrable _ hf h0) i, }
end
lemma set_to_simple_func_nonneg {m : measurable_space α}
(T : set α → G' →L[ℝ] G'') (hT_nonneg : ∀ s x, 0 ≤ x → 0 ≤ T s x) (f : α →ₛ G') (hf : 0 ≤ f) :
0 ≤ set_to_simple_func T f :=
begin
refine sum_nonneg (λ i hi, hT_nonneg _ i _),
rw mem_range at hi,
obtain ⟨y, hy⟩ := set.mem_range.mp hi,
rw ← hy,
refine le_trans _ (hf y),
simp,
end
lemma set_to_simple_func_nonneg' (T : set α → G' →L[ℝ] G'')
(hT_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x)
(f : α →ₛ G') (hf : 0 ≤ f) (hfi : integrable f μ) :
0 ≤ set_to_simple_func T f :=
begin
refine sum_nonneg (λ i hi, _),
by_cases h0 : i = 0,
{ simp [h0], },
refine hT_nonneg _ (measurable_set_fiber _ _)
(measure_preimage_lt_top_of_integrable _ hfi h0) i _,
rw mem_range at hi,
obtain ⟨y, hy⟩ := set.mem_range.mp hi,
rw ← hy,
convert (hf y),
end
lemma set_to_simple_func_mono
{T : set α → G' →L[ℝ] G''} (h_add : fin_meas_additive μ T)
(hT_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α →ₛ G'}
(hfi : integrable f μ) (hgi : integrable g μ) (hfg : f ≤ g) :
set_to_simple_func T f ≤ set_to_simple_func T g :=
begin
rw [← sub_nonneg, ← set_to_simple_func_sub T h_add hgi hfi],
refine set_to_simple_func_nonneg' T hT_nonneg _ _ (hgi.sub hfi),
intro x,
simp only [coe_sub, sub_nonneg, coe_zero, pi.zero_apply, pi.sub_apply],
exact hfg x,
end
end order
lemma norm_set_to_simple_func_le_sum_op_norm {m : measurable_space α}
(T : set α → F' →L[ℝ] F) (f : α →ₛ F') :
‖f.set_to_simple_func T‖ ≤ ∑ x in f.range, ‖T (f ⁻¹' {x})‖ * ‖x‖ :=
calc ‖∑ x in f.range, T (f ⁻¹' {x}) x‖
≤ ∑ x in f.range, ‖T (f ⁻¹' {x}) x‖ : norm_sum_le _ _
... ≤ ∑ x in f.range, ‖T (f ⁻¹' {x})‖ * ‖x‖ :
by { refine finset.sum_le_sum (λb hb, _), simp_rw continuous_linear_map.le_op_norm, }
lemma norm_set_to_simple_func_le_sum_mul_norm (T : set α → F →L[ℝ] F') {C : ℝ}
(hT_norm : ∀ s, measurable_set s → ‖T s‖ ≤ C * (μ s).to_real) (f : α →ₛ F) :
‖f.set_to_simple_func T‖ ≤ C * ∑ x in f.range, (μ (f ⁻¹' {x})).to_real * ‖x‖ :=
calc ‖f.set_to_simple_func T‖
≤ ∑ x in f.range, ‖T (f ⁻¹' {x})‖ * ‖x‖ : norm_set_to_simple_func_le_sum_op_norm T f
... ≤ ∑ x in f.range, C * (μ (f ⁻¹' {x})).to_real * ‖x‖
: sum_le_sum $ λ b hb, mul_le_mul_of_nonneg_right
(hT_norm _ $ simple_func.measurable_set_fiber _ _) $ norm_nonneg _
... ≤ C * ∑ x in f.range, (μ (f ⁻¹' {x})).to_real * ‖x‖ : by simp_rw [mul_sum, ← mul_assoc]
lemma norm_set_to_simple_func_le_sum_mul_norm_of_integrable (T : set α → E →L[ℝ] F') {C : ℝ}
(hT_norm : ∀ s, measurable_set s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).to_real) (f : α →ₛ E)
(hf : integrable f μ) :
‖f.set_to_simple_func T‖ ≤ C * ∑ x in f.range, (μ (f ⁻¹' {x})).to_real * ‖x‖ :=
calc ‖f.set_to_simple_func T‖
≤ ∑ x in f.range, ‖T (f ⁻¹' {x})‖ * ‖x‖ : norm_set_to_simple_func_le_sum_op_norm T f
... ≤ ∑ x in f.range, C * (μ (f ⁻¹' {x})).to_real * ‖x‖ :
begin
refine finset.sum_le_sum (λ b hb, _),
obtain rfl | hb := eq_or_ne b 0,
{ simp },
exact mul_le_mul_of_nonneg_right (hT_norm _ (simple_func.measurable_set_fiber _ _) $
simple_func.measure_preimage_lt_top_of_integrable _ hf hb) (norm_nonneg _),
end
... ≤ C * ∑ x in f.range, (μ (f ⁻¹' {x})).to_real * ‖x‖ : by simp_rw [mul_sum, ← mul_assoc]
lemma set_to_simple_func_indicator (T : set α → F →L[ℝ] F') (hT_empty : T ∅ = 0)
{m : measurable_space α} {s : set α} (hs : measurable_set s) (x : F) :
simple_func.set_to_simple_func T
(simple_func.piecewise s hs (simple_func.const α x) (simple_func.const α 0))
= T s x :=
begin
obtain rfl | hs_empty := s.eq_empty_or_nonempty,
{ simp only [hT_empty, continuous_linear_map.zero_apply, piecewise_empty, const_zero,
set_to_simple_func_zero_apply], },
simp_rw set_to_simple_func,
obtain rfl | hs_univ := eq_or_ne s univ,
{ haveI hα := hs_empty.to_type,
simp },
rw range_indicator hs hs_empty hs_univ,
by_cases hx0 : x = 0,
{ simp_rw hx0, simp, },
rw sum_insert,
swap, { rw finset.mem_singleton, exact hx0, },
rw [sum_singleton, (T _).map_zero, add_zero],
congr,
simp only [coe_piecewise, piecewise_eq_indicator, coe_const, pi.const_zero,
piecewise_eq_indicator],
rw [indicator_preimage, preimage_const_of_mem],
swap, { exact set.mem_singleton x, },
rw [← pi.const_zero, preimage_const_of_not_mem],
swap, { rw set.mem_singleton_iff, exact ne.symm hx0, },
simp,
end
lemma set_to_simple_func_const' [nonempty α] (T : set α → F →L[ℝ] F') (x : F)
{m : measurable_space α} :
simple_func.set_to_simple_func T (simple_func.const α x) = T univ x :=
by simp only [set_to_simple_func, range_const, set.mem_singleton, preimage_const_of_mem,
sum_singleton, coe_const]
lemma set_to_simple_func_const (T : set α → F →L[ℝ] F') (hT_empty : T ∅ = 0) (x : F)
{m : measurable_space α} :
simple_func.set_to_simple_func T (simple_func.const α x) = T univ x :=
begin
casesI hα : is_empty_or_nonempty α,
{ have h_univ_empty : (univ : set α) = ∅, from subsingleton.elim _ _,
rw [h_univ_empty, hT_empty],
simp only [set_to_simple_func, continuous_linear_map.zero_apply, sum_empty,
range_eq_empty_of_is_empty], },
{ exact set_to_simple_func_const' T x, },
end
end simple_func
namespace L1
open ae_eq_fun Lp.simple_func Lp
variables {α E μ}
namespace simple_func
lemma norm_eq_sum_mul (f : α →₁ₛ[μ] G) :
‖f‖ = ∑ x in (to_simple_func f).range, (μ ((to_simple_func f) ⁻¹' {x})).to_real * ‖x‖ :=
begin
rw [norm_to_simple_func, snorm_one_eq_lintegral_nnnorm],
have h_eq := simple_func.map_apply (λ x, (‖x‖₊ : ℝ≥0∞)) (to_simple_func f),
dsimp only at h_eq,
simp_rw ← h_eq,
rw [simple_func.lintegral_eq_lintegral, simple_func.map_lintegral, ennreal.to_real_sum],
{ congr,
ext1 x,
rw [ennreal.to_real_mul, mul_comm, ← of_real_norm_eq_coe_nnnorm,
ennreal.to_real_of_real (norm_nonneg _)], },
{ intros x hx,
by_cases hx0 : x = 0,
{ rw hx0, simp, },
{ exact ennreal.mul_ne_top ennreal.coe_ne_top
(simple_func.measure_preimage_lt_top_of_integrable _ (simple_func.integrable f) hx0).ne } }
end
section set_to_L1s
variables [normed_field 𝕜] [normed_space 𝕜 E]
local attribute [instance] Lp.simple_func.module
local attribute [instance] Lp.simple_func.normed_space
/-- Extend `set α → (E →L[ℝ] F')` to `(α →₁ₛ[μ] E) → F'`. -/
def set_to_L1s (T : set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) : F :=
(to_simple_func f).set_to_simple_func T
lemma set_to_L1s_eq_set_to_simple_func (T : set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) :
set_to_L1s T f = (to_simple_func f).set_to_simple_func T :=
rfl
@[simp] lemma set_to_L1s_zero_left (f : α →₁ₛ[μ] E) :
set_to_L1s (0 : set α → E →L[ℝ] F) f = 0 :=
simple_func.set_to_simple_func_zero _
lemma set_to_L1s_zero_left' {T : set α → E →L[ℝ] F}
(h_zero : ∀ s, measurable_set s → μ s < ∞ → T s = 0) (f : α →₁ₛ[μ] E) :
set_to_L1s T f = 0 :=
simple_func.set_to_simple_func_zero' h_zero _ (simple_func.integrable f)
lemma set_to_L1s_congr (T : set α → E →L[ℝ] F) (h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0)
(h_add : fin_meas_additive μ T)
{f g : α →₁ₛ[μ] E} (h : to_simple_func f =ᵐ[μ] to_simple_func g) :
set_to_L1s T f = set_to_L1s T g :=
simple_func.set_to_simple_func_congr T h_zero h_add (simple_func.integrable f) h
lemma set_to_L1s_congr_left (T T' : set α → E →L[ℝ] F)
(h : ∀ s, measurable_set s → μ s < ∞ → T s = T' s) (f : α →₁ₛ[μ] E) :
set_to_L1s T f = set_to_L1s T' f :=
simple_func.set_to_simple_func_congr_left T T' h (simple_func.to_simple_func f)
(simple_func.integrable f)
/-- `set_to_L1s` does not change if we replace the measure `μ` by `μ'` with `μ ≪ μ'`. The statement
uses two functions `f` and `f'` because they have to belong to different types, but morally these
are the same function (we have `f =ᵐ[μ] f'`). -/
lemma set_to_L1s_congr_measure {μ' : measure α} (T : set α → E →L[ℝ] F)
(h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0) (h_add : fin_meas_additive μ T)
(hμ : μ ≪ μ') (f : α →₁ₛ[μ] E) (f' : α →₁ₛ[μ'] E) (h : f =ᵐ[μ] f') :
set_to_L1s T f = set_to_L1s T f' :=
begin
refine simple_func.set_to_simple_func_congr T h_zero h_add (simple_func.integrable f) _,
refine (to_simple_func_eq_to_fun f).trans _,
suffices : f' =ᵐ[μ] ⇑(simple_func.to_simple_func f'), from h.trans this,
have goal' : f' =ᵐ[μ'] simple_func.to_simple_func f', from (to_simple_func_eq_to_fun f').symm,
exact hμ.ae_eq goal',
end
lemma set_to_L1s_add_left (T T' : set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) :
set_to_L1s (T + T') f = set_to_L1s T f + set_to_L1s T' f :=
simple_func.set_to_simple_func_add_left T T'
lemma set_to_L1s_add_left' (T T' T'' : set α → E →L[ℝ] F)
(h_add : ∀ s, measurable_set s → μ s < ∞ → T'' s = T s + T' s) (f : α →₁ₛ[μ] E) :
set_to_L1s T'' f = set_to_L1s T f + set_to_L1s T' f :=
simple_func.set_to_simple_func_add_left' T T' T'' h_add (simple_func.integrable f)
lemma set_to_L1s_smul_left (T : set α → E →L[ℝ] F) (c : ℝ) (f : α →₁ₛ[μ] E) :
set_to_L1s (λ s, c • (T s)) f = c • set_to_L1s T f :=
simple_func.set_to_simple_func_smul_left T c _
lemma set_to_L1s_smul_left' (T T' : set α → E →L[ℝ] F) (c : ℝ)
(h_smul : ∀ s, measurable_set s → μ s < ∞ → T' s = c • (T s)) (f : α →₁ₛ[μ] E) :
set_to_L1s T' f = c • set_to_L1s T f :=
simple_func.set_to_simple_func_smul_left' T T' c h_smul (simple_func.integrable f)
lemma set_to_L1s_add (T : set α → E →L[ℝ] F) (h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0)
(h_add : fin_meas_additive μ T) (f g : α →₁ₛ[μ] E) :
set_to_L1s T (f + g) = set_to_L1s T f + set_to_L1s T g :=
begin
simp_rw set_to_L1s,
rw ← simple_func.set_to_simple_func_add T h_add
(simple_func.integrable f) (simple_func.integrable g),
exact simple_func.set_to_simple_func_congr T h_zero h_add (simple_func.integrable _)
(add_to_simple_func f g),
end
lemma set_to_L1s_neg {T : set α → E →L[ℝ] F}
(h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0) (h_add : fin_meas_additive μ T)
(f : α →₁ₛ[μ] E) :
set_to_L1s T (-f) = - set_to_L1s T f :=
begin
simp_rw set_to_L1s,
have : simple_func.to_simple_func (-f) =ᵐ[μ] ⇑(-simple_func.to_simple_func f),
from neg_to_simple_func f,
rw simple_func.set_to_simple_func_congr T h_zero h_add (simple_func.integrable _) this,
exact simple_func.set_to_simple_func_neg T h_add (simple_func.integrable f),
end
lemma set_to_L1s_sub {T : set α → E →L[ℝ] F}
(h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0) (h_add : fin_meas_additive μ T)
(f g : α →₁ₛ[μ] E) :
set_to_L1s T (f - g) = set_to_L1s T f - set_to_L1s T g :=
by rw [sub_eq_add_neg, set_to_L1s_add T h_zero h_add, set_to_L1s_neg h_zero h_add, sub_eq_add_neg]
lemma set_to_L1s_smul_real (T : set α → E →L[ℝ] F)
(h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0) (h_add : fin_meas_additive μ T)
(c : ℝ) (f : α →₁ₛ[μ] E) :
set_to_L1s T (c • f) = c • set_to_L1s T f :=
begin
simp_rw set_to_L1s,
rw ← simple_func.set_to_simple_func_smul_real T h_add c (simple_func.integrable f),
refine simple_func.set_to_simple_func_congr T h_zero h_add (simple_func.integrable _) _,
exact smul_to_simple_func c f,
end
lemma set_to_L1s_smul {E} [normed_add_comm_group E] [normed_space ℝ E]
[normed_space 𝕜 E] [normed_space 𝕜 F]
(T : set α → E →L[ℝ] F) (h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0)
(h_add : fin_meas_additive μ T)
(h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜) (f : α →₁ₛ[μ] E) :
set_to_L1s T (c • f) = c • set_to_L1s T f :=
begin
simp_rw set_to_L1s,
rw ← simple_func.set_to_simple_func_smul T h_add h_smul c (simple_func.integrable f),
refine simple_func.set_to_simple_func_congr T h_zero h_add (simple_func.integrable _) _,
exact smul_to_simple_func c f,
end
lemma norm_set_to_L1s_le (T : set α → E →L[ℝ] F) {C : ℝ}
(hT_norm : ∀ s, measurable_set s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).to_real) (f : α →₁ₛ[μ] E) :
‖set_to_L1s T f‖ ≤ C * ‖f‖ :=
begin
rw [set_to_L1s, norm_eq_sum_mul f],
exact simple_func.norm_set_to_simple_func_le_sum_mul_norm_of_integrable T hT_norm _
(simple_func.integrable f),
end
lemma set_to_L1s_indicator_const {T : set α → E →L[ℝ] F} {s : set α}
(h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0) (h_add : fin_meas_additive μ T)
(hs : measurable_set s) (hμs : μ s < ∞) (x : E) :
set_to_L1s T (simple_func.indicator_const 1 hs hμs.ne x) = T s x :=
begin
have h_empty : T ∅ = 0, from h_zero _ measurable_set.empty measure_empty,
rw set_to_L1s_eq_set_to_simple_func,
refine eq.trans _ (simple_func.set_to_simple_func_indicator T h_empty hs x),
refine simple_func.set_to_simple_func_congr T h_zero h_add (simple_func.integrable _) _,
exact to_simple_func_indicator_const hs hμs.ne x,
end
lemma set_to_L1s_const [is_finite_measure μ] {T : set α → E →L[ℝ] F}
(h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0) (h_add : fin_meas_additive μ T) (x : E) :
set_to_L1s T (simple_func.indicator_const 1 measurable_set.univ (measure_ne_top μ _) x)
= T univ x :=
set_to_L1s_indicator_const h_zero h_add measurable_set.univ (measure_lt_top _ _) x
section order
variables {G'' G' : Type*} [normed_lattice_add_comm_group G'] [normed_space ℝ G']
[normed_lattice_add_comm_group G''] [normed_space ℝ G'']
{T : set α → G'' →L[ℝ] G'}
lemma set_to_L1s_mono_left {T T' : set α → E →L[ℝ] G''} (hTT' : ∀ s x, T s x ≤ T' s x)
(f : α →₁ₛ[μ] E) :
set_to_L1s T f ≤ set_to_L1s T' f :=
simple_func.set_to_simple_func_mono_left T T' hTT' _
lemma set_to_L1s_mono_left' {T T' : set α → E →L[ℝ] G''}
(hTT' : ∀ s, measurable_set s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →₁ₛ[μ] E) :
set_to_L1s T f ≤ set_to_L1s T' f :=
simple_func.set_to_simple_func_mono_left' T T' hTT' _ (simple_func.integrable f)
lemma set_to_L1s_nonneg (h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0)
(h_add : fin_meas_additive μ T)
(hT_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x)
{f : α →₁ₛ[μ] G''} (hf : 0 ≤ f) :
0 ≤ set_to_L1s T f :=
begin
simp_rw set_to_L1s,
obtain ⟨f', hf', hff'⟩ : ∃ f' : α →ₛ G'', 0 ≤ f' ∧ simple_func.to_simple_func f =ᵐ[μ] f',
{ obtain ⟨f'', hf'', hff''⟩ := exists_simple_func_nonneg_ae_eq hf,
exact ⟨f'', hf'', (Lp.simple_func.to_simple_func_eq_to_fun f).trans hff''⟩, },
rw simple_func.set_to_simple_func_congr _ h_zero h_add (simple_func.integrable _) hff',
exact simple_func.set_to_simple_func_nonneg' T hT_nonneg _ hf'
((simple_func.integrable f).congr hff'),
end
lemma set_to_L1s_mono (h_zero : ∀ s, measurable_set s → μ s = 0 → T s = 0)
(h_add : fin_meas_additive μ T)
(hT_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x)
{f g : α →₁ₛ[μ] G''} (hfg : f ≤ g) :
set_to_L1s T f ≤ set_to_L1s T g :=
begin
rw ← sub_nonneg at ⊢ hfg,
rw ← set_to_L1s_sub h_zero h_add,
exact set_to_L1s_nonneg h_zero h_add hT_nonneg hfg,
end
end order
variables [normed_space 𝕜 F]
variables (α E μ 𝕜)
/-- Extend `set α → E →L[ℝ] F` to `(α →₁ₛ[μ] E) →L[𝕜] F`. -/
def set_to_L1s_clm' {T : set α → E →L[ℝ] F} {C : ℝ} (hT : dominated_fin_meas_additive μ T C)
(h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) :
(α →₁ₛ[μ] E) →L[𝕜] F :=
linear_map.mk_continuous ⟨set_to_L1s T, set_to_L1s_add T (λ _, hT.eq_zero_of_measure_zero) hT.1,
set_to_L1s_smul T (λ _, hT.eq_zero_of_measure_zero) hT.1 h_smul⟩ C
(λ f, norm_set_to_L1s_le T hT.2 f)
/-- Extend `set α → E →L[ℝ] F` to `(α →₁ₛ[μ] E) →L[ℝ] F`. -/
def set_to_L1s_clm {T : set α → E →L[ℝ] F} {C : ℝ} (hT : dominated_fin_meas_additive μ T C) :
(α →₁ₛ[μ] E) →L[ℝ] F :=
linear_map.mk_continuous ⟨set_to_L1s T, set_to_L1s_add T (λ _, hT.eq_zero_of_measure_zero) hT.1,
set_to_L1s_smul_real T (λ _, hT.eq_zero_of_measure_zero) hT.1⟩ C
(λ f, norm_set_to_L1s_le T hT.2 f)
variables {α E μ 𝕜}
variables {T T' T'' : set α → E →L[ℝ] F} {C C' C'' : ℝ}
@[simp] lemma set_to_L1s_clm_zero_left
(hT : dominated_fin_meas_additive μ (0 : set α → E →L[ℝ] F) C) (f : α →₁ₛ[μ] E) :
set_to_L1s_clm α E μ hT f = 0 :=
set_to_L1s_zero_left _
lemma set_to_L1s_clm_zero_left' (hT : dominated_fin_meas_additive μ T C)
(h_zero : ∀ s, measurable_set s → μ s < ∞ → T s = 0) (f : α →₁ₛ[μ] E) :
set_to_L1s_clm α E μ hT f = 0 :=
set_to_L1s_zero_left' h_zero f
lemma set_to_L1s_clm_congr_left (hT : dominated_fin_meas_additive μ T C)
(hT' : dominated_fin_meas_additive μ T' C') (h : T = T') (f : α →₁ₛ[μ] E) :
set_to_L1s_clm α E μ hT f = set_to_L1s_clm α E μ hT' f :=
set_to_L1s_congr_left T T' (λ _ _ _, by rw h) f
lemma set_to_L1s_clm_congr_left' (hT : dominated_fin_meas_additive μ T C)
(hT' : dominated_fin_meas_additive μ T' C')
(h : ∀ s, measurable_set s → μ s < ∞ → T s = T' s) (f : α →₁ₛ[μ] E) :
set_to_L1s_clm α E μ hT f = set_to_L1s_clm α E μ hT' f :=
set_to_L1s_congr_left T T' h f
lemma set_to_L1s_clm_congr_measure {μ' : measure α}
(hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ' T C')
(hμ : μ ≪ μ') (f : α →₁ₛ[μ] E) (f' : α →₁ₛ[μ'] E) (h : f =ᵐ[μ] f') :
set_to_L1s_clm α E μ hT f = set_to_L1s_clm α E μ' hT' f' :=
set_to_L1s_congr_measure T (λ s, hT.eq_zero_of_measure_zero) hT.1 hμ _ _ h
lemma set_to_L1s_clm_add_left (hT : dominated_fin_meas_additive μ T C)
(hT' : dominated_fin_meas_additive μ T' C') (f : α →₁ₛ[μ] E) :
set_to_L1s_clm α E μ (hT.add hT') f = set_to_L1s_clm α E μ hT f + set_to_L1s_clm α E μ hT' f :=
set_to_L1s_add_left T T' f
lemma set_to_L1s_clm_add_left' (hT : dominated_fin_meas_additive μ T C)
(hT' : dominated_fin_meas_additive μ T' C') (hT'' : dominated_fin_meas_additive μ T'' C'')
(h_add : ∀ s, measurable_set s → μ s < ∞ → T'' s = T s + T' s) (f : α →₁ₛ[μ] E) :
set_to_L1s_clm α E μ hT'' f = set_to_L1s_clm α E μ hT f + set_to_L1s_clm α E μ hT' f :=
set_to_L1s_add_left' T T' T'' h_add f
lemma set_to_L1s_clm_smul_left (c : ℝ) (hT : dominated_fin_meas_additive μ T C) (f : α →₁ₛ[μ] E) :
set_to_L1s_clm α E μ (hT.smul c) f = c • set_to_L1s_clm α E μ hT f :=
set_to_L1s_smul_left T c f
lemma set_to_L1s_clm_smul_left' (c : ℝ)
(hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C')
(h_smul : ∀ s, measurable_set s → μ s < ∞ → T' s = c • (T s)) (f : α →₁ₛ[μ] E) :
set_to_L1s_clm α E μ hT' f = c • set_to_L1s_clm α E μ hT f :=
set_to_L1s_smul_left' T T' c h_smul f
lemma norm_set_to_L1s_clm_le {T : set α → E →L[ℝ] F} {C : ℝ}
(hT : dominated_fin_meas_additive μ T C) (hC : 0 ≤ C) :
‖set_to_L1s_clm α E μ hT‖ ≤ C :=
linear_map.mk_continuous_norm_le _ hC _
lemma norm_set_to_L1s_clm_le' {T : set α → E →L[ℝ] F} {C : ℝ}
(hT : dominated_fin_meas_additive μ T C) :
‖set_to_L1s_clm α E μ hT‖ ≤ max C 0 :=
linear_map.mk_continuous_norm_le' _ _
lemma set_to_L1s_clm_const [is_finite_measure μ] {T : set α → E →L[ℝ] F} {C : ℝ}
(hT : dominated_fin_meas_additive μ T C) (x : E) :
set_to_L1s_clm α E μ hT (simple_func.indicator_const 1 measurable_set.univ (measure_ne_top μ _) x)
= T univ x :=
set_to_L1s_const (λ s, hT.eq_zero_of_measure_zero) hT.1 x
section order
variables {G' G'' : Type*} [normed_lattice_add_comm_group G''] [normed_space ℝ G'']
[normed_lattice_add_comm_group G'] [normed_space ℝ G']
lemma set_to_L1s_clm_mono_left {T T' : set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C')
(hTT' : ∀ s x, T s x ≤ T' s x) (f : α →₁ₛ[μ] E) :
set_to_L1s_clm α E μ hT f ≤ set_to_L1s_clm α E μ hT' f :=
simple_func.set_to_simple_func_mono_left T T' hTT' _
lemma set_to_L1s_clm_mono_left' {T T' : set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C')
(hTT' : ∀ s, measurable_set s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →₁ₛ[μ] E) :
set_to_L1s_clm α E μ hT f ≤ set_to_L1s_clm α E μ hT' f :=
simple_func.set_to_simple_func_mono_left' T T' hTT' _ (simple_func.integrable f)
lemma set_to_L1s_clm_nonneg {T : set α → G' →L[ℝ] G''} {C : ℝ}
(hT : dominated_fin_meas_additive μ T C)
(hT_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x)
{f : α →₁ₛ[μ] G'} (hf : 0 ≤ f) :
0 ≤ set_to_L1s_clm α G' μ hT f :=
set_to_L1s_nonneg (λ s, hT.eq_zero_of_measure_zero) hT.1 hT_nonneg hf
lemma set_to_L1s_clm_mono {T : set α → G' →L[ℝ] G''} {C : ℝ}
(hT : dominated_fin_meas_additive μ T C)
(hT_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x)
{f g : α →₁ₛ[μ] G'} (hfg : f ≤ g) :
set_to_L1s_clm α G' μ hT f ≤ set_to_L1s_clm α G' μ hT g :=
set_to_L1s_mono (λ s, hT.eq_zero_of_measure_zero) hT.1 hT_nonneg hfg
end order
end set_to_L1s
end simple_func
open simple_func
section set_to_L1
local attribute [instance] Lp.simple_func.module
local attribute [instance] Lp.simple_func.normed_space
variables (𝕜) [nontrivially_normed_field 𝕜] [normed_space 𝕜 E]
[normed_space 𝕜 F] [complete_space F]
{T T' T'' : set α → E →L[ℝ] F} {C C' C'' : ℝ}
/-- Extend `set α → (E →L[ℝ] F)` to `(α →₁[μ] E) →L[𝕜] F`. -/
def set_to_L1' (hT : dominated_fin_meas_additive μ T C)
(h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) :
(α →₁[μ] E) →L[𝕜] F :=
(set_to_L1s_clm' α E 𝕜 μ hT h_smul).extend
(coe_to_Lp α E 𝕜) (simple_func.dense_range one_ne_top) simple_func.uniform_inducing
variables {𝕜}
/-- Extend `set α → E →L[ℝ] F` to `(α →₁[μ] E) →L[ℝ] F`. -/
def set_to_L1 (hT : dominated_fin_meas_additive μ T C) : (α →₁[μ] E) →L[ℝ] F :=
(set_to_L1s_clm α E μ hT).extend
(coe_to_Lp α E ℝ) (simple_func.dense_range one_ne_top) simple_func.uniform_inducing
lemma set_to_L1_eq_set_to_L1s_clm (hT : dominated_fin_meas_additive μ T C) (f : α →₁ₛ[μ] E) :
set_to_L1 hT f = set_to_L1s_clm α E μ hT f :=
uniformly_extend_of_ind simple_func.uniform_inducing (simple_func.dense_range one_ne_top)
(set_to_L1s_clm α E μ hT).uniform_continuous _
lemma set_to_L1_eq_set_to_L1' (hT : dominated_fin_meas_additive μ T C)
(h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (f : α →₁[μ] E) :
set_to_L1 hT f = set_to_L1' 𝕜 hT h_smul f :=
rfl
@[simp] lemma set_to_L1_zero_left
(hT : dominated_fin_meas_additive μ (0 : set α → E →L[ℝ] F) C) (f : α →₁[μ] E) :
set_to_L1 hT f = 0 :=
begin
suffices : set_to_L1 hT = 0, by { rw this, simp, },
refine continuous_linear_map.extend_unique (set_to_L1s_clm α E μ hT) _ _ _ _ _,
ext1 f,
rw [set_to_L1s_clm_zero_left hT f, continuous_linear_map.zero_comp,
continuous_linear_map.zero_apply],
end
lemma set_to_L1_zero_left' (hT : dominated_fin_meas_additive μ T C)
(h_zero : ∀ s, measurable_set s → μ s < ∞ → T s = 0) (f : α →₁[μ] E) :
set_to_L1 hT f = 0 :=
begin
suffices : set_to_L1 hT = 0, by { rw this, simp, },
refine continuous_linear_map.extend_unique (set_to_L1s_clm α E μ hT) _ _ _ _ _,
ext1 f,
rw [set_to_L1s_clm_zero_left' hT h_zero f, continuous_linear_map.zero_comp,
continuous_linear_map.zero_apply],
end
lemma set_to_L1_congr_left (T T' : set α → E →L[ℝ] F) {C C' : ℝ}
(hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C')
(h : T = T') (f : α →₁[μ] E) :
set_to_L1 hT f = set_to_L1 hT' f :=
begin
suffices : set_to_L1 hT = set_to_L1 hT', by rw this,
refine continuous_linear_map.extend_unique (set_to_L1s_clm α E μ hT) _ _ _ _ _,
ext1 f,
suffices : set_to_L1 hT' f = set_to_L1s_clm α E μ hT f,
by { rw ← this, congr' 1, },
rw set_to_L1_eq_set_to_L1s_clm,
exact set_to_L1s_clm_congr_left hT' hT h.symm f,
end
lemma set_to_L1_congr_left' (T T' : set α → E →L[ℝ] F) {C C' : ℝ}
(hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C')
(h : ∀ s, measurable_set s → μ s < ∞ → T s = T' s) (f : α →₁[μ] E) :
set_to_L1 hT f = set_to_L1 hT' f :=
begin
suffices : set_to_L1 hT = set_to_L1 hT', by rw this,
refine continuous_linear_map.extend_unique (set_to_L1s_clm α E μ hT) _ _ _ _ _,
ext1 f,
suffices : set_to_L1 hT' f = set_to_L1s_clm α E μ hT f,
by { rw ← this, congr' 1, },
rw set_to_L1_eq_set_to_L1s_clm,
exact (set_to_L1s_clm_congr_left' hT hT' h f).symm,
end
lemma set_to_L1_add_left (hT : dominated_fin_meas_additive μ T C)
(hT' : dominated_fin_meas_additive μ T' C') (f : α →₁[μ] E) :
set_to_L1 (hT.add hT') f = set_to_L1 hT f + set_to_L1 hT' f :=
begin
suffices : set_to_L1 (hT.add hT') = set_to_L1 hT + set_to_L1 hT',
by { rw [this, continuous_linear_map.add_apply], },
refine continuous_linear_map.extend_unique (set_to_L1s_clm α E μ (hT.add hT')) _ _ _ _ _,
ext1 f,
simp only [continuous_linear_map.add_comp, continuous_linear_map.coe_comp', function.comp_app,
continuous_linear_map.add_apply],
suffices : set_to_L1 hT f + set_to_L1 hT' f = set_to_L1s_clm α E μ (hT.add hT') f,
by { rw ← this, congr, },
rw [set_to_L1_eq_set_to_L1s_clm, set_to_L1_eq_set_to_L1s_clm, set_to_L1s_clm_add_left hT hT'],
end
lemma set_to_L1_add_left' (hT : dominated_fin_meas_additive μ T C)
(hT' : dominated_fin_meas_additive μ T' C') (hT'' : dominated_fin_meas_additive μ T'' C'')
(h_add : ∀ s, measurable_set s → μ s < ∞ → T'' s = T s + T' s) (f : α →₁[μ] E) :
set_to_L1 hT'' f = set_to_L1 hT f + set_to_L1 hT' f :=
begin
suffices : set_to_L1 hT'' = set_to_L1 hT + set_to_L1 hT',
by { rw [this, continuous_linear_map.add_apply], },
refine continuous_linear_map.extend_unique (set_to_L1s_clm α E μ hT'') _ _ _ _ _,
ext1 f,
simp only [continuous_linear_map.add_comp, continuous_linear_map.coe_comp', function.comp_app,
continuous_linear_map.add_apply],
suffices : set_to_L1 hT f + set_to_L1 hT' f = set_to_L1s_clm α E μ hT'' f,
by { rw ← this, congr, },
rw [set_to_L1_eq_set_to_L1s_clm, set_to_L1_eq_set_to_L1s_clm,
set_to_L1s_clm_add_left' hT hT' hT'' h_add],
end
lemma set_to_L1_smul_left (hT : dominated_fin_meas_additive μ T C) (c : ℝ) (f : α →₁[μ] E) :
set_to_L1 (hT.smul c) f = c • set_to_L1 hT f :=
begin
suffices : set_to_L1 (hT.smul c) = c • set_to_L1 hT,
by { rw [this, continuous_linear_map.smul_apply], },
refine continuous_linear_map.extend_unique (set_to_L1s_clm α E μ (hT.smul c)) _ _ _ _ _,
ext1 f,
simp only [continuous_linear_map.coe_comp', function.comp_app, continuous_linear_map.smul_comp,
pi.smul_apply, continuous_linear_map.coe_smul'],
suffices : c • set_to_L1 hT f = set_to_L1s_clm α E μ (hT.smul c) f, by { rw ← this, congr, },
rw [set_to_L1_eq_set_to_L1s_clm, set_to_L1s_clm_smul_left c hT],
end
lemma set_to_L1_smul_left' (hT : dominated_fin_meas_additive μ T C)
(hT' : dominated_fin_meas_additive μ T' C') (c : ℝ)
(h_smul : ∀ s, measurable_set s → μ s < ∞ → T' s = c • (T s)) (f : α →₁[μ] E) :
set_to_L1 hT' f = c • set_to_L1 hT f :=
begin
suffices : set_to_L1 hT' = c • set_to_L1 hT,
by { rw [this, continuous_linear_map.smul_apply], },
refine continuous_linear_map.extend_unique (set_to_L1s_clm α E μ hT') _ _ _ _ _,
ext1 f,
simp only [continuous_linear_map.coe_comp', function.comp_app, continuous_linear_map.smul_comp,
pi.smul_apply, continuous_linear_map.coe_smul'],
suffices : c • set_to_L1 hT f = set_to_L1s_clm α E μ hT' f, by { rw ← this, congr, },
rw [set_to_L1_eq_set_to_L1s_clm, set_to_L1s_clm_smul_left' c hT hT' h_smul],
end
lemma set_to_L1_smul (hT : dominated_fin_meas_additive μ T C)
(h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜) (f : α →₁[μ] E) :
set_to_L1 hT (c • f) = c • set_to_L1 hT f :=
begin
rw [set_to_L1_eq_set_to_L1' hT h_smul, set_to_L1_eq_set_to_L1' hT h_smul],
exact continuous_linear_map.map_smul _ _ _,
end
lemma set_to_L1_simple_func_indicator_const (hT : dominated_fin_meas_additive μ T C) {s : set α}
(hs : measurable_set s) (hμs : μ s < ∞) (x : E) :
set_to_L1 hT (simple_func.indicator_const 1 hs hμs.ne x) = T s x :=
begin
rw set_to_L1_eq_set_to_L1s_clm,
exact set_to_L1s_indicator_const (λ s, hT.eq_zero_of_measure_zero) hT.1 hs hμs x,
end
lemma set_to_L1_indicator_const_Lp (hT : dominated_fin_meas_additive μ T C) {s : set α}
(hs : measurable_set s) (hμs : μ s ≠ ∞) (x : E) :
set_to_L1 hT (indicator_const_Lp 1 hs hμs x) = T s x :=
begin
rw ← Lp.simple_func.coe_indicator_const hs hμs x,
exact set_to_L1_simple_func_indicator_const hT hs hμs.lt_top x,
end
lemma set_to_L1_const [is_finite_measure μ] (hT : dominated_fin_meas_additive μ T C) (x : E) :
set_to_L1 hT (indicator_const_Lp 1 measurable_set.univ (measure_ne_top _ _) x) = T univ x :=
set_to_L1_indicator_const_Lp hT measurable_set.univ (measure_ne_top _ _) x
section order
variables {G' G'' : Type*} [normed_lattice_add_comm_group G''] [normed_space ℝ G'']
[complete_space G'']
[normed_lattice_add_comm_group G'] [normed_space ℝ G']
lemma set_to_L1_mono_left' {T T' : set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C')
(hTT' : ∀ s, measurable_set s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →₁[μ] E) :
set_to_L1 hT f ≤ set_to_L1 hT' f :=
begin
refine Lp.induction one_ne_top _ _ _ _ f,
{ intros c s hs hμs,
rw [set_to_L1_simple_func_indicator_const hT hs hμs,
set_to_L1_simple_func_indicator_const hT' hs hμs],
exact hTT' s hs hμs c, },
{ intros f g hf hg hfg_disj hf_le hg_le,
rw [(set_to_L1 hT).map_add, (set_to_L1 hT').map_add],
exact add_le_add hf_le hg_le, },
{ exact is_closed_le (set_to_L1 hT).continuous (set_to_L1 hT').continuous, },
end
lemma set_to_L1_mono_left {T T' : set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C')
(hTT' : ∀ s x, T s x ≤ T' s x) (f : α →₁[μ] E) :
set_to_L1 hT f ≤ set_to_L1 hT' f :=
set_to_L1_mono_left' hT hT' (λ s _ _ x, hTT' s x) f
lemma set_to_L1_nonneg {T : set α → G' →L[ℝ] G''} {C : ℝ} (hT : dominated_fin_meas_additive μ T C)
(hT_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x)
{f : α →₁[μ] G'} (hf : 0 ≤ f) :
0 ≤ set_to_L1 hT f :=
begin
suffices : ∀ f : {g : α →₁[μ] G' // 0 ≤ g}, 0 ≤ set_to_L1 hT f,
from this (⟨f, hf⟩ : {g : α →₁[μ] G' // 0 ≤ g}),
refine λ g, @is_closed_property {g : α →₁ₛ[μ] G' // 0 ≤ g} {g : α →₁[μ] G' // 0 ≤ g} _ _ _
(dense_range_coe_simple_func_nonneg_to_Lp_nonneg 1 μ G' one_ne_top) _ _ g,
{ exact is_closed_le continuous_zero ((set_to_L1 hT).continuous.comp continuous_induced_dom), },
{ intros g,
have : (coe_simple_func_nonneg_to_Lp_nonneg 1 μ G' g : α →₁[μ] G') = (g : α →₁ₛ[μ] G') := rfl,
rw [this, set_to_L1_eq_set_to_L1s_clm],
exact set_to_L1s_nonneg (λ s, hT.eq_zero_of_measure_zero) hT.1 hT_nonneg g.2, },
end
lemma set_to_L1_mono {T : set α → G' →L[ℝ] G''} {C : ℝ} (hT : dominated_fin_meas_additive μ T C)
(hT_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x)
{f g : α →₁[μ] G'} (hfg : f ≤ g) :
set_to_L1 hT f ≤ set_to_L1 hT g :=
begin
rw ← sub_nonneg at hfg ⊢,
rw ← (set_to_L1 hT).map_sub,
exact set_to_L1_nonneg hT hT_nonneg hfg,
end
end order
lemma norm_set_to_L1_le_norm_set_to_L1s_clm (hT : dominated_fin_meas_additive μ T C) :
‖set_to_L1 hT‖ ≤ ‖set_to_L1s_clm α E μ hT‖ :=
calc ‖set_to_L1 hT‖
≤ (1 : ℝ≥0) * ‖set_to_L1s_clm α E μ hT‖ : begin
refine continuous_linear_map.op_norm_extend_le (set_to_L1s_clm α E μ hT) (coe_to_Lp α E ℝ)
(simple_func.dense_range one_ne_top) (λ x, le_of_eq _),
rw [nnreal.coe_one, one_mul],
refl,
end
... = ‖set_to_L1s_clm α E μ hT‖ : by rw [nnreal.coe_one, one_mul]
lemma norm_set_to_L1_le_mul_norm (hT : dominated_fin_meas_additive μ T C) (hC : 0 ≤ C)
(f : α →₁[μ] E) :
‖set_to_L1 hT f‖ ≤ C * ‖f‖ :=
calc ‖set_to_L1 hT f‖
≤ ‖set_to_L1s_clm α E μ hT‖ * ‖f‖ :
continuous_linear_map.le_of_op_norm_le _ (norm_set_to_L1_le_norm_set_to_L1s_clm hT) _
... ≤ C * ‖f‖ : mul_le_mul (norm_set_to_L1s_clm_le hT hC) le_rfl (norm_nonneg _) hC
lemma norm_set_to_L1_le_mul_norm' (hT : dominated_fin_meas_additive μ T C) (f : α →₁[μ] E) :
‖set_to_L1 hT f‖ ≤ max C 0 * ‖f‖ :=
calc ‖set_to_L1 hT f‖
≤ ‖set_to_L1s_clm α E μ hT‖ * ‖f‖ :
continuous_linear_map.le_of_op_norm_le _ (norm_set_to_L1_le_norm_set_to_L1s_clm hT) _
... ≤ max C 0 * ‖f‖ :
mul_le_mul (norm_set_to_L1s_clm_le' hT) le_rfl (norm_nonneg _) (le_max_right _ _)
lemma norm_set_to_L1_le (hT : dominated_fin_meas_additive μ T C) (hC : 0 ≤ C) :
‖set_to_L1 hT‖ ≤ C :=
continuous_linear_map.op_norm_le_bound _ hC (norm_set_to_L1_le_mul_norm hT hC)
lemma norm_set_to_L1_le' (hT : dominated_fin_meas_additive μ T C) :
‖set_to_L1 hT‖ ≤ max C 0 :=
continuous_linear_map.op_norm_le_bound _ (le_max_right _ _) (norm_set_to_L1_le_mul_norm' hT)
lemma set_to_L1_lipschitz (hT : dominated_fin_meas_additive μ T C) :
lipschitz_with (real.to_nnreal C) (set_to_L1 hT) :=
(set_to_L1 hT).lipschitz.weaken (norm_set_to_L1_le' hT)
/-- If `fs i → f` in `L1`, then `set_to_L1 hT (fs i) → set_to_L1 hT f`. -/
lemma tendsto_set_to_L1 (hT : dominated_fin_meas_additive μ T C) (f : α →₁[μ] E)
{ι} (fs : ι → α →₁[μ] E) {l : filter ι} (hfs : tendsto fs l (𝓝 f)) :
tendsto (λ i, set_to_L1 hT (fs i)) l (𝓝 $ set_to_L1 hT f) :=
((set_to_L1 hT).continuous.tendsto _).comp hfs
end set_to_L1
end L1
section function
variables [complete_space F]
{T T' T'': set α → E →L[ℝ] F} {C C' C'' : ℝ} {f g : α → E}
variables (μ T)
/-- Extend `T : set α → E →L[ℝ] F` to `(α → E) → F` (for integrable functions `α → E`). We set it to
0 if the function is not integrable. -/
def set_to_fun (hT : dominated_fin_meas_additive μ T C) (f : α → E) : F :=
if hf : integrable f μ then L1.set_to_L1 hT (hf.to_L1 f) else 0
variables {μ T}
lemma set_to_fun_eq (hT : dominated_fin_meas_additive μ T C) (hf : integrable f μ) :
set_to_fun μ T hT f = L1.set_to_L1 hT (hf.to_L1 f) :=
dif_pos hf
lemma L1.set_to_fun_eq_set_to_L1 (hT : dominated_fin_meas_additive μ T C) (f : α →₁[μ] E) :
set_to_fun μ T hT f = L1.set_to_L1 hT f :=
by rw [set_to_fun_eq hT (L1.integrable_coe_fn f), integrable.to_L1_coe_fn]
lemma set_to_fun_undef (hT : dominated_fin_meas_additive μ T C) (hf : ¬ integrable f μ) :
set_to_fun μ T hT f = 0 :=
dif_neg hf
lemma set_to_fun_non_ae_strongly_measurable (hT : dominated_fin_meas_additive μ T C)
(hf : ¬ ae_strongly_measurable f μ) :
set_to_fun μ T hT f = 0 :=
set_to_fun_undef hT (not_and_of_not_left _ hf)
lemma set_to_fun_congr_left (hT : dominated_fin_meas_additive μ T C)
(hT' : dominated_fin_meas_additive μ T' C') (h : T = T') (f : α → E) :
set_to_fun μ T hT f = set_to_fun μ T' hT' f :=
begin
by_cases hf : integrable f μ,
{ simp_rw [set_to_fun_eq _ hf, L1.set_to_L1_congr_left T T' hT hT' h], },
{ simp_rw [set_to_fun_undef _ hf], },
end
lemma set_to_fun_congr_left'
(hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C')
(h : ∀ s, measurable_set s → μ s < ∞ → T s = T' s) (f : α → E) :
set_to_fun μ T hT f = set_to_fun μ T' hT' f :=
begin
by_cases hf : integrable f μ,
{ simp_rw [set_to_fun_eq _ hf, L1.set_to_L1_congr_left' T T' hT hT' h], },
{ simp_rw [set_to_fun_undef _ hf], },
end
lemma set_to_fun_add_left (hT : dominated_fin_meas_additive μ T C)
(hT' : dominated_fin_meas_additive μ T' C') (f : α → E) :
set_to_fun μ (T + T') (hT.add hT') f = set_to_fun μ T hT f + set_to_fun μ T' hT' f :=
begin
by_cases hf : integrable f μ,
{ simp_rw [set_to_fun_eq _ hf, L1.set_to_L1_add_left hT hT'], },
{ simp_rw [set_to_fun_undef _ hf, add_zero], },
end
lemma set_to_fun_add_left' (hT : dominated_fin_meas_additive μ T C)
(hT' : dominated_fin_meas_additive μ T' C') (hT'' : dominated_fin_meas_additive μ T'' C'')
(h_add : ∀ s, measurable_set s → μ s < ∞ → T'' s = T s + T' s) (f : α → E) :
set_to_fun μ T'' hT'' f = set_to_fun μ T hT f + set_to_fun μ T' hT' f :=
begin
by_cases hf : integrable f μ,
{ simp_rw [set_to_fun_eq _ hf, L1.set_to_L1_add_left' hT hT' hT'' h_add], },
{ simp_rw [set_to_fun_undef _ hf, add_zero], },
end
lemma set_to_fun_smul_left (hT : dominated_fin_meas_additive μ T C) (c : ℝ) (f : α → E) :
set_to_fun μ (λ s, c • (T s)) (hT.smul c) f = c • set_to_fun μ T hT f :=
begin
by_cases hf : integrable f μ,
{ simp_rw [set_to_fun_eq _ hf, L1.set_to_L1_smul_left hT c], },
{ simp_rw [set_to_fun_undef _ hf, smul_zero], },
end
lemma set_to_fun_smul_left' (hT : dominated_fin_meas_additive μ T C)
(hT' : dominated_fin_meas_additive μ T' C') (c : ℝ)
(h_smul : ∀ s, measurable_set s → μ s < ∞ → T' s = c • (T s)) (f : α → E) :
set_to_fun μ T' hT' f = c • set_to_fun μ T hT f :=
begin
by_cases hf : integrable f μ,
{ simp_rw [set_to_fun_eq _ hf, L1.set_to_L1_smul_left' hT hT' c h_smul], },
{ simp_rw [set_to_fun_undef _ hf, smul_zero], },
end
@[simp] lemma set_to_fun_zero (hT : dominated_fin_meas_additive μ T C) :
set_to_fun μ T hT (0 : α → E) = 0 :=
begin
rw set_to_fun_eq hT,
{ simp only [integrable.to_L1_zero, continuous_linear_map.map_zero], },
{ exact integrable_zero _ _ _, },
end
@[simp] lemma set_to_fun_zero_left {hT : dominated_fin_meas_additive μ (0 : set α → E →L[ℝ] F) C} :
set_to_fun μ 0 hT f = 0 :=
begin
by_cases hf : integrable f μ,
{ rw set_to_fun_eq hT hf, exact L1.set_to_L1_zero_left hT _, },
{ exact set_to_fun_undef hT hf, },
end
lemma set_to_fun_zero_left' (hT : dominated_fin_meas_additive μ T C)
(h_zero : ∀ s, measurable_set s → μ s < ∞ → T s = 0) :
set_to_fun μ T hT f = 0 :=
begin
by_cases hf : integrable f μ,
{ rw set_to_fun_eq hT hf, exact L1.set_to_L1_zero_left' hT h_zero _, },
{ exact set_to_fun_undef hT hf, },
end
lemma set_to_fun_add (hT : dominated_fin_meas_additive μ T C)
(hf : integrable f μ) (hg : integrable g μ) :
set_to_fun μ T hT (f + g) = set_to_fun μ T hT f + set_to_fun μ T hT g :=
by rw [set_to_fun_eq hT (hf.add hg), set_to_fun_eq hT hf, set_to_fun_eq hT hg, integrable.to_L1_add,
(L1.set_to_L1 hT).map_add]
lemma set_to_fun_finset_sum' (hT : dominated_fin_meas_additive μ T C) {ι} (s : finset ι)
{f : ι → α → E} (hf : ∀ i ∈ s, integrable (f i) μ) :
set_to_fun μ T hT (∑ i in s, f i) = ∑ i in s, set_to_fun μ T hT (f i) :=
begin
revert hf,
refine finset.induction_on s _ _,
{ intro h,
simp only [set_to_fun_zero, finset.sum_empty] },
{ assume i s his ih hf,
simp only [his, finset.sum_insert, not_false_iff],
rw set_to_fun_add hT (hf i (finset.mem_insert_self i s)) _,
{ rw ih (λ i hi, hf i (finset.mem_insert_of_mem hi)), },
{ convert (integrable_finset_sum s (λ i hi, hf i (finset.mem_insert_of_mem hi))),
ext1 x,
simp, }, }
end
lemma set_to_fun_finset_sum (hT : dominated_fin_meas_additive μ T C) {ι} (s : finset ι)
{f : ι → α → E} (hf : ∀ i ∈ s, integrable (f i) μ) :
set_to_fun μ T hT (λ a, ∑ i in s, f i a) = ∑ i in s, set_to_fun μ T hT (f i) :=
by { convert set_to_fun_finset_sum' hT s hf, ext1 a, simp, }
lemma set_to_fun_neg (hT : dominated_fin_meas_additive μ T C) (f : α → E) :
set_to_fun μ T hT (-f) = - set_to_fun μ T hT f :=
begin
by_cases hf : integrable f μ,
{ rw [set_to_fun_eq hT hf, set_to_fun_eq hT hf.neg,
integrable.to_L1_neg, (L1.set_to_L1 hT).map_neg], },
{ rw [set_to_fun_undef hT hf, set_to_fun_undef hT, neg_zero],
rwa [← integrable_neg_iff] at hf, }
end
lemma set_to_fun_sub (hT : dominated_fin_meas_additive μ T C)
(hf : integrable f μ) (hg : integrable g μ) :
set_to_fun μ T hT (f - g) = set_to_fun μ T hT f - set_to_fun μ T hT g :=
by rw [sub_eq_add_neg, sub_eq_add_neg, set_to_fun_add hT hf hg.neg, set_to_fun_neg hT g]
lemma set_to_fun_smul [nontrivially_normed_field 𝕜]
[normed_space 𝕜 E] [normed_space 𝕜 F] (hT : dominated_fin_meas_additive μ T C)
(h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜) (f : α → E) :
set_to_fun μ T hT (c • f) = c • set_to_fun μ T hT f :=
begin
by_cases hf : integrable f μ,
{ rw [set_to_fun_eq hT hf, set_to_fun_eq hT, integrable.to_L1_smul',
L1.set_to_L1_smul hT h_smul c _], },
{ by_cases hr : c = 0,
{ rw hr, simp, },
{ have hf' : ¬ integrable (c • f) μ, by rwa [integrable_smul_iff hr f],
rw [set_to_fun_undef hT hf, set_to_fun_undef hT hf',
smul_zero], }, },
end
lemma set_to_fun_congr_ae (hT : dominated_fin_meas_additive μ T C) (h : f =ᵐ[μ] g) :
set_to_fun μ T hT f = set_to_fun μ T hT g :=
begin
by_cases hfi : integrable f μ,
{ have hgi : integrable g μ := hfi.congr h,
rw [set_to_fun_eq hT hfi, set_to_fun_eq hT hgi,
(integrable.to_L1_eq_to_L1_iff f g hfi hgi).2 h] },
{ have hgi : ¬ integrable g μ, { rw integrable_congr h at hfi, exact hfi },
rw [set_to_fun_undef hT hfi, set_to_fun_undef hT hgi] },
end
lemma set_to_fun_measure_zero (hT : dominated_fin_meas_additive μ T C) (h : μ = 0) :
set_to_fun μ T hT f = 0 :=
by { have : f =ᵐ[μ] 0, by simp [h], rw [set_to_fun_congr_ae hT this, set_to_fun_zero], }
lemma set_to_fun_measure_zero' (hT : dominated_fin_meas_additive μ T C)
(h : ∀ s, measurable_set s → μ s < ∞ → μ s = 0) :
set_to_fun μ T hT f = 0 :=
set_to_fun_zero_left' hT (λ s hs hμs, hT.eq_zero_of_measure_zero hs (h s hs hμs))
lemma set_to_fun_to_L1 (hT : dominated_fin_meas_additive μ T C) (hf : integrable f μ) :
set_to_fun μ T hT (hf.to_L1 f) = set_to_fun μ T hT f :=
set_to_fun_congr_ae hT hf.coe_fn_to_L1
lemma set_to_fun_indicator_const (hT : dominated_fin_meas_additive μ T C) {s : set α}
(hs : measurable_set s) (hμs : μ s ≠ ∞) (x : E) :
set_to_fun μ T hT (s.indicator (λ _, x)) = T s x :=
begin
rw set_to_fun_congr_ae hT (@indicator_const_Lp_coe_fn _ _ _ 1 _ _ _ hs hμs x).symm,
rw L1.set_to_fun_eq_set_to_L1 hT,
exact L1.set_to_L1_indicator_const_Lp hT hs hμs x,
end
lemma set_to_fun_const [is_finite_measure μ] (hT : dominated_fin_meas_additive μ T C) (x : E) :
set_to_fun μ T hT (λ _, x) = T univ x :=
begin
have : (λ (_ : α) , x) = set.indicator univ (λ _, x), from (indicator_univ _).symm,
rw this,
exact set_to_fun_indicator_const hT measurable_set.univ (measure_ne_top _ _) x,
end
section order
variables {G' G'' : Type*} [normed_lattice_add_comm_group G''] [normed_space ℝ G'']
[complete_space G'']
[normed_lattice_add_comm_group G'] [normed_space ℝ G']
lemma set_to_fun_mono_left' {T T' : set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C')
(hTT' : ∀ s, measurable_set s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α → E) :
set_to_fun μ T hT f ≤ set_to_fun μ T' hT' f :=
begin
by_cases hf : integrable f μ,
{ simp_rw set_to_fun_eq _ hf, exact L1.set_to_L1_mono_left' hT hT' hTT' _, },
{ simp_rw set_to_fun_undef _ hf, },
end
lemma set_to_fun_mono_left {T T' : set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ T' C')
(hTT' : ∀ s x, T s x ≤ T' s x) (f : α →₁[μ] E) :
set_to_fun μ T hT f ≤ set_to_fun μ T' hT' f :=
set_to_fun_mono_left' hT hT' (λ s _ _ x, hTT' s x) f
lemma set_to_fun_nonneg {T : set α → G' →L[ℝ] G''} {C : ℝ} (hT : dominated_fin_meas_additive μ T C)
(hT_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x)
{f : α → G'} (hf : 0 ≤ᵐ[μ] f) :
0 ≤ set_to_fun μ T hT f :=
begin
by_cases hfi : integrable f μ,
{ simp_rw set_to_fun_eq _ hfi,
refine L1.set_to_L1_nonneg hT hT_nonneg _,
rw ← Lp.coe_fn_le,
have h0 := Lp.coe_fn_zero G' 1 μ,
have h := integrable.coe_fn_to_L1 hfi,
filter_upwards [h0, h, hf] with _ h0a ha hfa,
rw [h0a, ha],
exact hfa, },
{ simp_rw set_to_fun_undef _ hfi, },
end
lemma set_to_fun_mono {T : set α → G' →L[ℝ] G''} {C : ℝ} (hT : dominated_fin_meas_additive μ T C)
(hT_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x)
{f g : α → G'} (hf : integrable f μ) (hg : integrable g μ) (hfg : f ≤ᵐ[μ] g) :
set_to_fun μ T hT f ≤ set_to_fun μ T hT g :=
begin
rw [← sub_nonneg, ← set_to_fun_sub hT hg hf],
refine set_to_fun_nonneg hT hT_nonneg (hfg.mono (λ a ha, _)),
rw [pi.sub_apply, pi.zero_apply, sub_nonneg],
exact ha,
end
end order
@[continuity]
lemma continuous_set_to_fun (hT : dominated_fin_meas_additive μ T C) :
continuous (λ (f : α →₁[μ] E), set_to_fun μ T hT f) :=
by { simp_rw L1.set_to_fun_eq_set_to_L1 hT, exact continuous_linear_map.continuous _, }
/-- If `F i → f` in `L1`, then `set_to_fun μ T hT (F i) → set_to_fun μ T hT f`. -/
lemma tendsto_set_to_fun_of_L1 (hT : dominated_fin_meas_additive μ T C)
{ι} (f : α → E) (hfi : integrable f μ)
{fs : ι → α → E} {l : filter ι} (hfsi : ∀ᶠ i in l, integrable (fs i) μ)
(hfs : tendsto (λ i, ∫⁻ x, ‖fs i x - f x‖₊ ∂μ) l (𝓝 0)) :
tendsto (λ i, set_to_fun μ T hT (fs i)) l (𝓝 $ set_to_fun μ T hT f) :=
begin
classical,
let f_lp := hfi.to_L1 f,
let F_lp := λ i, if hFi : integrable (fs i) μ then hFi.to_L1 (fs i) else 0,
have tendsto_L1 : tendsto F_lp l (𝓝 f_lp),
{ rw Lp.tendsto_Lp_iff_tendsto_ℒp',
simp_rw [snorm_one_eq_lintegral_nnnorm, pi.sub_apply],
refine (tendsto_congr' _).mp hfs,
filter_upwards [hfsi] with i hi,
refine lintegral_congr_ae _,
filter_upwards [hi.coe_fn_to_L1, hfi.coe_fn_to_L1] with x hxi hxf,
simp_rw [F_lp, dif_pos hi, hxi, hxf], },
suffices : tendsto (λ i, set_to_fun μ T hT (F_lp i)) l (𝓝 (set_to_fun μ T hT f)),
{ refine (tendsto_congr' _).mp this,
filter_upwards [hfsi] with i hi,
suffices h_ae_eq : F_lp i =ᵐ[μ] fs i, from set_to_fun_congr_ae hT h_ae_eq,
simp_rw [F_lp, dif_pos hi],
exact hi.coe_fn_to_L1, },
rw set_to_fun_congr_ae hT (hfi.coe_fn_to_L1).symm,
exact ((continuous_set_to_fun hT).tendsto f_lp).comp tendsto_L1,
end
lemma tendsto_set_to_fun_approx_on_of_measurable (hT : dominated_fin_meas_additive μ T C)
[measurable_space E] [borel_space E]
{f : α → E} {s : set E} [separable_space s] (hfi : integrable f μ)
(hfm : measurable f) (hs : ∀ᵐ x ∂μ, f x ∈ closure s) {y₀ : E} (h₀ : y₀ ∈ s)
(h₀i : integrable (λ x, y₀) μ) :
tendsto (λ n, set_to_fun μ T hT (simple_func.approx_on f hfm s y₀ h₀ n)) at_top
(𝓝 $ set_to_fun μ T hT f) :=
tendsto_set_to_fun_of_L1 hT _ hfi
(eventually_of_forall (simple_func.integrable_approx_on hfm hfi h₀ h₀i))
(simple_func.tendsto_approx_on_L1_nnnorm hfm _ hs (hfi.sub h₀i).2)
lemma tendsto_set_to_fun_approx_on_of_measurable_of_range_subset
(hT : dominated_fin_meas_additive μ T C)
[measurable_space E] [borel_space E] {f : α → E}
(fmeas : measurable f) (hf : integrable f μ) (s : set E) [separable_space s]
(hs : range f ∪ {0} ⊆ s) :
tendsto (λ n, set_to_fun μ T hT (simple_func.approx_on f fmeas s 0 (hs $ by simp) n)) at_top
(𝓝 $ set_to_fun μ T hT f) :=
begin
refine tendsto_set_to_fun_approx_on_of_measurable hT hf fmeas _ _ (integrable_zero _ _ _),
exact eventually_of_forall (λ x, subset_closure (hs (set.mem_union_left _ (mem_range_self _)))),
end
/-- Auxiliary lemma for `set_to_fun_congr_measure`: the function sending `f : α →₁[μ] G` to
`f : α →₁[μ'] G` is continuous when `μ' ≤ c' • μ` for `c' ≠ ∞`. -/
lemma continuous_L1_to_L1
{μ' : measure α} (c' : ℝ≥0∞) (hc' : c' ≠ ∞) (hμ'_le : μ' ≤ c' • μ) :
continuous (λ f : α →₁[μ] G,
(integrable.of_measure_le_smul c' hc' hμ'_le (L1.integrable_coe_fn f)).to_L1 f) :=
begin
by_cases hc'0 : c' = 0,
{ have hμ'0 : μ' = 0,
{ rw ← measure.nonpos_iff_eq_zero', refine hμ'_le.trans _, simp [hc'0], },
have h_im_zero : (λ f : α →₁[μ] G,
(integrable.of_measure_le_smul c' hc' hμ'_le (L1.integrable_coe_fn f)).to_L1 f) = 0,
by { ext1 f, ext1, simp_rw hμ'0, simp only [ae_zero], },
rw h_im_zero,
exact continuous_zero, },
rw metric.continuous_iff,
intros f ε hε_pos,
use (ε / 2) / c'.to_real,
refine ⟨div_pos (half_pos hε_pos) (to_real_pos hc'0 hc'), _⟩,
intros g hfg,
rw Lp.dist_def at hfg ⊢,
let h_int := λ f' : α →₁[μ] G, (L1.integrable_coe_fn f').of_measure_le_smul c' hc' hμ'_le,
have : snorm (integrable.to_L1 g (h_int g) - integrable.to_L1 f (h_int f)) 1 μ'
= snorm (g - f) 1 μ',
from snorm_congr_ae ((integrable.coe_fn_to_L1 _).sub (integrable.coe_fn_to_L1 _)),
rw this,
have h_snorm_ne_top : snorm (g - f) 1 μ ≠ ∞,
by { rw ← snorm_congr_ae (Lp.coe_fn_sub _ _), exact Lp.snorm_ne_top _, },
have h_snorm_ne_top' : snorm (g - f) 1 μ' ≠ ∞,
{ refine ((snorm_mono_measure _ hμ'_le).trans_lt _).ne,
rw [snorm_smul_measure_of_ne_zero hc'0, smul_eq_mul],
refine ennreal.mul_lt_top _ h_snorm_ne_top,
simp [hc', hc'0], },
calc (snorm (g - f) 1 μ').to_real ≤ (c' * snorm (g - f) 1 μ).to_real :
by { rw to_real_le_to_real h_snorm_ne_top' (ennreal.mul_ne_top hc' h_snorm_ne_top),
refine (snorm_mono_measure (⇑g - ⇑f) hμ'_le).trans _,
rw [snorm_smul_measure_of_ne_zero hc'0, smul_eq_mul],
simp, }
... = c'.to_real * (snorm (⇑g - ⇑f) 1 μ).to_real : to_real_mul
... ≤ c'.to_real * ((ε / 2) / c'.to_real) :
mul_le_mul le_rfl hfg.le to_real_nonneg to_real_nonneg
... = ε / 2 :
by { refine mul_div_cancel' (ε / 2) _, rw [ne.def, to_real_eq_zero_iff], simp [hc', hc'0], }
... < ε : half_lt_self hε_pos,
end
lemma set_to_fun_congr_measure_of_integrable {μ' : measure α} (c' : ℝ≥0∞)
(hc' : c' ≠ ∞) (hμ'_le : μ' ≤ c' • μ)
(hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ' T C') (f : α → E)
(hfμ : integrable f μ) :
set_to_fun μ T hT f = set_to_fun μ' T hT' f :=
begin
/- integrability for `μ` implies integrability for `μ'`. -/
have h_int : ∀ g : α → E, integrable g μ → integrable g μ',
from λ g hg, integrable.of_measure_le_smul c' hc' hμ'_le hg,
/- We use `integrable.induction` -/
refine hfμ.induction _ _ _ _ _,
{ intros c s hs hμs,
have hμ's : μ' s ≠ ∞,
{ refine ((hμ'_le s hs).trans_lt _).ne,
rw [measure.smul_apply, smul_eq_mul],
exact ennreal.mul_lt_top hc' hμs.ne, },
rw [set_to_fun_indicator_const hT hs hμs.ne, set_to_fun_indicator_const hT' hs hμ's], },
{ intros f₂ g₂ h_dish hf₂ hg₂ h_eq_f h_eq_g,
rw [set_to_fun_add hT hf₂ hg₂,
set_to_fun_add hT' (h_int f₂ hf₂) (h_int g₂ hg₂), h_eq_f, h_eq_g], },
{ refine is_closed_eq (continuous_set_to_fun hT) _,
have : (λ f : α →₁[μ] E, set_to_fun μ' T hT' f)
= (λ f : α →₁[μ] E, set_to_fun μ' T hT' ((h_int f (L1.integrable_coe_fn f)).to_L1 f)),
{ ext1 f, exact set_to_fun_congr_ae hT' (integrable.coe_fn_to_L1 _).symm, },
rw this,
exact (continuous_set_to_fun hT').comp (continuous_L1_to_L1 c' hc' hμ'_le), },
{ intros f₂ g₂ hfg hf₂ hf_eq,
have hfg' : f₂ =ᵐ[μ'] g₂, from (measure.absolutely_continuous_of_le_smul hμ'_le).ae_eq hfg,
rw [← set_to_fun_congr_ae hT hfg, hf_eq, set_to_fun_congr_ae hT' hfg'], },
end
lemma set_to_fun_congr_measure {μ' : measure α} (c c' : ℝ≥0∞) (hc : c ≠ ∞) (hc' : c' ≠ ∞)
(hμ_le : μ ≤ c • μ') (hμ'_le : μ' ≤ c' • μ)
(hT : dominated_fin_meas_additive μ T C) (hT' : dominated_fin_meas_additive μ' T C') (f : α → E) :
set_to_fun μ T hT f = set_to_fun μ' T hT' f :=
begin
by_cases hf : integrable f μ,
{ exact set_to_fun_congr_measure_of_integrable c' hc' hμ'_le hT hT' f hf, },
{ /- if `f` is not integrable, both `set_to_fun` are 0. -/
have h_int : ∀ g : α → E, ¬ integrable g μ → ¬ integrable g μ',
from λ g, mt (λ h, h.of_measure_le_smul _ hc hμ_le),
simp_rw [set_to_fun_undef _ hf, set_to_fun_undef _ (h_int f hf)], },
end
lemma set_to_fun_congr_measure_of_add_right {μ' : measure α}
(hT_add : dominated_fin_meas_additive (μ + μ') T C') (hT : dominated_fin_meas_additive μ T C)
(f : α → E) (hf : integrable f (μ + μ')) :
set_to_fun (μ + μ') T hT_add f = set_to_fun μ T hT f :=
begin
refine set_to_fun_congr_measure_of_integrable 1 one_ne_top _ hT_add hT f hf,
rw one_smul,
nth_rewrite 0 ← add_zero μ,
exact add_le_add le_rfl bot_le,
end
lemma set_to_fun_congr_measure_of_add_left {μ' : measure α}
(hT_add : dominated_fin_meas_additive (μ + μ') T C') (hT : dominated_fin_meas_additive μ' T C)
(f : α → E) (hf : integrable f (μ + μ')) :
set_to_fun (μ + μ') T hT_add f = set_to_fun μ' T hT f :=
begin
refine set_to_fun_congr_measure_of_integrable 1 one_ne_top _ hT_add hT f hf,
rw one_smul,
nth_rewrite 0 ← zero_add μ',
exact add_le_add bot_le le_rfl,
end
lemma set_to_fun_top_smul_measure (hT : dominated_fin_meas_additive (∞ • μ) T C) (f : α → E) :
set_to_fun (∞ • μ) T hT f = 0 :=
begin
refine set_to_fun_measure_zero' hT (λ s hs hμs, _),
rw lt_top_iff_ne_top at hμs,
simp only [true_and, measure.smul_apply, with_top.mul_eq_top_iff, eq_self_iff_true, top_ne_zero,
ne.def, not_false_iff, not_or_distrib, not_not, smul_eq_mul] at hμs,
simp only [hμs.right, measure.smul_apply, mul_zero, smul_eq_mul],
end
lemma set_to_fun_congr_smul_measure (c : ℝ≥0∞) (hc_ne_top : c ≠ ∞)
(hT : dominated_fin_meas_additive μ T C) (hT_smul : dominated_fin_meas_additive (c • μ) T C')
(f : α → E) :
set_to_fun μ T hT f = set_to_fun (c • μ) T hT_smul f :=
begin
by_cases hc0 : c = 0,
{ simp [hc0] at hT_smul,
have h : ∀ s, measurable_set s → μ s < ∞ → T s = 0,
from λ s hs hμs, hT_smul.eq_zero hs,
rw [set_to_fun_zero_left' _ h, set_to_fun_measure_zero],
simp [hc0], },
refine set_to_fun_congr_measure c⁻¹ c _ hc_ne_top (le_of_eq _) le_rfl hT hT_smul f,
{ simp [hc0], },
{ rw [smul_smul, ennreal.inv_mul_cancel hc0 hc_ne_top, one_smul], },
end
lemma norm_set_to_fun_le_mul_norm (hT : dominated_fin_meas_additive μ T C) (f : α →₁[μ] E)
(hC : 0 ≤ C) :
‖set_to_fun μ T hT f‖ ≤ C * ‖f‖ :=
by { rw L1.set_to_fun_eq_set_to_L1, exact L1.norm_set_to_L1_le_mul_norm hT hC f, }
lemma norm_set_to_fun_le_mul_norm' (hT : dominated_fin_meas_additive μ T C) (f : α →₁[μ] E) :
‖set_to_fun μ T hT f‖ ≤ max C 0 * ‖f‖ :=
by { rw L1.set_to_fun_eq_set_to_L1, exact L1.norm_set_to_L1_le_mul_norm' hT f, }
lemma norm_set_to_fun_le (hT : dominated_fin_meas_additive μ T C) (hf : integrable f μ)
(hC : 0 ≤ C) :
‖set_to_fun μ T hT f‖ ≤ C * ‖hf.to_L1 f‖ :=
by { rw set_to_fun_eq hT hf, exact L1.norm_set_to_L1_le_mul_norm hT hC _, }
lemma norm_set_to_fun_le' (hT : dominated_fin_meas_additive μ T C) (hf : integrable f μ) :
‖set_to_fun μ T hT f‖ ≤ max C 0 * ‖hf.to_L1 f‖ :=
by { rw set_to_fun_eq hT hf, exact L1.norm_set_to_L1_le_mul_norm' hT _, }
/-- Lebesgue dominated convergence theorem provides sufficient conditions under which almost
everywhere convergence of a sequence of functions implies the convergence of their image by
`set_to_fun`.
We could weaken the condition `bound_integrable` to require `has_finite_integral bound μ` instead
(i.e. not requiring that `bound` is measurable), but in all applications proving integrability
is easier. -/
theorem tendsto_set_to_fun_of_dominated_convergence (hT : dominated_fin_meas_additive μ T C)
{fs : ℕ → α → E} {f : α → E} (bound : α → ℝ)
(fs_measurable : ∀ n, ae_strongly_measurable (fs n) μ)
(bound_integrable : integrable bound μ) (h_bound : ∀ n, ∀ᵐ a ∂μ, ‖fs n a‖ ≤ bound a)
(h_lim : ∀ᵐ a ∂μ, tendsto (λ n, fs n a) at_top (𝓝 (f a))) :
tendsto (λ n, set_to_fun μ T hT (fs n)) at_top (𝓝 $ set_to_fun μ T hT f) :=
begin
/- `f` is a.e.-measurable, since it is the a.e.-pointwise limit of a.e.-measurable functions. -/
have f_measurable : ae_strongly_measurable f μ :=
ae_strongly_measurable_of_tendsto_ae _ fs_measurable h_lim,
/- all functions we consider are integrable -/
have fs_int : ∀ n, integrable (fs n) μ :=
λ n, bound_integrable.mono' (fs_measurable n) (h_bound _),
have f_int : integrable f μ :=
⟨f_measurable, has_finite_integral_of_dominated_convergence
bound_integrable.has_finite_integral h_bound h_lim⟩,
/- it suffices to prove the result for the corresponding L1 functions -/
suffices : tendsto (λ n, L1.set_to_L1 hT ((fs_int n).to_L1 (fs n))) at_top
(𝓝 (L1.set_to_L1 hT (f_int.to_L1 f))),
{ convert this,
{ ext1 n, exact set_to_fun_eq hT (fs_int n), },
{ exact set_to_fun_eq hT f_int, }, },
/- the convergence of set_to_L1 follows from the convergence of the L1 functions -/
refine L1.tendsto_set_to_L1 hT _ _ _,
/- up to some rewriting, what we need to prove is `h_lim` -/
rw tendsto_iff_norm_tendsto_zero,
have lintegral_norm_tendsto_zero :
tendsto (λn, ennreal.to_real $ ∫⁻ a, (ennreal.of_real ‖fs n a - f a‖) ∂μ) at_top (𝓝 0) :=
(tendsto_to_real zero_ne_top).comp
(tendsto_lintegral_norm_of_dominated_convergence
fs_measurable bound_integrable.has_finite_integral h_bound h_lim),
convert lintegral_norm_tendsto_zero,
ext1 n,
rw L1.norm_def,
congr' 1,
refine lintegral_congr_ae _,
rw ← integrable.to_L1_sub,
refine ((fs_int n).sub f_int).coe_fn_to_L1.mono (λ x hx, _),
dsimp only,
rw [hx, of_real_norm_eq_coe_nnnorm, pi.sub_apply],
end
/-- Lebesgue dominated convergence theorem for filters with a countable basis -/
lemma tendsto_set_to_fun_filter_of_dominated_convergence (hT : dominated_fin_meas_additive μ T C)
{ι} {l : _root_.filter ι} [l.is_countably_generated]
{fs : ι → α → E} {f : α → E} (bound : α → ℝ)
(hfs_meas : ∀ᶠ n in l, ae_strongly_measurable (fs n) μ)
(h_bound : ∀ᶠ n in l, ∀ᵐ a ∂μ, ‖fs n a‖ ≤ bound a)
(bound_integrable : integrable bound μ)
(h_lim : ∀ᵐ a ∂μ, tendsto (λ n, fs n a) l (𝓝 (f a))) :
tendsto (λ n, set_to_fun μ T hT (fs n)) l (𝓝 $ set_to_fun μ T hT f) :=
begin
rw tendsto_iff_seq_tendsto,
intros x xl,
have hxl : ∀ s ∈ l, ∃ a, ∀ b ≥ a, x b ∈ s, by { rwa tendsto_at_top' at xl, },
have h : {x : ι | (λ n, ae_strongly_measurable (fs n) μ) x}
∩ {x : ι | (λ n, ∀ᵐ a ∂μ, ‖fs n a‖ ≤ bound a) x} ∈ l,
from inter_mem hfs_meas h_bound,
obtain ⟨k, h⟩ := hxl _ h,
rw ← tendsto_add_at_top_iff_nat k,
refine tendsto_set_to_fun_of_dominated_convergence hT bound _ bound_integrable _ _,
{ exact λ n, (h _ (self_le_add_left _ _)).1, },
{ exact λ n, (h _ (self_le_add_left _ _)).2, },
{ filter_upwards [h_lim],
refine λ a h_lin, @tendsto.comp _ _ _ (λ n, x (n + k)) (λ n, fs n a) _ _ _ h_lin _,
rw tendsto_add_at_top_iff_nat,
assumption }
end
variables {X : Type*} [topological_space X] [first_countable_topology X]
lemma continuous_within_at_set_to_fun_of_dominated (hT : dominated_fin_meas_additive μ T C)
{fs : X → α → E} {x₀ : X} {bound : α → ℝ} {s : set X}
(hfs_meas : ∀ᶠ x in 𝓝[s] x₀, ae_strongly_measurable (fs x) μ)
(h_bound : ∀ᶠ x in 𝓝[s] x₀, ∀ᵐ a ∂μ, ‖fs x a‖ ≤ bound a)
(bound_integrable : integrable bound μ)
(h_cont : ∀ᵐ a ∂μ, continuous_within_at (λ x, fs x a) s x₀) :
continuous_within_at (λ x, set_to_fun μ T hT (fs x)) s x₀ :=
tendsto_set_to_fun_filter_of_dominated_convergence hT bound ‹_› ‹_› ‹_› ‹_›
lemma continuous_at_set_to_fun_of_dominated (hT : dominated_fin_meas_additive μ T C)
{fs : X → α → E} {x₀ : X} {bound : α → ℝ}
(hfs_meas : ∀ᶠ x in 𝓝 x₀, ae_strongly_measurable (fs x) μ)
(h_bound : ∀ᶠ x in 𝓝 x₀, ∀ᵐ a ∂μ, ‖fs x a‖ ≤ bound a)
(bound_integrable : integrable bound μ) (h_cont : ∀ᵐ a ∂μ, continuous_at (λ x, fs x a) x₀) :
continuous_at (λ x, set_to_fun μ T hT (fs x)) x₀ :=
tendsto_set_to_fun_filter_of_dominated_convergence hT bound ‹_› ‹_› ‹_› ‹_›
lemma continuous_on_set_to_fun_of_dominated (hT : dominated_fin_meas_additive μ T C)
{fs : X → α → E} {bound : α → ℝ} {s : set X}
(hfs_meas : ∀ x ∈ s, ae_strongly_measurable (fs x) μ)
(h_bound : ∀ x ∈ s, ∀ᵐ a ∂μ, ‖fs x a‖ ≤ bound a)
(bound_integrable : integrable bound μ) (h_cont : ∀ᵐ a ∂μ, continuous_on (λ x, fs x a) s) :
continuous_on (λ x, set_to_fun μ T hT (fs x)) s :=
begin
assume x hx,
refine continuous_within_at_set_to_fun_of_dominated hT _ _ bound_integrable _,
{ filter_upwards [self_mem_nhds_within] with x hx using hfs_meas x hx },
{ filter_upwards [self_mem_nhds_within] with x hx using h_bound x hx },
{ filter_upwards [h_cont] with a ha using ha x hx }
end
lemma continuous_set_to_fun_of_dominated (hT : dominated_fin_meas_additive μ T C)
{fs : X → α → E} {bound : α → ℝ}
(hfs_meas : ∀ x, ae_strongly_measurable (fs x) μ) (h_bound : ∀ x, ∀ᵐ a ∂μ, ‖fs x a‖ ≤ bound a)
(bound_integrable : integrable bound μ) (h_cont : ∀ᵐ a ∂μ, continuous (λ x, fs x a)) :
continuous (λ x, set_to_fun μ T hT (fs x)) :=
continuous_iff_continuous_at.mpr (λ x₀, continuous_at_set_to_fun_of_dominated hT
(eventually_of_forall hfs_meas) (eventually_of_forall h_bound) ‹_› $ h_cont.mono $
λ _, continuous.continuous_at)
end function
end measure_theory
|
3b6860a64868568e742f48c184d3e8c14fd12313
|
a45212b1526d532e6e83c44ddca6a05795113ddc
|
/src/data/real/irrational.lean
|
006e0db47bdf84648acc18563f66d2329fef3c2c
|
[
"Apache-2.0"
] |
permissive
|
fpvandoorn/mathlib
|
b21ab4068db079cbb8590b58fda9cc4bc1f35df4
|
b3433a51ea8bc07c4159c1073838fc0ee9b8f227
|
refs/heads/master
| 1,624,791,089,608
| 1,556,715,231,000
| 1,556,715,231,000
| 165,722,980
| 5
| 0
|
Apache-2.0
| 1,552,657,455,000
| 1,547,494,646,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 4,747
|
lean
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne.
Irrationality of real numbers.
-/
import data.real.basic data.padics.padic_norm
open rat real multiplicity
def irrational (x : ℝ) := ¬ ∃ q : ℚ, x = q
theorem irr_nrt_of_notint_nrt {x : ℝ} (n : ℕ) (m : ℤ)
(hxr : x ^ n = m) (hv : ¬ ∃ y : ℤ, x = y) (hnpos : n > 0) :
irrational x
| ⟨q, e⟩ := begin
rw [e, ← cast_pow] at hxr, cases q with N D P C,
have c1 : ((D : ℤ) : ℝ) ≠ 0,
{ rw [int.cast_ne_zero, int.coe_nat_ne_zero], exact ne_of_gt P },
have c2 : ((D : ℤ) : ℝ) ^ n ≠ 0 := pow_ne_zero _ c1,
rw [num_denom', cast_pow, cast_mk, div_pow _ c1, div_eq_iff_mul_eq c2,
← int.cast_pow, ← int.cast_pow, ← int.cast_mul, int.cast_inj] at hxr,
have hdivn : ↑D ^ n ∣ N ^ n := dvd.intro_left m hxr,
rw [← int.dvd_nat_abs, ← int.coe_nat_pow, int.coe_nat_dvd, int.nat_abs_pow, nat.pow_dvd_pow_iff hnpos] at hdivn,
have hdivn' : nat.gcd N.nat_abs D = D := nat.gcd_eq_right hdivn,
refine hv ⟨N, _⟩,
rwa [num_denom', ← hdivn', C.gcd_eq_one, int.coe_nat_one, mk_eq_div,
int.cast_one, div_one, cast_coe_int] at e
end
theorem irr_nrt_of_n_not_dvd_multiplicity {x : ℝ} (n : ℕ) {m : ℤ} (hm : m ≠ 0) (p : ℕ)
[hp : nat.prime p] (hxr : x ^ n = m)
(hv : (multiplicity (p : ℤ) m).get (finite_int_iff.2 ⟨hp.ne_one, hm⟩) % n ≠ 0) :
irrational x :=
begin
rcases nat.eq_zero_or_pos n with rfl | hnpos,
{ rw [eq_comm, pow_zero, ← int.cast_one, int.cast_inj] at hxr,
simpa [hxr, multiplicity.one_right (mt is_unit_iff_dvd_one.1
(mt int.coe_nat_dvd.1 hp.not_dvd_one)), nat.zero_mod] using hv },
refine irr_nrt_of_notint_nrt _ _ hxr _ hnpos,
rintro ⟨y, rfl⟩,
rw [← int.cast_pow, int.cast_inj] at hxr, subst m,
have : y ≠ 0, { rintro rfl, rw zero_pow hnpos at hm, exact hm rfl },
erw [multiplicity.pow' (nat.prime_iff_prime_int.1 hp)
(finite_int_iff.2 ⟨hp.ne_one, this⟩), nat.mul_mod_right] at hv,
exact hv rfl
end
theorem irr_sqrt_of_multiplicity_odd (m : ℤ) (hm : 0 < m)
(p : ℕ) [hp : nat.prime p]
(Hpv : (multiplicity (p : ℤ) m).get (finite_int_iff.2 ⟨hp.ne_one, ne.symm (ne_of_lt hm)⟩) % 2 = 1) :
irrational (sqrt m) :=
irr_nrt_of_n_not_dvd_multiplicity 2 (ne.symm (ne_of_lt hm)) p
(sqr_sqrt (int.cast_nonneg.2 $ le_of_lt hm))
(by rw Hpv; exact one_ne_zero)
theorem irr_sqrt_of_prime (p : ℕ) (hp : nat.prime p) : irrational (sqrt p) :=
irr_sqrt_of_multiplicity_odd p (int.coe_nat_pos.2 hp.pos) p $
by simp [multiplicity_self (mt is_unit_iff_dvd_one.1 (mt int.coe_nat_dvd.1 hp.not_dvd_one) : _)];
refl
theorem irr_sqrt_two : irrational (sqrt 2) :=
by simpa using irr_sqrt_of_prime 2 nat.prime_two
theorem irr_sqrt_rat_iff (q : ℚ) : irrational (sqrt q) ↔
rat.sqrt q * rat.sqrt q ≠ q ∧ 0 ≤ q :=
if H1 : rat.sqrt q * rat.sqrt q = q
then iff_of_false (not_not_intro ⟨rat.sqrt q,
by rw [← H1, cast_mul, sqrt_mul_self (cast_nonneg.2 $ rat.sqrt_nonneg q),
sqrt_eq, abs_of_nonneg (rat.sqrt_nonneg q)]⟩) (λ h, h.1 H1)
else if H2 : 0 ≤ q
then iff_of_true (λ ⟨r, hr⟩, H1 $ (exists_mul_self _).1 ⟨r,
by rwa [sqrt_eq_iff_mul_self_eq (cast_nonneg.2 H2), ← cast_mul, cast_inj] at hr;
rw [← hr]; exact real.sqrt_nonneg _⟩) ⟨H1, H2⟩
else iff_of_false (not_not_intro ⟨0,
by rw cast_zero; exact sqrt_eq_zero_of_nonpos (rat.cast_nonpos.2 $ le_of_not_le H2)⟩)
(λ h, H2 h.2)
instance (q : ℚ) : decidable (irrational (sqrt q)) :=
decidable_of_iff' _ (irr_sqrt_rat_iff q)
variables {q : ℚ} {x : ℝ}
theorem irr_rat_add_of_irr : irrational x → irrational (q + x) :=
mt $ λ ⟨a, h⟩, ⟨-q + a, by rw [rat.cast_add, ← h, rat.cast_neg, neg_add_cancel_left]⟩
@[simp] theorem irr_rat_add_iff_irr : irrational (q + x) ↔ irrational x :=
⟨by simpa only [cast_neg, neg_add_cancel_left] using @irr_rat_add_of_irr (-q) (q+x),
irr_rat_add_of_irr⟩
@[simp] theorem irr_add_rat_iff_irr : irrational (x + q) ↔ irrational x :=
by rw [add_comm, irr_rat_add_iff_irr]
theorem irr_mul_rat_iff_irr (Hqn0 : q ≠ 0) : irrational (x * ↑q) ↔ irrational x :=
⟨mt $ λ ⟨r, hr⟩, ⟨r * q, hr.symm ▸ (rat.cast_mul _ _).symm⟩,
mt $ λ ⟨r, hr⟩, ⟨r / q, by rw [cast_div, ← hr, mul_div_cancel]; rwa cast_ne_zero⟩⟩
theorem irr_of_irr_mul_self : irrational (x * x) → irrational x :=
mt $ λ ⟨p, e⟩, ⟨p * p, by rw [e, cast_mul]⟩
@[simp] theorem irr_neg : irrational (-x) ↔ irrational x :=
⟨λ hn ⟨q, hx⟩, hn ⟨-q, by rw [hx, cast_neg]⟩,
λ hx ⟨q, hn⟩, hx ⟨-q, by rw [←neg_neg x, hn, cast_neg]⟩⟩
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.