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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ffe88e667ef6214f45f9e83f269379ead9357551 | f313d4982feee650661f61ed73f0cb6635326350 | /Mathlib/Tactic/Basic.lean | deddb92ea6b37b9bf0899cdeadd4e6d1ae554efc | [
"Apache-2.0"
] | permissive | shingtaklam1324/mathlib4 | 38c6e172eec1385944db5a70a3b5545c924980ee | 50610c343b7065e8eec056d641f859ceed608e69 | refs/heads/master | 1,683,032,333,313 | 1,621,942,699,000 | 1,621,942,699,000 | 371,130,608 | 0 | 0 | Apache-2.0 | 1,622,053,166,000 | 1,622,053,166,000 | null | UTF-8 | Lean | false | false | 1,824 | lean | /-
Copyright (c) 2021 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
-/
import Mathlib.Tactic.Split
import Mathlib.Tactic.NoMatch
import Mathlib.Tactic.Block
import Lean.Elab.Command
open Lean Parser.Tactic Elab Command
syntax (name := «variables») "variables" (bracketedBinder)* : command
@[commandElab «variables»] def elabVariables : CommandElab
| `(variables%$pos $binders*) => do
logWarningAt pos "'variables' has been replaced by 'variable' in lean 4"
elabVariable (← `(variable%$pos $binders*))
| _ => throwUnsupportedSyntax
macro mods:declModifiers "lemma" n:declId sig:declSig val:declVal : command =>
`($mods:declModifiers theorem $n $sig $val)
macro "exfalso" : tactic => `(apply False.elim)
macro "_" : tactic => `({})
macro_rules | `(tactic| rfl) => `(tactic| exact Iff.rfl)
macro_rules
| `(tactic| change $e:term) => `(tactic| show $e)
macro "sorry" : tactic => `(tactic| admit)
syntax "rwa " rwRuleSeq (location)? : tactic
macro_rules
| `(tactic| rwa $rws:rwRuleSeq $[$loc:location]?) =>
`(tactic| rw $rws:rwRuleSeq $[$loc:location]?; assumption)
macro "by_cases " h:ident ":" e:term : tactic =>
`(cases Decidable.em $e with | inl $h => ?pos | inr $h => ?neg)
set_option hygiene false in
macro "by_cases " e:term : tactic =>
`(cases Decidable.em $e with | inl h => ?pos | inr h => ?neg)
syntax "transitivity" (colGt term)? : tactic
set_option hygiene false in
macro_rules
| `(tactic| transitivity) => `(tactic| apply Nat.le_trans)
| `(tactic| transitivity $e) => `(tactic| apply Nat.le_trans (m := $e))
set_option hygiene false in
macro_rules
| `(tactic| transitivity) => `(tactic| apply Nat.lt_trans)
| `(tactic| transitivity $e) => `(tactic| apply Nat.lt_trans (m := $e))
|
1bae8c1e43049a93de9bf4db30b15b4522532686 | 82b86ba2ae0d5aed0f01f49c46db5afec0eb2bd7 | /stage0/src/Init/Tactics.lean | 9f3e2be3c73a198eb0557910b7f8cc47ad446649 | [
"Apache-2.0"
] | permissive | banksonian/lean4 | 3a2e6b0f1eb63aa56ff95b8d07b2f851072d54dc | 78da6b3aa2840693eea354a41e89fc5b212a5011 | refs/heads/master | 1,673,703,624,165 | 1,605,123,551,000 | 1,605,123,551,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 921 | 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.LeanInit
import Init.Data.Array.Macros
macro "rfl" : tactic => `(exact rfl)
macro "decide!" : tactic => `(exact decide!)
macro "admit" : tactic => `(exact sorry)
/- We use a priority > 0, to avoid ambiguity with the builtin `have` notation -/
macro[1] "have" x:ident ":=" p:term : tactic => `(have $x:ident : _ := $p)
syntax "repeat " tacticSeq : tactic
macro_rules
| `(tactic| repeat $seq) => `(tactic| (($seq); repeat $seq) <|> skip)
macro "try " t:tacticSeq : tactic => `(($t) <|> skip)
syntax "funext " (>col term:max)+ : tactic
macro_rules
| `(tactic|funext $xs*) =>
if xs.size == 1 then
`(tactic| apply funext; intro $(xs[0]):term)
else
`(tactic| apply funext; intro $(xs[0]):term; funext $(xs[1:])*)
|
8f3dd99c24c7ac8b43afe31cffb84b1560c408e7 | 5e3548e65f2c037cb94cd5524c90c623fbd6d46a | /src_icannos_totilas/aops/2003-Pan_African_MO-Problem_6.lean | d148e3da7051b0059b42e50bb0142cfb2dbfa2e7 | [] | no_license | ahayat16/lean_exos | d4f08c30adb601a06511a71b5ffb4d22d12ef77f | 682f2552d5b04a8c8eb9e4ab15f875a91b03845c | refs/heads/main | 1,693,101,073,585 | 1,636,479,336,000 | 1,636,479,336,000 | 415,000,441 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 160 | lean | import data.real.basic
theorem exo (f: real -> real):
(forall x y, f(x^2)-f(y^2)=(x+y)*(f(x)-f(y)))
-> (exists m l, forall x, f(x) = m * x + l)
:=
sorry
|
45cf2eab17270253d749b8eb1bd0843589f3c844 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/data/set/countable_auto.lean | 9718762a9cf30ae070e46916451a6ebf27d0a190 | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,887 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Johannes Hölzl
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.equiv.list
import Mathlib.data.set.finite
import Mathlib.PostPort
universes u v u_1
namespace Mathlib
/-!
# Countable sets
-/
namespace set
/-- A set is countable if there exists an encoding of the set into the natural numbers.
An encoding is an injection with a partial inverse, which can be viewed as a
constructive analogue of countability. (For the most part, theorems about
`countable` will be classical and `encodable` will be constructive.)
-/
def countable {α : Type u} (s : set α) := Nonempty (encodable ↥s)
theorem countable_iff_exists_injective {α : Type u} {s : set α} :
countable s ↔ ∃ (f : ↥s → ℕ), function.injective f :=
sorry
/-- A set `s : set α` is countable if and only if there exists a function `α → ℕ` injective
on `s`. -/
theorem countable_iff_exists_inj_on {α : Type u} {s : set α} :
countable s ↔ ∃ (f : α → ℕ), inj_on f s :=
sorry
theorem countable_iff_exists_surjective {α : Type u} [ne : Nonempty α] {s : set α} :
countable s ↔ ∃ (f : ℕ → α), s ⊆ range f :=
sorry
/--
A non-empty set is countable iff there exists a surjection from the
natural numbers onto the subtype induced by the set.
-/
theorem countable_iff_exists_surjective_to_subtype {α : Type u} {s : set α} (hs : set.nonempty s) :
countable s ↔ ∃ (f : ℕ → ↥s), function.surjective f :=
sorry
/-- Convert `countable s` to `encodable s` (noncomputable). -/
def countable.to_encodable {α : Type u} {s : set α} : countable s → encodable ↥s := Classical.choice
theorem countable_encodable' {α : Type u} (s : set α) [H : encodable ↥s] : countable s :=
Nonempty.intro H
theorem countable_encodable {α : Type u} [encodable α] (s : set α) : countable s :=
Nonempty.intro encodable.subtype
/-- If `s : set α` is a nonempty countable set, then there exists a map
`f : ℕ → α` such that `s = range f`. -/
theorem countable.exists_surjective {α : Type u} {s : set α} (hc : countable s)
(hs : set.nonempty s) : ∃ (f : ℕ → α), s = range f :=
sorry
@[simp] theorem countable_empty {α : Type u} : countable ∅ :=
Nonempty.intro
(encodable.mk (fun (x : ↥∅) => false.elim (subtype.property x)) (fun (n : ℕ) => none)
fun (x : ↥∅) => false.elim (subtype.property x))
@[simp] theorem countable_singleton {α : Type u} (a : α) : countable (singleton a) :=
Nonempty.intro (encodable.of_equiv PUnit (equiv.set.singleton a))
theorem countable.mono {α : Type u} {s₁ : set α} {s₂ : set α} (h : s₁ ⊆ s₂) :
countable s₂ → countable s₁ :=
sorry
theorem countable.image {α : Type u} {β : Type v} {s : set α} (hs : countable s) (f : α → β) :
countable (f '' s) :=
sorry
theorem countable_range {α : Type u} {β : Type v} [encodable α] (f : α → β) : countable (range f) :=
eq.mpr (id (Eq._oldrec (Eq.refl (countable (range f))) (Eq.symm image_univ)))
(countable.image (countable_encodable univ) f)
theorem exists_seq_supr_eq_top_iff_countable {α : Type u} [complete_lattice α] {p : α → Prop}
(h : ∃ (x : α), p x) :
(∃ (s : ℕ → α), (∀ (n : ℕ), p (s n)) ∧ (supr fun (n : ℕ) => s n) = ⊤) ↔
∃ (S : set α), countable S ∧ (∀ (s : α), s ∈ S → p s) ∧ Sup S = ⊤ :=
sorry
theorem exists_seq_cover_iff_countable {α : Type u} {p : set α → Prop} (h : ∃ (s : set α), p s) :
(∃ (s : ℕ → set α), (∀ (n : ℕ), p (s n)) ∧ (Union fun (n : ℕ) => s n) = univ) ↔
∃ (S : set (set α)), countable S ∧ (∀ (s : set α), s ∈ S → p s) ∧ ⋃₀S = univ :=
exists_seq_supr_eq_top_iff_countable h
theorem countable_of_injective_of_countable_image {α : Type u} {β : Type v} {s : set α} {f : α → β}
(hf : inj_on f s) (hs : countable (f '' s)) : countable s :=
sorry
theorem countable_Union {α : Type u} {β : Type v} {t : α → set β} [encodable α]
(ht : ∀ (a : α), countable (t a)) : countable (Union fun (a : α) => t a) :=
eq.mpr
(id
(Eq._oldrec (Eq.refl (countable (Union fun (a : α) => t a)))
(Union_eq_range_sigma fun (a : α) => t a)))
(countable_range fun (a : sigma fun (i : α) => ↥(t i)) => ↑(sigma.snd a))
theorem countable.bUnion {α : Type u} {β : Type v} {s : set α} {t : (x : α) → x ∈ s → set β}
(hs : countable s) (ht : ∀ (a : α) (H : a ∈ s), countable (t a H)) :
countable (Union fun (a : α) => Union fun (H : a ∈ s) => t a H) :=
sorry
theorem countable.sUnion {α : Type u} {s : set (set α)} (hs : countable s)
(h : ∀ (a : set α), a ∈ s → countable a) : countable (⋃₀s) :=
eq.mpr (id (Eq._oldrec (Eq.refl (countable (⋃₀s))) sUnion_eq_bUnion)) (countable.bUnion hs h)
theorem countable_Union_Prop {β : Type v} {p : Prop} {t : p → set β}
(ht : ∀ (h : p), countable (t h)) : countable (Union fun (h : p) => t h) :=
sorry
theorem countable.union {α : Type u} {s₁ : set α} {s₂ : set α} (h₁ : countable s₁)
(h₂ : countable s₂) : countable (s₁ ∪ s₂) :=
eq.mpr (id (Eq._oldrec (Eq.refl (countable (s₁ ∪ s₂))) union_eq_Union))
(countable_Union (iff.mpr bool.forall_bool { left := h₂, right := h₁ }))
theorem countable.insert {α : Type u} {s : set α} (a : α) (h : countable s) :
countable (insert a s) :=
eq.mpr (id (Eq._oldrec (Eq.refl (countable (insert a s))) (insert_eq a s)))
(countable.union (countable_singleton a) h)
theorem finite.countable {α : Type u} {s : set α} : finite s → countable s := sorry
/-- The set of finite subsets of a countable set is countable. -/
theorem countable_set_of_finite_subset {α : Type u} {s : set α} :
countable s → countable (set_of fun (t : set α) => finite t ∧ t ⊆ s) :=
sorry
theorem countable_pi {α : Type u} {π : α → Type u_1} [fintype α] {s : (a : α) → set (π a)}
(hs : ∀ (a : α), countable (s a)) :
countable (set_of fun (f : (a : α) → π a) => ∀ (a : α), f a ∈ s a) :=
sorry
theorem countable_prod {α : Type u} {β : Type v} {s : set α} {t : set β} (hs : countable s)
(ht : countable t) : countable (set.prod s t) :=
sorry
/-- Enumerate elements in a countable set.-/
def enumerate_countable {α : Type u} {s : set α} (h : countable s) (default : α) : ℕ → α :=
fun (n : ℕ) => sorry
theorem subset_range_enumerate {α : Type u} {s : set α} (h : countable s) (default : α) :
s ⊆ range (enumerate_countable h default) :=
sorry
end set
theorem finset.countable_to_set {α : Type u} (s : finset α) : set.countable ↑s :=
set.finite.countable (finset.finite_to_set s)
end Mathlib |
f321a5a6a8e7d42ec813097f5b9c86542738fb8b | 6fca17f8d5025f89be1b2d9d15c9e0c4b4900cbf | /src/game/world7/level3.lean | 5b1eafb1989a80d50c9c84fb6e494ed85c6baadd | [
"Apache-2.0"
] | permissive | arolihas/natural_number_game | 4f0c93feefec93b8824b2b96adff8b702b8b43ce | 8e4f7b4b42888a3b77429f90cce16292bd288138 | refs/heads/master | 1,621,872,426,808 | 1,586,270,467,000 | 1,586,270,467,000 | 253,648,466 | 0 | 0 | null | 1,586,219,694,000 | 1,586,219,694,000 | null | UTF-8 | Lean | false | false | 262 | lean | /-
# Advanced proposition world.
## Level 3: and_trans.
-/
/- Lemma
If $P$, $Q$ and $R$ are true/false statements, then $P\land Q$ and
$Q\land R$ together imply $P\land R$.
-/
lemma and_trans (P Q R : Prop) : P ∧ Q → Q ∧ R → P ∧ R :=
begin
end
|
aed1250f770a3cc6d2fa12bc6e8cd2cfc9272da4 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/category_theory/limits/preserves/finite.lean | f95bdb22c101ea22bc45fa40520d0c0d00860cf8 | [
"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 | 5,934 | lean | /-
Copyright (c) 2021 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import category_theory.limits.preserves.basic
import category_theory.fin_category
/-!
# Preservation of finite (co)limits.
These functors are also known as left exact (flat) or right exact functors when the categories
involved are abelian, or more generally, finitely (co)complete.
## Related results
* `category_theory.limits.preserves_finite_limits_of_preserves_equalizers_and_finite_products` :
see `category_theory/limits/constructions/limits_of_products_and_equalizers.lean`. Also provides
the dual version.
* `category_theory.limits.preserves_finite_limits_iff_flat` :
see `category_theory/flat_functors.lean`.
-/
open category_theory
namespace category_theory.limits
-- declare the `v`'s first; see `category_theory.category` for an explanation
universes w w₂ v₁ v₂ v₃ u₁ u₂ u₃
variables {C : Type u₁} [category.{v₁} C]
variables {D : Type u₂} [category.{v₂} D]
variables {E : Type u₃} [category.{v₃} E]
variables {J : Type w} [small_category J] {K : J ⥤ C}
/--
A functor is said to preserve finite limits, if it preserves all limits of shape `J`,
where `J : Type` is a finite category.
-/
class preserves_finite_limits (F : C ⥤ D) :=
(preserves_finite_limits : Π (J : Type) [small_category J] [fin_category J],
preserves_limits_of_shape J F . tactic.apply_instance)
attribute [instance] preserves_finite_limits.preserves_finite_limits
/-- Preserving finite limits also implies preserving limits over finite shapes in higher universes,
though through a noncomputable instance. -/
@[priority 100]
noncomputable instance preserves_limits_of_shape_of_preserves_finite_limits (F : C ⥤ D)
[preserves_finite_limits F] (J : Type w) [small_category J] [fin_category J] :
preserves_limits_of_shape J F :=
by apply preserves_limits_of_shape_of_equiv (fin_category.equiv_as_type J)
@[priority 100]
noncomputable instance preserves_limits.preserves_finite_limits_of_size (F : C ⥤ D)
[preserves_limits_of_size.{w w₂} F] : preserves_finite_limits F :=
⟨λ J sJ fJ,
begin
haveI := preserves_smallest_limits_of_preserves_limits F,
exact preserves_limits_of_shape_of_equiv (fin_category.equiv_as_type J) F,
end⟩
@[priority 120]
noncomputable instance preserves_limits.preserves_finite_limits (F : C ⥤ D)
[preserves_limits F] : preserves_finite_limits F :=
preserves_limits.preserves_finite_limits_of_size F
/-- We can always derive `preserves_finite_limits C` by showing that we are preserving limits at an
arbitrary universe. -/
def preserves_finite_limits_of_preserves_finite_limits_of_size (F : C ⥤ D)
(h : ∀ (J : Type w) {𝒥 : small_category J} (hJ : @fin_category J 𝒥),
by { resetI, exact preserves_limits_of_shape J F }) :
preserves_finite_limits F :=
⟨λ J hJ hhJ,
begin
resetI,
letI : category.{w w} (ulift_hom.{w} (ulift.{w 0} J)),
{ apply ulift_hom.category.{0}, exact category_theory.ulift_category J },
haveI := h (ulift_hom.{w} (ulift.{w} J)) category_theory.fin_category_ulift,
exact preserves_limits_of_shape_of_equiv (ulift_hom_ulift_category.equiv.{w w} J).symm F
end⟩
instance id_preserves_finite_limits : preserves_finite_limits (𝟭 C) := {}
/-- The composition of two left exact functors is left exact. -/
def comp_preserves_finite_limits (F : C ⥤ D) (G : D ⥤ E)
[preserves_finite_limits F] [preserves_finite_limits G] : preserves_finite_limits (F ⋙ G) :=
⟨λ _ _ _, by { resetI, apply_instance }⟩
/--
A functor is said to preserve finite colimits, if it preserves all colimits of
shape `J`, where `J : Type` is a finite category.
-/
class preserves_finite_colimits (F : C ⥤ D) :=
(preserves_finite_colimits : Π (J : Type) [small_category J] [fin_category J],
preserves_colimits_of_shape J F . tactic.apply_instance)
attribute [instance] preserves_finite_colimits.preserves_finite_colimits
/-- Preserving finite limits also implies preserving limits over finite shapes in higher universes,
though through a noncomputable instance. -/
@[priority 100]
noncomputable instance preserves_colimits_of_shape_of_preserves_finite_colimits (F : C ⥤ D)
[preserves_finite_colimits F] (J : Type w) [small_category J] [fin_category J] :
preserves_colimits_of_shape J F :=
by apply preserves_colimits_of_shape_of_equiv (fin_category.equiv_as_type J)
@[priority 100]
noncomputable instance preserves_colimits.preserves_finite_colimits (F : C ⥤ D)
[preserves_colimits_of_size.{w w₂} F] : preserves_finite_colimits F :=
⟨λ J sJ fJ,
begin
haveI := preserves_smallest_colimits_of_preserves_colimits F,
exact preserves_colimits_of_shape_of_equiv (fin_category.equiv_as_type J) F,
end⟩
/-- We can always derive `preserves_finite_limits C` by showing that we are preserving limits at an
arbitrary universe. -/
def preserves_finite_colimits_of_preserves_finite_colimits_of_size (F : C ⥤ D)
(h : ∀ (J : Type w) {𝒥 : small_category J} (hJ : @fin_category J 𝒥),
by { resetI, exact preserves_colimits_of_shape J F }) :
preserves_finite_colimits F :=
⟨λ J hJ hhJ,
begin
resetI,
letI : category.{w w} (ulift_hom.{w} (ulift.{w 0} J)),
{ apply ulift_hom.category.{0}, exact category_theory.ulift_category J },
haveI := h (ulift_hom.{w} (ulift.{w} J)) category_theory.fin_category_ulift,
exact preserves_colimits_of_shape_of_equiv (ulift_hom_ulift_category.equiv.{w w} J).symm F
end⟩
instance id_preserves_finite_colimits : preserves_finite_colimits (𝟭 C) := {}
/-- The composition of two right exact functors is right exact. -/
def comp_preserves_finite_colimits (F : C ⥤ D) (G : D ⥤ E)
[preserves_finite_colimits F] [preserves_finite_colimits G] :
preserves_finite_colimits (F ⋙ G) :=
⟨λ _ _ _, by { resetI, apply_instance }⟩
end category_theory.limits
|
62893b88d0c44ca09b4da1011da290dc29f1744c | 9a0b1b3a653ea926b03d1495fef64da1d14b3174 | /tidy/rewrite_search/discovery/collect.lean | 5421ba6dce7bcf3c8726f5fad2425c81eaa55868 | [
"Apache-2.0"
] | permissive | khoek/mathlib-tidy | 8623b27b4e04e7d598164e7eaf248610d58f768b | 866afa6ab597c47f1b72e8fe2b82b97fff5b980f | refs/heads/master | 1,585,598,975,772 | 1,538,659,544,000 | 1,538,659,544,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,967 | lean | import tidy.lib.env
import tidy.rewrite_search.core.shared
import .types
import .screening
import .bundle
import .suggest
import .collector
open tactic
open tidy.rewrite_search
universe u
namespace tidy.rewrite_search.discovery
-- TODO trace only when we have success.
-- TODO add configurable "persistence"
meta def default_collectors : list collector := [try_bundles, try_everything]
/-- Bundle names are names like ```logic``. -/
meta def collect (use_suggest_annotations : bool) (p : persistence) (suggested_bundle_names : list name) (extra_names : list name) : tactic (progress × list (expr × bool)) := do
n_bs ← suggested_bundle_names.mmap get_bundle,
i_bs ← if use_suggest_annotations then get_suggested_bundle_idents >>= list.mmap lookup_bundle else pure [],
let bs := n_bs ++ i_bs,
exprs ← collect_bundle_members bs >>= load_names,
extra_exprs ← load_names extra_names,
extra_exprs.mmap assert_acceptable_lemma,
return (⟨p, bs⟩, rewrite_list_from_lemmas $ exprs ++ extra_exprs)
-- Currently, we guarentee that each rewrite we return gives some expression the environment
-- hasn't seen before.
meta def collect_more_using : list collector → config → progress → list expr → tactic (progress × list (expr × bool))
| [] conf p _ := do
if conf.trace_discovery ∧ ¬(p.persistence = persistence.speedy) then
discovery_trace "Giving up." ff
else skip,
return (p, [])
| (fn :: rest) conf p sample := do
(p, rws) ← fn conf p sample,
if rws.length = 0 then
collect_more_using rest conf p sample
else
return (p, rws)
meta def collect_more (conf : config) (prog : progress) (sample : list expr) : tactic (progress × list (expr × bool)) := do
if conf.trace_discovery ∧ ¬(prog.persistence = discovery.persistence.speedy) then
tactic.trace "rewrite_search is getting desperate...\n"
else skip,
collect_more_using default_collectors conf prog sample
end tidy.rewrite_search.discovery |
bb15af19cbb72f68a59d5c7fc061b767fc541a29 | 66a6486e19b71391cc438afee5f081a4257564ec | /algebra/spectral_sequence.hlean | 5240c7de5fd40f7c1e5dc53384de5b9f8afa5460 | [
"Apache-2.0"
] | permissive | spiceghello/Spectral | c8ccd1e32d4b6a9132ccee20fcba44b477cd0331 | 20023aa3de27c22ab9f9b4a177f5a1efdec2b19f | refs/heads/master | 1,611,263,374,078 | 1,523,349,717,000 | 1,523,349,717,000 | 92,312,239 | 0 | 0 | null | 1,495,642,470,000 | 1,495,642,470,000 | null | UTF-8 | Lean | false | false | 39,340 | hlean | /- Exact couples of graded (left-) R-modules. This file includes:
- Constructing exact couples from sequences of maps
- Deriving an exact couple
- The convergence theorem for exact couples -/
-- Author: Floris van Doorn
import .graded ..spectrum.basic .product_group
open algebra is_trunc left_module is_equiv equiv eq function nat sigma set_quotient
/- exact couples -/
namespace left_module
section
/- move to left_module -/
structure is_built_from.{u v w} {R : Ring} (D : LeftModule.{u v} R)
(E : ℕ → LeftModule.{u w} R) : Type.{max u (v+1) w} :=
(part : ℕ → LeftModule.{u v} R)
(ses : Πn, short_exact_mod (E n) (part n) (part (n+1)))
(e0 : part 0 ≃lm D)
(n₀ : ℕ)
(HD' : Π(s : ℕ), n₀ ≤ s → is_contr (part s))
open is_built_from
universe variables u v w
variables {R : Ring.{u}} {D D' : LeftModule.{u v} R} {E E' : ℕ → LeftModule.{u w} R}
definition is_built_from_shift (H : is_built_from D E) :
is_built_from (part H 1) (λn, E (n+1)) :=
is_built_from.mk (λn, part H (n+1)) (λn, ses H (n+1)) isomorphism.rfl (pred (n₀ H))
(λs Hle, HD' H _ (le_succ_of_pred_le Hle))
definition isomorphism_of_is_contr_part (H : is_built_from D E) (n : ℕ) (HE : is_contr (E n)) :
part H n ≃lm part H (n+1) :=
isomorphism_of_is_contr_left (ses H n) HE
definition is_contr_submodules (H : is_built_from D E) (HD : is_contr D) (n : ℕ) :
is_contr (part H n) :=
begin
induction n with n IH,
{ exact is_trunc_equiv_closed_rev -2 (equiv_of_isomorphism (e0 H)) },
{ exact is_contr_right_of_short_exact_mod (ses H n) IH }
end
definition is_contr_quotients (H : is_built_from D E) (HD : is_contr D) (n : ℕ) :
is_contr (E n) :=
begin
apply is_contr_left_of_short_exact_mod (ses H n),
exact is_contr_submodules H HD n
end
definition is_contr_total (H : is_built_from D E) (HE : Πn, is_contr (E n)) : is_contr D :=
have is_contr (part H 0), from
nat.rec_down (λn, is_contr (part H n)) _ (HD' H _ !le.refl)
(λn H2, is_contr_middle_of_short_exact_mod (ses H n) (HE n) H2),
is_contr_equiv_closed (equiv_of_isomorphism (e0 H))
definition is_built_from_isomorphism (e : D ≃lm D') (f : Πn, E n ≃lm E' n)
(H : is_built_from D E) : is_built_from D' E' :=
⦃is_built_from, H, e0 := e0 H ⬝lm e,
ses := λn, short_exact_mod_isomorphism (f n)⁻¹ˡᵐ isomorphism.rfl isomorphism.rfl (ses H n)⦄
definition is_built_from_isomorphism_left (e : D ≃lm D') (H : is_built_from D E) :
is_built_from D' E :=
⦃is_built_from, H, e0 := e0 H ⬝lm e⦄
definition isomorphism_zero_of_is_built_from (H : is_built_from D E) (p : n₀ H = 1) : E 0 ≃lm D :=
isomorphism_of_is_contr_right (ses H 0) (HD' H 1 (le_of_eq p)) ⬝lm e0 H
end
structure exact_couple (R : Ring) (I : Set) : Type :=
(D E : graded_module R I)
(i : D →gm D) (j : D →gm E) (k : E →gm D)
(ij : is_exact_gmod i j)
(jk : is_exact_gmod j k)
(ki : is_exact_gmod k i)
open exact_couple
definition exact_couple_reindex [constructor] {R : Ring} {I J : Set} (e : J ≃ I)
(X : exact_couple R I) : exact_couple R J :=
⦃exact_couple, D := λy, D X (e y), E := λy, E X (e y),
i := graded_hom_reindex e (i X), j := graded_hom_reindex e (j X),
k := graded_hom_reindex e (k X), ij := is_exact_gmod_reindex e (ij X),
jk := is_exact_gmod_reindex e (jk X), ki := is_exact_gmod_reindex e (ki X)⦄
namespace derived_couple
section
parameters {R : Ring} {I : Set} (X : exact_couple R I)
local abbreviation D := D X
local abbreviation E := E X
local abbreviation i := i X
local abbreviation j := j X
local abbreviation k := k X
local abbreviation ij := ij X
local abbreviation jk := jk X
local abbreviation ki := ki X
definition d : E →gm E := j ∘gm k
definition D' : graded_module R I := graded_image i
definition E' : graded_module R I := graded_homology d d
definition is_contr_E' {x : I} (H : is_contr (E x)) : is_contr (E' x) :=
!is_contr_homology
definition is_contr_D' {x : I} (H : is_contr (D x)) : is_contr (D' x) :=
!is_contr_image_module
definition E'_isomorphism {x : I} (H1 : is_contr (E ((deg d)⁻¹ᵉ x)))
(H2 : is_contr (E (deg d x))) : E' x ≃lm E x :=
@(homology_isomorphism _ _) H1 H2
definition i' : D' →gm D' :=
graded_image_lift i ∘gm graded_submodule_incl (λx, image (i ← x))
lemma is_surjective_i' {x y : I} (p : deg i' x = y)
(H : Π⦃z⦄ (q : deg i z = x), is_surjective (i ↘ q)) : is_surjective (i' ↘ p) :=
begin
apply is_surjective_graded_hom_compose,
{ intro y q, apply is_surjective_graded_image_lift },
{ intro y q, apply is_surjective_of_is_equiv,
induction q,
exact to_is_equiv (equiv_of_isomorphism (image_module_isomorphism (i ← x) (H _)))
}
end
lemma j_lemma1 ⦃x : I⦄ (m : D x) : d ((deg j) x) (j x m) = 0 :=
begin
rewrite [graded_hom_compose_fn,↑d,graded_hom_compose_fn],
refine ap (graded_hom_fn j (deg k (deg j x))) _ ⬝
!to_respect_zero,
exact compose_constant.elim (gmod_im_in_ker (jk)) x m
end
lemma j_lemma2 : Π⦃x : I⦄ ⦃m : D x⦄ (p : i x m = 0),
(graded_homology_intro _ _ ∘gm graded_hom_lift _ j j_lemma1) x m = 0 :> E' _ :=
begin
have Π⦃x y : I⦄ (q : deg k x = y) (r : deg d x = deg j y)
(s : ap (deg j) q = r) ⦃m : D y⦄ (p : i y m = 0), image (d ↘ r) (j y m),
begin
intros, induction s, induction q,
note m_in_im_k := is_exact.ker_in_im (ki idp _) _ p,
induction m_in_im_k with e q,
induction q,
apply image.mk e idp
end,
have Π⦃x : I⦄ ⦃m : D x⦄ (p : i x m = 0), image (d ← (deg j x)) (j x m),
begin
intros,
refine this _ _ _ p,
exact to_right_inv (deg k) _ ⬝ to_left_inv (deg j) x,
apply is_set.elim
-- rewrite [ap_con, -adj],
end,
intros,
rewrite [graded_hom_compose_fn],
exact @quotient_map_eq_zero _ _ _ _ _ (this p)
end
definition j' : D' →gm E' :=
graded_image_elim (graded_homology_intro d d ∘gm graded_hom_lift _ j j_lemma1) j_lemma2
-- degree deg j - deg i
lemma k_lemma1 ⦃x : I⦄ (m : E x) (p : d x m = 0) : image (i ← (deg k x)) (k x m) :=
gmod_ker_in_im (exact_couple.ij X) (k x m) p
definition k₂ : graded_kernel d →gm D' := graded_submodule_functor k k_lemma1
lemma k_lemma2 ⦃x : I⦄ (m : E x) (h₁ : lm_kernel (d x) m) (h₂ : image (d ← x) m) :
k₂ x ⟨m, h₁⟩ = 0 :=
begin
assert H₁ : Π⦃x' y z w : I⦄ (p : deg k x' = y) (q : deg j y = z) (r : deg k z = w) (n : E x'),
k ↘ r (j ↘ q (k ↘ p n)) = 0,
{ intros, exact gmod_im_in_ker (exact_couple.jk X) q r (k ↘ p n) },
induction h₂ with n p,
assert H₂ : k x m = 0,
{ rewrite [-p], refine ap (k x) (graded_hom_compose_fn_out j k x n) ⬝ _, apply H₁ },
exact subtype_eq H₂
end
definition k' : E' →gm D' :=
@graded_quotient_elim _ _ _ _ _ _ k₂
(by intro x m h; cases m with [m1, m2]; exact k_lemma2 m1 m2 h)
open sigma.ops
definition i'_eq ⦃x : I⦄ (m : D x) (h : image (i ← x) m) : (i' x ⟨m, h⟩).1 = i x m :=
by reflexivity
definition k'_eq ⦃x : I⦄ (m : E x) (h : d x m = 0) : (k' x (class_of ⟨m, h⟩)).1 = k x m :=
by reflexivity
lemma j'_eq {x : I} (m : D x) : j' ↘ (ap (deg j) (left_inv (deg i) x)) (graded_image_lift i x m) =
class_of (graded_hom_lift _ j proof j_lemma1 qed x m) :=
begin
refine graded_image_elim_destruct _ _ _ idp _ m,
apply is_set.elim,
end
definition deg_i' : deg i' ~ deg i := by reflexivity
definition deg_j' : deg j' ~ deg j ∘ (deg i)⁻¹ := by reflexivity
definition deg_k' : deg k' ~ deg k := by reflexivity
open group
set_option pp.coercions true
lemma i'j' : is_exact_gmod i' j' :=
begin
intro x, refine equiv_rect (deg i) _ _,
intros y z p q, revert z q x p,
refine eq.rec_grading (deg i ⬝e deg j') (deg j) (ap (deg j) (left_inv (deg i) y)) _,
intro x, revert y, refine eq.rec_equiv (deg i) _,
apply transport (λx, is_exact_mod x _) (idpath (i' x)),
apply transport (λx, is_exact_mod _ (j' ↘ (ap (deg j) (left_inv (deg i) x)))) (idpath x),
apply is_exact_mod.mk,
{ revert x, refine equiv_rect (deg i) _ _, intro x,
refine graded_image.rec _, intro m,
transitivity j' ↘ _ (graded_image_lift i (deg i x) (i x m)),
apply ap (λx, j' ↘ _ x), apply subtype_eq, apply i'_eq,
refine !j'_eq ⬝ _,
apply ap class_of, apply subtype_eq, exact is_exact.im_in_ker (exact_couple.ij X idp idp) m },
{ revert x, refine equiv_rect (deg k) _ _, intro x,
refine graded_image.rec _, intro m p,
assert q : graded_homology_intro d d (deg j (deg k x))
(graded_hom_lift _ j j_lemma1 (deg k x) m) = 0,
{ exact !j'_eq⁻¹ ⬝ p },
note q2 := image_of_graded_homology_intro_eq_zero idp (graded_hom_lift _ j _ _ m) q,
induction q2 with n r,
assert s : j (deg k x) (m - k x n) = 0,
{ refine respect_sub (j (deg k x)) m (k x n) ⬝ _,
refine ap (sub _) r ⬝ _, apply sub_self },
assert t : trunctype.carrier (image (i ← (deg k x)) (m - k x n)),
{ exact is_exact.ker_in_im (exact_couple.ij X _ _) _ s },
refine image.mk ⟨m - k x n, t⟩ _,
apply subtype_eq, refine !i'_eq ⬝ !to_respect_sub ⬝ _,
refine ap (@sub (D (deg i (deg k x))) _ _) _ ⬝ @sub_zero _ _ _,
apply is_exact.im_in_ker (exact_couple.ki X _ _) }
end
lemma j'k' : is_exact_gmod j' k' :=
begin
refine equiv_rect (deg i) _ _,
intros x y z p, revert y p z,
refine eq.rec_grading (deg i ⬝e deg j') (deg j) (ap (deg j) (left_inv (deg i) x)) _,
intro z q, induction q,
apply is_exact_mod.mk,
{ refine graded_image.rec _, intro m,
refine ap (k' _) (j'_eq m) ⬝ _,
apply subtype_eq,
refine k'_eq _ _ ⬝ _,
exact is_exact.im_in_ker (exact_couple.jk X idp idp) m },
{ intro m p, induction m using set_quotient.rec_prop with m,
induction m with m h, note q := (k'_eq m h)⁻¹ ⬝ ap pr1 p,
induction is_exact.ker_in_im (exact_couple.jk X idp idp) m q with n r,
apply image.mk (graded_image_lift i x n),
refine !j'_eq ⬝ _,
apply ap class_of, apply subtype_eq, exact r }
end
lemma k'i' : is_exact_gmod k' i' :=
begin
apply is_exact_gmod.mk,
{ intro x m, induction m using set_quotient.rec_prop with m,
cases m with m p, apply subtype_eq,
change i (deg k x) (k x m) = 0,
exact is_exact.im_in_ker (exact_couple.ki X idp idp) m },
{ intro x m, induction m with m h, intro p,
have i (deg k x) m = 0, from ap pr1 p,
induction is_exact.ker_in_im (exact_couple.ki X idp idp) m this with n q,
have j (deg k x) m = 0, from @(is_exact.im_in_ker2 (exact_couple.ij X _ _)) m h,
have d x n = 0, from ap (j (deg k x)) q ⬝ this,
exact image.mk (class_of ⟨n, this⟩) (subtype_eq q) }
end
end
end derived_couple
open derived_couple
definition derived_couple [constructor] {R : Ring} {I : Set}
(X : exact_couple R I) : exact_couple R I :=
⦃exact_couple, D := D' X, E := E' X, i := i' X, j := j' X, k := k' X,
ij := i'j' X, jk := j'k' X, ki := k'i' X⦄
/- if an exact couple is bounded, we can prove the convergence theorem for it -/
structure is_bounded {R : Ring} {I : Set} (X : exact_couple R I) : Type :=
mk' :: (B B' : I → ℕ)
(Dub : Π⦃x y⦄ ⦃s : ℕ⦄, (deg (i X))^[s] x = y → B x ≤ s → is_contr (D X y))
(Dlb : Π⦃x y z⦄ ⦃s : ℕ⦄ (p : deg (i X) x = y), (deg (i X))^[s] y = z → B' z ≤ s → is_surjective (i X ↘ p))
(Elb : Π⦃x y⦄ ⦃s : ℕ⦄, (deg (i X))⁻¹ᵉ^[s] x = y → B x ≤ s → is_contr (E X y))
(deg_ik_commute : hsquare (deg (k X)) (deg (k X)) (deg (i X)) (deg (i X)))
(deg_ij_commute : hsquare (deg (j X)) (deg (j X)) (deg (i X)) (deg (i X)))
/- Note: Elb proves Dlb for some bound B', but we want tight control over when B' = 0 -/
protected definition is_bounded.mk [constructor] {R : Ring} {I : Set} {X : exact_couple R I}
(B B' B'' : I → ℕ)
(Dub : Π⦃x : I⦄ ⦃s : ℕ⦄, B x ≤ s → is_contr (D X ((deg (i X))^[s] x)))
(Dlb : Π⦃x : I⦄ ⦃s : ℕ⦄, B' x ≤ s → is_surjective (i X (((deg (i X))⁻¹ᵉ^[s + 1] x))))
(Elb : Π⦃x : I⦄ ⦃s : ℕ⦄, B'' x ≤ s → is_contr (E X ((deg (i X))⁻¹ᵉ^[s] x)))
(deg_ik_commute : hsquare (deg (k X)) (deg (k X)) (deg (i X)) (deg (i X)))
(deg_ij_commute : hsquare (deg (j X)) (deg (j X)) (deg (i X)) (deg (i X))) : is_bounded X :=
begin
apply is_bounded.mk' (λx, max (B x) (B'' x)) B',
{ intro x y s p h, induction p, exact Dub (le.trans !le_max_left h) },
{ exact abstract begin intro x y z s p q h, induction p, induction q,
refine transport (λx, is_surjective (i X x)) _ (Dlb h),
rewrite [-iterate_succ], apply iterate_left_inv end end },
{ intro x y s p h, induction p, exact Elb (le.trans !le_max_right h) },
{ assumption },
{ assumption }
end
open is_bounded
definition is_bounded_reindex [constructor] {R : Ring} {I J : Set} (e : J ≃ I)
{X : exact_couple R I} (HH : is_bounded X) : is_bounded (exact_couple_reindex e X) :=
begin
apply is_bounded.mk' (B HH ∘ e) (B' HH ∘ e),
{ intros x y s p h, refine Dub HH _ h,
refine (iterate_hsquare e _ s x)⁻¹ ⬝ ap e p, intro x, exact to_right_inv e _ },
{ intros x y z s p q h, refine Dlb HH _ _ h,
refine (iterate_hsquare e _ s y)⁻¹ ⬝ ap e q, intro x, exact to_right_inv e _ },
{ intro x y s p h, refine Elb HH _ h,
refine (iterate_hsquare e _ s x)⁻¹ ⬝ ap e p, intro x, exact to_right_inv e _ },
{ intro y, exact ap e⁻¹ᵉ (ap (deg (i X)) (to_right_inv e _) ⬝
deg_ik_commute HH (e y) ⬝ ap (deg (k X)) (to_right_inv e _)⁻¹) },
{ intro y, exact ap e⁻¹ᵉ (ap (deg (i X)) (to_right_inv e _) ⬝
deg_ij_commute HH (e y) ⬝ ap (deg (j X)) (to_right_inv e _)⁻¹) }
end
namespace convergence_theorem
section
parameters {R : Ring} {I : Set} (X : exact_couple R I) (HH : is_bounded X)
local abbreviation B := B HH
local abbreviation B' := B' HH
local abbreviation Dub := Dub HH
local abbreviation Dlb := Dlb HH
local abbreviation Elb := Elb HH
local abbreviation deg_ik_commute := deg_ik_commute HH
local abbreviation deg_ij_commute := deg_ij_commute HH
/- We start counting pages at 0, which corresponds to what is usually called the second page -/
definition page (r : ℕ) : exact_couple R I :=
iterate derived_couple r X
definition is_contr_E (r : ℕ) (x : I) (h : is_contr (E X x)) :
is_contr (E (page r) x) :=
by induction r with r IH; exact h; exact is_contr_E' (page r) IH
definition is_contr_D (r : ℕ) (x : I) (h : is_contr (D X x)) :
is_contr (D (page r) x) :=
by induction r with r IH; exact h; exact is_contr_D' (page r) IH
definition deg_i (r : ℕ) : deg (i (page r)) ~ deg (i X) :=
begin
induction r with r IH,
{ reflexivity },
{ exact IH }
end
definition deg_k (r : ℕ) : deg (k (page r)) ~ deg (k X) :=
begin
induction r with r IH,
{ reflexivity },
{ exact IH }
end
definition deg_j (r : ℕ) :
deg (j (page r)) ~ deg (j X) ∘ iterate (deg (i X))⁻¹ r :=
begin
induction r with r IH,
{ reflexivity },
{ refine hwhisker_left (deg (j (page r)))
(to_inv_homotopy_inv (deg_i r)) ⬝hty _,
refine hwhisker_right _ IH ⬝hty _,
apply hwhisker_left, symmetry, apply iterate_succ }
end
definition deg_j_inv (r : ℕ) :
(deg (j (page r)))⁻¹ ~ iterate (deg (i X)) r ∘ (deg (j X))⁻¹ :=
have H : deg (j (page r)) ~ iterate_equiv (deg (i X))⁻¹ᵉ r ⬝e deg (j X), from deg_j r,
λx, to_inv_homotopy_inv H x ⬝ iterate_inv (deg (i X))⁻¹ᵉ r ((deg (j X))⁻¹ x)
definition deg_d (r : ℕ) :
deg (d (page r)) ~ deg (j X) ∘ iterate (deg (i X))⁻¹ r ∘ deg (k X) :=
compose2 (deg_j r) (deg_k r)
definition deg_d_inv (r : ℕ) :
(deg (d (page r)))⁻¹ ~ (deg (k X))⁻¹ ∘ iterate (deg (i X)) r ∘ (deg (j X))⁻¹ :=
compose2 (to_inv_homotopy_inv (deg_k r)) (deg_j_inv r)
definition E_isomorphism' {x : I} {r₁ r₂ : ℕ} (H : r₁ ≤ r₂)
(H1 : Π⦃r⦄, r₁ ≤ r → r < r₂ → is_contr (E X ((deg (d (page r)))⁻¹ᵉ x)))
(H2 : Π⦃r⦄, r₁ ≤ r → r < r₂ → is_contr (E X (deg (d (page r)) x))) :
E (page r₂) x ≃lm E (page r₁) x :=
begin
assert H2 : Π⦃r⦄, r₁ ≤ r → r ≤ r₂ → E (page r) x ≃lm E (page r₁) x,
{ intro r Hr₁ Hr₂,
induction Hr₁ with r Hr₁ IH, reflexivity,
let Hr₂' := le_of_succ_le Hr₂,
exact E'_isomorphism (page r) (is_contr_E r _ (H1 Hr₁ Hr₂)) (is_contr_E r _ (H2 Hr₁ Hr₂))
⬝lm IH Hr₂' },
exact H2 H (le.refl _)
end
definition E_isomorphism0' {x : I} {r : ℕ}
(H1 : Πr, is_contr (E X ((deg (d (page r)))⁻¹ᵉ x)))
(H2 : Πr, is_contr (E X (deg (d (page r)) x))) : E (page r) x ≃lm E X x :=
E_isomorphism' (zero_le r) _ _
parameter {X}
definition deg_iterate_ik_commute (n : ℕ) :
hsquare (deg (k X)) (deg (k X)) ((deg (i X))^[n]) ((deg (i X))^[n]) :=
iterate_commute n deg_ik_commute
definition deg_iterate_ij_commute (n : ℕ) :
hsquare (deg (j X)) (deg (j X)) ((deg (i X))⁻¹ᵉ^[n]) ((deg (i X))⁻¹ᵉ^[n]) :=
iterate_commute n (hvinverse deg_ij_commute)
definition B2 (x : I) : ℕ := max (B (deg (k X) x)) (B ((deg (j X))⁻¹ x))
definition Eub ⦃x y : I⦄ ⦃s : ℕ⦄ (p : (deg (i X))^[s] x = y) (h : B2 x ≤ s) :
is_contr (E X y) :=
begin
induction p,
refine @(is_contr_middle_of_is_exact (exact_couple.jk X (right_inv (deg (j X)) _) idp)) _ _ _,
exact Dub (iterate_commute s (hhinverse deg_ij_commute) x) (le.trans !le_max_right h),
exact Dub !deg_iterate_ik_commute (le.trans !le_max_left h)
end
definition B3 (x : I) : ℕ :=
max (B (deg (j X) (deg (k X) x))) (B2 ((deg (k X))⁻¹ ((deg (j X))⁻¹ x)))
definition Estable {x : I} {r : ℕ} (H : B3 x ≤ r) :
E (page (r + 1)) x ≃lm E (page r) x :=
begin
change homology (d (page r) x) (d (page r) ← x) ≃lm E (page r) x,
apply homology_isomorphism: apply is_contr_E,
exact Eub (hhinverse (deg_iterate_ik_commute r) _ ⬝ (deg_d_inv r x)⁻¹)
(le.trans !le_max_right H),
exact Elb (deg_iterate_ij_commute r _ ⬝ (deg_d r x)⁻¹)
(le.trans !le_max_left H)
end
definition is_surjective_i {x y z : I} {r s : ℕ} (H : B' z ≤ s + r)
(p : deg (i (page r)) x = y) (q : iterate (deg (i X)) s y = z) :
is_surjective (i (page r) ↘ p) :=
begin
revert x y z s H p q, induction r with r IH: intro x y z s H p q,
{ exact Dlb p q H },
{ change is_surjective (i' (page r) ↘ p),
apply is_surjective_i', intro z' q',
refine IH _ _ _ _ (le.trans H (le_of_eq (succ_add s r)⁻¹)) _ _,
refine !iterate_succ ⬝ ap ((deg (i X))^[s]) _ ⬝ q,
exact !deg_i⁻¹ ⬝ p }
end
definition Dstable {x : I} {r : ℕ} (H : B' x ≤ r) :
D (page (r + 1)) x ≃lm D (page r) x :=
begin
change image_module (i (page r) ← x) ≃lm D (page r) x,
refine image_module_isomorphism (i (page r) ← x)
(is_surjective_i (le.trans H (le_of_eq !zero_add⁻¹)) _ _),
reflexivity
end
/- the infinity pages of E and D -/
definition Einf : graded_module R I :=
λx, E (page (B3 x)) x
definition Dinf : graded_module R I :=
λx, D (page (B' x)) x
definition Einfstable {x y : I} {r : ℕ} (Hr : B3 y ≤ r) (p : x = y) : Einf y ≃lm E (page r) x :=
by symmetry; induction p; induction Hr with r Hr IH; reflexivity; exact Estable Hr ⬝lm IH
definition Dinfstable {x y : I} {r : ℕ} (Hr : B' y ≤ r) (p : x = y) : Dinf y ≃lm D (page r) x :=
by symmetry; induction p; induction Hr with r Hr IH; reflexivity; exact Dstable Hr ⬝lm IH
definition Einf_isomorphism' {x : I} (r₁ : ℕ)
(H1 : Π⦃r⦄, r₁ ≤ r → is_contr (E X ((deg (d (page r)))⁻¹ᵉ x)))
(H2 : Π⦃r⦄, r₁ ≤ r → is_contr (E X (deg (d (page r)) x))) :
Einf x ≃lm E (page r₁) x :=
begin
cases le.total r₁ (B3 x) with Hr Hr,
exact E_isomorphism' Hr (λr Hr₁ Hr₂, H1 Hr₁) (λr Hr₁ Hr₂, H2 Hr₁),
exact Einfstable Hr idp
end
definition Einf_isomorphism0' {x : I}
(H1 : Π⦃r⦄, is_contr (E X ((deg (d (page r)))⁻¹ᵉ x)))
(H2 : Π⦃r⦄, is_contr (E X (deg (d (page r)) x))) :
Einf x ≃lm E X x :=
E_isomorphism0' _ _
parameters (x : I)
definition r (n : ℕ) : ℕ :=
max (max (B (deg (j X) (deg (k X) x)) + n + 1) (B3 ((deg (i X))^[n] x)))
(max (B' (deg (k X) ((deg (i X))^[n] x)))
(max (B' (deg (k X) ((deg (i X))^[n+1] x))) (B ((deg (j X))⁻¹ ((deg (i X))^[n] x)))))
lemma rb0 (n : ℕ) : r n ≥ n + 1 :=
ge.trans !le_max_left (ge.trans !le_max_left !le_add_left)
lemma rb1 (n : ℕ) : B (deg (j X) (deg (k X) x)) ≤ r n - (n + 1) :=
nat.le_sub_of_add_le (le.trans !le_max_left !le_max_left)
lemma rb2 (n : ℕ) : B3 ((deg (i X))^[n] x) ≤ r n :=
le.trans !le_max_right !le_max_left
lemma rb3 (n : ℕ) : B' (deg (k X) ((deg (i X))^[n] x)) ≤ r n :=
le.trans !le_max_left !le_max_right
lemma rb4 (n : ℕ) : B' (deg (k X) ((deg (i X))^[n+1] x)) ≤ r n :=
le.trans (le.trans !le_max_left !le_max_right) !le_max_right
lemma rb5 (n : ℕ) : B ((deg (j X))⁻¹ ((deg (i X))^[n] x)) ≤ r n :=
le.trans (le.trans !le_max_right !le_max_right) !le_max_right
definition Einfdiag : graded_module R ℕ :=
λn, Einf ((deg (i X))^[n] x)
definition Dinfdiag : graded_module R ℕ :=
λn, Dinf (deg (k X) ((deg (i X))^[n] x))
definition short_exact_mod_page_r (n : ℕ) : short_exact_mod
(E (page (r n)) ((deg (i X))^[n] x))
(D (page (r n)) (deg (k (page (r n))) ((deg (i X))^[n] x)))
(D (page (r n)) (deg (i (page (r n))) (deg (k (page (r n))) ((deg (i X))^[n] x)))) :=
begin
fapply short_exact_mod_of_is_exact,
{ exact j (page (r n)) ← ((deg (i X))^[n] x) },
{ exact k (page (r n)) ((deg (i X))^[n] x) },
{ exact i (page (r n)) (deg (k (page (r n))) ((deg (i X))^[n] x)) },
{ exact j (page (r n)) _ },
{ apply is_contr_D, refine Dub !deg_j_inv⁻¹ (rb5 n) },
{ apply is_contr_E, refine Elb _ (rb1 n),
refine !deg_iterate_ij_commute ⬝ _,
refine ap (deg (j X)) _ ⬝ !deg_j⁻¹,
refine iterate_sub _ !rb0 _ ⬝ _, apply ap (_^[r n]),
exact ap (deg (i X)) (!deg_iterate_ik_commute ⬝ !deg_k⁻¹) ⬝ !deg_i⁻¹ },
{ apply jk (page (r n)) },
{ apply ki (page (r n)) },
{ apply ij (page (r n)) }
end
definition short_exact_mod_infpage (n : ℕ) :
short_exact_mod (Einfdiag n) (Dinfdiag n) (Dinfdiag (n+1)) :=
begin
refine short_exact_mod_isomorphism _ _ _ (short_exact_mod_page_r n),
{ exact Einfstable !rb2 idp },
{ exact Dinfstable !rb3 !deg_k },
{ exact Dinfstable !rb4 (!deg_i ⬝ ap (deg (i X)) !deg_k ⬝ !deg_ik_commute) }
end
definition Dinfdiag0 (bound_zero : B' (deg (k X) x) = 0) : Dinfdiag 0 ≃lm D X (deg (k X) x) :=
Dinfstable (le_of_eq bound_zero) idp
lemma Dinfdiag_stable {s : ℕ} (h : B (deg (k X) x) ≤ s) : is_contr (Dinfdiag s) :=
is_contr_D _ _ (Dub !deg_iterate_ik_commute h)
/- some useful immediate properties -/
definition short_exact_mod_infpage0 (bound_zero : B' (deg (k X) x) = 0) :
short_exact_mod (Einfdiag 0) (D X (deg (k X) x)) (Dinfdiag 1) :=
begin
refine short_exact_mod_isomorphism _ _ _ (short_exact_mod_infpage 0),
{ reflexivity },
{ exact (Dinfdiag0 bound_zero)⁻¹ˡᵐ },
{ reflexivity }
end
/- the convergence theorem is the following result -/
definition is_built_from_infpage (bound_zero : B' (deg (k X) x) = 0) :
is_built_from (D X (deg (k X) x)) Einfdiag :=
is_built_from.mk Dinfdiag short_exact_mod_infpage (Dinfdiag0 bound_zero) (B (deg (k X) x))
(λs, Dinfdiag_stable)
end
end convergence_theorem
open int group prod convergence_theorem prod.ops
definition Z2 [constructor] : Set := gℤ ×g gℤ
/- TODO: redefine/generalize converges_to so that it supports the usual indexing on ℤ × ℤ -/
structure converges_to.{u v w} {R : Ring} (E' : gℤ → gℤ → LeftModule.{u v} R)
(Dinf : gℤ → LeftModule.{u w} R) : Type.{max u (v+1) (w+1)} :=
(X : exact_couple.{u 0 w v} R Z2)
(HH : is_bounded X)
(s₀ : gℤ → gℤ)
(HB : Π(n : gℤ), is_bounded.B' HH (deg (k X) (n, s₀ n)) = 0)
(e : Π(x : Z2), exact_couple.E X x ≃lm E' x.1 x.2)
(f : Π(n : gℤ), exact_couple.D X (deg (k X) (n, s₀ n)) ≃lm Dinf n)
(deg_d1 : ℕ → gℤ) (deg_d2 : ℕ → gℤ)
(deg_d_eq : Π(r : ℕ) (n s : gℤ), deg (d (page X r)) (n, s) = (n + deg_d1 r, s + deg_d2 r))
structure converging_spectral_sequence.{u v w} {R : Ring} (E' : gℤ → gℤ → LeftModule.{u v} R)
(Dinf : gℤ → LeftModule.{u w} R) : Type.{max u (v+1) (w+1)} :=
(E : ℕ → graded_module.{u 0 v} R Z2)
(d : Π(n : ℕ), E n →gm E n)
(α : Π(n : ℕ) (x : Z2), E (n+1) x ≃lm graded_homology (d n) (d n) x)
(e : Π(n : ℕ) (x : Z2), E 0 x ≃lm E' x.1 x.2)
(s₀ : Z2 → ℕ)
(f : Π{n : ℕ} {x : Z2} (h : s₀ x ≤ n), E (s₀ x) x ≃lm E n x)
(HDinf : Π(n : gℤ), is_built_from (Dinf n) (λ(k : ℕ), (λx, E (s₀ x) x) (k, n - k)))
infix ` ⟹ `:25 := converges_to
definition converges_to_g [reducible] (E' : gℤ → gℤ → AbGroup) (Dinf : gℤ → AbGroup) : Type :=
(λn s, LeftModule_int_of_AbGroup (E' n s)) ⟹ (λn, LeftModule_int_of_AbGroup (Dinf n))
infix ` ⟹ᵍ `:25 := converges_to_g
section
open converges_to
parameters {R : Ring} {E' : gℤ → gℤ → LeftModule R} {Dinf : gℤ → LeftModule R} (c : E' ⟹ Dinf)
local abbreviation X := X c
local abbreviation i := i X
local abbreviation HH := HH c
local abbreviation s₀ := s₀ c
local abbreviation Dinfdiag (n : gℤ) (k : ℕ) := Dinfdiag HH (n, s₀ n) k
local abbreviation Einfdiag (n : gℤ) (k : ℕ) := Einfdiag HH (n, s₀ n) k
definition deg_d_inv_eq (r : ℕ) (n s : gℤ) :
(deg (d (page X r)))⁻¹ᵉ (n, s) = (n - deg_d1 c r, s - deg_d2 c r) :=
inv_eq_of_eq (!deg_d_eq ⬝ prod_eq !sub_add_cancel !sub_add_cancel)⁻¹
definition converges_to_isomorphism {E'' : gℤ → gℤ → LeftModule R} {Dinf' : graded_module R gℤ}
(e' : Πn s, E' n s ≃lm E'' n s) (f' : Πn, Dinf n ≃lm Dinf' n) : E'' ⟹ Dinf' :=
converges_to.mk X HH s₀ (HB c)
begin intro x, induction x with n s, exact e c (n, s) ⬝lm e' n s end
(λn, f c n ⬝lm f' n)
(deg_d1 c) (deg_d2 c) (λr n s, deg_d_eq c r n s)
/- definition converges_to_reindex {E'' : gℤ → gℤ → LeftModule R} {Dinf' : graded_module R gℤ}
(i : gℤ ×g gℤ ≃ gℤ × gℤ) (e' : Πp q, E' p q ≃lm E'' (i (p, q)).1 (i (p, q)).2)
(i2 : gℤ ≃ gℤ) (f' : Πn, Dinf n ≃lm Dinf' (i2 n)) :
(λp q, E'' p q) ⟹ λn, Dinf' n :=
converges_to.mk (exact_couple_reindex i X) (is_bounded_reindex i HH) s₀
sorry --(λn, ap (B' HH) (to_right_inv i _ ⬝ begin end) ⬝ HB c n)
sorry --begin intro x, induction x with p q, exact e c (p, q) ⬝lm e' p q end
sorry-/
/- definition converges_to_reindex_neg {E'' : gℤ → gℤ → LeftModule R} {Dinf' : graded_module R gℤ}
(e' : Πp q, E' p q ≃lm E'' (-p) (-q))
(f' : Πn, Dinf n ≃lm Dinf' (-n)) :
(λp q, E'' p q) ⟹ λn, Dinf' n :=
converges_to.mk (exact_couple_reindex (equiv_neg ×≃ equiv_neg) X) (is_bounded_reindex _ HH)
(λn, -s₀ (-n))
(λn, ap (B' HH) (begin esimp, end) ⬝ HB c n)
sorry --begin intro x, induction x with p q, exact e c (p, q) ⬝lm e' p q end
sorry-/
definition is_built_from_of_converges_to (n : ℤ) : is_built_from (Dinf n) (Einfdiag n) :=
is_built_from_isomorphism_left (f c n) (is_built_from_infpage HH (n, s₀ n) (HB c n))
/- TODO: reprove this using is_built_of -/
theorem is_contr_converges_to_precise (n : gℤ)
(H : Π(n : gℤ) (l : ℕ), is_contr (E' ((deg i)^[l] (n, s₀ n)).1 ((deg i)^[l] (n, s₀ n)).2)) :
is_contr (Dinf n) :=
begin
assert H2 : Π(l : ℕ), is_contr (Einfdiag n l),
{ intro l, apply is_contr_E,
refine @(is_trunc_equiv_closed_rev -2 (equiv_of_isomorphism (e c _))) (H n l) },
assert H3 : is_contr (Dinfdiag n 0),
{ fapply nat.rec_down (λk, is_contr (Dinfdiag n k)),
{ exact is_bounded.B HH (deg (k X) (n, s₀ n)) },
{ apply Dinfdiag_stable, reflexivity },
{ intro l H,
exact is_contr_middle_of_short_exact_mod (short_exact_mod_infpage HH (n, s₀ n) l)
(H2 l) H }},
refine @is_trunc_equiv_closed _ _ _ _ H3,
exact equiv_of_isomorphism (Dinfdiag0 HH (n, s₀ n) (HB c n) ⬝lm f c n)
end
theorem is_contr_converges_to (n : gℤ) (H : Π(n s : gℤ), is_contr (E' n s)) : is_contr (Dinf n) :=
is_contr_converges_to_precise n (λn s, !H)
definition E_isomorphism {r₁ r₂ : ℕ} {n s : gℤ} (H : r₁ ≤ r₂)
(H1 : Π⦃r⦄, r₁ ≤ r → r < r₂ → is_contr (E X (n - deg_d1 c r, s - deg_d2 c r)))
(H2 : Π⦃r⦄, r₁ ≤ r → r < r₂ → is_contr (E X (n + deg_d1 c r, s + deg_d2 c r))) :
E (page X r₂) (n, s) ≃lm E (page X r₁) (n, s) :=
E_isomorphism' X H (λr Hr₁ Hr₂, transport (is_contr ∘ E X) (deg_d_inv_eq r n s)⁻¹ᵖ (H1 Hr₁ Hr₂))
(λr Hr₁ Hr₂, transport (is_contr ∘ E X) (deg_d_eq c r n s)⁻¹ᵖ (H2 Hr₁ Hr₂))
definition E_isomorphism0 {r : ℕ} {n s : gℤ}
(H1 : Πr, is_contr (E X (n - deg_d1 c r, s - deg_d2 c r)))
(H2 : Πr, is_contr (E X (n + deg_d1 c r, s + deg_d2 c r))) :
E (page X r) (n, s) ≃lm E' n s :=
E_isomorphism (zero_le r) _ _ ⬝lm e c (n, s)
definition Einf_isomorphism (r₁ : ℕ) {n s : gℤ}
(H1 : Π⦃r⦄, r₁ ≤ r → is_contr (E X (n - deg_d1 c r, s - deg_d2 c r)))
(H2 : Π⦃r⦄, r₁ ≤ r → is_contr (E X (n + deg_d1 c r, s + deg_d2 c r))) :
Einf HH (n, s) ≃lm E (page X r₁) (n, s) :=
Einf_isomorphism' HH r₁ (λr Hr₁, transport (is_contr ∘ E X) (deg_d_inv_eq r n s)⁻¹ᵖ (H1 Hr₁))
(λr Hr₁, transport (is_contr ∘ E X) (deg_d_eq c r n s)⁻¹ᵖ (H2 Hr₁))
definition Einf_isomorphism0 {n s : gℤ}
(H1 : Π⦃r⦄, is_contr (E X (n - deg_d1 c r, s - deg_d2 c r)))
(H2 : Π⦃r⦄, is_contr (E X (n + deg_d1 c r, s + deg_d2 c r))) :
Einf HH (n, s) ≃lm E' n s :=
E_isomorphism0 _ _
end
variables {E' : gℤ → gℤ → AbGroup} {Dinf : gℤ → AbGroup} (c : E' ⟹ᵍ Dinf)
definition converges_to_g_isomorphism {E'' : gℤ → gℤ → AbGroup} {Dinf' : gℤ → AbGroup}
(e' : Πn s, E' n s ≃g E'' n s) (f' : Πn, Dinf n ≃g Dinf' n) : E'' ⟹ᵍ Dinf' :=
converges_to_isomorphism c (λn s, lm_iso_int.mk (e' n s)) (λn, lm_iso_int.mk (f' n))
end left_module
open left_module
namespace pointed
open pointed int group is_trunc trunc is_conn
definition homotopy_group_conn_nat (n : ℕ) (A : Type*[1]) : AbGroup :=
AbGroup.mk (π[n] A) (ab_group_homotopy_group_of_is_conn n A)
definition homotopy_group_conn : Π(n : ℤ) (A : Type*[1]), AbGroup
| (of_nat n) A := homotopy_group_conn_nat n A
| (-[1+ n]) A := trivial_ab_group_lift
notation `πc[`:95 n:0 `]`:0 := homotopy_group_conn n
definition homotopy_group_conn_nat_functor (n : ℕ) {A B : Type*[1]} (f : A →* B) :
homotopy_group_conn_nat n A →g homotopy_group_conn_nat n B :=
begin
cases n with n, { apply trivial_homomorphism },
cases n with n, { apply trivial_homomorphism },
exact π→g[n+2] f
end
definition homotopy_group_conn_functor :
Π(n : ℤ) {A B : Type*[1]} (f : A →* B), πc[n] A →g πc[n] B
| (of_nat n) A B f := homotopy_group_conn_nat_functor n f
| (-[1+ n]) A B f := trivial_homomorphism _ _
notation `π→c[`:95 n:0 `]`:0 := homotopy_group_conn_functor n
section
open prod prod.ops fiber
parameters {A : ℤ → Type*[1]} (f : Π(n : ℤ), A n →* A (n - 1)) [Hf : Πn, is_conn_fun 1 (f n)]
include Hf
local abbreviation I [constructor] := Z2
-- definition D_sequence : graded_module rℤ I :=
-- λv, LeftModule_int_of_AbGroup (πc[v.2] (A (v.1)))
-- definition E_sequence : graded_module rℤ I :=
-- λv, LeftModule_int_of_AbGroup (πc[v.2] (pconntype.mk (pfiber (f (v.1))) !Hf pt))
/- first need LES of these connected homotopy groups -/
-- definition exact_couple_sequence : exact_couple rℤ I :=
-- exact_couple.mk D_sequence E_sequence sorry sorry sorry sorry sorry sorry
end
end pointed
namespace spectrum
open pointed int group is_trunc trunc is_conn prod prod.ops group fin chain_complex
section
parameters {A : ℤ → spectrum} (f : Π(s : ℤ), A s →ₛ A (s - 1))
-- protected definition I [constructor] : Set := gℤ ×g gℤ
local abbreviation I [constructor] := Z2
definition D_sequence : graded_module rℤ I :=
λv, LeftModule_int_of_AbGroup (πₛ[v.1] (A (v.2)))
definition E_sequence : graded_module rℤ I :=
λv, LeftModule_int_of_AbGroup (πₛ[v.1] (sfiber (f (v.2))))
include f
definition i_sequence : D_sequence →gm D_sequence :=
begin
fapply graded_hom.mk, exact (prod_equiv_prod erfl (add_right_action (- 1))),
intro v,
apply lm_hom_int.mk, esimp,
exact πₛ→[v.1] (f v.2)
end
definition deg_j_seq_inv [constructor] : I ≃ I :=
prod_equiv_prod (add_right_action 1) (add_right_action (- 1))
definition fn_j_sequence [unfold 3] (x : I) :
D_sequence (deg_j_seq_inv x) →lm E_sequence x :=
begin
induction x with n s,
apply lm_hom_int.mk, esimp,
rexact shomotopy_groups_fun (f s) (n, 2)
end
definition j_sequence : D_sequence →gm E_sequence :=
graded_hom.mk_out deg_j_seq_inv⁻¹ᵉ fn_j_sequence
definition k_sequence : E_sequence →gm D_sequence :=
begin
fapply graded_hom.mk erfl,
intro v, induction v with n s,
apply lm_hom_int.mk, esimp,
exact πₛ→[n] (spoint (f s))
end
lemma ij_sequence : is_exact_gmod i_sequence j_sequence :=
begin
intro x y z p q,
revert y z q p,
refine eq.rec_right_inv (deg j_sequence) _,
intro y, induction x with n s, induction y with m t,
refine equiv_rect !pair_eq_pair_equiv⁻¹ᵉ _ _,
intro pq, esimp at pq, induction pq with p q,
revert t q, refine eq.rec_equiv (add_right_action (- 1)) _,
induction p using eq.rec_symm,
apply is_exact_homotopy homotopy.rfl,
{ symmetry, exact graded_hom_mk_out_destruct deg_j_seq_inv⁻¹ᵉ fn_j_sequence },
rexact is_exact_of_is_exact_at (is_exact_LES_of_shomotopy_groups (f s) (m, 2)),
end
lemma jk_sequence : is_exact_gmod j_sequence k_sequence :=
begin
intro x y z p q, induction q,
revert x y p, refine eq.rec_right_inv (deg j_sequence) _,
intro x, induction x with n s,
apply is_exact_homotopy,
{ symmetry, exact graded_hom_mk_out_destruct deg_j_seq_inv⁻¹ᵉ fn_j_sequence },
{ reflexivity },
rexact is_exact_of_is_exact_at (is_exact_LES_of_shomotopy_groups (f s) (n, 1)),
end
lemma ki_sequence : is_exact_gmod k_sequence i_sequence :=
begin
intro i j k p q, induction p, induction q, induction i with n s,
rexact is_exact_of_is_exact_at (is_exact_LES_of_shomotopy_groups (f s) (n, 0)),
end
definition exact_couple_sequence [constructor] : exact_couple rℤ I :=
exact_couple.mk D_sequence E_sequence i_sequence j_sequence k_sequence
ij_sequence jk_sequence ki_sequence
open int
parameters (ub : ℤ) (lb : ℤ → ℤ)
(Aub : Π(s n : ℤ), s ≥ ub + 1 → is_equiv (f s n))
(Alb : Π(s n : ℤ), s ≤ lb n → is_contr (πₛ[n] (A s)))
definition B : I → ℕ
| (n, s) := max0 (s - lb n)
definition B' : I → ℕ
| (n, s) := max0 (ub - s)
definition B'' : I → ℕ
| (n, s) := max0 (ub + 1 - s)
lemma iterate_deg_i (n s : ℤ) (m : ℕ) : (deg i_sequence)^[m] (n, s) = (n, s - m) :=
begin
induction m with m IH,
{ exact prod_eq idp !sub_zero⁻¹ },
{ exact ap (deg i_sequence) IH ⬝ (prod_eq idp !sub_sub) }
end
lemma iterate_deg_i_inv (n s : ℤ) (m : ℕ) : (deg i_sequence)⁻¹ᵉ^[m] (n, s) = (n, s + m) :=
begin
induction m with m IH,
{ exact prod_eq idp !add_zero⁻¹ },
{ exact ap (deg i_sequence)⁻¹ᵉ IH ⬝ (prod_eq idp !add.assoc) }
end
include Aub Alb
lemma Dub ⦃x : I⦄ ⦃t : ℕ⦄ (h : B x ≤ t) : is_contr (D_sequence ((deg i_sequence)^[t] x)) :=
begin
apply Alb, induction x with n s, rewrite [iterate_deg_i],
apply sub_le_of_sub_le,
exact le_of_max0_le h,
end
lemma Dlb ⦃x : I⦄ ⦃t : ℕ⦄ (h : B' x ≤ t) :
is_surjective (i_sequence ((deg i_sequence)⁻¹ᵉ^[t+1] x)) :=
begin
apply is_surjective_of_is_equiv,
apply is_equiv_homotopy_group_functor,
apply Aub, induction x with n s,
rewrite [iterate_deg_i_inv, ▸*, of_nat_add, -add.assoc],
apply add_le_add_right,
apply le_add_of_sub_left_le,
exact le_of_max0_le h
end
lemma Elb ⦃x : I⦄ ⦃t : ℕ⦄ (h : B'' x ≤ t) : is_contr (E_sequence ((deg i_sequence)⁻¹ᵉ^[t] x)) :=
begin
apply is_contr_homotopy_group_of_is_contr,
apply is_contr_fiber_of_is_equiv,
apply Aub, induction x with n s,
rewrite [iterate_deg_i_inv, ▸*],
apply le_add_of_sub_left_le,
apply le_of_max0_le h,
end
definition is_bounded_sequence [constructor] : is_bounded exact_couple_sequence :=
is_bounded.mk B B' B'' Dub Dlb Elb
(by intro x; reflexivity)
begin
intro x, induction x with n s, apply pair_eq, esimp, esimp, esimp [j_sequence, i_sequence],
refine !add.assoc ⬝ ap (add s) !add.comm ⬝ !add.assoc⁻¹,
end
definition converges_to_sequence : (λn s, πₛ[n] (sfiber (f s))) ⟹ᵍ (λn, πₛ[n] (A ub)) :=
begin
fapply converges_to.mk,
{ exact exact_couple_sequence },
{ exact is_bounded_sequence },
{ intro n, exact ub },
{ intro n, change max0 (ub - ub) = 0, exact ap max0 (sub_self ub) },
{ intro ns, reflexivity },
{ intro n, reflexivity },
{ intro r, exact - 1 },
{ intro r, exact r + 1 },
{ intro r n s, refine !convergence_theorem.deg_d ⬝ _,
refine ap (deg j_sequence) !iterate_deg_i_inv ⬝ _,
exact prod_eq idp (!add.assoc ⬝ ap (λx, s + (r + x)) !neg_neg) },
end
end
-- Uncomment the next line to see that the proof uses univalence, but that there are no holes
--('sorry') in the proof:
-- print axioms is_bounded_sequence
-- I think it depends on univalence in an essential way. The reason is that the long exact sequence
-- of homotopy groups already depends on univalence. Namely, in that proof we need to show that if f
-- : A → B and g : B → C are exact at B, then ∥A∥₀ → ∥B∥₀ → ∥C∥₀ is exact at ∥B∥₀. For this we need
-- that the equality |b|₀ = |b'|₀ is equivalent to ∥b = b'∥₋₁, which requires univalence.
end spectrum
|
d44307a867a3edb77592596972f109bc5c974235 | 1dd482be3f611941db7801003235dc84147ec60a | /src/data/int/gcd.lean | d07761397a1f9a55512678a59732512abf0e6b6a | [
"Apache-2.0"
] | permissive | sanderdahmen/mathlib | 479039302bd66434bb5672c2a4cecf8d69981458 | 8f0eae75cd2d8b7a083cf935666fcce4565df076 | refs/heads/master | 1,587,491,322,775 | 1,549,672,060,000 | 1,549,672,060,000 | 169,748,224 | 0 | 0 | Apache-2.0 | 1,549,636,694,000 | 1,549,636,694,000 | null | UTF-8 | Lean | false | false | 11,960 | lean | /-
Copyright (c) 2018 Guy Leroy. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sangwoo Jo (aka Jason), Guy Leroy, Johannes Hölzl
Greatest common divisor (gcd) and least common multiple (lcm) for integers.
This sets up ℤ to be a GCD domain, and introduces rules about `int.gcd`, as well as `int.lcm`.
NOTE: If you add rules to this theory, check that the corresponding rules are available for
`gcd_domain`.
-/
import data.int.basic data.nat.prime algebra.gcd_domain
/- Extended Euclidean algorithm -/
namespace nat
def xgcd_aux : ℕ → ℤ → ℤ → ℕ → ℤ → ℤ → ℕ × ℤ × ℤ
| 0 s t r' s' t' := (r', s', t')
| r@(succ _) s t r' s' t' :=
have r' % r < r, from mod_lt _ $ succ_pos _,
let q := r' / r in xgcd_aux (r' % r) (s' - q * s) (t' - q * t) r s t
@[simp] theorem xgcd_zero_left {s t r' s' t'} : xgcd_aux 0 s t r' s' t' = (r', s', t') :=
by simp [xgcd_aux]
@[simp] theorem xgcd_aux_rec {r s t r' s' t'} (h : 0 < r) : xgcd_aux r s t r' s' t' = xgcd_aux (r' % r) (s' - (r' / r) * s) (t' - (r' / r) * t) r s t :=
by cases r; [exact absurd h (lt_irrefl _), {simp only [xgcd_aux], refl}]
/-- Use the extended GCD algorithm to generate the `a` and `b` values
satisfying `gcd x y = x * a + y * b`. -/
def xgcd (x y : ℕ) : ℤ × ℤ := (xgcd_aux x 1 0 y 0 1).2
/-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/
def gcd_a (x y : ℕ) : ℤ := (xgcd x y).1
/-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/
def gcd_b (x y : ℕ) : ℤ := (xgcd x y).2
@[simp] theorem xgcd_aux_fst (x y) : ∀ s t s' t',
(xgcd_aux x s t y s' t').1 = gcd x y :=
gcd.induction x y (by simp) (λ x y h IH s t s' t', by simp [h, IH]; rw ← gcd_rec)
theorem xgcd_aux_val (x y) : xgcd_aux x 1 0 y 0 1 = (gcd x y, xgcd x y) :=
by rw [xgcd, ← xgcd_aux_fst x y 1 0 0 1]; cases xgcd_aux x 1 0 y 0 1; refl
theorem xgcd_val (x y) : xgcd x y = (gcd_a x y, gcd_b x y) :=
by unfold gcd_a gcd_b; cases xgcd x y; refl
section
parameters (a b : ℕ)
private def P : ℕ × ℤ × ℤ → Prop | (r, s, t) := (r : ℤ) = a * s + b * t
theorem xgcd_aux_P {r r'} : ∀ {s t s' t'}, P (r, s, t) → P (r', s', t') → P (xgcd_aux r s t r' s' t') :=
gcd.induction r r' (by simp) $ λ x y h IH s t s' t' p p', begin
rw [xgcd_aux_rec h], refine IH _ p, dsimp [P] at *,
rw [int.mod_def], generalize : (y / x : ℤ) = k,
rw [p, p'], simp [mul_add, mul_comm, mul_left_comm]
end
theorem gcd_eq_gcd_ab : (gcd a b : ℤ) = a * gcd_a a b + b * gcd_b a b :=
by have := @xgcd_aux_P a b a b 1 0 0 1 (by simp [P]) (by simp [P]);
rwa [xgcd_aux_val, xgcd_val] at this
end
end nat
namespace int
theorem nat_abs_div (a b : ℤ) (H : b ∣ a) : nat_abs (a / b) = (nat_abs a) / (nat_abs b) :=
begin
cases (nat.eq_zero_or_pos (nat_abs b)),
rw eq_zero_of_nat_abs_eq_zero h,
simp,
calc
nat_abs (a / b) = nat_abs (a / b) * 1 : by rw mul_one
... = nat_abs (a / b) * (nat_abs b / nat_abs b) : by rw nat.div_self h
... = nat_abs (a / b) * nat_abs b / nat_abs b : by rw (nat.mul_div_assoc _ (dvd_refl _))
... = nat_abs (a / b * b) / nat_abs b : by rw (nat_abs_mul (a / b) b)
... = nat_abs a / nat_abs b : by rw int.div_mul_cancel H,
end
theorem nat_abs_dvd_abs_iff {i j : ℤ} : i.nat_abs ∣ j.nat_abs ↔ i ∣ j :=
⟨assume (H : i.nat_abs ∣ j.nat_abs), dvd_nat_abs.mp (nat_abs_dvd.mp (coe_nat_dvd.mpr H)),
assume H : (i ∣ j), coe_nat_dvd.mp (dvd_nat_abs.mpr (nat_abs_dvd.mpr H))⟩
lemma succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : ℕ} (p_prime : nat.prime p) {m n : ℤ} {k l : ℕ}
(hpm : ↑(p ^ k) ∣ m)
(hpn : ↑(p ^ l) ∣ n) (hpmn : ↑(p ^ (k+l+1)) ∣ m*n) : ↑(p ^ (k+1)) ∣ m ∨ ↑(p ^ (l+1)) ∣ n :=
have hpm' : p ^ k ∣ m.nat_abs, from int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpm,
have hpn' : p ^ l ∣ n.nat_abs, from int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpn,
have hpmn' : (p ^ (k+l+1)) ∣ m.nat_abs*n.nat_abs,
by rw ←int.nat_abs_mul; apply (int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpmn),
let hsd := nat.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul p_prime hpm' hpn' hpmn' in
hsd.elim
(λ hsd1, or.inl begin apply int.dvd_nat_abs.1, apply int.coe_nat_dvd.2 hsd1 end)
(λ hsd2, or.inr begin apply int.dvd_nat_abs.1, apply int.coe_nat_dvd.2 hsd2 end)
theorem dvd_of_mul_dvd_mul_left {i j k : ℤ} (k_non_zero : k ≠ 0) (H : k * i ∣ k * j) : i ∣ j :=
dvd.elim H (λl H1, by rw mul_assoc at H1; exact ⟨_, eq_of_mul_eq_mul_left k_non_zero H1⟩)
theorem dvd_of_mul_dvd_mul_right {i j k : ℤ} (k_non_zero : k ≠ 0) (H : i * k ∣ j * k) : i ∣ j :=
by rw [mul_comm i k, mul_comm j k] at H; exact dvd_of_mul_dvd_mul_left k_non_zero H
section normalization_domain
instance : normalization_domain ℤ :=
{ norm_unit := λa:ℤ, if 0 ≤ a then 1 else -1,
norm_unit_zero := if_pos (le_refl _),
norm_unit_mul := assume a b hna hnb,
begin
by_cases ha : 0 ≤ a; by_cases hb : 0 ≤ b; simp [ha, hb],
exact if_pos (mul_nonneg ha hb),
exact if_neg (assume h, hb $ nonneg_of_mul_nonneg_left h $ lt_of_le_of_ne ha hna.symm),
exact if_neg (assume h, ha $ nonneg_of_mul_nonneg_right h $ lt_of_le_of_ne hb hnb.symm),
exact if_pos (mul_nonneg_of_nonpos_of_nonpos (le_of_not_ge ha) (le_of_not_ge hb))
end,
norm_unit_coe_units := assume u, (units_eq_one_or u).elim
(assume eq, eq.symm ▸ if_pos zero_le_one)
(assume eq, eq.symm ▸ if_neg (not_le_of_gt $ show (-1:ℤ) < 0, by simp [@neg_lt ℤ _ 1 0])),
.. (infer_instance : integral_domain ℤ) }
lemma norm_unit_of_nonneg {z : ℤ} (h : 0 ≤ z) : norm_unit z = 1 :=
by unfold norm_unit; exact if_pos h
lemma norm_unit_of_neg {z : ℤ} (h : z < 0) : norm_unit z = -1 :=
by unfold norm_unit; exact if_neg (not_le_of_gt h)
lemma norm_unit_nat_coe (n : ℕ) : norm_unit (n : ℤ) = 1 :=
norm_unit_of_nonneg (coe_nat_le_coe_nat_of_le $ nat.zero_le n)
theorem coe_nat_abs_eq_mul_norm_unit {z : ℤ} : (z.nat_abs : ℤ) = z * norm_unit z :=
begin
by_cases 0 ≤ z,
{ simp [nat_abs_of_nonneg h, norm_unit_of_nonneg h] },
{ simp [of_nat_nat_abs_of_nonpos (le_of_not_ge h), norm_unit_of_neg (lt_of_not_ge h)] }
end
end normalization_domain
/-- ℤ specific version of least common multiple. -/
def lcm (i j : ℤ) : ℕ := nat.lcm (nat_abs i) (nat_abs j)
theorem lcm_def (i j : ℤ) : lcm i j = nat.lcm (nat_abs i) (nat_abs j) := rfl
section gcd_domain
theorem gcd_dvd_left (i j : ℤ) : (gcd i j : ℤ) ∣ i :=
dvd_nat_abs.mp $ coe_nat_dvd.mpr $ nat.gcd_dvd_left _ _
theorem gcd_dvd_right (i j : ℤ) : (gcd i j : ℤ) ∣ j :=
dvd_nat_abs.mp $ coe_nat_dvd.mpr $ nat.gcd_dvd_right _ _
theorem dvd_gcd {i j k : ℤ} (h1 : k ∣ i) (h2 : k ∣ j) : k ∣ gcd i j :=
nat_abs_dvd.1 $ coe_nat_dvd.2 $ nat.dvd_gcd (nat_abs_dvd_abs_iff.2 h1) (nat_abs_dvd_abs_iff.2 h2)
theorem gcd_mul_lcm (i j : ℤ) : gcd i j * lcm i j = nat_abs (i * j) :=
by rw [int.gcd, int.lcm, nat.gcd_mul_lcm, nat_abs_mul]
instance : gcd_domain ℤ :=
{ gcd := λa b, int.gcd a b,
lcm := λa b, int.lcm a b,
gcd_dvd_left := assume a b, int.gcd_dvd_left _ _,
gcd_dvd_right := assume a b, int.gcd_dvd_right _ _,
dvd_gcd := assume a b c, dvd_gcd,
norm_unit_gcd := assume a b, norm_unit_nat_coe _,
gcd_mul_lcm := by intros; rw [← int.coe_nat_mul, gcd_mul_lcm, coe_nat_abs_eq_mul_norm_unit],
lcm_zero_left := assume a, coe_nat_eq_zero.2 $ nat.lcm_zero_left _,
lcm_zero_right := assume a, coe_nat_eq_zero.2 $ nat.lcm_zero_right _,
.. int.normalization_domain }
lemma coe_gcd (i j : ℤ) : ↑(int.gcd i j) = gcd_domain.gcd i j := rfl
lemma coe_lcm (i j : ℤ) : ↑(int.lcm i j) = gcd_domain.lcm i j := rfl
lemma nat_abs_gcd (i j : ℤ) : nat_abs (gcd_domain.gcd i j) = int.gcd i j := rfl
lemma nat_abs_lcm (i j : ℤ) : nat_abs (gcd_domain.lcm i j) = int.lcm i j := rfl
end gcd_domain
theorem gcd_comm (i j : ℤ) : gcd i j = gcd j i := nat.gcd_comm _ _
theorem gcd_assoc (i j k : ℤ) : gcd (gcd i j) k = gcd i (gcd j k) := nat.gcd_assoc _ _ _
@[simp] theorem gcd_self (i : ℤ) : gcd i i = nat_abs i := by simp [gcd]
@[simp] theorem gcd_zero_left (i : ℤ) : gcd 0 i = nat_abs i := by simp [gcd]
@[simp] theorem gcd_zero_right (i : ℤ) : gcd i 0 = nat_abs i := by simp [gcd]
@[simp] theorem gcd_one_left (i : ℤ) : gcd 1 i = 1 := nat.gcd_one_left _
@[simp] theorem gcd_one_right (i : ℤ) : gcd i 1 = 1 := nat.gcd_one_right _
theorem gcd_mul_left (i j k : ℤ) : gcd (i * j) (i * k) = nat_abs i * gcd j k :=
by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_gcd, coe_nat_abs_eq_mul_norm_unit]
theorem gcd_mul_right (i j k : ℤ) : gcd (i * j) (k * j) = gcd i k * nat_abs j :=
by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_gcd, coe_nat_abs_eq_mul_norm_unit]
theorem gcd_pos_of_non_zero_left {i : ℤ} (j : ℤ) (i_non_zero : i ≠ 0) : gcd i j > 0 :=
nat.gcd_pos_of_pos_left (nat_abs j) (nat_abs_pos_of_ne_zero i_non_zero)
theorem gcd_pos_of_non_zero_right (i : ℤ) {j : ℤ} (j_non_zero : j ≠ 0) : gcd i j > 0 :=
nat.gcd_pos_of_pos_right (nat_abs i) (nat_abs_pos_of_ne_zero j_non_zero)
theorem gcd_eq_zero_iff {i j : ℤ} : gcd i j = 0 ↔ i = 0 ∧ j = 0 :=
by rw [← int.coe_nat_eq_coe_nat_iff, int.coe_nat_zero, coe_gcd, gcd_eq_zero_iff]
theorem gcd_div {i j k : ℤ} (H1 : k ∣ i) (H2 : k ∣ j) :
gcd (i / k) (j / k) = gcd i j / nat_abs k :=
by rw [gcd, nat_abs_div i k H1, nat_abs_div j k H2];
exact nat.gcd_div (nat_abs_dvd_abs_iff.mpr H1) (nat_abs_dvd_abs_iff.mpr H2)
theorem gcd_dvd_gcd_of_dvd_left {i k : ℤ} (j : ℤ) (H : i ∣ k) : gcd i j ∣ gcd k j :=
int.coe_nat_dvd.1 $ dvd_gcd (dvd.trans (gcd_dvd_left i j) H) (gcd_dvd_right i j)
theorem gcd_dvd_gcd_of_dvd_right {i k : ℤ} (j : ℤ) (H : i ∣ k) : gcd j i ∣ gcd j k :=
int.coe_nat_dvd.1 $ dvd_gcd (gcd_dvd_left j i) (dvd.trans (gcd_dvd_right j i) H)
theorem gcd_dvd_gcd_mul_left (i j k : ℤ) : gcd i j ∣ gcd (k * i) j :=
gcd_dvd_gcd_of_dvd_left _ (dvd_mul_left _ _)
theorem gcd_dvd_gcd_mul_right (i j k : ℤ) : gcd i j ∣ gcd (i * k) j :=
gcd_dvd_gcd_of_dvd_left _ (dvd_mul_right _ _)
theorem gcd_dvd_gcd_mul_left_right (i j k : ℤ) : gcd i j ∣ gcd i (k * j) :=
gcd_dvd_gcd_of_dvd_right _ (dvd_mul_left _ _)
theorem gcd_dvd_gcd_mul_right_right (i j k : ℤ) : gcd i j ∣ gcd i (j * k) :=
gcd_dvd_gcd_of_dvd_right _ (dvd_mul_right _ _)
theorem gcd_eq_left {i j : ℤ} (H : i ∣ j) : gcd i j = nat_abs i :=
nat.dvd_antisymm (by unfold gcd; exact nat.gcd_dvd_left _ _)
(by unfold gcd; exact nat.dvd_gcd (dvd_refl _) (nat_abs_dvd_abs_iff.mpr H))
theorem gcd_eq_right {i j : ℤ} (H : j ∣ i) : gcd i j = nat_abs j :=
by rw [gcd_comm, gcd_eq_left H]
/- lcm -/
theorem lcm_comm (i j : ℤ) : lcm i j = lcm j i :=
by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm, lcm_comm]
theorem lcm_assoc (i j k : ℤ) : lcm (lcm i j) k = lcm i (lcm j k) :=
by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm, lcm_assoc]
@[simp] theorem lcm_zero_left (i : ℤ) : lcm 0 i = 0 :=
by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm]
@[simp] theorem lcm_zero_right (i : ℤ) : lcm i 0 = 0 :=
by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm]
@[simp] theorem lcm_one_left (i : ℤ) : lcm 1 i = nat_abs i :=
by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm, coe_nat_abs_eq_mul_norm_unit]
@[simp] theorem lcm_one_right (i : ℤ) : lcm i 1 = nat_abs i :=
by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm, coe_nat_abs_eq_mul_norm_unit]
@[simp] theorem lcm_self (i : ℤ) : lcm i i = nat_abs i :=
by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm, coe_nat_abs_eq_mul_norm_unit]
theorem dvd_lcm_left (i j : ℤ) : i ∣ lcm i j :=
by rw [coe_lcm]; exact dvd_lcm_left _ _
theorem dvd_lcm_right (i j : ℤ) : j ∣ lcm i j :=
by rw [coe_lcm]; exact dvd_lcm_right _ _
theorem lcm_dvd {i j k : ℤ} : i ∣ k → j ∣ k → (lcm i j : ℤ) ∣ k :=
by rw [coe_lcm]; exact lcm_dvd
end int
|
57c5117be6b67b6e1eed00c9f6428a199b0dbea1 | ce6917c5bacabee346655160b74a307b4a5ab620 | /src/ch5/ex0110.lean | 5608e9ad2f14428a3c98632272a397a0422140ea | [] | no_license | Ailrun/Theorem_Proving_in_Lean | ae6a23f3c54d62d401314d6a771e8ff8b4132db2 | 2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68 | refs/heads/master | 1,609,838,270,467 | 1,586,846,743,000 | 1,586,846,743,000 | 240,967,761 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 164 | lean | variables {p q : Prop} (hp : p) (hq : q)
section
include hp hq
example : p ∧ q ∧ p :=
begin
apply and.intro hp,
exact and.intro hq hp
end
end
|
5796b77bbcc0bea0f5bb8165fde25216395997db | 48eee836fdb5c613d9a20741c17db44c8e12e61c | /src/util/multi_function.lean | 8e5d6e7eaa9650f7eb970dc70f460b98c2d9bf6b | [
"Apache-2.0"
] | permissive | fgdorais/lean-universal | 06430443a4abe51e303e602684c2977d1f5c0834 | 9259b0f7fb3aa83a9e0a7a3eaa44c262e42cc9b1 | refs/heads/master | 1,592,479,744,136 | 1,589,473,399,000 | 1,589,473,399,000 | 196,287,552 | 1 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 19,413 | lean | -- Copyright © 2019 François G. Dorais. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
import .meta.ind_utils
/-
structure {u_0 u_1 ... u_{n-1} v_0 v_1 ... v_{n-1}} multi_function_n
(α_0 : Sort u_0) (α_1 : Sort u_1) ... (α_{n-1} : Sort u_{n-1})
(β_0 : Sort v_0) (β_1 : Sort v_1) ... (β_{n-1} : Sort v_{n-1}) :=
mk :: (fn_0 : α_0 → β_0) (fn_1 : α_1 → β_1) ... (fn_{n-1} : α_{n-1} → β_{n-1})
theorem multi_function_n.mk.eta {α_0 α_1 ... α_{n-1} β_0 β_1 ... β_{n-1}} (f : multi_function_n α_0 α_1 ... α_{n-1} β_0 β_1 ... β_{n-1}),
multi_function_n.mk (multi_function_n.fn_0 f) (multi_function_n.fn_1 f) ... (multi_function_n.fn_{n-1} f) = f
definition multi_function_n.id {α_0 α_1 ... α_{n-1}} :
multi_function_n α_0 α_1 ... α_{n-1} α_0 α_1 ... α_{n-1}
definition multi_function_n.comp {α_0 α_1 ... α_{n-1} β_0 β_1 ... β_{n-1} γ_0 γ_1 ... γ_{n-1}} :
multi_function_n β_0 β_1 ... β_{n-1} γ_0 γ_1 ... γ_{n-1} →
multi_function_n α_0 α_1 ... α_{n-1} β_0 β_1 ... β_{n-1} →
multi_function_n α_0 α_1 ... α_{n-1} γ_0 γ_1 ... γ_{n-1}
theorem multi_function_n.comp.assoc {α_0 α_1 ... α_{n-1} β_0 β_1 ... β_{n-1} γ_0 γ_1 ... γ_{n-1} δ_0 δ_1 ... δ_{n-1}}
(f : multi_function_n γ_0 γ_1 ... γ_{n-1} δ_0 δ_1 ... δ_{n-1})
(g : multi_function_n β_0 β_1 ... β_{n-1} γ_0 γ_1 ... γ_{n-1})
(h : multi_function_n α_0 α_1 ... α_{n-1} β_0 β_1 ... β_{n-1}) :
multi_function_n.comp (multi_function_n.comp f g) h = multi_function_n.comp f (multi_function_n.comp g h)
theorem multi_function_n.comp.left_id {α_0 α_1 ... α_{n-1} β_0 β_1 ... β_{n-1}}
(f : multi_function_n α_0 α_1 ... α_{n-1} β_0 β_1 ... β_{n-1}) :
multi_function_n.comp multi_function_n.id f = f
theorem multi_function_n.comp.right_id {α_0 α_1 ... α_{n-1} β_0 β_1 ... β_{n-1}}
(f : multi_function_n α_0 α_1 ... α_{n-1} β_0 β_1 ... β_{n-1}) :
multi_function_n.comp f multi_function_n.id = f
-/
namespace multi_function
def to_name (n : nat) : name := mk_sub_name `multi_function n
def mk_name (n : nat) : name := to_name n ++ `mk
def fn_name (n i : nat) : name := to_name n ++ mk_sub_name `fn i
meta def mk_decl (n : nat) : inductive_declaration :=
let nm := to_name n in
let dus := mk_sub_names `u n in
let dls := dus.map level.param in
let dns := mk_sub_names `α n in
let cus := mk_sub_names `v n in
let cls := cus.map level.param in
let cns := mk_sub_names `β n in
let ctx : expr_ctx :=
(dns ++ cns).reverse.zip $
(dls ++ cls).reverse.map $
λ l, (expr.sort l, binder_info.default) in
let lt := level.list_max (level.one :: dls ++ cls) in
let type : expr := ctx.pi (expr.sort lt) in
let inst : expr := ctx.app (expr.const nm (dls ++ cls)) in
let ctx : expr_ctx := ctx.map (λ ⟨n, t, _⟩, (n, t, binder_info.implicit)) in
let ctx : expr_ctx := (mk_sub_names `fn n).reverse.enum.foldr (λ ⟨k, fn⟩ ctx,
ctx.add fn (expr.pi `_ binder_info.default (expr.var (2 * n - 1)) (expr.var n))
) ctx in
let cons : expr := ctx.pi (inst.lift_vars 0 n) in
{ to_name := nm
, univ_params := dus ++ cus
, type := type
, recursor := some (nm ++ `rec)
, constructors := [(mk_name n, cons)]
, num_params := 2 * n
, num_indices := 0
, is_trusted := tt
}
meta def mk_proj (n : nat) : list declaration :=
let nm := to_name n in
let dus := mk_sub_names `u n in
let dls := dus.map level.param in
let dns := mk_sub_names `α n in
let cus := mk_sub_names `v n in
let cls := cus.map level.param in
let cns := mk_sub_names `β n in
let ctx : expr_ctx :=
(dns ++ cns).reverse.zip $
(dls ++ cls).reverse.map $
λ l, (expr.sort l, binder_info.implicit) in
let inst : expr := ctx.app (expr.const nm (dls ++ cls)) in
let tctx : expr_ctx := ctx.add `f inst in
let types : list expr := (list.range' n).map (λ k,
tctx.pi (expr.pi `_ binder_info.default (expr.var (2 * n - k)) (expr.var (n + 1 - k)))
) in
let fctx : expr_ctx := (mk_sub_names `fn n).reverse.map (λ fn,
(fn, (expr.pi `_ binder_info.default (expr.var (2 * n - 1)) (expr.var n)), binder_info.default)
) in
let values : list expr := (list.range' n).map (λ k,
let l := level.imax (level.param $ mk_sub_name `u k) (level.param $ mk_sub_name `v k) in
let mot : expr := expr.pi `_ binder_info.default (expr.var (2 * n - k)) (expr.var (n + 1 - k)) in
let mot : expr := expr.lam `H binder_info.default inst mot in
let val : expr := fctx.lam (expr.var (n - k - 1)) in
let rec : expr := ctx.app (expr.const (nm ++ `rec) (l :: dls ++ cls)) in
let rec : expr := rec.app mot in
let rec : expr := rec.app val in
ctx.lam rec
) in
(list.zip types values).enum.map (λ ⟨k, t, v⟩,
declaration.defn (fn_name n k) (dus ++ cus) t v reducibility_hints.abbrev tt
)
meta def mk_eta (n : nat) : declaration :=
let nm := to_name n in
let dus := mk_sub_names `u n in
let dls := dus.map level.param in
let dns := mk_sub_names `α n in
let cus := mk_sub_names `v n in
let cls := cus.map level.param in
let cns := mk_sub_names `β n in
let lvl := level.list_max (level.one :: dls ++ cls) in
let ctx : expr_ctx :=
(dns ++ cns).reverse.zip $
(dls ++ cls).reverse.map $
λ l, (expr.sort l, binder_info.implicit) in
let inst : expr := ctx.app (expr.const nm (dls ++ cls)) in
let cons : expr := ctx.app (expr.const (mk_name n) (dls ++ cls)) in
let tctx : expr_ctx := ctx.add `f inst in
let fns : list expr := (list.range n).map (λ k,
let e : expr := expr.const (fn_name n k) (dls ++ cls) in
tctx.app e
) in
let lhs : expr := expr.mk_app (cons.lift_vars 0 1) fns in
let eqn : expr := expr.mk_app (expr.const `eq [lvl]) [inst.lift_vars 0 1, lhs, expr.var 0] in
let type : expr := tctx.pi $ eqn in
let rec : expr := ctx.app $ expr.const (nm ++ `rec_on) (level.zero :: dls ++ cls) in
let rec : expr := rec.app (expr.lam `f binder_info.default inst eqn) in
let rec : expr := expr.app (rec.lift_vars 0 1) (expr.var 0) in
let fctx : expr_ctx := (list.range n).map (λ k,
(mk_sub_name `fn (n-k-1), expr.pi `_ binder_info.default (expr.var (2 * n)) (expr.var (n+1)), binder_info.default)
) in
let fobj : expr := fctx.app (cons.lift_vars 0 (n+1)) in
let prf : expr := expr.const `eq.refl [lvl] in
let prf : expr := prf.mk_app [inst.lift_vars 0 (n+1), fobj] in
let value : expr := tctx.lam (rec.app $ fctx.lam prf) in
declaration.thm (mk_name n ++ `eta) (dus ++ cus) type (pure value)
/-
meta def mk_eq (n : nat) : declaration :=
let nm := to_name n in
let dus := mk_sub_names `u n in
let dls := dus.map level.param in
let dns := mk_sub_names `α n in
let cus := mk_sub_names `v n in
let cls := cus.map level.param in
let cns := mk_sub_names `β n in
let lvl := level.list_max (level.one :: dls ++ cls) in
let ctx : expr_ctx :=
(dns ++ cns).reverse.zip $
(dls ++ cls).reverse.map $
λ l, (expr.sort l, binder_info.implicit) in
let inst : expr := ctx.app (expr.const nm (dls ++ cls)) in
let tctx : expr_ctx :=
[ (mk_sub_name `f 2, inst.lift_vars 0 1, binder_info.default)
, (mk_sub_name `f 1, inst, binder_info.default)
] ++ ctx in
let tctx : expr_ctx := (list.zip dls cls).indexed.foldl (λ tctx ⟨k, dl, cl⟩,
let typ : expr := expr.pi `_ binder_info.default (expr.var (2 * n + 1)) (expr.var (n + 2)) in
let lhs : expr := expr.const (nm ++ mk_sub_name `fn k) (dls ++ cls) in
let lhs : expr := lhs.app (expr.var (k+1)) in
let rhs : expr := expr.const (nm ++ mk_sub_name `fn k) (dls ++ cls) in
let rhs : expr := rhs.app (expr.var k) in
let eqn : expr := expr.const `eq [level.imax dl cl] in
let eqn : expr := eqn.mk_app [typ, lhs, rhs] in
tctx.add (mk_sub_name `h k) eqn
) tctx in
let type : expr := tctx.pi $ expr.mk_app (expr.const `eq [lvl]) [inst.lift_vars 0 (n+2), expr.var (n+1), expr.var n]
in
let value : expr := inhabited.default expr in
declaration.thm (nm ++ `eq) (dus ++ cus) type (pure value)
-/
meta def mk_id (n : nat) : declaration :=
let nm := to_name n in
let us := mk_sub_names `u n in
let ls := us.map level.param in
let ts := mk_sub_names `α n in
let ctx : expr_ctx := ts.reverse.zip $ ls.reverse.map (λ l, (expr.sort l, binder_info.implicit)) in
let type : expr := expr.const nm (ls ++ ls) in
let type : expr := type.mk_app (expr.mk_num_vars n ++ expr.mk_num_vars n).reverse in
let type : expr := ctx.pi type in
let value : expr := expr.const (nm ++ `mk) (ls ++ ls) in
let value : expr := value.mk_app (expr.mk_num_vars n ++ expr.mk_num_vars n).reverse in
let value : expr := value.mk_app $ (list.range' n).map (λ k,
let e : expr := expr.const `id [level.param $ mk_sub_name `u k] in
e.app (expr.var (n - k - 1))
) in
let value : expr := ctx.lam value in
declaration.defn (nm ++ `id) us type value reducibility_hints.abbrev tt
meta def mk_comp (n : nat) : declaration :=
let nm := to_name n in
let nus := mk_sub_names `u n in
let nvs := mk_sub_names `v n in
let nws := mk_sub_names `w n in
let lus := nus.map level.param in
let lvs := nvs.map level.param in
let lws := nws.map level.param in
let tus := mk_sub_names `α n in
let tvs := mk_sub_names `β n in
let tws := mk_sub_names `γ n in
let ctx : expr_ctx :=
(tus ++ tvs ++ tws).reverse.zip $
(lus ++ lvs ++ lws).reverse.map $
λ l, (expr.sort l, binder_info.implicit) in
let typeuv : expr := expr.const nm (lus ++ lvs) in
let typevw : expr := expr.const nm (lvs ++ lws) in
let typeuw : expr := expr.const nm (lus ++ lws) in
let typeuv : expr := typeuv.mk_app (expr.mk_num_vars n (2 * n)).reverse in
let typeuv : expr := typeuv.mk_app (expr.mk_num_vars n (1 * n)).reverse in
let typeuw : expr := typeuw.mk_app (expr.mk_num_vars n (2 * n)).reverse in
let typeuw : expr := typeuw.mk_app (expr.mk_num_vars n (0 * n)).reverse in
let typevw : expr := typevw.mk_app (expr.mk_num_vars n (1 * n)).reverse in
let typevw : expr := typevw.mk_app (expr.mk_num_vars n (0 * n)).reverse in
let ctx : expr_ctx := ctx.add `f typevw in
let ctx : expr_ctx := ctx.add `g (typeuv.lift_vars 0 1) in
let type : expr := ctx.pi (typeuw.lift_vars 0 2) in
let pruv : list expr := (list.range n).map (λ k,
let e : expr := expr.const (nm ++ mk_sub_name `fn k) (lus ++ lvs) in
let e : expr := e.mk_app (expr.mk_num_vars n (2 * n + 2)).reverse in
let e : expr := e.mk_app (expr.mk_num_vars n (1 * n + 2)).reverse in
e.app (expr.var 0)
) in
let prvw : list expr := (list.range n).map (λ k,
let e : expr := expr.const (nm ++ mk_sub_name `fn k) (lvs ++ lws) in
let e : expr := e.mk_app (expr.mk_num_vars n (1 * n + 2)).reverse in
let e : expr := e.mk_app (expr.mk_num_vars n (0 * n + 2)).reverse in
e.app (expr.var 1)
) in
let args : list expr := (list.zip pruv prvw).reverse.enum.map (λ ⟨k, fuv, fvw⟩,
let u := [mk_sub_name `u (n-k-1), mk_sub_name `v (n-k-1), mk_sub_name `w (n-k-1)] in
let e : expr := expr.const `function.comp (u.map level.param) in
e.mk_app [expr.var (2*n+2+k), expr.var (1*n+2+k), expr.var (0*n+2+k), fvw, fuv]
) in
let value : expr := expr.const (nm ++ `mk) (lus ++ lws) in
let value : expr := value.mk_app (expr.mk_num_vars n (2 * n + 2)).reverse in
let value : expr := value.mk_app (expr.mk_num_vars n (0 * n + 2)).reverse in
let value : expr := value.mk_app args.reverse in
let value : expr := ctx.lam value in
declaration.defn (nm ++ `comp) (nus ++ nvs ++ nws) type value reducibility_hints.abbrev tt
meta def mk_comp_assoc (n : nat) : declaration :=
let nm := to_name n in
let nts := mk_sub_names `t n in
let nus := mk_sub_names `u n in
let nvs := mk_sub_names `v n in
let nws := mk_sub_names `w n in
let lts := nts.map level.param in
let lus := nus.map level.param in
let lvs := nvs.map level.param in
let lws := nws.map level.param in
let tts := mk_sub_names `α n in
let tus := mk_sub_names `β n in
let tvs := mk_sub_names `γ n in
let tws := mk_sub_names `δ n in
let ctx : expr_ctx :=
(tts ++ tus ++ tvs ++ tws).reverse.zip $
(lts ++ lus ++ lvs ++ lws).reverse.map $
λ l, (expr.sort l, binder_info.implicit) in
let typetu : expr := expr.const nm (lts ++ lus) in
let typetu : expr := typetu.mk_app (expr.mk_num_vars n (3 * n)).reverse in
let typetu : expr := typetu.mk_app (expr.mk_num_vars n (2 * n)).reverse in
let typeuv : expr := expr.const nm (lus ++ lvs) in
let typeuv : expr := typeuv.mk_app (expr.mk_num_vars n (2 * n)).reverse in
let typeuv : expr := typeuv.mk_app (expr.mk_num_vars n (1 * n)).reverse in
let typevw : expr := expr.const nm (lvs ++ lws) in
let typevw : expr := typevw.mk_app (expr.mk_num_vars n (1 * n)).reverse in
let typevw : expr := typevw.mk_app (expr.mk_num_vars n (0 * n)).reverse in
let typetw : expr := expr.const nm (lts ++ lws) in
let typetw : expr := typetw.mk_app (expr.mk_num_vars n (3 * n)).reverse in
let typetw : expr := typetw.mk_app (expr.mk_num_vars n (0 * n)).reverse in
let ctx : expr_ctx := ctx.add `f typevw in
let ctx : expr_ctx := ctx.add `g (typeuv.lift_vars 0 1) in
let ctx : expr_ctx := ctx.add `h (typetu.lift_vars 0 2) in
let lhsl : expr := expr.const (nm ++ `comp) (lus ++ lvs ++ lws) in
let lhsl : expr := lhsl.mk_app (expr.mk_num_vars n (2 * n + 3)).reverse in
let lhsl : expr := lhsl.mk_app (expr.mk_num_vars n (1 * n + 3)).reverse in
let lhsl : expr := lhsl.mk_app (expr.mk_num_vars n (0 * n + 3)).reverse in
let lhsl : expr := lhsl.mk_app [expr.var 2, expr.var 1] in
let lhs : expr := expr.const (nm ++ `comp) (lts ++ lus ++ lws) in
let lhs : expr := lhs.mk_app (expr.mk_num_vars n (3 * n + 3)).reverse in
let lhs : expr := lhs.mk_app (expr.mk_num_vars n (2 * n + 3)).reverse in
let lhs : expr := lhs.mk_app (expr.mk_num_vars n (0 * n + 3)).reverse in
let lhs : expr := lhs.mk_app [lhsl, expr.var 0] in
let rhsr : expr := expr.const (nm ++ `comp) (lts ++ lus ++ lvs) in
let rhsr : expr := rhsr.mk_app (expr.mk_num_vars n (3 * n + 3)).reverse in
let rhsr : expr := rhsr.mk_app (expr.mk_num_vars n (2 * n + 3)).reverse in
let rhsr : expr := rhsr.mk_app (expr.mk_num_vars n (1 * n + 3)).reverse in
let rhsr : expr := rhsr.mk_app [expr.var 1, expr.var 0] in
let rhs : expr := expr.const (nm ++ `comp) (lts ++ lvs ++ lws) in
let rhs : expr := rhs.mk_app (expr.mk_num_vars n (3 * n + 3)).reverse in
let rhs : expr := rhs.mk_app (expr.mk_num_vars n (1 * n + 3)).reverse in
let rhs : expr := rhs.mk_app (expr.mk_num_vars n (0 * n + 3)).reverse in
let rhs : expr := rhs.mk_app [expr.var 2, rhsr] in
let lvl : level := level.list_max (level.one :: lts ++ lws) in
let eqn : expr := expr.const `eq [lvl] in
let eqn : expr := eqn.mk_app [typetw.lift_vars 0 3, lhs, rhs] in
let type : expr := ctx.pi eqn in
let proof : expr := expr.const `eq.refl [lvl] in
let proof : expr := proof.mk_app [typetw.lift_vars 0 3, lhs] in
let proof : expr := ctx.lam proof in
declaration.thm (nm ++ `comp ++ `assoc) (nts ++ nus ++ nvs ++ nws) type (pure proof)
meta def mk_comp_left_id (n : nat) : declaration :=
let nm := to_name n in
let nus := mk_sub_names `u n in
let nvs := mk_sub_names `v n in
let lus := nus.map level.param in
let lvs := nvs.map level.param in
let tus := mk_sub_names `α n in
let tvs := mk_sub_names `β n in
let ctx : expr_ctx := (list.zip (tus ++ tvs) (lus ++ lvs)).reverse.map (λ ⟨n, l⟩,
(n, expr.sort l, binder_info.implicit)
) in
let typeuv : expr := ctx.app (expr.const nm (lus ++ lvs)) in
let ctx : expr_ctx := ctx.add `f typeuv in
let compuvv : expr := expr.const (nm ++ `comp) (lus ++ lvs ++ lvs) in
let compuvv : expr := compuvv.mk_app (expr.mk_num_vars n n).reverse in
let compuvv : expr := compuvv.mk_app (expr.mk_num_vars n 0).reverse in
let compuvv : expr := compuvv.mk_app (expr.mk_num_vars n 0).reverse in
let idv : expr := expr.const (nm ++ `id) lvs in
let idv : expr := idv.mk_app (expr.mk_num_vars n 0).reverse in
let lvl : level := level.list_max (level.one :: lus ++ lvs) in
let lhs : expr := expr.mk_app (compuvv.lift_vars 0 1) [idv.lift_vars 0 1, expr.var 0] in
let type : expr := expr.const `eq [lvl] in
let type : expr := type.mk_app [typeuv.lift_vars 0 1, lhs, expr.var 0] in
let type : expr := ctx.pi type in
let proof : expr := ctx.app $ expr.const (mk_name n ++ `eta) (lus ++ lvs) in
let proof : expr := ctx.lam proof in
declaration.thm (nm ++ `comp ++ `left_id) (nus ++ nvs) type (pure proof)
meta def mk_comp_right_id (n : nat) : declaration :=
let nm := to_name n in
let nus := mk_sub_names `u n in
let nvs := mk_sub_names `v n in
let lus := nus.map level.param in
let lvs := nvs.map level.param in
let tus := mk_sub_names `α n in
let tvs := mk_sub_names `β n in
let ctx : expr_ctx := (list.zip (tus ++ tvs) (lus ++ lvs)).reverse.map (λ ⟨n, l⟩,
(n, expr.sort l, binder_info.implicit)
) in
let typeuv : expr := ctx.app (expr.const nm (lus ++ lvs)) in
let ctx : expr_ctx := ctx.add `f typeuv in
let compuuv : expr := expr.const (nm ++ `comp) (lus ++ lus ++ lvs) in
let compuuv : expr := compuuv.mk_app (expr.mk_num_vars n n).reverse in
let compuuv : expr := compuuv.mk_app (expr.mk_num_vars n n).reverse in
let compuuv : expr := compuuv.mk_app (expr.mk_num_vars n 0).reverse in
let idu : expr := expr.const (nm ++ `id) lus in
let idu : expr := idu.mk_app (expr.mk_num_vars n n).reverse in
let lvl : level := level.list_max (level.one :: lus ++ lvs) in
let lhs : expr := expr.mk_app (compuuv.lift_vars 0 1) [expr.var 0, idu.lift_vars 0 1] in
let type : expr := expr.const `eq [lvl] in
let type : expr := type.mk_app [typeuv.lift_vars 0 1, lhs, expr.var 0] in
let type : expr := ctx.pi type in
let proof : expr := ctx.app $ expr.const (mk_name n ++ `eta) (lus ++ lvs) in
let proof : expr := ctx.lam proof in
declaration.thm (nm ++ `comp ++ `right_id) (nus ++ nvs) type (pure proof)
end multi_function
meta def environment.add_multi_function (env : environment) (n : nat) : exceptional environment :=
env.add_ind (multi_function.mk_decl n) tt >>= λ env, list.mfoldl environment.add env $
multi_function.mk_proj n ++
[ multi_function.mk_eta n
, multi_function.mk_id n
, multi_function.mk_comp n
, multi_function.mk_comp_assoc n
, multi_function.mk_comp_left_id n
, multi_function.mk_comp_right_id n
]
namespace tactic
meta def add_multi_function (n : nat) : tactic unit :=
do {
let mfn := multi_function.to_name n,
updateex_env $ λ env, env.add_multi_function n,
-- vm needs code for cases_on ...
ron ← get_decl (mfn ++ `rec_on),
add_decl (ron.update_name $ mfn ++ `cases_on),
-- set attributes
(list.range n).mmap (λ k,
set_basic_attribute `reducible (mfn ++ mk_sub_name `fn k) tt >>
set_basic_attribute `inline (mfn ++ mk_sub_name `fn k) tt
),
set_basic_attribute `reducible (mfn ++ `id) tt,
set_basic_attribute `reducible (mfn ++ `comp) tt,
guard (n = 0) <|> set_basic_attribute `simp (mfn ++ `mk.eta) tt,
guard (n = 0) <|> set_basic_attribute `simp (mfn ++ `comp.left_id) tt,
guard (n = 0) <|> set_basic_attribute `simp (mfn ++ `comp.right_id) tt,
skip
}
meta def ensure_multi_function (n : nat) : tactic unit :=
get_decl (multi_function.to_name n) >> skip <|> add_multi_function n
end tactic
run_cmd tactic.add_multi_function 1
run_cmd tactic.add_multi_function 2
instance {α} {β} : has_coe_to_fun (multi_function_1 α β) := ⟨_, multi_function_1.fn_0⟩
theorem multi_function_1.eq {α} {β} {f g : multi_function_1 α β} : f.fn_0 = g.fn_0 → f = g :=
λ h,
eq.subst (multi_function_1.mk.eta f) $
eq.subst (multi_function_1.mk.eta g) $
congr rfl h
theorem multi_function_2.eq {α_0} {α_1} {β_0} {β_1} {f g : multi_function_2 α_0 α_1 β_0 β_1} : f.fn_0 = g.fn_0 → f.fn_1 = g.fn_1 → f = g :=
λ h_0 h_1,
eq.subst (multi_function_2.mk.eta f) $
eq.subst (multi_function_2.mk.eta g) $
congr (congr rfl h_0) h_1
|
05e48437612ce2a66caebd290bd279b1d3f3c32e | 93366ecea09eebeeb0b320567c6f71715434c3f0 | /src/bum/parser.lean | 1dbad560ff4f02b9a3269fa80c6de45136280694 | [
"LicenseRef-scancode-mit-taylor-variant",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive | o89/bum | 9c1286cedb878c1e14c618e81b33d365f62c8a8a | 18ffb2b46932ba767c50758a93cc99846ef1b46a | refs/heads/master | 1,670,171,693,018 | 1,669,086,393,000 | 1,669,086,393,000 | 205,409,352 | 8 | 6 | null | null | null | null | UTF-8 | Lean | false | false | 3,663 | lean | inductive ParseResult (α : Type)
| done (pos : Nat) (result : α) : ParseResult α
| fail (pos : Nat) (msg : List String) : ParseResult α
def Parser (α : Type) :=
∀ (input : String) (start : Nat), ParseResult α
def Parser.bind {α β : Type} (p : Parser α) (f : α → Parser β) : Parser β :=
λ input pos => match p input pos with
| ParseResult.done pos a => f a input pos
| ParseResult.fail pos msg => ParseResult.fail pos msg
def Parser.pure {α : Type} (a : α) : Parser α :=
λ input pos => ParseResult.done pos a
def Parser.fail {α : Type} (msg : String) : Parser α :=
λ _ pos => ParseResult.fail pos [ msg ]
instance : Monad Parser :=
{ pure := Parser.pure, bind := Parser.bind }
def Parser.failure {α : Type} : Parser α :=
λ _ pos => ParseResult.fail pos []
def Parser.orElse {α : Type} (p : Parser α) (q : Unit → Parser α) : Parser α :=
λ input pos => match p input pos with
| ParseResult.fail pos₁ msg₁ =>
if pos₁ ≠ pos then ParseResult.fail pos₁ msg₁
else match q () input pos with
| ParseResult.fail pos₂ msg₂ =>
if pos₁ < pos₂ then ParseResult.fail pos₁ msg₁
else if pos₂ < pos₁ then ParseResult.fail pos₂ msg₂
else ParseResult.fail pos₁ (msg₁ ++ msg₂)
| ok => ok
| ok => ok
instance : Alternative Parser :=
{ failure := Parser.failure, orElse := Parser.orElse }
def decorateErrors {α : Type} (msgs : List String) (p : Parser α) : Parser α :=
λ input pos => match p input pos with
| ParseResult.fail _ _ => ParseResult.fail pos msgs
| ok => ok
def decorateError {α : Type} (msg : String) : Parser α → Parser α :=
decorateErrors [ msg ]
def foldrCore {α β : Type} (f : α → β → β) (p : Parser α) (b : β) : Nat → Parser β
| 0 => failure
| reps + 1 => (p >>= λ x => foldrCore f p b reps >>= λ xs => pure (f x xs)) <|> pure b
def foldr {α β : Type} (f : α → β → β) (p : Parser α) (b : β) : Parser β :=
λ input pos => foldrCore f p b (input.length - pos + 1) input pos
def eps : Parser Unit := pure ()
def many {α : Type} (p : Parser α) : Parser (List α) :=
foldr List.cons p []
def many1 {α : Type} (p : Parser α) : Parser (List α) :=
List.cons <$> p <*> many p
def str (p : Parser Char) : Parser String :=
String.mk <$> many p
def sepBy1 {α : Type} (sep : Parser Unit) (p : Parser α) : Parser (List α) :=
List.cons <$> p <*> many (do sep; p)
def sepBy {α : Type} (sep : Parser Unit) (p : Parser α) : Parser (List α) :=
sepBy1 sep p <|> pure []
def fixAux {α : Type} (F : Parser α → Parser α) : Nat → Parser α
| 0 => failure
| maxDepth + 1 => F (fixAux F maxDepth)
def Parser.fix {α : Type} (F : Parser α → Parser α) : Parser α :=
λ input pos => fixAux F (input.length - pos + 1) input pos
def sat (p : Char → Bool) : Parser Char :=
λ input pos =>
if pos < input.length then
let c := input.get pos;
if p c then ParseResult.done (pos + 1) c
else ParseResult.fail pos []
else ParseResult.fail pos []
def ch (c : Char) : Parser Unit :=
decorateError (String.singleton c) (sat (λ x => c == x) >>= λ _ => eps)
def remaining : Parser Nat :=
λ input pos => ParseResult.done pos (input.length - pos)
def eof : Parser Unit :=
decorateError "<end-of-file>" $
do let rem ← remaining; guard (rem = 0)
def Parser.run {α : Type} (p : Parser α) (input : String) : Except String α :=
match (p <* eof) input 0 with
| ParseResult.done pos res => Except.ok res
| ParseResult.fail pos msg =>
Except.error ("expected “" ++ String.intercalate "or " msg ++
"” at " ++ toString pos ++
" in:\n" ++ input.extract (pos - 10) (pos + 10) ++ "...")
|
ce46bbd1dacfbe92749b37364a7f7e7700554571 | 2c41ae31b2b771ad5646ad880201393f5269a7f0 | /Lean/Qualities/Survivable.lean | cb9e05291cca88defc6c502654673c7368062c53 | [] | no_license | kevinsullivan/Boehm | 926f25bc6f1a8b6bd47d333d936fdfc278228312 | 55208395bff20d48a598b7fa33a4d55a2447a9cf | refs/heads/master | 1,586,127,134,302 | 1,488,252,326,000 | 1,488,252,326,000 | 32,836,930 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 667 | lean | -- Survivable
/-
[Survivable] is parameterized by an instance of type [SystemType], and it's a sub-attribute to [Dependable].
An instance of type [SystemType] is deemed [Survivable] if and only if all the requirements are satisfied.
-/
import SystemModel.System
inductive Survivable (sys_type: SystemType): Prop
| intro : (exists survivable: sys_type ^.Contexts -> sys_type ^.Phases -> sys_type ^.Stakeholders -> @SystemInstance sys_type -> Prop,
forall c: sys_type ^.Contexts, forall p: sys_type ^.Phases,
forall s: sys_type ^.Stakeholders, forall st: @SystemInstance sys_type, survivable c p s st) ->
Survivable
|
dda86b6185302425e66de3bd88ba83452194de5d | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/analysis/special_functions/trigonometric/inverse_deriv.lean | ac904bb69220bfd2eb28ccce870a1c893d7b4f2a | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 7,805 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import analysis.special_functions.trigonometric.inverse
import analysis.special_functions.trigonometric.deriv
/-!
# derivatives of the inverse trigonometric functions
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
Derivatives of `arcsin` and `arccos`.
-/
noncomputable theory
open_locale classical topology filter
open set filter
open_locale real
namespace real
section arcsin
lemma deriv_arcsin_aux {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) :
has_strict_deriv_at arcsin (1 / sqrt (1 - x ^ 2)) x ∧ cont_diff_at ℝ ⊤ arcsin x :=
begin
cases h₁.lt_or_lt with h₁ h₁,
{ have : 1 - x ^ 2 < 0, by nlinarith [h₁],
rw [sqrt_eq_zero'.2 this.le, div_zero],
have : arcsin =ᶠ[𝓝 x] λ _, -(π / 2) :=
(gt_mem_nhds h₁).mono (λ y hy, arcsin_of_le_neg_one hy.le),
exact ⟨(has_strict_deriv_at_const _ _).congr_of_eventually_eq this.symm,
cont_diff_at_const.congr_of_eventually_eq this⟩ },
cases h₂.lt_or_lt with h₂ h₂,
{ have : 0 < sqrt (1 - x ^ 2) := sqrt_pos.2 (by nlinarith [h₁, h₂]),
simp only [← cos_arcsin, one_div] at this ⊢,
exact ⟨sin_local_homeomorph.has_strict_deriv_at_symm ⟨h₁, h₂⟩ this.ne'
(has_strict_deriv_at_sin _),
sin_local_homeomorph.cont_diff_at_symm_deriv this.ne' ⟨h₁, h₂⟩
(has_deriv_at_sin _) cont_diff_sin.cont_diff_at⟩ },
{ have : 1 - x ^ 2 < 0, by nlinarith [h₂],
rw [sqrt_eq_zero'.2 this.le, div_zero],
have : arcsin =ᶠ[𝓝 x] λ _, π / 2 := (lt_mem_nhds h₂).mono (λ y hy, arcsin_of_one_le hy.le),
exact ⟨(has_strict_deriv_at_const _ _).congr_of_eventually_eq this.symm,
cont_diff_at_const.congr_of_eventually_eq this⟩ }
end
lemma has_strict_deriv_at_arcsin {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) :
has_strict_deriv_at arcsin (1 / sqrt (1 - x ^ 2)) x :=
(deriv_arcsin_aux h₁ h₂).1
lemma has_deriv_at_arcsin {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) :
has_deriv_at arcsin (1 / sqrt (1 - x ^ 2)) x :=
(has_strict_deriv_at_arcsin h₁ h₂).has_deriv_at
lemma cont_diff_at_arcsin {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) {n : ℕ∞} :
cont_diff_at ℝ n arcsin x :=
(deriv_arcsin_aux h₁ h₂).2.of_le le_top
lemma has_deriv_within_at_arcsin_Ici {x : ℝ} (h : x ≠ -1) :
has_deriv_within_at arcsin (1 / sqrt (1 - x ^ 2)) (Ici x) x :=
begin
rcases em (x = 1) with (rfl|h'),
{ convert (has_deriv_within_at_const _ _ (π / 2)).congr _ _;
simp [arcsin_of_one_le] { contextual := tt } },
{ exact (has_deriv_at_arcsin h h').has_deriv_within_at }
end
lemma has_deriv_within_at_arcsin_Iic {x : ℝ} (h : x ≠ 1) :
has_deriv_within_at arcsin (1 / sqrt (1 - x ^ 2)) (Iic x) x :=
begin
rcases em (x = -1) with (rfl|h'),
{ convert (has_deriv_within_at_const _ _ (-(π / 2))).congr _ _;
simp [arcsin_of_le_neg_one] { contextual := tt } },
{ exact (has_deriv_at_arcsin h' h).has_deriv_within_at }
end
lemma differentiable_within_at_arcsin_Ici {x : ℝ} :
differentiable_within_at ℝ arcsin (Ici x) x ↔ x ≠ -1 :=
begin
refine ⟨_, λ h, (has_deriv_within_at_arcsin_Ici h).differentiable_within_at⟩,
rintro h rfl,
have : sin ∘ arcsin =ᶠ[𝓝[≥] (-1 : ℝ)] id,
{ filter_upwards [Icc_mem_nhds_within_Ici ⟨le_rfl, neg_lt_self (zero_lt_one' ℝ)⟩]
with x using sin_arcsin', },
have := h.has_deriv_within_at.sin.congr_of_eventually_eq this.symm (by simp),
simpa using (unique_diff_on_Ici _ _ left_mem_Ici).eq_deriv _ this (has_deriv_within_at_id _ _)
end
lemma differentiable_within_at_arcsin_Iic {x : ℝ} :
differentiable_within_at ℝ arcsin (Iic x) x ↔ x ≠ 1 :=
begin
refine ⟨λ h, _, λ h, (has_deriv_within_at_arcsin_Iic h).differentiable_within_at⟩,
rw [← neg_neg x, ← image_neg_Ici] at h,
have := (h.comp (-x) differentiable_within_at_id.neg (maps_to_image _ _)).neg,
simpa [(∘), differentiable_within_at_arcsin_Ici] using this
end
lemma differentiable_at_arcsin {x : ℝ} :
differentiable_at ℝ arcsin x ↔ x ≠ -1 ∧ x ≠ 1 :=
⟨λ h, ⟨differentiable_within_at_arcsin_Ici.1 h.differentiable_within_at,
differentiable_within_at_arcsin_Iic.1 h.differentiable_within_at⟩,
λ h, (has_deriv_at_arcsin h.1 h.2).differentiable_at⟩
@[simp] lemma deriv_arcsin : deriv arcsin = λ x, 1 / sqrt (1 - x ^ 2) :=
begin
funext x,
by_cases h : x ≠ -1 ∧ x ≠ 1,
{ exact (has_deriv_at_arcsin h.1 h.2).deriv },
{ rw [deriv_zero_of_not_differentiable_at (mt differentiable_at_arcsin.1 h)],
simp only [not_and_distrib, ne.def, not_not] at h,
rcases h with (rfl|rfl); simp }
end
lemma differentiable_on_arcsin : differentiable_on ℝ arcsin {-1, 1}ᶜ :=
λ x hx, (differentiable_at_arcsin.2
⟨λ h, hx (or.inl h), λ h, hx (or.inr h)⟩).differentiable_within_at
lemma cont_diff_on_arcsin {n : ℕ∞} :
cont_diff_on ℝ n arcsin {-1, 1}ᶜ :=
λ x hx, (cont_diff_at_arcsin (mt or.inl hx) (mt or.inr hx)).cont_diff_within_at
lemma cont_diff_at_arcsin_iff {x : ℝ} {n : ℕ∞} :
cont_diff_at ℝ n arcsin x ↔ n = 0 ∨ (x ≠ -1 ∧ x ≠ 1) :=
⟨λ h, or_iff_not_imp_left.2 $ λ hn, differentiable_at_arcsin.1 $ h.differentiable_at $
enat.one_le_iff_ne_zero.2 hn,
λ h, h.elim (λ hn, hn.symm ▸ (cont_diff_zero.2 continuous_arcsin).cont_diff_at) $
λ hx, cont_diff_at_arcsin hx.1 hx.2⟩
end arcsin
section arccos
lemma has_strict_deriv_at_arccos {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) :
has_strict_deriv_at arccos (-(1 / sqrt (1 - x ^ 2))) x :=
(has_strict_deriv_at_arcsin h₁ h₂).const_sub (π / 2)
lemma has_deriv_at_arccos {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) :
has_deriv_at arccos (-(1 / sqrt (1 - x ^ 2))) x :=
(has_deriv_at_arcsin h₁ h₂).const_sub (π / 2)
lemma cont_diff_at_arccos {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) {n : ℕ∞} :
cont_diff_at ℝ n arccos x :=
cont_diff_at_const.sub (cont_diff_at_arcsin h₁ h₂)
lemma has_deriv_within_at_arccos_Ici {x : ℝ} (h : x ≠ -1) :
has_deriv_within_at arccos (-(1 / sqrt (1 - x ^ 2))) (Ici x) x :=
(has_deriv_within_at_arcsin_Ici h).const_sub _
lemma has_deriv_within_at_arccos_Iic {x : ℝ} (h : x ≠ 1) :
has_deriv_within_at arccos (-(1 / sqrt (1 - x ^ 2))) (Iic x) x :=
(has_deriv_within_at_arcsin_Iic h).const_sub _
lemma differentiable_within_at_arccos_Ici {x : ℝ} :
differentiable_within_at ℝ arccos (Ici x) x ↔ x ≠ -1 :=
(differentiable_within_at_const_sub_iff _).trans differentiable_within_at_arcsin_Ici
lemma differentiable_within_at_arccos_Iic {x : ℝ} :
differentiable_within_at ℝ arccos (Iic x) x ↔ x ≠ 1 :=
(differentiable_within_at_const_sub_iff _).trans differentiable_within_at_arcsin_Iic
lemma differentiable_at_arccos {x : ℝ} :
differentiable_at ℝ arccos x ↔ x ≠ -1 ∧ x ≠ 1 :=
(differentiable_at_const_sub_iff _).trans differentiable_at_arcsin
@[simp] lemma deriv_arccos : deriv arccos = λ x, -(1 / sqrt (1 - x ^ 2)) :=
funext $ λ x, (deriv_const_sub _).trans $ by simp only [deriv_arcsin]
lemma differentiable_on_arccos : differentiable_on ℝ arccos {-1, 1}ᶜ :=
differentiable_on_arcsin.const_sub _
lemma cont_diff_on_arccos {n : ℕ∞} :
cont_diff_on ℝ n arccos {-1, 1}ᶜ :=
cont_diff_on_const.sub cont_diff_on_arcsin
lemma cont_diff_at_arccos_iff {x : ℝ} {n : ℕ∞} :
cont_diff_at ℝ n arccos x ↔ n = 0 ∨ (x ≠ -1 ∧ x ≠ 1) :=
by refine iff.trans ⟨λ h, _, λ h, _⟩ cont_diff_at_arcsin_iff;
simpa [arccos] using (@cont_diff_at_const _ _ _ _ _ _ _ _ _ _ (π / 2)).sub h
end arccos
end real
|
5074428527680af1f51ec20ed5583503ce9cbf83 | 80cc5bf14c8ea85ff340d1d747a127dcadeb966f | /src/tactic/rcases.lean | addbfbe2d999cfbb13a936b52e1ecca0b9aea0e3 | [
"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 | 33,748 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.dlist
import tactic.core
import tactic.clear
/-!
# Recursive cases (`rcases`) tactic and related tactics
`rcases` is a tactic that will perform `cases` recursively, according to a pattern. It is used to
destructure hypotheses or expressions composed of inductive types like `h1 : a ∧ b ∧ c ∨ d` or
`h2 : ∃ x y, trans_rel R x y`. Usual usage might be `rcases h1 with ⟨ha, hb, hc⟩ | hd` or
`rcases h2 with ⟨x, y, _ | ⟨z, hxz, hzy⟩⟩` for these examples.
Each element of an `rcases` pattern is matched against a particular local hypothesis (most of which
are generated during the execution of `rcases` and represent individual elements destructured from
the input expression). An `rcases` pattern has the following grammar:
* A name like `x`, which names the active hypothesis as `x`.
* A blank `_`, which does nothing (letting the automatic naming system used by `cases` name the
hypothesis).
* A hyphen `-`, which clears the active hypothesis and any dependents.
* The keyword `rfl`, which expects the hypothesis to be `h : a = b`, and calls `subst` on the
hypothesis (which has the effect of replacing `b` with `a` everywhere or vice versa).
* A type ascription `p : ty`, which sets the type of the hypothesis to `ty` and then matches it
against `p`. (Of course, `ty` must unify with the actual type of `h` for this to work.)
* A tuple pattern `⟨p1, p2, p3⟩`, which matches a constructor with many arguments, or a series
of nested conjunctions or existentials. For example if the active hypothesis is `a ∧ b ∧ c`,
then the conjunction will be destructured, and `p1` will be matched against `a`, `p2` against `b`
and so on.
* An alteration pattern `p1 | p2 | p3`, which matches an inductive type with multiple constructors,
or a nested disjunction like `a ∨ b ∨ c`.
The patterns are fairly liberal about the exact shape of the constructors, and will insert
additional alternation branches and tuple arguments if there are not enough arguments provided, and
reuse the tail for further matches if there are too many arguments provided to alternation and
tuple patterns.
This file also contains the `obtain` and `rintro` tactics, which use the same syntax of `rcases`
patterns but with a slightly different use case:
* `rintro` (or `rintros`) is used like `rintro x ⟨y, z⟩` and is the same as `intros` followed by
`rcases` on the newly introduced arguments.
* `obtain` is the same as `rcases` but with a syntax styled after `have` rather than `cases`.
`obtain ⟨hx, hy⟩ | hz := foo` is equivalent to `rcases foo with ⟨hx, hy⟩ | hz`. Unlike `rcases`,
`obtain` also allows one to omit `:= foo`, although a type must be provided in this case,
as in `obtain ⟨hx, hy⟩ | hz : a ∧ b ∨ c`, in which case it produces a subgoal for proving
`a ∧ b ∨ c` in addition to the subgoals `hx : a, hy : b |- goal` and `hz : c |- goal`.
## Tags
rcases, rintro, obtain, destructuring, cases, pattern matching, match
-/
open lean lean.parser
namespace tactic
/-!
These synonyms for `list` are used to clarify the meanings of the many
usages of lists in this module.
- `listΣ` is used where a list represents a disjunction, such as the
list of possible constructors of an inductive type.
- `listΠ` is used where a list represents a conjunction, such as the
list of arguments of an individual constructor.
These are merely type synonyms, and so are not checked for consistency
by the compiler.
The `def`/`local notation` combination makes Lean retain these
annotations in reported types.
-/
/-- A list, with a disjunctive meaning (like a list of inductive constructors, or subgoals) -/
@[reducible] def list_Sigma := list
/-- A list, with a conjunctive meaning (like a list of constructor arguments, or hypotheses) -/
@[reducible] def list_Pi := list
local notation `listΣ` := list_Sigma
local notation `listΠ` := list_Pi
/-- A metavariable representing a subgoal, together with a list of local constants to clear. -/
@[reducible] meta def uncleared_goal := list expr × expr
/--
An `rcases` pattern can be one of the following, in a nested combination:
* A name like `foo`
* The special keyword `rfl` (for pattern matching on equality using `subst`)
* A hyphen `-`, which clears the active hypothesis and any dependents.
* A type ascription like `pat : ty` (parentheses are optional)
* A tuple constructor like `⟨p1, p2, p3⟩`
* An alternation / variant pattern `p1 | p2 | p3`
Parentheses can be used for grouping; alternation is higher precedence than type ascription, so
`p1 | p2 | p3 : ty` means `(p1 | p2 | p3) : ty`.
N-ary alternations are treated as a group, so `p1 | p2 | p3` is not the same as `p1 | (p2 | p3)`,
and similarly for tuples. However, note that an n-ary alternation or tuple can match an n-ary
conjunction or disjunction, because if the number of patterns exceeds the number of constructors in
the type being destructed, the extra patterns will match on the last element, meaning that
`p1 | p2 | p3` will act like `p1 | (p2 | p3)` when matching `a1 ∨ a2 ∨ a3`. If matching against a
type with 3 constructors, `p1 | (p2 | p3)` will act like `p1 | (p2 | p3) | _` instead.
-/
meta inductive rcases_patt : Type
| one : name → rcases_patt
| clear : rcases_patt
| typed : rcases_patt → pexpr → rcases_patt
| tuple : listΠ rcases_patt → rcases_patt
| alts : listΣ rcases_patt → rcases_patt
namespace rcases_patt
meta instance inhabited : inhabited rcases_patt :=
⟨one `_⟩
/-- Get the name from a pattern, if provided -/
meta def name : rcases_patt → option name
| (one `_) := none
| (one `rfl) := none
| (one n) := some n
| (typed p _) := p.name
| (alts [p]) := p.name
| _ := none
/-- Interpret an rcases pattern as a tuple, where `p` becomes `⟨p⟩`
if `p` is not already a tuple. -/
meta def as_tuple : rcases_patt → listΠ rcases_patt
| (tuple ps) := ps
| p := [p]
/-- Interpret an rcases pattern as an alternation, where non-alternations are treated as one
alternative. -/
meta def as_alts : rcases_patt → listΣ rcases_patt
| (alts ps) := ps
| p := [p]
/-- Convert a list of patterns to a tuple pattern, but mapping `[p]` to `p` instead of `⟨p⟩`. -/
meta def tuple' : listΠ rcases_patt → rcases_patt
| [p] := p
| ps := tuple ps
/-- Convert a list of patterns to an alternation pattern, but mapping `[p]` to `p` instead of
a unary alternation `|p`. -/
meta def alts' : listΣ rcases_patt → rcases_patt
| [p] := p
| ps := alts ps
/-- This function is used for producing rcases patterns based on a case tree. Suppose that we have
a list of patterns `ps` that will match correctly against the branches of the case tree for one
constructor. This function will merge tuples at the end of the list, so that `[a, b, ⟨c, d⟩]`
becomes `⟨a, b, c, d⟩` instead of `⟨a, b, ⟨c, d⟩⟩`.
We must be careful to turn `[a, ⟨⟩]` into `⟨a, ⟨⟩⟩` instead of `⟨a⟩` (which will not perform the
nested match). -/
meta def tuple₁_core : listΠ rcases_patt → listΠ rcases_patt
| [] := []
| [tuple []] := [tuple []]
| [tuple ps] := ps
| (p :: ps) := p :: tuple₁_core ps
/-- This function is used for producing rcases patterns based on a case tree. This is like
`tuple₁_core` but it produces a pattern instead of a tuple pattern list, converting `[n]` to `n`
instead of `⟨n⟩` and `[]` to `_`, and otherwise just converting `[a, b, c]` to `⟨a, b, c⟩`. -/
meta def tuple₁ : listΠ rcases_patt → rcases_patt
| [] := default _
| [one n] := one n
| ps := tuple (tuple₁_core ps)
/-- This function is used for producing rcases patterns based on a case tree. Here we are given
the list of patterns to apply to each argument of each constructor after the main case, and must
produce a list of alternatives with the same effect. This function calls `tuple₁` to make the
individual alternatives, and handles merging `[a, b, c | d]` to `a | b | c | d` instead of
`a | b | (c | d)`. -/
meta def alts₁_core : listΣ (listΠ rcases_patt) → listΣ rcases_patt
| [] := []
| [[alts ps]] := ps
| (p :: ps) := tuple₁ p :: alts₁_core ps
/-- This function is used for producing rcases patterns based on a case tree. This is like
`alts₁_core`, but it produces a cases pattern directly instead of a list of alternatives. We
specially translate the empty alternation to `⟨⟩`, and translate `|(a | b)` to `⟨a | b⟩` (because we
don't have any syntax for unary alternation). Otherwise we can use the regular merging of
alternations at the last argument so that `a | b | (c | d)` becomes `a | b | c | d`. -/
meta def alts₁ : listΣ (listΠ rcases_patt) → rcases_patt
| [[]] := tuple []
| [[alts ps]] := tuple [alts ps]
| ps := alts' (alts₁_core ps)
meta instance has_reflect : has_reflect rcases_patt
| (one n) := `(_)
| clear := `(_)
| (typed l e) :=
(`(typed).subst (has_reflect l)).subst (reflect e)
| (tuple l) := `(λ l, tuple l).subst $
by haveI := has_reflect; exact list.reflect l
| (alts l) := `(λ l, alts l).subst $
by haveI := has_reflect; exact list.reflect l
/-- Formats an `rcases` pattern. If the `bracket` argument is true, then it will be
printed at high precedence, i.e. it will have parentheses around it if it is not already a tuple
or atomic name. -/
protected meta def format : ∀ bracket : bool, rcases_patt → tactic _root_.format
| _ (one n) := pure $ to_fmt n
| _ clear := pure "-"
| _ (tuple []) := pure "⟨⟩"
| _ (tuple ls) := do
fs ← ls.mmap $ format ff,
pure $ "⟨" ++ _root_.format.group (_root_.format.nest 1 $
_root_.format.join $ list.intersperse ("," ++ _root_.format.line) fs) ++ "⟩"
| br (alts ls) := do
fs ← ls.mmap $ format tt,
let fmt := _root_.format.join $ list.intersperse (↑" |" ++ _root_.format.space) fs,
pure $ if br then _root_.format.bracket "(" ")" fmt else fmt
| br (typed p e) := do
fp ← format ff p,
fe ← pp e,
let fmt := fp ++ " : " ++ fe,
pure $ if br then _root_.format.bracket "(" ")" fmt else fmt
meta instance has_to_tactic_format : has_to_tactic_format rcases_patt := ⟨rcases_patt.format ff⟩
end rcases_patt
/-- Takes the number of fields of a single constructor and patterns to match its fields against
(not necessarily the same number). The returned lists each contain one element per field of the
constructor. The `name` is the name which will be used in the top-level `cases` tactic, and the
`rcases_patt` is the pattern which the field will be matched against by subsequent `cases`
tactics. -/
meta def rcases.process_constructor :
nat → listΠ rcases_patt → listΠ name × listΠ rcases_patt
| 0 ps := ([], [])
| 1 [] := ([`_], [default _])
| 1 [p] := ([p.name.get_or_else `_], [p])
-- The interesting case: we matched the last field against multiple
-- patterns, so split off the remaining patterns into a subsequent
-- match. This handles matching `α × β × γ` against `⟨a, b, c⟩`.
| 1 ps := ([`_], [rcases_patt.tuple ps])
| (n+1) ps :=
let hd := ps.head, (ns, tl) := rcases.process_constructor n ps.tail in
(hd.name.get_or_else `_ :: ns, hd :: tl)
/-- Takes a list of constructor names, and an (alternation) list of patterns, and matches each
pattern against its constructor. It returns the list of names that will be passed to `cases`,
and the list of `(constructor name, patterns)` for each constructor, where `patterns` is the
(conjunctive) list of patterns to apply to each constructor argument. -/
meta def rcases.process_constructors (params : nat) :
listΣ name → listΣ rcases_patt →
tactic (dlist name × listΣ (name × listΠ rcases_patt))
| [] ps := pure (dlist.empty, [])
| (c::cs) ps := do
n ← mk_const c >>= get_arity,
let (h, t) := (match cs, ps.tail with
-- We matched the last constructor against multiple patterns,
-- so split off the remaining constructors. This handles matching
-- `α ⊕ β ⊕ γ` against `a|b|c`.
| [], _::_ := ([rcases_patt.alts ps], [])
| _, _ := (ps.head.as_tuple, ps.tail)
end : _),
let (ns, ps) := rcases.process_constructor (n - params) h,
(l, r) ← rcases.process_constructors cs t,
pure (dlist.of_list ns ++ l, (c, ps) :: r)
/-- Like `zip`, but only elements satisfying a matching predicate `p` will go in the list,
and elements of the first list that fail to match the second list will be skipped. -/
private def align {α β} (p : α → β → Prop) [∀ a b, decidable (p a b)] :
list α → list β → list (α × β)
| (a::as) (b::bs) :=
if p a b then (a, b) :: align as bs else align as (b::bs)
| _ _ := []
/-- Given a local constant `e`, get its type. *But* if `e` does not exist, go find a hypothesis
with the same pretty name as `e` and get it instead. This is needed because we can sometimes lose
track of the unique names of hypotheses when they are revert/intro'd by `change` and `cases`. (A
better solution would be for these tactics to return a map of renamed hypotheses so that we don't
lose track of them.) -/
private meta def get_local_and_type (e : expr) : tactic (expr × expr) :=
(do t ← infer_type e, pure (t, e)) <|> (do
e ← get_local e.local_pp_name,
t ← infer_type e, pure (t, e))
/--
* `rcases_core p e` will match a pattern `p` against a local hypothesis `e`.
It returns the list of subgoals that were produced.
* `rcases.continue pes` will match a (conjunctive) list of `(p, e)` pairs which refer to
patterns and local hypotheses to match against, and applies all of them. Note that this can
involve matching later arguments multiple times given earlier arguments, for example
`⟨a | b, ⟨c, d⟩⟩` performs the `⟨c, d⟩` match twice, once on the `a` branch and once on `b`.
-/
meta mutual def rcases_core, rcases.continue
with rcases_core : rcases_patt → expr → tactic (list uncleared_goal)
| (rcases_patt.one `rfl) e := do
(t, e) ← get_local_and_type e,
subst e,
list.map (prod.mk []) <$> get_goals
-- If the pattern is any other name, we already bound the name in the
-- top-level `cases` tactic, so there is no more work to do for it.
| (rcases_patt.one _) _ := list.map (prod.mk []) <$> get_goals
| rcases_patt.clear e := do
m ← try_core (get_local_and_type e),
list.map (prod.mk $ m.elim [] (λ ⟨_, e⟩, [e])) <$> get_goals
| (rcases_patt.typed p ty) e := do
(t, e) ← get_local_and_type e,
ty ← i_to_expr_no_subgoals ``(%%ty : Sort*),
unify t ty,
t ← instantiate_mvars t,
ty ← instantiate_mvars ty,
e ← if t =ₐ ty then pure e else
change_core ty (some e) >> get_local e.local_pp_name,
rcases_core p e
| (rcases_patt.alts [p]) e := rcases_core p e
| pat e := do
(t, e) ← get_local_and_type e,
t ← whnf t,
env ← get_env,
let I := t.get_app_fn.const_name,
let pat := pat.as_alts,
(ids, r, l) ← (if I ≠ `quot
then do
when (¬env.is_inductive I) $
fail format!"rcases tactic failed: {e} : {I} is not an inductive datatype",
let params := env.inductive_num_params I,
let c := env.constructors_of I,
(ids, r) ← rcases.process_constructors params c pat,
l ← cases_core e ids.to_list,
pure (ids, r, l)
else do
(ids, r) ← rcases.process_constructors 2 [`quot.mk] pat,
[(_, d)] ← induction e ids.to_list `quot.induction_on |
fail format!"quotient induction on {e} failed. Maybe goal is not in Prop?",
-- the result from `induction` is missing the information that the original constructor was
-- `quot.mk` so we fix this up:
pure (ids, r, [(`quot.mk, d)])),
gs ← get_goals,
-- `cases_core` may not generate a new goal for every constructor,
-- as some constructors may be impossible for type reasons. (See its
-- documentation.) Match up the new goals with our remaining work
-- by constructor name.
let ls := align (λ (a : name × _) (b : _ × name × _), a.1 = b.2.1) r (gs.zip l),
list.join <$> ls.mmap (λ⟨⟨_, ps⟩, g, _, hs, _⟩, set_goals [g] >> rcases.continue (ps.zip hs))
with rcases.continue : listΠ (rcases_patt × expr) → tactic (list uncleared_goal)
| [] := list.map (prod.mk []) <$> get_goals
| ((pat, e) :: pes) := do
gs ← rcases_core pat e,
list.join <$> gs.mmap (λ ⟨cs, g⟩, do
set_goals [g],
ugs ← rcases.continue pes,
pure $ ugs.map $ λ ⟨cs', gs⟩, (cs ++ cs', gs))
/-- Given a list of `uncleared_goal`s, each of which is a goal metavariable and
a list of variables to clear, actually perform the clear and set the goals with the result. -/
meta def clear_goals (ugs : list uncleared_goal) : tactic unit := do
gs ← ugs.mmap (λ ⟨cs, g⟩, do
set_goals [g],
cs ← cs.mfoldr (λ c cs,
(do (_, c) ← get_local_and_type c, pure (c :: cs)) <|> pure cs) [],
clear' tt cs,
[g] ← get_goals,
pure g),
set_goals gs
/-- `rcases h e pat` performs case distinction on `e` using `pat` to
name the arising new variables and assumptions. If `h` is `some` name,
a new assumption `h : e = pat` will relate the expression `e` with the
current pattern. See the module comment for the syntax of `pat`. -/
meta def rcases (h : option name) (p : pexpr) (pat : rcases_patt) : tactic unit := do
let p := match pat with
| rcases_patt.typed _ ty := ``(%%p : %%ty)
| _ := p
end,
e ← match h with
| some h := do
x ← get_unused_name $ pat.name.get_or_else `this,
interactive.generalize h () (p, x),
get_local x
| none := i_to_expr p
end,
if e.is_local_constant then
focus1 (rcases_core pat e >>= clear_goals)
else do
x ← pat.name.elim mk_fresh_name pure,
n ← revert_kdependencies e semireducible,
tactic.generalize e x <|> (do
t ← infer_type e,
tactic.assertv x t e,
get_local x >>= tactic.revert,
pure ()),
h ← tactic.intro1,
focus1 (rcases_core pat h >>= clear_goals)
/-- `rintro pat₁ pat₂ ... patₙ` introduces `n` arguments, then pattern matches on the `patᵢ` using
the same syntax as `rcases`. -/
meta def rintro (ids : listΠ rcases_patt) : tactic unit :=
do l ← ids.mmap (λ id, do
e ← intro $ id.name.get_or_else `_,
pure (id, e)),
focus1 (rcases.continue l >>= clear_goals)
/-- Like `zip_with`, but if the lists don't match in length, the excess elements will be put at the
end of the result. -/
def merge_list {α} (m : α → α → α) : list α → list α → list α
| [] l₂ := l₂
| l₁ [] := l₁
| (a :: l₁) (b :: l₂) := m a b :: merge_list l₁ l₂
/-- Merge two `rcases` patterns. This is used to underapproximate a case tree by an `rcases`
pattern. The two patterns come from cases in two branches, that due to the syntax of `rcases`
patterns are forced to overlap. The rule here is that we take only the case splits that are in
common between both branches. For example if one branch does `⟨a, b⟩` and the other does `c`,
then we return `c` because we don't know that a case on `c` would be safe to do. -/
meta def rcases_patt.merge : rcases_patt → rcases_patt → rcases_patt
| (rcases_patt.alts p₁) p₂ := rcases_patt.alts (merge_list rcases_patt.merge p₁ p₂.as_alts)
| p₁ (rcases_patt.alts p₂) := rcases_patt.alts (merge_list rcases_patt.merge p₁.as_alts p₂)
| (rcases_patt.tuple p₁) p₂ := rcases_patt.tuple (merge_list rcases_patt.merge p₁ p₂.as_tuple)
| p₁ (rcases_patt.tuple p₂) := rcases_patt.tuple (merge_list rcases_patt.merge p₁.as_tuple p₂)
| (rcases_patt.typed p₁ e) p₂ := rcases_patt.typed (p₁.merge p₂) e
| p₁ (rcases_patt.typed p₂ e) := rcases_patt.typed (p₁.merge p₂) e
| (rcases_patt.one `rfl) (rcases_patt.one `rfl) := rcases_patt.one `rfl
| (rcases_patt.one `_) p := p
| p (rcases_patt.one `_) := p
| rcases_patt.clear p := p
| p rcases_patt.clear := p
| (rcases_patt.one n) _ := rcases_patt.one n
/--
* `rcases_hint_core depth e` does the same as `rcases p e`, except the pattern `p` is an output
instead of an input, controlled only by the case depth argument `depth`. We use `cases` to depth
`depth` and then reconstruct an `rcases` pattern `p` that would, if passed to `rcases`, perform
the same thing as the case tree we just constructed (or at least, the nearest expressible
approximation to this.)
* `rcases_hint.process_constructors depth cs l` takes a list of constructor names `cs` and a
matching list `l` of elements `(g, c', hs, _)` where `c'` is a constructor name (used for
alignment with `cs`), `g` is the subgoal, and `hs` is the list of local hypotheses created by
`cases` in that subgoal. It matches on all of them, and then produces a `ΣΠ`-list of `rcases`
patterns describing the result, and the list of generated subgoals.
* `rcases_hint.continue depth es` does the same as `rcases.continue (ps.zip es)`, except the
patterns `ps` are an output instead of an input, created by matching on everything to depth
`depth` and recording the successful cases. It returns `ps`, and the list of generated subgoals.
-/
meta mutual def rcases_hint_core, rcases_hint.process_constructors, rcases_hint.continue
with rcases_hint_core : ℕ → expr → tactic (rcases_patt × list expr)
| depth e := do
(t, e) ← get_local_and_type e,
t ← whnf t,
env ← get_env,
let I := t.get_app_fn.const_name,
(do guard (I = ``eq),
subst e,
prod.mk (rcases_patt.one `rfl) <$> get_goals) <|>
(do
let c := env.constructors_of I,
some l ← try_core (guard (depth ≠ 0) >> cases_core e) |
prod.mk (rcases_patt.one e.local_pp_name) <$> get_goals,
gs ← get_goals,
(ps, gs') ← rcases_hint.process_constructors (depth - 1) c (gs.zip l),
pure (rcases_patt.alts₁ ps, gs'))
with rcases_hint.process_constructors : ℕ → listΣ name →
list (expr × name × listΠ expr × list (name × expr)) →
tactic (listΣ (listΠ rcases_patt) × list expr)
| depth [] _ := pure ([], [])
| depth cs [] := pure (cs.map (λ _, []), [])
| depth (c::cs) ((g, c', hs, _) :: l) :=
if c ≠ c' then do
(ps, gs) ← rcases_hint.process_constructors depth cs l,
pure (default _ :: ps, gs)
else do
(p, gs) ← set_goals [g] >> rcases_hint.continue depth hs,
(ps, gs') ← rcases_hint.process_constructors depth cs l,
pure (p :: ps, gs ++ gs')
with rcases_hint.continue : ℕ → listΠ expr → tactic (listΠ rcases_patt × list expr)
| depth [] := prod.mk [] <$> get_goals
| depth (e :: es) := do
(p, gs) ← rcases_hint_core depth e,
(ps, gs') ← gs.mfoldl (λ (r : listΠ rcases_patt × list expr) g,
do (ps, gs') ← set_goals [g] >> rcases_hint.continue depth es,
pure (merge_list rcases_patt.merge r.1 ps, r.2 ++ gs')) ([], []),
pure (p :: ps, gs')
/--
* `rcases? e` is like `rcases e with ...`, except it generates `...` by matching on everything it
can, and it outputs an `rcases` invocation that should have the same effect.
* `rcases? e : n` can be used to control the depth of case splits (especially important for
recursive types like `nat`, which can be cased as many times as you like). -/
meta def rcases_hint (p : pexpr) (depth : nat) : tactic rcases_patt :=
do e ← i_to_expr p,
if e.is_local_constant then
focus1 $ do (p, gs) ← rcases_hint_core depth e, set_goals gs, pure p
else do
x ← mk_fresh_name,
n ← revert_kdependencies e semireducible,
tactic.generalize e x <|> (do
t ← infer_type e,
tactic.assertv x t e,
get_local x >>= tactic.revert,
pure ()),
h ← tactic.intro1,
focus1 $ do (p, gs) ← rcases_hint_core depth h, set_goals gs, pure p
/--
* `rintro?` is like `rintro ...`, except it generates `...` by introducing and matching on
everything it can, and it outputs an `rintro` invocation that should have the same effect.
* `rintro? : n` can be used to control the depth of case splits (especially important for
recursive types like `nat`, which can be cased as many times as you like). -/
meta def rintro_hint (depth : nat) : tactic (listΠ rcases_patt) :=
do l ← intros,
focus1 $ do
(p, gs) ← rcases_hint.continue depth l,
set_goals gs,
pure p
setup_tactic_parser
/--
* `rcases_patt_parse tt` will parse a high precedence `rcases` pattern, `patt_hi`.
This means only tuples and identifiers are allowed; alternations and type ascriptions
require `(...)` instead, which switches to `patt`.
* `rcases_patt_parse ff` will parse a low precedence `rcases` pattern, `patt`. This consists of a
`patt_med` (which deals with alternations), optionally followed by a `: ty` type ascription. The
expression `ty` is at `texpr` precedence because it can appear at the end of a tactic, for
example in `rcases e with x : ty <|> skip`.
* `rcases_patt_parse_list` will parse an alternation list, `patt_med`, one or more `patt`
patterns separated by `|`. It does not parse a `:` at the end, so that `a | b : ty` parses as
`(a | b) : ty` where `a | b` is the `patt_med` part.
* `rcases_patt_parse_list_rest a` parses an alternation list after the initial pattern, `| b | c`.
```lean
patt ::= patt_med (":" expr)?
patt_med ::= (patt_hi "|")* patt_hi
patt_hi ::= id | "rfl" | "_" | "⟨" (patt ",")* patt "⟩" | "(" patt ")"
```
-/
meta mutual def rcases_patt_parse, rcases_patt_parse_list, rcases_patt_parse_list_rest
with rcases_patt_parse : bool → parser rcases_patt
| tt := with_desc "patt_hi" $
(brackets "(" ")" (rcases_patt_parse ff)) <|>
(rcases_patt.tuple <$> brackets "⟨" "⟩" (sep_by (tk ",") (rcases_patt_parse ff))) <|>
(tk "-" $> rcases_patt.clear) <|>
(rcases_patt.one <$> ident_)
| ff := with_desc "patt" $ do
pat ← rcases_patt.alts' <$> rcases_patt_parse_list,
(tk ":" *> pat.typed <$> texpr) <|> pure pat
with rcases_patt_parse_list : parser (listΣ rcases_patt)
| x := (with_desc "patt_med" $ rcases_patt_parse tt >>= rcases_patt_parse_list_rest) x
with rcases_patt_parse_list_rest : rcases_patt → parser (listΣ rcases_patt)
| pat :=
(tk "|" *> list.cons pat <$> rcases_patt_parse_list) <|>
-- hack to support `-|-` patterns, because `|-` is a token
(tk "|-" *> list.cons pat <$> rcases_patt_parse_list_rest rcases_patt.clear) <|>
pure [pat]
/-- Parse the optional depth argument `(: n)?` of `rcases?` and `rintro?`, with default depth 5. -/
meta def rcases_parse_depth : parser nat :=
do o ← (tk ":" *> small_nat)?, pure $ o.get_or_else 5
precedence `?`:max
/-- Syntax for a `rcases` pattern:
* `rcases? expr (: n)?`
* `rcases (h :)? expr (with patt_list (: expr)?)?`. -/
meta def rcases_parse : parser (pexpr × ((option name × rcases_patt) ⊕ nat)) :=
with_desc "('?' expr (: n)?) | ((h :)? expr (with patt)?)" $ do
hint ← (tk "?")?,
p ← texpr,
match hint with
| none := do
(h, p) ←
(do expr.local_const h _ _ _ ← pure p, tk ":" *> prod.mk (some h) <$> texpr) <|>
pure (none, p),
ids ← (tk "with" *> rcases_patt_parse ff)?,
pure (p, sum.inl (h, ids.get_or_else (rcases_patt.tuple [])))
| some _ := do depth ← rcases_parse_depth, pure (p, sum.inr depth)
end
/-- Syntax for a `rintro` pattern: `('?' (: n)?) | patt*`. -/
meta def rintro_parse : parser (listΠ rcases_patt ⊕ nat) :=
with_desc "('?' (: n)?) | patt*" $
(tk "?" >> sum.inr <$> rcases_parse_depth) <|>
sum.inl <$> (rcases_patt_parse tt)*
namespace interactive
open interactive interactive.types expr
/--
`rcases` is a tactic that will perform `cases` recursively, according to a pattern. It is used to
destructure hypotheses or expressions composed of inductive types like `h1 : a ∧ b ∧ c ∨ d` or
`h2 : ∃ x y, trans_rel R x y`. Usual usage might be `rcases h1 with ⟨ha, hb, hc⟩ | hd` or
`rcases h2 with ⟨x, y, _ | ⟨z, hxz, hzy⟩⟩` for these examples.
Each element of an `rcases` pattern is matched against a particular local hypothesis (most of which
are generated during the execution of `rcases` and represent individual elements destructured from
the input expression). An `rcases` pattern has the following grammar:
* A name like `x`, which names the active hypothesis as `x`.
* A blank `_`, which does nothing (letting the automatic naming system used by `cases` name the
hypothesis).
* A hyphen `-`, which clears the active hypothesis and any dependents.
* The keyword `rfl`, which expects the hypothesis to be `h : a = b`, and calls `subst` on the
hypothesis (which has the effect of replacing `b` with `a` everywhere or vice versa).
* A type ascription `p : ty`, which sets the type of the hypothesis to `ty` and then matches it
against `p`. (Of course, `ty` must unify with the actual type of `h` for this to work.)
* A tuple pattern `⟨p1, p2, p3⟩`, which matches a constructor with many arguments, or a series
of nested conjunctions or existentials. For example if the active hypothesis is `a ∧ b ∧ c`,
then the conjunction will be destructured, and `p1` will be matched against `a`, `p2` against `b`
and so on.
* An alteration pattern `p1 | p2 | p3`, which matches an inductive type with multiple constructors,
or a nested disjunction like `a ∨ b ∨ c`.
A pattern like `⟨a, b, c⟩ | ⟨d, e⟩` will do a split over the inductive datatype,
naming the first three parameters of the first constructor as `a,b,c` and the
first two of the second constructor `d,e`. If the list is not as long as the
number of arguments to the constructor or the number of constructors, the
remaining variables will be automatically named. If there are nested brackets
such as `⟨⟨a⟩, b | c⟩ | d` then these will cause more case splits as necessary.
If there are too many arguments, such as `⟨a, b, c⟩` for splitting on
`∃ x, ∃ y, p x`, then it will be treated as `⟨a, ⟨b, c⟩⟩`, splitting the last
parameter as necessary.
`rcases` also has special support for quotient types: quotient induction into Prop works like
matching on the constructor `quot.mk`.
`rcases h : e with PAT` will do the same as `rcases e with PAT` with the exception that an assumption
`h : e = PAT` will be added to the context.
`rcases? e` will perform case splits on `e` in the same way as `rcases e`,
but rather than accepting a pattern, it does a maximal cases and prints the
pattern that would produce this case splitting. The default maximum depth is 5,
but this can be modified with `rcases? e : n`.
-/
meta def rcases : parse rcases_parse → tactic unit
| (p, sum.inl (h, ids)) := tactic.rcases h p ids
| (p, sum.inr depth) := do
patt ← tactic.rcases_hint p depth,
pe ← pp p,
ppat ← pp patt,
trace $ ↑"Try this: rcases " ++ pe ++ " with " ++ ppat
add_tactic_doc
{ name := "rcases",
category := doc_category.tactic,
decl_names := [`tactic.interactive.rcases],
tags := ["induction"] }
/--
The `rintro` tactic is a combination of the `intros` tactic with `rcases` to
allow for destructuring patterns while introducing variables. See `rcases` for
a description of supported patterns. For example, `rintro (a | ⟨b, c⟩) ⟨d, e⟩`
will introduce two variables, and then do case splits on both of them producing
two subgoals, one with variables `a d e` and the other with `b c d e`.
`rintro?` will introduce and case split on variables in the same way as
`rintro`, but will also print the `rintro` invocation that would have the same
result. Like `rcases?`, `rintro? : n` allows for modifying the
depth of splitting; the default is 5.
`rintros` is an alias for `rintro`.
-/
meta def rintro : parse rintro_parse → tactic unit
| (sum.inl []) := intros []
| (sum.inl l) := tactic.rintro l
| (sum.inr depth) := do
ps ← tactic.rintro_hint depth,
fs ← ps.mmap (λ p, do
f ← pp $ p.format tt,
pure $ format.space ++ format.group f),
trace $ ↑"Try this: rintro" ++ format.join fs
/-- Alias for `rintro`. -/
meta def rintros := rintro
add_tactic_doc
{ name := "rintro",
category := doc_category.tactic,
decl_names := [`tactic.interactive.rintro, `tactic.interactive.rintros],
tags := ["induction"],
inherit_description_from := `tactic.interactive.rintro }
setup_tactic_parser
/-- Parses `patt? (: expr)?`. (This is almost the same as `-/
meta def obtain_parse : parser (option rcases_patt × option pexpr) :=
with_desc "patt? (: expr)?" $
(do pat ← rcases_patt_parse ff,
pure $ match pat with
| rcases_patt.typed pat tp := (some pat, some tp)
| _ := (some pat, none)
end) <|>
prod.mk none <$> (tk ":" >> texpr)?
/--
The `obtain` tactic is a combination of `have` and `rcases`. See `rcases` for
a description of supported patterns.
```lean
obtain ⟨patt⟩ : type,
{ ... }
```
is equivalent to
```lean
have h : type,
{ ... },
rcases h with ⟨patt⟩
```
The syntax `obtain ⟨patt⟩ : type := proof` is also supported.
If `⟨patt⟩` is omitted, `rcases` will try to infer the pattern.
If `type` is omitted, `:= proof` is required.
-/
meta def obtain : parse obtain_parse → parse (tk ":=" >> texpr)? → tactic unit
| (pat, none) (some val) := tactic.rcases none val (pat.get_or_else (default _))
| (pat, some tp) (some val) := tactic.rcases none val $ (pat.get_or_else (default _)).typed tp
| (pat, some tp) none := do
nm ← mk_fresh_name,
e ← to_expr tp >>= assert nm,
(g :: gs) ← get_goals,
set_goals gs,
tactic.rcases none ``(%%e) (pat.get_or_else (rcases_patt.one `this)),
gs ← get_goals,
set_goals (g::gs)
| (pat, none) none :=
fail $ "`obtain` requires either an expected type or a value.\n" ++
"usage: `obtain ⟨patt⟩? : type (:= val)?` or `obtain ⟨patt⟩? (: type)? := val`"
add_tactic_doc
{ name := "obtain",
category := doc_category.tactic,
decl_names := [`tactic.interactive.obtain],
tags := ["induction"] }
end interactive
end tactic
|
3229dc38541fb215ada0bda1c7c6e97f359f36e1 | 6b45072eb2b3db3ecaace2a7a0241ce81f815787 | /data/int/order.lean | e7d90ffa64bd76cba4cf9d18edb1704a5e9cea4e | [] | no_license | avigad/library_dev | 27b47257382667b5eb7e6476c4f5b0d685dd3ddc | 9d8ac7c7798ca550874e90fed585caad030bbfac | refs/heads/master | 1,610,452,468,791 | 1,500,712,839,000 | 1,500,713,478,000 | 69,311,142 | 1 | 0 | null | 1,474,942,903,000 | 1,474,942,902,000 | null | UTF-8 | Lean | false | false | 7,356 | lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
The order relation on the integers.
-/
import .basic
namespace int
end int
/-
/- more facts specific to int -/
theorem coe_nat_nonneg (n : ℕ) : 0 ≤ ↑n := trivial
theorem coe_nat_pos {n : ℕ} (Hpos : #nat n > 0) : ↑n > 0 :=
coe_nat_lt_coe_nat_of_lt Hpos
theorem coe_nat_succ_pos (n : nat) : ↑(nat.succ n) > 0 :=
coe_nat_pos !nat.succ_pos
theorem exists_eq_coe_nat {a : ℤ} (H : 0 ≤ a) : ∃n : ℕ, a = ↑n :=
obtain (n : ℕ) (H1 : 0 + ↑n = a), from le.dest H,
exists.intro n (!zero_add ▸ (H1⁻¹))
theorem exists_eq_neg_coe_nat {a : ℤ} (H : a ≤ 0) : ∃n : ℕ, a = -(↑n) :=
have -a ≥ 0, from iff.mpr !neg_nonneg_iff_nonpos H,
obtain (n : ℕ) (Hn : -a = ↑n), from exists_eq_coe_nat this,
exists.intro n (eq_neg_of_eq_neg (Hn⁻¹))
theorem coe_nat_nat_abs_of_nonneg {a : ℤ} (H : a ≥ 0) : ↑(nat_abs a) = a :=
obtain (n : ℕ) (Hn : a = ↑n), from exists_eq_coe_nat H,
Hn⁻¹ ▸ congr_arg coe_nat (nat_abs_↑n)
theorem coe_nat_nat_abs_of_nonpos {a : ℤ} (H : a ≤ 0) : ↑(nat_abs a) = -a :=
have -a ≥ 0, from iff.mpr !neg_nonneg_iff_nonpos H,
calc
coe_nat (nat_abs a) = coe_nat (nat_abs (-a)) : nat_abs_neg
... = -a : coe_nat_nat_abs_of_nonneg this
theorem coe_nat_nat_abs (b : ℤ) : nat_abs b = abs b :=
or.elim (le.total 0 b)
(assume H : b ≥ 0, coe_nat_nat_abs_of_nonneg H ⬝ (abs_of_nonneg H)⁻¹)
(assume H : b ≤ 0, coe_nat_nat_abs_of_nonpos H ⬝ (abs_of_nonpos H)⁻¹)
theorem nat_abs_abs (a : ℤ) : nat_abs (abs a) = nat_abs a :=
abs.by_cases rfl !nat_abs_neg
theorem lt_of_add_one_le {a b : ℤ} (H : a + 1 ≤ b) : a < b :=
obtain (n : nat) (H1 : a + 1 + n = b), from le.dest H,
have a + succ n = b, by rewrite [←H1, add.assoc, add.comm 1],
lt.intro this
theorem add_one_le_of_lt {a b : ℤ} (H : a < b) : a + 1 ≤ b :=
obtain (n : nat) (H1 : a + succ n = b), from lt.elim H,
have a + 1 + n = b, by rewrite [←H1, add.assoc, add.comm 1],
le.intro this
theorem lt_add_one_of_le {a b : ℤ} (H : a ≤ b) : a < b + 1 :=
lt_add_of_le_of_pos H trivial
theorem le_of_lt_add_one {a b : ℤ} (H : a < b + 1) : a ≤ b :=
have H1 : a + 1 ≤ b + 1, from add_one_le_of_lt H,
le_of_add_le_add_right H1
theorem sub_one_le_of_lt {a b : ℤ} (H : a ≤ b) : a - 1 < b :=
lt_of_add_one_le (begin rewrite sub_add_cancel, exact H end)
theorem lt_of_sub_one_le {a b : ℤ} (H : a - 1 < b) : a ≤ b :=
!sub_add_cancel ▸ add_one_le_of_lt H
theorem le_sub_one_of_lt {a b : ℤ} (H : a < b) : a ≤ b - 1 :=
le_of_lt_add_one begin rewrite sub_add_cancel, exact H end
theorem lt_of_le_sub_one {a b : ℤ} (H : a ≤ b - 1) : a < b :=
!sub_add_cancel ▸ (lt_add_one_of_le H)
theorem sign_of_succ (n : nat) : sign (nat.succ n) = 1 :=
sign_of_pos (coe_nat_pos !nat.succ_pos)
theorem exists_eq_neg_succ_coe_nat {a : ℤ} : a < 0 → ∃m : ℕ, a = -[1+m] :=
int.cases_on a
(assume (m : nat) H, absurd (coe_nat_nonneg m : 0 ≤ m) (not_le_of_gt H))
(assume (m : nat) H, exists.intro m rfl)
theorem eq_one_of_mul_eq_one_right {a b : ℤ} (H : a ≥ 0) (H' : a * b = 1) : a = 1 :=
have a * b > 0, by rewrite H'; apply trivial,
have b > 0, from pos_of_mul_pos_left this H,
have a > 0, from pos_of_mul_pos_right `a * b > 0` (le_of_lt `b > 0`),
or.elim (le_or_gt a 1)
(assume : a ≤ 1,
show a = 1, from le.antisymm this (add_one_le_of_lt `a > 0`))
(assume : a > 1,
have a * b ≥ 2 * 1,
from mul_le_mul (add_one_le_of_lt `a > 1`) (add_one_le_of_lt `b > 0`) trivial H,
have false, by rewrite [H' at this]; exact this,
false.elim this)
theorem eq_one_of_mul_eq_one_left {a b : ℤ} (H : b ≥ 0) (H' : a * b = 1) : b = 1 :=
eq_one_of_mul_eq_one_right H (!mul.comm ▸ H')
theorem eq_one_of_mul_eq_self_left {a b : ℤ} (Hpos : a ≠ 0) (H : b * a = a) : b = 1 :=
eq_of_mul_eq_mul_right Hpos (H ⬝ (one_mul a)⁻¹)
theorem eq_one_of_mul_eq_self_right {a b : ℤ} (Hpos : b ≠ 0) (H : b * a = b) : a = 1 :=
eq_one_of_mul_eq_self_left Hpos (!mul.comm ▸ H)
theorem eq_one_of_dvd_one {a : ℤ} (H : a ≥ 0) (H' : a ∣ 1) : a = 1 :=
dvd.elim H'
(assume b,
assume : 1 = a * b,
eq_one_of_mul_eq_one_right H this⁻¹)
theorem exists_least_of_bdd {P : ℤ → Prop} [HP : decidable_pred P]
(Hbdd : ∃ b : ℤ, ∀ z : ℤ, z ≤ b → ¬ P z)
(Hinh : ∃ z : ℤ, P z) : ∃ lb : ℤ, P lb ∧ (∀ z : ℤ, z < lb → ¬ P z) :=
begin
cases Hbdd with [b, Hb],
cases Hinh with [elt, Helt],
existsi b + coe_nat (least (λ n, P (b + ↑n)) (nat.succ (nat_abs (elt - b)))),
have Heltb : elt > b, begin
apply lt_of_not_ge,
intro Hge,
apply (Hb _ Hge) Helt
end,
have H' : P (b + coe_nat (nat_abs (elt - b))), begin
rewrite [coe_nat_nat_abs_of_nonneg (int.le_of_lt (iff.mpr !sub_pos_iff_lt Heltb)),
add.comm, sub_add_cancel],
apply Helt
end,
apply and.intro,
apply least_of_lt _ !lt_succ_self H',
intros z Hz,
cases em (z ≤ b) with [Hzb, Hzb],
apply Hb _ Hzb,
let Hzb' := lt_of_not_ge Hzb,
let Hpos := iff.mpr !sub_pos_iff_lt Hzb',
have Hzbk : z = b + coe_nat (nat_abs (z - b)),
by rewrite [coe_nat_nat_abs_of_nonneg (int.le_of_lt Hpos), int.add_comm, sub_add_cancel],
have Hk : nat_abs (z - b) < least (λ n, P (b + ↑n)) (nat.succ (nat_abs (elt - b))), begin
have Hz' := iff.mp !lt_add_iff_sub_lt_left Hz,
rewrite [←coe_nat_nat_abs_of_nonneg (int.le_of_lt Hpos) at Hz'],
apply lt_of_coe_nat_lt_coe_nat Hz'
end,
let Hk' := not_le_of_gt Hk,
rewrite Hzbk,
apply λ p, mt (ge_least_of_lt _ p) Hk',
apply nat.lt_trans Hk,
apply least_lt _ !lt_succ_self H'
end
theorem exists_greatest_of_bdd {P : ℤ → Prop} [HP : decidable_pred P]
(Hbdd : ∃ b : ℤ, ∀ z : ℤ, z ≥ b → ¬ P z)
(Hinh : ∃ z : ℤ, P z) : ∃ ub : ℤ, P ub ∧ (∀ z : ℤ, z > ub → ¬ P z) :=
begin
cases Hbdd with [b, Hb],
cases Hinh with [elt, Helt],
existsi b - coe_nat (least (λ n, P (b - ↑n)) (nat.succ (nat_abs (b - elt)))),
have Heltb : elt < b, begin
apply lt_of_not_ge,
intro Hge,
apply (Hb _ Hge) Helt
end,
have H' : P (b - coe_nat (nat_abs (b - elt))), begin
rewrite [coe_nat_nat_abs_of_nonneg (int.le_of_lt (iff.mpr !sub_pos_iff_lt Heltb)),
sub_sub_self],
apply Helt
end,
apply and.intro,
apply least_of_lt _ !lt_succ_self H',
intros z Hz,
cases em (z ≥ b) with [Hzb, Hzb],
apply Hb _ Hzb,
let Hzb' := lt_of_not_ge Hzb,
let Hpos := iff.mpr !sub_pos_iff_lt Hzb',
have Hzbk : z = b - coe_nat (nat_abs (b - z)),
by rewrite [coe_nat_nat_abs_of_nonneg (int.le_of_lt Hpos), sub_sub_self],
have Hk : nat_abs (b - z) < least (λ n, P (b - ↑n)) (nat.succ (nat_abs (b - elt))), begin
have Hz' := iff.mp !lt_add_iff_sub_lt_left (iff.mpr !lt_add_iff_sub_lt_right Hz),
rewrite [←coe_nat_nat_abs_of_nonneg (int.le_of_lt Hpos) at Hz'],
apply lt_of_coe_nat_lt_coe_nat Hz'
end,
let Hk' := not_le_of_gt Hk,
rewrite Hzbk,
apply λ p, mt (ge_least_of_lt _ p) Hk',
apply nat.lt_trans Hk,
apply least_lt _ !lt_succ_self H'
end
end int
-/
|
7121208bb30b474846f1b25cb73c9638712efecb | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/combinatorics/simple_graph/trails.lean | 6c71112054a68199b44d28fd8711d1a043aa9b49 | [
"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 | 6,039 | lean | /-
Copyright (c) 2022 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import combinatorics.simple_graph.connectivity
import data.nat.parity
/-!
# Trails and Eulerian trails
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This module contains additional theory about trails, including Eulerian trails (also known
as Eulerian circuits).
## Main definitions
* `simple_graph.walk.is_eulerian` is the predicate that a trail is an Eulerian trail.
* `simple_graph.walk.is_trail.even_countp_edges_iff` gives a condition on the number of edges
in a trail that can be incident to a given vertex.
* `simple_graph.walk.is_eulerian.even_degree_iff` gives a condition on the degrees of vertices
when there exists an Eulerian trail.
* `simple_graph.walk.is_eulerian.card_odd_degree` gives the possible numbers of odd-degree
vertices when there exists an Eulerian trail.
## Todo
* Prove that there exists an Eulerian trail when the conclusion to
`simple_graph.walk.is_eulerian.card_odd_degree` holds.
## Tags
Eulerian trails
-/
namespace simple_graph
variables {V : Type*} {G : simple_graph V}
namespace walk
/-- The edges of a trail as a finset, since each edge in a trail appears exactly once. -/
@[reducible] def is_trail.edges_finset {u v : V} {p : G.walk u v}
(h : p.is_trail) : finset (sym2 V) :=
⟨p.edges, h.edges_nodup⟩
variables [decidable_eq V]
lemma is_trail.even_countp_edges_iff {u v : V} {p : G.walk u v} (ht : p.is_trail) (x : V) :
even (p.edges.countp (λ e, x ∈ e)) ↔ (u ≠ v → x ≠ u ∧ x ≠ v) :=
begin
induction p with u u v w huv p ih,
{ simp, },
{ rw [cons_is_trail_iff] at ht,
specialize ih ht.1,
simp only [list.countp_cons, ne.def, edges_cons, sym2.mem_iff],
split_ifs with h,
{ obtain (rfl | rfl) := h,
{ rw [nat.even_add_one, ih],
simp only [huv.ne, imp_false, ne.def, not_false_iff, true_and, not_forall, not_not,
exists_prop, eq_self_iff_true, not_true, false_and, and_iff_right_iff_imp],
rintro rfl rfl,
exact G.loopless _ huv, },
{ rw [nat.even_add_one, ih, ← not_iff_not],
simp only [huv.ne.symm, ne.def, eq_self_iff_true, not_true, false_and, not_forall,
not_false_iff, exists_prop, and_true, not_not, true_and, iff_and_self],
rintro rfl,
exact huv.ne, } },
{ rw not_or_distrib at h,
simp only [h.1, h.2, not_false_iff, true_and, add_zero, ne.def] at ih ⊢,
rw ih,
split;
{ rintro h' h'' rfl,
simp only [imp_false, eq_self_iff_true, not_true, not_not] at h',
cases h',
simpa using h } } },
end
/-- An *Eulerian trail* (also known as an "Eulerian path") is a walk
`p` that visits every edge exactly once. The lemma `simple_graph.walk.is_eulerian.is_trail` shows
that these are trails.
Combine with `p.is_circuit` to get an Eulerian circuit (also known as an "Eulerian cycle"). -/
def is_eulerian {u v : V} (p : G.walk u v) : Prop :=
∀ e, e ∈ G.edge_set → p.edges.count e = 1
lemma is_eulerian.is_trail {u v : V} {p : G.walk u v}
(h : p.is_eulerian) : p.is_trail :=
begin
rw [is_trail_def, list.nodup_iff_count_le_one],
intro e,
by_cases he : e ∈ p.edges,
{ exact (h e (edges_subset_edge_set _ he)).le },
{ simp [he] },
end
lemma is_eulerian.mem_edges_iff {u v : V} {p : G.walk u v} (h : p.is_eulerian) {e : sym2 V} :
e ∈ p.edges ↔ e ∈ G.edge_set :=
⟨λ h, p.edges_subset_edge_set h, λ he, by simpa using (h e he).ge⟩
/-- The edge set of an Eulerian graph is finite. -/
def is_eulerian.fintype_edge_set {u v : V} {p : G.walk u v}
(h : p.is_eulerian) : fintype G.edge_set :=
fintype.of_finset h.is_trail.edges_finset $ λ e,
by simp only [finset.mem_mk, multiset.mem_coe, h.mem_edges_iff]
lemma is_trail.is_eulerian_of_forall_mem {u v : V} {p : G.walk u v}
(h : p.is_trail) (hc : ∀ e, e ∈ G.edge_set → e ∈ p.edges) :
p.is_eulerian :=
λ e he, list.count_eq_one_of_mem h.edges_nodup (hc e he)
lemma is_eulerian_iff {u v : V} (p : G.walk u v) :
p.is_eulerian ↔ p.is_trail ∧ ∀ e, e ∈ G.edge_set → e ∈ p.edges :=
begin
split,
{ intro h,
exact ⟨h.is_trail, λ _, h.mem_edges_iff.mpr⟩, },
{ rintro ⟨h, hl⟩,
exact h.is_eulerian_of_forall_mem hl, },
end
lemma is_eulerian.edges_finset_eq [fintype G.edge_set]
{u v : V} {p : G.walk u v} (h : p.is_eulerian) :
h.is_trail.edges_finset = G.edge_finset :=
by { ext e, simp [h.mem_edges_iff] }
lemma is_eulerian.even_degree_iff {x u v : V} {p : G.walk u v} (ht : p.is_eulerian)
[fintype V] [decidable_rel G.adj] :
even (G.degree x) ↔ (u ≠ v → x ≠ u ∧ x ≠ v) :=
begin
convert ht.is_trail.even_countp_edges_iff x,
rw [← multiset.coe_countp, multiset.countp_eq_card_filter, ← card_incidence_finset_eq_degree],
change multiset.card _ = _,
congr' 1,
convert_to _ = (ht.is_trail.edges_finset.filter (has_mem.mem x)).val,
rw [ht.edges_finset_eq, G.incidence_finset_eq_filter x],
end
lemma is_eulerian.card_filter_odd_degree [fintype V] [decidable_rel G.adj]
{u v : V} {p : G.walk u v} (ht : p.is_eulerian)
{s} (h : s = (finset.univ : finset V).filter (λ v, odd (G.degree v))) :
s.card = 0 ∨ s.card = 2 :=
begin
subst s,
simp only [nat.odd_iff_not_even, finset.card_eq_zero],
simp only [ht.even_degree_iff, ne.def, not_forall, not_and, not_not, exists_prop],
obtain (rfl | hn) := eq_or_ne u v,
{ left,
simp, },
{ right,
convert_to _ = ({u, v} : finset V).card,
{ simp [hn], },
{ congr',
ext x,
simp [hn, imp_iff_not_or], } },
end
lemma is_eulerian.card_odd_degree [fintype V] [decidable_rel G.adj]
{u v : V} {p : G.walk u v} (ht : p.is_eulerian) :
fintype.card {v : V | odd (G.degree v)} = 0 ∨ fintype.card {v : V | odd (G.degree v)} = 2 :=
begin
rw ← set.to_finset_card,
apply is_eulerian.card_filter_odd_degree ht,
ext v,
simp,
end
end walk
end simple_graph
|
025bb394d817abc4476fe0388786192f8d7f2c92 | 82e44445c70db0f03e30d7be725775f122d72f3e | /src/ring_theory/coprime.lean | e3b5f45e23aebab372c4256feb698e6732dacf31 | [
"Apache-2.0"
] | permissive | stjordanis/mathlib | 51e286d19140e3788ef2c470bc7b953e4991f0c9 | 2568d41bca08f5d6bf39d915434c8447e21f42ee | refs/heads/master | 1,631,748,053,501 | 1,627,938,886,000 | 1,627,938,886,000 | 228,728,358 | 0 | 0 | Apache-2.0 | 1,576,630,588,000 | 1,576,630,587,000 | null | UTF-8 | Lean | false | false | 13,715 | lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Ken Lee, Chris Hughes
-/
import algebra.big_operators.basic
import data.fintype.basic
import data.int.gcd
import data.set.pairwise
import tactic.ring
/-!
# Coprime elements of a ring
## Main definitions
* `is_coprime x y`: that `x` and `y` are coprime, defined to be the existence of `a` and `b` such
that `a * x + b * y = 1`. Note that elements with no common divisors are not necessarily coprime,
e.g., the multivariate polynomials `x₁` and `x₂` are not coprime.
-/
open_locale classical big_operators
universes u v
section comm_semiring
variables {R : Type u} [comm_semiring R] (x y z : R)
/-- The proposition that `x` and `y` are coprime, defined to be the existence of `a` and `b` such
that `a * x + b * y = 1`. Note that elements with no common divisors are not necessarily coprime,
e.g., the multivariate polynomials `x₁` and `x₂` are not coprime. -/
@[simp] def is_coprime : Prop :=
∃ a b, a * x + b * y = 1
theorem nat.is_coprime_iff_coprime {m n : ℕ} : is_coprime (m : ℤ) n ↔ nat.coprime m n :=
⟨λ ⟨a, b, H⟩, nat.eq_one_of_dvd_one $ int.coe_nat_dvd.1 $ by { rw [int.coe_nat_one, ← H],
exact dvd_add (dvd_mul_of_dvd_right (int.coe_nat_dvd.2 $ nat.gcd_dvd_left m n) _)
(dvd_mul_of_dvd_right (int.coe_nat_dvd.2 $ nat.gcd_dvd_right m n) _) },
λ H, ⟨nat.gcd_a m n, nat.gcd_b m n, by rw [mul_comm _ (m : ℤ), mul_comm _ (n : ℤ),
← nat.gcd_eq_gcd_ab, show _ = _, from H, int.coe_nat_one]⟩⟩
variables {x y z}
theorem is_coprime.symm (H : is_coprime x y) : is_coprime y x :=
let ⟨a, b, H⟩ := H in ⟨b, a, by rw [add_comm, H]⟩
theorem is_coprime_comm : is_coprime x y ↔ is_coprime y x :=
⟨is_coprime.symm, is_coprime.symm⟩
theorem is_coprime_self : is_coprime x x ↔ is_unit x :=
⟨λ ⟨a, b, h⟩, is_unit_of_mul_eq_one x (a + b) $ by rwa [mul_comm, add_mul],
λ h, let ⟨b, hb⟩ := is_unit_iff_exists_inv'.1 h in ⟨b, 0, by rwa [zero_mul, add_zero]⟩⟩
theorem is_coprime_zero_left : is_coprime 0 x ↔ is_unit x :=
⟨λ ⟨a, b, H⟩, is_unit_of_mul_eq_one x b $ by rwa [mul_zero, zero_add, mul_comm] at H,
λ H, let ⟨b, hb⟩ := is_unit_iff_exists_inv'.1 H in ⟨1, b, by rwa [one_mul, zero_add]⟩⟩
theorem is_coprime_zero_right : is_coprime x 0 ↔ is_unit x :=
is_coprime_comm.trans is_coprime_zero_left
lemma not_coprime_zero_zero [nontrivial R] : ¬ is_coprime (0 : R) 0 :=
mt is_coprime_zero_right.mp not_is_unit_zero
theorem is_coprime_one_left : is_coprime 1 x :=
⟨1, 0, by rw [one_mul, zero_mul, add_zero]⟩
theorem is_coprime_one_right : is_coprime x 1 :=
⟨0, 1, by rw [one_mul, zero_mul, zero_add]⟩
theorem is_coprime.dvd_of_dvd_mul_right (H1 : is_coprime x z) (H2 : x ∣ y * z) : x ∣ y :=
let ⟨a, b, H⟩ := H1 in by { rw [← mul_one y, ← H, mul_add, ← mul_assoc, mul_left_comm],
exact dvd_add (dvd_mul_left _ _) (dvd_mul_of_dvd_right H2 _) }
theorem is_coprime.dvd_of_dvd_mul_left (H1 : is_coprime x y) (H2 : x ∣ y * z) : x ∣ z :=
let ⟨a, b, H⟩ := H1 in by { rw [← one_mul z, ← H, add_mul, mul_right_comm, mul_assoc b],
exact dvd_add (dvd_mul_left _ _) (dvd_mul_of_dvd_right H2 _) }
theorem is_coprime.mul_left (H1 : is_coprime x z) (H2 : is_coprime y z) : is_coprime (x * y) z :=
let ⟨a, b, h1⟩ := H1, ⟨c, d, h2⟩ := H2 in
⟨a * c, a * x * d + b * c * y + b * d * z,
calc a * c * (x * y) + (a * x * d + b * c * y + b * d * z) * z
= (a * x + b * z) * (c * y + d * z) : by ring
... = 1 : by rw [h1, h2, mul_one]⟩
theorem is_coprime.mul_right (H1 : is_coprime x y) (H2 : is_coprime x z) : is_coprime x (y * z) :=
by { rw is_coprime_comm at H1 H2 ⊢, exact H1.mul_left H2 }
variables {I : Type v} {s : I → R} {t : finset I}
theorem is_coprime.prod_left : (∀ i ∈ t, is_coprime (s i) x) → is_coprime (∏ i in t, s i) x :=
finset.induction_on t (λ _, is_coprime_one_left) $ λ b t hbt ih H,
by { rw finset.prod_insert hbt, rw finset.forall_mem_insert at H, exact H.1.mul_left (ih H.2) }
theorem is_coprime.prod_right : (∀ i ∈ t, is_coprime x (s i)) → is_coprime x (∏ i in t, s i) :=
by simpa only [is_coprime_comm] using is_coprime.prod_left
theorem is_coprime.mul_dvd (H : is_coprime x y) (H1 : x ∣ z) (H2 : y ∣ z) : x * y ∣ z :=
begin
obtain ⟨a, b, h⟩ := H,
rw [← mul_one z, ← h, mul_add],
apply dvd_add,
{ rw [mul_comm z, mul_assoc],
exact dvd_mul_of_dvd_right (mul_dvd_mul_left _ H2) _ },
{ rw [mul_comm b, ← mul_assoc],
exact dvd_mul_of_dvd_left (mul_dvd_mul_right H1 _) _ }
end
theorem finset.prod_dvd_of_coprime :
∀ (Hs : set.pairwise_on (↑t : set I) (is_coprime on s)) (Hs1 : ∀ i ∈ t, s i ∣ z),
∏ x in t, s x ∣ z :=
finset.induction_on t (λ _ _, one_dvd z)
begin
intros a r har ih Hs Hs1,
rw finset.prod_insert har,
have aux1 : a ∈ (↑(insert a r) : set I) := finset.mem_insert_self a r,
refine (is_coprime.prod_right $ λ i hir, Hs a aux1 i _ (by { rintro rfl, exact har hir })).mul_dvd
(Hs1 a aux1) (ih (Hs.mono _) $ λ i hi, Hs1 i (finset.mem_insert_of_mem hi)),
{ exact finset.mem_insert_of_mem hir },
{ simp only [finset.coe_insert, set.subset_insert] }
end
theorem fintype.prod_dvd_of_coprime [fintype I] (Hs : pairwise (is_coprime on s))
(Hs1 : ∀ i, s i ∣ z) : ∏ x, s x ∣ z :=
finset.prod_dvd_of_coprime (Hs.pairwise_on _) (λ i _, Hs1 i)
theorem is_coprime.of_mul_left_left (H : is_coprime (x * y) z) : is_coprime x z :=
let ⟨a, b, h⟩ := H in ⟨a * y, b, by rwa [mul_right_comm, mul_assoc]⟩
theorem is_coprime.of_mul_left_right (H : is_coprime (x * y) z) : is_coprime y z :=
by { rw mul_comm at H, exact H.of_mul_left_left }
theorem is_coprime.of_mul_right_left (H : is_coprime x (y * z)) : is_coprime x y :=
by { rw is_coprime_comm at H ⊢, exact H.of_mul_left_left }
theorem is_coprime.of_mul_right_right (H : is_coprime x (y * z)) : is_coprime x z :=
by { rw mul_comm at H, exact H.of_mul_right_left }
theorem is_coprime.mul_left_iff : is_coprime (x * y) z ↔ is_coprime x z ∧ is_coprime y z :=
⟨λ H, ⟨H.of_mul_left_left, H.of_mul_left_right⟩, λ ⟨H1, H2⟩, H1.mul_left H2⟩
theorem is_coprime.mul_right_iff : is_coprime x (y * z) ↔ is_coprime x y ∧ is_coprime x z :=
by rw [is_coprime_comm, is_coprime.mul_left_iff, is_coprime_comm, @is_coprime_comm _ _ z]
theorem is_coprime.prod_left_iff : is_coprime (∏ i in t, s i) x ↔ ∀ i ∈ t, is_coprime (s i) x :=
finset.induction_on t (iff_of_true is_coprime_one_left $ λ _, false.elim) $ λ b t hbt ih,
by rw [finset.prod_insert hbt, is_coprime.mul_left_iff, ih, finset.forall_mem_insert]
theorem is_coprime.prod_right_iff : is_coprime x (∏ i in t, s i) ↔ ∀ i ∈ t, is_coprime x (s i) :=
by simpa only [is_coprime_comm] using is_coprime.prod_left_iff
theorem is_coprime.of_prod_left (H1 : is_coprime (∏ i in t, s i) x) (i : I) (hit : i ∈ t) :
is_coprime (s i) x :=
is_coprime.prod_left_iff.1 H1 i hit
theorem is_coprime.of_prod_right (H1 : is_coprime x (∏ i in t, s i)) (i : I) (hit : i ∈ t) :
is_coprime x (s i) :=
is_coprime.prod_right_iff.1 H1 i hit
variables {m n : ℕ}
theorem is_coprime.pow_left (H : is_coprime x y) : is_coprime (x ^ m) y :=
by { rw [← finset.card_range m, ← finset.prod_const], exact is_coprime.prod_left (λ _ _, H) }
theorem is_coprime.pow_right (H : is_coprime x y) : is_coprime x (y ^ n) :=
by { rw [← finset.card_range n, ← finset.prod_const], exact is_coprime.prod_right (λ _ _, H) }
theorem is_coprime.pow (H : is_coprime x y) : is_coprime (x ^ m) (y ^ n) :=
H.pow_left.pow_right
theorem is_coprime.pow_left_iff (hm : 0 < m) : is_coprime (x ^ m) y ↔ is_coprime x y :=
begin
refine ⟨λ h, _, is_coprime.pow_left⟩,
rw [← finset.card_range m, ← finset.prod_const] at h,
exact h.of_prod_left 0 (finset.mem_range.mpr hm),
end
theorem is_coprime.pow_right_iff (hm : 0 < m) : is_coprime x (y ^ m) ↔ is_coprime x y :=
is_coprime_comm.trans $ (is_coprime.pow_left_iff hm).trans $ is_coprime_comm
theorem is_coprime.pow_iff (hm : 0 < m) (hn : 0 < n) :
is_coprime (x ^ m) (y ^ n) ↔ is_coprime x y :=
(is_coprime.pow_left_iff hm).trans $ is_coprime.pow_right_iff hn
theorem is_coprime.of_coprime_of_dvd_left (h : is_coprime y z) (hdvd : x ∣ y) : is_coprime x z :=
begin
obtain ⟨d, rfl⟩ := hdvd,
exact is_coprime.of_mul_left_left h
end
theorem is_coprime.of_coprime_of_dvd_right (h : is_coprime z y) (hdvd : x ∣ y) : is_coprime z x :=
(h.symm.of_coprime_of_dvd_left hdvd).symm
theorem is_coprime.is_unit_of_dvd (H : is_coprime x y) (d : x ∣ y) : is_unit x :=
let ⟨k, hk⟩ := d in is_coprime_self.1 $ is_coprime.of_mul_right_left $
show is_coprime x (x * k), from hk ▸ H
theorem is_coprime.is_unit_of_dvd' {a b x : R} (h : is_coprime a b) (ha : x ∣ a) (hb : x ∣ b) :
is_unit x :=
(h.of_coprime_of_dvd_left ha).is_unit_of_dvd hb
theorem is_coprime.map (H : is_coprime x y) {S : Type v} [comm_semiring S] (f : R →+* S) :
is_coprime (f x) (f y) :=
let ⟨a, b, h⟩ := H in ⟨f a, f b, by rw [← f.map_mul, ← f.map_mul, ← f.map_add, h, f.map_one]⟩
variables {x y z}
lemma is_coprime.of_add_mul_left_left (h : is_coprime (x + y * z) y) : is_coprime x y :=
let ⟨a, b, H⟩ := h in ⟨a, a * z + b, by simpa only [add_mul, mul_add,
add_assoc, add_comm, add_left_comm, mul_assoc, mul_comm, mul_left_comm] using H⟩
lemma is_coprime.of_add_mul_right_left (h : is_coprime (x + z * y) y) : is_coprime x y :=
by { rw mul_comm at h, exact h.of_add_mul_left_left }
lemma is_coprime.of_add_mul_left_right (h : is_coprime x (y + x * z)) : is_coprime x y :=
by { rw is_coprime_comm at h ⊢, exact h.of_add_mul_left_left }
lemma is_coprime.of_add_mul_right_right (h : is_coprime x (y + z * x)) : is_coprime x y :=
by { rw mul_comm at h, exact h.of_add_mul_left_right }
lemma is_coprime.of_mul_add_left_left (h : is_coprime (y * z + x) y) : is_coprime x y :=
by { rw add_comm at h, exact h.of_add_mul_left_left }
lemma is_coprime.of_mul_add_right_left (h : is_coprime (z * y + x) y) : is_coprime x y :=
by { rw add_comm at h, exact h.of_add_mul_right_left }
lemma is_coprime.of_mul_add_left_right (h : is_coprime x (x * z + y)) : is_coprime x y :=
by { rw add_comm at h, exact h.of_add_mul_left_right }
lemma is_coprime.of_mul_add_right_right (h : is_coprime x (z * x + y)) : is_coprime x y :=
by { rw add_comm at h, exact h.of_add_mul_right_right }
end comm_semiring
namespace is_coprime
section comm_ring
variables {R : Type u} [comm_ring R]
lemma add_mul_left_left {x y : R} (h : is_coprime x y) (z : R) : is_coprime (x + y * z) y :=
@of_add_mul_left_left R _ _ _ (-z) $
by simpa only [mul_neg_eq_neg_mul_symm, add_neg_cancel_right] using h
lemma add_mul_right_left {x y : R} (h : is_coprime x y) (z : R) : is_coprime (x + z * y) y :=
by { rw mul_comm, exact h.add_mul_left_left z }
lemma add_mul_left_right {x y : R} (h : is_coprime x y) (z : R) : is_coprime x (y + x * z) :=
by { rw is_coprime_comm, exact h.symm.add_mul_left_left z }
lemma add_mul_right_right {x y : R} (h : is_coprime x y) (z : R) : is_coprime x (y + z * x) :=
by { rw is_coprime_comm, exact h.symm.add_mul_right_left z }
lemma mul_add_left_left {x y : R} (h : is_coprime x y) (z : R) : is_coprime (y * z + x) y :=
by { rw add_comm, exact h.add_mul_left_left z }
lemma mul_add_right_left {x y : R} (h : is_coprime x y) (z : R) : is_coprime (z * y + x) y :=
by { rw add_comm, exact h.add_mul_right_left z }
lemma mul_add_left_right {x y : R} (h : is_coprime x y) (z : R) : is_coprime x (x * z + y) :=
by { rw add_comm, exact h.add_mul_left_right z }
lemma mul_add_right_right {x y : R} (h : is_coprime x y) (z : R) : is_coprime x (z * x + y) :=
by { rw add_comm, exact h.add_mul_right_right z }
lemma add_mul_left_left_iff {x y z : R} : is_coprime (x + y * z) y ↔ is_coprime x y :=
⟨of_add_mul_left_left, λ h, h.add_mul_left_left z⟩
lemma add_mul_right_left_iff {x y z : R} : is_coprime (x + z * y) y ↔ is_coprime x y :=
⟨of_add_mul_right_left, λ h, h.add_mul_right_left z⟩
lemma add_mul_left_right_iff {x y z : R} : is_coprime x (y + x * z) ↔ is_coprime x y :=
⟨of_add_mul_left_right, λ h, h.add_mul_left_right z⟩
lemma add_mul_right_right_iff {x y z : R} : is_coprime x (y + z * x) ↔ is_coprime x y :=
⟨of_add_mul_right_right, λ h, h.add_mul_right_right z⟩
lemma mul_add_left_left_iff {x y z : R} : is_coprime (y * z + x) y ↔ is_coprime x y :=
⟨of_mul_add_left_left, λ h, h.mul_add_left_left z⟩
lemma mul_add_right_left_iff {x y z : R} : is_coprime (z * y + x) y ↔ is_coprime x y :=
⟨of_mul_add_right_left, λ h, h.mul_add_right_left z⟩
lemma mul_add_left_right_iff {x y z : R} : is_coprime x (x * z + y) ↔ is_coprime x y :=
⟨of_mul_add_left_right, λ h, h.mul_add_left_right z⟩
lemma mul_add_right_right_iff {x y z : R} : is_coprime x (z * x + y) ↔ is_coprime x y :=
⟨of_mul_add_right_right, λ h, h.mul_add_right_right z⟩
lemma neg_left {x y : R} (h : is_coprime x y) : is_coprime (-x) y :=
begin
obtain ⟨a, b, h⟩ := h,
use [-a, b],
rwa neg_mul_neg,
end
lemma neg_left_iff (x y : R) : is_coprime (-x) y ↔ is_coprime x y :=
⟨λ h, neg_neg x ▸ h.neg_left, neg_left⟩
lemma neg_right {x y : R} (h : is_coprime x y) : is_coprime x (-y) :=
h.symm.neg_left.symm
lemma neg_right_iff (x y : R) : is_coprime x (-y) ↔ is_coprime x y :=
⟨λ h, neg_neg y ▸ h.neg_right, neg_right⟩
lemma neg_neg {x y : R} (h : is_coprime x y) : is_coprime (-x) (-y) :=
h.neg_left.neg_right
lemma neg_neg_iff (x y : R) : is_coprime (-x) (-y) ↔ is_coprime x y :=
(neg_left_iff _ _).trans (neg_right_iff _ _)
end comm_ring
end is_coprime
|
ad35641924173b81c1f7a630a775e9ae3672c554 | e39f04f6ff425fe3b3f5e26a8998b817d1dba80f | /algebra/group.lean | fed91323c530745b973b0527122426203d103adb | [
"Apache-2.0"
] | permissive | kristychoi/mathlib | c504b5e8f84e272ea1d8966693c42de7523bf0ec | 257fd84fe98927ff4a5ffe044f68c4e9d235cc75 | refs/heads/master | 1,586,520,722,896 | 1,544,030,145,000 | 1,544,031,933,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 28,115 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
Various multiplicative and additive structures.
-/
import tactic.interactive data.option
section pending_1857
/- Transport multiplicative to additive -/
section transport
open tactic
@[user_attribute]
meta def to_additive_attr : user_attribute (name_map name) name :=
{ name := `to_additive,
descr := "Transport multiplicative to additive",
cache_cfg := ⟨λ ns, ns.mfoldl (λ dict n, do
val ← to_additive_attr.get_param n,
pure $ dict.insert n val) mk_name_map, []⟩,
parser := lean.parser.ident,
after_set := some $ λ src _ _, do
env ← get_env,
dict ← to_additive_attr.get_cache,
tgt ← to_additive_attr.get_param src,
(get_decl tgt >> skip) <|>
transport_with_dict dict src tgt }
end transport
/- map operations -/
attribute [to_additive has_add.add] has_mul.mul
attribute [to_additive has_zero.zero] has_one.one
attribute [to_additive has_neg.neg] has_inv.inv
attribute [to_additive has_add] has_mul
attribute [to_additive has_zero] has_one
attribute [to_additive has_neg] has_inv
/- map constructors -/
attribute [to_additive has_add.mk] has_mul.mk
attribute [to_additive has_zero.mk] has_one.mk
attribute [to_additive has_neg.mk] has_inv.mk
/- map structures -/
attribute [to_additive add_semigroup] semigroup
attribute [to_additive add_semigroup.mk] semigroup.mk
attribute [to_additive add_semigroup.to_has_add] semigroup.to_has_mul
attribute [to_additive add_semigroup.add_assoc] semigroup.mul_assoc
attribute [to_additive add_semigroup.add] semigroup.mul
attribute [to_additive add_comm_semigroup] comm_semigroup
attribute [to_additive add_comm_semigroup.mk] comm_semigroup.mk
attribute [to_additive add_comm_semigroup.to_add_semigroup] comm_semigroup.to_semigroup
attribute [to_additive add_comm_semigroup.add_comm] comm_semigroup.mul_comm
attribute [to_additive add_left_cancel_semigroup] left_cancel_semigroup
attribute [to_additive add_left_cancel_semigroup.mk] left_cancel_semigroup.mk
attribute [to_additive add_left_cancel_semigroup.to_add_semigroup] left_cancel_semigroup.to_semigroup
attribute [to_additive add_left_cancel_semigroup.add_left_cancel] left_cancel_semigroup.mul_left_cancel
attribute [to_additive add_right_cancel_semigroup] right_cancel_semigroup
attribute [to_additive add_right_cancel_semigroup.mk] right_cancel_semigroup.mk
attribute [to_additive add_right_cancel_semigroup.to_add_semigroup] right_cancel_semigroup.to_semigroup
attribute [to_additive add_right_cancel_semigroup.add_right_cancel] right_cancel_semigroup.mul_right_cancel
attribute [to_additive add_monoid] monoid
attribute [to_additive add_monoid.mk] monoid.mk
attribute [to_additive add_monoid.to_has_zero] monoid.to_has_one
attribute [to_additive add_monoid.to_add_semigroup] monoid.to_semigroup
attribute [to_additive add_monoid.add] monoid.mul
attribute [to_additive add_monoid.add_assoc] monoid.mul_assoc
attribute [to_additive add_monoid.zero] monoid.one
attribute [to_additive add_monoid.zero_add] monoid.one_mul
attribute [to_additive add_monoid.add_zero] monoid.mul_one
attribute [to_additive add_comm_monoid] comm_monoid
attribute [to_additive add_comm_monoid.mk] comm_monoid.mk
attribute [to_additive add_comm_monoid.to_add_monoid] comm_monoid.to_monoid
attribute [to_additive add_comm_monoid.to_add_comm_semigroup] comm_monoid.to_comm_semigroup
attribute [to_additive add_group] group
attribute [to_additive add_group.mk] group.mk
attribute [to_additive add_group.to_has_neg] group.to_has_inv
attribute [to_additive add_group.to_add_monoid] group.to_monoid
attribute [to_additive add_group.add_left_neg] group.mul_left_inv
attribute [to_additive add_group.add] group.mul
attribute [to_additive add_group.add_assoc] group.mul_assoc
attribute [to_additive add_group.zero] group.one
attribute [to_additive add_group.zero_add] group.one_mul
attribute [to_additive add_group.add_zero] group.mul_one
attribute [to_additive add_group.neg] group.inv
attribute [to_additive add_comm_group] comm_group
attribute [to_additive add_comm_group.mk] comm_group.mk
attribute [to_additive add_comm_group.to_add_group] comm_group.to_group
attribute [to_additive add_comm_group.to_add_comm_monoid] comm_group.to_comm_monoid
/- map theorems -/
attribute [to_additive add_assoc] mul_assoc
attribute [to_additive add_semigroup_to_is_associative] semigroup_to_is_associative
attribute [to_additive add_comm] mul_comm
attribute [to_additive add_comm_semigroup_to_is_commutative] comm_semigroup_to_is_commutative
attribute [to_additive add_left_comm] mul_left_comm
attribute [to_additive add_right_comm] mul_right_comm
attribute [to_additive add_left_cancel] mul_left_cancel
attribute [to_additive add_right_cancel] mul_right_cancel
attribute [to_additive add_left_cancel_iff] mul_left_cancel_iff
attribute [to_additive add_right_cancel_iff] mul_right_cancel_iff
attribute [to_additive zero_add] one_mul
attribute [to_additive add_zero] mul_one
attribute [to_additive add_left_neg] mul_left_inv
attribute [to_additive neg_add_self] inv_mul_self
attribute [to_additive neg_add_cancel_left] inv_mul_cancel_left
attribute [to_additive neg_add_cancel_right] inv_mul_cancel_right
attribute [to_additive neg_eq_of_add_eq_zero] inv_eq_of_mul_eq_one
attribute [to_additive neg_zero] one_inv
attribute [to_additive neg_neg] inv_inv
attribute [to_additive add_right_neg] mul_right_inv
attribute [to_additive add_neg_self] mul_inv_self
attribute [to_additive neg_inj] inv_inj
attribute [to_additive add_group.add_left_cancel] group.mul_left_cancel
attribute [to_additive add_group.add_right_cancel] group.mul_right_cancel
attribute [to_additive add_group.to_left_cancel_add_semigroup] group.to_left_cancel_semigroup
attribute [to_additive add_group.to_right_cancel_add_semigroup] group.to_right_cancel_semigroup
attribute [to_additive add_neg_cancel_left] mul_inv_cancel_left
attribute [to_additive add_neg_cancel_right] mul_inv_cancel_right
attribute [to_additive neg_add_rev] mul_inv_rev
attribute [to_additive eq_neg_of_eq_neg] eq_inv_of_eq_inv
attribute [to_additive eq_neg_of_add_eq_zero] eq_inv_of_mul_eq_one
attribute [to_additive eq_add_neg_of_add_eq] eq_mul_inv_of_mul_eq
attribute [to_additive eq_neg_add_of_add_eq] eq_inv_mul_of_mul_eq
attribute [to_additive neg_add_eq_of_eq_add] inv_mul_eq_of_eq_mul
attribute [to_additive add_neg_eq_of_eq_add] mul_inv_eq_of_eq_mul
attribute [to_additive eq_add_of_add_neg_eq] eq_mul_of_mul_inv_eq
attribute [to_additive eq_add_of_neg_add_eq] eq_mul_of_inv_mul_eq
attribute [to_additive add_eq_of_eq_neg_add] mul_eq_of_eq_inv_mul
attribute [to_additive add_eq_of_eq_add_neg] mul_eq_of_eq_mul_inv
attribute [to_additive neg_add] mul_inv
end pending_1857
instance monoid_to_is_left_id {α : Type*} [monoid α]
: is_left_id α (*) 1 :=
⟨ monoid.one_mul ⟩
instance monoid_to_is_right_id {α : Type*} [monoid α]
: is_right_id α (*) 1 :=
⟨ monoid.mul_one ⟩
instance add_monoid_to_is_left_id {α : Type*} [add_monoid α]
: is_left_id α (+) 0 :=
⟨ add_monoid.zero_add ⟩
instance add_monoid_to_is_right_id {α : Type*} [add_monoid α]
: is_right_id α (+) 0 :=
⟨ add_monoid.add_zero ⟩
universes u v
variables {α : Type u} {β : Type v}
def additive (α : Type*) := α
def multiplicative (α : Type*) := α
instance [semigroup α] : add_semigroup (additive α) :=
{ add := ((*) : α → α → α),
add_assoc := @mul_assoc _ _ }
instance [add_semigroup α] : semigroup (multiplicative α) :=
{ mul := ((+) : α → α → α),
mul_assoc := @add_assoc _ _ }
instance [comm_semigroup α] : add_comm_semigroup (additive α) :=
{ add_comm := @mul_comm _ _,
..additive.add_semigroup }
instance [add_comm_semigroup α] : comm_semigroup (multiplicative α) :=
{ mul_comm := @add_comm _ _,
..multiplicative.semigroup }
instance [left_cancel_semigroup α] : add_left_cancel_semigroup (additive α) :=
{ add_left_cancel := @mul_left_cancel _ _,
..additive.add_semigroup }
instance [add_left_cancel_semigroup α] : left_cancel_semigroup (multiplicative α) :=
{ mul_left_cancel := @add_left_cancel _ _,
..multiplicative.semigroup }
instance [right_cancel_semigroup α] : add_right_cancel_semigroup (additive α) :=
{ add_right_cancel := @mul_right_cancel _ _,
..additive.add_semigroup }
instance [add_right_cancel_semigroup α] : right_cancel_semigroup (multiplicative α) :=
{ mul_right_cancel := @add_right_cancel _ _,
..multiplicative.semigroup }
@[simp, to_additive add_left_inj]
theorem mul_left_inj [left_cancel_semigroup α] (a : α) {b c : α} : a * b = a * c ↔ b = c :=
⟨mul_left_cancel, congr_arg _⟩
@[simp, to_additive add_right_inj]
theorem mul_right_inj [right_cancel_semigroup α] (a : α) {b c : α} : b * a = c * a ↔ b = c :=
⟨mul_right_cancel, congr_arg _⟩
structure units (α : Type u) [monoid α] :=
(val : α)
(inv : α)
(val_inv : val * inv = 1)
(inv_val : inv * val = 1)
namespace units
variables [monoid α] {a b c : units α}
instance : has_coe (units α) α := ⟨val⟩
@[extensionality] theorem ext : ∀ {a b : units α}, (a : α) = b → a = b
| ⟨v, i₁, vi₁, iv₁⟩ ⟨v', i₂, vi₂, iv₂⟩ e :=
by change v = v' at e; subst v'; congr;
simpa only [iv₂, vi₁, one_mul, mul_one] using mul_assoc i₂ v i₁
theorem ext_iff {a b : units α} : a = b ↔ (a : α) = b :=
⟨congr_arg _, ext⟩
instance [decidable_eq α] : decidable_eq (units α)
| a b := decidable_of_iff' _ ext_iff
protected def mul (u₁ u₂ : units α) : units α :=
⟨u₁.val * u₂.val, u₂.inv * u₁.inv,
have u₁.val * (u₂.val * u₂.inv) * u₁.inv = 1,
by rw [u₂.val_inv]; rw [mul_one, u₁.val_inv],
by simpa only [mul_assoc],
have u₂.inv * (u₁.inv * u₁.val) * u₂.val = 1,
by rw [u₁.inv_val]; rw [mul_one, u₂.inv_val],
by simpa only [mul_assoc]⟩
protected def inv' (u : units α) : units α :=
⟨u.inv, u.val, u.inv_val, u.val_inv⟩
instance : has_mul (units α) := ⟨units.mul⟩
instance : has_one (units α) := ⟨⟨1, 1, mul_one 1, one_mul 1⟩⟩
instance : has_inv (units α) := ⟨units.inv'⟩
variables (a b)
@[simp] lemma coe_mul : (↑(a * b) : α) = a * b := rfl
@[simp] lemma coe_one : ((1 : units α) : α) = 1 := rfl
lemma val_coe : (↑a : α) = a.val := rfl
lemma coe_inv : ((a⁻¹ : units α) : α) = a.inv := rfl
@[simp] lemma inv_mul : (↑a⁻¹ * a : α) = 1 := inv_val _
@[simp] lemma mul_inv : (a * ↑a⁻¹ : α) = 1 := val_inv _
@[simp] lemma mul_inv_cancel_left (a : units α) (b : α) : (a:α) * (↑a⁻¹ * b) = b :=
by rw [← mul_assoc, mul_inv, one_mul]
@[simp] lemma inv_mul_cancel_left (a : units α) (b : α) : (↑a⁻¹:α) * (a * b) = b :=
by rw [← mul_assoc, inv_mul, one_mul]
@[simp] lemma mul_inv_cancel_right (a : α) (b : units α) : a * b * ↑b⁻¹ = a :=
by rw [mul_assoc, mul_inv, mul_one]
@[simp] lemma inv_mul_cancel_right (a : α) (b : units α) : a * ↑b⁻¹ * b = a :=
by rw [mul_assoc, inv_mul, mul_one]
instance : group (units α) :=
by refine {mul := (*), one := 1, inv := has_inv.inv, ..};
{ intros, apply ext, simp only [coe_mul, coe_one,
mul_assoc, one_mul, mul_one, inv_mul] }
instance {α} [comm_monoid α] : comm_group (units α) :=
{ mul_comm := λ u₁ u₂, ext $ mul_comm _ _, ..units.group }
instance [has_repr α] : has_repr (units α) := ⟨repr ∘ val⟩
@[simp] theorem mul_left_inj (a : units α) {b c : α} : (a:α) * b = a * c ↔ b = c :=
⟨λ h, by simpa only [inv_mul_cancel_left] using congr_arg ((*) ↑(a⁻¹ : units α)) h, congr_arg _⟩
@[simp] theorem mul_right_inj (a : units α) {b c : α} : b * a = c * a ↔ b = c :=
⟨λ h, by simpa only [mul_inv_cancel_right] using congr_arg (* ↑(a⁻¹ : units α)) h, congr_arg _⟩
end units
theorem nat.units_eq_one (u : units ℕ) : u = 1 :=
units.ext $ nat.eq_one_of_dvd_one ⟨u.inv, u.val_inv.symm⟩
def units.mk_of_mul_eq_one [comm_monoid α] (a b : α) (hab : a * b = 1) : units α :=
⟨a, b, hab, (mul_comm b a).trans hab⟩
@[to_additive with_zero]
def with_one (α) := option α
@[to_additive with_zero.has_coe_t]
instance : has_coe_t α (with_one α) := ⟨some⟩
instance [semigroup α] : monoid (with_one α) :=
{ one := none,
mul := option.lift_or_get (*),
mul_assoc := (option.lift_or_get_assoc _).1,
one_mul := (option.lift_or_get_is_left_id _).1,
mul_one := (option.lift_or_get_is_right_id _).1 }
attribute [to_additive with_zero.add_monoid._proof_1] with_one.monoid._proof_1
attribute [to_additive with_zero.add_monoid._proof_2] with_one.monoid._proof_2
attribute [to_additive with_zero.add_monoid._proof_3] with_one.monoid._proof_3
attribute [to_additive with_zero.add_monoid] with_one.monoid
instance [semigroup α] : mul_zero_class (with_zero α) :=
{ zero := none,
mul := λ o₁ o₂, o₁.bind (λ a, o₂.map (λ b, a * b)),
zero_mul := λ a, rfl,
mul_zero := λ a, by cases a; refl,
..with_zero.add_monoid }
instance [semigroup α] : semigroup (with_zero α) :=
{ mul_assoc := λ a b c, match a, b, c with
| none, _, _ := rfl
| some a, none, _ := rfl
| some a, some b, none := rfl
| some a, some b, some c := congr_arg some (mul_assoc _ _ _)
end,
..with_zero.mul_zero_class }
instance [comm_semigroup α] : comm_semigroup (with_zero α) :=
{ mul_comm := λ a b, match a, b with
| none, _ := (mul_zero _).symm
| some a, none := rfl
| some a, some b := congr_arg some (mul_comm _ _)
end,
..with_zero.semigroup }
instance [monoid α] : monoid (with_zero α) :=
{ one := some 1,
one_mul := λ a, match a with
| none := rfl
| some a := congr_arg some $ one_mul _
end,
mul_one := λ a, match a with
| none := rfl
| some a := congr_arg some $ mul_one _
end,
..with_zero.semigroup }
instance [comm_monoid α] : comm_monoid (with_zero α) :=
{ ..with_zero.monoid, ..with_zero.comm_semigroup }
instance [monoid α] : add_monoid (additive α) :=
{ zero := (1 : α),
zero_add := @one_mul _ _,
add_zero := @mul_one _ _,
..additive.add_semigroup }
instance [add_monoid α] : monoid (multiplicative α) :=
{ one := (0 : α),
one_mul := @zero_add _ _,
mul_one := @add_zero _ _,
..multiplicative.semigroup }
section monoid
variables [monoid α] {a b c : α}
/-- Partial division. It is defined when the
second argument is invertible, and unlike the division operator
in `division_ring` it is not totalized at zero. -/
def divp (a : α) (u) : α := a * (u⁻¹ : units α)
infix ` /ₚ `:70 := divp
@[simp] theorem divp_self (u : units α) : (u : α) /ₚ u = 1 := units.mul_inv _
@[simp] theorem divp_one (a : α) : a /ₚ 1 = a := mul_one _
theorem divp_assoc (a b : α) (u : units α) : a * b /ₚ u = a * (b /ₚ u) :=
mul_assoc _ _ _
@[simp] theorem divp_mul_cancel (a : α) (u : units α) : a /ₚ u * u = a :=
(mul_assoc _ _ _).trans $ by rw [units.inv_mul, mul_one]
@[simp] theorem mul_divp_cancel (a : α) (u : units α) : (a * u) /ₚ u = a :=
(mul_assoc _ _ _).trans $ by rw [units.mul_inv, mul_one]
@[simp] theorem divp_right_inj (u : units α) {a b : α} : a /ₚ u = b /ₚ u ↔ a = b :=
units.mul_right_inj _
theorem divp_eq_one (a : α) (u : units α) : a /ₚ u = 1 ↔ a = u :=
(units.mul_right_inj u).symm.trans $ by rw [divp_mul_cancel, one_mul]
@[simp] theorem one_divp (u : units α) : 1 /ₚ u = ↑u⁻¹ :=
one_mul _
end monoid
instance [comm_semigroup α] : comm_monoid (with_one α) :=
{ mul_comm := (option.lift_or_get_comm _).1,
..with_one.monoid }
instance [add_comm_semigroup α] : add_comm_monoid (with_zero α) :=
{ add_comm := (option.lift_or_get_comm _).1,
..with_zero.add_monoid }
attribute [to_additive with_zero.add_comm_monoid] with_one.comm_monoid
instance [comm_monoid α] : add_comm_monoid (additive α) :=
{ add_comm := @mul_comm α _,
..additive.add_monoid }
instance [add_comm_monoid α] : comm_monoid (multiplicative α) :=
{ mul_comm := @add_comm α _,
..multiplicative.monoid }
instance [group α] : add_group (additive α) :=
{ neg := @has_inv.inv α _,
add_left_neg := @mul_left_inv _ _,
..additive.add_monoid }
instance [add_group α] : group (multiplicative α) :=
{ inv := @has_neg.neg α _,
mul_left_inv := @add_left_neg _ _,
..multiplicative.monoid }
section group
variables [group α] {a b c : α}
instance : has_lift α (units α) :=
⟨λ a, ⟨a, a⁻¹, mul_inv_self _, inv_mul_self _⟩⟩
@[simp, to_additive neg_inj']
theorem inv_inj' : a⁻¹ = b⁻¹ ↔ a = b :=
⟨λ h, by rw [← inv_inv a, h, inv_inv], congr_arg _⟩
@[to_additive eq_of_neg_eq_neg]
theorem eq_of_inv_eq_inv : a⁻¹ = b⁻¹ → a = b :=
inv_inj'.1
@[simp, to_additive add_self_iff_eq_zero]
theorem mul_self_iff_eq_one : a * a = a ↔ a = 1 :=
by have := @mul_left_inj _ _ a a 1; rwa mul_one at this
@[simp, to_additive neg_eq_zero]
theorem inv_eq_one : a⁻¹ = 1 ↔ a = 1 :=
by rw [← @inv_inj' _ _ a 1, one_inv]
@[simp, to_additive neg_ne_zero]
theorem inv_ne_one : a⁻¹ ≠ 1 ↔ a ≠ 1 :=
not_congr inv_eq_one
@[to_additive left_inverse_neg]
theorem left_inverse_inv (α) [group α] :
function.left_inverse (λ a : α, a⁻¹) (λ a, a⁻¹) :=
assume a, inv_inv a
attribute [simp] mul_inv_cancel_left add_neg_cancel_left
mul_inv_cancel_right add_neg_cancel_right
@[to_additive eq_neg_iff_eq_neg]
theorem eq_inv_iff_eq_inv : a = b⁻¹ ↔ b = a⁻¹ :=
⟨eq_inv_of_eq_inv, eq_inv_of_eq_inv⟩
@[to_additive neg_eq_iff_neg_eq]
theorem inv_eq_iff_inv_eq : a⁻¹ = b ↔ b⁻¹ = a :=
by rw [eq_comm, @eq_comm _ _ a, eq_inv_iff_eq_inv]
@[to_additive add_eq_zero_iff_eq_neg]
theorem mul_eq_one_iff_eq_inv : a * b = 1 ↔ a = b⁻¹ :=
by simpa [mul_left_inv, -mul_right_inj] using @mul_right_inj _ _ b a (b⁻¹)
@[to_additive add_eq_zero_iff_neg_eq]
theorem mul_eq_one_iff_inv_eq : a * b = 1 ↔ a⁻¹ = b :=
by rw [mul_eq_one_iff_eq_inv, eq_inv_iff_eq_inv, eq_comm]
@[to_additive eq_neg_iff_add_eq_zero]
theorem eq_inv_iff_mul_eq_one : a = b⁻¹ ↔ a * b = 1 :=
mul_eq_one_iff_eq_inv.symm
@[to_additive neg_eq_iff_add_eq_zero]
theorem inv_eq_iff_mul_eq_one : a⁻¹ = b ↔ a * b = 1 :=
mul_eq_one_iff_inv_eq.symm
@[to_additive eq_add_neg_iff_add_eq]
theorem eq_mul_inv_iff_mul_eq : a = b * c⁻¹ ↔ a * c = b :=
⟨λ h, by rw [h, inv_mul_cancel_right], λ h, by rw [← h, mul_inv_cancel_right]⟩
@[to_additive eq_neg_add_iff_add_eq]
theorem eq_inv_mul_iff_mul_eq : a = b⁻¹ * c ↔ b * a = c :=
⟨λ h, by rw [h, mul_inv_cancel_left], λ h, by rw [← h, inv_mul_cancel_left]⟩
@[to_additive neg_add_eq_iff_eq_add]
theorem inv_mul_eq_iff_eq_mul : a⁻¹ * b = c ↔ b = a * c :=
⟨λ h, by rw [← h, mul_inv_cancel_left], λ h, by rw [h, inv_mul_cancel_left]⟩
@[to_additive add_neg_eq_iff_eq_add]
theorem mul_inv_eq_iff_eq_mul : a * b⁻¹ = c ↔ a = c * b :=
⟨λ h, by rw [← h, inv_mul_cancel_right], λ h, by rw [h, mul_inv_cancel_right]⟩
@[to_additive add_neg_eq_zero]
theorem mul_inv_eq_one {a b : α} : a * b⁻¹ = 1 ↔ a = b :=
by rw [mul_eq_one_iff_eq_inv, inv_inv]
@[to_additive neg_comm_of_comm]
theorem inv_comm_of_comm {a b : α} (H : a * b = b * a) : a⁻¹ * b = b * a⁻¹ :=
begin
have : a⁻¹ * (b * a) * a⁻¹ = a⁻¹ * (a * b) * a⁻¹ :=
congr_arg (λ x:α, a⁻¹ * x * a⁻¹) H.symm,
rwa [inv_mul_cancel_left, mul_assoc, mul_inv_cancel_right] at this
end
end group
instance [comm_group α] : add_comm_group (additive α) :=
{ add_comm := @mul_comm α _,
..additive.add_group }
instance [add_comm_group α] : comm_group (multiplicative α) :=
{ mul_comm := @add_comm α _,
..multiplicative.group }
section add_monoid
variables [add_monoid α] {a b c : α}
@[simp] lemma bit0_zero : bit0 (0 : α) = 0 := add_zero _
@[simp] lemma bit1_zero [has_one α] : bit1 (0 : α) = 1 :=
show 0+0+1=(1:α), by rw [zero_add, zero_add]
end add_monoid
section add_group
variables [add_group α] {a b c : α}
local attribute [simp] sub_eq_add_neg
def sub_sub_cancel := @sub_sub_self
@[simp] lemma sub_left_inj : a - b = a - c ↔ b = c :=
(add_left_inj _).trans neg_inj'
@[simp] lemma sub_right_inj : b - a = c - a ↔ b = c :=
add_right_inj _
lemma sub_add_sub_cancel (a b c : α) : (a - b) + (b - c) = a - c :=
by rw [← add_sub_assoc, sub_add_cancel]
lemma sub_sub_sub_cancel_right (a b c : α) : (a - c) - (b - c) = a - b :=
by rw [← neg_sub c b, sub_neg_eq_add, sub_add_sub_cancel]
theorem sub_eq_zero : a - b = 0 ↔ a = b :=
⟨eq_of_sub_eq_zero, λ h, by rw [h, sub_self]⟩
theorem sub_ne_zero : a - b ≠ 0 ↔ a ≠ b :=
not_congr sub_eq_zero
theorem eq_sub_iff_add_eq : a = b - c ↔ a + c = b :=
eq_add_neg_iff_add_eq
theorem sub_eq_iff_eq_add : a - b = c ↔ a = c + b :=
add_neg_eq_iff_eq_add
theorem eq_iff_eq_of_sub_eq_sub {a b c d : α} (H : a - b = c - d) : a = b ↔ c = d :=
by rw [← sub_eq_zero, H, sub_eq_zero]
theorem left_inverse_sub_add_left (c : α) : function.left_inverse (λ x, x - c) (λ x, x + c) :=
assume x, add_sub_cancel x c
theorem left_inverse_add_left_sub (c : α) : function.left_inverse (λ x, x + c) (λ x, x - c) :=
assume x, sub_add_cancel x c
theorem left_inverse_add_right_neg_add (c : α) :
function.left_inverse (λ x, c + x) (λ x, - c + x) :=
assume x, add_neg_cancel_left c x
theorem left_inverse_neg_add_add_right (c : α) :
function.left_inverse (λ x, - c + x) (λ x, c + x) :=
assume x, neg_add_cancel_left c x
end add_group
section add_comm_group
variables [add_comm_group α] {a b c : α}
lemma sub_eq_neg_add (a b : α) : a - b = -b + a :=
add_comm _ _
theorem neg_add' (a b : α) : -(a + b) = -a - b := neg_add a b
lemma eq_sub_iff_add_eq' : a = b - c ↔ c + a = b :=
by rw [eq_sub_iff_add_eq, add_comm]
lemma sub_eq_iff_eq_add' : a - b = c ↔ a = b + c :=
by rw [sub_eq_iff_eq_add, add_comm]
lemma add_sub_cancel' (a b : α) : a + b - a = b :=
by rw [sub_eq_neg_add, neg_add_cancel_left]
lemma add_sub_cancel'_right (a b : α) : a + (b - a) = b :=
by rw [← add_sub_assoc, add_sub_cancel']
lemma sub_right_comm (a b c : α) : a - b - c = a - c - b :=
add_right_comm _ _ _
lemma sub_add_sub_cancel' (a b c : α) : (a - b) + (c - a) = c - b :=
by rw add_comm; apply sub_add_sub_cancel
lemma sub_sub_sub_cancel_left (a b c : α) : (c - a) - (c - b) = b - a :=
by rw [← neg_sub b c, sub_neg_eq_add, add_comm, sub_add_sub_cancel]
end add_comm_group
section is_conj
variables [group α] [group β]
def is_conj (a b : α) := ∃ c : α, c * a * c⁻¹ = b
@[refl] lemma is_conj_refl (a : α) : is_conj a a :=
⟨1, by rw [one_mul, one_inv, mul_one]⟩
@[symm] lemma is_conj_symm (a b : α) : is_conj a b → is_conj b a
| ⟨c, hc⟩ := ⟨c⁻¹, by rw [← hc, mul_assoc, mul_inv_cancel_right, inv_mul_cancel_left]⟩
@[trans] lemma is_conj_trans (a b c : α) : is_conj a b → is_conj b c → is_conj a c
| ⟨c₁, hc₁⟩ ⟨c₂, hc₂⟩ := ⟨c₂ * c₁, by rw [← hc₂, ← hc₁, mul_inv_rev]; simp only [mul_assoc]⟩
@[simp] lemma is_conj_iff_eq {α : Type*} [comm_group α] {a b : α} : is_conj a b ↔ a = b :=
⟨λ ⟨c, hc⟩, by rw [← hc, mul_right_comm, mul_inv_self, one_mul], λ h, by rw h⟩
end is_conj
class is_monoid_hom [monoid α] [monoid β] (f : α → β) : Prop :=
(map_one : f 1 = 1)
(map_mul : ∀ {x y}, f (x * y) = f x * f y)
class is_add_monoid_hom [add_monoid α] [add_monoid β] (f : α → β) : Prop :=
(map_zero : f 0 = 0)
(map_add : ∀ {x y}, f (x + y) = f x + f y)
attribute [to_additive is_add_monoid_hom] is_monoid_hom
attribute [to_additive is_add_monoid_hom.map_add] is_monoid_hom.map_mul
attribute [to_additive is_add_monoid_hom.mk] is_monoid_hom.mk
namespace is_monoid_hom
variables [monoid α] [monoid β] (f : α → β) [is_monoid_hom f]
@[to_additive is_add_monoid_hom.id]
instance id : is_monoid_hom (@id α) := by refine {..}; intros; refl
@[to_additive is_add_monoid_hom.id]
instance comp {γ} [monoid γ] (g : β → γ) [is_monoid_hom g] :
is_monoid_hom (g ∘ f) :=
{ map_mul := λ x y, show g _ = g _ * g _, by rw [map_mul f, map_mul g],
map_one := show g _ = 1, by rw [map_one f, map_one g] }
end is_monoid_hom
-- TODO rename fields of is_group_hom: mul ↝ map_mul?
/-- Predicate for group homomorphism. -/
class is_group_hom [group α] [group β] (f : α → β) : Prop :=
(mul : ∀ a b : α, f (a * b) = f a * f b)
class is_add_group_hom [add_group α] [add_group β] (f : α → β) : Prop :=
(add : ∀ a b, f (a + b) = f a + f b)
attribute [to_additive is_add_group_hom] is_group_hom
attribute [to_additive is_add_group_hom.add] is_group_hom.mul
attribute [to_additive is_add_group_hom.mk] is_group_hom.mk
namespace is_group_hom
variables [group α] [group β] (f : α → β) [is_group_hom f]
@[to_additive is_add_group_hom.zero]
theorem one : f 1 = 1 :=
mul_self_iff_eq_one.1 $ by rw [← mul f, one_mul]
@[to_additive is_add_group_hom.neg]
theorem inv (a : α) : f a⁻¹ = (f a)⁻¹ :=
eq_inv_of_mul_eq_one $ by rw [← mul f, inv_mul_self, one f]
@[to_additive is_add_group_hom.id]
instance id : is_group_hom (@id α) :=
⟨λ _ _, rfl⟩
@[to_additive is_add_group_hom.comp]
instance comp {γ} [group γ] (g : β → γ) [is_group_hom g] :
is_group_hom (g ∘ f) :=
⟨λ x y, show g _ = g _ * g _, by rw [mul f, mul g]⟩
protected lemma is_conj (f : α → β) [is_group_hom f] {a b : α} : is_conj a b → is_conj (f a) (f b)
| ⟨c, hc⟩ := ⟨f c, by rw [← is_group_hom.mul f, ← is_group_hom.inv f, ← is_group_hom.mul f, hc]⟩
end is_group_hom
@[to_additive is_add_group_hom_add]
lemma is_group_hom_mul {α β} [group α] [comm_group β]
(f g : α → β) [is_group_hom f] [is_group_hom g] :
is_group_hom (λa, f a * g a) :=
⟨assume a b, by simp only [is_group_hom.mul f, is_group_hom.mul g, mul_comm, mul_assoc, mul_left_comm]⟩
attribute [instance] is_group_hom_mul is_add_group_hom_add
@[to_additive is_add_group_hom_neg]
lemma is_group_hom_inv {α β} [group α] [comm_group β] (f : α → β) [is_group_hom f] :
is_group_hom (λa, (f a)⁻¹) :=
⟨assume a b, by rw [is_group_hom.mul f, mul_inv]⟩
attribute [instance] is_group_hom_inv is_add_group_hom_neg
/-- Predicate for group anti-homomorphism, or a homomorphism
into the opposite group. -/
class is_group_anti_hom {β : Type*} [group α] [group β] (f : α → β) : Prop :=
(mul : ∀ a b : α, f (a * b) = f b * f a)
namespace is_group_anti_hom
variables [group α] [group β] (f : α → β) [w : is_group_anti_hom f]
include w
theorem one : f 1 = 1 :=
mul_self_iff_eq_one.1 $ by rw [← mul f, one_mul]
theorem inv (a : α) : f a⁻¹ = (f a)⁻¹ :=
eq_inv_of_mul_eq_one $ by rw [← mul f, mul_inv_self, one f]
end is_group_anti_hom
theorem inv_is_group_anti_hom [group α] : is_group_anti_hom (λ x : α, x⁻¹) :=
⟨mul_inv_rev⟩
namespace is_add_group_hom
variables [add_group α] [add_group β] (f : α → β) [is_add_group_hom f]
lemma sub (a b) : f (a - b) = f a - f b :=
calc f (a - b) = f (a + -b) : rfl
... = f a + f (-b) : add f _ _
... = f a - f b : by simp[neg f]
end is_add_group_hom
lemma is_add_group_hom_sub {α β} [add_group α] [add_comm_group β]
(f g : α → β) [is_add_group_hom f] [is_add_group_hom g] :
is_add_group_hom (λa, f a - g a) :=
is_add_group_hom_add f (λa, - g a)
attribute [instance] is_add_group_hom_sub
namespace units
variables [monoid α] [monoid β] (f : α → β) [is_monoid_hom f]
definition map : units α → units β :=
λ u, ⟨f u.val, f u.inv,
by rw [← is_monoid_hom.map_mul f, u.val_inv, is_monoid_hom.map_one f],
by rw [← is_monoid_hom.map_mul f, u.inv_val, is_monoid_hom.map_one f] ⟩
instance : is_group_hom (units.map f) :=
⟨λ a b, by ext; exact is_monoid_hom.map_mul f ⟩
end units
|
89502506f11b8ef58c2f09f0f5ac197113bf0915 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/dsimp_unfold_reducible_bug.lean | 4706077bd60c0e61c5757b7c2a3527f879a2dde9 | [
"Apache-2.0"
] | permissive | leanprover-community/lean | 12b87f69d92e614daea8bcc9d4de9a9ace089d0e | cce7990ea86a78bdb383e38ed7f9b5ba93c60ce0 | refs/heads/master | 1,687,508,156,644 | 1,684,951,104,000 | 1,684,951,104,000 | 169,960,991 | 457 | 107 | Apache-2.0 | 1,686,744,372,000 | 1,549,790,268,000 | C++ | UTF-8 | Lean | false | false | 696 | lean | open tactic
example ( a b : nat → nat ) ( p : (a ∘ b) 0 = 0 ) : a ( b 0 ) = 0 :=
begin
dsimp [function.comp] at p,
(do t ← get_local `p >>= infer_type, e ← to_expr ```(a (b 0) = 0), guard (t = e)),
assumption
end
example ( a b : nat → nat ) ( p : (a ∘ b) 0 = 0 ) : a ( b 0 ) = 0 :=
begin
dsimp at p {unfold_reducible := tt},
(do t ← get_local `p >>= infer_type, e ← to_expr ```(a (b 0) = 0), guard (t = e)),
assumption
end
example ( a b : nat → nat ) ( p : (a ∘ b) 0 = 0 ) : a (b 0) = 0 :=
begin
dsimp at p {unfold_reducible := tt, single_pass := tt},
(do t ← get_local `p >>= infer_type, e ← to_expr ```(a (b 0) = 0), guard (t = e)),
assumption
end
|
7e5e9db62050ebb7d5382b9518a5577de6a7e249 | 1a61aba1b67cddccce19532a9596efe44be4285f | /library/data/real/division.lean | 87ff02a6529a379daff156e3b8a708a568a01d12 | [
"Apache-2.0"
] | permissive | eigengrau/lean | 07986a0f2548688c13ba36231f6cdbee82abf4c6 | f8a773be1112015e2d232661ce616d23f12874d0 | refs/heads/master | 1,610,939,198,566 | 1,441,352,386,000 | 1,441,352,494,000 | 41,903,576 | 0 | 0 | null | 1,441,352,210,000 | 1,441,352,210,000 | null | UTF-8 | Lean | false | false | 21,996 | lean | /-
Copyright (c) 2015 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Robert Y. Lewis
The real numbers, constructed as equivalence classes of Cauchy sequences of rationals.
This construction follows Bishop and Bridges (1985).
At this point, we no longer proceed constructively: this file makes heavy use of decidability
and excluded middle.
-/
import data.real.basic data.real.order data.rat data.nat
open -[coercions] rat
open -[coercions] nat
open eq.ops pnat classical
local notation 0 := rat.of_num 0
local notation 1 := rat.of_num 1
local notation 2 := subtype.tag (nat.of_num 2) dec_trivial
namespace s
-----------------------------
-- helper lemmas
theorem and_of_not_or {a b : Prop} (H : ¬ (a ∨ b)) : ¬ a ∧ ¬ b :=
and.intro (assume H', H (or.inl H')) (assume H', H (or.inr H'))
-----------------------------
-- Facts about absolute values of sequences, to define inverse
definition s_abs (s : seq) : seq := λ n, abs (s n)
theorem abs_reg_of_reg {s : seq} (Hs : regular s) : regular (s_abs s) :=
begin
intros,
apply rat.le.trans,
apply abs_abs_sub_abs_le_abs_sub,
apply Hs
end
theorem abs_pos_of_nonzero {s : seq} (Hs : regular s) (Hnz : sep s zero) :
∃ N : ℕ+, ∀ m : ℕ+, m ≥ N → abs (s m) ≥ N⁻¹ :=
begin
rewrite [↑sep at Hnz, ↑s_lt at Hnz],
apply or.elim Hnz,
intro Hnz1,
have H' : pos (sneg s), begin
apply pos_of_pos_equiv,
rotate 2,
apply Hnz1,
rotate 1,
apply s_zero_add,
repeat (assumption | apply reg_add_reg | apply reg_neg_reg | apply zero_is_reg)
end,
cases bdd_away_of_pos (reg_neg_reg Hs) H' with [N, HN],
existsi N,
intro m Hm,
apply rat.le.trans,
apply HN m Hm,
rewrite ↑sneg,
apply neg_le_abs_self,
intro Hnz2,
let H' := pos_of_pos_equiv (reg_add_reg Hs (reg_neg_reg zero_is_reg)) (s_add_zero s Hs) Hnz2,
let H'' := bdd_away_of_pos Hs H',
cases H'' with [N, HN],
existsi N,
intro m Hm,
apply rat.le.trans,
apply HN m Hm,
apply le_abs_self
end
theorem sep_zero_of_pos {s : seq} (Hs : regular s) (Hpos : pos s) : sep s zero :=
begin
apply or.inr,
apply pos_of_pos_equiv,
rotate 2,
apply Hpos,
apply Hs,
apply equiv.symm,
apply s_sub_zero Hs
end
------------------------
-- This section could be cleaned up.
noncomputable definition pb {s : seq} (Hs : regular s) (Hpos : pos s) :=
some (abs_pos_of_nonzero Hs (sep_zero_of_pos Hs Hpos))
noncomputable definition ps {s : seq} (Hs : regular s) (Hsep : sep s zero) :=
some (abs_pos_of_nonzero Hs Hsep)
theorem pb_spec {s : seq} (Hs : regular s) (Hpos : pos s) :
∀ m : ℕ+, m ≥ (pb Hs Hpos) → abs (s m) ≥ (pb Hs Hpos)⁻¹ :=
some_spec (abs_pos_of_nonzero Hs (sep_zero_of_pos Hs Hpos))
theorem ps_spec {s : seq} (Hs : regular s) (Hsep : sep s zero) :
∀ m : ℕ+, m ≥ (ps Hs Hsep) → abs (s m) ≥ (ps Hs Hsep)⁻¹ :=
some_spec (abs_pos_of_nonzero Hs Hsep)
noncomputable definition s_inv {s : seq} (Hs : regular s) (n : ℕ+) : ℚ :=
if H : sep s zero then
(if n < (ps Hs H) then 1 / (s ((ps Hs H) * (ps Hs H) * (ps Hs H)))
else 1 / (s ((ps Hs H) * (ps Hs H) * n)))
else 0
theorem peq {s : seq} (Hsep : sep s zero) (Hpos : pos s) (Hs : regular s) :
pb Hs Hpos = ps Hs Hsep := rfl
theorem s_inv_of_sep_lt_p {s : seq} (Hs : regular s) (Hsep : sep s zero) {n : ℕ+}
(Hn : n < (ps Hs Hsep)) : s_inv Hs n = 1 / s ((ps Hs Hsep) * (ps Hs Hsep) * (ps Hs Hsep)) :=
begin
apply eq.trans,
apply dif_pos Hsep,
apply dif_pos Hn
end
theorem s_inv_of_sep_gt_p {s : seq} (Hs : regular s) (Hsep : sep s zero) {n : ℕ+}
(Hn : n ≥ (ps Hs Hsep)) : s_inv Hs n = 1 / s ((ps Hs Hsep) * (ps Hs Hsep) * n) :=
begin
apply eq.trans,
apply dif_pos Hsep,
apply dif_neg (pnat.not_lt_of_ge Hn)
end
theorem s_inv_of_pos_lt_p {s : seq} (Hs : regular s) (Hpos : pos s) {n : ℕ+}
(Hn : n < (pb Hs Hpos)) : s_inv Hs n = 1 / s ((pb Hs Hpos) * (pb Hs Hpos) * (pb Hs Hpos)) :=
s_inv_of_sep_lt_p Hs (sep_zero_of_pos Hs Hpos) Hn
theorem s_inv_of_pos_gt_p {s : seq} (Hs : regular s) (Hpos : pos s) {n : ℕ+}
(Hn : n ≥ (pb Hs Hpos)) : s_inv Hs n = 1 / s ((pb Hs Hpos) * (pb Hs Hpos) * n) :=
s_inv_of_sep_gt_p Hs (sep_zero_of_pos Hs Hpos) Hn
theorem le_ps {s : seq} (Hs : regular s) (Hsep : sep s zero) (n : ℕ+) :
abs (s_inv Hs n) ≤ (rat_of_pnat (ps Hs Hsep)) :=
if Hn : n < ps Hs Hsep then
(begin
rewrite [(s_inv_of_sep_lt_p Hs Hsep Hn), abs_one_div],
apply div_le_pnat,
apply ps_spec,
apply pnat.mul_le_mul_left
end)
else
(begin
rewrite [(s_inv_of_sep_gt_p Hs Hsep (le_of_not_gt Hn)), abs_one_div],
apply div_le_pnat,
apply ps_spec,
rewrite pnat.mul.assoc,
apply pnat.mul_le_mul_right
end)
theorem s_inv_zero : s_inv zero_is_reg = zero :=
funext (λ n, dif_neg (!not_sep_self))
theorem s_inv_of_zero' {s : seq} (Hs : regular s) (Hz : ¬ sep s zero) (n : ℕ+) : s_inv Hs n = 0 :=
dif_neg Hz
theorem s_inv_of_zero {s : seq} (Hs : regular s) (Hz : ¬ sep s zero) : s_inv Hs = zero :=
begin
apply funext,
intro n,
apply s_inv_of_zero' Hs Hz n
end
theorem s_ne_zero_of_ge_p {s : seq} (Hs : regular s) (Hsep : sep s zero) {n : ℕ+}
(Hn : n ≥ (ps Hs Hsep)) : s n ≠ 0 :=
begin
let Hps := ps_spec Hs Hsep,
apply ne_zero_of_abs_ne_zero,
apply ne_of_gt,
apply gt_of_ge_of_gt,
apply Hps,
apply Hn,
apply inv_pos
end
theorem reg_inv_reg {s : seq} (Hs : regular s) (Hsep : sep s zero) : regular (s_inv Hs) :=
begin
rewrite ↑regular,
intros,
have Hsp : s ((ps Hs Hsep) * (ps Hs Hsep) * (ps Hs Hsep)) ≠ 0, from
s_ne_zero_of_ge_p Hs Hsep !mul_le_mul_left,
have Hspn : s ((ps Hs Hsep) * (ps Hs Hsep) * n) ≠ 0, from
s_ne_zero_of_ge_p Hs Hsep (show (ps Hs Hsep) * (ps Hs Hsep) * n ≥ ps Hs Hsep, by
rewrite pnat.mul.assoc; apply pnat.mul_le_mul_right),
have Hspm : s ((ps Hs Hsep) * (ps Hs Hsep) * m) ≠ 0, from
s_ne_zero_of_ge_p Hs Hsep (show (ps Hs Hsep) * (ps Hs Hsep) * m ≥ ps Hs Hsep, by
rewrite pnat.mul.assoc; apply pnat.mul_le_mul_right),
cases em (m < ps Hs Hsep) with [Hmlt, Hmlt],
cases em (n < ps Hs Hsep) with [Hnlt, Hnlt],
rewrite [(s_inv_of_sep_lt_p Hs Hsep Hmlt), (s_inv_of_sep_lt_p Hs Hsep Hnlt)],
rewrite [sub_self, abs_zero],
apply add_invs_nonneg,
rewrite [(s_inv_of_sep_lt_p Hs Hsep Hmlt),
(s_inv_of_sep_gt_p Hs Hsep (le_of_not_gt Hnlt))],
rewrite [(!div_sub_div Hsp Hspn), div_eq_mul_one_div, *abs_mul, *mul_one, *one_mul],
apply rat.le.trans,
apply rat.mul_le_mul,
apply Hs,
rewrite [-(mul_one 1), -(!field.div_mul_div Hsp Hspn), abs_mul],
apply rat.mul_le_mul,
rewrite -(s_inv_of_sep_lt_p Hs Hsep Hmlt),
apply le_ps Hs Hsep,
rewrite -(s_inv_of_sep_gt_p Hs Hsep (le_of_not_gt Hnlt)),
apply le_ps Hs Hsep,
apply abs_nonneg,
apply le_of_lt !rat_of_pnat_is_pos,
apply abs_nonneg,
apply add_invs_nonneg,
rewrite [right_distrib, *pnat_cancel', rat.add.comm],
apply rat.add_le_add_right,
apply inv_ge_of_le,
apply pnat.le_of_lt,
apply Hmlt,
cases em (n < ps Hs Hsep) with [Hnlt, Hnlt],
rewrite [(s_inv_of_sep_lt_p Hs Hsep Hnlt),
(s_inv_of_sep_gt_p Hs Hsep (le_of_not_gt Hmlt))],
rewrite [(!div_sub_div Hspm Hsp), div_eq_mul_one_div, *abs_mul, *mul_one, *one_mul],
apply rat.le.trans,
apply rat.mul_le_mul,
apply Hs,
rewrite [-(mul_one 1), -(!field.div_mul_div Hspm Hsp), abs_mul],
apply rat.mul_le_mul,
rewrite -(s_inv_of_sep_gt_p Hs Hsep (le_of_not_gt Hmlt)),
apply le_ps Hs Hsep,
rewrite -(s_inv_of_sep_lt_p Hs Hsep Hnlt),
apply le_ps Hs Hsep,
apply abs_nonneg,
apply le_of_lt !rat_of_pnat_is_pos,
apply abs_nonneg,
apply add_invs_nonneg,
rewrite [right_distrib, *pnat_cancel', rat.add.comm],
apply rat.add_le_add_left,
apply inv_ge_of_le,
apply pnat.le_of_lt,
apply Hnlt,
rewrite [(s_inv_of_sep_gt_p Hs Hsep (le_of_not_gt Hnlt)),
(s_inv_of_sep_gt_p Hs Hsep (le_of_not_gt Hmlt))],
rewrite [(!div_sub_div Hspm Hspn), div_eq_mul_one_div, abs_mul, *one_mul, *mul_one],
apply rat.le.trans,
apply rat.mul_le_mul,
apply Hs,
rewrite [-(mul_one 1), -(!field.div_mul_div Hspm Hspn), abs_mul],
apply rat.mul_le_mul,
rewrite -(s_inv_of_sep_gt_p Hs Hsep (le_of_not_gt Hmlt)),
apply le_ps Hs Hsep,
rewrite -(s_inv_of_sep_gt_p Hs Hsep (le_of_not_gt Hnlt)),
apply le_ps Hs Hsep,
apply abs_nonneg,
apply le_of_lt !rat_of_pnat_is_pos,
apply abs_nonneg,
apply add_invs_nonneg,
rewrite [right_distrib, *pnat_cancel', rat.add.comm],
apply rat.le.refl
end
theorem s_inv_ne_zero {s : seq} (Hs : regular s) (Hsep : sep s zero) (n : ℕ+) : s_inv Hs n ≠ 0 :=
if H : n ≥ ps Hs Hsep then
(begin
rewrite (s_inv_of_sep_gt_p Hs Hsep H),
apply one_div_ne_zero,
apply s_ne_zero_of_ge_p,
apply pnat.le.trans,
apply H,
apply pnat.mul_le_mul_left
end)
else
(begin
rewrite (s_inv_of_sep_lt_p Hs Hsep (lt_of_not_ge H)),
apply one_div_ne_zero,
apply s_ne_zero_of_ge_p,
apply pnat.mul_le_mul_left
end)
theorem mul_inv {s : seq} (Hs : regular s) (Hsep : sep s zero) : smul s (s_inv Hs) ≡ one :=
begin
let Rsi := reg_inv_reg Hs Hsep,
let Rssi := reg_mul_reg Hs Rsi,
apply eq_of_bdd Rssi one_is_reg,
intros,
existsi max (ps Hs Hsep) j,
intro n Hn,
have Hnz : s_inv Hs ((K₂ s (s_inv Hs)) * 2 * n) ≠ 0, from s_inv_ne_zero Hs Hsep _,
rewrite [↑smul, ↑one, rat.mul.comm, -(mul_one_div_cancel Hnz),
-rat.mul_sub_left_distrib, abs_mul],
apply rat.le.trans,
apply rat.mul_le_mul_of_nonneg_right,
apply canon_2_bound_right s,
apply Rsi,
apply abs_nonneg,
have Hp : (K₂ s (s_inv Hs)) * 2 * n ≥ ps Hs Hsep, begin
apply pnat.le.trans,
apply max_left,
rotate 1,
apply pnat.le.trans,
apply Hn,
apply pnat.mul_le_mul_left
end,
have Hnz' : s (((ps Hs Hsep) * (ps Hs Hsep)) * ((K₂ s (s_inv Hs)) * 2 * n)) ≠ 0, from
s_ne_zero_of_ge_p Hs Hsep
(show ps Hs Hsep ≤ ((ps Hs Hsep) * (ps Hs Hsep)) * ((K₂ s (s_inv Hs)) * 2 * n),
by rewrite *pnat.mul.assoc; apply pnat.mul_le_mul_right),
rewrite [(s_inv_of_sep_gt_p Hs Hsep Hp), (division_ring.one_div_one_div Hnz')],
apply rat.le.trans,
apply rat.mul_le_mul_of_nonneg_left,
apply Hs,
apply le_of_lt,
apply rat_of_pnat_is_pos,
rewrite [rat.mul.left_distrib, mul.comm ((ps Hs Hsep) * (ps Hs Hsep)), *pnat.mul.assoc,
*(@inv_mul_eq_mul_inv (K₂ s (s_inv Hs))), -*rat.mul.assoc, *inv_cancel_left,
*one_mul, -(add_halves j)],
apply rat.add_le_add,
apply inv_ge_of_le,
apply pnat_mul_le_mul_left',
apply pnat.le.trans,
rotate 1,
apply Hn,
rotate_right 1,
apply max_right,
apply inv_ge_of_le,
apply pnat_mul_le_mul_left',
apply pnat.le.trans,
apply max_right,
rotate 1,
apply pnat.le.trans,
apply Hn,
apply pnat.mul_le_mul_right
end
theorem inv_mul {s : seq} (Hs : regular s) (Hsep : sep s zero) : smul (s_inv Hs) s ≡ one :=
begin
apply equiv.trans,
rotate 3,
apply s_mul_comm,
apply mul_inv,
repeat (assumption | apply reg_mul_reg | apply reg_inv_reg | apply zero_is_reg)
end
theorem sep_of_equiv_sep {s t : seq} (Hs : regular s) (Ht : regular t) (Heq : s ≡ t)
(Hsep : sep s zero) : sep t zero :=
begin
apply or.elim Hsep,
intro Hslt,
apply or.inl,
rewrite ↑s_lt at *,
apply pos_of_pos_equiv,
rotate 2,
apply Hslt,
rotate_right 1,
apply add_well_defined,
rotate 4,
apply equiv.refl,
apply neg_well_defined,
apply Heq,
intro Hslt,
apply or.inr,
rewrite ↑s_lt at *,
apply pos_of_pos_equiv,
rotate 2,
apply Hslt,
rotate_right 1,
apply add_well_defined,
rotate 5,
apply equiv.refl,
repeat (assumption | apply reg_neg_reg | apply reg_add_reg | apply zero_is_reg)
end
theorem inv_unique {s t : seq} (Hs : regular s) (Ht : regular t) (Hsep : sep s zero)
(Heq : smul s t ≡ one) : s_inv Hs ≡ t :=
begin
apply equiv.trans,
rotate 3,
apply equiv.symm,
apply s_mul_one,
rotate 1,
apply equiv.trans,
rotate 3,
apply mul_well_defined,
rotate 4,
apply equiv.refl,
apply equiv.symm,
apply Heq,
apply equiv.trans,
rotate 3,
apply equiv.symm,
apply s_mul_assoc,
rotate 3,
apply equiv.trans,
rotate 3,
apply mul_well_defined,
rotate 4,
apply inv_mul,
rotate 1,
apply equiv.refl,
apply s_one_mul,
repeat (assumption | apply reg_inv_reg | apply reg_mul_reg | apply one_is_reg)
end
theorem inv_well_defined {s t : seq} (Hs : regular s) (Ht : regular t) (Heq : s ≡ t) :
s_inv Hs ≡ s_inv Ht :=
if Hsep : sep s zero then
(begin
let Hsept := sep_of_equiv_sep Hs Ht Heq Hsep,
have Hm : smul t (s_inv Hs) ≡ smul s (s_inv Hs), begin
apply mul_well_defined,
repeat (assumption | apply reg_inv_reg),
apply equiv.symm s t Heq,
apply equiv.refl
end,
apply equiv.symm,
apply inv_unique,
rotate 2,
apply equiv.trans,
rotate 3,
apply Hm,
apply mul_inv,
repeat (assumption | apply reg_inv_reg | apply reg_mul_reg),
apply one_is_reg
end)
else
(have H : s_inv Hs = zero, from funext (λ n, dif_neg Hsep),
have Hsept : ¬ sep t zero, from
assume H', Hsep (sep_of_equiv_sep Ht Hs (equiv.symm _ _ Heq) H'),
have H' : s_inv Ht = zero, from funext (λ n, dif_neg Hsept),
H'⁻¹ ▸ (H⁻¹ ▸ equiv.refl zero))
theorem s_neg_neg {s : seq} : sneg (sneg s) ≡ s :=
begin
rewrite [↑equiv, ↑sneg],
intro n,
rewrite [neg_neg, sub_self, abs_zero],
apply add_invs_nonneg
end
theorem s_neg_sub {s t : seq} (Hs : regular s) (Ht : regular t) :
sneg (sadd s (sneg t)) ≡ sadd t (sneg s) :=
begin
apply equiv.trans,
rotate 3,
apply s_neg_add_eq_s_add_neg,
apply equiv.trans,
rotate 3,
apply add_well_defined,
rotate 4,
apply equiv.refl,
apply s_neg_neg,
apply s_add_comm,
repeat (assumption | apply reg_add_reg | apply reg_neg_reg)
end
theorem s_le_total {s t : seq} (Hs : regular s) (Ht : regular t) : s_le s t ∨ s_le t s :=
if H : s_le s t then or.inl H else or.inr begin
rewrite [↑s_le at *],
have H' : ∃ n : ℕ+, -n⁻¹ > sadd t (sneg s) n, begin
apply by_contradiction,
intro Hex,
have Hex' : ∀ n : ℕ+, -n⁻¹ ≤ sadd t (sneg s) n, begin
intro m,
apply by_contradiction,
intro Hm,
let Hm' := rat.lt_of_not_ge Hm,
let Hex'' := exists.intro m Hm',
apply Hex Hex''
end,
apply H Hex'
end,
eapply exists.elim H',
intro m Hm,
let Hm' := neg_lt_neg Hm,
rewrite neg_neg at Hm',
apply s_nonneg_of_pos,
rotate 1,
apply pos_of_pos_equiv,
rotate 1,
apply s_neg_sub,
rotate 2,
rewrite [↑pos, ↑sneg],
existsi m,
apply Hm',
repeat (assumption | apply reg_add_reg | apply reg_neg_reg)
end
theorem s_le_of_not_lt {s t : seq} (Hle : ¬ s_lt s t) : s_le t s :=
begin
rewrite [↑s_le, ↑nonneg, ↑s_lt at Hle, ↑pos at Hle],
let Hle' := iff.mp forall_iff_not_exists Hle,
intro n,
let Hn := neg_le_neg (rat.le_of_not_gt (Hle' n)),
rewrite [↑sadd, ↑sneg, add_neg_eq_neg_add_rev],
apply Hn
end
theorem sep_of_nequiv {s t : seq} (Hs : regular s) (Ht : regular t) (Hneq : ¬ equiv s t) :
sep s t :=
begin
rewrite ↑sep,
apply by_contradiction,
intro Hnor,
let Hand := and_of_not_or Hnor,
let Hle1 := s_le_of_not_lt (and.left Hand),
let Hle2 := s_le_of_not_lt (and.right Hand),
apply Hneq (equiv_of_le_of_ge Hs Ht Hle2 Hle1)
end
theorem s_zero_inv_equiv_zero : s_inv zero_is_reg ≡ zero :=
by rewrite s_inv_zero; apply equiv.refl
theorem lt_or_equiv_of_le {s t : seq} (Hs : regular s) (Ht : regular t) (Hle : s_le s t) :
s_lt s t ∨ s ≡ t :=
if H : s ≡ t then or.inr H else
or.inl (lt_of_le_and_sep Hs Ht (and.intro Hle (sep_of_nequiv Hs Ht H)))
theorem s_le_of_equiv_le_left {s t u : seq} (Hs : regular s) (Ht : regular t) (Hu : regular u)
(Heq : s ≡ t) (Hle : s_le s u) : s_le t u :=
begin
rewrite ↑s_le at *,
apply nonneg_of_nonneg_equiv,
rotate 2,
apply add_well_defined,
rotate 4,
apply equiv.refl,
apply neg_well_defined,
apply Heq,
repeat (assumption | apply reg_add_reg | apply reg_neg_reg)
end
theorem s_le_of_equiv_le_right {s t u : seq} (Hs : regular s) (Ht : regular t) (Hu : regular u)
(Heq : t ≡ u) (Hle : s_le s t) : s_le s u :=
begin
rewrite ↑s_le at *,
apply nonneg_of_nonneg_equiv,
rotate 2,
apply add_well_defined,
rotate 4,
apply Heq,
apply equiv.refl,
repeat (assumption | apply reg_add_reg | apply reg_neg_reg)
end
-----------------------------
noncomputable definition r_inv (s : reg_seq) : reg_seq := reg_seq.mk (s_inv (reg_seq.is_reg s))
(if H : sep (reg_seq.sq s) zero then reg_inv_reg (reg_seq.is_reg s) H else
have Hz : s_inv (reg_seq.is_reg s) = zero, from funext (λ n, dif_neg H), Hz⁻¹ ▸ zero_is_reg)
theorem r_inv_zero : requiv (r_inv r_zero) r_zero :=
s_zero_inv_equiv_zero
theorem r_inv_well_defined {s t : reg_seq} (H : requiv s t) : requiv (r_inv s) (r_inv t) :=
inv_well_defined (reg_seq.is_reg s) (reg_seq.is_reg t) H
theorem r_le_total (s t : reg_seq) : r_le s t ∨ r_le t s :=
s_le_total (reg_seq.is_reg s) (reg_seq.is_reg t)
theorem r_mul_inv (s : reg_seq) (Hsep : r_sep s r_zero) : requiv (s * (r_inv s)) r_one :=
mul_inv (reg_seq.is_reg s) Hsep
theorem r_sep_of_nequiv (s t : reg_seq) (Hneq : ¬ requiv s t) : r_sep s t :=
sep_of_nequiv (reg_seq.is_reg s) (reg_seq.is_reg t) Hneq
theorem r_lt_or_equiv_of_le (s t : reg_seq) (Hle : r_le s t) : r_lt s t ∨ requiv s t :=
lt_or_equiv_of_le (reg_seq.is_reg s) (reg_seq.is_reg t) Hle
theorem r_le_of_equiv_le_left {s t u : reg_seq} (Heq : requiv s t) (Hle : r_le s u) : r_le t u :=
s_le_of_equiv_le_left (reg_seq.is_reg s) (reg_seq.is_reg t) (reg_seq.is_reg u) Heq Hle
theorem r_le_of_equiv_le_right {s t u : reg_seq} (Heq : requiv t u) (Hle : r_le s t) : r_le s u :=
s_le_of_equiv_le_right (reg_seq.is_reg s) (reg_seq.is_reg t) (reg_seq.is_reg u) Heq Hle
end s
namespace real
open [classes] s
noncomputable definition inv (x : ℝ) : ℝ := quot.lift_on x (λ a, quot.mk (s.r_inv a))
(λ a b H, quot.sound (s.r_inv_well_defined H))
postfix [priority real.prio] `⁻¹` := inv
theorem le_total (x y : ℝ) : x ≤ y ∨ y ≤ x :=
quot.induction_on₂ x y (λ s t, s.r_le_total s t)
theorem mul_inv' (x : ℝ) : x ≢ 0 → x * x⁻¹ = 1 :=
quot.induction_on x (λ s H, quot.sound (s.r_mul_inv s H))
theorem inv_mul' (x : ℝ) : x ≢ 0 → x⁻¹ * x = 1 :=
by rewrite real.mul_comm; apply mul_inv'
theorem neq_of_sep {x y : ℝ} (H : x ≢ y) : ¬ x = y :=
assume Heq, !not_sep_self (Heq ▸ H)
theorem sep_of_neq {x y : ℝ} : ¬ x = y → x ≢ y :=
quot.induction_on₂ x y (λ s t H, s.r_sep_of_nequiv s t (assume Heq, H (quot.sound Heq)))
theorem sep_is_neq (x y : ℝ) : (x ≢ y) = (¬ x = y) :=
propext (iff.intro neq_of_sep sep_of_neq)
theorem mul_inv (x : ℝ) : x ≠ 0 → x * x⁻¹ = 1 := !sep_is_neq ▸ !mul_inv'
theorem inv_mul (x : ℝ) : x ≠ 0 → x⁻¹ * x = 1 := !sep_is_neq ▸ !inv_mul'
theorem inv_zero : (0 : ℝ)⁻¹ = 0 := quot.sound (s.r_inv_zero)
theorem lt_or_eq_of_le (x y : ℝ) : x ≤ y → x < y ∨ x = y :=
quot.induction_on₂ x y (λ s t H, or.elim (s.r_lt_or_equiv_of_le s t H)
(assume H1, or.inl H1)
(assume H2, or.inr (quot.sound H2)))
theorem le_iff_lt_or_eq (x y : ℝ) : x ≤ y ↔ x < y ∨ x = y :=
iff.intro (lt_or_eq_of_le x y) (le_of_lt_or_eq x y)
noncomputable definition dec_lt : decidable_rel lt :=
begin
rewrite ↑decidable_rel,
intros,
apply prop_decidable
end
section migrate_algebra
open [classes] algebra
protected noncomputable definition discrete_linear_ordered_field [reducible] :
algebra.discrete_linear_ordered_field ℝ :=
⦃ algebra.discrete_linear_ordered_field, real.comm_ring, real.ordered_ring,
le_total := le_total,
mul_inv_cancel := mul_inv,
inv_mul_cancel := inv_mul,
zero_lt_one := zero_lt_one,
inv_zero := inv_zero,
le_iff_lt_or_eq := le_iff_lt_or_eq,
decidable_lt := dec_lt
⦄
local attribute real.discrete_linear_ordered_field [trans-instance]
local attribute real.comm_ring [instance]
local attribute real.ordered_ring [instance]
noncomputable definition abs (n : ℝ) : ℝ := algebra.abs n
noncomputable definition sign (n : ℝ) : ℝ := algebra.sign n
noncomputable definition max (a b : ℝ) : ℝ := algebra.max a b
noncomputable definition min (a b : ℝ) : ℝ := algebra.min a b
noncomputable definition divide (a b : ℝ): ℝ := algebra.divide a b
migrate from algebra with real
replacing has_le.ge → ge, has_lt.gt → gt, sub → sub, abs → abs, sign → sign, dvd → dvd,
divide → divide, max → max, min → min, pow → pow, nmul → nmul, imul → imul
end migrate_algebra
infix / := divide
end real
|
2abbf9cdb3eb1c75cc353950891eeaafae557712 | dd0f5513e11c52db157d2fcc8456d9401a6cd9da | /09_Type_Classes.org.21.lean | d5cc2c7be5651de5e41e3b42e73f4425c37ce020 | [] | 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 | 89 | lean | import standard
import standard
-- BEGIN
print classes
print instances inhabited
-- END
|
584796feecb361dd324dc68ea968cbc0b4cbf3e0 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/number_theory/arithmetic_function.lean | 6e57901662c52f85c24d0ca744bad397db65bc34 | [
"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 | 32,432 | lean | /-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import algebra.big_operators.ring
import number_theory.divisors
import algebra.squarefree
import algebra.invertible
/-!
# Arithmetic Functions and Dirichlet Convolution
This file defines arithmetic functions, which are functions from `ℕ` to a specified type that map 0
to 0. In the literature, they are often instead defined as functions from `ℕ+`. These arithmetic
functions are endowed with a multiplication, given by Dirichlet convolution, and pointwise addition,
to form the Dirichlet ring.
## Main Definitions
* `arithmetic_function R` consists of functions `f : ℕ → R` such that `f 0 = 0`.
* An arithmetic function `f` `is_multiplicative` when `x.coprime y → f (x * y) = f x * f y`.
* The pointwise operations `pmul` and `ppow` differ from the multiplication
and power instances on `arithmetic_function R`, which use Dirichlet multiplication.
* `ζ` is the arithmetic function such that `ζ x = 1` for `0 < x`.
* `σ k` is the arithmetic function such that `σ k x = ∑ y in divisors x, y ^ k` for `0 < x`.
* `pow k` is the arithmetic function such that `pow k x = x ^ k` for `0 < x`.
* `id` is the identity arithmetic function on `ℕ`.
* `ω n` is the number of distinct prime factors of `n`.
* `Ω n` is the number of prime factors of `n` counted with multiplicity.
* `μ` is the Möbius function.
## Main Results
* Several forms of Möbius inversion:
* `sum_eq_iff_sum_mul_moebius_eq` for functions to a `comm_ring`
* `sum_eq_iff_sum_smul_moebius_eq` for functions to an `add_comm_group`
* `prod_eq_iff_prod_pow_moebius_eq` for functions to a `comm_group`
* `prod_eq_iff_prod_pow_moebius_eq_of_nonzero` for functions to a `comm_group_with_zero`
## Notation
The arithmetic functions `ζ` and `σ` have Greek letter names, which are localized notation in
the namespace `arithmetic_function`.
## Tags
arithmetic functions, dirichlet convolution, divisors
-/
open finset
open_locale big_operators
namespace nat
variable (R : Type*)
/-- An arithmetic function is a function from `ℕ` that maps 0 to 0. In the literature, they are
often instead defined as functions from `ℕ+`. Multiplication on `arithmetic_functions` is by
Dirichlet convolution. -/
@[derive [has_coe_to_fun, has_zero, inhabited]]
def arithmetic_function [has_zero R] := zero_hom ℕ R
variable {R}
namespace arithmetic_function
section has_zero
variable [has_zero R]
@[simp] lemma to_fun_eq (f : arithmetic_function R) : f.to_fun = f := rfl
@[simp]
lemma map_zero {f : arithmetic_function R} : f 0 = 0 :=
zero_hom.map_zero' f
theorem coe_inj {f g : arithmetic_function R} : (f : ℕ → R) = g ↔ f = g :=
⟨λ h, zero_hom.coe_inj h, λ h, h ▸ rfl⟩
@[simp]
lemma zero_apply {x : ℕ} : (0 : arithmetic_function R) x = 0 :=
zero_hom.zero_apply x
@[ext] theorem ext ⦃f g : arithmetic_function R⦄ (h : ∀ x, f x = g x) : f = g :=
zero_hom.ext h
theorem ext_iff {f g : arithmetic_function R} : f = g ↔ ∀ x, f x = g x :=
zero_hom.ext_iff
section has_one
variable [has_one R]
instance : has_one (arithmetic_function R) := ⟨⟨λ x, ite (x = 1) 1 0, rfl⟩⟩
@[simp]
lemma one_one : (1 : arithmetic_function R) 1 = 1 := rfl
@[simp]
lemma one_apply_ne {x : ℕ} (h : x ≠ 1) : (1 : arithmetic_function R) x = 0 := if_neg h
end has_one
end has_zero
instance nat_coe [has_zero R] [has_one R] [has_add R] :
has_coe (arithmetic_function ℕ) (arithmetic_function R) :=
⟨λ f, ⟨↑(f : ℕ → ℕ), by { transitivity ↑(f 0), refl, simp }⟩⟩
@[simp]
lemma nat_coe_nat (f : arithmetic_function ℕ) :
(↑f : arithmetic_function ℕ) = f :=
ext $ λ _, cast_id _
@[simp]
lemma nat_coe_apply [has_zero R] [has_one R] [has_add R] {f : arithmetic_function ℕ} {x : ℕ} :
(f : arithmetic_function R) x = f x := rfl
instance int_coe [has_zero R] [has_one R] [has_add R] [has_neg R] :
has_coe (arithmetic_function ℤ) (arithmetic_function R) :=
⟨λ f, ⟨↑(f : ℕ → ℤ), by { transitivity ↑(f 0), refl, simp }⟩⟩
@[simp]
lemma int_coe_int (f : arithmetic_function ℤ) :
(↑f : arithmetic_function ℤ) = f :=
ext $ λ _, int.cast_id _
@[simp]
lemma int_coe_apply [has_zero R] [has_one R] [has_add R] [has_neg R]
{f : arithmetic_function ℤ} {x : ℕ} :
(f : arithmetic_function R) x = f x := rfl
@[simp]
lemma coe_coe [has_zero R] [has_one R] [has_add R] [has_neg R] {f : arithmetic_function ℕ} :
((f : arithmetic_function ℤ) : arithmetic_function R) = f :=
by { ext, simp, }
section add_monoid
variable [add_monoid R]
instance : has_add (arithmetic_function R) := ⟨λ f g, ⟨λ n, f n + g n, by simp⟩⟩
@[simp]
lemma add_apply {f g : arithmetic_function R} {n : ℕ} : (f + g) n = f n + g n := rfl
instance : add_monoid (arithmetic_function R) :=
{ add_assoc := λ _ _ _, ext (λ _, add_assoc _ _ _),
zero_add := λ _, ext (λ _, zero_add _),
add_zero := λ _, ext (λ _, add_zero _),
.. arithmetic_function.has_zero R,
.. arithmetic_function.has_add }
end add_monoid
instance [add_comm_monoid R] : add_comm_monoid (arithmetic_function R) :=
{ add_comm := λ _ _, ext (λ _, add_comm _ _),
.. arithmetic_function.add_monoid }
instance [add_group R] : add_group (arithmetic_function R) :=
{ neg := λ f, ⟨λ n, - f n, by simp⟩,
add_left_neg := λ _, ext (λ _, add_left_neg _),
.. arithmetic_function.add_monoid }
instance [add_comm_group R] : add_comm_group (arithmetic_function R) :=
{ .. arithmetic_function.add_comm_monoid,
.. arithmetic_function.add_group }
section has_scalar
variables {M : Type*} [has_zero R] [add_comm_monoid M] [has_scalar R M]
/-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function
such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/
instance : has_scalar (arithmetic_function R) (arithmetic_function M) :=
⟨λ f g, ⟨λ n, ∑ x in divisors_antidiagonal n, f x.fst • g x.snd, by simp⟩⟩
@[simp]
lemma smul_apply {f : arithmetic_function R} {g : arithmetic_function M} {n : ℕ} :
(f • g) n = ∑ x in divisors_antidiagonal n, f x.fst • g x.snd := rfl
end has_scalar
/-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function
such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/
instance [semiring R] : has_mul (arithmetic_function R) := ⟨(•)⟩
@[simp]
lemma mul_apply [semiring R] {f g : arithmetic_function R} {n : ℕ} :
(f * g) n = ∑ x in divisors_antidiagonal n, f x.fst * g x.snd := rfl
section module
variables {M : Type*} [semiring R] [add_comm_monoid M] [module R M]
lemma mul_smul' (f g : arithmetic_function R) (h : arithmetic_function M) :
(f * g) • h = f • g • h :=
begin
ext n,
simp only [mul_apply, smul_apply, sum_smul, mul_smul, smul_sum, finset.sum_sigma'],
apply finset.sum_bij,
swap 5,
{ rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H, exact ⟨(k, l*j), (l, j)⟩ },
{ rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H,
simp only [finset.mem_sigma, mem_divisors_antidiagonal] at H ⊢,
rcases H with ⟨⟨rfl, n0⟩, rfl, i0⟩,
refine ⟨⟨(mul_assoc _ _ _).symm, n0⟩, rfl, _⟩,
rw mul_ne_zero_iff at *,
exact ⟨i0.2, n0.2⟩, },
{ rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H, simp only [mul_assoc] },
{ rintros ⟨⟨a,b⟩, ⟨c,d⟩⟩ ⟨⟨i,j⟩, ⟨k,l⟩⟩ H₁ H₂,
simp only [finset.mem_sigma, mem_divisors_antidiagonal,
and_imp, prod.mk.inj_iff, add_comm, heq_iff_eq] at H₁ H₂ ⊢,
rintros rfl h2 rfl rfl,
exact ⟨⟨eq.trans H₁.2.1.symm H₂.2.1, rfl⟩, rfl, rfl⟩ },
{ rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H, refine ⟨⟨(i*k, l), (i, k)⟩, _, _⟩,
{ simp only [finset.mem_sigma, mem_divisors_antidiagonal] at H ⊢,
rcases H with ⟨⟨rfl, n0⟩, rfl, j0⟩,
refine ⟨⟨mul_assoc _ _ _, n0⟩, rfl, _⟩,
rw mul_ne_zero_iff at *,
exact ⟨n0.1, j0.1⟩ },
{ simp only [true_and, mem_divisors_antidiagonal, and_true, prod.mk.inj_iff, eq_self_iff_true,
ne.def, mem_sigma, heq_iff_eq] at H ⊢,
rw H.2.1 } }
end
lemma one_smul' (b : arithmetic_function M) :
(1 : arithmetic_function R) • b = b :=
begin
ext,
rw smul_apply,
by_cases x0 : x = 0, {simp [x0]},
have h : {(1,x)} ⊆ divisors_antidiagonal x := by simp [x0],
rw ← sum_subset h, {simp},
intros y ymem ynmem,
have y1ne : y.fst ≠ 1,
{ intro con,
simp only [con, mem_divisors_antidiagonal, one_mul, ne.def] at ymem,
simp only [mem_singleton, prod.ext_iff] at ynmem,
tauto },
simp [y1ne],
end
end module
section semiring
variable [semiring R]
instance : monoid (arithmetic_function R) :=
{ one_mul := one_smul',
mul_one := λ f,
begin
ext,
rw mul_apply,
by_cases x0 : x = 0, {simp [x0]},
have h : {(x,1)} ⊆ divisors_antidiagonal x := by simp [x0],
rw ← sum_subset h, {simp},
intros y ymem ynmem,
have y2ne : y.snd ≠ 1,
{ intro con,
simp only [con, mem_divisors_antidiagonal, mul_one, ne.def] at ymem,
simp only [mem_singleton, prod.ext_iff] at ynmem,
tauto },
simp [y2ne],
end,
mul_assoc := mul_smul',
.. arithmetic_function.has_one,
.. arithmetic_function.has_mul }
instance : semiring (arithmetic_function R) :=
{ zero_mul := λ f, by { ext, simp only [mul_apply, zero_mul, sum_const_zero, zero_apply] },
mul_zero := λ f, by { ext, simp only [mul_apply, sum_const_zero, mul_zero, zero_apply] },
left_distrib := λ a b c, by { ext, simp only [←sum_add_distrib, mul_add, mul_apply, add_apply] },
right_distrib := λ a b c, by { ext, simp only [←sum_add_distrib, add_mul, mul_apply, add_apply] },
.. arithmetic_function.has_zero R,
.. arithmetic_function.has_mul,
.. arithmetic_function.has_add,
.. arithmetic_function.add_comm_monoid,
.. arithmetic_function.monoid }
end semiring
instance [comm_semiring R] : comm_semiring (arithmetic_function R) :=
{ mul_comm := λ f g, by { ext,
rw [mul_apply, ← map_swap_divisors_antidiagonal, sum_map],
simp [mul_comm] },
.. arithmetic_function.semiring }
instance [comm_ring R] : comm_ring (arithmetic_function R) :=
{ .. arithmetic_function.add_comm_group,
.. arithmetic_function.comm_semiring }
instance {M : Type*} [semiring R] [add_comm_monoid M] [module R M] :
module (arithmetic_function R) (arithmetic_function M) :=
{ one_smul := one_smul',
mul_smul := mul_smul',
smul_add := λ r x y, by { ext, simp only [sum_add_distrib, smul_add, smul_apply, add_apply] },
smul_zero := λ r, by { ext, simp only [smul_apply, sum_const_zero, smul_zero, zero_apply] },
add_smul := λ r s x, by { ext, simp only [add_smul, sum_add_distrib, smul_apply, add_apply] },
zero_smul := λ r, by { ext, simp only [smul_apply, sum_const_zero, zero_smul, zero_apply] }, }
section zeta
/-- `ζ 0 = 0`, otherwise `ζ x = 1`. The Dirichlet Series is the Riemann ζ. -/
def zeta : arithmetic_function ℕ :=
⟨λ x, ite (x = 0) 0 1, rfl⟩
localized "notation `ζ` := zeta" in arithmetic_function
@[simp]
lemma zeta_apply {x : ℕ} : ζ x = if (x = 0) then 0 else 1 := rfl
lemma zeta_apply_ne {x : ℕ} (h : x ≠ 0) : ζ x = 1 := if_neg h
@[simp]
theorem coe_zeta_mul_apply [semiring R] {f : arithmetic_function R} {x : ℕ} :
(↑ζ * f) x = ∑ i in divisors x, f i :=
begin
rw mul_apply,
transitivity ∑ i in divisors_antidiagonal x, f i.snd,
{ apply sum_congr rfl,
intros i hi,
rcases mem_divisors_antidiagonal.1 hi with ⟨rfl, h⟩,
rw [nat_coe_apply, zeta_apply_ne (left_ne_zero_of_mul h), cast_one, one_mul] },
{ apply sum_bij (λ i h, prod.snd i),
{ rintros ⟨a, b⟩ h, simp [snd_mem_divisors_of_mem_antidiagonal h] },
{ rintros ⟨a, b⟩ h, refl },
{ rintros ⟨a1, b1⟩ ⟨a2, b2⟩ h1 h2 h,
dsimp at h,
rw h at *,
rw mem_divisors_antidiagonal at *,
ext, swap, {refl},
simp only [prod.fst, prod.snd] at *,
apply nat.eq_of_mul_eq_mul_right _ (eq.trans h1.1 h2.1.symm),
rcases h1 with ⟨rfl, h⟩,
apply nat.pos_of_ne_zero (right_ne_zero_of_mul h) },
{ intros a ha,
rcases mem_divisors.1 ha with ⟨⟨b, rfl⟩, ne0⟩,
use (b, a),
simp [ne0, mul_comm] } }
end
theorem coe_zeta_smul_apply {M : Type*} [comm_ring R] [add_comm_group M] [module R M]
{f : arithmetic_function M} {x : ℕ} :
((↑ζ : arithmetic_function R) • f) x = ∑ i in divisors x, f i :=
begin
rw smul_apply,
transitivity ∑ i in divisors_antidiagonal x, f i.snd,
{ apply sum_congr rfl,
intros i hi,
rcases mem_divisors_antidiagonal.1 hi with ⟨rfl, h⟩,
rw [nat_coe_apply, zeta_apply_ne (left_ne_zero_of_mul h), cast_one, one_smul] },
{ apply sum_bij (λ i h, prod.snd i),
{ rintros ⟨a, b⟩ h, simp [snd_mem_divisors_of_mem_antidiagonal h] },
{ rintros ⟨a, b⟩ h, refl },
{ rintros ⟨a1, b1⟩ ⟨a2, b2⟩ h1 h2 h,
dsimp at h,
rw h at *,
rw mem_divisors_antidiagonal at *,
ext, swap, {refl},
simp only [prod.fst, prod.snd] at *,
apply nat.eq_of_mul_eq_mul_right _ (eq.trans h1.1 h2.1.symm),
rcases h1 with ⟨rfl, h⟩,
apply nat.pos_of_ne_zero (right_ne_zero_of_mul h) },
{ intros a ha,
rcases mem_divisors.1 ha with ⟨⟨b, rfl⟩, ne0⟩,
use (b, a),
simp [ne0, mul_comm] } }
end
@[simp]
theorem coe_mul_zeta_apply [semiring R] {f : arithmetic_function R} {x : ℕ} :
(f * ζ) x = ∑ i in divisors x, f i :=
begin
apply opposite.op_injective,
rw [op_sum],
convert @coe_zeta_mul_apply Rᵒᵖ _ { to_fun := opposite.op ∘ f, map_zero' := by simp} x,
rw [mul_apply, mul_apply, op_sum],
conv_lhs { rw ← map_swap_divisors_antidiagonal, },
rw sum_map,
apply sum_congr rfl,
intros y hy,
by_cases h1 : y.fst = 0,
{ simp [function.comp_apply, h1] },
{ simp only [h1, mul_one, one_mul, prod.fst_swap, function.embedding.coe_fn_mk, prod.snd_swap,
if_false, zeta_apply, zero_hom.coe_mk, nat_coe_apply, cast_one] }
end
theorem zeta_mul_apply {f : arithmetic_function ℕ} {x : ℕ} :
(ζ * f) x = ∑ i in divisors x, f i :=
by rw [← nat_coe_nat ζ, coe_zeta_mul_apply]
theorem mul_zeta_apply {f : arithmetic_function ℕ} {x : ℕ} :
(f * ζ) x = ∑ i in divisors x, f i :=
by rw [← nat_coe_nat ζ, coe_mul_zeta_apply]
end zeta
open_locale arithmetic_function
section pmul
/-- This is the pointwise product of `arithmetic_function`s. -/
def pmul [mul_zero_class R] (f g : arithmetic_function R) :
arithmetic_function R :=
⟨λ x, f x * g x, by simp⟩
@[simp]
lemma pmul_apply [mul_zero_class R] {f g : arithmetic_function R} {x : ℕ} :
f.pmul g x = f x * g x := rfl
lemma pmul_comm [comm_monoid_with_zero R] (f g : arithmetic_function R) :
f.pmul g = g.pmul f :=
by { ext, simp [mul_comm] }
variable [semiring R]
@[simp]
lemma pmul_zeta (f : arithmetic_function R) : f.pmul ↑ζ = f :=
begin
ext x,
cases x;
simp [nat.succ_ne_zero],
end
@[simp]
lemma zeta_pmul (f : arithmetic_function R) : (ζ : arithmetic_function R).pmul f = f :=
begin
ext x,
cases x;
simp [nat.succ_ne_zero],
end
/-- This is the pointwise power of `arithmetic_function`s. -/
def ppow (f : arithmetic_function R) (k : ℕ) :
arithmetic_function R :=
if h0 : k = 0 then ζ else ⟨λ x, (f x) ^ k,
by { rw [map_zero], exact zero_pow (nat.pos_of_ne_zero h0) }⟩
@[simp]
lemma ppow_zero {f : arithmetic_function R} : f.ppow 0 = ζ :=
by rw [ppow, dif_pos rfl]
@[simp]
lemma ppow_apply {f : arithmetic_function R} {k x : ℕ} (kpos : 0 < k) :
f.ppow k x = (f x) ^ k :=
by { rw [ppow, dif_neg (ne_of_gt kpos)], refl }
lemma ppow_succ {f : arithmetic_function R} {k : ℕ} :
f.ppow (k + 1) = f.pmul (f.ppow k) :=
begin
ext x,
rw [ppow_apply (nat.succ_pos k), pow_succ],
induction k; simp,
end
lemma ppow_succ' {f : arithmetic_function R} {k : ℕ} {kpos : 0 < k} :
f.ppow (k + 1) = (f.ppow k).pmul f :=
begin
ext x,
rw [ppow_apply (nat.succ_pos k), pow_succ'],
induction k; simp,
end
end pmul
/-- Multiplicative functions -/
def is_multiplicative [monoid_with_zero R] (f : arithmetic_function R) : Prop :=
f 1 = 1 ∧ (∀ {m n : ℕ}, m.coprime n → f (m * n) = f m * f n)
namespace is_multiplicative
section monoid_with_zero
variable [monoid_with_zero R]
@[simp]
lemma map_one {f : arithmetic_function R} (h : f.is_multiplicative) : f 1 = 1 :=
h.1
@[simp]
lemma map_mul_of_coprime {f : arithmetic_function R} (hf : f.is_multiplicative)
{m n : ℕ} (h : m.coprime n) : f (m * n) = f m * f n :=
hf.2 h
end monoid_with_zero
lemma nat_cast {f : arithmetic_function ℕ} [semiring R] (h : f.is_multiplicative) :
is_multiplicative (f : arithmetic_function R) :=
⟨by simp [h], λ m n cop, by simp [cop, h]⟩
lemma int_cast {f : arithmetic_function ℤ} [ring R] (h : f.is_multiplicative) :
is_multiplicative (f : arithmetic_function R) :=
⟨by simp [h], λ m n cop, by simp [cop, h]⟩
lemma mul [comm_semiring R] {f g : arithmetic_function R}
(hf : f.is_multiplicative) (hg : g.is_multiplicative) :
is_multiplicative (f * g) :=
⟨by { simp [hf, hg], }, begin
simp only [mul_apply],
intros m n cop,
rw sum_mul_sum,
symmetry,
apply sum_bij (λ (x : (ℕ × ℕ) × ℕ × ℕ) h, (x.1.1 * x.2.1, x.1.2 * x.2.2)),
{ rintros ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ h,
simp only [mem_divisors_antidiagonal, ne.def, mem_product] at h,
rcases h with ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩,
simp only [mem_divisors_antidiagonal, nat.mul_eq_zero, ne.def],
split, {ring},
rw nat.mul_eq_zero at *,
apply not_or ha hb },
{ rintros ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ h,
simp only [mem_divisors_antidiagonal, ne.def, mem_product] at h,
rcases h with ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩,
dsimp only,
rw [hf.map_mul_of_coprime cop.coprime_mul_right.coprime_mul_right_right,
hg.map_mul_of_coprime cop.coprime_mul_left.coprime_mul_left_right],
ring, },
{ rintros ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ ⟨⟨c1, c2⟩, ⟨d1, d2⟩⟩ hab hcd h,
simp only [mem_divisors_antidiagonal, ne.def, mem_product] at hab,
rcases hab with ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩,
simp only [mem_divisors_antidiagonal, ne.def, mem_product] at hcd,
simp only [prod.mk.inj_iff] at h,
ext; dsimp only,
{ transitivity nat.gcd (a1 * a2) (a1 * b1),
{ rw [nat.gcd_mul_left, cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one] },
{ rw [← hcd.1.1, ← hcd.2.1] at cop,
rw [← hcd.1.1, h.1, nat.gcd_mul_left,
cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one] } },
{ transitivity nat.gcd (a1 * a2) (a2 * b2),
{ rw [mul_comm, nat.gcd_mul_left, cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one,
mul_one] },
{ rw [← hcd.1.1, ← hcd.2.1] at cop,
rw [← hcd.1.1, h.2, mul_comm, nat.gcd_mul_left,
cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one, mul_one] } },
{ transitivity nat.gcd (b1 * b2) (a1 * b1),
{ rw [mul_comm, nat.gcd_mul_right,
cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, one_mul] },
{ rw [← hcd.1.1, ← hcd.2.1] at cop,
rw [← hcd.2.1, h.1, mul_comm c1 d1, nat.gcd_mul_left,
cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, mul_one] } },
{ transitivity nat.gcd (b1 * b2) (a2 * b2),
{ rw [nat.gcd_mul_right,
cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one, one_mul] },
{ rw [← hcd.1.1, ← hcd.2.1] at cop,
rw [← hcd.2.1, h.2, nat.gcd_mul_right,
cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one, one_mul] } } },
{ rintros ⟨b1, b2⟩ h,
simp only [mem_divisors_antidiagonal, ne.def, mem_product] at h,
use ((b1.gcd m, b2.gcd m), (b1.gcd n, b2.gcd n)),
simp only [exists_prop, prod.mk.inj_iff, ne.def, mem_product, mem_divisors_antidiagonal],
rw [← cop.gcd_mul _, ← cop.gcd_mul _, ← h.1, nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop h.1,
nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop.symm _],
{ rw [nat.mul_eq_zero, decidable.not_or_iff_and_not] at h, simp [h.2.1, h.2.2] },
rw [mul_comm n m, h.1] }
end⟩
lemma pmul [comm_semiring R] {f g : arithmetic_function R}
(hf : f.is_multiplicative) (hg : g.is_multiplicative) :
is_multiplicative (f.pmul g) :=
⟨by { simp [hf, hg], }, λ m n cop, begin
simp only [pmul_apply, hf.map_mul_of_coprime cop, hg.map_mul_of_coprime cop],
ring,
end⟩
end is_multiplicative
section special_functions
/-- The identity on `ℕ` as an `arithmetic_function`. -/
def id : arithmetic_function ℕ := ⟨id, rfl⟩
@[simp]
lemma id_apply {x : ℕ} : id x = x := rfl
/-- `pow k n = n ^ k`, except `pow 0 0 = 0`. -/
def pow (k : ℕ) : arithmetic_function ℕ := id.ppow k
@[simp]
lemma pow_apply {k n : ℕ} : pow k n = if (k = 0 ∧ n = 0) then 0 else n ^ k :=
begin
cases k,
{ simp [pow] },
simp [pow, (ne_of_lt (nat.succ_pos k)).symm],
end
/-- `σ k n` is the sum of the `k`th powers of the divisors of `n` -/
def sigma (k : ℕ) : arithmetic_function ℕ :=
⟨λ n, ∑ d in divisors n, d ^ k, by simp⟩
localized "notation `σ` := sigma" in arithmetic_function
@[simp]
lemma sigma_apply {k n : ℕ} : σ k n = ∑ d in divisors n, d ^ k := rfl
lemma sigma_one_apply {n : ℕ} : σ 1 n = ∑ d in divisors n, d := by simp
lemma zeta_mul_pow_eq_sigma {k : ℕ} : ζ * pow k = σ k :=
begin
ext,
rw [sigma, zeta_mul_apply],
apply sum_congr rfl,
intros x hx,
rw [pow_apply, if_neg (not_and_of_not_right _ _)],
contrapose! hx,
simp [hx],
end
lemma is_multiplicative_zeta : is_multiplicative ζ :=
⟨by simp, λ m n cop, begin
cases m, {simp},
cases n, {simp},
simp [nat.succ_ne_zero]
end⟩
lemma is_multiplicative_id : is_multiplicative arithmetic_function.id :=
⟨rfl, λ _ _ _, rfl⟩
lemma is_multiplicative.ppow [comm_semiring R] {f : arithmetic_function R}
(hf : f.is_multiplicative) {k : ℕ} :
is_multiplicative (f.ppow k) :=
begin
induction k with k hi,
{ exact is_multiplicative_zeta.nat_cast },
{ rw ppow_succ,
apply hf.pmul hi },
end
lemma is_multiplicative_pow {k : ℕ} : is_multiplicative (pow k) :=
is_multiplicative_id.ppow
lemma is_multiplicative_sigma {k : ℕ} :
is_multiplicative (sigma k) :=
begin
rw [← zeta_mul_pow_eq_sigma],
apply ((is_multiplicative_zeta).mul is_multiplicative_pow)
end
/-- `Ω n` is the number of prime factors of `n`. -/
def card_factors : arithmetic_function ℕ :=
⟨λ n, n.factors.length, by simp⟩
localized "notation `Ω` := card_factors" in arithmetic_function
lemma card_factors_apply {n : ℕ} :
Ω n = n.factors.length := rfl
@[simp]
lemma card_factors_one : Ω 1 = 0 := by simp [card_factors]
lemma card_factors_eq_one_iff_prime {n : ℕ} :
Ω n = 1 ↔ n.prime :=
begin
refine ⟨λ h, _, λ h, list.length_eq_one.2 ⟨n, factors_prime h⟩⟩,
cases n,
{ contrapose! h,
simp },
rcases list.length_eq_one.1 h with ⟨x, hx⟩,
rw [← prod_factors n.succ_pos, hx, list.prod_singleton],
apply prime_of_mem_factors,
rw [hx, list.mem_singleton]
end
lemma card_factors_mul {m n : ℕ} (m0 : m ≠ 0) (n0 : n ≠ 0) :
Ω (m * n) = Ω m + Ω n :=
by rw [card_factors_apply, card_factors_apply, card_factors_apply, ← multiset.coe_card,
← factors_eq, unique_factorization_monoid.factors_mul m0 n0, factors_eq, factors_eq,
multiset.card_add, multiset.coe_card, multiset.coe_card]
lemma card_factors_multiset_prod {s : multiset ℕ} (h0 : s.prod ≠ 0) :
Ω s.prod = (multiset.map Ω s).sum :=
begin
revert h0,
apply s.induction_on, by simp,
intros a t h h0,
rw [multiset.prod_cons, mul_ne_zero_iff] at h0,
simp [h0, card_factors_mul, h],
end
/-- `ω n` is the number of distinct prime factors of `n`. -/
def card_distinct_factors : arithmetic_function ℕ :=
⟨λ n, n.factors.erase_dup.length, by simp⟩
localized "notation `ω` := card_distinct_factors" in arithmetic_function
lemma card_distinct_factors_zero : ω 0 = 0 := by simp
lemma card_distinct_factors_apply {n : ℕ} :
ω n = n.factors.erase_dup.length := rfl
lemma card_distinct_factors_eq_card_factors_iff_squarefree {n : ℕ} (h0 : n ≠ 0) :
ω n = Ω n ↔ squarefree n :=
begin
rw [squarefree_iff_nodup_factors h0, card_distinct_factors_apply],
split; intro h,
{ rw ← list.eq_of_sublist_of_length_eq n.factors.erase_dup_sublist h,
apply list.nodup_erase_dup },
{ rw list.erase_dup_eq_self.2 h,
refl }
end
/-- `μ` is the Möbius function. If `n` is squarefree with an even number of distinct prime factors,
`μ n = 1`. If `n` is squarefree with an odd number of distinct prime factors, `μ n = -1`.
If `n` is not squarefree, `μ n = 0`. -/
def moebius : arithmetic_function ℤ :=
⟨λ n, if squarefree n then (-1) ^ (card_factors n) else 0, by simp⟩
localized "notation `μ` := moebius" in arithmetic_function
@[simp]
lemma moebius_apply_of_squarefree {n : ℕ} (h : squarefree n): μ n = (-1) ^ (card_factors n) :=
if_pos h
@[simp]
lemma moebius_eq_zero_of_not_squarefree {n : ℕ} (h : ¬ squarefree n): μ n = 0 := if_neg h
lemma moebius_ne_zero_iff_squarefree {n : ℕ} : μ n ≠ 0 ↔ squarefree n :=
begin
split; intro h,
{ contrapose! h,
simp [h] },
{ simp [h, pow_ne_zero] }
end
lemma moebius_ne_zero_iff_eq_or {n : ℕ} : μ n ≠ 0 ↔ μ n = 1 ∨ μ n = -1 :=
begin
split; intro h,
{ rw moebius_ne_zero_iff_squarefree at h,
rw moebius_apply_of_squarefree h,
apply neg_one_pow_eq_or },
{ rcases h with h | h; simp [h] }
end
open unique_factorization_monoid
@[simp] lemma coe_moebius_mul_coe_zeta [comm_ring R] : (μ * ζ : arithmetic_function R) = 1 :=
begin
ext x,
cases x,
{ simp only [divisors_zero, sum_empty, ne.def, not_false_iff, coe_mul_zeta_apply,
zero_ne_one, one_apply_ne] },
cases x,
{ simp only [moebius_apply_of_squarefree, card_factors_one, squarefree_one, divisors_one,
int.cast_one, sum_singleton, coe_mul_zeta_apply, one_one, int_coe_apply, pow_zero] },
rw [coe_mul_zeta_apply, one_apply_ne (ne_of_gt (succ_lt_succ (nat.succ_pos _)))],
simp_rw [int_coe_apply],
rw [← finset.sum_int_cast, ← sum_filter_ne_zero],
convert int.cast_zero,
simp only [moebius_ne_zero_iff_squarefree],
suffices :
∑ (y : finset ℕ) in (unique_factorization_monoid.factors x.succ.succ).to_finset.powerset,
ite (squarefree y.val.prod) ((-1:ℤ) ^ Ω y.val.prod) 0 = 0,
{ have h : ∑ i in _, ite (squarefree i) ((-1:ℤ) ^ Ω i) 0 = _ :=
(sum_divisors_filter_squarefree (nat.succ_ne_zero _)),
exact (eq.trans (by congr') h).trans this },
apply eq.trans (sum_congr rfl _) (sum_powerset_neg_one_pow_card_of_nonempty _),
{ intros y hy,
rw [finset.mem_powerset, ← finset.val_le_iff, multiset.to_finset_val] at hy,
have h : unique_factorization_monoid.factors y.val.prod = y.val,
{ apply factors_multiset_prod_of_irreducible,
intros z hz,
apply irreducible_of_factor _ (multiset.subset_of_le
(le_trans hy (multiset.erase_dup_le _)) hz) },
rw [if_pos],
{ rw [card_factors_apply, ← multiset.coe_card, ← factors_eq, h, finset.card] },
rw [unique_factorization_monoid.squarefree_iff_nodup_factors, h],
{ apply y.nodup },
rw [ne.def, multiset.prod_eq_zero_iff],
intro con,
rw ← h at con,
exact not_irreducible_zero (irreducible_of_factor 0 con) },
{ rw finset.nonempty,
rcases wf_dvd_monoid.exists_irreducible_factor _ (nat.succ_ne_zero _) with ⟨i, hi⟩,
{ rcases exists_mem_factors_of_dvd (nat.succ_ne_zero _) hi.1 hi.2 with ⟨j, hj, hj2⟩,
use j,
apply multiset.mem_to_finset.2 hj },
rw nat.is_unit_iff,
norm_num },
end
@[simp] lemma coe_zeta_mul_coe_moebius [comm_ring R] : (ζ * μ : arithmetic_function R) = 1 :=
by rw [mul_comm, coe_moebius_mul_coe_zeta]
@[simp] lemma moebius_mul_coe_zeta : (μ * ζ : arithmetic_function ℤ) = 1 :=
by rw [← int_coe_int μ, coe_moebius_mul_coe_zeta]
@[simp] lemma coe_zeta_mul_moebius : (ζ * μ : arithmetic_function ℤ) = 1 :=
by rw [← int_coe_int μ, coe_zeta_mul_coe_moebius]
section comm_ring
variable [comm_ring R]
instance : invertible (ζ : arithmetic_function R) :=
{ inv_of := μ,
inv_of_mul_self := coe_moebius_mul_coe_zeta,
mul_inv_of_self := coe_zeta_mul_coe_moebius}
/-- A unit in `arithmetic_function R` that evaluates to `ζ`, with inverse `μ`. -/
def zeta_unit : units (arithmetic_function R) :=
⟨ζ, μ, coe_zeta_mul_coe_moebius, coe_moebius_mul_coe_zeta⟩
@[simp]
lemma coe_zeta_unit :
((zeta_unit : units (arithmetic_function R)) : arithmetic_function R) = ζ := rfl
@[simp]
lemma inv_zeta_unit :
((zeta_unit⁻¹ : units (arithmetic_function R)) : arithmetic_function R) = μ := rfl
end comm_ring
/-- Möbius inversion for functions to an `add_comm_group`. -/
theorem sum_eq_iff_sum_smul_moebius_eq
[add_comm_group R] {f g : ℕ → R} :
(∀ (n : ℕ), 0 < n → ∑ i in (n.divisors), f i = g n) ↔
∀ (n : ℕ), 0 < n → ∑ (x : ℕ × ℕ) in n.divisors_antidiagonal, μ x.fst • g x.snd = f n :=
begin
let f' : arithmetic_function R := ⟨λ x, if x = 0 then 0 else f x, if_pos rfl⟩,
let g' : arithmetic_function R := ⟨λ x, if x = 0 then 0 else g x, if_pos rfl⟩,
transitivity (ζ : arithmetic_function ℤ) • f' = g',
{ rw ext_iff,
apply forall_congr,
intro n,
cases n, { simp },
rw coe_zeta_smul_apply,
simp only [n.succ_ne_zero, forall_prop_of_true, succ_pos', if_false, zero_hom.coe_mk],
rw sum_congr rfl (λ x hx, _),
rw (if_neg (ne_of_gt (nat.pos_of_mem_divisors hx))) },
transitivity μ • g' = f',
{ split; intro h,
{ rw [← h, ← mul_smul, moebius_mul_coe_zeta, one_smul] },
{ rw [← h, ← mul_smul, coe_zeta_mul_moebius, one_smul] } },
{ rw ext_iff,
apply forall_congr,
intro n,
cases n, { simp },
simp only [n.succ_ne_zero, forall_prop_of_true, succ_pos', smul_apply,
if_false, zero_hom.coe_mk],
rw sum_congr rfl (λ x hx, _),
rw (if_neg (ne_of_gt (nat.pos_of_mem_divisors (snd_mem_divisors_of_mem_antidiagonal hx)))) },
end
/-- Möbius inversion for functions to a `comm_ring`. -/
theorem sum_eq_iff_sum_mul_moebius_eq [comm_ring R] {f g : ℕ → R} :
(∀ (n : ℕ), 0 < n → ∑ i in (n.divisors), f i = g n) ↔
∀ (n : ℕ), 0 < n → ∑ (x : ℕ × ℕ) in n.divisors_antidiagonal, (μ x.fst : R) * g x.snd = f n :=
begin
rw sum_eq_iff_sum_smul_moebius_eq,
apply forall_congr,
intro a,
apply imp_congr (iff.refl _) (eq.congr_left (sum_congr rfl (λ x hx, _))),
rw [gsmul_eq_mul],
end
/-- Möbius inversion for functions to a `comm_group`. -/
theorem prod_eq_iff_prod_pow_moebius_eq [comm_group R] {f g : ℕ → R} :
(∀ (n : ℕ), 0 < n → ∏ i in (n.divisors), f i = g n) ↔
∀ (n : ℕ), 0 < n → ∏ (x : ℕ × ℕ) in n.divisors_antidiagonal, g x.snd ^ (μ x.fst) = f n :=
@sum_eq_iff_sum_smul_moebius_eq (additive R) _ _ _
/-- Möbius inversion for functions to a `comm_group_with_zero`. -/
theorem prod_eq_iff_prod_pow_moebius_eq_of_nonzero [comm_group_with_zero R] {f g : ℕ → R}
(hf : ∀ (n : ℕ), 0 < n → f n ≠ 0) (hg : ∀ (n : ℕ), 0 < n → g n ≠ 0) :
(∀ (n : ℕ), 0 < n → ∏ i in (n.divisors), f i = g n) ↔
∀ (n : ℕ), 0 < n → ∏ (x : ℕ × ℕ) in n.divisors_antidiagonal, g x.snd ^ (μ x.fst) = f n :=
begin
refine iff.trans (iff.trans (forall_congr (λ n, _)) (@prod_eq_iff_prod_pow_moebius_eq (units R) _
(λ n, if h : 0 < n then units.mk0 (f n) (hf n h) else 1)
(λ n, if h : 0 < n then units.mk0 (g n) (hg n h) else 1))) (forall_congr (λ n, _));
refine imp_congr_right (λ hn, _),
{ dsimp,
rw [dif_pos hn, ← units.eq_iff, ← units.coe_hom_apply, monoid_hom.map_prod, units.coe_mk0,
prod_congr rfl _],
intros x hx,
rw [dif_pos (nat.pos_of_mem_divisors hx), units.coe_hom_apply, units.coe_mk0] },
{ dsimp,
rw [dif_pos hn, ← units.eq_iff, ← units.coe_hom_apply, monoid_hom.map_prod, units.coe_mk0,
prod_congr rfl _],
intros x hx,
rw [dif_pos (nat.pos_of_mem_divisors (nat.snd_mem_divisors_of_mem_antidiagonal hx)),
units.coe_hom_apply, units.coe_gpow', units.coe_mk0] }
end
end special_functions
end arithmetic_function
end nat
|
b4e1d248320d10db7a8ac0d12d9f4d954e22e55f | e0f9ba56b7fedc16ef8697f6caeef5898b435143 | /test/nth_rewrite.lean | 580b1fff1574304600e2c89ac5fd14b8124be214 | [
"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 | 3,138 | lean | /-
Copyright (c) 2018 Keeley Hoek. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Keeley Hoek, Scott Morrison
-/
import tactic.nth_rewrite
import data.vector
structure F :=
(a : ℕ)
(v : vector ℕ a)
(p : v.val = [])
example (f : F) : f.v.val = [] :=
begin
nth_rewrite 0 [f.p],
end
structure cat :=
(O : Type)
(H : O → O → Type)
(i : Π o : O, H o o)
(c : Π {X Y Z : O} (f : H X Y) (g : H Y Z), H X Z)
(li : Π {X Y : O} (f : H X Y), c (i X) f = f)
(ri : Π {X Y : O} (f : H X Y), c f (i Y) = f)
(a : Π {W X Y Z : O} (f : H W X) (g : H X Y) (h : H Y Z), c (c f g) h = c f (c g h))
open tactic
example (C : cat) (W X Y Z : C.O) (f : C.H X Y) (g : C.H W X) (h k : C.H Y Z) : C.c (C.c g f) h = C.c g (C.c f h) :=
begin
nth_rewrite 0 [C.a],
end
example (C : cat) (X Y : C.O) (f : C.H X Y) : C.c f (C.i Y) = f :=
begin
nth_rewrite 0 [C.ri],
end
-- The next two examples fail when using the kabstract backend.
axiom foo : [1] = [2]
example : [[1], [1], [1]] = [[1], [2], [1]] :=
begin
nth_rewrite_lhs 1 [foo],
end
axiom foo' : [6] = [7]
axiom bar' : [[5],[5]] = [[6],[6]]
example : [[7],[6]] = [[5],[5]] :=
begin
nth_rewrite_lhs 0 foo',
nth_rewrite_rhs 0 bar',
nth_rewrite_lhs 0 ←foo',
nth_rewrite_lhs 0 ←foo',
end
axiom wowzer : (3, 3) = (5, 2)
axiom kachow (n : ℕ) : (4, n) = (5, n)
axiom pchew (n : ℕ) : (n, 5) = (5, n)
axiom smash (n m : ℕ) : (n, m) = (1, 1)
example : [(3, 3), (5, 9), (5, 9)] = [(4, 5), (3, 6), (1, 1)] :=
begin
nth_rewrite_lhs 0 wowzer,
nth_rewrite_lhs 2 ←pchew,
nth_rewrite_rhs 0 pchew,
nth_rewrite_rhs 0 smash,
nth_rewrite_rhs 1 smash,
nth_rewrite_rhs 2 smash,
nth_rewrite_lhs 0 smash,
nth_rewrite_lhs 1 smash,
nth_rewrite_lhs 2 smash,
end
example (a b c : ℕ) : c + a + b = a + c + b :=
begin
nth_rewrite_rhs 1 add_comm,
end
-- With the `kabstract` backend, we only find one rewrite, even though there are obviously two.
-- The problem is that `(a + b) + c` matches directly, so the WHOLE THING gets replaced with a
-- metavariable, per the `kabstract` strategy. This is devastating to the search, since we cannot
-- see inside this metavariable.
-- I still think it's fixable. Because all applications have an order, I'm pretty sure we can't
-- miss any rewrites if we also look inside every thing we chunk-up into a metavariable as well.
-- In almost every case this will bring up no results (with the exception of situations like this
-- one), so there should be essentially no change in complexity.
example (x y : Prop) (h₁ : x ↔ y) (h₂ : x ↔ x ∧ x) : x ∧ x ↔ x :=
begin
nth_rewrite_rhs 1 [h₁] at h₂,
nth_rewrite_rhs 0 [← h₁] at h₂,
nth_rewrite_rhs 0 h₂,
end
example (x y : ℕ) (h₁ : x = y) (h₂ : x = x + x) : x + x = x :=
begin
nth_rewrite_rhs 1 [h₁] at h₂,
nth_rewrite_rhs 0 [← h₁] at h₂,
nth_rewrite_rhs 0 h₂,
end
example (x y z : ℕ) (h1 : x = y) (h2 : y = z) :
x + x + x + y = y + y + x + x :=
begin
nth_rewrite 2 [h1, h2], -- h2 is not used
nth_rewrite 2 [h2],
repeat { rw h1 },
repeat { rw h2 },
end
|
4cb63fb5c6d0bd3ea28333adb5f7648658378c72 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/category_theory/limits/shapes/products.lean | 3ef9b72a2f599bb7c4f3b7d62d2268bdc8577606 | [
"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 | 14,282 | lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Bhavik Mehta
-/
import category_theory.limits.has_limits
import category_theory.discrete_category
/-!
# Categorical (co)products
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file defines (co)products as special cases of (co)limits.
A product is the categorical generalization of the object `Π i, f i` where `f : ι → C`. It is a
limit cone over the diagram formed by `f`, implemented by converting `f` into a functor
`discrete ι ⥤ C`.
A coproduct is the dual concept.
## Main definitions
* a `fan` is a cone over a discrete category
* `fan.mk` constructs a fan from an indexed collection of maps
* a `pi` is a `limit (discrete.functor f)`
Each of these has a dual.
## Implementation notes
As with the other special shapes in the limits library, all the definitions here are given as
`abbreviation`s of the general statements for limits, so all the `simp` lemmas and theorems about
general limits can be used.
-/
noncomputable theory
universes w v v₂ u u₂
open category_theory
namespace category_theory.limits
variables {β : Type w}
variables {C : Type u} [category.{v} C]
-- We don't need an analogue of `pair` (for binary products), `parallel_pair` (for equalizers),
-- or `(co)span`, since we already have `discrete.functor`.
local attribute [tidy] tactic.discrete_cases
/-- A fan over `f : β → C` consists of a collection of maps from an object `P` to every `f b`. -/
abbreviation fan (f : β → C) := cone (discrete.functor f)
/-- A cofan over `f : β → C` consists of a collection of maps from every `f b` to an object `P`. -/
abbreviation cofan (f : β → C) := cocone (discrete.functor f)
/-- A fan over `f : β → C` consists of a collection of maps from an object `P` to every `f b`. -/
@[simps]
def fan.mk {f : β → C} (P : C) (p : Π b, P ⟶ f b) : fan f :=
{ X := P,
π := { app := λ X, p X.as } }
/-- A cofan over `f : β → C` consists of a collection of maps from every `f b` to an object `P`. -/
@[simps]
def cofan.mk {f : β → C} (P : C) (p : Π b, f b ⟶ P) : cofan f :=
{ X := P,
ι := { app := λ X, p X.as } }
-- FIXME dualize as needed below (and rename?)
/-- Get the `j`th map in the fan -/
def fan.proj {f : β → C} (p : fan f) (j : β) : p.X ⟶ f j := p.π.app (discrete.mk j)
@[simp] lemma fan_mk_proj {f : β → C} (P : C) (p : Π b, P ⟶ f b) (j : β) :
(fan.mk P p).proj j = p j := rfl
/-- An abbreviation for `has_limit (discrete.functor f)`. -/
abbreviation has_product (f : β → C) := has_limit (discrete.functor f)
/-- An abbreviation for `has_colimit (discrete.functor f)`. -/
abbreviation has_coproduct (f : β → C) := has_colimit (discrete.functor f)
/-- Make a fan `f` into a limit fan by providing `lift`, `fac`, and `uniq` --
just a convenience lemma to avoid having to go through `discrete` -/
@[simps] def mk_fan_limit {f : β → C} (t : fan f)
(lift : Π s : fan f, s.X ⟶ t.X)
(fac : ∀ (s : fan f) (j : β), lift s ≫ (t.proj j) = s.proj j)
(uniq : ∀ (s : fan f) (m : s.X ⟶ t.X) (w : ∀ j : β, m ≫ t.proj j = s.proj j), m = lift s) :
is_limit t :=
{ lift := lift,
fac' := λ s j, by convert fac s j.as; simp,
uniq' := λ s m w, uniq s m (λ j, w (discrete.mk j)), }
section
variables (C)
/-- An abbreviation for `has_limits_of_shape (discrete f)`. -/
abbreviation has_products_of_shape (β : Type v) := has_limits_of_shape.{v} (discrete β)
/-- An abbreviation for `has_colimits_of_shape (discrete f)`. -/
abbreviation has_coproducts_of_shape (β : Type v) := has_colimits_of_shape.{v} (discrete β)
end
/-- `pi_obj f` computes the product of a family of elements `f`.
(It is defined as an abbreviation for `limit (discrete.functor f)`,
so for most facts about `pi_obj f`, you will just use general facts about limits.) -/
abbreviation pi_obj (f : β → C) [has_product f] := limit (discrete.functor f)
/-- `sigma_obj f` computes the coproduct of a family of elements `f`.
(It is defined as an abbreviation for `colimit (discrete.functor f)`,
so for most facts about `sigma_obj f`, you will just use general facts about colimits.) -/
abbreviation sigma_obj (f : β → C) [has_coproduct f] := colimit (discrete.functor f)
notation `∏ ` f:20 := pi_obj f
notation `∐ ` f:20 := sigma_obj f
/-- The `b`-th projection from the pi object over `f` has the form `∏ f ⟶ f b`. -/
abbreviation pi.π (f : β → C) [has_product f] (b : β) : ∏ f ⟶ f b :=
limit.π (discrete.functor f) (discrete.mk b)
/-- The `b`-th inclusion into the sigma object over `f` has the form `f b ⟶ ∐ f`. -/
abbreviation sigma.ι (f : β → C) [has_coproduct f] (b : β) : f b ⟶ ∐ f :=
colimit.ι (discrete.functor f) (discrete.mk b)
/-- The fan constructed of the projections from the product is limiting. -/
def product_is_product (f : β → C) [has_product f] :
is_limit (fan.mk _ (pi.π f)) :=
is_limit.of_iso_limit (limit.is_limit (discrete.functor f)) (cones.ext (iso.refl _) (by tidy))
/-- The cofan constructed of the inclusions from the coproduct is colimiting. -/
def coproduct_is_coproduct (f : β → C) [has_coproduct f] :
is_colimit (cofan.mk _ (sigma.ι f)) :=
is_colimit.of_iso_colimit (colimit.is_colimit (discrete.functor f)) (cocones.ext (iso.refl _)
(by tidy))
/-- A collection of morphisms `P ⟶ f b` induces a morphism `P ⟶ ∏ f`. -/
abbreviation pi.lift {f : β → C} [has_product f] {P : C} (p : Π b, P ⟶ f b) : P ⟶ ∏ f :=
limit.lift _ (fan.mk P p)
/-- A collection of morphisms `f b ⟶ P` induces a morphism `∐ f ⟶ P`. -/
abbreviation sigma.desc {f : β → C} [has_coproduct f] {P : C} (p : Π b, f b ⟶ P) : ∐ f ⟶ P :=
colimit.desc _ (cofan.mk P p)
/--
Construct a morphism between categorical products (indexed by the same type)
from a family of morphisms between the factors.
-/
abbreviation pi.map {f g : β → C} [has_product f] [has_product g]
(p : Π b, f b ⟶ g b) : ∏ f ⟶ ∏ g :=
lim_map (discrete.nat_trans (λ X, p X.as))
instance pi.map_mono {f g : β → C} [has_product f] [has_product g]
(p : Π b, f b ⟶ g b) [Π i, mono (p i)] : mono $ pi.map p :=
@@limits.lim_map_mono _ _ _ _ _ (by { dsimp, apply_instance })
/--
Construct an isomorphism between categorical products (indexed by the same type)
from a family of isomorphisms between the factors.
-/
abbreviation pi.map_iso {f g : β → C} [has_products_of_shape β C]
(p : Π b, f b ≅ g b) : ∏ f ≅ ∏ g :=
lim.map_iso (discrete.nat_iso (λ X, p X.as))
/--
Construct a morphism between categorical coproducts (indexed by the same type)
from a family of morphisms between the factors.
-/
abbreviation sigma.map {f g : β → C} [has_coproduct f] [has_coproduct g]
(p : Π b, f b ⟶ g b) : ∐ f ⟶ ∐ g :=
colim_map (discrete.nat_trans (λ X, p X.as))
instance sigma.map_epi {f g : β → C} [has_coproduct f] [has_coproduct g]
(p : Π b, f b ⟶ g b) [Π i, epi (p i)] : epi $ sigma.map p :=
@@limits.colim_map_epi _ _ _ _ _ (by { dsimp, apply_instance })
/--
Construct an isomorphism between categorical coproducts (indexed by the same type)
from a family of isomorphisms between the factors.
-/
abbreviation sigma.map_iso {f g : β → C} [has_coproducts_of_shape β C]
(p : Π b, f b ≅ g b) : ∐ f ≅ ∐ g :=
colim.map_iso (discrete.nat_iso (λ X, p X.as))
section comparison
variables {D : Type u₂} [category.{v₂} D] (G : C ⥤ D)
variables (f : β → C)
/-- The comparison morphism for the product of `f`. This is an iso iff `G` preserves the product
of `f`, see `preserves_product.of_iso_comparison`. -/
def pi_comparison [has_product f] [has_product (λ b, G.obj (f b))] :
G.obj (∏ f) ⟶ ∏ (λ b, G.obj (f b)) :=
pi.lift (λ b, G.map (pi.π f b))
@[simp, reassoc]
lemma pi_comparison_comp_π [has_product f] [has_product (λ b, G.obj (f b))] (b : β) :
pi_comparison G f ≫ pi.π _ b = G.map (pi.π f b) :=
limit.lift_π _ (discrete.mk b)
@[simp, reassoc]
lemma map_lift_pi_comparison [has_product f] [has_product (λ b, G.obj (f b))]
(P : C) (g : Π j, P ⟶ f j) :
G.map (pi.lift g) ≫ pi_comparison G f = pi.lift (λ j, G.map (g j)) :=
by { ext, discrete_cases, simp [← G.map_comp] }
/-- The comparison morphism for the coproduct of `f`. This is an iso iff `G` preserves the coproduct
of `f`, see `preserves_coproduct.of_iso_comparison`. -/
def sigma_comparison [has_coproduct f] [has_coproduct (λ b, G.obj (f b))] :
∐ (λ b, G.obj (f b)) ⟶ G.obj (∐ f) :=
sigma.desc (λ b, G.map (sigma.ι f b))
@[simp, reassoc]
lemma ι_comp_sigma_comparison [has_coproduct f] [has_coproduct (λ b, G.obj (f b))] (b : β) :
sigma.ι _ b ≫ sigma_comparison G f = G.map (sigma.ι f b) :=
colimit.ι_desc _ (discrete.mk b)
@[simp, reassoc]
lemma sigma_comparison_map_desc [has_coproduct f] [has_coproduct (λ b, G.obj (f b))]
(P : C) (g : Π j, f j ⟶ P) :
sigma_comparison G f ≫ G.map (sigma.desc g) = sigma.desc (λ j, G.map (g j)) :=
by { ext, discrete_cases, simp [← G.map_comp] }
end comparison
variables (C)
/-- An abbreviation for `Π J, has_limits_of_shape (discrete J) C` -/
abbreviation has_products := Π (J : Type w), has_limits_of_shape (discrete J) C
/-- An abbreviation for `Π J, has_colimits_of_shape (discrete J) C` -/
abbreviation has_coproducts := Π (J : Type w), has_colimits_of_shape (discrete J) C
variable {C}
lemma has_smallest_products_of_has_products [has_products.{w} C] : has_products.{0} C :=
λ J, has_limits_of_shape_of_equivalence
(discrete.equivalence equiv.ulift : discrete (ulift.{w} J) ≌ _)
lemma has_smallest_coproducts_of_has_coproducts [has_coproducts.{w} C] : has_coproducts.{0} C :=
λ J, has_colimits_of_shape_of_equivalence
(discrete.equivalence equiv.ulift : discrete (ulift.{w} J) ≌ _)
lemma has_products_of_limit_fans (lf : ∀ {J : Type w} (f : J → C), fan f)
(lf_is_limit : ∀ {J : Type w} (f : J → C), is_limit (lf f)) : has_products.{w} C :=
λ (J : Type w), { has_limit := λ F, has_limit.mk
⟨(cones.postcompose discrete.nat_iso_functor.inv).obj (lf (λ j, F.obj ⟨j⟩)),
(is_limit.postcompose_inv_equiv _ _).symm (lf_is_limit _)⟩ }
/-!
(Co)products over a type with a unique term.
-/
section unique
variables {C} [unique β] (f : β → C)
/-- The limit cone for the product over an index type with exactly one term. -/
@[simps]
def limit_cone_of_unique : limit_cone (discrete.functor f) :=
{ cone :=
{ X := f default,
π := { app := λ j, eq_to_hom (by { dsimp, congr, }), }, },
is_limit :=
{ lift := λ s, s.π.app default,
fac' := λ s j, begin
have w := (s.π.naturality (eq_to_hom (unique.default_eq _))).symm,
dsimp at w,
simpa [eq_to_hom_map] using w,
end,
uniq' := λ s m w, begin
specialize w default,
dsimp at w,
simpa using w,
end, }, }
@[priority 100] instance has_product_unique : has_product f :=
has_limit.mk (limit_cone_of_unique f)
/-- A product over a index type with exactly one term is just the object over that term. -/
@[simps]
def product_unique_iso : ∏ f ≅ f default :=
is_limit.cone_point_unique_up_to_iso (limit.is_limit _) (limit_cone_of_unique f).is_limit
/-- The colimit cocone for the coproduct over an index type with exactly one term. -/
@[simps]
def colimit_cocone_of_unique : colimit_cocone (discrete.functor f) :=
{ cocone :=
{ X := f default,
ι := { app := λ j, eq_to_hom (by { discrete_cases, dsimp, congr, }), }, },
is_colimit :=
{ desc := λ s, s.ι.app default,
fac' := λ s j, begin
have w := (s.ι.naturality (eq_to_hom (unique.eq_default _))),
dsimp at w,
simpa [eq_to_hom_map] using w,
end,
uniq' := λ s m w, begin
specialize w default,
dsimp at w,
simpa using w,
end, }, }
@[priority 100] instance has_coproduct_unique : has_coproduct f :=
has_colimit.mk (colimit_cocone_of_unique f)
/-- A coproduct over a index type with exactly one term is just the object over that term. -/
@[simps]
def coproduct_unique_iso : ∐ f ≅ f default :=
is_colimit.cocone_point_unique_up_to_iso (colimit.is_colimit _)
(colimit_cocone_of_unique f).is_colimit
end unique
section reindex
variables {C} {γ : Type v} (ε : β ≃ γ) (f : γ → C)
section
variables [has_product f] [has_product (f ∘ ε)]
/-- Reindex a categorical product via an equivalence of the index types. -/
def pi.reindex : pi_obj (f ∘ ε) ≅ pi_obj f :=
has_limit.iso_of_equivalence (discrete.equivalence ε) (discrete.nat_iso (λ i, iso.refl _))
@[simp, reassoc]
lemma pi.reindex_hom_π (b : β) : (pi.reindex ε f).hom ≫ pi.π f (ε b) = pi.π (f ∘ ε) b :=
begin
dsimp [pi.reindex],
simp only [has_limit.iso_of_equivalence_hom_π, discrete.nat_iso_inv_app,
equivalence.equivalence_mk'_counit, discrete.equivalence_counit_iso, discrete.nat_iso_hom_app,
eq_to_iso.hom, eq_to_hom_map],
dsimp,
simpa [eq_to_hom_map] using
limit.w (discrete.functor (f ∘ ε)) (discrete.eq_to_hom' (ε.symm_apply_apply b)),
end
@[simp, reassoc]
lemma pi.reindex_inv_π (b : β) : (pi.reindex ε f).inv ≫ pi.π (f ∘ ε) b = pi.π f (ε b) :=
by simp [iso.inv_comp_eq]
end
section
variables [has_coproduct f] [has_coproduct (f ∘ ε)]
/-- Reindex a categorical coproduct via an equivalence of the index types. -/
def sigma.reindex : sigma_obj (f ∘ ε) ≅ sigma_obj f :=
has_colimit.iso_of_equivalence (discrete.equivalence ε) (discrete.nat_iso (λ i, iso.refl _))
@[simp, reassoc]
lemma sigma.ι_reindex_hom (b : β) : sigma.ι (f ∘ ε) b ≫ (sigma.reindex ε f).hom = sigma.ι f (ε b) :=
begin
dsimp [sigma.reindex],
simp only [has_colimit.iso_of_equivalence_hom_π, equivalence.equivalence_mk'_unit,
discrete.equivalence_unit_iso, discrete.nat_iso_hom_app, eq_to_iso.hom, eq_to_hom_map,
discrete.nat_iso_inv_app],
dsimp,
simp [eq_to_hom_map,
←colimit.w (discrete.functor f) (discrete.eq_to_hom' (ε.apply_symm_apply (ε b)))],
end
@[simp, reassoc]
lemma sigma.ι_reindex_inv (b : β) : sigma.ι f (ε b) ≫ (sigma.reindex ε f).inv = sigma.ι (f ∘ ε) b :=
by simp [iso.comp_inv_eq]
end
end reindex
end category_theory.limits
|
05a5198a794880a3a6f2257fea8834d52ca14feb | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/data/polynomial/monomial.lean | 4abc301b80d97042d22ea1df47980f5df9b0fce2 | [
"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,608 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker
-/
import data.polynomial.coeff
/-!
# Univariate monomials
Preparatory lemmas for degree_basic.
-/
noncomputable theory
namespace polynomial
universes u
variables {R : Type u} {a b : R} {m n : ℕ}
variables [semiring R] {p q r : polynomial R}
lemma monomial_one_eq_iff [nontrivial R] {i j : ℕ} :
(monomial i 1 : polynomial R) = monomial j 1 ↔ i = j :=
by simp [monomial, monomial_fun, finsupp.single_eq_single_iff]
lemma smul_eq_C_mul (a : R) : a • p = C a * p := by simp [ext_iff]
instance [nontrivial R] : infinite (polynomial R) :=
infinite.of_injective (λ i, monomial i 1) $
λ m n h, by simpa [monomial_one_eq_iff] using h
lemma card_support_le_one_iff_monomial {f : polynomial R} :
finset.card f.support ≤ 1 ↔ ∃ n a, f = monomial n a :=
begin
split,
{ assume H,
rw finset.card_le_one_iff_subset_singleton at H,
rcases H with ⟨n, hn⟩,
refine ⟨n, f.coeff n, _⟩,
ext i,
by_cases hi : i = n,
{ simp [hi, coeff_monomial] },
{ have : f.coeff i = 0,
{ rw ← not_mem_support_iff,
exact λ hi', hi (finset.mem_singleton.1 (hn hi')) },
simp [this, ne.symm hi, coeff_monomial] } },
{ rintros ⟨n, a, rfl⟩,
rw ← finset.card_singleton n,
apply finset.card_le_of_subset,
exact support_monomial' _ _ }
end
lemma ring_hom_ext {S} [semiring S] {f g : polynomial R →+* S}
(h₁ : ∀ a, f (C a) = g (C a)) (h₂ : f X = g X) : f = g :=
begin
set f' := f.comp (to_finsupp_iso R).symm.to_ring_hom with hf',
set g' := g.comp (to_finsupp_iso R).symm.to_ring_hom with hg',
have A : f' = g',
{ ext,
{ simp [h₁, ring_equiv.to_ring_hom_eq_coe] },
{ simpa [ring_equiv.to_ring_hom_eq_coe] using h₂, } },
have B : f = f'.comp (to_finsupp_iso R),
by { rw [hf', ring_hom.comp_assoc], ext x, simp only [ring_equiv.to_ring_hom_eq_coe,
ring_equiv.symm_apply_apply, function.comp_app, ring_hom.coe_comp,
ring_equiv.coe_to_ring_hom] },
have C : g = g'.comp (to_finsupp_iso R),
by { rw [hg', ring_hom.comp_assoc], ext x, simp only [ring_equiv.to_ring_hom_eq_coe,
ring_equiv.symm_apply_apply, function.comp_app, ring_hom.coe_comp,
ring_equiv.coe_to_ring_hom] },
rw [B, C, A]
end
@[ext] lemma ring_hom_ext' {S} [semiring S] {f g : polynomial R →+* S}
(h₁ : f.comp C = g.comp C) (h₂ : f X = g X) : f = g :=
ring_hom_ext (ring_hom.congr_fun h₁) h₂
end polynomial
|
c044d555168af939ac7b002501c5940c2813b140 | aa2345b30d710f7e75f13157a35845ee6d48c017 | /data/real/irrational.lean | 8bf845e119d93eb2ba0cacbba00abad0159613b9 | [
"Apache-2.0"
] | permissive | CohenCyril/mathlib | 5241b20a3fd0ac0133e48e618a5fb7761ca7dcbe | a12d5a192f5923016752f638d19fc1a51610f163 | refs/heads/master | 1,586,031,957,957 | 1,541,432,824,000 | 1,541,432,824,000 | 156,246,337 | 0 | 0 | Apache-2.0 | 1,541,434,514,000 | 1,541,434,513,000 | null | UTF-8 | Lean | false | false | 4,447 | 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
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_padic_val {x : ℝ} (n : ℕ) (m : ℤ) (p : ℕ)
[hp : nat.prime p] (hxr : x ^ n = m) (hv : padic_val p m % 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,
rw [hxr, padic_val.one hp.gt_one, nat.zero_mod] at hv,
exact (hv rfl).elim },
rcases decidable.em (m = 0) with rfl | hm,
{ rw [padic_val.zero, nat.zero_mod] at hv,
exact (hv rfl).elim },
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 },
rw [padic_val.pow p this, nat.mul_mod_right] at hv, exact hv rfl
end
theorem irr_sqrt_of_padic_val_odd (m : ℤ) (hm : m ≥ 0)
(p : ℕ) [hp : nat.prime p] (Hpv : padic_val p m % 2 = 1) :
irrational (sqrt m) :=
irr_nrt_of_n_not_dvd_padic_val 2 m p
(sqr_sqrt (int.cast_nonneg.2 hm))
(by rw Hpv; exact one_ne_zero)
theorem irr_sqrt_of_prime (p : ℕ) (hp : nat.prime p) : irrational (sqrt p) :=
irr_sqrt_of_padic_val_odd p (int.coe_nat_nonneg p) p $
by rw padic_val.padic_val_self hp.gt_one; refl
theorem irr_sqrt_two : irrational (sqrt 2) := 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]⟩⟩
|
44d1f91c7853e443e8fb4495380ad62e2b1ef715 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/topology/category/Profinite/cofiltered_limit.lean | 0e36712aa5c79e435716c3d8011fe70738446630 | [
"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,592 | lean | /-
Copyright (c) 2021 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz
-/
import topology.category.Profinite.basic
import topology.locally_constant.basic
import topology.discrete_quotient
import topology.category.Top.limits.cofiltered
import topology.category.Top.limits.konig
/-!
# Cofiltered limits of profinite sets.
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file contains some theorems about cofiltered limits of profinite sets.
## Main Results
- `exists_clopen_of_cofiltered` shows that any clopen set in a cofiltered limit of profinite
sets is the pullback of a clopen set from one of the factors in the limit.
- `exists_locally_constant` shows that any locally constant function from a cofiltered limit
of profinite sets factors through one of the components.
-/
namespace Profinite
open_locale classical
open category_theory
open category_theory.limits
universe u
variables {J : Type u} [small_category J] [is_cofiltered J]
{F : J ⥤ Profinite.{u}} (C : cone F) (hC : is_limit C)
include hC
/--
If `X` is a cofiltered limit of profinite sets, then any clopen subset of `X` arises from
a clopen set in one of the terms in the limit.
-/
theorem exists_clopen_of_cofiltered {U : set C.X} (hU : is_clopen U) :
∃ (j : J) (V : set (F.obj j)) (hV : is_clopen V), U = C.π.app j ⁻¹' V :=
begin
-- First, we have the topological basis of the cofiltered limit obtained by pulling back
-- clopen sets from the factors in the limit. By continuity, all such sets are again clopen.
have hB := Top.is_topological_basis_cofiltered_limit.{u}
(F ⋙ Profinite.to_Top)
(Profinite.to_Top.map_cone C)
(is_limit_of_preserves _ hC)
(λ j, {W | is_clopen W})
_ (λ i, is_clopen_univ) (λ i U1 U2 hU1 hU2, hU1.inter hU2) _,
rotate,
{ intros i,
change topological_space.is_topological_basis
{W : set (F.obj i) | is_clopen W},
apply is_topological_basis_clopen },
{ rintros i j f V (hV : is_clopen _),
refine ⟨hV.1.preimage _, hV.2.preimage _⟩;
continuity },
-- Using this, since `U` is open, we can write `U` as a union of clopen sets all of which
-- are preimages of clopens from the factors in the limit.
obtain ⟨S,hS,h⟩ := hB.open_eq_sUnion hU.1,
clear hB,
let j : S → J := λ s, (hS s.2).some,
let V : Π (s : S), set (F.obj (j s)) := λ s, (hS s.2).some_spec.some,
have hV : ∀ (s : S), is_clopen (V s) ∧ s.1 = C.π.app (j s) ⁻¹' (V s) :=
λ s, (hS s.2).some_spec.some_spec,
-- Since `U` is also closed, hence compact, it is covered by finitely many of the
-- clopens constructed in the previous step.
have := hU.2.is_compact.elim_finite_subcover (λ s : S, C.π.app (j s) ⁻¹' (V s)) _ _,
rotate,
{ intros s,
refine (hV s).1.1.preimage _,
continuity },
{ dsimp only,
rw h,
rintro x ⟨T,hT,hx⟩,
refine ⟨_,⟨⟨T,hT⟩,rfl⟩,_⟩,
dsimp only,
rwa ← (hV ⟨T,hT⟩).2 },
-- We thus obtain a finite set `G : finset J` and a clopen set of `F.obj j` for each
-- `j ∈ G` such that `U` is the union of the preimages of these clopen sets.
obtain ⟨G,hG⟩ := this,
-- Since `J` is cofiltered, we can find a single `j0` dominating all the `j ∈ G`.
-- Pulling back all of the sets from the previous step to `F.obj j0` and taking a union,
-- we obtain a clopen set in `F.obj j0` which works.
obtain ⟨j0,hj0⟩ := is_cofiltered.inf_objs_exists (G.image j),
let f : Π (s : S) (hs : s ∈ G), j0 ⟶ j s :=
λ s hs, (hj0 (finset.mem_image.mpr ⟨s,hs,rfl⟩)).some,
let W : S → set (F.obj j0) := λ s,
if hs : s ∈ G then F.map (f s hs) ⁻¹' (V s) else set.univ,
-- Conclude, using the `j0` and the clopen set of `F.obj j0` obtained above.
refine ⟨j0, ⋃ (s : S) (hs : s ∈ G), W s, _, _⟩,
{ apply is_clopen_bUnion_finset,
intros s hs,
dsimp only [W],
rw dif_pos hs,
refine ⟨(hV s).1.1.preimage _, (hV s).1.2.preimage _⟩;
continuity },
{ ext x,
split,
{ intro hx,
simp_rw [set.preimage_Union, set.mem_Union],
obtain ⟨_, ⟨s,rfl⟩, _, ⟨hs, rfl⟩, hh⟩ := hG hx,
refine ⟨s, hs, _⟩,
dsimp only [W] at hh ⊢,
rwa [dif_pos hs, ← set.preimage_comp, ← Profinite.coe_comp, C.w] },
{ intro hx,
simp_rw [set.preimage_Union, set.mem_Union] at hx,
obtain ⟨s,hs,hx⟩ := hx,
rw h,
refine ⟨s.1,s.2,_⟩,
rw (hV s).2,
dsimp only [W] at hx,
rwa [dif_pos hs, ← set.preimage_comp, ← Profinite.coe_comp, C.w] at hx } }
end
lemma exists_locally_constant_fin_two (f : locally_constant C.X (fin 2)) :
∃ (j : J) (g : locally_constant (F.obj j) (fin 2)), f = g.comap (C.π.app _) :=
begin
let U := f ⁻¹' {0},
have hU : is_clopen U := f.is_locally_constant.is_clopen_fiber _,
obtain ⟨j,V,hV,h⟩ := exists_clopen_of_cofiltered C hC hU,
use [j, locally_constant.of_clopen hV],
apply locally_constant.locally_constant_eq_of_fiber_zero_eq,
rw locally_constant.coe_comap _ _ (C.π.app j).continuous,
conv_rhs { rw set.preimage_comp },
rw [locally_constant.of_clopen_fiber_zero hV, ← h],
end
theorem exists_locally_constant_finite_aux {α : Type*} [finite α] (f : locally_constant C.X α) :
∃ (j : J) (g : locally_constant (F.obj j) (α → fin 2)),
f.map (λ a b, if a = b then (0 : fin 2) else 1) = g.comap (C.π.app _) :=
begin
casesI nonempty_fintype α,
let ι : α → α → fin 2 := λ x y, if x = y then 0 else 1,
let ff := (f.map ι).flip,
have hff := λ (a : α), exists_locally_constant_fin_two _ hC (ff a),
choose j g h using hff,
let G : finset J := finset.univ.image j,
obtain ⟨j0,hj0⟩ := is_cofiltered.inf_objs_exists G,
have hj : ∀ a, j a ∈ G,
{ intros a,
simp [G] },
let fs : Π (a : α), j0 ⟶ j a := λ a, (hj0 (hj a)).some,
let gg : α → locally_constant (F.obj j0) (fin 2) := λ a, (g a).comap (F.map (fs _)),
let ggg := locally_constant.unflip gg,
refine ⟨j0, ggg, _⟩,
have : f.map ι = locally_constant.unflip (f.map ι).flip, by simp,
rw this, clear this,
have : locally_constant.comap (C.π.app j0) ggg =
locally_constant.unflip (locally_constant.comap (C.π.app j0) ggg).flip, by simp,
rw this, clear this,
congr' 1,
ext1 a,
change ff a = _,
rw h,
dsimp [ggg, gg],
ext1,
repeat
{ rw locally_constant.coe_comap,
dsimp [locally_constant.flip, locally_constant.unflip] },
{ congr' 1,
change _ = ((C.π.app j0) ≫ (F.map (fs a))) x,
rw C.w },
all_goals { continuity },
end
theorem exists_locally_constant_finite_nonempty {α : Type*} [finite α] [nonempty α]
(f : locally_constant C.X α) :
∃ (j : J) (g : locally_constant (F.obj j) α), f = g.comap (C.π.app _) :=
begin
inhabit α,
obtain ⟨j,gg,h⟩ := exists_locally_constant_finite_aux _ hC f,
let ι : α → α → fin 2 := λ a b, if a = b then 0 else 1,
let σ : (α → fin 2) → α := λ f, if h : ∃ (a : α), ι a = f then h.some else arbitrary _,
refine ⟨j, gg.map σ, _⟩,
ext,
rw locally_constant.coe_comap _ _ (C.π.app j).continuous,
dsimp [σ],
have h1 : ι (f x) = gg (C.π.app j x),
{ change f.map (λ a b, if a = b then (0 : fin 2) else 1) x = _,
rw [h, locally_constant.coe_comap _ _ (C.π.app j).continuous] },
have h2 : ∃ a : α, ι a = gg (C.π.app j x) := ⟨f x, h1⟩,
rw dif_pos h2,
apply_fun ι,
{ rw h2.some_spec,
exact h1 },
{ intros a b hh,
apply_fun (λ e, e a) at hh,
dsimp [ι] at hh,
rw if_pos rfl at hh,
split_ifs at hh with hh1 hh1,
{ exact hh1.symm },
{ exact false.elim (bot_ne_top hh) } }
end
/-- Any locally constant function from a cofiltered limit of profinite sets factors through
one of the components. -/
theorem exists_locally_constant {α : Type*} (f : locally_constant C.X α) :
∃ (j : J) (g : locally_constant (F.obj j) α), f = g.comap (C.π.app _) :=
begin
let S := f.discrete_quotient,
let ff : S → α := f.lift,
casesI is_empty_or_nonempty S,
{ suffices : ∃ j, is_empty (F.obj j),
{ refine this.imp (λ j hj, _),
refine ⟨⟨hj.elim, λ A, _⟩, _⟩,
{ convert is_open_empty,
exact @set.eq_empty_of_is_empty _ hj _ },
{ ext x,
exact hj.elim' (C.π.app j x) } },
simp only [← not_nonempty_iff, ← not_forall],
intros h,
haveI : ∀ j : J, nonempty ((F ⋙ Profinite.to_Top).obj j) := h,
haveI : ∀ j : J, t2_space ((F ⋙ Profinite.to_Top).obj j) := λ j,
(infer_instance : t2_space (F.obj j)),
haveI : ∀ j : J, compact_space ((F ⋙ Profinite.to_Top).obj j) := λ j,
(infer_instance : compact_space (F.obj j)),
have cond := Top.nonempty_limit_cone_of_compact_t2_cofiltered_system
(F ⋙ Profinite.to_Top),
suffices : nonempty C.X, from is_empty.false (S.proj this.some),
let D := Profinite.to_Top.map_cone C,
have hD : is_limit D := is_limit_of_preserves Profinite.to_Top hC,
have CD := (hD.cone_point_unique_up_to_iso (Top.limit_cone_is_limit.{u} _)).inv,
exact cond.map CD },
{ let f' : locally_constant C.X S := ⟨S.proj, S.proj_is_locally_constant⟩,
obtain ⟨j, g', hj⟩ := exists_locally_constant_finite_nonempty _ hC f',
refine ⟨j, ⟨ff ∘ g', g'.is_locally_constant.comp _⟩,_⟩,
ext1 t,
apply_fun (λ e, e t) at hj,
rw locally_constant.coe_comap _ _ (C.π.app j).continuous at hj ⊢,
dsimp at hj ⊢,
rw ← hj,
refl },
end
end Profinite
|
36fbcf30f77550d4938a4a73254126f068363ed0 | 6dc0c8ce7a76229dd81e73ed4474f15f88a9e294 | /tests/lean/run/KyleAlg.lean | c09630bf2aa6dc82426a2089f8ecf1d18e14f236 | [
"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 | 8,407 | lean | import Lean
/- from core:
class OfNat (α : Type u) (n : Nat) where
ofNat : α
class Mul (α : Type u) where
mul : α → α → α
class Add (α : Type u) where
add : α → α → α
-/
class Inv (α : Type u) where
inv : α → α
postfix:max "⁻¹" => Inv.inv
class One (α : Type u) where
one : α
export One (one)
instance [One α] : OfNat α (natLit! 1) where
ofNat := one
class Zero (α : Type u) where
zero : α
export Zero (zero)
instance [Zero α] : OfNat α (natLit! 0) where
ofNat := zero
class MulComm (α : Type u) [Mul α] : Prop where
mulComm : {a b : α} → a * b = b * a
export MulComm (mulComm)
class MulAssoc (α : Type u) [Mul α] : Prop where
mulAssoc : {a b c : α} → a * b * c = a * (b * c)
export MulAssoc (mulAssoc)
class OneUnit (α : Type u) [Mul α] [One α] : Prop where
oneMul : {a : α} → 1 * a = a
mulOne : {a : α} → a * 1 = a
export OneUnit (oneMul mulOne)
class AddComm (α : Type u) [Add α] : Prop where
addComm : {a b : α} → a + b = b + a
export AddComm (addComm)
class AddAssoc (α : Type u) [Add α] : Prop where
addAssoc : {a b c : α} → a + b + c = a + (b + c)
export AddAssoc (addAssoc)
class ZeroUnit (α : Type u) [Add α] [Zero α] : Prop where
zeroAdd : {a : α} → 0 + a = a
addZero : {a : α} → a + 0 = a
export ZeroUnit (zeroAdd addZero)
class InvMul (α : Type u) [Mul α] [One α] [Inv α] : Prop where
invMul : {a : α} → a⁻¹ * a = 1
export InvMul (invMul)
class NegAdd (α : Type u) [Add α] [Zero α] [Neg α] : Prop where
negAdd : {a : α} → -a + a = 0
export NegAdd (negAdd)
class ZeroMul (α : Type u) [Mul α] [Zero α] : Prop where
zeroMul : {a : α} → 0 * a = 0
export ZeroMul (zeroMul)
class Distrib (α : Type u) [Add α] [Mul α] : Prop where
leftDistrib : {a b c : α} → a * (b + c) = a * b + a * c
rightDistrib : {a b c : α} → (a + b) * c = a * c + b * c
export Distrib (leftDistrib rightDistrib)
class Domain (α : Type u) [Mul α] [Zero α] : Prop where
eqZeroOrEqZeroOfMulEqZero : {a b : α} → a * b = 0 → a = 0 ∨ b = 0
export Domain (eqZeroOrEqZeroOfMulEqZero)
class Semigroup (α : Type u) extends Mul α, MulAssoc α
attribute [instance] Semigroup.mk
class AddSemigroup (α : Type u) extends Add α, AddAssoc α
attribute [instance] AddSemigroup.mk
class Monoid (α : Type u) extends Semigroup α, One α, OneUnit α
attribute [instance] Monoid.mk
class AddMonoid (α : Type u) extends AddSemigroup α, Zero α, ZeroUnit α
attribute [instance] AddMonoid.mk
class CommSemigroup (α : Type u) extends Semigroup α, MulComm α
attribute [instance] CommSemigroup.mk
class CommMonoid (α : Type u) extends Monoid α, MulComm α
attribute [instance] CommMonoid.mk
class Group (α : Type u) extends Monoid α, Inv α, InvMul α
attribute [instance] Group.mk
class AddGroup (α : Type u) extends AddMonoid α, Neg α, NegAdd α
attribute [instance] AddGroup.mk
class Semiring (α : Type u) extends AddMonoid α, Monoid α, AddComm α, ZeroMul α, Distrib α
attribute [instance] Semiring.mk
class Ring (α : Type u) extends AddGroup α, Monoid α, AddComm α, Distrib α
attribute [instance] Ring.mk
class CommRing (α : Type u) extends Ring α, MulComm α
attribute [instance] CommRing.mk
class IntegralDomain (α : Type u) extends CommRing α, Domain α
attribute [instance] IntegralDomain.mk
section test1
variable (α : Type u) [h : CommMonoid α]
example : Semigroup α := inferInstance
example : Monoid α := inferInstance
example : CommSemigroup α := inferInstance
end test1
section test2
variable (β : Type u) [CommSemigroup β] [One β] [OneUnit β]
example : Monoid β := inferInstance
example : CommMonoid β := inferInstance
example : Semigroup β := inferInstance
end test2
section test3
variable (β : Type u) [Mul β] [One β] [MulAssoc β] [OneUnit β]
example : Monoid β := inferInstance
example : Semigroup β := inferInstance
end test3
theorem negZero [AddGroup α] : -(0 : α) = 0 := by
rw [←addZero (a := -(0 : α)), negAdd]
theorem subZero [AddGroup α] {a : α} : a + -(0 : α) = a := by
rw [←addZero (a := a), addAssoc, negZero, addZero]
theorem negNeg [AddGroup α] {a : α} : -(-a) = a := by {
rw ←addZero (a := - -a);
rw ←negAdd (a := a);
rw ←addAssoc;
rw negAdd;
rw zeroAdd;
}
theorem addNeg [AddGroup α] {a : α} : a + -a = 0 := by {
have h : - -a + -a = 0 := by { rw negAdd };
rw negNeg at h;
exact h
}
theorem addIdemIffZero [AddGroup α] {a : α} : a + a = a ↔ a = 0 := by
apply Iff.intro
focus
intro h
have h' := congrArg (λ x => x + -a) h
simp at h'
rw [addAssoc, addNeg, addZero] at h'
exact h'
focus
intro h
subst a
rw addZero
instance [Ring α] : ZeroMul α := by {
apply ZeroMul.mk;
intro a;
have h : 0 * a + 0 * a = 0 * a := by { rw [←rightDistrib, addZero] };
rw addIdemIffZero (a := 0 * a) at h;
rw h;
}
example [Ring α] : Semiring α := inferInstance
section prod
instance [Mul α] [Mul β] : Mul (α × β) where
mul p p' := (p.1 * p'.1, p.2 * p'.2)
instance [Inv α] [Inv β] : Inv (α × β) where
inv p := (p.1⁻¹, p.2⁻¹)
instance [One α] [One β] : One (α × β) where
one := (1, 1)
theorem Product.ext : {p q : α × β} → p.1 = q.1 → p.2 = q.2 → p = q
| (a, b), (c, d) => by simp; intro h; subst a; intro h; subst b; rfl
instance [Semigroup α] [Semigroup β] : Semigroup (α × β) where
mulAssoc := by
apply Product.ext
apply mulAssoc
apply mulAssoc
instance [Monoid α] [Monoid β] : Monoid (α × β) where
oneMul := by
apply Product.ext
apply oneMul
apply oneMul
mulOne := by
apply Product.ext
apply mulOne
apply mulOne
instance [Group α] [Group β] : Group (α × β) where
invMul := by
apply Product.ext
apply invMul
apply invMul
end prod
def test1 {G : Type _} [Group G]: Group (G) := inferInstance
def test2 {G : Type _} [Group G]: Group (G × G) := inferInstance
def test3 {G : Type _} [Group G]: Group (G × G × G) := inferInstance
def test4 {G : Type _} [Group G]: Group (G × G × G × G) := inferInstance
def test5 {G : Type _} [Group G]: Group (G × G × G × G × G) := inferInstance
def test6 {G : Type _} [Group G]: Group (G × G × G × G × G × G) := inferInstance
def test7 {G : Type _} [Group G]: Group (G × G × G × G × G × G × G) := inferInstance
def test8 {G : Type _} [Group G]: Group (G × G × G × G × G × G × G × G) := inferInstance
namespace Lean
unsafe def Expr.dagSizeUnsafe (e : Expr) : IO Nat := do
let (_, s) ← visit e |>. run ({}, 0)
return s.2
where
visit (e : Expr) : StateRefT (Std.HashSet USize × Nat) IO Unit := do
let addr := ptrAddrUnsafe e
unless (← get).1.contains addr do
modify fun (s, c) => (s.insert addr, c+1)
match e with
| Expr.proj _ _ s _ => visit s
| Expr.forallE _ d b _ => visit d; visit b
| Expr.lam _ d b _ => visit d; visit b
| Expr.letE _ t v b _ => visit t; visit v; visit b
| Expr.app f a _ => visit f; visit a
| Expr.mdata _ b _ => visit b
| _ => return ()
@[implementedBy Expr.dagSizeUnsafe]
constant Expr.dagSize (e : Expr) : IO Nat
def getDeclTypeValueDagSize (declName : Name) : CoreM Nat := do
let info ← getConstInfo declName
let n ← info.type.dagSize
match info.value? with
| none => return n
| some v => return n + (← v.dagSize)
#eval getDeclTypeValueDagSize `test2
#eval getDeclTypeValueDagSize `test3
#eval getDeclTypeValueDagSize `test4
#eval getDeclTypeValueDagSize `test5
#eval getDeclTypeValueDagSize `test6
#eval getDeclTypeValueDagSize `test7
#eval getDeclTypeValueDagSize `test8
def reduceAndGetDagSize (declName : Name) : MetaM Nat := do
let c := mkConst declName [levelOne]
let e ← Meta.reduce c
trace[Meta.debug]! "{e}"
e.dagSize
#eval reduceAndGetDagSize `test1
#eval reduceAndGetDagSize `test2
#eval reduceAndGetDagSize `test3
#eval reduceAndGetDagSize `test4
#eval reduceAndGetDagSize `test5
#eval reduceAndGetDagSize `test6
#eval reduceAndGetDagSize `test7
-- Use `set_option` to trace the reduced term
set_option pp.all true in
set_option trace.Meta.debug true in
#eval reduceAndGetDagSize `test8
|
cbdfe2289c684a1db11663e30190215edbbd4de0 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/algebra/homology/homotopy_category.lean | 373657a40e7572c2687b5125316741232a2f4394 | [
"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 | 7,618 | lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import algebra.homology.homotopy
import category_theory.quotient
/-!
# The homotopy category
`homotopy_category V c` gives the category of chain complexes of shape `c` in `V`,
with chain maps identified when they are homotopic.
-/
universes v u
open_locale classical
noncomputable theory
open category_theory category_theory.limits homological_complex
variables {ι : Type*}
variables (V : Type u) [category.{v} V] [preadditive V]
variables (c : complex_shape ι)
/--
The congruence on `homological_complex V c` given by the existence of a homotopy.
-/
def homotopic : hom_rel (homological_complex V c) := λ C D f g, nonempty (homotopy f g)
instance homotopy_congruence : congruence (homotopic V c) :=
{ is_equiv := λ C D,
{ refl := λ C, ⟨homotopy.refl C⟩,
symm := λ f g ⟨w⟩, ⟨w.symm⟩,
trans := λ f g h ⟨w₁⟩ ⟨w₂⟩, ⟨w₁.trans w₂⟩, },
comp_left := λ E F G m₁ m₂ g ⟨i⟩, ⟨i.comp_left _⟩,
comp_right := λ E F G f m₁ m₂ ⟨i⟩, ⟨i.comp_right _⟩, }
/-- `homotopy_category V c` is the category of chain complexes of shape `c` in `V`,
with chain maps identified when they are homotopic. -/
@[derive category]
def homotopy_category := category_theory.quotient (homotopic V c)
-- TODO the homotopy_category is preadditive
namespace homotopy_category
/-- The quotient functor from complexes to the homotopy category. -/
def quotient : homological_complex V c ⥤ homotopy_category V c :=
category_theory.quotient.functor _
local attribute [instance] has_zero_object.has_zero
-- TODO upgrade this is to `has_zero_object`, presumably for any `quotient`.
instance [has_zero_object V] : inhabited (homotopy_category V c) := ⟨(quotient V c).obj 0⟩
variables {V c}
@[simp] lemma quotient_obj_as (C : homological_complex V c) :
((quotient V c).obj C).as = C := rfl
@[simp] lemma quotient_map_out {C D : homotopy_category V c} (f : C ⟶ D) :
(quotient V c).map f.out = f :=
quot.out_eq _
lemma eq_of_homotopy {C D : homological_complex V c} (f g : C ⟶ D) (h : homotopy f g) :
(quotient V c).map f = (quotient V c).map g :=
category_theory.quotient.sound _ ⟨h⟩
/-- If two chain maps become equal in the homotopy category, then they are homotopic. -/
def homotopy_of_eq {C D : homological_complex V c} (f g : C ⟶ D)
(w : (quotient V c).map f = (quotient V c).map g) : homotopy f g :=
((quotient.functor_map_eq_iff _ _ _).mp w).some
/--
An arbitrarily chosen representation of the image of a chain map in the homotopy category
is homotopic to the original chain map.
-/
def homotopy_out_map {C D : homological_complex V c} (f : C ⟶ D) :
homotopy ((quotient V c).map f).out f :=
begin
apply homotopy_of_eq,
simp,
end
@[simp] lemma quotient_map_out_comp_out {C D E : homotopy_category V c} (f : C ⟶ D) (g : D ⟶ E) :
(quotient V c).map (quot.out f ≫ quot.out g) = f ≫ g :=
by conv_rhs { erw [←quotient_map_out f, ←quotient_map_out g, ←(quotient V c).map_comp], }
/-- Homotopy equivalent complexes become isomorphic in the homotopy category. -/
@[simps]
def iso_of_homotopy_equiv {C D : homological_complex V c} (f : homotopy_equiv C D) :
(quotient V c).obj C ≅ (quotient V c).obj D :=
{ hom := (quotient V c).map f.hom,
inv := (quotient V c).map f.inv,
hom_inv_id' := begin
rw [←(quotient V c).map_comp, ←(quotient V c).map_id],
exact eq_of_homotopy _ _ f.homotopy_hom_inv_id,
end,
inv_hom_id' := begin
rw [←(quotient V c).map_comp, ←(quotient V c).map_id],
exact eq_of_homotopy _ _ f.homotopy_inv_hom_id,
end }
/-- If two complexes become isomorphic in the homotopy category,
then they were homotopy equivalent. -/
def homotopy_equiv_of_iso
{C D : homological_complex V c} (i : (quotient V c).obj C ≅ (quotient V c).obj D) :
homotopy_equiv C D :=
{ hom := quot.out i.hom,
inv := quot.out i.inv,
homotopy_hom_inv_id := homotopy_of_eq _ _ (by { simp, refl, }),
homotopy_inv_hom_id := homotopy_of_eq _ _ (by { simp, refl, }), }
variables (V c) [has_zero_object V] [has_equalizers V] [has_images V] [has_image_maps V]
[has_cokernels V]
/-- The `i`-th homology, as a functor from the homotopy category. -/
def homology_functor (i : ι) : homotopy_category V c ⥤ V :=
category_theory.quotient.lift _ (homology_functor V c i)
(λ C D f g ⟨h⟩, homology_map_eq_of_homotopy h i)
/-- The homology functor on the homotopy category is just the usual homology functor. -/
def homology_factors (i : ι) :
quotient V c ⋙ homology_functor V c i ≅ _root_.homology_functor V c i :=
category_theory.quotient.lift.is_lift _ _ _
@[simp] lemma homology_factors_hom_app (i : ι) (C : homological_complex V c) :
(homology_factors V c i).hom.app C = 𝟙 _ :=
rfl
@[simp] lemma homology_factors_inv_app (i : ι) (C : homological_complex V c) :
(homology_factors V c i).inv.app C = 𝟙 _ :=
rfl
lemma homology_functor_map_factors (i : ι) {C D : homological_complex V c} (f : C ⟶ D) :
(_root_.homology_functor V c i).map f =
((homology_functor V c i).map ((quotient V c).map f) : _) :=
(category_theory.quotient.lift_map_functor_map _ (_root_.homology_functor V c i) _ f).symm
end homotopy_category
namespace category_theory
variables {V} {W : Type*} [category W] [preadditive W]
/-- An additive functor induces a functor between homotopy categories. -/
@[simps]
def functor.map_homotopy_category (c : complex_shape ι) (F : V ⥤ W) [F.additive] :
homotopy_category V c ⥤ homotopy_category W c :=
{ obj := λ C, (homotopy_category.quotient W c).obj ((F.map_homological_complex c).obj C.as),
map := λ C D f,
(homotopy_category.quotient W c).map ((F.map_homological_complex c).map (quot.out f)),
map_id' := λ C, begin
rw ←(homotopy_category.quotient W c).map_id,
apply homotopy_category.eq_of_homotopy,
rw ←(F.map_homological_complex c).map_id,
apply F.map_homotopy,
apply homotopy_category.homotopy_of_eq,
exact quot.out_eq _,
end,
map_comp' := λ C D E f g, begin
rw ←(homotopy_category.quotient W c).map_comp,
apply homotopy_category.eq_of_homotopy,
rw ←(F.map_homological_complex c).map_comp,
apply F.map_homotopy,
apply homotopy_category.homotopy_of_eq,
convert quot.out_eq _,
exact homotopy_category.quotient_map_out_comp_out _ _,
end }.
-- TODO `F.map_homotopy_category c` is additive (and linear when `F` is linear).
/-- A natural transformation induces a natural transformation between
the induced functors on the homotopy category. -/
@[simps]
def nat_trans.map_homotopy_category {F G : V ⥤ W} [F.additive] [G.additive]
(α : F ⟶ G) (c : complex_shape ι) : F.map_homotopy_category c ⟶ G.map_homotopy_category c :=
{ app := λ C,
(homotopy_category.quotient W c).map ((nat_trans.map_homological_complex α c).app C.as),
naturality' := λ C D f,
begin
dsimp,
simp only [←functor.map_comp],
congr' 1,
ext,
dsimp,
simp,
end }
@[simp] lemma nat_trans.map_homotopy_category_id (c : complex_shape ι) (F : V ⥤ W) [F.additive] :
nat_trans.map_homotopy_category (𝟙 F) c = 𝟙 (F.map_homotopy_category c) :=
by tidy
@[simp] lemma nat_trans.map_homotopy_category_comp (c : complex_shape ι)
{F G H : V ⥤ W} [F.additive] [G.additive] [H.additive]
(α : F ⟶ G) (β : G ⟶ H):
nat_trans.map_homotopy_category (α ≫ β) c =
nat_trans.map_homotopy_category α c ≫ nat_trans.map_homotopy_category β c :=
by tidy
end category_theory
|
5fecd6fe84e655fce620b5577468cd6d34da76e8 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/linear_algebra/dfinsupp.lean | eaa222ea678ab260abcc48a847dbca61c53e713c | [
"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 | 20,859 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Kenny Lau
-/
import data.finsupp.to_dfinsupp
import linear_algebra.basis
/-!
# Properties of the module `Π₀ i, M i`
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
Given an indexed collection of `R`-modules `M i`, the `R`-module structure on `Π₀ i, M i`
is defined in `data.dfinsupp`.
In this file we define `linear_map` versions of various maps:
* `dfinsupp.lsingle a : M →ₗ[R] Π₀ i, M i`: `dfinsupp.single a` as a linear map;
* `dfinsupp.lmk s : (Π i : (↑s : set ι), M i) →ₗ[R] Π₀ i, M i`: `dfinsupp.single a` as a linear map;
* `dfinsupp.lapply i : (Π₀ i, M i) →ₗ[R] M`: the map `λ f, f i` as a linear map;
* `dfinsupp.lsum`: `dfinsupp.sum` or `dfinsupp.lift_add_hom` as a `linear_map`;
## Implementation notes
This file should try to mirror `linear_algebra.finsupp` where possible. The API of `finsupp` is
much more developed, but many lemmas in that file should be eligible to copy over.
## Tags
function with finite support, module, linear algebra
-/
variables {ι : Type*} {R : Type*} {S : Type*} {M : ι → Type*} {N : Type*}
variables [dec_ι : decidable_eq ι]
namespace dfinsupp
variables [semiring R] [Π i, add_comm_monoid (M i)] [Π i, module R (M i)]
variables [add_comm_monoid N] [module R N]
include dec_ι
/-- `dfinsupp.mk` as a `linear_map`. -/
def lmk (s : finset ι) : (Π i : (↑s : set ι), M i) →ₗ[R] Π₀ i, M i :=
{ to_fun := mk s, map_add' := λ _ _, mk_add, map_smul' := λ c x, mk_smul c x}
/-- `dfinsupp.single` as a `linear_map` -/
def lsingle (i) : M i →ₗ[R] Π₀ i, M i :=
{ to_fun := single i, map_smul' := single_smul, .. dfinsupp.single_add_hom _ _ }
/-- Two `R`-linear maps from `Π₀ i, M i` which agree on each `single i x` agree everywhere. -/
lemma lhom_ext ⦃φ ψ : (Π₀ i, M i) →ₗ[R] N⦄
(h : ∀ i x, φ (single i x) = ψ (single i x)) :
φ = ψ :=
linear_map.to_add_monoid_hom_injective $ add_hom_ext h
/-- Two `R`-linear maps from `Π₀ i, M i` which agree on each `single i x` agree everywhere.
See note [partially-applied ext lemmas].
After apply this lemma, if `M = R` then it suffices to verify `φ (single a 1) = ψ (single a 1)`. -/
@[ext] lemma lhom_ext' ⦃φ ψ : (Π₀ i, M i) →ₗ[R] N⦄
(h : ∀ i, φ.comp (lsingle i) = ψ.comp (lsingle i)) :
φ = ψ :=
lhom_ext $ λ i, linear_map.congr_fun (h i)
omit dec_ι
/-- Interpret `λ (f : Π₀ i, M i), f i` as a linear map. -/
def lapply (i : ι) : (Π₀ i, M i) →ₗ[R] M i :=
{ to_fun := λ f, f i,
map_add' := λ f g, add_apply f g i,
map_smul' := λ c f, smul_apply c f i}
include dec_ι
@[simp] lemma lmk_apply (s : finset ι) (x) : (lmk s : _ →ₗ[R] Π₀ i, M i) x = mk s x := rfl
@[simp] lemma lsingle_apply (i : ι) (x : M i) : (lsingle i : _ →ₗ[R] _) x = single i x := rfl
omit dec_ι
@[simp] lemma lapply_apply (i : ι) (f : Π₀ i, M i) : (lapply i : _ →ₗ[R] _) f = f i := rfl
section lsum
/-- Typeclass inference can't find `dfinsupp.add_comm_monoid` without help for this case.
This instance allows it to be found where it is needed on the LHS of the colon in
`dfinsupp.module_of_linear_map`. -/
instance add_comm_monoid_of_linear_map : add_comm_monoid (Π₀ (i : ι), M i →ₗ[R] N) :=
@dfinsupp.add_comm_monoid _ (λ i, M i →ₗ[R] N) _
/-- Typeclass inference can't find `dfinsupp.module` without help for this case.
This is needed to define `dfinsupp.lsum` below.
The cause seems to be an inability to unify the `Π i, add_comm_monoid (M i →ₗ[R] N)` instance that
we have with the `Π i, has_zero (M i →ₗ[R] N)` instance which appears as a parameter to the
`dfinsupp` type. -/
instance module_of_linear_map [semiring S] [module S N] [smul_comm_class R S N] :
module S (Π₀ (i : ι), M i →ₗ[R] N) :=
@dfinsupp.module _ _ (λ i, M i →ₗ[R] N) _ _ _
variables (S)
include dec_ι
/-- The `dfinsupp` version of `finsupp.lsum`.
See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/
@[simps]
def lsum [semiring S] [module S N] [smul_comm_class R S N] :
(Π i, M i →ₗ[R] N) ≃ₗ[S] ((Π₀ i, M i) →ₗ[R] N) :=
{ to_fun := λ F,
{ to_fun := sum_add_hom (λ i, (F i).to_add_monoid_hom),
map_add' := (lift_add_hom (λ i, (F i).to_add_monoid_hom)).map_add,
map_smul' := λ c f, by
{ dsimp,
apply dfinsupp.induction f,
{ rw [smul_zero, add_monoid_hom.map_zero, smul_zero] },
{ intros a b f ha hb hf,
rw [smul_add, add_monoid_hom.map_add, add_monoid_hom.map_add, smul_add, hf, ←single_smul,
sum_add_hom_single, sum_add_hom_single, linear_map.to_add_monoid_hom_coe,
linear_map.map_smul], } } },
inv_fun := λ F i, F.comp (lsingle i),
left_inv := λ F, by { ext x y, simp },
right_inv := λ F, by { ext x y, simp },
map_add' := λ F G, by { ext x y, simp },
map_smul' := λ c F, by { ext, simp } }
/-- While `simp` can prove this, it is often convenient to avoid unfolding `lsum` into `sum_add_hom`
with `dfinsupp.lsum_apply_apply`. -/
lemma lsum_single [semiring S] [module S N] [smul_comm_class R S N]
(F : Π i, M i →ₗ[R] N) (i) (x : M i) :
lsum S F (single i x) = F i x :=
sum_add_hom_single _ _ _
end lsum
/-! ### Bundled versions of `dfinsupp.map_range`
The names should match the equivalent bundled `finsupp.map_range` definitions.
-/
section map_range
variables {β β₁ β₂: ι → Type*}
variables [Π i, add_comm_monoid (β i)] [Π i, add_comm_monoid (β₁ i)] [Π i, add_comm_monoid (β₂ i)]
variables [Π i, module R (β i)] [Π i, module R (β₁ i)] [Π i, module R (β₂ i)]
lemma map_range_smul (f : Π i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0)
(r : R) (hf' : ∀ i x, f i (r • x) = r • f i x) (g : Π₀ i, β₁ i):
map_range f hf (r • g) = r • map_range f hf g :=
begin
ext,
simp only [map_range_apply f, coe_smul, pi.smul_apply, hf']
end
/-- `dfinsupp.map_range` as an `linear_map`. -/
@[simps apply]
def map_range.linear_map (f : Π i, β₁ i →ₗ[R] β₂ i) : (Π₀ i, β₁ i) →ₗ[R] (Π₀ i, β₂ i) :=
{ to_fun := map_range (λ i x, f i x) (λ i, (f i).map_zero),
map_smul' := λ r, map_range_smul _ _ _ (λ i, (f i).map_smul r),
.. map_range.add_monoid_hom (λ i, (f i).to_add_monoid_hom) }
@[simp]
lemma map_range.linear_map_id :
map_range.linear_map (λ i, (linear_map.id : (β₂ i) →ₗ[R] _)) = linear_map.id :=
linear_map.ext map_range_id
lemma map_range.linear_map_comp (f : Π i, β₁ i →ₗ[R] β₂ i) (f₂ : Π i, β i →ₗ[R] β₁ i):
map_range.linear_map (λ i, (f i).comp (f₂ i)) =
(map_range.linear_map f).comp (map_range.linear_map f₂) :=
linear_map.ext $ map_range_comp (λ i x, f i x) (λ i x, f₂ i x) _ _ _
include dec_ι
lemma sum_map_range_index.linear_map
[Π (i : ι) (x : β₁ i), decidable (x ≠ 0)] [Π (i : ι) (x : β₂ i), decidable (x ≠ 0)]
{f : Π i, β₁ i →ₗ[R] β₂ i} {h : Π i, β₂ i →ₗ[R] N} {l : Π₀ i, β₁ i} :
dfinsupp.lsum ℕ h (map_range.linear_map f l) = dfinsupp.lsum ℕ (λ i, (h i).comp (f i)) l :=
by simpa [dfinsupp.sum_add_hom_apply] using
@sum_map_range_index ι N _ _ _ _ _ _ _ _ (λ i, f i) (λ i, by simp) l (λ i, h i) (λ i, by simp)
omit dec_ι
/-- `dfinsupp.map_range.linear_map` as an `linear_equiv`. -/
@[simps apply]
def map_range.linear_equiv (e : Π i, β₁ i ≃ₗ[R] β₂ i) : (Π₀ i, β₁ i) ≃ₗ[R] (Π₀ i, β₂ i) :=
{ to_fun := map_range (λ i x, e i x) (λ i, (e i).map_zero),
inv_fun := map_range (λ i x, (e i).symm x) (λ i, (e i).symm.map_zero),
.. map_range.add_equiv (λ i, (e i).to_add_equiv),
.. map_range.linear_map (λ i, (e i).to_linear_map) }
@[simp]
lemma map_range.linear_equiv_refl :
(map_range.linear_equiv $ λ i, linear_equiv.refl R (β₁ i)) = linear_equiv.refl _ _ :=
linear_equiv.ext map_range_id
lemma map_range.linear_equiv_trans (f : Π i, β i ≃ₗ[R] β₁ i) (f₂ : Π i, β₁ i ≃ₗ[R] β₂ i):
map_range.linear_equiv (λ i, (f i).trans (f₂ i)) =
(map_range.linear_equiv f).trans (map_range.linear_equiv f₂) :=
linear_equiv.ext $ map_range_comp (λ i x, f₂ i x) (λ i x, f i x) _ _ _
@[simp]
lemma map_range.linear_equiv_symm (e : Π i, β₁ i ≃ₗ[R] β₂ i) :
(map_range.linear_equiv e).symm = map_range.linear_equiv (λ i, (e i).symm) := rfl
end map_range
section coprod_map
variables [decidable_eq ι] [Π (x : N), decidable (x ≠ 0)]
/-- Given a family of linear maps `f i : M i →ₗ[R] N`, we can form a linear map
`(Π₀ i, M i) →ₗ[R] N` which sends `x : Π₀ i, M i` to the sum over `i` of `f i` applied to `x i`.
This is the map coming from the universal property of `Π₀ i, M i` as the coproduct of the `M i`.
See also `linear_map.coprod` for the binary product version. -/
noncomputable def coprod_map (f : Π (i : ι), M i →ₗ[R] N) : (Π₀ i, M i) →ₗ[R] N :=
finsupp.lsum ℕ (λ i : ι, linear_map.id) ∘ₗ
(@finsupp_lequiv_dfinsupp ι R N _ _ _ _ _).symm.to_linear_map ∘ₗ
(dfinsupp.map_range.linear_map f)
lemma coprod_map_apply (f : Π (i : ι), M i →ₗ[R] N) (x : Π₀ i, M i) :
coprod_map f x =
finsupp.sum (map_range (λ i, f i) (λ i, linear_map.map_zero _) x).to_finsupp (λ i, id) := rfl
end coprod_map
section basis
/-- The direct sum of free modules is free.
Note that while this is stated for `dfinsupp` not `direct_sum`, the types are defeq. -/
noncomputable def basis {η : ι → Type*} (b : Π i, basis (η i) R (M i)) :
basis (Σ i, η i) R (Π₀ i, M i) :=
basis.of_repr ((map_range.linear_equiv (λ i, (b i).repr)).trans
(sigma_finsupp_lequiv_dfinsupp R).symm)
end basis
end dfinsupp
include dec_ι
namespace submodule
variables [semiring R] [add_comm_monoid N] [module R N]
open dfinsupp
lemma dfinsupp_sum_mem {β : ι → Type*} [Π i, has_zero (β i)]
[Π i (x : β i), decidable (x ≠ 0)] (S : submodule R N)
(f : Π₀ i, β i) (g : Π i, β i → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ S) : f.sum g ∈ S :=
dfinsupp_sum_mem S f g h
lemma dfinsupp_sum_add_hom_mem {β : ι → Type*} [Π i, add_zero_class (β i)]
(S : submodule R N) (f : Π₀ i, β i) (g : Π i, β i →+ N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ S) :
dfinsupp.sum_add_hom g f ∈ S :=
dfinsupp_sum_add_hom_mem S f g h
/-- The supremum of a family of submodules is equal to the range of `dfinsupp.lsum`; that is
every element in the `supr` can be produced from taking a finite number of non-zero elements
of `p i`, coercing them to `N`, and summing them. -/
lemma supr_eq_range_dfinsupp_lsum (p : ι → submodule R N) :
supr p = (dfinsupp.lsum ℕ (λ i, (p i).subtype)).range :=
begin
apply le_antisymm,
{ apply supr_le _,
intros i y hy,
exact ⟨dfinsupp.single i ⟨y, hy⟩, dfinsupp.sum_add_hom_single _ _ _⟩, },
{ rintros x ⟨v, rfl⟩,
exact dfinsupp_sum_add_hom_mem _ v _ (λ i _, (le_supr p i : p i ≤ _) (v i).prop) }
end
/-- The bounded supremum of a family of commutative additive submonoids is equal to the range of
`dfinsupp.sum_add_hom` composed with `dfinsupp.filter_add_monoid_hom`; that is, every element in the
bounded `supr` can be produced from taking a finite number of non-zero elements from the `S i` that
satisfy `p i`, coercing them to `γ`, and summing them. -/
lemma bsupr_eq_range_dfinsupp_lsum (p : ι → Prop)
[decidable_pred p] (S : ι → submodule R N) :
(⨆ i (h : p i), S i) =
((dfinsupp.lsum ℕ (λ i, (S i).subtype)).comp (dfinsupp.filter_linear_map R _ p)).range :=
begin
apply le_antisymm,
{ refine supr₂_le (λ i hi y hy, ⟨dfinsupp.single i ⟨y, hy⟩, _⟩),
rw [linear_map.comp_apply, filter_linear_map_apply, filter_single_pos _ _ hi],
exact dfinsupp.sum_add_hom_single _ _ _, },
{ rintros x ⟨v, rfl⟩,
refine dfinsupp_sum_add_hom_mem _ _ _ (λ i hi, _),
refine mem_supr_of_mem i _,
by_cases hp : p i,
{ simp [hp], },
{ simp [hp] }, }
end
lemma mem_supr_iff_exists_dfinsupp (p : ι → submodule R N) (x : N) :
x ∈ supr p ↔ ∃ f : Π₀ i, p i, dfinsupp.lsum ℕ (λ i, (p i).subtype) f = x :=
set_like.ext_iff.mp (supr_eq_range_dfinsupp_lsum p) x
/-- A variant of `submodule.mem_supr_iff_exists_dfinsupp` with the RHS fully unfolded. -/
lemma mem_supr_iff_exists_dfinsupp' (p : ι → submodule R N) [Π i (x : p i), decidable (x ≠ 0)]
(x : N) :
x ∈ supr p ↔ ∃ f : Π₀ i, p i, f.sum (λ i xi, ↑xi) = x :=
begin
rw mem_supr_iff_exists_dfinsupp,
simp_rw [dfinsupp.lsum_apply_apply, dfinsupp.sum_add_hom_apply],
congr',
end
lemma mem_bsupr_iff_exists_dfinsupp (p : ι → Prop) [decidable_pred p] (S : ι → submodule R N)
(x : N) :
x ∈ (⨆ i (h : p i), S i) ↔
∃ f : Π₀ i, S i, dfinsupp.lsum ℕ (λ i, (S i).subtype) (f.filter p) = x :=
set_like.ext_iff.mp (bsupr_eq_range_dfinsupp_lsum p S) x
open_locale big_operators
omit dec_ι
lemma mem_supr_finset_iff_exists_sum {s : finset ι} (p : ι → submodule R N) (a : N) :
a ∈ (⨆ i ∈ s, p i) ↔ ∃ μ : Π i, p i, ∑ i in s, (μ i : N) = a :=
begin
classical,
rw submodule.mem_supr_iff_exists_dfinsupp',
split; rintro ⟨μ, hμ⟩,
{ use λ i, ⟨μ i, (supr_const_le : _ ≤ p i) (coe_mem $ μ i)⟩,
rw ← hμ, symmetry, apply finset.sum_subset,
{ intro x, contrapose, intro hx,
rw [mem_support_iff, not_ne_iff],
ext, rw [coe_zero, ← mem_bot R], convert coe_mem (μ x),
symmetry, exact supr_neg hx },
{ intros x _ hx, rw [mem_support_iff, not_ne_iff] at hx, rw hx, refl } },
{ refine ⟨dfinsupp.mk s _, _⟩,
{ rintro ⟨i, hi⟩, refine ⟨μ i, _⟩,
rw supr_pos, { exact coe_mem _ }, { exact hi } },
simp only [dfinsupp.sum],
rw [finset.sum_subset support_mk_subset, ← hμ],
exact finset.sum_congr rfl (λ x hx, congr_arg coe $ mk_of_mem hx),
{ intros x _ hx, rw [mem_support_iff, not_ne_iff] at hx, rw hx, refl } }
end
end submodule
namespace complete_lattice
open dfinsupp
section semiring
variables [semiring R] [add_comm_monoid N] [module R N]
/-- Independence of a family of submodules can be expressed as a quantifier over `dfinsupp`s.
This is an intermediate result used to prove
`complete_lattice.independent_of_dfinsupp_lsum_injective` and
`complete_lattice.independent.dfinsupp_lsum_injective`. -/
lemma independent_iff_forall_dfinsupp (p : ι → submodule R N) :
independent p ↔
∀ i (x : p i) (v : Π₀ (i : ι), ↥(p i)), lsum ℕ (λ i, (p i).subtype) (erase i v) = x → x = 0 :=
begin
simp_rw [complete_lattice.independent_def, submodule.disjoint_def,
submodule.mem_bsupr_iff_exists_dfinsupp, exists_imp_distrib, filter_ne_eq_erase],
apply forall_congr (λ i, _),
refine subtype.forall'.trans _,
simp_rw submodule.coe_eq_zero,
refl,
end
/- If `dfinsupp.lsum` applied with `submodule.subtype` is injective then the submodules are
independent. -/
lemma independent_of_dfinsupp_lsum_injective (p : ι → submodule R N)
(h : function.injective (lsum ℕ (λ i, (p i).subtype))) :
independent p :=
begin
rw independent_iff_forall_dfinsupp,
intros i x v hv,
replace hv : lsum ℕ (λ i, (p i).subtype) (erase i v) = lsum ℕ (λ i, (p i).subtype) (single i x),
{ simpa only [lsum_single] using hv, },
have := dfinsupp.ext_iff.mp (h hv) i,
simpa [eq_comm] using this,
end
/- If `dfinsupp.sum_add_hom` applied with `add_submonoid.subtype` is injective then the additive
submonoids are independent. -/
lemma independent_of_dfinsupp_sum_add_hom_injective (p : ι → add_submonoid N)
(h : function.injective (sum_add_hom (λ i, (p i).subtype))) :
independent p :=
begin
rw ←independent_map_order_iso_iff (add_submonoid.to_nat_submodule : add_submonoid N ≃o _),
exact independent_of_dfinsupp_lsum_injective _ h,
end
/-- Combining `dfinsupp.lsum` with `linear_map.to_span_singleton` is the same as `finsupp.total` -/
lemma lsum_comp_map_range_to_span_singleton
[Π (m : R), decidable (m ≠ 0)]
(p : ι → submodule R N) {v : ι → N} (hv : ∀ (i : ι), v i ∈ p i) :
((lsum ℕ) (λ i, (p i).subtype) : _ →ₗ[R] _).comp
((map_range.linear_map
(λ i, linear_map.to_span_singleton R ↥(p i) ⟨v i, hv i⟩) : _ →ₗ[R] _).comp
(finsupp_lequiv_dfinsupp R : (ι →₀ R) ≃ₗ[R] _).to_linear_map) =
finsupp.total ι N R v :=
by { ext, simp }
end semiring
section ring
variables [ring R] [add_comm_group N] [module R N]
/- If `dfinsupp.sum_add_hom` applied with `add_submonoid.subtype` is injective then the additive
subgroups are independent. -/
lemma independent_of_dfinsupp_sum_add_hom_injective' (p : ι → add_subgroup N)
(h : function.injective (sum_add_hom (λ i, (p i).subtype))) :
independent p :=
begin
rw ←independent_map_order_iso_iff (add_subgroup.to_int_submodule : add_subgroup N ≃o _),
exact independent_of_dfinsupp_lsum_injective _ h,
end
/-- The canonical map out of a direct sum of a family of submodules is injective when the submodules
are `complete_lattice.independent`.
Note that this is not generally true for `[semiring R]`, for instance when `A` is the
`ℕ`-submodules of the positive and negative integers.
See `counterexamples/direct_sum_is_internal.lean` for a proof of this fact. -/
lemma independent.dfinsupp_lsum_injective {p : ι → submodule R N}
(h : independent p) : function.injective (lsum ℕ (λ i, (p i).subtype)) :=
begin
-- simplify everything down to binders over equalities in `N`
rw independent_iff_forall_dfinsupp at h,
suffices : (lsum ℕ (λ i, (p i).subtype)).ker = ⊥,
{ -- Lean can't find this without our help
letI : add_comm_group (Π₀ i, p i) := @dfinsupp.add_comm_group _ (λ i, p i) _,
rw linear_map.ker_eq_bot at this, exact this },
rw linear_map.ker_eq_bot',
intros m hm,
ext i : 1,
-- split `m` into the piece at `i` and the pieces elsewhere, to match `h`
rw [dfinsupp.zero_apply, ←neg_eq_zero],
refine h i (-m i) m _,
rwa [←erase_add_single i m, linear_map.map_add, lsum_single, submodule.subtype_apply,
add_eq_zero_iff_eq_neg, ←submodule.coe_neg] at hm,
end
/-- The canonical map out of a direct sum of a family of additive subgroups is injective when the
additive subgroups are `complete_lattice.independent`. -/
lemma independent.dfinsupp_sum_add_hom_injective {p : ι → add_subgroup N}
(h : independent p) : function.injective (sum_add_hom (λ i, (p i).subtype)) :=
begin
rw ←independent_map_order_iso_iff (add_subgroup.to_int_submodule : add_subgroup N ≃o _) at h,
exact h.dfinsupp_lsum_injective,
end
/-- A family of submodules over an additive group are independent if and only iff `dfinsupp.lsum`
applied with `submodule.subtype` is injective.
Note that this is not generally true for `[semiring R]`; see
`complete_lattice.independent.dfinsupp_lsum_injective` for details. -/
lemma independent_iff_dfinsupp_lsum_injective (p : ι → submodule R N) :
independent p ↔ function.injective (lsum ℕ (λ i, (p i).subtype)) :=
⟨independent.dfinsupp_lsum_injective, independent_of_dfinsupp_lsum_injective p⟩
/-- A family of additive subgroups over an additive group are independent if and only if
`dfinsupp.sum_add_hom` applied with `add_subgroup.subtype` is injective. -/
lemma independent_iff_dfinsupp_sum_add_hom_injective (p : ι → add_subgroup N) :
independent p ↔ function.injective (sum_add_hom (λ i, (p i).subtype)) :=
⟨independent.dfinsupp_sum_add_hom_injective, independent_of_dfinsupp_sum_add_hom_injective' p⟩
omit dec_ι
/-- If a family of submodules is `independent`, then a choice of nonzero vector from each submodule
forms a linearly independent family.
See also `complete_lattice.independent.linear_independent'`. -/
lemma independent.linear_independent [no_zero_smul_divisors R N] (p : ι → submodule R N)
(hp : independent p) {v : ι → N} (hv : ∀ i, v i ∈ p i) (hv' : ∀ i, v i ≠ 0) :
linear_independent R v :=
begin
classical,
rw linear_independent_iff,
intros l hl,
let a := dfinsupp.map_range.linear_map
(λ i, linear_map.to_span_singleton R (p i) (⟨v i, hv i⟩)) l.to_dfinsupp,
have ha : a = 0,
{ apply hp.dfinsupp_lsum_injective,
rwa ←lsum_comp_map_range_to_span_singleton _ hv at hl },
ext i,
apply smul_left_injective R (hv' i),
have : l i • v i = a i := rfl,
simp [this, ha],
end
lemma independent_iff_linear_independent_of_ne_zero [no_zero_smul_divisors R N] {v : ι → N}
(h_ne_zero : ∀ i, v i ≠ 0) :
independent (λ i, R ∙ v i) ↔ linear_independent R v :=
⟨λ hv, hv.linear_independent _ (λ i, submodule.mem_span_singleton_self $ v i) h_ne_zero,
λ hv, hv.independent_span_singleton⟩
end ring
end complete_lattice
|
9233c4ae344a825c9f51a9b60262720039ef3e5d | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/362c.lean | 153437dddea9c5587f83d101e6ea5af5e21aa64c | [
"Apache-2.0"
] | permissive | leanprover-community/lean | 12b87f69d92e614daea8bcc9d4de9a9ace089d0e | cce7990ea86a78bdb383e38ed7f9b5ba93c60ce0 | refs/heads/master | 1,687,508,156,644 | 1,684,951,104,000 | 1,684,951,104,000 | 169,960,991 | 457 | 107 | Apache-2.0 | 1,686,744,372,000 | 1,549,790,268,000 | C++ | UTF-8 | Lean | false | false | 63 | lean | open tactic
#eval success_if_fail $ unify `(1 : ℕ) `(1 : ℤ) |
2c8e3b434fa6897a45888a1efb471bbe4788f8ad | 05f637fa14ac28031cb1ea92086a0f4eb23ff2b1 | /tests/lean/interactive/elab6.lean | 28a1e5068291dc4ad414579633cb30cbbdeee1e8 | [
"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 | 279 | lean | (*
-- The elaborator does not expand definitions marked as 'opaque'.
-- To be able to prove the following theorem, we have to unmark the
-- 'forall'
local env = get_environment()
*)
theorem forall::intro2 (A : (Type U)) (P : A -> Bool) (H : forall x, P x) : forall x, P x :=
H
|
84db16663d8a7b534d538bcb2970ea172fc7b7d5 | 453dcd7c0d1ef170b0843a81d7d8caedc9741dce | /data/finsupp.lean | b9286b459a819132c909cf84b4f9921f49b79c9c | [
"Apache-2.0"
] | permissive | amswerdlow/mathlib | 9af77a1f08486d8fa059448ae2d97795bd12ec0c | 27f96e30b9c9bf518341705c99d641c38638dfd0 | refs/heads/master | 1,585,200,953,598 | 1,534,275,532,000 | 1,534,275,532,000 | 144,564,700 | 0 | 0 | null | 1,534,156,197,000 | 1,534,156,197,000 | null | UTF-8 | Lean | false | false | 28,611 | 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
Type of functions with finite support.
Functions with finite support provide the basis for the following concrete instances:
* ℕ →₀ α: Polynomials (where α is a ring)
* (σ →₀ ℕ) →₀ α: Multivariate Polynomials (again α is a ring, and σ are variable names)
* α →₀ ℕ: Multisets
* α →₀ ℤ: Abelean groups freely generated by α
* β →₀ α: Linear combinations over β where α is the scalar ring
Most of the theory assumes that the range is a commutative monoid. This gives us the big sum
operator as a powerful way to construct `finsupp` elements.
A general advice is to not use α →₀ β directly, as the type class setup might not be fitting.
The best is to define a copy and select the instances best suited.
-/
import data.finset data.set.finite algebra.big_operators algebra.module
open finset
reserve infix ` →₀ `:25
universes u u₁ u₂ v v₁ v₂ v₃ w x y
namespace finset
variables {α : Type u} [decidable_eq α]
protected def subtype (p : α → Prop) [decidable_pred p] (s : finset α) : finset (subtype p) :=
(s.filter p).attach.image $ λ⟨a, ha⟩, ⟨a, (mem_filter.1 ha).2⟩
@[simp] lemma mem_subtype {p : α → Prop} [decidable_pred p] {s : finset α} :
∀{a : subtype p}, a ∈ s.subtype p ↔ a.val ∈ s
| ⟨a, ha⟩ := by simp [finset.subtype, ha]
end finset
/-- `finsupp α β`, denoted `α →₀ β`, is the type of functions `f : α → β` such that
`f x = 0` for all but finitely many `x`. -/
structure finsupp (α : Type u) (β : Type v) [has_zero β] :=
(support : finset α)
(to_fun : α → β)
(mem_support_to_fun : ∀a, a ∈ support ↔ to_fun a ≠ 0)
infix →₀ := finsupp
namespace finsupp
variables {α : Type u} {β : Type v} {γ : Type w}
{α₁ : Type u₁} {α₂ : Type u₂} {β₁ : Type v₁} {β₂ : Type v₂}
section basic
variable [has_zero β]
instance : has_coe_to_fun (α →₀ β) := ⟨λ_, α → β, finsupp.to_fun⟩
instance : has_zero (α →₀ β) := ⟨⟨∅, (λ_, 0), by simp⟩⟩
@[simp] lemma zero_apply {a : α} : (0 : α →₀ β) a = 0 := rfl
@[simp] lemma support_zero : (0 : α →₀ β).support = ∅ := rfl
instance : inhabited (α →₀ β) := ⟨0⟩
@[simp] lemma mem_support_iff (f : α →₀ β) : ∀a:α, a ∈ f.support ↔ f a ≠ 0 :=
f.mem_support_to_fun
@[extensionality]
lemma ext : ∀{f g : α →₀ β}, (∀a, f a = g a) → f = g
| ⟨s, f, hf⟩ ⟨t, g, hg⟩ h :=
begin
have : f = g, { funext a, exact h a },
subst this,
have : s = t, { simp [finset.ext, hf, hg] },
subst this
end
@[simp] lemma support_eq_empty [decidable_eq β] {f : α →₀ β} : f.support = ∅ ↔ f = 0 :=
⟨assume h, ext $ assume a, by simp [finset.ext] at h; exact h a, by simp {contextual:=tt}⟩
instance [decidable_eq α] [decidable_eq β] : decidable_eq (α →₀ β) :=
assume f g, decidable_of_iff (f.support = g.support ∧ (∀a∈f.support, f a = g a))
⟨assume ⟨h₁, h₂⟩, ext $ assume a,
if h : a ∈ f.support then h₂ a h else
have hf : f a = 0, by rwa [f.mem_support_iff, not_not] at h,
have hg : g a = 0, by rwa [h₁, g.mem_support_iff, not_not] at h,
by rw [hf, hg],
by intro h; subst h; simp⟩
lemma finite_supp (f : α →₀ β) : set.finite {a | f a ≠ 0} :=
⟨set.fintype_of_finset f.support f.mem_support_iff⟩
lemma support_subset_iff {s : set α} {f : α →₀ β} [decidable_eq α] :
↑f.support ⊆ s ↔ (∀a∉s, f a = 0) :=
by simp [set.subset_def];
exact forall_congr (assume a, @not_imp_comm _ _ (classical.dec _) (classical.dec _))
end basic
section single
variables [decidable_eq α] [decidable_eq β] [has_zero β] {a a' : α} {b : β}
/-- `single a b` is the finitely supported function which has
value `b` at `a` and zero otherwise. -/
def single (a : α) (b : β) : α →₀ β :=
⟨(if b = 0 then ∅ else {a}), (λa', if a = a' then b else 0),
begin intro a', by_cases hb : b = 0; by_cases a = a'; simp [h, hb], simp [ne.symm h, h] end⟩
lemma single_apply : (single a b : α →₀ β) a' = (if a = a' then b else 0) :=
rfl
@[simp] lemma single_eq_same : (single a b : α →₀ β) a = b :=
by simp [single_apply]
@[simp] lemma single_eq_of_ne (h : a ≠ a') : (single a b : α →₀ β) a' = 0 :=
by simp [single_apply, h]
@[simp] lemma single_zero : (single a 0 : α →₀ β) = 0 :=
ext $ assume a',
begin
by_cases h : a = a',
{ rw [h, single_eq_same, zero_apply] },
{ rw [single_eq_of_ne h, zero_apply] }
end
lemma support_single_ne_zero (hb : b ≠ 0) : (single a b).support = {a} :=
if_neg hb
lemma support_single_subset : (single a b).support ⊆ {a} :=
by by_cases b = 0; simp [support_single_ne_zero, h]
end single
section on_finset
variables [decidable_eq β] [has_zero β]
/-- `on_finset s f hf` is the finsupp function representing `f` restricted to the set `s`.
The function needs to be 0 outside of `s`. Use this when the set needs filtered anyway, otherwise
often better set representation is available. -/
def on_finset (s : finset α) (f : α → β) (hf : ∀a, f a ≠ 0 → a ∈ s) : α →₀ β :=
⟨s.filter (λa, f a ≠ 0), f,
assume a, classical.by_cases
(assume h : f a = 0, by simp [h])
(assume h : f a ≠ 0, by simp [h, hf])⟩
@[simp] lemma on_finset_apply {s : finset α} {f : α → β} {hf a} :
(on_finset s f hf : α →₀ β) a = f a :=
rfl
@[simp] lemma support_on_finset_subset {s : finset α} {f : α → β} {hf} :
(on_finset s f hf).support ⊆ s :=
by simp [on_finset]
end on_finset
section map_range
variables [has_zero β₁] [has_zero β₂] [decidable_eq β₂]
/-- The composition of `f : β₁ → β₂` and `g : α →₀ β₁` is
`map_range f hf g : α →₀ β₂`, well defined when `f 0 = 0`. -/
def map_range (f : β₁ → β₂) (hf : f 0 = 0) (g : α →₀ β₁) : α →₀ β₂ :=
on_finset g.support (f ∘ g) $
assume a, by rw [mem_support_iff, not_imp_not]; simp [hf] {contextual := tt}
@[simp] lemma map_range_apply {f : β₁ → β₂} {hf : f 0 = 0} {g : α →₀ β₁} {a : α} :
map_range f hf g a = f (g a) :=
rfl
lemma support_map_range {f : β₁ → β₂} {hf : f 0 = 0} {g : α →₀ β₁} :
(map_range f hf g).support ⊆ g.support :=
support_on_finset_subset
variables [decidable_eq α] [decidable_eq β₁]
@[simp] lemma map_range_single {f : β₁ → β₂} {hf : f 0 = 0} {a : α} {b : β₁} :
map_range f hf (single a b) = single a (f b) :=
finsupp.ext $ λ a', by by_cases a = a'; [{subst a', simp}, simp [h, hf]]
end map_range
section zip_with
variables [has_zero β] [has_zero β₁] [has_zero β₂] [decidable_eq α] [decidable_eq β]
/-- `zip_with f hf g₁ g₂` is the finitely supported function satisfying
`zip_with f hf g₁ g₂ a = f (g₁ a) (g₂ a)`, and well defined when `f 0 0 = 0`. -/
def zip_with (f : β₁ → β₂ → β) (hf : f 0 0 = 0) (g₁ : α →₀ β₁) (g₂ : α →₀ β₂) : (α →₀ β) :=
on_finset (g₁.support ∪ g₂.support) (λa, f (g₁ a) (g₂ a)) $
assume a, classical.by_cases
(assume h : g₁ a = 0, by simp [h]; rw [not_imp_not]; simp [hf] {contextual := tt})
(assume h : g₁ a ≠ 0, by simp [h])
@[simp] lemma zip_with_apply
{f : β₁ → β₂ → β} {hf : f 0 0 = 0} {g₁ : α →₀ β₁} {g₂ : α →₀ β₂} {a : α} :
zip_with f hf g₁ g₂ a = f (g₁ a) (g₂ a) :=
rfl
lemma support_zip_with {f : β₁ → β₂ → β} {hf : f 0 0 = 0} {g₁ : α →₀ β₁} {g₂ : α →₀ β₂} :
(zip_with f hf g₁ g₂).support ⊆ g₁.support ∪ g₂.support :=
support_on_finset_subset
end zip_with
section erase
variables [decidable_eq α] [decidable_eq β]
def erase [has_zero β] (a : α) (f : α →₀ β) : α →₀ β :=
⟨f.support.erase a, (λa', if a' = a then 0 else f a'),
assume a', by by_cases a' = a; simp [h]⟩
@[simp] lemma support_erase [has_zero β] {a : α} {f : α →₀ β} :
(f.erase a).support = f.support.erase a :=
rfl
@[simp] lemma erase_same [has_zero β] {a : α} {f : α →₀ β} : (f.erase a) a = 0 :=
if_pos rfl
@[simp] lemma erase_ne [has_zero β] {a a' : α} {f : α →₀ β} (h : a' ≠ a) : (f.erase a) a' = f a' :=
if_neg h
end erase
-- [to_additive finsupp.sum] for finsupp.prod doesn't work, the equation lemmas are not generated
/-- `sum f g` is the sum of `g a (f a)` over the support of `f`. -/
def sum [has_zero β] [add_comm_monoid γ] (f : α →₀ β) (g : α → β → γ) : γ :=
f.support.sum (λa, g a (f a))
/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/
@[to_additive finsupp.sum]
def prod [has_zero β] [comm_monoid γ] (f : α →₀ β) (g : α → β → γ) : γ :=
f.support.prod (λa, g a (f a))
attribute [to_additive finsupp.sum.equations._eqn_1] finsupp.prod.equations._eqn_1
@[to_additive finsupp.sum_map_range_index]
lemma prod_map_range_index [has_zero β₁] [has_zero β₂] [comm_monoid γ] [decidable_eq β₂]
{f : β₁ → β₂} {hf : f 0 = 0} {g : α →₀ β₁} {h : α → β₂ → γ} (h0 : ∀a, h a 0 = 1) :
(map_range f hf g).prod h = g.prod (λa b, h a (f b)) :=
finset.prod_subset support_map_range $ by simp [h0] {contextual := tt}
@[to_additive finsupp.sum_zero_index]
lemma prod_zero_index [add_comm_monoid β] [comm_monoid γ] {h : α → β → γ} :
(0 : α →₀ β).prod h = 1 :=
by simp [finsupp.prod]
section decidable
variables [decidable_eq α] [decidable_eq β]
section add_monoid
variables [add_monoid β]
@[to_additive finsupp.sum_single_index]
lemma prod_single_index [comm_monoid γ] {a : α} {b : β} {h : α → β → γ} (h_zero : h a 0 = 1) :
(single a b).prod h = h a b :=
begin
by_cases h : b = 0,
{ simp [h, prod_zero_index, h_zero], refl },
{ simp [finsupp.prod, support_single_ne_zero h] }
end
instance : has_add (α →₀ β) := ⟨zip_with (+) (add_zero 0)⟩
@[simp] lemma add_apply {g₁ g₂ : α →₀ β} {a : α} : (g₁ + g₂) a = g₁ a + g₂ a :=
rfl
lemma support_add {g₁ g₂ : α →₀ β} : (g₁ + g₂).support ⊆ g₁.support ∪ g₂.support :=
support_zip_with
@[simp] lemma single_add {a : α} {b₁ b₂ : β} : single a (b₁ + b₂) = single a b₁ + single a b₂ :=
ext $ assume a',
begin
by_cases h : a = a',
{ rw [h, add_apply, single_eq_same, single_eq_same, single_eq_same] },
{ rw [add_apply, single_eq_of_ne h, single_eq_of_ne h, single_eq_of_ne h, zero_add] }
end
instance : add_monoid (α →₀ β) :=
{ add_monoid .
zero := 0,
add := (+),
add_assoc := assume ⟨s, f, hf⟩ ⟨t, g, hg⟩ ⟨u, h, hh⟩, ext $ assume a, add_assoc _ _ _,
zero_add := assume ⟨s, f, hf⟩, ext $ assume a, zero_add _,
add_zero := assume ⟨s, f, hf⟩, ext $ assume a, add_zero _ }
lemma single_add_erase {a : α} {f : α →₀ β} : single a (f a) + f.erase a = f :=
ext $ λ a',
if h : a = a' then by subst h; simp
else by simp [ne.symm h, h]
lemma erase_add_single {a : α} {f : α →₀ β} : f.erase a + single a (f a) = f :=
ext $ λ a',
if h : a = a' then by subst h; simp
else by simp [ne.symm h, h]
protected theorem induction {p : (α →₀ β) → Prop} (f : α →₀ β)
(h0 : p 0) (ha : ∀a b (f : α →₀ β), a ∉ f.support → b ≠ 0 → p f → p (single a b + f)) :
p f :=
suffices ∀s (f : α →₀ β), f.support = s → p f, from this _ _ rfl,
assume s, finset.induction_on s (by simp [h0] {contextual := tt}) $
assume a s has ih f hf,
suffices p (single a (f a) + f.erase a), by rwa [single_add_erase] at this,
begin
apply ha,
{ simp },
{ rw [← mem_support_iff _ a, hf], simp },
{ apply ih _ _,
simp [hf, has, finset.erase_insert] }
end
lemma induction₂ {p : (α →₀ β) → Prop} (f : α →₀ β)
(h0 : p 0) (ha : ∀a b (f : α →₀ β), a ∉ f.support → b ≠ 0 → p f → p (f + single a b)) :
p f :=
suffices ∀s (f : α →₀ β), f.support = s → p f, from this _ _ rfl,
assume s, finset.induction_on s (by simp [h0] {contextual := tt}) $
assume a s has ih f hf,
suffices p (f.erase a + single a (f a)), by rwa [erase_add_single] at this,
begin
apply ha,
{ simp },
{ rw [← mem_support_iff _ a, hf], simp },
{ apply ih _ _,
simp [hf, has, finset.erase_insert] }
end
end add_monoid
instance [add_comm_monoid β] : add_comm_monoid (α →₀ β) :=
{ add_comm := assume ⟨s, f, _⟩ ⟨t, g, _⟩, ext $ assume a, add_comm _ _,
.. finsupp.add_monoid }
instance [add_group β] : add_group (α →₀ β) :=
{ neg := map_range (has_neg.neg) neg_zero,
add_left_neg := assume ⟨s, f, _⟩, ext $ assume x, add_left_neg _,
.. finsupp.add_monoid }
@[to_additive finsupp.sum_neg_index]
lemma prod_neg_index [add_group β] [comm_monoid γ]
{g : α →₀ β} {h : α → β → γ} (h0 : ∀a, h a 0 = 1) :
(-g).prod h = g.prod (λa b, h a (- b)) :=
prod_map_range_index h0
@[simp] lemma neg_apply [add_group β] {g : α →₀ β} {a : α} : (- g) a = - g a := rfl
@[simp] lemma sub_apply [add_group β] {g₁ g₂ : α →₀ β} {a : α} : (g₁ - g₂) a = g₁ a - g₂ a := rfl
@[simp] lemma support_neg [add_group β] {f : α →₀ β} : support (-f) = support f :=
finset.subset.antisymm
support_map_range
(calc support f = support (- (- f)) : by simp
... ⊆ support (- f) : support_map_range)
instance [add_comm_group β] : add_comm_group (α →₀ β) :=
{ add_comm := add_comm, ..finsupp.add_group }
@[simp] lemma sum_apply [has_zero β₁] [add_comm_monoid β]
{f : α₁ →₀ β₁} {g : α₁ → β₁ → α →₀ β} {a₂ : α} :
(f.sum g) a₂ = f.sum (λa₁ b, g a₁ b a₂) :=
(finset.sum_hom (λf : α →₀ β, f a₂) rfl (assume a b, rfl)).symm
lemma support_sum [has_zero β₁] [add_comm_monoid β]
{f : α₁ →₀ β₁} {g : α₁ → β₁ → (α →₀ β)} :
(f.sum g).support ⊆ f.support.bind (λa, (g a (f a)).support) :=
have ∀a₁ : α, f.sum (λ (a : α₁) (b : β₁), (g a b) a₁) ≠ 0 →
(∃ (a : α₁), f a ≠ 0 ∧ ¬ (g a (f a)) a₁ = 0),
from assume a₁ h,
let ⟨a, ha, ne⟩ := finset.exists_ne_zero_of_sum_ne_zero h in
⟨a, (f.mem_support_iff a).mp ha, ne⟩,
by simpa [finset.subset_iff, mem_support_iff, finset.mem_bind, sum_apply] using this
@[simp] lemma sum_zero {γ : Type w} [add_comm_monoid β] [add_comm_monoid γ] {f : α →₀ β} :
f.sum (λa b, (0 : γ)) = 0 :=
finset.sum_const_zero
@[simp] lemma sum_add {γ : Type w} [add_comm_monoid β] [add_comm_monoid γ] {f : α →₀ β}
{h₁ h₂ : α → β → γ} :
f.sum (λa b, h₁ a b + h₂ a b) = f.sum h₁ + f.sum h₂ :=
finset.sum_add_distrib
@[simp] lemma sum_neg {γ : Type w} [add_comm_monoid β] [add_comm_group γ] {f : α →₀ β}
{h : α → β → γ} : f.sum (λa b, - h a b) = - f.sum h :=
finset.sum_hom (@has_neg.neg γ _) neg_zero (assume a b, neg_add _ _)
@[simp] lemma sum_single [add_comm_monoid β] {f : α →₀ β} :
f.sum single = f :=
have ∀a:α, f.sum (λa' b, ite (a' = a) b 0) =
({a} : finset α).sum (λa', ite (a' = a) (f a') 0),
begin
intro a,
by_cases h : a ∈ f.support,
{ have : (finset.singleton a : finset α) ⊆ f.support,
{ simp [finset.subset_iff, *] at * },
refine (finset.sum_subset this _).symm,
simp {contextual := tt} },
{ transitivity (f.support.sum (λa, (0 : β))),
{ refine (finset.sum_congr rfl _),
intros a' ha',
have h: a' ≠ a,
{ assume eq, simp * at * },
simp * at * },
{ simp * at * } }
end,
ext $ assume a, by simp [single_apply, this]
@[to_additive finsupp.sum_add_index]
lemma prod_add_index {γ : Type w} [add_comm_monoid β] [comm_monoid γ] {f g : α →₀ β}
{h : α → β → γ} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :
(f + g).prod h = f.prod h * g.prod h :=
have f_eq : (f.support ∪ g.support).prod (λa, h a (f a)) = f.prod h,
from (finset.prod_subset finset.subset_union_left $
by simp [mem_support_iff, h_zero] {contextual := tt}).symm,
have g_eq : (f.support ∪ g.support).prod (λa, h a (g a)) = g.prod h,
from (finset.prod_subset finset.subset_union_right $
by simp [mem_support_iff, h_zero] {contextual := tt}).symm,
calc (f + g).support.prod (λa, h a ((f + g) a)) =
(f.support ∪ g.support).prod (λa, h a ((f + g) a)) :
finset.prod_subset support_add $
by simp [mem_support_iff, h_zero] {contextual := tt}
... = (f.support ∪ g.support).prod (λa, h a (f a)) *
(f.support ∪ g.support).prod (λa, h a (g a)) :
by simp [h_add, finset.prod_mul_distrib]
... = _ : by rw [f_eq, g_eq]
lemma sum_sub_index {γ : Type w} [add_comm_group β] [add_comm_group γ] {f g : α →₀ β}
{h : α → β → γ} (h_sub : ∀a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) :
(f - g).sum h = f.sum h - g.sum h :=
have h_zero : ∀a, h a 0 = 0,
from assume a,
have h a (0 - 0) = h a 0 - h a 0, from h_sub a 0 0,
by simpa using this,
have h_neg : ∀a b, h a (- b) = - h a b,
from assume a b,
have h a (0 - b) = h a 0 - h a b, from h_sub a 0 b,
by simpa [h_zero] using this,
have h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ + h a b₂,
from assume a b₁ b₂,
have h a (b₁ - (- b₂)) = h a b₁ - h a (- b₂), from h_sub a b₁ (-b₂),
by simpa [h_neg] using this,
calc (f - g).sum h = (f + - g).sum h : by simp
... = f.sum h + - g.sum h : by simp [sum_add_index, sum_neg_index, h_add, h_zero, h_neg]
... = _ : by simp
@[to_additive finsupp.sum_finset_sum_index]
lemma prod_finset_sum_index {γ : Type w} {ι : Type x}
[add_comm_monoid β] [comm_monoid γ] [decidable_eq ι]
{s : finset ι} {g : ι → α →₀ β}
{h : α → β → γ} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂):
s.prod (λi, (g i).prod h) = (s.sum g).prod h :=
finset.induction_on s
(by simp [prod_zero_index])
(by simp [prod_add_index, h_zero, h_add] {contextual := tt})
@[to_additive finsupp.sum_sum_index]
lemma prod_sum_index {γ : Type w}
[decidable_eq α₁] [add_comm_monoid β₁] [add_comm_monoid β] [comm_monoid γ]
{f : α₁ →₀ β₁} {g : α₁ → β₁ → α →₀ β}
{h : α → β → γ} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂):
(f.sum g).prod h = f.prod (λa b, (g a b).prod h) :=
(prod_finset_sum_index h_zero h_add).symm
section map_domain
variables [decidable_eq α₁] [decidable_eq α₂] [add_comm_monoid β] {v v₁ v₂ : α →₀ β}
/-- Given `f : α₁ → α₂` and `v : α₁ →₀ β`, `map_domain f v : α₂ →₀ β`
is the finitely supported function whose value at `a : α₂` is the sum
of `v x` over all `x` such that `f x = a`. -/
def map_domain (f : α₁ → α₂) (v : α₁ →₀ β) : α₂ →₀ β :=
v.sum $ λa, single (f a)
lemma map_domain_id : map_domain id v = v :=
sum_single
lemma map_domain_comp {f : α → α₁} {g : α₁ → α₂} :
map_domain (g ∘ f) v = map_domain g (map_domain f v) :=
by simp [map_domain, sum_sum_index, sum_single_index]
lemma map_domain_single {f : α → α₁} {a : α} {b : β} : map_domain f (single a b) = single (f a) b :=
sum_single_index (by simp)
lemma map_domain_zero {f : α → α₂} : map_domain f 0 = (0 : α₂ →₀ β) :=
sum_zero_index
lemma map_domain_congr {f g : α → α₂} (h : ∀x∈v.support, f x = g x) :
v.map_domain f = v.map_domain g :=
finset.sum_congr rfl $ by simp [*] at * {contextual := tt}
lemma map_domain_add {f : α → α₂} : map_domain f (v₁ + v₂) = map_domain f v₁ + map_domain f v₂ :=
sum_add_index (by simp) (by simp)
lemma map_domain_finset_sum {ι : Type x} [decidable_eq ι]
{f : α → α₂} {s : finset ι} {v : ι → α →₀ β} :
map_domain f (s.sum v) = s.sum (λi, map_domain f (v i)) :=
by refine (sum_finset_sum_index _ _).symm; simp
lemma map_domain_sum [has_zero β₁] {f : α → α₂} {s : α →₀ β₁} {v : α → β₁ → α →₀ β} :
map_domain f (s.sum v) = s.sum (λa b, map_domain f (v a b)) :=
by refine (sum_finset_sum_index _ _).symm; simp
lemma map_domain_support {f : α → α₂} {s : α →₀ β} :
(s.map_domain f).support ⊆ s.support.image f :=
finset.subset.trans support_sum $
finset.subset.trans (finset.bind_mono $ assume a ha, support_single_subset) $
by rw [finset.bind_singleton]; exact subset.refl _
@[to_additive finsupp.sum_map_domain_index]
lemma prod_map_domain_index {γ : Type w} [comm_monoid γ] {f : α → α₂} {s : α →₀ β}
{h : α₂ → β → γ} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :
(s.map_domain f).prod h = s.prod (λa b, h (f a) b) :=
by simp [map_domain, prod_sum_index, h_zero, h_add, prod_single_index]
end map_domain
/-- The product of `f g : α →₀ β` is the finitely supported function
whose value at `a` is the sum of `f x * g y` over all pairs `x, y`
such that `x + y = a`. (Think of the product of multivariate
polynomials where `α` is the monoid of monomial exponents.) -/
instance [has_add α] [semiring β] : has_mul (α →₀ β) :=
⟨λf g, f.sum $ λa₁ b₁, g.sum $ λa₂ b₂, single (a₁ + a₂) (b₁ * b₂)⟩
lemma mul_def [has_add α] [semiring β] {f g : α →₀ β} :
f * g = (f.sum $ λa₁ b₁, g.sum $ λa₂ b₂, single (a₁ + a₂) (b₁ * b₂)) := rfl
/-- The unit of the multiplication is `single 0 1`, i.e. the function
that is 1 at 0 and zero elsewhere. -/
instance [has_zero α] [has_zero β] [has_one β] : has_one (α →₀ β) :=
⟨single 0 1⟩
lemma one_def [has_zero α] [has_zero β] [has_one β] : 1 = (single 0 1 : α →₀ β) := rfl
section filter -- TODO: remove filter? build upon subtype_domain?
section has_zero
variables [has_zero β] {p : α → Prop} [decidable_pred p] {f : α →₀ β}
/-- `filter p f` is the function which is `f a` if `p a` is true and 0 otherwise. -/
def filter (p : α → Prop) [decidable_pred p] (f : α →₀ β) : α →₀ β :=
on_finset f.support (λa, if p a then f a else 0) (assume a, by by_cases (p a); simp [h])
@[simp] lemma filter_apply_pos {a : α} (h : p a) : f.filter p a = f a :=
if_pos h
@[simp] lemma filter_apply_neg {a : α} (h : ¬ p a) : f.filter p a = 0 :=
if_neg h
@[simp] lemma support_filter : (f.filter p).support = f.support.filter p :=
finset.ext.mpr $ assume a, by by_cases p a; simp *
end has_zero
lemma filter_pos_add_filter_neg [add_monoid β] {f : α →₀ β} {p : α → Prop}
[decidable_pred p] [decidable_pred (λa, ¬ p a)] :
f.filter p + f.filter (λa, ¬ p a) = f :=
finsupp.ext $ assume a, by by_cases p a; simp *
end filter
section subtype_domain
variables {α' : Type u₁} {δ : Type y} [has_zero δ] {p : α → Prop} [decidable_pred p]
section zero
variables [has_zero β] {v v' : α' →₀ β}
/-- `subtype_domain p f` is the restriction of the finitely supported function
`f` to the subtype `p`. -/
def subtype_domain (p : α → Prop) [decidable_pred p] (f : α →₀ β) : (subtype p →₀ β) :=
⟨f.support.subtype p, f ∘ subtype.val, by simp⟩
@[simp] lemma support_subtype_domain {f : α →₀ β} :
(subtype_domain p f).support = f.support.subtype p :=
rfl
@[simp] lemma subtype_domain_apply {a : subtype p} {v : α →₀ β} :
(subtype_domain p v) a = v (a.val) :=
rfl
@[simp] lemma subtype_domain_zero : subtype_domain p (0 : α →₀ β) = 0 :=
rfl
@[to_additive finsupp.sum_subtype_domain_index]
lemma prod_subtype_domain_index [comm_monoid γ] {v : α →₀ β}
{h : α → β → γ} (hp : ∀x∈v.support, p x) :
(v.subtype_domain p).prod (λa b, h a.1 b) = v.prod h :=
prod_bij (λp _, p.val)
(by simp)
(by simp)
(assume ⟨a₀, ha₀⟩ ⟨a₁, ha₁⟩, by simp)
(begin simp; exact assume b hb, ⟨b, hp _ (by simp [hb]), by simp [hb]⟩ end)
end zero
section monoid
variables [add_monoid β] {v v' : α' →₀ β}
@[simp] lemma subtype_domain_add {v v' : α →₀ β} :
(v + v').subtype_domain p = v.subtype_domain p + v'.subtype_domain p :=
ext $ by simp
end monoid
section comm_monoid
variables [add_comm_monoid β]
lemma subtype_domain_sum {s : finset γ} {h : γ → α →₀ β} :
(s.sum h).subtype_domain p = s.sum (λc, (h c).subtype_domain p) :=
eq.symm (finset.sum_hom _ subtype_domain_zero $ assume v v', subtype_domain_add)
lemma subtype_domain_finsupp_sum {s : γ →₀ δ} {h : γ → δ → α →₀ β} :
(s.sum h).subtype_domain p = s.sum (λc d, (h c d).subtype_domain p) :=
subtype_domain_sum
end comm_monoid
section group
variables [add_group β] {v v' : α' →₀ β}
@[simp] lemma subtype_domain_neg {v : α →₀ β} :
(- v).subtype_domain p = - v.subtype_domain p :=
ext $ by simp
@[simp] lemma subtype_domain_sub {v v' : α →₀ β} :
(v - v').subtype_domain p = v.subtype_domain p - v'.subtype_domain p :=
ext $ by simp
end group
end subtype_domain
section
variables [add_monoid α] [semiring β]
-- TODO: the simplifier unfolds 0 in the instance proof!
private lemma zero_mul (f : α →₀ β) : 0 * f = 0 := by simp [mul_def, sum_zero_index]
private lemma mul_zero (f : α →₀ β) : f * 0 = 0 := by simp [mul_def, sum_zero_index]
private lemma left_distrib (a b c : α →₀ β) : a * (b + c) = a * b + a * c :=
by simp [mul_def, sum_add_index, mul_add]
private lemma right_distrib (a b c : α →₀ β) : (a + b) * c = a * c + b * c :=
by simp [mul_def, sum_add_index, add_mul]
def to_semiring : semiring (α →₀ β) :=
{ one := 1,
mul := (*),
one_mul := assume f, by simp [mul_def, one_def, sum_single_index],
mul_one := assume f, by simp [mul_def, one_def, sum_single_index],
zero_mul := zero_mul,
mul_zero := mul_zero,
mul_assoc := assume f g h,
by simp [mul_def, sum_sum_index, sum_zero_index, sum_add_index, sum_single_index,
add_mul, mul_add, mul_assoc],
left_distrib := left_distrib,
right_distrib := right_distrib,
.. finsupp.add_comm_monoid }
end
local attribute [instance] to_semiring
def to_comm_semiring [add_comm_monoid α] [comm_semiring β] : comm_semiring (α →₀ β) :=
{ mul_comm := assume f g,
begin
simp [mul_def, finsupp.sum, mul_comm],
rw [finset.sum_comm],
simp
end,
.. finsupp.to_semiring }
local attribute [instance] to_comm_semiring
def to_ring [add_monoid α] [ring β] : ring (α →₀ β) :=
{ neg := has_neg.neg,
add_left_neg := add_left_neg,
.. finsupp.to_semiring }
def to_comm_ring [add_comm_monoid α] [comm_ring β] : comm_ring (α →₀ β) :=
{ mul_comm := mul_comm, .. finsupp.to_ring}
lemma single_mul_single [has_add α] [semiring β] {a₁ a₂ : α} {b₁ b₂ : β}:
single a₁ b₁ * single a₂ b₂ = single (a₁ + a₂) (b₁ * b₂) :=
by simp [mul_def, sum_single_index]
lemma prod_single {ι : Type x} [decidable_eq ι] [add_comm_monoid α] [comm_semiring β]
{s : finset ι} {a : ι → α} {b : ι → β} :
s.prod (λi, single (a i) (b i)) = single (s.sum a) (s.prod b) :=
finset.induction_on s (by simp [one_def]) (by simp [single_mul_single] {contextual := tt})
def to_has_scalar [semiring β] : has_scalar β (α →₀ β) := ⟨λa v, v.map_range ((*) a) (mul_zero a)⟩
local attribute [instance] to_has_scalar
@[simp] lemma smul_apply [semiring β] {a : α} {b : β} {v : α →₀ β} :
(b • v) a = b * v a := rfl
/- should this be stronger? [module γ β] → module γ (α →₀ β) -/
def to_module [ring β] : module β (α →₀ β) :=
{ smul := (•),
smul_add := assume a x y, finsupp.ext $ by simp [mul_add],
add_smul := assume a x y, finsupp.ext $ by simp [add_mul],
one_smul := assume x, finsupp.ext $ by simp,
mul_smul := assume r s x, finsupp.ext $ by simp [mul_assoc],
.. finsupp.add_comm_group }
lemma sum_smul_index [ring β] [add_comm_monoid γ] {g : α →₀ β} {b : β} {h : α → β → γ}
(h0 : ∀i, h i 0 = 0) : (b • g).sum h = g.sum (λi a, h i (b * a)) :=
finsupp.sum_map_range_index h0
end decidable
section
variables [semiring β] [semiring γ]
lemma sum_mul (b : γ) (s : α →₀ β) {f : α → β → γ} :
(s.sum f) * b = s.sum (λ a c, (f a (s a)) * b) :=
by simp [finsupp.sum, finset.sum_mul]
lemma mul_sum [semiring β] [semiring γ] (b : γ) (s : α →₀ β) {f : α → β → γ} :
b * (s.sum f) = s.sum (λ a c, b * (f a (s a))) :=
by simp [finsupp.sum, finset.mul_sum]
end
end finsupp
|
39ef9e5785437c2763b5aa964135cdd4aecafb04 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/group_theory/perm/subgroup.lean | 6bfaa6fafde50313eb42e14cb3cfe25bc2b47844 | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 3,158 | lean | /-
Copyright (c) 2020 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import group_theory.perm.basic
import data.fintype.perm
import group_theory.subgroup.basic
/-!
# Lemmas about subgroups within the permutations (self-equivalences) of a type `α`
This file provides extra lemmas about some `subgroup`s that exist within `equiv.perm α`.
`group_theory.subgroup` depends on `group_theory.perm.basic`, so these need to be in a separate
file.
It also provides decidable instances on membership in these subgroups, since
`monoid_hom.decidable_mem_range` cannot be inferred without the help of a lambda.
The presence of these instances induces a `fintype` instance on the `quotient_group.quotient` of
these subgroups.
-/
namespace equiv
namespace perm
universes u
instance sum_congr_hom.decidable_mem_range {α β : Type*}
[decidable_eq α] [decidable_eq β] [fintype α] [fintype β] :
decidable_pred (∈ (sum_congr_hom α β).range) :=
λ x, infer_instance
@[simp]
lemma sum_congr_hom.card_range {α β : Type*}
[fintype (sum_congr_hom α β).range] [fintype (perm α × perm β)] :
fintype.card (sum_congr_hom α β).range = fintype.card (perm α × perm β) :=
fintype.card_eq.mpr ⟨(of_injective (sum_congr_hom α β) sum_congr_hom_injective).symm⟩
instance sigma_congr_right_hom.decidable_mem_range {α : Type*} {β : α → Type*}
[decidable_eq α] [∀ a, decidable_eq (β a)] [fintype α] [∀ a, fintype (β a)] :
decidable_pred (∈ (sigma_congr_right_hom β).range) :=
λ x, infer_instance
@[simp]
lemma sigma_congr_right_hom.card_range {α : Type*} {β : α → Type*}
[fintype (sigma_congr_right_hom β).range] [fintype (Π a, perm (β a))] :
fintype.card (sigma_congr_right_hom β).range = fintype.card (Π a, perm (β a)) :=
fintype.card_eq.mpr ⟨(of_injective (sigma_congr_right_hom β) sigma_congr_right_hom_injective).symm⟩
instance subtype_congr_hom.decidable_mem_range {α : Type*} (p : α → Prop) [decidable_pred p]
[fintype (perm {a // p a} × perm {a // ¬ p a})] [decidable_eq (perm α)] :
decidable_pred (∈ (subtype_congr_hom p).range) :=
λ x, infer_instance
@[simp]
lemma subtype_congr_hom.card_range {α : Type*} (p : α → Prop) [decidable_pred p]
[fintype (subtype_congr_hom p).range] [fintype (perm {a // p a} × perm {a // ¬ p a})] :
fintype.card (subtype_congr_hom p).range = fintype.card (perm {a // p a} × perm {a // ¬ p a}) :=
fintype.card_eq.mpr ⟨(of_injective (subtype_congr_hom p) (subtype_congr_hom_injective p)).symm⟩
/-- **Cayley's theorem**: Every group G is isomorphic to a subgroup of the symmetric group acting on
`G`. Note that we generalize this to an arbitrary "faithful" group action by `G`. Setting `H = G`
recovers the usual statement of Cayley's theorem via `right_cancel_monoid.to_has_faithful_smul` -/
noncomputable def subgroup_of_mul_action (G H : Type*) [group G] [mul_action G H]
[has_faithful_smul G H] : G ≃* (mul_action.to_perm_hom G H).range :=
mul_equiv.of_left_inverse' _ (classical.some_spec mul_action.to_perm_injective.has_left_inverse)
end perm
end equiv
|
58b57d786349ca0772b75652fa2d4e3219c525ef | dd0f5513e11c52db157d2fcc8456d9401a6cd9da | /12_Axioms.org.26.lean | 3e7e32ca1e3d19933ba39e5a1fcc0ebcbf3d89e6 | [] | 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 | 1,240 | lean | import standard
import logic.eq
open classical eq.ops
section
parameter p : Prop
definition U (x : Prop) : Prop := x = true ∨ p
definition V (x : Prop) : Prop := x = false ∨ p
noncomputable definition u := epsilon U
noncomputable definition v := epsilon V
lemma u_def : U u :=
epsilon_spec (exists.intro true (or.inl rfl))
lemma v_def : V v :=
epsilon_spec (exists.intro false (or.inl rfl))
lemma not_uv_or_p : ¬(u = v) ∨ p :=
or.elim u_def
(assume Hut : u = true,
or.elim v_def
(assume Hvf : v = false,
have Hne : ¬(u = v), from Hvf⁻¹ ▸ Hut⁻¹ ▸ true_ne_false,
or.inl Hne)
(assume Hp : p, or.inr Hp))
(assume Hp : p, or.inr Hp)
lemma p_implies_uv : p → u = v :=
assume Hp : p,
have Hpred : U = V, from
funext (take x : Prop,
have Hl : (x = true ∨ p) → (x = false ∨ p), from
assume A, or.inr Hp,
have Hr : (x = false ∨ p) → (x = true ∨ p), from
assume A, or.inr Hp,
show (x = true ∨ p) = (x = false ∨ p), from
propext (iff.intro Hl Hr)),
have H' : epsilon U = epsilon V, from Hpred ▸ rfl,
show u = v, from H'
-- BEGIN
theorem EM : p ∨ ¬p :=
have H : ¬(u = v) → ¬p, from mt p_implies_uv,
or.elim not_uv_or_p
(assume Hne : ¬(u = v), or.inr (H Hne))
(assume Hp : p, or.inl Hp)
-- END
end
|
c186fcf7ed62f31a878f243ff0fc71bc4001e54d | 31f556cdeb9239ffc2fad8f905e33987ff4feab9 | /src/Lean/Linter/Util.lean | 0bf9bd054abbc173382540a4206979db91daa76d | [
"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 | tobiasgrosser/lean4 | ce0fd9cca0feba1100656679bf41f0bffdbabb71 | ebdbdc10436a4d9d6b66acf78aae7a23f5bd073f | refs/heads/master | 1,673,103,412,948 | 1,664,930,501,000 | 1,664,930,501,000 | 186,870,185 | 0 | 0 | Apache-2.0 | 1,665,129,237,000 | 1,557,939,901,000 | Lean | UTF-8 | Lean | false | false | 2,058 | lean | import Lean.Data.Options
import Lean.Elab.Command
import Lean.Server.InfoUtils
namespace Lean.Linter
register_builtin_option linter.all : Bool := {
defValue := false
descr := "enable all linters"
}
def getLinterAll (o : Options) (defValue := linter.all.defValue) : Bool := o.get linter.all.name defValue
def getLinterValue (opt : Lean.Option Bool) (o : Options) : Bool := o.get opt.name (getLinterAll o opt.defValue)
open Lean.Elab Lean.Elab.Command
def logLint (linterOption : Lean.Option Bool) (stx : Syntax) (msg : MessageData) : CommandElabM Unit :=
logWarningAt stx (.tagged linterOption.name m!"{msg} [{linterOption.name}]")
/-- Go upwards through the given `tree` starting from the smallest node that
contains the given `range` and collect all `MacroExpansionInfo`s on the way up.
The result is `some []` if no `MacroExpansionInfo` was found on the way and
`none` if no `InfoTree` node was found that covers the given `range`.
Return the result reversed, s.t. the macro expansion that would be applied to
the original syntax first is the first element of the returned list. -/
def collectMacroExpansions? {m} [Monad m] (range : String.Range) (tree : Elab.InfoTree) : m <| Option <| List Elab.MacroExpansionInfo := do
if let .some <| .some result ← go then
return some result.reverse
else
return none
where
go : m <| Option <| Option <| List Elab.MacroExpansionInfo := tree.visitM (postNode := fun _ i _ results => do
let results := results |>.filterMap id |>.filterMap id
-- we expect that at most one InfoTree child returns a result
if let results :: _ := results then
if let .ofMacroExpansionInfo i := i then
return some <| i :: results
else
return some results
else if i.contains range.start && i.contains (includeStop := true) range.stop then
if let .ofMacroExpansionInfo i := i then
return some [i]
else
return some []
else
return none)
abbrev IgnoreFunction := Syntax → Syntax.Stack → Options → Bool
end Lean.Linter
|
d28d32fd736a85d87556001b6b7d1e9b5262385a | dd0f5513e11c52db157d2fcc8456d9401a6cd9da | /06_Inductive_Types.org.4.lean | 0c04c853936e3bc4aae154b6c8fe306503dd2bd1 | [] | 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 | 324 | lean | /- page 78 -/
import standard
import data.nat
open nat
inductive weekday : Type :=
| sunday : weekday
| monday : weekday
| tuesday : weekday
| wednesday : weekday
| thursday : weekday
| friday : weekday
| saturday : weekday
-- BEGIN
definition number_of_day (d : weekday) : nat :=
weekday.cases_on d 1 2 3 4 5 6 7
-- END
|
a925ea31ef9b7b2afca339ea74a089534f3112b9 | 86f6f4f8d827a196a32bfc646234b73328aeb306 | /examples/basics/unnamed_370.lean | a4199f728e6ed221d985a8b13d438736ac0386cc | [] | 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 | 133 | lean | import data.real.basic
variables a b c d : ℝ
-- BEGIN
example : (a + b) * (c + d) = a * c + a * d + b * c + b * d :=
sorry
-- END |
620dd24830766cd3a29f45ddcbe2348f97701956 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/induction_naming2.lean | b8268a2a205428e584a3c2c5a03fd03f6d053234 | [
"Apache-2.0"
] | permissive | leanprover-community/lean | 12b87f69d92e614daea8bcc9d4de9a9ace089d0e | cce7990ea86a78bdb383e38ed7f9b5ba93c60ce0 | refs/heads/master | 1,687,508,156,644 | 1,684,951,104,000 | 1,684,951,104,000 | 169,960,991 | 457 | 107 | Apache-2.0 | 1,686,744,372,000 | 1,549,790,268,000 | C++ | UTF-8 | Lean | false | false | 208 | lean | inductive tree
| leaf : tree
| node (left : tree) (val : nat) (right : tree) : tree
constant foo : tree → tree
example (a : tree) : foo a = a :=
begin
induction a,
trace_state,
repeat { admit }
end
|
a31aa110782dadb51f6ddea68e39a41d00cb8164 | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/order/filter/ultrafilter.lean | 12ad2389738b342e94dd3bfe607d4de3bbe57320 | [
"Apache-2.0"
] | permissive | ramonfmir/mathlib | c5dc8b33155473fab97c38bd3aa6723dc289beaa | 14c52e990c17f5a00c0cc9e09847af16fabbed25 | refs/heads/master | 1,661,979,343,526 | 1,660,830,384,000 | 1,660,830,384,000 | 182,072,989 | 0 | 0 | null | 1,555,585,876,000 | 1,555,585,876,000 | null | UTF-8 | Lean | false | false | 16,728 | 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, Jeremy Avigad, Yury Kudryashov
-/
import order.filter.cofinite
import order.zorn
/-!
# Ultrafilters
An ultrafilter is a minimal (maximal in the set order) proper filter.
In this file we define
* `ultrafilter.of`: an ultrafilter that is less than or equal to a given filter;
* `ultrafilter`: subtype of ultrafilters;
* `ultrafilter.pure`: `pure x` as an `ultrafiler`;
* `ultrafilter.map`, `ultrafilter.bind`, `ultrafilter.comap` : operations on ultrafilters;
* `hyperfilter`: the ultrafilter extending the cofinite filter.
-/
universes u v
variables {α : Type u} {β : Type v} {γ : Type*}
open set filter function
open_locale classical filter
/-- An ultrafilter is a minimal (maximal in the set order) proper filter. -/
@[protect_proj]
structure ultrafilter (α : Type*) extends filter α :=
(ne_bot' : ne_bot to_filter)
(le_of_le : ∀ g, filter.ne_bot g → g ≤ to_filter → to_filter ≤ g)
namespace ultrafilter
variables {f g : ultrafilter α} {s t : set α} {p q : α → Prop}
instance : has_coe_t (ultrafilter α) (filter α) := ⟨ultrafilter.to_filter⟩
instance : has_mem (set α) (ultrafilter α) := ⟨λ s f, s ∈ (f : filter α)⟩
lemma unique (f : ultrafilter α) {g : filter α} (h : g ≤ f)
(hne : ne_bot g . tactic.apply_instance) : g = f :=
le_antisymm h $ f.le_of_le g hne h
instance ne_bot (f : ultrafilter α) : ne_bot (f : filter α) := f.ne_bot'
@[simp, norm_cast] lemma mem_coe : s ∈ (f : filter α) ↔ s ∈ f := iff.rfl
lemma coe_injective : injective (coe : ultrafilter α → filter α)
| ⟨f, h₁, h₂⟩ ⟨g, h₃, h₄⟩ rfl := by congr
lemma eq_of_le {f g : ultrafilter α} (h : (f : filter α) ≤ g) : f = g :=
coe_injective (g.unique h)
@[simp, norm_cast] lemma coe_le_coe {f g : ultrafilter α} : (f : filter α) ≤ g ↔ f = g :=
⟨λ h, eq_of_le h, λ h, h ▸ le_rfl⟩
@[simp, norm_cast] lemma coe_inj : (f : filter α) = g ↔ f = g := coe_injective.eq_iff
@[ext] lemma ext ⦃f g : ultrafilter α⦄ (h : ∀ s, s ∈ f ↔ s ∈ g) : f = g :=
coe_injective $ filter.ext h
lemma le_of_inf_ne_bot (f : ultrafilter α) {g : filter α} (hg : ne_bot (↑f ⊓ g)) : ↑f ≤ g :=
le_of_inf_eq (f.unique inf_le_left hg)
lemma le_of_inf_ne_bot' (f : ultrafilter α) {g : filter α} (hg : ne_bot (g ⊓ f)) : ↑f ≤ g :=
f.le_of_inf_ne_bot $ by rwa inf_comm
@[simp] lemma compl_not_mem_iff : sᶜ ∉ f ↔ s ∈ f :=
⟨λ hsc, le_principal_iff.1 $ f.le_of_inf_ne_bot
⟨λ h, hsc $ mem_of_eq_bot$ by rwa compl_compl⟩, compl_not_mem⟩
@[simp] lemma frequently_iff_eventually : (∃ᶠ x in f, p x) ↔ ∀ᶠ x in f, p x :=
compl_not_mem_iff
alias frequently_iff_eventually ↔ _root_.filter.frequently.eventually _
lemma compl_mem_iff_not_mem : sᶜ ∈ f ↔ s ∉ f := by rw [← compl_not_mem_iff, compl_compl]
lemma diff_mem_iff (f : ultrafilter α) : s \ t ∈ f ↔ s ∈ f ∧ t ∉ f :=
inter_mem_iff.trans $ and_congr iff.rfl compl_mem_iff_not_mem
/-- If `sᶜ ∉ f ↔ s ∈ f`, then `f` is an ultrafilter. The other implication is given by
`ultrafilter.compl_not_mem_iff`. -/
def of_compl_not_mem_iff (f : filter α) (h : ∀ s, sᶜ ∉ f ↔ s ∈ f) : ultrafilter α :=
{ to_filter := f,
ne_bot' := ⟨λ hf, by simpa [hf] using h⟩,
le_of_le := λ g hg hgf s hs, (h s).1 $ λ hsc, by exactI compl_not_mem hs (hgf hsc) }
lemma nonempty_of_mem (hs : s ∈ f) : s.nonempty := nonempty_of_mem hs
lemma ne_empty_of_mem (hs : s ∈ f) : s ≠ ∅ := (nonempty_of_mem hs).ne_empty
@[simp] lemma empty_not_mem : ∅ ∉ f := empty_not_mem f
lemma mem_or_compl_mem (f : ultrafilter α) (s : set α) : s ∈ f ∨ sᶜ ∈ f :=
or_iff_not_imp_left.2 compl_mem_iff_not_mem.2
protected lemma em (f : ultrafilter α) (p : α → Prop) :
(∀ᶠ x in f, p x) ∨ ∀ᶠ x in f, ¬p x :=
f.mem_or_compl_mem {x | p x}
lemma eventually_or : (∀ᶠ x in f, p x ∨ q x) ↔ (∀ᶠ x in f, p x) ∨ ∀ᶠ x in f, q x :=
⟨λ H, (f.em p).imp_right $ λ hp, (H.and hp).mono $ λ x ⟨hx, hnx⟩, hx.resolve_left hnx,
λ H, H.elim (λ hp, hp.mono $ λ x, or.inl) (λ hp, hp.mono $ λ x, or.inr)⟩
lemma union_mem_iff : s ∪ t ∈ f ↔ s ∈ f ∨ t ∈ f := eventually_or
lemma eventually_not : (∀ᶠ x in f, ¬p x) ↔ ¬∀ᶠ x in f, p x := compl_mem_iff_not_mem
lemma eventually_imp : (∀ᶠ x in f, p x → q x) ↔ (∀ᶠ x in f, p x) → ∀ᶠ x in f, q x :=
by simp only [imp_iff_not_or, eventually_or, eventually_not]
lemma finite_sUnion_mem_iff {s : set (set α)} (hs : s.finite) : ⋃₀ s ∈ f ↔ ∃t∈s, t ∈ f :=
finite.induction_on hs (by simp) $ λ a s ha hs his,
by simp [union_mem_iff, his, or_and_distrib_right, exists_or_distrib]
lemma finite_bUnion_mem_iff {is : set β} {s : β → set α} (his : is.finite) :
(⋃i∈is, s i) ∈ f ↔ ∃i∈is, s i ∈ f :=
by simp only [← sUnion_image, finite_sUnion_mem_iff (his.image s), bex_image_iff]
/-- Pushforward for ultrafilters. -/
def map (m : α → β) (f : ultrafilter α) : ultrafilter β :=
of_compl_not_mem_iff (map m f) $ λ s, @compl_not_mem_iff _ f (m ⁻¹' s)
@[simp, norm_cast] lemma coe_map (m : α → β) (f : ultrafilter α) :
(map m f : filter β) = filter.map m ↑f := rfl
@[simp] lemma mem_map {m : α → β} {f : ultrafilter α} {s : set β} :
s ∈ map m f ↔ m ⁻¹' s ∈ f := iff.rfl
@[simp] lemma map_id (f : ultrafilter α) : f.map id = f := coe_injective map_id
@[simp] lemma map_id' (f : ultrafilter α) : f.map (λ x, x) = f := map_id _
@[simp] lemma map_map (f : ultrafilter α) (m : α → β) (n : β → γ) :
(f.map m).map n = f.map (n ∘ m) :=
coe_injective map_map
/-- The pullback of an ultrafilter along an injection whose range is large with respect to the given
ultrafilter. -/
def comap {m : α → β} (u : ultrafilter β) (inj : injective m)
(large : set.range m ∈ u) : ultrafilter α :=
{ to_filter := comap m u,
ne_bot' := u.ne_bot'.comap_of_range_mem large,
le_of_le := λ g hg hgu, by { resetI,
simp only [← u.unique (map_le_iff_le_comap.2 hgu), comap_map inj, le_rfl] } }
@[simp] lemma mem_comap {m : α → β} (u : ultrafilter β) (inj : injective m)
(large : set.range m ∈ u) {s : set α} :
s ∈ u.comap inj large ↔ m '' s ∈ u :=
mem_comap_iff inj large
@[simp, norm_cast] lemma coe_comap {m : α → β} (u : ultrafilter β) (inj : injective m)
(large : set.range m ∈ u) : (u.comap inj large : filter α) = filter.comap m u := rfl
@[simp] lemma comap_id (f : ultrafilter α) (h₀ : injective (id : α → α) := injective_id)
(h₁ : range id ∈ f := by { rw range_id, exact univ_mem}) :
f.comap h₀ h₁ = f :=
coe_injective comap_id
@[simp] lemma comap_comap (f : ultrafilter γ) {m : α → β} {n : β → γ} (inj₀ : injective n)
(large₀ : range n ∈ f) (inj₁ : injective m) (large₁ : range m ∈ f.comap inj₀ large₀)
(inj₂ : injective (n ∘ m) := inj₀.comp inj₁)
(large₂ : range (n ∘ m) ∈ f := by { rw range_comp, exact image_mem_of_mem_comap large₀ large₁ }) :
(f.comap inj₀ large₀).comap inj₁ large₁ = f.comap inj₂ large₂ :=
coe_injective comap_comap
/-- The principal ultrafilter associated to a point `x`. -/
instance : has_pure ultrafilter :=
⟨λ α a, of_compl_not_mem_iff (pure a) $ λ s, by simp⟩
@[simp] lemma mem_pure {a : α} {s : set α} : s ∈ (pure a : ultrafilter α) ↔ a ∈ s := iff.rfl
@[simp] lemma coe_pure (a : α) : ↑(pure a : ultrafilter α) = (pure a : filter α) := rfl
@[simp] lemma map_pure (m : α → β) (a : α) : map m (pure a) = pure (m a) := rfl
@[simp] lemma comap_pure {m : α → β} (a : α) (inj : injective m) (large) :
comap (pure $ m a) inj large = pure a :=
coe_injective $ comap_pure.trans $
by rw [coe_pure, ←principal_singleton, ←image_singleton, preimage_image_eq _ inj]
lemma pure_injective : injective (pure : α → ultrafilter α) :=
λ a b h, filter.pure_injective (congr_arg ultrafilter.to_filter h : _)
instance [inhabited α] : inhabited (ultrafilter α) := ⟨pure default⟩
instance [nonempty α] : nonempty (ultrafilter α) := nonempty.map pure infer_instance
lemma eq_pure_of_finite_mem (h : s.finite) (h' : s ∈ f) : ∃ x ∈ s, (f : filter α) = pure x :=
begin
rw ← bUnion_of_singleton s at h',
rcases (ultrafilter.finite_bUnion_mem_iff h).mp h' with ⟨a, has, haf⟩,
use [a, has],
change (f : filter α) = (pure a : ultrafilter α),
rw [ultrafilter.coe_inj, ← ultrafilter.coe_le_coe],
change (f : filter α) ≤ pure a,
rwa [← principal_singleton, le_principal_iff]
end
lemma eq_pure_of_finite [finite α] (f : ultrafilter α) : ∃ a, (f : filter α) = pure a :=
(eq_pure_of_finite_mem finite_univ univ_mem).imp $ λ a ⟨_, ha⟩, ha
/-- Monadic bind for ultrafilters, coming from the one on filters
defined in terms of map and join.-/
def bind (f : ultrafilter α) (m : α → ultrafilter β) : ultrafilter β :=
of_compl_not_mem_iff (bind ↑f (λ x, ↑(m x))) $ λ s,
by simp only [mem_bind', mem_coe, ← compl_mem_iff_not_mem, compl_set_of, compl_compl]
instance has_bind : has_bind ultrafilter := ⟨@ultrafilter.bind⟩
instance functor : functor ultrafilter := { map := @ultrafilter.map }
instance monad : monad ultrafilter := { map := @ultrafilter.map }
section
local attribute [instance] filter.monad filter.is_lawful_monad
instance is_lawful_monad : is_lawful_monad ultrafilter :=
{ id_map := assume α f, coe_injective (id_map f.1),
pure_bind := assume α β a f, coe_injective (pure_bind a (coe ∘ f)),
bind_assoc := assume α β γ f m₁ m₂, coe_injective (filter_eq rfl),
bind_pure_comp_eq_map := assume α β f x, coe_injective (bind_pure_comp_eq_map f x.1) }
end
/-- The ultrafilter lemma: Any proper filter is contained in an ultrafilter. -/
lemma exists_le (f : filter α) [h : ne_bot f] : ∃u : ultrafilter α, ↑u ≤ f :=
begin
let τ := {f' // ne_bot f' ∧ f' ≤ f},
let r : τ → τ → Prop := λt₁ t₂, t₂.val ≤ t₁.val,
haveI := nonempty_of_ne_bot f,
let top : τ := ⟨f, h, le_refl f⟩,
let sup : Π(c:set τ), is_chain r c → τ :=
λc hc, ⟨⨅a:{a:τ // a ∈ insert top c}, a.1,
infi_ne_bot_of_directed
(is_chain.directed $ hc.insert $ λ ⟨b, _, hb⟩ _ _, or.inl hb)
(assume ⟨⟨a, ha, _⟩, _⟩, ha),
infi_le_of_le ⟨top, mem_insert _ _⟩ le_rfl⟩,
have : ∀ c (hc : is_chain r c) a (ha : a ∈ c), r a (sup c hc),
from assume c hc a ha, infi_le_of_le ⟨a, mem_insert_of_mem _ ha⟩ le_rfl,
have : (∃ (u : τ), ∀ (a : τ), r u a → r a u),
from exists_maximal_of_chains_bounded (assume c hc, ⟨sup c hc, this c hc⟩)
(assume f₁ f₂ f₃ h₁ h₂, le_trans h₂ h₁),
cases this with uτ hmin,
exact ⟨⟨uτ.val, uτ.property.left, assume g hg₁ hg₂,
hmin ⟨g, hg₁, le_trans hg₂ uτ.property.right⟩ hg₂⟩, uτ.property.right⟩
end
alias exists_le ← _root_.filter.exists_ultrafilter_le
/-- Construct an ultrafilter extending a given filter.
The ultrafilter lemma is the assertion that such a filter exists;
we use the axiom of choice to pick one. -/
noncomputable def of (f : filter α) [ne_bot f] : ultrafilter α :=
classical.some (exists_le f)
lemma of_le (f : filter α) [ne_bot f] : ↑(of f) ≤ f := classical.some_spec (exists_le f)
lemma of_coe (f : ultrafilter α) : of ↑f = f :=
coe_inj.1 $ f.unique (of_le f)
lemma exists_ultrafilter_of_finite_inter_nonempty (S : set (set α))
(cond : ∀ T : finset (set α), (↑T : set (set α)) ⊆ S → (⋂₀ (↑T : set (set α))).nonempty) :
∃ F : ultrafilter α, S ⊆ F.sets :=
begin
suffices : ∃ F : filter α, ne_bot F ∧ S ⊆ F.sets,
{ rcases this with ⟨F, cond, hF⟩,
resetI,
obtain ⟨G : ultrafilter α, h1 : ↑G ≤ F⟩ := exists_le F,
exact ⟨G, λ T hT, h1 (hF hT)⟩ },
use filter.generate S,
refine ⟨_, λ T hT, filter.generate_sets.basic hT⟩,
rw ← forall_mem_nonempty_iff_ne_bot,
intros T hT,
rcases mem_generate_iff.mp hT with ⟨A, h1, h2, h3⟩,
let B := set.finite.to_finset h2,
rw (show A = ↑B, by simp) at *,
rcases cond B h1 with ⟨x, hx⟩,
exact ⟨x, h3 hx⟩,
end
end ultrafilter
namespace filter
variables {f : filter α} {s : set α} {a : α}
open ultrafilter
protected lemma ne_bot.le_pure_iff (hf : f.ne_bot) : f ≤ pure a ↔ f = pure a :=
⟨ultrafilter.unique (pure a), le_of_eq⟩
lemma mem_iff_ultrafilter : s ∈ f ↔ ∀ g : ultrafilter α, ↑g ≤ f → s ∈ g :=
begin
refine ⟨λ hf g hg, hg hf, λ H, by_contra $ λ hf, _⟩,
set g : filter ↥sᶜ := comap coe f,
haveI : ne_bot g := comap_ne_bot_iff_compl_range.2 (by simpa [compl_set_of]),
simpa using H ((of g).map coe) (map_le_iff_le_comap.mpr (of_le g))
end
lemma le_iff_ultrafilter {f₁ f₂ : filter α} : f₁ ≤ f₂ ↔ ∀ g : ultrafilter α, ↑g ≤ f₁ → ↑g ≤ f₂ :=
⟨λ h g h₁, h₁.trans h, λ h s hs, mem_iff_ultrafilter.2 $ λ g hg, h g hg hs⟩
/-- A filter equals the intersection of all the ultrafilters which contain it. -/
lemma supr_ultrafilter_le_eq (f : filter α) :
(⨆ (g : ultrafilter α) (hg : ↑g ≤ f), (g : filter α)) = f :=
eq_of_forall_ge_iff $ λ f', by simp only [supr_le_iff, ← le_iff_ultrafilter]
/-- The `tendsto` relation can be checked on ultrafilters. -/
lemma tendsto_iff_ultrafilter (f : α → β) (l₁ : filter α) (l₂ : filter β) :
tendsto f l₁ l₂ ↔ ∀ g : ultrafilter α, ↑g ≤ l₁ → tendsto f g l₂ :=
by simpa only [tendsto_iff_comap] using le_iff_ultrafilter
lemma exists_ultrafilter_iff {f : filter α} : (∃ (u : ultrafilter α), ↑u ≤ f) ↔ ne_bot f :=
⟨λ ⟨u, uf⟩, ne_bot_of_le uf, λ h, @exists_ultrafilter_le _ _ h⟩
lemma forall_ne_bot_le_iff {g : filter α} {p : filter α → Prop} (hp : monotone p) :
(∀ f : filter α, ne_bot f → f ≤ g → p f) ↔ ∀ f : ultrafilter α, ↑f ≤ g → p f :=
begin
refine ⟨λ H f hf, H f f.ne_bot hf, _⟩,
introsI H f hf hfg,
exact hp (of_le f) (H _ ((of_le f).trans hfg))
end
section hyperfilter
variables (α) [infinite α]
/-- The ultrafilter extending the cofinite filter. -/
noncomputable def hyperfilter : ultrafilter α := ultrafilter.of cofinite
variable {α}
lemma hyperfilter_le_cofinite : ↑(hyperfilter α) ≤ @cofinite α :=
ultrafilter.of_le cofinite
@[simp] lemma bot_ne_hyperfilter : (⊥ : filter α) ≠ hyperfilter α :=
(by apply_instance : ne_bot ↑(hyperfilter α)).1.symm
theorem nmem_hyperfilter_of_finite {s : set α} (hf : s.finite) : s ∉ hyperfilter α :=
λ hy, compl_not_mem hy $ hyperfilter_le_cofinite hf.compl_mem_cofinite
alias nmem_hyperfilter_of_finite ← _root_.set.finite.nmem_hyperfilter
theorem compl_mem_hyperfilter_of_finite {s : set α} (hf : set.finite s) :
sᶜ ∈ hyperfilter α :=
compl_mem_iff_not_mem.2 hf.nmem_hyperfilter
alias compl_mem_hyperfilter_of_finite ← _root_.set.finite.compl_mem_hyperfilter
theorem mem_hyperfilter_of_finite_compl {s : set α} (hf : set.finite sᶜ) :
s ∈ hyperfilter α :=
compl_compl s ▸ hf.compl_mem_hyperfilter
end hyperfilter
end filter
namespace ultrafilter
open filter
variables {m : α → β} {s : set α} {g : ultrafilter β}
lemma comap_inf_principal_ne_bot_of_image_mem (h : m '' s ∈ g) :
(filter.comap m g ⊓ 𝓟 s).ne_bot :=
filter.comap_inf_principal_ne_bot_of_image_mem g.ne_bot h
/-- Ultrafilter extending the inf of a comapped ultrafilter and a principal ultrafilter. -/
noncomputable def of_comap_inf_principal (h : m '' s ∈ g) : ultrafilter α :=
@of _ (filter.comap m g ⊓ 𝓟 s) (comap_inf_principal_ne_bot_of_image_mem h)
lemma of_comap_inf_principal_mem (h : m '' s ∈ g) : s ∈ of_comap_inf_principal h :=
begin
let f := filter.comap m g ⊓ 𝓟 s,
haveI : f.ne_bot := comap_inf_principal_ne_bot_of_image_mem h,
have : s ∈ f := mem_inf_of_right (mem_principal_self s),
exact le_def.mp (of_le _) s this
end
lemma of_comap_inf_principal_eq_of_map (h : m '' s ∈ g) :
(of_comap_inf_principal h).map m = g :=
begin
let f := filter.comap m g ⊓ 𝓟 s,
haveI : f.ne_bot := comap_inf_principal_ne_bot_of_image_mem h,
apply eq_of_le,
calc filter.map m (of f) ≤ filter.map m f : map_mono (of_le _)
... ≤ (filter.map m $ filter.comap m g) ⊓ filter.map m (𝓟 s) : map_inf_le
... = (filter.map m $ filter.comap m g) ⊓ (𝓟 $ m '' s) : by rw map_principal
... ≤ g ⊓ (𝓟 $ m '' s) : inf_le_inf_right _ map_comap_le
... = g : inf_of_le_left (le_principal_iff.mpr h)
end
end ultrafilter
|
bf10039d38fc50a0cde82443441b8259475c0510 | 367134ba5a65885e863bdc4507601606690974c1 | /src/category_theory/adjunction/mates.lean | a9a13c71ec0f3a1451b69ab2f4bb5b764bcfc547 | [
"Apache-2.0"
] | permissive | kodyvajjha/mathlib | 9bead00e90f68269a313f45f5561766cfd8d5cad | b98af5dd79e13a38d84438b850a2e8858ec21284 | refs/heads/master | 1,624,350,366,310 | 1,615,563,062,000 | 1,615,563,062,000 | 162,666,963 | 0 | 0 | Apache-2.0 | 1,545,367,651,000 | 1,545,367,651,000 | null | UTF-8 | Lean | false | false | 10,536 | lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Bhavik Mehta
-/
import category_theory.adjunction.basic
import category_theory.conj
import category_theory.yoneda
/-!
# Mate of natural transformations
This file establishes the bijection between the 2-cells
L₁ R₁
C --→ D C ←-- D
G ↓ ↗ ↓ H G ↓ ↘ ↓ H
E --→ F E ←-- F
L₂ R₂
where `L₁ ⊣ R₁` and `L₂ ⊣ R₂`, and shows that in the special case where `G,H` are identity then the
bijection preserves and reflects isomorphisms (i.e. we have bijections `(L₂ ⟶ L₁) ≃ (R₁ ⟶ R₂)`, and
if either side is an iso then the other side is as well).
On its own, this bijection is not particularly useful but it includes a number of interesting cases
as specializations.
For instance, this generalises the fact that adjunctions are unique (since if `L₁ ≅ L₂` then we
deduce `R₁ ≅ R₂`).
Another example arises from considering the square representing that a functor `H` preserves
products, in particular the morphism `HA ⨯ H- ⟶ H(A ⨯ -)`. Then provided `(A ⨯ -)` and `HA ⨯ -` have
left adjoints (for instance if the relevant categories are cartesian closed), the transferred
natural transformation is the exponential comparison morphism: `H(A ^ -) ⟶ HA ^ H-`.
Furthermore if `H` has a left adjoint `L`, this morphism is an isomorphism iff its mate
`L(HA ⨯ -) ⟶ A ⨯ L-` is an isomorphism, see
https://ncatlab.org/nlab/show/Frobenius+reciprocity#InCategoryTheory.
This also relates to Grothendieck's yoga of six operations, though this is not spelled out in
mathlib: https://ncatlab.org/nlab/show/six+operations.
-/
universes v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄
namespace category_theory
open category
variables {C : Type u₁} {D : Type u₂} [category.{v₁} C] [category.{v₂} D]
section square
variables {E : Type u₃} {F : Type u₄} [category.{v₃} E] [category.{v₄} F]
variables {G : C ⥤ E} {H : D ⥤ F} {L₁ : C ⥤ D} {R₁ : D ⥤ C} {L₂ : E ⥤ F} {R₂ : F ⥤ E}
variables (adj₁ : L₁ ⊣ R₁) (adj₂ : L₂ ⊣ R₂)
include adj₁ adj₂
/--
Suppose we have a square of functors (where the top and bottom are adjunctions `L₁ ⊣ R₁` and
`L₂ ⊣ R₂` respectively).
C ↔ D
G ↓ ↓ H
E ↔ F
Then we have a bijection between natural transformations `G ⋙ L₂ ⟶ L₁ ⋙ H` and
`R₁ ⋙ G ⟶ H ⋙ R₂`.
This can be seen as a bijection of the 2-cells:
L₁ R₁
C --→ D C ←-- D
G ↓ ↗ ↓ H G ↓ ↘ ↓ H
E --→ F E ←-- F
L₂ R₂
Note that if one of the transformations is an iso, it does not imply the other is an iso.
-/
def transfer_nat_trans : (G ⋙ L₂ ⟶ L₁ ⋙ H) ≃ (R₁ ⋙ G ⟶ H ⋙ R₂) :=
{ to_fun := λ h,
{ app := λ X, adj₂.unit.app _ ≫ R₂.map (h.app _ ≫ H.map (adj₁.counit.app _)),
naturality' := λ X Y f,
begin
dsimp,
rw [assoc, ← R₂.map_comp, assoc, ← H.map_comp, ← adj₁.counit_naturality, H.map_comp,
←functor.comp_map L₁, ←h.naturality_assoc],
simp,
end },
inv_fun := λ h,
{ app := λ X, L₂.map (G.map (adj₁.unit.app _) ≫ h.app _) ≫ adj₂.counit.app _,
naturality' := λ X Y f,
begin
dsimp,
rw [← L₂.map_comp_assoc, ← G.map_comp_assoc, ← adj₁.unit_naturality, G.map_comp_assoc,
← functor.comp_map, h.naturality],
simp,
end },
left_inv := λ h,
begin
ext X,
dsimp,
simp only [L₂.map_comp, assoc, adj₂.counit_naturality, adj₂.left_triangle_components_assoc,
←functor.comp_map G L₂, h.naturality_assoc, functor.comp_map L₁, ←H.map_comp,
adj₁.left_triangle_components],
dsimp,
simp, -- See library note [dsimp, simp].
end,
right_inv := λ h,
begin
ext X,
dsimp,
simp [-functor.comp_map, ←functor.comp_map H, functor.comp_map R₁, -nat_trans.naturality,
←h.naturality, -functor.map_comp, ←functor.map_comp_assoc G, R₂.map_comp],
end }
lemma transfer_nat_trans_counit (f : G ⋙ L₂ ⟶ L₁ ⋙ H) (Y : D) :
L₂.map ((transfer_nat_trans adj₁ adj₂ f).app _) ≫ adj₂.counit.app _ =
f.app _ ≫ H.map (adj₁.counit.app Y) :=
by { erw functor.map_comp, simp }
lemma unit_transfer_nat_trans (f : G ⋙ L₂ ⟶ L₁ ⋙ H) (X : C) :
G.map (adj₁.unit.app X) ≫ (transfer_nat_trans adj₁ adj₂ f).app _ =
adj₂.unit.app _ ≫ R₂.map (f.app _) :=
begin
dsimp [transfer_nat_trans],
rw [←adj₂.unit_naturality_assoc, ←R₂.map_comp, ← functor.comp_map G L₂, f.naturality_assoc,
functor.comp_map, ← H.map_comp],
dsimp, simp, -- See library note [dsimp, simp]
end
end square
section self
variables {L₁ L₂ L₃ : C ⥤ D} {R₁ R₂ R₃ : D ⥤ C}
variables (adj₁ : L₁ ⊣ R₁) (adj₂ : L₂ ⊣ R₂) (adj₃ : L₃ ⊣ R₃)
/--
Given two adjunctions `L₁ ⊣ R₁` and `L₂ ⊣ R₂` both between categories `C`, `D`, there is a
bijection between natural transformations `L₂ ⟶ L₁` and natural transformations `R₁ ⟶ R₂`.
This is defined as a special case of `transfer_nat_trans`, where the two "vertical" functors are
identity.
TODO: Generalise to when the two vertical functors are equivalences rather than being exactly `𝟭`.
Furthermore, this bijection preserves (and reflects) isomorphisms, i.e. a transformation is an iso
iff its image under the bijection is an iso, see eg `category_theory.transfer_nat_trans_self_iso`.
This is in contrast to the general case `transfer_nat_trans` which does not in general have this
property.
-/
def transfer_nat_trans_self : (L₂ ⟶ L₁) ≃ (R₁ ⟶ R₂) :=
calc (L₂ ⟶ L₁) ≃ _ : (iso.hom_congr L₂.left_unitor L₁.right_unitor).symm
... ≃ _ : transfer_nat_trans adj₁ adj₂
... ≃ (R₁ ⟶ R₂) : R₁.right_unitor.hom_congr R₂.left_unitor
lemma transfer_nat_trans_self_counit (f : L₂ ⟶ L₁) (X) :
L₂.map ((transfer_nat_trans_self adj₁ adj₂ f).app _) ≫ adj₂.counit.app X =
f.app _ ≫ adj₁.counit.app X :=
begin
dsimp [transfer_nat_trans_self],
rw [id_comp, comp_id],
have := transfer_nat_trans_counit adj₁ adj₂ (L₂.left_unitor.hom ≫ f ≫ L₁.right_unitor.inv) X,
dsimp at this,
rw this,
simp,
end
lemma unit_transfer_nat_trans_self (f : L₂ ⟶ L₁) (X) :
adj₁.unit.app _ ≫ (transfer_nat_trans_self adj₁ adj₂ f).app _ =
adj₂.unit.app X ≫ functor.map _ (f.app _) :=
begin
dsimp [transfer_nat_trans_self],
rw [id_comp, comp_id],
have := unit_transfer_nat_trans adj₁ adj₂ (L₂.left_unitor.hom ≫ f ≫ L₁.right_unitor.inv) X,
dsimp at this,
rw this,
simp
end
@[simp]
lemma transfer_nat_trans_self_id : transfer_nat_trans_self adj₁ adj₁ (𝟙 _) = 𝟙 _ :=
by { ext, dsimp [transfer_nat_trans_self, transfer_nat_trans], simp }
-- See library note [dsimp, simp]
@[simp]
lemma transfer_nat_trans_self_symm_id :
(transfer_nat_trans_self adj₁ adj₁).symm (𝟙 _) = 𝟙 _ :=
by { rw equiv.symm_apply_eq, simp }
lemma transfer_nat_trans_self_comp (f g) :
transfer_nat_trans_self adj₁ adj₂ f ≫ transfer_nat_trans_self adj₂ adj₃ g =
transfer_nat_trans_self adj₁ adj₃ (g ≫ f) :=
begin
ext,
dsimp [transfer_nat_trans_self, transfer_nat_trans],
simp only [id_comp, comp_id],
rw [←adj₃.unit_naturality_assoc, ←R₃.map_comp, g.naturality_assoc, L₂.map_comp, assoc,
adj₂.counit_naturality, adj₂.left_triangle_components_assoc, assoc],
end
lemma transfer_nat_trans_self_symm_comp (f g) :
(transfer_nat_trans_self adj₂ adj₁).symm f ≫ (transfer_nat_trans_self adj₃ adj₂).symm g =
(transfer_nat_trans_self adj₃ adj₁).symm (g ≫ f) :=
by { rw [equiv.eq_symm_apply, ← transfer_nat_trans_self_comp _ adj₂], simp }
lemma transfer_nat_trans_self_comm {f g} (gf : g ≫ f = 𝟙 _) :
transfer_nat_trans_self adj₁ adj₂ f ≫ transfer_nat_trans_self adj₂ adj₁ g = 𝟙 _ :=
by rw [transfer_nat_trans_self_comp, gf, transfer_nat_trans_self_id]
lemma transfer_nat_trans_self_symm_comm {f g} (gf : g ≫ f = 𝟙 _) :
(transfer_nat_trans_self adj₁ adj₂).symm f ≫ (transfer_nat_trans_self adj₂ adj₁).symm g = 𝟙 _ :=
by rw [transfer_nat_trans_self_symm_comp, gf, transfer_nat_trans_self_symm_id]
/--
If `f` is an isomorphism, then the transferred natural transformation is an isomorphism.
The converse is given in `transfer_nat_trans_self_of_iso`.
-/
instance transfer_nat_trans_self_iso (f : L₂ ⟶ L₁) [is_iso f] :
is_iso (transfer_nat_trans_self adj₁ adj₂ f) :=
{ inv := transfer_nat_trans_self adj₂ adj₁ (inv f),
hom_inv_id' := transfer_nat_trans_self_comm _ _ (by simp),
inv_hom_id' := transfer_nat_trans_self_comm _ _ (by simp) }
/--
If `f` is an isomorphism, then the un-transferred natural transformation is an isomorphism.
The converse is given in `transfer_nat_trans_self_symm_of_iso`.
-/
instance transfer_nat_trans_self_symm_iso (f : R₁ ⟶ R₂) [is_iso f] :
is_iso ((transfer_nat_trans_self adj₁ adj₂).symm f) :=
{ inv := (transfer_nat_trans_self adj₂ adj₁).symm (inv f),
hom_inv_id' := transfer_nat_trans_self_symm_comm _ _ (by simp),
inv_hom_id' := transfer_nat_trans_self_symm_comm _ _ (by simp) }
/--
If `f` is a natural transformation whose transferred natural transformation is an isomorphism,
then `f` is an isomorphism.
The converse is given in `transfer_nat_trans_self_iso`.
-/
def transfer_nat_trans_self_of_iso (f : L₂ ⟶ L₁) [is_iso (transfer_nat_trans_self adj₁ adj₂ f)] :
is_iso f :=
begin
suffices :
is_iso ((transfer_nat_trans_self adj₁ adj₂).symm (transfer_nat_trans_self adj₁ adj₂ f)),
{ simpa using this },
apply_instance,
end
/--
If `f` is a natural transformation whose un-transferred natural transformation is an isomorphism,
then `f` is an isomorphism.
The converse is given in `transfer_nat_trans_self_symm_iso`.
-/
def transfer_nat_trans_self_symm_of_iso (f : R₁ ⟶ R₂)
[is_iso ((transfer_nat_trans_self adj₁ adj₂).symm f)] :
is_iso f :=
begin
suffices :
is_iso ((transfer_nat_trans_self adj₁ adj₂) ((transfer_nat_trans_self adj₁ adj₂).symm f)),
{ simpa using this },
apply_instance,
end
end self
end category_theory
|
5c802e07ad69d10e9bc3220a6f0231708e515e8d | 01f6b345a06ece970e589d4bbc68ee8b9b2cf58a | /src/Cp_def.lean | 54e5a04274cb30beac2b72d01061a3427b774866 | [] | 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 | 7,547 | 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 number_theory.padics.padic_numbers
import ring_theory.valuation.integers
import topology.metric_space.cau_seq_filter
import topology.algebra.valued_field
import spectral_norm_unique
import normed_valued
/-!
# The `p`-adic complex numbers.
In this file we define the field `ℂ_[p]` of `p`-adic complex numbers and we give it both a normed
field and a valued field structure, induced by the unique extension of the `p`-adic norm to `ℂ_[p]`.
## Main Definitions
* `padic_complex` : the type of `p`-adic complex numbers.
* `padic_complex_integers` : the ring of integers of `ℂ_[p]`.
## Main Results
* `padic_complex.norm_extends` : the norm on `ℂ_[p]` extends the norm on `Q_p_alg p`, and hence
the norm on `ℚ_[p]`.
* `padic_complex.is_nonarchimedean` : The norm on `ℂ_[p]` is nonarchimedean.
## Notation
We introduce the notation `ℂ_[p]` for the `p`-adic complex numbers, and `𝓞_ℂ_[p]` for its ring of
integers.
## Tags
p-adic, p adic, padic, norm, valuation, cauchy, completion, p-adic completion
-/
noncomputable theory
open rank_one_valuation
open_locale nnreal
variables (p : ℕ) [fact (nat.prime p)]
/-- `Q_p_alg p` is the algebraic closure of `ℚ_[p]`. -/
@[reducible] def Q_p_alg : Type* := algebraic_closure ℚ_[p]
/-- `Q_p_alg p` is an algebraic extension of `ℚ_[p]`. -/
lemma Q_p_alg.is_algebraic : algebra.is_algebraic ℚ_[p] (Q_p_alg p) :=
algebraic_closure.is_algebraic _
instance : has_coe ℚ_[p] (Q_p_alg p) := ⟨algebra_map ℚ_[p] (Q_p_alg p)⟩
protected lemma coe_eq : (coe : ℚ_[p] → (Q_p_alg p)) = algebra_map ℚ_[p] (Q_p_alg p) := rfl
namespace Q_p_alg
/-- `Q_p_alg p` is a normed field, where the norm is the `p`-adic norm, that is, the spectral norm
induced by the `p`-adic norm on `ℚ_[p]`. -/
instance normed_field : normed_field (Q_p_alg p) :=
@spectral_norm_to_normed_field ℚ_[p] _ _ _ _ padic.complete_space (Q_p_alg.is_algebraic p)
padic_norm_e.nonarchimedean
/-- The norm on `Q_p_alg p` is nonarchimedean. -/
lemma is_nonarchimedean : is_nonarchimedean (norm : (Q_p_alg p) → ℝ) :=
spectral_norm_is_nonarchimedean (Q_p_alg.is_algebraic p) (padic_norm_e.nonarchimedean)
/-- The norm on `Q_p_alg p` is the spectral norm induced by the `p`-adic norm on `ℚ_[p]`. -/
lemma norm_def (x : Q_p_alg p) : ‖ x ‖ = spectral_norm ℚ_[p] (Q_p_alg p) x := rfl
/-- The norm on `Q_p_alg p` extends the `p`-adic norm on `ℚ_[p]`. -/
lemma Q_p.norm_extends (x : ℚ_[p]) : ‖ (x : Q_p_alg p) ‖ = ‖ x ‖ :=
spectral_alg_norm_extends (Q_p_alg.is_algebraic p) _ (padic_norm_e.nonarchimedean)
/-- `Q_p_alg p` is a valued field, with the valuation corresponding to the `p`-adic norm. -/
instance valued_field : valued (Q_p_alg p) ℝ≥0 :=
normed_field.to_valued (Q_p_alg.is_nonarchimedean p)
/-- The valuation of `x : Q_p_alg p` agrees with its `ℝ≥0`-valued norm. -/
lemma v_def (x : Q_p_alg p) : valued.v x = ‖ x ‖₊ := rfl
/-- The coercion of the valuation of `x : Q_p_alg p` to `ℝ` agrees with its norm. -/
lemma v_def_coe (x : Q_p_alg p) :
((valued.v x : ℝ≥0) : ℝ) = spectral_norm ℚ_[p] (Q_p_alg p) x := rfl
/-- The valuation of `p : Q_p_alg p` is `1/p`. -/
lemma valuation_p (p : ℕ) [fact p.prime] : valued.v (p : Q_p_alg p) = 1/(p : ℝ≥0) :=
begin
rw [← map_nat_cast (algebra_map ℚ_[p] (Q_p_alg p)), ← coe_eq],
ext,
rw [v_def_coe, coe_eq, spectral_norm_extends,padic_norm_e.norm_p, one_div, nonneg.coe_inv,
nnreal.coe_nat_cast],
end
end Q_p_alg
/-- `ℂ_[p]` is the field of `p`-adic complex numbers, that is, the completion of `Q_p_alg p` with
respect to the `p`-adic norm. -/
def padic_complex := uniform_space.completion (Q_p_alg p)
notation `ℂ_[`p`]` := padic_complex p
namespace padic_complex
/-- The `p`-adic complex numbers have a field structure. -/
instance : field ℂ_[p] := uniform_space.completion.field
/-- The `p`-adic complex numbers are inhabited. -/
instance : inhabited ℂ_[p] := ⟨0⟩
/-- `ℂ_[p]` is a valued field, where the valuation is the one extending that on `Q_p_alg p`. -/
instance valued_field : valued (ℂ_[p]) ℝ≥0 := valued.valued_completion
/-- `ℂ_[p]` is a complete space. -/
instance complete_space : complete_space (ℂ_[p]) := uniform_space.completion.complete_space _
instance : has_coe_t (Q_p_alg p) ℂ_[p] := uniform_space.completion.has_coe_t _
/-- The valuation on `ℂ_[p]` extends the valuation on `Q_p_alg p`. -/
lemma valuation_extends (x : Q_p_alg p) : valued.v (x : ℂ_[p]) = valued.v x :=
valued.extension_extends _
/-- `ℂ_[p]` is an algebra over `Q_p_alg p`. -/
instance : algebra (Q_p_alg p) ℂ_[p] := uniform_space.completion.algebra' _
lemma coe_eq : (coe : (Q_p_alg p) → ℂ_[p]) = algebra_map (Q_p_alg p) ℂ_[p] := rfl
lemma coe_zero : ((0 : Q_p_alg p) : ℂ_[p]) = 0 := rfl
/-- The valuation of `p : ℂ_[p]` is `1/p`. -/
lemma valuation_p (p : ℕ) [fact p.prime] : valued.v (p : ℂ_[p]) = 1/(p : ℝ≥0) :=
by rw [← map_nat_cast (algebra_map _ _), ← coe_eq, valuation_extends, Q_p_alg.valuation_p]
/-- The valuation on `ℂ_[p]` has rank one. -/
instance : is_rank_one (padic_complex.valued_field p).v :=
{ hom := monoid_with_zero_hom.id ℝ≥0,
strict_mono := strict_mono_id,
nontrivial :=
begin
use p,
haveI hp : nat.prime p := _inst_1.elim,
simp only [valuation_p, one_div, ne.def, inv_eq_zero, nat.cast_eq_zero,
inv_eq_one, nat.cast_eq_one],
exact ⟨hp.ne_zero, hp.ne_one⟩,
end }
/-- `ℂ_[p]` is a normed field, where the norm corresponds to the extension of the `p`-adic
valuation.-/
instance : normed_field ℂ_[p] := valued_field.to_normed_field
/-- The norm on `ℂ_[p]` agrees with the valuation. -/
lemma norm_def : (norm : ℂ_[p] → ℝ) = rank_one_valuation.norm_def := rfl
/-- The norm on `ℂ_[p]` extends the norm on `Q_p_alg p`. -/
lemma norm_extends (x : Q_p_alg p) : ‖ (x : ℂ_[p]) ‖ = ‖ x ‖ :=
begin
by_cases hx : x = 0,
{ rw [hx, coe_zero, norm_zero, norm_zero] },
{ simp only [norm_def, rank_one_valuation.norm_def, valuation_extends,
monoid_with_zero_hom.coe_mk],
refl }
end
/-- The `ℝ≥0`-valued norm on `ℂ_[p]` extends that on `Q_p_alg p`. -/
lemma nnnorm_extends (x : Q_p_alg p) : ‖ (x : ℂ_[p]) ‖₊ = ‖ x ‖₊ :=
by { ext, exact norm_extends p x }
/-- The norm on `ℂ_[p]` is nonarchimedean. -/
lemma is_nonarchimedean : is_nonarchimedean (norm : ℂ_[p] → ℝ) :=
begin
intros x y,
apply uniform_space.completion.induction_on₂ x y,
{ exact is_closed_le (continuous.comp continuous_norm continuous_add) (continuous.max
(continuous.comp (@continuous_norm ℂ_[p] _) (continuous.fst continuous_id))
(continuous.comp (@continuous_norm ℂ_[p] _) (continuous.snd continuous_id))) },
{ intros a b,
simp only [← uniform_space.completion.coe_add, norm_extends],
exact Q_p_alg.is_nonarchimedean p a b }
end
end padic_complex
/-- We define `𝓞_ℂ_[p]` as the subring elements of `ℂ_[p]` with valuation `≤ 1`. -/
def padic_complex_integers : subring ℂ_[p] := (padic_complex.valued_field p).v.integer
notation `𝓞_ℂ_[`p`]` := padic_complex_integers p
/-- `𝓞_ℂ_[p]` is the ring of integers of `ℂ_[p]`. -/
lemma padic_complex.integers : valuation.integers (padic_complex.valued_field p).v 𝓞_ℂ_[p] :=
valuation.integer.integers _ |
2cf09b5a238b7bf1c548550f44dae6c568e05795 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /hott/algebra/graph.hlean | a86b7aeb8397087bc6f68ddfba8c6e1ee95d017d | [
"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 | 13,164 | hlean | /-
Copyright (c) 2016 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
Graphs and operations on graphs
Currently we only define the notion of a path in a graph, and prove properties and operations on
paths.
-/
open eq sigma nat
/-
A path is a list of vertexes which are adjacent. We maybe use a weird ordering of cons, because
the major example where we use this is a category where this ordering makes more sense.
For the operations on paths we use the names from the corresponding operations on lists. Opening
both the list and the paths namespace will lead to many name clashes, so that is not advised.
-/
inductive paths {A : Type} (R : A → A → Type) : A → A → Type :=
| nil {} : Π{a : A}, paths R a a
| cons : Π{a₁ a₂ a₃ : A} (r : R a₂ a₃), paths R a₁ a₂ → paths R a₁ a₃
namespace paths
notation h :: t := cons h t
notation `[` l:(foldr `, ` (h t, cons h t) nil `]`) := l
variables {A : Type} {R : A → A → Type} {a a' a₁ a₂ a₃ a₄ : A}
definition concat (r : R a₁ a₂) (l : paths R a₂ a₃) : paths R a₁ a₃ :=
begin
induction l with a a₂ a₃ a₄ r' l IH,
{ exact [r]},
{ exact r' :: IH r}
end
theorem concat_nil (r : R a₁ a₂) : concat r (@nil A R a₂) = [r] := idp
theorem concat_cons (r : R a₁ a₂) (r' : R a₃ a₄) (l : paths R a₂ a₃)
: concat r (r'::l) = r'::(concat r l) := idp
definition append (l₂ : paths R a₂ a₃) (l₁ : paths R a₁ a₂) :
paths R a₁ a₃ :=
begin
induction l₂,
{ exact l₁},
{ exact cons r (v_0 l₁)}
end
infix ` ++ ` := append
definition nil_append (l : paths R a₁ a₂) : nil ++ l = l := idp
definition cons_append (r : R a₃ a₄) (l₂ : paths R a₂ a₃) (l₁ : paths R a₁ a₂) :
(r :: l₂) ++ l₁ = r :: (l₂ ++ l₁) := idp
definition singleton_append (r : R a₂ a₃) (l : paths R a₁ a₂) : [r] ++ l = r :: l := idp
definition append_singleton (l : paths R a₂ a₃) (r : R a₁ a₂) : l ++ [r] = concat r l :=
begin
induction l,
{ reflexivity},
{ exact ap (cons r) !v_0}
end
definition append_nil (l : paths R a₁ a₂) : l ++ nil = l :=
begin
induction l,
{ reflexivity},
{ exact ap (cons r) v_0}
end
definition append_assoc (l₃ : paths R a₃ a₄) (l₂ : paths R a₂ a₃)
(l₁ : paths R a₁ a₂) : (l₃ ++ l₂) ++ l₁ = l₃ ++ (l₂ ++ l₁) :=
begin
induction l₃,
{ reflexivity},
{ refine ap (cons r) !v_0}
end
theorem append_concat (l₂ : paths R a₃ a₄) (l₁ : paths R a₂ a₃) (r : R a₁ a₂) :
l₂ ++ concat r l₁ = concat r (l₂ ++ l₁) :=
begin
induction l₂,
{ reflexivity},
{ exact ap (cons r_1) !v_0}
end
theorem concat_append (l₂ : paths R a₃ a₄) (r : R a₂ a₃) (l₁ : paths R a₁ a₂) :
concat r l₂ ++ l₁ = l₂ ++ r :: l₁ :=
begin
induction l₂,
{ reflexivity},
{ exact ap (cons r) !v_0}
end
definition paths.rec_tail {C : Π⦃a a' : A⦄, paths R a a' → Type}
(H0 : Π {a : A}, @C a a nil)
(H1 : Π {a₁ a₂ a₃ : A} (r : R a₁ a₂) (l : paths R a₂ a₃), C l → C (concat r l)) :
Π{a a' : A} (l : paths R a a'), C l :=
begin
have Π{a₁ a₂ a₃ : A} (l₂ : paths R a₂ a₃) (l₁ : paths R a₁ a₂) (c : C l₂),
C (l₂ ++ l₁),
begin
intros, revert a₃ l₂ c, induction l₁: intros a₃ l₂ c,
{ rewrite append_nil, exact c},
{ rewrite [-concat_append], apply v_0, apply H1, exact c}
end,
intros, rewrite [-nil_append], apply this, apply H0
end
definition cons_eq_concat (r : R a₂ a₃) (l : paths R a₁ a₂) :
Σa (r' : R a₁ a) (l' : paths R a a₃), r :: l = concat r' l' :=
begin
revert a₃ r, induction l: intros a₃' r',
{ exact ⟨a₃', r', nil, idp⟩},
{ cases (v_0 a₃ r) with a₄ w, cases w with r₂ w, cases w with l p, clear v_0,
exact ⟨a₄, r₂, r' :: l, ap (cons r') p⟩}
end
definition length (l : paths R a₁ a₂) : ℕ :=
begin
induction l,
{ exact 0},
{ exact succ v_0}
end
/- If we can reverse edges in the graph we can reverse paths -/
definition reverse (rev : Π⦃a a'⦄, R a a' → R a' a) (l : paths R a₁ a₂) :
paths R a₂ a₁ :=
begin
induction l,
{ exact nil},
{ exact concat (rev r) v_0}
end
theorem reverse_nil (rev : Π⦃a a'⦄, R a a' → R a' a) : reverse rev (@nil A R a₁) = [] := idp
theorem reverse_cons (rev : Π⦃a a'⦄, R a a' → R a' a) (r : R a₂ a₃) (l : paths R a₁ a₂) :
reverse rev (r::l) = concat (rev r) (reverse rev l) := idp
theorem reverse_singleton (rev : Π⦃a a'⦄, R a a' → R a' a) (r : R a₁ a₂) :
reverse rev [r] = [rev r] := idp
theorem reverse_pair (rev : Π⦃a a'⦄, R a a' → R a' a) (r₂ : R a₂ a₃) (r₁ : R a₁ a₂) :
reverse rev [r₂, r₁] = [rev r₁, rev r₂] := idp
theorem reverse_concat (rev : Π⦃a a'⦄, R a a' → R a' a) (r : R a₁ a₂) (l : paths R a₂ a₃) :
reverse rev (concat r l) = rev r :: (reverse rev l) :=
begin
induction l,
{ reflexivity},
{ rewrite [concat_cons, reverse_cons, v_0]}
end
theorem reverse_append (rev : Π⦃a a'⦄, R a a' → R a' a) (l₂ : paths R a₂ a₃)
(l₁ : paths R a₁ a₂) : reverse rev (l₂ ++ l₁) = reverse rev l₁ ++ reverse rev l₂ :=
begin
induction l₂,
{ exact !append_nil⁻¹},
{ rewrite [cons_append, +reverse_cons, append_concat, v_0]}
end
definition realize (P : A → A → Type) (f : Π⦃a a'⦄, R a a' → P a a') (ρ : Πa, P a a)
(c : Π⦃a₁ a₂ a₃⦄, P a₁ a₂ → P a₂ a₃ → P a₁ a₃)
⦃a a' : A⦄ (l : paths R a a') : P a a' :=
begin
induction l,
{ exact ρ a},
{ exact c v_0 (f r)}
end
definition realize_nil (P : A → A → Type) (f : Π⦃a a'⦄, R a a' → P a a') (ρ : Πa, P a a)
(c : Π⦃a₁ a₂ a₃⦄, P a₁ a₂ → P a₂ a₃ → P a₁ a₃) (a : A) :
realize P f ρ c nil = ρ a :=
idp
definition realize_cons (P : A → A → Type) (f : Π⦃a a'⦄, R a a' → P a a') (ρ : Πa, P a a)
(c : Π⦃a₁ a₂ a₃⦄, P a₁ a₂ → P a₂ a₃ → P a₁ a₃)
⦃a₁ a₂ a₃ : A⦄ (r : R a₂ a₃) (l : paths R a₁ a₂) :
realize P f ρ c (r :: l) = c (realize P f ρ c l) (f r) :=
idp
theorem realize_singleton {P : A → A → Type} {f : Π⦃a a'⦄, R a a' → P a a'} {ρ : Πa, P a a}
{c : Π⦃a₁ a₂ a₃⦄, P a₁ a₂ → P a₂ a₃ → P a₁ a₃}
(id_left : Π⦃a₁ a₂⦄ (p : P a₁ a₂), c (ρ a₁) p = p)
⦃a₁ a₂ : A⦄ (r : R a₁ a₂) :
realize P f ρ c [r] = f r :=
id_left (f r)
theorem realize_pair {P : A → A → Type} {f : Π⦃a a'⦄, R a a' → P a a'} {ρ : Πa, P a a}
{c : Π⦃a₁ a₂ a₃⦄, P a₁ a₂ → P a₂ a₃ → P a₁ a₃}
(id_left : Π⦃a₁ a₂⦄ (p : P a₁ a₂), c (ρ a₁) p = p)
⦃a₁ a₂ a₃ : A⦄ (r₂ : R a₂ a₃) (r₁ : R a₁ a₂) :
realize P f ρ c [r₂, r₁] = c (f r₁) (f r₂) :=
ap (λx, c x (f r₂)) (realize_singleton id_left r₁)
theorem realize_append {P : A → A → Type} {f : Π⦃a a'⦄, R a a' → P a a'} {ρ : Πa, P a a}
{c : Π⦃a₁ a₂ a₃⦄, P a₁ a₂ → P a₂ a₃ → P a₁ a₃}
(assoc : Π⦃a₁ a₂ a₃ a₄⦄ (p : P a₁ a₂) (q : P a₂ a₃) (r : P a₃ a₄), c (c p q) r = c p (c q r))
(id_right : Π⦃a₁ a₂⦄ (p : P a₁ a₂), c p (ρ a₂) = p)
⦃a₁ a₂ a₃ : A⦄ (l₂ : paths R a₂ a₃) (l₁ : paths R a₁ a₂) :
realize P f ρ c (l₂ ++ l₁) = c (realize P f ρ c l₁) (realize P f ρ c l₂) :=
begin
induction l₂,
{ exact !id_right⁻¹},
{ rewrite [cons_append, +realize_cons, v_0, assoc]}
end
/-
We sometimes want to take quotients of paths (this library was developed to define the pushout of
categories). The definition paths_rel will - given some basic reduction rules codified by Q -
extend the reduction to a reflexive transitive relation respecting concatenation of paths.
-/
inductive paths_rel {A : Type} {R : A → A → Type}
(Q : Π⦃a a' : A⦄, paths R a a' → paths R a a' → Type)
: Π⦃a a' : A⦄, paths R a a' → paths R a a' → Type :=
| rrefl : Π{a a' : A} (l : paths R a a'), paths_rel Q l l
| rel : Π{a₁ a₂ a₃ : A} {l₂ l₃ : paths R a₂ a₃} (l : paths R a₁ a₂) (q : Q l₂ l₃),
paths_rel Q (l₂ ++ l) (l₃ ++ l)
| rcons : Π{a₁ a₂ a₃ : A} {l₁ l₂ : paths R a₁ a₂} (r : R a₂ a₃),
paths_rel Q l₁ l₂ → paths_rel Q (cons r l₁) (cons r l₂)
| rtrans : Π{a₁ a₂ : A} {l₁ l₂ l₃ : paths R a₁ a₂},
paths_rel Q l₁ l₂ → paths_rel Q l₂ l₃ → paths_rel Q l₁ l₃
open paths_rel
attribute rrefl [refl]
attribute rtrans [trans]
variables {Q : Π⦃a a' : A⦄, paths R a a' → paths R a a' → Type}
definition paths_rel_of_Q {l₁ l₂ : paths R a₁ a₂} (q : Q l₁ l₂) :
paths_rel Q l₁ l₂ :=
begin
rewrite [-append_nil l₁, -append_nil l₂], exact rel nil q,
end
theorem rel_respect_append_left (l : paths R a₂ a₃) {l₃ l₄ : paths R a₁ a₂}
(H : paths_rel Q l₃ l₄) : paths_rel Q (l ++ l₃) (l ++ l₄) :=
begin
induction l,
{ exact H},
{ exact rcons r (v_0 _ _ H)}
end
theorem rel_respect_append_right {l₁ l₂ : paths R a₂ a₃} (l : paths R a₁ a₂)
(H₁ : paths_rel Q l₁ l₂) : paths_rel Q (l₁ ++ l) (l₂ ++ l) :=
begin
induction H₁ with a₁ a₂ l₁
a₂ a₃ a₄ l₂ l₂' l₁ q
a₂ a₃ a₄ l₁ l₂ r H₁ IH
a₂ a₃ l₁ l₂ l₂' H₁ H₁' IH IH',
{ reflexivity},
{ rewrite [+ append_assoc], exact rel _ q},
{ exact rcons r (IH l) },
{ exact rtrans (IH l) (IH' l)}
end
theorem rel_respect_append {l₁ l₂ : paths R a₂ a₃} {l₃ l₄ : paths R a₁ a₂}
(H₁ : paths_rel Q l₁ l₂) (H₂ : paths_rel Q l₃ l₄) :
paths_rel Q (l₁ ++ l₃) (l₂ ++ l₄) :=
begin
induction H₁ with a₁ a₂ l
a₂ a₃ a₄ l₂ l₂' l q
a₂ a₃ a₄ l₁ l₂ r H₁ IH
a₂ a₃ l₁ l₂ l₂' H₁ H₁' IH IH',
{ exact rel_respect_append_left _ H₂},
{ rewrite [+ append_assoc], transitivity _, exact rel _ q,
apply rel_respect_append_left, apply rel_respect_append_left, exact H₂},
{ exact rcons r (IH _ _ H₂) },
{ refine rtrans (IH _ _ H₂) _, apply rel_respect_append_right, exact H₁'}
end
/- assuming some extra properties the relation respects reversing -/
theorem rel_respect_reverse (rev : Π⦃a a'⦄, R a a' → R a' a) {l₁ l₂ : paths R a₁ a₂}
(H : paths_rel Q l₁ l₂)
(rev_rel : Π⦃a a' : A⦄ {l l' : paths R a a'},
Q l l' → paths_rel Q (reverse rev l) (reverse rev l')) :
paths_rel Q (reverse rev l₁) (reverse rev l₂) :=
begin
induction H,
{ reflexivity},
{ rewrite [+ reverse_append], apply rel_respect_append_left, apply rev_rel q},
{ rewrite [+reverse_cons,-+append_singleton], apply rel_respect_append_right, exact v_0},
{ exact rtrans v_0 v_1}
end
theorem rel_left_inv (rev : Π⦃a a'⦄, R a a' → R a' a) (l : paths R a₁ a₂)
(li : Π⦃a a' : A⦄ (r : R a a'), paths_rel Q [rev r, r] nil) :
paths_rel Q (reverse rev l ++ l) nil :=
begin
induction l,
{ reflexivity},
{ rewrite [reverse_cons, concat_append],
refine rtrans _ v_0, apply rel_respect_append_left,
exact rel_respect_append_right _ (li r)}
end
theorem rel_right_inv (rev : Π⦃a a'⦄, R a a' → R a' a) (l : paths R a₁ a₂)
(ri : Π⦃a a' : A⦄ (r : R a a'), paths_rel Q [r, rev r] nil) :
paths_rel Q (l ++ reverse rev l) nil :=
begin
induction l using paths.rec_tail,
{ reflexivity},
{ rewrite [reverse_concat, concat_append],
refine rtrans _ a, apply rel_respect_append_left,
exact rel_respect_append_right _ (ri r)}
end
definition realize_eq {P : A → A → Type} {f : Π⦃a a'⦄, R a a' → P a a'} {ρ : Πa, P a a}
{c : Π⦃a₁ a₂ a₃⦄, P a₁ a₂ → P a₂ a₃ → P a₁ a₃}
(assoc : Π⦃a₁ a₂ a₃ a₄⦄ (p : P a₁ a₂) (q : P a₂ a₃) (r : P a₃ a₄), c (c p q) r = c p (c q r))
(id_right : Π⦃a₁ a₂⦄ (p : P a₁ a₂), c p (ρ a₂) = p)
(resp_rel : Π⦃a₁ a₂⦄ {l₁ l₂ : paths R a₁ a₂}, Q l₁ l₂ →
realize P f ρ c l₁ = realize P f ρ c l₂)
⦃a a' : A⦄ {l l' : paths R a a'} (H : paths_rel Q l l') :
realize P f ρ c l = realize P f ρ c l' :=
begin
induction H,
{ reflexivity},
{ rewrite [+realize_append assoc id_right], apply ap (c _), exact resp_rel q},
{ exact ap (λx, c x (f r)) v_0},
{ exact v_0 ⬝ v_1}
end
end paths
|
10aaf972d8b21d5aeb700b08c253b9595bf78ff7 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/Lean3Lib/init/data/default.lean | 9b0f531586cabb192b8e62e046cc4ca43a9b5af6 | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,066 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.data.basic
import Mathlib.Lean3Lib.init.data.sigma.default
import Mathlib.Lean3Lib.init.data.nat.default
import Mathlib.Lean3Lib.init.data.char.default
import Mathlib.Lean3Lib.init.data.string.default
import Mathlib.Lean3Lib.init.data.list.default
import Mathlib.Lean3Lib.init.data.sum.default
import Mathlib.Lean3Lib.init.data.subtype.default
import Mathlib.Lean3Lib.init.data.int.default
import Mathlib.Lean3Lib.init.data.array.default
import Mathlib.Lean3Lib.init.data.bool.default
import Mathlib.Lean3Lib.init.data.fin.default
import Mathlib.Lean3Lib.init.data.unsigned.default
import Mathlib.Lean3Lib.init.data.ordering.default
import Mathlib.Lean3Lib.init.data.rbtree.default
import Mathlib.Lean3Lib.init.data.rbmap.default
import Mathlib.Lean3Lib.init.data.option.basic
import Mathlib.Lean3Lib.init.data.option.instances
namespace Mathlib
|
c4e5734070bfed0090d165cdead7f99c28d175bc | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/analysis/calculus/fderiv.lean | 2a18bd143f570afa19e09f1165eee2c20947c408 | [
"Apache-2.0"
] | permissive | ramonfmir/mathlib | c5dc8b33155473fab97c38bd3aa6723dc289beaa | 14c52e990c17f5a00c0cc9e09847af16fabbed25 | refs/heads/master | 1,661,979,343,526 | 1,660,830,384,000 | 1,660,830,384,000 | 182,072,989 | 0 | 0 | null | 1,555,585,876,000 | 1,555,585,876,000 | null | UTF-8 | Lean | false | false | 136,705 | lean | /-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov
-/
import analysis.asymptotics.asymptotic_equivalent
import analysis.calculus.tangent_cone
import analysis.normed_space.bounded_linear_maps
import analysis.normed_space.units
/-!
# The Fréchet derivative
Let `E` and `F` be normed spaces, `f : E → F`, and `f' : E →L[𝕜] F` a
continuous 𝕜-linear map, where `𝕜` is a non-discrete normed field. Then
`has_fderiv_within_at f f' s x`
says that `f` has derivative `f'` at `x`, where the domain of interest
is restricted to `s`. We also have
`has_fderiv_at f f' x := has_fderiv_within_at f f' x univ`
Finally,
`has_strict_fderiv_at f f' x`
means that `f : E → F` has derivative `f' : E →L[𝕜] F` in the sense of strict differentiability,
i.e., `f y - f z - f'(y - z) = o(y - z)` as `y, z → x`. This notion is used in the inverse
function theorem, and is defined here only to avoid proving theorems like
`is_bounded_bilinear_map.has_fderiv_at` twice: first for `has_fderiv_at`, then for
`has_strict_fderiv_at`.
## Main results
In addition to the definition and basic properties of the derivative, this file contains the
usual formulas (and existence assertions) for the derivative of
* constants
* the identity
* bounded linear maps
* bounded bilinear maps
* sum of two functions
* sum of finitely many functions
* multiplication of a function by a scalar constant
* negative of a function
* subtraction of two functions
* multiplication of a function by a scalar function
* multiplication of two scalar functions
* composition of functions (the chain rule)
* inverse function (assuming that it exists; the inverse function theorem is in `inverse.lean`)
For most binary operations we also define `const_op` and `op_const` theorems for the cases when
the first or second argument is a constant. This makes writing chains of `has_deriv_at`'s easier,
and they more frequently lead to the desired result.
One can also interpret the derivative of a function `f : 𝕜 → E` as an element of `E` (by identifying
a linear function from `𝕜` to `E` with its value at `1`). Results on the Fréchet derivative are
translated to this more elementary point of view on the derivative in the file `deriv.lean`. The
derivative of polynomials is handled there, as it is naturally one-dimensional.
The simplifier is set up to prove automatically that some functions are differentiable, or
differentiable at a point (but not differentiable on a set or within a set at a point, as checking
automatically that the good domains are mapped one to the other when using composition is not
something the simplifier can easily do). This means that one can write
`example (x : ℝ) : differentiable ℝ (λ x, sin (exp (3 + x^2)) - 5 * cos x) := by simp`.
If there are divisions, one needs to supply to the simplifier proofs that the denominators do
not vanish, as in
```lean
example (x : ℝ) (h : 1 + sin x ≠ 0) : differentiable_at ℝ (λ x, exp x / (1 + sin x)) x :=
by simp [h]
```
Of course, these examples only work once `exp`, `cos` and `sin` have been shown to be
differentiable, in `analysis.special_functions.trigonometric`.
The simplifier is not set up to compute the Fréchet derivative of maps (as these are in general
complicated multidimensional linear maps), but it will compute one-dimensional derivatives,
see `deriv.lean`.
## Implementation details
The derivative is defined in terms of the `is_o` relation, but also
characterized in terms of the `tendsto` relation.
We also introduce predicates `differentiable_within_at 𝕜 f s x` (where `𝕜` is the base field,
`f` the function to be differentiated, `x` the point at which the derivative is asserted to exist,
and `s` the set along which the derivative is defined), as well as `differentiable_at 𝕜 f x`,
`differentiable_on 𝕜 f s` and `differentiable 𝕜 f` to express the existence of a derivative.
To be able to compute with derivatives, we write `fderiv_within 𝕜 f s x` and `fderiv 𝕜 f x`
for some choice of a derivative if it exists, and the zero function otherwise. This choice only
behaves well along sets for which the derivative is unique, i.e., those for which the tangent
directions span a dense subset of the whole space. The predicates `unique_diff_within_at s x` and
`unique_diff_on s`, defined in `tangent_cone.lean` express this property. We prove that indeed
they imply the uniqueness of the derivative. This is satisfied for open subsets, and in particular
for `univ`. This uniqueness only holds when the field is non-discrete, which we request at the very
beginning: otherwise, a derivative can be defined, but it has no interesting properties whatsoever.
To make sure that the simplifier can prove automatically that functions are differentiable, we tag
many lemmas with the `simp` attribute, for instance those saying that the sum of differentiable
functions is differentiable, as well as their product, their cartesian product, and so on. A notable
exception is the chain rule: we do not mark as a simp lemma the fact that, if `f` and `g` are
differentiable, then their composition also is: `simp` would always be able to match this lemma,
by taking `f` or `g` to be the identity. Instead, for every reasonable function (say, `exp`),
we add a lemma that if `f` is differentiable then so is `(λ x, exp (f x))`. This means adding
some boilerplate lemmas, but these can also be useful in their own right.
Tests for this ability of the simplifier (with more examples) are provided in
`tests/differentiable.lean`.
## Tags
derivative, differentiable, Fréchet, calculus
-/
open filter asymptotics continuous_linear_map set metric
open_locale topological_space classical nnreal filter asymptotics ennreal
noncomputable theory
section
variables {𝕜 : Type*} [nontrivially_normed_field 𝕜]
variables {E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E]
variables {F : Type*} [normed_add_comm_group F] [normed_space 𝕜 F]
variables {G : Type*} [normed_add_comm_group G] [normed_space 𝕜 G]
variables {G' : Type*} [normed_add_comm_group G'] [normed_space 𝕜 G']
/-- A function `f` has the continuous linear map `f'` as derivative along the filter `L` if
`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` converges along the filter `L`. This definition
is designed to be specialized for `L = 𝓝 x` (in `has_fderiv_at`), giving rise to the usual notion
of Fréchet derivative, and for `L = 𝓝[s] x` (in `has_fderiv_within_at`), giving rise to
the notion of Fréchet derivative along the set `s`. -/
def has_fderiv_at_filter (f : E → F) (f' : E →L[𝕜] F) (x : E) (L : filter E) :=
(λ x', f x' - f x - f' (x' - x)) =o[L] (λ x', x' - x)
/-- A function `f` has the continuous linear map `f'` as derivative at `x` within a set `s` if
`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x` inside `s`. -/
def has_fderiv_within_at (f : E → F) (f' : E →L[𝕜] F) (s : set E) (x : E) :=
has_fderiv_at_filter f f' x (𝓝[s] x)
/-- A function `f` has the continuous linear map `f'` as derivative at `x` if
`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x`. -/
def has_fderiv_at (f : E → F) (f' : E →L[𝕜] F) (x : E) :=
has_fderiv_at_filter f f' x (𝓝 x)
/-- A function `f` has derivative `f'` at `a` in the sense of *strict differentiability*
if `f x - f y - f' (x - y) = o(x - y)` as `x, y → a`. This form of differentiability is required,
e.g., by the inverse function theorem. Any `C^1` function on a vector space over `ℝ` is strictly
differentiable but this definition works, e.g., for vector spaces over `p`-adic numbers. -/
def has_strict_fderiv_at (f : E → F) (f' : E →L[𝕜] F) (x : E) :=
(λ p : E × E, f p.1 - f p.2 - f' (p.1 - p.2)) =o[𝓝 (x, x)] (λ p : E × E, p.1 - p.2)
variables (𝕜)
/-- A function `f` is differentiable at a point `x` within a set `s` if it admits a derivative
there (possibly non-unique). -/
def differentiable_within_at (f : E → F) (s : set E) (x : E) :=
∃f' : E →L[𝕜] F, has_fderiv_within_at f f' s x
/-- A function `f` is differentiable at a point `x` if it admits a derivative there (possibly
non-unique). -/
def differentiable_at (f : E → F) (x : E) :=
∃f' : E →L[𝕜] F, has_fderiv_at f f' x
/-- If `f` has a derivative at `x` within `s`, then `fderiv_within 𝕜 f s x` is such a derivative.
Otherwise, it is set to `0`. -/
def fderiv_within (f : E → F) (s : set E) (x : E) : E →L[𝕜] F :=
if h : ∃f', has_fderiv_within_at f f' s x then classical.some h else 0
/-- If `f` has a derivative at `x`, then `fderiv 𝕜 f x` is such a derivative. Otherwise, it is
set to `0`. -/
def fderiv (f : E → F) (x : E) : E →L[𝕜] F :=
if h : ∃f', has_fderiv_at f f' x then classical.some h else 0
/-- `differentiable_on 𝕜 f s` means that `f` is differentiable within `s` at any point of `s`. -/
def differentiable_on (f : E → F) (s : set E) :=
∀x ∈ s, differentiable_within_at 𝕜 f s x
/-- `differentiable 𝕜 f` means that `f` is differentiable at any point. -/
def differentiable (f : E → F) :=
∀x, differentiable_at 𝕜 f x
variables {𝕜}
variables {f f₀ f₁ g : E → F}
variables {f' f₀' f₁' g' : E →L[𝕜] F}
variables (e : E →L[𝕜] F)
variables {x : E}
variables {s t : set E}
variables {L L₁ L₂ : filter E}
lemma fderiv_within_zero_of_not_differentiable_within_at
(h : ¬ differentiable_within_at 𝕜 f s x) : fderiv_within 𝕜 f s x = 0 :=
have ¬ ∃ f', has_fderiv_within_at f f' s x, from h,
by simp [fderiv_within, this]
lemma fderiv_zero_of_not_differentiable_at (h : ¬ differentiable_at 𝕜 f x) : fderiv 𝕜 f x = 0 :=
have ¬ ∃ f', has_fderiv_at f f' x, from h,
by simp [fderiv, this]
section derivative_uniqueness
/- In this section, we discuss the uniqueness of the derivative.
We prove that the definitions `unique_diff_within_at` and `unique_diff_on` indeed imply the
uniqueness of the derivative. -/
/-- If a function f has a derivative f' at x, a rescaled version of f around x converges to f',
i.e., `n (f (x + (1/n) v) - f x)` converges to `f' v`. More generally, if `c n` tends to infinity
and `c n * d n` tends to `v`, then `c n * (f (x + d n) - f x)` tends to `f' v`. This lemma expresses
this fact, for functions having a derivative within a set. Its specific formulation is useful for
tangent cone related discussions. -/
theorem has_fderiv_within_at.lim (h : has_fderiv_within_at f f' s x) {α : Type*} (l : filter α)
{c : α → 𝕜} {d : α → E} {v : E} (dtop : ∀ᶠ n in l, x + d n ∈ s)
(clim : tendsto (λ n, ∥c n∥) l at_top)
(cdlim : tendsto (λ n, c n • d n) l (𝓝 v)) :
tendsto (λn, c n • (f (x + d n) - f x)) l (𝓝 (f' v)) :=
begin
have tendsto_arg : tendsto (λ n, x + d n) l (𝓝[s] x),
{ conv in (𝓝[s] x) { rw ← add_zero x },
rw [nhds_within, tendsto_inf],
split,
{ apply tendsto_const_nhds.add (tangent_cone_at.lim_zero l clim cdlim) },
{ rwa tendsto_principal } },
have : (λ y, f y - f x - f' (y - x)) =o[𝓝[s] x] (λ y, y - x) := h,
have : (λ n, f (x + d n) - f x - f' ((x + d n) - x)) =o[l] (λ n, (x + d n) - x) :=
this.comp_tendsto tendsto_arg,
have : (λ n, f (x + d n) - f x - f' (d n)) =o[l] d := by simpa only [add_sub_cancel'],
have : (λ n, c n • (f (x + d n) - f x - f' (d n))) =o[l] (λ n, c n • d n) :=
(is_O_refl c l).smul_is_o this,
have : (λ n, c n • (f (x + d n) - f x - f' (d n))) =o[l] (λ n, (1:ℝ)) :=
this.trans_is_O (cdlim.is_O_one ℝ),
have L1 : tendsto (λn, c n • (f (x + d n) - f x - f' (d n))) l (𝓝 0) :=
(is_o_one_iff ℝ).1 this,
have L2 : tendsto (λn, f' (c n • d n)) l (𝓝 (f' v)) :=
tendsto.comp f'.cont.continuous_at cdlim,
have L3 : tendsto (λn, (c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)))
l (𝓝 (0 + f' v)) :=
L1.add L2,
have : (λn, (c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)))
= (λn, c n • (f (x + d n) - f x)),
by { ext n, simp [smul_add, smul_sub] },
rwa [this, zero_add] at L3
end
/-- If `f'` and `f₁'` are two derivatives of `f` within `s` at `x`, then they are equal on the
tangent cone to `s` at `x` -/
theorem has_fderiv_within_at.unique_on (hf : has_fderiv_within_at f f' s x)
(hg : has_fderiv_within_at f f₁' s x) :
eq_on f' f₁' (tangent_cone_at 𝕜 s x) :=
λ y ⟨c, d, dtop, clim, cdlim⟩,
tendsto_nhds_unique (hf.lim at_top dtop clim cdlim) (hg.lim at_top dtop clim cdlim)
/-- `unique_diff_within_at` achieves its goal: it implies the uniqueness of the derivative. -/
theorem unique_diff_within_at.eq (H : unique_diff_within_at 𝕜 s x)
(hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at f f₁' s x) : f' = f₁' :=
continuous_linear_map.ext_on H.1 (hf.unique_on hg)
theorem unique_diff_on.eq (H : unique_diff_on 𝕜 s) (hx : x ∈ s)
(h : has_fderiv_within_at f f' s x) (h₁ : has_fderiv_within_at f f₁' s x) : f' = f₁' :=
(H x hx).eq h h₁
end derivative_uniqueness
section fderiv_properties
/-! ### Basic properties of the derivative -/
theorem has_fderiv_at_filter_iff_tendsto :
has_fderiv_at_filter f f' x L ↔
tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) L (𝓝 0) :=
have h : ∀ x', ∥x' - x∥ = 0 → ∥f x' - f x - f' (x' - x)∥ = 0, from λ x' hx',
by { rw [sub_eq_zero.1 (norm_eq_zero.1 hx')], simp },
begin
unfold has_fderiv_at_filter,
rw [←is_o_norm_left, ←is_o_norm_right, is_o_iff_tendsto h],
exact tendsto_congr (λ _, div_eq_inv_mul _ _),
end
theorem has_fderiv_within_at_iff_tendsto : has_fderiv_within_at f f' s x ↔
tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) (𝓝[s] x) (𝓝 0) :=
has_fderiv_at_filter_iff_tendsto
theorem has_fderiv_at_iff_tendsto : has_fderiv_at f f' x ↔
tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) (𝓝 x) (𝓝 0) :=
has_fderiv_at_filter_iff_tendsto
theorem has_fderiv_at_iff_is_o_nhds_zero : has_fderiv_at f f' x ↔
(λ h : E, f (x + h) - f x - f' h) =o[𝓝 0] (λh, h) :=
begin
rw [has_fderiv_at, has_fderiv_at_filter, ← map_add_left_nhds_zero x, is_o_map],
simp [(∘)]
end
/-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz
on a neighborhood of `x₀` then it its derivative at `x₀` has norm bounded by `C`. This version
only assumes that `∥f x - f x₀∥ ≤ C * ∥x - x₀∥` in a neighborhood of `x`. -/
lemma has_fderiv_at.le_of_lip' {f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : has_fderiv_at f f' x₀)
{C : ℝ} (hC₀ : 0 ≤ C) (hlip : ∀ᶠ x in 𝓝 x₀, ∥f x - f x₀∥ ≤ C * ∥x - x₀∥) : ∥f'∥ ≤ C :=
begin
refine le_of_forall_pos_le_add (λ ε ε0, op_norm_le_of_nhds_zero _ _),
exact add_nonneg hC₀ ε0.le,
rw [← map_add_left_nhds_zero x₀, eventually_map] at hlip,
filter_upwards [is_o_iff.1 (has_fderiv_at_iff_is_o_nhds_zero.1 hf) ε0, hlip] with y hy hyC,
rw add_sub_cancel' at hyC,
calc ∥f' y∥ ≤ ∥f (x₀ + y) - f x₀∥ + ∥f (x₀ + y) - f x₀ - f' y∥ : norm_le_insert _ _
... ≤ C * ∥y∥ + ε * ∥y∥ : add_le_add hyC hy
... = (C + ε) * ∥y∥ : (add_mul _ _ _).symm
end
/-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz
on a neighborhood of `x₀` then it its derivative at `x₀` has norm bounded by `C`. -/
lemma has_fderiv_at.le_of_lip {f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : has_fderiv_at f f' x₀)
{s : set E} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : lipschitz_on_with C f s) : ∥f'∥ ≤ C :=
begin
refine hf.le_of_lip' C.coe_nonneg _,
filter_upwards [hs] with x hx using hlip.norm_sub_le hx (mem_of_mem_nhds hs),
end
theorem has_fderiv_at_filter.mono (h : has_fderiv_at_filter f f' x L₂) (hst : L₁ ≤ L₂) :
has_fderiv_at_filter f f' x L₁ :=
h.mono hst
theorem has_fderiv_within_at.mono_of_mem (h : has_fderiv_within_at f f' t x) (hst : t ∈ 𝓝[s] x) :
has_fderiv_within_at f f' s x :=
h.mono $ nhds_within_le_iff.mpr hst
theorem has_fderiv_within_at.mono (h : has_fderiv_within_at f f' t x) (hst : s ⊆ t) :
has_fderiv_within_at f f' s x :=
h.mono $ nhds_within_mono _ hst
theorem has_fderiv_at.has_fderiv_at_filter (h : has_fderiv_at f f' x) (hL : L ≤ 𝓝 x) :
has_fderiv_at_filter f f' x L :=
h.mono hL
theorem has_fderiv_at.has_fderiv_within_at
(h : has_fderiv_at f f' x) : has_fderiv_within_at f f' s x :=
h.has_fderiv_at_filter inf_le_left
lemma has_fderiv_within_at.differentiable_within_at (h : has_fderiv_within_at f f' s x) :
differentiable_within_at 𝕜 f s x :=
⟨f', h⟩
lemma has_fderiv_at.differentiable_at (h : has_fderiv_at f f' x) : differentiable_at 𝕜 f x :=
⟨f', h⟩
@[simp] lemma has_fderiv_within_at_univ :
has_fderiv_within_at f f' univ x ↔ has_fderiv_at f f' x :=
by { simp only [has_fderiv_within_at, nhds_within_univ], refl }
lemma has_strict_fderiv_at.is_O_sub (hf : has_strict_fderiv_at f f' x) :
(λ p : E × E, f p.1 - f p.2) =O[𝓝 (x, x)] (λ p : E × E, p.1 - p.2) :=
hf.is_O.congr_of_sub.2 (f'.is_O_comp _ _)
lemma has_fderiv_at_filter.is_O_sub (h : has_fderiv_at_filter f f' x L) :
(λ x', f x' - f x) =O[L] (λ x', x' - x) :=
h.is_O.congr_of_sub.2 (f'.is_O_sub _ _)
protected lemma has_strict_fderiv_at.has_fderiv_at (hf : has_strict_fderiv_at f f' x) :
has_fderiv_at f f' x :=
begin
rw [has_fderiv_at, has_fderiv_at_filter, is_o_iff],
exact (λ c hc, tendsto_id.prod_mk_nhds tendsto_const_nhds (is_o_iff.1 hf hc))
end
protected lemma has_strict_fderiv_at.differentiable_at (hf : has_strict_fderiv_at f f' x) :
differentiable_at 𝕜 f x :=
hf.has_fderiv_at.differentiable_at
/-- If `f` is strictly differentiable at `x` with derivative `f'` and `K > ∥f'∥₊`, then `f` is
`K`-Lipschitz in a neighborhood of `x`. -/
lemma has_strict_fderiv_at.exists_lipschitz_on_with_of_nnnorm_lt (hf : has_strict_fderiv_at f f' x)
(K : ℝ≥0) (hK : ∥f'∥₊ < K) : ∃ s ∈ 𝓝 x, lipschitz_on_with K f s :=
begin
have := hf.add_is_O_with (f'.is_O_with_comp _ _) hK,
simp only [sub_add_cancel, is_O_with] at this,
rcases exists_nhds_square this with ⟨U, Uo, xU, hU⟩,
exact ⟨U, Uo.mem_nhds xU, lipschitz_on_with_iff_norm_sub_le.2 $
λ x hx y hy, hU (mk_mem_prod hx hy)⟩
end
/-- If `f` is strictly differentiable at `x` with derivative `f'`, then `f` is Lipschitz in a
neighborhood of `x`. See also `has_strict_fderiv_at.exists_lipschitz_on_with_of_nnnorm_lt` for a
more precise statement. -/
lemma has_strict_fderiv_at.exists_lipschitz_on_with (hf : has_strict_fderiv_at f f' x) :
∃ K (s ∈ 𝓝 x), lipschitz_on_with K f s :=
(exists_gt _).imp hf.exists_lipschitz_on_with_of_nnnorm_lt
/-- Directional derivative agrees with `has_fderiv`. -/
lemma has_fderiv_at.lim (hf : has_fderiv_at f f' x) (v : E) {α : Type*} {c : α → 𝕜}
{l : filter α} (hc : tendsto (λ n, ∥c n∥) l at_top) :
tendsto (λ n, (c n) • (f (x + (c n)⁻¹ • v) - f x)) l (𝓝 (f' v)) :=
begin
refine (has_fderiv_within_at_univ.2 hf).lim _ (univ_mem' (λ _, trivial)) hc _,
assume U hU,
refine (eventually_ne_of_tendsto_norm_at_top hc (0:𝕜)).mono (λ y hy, _),
convert mem_of_mem_nhds hU,
dsimp only,
rw [← mul_smul, mul_inv_cancel hy, one_smul]
end
theorem has_fderiv_at.unique
(h₀ : has_fderiv_at f f₀' x) (h₁ : has_fderiv_at f f₁' x) : f₀' = f₁' :=
begin
rw ← has_fderiv_within_at_univ at h₀ h₁,
exact unique_diff_within_at_univ.eq h₀ h₁
end
lemma has_fderiv_within_at_inter' (h : t ∈ 𝓝[s] x) :
has_fderiv_within_at f f' (s ∩ t) x ↔ has_fderiv_within_at f f' s x :=
by simp [has_fderiv_within_at, nhds_within_restrict'' s h]
lemma has_fderiv_within_at_inter (h : t ∈ 𝓝 x) :
has_fderiv_within_at f f' (s ∩ t) x ↔ has_fderiv_within_at f f' s x :=
by simp [has_fderiv_within_at, nhds_within_restrict' s h]
lemma has_fderiv_within_at.union (hs : has_fderiv_within_at f f' s x)
(ht : has_fderiv_within_at f f' t x) :
has_fderiv_within_at f f' (s ∪ t) x :=
begin
simp only [has_fderiv_within_at, nhds_within_union],
exact hs.sup ht,
end
lemma has_fderiv_within_at.nhds_within (h : has_fderiv_within_at f f' s x)
(ht : s ∈ 𝓝[t] x) : has_fderiv_within_at f f' t x :=
(has_fderiv_within_at_inter' ht).1 (h.mono (inter_subset_right _ _))
lemma has_fderiv_within_at.has_fderiv_at (h : has_fderiv_within_at f f' s x) (hs : s ∈ 𝓝 x) :
has_fderiv_at f f' x :=
by rwa [← univ_inter s, has_fderiv_within_at_inter hs, has_fderiv_within_at_univ] at h
lemma differentiable_within_at.differentiable_at
(h : differentiable_within_at 𝕜 f s x) (hs : s ∈ 𝓝 x) : differentiable_at 𝕜 f x :=
h.imp (λ f' hf', hf'.has_fderiv_at hs)
lemma differentiable_within_at.has_fderiv_within_at (h : differentiable_within_at 𝕜 f s x) :
has_fderiv_within_at f (fderiv_within 𝕜 f s x) s x :=
begin
dunfold fderiv_within,
dunfold differentiable_within_at at h,
rw dif_pos h,
exact classical.some_spec h
end
lemma differentiable_at.has_fderiv_at (h : differentiable_at 𝕜 f x) :
has_fderiv_at f (fderiv 𝕜 f x) x :=
begin
dunfold fderiv,
dunfold differentiable_at at h,
rw dif_pos h,
exact classical.some_spec h
end
lemma differentiable_on.has_fderiv_at (h : differentiable_on 𝕜 f s) (hs : s ∈ 𝓝 x) :
has_fderiv_at f (fderiv 𝕜 f x) x :=
((h x (mem_of_mem_nhds hs)).differentiable_at hs).has_fderiv_at
lemma differentiable_on.differentiable_at (h : differentiable_on 𝕜 f s) (hs : s ∈ 𝓝 x) :
differentiable_at 𝕜 f x :=
(h.has_fderiv_at hs).differentiable_at
lemma differentiable_on.eventually_differentiable_at (h : differentiable_on 𝕜 f s) (hs : s ∈ 𝓝 x) :
∀ᶠ y in 𝓝 x, differentiable_at 𝕜 f y :=
(eventually_eventually_nhds.2 hs).mono $ λ y, h.differentiable_at
lemma has_fderiv_at.fderiv (h : has_fderiv_at f f' x) : fderiv 𝕜 f x = f' :=
by { ext, rw h.unique h.differentiable_at.has_fderiv_at }
lemma fderiv_eq {f' : E → E →L[𝕜] F} (h : ∀ x, has_fderiv_at f (f' x) x) : fderiv 𝕜 f = f' :=
funext $ λ x, (h x).fderiv
/-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz
on a neighborhood of `x₀` then it its derivative at `x₀` has norm bounded by `C`.
Version using `fderiv`. -/
lemma fderiv_at.le_of_lip {f : E → F} {x₀ : E} (hf : differentiable_at 𝕜 f x₀)
{s : set E} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : lipschitz_on_with C f s) : ∥fderiv 𝕜 f x₀∥ ≤ C :=
hf.has_fderiv_at.le_of_lip hs hlip
lemma has_fderiv_within_at.fderiv_within
(h : has_fderiv_within_at f f' s x) (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 f s x = f' :=
(hxs.eq h h.differentiable_within_at.has_fderiv_within_at).symm
/-- If `x` is not in the closure of `s`, then `f` has any derivative at `x` within `s`,
as this statement is empty. -/
lemma has_fderiv_within_at_of_not_mem_closure (h : x ∉ closure s) :
has_fderiv_within_at f f' s x :=
begin
simp only [mem_closure_iff_nhds_within_ne_bot, ne_bot_iff, ne.def, not_not] at h,
simp [has_fderiv_within_at, has_fderiv_at_filter, h, is_o, is_O_with],
end
lemma differentiable_within_at.mono (h : differentiable_within_at 𝕜 f t x) (st : s ⊆ t) :
differentiable_within_at 𝕜 f s x :=
begin
rcases h with ⟨f', hf'⟩,
exact ⟨f', hf'.mono st⟩
end
lemma differentiable_within_at.mono_of_mem (h : differentiable_within_at 𝕜 f s x) {t : set E}
(hst : s ∈ nhds_within x t) :
differentiable_within_at 𝕜 f t x :=
(h.has_fderiv_within_at.mono_of_mem hst).differentiable_within_at
lemma differentiable_within_at_univ :
differentiable_within_at 𝕜 f univ x ↔ differentiable_at 𝕜 f x :=
by simp only [differentiable_within_at, has_fderiv_within_at_univ, differentiable_at]
lemma differentiable_within_at_inter (ht : t ∈ 𝓝 x) :
differentiable_within_at 𝕜 f (s ∩ t) x ↔ differentiable_within_at 𝕜 f s x :=
by simp only [differentiable_within_at, has_fderiv_within_at, has_fderiv_at_filter,
nhds_within_restrict' s ht]
lemma differentiable_within_at_inter' (ht : t ∈ 𝓝[s] x) :
differentiable_within_at 𝕜 f (s ∩ t) x ↔ differentiable_within_at 𝕜 f s x :=
by simp only [differentiable_within_at, has_fderiv_within_at, has_fderiv_at_filter,
nhds_within_restrict'' s ht]
lemma differentiable_within_at.antimono (h : differentiable_within_at 𝕜 f s x) (hst : s ⊆ t)
(hx : s ∈ 𝓝[t] x) :
differentiable_within_at 𝕜 f t x :=
by rwa [← differentiable_within_at_inter' hx, inter_eq_self_of_subset_right hst]
lemma has_fderiv_within_at.antimono (h : has_fderiv_within_at f f' s x) (hst : s ⊆ t)
(hs : unique_diff_within_at 𝕜 s x) (hx : s ∈ 𝓝[t] x) :
has_fderiv_within_at f f' t x :=
begin
have h' : has_fderiv_within_at f _ t x :=
(h.differentiable_within_at.antimono hst hx).has_fderiv_within_at,
rwa hs.eq h (h'.mono hst),
end
lemma differentiable_at.differentiable_within_at
(h : differentiable_at 𝕜 f x) : differentiable_within_at 𝕜 f s x :=
(differentiable_within_at_univ.2 h).mono (subset_univ _)
lemma differentiable.differentiable_at (h : differentiable 𝕜 f) :
differentiable_at 𝕜 f x :=
h x
lemma differentiable_at.fderiv_within
(h : differentiable_at 𝕜 f x) (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 f s x = fderiv 𝕜 f x :=
begin
apply has_fderiv_within_at.fderiv_within _ hxs,
exact h.has_fderiv_at.has_fderiv_within_at
end
lemma differentiable_on.mono (h : differentiable_on 𝕜 f t) (st : s ⊆ t) :
differentiable_on 𝕜 f s :=
λx hx, (h x (st hx)).mono st
lemma differentiable_on_univ :
differentiable_on 𝕜 f univ ↔ differentiable 𝕜 f :=
by { simp [differentiable_on, differentiable_within_at_univ], refl }
lemma differentiable.differentiable_on (h : differentiable 𝕜 f) : differentiable_on 𝕜 f s :=
(differentiable_on_univ.2 h).mono (subset_univ _)
lemma differentiable_on_of_locally_differentiable_on
(h : ∀x∈s, ∃u, is_open u ∧ x ∈ u ∧ differentiable_on 𝕜 f (s ∩ u)) : differentiable_on 𝕜 f s :=
begin
assume x xs,
rcases h x xs with ⟨t, t_open, xt, ht⟩,
exact (differentiable_within_at_inter (is_open.mem_nhds t_open xt)).1 (ht x ⟨xs, xt⟩)
end
lemma fderiv_within_subset (st : s ⊆ t) (ht : unique_diff_within_at 𝕜 s x)
(h : differentiable_within_at 𝕜 f t x) :
fderiv_within 𝕜 f s x = fderiv_within 𝕜 f t x :=
((differentiable_within_at.has_fderiv_within_at h).mono st).fderiv_within ht
lemma fderiv_within_subset' (st : s ⊆ t) (ht : unique_diff_within_at 𝕜 s x) (hx : s ∈ 𝓝[t] x)
(h : differentiable_within_at 𝕜 f s x) :
fderiv_within 𝕜 f s x = fderiv_within 𝕜 f t x :=
fderiv_within_subset st ht (h.antimono st hx)
@[simp] lemma fderiv_within_univ : fderiv_within 𝕜 f univ = fderiv 𝕜 f :=
begin
ext x : 1,
by_cases h : differentiable_at 𝕜 f x,
{ apply has_fderiv_within_at.fderiv_within _ unique_diff_within_at_univ,
rw has_fderiv_within_at_univ,
apply h.has_fderiv_at },
{ have : ¬ differentiable_within_at 𝕜 f univ x,
by contrapose! h; rwa ← differentiable_within_at_univ,
rw [fderiv_zero_of_not_differentiable_at h,
fderiv_within_zero_of_not_differentiable_within_at this] }
end
lemma fderiv_within_inter (ht : t ∈ 𝓝 x) (hs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 f (s ∩ t) x = fderiv_within 𝕜 f s x :=
begin
by_cases h : differentiable_within_at 𝕜 f (s ∩ t) x,
{ apply fderiv_within_subset (inter_subset_left _ _) _ ((differentiable_within_at_inter ht).1 h),
apply hs.inter ht },
{ have : ¬ differentiable_within_at 𝕜 f s x,
by contrapose! h; rw differentiable_within_at_inter; assumption,
rw [fderiv_within_zero_of_not_differentiable_within_at h,
fderiv_within_zero_of_not_differentiable_within_at this] }
end
lemma fderiv_within_of_mem_nhds (h : s ∈ 𝓝 x) :
fderiv_within 𝕜 f s x = fderiv 𝕜 f x :=
begin
have : s = univ ∩ s, by simp only [univ_inter],
rw [this, ← fderiv_within_univ],
exact fderiv_within_inter h (unique_diff_on_univ _ (mem_univ _))
end
lemma fderiv_within_of_open (hs : is_open s) (hx : x ∈ s) :
fderiv_within 𝕜 f s x = fderiv 𝕜 f x :=
fderiv_within_of_mem_nhds (is_open.mem_nhds hs hx)
lemma fderiv_within_eq_fderiv (hs : unique_diff_within_at 𝕜 s x) (h : differentiable_at 𝕜 f x) :
fderiv_within 𝕜 f s x = fderiv 𝕜 f x :=
begin
rw ← fderiv_within_univ,
exact fderiv_within_subset (subset_univ _) hs h.differentiable_within_at
end
lemma fderiv_mem_iff {f : E → F} {s : set (E →L[𝕜] F)} {x : E} :
fderiv 𝕜 f x ∈ s ↔ (differentiable_at 𝕜 f x ∧ fderiv 𝕜 f x ∈ s) ∨
(¬differentiable_at 𝕜 f x ∧ (0 : E →L[𝕜] F) ∈ s) :=
by by_cases hx : differentiable_at 𝕜 f x; simp [fderiv_zero_of_not_differentiable_at, *]
lemma fderiv_within_mem_iff {f : E → F} {t : set E} {s : set (E →L[𝕜] F)} {x : E} :
fderiv_within 𝕜 f t x ∈ s ↔ (differentiable_within_at 𝕜 f t x ∧ fderiv_within 𝕜 f t x ∈ s) ∨
(¬differentiable_within_at 𝕜 f t x ∧ (0 : E →L[𝕜] F) ∈ s) :=
by by_cases hx : differentiable_within_at 𝕜 f t x;
simp [fderiv_within_zero_of_not_differentiable_within_at, *]
end fderiv_properties
section continuous
/-! ### Deducing continuity from differentiability -/
theorem has_fderiv_at_filter.tendsto_nhds
(hL : L ≤ 𝓝 x) (h : has_fderiv_at_filter f f' x L) :
tendsto f L (𝓝 (f x)) :=
begin
have : tendsto (λ x', f x' - f x) L (𝓝 0),
{ refine h.is_O_sub.trans_tendsto (tendsto.mono_left _ hL),
rw ← sub_self x, exact tendsto_id.sub tendsto_const_nhds },
have := tendsto.add this tendsto_const_nhds,
rw zero_add (f x) at this,
exact this.congr (by simp)
end
theorem has_fderiv_within_at.continuous_within_at
(h : has_fderiv_within_at f f' s x) : continuous_within_at f s x :=
has_fderiv_at_filter.tendsto_nhds inf_le_left h
theorem has_fderiv_at.continuous_at (h : has_fderiv_at f f' x) :
continuous_at f x :=
has_fderiv_at_filter.tendsto_nhds le_rfl h
lemma differentiable_within_at.continuous_within_at (h : differentiable_within_at 𝕜 f s x) :
continuous_within_at f s x :=
let ⟨f', hf'⟩ := h in hf'.continuous_within_at
lemma differentiable_at.continuous_at (h : differentiable_at 𝕜 f x) : continuous_at f x :=
let ⟨f', hf'⟩ := h in hf'.continuous_at
lemma differentiable_on.continuous_on (h : differentiable_on 𝕜 f s) : continuous_on f s :=
λx hx, (h x hx).continuous_within_at
lemma differentiable.continuous (h : differentiable 𝕜 f) : continuous f :=
continuous_iff_continuous_at.2 $ λx, (h x).continuous_at
protected lemma has_strict_fderiv_at.continuous_at (hf : has_strict_fderiv_at f f' x) :
continuous_at f x :=
hf.has_fderiv_at.continuous_at
lemma has_strict_fderiv_at.is_O_sub_rev {f' : E ≃L[𝕜] F}
(hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) x) :
(λ p : E × E, p.1 - p.2) =O[𝓝 (x, x)](λ p : E × E, f p.1 - f p.2) :=
((f'.is_O_comp_rev _ _).trans (hf.trans_is_O (f'.is_O_comp_rev _ _)).right_is_O_add).congr
(λ _, rfl) (λ _, sub_add_cancel _ _)
lemma has_fderiv_at_filter.is_O_sub_rev (hf : has_fderiv_at_filter f f' x L) {C}
(hf' : antilipschitz_with C f') :
(λ x', x' - x) =O[L] (λ x', f x' - f x) :=
have (λ x', x' - x) =O[L] (λ x', f' (x' - x)),
from is_O_iff.2 ⟨C, eventually_of_forall $ λ x',
add_monoid_hom_class.bound_of_antilipschitz f' hf' _⟩,
(this.trans (hf.trans_is_O this).right_is_O_add).congr (λ _, rfl) (λ _, sub_add_cancel _ _)
end continuous
section congr
/-! ### congr properties of the derivative -/
theorem filter.eventually_eq.has_strict_fderiv_at_iff
(h : f₀ =ᶠ[𝓝 x] f₁) (h' : ∀ y, f₀' y = f₁' y) :
has_strict_fderiv_at f₀ f₀' x ↔ has_strict_fderiv_at f₁ f₁' x :=
begin
refine is_o_congr ((h.prod_mk_nhds h).mono _) (eventually_of_forall $ λ _, rfl),
rintros p ⟨hp₁, hp₂⟩,
simp only [*]
end
theorem has_strict_fderiv_at.congr_of_eventually_eq (h : has_strict_fderiv_at f f' x)
(h₁ : f =ᶠ[𝓝 x] f₁) : has_strict_fderiv_at f₁ f' x :=
(h₁.has_strict_fderiv_at_iff (λ _, rfl)).1 h
theorem filter.eventually_eq.has_fderiv_at_filter_iff
(h₀ : f₀ =ᶠ[L] f₁) (hx : f₀ x = f₁ x) (h₁ : ∀ x, f₀' x = f₁' x) :
has_fderiv_at_filter f₀ f₀' x L ↔ has_fderiv_at_filter f₁ f₁' x L :=
is_o_congr (h₀.mono $ λ y hy, by simp only [hy, h₁, hx]) (eventually_of_forall $ λ _, rfl)
lemma has_fderiv_at_filter.congr_of_eventually_eq (h : has_fderiv_at_filter f f' x L)
(hL : f₁ =ᶠ[L] f) (hx : f₁ x = f x) : has_fderiv_at_filter f₁ f' x L :=
(hL.has_fderiv_at_filter_iff hx $ λ _, rfl).2 h
theorem filter.eventually_eq.has_fderiv_at_iff (h : f₀ =ᶠ[𝓝 x] f₁) :
has_fderiv_at f₀ f' x ↔ has_fderiv_at f₁ f' x :=
h.has_fderiv_at_filter_iff h.eq_of_nhds (λ _, rfl)
theorem filter.eventually_eq.differentiable_at_iff (h : f₀ =ᶠ[𝓝 x] f₁) :
differentiable_at 𝕜 f₀ x ↔ differentiable_at 𝕜 f₁ x :=
exists_congr $ λ f', h.has_fderiv_at_iff
theorem filter.eventually_eq.has_fderiv_within_at_iff (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : f₀ x = f₁ x) :
has_fderiv_within_at f₀ f' s x ↔ has_fderiv_within_at f₁ f' s x :=
h.has_fderiv_at_filter_iff hx (λ _, rfl)
theorem filter.eventually_eq.has_fderiv_within_at_iff_of_mem (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : x ∈ s) :
has_fderiv_within_at f₀ f' s x ↔ has_fderiv_within_at f₁ f' s x :=
h.has_fderiv_within_at_iff (h.eq_of_nhds_within hx)
theorem filter.eventually_eq.differentiable_within_at_iff (h : f₀ =ᶠ[𝓝[s] x] f₁)
(hx : f₀ x = f₁ x) :
differentiable_within_at 𝕜 f₀ s x ↔ differentiable_within_at 𝕜 f₁ s x :=
exists_congr $ λ f', h.has_fderiv_within_at_iff hx
theorem filter.eventually_eq.differentiable_within_at_iff_of_mem (h : f₀ =ᶠ[𝓝[s] x] f₁)
(hx : x ∈ s) :
differentiable_within_at 𝕜 f₀ s x ↔ differentiable_within_at 𝕜 f₁ s x :=
h.differentiable_within_at_iff (h.eq_of_nhds_within hx)
lemma has_fderiv_within_at.congr_mono (h : has_fderiv_within_at f f' s x) (ht : ∀x ∈ t, f₁ x = f x)
(hx : f₁ x = f x) (h₁ : t ⊆ s) : has_fderiv_within_at f₁ f' t x :=
has_fderiv_at_filter.congr_of_eventually_eq (h.mono h₁) (filter.mem_inf_of_right ht) hx
lemma has_fderiv_within_at.congr (h : has_fderiv_within_at f f' s x) (hs : ∀x ∈ s, f₁ x = f x)
(hx : f₁ x = f x) : has_fderiv_within_at f₁ f' s x :=
h.congr_mono hs hx (subset.refl _)
lemma has_fderiv_within_at.congr' (h : has_fderiv_within_at f f' s x) (hs : ∀x ∈ s, f₁ x = f x)
(hx : x ∈ s) : has_fderiv_within_at f₁ f' s x :=
h.congr hs (hs x hx)
lemma has_fderiv_within_at.congr_of_eventually_eq (h : has_fderiv_within_at f f' s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : has_fderiv_within_at f₁ f' s x :=
has_fderiv_at_filter.congr_of_eventually_eq h h₁ hx
lemma has_fderiv_at.congr_of_eventually_eq (h : has_fderiv_at f f' x)
(h₁ : f₁ =ᶠ[𝓝 x] f) : has_fderiv_at f₁ f' x :=
has_fderiv_at_filter.congr_of_eventually_eq h h₁ (mem_of_mem_nhds h₁ : _)
lemma differentiable_within_at.congr_mono (h : differentiable_within_at 𝕜 f s x)
(ht : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (h₁ : t ⊆ s) : differentiable_within_at 𝕜 f₁ t x :=
(has_fderiv_within_at.congr_mono h.has_fderiv_within_at ht hx h₁).differentiable_within_at
lemma differentiable_within_at.congr (h : differentiable_within_at 𝕜 f s x)
(ht : ∀x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : differentiable_within_at 𝕜 f₁ s x :=
differentiable_within_at.congr_mono h ht hx (subset.refl _)
lemma differentiable_within_at.congr_of_eventually_eq
(h : differentiable_within_at 𝕜 f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f)
(hx : f₁ x = f x) : differentiable_within_at 𝕜 f₁ s x :=
(h.has_fderiv_within_at.congr_of_eventually_eq h₁ hx).differentiable_within_at
lemma differentiable_on.congr_mono (h : differentiable_on 𝕜 f s) (h' : ∀x ∈ t, f₁ x = f x)
(h₁ : t ⊆ s) : differentiable_on 𝕜 f₁ t :=
λ x hx, (h x (h₁ hx)).congr_mono h' (h' x hx) h₁
lemma differentiable_on.congr (h : differentiable_on 𝕜 f s) (h' : ∀x ∈ s, f₁ x = f x) :
differentiable_on 𝕜 f₁ s :=
λ x hx, (h x hx).congr h' (h' x hx)
lemma differentiable_on_congr (h' : ∀x ∈ s, f₁ x = f x) :
differentiable_on 𝕜 f₁ s ↔ differentiable_on 𝕜 f s :=
⟨λ h, differentiable_on.congr h (λy hy, (h' y hy).symm),
λ h, differentiable_on.congr h h'⟩
lemma differentiable_at.congr_of_eventually_eq (h : differentiable_at 𝕜 f x) (hL : f₁ =ᶠ[𝓝 x] f) :
differentiable_at 𝕜 f₁ x :=
hL.differentiable_at_iff.2 h
lemma differentiable_within_at.fderiv_within_congr_mono (h : differentiable_within_at 𝕜 f s x)
(hs : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (hxt : unique_diff_within_at 𝕜 t x) (h₁ : t ⊆ s) :
fderiv_within 𝕜 f₁ t x = fderiv_within 𝕜 f s x :=
(has_fderiv_within_at.congr_mono h.has_fderiv_within_at hs hx h₁).fderiv_within hxt
lemma filter.eventually_eq.fderiv_within_eq (hs : unique_diff_within_at 𝕜 s x)
(hL : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) :
fderiv_within 𝕜 f₁ s x = fderiv_within 𝕜 f s x :=
if h : differentiable_within_at 𝕜 f s x
then has_fderiv_within_at.fderiv_within (h.has_fderiv_within_at.congr_of_eventually_eq hL hx) hs
else
have h' : ¬ differentiable_within_at 𝕜 f₁ s x,
from mt (λ h, h.congr_of_eventually_eq (hL.mono $ λ x, eq.symm) hx.symm) h,
by rw [fderiv_within_zero_of_not_differentiable_within_at h,
fderiv_within_zero_of_not_differentiable_within_at h']
lemma filter.eventually_eq.fderiv_within_eq_nhds (hs : unique_diff_within_at 𝕜 s x)
(hL : f₁ =ᶠ[𝓝 x] f) :
fderiv_within 𝕜 f₁ s x = fderiv_within 𝕜 f s x :=
(show f₁ =ᶠ[𝓝[s] x] f, from nhds_within_le_nhds hL).fderiv_within_eq hs (mem_of_mem_nhds hL : _)
lemma fderiv_within_congr (hs : unique_diff_within_at 𝕜 s x)
(hL : ∀y∈s, f₁ y = f y) (hx : f₁ x = f x) :
fderiv_within 𝕜 f₁ s x = fderiv_within 𝕜 f s x :=
begin
apply filter.eventually_eq.fderiv_within_eq hs _ hx,
apply mem_of_superset self_mem_nhds_within,
exact hL
end
lemma filter.eventually_eq.fderiv_eq (hL : f₁ =ᶠ[𝓝 x] f) :
fderiv 𝕜 f₁ x = fderiv 𝕜 f x :=
begin
have A : f₁ x = f x := hL.eq_of_nhds,
rw [← fderiv_within_univ, ← fderiv_within_univ],
rw ← nhds_within_univ at hL,
exact hL.fderiv_within_eq unique_diff_within_at_univ A
end
protected lemma filter.eventually_eq.fderiv (h : f₁ =ᶠ[𝓝 x] f) :
fderiv 𝕜 f₁ =ᶠ[𝓝 x] fderiv 𝕜 f :=
h.eventually_eq_nhds.mono $ λ x h, h.fderiv_eq
end congr
section id
/-! ### Derivative of the identity -/
theorem has_strict_fderiv_at_id (x : E) :
has_strict_fderiv_at id (id 𝕜 E) x :=
(is_o_zero _ _).congr_left $ by simp
theorem has_fderiv_at_filter_id (x : E) (L : filter E) :
has_fderiv_at_filter id (id 𝕜 E) x L :=
(is_o_zero _ _).congr_left $ by simp
theorem has_fderiv_within_at_id (x : E) (s : set E) :
has_fderiv_within_at id (id 𝕜 E) s x :=
has_fderiv_at_filter_id _ _
theorem has_fderiv_at_id (x : E) : has_fderiv_at id (id 𝕜 E) x :=
has_fderiv_at_filter_id _ _
@[simp] lemma differentiable_at_id : differentiable_at 𝕜 id x :=
(has_fderiv_at_id x).differentiable_at
@[simp] lemma differentiable_at_id' : differentiable_at 𝕜 (λ x, x) x :=
(has_fderiv_at_id x).differentiable_at
lemma differentiable_within_at_id : differentiable_within_at 𝕜 id s x :=
differentiable_at_id.differentiable_within_at
@[simp] lemma differentiable_id : differentiable 𝕜 (id : E → E) :=
λx, differentiable_at_id
@[simp] lemma differentiable_id' : differentiable 𝕜 (λ (x : E), x) :=
λx, differentiable_at_id
lemma differentiable_on_id : differentiable_on 𝕜 id s :=
differentiable_id.differentiable_on
lemma fderiv_id : fderiv 𝕜 id x = id 𝕜 E :=
has_fderiv_at.fderiv (has_fderiv_at_id x)
@[simp] lemma fderiv_id' : fderiv 𝕜 (λ (x : E), x) x = continuous_linear_map.id 𝕜 E :=
fderiv_id
lemma fderiv_within_id (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 id s x = id 𝕜 E :=
begin
rw differentiable_at.fderiv_within (differentiable_at_id) hxs,
exact fderiv_id
end
lemma fderiv_within_id' (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (λ (x : E), x) s x = continuous_linear_map.id 𝕜 E :=
fderiv_within_id hxs
end id
section const
/-! ### derivative of a constant function -/
theorem has_strict_fderiv_at_const (c : F) (x : E) :
has_strict_fderiv_at (λ _, c) (0 : E →L[𝕜] F) x :=
(is_o_zero _ _).congr_left $ λ _, by simp only [zero_apply, sub_self]
theorem has_fderiv_at_filter_const (c : F) (x : E) (L : filter E) :
has_fderiv_at_filter (λ x, c) (0 : E →L[𝕜] F) x L :=
(is_o_zero _ _).congr_left $ λ _, by simp only [zero_apply, sub_self]
theorem has_fderiv_within_at_const (c : F) (x : E) (s : set E) :
has_fderiv_within_at (λ x, c) (0 : E →L[𝕜] F) s x :=
has_fderiv_at_filter_const _ _ _
theorem has_fderiv_at_const (c : F) (x : E) :
has_fderiv_at (λ x, c) (0 : E →L[𝕜] F) x :=
has_fderiv_at_filter_const _ _ _
@[simp] lemma differentiable_at_const (c : F) : differentiable_at 𝕜 (λx, c) x :=
⟨0, has_fderiv_at_const c x⟩
lemma differentiable_within_at_const (c : F) : differentiable_within_at 𝕜 (λx, c) s x :=
differentiable_at.differentiable_within_at (differentiable_at_const _)
lemma fderiv_const_apply (c : F) : fderiv 𝕜 (λy, c) x = 0 :=
has_fderiv_at.fderiv (has_fderiv_at_const c x)
@[simp] lemma fderiv_const (c : F) : fderiv 𝕜 (λ (y : E), c) = 0 :=
by { ext m, rw fderiv_const_apply, refl }
lemma fderiv_within_const_apply (c : F) (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (λy, c) s x = 0 :=
begin
rw differentiable_at.fderiv_within (differentiable_at_const _) hxs,
exact fderiv_const_apply _
end
@[simp] lemma differentiable_const (c : F) : differentiable 𝕜 (λx : E, c) :=
λx, differentiable_at_const _
lemma differentiable_on_const (c : F) : differentiable_on 𝕜 (λx, c) s :=
(differentiable_const _).differentiable_on
lemma has_fderiv_within_at_singleton (f : E → F) (x : E) :
has_fderiv_within_at f (0 : E →L[𝕜] F) {x} x :=
by simp only [has_fderiv_within_at, nhds_within_singleton, has_fderiv_at_filter, is_o_pure,
continuous_linear_map.zero_apply, sub_self]
lemma has_fderiv_at_of_subsingleton [h : subsingleton E] (f : E → F) (x : E) :
has_fderiv_at f (0 : E →L[𝕜] F) x :=
begin
rw [← has_fderiv_within_at_univ, subsingleton_univ.eq_singleton_of_mem (mem_univ x)],
exact has_fderiv_within_at_singleton f x
end
lemma differentiable_on_empty : differentiable_on 𝕜 f ∅ := λ x, false.elim
lemma differentiable_on_singleton : differentiable_on 𝕜 f {x} :=
forall_eq.2 (has_fderiv_within_at_singleton f x).differentiable_within_at
lemma set.subsingleton.differentiable_on (hs : s.subsingleton) : differentiable_on 𝕜 f s :=
hs.induction_on differentiable_on_empty (λ x, differentiable_on_singleton)
end const
section continuous_linear_map
/-!
### Continuous linear maps
There are currently two variants of these in mathlib, the bundled version
(named `continuous_linear_map`, and denoted `E →L[𝕜] F`), and the unbundled version (with a
predicate `is_bounded_linear_map`). We give statements for both versions. -/
protected theorem continuous_linear_map.has_strict_fderiv_at {x : E} :
has_strict_fderiv_at e e x :=
(is_o_zero _ _).congr_left $ λ x, by simp only [e.map_sub, sub_self]
protected lemma continuous_linear_map.has_fderiv_at_filter :
has_fderiv_at_filter e e x L :=
(is_o_zero _ _).congr_left $ λ x, by simp only [e.map_sub, sub_self]
protected lemma continuous_linear_map.has_fderiv_within_at : has_fderiv_within_at e e s x :=
e.has_fderiv_at_filter
protected lemma continuous_linear_map.has_fderiv_at : has_fderiv_at e e x :=
e.has_fderiv_at_filter
@[simp] protected lemma continuous_linear_map.differentiable_at : differentiable_at 𝕜 e x :=
e.has_fderiv_at.differentiable_at
protected lemma continuous_linear_map.differentiable_within_at : differentiable_within_at 𝕜 e s x :=
e.differentiable_at.differentiable_within_at
@[simp] protected lemma continuous_linear_map.fderiv : fderiv 𝕜 e x = e :=
e.has_fderiv_at.fderiv
protected lemma continuous_linear_map.fderiv_within (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 e s x = e :=
begin
rw differentiable_at.fderiv_within e.differentiable_at hxs,
exact e.fderiv
end
@[simp] protected lemma continuous_linear_map.differentiable : differentiable 𝕜 e :=
λx, e.differentiable_at
protected lemma continuous_linear_map.differentiable_on : differentiable_on 𝕜 e s :=
e.differentiable.differentiable_on
lemma is_bounded_linear_map.has_fderiv_at_filter (h : is_bounded_linear_map 𝕜 f) :
has_fderiv_at_filter f h.to_continuous_linear_map x L :=
h.to_continuous_linear_map.has_fderiv_at_filter
lemma is_bounded_linear_map.has_fderiv_within_at (h : is_bounded_linear_map 𝕜 f) :
has_fderiv_within_at f h.to_continuous_linear_map s x :=
h.has_fderiv_at_filter
lemma is_bounded_linear_map.has_fderiv_at (h : is_bounded_linear_map 𝕜 f) :
has_fderiv_at f h.to_continuous_linear_map x :=
h.has_fderiv_at_filter
lemma is_bounded_linear_map.differentiable_at (h : is_bounded_linear_map 𝕜 f) :
differentiable_at 𝕜 f x :=
h.has_fderiv_at.differentiable_at
lemma is_bounded_linear_map.differentiable_within_at (h : is_bounded_linear_map 𝕜 f) :
differentiable_within_at 𝕜 f s x :=
h.differentiable_at.differentiable_within_at
lemma is_bounded_linear_map.fderiv (h : is_bounded_linear_map 𝕜 f) :
fderiv 𝕜 f x = h.to_continuous_linear_map :=
has_fderiv_at.fderiv (h.has_fderiv_at)
lemma is_bounded_linear_map.fderiv_within (h : is_bounded_linear_map 𝕜 f)
(hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 f s x = h.to_continuous_linear_map :=
begin
rw differentiable_at.fderiv_within h.differentiable_at hxs,
exact h.fderiv
end
lemma is_bounded_linear_map.differentiable (h : is_bounded_linear_map 𝕜 f) :
differentiable 𝕜 f :=
λx, h.differentiable_at
lemma is_bounded_linear_map.differentiable_on (h : is_bounded_linear_map 𝕜 f) :
differentiable_on 𝕜 f s :=
h.differentiable.differentiable_on
end continuous_linear_map
section composition
/-!
### Derivative of the composition of two functions
For composition lemmas, we put x explicit to help the elaborator, as otherwise Lean tends to
get confused since there are too many possibilities for composition -/
variable (x)
theorem has_fderiv_at_filter.comp {g : F → G} {g' : F →L[𝕜] G} {L' : filter F}
(hg : has_fderiv_at_filter g g' (f x) L')
(hf : has_fderiv_at_filter f f' x L) (hL : tendsto f L L') :
has_fderiv_at_filter (g ∘ f) (g'.comp f') x L :=
let eq₁ := (g'.is_O_comp _ _).trans_is_o hf in
let eq₂ := (hg.comp_tendsto hL).trans_is_O hf.is_O_sub in
by { refine eq₂.triangle (eq₁.congr_left (λ x', _)), simp }
/- A readable version of the previous theorem,
a general form of the chain rule. -/
example {g : F → G} {g' : F →L[𝕜] G}
(hg : has_fderiv_at_filter g g' (f x) (L.map f))
(hf : has_fderiv_at_filter f f' x L) :
has_fderiv_at_filter (g ∘ f) (g'.comp f') x L :=
begin
unfold has_fderiv_at_filter at hg,
have := calc (λ x', g (f x') - g (f x) - g' (f x' - f x)) =o[L] (λ x', f x' - f x) :
hg.comp_tendsto le_rfl
... =O[L] (λ x', x' - x) : hf.is_O_sub,
refine this.triangle _,
calc (λ x' : E, g' (f x' - f x) - g'.comp f' (x' - x))
=ᶠ[L] λ x', g' (f x' - f x - f' (x' - x)) : eventually_of_forall (λ x', by simp)
... =O[L] λ x', f x' - f x - f' (x' - x) : g'.is_O_comp _ _
... =o[L] λ x', x' - x : hf
end
theorem has_fderiv_within_at.comp {g : F → G} {g' : F →L[𝕜] G} {t : set F}
(hg : has_fderiv_within_at g g' t (f x)) (hf : has_fderiv_within_at f f' s x)
(hst : maps_to f s t) :
has_fderiv_within_at (g ∘ f) (g'.comp f') s x :=
hg.comp x hf $ hf.continuous_within_at.tendsto_nhds_within hst
theorem has_fderiv_at.comp_has_fderiv_within_at {g : F → G} {g' : F →L[𝕜] G}
(hg : has_fderiv_at g g' (f x)) (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (g ∘ f) (g'.comp f') s x :=
hg.comp x hf hf.continuous_within_at
/-- The chain rule. -/
theorem has_fderiv_at.comp {g : F → G} {g' : F →L[𝕜] G}
(hg : has_fderiv_at g g' (f x)) (hf : has_fderiv_at f f' x) :
has_fderiv_at (g ∘ f) (g'.comp f') x :=
hg.comp x hf hf.continuous_at
lemma differentiable_within_at.comp {g : F → G} {t : set F}
(hg : differentiable_within_at 𝕜 g t (f x)) (hf : differentiable_within_at 𝕜 f s x)
(h : maps_to f s t) : differentiable_within_at 𝕜 (g ∘ f) s x :=
(hg.has_fderiv_within_at.comp x hf.has_fderiv_within_at h).differentiable_within_at
lemma differentiable_within_at.comp' {g : F → G} {t : set F}
(hg : differentiable_within_at 𝕜 g t (f x)) (hf : differentiable_within_at 𝕜 f s x) :
differentiable_within_at 𝕜 (g ∘ f) (s ∩ f⁻¹' t) x :=
hg.comp x (hf.mono (inter_subset_left _ _)) (inter_subset_right _ _)
lemma differentiable_at.comp {g : F → G}
(hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_at 𝕜 f x) :
differentiable_at 𝕜 (g ∘ f) x :=
(hg.has_fderiv_at.comp x hf.has_fderiv_at).differentiable_at
lemma differentiable_at.comp_differentiable_within_at {g : F → G}
(hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_within_at 𝕜 f s x) :
differentiable_within_at 𝕜 (g ∘ f) s x :=
hg.differentiable_within_at.comp x hf (maps_to_univ _ _)
lemma fderiv_within.comp {g : F → G} {t : set F}
(hg : differentiable_within_at 𝕜 g t (f x)) (hf : differentiable_within_at 𝕜 f s x)
(h : maps_to f s t) (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (g ∘ f) s x = (fderiv_within 𝕜 g t (f x)).comp (fderiv_within 𝕜 f s x) :=
(hg.has_fderiv_within_at.comp x (hf.has_fderiv_within_at) h).fderiv_within hxs
/-- Ternary version of `fderiv_within.comp`, with equality assumptions of basepoints added, in
order to apply more easily as a rewrite from right-to-left. -/
lemma fderiv_within.comp₃ {g' : G → G'} {g : F → G} {t : set F} {u : set G} {y : F} {y' : G}
(hg' : differentiable_within_at 𝕜 g' u y') (hg : differentiable_within_at 𝕜 g t y)
(hf : differentiable_within_at 𝕜 f s x)
(h2g : maps_to g t u) (h2f : maps_to f s t)
(h3g : g y = y') (h3f : f x = y) (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (g' ∘ g ∘ f) s x = (fderiv_within 𝕜 g' u y').comp
((fderiv_within 𝕜 g t y).comp (fderiv_within 𝕜 f s x)) :=
begin
substs h3g h3f,
exact (hg'.has_fderiv_within_at.comp x
(hg.has_fderiv_within_at.comp x (hf.has_fderiv_within_at) h2f) $ h2g.comp h2f).fderiv_within hxs
end
lemma fderiv.comp {g : F → G}
(hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_at 𝕜 f x) :
fderiv 𝕜 (g ∘ f) x = (fderiv 𝕜 g (f x)).comp (fderiv 𝕜 f x) :=
(hg.has_fderiv_at.comp x hf.has_fderiv_at).fderiv
lemma fderiv.comp_fderiv_within {g : F → G}
(hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_within_at 𝕜 f s x)
(hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (g ∘ f) s x = (fderiv 𝕜 g (f x)).comp (fderiv_within 𝕜 f s x) :=
(hg.has_fderiv_at.comp_has_fderiv_within_at x hf.has_fderiv_within_at).fderiv_within hxs
lemma differentiable_on.comp {g : F → G} {t : set F}
(hg : differentiable_on 𝕜 g t) (hf : differentiable_on 𝕜 f s) (st : maps_to f s t) :
differentiable_on 𝕜 (g ∘ f) s :=
λx hx, differentiable_within_at.comp x (hg (f x) (st hx)) (hf x hx) st
lemma differentiable.comp {g : F → G} (hg : differentiable 𝕜 g) (hf : differentiable 𝕜 f) :
differentiable 𝕜 (g ∘ f) :=
λx, differentiable_at.comp x (hg (f x)) (hf x)
lemma differentiable.comp_differentiable_on {g : F → G} (hg : differentiable 𝕜 g)
(hf : differentiable_on 𝕜 f s) :
differentiable_on 𝕜 (g ∘ f) s :=
hg.differentiable_on.comp hf (maps_to_univ _ _)
/-- The chain rule for derivatives in the sense of strict differentiability. -/
protected lemma has_strict_fderiv_at.comp {g : F → G} {g' : F →L[𝕜] G}
(hg : has_strict_fderiv_at g g' (f x)) (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, g (f x)) (g'.comp f') x :=
((hg.comp_tendsto (hf.continuous_at.prod_map' hf.continuous_at)).trans_is_O hf.is_O_sub).triangle $
by simpa only [g'.map_sub, f'.coe_comp'] using (g'.is_O_comp _ _).trans_is_o hf
protected lemma differentiable.iterate {f : E → E} (hf : differentiable 𝕜 f) (n : ℕ) :
differentiable 𝕜 (f^[n]) :=
nat.rec_on n differentiable_id (λ n ihn, ihn.comp hf)
protected lemma differentiable_on.iterate {f : E → E} (hf : differentiable_on 𝕜 f s)
(hs : maps_to f s s) (n : ℕ) :
differentiable_on 𝕜 (f^[n]) s :=
nat.rec_on n differentiable_on_id (λ n ihn, ihn.comp hf hs)
variable {x}
protected lemma has_fderiv_at_filter.iterate {f : E → E} {f' : E →L[𝕜] E}
(hf : has_fderiv_at_filter f f' x L) (hL : tendsto f L L) (hx : f x = x) (n : ℕ) :
has_fderiv_at_filter (f^[n]) (f'^n) x L :=
begin
induction n with n ihn,
{ exact has_fderiv_at_filter_id x L },
{ rw [function.iterate_succ, pow_succ'],
rw ← hx at ihn,
exact ihn.comp x hf hL }
end
protected lemma has_fderiv_at.iterate {f : E → E} {f' : E →L[𝕜] E}
(hf : has_fderiv_at f f' x) (hx : f x = x) (n : ℕ) :
has_fderiv_at (f^[n]) (f'^n) x :=
begin
refine hf.iterate _ hx n,
convert hf.continuous_at,
exact hx.symm
end
protected lemma has_fderiv_within_at.iterate {f : E → E} {f' : E →L[𝕜] E}
(hf : has_fderiv_within_at f f' s x) (hx : f x = x) (hs : maps_to f s s) (n : ℕ) :
has_fderiv_within_at (f^[n]) (f'^n) s x :=
begin
refine hf.iterate _ hx n,
convert tendsto_inf.2 ⟨hf.continuous_within_at, _⟩,
exacts [hx.symm, (tendsto_principal_principal.2 hs).mono_left inf_le_right]
end
protected lemma has_strict_fderiv_at.iterate {f : E → E} {f' : E →L[𝕜] E}
(hf : has_strict_fderiv_at f f' x) (hx : f x = x) (n : ℕ) :
has_strict_fderiv_at (f^[n]) (f'^n) x :=
begin
induction n with n ihn,
{ exact has_strict_fderiv_at_id x },
{ rw [function.iterate_succ, pow_succ'],
rw ← hx at ihn,
exact ihn.comp x hf }
end
protected lemma differentiable_at.iterate {f : E → E} (hf : differentiable_at 𝕜 f x)
(hx : f x = x) (n : ℕ) :
differentiable_at 𝕜 (f^[n]) x :=
(hf.has_fderiv_at.iterate hx n).differentiable_at
protected lemma differentiable_within_at.iterate {f : E → E} (hf : differentiable_within_at 𝕜 f s x)
(hx : f x = x) (hs : maps_to f s s) (n : ℕ) :
differentiable_within_at 𝕜 (f^[n]) s x :=
(hf.has_fderiv_within_at.iterate hx hs n).differentiable_within_at
end composition
section cartesian_product
/-! ### Derivative of the cartesian product of two functions -/
section prod
variables {f₂ : E → G} {f₂' : E →L[𝕜] G}
protected lemma has_strict_fderiv_at.prod
(hf₁ : has_strict_fderiv_at f₁ f₁' x) (hf₂ : has_strict_fderiv_at f₂ f₂' x) :
has_strict_fderiv_at (λx, (f₁ x, f₂ x)) (f₁'.prod f₂') x :=
hf₁.prod_left hf₂
lemma has_fderiv_at_filter.prod
(hf₁ : has_fderiv_at_filter f₁ f₁' x L) (hf₂ : has_fderiv_at_filter f₂ f₂' x L) :
has_fderiv_at_filter (λx, (f₁ x, f₂ x)) (f₁'.prod f₂') x L :=
hf₁.prod_left hf₂
lemma has_fderiv_within_at.prod
(hf₁ : has_fderiv_within_at f₁ f₁' s x) (hf₂ : has_fderiv_within_at f₂ f₂' s x) :
has_fderiv_within_at (λx, (f₁ x, f₂ x)) (f₁'.prod f₂') s x :=
hf₁.prod hf₂
lemma has_fderiv_at.prod (hf₁ : has_fderiv_at f₁ f₁' x) (hf₂ : has_fderiv_at f₂ f₂' x) :
has_fderiv_at (λx, (f₁ x, f₂ x)) (f₁'.prod f₂') x :=
hf₁.prod hf₂
lemma has_fderiv_at_prod_mk_left (e₀ : E) (f₀ : F) :
has_fderiv_at (λ e : E, (e, f₀)) (inl 𝕜 E F) e₀ :=
(has_fderiv_at_id e₀).prod (has_fderiv_at_const f₀ e₀)
lemma has_fderiv_at_prod_mk_right (e₀ : E) (f₀ : F) :
has_fderiv_at (λ f : F, (e₀, f)) (inr 𝕜 E F) f₀ :=
(has_fderiv_at_const e₀ f₀).prod (has_fderiv_at_id f₀)
lemma differentiable_within_at.prod
(hf₁ : differentiable_within_at 𝕜 f₁ s x) (hf₂ : differentiable_within_at 𝕜 f₂ s x) :
differentiable_within_at 𝕜 (λx:E, (f₁ x, f₂ x)) s x :=
(hf₁.has_fderiv_within_at.prod hf₂.has_fderiv_within_at).differentiable_within_at
@[simp]
lemma differentiable_at.prod (hf₁ : differentiable_at 𝕜 f₁ x) (hf₂ : differentiable_at 𝕜 f₂ x) :
differentiable_at 𝕜 (λx:E, (f₁ x, f₂ x)) x :=
(hf₁.has_fderiv_at.prod hf₂.has_fderiv_at).differentiable_at
lemma differentiable_on.prod (hf₁ : differentiable_on 𝕜 f₁ s) (hf₂ : differentiable_on 𝕜 f₂ s) :
differentiable_on 𝕜 (λx:E, (f₁ x, f₂ x)) s :=
λx hx, differentiable_within_at.prod (hf₁ x hx) (hf₂ x hx)
@[simp]
lemma differentiable.prod (hf₁ : differentiable 𝕜 f₁) (hf₂ : differentiable 𝕜 f₂) :
differentiable 𝕜 (λx:E, (f₁ x, f₂ x)) :=
λ x, differentiable_at.prod (hf₁ x) (hf₂ x)
lemma differentiable_at.fderiv_prod
(hf₁ : differentiable_at 𝕜 f₁ x) (hf₂ : differentiable_at 𝕜 f₂ x) :
fderiv 𝕜 (λx:E, (f₁ x, f₂ x)) x = (fderiv 𝕜 f₁ x).prod (fderiv 𝕜 f₂ x) :=
(hf₁.has_fderiv_at.prod hf₂.has_fderiv_at).fderiv
lemma differentiable_at.fderiv_within_prod
(hf₁ : differentiable_within_at 𝕜 f₁ s x) (hf₂ : differentiable_within_at 𝕜 f₂ s x)
(hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (λx:E, (f₁ x, f₂ x)) s x =
(fderiv_within 𝕜 f₁ s x).prod (fderiv_within 𝕜 f₂ s x) :=
(hf₁.has_fderiv_within_at.prod hf₂.has_fderiv_within_at).fderiv_within hxs
end prod
section fst
variables {f₂ : E → F × G} {f₂' : E →L[𝕜] F × G} {p : E × F}
lemma has_strict_fderiv_at_fst : has_strict_fderiv_at (@prod.fst E F) (fst 𝕜 E F) p :=
(fst 𝕜 E F).has_strict_fderiv_at
protected lemma has_strict_fderiv_at.fst (h : has_strict_fderiv_at f₂ f₂' x) :
has_strict_fderiv_at (λ x, (f₂ x).1) ((fst 𝕜 F G).comp f₂') x :=
has_strict_fderiv_at_fst.comp x h
lemma has_fderiv_at_filter_fst {L : filter (E × F)} :
has_fderiv_at_filter (@prod.fst E F) (fst 𝕜 E F) p L :=
(fst 𝕜 E F).has_fderiv_at_filter
protected lemma has_fderiv_at_filter.fst (h : has_fderiv_at_filter f₂ f₂' x L) :
has_fderiv_at_filter (λ x, (f₂ x).1) ((fst 𝕜 F G).comp f₂') x L :=
has_fderiv_at_filter_fst.comp x h tendsto_map
lemma has_fderiv_at_fst : has_fderiv_at (@prod.fst E F) (fst 𝕜 E F) p :=
has_fderiv_at_filter_fst
protected lemma has_fderiv_at.fst (h : has_fderiv_at f₂ f₂' x) :
has_fderiv_at (λ x, (f₂ x).1) ((fst 𝕜 F G).comp f₂') x :=
h.fst
lemma has_fderiv_within_at_fst {s : set (E × F)} :
has_fderiv_within_at (@prod.fst E F) (fst 𝕜 E F) s p :=
has_fderiv_at_filter_fst
protected lemma has_fderiv_within_at.fst (h : has_fderiv_within_at f₂ f₂' s x) :
has_fderiv_within_at (λ x, (f₂ x).1) ((fst 𝕜 F G).comp f₂') s x :=
h.fst
lemma differentiable_at_fst : differentiable_at 𝕜 prod.fst p :=
has_fderiv_at_fst.differentiable_at
@[simp] protected lemma differentiable_at.fst (h : differentiable_at 𝕜 f₂ x) :
differentiable_at 𝕜 (λ x, (f₂ x).1) x :=
differentiable_at_fst.comp x h
lemma differentiable_fst : differentiable 𝕜 (prod.fst : E × F → E) :=
λ x, differentiable_at_fst
@[simp] protected lemma differentiable.fst (h : differentiable 𝕜 f₂) :
differentiable 𝕜 (λ x, (f₂ x).1) :=
differentiable_fst.comp h
lemma differentiable_within_at_fst {s : set (E × F)} : differentiable_within_at 𝕜 prod.fst s p :=
differentiable_at_fst.differentiable_within_at
protected lemma differentiable_within_at.fst (h : differentiable_within_at 𝕜 f₂ s x) :
differentiable_within_at 𝕜 (λ x, (f₂ x).1) s x :=
differentiable_at_fst.comp_differentiable_within_at x h
lemma differentiable_on_fst {s : set (E × F)} : differentiable_on 𝕜 prod.fst s :=
differentiable_fst.differentiable_on
protected lemma differentiable_on.fst (h : differentiable_on 𝕜 f₂ s) :
differentiable_on 𝕜 (λ x, (f₂ x).1) s :=
differentiable_fst.comp_differentiable_on h
lemma fderiv_fst : fderiv 𝕜 prod.fst p = fst 𝕜 E F := has_fderiv_at_fst.fderiv
lemma fderiv.fst (h : differentiable_at 𝕜 f₂ x) :
fderiv 𝕜 (λ x, (f₂ x).1) x = (fst 𝕜 F G).comp (fderiv 𝕜 f₂ x) :=
h.has_fderiv_at.fst.fderiv
lemma fderiv_within_fst {s : set (E × F)} (hs : unique_diff_within_at 𝕜 s p) :
fderiv_within 𝕜 prod.fst s p = fst 𝕜 E F :=
has_fderiv_within_at_fst.fderiv_within hs
lemma fderiv_within.fst (hs : unique_diff_within_at 𝕜 s x) (h : differentiable_within_at 𝕜 f₂ s x) :
fderiv_within 𝕜 (λ x, (f₂ x).1) s x = (fst 𝕜 F G).comp (fderiv_within 𝕜 f₂ s x) :=
h.has_fderiv_within_at.fst.fderiv_within hs
end fst
section snd
variables {f₂ : E → F × G} {f₂' : E →L[𝕜] F × G} {p : E × F}
lemma has_strict_fderiv_at_snd : has_strict_fderiv_at (@prod.snd E F) (snd 𝕜 E F) p :=
(snd 𝕜 E F).has_strict_fderiv_at
protected lemma has_strict_fderiv_at.snd (h : has_strict_fderiv_at f₂ f₂' x) :
has_strict_fderiv_at (λ x, (f₂ x).2) ((snd 𝕜 F G).comp f₂') x :=
has_strict_fderiv_at_snd.comp x h
lemma has_fderiv_at_filter_snd {L : filter (E × F)} :
has_fderiv_at_filter (@prod.snd E F) (snd 𝕜 E F) p L :=
(snd 𝕜 E F).has_fderiv_at_filter
protected lemma has_fderiv_at_filter.snd (h : has_fderiv_at_filter f₂ f₂' x L) :
has_fderiv_at_filter (λ x, (f₂ x).2) ((snd 𝕜 F G).comp f₂') x L :=
has_fderiv_at_filter_snd.comp x h tendsto_map
lemma has_fderiv_at_snd : has_fderiv_at (@prod.snd E F) (snd 𝕜 E F) p :=
has_fderiv_at_filter_snd
protected lemma has_fderiv_at.snd (h : has_fderiv_at f₂ f₂' x) :
has_fderiv_at (λ x, (f₂ x).2) ((snd 𝕜 F G).comp f₂') x :=
h.snd
lemma has_fderiv_within_at_snd {s : set (E × F)} :
has_fderiv_within_at (@prod.snd E F) (snd 𝕜 E F) s p :=
has_fderiv_at_filter_snd
protected lemma has_fderiv_within_at.snd (h : has_fderiv_within_at f₂ f₂' s x) :
has_fderiv_within_at (λ x, (f₂ x).2) ((snd 𝕜 F G).comp f₂') s x :=
h.snd
lemma differentiable_at_snd : differentiable_at 𝕜 prod.snd p :=
has_fderiv_at_snd.differentiable_at
@[simp] protected lemma differentiable_at.snd (h : differentiable_at 𝕜 f₂ x) :
differentiable_at 𝕜 (λ x, (f₂ x).2) x :=
differentiable_at_snd.comp x h
lemma differentiable_snd : differentiable 𝕜 (prod.snd : E × F → F) :=
λ x, differentiable_at_snd
@[simp] protected lemma differentiable.snd (h : differentiable 𝕜 f₂) :
differentiable 𝕜 (λ x, (f₂ x).2) :=
differentiable_snd.comp h
lemma differentiable_within_at_snd {s : set (E × F)} : differentiable_within_at 𝕜 prod.snd s p :=
differentiable_at_snd.differentiable_within_at
protected lemma differentiable_within_at.snd (h : differentiable_within_at 𝕜 f₂ s x) :
differentiable_within_at 𝕜 (λ x, (f₂ x).2) s x :=
differentiable_at_snd.comp_differentiable_within_at x h
lemma differentiable_on_snd {s : set (E × F)} : differentiable_on 𝕜 prod.snd s :=
differentiable_snd.differentiable_on
protected lemma differentiable_on.snd (h : differentiable_on 𝕜 f₂ s) :
differentiable_on 𝕜 (λ x, (f₂ x).2) s :=
differentiable_snd.comp_differentiable_on h
lemma fderiv_snd : fderiv 𝕜 prod.snd p = snd 𝕜 E F := has_fderiv_at_snd.fderiv
lemma fderiv.snd (h : differentiable_at 𝕜 f₂ x) :
fderiv 𝕜 (λ x, (f₂ x).2) x = (snd 𝕜 F G).comp (fderiv 𝕜 f₂ x) :=
h.has_fderiv_at.snd.fderiv
lemma fderiv_within_snd {s : set (E × F)} (hs : unique_diff_within_at 𝕜 s p) :
fderiv_within 𝕜 prod.snd s p = snd 𝕜 E F :=
has_fderiv_within_at_snd.fderiv_within hs
lemma fderiv_within.snd (hs : unique_diff_within_at 𝕜 s x) (h : differentiable_within_at 𝕜 f₂ s x) :
fderiv_within 𝕜 (λ x, (f₂ x).2) s x = (snd 𝕜 F G).comp (fderiv_within 𝕜 f₂ s x) :=
h.has_fderiv_within_at.snd.fderiv_within hs
end snd
section prod_map
variables {f₂ : G → G'} {f₂' : G →L[𝕜] G'} {y : G} (p : E × G)
protected theorem has_strict_fderiv_at.prod_map (hf : has_strict_fderiv_at f f' p.1)
(hf₂ : has_strict_fderiv_at f₂ f₂' p.2) :
has_strict_fderiv_at (prod.map f f₂) (f'.prod_map f₂') p :=
(hf.comp p has_strict_fderiv_at_fst).prod (hf₂.comp p has_strict_fderiv_at_snd)
protected theorem has_fderiv_at.prod_map (hf : has_fderiv_at f f' p.1)
(hf₂ : has_fderiv_at f₂ f₂' p.2) :
has_fderiv_at (prod.map f f₂) (f'.prod_map f₂') p :=
(hf.comp p has_fderiv_at_fst).prod (hf₂.comp p has_fderiv_at_snd)
@[simp] protected theorem differentiable_at.prod_map (hf : differentiable_at 𝕜 f p.1)
(hf₂ : differentiable_at 𝕜 f₂ p.2) :
differentiable_at 𝕜 (λ p : E × G, (f p.1, f₂ p.2)) p :=
(hf.comp p differentiable_at_fst).prod (hf₂.comp p differentiable_at_snd)
end prod_map
end cartesian_product
section const_smul
variables {R : Type*} [semiring R] [module R F] [smul_comm_class 𝕜 R F]
[has_continuous_const_smul R F]
/-! ### Derivative of a function multiplied by a constant -/
theorem has_strict_fderiv_at.const_smul (h : has_strict_fderiv_at f f' x) (c : R) :
has_strict_fderiv_at (λ x, c • f x) (c • f') x :=
(c • (1 : F →L[𝕜] F)).has_strict_fderiv_at.comp x h
theorem has_fderiv_at_filter.const_smul (h : has_fderiv_at_filter f f' x L) (c : R) :
has_fderiv_at_filter (λ x, c • f x) (c • f') x L :=
(c • (1 : F →L[𝕜] F)).has_fderiv_at_filter.comp x h tendsto_map
theorem has_fderiv_within_at.const_smul (h : has_fderiv_within_at f f' s x) (c : R) :
has_fderiv_within_at (λ x, c • f x) (c • f') s x :=
h.const_smul c
theorem has_fderiv_at.const_smul (h : has_fderiv_at f f' x) (c : R) :
has_fderiv_at (λ x, c • f x) (c • f') x :=
h.const_smul c
lemma differentiable_within_at.const_smul (h : differentiable_within_at 𝕜 f s x) (c : R) :
differentiable_within_at 𝕜 (λy, c • f y) s x :=
(h.has_fderiv_within_at.const_smul c).differentiable_within_at
lemma differentiable_at.const_smul (h : differentiable_at 𝕜 f x) (c : R) :
differentiable_at 𝕜 (λy, c • f y) x :=
(h.has_fderiv_at.const_smul c).differentiable_at
lemma differentiable_on.const_smul (h : differentiable_on 𝕜 f s) (c : R) :
differentiable_on 𝕜 (λy, c • f y) s :=
λx hx, (h x hx).const_smul c
lemma differentiable.const_smul (h : differentiable 𝕜 f) (c : R) :
differentiable 𝕜 (λy, c • f y) :=
λx, (h x).const_smul c
lemma fderiv_within_const_smul (hxs : unique_diff_within_at 𝕜 s x)
(h : differentiable_within_at 𝕜 f s x) (c : R) :
fderiv_within 𝕜 (λy, c • f y) s x = c • fderiv_within 𝕜 f s x :=
(h.has_fderiv_within_at.const_smul c).fderiv_within hxs
lemma fderiv_const_smul (h : differentiable_at 𝕜 f x) (c : R) :
fderiv 𝕜 (λy, c • f y) x = c • fderiv 𝕜 f x :=
(h.has_fderiv_at.const_smul c).fderiv
end const_smul
section add
/-! ### Derivative of the sum of two functions -/
theorem has_strict_fderiv_at.add (hf : has_strict_fderiv_at f f' x)
(hg : has_strict_fderiv_at g g' x) :
has_strict_fderiv_at (λ y, f y + g y) (f' + g') x :=
(hf.add hg).congr_left $ λ y, by simp; abel
theorem has_fderiv_at_filter.add
(hf : has_fderiv_at_filter f f' x L) (hg : has_fderiv_at_filter g g' x L) :
has_fderiv_at_filter (λ y, f y + g y) (f' + g') x L :=
(hf.add hg).congr_left $ λ _, by simp; abel
theorem has_fderiv_within_at.add
(hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at g g' s x) :
has_fderiv_within_at (λ y, f y + g y) (f' + g') s x :=
hf.add hg
theorem has_fderiv_at.add
(hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x) :
has_fderiv_at (λ x, f x + g x) (f' + g') x :=
hf.add hg
lemma differentiable_within_at.add
(hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) :
differentiable_within_at 𝕜 (λ y, f y + g y) s x :=
(hf.has_fderiv_within_at.add hg.has_fderiv_within_at).differentiable_within_at
@[simp] lemma differentiable_at.add
(hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) :
differentiable_at 𝕜 (λ y, f y + g y) x :=
(hf.has_fderiv_at.add hg.has_fderiv_at).differentiable_at
lemma differentiable_on.add
(hf : differentiable_on 𝕜 f s) (hg : differentiable_on 𝕜 g s) :
differentiable_on 𝕜 (λy, f y + g y) s :=
λx hx, (hf x hx).add (hg x hx)
@[simp] lemma differentiable.add
(hf : differentiable 𝕜 f) (hg : differentiable 𝕜 g) :
differentiable 𝕜 (λy, f y + g y) :=
λx, (hf x).add (hg x)
lemma fderiv_within_add (hxs : unique_diff_within_at 𝕜 s x)
(hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) :
fderiv_within 𝕜 (λy, f y + g y) s x = fderiv_within 𝕜 f s x + fderiv_within 𝕜 g s x :=
(hf.has_fderiv_within_at.add hg.has_fderiv_within_at).fderiv_within hxs
lemma fderiv_add
(hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) :
fderiv 𝕜 (λy, f y + g y) x = fderiv 𝕜 f x + fderiv 𝕜 g x :=
(hf.has_fderiv_at.add hg.has_fderiv_at).fderiv
theorem has_strict_fderiv_at.add_const (hf : has_strict_fderiv_at f f' x) (c : F) :
has_strict_fderiv_at (λ y, f y + c) f' x :=
add_zero f' ▸ hf.add (has_strict_fderiv_at_const _ _)
theorem has_fderiv_at_filter.add_const
(hf : has_fderiv_at_filter f f' x L) (c : F) :
has_fderiv_at_filter (λ y, f y + c) f' x L :=
add_zero f' ▸ hf.add (has_fderiv_at_filter_const _ _ _)
theorem has_fderiv_within_at.add_const
(hf : has_fderiv_within_at f f' s x) (c : F) :
has_fderiv_within_at (λ y, f y + c) f' s x :=
hf.add_const c
theorem has_fderiv_at.add_const (hf : has_fderiv_at f f' x) (c : F):
has_fderiv_at (λ x, f x + c) f' x :=
hf.add_const c
lemma differentiable_within_at.add_const
(hf : differentiable_within_at 𝕜 f s x) (c : F) :
differentiable_within_at 𝕜 (λ y, f y + c) s x :=
(hf.has_fderiv_within_at.add_const c).differentiable_within_at
@[simp] lemma differentiable_within_at_add_const_iff (c : F) :
differentiable_within_at 𝕜 (λ y, f y + c) s x ↔ differentiable_within_at 𝕜 f s x :=
⟨λ h, by simpa using h.add_const (-c), λ h, h.add_const c⟩
lemma differentiable_at.add_const
(hf : differentiable_at 𝕜 f x) (c : F) :
differentiable_at 𝕜 (λ y, f y + c) x :=
(hf.has_fderiv_at.add_const c).differentiable_at
@[simp] lemma differentiable_at_add_const_iff (c : F) :
differentiable_at 𝕜 (λ y, f y + c) x ↔ differentiable_at 𝕜 f x :=
⟨λ h, by simpa using h.add_const (-c), λ h, h.add_const c⟩
lemma differentiable_on.add_const
(hf : differentiable_on 𝕜 f s) (c : F) :
differentiable_on 𝕜 (λy, f y + c) s :=
λx hx, (hf x hx).add_const c
@[simp] lemma differentiable_on_add_const_iff (c : F) :
differentiable_on 𝕜 (λ y, f y + c) s ↔ differentiable_on 𝕜 f s :=
⟨λ h, by simpa using h.add_const (-c), λ h, h.add_const c⟩
lemma differentiable.add_const
(hf : differentiable 𝕜 f) (c : F) :
differentiable 𝕜 (λy, f y + c) :=
λx, (hf x).add_const c
@[simp] lemma differentiable_add_const_iff (c : F) :
differentiable 𝕜 (λ y, f y + c) ↔ differentiable 𝕜 f :=
⟨λ h, by simpa using h.add_const (-c), λ h, h.add_const c⟩
lemma fderiv_within_add_const (hxs : unique_diff_within_at 𝕜 s x) (c : F) :
fderiv_within 𝕜 (λy, f y + c) s x = fderiv_within 𝕜 f s x :=
if hf : differentiable_within_at 𝕜 f s x
then (hf.has_fderiv_within_at.add_const c).fderiv_within hxs
else by { rw [fderiv_within_zero_of_not_differentiable_within_at hf,
fderiv_within_zero_of_not_differentiable_within_at], simpa }
lemma fderiv_add_const (c : F) : fderiv 𝕜 (λy, f y + c) x = fderiv 𝕜 f x :=
by simp only [← fderiv_within_univ, fderiv_within_add_const unique_diff_within_at_univ]
theorem has_strict_fderiv_at.const_add (hf : has_strict_fderiv_at f f' x) (c : F) :
has_strict_fderiv_at (λ y, c + f y) f' x :=
zero_add f' ▸ (has_strict_fderiv_at_const _ _).add hf
theorem has_fderiv_at_filter.const_add
(hf : has_fderiv_at_filter f f' x L) (c : F) :
has_fderiv_at_filter (λ y, c + f y) f' x L :=
zero_add f' ▸ (has_fderiv_at_filter_const _ _ _).add hf
theorem has_fderiv_within_at.const_add
(hf : has_fderiv_within_at f f' s x) (c : F) :
has_fderiv_within_at (λ y, c + f y) f' s x :=
hf.const_add c
theorem has_fderiv_at.const_add
(hf : has_fderiv_at f f' x) (c : F):
has_fderiv_at (λ x, c + f x) f' x :=
hf.const_add c
lemma differentiable_within_at.const_add
(hf : differentiable_within_at 𝕜 f s x) (c : F) :
differentiable_within_at 𝕜 (λ y, c + f y) s x :=
(hf.has_fderiv_within_at.const_add c).differentiable_within_at
@[simp] lemma differentiable_within_at_const_add_iff (c : F) :
differentiable_within_at 𝕜 (λ y, c + f y) s x ↔ differentiable_within_at 𝕜 f s x :=
⟨λ h, by simpa using h.const_add (-c), λ h, h.const_add c⟩
lemma differentiable_at.const_add
(hf : differentiable_at 𝕜 f x) (c : F) :
differentiable_at 𝕜 (λ y, c + f y) x :=
(hf.has_fderiv_at.const_add c).differentiable_at
@[simp] lemma differentiable_at_const_add_iff (c : F) :
differentiable_at 𝕜 (λ y, c + f y) x ↔ differentiable_at 𝕜 f x :=
⟨λ h, by simpa using h.const_add (-c), λ h, h.const_add c⟩
lemma differentiable_on.const_add (hf : differentiable_on 𝕜 f s) (c : F) :
differentiable_on 𝕜 (λy, c + f y) s :=
λx hx, (hf x hx).const_add c
@[simp] lemma differentiable_on_const_add_iff (c : F) :
differentiable_on 𝕜 (λ y, c + f y) s ↔ differentiable_on 𝕜 f s :=
⟨λ h, by simpa using h.const_add (-c), λ h, h.const_add c⟩
lemma differentiable.const_add (hf : differentiable 𝕜 f) (c : F) :
differentiable 𝕜 (λy, c + f y) :=
λx, (hf x).const_add c
@[simp] lemma differentiable_const_add_iff (c : F) :
differentiable 𝕜 (λ y, c + f y) ↔ differentiable 𝕜 f :=
⟨λ h, by simpa using h.const_add (-c), λ h, h.const_add c⟩
lemma fderiv_within_const_add (hxs : unique_diff_within_at 𝕜 s x) (c : F) :
fderiv_within 𝕜 (λy, c + f y) s x = fderiv_within 𝕜 f s x :=
by simpa only [add_comm] using fderiv_within_add_const hxs c
lemma fderiv_const_add (c : F) : fderiv 𝕜 (λy, c + f y) x = fderiv 𝕜 f x :=
by simp only [add_comm c, fderiv_add_const]
end add
section sum
/-! ### Derivative of a finite sum of functions -/
open_locale big_operators
variables {ι : Type*} {u : finset ι} {A : ι → (E → F)} {A' : ι → (E →L[𝕜] F)}
theorem has_strict_fderiv_at.sum (h : ∀ i ∈ u, has_strict_fderiv_at (A i) (A' i) x) :
has_strict_fderiv_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x :=
begin
dsimp [has_strict_fderiv_at] at *,
convert is_o.sum h,
simp [finset.sum_sub_distrib, continuous_linear_map.sum_apply]
end
theorem has_fderiv_at_filter.sum (h : ∀ i ∈ u, has_fderiv_at_filter (A i) (A' i) x L) :
has_fderiv_at_filter (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x L :=
begin
dsimp [has_fderiv_at_filter] at *,
convert is_o.sum h,
simp [continuous_linear_map.sum_apply]
end
theorem has_fderiv_within_at.sum (h : ∀ i ∈ u, has_fderiv_within_at (A i) (A' i) s x) :
has_fderiv_within_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) s x :=
has_fderiv_at_filter.sum h
theorem has_fderiv_at.sum (h : ∀ i ∈ u, has_fderiv_at (A i) (A' i) x) :
has_fderiv_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x :=
has_fderiv_at_filter.sum h
theorem differentiable_within_at.sum (h : ∀ i ∈ u, differentiable_within_at 𝕜 (A i) s x) :
differentiable_within_at 𝕜 (λ y, ∑ i in u, A i y) s x :=
has_fderiv_within_at.differentiable_within_at $ has_fderiv_within_at.sum $
λ i hi, (h i hi).has_fderiv_within_at
@[simp] theorem differentiable_at.sum (h : ∀ i ∈ u, differentiable_at 𝕜 (A i) x) :
differentiable_at 𝕜 (λ y, ∑ i in u, A i y) x :=
has_fderiv_at.differentiable_at $ has_fderiv_at.sum $ λ i hi, (h i hi).has_fderiv_at
theorem differentiable_on.sum (h : ∀ i ∈ u, differentiable_on 𝕜 (A i) s) :
differentiable_on 𝕜 (λ y, ∑ i in u, A i y) s :=
λ x hx, differentiable_within_at.sum $ λ i hi, h i hi x hx
@[simp] theorem differentiable.sum (h : ∀ i ∈ u, differentiable 𝕜 (A i)) :
differentiable 𝕜 (λ y, ∑ i in u, A i y) :=
λ x, differentiable_at.sum $ λ i hi, h i hi x
theorem fderiv_within_sum (hxs : unique_diff_within_at 𝕜 s x)
(h : ∀ i ∈ u, differentiable_within_at 𝕜 (A i) s x) :
fderiv_within 𝕜 (λ y, ∑ i in u, A i y) s x = (∑ i in u, fderiv_within 𝕜 (A i) s x) :=
(has_fderiv_within_at.sum (λ i hi, (h i hi).has_fderiv_within_at)).fderiv_within hxs
theorem fderiv_sum (h : ∀ i ∈ u, differentiable_at 𝕜 (A i) x) :
fderiv 𝕜 (λ y, ∑ i in u, A i y) x = (∑ i in u, fderiv 𝕜 (A i) x) :=
(has_fderiv_at.sum (λ i hi, (h i hi).has_fderiv_at)).fderiv
end sum
section pi
/-!
### Derivatives of functions `f : E → Π i, F' i`
In this section we formulate `has_*fderiv*_pi` theorems as `iff`s, and provide two versions of each
theorem:
* the version without `'` deals with `φ : Π i, E → F' i` and `φ' : Π i, E →L[𝕜] F' i`
and is designed to deduce differentiability of `λ x i, φ i x` from differentiability
of each `φ i`;
* the version with `'` deals with `Φ : E → Π i, F' i` and `Φ' : E →L[𝕜] Π i, F' i`
and is designed to deduce differentiability of the components `λ x, Φ x i` from
differentiability of `Φ`.
-/
variables {ι : Type*} [fintype ι] {F' : ι → Type*} [Π i, normed_add_comm_group (F' i)]
[Π i, normed_space 𝕜 (F' i)] {φ : Π i, E → F' i} {φ' : Π i, E →L[𝕜] F' i}
{Φ : E → Π i, F' i} {Φ' : E →L[𝕜] Π i, F' i}
@[simp] lemma has_strict_fderiv_at_pi' :
has_strict_fderiv_at Φ Φ' x ↔
∀ i, has_strict_fderiv_at (λ x, Φ x i) ((proj i).comp Φ') x :=
begin
simp only [has_strict_fderiv_at, continuous_linear_map.coe_pi],
exact is_o_pi
end
@[simp] lemma has_strict_fderiv_at_pi :
has_strict_fderiv_at (λ x i, φ i x) (continuous_linear_map.pi φ') x ↔
∀ i, has_strict_fderiv_at (φ i) (φ' i) x :=
has_strict_fderiv_at_pi'
@[simp] lemma has_fderiv_at_filter_pi' :
has_fderiv_at_filter Φ Φ' x L ↔
∀ i, has_fderiv_at_filter (λ x, Φ x i) ((proj i).comp Φ') x L :=
begin
simp only [has_fderiv_at_filter, continuous_linear_map.coe_pi],
exact is_o_pi
end
lemma has_fderiv_at_filter_pi :
has_fderiv_at_filter (λ x i, φ i x) (continuous_linear_map.pi φ') x L ↔
∀ i, has_fderiv_at_filter (φ i) (φ' i) x L :=
has_fderiv_at_filter_pi'
@[simp] lemma has_fderiv_at_pi' :
has_fderiv_at Φ Φ' x ↔
∀ i, has_fderiv_at (λ x, Φ x i) ((proj i).comp Φ') x :=
has_fderiv_at_filter_pi'
lemma has_fderiv_at_pi :
has_fderiv_at (λ x i, φ i x) (continuous_linear_map.pi φ') x ↔
∀ i, has_fderiv_at (φ i) (φ' i) x :=
has_fderiv_at_filter_pi
@[simp] lemma has_fderiv_within_at_pi' :
has_fderiv_within_at Φ Φ' s x ↔
∀ i, has_fderiv_within_at (λ x, Φ x i) ((proj i).comp Φ') s x :=
has_fderiv_at_filter_pi'
lemma has_fderiv_within_at_pi :
has_fderiv_within_at (λ x i, φ i x) (continuous_linear_map.pi φ') s x ↔
∀ i, has_fderiv_within_at (φ i) (φ' i) s x :=
has_fderiv_at_filter_pi
@[simp] lemma differentiable_within_at_pi :
differentiable_within_at 𝕜 Φ s x ↔
∀ i, differentiable_within_at 𝕜 (λ x, Φ x i) s x :=
⟨λ h i, (has_fderiv_within_at_pi'.1 h.has_fderiv_within_at i).differentiable_within_at,
λ h, (has_fderiv_within_at_pi.2 (λ i, (h i).has_fderiv_within_at)).differentiable_within_at⟩
@[simp] lemma differentiable_at_pi :
differentiable_at 𝕜 Φ x ↔ ∀ i, differentiable_at 𝕜 (λ x, Φ x i) x :=
⟨λ h i, (has_fderiv_at_pi'.1 h.has_fderiv_at i).differentiable_at,
λ h, (has_fderiv_at_pi.2 (λ i, (h i).has_fderiv_at)).differentiable_at⟩
lemma differentiable_on_pi :
differentiable_on 𝕜 Φ s ↔ ∀ i, differentiable_on 𝕜 (λ x, Φ x i) s :=
⟨λ h i x hx, differentiable_within_at_pi.1 (h x hx) i,
λ h x hx, differentiable_within_at_pi.2 (λ i, h i x hx)⟩
lemma differentiable_pi :
differentiable 𝕜 Φ ↔ ∀ i, differentiable 𝕜 (λ x, Φ x i) :=
⟨λ h i x, differentiable_at_pi.1 (h x) i, λ h x, differentiable_at_pi.2 (λ i, h i x)⟩
-- TODO: find out which version (`φ` or `Φ`) works better with `rw`/`simp`
lemma fderiv_within_pi (h : ∀ i, differentiable_within_at 𝕜 (φ i) s x)
(hs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (λ x i, φ i x) s x = pi (λ i, fderiv_within 𝕜 (φ i) s x) :=
(has_fderiv_within_at_pi.2 (λ i, (h i).has_fderiv_within_at)).fderiv_within hs
lemma fderiv_pi (h : ∀ i, differentiable_at 𝕜 (φ i) x) :
fderiv 𝕜 (λ x i, φ i x) x = pi (λ i, fderiv 𝕜 (φ i) x) :=
(has_fderiv_at_pi.2 (λ i, (h i).has_fderiv_at)).fderiv
end pi
section neg
/-! ### Derivative of the negative of a function -/
theorem has_strict_fderiv_at.neg (h : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, -f x) (-f') x :=
(-1 : F →L[𝕜] F).has_strict_fderiv_at.comp x h
theorem has_fderiv_at_filter.neg (h : has_fderiv_at_filter f f' x L) :
has_fderiv_at_filter (λ x, -f x) (-f') x L :=
(-1 : F →L[𝕜] F).has_fderiv_at_filter.comp x h tendsto_map
theorem has_fderiv_within_at.neg (h : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, -f x) (-f') s x :=
h.neg
theorem has_fderiv_at.neg (h : has_fderiv_at f f' x) :
has_fderiv_at (λ x, -f x) (-f') x :=
h.neg
lemma differentiable_within_at.neg (h : differentiable_within_at 𝕜 f s x) :
differentiable_within_at 𝕜 (λy, -f y) s x :=
h.has_fderiv_within_at.neg.differentiable_within_at
@[simp] lemma differentiable_within_at_neg_iff :
differentiable_within_at 𝕜 (λy, -f y) s x ↔ differentiable_within_at 𝕜 f s x :=
⟨λ h, by simpa only [neg_neg] using h.neg, λ h, h.neg⟩
lemma differentiable_at.neg (h : differentiable_at 𝕜 f x) :
differentiable_at 𝕜 (λy, -f y) x :=
h.has_fderiv_at.neg.differentiable_at
@[simp] lemma differentiable_at_neg_iff :
differentiable_at 𝕜 (λy, -f y) x ↔ differentiable_at 𝕜 f x :=
⟨λ h, by simpa only [neg_neg] using h.neg, λ h, h.neg⟩
lemma differentiable_on.neg (h : differentiable_on 𝕜 f s) :
differentiable_on 𝕜 (λy, -f y) s :=
λx hx, (h x hx).neg
@[simp] lemma differentiable_on_neg_iff :
differentiable_on 𝕜 (λy, -f y) s ↔ differentiable_on 𝕜 f s :=
⟨λ h, by simpa only [neg_neg] using h.neg, λ h, h.neg⟩
lemma differentiable.neg (h : differentiable 𝕜 f) :
differentiable 𝕜 (λy, -f y) :=
λx, (h x).neg
@[simp] lemma differentiable_neg_iff : differentiable 𝕜 (λy, -f y) ↔ differentiable 𝕜 f :=
⟨λ h, by simpa only [neg_neg] using h.neg, λ h, h.neg⟩
lemma fderiv_within_neg (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (λy, -f y) s x = - fderiv_within 𝕜 f s x :=
if h : differentiable_within_at 𝕜 f s x
then h.has_fderiv_within_at.neg.fderiv_within hxs
else by { rw [fderiv_within_zero_of_not_differentiable_within_at h,
fderiv_within_zero_of_not_differentiable_within_at, neg_zero], simpa }
@[simp] lemma fderiv_neg : fderiv 𝕜 (λy, -f y) x = - fderiv 𝕜 f x :=
by simp only [← fderiv_within_univ, fderiv_within_neg unique_diff_within_at_univ]
end neg
section sub
/-! ### Derivative of the difference of two functions -/
theorem has_strict_fderiv_at.sub
(hf : has_strict_fderiv_at f f' x) (hg : has_strict_fderiv_at g g' x) :
has_strict_fderiv_at (λ x, f x - g x) (f' - g') x :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
theorem has_fderiv_at_filter.sub
(hf : has_fderiv_at_filter f f' x L) (hg : has_fderiv_at_filter g g' x L) :
has_fderiv_at_filter (λ x, f x - g x) (f' - g') x L :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
theorem has_fderiv_within_at.sub
(hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at g g' s x) :
has_fderiv_within_at (λ x, f x - g x) (f' - g') s x :=
hf.sub hg
theorem has_fderiv_at.sub
(hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x) :
has_fderiv_at (λ x, f x - g x) (f' - g') x :=
hf.sub hg
lemma differentiable_within_at.sub
(hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) :
differentiable_within_at 𝕜 (λ y, f y - g y) s x :=
(hf.has_fderiv_within_at.sub hg.has_fderiv_within_at).differentiable_within_at
@[simp] lemma differentiable_at.sub
(hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) :
differentiable_at 𝕜 (λ y, f y - g y) x :=
(hf.has_fderiv_at.sub hg.has_fderiv_at).differentiable_at
lemma differentiable_on.sub
(hf : differentiable_on 𝕜 f s) (hg : differentiable_on 𝕜 g s) :
differentiable_on 𝕜 (λy, f y - g y) s :=
λx hx, (hf x hx).sub (hg x hx)
@[simp] lemma differentiable.sub
(hf : differentiable 𝕜 f) (hg : differentiable 𝕜 g) :
differentiable 𝕜 (λy, f y - g y) :=
λx, (hf x).sub (hg x)
lemma fderiv_within_sub (hxs : unique_diff_within_at 𝕜 s x)
(hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) :
fderiv_within 𝕜 (λy, f y - g y) s x = fderiv_within 𝕜 f s x - fderiv_within 𝕜 g s x :=
(hf.has_fderiv_within_at.sub hg.has_fderiv_within_at).fderiv_within hxs
lemma fderiv_sub
(hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) :
fderiv 𝕜 (λy, f y - g y) x = fderiv 𝕜 f x - fderiv 𝕜 g x :=
(hf.has_fderiv_at.sub hg.has_fderiv_at).fderiv
theorem has_strict_fderiv_at.sub_const
(hf : has_strict_fderiv_at f f' x) (c : F) :
has_strict_fderiv_at (λ x, f x - c) f' x :=
by simpa only [sub_eq_add_neg] using hf.add_const (-c)
theorem has_fderiv_at_filter.sub_const
(hf : has_fderiv_at_filter f f' x L) (c : F) :
has_fderiv_at_filter (λ x, f x - c) f' x L :=
by simpa only [sub_eq_add_neg] using hf.add_const (-c)
theorem has_fderiv_within_at.sub_const
(hf : has_fderiv_within_at f f' s x) (c : F) :
has_fderiv_within_at (λ x, f x - c) f' s x :=
hf.sub_const c
theorem has_fderiv_at.sub_const
(hf : has_fderiv_at f f' x) (c : F) :
has_fderiv_at (λ x, f x - c) f' x :=
hf.sub_const c
lemma differentiable_within_at.sub_const
(hf : differentiable_within_at 𝕜 f s x) (c : F) :
differentiable_within_at 𝕜 (λ y, f y - c) s x :=
(hf.has_fderiv_within_at.sub_const c).differentiable_within_at
@[simp] lemma differentiable_within_at_sub_const_iff (c : F) :
differentiable_within_at 𝕜 (λ y, f y - c) s x ↔ differentiable_within_at 𝕜 f s x :=
by simp only [sub_eq_add_neg, differentiable_within_at_add_const_iff]
lemma differentiable_at.sub_const (hf : differentiable_at 𝕜 f x) (c : F) :
differentiable_at 𝕜 (λ y, f y - c) x :=
(hf.has_fderiv_at.sub_const c).differentiable_at
@[simp] lemma differentiable_at_sub_const_iff (c : F) :
differentiable_at 𝕜 (λ y, f y - c) x ↔ differentiable_at 𝕜 f x :=
by simp only [sub_eq_add_neg, differentiable_at_add_const_iff]
lemma differentiable_on.sub_const (hf : differentiable_on 𝕜 f s) (c : F) :
differentiable_on 𝕜 (λy, f y - c) s :=
λx hx, (hf x hx).sub_const c
@[simp] lemma differentiable_on_sub_const_iff (c : F) :
differentiable_on 𝕜 (λ y, f y - c) s ↔ differentiable_on 𝕜 f s :=
by simp only [sub_eq_add_neg, differentiable_on_add_const_iff]
lemma differentiable.sub_const (hf : differentiable 𝕜 f) (c : F) :
differentiable 𝕜 (λy, f y - c) :=
λx, (hf x).sub_const c
@[simp] lemma differentiable_sub_const_iff (c : F) :
differentiable 𝕜 (λ y, f y - c) ↔ differentiable 𝕜 f :=
by simp only [sub_eq_add_neg, differentiable_add_const_iff]
lemma fderiv_within_sub_const (hxs : unique_diff_within_at 𝕜 s x) (c : F) :
fderiv_within 𝕜 (λy, f y - c) s x = fderiv_within 𝕜 f s x :=
by simp only [sub_eq_add_neg, fderiv_within_add_const hxs]
lemma fderiv_sub_const (c : F) : fderiv 𝕜 (λy, f y - c) x = fderiv 𝕜 f x :=
by simp only [sub_eq_add_neg, fderiv_add_const]
theorem has_strict_fderiv_at.const_sub
(hf : has_strict_fderiv_at f f' x) (c : F) :
has_strict_fderiv_at (λ x, c - f x) (-f') x :=
by simpa only [sub_eq_add_neg] using hf.neg.const_add c
theorem has_fderiv_at_filter.const_sub
(hf : has_fderiv_at_filter f f' x L) (c : F) :
has_fderiv_at_filter (λ x, c - f x) (-f') x L :=
by simpa only [sub_eq_add_neg] using hf.neg.const_add c
theorem has_fderiv_within_at.const_sub
(hf : has_fderiv_within_at f f' s x) (c : F) :
has_fderiv_within_at (λ x, c - f x) (-f') s x :=
hf.const_sub c
theorem has_fderiv_at.const_sub
(hf : has_fderiv_at f f' x) (c : F) :
has_fderiv_at (λ x, c - f x) (-f') x :=
hf.const_sub c
lemma differentiable_within_at.const_sub
(hf : differentiable_within_at 𝕜 f s x) (c : F) :
differentiable_within_at 𝕜 (λ y, c - f y) s x :=
(hf.has_fderiv_within_at.const_sub c).differentiable_within_at
@[simp] lemma differentiable_within_at_const_sub_iff (c : F) :
differentiable_within_at 𝕜 (λ y, c - f y) s x ↔ differentiable_within_at 𝕜 f s x :=
by simp [sub_eq_add_neg]
lemma differentiable_at.const_sub
(hf : differentiable_at 𝕜 f x) (c : F) :
differentiable_at 𝕜 (λ y, c - f y) x :=
(hf.has_fderiv_at.const_sub c).differentiable_at
@[simp] lemma differentiable_at_const_sub_iff (c : F) :
differentiable_at 𝕜 (λ y, c - f y) x ↔ differentiable_at 𝕜 f x :=
by simp [sub_eq_add_neg]
lemma differentiable_on.const_sub (hf : differentiable_on 𝕜 f s) (c : F) :
differentiable_on 𝕜 (λy, c - f y) s :=
λx hx, (hf x hx).const_sub c
@[simp] lemma differentiable_on_const_sub_iff (c : F) :
differentiable_on 𝕜 (λ y, c - f y) s ↔ differentiable_on 𝕜 f s :=
by simp [sub_eq_add_neg]
lemma differentiable.const_sub (hf : differentiable 𝕜 f) (c : F) :
differentiable 𝕜 (λy, c - f y) :=
λx, (hf x).const_sub c
@[simp] lemma differentiable_const_sub_iff (c : F) :
differentiable 𝕜 (λ y, c - f y) ↔ differentiable 𝕜 f :=
by simp [sub_eq_add_neg]
lemma fderiv_within_const_sub (hxs : unique_diff_within_at 𝕜 s x) (c : F) :
fderiv_within 𝕜 (λy, c - f y) s x = -fderiv_within 𝕜 f s x :=
by simp only [sub_eq_add_neg, fderiv_within_const_add, fderiv_within_neg, hxs]
lemma fderiv_const_sub (c : F) : fderiv 𝕜 (λy, c - f y) x = -fderiv 𝕜 f x :=
by simp only [← fderiv_within_univ, fderiv_within_const_sub unique_diff_within_at_univ]
end sub
section bilinear_map
/-! ### Derivative of a bounded bilinear map -/
variables {b : E × F → G} {u : set (E × F) }
open normed_field
lemma is_bounded_bilinear_map.has_strict_fderiv_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) :
has_strict_fderiv_at b (h.deriv p) p :=
begin
rw has_strict_fderiv_at,
set T := (E × F) × (E × F),
have : (λ q : T, b (q.1 - q.2)) =o[𝓝 (p, p)] (λ q : T, ∥q.1 - q.2∥ * 1),
{ refine (h.is_O'.comp_tendsto le_top).trans_is_o _,
simp only [(∘)],
refine (is_O_refl (λ q : T, ∥q.1 - q.2∥) _).mul_is_o (is_o.norm_left $ (is_o_one_iff _).2 _),
rw [← sub_self p],
exact continuous_at_fst.sub continuous_at_snd },
simp only [mul_one, is_o_norm_right] at this,
refine (is_o.congr_of_sub _).1 this, clear this,
convert_to (λ q : T, h.deriv (p - q.2) (q.1 - q.2)) =o[𝓝 (p, p)] (λ q : T, q.1 - q.2),
{ ext ⟨⟨x₁, y₁⟩, ⟨x₂, y₂⟩⟩, rcases p with ⟨x, y⟩,
simp only [is_bounded_bilinear_map_deriv_coe, prod.mk_sub_mk, h.map_sub_left, h.map_sub_right],
abel },
have : (λ q : T, p - q.2) =o[𝓝 (p, p)] (λ q, (1:ℝ)),
from (is_o_one_iff _).2 (sub_self p ▸ tendsto_const_nhds.sub continuous_at_snd),
apply is_bounded_bilinear_map_apply.is_O_comp.trans_is_o,
refine is_o.trans_is_O _ (is_O_const_mul_self 1 _ _).of_norm_right,
refine is_o.mul_is_O _ (is_O_refl _ _),
exact (((h.is_bounded_linear_map_deriv.is_O_id ⊤).comp_tendsto le_top : _).trans_is_o
this).norm_left
end
lemma is_bounded_bilinear_map.has_fderiv_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) :
has_fderiv_at b (h.deriv p) p :=
(h.has_strict_fderiv_at p).has_fderiv_at
lemma is_bounded_bilinear_map.has_fderiv_within_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) :
has_fderiv_within_at b (h.deriv p) u p :=
(h.has_fderiv_at p).has_fderiv_within_at
lemma is_bounded_bilinear_map.differentiable_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) :
differentiable_at 𝕜 b p :=
(h.has_fderiv_at p).differentiable_at
lemma is_bounded_bilinear_map.differentiable_within_at (h : is_bounded_bilinear_map 𝕜 b)
(p : E × F) :
differentiable_within_at 𝕜 b u p :=
(h.differentiable_at p).differentiable_within_at
lemma is_bounded_bilinear_map.fderiv (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) :
fderiv 𝕜 b p = h.deriv p :=
has_fderiv_at.fderiv (h.has_fderiv_at p)
lemma is_bounded_bilinear_map.fderiv_within (h : is_bounded_bilinear_map 𝕜 b) (p : E × F)
(hxs : unique_diff_within_at 𝕜 u p) : fderiv_within 𝕜 b u p = h.deriv p :=
begin
rw differentiable_at.fderiv_within (h.differentiable_at p) hxs,
exact h.fderiv p
end
lemma is_bounded_bilinear_map.differentiable (h : is_bounded_bilinear_map 𝕜 b) :
differentiable 𝕜 b :=
λx, h.differentiable_at x
lemma is_bounded_bilinear_map.differentiable_on (h : is_bounded_bilinear_map 𝕜 b) :
differentiable_on 𝕜 b u :=
h.differentiable.differentiable_on
end bilinear_map
section clm_comp_apply
/-! ### Derivative of the pointwise composition/application of continuous linear maps -/
variables {H : Type*} [normed_add_comm_group H] [normed_space 𝕜 H] {c : E → G →L[𝕜] H}
{c' : E →L[𝕜] G →L[𝕜] H} {d : E → F →L[𝕜] G} {d' : E →L[𝕜] F →L[𝕜] G} {u : E → G}
{u' : E →L[𝕜] G}
lemma has_strict_fderiv_at.clm_comp (hc : has_strict_fderiv_at c c' x)
(hd : has_strict_fderiv_at d d' x) : has_strict_fderiv_at (λ y, (c y).comp (d y))
((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') x :=
(is_bounded_bilinear_map_comp.has_strict_fderiv_at (c x, d x)).comp x $ hc.prod hd
lemma has_fderiv_within_at.clm_comp (hc : has_fderiv_within_at c c' s x)
(hd : has_fderiv_within_at d d' s x) : has_fderiv_within_at (λ y, (c y).comp (d y))
((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') s x :=
(is_bounded_bilinear_map_comp.has_fderiv_at (c x, d x)).comp_has_fderiv_within_at x $ hc.prod hd
lemma has_fderiv_at.clm_comp (hc : has_fderiv_at c c' x)
(hd : has_fderiv_at d d' x) : has_fderiv_at (λ y, (c y).comp (d y))
((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') x :=
(is_bounded_bilinear_map_comp.has_fderiv_at (c x, d x)).comp x $ hc.prod hd
lemma differentiable_within_at.clm_comp
(hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) :
differentiable_within_at 𝕜 (λ y, (c y).comp (d y)) s x :=
(hc.has_fderiv_within_at.clm_comp hd.has_fderiv_within_at).differentiable_within_at
lemma differentiable_at.clm_comp (hc : differentiable_at 𝕜 c x)
(hd : differentiable_at 𝕜 d x) : differentiable_at 𝕜 (λ y, (c y).comp (d y)) x :=
(hc.has_fderiv_at.clm_comp hd.has_fderiv_at).differentiable_at
lemma differentiable_on.clm_comp (hc : differentiable_on 𝕜 c s) (hd : differentiable_on 𝕜 d s) :
differentiable_on 𝕜 (λ y, (c y).comp (d y)) s :=
λx hx, (hc x hx).clm_comp (hd x hx)
lemma differentiable.clm_comp (hc : differentiable 𝕜 c) (hd : differentiable 𝕜 d) :
differentiable 𝕜 (λ y, (c y).comp (d y)) :=
λx, (hc x).clm_comp (hd x)
lemma fderiv_within_clm_comp (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) :
fderiv_within 𝕜 (λ y, (c y).comp (d y)) s x =
(compL 𝕜 F G H (c x)).comp (fderiv_within 𝕜 d s x) +
((compL 𝕜 F G H).flip (d x)).comp (fderiv_within 𝕜 c s x) :=
(hc.has_fderiv_within_at.clm_comp hd.has_fderiv_within_at).fderiv_within hxs
lemma fderiv_clm_comp (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) :
fderiv 𝕜 (λ y, (c y).comp (d y)) x =
(compL 𝕜 F G H (c x)).comp (fderiv 𝕜 d x) +
((compL 𝕜 F G H).flip (d x)).comp (fderiv 𝕜 c x) :=
(hc.has_fderiv_at.clm_comp hd.has_fderiv_at).fderiv
lemma has_strict_fderiv_at.clm_apply (hc : has_strict_fderiv_at c c' x)
(hu : has_strict_fderiv_at u u' x) :
has_strict_fderiv_at (λ y, (c y) (u y)) ((c x).comp u' + c'.flip (u x)) x :=
(is_bounded_bilinear_map_apply.has_strict_fderiv_at (c x, u x)).comp x (hc.prod hu)
lemma has_fderiv_within_at.clm_apply (hc : has_fderiv_within_at c c' s x)
(hu : has_fderiv_within_at u u' s x) :
has_fderiv_within_at (λ y, (c y) (u y)) ((c x).comp u' + c'.flip (u x)) s x :=
(is_bounded_bilinear_map_apply.has_fderiv_at (c x, u x)).comp_has_fderiv_within_at x (hc.prod hu)
lemma has_fderiv_at.clm_apply (hc : has_fderiv_at c c' x) (hu : has_fderiv_at u u' x) :
has_fderiv_at (λ y, (c y) (u y)) ((c x).comp u' + c'.flip (u x)) x :=
(is_bounded_bilinear_map_apply.has_fderiv_at (c x, u x)).comp x (hc.prod hu)
lemma differentiable_within_at.clm_apply
(hc : differentiable_within_at 𝕜 c s x) (hu : differentiable_within_at 𝕜 u s x) :
differentiable_within_at 𝕜 (λ y, (c y) (u y)) s x :=
(hc.has_fderiv_within_at.clm_apply hu.has_fderiv_within_at).differentiable_within_at
lemma differentiable_at.clm_apply (hc : differentiable_at 𝕜 c x)
(hu : differentiable_at 𝕜 u x) : differentiable_at 𝕜 (λ y, (c y) (u y)) x :=
(hc.has_fderiv_at.clm_apply hu.has_fderiv_at).differentiable_at
lemma differentiable_on.clm_apply (hc : differentiable_on 𝕜 c s) (hu : differentiable_on 𝕜 u s) :
differentiable_on 𝕜 (λ y, (c y) (u y)) s :=
λx hx, (hc x hx).clm_apply (hu x hx)
lemma differentiable.clm_apply (hc : differentiable 𝕜 c) (hu : differentiable 𝕜 u) :
differentiable 𝕜 (λ y, (c y) (u y)) :=
λx, (hc x).clm_apply (hu x)
lemma fderiv_within_clm_apply (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (hu : differentiable_within_at 𝕜 u s x) :
fderiv_within 𝕜 (λ y, (c y) (u y)) s x =
((c x).comp (fderiv_within 𝕜 u s x) + (fderiv_within 𝕜 c s x).flip (u x)) :=
(hc.has_fderiv_within_at.clm_apply hu.has_fderiv_within_at).fderiv_within hxs
lemma fderiv_clm_apply (hc : differentiable_at 𝕜 c x) (hu : differentiable_at 𝕜 u x) :
fderiv 𝕜 (λ y, (c y) (u y)) x = ((c x).comp (fderiv 𝕜 u x) + (fderiv 𝕜 c x).flip (u x)) :=
(hc.has_fderiv_at.clm_apply hu.has_fderiv_at).fderiv
end clm_comp_apply
section smul
/-! ### Derivative of the product of a scalar-valued function and a vector-valued function
If `c` is a differentiable scalar-valued function and `f` is a differentiable vector-valued
function, then `λ x, c x • f x` is differentiable as well. Lemmas in this section works for
function `c` taking values in the base field, as well as in a normed algebra over the base
field: e.g., they work for `c : E → ℂ` and `f : E → F` provided that `F` is a complex
normed vector space.
-/
variables {𝕜' : Type*} [nontrivially_normed_field 𝕜'] [normed_algebra 𝕜 𝕜']
[normed_space 𝕜' F] [is_scalar_tower 𝕜 𝕜' F]
variables {c : E → 𝕜'} {c' : E →L[𝕜] 𝕜'}
theorem has_strict_fderiv_at.smul (hc : has_strict_fderiv_at c c' x)
(hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ y, c y • f y) (c x • f' + c'.smul_right (f x)) x :=
(is_bounded_bilinear_map_smul.has_strict_fderiv_at (c x, f x)).comp x $
hc.prod hf
theorem has_fderiv_within_at.smul
(hc : has_fderiv_within_at c c' s x) (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ y, c y • f y) (c x • f' + c'.smul_right (f x)) s x :=
(is_bounded_bilinear_map_smul.has_fderiv_at (c x, f x)).comp_has_fderiv_within_at x $
hc.prod hf
theorem has_fderiv_at.smul (hc : has_fderiv_at c c' x) (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ y, c y • f y) (c x • f' + c'.smul_right (f x)) x :=
(is_bounded_bilinear_map_smul.has_fderiv_at (c x, f x)).comp x $
hc.prod hf
lemma differentiable_within_at.smul
(hc : differentiable_within_at 𝕜 c s x) (hf : differentiable_within_at 𝕜 f s x) :
differentiable_within_at 𝕜 (λ y, c y • f y) s x :=
(hc.has_fderiv_within_at.smul hf.has_fderiv_within_at).differentiable_within_at
@[simp] lemma differentiable_at.smul (hc : differentiable_at 𝕜 c x) (hf : differentiable_at 𝕜 f x) :
differentiable_at 𝕜 (λ y, c y • f y) x :=
(hc.has_fderiv_at.smul hf.has_fderiv_at).differentiable_at
lemma differentiable_on.smul (hc : differentiable_on 𝕜 c s) (hf : differentiable_on 𝕜 f s) :
differentiable_on 𝕜 (λ y, c y • f y) s :=
λx hx, (hc x hx).smul (hf x hx)
@[simp] lemma differentiable.smul (hc : differentiable 𝕜 c) (hf : differentiable 𝕜 f) :
differentiable 𝕜 (λ y, c y • f y) :=
λx, (hc x).smul (hf x)
lemma fderiv_within_smul (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (hf : differentiable_within_at 𝕜 f s x) :
fderiv_within 𝕜 (λ y, c y • f y) s x =
c x • fderiv_within 𝕜 f s x + (fderiv_within 𝕜 c s x).smul_right (f x) :=
(hc.has_fderiv_within_at.smul hf.has_fderiv_within_at).fderiv_within hxs
lemma fderiv_smul (hc : differentiable_at 𝕜 c x) (hf : differentiable_at 𝕜 f x) :
fderiv 𝕜 (λ y, c y • f y) x =
c x • fderiv 𝕜 f x + (fderiv 𝕜 c x).smul_right (f x) :=
(hc.has_fderiv_at.smul hf.has_fderiv_at).fderiv
theorem has_strict_fderiv_at.smul_const (hc : has_strict_fderiv_at c c' x) (f : F) :
has_strict_fderiv_at (λ y, c y • f) (c'.smul_right f) x :=
by simpa only [smul_zero, zero_add] using hc.smul (has_strict_fderiv_at_const f x)
theorem has_fderiv_within_at.smul_const (hc : has_fderiv_within_at c c' s x) (f : F) :
has_fderiv_within_at (λ y, c y • f) (c'.smul_right f) s x :=
by simpa only [smul_zero, zero_add] using hc.smul (has_fderiv_within_at_const f x s)
theorem has_fderiv_at.smul_const (hc : has_fderiv_at c c' x) (f : F) :
has_fderiv_at (λ y, c y • f) (c'.smul_right f) x :=
by simpa only [smul_zero, zero_add] using hc.smul (has_fderiv_at_const f x)
lemma differentiable_within_at.smul_const
(hc : differentiable_within_at 𝕜 c s x) (f : F) :
differentiable_within_at 𝕜 (λ y, c y • f) s x :=
(hc.has_fderiv_within_at.smul_const f).differentiable_within_at
lemma differentiable_at.smul_const (hc : differentiable_at 𝕜 c x) (f : F) :
differentiable_at 𝕜 (λ y, c y • f) x :=
(hc.has_fderiv_at.smul_const f).differentiable_at
lemma differentiable_on.smul_const (hc : differentiable_on 𝕜 c s) (f : F) :
differentiable_on 𝕜 (λ y, c y • f) s :=
λx hx, (hc x hx).smul_const f
lemma differentiable.smul_const (hc : differentiable 𝕜 c) (f : F) :
differentiable 𝕜 (λ y, c y • f) :=
λx, (hc x).smul_const f
lemma fderiv_within_smul_const (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (f : F) :
fderiv_within 𝕜 (λ y, c y • f) s x =
(fderiv_within 𝕜 c s x).smul_right f :=
(hc.has_fderiv_within_at.smul_const f).fderiv_within hxs
lemma fderiv_smul_const (hc : differentiable_at 𝕜 c x) (f : F) :
fderiv 𝕜 (λ y, c y • f) x = (fderiv 𝕜 c x).smul_right f :=
(hc.has_fderiv_at.smul_const f).fderiv
end smul
section mul
/-! ### Derivative of the product of two functions -/
variables {𝔸 𝔸' : Type*} [normed_ring 𝔸] [normed_comm_ring 𝔸'] [normed_algebra 𝕜 𝔸]
[normed_algebra 𝕜 𝔸'] {a b : E → 𝔸} {a' b' : E →L[𝕜] 𝔸} {c d : E → 𝔸'} {c' d' : E →L[𝕜] 𝔸'}
theorem has_strict_fderiv_at.mul' {x : E} (ha : has_strict_fderiv_at a a' x)
(hb : has_strict_fderiv_at b b' x) :
has_strict_fderiv_at (λ y, a y * b y) (a x • b' + a'.smul_right (b x)) x :=
((continuous_linear_map.lmul 𝕜 𝔸).is_bounded_bilinear_map.has_strict_fderiv_at (a x, b x)).comp x
(ha.prod hb)
theorem has_strict_fderiv_at.mul
(hc : has_strict_fderiv_at c c' x) (hd : has_strict_fderiv_at d d' x) :
has_strict_fderiv_at (λ y, c y * d y) (c x • d' + d x • c') x :=
by { convert hc.mul' hd, ext z, apply mul_comm }
theorem has_fderiv_within_at.mul'
(ha : has_fderiv_within_at a a' s x) (hb : has_fderiv_within_at b b' s x) :
has_fderiv_within_at (λ y, a y * b y) (a x • b' + a'.smul_right (b x)) s x :=
((continuous_linear_map.lmul 𝕜 𝔸).is_bounded_bilinear_map.has_fderiv_at
(a x, b x)).comp_has_fderiv_within_at x (ha.prod hb)
theorem has_fderiv_within_at.mul
(hc : has_fderiv_within_at c c' s x) (hd : has_fderiv_within_at d d' s x) :
has_fderiv_within_at (λ y, c y * d y) (c x • d' + d x • c') s x :=
by { convert hc.mul' hd, ext z, apply mul_comm }
theorem has_fderiv_at.mul'
(ha : has_fderiv_at a a' x) (hb : has_fderiv_at b b' x) :
has_fderiv_at (λ y, a y * b y) (a x • b' + a'.smul_right (b x)) x :=
((continuous_linear_map.lmul 𝕜 𝔸).is_bounded_bilinear_map.has_fderiv_at (a x, b x)).comp x
(ha.prod hb)
theorem has_fderiv_at.mul (hc : has_fderiv_at c c' x) (hd : has_fderiv_at d d' x) :
has_fderiv_at (λ y, c y * d y) (c x • d' + d x • c') x :=
by { convert hc.mul' hd, ext z, apply mul_comm }
lemma differentiable_within_at.mul
(ha : differentiable_within_at 𝕜 a s x) (hb : differentiable_within_at 𝕜 b s x) :
differentiable_within_at 𝕜 (λ y, a y * b y) s x :=
(ha.has_fderiv_within_at.mul' hb.has_fderiv_within_at).differentiable_within_at
@[simp] lemma differentiable_at.mul (ha : differentiable_at 𝕜 a x) (hb : differentiable_at 𝕜 b x) :
differentiable_at 𝕜 (λ y, a y * b y) x :=
(ha.has_fderiv_at.mul' hb.has_fderiv_at).differentiable_at
lemma differentiable_on.mul (ha : differentiable_on 𝕜 a s) (hb : differentiable_on 𝕜 b s) :
differentiable_on 𝕜 (λ y, a y * b y) s :=
λx hx, (ha x hx).mul (hb x hx)
@[simp] lemma differentiable.mul (ha : differentiable 𝕜 a) (hb : differentiable 𝕜 b) :
differentiable 𝕜 (λ y, a y * b y) :=
λx, (ha x).mul (hb x)
lemma differentiable_within_at.pow (ha : differentiable_within_at 𝕜 a s x) :
∀ n : ℕ, differentiable_within_at 𝕜 (λ x, a x ^ n) s x
| 0 := by simp only [pow_zero, differentiable_within_at_const]
| (n + 1) := by simp only [pow_succ, differentiable_within_at.pow n, ha.mul]
@[simp] lemma differentiable_at.pow (ha : differentiable_at 𝕜 a x) (n : ℕ) :
differentiable_at 𝕜 (λ x, a x ^ n) x :=
differentiable_within_at_univ.mp $ ha.differentiable_within_at.pow n
lemma differentiable_on.pow (ha : differentiable_on 𝕜 a s) (n : ℕ) :
differentiable_on 𝕜 (λ x, a x ^ n) s :=
λ x h, (ha x h).pow n
@[simp] lemma differentiable.pow (ha : differentiable 𝕜 a) (n : ℕ) :
differentiable 𝕜 (λ x, a x ^ n) :=
λx, (ha x).pow n
lemma fderiv_within_mul' (hxs : unique_diff_within_at 𝕜 s x)
(ha : differentiable_within_at 𝕜 a s x) (hb : differentiable_within_at 𝕜 b s x) :
fderiv_within 𝕜 (λ y, a y * b y) s x =
a x • fderiv_within 𝕜 b s x + (fderiv_within 𝕜 a s x).smul_right (b x) :=
(ha.has_fderiv_within_at.mul' hb.has_fderiv_within_at).fderiv_within hxs
lemma fderiv_within_mul (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) :
fderiv_within 𝕜 (λ y, c y * d y) s x =
c x • fderiv_within 𝕜 d s x + d x • fderiv_within 𝕜 c s x :=
(hc.has_fderiv_within_at.mul hd.has_fderiv_within_at).fderiv_within hxs
lemma fderiv_mul' (ha : differentiable_at 𝕜 a x) (hb : differentiable_at 𝕜 b x) :
fderiv 𝕜 (λ y, a y * b y) x =
a x • fderiv 𝕜 b x + (fderiv 𝕜 a x).smul_right (b x) :=
(ha.has_fderiv_at.mul' hb.has_fderiv_at).fderiv
lemma fderiv_mul (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) :
fderiv 𝕜 (λ y, c y * d y) x =
c x • fderiv 𝕜 d x + d x • fderiv 𝕜 c x :=
(hc.has_fderiv_at.mul hd.has_fderiv_at).fderiv
theorem has_strict_fderiv_at.mul_const' (ha : has_strict_fderiv_at a a' x) (b : 𝔸) :
has_strict_fderiv_at (λ y, a y * b) (a'.smul_right b) x :=
(((continuous_linear_map.lmul 𝕜 𝔸).flip b).has_strict_fderiv_at).comp x ha
theorem has_strict_fderiv_at.mul_const (hc : has_strict_fderiv_at c c' x) (d : 𝔸') :
has_strict_fderiv_at (λ y, c y * d) (d • c') x :=
by { convert hc.mul_const' d, ext z, apply mul_comm }
theorem has_fderiv_within_at.mul_const' (ha : has_fderiv_within_at a a' s x) (b : 𝔸) :
has_fderiv_within_at (λ y, a y * b) (a'.smul_right b) s x :=
(((continuous_linear_map.lmul 𝕜 𝔸).flip b).has_fderiv_at).comp_has_fderiv_within_at x ha
theorem has_fderiv_within_at.mul_const (hc : has_fderiv_within_at c c' s x) (d : 𝔸') :
has_fderiv_within_at (λ y, c y * d) (d • c') s x :=
by { convert hc.mul_const' d, ext z, apply mul_comm }
theorem has_fderiv_at.mul_const' (ha : has_fderiv_at a a' x) (b : 𝔸) :
has_fderiv_at (λ y, a y * b) (a'.smul_right b) x :=
(((continuous_linear_map.lmul 𝕜 𝔸).flip b).has_fderiv_at).comp x ha
theorem has_fderiv_at.mul_const (hc : has_fderiv_at c c' x) (d : 𝔸') :
has_fderiv_at (λ y, c y * d) (d • c') x :=
by { convert hc.mul_const' d, ext z, apply mul_comm }
lemma differentiable_within_at.mul_const
(ha : differentiable_within_at 𝕜 a s x) (b : 𝔸) :
differentiable_within_at 𝕜 (λ y, a y * b) s x :=
(ha.has_fderiv_within_at.mul_const' b).differentiable_within_at
lemma differentiable_at.mul_const (ha : differentiable_at 𝕜 a x) (b : 𝔸) :
differentiable_at 𝕜 (λ y, a y * b) x :=
(ha.has_fderiv_at.mul_const' b).differentiable_at
lemma differentiable_on.mul_const (ha : differentiable_on 𝕜 a s) (b : 𝔸) :
differentiable_on 𝕜 (λ y, a y * b) s :=
λx hx, (ha x hx).mul_const b
lemma differentiable.mul_const (ha : differentiable 𝕜 a) (b : 𝔸) :
differentiable 𝕜 (λ y, a y * b) :=
λx, (ha x).mul_const b
lemma fderiv_within_mul_const' (hxs : unique_diff_within_at 𝕜 s x)
(ha : differentiable_within_at 𝕜 a s x) (b : 𝔸) :
fderiv_within 𝕜 (λ y, a y * b) s x = (fderiv_within 𝕜 a s x).smul_right b :=
(ha.has_fderiv_within_at.mul_const' b).fderiv_within hxs
lemma fderiv_within_mul_const (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (d : 𝔸') :
fderiv_within 𝕜 (λ y, c y * d) s x = d • fderiv_within 𝕜 c s x :=
(hc.has_fderiv_within_at.mul_const d).fderiv_within hxs
lemma fderiv_mul_const' (ha : differentiable_at 𝕜 a x) (b : 𝔸) :
fderiv 𝕜 (λ y, a y * b) x = (fderiv 𝕜 a x).smul_right b :=
(ha.has_fderiv_at.mul_const' b).fderiv
lemma fderiv_mul_const (hc : differentiable_at 𝕜 c x) (d : 𝔸') :
fderiv 𝕜 (λ y, c y * d) x = d • fderiv 𝕜 c x :=
(hc.has_fderiv_at.mul_const d).fderiv
theorem has_strict_fderiv_at.const_mul (ha : has_strict_fderiv_at a a' x) (b : 𝔸) :
has_strict_fderiv_at (λ y, b * a y) (b • a') x :=
(((continuous_linear_map.lmul 𝕜 𝔸) b).has_strict_fderiv_at).comp x ha
theorem has_fderiv_within_at.const_mul
(ha : has_fderiv_within_at a a' s x) (b : 𝔸) :
has_fderiv_within_at (λ y, b * a y) (b • a') s x :=
(((continuous_linear_map.lmul 𝕜 𝔸) b).has_fderiv_at).comp_has_fderiv_within_at x ha
theorem has_fderiv_at.const_mul (ha : has_fderiv_at a a' x) (b : 𝔸) :
has_fderiv_at (λ y, b * a y) (b • a') x :=
(((continuous_linear_map.lmul 𝕜 𝔸) b).has_fderiv_at).comp x ha
lemma differentiable_within_at.const_mul
(ha : differentiable_within_at 𝕜 a s x) (b : 𝔸) :
differentiable_within_at 𝕜 (λ y, b * a y) s x :=
(ha.has_fderiv_within_at.const_mul b).differentiable_within_at
lemma differentiable_at.const_mul (ha : differentiable_at 𝕜 a x) (b : 𝔸) :
differentiable_at 𝕜 (λ y, b * a y) x :=
(ha.has_fderiv_at.const_mul b).differentiable_at
lemma differentiable_on.const_mul (ha : differentiable_on 𝕜 a s) (b : 𝔸) :
differentiable_on 𝕜 (λ y, b * a y) s :=
λx hx, (ha x hx).const_mul b
lemma differentiable.const_mul (ha : differentiable 𝕜 a) (b : 𝔸) :
differentiable 𝕜 (λ y, b * a y) :=
λx, (ha x).const_mul b
lemma fderiv_within_const_mul (hxs : unique_diff_within_at 𝕜 s x)
(ha : differentiable_within_at 𝕜 a s x) (b : 𝔸) :
fderiv_within 𝕜 (λ y, b * a y) s x = b • fderiv_within 𝕜 a s x :=
(ha.has_fderiv_within_at.const_mul b).fderiv_within hxs
lemma fderiv_const_mul (ha : differentiable_at 𝕜 a x) (b : 𝔸) :
fderiv 𝕜 (λ y, b * a y) x = b • fderiv 𝕜 a x :=
(ha.has_fderiv_at.const_mul b).fderiv
end mul
section algebra_inverse
variables {R : Type*} [normed_ring R] [normed_algebra 𝕜 R] [complete_space R]
open normed_ring continuous_linear_map ring
/-- At an invertible element `x` of a normed algebra `R`, the Fréchet derivative of the inversion
operation is the linear map `λ t, - x⁻¹ * t * x⁻¹`. -/
lemma has_fderiv_at_ring_inverse (x : Rˣ) :
has_fderiv_at ring.inverse (-lmul_left_right 𝕜 R ↑x⁻¹ ↑x⁻¹) x :=
begin
have h_is_o : (λ (t : R), inverse (↑x + t) - ↑x⁻¹ + ↑x⁻¹ * t * ↑x⁻¹) =o[𝓝 0] (λ (t : R), t),
{ refine (inverse_add_norm_diff_second_order x).trans_is_o ((is_o_norm_norm).mp _),
simp only [norm_pow, norm_norm],
have h12 : 1 < 2 := by norm_num,
convert (asymptotics.is_o_pow_pow h12).comp_tendsto tendsto_norm_zero,
ext, simp },
have h_lim : tendsto (λ (y:R), y - x) (𝓝 x) (𝓝 0),
{ refine tendsto_zero_iff_norm_tendsto_zero.mpr _,
exact tendsto_iff_norm_tendsto_zero.mp tendsto_id },
simp only [has_fderiv_at, has_fderiv_at_filter],
convert h_is_o.comp_tendsto h_lim,
ext y,
simp only [coe_comp', function.comp_app, lmul_left_right_apply, neg_apply, inverse_unit x,
units.inv_mul, add_sub_cancel'_right, mul_sub, sub_mul, one_mul, sub_neg_eq_add]
end
lemma differentiable_at_inverse (x : Rˣ) : differentiable_at 𝕜 (@ring.inverse R _) x :=
(has_fderiv_at_ring_inverse x).differentiable_at
lemma fderiv_inverse (x : Rˣ) :
fderiv 𝕜 (@ring.inverse R _) x = - lmul_left_right 𝕜 R ↑x⁻¹ ↑x⁻¹ :=
(has_fderiv_at_ring_inverse x).fderiv
end algebra_inverse
namespace continuous_linear_equiv
/-! ### Differentiability of linear equivs, and invariance of differentiability -/
variable (iso : E ≃L[𝕜] F)
protected lemma has_strict_fderiv_at :
has_strict_fderiv_at iso (iso : E →L[𝕜] F) x :=
iso.to_continuous_linear_map.has_strict_fderiv_at
protected lemma has_fderiv_within_at :
has_fderiv_within_at iso (iso : E →L[𝕜] F) s x :=
iso.to_continuous_linear_map.has_fderiv_within_at
protected lemma has_fderiv_at : has_fderiv_at iso (iso : E →L[𝕜] F) x :=
iso.to_continuous_linear_map.has_fderiv_at_filter
protected lemma differentiable_at : differentiable_at 𝕜 iso x :=
iso.has_fderiv_at.differentiable_at
protected lemma differentiable_within_at :
differentiable_within_at 𝕜 iso s x :=
iso.differentiable_at.differentiable_within_at
protected lemma fderiv : fderiv 𝕜 iso x = iso :=
iso.has_fderiv_at.fderiv
protected lemma fderiv_within (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 iso s x = iso :=
iso.to_continuous_linear_map.fderiv_within hxs
protected lemma differentiable : differentiable 𝕜 iso :=
λx, iso.differentiable_at
protected lemma differentiable_on : differentiable_on 𝕜 iso s :=
iso.differentiable.differentiable_on
lemma comp_differentiable_within_at_iff {f : G → E} {s : set G} {x : G} :
differentiable_within_at 𝕜 (iso ∘ f) s x ↔ differentiable_within_at 𝕜 f s x :=
begin
refine ⟨λ H, _, λ H, iso.differentiable.differentiable_at.comp_differentiable_within_at x H⟩,
have : differentiable_within_at 𝕜 (iso.symm ∘ (iso ∘ f)) s x :=
iso.symm.differentiable.differentiable_at.comp_differentiable_within_at x H,
rwa [← function.comp.assoc iso.symm iso f, iso.symm_comp_self] at this,
end
lemma comp_differentiable_at_iff {f : G → E} {x : G} :
differentiable_at 𝕜 (iso ∘ f) x ↔ differentiable_at 𝕜 f x :=
by rw [← differentiable_within_at_univ, ← differentiable_within_at_univ,
iso.comp_differentiable_within_at_iff]
lemma comp_differentiable_on_iff {f : G → E} {s : set G} :
differentiable_on 𝕜 (iso ∘ f) s ↔ differentiable_on 𝕜 f s :=
begin
rw [differentiable_on, differentiable_on],
simp only [iso.comp_differentiable_within_at_iff],
end
lemma comp_differentiable_iff {f : G → E} :
differentiable 𝕜 (iso ∘ f) ↔ differentiable 𝕜 f :=
begin
rw [← differentiable_on_univ, ← differentiable_on_univ],
exact iso.comp_differentiable_on_iff
end
lemma comp_has_fderiv_within_at_iff
{f : G → E} {s : set G} {x : G} {f' : G →L[𝕜] E} :
has_fderiv_within_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') s x ↔ has_fderiv_within_at f f' s x :=
begin
refine ⟨λ H, _, λ H, iso.has_fderiv_at.comp_has_fderiv_within_at x H⟩,
have A : f = iso.symm ∘ (iso ∘ f), by { rw [← function.comp.assoc, iso.symm_comp_self], refl },
have B : f' = (iso.symm : F →L[𝕜] E).comp ((iso : E →L[𝕜] F).comp f'),
by rw [← continuous_linear_map.comp_assoc, iso.coe_symm_comp_coe,
continuous_linear_map.id_comp],
rw [A, B],
exact iso.symm.has_fderiv_at.comp_has_fderiv_within_at x H
end
lemma comp_has_strict_fderiv_at_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} :
has_strict_fderiv_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ has_strict_fderiv_at f f' x :=
begin
refine ⟨λ H, _, λ H, iso.has_strict_fderiv_at.comp x H⟩,
convert iso.symm.has_strict_fderiv_at.comp x H; ext z; apply (iso.symm_apply_apply _).symm
end
lemma comp_has_fderiv_at_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} :
has_fderiv_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ has_fderiv_at f f' x :=
by rw [← has_fderiv_within_at_univ, ← has_fderiv_within_at_univ, iso.comp_has_fderiv_within_at_iff]
lemma comp_has_fderiv_within_at_iff'
{f : G → E} {s : set G} {x : G} {f' : G →L[𝕜] F} :
has_fderiv_within_at (iso ∘ f) f' s x ↔
has_fderiv_within_at f ((iso.symm : F →L[𝕜] E).comp f') s x :=
by rw [← iso.comp_has_fderiv_within_at_iff, ← continuous_linear_map.comp_assoc,
iso.coe_comp_coe_symm, continuous_linear_map.id_comp]
lemma comp_has_fderiv_at_iff' {f : G → E} {x : G} {f' : G →L[𝕜] F} :
has_fderiv_at (iso ∘ f) f' x ↔ has_fderiv_at f ((iso.symm : F →L[𝕜] E).comp f') x :=
by rw [← has_fderiv_within_at_univ, ← has_fderiv_within_at_univ, iso.comp_has_fderiv_within_at_iff']
lemma comp_fderiv_within {f : G → E} {s : set G} {x : G}
(hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (iso ∘ f) s x = (iso : E →L[𝕜] F).comp (fderiv_within 𝕜 f s x) :=
begin
by_cases h : differentiable_within_at 𝕜 f s x,
{ rw [fderiv.comp_fderiv_within x iso.differentiable_at h hxs, iso.fderiv] },
{ have : ¬differentiable_within_at 𝕜 (iso ∘ f) s x,
from mt iso.comp_differentiable_within_at_iff.1 h,
rw [fderiv_within_zero_of_not_differentiable_within_at h,
fderiv_within_zero_of_not_differentiable_within_at this,
continuous_linear_map.comp_zero] }
end
lemma comp_fderiv {f : G → E} {x : G} :
fderiv 𝕜 (iso ∘ f) x = (iso : E →L[𝕜] F).comp (fderiv 𝕜 f x) :=
begin
rw [← fderiv_within_univ, ← fderiv_within_univ],
exact iso.comp_fderiv_within unique_diff_within_at_univ,
end
end continuous_linear_equiv
namespace linear_isometry_equiv
/-! ### Differentiability of linear isometry equivs, and invariance of differentiability -/
variable (iso : E ≃ₗᵢ[𝕜] F)
protected lemma has_strict_fderiv_at : has_strict_fderiv_at iso (iso : E →L[𝕜] F) x :=
(iso : E ≃L[𝕜] F).has_strict_fderiv_at
protected lemma has_fderiv_within_at : has_fderiv_within_at iso (iso : E →L[𝕜] F) s x :=
(iso : E ≃L[𝕜] F).has_fderiv_within_at
protected lemma has_fderiv_at : has_fderiv_at iso (iso : E →L[𝕜] F) x :=
(iso : E ≃L[𝕜] F).has_fderiv_at
protected lemma differentiable_at : differentiable_at 𝕜 iso x :=
iso.has_fderiv_at.differentiable_at
protected lemma differentiable_within_at :
differentiable_within_at 𝕜 iso s x :=
iso.differentiable_at.differentiable_within_at
protected lemma fderiv : fderiv 𝕜 iso x = iso := iso.has_fderiv_at.fderiv
protected lemma fderiv_within (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 iso s x = iso :=
(iso : E ≃L[𝕜] F).fderiv_within hxs
protected lemma differentiable : differentiable 𝕜 iso :=
λx, iso.differentiable_at
protected lemma differentiable_on : differentiable_on 𝕜 iso s :=
iso.differentiable.differentiable_on
lemma comp_differentiable_within_at_iff {f : G → E} {s : set G} {x : G} :
differentiable_within_at 𝕜 (iso ∘ f) s x ↔ differentiable_within_at 𝕜 f s x :=
(iso : E ≃L[𝕜] F).comp_differentiable_within_at_iff
lemma comp_differentiable_at_iff {f : G → E} {x : G} :
differentiable_at 𝕜 (iso ∘ f) x ↔ differentiable_at 𝕜 f x :=
(iso : E ≃L[𝕜] F).comp_differentiable_at_iff
lemma comp_differentiable_on_iff {f : G → E} {s : set G} :
differentiable_on 𝕜 (iso ∘ f) s ↔ differentiable_on 𝕜 f s :=
(iso : E ≃L[𝕜] F).comp_differentiable_on_iff
lemma comp_differentiable_iff {f : G → E} :
differentiable 𝕜 (iso ∘ f) ↔ differentiable 𝕜 f :=
(iso : E ≃L[𝕜] F).comp_differentiable_iff
lemma comp_has_fderiv_within_at_iff
{f : G → E} {s : set G} {x : G} {f' : G →L[𝕜] E} :
has_fderiv_within_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') s x ↔ has_fderiv_within_at f f' s x :=
(iso : E ≃L[𝕜] F).comp_has_fderiv_within_at_iff
lemma comp_has_strict_fderiv_at_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} :
has_strict_fderiv_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ has_strict_fderiv_at f f' x :=
(iso : E ≃L[𝕜] F).comp_has_strict_fderiv_at_iff
lemma comp_has_fderiv_at_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} :
has_fderiv_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ has_fderiv_at f f' x :=
(iso : E ≃L[𝕜] F).comp_has_fderiv_at_iff
lemma comp_has_fderiv_within_at_iff'
{f : G → E} {s : set G} {x : G} {f' : G →L[𝕜] F} :
has_fderiv_within_at (iso ∘ f) f' s x ↔
has_fderiv_within_at f ((iso.symm : F →L[𝕜] E).comp f') s x :=
(iso : E ≃L[𝕜] F).comp_has_fderiv_within_at_iff'
lemma comp_has_fderiv_at_iff' {f : G → E} {x : G} {f' : G →L[𝕜] F} :
has_fderiv_at (iso ∘ f) f' x ↔ has_fderiv_at f ((iso.symm : F →L[𝕜] E).comp f') x :=
(iso : E ≃L[𝕜] F).comp_has_fderiv_at_iff'
lemma comp_fderiv_within {f : G → E} {s : set G} {x : G}
(hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (iso ∘ f) s x = (iso : E →L[𝕜] F).comp (fderiv_within 𝕜 f s x) :=
(iso : E ≃L[𝕜] F).comp_fderiv_within hxs
lemma comp_fderiv {f : G → E} {x : G} :
fderiv 𝕜 (iso ∘ f) x = (iso : E →L[𝕜] F).comp (fderiv 𝕜 f x) :=
(iso : E ≃L[𝕜] F).comp_fderiv
end linear_isometry_equiv
/-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an
invertible derivative `f'` at `g a` in the strict sense, then `g` has the derivative `f'⁻¹` at `a`
in the strict sense.
This is one of the easy parts of the inverse function theorem: it assumes that we already have an
inverse function. -/
theorem has_strict_fderiv_at.of_local_left_inverse {f : E → F} {f' : E ≃L[𝕜] F} {g : F → E} {a : F}
(hg : continuous_at g a) (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) (g a))
(hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) :
has_strict_fderiv_at g (f'.symm : F →L[𝕜] E) a :=
begin
replace hg := hg.prod_map' hg,
replace hfg := hfg.prod_mk_nhds hfg,
have : (λ p : F × F, g p.1 - g p.2 - f'.symm (p.1 - p.2)) =O[𝓝 (a, a)]
(λ p : F × F, f' (g p.1 - g p.2) - (p.1 - p.2)),
{ refine ((f'.symm : F →L[𝕜] E).is_O_comp _ _).congr (λ x, _) (λ _, rfl),
simp },
refine this.trans_is_o _, clear this,
refine ((hf.comp_tendsto hg).symm.congr' (hfg.mono _)
(eventually_of_forall $ λ _, rfl)).trans_is_O _,
{ rintros p ⟨hp1, hp2⟩,
simp [hp1, hp2] },
{ refine (hf.is_O_sub_rev.comp_tendsto hg).congr'
(eventually_of_forall $ λ _, rfl) (hfg.mono _),
rintros p ⟨hp1, hp2⟩,
simp only [(∘), hp1, hp2] }
end
/-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an
invertible derivative `f'` at `g a`, then `g` has the derivative `f'⁻¹` at `a`.
This is one of the easy parts of the inverse function theorem: it assumes that we already have
an inverse function. -/
theorem has_fderiv_at.of_local_left_inverse {f : E → F} {f' : E ≃L[𝕜] F} {g : F → E} {a : F}
(hg : continuous_at g a) (hf : has_fderiv_at f (f' : E →L[𝕜] F) (g a))
(hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) :
has_fderiv_at g (f'.symm : F →L[𝕜] E) a :=
begin
have : (λ x : F, g x - g a - f'.symm (x - a)) =O[𝓝 a] (λ x : F, f' (g x - g a) - (x - a)),
{ refine ((f'.symm : F →L[𝕜] E).is_O_comp _ _).congr (λ x, _) (λ _, rfl),
simp },
refine this.trans_is_o _, clear this,
refine ((hf.comp_tendsto hg).symm.congr' (hfg.mono _)
(eventually_of_forall $ λ _, rfl)).trans_is_O _,
{ rintros p hp,
simp [hp, hfg.self_of_nhds] },
{ refine ((hf.is_O_sub_rev f'.antilipschitz).comp_tendsto hg).congr'
(eventually_of_forall $ λ _, rfl) (hfg.mono _),
rintros p hp,
simp only [(∘), hp, hfg.self_of_nhds] }
end
/-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has an
invertible derivative `f'` in the sense of strict differentiability at `f.symm a`, then `f.symm` has
the derivative `f'⁻¹` at `a`.
This is one of the easy parts of the inverse function theorem: it assumes that we already have
an inverse function. -/
lemma local_homeomorph.has_strict_fderiv_at_symm (f : local_homeomorph E F) {f' : E ≃L[𝕜] F} {a : F}
(ha : a ∈ f.target) (htff' : has_strict_fderiv_at f (f' : E →L[𝕜] F) (f.symm a)) :
has_strict_fderiv_at f.symm (f'.symm : F →L[𝕜] E) a :=
htff'.of_local_left_inverse (f.symm.continuous_at ha) (f.eventually_right_inverse ha)
/-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has an
invertible derivative `f'` at `f.symm a`, then `f.symm` has the derivative `f'⁻¹` at `a`.
This is one of the easy parts of the inverse function theorem: it assumes that we already have
an inverse function. -/
lemma local_homeomorph.has_fderiv_at_symm (f : local_homeomorph E F) {f' : E ≃L[𝕜] F} {a : F}
(ha : a ∈ f.target) (htff' : has_fderiv_at f (f' : E →L[𝕜] F) (f.symm a)) :
has_fderiv_at f.symm (f'.symm : F →L[𝕜] E) a :=
htff'.of_local_left_inverse (f.symm.continuous_at ha) (f.eventually_right_inverse ha)
lemma has_fderiv_within_at.eventually_ne (h : has_fderiv_within_at f f' s x)
(hf' : ∃ C, ∀ z, ∥z∥ ≤ C * ∥f' z∥) :
∀ᶠ z in 𝓝[s \ {x}] x, f z ≠ f x :=
begin
rw [nhds_within, diff_eq, ← inf_principal, ← inf_assoc, eventually_inf_principal],
have A : (λ z, z - x) =O[𝓝[s] x] (λ z, f' (z - x)) :=
(is_O_iff.2 $ hf'.imp $ λ C hC, eventually_of_forall $ λ z, hC _),
have : (λ z, f z - f x) ~[𝓝[s] x] (λ z, f' (z - x)) := h.trans_is_O A,
simpa [not_imp_not, sub_eq_zero] using (A.trans this.is_O_symm).eq_zero_imp
end
lemma has_fderiv_at.eventually_ne (h : has_fderiv_at f f' x) (hf' : ∃ C, ∀ z, ∥z∥ ≤ C * ∥f' z∥) :
∀ᶠ z in 𝓝[≠] x, f z ≠ f x :=
by simpa only [compl_eq_univ_diff] using (has_fderiv_within_at_univ.2 h).eventually_ne hf'
end
section
/-
In the special case of a normed space over the reals,
we can use scalar multiplication in the `tendsto` characterization
of the Fréchet derivative.
-/
variables {E : Type*} [normed_add_comm_group E] [normed_space ℝ E]
variables {F : Type*} [normed_add_comm_group F] [normed_space ℝ F]
variables {f : E → F} {f' : E →L[ℝ] F} {x : E}
theorem has_fderiv_at_filter_real_equiv {L : filter E} :
tendsto (λ x' : E, ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) L (𝓝 0) ↔
tendsto (λ x' : E, ∥x' - x∥⁻¹ • (f x' - f x - f' (x' - x))) L (𝓝 0) :=
begin
symmetry,
rw [tendsto_iff_norm_tendsto_zero], refine tendsto_congr (λ x', _),
have : ∥x' - x∥⁻¹ ≥ 0, from inv_nonneg.mpr (norm_nonneg _),
simp [norm_smul, abs_of_nonneg this]
end
lemma has_fderiv_at.lim_real (hf : has_fderiv_at f f' x) (v : E) :
tendsto (λ (c:ℝ), c • (f (x + c⁻¹ • v) - f x)) at_top (𝓝 (f' v)) :=
begin
apply hf.lim v,
rw tendsto_at_top_at_top,
exact λ b, ⟨b, λ a ha, le_trans ha (le_abs_self _)⟩
end
end
section tangent_cone
variables {𝕜 : Type*} [nontrivially_normed_field 𝕜]
{E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E]
{F : Type*} [normed_add_comm_group F] [normed_space 𝕜 F]
{f : E → F} {s : set E} {f' : E →L[𝕜] F}
/-- The image of a tangent cone under the differential of a map is included in the tangent cone to
the image. -/
lemma has_fderiv_within_at.maps_to_tangent_cone {x : E} (h : has_fderiv_within_at f f' s x) :
maps_to f' (tangent_cone_at 𝕜 s x) (tangent_cone_at 𝕜 (f '' s) (f x)) :=
begin
rintros v ⟨c, d, dtop, clim, cdlim⟩,
refine ⟨c, (λn, f (x + d n) - f x), mem_of_superset dtop _, clim,
h.lim at_top dtop clim cdlim⟩,
simp [-mem_image, mem_image_of_mem] {contextual := tt}
end
/-- If a set has the unique differentiability property at a point x, then the image of this set
under a map with onto derivative has also the unique differentiability property at the image point.
-/
lemma has_fderiv_within_at.unique_diff_within_at {x : E} (h : has_fderiv_within_at f f' s x)
(hs : unique_diff_within_at 𝕜 s x) (h' : dense_range f') :
unique_diff_within_at 𝕜 (f '' s) (f x) :=
begin
refine ⟨h'.dense_of_maps_to f'.continuous hs.1 _,
h.continuous_within_at.mem_closure_image hs.2⟩,
show submodule.span 𝕜 (tangent_cone_at 𝕜 s x) ≤
(submodule.span 𝕜 (tangent_cone_at 𝕜 (f '' s) (f x))).comap ↑f',
rw [submodule.span_le],
exact h.maps_to_tangent_cone.mono (subset.refl _) submodule.subset_span
end
lemma unique_diff_on.image {f' : E → E →L[𝕜] F} (hs : unique_diff_on 𝕜 s)
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) (hd : ∀ x ∈ s, dense_range (f' x)) :
unique_diff_on 𝕜 (f '' s) :=
ball_image_iff.2 $ λ x hx, (hf' x hx).unique_diff_within_at (hs x hx) (hd x hx)
lemma has_fderiv_within_at.unique_diff_within_at_of_continuous_linear_equiv
{x : E} (e' : E ≃L[𝕜] F) (h : has_fderiv_within_at f (e' : E →L[𝕜] F) s x)
(hs : unique_diff_within_at 𝕜 s x) :
unique_diff_within_at 𝕜 (f '' s) (f x) :=
h.unique_diff_within_at hs e'.surjective.dense_range
lemma continuous_linear_equiv.unique_diff_on_image (e : E ≃L[𝕜] F) (h : unique_diff_on 𝕜 s) :
unique_diff_on 𝕜 (e '' s) :=
h.image (λ x _, e.has_fderiv_within_at) (λ x hx, e.surjective.dense_range)
@[simp] lemma continuous_linear_equiv.unique_diff_on_image_iff (e : E ≃L[𝕜] F) :
unique_diff_on 𝕜 (e '' s) ↔ unique_diff_on 𝕜 s :=
⟨λ h, e.symm_image_image s ▸ e.symm.unique_diff_on_image h, e.unique_diff_on_image⟩
@[simp] lemma continuous_linear_equiv.unique_diff_on_preimage_iff (e : F ≃L[𝕜] E) :
unique_diff_on 𝕜 (e ⁻¹' s) ↔ unique_diff_on 𝕜 s :=
by rw [← e.image_symm_eq_preimage, e.symm.unique_diff_on_image_iff]
end tangent_cone
section restrict_scalars
/-!
### Restricting from `ℂ` to `ℝ`, or generally from `𝕜'` to `𝕜`
If a function is differentiable over `ℂ`, then it is differentiable over `ℝ`. In this paragraph,
we give variants of this statement, in the general situation where `ℂ` and `ℝ` are replaced
respectively by `𝕜'` and `𝕜` where `𝕜'` is a normed algebra over `𝕜`.
-/
variables (𝕜 : Type*) [nontrivially_normed_field 𝕜]
variables {𝕜' : Type*} [nontrivially_normed_field 𝕜'] [normed_algebra 𝕜 𝕜']
variables {E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E] [normed_space 𝕜' E]
variables [is_scalar_tower 𝕜 𝕜' E]
variables {F : Type*} [normed_add_comm_group F] [normed_space 𝕜 F] [normed_space 𝕜' F]
variables [is_scalar_tower 𝕜 𝕜' F]
variables {f : E → F} {f' : E →L[𝕜'] F} {s : set E} {x : E}
lemma has_strict_fderiv_at.restrict_scalars (h : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at f (f'.restrict_scalars 𝕜) x := h
lemma has_fderiv_at_filter.restrict_scalars {L} (h : has_fderiv_at_filter f f' x L) :
has_fderiv_at_filter f (f'.restrict_scalars 𝕜) x L := h
lemma has_fderiv_at.restrict_scalars (h : has_fderiv_at f f' x) :
has_fderiv_at f (f'.restrict_scalars 𝕜) x := h
lemma has_fderiv_within_at.restrict_scalars (h : has_fderiv_within_at f f' s x) :
has_fderiv_within_at f (f'.restrict_scalars 𝕜) s x := h
lemma differentiable_at.restrict_scalars (h : differentiable_at 𝕜' f x) :
differentiable_at 𝕜 f x :=
(h.has_fderiv_at.restrict_scalars 𝕜).differentiable_at
lemma differentiable_within_at.restrict_scalars (h : differentiable_within_at 𝕜' f s x) :
differentiable_within_at 𝕜 f s x :=
(h.has_fderiv_within_at.restrict_scalars 𝕜).differentiable_within_at
lemma differentiable_on.restrict_scalars (h : differentiable_on 𝕜' f s) :
differentiable_on 𝕜 f s :=
λx hx, (h x hx).restrict_scalars 𝕜
lemma differentiable.restrict_scalars (h : differentiable 𝕜' f) :
differentiable 𝕜 f :=
λx, (h x).restrict_scalars 𝕜
lemma has_fderiv_within_at_of_restrict_scalars
{g' : E →L[𝕜] F} (h : has_fderiv_within_at f g' s x)
(H : f'.restrict_scalars 𝕜 = g') : has_fderiv_within_at f f' s x :=
by { rw ← H at h, exact h }
lemma has_fderiv_at_of_restrict_scalars {g' : E →L[𝕜] F} (h : has_fderiv_at f g' x)
(H : f'.restrict_scalars 𝕜 = g') : has_fderiv_at f f' x :=
by { rw ← H at h, exact h }
lemma differentiable_at.fderiv_restrict_scalars (h : differentiable_at 𝕜' f x) :
fderiv 𝕜 f x = (fderiv 𝕜' f x).restrict_scalars 𝕜 :=
(h.has_fderiv_at.restrict_scalars 𝕜).fderiv
lemma differentiable_within_at_iff_restrict_scalars
(hf : differentiable_within_at 𝕜 f s x) (hs : unique_diff_within_at 𝕜 s x) :
differentiable_within_at 𝕜' f s x ↔
∃ (g' : E →L[𝕜'] F), g'.restrict_scalars 𝕜 = fderiv_within 𝕜 f s x :=
begin
split,
{ rintros ⟨g', hg'⟩,
exact ⟨g', hs.eq (hg'.restrict_scalars 𝕜) hf.has_fderiv_within_at⟩, },
{ rintros ⟨f', hf'⟩,
exact ⟨f', has_fderiv_within_at_of_restrict_scalars 𝕜 hf.has_fderiv_within_at hf'⟩, },
end
lemma differentiable_at_iff_restrict_scalars (hf : differentiable_at 𝕜 f x) :
differentiable_at 𝕜' f x ↔ ∃ (g' : E →L[𝕜'] F), g'.restrict_scalars 𝕜 = fderiv 𝕜 f x :=
begin
rw [← differentiable_within_at_univ, ← fderiv_within_univ],
exact differentiable_within_at_iff_restrict_scalars 𝕜
hf.differentiable_within_at unique_diff_within_at_univ,
end
end restrict_scalars
/-! ### Support of derivatives -/
section support
open function
variables (𝕜 : Type*) {E F : Type*} [nontrivially_normed_field 𝕜] [normed_add_comm_group E]
[normed_space 𝕜 E] [normed_add_comm_group F] [normed_space 𝕜 F] {f : E → F}
lemma support_fderiv_subset : support (fderiv 𝕜 f) ⊆ tsupport f :=
begin
intros x,
rw [← not_imp_not],
intro h2x,
rw [not_mem_tsupport_iff_eventually_eq] at h2x,
exact nmem_support.mpr (h2x.fderiv_eq.trans $ fderiv_const_apply 0),
end
lemma has_compact_support.fderiv (hf : has_compact_support f) : has_compact_support (fderiv 𝕜 f) :=
hf.mono' $ support_fderiv_subset 𝕜
end support
|
4634d1718825ff3e2f65ffa31fe8b0596d86647e | 43390109ab88557e6090f3245c47479c123ee500 | /src/M1F/problem_bank/0104/S0104.lean | 6ca35555f69968c9596b5231f4732aae1a67c49e | [
"Apache-2.0"
] | permissive | Ja1941/xena-UROP-2018 | 41f0956519f94d56b8bf6834a8d39473f4923200 | b111fb87f343cf79eca3b886f99ee15c1dd9884b | refs/heads/master | 1,662,355,955,139 | 1,590,577,325,000 | 1,590,577,325,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,703 | lean | /-
M1F 2017-18 Sheet 1 Question 2 to 4 solutions.
Author : Kevin Buzzard
This file should work with any version of lean -- whether you installed it yourself
or are running the version on https://leanprover.github.io/live/latest/
-/
-- We probably need the "law of the excluded middle" for this question -- every
-- proposition is either true or false! Don't even ask me to explain what the
-- other options are, but Lean does not come with this axiom by default (blame
-- the computer scientists) and mathematicians have to add it themselves.
-- It's easy to add though. "em" for excluded middle.
axiom em (X : Prop) : X ∨ ¬ X
variables P Q R S : Prop -- A "Prop" is a proposition, that is, a true/false statement.
-- Sheet 1 Q4.
-- Let me first make a tool which is capable of proving all three hypotheses
-- when we have the right assumptions.
meta def prove_hyps : tactic unit :=
`[
{ -- This tactic will try to prove
-- (P → Q ∨ R) ∧ (¬ Q → R ∨ ¬ P) ∧ (Q ∧ R → ¬ P)
apply and.intro, -- next goal is P → Q ∨ R
intro, -- now P is a hypothesis and Q ∨ R is the goal.
-- next line works if any of ¬ P or Q or R are true.
contradiction <|> {left,assumption} <|> {right,assumption},
apply and.intro, -- same story,
intro,contradiction <|> {left,assumption} <|> {right,assumption},
-- next line attempts to prove Q and R -> not P.
intro HQR, --
have Q, from HQR.left,
have R, from HQR.right,
-- now Q and R are assumptions and not P is the goal.
assumption <|> contradiction
}
]
-- I used that tool to figure out what the answer is.
-- The answer to Q4 is that all three hypotheses are true if and only if either
-- (i) P is false, or
-- (ii) P is true, and exactly one of Q and R are true.
-- It's possible to write a very long proof of this.
-- But in this case I just did a brute force case by case check,
-- using basic tactics joined together with glue I learnt about
-- in section 5.5 of Theorem Proving In Lean.
theorem m1f_sheet01_q04 : (P → (Q ∨ R)) ∧ (¬ Q → (R ∨ ¬ P)) ∧ ((Q ∧ R) → ¬ P) ↔
(¬ P) ∨ (P ∧ Q ∧ ¬ R) ∨ (P ∧ ¬ Q ∧ R) :=
begin
cases em P with HP HnP;cases em Q with HQ HnQ;cases em R with HR HnR;apply iff.intro,
repeat {-- we'll do all eight cases automatically.
intro hyps,
cc, -- this does the case where hyps implies my solution
-- now check my solution implies hyps (possibly by contradiction)
intro hmypqr,
{ prove_hyps } <|> {
cases hmypqr with h1 h2,
contradiction,
cases h2 with ha hb,
cases ha with h3 h4,
cases h4,
contradiction,
cases hb with h5 h6,
cases h6,
contradiction
}
},
end |
4ed5eb54e1280171a5dcf9cc9bbb34f96c2904fc | 55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5 | /src/algebra/big_operators/order.lean | 7a022666875c44ff0750a6e0d21be079a7ffb15e | [
"Apache-2.0"
] | permissive | dupuisf/mathlib | 62de4ec6544bf3b79086afd27b6529acfaf2c1bb | 8582b06b0a5d06c33ee07d0bdf7c646cae22cf36 | refs/heads/master | 1,669,494,854,016 | 1,595,692,409,000 | 1,595,692,409,000 | 272,046,630 | 0 | 0 | Apache-2.0 | 1,592,066,143,000 | 1,592,066,142,000 | null | UTF-8 | Lean | false | false | 10,312 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import algebra.big_operators.basic
/-!
# Results about big operators with values in an ordered algebraic structure.
Mostly monotonicity results for the `∑` operation.
-/
universes u v w
open_locale big_operators
variables {α : Type u} {β : Type v} {γ : Type w}
namespace finset
variables {s s₁ s₂ : finset α} {a : α} {f g : α → β}
lemma le_sum_of_subadditive [add_comm_monoid α] [ordered_add_comm_monoid β]
(f : α → β) (h_zero : f 0 = 0) (h_add : ∀x y, f (x + y) ≤ f x + f y) (s : finset γ) (g : γ → α) :
f (∑ x in s, g x) ≤ ∑ x in s, f (g x) :=
begin
refine le_trans (multiset.le_sum_of_subadditive f h_zero h_add _) _,
rw [multiset.map_map],
refl
end
lemma abs_sum_le_sum_abs [discrete_linear_ordered_field α] {f : β → α} {s : finset β} :
abs (∑ x in s, f x) ≤ ∑ x in s, abs (f x) :=
le_sum_of_subadditive _ abs_zero abs_add s f
section ordered_add_comm_monoid
variables [ordered_add_comm_monoid β]
lemma sum_le_sum : (∀x∈s, f x ≤ g x) → (∑ x in s, f x) ≤ (∑ x in s, g x) :=
begin
classical,
apply finset.induction_on s,
exact (λ _, le_refl _),
assume a s ha ih h,
have : f a + (∑ x in s, f x) ≤ g a + (∑ x in s, g x),
from add_le_add (h _ (mem_insert_self _ _)) (ih $ assume x hx, h _ $ mem_insert_of_mem hx),
by simpa only [sum_insert ha]
end
theorem card_le_mul_card_image [decidable_eq γ] {f : α → γ} (s : finset α)
(n : ℕ) (hn : ∀ a ∈ s.image f, (s.filter (λ x, f x = a)).card ≤ n) :
s.card ≤ n * (s.image f).card :=
calc s.card = (∑ a in s.image f, (s.filter (λ x, f x = a)).card) :
card_eq_sum_card_image _ _
... ≤ (∑ _ in s.image f, n) : sum_le_sum hn
... = _ : by simp [mul_comm]
lemma sum_nonneg (h : ∀x∈s, 0 ≤ f x) : 0 ≤ (∑ x in s, f x) :=
le_trans (by rw [sum_const_zero]) (sum_le_sum h)
lemma sum_nonpos (h : ∀x∈s, f x ≤ 0) : (∑ x in s, f x) ≤ 0 :=
le_trans (sum_le_sum h) (by rw [sum_const_zero])
lemma sum_le_sum_of_subset_of_nonneg
(h : s₁ ⊆ s₂) (hf : ∀x∈s₂, x ∉ s₁ → 0 ≤ f x) : (∑ x in s₁, f x) ≤ (∑ x in s₂, f x) :=
by classical;
calc (∑ x in s₁, f x) ≤ (∑ x in s₂ \ s₁, f x) + (∑ x in s₁, f x) :
le_add_of_nonneg_left $ sum_nonneg $ by simpa only [mem_sdiff, and_imp]
... = ∑ x in s₂ \ s₁ ∪ s₁, f x : (sum_union sdiff_disjoint).symm
... = (∑ x in s₂, f x) : by rw [sdiff_union_of_subset h]
lemma sum_mono_set_of_nonneg (hf : ∀ x, 0 ≤ f x) : monotone (λ s, ∑ x in s, f x) :=
λ s₁ s₂ hs, sum_le_sum_of_subset_of_nonneg hs $ λ x _ _, hf x
lemma sum_eq_zero_iff_of_nonneg : (∀x∈s, 0 ≤ f x) → ((∑ x in s, f x) = 0 ↔ ∀x∈s, f x = 0) :=
begin
classical,
apply finset.induction_on s,
exact λ _, ⟨λ _ _, false.elim, λ _, rfl⟩,
assume a s ha ih H,
have : ∀ x ∈ s, 0 ≤ f x, from λ _, H _ ∘ mem_insert_of_mem,
rw [sum_insert ha, add_eq_zero_iff' (H _ $ mem_insert_self _ _) (sum_nonneg this),
forall_mem_insert, ih this]
end
lemma sum_eq_zero_iff_of_nonpos : (∀x∈s, f x ≤ 0) → ((∑ x in s, f x) = 0 ↔ ∀x∈s, f x = 0) :=
@sum_eq_zero_iff_of_nonneg _ (order_dual β) _ _ _
lemma single_le_sum (hf : ∀x∈s, 0 ≤ f x) {a} (h : a ∈ s) : f a ≤ (∑ x in s, f x) :=
have ∑ x in {a}, f x ≤ (∑ x in s, f x),
from sum_le_sum_of_subset_of_nonneg
(λ x e, (mem_singleton.1 e).symm ▸ h) (λ x h _, hf x h),
by rwa sum_singleton at this
end ordered_add_comm_monoid
section canonically_ordered_add_monoid
variables [canonically_ordered_add_monoid β]
@[simp] lemma sum_eq_zero_iff : ∑ x in s, f x = 0 ↔ ∀ x ∈ s, f x = 0 :=
sum_eq_zero_iff_of_nonneg $ λ x hx, zero_le (f x)
lemma sum_le_sum_of_subset (h : s₁ ⊆ s₂) : (∑ x in s₁, f x) ≤ (∑ x in s₂, f x) :=
sum_le_sum_of_subset_of_nonneg h $ assume x h₁ h₂, zero_le _
lemma sum_mono_set (f : α → β) : monotone (λ s, ∑ x in s, f x) :=
λ s₁ s₂ hs, sum_le_sum_of_subset hs
lemma sum_le_sum_of_ne_zero (h : ∀x∈s₁, f x ≠ 0 → x ∈ s₂) :
(∑ x in s₁, f x) ≤ (∑ x in s₂, f x) :=
by classical;
calc (∑ x in s₁, f x) = ∑ x in s₁.filter (λx, f x = 0), f x + ∑ x in s₁.filter (λx, f x ≠ 0), f x :
by rw [←sum_union, filter_union_filter_neg_eq];
exact disjoint_filter.2 (assume _ _ h n_h, n_h h)
... ≤ (∑ x in s₂, f x) : add_le_of_nonpos_of_le'
(sum_nonpos $ by simp only [mem_filter, and_imp]; exact λ _ _, le_of_eq)
(sum_le_sum_of_subset $ by simpa only [subset_iff, mem_filter, and_imp])
end canonically_ordered_add_monoid
section ordered_cancel_comm_monoid
variables [ordered_cancel_add_comm_monoid β]
theorem sum_lt_sum (Hle : ∀ i ∈ s, f i ≤ g i) (Hlt : ∃ i ∈ s, f i < g i) :
(∑ x in s, f x) < (∑ x in s, g x) :=
begin
classical,
rcases Hlt with ⟨i, hi, hlt⟩,
rw [← insert_erase hi, sum_insert (not_mem_erase _ _), sum_insert (not_mem_erase _ _)],
exact add_lt_add_of_lt_of_le hlt (sum_le_sum $ λ j hj, Hle j $ mem_of_mem_erase hj)
end
lemma sum_lt_sum_of_nonempty (hs : s.nonempty) (Hlt : ∀ x ∈ s, f x < g x) :
(∑ x in s, f x) < (∑ x in s, g x) :=
begin
apply sum_lt_sum,
{ intros i hi, apply le_of_lt (Hlt i hi) },
cases hs with i hi,
exact ⟨i, hi, Hlt i hi⟩,
end
lemma sum_lt_sum_of_subset [decidable_eq α]
(h : s₁ ⊆ s₂) {i : α} (hi : i ∈ s₂ \ s₁) (hpos : 0 < f i) (hnonneg : ∀ j ∈ s₂ \ s₁, 0 ≤ f j) :
(∑ x in s₁, f x) < (∑ x in s₂, f x) :=
calc (∑ x in s₁, f x) < (∑ x in insert i s₁, f x) :
begin
simp only [mem_sdiff] at hi,
rw sum_insert hi.2,
exact lt_add_of_pos_left (∑ x in s₁, f x) hpos,
end
... ≤ (∑ x in s₂, f x) :
begin
simp only [mem_sdiff] at hi,
apply sum_le_sum_of_subset_of_nonneg,
{ simp [finset.insert_subset, h, hi.1] },
{ assume x hx h'x,
apply hnonneg x,
simp [mem_insert, not_or_distrib] at h'x,
rw mem_sdiff,
simp [hx, h'x] }
end
end ordered_cancel_comm_monoid
section decidable_linear_ordered_cancel_comm_monoid
variables [decidable_linear_ordered_cancel_add_comm_monoid β]
theorem exists_le_of_sum_le (hs : s.nonempty) (Hle : (∑ x in s, f x) ≤ ∑ x in s, g x) :
∃ i ∈ s, f i ≤ g i :=
begin
classical,
contrapose! Hle with Hlt,
rcases hs with ⟨i, hi⟩,
exact sum_lt_sum (λ i hi, le_of_lt (Hlt i hi)) ⟨i, hi, Hlt i hi⟩
end
lemma exists_pos_of_sum_zero_of_exists_nonzero (f : α → β)
(h₁ : ∑ e in s, f e = 0) (h₂ : ∃ x ∈ s, f x ≠ 0) :
∃ x ∈ s, 0 < f x :=
begin
contrapose! h₁,
obtain ⟨x, m, x_nz⟩ : ∃ x ∈ s, f x ≠ 0 := h₂,
apply ne_of_lt,
calc ∑ e in s, f e < ∑ e in s, 0 : by { apply sum_lt_sum h₁ ⟨x, m, lt_of_le_of_ne (h₁ x m) x_nz⟩ }
... = 0 : by rw [finset.sum_const, nsmul_zero],
end
end decidable_linear_ordered_cancel_comm_monoid
section linear_ordered_comm_ring
variables [linear_ordered_comm_ring β]
open_locale classical
/- this is also true for a ordered commutative multiplicative monoid -/
lemma prod_nonneg {s : finset α} {f : α → β}
(h0 : ∀(x ∈ s), 0 ≤ f x) : 0 ≤ (∏ x in s, f x) :=
prod_induction f (λ x, 0 ≤ x) (λ _ _ ha hb, mul_nonneg ha hb) zero_le_one h0
/- this is also true for a ordered commutative multiplicative monoid -/
lemma prod_pos {s : finset α} {f : α → β} (h0 : ∀(x ∈ s), 0 < f x) : 0 < (∏ x in s, f x) :=
prod_induction f (λ x, 0 < x) (λ _ _ ha hb, mul_pos ha hb) zero_lt_one h0
/- this is also true for a ordered commutative multiplicative monoid -/
lemma prod_le_prod {s : finset α} {f g : α → β} (h0 : ∀(x ∈ s), 0 ≤ f x)
(h1 : ∀(x ∈ s), f x ≤ g x) : (∏ x in s, f x) ≤ (∏ x in s, g x) :=
begin
induction s using finset.induction with a s has ih h,
{ simp },
{ simp [has], apply mul_le_mul,
exact h1 a (mem_insert_self a s),
apply ih (λ x H, h0 _ _) (λ x H, h1 _ _); exact (mem_insert_of_mem H),
apply prod_nonneg (λ x H, h0 x (mem_insert_of_mem H)),
apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) }
end
end linear_ordered_comm_ring
section canonically_ordered_comm_semiring
variables [canonically_ordered_comm_semiring β]
lemma prod_le_prod' {s : finset α} {f g : α → β} (h : ∀ i ∈ s, f i ≤ g i) :
(∏ x in s, f x) ≤ (∏ x in s, g x) :=
begin
classical,
induction s using finset.induction with a s has ih h,
{ simp },
{ rw [finset.prod_insert has, finset.prod_insert has],
apply canonically_ordered_semiring.mul_le_mul,
{ exact h _ (finset.mem_insert_self a s) },
{ exact ih (λ i hi, h _ (finset.mem_insert_of_mem hi)) } }
end
end canonically_ordered_comm_semiring
end finset
namespace with_top
open finset
open_locale classical
/-- A sum of finite numbers is still finite -/
lemma sum_lt_top [ordered_add_comm_monoid β] {s : finset α} {f : α → with_top β} :
(∀a∈s, f a < ⊤) → (∑ x in s, f x) < ⊤ :=
λ h, sum_induction f (λ a, a < ⊤) (by { simp_rw add_lt_top, tauto }) zero_lt_top h
/-- A sum of finite numbers is still finite -/
lemma sum_lt_top_iff [canonically_ordered_add_monoid β] {s : finset α} {f : α → with_top β} :
(∑ x in s, f x) < ⊤ ↔ (∀a∈s, f a < ⊤) :=
iff.intro (λh a ha, lt_of_le_of_lt (single_le_sum (λa ha, zero_le _) ha) h) sum_lt_top
/-- A sum of numbers is infinite iff one of them is infinite -/
lemma sum_eq_top_iff [canonically_ordered_add_monoid β] {s : finset α} {f : α → with_top β} :
(∑ x in s, f x) = ⊤ ↔ (∃a∈s, f a = ⊤) :=
begin
rw ← not_iff_not,
push_neg,
simp only [← lt_top_iff_ne_top],
exact sum_lt_top_iff
end
open opposite
/-- Moving to the opposite additive commutative monoid commutes with summing. -/
@[simp] lemma op_sum [add_comm_monoid β] {s : finset α} (f : α → β) :
op (∑ x in s, f x) = ∑ x in s, op (f x) :=
(@op_add_hom β _).map_sum _ _
@[simp] lemma unop_sum [add_comm_monoid β] {s : finset α} (f : α → βᵒᵖ) :
unop (∑ x in s, f x) = ∑ x in s, unop (f x) :=
(@unop_add_hom β _).map_sum _ _
end with_top
|
260525f49ef3957273d67a4d6a1061c8755359ec | 69d4931b605e11ca61881fc4f66db50a0a875e39 | /src/number_theory/fermat4.lean | b156b25ba66feef5429e813f4c522481f5ea617a | [
"Apache-2.0"
] | permissive | abentkamp/mathlib | d9a75d291ec09f4637b0f30cc3880ffb07549ee5 | 5360e476391508e092b5a1e5210bd0ed22dc0755 | refs/heads/master | 1,682,382,954,948 | 1,622,106,077,000 | 1,622,106,077,000 | 149,285,665 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 12,344 | lean | /-
Copyright (c) 2020 Paul van Wamelen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Paul van Wamelen
-/
import number_theory.pythagorean_triples
import ring_theory.coprime
/-!
# Fermat's Last Theorem for the case n = 4
There are no non-zero integers `a`, `b` and `c` such that `a ^ 4 + b ^ 4 = c ^ 4`.
-/
noncomputable theory
open_locale classical
/-- Shorthand for three non-zero integers `a`, `b`, and `c` satisfying `a ^ 4 + b ^ 4 = c ^ 2`.
We will show that no integers satisfy this equation. Clearly Fermat's Last theorem for n = 4
follows. -/
def fermat_42 (a b c : ℤ) : Prop := a ≠ 0 ∧ b ≠ 0 ∧ a ^ 4 + b ^ 4 = c ^ 2
namespace fermat_42
lemma comm {a b c : ℤ} :
(fermat_42 a b c) ↔ (fermat_42 b a c) :=
by { delta fermat_42, rw add_comm, tauto }
lemma mul {a b c k : ℤ} (hk0 : k ≠ 0) :
fermat_42 a b c ↔ fermat_42 (k * a) (k * b) (k ^ 2 * c) :=
begin
delta fermat_42,
split,
{ intro f42,
split, { exact mul_ne_zero hk0 f42.1 },
split, { exact mul_ne_zero hk0 f42.2.1 },
{ calc (k * a) ^ 4 + (k * b) ^ 4
= k ^ 4 * (a ^ 4 + b ^ 4) : by ring
... = k ^ 4 * c ^ 2 : by rw f42.2.2
... = (k ^ 2 * c) ^ 2 : by ring }},
{ intro f42,
split, { exact right_ne_zero_of_mul f42.1 },
split, { exact right_ne_zero_of_mul f42.2.1 },
apply (mul_right_inj' (pow_ne_zero 4 hk0)).mp,
{ calc k ^ 4 * (a ^ 4 + b ^ 4)
= (k * a) ^ 4 + (k * b) ^ 4 : by ring
... = (k ^ 2 * c) ^ 2 : by rw f42.2.2
... = k ^ 4 * c ^ 2 : by ring }}
end
lemma ne_zero {a b c : ℤ} (h : fermat_42 a b c) : c ≠ 0 :=
begin
apply ne_zero_pow (dec_trivial : 2 ≠ 0), apply ne_of_gt,
rw [← h.2.2, (by ring : a ^ 4 + b ^ 4 = (a ^ 2) ^ 2 + (b ^ 2) ^ 2)],
exact add_pos (sq_pos_of_ne_zero _ (pow_ne_zero 2 h.1))
(sq_pos_of_ne_zero _ (pow_ne_zero 2 h.2.1))
end
/-- We say a solution to `a ^ 4 + b ^ 4 = c ^ 2` is minimal if there is no other solution with
a smaller `c` (in absolute value). -/
def minimal (a b c : ℤ) : Prop :=
(fermat_42 a b c) ∧ ∀ (a1 b1 c1 : ℤ), (fermat_42 a1 b1 c1) → int.nat_abs c ≤ int.nat_abs c1
/-- if we have a solution to `a ^ 4 + b ^ 4 = c ^ 2` then there must be a minimal one. -/
lemma exists_minimal {a b c : ℤ} (h : fermat_42 a b c) :
∃ (a0 b0 c0), (minimal a0 b0 c0) :=
begin
let S : set ℕ := { n | ∃ (s : ℤ × ℤ × ℤ), fermat_42 s.1 s.2.1 s.2.2 ∧ n = int.nat_abs s.2.2},
have S_nonempty : S.nonempty,
{ use int.nat_abs c,
rw set.mem_set_of_eq,
use ⟨a, ⟨b, c⟩⟩, tauto },
let m : ℕ := nat.find S_nonempty,
have m_mem : m ∈ S := nat.find_spec S_nonempty,
rcases m_mem with ⟨s0, hs0, hs1⟩,
use [s0.1, s0.2.1, s0.2.2, hs0],
intros a1 b1 c1 h1,
rw ← hs1,
apply nat.find_min',
use ⟨a1, ⟨b1, c1⟩⟩, tauto
end
/-- a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2` must have `a` and `b` coprime. -/
lemma coprime_of_minimal {a b c : ℤ} (h : minimal a b c) : is_coprime a b :=
begin
apply int.gcd_eq_one_iff_coprime.mp,
by_contradiction hab,
obtain ⟨p, hp, hpa, hpb⟩ := nat.prime.not_coprime_iff_dvd.mp hab,
obtain ⟨a1, rfl⟩ := (int.coe_nat_dvd_left.mpr hpa),
obtain ⟨b1, rfl⟩ := (int.coe_nat_dvd_left.mpr hpb),
have hpc : (p : ℤ) ^ 2 ∣ c,
{ apply (int.pow_dvd_pow_iff (dec_trivial : 0 < 2)).mp,
rw ← h.1.2.2,
apply dvd.intro (a1 ^ 4 + b1 ^ 4), ring },
obtain ⟨c1, rfl⟩ := hpc,
have hf : fermat_42 a1 b1 c1,
exact (fermat_42.mul (int.coe_nat_ne_zero.mpr (nat.prime.ne_zero hp))).mpr h.1,
apply nat.le_lt_antisymm (h.2 _ _ _ hf),
rw [int.nat_abs_mul, lt_mul_iff_one_lt_left, int.nat_abs_pow, int.nat_abs_of_nat],
{ exact nat.one_lt_pow _ _ (show 0 < 2, from dec_trivial) (nat.prime.one_lt hp) },
{ exact (nat.pos_of_ne_zero (int.nat_abs_ne_zero_of_ne_zero (ne_zero hf))) },
end
/-- We can swap `a` and `b` in a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2`. -/
lemma minimal_comm {a b c : ℤ} : (minimal a b c) → (minimal b a c) :=
λ ⟨h1, h2⟩, ⟨fermat_42.comm.mp h1, h2⟩
/-- We can assume that a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2` has positive `c`. -/
lemma neg_of_minimal {a b c : ℤ} :
(minimal a b c) → (minimal a b (-c)) :=
begin
rintros ⟨⟨ha, hb, heq⟩, h2⟩,
split,
{ apply and.intro ha (and.intro hb _),
rw heq, exact (neg_sq c).symm },
rwa (int.nat_abs_neg c),
end
/-- We can assume that a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2` has `a` odd. -/
lemma exists_odd_minimal {a b c : ℤ} (h : fermat_42 a b c) :
∃ (a0 b0 c0), (minimal a0 b0 c0) ∧ a0 % 2 = 1 :=
begin
obtain ⟨a0, b0, c0, hf⟩ := exists_minimal h,
cases int.mod_two_eq_zero_or_one a0 with hap hap,
{ cases int.mod_two_eq_zero_or_one b0 with hbp hbp,
{ exfalso,
have h1 : 2 ∣ (int.gcd a0 b0 : ℤ),
{ exact int.dvd_gcd (int.dvd_of_mod_eq_zero hap) (int.dvd_of_mod_eq_zero hbp) },
rw int.gcd_eq_one_iff_coprime.mpr (coprime_of_minimal hf) at h1, revert h1, norm_num },
{ exact ⟨b0, ⟨a0, ⟨c0, minimal_comm hf, hbp⟩⟩⟩ }},
exact ⟨a0, ⟨b0, ⟨c0 , hf, hap⟩⟩⟩,
end
/-- We can assume that a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2` has
`a` odd and `c` positive. -/
lemma exists_pos_odd_minimal {a b c : ℤ} (h : fermat_42 a b c) :
∃ (a0 b0 c0), (minimal a0 b0 c0) ∧ a0 % 2 = 1 ∧ 0 < c0 :=
begin
obtain ⟨a0, b0, c0, hf, hc⟩ := exists_odd_minimal h,
rcases lt_trichotomy 0 c0 with (h1 | rfl | h1),
{ use [a0, b0, c0], tauto },
{ exfalso, exact ne_zero hf.1 rfl},
{ use [a0, b0, -c0, neg_of_minimal hf, hc],
exact neg_pos.mpr h1 },
end
end fermat_42
lemma int.coprime_of_sq_sum {r s : ℤ} (h2 : is_coprime s r) :
is_coprime (r ^ 2 + s ^ 2) r :=
begin
rw [sq, sq],
exact (is_coprime.mul_left h2 h2).mul_add_left_left r
end
lemma int.coprime_of_sq_sum' {r s : ℤ} (h : is_coprime r s) :
is_coprime (r ^ 2 + s ^ 2) (r * s) :=
begin
apply is_coprime.mul_right (int.coprime_of_sq_sum (is_coprime_comm.mp h)),
rw add_comm, apply int.coprime_of_sq_sum h
end
namespace fermat_42
-- If we have a solution to a ^ 4 + b ^ 4 = c ^ 2, we can construct a smaller one. This
-- implies there can't be a smallest solution.
lemma not_minimal {a b c : ℤ}
(h : minimal a b c) (ha2 : a % 2 = 1) (hc : 0 < c) : false :=
begin
-- Use the fact that a ^ 2, b ^ 2, c form a pythagorean triple to obtain m and n such that
-- a ^ 2 = m ^ 2 - n ^ 2, b ^ 2 = 2 * m * n and c = m ^ 2 + n ^ 2
-- first the formula:
have ht : pythagorean_triple (a ^ 2) (b ^ 2) c,
{ calc ((a ^ 2) * (a ^ 2)) + ((b ^ 2) * (b ^ 2))
= a ^ 4 + b ^ 4 : by ring
... = c ^ 2 : by rw h.1.2.2
... = c * c : by rw sq },
-- coprime requirement:
have h2 : int.gcd (a ^ 2) (b ^ 2) = 1 :=
int.gcd_eq_one_iff_coprime.mpr (coprime_of_minimal h).pow,
-- in order to reduce the possibilities we get from the classification of pythagorean triples
-- it helps if we know the parity of a ^ 2 (and the sign of c):
have ha22 : a ^ 2 % 2 = 1, { rw [sq, int.mul_mod, ha2], norm_num },
obtain ⟨m, n, ht1, ht2, ht3, ht4, ht5, ht6⟩ :=
pythagorean_triple.coprime_classification' ht h2 ha22 hc,
-- Now a, n, m form a pythagorean triple and so we can obtain r and s such that
-- a = r ^ 2 - s ^ 2, n = 2 * r * s and m = r ^ 2 + s ^ 2
-- formula:
have htt : pythagorean_triple a n m,
{ delta pythagorean_triple,
rw [← sq, ← sq, ← sq], exact (add_eq_of_eq_sub ht1) },
-- a and n are coprime, because a ^ 2 = m ^ 2 - n ^ 2 and m and n are coprime.
have h3 : int.gcd a n = 1,
{ apply int.gcd_eq_one_iff_coprime.mpr,
apply @is_coprime.of_mul_left_left _ _ _ a,
rw [← sq, ht1, (by ring : m ^ 2 - n ^ 2 = m ^ 2 + (-n) * n)],
exact (int.gcd_eq_one_iff_coprime.mp ht4).pow_left.add_mul_right_left (-n) },
-- m is positive because b is non-zero and b ^ 2 = 2 * m * n and we already have 0 ≤ m.
have hb20 : b ^ 2 ≠ 0 := mt pow_eq_zero h.1.2.1,
have h4 : 0 < m,
{ apply lt_of_le_of_ne ht6,
rintro rfl,
revert hb20,
rw ht2, simp },
obtain ⟨r, s, htt1, htt2, htt3, htt4, htt5, htt6⟩ :=
pythagorean_triple.coprime_classification' htt h3 ha2 h4,
-- Now use the fact that (b / 2) ^ 2 = m * r * s, and m, r and s are pairwise coprime to obtain
-- i, j and k such that m = i ^ 2, r = j ^ 2 and s = k ^ 2.
-- m and r * s are coprime because m = r ^ 2 + s ^ 2 and r and s are coprime.
have hcp : int.gcd m (r * s) = 1,
{ rw htt3,
exact int.gcd_eq_one_iff_coprime.mpr (int.coprime_of_sq_sum'
(int.gcd_eq_one_iff_coprime.mp htt4)) },
-- b is even because b ^ 2 = 2 * m * n.
have hb2 : 2 ∣ b,
{ apply @int.prime.dvd_pow' _ 2 _ (by norm_num : nat.prime 2),
rw [ht2, mul_assoc], exact dvd_mul_right 2 (m * n) },
cases hb2 with b' hb2',
have hs : b' ^ 2 = m * (r * s),
{ apply (mul_right_inj' (by norm_num : (4 : ℤ) ≠ 0)).mp,
calc 4 * b' ^ 2 = (2 * b') * (2 * b') : by ring
... = 2 * m * (2 * r * s) : by rw [← hb2', ← sq, ht2, htt2]
... = 4 * (m * (r * s)) : by ring },
have hrsz : r * s ≠ 0, -- because b ^ 2 is not zero and (b / 2) ^ 2 = m * (r * s)
{ by_contradiction hrsz,
revert hb20, rw [ht2, htt2, mul_assoc, @mul_assoc _ _ _ r s, (not_not.mp hrsz)],
simp },
have h2b0 : b' ≠ 0,
{ apply ne_zero_pow (dec_trivial : 2 ≠ 0),
rw hs, apply mul_ne_zero, { exact ne_of_gt h4}, { exact hrsz } },
obtain ⟨i, hi⟩ := int.sq_of_gcd_eq_one hcp hs.symm,
-- use m is positive to exclude m = - i ^ 2
have hi' : ¬ m = - i ^ 2,
{ by_contradiction h1,
have hit : - i ^ 2 ≤ 0, apply neg_nonpos.mpr (sq_nonneg i),
rw ← h1 at hit,
apply absurd h4 (not_lt.mpr hit) },
replace hi : m = i ^ 2, { apply or.resolve_right hi hi' },
rw mul_comm at hs,
rw [int.gcd_comm] at hcp,
-- obtain d such that r * s = d ^ 2
obtain ⟨d, hd⟩ := int.sq_of_gcd_eq_one hcp hs.symm,
-- (b / 2) ^ 2 and m are positive so r * s is positive
have hd' : ¬ r * s = - d ^ 2,
{ by_contradiction h1,
rw h1 at hs,
have h2 : b' ^ 2 ≤ 0,
{ rw [hs, (by ring : - d ^ 2 * m = - (d ^ 2 * m))], apply neg_nonpos.mpr,
apply (zero_le_mul_right h4).mpr (sq_nonneg d) },
have h2' : 0 ≤ b' ^ 2, { apply sq_nonneg b' },
exact absurd (lt_of_le_of_ne h2' (ne.symm (pow_ne_zero _ h2b0))) (not_lt.mpr h2) },
replace hd : r * s = d ^ 2, { apply or.resolve_right hd hd' },
-- r = +/- j ^ 2
obtain ⟨j, hj⟩ := int.sq_of_gcd_eq_one htt4 hd,
have hj0 : j ≠ 0,
{ intro h0, rw [h0, zero_pow (dec_trivial : 0 < 2), neg_zero, or_self] at hj,
apply left_ne_zero_of_mul hrsz hj },
rw mul_comm at hd,
rw [int.gcd_comm] at htt4,
-- s = +/- k ^ 2
obtain ⟨k, hk⟩ := int.sq_of_gcd_eq_one htt4 hd,
have hk0 : k ≠ 0,
{ intro h0, rw [h0, zero_pow (dec_trivial : 0 < 2), neg_zero, or_self] at hk,
apply right_ne_zero_of_mul hrsz hk },
have hj2 : r ^ 2 = j ^ 4, { cases hj with hjp hjp; { rw hjp, ring } },
have hk2 : s ^ 2 = k ^ 4, { cases hk with hkp hkp; { rw hkp, ring } },
-- from m = r ^ 2 + s ^ 2 we now get a new solution to a ^ 4 + b ^ 4 = c ^ 2:
have hh : i ^ 2 = j ^ 4 + k ^ 4, { rw [← hi, htt3, hj2, hk2] },
have hn : n ≠ 0, { rw ht2 at hb20, apply right_ne_zero_of_mul hb20 },
-- and it has a smaller c: from c = m ^ 2 + n ^ 2 we see that m is smaller than c, and i ^ 2 = m.
have hic : int.nat_abs i < int.nat_abs c,
{ apply int.coe_nat_lt.mp, rw ← (int.eq_nat_abs_of_zero_le (le_of_lt hc)),
apply gt_of_gt_of_ge _ (int.abs_le_self_sq i),
rw [← hi, ht3],
apply gt_of_gt_of_ge _ (int.le_self_sq m),
exact lt_add_of_pos_right (m ^ 2) (sq_pos_of_ne_zero n hn) },
have hic' : int.nat_abs c ≤ int.nat_abs i,
{ apply (h.2 j k i),
exact ⟨hj0, hk0, hh.symm⟩ },
apply absurd (not_le_of_lt hic) (not_not.mpr hic')
end
end fermat_42
lemma not_fermat_42 {a b c : ℤ} (ha : a ≠ 0) (hb : b ≠ 0) :
a ^ 4 + b ^ 4 ≠ c ^ 2 :=
begin
intro h,
obtain ⟨a0, b0, c0, ⟨hf, h2, hp⟩⟩ :=
fermat_42.exists_pos_odd_minimal (and.intro ha (and.intro hb h)),
apply fermat_42.not_minimal hf h2 hp
end
theorem not_fermat_4 {a b c : ℤ} (ha : a ≠ 0) (hb : b ≠ 0) :
a ^ 4 + b ^ 4 ≠ c ^ 4 :=
begin
intro heq,
apply @not_fermat_42 _ _ (c ^ 2) ha hb,
rw heq, ring
end
|
12879cefce1d6494b10a2ad882f991b822db9033 | bb31430994044506fa42fd667e2d556327e18dfe | /src/logic/equiv/basic.lean | 6628c06c978caaf803a8f0945921789ac607db39 | [
"Apache-2.0"
] | permissive | sgouezel/mathlib | 0cb4e5335a2ba189fa7af96d83a377f83270e503 | 00638177efd1b2534fc5269363ebf42a7871df9a | refs/heads/master | 1,674,527,483,042 | 1,673,665,568,000 | 1,673,665,568,000 | 119,598,202 | 0 | 0 | null | 1,517,348,647,000 | 1,517,348,646,000 | null | UTF-8 | Lean | false | false | 62,390 | lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Mario Carneiro
-/
import logic.equiv.defs
import data.option.basic
import data.prod.basic
import data.sigma.basic
import data.subtype
import data.sum.basic
import logic.function.conjugate
/-!
# Equivalence between types
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In this file we continue the work on equivalences begun in `logic/equiv/defs.lean`, defining
* canonical isomorphisms between various types: e.g.,
- `equiv.sum_equiv_sigma_bool` is the canonical equivalence between the sum of two types `α ⊕ β`
and the sigma-type `Σ b : bool, cond b α β`;
- `equiv.prod_sum_distrib : α × (β ⊕ γ) ≃ (α × β) ⊕ (α × γ)` shows that type product and type sum
satisfy the distributive law up to a canonical equivalence;
* operations on equivalences: e.g.,
- `equiv.prod_congr ea eb : α₁ × β₁ ≃ α₂ × β₂`: combine two equivalences `ea : α₁ ≃ α₂` and
`eb : β₁ ≃ β₂` using `prod.map`.
More definitions of this kind can be found in other files. E.g., `data/equiv/transfer_instance`
does it for many algebraic type classes like `group`, `module`, etc.
## Tags
equivalence, congruence, bijective map
-/
open function
universes u v w z
variables {α : Sort u} {β : Sort v} {γ : Sort w}
namespace equiv
/-- `pprod α β` is equivalent to `α × β` -/
@[simps apply symm_apply]
def pprod_equiv_prod {α β : Type*} : pprod α β ≃ α × β :=
{ to_fun := λ x, (x.1, x.2),
inv_fun := λ x, ⟨x.1, x.2⟩,
left_inv := λ ⟨x, y⟩, rfl,
right_inv := λ ⟨x, y⟩, rfl }
/-- Product of two equivalences, in terms of `pprod`. If `α ≃ β` and `γ ≃ δ`, then
`pprod α γ ≃ pprod β δ`. -/
@[congr, simps apply]
def pprod_congr {δ : Sort z} (e₁ : α ≃ β) (e₂ : γ ≃ δ) : pprod α γ ≃ pprod β δ :=
{ to_fun := λ x, ⟨e₁ x.1, e₂ x.2⟩,
inv_fun := λ x, ⟨e₁.symm x.1, e₂.symm x.2⟩,
left_inv := λ ⟨x, y⟩, by simp,
right_inv := λ ⟨x, y⟩, by simp }
/-- Combine two equivalences using `pprod` in the domain and `prod` in the codomain. -/
@[simps apply symm_apply]
def pprod_prod {α₁ β₁ : Sort*} {α₂ β₂ : Type*} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) :
pprod α₁ β₁ ≃ α₂ × β₂ :=
(ea.pprod_congr eb).trans pprod_equiv_prod
/-- Combine two equivalences using `pprod` in the codomain and `prod` in the domain. -/
@[simps apply symm_apply]
def prod_pprod {α₁ β₁ : Type*} {α₂ β₂ : Sort*} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) :
α₁ × β₁ ≃ pprod α₂ β₂ :=
(ea.symm.pprod_prod eb.symm).symm
/-- `pprod α β` is equivalent to `plift α × plift β` -/
@[simps apply symm_apply]
def pprod_equiv_prod_plift {α β : Sort*} : pprod α β ≃ plift α × plift β :=
equiv.plift.symm.pprod_prod equiv.plift.symm
/-- Product of two equivalences. If `α₁ ≃ α₂` and `β₁ ≃ β₂`, then `α₁ × β₁ ≃ α₂ × β₂`. This is
`prod.map` as an equivalence. -/
@[congr, simps apply]
def prod_congr {α₁ β₁ α₂ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : α₁ × β₁ ≃ α₂ × β₂ :=
⟨prod.map e₁ e₂, prod.map e₁.symm e₂.symm, λ ⟨a, b⟩, by simp, λ ⟨a, b⟩, by simp⟩
@[simp] theorem prod_congr_symm {α₁ β₁ α₂ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) :
(prod_congr e₁ e₂).symm = prod_congr e₁.symm e₂.symm :=
rfl
/-- Type product is commutative up to an equivalence: `α × β ≃ β × α`. This is `prod.swap` as an
equivalence.-/
def prod_comm (α β : Type*) : α × β ≃ β × α :=
⟨prod.swap, prod.swap, prod.swap_swap, prod.swap_swap⟩
@[simp] lemma coe_prod_comm (α β : Type*) : ⇑(prod_comm α β) = prod.swap := rfl
@[simp] lemma prod_comm_apply {α β : Type*} (x : α × β) : prod_comm α β x = x.swap := rfl
@[simp] lemma prod_comm_symm (α β) : (prod_comm α β).symm = prod_comm β α := rfl
/-- Type product is associative up to an equivalence. -/
@[simps] def prod_assoc (α β γ : Sort*) : (α × β) × γ ≃ α × (β × γ) :=
⟨λ p, (p.1.1, p.1.2, p.2), λ p, ((p.1, p.2.1), p.2.2), λ ⟨⟨a, b⟩, c⟩, rfl, λ ⟨a, ⟨b, c⟩⟩, rfl⟩
/-- Functions on `α × β` are equivalent to functions `α → β → γ`. -/
@[simps {fully_applied := ff}] def curry (α β γ : Type*) :
(α × β → γ) ≃ (α → β → γ) :=
{ to_fun := curry,
inv_fun := uncurry,
left_inv := uncurry_curry,
right_inv := curry_uncurry }
section
/-- `punit` is a right identity for type product up to an equivalence. -/
@[simps] def prod_punit (α : Type*) : α × punit.{u+1} ≃ α :=
⟨λ p, p.1, λ a, (a, punit.star), λ ⟨_, punit.star⟩, rfl, λ a, rfl⟩
/-- `punit` is a left identity for type product up to an equivalence. -/
@[simps] def punit_prod (α : Type*) : punit.{u+1} × α ≃ α :=
calc punit × α ≃ α × punit : prod_comm _ _
... ≃ α : prod_punit _
/-- Any `unique` type is a right identity for type product up to equivalence. -/
def prod_unique (α β : Type*) [unique β] : α × β ≃ α :=
((equiv.refl α).prod_congr $ equiv_punit β).trans $ prod_punit α
@[simp] lemma coe_prod_unique {α β : Type*} [unique β] :
⇑(prod_unique α β) = prod.fst := rfl
lemma prod_unique_apply {α β : Type*} [unique β] (x : α × β) :
prod_unique α β x = x.1 := rfl
@[simp] lemma prod_unique_symm_apply {α β : Type*} [unique β] (x : α) :
(prod_unique α β).symm x = (x, default) := rfl
/-- Any `unique` type is a left identity for type product up to equivalence. -/
def unique_prod (α β : Type*) [unique β] : β × α ≃ α :=
((equiv_punit β).prod_congr $ equiv.refl α).trans $ punit_prod α
@[simp] lemma coe_unique_prod {α β : Type*} [unique β] :
⇑(unique_prod α β) = prod.snd := rfl
lemma unique_prod_apply {α β : Type*} [unique β] (x : β × α) :
unique_prod α β x = x.2 := rfl
@[simp] lemma unique_prod_symm_apply {α β : Type*} [unique β] (x : α) :
(unique_prod α β).symm x = (default, x) := rfl
/-- `empty` type is a right absorbing element for type product up to an equivalence. -/
def prod_empty (α : Type*) : α × empty ≃ empty :=
equiv_empty _
/-- `empty` type is a left absorbing element for type product up to an equivalence. -/
def empty_prod (α : Type*) : empty × α ≃ empty :=
equiv_empty _
/-- `pempty` type is a right absorbing element for type product up to an equivalence. -/
def prod_pempty (α : Type*) : α × pempty ≃ pempty :=
equiv_pempty _
/-- `pempty` type is a left absorbing element for type product up to an equivalence. -/
def pempty_prod (α : Type*) : pempty × α ≃ pempty :=
equiv_pempty _
end
section
open sum
/-- `psum` is equivalent to `sum`. -/
def psum_equiv_sum (α β : Type*) : psum α β ≃ α ⊕ β :=
{ to_fun := λ s, psum.cases_on s inl inr,
inv_fun := sum.elim psum.inl psum.inr,
left_inv := λ s, by cases s; refl,
right_inv := λ s, by cases s; refl }
/-- If `α ≃ α'` and `β ≃ β'`, then `α ⊕ β ≃ α' ⊕ β'`. This is `sum.map` as an equivalence. -/
@[simps apply]
def sum_congr {α₁ β₁ α₂ β₂ : Type*} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : α₁ ⊕ β₁ ≃ α₂ ⊕ β₂ :=
⟨sum.map ea eb, sum.map ea.symm eb.symm, λ x, by simp, λ x, by simp⟩
/-- If `α ≃ α'` and `β ≃ β'`, then `psum α β ≃ psum α' β'`. -/
def psum_congr {δ : Sort z} (e₁ : α ≃ β) (e₂ : γ ≃ δ) : psum α γ ≃ psum β δ :=
{ to_fun := λ x, psum.cases_on x (psum.inl ∘ e₁) (psum.inr ∘ e₂),
inv_fun := λ x, psum.cases_on x (psum.inl ∘ e₁.symm) (psum.inr ∘ e₂.symm),
left_inv := by rintro (x|x); simp,
right_inv := by rintro (x|x); simp }
/-- Combine two `equiv`s using `psum` in the domain and `sum` in the codomain. -/
def psum_sum {α₁ β₁ : Sort*} {α₂ β₂ : Type*} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : psum α₁ β₁ ≃ α₂ ⊕ β₂ :=
(ea.psum_congr eb).trans (psum_equiv_sum _ _)
/-- Combine two `equiv`s using `sum` in the domain and `psum` in the codomain. -/
def sum_psum {α₁ β₁ : Type*} {α₂ β₂ : Sort*} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : α₁ ⊕ β₁ ≃ psum α₂ β₂ :=
(ea.symm.psum_sum eb.symm).symm
@[simp] lemma sum_congr_trans {α₁ α₂ β₁ β₂ γ₁ γ₂ : Sort*}
(e : α₁ ≃ β₁) (f : α₂ ≃ β₂) (g : β₁ ≃ γ₁) (h : β₂ ≃ γ₂) :
(equiv.sum_congr e f).trans (equiv.sum_congr g h) = (equiv.sum_congr (e.trans g) (f.trans h)) :=
by { ext i, cases i; refl }
@[simp] lemma sum_congr_symm {α β γ δ : Sort*} (e : α ≃ β) (f : γ ≃ δ) :
(equiv.sum_congr e f).symm = (equiv.sum_congr (e.symm) (f.symm)) :=
rfl
@[simp] lemma sum_congr_refl {α β : Sort*} :
equiv.sum_congr (equiv.refl α) (equiv.refl β) = equiv.refl (α ⊕ β) :=
by { ext i, cases i; refl }
namespace perm
/-- Combine a permutation of `α` and of `β` into a permutation of `α ⊕ β`. -/
@[reducible]
def sum_congr {α β : Type*} (ea : equiv.perm α) (eb : equiv.perm β) : equiv.perm (α ⊕ β) :=
equiv.sum_congr ea eb
@[simp] lemma sum_congr_apply {α β : Type*} (ea : equiv.perm α) (eb : equiv.perm β) (x : α ⊕ β) :
sum_congr ea eb x = sum.map ⇑ea ⇑eb x := equiv.sum_congr_apply ea eb x
@[simp] lemma sum_congr_trans {α β : Sort*}
(e : equiv.perm α) (f : equiv.perm β) (g : equiv.perm α) (h : equiv.perm β) :
(sum_congr e f).trans (sum_congr g h) = sum_congr (e.trans g) (f.trans h) :=
equiv.sum_congr_trans e f g h
@[simp] lemma sum_congr_symm {α β : Sort*} (e : equiv.perm α) (f : equiv.perm β) :
(sum_congr e f).symm = sum_congr (e.symm) (f.symm) :=
equiv.sum_congr_symm e f
@[simp] lemma sum_congr_refl {α β : Sort*} :
sum_congr (equiv.refl α) (equiv.refl β) = equiv.refl (α ⊕ β) :=
equiv.sum_congr_refl
end perm
/-- `bool` is equivalent the sum of two `punit`s. -/
def bool_equiv_punit_sum_punit : bool ≃ punit.{u+1} ⊕ punit.{v+1} :=
⟨λ b, cond b (inr punit.star) (inl punit.star),
sum.elim (λ _, ff) (λ _, tt),
λ b, by cases b; refl,
λ s, by rcases s with ⟨⟨⟩⟩ | ⟨⟨⟩⟩; refl⟩
/-- Sum of types is commutative up to an equivalence. This is `sum.swap` as an equivalence. -/
@[simps apply {fully_applied := ff}]
def sum_comm (α β : Type*) : α ⊕ β ≃ β ⊕ α :=
⟨sum.swap, sum.swap, sum.swap_swap, sum.swap_swap⟩
@[simp] lemma sum_comm_symm (α β) : (sum_comm α β).symm = sum_comm β α := rfl
/-- Sum of types is associative up to an equivalence. -/
def sum_assoc (α β γ : Type*) : (α ⊕ β) ⊕ γ ≃ α ⊕ (β ⊕ γ) :=
⟨sum.elim (sum.elim sum.inl (sum.inr ∘ sum.inl)) (sum.inr ∘ sum.inr),
sum.elim (sum.inl ∘ sum.inl) $ sum.elim (sum.inl ∘ sum.inr) sum.inr,
by rintros (⟨_ | _⟩ | _); refl,
by rintros (_ | ⟨_ | _⟩); refl⟩
@[simp] lemma sum_assoc_apply_inl_inl {α β γ} (a) : sum_assoc α β γ (inl (inl a)) = inl a := rfl
@[simp] lemma sum_assoc_apply_inl_inr {α β γ} (b) : sum_assoc α β γ (inl (inr b)) = inr (inl b) :=
rfl
@[simp] lemma sum_assoc_apply_inr {α β γ} (c) : sum_assoc α β γ (inr c) = inr (inr c) := rfl
@[simp] lemma sum_assoc_symm_apply_inl {α β γ} (a) : (sum_assoc α β γ).symm (inl a) = inl (inl a) :=
rfl
@[simp] lemma sum_assoc_symm_apply_inr_inl {α β γ} (b) :
(sum_assoc α β γ).symm (inr (inl b)) = inl (inr b) := rfl
@[simp] lemma sum_assoc_symm_apply_inr_inr {α β γ} (c) :
(sum_assoc α β γ).symm (inr (inr c)) = inr c := rfl
/-- Sum with `empty` is equivalent to the original type. -/
@[simps symm_apply] def sum_empty (α β : Type*) [is_empty β] : α ⊕ β ≃ α :=
⟨sum.elim id is_empty_elim,
inl,
λ s, by { rcases s with _ | x, refl, exact is_empty_elim x },
λ a, rfl⟩
@[simp] lemma sum_empty_apply_inl {α β : Type*} [is_empty β] (a : α) :
sum_empty α β (sum.inl a) = a := rfl
/-- The sum of `empty` with any `Sort*` is equivalent to the right summand. -/
@[simps symm_apply] def empty_sum (α β : Type*) [is_empty α] : α ⊕ β ≃ β :=
(sum_comm _ _).trans $ sum_empty _ _
@[simp] lemma empty_sum_apply_inr {α β : Type*} [is_empty α] (b : β) :
empty_sum α β (sum.inr b) = b := rfl
/-- `option α` is equivalent to `α ⊕ punit` -/
def option_equiv_sum_punit (α : Type*) : option α ≃ α ⊕ punit.{u+1} :=
⟨λ o, o.elim (inr punit.star) inl,
λ s, s.elim some (λ _, none),
λ o, by cases o; refl,
λ s, by rcases s with _ | ⟨⟨⟩⟩; refl⟩
@[simp] lemma option_equiv_sum_punit_none {α} :
option_equiv_sum_punit α none = sum.inr punit.star := rfl
@[simp] lemma option_equiv_sum_punit_some {α} (a) :
option_equiv_sum_punit α (some a) = sum.inl a := rfl
@[simp] lemma option_equiv_sum_punit_coe {α} (a : α) :
option_equiv_sum_punit α a = sum.inl a := rfl
@[simp] lemma option_equiv_sum_punit_symm_inl {α} (a) :
(option_equiv_sum_punit α).symm (sum.inl a) = a :=
rfl
@[simp] lemma option_equiv_sum_punit_symm_inr {α} (a) :
(option_equiv_sum_punit α).symm (sum.inr a) = none :=
rfl
/-- The set of `x : option α` such that `is_some x` is equivalent to `α`. -/
@[simps] def option_is_some_equiv (α : Type*) : {x : option α // x.is_some} ≃ α :=
{ to_fun := λ o, option.get o.2,
inv_fun := λ x, ⟨some x, dec_trivial⟩,
left_inv := λ o, subtype.eq $ option.some_get _,
right_inv := λ x, option.get_some _ _ }
/-- The product over `option α` of `β a` is the binary product of the
product over `α` of `β (some α)` and `β none` -/
@[simps] def pi_option_equiv_prod {α : Type*} {β : option α → Type*} :
(Π a : option α, β a) ≃ (β none × Π a : α, β (some a)) :=
{ to_fun := λ f, (f none, λ a, f (some a)),
inv_fun := λ x a, option.cases_on a x.fst x.snd,
left_inv := λ f, funext $ λ a, by cases a; refl,
right_inv := λ x, by simp }
/-- `α ⊕ β` is equivalent to a `sigma`-type over `bool`. Note that this definition assumes `α` and
`β` to be types from the same universe, so it cannot by used directly to transfer theorems about
sigma types to theorems about sum types. In many cases one can use `ulift` to work around this
difficulty. -/
def sum_equiv_sigma_bool (α β : Type u) : α ⊕ β ≃ (Σ b: bool, cond b α β) :=
⟨λ s, s.elim (λ x, ⟨tt, x⟩) (λ x, ⟨ff, x⟩),
λ s, match s with ⟨tt, a⟩ := inl a | ⟨ff, b⟩ := inr b end,
λ s, by cases s; refl,
λ s, by rcases s with ⟨_|_, _⟩; refl⟩
/-- `sigma_fiber_equiv f` for `f : α → β` is the natural equivalence between
the type of all fibres of `f` and the total space `α`. -/
-- See also `equiv.sigma_preimage_equiv`.
@[simps]
def sigma_fiber_equiv {α β : Type*} (f : α → β) :
(Σ y : β, {x // f x = y}) ≃ α :=
⟨λ x, ↑x.2, λ x, ⟨f x, x, rfl⟩, λ ⟨y, x, rfl⟩, rfl, λ x, rfl⟩
end
section sum_compl
/-- For any predicate `p` on `α`,
the sum of the two subtypes `{a // p a}` and its complement `{a // ¬ p a}`
is naturally equivalent to `α`.
See `subtype_or_equiv` for sum types over subtypes `{x // p x}` and `{x // q x}`
that are not necessarily `is_compl p q`. -/
def sum_compl {α : Type*} (p : α → Prop) [decidable_pred p] :
{a // p a} ⊕ {a // ¬ p a} ≃ α :=
{ to_fun := sum.elim coe coe,
inv_fun := λ a, if h : p a then sum.inl ⟨a, h⟩ else sum.inr ⟨a, h⟩,
left_inv := by { rintros (⟨x,hx⟩|⟨x,hx⟩); dsimp; [rw dif_pos, rw dif_neg], },
right_inv := λ a, by { dsimp, split_ifs; refl } }
@[simp] lemma sum_compl_apply_inl {α : Type*} (p : α → Prop) [decidable_pred p]
(x : {a // p a}) :
sum_compl p (sum.inl x) = x := rfl
@[simp] lemma sum_compl_apply_inr {α : Type*} (p : α → Prop) [decidable_pred p]
(x : {a // ¬ p a}) :
sum_compl p (sum.inr x) = x := rfl
@[simp] lemma sum_compl_apply_symm_of_pos {α : Type*} (p : α → Prop) [decidable_pred p]
(a : α) (h : p a) :
(sum_compl p).symm a = sum.inl ⟨a, h⟩ := dif_pos h
@[simp] lemma sum_compl_apply_symm_of_neg {α : Type*} (p : α → Prop) [decidable_pred p]
(a : α) (h : ¬ p a) :
(sum_compl p).symm a = sum.inr ⟨a, h⟩ := dif_neg h
/-- Combines an `equiv` between two subtypes with an `equiv` between their complements to form a
permutation. -/
def subtype_congr {α : Type*} {p q : α → Prop} [decidable_pred p] [decidable_pred q]
(e : {x // p x} ≃ {x // q x}) (f : {x // ¬p x} ≃ {x // ¬q x}) : perm α :=
(sum_compl p).symm.trans ((sum_congr e f).trans
(sum_compl q))
open equiv
variables {ε : Type*} {p : ε → Prop} [decidable_pred p]
variables (ep ep' : perm {a // p a}) (en en' : perm {a // ¬ p a})
/-- Combining permutations on `ε` that permute only inside or outside the subtype
split induced by `p : ε → Prop` constructs a permutation on `ε`. -/
def perm.subtype_congr : equiv.perm ε :=
perm_congr (sum_compl p) (sum_congr ep en)
lemma perm.subtype_congr.apply (a : ε) :
ep.subtype_congr en a = if h : p a then ep ⟨a, h⟩ else en ⟨a, h⟩ :=
by { by_cases h : p a; simp [perm.subtype_congr, h] }
@[simp] lemma perm.subtype_congr.left_apply {a : ε} (h : p a) :
ep.subtype_congr en a = ep ⟨a, h⟩ :=
by simp [perm.subtype_congr.apply, h]
@[simp] lemma perm.subtype_congr.left_apply_subtype (a : {a // p a}) :
ep.subtype_congr en a = ep a :=
by { convert perm.subtype_congr.left_apply _ _ a.property, simp }
@[simp] lemma perm.subtype_congr.right_apply {a : ε} (h : ¬ p a) :
ep.subtype_congr en a = en ⟨a, h⟩ :=
by simp [perm.subtype_congr.apply, h]
@[simp] lemma perm.subtype_congr.right_apply_subtype (a : {a // ¬ p a}) :
ep.subtype_congr en a = en a :=
by { convert perm.subtype_congr.right_apply _ _ a.property, simp }
@[simp] lemma perm.subtype_congr.refl :
perm.subtype_congr (equiv.refl {a // p a}) (equiv.refl {a // ¬ p a}) = equiv.refl ε :=
by { ext x, by_cases h : p x; simp [h] }
@[simp] lemma perm.subtype_congr.symm :
(ep.subtype_congr en).symm = perm.subtype_congr ep.symm en.symm :=
begin
ext x,
by_cases h : p x,
{ have : p (ep.symm ⟨x, h⟩) := subtype.property _,
simp [perm.subtype_congr.apply, h, symm_apply_eq, this] },
{ have : ¬ p (en.symm ⟨x, h⟩) := subtype.property (en.symm _),
simp [perm.subtype_congr.apply, h, symm_apply_eq, this] }
end
@[simp] lemma perm.subtype_congr.trans :
(ep.subtype_congr en).trans (ep'.subtype_congr en') =
perm.subtype_congr (ep.trans ep') (en.trans en') :=
begin
ext x,
by_cases h : p x,
{ have : p (ep ⟨x, h⟩) := subtype.property _,
simp [perm.subtype_congr.apply, h, this] },
{ have : ¬ p (en ⟨x, h⟩) := subtype.property (en _),
simp [perm.subtype_congr.apply, h, symm_apply_eq, this] }
end
end sum_compl
section subtype_preimage
variables (p : α → Prop) [decidable_pred p] (x₀ : {a // p a} → β)
/-- For a fixed function `x₀ : {a // p a} → β` defined on a subtype of `α`,
the subtype of functions `x : α → β` that agree with `x₀` on the subtype `{a // p a}`
is naturally equivalent to the type of functions `{a // ¬ p a} → β`. -/
@[simps]
def subtype_preimage :
{x : α → β // x ∘ coe = x₀} ≃ ({a // ¬ p a} → β) :=
{ to_fun := λ (x : {x : α → β // x ∘ coe = x₀}) a, (x : α → β) a,
inv_fun := λ x, ⟨λ a, if h : p a then x₀ ⟨a, h⟩ else x ⟨a, h⟩,
funext $ λ ⟨a, h⟩, dif_pos h⟩,
left_inv := λ ⟨x, hx⟩, subtype.val_injective $ funext $ λ a,
(by { dsimp, split_ifs; [ rw ← hx, skip ]; refl }),
right_inv := λ x, funext $ λ ⟨a, h⟩,
show dite (p a) _ _ = _, by { dsimp, rw [dif_neg h] } }
lemma subtype_preimage_symm_apply_coe_pos (x : {a // ¬ p a} → β) (a : α) (h : p a) :
((subtype_preimage p x₀).symm x : α → β) a = x₀ ⟨a, h⟩ :=
dif_pos h
lemma subtype_preimage_symm_apply_coe_neg (x : {a // ¬ p a} → β) (a : α) (h : ¬ p a) :
((subtype_preimage p x₀).symm x : α → β) a = x ⟨a, h⟩ :=
dif_neg h
end subtype_preimage
section
/-- A family of equivalences `Π a, β₁ a ≃ β₂ a` generates an equivalence between `Π a, β₁ a` and
`Π a, β₂ a`. -/
def Pi_congr_right {α} {β₁ β₂ : α → Sort*} (F : Π a, β₁ a ≃ β₂ a) : (Π a, β₁ a) ≃ (Π a, β₂ a) :=
⟨λ H a, F a (H a), λ H a, (F a).symm (H a),
λ H, funext $ by simp, λ H, funext $ by simp⟩
/-- Given `φ : α → β → Sort*`, we have an equivalence between `Π a b, φ a b` and `Π b a, φ a b`.
This is `function.swap` as an `equiv`. -/
@[simps apply]
def Pi_comm {α β} (φ : α → β → Sort*) : (Π a b, φ a b) ≃ (Π b a, φ a b) :=
⟨swap, swap, λ x, rfl, λ y, rfl⟩
@[simp] lemma Pi_comm_symm {α β} {φ : α → β → Sort*} :
(Pi_comm φ).symm = (Pi_comm $ swap φ) :=
rfl
/-- Dependent `curry` equivalence: the type of dependent functions on `Σ i, β i` is equivalent
to the type of dependent functions of two arguments (i.e., functions to the space of functions).
This is `sigma.curry` and `sigma.uncurry` together as an equiv. -/
def Pi_curry {α} {β : α → Sort*} (γ : Π a, β a → Sort*) :
(Π x : Σ i, β i, γ x.1 x.2) ≃ (Π a b, γ a b) :=
{ to_fun := sigma.curry,
inv_fun := sigma.uncurry,
left_inv := sigma.uncurry_curry,
right_inv := sigma.curry_uncurry }
end
section prod_congr
variables {α₁ β₁ β₂ : Type*} (e : α₁ → β₁ ≃ β₂)
/-- A family of equivalences `Π (a : α₁), β₁ ≃ β₂` generates an equivalence
between `β₁ × α₁` and `β₂ × α₁`. -/
def prod_congr_left : β₁ × α₁ ≃ β₂ × α₁ :=
{ to_fun := λ ab, ⟨e ab.2 ab.1, ab.2⟩,
inv_fun := λ ab, ⟨(e ab.2).symm ab.1, ab.2⟩,
left_inv := by { rintros ⟨a, b⟩, simp },
right_inv := by { rintros ⟨a, b⟩, simp } }
@[simp] lemma prod_congr_left_apply (b : β₁) (a : α₁) :
prod_congr_left e (b, a) = (e a b, a) := rfl
lemma prod_congr_refl_right (e : β₁ ≃ β₂) :
prod_congr e (equiv.refl α₁) = prod_congr_left (λ _, e) :=
by { ext ⟨a, b⟩ : 1, simp }
/-- A family of equivalences `Π (a : α₁), β₁ ≃ β₂` generates an equivalence
between `α₁ × β₁` and `α₁ × β₂`. -/
def prod_congr_right : α₁ × β₁ ≃ α₁ × β₂ :=
{ to_fun := λ ab, ⟨ab.1, e ab.1 ab.2⟩,
inv_fun := λ ab, ⟨ab.1, (e ab.1).symm ab.2⟩,
left_inv := by { rintros ⟨a, b⟩, simp },
right_inv := by { rintros ⟨a, b⟩, simp } }
@[simp] lemma prod_congr_right_apply (a : α₁) (b : β₁) :
prod_congr_right e (a, b) = (a, e a b) := rfl
lemma prod_congr_refl_left (e : β₁ ≃ β₂) :
prod_congr (equiv.refl α₁) e = prod_congr_right (λ _, e) :=
by { ext ⟨a, b⟩ : 1, simp }
@[simp] lemma prod_congr_left_trans_prod_comm :
(prod_congr_left e).trans (prod_comm _ _) = (prod_comm _ _).trans (prod_congr_right e) :=
by { ext ⟨a, b⟩ : 1, simp }
@[simp] lemma prod_congr_right_trans_prod_comm :
(prod_congr_right e).trans (prod_comm _ _) = (prod_comm _ _).trans (prod_congr_left e) :=
by { ext ⟨a, b⟩ : 1, simp }
lemma sigma_congr_right_sigma_equiv_prod :
(sigma_congr_right e).trans (sigma_equiv_prod α₁ β₂) =
(sigma_equiv_prod α₁ β₁).trans (prod_congr_right e) :=
by { ext ⟨a, b⟩ : 1, simp }
lemma sigma_equiv_prod_sigma_congr_right :
(sigma_equiv_prod α₁ β₁).symm.trans (sigma_congr_right e) =
(prod_congr_right e).trans (sigma_equiv_prod α₁ β₂).symm :=
by { ext ⟨a, b⟩ : 1, simp }
/-- A family of equivalences between fibers gives an equivalence between domains. -/
-- See also `equiv.of_preimage_equiv`.
@[simps]
def of_fiber_equiv {α β γ : Type*} {f : α → γ} {g : β → γ}
(e : Π c, {a // f a = c} ≃ {b // g b = c}) :
α ≃ β :=
(sigma_fiber_equiv f).symm.trans $ (equiv.sigma_congr_right e).trans (sigma_fiber_equiv g)
lemma of_fiber_equiv_map {α β γ} {f : α → γ} {g : β → γ}
(e : Π c, {a // f a = c} ≃ {b // g b = c}) (a : α) : g (of_fiber_equiv e a) = f a :=
(_ : {b // g b = _}).prop
/-- A variation on `equiv.prod_congr` where the equivalence in the second component can depend
on the first component. A typical example is a shear mapping, explaining the name of this
declaration. -/
@[simps {fully_applied := ff}]
def prod_shear {α₁ β₁ α₂ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : α₁ → β₁ ≃ β₂) : α₁ × β₁ ≃ α₂ × β₂ :=
{ to_fun := λ x : α₁ × β₁, (e₁ x.1, e₂ x.1 x.2),
inv_fun := λ y : α₂ × β₂, (e₁.symm y.1, (e₂ $ e₁.symm y.1).symm y.2),
left_inv := by { rintro ⟨x₁, y₁⟩, simp only [symm_apply_apply] },
right_inv := by { rintro ⟨x₁, y₁⟩, simp only [apply_symm_apply] } }
end prod_congr
namespace perm
variables {α₁ β₁ β₂ : Type*} [decidable_eq α₁] (a : α₁) (e : perm β₁)
/-- `prod_extend_right a e` extends `e : perm β` to `perm (α × β)` by sending `(a, b)` to
`(a, e b)` and keeping the other `(a', b)` fixed. -/
def prod_extend_right : perm (α₁ × β₁) :=
{ to_fun := λ ab, if ab.fst = a then (a, e ab.snd) else ab,
inv_fun := λ ab, if ab.fst = a then (a, e.symm ab.snd) else ab,
left_inv := by { rintros ⟨k', x⟩, dsimp only, split_ifs with h; simp [h] },
right_inv := by { rintros ⟨k', x⟩, dsimp only, split_ifs with h; simp [h] } }
@[simp] lemma prod_extend_right_apply_eq (b : β₁) :
prod_extend_right a e (a, b) = (a, e b) := if_pos rfl
lemma prod_extend_right_apply_ne {a a' : α₁} (h : a' ≠ a) (b : β₁) :
prod_extend_right a e (a', b) = (a', b) := if_neg h
lemma eq_of_prod_extend_right_ne {e : perm β₁} {a a' : α₁} {b : β₁}
(h : prod_extend_right a e (a', b) ≠ (a', b)) : a' = a :=
by { contrapose! h, exact prod_extend_right_apply_ne _ h _ }
@[simp] lemma fst_prod_extend_right (ab : α₁ × β₁) :
(prod_extend_right a e ab).fst = ab.fst :=
begin
rw [prod_extend_right, coe_fn_mk],
split_ifs with h,
{ rw h },
{ refl }
end
end perm
section
/-- The type of functions to a product `α × β` is equivalent to the type of pairs of functions
`γ → α` and `γ → β`. -/
def arrow_prod_equiv_prod_arrow (α β γ : Type*) : (γ → α × β) ≃ (γ → α) × (γ → β) :=
⟨λ f, (λ c, (f c).1, λ c, (f c).2),
λ p c, (p.1 c, p.2 c),
λ f, funext $ λ c, prod.mk.eta,
λ p, by { cases p, refl }⟩
open sum
/-- The type of functions on a sum type `α ⊕ β` is equivalent to the type of pairs of functions
on `α` and on `β`. -/
def sum_arrow_equiv_prod_arrow (α β γ : Type*) : ((α ⊕ β) → γ) ≃ (α → γ) × (β → γ) :=
⟨λ f, (f ∘ inl, f ∘ inr),
λ p, sum.elim p.1 p.2,
λ f, by { ext ⟨⟩; refl },
λ p, by { cases p, refl }⟩
@[simp] lemma sum_arrow_equiv_prod_arrow_apply_fst {α β γ} (f : (α ⊕ β) → γ) (a : α) :
(sum_arrow_equiv_prod_arrow α β γ f).1 a = f (inl a) := rfl
@[simp] lemma sum_arrow_equiv_prod_arrow_apply_snd {α β γ} (f : (α ⊕ β) → γ) (b : β) :
(sum_arrow_equiv_prod_arrow α β γ f).2 b = f (inr b) := rfl
@[simp] lemma sum_arrow_equiv_prod_arrow_symm_apply_inl {α β γ} (f : α → γ) (g : β → γ) (a : α) :
((sum_arrow_equiv_prod_arrow α β γ).symm (f, g)) (inl a) = f a := rfl
@[simp] lemma sum_arrow_equiv_prod_arrow_symm_apply_inr {α β γ} (f : α → γ) (g : β → γ) (b : β) :
((sum_arrow_equiv_prod_arrow α β γ).symm (f, g)) (inr b) = g b := rfl
/-- Type product is right distributive with respect to type sum up to an equivalence. -/
def sum_prod_distrib (α β γ : Sort*) : (α ⊕ β) × γ ≃ (α × γ) ⊕ (β × γ) :=
⟨λ p, p.1.map (λ x, (x, p.2)) (λ x, (x, p.2)),
λ s, s.elim (prod.map inl id) (prod.map inr id),
by rintro ⟨_ | _, _⟩; refl,
by rintro (⟨_, _⟩ | ⟨_, _⟩); refl⟩
@[simp] theorem sum_prod_distrib_apply_left {α β γ} (a : α) (c : γ) :
sum_prod_distrib α β γ (sum.inl a, c) = sum.inl (a, c) := rfl
@[simp] theorem sum_prod_distrib_apply_right {α β γ} (b : β) (c : γ) :
sum_prod_distrib α β γ (sum.inr b, c) = sum.inr (b, c) := rfl
@[simp] theorem sum_prod_distrib_symm_apply_left {α β γ} (a : α × γ) :
(sum_prod_distrib α β γ).symm (inl a) = (inl a.1, a.2) := rfl
@[simp] theorem sum_prod_distrib_symm_apply_right {α β γ} (b : β × γ) :
(sum_prod_distrib α β γ).symm (inr b) = (inr b.1, b.2) := rfl
/-- Type product is left distributive with respect to type sum up to an equivalence. -/
def prod_sum_distrib (α β γ : Sort*) : α × (β ⊕ γ) ≃ (α × β) ⊕ (α × γ) :=
calc α × (β ⊕ γ) ≃ (β ⊕ γ) × α : prod_comm _ _
... ≃ (β × α) ⊕ (γ × α) : sum_prod_distrib _ _ _
... ≃ (α × β) ⊕ (α × γ) : sum_congr (prod_comm _ _) (prod_comm _ _)
@[simp] theorem prod_sum_distrib_apply_left {α β γ} (a : α) (b : β) :
prod_sum_distrib α β γ (a, sum.inl b) = sum.inl (a, b) := rfl
@[simp] theorem prod_sum_distrib_apply_right {α β γ} (a : α) (c : γ) :
prod_sum_distrib α β γ (a, sum.inr c) = sum.inr (a, c) := rfl
@[simp] theorem prod_sum_distrib_symm_apply_left {α β γ} (a : α × β) :
(prod_sum_distrib α β γ).symm (inl a) = (a.1, inl a.2) := rfl
@[simp] theorem prod_sum_distrib_symm_apply_right {α β γ} (a : α × γ) :
(prod_sum_distrib α β γ).symm (inr a) = (a.1, inr a.2) := rfl
/-- An indexed sum of disjoint sums of types is equivalent to the sum of the indexed sums. -/
@[simps] def sigma_sum_distrib {ι : Type*} (α β : ι → Type*) :
(Σ i, α i ⊕ β i) ≃ (Σ i, α i) ⊕ Σ i, β i :=
⟨λ p, p.2.map (sigma.mk p.1) (sigma.mk p.1),
sum.elim (sigma.map id (λ _, sum.inl)) (sigma.map id (λ _, sum.inr)),
λ p, by { rcases p with ⟨i, (a | b)⟩; refl },
λ p, by { rcases p with (⟨i, a⟩ | ⟨i, b⟩); refl }⟩
/-- The product of an indexed sum of types (formally, a `sigma`-type `Σ i, α i`) by a type `β` is
equivalent to the sum of products `Σ i, (α i × β)`. -/
def sigma_prod_distrib {ι : Type*} (α : ι → Type*) (β : Type*) :
((Σ i, α i) × β) ≃ (Σ i, (α i × β)) :=
⟨λ p, ⟨p.1.1, (p.1.2, p.2)⟩,
λ p, (⟨p.1, p.2.1⟩, p.2.2),
λ p, by { rcases p with ⟨⟨_, _⟩, _⟩, refl },
λ p, by { rcases p with ⟨_, ⟨_, _⟩⟩, refl }⟩
/-- An equivalence that separates out the 0th fiber of `(Σ (n : ℕ), f n)`. -/
def sigma_nat_succ (f : ℕ → Type u) :
(Σ n, f n) ≃ f 0 ⊕ Σ n, f (n + 1) :=
⟨λ x, @sigma.cases_on ℕ f (λ _, f 0 ⊕ Σ n, f (n + 1)) x (λ n, @nat.cases_on (λ i, f i → (f 0 ⊕
Σ (n : ℕ), f (n + 1))) n (λ (x : f 0), sum.inl x) (λ (n : ℕ) (x : f n.succ), sum.inr ⟨n, x⟩)),
sum.elim (sigma.mk 0) (sigma.map nat.succ (λ _, id)),
by { rintro ⟨(n | n), x⟩; refl }, by { rintro (x | ⟨n, x⟩); refl }⟩
/-- The product `bool × α` is equivalent to `α ⊕ α`. -/
@[simps] def bool_prod_equiv_sum (α : Type u) : bool × α ≃ α ⊕ α :=
{ to_fun := λ p, cond p.1 (inr p.2) (inl p.2),
inv_fun := sum.elim (prod.mk ff) (prod.mk tt),
left_inv := by rintro ⟨(_|_), _⟩; refl,
right_inv := by rintro (_|_); refl }
/-- The function type `bool → α` is equivalent to `α × α`. -/
@[simps] def bool_arrow_equiv_prod (α : Type u) : (bool → α) ≃ α × α :=
{ to_fun := λ f, (f tt, f ff),
inv_fun := λ p b, cond b p.1 p.2,
left_inv := λ f, funext $ bool.forall_bool.2 ⟨rfl, rfl⟩,
right_inv := λ ⟨x, y⟩, rfl }
end
section
open sum nat
/-- The set of natural numbers is equivalent to `ℕ ⊕ punit`. -/
def nat_equiv_nat_sum_punit : ℕ ≃ ℕ ⊕ punit.{u+1} :=
{ to_fun := λ n, nat.cases_on n (inr punit.star) inl,
inv_fun := sum.elim nat.succ (λ _, 0),
left_inv := λ n, by cases n; refl,
right_inv := by rintro (_|_|_); refl }
/-- `ℕ ⊕ punit` is equivalent to `ℕ`. -/
def nat_sum_punit_equiv_nat : ℕ ⊕ punit.{u+1} ≃ ℕ :=
nat_equiv_nat_sum_punit.symm
/-- The type of integer numbers is equivalent to `ℕ ⊕ ℕ`. -/
def int_equiv_nat_sum_nat : ℤ ≃ ℕ ⊕ ℕ :=
{ to_fun := λ z, int.cases_on z inl inr,
inv_fun := sum.elim coe int.neg_succ_of_nat,
left_inv := by rintro (m|n); refl,
right_inv := by rintro (m|n); refl }
end
/-- An equivalence between `α` and `β` generates an equivalence between `list α` and `list β`. -/
def list_equiv_of_equiv {α β : Type*} (e : α ≃ β) : list α ≃ list β :=
{ to_fun := list.map e,
inv_fun := list.map e.symm,
left_inv := λ l, by rw [list.map_map, e.symm_comp_self, list.map_id],
right_inv := λ l, by rw [list.map_map, e.self_comp_symm, list.map_id] }
/-- If `α` is equivalent to `β`, then `unique α` is equivalent to `unique β`. -/
def unique_congr (e : α ≃ β) : unique α ≃ unique β :=
{ to_fun := λ h, @equiv.unique _ _ h e.symm,
inv_fun := λ h, @equiv.unique _ _ h e,
left_inv := λ _, subsingleton.elim _ _,
right_inv := λ _, subsingleton.elim _ _ }
/-- If `α` is equivalent to `β`, then `is_empty α` is equivalent to `is_empty β`. -/
lemma is_empty_congr (e : α ≃ β) : is_empty α ↔ is_empty β :=
⟨λ h, @function.is_empty _ _ h e.symm, λ h, @function.is_empty _ _ h e⟩
protected lemma is_empty (e : α ≃ β) [is_empty β] : is_empty α :=
e.is_empty_congr.mpr ‹_›
section
open subtype
/-- If `α` is equivalent to `β` and the predicates `p : α → Prop` and `q : β → Prop` are equivalent
at corresponding points, then `{a // p a}` is equivalent to `{b // q b}`.
For the statement where `α = β`, that is, `e : perm α`, see `perm.subtype_perm`. -/
def subtype_equiv {p : α → Prop} {q : β → Prop}
(e : α ≃ β) (h : ∀ a, p a ↔ q (e a)) : {a : α // p a} ≃ {b : β // q b} :=
{ to_fun := λ a, ⟨e a, (h _).mp a.prop⟩,
inv_fun := λ b, ⟨e.symm b, (h _).mpr ((e.apply_symm_apply b).symm ▸ b.prop)⟩,
left_inv := λ a, subtype.ext $ by simp,
right_inv := λ b, subtype.ext $ by simp }
@[simp] lemma subtype_equiv_refl {p : α → Prop}
(h : ∀ a, p a ↔ p (equiv.refl _ a) := λ a, iff.rfl) :
(equiv.refl α).subtype_equiv h = equiv.refl {a : α // p a} :=
by { ext, refl }
@[simp] lemma subtype_equiv_symm {p : α → Prop} {q : β → Prop} (e : α ≃ β)
(h : ∀ (a : α), p a ↔ q (e a)) :
(e.subtype_equiv h).symm = e.symm.subtype_equiv (λ a, by
{ convert (h $ e.symm a).symm,
exact (e.apply_symm_apply a).symm }) :=
rfl
@[simp] lemma subtype_equiv_trans {p : α → Prop} {q : β → Prop} {r : γ → Prop}
(e : α ≃ β) (f : β ≃ γ)
(h : ∀ (a : α), p a ↔ q (e a)) (h' : ∀ (b : β), q b ↔ r (f b)):
(e.subtype_equiv h).trans (f.subtype_equiv h') =
(e.trans f).subtype_equiv (λ a, (h a).trans (h' $ e a)) :=
rfl
@[simp] lemma subtype_equiv_apply {p : α → Prop} {q : β → Prop} (e : α ≃ β)
(h : ∀ (a : α), p a ↔ q (e a)) (x : {x // p x}) :
e.subtype_equiv h x = ⟨e x, (h _).1 x.2⟩ :=
rfl
/-- If two predicates `p` and `q` are pointwise equivalent, then `{x // p x}` is equivalent to
`{x // q x}`. -/
@[simps]
def subtype_equiv_right {p q : α → Prop} (e : ∀x, p x ↔ q x) : {x // p x} ≃ {x // q x} :=
subtype_equiv (equiv.refl _) e
/-- If `α ≃ β`, then for any predicate `p : β → Prop` the subtype `{a // p (e a)}` is equivalent
to the subtype `{b // p b}`. -/
def subtype_equiv_of_subtype {p : β → Prop} (e : α ≃ β) :
{a : α // p (e a)} ≃ {b : β // p b} :=
subtype_equiv e $ by simp
/-- If `α ≃ β`, then for any predicate `p : α → Prop` the subtype `{a // p a}` is equivalent
to the subtype `{b // p (e.symm b)}`. This version is used by `equiv_rw`. -/
def subtype_equiv_of_subtype' {p : α → Prop} (e : α ≃ β) :
{a : α // p a} ≃ {b : β // p (e.symm b)} :=
e.symm.subtype_equiv_of_subtype.symm
/-- If two predicates are equal, then the corresponding subtypes are equivalent. -/
def subtype_equiv_prop {α : Type*} {p q : α → Prop} (h : p = q) : subtype p ≃ subtype q :=
subtype_equiv (equiv.refl α) (assume a, h ▸ iff.rfl)
/-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. This
version allows the “inner” predicate to depend on `h : p a`. -/
@[simps]
def subtype_subtype_equiv_subtype_exists {α : Type u} (p : α → Prop) (q : subtype p → Prop) :
subtype q ≃ {a : α // ∃h:p a, q ⟨a, h⟩ } :=
⟨λ a, ⟨a, a.1.2, by { rcases a with ⟨⟨a, hap⟩, haq⟩, exact haq }⟩,
λ a, ⟨⟨a, a.2.fst⟩, a.2.snd⟩,
assume ⟨⟨a, ha⟩, h⟩, rfl, assume ⟨a, h₁, h₂⟩, rfl⟩
/-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. -/
@[simps] def subtype_subtype_equiv_subtype_inter {α : Type u} (p q : α → Prop) :
{x : subtype p // q x.1} ≃ subtype (λ x, p x ∧ q x) :=
(subtype_subtype_equiv_subtype_exists p _).trans $
subtype_equiv_right $ λ x, exists_prop
/-- If the outer subtype has more restrictive predicate than the inner one,
then we can drop the latter. -/
@[simps] def subtype_subtype_equiv_subtype {α : Type u} {p q : α → Prop} (h : ∀ {x}, q x → p x) :
{x : subtype p // q x.1} ≃ subtype q :=
(subtype_subtype_equiv_subtype_inter p _).trans $
subtype_equiv_right $ λ x, and_iff_right_of_imp h
/-- If a proposition holds for all elements, then the subtype is
equivalent to the original type. -/
@[simps apply symm_apply]
def subtype_univ_equiv {α : Type u} {p : α → Prop} (h : ∀ x, p x) :
subtype p ≃ α :=
⟨λ x, x, λ x, ⟨x, h x⟩, λ x, subtype.eq rfl, λ x, rfl⟩
/-- A subtype of a sigma-type is a sigma-type over a subtype. -/
def subtype_sigma_equiv {α : Type u} (p : α → Type v) (q : α → Prop) :
{ y : sigma p // q y.1 } ≃ Σ(x : subtype q), p x.1 :=
⟨λ x, ⟨⟨x.1.1, x.2⟩, x.1.2⟩,
λ x, ⟨⟨x.1.1, x.2⟩, x.1.2⟩,
λ ⟨⟨x, h⟩, y⟩, rfl,
λ ⟨⟨x, y⟩, h⟩, rfl⟩
/-- A sigma type over a subtype is equivalent to the sigma set over the original type,
if the fiber is empty outside of the subset -/
def sigma_subtype_equiv_of_subset {α : Type u} (p : α → Type v) (q : α → Prop)
(h : ∀ x, p x → q x) :
(Σ x : subtype q, p x) ≃ Σ x : α, p x :=
(subtype_sigma_equiv p q).symm.trans $ subtype_univ_equiv $ λ x, h x.1 x.2
/-- If a predicate `p : β → Prop` is true on the range of a map `f : α → β`, then
`Σ y : {y // p y}, {x // f x = y}` is equivalent to `α`. -/
def sigma_subtype_fiber_equiv {α : Type u} {β : Type v} (f : α → β) (p : β → Prop)
(h : ∀ x, p (f x)) :
(Σ y : subtype p, {x : α // f x = y}) ≃ α :=
calc _ ≃ Σ y : β, {x : α // f x = y} : sigma_subtype_equiv_of_subset _ p (λ y ⟨x, h'⟩, h' ▸ h x)
... ≃ α : sigma_fiber_equiv f
/-- If for each `x` we have `p x ↔ q (f x)`, then `Σ y : {y // q y}, f ⁻¹' {y}` is equivalent
to `{x // p x}`. -/
def sigma_subtype_fiber_equiv_subtype {α : Type u} {β : Type v} (f : α → β)
{p : α → Prop} {q : β → Prop} (h : ∀ x, p x ↔ q (f x)) :
(Σ y : subtype q, {x : α // f x = y}) ≃ subtype p :=
calc (Σ y : subtype q, {x : α // f x = y}) ≃
Σ y : subtype q, {x : subtype p // subtype.mk (f x) ((h x).1 x.2) = y} :
begin
apply sigma_congr_right,
assume y,
symmetry,
refine (subtype_subtype_equiv_subtype_exists _ _).trans (subtype_equiv_right _),
assume x,
exact ⟨λ ⟨hp, h'⟩, congr_arg subtype.val h', λ h', ⟨(h x).2 (h'.symm ▸ y.2), subtype.eq h'⟩⟩
end
... ≃ subtype p : sigma_fiber_equiv (λ x : subtype p, (⟨f x, (h x).1 x.property⟩ : subtype q))
/-- A sigma type over an `option` is equivalent to the sigma set over the original type,
if the fiber is empty at none. -/
def sigma_option_equiv_of_some {α : Type u} (p : option α → Type v) (h : p none → false) :
(Σ x : option α, p x) ≃ (Σ x : α, p (some x)) :=
begin
have h' : ∀ x, p x → x.is_some,
{ intro x,
cases x,
{ intro n, exfalso, exact h n },
{ intro s, exact rfl } },
exact (sigma_subtype_equiv_of_subset _ _ h').symm.trans
(sigma_congr_left' (option_is_some_equiv α)),
end
/-- The `pi`-type `Π i, π i` is equivalent to the type of sections `f : ι → Σ i, π i` of the
`sigma` type such that for all `i` we have `(f i).fst = i`. -/
def pi_equiv_subtype_sigma (ι : Type*) (π : ι → Type*) :
(Π i, π i) ≃ {f : ι → Σ i, π i // ∀ i, (f i).1 = i } :=
⟨ λf, ⟨λi, ⟨i, f i⟩, assume i, rfl⟩, λf i, begin rw ← f.2 i, exact (f.1 i).2 end,
assume f, funext $ assume i, rfl,
assume ⟨f, hf⟩, subtype.eq $ funext $ assume i, sigma.eq (hf i).symm $
eq_of_heq $ rec_heq_of_heq _ $ rec_heq_of_heq _ $ heq.refl _⟩
/-- The set of functions `f : Π a, β a` such that for all `a` we have `p a (f a)` is equivalent
to the set of functions `Π a, {b : β a // p a b}`. -/
def subtype_pi_equiv_pi {α : Sort u} {β : α → Sort v} {p : Πa, β a → Prop} :
{f : Πa, β a // ∀a, p a (f a) } ≃ Πa, { b : β a // p a b } :=
⟨λf a, ⟨f.1 a, f.2 a⟩, λf, ⟨λa, (f a).1, λa, (f a).2⟩,
by { rintro ⟨f, h⟩, refl },
by { rintro f, funext a, exact subtype.ext_val rfl }⟩
/-- A subtype of a product defined by componentwise conditions
is equivalent to a product of subtypes. -/
def subtype_prod_equiv_prod {α : Type u} {β : Type v} {p : α → Prop} {q : β → Prop} :
{c : α × β // p c.1 ∧ q c.2} ≃ ({a // p a} × {b // q b}) :=
⟨λ x, ⟨⟨x.1.1, x.2.1⟩, ⟨x.1.2, x.2.2⟩⟩,
λ x, ⟨⟨x.1.1, x.2.1⟩, ⟨x.1.2, x.2.2⟩⟩,
λ ⟨⟨_, _⟩, ⟨_, _⟩⟩, rfl,
λ ⟨⟨_, _⟩, ⟨_, _⟩⟩, rfl⟩
/-- A subtype of a `prod` is equivalent to a sigma type whose fibers are subtypes. -/
def subtype_prod_equiv_sigma_subtype {α β : Type*} (p : α → β → Prop) :
{x : α × β // p x.1 x.2} ≃ Σ a, {b : β // p a b} :=
{ to_fun := λ x, ⟨x.1.1, x.1.2, x.prop⟩,
inv_fun := λ x, ⟨⟨x.1, x.2⟩, x.2.prop⟩,
left_inv := λ x, by ext; refl,
right_inv := λ ⟨a, b, pab⟩, rfl }
/-- The type `Π (i : α), β i` can be split as a product by separating the indices in `α`
depending on whether they satisfy a predicate `p` or not. -/
@[simps] def pi_equiv_pi_subtype_prod
{α : Type*} (p : α → Prop) (β : α → Type*) [decidable_pred p] :
(Π (i : α), β i) ≃ (Π (i : {x // p x}), β i) × (Π (i : {x // ¬ p x}), β i) :=
{ to_fun := λ f, (λ x, f x, λ x, f x),
inv_fun := λ f x, if h : p x then f.1 ⟨x, h⟩ else f.2 ⟨x, h⟩,
right_inv := begin
rintros ⟨f, g⟩,
ext1;
{ ext y,
rcases y,
simp only [y_property, dif_pos, dif_neg, not_false_iff, subtype.coe_mk],
refl },
end,
left_inv := λ f, begin
ext x,
by_cases h : p x;
{ simp only [h, dif_neg, dif_pos, not_false_iff],
refl },
end }
/-- A product of types can be split as the binary product of one of the types and the product
of all the remaining types. -/
@[simps] def pi_split_at {α : Type*} [decidable_eq α] (i : α) (β : α → Type*) :
(Π j, β j) ≃ β i × Π j : {j // j ≠ i}, β j :=
{ to_fun := λ f, ⟨f i, λ j, f j⟩,
inv_fun := λ f j, if h : j = i then h.symm.rec f.1 else f.2 ⟨j, h⟩,
right_inv := λ f, by { ext, exacts [dif_pos rfl, (dif_neg x.2).trans (by cases x; refl)] },
left_inv := λ f, by { ext, dsimp only, split_ifs, { subst h }, { refl } } }
/-- A product of copies of a type can be split as the binary product of one copy and the product
of all the remaining copies. -/
@[simps] def fun_split_at {α : Type*} [decidable_eq α] (i : α) (β : Type*) :
(α → β) ≃ β × ({j // j ≠ i} → β) := pi_split_at i _
end
section subtype_equiv_codomain
variables {X : Type*} {Y : Type*} [decidable_eq X] {x : X}
/-- The type of all functions `X → Y` with prescribed values for all `x' ≠ x`
is equivalent to the codomain `Y`. -/
def subtype_equiv_codomain (f : {x' // x' ≠ x} → Y) : {g : X → Y // g ∘ coe = f} ≃ Y :=
(subtype_preimage _ f).trans $
@fun_unique {x' // ¬ x' ≠ x} _ $
show unique {x' // ¬ x' ≠ x}, from @equiv.unique _ _
(show unique {x' // x' = x}, from
{ default := ⟨x, rfl⟩, uniq := λ ⟨x', h⟩, subtype.val_injective h })
(subtype_equiv_right $ λ a, not_not)
@[simp] lemma coe_subtype_equiv_codomain (f : {x' // x' ≠ x} → Y) :
(subtype_equiv_codomain f : {g : X → Y // g ∘ coe = f} → Y) = λ g, (g : X → Y) x := rfl
@[simp] lemma subtype_equiv_codomain_apply (f : {x' // x' ≠ x} → Y)
(g : {g : X → Y // g ∘ coe = f}) :
subtype_equiv_codomain f g = (g : X → Y) x := rfl
lemma coe_subtype_equiv_codomain_symm (f : {x' // x' ≠ x} → Y) :
((subtype_equiv_codomain f).symm : Y → {g : X → Y // g ∘ coe = f}) =
λ y, ⟨λ x', if h : x' ≠ x then f ⟨x', h⟩ else y,
by { funext x', dsimp, erw [dif_pos x'.2, subtype.coe_eta] }⟩ := rfl
@[simp] lemma subtype_equiv_codomain_symm_apply (f : {x' // x' ≠ x} → Y) (y : Y) (x' : X) :
((subtype_equiv_codomain f).symm y : X → Y) x' = if h : x' ≠ x then f ⟨x', h⟩ else y :=
rfl
@[simp] lemma subtype_equiv_codomain_symm_apply_eq (f : {x' // x' ≠ x} → Y) (y : Y) :
((subtype_equiv_codomain f).symm y : X → Y) x = y :=
dif_neg (not_not.mpr rfl)
lemma subtype_equiv_codomain_symm_apply_ne (f : {x' // x' ≠ x} → Y) (y : Y) (x' : X) (h : x' ≠ x) :
((subtype_equiv_codomain f).symm y : X → Y) x' = f ⟨x', h⟩ :=
dif_pos h
end subtype_equiv_codomain
/-- If `f` is a bijective function, then its domain is equivalent to its codomain. -/
@[simps apply]
noncomputable def of_bijective (f : α → β) (hf : bijective f) : α ≃ β :=
{ to_fun := f,
inv_fun := function.surj_inv hf.surjective,
left_inv := function.left_inverse_surj_inv hf,
right_inv := function.right_inverse_surj_inv _}
lemma of_bijective_apply_symm_apply (f : α → β) (hf : bijective f) (x : β) :
f ((of_bijective f hf).symm x) = x :=
(of_bijective f hf).apply_symm_apply x
@[simp] lemma of_bijective_symm_apply_apply (f : α → β) (hf : bijective f) (x : α) :
(of_bijective f hf).symm (f x) = x :=
(of_bijective f hf).symm_apply_apply x
instance : can_lift (α → β) (α ≃ β) coe_fn bijective :=
{ prf := λ f hf, ⟨of_bijective f hf, rfl⟩ }
section
variables {α' β' : Type*} (e : perm α') {p : β' → Prop} [decidable_pred p]
(f : α' ≃ subtype p)
/--
Extend the domain of `e : equiv.perm α` to one that is over `β` via `f : α → subtype p`,
where `p : β → Prop`, permuting only the `b : β` that satisfy `p b`.
This can be used to extend the domain across a function `f : α → β`,
keeping everything outside of `set.range f` fixed. For this use-case `equiv` given by `f` can
be constructed by `equiv.of_left_inverse'` or `equiv.of_left_inverse` when there is a known
inverse, or `equiv.of_injective` in the general case.`.
-/
def perm.extend_domain : perm β' :=
(perm_congr f e).subtype_congr (equiv.refl _)
@[simp] lemma perm.extend_domain_apply_image (a : α') :
e.extend_domain f (f a) = f (e a) :=
by simp [perm.extend_domain]
lemma perm.extend_domain_apply_subtype {b : β'} (h : p b) :
e.extend_domain f b = f (e (f.symm ⟨b, h⟩)) :=
by simp [perm.extend_domain, h]
lemma perm.extend_domain_apply_not_subtype {b : β'} (h : ¬ p b) :
e.extend_domain f b = b :=
by simp [perm.extend_domain, h]
@[simp] lemma perm.extend_domain_refl : perm.extend_domain (equiv.refl _) f = equiv.refl _ :=
by simp [perm.extend_domain]
@[simp] lemma perm.extend_domain_symm :
(e.extend_domain f).symm = perm.extend_domain e.symm f := rfl
lemma perm.extend_domain_trans (e e' : perm α') :
(e.extend_domain f).trans (e'.extend_domain f) = perm.extend_domain (e.trans e') f :=
by simp [perm.extend_domain, perm_congr_trans]
end
/-- Subtype of the quotient is equivalent to the quotient of the subtype. Let `α` be a setoid with
equivalence relation `~`. Let `p₂` be a predicate on the quotient type `α/~`, and `p₁` be the lift
of this predicate to `α`: `p₁ a ↔ p₂ ⟦a⟧`. Let `~₂` be the restriction of `~` to `{x // p₁ x}`.
Then `{x // p₂ x}` is equivalent to the quotient of `{x // p₁ x}` by `~₂`. -/
def subtype_quotient_equiv_quotient_subtype (p₁ : α → Prop) [s₁ : setoid α]
[s₂ : setoid (subtype p₁)] (p₂ : quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧)
(h : ∀ x y : subtype p₁, @setoid.r _ s₂ x y ↔ (x : α) ≈ y) :
{x // p₂ x} ≃ quotient s₂ :=
{ to_fun := λ a, quotient.hrec_on a.1 (λ a h, ⟦⟨a, (hp₂ _).2 h⟩⟧)
(λ a b hab, hfunext (by rw quotient.sound hab)
(λ h₁ h₂ _, heq_of_eq (quotient.sound ((h _ _).2 hab)))) a.2,
inv_fun := λ a, quotient.lift_on a (λ a, (⟨⟦a.1⟧, (hp₂ _).1 a.2⟩ : {x // p₂ x}))
(λ a b hab, subtype.ext_val (quotient.sound ((h _ _).1 hab))),
left_inv := λ ⟨a, ha⟩, quotient.induction_on a (λ a ha, rfl) ha,
right_inv := λ a, quotient.induction_on a (λ ⟨a, ha⟩, rfl) }
@[simp] lemma subtype_quotient_equiv_quotient_subtype_mk (p₁ : α → Prop) [s₁ : setoid α]
[s₂ : setoid (subtype p₁)] (p₂ : quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧)
(h : ∀ x y : subtype p₁, @setoid.r _ s₂ x y ↔ (x : α) ≈ y) (x hx) :
subtype_quotient_equiv_quotient_subtype p₁ p₂ hp₂ h ⟨⟦x⟧, hx⟩ = ⟦⟨x, (hp₂ _).2 hx⟩⟧ := rfl
@[simp] lemma subtype_quotient_equiv_quotient_subtype_symm_mk (p₁ : α → Prop) [s₁ : setoid α]
[s₂ : setoid (subtype p₁)] (p₂ : quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧)
(h : ∀ x y : subtype p₁, @setoid.r _ s₂ x y ↔ (x : α) ≈ y) (x) :
(subtype_quotient_equiv_quotient_subtype p₁ p₂ hp₂ h).symm ⟦x⟧ = ⟨⟦x⟧, (hp₂ _).1 x.prop⟩ := rfl
section swap
variable [decidable_eq α]
/-- A helper function for `equiv.swap`. -/
def swap_core (a b r : α) : α :=
if r = a then b
else if r = b then a
else r
theorem swap_core_self (r a : α) : swap_core a a r = r :=
by { unfold swap_core, split_ifs; cc }
theorem swap_core_swap_core (r a b : α) : swap_core a b (swap_core a b r) = r :=
by { unfold swap_core, split_ifs; cc }
theorem swap_core_comm (r a b : α) : swap_core a b r = swap_core b a r :=
by { unfold swap_core, split_ifs; cc }
/-- `swap a b` is the permutation that swaps `a` and `b` and
leaves other values as is. -/
def swap (a b : α) : perm α :=
⟨swap_core a b, swap_core a b, λr, swap_core_swap_core r a b, λr, swap_core_swap_core r a b⟩
@[simp] theorem swap_self (a : α) : swap a a = equiv.refl _ :=
ext $ λ r, swap_core_self r a
theorem swap_comm (a b : α) : swap a b = swap b a :=
ext $ λ r, swap_core_comm r _ _
theorem swap_apply_def (a b x : α) : swap a b x = if x = a then b else if x = b then a else x :=
rfl
@[simp] theorem swap_apply_left (a b : α) : swap a b a = b :=
if_pos rfl
@[simp] theorem swap_apply_right (a b : α) : swap a b b = a :=
by { by_cases h : b = a; simp [swap_apply_def, h], }
theorem swap_apply_of_ne_of_ne {a b x : α} : x ≠ a → x ≠ b → swap a b x = x :=
by simp [swap_apply_def] {contextual := tt}
@[simp] theorem swap_swap (a b : α) : (swap a b).trans (swap a b) = equiv.refl _ :=
ext $ λ x, swap_core_swap_core _ _ _
@[simp] lemma symm_swap (a b : α) : (swap a b).symm = swap a b := rfl
@[simp] lemma swap_eq_refl_iff {x y : α} : swap x y = equiv.refl _ ↔ x = y :=
begin
refine ⟨λ h, (equiv.refl _).injective _, λ h, h ▸ (swap_self _)⟩,
rw [←h, swap_apply_left, h, refl_apply]
end
theorem swap_comp_apply {a b x : α} (π : perm α) :
π.trans (swap a b) x = if π x = a then b else if π x = b then a else π x :=
by { cases π, refl }
lemma swap_eq_update (i j : α) :
(equiv.swap i j : α → α) = update (update id j i) i j :=
funext $ λ x, by rw [update_apply _ i j, update_apply _ j i, equiv.swap_apply_def, id.def]
lemma comp_swap_eq_update (i j : α) (f : α → β) :
f ∘ equiv.swap i j = update (update f j (f i)) i (f j) :=
by rw [swap_eq_update, comp_update, comp_update, comp.right_id]
@[simp] lemma symm_trans_swap_trans [decidable_eq β] (a b : α) (e : α ≃ β) :
(e.symm.trans (swap a b)).trans e = swap (e a) (e b) :=
equiv.ext (λ x, begin
have : ∀ a, e.symm x = a ↔ x = e a :=
λ a, by { rw @eq_comm _ (e.symm x), split; intros; simp * at * },
simp [swap_apply_def, this],
split_ifs; simp
end)
@[simp] lemma trans_swap_trans_symm [decidable_eq β] (a b : β)
(e : α ≃ β) : (e.trans (swap a b)).trans e.symm = swap (e.symm a) (e.symm b) :=
symm_trans_swap_trans a b e.symm
@[simp] lemma swap_apply_self (i j a : α) :
swap i j (swap i j a) = a :=
by rw [← equiv.trans_apply, equiv.swap_swap, equiv.refl_apply]
/-- A function is invariant to a swap if it is equal at both elements -/
lemma apply_swap_eq_self {v : α → β} {i j : α} (hv : v i = v j) (k : α) : v (swap i j k) = v k :=
begin
by_cases hi : k = i, { rw [hi, swap_apply_left, hv] },
by_cases hj : k = j, { rw [hj, swap_apply_right, hv] },
rw swap_apply_of_ne_of_ne hi hj,
end
lemma swap_apply_eq_iff {x y z w : α} :
swap x y z = w ↔ z = swap x y w :=
by rw [apply_eq_iff_eq_symm_apply, symm_swap]
lemma swap_apply_ne_self_iff {a b x : α} : swap a b x ≠ x ↔ a ≠ b ∧ (x = a ∨ x = b) :=
begin
by_cases hab : a = b,
{ simp [hab] },
by_cases hax : x = a,
{ simp [hax, eq_comm] },
by_cases hbx : x = b,
{ simp [hbx] },
simp [hab, hax, hbx, swap_apply_of_ne_of_ne]
end
namespace perm
@[simp] lemma sum_congr_swap_refl {α β : Sort*} [decidable_eq α] [decidable_eq β] (i j : α) :
equiv.perm.sum_congr (equiv.swap i j) (equiv.refl β) = equiv.swap (sum.inl i) (sum.inl j) :=
begin
ext x,
cases x,
{ simp [sum.map, swap_apply_def],
split_ifs; refl},
{ simp [sum.map, swap_apply_of_ne_of_ne] },
end
@[simp] lemma sum_congr_refl_swap {α β : Sort*} [decidable_eq α] [decidable_eq β] (i j : β) :
equiv.perm.sum_congr (equiv.refl α) (equiv.swap i j) = equiv.swap (sum.inr i) (sum.inr j) :=
begin
ext x,
cases x,
{ simp [sum.map, swap_apply_of_ne_of_ne] },
{ simp [sum.map, swap_apply_def],
split_ifs; refl},
end
end perm
/-- Augment an equivalence with a prescribed mapping `f a = b` -/
def set_value (f : α ≃ β) (a : α) (b : β) : α ≃ β :=
(swap a (f.symm b)).trans f
@[simp] theorem set_value_eq (f : α ≃ β) (a : α) (b : β) : set_value f a b a = b :=
by { dsimp [set_value], simp [swap_apply_left] }
end swap
end equiv
namespace function.involutive
/-- Convert an involutive function `f` to a permutation with `to_fun = inv_fun = f`. -/
def to_perm (f : α → α) (h : involutive f) : equiv.perm α :=
⟨f, f, h.left_inverse, h.right_inverse⟩
@[simp] lemma coe_to_perm {f : α → α} (h : involutive f) : (h.to_perm f : α → α) = f := rfl
@[simp] lemma to_perm_symm {f : α → α} (h : involutive f) : (h.to_perm f).symm = h.to_perm f := rfl
lemma to_perm_involutive {f : α → α} (h : involutive f) : involutive (h.to_perm f) := h
end function.involutive
lemma plift.eq_up_iff_down_eq {x : plift α} {y : α} : x = plift.up y ↔ x.down = y :=
equiv.plift.eq_symm_apply
lemma function.injective.map_swap {α β : Type*} [decidable_eq α] [decidable_eq β]
{f : α → β} (hf : function.injective f) (x y z : α) :
f (equiv.swap x y z) = equiv.swap (f x) (f y) (f z) :=
begin
conv_rhs { rw equiv.swap_apply_def },
split_ifs with h₁ h₂,
{ rw [hf h₁, equiv.swap_apply_left] },
{ rw [hf h₂, equiv.swap_apply_right] },
{ rw [equiv.swap_apply_of_ne_of_ne (mt (congr_arg f) h₁) (mt (congr_arg f) h₂)] }
end
namespace equiv
section
variables (P : α → Sort w) (e : α ≃ β)
/--
Transport dependent functions through an equivalence of the base space.
-/
@[simps] def Pi_congr_left' : (Π a, P a) ≃ (Π b, P (e.symm b)) :=
{ to_fun := λ f x, f (e.symm x),
inv_fun := λ f x, begin rw [← e.symm_apply_apply x], exact f (e x) end,
left_inv := λ f, funext $ λ x, eq_of_heq ((eq_rec_heq _ _).trans
(by { dsimp, rw e.symm_apply_apply })),
right_inv := λ f, funext $ λ x, eq_of_heq ((eq_rec_heq _ _).trans
(by { rw e.apply_symm_apply })) }
end
section
variables (P : β → Sort w) (e : α ≃ β)
/--
Transporting dependent functions through an equivalence of the base,
expressed as a "simplification".
-/
def Pi_congr_left : (Π a, P (e a)) ≃ (Π b, P b) :=
(Pi_congr_left' P e.symm).symm
end
section
variables
{W : α → Sort w} {Z : β → Sort z} (h₁ : α ≃ β) (h₂ : Π a : α, (W a ≃ Z (h₁ a)))
/--
Transport dependent functions through
an equivalence of the base spaces and a family
of equivalences of the matching fibers.
-/
def Pi_congr : (Π a, W a) ≃ (Π b, Z b) :=
(equiv.Pi_congr_right h₂).trans (equiv.Pi_congr_left _ h₁)
@[simp] lemma coe_Pi_congr_symm :
((h₁.Pi_congr h₂).symm : (Π b, Z b) → (Π a, W a)) = λ f a, (h₂ a).symm (f (h₁ a)) :=
rfl
lemma Pi_congr_symm_apply (f : Π b, Z b) :
(h₁.Pi_congr h₂).symm f = λ a, (h₂ a).symm (f (h₁ a)) :=
rfl
@[simp] lemma Pi_congr_apply_apply (f : Π a, W a) (a : α) :
h₁.Pi_congr h₂ f (h₁ a) = h₂ a (f a) :=
begin
change cast _ ((h₂ (h₁.symm (h₁ a))) (f (h₁.symm (h₁ a)))) = (h₂ a) (f a),
generalize_proofs hZa,
revert hZa,
rw h₁.symm_apply_apply a,
simp,
end
end
section
variables
{W : α → Sort w} {Z : β → Sort z} (h₁ : α ≃ β) (h₂ : Π b : β, (W (h₁.symm b) ≃ Z b))
/--
Transport dependent functions through
an equivalence of the base spaces and a family
of equivalences of the matching fibres.
-/
def Pi_congr' : (Π a, W a) ≃ (Π b, Z b) :=
(Pi_congr h₁.symm (λ b, (h₂ b).symm)).symm
@[simp] lemma coe_Pi_congr' :
(h₁.Pi_congr' h₂ : (Π a, W a) → (Π b, Z b)) = λ f b, h₂ b $ f $ h₁.symm b :=
rfl
lemma Pi_congr'_apply (f : Π a, W a) :
h₁.Pi_congr' h₂ f = λ b, h₂ b $ f $ h₁.symm b :=
rfl
@[simp] lemma Pi_congr'_symm_apply_symm_apply (f : Π b, Z b) (b : β) :
(h₁.Pi_congr' h₂).symm f (h₁.symm b) = (h₂ b).symm (f b) :=
begin
change cast _ ((h₂ (h₁ (h₁.symm b))).symm (f (h₁ (h₁.symm b)))) = (h₂ b).symm (f b),
generalize_proofs hWb,
revert hWb,
generalize hb : h₁ (h₁.symm b) = b',
rw h₁.apply_symm_apply b at hb,
subst hb,
simp,
end
end
section binary_op
variables {α₁ β₁ : Type*} (e : α₁ ≃ β₁) (f : α₁ → α₁ → α₁)
lemma semiconj_conj (f : α₁ → α₁) : semiconj e f (e.conj f) := λ x, by simp
lemma semiconj₂_conj : semiconj₂ e f (e.arrow_congr e.conj f) := λ x y, by simp
instance [is_associative α₁ f] :
is_associative β₁ (e.arrow_congr (e.arrow_congr e) f) :=
(e.semiconj₂_conj f).is_associative_right e.surjective
instance [is_idempotent α₁ f] :
is_idempotent β₁ (e.arrow_congr (e.arrow_congr e) f) :=
(e.semiconj₂_conj f).is_idempotent_right e.surjective
instance [is_left_cancel α₁ f] :
is_left_cancel β₁ (e.arrow_congr (e.arrow_congr e) f) :=
⟨e.surjective.forall₃.2 $ λ x y z, by simpa using @is_left_cancel.left_cancel _ f _ x y z⟩
instance [is_right_cancel α₁ f] :
is_right_cancel β₁ (e.arrow_congr (e.arrow_congr e) f) :=
⟨e.surjective.forall₃.2 $ λ x y z, by simpa using @is_right_cancel.right_cancel _ f _ x y z⟩
end binary_op
end equiv
lemma function.injective.swap_apply [decidable_eq α] [decidable_eq β] {f : α → β}
(hf : function.injective f) (x y z : α) :
equiv.swap (f x) (f y) (f z) = f (equiv.swap x y z) :=
begin
by_cases hx : z = x, by simp [hx],
by_cases hy : z = y, by simp [hy],
rw [equiv.swap_apply_of_ne_of_ne hx hy, equiv.swap_apply_of_ne_of_ne (hf.ne hx) (hf.ne hy)]
end
lemma function.injective.swap_comp [decidable_eq α] [decidable_eq β] {f : α → β}
(hf : function.injective f) (x y : α) :
equiv.swap (f x) (f y) ∘ f = f ∘ equiv.swap x y :=
funext $ λ z, hf.swap_apply _ _ _
/-- If `α` is a subsingleton, then it is equivalent to `α × α`. -/
def subsingleton_prod_self_equiv {α : Type*} [subsingleton α] : α × α ≃ α :=
{ to_fun := λ p, p.1,
inv_fun := λ a, (a, a),
left_inv := λ p, subsingleton.elim _ _,
right_inv := λ p, subsingleton.elim _ _, }
/-- To give an equivalence between two subsingleton types, it is sufficient to give any two
functions between them. -/
def equiv_of_subsingleton_of_subsingleton [subsingleton α] [subsingleton β]
(f : α → β) (g : β → α) : α ≃ β :=
{ to_fun := f,
inv_fun := g,
left_inv := λ _, subsingleton.elim _ _,
right_inv := λ _, subsingleton.elim _ _ }
/-- A nonempty subsingleton type is (noncomputably) equivalent to `punit`. -/
noncomputable
def equiv.punit_of_nonempty_of_subsingleton {α : Sort*} [h : nonempty α] [subsingleton α] :
α ≃ punit.{v} :=
equiv_of_subsingleton_of_subsingleton
(λ _, punit.star) (λ _, h.some)
/-- `unique (unique α)` is equivalent to `unique α`. -/
def unique_unique_equiv : unique (unique α) ≃ unique α :=
equiv_of_subsingleton_of_subsingleton (λ h, h.default)
(λ h, { default := h, uniq := λ _, subsingleton.elim _ _ })
namespace function
lemma update_comp_equiv {α β α' : Sort*} [decidable_eq α'] [decidable_eq α] (f : α → β) (g : α' ≃ α)
(a : α) (v : β) :
update f a v ∘ g = update (f ∘ g) (g.symm a) v :=
by rw [← update_comp_eq_of_injective _ g.injective, g.apply_symm_apply]
lemma update_apply_equiv_apply {α β α' : Sort*} [decidable_eq α'] [decidable_eq α]
(f : α → β) (g : α' ≃ α) (a : α) (v : β) (a' : α') :
update f a v (g a') = update (f ∘ g) (g.symm a) v a' :=
congr_fun (update_comp_equiv f g a v) a'
lemma Pi_congr_left'_update [decidable_eq α] [decidable_eq β]
(P : α → Sort*) (e : α ≃ β) (f : Π a, P a) (b : β) (x : P (e.symm b)) :
e.Pi_congr_left' P (update f (e.symm b) x) = update (e.Pi_congr_left' P f) b x :=
begin
ext b',
rcases eq_or_ne b' b with rfl | h,
{ simp, },
{ simp [h], },
end
lemma Pi_congr_left'_symm_update [decidable_eq α] [decidable_eq β]
(P : α → Sort*) (e : α ≃ β) (f : Π b, P (e.symm b)) (b : β) (x : P (e.symm b)) :
(e.Pi_congr_left' P).symm (update f b x) = update ((e.Pi_congr_left' P).symm f) (e.symm b) x :=
by simp [(e.Pi_congr_left' P).symm_apply_eq, Pi_congr_left'_update]
end function
|
64c22b3e8a337083386cd4d9b3606c6fcba1feaa | ec62863c729b7eedee77b86d974f2c529fa79d25 | /23/b.lean | d10c59a237453c11dc3b62d06d7255f8447a87d8 | [] | no_license | rwbarton/advent-of-lean-4 | 2ac9b17ba708f66051e3d8cd694b0249bc433b65 | 417c7e2718253ba7148c0279fcb251b6fc291477 | refs/heads/main | 1,675,917,092,057 | 1,609,864,581,000 | 1,609,864,581,000 | 317,700,289 | 24 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,322 | lean | structure St where
cur : Nat
next : Array Nat
prev : Array Nat
def MAX : Nat := 1000000
partial def resolve (bad : List Nat) (x : Nat) : Nat :=
let x' := if x = 0 then MAX else x
if bad.any (· = x') then resolve bad (x'-1) else x'
def step (s : St) : St := do
let a := s.cur
let b₁ := s.next[a]
let b₂ := s.next[b₁]
let b₃ := s.next[b₂]
let b₄ := s.next[b₃]
let tgt := resolve [b₁, b₂, b₃] (a-1)
let tgt' := s.next[tgt]
let mut next' := s.next
let mut prev' := s.prev
next' := ((next'.set! a b₄).set! b₃ tgt').set! tgt b₁
prev' := ((prev'.set! b₄ a).set! tgt' b₃).set! b₁ tgt
{ cur := b₄, next := next', prev := prev' }
def main : IO Unit := do
let input ← IO.FS.lines "a.in"
let init₀ := (Array.mk input[0].toList).map (String.toNat! ∘ String.singleton)
let mut init := Array.mkArray MAX 0
for i in [0:MAX] do
init := init.set! i (i+1)
for i in [0:init₀.size] do
init := init.set! i init₀[i]
let N := init.size
let mut next := Array.mkArray (N + 1) 0
let mut prev := Array.mkArray (N + 1) 0
for i in [0:init.size] do
next := next.set! init[i] init[(i+1)%N]
prev := prev.set! init[(i+1)%N] init[i]
let st := ⟨init[0], next, prev⟩
let after := Nat.repeat step 10000000 st
let a₁ := after.next[1]
let a₂ := after.next[a₁]
IO.print s!"{a₁ * a₂}\n"
|
64e3e7669e7134702e494b08246bc943932fc22f | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/intModBug.lean | d419870087a825f86cb7a33e8a4c2b45c2b731ee | [
"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 | 309 | lean | #reduce (10 : Int) % 0
#reduce (-10 : Int) % 0
#eval (10:Int) % 0
#eval (-10 : Int) % 0
#reduce (10000000000000000000000000000000000 : Int) % 0
#reduce (-10000000000000000000000000000000000 : Int) % 0
#eval (10000000000000000000000000000000000:Int) % 0
#eval (-10000000000000000000000000000000000 : Int) % 0
|
98b3c6328832b805e870b7e7949d4e3d462b7dfc | 26ac254ecb57ffcb886ff709cf018390161a9225 | /src/topology/uniform_space/basic.lean | 431466d08aa7f3af99c6a62e8630cbbb76e38ed6 | [
"Apache-2.0"
] | permissive | eric-wieser/mathlib | 42842584f584359bbe1fc8b88b3ff937c8acd72d | d0df6b81cd0920ad569158c06a3fd5abb9e63301 | refs/heads/master | 1,669,546,404,255 | 1,595,254,668,000 | 1,595,254,668,000 | 281,173,504 | 0 | 0 | Apache-2.0 | 1,595,263,582,000 | 1,595,263,581,000 | null | UTF-8 | Lean | false | false | 69,119 | 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.lift
import topology.separation
/-!
# Uniform spaces
Uniform spaces are a generalization of metric spaces and topological groups. Many concepts directly
generalize to uniform spaces, e.g.
* uniform continuity (in this file)
* completeness (in `cauchy.lean`)
* extension of uniform continuous functions to complete spaces (in `uniform_embedding.lean`)
* totally bounded sets (in `cauchy.lean`)
* totally bounded complete sets are compact (in `cauchy.lean`)
A uniform structure on a type `X` is a filter `𝓤 X` on `X × X` satisfying some conditions
which makes it reasonable to say that `∀ᶠ (p : X × X) in 𝓤 X, ...` means
"for all p.1 and p.2 in X close enough, ...". Elements of this filter are called entourages
of `X`. The two main examples are:
* If `X` is a metric space, `V ∈ 𝓤 X ↔ ∃ ε > 0, { p | dist p.1 p.2 < ε } ⊆ V`
* If `G` is an additive topological group, `V ∈ 𝓤 G ↔ ∃ U ∈ 𝓝 (0 : G), {p | p.2 - p.1 ∈ U} ⊆ V`
Those examples are generalizations in two different directions of the elementary example where
`X = ℝ` and `V ∈ 𝓤 ℝ ↔ ∃ ε > 0, { p | |p.2 - p.1| < ε } ⊆ V` which features both the topological
group structure on `ℝ` and its metric space structure.
Each uniform structure on `X` induces a topology on `X` characterized by
> `nhds_eq_comap_uniformity : ∀ {x : X}, 𝓝 x = comap (prod.mk x) (𝓤 X)`
where `prod.mk x : X → X × X := (λ y, (x, y))` is the partial evaluation of the product
constructor.
The dictionary with metric spaces includes:
* an upper bound for `dist x y` translates into `(x, y) ∈ V` for some `V ∈ 𝓤 X`
* a ball `ball x r` roughly corresponds to `uniform_space.ball x V := {y | (x, y) ∈ V}`
for some `V ∈ 𝓤 X`, but the later is more general (it includes in
particular both open and closed balls for suitable `V`).
In particular we have:
`is_open_iff_ball_subset {s : set X} : is_open s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 X, ball x V ⊆ s`
The triangle inequality is abstracted to a statement involving the composition of relations in `X`.
First note that the triangle inequality in a metric space is equivalent to
`∀ (x y z : X) (r r' : ℝ), dist x y ≤ r → dist y z ≤ r' → dist x z ≤ r + r'`.
Then, for any `V` and `W` with type `set (X × X)`, the composition `V ○ W : set (X × X)` is
defined as `{ p : X × X | ∃ z, (p.1, z) ∈ V ∧ (z, p.2) ∈ W }`.
In the metric space case, if `V = { p | dist p.1 p.2 ≤ r }` and `W = { p | dist p.1 p.2 ≤ r' }`
then the triangle inequality, as reformulated above, says `V ○ W` is contained in
`{p | dist p.1 p.2 ≤ r + r'}` which is the entourage associated to the radius `r + r'`.
In general we have `mem_ball_comp (h : y ∈ ball x V) (h' : z ∈ ball y W) : z ∈ ball x (V ○ W)`.
Note that this discussion does not depend on any axiom imposed on the uniformity filter,
it is simply captured by the definition of composition.
The uniform space axioms ask the filter `𝓤 X` to satisfy the following:
* every `V ∈ 𝓤 X` contains the diagonal `id_rel = { p | p.1 = p.2 }`. This abstracts the fact
that `dist x x ≤ r` for every non-negative radius `r` in the metric space case and also that
`x - x` belongs to every neighborhood of zero in the topological group case.
* `V ∈ 𝓤 X → prod.swap '' V ∈ 𝓤 X`. This is tightly related the fact that `dist x y = dist y x`
in a metric space, and to continuity of negation in the topological group case.
* `∀ V ∈ 𝓤 X, ∃ W ∈ 𝓤 X, W ○ W ⊆ V`. In the metric space case, it corresponds
to cutting the radius of a ball in half and applying the triangle inequality.
In the topological group case, it comes from continuity of addition at `(0, 0)`.
These three axioms are stated more abstractly in the definition below, in terms of
operations on filters, without directly manipulating entourages.
## Main definitions
* `uniform_space X` is a uniform space structure on a type `X`
* `uniform_continuous f` is a predicate saying a function `f : α → β` between uniform spaces
is uniformly continuous : `∀ r ∈ 𝓤 β, ∀ᶠ (x : α × α) in 𝓤 α, (f x.1, f x.2) ∈ r`
In this file we also define a complete lattice structure on the type `uniform_space X`
of uniform structures on `X`, as well as the pullback (`uniform_space.comap`) of uniform structures
coming from the pullback of filters.
Like distance functions, uniform structures cannot be pushed forward in general.
## Notations
Localized in `uniformity`, we have the notation `𝓤 X` for the uniformity on a uniform space `X`,
and `○` for composition of relations, seen as terms with type `set (X × X)`.
## Implementation notes
There is already a theory of relations in `data/rel.lean` where the main definition is
`def rel (α β : Type*) := α → β → Prop`.
The relations used in the current file involve only one type, but this is not the reason why
we don't reuse `data/rel.lean`. We use `set (α × α)`
instead of `rel α α` because we really need sets to use the filter library, and elements
of filters on `α × α` have type `set (α × α)`.
The structure `uniform_space X` bundles a uniform structure on `X`, a topology on `X` and
an assumption saying those are compatible. This may not seem mathematically reasonable at first,
but is in fact an instance of the forgetful inheritance pattern. See Note [forgetful inheritance]
below.
## References
The formalization uses the books:
* [N. Bourbaki, *General Topology*][bourbaki1966]
* [I. M. James, *Topologies and Uniformities*][james1999]
But it makes a more systematic use of the filter library.
-/
open set filter classical
open_locale classical topological_space filter
set_option eqn_compiler.zeta true
universes u
/-!
### Relations, seen as `set (α × α)`
-/
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {ι : Sort*}
/-- The identity relation, or the graph of the identity function -/
def id_rel {α : Type*} := {p : α × α | p.1 = p.2}
@[simp] theorem mem_id_rel {a b : α} : (a, b) ∈ @id_rel α ↔ a = b := iff.rfl
@[simp] theorem id_rel_subset {s : set (α × α)} : id_rel ⊆ s ↔ ∀ a, (a, a) ∈ s :=
by simp [subset_def]; exact forall_congr (λ a, by simp)
/-- The composition of relations -/
def comp_rel {α : Type u} (r₁ r₂ : set (α×α)) := {p : α × α | ∃z:α, (p.1, z) ∈ r₁ ∧ (z, p.2) ∈ r₂}
localized "infix ` ○ `:55 := comp_rel" in uniformity
@[simp] theorem mem_comp_rel {r₁ r₂ : set (α×α)}
{x y : α} : (x, y) ∈ r₁ ○ r₂ ↔ ∃ z, (x, z) ∈ r₁ ∧ (z, y) ∈ r₂ := iff.rfl
@[simp] theorem swap_id_rel : prod.swap '' id_rel = @id_rel α :=
set.ext $ assume ⟨a, b⟩, by simp [image_swap_eq_preimage_swap]; exact eq_comm
theorem monotone_comp_rel [preorder β] {f g : β → set (α×α)}
(hf : monotone f) (hg : monotone g) : monotone (λx, (f x) ○ (g x)) :=
assume a b h p ⟨z, h₁, h₂⟩, ⟨z, hf h h₁, hg h h₂⟩
@[mono]
lemma comp_rel_mono {f g h k: set (α×α)} (h₁ : f ⊆ h) (h₂ : g ⊆ k) : f ○ g ⊆ h ○ k :=
λ ⟨x, y⟩ ⟨z, h, h'⟩, ⟨z, h₁ h, h₂ h'⟩
lemma prod_mk_mem_comp_rel {a b c : α} {s t : set (α×α)} (h₁ : (a, c) ∈ s) (h₂ : (c, b) ∈ t) :
(a, b) ∈ s ○ t :=
⟨c, h₁, h₂⟩
@[simp] lemma id_comp_rel {r : set (α×α)} : id_rel ○ r = r :=
set.ext $ assume ⟨a, b⟩, by simp
lemma comp_rel_assoc {r s t : set (α×α)} :
(r ○ s) ○ t = r ○ (s ○ t) :=
by ext p; cases p; simp only [mem_comp_rel]; tauto
lemma subset_comp_self {α : Type*} {s : set (α × α)} (h : id_rel ⊆ s) : s ⊆ s ○ s :=
λ ⟨x, y⟩ xy_in, ⟨x, h (by rw mem_id_rel), xy_in⟩
/-- The relation is invariant under swapping factors. -/
def symmetric_rel (V : set (α × α)) : Prop := prod.swap ⁻¹' V = V
/-- The maximal symmetric relation contained in a given relation. -/
def symmetrize_rel (V : set (α × α)) : set (α × α) := V ∩ prod.swap ⁻¹' V
lemma symmetric_symmetrize_rel (V : set (α × α)) : symmetric_rel (symmetrize_rel V) :=
by simp [symmetric_rel, symmetrize_rel, preimage_inter, inter_comm, ← preimage_comp]
lemma symmetrize_rel_subset_self (V : set (α × α)) : symmetrize_rel V ⊆ V :=
sep_subset _ _
@[mono]
lemma symmetrize_mono {V W: set (α × α)} (h : V ⊆ W) : symmetrize_rel V ⊆ symmetrize_rel W :=
inter_subset_inter h $ preimage_mono h
lemma symmetric_rel_inter {U V : set (α × α)} (hU : symmetric_rel U) (hV : symmetric_rel V) :
symmetric_rel (U ∩ V) :=
begin
unfold symmetric_rel at *,
rw [preimage_inter, hU, hV],
end
/-- This core description of a uniform space is outside of the type class hierarchy. It is useful
for constructions of uniform spaces, when the topology is derived from the uniform space. -/
structure uniform_space.core (α : Type u) :=
(uniformity : filter (α × α))
(refl : 𝓟 id_rel ≤ uniformity)
(symm : tendsto prod.swap uniformity uniformity)
(comp : uniformity.lift' (λs, s ○ s) ≤ uniformity)
/-- An alternative constructor for `uniform_space.core`. This version unfolds various
`filter`-related definitions. -/
def uniform_space.core.mk' {α : Type u} (U : filter (α × α))
(refl : ∀ (r ∈ U) x, (x, x) ∈ r)
(symm : ∀ r ∈ U, prod.swap ⁻¹' r ∈ U)
(comp : ∀ r ∈ U, ∃ t ∈ U, t ○ t ⊆ r) : uniform_space.core α :=
⟨U, λ r ru, id_rel_subset.2 (refl _ ru), symm,
begin
intros r ru,
rw [mem_lift'_sets],
exact comp _ ru,
apply monotone_comp_rel; exact monotone_id,
end⟩
/-- A uniform space generates a topological space -/
def uniform_space.core.to_topological_space {α : Type u} (u : uniform_space.core α) :
topological_space α :=
{ is_open := λs, ∀x∈s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ u.uniformity,
is_open_univ := by simp; intro; exact univ_mem_sets,
is_open_inter :=
assume s t hs ht x ⟨xs, xt⟩, by filter_upwards [hs x xs, ht x xt]; simp {contextual := tt},
is_open_sUnion :=
assume s hs x ⟨t, ts, xt⟩, by filter_upwards [hs t ts x xt] assume p ph h, ⟨t, ts, ph h⟩ }
lemma uniform_space.core_eq : ∀{u₁ u₂ : uniform_space.core α}, u₁.uniformity = u₂.uniformity → u₁ = u₂
| ⟨u₁, _, _, _⟩ ⟨u₂, _, _, _⟩ h := have u₁ = u₂, from h, by simp [*]
section prio
/-- Suppose that one can put two mathematical structures on a type, a rich one `R` and a poor one
`P`, and that one can deduce the poor structure from the rich structure through a map `F` (called a
forgetful functor) (think `R = metric_space` and `P = topological_space`). A possible
implementation would be to have a type class `rich` containing a field `R`, a type class `poor`
containing a field `P`, and an instance from `rich` to `poor`. However, this creates diamond
problems, and a better approach is to let `rich` extend `poor` and have a field saying that
`F R = P`.
To illustrate this, consider the pair `metric_space` / `topological_space`. Consider the topology
on a product of two metric spaces. With the first approach, it could be obtained by going first from
each metric space to its topology, and then taking the product topology. But it could also be
obtained by considering the product metric space (with its sup distance) and then the topology
coming from this distance. These would be the same topology, but not definitionally, which means
that from the point of view of Lean's kernel, there would be two different `topological_space`
instances on the product. This is not compatible with the way instances are designed and used:
there should be at most one instance of a kind on each type. This approach has created an instance
diamond that does not commute definitionally.
The second approach solves this issue. Now, a metric space contains both a distance, a topology, and
a proof that the topology coincides with the one coming from the distance. When one defines the
product of two metric spaces, one uses the sup distance and the product topology, and one has to
give the proof that the sup distance induces the product topology. Following both sides of the
instance diamond then gives rise (definitionally) to the product topology on the product space.
Another approach would be to have the rich type class take the poor type class as an instance
parameter. It would solve the diamond problem, but it would lead to a blow up of the number
of type classes one would need to declare to work with complicated classes, say a real inner
product space, and would create exponential complexity when working with products of
such complicated spaces, that are avoided by bundling things carefully as above.
Note that this description of this specific case of the product of metric spaces is oversimplified
compared to mathlib, as there is an intermediate typeclass between `metric_space` and
`topological_space` called `uniform_space`. The above scheme is used at both levels, embedding a
topology in the uniform space structure, and a uniform structure in the metric space structure.
Note also that, when `P` is a proposition, there is no such issue as any two proofs of `P` are
definitionally equivalent in Lean.
To avoid boilerplate, there are some designs that can automatically fill the poor fields when
creating a rich structure if one doesn't want to do something special about them. For instance,
in the definition of metric spaces, default tactics fill the uniform space fields if they are
not given explicitly. One can also have a helper function creating the rich structure from a
structure with less fields, where the helper function fills the remaining fields. See for instance
`uniform_space.of_core` or `real_inner_product.of_core`.
For more details on this question, called the forgetful inheritance pattern, see [Competing
inheritance paths in dependent type theory: a case study in functional
analysis](https://hal.inria.fr/hal-02463336).
-/
library_note "forgetful inheritance"
set_option default_priority 100 -- see Note [default priority]
/-- A uniform space is a generalization of the "uniform" topological aspects of a
metric space. It consists of a filter on `α × α` called the "uniformity", which
satisfies properties analogous to the reflexivity, symmetry, and triangle properties
of a metric.
A metric space has a natural uniformity, and a uniform space has a natural topology.
A topological group also has a natural uniformity, even when it is not metrizable. -/
class uniform_space (α : Type u) extends topological_space α, uniform_space.core α :=
(is_open_uniformity : ∀s, is_open s ↔ (∀x∈s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ uniformity))
end prio
/-- Alternative constructor for `uniform_space α` when a topology is already given. -/
@[pattern] def uniform_space.mk' {α} (t : topological_space α)
(c : uniform_space.core α)
(is_open_uniformity : ∀s:set α, t.is_open s ↔
(∀x∈s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ c.uniformity)) :
uniform_space α := ⟨c, is_open_uniformity⟩
/-- Construct a `uniform_space` from a `uniform_space.core`. -/
def uniform_space.of_core {α : Type u} (u : uniform_space.core α) : uniform_space α :=
{ to_core := u,
to_topological_space := u.to_topological_space,
is_open_uniformity := assume a, iff.rfl }
/-- Construct a `uniform_space` from a `u : uniform_space.core` and a `topological_space` structure
that is equal to `u.to_topological_space`. -/
def uniform_space.of_core_eq {α : Type u} (u : uniform_space.core α) (t : topological_space α)
(h : t = u.to_topological_space) : uniform_space α :=
{ to_core := u,
to_topological_space := t,
is_open_uniformity := assume a, h.symm ▸ iff.rfl }
lemma uniform_space.to_core_to_topological_space (u : uniform_space α) :
u.to_core.to_topological_space = u.to_topological_space :=
topological_space_eq $ funext $ assume s,
by rw [uniform_space.core.to_topological_space, uniform_space.is_open_uniformity]
@[ext]
lemma uniform_space_eq : ∀{u₁ u₂ : uniform_space α}, u₁.uniformity = u₂.uniformity → u₁ = u₂
| (uniform_space.mk' t₁ u₁ o₁) (uniform_space.mk' t₂ u₂ o₂) h :=
have u₁ = u₂, from uniform_space.core_eq h,
have t₁ = t₂, from topological_space_eq $ funext $ assume s, by rw [o₁, o₂]; simp [this],
by simp [*]
lemma uniform_space.of_core_eq_to_core
(u : uniform_space α) (t : topological_space α) (h : t = u.to_core.to_topological_space) :
uniform_space.of_core_eq u.to_core t h = u :=
uniform_space_eq rfl
section uniform_space
variables [uniform_space α]
/-- The uniformity is a filter on α × α (inferred from an ambient uniform space
structure on α). -/
def uniformity (α : Type u) [uniform_space α] : filter (α × α) :=
(@uniform_space.to_core α _).uniformity
localized "notation `𝓤` := uniformity" in uniformity
lemma is_open_uniformity {s : set α} :
is_open s ↔ (∀x∈s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ 𝓤 α) :=
uniform_space.is_open_uniformity s
lemma refl_le_uniformity : 𝓟 id_rel ≤ 𝓤 α :=
(@uniform_space.to_core α _).refl
lemma refl_mem_uniformity {x : α} {s : set (α × α)} (h : s ∈ 𝓤 α) :
(x, x) ∈ s :=
refl_le_uniformity h rfl
lemma symm_le_uniformity : map (@prod.swap α α) (𝓤 _) ≤ (𝓤 _) :=
(@uniform_space.to_core α _).symm
lemma comp_le_uniformity : (𝓤 α).lift' (λs:set (α×α), s ○ s) ≤ 𝓤 α :=
(@uniform_space.to_core α _).comp
lemma tendsto_swap_uniformity : tendsto (@prod.swap α α) (𝓤 α) (𝓤 α) :=
symm_le_uniformity
lemma comp_mem_uniformity_sets {s : set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, t ○ t ⊆ s :=
have s ∈ (𝓤 α).lift' (λt:set (α×α), t ○ t),
from comp_le_uniformity hs,
(mem_lift'_sets $ monotone_comp_rel monotone_id monotone_id).mp this
/-- Relation `λ f g, tendsto (λ x, (f x, g x)) l (𝓤 α)` is transitive. -/
lemma filter.tendsto.uniformity_trans {l : filter β} {f₁ f₂ f₃ : β → α}
(h₁₂ : tendsto (λ x, (f₁ x, f₂ x)) l (𝓤 α)) (h₂₃ : tendsto (λ x, (f₂ x, f₃ x)) l (𝓤 α)) :
tendsto (λ x, (f₁ x, f₃ x)) l (𝓤 α) :=
begin
refine le_trans (le_lift' $ λ s hs, mem_map.2 _) comp_le_uniformity,
filter_upwards [h₁₂ hs, h₂₃ hs],
exact λ x hx₁₂ hx₂₃, ⟨_, hx₁₂, hx₂₃⟩
end
/-- Relation `λ f g, tendsto (λ x, (f x, g x)) l (𝓤 α)` is symmetric -/
lemma filter.tendsto.uniformity_symm {l : filter β} {f : β → α × α}
(h : tendsto f l (𝓤 α)) :
tendsto (λ x, ((f x).2, (f x).1)) l (𝓤 α) :=
tendsto_swap_uniformity.comp h
/-- Relation `λ f g, tendsto (λ x, (f x, g x)) l (𝓤 α)` is reflexive. -/
lemma tendsto_diag_uniformity (f : β → α) (l : filter β) :
tendsto (λ x, (f x, f x)) l (𝓤 α) :=
assume s hs, mem_map.2 $ univ_mem_sets' $ λ x, refl_mem_uniformity hs
lemma tendsto_const_uniformity {a : α} {f : filter β} : tendsto (λ _, (a, a)) f (𝓤 α) :=
tendsto_diag_uniformity (λ _, a) f
lemma symm_of_uniformity {s : set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, (∀a b, (a, b) ∈ t → (b, a) ∈ t) ∧ t ⊆ s :=
have preimage prod.swap s ∈ 𝓤 α, from symm_le_uniformity hs,
⟨s ∩ preimage prod.swap s, inter_mem_sets hs this, assume a b ⟨h₁, h₂⟩, ⟨h₂, h₁⟩, inter_subset_left _ _⟩
lemma comp_symm_of_uniformity {s : set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, (∀{a b}, (a, b) ∈ t → (b, a) ∈ t) ∧ t ○ t ⊆ s :=
let ⟨t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs in
let ⟨t', ht', ht'₁, ht'₂⟩ := symm_of_uniformity ht₁ in
⟨t', ht', ht'₁, subset.trans (monotone_comp_rel monotone_id monotone_id ht'₂) ht₂⟩
lemma uniformity_le_symm : 𝓤 α ≤ (@prod.swap α α) <$> 𝓤 α :=
by rw [map_swap_eq_comap_swap];
from map_le_iff_le_comap.1 tendsto_swap_uniformity
lemma uniformity_eq_symm : 𝓤 α = (@prod.swap α α) <$> 𝓤 α :=
le_antisymm uniformity_le_symm symm_le_uniformity
lemma symmetrize_mem_uniformity {V : set (α × α)} (h : V ∈ 𝓤 α) : symmetrize_rel V ∈ 𝓤 α :=
begin
apply (𝓤 α).inter_sets h,
rw [← image_swap_eq_preimage_swap, uniformity_eq_symm],
exact image_mem_map h,
end
theorem uniformity_lift_le_swap {g : set (α×α) → filter β} {f : filter β} (hg : monotone g)
(h : (𝓤 α).lift (λs, g (preimage prod.swap s)) ≤ f) : (𝓤 α).lift g ≤ f :=
calc (𝓤 α).lift g ≤ (filter.map (@prod.swap α α) $ 𝓤 α).lift g :
lift_mono uniformity_le_symm (le_refl _)
... ≤ _ :
by rw [map_lift_eq2 hg, image_swap_eq_preimage_swap]; exact h
lemma uniformity_lift_le_comp {f : set (α×α) → filter β} (h : monotone f) :
(𝓤 α).lift (λs, f (s ○ s)) ≤ (𝓤 α).lift f :=
calc (𝓤 α).lift (λs, f (s ○ s)) =
((𝓤 α).lift' (λs:set (α×α), s ○ s)).lift f :
begin
rw [lift_lift'_assoc],
exact monotone_comp_rel monotone_id monotone_id,
exact h
end
... ≤ (𝓤 α).lift f : lift_mono comp_le_uniformity (le_refl _)
lemma comp_le_uniformity3 :
(𝓤 α).lift' (λs:set (α×α), s ○ (s ○ s)) ≤ (𝓤 α) :=
calc (𝓤 α).lift' (λd, d ○ (d ○ d)) =
(𝓤 α).lift (λs, (𝓤 α).lift' (λt:set(α×α), s ○ (t ○ t))) :
begin
rw [lift_lift'_same_eq_lift'],
exact (assume x, monotone_comp_rel monotone_const $ monotone_comp_rel monotone_id monotone_id),
exact (assume x, monotone_comp_rel monotone_id monotone_const),
end
... ≤ (𝓤 α).lift (λs, (𝓤 α).lift' (λt:set(α×α), s ○ t)) :
lift_mono' $ assume s hs, @uniformity_lift_le_comp α _ _ (𝓟 ∘ (○) s) $
monotone_principal.comp (monotone_comp_rel monotone_const monotone_id)
... = (𝓤 α).lift' (λs:set(α×α), s ○ s) :
lift_lift'_same_eq_lift'
(assume s, monotone_comp_rel monotone_const monotone_id)
(assume s, monotone_comp_rel monotone_id monotone_const)
... ≤ (𝓤 α) : comp_le_uniformity
lemma comp_symm_mem_uniformity_sets {s : set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, symmetric_rel t ∧ t ○ t ⊆ s :=
begin
obtain ⟨w, w_in, w_sub⟩ : ∃ w ∈ 𝓤 α, w ○ w ⊆ s := comp_mem_uniformity_sets hs,
use [symmetrize_rel w, symmetrize_mem_uniformity w_in, symmetric_symmetrize_rel w],
have : symmetrize_rel w ⊆ w := symmetrize_rel_subset_self w,
calc symmetrize_rel w ○ symmetrize_rel w ⊆ w ○ w : by mono
... ⊆ s : w_sub,
end
lemma subset_comp_self_of_mem_uniformity {s : set (α × α)} (h : s ∈ 𝓤 α) : s ⊆ s ○ s :=
subset_comp_self (refl_le_uniformity h)
lemma comp_comp_symm_mem_uniformity_sets {s : set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, symmetric_rel t ∧ t ○ t ○ t ⊆ s :=
begin
rcases comp_symm_mem_uniformity_sets hs with ⟨w, w_in, w_symm, w_sub⟩,
rcases comp_symm_mem_uniformity_sets w_in with ⟨t, t_in, t_symm, t_sub⟩,
use [t, t_in, t_symm],
have : t ⊆ t ○ t := subset_comp_self_of_mem_uniformity t_in,
calc
t ○ t ○ t ⊆ w ○ t : by mono
... ⊆ w ○ (t ○ t) : by mono
... ⊆ w ○ w : by mono
... ⊆ s : w_sub,
end
/-!
### Balls in uniform spaces
-/
/-- The ball around `(x : β)` with respect to `(V : set (β × β))`. Intended to be
used for `V ∈ 𝓤 β`, but this is not needed for the definition. Recovers the
notions of metric space ball when `V = {p | dist p.1 p.2 < r }`. -/
def uniform_space.ball (x : β) (V : set (β × β)) : set β := (prod.mk x) ⁻¹' V
open uniform_space (ball)
/-- The triangle inequality for `uniform_space.ball` -/
lemma mem_ball_comp {V W : set (β × β)} {x y z} (h : y ∈ ball x V) (h' : z ∈ ball y W) :
z ∈ ball x (V ○ W) :=
prod_mk_mem_comp_rel h h'
lemma ball_subset_of_comp_subset {V W : set (β × β)} {x y} (h : x ∈ ball y W) (h' : W ○ W ⊆ V) :
ball x W ⊆ ball y V :=
λ z z_in, h' (mem_ball_comp h z_in)
lemma ball_mono {V W : set (β × β)} (h : V ⊆ W) (x : β) : ball x V ⊆ ball x W :=
by tauto
lemma mem_ball_symmetry {V : set (β × β)} (hV : symmetric_rel V) {x y} :
x ∈ ball y V ↔ y ∈ ball x V :=
show (x, y) ∈ prod.swap ⁻¹' V ↔ (x, y) ∈ V, by { unfold symmetric_rel at hV, rw hV }
lemma ball_eq_of_symmetry {V : set (β × β)} (hV : symmetric_rel V) {x} :
ball x V = {y | (y, x) ∈ V} :=
by { ext y, rw mem_ball_symmetry hV, exact iff.rfl }
lemma mem_comp_of_mem_ball {V W : set (β × β)} {x y z : β} (hV : symmetric_rel V)
(hx : x ∈ ball z V) (hy : y ∈ ball z W) : (x, y) ∈ V ○ W :=
begin
rw mem_ball_symmetry hV at hx,
exact ⟨z, hx, hy⟩
end
lemma mem_comp_comp {V W M : set (β × β)} (hW' : symmetric_rel W) {p : β × β} :
p ∈ V ○ M ○ W ↔ ((ball p.1 V).prod (ball p.2 W) ∩ M).nonempty :=
begin
cases p with x y,
split,
{ rintros ⟨z, ⟨w, hpw, hwz⟩, hzy⟩,
exact ⟨(w, z), ⟨hpw, by rwa mem_ball_symmetry hW'⟩, hwz⟩, },
{ rintro ⟨⟨w, z⟩, ⟨w_in, z_in⟩, hwz⟩,
rwa mem_ball_symmetry hW' at z_in,
use [z, w] ; tauto },
end
/-!
### Neighborhoods in uniform spaces
-/
lemma mem_nhds_uniformity_iff_right {x : α} {s : set α} :
s ∈ 𝓝 x ↔ {p : α × α | p.1 = x → p.2 ∈ s} ∈ 𝓤 α :=
⟨ begin
simp only [mem_nhds_sets_iff, is_open_uniformity, and_imp, exists_imp_distrib],
exact assume t ts ht xt, by filter_upwards [ht x xt] assume ⟨x', y⟩ h eq, ts $ h eq
end,
assume hs,
mem_nhds_sets_iff.mpr ⟨{x | {p : α × α | p.1 = x → p.2 ∈ s} ∈ 𝓤 α},
assume x' hx', refl_mem_uniformity hx' rfl,
is_open_uniformity.mpr $ assume x' hx',
let ⟨t, ht, tr⟩ := comp_mem_uniformity_sets hx' in
by filter_upwards [ht] assume ⟨a, b⟩ hp' (hax' : a = x'),
by filter_upwards [ht] assume ⟨a, b'⟩ hp'' (hab : a = b),
have hp : (x', b) ∈ t, from hax' ▸ hp',
have (b, b') ∈ t, from hab ▸ hp'',
have (x', b') ∈ t ○ t, from ⟨b, hp, this⟩,
show b' ∈ s,
from tr this rfl,
hs⟩⟩
lemma mem_nhds_uniformity_iff_left {x : α} {s : set α} :
s ∈ 𝓝 x ↔ {p : α × α | p.2 = x → p.1 ∈ s} ∈ 𝓤 α :=
by { rw [uniformity_eq_symm, mem_nhds_uniformity_iff_right], refl }
lemma nhds_eq_comap_uniformity_aux {α : Type u} {x : α} {s : set α} {F : filter (α × α)} :
{p : α × α | p.fst = x → p.snd ∈ s} ∈ F ↔ s ∈ comap (prod.mk x) F :=
by rw mem_comap_sets ; from iff.intro
(assume hs, ⟨_, hs, assume x hx, hx rfl⟩)
(assume ⟨t, h, ht⟩, F.sets_of_superset h $
assume ⟨p₁, p₂⟩ hp (h : p₁ = x), ht $ by simp [h.symm, hp])
lemma nhds_eq_comap_uniformity {x : α} : 𝓝 x = (𝓤 α).comap (prod.mk x) :=
by { ext s, rw [mem_nhds_uniformity_iff_right], exact nhds_eq_comap_uniformity_aux }
lemma is_open_iff_ball_subset {s : set α} : is_open s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 α, ball x V ⊆ s :=
begin
simp_rw [is_open_iff_mem_nhds, nhds_eq_comap_uniformity],
exact iff.rfl,
end
lemma nhds_basis_uniformity' {p : β → Prop} {s : β → set (α × α)} (h : (𝓤 α).has_basis p s) {x : α} :
(𝓝 x).has_basis p (λ i, {y | (x, y) ∈ s i}) :=
by { rw [nhds_eq_comap_uniformity], exact h.comap (prod.mk x) }
lemma nhds_basis_uniformity {p : β → Prop} {s : β → set (α × α)} (h : (𝓤 α).has_basis p s) {x : α} :
(𝓝 x).has_basis p (λ i, {y | (y, x) ∈ s i}) :=
begin
replace h := h.comap prod.swap,
rw [← map_swap_eq_comap_swap, ← uniformity_eq_symm] at h,
exact nhds_basis_uniformity' h
end
lemma uniform_space.mem_nhds_iff {x : α} {s : set α} : s ∈ 𝓝 x ↔ ∃ V ∈ 𝓤 α, ball x V ⊆ s :=
begin
rw [nhds_eq_comap_uniformity, mem_comap_sets],
exact iff.rfl,
end
lemma uniform_space.ball_mem_nhds (x : α) ⦃V : set (α × α)⦄ (V_in : V ∈ 𝓤 α) : ball x V ∈ 𝓝 x :=
begin
rw uniform_space.mem_nhds_iff,
exact ⟨V, V_in, subset.refl _⟩
end
lemma uniform_space.mem_nhds_iff_symm {x : α} {s : set α} :
s ∈ 𝓝 x ↔ ∃ V ∈ 𝓤 α, symmetric_rel V ∧ ball x V ⊆ s :=
begin
rw uniform_space.mem_nhds_iff,
split,
{ rintros ⟨V, V_in, V_sub⟩,
use [symmetrize_rel V, symmetrize_mem_uniformity V_in, symmetric_symmetrize_rel V],
exact subset.trans (ball_mono (symmetrize_rel_subset_self V) x) V_sub },
{ rintros ⟨V, V_in, V_symm, V_sub⟩,
exact ⟨V, V_in, V_sub⟩ }
end
lemma uniform_space.has_basis_nhds (x : α) :
has_basis (𝓝 x) (λ s : set (α × α), s ∈ 𝓤 α ∧ symmetric_rel s) (λ s, ball x s) :=
⟨λ t, by simp [uniform_space.mem_nhds_iff_symm, and_assoc]⟩
open uniform_space
lemma uniform_space.has_basis_nhds_prod (x y : α) :
has_basis (𝓝 (x, y)) (λ s, s ∈ 𝓤 α ∧ symmetric_rel s) $ λ s, (ball x s).prod (ball y s) :=
begin
rw nhds_prod_eq,
apply (has_basis_nhds x).prod' (has_basis_nhds y),
rintro U V ⟨U_in, U_symm⟩ ⟨V_in, V_symm⟩,
exact ⟨U ∩ V, ⟨(𝓤 α).inter_sets U_in V_in, symmetric_rel_inter U_symm V_symm⟩,
ball_mono (inter_subset_left U V) x, ball_mono (inter_subset_right U V) y⟩,
end
lemma nhds_eq_uniformity {x : α} : 𝓝 x = (𝓤 α).lift' (λs:set (α×α), {y | (x, y) ∈ s}) :=
(nhds_basis_uniformity' (𝓤 α).basis_sets).eq_binfi
lemma mem_nhds_left (x : α) {s : set (α×α)} (h : s ∈ 𝓤 α) :
{y : α | (x, y) ∈ s} ∈ 𝓝 x :=
(nhds_basis_uniformity' (𝓤 α).basis_sets).mem_of_mem h
lemma mem_nhds_right (y : α) {s : set (α×α)} (h : s ∈ 𝓤 α) :
{x : α | (x, y) ∈ s} ∈ 𝓝 y :=
mem_nhds_left _ (symm_le_uniformity h)
lemma tendsto_right_nhds_uniformity {a : α} : tendsto (λa', (a', a)) (𝓝 a) (𝓤 α) :=
assume s, mem_nhds_right a
lemma tendsto_left_nhds_uniformity {a : α} : tendsto (λa', (a, a')) (𝓝 a) (𝓤 α) :=
assume s, mem_nhds_left a
lemma lift_nhds_left {x : α} {g : set α → filter β} (hg : monotone g) :
(𝓝 x).lift g = (𝓤 α).lift (λs:set (α×α), g {y | (x, y) ∈ s}) :=
eq.trans
begin
rw [nhds_eq_uniformity],
exact (filter.lift_assoc $ monotone_principal.comp $ monotone_preimage.comp monotone_preimage )
end
(congr_arg _ $ funext $ assume s, filter.lift_principal hg)
lemma lift_nhds_right {x : α} {g : set α → filter β} (hg : monotone g) :
(𝓝 x).lift g = (𝓤 α).lift (λs:set (α×α), g {y | (y, x) ∈ s}) :=
calc (𝓝 x).lift g = (𝓤 α).lift (λs:set (α×α), g {y | (x, y) ∈ s}) : lift_nhds_left hg
... = ((@prod.swap α α) <$> (𝓤 α)).lift (λs:set (α×α), g {y | (x, y) ∈ s}) : by rw [←uniformity_eq_symm]
... = (𝓤 α).lift (λs:set (α×α), g {y | (x, y) ∈ image prod.swap s}) :
map_lift_eq2 $ hg.comp monotone_preimage
... = _ : by simp [image_swap_eq_preimage_swap]
lemma nhds_nhds_eq_uniformity_uniformity_prod {a b : α} :
filter.prod (𝓝 a) (𝓝 b) =
(𝓤 α).lift (λs:set (α×α), (𝓤 α).lift' (λt:set (α×α),
set.prod {y : α | (y, a) ∈ s} {y : α | (b, y) ∈ t})) :=
begin
rw [prod_def],
show (𝓝 a).lift (λs:set α, (𝓝 b).lift (λt:set α, 𝓟 (set.prod s t))) = _,
rw [lift_nhds_right],
apply congr_arg, funext s,
rw [lift_nhds_left],
refl,
exact monotone_principal.comp (monotone_prod monotone_const monotone_id),
exact (monotone_lift' monotone_const $ monotone_lam $
assume x, monotone_prod monotone_id monotone_const)
end
lemma nhds_eq_uniformity_prod {a b : α} :
𝓝 (a, b) =
(𝓤 α).lift' (λs:set (α×α), set.prod {y : α | (y, a) ∈ s} {y : α | (b, y) ∈ s}) :=
begin
rw [nhds_prod_eq, nhds_nhds_eq_uniformity_uniformity_prod, lift_lift'_same_eq_lift'],
{ intro s, exact monotone_prod monotone_const monotone_preimage },
{ intro t, exact monotone_prod monotone_preimage monotone_const }
end
lemma nhdset_of_mem_uniformity {d : set (α×α)} (s : set (α×α)) (hd : d ∈ 𝓤 α) :
∃(t : set (α×α)), is_open t ∧ s ⊆ t ∧ t ⊆ {p | ∃x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d} :=
let cl_d := {p:α×α | ∃x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d} in
have ∀p ∈ s, ∃t ⊆ cl_d, is_open t ∧ p ∈ t, from
assume ⟨x, y⟩ hp, mem_nhds_sets_iff.mp $
show cl_d ∈ 𝓝 (x, y),
begin
rw [nhds_eq_uniformity_prod, mem_lift'_sets],
exact ⟨d, hd, assume ⟨a, b⟩ ⟨ha, hb⟩, ⟨x, y, ha, hp, hb⟩⟩,
exact monotone_prod monotone_preimage monotone_preimage
end,
have ∃t:(Π(p:α×α) (h:p ∈ s), set (α×α)),
∀p, ∀h:p ∈ s, t p h ⊆ cl_d ∧ is_open (t p h) ∧ p ∈ t p h,
by simp [classical.skolem] at this; simp; assumption,
match this with
| ⟨t, ht⟩ :=
⟨(⋃ p:α×α, ⋃ h : p ∈ s, t p h : set (α×α)),
is_open_Union $ assume (p:α×α), is_open_Union $ assume hp, (ht p hp).right.left,
assume ⟨a, b⟩ hp, begin simp; exact ⟨a, b, hp, (ht (a,b) hp).right.right⟩ end,
Union_subset $ assume p, Union_subset $ assume hp, (ht p hp).left⟩
end
/-- Entourages are neighborhoods of the diagonal. -/
lemma nhds_le_uniformity : (⨆ x : α, 𝓝 (x, x)) ≤ 𝓤 α :=
begin
apply supr_le _,
intros x V V_in,
rcases comp_symm_mem_uniformity_sets V_in with ⟨w, w_in, w_symm, w_sub⟩,
have : (ball x w).prod (ball x w) ∈ 𝓝 (x, x),
{ rw nhds_prod_eq,
exact prod_mem_prod (ball_mem_nhds x w_in) (ball_mem_nhds x w_in) },
apply mem_sets_of_superset this,
rintros ⟨u, v⟩ ⟨u_in, v_in⟩,
exact w_sub (mem_comp_of_mem_ball w_symm u_in v_in)
end
/-!
### Closure and interior in uniform spaces
-/
lemma closure_eq_uniformity (s : set $ α × α) :
closure s = ⋂ V ∈ {V | V ∈ 𝓤 α ∧ symmetric_rel V}, V ○ s ○ V :=
begin
ext ⟨x, y⟩,
simp_rw [mem_closure_iff_nhds_basis (uniform_space.has_basis_nhds_prod x y),
mem_Inter, mem_set_of_eq],
apply forall_congr,
intro V,
apply forall_congr,
rintros ⟨V_in, V_symm⟩,
simp_rw [mem_comp_comp V_symm, inter_comm, exists_prop],
exact iff.rfl,
end
lemma uniformity_has_basis_closed : has_basis (𝓤 α) (λ V : set (α × α), V ∈ 𝓤 α ∧ is_closed V) id :=
begin
rw filter.has_basis_self,
intro t,
split,
{ intro h,
rcases comp_comp_symm_mem_uniformity_sets h with ⟨w, w_in, w_symm, r⟩,
refine ⟨closure w, _, is_closed_closure, _⟩,
apply mem_sets_of_superset w_in subset_closure,
refine subset.trans _ r,
rw closure_eq_uniformity,
apply Inter_subset_of_subset,
apply Inter_subset,
exact ⟨w_in, w_symm⟩ },
{ rintros ⟨r, r_in, r_closed, r_sub⟩,
exact mem_sets_of_superset r_in r_sub, }
end
/-- Closed entourages form a basis of the uniformity filter. -/
lemma uniformity_has_basis_closure : has_basis (𝓤 α) (λ V : set (α × α), V ∈ 𝓤 α) closure :=
⟨begin
intro t,
rw uniformity_has_basis_closed.mem_iff,
split,
{ rintros ⟨r, ⟨r_in, r_closed⟩, r_sub⟩,
use [r, r_in],
convert r_sub,
rw r_closed.closure_eq,
refl },
{ rintros ⟨r, r_in, r_sub⟩,
exact ⟨closure r, ⟨mem_sets_of_superset r_in subset_closure, is_closed_closure⟩, r_sub⟩ }
end⟩
lemma closure_eq_inter_uniformity {t : set (α×α)} :
closure t = (⋂ d ∈ 𝓤 α, d ○ (t ○ d)) :=
set.ext $ assume ⟨a, b⟩,
calc (a, b) ∈ closure t ↔ (𝓝 (a, b) ⊓ 𝓟 t ≠ ⊥) : mem_closure_iff_cluster_pt
... ↔ (((@prod.swap α α) <$> 𝓤 α).lift'
(λ (s : set (α × α)), set.prod {x : α | (x, a) ∈ s} {y : α | (b, y) ∈ s}) ⊓ 𝓟 t ≠ ⊥) :
by rw [←uniformity_eq_symm, nhds_eq_uniformity_prod]
... ↔ ((map (@prod.swap α α) (𝓤 α)).lift'
(λ (s : set (α × α)), set.prod {x : α | (x, a) ∈ s} {y : α | (b, y) ∈ s}) ⊓ 𝓟 t ≠ ⊥) :
by refl
... ↔ ((𝓤 α).lift'
(λ (s : set (α × α)), set.prod {y : α | (a, y) ∈ s} {x : α | (x, b) ∈ s}) ⊓ 𝓟 t ≠ ⊥) :
begin
rw [map_lift'_eq2],
simp [image_swap_eq_preimage_swap, function.comp],
exact monotone_prod monotone_preimage monotone_preimage
end
... ↔ (∀s ∈ 𝓤 α, (set.prod {y : α | (a, y) ∈ s} {x : α | (x, b) ∈ s} ∩ t).nonempty) :
begin
rw [lift'_inf_principal_eq, ← ne_bot, lift'_ne_bot_iff],
exact monotone_inter (monotone_prod monotone_preimage monotone_preimage) monotone_const
end
... ↔ (∀ s ∈ 𝓤 α, (a, b) ∈ s ○ (t ○ s)) :
forall_congr $ assume s, forall_congr $ assume hs,
⟨assume ⟨⟨x, y⟩, ⟨⟨hx, hy⟩, hxyt⟩⟩, ⟨x, hx, y, hxyt, hy⟩,
assume ⟨x, hx, y, hxyt, hy⟩, ⟨⟨x, y⟩, ⟨⟨hx, hy⟩, hxyt⟩⟩⟩
... ↔ _ : by simp
lemma uniformity_eq_uniformity_closure : 𝓤 α = (𝓤 α).lift' closure :=
le_antisymm
(le_infi $ assume s, le_infi $ assume hs, by simp; filter_upwards [hs] subset_closure)
(calc (𝓤 α).lift' closure ≤ (𝓤 α).lift' (λd, d ○ (d ○ d)) :
lift'_mono' (by intros s hs; rw [closure_eq_inter_uniformity]; exact bInter_subset_of_mem hs)
... ≤ (𝓤 α) : comp_le_uniformity3)
lemma uniformity_eq_uniformity_interior : 𝓤 α = (𝓤 α).lift' interior :=
le_antisymm
(le_infi $ assume d, le_infi $ assume hd,
let ⟨s, hs, hs_comp⟩ := (mem_lift'_sets $
monotone_comp_rel monotone_id $ monotone_comp_rel monotone_id monotone_id).mp (comp_le_uniformity3 hd) in
let ⟨t, ht, hst, ht_comp⟩ := nhdset_of_mem_uniformity s hs in
have s ⊆ interior d, from
calc s ⊆ t : hst
... ⊆ interior d : (subset_interior_iff_subset_of_open ht).mpr $
assume x, assume : x ∈ t, let ⟨x, y, h₁, h₂, h₃⟩ := ht_comp this in hs_comp ⟨x, h₁, y, h₂, h₃⟩,
have interior d ∈ 𝓤 α, by filter_upwards [hs] this,
by simp [this])
(assume s hs, ((𝓤 α).lift' interior).sets_of_superset (mem_lift' hs) interior_subset)
lemma interior_mem_uniformity {s : set (α × α)} (hs : s ∈ 𝓤 α) :
interior s ∈ 𝓤 α :=
by rw [uniformity_eq_uniformity_interior]; exact mem_lift' hs
lemma mem_uniformity_is_closed {s : set (α×α)} (h : s ∈ 𝓤 α) :
∃t ∈ 𝓤 α, is_closed t ∧ t ⊆ s :=
have s ∈ (𝓤 α).lift' closure, by rwa [uniformity_eq_uniformity_closure] at h,
have ∃ t ∈ 𝓤 α, closure t ⊆ s,
by rwa [mem_lift'_sets] at this; apply closure_mono,
let ⟨t, ht, hst⟩ := this in
⟨closure t, (𝓤 α).sets_of_superset ht subset_closure, is_closed_closure, hst⟩
/-!
### Uniformity bases
-/
lemma filter.has_basis.mem_uniformity_iff {p : β → Prop} {s : β → set (α×α)}
(h : (𝓤 α).has_basis p s) {t : set (α × α)} :
t ∈ 𝓤 α ↔ ∃ i (hi : p i), ∀ a b, (a, b) ∈ s i → (a, b) ∈ t :=
h.mem_iff.trans $ by simp only [prod.forall, subset_def]
/-- Symmetric entourages form a basis of `𝓤 α` -/
lemma uniform_space.has_basis_symmetric :
(𝓤 α).has_basis (λ s : set (α × α), s ∈ 𝓤 α ∧ symmetric_rel s) id :=
⟨λ t, ⟨λ t_in, ⟨symmetrize_rel t,
⟨⟨symmetrize_mem_uniformity t_in, symmetric_symmetrize_rel t⟩,
symmetrize_rel_subset_self _⟩⟩,
λ ⟨s, ⟨s_in, h⟩, hst⟩, mem_sets_of_superset s_in hst⟩⟩
lemma uniform_space.has_seq_basis (h : is_countably_generated $ 𝓤 α) :
∃ V : ℕ → set (α × α), has_antimono_basis (𝓤 α) (λ _, true) V ∧ ∀ n, symmetric_rel (V n) :=
begin
rcases h.has_antimono_basis with ⟨U, hbasis, hdec, monotrue⟩, clear monotrue,
simp only [forall_prop_of_true] at hdec,
use λ n, symmetrize_rel (U n),
refine ⟨⟨⟨_⟩, by intros ; mono, by tauto⟩, λ n, symmetric_symmetrize_rel _⟩,
intros t,
rw hbasis.mem_iff,
split,
{ rintro ⟨i, _, hi⟩,
exact ⟨i, trivial, subset.trans (inter_subset_left _ _) hi⟩ },
{ rintro ⟨i, _, hi⟩,
rcases hbasis.mem_iff.mp (symmetrize_mem_uniformity $ hbasis.mem_of_mem trivial)
with ⟨j, _, hj⟩,
use j,
tauto }
end
/-! ### Uniform continuity -/
/-- A function `f : α → β` is *uniformly continuous* if `(f x, f y)` tends to the diagonal
as `(x, y)` tends to the diagonal. In other words, if `x` is sufficiently close to `y`, then
`f x` is close to `f y` no matter where `x` and `y` are located in `α`. -/
def uniform_continuous [uniform_space β] (f : α → β) :=
tendsto (λx:α×α, (f x.1, f x.2)) (𝓤 α) (𝓤 β)
/-- A function `f : α → β` is *uniformly continuous* on `s : set α` if `(f x, f y)` tends to
the diagonal as `(x, y)` tends to the diagonal while remaining in `s.prod s`.
In other words, if `x` is sufficiently close to `y`, then `f x` is close to
`f y` no matter where `x` and `y` are located in `s`.-/
def uniform_continuous_on [uniform_space β] (f : α → β) (s : set α) : Prop :=
tendsto (λ x : α × α, (f x.1, f x.2)) (𝓤 α ⊓ principal (s.prod s)) (𝓤 β)
theorem uniform_continuous_def [uniform_space β] {f : α → β} :
uniform_continuous f ↔ ∀ r ∈ 𝓤 β, { x : α × α | (f x.1, f x.2) ∈ r} ∈ 𝓤 α :=
iff.rfl
theorem uniform_continuous_iff_eventually [uniform_space β] {f : α → β} :
uniform_continuous f ↔ ∀ r ∈ 𝓤 β, ∀ᶠ (x : α × α) in 𝓤 α, (f x.1, f x.2) ∈ r :=
iff.rfl
lemma uniform_continuous_of_const [uniform_space β] {c : α → β} (h : ∀a b, c a = c b) :
uniform_continuous c :=
have (λ (x : α × α), (c (x.fst), c (x.snd))) ⁻¹' id_rel = univ, from
eq_univ_iff_forall.2 $ assume ⟨a, b⟩, h a b,
le_trans (map_le_iff_le_comap.2 $ by simp [comap_principal, this, univ_mem_sets]) refl_le_uniformity
lemma uniform_continuous_id : uniform_continuous (@id α) :=
by simp [uniform_continuous]; exact tendsto_id
lemma uniform_continuous_const [uniform_space β] {b : β} : uniform_continuous (λa:α, b) :=
uniform_continuous_of_const $ λ _ _, rfl
lemma uniform_continuous.comp [uniform_space β] [uniform_space γ] {g : β → γ} {f : α → β}
(hg : uniform_continuous g) (hf : uniform_continuous f) : uniform_continuous (g ∘ f) :=
hg.comp hf
lemma filter.has_basis.uniform_continuous_iff [uniform_space β] {p : γ → Prop} {s : γ → set (α×α)}
(ha : (𝓤 α).has_basis p s) {q : δ → Prop} {t : δ → set (β×β)} (hb : (𝓤 β).has_basis q t)
{f : α → β} :
uniform_continuous f ↔ ∀ i (hi : q i), ∃ j (hj : p j), ∀ x y, (x, y) ∈ s j → (f x, f y) ∈ t i :=
(ha.tendsto_iff hb).trans $ by simp only [prod.forall]
end uniform_space
open_locale uniformity
section constructions
instance : partial_order (uniform_space α) :=
{ le := λt s, t.uniformity ≤ s.uniformity,
le_antisymm := assume t s h₁ h₂, uniform_space_eq $ le_antisymm h₁ h₂,
le_refl := assume t, le_refl _,
le_trans := assume a b c h₁ h₂, le_trans h₁ h₂ }
instance : has_Inf (uniform_space α) :=
⟨assume s, uniform_space.of_core {
uniformity := (⨅u∈s, @uniformity α u),
refl := le_infi $ assume u, le_infi $ assume hu, u.refl,
symm := le_infi $ assume u, le_infi $ assume hu,
le_trans (map_mono $ infi_le_of_le _ $ infi_le _ hu) u.symm,
comp := le_infi $ assume u, le_infi $ assume hu,
le_trans (lift'_mono (infi_le_of_le _ $ infi_le _ hu) $ le_refl _) u.comp }⟩
private lemma Inf_le {tt : set (uniform_space α)} {t : uniform_space α} (h : t ∈ tt) :
Inf tt ≤ t :=
show (⨅u∈tt, @uniformity α u) ≤ t.uniformity,
from infi_le_of_le t $ infi_le _ h
private lemma le_Inf {tt : set (uniform_space α)} {t : uniform_space α} (h : ∀t'∈tt, t ≤ t') :
t ≤ Inf tt :=
show t.uniformity ≤ (⨅u∈tt, @uniformity α u),
from le_infi $ assume t', le_infi $ assume ht', h t' ht'
instance : has_top (uniform_space α) :=
⟨uniform_space.of_core { uniformity := ⊤, refl := le_top, symm := le_top, comp := le_top }⟩
instance : has_bot (uniform_space α) :=
⟨{ to_topological_space := ⊥,
uniformity := 𝓟 id_rel,
refl := le_refl _,
symm := by simp [tendsto]; apply subset.refl,
comp :=
begin
rw [lift'_principal], {simp},
exact monotone_comp_rel monotone_id monotone_id
end,
is_open_uniformity :=
assume s, by simp [is_open_fold, subset_def, id_rel] {contextual := tt } } ⟩
instance : complete_lattice (uniform_space α) :=
{ sup := λa b, Inf {x | a ≤ x ∧ b ≤ x},
le_sup_left := λ a b, le_Inf (λ _ ⟨h, _⟩, h),
le_sup_right := λ a b, le_Inf (λ _ ⟨_, h⟩, h),
sup_le := λ a b c h₁ h₂, Inf_le ⟨h₁, h₂⟩,
inf := λ a b, Inf {a, b},
le_inf := λ a b c h₁ h₂, le_Inf (λ u h,
by { cases h, exact h.symm ▸ h₁, exact (mem_singleton_iff.1 h).symm ▸ h₂ }),
inf_le_left := λ a b, Inf_le (by simp),
inf_le_right := λ a b, Inf_le (by simp),
top := ⊤,
le_top := λ a, show a.uniformity ≤ ⊤, from le_top,
bot := ⊥,
bot_le := λ u, u.refl,
Sup := λ tt, Inf {t | ∀ t' ∈ tt, t' ≤ t},
le_Sup := λ s u h, le_Inf (λ u' h', h' u h),
Sup_le := λ s u h, Inf_le h,
Inf := Inf,
le_Inf := λ s a hs, le_Inf hs,
Inf_le := λ s a ha, Inf_le ha,
..uniform_space.partial_order }
lemma infi_uniformity {ι : Sort*} {u : ι → uniform_space α} :
(infi u).uniformity = (⨅i, (u i).uniformity) :=
show (⨅a (h : ∃i:ι, u i = a), a.uniformity) = _, from
le_antisymm
(le_infi $ assume i, infi_le_of_le (u i) $ infi_le _ ⟨i, rfl⟩)
(le_infi $ assume a, le_infi $ assume ⟨i, (ha : u i = a)⟩, ha ▸ infi_le _ _)
lemma inf_uniformity {u v : uniform_space α} :
(u ⊓ v).uniformity = u.uniformity ⊓ v.uniformity :=
have (u ⊓ v) = (⨅i (h : i = u ∨ i = v), i), by simp [infi_or, infi_inf_eq],
calc (u ⊓ v).uniformity = ((⨅i (h : i = u ∨ i = v), i) : uniform_space α).uniformity : by rw [this]
... = _ : by simp [infi_uniformity, infi_or, infi_inf_eq]
instance inhabited_uniform_space : inhabited (uniform_space α) := ⟨⊥⟩
instance inhabited_uniform_space_core : inhabited (uniform_space.core α) :=
⟨@uniform_space.to_core _ (default _)⟩
/-- Given `f : α → β` and a uniformity `u` on `β`, the inverse image of `u` under `f`
is the inverse image in the filter sense of the induced function `α × α → β × β`. -/
def uniform_space.comap (f : α → β) (u : uniform_space β) : uniform_space α :=
{ uniformity := u.uniformity.comap (λp:α×α, (f p.1, f p.2)),
to_topological_space := u.to_topological_space.induced f,
refl := le_trans (by simp; exact assume ⟨a, b⟩ (h : a = b), h ▸ rfl) (comap_mono u.refl),
symm := by simp [tendsto_comap_iff, prod.swap, (∘)]; exact tendsto_swap_uniformity.comp tendsto_comap,
comp := le_trans
begin
rw [comap_lift'_eq, comap_lift'_eq2],
exact (lift'_mono' $ assume s hs ⟨a₁, a₂⟩ ⟨x, h₁, h₂⟩, ⟨f x, h₁, h₂⟩),
repeat { exact monotone_comp_rel monotone_id monotone_id }
end
(comap_mono u.comp),
is_open_uniformity := λ s, begin
change (@is_open α (u.to_topological_space.induced f) s ↔ _),
simp [is_open_iff_nhds, nhds_induced, mem_nhds_uniformity_iff_right, filter.comap, and_comm],
refine ball_congr (λ x hx, ⟨_, _⟩),
{ rintro ⟨t, hts, ht⟩, refine ⟨_, ht, _⟩,
rintro ⟨x₁, x₂⟩ h rfl, exact hts (h rfl) },
{ rintro ⟨t, ht, hts⟩,
exact ⟨{y | (f x, y) ∈ t}, λ y hy, @hts (x, y) hy rfl,
mem_nhds_uniformity_iff_right.1 $ mem_nhds_left _ ht⟩ }
end }
lemma uniformity_comap [uniform_space α] [uniform_space β] {f : α → β}
(h : ‹uniform_space α› = uniform_space.comap f ‹uniform_space β›) :
𝓤 α = comap (prod.map f f) (𝓤 β) :=
by { rw h, refl }
lemma uniform_space_comap_id {α : Type*} : uniform_space.comap (id : α → α) = id :=
by ext u ; dsimp [uniform_space.comap] ; rw [prod.id_prod, filter.comap_id]
lemma uniform_space.comap_comap {α β γ} [uγ : uniform_space γ] {f : α → β} {g : β → γ} :
uniform_space.comap (g ∘ f) uγ = uniform_space.comap f (uniform_space.comap g uγ) :=
by ext ; dsimp [uniform_space.comap] ; rw filter.comap_comap
lemma uniform_continuous_iff {α β} [uα : uniform_space α] [uβ : uniform_space β] {f : α → β} :
uniform_continuous f ↔ uα ≤ uβ.comap f :=
filter.map_le_iff_le_comap
lemma uniform_continuous_comap {f : α → β} [u : uniform_space β] :
@uniform_continuous α β (uniform_space.comap f u) u f :=
tendsto_comap
theorem to_topological_space_comap {f : α → β} {u : uniform_space β} :
@uniform_space.to_topological_space _ (uniform_space.comap f u) =
topological_space.induced f (@uniform_space.to_topological_space β u) := rfl
lemma uniform_continuous_comap' {f : γ → β} {g : α → γ} [v : uniform_space β] [u : uniform_space α]
(h : uniform_continuous (f ∘ g)) : @uniform_continuous α γ u (uniform_space.comap f v) g :=
tendsto_comap_iff.2 h
lemma to_topological_space_mono {u₁ u₂ : uniform_space α} (h : u₁ ≤ u₂) :
@uniform_space.to_topological_space _ u₁ ≤ @uniform_space.to_topological_space _ u₂ :=
le_of_nhds_le_nhds $ assume a,
by rw [@nhds_eq_uniformity α u₁ a, @nhds_eq_uniformity α u₂ a]; exact (lift'_mono h $ le_refl _)
lemma uniform_continuous.continuous [uniform_space α] [uniform_space β] {f : α → β}
(hf : uniform_continuous f) : continuous f :=
continuous_iff_le_induced.mpr $ to_topological_space_mono $ uniform_continuous_iff.1 hf
lemma to_topological_space_bot : @uniform_space.to_topological_space α ⊥ = ⊥ := rfl
lemma to_topological_space_top : @uniform_space.to_topological_space α ⊤ = ⊤ :=
top_unique $ assume s hs, s.eq_empty_or_nonempty.elim
(assume : s = ∅, this.symm ▸ @is_open_empty _ ⊤)
(assume ⟨x, hx⟩,
have s = univ, from top_unique $ assume y hy, hs x hx (x, y) rfl,
this.symm ▸ @is_open_univ _ ⊤)
lemma to_topological_space_infi {ι : Sort*} {u : ι → uniform_space α} :
(infi u).to_topological_space = ⨅i, (u i).to_topological_space :=
classical.by_cases
(assume h : nonempty ι,
eq_of_nhds_eq_nhds $ assume a,
begin
rw [nhds_infi, nhds_eq_uniformity],
change (infi u).uniformity.lift' (preimage $ prod.mk a) = _,
begin
rw [infi_uniformity, lift'_infi],
exact (congr_arg _ $ funext $ assume i, (@nhds_eq_uniformity α (u i) a).symm),
exact h,
exact assume a b, rfl
end
end)
(assume : ¬ nonempty ι,
le_antisymm
(le_infi $ assume i, to_topological_space_mono $ infi_le _ _)
(have infi u = ⊤, from top_unique $ le_infi $ assume i, (this ⟨i⟩).elim,
have @uniform_space.to_topological_space _ (infi u) = ⊤,
from this.symm ▸ to_topological_space_top,
this.symm ▸ le_top))
lemma to_topological_space_Inf {s : set (uniform_space α)} :
(Inf s).to_topological_space = (⨅i∈s, @uniform_space.to_topological_space α i) :=
begin
rw [Inf_eq_infi, to_topological_space_infi],
apply congr rfl,
funext x,
exact to_topological_space_infi
end
lemma to_topological_space_inf {u v : uniform_space α} :
(u ⊓ v).to_topological_space = u.to_topological_space ⊓ v.to_topological_space :=
by rw [to_topological_space_Inf, infi_pair]
instance : uniform_space empty := ⊥
instance : uniform_space unit := ⊥
instance : uniform_space bool := ⊥
instance : uniform_space ℕ := ⊥
instance : uniform_space ℤ := ⊥
instance {p : α → Prop} [t : uniform_space α] : uniform_space (subtype p) :=
uniform_space.comap subtype.val t
lemma uniformity_subtype {p : α → Prop} [t : uniform_space α] :
𝓤 (subtype p) = comap (λq:subtype p × subtype p, (q.1.1, q.2.1)) (𝓤 α) :=
rfl
lemma uniform_continuous_subtype_val {p : α → Prop} [uniform_space α] :
uniform_continuous (subtype.val : {a : α // p a} → α) :=
uniform_continuous_comap
lemma uniform_continuous_subtype_mk {p : α → Prop} [uniform_space α] [uniform_space β]
{f : β → α} (hf : uniform_continuous f) (h : ∀x, p (f x)) :
uniform_continuous (λx, ⟨f x, h x⟩ : β → subtype p) :=
uniform_continuous_comap' hf
lemma uniform_continuous_on_iff_restrict [uniform_space α] [uniform_space β] (f : α → β) (s : set α) :
uniform_continuous_on f s ↔ uniform_continuous (s.restrict f) :=
begin
unfold uniform_continuous_on set.restrict uniform_continuous tendsto,
rw [show (λ x : s × s, (f x.1, f x.2)) = prod.map f f ∘ coe, by ext x; cases x; refl,
uniformity_comap rfl,
show prod.map subtype.val subtype.val = (coe : s × s → α × α), by ext x; cases x; refl],
conv in (map _ (comap _ _)) { rw ← filter.map_map },
rw subtype_coe_map_comap_prod, refl,
end
lemma tendsto_of_uniform_continuous_subtype
[uniform_space α] [uniform_space β] {f : α → β} {s : set α} {a : α}
(hf : uniform_continuous (λx:s, f x.val)) (ha : s ∈ 𝓝 a) :
tendsto f (𝓝 a) (𝓝 (f a)) :=
by rw [(@map_nhds_subtype_coe_eq α _ s a (mem_of_nhds ha) ha).symm]; exact
tendsto_map' (continuous_iff_continuous_at.mp hf.continuous _)
section prod
/- a similar product space is possible on the function space (uniformity of pointwise convergence),
but we want to have the uniformity of uniform convergence on function spaces -/
instance [u₁ : uniform_space α] [u₂ : uniform_space β] : uniform_space (α × β) :=
uniform_space.of_core_eq
(u₁.comap prod.fst ⊓ u₂.comap prod.snd).to_core
prod.topological_space
(calc prod.topological_space = (u₁.comap prod.fst ⊓ u₂.comap prod.snd).to_topological_space :
by rw [to_topological_space_inf, to_topological_space_comap, to_topological_space_comap]; refl
... = _ : by rw [uniform_space.to_core_to_topological_space])
theorem uniformity_prod [uniform_space α] [uniform_space β] : 𝓤 (α × β) =
(𝓤 α).comap (λp:(α × β) × α × β, (p.1.1, p.2.1)) ⊓
(𝓤 β).comap (λp:(α × β) × α × β, (p.1.2, p.2.2)) :=
inf_uniformity
lemma uniformity_prod_eq_prod [uniform_space α] [uniform_space β] :
𝓤 (α×β) =
map (λp:(α×α)×(β×β), ((p.1.1, p.2.1), (p.1.2, p.2.2))) (filter.prod (𝓤 α) (𝓤 β)) :=
have map (λp:(α×α)×(β×β), ((p.1.1, p.2.1), (p.1.2, p.2.2))) =
comap (λp:(α×β)×(α×β), ((p.1.1, p.2.1), (p.1.2, p.2.2))),
from funext $ assume f, map_eq_comap_of_inverse
(funext $ assume ⟨⟨_, _⟩, ⟨_, _⟩⟩, rfl) (funext $ assume ⟨⟨_, _⟩, ⟨_, _⟩⟩, rfl),
by rw [this, uniformity_prod, filter.prod, comap_inf, comap_comap, comap_comap]
lemma mem_map_sets_iff' {α : Type*} {β : Type*} {f : filter α} {m : α → β} {t : set β} :
t ∈ (map m f).sets ↔ (∃s∈f, m '' s ⊆ t) :=
mem_map_sets_iff
lemma mem_uniformity_of_uniform_continuous_invariant [uniform_space α] {s:set (α×α)} {f : α → α → α}
(hf : uniform_continuous (λp:α×α, f p.1 p.2)) (hs : s ∈ 𝓤 α) :
∃u∈𝓤 α, ∀a b c, (a, b) ∈ u → (f a c, f b c) ∈ s :=
begin
rw [uniform_continuous, uniformity_prod_eq_prod, tendsto_map'_iff, (∘)] at hf,
rcases mem_map_sets_iff'.1 (hf hs) with ⟨t, ht, hts⟩, clear hf,
rcases mem_prod_iff.1 ht with ⟨u, hu, v, hv, huvt⟩, clear ht,
refine ⟨u, hu, assume a b c hab, hts $ (mem_image _ _ _).2 ⟨⟨⟨a, b⟩, ⟨c, c⟩⟩, huvt ⟨_, _⟩, _⟩⟩,
exact hab,
exact refl_mem_uniformity hv,
refl
end
lemma mem_uniform_prod [t₁ : uniform_space α] [t₂ : uniform_space β] {a : set (α × α)} {b : set (β × β)}
(ha : a ∈ 𝓤 α) (hb : b ∈ 𝓤 β) :
{p:(α×β)×(α×β) | (p.1.1, p.2.1) ∈ a ∧ (p.1.2, p.2.2) ∈ b } ∈ (@uniformity (α × β) _) :=
by rw [uniformity_prod]; exact inter_mem_inf_sets (preimage_mem_comap ha) (preimage_mem_comap hb)
lemma tendsto_prod_uniformity_fst [uniform_space α] [uniform_space β] :
tendsto (λp:(α×β)×(α×β), (p.1.1, p.2.1)) (𝓤 (α × β)) (𝓤 α) :=
le_trans (map_mono (@inf_le_left (uniform_space (α×β)) _ _ _)) map_comap_le
lemma tendsto_prod_uniformity_snd [uniform_space α] [uniform_space β] :
tendsto (λp:(α×β)×(α×β), (p.1.2, p.2.2)) (𝓤 (α × β)) (𝓤 β) :=
le_trans (map_mono (@inf_le_right (uniform_space (α×β)) _ _ _)) map_comap_le
lemma uniform_continuous_fst [uniform_space α] [uniform_space β] : uniform_continuous (λp:α×β, p.1) :=
tendsto_prod_uniformity_fst
lemma uniform_continuous_snd [uniform_space α] [uniform_space β] : uniform_continuous (λp:α×β, p.2) :=
tendsto_prod_uniformity_snd
variables [uniform_space α] [uniform_space β] [uniform_space γ]
lemma uniform_continuous.prod_mk
{f₁ : α → β} {f₂ : α → γ} (h₁ : uniform_continuous f₁) (h₂ : uniform_continuous f₂) :
uniform_continuous (λa, (f₁ a, f₂ a)) :=
by rw [uniform_continuous, uniformity_prod]; exact
tendsto_inf.2 ⟨tendsto_comap_iff.2 h₁, tendsto_comap_iff.2 h₂⟩
lemma uniform_continuous.prod_mk_left {f : α × β → γ} (h : uniform_continuous f) (b) :
uniform_continuous (λ a, f (a,b)) :=
h.comp (uniform_continuous_id.prod_mk uniform_continuous_const)
lemma uniform_continuous.prod_mk_right {f : α × β → γ} (h : uniform_continuous f) (a) :
uniform_continuous (λ b, f (a,b)) :=
h.comp (uniform_continuous_const.prod_mk uniform_continuous_id)
lemma uniform_continuous.prod_map [uniform_space δ] {f : α → γ} {g : β → δ}
(hf : uniform_continuous f) (hg : uniform_continuous g) :
uniform_continuous (prod.map f g) :=
(hf.comp uniform_continuous_fst).prod_mk (hg.comp uniform_continuous_snd)
lemma to_topological_space_prod {α} {β} [u : uniform_space α] [v : uniform_space β] :
@uniform_space.to_topological_space (α × β) prod.uniform_space =
@prod.topological_space α β u.to_topological_space v.to_topological_space := rfl
end prod
section
open uniform_space function
variables {δ' : Type*} [uniform_space α] [uniform_space β] [uniform_space γ] [uniform_space δ]
[uniform_space δ']
local notation f `∘₂` g := function.bicompr f g
/-- Uniform continuity for functions of two variables. -/
def uniform_continuous₂ (f : α → β → γ) := uniform_continuous (uncurry f)
lemma uniform_continuous₂_def (f : α → β → γ) :
uniform_continuous₂ f ↔ uniform_continuous (uncurry f) := iff.rfl
lemma uniform_continuous₂.uniform_continuous {f : α → β → γ} (h : uniform_continuous₂ f) :
uniform_continuous (uncurry f) := h
lemma uniform_continuous₂_curry (f : α × β → γ) :
uniform_continuous₂ (function.curry f) ↔ uniform_continuous f :=
by rw [uniform_continuous₂, uncurry_curry]
lemma uniform_continuous₂.comp {f : α → β → γ} {g : γ → δ}
(hg : uniform_continuous g) (hf : uniform_continuous₂ f) :
uniform_continuous₂ (g ∘₂ f) :=
hg.comp hf
lemma uniform_continuous₂.bicompl {f : α → β → γ} {ga : δ → α} {gb : δ' → β}
(hf : uniform_continuous₂ f) (hga : uniform_continuous ga) (hgb : uniform_continuous gb) :
uniform_continuous₂ (bicompl f ga gb) :=
hf.uniform_continuous.comp (hga.prod_map hgb)
end
lemma to_topological_space_subtype [u : uniform_space α] {p : α → Prop} :
@uniform_space.to_topological_space (subtype p) subtype.uniform_space =
@subtype.topological_space α p u.to_topological_space := rfl
section sum
variables [uniform_space α] [uniform_space β]
open sum
/-- Uniformity on a disjoint union. Entourages of the diagonal in the union are obtained
by taking independently an entourage of the diagonal in the first part, and an entourage of
the diagonal in the second part. -/
def uniform_space.core.sum : uniform_space.core (α ⊕ β) :=
uniform_space.core.mk'
(map (λ p : α × α, (inl p.1, inl p.2)) (𝓤 α) ⊔ map (λ p : β × β, (inr p.1, inr p.2)) (𝓤 β))
(λ r ⟨H₁, H₂⟩ x, by cases x; [apply refl_mem_uniformity H₁, apply refl_mem_uniformity H₂])
(λ r ⟨H₁, H₂⟩, ⟨symm_le_uniformity H₁, symm_le_uniformity H₂⟩)
(λ r ⟨Hrα, Hrβ⟩, begin
rcases comp_mem_uniformity_sets Hrα with ⟨tα, htα, Htα⟩,
rcases comp_mem_uniformity_sets Hrβ with ⟨tβ, htβ, Htβ⟩,
refine ⟨_,
⟨mem_map_sets_iff.2 ⟨tα, htα, subset_union_left _ _⟩,
mem_map_sets_iff.2 ⟨tβ, htβ, subset_union_right _ _⟩⟩, _⟩,
rintros ⟨_, _⟩ ⟨z, ⟨⟨a, b⟩, hab, ⟨⟩⟩ | ⟨⟨a, b⟩, hab, ⟨⟩⟩,
⟨⟨_, c⟩, hbc, ⟨⟩⟩ | ⟨⟨_, c⟩, hbc, ⟨⟩⟩⟩,
{ have A : (a, c) ∈ tα ○ tα := ⟨b, hab, hbc⟩,
exact Htα A },
{ have A : (a, c) ∈ tβ ○ tβ := ⟨b, hab, hbc⟩,
exact Htβ A }
end)
/-- The union of an entourage of the diagonal in each set of a disjoint union is again an entourage
of the diagonal. -/
lemma union_mem_uniformity_sum
{a : set (α × α)} (ha : a ∈ 𝓤 α) {b : set (β × β)} (hb : b ∈ 𝓤 β) :
((λ p : (α × α), (inl p.1, inl p.2)) '' a ∪ (λ p : (β × β), (inr p.1, inr p.2)) '' b) ∈
(@uniform_space.core.sum α β _ _).uniformity :=
⟨mem_map_sets_iff.2 ⟨_, ha, subset_union_left _ _⟩, mem_map_sets_iff.2 ⟨_, hb, subset_union_right _ _⟩⟩
/- To prove that the topology defined by the uniform structure on the disjoint union coincides with
the disjoint union topology, we need two lemmas saying that open sets can be characterized by
the uniform structure -/
lemma uniformity_sum_of_open_aux {s : set (α ⊕ β)} (hs : is_open s) {x : α ⊕ β} (xs : x ∈ s) :
{ p : ((α ⊕ β) × (α ⊕ β)) | p.1 = x → p.2 ∈ s } ∈ (@uniform_space.core.sum α β _ _).uniformity :=
begin
cases x,
{ refine mem_sets_of_superset
(union_mem_uniformity_sum (mem_nhds_uniformity_iff_right.1 (mem_nhds_sets hs.1 xs)) univ_mem_sets)
(union_subset _ _);
rintro _ ⟨⟨_, b⟩, h, ⟨⟩⟩ ⟨⟩,
exact h rfl },
{ refine mem_sets_of_superset
(union_mem_uniformity_sum univ_mem_sets (mem_nhds_uniformity_iff_right.1 (mem_nhds_sets hs.2 xs)))
(union_subset _ _);
rintro _ ⟨⟨a, _⟩, h, ⟨⟩⟩ ⟨⟩,
exact h rfl },
end
lemma open_of_uniformity_sum_aux {s : set (α ⊕ β)}
(hs : ∀x ∈ s, { p : ((α ⊕ β) × (α ⊕ β)) | p.1 = x → p.2 ∈ s } ∈ (@uniform_space.core.sum α β _ _).uniformity) :
is_open s :=
begin
split,
{ refine (@is_open_iff_mem_nhds α _ _).2 (λ a ha, mem_nhds_uniformity_iff_right.2 _),
rcases mem_map_sets_iff.1 (hs _ ha).1 with ⟨t, ht, st⟩,
refine mem_sets_of_superset ht _,
rintro p pt rfl, exact st ⟨_, pt, rfl⟩ rfl },
{ refine (@is_open_iff_mem_nhds β _ _).2 (λ b hb, mem_nhds_uniformity_iff_right.2 _),
rcases mem_map_sets_iff.1 (hs _ hb).2 with ⟨t, ht, st⟩,
refine mem_sets_of_superset ht _,
rintro p pt rfl, exact st ⟨_, pt, rfl⟩ rfl }
end
/- We can now define the uniform structure on the disjoint union -/
instance sum.uniform_space : uniform_space (α ⊕ β) :=
{ to_core := uniform_space.core.sum,
is_open_uniformity := λ s, ⟨uniformity_sum_of_open_aux, open_of_uniformity_sum_aux⟩ }
lemma sum.uniformity : 𝓤 (α ⊕ β) =
map (λ p : α × α, (inl p.1, inl p.2)) (𝓤 α) ⊔
map (λ p : β × β, (inr p.1, inr p.2)) (𝓤 β) := rfl
end sum
end constructions
-- For a version of the Lebesgue number lemma assuming only a sequentially compact space,
-- see topology/sequences.lean
lemma lebesgue_number_lemma {α : Type u} [uniform_space α] {s : set α} {ι} {c : ι → set α}
(hs : is_compact s) (hc₁ : ∀ i, is_open (c i)) (hc₂ : s ⊆ ⋃ i, c i) :
∃ n ∈ 𝓤 α, ∀ x ∈ s, ∃ i, {y | (x, y) ∈ n} ⊆ c i :=
begin
let u := λ n, {x | ∃ i (m ∈ 𝓤 α), {y | (x, y) ∈ m ○ n} ⊆ c i},
have hu₁ : ∀ n ∈ 𝓤 α, is_open (u n),
{ refine λ n hn, is_open_uniformity.2 _,
rintro x ⟨i, m, hm, h⟩,
rcases comp_mem_uniformity_sets hm with ⟨m', hm', mm'⟩,
apply (𝓤 α).sets_of_superset hm',
rintros ⟨x, y⟩ hp rfl,
refine ⟨i, m', hm', λ z hz, h (monotone_comp_rel monotone_id monotone_const mm' _)⟩,
dsimp at hz ⊢, rw comp_rel_assoc,
exact ⟨y, hp, hz⟩ },
have hu₂ : s ⊆ ⋃ n ∈ 𝓤 α, u n,
{ intros x hx,
rcases mem_Union.1 (hc₂ hx) with ⟨i, h⟩,
rcases comp_mem_uniformity_sets (is_open_uniformity.1 (hc₁ i) x h) with ⟨m', hm', mm'⟩,
exact mem_bUnion hm' ⟨i, _, hm', λ y hy, mm' hy rfl⟩ },
rcases hs.elim_finite_subcover_image hu₁ hu₂ with ⟨b, bu, b_fin, b_cover⟩,
refine ⟨_, Inter_mem_sets b_fin bu, λ x hx, _⟩,
rcases mem_bUnion_iff.1 (b_cover hx) with ⟨n, bn, i, m, hm, h⟩,
refine ⟨i, λ y hy, h _⟩,
exact prod_mk_mem_comp_rel (refl_mem_uniformity hm) (bInter_subset_of_mem bn hy)
end
lemma lebesgue_number_lemma_sUnion {α : Type u} [uniform_space α] {s : set α} {c : set (set α)}
(hs : is_compact s) (hc₁ : ∀ t ∈ c, is_open t) (hc₂ : s ⊆ ⋃₀ c) :
∃ n ∈ 𝓤 α, ∀ x ∈ s, ∃ t ∈ c, ∀ y, (x, y) ∈ n → y ∈ t :=
by rw sUnion_eq_Union at hc₂;
simpa using lebesgue_number_lemma hs (by simpa) hc₂
/-!
### Expressing continuity properties in uniform spaces
We reformulate the various continuity properties of functions taking values in a uniform space
in terms of the uniformity in the target. Since the same lemmas (essentially with the same names)
also exist for metric spaces and emetric spaces (reformulating things in terms of the distance or
the edistance in the target), we put them in a namespace `uniform` here.
In the metric and emetric space setting, there are also similar lemmas where one assumes that
both the source and the target are metric spaces, reformulating things in terms of the distance
on both sides. These lemmas are generally written without primes, and the versions where only
the target is a metric space is primed. We follow the same convention here, thus giving lemmas
with primes.
-/
namespace uniform
variables [uniform_space α]
theorem tendsto_nhds_right {f : filter β} {u : β → α} {a : α} :
tendsto u f (𝓝 a) ↔ tendsto (λ x, (a, u x)) f (𝓤 α) :=
⟨λ H, tendsto_left_nhds_uniformity.comp H,
λ H s hs, by simpa [mem_of_nhds hs] using H (mem_nhds_uniformity_iff_right.1 hs)⟩
theorem tendsto_nhds_left {f : filter β} {u : β → α} {a : α} :
tendsto u f (𝓝 a) ↔ tendsto (λ x, (u x, a)) f (𝓤 α) :=
⟨λ H, tendsto_right_nhds_uniformity.comp H,
λ H s hs, by simpa [mem_of_nhds hs] using H (mem_nhds_uniformity_iff_left.1 hs)⟩
theorem continuous_at_iff'_right [topological_space β] {f : β → α} {b : β} :
continuous_at f b ↔ tendsto (λ x, (f b, f x)) (𝓝 b) (𝓤 α) :=
by rw [continuous_at, tendsto_nhds_right]
theorem continuous_at_iff'_left [topological_space β] {f : β → α} {b : β} :
continuous_at f b ↔ tendsto (λ x, (f x, f b)) (𝓝 b) (𝓤 α) :=
by rw [continuous_at, tendsto_nhds_left]
theorem continuous_within_at_iff'_right [topological_space β] {f : β → α} {b : β} {s : set β} :
continuous_within_at f s b ↔ tendsto (λ x, (f b, f x)) (nhds_within b s) (𝓤 α) :=
by rw [continuous_within_at, tendsto_nhds_right]
theorem continuous_within_at_iff'_left [topological_space β] {f : β → α} {b : β} {s : set β} :
continuous_within_at f s b ↔ tendsto (λ x, (f x, f b)) (nhds_within b s) (𝓤 α) :=
by rw [continuous_within_at, tendsto_nhds_left]
theorem continuous_on_iff'_right [topological_space β] {f : β → α} {s : set β} :
continuous_on f s ↔ ∀ b ∈ s, tendsto (λ x, (f b, f x)) (nhds_within b s) (𝓤 α) :=
by simp [continuous_on, continuous_within_at_iff'_right]
theorem continuous_on_iff'_left [topological_space β] {f : β → α} {s : set β} :
continuous_on f s ↔ ∀ b ∈ s, tendsto (λ x, (f x, f b)) (nhds_within b s) (𝓤 α) :=
by simp [continuous_on, continuous_within_at_iff'_left]
theorem continuous_iff'_right [topological_space β] {f : β → α} :
continuous f ↔ ∀ b, tendsto (λ x, (f b, f x)) (𝓝 b) (𝓤 α) :=
continuous_iff_continuous_at.trans $ forall_congr $ λ b, tendsto_nhds_right
theorem continuous_iff'_left [topological_space β] {f : β → α} :
continuous f ↔ ∀ b, tendsto (λ x, (f x, f b)) (𝓝 b) (𝓤 α) :=
continuous_iff_continuous_at.trans $ forall_congr $ λ b, tendsto_nhds_left
end uniform
lemma filter.tendsto.congr_uniformity {α β} [uniform_space β] {f g : α → β} {l : filter α} {b : β}
(hf : tendsto f l (𝓝 b)) (hg : tendsto (λ x, (f x, g x)) l (𝓤 β)) :
tendsto g l (𝓝 b) :=
uniform.tendsto_nhds_right.2 $ (uniform.tendsto_nhds_right.1 hf).uniformity_trans hg
lemma uniform.tendsto_congr {α β} [uniform_space β] {f g : α → β} {l : filter α} {b : β}
(hfg : tendsto (λ x, (f x, g x)) l (𝓤 β)) :
tendsto f l (𝓝 b) ↔ tendsto g l (𝓝 b) :=
⟨λ h, h.congr_uniformity hfg, λ h, h.congr_uniformity hfg.uniformity_symm⟩
|
3ea4c1348cbdd1ec277dcf329ed18393f198833e | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/topology/order/lattice.lean | d23ca1982ae6db91a2afe1cd65f70d4f8ac156a0 | [
"Apache-2.0"
] | permissive | robertylewis/mathlib | 3d16e3e6daf5ddde182473e03a1b601d2810952c | 1d13f5b932f5e40a8308e3840f96fc882fae01f0 | refs/heads/master | 1,651,379,945,369 | 1,644,276,960,000 | 1,644,276,960,000 | 98,875,504 | 0 | 0 | Apache-2.0 | 1,644,253,514,000 | 1,501,495,700,000 | Lean | UTF-8 | Lean | false | false | 3,191 | lean | /-
Copyright (c) 2021 Christopher Hoskin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Christopher Hoskin
-/
import topology.basic
import topology.constructions
import topology.algebra.ordered.basic
/-!
# Topological lattices
In this file we define mixin classes `has_continuous_inf` and `has_continuous_sup`. We define the
class `topological_lattice` as a topological space and lattice `L` extending `has_continuous_inf`
and `has_continuous_sup`.
## References
* [Gierz et al, A Compendium of Continuous Lattices][GierzEtAl1980]
## Tags
topological, lattice
-/
/--
Let `L` be a topological space and let `L×L` be equipped with the product topology and let
`⊓:L×L → L` be an infimum. Then `L` is said to have *(jointly) continuous infimum* if the map
`⊓:L×L → L` is continuous.
-/
class has_continuous_inf (L : Type*) [topological_space L] [has_inf L] : Prop :=
(continuous_inf : continuous (λ p : L × L, p.1 ⊓ p.2))
/--
Let `L` be a topological space and let `L×L` be equipped with the product topology and let
`⊓:L×L → L` be a supremum. Then `L` is said to have *(jointly) continuous supremum* if the map
`⊓:L×L → L` is continuous.
-/
class has_continuous_sup (L : Type*) [topological_space L] [has_sup L] : Prop :=
(continuous_sup : continuous (λ p : L × L, p.1 ⊔ p.2))
@[priority 100] -- see Note [lower instance priority]
instance order_dual.has_continuous_sup
(L : Type*) [topological_space L] [has_inf L] [has_continuous_inf L] :
has_continuous_sup (order_dual L) :=
{ continuous_sup := @has_continuous_inf.continuous_inf L _ _ _ }
@[priority 100] -- see Note [lower instance priority]
instance order_dual.has_continuous_inf
(L : Type*) [topological_space L] [has_sup L] [has_continuous_sup L] :
has_continuous_inf (order_dual L) :=
{ continuous_inf := @has_continuous_sup.continuous_sup L _ _ _ }
/--
Let `L` be a lattice equipped with a topology such that `L` has continuous infimum and supremum.
Then `L` is said to be a *topological lattice*.
-/
class topological_lattice (L : Type*) [topological_space L] [lattice L]
extends has_continuous_inf L, has_continuous_sup L
@[priority 100] -- see Note [lower instance priority]
instance order_dual.topological_lattice
(L : Type*) [topological_space L] [lattice L] [topological_lattice L] :
topological_lattice (order_dual L) := {}
variables {L : Type*} [topological_space L]
variables {X : Type*} [topological_space X]
@[continuity] lemma continuous_inf [has_inf L] [has_continuous_inf L] :
continuous (λp:L×L, p.1 ⊓ p.2) :=
has_continuous_inf.continuous_inf
@[continuity] lemma continuous.inf [has_inf L] [has_continuous_inf L]
{f g : X → L} (hf : continuous f) (hg : continuous g) :
continuous (λx, f x ⊓ g x) :=
continuous_inf.comp (hf.prod_mk hg : _)
@[continuity] lemma continuous_sup [has_sup L] [has_continuous_sup L] :
continuous (λp:L×L, p.1 ⊔ p.2) :=
has_continuous_sup.continuous_sup
@[continuity] lemma continuous.sup [has_sup L] [has_continuous_sup L]
{f g : X → L} (hf : continuous f) (hg : continuous g) :
continuous (λx, f x ⊔ g x) :=
continuous_sup.comp (hf.prod_mk hg : _)
|
a8fc085f7858b8341c17c3d095fc2636a9898396 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/ring_theory/ideal/idempotent_fg.lean | 029aa6c03d62aa5d71cc2bf60d58e361bed80284 | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 1,589 | lean | /-
Copyright (c) 2018 Mario Carneiro, Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kevin Buzzard
-/
import algebra.ring.idempotents
import ring_theory.finiteness
/-!
## Lemmas on idempotent finitely generated ideals
-/
namespace ideal
/-- A finitely generated idempotent ideal is generated by an idempotent element -/
lemma is_idempotent_elem_iff_of_fg {R : Type*} [comm_ring R] (I : ideal R)
(h : I.fg) :
is_idempotent_elem I ↔ ∃ e : R, is_idempotent_elem e ∧ I = R ∙ e :=
begin
split,
{ intro e,
obtain ⟨r, hr, hr'⟩ := submodule.exists_mem_and_smul_eq_self_of_fg_of_le_smul I I h
(by { rw [smul_eq_mul], exact e.ge }),
simp_rw smul_eq_mul at hr',
refine ⟨r, hr' r hr, antisymm _ ((submodule.span_singleton_le_iff_mem _ _).mpr hr)⟩,
intros x hx,
rw ← hr' x hx,
exact ideal.mem_span_singleton'.mpr ⟨_, mul_comm _ _⟩ },
{ rintros ⟨e, he, rfl⟩,
simp [is_idempotent_elem, ideal.span_singleton_mul_span_singleton, he.eq] }
end
lemma is_idempotent_elem_iff_eq_bot_or_top {R : Type*} [comm_ring R] [is_domain R]
(I : ideal R) (h : I.fg) :
is_idempotent_elem I ↔ I = ⊥ ∨ I = ⊤ :=
begin
split,
{ intro H,
obtain ⟨e, he, rfl⟩ := (I.is_idempotent_elem_iff_of_fg h).mp H,
simp only [ideal.submodule_span_eq, ideal.span_singleton_eq_bot],
apply or_of_or_of_imp_of_imp (is_idempotent_elem.iff_eq_zero_or_one.mp he) id,
rintro rfl,
simp },
{ rintro (rfl|rfl); simp [is_idempotent_elem] }
end
end ideal
|
82d19f105ec80c9c735924d3b8558cd01df3a1db | 3dd1b66af77106badae6edb1c4dea91a146ead30 | /tests/lean/run/t8.lean | e5c0240135ca40b52057d5d42a34001d42e89be4 | [
"Apache-2.0"
] | permissive | silky/lean | 79c20c15c93feef47bb659a2cc139b26f3614642 | df8b88dca2f8da1a422cb618cd476ef5be730546 | refs/heads/master | 1,610,737,587,697 | 1,406,574,534,000 | 1,406,574,534,000 | 22,362,176 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 54 | lean | import standard
using tactic
print raw (by assumption) |
6ab0f8d0c2c354f23198e6e3dfab1fb561044368 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/Lean/Elab/DeclModifiers.lean | 2a76ef542440f9572c5cf2cbab34396f8b7a7053 | [
"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 | 10,406 | 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.Structure
import Lean.Elab.Attributes
namespace Lean.Elab
/--
Ensure the environment does not contain a declaration with name `declName`.
Recall that a private declaration cannot shadow a non-private one and vice-versa, although
they internally have different names.
-/
def checkNotAlreadyDeclared {m} [Monad m] [MonadEnv m] [MonadError m] [MonadInfoTree m] (declName : Name) : m Unit := do
let env ← getEnv
let addInfo declName := do
pushInfoLeaf <| .ofTermInfo {
elaborator := .anonymous, lctx := {}, expectedType? := none
stx := (← getRef)
expr := (← mkConstWithLevelParams declName)
}
if env.contains declName then
addInfo declName
match privateToUserName? declName with
| none => throwError "'{declName}' has already been declared"
| some declName => throwError "private declaration '{declName}' has already been declared"
if env.contains (mkPrivateName env declName) then
addInfo (mkPrivateName env declName)
throwError "a private declaration '{declName}' has already been declared"
match privateToUserName? declName with
| none => pure ()
| some declName =>
if env.contains declName then
addInfo declName
throwError "a non-private declaration '{declName}' has already been declared"
/-- Declaration visibility modifier. That is, whether a declaration is regular, protected or private. -/
inductive Visibility where
| regular | «protected» | «private»
deriving Inhabited
instance : ToString Visibility where
toString
| .regular => "regular"
| .private => "private"
| .protected => "protected"
/-- Whether a declaration is default, partial or nonrec. -/
inductive RecKind where
| «partial» | «nonrec» | default
deriving Inhabited
/-- Flags and data added to declarations (eg docstrings, attributes, `private`, `unsafe`, `partial`, ...). -/
structure Modifiers where
docString? : Option String := none
visibility : Visibility := Visibility.regular
isNoncomputable : Bool := false
recKind : RecKind := RecKind.default
isUnsafe : Bool := false
attrs : Array Attribute := #[]
deriving Inhabited
def Modifiers.isPrivate : Modifiers → Bool
| { visibility := .private, .. } => true
| _ => false
def Modifiers.isProtected : Modifiers → Bool
| { visibility := .protected, .. } => true
| _ => false
def Modifiers.isPartial : Modifiers → Bool
| { recKind := .partial, .. } => true
| _ => false
def Modifiers.isNonrec : Modifiers → Bool
| { recKind := .nonrec, .. } => true
| _ => false
/-- Store `attr` in `modifiers` -/
def Modifiers.addAttribute (modifiers : Modifiers) (attr : Attribute) : Modifiers :=
{ modifiers with attrs := modifiers.attrs.push attr }
instance : ToFormat Modifiers := ⟨fun m =>
let components : List Format :=
(match m.docString? with
| some str => [f!"/--{str}-/"]
| none => [])
++ (match m.visibility with
| .regular => []
| .protected => [f!"protected"]
| .private => [f!"private"])
++ (if m.isNoncomputable then [f!"noncomputable"] else [])
++ (match m.recKind with | RecKind.partial => [f!"partial"] | RecKind.nonrec => [f!"nonrec"] | _ => [])
++ (if m.isUnsafe then [f!"unsafe"] else [])
++ m.attrs.toList.map (fun attr => format attr)
Format.bracket "{" (Format.joinSep components ("," ++ Format.line)) "}"⟩
instance : ToString Modifiers := ⟨toString ∘ format⟩
/--
Retrieve doc string from `stx` of the form `(docComment)?`.
-/
def expandOptDocComment? [Monad m] [MonadError m] (optDocComment : Syntax) : m (Option String) :=
match optDocComment.getOptional? with
| none => return none
| some s => match s[1] with
| .atom _ val => return some (val.extract 0 (val.endPos - ⟨2⟩))
| _ => throwErrorAt s "unexpected doc string{indentD s[1]}"
section Methods
variable [Monad m] [MonadEnv m] [MonadResolveName m] [MonadError m] [MonadMacroAdapter m] [MonadRecDepth m] [MonadTrace m] [MonadOptions m] [AddMessageContext m] [MonadLog m] [MonadInfoTree m] [MonadLiftT IO m]
/-- Elaborate declaration modifiers (i.e., attributes, `partial`, `private`, `proctected`, `unsafe`, `noncomputable`, doc string)-/
def elabModifiers (stx : Syntax) : m Modifiers := do
let docCommentStx := stx[0]
let attrsStx := stx[1]
let visibilityStx := stx[2]
let noncompStx := stx[3]
let unsafeStx := stx[4]
let recKind :=
if stx[5].isNone then
RecKind.default
else if stx[5][0].getKind == ``Parser.Command.partial then
RecKind.partial
else
RecKind.nonrec
let docString? ← match docCommentStx.getOptional? with
| none => pure none
| some s => pure (some (← getDocStringText ⟨s⟩))
let visibility ← match visibilityStx.getOptional? with
| none => pure Visibility.regular
| some v =>
let kind := v.getKind
if kind == ``Parser.Command.private then pure Visibility.private
else if kind == ``Parser.Command.protected then pure Visibility.protected
else throwErrorAt v "unexpected visibility modifier"
let attrs ← match attrsStx.getOptional? with
| none => pure #[]
| some attrs => elabDeclAttrs attrs
return {
docString?, visibility, recKind, attrs,
isUnsafe := !unsafeStx.isNone
isNoncomputable := !noncompStx.isNone
}
/--
Ensure the function has not already been declared, and apply the given visibility setting to `declName`.
If `private`, return the updated name using our internal encoding for private names.
If `protected`, register `declName` as protected in the environment.
-/
def applyVisibility (visibility : Visibility) (declName : Name) : m Name := do
match visibility with
| .private =>
let declName := mkPrivateName (← getEnv) declName
checkNotAlreadyDeclared declName
return declName
| .protected =>
checkNotAlreadyDeclared declName
modifyEnv fun env => addProtected env declName
return declName
| _ =>
checkNotAlreadyDeclared declName
pure declName
def checkIfShadowingStructureField (declName : Name) : m Unit := do
match declName with
| Name.str pre .. =>
if isStructure (← getEnv) pre then
let fieldNames := getStructureFieldsFlattened (← getEnv) pre
for fieldName in fieldNames do
if pre ++ fieldName == declName then
throwError "invalid declaration name '{declName}', structure '{pre}' has field '{fieldName}'"
| _ => pure ()
def mkDeclName (currNamespace : Name) (modifiers : Modifiers) (shortName : Name) : m (Name × Name) := do
let mut shortName := shortName
let mut currNamespace := currNamespace
let view := extractMacroScopes shortName
let name := view.name
let isRootName := (`_root_).isPrefixOf name
if name == `_root_ then
throwError "invalid declaration name `_root_`, `_root_` is a prefix used to refer to the 'root' namespace"
let declName := if isRootName then { view with name := name.replacePrefix `_root_ Name.anonymous }.review else currNamespace ++ shortName
if isRootName then
let .str p s := name | throwError "invalid declaration name '{name}'"
shortName := Name.mkSimple s
currNamespace := p.replacePrefix `_root_ Name.anonymous
checkIfShadowingStructureField declName
let declName ← applyVisibility modifiers.visibility declName
match modifiers.visibility with
| Visibility.protected =>
match currNamespace with
| .str _ s => return (declName, Name.mkSimple s ++ shortName)
| _ =>
if shortName.isAtomic then
throwError "protected declarations must be in a namespace"
return (declName, shortName)
| _ => return (declName, shortName)
/--
`declId` is of the form
```
leading_parser ident >> optional (".{" >> sepBy1 ident ", " >> "}")
```
but we also accept a single identifier to users to make macro writing more convenient .
-/
def expandDeclIdCore (declId : Syntax) : Name × Syntax :=
if declId.isIdent then
(declId.getId, mkNullNode)
else
let id := declId[0].getId
let optUnivDeclStx := declId[1]
(id, optUnivDeclStx)
/-- `expandDeclId` resulting type. -/
structure ExpandDeclIdResult where
/-- Short name for recursively referring to the declaration. -/
shortName : Name
/-- Fully qualified name that will be used to name the declaration in the kernel. -/
declName : Name
/-- Universe parameter names provided using the `universe` command and `.{...}` notation. -/
levelNames : List Name
/--
Given a declaration identifier (e.g., `ident (".{" ident,+ "}")?`) that may contain explicit universe parameters
- Ensure the new universe parameters do not shadow universe parameters declared using `universe` command.
- Create the fully qualified named for the declaration using the current namespace, and given `modifiers`
- Create a short version for recursively referring to the declaration. Recall that the `protected` modifier affects the generation of the short name.
The result also contains the universe parameters provided using `universe` command, and the `.{...}` notation.
This commands also stores the doc string stored in `modifiers`.
-/
def expandDeclId (currNamespace : Name) (currLevelNames : List Name) (declId : Syntax) (modifiers : Modifiers) : m ExpandDeclIdResult := do
-- ident >> optional (".{" >> sepBy1 ident ", " >> "}")
let (shortName, optUnivDeclStx) := expandDeclIdCore declId
let levelNames ← if optUnivDeclStx.isNone then
pure currLevelNames
else
let extraLevels := optUnivDeclStx[1].getArgs.getEvenElems
extraLevels.foldlM
(fun levelNames idStx =>
let id := idStx.getId
if levelNames.elem id then
withRef idStx <| throwAlreadyDeclaredUniverseLevel id
else
pure (id :: levelNames))
currLevelNames
let (declName, shortName) ← withRef declId <| mkDeclName currNamespace modifiers shortName
addDocString' declName modifiers.docString?
return { shortName := shortName, declName := declName, levelNames := levelNames }
end Methods
end Lean.Elab
|
47fe6d504e53ad8b5aca54d25416819e06897580 | 3d2a7f1582fe5bae4d0bdc2fe86e997521239a65 | /misc/bs1.lean | 2440488516fdcc6cd4340be1c33b6eebcff3e766 | [] | no_license | own-pt/common-sense-lean | e4fa643ae010459de3d1bf673be7cbc7062563c9 | f672210aecb4172f5bae265e43e6867397e13b1c | refs/heads/master | 1,622,065,660,261 | 1,589,487,533,000 | 1,589,487,533,000 | 254,167,782 | 3 | 2 | null | 1,589,487,535,000 | 1,586,370,214,000 | Lean | UTF-8 | Lean | false | false | 7,358 | lean | import tactic.rcases
/-
The problem is originally presented in:
A. Pease, G. Sutcliffe, N. Siegel, and S. Trac, “Large Theory
Reasoning with SUMO at CASC,” pp. 1–8, Jul. 2009.
Here we present the natural deduction proof in Lean.
adapted https://gist.github.com/digama0/16c62d1af34212de2e3fba380d87c043#file-common-sense-lean-lean-L170
-/
constant U : Type
constants SetOrClass Set Class Object Entity NullList_m List
CorpuscularObject Invertebrate Vertebrate Animal SpinalColumn
Organism Agent Physical Abstract
subclass_m TransitiveRelation PartialOrderingRelation Relation : U
constant BananaSlug10 : U
@[class] constants exhaustiveDecomposition3 disjointDecomposition3 partition3 : U → U → U → Prop
@[class] constant ins : U → U → Prop
@[class] constant subclass : U → U → Prop
@[class] constant disjoint : U → U → Prop
@[class] constant component : U → U → Prop
@[class] constant part : U → U → Prop
@[class] constant inList : U → U → Prop
@[class] constant ConsFn : U → U → U
@[class] constant ListFn1 : U → U
@[class] constant ListFn2 : U → U → U
@[class] constant ListFn3 : U → U → U → U
@[class] noncomputable def subclass1 := subclass
@[instance] def subclass1_single (x y : U) [subclass1 x y] : subclass x y := by assumption
/- SUMO axioms -/
@[instance] axiom a13 : ins subclass_m PartialOrderingRelation
@[instance] axiom a15 (x y z : U) [ins x SetOrClass] [ins y SetOrClass]
[ins z x] [subclass1 x y] : ins z y
/- EDITED (see https://github.com/own-pt/cl-krr/issues/23) -/
axiom a72773 (a : U) [ins a Animal] : (¬ ∃ p : U, ins p SpinalColumn ∧ part p a)
→ ¬ ins a Vertebrate
/- EDITED -/
axiom a72774 : ¬ ∃ s : U, ins s SpinalColumn ∧ part s BananaSlug10
axiom a72761 (x row0 row1 : U) [ins row0 Entity] [ins row1 Entity] [ins x Entity] :
(ListFn3 x row0 row1 = ConsFn x (ListFn2 row0 row1))
axiom a72767 (x y : U) [ins x Entity] [ins y Entity] :
((ListFn2 x y) = (ConsFn x (ConsFn y NullList_m)))
axiom a72768 (x : U) [ins x Entity] : (ListFn1 x = ConsFn x NullList_m)
axiom a72769 (x : U) [ins x Entity] : ¬ inList x NullList_m
axiom a72770 (L x y : U) [ins x Entity] [ins y Entity] [ins L List] :
((inList x (ConsFn y L)) ↔ ((x = y) ∨ inList x L))
@[instance] axiom a67959 : ins NullList_m List
@[instance] axiom a67958 : ins List SetOrClass
@[instance] axiom a72772 : ins BananaSlug10 Animal
@[instance] axiom a72771 : ins Animal SetOrClass
@[instance] axiom a72778 : ins Invertebrate SetOrClass
@[instance] axiom a71402 : ins Vertebrate SetOrClass
@[instance] axiom a71371 : ins Organism SetOrClass
@[instance] axiom a71872 : ins Agent SetOrClass
@[instance] axiom a71669 : ins Object SetOrClass
@[instance] axiom a69763 : ins Physical SetOrClass
@[instance] axiom a67331 : ins Entity SetOrClass
@[instance] axiom a67448 : ins SetOrClass SetOrClass
@[instance] axiom a68771 : ins Abstract SetOrClass
@[instance] axiom a68763 : ins Relation SetOrClass
@[instance] axiom a71844 : ins TransitiveRelation SetOrClass
@[instance] axiom a72180 : ins PartialOrderingRelation SetOrClass
@[instance] axiom a71370 : partition3 Animal Vertebrate Invertebrate
axiom a67131 {c row0 row1 : U} [ins c Class] [ins row0 Class] [ins row1 Class] :
(partition3 c row0 row1 ↔ (exhaustiveDecomposition3 c row0 row1 ∧ disjointDecomposition3 c row0 row1))
-- EDITED (see https://github.com/own-pt/cl-krr/issues/22)
axiom a67115 :
∀ (row0 row1 c obj : U),
∃ (item : U),
ins item SetOrClass ∧
(ins obj Entity →
ins c SetOrClass → ins c Class →
ins row0 Class → ins row0 Entity →
ins row1 Class → ins row1 Entity →
exhaustiveDecomposition3 c row0 row1 → ins obj c →
inList item (ListFn2 row0 row1) ∧ ins obj item)
@[instance] axiom a67447 : partition3 SetOrClass Set Class
axiom a67172 : ∃ x : U, ins x Entity
axiom a67173 : ∀ {c : U}, ins c Class ↔ subclass c Entity
@[instance] axiom a67818 : subclass1 PartialOrderingRelation TransitiveRelation
@[instance] axiom a67809 (x y z : U) [ins x SetOrClass] [ins y SetOrClass] [ins z SetOrClass]
[ins subclass_m TransitiveRelation] [subclass x y] [subclass1 y z] : subclass x z
@[instance] axiom a71382 : subclass1 Vertebrate Animal
@[instance] axiom a71383 : subclass1 Invertebrate Animal
@[instance] axiom a71369 : subclass1 Animal Organism
@[instance] axiom a71340 : subclass1 Organism Agent
@[instance] axiom a67315 : subclass1 Agent Object
@[instance] axiom a67177 : subclass1 Object Physical
@[instance] axiom a67174 : subclass1 Physical Entity
@[instance] axiom a67446 : subclass1 SetOrClass Abstract
@[instance] axiom a67332 : subclass1 Abstract Entity
@[instance] axiom a67954 : subclass1 List Relation
@[instance] axiom a67450 : subclass1 Relation Abstract
-- commented in list.kif
@[instance] axiom novo1 (x L : U) [ins L Entity] [ins L List] : ins (ConsFn x L) List
-- some initial tests
lemma VertebrateAnimal (x : U) [ins x Vertebrate] : ins x Animal := by apply_instance
lemma subclass_TransitiveRelation : ins subclass_m TransitiveRelation := by apply_instance
lemma VertebrateOrganism (x : U) [ins x Vertebrate] : ins x Organism := by apply_instance
lemma VertebrateEntity (x : U) [ins x Vertebrate] : ins x Entity := by apply_instance
lemma listLemma [hne : nonempty U] {x y z : U} [ins x Entity] [ins y Entity] [ins z Entity] :
inList x (ListFn2 y z) → x = y ∨ x = z :=
begin
intros h1,
rw a72767 at h1,
have h2 : x = y ∨ inList x (ConsFn z NullList_m), {rwa ← a72770},
cases h2,
{ exact or.inl h2 },
{ have h3 : x = z ∨ inList x NullList_m, {rwa ← a72770},
cases h3,
{ exact or.inr h3 },
{ exfalso,
exact a72769 x h3 } }
end
lemma lX [hne : nonempty U] {x c c1 c2}
[ins c SetOrClass] [ins c1 SetOrClass] [ins c2 SetOrClass]
[ins c Class] [ins c1 Class] [ins c2 Class] [ins x Entity] :
partition3 c c1 c2 → ins x c → ¬ ins x c1 → ins x c2 :=
begin
intros h1 h2 h3,
obtain ⟨h4a, h4b⟩ := a67131.1 h1,
obtain ⟨b, h7, h8⟩ := a67115 _ _ _ _, resetI,
cases h8 _ _ _ _ _ _ _ h4a h2 with h8a h8b; try {apply_instance},
obtain rfl | rfl := listLemma h8a,
{contradiction}, {assumption}
end
set_option class.instance_max_depth 200
set_option trace.class_instances true
lemma subclass_animal_entity : subclass Animal Entity := by apply_instance
lemma subclass_vertebrate_entity : subclass Vertebrate Entity := by apply_instance
lemma subclass_invertebrate_entity : subclass Invertebrate Entity := by apply_instance
lemma ins_banana_entity : ins BananaSlug10 Entity := by apply_instance
lemma ins_animal_class : ins Animal Class := a67173.2 $ by apply_instance
lemma l0 [nonempty U] : ¬(ins BananaSlug10 Vertebrate) := a72773 _ a72774
instance Vertebrate_class : ins Vertebrate Class := a67173.2 $ by apply_instance
instance Invertebrate_class : ins Invertebrate Class := a67173.2 $ by apply_instance
instance Animal_class : ins Animal Class := a67173.2 $ by apply_instance
theorem Banana_Invertebrate [nonempty U] : ins BananaSlug10 Invertebrate :=
by apply lX a71370 _ l0; apply_instance
example (X Y C : U) [h : partition3 C X Y] : subclass X C ∧ subclass Y C := sorry -- not provable
example (h : ins SetOrClass SetOrClass) : false := sorry -- not provable
|
9303e9542864c55f40b8005a42d0aeb4e14b271a | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/ac_refl1.lean | 0eb4cd0a981bc95b5eb908913e86888260f386dc | [
"Apache-2.0"
] | permissive | leanprover-community/lean | 12b87f69d92e614daea8bcc9d4de9a9ace089d0e | cce7990ea86a78bdb383e38ed7f9b5ba93c60ce0 | refs/heads/master | 1,687,508,156,644 | 1,684,951,104,000 | 1,684,951,104,000 | 169,960,991 | 457 | 107 | Apache-2.0 | 1,686,744,372,000 | 1,549,790,268,000 | C++ | UTF-8 | Lean | false | false | 847 | lean | instance aa : is_associative ℕ (+) := ⟨nat.add_assoc⟩
instance ac : is_commutative ℕ (+) := ⟨nat.add_comm⟩
instance ma : is_associative ℕ (*) := ⟨nat.mul_assoc⟩
instance mc : is_commutative ℕ (*) := ⟨nat.mul_comm⟩
example (a b c : nat) (f : nat → nat) : f (a + b + c) = f (b + c + a) :=
by ac_refl
example (a b c : nat) (f : nat → nat) : f (a + b + (c * b * a)) = f (b + (a * c * b) + a) :=
by ac_refl
example (a b c : nat) (f : nat → nat → nat) : f (b * c) (c * b * a) = f (c * b) (a * c * b) :=
by ac_refl
example (a b c : nat) (f : nat → nat) : f (a + (b * c) + (c * b * a)) = f ((c * b) + (a * c * b) + a) :=
by ac_refl
example (a b c : nat) (f : nat → nat) (g : nat → nat → nat) : g (f (a + (b * c) + (c * b * a))) (a + c + b + a) = g (f ((c * b) + (a * c * b) + a)) (c + b + a + a) :=
by ac_refl
|
eaed6c6d2bd34212863a0d4f6498aba2cca45036 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /tests/lean/run/confuse_ind.lean | 38617d9b8440247c0f252792b6d712fd41089ca6 | [
"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 | 221 | lean | attribute [reducible] definition mk_arrow (A : Type*) (B : Type*) :=
A → A → B
inductive confuse (A : Type)
| leaf1 : confuse
| leaf2 : num → confuse
| node : mk_arrow A confuse → confuse
check confuse.cases_on
|
d97b5e9fbe2997968c662274a16fe2ed97355841 | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/data/pfunctor/univariate/basic.lean | 112414b012f8c9c8d7e39cee53277b8b4abd1c5b | [
"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 | 6,312 | lean | /-
Copyright (c) 2018 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
-/
import data.W
/-!
# Polynomial functors
This file defines polynomial functors and the W-type construction as a
polynomial functor. (For the M-type construction, see
pfunctor/M.lean.)
-/
universe u
/--
A polynomial functor `P` is given by a type `A` and a family `B` of types over `A`. `P` maps
any type `α` to a new type `P.obj α`, which is defined as the sigma type `Σ x, P.B x → α`.
An element of `P.obj α` is a pair `⟨a, f⟩`, where `a` is an element of a type `A` and
`f : B a → α`. Think of `a` as the shape of the object and `f` as an index to the relevant
elements of `α`.
-/
structure pfunctor :=
(A : Type u) (B : A → Type u)
namespace pfunctor
instance : inhabited pfunctor :=
⟨⟨default _, default _⟩⟩
variables (P : pfunctor) {α β : Type u}
/-- Applying `P` to an object of `Type` -/
def obj (α : Type*) := Σ x : P.A, P.B x → α
/-- Applying `P` to a morphism of `Type` -/
def map {α β : Type*} (f : α → β) : P.obj α → P.obj β :=
λ ⟨a, g⟩, ⟨a, f ∘ g⟩
instance obj.inhabited [inhabited P.A] [inhabited α] : inhabited (P.obj α) :=
⟨ ⟨ default _, λ _, default _ ⟩ ⟩
instance : functor P.obj := {map := @map P}
protected theorem map_eq {α β : Type*} (f : α → β) (a : P.A) (g : P.B a → α) :
@functor.map P.obj _ _ _ f ⟨a, g⟩ = ⟨a, f ∘ g⟩ :=
rfl
protected theorem id_map {α : Type*} : ∀ x : P.obj α, id <$> x = id x :=
λ ⟨a, b⟩, rfl
protected theorem comp_map {α β γ : Type*} (f : α → β) (g : β → γ) :
∀ x : P.obj α, (g ∘ f) <$> x = g <$> (f <$> x) :=
λ ⟨a, b⟩, rfl
instance : is_lawful_functor P.obj :=
{id_map := @pfunctor.id_map P, comp_map := @pfunctor.comp_map P}
/-- re-export existing definition of W-types and
adapt it to a packaged definition of polynomial functor -/
def W := _root_.W P.B
/- inhabitants of W types is awkward to encode as an instance
assumption because there needs to be a value `a : P.A`
such that `P.B a` is empty to yield a finite tree -/
attribute [nolint has_inhabited_instance] W
variables {P}
/-- root element of a W tree -/
def W.head : W P → P.A
| ⟨a, f⟩ := a
/-- children of the root of a W tree -/
def W.children : Π x : W P, P.B (W.head x) → W P
| ⟨a, f⟩ := f
/-- destructor for W-types -/
def W.dest : W P → P.obj (W P)
| ⟨a, f⟩ := ⟨a, f⟩
/-- constructor for W-types -/
def W.mk : P.obj (W P) → W P
| ⟨a, f⟩ := ⟨a, f⟩
@[simp] theorem W.dest_mk (p : P.obj (W P)) : W.dest (W.mk p) = p :=
by cases p; reflexivity
@[simp] theorem W.mk_dest (p : W P) : W.mk (W.dest p) = p :=
by cases p; reflexivity
variables (P)
/-- `Idx` identifies a location inside the application of a pfunctor.
For `F : pfunctor`, `x : F.obj α` and `i : F.Idx`, `i` can designate
one part of `x` or is invalid, if `i.1 ≠ x.1` -/
def Idx := Σ x : P.A, P.B x
instance Idx.inhabited [inhabited P.A] [inhabited (P.B (default _))] : inhabited P.Idx :=
⟨ ⟨default _, default _⟩ ⟩
variables {P}
/-- `x.iget i` takes the component of `x` designated by `i` if any is or returns
a default value -/
def obj.iget [decidable_eq P.A] {α} [inhabited α] (x : P.obj α) (i : P.Idx) : α :=
if h : i.1 = x.1
then x.2 (cast (congr_arg _ h) i.2)
else default _
@[simp]
lemma fst_map {α β : Type u} (x : P.obj α) (f : α → β) :
(f <$> x).1 = x.1 := by { cases x; refl }
@[simp]
lemma iget_map [decidable_eq P.A] {α β : Type u} [inhabited α] [inhabited β]
(x : P.obj α) (f : α → β) (i : P.Idx)
(h : i.1 = x.1) :
(f <$> x).iget i = f (x.iget i) :=
by { simp only [obj.iget, fst_map, *, dif_pos, eq_self_iff_true],
cases x, refl }
end pfunctor
/-
Composition of polynomial functors.
-/
namespace pfunctor
/-- functor composition for polynomial functors -/
def comp (P₂ P₁ : pfunctor.{u}) : pfunctor.{u} :=
⟨ Σ a₂ : P₂.1, P₂.2 a₂ → P₁.1,
λ a₂a₁, Σ u : P₂.2 a₂a₁.1, P₁.2 (a₂a₁.2 u) ⟩
/-- constructor for composition -/
def comp.mk (P₂ P₁ : pfunctor.{u}) {α : Type} (x : P₂.obj (P₁.obj α)) : (comp P₂ P₁).obj α :=
⟨ ⟨ x.1, sigma.fst ∘ x.2 ⟩, λ a₂a₁, (x.2 a₂a₁.1).2 a₂a₁.2 ⟩
/-- destructor for composition -/
def comp.get (P₂ P₁ : pfunctor.{u}) {α : Type} (x : (comp P₂ P₁).obj α) : P₂.obj (P₁.obj α) :=
⟨ x.1.1, λ a₂, ⟨x.1.2 a₂, λ a₁, x.2 ⟨a₂,a₁⟩ ⟩ ⟩
end pfunctor
/-
Lifting predicates and relations.
-/
namespace pfunctor
variables {P : pfunctor.{u}}
open functor
theorem liftp_iff {α : Type u} (p : α → Prop) (x : P.obj α) :
liftp p x ↔ ∃ a f, x = ⟨a, f⟩ ∧ ∀ i, p (f i) :=
begin
split,
{ rintros ⟨y, hy⟩, cases h : y with a f,
refine ⟨a, λ i, (f i).val, _, λ i, (f i).property⟩,
rw [←hy, h, pfunctor.map_eq] },
rintros ⟨a, f, xeq, pf⟩,
use ⟨a, λ i, ⟨f i, pf i⟩⟩,
rw [xeq], reflexivity
end
theorem liftp_iff' {α : Type u} (p : α → Prop) (a : P.A) (f : P.B a → α) :
@liftp.{u} P.obj _ α p ⟨a,f⟩ ↔ ∀ i, p (f i) :=
begin
simp only [liftp_iff, sigma.mk.inj_iff]; split; intro,
{ casesm* [Exists _, _ ∧ _], subst_vars, assumption },
repeat { constructor <|> assumption }
end
theorem liftr_iff {α : Type u} (r : α → α → Prop) (x y : P.obj α) :
liftr r x y ↔ ∃ a f₀ f₁, x = ⟨a, f₀⟩ ∧ y = ⟨a, f₁⟩ ∧ ∀ i, r (f₀ i) (f₁ i) :=
begin
split,
{ rintros ⟨u, xeq, yeq⟩, cases h : u with a f,
use [a, λ i, (f i).val.fst, λ i, (f i).val.snd],
split, { rw [←xeq, h], refl },
split, { rw [←yeq, h], refl },
intro i, exact (f i).property },
rintros ⟨a, f₀, f₁, xeq, yeq, h⟩,
use ⟨a, λ i, ⟨(f₀ i, f₁ i), h i⟩⟩,
split,
{ rw [xeq], refl },
rw [yeq], refl
end
open set
theorem supp_eq {α : Type u} (a : P.A) (f : P.B a → α) :
@supp.{u} P.obj _ α (⟨a,f⟩ : P.obj α) = f '' univ :=
begin
ext, simp only [supp, image_univ, mem_range, mem_set_of_eq],
split; intro h,
{ apply @h (λ x, ∃ (y : P.B a), f y = x),
rw liftp_iff', intro, refine ⟨_,rfl⟩ },
{ simp only [liftp_iff'], cases h, subst x,
tauto }
end
end pfunctor
|
8e1a31c78df96fc1e8f88fb13369c278186bd67e | fe25de614feb5587799621c41487aaee0d083b08 | /stage0/src/Lean/Elab/BuiltinTerm.lean | 83f191a014a9267d200ab49030b1f241ca19fac2 | [
"Apache-2.0"
] | permissive | pollend/lean4 | e8469c2f5fb8779b773618c3267883cf21fb9fac | c913886938c4b3b83238a3f99673c6c5a9cec270 | refs/heads/master | 1,687,973,251,481 | 1,628,039,739,000 | 1,628,039,739,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 8,466 | lean | /-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Elab.Term
namespace Lean.Elab.Term
open Meta
@[builtinTermElab «prop»] def elabProp : TermElab := fun _ _ =>
return mkSort levelZero
private def elabOptLevel (stx : Syntax) : TermElabM Level :=
if stx.isNone then
pure levelZero
else
elabLevel stx[0]
@[builtinTermElab «sort»] def elabSort : TermElab := fun stx _ =>
return mkSort (← elabOptLevel stx[1])
@[builtinTermElab «type»] def elabTypeStx : TermElab := fun stx _ =>
return mkSort (mkLevelSucc (← elabOptLevel stx[1]))
/-
the method `resolveName` adds a completion point for it using the given
expected type. Thus, we propagate the expected type if `stx[0]` is an identifier.
It doesn't "hurt" if the identifier can be resolved because the expected type is not used in this case.
Recall that if the name resolution fails a synthetic sorry is returned.-/
@[builtinTermElab «pipeCompletion»] def elabPipeCompletion : TermElab := fun stx expectedType? => do
let e ← elabTerm stx[0] none
unless e.isSorry do
addDotCompletionInfo stx e expectedType?
throwErrorAt stx[1] "invalid field notation, identifier or numeral expected"
@[builtinTermElab «completion»] def elabCompletion : TermElab := fun stx expectedType? => do
/- `ident.` is ambiguous in Lean, we may try to be completing a declaration name or access a "field". -/
if stx[0].isIdent then
/- If we can elaborate the identifier successfully, we assume it a dot-completion. Otherwise, we treat it as
identifier completion with a dangling `.`.
Recall that the server falls back to identifier completion when dot-completion fails. -/
let s ← saveState
try
let e ← elabTerm stx[0] none
addDotCompletionInfo stx e expectedType?
catch _ =>
s.restore
addCompletionInfo <| CompletionInfo.id stx stx[0].getId (danglingDot := true) (← getLCtx) expectedType?
throwErrorAt stx[1] "invalid field notation, identifier or numeral expected"
else
elabPipeCompletion stx expectedType?
@[builtinTermElab «hole»] def elabHole : TermElab := fun stx expectedType? => do
let mvar ← mkFreshExprMVar expectedType?
registerMVarErrorHoleInfo mvar.mvarId! stx
pure mvar
@[builtinTermElab «syntheticHole»] def elabSyntheticHole : TermElab := fun stx expectedType? => do
let arg := stx[1]
let userName := if arg.isIdent then arg.getId else Name.anonymous
let mkNewHole : Unit → TermElabM Expr := fun _ => do
let mvar ← mkFreshExprMVar expectedType? MetavarKind.syntheticOpaque userName
registerMVarErrorHoleInfo mvar.mvarId! stx
pure mvar
if userName.isAnonymous then
mkNewHole ()
else
let mctx ← getMCtx
match mctx.findUserName? userName with
| none => mkNewHole ()
| some mvarId =>
let mvar := mkMVar mvarId
let mvarDecl ← getMVarDecl mvarId
let lctx ← getLCtx
if mvarDecl.lctx.isSubPrefixOf lctx then
pure mvar
else match mctx.getExprAssignment? mvarId with
| some val =>
let val ← instantiateMVars val
if mctx.isWellFormed lctx val then
pure val
else
withLCtx mvarDecl.lctx mvarDecl.localInstances do
throwError "synthetic hole has already been defined and assigned to value incompatible with the current context{indentExpr val}"
| none =>
if mctx.isDelayedAssigned mvarId then
-- We can try to improve this case if needed.
throwError "synthetic hole has already beend defined and delayed assigned with an incompatible local context"
else if lctx.isSubPrefixOf mvarDecl.lctx then
let mvarNew ← mkNewHole ()
modifyMCtx fun mctx => mctx.assignExpr mvarId mvarNew
pure mvarNew
else
throwError "synthetic hole has already been defined with an incompatible local context"
private def mkTacticMVar (type : Expr) (tacticCode : Syntax) : TermElabM Expr := do
let mvar ← mkFreshExprMVar type MetavarKind.syntheticOpaque
let mvarId := mvar.mvarId!
let ref ← getRef
let declName? ← getDeclName?
registerSyntheticMVar ref mvarId <| SyntheticMVarKind.tactic tacticCode (← saveContext)
return mvar
@[builtinTermElab byTactic] def elabByTactic : TermElab := fun stx expectedType? =>
match expectedType? with
| some expectedType => mkTacticMVar expectedType stx
| none => throwError ("invalid 'by' tactic, expected type has not been provided")
@[builtinTermElab noImplicitLambda] def elabNoImplicitLambda : TermElab := fun stx expectedType? =>
elabTerm stx[1] (mkNoImplicitLambdaAnnotation <$> expectedType?)
@[builtinTermElab cdot] def elabBadCDot : TermElab := fun stx _ =>
throwError "invalid occurrence of `·` notation, it must be surrounded by parentheses (e.g. `(· + 1)`)"
@[builtinTermElab strLit] def elabStrLit : TermElab := fun stx _ => do
match stx.isStrLit? with
| some val => pure $ mkStrLit val
| none => throwIllFormedSyntax
private def mkFreshTypeMVarFor (expectedType? : Option Expr) : TermElabM Expr := do
let typeMVar ← mkFreshTypeMVar MetavarKind.synthetic
match expectedType? with
| some expectedType => discard <| isDefEq expectedType typeMVar
| _ => pure ()
return typeMVar
@[builtinTermElab numLit] def elabNumLit : TermElab := fun stx expectedType? => do
let val ← match stx.isNatLit? with
| some val => pure val
| none => throwIllFormedSyntax
let typeMVar ← mkFreshTypeMVarFor expectedType?
let u ← getDecLevel typeMVar
let mvar ← mkInstMVar (mkApp2 (Lean.mkConst ``OfNat [u]) typeMVar (mkRawNatLit val))
let r := mkApp3 (Lean.mkConst ``OfNat.ofNat [u]) typeMVar (mkRawNatLit val) mvar
registerMVarErrorImplicitArgInfo mvar.mvarId! stx r
return r
@[builtinTermElab rawNatLit] def elabRawNatLit : TermElab := fun stx expectedType? => do
match stx[1].isNatLit? with
| some val => return mkRawNatLit val
| none => throwIllFormedSyntax
@[builtinTermElab scientificLit]
def elabScientificLit : TermElab := fun stx expectedType? => do
match stx.isScientificLit? with
| none => throwIllFormedSyntax
| some (m, sign, e) =>
let typeMVar ← mkFreshTypeMVarFor expectedType?
let u ← getDecLevel typeMVar
let mvar ← mkInstMVar (mkApp (Lean.mkConst ``OfScientific [u]) typeMVar)
return mkApp5 (Lean.mkConst ``OfScientific.ofScientific [u]) typeMVar mvar (mkRawNatLit m) (toExpr sign) (mkRawNatLit e)
@[builtinTermElab charLit] def elabCharLit : TermElab := fun stx _ => do
match stx.isCharLit? with
| some val => return mkApp (Lean.mkConst ``Char.ofNat) (mkRawNatLit val.toNat)
| none => throwIllFormedSyntax
@[builtinTermElab quotedName] def elabQuotedName : TermElab := fun stx _ =>
match stx[0].isNameLit? with
| some val => pure $ toExpr val
| none => throwIllFormedSyntax
@[builtinTermElab doubleQuotedName] def elabDoubleQuotedName : TermElab := fun stx _ => do
toExpr (← resolveGlobalConstNoOverloadWithInfo stx[2])
@[builtinTermElab typeOf] def elabTypeOf : TermElab := fun stx _ => do
inferType (← elabTerm stx[1] none)
@[builtinTermElab ensureTypeOf] def elabEnsureTypeOf : TermElab := fun stx expectedType? =>
match stx[2].isStrLit? with
| none => throwIllFormedSyntax
| some msg => do
let refTerm ← elabTerm stx[1] none
let refTermType ← inferType refTerm
elabTermEnsuringType stx[3] refTermType (errorMsgHeader? := msg)
@[builtinTermElab ensureExpectedType] def elabEnsureExpectedType : TermElab := fun stx expectedType? =>
match stx[1].isStrLit? with
| none => throwIllFormedSyntax
| some msg => elabTermEnsuringType stx[2] expectedType? (errorMsgHeader? := msg)
@[builtinTermElab «open»] def elabOpen : TermElab := fun stx expectedType? => do
try
pushScope
let openDecls ← elabOpenDecl stx[1]
withTheReader Core.Context (fun ctx => { ctx with openDecls := openDecls }) do
elabTerm stx[3] expectedType?
finally
popScope
@[builtinTermElab «set_option»] def elabSetOption : TermElab := fun stx expectedType? => do
let options ← Elab.elabSetOption stx[1] stx[2]
withTheReader Core.Context (fun ctx => { ctx with maxRecDepth := maxRecDepth.get options, options := options }) do
elabTerm stx[4] expectedType?
end Lean.Elab.Term
|
478a9fe84f58d05f852c5f784f17654f360bea01 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/topology/continuous_function/basic.lean | 00f426853fa6fec9b77543c98c648fa788430a26 | [
"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 | 7,519 | lean | /-
Copyright © 2020 Nicolò Cavalleri. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nicolò Cavalleri
-/
import topology.subset_properties
import topology.tactic
import topology.algebra.ordered.basic
/-!
# Continuous bundled map
In this file we define the type `continuous_map` of continuous bundled maps.
-/
/-- Bundled continuous maps. -/
@[protect_proj]
structure continuous_map (α : Type*) (β : Type*)
[topological_space α] [topological_space β] :=
(to_fun : α → β)
(continuous_to_fun : continuous to_fun . tactic.interactive.continuity')
notation `C(` α `, ` β `)` := continuous_map α β
namespace continuous_map
attribute [continuity] continuous_map.continuous_to_fun
variables {α : Type*} {β : Type*} {γ : Type*}
variables [topological_space α] [topological_space β] [topological_space γ]
instance : has_coe_to_fun (C(α, β)) := ⟨_, continuous_map.to_fun⟩
@[simp] lemma to_fun_eq_coe {f : C(α, β)} : f.to_fun = (f : α → β) := rfl
variables {α β} {f g : continuous_map α β}
@[continuity] protected lemma continuous (f : C(α, β)) : continuous f := f.continuous_to_fun
@[continuity] lemma continuous_set_coe (s : set C(α, β)) (f : s) : continuous f :=
by { cases f, dsimp, continuity, }
protected lemma continuous_at (f : C(α, β)) (x : α) : continuous_at f x :=
f.continuous.continuous_at
protected lemma continuous_within_at (f : C(α, β)) (s : set α) (x : α) :
continuous_within_at f s x :=
f.continuous.continuous_within_at
protected lemma congr_fun {f g : C(α, β)} (H : f = g) (x : α) : f x = g x := H ▸ rfl
protected lemma congr_arg (f : C(α, β)) {x y : α} (h : x = y) : f x = f y := h ▸ rfl
@[ext] theorem ext (H : ∀ x, f x = g x) : f = g :=
by cases f; cases g; congr'; exact funext H
lemma ext_iff : f = g ↔ ∀ x, f x = g x :=
⟨continuous_map.congr_fun, ext⟩
instance [inhabited β] : inhabited C(α, β) :=
⟨{ to_fun := λ _, default _, }⟩
lemma coe_inj ⦃f g : C(α, β)⦄ (h : (f : α → β) = g) : f = g :=
by cases f; cases g; cases h; refl
@[simp] lemma coe_mk (f : α → β) (h : continuous f) :
⇑(⟨f, h⟩ : continuous_map α β) = f := rfl
section
variables (α β)
/--
The continuous functions from `α` to `β` are the same as the plain functions when `α` is discrete.
-/
@[simps]
def equiv_fn_of_discrete [discrete_topology α] : C(α, β) ≃ (α → β) :=
⟨(λ f, f), (λ f, ⟨f, continuous_of_discrete_topology⟩),
λ f, by { ext, refl, }, λ f, by { ext, refl, }⟩
end
/-- The identity as a continuous map. -/
def id : C(α, α) := ⟨id⟩
@[simp] lemma id_coe : (id : α → α) = id := rfl
lemma id_apply (a : α) : id a = a := rfl
/-- The composition of continuous maps, as a continuous map. -/
def comp (f : C(β, γ)) (g : C(α, β)) : C(α, γ) := ⟨f ∘ g⟩
@[simp] lemma comp_coe (f : C(β, γ)) (g : C(α, β)) : (comp f g : α → γ) = f ∘ g := rfl
lemma comp_apply (f : C(β, γ)) (g : C(α, β)) (a : α) : comp f g a = f (g a) := rfl
/-- Constant map as a continuous map -/
def const (b : β) : C(α, β) := ⟨λ x, b⟩
@[simp] lemma const_coe (b : β) : (const b : α → β) = (λ x, b) := rfl
lemma const_apply (b : β) (a : α) : const b a = b := rfl
instance [nonempty α] [nontrivial β] : nontrivial C(α, β) :=
{ exists_pair_ne := begin
obtain ⟨b₁, b₂, hb⟩ := exists_pair_ne β,
refine ⟨const b₁, const b₂, _⟩,
contrapose! hb,
inhabit α,
change const b₁ (default α) = const b₂ (default α),
simp [hb]
end }
section
variables [linear_ordered_add_comm_group β] [order_topology β]
/-- The pointwise absolute value of a continuous function as a continuous function. -/
def abs (f : C(α, β)) : C(α, β) :=
{ to_fun := λ x, abs (f x), }
@[simp] lemma abs_apply (f : C(α, β)) (x : α) : f.abs x = _root_.abs (f x) :=
rfl
end
/-!
We now set up the partial order and lattice structure (given by pointwise min and max)
on continuous functions.
-/
section lattice
instance partial_order [partial_order β] :
partial_order C(α, β) :=
partial_order.lift (λ f, f.to_fun) (by tidy)
lemma le_def [partial_order β] {f g : C(α, β)} : f ≤ g ↔ ∀ a, f a ≤ g a :=
pi.le_def
lemma lt_def [partial_order β] {f g : C(α, β)} :
f < g ↔ (∀ a, f a ≤ g a) ∧ (∃ a, f a < g a) :=
pi.lt_def
instance has_sup [linear_order β] [order_closed_topology β] : has_sup C(α, β) :=
{ sup := λ f g, { to_fun := λ a, max (f a) (g a), } }
@[simp, norm_cast] lemma sup_coe [linear_order β] [order_closed_topology β] (f g : C(α, β)) :
((f ⊔ g : C(α, β)) : α → β) = (f ⊔ g : α → β) :=
rfl
@[simp] lemma sup_apply [linear_order β] [order_closed_topology β] (f g : C(α, β)) (a : α) :
(f ⊔ g) a = max (f a) (g a) :=
rfl
instance [linear_order β] [order_closed_topology β] : semilattice_sup C(α, β) :=
{ le_sup_left := λ f g, le_def.mpr (by simp [le_refl]),
le_sup_right := λ f g, le_def.mpr (by simp [le_refl]),
sup_le := λ f₁ f₂ g w₁ w₂, le_def.mpr (λ a, by simp [le_def.mp w₁ a, le_def.mp w₂ a]),
..continuous_map.partial_order,
..continuous_map.has_sup, }
instance has_inf [linear_order β] [order_closed_topology β] : has_inf C(α, β) :=
{ inf := λ f g, { to_fun := λ a, min (f a) (g a), } }
@[simp, norm_cast] lemma inf_coe [linear_order β] [order_closed_topology β] (f g : C(α, β)) :
((f ⊓ g : C(α, β)) : α → β) = (f ⊓ g : α → β) :=
rfl
@[simp] lemma inf_apply [linear_order β] [order_closed_topology β] (f g : C(α, β)) (a : α) :
(f ⊓ g) a = min (f a) (g a) :=
rfl
instance [linear_order β] [order_closed_topology β] : semilattice_inf C(α, β) :=
{ inf_le_left := λ f g, le_def.mpr (by simp [le_refl]),
inf_le_right := λ f g, le_def.mpr (by simp [le_refl]),
le_inf := λ f₁ f₂ g w₁ w₂, le_def.mpr (λ a, by simp [le_def.mp w₁ a, le_def.mp w₂ a]),
..continuous_map.partial_order,
..continuous_map.has_inf, }
instance [linear_order β] [order_closed_topology β] : lattice C(α, β) :=
{ ..continuous_map.semilattice_inf,
..continuous_map.semilattice_sup }
-- TODO transfer this lattice structure to `bounded_continuous_function`
section sup'
variables [linear_order γ] [order_closed_topology γ]
lemma sup'_apply {ι : Type*} {s : finset ι} (H : s.nonempty) (f : ι → C(β, γ)) (b : β) :
s.sup' H f b = s.sup' H (λ a, f a b) :=
finset.comp_sup'_eq_sup'_comp H (λ f : C(β, γ), f b) (λ i j, rfl)
@[simp, norm_cast]
lemma sup'_coe {ι : Type*} {s : finset ι} (H : s.nonempty) (f : ι → C(β, γ)) :
((s.sup' H f : C(β, γ)) : ι → β) = s.sup' H (λ a, (f a : β → γ)) :=
by { ext, simp [sup'_apply], }
end sup'
section inf'
variables [linear_order γ] [order_closed_topology γ]
lemma inf'_apply {ι : Type*} {s : finset ι} (H : s.nonempty) (f : ι → C(β, γ)) (b : β) :
s.inf' H f b = s.inf' H (λ a, f a b) :=
@sup'_apply _ (order_dual γ) _ _ _ _ _ _ H f b
@[simp, norm_cast]
lemma inf'_coe {ι : Type*} {s : finset ι} (H : s.nonempty) (f : ι → C(β, γ)) :
((s.inf' H f : C(β, γ)) : ι → β) = s.inf' H (λ a, (f a : β → γ)) :=
@sup'_coe _ (order_dual γ) _ _ _ _ _ _ H f
end inf'
end lattice
end continuous_map
/--
The forward direction of a homeomorphism, as a bundled continuous map.
-/
@[simps]
def homeomorph.to_continuous_map {α β : Type*} [topological_space α] [topological_space β]
(e : α ≃ₜ β) : C(α, β) := ⟨e⟩
|
8a5a0cf80a09f05ca314fe7df0e433b57258d5c4 | e61a235b8468b03aee0120bf26ec615c045005d2 | /stage0/src/Init/Data.lean | edfd8ed3747bbb23211f5d4eba2473dfc4a517d3 | [
"Apache-2.0"
] | permissive | SCKelemen/lean4 | 140dc63a80539f7c61c8e43e1c174d8500ec3230 | e10507e6615ddbef73d67b0b6c7f1e4cecdd82bc | refs/heads/master | 1,660,973,595,917 | 1,590,278,033,000 | 1,590,278,033,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 615 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Data.Basic
import Init.Data.Nat
import Init.Data.Char
import Init.Data.String
import Init.Data.List
import Init.Data.Int
import Init.Data.Array
import Init.Data.ByteArray
import Init.Data.FloatArray
import Init.Data.Fin
import Init.Data.UInt
import Init.Data.Float
import Init.Data.RBTree
import Init.Data.RBMap
import Init.Data.Option
import Init.Data.HashMap
import Init.Data.Random
import Init.Data.Queue
import Init.Data.Stack
|
1e6f7d07c757c956ef1835c11c96744aec57a4fe | a4673261e60b025e2c8c825dfa4ab9108246c32e | /tests/lean/funExpected.lean | 217b9a8907b72d63c6fdfb427d2451c931456891 | [
"Apache-2.0"
] | permissive | jcommelin/lean4 | c02dec0cc32c4bccab009285475f265f17d73228 | 2909313475588cc20ac0436e55548a4502050d0a | refs/heads/master | 1,674,129,550,893 | 1,606,415,348,000 | 1,606,415,348,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 77 | lean | #lang lean4
def f (xs : List Nat) : List Nat :=
xs.map (fun x => x + 1) [1]
|
8c3e4215e9b1af7f42ace3ec3f01e15cedc31351 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/number_theory/padics/padic_numbers.lean | 4108697f8f977dd162203dbff43f07a17db17560 | [
"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,519 | lean | /-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis
-/
import analysis.normed_space.basic
import number_theory.padics.padic_norm
/-!
# p-adic numbers
This file defines the p-adic numbers (rationals) `ℚ_p` as
the completion of `ℚ` with respect to the p-adic norm.
We show that the p-adic norm on ℚ extends to `ℚ_p`, that `ℚ` is embedded in `ℚ_p`,
and that `ℚ_p` is Cauchy complete.
## Important definitions
* `padic` : the type of p-adic numbers
* `padic_norm_e` : the rational valued p-adic norm on `ℚ_p`
## Notation
We introduce the notation `ℚ_[p]` for the p-adic numbers.
## Implementation notes
Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically
by taking `[fact (prime p)]` as a type class argument.
We use the same concrete Cauchy sequence construction that is used to construct ℝ.
`ℚ_p` inherits a field structure from this construction.
The extension of the norm on ℚ to `ℚ_p` is *not* analogous to extending the absolute value to ℝ,
and hence the proof that `ℚ_p` is complete is different from the proof that ℝ is complete.
A small special-purpose simplification tactic, `padic_index_simp`, is used to manipulate sequence
indices in the proof that the norm extends.
`padic_norm_e` is the rational-valued p-adic norm on `ℚ_p`.
To instantiate `ℚ_p` as a normed field, we must cast this into a ℝ-valued norm.
The `ℝ`-valued norm, using notation `∥ ∥` from normed spaces,
is the canonical representation of this norm.
`simp` prefers `padic_norm` to `padic_norm_e` when possible.
Since `padic_norm_e` and `∥ ∥` have different types, `simp` does not rewrite one to the other.
Coercions from `ℚ` to `ℚ_p` are set up to work with the `norm_cast` tactic.
## References
* [F. Q. Gouêva, *p-adic numbers*][gouvea1997]
* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]
* <https://en.wikipedia.org/wiki/P-adic_number>
## Tags
p-adic, p adic, padic, norm, valuation, cauchy, completion, p-adic completion
-/
noncomputable theory
open_locale classical
open nat multiplicity padic_norm cau_seq cau_seq.completion metric
/-- The type of Cauchy sequences of rationals with respect to the p-adic norm. -/
@[reducible] def padic_seq (p : ℕ) := cau_seq _ (padic_norm p)
namespace padic_seq
section
variables {p : ℕ} [fact p.prime]
/-- The p-adic norm of the entries of a nonzero Cauchy sequence of rationals is eventually
constant. -/
lemma stationary {f : cau_seq ℚ (padic_norm p)} (hf : ¬ f ≈ 0) :
∃ N, ∀ m n, N ≤ m → N ≤ n → padic_norm p (f n) = padic_norm p (f m) :=
have ∃ ε > 0, ∃ N1, ∀ j ≥ N1, ε ≤ padic_norm p (f j),
from cau_seq.abv_pos_of_not_lim_zero $ not_lim_zero_of_not_congr_zero hf,
let ⟨ε, hε, N1, hN1⟩ := this,
⟨N2, hN2⟩ := cau_seq.cauchy₂ f hε in
⟨ max N1 N2,
λ n m hn hm,
have padic_norm p (f n - f m) < ε, from hN2 _ (max_le_iff.1 hn).2 _ (max_le_iff.1 hm).2,
have padic_norm p (f n - f m) < padic_norm p (f n),
from lt_of_lt_of_le this $ hN1 _ (max_le_iff.1 hn).1,
have padic_norm p (f n - f m) < max (padic_norm p (f n)) (padic_norm p (f m)),
from lt_max_iff.2 (or.inl this),
begin
by_contradiction hne,
rw ←padic_norm.neg p (f m) at hne,
have hnam := add_eq_max_of_ne p hne,
rw [padic_norm.neg, max_comm] at hnam,
rw [←hnam, sub_eq_add_neg, add_comm] at this,
apply _root_.lt_irrefl _ this
end ⟩
/-- For all n ≥ stationary_point f hf, the p-adic norm of f n is the same. -/
def stationary_point {f : padic_seq p} (hf : ¬ f ≈ 0) : ℕ :=
classical.some $ stationary hf
lemma stationary_point_spec {f : padic_seq p} (hf : ¬ f ≈ 0) :
∀ {m n}, stationary_point hf ≤ m → stationary_point hf ≤ n →
padic_norm p (f n) = padic_norm p (f m) :=
classical.some_spec $ stationary hf
/-- Since the norm of the entries of a Cauchy sequence is eventually stationary,
we can lift the norm to sequences. -/
def norm (f : padic_seq p) : ℚ :=
if hf : f ≈ 0 then 0 else padic_norm p (f (stationary_point hf))
lemma norm_zero_iff (f : padic_seq p) : f.norm = 0 ↔ f ≈ 0 :=
begin
constructor,
{ intro h,
by_contradiction hf,
unfold norm at h, split_ifs at h,
apply hf,
intros ε hε,
existsi stationary_point hf,
intros j hj,
have heq := stationary_point_spec hf le_rfl hj,
simpa [h, heq] },
{ intro h,
simp [norm, h] }
end
end
section embedding
open cau_seq
variables {p : ℕ} [fact p.prime]
lemma equiv_zero_of_val_eq_of_equiv_zero {f g : padic_seq p}
(h : ∀ k, padic_norm p (f k) = padic_norm p (g k)) (hf : f ≈ 0) : g ≈ 0 :=
λ ε hε, let ⟨i, hi⟩ := hf _ hε in
⟨i, λ j hj, by simpa [h] using hi _ hj⟩
lemma norm_nonzero_of_not_equiv_zero {f : padic_seq p} (hf : ¬ f ≈ 0) :
f.norm ≠ 0 :=
hf ∘ f.norm_zero_iff.1
lemma norm_eq_norm_app_of_nonzero {f : padic_seq p} (hf : ¬ f ≈ 0) :
∃ k, f.norm = padic_norm p k ∧ k ≠ 0 :=
have heq : f.norm = padic_norm p (f $ stationary_point hf), by simp [norm, hf],
⟨f $ stationary_point hf, heq,
λ h, norm_nonzero_of_not_equiv_zero hf (by simpa [h] using heq)⟩
lemma not_lim_zero_const_of_nonzero {q : ℚ} (hq : q ≠ 0) : ¬ lim_zero (const (padic_norm p) q) :=
λ h', hq $ const_lim_zero.1 h'
lemma not_equiv_zero_const_of_nonzero {q : ℚ} (hq : q ≠ 0) : ¬ (const (padic_norm p) q) ≈ 0 :=
λ h : lim_zero (const (padic_norm p) q - 0), not_lim_zero_const_of_nonzero hq $ by simpa using h
lemma norm_nonneg (f : padic_seq p) : 0 ≤ f.norm :=
if hf : f ≈ 0 then by simp [hf, norm]
else by simp [norm, hf, padic_norm.nonneg]
/-- An auxiliary lemma for manipulating sequence indices. -/
lemma lift_index_left_left {f : padic_seq p} (hf : ¬ f ≈ 0) (v2 v3 : ℕ) :
padic_norm p (f (stationary_point hf)) =
padic_norm p (f (max (stationary_point hf) (max v2 v3))) :=
begin
apply stationary_point_spec hf,
{ apply le_max_left },
{ exact le_rfl }
end
/-- An auxiliary lemma for manipulating sequence indices. -/
lemma lift_index_left {f : padic_seq p} (hf : ¬ f ≈ 0) (v1 v3 : ℕ) :
padic_norm p (f (stationary_point hf)) =
padic_norm p (f (max v1 (max (stationary_point hf) v3))) :=
begin
apply stationary_point_spec hf,
{ apply le_trans,
{ apply le_max_left _ v3 },
{ apply le_max_right } },
{ exact le_rfl }
end
/-- An auxiliary lemma for manipulating sequence indices. -/
lemma lift_index_right {f : padic_seq p} (hf : ¬ f ≈ 0) (v1 v2 : ℕ) :
padic_norm p (f (stationary_point hf)) =
padic_norm p (f (max v1 (max v2 (stationary_point hf)))) :=
begin
apply stationary_point_spec hf,
{ apply le_trans,
{ apply le_max_right v2 },
{ apply le_max_right } },
{ exact le_rfl }
end
end embedding
section valuation
open cau_seq
variables {p : ℕ} [fact p.prime]
/-! ### Valuation on `padic_seq` -/
/--
The `p`-adic valuation on `ℚ` lifts to `padic_seq p`.
`valuation f` is defined to be the valuation of the (`ℚ`-valued) stationary point of `f`.
-/
def valuation (f : padic_seq p) : ℤ :=
if hf : f ≈ 0 then 0 else padic_val_rat p (f (stationary_point hf))
lemma norm_eq_pow_val {f : padic_seq p} (hf : ¬ f ≈ 0) :
f.norm = p^(-f.valuation : ℤ) :=
begin
rw [norm, valuation, dif_neg hf, dif_neg hf, padic_norm, if_neg],
intro H,
apply cau_seq.not_lim_zero_of_not_congr_zero hf,
intros ε hε,
use (stationary_point hf),
intros n hn,
rw stationary_point_spec hf le_rfl hn,
simpa [H] using hε,
end
lemma val_eq_iff_norm_eq {f g : padic_seq p} (hf : ¬ f ≈ 0) (hg : ¬ g ≈ 0) :
f.valuation = g.valuation ↔ f.norm = g.norm :=
begin
rw [norm_eq_pow_val hf, norm_eq_pow_val hg, ← neg_inj, zpow_inj],
{ exact_mod_cast (fact.out p.prime).pos },
{ exact_mod_cast (fact.out p.prime).ne_one },
end
end valuation
end padic_seq
section
open padic_seq
private meta def index_simp_core (hh hf hg : expr)
(at_ : interactive.loc := interactive.loc.ns [none]) : tactic unit :=
do [v1, v2, v3] ← [hh, hf, hg].mmap
(λ n, tactic.mk_app ``stationary_point [n] <|> return n),
e1 ← tactic.mk_app ``lift_index_left_left [hh, v2, v3] <|> return `(true),
e2 ← tactic.mk_app ``lift_index_left [hf, v1, v3] <|> return `(true),
e3 ← tactic.mk_app ``lift_index_right [hg, v1, v2] <|> return `(true),
sl ← [e1, e2, e3].mfoldl (λ s e, simp_lemmas.add s e) simp_lemmas.mk,
when at_.include_goal (tactic.simp_target sl >> tactic.skip),
hs ← at_.get_locals, hs.mmap' (tactic.simp_hyp sl [])
/--
This is a special-purpose tactic that lifts padic_norm (f (stationary_point f)) to
padic_norm (f (max _ _ _)).
-/
meta def tactic.interactive.padic_index_simp (l : interactive.parse interactive.types.pexpr_list)
(at_ : interactive.parse interactive.types.location) : tactic unit :=
do [h, f, g] ← l.mmap tactic.i_to_expr,
index_simp_core h f g at_
end
namespace padic_seq
section embedding
open cau_seq
variables {p : ℕ} [hp : fact p.prime]
include hp
lemma norm_mul (f g : padic_seq p) : (f * g).norm = f.norm * g.norm :=
if hf : f ≈ 0 then
have hg : f * g ≈ 0, from mul_equiv_zero' _ hf,
by simp only [hf, hg, norm, dif_pos, zero_mul]
else if hg : g ≈ 0 then
have hf : f * g ≈ 0, from mul_equiv_zero _ hg,
by simp only [hf, hg, norm, dif_pos, mul_zero]
else
have hfg : ¬ f * g ≈ 0, by apply mul_not_equiv_zero; assumption,
begin
unfold norm,
split_ifs,
padic_index_simp [hfg, hf, hg],
apply padic_norm.mul
end
lemma eq_zero_iff_equiv_zero (f : padic_seq p) : mk f = 0 ↔ f ≈ 0 :=
mk_eq
lemma ne_zero_iff_nequiv_zero (f : padic_seq p) : mk f ≠ 0 ↔ ¬ f ≈ 0 :=
not_iff_not.2 (eq_zero_iff_equiv_zero _)
lemma norm_const (q : ℚ) : norm (const (padic_norm p) q) = padic_norm p q :=
if hq : q = 0 then
have (const (padic_norm p) q) ≈ 0,
by simp [hq]; apply setoid.refl (const (padic_norm p) 0),
by subst hq; simp [norm, this]
else
have ¬ (const (padic_norm p) q) ≈ 0, from not_equiv_zero_const_of_nonzero hq,
by simp [norm, this]
lemma norm_values_discrete (a : padic_seq p) (ha : ¬ a ≈ 0) :
(∃ (z : ℤ), a.norm = ↑p ^ (-z)) :=
let ⟨k, hk, hk'⟩ := norm_eq_norm_app_of_nonzero ha in
by simpa [hk] using padic_norm.values_discrete p hk'
lemma norm_one : norm (1 : padic_seq p) = 1 :=
have h1 : ¬ (1 : padic_seq p) ≈ 0, from one_not_equiv_zero _,
by simp [h1, norm, hp.1.one_lt]
private lemma norm_eq_of_equiv_aux {f g : padic_seq p} (hf : ¬ f ≈ 0) (hg : ¬ g ≈ 0) (hfg : f ≈ g)
(h : padic_norm p (f (stationary_point hf)) ≠ padic_norm p (g (stationary_point hg)))
(hlt : padic_norm p (g (stationary_point hg)) < padic_norm p (f (stationary_point hf))) :
false :=
begin
have hpn : 0 < padic_norm p (f (stationary_point hf)) - padic_norm p (g (stationary_point hg)),
from sub_pos_of_lt hlt,
cases hfg _ hpn with N hN,
let i := max N (max (stationary_point hf) (stationary_point hg)),
have hi : N ≤ i, from le_max_left _ _,
have hN' := hN _ hi,
padic_index_simp [N, hf, hg] at hN' h hlt,
have hpne : padic_norm p (f i) ≠ padic_norm p (-(g i)),
by rwa [ ←padic_norm.neg p (g i)] at h,
let hpnem := add_eq_max_of_ne p hpne,
have hpeq : padic_norm p ((f - g) i) = max (padic_norm p (f i)) (padic_norm p (g i)),
{ rwa padic_norm.neg at hpnem },
rw [hpeq, max_eq_left_of_lt hlt] at hN',
have : padic_norm p (f i) < padic_norm p (f i),
{ apply lt_of_lt_of_le hN', apply sub_le_self, apply padic_norm.nonneg },
exact lt_irrefl _ this
end
private lemma norm_eq_of_equiv {f g : padic_seq p} (hf : ¬ f ≈ 0) (hg : ¬ g ≈ 0) (hfg : f ≈ g) :
padic_norm p (f (stationary_point hf)) = padic_norm p (g (stationary_point hg)) :=
begin
by_contradiction h,
cases (decidable.em (padic_norm p (g (stationary_point hg)) <
padic_norm p (f (stationary_point hf))))
with hlt hnlt,
{ exact norm_eq_of_equiv_aux hf hg hfg h hlt },
{ apply norm_eq_of_equiv_aux hg hf (setoid.symm hfg) (ne.symm h),
apply lt_of_le_of_ne,
apply le_of_not_gt hnlt,
apply h }
end
theorem norm_equiv {f g : padic_seq p} (hfg : f ≈ g) : f.norm = g.norm :=
if hf : f ≈ 0 then
have hg : g ≈ 0, from setoid.trans (setoid.symm hfg) hf,
by simp [norm, hf, hg]
else have hg : ¬ g ≈ 0, from hf ∘ setoid.trans hfg,
by unfold norm; split_ifs; exact norm_eq_of_equiv hf hg hfg
private lemma norm_nonarchimedean_aux {f g : padic_seq p}
(hfg : ¬ f + g ≈ 0) (hf : ¬ f ≈ 0) (hg : ¬ g ≈ 0) : (f + g).norm ≤ max (f.norm) (g.norm) :=
begin
unfold norm, split_ifs,
padic_index_simp [hfg, hf, hg],
apply padic_norm.nonarchimedean
end
theorem norm_nonarchimedean (f g : padic_seq p) : (f + g).norm ≤ max (f.norm) (g.norm) :=
if hfg : f + g ≈ 0 then
have 0 ≤ max (f.norm) (g.norm), from le_max_of_le_left (norm_nonneg _),
by simpa only [hfg, norm, ne.def, le_max_iff, cau_seq.add_apply, not_true, dif_pos]
else if hf : f ≈ 0 then
have hfg' : f + g ≈ g,
{ change lim_zero (f - 0) at hf,
show lim_zero (f + g - g), by simpa only [sub_zero, add_sub_cancel] using hf },
have hcfg : (f + g).norm = g.norm, from norm_equiv hfg',
have hcl : f.norm = 0, from (norm_zero_iff f).2 hf,
have max (f.norm) (g.norm) = g.norm,
by rw hcl; exact max_eq_right (norm_nonneg _),
by rw [this, hcfg]
else if hg : g ≈ 0 then
have hfg' : f + g ≈ f,
{ change lim_zero (g - 0) at hg,
show lim_zero (f + g - f), by simpa only [add_sub_cancel', sub_zero] using hg },
have hcfg : (f + g).norm = f.norm, from norm_equiv hfg',
have hcl : g.norm = 0, from (norm_zero_iff g).2 hg,
have max (f.norm) (g.norm) = f.norm,
by rw hcl; exact max_eq_left (norm_nonneg _),
by rw [this, hcfg]
else norm_nonarchimedean_aux hfg hf hg
lemma norm_eq {f g : padic_seq p} (h : ∀ k, padic_norm p (f k) = padic_norm p (g k)) :
f.norm = g.norm :=
if hf : f ≈ 0 then
have hg : g ≈ 0, from equiv_zero_of_val_eq_of_equiv_zero h hf,
by simp only [hf, hg, norm, dif_pos]
else
have hg : ¬ g ≈ 0, from λ hg, hf $ equiv_zero_of_val_eq_of_equiv_zero
(by simp only [h, forall_const, eq_self_iff_true]) hg,
begin
simp only [hg, hf, norm, dif_neg, not_false_iff],
let i := max (stationary_point hf) (stationary_point hg),
have hpf : padic_norm p (f (stationary_point hf)) = padic_norm p (f i),
{ apply stationary_point_spec, apply le_max_left, exact le_rfl },
have hpg : padic_norm p (g (stationary_point hg)) = padic_norm p (g i),
{ apply stationary_point_spec, apply le_max_right, exact le_rfl },
rw [hpf, hpg, h]
end
lemma norm_neg (a : padic_seq p) : (-a).norm = a.norm :=
norm_eq $ by simp
lemma norm_eq_of_add_equiv_zero {f g : padic_seq p} (h : f + g ≈ 0) : f.norm = g.norm :=
have lim_zero (f + g - 0), from h,
have f ≈ -g, from show lim_zero (f - (-g)), by simpa only [sub_zero, sub_neg_eq_add],
have f.norm = (-g).norm, from norm_equiv this,
by simpa only [norm_neg] using this
lemma add_eq_max_of_ne {f g : padic_seq p} (hfgne : f.norm ≠ g.norm) :
(f + g).norm = max f.norm g.norm :=
have hfg : ¬f + g ≈ 0, from mt norm_eq_of_add_equiv_zero hfgne,
if hf : f ≈ 0 then
have lim_zero (f - 0), from hf,
have f + g ≈ g, from show lim_zero ((f + g) - g), by simpa only [sub_zero, add_sub_cancel],
have h1 : (f+g).norm = g.norm, from norm_equiv this,
have h2 : f.norm = 0, from (norm_zero_iff _).2 hf,
by rw [h1, h2]; rw max_eq_right (norm_nonneg _)
else if hg : g ≈ 0 then
have lim_zero (g - 0), from hg,
have f + g ≈ f, from show lim_zero ((f + g) - f), by rw [add_sub_cancel']; simpa only [sub_zero],
have h1 : (f+g).norm = f.norm, from norm_equiv this,
have h2 : g.norm = 0, from (norm_zero_iff _).2 hg,
by rw [h1, h2]; rw max_eq_left (norm_nonneg _)
else
begin
unfold norm at ⊢ hfgne, split_ifs at ⊢ hfgne,
padic_index_simp [hfg, hf, hg] at ⊢ hfgne,
exact padic_norm.add_eq_max_of_ne p hfgne
end
end embedding
end padic_seq
/-- The p-adic numbers `Q_[p]` are the Cauchy completion of `ℚ` with respect to the p-adic norm. -/
def padic (p : ℕ) [fact p.prime] := @cau_seq.completion.Cauchy _ _ _ _ (padic_norm p) _
notation `ℚ_[` p `]` := padic p
namespace padic
section completion
variables {p : ℕ} [fact p.prime]
/-- The discrete field structure on `ℚ_p` is inherited from the Cauchy completion construction. -/
instance field : field (ℚ_[p]) :=
cau_seq.completion.field
instance : inhabited ℚ_[p] := ⟨0⟩
-- short circuits
instance : has_zero ℚ_[p] := by apply_instance
instance : has_one ℚ_[p] := by apply_instance
instance : has_add ℚ_[p] := by apply_instance
instance : has_mul ℚ_[p] := by apply_instance
instance : has_sub ℚ_[p] := by apply_instance
instance : has_neg ℚ_[p] := by apply_instance
instance : has_div ℚ_[p] := by apply_instance
instance : add_comm_group ℚ_[p] := by apply_instance
instance : comm_ring ℚ_[p] := by apply_instance
/-- Builds the equivalence class of a Cauchy sequence of rationals. -/
def mk : padic_seq p → ℚ_[p] := quotient.mk
end completion
section completion
variables (p : ℕ) [fact p.prime]
lemma mk_eq {f g : padic_seq p} : mk f = mk g ↔ f ≈ g := quotient.eq
/-- Embeds the rational numbers in the p-adic numbers. -/
def of_rat : ℚ → ℚ_[p] := cau_seq.completion.of_rat
@[simp] lemma of_rat_add : ∀ (x y : ℚ), of_rat p (x + y) = of_rat p x + of_rat p y :=
cau_seq.completion.of_rat_add
@[simp] lemma of_rat_neg : ∀ (x : ℚ), of_rat p (-x) = -of_rat p x :=
cau_seq.completion.of_rat_neg
@[simp] lemma of_rat_mul : ∀ (x y : ℚ), of_rat p (x * y) = of_rat p x * of_rat p y :=
cau_seq.completion.of_rat_mul
@[simp] lemma of_rat_sub : ∀ (x y : ℚ), of_rat p (x - y) = of_rat p x - of_rat p y :=
cau_seq.completion.of_rat_sub
@[simp] lemma of_rat_div : ∀ (x y : ℚ), of_rat p (x / y) = of_rat p x / of_rat p y :=
cau_seq.completion.of_rat_div
@[simp] lemma of_rat_one : of_rat p 1 = 1 := rfl
@[simp] lemma of_rat_zero : of_rat p 0 = 0 := rfl
lemma cast_eq_of_rat_of_nat (n : ℕ) : (↑n : ℚ_[p]) = of_rat p n :=
begin
induction n with n ih,
{ refl },
{ simpa using ih }
end
lemma cast_eq_of_rat_of_int (n : ℤ) : ↑n = of_rat p n :=
by induction n; simp [cast_eq_of_rat_of_nat]
lemma cast_eq_of_rat : ∀ (q : ℚ), (↑q : ℚ_[p]) = of_rat p q
| ⟨n, d, h1, h2⟩ :=
show ↑n / ↑d = _, from
have (⟨n, d, h1, h2⟩ : ℚ) = rat.mk n d, from rat.num_denom',
by simp [this, rat.mk_eq_div, of_rat_div, cast_eq_of_rat_of_int, cast_eq_of_rat_of_nat]
@[norm_cast] lemma coe_add : ∀ {x y : ℚ}, (↑(x + y) : ℚ_[p]) = ↑x + ↑y := by simp [cast_eq_of_rat]
@[norm_cast] lemma coe_neg : ∀ {x : ℚ}, (↑(-x) : ℚ_[p]) = -↑x := by simp [cast_eq_of_rat]
@[norm_cast] lemma coe_mul : ∀ {x y : ℚ}, (↑(x * y) : ℚ_[p]) = ↑x * ↑y := by simp [cast_eq_of_rat]
@[norm_cast] lemma coe_sub : ∀ {x y : ℚ}, (↑(x - y) : ℚ_[p]) = ↑x - ↑y := by simp [cast_eq_of_rat]
@[norm_cast] lemma coe_div : ∀ {x y : ℚ}, (↑(x / y) : ℚ_[p]) = ↑x / ↑y := by simp [cast_eq_of_rat]
@[norm_cast] lemma coe_one : (↑1 : ℚ_[p]) = 1 := by simp [cast_eq_of_rat]
@[norm_cast] lemma coe_zero : (↑0 : ℚ_[p]) = 0 := rfl
lemma const_equiv {q r : ℚ} : const (padic_norm p) q ≈ const (padic_norm p) r ↔ q = r :=
⟨ λ heq : lim_zero (const (padic_norm p) (q - r)),
eq_of_sub_eq_zero $ const_lim_zero.1 heq,
λ heq, by rw heq; apply setoid.refl _ ⟩
lemma of_rat_eq {q r : ℚ} : of_rat p q = of_rat p r ↔ q = r :=
⟨(const_equiv p).1 ∘ quotient.eq.1, λ h, by rw h⟩
@[norm_cast] lemma coe_inj {q r : ℚ} : (↑q : ℚ_[p]) = ↑r ↔ q = r :=
by simp [cast_eq_of_rat, of_rat_eq]
instance : char_zero ℚ_[p] :=
⟨λ m n, by { rw ← rat.cast_coe_nat, norm_cast, exact id }⟩
end completion
end padic
/-- The rational-valued p-adic norm on `ℚ_p` is lifted from the norm on Cauchy sequences. The
canonical form of this function is the normed space instance, with notation `∥ ∥`. -/
def padic_norm_e {p : ℕ} [hp : fact p.prime] : ℚ_[p] → ℚ :=
quotient.lift padic_seq.norm $ @padic_seq.norm_equiv _ _
namespace padic_norm_e
section embedding
open padic_seq
variables {p : ℕ} [fact p.prime]
lemma defn (f : padic_seq p) {ε : ℚ} (hε : 0 < ε) : ∃ N, ∀ i ≥ N, padic_norm_e (⟦f⟧ - f i) < ε :=
begin
simp only [padic.cast_eq_of_rat],
change ∃ N, ∀ i ≥ N, (f - const _ (f i)).norm < ε,
by_contradiction h,
cases cauchy₂ f hε with N hN,
have : ∀ N, ∃ i ≥ N, ε ≤ (f - const _ (f i)).norm,
by simpa only [not_forall, not_exists, not_lt] using h,
rcases this N with ⟨i, hi, hge⟩,
have hne : ¬ (f - const (padic_norm p) (f i)) ≈ 0,
{ intro h, unfold padic_seq.norm at hge; split_ifs at hge, exact not_lt_of_ge hge hε },
unfold padic_seq.norm at hge; split_ifs at hge,
apply not_le_of_gt _ hge,
cases decidable.em (N ≤ stationary_point hne) with hgen hngen,
{ apply hN; assumption },
{ have := stationary_point_spec hne le_rfl (le_of_not_le hngen),
rw ←this,
apply hN,
exact le_rfl, assumption }
end
protected lemma nonneg (q : ℚ_[p]) : 0 ≤ padic_norm_e q :=
quotient.induction_on q $ norm_nonneg
lemma zero_def : (0 : ℚ_[p]) = ⟦0⟧ := rfl
lemma zero_iff (q : ℚ_[p]) : padic_norm_e q = 0 ↔ q = 0 :=
quotient.induction_on q $
by simpa only [zero_def, quotient.eq] using norm_zero_iff
@[simp] protected lemma zero : padic_norm_e (0 : ℚ_[p]) = 0 :=
(zero_iff _).2 rfl
/-- Theorems about `padic_norm_e` are named with a `'` so the names do not conflict with the
equivalent theorems about `norm` (`∥ ∥`). -/
@[simp] protected lemma one' : padic_norm_e (1 : ℚ_[p]) = 1 :=
norm_one
@[simp] protected lemma neg (q : ℚ_[p]) : padic_norm_e (-q) = padic_norm_e q :=
quotient.induction_on q $ norm_neg
/-- Theorems about `padic_norm_e` are named with a `'` so the names do not conflict with the
equivalent theorems about `norm` (`∥ ∥`). -/
theorem nonarchimedean' (q r : ℚ_[p]) :
padic_norm_e (q + r) ≤ max (padic_norm_e q) (padic_norm_e r) :=
quotient.induction_on₂ q r $ norm_nonarchimedean
/-- Theorems about `padic_norm_e` are named with a `'` so the names do not conflict with the
equivalent theorems about `norm` (`∥ ∥`). -/
theorem add_eq_max_of_ne' {q r : ℚ_[p]} :
padic_norm_e q ≠ padic_norm_e r → padic_norm_e (q + r) = max (padic_norm_e q) (padic_norm_e r) :=
quotient.induction_on₂ q r $ λ _ _, padic_seq.add_eq_max_of_ne
lemma triangle_ineq (x y z : ℚ_[p]) :
padic_norm_e (x - z) ≤ padic_norm_e (x - y) + padic_norm_e (y - z) :=
calc padic_norm_e (x - z) = padic_norm_e ((x - y) + (y - z)) : by rw sub_add_sub_cancel
... ≤ max (padic_norm_e (x - y)) (padic_norm_e (y - z)) : padic_norm_e.nonarchimedean' _ _
... ≤ padic_norm_e (x - y) + padic_norm_e (y - z) :
max_le_add_of_nonneg (padic_norm_e.nonneg _) (padic_norm_e.nonneg _)
protected lemma add (q r : ℚ_[p]) : padic_norm_e (q + r) ≤ (padic_norm_e q) + (padic_norm_e r) :=
calc
padic_norm_e (q + r) ≤ max (padic_norm_e q) (padic_norm_e r) : nonarchimedean' _ _
... ≤ (padic_norm_e q) + (padic_norm_e r) :
max_le_add_of_nonneg (padic_norm_e.nonneg _) (padic_norm_e.nonneg _)
protected lemma mul' (q r : ℚ_[p]) : padic_norm_e (q * r) = (padic_norm_e q) * (padic_norm_e r) :=
quotient.induction_on₂ q r $ norm_mul
instance : is_absolute_value (@padic_norm_e p _) :=
{ abv_nonneg := padic_norm_e.nonneg,
abv_eq_zero := zero_iff,
abv_add := padic_norm_e.add,
abv_mul := padic_norm_e.mul' }
@[simp] lemma eq_padic_norm' (q : ℚ) : padic_norm_e (padic.of_rat p q) = padic_norm p q :=
norm_const _
protected theorem image' {q : ℚ_[p]} : q ≠ 0 → ∃ n : ℤ, padic_norm_e q = p ^ (-n) :=
quotient.induction_on q $ λ f hf,
have ¬ f ≈ 0, from (ne_zero_iff_nequiv_zero f).1 hf,
norm_values_discrete f this
lemma sub_rev (q r : ℚ_[p]) : padic_norm_e (q - r) = padic_norm_e (r - q) :=
by rw ←(padic_norm_e.neg); simp
end embedding
end padic_norm_e
namespace padic
section complete
open padic_seq padic
theorem rat_dense' {p : ℕ} [fact p.prime] (q : ℚ_[p]) {ε : ℚ} (hε : 0 < ε) :
∃ r : ℚ, padic_norm_e (q - r) < ε :=
quotient.induction_on q $ λ q',
have ∃ N, ∀ m n ≥ N, padic_norm p (q' m - q' n) < ε, from cauchy₂ _ hε,
let ⟨N, hN⟩ := this in
⟨q' N,
begin
simp only [padic.cast_eq_of_rat],
change padic_seq.norm (q' - const _ (q' N)) < ε,
cases decidable.em ((q' - const (padic_norm p) (q' N)) ≈ 0) with heq hne',
{ simpa only [heq, padic_seq.norm, dif_pos] },
{ simp only [padic_seq.norm, dif_neg hne'],
change padic_norm p (q' _ - q' _) < ε,
have := stationary_point_spec hne',
cases decidable.em (stationary_point hne' ≤ N) with hle hle,
{ have := eq.symm (this le_rfl hle),
simp only [const_apply, sub_apply, padic_norm.zero, sub_self] at this,
simpa only [this] },
{ apply hN,
apply le_of_lt, apply lt_of_not_ge, apply hle, exact le_rfl }}
end⟩
variables {p : ℕ} [fact p.prime] (f : cau_seq _ (@padic_norm_e p _))
open classical
private lemma div_nat_pos (n : ℕ) : 0 < (1 / ((n + 1): ℚ)) :=
div_pos zero_lt_one (by exact_mod_cast succ_pos _)
/-- `lim_seq f`, for `f` a Cauchy sequence of `p`-adic numbers,
is a sequence of rationals with the same limit point as `f`. -/
def lim_seq : ℕ → ℚ := λ n, classical.some (rat_dense' (f n) (div_nat_pos n))
lemma exi_rat_seq_conv {ε : ℚ} (hε : 0 < ε) :
∃ N, ∀ i ≥ N, padic_norm_e (f i - ((lim_seq f) i : ℚ_[p])) < ε :=
begin
refine (exists_nat_gt (1/ε)).imp (λ N hN i hi, _),
have h := classical.some_spec (rat_dense' (f i) (div_nat_pos i)),
refine lt_of_lt_of_le h ((div_le_iff' $ by exact_mod_cast succ_pos _).mpr _),
rw right_distrib,
apply le_add_of_le_of_nonneg,
{ exact (div_le_iff hε).mp (le_trans (le_of_lt hN) (by exact_mod_cast hi)) },
{ apply le_of_lt, simpa }
end
lemma exi_rat_seq_conv_cauchy : is_cau_seq (padic_norm p) (lim_seq f) :=
assume ε hε,
have hε3 : 0 < ε / 3, from div_pos hε (by norm_num),
let ⟨N, hN⟩ := exi_rat_seq_conv f hε3,
⟨N2, hN2⟩ := f.cauchy₂ hε3 in
begin
existsi max N N2,
intros j hj,
suffices :
padic_norm_e ((↑(lim_seq f j) - f (max N N2)) + (f (max N N2) - lim_seq f (max N N2))) < ε,
{ ring_nf at this ⊢,
rw [← padic_norm_e.eq_padic_norm', ← padic.cast_eq_of_rat],
exact_mod_cast this },
{ apply lt_of_le_of_lt,
{ apply padic_norm_e.add },
{ have : (3 : ℚ) ≠ 0, by norm_num,
have : ε = ε / 3 + ε / 3 + ε / 3,
{ field_simp [this], simp only [bit0, bit1, mul_add, mul_one] },
rw this,
apply add_lt_add,
{ suffices : padic_norm_e ((↑(lim_seq f j) - f j) + (f j - f (max N N2))) < ε / 3 + ε / 3,
by simpa only [sub_add_sub_cancel],
apply lt_of_le_of_lt,
{ apply padic_norm_e.add },
{ apply add_lt_add,
{ rw [padic_norm_e.sub_rev],
apply_mod_cast hN,
exact le_of_max_le_left hj },
{ apply hN2,
exact le_of_max_le_right hj,
apply le_max_right }}},
{ apply_mod_cast hN,
apply le_max_left }}}
end
private def lim' : padic_seq p := ⟨_, exi_rat_seq_conv_cauchy f⟩
private def lim : ℚ_[p] := ⟦lim' f⟧
theorem complete' : ∃ q : ℚ_[p], ∀ ε > 0, ∃ N, ∀ i ≥ N, padic_norm_e (q - f i) < ε :=
⟨ lim f,
λ ε hε,
let ⟨N, hN⟩ := exi_rat_seq_conv f (show 0 < ε / 2, from div_pos hε (by norm_num)),
⟨N2, hN2⟩ := padic_norm_e.defn (lim' f) (show 0 < ε / 2, from div_pos hε (by norm_num)) in
begin
existsi max N N2,
intros i hi,
suffices : padic_norm_e ((lim f - lim' f i) + (lim' f i - f i)) < ε,
{ ring_nf at this; exact this },
{ apply lt_of_le_of_lt,
{ apply padic_norm_e.add },
{ have : ε = ε / 2 + ε / 2, by rw ←(add_self_div_two ε); simp,
rw this,
apply add_lt_add,
{ apply hN2, exact le_of_max_le_right hi },
{ rw_mod_cast [padic_norm_e.sub_rev],
apply hN,
exact le_of_max_le_left hi }}}
end ⟩
end complete
section normed_space
variables (p : ℕ) [fact p.prime]
instance : has_dist ℚ_[p] := ⟨λ x y, padic_norm_e (x - y)⟩
instance : metric_space ℚ_[p] :=
{ dist_self := by simp [dist],
dist_comm := λ x y, by unfold dist; rw ←padic_norm_e.neg (x - y); simp,
dist_triangle :=
begin
intros, unfold dist,
exact_mod_cast padic_norm_e.triangle_ineq _ _ _,
end,
eq_of_dist_eq_zero :=
begin
unfold dist, intros _ _ h,
apply eq_of_sub_eq_zero,
apply (padic_norm_e.zero_iff _).1,
exact_mod_cast h
end }
instance : has_norm ℚ_[p] := ⟨λ x, padic_norm_e x⟩
instance : normed_field ℚ_[p] :=
{ dist_eq := λ _ _, rfl,
norm_mul' := by simp [has_norm.norm, padic_norm_e.mul'] }
instance is_absolute_value : is_absolute_value (λ a : ℚ_[p], ∥a∥) :=
{ abv_nonneg := norm_nonneg,
abv_eq_zero := λ _, norm_eq_zero,
abv_add := norm_add_le,
abv_mul := by simp [has_norm.norm, padic_norm_e.mul'] }
theorem rat_dense {p : ℕ} {hp : fact p.prime} (q : ℚ_[p]) {ε : ℝ} (hε : 0 < ε) :
∃ r : ℚ, ∥q - r∥ < ε :=
let ⟨ε', hε'l, hε'r⟩ := exists_rat_btwn hε,
⟨r, hr⟩ := rat_dense' q (by simpa using hε'l) in
⟨r, lt_trans (by simpa [has_norm.norm] using hr) hε'r⟩
end normed_space
end padic
namespace padic_norm_e
section normed_space
variables {p : ℕ} [hp : fact p.prime]
include hp
@[simp] protected lemma mul (q r : ℚ_[p]) : ∥q * r∥ = ∥q∥ * ∥r∥ :=
by simp [has_norm.norm, padic_norm_e.mul']
protected lemma is_norm (q : ℚ_[p]) : ↑(padic_norm_e q) = ∥q∥ := rfl
theorem nonarchimedean (q r : ℚ_[p]) : ∥q + r∥ ≤ max (∥q∥) (∥r∥) :=
begin
unfold has_norm.norm,
exact_mod_cast nonarchimedean' _ _
end
theorem add_eq_max_of_ne {q r : ℚ_[p]} (h : ∥q∥ ≠ ∥r∥) : ∥q+r∥ = max (∥q∥) (∥r∥) :=
begin
unfold has_norm.norm,
apply_mod_cast add_eq_max_of_ne',
intro h',
apply h,
unfold has_norm.norm,
exact_mod_cast h'
end
@[simp] lemma eq_padic_norm (q : ℚ) : ∥(↑q : ℚ_[p])∥ = padic_norm p q :=
begin
unfold has_norm.norm,
rw [← padic_norm_e.eq_padic_norm', ← padic.cast_eq_of_rat]
end
@[simp] lemma norm_p : ∥(p : ℚ_[p])∥ = p⁻¹ :=
begin
have p₀ : p ≠ 0 := hp.1.ne_zero,
have p₁ : p ≠ 1 := hp.1.ne_one,
simp [p₀, p₁, norm, padic_norm, padic_val_rat, zpow_neg, padic.cast_eq_of_rat_of_nat],
end
lemma norm_p_lt_one : ∥(p : ℚ_[p])∥ < 1 :=
begin
rw norm_p,
apply inv_lt_one,
exact_mod_cast hp.1.one_lt
end
@[simp] lemma norm_p_pow (n : ℤ) : ∥(p^n : ℚ_[p])∥ = p^-n :=
by rw [normed_field.norm_zpow, norm_p]; field_simp
instance : nondiscrete_normed_field ℚ_[p] :=
{ non_trivial := ⟨p⁻¹, begin
rw [normed_field.norm_inv, norm_p, inv_inv₀],
exact_mod_cast hp.1.one_lt
end⟩ }
protected theorem image {q : ℚ_[p]} : q ≠ 0 → ∃ n : ℤ, ∥q∥ = ↑((↑p : ℚ) ^ (-n)) :=
quotient.induction_on q $ λ f hf,
have ¬ f ≈ 0, from (padic_seq.ne_zero_iff_nequiv_zero f).1 hf,
let ⟨n, hn⟩ := padic_seq.norm_values_discrete f this in
⟨n, congr_arg coe hn⟩
protected lemma is_rat (q : ℚ_[p]) : ∃ q' : ℚ, ∥q∥ = ↑q' :=
if h : q = 0 then ⟨0, by simp [h]⟩
else let ⟨n, hn⟩ := padic_norm_e.image h in ⟨_, hn⟩
/--`rat_norm q`, for a `p`-adic number `q` is the `p`-adic norm of `q`, as rational number.
The lemma `padic_norm_e.eq_rat_norm` asserts `∥q∥ = rat_norm q`. -/
def rat_norm (q : ℚ_[p]) : ℚ := classical.some (padic_norm_e.is_rat q)
lemma eq_rat_norm (q : ℚ_[p]) : ∥q∥ = rat_norm q := classical.some_spec (padic_norm_e.is_rat q)
theorem norm_rat_le_one : ∀ {q : ℚ} (hq : ¬ p ∣ q.denom), ∥(q : ℚ_[p])∥ ≤ 1
| ⟨n, d, hn, hd⟩ := λ hq : ¬ p ∣ d,
if hnz : n = 0 then
have (⟨n, d, hn, hd⟩ : ℚ) = 0,
from rat.zero_iff_num_zero.mpr hnz,
by norm_num [this]
else
begin
have hnz' : { rat . num := n, denom := d, pos := hn, cop := hd } ≠ 0,
from mt rat.zero_iff_num_zero.1 hnz,
rw [padic_norm_e.eq_padic_norm],
norm_cast,
rw [padic_norm.eq_zpow_of_nonzero p hnz', padic_val_rat_def p hnz'],
have h : (multiplicity p d).get _ = 0, by simp [multiplicity_eq_zero_of_not_dvd, hq],
simp only, norm_cast,
rw_mod_cast [h, sub_zero],
apply zpow_le_one_of_nonpos,
{ exact_mod_cast le_of_lt hp.1.one_lt, },
{ apply neg_nonpos_of_nonneg, norm_cast, simp, }
end
theorem norm_int_le_one (z : ℤ) : ∥(z : ℚ_[p])∥ ≤ 1 :=
suffices ∥((z : ℚ) : ℚ_[p])∥ ≤ 1, by simpa,
norm_rat_le_one $ by simp [hp.1.ne_one]
lemma norm_int_lt_one_iff_dvd (k : ℤ) : ∥(k : ℚ_[p])∥ < 1 ↔ ↑p ∣ k :=
begin
split,
{ intro h,
contrapose! h,
apply le_of_eq,
rw eq_comm,
calc ∥(k : ℚ_[p])∥ = ∥((k : ℚ) : ℚ_[p])∥ : by { norm_cast }
... = padic_norm p k : padic_norm_e.eq_padic_norm _
... = 1 : _,
rw padic_norm,
split_ifs with H,
{ exfalso,
apply h,
norm_cast at H,
rw H,
apply dvd_zero },
{ norm_cast at H ⊢,
convert zpow_zero _,
simp only [neg_eq_zero],
rw padic_val_rat.padic_val_rat_of_int _ hp.1.ne_one H,
norm_cast,
rw [← enat.coe_inj, enat.coe_get, nat.cast_zero],
apply multiplicity.multiplicity_eq_zero_of_not_dvd h } },
{ rintro ⟨x, rfl⟩,
push_cast,
rw padic_norm_e.mul,
calc _ ≤ ∥(p : ℚ_[p])∥ * 1 : mul_le_mul le_rfl (by simpa using norm_int_le_one _)
(norm_nonneg _) (norm_nonneg _)
... < 1 : _,
{ rw [mul_one, padic_norm_e.norm_p],
apply inv_lt_one,
exact_mod_cast hp.1.one_lt }, },
end
lemma norm_int_le_pow_iff_dvd (k : ℤ) (n : ℕ) : ∥(k : ℚ_[p])∥ ≤ ((↑p)^(-n : ℤ)) ↔ ↑(p^n) ∣ k :=
begin
have : (p : ℝ) ^ (-n : ℤ) = ↑((p ^ (-n : ℤ) : ℚ)), {simp},
rw [show (k : ℚ_[p]) = ((k : ℚ) : ℚ_[p]), by norm_cast, eq_padic_norm, this],
norm_cast,
rw padic_norm.dvd_iff_norm_le,
end
lemma eq_of_norm_add_lt_right {p : ℕ} {hp : fact p.prime} {z1 z2 : ℚ_[p]}
(h : ∥z1 + z2∥ < ∥z2∥) : ∥z1∥ = ∥z2∥ :=
by_contradiction $ λ hne,
not_lt_of_ge (by rw padic_norm_e.add_eq_max_of_ne hne; apply le_max_right) h
lemma eq_of_norm_add_lt_left {p : ℕ} {hp : fact p.prime} {z1 z2 : ℚ_[p]}
(h : ∥z1 + z2∥ < ∥z1∥) : ∥z1∥ = ∥z2∥ :=
by_contradiction $ λ hne,
not_lt_of_ge (by rw padic_norm_e.add_eq_max_of_ne hne; apply le_max_left) h
end normed_space
end padic_norm_e
namespace padic
variables {p : ℕ} [hp_prime : fact p.prime]
include hp_prime
set_option eqn_compiler.zeta true
instance complete : cau_seq.is_complete ℚ_[p] norm :=
begin
split, intro f,
have cau_seq_norm_e : is_cau_seq padic_norm_e f,
{ intros ε hε,
let h := is_cau f ε (by exact_mod_cast hε),
unfold norm at h,
apply_mod_cast h },
cases padic.complete' ⟨f, cau_seq_norm_e⟩ with q hq,
existsi q,
intros ε hε,
cases exists_rat_btwn hε with ε' hε',
norm_cast at hε',
cases hq ε' hε'.1 with N hN, existsi N,
intros i hi, let h := hN i hi,
unfold norm,
rw_mod_cast [cau_seq.sub_apply, padic_norm_e.sub_rev],
refine lt_trans _ hε'.2,
exact_mod_cast hN i hi
end
lemma padic_norm_e_lim_le {f : cau_seq ℚ_[p] norm} {a : ℝ} (ha : 0 < a)
(hf : ∀ i, ∥f i∥ ≤ a) : ∥f.lim∥ ≤ a :=
let ⟨N, hN⟩ := setoid.symm (cau_seq.equiv_lim f) _ ha in
calc ∥f.lim∥ = ∥f.lim - f N + f N∥ : by simp
... ≤ max (∥f.lim - f N∥) (∥f N∥) : padic_norm_e.nonarchimedean _ _
... ≤ a : max_le (le_of_lt (hN _ le_rfl)) (hf _)
/-!
### Valuation on `ℚ_[p]`
-/
/--
`padic.valuation` lifts the p-adic valuation on rationals to `ℚ_[p]`.
-/
def valuation : ℚ_[p] → ℤ :=
quotient.lift (@padic_seq.valuation p _) (λ f g h,
begin
by_cases hf : f ≈ 0,
{ have hg : g ≈ 0, from setoid.trans (setoid.symm h) hf,
simp [hf, hg, padic_seq.valuation] },
{ have hg : ¬ g ≈ 0, from (λ hg, hf (setoid.trans h hg)),
rw padic_seq.val_eq_iff_norm_eq hf hg,
exact padic_seq.norm_equiv h },
end)
@[simp] lemma valuation_zero : valuation (0 : ℚ_[p]) = 0 :=
dif_pos ((const_equiv p).2 rfl)
@[simp] lemma valuation_one : valuation (1 : ℚ_[p]) = 0 :=
begin
change dite (cau_seq.const (padic_norm p) 1 ≈ _) _ _ = _,
have h : ¬ cau_seq.const (padic_norm p) 1 ≈ 0,
{ assume H, erw const_equiv p at H, exact one_ne_zero H },
rw dif_neg h,
simp,
end
lemma norm_eq_pow_val {x : ℚ_[p]} : x ≠ 0 → ∥x∥ = p^(-x.valuation) :=
begin
apply quotient.induction_on' x, clear x,
intros f hf,
change (padic_seq.norm _ : ℝ) = (p : ℝ) ^ -padic_seq.valuation _,
rw padic_seq.norm_eq_pow_val,
change ↑((p : ℚ) ^ -padic_seq.valuation f) = (p : ℝ) ^ -padic_seq.valuation f,
{ rw rat.cast_zpow,
congr' 1,
norm_cast },
{ apply cau_seq.not_lim_zero_of_not_congr_zero,
contrapose! hf,
apply quotient.sound,
simpa using hf, }
end
@[simp] lemma valuation_p : valuation (p : ℚ_[p]) = 1 :=
begin
have h : (1 : ℝ) < p := by exact_mod_cast (fact.out p.prime).one_lt,
rw ← neg_inj,
apply (zpow_strict_mono h).injective,
dsimp only,
rw ← norm_eq_pow_val,
{ simp },
{ exact_mod_cast (fact.out p.prime).ne_zero }
end
section norm_le_iff
/-! ### Various characterizations of open unit balls -/
lemma norm_le_pow_iff_norm_lt_pow_add_one (x : ℚ_[p]) (n : ℤ) :
∥x∥ ≤ p ^ n ↔ ∥x∥ < p ^ (n + 1) :=
begin
have aux : ∀ n : ℤ, 0 < (p ^ n : ℝ),
{ apply nat.zpow_pos_of_pos, exact hp_prime.1.pos },
by_cases hx0 : x = 0, { simp [hx0, norm_zero, aux, le_of_lt (aux _)], },
rw norm_eq_pow_val hx0,
have h1p : 1 < (p : ℝ), { exact_mod_cast hp_prime.1.one_lt },
have H := zpow_strict_mono h1p,
rw [H.le_iff_le, H.lt_iff_lt, int.lt_add_one_iff],
end
lemma norm_lt_pow_iff_norm_le_pow_sub_one (x : ℚ_[p]) (n : ℤ) :
∥x∥ < p ^ n ↔ ∥x∥ ≤ p ^ (n - 1) :=
by rw [norm_le_pow_iff_norm_lt_pow_add_one, sub_add_cancel]
end norm_le_iff
end padic
|
37106f7bfdfc26dd4785ddf62e90b6e403638bb8 | 8e2026ac8a0660b5a490dfb895599fb445bb77a0 | /tests/lean/run/default_param2.lean | 7ede3a526f4abac40c0d20b08fcee1ca5b14b845 | [
"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 | 1,073 | lean | universe variable u
def f (a : nat) (o : nat := 5) :=
a + o
example : f 1 = f 1 5 :=
rfl
#check f 1
structure config :=
(v1 := 10)
(v2 := 20)
(flag := tt)
(ps := ["hello", "world"])
def g (a : nat) (c : config := {}) : nat :=
if c^.flag then a + c^.v1 else a + c^.v2
example : g 1 = 11 :=
rfl
example : g 1 {flag := ff} = 21 :=
rfl
example : g 1 {v1 := 100} = 101 :=
rfl
def h (a : nat) (c : config := {v1 := a}) : nat :=
g a c
example : h 2 = 4 :=
rfl
example : h 3 = 6 :=
rfl
example : h 2 {flag := ff} = 22 :=
rfl
def boo (a : nat) (b : nat := a) (c : bool := ff) (d : config := {v2 := b, flag := c}) :=
g a d
#check boo 2
example : boo 2 = 4 :=
rfl
example : boo 2 20 = 22 :=
rfl
example : boo 2 0 tt = 12 :=
rfl
open tactic
set_option pp.all true
meta def check_expr (p : pexpr) (t : expr) : tactic unit :=
do e ← to_expr p, guard (t = e)
run_cmd do
e ← to_expr `(boo 2),
check_expr `(boo 2 (2:nat) ff {v1 := config.v1._default, v2 := 2, flag := ff, ps := config.ps._default}) e,
e ← to_expr `(f 1),
check_expr `(f 1 (5:nat)) e
|
1b8dd48439004b367ceae5b3136e9aed0cb64ff5 | 3863d2564418bccb1859e057bf5a4ef240e75fd7 | /hott/hit/quotient.hlean | 94968740c215fbc9718527e6fd46190f6d91732a | [
"Apache-2.0"
] | permissive | JacobGross/lean | 118bbb067ff4d4af48a266face2c7eb9868fa91c | eb26087df940c54337cb807b4bc6d345d1fc1085 | refs/heads/master | 1,582,735,011,532 | 1,462,557,826,000 | 1,462,557,826,000 | 46,451,196 | 0 | 0 | null | 1,462,557,826,000 | 1,447,885,161,000 | C++ | UTF-8 | Lean | false | false | 7,860 | 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
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 ⬝ _,
rewrite [apo011_eq_apo11_apd, rec_eq_of_rel, ▸*, apo011_arrow_pathover_constant_right,
↑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
|
58f6297ab30c40485eacae5d56c05170f37500e6 | 618003631150032a5676f229d13a079ac875ff77 | /src/order/conditionally_complete_lattice.lean | d3570f4ea341d192b3ecd60acf74f3f5867287e7 | [
"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 | 27,894 | lean | /-
Copyright (c) 2018 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import data.nat.enat
/-!
# Theory of conditionally complete lattices.
A conditionally complete lattice is a lattice in which every non-empty bounded subset s
has a least upper bound and a greatest lower bound, denoted below by Sup s and Inf s.
Typical examples are real, nat, int with their usual orders.
The theory is very comparable to the theory of complete lattices, except that suitable
boundedness and nonemptiness assumptions have to be added to most statements.
We introduce two predicates bdd_above and bdd_below to express this boundedness, prove
their basic properties, and then go on to prove most useful properties of Sup and Inf
in conditionally complete lattices.
To differentiate the statements between complete lattices and conditionally complete
lattices, we prefix Inf and Sup in the statements by c, giving cInf and cSup. For instance,
Inf_le is a statement in complete lattices ensuring Inf s ≤ x, while cInf_le is the same
statement in conditionally complete lattices with an additional assumption that s is
bounded below.
-/
set_option old_structure_cmd true
open set
universes u v w
variables {α : Type u} {β : Type v} {ι : Sort w}
section
/-!
Extension of Sup and Inf from a preorder `α` to `with_top α` and `with_bot α`
-/
open_locale classical
noncomputable instance {α : Type*} [preorder α] [has_Sup α] : has_Sup (with_top α) :=
⟨λ S, if ⊤ ∈ S then ⊤ else
if bdd_above (coe ⁻¹' S : set α) then ↑(Sup (coe ⁻¹' S : set α)) else ⊤⟩
noncomputable instance {α : Type*} [has_Inf α] : has_Inf (with_top α) :=
⟨λ S, if S ⊆ {⊤} then ⊤ else ↑(Inf (coe ⁻¹' S : set α))⟩
noncomputable instance {α : Type*} [has_Sup α] : has_Sup (with_bot α) :=
⟨(@with_top.has_Inf (order_dual α) _).Inf⟩
noncomputable instance {α : Type*} [preorder α] [has_Inf α] : has_Inf (with_bot α) :=
⟨(@with_top.has_Sup (order_dual α) _ _).Sup⟩
end -- section
section prio
set_option default_priority 100 -- see Note [default priority]
/-- A conditionally complete lattice is a lattice in which
every nonempty subset which is bounded above has a supremum, and
every nonempty subset which is bounded below has an infimum.
Typical examples are real numbers or natural numbers.
To differentiate the statements from the corresponding statements in (unconditional)
complete lattices, we prefix Inf and Sup by a c everywhere. The same statements should
hold in both worlds, sometimes with additional assumptions of nonemptiness or
boundedness.-/
class conditionally_complete_lattice (α : Type u) extends lattice α, has_Sup α, has_Inf α :=
(le_cSup : ∀s a, bdd_above s → a ∈ s → a ≤ Sup s)
(cSup_le : ∀ s a, set.nonempty s → a ∈ upper_bounds s → Sup s ≤ a)
(cInf_le : ∀s a, bdd_below s → a ∈ s → Inf s ≤ a)
(le_cInf : ∀s a, set.nonempty s → a ∈ lower_bounds s → a ≤ Inf s)
class conditionally_complete_linear_order (α : Type u)
extends conditionally_complete_lattice α, decidable_linear_order α
class conditionally_complete_linear_order_bot (α : Type u)
extends conditionally_complete_lattice α, decidable_linear_order α, order_bot α :=
(cSup_empty : Sup ∅ = ⊥)
end prio
/- A complete lattice is a conditionally complete lattice, as there are no restrictions
on the properties of Inf and Sup in a complete lattice.-/
@[priority 100] -- see Note [lower instance priority]
instance conditionally_complete_lattice_of_complete_lattice [complete_lattice α]:
conditionally_complete_lattice α :=
{ le_cSup := by intros; apply le_Sup; assumption,
cSup_le := by intros; apply Sup_le; assumption,
cInf_le := by intros; apply Inf_le; assumption,
le_cInf := by intros; apply le_Inf; assumption,
..‹complete_lattice α› }
@[priority 100] -- see Note [lower instance priority]
instance conditionally_complete_linear_order_of_complete_linear_order [complete_linear_order α]:
conditionally_complete_linear_order α :=
{ ..conditionally_complete_lattice_of_complete_lattice, .. ‹complete_linear_order α› }
section conditionally_complete_lattice
variables [conditionally_complete_lattice α] {s t : set α} {a b : α}
theorem le_cSup (h₁ : bdd_above s) (h₂ : a ∈ s) : a ≤ Sup s :=
conditionally_complete_lattice.le_cSup s a h₁ h₂
theorem cSup_le (h₁ : s.nonempty) (h₂ : ∀b∈s, b ≤ a) : Sup s ≤ a :=
conditionally_complete_lattice.cSup_le s a h₁ h₂
theorem cInf_le (h₁ : bdd_below s) (h₂ : a ∈ s) : Inf s ≤ a :=
conditionally_complete_lattice.cInf_le s a h₁ h₂
theorem le_cInf (h₁ : s.nonempty) (h₂ : ∀b∈s, a ≤ b) : a ≤ Inf s :=
conditionally_complete_lattice.le_cInf s a h₁ h₂
theorem le_cSup_of_le (_ : bdd_above s) (hb : b ∈ s) (h : a ≤ b) : a ≤ Sup s :=
le_trans h (le_cSup ‹bdd_above s› hb)
theorem cInf_le_of_le (_ : bdd_below s) (hb : b ∈ s) (h : b ≤ a) : Inf s ≤ a :=
le_trans (cInf_le ‹bdd_below s› hb) h
theorem cSup_le_cSup (_ : bdd_above t) (_ : s.nonempty) (h : s ⊆ t) : Sup s ≤ Sup t :=
cSup_le ‹_› (assume (a) (ha : a ∈ s), le_cSup ‹bdd_above t› (h ha))
theorem cInf_le_cInf (_ : bdd_below t) (_ : s.nonempty) (h : s ⊆ t) : Inf t ≤ Inf s :=
le_cInf ‹_› (assume (a) (ha : a ∈ s), cInf_le ‹bdd_below t› (h ha))
lemma is_lub_cSup (ne : s.nonempty) (H : bdd_above s) : is_lub s (Sup s) :=
⟨assume x, le_cSup H, assume x, cSup_le ne⟩
lemma is_glb_cInf (ne : s.nonempty) (H : bdd_below s) : is_glb s (Inf s) :=
⟨assume x, cInf_le H, assume x, le_cInf ne⟩
lemma is_lub.cSup_eq (H : is_lub s a) (ne : s.nonempty) : Sup s = a :=
(is_lub_cSup ne ⟨a, H.1⟩).unique H
/-- A greatest element of a set is the supremum of this set. -/
lemma is_greatest.cSup_eq (H : is_greatest s a) : Sup s = a :=
H.is_lub.cSup_eq H.nonempty
lemma is_glb.cInf_eq (H : is_glb s a) (ne : s.nonempty) : Inf s = a :=
(is_glb_cInf ne ⟨a, H.1⟩).unique H
/-- A least element of a set is the infimum of this set. -/
lemma is_least.cInf_eq (H : is_least s a) : Inf s = a :=
H.is_glb.cInf_eq H.nonempty
theorem cSup_le_iff (hb : bdd_above s) (ne : s.nonempty) : Sup s ≤ a ↔ (∀b ∈ s, b ≤ a) :=
is_lub_le_iff (is_lub_cSup ne hb)
theorem le_cInf_iff (hb : bdd_below s) (ne : s.nonempty) : a ≤ Inf s ↔ (∀b ∈ s, a ≤ b) :=
le_is_glb_iff (is_glb_cInf ne hb)
lemma cSup_lower_bounds_eq_cInf {s : set α} (h : bdd_below s) (hs : s.nonempty) :
Sup (lower_bounds s) = Inf s :=
(is_lub_cSup h $ hs.mono $ λ x hx y hy, hy hx).unique (is_glb_cInf hs h).is_lub
lemma cInf_upper_bounds_eq_cSup {s : set α} (h : bdd_above s) (hs : s.nonempty) :
Inf (upper_bounds s) = Sup s :=
(is_glb_cInf h $ hs.mono $ λ x hx y hy, hy hx).unique (is_lub_cSup hs h).is_glb
/--Introduction rule to prove that b is the supremum of s: it suffices to check that b
is larger than all elements of s, and that this is not the case of any `w<b`.-/
theorem cSup_intro (_ : s.nonempty) (_ : ∀a∈s, a ≤ b) (H : ∀w, w < b → (∃a∈s, w < a)) : Sup s = b :=
have bdd_above s := ⟨b, by assumption⟩,
have (Sup s < b) ∨ (Sup s = b) := lt_or_eq_of_le (cSup_le ‹_› ‹∀a∈s, a ≤ b›),
have ¬(Sup s < b) :=
assume: Sup s < b,
let ⟨a, _, _⟩ := (H (Sup s) ‹Sup s < b›) in /- a ∈ s, Sup s < a-/
have Sup s < Sup s := lt_of_lt_of_le ‹Sup s < a› (le_cSup ‹bdd_above s› ‹a ∈ s›),
show false, by finish [lt_irrefl (Sup s)],
show Sup s = b, by finish
/--Introduction rule to prove that b is the infimum of s: it suffices to check that b
is smaller than all elements of s, and that this is not the case of any `w>b`.-/
theorem cInf_intro (_ : s.nonempty) (_ : ∀a∈s, b ≤ a) (H : ∀w, b < w → (∃a∈s, a < w)) : Inf s = b :=
have bdd_below s := ⟨b, by assumption⟩,
have (b < Inf s) ∨ (b = Inf s) := lt_or_eq_of_le (le_cInf ‹_› ‹∀a∈s, b ≤ a›),
have ¬(b < Inf s) :=
assume: b < Inf s,
let ⟨a, _, _⟩ := (H (Inf s) ‹b < Inf s›) in /- a ∈ s, a < Inf s-/
have Inf s < Inf s := lt_of_le_of_lt (cInf_le ‹bdd_below s› ‹a ∈ s›) ‹a < Inf s› ,
show false, by finish [lt_irrefl (Inf s)],
show Inf s = b, by finish
/--b < Sup s when there is an element a in s with b < a, when s is bounded above.
This is essentially an iff, except that the assumptions for the two implications are
slightly different (one needs boundedness above for one direction, nonemptiness and linear
order for the other one), so we formulate separately the two implications, contrary to
the complete_lattice case.-/
lemma lt_cSup_of_lt (_ : bdd_above s) (_ : a ∈ s) (_ : b < a) : b < Sup s :=
lt_of_lt_of_le ‹b < a› (le_cSup ‹bdd_above s› ‹a ∈ s›)
/--Inf s < b when there is an element a in s with a < b, when s is bounded below.
This is essentially an iff, except that the assumptions for the two implications are
slightly different (one needs boundedness below for one direction, nonemptiness and linear
order for the other one), so we formulate separately the two implications, contrary to
the complete_lattice case.-/
lemma cInf_lt_of_lt (_ : bdd_below s) (_ : a ∈ s) (_ : a < b) : Inf s < b :=
lt_of_le_of_lt (cInf_le ‹bdd_below s› ‹a ∈ s›) ‹a < b›
/-- If all elements of a nonempty set `s` are less than or equal to all elements
of a nonempty set `t`, then there exists an element between these sets. -/
lemma exists_between_of_forall_le (sne : s.nonempty) (tne : t.nonempty)
(hst : ∀ (x ∈ s) (y ∈ t), x ≤ y) :
(upper_bounds s ∩ lower_bounds t).nonempty :=
⟨Inf t, λ x hx, le_cInf tne $ hst x hx, λ y hy, cInf_le (sne.mono hst) hy⟩
/--The supremum of a singleton is the element of the singleton-/
@[simp] theorem cSup_singleton (a : α) : Sup {a} = a :=
is_greatest_singleton.cSup_eq
/--The infimum of a singleton is the element of the singleton-/
@[simp] theorem cInf_singleton (a : α) : Inf {a} = a :=
is_least_singleton.cInf_eq
/--If a set is bounded below and above, and nonempty, its infimum is less than or equal to
its supremum.-/
theorem cInf_le_cSup (hb : bdd_below s) (ha : bdd_above s) (ne : s.nonempty) : Inf s ≤ Sup s :=
is_glb_le_is_lub (is_glb_cInf ne hb) (is_lub_cSup ne ha) ne
/--The sup of a union of two sets is the max of the suprema of each subset, under the assumptions
that all sets are bounded above and nonempty.-/
theorem cSup_union (hs : bdd_above s) (sne : s.nonempty) (ht : bdd_above t) (tne : t.nonempty) :
Sup (s ∪ t) = Sup s ⊔ Sup t :=
((is_lub_cSup sne hs).union (is_lub_cSup tne ht)).cSup_eq sne.inl
/--The inf of a union of two sets is the min of the infima of each subset, under the assumptions
that all sets are bounded below and nonempty.-/
theorem cInf_union (hs : bdd_below s) (sne : s.nonempty) (ht : bdd_below t) (tne : t.nonempty) :
Inf (s ∪ t) = Inf s ⊓ Inf t :=
((is_glb_cInf sne hs).union (is_glb_cInf tne ht)).cInf_eq sne.inl
/--The supremum of an intersection of two sets is bounded by the minimum of the suprema of each
set, if all sets are bounded above and nonempty.-/
theorem cSup_inter_le (_ : bdd_above s) (_ : bdd_above t) (hst : (s ∩ t).nonempty) :
Sup (s ∩ t) ≤ Sup s ⊓ Sup t :=
begin
apply cSup_le hst, simp only [le_inf_iff, and_imp, set.mem_inter_eq], intros b _ _, split,
apply le_cSup ‹bdd_above s› ‹b ∈ s›,
apply le_cSup ‹bdd_above t› ‹b ∈ t›
end
/--The infimum of an intersection of two sets is bounded below by the maximum of the
infima of each set, if all sets are bounded below and nonempty.-/
theorem le_cInf_inter (_ : bdd_below s) (_ : bdd_below t) (hst : (s ∩ t).nonempty) :
Inf s ⊔ Inf t ≤ Inf (s ∩ t) :=
begin
apply le_cInf hst, simp only [and_imp, set.mem_inter_eq, sup_le_iff], intros b _ _, split,
apply cInf_le ‹bdd_below s› ‹b ∈ s›,
apply cInf_le ‹bdd_below t› ‹b ∈ t›
end
/-- The supremum of insert a s is the maximum of a and the supremum of s, if s is
nonempty and bounded above.-/
theorem cSup_insert (hs : bdd_above s) (sne : s.nonempty) : Sup (insert a s) = a ⊔ Sup s :=
((is_lub_cSup sne hs).insert a).cSup_eq (insert_nonempty a s)
/-- The infimum of insert a s is the minimum of a and the infimum of s, if s is
nonempty and bounded below.-/
theorem cInf_insert (hs : bdd_below s) (sne : s.nonempty) : Inf (insert a s) = a ⊓ Inf s :=
((is_glb_cInf sne hs).insert a).cInf_eq (insert_nonempty a s)
@[simp] lemma cInf_Ici : Inf (Ici a) = a := is_least_Ici.cInf_eq
@[simp] lemma cSup_Iic : Sup (Iic a) = a := is_greatest_Iic.cSup_eq
/--The indexed supremum of two functions are comparable if the functions are pointwise comparable-/
lemma csupr_le_csupr {f g : ι → α} (B : bdd_above (range g)) (H : ∀x, f x ≤ g x) :
supr f ≤ supr g :=
begin
classical, by_cases hι : nonempty ι,
{ have Rf : (range f).nonempty := range_nonempty _,
apply cSup_le Rf,
rintros y ⟨x, rfl⟩,
have : g x ∈ range g := ⟨x, rfl⟩,
exact le_cSup_of_le B this (H x) },
{ have Rf : range f = ∅, from range_eq_empty.2 hι,
have Rg : range g = ∅, from range_eq_empty.2 hι,
unfold supr, rw [Rf, Rg] }
end
/--The indexed supremum of a function is bounded above by a uniform bound-/
lemma csupr_le [nonempty ι] {f : ι → α} {c : α} (H : ∀x, f x ≤ c) : supr f ≤ c :=
cSup_le (range_nonempty f) (by rwa forall_range_iff)
/--The indexed supremum of a function is bounded below by the value taken at one point-/
lemma le_csupr {f : ι → α} (H : bdd_above (range f)) (c : ι) : f c ≤ supr f :=
le_cSup H (mem_range_self _)
/--The indexed infimum of two functions are comparable if the functions are pointwise comparable-/
lemma cinfi_le_cinfi {f g : ι → α} (B : bdd_below (range f)) (H : ∀x, f x ≤ g x) :
infi f ≤ infi g :=
begin
classical, by_cases hι : nonempty ι,
{ have Rg : (range g).nonempty, from range_nonempty _,
apply le_cInf Rg,
rintros y ⟨x, rfl⟩,
have : f x ∈ range f := ⟨x, rfl⟩,
exact cInf_le_of_le B this (H x) },
{ have Rf : range f = ∅, from range_eq_empty.2 hι,
have Rg : range g = ∅, from range_eq_empty.2 hι,
unfold infi, rw [Rf, Rg] }
end
/--The indexed minimum of a function is bounded below by a uniform lower bound-/
lemma le_cinfi [nonempty ι] {f : ι → α} {c : α} (H : ∀x, c ≤ f x) : c ≤ infi f :=
le_cInf (range_nonempty f) (by rwa forall_range_iff)
/--The indexed infimum of a function is bounded above by the value taken at one point-/
lemma cinfi_le {f : ι → α} (H : bdd_below (range f)) (c : ι) : infi f ≤ f c :=
cInf_le H (mem_range_self _)
@[simp] theorem cinfi_const [hι : nonempty ι] {a : α} : (⨅ b:ι, a) = a :=
by rw [infi, range_const, cInf_singleton]
@[simp] theorem csupr_const [hι : nonempty ι] {a : α} : (⨆ b:ι, a) = a :=
by rw [supr, range_const, cSup_singleton]
end conditionally_complete_lattice
section conditionally_complete_linear_order
variables [conditionally_complete_linear_order α] {s t : set α} {a b : α}
/-- When b < Sup s, there is an element a in s with b < a, if s is nonempty and the order is
a linear order. -/
lemma exists_lt_of_lt_cSup (hs : s.nonempty) (hb : b < Sup s) : ∃a∈s, b < a :=
begin
classical, contrapose! hb,
exact cSup_le hs hb
end
/--
Indexed version of the above lemma `exists_lt_of_lt_cSup`.
When `b < supr f`, there is an element `i` such that `b < f i`.
-/
lemma exists_lt_of_lt_csupr [nonempty ι] {f : ι → α} (h : b < supr f) :
∃i, b < f i :=
let ⟨_, ⟨i, rfl⟩, h⟩ := exists_lt_of_lt_cSup (range_nonempty f) h in ⟨i, h⟩
/--When Inf s < b, there is an element a in s with a < b, if s is nonempty and the order is
a linear order.-/
lemma exists_lt_of_cInf_lt (hs : s.nonempty) (hb : Inf s < b) : ∃a∈s, a < b :=
begin
classical, contrapose! hb,
exact le_cInf hs hb
end
/--
Indexed version of the above lemma `exists_lt_of_cInf_lt`
When `infi f < a`, there is an element `i` such that `f i < a`.
-/
lemma exists_lt_of_cinfi_lt [nonempty ι] {f : ι → α} (h : infi f < a) :
(∃i, f i < a) :=
let ⟨_, ⟨i, rfl⟩, h⟩ := exists_lt_of_cInf_lt (range_nonempty f) h in ⟨i, h⟩
/--Introduction rule to prove that b is the supremum of s: it suffices to check that
1) b is an upper bound
2) every other upper bound b' satisfies b ≤ b'.-/
theorem cSup_intro' (_ : s.nonempty)
(h_is_ub : ∀ a ∈ s, a ≤ b) (h_b_le_ub : ∀ub, (∀ a ∈ s, a ≤ ub) → (b ≤ ub)) : Sup s = b :=
le_antisymm
(show Sup s ≤ b, from cSup_le ‹s.nonempty› h_is_ub)
(show b ≤ Sup s, from h_b_le_ub _ $ assume a, le_cSup ⟨b, h_is_ub⟩)
end conditionally_complete_linear_order
section conditionally_complete_linear_order_bot
lemma cSup_empty [conditionally_complete_linear_order_bot α] : (Sup ∅ : α) = ⊥ :=
conditionally_complete_linear_order_bot.cSup_empty
end conditionally_complete_linear_order_bot
section
open_locale classical
noncomputable instance : has_Inf ℕ :=
⟨λs, if h : ∃n, n ∈ s then @nat.find (λn, n ∈ s) _ h else 0⟩
noncomputable instance : has_Sup ℕ :=
⟨λs, if h : ∃n, ∀a∈s, a ≤ n then @nat.find (λn, ∀a∈s, a ≤ n) _ h else 0⟩
lemma Inf_nat_def {s : set ℕ} (h : ∃n, n ∈ s) : Inf s = @nat.find (λn, n ∈ s) _ h :=
dif_pos _
lemma Sup_nat_def {s : set ℕ} (h : ∃n, ∀a∈s, a ≤ n) :
Sup s = @nat.find (λn, ∀a∈s, a ≤ n) _ h :=
dif_pos _
/-- This instance is necessary, otherwise the lattice operations would be derived via
conditionally_complete_linear_order_bot and marked as noncomputable. -/
instance : lattice ℕ := infer_instance
noncomputable instance : conditionally_complete_linear_order_bot ℕ :=
{ Sup := Sup, Inf := Inf,
le_cSup := assume s a hb ha, by rw [Sup_nat_def hb]; revert a ha; exact @nat.find_spec _ _ hb,
cSup_le := assume s a hs ha, by rw [Sup_nat_def ⟨a, ha⟩]; exact nat.find_min' _ ha,
le_cInf := assume s a hs hb,
by rw [Inf_nat_def hs]; exact hb (@nat.find_spec (λn, n ∈ s) _ _),
cInf_le := assume s a hb ha, by rw [Inf_nat_def ⟨a, ha⟩]; exact nat.find_min' _ ha,
cSup_empty :=
begin
simp only [Sup_nat_def, set.mem_empty_eq, forall_const, forall_prop_of_false, not_false_iff, exists_const],
apply bot_unique (nat.find_min' _ _),
trivial
end,
.. (infer_instance : order_bot ℕ), .. (infer_instance : lattice ℕ),
.. (infer_instance : decidable_linear_order ℕ) }
end
namespace with_top
open_locale classical
variables [conditionally_complete_linear_order_bot α]
/-- The Sup of a non-empty set is its least upper bound for a conditionally
complete lattice with a top. -/
lemma is_lub_Sup' {β : Type*} [conditionally_complete_lattice β]
{s : set (with_top β)} (hs : s.nonempty) : is_lub s (Sup s) :=
begin
split,
{ show ite _ _ _ ∈ _,
split_ifs,
{ intros _ _, exact le_top },
{ rintro (⟨⟩|a) ha,
{ contradiction },
apply some_le_some.2,
exact le_cSup h_1 ha },
{ intros _ _, exact le_top } },
{ show ite _ _ _ ∈ _,
split_ifs,
{ rintro (⟨⟩|a) ha,
{ exact _root_.le_refl _ },
{ exact false.elim (not_top_le_coe a (ha h)) } },
{ rintro (⟨⟩|b) hb,
{ exact le_top },
refine some_le_some.2 (cSup_le _ _),
{ rcases hs with ⟨⟨⟩|b, hb⟩,
{ exact absurd hb h },
{ exact ⟨b, hb⟩ } },
{ intros a ha, exact some_le_some.1 (hb ha) } },
{ rintro (⟨⟩|b) hb,
{ exact _root_.le_refl _ },
{ exfalso, apply h_1, use b, intros a ha, exact some_le_some.1 (hb ha) } } }
end
lemma is_lub_Sup (s : set (with_top α)) : is_lub s (Sup s) :=
begin
cases s.eq_empty_or_nonempty with hs hs,
{ rw hs,
show is_lub ∅ (ite _ _ _),
split_ifs,
{ cases h },
{ rw [preimage_empty, cSup_empty], exact is_lub_empty },
{ exfalso, apply h_1, use ⊥, rintro a ⟨⟩ } },
exact is_lub_Sup' hs,
end
/-- The Inf of a bounded-below set is its greatest lower bound for a conditionally
complete lattice with a top. -/
lemma is_glb_Inf' {β : Type*} [conditionally_complete_lattice β]
{s : set (with_top β)} (hs : bdd_below s) : is_glb s (Inf s) :=
begin
split,
{ show ite _ _ _ ∈ _,
split_ifs,
{ intros a ha, exact top_le_iff.2 (set.mem_singleton_iff.1 (h ha)) },
{ rintro (⟨⟩|a) ha,
{ exact le_top },
refine some_le_some.2 (cInf_le _ ha),
rcases hs with ⟨⟨⟩|b, hb⟩,
{ exfalso,
apply h,
intros c hc,
rw [mem_singleton_iff, ←top_le_iff],
exact hb hc },
use b,
intros c hc,
exact some_le_some.1 (hb hc) } },
{ show ite _ _ _ ∈ _,
split_ifs,
{ intros _ _, exact le_top },
{ rintro (⟨⟩|a) ha,
{ exfalso, apply h, intros b hb, exact set.mem_singleton_iff.2 (top_le_iff.1 (ha hb)) },
{ refine some_le_some.2 (le_cInf _ _),
{ classical, contrapose! h,
rintros (⟨⟩|a) ha,
{ exact mem_singleton ⊤ },
{ exact (h ⟨a, ha⟩).elim }},
{ intros b hb,
rw ←some_le_some,
exact ha hb } } } }
end
lemma is_glb_Inf (s : set (with_top α)) : is_glb s (Inf s) :=
begin
by_cases hs : bdd_below s,
{ exact is_glb_Inf' hs },
{ exfalso, apply hs, use ⊥, intros _ _, exact bot_le },
end
noncomputable instance : complete_linear_order (with_top α) :=
{ Sup := Sup, le_Sup := assume s, (is_lub_Sup s).1, Sup_le := assume s, (is_lub_Sup s).2,
Inf := Inf, le_Inf := assume s, (is_glb_Inf s).2, Inf_le := assume s, (is_glb_Inf s).1,
decidable_le := classical.dec_rel _,
.. with_top.linear_order, ..with_top.lattice, ..with_top.order_top, ..with_top.order_bot }
lemma coe_Sup {s : set α} (hb : bdd_above s) : (↑(Sup s) : with_top α) = (⨆a∈s, ↑a) :=
begin
cases s.eq_empty_or_nonempty with hs hs,
{ rw [hs, cSup_empty], simp only [set.mem_empty_eq, supr_bot, supr_false], refl },
apply le_antisymm,
{ refine ((coe_le_iff _ _).2 $ assume b hb, cSup_le hs $ assume a has, coe_le_coe.1 $ hb ▸ _),
exact (le_supr_of_le a $ le_supr_of_le has $ _root_.le_refl _) },
{ exact (supr_le $ assume a, supr_le $ assume ha, coe_le_coe.2 $ le_cSup hb ha) }
end
lemma coe_Inf {s : set α} (hs : s.nonempty) : (↑(Inf s) : with_top α) = (⨅a∈s, ↑a) :=
let ⟨x, hx⟩ := hs in
have (⨅a∈s, ↑a : with_top α) ≤ x, from infi_le_of_le x $ infi_le_of_le hx $ _root_.le_refl _,
let ⟨r, r_eq, hr⟩ := (le_coe_iff _ _).1 this in
le_antisymm
(le_infi $ assume a, le_infi $ assume ha, coe_le_coe.2 $ cInf_le (order_bot.bdd_below s) ha)
begin
refine (r_eq.symm ▸ coe_le_coe.2 $ le_cInf hs $ assume a has, coe_le_coe.1 $ _),
refine (r_eq ▸ infi_le_of_le a _),
exact (infi_le_of_le has $ _root_.le_refl _),
end
end with_top
namespace enat
open_locale classical
noncomputable instance : complete_linear_order enat :=
{ Sup := λ s, with_top_equiv.symm $ Sup (with_top_equiv '' s),
Inf := λ s, with_top_equiv.symm $ Inf (with_top_equiv '' s),
le_Sup := by intros; rw ← with_top_equiv_le; simp; apply le_Sup _; simpa,
Inf_le := by intros; rw ← with_top_equiv_le; simp; apply Inf_le _; simpa,
Sup_le := begin
intros s a h1,
rw [← with_top_equiv_le, with_top_equiv.right_inverse_symm],
apply Sup_le _,
rintros b ⟨x, h2, rfl⟩,
rw with_top_equiv_le,
apply h1,
assumption
end,
le_Inf := begin
intros s a h1,
rw [← with_top_equiv_le, with_top_equiv.right_inverse_symm],
apply le_Inf _,
rintros b ⟨x, h2, rfl⟩,
rw with_top_equiv_le,
apply h1,
assumption
end,
..enat.decidable_linear_order,
..enat.bounded_lattice }
end enat
section order_dual
instance (α : Type*) [conditionally_complete_lattice α] :
conditionally_complete_lattice (order_dual α) :=
{ le_cSup := @cInf_le α _,
cSup_le := @le_cInf α _,
le_cInf := @cSup_le α _,
cInf_le := @le_cSup α _,
..order_dual.has_Inf α,
..order_dual.has_Sup α,
..order_dual.lattice α }
instance (α : Type*) [conditionally_complete_linear_order α] :
conditionally_complete_linear_order (order_dual α) :=
{ ..order_dual.conditionally_complete_lattice α,
..order_dual.decidable_linear_order α }
end order_dual
section with_top_bot
/-!
### Complete lattice structure on `with_top (with_bot α)`
If `α` is a `conditionally_complete_lattice`, then we show that `with_top α` and `with_bot α`
also inherit the structure of conditionally complete lattices. Furthermore, we show
that `with_top (with_bot α)` naturally inherits the structure of a complete lattice. Note that
for α a conditionally complete lattice, `Sup` and `Inf` both return junk values
for sets which are empty or unbounded. The extension of `Sup` to `with_top α` fixes
the unboundedness problem and the extension to `with_bot α` fixes the problem with
the empty set.
This result can be used to show that the extended reals [-∞, ∞] are a complete lattice.
-/
open_locale classical
/-- Adding a top element to a conditionally complete lattice gives a conditionally complete lattice -/
noncomputable instance with_top.conditionally_complete_lattice
{α : Type*} [conditionally_complete_lattice α] :
conditionally_complete_lattice (with_top α) :=
{ le_cSup := λ S a hS haS, (with_top.is_lub_Sup' ⟨a, haS⟩).1 haS,
cSup_le := λ S a hS haS, (with_top.is_lub_Sup' hS).2 haS,
cInf_le := λ S a hS haS, (with_top.is_glb_Inf' hS).1 haS,
le_cInf := λ S a hS haS, (with_top.is_glb_Inf' ⟨a, haS⟩).2 haS,
..with_top.lattice,
..with_top.has_Sup,
..with_top.has_Inf }
/-- Adding a bottom element to a conditionally complete lattice gives a conditionally complete lattice -/
noncomputable instance with_bot.conditionally_complete_lattice
{α : Type*} [conditionally_complete_lattice α] :
conditionally_complete_lattice (with_bot α) :=
{ le_cSup := (@with_top.conditionally_complete_lattice (order_dual α) _).cInf_le,
cSup_le := (@with_top.conditionally_complete_lattice (order_dual α) _).le_cInf,
cInf_le := (@with_top.conditionally_complete_lattice (order_dual α) _).le_cSup,
le_cInf := (@with_top.conditionally_complete_lattice (order_dual α) _).cSup_le,
..with_bot.lattice,
..with_bot.has_Sup,
..with_bot.has_Inf }
/-- Adding a bottom and a top to a conditionally complete lattice gives a bounded lattice-/
noncomputable instance with_top.with_bot.bounded_lattice {α : Type*}
[conditionally_complete_lattice α] : bounded_lattice (with_top (with_bot α)) :=
{ ..with_top.order_bot,
..with_top.order_top,
..conditionally_complete_lattice.to_lattice _ }
theorem with_bot.cSup_empty {α : Type*} [conditionally_complete_lattice α] :
Sup (∅ : set (with_bot α)) = ⊥ :=
begin
show ite _ _ _ = ⊥,
split_ifs; finish,
end
noncomputable instance with_top.with_bot.complete_lattice {α : Type*}
[conditionally_complete_lattice α] : complete_lattice (with_top (with_bot α)) :=
{ le_Sup := λ S a haS, (with_top.is_lub_Sup' ⟨a, haS⟩).1 haS,
Sup_le := λ S a ha,
begin
cases S.eq_empty_or_nonempty with h,
{ show ite _ _ _ ≤ a,
split_ifs,
{ rw h at h_1, cases h_1 },
{ convert bot_le, convert with_bot.cSup_empty, rw h, refl },
{ exfalso, apply h_2, use ⊥, rw h, rintro b ⟨⟩ } },
{ refine (with_top.is_lub_Sup' h).2 ha }
end,
Inf_le := λ S a haS,
show ite _ _ _ ≤ a,
begin
split_ifs,
{ cases a with a, exact _root_.le_refl _,
cases (h haS); tauto },
{ cases a,
{ exact le_top },
{ apply with_top.some_le_some.2, refine cInf_le _ haS, use ⊥, intros b hb, exact bot_le } }
end,
le_Inf := λ S a haS, (with_top.is_glb_Inf' ⟨a, haS⟩).2 haS,
..with_top.has_Inf,
..with_top.has_Sup,
..with_top.with_bot.bounded_lattice }
end with_top_bot
|
c422afc2e8a85f597a72f5eed805d1acd15b9142 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/algebra/direct_sum_graded.lean | df7bf434b8d10ae296708e36522ccc059d6ad04a | [
"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 | 25,821 | lean | /-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import algebra.direct_sum
import algebra.algebra.basic
import algebra.algebra.operations
import group_theory.subgroup
/-!
# Additively-graded multiplicative structures on `⨁ i, A i`
This module provides a set of heterogeneous typeclasses for defining a multiplicative structure
over `⨁ i, A i` such that `(*) : A i → A j → A (i + j)`; that is to say, `A` forms an
additively-graded ring. The typeclasses are:
* `direct_sum.ghas_one A`
* `direct_sum.ghas_mul A`
* `direct_sum.gmonoid A`
* `direct_sum.gcomm_monoid A`
Respectively, these imbue the direct sum `⨁ i, A i` with:
* `direct_sum.has_one`
* `direct_sum.non_unital_non_assoc_semiring`
* `direct_sum.semiring`, `direct_sum.ring`
* `direct_sum.comm_semiring`, `direct_sum.comm_ring`
the base ring `A 0` with:
* `direct_sum.grade_zero.has_one`
* `direct_sum.grade_zero.non_unital_non_assoc_semiring`
* `direct_sum.grade_zero.semiring`, `direct_sum.grade_zero.ring`
* `direct_sum.grade_zero.comm_semiring`, `direct_sum.grade_zero.comm_ring`
and the `i`th grade `A i` with `A 0`-actions (`•`) defined as left-multiplication:
* (nothing)
* `direct_sum.grade_zero.has_scalar (A 0)`, `direct_sum.grade_zero.smul_with_zero (A 0)`
* `direct_sum.grade_zero.module (A 0)`
* (nothing)
Note that in the presence of these instances, `⨁ i, A i` itself inherits an `A 0`-action.
`direct_sum.of_zero_ring_hom : A 0 →+* ⨁ i, A i` provides `direct_sum.of A 0` as a ring
homomorphism.
`direct_sum.to_semiring` extends `direct_sum.to_add_monoid` to produce a `ring_hom`.
## Direct sums of subobjects
Additionally, this module provides helper functions to construct `gmonoid` and `gcomm_monoid`
instances for:
* `A : ι → submonoid S`:
`direct_sum.ghas_one.of_add_submonoids`, `direct_sum.ghas_mul.of_add_submonoids`,
`direct_sum.gmonoid.of_add_submonoids`, `direct_sum.gcomm_monoid.of_add_submonoids`.
* `A : ι → subgroup S`:
`direct_sum.ghas_one.of_add_subgroups`, `direct_sum.ghas_mul.of_add_subgroups`,
`direct_sum.gmonoid.of_add_subgroups`, `direct_sum.gcomm_monoid.of_add_subgroups`.
* `A : ι → submodule S`:
`direct_sum.ghas_one.of_submodules`, `direct_sum.ghas_mul.of_submodules`,
`direct_sum.gmonoid.of_submodules`, `direct_sum.gcomm_monoid.of_submodules`.
If `complete_lattice.independent (set.range A)`, these provide a gradation of `⨆ i, A i`, and the
mapping `⨁ i, A i →+ ⨆ i, A i` can be obtained as
`direct_sum.to_monoid (λ i, add_submonoid.inclusion $ le_supr A i)`.
## tags
graded ring, filtered ring, direct sum, add_submonoid
-/
variables {ι : Type*} [decidable_eq ι]
namespace direct_sum
open_locale direct_sum
/-! ### Typeclasses -/
section defs
variables (A : ι → Type*)
/-- A graded version of `has_one`, which must be of grade 0. -/
class ghas_one [has_zero ι] :=
(one : A 0)
/-- A graded version of `has_mul` that also subsumes `non_unital_non_assoc_semiring` by requiring
the multiplication be an `add_monoid_hom`. Multiplication combines grades additively, like
`add_monoid_algebra`. -/
class ghas_mul [has_add ι] [Π i, add_comm_monoid (A i)] :=
(mul {i j} : A i →+ A j →+ A (i + j))
variables {A}
/-- `direct_sum.ghas_one` implies a `has_one (Σ i, A i)`, although this is only used as an instance
locally to define notation in `direct_sum.gmonoid`. -/
def ghas_one.to_sigma_has_one [has_zero ι] [ghas_one A] : has_one (Σ i, A i) := ⟨⟨_, ghas_one.one⟩⟩
/-- `direct_sum.ghas_mul` implies a `has_mul (Σ i, A i)`, although this is only used as an instance
locally to define notation in `direct_sum.gmonoid`. -/
def ghas_mul.to_sigma_has_mul [has_add ι] [Π i, add_comm_monoid (A i)] [ghas_mul A] :
has_mul (Σ i, A i) :=
⟨λ (x y : Σ i, A i), ⟨_, ghas_mul.mul x.snd y.snd⟩⟩
end defs
section defs
variables (A : ι → Type*)
local attribute [instance] ghas_one.to_sigma_has_one
local attribute [instance] ghas_mul.to_sigma_has_mul
/-- A graded version of `monoid`. -/
class gmonoid [add_monoid ι] [Π i, add_comm_monoid (A i)] extends ghas_mul A, ghas_one A :=
(one_mul (a : Σ i, A i) : 1 * a = a)
(mul_one (a : Σ i, A i) : a * 1 = a)
(mul_assoc (a : Σ i, A i) (b : Σ i, A i) (c : Σ i, A i) : a * b * c = a * (b * c))
/-- A graded version of `comm_monoid`. -/
class gcomm_monoid [add_comm_monoid ι] [Π i, add_comm_monoid (A i)] extends gmonoid A :=
(mul_comm (a : Σ i, A i) (b : Σ i, A i) : a * b = b * a)
end defs
/-! ### Shorthands for creating the above typeclasses -/
section shorthands
variables {R : Type*}
/-! #### From `add_submonoid`s -/
/-- Build a `ghas_one` instance for a collection of `add_submonoid`s. -/
@[simps one]
def ghas_one.of_add_submonoids [semiring R] [has_zero ι]
(carriers : ι → add_submonoid R)
(one_mem : (1 : R) ∈ carriers 0) :
ghas_one (λ i, carriers i) :=
{ one := ⟨1, one_mem⟩ }
-- `@[simps]` doesn't generate a useful lemma, so we state one manually below.
/-- Build a `ghas_mul` instance for a collection of `add_submonoids`. -/
def ghas_mul.of_add_submonoids [semiring R] [has_add ι]
(carriers : ι → add_submonoid R)
(mul_mem : ∀ ⦃i j⦄ (gi : carriers i) (gj : carriers j), (gi * gj : R) ∈ carriers (i + j)) :
ghas_mul (λ i, carriers i) :=
{ mul := λ i j,
{ to_fun := λ a,
{ to_fun := λ b, ⟨(a * b : R), mul_mem a b⟩,
map_add' := λ _ _, subtype.ext (mul_add _ _ _),
map_zero' := subtype.ext (mul_zero _), },
map_add' := λ _ _, add_monoid_hom.ext $ λ _, subtype.ext (add_mul _ _ _),
map_zero' := add_monoid_hom.ext $ λ _, subtype.ext (zero_mul _) }, }
-- `@[simps]` doesn't generate this well
@[simp] lemma ghas_mul.of_add_submonoids_mul [semiring R] [has_add ι]
(carriers : ι → add_submonoid R) (mul_mem) {i j} (a : carriers i) (b : carriers j) :
@ghas_mul.mul _ _ _ _ _ (ghas_mul.of_add_submonoids carriers mul_mem) i j a b =
⟨a * b, mul_mem a b⟩ := rfl
/-- Build a `gmonoid` instance for a collection of `add_submonoid`s. -/
@[simps to_ghas_one to_ghas_mul]
def gmonoid.of_add_submonoids [semiring R] [add_monoid ι]
(carriers : ι → add_submonoid R)
(one_mem : (1 : R) ∈ carriers 0)
(mul_mem : ∀ ⦃i j⦄ (gi : carriers i) (gj : carriers j), (gi * gj : R) ∈ carriers (i + j)) :
gmonoid (λ i, carriers i) :=
{ one_mul := λ ⟨i, a, h⟩, sigma.subtype_ext (zero_add _) (one_mul _),
mul_one := λ ⟨i, a, h⟩, sigma.subtype_ext (add_zero _) (mul_one _),
mul_assoc := λ ⟨i, a, ha⟩ ⟨j, b, hb⟩ ⟨k, c, hc⟩,
sigma.subtype_ext (add_assoc _ _ _) (mul_assoc _ _ _),
..ghas_one.of_add_submonoids carriers one_mem,
..ghas_mul.of_add_submonoids carriers mul_mem }
/-- Build a `gcomm_monoid` instance for a collection of `add_submonoid`s. -/
@[simps to_gmonoid]
def gcomm_monoid.of_add_submonoids [comm_semiring R] [add_comm_monoid ι]
(carriers : ι → add_submonoid R)
(one_mem : (1 : R) ∈ carriers 0)
(mul_mem : ∀ ⦃i j⦄ (gi : carriers i) (gj : carriers j), (gi * gj : R) ∈ carriers (i + j)) :
gcomm_monoid (λ i, carriers i) :=
{ mul_comm := λ ⟨i, a, ha⟩ ⟨j, b, hb⟩, sigma.subtype_ext (add_comm _ _) (mul_comm _ _),
..gmonoid.of_add_submonoids carriers one_mem mul_mem}
/-! #### From `add_subgroup`s -/
/-- Build a `ghas_one` instance for a collection of `add_subgroup`s. -/
@[simps one]
def ghas_one.of_add_subgroups [ring R] [has_zero ι]
(carriers : ι → add_subgroup R)
(one_mem : (1 : R) ∈ carriers 0) :
ghas_one (λ i, carriers i) :=
ghas_one.of_add_submonoids (λ i, (carriers i).to_add_submonoid) one_mem
-- `@[simps]` doesn't generate a useful lemma, so we state one manually below.
/-- Build a `ghas_mul` instance for a collection of `add_subgroup`s. -/
def ghas_mul.of_add_subgroups [ring R] [has_add ι]
(carriers : ι → add_subgroup R)
(mul_mem : ∀ ⦃i j⦄ (gi : carriers i) (gj : carriers j), (gi * gj : R) ∈ carriers (i + j)) :
ghas_mul (λ i, carriers i) :=
ghas_mul.of_add_submonoids (λ i, (carriers i).to_add_submonoid) mul_mem
-- `@[simps]` doesn't generate this well
@[simp] lemma ghas_mul.of_add_subgroups_mul [ring R] [has_add ι]
(carriers : ι → add_subgroup R) (mul_mem) {i j} (a : carriers i) (b : carriers j) :
@ghas_mul.mul _ _ _ _ _ (ghas_mul.of_add_subgroups carriers mul_mem) i j a b =
⟨a * b, mul_mem a b⟩ := rfl
/-- Build a `gmonoid` instance for a collection of `add_subgroup`s. -/
@[simps to_ghas_one to_ghas_mul]
def gmonoid.of_add_subgroups [ring R] [add_monoid ι]
(carriers : ι → add_subgroup R)
(one_mem : (1 : R) ∈ carriers 0)
(mul_mem : ∀ ⦃i j⦄ (gi : carriers i) (gj : carriers j), (gi * gj : R) ∈ carriers (i + j)) :
gmonoid (λ i, carriers i) :=
gmonoid.of_add_submonoids (λ i, (carriers i).to_add_submonoid) one_mem mul_mem
/-- Build a `gcomm_monoid` instance for a collection of `add_subgroup`s. -/
@[simps to_gmonoid]
def gcomm_monoid.of_add_subgroups [comm_ring R] [add_comm_monoid ι]
(carriers : ι → add_subgroup R)
(one_mem : (1 : R) ∈ carriers 0)
(mul_mem : ∀ ⦃i j⦄ (gi : carriers i) (gj : carriers j), (gi * gj : R) ∈ carriers (i + j)) :
gcomm_monoid (λ i, carriers i) :=
gcomm_monoid.of_add_submonoids (λ i, (carriers i).to_add_submonoid) one_mem mul_mem
/-! #### From `submodules`s -/
variables {A : Type*}
/-- Build a `ghas_one` instance for a collection of `submodule`s. -/
@[simps one]
def ghas_one.of_submodules
[comm_semiring R] [semiring A] [algebra R A] [has_zero ι]
(carriers : ι → submodule R A)
(one_mem : (1 : A) ∈ carriers 0) :
ghas_one (λ i, carriers i) :=
ghas_one.of_add_submonoids (λ i, (carriers i).to_add_submonoid) one_mem
-- `@[simps]` doesn't generate a useful lemma, so we state one manually below.
/-- Build a `ghas_mul` instance for a collection of `submodule`s. -/
def ghas_mul.of_submodules
[comm_semiring R] [semiring A] [algebra R A] [has_add ι]
(carriers : ι → submodule R A)
(mul_mem : ∀ ⦃i j⦄ (gi : carriers i) (gj : carriers j), (gi * gj : A) ∈ carriers (i + j)) :
ghas_mul (λ i, carriers i) :=
ghas_mul.of_add_submonoids (λ i, (carriers i).to_add_submonoid) mul_mem
-- `@[simps]` doesn't generate this well
@[simp] lemma ghas_mul.of_submodules_mul
[comm_semiring R] [semiring A] [algebra R A] [has_add ι]
(carriers : ι → submodule R A) (mul_mem) {i j} (a : carriers i) (b : carriers j) :
@ghas_mul.mul _ _ _ _ _ (ghas_mul.of_submodules carriers mul_mem) i j a b =
⟨a * b, mul_mem a b⟩ := rfl
/-- Build a `gmonoid` instance for a collection of `submodules`s. -/
@[simps to_ghas_one to_ghas_mul]
def gmonoid.of_submodules
[comm_semiring R] [semiring A] [algebra R A] [add_monoid ι]
(carriers : ι → submodule R A)
(one_mem : (1 : A) ∈ carriers 0)
(mul_mem : ∀ ⦃i j⦄ (gi : carriers i) (gj : carriers j), (gi * gj : A) ∈ carriers (i + j)) :
gmonoid (λ i, carriers i) :=
gmonoid.of_add_submonoids (λ i, (carriers i).to_add_submonoid) one_mem mul_mem
/-- Build a `gcomm_monoid` instance for a collection of `submodules`s. -/
@[simps to_gmonoid]
def gcomm_monoid.of_submodules
[comm_semiring R] [comm_semiring A] [algebra R A] [add_comm_monoid ι]
(carriers : ι → submodule R A)
(one_mem : (1 : A) ∈ carriers 0)
(mul_mem : ∀ ⦃i j⦄ (gi : carriers i) (gj : carriers j), (gi * gj : A) ∈ carriers (i + j)) :
gcomm_monoid (λ i, carriers i) :=
gcomm_monoid.of_add_submonoids (λ i, (carriers i).to_add_submonoid) one_mem mul_mem
end shorthands
variables (A : ι → Type*)
/-! ### Instances for `⨁ i, A i` -/
section one
variables [has_zero ι] [ghas_one A] [Π i, add_comm_monoid (A i)]
instance : has_one (⨁ i, A i) :=
{ one := direct_sum.of (λ i, A i) 0 ghas_one.one}
end one
section mul
variables [has_add ι] [Π i, add_comm_monoid (A i)] [ghas_mul A]
open add_monoid_hom (map_zero map_add flip_apply coe_comp comp_hom_apply_apply)
/-- The multiplication from the `has_mul` instance, as a bundled homomorphism. -/
def mul_hom : (⨁ i, A i) →+ (⨁ i, A i) →+ ⨁ i, A i :=
direct_sum.to_add_monoid $ λ i,
add_monoid_hom.flip $ direct_sum.to_add_monoid $ λ j, add_monoid_hom.flip $
(direct_sum.of A _).comp_hom.comp ghas_mul.mul
instance : non_unital_non_assoc_semiring (⨁ i, A i) :=
{ mul := λ a b, mul_hom A a b,
zero := 0,
add := (+),
zero_mul := λ a, by simp only [map_zero, add_monoid_hom.zero_apply],
mul_zero := λ a, by simp only [map_zero],
left_distrib := λ a b c, by simp only [map_add],
right_distrib := λ a b c, by simp only [map_add, add_monoid_hom.add_apply],
.. direct_sum.add_comm_monoid _ _}
variables {A}
lemma mul_hom_of_of {i j} (a : A i) (b : A j) :
mul_hom A (of _ i a) (of _ j b) = of _ (i + j) (ghas_mul.mul a b) :=
begin
unfold mul_hom,
rw [to_add_monoid_of, flip_apply, to_add_monoid_of, flip_apply, coe_comp, function.comp_app,
comp_hom_apply_apply, coe_comp, function.comp_app],
end
lemma of_mul_of {i j} (a : A i) (b : A j) :
of _ i a * of _ j b = of _ (i + j) (ghas_mul.mul a b) :=
mul_hom_of_of a b
end mul
section semiring
variables [Π i, add_comm_monoid (A i)] [add_monoid ι] [gmonoid A]
open add_monoid_hom (flip_hom coe_comp comp_hom_apply_apply flip_apply flip_hom_apply)
private lemma one_mul (x : ⨁ i, A i) : 1 * x = x :=
suffices mul_hom A 1 = add_monoid_hom.id (⨁ i, A i),
from add_monoid_hom.congr_fun this x,
begin
apply add_hom_ext, intros i xi,
unfold has_one.one,
rw mul_hom_of_of,
exact dfinsupp.single_eq_of_sigma_eq (gmonoid.one_mul ⟨i, xi⟩),
end
private lemma mul_one (x : ⨁ i, A i) : x * 1 = x :=
suffices (mul_hom A).flip 1 = add_monoid_hom.id (⨁ i, A i),
from add_monoid_hom.congr_fun this x,
begin
apply add_hom_ext, intros i xi,
unfold has_one.one,
rw [flip_apply, mul_hom_of_of],
exact dfinsupp.single_eq_of_sigma_eq (gmonoid.mul_one ⟨i, xi⟩),
end
private lemma mul_assoc (a b c : ⨁ i, A i) : a * b * c = a * (b * c) :=
suffices (mul_hom A).comp_hom.comp (mul_hom A) -- `λ a b c, a * b * c` as a bundled hom
= (add_monoid_hom.comp_hom flip_hom $ -- `λ a b c, a * (b * c)` as a bundled hom
(mul_hom A).flip.comp_hom.comp (mul_hom A)).flip,
from add_monoid_hom.congr_fun (add_monoid_hom.congr_fun (add_monoid_hom.congr_fun this a) b) c,
begin
ext ai ax bi bx ci cx : 6,
dsimp only [coe_comp, function.comp_app, comp_hom_apply_apply, flip_apply, flip_hom_apply],
rw [mul_hom_of_of, mul_hom_of_of, mul_hom_of_of, mul_hom_of_of],
exact dfinsupp.single_eq_of_sigma_eq (gmonoid.mul_assoc ⟨ai, ax⟩ ⟨bi, bx⟩ ⟨ci, cx⟩),
end
/-- The `semiring` structure derived from `gmonoid A`. -/
instance semiring : semiring (⨁ i, A i) := {
one := 1,
mul := (*),
zero := 0,
add := (+),
one_mul := one_mul A,
mul_one := mul_one A,
mul_assoc := mul_assoc A,
..direct_sum.non_unital_non_assoc_semiring _, }
end semiring
section comm_semiring
variables [Π i, add_comm_monoid (A i)] [add_comm_monoid ι] [gcomm_monoid A]
private lemma mul_comm (a b : ⨁ i, A i) : a * b = b * a :=
suffices mul_hom A = (mul_hom A).flip,
from add_monoid_hom.congr_fun (add_monoid_hom.congr_fun this a) b,
begin
apply add_hom_ext, intros ai ax, apply add_hom_ext, intros bi bx,
rw [add_monoid_hom.flip_apply, mul_hom_of_of, mul_hom_of_of],
exact dfinsupp.single_eq_of_sigma_eq (gcomm_monoid.mul_comm ⟨ai, ax⟩ ⟨bi, bx⟩),
end
/-- The `comm_semiring` structure derived from `gcomm_monoid A`. -/
instance comm_semiring : comm_semiring (⨁ i, A i) := {
one := 1,
mul := (*),
zero := 0,
add := (+),
mul_comm := mul_comm A,
..direct_sum.semiring _, }
end comm_semiring
section ring
variables [Π i, add_comm_group (A i)] [add_comm_monoid ι] [gmonoid A]
/-- The `ring` derived from `gmonoid A`. -/
instance ring : ring (⨁ i, A i) := {
one := 1,
mul := (*),
zero := 0,
add := (+),
neg := has_neg.neg,
..(direct_sum.semiring _),
..(direct_sum.add_comm_group _), }
end ring
section comm_ring
variables [Π i, add_comm_group (A i)] [add_comm_monoid ι] [gcomm_monoid A]
/-- The `comm_ring` derived from `gcomm_monoid A`. -/
instance comm_ring : comm_ring (⨁ i, A i) := {
one := 1,
mul := (*),
zero := 0,
add := (+),
neg := has_neg.neg,
..(direct_sum.ring _),
..(direct_sum.comm_semiring _), }
end comm_ring
/-! ### Instances for `A 0`
The various `g*` instances are enough to promote the `add_comm_monoid (A 0)` structure to various
types of multiplicative structure.
-/
section grade_zero
section one
variables [has_zero ι] [ghas_one A] [Π i, add_comm_monoid (A i)]
/-- `1 : A 0` is the value provided in `direct_sum.ghas_one.one`. -/
@[nolint unused_arguments]
instance grade_zero.has_one : has_one (A 0) :=
⟨ghas_one.one⟩
@[simp] lemma of_zero_one : of _ 0 (1 : A 0) = 1 := rfl
end one
section mul
variables [add_monoid ι] [Π i, add_comm_monoid (A i)] [ghas_mul A]
/-- `(•) : A 0 → A i → A i` is the value provided in `direct_sum.ghas_mul.mul`, composed with
an `eq.rec` to turn `A (0 + i)` into `A i`.
-/
instance grade_zero.has_scalar (i : ι) : has_scalar (A 0) (A i) :=
{ smul := λ x y, (zero_add i).rec (ghas_mul.mul x y) }
/-- `(*) : A 0 → A 0 → A 0` is the value provided in `direct_sum.ghas_mul.mul`, composed with
an `eq.rec` to turn `A (0 + 0)` into `A 0`.
-/
instance grade_zero.has_mul : has_mul (A 0) :=
{ mul := (•) }
@[simp]lemma grade_zero.smul_eq_mul (a b : A 0) : a • b = a * b := rfl
@[simp] lemma of_zero_smul {i} (a : A 0) (b : A i) : of _ _ (a • b) = of _ _ a * of _ _ b :=
begin
rw of_mul_of,
dsimp [has_mul.mul, direct_sum.of, dfinsupp.single_add_hom_apply],
congr' 1,
rw zero_add,
apply eq_rec_heq,
end
@[simp] lemma of_zero_mul (a b : A 0) : of _ 0 (a * b) = of _ 0 a * of _ 0 b:=
of_zero_smul A a b
instance grade_zero.non_unital_non_assoc_semiring : non_unital_non_assoc_semiring (A 0) :=
function.injective.non_unital_non_assoc_semiring (of A 0) dfinsupp.single_injective
(of A 0).map_zero (of A 0).map_add (of_zero_mul A)
instance grade_zero.smul_with_zero (i : ι) : smul_with_zero (A 0) (A i) :=
begin
letI := smul_with_zero.comp_hom (⨁ i, A i) (of A 0).to_zero_hom,
refine dfinsupp.single_injective.smul_with_zero (of A i).to_zero_hom (of_zero_smul A),
end
end mul
section semiring
variables [Π i, add_comm_monoid (A i)] [add_monoid ι] [gmonoid A]
/-- The `semiring` structure derived from `gmonoid A`. -/
instance grade_zero.semiring : semiring (A 0) :=
function.injective.semiring (of A 0) dfinsupp.single_injective
(of A 0).map_zero (of_zero_one A) (of A 0).map_add (of_zero_mul A)
/-- `of A 0` is a `ring_hom`, using the `direct_sum.grade_zero.semiring` structure. -/
def of_zero_ring_hom : A 0 →+* (⨁ i, A i) :=
{ map_one' := of_zero_one A, map_mul' := of_zero_mul A, ..(of _ 0) }
/-- Each grade `A i` derives a `A 0`-module structure from `gmonoid A`. Note that this results
in an overall `module (A 0) (⨁ i, A i)` structure via `direct_sum.module`.
-/
instance grade_zero.module {i} : module (A 0) (A i) :=
begin
letI := module.comp_hom (⨁ i, A i) (of_zero_ring_hom A),
exact dfinsupp.single_injective.module (A 0) (of A i) (λ a, of_zero_smul A a),
end
end semiring
section comm_semiring
variables [Π i, add_comm_monoid (A i)] [add_comm_monoid ι] [gcomm_monoid A]
/-- The `comm_semiring` structure derived from `gcomm_monoid A`. -/
instance grade_zero.comm_semiring : comm_semiring (A 0) :=
function.injective.comm_semiring (of A 0) dfinsupp.single_injective
(of A 0).map_zero (of_zero_one A) (of A 0).map_add (of_zero_mul A)
end comm_semiring
section ring
variables [Π i, add_comm_group (A i)] [add_comm_monoid ι] [gmonoid A]
/-- The `ring` derived from `gmonoid A`. -/
instance grade_zero.ring : ring (A 0) :=
function.injective.ring (of A 0) dfinsupp.single_injective
(of A 0).map_zero (of_zero_one A) (of A 0).map_add (of_zero_mul A)
(of A 0).map_neg (of A 0).map_sub
end ring
section comm_ring
variables [Π i, add_comm_group (A i)] [add_comm_monoid ι] [gcomm_monoid A]
/-- The `comm_ring` derived from `gcomm_monoid A`. -/
instance grade_zero.comm_ring : comm_ring (A 0) :=
function.injective.comm_ring (of A 0) dfinsupp.single_injective
(of A 0).map_zero (of_zero_one A) (of A 0).map_add (of_zero_mul A)
(of A 0).map_neg (of A 0).map_sub
end comm_ring
end grade_zero
section to_semiring
variables {R : Type*} [Π i, add_comm_monoid (A i)] [add_monoid ι] [gmonoid A] [semiring R]
variables {A}
/-- If two ring homomorphisms from `⨁ i, A i` are equal on each `of A i y`,
then they are equal.
See note [partially-applied ext lemmas]. -/
@[ext]
lemma ring_hom_ext' (F G : (⨁ i, A i) →+* R)
(h : ∀ i, (F : (⨁ i, A i) →+ R).comp (of _ i) = (G : (⨁ i, A i) →+ R).comp (of _ i)) : F = G :=
ring_hom.coe_add_monoid_hom_injective $ direct_sum.add_hom_ext' h
/-- A family of `add_monoid_hom`s preserving `direct_sum.ghas_one.one` and `direct_sum.ghas_mul.mul`
describes a `ring_hom`s on `⨁ i, A i`. This is a stronger version of `direct_sum.to_monoid`.
Of particular interest is the case when `A i` are bundled subojects, `f` is the family of
coercions such as `add_submonoid.subtype (A i)`, and the `[gmonoid A]` structure originates from
`direct_sum.gmonoid.of_add_submonoids`, in which case the proofs about `ghas_one` and `ghas_mul`
can be discharged by `rfl`. -/
@[simps]
def to_semiring
(f : Π i, A i →+ R) (hone : f _ (ghas_one.one) = 1)
(hmul : ∀ {i j} (ai : A i) (aj : A j), f _ (ghas_mul.mul ai aj) = f _ ai * f _ aj) :
(⨁ i, A i) →+* R :=
{ to_fun := to_add_monoid f,
map_one' := begin
change (to_add_monoid f) (of _ 0 _) = 1,
rw to_add_monoid_of,
exact hone
end,
map_mul' := begin
rw (to_add_monoid f).map_mul_iff,
ext xi xv yi yv : 4,
show to_add_monoid f (of A xi xv * of A yi yv) =
to_add_monoid f (of A xi xv) * to_add_monoid f (of A yi yv),
rw [of_mul_of, to_add_monoid_of, to_add_monoid_of, to_add_monoid_of],
exact hmul _ _,
end,
.. to_add_monoid f}
@[simp] lemma to_semiring_of (f : Π i, A i →+ R) (hone hmul) (i : ι) (x : A i) :
to_semiring f hone hmul (of _ i x) = f _ x :=
to_add_monoid_of f i x
@[simp] lemma to_semiring_coe_add_monoid_hom (f : Π i, A i →+ R) (hone hmul):
(to_semiring f hone hmul : (⨁ i, A i) →+ R) = to_add_monoid f := rfl
/-- Families of `add_monoid_hom`s preserving `direct_sum.ghas_one.one` and `direct_sum.ghas_mul.mul`
are isomorphic to `ring_hom`s on `⨁ i, A i`. This is a stronger version of `dfinsupp.lift_add_hom`.
-/
@[simps]
def lift_ring_hom :
{f : Π {i}, A i →+ R //
f (ghas_one.one) = 1 ∧
∀ {i j} (ai : A i) (aj : A j), f (ghas_mul.mul ai aj) = f ai * f aj} ≃
((⨁ i, A i) →+* R) :=
{ to_fun := λ f, to_semiring f.1 f.2.1 f.2.2,
inv_fun := λ F,
⟨λ i, (F : (⨁ i, A i) →+ R).comp (of _ i), begin
simp only [add_monoid_hom.comp_apply, ring_hom.coe_add_monoid_hom],
rw ←F.map_one,
refl
end, λ i j ai aj, begin
simp only [add_monoid_hom.comp_apply, ring_hom.coe_add_monoid_hom],
rw [←F.map_mul, of_mul_of],
end⟩,
left_inv := λ f, begin
ext xi xv,
exact to_add_monoid_of f.1 xi xv,
end,
right_inv := λ F, begin
apply ring_hom.coe_add_monoid_hom_injective,
ext xi xv,
simp only [ring_hom.coe_add_monoid_hom_mk,
direct_sum.to_add_monoid_of,
add_monoid_hom.mk_coe,
add_monoid_hom.comp_apply, to_semiring_coe_add_monoid_hom],
end}
end to_semiring
end direct_sum
/-! ### Concrete instances -/
/-- A direct sum of copies of a `semiring` inherits the multiplication structure. -/
instance semiring.direct_sum_gmonoid {R : Type*} [add_monoid ι] [semiring R] :
direct_sum.gmonoid (λ i : ι, R) :=
{ mul := λ i j, add_monoid_hom.mul,
one_mul := λ a, sigma.ext (zero_add _) (heq_of_eq (one_mul _)),
mul_one := λ a, sigma.ext (add_zero _) (heq_of_eq (mul_one _)),
mul_assoc := λ a b c, sigma.ext (add_assoc _ _ _) (heq_of_eq (mul_assoc _ _ _)),
one := 1 }
@[simp] lemma semiring.direct_sum_mul {R : Type*} [add_monoid ι] [semiring R] {i j} (x y : R) :
@direct_sum.ghas_mul.mul _ _ (λ _ : ι, R) _ _ _ i j x y = x * y := rfl
open_locale direct_sum
-- To check the lemma above does match
example {R : Type*} [add_monoid ι] [semiring R] (i j : ι) (a b : R) :
(direct_sum.of _ i a * direct_sum.of _ j b : ⨁ i, R) = direct_sum.of _ (i + j) (by exact a * b) :=
by rw [direct_sum.of_mul_of, semiring.direct_sum_mul]
/-- A direct sum of copies of a `comm_semiring` inherits the commutative multiplication structure.
-/
instance comm_semiring.direct_sum_gcomm_monoid {R : Type*} [add_comm_monoid ι] [comm_semiring R] :
direct_sum.gcomm_monoid (λ i : ι, R) :=
{ mul_comm := λ a b, sigma.ext (add_comm _ _) (heq_of_eq (mul_comm _ _)),
.. semiring.direct_sum_gmonoid }
namespace submodule
variables {R A : Type*} [comm_semiring R]
/-- A direct sum of powers of a submodule of an algebra has a multiplicative structure. -/
instance nat_power_direct_sum_gmonoid [semiring A] [algebra R A] (S : submodule R A) :
direct_sum.gmonoid (λ i : ℕ, ↥(S ^ i)) :=
direct_sum.gmonoid.of_submodules _
(by { rw [←one_le, pow_zero], exact le_rfl })
(λ i j p q, by { rw pow_add, exact submodule.mul_mem_mul p.prop q.prop })
/-- A direct sum of powers of a submodule of a commutative algebra has a commutative multiplicative
structure. -/
instance nat_power_direct_sum_gcomm_monoid [comm_semiring A] [algebra R A] (S : submodule R A) :
direct_sum.gcomm_monoid (λ i : ℕ, ↥(S ^ i)) :=
direct_sum.gcomm_monoid.of_submodules _
(by { rw [←one_le, pow_zero], exact le_rfl })
(λ i j p q, by { rw pow_add, exact submodule.mul_mem_mul p.prop q.prop })
end submodule
|
d3384f247a462cbd2d9c8a0ac56b61532138a4c1 | 9f1929110d7ce695e60c30a12c83161ea7eadc15 | /experiments/bench/repeat_econstructor_exists_1000_true.lean | d34507624f61f0fcfb18438fd46ff4221320f182 | [] | no_license | andres-erbsen/coq-experiments | 4820d05608c445eba0ea965e23bd9cf39a5c418f | 2018edd397a23c0429d316c96e86f9be7a9678f1 | refs/heads/master | 1,619,935,106,811 | 1,578,518,728,000 | 1,578,518,728,000 | 120,850,328 | 1 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 160 | lean | open nat
definition exn : nat → Prop
| exn 0 := true
| exn (n+1) := exists x : true, exn n
lemma exn_1000 : exn 1000 :=
begin
repeat (constructor)
end |
b458947bd57c3a12c22d740678f91588d05ca04b | 35b83be3126daae10419b573c55e1fed009d3ae8 | /_target/deps/mathlib/analysis/topology/topological_structures.lean | 2eb7b511f2ed8fd83cd79a320d93d82bc3a896b1 | [] | no_license | AHassan1024/Lean_Playground | ccb25b72029d199c0d23d002db2d32a9f2689ebc | a00b004c3a2eb9e3e863c361aa2b115260472414 | refs/heads/master | 1,586,221,905,125 | 1,544,951,310,000 | 1,544,951,310,000 | 157,934,290 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 54,345 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
Theory of topological monoids, groups and rings.
TODO: generalize `topological_monoid` and `topological_add_monoid` to semigroups, or add a type class
`topological_operator α (*)`.
-/
import order.liminf_limsup
import algebra.big_operators algebra.group algebra.pi_instances
import data.set.intervals data.equiv.algebra
import analysis.topology.topological_space analysis.topology.continuity analysis.topology.uniform_space
import ring_theory.ideals
open classical set lattice filter topological_space
local attribute [instance] classical.prop_decidable
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
section topological_monoid
/-- A topological monoid is a monoid in which the multiplication is continuous as a function
`α × α → α`. -/
class topological_monoid (α : Type u) [topological_space α] [monoid α] : Prop :=
(continuous_mul : continuous (λp:α×α, p.1 * p.2))
/-- A topological (additive) monoid is a monoid in which the addition is
continuous as a function `α × α → α`. -/
class topological_add_monoid (α : Type u) [topological_space α] [add_monoid α] : Prop :=
(continuous_add : continuous (λp:α×α, p.1 + p.2))
attribute [to_additive topological_add_monoid] topological_monoid
attribute [to_additive topological_add_monoid.mk] topological_monoid.mk
attribute [to_additive topological_add_monoid.continuous_add] topological_monoid.continuous_mul
section
variables [topological_space α] [monoid α] [topological_monoid α]
@[to_additive continuous_add']
lemma continuous_mul' : continuous (λp:α×α, p.1 * p.2) :=
topological_monoid.continuous_mul α
@[to_additive continuous_add]
lemma continuous_mul [topological_space β] {f : β → α} {g : β → α}
(hf : continuous f) (hg : continuous g) :
continuous (λx, f x * g x) :=
(hf.prod_mk hg).comp continuous_mul'
-- @[to_additive continuous_smul]
lemma continuous_pow : ∀ n : ℕ, continuous (λ a : α, a ^ n)
| 0 := by simpa using continuous_const
| (k+1) := show continuous (λ (a : α), a * a ^ k), from continuous_mul continuous_id (continuous_pow _)
@[to_additive tendsto_add']
lemma tendsto_mul' {a b : α} : tendsto (λp:α×α, p.fst * p.snd) (nhds (a, b)) (nhds (a * b)) :=
continuous_iff_tendsto.mp (topological_monoid.continuous_mul α) (a, b)
@[to_additive tendsto_add]
lemma tendsto_mul {f : β → α} {g : β → α} {x : filter β} {a b : α}
(hf : tendsto f x (nhds a)) (hg : tendsto g x (nhds b)) :
tendsto (λx, f x * g x) x (nhds (a * b)) :=
(hf.prod_mk hg).comp (by rw [←nhds_prod_eq]; exact tendsto_mul')
@[to_additive tendsto_list_sum]
lemma tendsto_list_prod {f : γ → β → α} {x : filter β} {a : γ → α} :
∀l:list γ, (∀c∈l, tendsto (f c) x (nhds (a c))) →
tendsto (λb, (l.map (λc, f c b)).prod) x (nhds ((l.map a).prod))
| [] _ := by simp [tendsto_const_nhds]
| (f :: l) h :=
begin
simp,
exact tendsto_mul
(h f (list.mem_cons_self _ _))
(tendsto_list_prod l (assume c hc, h c (list.mem_cons_of_mem _ hc)))
end
@[to_additive continuous_list_sum]
lemma continuous_list_prod [topological_space β] {f : γ → β → α} (l : list γ)
(h : ∀c∈l, continuous (f c)) :
continuous (λa, (l.map (λc, f c a)).prod) :=
continuous_iff_tendsto.2 $ assume x, tendsto_list_prod l $ assume c hc,
continuous_iff_tendsto.1 (h c hc) x
@[to_additive prod.topological_add_monoid]
instance [topological_space β] [monoid β] [topological_monoid β] : topological_monoid (α × β) :=
⟨continuous.prod_mk
(continuous_mul (continuous_fst.comp continuous_fst) (continuous_snd.comp continuous_fst))
(continuous_mul (continuous_fst.comp continuous_snd) (continuous_snd.comp continuous_snd)) ⟩
attribute [instance] prod.topological_add_monoid
end
section
variables [topological_space α] [comm_monoid α] [topological_monoid α]
@[to_additive tendsto_multiset_sum]
lemma tendsto_multiset_prod {f : γ → β → α} {x : filter β} {a : γ → α} (s : multiset γ) :
(∀c∈s, tendsto (f c) x (nhds (a c))) →
tendsto (λb, (s.map (λc, f c b)).prod) x (nhds ((s.map a).prod)) :=
by { rcases s with ⟨l⟩, simp, exact tendsto_list_prod l }
@[to_additive tendsto_finset_sum]
lemma tendsto_finset_prod {f : γ → β → α} {x : filter β} {a : γ → α} (s : finset γ) :
(∀c∈s, tendsto (f c) x (nhds (a c))) → tendsto (λb, s.prod (λc, f c b)) x (nhds (s.prod a)) :=
tendsto_multiset_prod _
@[to_additive continuous_multiset_sum]
lemma continuous_multiset_prod [topological_space β] {f : γ → β → α} (s : multiset γ) :
(∀c∈s, continuous (f c)) → continuous (λa, (s.map (λc, f c a)).prod) :=
by { rcases s with ⟨l⟩, simp, exact continuous_list_prod l }
@[to_additive continuous_finset_sum]
lemma continuous_finset_prod [topological_space β] {f : γ → β → α} (s : finset γ) :
(∀c∈s, continuous (f c)) → continuous (λa, s.prod (λc, f c a)) :=
continuous_multiset_prod _
end
end topological_monoid
section topological_group
/-- A topological group is a group in which the multiplication and inversion operations are
continuous. -/
class topological_group (α : Type*) [topological_space α] [group α]
extends topological_monoid α : Prop :=
(continuous_inv : continuous (λa:α, a⁻¹))
/-- A topological (additive) group is a group in which the addition and negation operations are
continuous. -/
class topological_add_group (α : Type u) [topological_space α] [add_group α]
extends topological_add_monoid α : Prop :=
(continuous_neg : continuous (λa:α, -a))
attribute [to_additive topological_add_group] topological_group
attribute [to_additive topological_add_group.mk] topological_group.mk
attribute [to_additive topological_add_group.continuous_neg] topological_group.continuous_inv
attribute [to_additive topological_add_group.to_topological_add_monoid] topological_group.to_topological_monoid
variables [topological_space α] [group α]
@[to_additive continuous_neg']
lemma continuous_inv' [topological_group α] : continuous (λx:α, x⁻¹) :=
topological_group.continuous_inv α
@[to_additive continuous_neg]
lemma continuous_inv [topological_group α] [topological_space β] {f : β → α}
(hf : continuous f) : continuous (λx, (f x)⁻¹) :=
hf.comp continuous_inv'
@[to_additive tendsto_neg]
lemma tendsto_inv [topological_group α] {f : β → α} {x : filter β} {a : α}
(hf : tendsto f x (nhds a)) : tendsto (λx, (f x)⁻¹) x (nhds a⁻¹) :=
hf.comp (continuous_iff_tendsto.mp (topological_group.continuous_inv α) a)
@[to_additive prod.topological_add_group]
instance [topological_group α] [topological_space β] [group β] [topological_group β] :
topological_group (α × β) :=
{ continuous_inv := continuous.prod_mk (continuous_inv continuous_fst) (continuous_inv continuous_snd) }
attribute [instance] prod.topological_add_group
protected def homeomorph.mul_left [topological_group α] (a : α) : α ≃ₜ α :=
{ continuous_to_fun := continuous_mul continuous_const continuous_id,
continuous_inv_fun := continuous_mul continuous_const continuous_id,
.. equiv.mul_left a }
attribute [to_additive homeomorph.add_left._proof_1] homeomorph.mul_left._proof_1
attribute [to_additive homeomorph.add_left._proof_2] homeomorph.mul_left._proof_2
attribute [to_additive homeomorph.add_left._proof_3] homeomorph.mul_left._proof_3
attribute [to_additive homeomorph.add_left._proof_4] homeomorph.mul_left._proof_4
attribute [to_additive homeomorph.add_left] homeomorph.mul_left
@[to_additive is_open_map_add_left]
lemma is_open_map_mul_left [topological_group α] (a : α) : is_open_map (λ x, a * x) :=
(homeomorph.mul_left a).is_open_map
protected def homeomorph.mul_right
{α : Type*} [topological_space α] [group α] [topological_group α] (a : α) :
α ≃ₜ α :=
{ continuous_to_fun := continuous_mul continuous_id continuous_const,
continuous_inv_fun := continuous_mul continuous_id continuous_const,
.. equiv.mul_right a }
attribute [to_additive homeomorph.add_right._proof_1] homeomorph.mul_right._proof_1
attribute [to_additive homeomorph.add_right._proof_2] homeomorph.mul_right._proof_2
attribute [to_additive homeomorph.add_right._proof_3] homeomorph.mul_right._proof_3
attribute [to_additive homeomorph.add_right._proof_4] homeomorph.mul_right._proof_4
attribute [to_additive homeomorph.add_right] homeomorph.mul_right
@[to_additive is_open_map_add_right]
lemma is_open_map_mul_right [topological_group α] (a : α) : is_open_map (λ x, x * a) :=
(homeomorph.mul_right a).is_open_map
protected def homeomorph.inv (α : Type*) [topological_space α] [group α] [topological_group α] :
α ≃ₜ α :=
{ continuous_to_fun := continuous_inv',
continuous_inv_fun := continuous_inv',
.. equiv.inv α }
attribute [to_additive homeomorph.inv._proof_1] homeomorph.inv._proof_1
attribute [to_additive homeomorph.inv._proof_2] homeomorph.inv._proof_2
attribute [to_additive homeomorph.inv] homeomorph.inv
@[to_additive exists_nhds_half]
lemma exists_nhds_split [topological_group α] {s : set α} (hs : s ∈ (nhds (1 : α)).sets) :
∃ V ∈ (nhds (1 : α)).sets, ∀ v w ∈ V, v * w ∈ s :=
begin
have : ((λa:α×α, a.1 * a.2) ⁻¹' s) ∈ (nhds ((1, 1) : α × α)).sets :=
tendsto_mul' (by simpa using hs),
rw nhds_prod_eq at this,
rcases mem_prod_iff.1 this with ⟨V₁, H₁, V₂, H₂, H⟩,
exact ⟨V₁ ∩ V₂, inter_mem_sets H₁ H₂, assume v w ⟨hv, _⟩ ⟨_, hw⟩, @H (v, w) ⟨hv, hw⟩⟩
end
@[to_additive exists_nhds_quarter]
lemma exists_nhds_split4 [topological_group α] {u : set α} (hu : u ∈ (nhds (1 : α)).sets) :
∃ V ∈ (nhds (1 : α)).sets, ∀ {v w s t}, v ∈ V → w ∈ V → s ∈ V → t ∈ V → v * w * s * t ∈ u :=
begin
rcases exists_nhds_split hu with ⟨W, W_nhd, h⟩,
rcases exists_nhds_split W_nhd with ⟨V, V_nhd, h'⟩,
existsi [V, V_nhd],
intros v w s t v_in w_in s_in t_in,
simpa [mul_assoc] using h _ _ (h' v w v_in w_in) (h' s t s_in t_in)
end
section
variable (α)
@[to_additive nhds_zero_symm]
lemma nhds_one_symm [topological_group α] : comap (λr:α, r⁻¹) (nhds (1 : α)) = nhds (1 : α) :=
begin
have lim : tendsto (λr:α, r⁻¹) (nhds 1) (nhds 1),
{ simpa using tendsto_inv (@tendsto_id α (nhds 1)) },
refine comap_eq_of_inverse _ _ lim lim,
{ funext x, simp },
end
end
@[to_additive nhds_translation_add_neg]
lemma nhds_translation_mul_inv [topological_group α] (x : α) :
comap (λy:α, y * x⁻¹) (nhds 1) = nhds x :=
begin
refine comap_eq_of_inverse (λy:α, y * x) _ _ _,
{ funext x; simp },
{ suffices : tendsto (λy:α, y * x⁻¹) (nhds x) (nhds (x * x⁻¹)), { simpa },
exact tendsto_mul tendsto_id tendsto_const_nhds },
{ suffices : tendsto (λy:α, y * x) (nhds 1) (nhds (1 * x)), { simpa },
exact tendsto_mul tendsto_id tendsto_const_nhds }
end
end topological_group
section topological_add_group
variables [topological_space α] [add_group α]
lemma continuous_sub [topological_add_group α] [topological_space β] {f : β → α} {g : β → α}
(hf : continuous f) (hg : continuous g) : continuous (λx, f x - g x) :=
by simp; exact continuous_add hf (continuous_neg hg)
lemma continuous_sub' [topological_add_group α] : continuous (λp:α×α, p.1 - p.2) :=
continuous_sub continuous_fst continuous_snd
lemma tendsto_sub [topological_add_group α] {f : β → α} {g : β → α} {x : filter β} {a b : α}
(hf : tendsto f x (nhds a)) (hg : tendsto g x (nhds b)) : tendsto (λx, f x - g x) x (nhds (a - b)) :=
by simp; exact tendsto_add hf (tendsto_neg hg)
lemma nhds_translation [topological_add_group α] (x : α) : comap (λy:α, y - x) (nhds 0) = nhds x :=
nhds_translation_add_neg x
end topological_add_group
section uniform_add_group
/-- A uniform (additive) group is a group in which the addition and negation are
uniformly continuous. -/
class uniform_add_group (α : Type u) [uniform_space α] [add_group α] : Prop :=
(uniform_continuous_sub : uniform_continuous (λp:α×α, p.1 - p.2))
theorem uniform_add_group.mk' {α} [uniform_space α] [add_group α]
(h₁ : uniform_continuous (λp:α×α, p.1 + p.2))
(h₂ : uniform_continuous (λp:α, -p)) : uniform_add_group α :=
⟨(uniform_continuous_fst.prod_mk (uniform_continuous_snd.comp h₂)).comp h₁⟩
variables [uniform_space α] [add_group α] [uniform_add_group α]
lemma uniform_continuous_sub' : uniform_continuous (λp:α×α, p.1 - p.2) :=
uniform_add_group.uniform_continuous_sub α
lemma uniform_continuous_sub [uniform_space β] {f : β → α} {g : β → α}
(hf : uniform_continuous f) (hg : uniform_continuous g) : uniform_continuous (λx, f x - g x) :=
(hf.prod_mk hg).comp uniform_continuous_sub'
lemma uniform_continuous_neg [uniform_space β] {f : β → α}
(hf : uniform_continuous f) : uniform_continuous (λx, - f x) :=
have uniform_continuous (λx, 0 - f x),
from uniform_continuous_sub uniform_continuous_const hf,
by simp * at *
lemma uniform_continuous_neg' : uniform_continuous (λx:α, - x) :=
uniform_continuous_neg uniform_continuous_id
lemma uniform_continuous_add [uniform_space β] {f : β → α} {g : β → α}
(hf : uniform_continuous f) (hg : uniform_continuous g) : uniform_continuous (λx, f x + g x) :=
have uniform_continuous (λx, f x - - g x),
from uniform_continuous_sub hf $ uniform_continuous_neg hg,
by simp * at *
lemma uniform_continuous_add' : uniform_continuous (λp:α×α, p.1 + p.2) :=
uniform_continuous_add uniform_continuous_fst uniform_continuous_snd
instance uniform_add_group.to_topological_add_group : topological_add_group α :=
{ continuous_add := uniform_continuous_add'.continuous,
continuous_neg := uniform_continuous_neg'.continuous }
instance [uniform_space β] [add_group β] [uniform_add_group β] : uniform_add_group (α × β) :=
⟨uniform_continuous.prod_mk
(uniform_continuous_sub
(uniform_continuous_fst.comp uniform_continuous_fst)
(uniform_continuous_snd.comp uniform_continuous_fst))
(uniform_continuous_sub
(uniform_continuous_fst.comp uniform_continuous_snd)
(uniform_continuous_snd.comp uniform_continuous_snd)) ⟩
lemma uniformity_translate (a : α) : uniformity.map (λx:α×α, (x.1 + a, x.2 + a)) = uniformity :=
le_antisymm
(uniform_continuous_add uniform_continuous_id uniform_continuous_const)
(calc uniformity =
(uniformity.map (λx:α×α, (x.1 + -a, x.2 + -a))).map (λx:α×α, (x.1 + a, x.2 + a)) :
by simp [filter.map_map, (∘)]; exact filter.map_id.symm
... ≤ uniformity.map (λx:α×α, (x.1 + a, x.2 + a)) :
filter.map_mono (uniform_continuous_add uniform_continuous_id uniform_continuous_const))
lemma uniform_embedding_translate (a : α) : uniform_embedding (λx:α, x + a) :=
begin
refine ⟨assume x y, eq_of_add_eq_add_right, _⟩,
rw [← uniformity_translate a, comap_map] {occs := occurrences.pos [1]},
rintros ⟨p₁, p₂⟩ ⟨q₁, q₂⟩,
simp [prod.eq_iff_fst_eq_snd_eq] {contextual := tt}
end
section
variables (α)
lemma uniformity_eq_comap_nhds_zero : uniformity = comap (λx:α×α, x.2 - x.1) (nhds (0:α)) :=
begin
rw [nhds_eq_comap_uniformity, filter.comap_comap_comp],
refine le_antisymm (filter.map_le_iff_le_comap.1 _) _,
{ assume s hs,
rcases mem_uniformity_of_uniform_continuous_invarant uniform_continuous_sub' hs with ⟨t, ht, hts⟩,
refine mem_map.2 (mem_sets_of_superset ht _),
rintros ⟨a, b⟩,
simpa [subset_def] using hts a b a },
{ assume s hs,
rcases mem_uniformity_of_uniform_continuous_invarant uniform_continuous_add' hs with ⟨t, ht, hts⟩,
refine ⟨_, ht, _⟩,
rintros ⟨a, b⟩, simpa [subset_def] using hts 0 (b - a) a }
end
end
lemma group_separation_rel (x y : α) : (x, y) ∈ separation_rel α ↔ x - y ∈ closure ({0} : set α) :=
have embedding (λa, a + (y - x)), from (uniform_embedding_translate (y - x)).embedding,
show (x, y) ∈ ⋂₀ uniformity.sets ↔ x - y ∈ closure ({0} : set α),
begin
rw [this.closure_eq_preimage_closure_image, uniformity_eq_comap_nhds_zero α, sInter_comap_sets],
simp [mem_closure_iff_nhds, inter_singleton_eq_empty]
end
lemma uniform_continuous_of_tendsto_zero [uniform_space β] [add_group β] [uniform_add_group β]
{f : α → β} [is_add_group_hom f] (h : tendsto f (nhds 0) (nhds 0)) :
uniform_continuous f :=
begin
have : ((λx:β×β, x.2 - x.1) ∘ (λx:α×α, (f x.1, f x.2))) = (λx:α×α, f (x.2 - x.1)),
{ simp only [is_add_group_hom.sub f] },
rw [uniform_continuous, uniformity_eq_comap_nhds_zero α, uniformity_eq_comap_nhds_zero β,
tendsto_comap_iff, this],
exact tendsto.comp tendsto_comap h
end
lemma uniform_continuous_of_continuous [uniform_space β] [add_group β] [uniform_add_group β]
{f : α → β} [is_add_group_hom f] (h : continuous f) :
uniform_continuous f :=
uniform_continuous_of_tendsto_zero $
suffices tendsto f (nhds 0) (nhds (f 0)), by rwa [is_add_group_hom.zero f] at this,
h.tendsto 0
end uniform_add_group
section topological_ring
universe u'
variables (α) [topological_space α]
/-- A topological semiring is a semiring where addition and multiplication are continuous. -/
class topological_semiring [semiring α]
extends topological_add_monoid α, topological_monoid α : Prop
variables [ring α]
/-- A topological ring is a ring where the ring operations are continuous. -/
class topological_ring extends topological_add_monoid α, topological_monoid α : Prop :=
(continuous_neg : continuous (λa:α, -a))
variables [t : topological_ring α]
instance topological_ring.to_topological_semiring : topological_semiring α := {..t}
instance topological_ring.to_topological_add_group : topological_add_group α := {..t}
end topological_ring
section topological_comm_ring
universe u'
variables (α) [topological_space α] [comm_ring α] [topological_ring α]
instance ideal_closure (S : set α) [is_ideal S] : is_ideal (closure S) :=
{ zero_ := subset_closure (is_ideal.zero S),
add_ := assume x y hx hy,
mem_closure2 continuous_add' hx hy $ assume a b, is_ideal.add,
smul := assume c x hx,
have continuous (λx:α, c * x) := continuous_mul continuous_const continuous_id,
mem_closure this hx $ assume a, is_ideal.mul_left }
end topological_comm_ring
/-- (Partially) ordered topology
Also called: partially ordered spaces (pospaces).
Usually ordered topology is used for a topology on linear ordered spaces, where the open intervals
are open sets. This is a generalization as for each linear order where open interals are open sets,
the order relation is closed. -/
class ordered_topology (α : Type*) [t : topological_space α] [partial_order α] : Prop :=
(is_closed_le' : is_closed (λp:α×α, p.1 ≤ p.2))
section ordered_topology
section partial_order
variables [topological_space α] [partial_order α] [t : ordered_topology α]
include t
lemma is_closed_le [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) :
is_closed {b | f b ≤ g b} :=
continuous_iff_is_closed.mp (hf.prod_mk hg) _ t.is_closed_le'
lemma is_closed_le' (a : α) : is_closed {b | b ≤ a} :=
is_closed_le continuous_id continuous_const
lemma is_closed_ge' (a : α) : is_closed {b | a ≤ b} :=
is_closed_le continuous_const continuous_id
lemma is_closed_Icc {a b : α} : is_closed (Icc a b) :=
is_closed_inter (is_closed_ge' a) (is_closed_le' b)
lemma le_of_tendsto {f g : β → α} {b : filter β} {a₁ a₂ : α} (hb : b ≠ ⊥)
(hf : tendsto f b (nhds a₁)) (hg : tendsto g b (nhds a₂)) (h : {b | f b ≤ g b} ∈ b.sets) :
a₁ ≤ a₂ :=
have tendsto (λb, (f b, g b)) b (nhds (a₁, a₂)),
by rw [nhds_prod_eq]; exact hf.prod_mk hg,
show (a₁, a₂) ∈ {p:α×α | p.1 ≤ p.2},
from mem_of_closed_of_tendsto hb this t.is_closed_le' h
private lemma is_closed_eq : is_closed {p : α × α | p.1 = p.2} :=
by simp [le_antisymm_iff];
exact is_closed_inter t.is_closed_le' (is_closed_le continuous_snd continuous_fst)
instance ordered_topology.to_t2_space : t2_space α :=
{ t2 :=
have is_open {p : α × α | p.1 ≠ p.2}, from is_closed_eq,
assume a b h,
let ⟨u, v, hu, hv, ha, hb, h⟩ := is_open_prod_iff.mp this a b h in
⟨u, v, hu, hv, ha, hb,
set.eq_empty_iff_forall_not_mem.2 $ assume a ⟨h₁, h₂⟩,
have a ≠ a, from @h (a, a) ⟨h₁, h₂⟩,
this rfl⟩ }
@[simp] lemma closure_le_eq [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) :
closure {b | f b ≤ g b} = {b | f b ≤ g b} :=
closure_eq_iff_is_closed.mpr $ is_closed_le hf hg
end partial_order
section linear_order
variables [topological_space α] [linear_order α] [t : ordered_topology α]
include t
lemma is_open_lt [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) :
is_open {b | f b < g b} :=
by simp [lt_iff_not_ge, -not_le]; exact is_closed_le hg hf
lemma is_open_Ioo {a b : α} : is_open (Ioo a b) :=
is_open_and (is_open_lt continuous_const continuous_id) (is_open_lt continuous_id continuous_const)
lemma is_open_Iio {a : α} : is_open (Iio a) :=
is_open_lt continuous_id continuous_const
end linear_order
section decidable_linear_order
variables [topological_space α] [decidable_linear_order α] [t : ordered_topology α]
[topological_space β] {f g : β → α}
include t
section
variables (hf : continuous f) (hg : continuous g)
include hf hg
lemma frontier_le_subset_eq : frontier {b | f b ≤ g b} ⊆ {b | f b = g b} :=
assume b ⟨hb₁, hb₂⟩,
le_antisymm
(by simpa [closure_le_eq hf hg] using hb₁)
(not_lt.1 $ assume hb : f b < g b,
have {b | f b < g b} ⊆ interior {b | f b ≤ g b},
from (subset_interior_iff_subset_of_open $ is_open_lt hf hg).mpr $ assume x, le_of_lt,
have b ∈ interior {b | f b ≤ g b}, from this hb,
by exact hb₂ this)
lemma frontier_lt_subset_eq : frontier {b | f b < g b} ⊆ {b | f b = g b} :=
by rw ← frontier_compl;
convert frontier_le_subset_eq hg hf; simp [ext_iff, eq_comm]
lemma continuous_max : continuous (λb, max (f b) (g b)) :=
have ∀b∈frontier {b | f b ≤ g b}, g b = f b, from assume b hb, (frontier_le_subset_eq hf hg hb).symm,
continuous_if this hg hf
lemma continuous_min : continuous (λb, min (f b) (g b)) :=
have ∀b∈frontier {b | f b ≤ g b}, f b = g b, from assume b hb, frontier_le_subset_eq hf hg hb,
continuous_if this hf hg
end
lemma tendsto_max {b : filter β} {a₁ a₂ : α} (hf : tendsto f b (nhds a₁)) (hg : tendsto g b (nhds a₂)) :
tendsto (λb, max (f b) (g b)) b (nhds (max a₁ a₂)) :=
show tendsto ((λp:α×α, max p.1 p.2) ∘ (λb, (f b, g b))) b (nhds (max a₁ a₂)),
from (hf.prod_mk hg).comp
begin
rw [←nhds_prod_eq],
from continuous_iff_tendsto.mp (continuous_max continuous_fst continuous_snd) _
end
lemma tendsto_min {b : filter β} {a₁ a₂ : α} (hf : tendsto f b (nhds a₁)) (hg : tendsto g b (nhds a₂)) :
tendsto (λb, min (f b) (g b)) b (nhds (min a₁ a₂)) :=
show tendsto ((λp:α×α, min p.1 p.2) ∘ (λb, (f b, g b))) b (nhds (min a₁ a₂)),
from (hf.prod_mk hg).comp
begin
rw [←nhds_prod_eq],
from continuous_iff_tendsto.mp (continuous_min continuous_fst continuous_snd) _
end
end decidable_linear_order
end ordered_topology
/-- Topologies generated by the open intervals.
This is restricted to linear orders. Only then it is guaranteed that they are also a ordered
topology. -/
class orderable_topology (α : Type*) [t : topological_space α] [partial_order α] : Prop :=
(topology_eq_generate_intervals :
t = generate_from {s | ∃a, s = {b : α | a < b} ∨ s = {b : α | b < a}})
section orderable_topology
section partial_order
variables [topological_space α] [partial_order α] [t : orderable_topology α]
include t
lemma is_open_iff_generate_intervals {s : set α} :
is_open s ↔ generate_open {s | ∃a, s = {b : α | a < b} ∨ s = {b : α | b < a}} s :=
by rw [t.topology_eq_generate_intervals]; refl
lemma is_open_lt' (a : α) : is_open {b:α | a < b} :=
by rw [@is_open_iff_generate_intervals α _ _ t]; exact generate_open.basic _ ⟨a, or.inl rfl⟩
lemma is_open_gt' (a : α) : is_open {b:α | b < a} :=
by rw [@is_open_iff_generate_intervals α _ _ t]; exact generate_open.basic _ ⟨a, or.inr rfl⟩
lemma lt_mem_nhds {a b : α} (h : a < b) : {b | a < b} ∈ (nhds b).sets :=
mem_nhds_sets (is_open_lt' _) h
lemma le_mem_nhds {a b : α} (h : a < b) : {b | a ≤ b} ∈ (nhds b).sets :=
(nhds b).sets_of_superset (lt_mem_nhds h) $ assume b hb, le_of_lt hb
lemma gt_mem_nhds {a b : α} (h : a < b) : {a | a < b} ∈ (nhds a).sets :=
mem_nhds_sets (is_open_gt' _) h
lemma ge_mem_nhds {a b : α} (h : a < b) : {a | a ≤ b} ∈ (nhds a).sets :=
(nhds a).sets_of_superset (gt_mem_nhds h) $ assume b hb, le_of_lt hb
lemma nhds_eq_orderable {a : α} :
nhds a = (⨅b<a, principal {c | b < c}) ⊓ (⨅b>a, principal {c | c < b}) :=
by rw [t.topology_eq_generate_intervals, nhds_generate_from];
from le_antisymm
(le_inf
(le_infi $ assume b, le_infi $ assume hb,
infi_le_of_le {c : α | b < c} $ infi_le _ ⟨hb, b, or.inl rfl⟩)
(le_infi $ assume b, le_infi $ assume hb,
infi_le_of_le {c : α | c < b} $ infi_le _ ⟨hb, b, or.inr rfl⟩))
(le_infi $ assume s, le_infi $ assume ⟨ha, b, hs⟩,
match s, ha, hs with
| _, h, (or.inl rfl) := inf_le_left_of_le $ infi_le_of_le b $ infi_le _ h
| _, h, (or.inr rfl) := inf_le_right_of_le $ infi_le_of_le b $ infi_le _ h
end)
lemma tendsto_orderable {f : β → α} {a : α} {x : filter β} :
tendsto f x (nhds a) ↔ (∀a'<a, {b | a' < f b} ∈ x.sets) ∧ (∀a'>a, {b | a' > f b} ∈ x.sets) :=
by simp [@nhds_eq_orderable α _ _, tendsto_inf, tendsto_infi, tendsto_principal]
/-- Also known as squeeze or sandwich theorem. -/
lemma tendsto_of_tendsto_of_tendsto_of_le_of_le {f g h : β → α} {b : filter β} {a : α}
(hg : tendsto g b (nhds a)) (hh : tendsto h b (nhds a))
(hgf : {b | g b ≤ f b} ∈ b.sets) (hfh : {b | f b ≤ h b} ∈ b.sets) :
tendsto f b (nhds a) :=
tendsto_orderable.2
⟨assume a' h',
have {b : β | a' < g b} ∈ b.sets, from (tendsto_orderable.1 hg).left a' h',
by filter_upwards [this, hgf] assume a, lt_of_lt_of_le,
assume a' h',
have {b : β | h b < a'} ∈ b.sets, from (tendsto_orderable.1 hh).right a' h',
by filter_upwards [this, hfh] assume a h₁ h₂, lt_of_le_of_lt h₂ h₁⟩
lemma nhds_orderable_unbounded {a : α} (hu : ∃u, a < u) (hl : ∃l, l < a) :
nhds a = (⨅l (h₂ : l < a) u (h₂ : a < u), principal {x | l < x ∧ x < u }) :=
let ⟨u, hu⟩ := hu, ⟨l, hl⟩ := hl in
calc nhds a = (⨅b<a, principal {c | b < c}) ⊓ (⨅b>a, principal {c | c < b}) : nhds_eq_orderable
... = (⨅b<a, principal {c | b < c} ⊓ (⨅b>a, principal {c | c < b})) :
binfi_inf hl
... = (⨅l<a, (⨅u>a, principal {c | c < u} ⊓ principal {c | l < c})) :
begin
congr, funext x,
congr, funext hx,
rw [inf_comm],
apply binfi_inf hu
end
... = _ : by simp [inter_comm]; refl
lemma tendsto_orderable_unbounded {f : β → α} {a : α} {x : filter β}
(hu : ∃u, a < u) (hl : ∃l, l < a) (h : ∀l u, l < a → a < u → {b | l < f b ∧ f b < u } ∈ x.sets) :
tendsto f x (nhds a) :=
by rw [nhds_orderable_unbounded hu hl];
from (tendsto_infi.2 $ assume l, tendsto_infi.2 $ assume hl,
tendsto_infi.2 $ assume u, tendsto_infi.2 $ assume hu, tendsto_principal.2 $ h l u hl hu)
end partial_order
theorem induced_orderable_topology' {α : Type u} {β : Type v}
[partial_order α] [ta : topological_space β] [partial_order β] [orderable_topology β]
(f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y)
(H₁ : ∀ {a x}, x < f a → ∃ b < a, x ≤ f b)
(H₂ : ∀ {a x}, f a < x → ∃ b > a, f b ≤ x) :
@orderable_topology _ (induced f ta) _ :=
begin
letI := induced f ta,
refine ⟨eq_of_nhds_eq_nhds (λ a, _)⟩,
rw [nhds_induced_eq_comap, nhds_generate_from, @nhds_eq_orderable β _ _], apply le_antisymm,
{ rw [← map_le_iff_le_comap],
refine le_inf _ _; refine le_infi (λ x, le_infi $ λ h, le_principal_iff.2 _); simp,
{ rcases H₁ h with ⟨b, ab, xb⟩,
refine mem_infi_sets _ (mem_infi_sets ⟨ab, b, or.inl rfl⟩ (mem_principal_sets.2 _)),
exact λ c hc, lt_of_le_of_lt xb (hf.2 hc) },
{ rcases H₂ h with ⟨b, ab, xb⟩,
refine mem_infi_sets _ (mem_infi_sets ⟨ab, b, or.inr rfl⟩ (mem_principal_sets.2 _)),
exact λ c hc, lt_of_lt_of_le (hf.2 hc) xb } },
refine le_infi (λ s, le_infi $ λ hs, le_principal_iff.2 _),
rcases hs with ⟨ab, b, rfl|rfl⟩,
{ exact mem_comap_sets.2 ⟨{x | f b < x},
mem_inf_sets_of_left $ mem_infi_sets _ $ mem_infi_sets (hf.2 ab) $ mem_principal_self _,
λ x, hf.1⟩ },
{ exact mem_comap_sets.2 ⟨{x | x < f b},
mem_inf_sets_of_right $ mem_infi_sets _ $ mem_infi_sets (hf.2 ab) $ mem_principal_self _,
λ x, hf.1⟩ }
end
theorem induced_orderable_topology {α : Type u} {β : Type v}
[partial_order α] [ta : topological_space β] [partial_order β] [orderable_topology β]
(f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y)
(H : ∀ {x y}, x < y → ∃ a, x < f a ∧ f a < y) :
@orderable_topology _ (induced f ta) _ :=
induced_orderable_topology' f @hf
(λ a x xa, let ⟨b, xb, ba⟩ := H xa in ⟨b, hf.1 ba, le_of_lt xb⟩)
(λ a x ax, let ⟨b, ab, bx⟩ := H ax in ⟨b, hf.1 ab, le_of_lt bx⟩)
lemma nhds_top_orderable [topological_space α] [order_top α] [orderable_topology α] :
nhds (⊤:α) = (⨅l (h₂ : l < ⊤), principal {x | l < x}) :=
by rw [@nhds_eq_orderable α _ _]; simp [(>)]
lemma nhds_bot_orderable [topological_space α] [order_bot α] [orderable_topology α] :
nhds (⊥:α) = (⨅l (h₂ : ⊥ < l), principal {x | x < l}) :=
by rw [@nhds_eq_orderable α _ _]; simp
section linear_order
variables [topological_space α] [linear_order α] [t : orderable_topology α]
include t
lemma mem_nhds_orderable_dest {a : α} {s : set α} (hs : s ∈ (nhds a).sets) :
((∃u, u>a) → ∃u, a < u ∧ ∀b, a ≤ b → b < u → b ∈ s) ∧
((∃l, l<a) → ∃l, l < a ∧ ∀b, l < b → b ≤ a → b ∈ s) :=
let ⟨t₁, ht₁, t₂, ht₂, hts⟩ :=
mem_inf_sets.mp $ by rw [@nhds_eq_orderable α _ _ _] at hs; exact hs in
have ht₁ : ((∃l, l<a) → ∃l, l < a ∧ ∀b, l < b → b ∈ t₁) ∧ (∀b, a ≤ b → b ∈ t₁),
from infi_sets_induct ht₁
(by simp {contextual := tt})
(assume a' s₁ s₂ hs₁ ⟨hs₂, hs₃⟩,
begin
by_cases a' < a,
{ simp [h] at hs₁,
letI := classical.DLO α,
exact ⟨assume hx, let ⟨u, hu₁, hu₂⟩ := hs₂ hx in
⟨max u a', max_lt hu₁ h, assume b hb,
⟨hs₁ $ lt_of_le_of_lt (le_max_right _ _) hb,
hu₂ _ $ lt_of_le_of_lt (le_max_left _ _) hb⟩⟩,
assume b hb, ⟨hs₁ $ lt_of_lt_of_le h hb, hs₃ _ hb⟩⟩ },
{ simp [h] at hs₁, simp [hs₁],
exact ⟨by simpa using hs₂, hs₃⟩ }
end)
(assume s₁ s₂ h ih, and.intro
(assume hx, let ⟨u, hu₁, hu₂⟩ := ih.left hx in ⟨u, hu₁, assume b hb, h $ hu₂ _ hb⟩)
(assume b hb, h $ ih.right _ hb)),
have ht₂ : ((∃u, u>a) → ∃u, a < u ∧ ∀b, b < u → b ∈ t₂) ∧ (∀b, b ≤ a → b ∈ t₂),
from infi_sets_induct ht₂
(by simp {contextual := tt})
(assume a' s₁ s₂ hs₁ ⟨hs₂, hs₃⟩,
begin
by_cases a' > a,
{ simp [h] at hs₁,
letI := classical.DLO α,
exact ⟨assume hx, let ⟨u, hu₁, hu₂⟩ := hs₂ hx in
⟨min u a', lt_min hu₁ h, assume b hb,
⟨hs₁ $ lt_of_lt_of_le hb (min_le_right _ _),
hu₂ _ $ lt_of_lt_of_le hb (min_le_left _ _)⟩⟩,
assume b hb, ⟨hs₁ $ lt_of_le_of_lt hb h, hs₃ _ hb⟩⟩ },
{ simp [h] at hs₁, simp [hs₁],
exact ⟨by simpa using hs₂, hs₃⟩ }
end)
(assume s₁ s₂ h ih, and.intro
(assume hx, let ⟨u, hu₁, hu₂⟩ := ih.left hx in ⟨u, hu₁, assume b hb, h $ hu₂ _ hb⟩)
(assume b hb, h $ ih.right _ hb)),
and.intro
(assume hx, let ⟨u, hu, h⟩ := ht₂.left hx in ⟨u, hu, assume b hb hbu, hts ⟨ht₁.right b hb, h _ hbu⟩⟩)
(assume hx, let ⟨l, hl, h⟩ := ht₁.left hx in ⟨l, hl, assume b hbl hb, hts ⟨h _ hbl, ht₂.right b hb⟩⟩)
lemma mem_nhds_unbounded {a : α} {s : set α} (hu : ∃u, a < u) (hl : ∃l, l < a) :
s ∈ (nhds a).sets ↔ (∃l u, l < a ∧ a < u ∧ ∀b, l < b → b < u → b ∈ s) :=
let ⟨l, hl'⟩ := hl, ⟨u, hu'⟩ := hu in
have nhds a = (⨅p : {l // l < a} × {u // a < u}, principal {x | p.1.val < x ∧ x < p.2.val }),
by simp [nhds_orderable_unbounded hu hl, infi_subtype, infi_prod],
iff.intro
(assume hs, by rw [this] at hs; from infi_sets_induct hs
⟨l, u, hl', hu', by simp⟩
begin
intro p, rcases p with ⟨⟨l, hl⟩, ⟨u, hu⟩⟩,
simp [set.subset_def],
intros s₁ s₂ hs₁ l' hl' u' hu' hs₂,
letI := classical.DLO α,
refine ⟨max l l', _, min u u', _⟩;
simp [*, lt_min_iff, max_lt_iff] {contextual := tt}
end
(assume s₁ s₂ h ⟨l, u, h₁, h₂, h₃⟩, ⟨l, u, h₁, h₂, assume b hu hl, h $ h₃ _ hu hl⟩))
(assume ⟨l, u, hl, hu, h⟩,
by rw [this]; exact mem_infi_sets ⟨⟨l, hl⟩, ⟨u, hu⟩⟩ (assume b ⟨h₁, h₂⟩, h b h₁ h₂))
lemma order_separated {a₁ a₂ : α} (h : a₁ < a₂) :
∃u v : set α, is_open u ∧ is_open v ∧ a₁ ∈ u ∧ a₂ ∈ v ∧ (∀b₁∈u, ∀b₂∈v, b₁ < b₂) :=
match dense_or_discrete h with
| or.inl ⟨a, ha₁, ha₂⟩ := ⟨{a' | a' < a}, {a' | a < a'}, is_open_gt' a, is_open_lt' a, ha₁, ha₂,
assume b₁ h₁ b₂ h₂, lt_trans h₁ h₂⟩
| or.inr ⟨h₁, h₂⟩ := ⟨{a | a < a₂}, {a | a₁ < a}, is_open_gt' a₂, is_open_lt' a₁, h, h,
assume b₁ hb₁ b₂ hb₂,
calc b₁ ≤ a₁ : h₂ _ hb₁
... < a₂ : h
... ≤ b₂ : h₁ _ hb₂⟩
end
instance orderable_topology.to_ordered_topology : ordered_topology α :=
{ is_closed_le' :=
is_open_prod_iff.mpr $ assume a₁ a₂ (h : ¬ a₁ ≤ a₂),
have h : a₂ < a₁, from lt_of_not_ge h,
let ⟨u, v, hu, hv, ha₁, ha₂, h⟩ := order_separated h in
⟨v, u, hv, hu, ha₂, ha₁, assume ⟨b₁, b₂⟩ ⟨h₁, h₂⟩, not_le_of_gt $ h b₂ h₂ b₁ h₁⟩ }
instance orderable_topology.t2_space : t2_space α := by apply_instance
instance orderable_topology.regular_space : regular_space α :=
{ regular := assume s a hs ha,
have -s ∈ (nhds a).sets, from mem_nhds_sets hs ha,
let ⟨h₁, h₂⟩ := mem_nhds_orderable_dest this in
have ∃t:set α, is_open t ∧ (∀l∈ s, l < a → l ∈ t) ∧ nhds a ⊓ principal t = ⊥,
from by_cases
(assume h : ∃l, l < a,
let ⟨l, hl, h⟩ := h₂ h in
match dense_or_discrete hl with
| or.inl ⟨b, hb₁, hb₂⟩ := ⟨{a | a < b}, is_open_gt' _,
assume c hcs hca, show c < b,
from lt_of_not_ge $ assume hbc, h c (lt_of_lt_of_le hb₁ hbc) (le_of_lt hca) hcs,
inf_principal_eq_bot $ (nhds a).sets_of_superset (mem_nhds_sets (is_open_lt' _) hb₂) $
assume x (hx : b < x), show ¬ x < b, from not_lt.2 $ le_of_lt hx⟩
| or.inr ⟨h₁, h₂⟩ := ⟨{a' | a' < a}, is_open_gt' _, assume b hbs hba, hba,
inf_principal_eq_bot $ (nhds a).sets_of_superset (mem_nhds_sets (is_open_lt' _) hl) $
assume x (hx : l < x), show ¬ x < a, from not_lt.2 $ h₁ _ hx⟩
end)
(assume : ¬ ∃l, l < a, ⟨∅, is_open_empty, assume l _ hl, (this ⟨l, hl⟩).elim,
by rw [principal_empty, inf_bot_eq]⟩),
let ⟨t₁, ht₁o, ht₁s, ht₁a⟩ := this in
have ∃t:set α, is_open t ∧ (∀u∈ s, u>a → u ∈ t) ∧ nhds a ⊓ principal t = ⊥,
from by_cases
(assume h : ∃u, u > a,
let ⟨u, hu, h⟩ := h₁ h in
match dense_or_discrete hu with
| or.inl ⟨b, hb₁, hb₂⟩ := ⟨{a | b < a}, is_open_lt' _,
assume c hcs hca, show c > b,
from lt_of_not_ge $ assume hbc, h c (le_of_lt hca) (lt_of_le_of_lt hbc hb₂) hcs,
inf_principal_eq_bot $ (nhds a).sets_of_superset (mem_nhds_sets (is_open_gt' _) hb₁) $
assume x (hx : b > x), show ¬ x > b, from not_lt.2 $ le_of_lt hx⟩
| or.inr ⟨h₁, h₂⟩ := ⟨{a' | a' > a}, is_open_lt' _, assume b hbs hba, hba,
inf_principal_eq_bot $ (nhds a).sets_of_superset (mem_nhds_sets (is_open_gt' _) hu) $
assume x (hx : u > x), show ¬ x > a, from not_lt.2 $ h₂ _ hx⟩
end)
(assume : ¬ ∃u, u > a, ⟨∅, is_open_empty, assume l _ hl, (this ⟨l, hl⟩).elim,
by rw [principal_empty, inf_bot_eq]⟩),
let ⟨t₂, ht₂o, ht₂s, ht₂a⟩ := this in
⟨t₁ ∪ t₂, is_open_union ht₁o ht₂o,
assume x hx,
have x ≠ a, from assume eq, ha $ eq ▸ hx,
(ne_iff_lt_or_gt.mp this).imp (ht₁s _ hx) (ht₂s _ hx),
by rw [←sup_principal, inf_sup_left, ht₁a, ht₂a, bot_sup_eq]⟩,
..orderable_topology.t2_space }
end linear_order
lemma preimage_neg [add_group α] : preimage (has_neg.neg : α → α) = image (has_neg.neg : α → α) :=
(image_eq_preimage_of_inverse neg_neg neg_neg).symm
lemma filter.map_neg [add_group α] : map (has_neg.neg : α → α) = comap (has_neg.neg : α → α) :=
funext $ assume f, map_eq_comap_of_inverse (funext neg_neg) (funext neg_neg)
section topological_add_group
variables [topological_space α] [ordered_comm_group α] [orderable_topology α] [topological_add_group α]
lemma neg_preimage_closure {s : set α} : (λr:α, -r) ⁻¹' closure s = closure ((λr:α, -r) '' s) :=
have (λr:α, -r) ∘ (λr:α, -r) = id, from funext neg_neg,
by rw [preimage_neg]; exact
(subset.antisymm (image_closure_subset_closure_image continuous_neg') $
calc closure ((λ (r : α), -r) '' s) = (λr, -r) '' ((λr, -r) '' closure ((λ (r : α), -r) '' s)) :
by rw [←image_comp, this, image_id]
... ⊆ (λr, -r) '' closure ((λr, -r) '' ((λ (r : α), -r) '' s)) :
mono_image $ image_closure_subset_closure_image continuous_neg'
... = _ : by rw [←image_comp, this, image_id])
end topological_add_group
section order_topology
variables [topological_space α] [topological_space β]
[decidable_linear_order α] [decidable_linear_order β] [orderable_topology α] [orderable_topology β]
lemma nhds_principal_ne_bot_of_is_lub {a : α} {s : set α} (ha : is_lub s a) (hs : s ≠ ∅) :
nhds a ⊓ principal s ≠ ⊥ :=
let ⟨a', ha'⟩ := exists_mem_of_ne_empty hs in
forall_sets_neq_empty_iff_neq_bot.mp $ assume t ht,
let ⟨t₁, ht₁, t₂, ht₂, ht⟩ := mem_inf_sets.mp ht in
let ⟨hu, hl⟩ := mem_nhds_orderable_dest ht₁ in
by_cases
(assume h : a = a',
have a ∈ t₁, from mem_of_nhds ht₁,
have a ∈ t₂, from ht₂ $ by rwa [h],
ne_empty_iff_exists_mem.mpr ⟨a, ht ⟨‹a ∈ t₁›, ‹a ∈ t₂›⟩⟩)
(assume : a ≠ a',
have a' < a, from lt_of_le_of_ne (ha.left _ ‹a' ∈ s›) this.symm,
let ⟨l, hl, hlt₁⟩ := hl ⟨a', this⟩ in
have ∃a'∈s, l < a',
from classical.by_contradiction $ assume : ¬ ∃a'∈s, l < a',
have ∀a'∈s, a' ≤ l, from assume a ha, not_lt.1 $ assume ha', this ⟨a, ha, ha'⟩,
have ¬ l < a, from not_lt.2 $ ha.right _ this,
this ‹l < a›,
let ⟨a', ha', ha'l⟩ := this in
have a' ∈ t₁, from hlt₁ _ ‹l < a'› $ ha.left _ ha',
ne_empty_iff_exists_mem.mpr ⟨a', ht ⟨‹a' ∈ t₁›, ht₂ ‹a' ∈ s›⟩⟩)
lemma nhds_principal_ne_bot_of_is_glb {a : α} {s : set α} (ha : is_glb s a) (hs : s ≠ ∅) :
nhds a ⊓ principal s ≠ ⊥ :=
let ⟨a', ha'⟩ := exists_mem_of_ne_empty hs in
forall_sets_neq_empty_iff_neq_bot.mp $ assume t ht,
let ⟨t₁, ht₁, t₂, ht₂, ht⟩ := mem_inf_sets.mp ht in
let ⟨hu, hl⟩ := mem_nhds_orderable_dest ht₁ in
by_cases
(assume h : a = a',
have a ∈ t₁, from mem_of_nhds ht₁,
have a ∈ t₂, from ht₂ $ by rwa [h],
ne_empty_iff_exists_mem.mpr ⟨a, ht ⟨‹a ∈ t₁›, ‹a ∈ t₂›⟩⟩)
(assume : a ≠ a',
have a < a', from lt_of_le_of_ne (ha.left _ ‹a' ∈ s›) this,
let ⟨u, hu, hut₁⟩ := hu ⟨a', this⟩ in
have ∃a'∈s, a' < u,
from classical.by_contradiction $ assume : ¬ ∃a'∈s, a' < u,
have ∀a'∈s, u ≤ a', from assume a ha, not_lt.1 $ assume ha', this ⟨a, ha, ha'⟩,
have ¬ a < u, from not_lt.2 $ ha.right _ this,
this ‹a < u›,
let ⟨a', ha', ha'l⟩ := this in
have a' ∈ t₁, from hut₁ _ (ha.left _ ha') ‹a' < u›,
ne_empty_iff_exists_mem.mpr ⟨a', ht ⟨‹a' ∈ t₁›, ht₂ ‹a' ∈ s›⟩⟩)
lemma is_lub_of_mem_nhds {s : set α} {a : α} {f : filter α}
(hsa : a ∈ upper_bounds s) (hsf : s ∈ f.sets) (hfa : f ⊓ nhds a ≠ ⊥) : is_lub s a :=
⟨hsa, assume b hb,
not_lt.1 $ assume hba,
have s ∩ {a | b < a} ∈ (f ⊓ nhds a).sets,
from inter_mem_inf_sets hsf (mem_nhds_sets (is_open_lt' _) hba),
let ⟨x, ⟨hxs, hxb⟩⟩ := inhabited_of_mem_sets hfa this in
have b < b, from lt_of_lt_of_le hxb $ hb _ hxs,
lt_irrefl b this⟩
lemma is_glb_of_mem_nhds {s : set α} {a : α} {f : filter α}
(hsa : a ∈ lower_bounds s) (hsf : s ∈ f.sets) (hfa : f ⊓ nhds a ≠ ⊥) : is_glb s a :=
⟨hsa, assume b hb,
not_lt.1 $ assume hba,
have s ∩ {a | a < b} ∈ (f ⊓ nhds a).sets,
from inter_mem_inf_sets hsf (mem_nhds_sets (is_open_gt' _) hba),
let ⟨x, ⟨hxs, hxb⟩⟩ := inhabited_of_mem_sets hfa this in
have b < b, from lt_of_le_of_lt (hb _ hxs) hxb,
lt_irrefl b this⟩
lemma is_lub_of_is_lub_of_tendsto {f : α → β} {s : set α} {a : α} {b : β}
(hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) (ha : is_lub s a) (hs : s ≠ ∅)
(hb : tendsto f (nhds a ⊓ principal s) (nhds b)) : is_lub (f '' s) b :=
have hnbot : (nhds a ⊓ principal s) ≠ ⊥, from nhds_principal_ne_bot_of_is_lub ha hs,
have ∀a'∈s, ¬ b < f a',
from assume a' ha' h,
have {x | x < f a'} ∈ (nhds b).sets, from mem_nhds_sets (is_open_gt' _) h,
let ⟨t₁, ht₁, t₂, ht₂, hs⟩ := mem_inf_sets.mp (hb this) in
by_cases
(assume h : a = a',
have a ∈ t₁ ∩ t₂, from ⟨mem_of_nhds ht₁, ht₂ $ by rwa [h]⟩,
have f a < f a', from hs this,
lt_irrefl (f a') $ by rwa [h] at this)
(assume h : a ≠ a',
have a' < a, from lt_of_le_of_ne (ha.left _ ha') h.symm,
have {x | a' < x} ∈ (nhds a).sets, from mem_nhds_sets (is_open_lt' _) this,
have {x | a' < x} ∩ t₁ ∈ (nhds a).sets, from inter_mem_sets this ht₁,
have ({x | a' < x} ∩ t₁) ∩ s ∈ (nhds a ⊓ principal s).sets,
from inter_mem_inf_sets this (subset.refl s),
let ⟨x, ⟨hx₁, hx₂⟩, hx₃⟩ := inhabited_of_mem_sets hnbot this in
have hxa' : f x < f a', from hs ⟨hx₂, ht₂ hx₃⟩,
have ha'x : f a' ≤ f x, from hf _ ha' _ hx₃ $ le_of_lt hx₁,
lt_irrefl _ (lt_of_le_of_lt ha'x hxa')),
and.intro
(assume b' ⟨a', ha', h_eq⟩, h_eq ▸ not_lt.1 $ this _ ha')
(assume b' hb', le_of_tendsto hnbot hb tendsto_const_nhds $
mem_inf_sets_of_right $ assume x hx, hb' _ $ mem_image_of_mem _ hx)
lemma is_glb_of_is_glb_of_tendsto {f : α → β} {s : set α} {a : α} {b : β}
(hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) (ha : is_glb s a) (hs : s ≠ ∅)
(hb : tendsto f (nhds a ⊓ principal s) (nhds b)) : is_glb (f '' s) b :=
have hnbot : (nhds a ⊓ principal s) ≠ ⊥, from nhds_principal_ne_bot_of_is_glb ha hs,
have ∀a'∈s, ¬ b > f a',
from assume a' ha' h,
have {x | x > f a'} ∈ (nhds b).sets, from mem_nhds_sets (is_open_lt' _) h,
let ⟨t₁, ht₁, t₂, ht₂, hs⟩ := mem_inf_sets.mp (hb this) in
by_cases
(assume h : a = a',
have a ∈ t₁ ∩ t₂, from ⟨mem_of_nhds ht₁, ht₂ $ by rwa [h]⟩,
have f a > f a', from hs this,
lt_irrefl (f a') $ by rwa [h] at this)
(assume h : a ≠ a',
have a' > a, from lt_of_le_of_ne (ha.left _ ha') h,
have {x | a' > x} ∈ (nhds a).sets, from mem_nhds_sets (is_open_gt' _) this,
have {x | a' > x} ∩ t₁ ∈ (nhds a).sets, from inter_mem_sets this ht₁,
have ({x | a' > x} ∩ t₁) ∩ s ∈ (nhds a ⊓ principal s).sets,
from inter_mem_inf_sets this (subset.refl s),
let ⟨x, ⟨hx₁, hx₂⟩, hx₃⟩ := inhabited_of_mem_sets hnbot this in
have hxa' : f x > f a', from hs ⟨hx₂, ht₂ hx₃⟩,
have ha'x : f a' ≥ f x, from hf _ hx₃ _ ha' $ le_of_lt hx₁,
lt_irrefl _ (lt_of_lt_of_le hxa' ha'x)),
and.intro
(assume b' ⟨a', ha', h_eq⟩, h_eq ▸ not_lt.1 $ this _ ha')
(assume b' hb', le_of_tendsto hnbot tendsto_const_nhds hb $
mem_inf_sets_of_right $ assume x hx, hb' _ $ mem_image_of_mem _ hx)
lemma is_glb_of_is_lub_of_tendsto {f : α → β} {s : set α} {a : α} {b : β}
(hf : ∀x∈s, ∀y∈s, x ≤ y → f y ≤ f x) (ha : is_lub s a) (hs : s ≠ ∅)
(hb : tendsto f (nhds a ⊓ principal s) (nhds b)) : is_glb (f '' s) b :=
have hnbot : (nhds a ⊓ principal s) ≠ ⊥, from nhds_principal_ne_bot_of_is_lub ha hs,
have ∀a'∈s, ¬ b > f a',
from assume a' ha' h,
have {x | x > f a'} ∈ (nhds b).sets, from mem_nhds_sets (is_open_lt' _) h,
let ⟨t₁, ht₁, t₂, ht₂, hs⟩ := mem_inf_sets.mp (hb this) in
by_cases
(assume h : a = a',
have a ∈ t₁ ∩ t₂, from ⟨mem_of_nhds ht₁, ht₂ $ by rwa [h]⟩,
have f a > f a', from hs this,
lt_irrefl (f a') $ by rwa [h] at this)
(assume h : a ≠ a',
have a' < a, from lt_of_le_of_ne (ha.left _ ha') h.symm,
have {x | a' < x} ∈ (nhds a).sets, from mem_nhds_sets (is_open_lt' _) this,
have {x | a' < x} ∩ t₁ ∈ (nhds a).sets, from inter_mem_sets this ht₁,
have ({x | a' < x} ∩ t₁) ∩ s ∈ (nhds a ⊓ principal s).sets,
from inter_mem_inf_sets this (subset.refl s),
let ⟨x, ⟨hx₁, hx₂⟩, hx₃⟩ := inhabited_of_mem_sets hnbot this in
have hxa' : f x > f a', from hs ⟨hx₂, ht₂ hx₃⟩,
have ha'x : f a' ≥ f x, from hf _ ha' _ hx₃ $ le_of_lt hx₁,
lt_irrefl _ (lt_of_lt_of_le hxa' ha'x)),
and.intro
(assume b' ⟨a', ha', h_eq⟩, h_eq ▸ not_lt.1 $ this _ ha')
(assume b' hb', le_of_tendsto hnbot tendsto_const_nhds hb $
mem_inf_sets_of_right $ assume x hx, hb' _ $ mem_image_of_mem _ hx)
end order_topology
section liminf_limsup
section ordered_topology
variables [semilattice_sup α] [topological_space α] [orderable_topology α]
lemma is_bounded_le_nhds (a : α) : (nhds a).is_bounded (≤) :=
match forall_le_or_exists_lt_sup a with
| or.inl h := ⟨a, univ_mem_sets' h⟩
| or.inr ⟨b, hb⟩ := ⟨b, ge_mem_nhds hb⟩
end
lemma is_bounded_under_le_of_tendsto {f : filter β} {u : β → α} {a : α}
(h : tendsto u f (nhds a)) : f.is_bounded_under (≤) u :=
is_bounded_of_le h (is_bounded_le_nhds a)
lemma is_cobounded_ge_nhds (a : α) : (nhds a).is_cobounded (≥) :=
is_cobounded_of_is_bounded nhds_neq_bot (is_bounded_le_nhds a)
lemma is_cobounded_under_ge_of_tendsto {f : filter β} {u : β → α} {a : α}
(hf : f ≠ ⊥) (h : tendsto u f (nhds a)) : f.is_cobounded_under (≥) u :=
is_cobounded_of_is_bounded (map_ne_bot hf) (is_bounded_under_le_of_tendsto h)
end ordered_topology
section ordered_topology
variables [semilattice_inf α] [topological_space α] [orderable_topology α]
lemma is_bounded_ge_nhds (a : α) : (nhds a).is_bounded (≥) :=
match forall_le_or_exists_lt_inf a with
| or.inl h := ⟨a, univ_mem_sets' h⟩
| or.inr ⟨b, hb⟩ := ⟨b, le_mem_nhds hb⟩
end
lemma is_bounded_under_ge_of_tendsto {f : filter β} {u : β → α} {a : α}
(h : tendsto u f (nhds a)) : f.is_bounded_under (≥) u :=
is_bounded_of_le h (is_bounded_ge_nhds a)
lemma is_cobounded_le_nhds (a : α) : (nhds a).is_cobounded (≤) :=
is_cobounded_of_is_bounded nhds_neq_bot (is_bounded_ge_nhds a)
lemma is_cobounded_under_le_of_tendsto {f : filter β} {u : β → α} {a : α}
(hf : f ≠ ⊥) (h : tendsto u f (nhds a)) : f.is_cobounded_under (≤) u :=
is_cobounded_of_is_bounded (map_ne_bot hf) (is_bounded_under_ge_of_tendsto h)
end ordered_topology
section conditionally_complete_linear_order
variables [conditionally_complete_linear_order α] [topological_space α] [orderable_topology α]
theorem lt_mem_sets_of_Limsup_lt {f : filter α} {b} (h : f.is_bounded (≤)) (l : f.Limsup < b) :
{a | a < b} ∈ f.sets :=
let ⟨c, (h : {a : α | a ≤ c} ∈ f.sets), hcb⟩ :=
exists_lt_of_cInf_lt (ne_empty_iff_exists_mem.2 h) l in
mem_sets_of_superset h $ assume a hac, lt_of_le_of_lt hac hcb
theorem gt_mem_sets_of_Liminf_gt {f : filter α} {b} (h : f.is_bounded (≥)) (l : f.Liminf > b) :
{a | a > b} ∈ f.sets :=
let ⟨c, (h : {a : α | c ≤ a} ∈ f.sets), hbc⟩ :=
exists_lt_of_lt_cSup (ne_empty_iff_exists_mem.2 h) l in
mem_sets_of_superset h $ assume a hca, lt_of_lt_of_le hbc hca
/-- If the liminf and the limsup of a filter coincide, then this filter converges to
their common value, at least if the filter is eventually bounded above and below. -/
theorem le_nhds_of_Limsup_eq_Liminf {f : filter α} {a : α}
(hl : f.is_bounded (≤)) (hg : f.is_bounded (≥)) (hs : f.Limsup = a) (hi : f.Liminf = a) :
f ≤ nhds a :=
tendsto_orderable.2 $ and.intro
(assume b hb, gt_mem_sets_of_Liminf_gt hg $ hi.symm ▸ hb)
(assume b hb, lt_mem_sets_of_Limsup_lt hl $ hs.symm ▸ hb)
theorem Limsup_nhds (a : α) : Limsup (nhds a) = a :=
cInf_intro (ne_empty_iff_exists_mem.2 $ is_bounded_le_nhds a)
(assume a' (h : {n : α | n ≤ a'} ∈ (nhds a).sets), show a ≤ a', from @mem_of_nhds α _ a _ h)
(assume b (hba : a < b), show ∃c (h : {n : α | n ≤ c} ∈ (nhds a).sets), c < b, from
match dense_or_discrete hba with
| or.inl ⟨c, hac, hcb⟩ := ⟨c, ge_mem_nhds hac, hcb⟩
| or.inr ⟨_, h⟩ := ⟨a, (nhds a).sets_of_superset (gt_mem_nhds hba) h, hba⟩
end)
theorem Liminf_nhds (a : α) : Liminf (nhds a) = a :=
cSup_intro (ne_empty_iff_exists_mem.2 $ is_bounded_ge_nhds a)
(assume a' (h : {n : α | a' ≤ n} ∈ (nhds a).sets), show a' ≤ a, from mem_of_nhds h)
(assume b (hba : b < a), show ∃c (h : {n : α | c ≤ n} ∈ (nhds a).sets), b < c, from
match dense_or_discrete hba with
| or.inl ⟨c, hbc, hca⟩ := ⟨c, le_mem_nhds hca, hbc⟩
| or.inr ⟨h, _⟩ := ⟨a, (nhds a).sets_of_superset (lt_mem_nhds hba) h, hba⟩
end)
/-- If a filter is converging, its limsup coincides with its limit. -/
theorem Liminf_eq_of_le_nhds {f : filter α} {a : α} (hf : f ≠ ⊥) (h : f ≤ nhds a) : f.Liminf = a :=
have hb_ge : is_bounded (≥) f, from is_bounded_of_le h (is_bounded_ge_nhds a),
have hb_le : is_bounded (≤) f, from is_bounded_of_le h (is_bounded_le_nhds a),
le_antisymm
(calc f.Liminf ≤ f.Limsup : Liminf_le_Limsup hf hb_le hb_ge
... ≤ (nhds a).Limsup :
Limsup_le_Limsup_of_le h (is_cobounded_of_is_bounded hf hb_ge) (is_bounded_le_nhds a)
... = a : Limsup_nhds a)
(calc a = (nhds a).Liminf : (Liminf_nhds a).symm
... ≤ f.Liminf :
Liminf_le_Liminf_of_le h (is_bounded_ge_nhds a) (is_cobounded_of_is_bounded hf hb_le))
/-- If a filter is converging, its liminf coincides with its limit. -/
theorem Limsup_eq_of_le_nhds {f : filter α} {a : α} (hf : f ≠ ⊥) (h : f ≤ nhds a) : f.Limsup = a :=
have hb_ge : is_bounded (≥) f, from is_bounded_of_le h (is_bounded_ge_nhds a),
le_antisymm
(calc f.Limsup ≤ (nhds a).Limsup :
Limsup_le_Limsup_of_le h (is_cobounded_of_is_bounded hf hb_ge) (is_bounded_le_nhds a)
... = a : Limsup_nhds a)
(calc a = f.Liminf : (Liminf_eq_of_le_nhds hf h).symm
... ≤ f.Limsup : Liminf_le_Limsup hf (is_bounded_of_le h (is_bounded_le_nhds a)) hb_ge)
end conditionally_complete_linear_order
end liminf_limsup
end orderable_topology
lemma orderable_topology_of_nhds_abs
{α : Type*} [decidable_linear_ordered_comm_group α] [topological_space α]
(h_nhds : ∀a:α, nhds a = (⨅r>0, principal {b | abs (a - b) < r})) : orderable_topology α :=
orderable_topology.mk $ eq_of_nhds_eq_nhds $ assume a:α, le_antisymm_iff.mpr
begin
simp [infi_and, topological_space.nhds_generate_from,
h_nhds, le_infi_iff, -le_principal_iff, and_comm],
refine ⟨λ s ha b hs, _, λ r hr, _⟩,
{ rcases hs with rfl | rfl,
{ refine infi_le_of_le (a - b)
(infi_le_of_le (lt_sub_left_of_add_lt $ by simpa using ha) $
principal_mono.mpr $ assume c (hc : abs (a - c) < a - b), _),
have : a - c < a - b := lt_of_le_of_lt (le_abs_self _) hc,
exact lt_of_neg_lt_neg (lt_of_add_lt_add_left this) },
{ refine infi_le_of_le (b - a)
(infi_le_of_le (lt_sub_left_of_add_lt $ by simpa using ha) $
principal_mono.mpr $ assume c (hc : abs (a - c) < b - a), _),
have : abs (c - a) < b - a, {rw abs_sub; simpa using hc},
have : c - a < b - a := lt_of_le_of_lt (le_abs_self _) this,
exact lt_of_add_lt_add_right this } },
{ have h : {b | abs (a + -b) < r} = {b | a - r < b} ∩ {b | b < a + r},
from set.ext (assume b,
by simp [abs_lt, -sub_eq_add_neg, (sub_eq_add_neg _ _).symm,
sub_lt, lt_sub_iff_add_lt, and_comm, sub_lt_iff_lt_add']),
rw [h, ← inf_principal],
apply le_inf _ _,
{ exact infi_le_of_le {b : α | a - r < b} (infi_le_of_le (sub_lt_self a hr) $
infi_le_of_le (a - r) $ infi_le _ (or.inl rfl)) },
{ exact infi_le_of_le {b : α | b < a + r} (infi_le_of_le (lt_add_of_pos_right _ hr) $
infi_le_of_le (a + r) $ infi_le _ (or.inr rfl)) } }
end
|
9e36aaef517006716b847fae423739947830d4a2 | 02005f45e00c7ecf2c8ca5db60251bd1e9c860b5 | /src/group_theory/sylow.lean | b5b56e6b0fba8ea244290399988dbf5cb2902082 | [
"Apache-2.0"
] | permissive | anthony2698/mathlib | 03cd69fe5c280b0916f6df2d07c614c8e1efe890 | 407615e05814e98b24b2ff322b14e8e3eb5e5d67 | refs/heads/master | 1,678,792,774,873 | 1,614,371,563,000 | 1,614,371,563,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 12,216 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import group_theory.group_action
import group_theory.quotient_group
import group_theory.order_of_element
import data.zmod.basic
import data.fintype.card
import data.list.rotate
open equiv fintype finset mul_action function
open equiv.perm subgroup list quotient_group
open_locale big_operators
universes u v w
variables {G : Type u} {α : Type v} {β : Type w} [group G]
local attribute [instance, priority 10] subtype.fintype set_fintype classical.prop_decidable
namespace mul_action
variables [mul_action G α]
lemma mem_fixed_points_iff_card_orbit_eq_one {a : α}
[fintype (orbit G a)] : a ∈ fixed_points G α ↔ card (orbit G a) = 1 :=
begin
rw [fintype.card_eq_one_iff, mem_fixed_points],
split,
{ exact λ h, ⟨⟨a, mem_orbit_self _⟩, λ ⟨b, ⟨x, hx⟩⟩, subtype.eq $ by simp [h x, hx.symm]⟩ },
{ assume h x,
rcases h with ⟨⟨z, hz⟩, hz₁⟩,
exact calc x • a = z : subtype.mk.inj (hz₁ ⟨x • a, mem_orbit _ _⟩)
... = a : (subtype.mk.inj (hz₁ ⟨a, mem_orbit_self _⟩)).symm }
end
lemma card_modeq_card_fixed_points [fintype α] [fintype G] [fintype (fixed_points G α)]
(p : ℕ) {n : ℕ} [hp : fact p.prime] (h : card G = p ^ n) :
card α ≡ card (fixed_points G α) [MOD p] :=
calc card α = card (Σ y : quotient (orbit_rel G α), {x // quotient.mk' x = y}) :
card_congr (sigma_preimage_equiv (@quotient.mk' _ (orbit_rel G α))).symm
... = ∑ a : quotient (orbit_rel G α), card {x // quotient.mk' x = a} : card_sigma _
... ≡ ∑ a : fixed_points G α, 1 [MOD p] :
begin
rw [← zmod.eq_iff_modeq_nat p, sum_nat_cast, sum_nat_cast],
refine eq.symm (sum_bij_ne_zero (λ a _ _, quotient.mk' a.1)
(λ _ _ _, mem_univ _)
(λ a₁ a₂ _ _ _ _ h,
subtype.eq ((mem_fixed_points' α).1 a₂.2 a₁.1 (quotient.exact' h)))
(λ b, _)
(λ a ha _, by rw [← mem_fixed_points_iff_card_orbit_eq_one.1 a.2];
simp only [quotient.eq']; congr)),
{ refine quotient.induction_on' b (λ b _ hb, _),
have : card (orbit G b) ∣ p ^ n,
{ rw [← h, fintype.card_congr (orbit_equiv_quotient_stabilizer G b)],
exact card_quotient_dvd_card _ },
rcases (nat.dvd_prime_pow hp).1 this with ⟨k, _, hk⟩,
have hb' :¬ p ^ 1 ∣ p ^ k,
{ rw [pow_one, ← hk, ← nat.modeq.modeq_zero_iff, ← zmod.eq_iff_modeq_nat,
nat.cast_zero, ← ne.def],
exact eq.mpr (by simp only [quotient.eq']; congr) hb },
have : k = 0 := nat.le_zero_iff.1 (nat.le_of_lt_succ (lt_of_not_ge (mt (pow_dvd_pow p) hb'))),
refine ⟨⟨b, mem_fixed_points_iff_card_orbit_eq_one.2 $ by rw [hk, this, pow_zero]⟩,
mem_univ _, _, rfl⟩,
rw [nat.cast_one], exact one_ne_zero }
end
... = _ : by simp; refl
end mul_action
lemma quotient_group.card_preimage_mk [fintype G] (s : subgroup G)
(t : set (quotient s)) : fintype.card (quotient_group.mk ⁻¹' t) =
fintype.card s * fintype.card t :=
by rw [← fintype.card_prod, fintype.card_congr
(preimage_mk_equiv_subgroup_times_set _ _)]
namespace sylow
/-- Given a vector `v` of length `n`, make a vector of length `n+1` whose product is `1`,
by consing the the inverse of the product of `v`. -/
def mk_vector_prod_eq_one (n : ℕ) (v : vector G n) : vector G (n+1) :=
v.to_list.prod⁻¹ ::ᵥ v
lemma mk_vector_prod_eq_one_injective (n : ℕ) : injective (@mk_vector_prod_eq_one G _ n) :=
λ ⟨v, _⟩ ⟨w, _⟩ h, subtype.eq (show v = w, by injection h with h; injection h)
/-- The type of vectors with terms from `G`, length `n`, and product equal to `1:G`. -/
def vectors_prod_eq_one (G : Type*) [group G] (n : ℕ) : set (vector G n) :=
{v | v.to_list.prod = 1}
lemma mem_vectors_prod_eq_one {n : ℕ} (v : vector G n) :
v ∈ vectors_prod_eq_one G n ↔ v.to_list.prod = 1 := iff.rfl
lemma mem_vectors_prod_eq_one_iff {n : ℕ} (v : vector G (n + 1)) :
v ∈ vectors_prod_eq_one G (n + 1) ↔ v ∈ set.range (@mk_vector_prod_eq_one G _ n) :=
⟨λ (h : v.to_list.prod = 1), ⟨v.tail,
begin
unfold mk_vector_prod_eq_one,
conv {to_rhs, rw ← vector.cons_head_tail v},
suffices : (v.tail.to_list.prod)⁻¹ = v.head,
{ rw this },
rw [← mul_left_inj v.tail.to_list.prod, inv_mul_self, ← list.prod_cons,
← vector.to_list_cons, vector.cons_head_tail, h]
end⟩,
λ ⟨w, hw⟩, by rw [mem_vectors_prod_eq_one, ← hw, mk_vector_prod_eq_one,
vector.to_list_cons, list.prod_cons, inv_mul_self]⟩
/-- The rotation action of `zmod n` (viewed as multiplicative group) on
`vectors_prod_eq_one G n`, where `G` is a multiplicative group. -/
def rotate_vectors_prod_eq_one (G : Type*) [group G] (n : ℕ)
(m : multiplicative (zmod n)) (v : vectors_prod_eq_one G n) : vectors_prod_eq_one G n :=
⟨⟨v.1.to_list.rotate m.val, by simp⟩, prod_rotate_eq_one_of_prod_eq_one v.2 _⟩
instance rotate_vectors_prod_eq_one.mul_action (n : ℕ) [fact (0 < n)] :
mul_action (multiplicative (zmod n)) (vectors_prod_eq_one G n) :=
{ smul := (rotate_vectors_prod_eq_one G n),
one_smul :=
begin
intro v, apply subtype.eq, apply vector.eq _ _,
show rotate _ (0 : zmod n).val = _, rw zmod.val_zero,
exact rotate_zero v.1.to_list
end,
mul_smul := λ a b ⟨⟨v, hv₁⟩, hv₂⟩, subtype.eq $ vector.eq _ _ $
show v.rotate ((a + b : zmod n).val) = list.rotate (list.rotate v (b.val)) (a.val),
by rw [zmod.val_add, rotate_rotate, ← rotate_mod _ (b.val + a.val), add_comm, hv₁] }
lemma one_mem_vectors_prod_eq_one (n : ℕ) : vector.repeat (1 : G) n ∈ vectors_prod_eq_one G n :=
by simp [vector.repeat, vectors_prod_eq_one]
lemma one_mem_fixed_points_rotate (n : ℕ) [fact (0 < n)] :
(⟨vector.repeat (1 : G) n, one_mem_vectors_prod_eq_one n⟩ : vectors_prod_eq_one G n) ∈
fixed_points (multiplicative (zmod n)) (vectors_prod_eq_one G n) :=
λ m, subtype.eq $ vector.eq _ _ $
rotate_eq_self_iff_eq_repeat.2 ⟨(1 : G),
show list.repeat (1 : G) n = list.repeat 1 (list.repeat (1 : G) n).length, by simp⟩ _
/-- Cauchy's theorem -/
lemma exists_prime_order_of_dvd_card [fintype G] (p : ℕ) [hp : fact p.prime]
(hdvd : p ∣ card G) : ∃ x : G, order_of x = p :=
let n : ℕ+ := ⟨p - 1, nat.sub_pos_of_lt hp.one_lt⟩ in
have hn : p = n + 1 := nat.succ_sub hp.pos,
have hcard : card (vectors_prod_eq_one G (n + 1)) = card G ^ (n : ℕ),
by rw [set.ext mem_vectors_prod_eq_one_iff,
set.card_range_of_injective (mk_vector_prod_eq_one_injective _), card_vector],
have hzmod : fintype.card (multiplicative (zmod p)) = p ^ 1,
by { rw pow_one p, exact zmod.card p },
have hmodeq : _ = _ := @mul_action.card_modeq_card_fixed_points
(multiplicative (zmod p)) (vectors_prod_eq_one G p) _ _ _ _ _ _ 1 hp hzmod,
have hdvdcard : p ∣ fintype.card (vectors_prod_eq_one G (n + 1)) :=
calc p ∣ card G ^ 1 : by rwa pow_one
... ∣ card G ^ (n : ℕ) : pow_dvd_pow _ n.2
... = card (vectors_prod_eq_one G (n + 1)) : hcard.symm,
have hdvdcard₂ : p ∣ card (fixed_points (multiplicative (zmod p)) (vectors_prod_eq_one G p)),
by { rw nat.dvd_iff_mod_eq_zero at hdvdcard ⊢, rwa [← hn, hmodeq] at hdvdcard },
have hcard_pos : 0 < card (fixed_points (multiplicative (zmod p)) (vectors_prod_eq_one G p)) :=
fintype.card_pos_iff.2 ⟨⟨⟨vector.repeat 1 p, one_mem_vectors_prod_eq_one _⟩,
one_mem_fixed_points_rotate _⟩⟩,
have hlt : 1 < card (fixed_points (multiplicative (zmod p)) (vectors_prod_eq_one G p)) :=
calc (1 : ℕ) < p : hp.one_lt
... ≤ _ : nat.le_of_dvd hcard_pos hdvdcard₂,
let ⟨⟨⟨⟨x, hx₁⟩, hx₂⟩, hx₃⟩, hx₄⟩ := fintype.exists_ne_of_one_lt_card hlt
⟨_, one_mem_fixed_points_rotate p⟩ in
have hx : x ≠ list.repeat (1 : G) p, from λ h, by simpa [h, vector.repeat] using hx₄,
have ∃ a, x = list.repeat a x.length := by exactI rotate_eq_self_iff_eq_repeat.1 (λ n,
have list.rotate x (n : zmod p).val = x :=
subtype.mk.inj (subtype.mk.inj (hx₃ (n : zmod p))),
by rwa [zmod.val_nat_cast, ← hx₁, rotate_mod] at this),
let ⟨a, ha⟩ := this in
⟨a, have hx1 : x.prod = 1 := hx₂,
have ha1: a ≠ 1, from λ h, hx (ha.symm ▸ h ▸ hx₁ ▸ rfl),
have a ^ p = 1, by rwa [ha, list.prod_repeat, hx₁] at hx1,
(hp.2 _ (order_of_dvd_of_pow_eq_one this)).resolve_left
(λ h, ha1 (order_of_eq_one_iff.1 h))⟩
open subgroup submonoid is_group_hom mul_action
lemma mem_fixed_points_mul_left_cosets_iff_mem_normalizer {H : subgroup G}
[fintype ((H : set G) : Type u)] {x : G} :
(x : quotient H) ∈ fixed_points H (quotient H) ↔ x ∈ normalizer H :=
⟨λ hx, have ha : ∀ {y : quotient H}, y ∈ orbit H (x : quotient H) → y = x,
from λ _, ((mem_fixed_points' _).1 hx _),
(inv_mem_iff _).1 (@mem_normalizer_fintype _ _ _ _inst_2 _ (λ n (hn : n ∈ H),
have (n⁻¹ * x)⁻¹ * x ∈ H := quotient_group.eq.1 (ha (mem_orbit _ ⟨n⁻¹, H.inv_mem hn⟩)),
show _ ∈ H, by {rw [mul_inv_rev, inv_inv] at this, convert this, rw inv_inv}
)),
λ (hx : ∀ (n : G), n ∈ H ↔ x * n * x⁻¹ ∈ H),
(mem_fixed_points' _).2 $ λ y, quotient.induction_on' y $ λ y hy, quotient_group.eq.2
(let ⟨⟨b, hb₁⟩, hb₂⟩ := hy in
have hb₂ : (b * x)⁻¹ * y ∈ H := quotient_group.eq.1 hb₂,
(inv_mem_iff H).1 $ (hx _).2 $ (mul_mem_cancel_left H (H.inv_mem hb₁)).1
$ by rw hx at hb₂;
simpa [mul_inv_rev, mul_assoc] using hb₂)⟩
def fixed_points_mul_left_cosets_equiv_quotient (H : subgroup G) [fintype (H : set G)] :
fixed_points H (quotient H) ≃
quotient (subgroup.comap ((normalizer H).subtype : normalizer H →* G) H) :=
@subtype_quotient_equiv_quotient_subtype G (normalizer H : set G) (id _) (id _) (fixed_points _ _)
(λ a, (@mem_fixed_points_mul_left_cosets_iff_mem_normalizer _ _ _ _inst_2 _).symm)
(by intros; refl)
lemma exists_subgroup_card_pow_prime [fintype G] (p : ℕ) : ∀ {n : ℕ} [hp : fact p.prime]
(hdvd : p ^ n ∣ card G), ∃ H : subgroup G, fintype.card H = p ^ n
| 0 := λ _ _, ⟨(⊥ : subgroup G), by convert card_trivial⟩
| (n+1) := λ hp hdvd,
let ⟨H, hH2⟩ := @exists_subgroup_card_pow_prime _ hp
(dvd.trans (pow_dvd_pow _ (nat.le_succ _)) hdvd) in
let ⟨s, hs⟩ := exists_eq_mul_left_of_dvd hdvd in
have hcard : card (quotient H) = s * p :=
(nat.mul_left_inj (show card H > 0, from fintype.card_pos_iff.2
⟨⟨1, H.one_mem⟩⟩)).1
(by rwa [← card_eq_card_quotient_mul_card_subgroup H, hH2, hs,
pow_succ', mul_assoc, mul_comm p]),
have hm : s * p % p =
card (quotient (subgroup.comap ((normalizer H).subtype : normalizer H →* G) H)) % p :=
card_congr (fixed_points_mul_left_cosets_equiv_quotient H) ▸ hcard ▸
@card_modeq_card_fixed_points _ _ _ _ _ _ _ p _ hp hH2,
have hm' : p ∣ card (quotient (subgroup.comap ((normalizer H).subtype : normalizer H →* G) H)) :=
nat.dvd_of_mod_eq_zero
(by rwa [nat.mod_eq_zero_of_dvd (dvd_mul_left _ _), eq_comm] at hm),
let ⟨x, hx⟩ := @exists_prime_order_of_dvd_card _ (quotient_group.quotient.group _) _ _ hp hm' in
have hequiv : H ≃ (subgroup.comap ((normalizer H).subtype : normalizer H →* G) H) :=
⟨λ a, ⟨⟨a.1, le_normalizer a.2⟩, a.2⟩, λ a, ⟨a.1.1, a.2⟩,
λ ⟨_, _⟩, rfl, λ ⟨⟨_, _⟩, _⟩, rfl⟩,
-- begin proof of ∃ H : subgroup G, fintype.card H = p ^ n
⟨subgroup.map ((normalizer H).subtype) (subgroup.comap
(quotient_group.mk' (comap H.normalizer.subtype H)) (gpowers x)),
begin
show card ↥(map H.normalizer.subtype
(comap (mk' (comap H.normalizer.subtype H)) (subgroup.gpowers x))) = p ^ (n + 1),
suffices : card ↥(subtype.val '' ((subgroup.comap (mk' (comap H.normalizer.subtype H))
(gpowers x)) : set (↥(H.normalizer)))) = p^(n+1),
{ convert this using 2 },
rw [set.card_image_of_injective
(subgroup.comap (mk' (comap H.normalizer.subtype H)) (gpowers x) : set (H.normalizer))
subtype.val_injective,
pow_succ', ← hH2, fintype.card_congr hequiv, ← hx, order_eq_card_gpowers,
← fintype.card_prod],
exact @fintype.card_congr _ _ (id _) (id _) (preimage_mk_equiv_subgroup_times_set _ _)
end⟩
end sylow
|
5939ea78e3dd19e556df198aab49564f27429345 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/order/lattice_intervals_auto.lean | b683dd72480c848735915ff135c9b81cae20e2c5 | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 10,982 | lean | /-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Aaron Anderson.
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.order.bounded_lattice
import Mathlib.data.set.intervals.basic
import Mathlib.PostPort
universes u_1
namespace Mathlib
/-!
# Intervals in Lattices
In this file, we provide instances of lattice structures on intervals within lattices.
Some of them depend on the order of the endpoints of the interval, and thus are not made
global instances. These are probably not all of the lattice instances that could be placed on these
intervals, but more can be added easily along the same lines when needed.
## Main definitions
In the following, `*` can represent either `c`, `o`, or `i`.
* `set.Ic*.semilattice_inf_bot`
* `set.Ii*.semillatice_inf`
* `set.I*c.semilattice_sup_top`
* `set.I*c.semillatice_inf`
* `set.Iic.bounded_lattice`, within a `bounded_lattice`
* `set.Ici.bounded_lattice`, within a `bounded_lattice`
-/
namespace set
namespace Ico
protected instance semilattice_inf {α : Type u_1} {a : α} {b : α} [semilattice_inf α] :
semilattice_inf ↥(Ico a b) :=
subtype.semilattice_inf sorry
/-- `Ico a b` has a bottom element whenever `a < b`. -/
def order_bot {α : Type u_1} {a : α} {b : α} [partial_order α] (h : a < b) : order_bot ↥(Ico a b) :=
order_bot.mk { val := a, property := sorry } partial_order.le partial_order.lt sorry sorry sorry
sorry
/-- `Ico a b` is a `semilattice_inf_bot` whenever `a < b`. -/
def semilattice_inf_bot {α : Type u_1} {a : α} {b : α} [semilattice_inf α] (h : a < b) :
semilattice_inf_bot ↥(Ico a b) :=
semilattice_inf_bot.mk order_bot.bot semilattice_inf.le semilattice_inf.lt sorry sorry sorry sorry
semilattice_inf.inf sorry sorry sorry
end Ico
namespace Iio
protected instance semilattice_inf {α : Type u_1} [semilattice_inf α] {a : α} :
semilattice_inf ↥(Iio a) :=
subtype.semilattice_inf sorry
end Iio
namespace Ioc
protected instance semilattice_sup {α : Type u_1} {a : α} {b : α} [semilattice_sup α] :
semilattice_sup ↥(Ioc a b) :=
subtype.semilattice_sup sorry
/-- `Ioc a b` has a top element whenever `a < b`. -/
def order_top {α : Type u_1} {a : α} {b : α} [partial_order α] (h : a < b) : order_top ↥(Ioc a b) :=
order_top.mk { val := b, property := sorry } partial_order.le partial_order.lt sorry sorry sorry
sorry
/-- `Ioc a b` is a `semilattice_sup_top` whenever `a < b`. -/
def semilattice_sup_top {α : Type u_1} {a : α} {b : α} [semilattice_sup α] (h : a < b) :
semilattice_sup_top ↥(Ioc a b) :=
semilattice_sup_top.mk order_top.top semilattice_sup.le semilattice_sup.lt sorry sorry sorry sorry
semilattice_sup.sup sorry sorry sorry
end Ioc
namespace Iio
protected instance set.Ioi.semilattice_sup {α : Type u_1} [semilattice_sup α] {a : α} :
semilattice_sup ↥(Ioi a) :=
subtype.semilattice_sup sorry
end Iio
namespace Iic
protected instance semilattice_inf {α : Type u_1} {a : α} [semilattice_inf α] :
semilattice_inf ↥(Iic a) :=
subtype.semilattice_inf sorry
protected instance semilattice_sup {α : Type u_1} {a : α} [semilattice_sup α] :
semilattice_sup ↥(Iic a) :=
subtype.semilattice_sup sorry
protected instance lattice {α : Type u_1} {a : α} [lattice α] : lattice ↥(Iic a) :=
lattice.mk semilattice_sup.sup semilattice_inf.le semilattice_inf.lt sorry sorry sorry sorry sorry
sorry semilattice_inf.inf sorry sorry sorry
protected instance order_top {α : Type u_1} {a : α} [partial_order α] : order_top ↥(Iic a) :=
order_top.mk { val := a, property := sorry } partial_order.le partial_order.lt sorry sorry sorry
sorry
@[simp] theorem coe_top {α : Type u_1} [partial_order α] {a : α} : ↑⊤ = a := rfl
protected instance semilattice_inf_top {α : Type u_1} {a : α} [semilattice_inf α] :
semilattice_inf_top ↥(Iic a) :=
semilattice_inf_top.mk order_top.top semilattice_inf.le semilattice_inf.lt sorry sorry sorry sorry
semilattice_inf.inf sorry sorry sorry
protected instance semilattice_sup_top {α : Type u_1} {a : α} [semilattice_sup α] :
semilattice_sup_top ↥(Iic a) :=
semilattice_sup_top.mk order_top.top semilattice_sup.le semilattice_sup.lt sorry sorry sorry sorry
semilattice_sup.sup sorry sorry sorry
protected instance order_bot {α : Type u_1} {a : α} [order_bot α] : order_bot ↥(Iic a) :=
order_bot.mk { val := ⊥, property := bot_le } partial_order.le partial_order.lt sorry sorry sorry
sorry
@[simp] theorem coe_bot {α : Type u_1} [order_bot α] {a : α} : ↑⊥ = ⊥ := rfl
protected instance semilattice_inf_bot {α : Type u_1} {a : α} [semilattice_inf_bot α] :
semilattice_inf_bot ↥(Iic a) :=
semilattice_inf_bot.mk order_bot.bot semilattice_inf.le semilattice_inf.lt sorry sorry sorry sorry
semilattice_inf.inf sorry sorry sorry
protected instance semilattice_sup_bot {α : Type u_1} {a : α} [semilattice_sup_bot α] :
semilattice_sup_bot ↥(Iic a) :=
semilattice_sup_bot.mk order_bot.bot semilattice_sup.le semilattice_sup.lt sorry sorry sorry sorry
semilattice_sup.sup sorry sorry sorry
protected instance bounded_lattice {α : Type u_1} {a : α} [bounded_lattice α] :
bounded_lattice ↥(Iic a) :=
bounded_lattice.mk lattice.sup order_top.le order_top.lt sorry sorry sorry sorry sorry sorry
lattice.inf sorry sorry sorry order_top.top sorry order_bot.bot sorry
end Iic
namespace Ici
protected instance semilattice_inf {α : Type u_1} {a : α} [semilattice_inf α] :
semilattice_inf ↥(Ici a) :=
subtype.semilattice_inf sorry
protected instance semilattice_sup {α : Type u_1} {a : α} [semilattice_sup α] :
semilattice_sup ↥(Ici a) :=
subtype.semilattice_sup sorry
protected instance lattice {α : Type u_1} {a : α} [lattice α] : lattice ↥(Ici a) :=
lattice.mk semilattice_sup.sup semilattice_inf.le semilattice_inf.lt sorry sorry sorry sorry sorry
sorry semilattice_inf.inf sorry sorry sorry
protected instance order_bot {α : Type u_1} {a : α} [partial_order α] : order_bot ↥(Ici a) :=
order_bot.mk { val := a, property := sorry } partial_order.le partial_order.lt sorry sorry sorry
sorry
@[simp] theorem coe_bot {α : Type u_1} [partial_order α] {a : α} : ↑⊥ = a := rfl
protected instance semilattice_inf_bot {α : Type u_1} {a : α} [semilattice_inf α] :
semilattice_inf_bot ↥(Ici a) :=
semilattice_inf_bot.mk order_bot.bot semilattice_inf.le semilattice_inf.lt sorry sorry sorry sorry
semilattice_inf.inf sorry sorry sorry
protected instance semilattice_sup_bot {α : Type u_1} {a : α} [semilattice_sup α] :
semilattice_sup_bot ↥(Ici a) :=
semilattice_sup_bot.mk order_bot.bot semilattice_sup.le semilattice_sup.lt sorry sorry sorry sorry
semilattice_sup.sup sorry sorry sorry
protected instance order_top {α : Type u_1} {a : α} [order_top α] : order_top ↥(Ici a) :=
order_top.mk { val := ⊤, property := le_top } partial_order.le partial_order.lt sorry sorry sorry
sorry
@[simp] theorem coe_top {α : Type u_1} [order_top α] {a : α} : ↑⊤ = ⊤ := rfl
protected instance semilattice_sup_top {α : Type u_1} {a : α} [semilattice_sup_top α] :
semilattice_sup_top ↥(Ici a) :=
semilattice_sup_top.mk order_top.top semilattice_sup.le semilattice_sup.lt sorry sorry sorry sorry
semilattice_sup.sup sorry sorry sorry
protected instance semilattice_inf_top {α : Type u_1} {a : α} [semilattice_inf_top α] :
semilattice_inf_top ↥(Ici a) :=
semilattice_inf_top.mk order_top.top semilattice_inf.le semilattice_inf.lt sorry sorry sorry sorry
semilattice_inf.inf sorry sorry sorry
protected instance bounded_lattice {α : Type u_1} {a : α} [bounded_lattice α] :
bounded_lattice ↥(Ici a) :=
bounded_lattice.mk lattice.sup order_top.le order_top.lt sorry sorry sorry sorry sorry sorry
lattice.inf sorry sorry sorry order_top.top sorry order_bot.bot sorry
end Ici
namespace Icc
protected instance semilattice_inf {α : Type u_1} [semilattice_inf α] {a : α} {b : α} :
semilattice_inf ↥(Icc a b) :=
subtype.semilattice_inf sorry
protected instance semilattice_sup {α : Type u_1} [semilattice_sup α] {a : α} {b : α} :
semilattice_sup ↥(Icc a b) :=
subtype.semilattice_sup sorry
protected instance lattice {α : Type u_1} [lattice α] {a : α} {b : α} : lattice ↥(Icc a b) :=
lattice.mk semilattice_sup.sup semilattice_inf.le semilattice_inf.lt sorry sorry sorry sorry sorry
sorry semilattice_inf.inf sorry sorry sorry
/-- `Icc a b` has a bottom element whenever `a ≤ b`. -/
def order_bot {α : Type u_1} [partial_order α] {a : α} {b : α} (h : a ≤ b) : order_bot ↥(Icc a b) :=
order_bot.mk { val := a, property := sorry } partial_order.le partial_order.lt sorry sorry sorry
sorry
/-- `Icc a b` has a top element whenever `a ≤ b`. -/
def order_top {α : Type u_1} [partial_order α] {a : α} {b : α} (h : a ≤ b) : order_top ↥(Icc a b) :=
order_top.mk { val := b, property := sorry } partial_order.le partial_order.lt sorry sorry sorry
sorry
/-- `Icc a b` is a `semilattice_inf_bot` whenever `a ≤ b`. -/
def semilattice_inf_bot {α : Type u_1} [semilattice_inf α] {a : α} {b : α} (h : a ≤ b) :
semilattice_inf_bot ↥(Icc a b) :=
semilattice_inf_bot.mk order_bot.bot order_bot.le order_bot.lt sorry sorry sorry sorry
semilattice_inf.inf sorry sorry sorry
/-- `Icc a b` is a `semilattice_inf_top` whenever `a ≤ b`. -/
def semilattice_inf_top {α : Type u_1} [semilattice_inf α] {a : α} {b : α} (h : a ≤ b) :
semilattice_inf_top ↥(Icc a b) :=
semilattice_inf_top.mk order_top.top order_top.le order_top.lt sorry sorry sorry sorry
semilattice_inf.inf sorry sorry sorry
/-- `Icc a b` is a `semilattice_sup_bot` whenever `a ≤ b`. -/
def semilattice_sup_bot {α : Type u_1} [semilattice_sup α] {a : α} {b : α} (h : a ≤ b) :
semilattice_sup_bot ↥(Icc a b) :=
semilattice_sup_bot.mk order_bot.bot order_bot.le order_bot.lt sorry sorry sorry sorry
semilattice_sup.sup sorry sorry sorry
/-- `Icc a b` is a `semilattice_sup_top` whenever `a ≤ b`. -/
def semilattice_sup_top {α : Type u_1} [semilattice_sup α] {a : α} {b : α} (h : a ≤ b) :
semilattice_sup_top ↥(Icc a b) :=
semilattice_sup_top.mk order_top.top order_top.le order_top.lt sorry sorry sorry sorry
semilattice_sup.sup sorry sorry sorry
/-- `Icc a b` is a `bounded_lattice` whenever `a ≤ b`. -/
def bounded_lattice {α : Type u_1} [lattice α] {a : α} {b : α} (h : a ≤ b) :
bounded_lattice ↥(Icc a b) :=
bounded_lattice.mk semilattice_sup_top.sup semilattice_inf_bot.le semilattice_inf_bot.lt sorry
sorry sorry sorry sorry sorry semilattice_inf_bot.inf sorry sorry sorry semilattice_sup_top.top
sorry semilattice_inf_bot.bot sorry
end Mathlib |
0c5cf840e337a4c851be00712e8cba262e180a18 | 947b78d97130d56365ae2ec264df196ce769371a | /tests/bench/deriv.lean | 50c00effe562a7fe6849be98bdca9c10776f7ef6 | [
"Apache-2.0"
] | permissive | shyamalschandra/lean4 | 27044812be8698f0c79147615b1d5090b9f4b037 | 6e7a883b21eaf62831e8111b251dc9b18f40e604 | refs/heads/master | 1,671,417,126,371 | 1,601,859,995,000 | 1,601,860,020,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,906 | lean | /- Benchmark for new code generator -/
inductive Expr
| Val : Int → Expr
| Var : String → Expr
| Add : Expr → Expr → Expr
| Mul : Expr → Expr → Expr
| Pow : Expr → Expr → Expr
| Ln : Expr → Expr
open Expr
partial def pown : Int → Int → Int
| a, 0 => 1
| a, 1 => a
| a, n =>
let b := pown a (n / 2);
b * b * (if n % 2 = 0 then 1 else a)
partial def add : Expr → Expr → Expr
| Val n, Val m => Val (n + m)
| Val 0, f => f
| f, Val 0 => f
| f, Val n => add (Val n) f
| Val n, Add (Val m) f => add (Val (n+m)) f
| f, Add (Val n) g => add (Val n) (add f g)
| Add f g, h => add f (add g h)
| f, g => Add f g
partial def mul : Expr → Expr → Expr
| Val n, Val m => Val (n*m)
| Val 0, _ => Val 0
| _, Val 0 => Val 0
| Val 1, f => f
| f, Val 1 => f
| f, Val n => mul (Val n) f
| Val n, Mul (Val m) f => mul (Val (n*m)) f
| f, Mul (Val n) g => mul (Val n) (mul f g)
| Mul f g, h => mul f (mul g h)
| f, g => Mul f g
def pow : Expr → Expr → Expr
| Val m, Val n => Val (pown m n)
| _, Val 0 => Val 1
| f, Val 1 => f
| Val 0, _ => Val 0
| f, g => Pow f g
def ln : Expr → Expr
| Val 1 => Val 0
| f => Ln f
def d (x : String) : Expr → Expr
| Val _ => Val 0
| Var y => if x = y then Val 1 else Val 0
| Add f g => add (d f) (d g)
| Mul f g => add (mul f (d g)) (mul g (d f))
| Pow f g => mul (pow f g) (add (mul (mul g (d f)) (pow f (Val (-1)))) (mul (ln f) (d g)))
| Ln f => mul (d f) (pow f (Val (-1)))
def count : Expr → UInt32
| Val _ => 1
| Var _ => 1
| Add f g => count f + count g
| Mul f g => count f + count g
| Pow f g => count f + count g
| Ln f => count f
def Expr.toString : Expr → String
| Val n => toString n
| Var x => x
| Add f g => "(" ++ Expr.toString f ++ " + " ++ Expr.toString g ++ ")"
| Mul f g => "(" ++ Expr.toString f ++ " * " ++ Expr.toString g ++ ")"
| Pow f g => "(" ++ Expr.toString f ++ " ^ " ++ Expr.toString g ++ ")"
| Ln f => "ln(" ++ Expr.toString f ++ ")"
instance : HasToString Expr :=
⟨Expr.toString⟩
def nestAux (s : Nat) (f : Nat → Expr → IO Expr) : Nat → Expr → IO Expr
| 0, x => pure x
| m@(n+1), x => f (s - m) x >>= nestAux n
def nest (f : Nat → Expr → IO Expr) (n : Nat) (e : Expr) : IO Expr :=
nestAux n f n e
def deriv (i : Nat) (f : Expr) : IO Expr :=
do
let d := d "x" f;
IO.println (toString (i+1) ++ " count: " ++ (toString $ count d));
pure d
unsafe def main : List String → IO UInt32
| [s] => do
let n := s.toNat!;
let x := Var "x";
let f := pow x x;
_ ← nest deriv n f;
pure 0
| _ => pure 1
|
874cf1e35463b40ba0f289e9d013162257763bca | c055f4b7c29cf1aac2223bd8c1ac8d181a7c6447 | /src/categories/category.lean | 02f4278ef0681d1ad28f8203d2459a2b15b0d168 | [
"Apache-2.0"
] | permissive | rwbarton/lean-category-theory-pr | 77207b6674eeec1e258ec85dea58f3bff8d27065 | 591847d70c6a11c4d5561cd0eaf69b1fe85a70ab | refs/heads/master | 1,584,595,111,303 | 1,528,029,041,000 | 1,528,029,041,000 | 135,919,126 | 0 | 0 | null | 1,528,041,805,000 | 1,528,041,805,000 | null | UTF-8 | Lean | false | false | 2,873 | lean | -- Copyright (c) 2017 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Stephen Morgan, Scott Morrison
import .tactics
namespace categories
universes u v
/-
The propositional fields of `category` are annotated with the auto_param `obviously_stub`, which is just a synonym for `skip`.
Actually, there is a tactic called `obviously` which is not part of this pull request, which should be used here. It successfully
discharges a great many of these goals. For now, proofs which could be provided entirely by `obviously` (and hence omitted entirely
and discharged by an auto_param), are all marked with a comment "-- obviously says:".
-/
class category (Obj : Type u) : Type (max u (v+1)) :=
(Hom : Obj → Obj → Type v)
(identity : Π X : Obj, Hom X X)
(compose : Π {X Y Z : Obj}, Hom X Y → Hom Y Z → Hom X Z)
(left_identity : ∀ {X Y : Obj} (f : Hom X Y), compose (identity X) f = f . obviously)
(right_identity : ∀ {X Y : Obj} (f : Hom X Y), compose f (identity Y) = f . obviously)
(associativity : ∀ {W X Y Z : Obj} (f : Hom W X) (g : Hom X Y) (h : Hom Y Z), compose (compose f g) h = compose f (compose g h) . obviously)
notation `𝟙` := category.identity -- type as \b1
infixr ` ≫ `:80 := category.compose -- type as \gg
infixr ` ⟶ `:10 := category.Hom -- type as \h
-- make_lemma is a command that creates a lemma from a structure field, discarding all auto_param wrappers from the type.
make_lemma category.left_identity
make_lemma category.right_identity
make_lemma category.associativity
-- We tag some lemmas with the attribute @[ematch], for later automation.
attribute [simp,ematch] category.left_identity_lemma category.right_identity_lemma category.associativity_lemma
attribute [ematch] category.associativity_lemma
abbreviation large_category (C : Type (u+1)) : Type (u+1) := category.{u+1 u} C
abbreviation small_category (C : Type u) : Type (u+1) := category.{u u} C
-- TODO reconsider whether providing `has_one` is actually valuable
section
variable {C : Type (u+1)}
variables {X Y : C}
variable [large_category C]
instance large_category.has_one : has_one (X ⟶ X) :=
{ one := 𝟙 X }
@[simp] def large_category.left_identity_lemma' (f : X ⟶ Y) : 1 ≫ f = f := begin unfold has_one.one, simp end
@[simp] def large_category.right_identity_lemma' (f : X ⟶ Y) : f ≫ 1 = f := begin unfold has_one.one, simp end
end
section
variable {C : Type u}
variables {X Y : C}
variable [small_category C]
instance small_category.has_one : has_one (X ⟶ X) :=
{ one := 𝟙 X }
@[simp] def small_category.left_identity_lemma' (f : X ⟶ Y) : 1 ≫ f = f := begin unfold has_one.one, simp end
@[simp] def small_category.right_identity_lemma' (f : X ⟶ Y) : f ≫ 1 = f := begin unfold has_one.one, simp end
end
end categories
|
3a1729551836630e2a98a1ac8de3891586ffb879 | d1bbf1801b3dcb214451d48214589f511061da63 | /src/topology/separation.lean | 296def94dc466849495fed1839e27308774773a5 | [
"Apache-2.0"
] | permissive | cheraghchi/mathlib | 5c366f8c4f8e66973b60c37881889da8390cab86 | f29d1c3038422168fbbdb2526abf7c0ff13e86db | refs/heads/master | 1,676,577,831,283 | 1,610,894,638,000 | 1,610,894,638,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 35,157 | 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
Separation properties of topological spaces.
-/
import topology.subset_properties
open set filter
open_locale topological_space filter
local attribute [instance] classical.prop_decidable -- TODO: use "open_locale classical"
universes u v
variables {α : Type u} {β : Type v} [topological_space α]
section separation
/--
`separated` is a predicate on pairs of sub`set`s of a topological space. It holds if the two
sub`set`s are contained in disjoint open sets.
-/
def separated : set α → set α → Prop :=
λ (s t : set α), ∃ U V : (set α), (is_open U) ∧ is_open V ∧
(s ⊆ U) ∧ (t ⊆ V) ∧ disjoint U V
namespace separated
open separated
@[symm] lemma symm {s t : set α} : separated s t → separated t s :=
λ ⟨U, V, oU, oV, aU, bV, UV⟩, ⟨V, U, oV, oU, bV, aU, disjoint.symm UV⟩
lemma comm (s t : set α) : separated s t ↔ separated t s :=
⟨symm, symm⟩
lemma empty_right (a : set α) : separated a ∅ :=
⟨_, _, is_open_univ, is_open_empty, λ a h, mem_univ a, λ a h, by cases h, disjoint_empty _⟩
lemma empty_left (a : set α) : separated ∅ a :=
(empty_right _).symm
lemma union_left {a b c : set α} : separated a c → separated b c → separated (a ∪ b) c :=
λ ⟨U, V, oU, oV, aU, bV, UV⟩ ⟨W, X, oW, oX, aW, bX, WX⟩,
⟨U ∪ W, V ∩ X, is_open_union oU oW, is_open_inter oV oX,
union_subset_union aU aW, subset_inter bV bX, set.disjoint_union_left.mpr
⟨disjoint_of_subset_right (inter_subset_left _ _) UV,
disjoint_of_subset_right (inter_subset_right _ _) WX⟩⟩
lemma union_right {a b c : set α} (ab : separated a b) (ac : separated a c) :
separated a (b ∪ c) :=
(ab.symm.union_left ac.symm).symm
end separated
/-- A T₀ space, also known as a Kolmogorov space, is a topological space
where for every pair `x ≠ y`, there is an open set containing one but not the other. -/
class t0_space (α : Type u) [topological_space α] : Prop :=
(t0 : ∀ x y, x ≠ y → ∃ U:set α, is_open U ∧ (xor (x ∈ U) (y ∈ U)))
theorem exists_open_singleton_of_open_finset [t0_space α] (s : finset α) (sne : s.nonempty)
(hso : is_open (↑s : set α)) :
∃ x ∈ s, is_open ({x} : set α):=
begin
induction s using finset.strong_induction_on with s ihs,
by_cases hs : set.subsingleton (↑s : set α),
{ rcases sne with ⟨x, hx⟩,
refine ⟨x, hx, _⟩,
have : (↑s : set α) = {x}, from hs.eq_singleton_of_mem hx,
rwa this at hso },
{ dunfold set.subsingleton at hs,
push_neg at hs,
rcases hs with ⟨x, hx, y, hy, hxy⟩,
rcases t0_space.t0 x y hxy with ⟨U, hU, hxyU⟩,
wlog H : x ∈ U ∧ y ∉ U := hxyU using [x y, y x],
obtain ⟨z, hzs, hz⟩ : ∃ z ∈ s.filter (λ z, z ∈ U), is_open ({z} : set α),
{ refine ihs _ (finset.filter_ssubset.2 ⟨y, hy, H.2⟩) ⟨x, finset.mem_filter.2 ⟨hx, H.1⟩⟩ _,
rw [finset.coe_filter],
exact is_open_inter hso hU },
exact ⟨z, (finset.mem_filter.1 hzs).1, hz⟩ }
end
theorem exists_open_singleton_of_fintype [t0_space α] [f : fintype α] [ha : nonempty α] :
∃ x:α, is_open ({x}:set α) :=
begin
refine ha.elim (λ x, _),
have : is_open (↑(finset.univ : finset α) : set α), { simp },
rcases exists_open_singleton_of_open_finset _ ⟨x, finset.mem_univ x⟩ this with ⟨x, _, hx⟩,
exact ⟨x, hx⟩
end
instance subtype.t0_space [t0_space α] {p : α → Prop} : t0_space (subtype p) :=
⟨λ x y hxy, let ⟨U, hU, hxyU⟩ := t0_space.t0 (x:α) y ((not_congr subtype.ext_iff_val).1 hxy) in
⟨(coe : subtype p → α) ⁻¹' U, is_open_induced hU, hxyU⟩⟩
/-- A T₁ space, also known as a Fréchet space, is a topological space
where every singleton set is closed. Equivalently, for every pair
`x ≠ y`, there is an open set containing `x` and not `y`. -/
class t1_space (α : Type u) [topological_space α] : Prop :=
(t1 : ∀x, is_closed ({x} : set α))
lemma is_closed_singleton [t1_space α] {x : α} : is_closed ({x} : set α) :=
t1_space.t1 x
lemma is_open_compl_singleton [t1_space α] {x : α} : is_open ({x}ᶜ : set α) :=
is_closed_singleton
lemma is_open_ne [t1_space α] {x : α} : is_open {y | y ≠ x} :=
is_open_compl_singleton
instance subtype.t1_space {α : Type u} [topological_space α] [t1_space α] {p : α → Prop} :
t1_space (subtype p) :=
⟨λ ⟨x, hx⟩, is_closed_induced_iff.2 $ ⟨{x}, is_closed_singleton, set.ext $ λ y,
by simp [subtype.ext_iff_val]⟩⟩
@[priority 100] -- see Note [lower instance priority]
instance t1_space.t0_space [t1_space α] : t0_space α :=
⟨λ x y h, ⟨{z | z ≠ y}, is_open_ne, or.inl ⟨h, not_not_intro rfl⟩⟩⟩
lemma compl_singleton_mem_nhds [t1_space α] {x y : α} (h : y ≠ x) : {x}ᶜ ∈ 𝓝 y :=
mem_nhds_sets is_closed_singleton $ by rwa [mem_compl_eq, mem_singleton_iff]
@[simp] lemma closure_singleton [t1_space α] {a : α} :
closure ({a} : set α) = {a} :=
is_closed_singleton.closure_eq
lemma is_closed_map_const {α β} [topological_space α] [topological_space β] [t1_space β] {y : β} :
is_closed_map (function.const α y) :=
begin
apply is_closed_map.of_nonempty, intros s hs h2s, simp_rw [h2s.image_const, is_closed_singleton]
end
lemma discrete_of_t1_of_finite {X : Type*} [topological_space X] [t1_space X] [fintype X] :
discrete_topology X :=
begin
apply singletons_open_iff_discrete.mp,
intros x,
rw [← is_closed_compl_iff, ← bUnion_of_singleton ({x} : set X)ᶜ],
exact is_closed_bUnion (finite.of_fintype _) (λ y _, is_closed_singleton)
end
lemma singleton_mem_nhds_within_of_mem_discrete {s : set α} [discrete_topology s]
{x : α} (hx : x ∈ s) :
{x} ∈ 𝓝[s] x :=
begin
have : ({⟨x, hx⟩} : set s) ∈ 𝓝 (⟨x, hx⟩ : s), by simp [nhds_discrete],
simpa only [nhds_within_eq_map_subtype_coe hx, image_singleton]
using @image_mem_map _ _ _ (coe : s → α) _ this
end
lemma nhds_within_of_mem_discrete {s : set α} [discrete_topology s] {x : α} (hx : x ∈ s) :
𝓝[s] x = pure x :=
le_antisymm (le_pure_iff.2 $ singleton_mem_nhds_within_of_mem_discrete hx) (pure_le_nhds_within hx)
lemma filter.has_basis.exists_inter_eq_singleton_of_mem_discrete
{ι : Type*} {p : ι → Prop} {t : ι → set α} {s : set α} [discrete_topology s] {x : α}
(hb : (𝓝 x).has_basis p t) (hx : x ∈ s) :
∃ i (hi : p i), t i ∩ s = {x} :=
begin
rcases (nhds_within_has_basis hb s).mem_iff.1 (singleton_mem_nhds_within_of_mem_discrete hx)
with ⟨i, hi, hix⟩,
exact ⟨i, hi, subset.antisymm hix $ singleton_subset_iff.2 ⟨mem_of_nhds $ hb.mem_of_mem hi, hx⟩⟩
end
/-- A point `x` in a discrete subset `s` of a topological space admits a neighbourhood
that only meets `s` at `x`. -/
lemma nhds_inter_eq_singleton_of_mem_discrete {s : set α} [discrete_topology s]
{x : α} (hx : x ∈ s) :
∃ U ∈ 𝓝 x, U ∩ s = {x} :=
by simpa using (𝓝 x).basis_sets.exists_inter_eq_singleton_of_mem_discrete hx
/-- For point `x` in a discrete subset `s` of a topological space, there is a set `U`
such that
1. `U` is a punctured neighborhood of `x` (ie. `U ∪ {x}` is a neighbourhood of `x`),
2. `U` is disjoint from `s`.
-/
lemma disjoint_nhds_within_of_mem_discrete {s : set α} [discrete_topology s] {x : α} (hx : x ∈ s) :
∃ U ∈ 𝓝[{x}ᶜ] x, disjoint U s :=
let ⟨V, h, h'⟩ := nhds_inter_eq_singleton_of_mem_discrete hx in
⟨{x}ᶜ ∩ V, inter_mem_nhds_within _ h,
(disjoint_iff_inter_eq_empty.mpr (by { rw [inter_assoc, h', compl_inter_self] }))⟩
/-- A T₂ space, also known as a Hausdorff space, is one in which for every
`x ≠ y` there exists disjoint open sets around `x` and `y`. This is
the most widely used of the separation axioms. -/
class t2_space (α : Type u) [topological_space α] : Prop :=
(t2 : ∀x y, x ≠ y → ∃u v : set α, is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅)
lemma t2_separation [t2_space α] {x y : α} (h : x ≠ y) :
∃u v : set α, is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅ :=
t2_space.t2 x y h
@[priority 100] -- see Note [lower instance priority]
instance t2_space.t1_space [t2_space α] : t1_space α :=
⟨λ x, is_open_iff_forall_mem_open.2 $ λ y hxy,
let ⟨u, v, hu, hv, hyu, hxv, huv⟩ := t2_separation (mt mem_singleton_of_eq hxy) in
⟨u, λ z hz1 hz2, (ext_iff.1 huv x).1 ⟨mem_singleton_iff.1 hz2 ▸ hz1, hxv⟩, hu, hyu⟩⟩
lemma eq_of_nhds_ne_bot [ht : t2_space α] {x y : α} (h : ne_bot (𝓝 x ⊓ 𝓝 y)) : x = y :=
classical.by_contradiction $ assume : x ≠ y,
let ⟨u, v, hu, hv, hx, hy, huv⟩ := t2_space.t2 x y this in
absurd huv $ (inf_ne_bot_iff.1 h (mem_nhds_sets hu hx) (mem_nhds_sets hv hy)).ne_empty
lemma t2_iff_nhds : t2_space α ↔ ∀ {x y : α}, ne_bot (𝓝 x ⊓ 𝓝 y) → x = y :=
⟨assume h, by exactI λ x y, eq_of_nhds_ne_bot,
assume h, ⟨assume x y xy,
have 𝓝 x ⊓ 𝓝 y = ⊥ := classical.by_contradiction (mt h xy),
let ⟨u', hu', v', hv', u'v'⟩ := empty_in_sets_eq_bot.mpr this,
⟨u, uu', uo, hu⟩ := mem_nhds_sets_iff.mp hu',
⟨v, vv', vo, hv⟩ := mem_nhds_sets_iff.mp hv' in
⟨u, v, uo, vo, hu, hv, disjoint.eq_bot $ disjoint.mono uu' vv' u'v'⟩⟩⟩
lemma t2_iff_ultrafilter :
t2_space α ↔ ∀ {x y : α} (f : ultrafilter α), ↑f ≤ 𝓝 x → ↑f ≤ 𝓝 y → x = y :=
t2_iff_nhds.trans $ by simp only [←exists_ultrafilter_iff, and_imp, le_inf_iff, exists_imp_distrib]
lemma is_closed_diagonal [t2_space α] : is_closed (diagonal α) :=
is_closed_iff_cluster_pt.mpr $ assume ⟨a₁, a₂⟩ h, eq_of_nhds_ne_bot $ assume : 𝓝 a₁ ⊓ 𝓝 a₂ = ⊥, h $
let ⟨t₁, ht₁, t₂, ht₂, (h' : t₁ ∩ t₂ ⊆ ∅)⟩ :=
by rw [←empty_in_sets_eq_bot, mem_inf_sets] at this; exact this in
begin
change t₁ ∈ 𝓝 a₁ at ht₁,
change t₂ ∈ 𝓝 a₂ at ht₂,
rw [nhds_prod_eq, ←empty_in_sets_eq_bot],
apply filter.sets_of_superset,
apply inter_mem_inf_sets (prod_mem_prod ht₁ ht₂) (mem_principal_sets.mpr (subset.refl _)),
exact assume ⟨x₁, x₂⟩ ⟨⟨hx₁, hx₂⟩, (heq : x₁ = x₂)⟩,
show false, from @h' x₁ ⟨hx₁, heq.symm ▸ hx₂⟩
end
lemma t2_iff_is_closed_diagonal : t2_space α ↔ is_closed (diagonal α) :=
begin
split,
{ introI h,
exact is_closed_diagonal },
{ intro h,
constructor,
intros x y hxy,
have : (x, y) ∈ (diagonal α)ᶜ, by rwa [mem_compl_iff],
obtain ⟨t, t_sub, t_op, xyt⟩ : ∃ t ⊆ (diagonal α)ᶜ, is_open t ∧ (x, y) ∈ t :=
is_open_iff_forall_mem_open.mp h _ this,
rcases is_open_prod_iff.mp t_op x y xyt with ⟨U, V, U_op, V_op, xU, yV, H⟩,
use [U, V, U_op, V_op, xU, yV],
have := subset.trans H t_sub,
rw eq_empty_iff_forall_not_mem,
rintros z ⟨zU, zV⟩,
have : ¬ (z, z) ∈ diagonal α := this (mk_mem_prod zU zV),
exact this rfl },
end
section separated
open separated finset
lemma finset_disjoint_finset_opens_of_t2 [t2_space α] :
∀ (s t : finset α), disjoint s t → separated (s : set α) t :=
begin
refine induction_on_union _ (λ a b hi d, (hi d.symm).symm) (λ a d, empty_right a) (λ a b ab, _) _,
{ obtain ⟨U, V, oU, oV, aU, bV, UV⟩ := t2_separation
(by { rw [ne.def, ← finset.mem_singleton], exact (disjoint_singleton.mp ab.symm) }),
refine ⟨U, V, oU, oV, _, _, set.disjoint_iff_inter_eq_empty.mpr UV⟩;
exact singleton_subset_set_iff.mpr ‹_› },
{ intros a b c ac bc d,
apply_mod_cast union_left (ac (disjoint_of_subset_left (a.subset_union_left b) d)) (bc _),
exact disjoint_of_subset_left (a.subset_union_right b) d },
end
lemma point_disjoint_finset_opens_of_t2 [t2_space α] {x : α} {s : finset α} (h : x ∉ s) :
separated ({x} : set α) ↑s :=
by exact_mod_cast finset_disjoint_finset_opens_of_t2 {x} s (singleton_disjoint.mpr h)
end separated
@[simp] lemma nhds_eq_nhds_iff {a b : α} [t2_space α] : 𝓝 a = 𝓝 b ↔ a = b :=
⟨assume h, eq_of_nhds_ne_bot $ by rw [h, inf_idem]; exact nhds_ne_bot, assume h, h ▸ rfl⟩
@[simp] lemma nhds_le_nhds_iff {a b : α} [t2_space α] : 𝓝 a ≤ 𝓝 b ↔ a = b :=
⟨assume h, eq_of_nhds_ne_bot $ by rw [inf_of_le_left h]; exact nhds_ne_bot, assume h, h ▸ le_refl _⟩
lemma tendsto_nhds_unique [t2_space α] {f : β → α} {l : filter β} {a b : α}
[ne_bot l] (ha : tendsto f l (𝓝 a)) (hb : tendsto f l (𝓝 b)) : a = b :=
eq_of_nhds_ne_bot $ ne_bot_of_le $ le_inf ha hb
lemma tendsto_nhds_unique' [t2_space α] {f : β → α} {l : filter β} {a b : α}
(hl : ne_bot l) (ha : tendsto f l (𝓝 a)) (hb : tendsto f l (𝓝 b)) : a = b :=
eq_of_nhds_ne_bot $ ne_bot_of_le $ le_inf ha hb
section lim
variables [t2_space α] {f : filter α}
/-!
### Properties of `Lim` and `lim`
In this section we use explicit `nonempty α` instances for `Lim` and `lim`. This way the lemmas
are useful without a `nonempty α` instance.
-/
lemma Lim_eq {a : α} [ne_bot f] (h : f ≤ 𝓝 a) :
@Lim _ _ ⟨a⟩ f = a :=
tendsto_nhds_unique (le_nhds_Lim ⟨a, h⟩) h
lemma Lim_eq_iff [ne_bot f] (h : ∃ (a : α), f ≤ nhds a) {a} : @Lim _ _ ⟨a⟩ f = a ↔ f ≤ 𝓝 a :=
⟨λ c, c ▸ le_nhds_Lim h, Lim_eq⟩
lemma ultrafilter.Lim_eq_iff_le_nhds [compact_space α] {x : α} {F : ultrafilter α} :
F.Lim = x ↔ ↑F ≤ 𝓝 x :=
⟨λ h, h ▸ F.le_nhds_Lim, Lim_eq⟩
lemma is_open_iff_ultrafilter' [compact_space α] (U : set α) :
is_open U ↔ (∀ F : ultrafilter α, F.Lim ∈ U → U ∈ F.1) :=
begin
rw is_open_iff_ultrafilter,
refine ⟨λ h F hF, h F.Lim hF F F.le_nhds_Lim, _⟩,
intros cond x hx f h,
rw [← (ultrafilter.Lim_eq_iff_le_nhds.2 h)] at hx,
exact cond _ hx
end
lemma filter.tendsto.lim_eq {a : α} {f : filter β} [ne_bot f] {g : β → α} (h : tendsto g f (𝓝 a)) :
@lim _ _ _ ⟨a⟩ f g = a :=
Lim_eq h
lemma filter.lim_eq_iff {f : filter β} [ne_bot f] {g : β → α} (h : ∃ a, tendsto g f (𝓝 a)) {a} :
@lim _ _ _ ⟨a⟩ f g = a ↔ tendsto g f (𝓝 a) :=
⟨λ c, c ▸ tendsto_nhds_lim h, filter.tendsto.lim_eq⟩
lemma continuous.lim_eq [topological_space β] {f : β → α} (h : continuous f) (a : β) :
@lim _ _ _ ⟨f a⟩ (𝓝 a) f = f a :=
(h.tendsto a).lim_eq
@[simp] lemma Lim_nhds (a : α) : @Lim _ _ ⟨a⟩ (𝓝 a) = a :=
Lim_eq (le_refl _)
@[simp] lemma lim_nhds_id (a : α) : @lim _ _ _ ⟨a⟩ (𝓝 a) id = a :=
Lim_nhds a
@[simp] lemma Lim_nhds_within {a : α} {s : set α} (h : a ∈ closure s) :
@Lim _ _ ⟨a⟩ (𝓝[s] a) = a :=
by haveI : ne_bot (𝓝[s] a) := mem_closure_iff_cluster_pt.1 h;
exact Lim_eq inf_le_left
@[simp] lemma lim_nhds_within_id {a : α} {s : set α} (h : a ∈ closure s) :
@lim _ _ _ ⟨a⟩ (𝓝[s] a) id = a :=
Lim_nhds_within h
end lim
/-!
### Instances of `t2_space` typeclass
We use two lemmas to prove that various standard constructions generate Hausdorff spaces from
Hausdorff spaces:
* `separated_by_continuous` says that two points `x y : α` can be separated by open neighborhoods
provided that there exists a continuous map `f`: α → β` with a Hausdorff codomain such that
`f x ≠ f y`. We use this lemma to prove that topological spaces defined using `induced` are
Hausdorff spaces.
* `separated_by_open_embedding` says that for an open embedding `f : α → β` of a Hausdorff space
`α`, the images of two distinct points `x y : α`, `x ≠ y` can be separated by open neighborhoods.
We use this lemma to prove that topological spaces defined using `coinduced` are Hausdorff spaces.
-/
@[priority 100] -- see Note [lower instance priority]
instance t2_space_discrete {α : Type*} [topological_space α] [discrete_topology α] : t2_space α :=
{ t2 := assume x y hxy, ⟨{x}, {y}, is_open_discrete _, is_open_discrete _, rfl, rfl,
eq_empty_iff_forall_not_mem.2 $ by intros z hz;
cases eq_of_mem_singleton hz.1; cases eq_of_mem_singleton hz.2; cc⟩ }
lemma separated_by_continuous {α : Type*} {β : Type*}
[topological_space α] [topological_space β] [t2_space β]
{f : α → β} (hf : continuous f) {x y : α} (h : f x ≠ f y) :
∃u v : set α, is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅ :=
let ⟨u, v, uo, vo, xu, yv, uv⟩ := t2_separation h in
⟨f ⁻¹' u, f ⁻¹' v, uo.preimage hf, vo.preimage hf, xu, yv,
by rw [←preimage_inter, uv, preimage_empty]⟩
lemma separated_by_open_embedding {α β : Type*} [topological_space α] [topological_space β]
[t2_space α] {f : α → β} (hf : open_embedding f) {x y : α} (h : x ≠ y) :
∃ u v : set β, is_open u ∧ is_open v ∧ f x ∈ u ∧ f y ∈ v ∧ u ∩ v = ∅ :=
let ⟨u, v, uo, vo, xu, yv, uv⟩ := t2_separation h in
⟨f '' u, f '' v, hf.is_open_map _ uo, hf.is_open_map _ vo,
mem_image_of_mem _ xu, mem_image_of_mem _ yv, by rw [image_inter hf.inj, uv, image_empty]⟩
instance {α : Type*} {p : α → Prop} [t : topological_space α] [t2_space α] : t2_space (subtype p) :=
⟨assume x y h, separated_by_continuous continuous_subtype_val (mt subtype.eq h)⟩
instance {α : Type*} {β : Type*} [t₁ : topological_space α] [t2_space α]
[t₂ : topological_space β] [t2_space β] : t2_space (α × β) :=
⟨assume ⟨x₁,x₂⟩ ⟨y₁,y₂⟩ h,
or.elim (not_and_distrib.mp (mt prod.ext_iff.mpr h))
(λ h₁, separated_by_continuous continuous_fst h₁)
(λ h₂, separated_by_continuous continuous_snd h₂)⟩
instance {α : Type*} {β : Type*} [t₁ : topological_space α] [t2_space α]
[t₂ : topological_space β] [t2_space β] : t2_space (α ⊕ β) :=
begin
constructor,
rintros (x|x) (y|y) h,
{ replace h : x ≠ y := λ c, (c.subst h) rfl,
exact separated_by_open_embedding open_embedding_inl h },
{ exact ⟨_, _, is_open_range_inl, is_open_range_inr, ⟨x, rfl⟩, ⟨y, rfl⟩,
range_inl_inter_range_inr⟩ },
{ exact ⟨_, _, is_open_range_inr, is_open_range_inl, ⟨x, rfl⟩, ⟨y, rfl⟩,
range_inr_inter_range_inl⟩ },
{ replace h : x ≠ y := λ c, (c.subst h) rfl,
exact separated_by_open_embedding open_embedding_inr h }
end
instance Pi.t2_space {α : Type*} {β : α → Type v} [t₂ : Πa, topological_space (β a)]
[∀a, t2_space (β a)] :
t2_space (Πa, β a) :=
⟨assume x y h,
let ⟨i, hi⟩ := not_forall.mp (mt funext h) in
separated_by_continuous (continuous_apply i) hi⟩
instance sigma.t2_space {ι : Type*} {α : ι → Type*} [Πi, topological_space (α i)]
[∀a, t2_space (α a)] :
t2_space (Σi, α i) :=
begin
constructor,
rintros ⟨i, x⟩ ⟨j, y⟩ neq,
rcases em (i = j) with (rfl|h),
{ replace neq : x ≠ y := λ c, (c.subst neq) rfl,
exact separated_by_open_embedding open_embedding_sigma_mk neq },
{ exact ⟨_, _, is_open_range_sigma_mk, is_open_range_sigma_mk, ⟨x, rfl⟩, ⟨y, rfl⟩, by tidy⟩ }
end
variables [topological_space β]
lemma is_closed_eq [t2_space α] {f g : β → α}
(hf : continuous f) (hg : continuous g) : is_closed {x:β | f x = g x} :=
continuous_iff_is_closed.mp (hf.prod_mk hg) _ is_closed_diagonal
/-- If two continuous maps are equal on `s`, then they are equal on the closure of `s`. -/
lemma set.eq_on.closure [t2_space α] {s : set β} {f g : β → α} (h : eq_on f g s)
(hf : continuous f) (hg : continuous g) :
eq_on f g (closure s) :=
closure_minimal h (is_closed_eq hf hg)
/-- If two continuous functions are equal on a dense set, then they are equal. -/
lemma continuous.ext_on [t2_space α] {s : set β} (hs : dense s) {f g : β → α}
(hf : continuous f) (hg : continuous g) (h : eq_on f g s) :
f = g :=
funext $ λ x, h.closure hf hg (hs x)
lemma diagonal_eq_range_diagonal_map {α : Type*} : {p:α×α | p.1 = p.2} = range (λx, (x,x)) :=
ext $ assume p, iff.intro
(assume h, ⟨p.1, prod.ext_iff.2 ⟨rfl, h⟩⟩)
(assume ⟨x, hx⟩, show p.1 = p.2, by rw ←hx)
lemma prod_subset_compl_diagonal_iff_disjoint {α : Type*} {s t : set α} :
set.prod s t ⊆ {p:α×α | p.1 = p.2}ᶜ ↔ s ∩ t = ∅ :=
by rw [eq_empty_iff_forall_not_mem, subset_compl_comm,
diagonal_eq_range_diagonal_map, range_subset_iff]; simp
lemma compact_compact_separated [t2_space α] {s t : set α}
(hs : is_compact s) (ht : is_compact t) (hst : s ∩ t = ∅) :
∃u v : set α, is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ u ∩ v = ∅ :=
by simp only [prod_subset_compl_diagonal_iff_disjoint.symm] at ⊢ hst;
exact generalized_tube_lemma hs ht is_closed_diagonal hst
/-- In a `t2_space`, every compact set is closed. -/
lemma is_compact.is_closed [t2_space α] {s : set α} (hs : is_compact s) : is_closed s :=
is_open_compl_iff.mpr $ is_open_iff_forall_mem_open.mpr $ assume x hx,
let ⟨u, v, uo, vo, su, xv, uv⟩ :=
compact_compact_separated hs (compact_singleton : is_compact {x})
(by rwa [inter_comm, ←subset_compl_iff_disjoint, singleton_subset_iff]) in
have v ⊆ sᶜ, from
subset_compl_comm.mp (subset.trans su (subset_compl_iff_disjoint.mpr uv)),
⟨v, this, vo, by simpa using xv⟩
lemma is_compact.inter [t2_space α] {s t : set α} (hs : is_compact s) (ht : is_compact t) :
is_compact (s ∩ t) :=
hs.inter_right $ ht.is_closed
/-- If a compact set is covered by two open sets, then we can cover it by two compact subsets. -/
lemma is_compact.binary_compact_cover [t2_space α] {K U V : set α} (hK : is_compact K)
(hU : is_open U) (hV : is_open V) (h2K : K ⊆ U ∪ V) :
∃ K₁ K₂ : set α, is_compact K₁ ∧ is_compact K₂ ∧ K₁ ⊆ U ∧ K₂ ⊆ V ∧ K = K₁ ∪ K₂ :=
begin
rcases compact_compact_separated (compact_diff hK hU) (compact_diff hK hV)
(by rwa [diff_inter_diff, diff_eq_empty]) with ⟨O₁, O₂, h1O₁, h1O₂, h2O₁, h2O₂, hO⟩,
refine ⟨_, _, compact_diff hK h1O₁, compact_diff hK h1O₂,
by rwa [diff_subset_comm], by rwa [diff_subset_comm], by rw [← diff_inter, hO, diff_empty]⟩
end
section
open finset function
/-- For every finite open cover `Uᵢ` of a compact set, there exists a compact cover `Kᵢ ⊆ Uᵢ`. -/
lemma is_compact.finite_compact_cover [t2_space α] {s : set α} (hs : is_compact s)
{ι} (t : finset ι) (U : ι → set α) (hU : ∀ i ∈ t, is_open (U i)) (hsC : s ⊆ ⋃ i ∈ t, U i) :
∃ K : ι → set α, (∀ i, is_compact (K i)) ∧ (∀i, K i ⊆ U i) ∧ s = ⋃ i ∈ t, K i :=
begin
classical,
induction t using finset.induction with x t hx ih generalizing U hU s hs hsC,
{ refine ⟨λ _, ∅, λ i, compact_empty, λ i, empty_subset _, _⟩, simpa only [subset_empty_iff,
finset.not_mem_empty, Union_neg, Union_empty, not_false_iff] using hsC },
simp only [finset.bUnion_insert] at hsC,
simp only [finset.mem_insert] at hU,
have hU' : ∀ i ∈ t, is_open (U i) := λ i hi, hU i (or.inr hi),
rcases hs.binary_compact_cover (hU x (or.inl rfl)) (is_open_bUnion hU') hsC
with ⟨K₁, K₂, h1K₁, h1K₂, h2K₁, h2K₂, hK⟩,
rcases ih U hU' h1K₂ h2K₂ with ⟨K, h1K, h2K, h3K⟩,
refine ⟨update K x K₁, _, _, _⟩,
{ intros i, by_cases hi : i = x,
{ simp only [update_same, hi, h1K₁] },
{ rw [← ne.def] at hi, simp only [update_noteq hi, h1K] }},
{ intros i, by_cases hi : i = x,
{ simp only [update_same, hi, h2K₁] },
{ rw [← ne.def] at hi, simp only [update_noteq hi, h2K] }},
{ simp only [bUnion_insert_update _ hx, hK, h3K] }
end
end
lemma locally_compact_of_compact_nhds [t2_space α] (h : ∀ x : α, ∃ s, s ∈ 𝓝 x ∧ is_compact s) :
locally_compact_space α :=
⟨assume x n hn,
let ⟨u, un, uo, xu⟩ := mem_nhds_sets_iff.mp hn in
let ⟨k, kx, kc⟩ := h x in
-- K is compact but not necessarily contained in N.
-- K \ U is again compact and doesn't contain x, so
-- we may find open sets V, W separating x from K \ U.
-- Then K \ W is a compact neighborhood of x contained in U.
let ⟨v, w, vo, wo, xv, kuw, vw⟩ :=
compact_compact_separated compact_singleton (compact_diff kc uo)
(by rw [singleton_inter_eq_empty]; exact λ h, h.2 xu) in
have wn : wᶜ ∈ 𝓝 x, from
mem_nhds_sets_iff.mpr
⟨v, subset_compl_iff_disjoint.mpr vw, vo, singleton_subset_iff.mp xv⟩,
⟨k \ w,
filter.inter_mem_sets kx wn,
subset.trans (diff_subset_comm.mp kuw) un,
compact_diff kc wo⟩⟩
@[priority 100] -- see Note [lower instance priority]
instance locally_compact_of_compact [t2_space α] [compact_space α] : locally_compact_space α :=
locally_compact_of_compact_nhds (assume x, ⟨univ, mem_nhds_sets is_open_univ trivial, compact_univ⟩)
/-- In a locally compact T₂ space, every point has an open neighborhood with compact closure -/
lemma exists_open_with_compact_closure [locally_compact_space α] [t2_space α] (x : α) :
∃ (U : set α), is_open U ∧ x ∈ U ∧ is_compact (closure U) :=
begin
rcases locally_compact_space.local_compact_nhds x univ filter.univ_mem_sets with
⟨K, h1K, _, h2K⟩,
rw [mem_nhds_sets_iff] at h1K, rcases h1K with ⟨t, h1t, h2t, h3t⟩,
exact ⟨t, h2t, h3t, compact_of_is_closed_subset h2K is_closed_closure $
closure_minimal h1t $ h2K.is_closed⟩
end
/-- In a locally compact T₂ space, every compact set is contained in the interior of a compact
set. -/
lemma exists_compact_superset [locally_compact_space α] [t2_space α] {K : set α}
(hK : is_compact K) : ∃ (K' : set α), is_compact K' ∧ K ⊆ interior K' :=
begin
choose U hU using λ x : K, exists_open_with_compact_closure (x : α),
rcases hK.elim_finite_subcover U (λ x, (hU x).1) (λ x hx, ⟨_, ⟨⟨x, hx⟩, rfl⟩, (hU ⟨x, hx⟩).2.1⟩)
with ⟨s, hs⟩,
refine ⟨⋃ (i : K) (H : i ∈ s), closure (U i), _, _⟩,
exact (finite_mem_finset s).compact_bUnion (λ x hx, (hU x).2.2),
refine subset.trans hs _, rw subset_interior_iff_subset_of_open,
exact bUnion_subset_bUnion_right (λ x hx, subset_closure),
exact is_open_bUnion (λ x hx, (hU x).1)
end
end separation
section regularity
/-- A T₃ space, also known as a regular space (although this condition sometimes
omits T₂), is one in which for every closed `C` and `x ∉ C`, there exist
disjoint open sets containing `x` and `C` respectively. -/
class regular_space (α : Type u) [topological_space α] extends t1_space α : Prop :=
(regular : ∀{s:set α} {a}, is_closed s → a ∉ s → ∃t, is_open t ∧ s ⊆ t ∧ 𝓝[t] a = ⊥)
lemma nhds_is_closed [regular_space α] {a : α} {s : set α} (h : s ∈ 𝓝 a) :
∃t∈(𝓝 a), t ⊆ s ∧ is_closed t :=
let ⟨s', h₁, h₂, h₃⟩ := mem_nhds_sets_iff.mp h in
have ∃t, is_open t ∧ s'ᶜ ⊆ t ∧ 𝓝[t] a = ⊥,
from regular_space.regular (is_closed_compl_iff.mpr h₂) (not_not_intro h₃),
let ⟨t, ht₁, ht₂, ht₃⟩ := this in
⟨tᶜ,
mem_sets_of_eq_bot $ by rwa [compl_compl],
subset.trans (compl_subset_comm.1 ht₂) h₁,
is_closed_compl_iff.mpr ht₁⟩
lemma closed_nhds_basis [regular_space α] (a : α) :
(𝓝 a).has_basis (λ s : set α, s ∈ 𝓝 a ∧ is_closed s) id :=
⟨λ t, ⟨λ t_in, let ⟨s, s_in, h_st, h⟩ := nhds_is_closed t_in in ⟨s, ⟨s_in, h⟩, h_st⟩,
λ ⟨s, ⟨s_in, hs⟩, hst⟩, mem_sets_of_superset s_in hst⟩⟩
instance subtype.regular_space [regular_space α] {p : α → Prop} : regular_space (subtype p) :=
⟨begin
intros s a hs ha,
rcases is_closed_induced_iff.1 hs with ⟨s, hs', rfl⟩,
rcases regular_space.regular hs' ha with ⟨t, ht, hst, hat⟩,
refine ⟨coe ⁻¹' t, is_open_induced ht, preimage_mono hst, _⟩,
rw [nhds_within, nhds_induced, ← comap_principal, ← comap_inf, ← nhds_within, hat, comap_bot]
end⟩
variable (α)
@[priority 100] -- see Note [lower instance priority]
instance regular_space.t2_space [regular_space α] : t2_space α :=
⟨λ x y hxy,
let ⟨s, hs, hys, hxs⟩ := regular_space.regular is_closed_singleton
(mt mem_singleton_iff.1 hxy),
⟨t, hxt, u, hsu, htu⟩ := empty_in_sets_eq_bot.2 hxs,
⟨v, hvt, hv, hxv⟩ := mem_nhds_sets_iff.1 hxt in
⟨v, s, hv, hs, hxv, singleton_subset_iff.1 hys,
eq_empty_of_subset_empty $ λ z ⟨hzv, hzs⟩, htu ⟨hvt hzv, hsu hzs⟩⟩⟩
variable {α}
lemma disjoint_nested_nhds [regular_space α] {x y : α} (h : x ≠ y) :
∃ (U₁ V₁ ∈ 𝓝 x) (U₂ V₂ ∈ 𝓝 y), is_closed V₁ ∧ is_closed V₂ ∧ is_open U₁ ∧ is_open U₂ ∧
V₁ ⊆ U₁ ∧ V₂ ⊆ U₂ ∧ U₁ ∩ U₂ = ∅ :=
begin
rcases t2_separation h with ⟨U₁, U₂, U₁_op, U₂_op, x_in, y_in, H⟩,
rcases nhds_is_closed (mem_nhds_sets U₁_op x_in) with ⟨V₁, V₁_in, h₁, V₁_closed⟩,
rcases nhds_is_closed (mem_nhds_sets U₂_op y_in) with ⟨V₂, V₂_in, h₂, V₂_closed⟩,
use [U₁, V₁, mem_sets_of_superset V₁_in h₁, V₁_in,
U₂, V₂, mem_sets_of_superset V₂_in h₂, V₂_in],
tauto
end
end regularity
section normality
/-- A T₄ space, also known as a normal space (although this condition sometimes
omits T₂), is one in which for every pair of disjoint closed sets `C` and `D`,
there exist disjoint open sets containing `C` and `D` respectively. -/
class normal_space (α : Type u) [topological_space α] extends t1_space α : Prop :=
(normal : ∀ s t : set α, is_closed s → is_closed t → disjoint s t →
∃ u v, is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ disjoint u v)
theorem normal_separation [normal_space α] (s t : set α)
(H1 : is_closed s) (H2 : is_closed t) (H3 : disjoint s t) :
∃ u v, is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ disjoint u v :=
normal_space.normal s t H1 H2 H3
@[priority 100] -- see Note [lower instance priority]
instance normal_space.regular_space [normal_space α] : regular_space α :=
{ regular := λ s x hs hxs, let ⟨u, v, hu, hv, hsu, hxv, huv⟩ :=
normal_separation s {x} hs is_closed_singleton
(λ _ ⟨hx, hy⟩, hxs $ mem_of_eq_of_mem (eq_of_mem_singleton hy).symm hx) in
⟨u, hu, hsu, filter.empty_in_sets_eq_bot.1 $ filter.mem_inf_sets.2
⟨v, mem_nhds_sets hv (singleton_subset_iff.1 hxv), u, filter.mem_principal_self u,
inter_comm u v ▸ huv⟩⟩ }
-- We can't make this an instance because it could cause an instance loop.
lemma normal_of_compact_t2 [compact_space α] [t2_space α] : normal_space α :=
begin
refine ⟨assume s t hs ht st, _⟩,
simp only [disjoint_iff],
exact compact_compact_separated hs.compact ht.compact st.eq_bot
end
end normality
/-- In a compact t2 space, the connected component of a point equals the intersection of all
its clopen neighbourhoods. -/
lemma connected_component_eq_Inter_clopen [t2_space α] [compact_space α] {x : α} :
connected_component x = ⋂ Z : {Z : set α // is_clopen Z ∧ x ∈ Z}, Z :=
begin
apply eq_of_subset_of_subset connected_component_subset_Inter_clopen,
-- Reduce to showing that the clopen intersection is connected.
refine subset_connected_component _ (mem_Inter.2 (λ Z, Z.2.2)),
-- We do this by showing that any disjoint cover by two closed sets implies
-- that one of these closed sets must contain our whole thing. To reduce to the case
-- where the cover is disjoint on all of α we need that s is closed:
have hs : @is_closed _ _inst_1 (⋂ (Z : {Z : set α // is_clopen Z ∧ x ∈ Z}), ↑Z),
{ exact is_closed_Inter (λ Z, Z.2.1.2) },
apply (is_preconnected_iff_subset_of_fully_disjoint_closed hs).2,
intros a b ha hb hab ab_empty,
haveI := @normal_of_compact_t2 α _ _ _,
-- Since our space is normal, we get two larger disjoint open sets containing the disjoint
-- closed sets. If we can show that our intersection is a subset of any of these we can then
-- "descend" this to show that it is a subset of either a or b.
rcases normal_separation a b ha hb (disjoint_iff.2 ab_empty) with ⟨u, v, hu, hv, hau, hbv, huv⟩,
-- If we can find a clopen set around x, contained in u ∪ v, we get a disjoint decomposition
-- Z = Z ∩ u ∪ Z ∩ v of clopen sets. The intersection of all clopen neighbourhoods will then lie
-- in whatever component x lies in and hence will be a subset of either u or v.
suffices : ∃ (Z : set α), is_clopen Z ∧ x ∈ Z ∧ Z ⊆ u ∪ v,
{ cases this with Z H,
rw [disjoint_iff_inter_eq_empty] at huv,
have H1 := is_clopen_inter_of_disjoint_cover_clopen H.1 H.2.2 hu hv huv,
rw [union_comm] at H,
rw [inter_comm] at huv,
have H2 := is_clopen_inter_of_disjoint_cover_clopen H.1 H.2.2 hv hu huv,
by_cases (x ∈ u),
-- The x ∈ u case.
{ left,
suffices : (⋂ (Z : {Z : set α // is_clopen Z ∧ x ∈ Z}), ↑Z) ⊆ u,
{ rw [inter_comm, ←set.disjoint_iff_inter_eq_empty] at huv,
replace hab : (⋂ (Z : {Z // is_clopen Z ∧ x ∈ Z}), ↑Z) ≤ a ∪ b := hab,
replace this : (⋂ (Z : {Z // is_clopen Z ∧ x ∈ Z}), ↑Z) ≤ u := this,
exact disjoint.left_le_of_le_sup_right hab (huv.mono this hbv) },
{ apply subset.trans _ (inter_subset_right Z u),
apply Inter_subset (λ Z : {Z : set α // is_clopen Z ∧ x ∈ Z}, ↑Z)
⟨Z ∩ u, by {split, exact H1, apply mem_inter H.2.1 h}⟩ } },
-- If x ∉ u, we get x ∈ v since x ∈ u ∪ v. The rest is then like the x ∈ u case.
have h1 : x ∈ v,
{ cases (mem_union x u v).1 (mem_of_subset_of_mem (subset.trans hab
(union_subset_union hau hbv)) (mem_Inter.2 (λ i, i.2.2))) with h1 h1,
{ exfalso, apply h, exact h1},
{ exact h1} },
right,
suffices : (⋂ (Z : {Z : set α // is_clopen Z ∧ x ∈ Z}), ↑Z) ⊆ v,
{ rw [←set.disjoint_iff_inter_eq_empty] at huv,
replace hab : (⋂ (Z : {Z // is_clopen Z ∧ x ∈ Z}), ↑Z) ≤ a ∪ b := hab,
replace this : (⋂ (Z : {Z // is_clopen Z ∧ x ∈ Z}), ↑Z) ≤ v := this,
exact disjoint.left_le_of_le_sup_left hab (huv.mono this hau) },
{ apply subset.trans _ (inter_subset_right Z v),
apply Inter_subset (λ Z : {Z : set α // is_clopen Z ∧ x ∈ Z}, ↑Z)
⟨Z ∩ v, by {split, exact H2, apply mem_inter H.2.1 h1}⟩ } },
-- Now we find the required Z. We utilize the fact that X \ u ∪ v will be compact,
-- so there must be some finite intersection of clopen neighbourhoods of X disjoint to it,
-- but a finite intersection of clopen sets is clopen so we let this be our Z.
have H1 := (is_compact.inter_Inter_nonempty (is_closed.compact
(is_closed_compl_iff.2 (is_open_union hu hv)))
(λ Z : {Z : set α // is_clopen Z ∧ x ∈ Z}, Z) (λ Z, Z.2.1.2)),
rw [←not_imp_not, not_forall, not_nonempty_iff_eq_empty, inter_comm] at H1,
have huv_union := subset.trans hab (union_subset_union hau hbv),
rw [← compl_compl (u ∪ v), subset_compl_iff_disjoint] at huv_union,
cases H1 huv_union with Zi H2,
refine ⟨(⋂ (U ∈ Zi), subtype.val U), _, _, _⟩,
{ exact is_clopen_bInter (λ Z hZ, Z.2.1) },
{ exact mem_bInter_iff.2 (λ Z hZ, Z.2.2) },
{ rwa [not_nonempty_iff_eq_empty, inter_comm, ←subset_compl_iff_disjoint, compl_compl] at H2 }
end
|
5eaf5cfb619b9d940c825cf3b2643521edc556b6 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/measure_theory/constructions/borel_space/basic.lean | 95c59b3ffd372ba0c966a720ad84672fcea3db3f | [
"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 | 83,398 | 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, Yury Kudryashov
-/
import analysis.normed.group.basic
import measure_theory.function.ae_measurable_sequence
import measure_theory.group.arithmetic
import measure_theory.lattice
import measure_theory.measure.open_pos
import topology.algebra.order.liminf_limsup
import topology.continuous_function.basic
import topology.instances.ereal
import topology.metric_space.hausdorff_distance
import topology.G_delta
import topology.order.lattice
import topology.semicontinuous
/-!
# Borel (measurable) space
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
## Main definitions
* `borel α` : the least `σ`-algebra that contains all open sets;
* `class borel_space` : a space with `topological_space` and `measurable_space` structures
such that `‹measurable_space α› = borel α`;
* `class opens_measurable_space` : a space with `topological_space` and `measurable_space`
structures such that all open sets are measurable; equivalently, `borel α ≤ ‹measurable_space α›`.
* `borel_space` instances on `empty`, `unit`, `bool`, `nat`, `int`, `rat`;
* `measurable` and `borel_space` instances on `ℝ`, `ℝ≥0`, `ℝ≥0∞`.
## Main statements
* `is_open.measurable_set`, `is_closed.measurable_set`: open and closed sets are measurable;
* `continuous.measurable` : a continuous function is measurable;
* `continuous.measurable2` : if `f : α → β` and `g : α → γ` are measurable and `op : β × γ → δ`
is continuous, then `λ x, op (f x, g y)` is measurable;
* `measurable.add` etc : dot notation for arithmetic operations on `measurable` predicates,
and similarly for `dist` and `edist`;
* `ae_measurable.add` : similar dot notation for almost everywhere measurable functions;
* `measurable.ennreal*` : special cases for arithmetic operations on `ℝ≥0∞`.
-/
noncomputable theory
open classical set filter measure_theory
open_locale classical big_operators topology nnreal ennreal measure_theory
universes u v w x y
variables {α β γ γ₂ δ : Type*} {ι : Sort y} {s t u : set α}
open measurable_space topological_space
/-- `measurable_space` structure generated by `topological_space`. -/
def borel (α : Type u) [topological_space α] : measurable_space α :=
generate_from {s : set α | is_open s}
theorem borel_anti : antitone (@borel α) :=
λ _ _ h, measurable_space.generate_from_le $ λ s hs, generate_measurable.basic _ (h _ hs)
lemma borel_eq_top_of_discrete [topological_space α] [discrete_topology α] :
borel α = ⊤ :=
top_le_iff.1 $ λ s hs, generate_measurable.basic s (is_open_discrete s)
lemma borel_eq_top_of_countable [topological_space α] [t1_space α] [countable α] :
borel α = ⊤ :=
begin
refine (top_le_iff.1 $ λ s hs, bUnion_of_singleton s ▸ _),
apply measurable_set.bUnion s.to_countable,
intros x hx,
apply measurable_set.of_compl,
apply generate_measurable.basic,
exact is_closed_singleton.is_open_compl
end
lemma borel_eq_generate_from_of_subbasis {s : set (set α)}
[t : topological_space α] [second_countable_topology α] (hs : t = generate_from s) :
borel α = generate_from s :=
le_antisymm
(generate_from_le $ assume u (hu : t.is_open u),
begin
rw [hs] at hu,
induction hu,
case generate_open.basic : u hu
{ exact generate_measurable.basic u hu },
case generate_open.univ
{ exact @measurable_set.univ α (generate_from s) },
case generate_open.inter : s₁ s₂ _ _ hs₁ hs₂
{ exact @measurable_set.inter α (generate_from s) _ _ hs₁ hs₂ },
case generate_open.sUnion : f hf ih
{ rcases is_open_sUnion_countable f (by rwa hs) with ⟨v, hv, vf, vu⟩,
rw ← vu,
exact @measurable_set.sUnion α (generate_from s) _ hv
(λ x xv, ih _ (vf xv)) }
end)
(generate_from_le $ assume u hu, generate_measurable.basic _ $
show t.is_open u, by rw [hs]; exact generate_open.basic _ hu)
lemma topological_space.is_topological_basis.borel_eq_generate_from [topological_space α]
[second_countable_topology α] {s : set (set α)} (hs : is_topological_basis s) :
borel α = generate_from s :=
borel_eq_generate_from_of_subbasis hs.eq_generate_from
lemma is_pi_system_is_open [topological_space α] : is_pi_system (is_open : set α → Prop) :=
λ s hs t ht hst, is_open.inter hs ht
lemma borel_eq_generate_from_is_closed [topological_space α] :
borel α = generate_from {s | is_closed s} :=
le_antisymm
(generate_from_le $ λ t ht, @measurable_set.of_compl α _ (generate_from {s | is_closed s})
(generate_measurable.basic _ $ is_closed_compl_iff.2 ht))
(generate_from_le $ λ t ht, @measurable_set.of_compl α _ (borel α)
(generate_measurable.basic _ $ is_open_compl_iff.2 ht))
section order_topology
variable (α)
variables [topological_space α] [second_countable_topology α] [linear_order α] [order_topology α]
lemma borel_eq_generate_from_Iio : borel α = generate_from (range Iio) :=
begin
refine le_antisymm _ (generate_from_le _),
{ rw borel_eq_generate_from_of_subbasis (@order_topology.topology_eq_generate_intervals α _ _ _),
letI : measurable_space α := measurable_space.generate_from (range Iio),
have H : ∀ a : α, measurable_set (Iio a) := λ a, generate_measurable.basic _ ⟨_, rfl⟩,
refine generate_from_le _, rintro _ ⟨a, rfl | rfl⟩; [skip, apply H],
by_cases h : ∃ a', ∀ b, a < b ↔ a' ≤ b,
{ rcases h with ⟨a', ha'⟩,
rw (_ : Ioi a = (Iio a')ᶜ), { exact (H _).compl },
simp [set.ext_iff, ha'] },
{ rcases is_open_Union_countable
(λ a' : {a' : α // a < a'}, {b | a'.1 < b})
(λ a', is_open_lt' _) with ⟨v, ⟨hv⟩, vu⟩,
simp [set.ext_iff] at vu,
have : Ioi a = ⋃ x : v, (Iio x.1.1)ᶜ,
{ simp [set.ext_iff],
refine λ x, ⟨λ ax, _, λ ⟨a', ⟨h, av⟩, ax⟩, lt_of_lt_of_le h ax⟩,
rcases (vu x).2 _ with ⟨a', h₁, h₂⟩,
{ exact ⟨a', h₁, le_of_lt h₂⟩ },
refine not_imp_comm.1 (λ h, _) h,
exact ⟨x, λ b, ⟨λ ab, le_of_not_lt (λ h', h ⟨b, ab, h'⟩),
lt_of_lt_of_le ax⟩⟩ },
rw this, resetI,
apply measurable_set.Union,
exact λ _, (H _).compl } },
{ rw forall_range_iff,
intro a,
exact generate_measurable.basic _ is_open_Iio }
end
lemma borel_eq_generate_from_Ioi : borel α = generate_from (range Ioi) :=
@borel_eq_generate_from_Iio αᵒᵈ _ (by apply_instance : second_countable_topology α) _ _
lemma borel_eq_generate_from_Iic : borel α = measurable_space.generate_from (range Iic) :=
begin
rw borel_eq_generate_from_Ioi,
refine le_antisymm _ _,
{ refine measurable_space.generate_from_le (λ t ht, _),
obtain ⟨u, rfl⟩ := ht,
rw ← compl_Iic,
exact (measurable_space.measurable_set_generate_from (mem_range.mpr ⟨u, rfl⟩)).compl, },
{ refine measurable_space.generate_from_le (λ t ht, _),
obtain ⟨u, rfl⟩ := ht,
rw ← compl_Ioi,
exact (measurable_space.measurable_set_generate_from (mem_range.mpr ⟨u, rfl⟩)).compl, },
end
lemma borel_eq_generate_from_Ici : borel α = measurable_space.generate_from (range Ici) :=
@borel_eq_generate_from_Iic αᵒᵈ _ _ _ _
end order_topology
lemma borel_comap {f : α → β} {t : topological_space β} :
@borel α (t.induced f) = (@borel β t).comap f :=
comap_generate_from.symm
lemma continuous.borel_measurable [topological_space α] [topological_space β]
{f : α → β} (hf : continuous f) :
@measurable α β (borel α) (borel β) f :=
measurable.of_le_map $ generate_from_le $
λ s hs, generate_measurable.basic (f ⁻¹' s) (hs.preimage hf)
/-- A space with `measurable_space` and `topological_space` structures such that
all open sets are measurable. -/
class opens_measurable_space (α : Type*) [topological_space α] [h : measurable_space α] : Prop :=
(borel_le : borel α ≤ h)
/-- A space with `measurable_space` and `topological_space` structures such that
the `σ`-algebra of measurable sets is exactly the `σ`-algebra generated by open sets. -/
class borel_space (α : Type*) [topological_space α] [measurable_space α] : Prop :=
(measurable_eq : ‹measurable_space α› = borel α)
namespace tactic
/-- Add instances `borel α : measurable_space α` and `⟨rfl⟩ : borel_space α`. -/
meta def add_borel_instance (α : expr) : tactic unit :=
do
n1 ← get_unused_name "_inst",
to_expr ``(borel %%α) >>= pose n1,
reset_instance_cache,
n2 ← get_unused_name "_inst",
v ← to_expr ``(borel_space.mk rfl : borel_space %%α),
note n2 none v,
reset_instance_cache
/-- Given a type `α`, an assumption `i : measurable_space α`, and an instance `[borel_space α]`,
replace `i` with `borel α`. -/
meta def borel_to_refl (α i : expr) : tactic unit :=
do
n ← get_unused_name "h",
to_expr ``(%%i = borel %%α) >>= assert n,
applyc `borel_space.measurable_eq,
unfreezing (tactic.subst i),
n1 ← get_unused_name "_inst",
to_expr ``(borel %%α) >>= pose n1,
reset_instance_cache
/-- Given a type `α`, if there is an assumption `[i : measurable_space α]`, then try to prove
`[borel_space α]` and replace `i` with `borel α`. Otherwise, add instances
`borel α : measurable_space α` and `⟨rfl⟩ : borel_space α`. -/
meta def borelize (α : expr) : tactic unit :=
do
i ← optional (to_expr ``(measurable_space %%α) >>= find_assumption),
i.elim (add_borel_instance α) (borel_to_refl α)
namespace interactive
setup_tactic_parser
/-- The behaviour of `borelize α` depends on the existing assumptions on `α`.
- if `α` is a topological space with instances `[measurable_space α] [borel_space α]`, then
`borelize α` replaces the former instance by `borel α`;
- otherwise, `borelize α` adds instances `borel α : measurable_space α` and `⟨rfl⟩ : borel_space α`.
Finally, `borelize [α, β, γ]` runs `borelize α, borelize β, borelize γ`.
-/
meta def borelize (ts : parse pexpr_list_or_texpr) : tactic unit :=
mmap' (λ t, to_expr t >>= tactic.borelize) ts
add_tactic_doc
{ name := "borelize",
category := doc_category.tactic,
decl_names := [`tactic.interactive.borelize],
tags := ["type class"] }
end interactive
end tactic
@[priority 100]
instance order_dual.opens_measurable_space {α : Type*} [topological_space α] [measurable_space α]
[h : opens_measurable_space α] :
opens_measurable_space αᵒᵈ :=
{ borel_le := h.borel_le }
@[priority 100]
instance order_dual.borel_space {α : Type*} [topological_space α] [measurable_space α]
[h : borel_space α] :
borel_space αᵒᵈ :=
{ measurable_eq := h.measurable_eq }
/-- In a `borel_space` all open sets are measurable. -/
@[priority 100]
instance borel_space.opens_measurable {α : Type*} [topological_space α] [measurable_space α]
[borel_space α] : opens_measurable_space α :=
⟨ge_of_eq $ borel_space.measurable_eq⟩
instance subtype.borel_space {α : Type*} [topological_space α] [measurable_space α]
[hα : borel_space α] (s : set α) :
borel_space s :=
⟨by { rw [hα.1, subtype.measurable_space, ← borel_comap], refl }⟩
instance subtype.opens_measurable_space {α : Type*} [topological_space α] [measurable_space α]
[h : opens_measurable_space α] (s : set α) :
opens_measurable_space s :=
⟨by { rw [borel_comap], exact comap_mono h.1 }⟩
@[priority 100]
instance borel_space.countably_generated {α : Type*} [topological_space α] [measurable_space α]
[borel_space α] [second_countable_topology α] : countably_generated α :=
begin
obtain ⟨b, bct, -, hb⟩ := exists_countable_basis α,
refine ⟨⟨b, bct, _⟩⟩,
borelize α,
exact hb.borel_eq_generate_from,
end
theorem _root_.measurable_set.induction_on_open [topological_space α] [measurable_space α]
[borel_space α] {C : set α → Prop} (h_open : ∀ U, is_open U → C U)
(h_compl : ∀ t, measurable_set t → C t → C tᶜ)
(h_union : ∀ f : ℕ → set α, pairwise (disjoint on f) →
(∀ i, measurable_set (f i)) → (∀ i, C (f i)) → C (⋃ i, f i)) :
∀ ⦃t⦄, measurable_set t → C t :=
measurable_space.induction_on_inter borel_space.measurable_eq is_pi_system_is_open
(h_open _ is_open_empty) h_open h_compl h_union
section
variables [topological_space α] [measurable_space α] [opens_measurable_space α]
[topological_space β] [measurable_space β] [opens_measurable_space β]
[topological_space γ] [measurable_space γ] [borel_space γ]
[topological_space γ₂] [measurable_space γ₂] [borel_space γ₂]
[measurable_space δ]
lemma is_open.measurable_set (h : is_open s) : measurable_set s :=
opens_measurable_space.borel_le _ $ generate_measurable.basic _ h
@[measurability]
lemma measurable_set_interior : measurable_set (interior s) := is_open_interior.measurable_set
lemma is_Gδ.measurable_set (h : is_Gδ s) : measurable_set s :=
begin
rcases h with ⟨S, hSo, hSc, rfl⟩,
exact measurable_set.sInter hSc (λ t ht, (hSo t ht).measurable_set)
end
lemma measurable_set_of_continuous_at {β} [emetric_space β] (f : α → β) :
measurable_set {x | continuous_at f x} :=
(is_Gδ_set_of_continuous_at f).measurable_set
lemma is_closed.measurable_set (h : is_closed s) : measurable_set s :=
h.is_open_compl.measurable_set.of_compl
lemma is_compact.measurable_set [t2_space α] (h : is_compact s) : measurable_set s :=
h.is_closed.measurable_set
@[measurability]
lemma measurable_set_closure : measurable_set (closure s) :=
is_closed_closure.measurable_set
lemma measurable_of_is_open {f : δ → γ} (hf : ∀ s, is_open s → measurable_set (f ⁻¹' s)) :
measurable f :=
by { rw [‹borel_space γ›.measurable_eq], exact measurable_generate_from hf }
lemma measurable_of_is_closed {f : δ → γ} (hf : ∀ s, is_closed s → measurable_set (f ⁻¹' s)) :
measurable f :=
begin
apply measurable_of_is_open, intros s hs,
rw [← measurable_set.compl_iff, ← preimage_compl], apply hf, rw [is_closed_compl_iff], exact hs
end
lemma measurable_of_is_closed' {f : δ → γ}
(hf : ∀ s, is_closed s → s.nonempty → s ≠ univ → measurable_set (f ⁻¹' s)) : measurable f :=
begin
apply measurable_of_is_closed, intros s hs,
cases eq_empty_or_nonempty s with h1 h1, { simp [h1] },
by_cases h2 : s = univ, { simp [h2] },
exact hf s hs h1 h2
end
instance nhds_is_measurably_generated (a : α) : (𝓝 a).is_measurably_generated :=
begin
rw [nhds, infi_subtype'],
refine @filter.infi_is_measurably_generated _ _ _ _ (λ i, _),
exact i.2.2.measurable_set.principal_is_measurably_generated
end
/-- If `s` is a measurable set, then `𝓝[s] a` is a measurably generated filter for
each `a`. This cannot be an `instance` because it depends on a non-instance `hs : measurable_set s`.
-/
lemma measurable_set.nhds_within_is_measurably_generated {s : set α} (hs : measurable_set s)
(a : α) :
(𝓝[s] a).is_measurably_generated :=
by haveI := hs.principal_is_measurably_generated; exact filter.inf_is_measurably_generated _ _
@[priority 100] -- see Note [lower instance priority]
instance opens_measurable_space.to_measurable_singleton_class [t1_space α] :
measurable_singleton_class α :=
⟨λ x, is_closed_singleton.measurable_set⟩
instance pi.opens_measurable_space {ι : Type*} {π : ι → Type*} [countable ι]
[t' : Π i, topological_space (π i)]
[Π i, measurable_space (π i)] [∀ i, second_countable_topology (π i)]
[∀ i, opens_measurable_space (π i)] :
opens_measurable_space (Π i, π i) :=
begin
constructor,
have : Pi.topological_space =
generate_from {t | ∃(s:Πa, set (π a)) (i : finset ι), (∀a∈i, s a ∈ countable_basis (π a)) ∧
t = pi ↑i s},
{ rw [funext (λ a, @eq_generate_from_countable_basis (π a) _ _), pi_generate_from_eq] },
rw [borel_eq_generate_from_of_subbasis this],
apply generate_from_le,
rintros _ ⟨s, i, hi, rfl⟩,
refine measurable_set.pi i.countable_to_set (λ a ha, is_open.measurable_set _),
rw [eq_generate_from_countable_basis (π a)],
exact generate_open.basic _ (hi a ha)
end
instance prod.opens_measurable_space [second_countable_topology α] [second_countable_topology β] :
opens_measurable_space (α × β) :=
begin
constructor,
rw [((is_basis_countable_basis α).prod (is_basis_countable_basis β)).borel_eq_generate_from],
apply generate_from_le,
rintros _ ⟨u, v, hu, hv, rfl⟩,
exact (is_open_of_mem_countable_basis hu).measurable_set.prod
(is_open_of_mem_countable_basis hv).measurable_set
end
variables {α' : Type*} [topological_space α'] [measurable_space α']
lemma interior_ae_eq_of_null_frontier {μ : measure α'} {s : set α'}
(h : μ (frontier s) = 0) : interior s =ᵐ[μ] s :=
interior_subset.eventually_le.antisymm $
subset_closure.eventually_le.trans (ae_le_set.2 h)
lemma measure_interior_of_null_frontier {μ : measure α'} {s : set α'}
(h : μ (frontier s) = 0) : μ (interior s) = μ s :=
measure_congr (interior_ae_eq_of_null_frontier h)
lemma null_measurable_set_of_null_frontier {s : set α} {μ : measure α}
(h : μ (frontier s) = 0) : null_measurable_set s μ :=
⟨interior s, is_open_interior.measurable_set, (interior_ae_eq_of_null_frontier h).symm⟩
lemma closure_ae_eq_of_null_frontier {μ : measure α'} {s : set α'}
(h : μ (frontier s) = 0) : closure s =ᵐ[μ] s :=
((ae_le_set.2 h).trans interior_subset.eventually_le).antisymm $ subset_closure.eventually_le
lemma measure_closure_of_null_frontier {μ : measure α'} {s : set α'}
(h : μ (frontier s) = 0) : μ (closure s) = μ s :=
measure_congr (closure_ae_eq_of_null_frontier h)
section preorder
variables [preorder α] [order_closed_topology α] {a b x : α}
@[simp, measurability]
lemma measurable_set_Ici : measurable_set (Ici a) := is_closed_Ici.measurable_set
@[simp, measurability]
lemma measurable_set_Iic : measurable_set (Iic a) := is_closed_Iic.measurable_set
@[simp, measurability]
lemma measurable_set_Icc : measurable_set (Icc a b) := is_closed_Icc.measurable_set
instance nhds_within_Ici_is_measurably_generated :
(𝓝[Ici b] a).is_measurably_generated :=
measurable_set_Ici.nhds_within_is_measurably_generated _
instance nhds_within_Iic_is_measurably_generated :
(𝓝[Iic b] a).is_measurably_generated :=
measurable_set_Iic.nhds_within_is_measurably_generated _
instance nhds_within_Icc_is_measurably_generated :
is_measurably_generated (𝓝[Icc a b] x) :=
by { rw [← Ici_inter_Iic, nhds_within_inter], apply_instance }
instance at_top_is_measurably_generated : (filter.at_top : filter α).is_measurably_generated :=
@filter.infi_is_measurably_generated _ _ _ _ $
λ a, (measurable_set_Ici : measurable_set (Ici a)).principal_is_measurably_generated
instance at_bot_is_measurably_generated : (filter.at_bot : filter α).is_measurably_generated :=
@filter.infi_is_measurably_generated _ _ _ _ $
λ a, (measurable_set_Iic : measurable_set (Iic a)).principal_is_measurably_generated
end preorder
section partial_order
variables [partial_order α] [order_closed_topology α] [second_countable_topology α]
{a b : α}
@[measurability]
lemma measurable_set_le' : measurable_set {p : α × α | p.1 ≤ p.2} :=
order_closed_topology.is_closed_le'.measurable_set
@[measurability]
lemma measurable_set_le {f g : δ → α} (hf : measurable f) (hg : measurable g) :
measurable_set {a | f a ≤ g a} :=
hf.prod_mk hg measurable_set_le'
end partial_order
section linear_order
variables [linear_order α] [order_closed_topology α] {a b x : α}
-- we open this locale only here to avoid issues with list being treated as intervals above
open_locale interval
@[simp, measurability]
lemma measurable_set_Iio : measurable_set (Iio a) := is_open_Iio.measurable_set
@[simp, measurability]
lemma measurable_set_Ioi : measurable_set (Ioi a) := is_open_Ioi.measurable_set
@[simp, measurability]
lemma measurable_set_Ioo : measurable_set (Ioo a b) := is_open_Ioo.measurable_set
@[simp, measurability] lemma measurable_set_Ioc : measurable_set (Ioc a b) :=
measurable_set_Ioi.inter measurable_set_Iic
@[simp, measurability] lemma measurable_set_Ico : measurable_set (Ico a b) :=
measurable_set_Ici.inter measurable_set_Iio
instance nhds_within_Ioi_is_measurably_generated :
(𝓝[Ioi b] a).is_measurably_generated :=
measurable_set_Ioi.nhds_within_is_measurably_generated _
instance nhds_within_Iio_is_measurably_generated :
(𝓝[Iio b] a).is_measurably_generated :=
measurable_set_Iio.nhds_within_is_measurably_generated _
instance nhds_within_uIcc_is_measurably_generated :
is_measurably_generated (𝓝[[a, b]] x) :=
nhds_within_Icc_is_measurably_generated
@[measurability]
lemma measurable_set_lt' [second_countable_topology α] : measurable_set {p : α × α | p.1 < p.2} :=
(is_open_lt continuous_fst continuous_snd).measurable_set
@[measurability]
lemma measurable_set_lt [second_countable_topology α] {f g : δ → α} (hf : measurable f)
(hg : measurable g) : measurable_set {a | f a < g a} :=
hf.prod_mk hg measurable_set_lt'
lemma null_measurable_set_lt [second_countable_topology α] {μ : measure δ} {f g : δ → α}
(hf : ae_measurable f μ) (hg : ae_measurable g μ) :
null_measurable_set {a | f a < g a} μ :=
(hf.prod_mk hg).null_measurable measurable_set_lt'
lemma set.ord_connected.measurable_set (h : ord_connected s) : measurable_set s :=
begin
let u := ⋃ (x ∈ s) (y ∈ s), Ioo x y,
have huopen : is_open u := is_open_bUnion (λ x hx, is_open_bUnion (λ y hy, is_open_Ioo)),
have humeas : measurable_set u := huopen.measurable_set,
have hfinite : (s \ u).finite := s.finite_diff_Union_Ioo,
have : u ⊆ s :=
Union₂_subset (λ x hx, Union₂_subset (λ y hy, Ioo_subset_Icc_self.trans (h.out hx hy))),
rw ← union_diff_cancel this,
exact humeas.union hfinite.measurable_set
end
lemma is_preconnected.measurable_set
(h : is_preconnected s) : measurable_set s :=
h.ord_connected.measurable_set
lemma generate_from_Ico_mem_le_borel {α : Type*} [topological_space α] [linear_order α]
[order_closed_topology α] (s t : set α) :
measurable_space.generate_from {S | ∃ (l ∈ s) (u ∈ t) (h : l < u), Ico l u = S} ≤ borel α :=
begin
apply generate_from_le,
borelize α,
rintro _ ⟨a, -, b, -, -, rfl⟩,
exact measurable_set_Ico
end
lemma dense.borel_eq_generate_from_Ico_mem_aux {α : Type*} [topological_space α] [linear_order α]
[order_topology α] [second_countable_topology α] {s : set α} (hd : dense s)
(hbot : ∀ x, is_bot x → x ∈ s) (hIoo : ∀ x y : α, x < y → Ioo x y = ∅ → y ∈ s) :
borel α = generate_from {S : set α | ∃ (l ∈ s) (u ∈ s) (h : l < u), Ico l u = S} :=
begin
set S : set (set α) := {S | ∃ (l ∈ s) (u ∈ s) (h : l < u), Ico l u = S},
refine le_antisymm _ (generate_from_Ico_mem_le_borel _ _),
letI : measurable_space α := generate_from S,
rw borel_eq_generate_from_Iio,
refine generate_from_le (forall_range_iff.2 $ λ a, _),
rcases hd.exists_countable_dense_subset_bot_top with ⟨t, hts, hc, htd, htb, htt⟩,
by_cases ha : ∀ b < a, (Ioo b a).nonempty,
{ convert_to measurable_set (⋃ (l ∈ t) (u ∈ t) (hlu : l < u) (hu : u ≤ a), Ico l u),
{ ext y, simp only [mem_Union, mem_Iio, mem_Ico], split,
{ intro hy,
rcases htd.exists_le' (λ b hb, htb _ hb (hbot b hb)) y with ⟨l, hlt, hly⟩,
rcases htd.exists_mem_open is_open_Ioo (ha y hy) with ⟨u, hut, hyu, hua⟩,
exact ⟨l, hlt, u, hut, hly.trans_lt hyu, hua.le, hly, hyu⟩ },
{ rintro ⟨l, -, u, -, -, hua, -, hyu⟩,
exact hyu.trans_le hua } },
{ refine measurable_set.bUnion hc (λ a ha, measurable_set.bUnion hc $ λ b hb, _),
refine measurable_set.Union (λ hab, measurable_set.Union $ λ hb', _),
exact generate_measurable.basic _ ⟨a, hts ha, b, hts hb, hab, mem_singleton _⟩ } },
{ simp only [not_forall, not_nonempty_iff_eq_empty] at ha,
replace ha : a ∈ s := hIoo ha.some a ha.some_spec.fst ha.some_spec.snd,
convert_to measurable_set (⋃ (l ∈ t) (hl : l < a), Ico l a),
{ symmetry,
simp only [← Ici_inter_Iio, ← Union_inter, inter_eq_right_iff_subset, subset_def, mem_Union,
mem_Ici, mem_Iio],
intros x hx, rcases htd.exists_le' (λ b hb, htb _ hb (hbot b hb)) x with ⟨z, hzt, hzx⟩,
exact ⟨z, hzt, hzx.trans_lt hx, hzx⟩ },
{ refine measurable_set.bUnion hc (λ x hx, measurable_set.Union $ λ hlt, _),
exact generate_measurable.basic _ ⟨x, hts hx, a, ha, hlt, mem_singleton _⟩ } }
end
lemma dense.borel_eq_generate_from_Ico_mem {α : Type*} [topological_space α] [linear_order α]
[order_topology α] [second_countable_topology α] [densely_ordered α] [no_min_order α]
{s : set α} (hd : dense s) :
borel α = generate_from {S : set α | ∃ (l ∈ s) (u ∈ s) (h : l < u), Ico l u = S} :=
hd.borel_eq_generate_from_Ico_mem_aux (by simp) $
λ x y hxy H, ((nonempty_Ioo.2 hxy).ne_empty H).elim
lemma borel_eq_generate_from_Ico (α : Type*) [topological_space α]
[second_countable_topology α] [linear_order α] [order_topology α] :
borel α = generate_from {S : set α | ∃ l u (h : l < u), Ico l u = S} :=
by simpa only [exists_prop, mem_univ, true_and]
using (@dense_univ α _).borel_eq_generate_from_Ico_mem_aux (λ _ _, mem_univ _)
(λ _ _ _ _, mem_univ _)
lemma dense.borel_eq_generate_from_Ioc_mem_aux {α : Type*} [topological_space α] [linear_order α]
[order_topology α] [second_countable_topology α] {s : set α} (hd : dense s)
(hbot : ∀ x, is_top x → x ∈ s) (hIoo : ∀ x y : α, x < y → Ioo x y = ∅ → x ∈ s) :
borel α = generate_from {S : set α | ∃ (l ∈ s) (u ∈ s) (h : l < u), Ioc l u = S} :=
begin
convert hd.order_dual.borel_eq_generate_from_Ico_mem_aux hbot (λ x y hlt he, hIoo y x hlt _),
{ ext s,
split; rintro ⟨l, hl, u, hu, hlt, rfl⟩,
exacts [⟨u, hu, l, hl, hlt, dual_Ico⟩, ⟨u, hu, l, hl, hlt, dual_Ioc⟩] },
{ erw dual_Ioo,
exact he }
end
lemma dense.borel_eq_generate_from_Ioc_mem {α : Type*} [topological_space α] [linear_order α]
[order_topology α] [second_countable_topology α] [densely_ordered α] [no_max_order α]
{s : set α} (hd : dense s) :
borel α = generate_from {S : set α | ∃ (l ∈ s) (u ∈ s) (h : l < u), Ioc l u = S} :=
hd.borel_eq_generate_from_Ioc_mem_aux (by simp) $
λ x y hxy H, ((nonempty_Ioo.2 hxy).ne_empty H).elim
lemma borel_eq_generate_from_Ioc (α : Type*) [topological_space α]
[second_countable_topology α] [linear_order α] [order_topology α] :
borel α = generate_from {S : set α | ∃ l u (h : l < u), Ioc l u = S} :=
by simpa only [exists_prop, mem_univ, true_and]
using (@dense_univ α _).borel_eq_generate_from_Ioc_mem_aux (λ _ _, mem_univ _)
(λ _ _ _ _, mem_univ _)
namespace measure_theory.measure
/-- Two finite measures on a Borel space are equal if they agree on all closed-open intervals. If
`α` is a conditionally complete linear order with no top element,
`measure_theory.measure..ext_of_Ico` is an extensionality lemma with weaker assumptions on `μ` and
`ν`. -/
lemma ext_of_Ico_finite {α : Type*} [topological_space α] {m : measurable_space α}
[second_countable_topology α] [linear_order α] [order_topology α]
[borel_space α] (μ ν : measure α) [is_finite_measure μ] (hμν : μ univ = ν univ)
(h : ∀ ⦃a b⦄, a < b → μ (Ico a b) = ν (Ico a b)) : μ = ν :=
begin
refine ext_of_generate_finite _
(borel_space.measurable_eq.trans (borel_eq_generate_from_Ico α))
(is_pi_system_Ico (id : α → α) id) _ hμν,
{ rintro - ⟨a, b, hlt, rfl⟩,
exact h hlt }
end
/-- Two finite measures on a Borel space are equal if they agree on all open-closed intervals. If
`α` is a conditionally complete linear order with no top element,
`measure_theory.measure..ext_of_Ioc` is an extensionality lemma with weaker assumptions on `μ` and
`ν`. -/
lemma ext_of_Ioc_finite {α : Type*} [topological_space α] {m : measurable_space α}
[second_countable_topology α] [linear_order α] [order_topology α]
[borel_space α] (μ ν : measure α) [is_finite_measure μ] (hμν : μ univ = ν univ)
(h : ∀ ⦃a b⦄, a < b → μ (Ioc a b) = ν (Ioc a b)) : μ = ν :=
begin
refine @ext_of_Ico_finite αᵒᵈ _ _ _ _ _ ‹_› μ ν _ hμν (λ a b hab, _),
erw dual_Ico,
exact h hab
end
/-- Two measures which are finite on closed-open intervals are equal if the agree on all
closed-open intervals. -/
lemma ext_of_Ico' {α : Type*} [topological_space α] {m : measurable_space α}
[second_countable_topology α] [linear_order α] [order_topology α] [borel_space α]
[no_max_order α] (μ ν : measure α) (hμ : ∀ ⦃a b⦄, a < b → μ (Ico a b) ≠ ∞)
(h : ∀ ⦃a b⦄, a < b → μ (Ico a b) = ν (Ico a b)) : μ = ν :=
begin
rcases exists_countable_dense_bot_top α with ⟨s, hsc, hsd, hsb, hst⟩,
have : (⋃ (l ∈ s) (u ∈ s) (h : l < u), {Ico l u} : set (set α)).countable,
from hsc.bUnion (λ l hl, hsc.bUnion
(λ u hu, countable_Union $ λ _, countable_singleton _)),
simp only [← set_of_eq_eq_singleton, ← set_of_exists] at this,
refine measure.ext_of_generate_from_of_cover_subset
(borel_space.measurable_eq.trans (borel_eq_generate_from_Ico α))
(is_pi_system_Ico id id) _ this _ _ _,
{ rintro _ ⟨l, -, u, -, h, rfl⟩, exact ⟨l, u, h, rfl⟩ },
{ refine sUnion_eq_univ_iff.2 (λ x, _),
rcases hsd.exists_le' hsb x with ⟨l, hls, hlx⟩,
rcases hsd.exists_gt x with ⟨u, hus, hxu⟩,
exact ⟨_, ⟨l, hls, u, hus, hlx.trans_lt hxu, rfl⟩, hlx, hxu⟩ },
{ rintro _ ⟨l, -, u, -, hlt, rfl⟩, exact hμ hlt },
{ rintro _ ⟨l, u, hlt, rfl⟩, exact h hlt }
end
/-- Two measures which are finite on closed-open intervals are equal if the agree on all
open-closed intervals. -/
lemma ext_of_Ioc' {α : Type*} [topological_space α] {m : measurable_space α}
[second_countable_topology α] [linear_order α] [order_topology α] [borel_space α]
[no_min_order α] (μ ν : measure α) (hμ : ∀ ⦃a b⦄, a < b → μ (Ioc a b) ≠ ∞)
(h : ∀ ⦃a b⦄, a < b → μ (Ioc a b) = ν (Ioc a b)) : μ = ν :=
begin
refine @ext_of_Ico' αᵒᵈ _ _ _ _ _ ‹_› _ μ ν _ _;
intros a b hab; erw dual_Ico,
exacts [hμ hab, h hab]
end
/-- Two measures which are finite on closed-open intervals are equal if the agree on all
closed-open intervals. -/
lemma ext_of_Ico {α : Type*} [topological_space α] {m : measurable_space α}
[second_countable_topology α] [conditionally_complete_linear_order α] [order_topology α]
[borel_space α] [no_max_order α] (μ ν : measure α) [is_locally_finite_measure μ]
(h : ∀ ⦃a b⦄, a < b → μ (Ico a b) = ν (Ico a b)) : μ = ν :=
μ.ext_of_Ico' ν (λ a b hab, measure_Ico_lt_top.ne) h
/-- Two measures which are finite on closed-open intervals are equal if the agree on all
open-closed intervals. -/
lemma ext_of_Ioc {α : Type*} [topological_space α] {m : measurable_space α}
[second_countable_topology α] [conditionally_complete_linear_order α] [order_topology α]
[borel_space α] [no_min_order α] (μ ν : measure α) [is_locally_finite_measure μ]
(h : ∀ ⦃a b⦄, a < b → μ (Ioc a b) = ν (Ioc a b)) : μ = ν :=
μ.ext_of_Ioc' ν (λ a b hab, measure_Ioc_lt_top.ne) h
/-- Two finite measures on a Borel space are equal if they agree on all left-infinite right-closed
intervals. -/
lemma ext_of_Iic {α : Type*} [topological_space α] {m : measurable_space α}
[second_countable_topology α] [linear_order α] [order_topology α] [borel_space α]
(μ ν : measure α) [is_finite_measure μ] (h : ∀ a, μ (Iic a) = ν (Iic a)) : μ = ν :=
begin
refine ext_of_Ioc_finite μ ν _ (λ a b hlt, _),
{ rcases exists_countable_dense_bot_top α with ⟨s, hsc, hsd, -, hst⟩,
have : directed_on (≤) s, from directed_on_iff_directed.2 (directed_of_sup $ λ _ _, id),
simp only [← bsupr_measure_Iic hsc (hsd.exists_ge' hst) this, h] },
rw [← Iic_diff_Iic, measure_diff (Iic_subset_Iic.2 hlt.le) measurable_set_Iic,
measure_diff (Iic_subset_Iic.2 hlt.le) measurable_set_Iic, h a, h b],
{ rw ← h a, exact (measure_lt_top μ _).ne },
{ exact (measure_lt_top μ _).ne }
end
/-- Two finite measures on a Borel space are equal if they agree on all left-closed right-infinite
intervals. -/
lemma ext_of_Ici {α : Type*} [topological_space α] {m : measurable_space α}
[second_countable_topology α] [linear_order α] [order_topology α] [borel_space α]
(μ ν : measure α) [is_finite_measure μ] (h : ∀ a, μ (Ici a) = ν (Ici a)) : μ = ν :=
@ext_of_Iic αᵒᵈ _ _ _ _ _ ‹_› _ _ _ h
end measure_theory.measure
end linear_order
section linear_order
variables [linear_order α] [order_closed_topology α] {a b : α}
@[measurability] lemma measurable_set_uIcc : measurable_set (uIcc a b) := measurable_set_Icc
@[measurability] lemma measurable_set_uIoc : measurable_set (uIoc a b) := measurable_set_Ioc
variables [second_countable_topology α]
@[measurability]
lemma measurable.max {f g : δ → α} (hf : measurable f) (hg : measurable g) :
measurable (λ a, max (f a) (g a)) :=
by simpa only [max_def'] using hf.piecewise (measurable_set_le hg hf) hg
@[measurability]
lemma ae_measurable.max {f g : δ → α} {μ : measure δ}
(hf : ae_measurable f μ) (hg : ae_measurable g μ) : ae_measurable (λ a, max (f a) (g a)) μ :=
⟨λ a, max (hf.mk f a) (hg.mk g a), hf.measurable_mk.max hg.measurable_mk,
eventually_eq.comp₂ hf.ae_eq_mk _ hg.ae_eq_mk⟩
@[measurability]
lemma measurable.min {f g : δ → α} (hf : measurable f) (hg : measurable g) :
measurable (λ a, min (f a) (g a)) :=
by simpa only [min_def] using hf.piecewise (measurable_set_le hf hg) hg
@[measurability]
lemma ae_measurable.min {f g : δ → α} {μ : measure δ}
(hf : ae_measurable f μ) (hg : ae_measurable g μ) : ae_measurable (λ a, min (f a) (g a)) μ :=
⟨λ a, min (hf.mk f a) (hg.mk g a), hf.measurable_mk.min hg.measurable_mk,
eventually_eq.comp₂ hf.ae_eq_mk _ hg.ae_eq_mk⟩
end linear_order
/-- A continuous function from an `opens_measurable_space` to a `borel_space`
is measurable. -/
lemma continuous.measurable {f : α → γ} (hf : continuous f) :
measurable f :=
hf.borel_measurable.mono opens_measurable_space.borel_le
(le_of_eq $ borel_space.measurable_eq)
/-- A continuous function from an `opens_measurable_space` to a `borel_space`
is ae-measurable. -/
lemma continuous.ae_measurable {f : α → γ} (h : continuous f) {μ : measure α} : ae_measurable f μ :=
h.measurable.ae_measurable
lemma closed_embedding.measurable {f : α → γ} (hf : closed_embedding f) :
measurable f :=
hf.continuous.measurable
lemma continuous.is_open_pos_measure_map {f : β → γ} (hf : continuous f)
(hf_surj : function.surjective f) {μ : measure β} [μ.is_open_pos_measure] :
(measure.map f μ).is_open_pos_measure :=
begin
refine ⟨λ U hUo hUne, _⟩,
rw [measure.map_apply hf.measurable hUo.measurable_set],
exact (hUo.preimage hf).measure_ne_zero μ (hf_surj.nonempty_preimage.mpr hUne)
end
/-- If a function is defined piecewise in terms of functions which are continuous on their
respective pieces, then it is measurable. -/
lemma continuous_on.measurable_piecewise
{f g : α → γ} {s : set α} [Π (j : α), decidable (j ∈ s)]
(hf : continuous_on f s) (hg : continuous_on g sᶜ) (hs : measurable_set s) :
measurable (s.piecewise f g) :=
begin
refine measurable_of_is_open (λ t ht, _),
rw [piecewise_preimage, set.ite],
apply measurable_set.union,
{ rcases _root_.continuous_on_iff'.1 hf t ht with ⟨u, u_open, hu⟩,
rw hu,
exact u_open.measurable_set.inter hs },
{ rcases _root_.continuous_on_iff'.1 hg t ht with ⟨u, u_open, hu⟩,
rw [diff_eq_compl_inter, inter_comm, hu],
exact u_open.measurable_set.inter hs.compl }
end
@[priority 100, to_additive]
instance has_continuous_mul.has_measurable_mul [has_mul γ] [has_continuous_mul γ] :
has_measurable_mul γ :=
{ measurable_const_mul := λ c, (continuous_const.mul continuous_id).measurable,
measurable_mul_const := λ c, (continuous_id.mul continuous_const).measurable }
@[priority 100]
instance has_continuous_sub.has_measurable_sub [has_sub γ] [has_continuous_sub γ] :
has_measurable_sub γ :=
{ measurable_const_sub := λ c, (continuous_const.sub continuous_id).measurable,
measurable_sub_const := λ c, (continuous_id.sub continuous_const).measurable }
@[priority 100, to_additive]
instance topological_group.has_measurable_inv [group γ] [topological_group γ] :
has_measurable_inv γ :=
⟨continuous_inv.measurable⟩
@[priority 100]
instance has_continuous_smul.has_measurable_smul {M α} [topological_space M]
[topological_space α] [measurable_space M] [measurable_space α]
[opens_measurable_space M] [borel_space α] [has_smul M α] [has_continuous_smul M α] :
has_measurable_smul M α :=
⟨λ c, (continuous_const_smul _).measurable,
λ y, (continuous_id.smul continuous_const).measurable⟩
section lattice
@[priority 100]
instance has_continuous_sup.has_measurable_sup [has_sup γ] [has_continuous_sup γ] :
has_measurable_sup γ :=
{ measurable_const_sup := λ c, (continuous_const.sup continuous_id).measurable,
measurable_sup_const := λ c, (continuous_id.sup continuous_const).measurable }
@[priority 100]
instance has_continuous_sup.has_measurable_sup₂ [second_countable_topology γ] [has_sup γ]
[has_continuous_sup γ] :
has_measurable_sup₂ γ :=
⟨continuous_sup.measurable⟩
@[priority 100]
instance has_continuous_inf.has_measurable_inf [has_inf γ] [has_continuous_inf γ] :
has_measurable_inf γ :=
{ measurable_const_inf := λ c, (continuous_const.inf continuous_id).measurable,
measurable_inf_const := λ c, (continuous_id.inf continuous_const).measurable }
@[priority 100]
instance has_continuous_inf.has_measurable_inf₂ [second_countable_topology γ] [has_inf γ]
[has_continuous_inf γ] :
has_measurable_inf₂ γ :=
⟨continuous_inf.measurable⟩
end lattice
section homeomorph
@[measurability] protected lemma homeomorph.measurable (h : α ≃ₜ γ) : measurable h :=
h.continuous.measurable
/-- A homeomorphism between two Borel spaces is a measurable equivalence.-/
def homeomorph.to_measurable_equiv (h : γ ≃ₜ γ₂) : γ ≃ᵐ γ₂ :=
{ measurable_to_fun := h.measurable,
measurable_inv_fun := h.symm.measurable,
to_equiv := h.to_equiv }
@[simp]
lemma homeomorph.to_measurable_equiv_coe (h : γ ≃ₜ γ₂) : (h.to_measurable_equiv : γ → γ₂) = h :=
rfl
@[simp] lemma homeomorph.to_measurable_equiv_symm_coe (h : γ ≃ₜ γ₂) :
(h.to_measurable_equiv.symm : γ₂ → γ) = h.symm :=
rfl
end homeomorph
@[measurability] lemma continuous_map.measurable (f : C(α, γ)) : measurable f :=
f.continuous.measurable
lemma measurable_of_continuous_on_compl_singleton [t1_space α] {f : α → γ} (a : α)
(hf : continuous_on f {a}ᶜ) :
measurable f :=
measurable_of_measurable_on_compl_singleton a
(continuous_on_iff_continuous_restrict.1 hf).measurable
lemma continuous.measurable2 [second_countable_topology α] [second_countable_topology β]
{f : δ → α} {g : δ → β} {c : α → β → γ}
(h : continuous (λ p : α × β, c p.1 p.2)) (hf : measurable f) (hg : measurable g) :
measurable (λ a, c (f a) (g a)) :=
h.measurable.comp (hf.prod_mk hg)
lemma continuous.ae_measurable2 [second_countable_topology α] [second_countable_topology β]
{f : δ → α} {g : δ → β} {c : α → β → γ} {μ : measure δ}
(h : continuous (λ p : α × β, c p.1 p.2)) (hf : ae_measurable f μ) (hg : ae_measurable g μ) :
ae_measurable (λ a, c (f a) (g a)) μ :=
h.measurable.comp_ae_measurable (hf.prod_mk hg)
@[priority 100]
instance has_continuous_inv₀.has_measurable_inv [group_with_zero γ] [t1_space γ]
[has_continuous_inv₀ γ] :
has_measurable_inv γ :=
⟨measurable_of_continuous_on_compl_singleton 0 continuous_on_inv₀⟩
@[priority 100, to_additive]
instance has_continuous_mul.has_measurable_mul₂ [second_countable_topology γ] [has_mul γ]
[has_continuous_mul γ] : has_measurable_mul₂ γ :=
⟨continuous_mul.measurable⟩
@[priority 100]
instance has_continuous_sub.has_measurable_sub₂ [second_countable_topology γ] [has_sub γ]
[has_continuous_sub γ] : has_measurable_sub₂ γ :=
⟨continuous_sub.measurable⟩
@[priority 100]
instance has_continuous_smul.has_measurable_smul₂ {M α} [topological_space M]
[second_countable_topology M] [measurable_space M] [opens_measurable_space M]
[topological_space α] [second_countable_topology α] [measurable_space α]
[borel_space α] [has_smul M α] [has_continuous_smul M α] :
has_measurable_smul₂ M α :=
⟨continuous_smul.measurable⟩
end
section borel_space
variables [topological_space α] [measurable_space α] [borel_space α]
[topological_space β] [measurable_space β] [borel_space β]
[topological_space γ] [measurable_space γ] [borel_space γ]
[measurable_space δ]
lemma pi_le_borel_pi {ι : Type*} {π : ι → Type*} [Π i, topological_space (π i)]
[Π i, measurable_space (π i)] [∀ i, borel_space (π i)] :
measurable_space.pi ≤ borel (Π i, π i) :=
begin
have : ‹Π i, measurable_space (π i)› = λ i, borel (π i) :=
funext (λ i, borel_space.measurable_eq),
rw [this],
exact supr_le (λ i, comap_le_iff_le_map.2 $ (continuous_apply i).borel_measurable)
end
lemma prod_le_borel_prod : prod.measurable_space ≤ borel (α × β) :=
begin
rw [‹borel_space α›.measurable_eq, ‹borel_space β›.measurable_eq],
refine sup_le _ _,
{ exact comap_le_iff_le_map.mpr continuous_fst.borel_measurable },
{ exact comap_le_iff_le_map.mpr continuous_snd.borel_measurable }
end
instance pi.borel_space {ι : Type*} {π : ι → Type*} [countable ι] [Π i, topological_space (π i)]
[Π i, measurable_space (π i)] [∀ i, second_countable_topology (π i)] [∀ i, borel_space (π i)] :
borel_space (Π i, π i) :=
⟨le_antisymm pi_le_borel_pi opens_measurable_space.borel_le⟩
instance prod.borel_space [second_countable_topology α] [second_countable_topology β] :
borel_space (α × β) :=
⟨le_antisymm prod_le_borel_prod opens_measurable_space.borel_le⟩
protected lemma embedding.measurable_embedding {f : α → β} (h₁ : embedding f)
(h₂ : measurable_set (range f)) : measurable_embedding f :=
show measurable_embedding (coe ∘ (homeomorph.of_embedding f h₁).to_measurable_equiv),
from (measurable_embedding.subtype_coe h₂).comp (measurable_equiv.measurable_embedding _)
protected lemma closed_embedding.measurable_embedding {f : α → β} (h : closed_embedding f) :
measurable_embedding f :=
h.to_embedding.measurable_embedding h.closed_range.measurable_set
protected lemma open_embedding.measurable_embedding {f : α → β} (h : open_embedding f) :
measurable_embedding f :=
h.to_embedding.measurable_embedding h.open_range.measurable_set
section linear_order
variables [linear_order α] [order_topology α] [second_countable_topology α]
lemma measurable_of_Iio {f : δ → α} (hf : ∀ x, measurable_set (f ⁻¹' Iio x)) : measurable f :=
begin
convert measurable_generate_from _,
exact borel_space.measurable_eq.trans (borel_eq_generate_from_Iio _),
rintro _ ⟨x, rfl⟩, exact hf x
end
lemma upper_semicontinuous.measurable [topological_space δ] [opens_measurable_space δ]
{f : δ → α} (hf : upper_semicontinuous f) : measurable f :=
measurable_of_Iio (λ y, (hf.is_open_preimage y).measurable_set)
lemma measurable_of_Ioi {f : δ → α} (hf : ∀ x, measurable_set (f ⁻¹' Ioi x)) : measurable f :=
begin
convert measurable_generate_from _,
exact borel_space.measurable_eq.trans (borel_eq_generate_from_Ioi _),
rintro _ ⟨x, rfl⟩, exact hf x
end
lemma lower_semicontinuous.measurable [topological_space δ] [opens_measurable_space δ]
{f : δ → α} (hf : lower_semicontinuous f) : measurable f :=
measurable_of_Ioi (λ y, (hf.is_open_preimage y).measurable_set)
lemma measurable_of_Iic {f : δ → α} (hf : ∀ x, measurable_set (f ⁻¹' Iic x)) : measurable f :=
begin
apply measurable_of_Ioi,
simp_rw [← compl_Iic, preimage_compl, measurable_set.compl_iff],
assumption
end
lemma measurable_of_Ici {f : δ → α} (hf : ∀ x, measurable_set (f ⁻¹' Ici x)) : measurable f :=
begin
apply measurable_of_Iio,
simp_rw [← compl_Ici, preimage_compl, measurable_set.compl_iff],
assumption
end
lemma measurable.is_lub {ι} [countable ι] {f : ι → δ → α} {g : δ → α} (hf : ∀ i, measurable (f i))
(hg : ∀ b, is_lub {a | ∃ i, f i b = a} (g b)) :
measurable g :=
begin
change ∀ b, is_lub (range $ λ i, f i b) (g b) at hg,
rw [‹borel_space α›.measurable_eq, borel_eq_generate_from_Ioi α],
apply measurable_generate_from,
rintro _ ⟨a, rfl⟩,
simp_rw [set.preimage, mem_Ioi, lt_is_lub_iff (hg _), exists_range_iff, set_of_exists],
exact measurable_set.Union (λ i, hf i (is_open_lt' _).measurable_set)
end
private lemma ae_measurable.is_lub_of_nonempty {ι} (hι : nonempty ι)
{μ : measure δ} [countable ι] {f : ι → δ → α} {g : δ → α}
(hf : ∀ i, ae_measurable (f i) μ) (hg : ∀ᵐ b ∂μ, is_lub {a | ∃ i, f i b = a} (g b)) :
ae_measurable g μ :=
begin
let p : δ → (ι → α) → Prop := λ x f', is_lub {a | ∃ i, f' i = a} (g x),
let g_seq := λ x, ite (x ∈ ae_seq_set hf p) (g x) (⟨g x⟩ : nonempty α).some,
have hg_seq : ∀ b, is_lub {a | ∃ i, ae_seq hf p i b = a} (g_seq b),
{ intro b,
haveI hα : nonempty α := nonempty.map g ⟨b⟩,
simp only [ae_seq, g_seq],
split_ifs,
{ have h_set_eq : {a : α | ∃ (i : ι), (hf i).mk (f i) b = a} = {a : α | ∃ (i : ι), f i b = a},
{ ext x,
simp_rw [set.mem_set_of_eq, ae_seq.mk_eq_fun_of_mem_ae_seq_set hf h], },
rw h_set_eq,
exact ae_seq.fun_prop_of_mem_ae_seq_set hf h, },
{ have h_singleton : {a : α | ∃ (i : ι), hα.some = a} = {hα.some},
{ ext1 x,
exact ⟨λ hx, hx.some_spec.symm, λ hx, ⟨hι.some, hx.symm⟩⟩, },
rw h_singleton,
exact is_lub_singleton, }, },
refine ⟨g_seq, measurable.is_lub (ae_seq.measurable hf p) hg_seq, _⟩,
exact (ite_ae_eq_of_measure_compl_zero g (λ x, (⟨g x⟩ : nonempty α).some) (ae_seq_set hf p)
(ae_seq.measure_compl_ae_seq_set_eq_zero hf hg)).symm,
end
lemma ae_measurable.is_lub {ι} {μ : measure δ} [countable ι] {f : ι → δ → α} {g : δ → α}
(hf : ∀ i, ae_measurable (f i) μ) (hg : ∀ᵐ b ∂μ, is_lub {a | ∃ i, f i b = a} (g b)) :
ae_measurable g μ :=
begin
by_cases hμ : μ = 0, { rw hμ, exact ae_measurable_zero_measure },
haveI : μ.ae.ne_bot, { simpa [ne_bot_iff] },
by_cases hι : nonempty ι, { exact ae_measurable.is_lub_of_nonempty hι hf hg, },
suffices : ∃ x, g =ᵐ[μ] λ y, g x,
by { exact ⟨(λ y, g this.some), measurable_const, this.some_spec⟩, },
have h_empty : ∀ x, {a : α | ∃ (i : ι), f i x = a} = ∅,
{ intro x,
ext1 y,
rw [set.mem_set_of_eq, set.mem_empty_iff_false, iff_false],
exact λ hi, hι (nonempty_of_exists hi), },
simp_rw h_empty at hg,
exact ⟨hg.exists.some, hg.mono (λ y hy, is_lub.unique hy hg.exists.some_spec)⟩,
end
lemma measurable.is_glb {ι} [countable ι] {f : ι → δ → α} {g : δ → α} (hf : ∀ i, measurable (f i))
(hg : ∀ b, is_glb {a | ∃ i, f i b = a} (g b)) :
measurable g :=
begin
change ∀ b, is_glb (range $ λ i, f i b) (g b) at hg,
rw [‹borel_space α›.measurable_eq, borel_eq_generate_from_Iio α],
apply measurable_generate_from,
rintro _ ⟨a, rfl⟩,
simp_rw [set.preimage, mem_Iio, is_glb_lt_iff (hg _), exists_range_iff, set_of_exists],
exact measurable_set.Union (λ i, hf i (is_open_gt' _).measurable_set)
end
lemma ae_measurable.is_glb {ι} {μ : measure δ} [countable ι] {f : ι → δ → α} {g : δ → α}
(hf : ∀ i, ae_measurable (f i) μ) (hg : ∀ᵐ b ∂μ, is_glb {a | ∃ i, f i b = a} (g b)) :
ae_measurable g μ :=
begin
nontriviality α,
haveI hα : nonempty α := infer_instance,
casesI is_empty_or_nonempty ι with hι hι,
{ simp only [is_empty.exists_iff, set_of_false, is_glb_empty_iff] at hg,
exact ae_measurable_const' (hg.mono $ λ a ha, hg.mono $ λ b hb, (hb _).antisymm (ha _)) },
let p : δ → (ι → α) → Prop := λ x f', is_glb {a | ∃ i, f' i = a} (g x),
let g_seq := (ae_seq_set hf p).piecewise g (λ _, hα.some),
have hg_seq : ∀ b, is_glb {a | ∃ i, ae_seq hf p i b = a} (g_seq b),
{ intro b,
simp only [ae_seq, g_seq, set.piecewise],
split_ifs,
{ have h_set_eq : {a : α | ∃ (i : ι), (hf i).mk (f i) b = a} = {a : α | ∃ (i : ι), f i b = a},
{ ext x,
simp_rw [set.mem_set_of_eq, ae_seq.mk_eq_fun_of_mem_ae_seq_set hf h], },
rw h_set_eq,
exact ae_seq.fun_prop_of_mem_ae_seq_set hf h, },
{ exact is_least.is_glb ⟨(@exists_const (hα.some = hα.some) ι _).2 rfl, λ x ⟨i, hi⟩, hi.le⟩ } },
refine ⟨g_seq, measurable.is_glb (ae_seq.measurable hf p) hg_seq, _⟩,
exact (ite_ae_eq_of_measure_compl_zero g (λ x, hα.some) (ae_seq_set hf p)
(ae_seq.measure_compl_ae_seq_set_eq_zero hf hg)).symm,
end
protected lemma monotone.measurable [linear_order β] [order_closed_topology β] {f : β → α}
(hf : monotone f) : measurable f :=
suffices h : ∀ x, ord_connected (f ⁻¹' Ioi x),
from measurable_of_Ioi (λ x, (h x).measurable_set),
λ x, ord_connected_def.mpr (λ a ha b hb c hc, lt_of_lt_of_le ha (hf hc.1))
lemma ae_measurable_restrict_of_monotone_on [linear_order β] [order_closed_topology β]
{μ : measure β} {s : set β} (hs : measurable_set s) {f : β → α} (hf : monotone_on f s) :
ae_measurable f (μ.restrict s) :=
have this : monotone (f ∘ coe : s → α), from λ ⟨x, hx⟩ ⟨y, hy⟩ (hxy : x ≤ y), hf hx hy hxy,
ae_measurable_restrict_of_measurable_subtype hs this.measurable
protected lemma antitone.measurable [linear_order β] [order_closed_topology β] {f : β → α}
(hf : antitone f) :
measurable f :=
@monotone.measurable αᵒᵈ β _ _ ‹_› _ _ _ _ _ ‹_› _ _ _ hf
lemma ae_measurable_restrict_of_antitone_on [linear_order β] [order_closed_topology β]
{μ : measure β} {s : set β} (hs : measurable_set s) {f : β → α} (hf : antitone_on f s) :
ae_measurable f (μ.restrict s) :=
@ae_measurable_restrict_of_monotone_on αᵒᵈ β _ _ ‹_› _ _ _ _ _ ‹_› _ _ _ _ hs _ hf
lemma measurable_set_of_mem_nhds_within_Ioi_aux
{s : set α} (h : ∀ x ∈ s, s ∈ 𝓝[>] x) (h' : ∀ x ∈ s, ∃ y, x < y) :
measurable_set s :=
begin
choose! M hM using h',
suffices H : (s \ interior s).countable,
{ have : s = interior s ∪ (s \ interior s), by rw union_diff_cancel interior_subset,
rw this,
exact is_open_interior.measurable_set.union H.measurable_set },
have A : ∀ x ∈ s, ∃ y ∈ Ioi x, Ioo x y ⊆ s :=
λ x hx, (mem_nhds_within_Ioi_iff_exists_Ioo_subset' (hM x hx)).1 (h x hx),
choose! y hy h'y using A,
have B : set.pairwise_disjoint (s \ interior s) (λ x, Ioo x (y x)),
{ assume x hx x' hx' hxx',
rcases lt_or_gt_of_ne hxx' with h'|h',
{ apply disjoint_left.2 (λ z hz h'z, _),
have : x' ∈ interior s :=
mem_interior.2 ⟨Ioo x (y x), h'y _ hx.1, is_open_Ioo, ⟨h', h'z.1.trans hz.2⟩⟩,
exact false.elim (hx'.2 this) },
{ apply disjoint_left.2 (λ z hz h'z, _),
have : x ∈ interior s :=
mem_interior.2 ⟨Ioo x' (y x'), h'y _ hx'.1, is_open_Ioo, ⟨h', hz.1.trans h'z.2⟩⟩,
exact false.elim (hx.2 this) } },
exact B.countable_of_Ioo (λ x hx, hy x hx.1),
end
/-- If a set is a right-neighborhood of all of its points, then it is measurable. -/
lemma measurable_set_of_mem_nhds_within_Ioi {s : set α}
(h : ∀ x ∈ s, s ∈ 𝓝[>] x) : measurable_set s :=
begin
by_cases H : ∃ x ∈ s, is_top x,
{ rcases H with ⟨x₀, x₀s, h₀⟩,
have : s = {x₀} ∪ (s \ {x₀}), by rw union_diff_cancel (singleton_subset_iff.2 x₀s),
rw this,
refine (measurable_set_singleton _).union _,
have A : ∀ x ∈ s \ {x₀}, x < x₀ :=
λ x hx, lt_of_le_of_ne (h₀ _) (by simpa using hx.2),
refine measurable_set_of_mem_nhds_within_Ioi_aux (λ x hx, _) (λ x hx, ⟨x₀, A x hx⟩),
obtain ⟨u, hu, us⟩ : ∃ (u : α) (H : u ∈ Ioi x), Ioo x u ⊆ s :=
(mem_nhds_within_Ioi_iff_exists_Ioo_subset' (A x hx)).1 (h x hx.1),
refine (mem_nhds_within_Ioi_iff_exists_Ioo_subset' (A x hx)).2 ⟨u, hu, λ y hy, ⟨us hy, _⟩⟩,
exact ne_of_lt (hy.2.trans_le (h₀ _)) },
{ apply measurable_set_of_mem_nhds_within_Ioi_aux h,
simp only [is_top] at H,
push_neg at H,
exact H }
end
end linear_order
@[measurability]
lemma measurable.supr_Prop {α} [measurable_space α] [complete_lattice α]
(p : Prop) {f : δ → α} (hf : measurable f) :
measurable (λ b, ⨆ h : p, f b) :=
classical.by_cases
(assume h : p, begin convert hf, funext, exact supr_pos h end)
(assume h : ¬p, begin convert measurable_const, funext, exact supr_neg h end)
@[measurability]
lemma measurable.infi_Prop {α} [measurable_space α] [complete_lattice α]
(p : Prop) {f : δ → α} (hf : measurable f) :
measurable (λ b, ⨅ h : p, f b) :=
classical.by_cases
(assume h : p, begin convert hf, funext, exact infi_pos h end )
(assume h : ¬p, begin convert measurable_const, funext, exact infi_neg h end)
section complete_linear_order
variables [complete_linear_order α] [order_topology α] [second_countable_topology α]
@[measurability]
lemma measurable_supr {ι} [countable ι] {f : ι → δ → α} (hf : ∀ i, measurable (f i)) :
measurable (λ b, ⨆ i, f i b) :=
measurable.is_lub hf $ λ b, is_lub_supr
@[measurability]
lemma ae_measurable_supr {ι} {μ : measure δ} [countable ι] {f : ι → δ → α}
(hf : ∀ i, ae_measurable (f i) μ) :
ae_measurable (λ b, ⨆ i, f i b) μ :=
ae_measurable.is_lub hf $ (ae_of_all μ (λ b, is_lub_supr))
@[measurability]
lemma measurable_infi {ι} [countable ι] {f : ι → δ → α} (hf : ∀ i, measurable (f i)) :
measurable (λ b, ⨅ i, f i b) :=
measurable.is_glb hf $ λ b, is_glb_infi
@[measurability]
lemma ae_measurable_infi {ι} {μ : measure δ} [countable ι] {f : ι → δ → α}
(hf : ∀ i, ae_measurable (f i) μ) :
ae_measurable (λ b, ⨅ i, f i b) μ :=
ae_measurable.is_glb hf $ (ae_of_all μ (λ b, is_glb_infi))
lemma measurable_bsupr {ι} (s : set ι) {f : ι → δ → α} (hs : s.countable)
(hf : ∀ i, measurable (f i)) : measurable (λ b, ⨆ i ∈ s, f i b) :=
by { haveI : encodable s := hs.to_encodable, simp only [supr_subtype'],
exact measurable_supr (λ i, hf i) }
lemma ae_measurable_bsupr {ι} {μ : measure δ} (s : set ι) {f : ι → δ → α} (hs : s.countable)
(hf : ∀ i, ae_measurable (f i) μ) : ae_measurable (λ b, ⨆ i ∈ s, f i b) μ :=
begin
haveI : encodable s := hs.to_encodable,
simp only [supr_subtype'],
exact ae_measurable_supr (λ i, hf i),
end
lemma measurable_binfi {ι} (s : set ι) {f : ι → δ → α} (hs : s.countable)
(hf : ∀ i, measurable (f i)) : measurable (λ b, ⨅ i ∈ s, f i b) :=
by { haveI : encodable s := hs.to_encodable, simp only [infi_subtype'],
exact measurable_infi (λ i, hf i) }
lemma ae_measurable_binfi {ι} {μ : measure δ} (s : set ι) {f : ι → δ → α} (hs : s.countable)
(hf : ∀ i, ae_measurable (f i) μ) : ae_measurable (λ b, ⨅ i ∈ s, f i b) μ :=
begin
haveI : encodable s := hs.to_encodable,
simp only [infi_subtype'],
exact ae_measurable_infi (λ i, hf i),
end
/-- `liminf` over a general filter is measurable. See `measurable_liminf` for the version over `ℕ`.
-/
lemma measurable_liminf' {ι ι'} {f : ι → δ → α} {u : filter ι} (hf : ∀ i, measurable (f i))
{p : ι' → Prop} {s : ι' → set ι} (hu : u.has_countable_basis p s) (hs : ∀ i, (s i).countable) :
measurable (λ x, liminf (λ i, f i x) u) :=
begin
simp_rw [hu.to_has_basis.liminf_eq_supr_infi],
refine measurable_bsupr _ hu.countable _,
exact λ i, measurable_binfi _ (hs i) hf
end
/-- `limsup` over a general filter is measurable. See `measurable_limsup` for the version over `ℕ`.
-/
lemma measurable_limsup' {ι ι'} {f : ι → δ → α} {u : filter ι} (hf : ∀ i, measurable (f i))
{p : ι' → Prop} {s : ι' → set ι} (hu : u.has_countable_basis p s) (hs : ∀ i, (s i).countable) :
measurable (λ x, limsup (λ i, f i x) u) :=
begin
simp_rw [hu.to_has_basis.limsup_eq_infi_supr],
refine measurable_binfi _ hu.countable _,
exact λ i, measurable_bsupr _ (hs i) hf
end
/-- `liminf` over `ℕ` is measurable. See `measurable_liminf'` for a version with a general filter.
-/
@[measurability]
lemma measurable_liminf {f : ℕ → δ → α} (hf : ∀ i, measurable (f i)) :
measurable (λ x, liminf (λ i, f i x) at_top) :=
measurable_liminf' hf at_top_countable_basis (λ i, to_countable _)
/-- `limsup` over `ℕ` is measurable. See `measurable_limsup'` for a version with a general filter.
-/
@[measurability]
lemma measurable_limsup {f : ℕ → δ → α} (hf : ∀ i, measurable (f i)) :
measurable (λ x, limsup (λ i, f i x) at_top) :=
measurable_limsup' hf at_top_countable_basis (λ i, to_countable _)
end complete_linear_order
section conditionally_complete_linear_order
variables [conditionally_complete_linear_order α] [order_topology α] [second_countable_topology α]
lemma measurable_cSup {ι} {f : ι → δ → α} {s : set ι} (hs : s.countable)
(hf : ∀ i, measurable (f i)) (bdd : ∀ x, bdd_above ((λ i, f i x) '' s)) :
measurable (λ x, Sup ((λ i, f i x) '' s)) :=
begin
cases eq_empty_or_nonempty s with h2s h2s,
{ simp [h2s, measurable_const] },
{ apply measurable_of_Iic, intro y,
simp_rw [preimage, mem_Iic, cSup_le_iff (bdd _) (h2s.image _), ball_image_iff, set_of_forall],
exact measurable_set.bInter hs (λ i hi, measurable_set_le (hf i) measurable_const) }
end
lemma measurable_cInf {ι} {f : ι → δ → α} {s : set ι} (hs : s.countable)
(hf : ∀ i, measurable (f i)) (bdd : ∀ x, bdd_below ((λ i, f i x) '' s)) :
measurable (λ x, Inf ((λ i, f i x) '' s)) :=
@measurable_cSup αᵒᵈ _ _ _ _ _ _ _ _ _ _ _ hs hf bdd
lemma measurable_csupr {ι : Type*} [countable ι] {f : ι → δ → α}
(hf : ∀ i, measurable (f i)) (bdd : ∀ x, bdd_above (range (λ i, f i x))) :
measurable (λ x, ⨆ i, f i x) :=
begin
change measurable (λ x, Sup (range (λ i : ι, f i x))),
simp_rw ← image_univ at bdd ⊢,
refine measurable_cSup countable_univ hf bdd,
end
lemma measurable_cinfi {ι : Type*} [countable ι] {f : ι → δ → α}
(hf : ∀ i, measurable (f i)) (bdd : ∀ x, bdd_below (range (λ i, f i x))) :
measurable (λ x, ⨅ i, f i x) :=
@measurable_csupr αᵒᵈ _ _ _ _ _ _ _ _ _ _ _ hf bdd
end conditionally_complete_linear_order
/-- Convert a `homeomorph` to a `measurable_equiv`. -/
def homemorph.to_measurable_equiv (h : α ≃ₜ β) : α ≃ᵐ β :=
{ to_equiv := h.to_equiv,
measurable_to_fun := h.continuous_to_fun.measurable,
measurable_inv_fun := h.continuous_inv_fun.measurable }
protected lemma is_finite_measure_on_compacts.map
{α : Type*} {m0 : measurable_space α} [topological_space α] [opens_measurable_space α]
{β : Type*} [measurable_space β] [topological_space β] [borel_space β]
[t2_space β] (μ : measure α) [is_finite_measure_on_compacts μ] (f : α ≃ₜ β) :
is_finite_measure_on_compacts (measure.map f μ) :=
⟨begin
assume K hK,
rw [measure.map_apply f.measurable hK.measurable_set],
apply is_compact.measure_lt_top,
rwa f.is_compact_preimage
end⟩
end borel_space
instance empty.borel_space : borel_space empty := ⟨borel_eq_top_of_discrete.symm⟩
instance unit.borel_space : borel_space unit := ⟨borel_eq_top_of_discrete.symm⟩
instance bool.borel_space : borel_space bool := ⟨borel_eq_top_of_discrete.symm⟩
instance nat.borel_space : borel_space ℕ := ⟨borel_eq_top_of_discrete.symm⟩
instance int.borel_space : borel_space ℤ := ⟨borel_eq_top_of_discrete.symm⟩
instance rat.borel_space : borel_space ℚ := ⟨borel_eq_top_of_countable.symm⟩
/- Instances on `real` and `complex` are special cases of `is_R_or_C` but without these instances,
Lean fails to prove `borel_space (ι → ℝ)`, so we leave them here. -/
instance real.measurable_space : measurable_space ℝ := borel ℝ
instance real.borel_space : borel_space ℝ := ⟨rfl⟩
instance nnreal.measurable_space : measurable_space ℝ≥0 := subtype.measurable_space
instance nnreal.borel_space : borel_space ℝ≥0 := subtype.borel_space _
instance ennreal.measurable_space : measurable_space ℝ≥0∞ := borel ℝ≥0∞
instance ennreal.borel_space : borel_space ℝ≥0∞ := ⟨rfl⟩
instance ereal.measurable_space : measurable_space ereal := borel ereal
instance ereal.borel_space : borel_space ereal := ⟨rfl⟩
/-- One can cut out `ℝ≥0∞` into the sets `{0}`, `Ico (t^n) (t^(n+1))` for `n : ℤ` and `{∞}`. This
gives a way to compute the measure of a set in terms of sets on which a given function `f` does not
fluctuate by more than `t`. -/
lemma measure_eq_measure_preimage_add_measure_tsum_Ico_zpow [measurable_space α] (μ : measure α)
{f : α → ℝ≥0∞} (hf : measurable f) {s : set α} (hs : measurable_set s) {t : ℝ≥0} (ht : 1 < t) :
μ s = μ (s ∩ f⁻¹' {0}) + μ (s ∩ f⁻¹' {∞}) + ∑' (n : ℤ), μ (s ∩ f⁻¹' (Ico (t^n) (t^(n+1)))) :=
begin
have A : μ s = μ (s ∩ f⁻¹' {0}) + μ (s ∩ f⁻¹' (Ioi 0)),
{ rw ← measure_union,
{ congr' 1,
ext x,
have : 0 = f x ∨ 0 < f x := eq_or_lt_of_le bot_le,
rw eq_comm at this,
simp only [←and_or_distrib_left, this, mem_singleton_iff, mem_inter_iff, and_true,
mem_union, mem_Ioi, mem_preimage], },
{ apply disjoint_left.2 (λ x hx h'x, _),
have : 0 < f x := h'x.2,
exact lt_irrefl 0 (this.trans_le hx.2.le) },
{ exact hs.inter (hf measurable_set_Ioi) } },
have B : μ (s ∩ f⁻¹' (Ioi 0)) = μ (s ∩ f⁻¹' {∞}) + μ (s ∩ f⁻¹' (Ioo 0 ∞)),
{ rw ← measure_union,
{ rw ← inter_union_distrib_left,
congr,
ext x,
simp only [mem_singleton_iff, mem_union, mem_Ioo, mem_Ioi, mem_preimage],
have H : f x = ∞ ∨ f x < ∞ := eq_or_lt_of_le le_top,
cases H,
{ simp only [H, eq_self_iff_true, or_false, with_top.zero_lt_top, not_top_lt, and_false] },
{ simp only [H, H.ne, and_true, false_or] } },
{ apply disjoint_left.2 (λ x hx h'x, _),
have : f x < ∞ := h'x.2.2,
exact lt_irrefl _ (this.trans_le (le_of_eq hx.2.symm)) },
{ exact hs.inter (hf measurable_set_Ioo) } },
have C : μ (s ∩ f⁻¹' (Ioo 0 ∞)) = ∑' (n : ℤ), μ (s ∩ f⁻¹' (Ico (t^n) (t^(n+1)))),
{ rw [← measure_Union, ennreal.Ioo_zero_top_eq_Union_Ico_zpow (ennreal.one_lt_coe_iff.2 ht)
ennreal.coe_ne_top, preimage_Union, inter_Union],
{ assume i j,
simp only [function.on_fun],
assume hij,
wlog h : i < j generalizing i j,
{ exact (this hij.symm (hij.lt_or_lt.resolve_left h)).symm },
apply disjoint_left.2 (λ x hx h'x, lt_irrefl (f x) _),
calc f x < t ^ (i + 1) : hx.2.2
... ≤ t ^ j : ennreal.zpow_le_of_le (ennreal.one_le_coe_iff.2 ht.le) h
... ≤ f x : h'x.2.1 },
{ assume n,
exact hs.inter (hf measurable_set_Ico) } },
rw [A, B, C, add_assoc],
end
section pseudo_metric_space
variables [pseudo_metric_space α] [measurable_space α] [opens_measurable_space α]
variables [measurable_space β] {x : α} {ε : ℝ}
open metric
@[measurability]
lemma measurable_set_ball : measurable_set (metric.ball x ε) :=
metric.is_open_ball.measurable_set
@[measurability]
lemma measurable_set_closed_ball : measurable_set (metric.closed_ball x ε) :=
metric.is_closed_ball.measurable_set
@[measurability]
lemma measurable_inf_dist {s : set α} : measurable (λ x, inf_dist x s) :=
(continuous_inf_dist_pt s).measurable
@[measurability]
lemma measurable.inf_dist {f : β → α} (hf : measurable f) {s : set α} :
measurable (λ x, inf_dist (f x) s) :=
measurable_inf_dist.comp hf
@[measurability]
lemma measurable_inf_nndist {s : set α} : measurable (λ x, inf_nndist x s) :=
(continuous_inf_nndist_pt s).measurable
@[measurability]
lemma measurable.inf_nndist {f : β → α} (hf : measurable f) {s : set α} :
measurable (λ x, inf_nndist (f x) s) :=
measurable_inf_nndist.comp hf
section
variables [second_countable_topology α]
@[measurability]
lemma measurable_dist : measurable (λ p : α × α, dist p.1 p.2) :=
continuous_dist.measurable
@[measurability]
lemma measurable.dist {f g : β → α} (hf : measurable f) (hg : measurable g) :
measurable (λ b, dist (f b) (g b)) :=
(@continuous_dist α _).measurable2 hf hg
@[measurability]
lemma measurable_nndist : measurable (λ p : α × α, nndist p.1 p.2) :=
continuous_nndist.measurable
@[measurability]
lemma measurable.nndist {f g : β → α} (hf : measurable f) (hg : measurable g) :
measurable (λ b, nndist (f b) (g b)) :=
(@continuous_nndist α _).measurable2 hf hg
end
/-- If a set has a closed thickening with finite measure, then the measure of its `r`-closed
thickenings converges to the measure of its closure as `r` tends to `0`. -/
lemma tendsto_measure_cthickening {μ : measure α} {s : set α}
(hs : ∃ R > 0, μ (cthickening R s) ≠ ∞) :
tendsto (λ r, μ (cthickening r s)) (𝓝 0) (𝓝 (μ (closure s))) :=
begin
have A : tendsto (λ r, μ (cthickening r s)) (𝓝[Ioi 0] 0) (𝓝 (μ (closure s))),
{ rw closure_eq_Inter_cthickening,
exact tendsto_measure_bInter_gt (λ r hr, is_closed_cthickening.measurable_set)
(λ i j ipos ij, cthickening_mono ij _) hs },
have B : tendsto (λ r, μ (cthickening r s)) (𝓝[Iic 0] 0) (𝓝 (μ (closure s))),
{ apply tendsto.congr' _ tendsto_const_nhds,
filter_upwards [self_mem_nhds_within] with _ hr,
rw cthickening_of_nonpos hr, },
convert B.sup A,
exact (nhds_left_sup_nhds_right' 0).symm,
end
/-- If a closed set has a closed thickening with finite measure, then the measure of its `r`-closed
thickenings converges to its measure as `r` tends to `0`. -/
lemma tendsto_measure_cthickening_of_is_closed {μ : measure α} {s : set α}
(hs : ∃ R > 0, μ (cthickening R s) ≠ ∞) (h's : is_closed s) :
tendsto (λ r, μ (cthickening r s)) (𝓝 0) (𝓝 (μ s)) :=
begin
convert tendsto_measure_cthickening hs,
exact h's.closure_eq.symm
end
end pseudo_metric_space
/-- Given a compact set in a proper space, the measure of its `r`-closed thickenings converges to
its measure as `r` tends to `0`. -/
lemma tendsto_measure_cthickening_of_is_compact [metric_space α] [measurable_space α]
[opens_measurable_space α] [proper_space α] {μ : measure α}
[is_finite_measure_on_compacts μ] {s : set α} (hs : is_compact s) :
tendsto (λ r, μ (metric.cthickening r s)) (𝓝 0) (𝓝 (μ s)) :=
tendsto_measure_cthickening_of_is_closed
⟨1, zero_lt_one, hs.bounded.cthickening.measure_lt_top.ne⟩ hs.is_closed
section pseudo_emetric_space
variables [pseudo_emetric_space α] [measurable_space α] [opens_measurable_space α]
variables [measurable_space β] {x : α} {ε : ℝ≥0∞}
open emetric
@[measurability]
lemma measurable_set_eball : measurable_set (emetric.ball x ε) :=
emetric.is_open_ball.measurable_set
@[measurability]
lemma measurable_edist_right : measurable (edist x) :=
(continuous_const.edist continuous_id).measurable
@[measurability]
lemma measurable_edist_left : measurable (λ y, edist y x) :=
(continuous_id.edist continuous_const).measurable
@[measurability]
lemma measurable_inf_edist {s : set α} : measurable (λ x, inf_edist x s) :=
continuous_inf_edist.measurable
@[measurability]
lemma measurable.inf_edist {f : β → α} (hf : measurable f) {s : set α} :
measurable (λ x, inf_edist (f x) s) :=
measurable_inf_edist.comp hf
variables [second_countable_topology α]
@[measurability]
lemma measurable_edist : measurable (λ p : α × α, edist p.1 p.2) :=
continuous_edist.measurable
@[measurability]
lemma measurable.edist {f g : β → α} (hf : measurable f) (hg : measurable g) :
measurable (λ b, edist (f b) (g b)) :=
(@continuous_edist α _).measurable2 hf hg
@[measurability]
lemma ae_measurable.edist {f g : β → α} {μ : measure β}
(hf : ae_measurable f μ) (hg : ae_measurable g μ) : ae_measurable (λ a, edist (f a) (g a)) μ :=
(@continuous_edist α _).ae_measurable2 hf hg
end pseudo_emetric_space
namespace real
open measurable_space measure_theory
lemma borel_eq_generate_from_Ioo_rat :
borel ℝ = generate_from (⋃(a b : ℚ) (h : a < b), {Ioo a b}) :=
is_topological_basis_Ioo_rat.borel_eq_generate_from
lemma is_pi_system_Ioo_rat : @is_pi_system ℝ (⋃ (a b : ℚ) (h : a < b), {Ioo a b}) :=
begin
convert is_pi_system_Ioo (coe : ℚ → ℝ) (coe : ℚ → ℝ),
ext x,
simp [eq_comm]
end
/-- The intervals `(-(n + 1), (n + 1))` form a finite spanning sets in the set of open intervals
with rational endpoints for a locally finite measure `μ` on `ℝ`. -/
def finite_spanning_sets_in_Ioo_rat (μ : measure ℝ) [is_locally_finite_measure μ] :
μ.finite_spanning_sets_in (⋃ (a b : ℚ) (h : a < b), {Ioo a b}) :=
{ set := λ n, Ioo (-(n + 1)) (n + 1),
set_mem := λ n,
begin
simp only [mem_Union, mem_singleton_iff],
refine ⟨-(n + 1 : ℕ), n + 1, _, by simp⟩, -- TODO: norm_cast fails here?
exact (neg_nonpos.2 (@nat.cast_nonneg ℚ _ (n + 1))).trans_lt n.cast_add_one_pos
end,
finite := λ n, measure_Ioo_lt_top,
spanning := Union_eq_univ_iff.2 $ λ x,
⟨⌊|x|⌋₊, neg_lt.1 ((neg_le_abs_self x).trans_lt (nat.lt_floor_add_one _)),
(le_abs_self x).trans_lt (nat.lt_floor_add_one _)⟩ }
lemma measure_ext_Ioo_rat {μ ν : measure ℝ} [is_locally_finite_measure μ]
(h : ∀ a b : ℚ, μ (Ioo a b) = ν (Ioo a b)) : μ = ν :=
(finite_spanning_sets_in_Ioo_rat μ).ext borel_eq_generate_from_Ioo_rat is_pi_system_Ioo_rat $
by { simp only [mem_Union, mem_singleton_iff], rintro _ ⟨a, b, -, rfl⟩, apply h }
lemma borel_eq_generate_from_Iio_rat :
borel ℝ = generate_from (⋃ a : ℚ, {Iio a}) :=
begin
let g : measurable_space ℝ := generate_from (⋃ a : ℚ, {Iio a}),
refine le_antisymm _ _,
{ rw borel_eq_generate_from_Ioo_rat,
refine generate_from_le (λ t, _),
simp only [mem_Union, mem_singleton_iff], rintro ⟨a, b, h, rfl⟩,
rw (set.ext (λ x, _) : Ioo (a : ℝ) b = (⋃c>a, (Iio c)ᶜ) ∩ Iio b),
{ have hg : ∀ q : ℚ, measurable_set[g] (Iio q) :=
λ q, generate_measurable.basic (Iio q) (by simp),
refine @measurable_set.inter _ g _ _ _ (hg _),
refine @measurable_set.bUnion _ _ g _ _ (to_countable _) (λ c h, _),
exact @measurable_set.compl _ _ g (hg _) },
{ suffices : x < ↑b → (↑a < x ↔ ∃ (i : ℚ), a < i ∧ ↑i ≤ x), by simpa,
refine λ _, ⟨λ h, _, λ ⟨i, hai, hix⟩, (rat.cast_lt.2 hai).trans_le hix⟩,
rcases exists_rat_btwn h with ⟨c, ac, cx⟩,
exact ⟨c, rat.cast_lt.1 ac, cx.le⟩ } },
{ refine measurable_space.generate_from_le (λ _, _),
simp only [mem_Union, mem_singleton_iff], rintro ⟨r, rfl⟩, exact measurable_set_Iio }
end
end real
variable [measurable_space α]
@[measurability]
lemma measurable_real_to_nnreal : measurable (real.to_nnreal) :=
continuous_real_to_nnreal.measurable
@[measurability]
lemma measurable.real_to_nnreal {f : α → ℝ} (hf : measurable f) :
measurable (λ x, real.to_nnreal (f x)) :=
measurable_real_to_nnreal.comp hf
@[measurability]
lemma ae_measurable.real_to_nnreal {f : α → ℝ} {μ : measure α} (hf : ae_measurable f μ) :
ae_measurable (λ x, real.to_nnreal (f x)) μ :=
measurable_real_to_nnreal.comp_ae_measurable hf
@[measurability]
lemma measurable_coe_nnreal_real : measurable (coe : ℝ≥0 → ℝ) :=
nnreal.continuous_coe.measurable
@[measurability]
lemma measurable.coe_nnreal_real {f : α → ℝ≥0} (hf : measurable f) :
measurable (λ x, (f x : ℝ)) :=
measurable_coe_nnreal_real.comp hf
@[measurability]
lemma ae_measurable.coe_nnreal_real {f : α → ℝ≥0} {μ : measure α} (hf : ae_measurable f μ) :
ae_measurable (λ x, (f x : ℝ)) μ :=
measurable_coe_nnreal_real.comp_ae_measurable hf
@[measurability]
lemma measurable_coe_nnreal_ennreal : measurable (coe : ℝ≥0 → ℝ≥0∞) :=
ennreal.continuous_coe.measurable
@[measurability]
lemma measurable.coe_nnreal_ennreal {f : α → ℝ≥0} (hf : measurable f) :
measurable (λ x, (f x : ℝ≥0∞)) :=
ennreal.continuous_coe.measurable.comp hf
@[measurability]
lemma ae_measurable.coe_nnreal_ennreal {f : α → ℝ≥0} {μ : measure α} (hf : ae_measurable f μ) :
ae_measurable (λ x, (f x : ℝ≥0∞)) μ :=
ennreal.continuous_coe.measurable.comp_ae_measurable hf
@[measurability]
lemma measurable.ennreal_of_real {f : α → ℝ} (hf : measurable f) :
measurable (λ x, ennreal.of_real (f x)) :=
ennreal.continuous_of_real.measurable.comp hf
@[simp, norm_cast]
lemma measurable_coe_nnreal_real_iff {f : α → ℝ≥0} : measurable (λ x, f x : α → ℝ) ↔ measurable f :=
⟨λ h, by simpa only [real.to_nnreal_coe] using h.real_to_nnreal, measurable.coe_nnreal_real⟩
@[simp, norm_cast]
lemma ae_measurable_coe_nnreal_real_iff {f : α → ℝ≥0} {μ : measure α} :
ae_measurable (λ x, f x : α → ℝ) μ ↔ ae_measurable f μ :=
⟨λ h, by simpa only [real.to_nnreal_coe] using h.real_to_nnreal, ae_measurable.coe_nnreal_real⟩
/-- The set of finite `ℝ≥0∞` numbers is `measurable_equiv` to `ℝ≥0`. -/
def measurable_equiv.ennreal_equiv_nnreal : {r : ℝ≥0∞ | r ≠ ∞} ≃ᵐ ℝ≥0 :=
ennreal.ne_top_homeomorph_nnreal.to_measurable_equiv
namespace ennreal
lemma measurable_of_measurable_nnreal {f : ℝ≥0∞ → α}
(h : measurable (λ p : ℝ≥0, f p)) : measurable f :=
measurable_of_measurable_on_compl_singleton ∞
(measurable_equiv.ennreal_equiv_nnreal.symm.measurable_comp_iff.1 h)
/-- `ℝ≥0∞` is `measurable_equiv` to `ℝ≥0 ⊕ unit`. -/
def ennreal_equiv_sum : ℝ≥0∞ ≃ᵐ ℝ≥0 ⊕ unit :=
{ measurable_to_fun := measurable_of_measurable_nnreal measurable_inl,
measurable_inv_fun := measurable_sum measurable_coe_nnreal_ennreal
(@measurable_const ℝ≥0∞ unit _ _ ∞),
.. equiv.option_equiv_sum_punit ℝ≥0 }
open function (uncurry)
lemma measurable_of_measurable_nnreal_prod [measurable_space β] [measurable_space γ]
{f : ℝ≥0∞ × β → γ} (H₁ : measurable (λ p : ℝ≥0 × β, f (p.1, p.2)))
(H₂ : measurable (λ x, f (∞, x))) :
measurable f :=
let e : ℝ≥0∞ × β ≃ᵐ ℝ≥0 × β ⊕ unit × β :=
(ennreal_equiv_sum.prod_congr (measurable_equiv.refl β)).trans
(measurable_equiv.sum_prod_distrib _ _ _) in
e.symm.measurable_comp_iff.1 $ measurable_sum H₁ (H₂.comp measurable_id.snd)
lemma measurable_of_measurable_nnreal_nnreal [measurable_space β]
{f : ℝ≥0∞ × ℝ≥0∞ → β} (h₁ : measurable (λ p : ℝ≥0 × ℝ≥0, f (p.1, p.2)))
(h₂ : measurable (λ r : ℝ≥0, f (∞, r))) (h₃ : measurable (λ r : ℝ≥0, f (r, ∞))) :
measurable f :=
measurable_of_measurable_nnreal_prod
(measurable_swap_iff.1 $ measurable_of_measurable_nnreal_prod (h₁.comp measurable_swap) h₃)
(measurable_of_measurable_nnreal h₂)
@[measurability]
lemma measurable_of_real : measurable ennreal.of_real :=
ennreal.continuous_of_real.measurable
@[measurability]
lemma measurable_to_real : measurable ennreal.to_real :=
ennreal.measurable_of_measurable_nnreal measurable_coe_nnreal_real
@[measurability]
lemma measurable_to_nnreal : measurable ennreal.to_nnreal :=
ennreal.measurable_of_measurable_nnreal measurable_id
instance : has_measurable_mul₂ ℝ≥0∞ :=
begin
refine ⟨measurable_of_measurable_nnreal_nnreal _ _ _⟩,
{ simp only [← ennreal.coe_mul, measurable_mul.coe_nnreal_ennreal] },
{ simp only [ennreal.top_mul, ennreal.coe_eq_zero],
exact measurable_const.piecewise (measurable_set_singleton _) measurable_const },
{ simp only [ennreal.mul_top, ennreal.coe_eq_zero],
exact measurable_const.piecewise (measurable_set_singleton _) measurable_const }
end
instance : has_measurable_sub₂ ℝ≥0∞ :=
⟨by apply measurable_of_measurable_nnreal_nnreal;
simp [← with_top.coe_sub, continuous_sub.measurable.coe_nnreal_ennreal]⟩
instance : has_measurable_inv ℝ≥0∞ := ⟨continuous_inv.measurable⟩
end ennreal
@[measurability]
lemma measurable.ennreal_to_nnreal {f : α → ℝ≥0∞} (hf : measurable f) :
measurable (λ x, (f x).to_nnreal) :=
ennreal.measurable_to_nnreal.comp hf
@[measurability]
lemma ae_measurable.ennreal_to_nnreal {f : α → ℝ≥0∞} {μ : measure α} (hf : ae_measurable f μ) :
ae_measurable (λ x, (f x).to_nnreal) μ :=
ennreal.measurable_to_nnreal.comp_ae_measurable hf
@[simp, norm_cast] lemma measurable_coe_nnreal_ennreal_iff {f : α → ℝ≥0} :
measurable (λ x, (f x : ℝ≥0∞)) ↔ measurable f :=
⟨λ h, h.ennreal_to_nnreal, λ h, h.coe_nnreal_ennreal⟩
@[simp, norm_cast] lemma ae_measurable_coe_nnreal_ennreal_iff {f : α → ℝ≥0} {μ : measure α} :
ae_measurable (λ x, (f x : ℝ≥0∞)) μ ↔ ae_measurable f μ :=
⟨λ h, h.ennreal_to_nnreal, λ h, h.coe_nnreal_ennreal⟩
@[measurability]
lemma measurable.ennreal_to_real {f : α → ℝ≥0∞} (hf : measurable f) :
measurable (λ x, ennreal.to_real (f x)) :=
ennreal.measurable_to_real.comp hf
@[measurability]
lemma ae_measurable.ennreal_to_real {f : α → ℝ≥0∞} {μ : measure α} (hf : ae_measurable f μ) :
ae_measurable (λ x, ennreal.to_real (f x)) μ :=
ennreal.measurable_to_real.comp_ae_measurable hf
/-- note: `ℝ≥0∞` can probably be generalized in a future version of this lemma. -/
@[measurability]
lemma measurable.ennreal_tsum {ι} [countable ι] {f : ι → α → ℝ≥0∞} (h : ∀ i, measurable (f i)) :
measurable (λ x, ∑' i, f i x) :=
by { simp_rw [ennreal.tsum_eq_supr_sum], apply measurable_supr,
exact λ s, s.measurable_sum (λ i _, h i) }
@[measurability]
lemma measurable.ennreal_tsum' {ι} [countable ι] {f : ι → α → ℝ≥0∞} (h : ∀ i, measurable (f i)) :
measurable (∑' i, f i) :=
begin
convert measurable.ennreal_tsum h,
ext1 x,
exact tsum_apply (pi.summable.2 (λ _, ennreal.summable)),
end
@[measurability]
lemma measurable.nnreal_tsum {ι} [countable ι] {f : ι → α → ℝ≥0} (h : ∀ i, measurable (f i)) :
measurable (λ x, ∑' i, f i x) :=
begin
simp_rw [nnreal.tsum_eq_to_nnreal_tsum],
exact (measurable.ennreal_tsum (λ i, (h i).coe_nnreal_ennreal)).ennreal_to_nnreal,
end
@[measurability]
lemma ae_measurable.ennreal_tsum {ι} [countable ι] {f : ι → α → ℝ≥0∞} {μ : measure α}
(h : ∀ i, ae_measurable (f i) μ) :
ae_measurable (λ x, ∑' i, f i x) μ :=
by { simp_rw [ennreal.tsum_eq_supr_sum], apply ae_measurable_supr,
exact λ s, finset.ae_measurable_sum s (λ i _, h i) }
@[measurability]
lemma ae_measurable.nnreal_tsum {α : Type*} [measurable_space α] {ι : Type*}
[countable ι] {f : ι → α → nnreal} {μ : measure_theory.measure α}
(h : ∀ (i : ι), ae_measurable (f i) μ) :
ae_measurable (λ (x : α), ∑' (i : ι), f i x) μ :=
begin
simp_rw [nnreal.tsum_eq_to_nnreal_tsum],
exact (ae_measurable.ennreal_tsum (λ i, (h i).coe_nnreal_ennreal)).ennreal_to_nnreal,
end
@[measurability]
lemma measurable_coe_real_ereal : measurable (coe : ℝ → ereal) :=
continuous_coe_real_ereal.measurable
@[measurability]
lemma measurable.coe_real_ereal {f : α → ℝ} (hf : measurable f) :
measurable (λ x, (f x : ereal)) :=
measurable_coe_real_ereal.comp hf
@[measurability]
lemma ae_measurable.coe_real_ereal {f : α → ℝ} {μ : measure α} (hf : ae_measurable f μ) :
ae_measurable (λ x, (f x : ereal)) μ :=
measurable_coe_real_ereal.comp_ae_measurable hf
/-- The set of finite `ereal` numbers is `measurable_equiv` to `ℝ`. -/
def measurable_equiv.ereal_equiv_real : ({⊥, ⊤}ᶜ : set ereal) ≃ᵐ ℝ :=
ereal.ne_bot_top_homeomorph_real.to_measurable_equiv
lemma ereal.measurable_of_measurable_real {f : ereal → α}
(h : measurable (λ p : ℝ, f p)) : measurable f :=
measurable_of_measurable_on_compl_finite {⊥, ⊤} (by simp)
(measurable_equiv.ereal_equiv_real.symm.measurable_comp_iff.1 h)
@[measurability]
lemma measurable_ereal_to_real : measurable ereal.to_real :=
ereal.measurable_of_measurable_real (by simpa using measurable_id)
@[measurability]
lemma measurable.ereal_to_real {f : α → ereal} (hf : measurable f) :
measurable (λ x, (f x).to_real) :=
measurable_ereal_to_real.comp hf
@[measurability]
lemma ae_measurable.ereal_to_real {f : α → ereal} {μ : measure α} (hf : ae_measurable f μ) :
ae_measurable (λ x, (f x).to_real) μ :=
measurable_ereal_to_real.comp_ae_measurable hf
@[measurability]
lemma measurable_coe_ennreal_ereal : measurable (coe : ℝ≥0∞ → ereal) :=
continuous_coe_ennreal_ereal.measurable
@[measurability]
lemma measurable.coe_ereal_ennreal {f : α → ℝ≥0∞} (hf : measurable f) :
measurable (λ x, (f x : ereal)) :=
measurable_coe_ennreal_ereal.comp hf
@[measurability]
lemma ae_measurable.coe_ereal_ennreal {f : α → ℝ≥0∞} {μ : measure α} (hf : ae_measurable f μ) :
ae_measurable (λ x, (f x : ereal)) μ :=
measurable_coe_ennreal_ereal.comp_ae_measurable hf
section normed_add_comm_group
variables [normed_add_comm_group α] [opens_measurable_space α] [measurable_space β]
@[measurability]
lemma measurable_norm : measurable (norm : α → ℝ) :=
continuous_norm.measurable
@[measurability]
lemma measurable.norm {f : β → α} (hf : measurable f) : measurable (λ a, norm (f a)) :=
measurable_norm.comp hf
@[measurability]
lemma ae_measurable.norm {f : β → α} {μ : measure β} (hf : ae_measurable f μ) :
ae_measurable (λ a, norm (f a)) μ :=
measurable_norm.comp_ae_measurable hf
@[measurability]
lemma measurable_nnnorm : measurable (nnnorm : α → ℝ≥0) :=
continuous_nnnorm.measurable
@[measurability]
lemma measurable.nnnorm {f : β → α} (hf : measurable f) : measurable (λ a, ‖f a‖₊) :=
measurable_nnnorm.comp hf
@[measurability]
lemma ae_measurable.nnnorm {f : β → α} {μ : measure β} (hf : ae_measurable f μ) :
ae_measurable (λ a, ‖f a‖₊) μ :=
measurable_nnnorm.comp_ae_measurable hf
@[measurability]
lemma measurable_ennnorm : measurable (λ x : α, (‖x‖₊ : ℝ≥0∞)) :=
measurable_nnnorm.coe_nnreal_ennreal
@[measurability]
lemma measurable.ennnorm {f : β → α} (hf : measurable f) :
measurable (λ a, (‖f a‖₊ : ℝ≥0∞)) :=
hf.nnnorm.coe_nnreal_ennreal
@[measurability]
lemma ae_measurable.ennnorm {f : β → α} {μ : measure β} (hf : ae_measurable f μ) :
ae_measurable (λ a, (‖f a‖₊ : ℝ≥0∞)) μ :=
measurable_ennnorm.comp_ae_measurable hf
end normed_add_comm_group
|
6f2f1ffaf4eabd4a5e6c74f49a58f4be228923f4 | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/category_theory/limits/shapes/pullbacks.lean | ef688d715a6605977fd95749a60dc06d61a448ec | [
"Apache-2.0"
] | permissive | rmitta/mathlib | 8d90aee30b4db2b013e01f62c33f297d7e64a43d | 883d974b608845bad30ae19e27e33c285200bf84 | refs/heads/master | 1,585,776,832,544 | 1,576,874,096,000 | 1,576,874,096,000 | 153,663,165 | 0 | 2 | Apache-2.0 | 1,544,806,490,000 | 1,539,884,365,000 | Lean | UTF-8 | Lean | false | false | 11,113 | lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import data.fintype
import category_theory.limits.limits
import category_theory.sparse
/-!
# Pullbacks
We define a category `walking_cospan` (resp. `walking_span`), which is the index category
for the given data for a pullback (resp. pushout) diagram. Convenience methods `cospan f g`
and `span f g` construct functors from the walking (co)span, hitting the given morphisms.
We define `pullback f g` and `pushout f g` as limits and colimits of such functors.
Typeclasses `has_pullbacks` and `has_pushouts` assert the existence of (co)limits shaped as
walking (co)spans.
-/
open category_theory
namespace category_theory.limits
universes v u
local attribute [tidy] tactic.case_bash
/-- The type of objects for the diagram indexing a pullback. -/
@[derive decidable_eq] inductive walking_cospan : Type v
| left | right | one
/-- The type of objects for the diagram indexing a pushout. -/
@[derive decidable_eq] inductive walking_span : Type v
| zero | left | right
instance fintype_walking_cospan : fintype walking_cospan :=
{ elems := [walking_cospan.left, walking_cospan.right, walking_cospan.one].to_finset,
complete := λ x, by { cases x; simp } }
instance fintype_walking_span : fintype walking_span :=
{ elems := [walking_span.zero, walking_span.left, walking_span.right].to_finset,
complete := λ x, by { cases x; simp } }
namespace walking_cospan
/-- The arrows in a pullback diagram. -/
inductive hom : walking_cospan → walking_cospan → Type v
| inl : hom left one
| inr : hom right one
| id : Π X : walking_cospan.{v}, hom X X
open hom
def hom.comp : Π (X Y Z : walking_cospan) (f : hom X Y) (g : hom Y Z), hom X Z
| _ _ _ (id _) h := h
| _ _ _ inl (id one) := inl
| _ _ _ inr (id one) := inr
.
instance category_struct : category_struct walking_cospan :=
{ hom := hom,
id := hom.id,
comp := hom.comp, }
instance (X Y : walking_cospan) : subsingleton (X ⟶ Y) := by tidy
-- We make this a @[simp] lemma later; if we do it now there's a mysterious
-- failure in `cospan`, below.
lemma hom_id (X : walking_cospan.{v}) : hom.id X = 𝟙 X := rfl
/-- The walking_cospan is the index diagram for a pullback. -/
instance : small_category.{v} walking_cospan.{v} := sparse_category
end walking_cospan
namespace walking_span
/-- The arrows in a pushout diagram. -/
inductive hom : walking_span → walking_span → Type v
| fst : hom zero left
| snd : hom zero right
| id : Π X : walking_span.{v}, hom X X
open hom
def hom.comp : Π (X Y Z : walking_span) (f : hom X Y) (g : hom Y Z), hom X Z
| _ _ _ (id _) h := h
| _ _ _ fst (id left) := fst
| _ _ _ snd (id right) := snd
.
instance category_struct : category_struct walking_span :=
{ hom := hom,
id := hom.id,
comp := hom.comp }
instance (X Y : walking_span) : subsingleton (X ⟶ Y) := by tidy
-- We make this a @[simp] lemma later; if we do it now there's a mysterious
-- failure in `span`, below.
lemma hom_id (X : walking_span.{v}) : hom.id X = 𝟙 X := rfl
/-- The walking_span is the index diagram for a pushout. -/
instance : small_category.{v} walking_span.{v} := sparse_category
end walking_span
open walking_span walking_cospan walking_span.hom walking_cospan.hom
variables {C : Type u} [𝒞 : category.{v} C]
include 𝒞
/-- `cospan f g` is the functor from the walking cospan hitting `f` and `g`. -/
def cospan {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : walking_cospan.{v} ⥤ C :=
{ obj := λ x, match x with
| left := X
| right := Y
| one := Z
end,
map := λ x y h, match x, y, h with
| _, _, (id _) := 𝟙 _
| _, _, inl := f
| _, _, inr := g
end }
/-- `span f g` is the functor from the walking span hitting `f` and `g`. -/
def span {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : walking_span.{v} ⥤ C :=
{ obj := λ x, match x with
| zero := X
| left := Y
| right := Z
end,
map := λ x y h, match x, y, h with
| _, _, (id _) := 𝟙 _
| _, _, fst := f
| _, _, snd := g
end }
@[simp] lemma cospan_left {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
(cospan f g).obj walking_cospan.left = X := rfl
@[simp] lemma span_left {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) :
(span f g).obj walking_span.left = Y := rfl
@[simp] lemma cospan_right {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
(cospan f g).obj walking_cospan.right = Y := rfl
@[simp] lemma span_right {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) :
(span f g).obj walking_span.right = Z := rfl
@[simp] lemma cospan_one {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
(cospan f g).obj walking_cospan.one = Z := rfl
@[simp] lemma span_zero {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) :
(span f g).obj walking_span.zero = X := rfl
@[simp] lemma cospan_map_inl {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
(cospan f g).map walking_cospan.hom.inl = f := rfl
@[simp] lemma span_map_fst {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) :
(span f g).map walking_span.hom.fst = f := rfl
@[simp] lemma cospan_map_inr {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
(cospan f g).map walking_cospan.hom.inr = g := rfl
@[simp] lemma span_map_snd {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) :
(span f g).map walking_span.hom.snd = g := rfl
@[simp] lemma cospan_map_id {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) (w : walking_cospan) :
(cospan f g).map (walking_cospan.hom.id w) = 𝟙 _ := rfl
@[simp] lemma span_map_id {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) (w : walking_span) :
(span f g).map (walking_span.hom.id w) = 𝟙 _ := rfl
variables {X Y Z : C}
attribute [simp] walking_cospan.hom_id walking_span.hom_id
abbreviation pullback_cone (f : X ⟶ Z) (g : Y ⟶ Z) := cone (cospan f g)
namespace pullback_cone
variables {f : X ⟶ Z} {g : Y ⟶ Z}
abbreviation fst (t : pullback_cone f g) : t.X ⟶ X := t.π.app left
abbreviation snd (t : pullback_cone f g) : t.X ⟶ Y := t.π.app right
def mk {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : pullback_cone f g :=
{ X := W,
π :=
{ app := λ j, walking_cospan.cases_on j fst snd (fst ≫ f),
naturality' := λ j j' f, by cases f; obviously } }
@[reassoc] lemma condition (t : pullback_cone f g) : (fst t) ≫ f = (snd t) ≫ g :=
begin
erw [t.w inl, ← t.w inr], refl
end
end pullback_cone
abbreviation pushout_cocone (f : X ⟶ Y) (g : X ⟶ Z) := cocone (span f g)
namespace pushout_cocone
variables {f : X ⟶ Y} {g : X ⟶ Z}
abbreviation inl (t : pushout_cocone f g) : Y ⟶ t.X := t.ι.app left
abbreviation inr (t : pushout_cocone f g) : Z ⟶ t.X := t.ι.app right
def mk {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : pushout_cocone f g :=
{ X := W,
ι :=
{ app := λ j, walking_span.cases_on j (f ≫ inl) inl inr,
naturality' := λ j j' f, by cases f; obviously } }
@[reassoc] lemma condition (t : pushout_cocone f g) : f ≫ (inl t) = g ≫ (inr t) :=
begin
erw [t.w fst, ← t.w snd], refl
end
end pushout_cocone
def cone.of_pullback_cone
{F : walking_cospan.{v} ⥤ C} (t : pullback_cone (F.map inl) (F.map inr)) : cone F :=
{ X := t.X,
π :=
{ app := λ X, t.π.app X ≫ eq_to_hom (by tidy),
naturality' := λ j j' g,
begin
cases j; cases j'; cases g; dsimp; simp,
exact (t.w inl).symm,
exact (t.w inr).symm
end } }.
@[simp] lemma cone.of_pullback_cone_π
{F : walking_cospan.{v} ⥤ C} (t : pullback_cone (F.map inl) (F.map inr)) (j) :
(cone.of_pullback_cone t).π.app j = t.π.app j ≫ eq_to_hom (by tidy) := rfl
def cocone.of_pushout_cocone
{F : walking_span.{v} ⥤ C} (t : pushout_cocone (F.map fst) (F.map snd)) : cocone F :=
{ X := t.X,
ι :=
{ app := λ X, eq_to_hom (by tidy) ≫ t.ι.app X,
naturality' := λ j j' g,
begin
cases j; cases j'; cases g; dsimp; simp,
exact t.w fst,
exact t.w snd
end } }.
@[simp] lemma cocone.of_pushout_cocone_ι
{F : walking_span.{v} ⥤ C} (t : pushout_cocone (F.map fst) (F.map snd)) (j) :
(cocone.of_pushout_cocone t).ι.app j = eq_to_hom (by tidy) ≫ t.ι.app j := rfl
def pullback_cone.of_cone
{F : walking_cospan.{v} ⥤ C} (t : cone F) : pullback_cone (F.map inl) (F.map inr) :=
{ X := t.X,
π := { app := λ j, t.π.app j ≫ eq_to_hom (by tidy) } }
@[simp] lemma pullback_cone.of_cone_π {F : walking_cospan.{v} ⥤ C} (t : cone F) (j) :
(pullback_cone.of_cone t).π.app j = t.π.app j ≫ eq_to_hom (by tidy) := rfl
def pushout_cocone.of_cocone
{F : walking_span.{v} ⥤ C} (t : cocone F) : pushout_cocone (F.map fst) (F.map snd) :=
{ X := t.X,
ι := { app := λ j, eq_to_hom (by tidy) ≫ t.ι.app j } }
@[simp] lemma pushout_cocone.of_cocone_ι {F : walking_span.{v} ⥤ C} (t : cocone F) (j) :
(pushout_cocone.of_cocone t).ι.app j = eq_to_hom (by tidy) ≫ t.ι.app j := rfl
/-- `pullback f g` computes the pullback of a pair of morphisms with the same target. -/
abbreviation pullback {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [has_limit (cospan f g)] :=
limit (cospan f g)
/-- `pushout f g` computes the pushout of a pair of morphisms with the same source. -/
abbreviation pushout {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [has_colimit (span f g)] :=
colimit (span f g)
abbreviation pullback.fst {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [has_limit (cospan f g)] : pullback f g ⟶ X :=
limit.π (cospan f g) walking_cospan.left
abbreviation pullback.snd {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [has_limit (cospan f g)] : pullback f g ⟶ Y :=
limit.π (cospan f g) walking_cospan.right
abbreviation pushout.inl {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [has_colimit (span f g)] : Y ⟶ pushout f g :=
colimit.ι (span f g) walking_span.left
abbreviation pushout.inr {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [has_colimit (span f g)] : Z ⟶ pushout f g :=
colimit.ι (span f g) walking_span.right
abbreviation pullback.lift {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [has_limit (cospan f g)]
(h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : W ⟶ pullback f g :=
limit.lift _ (pullback_cone.mk h k w)
abbreviation pushout.desc {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [has_colimit (span f g)]
(h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : pushout f g ⟶ W :=
colimit.desc _ (pushout_cocone.mk h k w)
lemma pullback.condition {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [has_limit (cospan f g)] :
(pullback.fst : pullback f g ⟶ X) ≫ f = pullback.snd ≫ g :=
(limit.w (cospan f g) walking_cospan.hom.inl).trans
(limit.w (cospan f g) walking_cospan.hom.inr).symm
lemma pushout.condition {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [has_colimit (span f g)] :
f ≫ (pushout.inl : Y ⟶ pushout f g) = g ≫ pushout.inr :=
(colimit.w (span f g) walking_span.hom.fst).trans
(colimit.w (span f g) walking_span.hom.snd).symm
variables (C)
class has_pullbacks :=
(has_limits_of_shape : has_limits_of_shape.{v} walking_cospan C)
class has_pushouts :=
(has_colimits_of_shape : has_colimits_of_shape.{v} walking_span C)
attribute [instance] has_pullbacks.has_limits_of_shape has_pushouts.has_colimits_of_shape
end category_theory.limits
|
e5c435d8fdc0221c55aca0a65ca989fb98bc5a29 | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/tactic/omega/nat/main.lean | fd138863cc3c73ec60fb91d64e5f5b286b828467 | [
"Apache-2.0"
] | permissive | rmitta/mathlib | 8d90aee30b4db2b013e01f62c33f297d7e64a43d | 883d974b608845bad30ae19e27e33c285200bf84 | refs/heads/master | 1,585,776,832,544 | 1,576,874,096,000 | 1,576,874,096,000 | 153,663,165 | 0 | 2 | Apache-2.0 | 1,544,806,490,000 | 1,539,884,365,000 | Lean | UTF-8 | Lean | false | false | 4,891 | lean | /-
Copyright (c) 2019 Seul Baek. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Seul Baek
Main procedure for linear natural number arithmetic.
-/
import tactic.omega.prove_unsats
import tactic.omega.nat.dnf
import tactic.omega.nat.neg_elim
import tactic.omega.nat.sub_elim
open tactic
namespace omega
namespace nat
open_locale omega.nat
mk_simp_attribute sugar_nat none
attribute [sugar_nat]
ne not_le not_lt
nat.lt_iff_add_one_le
nat.succ_eq_add_one
or_false false_or
and_true true_and
ge gt mul_add add_mul mul_comm
one_mul mul_one
classical.imp_iff_not_or
classical.iff_iff_not_or_and_or_not
meta def desugar := `[try {simp only with sugar_nat}]
lemma univ_close_of_unsat_neg_elim_not (m) (p : form) :
(neg_elim (¬* p)).unsat → univ_close p (λ _, 0) m :=
begin
intro h1, apply univ_close_of_valid,
apply valid_of_unsat_not, intro h2, apply h1,
apply form.sat_of_implies_of_sat implies_neg_elim h2,
end
meta def preterm.prove_sub_free : preterm → tactic expr
| (& m) := return `(trivial)
| (m ** n) := return `(trivial)
| (t +* s) :=
do x ← preterm.prove_sub_free t,
y ← preterm.prove_sub_free s,
return `(@and.intro (preterm.sub_free %%`(t))
(preterm.sub_free %%`(s)) %%x %%y)
| (_ -* _) := failed
meta def prove_neg_free : form → tactic expr
| (t =* s) := return `(trivial)
| (t ≤* s) := return `(trivial)
| (p ∨* q) :=
do x ← prove_neg_free p,
y ← prove_neg_free q,
return `(@and.intro (form.neg_free %%`(p))
(form.neg_free %%`(q)) %%x %%y)
| (p ∧* q) :=
do x ← prove_neg_free p,
y ← prove_neg_free q,
return `(@and.intro (form.neg_free %%`(p))
(form.neg_free %%`(q)) %%x %%y)
| _ := failed
meta def prove_sub_free : form → tactic expr
| (t =* s) :=
do x ← preterm.prove_sub_free t,
y ← preterm.prove_sub_free s,
return `(@and.intro (preterm.sub_free %%`(t))
(preterm.sub_free %%`(s)) %%x %%y)
| (t ≤* s) :=
do x ← preterm.prove_sub_free t,
y ← preterm.prove_sub_free s,
return `(@and.intro (preterm.sub_free %%`(t))
(preterm.sub_free %%`(s)) %%x %%y)
| (¬*p) := prove_sub_free p
| (p ∨* q) :=
do x ← prove_sub_free p,
y ← prove_sub_free q,
return `(@and.intro (form.sub_free %%`(p))
(form.sub_free %%`(q)) %%x %%y)
| (p ∧* q) :=
do x ← prove_sub_free p,
y ← prove_sub_free q,
return `(@and.intro (form.sub_free %%`(p))
(form.sub_free %%`(q)) %%x %%y)
/- Given a p : form, return the expr of a term t : p.unsat,
where p is subtraction- and negation-free. -/
meta def prove_unsat_sub_free (p : form) : tactic expr :=
do x ← prove_neg_free p,
y ← prove_sub_free p,
z ← prove_unsats (dnf p),
return `(unsat_of_unsat_dnf %%`(p) %%x %%y %%z)
/- Given a p : form, return the expr of a term t : p.unsat,
where p is negation-free. -/
meta def prove_unsat_neg_free : form → tactic expr | p :=
match p.sub_terms with
| none := prove_unsat_sub_free p
| (some (t,s)) :=
do x ← prove_unsat_neg_free (sub_elim t s p),
return `(unsat_of_unsat_sub_elim %%`(t) %%`(s) %%`(p) %%x)
end
/- Given a (m : nat) and (p : form),
return the expr of (t : univ_close m p) -/
meta def prove_univ_close (m : nat) (p : form) : tactic expr :=
do x ← prove_unsat_neg_free (neg_elim (¬*p)),
to_expr ``(univ_close_of_unsat_neg_elim_not %%`(m) %%`(p) %%x)
meta def to_preterm : expr → tactic preterm
| (expr.var k) := return (preterm.var 1 k)
| `(%%(expr.var k) * %%mx) :=
do m ← eval_expr' nat mx,
return (preterm.var m k)
| `(%%t1x + %%t2x) :=
do t1 ← to_preterm t1x,
t2 ← to_preterm t2x,
return (preterm.add t1 t2)
| `(%%t1x - %%t2x) :=
do t1 ← to_preterm t1x,
t2 ← to_preterm t2x,
return (preterm.sub t1 t2)
| mx :=
do m ← eval_expr' nat mx,
return (preterm.cst m)
meta def to_form_core : expr → tactic form
| `(%%tx1 = %%tx2) :=
do t1 ← to_preterm tx1,
t2 ← to_preterm tx2,
return (t1 =* t2)
| `(%%tx1 ≤ %%tx2) :=
do t1 ← to_preterm tx1,
t2 ← to_preterm tx2,
return (t1 ≤* t2)
| `(¬ %%px) := do p ← to_form_core px, return (¬* p)
| `(%%px ∨ %%qx) :=
do p ← to_form_core px,
q ← to_form_core qx,
return (p ∨* q)
| `(%%px ∧ %%qx) :=
do p ← to_form_core px,
q ← to_form_core qx,
return (p ∧* q)
| `(_ → %%px) := to_form_core px
| x := trace "Cannot reify expr : " >> trace x >> failed
meta def to_form : nat → expr → tactic (form × nat)
| m `(_ → %%px) := to_form (m+1) px
| m x := do p ← to_form_core x, return (p,m)
meta def prove_lna : tactic expr :=
do (p,m) ← target >>= to_form 0,
prove_univ_close m p
end nat
end omega
open omega.nat
meta def omega_nat : tactic unit :=
desugar >> (done <|> (prove_lna >>= apply >> skip))
|
ff1f05411d1f7ca95deda9c5ae4ccf766ec69241 | 8b9f17008684d796c8022dab552e42f0cb6fb347 | /library/data/set/classical_inverse.lean | e2e8c3dd854462e2f793cace9ed5e56f7705a751 | [
"Apache-2.0"
] | permissive | chubbymaggie/lean | 0d06ae25f9dd396306fb02190e89422ea94afd7b | d2c7b5c31928c98f545b16420d37842c43b4ae9a | refs/heads/master | 1,611,313,622,901 | 1,430,266,839,000 | 1,430,267,083,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,745 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: data.set.function
Author: Jeremy Avigad, Andrew Zipperer
Using classical logic, defines an inverse function.
-/
import .function .map
import logic.axioms.classical
open eq.ops
namespace set
variables {X Y : Type}
definition inv_fun (f : X → Y) (a : set X) (dflt : X) (y : Y) : X :=
if H : ∃₀ x ∈ a, f x = y then some H else dflt
theorem inv_fun_pos {f : X → Y} {a : set X} {dflt : X} {y : Y}
(H : ∃₀ x ∈ a, f x = y) : (inv_fun f a dflt y ∈ a) ∧ (f (inv_fun f a dflt y) = y) :=
have H1 : inv_fun f a dflt y = some H, from dif_pos H,
H1⁻¹ ▸ some_spec H
theorem inv_fun_neg {f : X → Y} {a : set X} {dflt : X} {y : Y}
(H : ¬ ∃₀ x ∈ a, f x = y) : inv_fun f a dflt y = dflt :=
dif_neg H
variables {f : X → Y} {a : set X} {b : set Y}
theorem maps_to_inv_fun {dflt : X} (dflta : dflt ∈ a) :
maps_to (inv_fun f a dflt) b a :=
let f' := inv_fun f a dflt in
take y,
assume yb : y ∈ b,
show f' y ∈ a, from
by_cases
(assume H : ∃₀ x ∈ a, f x = y,
and.left (inv_fun_pos H))
(assume H : ¬ ∃₀ x ∈ a, f x = y,
(inv_fun_neg H)⁻¹ ▸ dflta)
theorem left_inv_on_inv_fun_of_inj_on (dflt : X) (H : inj_on f a) :
left_inv_on (inv_fun f a dflt) f a :=
let f' := inv_fun f a dflt in
take x,
assume xa : x ∈ a,
have H1 : ∃₀ x' ∈ a, f x' = f x, from exists.intro x (and.intro xa rfl),
have H2 : f' (f x) ∈ a ∧ f (f' (f x)) = f x, from inv_fun_pos H1,
show f' (f x) = x, from H (and.left H2) xa (and.right H2)
theorem right_inv_on_inv_fun_of_surj_on (dflt : X) (H : surj_on f a b) :
right_inv_on (inv_fun f a dflt) f b :=
let f' := inv_fun f a dflt in
take y,
assume yb: y ∈ b,
obtain x (Hx : x ∈ a ∧ f x = y), from H yb,
have Hy : f' y ∈ a ∧ f (f' y) = y, from inv_fun_pos (exists.intro x Hx),
and.right Hy
end set
open set
namespace map
variables {X Y : Type} {a : set X} {b : set Y}
protected definition inverse (f : map a b) {dflt : X} (dflta : dflt ∈ a) :=
map.mk (inv_fun f a dflt) (@maps_to_inv_fun _ _ _ _ b _ dflta)
theorem left_inverse_inverse {f : map a b} {dflt : X} (dflta : dflt ∈ a) (H : injective f) :
left_inverse (inverse f dflta) f :=
left_inv_on_inv_fun_of_inj_on dflt H
theorem right_inverse_inverse {f : map a b} {dflt : X} (dflta : dflt ∈ a) (H : surjective f) :
right_inverse (inverse f dflta) f :=
right_inv_on_inv_fun_of_surj_on dflt H
theorem is_inverse_inverse {f : map a b} {dflt : X} (dflta : dflt ∈ a) (H : bijective f) :
is_inverse (inverse f dflta) f :=
and.intro
(left_inverse_inverse dflta (and.left H))
(right_inverse_inverse dflta (and.right H))
end map
|
1cd122e7542f800a1e2e2ee7a1afe3e2a320d82b | 4fa118f6209450d4e8d058790e2967337811b2b5 | /src/valuation/linear_ordered_comm_group_with_zero.lean | b83a817aa265b665d47f7cddbde5c42cc3360657 | [
"Apache-2.0"
] | permissive | leanprover-community/lean-perfectoid-spaces | 16ab697a220ed3669bf76311daa8c466382207f7 | 95a6520ce578b30a80b4c36e36ab2d559a842690 | refs/heads/master | 1,639,557,829,139 | 1,638,797,866,000 | 1,638,797,866,000 | 135,769,296 | 96 | 10 | Apache-2.0 | 1,638,797,866,000 | 1,527,892,754,000 | Lean | UTF-8 | Lean | false | false | 7,259 | lean | import data.real.nnreal
import for_mathlib.group_with_zero
import for_mathlib.linear_ordered_comm_group
/-!
# Linearly ordered commutative groups with a zero element adjoined
This file sets up a special class of linearly ordered commutative monoids
that show up as the target of so-called “valuations” in algebraic number theory.
Usually, in the informal literature, these objects are constructed
by taking a linearly ordered commutative group Γ and formally adjoining a zero element: Γ ∪ {0}.
The disadvantage is that a type such as `nnreal` is not of that form,
whereas it is a very common target for valuations.
The solutions is to use a typeclass, and that is exactly what we do in this file.
We show that both `with_zero Γ` and `nnreal` are instances of `linear_ordered_comm_group_with_zero`.
-/
set_option old_structure_cmd true
/-- A linearly ordered commutative group with zero
is a linearly ordered commutative monoid with a zero element
such that all nonzero elements are invertible.-/
class linear_ordered_comm_group_with_zero (α : Type*)
extends linear_ordered_comm_monoid α, comm_group_with_zero α :=
(zero_le' : ∀ a, (0:α) ≤ a)
namespace with_zero
/-- Adjoining a zero element to a linearly ordered commutative group
gives a linearly ordered commutative group with zero.-/
instance (α : Type*) [linear_ordered_comm_group α] [decidable_eq α] :
linear_ordered_comm_group_with_zero (with_zero α) :=
{ zero_le' := λ a, with_zero.zero_le,
inv_zero := rfl,
mul_inv_cancel := λ a h, mul_right_inv a h,
.. (infer_instance : linear_ordered_comm_monoid (with_zero α)),
.. (infer_instance : has_inv (with_zero α)),
.. (infer_instance : zero_ne_one_class (with_zero α)),
.. (infer_instance : mul_zero_class (with_zero α)) }
end with_zero
namespace linear_ordered_comm_group_with_zero
variables (α : Type*) [linear_ordered_comm_group_with_zero α]
/--The units of a linearly ordered commutative group are linearly ordered.-/
instance units.linear_order : linear_order (units α) :=
linear_order.lift (coe : units α → α) units.ext infer_instance
/--The units of a linearly ordered commutative group with zero
form a linearly ordered commutative group.-/
instance units.linear_ordered_comm_group : linear_ordered_comm_group (units α) :=
{ mul_le_mul_left := λ a b h c, mul_le_mul_left h _,
.. units.linear_order α,
.. (infer_instance : comm_group (units α))}
end linear_ordered_comm_group_with_zero
namespace linear_ordered_structure
variables {α : Type*} [group_with_zero α]
variables {a b c d : α}
lemma ne_zero_iff_exists : a ≠ 0 ↔ ∃ u : units α, a = u :=
begin
split,
{ intro h, use [group_with_zero.mk₀ a h], refl },
{ rintro ⟨u, rfl⟩, exact group_with_zero.unit_ne_zero u }
end
end linear_ordered_structure
namespace linear_ordered_structure
variables {α : Type*} [linear_ordered_comm_group_with_zero α]
variables {a b c d : α}
open group_with_zero
local attribute [instance] classical.prop_decidable
local attribute [instance, priority 0] classical.DLO
@[simp] lemma zero_le {a : α} : 0 ≤ a :=
linear_ordered_comm_group_with_zero.zero_le' a
@[simp] lemma le_zero_iff : a ≤ 0 ↔ a = 0 :=
⟨λ h, le_antisymm h zero_le, λ h, h ▸ le_refl _⟩
lemma le_of_le_mul_right (h : c ≠ 0) (hab : a * c ≤ b * c) : a ≤ b :=
by simpa [h] using linear_ordered_structure.mul_le_mul_right hab c⁻¹
lemma le_mul_inv_of_mul_le (h : c ≠ 0) (hab : a * c ≤ b) : a ≤ b * c⁻¹ :=
le_of_le_mul_right h (by simpa [h] using hab)
lemma mul_inv_le_of_le_mul (h : c ≠ 0) (hab : a ≤ b * c) : a * c⁻¹ ≤ b :=
le_of_le_mul_right h (by simpa [h] using hab)
lemma div_le_div' (a b c d : α) (hb : b ≠ 0) (hd : d ≠ 0) :
a * b⁻¹ ≤ c * d⁻¹ ↔ a * d ≤ c * b :=
begin
by_cases ha : a = 0,
{ simp [ha] },
by_cases hc : c = 0,
{ replace hb := inv_ne_zero' _ hb,
simp [hb, hc, hd], },
exact (div_le_div (mk₀ a ha) (mk₀ b hb) (mk₀ c hc) (mk₀ d hd)),
end
lemma lt_of_mul_lt_mul_left' {a b c : α} (h : a * b < a * c) : b < c :=
begin
by_cases ha : a = 0, { contrapose! h, simp [ha] },
by_cases hc : c = 0, { contrapose! h, simp [hc] },
by_cases hb : b = 0, { contrapose! hc, simpa [hb] using hc },
exact linear_ordered_structure.lt_of_mul_lt_mul_left (mk₀ a ha) (mk₀ b hb) (mk₀ c hc) h
end
/-- Every linearly ordered commutative group with zero is an ordered commutative monoid.-/
instance : actual_ordered_comm_monoid α :=
{ lt_of_mul_lt_mul_left := λ a b c, lt_of_mul_lt_mul_left',
.. ‹linear_ordered_comm_group_with_zero α› }
@[move_cast] lemma coe_min (x y : units α) :
((min x y : units α) : α) = min (x : α) (y : α) :=
begin
by_cases h: x ≤ y,
{ simp [min_eq_left, h] },
{ simp [min_eq_right, le_of_not_le h] }
end
lemma ne_zero_of_lt (h : b < a) : a ≠ 0 :=
by { contrapose! h, simp [h] }
@[simp] lemma zero_lt_unit (u : units α) : (0 : α) < u :=
by { have h := group_with_zero.unit_ne_zero u, contrapose! h, simpa using h }
lemma mul_lt_mul' : a < b → c < d → a*c < b*d :=
begin
intros hab hcd,
let b' := group_with_zero.mk₀ b (ne_zero_of_lt hab),
let d' := group_with_zero.mk₀ d (ne_zero_of_lt hcd),
have hbd : 0 < b * d,
{ have h := group_with_zero.unit_ne_zero (b' * d'), contrapose! h, simpa using h },
by_cases ha : a = 0,
{ simp [ha, hbd], },
by_cases hc : c = 0,
{ simp [hc, hbd], },
let a' := group_with_zero.mk₀ a ha,
let c' := group_with_zero.mk₀ c hc,
show a' * c' < b' * d',
exact linear_ordered_structure.mul_lt_mul hab hcd
end
lemma mul_inv_lt_of_lt_mul' {x y z : α} (h : x < y*z) : x*z⁻¹ < y :=
begin
by_cases hx : x = 0, { contrapose! h, simp * at *, },
by_cases hy : y = 0, { contrapose! h, simp [hy] },
by_cases hz : z = 0, { contrapose! h, simp [hz] },
change (group_with_zero.mk₀ _ hx) < (group_with_zero.mk₀ _ hy) * (group_with_zero.mk₀ _ hz) at h,
exact mul_inv_lt_of_lt_mul h
end
.
lemma mul_lt_right' (γ : α) (h : a < b) (hγ : γ ≠ 0) : a*γ < b*γ :=
begin
have hb : b ≠ 0 := ne_zero_of_lt h,
by_cases ha : a = 0,
{ by_contra H, simp [ha] at H, tauto, },
change (group_with_zero.mk₀ _ ha) < (group_with_zero.mk₀ _ hb) at h,
exact linear_ordered_structure.mul_lt_right (group_with_zero.mk₀ _ hγ) h
end
lemma inv_lt_inv (ha : a ≠ 0) (hb : b ≠ 0) :
a⁻¹ < b⁻¹ ↔ b < a :=
begin
suffices : ∀ {x y : α}, x ≠ 0 → y ≠ 0 → x < y → y⁻¹ < x⁻¹,
{ refine ⟨_, this hb ha⟩, intro h, rw [← inv_inv'' a, ← inv_inv'' b],
apply this _ _ h; solve_by_elim [inv_ne_zero'], },
clear ha hb a b,
intros x y hx hy h,
have hx' : x⁻¹ ≠ 0 := by solve_by_elim [inv_ne_zero'],
have hy' : y⁻¹ ≠ 0 := by solve_by_elim [inv_ne_zero'],
replace h := linear_ordered_structure.mul_lt_right' _ h hx',
replace h := linear_ordered_structure.mul_lt_right' _ h hy',
rw [mul_inv_cancel' _ hx, _root_.one_mul] at h,
erw [mul_comm y x⁻¹, _root_.mul_assoc, mul_inv_cancel' _ hy, _root_.mul_one] at h,
exact h
end
lemma inv_le_inv (ha : a ≠ 0) (hb : b ≠ 0) :
a⁻¹ ≤ b⁻¹ ↔ b ≤ a :=
begin
have := not_iff_not_of_iff (inv_lt_inv hb ha),
push_neg at this,
exact this
end
end linear_ordered_structure
|
8e67afeab40cb31bed71f0a6a60214ecc44f823a | fd71e7836e9a5d14548f6d3291653cbb6c608dbe | /src/test/slim_check/testable.lean | 1ce23dac12971f864143a9c6e8662de714935e4d | [] | no_license | cipher1024/slim_check | 382c80a98aed105a97eeac84f590a06dca4d8c7d | 5969b7f72e01fdd46f2502ed0cbf69c0699061d4 | refs/heads/master | 1,625,514,334,828 | 1,574,118,572,000 | 1,574,118,572,000 | 101,538,155 | 2 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 5,922 | lean |
import test.slim_check.arbitrary
universes u v
variable α : Type u
variable β : α → Prop
variable f : Type → Prop
namespace slim_check
inductive test_result (p : Prop)
| success : (psum unit p) → test_result
| gave_up {} : ℕ → test_result
| failure : ¬ p → (list string) → test_result
class testable (p : Prop) :=
(run : gen (test_result p))
open list
open test_result
def combine {p q : Prop} : psum unit (p → q) → psum unit p → psum unit q
| (psum.inr f) (psum.inr x) := psum.inr (f x)
| _ _ := psum.inl ()
def convert_counter_example {p q : Prop}
(h : q → p)
: test_result p →
opt_param (psum unit (p → q)) (psum.inl ()) →
test_result q
| (failure Hce xs) _ := failure (mt h Hce) xs
| (success Hp) Hpq := success (combine Hpq Hp)
| (gave_up n) _ := gave_up n
def add_to_counter_example (x : string) {p q : Prop}
(h : q → p)
: test_result p →
opt_param (psum unit (p → q)) (psum.inl ()) →
test_result q
| (failure Hce xs) _ := failure (mt h Hce) $ x :: xs
| r hpq := convert_counter_example h r hpq
def add_var_to_counter_example {γ : Type v} [has_to_string γ]
(var : string) (x : γ) {p q : Prop}
(h : q → p)
: test_result p →
opt_param (psum unit (p → q)) (psum.inl ()) →
test_result q :=
@add_to_counter_example (var ++ " := " ++ to_string x) _ _ h
instance imp_dec_testable (p : Prop) [decidable p] (β : p → Prop)
[∀ h, testable (β h)]
: testable (Π h, β h) :=
⟨ do
if h : p
then (λ r, convert_counter_example ($ h) r (psum.inr $ λ q _, q)) <$> testable.run (β h)
else return $ gave_up 1 ⟩
instance all_types_testable [testable (f ℤ)]
: testable (Π x, f x) :=
⟨ do
r ← testable.run (f ℤ),
return $ add_to_counter_example "ℤ" ($ ℤ) r ⟩
def test_one (x : α) [testable (β x)] (var : option (string × string) := none)
: testable (Π x, β x) :=
⟨ do
r ← testable.run (β x),
return $ match var with
| none := convert_counter_example ($ x) r
| (some (v,x_str)) := add_var_to_counter_example v x_str ($ x) r
end ⟩
def test_forall_in_list (var : string) [∀ x, testable (β x)] [has_to_string α]
: Π xs : list α, testable (∀ x, x ∈ xs → β x)
| [] := ⟨ return $ success $ psum.inr (by { introv h, cases h} ) ⟩
| (x :: xs) :=
⟨ do
r ← testable.run (β x),
match r with
| failure _ _ := return $ add_var_to_counter_example var x
(by { intro h, apply h, left, refl }) r
| success hp := do
rs ← (test_forall_in_list xs).run,
return $ convert_counter_example
(by { intros h i h',
apply h,
right, apply h' })
rs
(combine (psum.inr
$ by { intros j h, simp only [ball_cons],
split ; assumption, } ) hp)
| gave_up n := do
rs ← (test_forall_in_list xs).run,
match rs with
| (success _) := return $ gave_up n
| (failure Hce xs) := return $ failure
(by { simp only [ball_cons],
apply not_and_of_not_right _ Hce, }) xs
| (gave_up n') := return $ gave_up (n + n')
end
end ⟩
def combine_testable (p : Prop)
(t : list $ testable p) (h : 0 < t.length)
: testable p :=
⟨ have 0 < length (map (@testable.run p) t),
by { rw [length_map], apply h },
one_of (list.map (@testable.run _) t) this ⟩
def var_testable [has_to_string α] [arbitrary α] [∀ x, testable (β x)]
(var : option string := none)
: testable (Π x : α, β x) :=
⟨ liftable.down' $ do
x ← arby α,
liftable.up' (do
r ← testable.run (β x),
return $ match var with
| none := add_to_counter_example (to_string x) ($ x) r
| (some v) := add_var_to_counter_example v x ($ x) r
end) ⟩
instance pi_testable [has_to_string α] [arbitrary α] [∀ x, testable (β x)]
: testable (Π x : α, β x) :=
var_testable α β
instance de_testable {p : Prop} [decidable p] : testable p :=
⟨ return $ if h : p then success (psum.inr h) else failure h [] ⟩
section io
variable (p : Prop)
variable [testable p]
open nat
variable {p}
def retry (cmd : rand (test_result p)) : ℕ → rand (test_result p)
| 0 := return $ gave_up 1
| (succ n) := do
r ← cmd,
match r with
| success hp := return $ success hp
| (failure Hce xs) := return (failure Hce xs)
| (gave_up _) := retry n
end
def give_up_once (x : ℕ) : test_result p → test_result p
| (success (psum.inl ())) := gave_up x
| (success (psum.inr p)) := success (psum.inr p)
| (gave_up n) := gave_up (n+x)
| (failure Hce xs) := failure Hce xs
variable (p)
def testable.run_suite_aux : test_result p → ℕ → rand (test_result p)
| r 0 := return r
| r (succ n) :=
do x ← retry ( (testable.run p).run ⟨ 99 - n ⟩) 10,
match x with
| (success (psum.inl ())) := testable.run_suite_aux r n
| (success (psum.inr Hp)) := return $ success (psum.inr Hp)
| (failure Hce xs) := return (failure Hce xs)
| (gave_up g) := testable.run_suite_aux (give_up_once g r) n
end
def testable.run_suite (bound : ℕ := 100) :=
testable.run_suite_aux p (success $ psum.inl ()) bound
def testable.check (bound : ℕ := 100) : io (test_result p) :=
io.run_rand (testable.run_suite p bound)
def testable.check' (bound : ℕ := 100) : io bool := do
x ← io.run_rand (testable.run_suite p bound),
match x with
| (success _) := return tt
| (gave_up n) := io.put_str_ln ("Gave up " ++ repr n ++ " times") >> return ff
| (failure _ xs) := do
io.put_str_ln "\n===================",
io.put_str_ln "Found problems!",
io.put_str_ln "",
list.mmap' io.put_str_ln xs,
io.put_str_ln "-------------------",
return ff
end
end io
end slim_check
|
7a1bb24697da8552d59e8fb18e86312ad4d2cd0a | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/set_theory/surreal/basic.lean | 13d1fb908e27b915e02f09130e94e9240b81010d | [
"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 | 14,150 | lean | /-
Copyright (c) 2019 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Scott Morrison
-/
import algebra.order.hom.monoid
import set_theory.game.ordinal
/-!
# Surreal numbers
The basic theory of surreal numbers, built on top of the theory of combinatorial (pre-)games.
A pregame is `numeric` if all the Left options are strictly smaller than all the Right options, and
all those options are themselves numeric. In terms of combinatorial games, the numeric games have
"frozen"; you can only make your position worse by playing, and Left is some definite "number" of
moves ahead (or behind) Right.
A surreal number is an equivalence class of numeric pregames.
In fact, the surreals form a complete ordered field, containing a copy of the reals (and much else
besides!) but we do not yet have a complete development.
## Order properties
Surreal numbers inherit the relations `≤` and `<` from games (`surreal.has_le` and
`surreal.has_lt`), and these relations satisfy the axioms of a partial order.
## Algebraic operations
We show that the surreals form a linear ordered commutative group.
One can also map all the ordinals into the surreals!
### Multiplication of surreal numbers
The proof that multiplication lifts to surreal numbers is surprisingly difficult and is currently
missing in the library. A sample proof can be found in Theorem 3.8 in the second reference below.
The difficulty lies in the length of the proof and the number of theorems that need to proven
simultaneously. This will make for a fun and challenging project.
The branch `surreal_mul` contains some progress on this proof.
### Todo
- Define the field structure on the surreals.
## References
* [Conway, *On numbers and games*][conway2001]
* [Schleicher, Stoll, *An introduction to Conway's games and numbers*][schleicher_stoll]
-/
universes u
open_locale pgame
namespace pgame
/-- A pre-game is numeric if everything in the L set is less than everything in the R set,
and all the elements of L and R are also numeric. -/
def numeric : pgame → Prop
| ⟨l, r, L, R⟩ :=
(∀ i j, L i < R j) ∧ (∀ i, numeric (L i)) ∧ (∀ j, numeric (R j))
lemma numeric_def {x : pgame} : numeric x ↔ (∀ i j, x.move_left i < x.move_right j) ∧
(∀ i, numeric (x.move_left i)) ∧ (∀ j, numeric (x.move_right j)) :=
by { cases x, refl }
namespace numeric
lemma mk {x : pgame} (h₁ : ∀ i j, x.move_left i < x.move_right j)
(h₂ : ∀ i, numeric (x.move_left i)) (h₃ : ∀ j, numeric (x.move_right j)) : numeric x :=
numeric_def.2 ⟨h₁, h₂, h₃⟩
lemma left_lt_right {x : pgame} (o : numeric x) (i : x.left_moves) (j : x.right_moves) :
x.move_left i < x.move_right j :=
by { cases x, exact o.1 i j }
lemma move_left {x : pgame} (o : numeric x) (i : x.left_moves) :
numeric (x.move_left i) :=
by { cases x, exact o.2.1 i }
lemma move_right {x : pgame} (o : numeric x) (j : x.right_moves) :
numeric (x.move_right j) :=
by { cases x, exact o.2.2 j }
end numeric
@[elab_as_eliminator]
theorem numeric_rec {C : pgame → Prop}
(H : ∀ l r (L : l → pgame) (R : r → pgame),
(∀ i j, L i < R j) → (∀ i, numeric (L i)) → (∀ i, numeric (R i)) →
(∀ i, C (L i)) → (∀ i, C (R i)) → C ⟨l, r, L, R⟩) :
∀ x, numeric x → C x
| ⟨l, r, L, R⟩ ⟨h, hl, hr⟩ :=
H _ _ _ _ h hl hr (λ i, numeric_rec _ (hl i)) (λ i, numeric_rec _ (hr i))
theorem relabelling.numeric_imp {x y : pgame} (r : x ≡r y) (ox : numeric x) : numeric y :=
begin
induction x using pgame.move_rec_on with x IHl IHr generalizing y,
apply numeric.mk (λ i j, _) (λ i, _) (λ j, _),
{ rw ←lt_congr (r.move_left_symm i).equiv (r.move_right_symm j).equiv,
apply ox.left_lt_right },
{ exact IHl _ (ox.move_left _) (r.move_left_symm i) },
{ exact IHr _ (ox.move_right _) (r.move_right_symm j) }
end
/-- Relabellings preserve being numeric. -/
theorem relabelling.numeric_congr {x y : pgame} (r : x ≡r y) : numeric x ↔ numeric y :=
⟨r.numeric_imp, r.symm.numeric_imp⟩
theorem lf_asymm {x y : pgame} (ox : numeric x) (oy : numeric y) : x ⧏ y → ¬ y ⧏ x :=
begin
refine numeric_rec (λ xl xr xL xR hx oxl oxr IHxl IHxr, _) x ox y oy,
refine numeric_rec (λ yl yr yL yR hy oyl oyr IHyl IHyr, _),
rw [mk_lf_mk, mk_lf_mk], rintro (⟨i, h₁⟩ | ⟨j, h₁⟩) (⟨i, h₂⟩ | ⟨j, h₂⟩),
{ exact IHxl _ _ (oyl _) (h₁.move_left_lf _) (h₂.move_left_lf _) },
{ exact (le_trans h₂ h₁).not_gf (lf_of_lt (hy _ _)) },
{ exact (le_trans h₁ h₂).not_gf (lf_of_lt (hx _ _)) },
{ exact IHxr _ _ (oyr _) (h₁.lf_move_right _) (h₂.lf_move_right _) },
end
theorem le_of_lf {x y : pgame} (h : x ⧏ y) (ox : numeric x) (oy : numeric y) : x ≤ y :=
not_lf.1 (lf_asymm ox oy h)
alias le_of_lf ← lf.le
theorem lt_of_lf {x y : pgame} (h : x ⧏ y) (ox : numeric x) (oy : numeric y) : x < y :=
(lt_or_fuzzy_of_lf h).resolve_right (not_fuzzy_of_le (h.le ox oy))
alias lt_of_lf ← lf.lt
theorem lf_iff_lt {x y : pgame} (ox : numeric x) (oy : numeric y) : x ⧏ y ↔ x < y :=
⟨λ h, h.lt ox oy, lf_of_lt⟩
/-- Definition of `x ≤ y` on numeric pre-games, in terms of `<` -/
theorem le_iff_forall_lt {x y : pgame} (ox : x.numeric) (oy : y.numeric) :
x ≤ y ↔ (∀ i, x.move_left i < y) ∧ ∀ j, x < y.move_right j :=
begin
refine le_iff_forall_lf.trans (and_congr _ _);
refine forall_congr (λ i, lf_iff_lt _ _);
apply_rules [numeric.move_left, numeric.move_right]
end
/-- Definition of `x < y` on numeric pre-games, in terms of `≤` -/
theorem lt_iff_exists_le {x y : pgame} (ox : x.numeric) (oy : y.numeric) :
x < y ↔ (∃ i, x ≤ y.move_left i) ∨ ∃ j, x.move_right j ≤ y :=
by rw [←lf_iff_lt ox oy, lf_iff_exists_le]
theorem lt_of_exists_le {x y : pgame} (ox : x.numeric) (oy : y.numeric) :
((∃ i, x ≤ y.move_left i) ∨ ∃ j, x.move_right j ≤ y) → x < y :=
(lt_iff_exists_le ox oy).2
/-- The definition of `x < y` on numeric pre-games, in terms of `<` two moves later. -/
theorem lt_def {x y : pgame} (ox : x.numeric) (oy : y.numeric) : x < y ↔
(∃ i, (∀ i', x.move_left i' < y.move_left i) ∧ ∀ j, x < (y.move_left i).move_right j) ∨
∃ j, (∀ i, (x.move_right j).move_left i < y) ∧ ∀ j', x.move_right j < y.move_right j' :=
begin
rw [←lf_iff_lt ox oy, lf_def],
refine or_congr _ _;
refine exists_congr (λ x_1, _);
refine and_congr _ _;
refine (forall_congr $ λ i, lf_iff_lt _ _);
apply_rules [numeric.move_left, numeric.move_right]
end
theorem not_fuzzy {x y : pgame} (ox : numeric x) (oy : numeric y) : ¬ fuzzy x y :=
λ h, not_lf.2 ((lf_of_fuzzy h).le ox oy) h.2
theorem lt_or_equiv_or_gt {x y : pgame} (ox : numeric x) (oy : numeric y) : x < y ∨ x ≈ y ∨ y < x :=
(lf_or_equiv_or_gf x y).imp (λ h, h.lt ox oy) $ or.imp_right $ λ h, h.lt oy ox
theorem numeric_of_is_empty (x : pgame) [is_empty x.left_moves] [is_empty x.right_moves] :
numeric x :=
numeric.mk is_empty_elim is_empty_elim is_empty_elim
theorem numeric_of_is_empty_left_moves (x : pgame) [is_empty x.left_moves] :
(∀ j, numeric (x.move_right j)) → numeric x :=
numeric.mk is_empty_elim is_empty_elim
theorem numeric_of_is_empty_right_moves (x : pgame) [is_empty x.right_moves]
(H : ∀ i, numeric (x.move_left i)) : numeric x :=
numeric.mk (λ _, is_empty_elim) H is_empty_elim
theorem numeric_zero : numeric 0 := numeric_of_is_empty 0
theorem numeric_one : numeric 1 := numeric_of_is_empty_right_moves 1 $ λ _, numeric_zero
theorem numeric.neg : Π {x : pgame} (o : numeric x), numeric (-x)
| ⟨l, r, L, R⟩ o := ⟨λ j i, neg_lt_neg_iff.2 (o.1 i j), λ j, (o.2.2 j).neg, λ i, (o.2.1 i).neg⟩
namespace numeric
theorem move_left_lt {x : pgame} (o : numeric x) (i) : x.move_left i < x :=
(move_left_lf i).lt (o.move_left i) o
theorem move_left_le {x : pgame} (o : numeric x) (i) : x.move_left i ≤ x :=
(o.move_left_lt i).le
theorem lt_move_right {x : pgame} (o : numeric x) (j) : x < x.move_right j :=
(lf_move_right j).lt o (o.move_right j)
theorem le_move_right {x : pgame} (o : numeric x) (j) : x ≤ x.move_right j :=
(o.lt_move_right j).le
theorem add : Π {x y : pgame} (ox : numeric x) (oy : numeric y), numeric (x + y)
| ⟨xl, xr, xL, xR⟩ ⟨yl, yr, yL, yR⟩ ox oy :=
⟨begin
rintros (ix|iy) (jx|jy),
{ exact add_lt_add_right (ox.1 ix jx) _ },
{ exact (add_lf_add_of_lf_of_le (lf_mk _ _ ix) (oy.le_move_right jy)).lt
((ox.move_left ix).add oy) (ox.add (oy.move_right jy)) },
{ exact (add_lf_add_of_lf_of_le (mk_lf _ _ jx) (oy.move_left_le iy)).lt
(ox.add (oy.move_left iy)) ((ox.move_right jx).add oy) },
{ exact add_lt_add_left (oy.1 iy jy) ⟨xl, xr, xL, xR⟩ }
end,
begin
split,
{ rintros (ix|iy),
{ exact (ox.move_left ix).add oy },
{ exact ox.add (oy.move_left iy) } },
{ rintros (jx|jy),
{ apply (ox.move_right jx).add oy },
{ apply ox.add (oy.move_right jy) } }
end⟩
using_well_founded { dec_tac := pgame_wf_tac }
lemma sub {x y : pgame} (ox : numeric x) (oy : numeric y) : numeric (x - y) := ox.add oy.neg
end numeric
/-- Pre-games defined by natural numbers are numeric. -/
theorem numeric_nat : Π (n : ℕ), numeric n
| 0 := numeric_zero
| (n + 1) := (numeric_nat n).add numeric_one
/-- Ordinal games are numeric. -/
theorem numeric_to_pgame (o : ordinal) : o.to_pgame.numeric :=
begin
induction o using ordinal.induction with o IH,
apply numeric_of_is_empty_right_moves,
simpa using λ i, IH _ (ordinal.to_left_moves_to_pgame_symm_lt i)
end
end pgame
open pgame
/-- The type of surreal numbers. These are the numeric pre-games quotiented
by the equivalence relation `x ≈ y ↔ x ≤ y ∧ y ≤ x`. In the quotient,
the order becomes a total order. -/
def surreal := quotient (subtype.setoid numeric)
namespace surreal
/-- Construct a surreal number from a numeric pre-game. -/
def mk (x : pgame) (h : x.numeric) : surreal := ⟦⟨x, h⟩⟧
instance : has_zero surreal := ⟨mk 0 numeric_zero⟩
instance : has_one surreal := ⟨mk 1 numeric_one⟩
instance : inhabited surreal := ⟨0⟩
/-- Lift an equivalence-respecting function on pre-games to surreals. -/
def lift {α} (f : ∀ x, numeric x → α)
(H : ∀ {x y} (hx : numeric x) (hy : numeric y), x.equiv y → f x hx = f y hy) : surreal → α :=
quotient.lift (λ x : {x // numeric x}, f x.1 x.2) (λ x y, H x.2 y.2)
/-- Lift a binary equivalence-respecting function on pre-games to surreals. -/
def lift₂ {α} (f : ∀ x y, numeric x → numeric y → α)
(H : ∀ {x₁ y₁ x₂ y₂} (ox₁ : numeric x₁) (oy₁ : numeric y₁) (ox₂ : numeric x₂) (oy₂ : numeric y₂),
x₁.equiv x₂ → y₁.equiv y₂ → f x₁ y₁ ox₁ oy₁ = f x₂ y₂ ox₂ oy₂) : surreal → surreal → α :=
lift (λ x ox, lift (λ y oy, f x y ox oy) (λ y₁ y₂ oy₁ oy₂, H _ _ _ _ equiv_rfl))
(λ x₁ x₂ ox₁ ox₂ h, funext $ quotient.ind $ by exact λ ⟨y, oy⟩, H _ _ _ _ h equiv_rfl)
instance : has_le surreal :=
⟨lift₂ (λ x y _ _, x ≤ y) (λ x₁ y₁ x₂ y₂ _ _ _ _ hx hy, propext (le_congr hx hy))⟩
instance : has_lt surreal :=
⟨lift₂ (λ x y _ _, x < y) (λ x₁ y₁ x₂ y₂ _ _ _ _ hx hy, propext (lt_congr hx hy))⟩
/-- Addition on surreals is inherited from pre-game addition:
the sum of `x = {xL | xR}` and `y = {yL | yR}` is `{xL + y, x + yL | xR + y, x + yR}`. -/
instance : has_add surreal :=
⟨surreal.lift₂
(λ (x y : pgame) (ox) (oy), ⟦⟨x + y, ox.add oy⟩⟧)
(λ x₁ y₁ x₂ y₂ _ _ _ _ hx hy, quotient.sound (add_congr hx hy))⟩
/-- Negation for surreal numbers is inherited from pre-game negation:
the negation of `{L | R}` is `{-R | -L}`. -/
instance : has_neg surreal :=
⟨surreal.lift
(λ x ox, ⟦⟨-x, ox.neg⟩⟧)
(λ _ _ _ _ a, quotient.sound (neg_equiv_neg_iff.2 a))⟩
instance : ordered_add_comm_group surreal :=
{ add := (+),
add_assoc := by { rintros ⟨_⟩ ⟨_⟩ ⟨_⟩, exact quotient.sound add_assoc_equiv },
zero := 0,
zero_add := by { rintros ⟨_⟩, exact quotient.sound (zero_add_equiv a) },
add_zero := by { rintros ⟨_⟩, exact quotient.sound (add_zero_equiv a) },
neg := has_neg.neg,
add_left_neg := by { rintros ⟨_⟩, exact quotient.sound (add_left_neg_equiv a) },
add_comm := by { rintros ⟨_⟩ ⟨_⟩, exact quotient.sound add_comm_equiv },
le := (≤),
lt := (<),
le_refl := by { rintros ⟨_⟩, apply @le_rfl pgame },
le_trans := by { rintros ⟨_⟩ ⟨_⟩ ⟨_⟩, apply @le_trans pgame },
lt_iff_le_not_le := by { rintros ⟨_, ox⟩ ⟨_, oy⟩, apply @lt_iff_le_not_le pgame },
le_antisymm := by { rintros ⟨_⟩ ⟨_⟩ h₁ h₂, exact quotient.sound ⟨h₁, h₂⟩ },
add_le_add_left := by { rintros ⟨_⟩ ⟨_⟩ hx ⟨_⟩, exact @add_le_add_left pgame _ _ _ _ _ hx _ } }
noncomputable instance : linear_ordered_add_comm_group surreal :=
{ le_total := by rintro ⟨⟨x, ox⟩⟩ ⟨⟨y, oy⟩⟩; classical; exact
or_iff_not_imp_left.2 (λ h, (pgame.not_le.1 h).le oy ox),
decidable_le := classical.dec_rel _,
..surreal.ordered_add_comm_group }
instance : add_monoid_with_one surreal := add_monoid_with_one.unary
/-- Casts a `surreal` number into a `game`. -/
def to_game : surreal →+o game :=
{ to_fun := lift (λ x _, ⟦x⟧) (λ x y ox oy, quot.sound),
map_zero' := rfl,
map_add' := by { rintros ⟨_, _⟩ ⟨_, _⟩, refl },
monotone' := by { rintros ⟨_, _⟩ ⟨_, _⟩, exact id } }
theorem zero_to_game : to_game 0 = 0 := rfl
@[simp] theorem one_to_game : to_game 1 = 1 := rfl
@[simp] theorem nat_to_game : ∀ n : ℕ, to_game n = n := map_nat_cast' _ one_to_game
end surreal
open surreal
namespace ordinal
/-- Converts an ordinal into the corresponding surreal. -/
noncomputable def to_surreal : ordinal ↪o surreal :=
{ to_fun := λ o, mk _ (numeric_to_pgame o),
inj' := λ a b h, to_pgame_equiv_iff.1 (quotient.exact h),
map_rel_iff' := @to_pgame_le_iff }
end ordinal
|
abe062d67b97f21226b146d9b90df22f5e749f3f | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/topology/extremally_disconnected.lean | c5796de9c98d7e25f19f6c32fcc2052ee8535f5a | [
"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 | 4,607 | lean | /-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import topology.stone_cech
/-!
# Extremally disconnected spaces
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
An extremally disconnected topological space is a space in which the closure of every open set is
open. Such spaces are also called Stonean spaces. They are the projective objects in the category of
compact Hausdorff spaces.
## Main declarations
* `extremally_disconnected`: Predicate for a space to be extremally disconnected.
* `compact_t2.projective`: ¨Predicate for a topological space to be a projective object in the
category of compact Hausdorff spaces.
* `compact_t2.projective.extremally_disconnected`: Compact Hausdorff spaces that are
projective are extremally disconnected.
# TODO
Prove the converse to `compact_t2.projective.extremally_disconnected`, namely that a compact,
Hausdorff, extremally disconnected space is a projective object in the category of compact Hausdorff
spaces.
## References
[Gleason, *Projective topological spaces*][gleason1958]
-/
noncomputable theory
open set
open_locale classical
universes u v w
variables (X : Type u) [topological_space X]
open function
/-- An extremally disconnected topological space is a space
in which the closure of every open set is open. -/
class extremally_disconnected : Prop :=
(open_closure : ∀ U : set X, is_open U → is_open (closure U))
section
include X
/-- The assertion `compact_t2.projective` states that given continuous maps
`f : X → Z` and `g : Y → Z` with `g` surjective between `t_2`, compact topological spaces,
there exists a continuous lift `h : X → Y`, such that `f = g ∘ h`. -/
def compact_t2.projective : Prop :=
Π {Y Z : Type u} [topological_space Y] [topological_space Z],
by exactI Π [compact_space Y] [t2_space Y] [compact_space Z] [t2_space Z],
Π {f : X → Z} {g : Y → Z} (hf : continuous f) (hg : continuous g) (g_sur : surjective g),
∃ h : X → Y, continuous h ∧ g ∘ h = f
end
variable {X}
lemma stone_cech.projective [discrete_topology X] : compact_t2.projective (stone_cech X) :=
begin
introsI Y Z _tsY _tsZ _csY _t2Y _csZ _csZ f g hf hg g_sur,
let s : Z → Y := λ z, classical.some $ g_sur z,
have hs : g ∘ s = id := funext (λ z, classical.some_spec (g_sur z)),
let t := s ∘ f ∘ stone_cech_unit,
have ht : continuous t := continuous_of_discrete_topology,
let h : stone_cech X → Y := stone_cech_extend ht,
have hh : continuous h := continuous_stone_cech_extend ht,
refine ⟨h, hh, dense_range_stone_cech_unit.equalizer (hg.comp hh) hf _⟩,
rw [comp.assoc, stone_cech_extend_extends ht, ← comp.assoc, hs, comp.left_id],
end
protected lemma compact_t2.projective.extremally_disconnected [compact_space X] [t2_space X]
(h : compact_t2.projective X) :
extremally_disconnected X :=
begin
refine { open_closure := λ U hU, _ },
let Z₁ : set (X × bool) := Uᶜ ×ˢ {tt},
let Z₂ : set (X × bool) := closure U ×ˢ {ff},
let Z : set (X × bool) := Z₁ ∪ Z₂,
have hZ₁₂ : disjoint Z₁ Z₂ := disjoint_left.2 (λ x hx₁ hx₂, by cases hx₁.2.symm.trans hx₂.2),
have hZ₁ : is_closed Z₁ := hU.is_closed_compl.prod (t1_space.t1 _),
have hZ₂ : is_closed Z₂ := is_closed_closure.prod (t1_space.t1 ff),
have hZ : is_closed Z := hZ₁.union hZ₂,
let f : Z → X := prod.fst ∘ subtype.val,
have f_cont : continuous f := continuous_fst.comp continuous_subtype_val,
have f_sur : surjective f,
{ intro x,
by_cases hx : x ∈ U,
{ exact ⟨⟨(x, ff), or.inr ⟨subset_closure hx, set.mem_singleton _⟩⟩, rfl⟩ },
{ exact ⟨⟨(x, tt), or.inl ⟨hx, set.mem_singleton _⟩⟩, rfl⟩ } },
haveI : compact_space Z := is_compact_iff_compact_space.mp hZ.is_compact,
obtain ⟨g, hg, g_sec⟩ := h continuous_id f_cont f_sur,
let φ := coe ∘ g,
have hφ : continuous φ := continuous_subtype_val.comp hg,
have hφ₁ : ∀ x, (φ x).1 = x := congr_fun g_sec,
suffices : closure U = φ ⁻¹' Z₂,
{ rw [this, set.preimage_comp, ←is_closed_compl_iff, ←preimage_compl,
←preimage_subtype_coe_eq_compl subset.rfl],
{ exact hZ₁.preimage hφ },
{ rw [hZ₁₂.inter_eq, inter_empty] } },
refine (closure_minimal _ $ hZ₂.preimage hφ).antisymm (λ x hx, _),
{ rintro x hx,
have : φ x ∈ (Z₁ ∪ Z₂) := (g x).2,
simpa [hx, hφ₁] using this },
{ rw ←hφ₁ x,
exact hx.1 }
end
|
2793c5f6acebe48c80b69fb165c8644cb52b8a96 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/combinatorics/additive/salem_spencer.lean | ed7ef2febd22b1be825f64fbea0f325d5216faad | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 18,045 | lean | /-
Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import algebra.hom.freiman
import analysis.asymptotics.asymptotics
import analysis.convex.strict_convex_space
/-!
# Salem-Spencer sets and Roth numbers
This file defines Salem-Spencer sets and the Roth number of a set.
A Salem-Spencer set is a set without arithmetic progressions of length `3`. Equivalently, the
average of any two distinct elements is not in the set.
The Roth number of a finset is the size of its biggest Salem-Spencer subset. This is a more general
definition than the one often found in mathematical litterature, where the `n`-th Roth number is
the size of the biggest Salem-Spencer subset of `{0, ..., n - 1}`.
## Main declarations
* `mul_salem_spencer`: Predicate for a set to be multiplicative Salem-Spencer.
* `add_salem_spencer`: Predicate for a set to be additive Salem-Spencer.
* `mul_roth_number`: The multiplicative Roth number of a finset.
* `add_roth_number`: The additive Roth number of a finset.
* `roth_number_nat`: The Roth number of a natural. This corresponds to
`add_roth_number (finset.range n)`.
## TODO
* Can `add_salem_spencer_iff_eq_right` be made more general?
* Generalize `mul_salem_spencer.image` to Freiman homs
## Tags
Salem-Spencer, Roth, arithmetic progression, average, three-free
-/
open finset function metric nat
open_locale pointwise
variables {F α β 𝕜 E : Type*}
section salem_spencer
open set
section monoid
variables [monoid α] [monoid β] (s t : set α)
/-- A multiplicative Salem-Spencer, aka non averaging, set `s` in a monoid is a set such that the
multiplicative average of any two distinct elements is not in the set. -/
@[to_additive "A Salem-Spencer, aka non averaging, set `s` in an additive monoid
is a set such that the average of any two distinct elements is not in the set."]
def mul_salem_spencer : Prop := ∀ ⦃a b c⦄, a ∈ s → b ∈ s → c ∈ s → a * b = c * c → a = b
/-- Whether a given finset is Salem-Spencer is decidable. -/
@[to_additive "Whether a given finset is Salem-Spencer is decidable."]
instance {α : Type*} [decidable_eq α] [monoid α] {s : finset α} :
decidable (mul_salem_spencer (s : set α)) :=
decidable_of_iff (∀ a ∈ s, ∀ b ∈ s, ∀ c ∈ s, a * b = c * c → a = b)
⟨λ h a b c ha hb hc, h a ha b hb c hc, λ h a ha b hb c hc, h ha hb hc⟩
variables {s t}
@[to_additive]
lemma mul_salem_spencer.mono (h : t ⊆ s) (hs : mul_salem_spencer s) : mul_salem_spencer t :=
λ a b c ha hb hc, hs (h ha) (h hb) (h hc)
@[simp, to_additive]
lemma mul_salem_spencer_empty : mul_salem_spencer (∅ : set α) := λ a _ _ ha, ha.elim
@[to_additive]
lemma set.subsingleton.mul_salem_spencer (hs : s.subsingleton) : mul_salem_spencer s :=
λ a b _ ha hb _ _, hs ha hb
@[simp, to_additive]
lemma mul_salem_spencer_singleton (a : α) : mul_salem_spencer ({a} : set α) :=
subsingleton_singleton.mul_salem_spencer
@[to_additive add_salem_spencer.prod]
lemma mul_salem_spencer.prod {t : set β} (hs : mul_salem_spencer s) (ht : mul_salem_spencer t) :
mul_salem_spencer (s ×ˢ t) :=
λ a b c ha hb hc h,
prod.ext (hs ha.1 hb.1 hc.1 (prod.ext_iff.1 h).1) (ht ha.2 hb.2 hc.2 (prod.ext_iff.1 h).2)
@[to_additive]
lemma mul_salem_spencer_pi {ι : Type*} {α : ι → Type*} [Π i, monoid (α i)] {s : Π i, set (α i)}
(hs : ∀ i, mul_salem_spencer (s i)) :
mul_salem_spencer ((univ : set ι).pi s) :=
λ a b c ha hb hc h, funext $ λ i, hs i (ha i trivial) (hb i trivial) (hc i trivial) $ congr_fun h i
end monoid
section comm_monoid
variables [comm_monoid α] [comm_monoid β] {s : set α} {a : α}
@[to_additive]
lemma mul_salem_spencer.of_image [fun_like F α (λ _, β)] [freiman_hom_class F s β 2] (f : F)
(hf : s.inj_on f) (h : mul_salem_spencer (f '' s)) :
mul_salem_spencer s :=
λ a b c ha hb hc habc, hf ha hb $ h (mem_image_of_mem _ ha) (mem_image_of_mem _ hb)
(mem_image_of_mem _ hc) $ map_mul_map_eq_map_mul_map f ha hb hc hc habc
-- TODO: Generalize to Freiman homs
@[to_additive]
lemma mul_salem_spencer.image [mul_hom_class F α β] (f : F) (hf : (s * s).inj_on f)
(h : mul_salem_spencer s) :
mul_salem_spencer (f '' s) :=
begin
rintro _ _ _ ⟨a, ha, rfl⟩ ⟨b, hb, rfl⟩ ⟨c, hc, rfl⟩ habc,
rw h ha hb hc (hf (mul_mem_mul ha hb) (mul_mem_mul hc hc) $ by rwa [map_mul, map_mul]),
end
end comm_monoid
section cancel_comm_monoid
variables [cancel_comm_monoid α] {s : set α} {a : α}
@[to_additive]
lemma mul_salem_spencer_insert :
mul_salem_spencer (insert a s) ↔ mul_salem_spencer s ∧
(∀ ⦃b c⦄, b ∈ s → c ∈ s → a * b = c * c → a = b) ∧
∀ ⦃b c⦄, b ∈ s → c ∈ s → b * c = a * a → b = c :=
begin
refine ⟨λ hs, ⟨hs.mono (subset_insert _ _),
λ b c hb hc, hs (or.inl rfl) (or.inr hb) (or.inr hc),
λ b c hb hc, hs (or.inr hb) (or.inr hc) (or.inl rfl)⟩, _⟩,
rintro ⟨hs, ha, ha'⟩ b c d hb hc hd h,
rw mem_insert_iff at hb hc hd,
obtain rfl | hb := hb;
obtain rfl | hc := hc,
{ refl },
all_goals { obtain rfl | hd := hd },
{ exact (mul_left_cancel h).symm },
{ exact ha hc hd h },
{ exact mul_right_cancel h },
{ exact (ha hb hd $ (mul_comm _ _).trans h).symm },
{ exact ha' hb hc h },
{ exact hs hb hc hd h }
end
@[simp, to_additive]
lemma mul_salem_spencer_pair (a b : α) : mul_salem_spencer ({a, b} : set α) :=
begin
rw mul_salem_spencer_insert,
refine ⟨mul_salem_spencer_singleton _, _, _⟩,
{ rintro c d (rfl : c = b) (rfl : d = c),
exact mul_right_cancel },
{ rintro c d (rfl : c = b) (rfl : d = c) _,
refl }
end
@[to_additive]
lemma mul_salem_spencer.mul_left (hs : mul_salem_spencer s) : mul_salem_spencer ((*) a '' s) :=
begin
rintro _ _ _ ⟨b, hb, rfl⟩ ⟨c, hc, rfl⟩ ⟨d, hd, rfl⟩ h,
rw [mul_mul_mul_comm, mul_mul_mul_comm a d] at h,
rw hs hb hc hd (mul_left_cancel h),
end
@[to_additive]
lemma mul_salem_spencer.mul_right (hs : mul_salem_spencer s) : mul_salem_spencer ((* a) '' s) :=
begin
rintro _ _ _ ⟨b, hb, rfl⟩ ⟨c, hc, rfl⟩ ⟨d, hd, rfl⟩ h,
rw [mul_mul_mul_comm, mul_mul_mul_comm d] at h,
rw hs hb hc hd (mul_right_cancel h),
end
@[to_additive]
lemma mul_salem_spencer_mul_left_iff : mul_salem_spencer ((*) a '' s) ↔ mul_salem_spencer s :=
⟨λ hs b c d hb hc hd h, mul_left_cancel (hs (mem_image_of_mem _ hb) (mem_image_of_mem _ hc)
(mem_image_of_mem _ hd) $ by rw [mul_mul_mul_comm, h, mul_mul_mul_comm]),
mul_salem_spencer.mul_left⟩
@[to_additive]
lemma mul_salem_spencer_mul_right_iff :
mul_salem_spencer ((* a) '' s) ↔ mul_salem_spencer s :=
⟨λ hs b c d hb hc hd h, mul_right_cancel (hs (set.mem_image_of_mem _ hb) (set.mem_image_of_mem _ hc)
(set.mem_image_of_mem _ hd) $ by rw [mul_mul_mul_comm, h, mul_mul_mul_comm]),
mul_salem_spencer.mul_right⟩
end cancel_comm_monoid
section ordered_cancel_comm_monoid
variables [ordered_cancel_comm_monoid α] {s : set α} {a : α}
@[to_additive]
lemma mul_salem_spencer_insert_of_lt (hs : ∀ i ∈ s, i < a) :
mul_salem_spencer (insert a s) ↔ mul_salem_spencer s ∧
∀ ⦃b c⦄, b ∈ s → c ∈ s → a * b = c * c → a = b :=
begin
refine mul_salem_spencer_insert.trans _,
rw ←and_assoc,
exact and_iff_left (λ b c hb hc h, ((mul_lt_mul_of_lt_of_lt (hs _ hb) (hs _ hc)).ne h).elim),
end
end ordered_cancel_comm_monoid
section cancel_comm_monoid_with_zero
variables [cancel_comm_monoid_with_zero α] [no_zero_divisors α] {s : set α} {a : α}
lemma mul_salem_spencer.mul_left₀ (hs : mul_salem_spencer s) (ha : a ≠ 0) :
mul_salem_spencer ((*) a '' s) :=
begin
rintro _ _ _ ⟨b, hb, rfl⟩ ⟨c, hc, rfl⟩ ⟨d, hd, rfl⟩ h,
rw [mul_mul_mul_comm, mul_mul_mul_comm a d] at h,
rw hs hb hc hd (mul_left_cancel₀ (mul_ne_zero ha ha) h),
end
lemma mul_salem_spencer.mul_right₀ (hs : mul_salem_spencer s) (ha : a ≠ 0) :
mul_salem_spencer ((* a) '' s) :=
begin
rintro _ _ _ ⟨b, hb, rfl⟩ ⟨c, hc, rfl⟩ ⟨d, hd, rfl⟩ h,
rw [mul_mul_mul_comm, mul_mul_mul_comm d] at h,
rw hs hb hc hd (mul_right_cancel₀ (mul_ne_zero ha ha) h),
end
lemma mul_salem_spencer_mul_left_iff₀ (ha : a ≠ 0) :
mul_salem_spencer ((*) a '' s) ↔ mul_salem_spencer s :=
⟨λ hs b c d hb hc hd h, mul_left_cancel₀ ha
(hs (set.mem_image_of_mem _ hb) (set.mem_image_of_mem _ hc) (set.mem_image_of_mem _ hd) $
by rw [mul_mul_mul_comm, h, mul_mul_mul_comm]),
λ hs, hs.mul_left₀ ha⟩
lemma mul_salem_spencer_mul_right_iff₀ (ha : a ≠ 0) :
mul_salem_spencer ((* a) '' s) ↔ mul_salem_spencer s :=
⟨λ hs b c d hb hc hd h, mul_right_cancel₀ ha
(hs (set.mem_image_of_mem _ hb) (set.mem_image_of_mem _ hc) (set.mem_image_of_mem _ hd) $
by rw [mul_mul_mul_comm, h, mul_mul_mul_comm]),
λ hs, hs.mul_right₀ ha⟩
end cancel_comm_monoid_with_zero
section nat
lemma add_salem_spencer_iff_eq_right {s : set ℕ} :
add_salem_spencer s ↔ ∀ ⦃a b c⦄, a ∈ s → b ∈ s → c ∈ s → a + b = c + c → a = c :=
begin
refine forall₄_congr (λ a b c _, forall₃_congr $ λ _ _ habc, ⟨_, _⟩),
{ rintro rfl,
simp_rw ←two_mul at habc,
exact mul_left_cancel₀ two_ne_zero habc },
{ rintro rfl,
exact (add_left_cancel habc).symm }
end
end nat
/-- The frontier of a closed strictly convex set only contains trivial arithmetic progressions.
The idea is that an arithmetic progression is contained on a line and the frontier of a strictly
convex set does not contain lines. -/
lemma add_salem_spencer_frontier [linear_ordered_field 𝕜] [topological_space E] [add_comm_monoid E]
[module 𝕜 E] {s : set E} (hs₀ : is_closed s) (hs₁ : strict_convex 𝕜 s) :
add_salem_spencer (frontier s) :=
begin
intros a b c ha hb hc habc,
obtain rfl : (1 / 2 : 𝕜) • a + (1 / 2 : 𝕜) • b = c,
{ rwa [←smul_add, one_div, inv_smul_eq_iff₀ (show (2 : 𝕜) ≠ 0, by norm_num), two_smul] },
exact hs₁.eq (hs₀.frontier_subset ha) (hs₀.frontier_subset hb) one_half_pos one_half_pos
(add_halves _) hc.2,
end
lemma add_salem_spencer_sphere [normed_add_comm_group E] [normed_space ℝ E]
[strict_convex_space ℝ E] (x : E) (r : ℝ) : add_salem_spencer (sphere x r) :=
begin
obtain rfl | hr := eq_or_ne r 0,
{ rw sphere_zero,
exact add_salem_spencer_singleton _ },
{ convert add_salem_spencer_frontier is_closed_ball (strict_convex_closed_ball ℝ x r),
exact (frontier_closed_ball _ hr).symm }
end
end salem_spencer
open finset
section roth_number
variables [decidable_eq α]
section monoid
variables [monoid α] [decidable_eq β] [monoid β] (s t : finset α)
/-- The multiplicative Roth number of a finset is the cardinality of its biggest multiplicative
Salem-Spencer subset. -/
@[to_additive "The additive Roth number of a finset is the cardinality of its biggest additive
Salem-Spencer subset. The usual Roth number corresponds to `add_roth_number (finset.range n)`, see
`roth_number_nat`. "]
def mul_roth_number : finset α →o ℕ :=
⟨λ s, nat.find_greatest (λ m, ∃ t ⊆ s, t.card = m ∧ mul_salem_spencer (t : set α)) s.card,
begin
rintro t u htu,
refine nat.find_greatest_mono (λ m, _) (card_le_of_subset htu),
rintro ⟨v, hvt, hv⟩,
exact ⟨v, hvt.trans htu, hv⟩,
end⟩
@[to_additive]
lemma mul_roth_number_le : mul_roth_number s ≤ s.card := by convert nat.find_greatest_le s.card
@[to_additive]
lemma mul_roth_number_spec : ∃ t ⊆ s, t.card = mul_roth_number s ∧ mul_salem_spencer (t : set α) :=
@nat.find_greatest_spec _ (λ m, ∃ t ⊆ s, t.card = m ∧ mul_salem_spencer (t : set α)) _ _
(nat.zero_le _) ⟨∅, empty_subset _, card_empty, mul_salem_spencer_empty⟩
variables {s t} {n : ℕ}
@[to_additive]
lemma mul_salem_spencer.le_mul_roth_number (hs : mul_salem_spencer (s : set α)) (h : s ⊆ t) :
s.card ≤ mul_roth_number t :=
le_find_greatest (card_le_of_subset h) ⟨s, h, rfl, hs⟩
@[to_additive]
lemma mul_salem_spencer.roth_number_eq (hs : mul_salem_spencer (s : set α)) :
mul_roth_number s = s.card :=
(mul_roth_number_le _).antisymm $ hs.le_mul_roth_number $ subset.refl _
@[simp, to_additive]
lemma mul_roth_number_empty : mul_roth_number (∅ : finset α) = 0 :=
nat.eq_zero_of_le_zero $ (mul_roth_number_le _).trans card_empty.le
@[simp, to_additive]
lemma mul_roth_number_singleton (a : α) : mul_roth_number ({a} : finset α) = 1 :=
begin
convert mul_salem_spencer.roth_number_eq _,
rw coe_singleton,
exact mul_salem_spencer_singleton a,
end
@[to_additive]
lemma mul_roth_number_union_le (s t : finset α) :
mul_roth_number (s ∪ t) ≤ mul_roth_number s + mul_roth_number t :=
let ⟨u, hus, hcard, hu⟩ := mul_roth_number_spec (s ∪ t) in
calc
mul_roth_number (s ∪ t)
= u.card : hcard.symm
... = (u ∩ s ∪ u ∩ t).card
: by rw [←inter_distrib_left, (inter_eq_left_iff_subset _ _).2 hus]
... ≤ (u ∩ s).card + (u ∩ t).card : card_union_le _ _
... ≤ mul_roth_number s + mul_roth_number t
: add_le_add ((hu.mono $ inter_subset_left _ _).le_mul_roth_number $ inter_subset_right _ _)
((hu.mono $ inter_subset_left _ _).le_mul_roth_number $ inter_subset_right _ _)
@[to_additive]
lemma le_mul_roth_number_product (s : finset α) (t : finset β) :
mul_roth_number s * mul_roth_number t ≤ mul_roth_number (s ×ˢ t) :=
begin
obtain ⟨u, hus, hucard, hu⟩ := mul_roth_number_spec s,
obtain ⟨v, hvt, hvcard, hv⟩ := mul_roth_number_spec t,
rw [←hucard, ←hvcard, ←card_product],
refine mul_salem_spencer.le_mul_roth_number _ (product_subset_product hus hvt),
rw coe_product,
exact hu.prod hv,
end
@[to_additive]
lemma mul_roth_number_lt_of_forall_not_mul_salem_spencer
(h : ∀ t ∈ powerset_len n s, ¬mul_salem_spencer ((t : finset α) : set α)) :
mul_roth_number s < n :=
begin
obtain ⟨t, hts, hcard, ht⟩ := mul_roth_number_spec s,
rw [←hcard, ←not_le],
intro hn,
obtain ⟨u, hut, rfl⟩ := exists_smaller_set t n hn,
exact h _ (mem_powerset_len.2 ⟨hut.trans hts, rfl⟩) (ht.mono hut),
end
end monoid
section cancel_comm_monoid
variables [cancel_comm_monoid α] (s : finset α) (a : α)
@[simp, to_additive] lemma mul_roth_number_map_mul_left :
mul_roth_number (s.map $ mul_left_embedding a) = mul_roth_number s :=
begin
refine le_antisymm _ _,
{ obtain ⟨u, hus, hcard, hu⟩ := mul_roth_number_spec (s.map $ mul_left_embedding a),
rw subset_map_iff at hus,
obtain ⟨u, hus, rfl⟩ := hus,
rw coe_map at hu,
rw [←hcard, card_map],
exact (mul_salem_spencer_mul_left_iff.1 hu).le_mul_roth_number hus },
{ obtain ⟨u, hus, hcard, hu⟩ := mul_roth_number_spec s,
have h : mul_salem_spencer (u.map $ mul_left_embedding a : set α),
{ rw coe_map,
exact hu.mul_left },
convert h.le_mul_roth_number (map_subset_map.2 hus),
rw [card_map, hcard] }
end
@[simp, to_additive] lemma mul_roth_number_map_mul_right :
mul_roth_number (s.map $ mul_right_embedding a) = mul_roth_number s :=
by rw [←mul_left_embedding_eq_mul_right_embedding, mul_roth_number_map_mul_left s a]
end cancel_comm_monoid
end roth_number
section roth_number_nat
variables {s : finset ℕ} {k n : ℕ}
/-- The Roth number of a natural `N` is the largest integer `m` for which there is a subset of
`range N` of size `m` with no arithmetic progression of length 3.
Trivially, `roth_number_nat N ≤ N`, but Roth's theorem (proved in 1953) shows that
`roth_number_nat N = o(N)` and the construction by Behrend gives a lower bound of the form
`N * exp(-C sqrt(log(N))) ≤ roth_number_nat N`.
A significant refinement of Roth's theorem by Bloom and Sisask announced in 2020 gives
`roth_number_nat N = O(N / (log N)^(1+c))` for an absolute constant `c`. -/
def roth_number_nat : ℕ →o ℕ :=
⟨λ n, add_roth_number (range n), add_roth_number.mono.comp range_mono⟩
lemma roth_number_nat_def (n : ℕ) : roth_number_nat n = add_roth_number (range n) := rfl
lemma roth_number_nat_le (N : ℕ) : roth_number_nat N ≤ N :=
(add_roth_number_le _).trans (card_range _).le
lemma roth_number_nat_spec (n : ℕ) :
∃ t ⊆ range n, t.card = roth_number_nat n ∧ add_salem_spencer (t : set ℕ) :=
add_roth_number_spec _
/-- A verbose specialization of `add_salem_spencer.le_add_roth_number`, sometimes convenient in
practice. -/
lemma add_salem_spencer.le_roth_number_nat (s : finset ℕ) (hs : add_salem_spencer (s : set ℕ))
(hsn : ∀ x ∈ s, x < n) (hsk : s.card = k) :
k ≤ roth_number_nat n :=
hsk.ge.trans $ hs.le_add_roth_number $ λ x hx, mem_range.2 $ hsn x hx
/-- The Roth number is a subadditive function. Note that by Fekete's lemma this shows that
the limit `roth_number_nat N / N` exists, but Roth's theorem gives the stronger result that this
limit is actually `0`. -/
lemma roth_number_nat_add_le (M N : ℕ) :
roth_number_nat (M + N) ≤ roth_number_nat M + roth_number_nat N :=
begin
simp_rw roth_number_nat_def,
rw [range_add_eq_union, ←add_roth_number_map_add_left (range N) M],
exact add_roth_number_union_le _ _,
end
@[simp] lemma roth_number_nat_zero : roth_number_nat 0 = 0 := rfl
lemma add_roth_number_Ico (a b : ℕ) : add_roth_number (Ico a b) = roth_number_nat (b - a) :=
begin
obtain h | h := le_total b a,
{ rw [tsub_eq_zero_of_le h, Ico_eq_empty_of_le h, roth_number_nat_zero, add_roth_number_empty] },
convert add_roth_number_map_add_left _ a,
rw [range_eq_Ico, map_eq_image],
convert (image_add_left_Ico 0 (b - a) _).symm,
exact (add_tsub_cancel_of_le h).symm,
end
open asymptotics filter
lemma roth_number_nat_is_O_with_id :
is_O_with 1 at_top (λ N, (roth_number_nat N : ℝ)) (λ N, (N : ℝ)) :=
is_O_with_of_le _ $ by simpa only [real.norm_coe_nat, nat.cast_le] using roth_number_nat_le
/-- The Roth number has the trivial bound `roth_number_nat N = O(N)`. -/
lemma roth_number_nat_is_O_id : (λ N, (roth_number_nat N : ℝ)) =O[at_top] (λ N, (N : ℝ)) :=
roth_number_nat_is_O_with_id.is_O
end roth_number_nat
|
26b13f2ed7e415e38fe34ece36923d0ab7a8494d | 4c630d016e43ace8c5f476a5070a471130c8a411 | /linear_algebra/submodule.lean | 39c5ec8164f8327147b2a8e73939b6d53b4f816a | [
"Apache-2.0"
] | permissive | ngamt/mathlib | 9a510c391694dc43eec969914e2a0e20b272d172 | 58909bd424209739a2214961eefaa012fb8a18d2 | refs/heads/master | 1,585,942,993,674 | 1,540,739,585,000 | 1,540,916,815,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,977 | lean | /-
Copyright (c) 2018 Mario Carneiro and Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro and Kevin Buzzard
-/
import order.order_iso
import tactic.tidy
import linear_algebra.subtype_module
import linear_algebra.quotient_module
import linear_algebra.prod_module
local attribute [instance] classical.dec
open lattice function set
structure {u v} submodule (α : Type u) (β : Type v) [ring α] [module α β] : Type v :=
(carrier : set β)
(to_is_submodule : is_submodule carrier)
namespace submodule
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} [ring α] [module α β] [module α γ] [module α δ]
include α
instance : has_coe (submodule α β) (set β) := ⟨submodule.carrier⟩
instance (s : submodule α β) : is_submodule (s : set β) := submodule.to_is_submodule _
instance : has_mem β (submodule α β) := ⟨λ x y, x ∈ (y : set β)⟩
@[simp] theorem mem_coe {b : β} {s : submodule α β} : b ∈ (s : set β) ↔ b ∈ s := iff.rfl
instance : has_subset (submodule α β) := ⟨λ s t, (s : set β) ⊆ t⟩
@[extensionality] theorem ext {s t : submodule α β} (h : (s : set β) = t) : s = t :=
by cases s; cases t; congr'
protected theorem ext_iff {s t : submodule α β} : (s : set β) = t ↔ s = t :=
iff.intro ext (assume h, h ▸ rfl)
instance : partial_order (submodule α β) :=
partial_order.lift (coe : submodule α β → set β) $ λ a b, ext
def span (s : set β) : submodule α β := ⟨span s, is_submodule_span⟩
theorem span_subset_iff {s : set β} {t : submodule α β} : span s ⊆ t ↔ s ⊆ t :=
⟨subset.trans subset_span, span_minimal t.2⟩
lemma span_singleton_subset {b : β} {s : submodule α β} : span {b} ⊆ s ↔ b ∈ s :=
by rw [submodule.span_subset_iff, set.singleton_subset_iff]; refl
lemma mem_span_singleton {b₁ b₂ : β} : b₁ ∈ span ({b₂} : set β) ↔ ∃c, b₁ = c • b₂ :=
show b₁ ∈ _root_.span ({b₂} : set β) ↔ ∃c, b₁ = c • b₂,
by simp [_root_.span_singleton, eq_comm]
protected def galois_insertion :
galois_insertion (@span α β _ _) coe :=
{ choice := λ s h, ⟨s, by rw le_antisymm (by exact subset_span) h; exact is_submodule_span⟩,
gc := λ s t, span_subset_iff,
le_l_u := λ s, subset_span,
choice_eq := λ s h, by ext1; exact le_antisymm (by exact subset_span) h }
instance : complete_lattice (submodule α β) := submodule.galois_insertion.lift_complete_lattice
instance : has_zero (submodule α β) := ⟨⊥⟩
@[simp] theorem sInter_set (S : set (submodule α β)) :
((Inf S : submodule α β) : set β) = ⋂ s ∈ S, ↑s := rfl
@[simp] theorem bot_set : ((⊥ : submodule α β) : set β) = {0} := span_empty
@[simp] theorem span_empty : (span ∅ : submodule α β) = ⊥ := rfl
@[simp] theorem top_set : ((⊤ : submodule α β) : set β) = univ := rfl
@[simp] theorem Union_set_of_directed {ι} (hι : nonempty ι)
(S : ι → submodule α β)
(H : ∀ i j, ∃ k, S i ≤ S k ∧ S j ≤ S k) :
((supr S : submodule α β) : set β) = ⋃ i, S i :=
begin
suffices su : is_submodule (⋃ i, (S i : set β)),
{ refine le_antisymm (_ : supr S ≤ ⟨_, su⟩) _,
{ exact supr_le (subset_Union (λ i, ↑(S i))) },
{ exact Union_subset (le_supr S) } },
unfreezeI,
exact {
zero_ := by cases hι with i; simp [-mem_coe];
exact ⟨i, is_submodule.zero⟩,
add_ := begin
simp, intros x y i hi j hj,
rcases H i j with ⟨k, ik, jk⟩,
exact ⟨k, is_submodule.add (ik hi) (jk hj)⟩
end,
smul := by simp [-mem_coe]; exact λ a x i hi,
⟨i, is_submodule.smul a hi⟩ }
end
theorem span_union (s t : set β) : (span (s ∪ t) : submodule α β) = span s ⊔ span t :=
(@submodule.galois_insertion α β _ _).gc.l_sup
/-- The pushforward -/
def map (f : β → γ) (h : is_linear_map f) (m : submodule α β) : submodule α γ :=
by letI := m.to_is_submodule; exact ⟨f '' m, is_submodule.image h⟩
lemma coe_map (f : β → γ) {h : is_linear_map f} (m : submodule α β) :
(map f h m : set γ) = f '' m := rfl
lemma map_id : map (@id β) is_linear_map.id = @id (submodule α β) :=
by ext; simp [-mem_coe, coe_map]
lemma map_comp (f : β → γ) (g : γ → δ) {hf : is_linear_map f} {hg : is_linear_map g} :
map (g ∘ f) (is_linear_map.comp hg hf) = map g hg ∘ map f hf :=
by ext : 2; simp [-mem_coe, coe_map, (set.image_comp g f _).symm]
lemma injective_map (f : β → γ) (h : is_linear_map f) (hf : injective f) : injective (map f h) :=
assume a b eq, by rwa [← submodule.ext_iff, coe_map, coe_map, image_eq_image hf, submodule.ext_iff] at eq
/-- The pullback -/
def comap (f : β → γ) (h : is_linear_map f) (m : submodule α γ) : submodule α β :=
by letI := m.to_is_submodule; exact ⟨f ⁻¹' m, is_submodule.preimage h⟩
lemma coe_comap (f : β → γ) {h : is_linear_map f} (m : submodule α γ) :
(comap f h m : set β) = f ⁻¹' m := rfl
lemma comap_id : comap (@id β) is_linear_map.id = @id (submodule α β) :=
by ext; simp [-mem_coe, coe_comap]
lemma comap_comp (f : β → γ) (g : γ → δ) {hf : is_linear_map f} {hg : is_linear_map g} :
comap (g ∘ f) (is_linear_map.comp hg hf) = comap f hf ∘ comap g hg :=
by ext : 2; simp [-mem_coe, coe_comap, set.preimage_comp.symm]
lemma injective_comap (f : β → γ) (h : is_linear_map f) (hf : surjective f) : injective (comap f h) :=
assume a b eq,
by rwa [← submodule.ext_iff, coe_comap, coe_comap, preimage_eq_preimage hf, submodule.ext_iff] at eq
lemma comap_map_eq {f : β → γ} (hf : is_linear_map f) (m : submodule α β) (h : ∀x, f x = 0 → x ∈ m) :
comap f hf (map f hf m) = m :=
begin
rw [← submodule.ext_iff, coe_comap, coe_map],
refine subset.antisymm _ (set.subset_preimage_image _ _),
rintros x ⟨y, hy, eq⟩,
have : f (y - x) = 0, { simp [eq, hf.sub, sub_self, -sub_eq_add_neg] },
have : y - x ∈ m, from h _ this,
suffices : y - (y - x) ∈ m, { simpa },
exact is_submodule.sub hy this
end
section subtype
variables (α β) (s : set β) [is_submodule s]
def map_subtype : submodule α s → submodule α β :=
map (coe : s → β) (is_submodule.is_linear_map_coe _)
lemma map_subtype_subset (m : submodule α s) : ↑(map_subtype α β s m) ⊆ s :=
by rintros x ⟨y, Hy, rfl⟩; exact y.property
/-- If N ⊆ M then submodules of N are the same as submodules of M contained in N -/
def map_subtype.order_iso :
((≤) : submodule α s → submodule α s → Prop) ≃o
((≤) : {m : submodule α β // ↑m ⊆ s} → {m : submodule α β // ↑m ⊆ s} → Prop) :=
{ to_fun := λP, ⟨map_subtype α β s P, map_subtype_subset α β s P⟩,
inv_fun := λ Q, comap (coe : s → β) (is_submodule.is_linear_map_coe _) Q,
left_inv := by tidy,
right_inv := by tidy,
ord := λ X Y, ⟨by tidy, assume h : subtype.val '' ↑X ⊆ subtype.val '' ↑Y, show X ⊆ Y, from
(image_subset_image_iff subtype.val_injective).1 h⟩ }
def map_subtype.le_order_embedding :
((≤) : submodule α s → submodule α s → Prop) ≼o ((≤) : submodule α β → submodule α β → Prop) :=
order_embedding.trans (order_iso.to_order_embedding $ map_subtype.order_iso α β s) (subtype.order_embedding _ _)
@[simp] lemma map_subtype_embedding_eq (P : submodule α s) :
map_subtype.le_order_embedding α β s P = map_subtype α β s P := rfl
def lt_order_embedding :
((<) : submodule α s → submodule α s → Prop) ≼o ((<) : submodule α β → submodule α β → Prop) :=
(map_subtype.le_order_embedding α β s).lt_embedding_of_le_embedding
end subtype
section quotient
open quotient_module is_submodule
variables (α β) (s : set β) [is_submodule s]
def comap_quotient : submodule α (quotient β s) → submodule α β :=
submodule.comap quotient_module.mk (is_linear_map_quotient_mk s)
lemma subset_comap_quotient (m : submodule α (quotient β s)) : s ⊆ comap_quotient α β s m :=
assume n hn, show ↑n ∈ m,
by rw [← quotient_module.coe_eq_zero s] at hn;
from hn.symm ▸ @is_submodule.zero _ _ _ _ (m : set (quotient β s)) _
/-- Correspondence Theorem -/
def comap_quotient.order_iso :
((≤) : submodule α (quotient β s) → submodule α (quotient β s) → Prop) ≃o
((≤) : {m : submodule α β // s ⊆ m} → {m : submodule α β // s ⊆ m} → Prop) :=
{ to_fun := λm, ⟨comap_quotient α β s m, subset_comap_quotient α β s m⟩,
inv_fun := λ X, submodule.map quotient_module.mk (is_linear_map_quotient_mk s) X,
left_inv := λ P, submodule.ext $ set.image_preimage_eq quotient_module.quotient.exists_rep,
right_inv :=
begin
rintros ⟨P, hP⟩,
have : ∀ (x : β), (x : quotient β s) = (0 : quotient β s) → x ∈ P,
{ assume a, rw [quotient_module.coe_eq_zero s], exact @hP a },
simp [comap_quotient, comap_map_eq (is_linear_map_quotient_mk s) P this]
end,
ord := by tidy }
end quotient
section prod
def prod (s : submodule α β) (t : submodule α γ) : submodule α (β × γ) :=
comap prod.fst prod.is_linear_map_prod_fst s ⊓ comap prod.snd prod.is_linear_map_prod_snd t
lemma coe_prod (s : submodule α β) (t : submodule α γ) : (prod s t : set (β × γ)) = set.prod s t :=
rfl
end prod
end submodule
namespace quotient_module
def le_order_embedding (R) [ring R] (M) [module R M] (N : set M) [is_submodule N] :
((≤) : submodule R (quotient M N) → submodule R (quotient M N) → Prop) ≼o
((≤): submodule R M → submodule R M → Prop) :=
order_embedding.trans (order_iso.to_order_embedding $
submodule.comap_quotient.order_iso R M N) (subtype.order_embedding _ _)
def lt_order_embedding (R) [ring R] (M) [module R M] (N : set M) [is_submodule N] :
((<) : submodule R (quotient M N) → submodule R (quotient M N) → Prop) ≼o
((<) : submodule R M → submodule R M → Prop) :=
(quotient_module.le_order_embedding R M N).lt_embedding_of_le_embedding
end quotient_module
|
f7635966d1fbeefd00fe946e133aec3161dcbbbe | 1fd908b06e3f9c1252cb2285ada1102623a67f72 | /init/funext.lean | 4b191ebcc27cbb1b54374a3a369a17a8766ece25 | [
"Apache-2.0"
] | permissive | avigad/hott3 | 609a002849182721e7c7ae536d9f1e2956d6d4d3 | f64750cd2de7a81e87d4828246d1369d59f16f43 | refs/heads/master | 1,629,027,243,322 | 1,510,946,717,000 | 1,510,946,717,000 | 103,570,461 | 0 | 0 | null | 1,505,415,620,000 | 1,505,415,620,000 | null | UTF-8 | Lean | false | false | 12,809 | lean | /-
Copyright (c) 2014 Jakob von Raumer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jakob von Raumer, Floris van Doorn
Ported from Coq HoTT
-/
import .trunc .equiv .ua
universes u v w l k
hott_theory
namespace hott
open hott.eq hott.is_trunc sigma function hott.is_equiv hott.equiv prod unit
/-
We now prove that funext follows from a couple of weaker-looking forms
of function extensionality.
This proof is originally due to Voevodsky; it has since been simplified
by Peter Lumsdaine and Michael Shulman.
-/
@[hott] def funext :=
Π ⦃A : Type l⦄ {P : A → Type k} (f g : Π x, P x), is_equiv (@apd10 A P f g)
-- Naive funext is the simple assertion that pointwise equal functions are equal.
@[hott] def naive_funext :=
Π ⦃A : Type _⦄ {P : A → Type _} (f g : Πx, P x), (f ~ g) → f = g
-- Weak funext says that a product of contractible types is contractible.
@[hott] def weak_funext :=
Π ⦃A : Type _⦄ (P : A → Type _) [H: Πx, is_contr (P x)], is_contr (Πx, P x)
@[hott] def weak_funext_of_naive_funext : naive_funext → weak_funext :=
begin
intros nf A P Pc,
let c := λ x, center (P x),
apply is_contr.mk c, intro f,
have eq' : (λx, center (P x)) ~ f := λ x, center_eq (f x),
have eq : (λx, center (P x)) = f := @nf A P (λx, center (P x)) f eq',
assumption
end
/-
The less obvious direction is that weak_funext implies funext
(and hence all three are logically equivalent). The point is that under weak
funext, the space of "pointwise homotopies" has the same universal property as
the space of paths.
-/
section
parameters [wf : weak_funext.{l k}] {A : Type.{l}} {B : A → Type.{k}} (f : Π x, B x)
@[hott] def is_contr_sigma_homotopy : is_contr (Σ (g : Π x, B x), f ~ g) :=
is_contr.mk (sigma.mk f (homotopy.refl f))
(λ ⟨(g : Π x, B x), (h : f ~ g)⟩,
let r := λ (k : Π x, Σ y, f x = y),
@sigma.mk _ (λg, f ~ g)
(λx, fst (k x)) (λx, snd (k x)) in
let s (g : Π x, B x) (h : f ~ g) (x) :=
@sigma.mk _ (λy, f x = y) (g x) (h x) in
have t1 : Πx, is_contr (Σ y, f x = y),
from (λx, is_contr_sigma_eq _),
have t2 : is_contr (Πx, Σ y, f x = y),
from wf _,
have t3 : (λ x, @sigma.mk _ (λ y, f x = y) (f x) idp) = s g h,
from @eq_of_is_contr (Π x, Σ y, f x = y) t2 _ _,
have t4 : r (λ x, sigma.mk (f x) idp) = r (s g h),
from ap r t3,
t4
)
local attribute [instance] is_contr_sigma_homotopy
parameters (Q : Π g (h : f ~ g), Type _) (d : Q f (homotopy.refl f))
@[hott] def homotopy_ind (g : Πx, B x) (h : f ~ g) : Q g h :=
@transport _ (λ gh, Q (sigma.fst gh) (snd gh)) (sigma.mk f (homotopy.refl f)) (sigma.mk g h)
(@eq_of_is_contr _ is_contr_sigma_homotopy _ _) d
-- local attribute weak_funext [reducible]
-- local attribute homotopy_ind [reducible]
@[hott] def homotopy_ind_comp : homotopy_ind f (homotopy.refl f) = d :=
begin
dsimp [homotopy_ind],
have := @prop_eq_of_is_contr _ _ _ _ (eq_of_is_contr _ _) idp,
rwr this, apply @is_contr_sigma_homotopy wf,
end
end
/- Now the proof is fairly easy; we can just use the same induction principle on both sides. -/
section
-- local attribute weak_funext [reducible]
@[hott] def funext_of_weak_funext (wf : weak_funext.{l k}) : funext.{l k} :=
begin
intros A B f g,
let eq_to_f := λ g' x, f = g',
let sim2path := @homotopy_ind wf _ _ f eq_to_f idp,
have t1 : sim2path f (homotopy.refl f) = idp,
by apply @homotopy_ind_comp wf,
have t2 : apd10 (sim2path f (homotopy.refl f)) = (homotopy.refl f),
from ap apd10 t1,
have left_inv : apd10 ∘ (sim2path g) ~ id,
from (@homotopy_ind wf _ _ f (λ g' x, apd10 (sim2path g' x) = x) t2) g,
have right_inv : @comp (f = g) (f ~ g) (f = g) (sim2path g) (@apd10 A B f g) ~ id,
{intro h, induction h, apply homotopy_ind_comp},
exact is_equiv.adjointify apd10 (sim2path g) left_inv right_inv
end
@[hott] def funext_from_naive_funext : naive_funext → funext :=
funext_of_weak_funext ∘ weak_funext_of_naive_funext
end
section
@[hott] private theorem ua_isequiv_postcompose {A B : Type.{l}} {C : Type u}
{w : A → B} [H0 : is_equiv w] : is_equiv (@comp C A B w) :=
let w' := equiv.mk w H0 in
let eqinv : A = B := ((@is_equiv.inv _ _ _ (univalence A B)) w') in
let eq' := equiv_of_eq eqinv in
have eqretr : eq' = w', from (@right_inv _ _ (@equiv_of_eq A B) (univalence A B) w'),
have invs_eq : eq'⁻¹ᶠ = w'⁻¹ᶠ, from inv_eq eq' w' eqretr,
is_equiv.adjointify (@comp C A B w)
(@comp C B A (is_equiv.inv w))
(λ (x : C → B),
have eqfin1 : Π(p : A = B), equiv_of_eq p ∘ ((equiv_of_eq p)⁻¹ᶠ ∘ x) = x,
by intro p; induction p; reflexivity,
have eqfin : eq' ∘ (eq'⁻¹ᶠ ∘ x) = x,
from eqfin1 eqinv,
have eqfin' : w' ∘ (eq'⁻¹ᶠ ∘ x) = x,
by { refine _ ⬝ eqfin, rwr eqretr },
show w' ∘ (w'⁻¹ᶠ ∘ x) = x,
by { refine _ ⬝ eqfin', rwr invs_eq }
)
(λ (x : C → A),
have eqfin1 : Π(p : A = B), (equiv_of_eq p)⁻¹ᶠ ∘ (equiv_of_eq p ∘ x) = x,
by intro p; induction p; reflexivity,
have eqfin : eq'⁻¹ᶠ ∘ (eq' ∘ x) = x,
from eqfin1 eqinv,
have eqfin' : eq'⁻¹ᶠ ∘ (w' ∘ x) = x,
by { refine _ ⬝ eqfin, rwr eqretr },
show w'⁻¹ᶠ ∘ (w' ∘ x) = x,
by { refine _ ⬝ eqfin', rwr invs_eq }
)
-- We are ready to prove functional extensionality,
-- starting with the naive non-dependent version.
@[hott] private def diagonal (B : Type _) : Type _
:= Σ xy : B × B, fst xy = snd xy
@[hott] private def isequiv_src_compose {A : Type u} {B : Type v}
: @is_equiv (A → diagonal B)
(A → B)
(comp (prod.fst ∘ sigma.fst)) :=
@ua_isequiv_postcompose (diagonal B) _ _ (prod.fst ∘ sigma.fst)
(is_equiv.adjointify (prod.fst ∘ sigma.fst)
(λ x : B, (sigma.mk (x , x) idp : diagonal B)) (λx, idp)
(λ ⟨⟨b, c⟩, p⟩, by { dsimp at p, induction p, refl }))
@[hott] private def isequiv_tgt_compose {A : Type u} {B : Type v}
: is_equiv (comp (prod.snd ∘ sigma.fst) : (A → diagonal B) → (A → B)) :=
@ua_isequiv_postcompose _ _ _ _ begin
fapply adjointify,
{ intro b, exact ⟨(b, b), idp⟩},
{ intro b, reflexivity},
{ intro a, induction a with q p, induction q, dsimp at *, induction p, reflexivity}
end
@[hott] theorem nondep_funext_from_ua {A : Type _} {B : Type _}
: Π {f g : A → B}, f ~ g → f = g :=
begin
intros f g p,
let d := λ (x : A), @sigma.mk (B × B) (λ (xy : B × B), xy.1 = xy.2) (f x , f x) (eq.refl (f x, f x).1),
let e := λ (x : A), @sigma.mk (B × B) (λ (xy : B × B), xy.1 = xy.2) (f x , g x) (p x),
let precomp1 : (A → diagonal B) → (A → B) := comp (prod.fst ∘ sigma.fst),
have equiv1 : is_equiv precomp1,
from @isequiv_src_compose A B,
have equiv2 : Π (x y : A → diagonal B), is_equiv (ap precomp1),
from is_equiv.is_equiv_ap precomp1,
have H' : Π (x y : A → diagonal B), prod.fst ∘ sigma.fst ∘ x = prod.fst ∘ sigma.fst ∘ y → x = y,
from (λ x y, is_equiv.inv (ap precomp1)),
have eq2 : prod.fst ∘ sigma.fst ∘ d = prod.fst ∘ sigma.fst ∘ e,
from idp,
have eq0 : d = e,
from H' d e eq2,
have eq1 : (prod.snd ∘ sigma.fst) ∘ d = (prod.snd ∘ sigma.fst) ∘ e,
from ap _ eq0,
exact eq1
end
end
-- Now we use this to prove weak funext, which as we know
-- implies (with dependent eta) also the strong dependent funext.
@[hott] theorem weak_funext_of_ua : weak_funext.{u v} :=
(λ (A : Type _) (P : A → Type _) allcontr,
let U := (λ (x : A), ulift unit) in
have pequiv : Π (x : A), P x ≃ unit,
from (λ x, @equiv_unit_of_is_contr (P x) (allcontr x)),
have psim : Π (x : A), P x = U x,
from (λ x, eq_of_equiv_lift (pequiv x)),
have p : P = U,
from @nondep_funext_from_ua A _ P U psim,
have tU' : is_contr (A → ulift unit),
from is_contr.mk (λ x, ulift.up ())
(λ f, nondep_funext_from_ua (λa, by induction (f a) with u;induction u;reflexivity)),
have tU : is_contr (Π x, U x),
from tU',
have tlast : is_contr (Πx, P x),
from transport (λ PU : A → Type v, is_contr $ Π x, PU x) p⁻¹ᵖ tU,
tlast)
-- we have proven function extensionality from the univalence axiom
@[hott] def funext_of_ua : funext :=
funext_of_weak_funext (@weak_funext_of_ua)
/-
We still take funext as an axiom, so that when you write "print axioms foo", you can see whether
it uses only function extensionality, and not also univalence.
-/
axiom function_extensionality : funext
variables {A : Type _} {P : A → Type _} {f g : Π x, P x}
namespace funext
@[instance, hott]
theorem is_equiv_apdt (f g : Π x, P x) : is_equiv (@apd10 A P f g) :=
function_extensionality f g
end funext
open funext
namespace eq
variables (f g)
@[hott] def eq_equiv_homotopy : (f = g) ≃ (f ~ g) :=
equiv.mk apd10 (by apply_instance)
variables {f g}
@[hott] def eq_of_homotopy : f ~ g → f = g :=
(@apd10 A P f g)⁻¹ᶠ
@[hott] def apd10_eq_of_homotopy (p : f ~ g) : apd10 (eq_of_homotopy p) = p :=
right_inv apd10 p
@[hott] def eq_of_homotopy_apd10 (p : f = g) : eq_of_homotopy (apd10 p) = p :=
left_inv apd10 p
@[hott] def eq_of_homotopy_idp (f : Π x, P x) : eq_of_homotopy (λx : A, idpath (f x)) = idpath f :=
is_equiv.left_inv apd10 idp
@[hott] def eq_of_homotopy_refl (f : Π x, P x) : eq_of_homotopy (homotopy.refl f) = idpath f :=
eq_of_homotopy_idp _
@[hott] def naive_funext_of_ua : naive_funext :=
λ A P f g h, eq_of_homotopy h
@[hott] protected def homotopy.rec_on {Q : (f ~ g) → Type _} (p : f ~ g)
(H : Π(q : f = g), Q (apd10 q)) : Q p :=
right_inv apd10 p ▸ H (eq_of_homotopy p)
@[hott] protected def homotopy.rec_on_idp {Q : Π{g}, (f ~ g) → Type _} {g : Π x, P x}
(p : f ~ g) (H : Q (homotopy.refl f)) : Q p :=
homotopy.rec_on p (λq, by induction q; exact H)
@[hott] protected def homotopy.rec_on' {f f' : Πa, P a} {Q : (f ~ f') → (f = f') → Type _}
(p : f ~ f') (H : Π(q : f = f'), Q (apd10 q) q) : Q p (eq_of_homotopy p) :=
begin
refine homotopy.rec_on p _,
intro q,
dunfold eq_of_homotopy, rwr left_inv apd10 q,
apply H
end
@[hott] protected def homotopy.rec_on_idp' {f : Πa, P a} {Q : Π{g}, (f ~ g) → (f = g) → Type _}
{g : Πa, P a} (p : f ~ g) (H : Q (homotopy.refl f) idp) : Q p (eq_of_homotopy p) :=
begin
refine homotopy.rec_on' p _, intro q, induction q, exact H
end
@[hott] protected def homotopy.rec_on_idp_left {A : Type _} {P : A → Type _} {g : Πa, P a}
{Q : Πf, (f ~ g) → Type _} {f : Π x, P x}
(p : f ~ g) (H : Q g (homotopy.refl g)) : Q f p :=
begin
refine homotopy.rec_on p (λ q, _), induction q, exact H
end
@[hott] def homotopy.rec_idp {A : Type _} {P : A → Type _} {f : Πa, P a}
(Q : Π{g}, (f ~ g) → Type _) (H : Q (homotopy.refl f)) {g : Π x, P x} (p : f ~ g) : Q p :=
homotopy.rec_on_idp p H
@[hott] def homotopy_rec_on_apd10 {A : Type _} {P : A → Type _} {f g : Πa, P a}
(Q : f ~ g → Type _) (H : Π(q : f = g), Q (apd10 q)) (p : f = g) :
homotopy.rec_on (apd10 p) H = H p :=
begin
dunfold homotopy.rec_on,
transitivity, rwr adj,
transitivity, symmetry; apply tr_compose,
apply apdt
end
@[hott] def homotopy_rec_idp_refl {A : Type _} {P : A → Type _} {f : Πa, P a}
(Q : Π{g}, f ~ g → Type _) (H : Q homotopy.rfl) :
homotopy.rec_idp @Q H homotopy.rfl = H :=
homotopy_rec_on_apd10 Q _ rfl
@[hott] def eq_of_homotopy_inv {f g : Π x, P x} (H : f ~ g)
: eq_of_homotopy (λx, (H x)⁻¹ᵖ) = (eq_of_homotopy H)⁻¹ :=
begin
apply homotopy.rec_on_idp H,
change eq_of_homotopy (λ x, idp) = _,
rwr [eq_of_homotopy_refl],
end
@[hott] def eq_of_homotopy_con {f g h : Π x, P x} (H1 : f ~ g) (H2 : g ~ h)
: eq_of_homotopy (λx, H1 x ⬝ H2 x) = eq_of_homotopy H1 ⬝ eq_of_homotopy H2 :=
begin
apply homotopy.rec_on_idp H2, apply homotopy.rec_on_idp H1,
rwr eq_of_homotopy_refl, apply eq_of_homotopy_idp,
end
@[hott] def compose_eq_of_homotopy {A B C : Type _} (g : B → C) {f f' : A → B} (H : f ~ f') :
ap (λf : A → B, g ∘ f) (eq_of_homotopy H) = eq_of_homotopy (hwhisker_left g H) :=
begin
apply homotopy.rec_on_idp H, rwr eq_of_homotopy_refl,
symmetry, apply eq_of_homotopy_idp
end
end eq
end hott |
a72236b2ca12989f6a012ec92212289f3d6d7a67 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /test/norm_digits.lean | d54e13f16b41c238cc41ac921fc468142e23b385 | [
"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 | 644 | lean | import data.nat.digits
example : nat.digits 0 0 = [] := by norm_num
example : nat.digits 1 0 = [] := by norm_num
example : nat.digits 2 0 = [] := by norm_num
example : nat.digits 10 0 = [] := by norm_num
example : nat.digits 0 1 = [1] := by norm_num
example : nat.digits 0 1000 = [1000] := by norm_num
example : nat.digits 1 10 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] := by norm_num
example : nat.digits 2 65536 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] := by norm_num
example : nat.digits 3 30000000 = [0, 1, 0, 1, 2, 0, 1, 1, 0, 0, 1, 1, 2, 0, 0, 2] := by norm_num
example : nat.digits 10 1234567 = [7, 6, 5, 4, 3, 2, 1] := by norm_num
|
37ecc8a1aa7c7165e347d239c9441d4748abc8b2 | 1abd1ed12aa68b375cdef28959f39531c6e95b84 | /src/group_theory/index.lean | 97118b008ea46ebf94ea2a4dbe291691a663416d | [
"Apache-2.0"
] | permissive | jumpy4/mathlib | d3829e75173012833e9f15ac16e481e17596de0f | af36f1a35f279f0e5b3c2a77647c6bf2cfd51a13 | refs/heads/master | 1,693,508,842,818 | 1,636,203,271,000 | 1,636,203,271,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,798 | lean | /-
Copyright (c) 2021 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import group_theory.quotient_group
import set_theory.fincard
/-!
# Index of a Subgroup
In this file we define the index of a subgroup, and prove several divisibility properties.
## Main definitions
- `H.index` : the index of `H : subgroup G` as a natural number,
and returns 0 if the index is infinite.
- `H.relindex K` : the relative index of `H : subgroup G` in `K : subgroup G` as a natural number,
and returns 0 if the relative index is infinite.
# Main results
- `index_mul_card` : `H.index * fintype.card H = fintype.card G`
- `index_dvd_card` : `H.index ∣ fintype.card G`
- `index_eq_mul_of_le` : If `H ≤ K`, then `H.index = K.index * (H.subgroup_of K).index`
- `index_dvd_of_le` : If `H ≤ K`, then `K.index ∣ H.index`
- `relindex_mul_relindex` : `relindex` is multiplicative in towers
-/
namespace subgroup
open_locale cardinal
variables {G : Type*} [group G] (H K L : subgroup G)
/-- The index of a subgroup as a natural number, and returns 0 if the index is infinite. -/
@[to_additive "The index of a subgroup as a natural number,
and returns 0 if the index is infinite."]
noncomputable def index : ℕ :=
nat.card (quotient_group.quotient H)
/-- The relative index of a subgroup as a natural number,
and returns 0 if the relative index is infinite. -/
@[to_additive "The relative index of a subgroup as a natural number,
and returns 0 if the relative index is infinite."]
noncomputable def relindex : ℕ :=
(H.subgroup_of K).index
@[to_additive] lemma index_comap_of_surjective {G' : Type*} [group G'] {f : G' →* G}
(hf : function.surjective f) : (H.comap f).index = H.index :=
begin
letI := quotient_group.left_rel H,
letI := quotient_group.left_rel (H.comap f),
have key : ∀ x y : G', setoid.r x y ↔ setoid.r (f x) (f y) :=
λ x y, iff_of_eq (congr_arg (∈ H) (by rw [f.map_mul, f.map_inv])),
refine cardinal.to_nat_congr (equiv.of_bijective (quotient.map' f (λ x y, (key x y).mp)) ⟨_, _⟩),
{ simp_rw [←quotient.eq'] at key,
refine quotient.ind' (λ x, _),
refine quotient.ind' (λ y, _),
exact (key x y).mpr },
{ refine quotient.ind' (λ x, _),
obtain ⟨y, hy⟩ := hf x,
exact ⟨y, (quotient.map'_mk' f _ y).trans (congr_arg quotient.mk' hy)⟩ },
end
@[to_additive] lemma index_comap {G' : Type*} [group G'] (f : G' →* G) :
(H.comap f).index = H.relindex f.range :=
eq.trans (congr_arg index (by refl))
((H.subgroup_of f.range).index_comap_of_surjective f.range_restrict_surjective)
variables {H K L}
@[to_additive] lemma relindex_mul_index (h : H ≤ K) : H.relindex K * K.index = H.index :=
((mul_comm _ _).trans (cardinal.to_nat_mul _ _).symm).trans
(congr_arg cardinal.to_nat (equiv.cardinal_eq (quotient_equiv_prod_of_le h))).symm
@[to_additive] lemma index_dvd_of_le (h : H ≤ K) : K.index ∣ H.index :=
dvd_of_mul_left_eq (H.relindex K) (relindex_mul_index h)
@[to_additive] lemma relindex_subgroup_of (hKL : K ≤ L) :
(H.subgroup_of L).relindex (K.subgroup_of L) = H.relindex K :=
((index_comap (H.subgroup_of L) (inclusion hKL)).trans (congr_arg _ (inclusion_range hKL))).symm
@[to_additive] lemma relindex_mul_relindex (hHK : H ≤ K) (hKL : K ≤ L) :
H.relindex K * K.relindex L = H.relindex L :=
begin
rw [←relindex_subgroup_of hKL],
exact relindex_mul_index (λ x hx, hHK hx),
end
variables (H K L)
lemma inf_relindex_right : (H ⊓ K).relindex K = H.relindex K :=
begin
rw [←subgroup_of_map_subtype, relindex, relindex, subgroup_of, comap_map_eq_self_of_injective],
exact subtype.coe_injective,
end
lemma inf_relindex_left : (H ⊓ K).relindex H = K.relindex H :=
by rw [inf_comm, inf_relindex_right]
lemma inf_relindex_eq_relindex_sup [K.normal] : (H ⊓ K).relindex H = K.relindex (H ⊔ K) :=
cardinal.to_nat_congr (quotient_group.quotient_inf_equiv_prod_normal_quotient H K).to_equiv
lemma relindex_eq_relindex_sup [K.normal] : K.relindex H = K.relindex (H ⊔ K) :=
by rw [←inf_relindex_left, inf_relindex_eq_relindex_sup]
variables {H K}
lemma relindex_dvd_of_le_left (hHK : H ≤ K) :
K.relindex L ∣ H.relindex L :=
begin
apply dvd_of_mul_left_eq ((H ⊓ L).relindex (K ⊓ L)),
rw [←inf_relindex_right H L, ←inf_relindex_right K L],
exact relindex_mul_relindex (inf_le_inf_right L hHK) inf_le_right,
end
variables (H K)
@[simp, to_additive] lemma index_top : (⊤ : subgroup G).index = 1 :=
cardinal.to_nat_eq_one_iff_unique.mpr ⟨quotient_group.subsingleton_quotient_top, ⟨1⟩⟩
@[simp, to_additive] lemma index_bot : (⊥ : subgroup G).index = nat.card G :=
cardinal.to_nat_congr (quotient_group.quotient_bot.to_equiv)
@[to_additive] lemma index_bot_eq_card [fintype G] : (⊥ : subgroup G).index = fintype.card G :=
index_bot.trans nat.card_eq_fintype_card
@[simp, to_additive] lemma relindex_top_left : (⊤ : subgroup G).relindex H = 1 :=
index_top
@[simp, to_additive] lemma relindex_top_right : H.relindex ⊤ = H.index :=
by rw [←relindex_mul_index (show H ≤ ⊤, from le_top), index_top, mul_one]
@[simp, to_additive] lemma relindex_bot_left : (⊥ : subgroup G).relindex H = nat.card H :=
by rw [relindex, bot_subgroup_of, index_bot]
@[to_additive] lemma relindex_bot_left_eq_card [fintype H] :
(⊥ : subgroup G).relindex H = fintype.card H :=
H.relindex_bot_left.trans nat.card_eq_fintype_card
@[simp, to_additive] lemma relindex_bot_right : H.relindex ⊥ = 1 :=
by rw [relindex, subgroup_of_bot_eq_top, index_top]
@[simp, to_additive] lemma relindex_self : H.relindex H = 1 :=
by rw [relindex, subgroup_of_self, index_top]
@[to_additive] lemma index_eq_card [fintype (quotient_group.quotient H)] :
H.index = fintype.card (quotient_group.quotient H) :=
nat.card_eq_fintype_card
@[to_additive] lemma index_mul_card [fintype G] [hH : fintype H] :
H.index * fintype.card H = fintype.card G :=
by rw [←relindex_bot_left_eq_card, ←index_bot_eq_card, mul_comm]; exact relindex_mul_index bot_le
@[to_additive] lemma index_dvd_card [fintype G] : H.index ∣ fintype.card G :=
begin
classical,
exact ⟨fintype.card H, H.index_mul_card.symm⟩,
end
variables {H}
@[simp] lemma index_eq_one : H.index = 1 ↔ H = ⊤ :=
⟨λ h, quotient_group.subgroup_eq_top_of_subsingleton H (cardinal.to_nat_eq_one_iff_unique.mp h).1,
λ h, (congr_arg index h).trans index_top⟩
lemma index_ne_zero_of_fintype [hH : fintype (quotient_group.quotient H)] : H.index ≠ 0 :=
by { rw index_eq_card, exact fintype.card_ne_zero }
lemma one_lt_index_of_ne_top [fintype (quotient_group.quotient H)] (hH : H ≠ ⊤) : 1 < H.index :=
nat.one_lt_iff_ne_zero_and_ne_one.mpr ⟨index_ne_zero_of_fintype, mt index_eq_one.mp hH⟩
end subgroup
|
51321d9490f992191eb996ffe227431c4df66def | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/measure_theory/measure/lebesgue.lean | 7ea3c63f4b71e55a8372c142ee9f2349de9c83fa | [
"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 | 25,289 | 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, Yury Kudryashov
-/
import dynamics.ergodic.measure_preserving
import linear_algebra.determinant
import linear_algebra.matrix.diagonal
import linear_algebra.matrix.transvection
import measure_theory.constructions.pi
import measure_theory.measure.stieltjes
/-!
# Lebesgue measure on the real line and on `ℝⁿ`
We construct Lebesgue measure on the real line, as a particular case of Stieltjes measure associated
to the function `x ↦ x`. We obtain as a consequence Lebesgue measure on `ℝⁿ`. We prove that they
are translation invariant.
We show that, on `ℝⁿ`, a linear map acts on Lebesgue measure by rescaling it through the absolute
value of its determinant, in `real.map_linear_map_volume_pi_eq_smul_volume_pi`.
More properties of the Lebesgue measure are deduced from this in `haar_lebesgue.lean`, where they
are proved more generally for any additive Haar measure on a finite-dimensional real vector space.
-/
noncomputable theory
open classical set filter measure_theory
open ennreal (of_real)
open_locale big_operators ennreal nnreal topological_space
/-!
### Definition of the Lebesgue measure and lengths of intervals
-/
/-- Lebesgue measure on the Borel sigma algebra, giving measure `b - a` to the interval `[a, b]`. -/
instance real.measure_space : measure_space ℝ :=
⟨stieltjes_function.id.measure⟩
namespace real
variables {ι : Type*} [fintype ι]
open_locale topological_space
theorem volume_val (s) : volume s = stieltjes_function.id.measure s := rfl
@[simp] lemma volume_Ico {a b : ℝ} : volume (Ico a b) = of_real (b - a) :=
by simp [volume_val]
@[simp] lemma volume_Icc {a b : ℝ} : volume (Icc a b) = of_real (b - a) :=
by simp [volume_val]
@[simp] lemma volume_Ioo {a b : ℝ} : volume (Ioo a b) = of_real (b - a) :=
by simp [volume_val]
@[simp] lemma volume_Ioc {a b : ℝ} : volume (Ioc a b) = of_real (b - a) :=
by simp [volume_val]
@[simp] lemma volume_singleton {a : ℝ} : volume ({a} : set ℝ) = 0 :=
by simp [volume_val]
@[simp] lemma volume_univ : volume (univ : set ℝ) = ∞ :=
ennreal.eq_top_of_forall_nnreal_le $ λ r,
calc (r : ℝ≥0∞) = volume (Icc (0 : ℝ) r) : by simp
... ≤ volume univ : measure_mono (subset_univ _)
@[simp] lemma volume_ball (a r : ℝ) :
volume (metric.ball a r) = of_real (2 * r) :=
by rw [ball_eq_Ioo, volume_Ioo, ← sub_add, add_sub_cancel', two_mul]
@[simp] lemma volume_closed_ball (a r : ℝ) :
volume (metric.closed_ball a r) = of_real (2 * r) :=
by rw [closed_ball_eq_Icc, volume_Icc, ← sub_add, add_sub_cancel', two_mul]
@[simp] lemma volume_emetric_ball (a : ℝ) (r : ℝ≥0∞) :
volume (emetric.ball a r) = 2 * r :=
begin
rcases eq_or_ne r ∞ with rfl|hr,
{ rw [metric.emetric_ball_top, volume_univ, two_mul, ennreal.top_add] },
{ lift r to ℝ≥0 using hr,
rw [metric.emetric_ball_nnreal, volume_ball, two_mul, ← nnreal.coe_add,
ennreal.of_real_coe_nnreal, ennreal.coe_add, two_mul] }
end
@[simp] lemma volume_emetric_closed_ball (a : ℝ) (r : ℝ≥0∞) :
volume (emetric.closed_ball a r) = 2 * r :=
begin
rcases eq_or_ne r ∞ with rfl|hr,
{ rw [emetric.closed_ball_top, volume_univ, two_mul, ennreal.top_add] },
{ lift r to ℝ≥0 using hr,
rw [metric.emetric_closed_ball_nnreal, volume_closed_ball, two_mul, ← nnreal.coe_add,
ennreal.of_real_coe_nnreal, ennreal.coe_add, two_mul] }
end
instance has_no_atoms_volume : has_no_atoms (volume : measure ℝ) :=
⟨λ x, volume_singleton⟩
@[simp] lemma volume_interval {a b : ℝ} : volume (interval a b) = of_real (|b - a|) :=
by rw [interval, volume_Icc, max_sub_min_eq_abs]
@[simp] lemma volume_Ioi {a : ℝ} : volume (Ioi a) = ∞ :=
top_unique $ le_of_tendsto' ennreal.tendsto_nat_nhds_top $ λ n,
calc (n : ℝ≥0∞) = volume (Ioo a (a + n)) : by simp
... ≤ volume (Ioi a) : measure_mono Ioo_subset_Ioi_self
@[simp] lemma volume_Ici {a : ℝ} : volume (Ici a) = ∞ :=
by simp [← measure_congr Ioi_ae_eq_Ici]
@[simp] lemma volume_Iio {a : ℝ} : volume (Iio a) = ∞ :=
top_unique $ le_of_tendsto' ennreal.tendsto_nat_nhds_top $ λ n,
calc (n : ℝ≥0∞) = volume (Ioo (a - n) a) : by simp
... ≤ volume (Iio a) : measure_mono Ioo_subset_Iio_self
@[simp] lemma volume_Iic {a : ℝ} : volume (Iic a) = ∞ :=
by simp [← measure_congr Iio_ae_eq_Iic]
instance locally_finite_volume : is_locally_finite_measure (volume : measure ℝ) :=
⟨λ x, ⟨Ioo (x - 1) (x + 1),
is_open.mem_nhds is_open_Ioo ⟨sub_lt_self _ zero_lt_one, lt_add_of_pos_right _ zero_lt_one⟩,
by simp only [real.volume_Ioo, ennreal.of_real_lt_top]⟩⟩
instance is_finite_measure_restrict_Icc (x y : ℝ) : is_finite_measure (volume.restrict (Icc x y)) :=
⟨by simp⟩
instance is_finite_measure_restrict_Ico (x y : ℝ) : is_finite_measure (volume.restrict (Ico x y)) :=
⟨by simp⟩
instance is_finite_measure_restrict_Ioc (x y : ℝ) : is_finite_measure (volume.restrict (Ioc x y)) :=
⟨by simp⟩
instance is_finite_measure_restrict_Ioo (x y : ℝ) : is_finite_measure (volume.restrict (Ioo x y)) :=
⟨by simp⟩
/-!
### Volume of a box in `ℝⁿ`
-/
lemma volume_Icc_pi {a b : ι → ℝ} : volume (Icc a b) = ∏ i, ennreal.of_real (b i - a i) :=
begin
rw [← pi_univ_Icc, volume_pi_pi],
simp only [real.volume_Icc]
end
@[simp] lemma volume_Icc_pi_to_real {a b : ι → ℝ} (h : a ≤ b) :
(volume (Icc a b)).to_real = ∏ i, (b i - a i) :=
by simp only [volume_Icc_pi, ennreal.to_real_prod, ennreal.to_real_of_real (sub_nonneg.2 (h _))]
lemma volume_pi_Ioo {a b : ι → ℝ} :
volume (pi univ (λ i, Ioo (a i) (b i))) = ∏ i, ennreal.of_real (b i - a i) :=
(measure_congr measure.univ_pi_Ioo_ae_eq_Icc).trans volume_Icc_pi
@[simp] lemma volume_pi_Ioo_to_real {a b : ι → ℝ} (h : a ≤ b) :
(volume (pi univ (λ i, Ioo (a i) (b i)))).to_real = ∏ i, (b i - a i) :=
by simp only [volume_pi_Ioo, ennreal.to_real_prod, ennreal.to_real_of_real (sub_nonneg.2 (h _))]
lemma volume_pi_Ioc {a b : ι → ℝ} :
volume (pi univ (λ i, Ioc (a i) (b i))) = ∏ i, ennreal.of_real (b i - a i) :=
(measure_congr measure.univ_pi_Ioc_ae_eq_Icc).trans volume_Icc_pi
@[simp] lemma volume_pi_Ioc_to_real {a b : ι → ℝ} (h : a ≤ b) :
(volume (pi univ (λ i, Ioc (a i) (b i)))).to_real = ∏ i, (b i - a i) :=
by simp only [volume_pi_Ioc, ennreal.to_real_prod, ennreal.to_real_of_real (sub_nonneg.2 (h _))]
lemma volume_pi_Ico {a b : ι → ℝ} :
volume (pi univ (λ i, Ico (a i) (b i))) = ∏ i, ennreal.of_real (b i - a i) :=
(measure_congr measure.univ_pi_Ico_ae_eq_Icc).trans volume_Icc_pi
@[simp] lemma volume_pi_Ico_to_real {a b : ι → ℝ} (h : a ≤ b) :
(volume (pi univ (λ i, Ico (a i) (b i)))).to_real = ∏ i, (b i - a i) :=
by simp only [volume_pi_Ico, ennreal.to_real_prod, ennreal.to_real_of_real (sub_nonneg.2 (h _))]
@[simp] lemma volume_pi_ball (a : ι → ℝ) {r : ℝ} (hr : 0 < r) :
volume (metric.ball a r) = ennreal.of_real ((2 * r) ^ fintype.card ι) :=
begin
simp only [volume_pi_ball a hr, volume_ball, finset.prod_const],
exact (ennreal.of_real_pow (mul_nonneg zero_le_two hr.le) _).symm
end
@[simp] lemma volume_pi_closed_ball (a : ι → ℝ) {r : ℝ} (hr : 0 ≤ r) :
volume (metric.closed_ball a r) = ennreal.of_real ((2 * r) ^ fintype.card ι) :=
begin
simp only [volume_pi_closed_ball a hr, volume_closed_ball, finset.prod_const],
exact (ennreal.of_real_pow (mul_nonneg zero_le_two hr) _).symm
end
lemma volume_le_diam (s : set ℝ) : volume s ≤ emetric.diam s :=
begin
by_cases hs : metric.bounded s,
{ rw [real.ediam_eq hs, ← volume_Icc],
exact volume.mono (real.subset_Icc_Inf_Sup_of_bounded hs) },
{ rw metric.ediam_of_unbounded hs, exact le_top }
end
lemma volume_pi_le_prod_diam (s : set (ι → ℝ)) :
volume s ≤ ∏ i : ι, emetric.diam (function.eval i '' s) :=
calc volume s ≤ volume (pi univ (λ i, closure (function.eval i '' s))) :
volume.mono $ subset.trans (subset_pi_eval_image univ s) $ pi_mono $ λ i hi, subset_closure
... = ∏ i, volume (closure $ function.eval i '' s) :
volume_pi_pi _
... ≤ ∏ i : ι, emetric.diam (function.eval i '' s) :
finset.prod_le_prod' $ λ i hi, (volume_le_diam _).trans_eq (emetric.diam_closure _)
lemma volume_pi_le_diam_pow (s : set (ι → ℝ)) :
volume s ≤ emetric.diam s ^ fintype.card ι :=
calc volume s ≤ ∏ i : ι, emetric.diam (function.eval i '' s) : volume_pi_le_prod_diam s
... ≤ ∏ i : ι, (1 : ℝ≥0) * emetric.diam s :
finset.prod_le_prod' $ λ i hi, (lipschitz_with.eval i).ediam_image_le s
... = emetric.diam s ^ fintype.card ι :
by simp only [ennreal.coe_one, one_mul, finset.prod_const, fintype.card]
/-!
### Images of the Lebesgue measure under translation/multiplication in ℝ
-/
lemma map_volume_add_left (a : ℝ) : measure.map ((+) a) volume = volume :=
eq.symm $ real.measure_ext_Ioo_rat $ λ p q,
by simp [measure.map_apply (measurable_const_add a) measurable_set_Ioo, sub_sub_sub_cancel_right]
@[simp] lemma volume_preimage_add_left (a : ℝ) (s : set ℝ) : volume (((+) a) ⁻¹' s) = volume s :=
calc volume (((+) a) ⁻¹' s) = measure.map ((+) a) volume s :
((homeomorph.add_left a).to_measurable_equiv.map_apply s).symm
... = volume s : by rw map_volume_add_left
lemma map_volume_add_right (a : ℝ) : measure.map (+ a) volume = volume :=
by simpa only [add_comm] using real.map_volume_add_left a
@[simp] lemma volume_preimage_add_right (a : ℝ) (s : set ℝ) : volume ((+ a) ⁻¹' s) = volume s :=
calc volume ((+ a) ⁻¹' s) = measure.map (+ a) volume s :
((homeomorph.add_right a).to_measurable_equiv.map_apply s).symm
... = volume s : by rw map_volume_add_right
lemma smul_map_volume_mul_left {a : ℝ} (h : a ≠ 0) :
ennreal.of_real (|a|) • measure.map ((*) a) volume = volume :=
begin
refine (real.measure_ext_Ioo_rat $ λ p q, _).symm,
cases lt_or_gt_of_ne h with h h,
{ simp only [real.volume_Ioo, measure.smul_apply, ← ennreal.of_real_mul (le_of_lt $ neg_pos.2 h),
measure.map_apply (measurable_const_mul a) measurable_set_Ioo, neg_sub_neg,
← neg_mul_eq_neg_mul, preimage_const_mul_Ioo_of_neg _ _ h, abs_of_neg h, mul_sub,
mul_div_cancel' _ (ne_of_lt h)] },
{ simp only [real.volume_Ioo, measure.smul_apply, ← ennreal.of_real_mul (le_of_lt h),
measure.map_apply (measurable_const_mul a) measurable_set_Ioo, preimage_const_mul_Ioo _ _ h,
abs_of_pos h, mul_sub, mul_div_cancel' _ (ne_of_gt h)] }
end
lemma map_volume_mul_left {a : ℝ} (h : a ≠ 0) :
measure.map ((*) a) volume = ennreal.of_real (|a⁻¹|) • volume :=
by conv_rhs { rw [← real.smul_map_volume_mul_left h, smul_smul,
← ennreal.of_real_mul (abs_nonneg _), ← abs_mul, inv_mul_cancel h, abs_one, ennreal.of_real_one,
one_smul] }
@[simp] lemma volume_preimage_mul_left {a : ℝ} (h : a ≠ 0) (s : set ℝ) :
volume (((*) a) ⁻¹' s) = ennreal.of_real (abs a⁻¹) * volume s :=
calc volume (((*) a) ⁻¹' s) = measure.map ((*) a) volume s :
((homeomorph.mul_left₀ a h).to_measurable_equiv.map_apply s).symm
... = ennreal.of_real (abs a⁻¹) * volume s : by { rw map_volume_mul_left h, refl }
lemma smul_map_volume_mul_right {a : ℝ} (h : a ≠ 0) :
ennreal.of_real (|a|) • measure.map (* a) volume = volume :=
by simpa only [mul_comm] using real.smul_map_volume_mul_left h
lemma map_volume_mul_right {a : ℝ} (h : a ≠ 0) :
measure.map (* a) volume = ennreal.of_real (|a⁻¹|) • volume :=
by simpa only [mul_comm] using real.map_volume_mul_left h
@[simp] lemma volume_preimage_mul_right {a : ℝ} (h : a ≠ 0) (s : set ℝ) :
volume ((* a) ⁻¹' s) = ennreal.of_real (abs a⁻¹) * volume s :=
calc volume ((* a) ⁻¹' s) = measure.map (* a) volume s :
((homeomorph.mul_right₀ a h).to_measurable_equiv.map_apply s).symm
... = ennreal.of_real (abs a⁻¹) * volume s : by { rw map_volume_mul_right h, refl }
@[simp] lemma map_volume_neg : measure.map has_neg.neg (volume : measure ℝ) = volume :=
eq.symm $ real.measure_ext_Ioo_rat $ λ p q,
by simp [show measure.map has_neg.neg volume (Ioo (p : ℝ) q) = _,
from measure.map_apply measurable_neg measurable_set_Ioo]
/-!
### Images of the Lebesgue measure under translation/linear maps in ℝⁿ
-/
lemma map_volume_pi_add_left (a : ι → ℝ) : measure.map ((+) a) volume = volume :=
begin
refine (measure.pi_eq (λ s hs, _)).symm,
have A : has_add.add a ⁻¹' (set.pi univ (λ (i : ι), s i))
= set.pi univ (λ (i : ι), ((+) (a i)) ⁻¹' (s i)), by { ext, simp },
rw [measure.map_apply (measurable_const_add a) (measurable_set.univ_pi_fintype hs), A,
volume_pi_pi],
simp only [volume_preimage_add_left]
end
@[simp] lemma volume_pi_preimage_add_left (a : ι → ℝ) (s : set (ι → ℝ)) :
volume (((+) a) ⁻¹' s) = volume s :=
calc volume (((+) a) ⁻¹' s) = measure.map ((+) a) volume s :
((homeomorph.add_left a).to_measurable_equiv.map_apply s).symm
... = volume s : by rw map_volume_pi_add_left
open matrix
/-- A diagonal matrix rescales Lebesgue according to its determinant. This is a special case of
`real.map_matrix_volume_pi_eq_smul_volume_pi`, that one should use instead (and whose proof
uses this particular case). -/
lemma smul_map_diagonal_volume_pi [decidable_eq ι] {D : ι → ℝ} (h : det (diagonal D) ≠ 0) :
ennreal.of_real (abs (det (diagonal D))) • measure.map ((diagonal D).to_lin') volume = volume :=
begin
refine (measure.pi_eq (λ s hs, _)).symm,
simp only [det_diagonal, measure.coe_smul, algebra.id.smul_eq_mul, pi.smul_apply],
rw [measure.map_apply _ (measurable_set.univ_pi_fintype hs)],
swap, { exact continuous.measurable (linear_map.continuous_on_pi _) },
have : (matrix.to_lin' (diagonal D)) ⁻¹' (set.pi set.univ (λ (i : ι), s i))
= set.pi set.univ (λ (i : ι), ((*) (D i)) ⁻¹' (s i)),
{ ext f,
simp only [linear_map.coe_proj, algebra.id.smul_eq_mul, linear_map.smul_apply, mem_univ_pi,
mem_preimage, linear_map.pi_apply, diagonal_to_lin'] },
have B : ∀ i, of_real (abs (D i)) * volume (has_mul.mul (D i) ⁻¹' s i) = volume (s i),
{ assume i,
have A : D i ≠ 0,
{ simp only [det_diagonal, ne.def] at h,
exact finset.prod_ne_zero_iff.1 h i (finset.mem_univ i) },
rw [volume_preimage_mul_left A, ← mul_assoc, ← ennreal.of_real_mul (abs_nonneg _), ← abs_mul,
mul_inv_cancel A, abs_one, ennreal.of_real_one, one_mul] },
rw [this, volume_pi_pi, finset.abs_prod,
ennreal.of_real_prod_of_nonneg (λ i hi, abs_nonneg (D i)), ← finset.prod_mul_distrib],
simp only [B]
end
/-- A transvection preserves Lebesgue measure. -/
lemma map_transvection_volume_pi [decidable_eq ι] (t : transvection_struct ι ℝ) :
measure.map (t.to_matrix.to_lin') volume = volume :=
begin
/- We separate the coordinate along which there is a shearing from the other ones, and apply
Fubini. Along this coordinate (and when all the other coordinates are fixed), it acts like a
translation, and therefore preserves Lebesgue. -/
suffices H : measure_preserving t.to_matrix.to_lin' volume volume, by exact H.2,
let p : ι → Prop := λ i, i ≠ t.i,
let α : Type* := {x // p x},
let β : Type* := {x // ¬ (p x)},
let g : (α → ℝ) → (β → ℝ) → (β → ℝ) := λ a b, (λ x, t.c * a ⟨t.j, t.hij.symm⟩) + b,
let F : (α → ℝ) × (β → ℝ) → (α → ℝ) × (β → ℝ) :=
λ p, (id p.1, g p.1 p.2),
let e := equiv.pi_equiv_pi_subtype_prod p (λ (i : ι), ℝ),
have : (t.to_matrix.to_lin' : (ι → ℝ) → (ι → ℝ)) = e.symm ∘ F ∘ e,
{ cases t,
ext f k,
simp only [linear_equiv.map_smul, dite_eq_ite, linear_map.id_coe, p, ite_not,
algebra.id.smul_eq_mul, one_mul, dot_product, std_basis_matrix,
equiv.pi_equiv_pi_subtype_prod_symm_apply, id.def, transvection,
pi.add_apply, zero_mul, linear_map.smul_apply, function.comp_app,
equiv.pi_equiv_pi_subtype_prod_apply, matrix.transvection_struct.to_matrix_mk,
matrix.mul_vec, linear_equiv.map_add, ite_mul, e, matrix.to_lin'_apply,
pi.smul_apply, subtype.coe_mk, g, linear_map.add_apply, finset.sum_congr, matrix.to_lin'_one],
by_cases h : t_i = k,
{ simp only [h, true_and, finset.mem_univ, if_true, eq_self_iff_true, finset.sum_ite_eq,
one_apply, boole_mul, add_comm], },
{ simp only [h, ne.symm h, add_zero, if_false, finset.sum_const_zero, false_and, mul_zero] } },
rw this,
have A : measure_preserving e volume volume :=
⟨ measurable_pi_equiv_pi_subtype_prod (λ i, ℝ) _,
(measure.map_pi_equiv_pi_subtype_prod (λ i, (volume : measure ℝ)) p : _) ⟩,
have B : measure_preserving F volume volume,
{ have g_meas : measurable (function.uncurry g),
{ have : measurable (λ (c : (α → ℝ)), c ⟨t.j, t.hij.symm⟩) :=
measurable_pi_apply ⟨t.j, t.hij.symm⟩,
refine measurable.add (measurable_pi_lambda _ (λ i, measurable.const_mul _ _)) measurable_snd,
exact this.comp measurable_fst },
exact measure_preserving.skew_product (measure_preserving.id _) g_meas
(eventually_of_forall (λ a, map_volume_pi_add_left _)) },
have C : measure_preserving e.symm volume volume :=
⟨ (measurable_pi_equiv_pi_subtype_prod_symm (λ (i : ι), ℝ) p : _),
(measure.map_pi_equiv_pi_subtype_prod_symm (λ (i : ι), volume) p : _) ⟩,
exact (C.comp B).comp A,
end
/-- Any invertible matrix rescales Lebesgue measure through the absolute value of its
determinant. -/
lemma map_matrix_volume_pi_eq_smul_volume_pi [decidable_eq ι] {M : matrix ι ι ℝ} (hM : det M ≠ 0) :
measure.map (M.to_lin') volume = ennreal.of_real (abs (det M)⁻¹) • volume :=
begin
-- This follows from the cases we have already proved, of diagonal matrices and transvections,
-- as these matrices generate all invertible matrices.
apply diagonal_transvection_induction_of_det_ne_zero _ M hM (λ D hD, _) (λ t, _)
(λ A B hA hB IHA IHB, _),
{ conv_rhs { rw [← smul_map_diagonal_volume_pi hD] },
rw [smul_smul, ← ennreal.of_real_mul (abs_nonneg _), ← abs_mul, inv_mul_cancel hD, abs_one,
ennreal.of_real_one, one_smul] },
{ simp only [matrix.transvection_struct.det, ennreal.of_real_one, map_transvection_volume_pi,
one_smul, _root_.inv_one, abs_one] },
{ rw [to_lin'_mul, det_mul, linear_map.coe_comp, ← measure.map_map, IHB, linear_map.map_smul,
IHA, smul_smul, ← ennreal.of_real_mul (abs_nonneg _), ← abs_mul, mul_comm, mul_inv₀],
{ apply continuous.measurable,
apply linear_map.continuous_on_pi },
{ apply continuous.measurable,
apply linear_map.continuous_on_pi } }
end
/-- Any invertible linear map rescales Lebesgue measure through the absolute value of its
determinant. -/
lemma map_linear_map_volume_pi_eq_smul_volume_pi {f : (ι → ℝ) →ₗ[ℝ] (ι → ℝ)} (hf : f.det ≠ 0) :
measure.map f volume = ennreal.of_real (abs (f.det)⁻¹) • volume :=
begin
-- this is deduced from the matrix case
classical,
let M := f.to_matrix',
have A : f.det = det M, by simp only [linear_map.det_to_matrix'],
have B : f = M.to_lin', by simp only [to_lin'_to_matrix'],
rw [A, B],
apply map_matrix_volume_pi_eq_smul_volume_pi,
rwa A at hf
end
end real
open_locale topological_space
lemma filter.eventually.volume_pos_of_nhds_real {p : ℝ → Prop} {a : ℝ} (h : ∀ᶠ x in 𝓝 a, p x) :
(0 : ℝ≥0∞) < volume {x | p x} :=
begin
rcases h.exists_Ioo_subset with ⟨l, u, hx, hs⟩,
refine lt_of_lt_of_le _ (measure_mono hs),
simpa [-mem_Ioo] using hx.1.trans hx.2
end
section region_between
open_locale classical
variable {α : Type*}
/-- The region between two real-valued functions on an arbitrary set. -/
def region_between (f g : α → ℝ) (s : set α) : set (α × ℝ) :=
{p : α × ℝ | p.1 ∈ s ∧ p.2 ∈ Ioo (f p.1) (g p.1)}
lemma region_between_subset (f g : α → ℝ) (s : set α) :
region_between f g s ⊆ s ×ˢ (univ : set ℝ) :=
by simpa only [prod_univ, region_between, set.preimage, set_of_subset_set_of] using λ a, and.left
variables [measurable_space α] {μ : measure α} {f g : α → ℝ} {s : set α}
/-- The region between two measurable functions on a measurable set is measurable. -/
lemma measurable_set_region_between
(hf : measurable f) (hg : measurable g) (hs : measurable_set s) :
measurable_set (region_between f g s) :=
begin
dsimp only [region_between, Ioo, mem_set_of_eq, set_of_and],
refine measurable_set.inter _ ((measurable_set_lt (hf.comp measurable_fst) measurable_snd).inter
(measurable_set_lt measurable_snd (hg.comp measurable_fst))),
exact measurable_fst hs
end
theorem volume_region_between_eq_lintegral'
(hf : measurable f) (hg : measurable g) (hs : measurable_set s) :
μ.prod volume (region_between f g s) = ∫⁻ y in s, ennreal.of_real ((g - f) y) ∂μ :=
begin
rw measure.prod_apply,
{ have h : (λ x, volume {a | x ∈ s ∧ a ∈ Ioo (f x) (g x)})
= s.indicator (λ x, ennreal.of_real (g x - f x)),
{ funext x,
rw indicator_apply,
split_ifs,
{ have hx : {a | x ∈ s ∧ a ∈ Ioo (f x) (g x)} = Ioo (f x) (g x) := by simp [h, Ioo],
simp only [hx, real.volume_Ioo, sub_zero] },
{ have hx : {a | x ∈ s ∧ a ∈ Ioo (f x) (g x)} = ∅ := by simp [h],
simp only [hx, measure_empty] } },
dsimp only [region_between, preimage_set_of_eq],
rw [h, lintegral_indicator];
simp only [hs, pi.sub_apply] },
{ exact measurable_set_region_between hf hg hs },
end
/-- The volume of the region between two almost everywhere measurable functions on a measurable set
can be represented as a Lebesgue integral. -/
theorem volume_region_between_eq_lintegral [sigma_finite μ]
(hf : ae_measurable f (μ.restrict s)) (hg : ae_measurable g (μ.restrict s))
(hs : measurable_set s) :
μ.prod volume (region_between f g s) = ∫⁻ y in s, ennreal.of_real ((g - f) y) ∂μ :=
begin
have h₁ : (λ y, ennreal.of_real ((g - f) y))
=ᵐ[μ.restrict s]
λ y, ennreal.of_real ((ae_measurable.mk g hg - ae_measurable.mk f hf) y) :=
(hg.ae_eq_mk.sub hf.ae_eq_mk).fun_comp _,
have h₂ : (μ.restrict s).prod volume (region_between f g s) =
(μ.restrict s).prod volume (region_between (ae_measurable.mk f hf) (ae_measurable.mk g hg) s),
{ apply measure_congr,
apply eventually_eq.rfl.inter,
exact
((ae_eq_comp' measurable_fst hf.ae_eq_mk measure.prod_fst_absolutely_continuous).comp₂ _
eventually_eq.rfl).inter
(eventually_eq.rfl.comp₂ _
(ae_eq_comp' measurable_fst hg.ae_eq_mk measure.prod_fst_absolutely_continuous)) },
rw [lintegral_congr_ae h₁,
← volume_region_between_eq_lintegral' hf.measurable_mk hg.measurable_mk hs],
convert h₂ using 1,
{ rw measure.restrict_prod_eq_prod_univ,
exact (measure.restrict_eq_self _ (region_between_subset f g s)).symm, },
{ rw measure.restrict_prod_eq_prod_univ,
exact (measure.restrict_eq_self _
(region_between_subset (ae_measurable.mk f hf) (ae_measurable.mk g hg) s)).symm },
end
theorem volume_region_between_eq_integral' [sigma_finite μ]
(f_int : integrable_on f s μ) (g_int : integrable_on g s μ)
(hs : measurable_set s) (hfg : f ≤ᵐ[μ.restrict s] g ) :
μ.prod volume (region_between f g s) = ennreal.of_real (∫ y in s, (g - f) y ∂μ) :=
begin
have h : g - f =ᵐ[μ.restrict s] (λ x, real.to_nnreal (g x - f x)),
from hfg.mono (λ x hx, (real.coe_to_nnreal _ $ sub_nonneg.2 hx).symm),
rw [volume_region_between_eq_lintegral f_int.ae_measurable g_int.ae_measurable hs,
integral_congr_ae h, lintegral_congr_ae,
lintegral_coe_eq_integral _ ((integrable_congr h).mp (g_int.sub f_int))],
simpa only,
end
/-- If two functions are integrable on a measurable set, and one function is less than
or equal to the other on that set, then the volume of the region
between the two functions can be represented as an integral. -/
theorem volume_region_between_eq_integral [sigma_finite μ]
(f_int : integrable_on f s μ) (g_int : integrable_on g s μ)
(hs : measurable_set s) (hfg : ∀ x ∈ s, f x ≤ g x) :
μ.prod volume (region_between f g s) = ennreal.of_real (∫ y in s, (g - f) y ∂μ) :=
volume_region_between_eq_integral' f_int g_int hs
((ae_restrict_iff' hs).mpr (eventually_of_forall hfg))
end region_between
/-
section vitali
def vitali_aux_h (x : ℝ) (h : x ∈ Icc (0:ℝ) 1) :
∃ y ∈ Icc (0:ℝ) 1, ∃ q:ℚ, ↑q = x - y :=
⟨x, h, 0, by simp⟩
def vitali_aux (x : ℝ) (h : x ∈ Icc (0:ℝ) 1) : ℝ :=
classical.some (vitali_aux_h x h)
theorem vitali_aux_mem (x : ℝ) (h : x ∈ Icc (0:ℝ) 1) : vitali_aux x h ∈ Icc (0:ℝ) 1 :=
Exists.fst (classical.some_spec (vitali_aux_h x h):_)
theorem vitali_aux_rel (x : ℝ) (h : x ∈ Icc (0:ℝ) 1) :
∃ q:ℚ, ↑q = x - vitali_aux x h :=
Exists.snd (classical.some_spec (vitali_aux_h x h):_)
def vitali : set ℝ := {x | ∃ h, x = vitali_aux x h}
theorem vitali_nonmeasurable : ¬ null_measurable_set measure_space.μ vitali :=
sorry
end vitali
-/
|
0fa378e4b8d2ce12534e2cea81a87db83f6b35cb | b70031c8e2c5337b91d7e70f1e0c5f528f7b0e77 | /src/linear_algebra/basic.lean | 5692b8ad6d2ba76d670517ce82d5af060b8cdba9 | [
"Apache-2.0"
] | permissive | molodiuc/mathlib | cae2ba3ef1601c1f42ca0b625c79b061b63fef5b | 98ebe5a6739fbe254f9ee9d401882d4388f91035 | refs/heads/master | 1,674,237,127,059 | 1,606,353,533,000 | 1,606,353,533,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 105,392 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov
-/
import algebra.big_operators.pi
import algebra.module.pi
import algebra.module.prod
import algebra.module.submodule
import algebra.group.prod
import data.finsupp.basic
import algebra.pointwise
/-!
# Linear algebra
This file defines the basics of linear algebra. It sets up the "categorical/lattice structure" of
modules over a ring, submodules, and linear maps. If `p` and `q` are submodules of a module, `p ≤ q`
means that `p ⊆ q`.
Many of the relevant definitions, including `module`, `submodule`, and `linear_map`, are found in
`src/algebra/module`.
## Main definitions
* Many constructors for linear maps, including `prod` and `coprod`
* `submodule.span s` is defined to be the smallest submodule containing the set `s`.
* If `p` is a submodule of `M`, `submodule.quotient p` is the quotient of `M` with respect to `p`:
that is, elements of `M` are identified if their difference is in `p`. This is itself a module.
* The kernel `ker` and range `range` of a linear map are submodules of the domain and codomain
respectively.
* The general linear group is defined to be the group of invertible linear maps from `M` to itself.
## Main statements
* The first and second isomorphism laws for modules are proved as `quot_ker_equiv_range` and
`quotient_inf_equiv_sup_quotient`.
## Notations
* We continue to use the notation `M →ₗ[R] M₂` for the type of linear maps from `M` to `M₂` over the
ring `R`.
* We introduce the notations `M ≃ₗ M₂` and `M ≃ₗ[R] M₂` for `linear_equiv M M₂`. In the first, the
ring `R` is implicit.
## Implementation notes
We note that, when constructing linear maps, it is convenient to use operations defined on bundled
maps (`prod`, `coprod`, arithmetic operations like `+`) instead of defining a function and proving
it is linear.
## Tags
linear algebra, vector space, module
-/
open function
open_locale big_operators
reserve infix ` ≃ₗ `:25
universes u v w x y z u' v' w' y'
variables {R : Type u} {K : Type u'} {M : Type v} {V : Type v'} {M₂ : Type w} {V₂ : Type w'}
variables {M₃ : Type y} {V₃ : Type y'} {M₄ : Type z} {ι : Type x}
namespace finsupp
lemma smul_sum {α : Type u} {β : Type v} {R : Type w} {M : Type y}
[has_zero β] [semiring R] [add_comm_monoid M] [semimodule R M]
{v : α →₀ β} {c : R} {h : α → β → M} :
c • (v.sum h) = v.sum (λa b, c • h a b) :=
finset.smul_sum
end finsupp
section
open_locale classical
/-- decomposing `x : ι → R` as a sum along the canonical basis -/
lemma pi_eq_sum_univ {ι : Type u} [fintype ι] {R : Type v} [semiring R] (x : ι → R) :
x = ∑ i, x i • (λj, if i = j then 1 else 0) :=
by { ext, simp }
end
/-! ### Properties of linear maps -/
namespace linear_map
section add_comm_monoid
variables [semiring R]
variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] [add_comm_monoid M₄]
variables [semimodule R M] [semimodule R M₂] [semimodule R M₃] [semimodule R M₄]
variables (f g : M →ₗ[R] M₂)
include R
@[simp] theorem comp_id : f.comp id = f :=
linear_map.ext $ λ x, rfl
@[simp] theorem id_comp : id.comp f = f :=
linear_map.ext $ λ x, rfl
theorem comp_assoc (g : M₂ →ₗ[R] M₃) (h : M₃ →ₗ[R] M₄) : (h.comp g).comp f = h.comp (g.comp f) :=
rfl
/-- The restriction of a linear map `f : M → M₂` to a submodule `p ⊆ M` gives a linear map
`p → M₂`. -/
def dom_restrict (f : M →ₗ[R] M₂) (p : submodule R M) : p →ₗ[R] M₂ := f.comp p.subtype
@[simp] lemma dom_restrict_apply (f : M →ₗ[R] M₂) (p : submodule R M) (x : p) :
f.dom_restrict p x = f x := rfl
/-- A linear map `f : M₂ → M` whose values lie in a submodule `p ⊆ M` can be restricted to a
linear map M₂ → p. -/
def cod_restrict (p : submodule R M) (f : M₂ →ₗ[R] M) (h : ∀c, f c ∈ p) : M₂ →ₗ[R] p :=
by refine {to_fun := λc, ⟨f c, h c⟩, ..}; intros; apply set_coe.ext; simp
@[simp] theorem cod_restrict_apply (p : submodule R M) (f : M₂ →ₗ[R] M) {h} (x : M₂) :
(cod_restrict p f h x : M) = f x := rfl
@[simp] lemma comp_cod_restrict (p : submodule R M₂) (h : ∀b, f b ∈ p) (g : M₃ →ₗ[R] M) :
(cod_restrict p f h).comp g = cod_restrict p (f.comp g) (assume b, h _) :=
ext $ assume b, rfl
@[simp] lemma subtype_comp_cod_restrict (p : submodule R M₂) (h : ∀b, f b ∈ p) :
p.subtype.comp (cod_restrict p f h) = f :=
ext $ assume b, rfl
/-- Restrict domain and codomain of an endomorphism. -/
def restrict (f : M →ₗ[R] M) {p : submodule R M} (hf : ∀ x ∈ p, f x ∈ p) : p →ₗ[R] p :=
{ to_fun := λ x, ⟨f x, hf x.1 x.2⟩,
map_add' := begin intros, apply set_coe.ext, simp end,
map_smul' := begin intros, apply set_coe.ext, simp end }
lemma restrict_apply
{f : M →ₗ[R] M} {p : submodule R M} (hf : ∀ x ∈ p, f x ∈ p) (x : p) :
f.restrict hf x = ⟨f x, hf x.1 x.2⟩ := rfl
lemma subtype_comp_restrict {f : M →ₗ[R] M} {p : submodule R M} (hf : ∀ x ∈ p, f x ∈ p) :
p.subtype.comp (f.restrict hf) = f.dom_restrict p := rfl
lemma restrict_eq_cod_restrict_dom_restrict
{f : M →ₗ[R] M} {p : submodule R M} (hf : ∀ x ∈ p, f x ∈ p) :
f.restrict hf = (f.dom_restrict p).cod_restrict p (λ x, hf x.1 x.2) := rfl
lemma restrict_eq_dom_restrict_cod_restrict
{f : M →ₗ[R] M} {p : submodule R M} (hf : ∀ x, f x ∈ p) :
f.restrict (λ x _, hf x) = (f.cod_restrict p hf).dom_restrict p := rfl
/-- The constant 0 map is linear. -/
instance : has_zero (M →ₗ[R] M₂) := ⟨⟨λ _, 0, by simp, by simp⟩⟩
instance : inhabited (M →ₗ[R] M₂) := ⟨0⟩
@[simp] lemma zero_apply (x : M) : (0 : M →ₗ[R] M₂) x = 0 := rfl
@[simp] lemma default_def : default (M →ₗ[R] M₂) = 0 := rfl
instance unique_of_left [subsingleton M] : unique (M →ₗ[R] M₂) :=
{ uniq := λ f, ext $ λ x, by rw [subsingleton.elim x 0, map_zero, map_zero],
.. linear_map.inhabited }
instance unique_of_right [subsingleton M₂] : unique (M →ₗ[R] M₂) :=
coe_injective.unique
/-- The sum of two linear maps is linear. -/
instance : has_add (M →ₗ[R] M₂) :=
⟨λ f g, ⟨λ b, f b + g b, by simp [add_comm, add_left_comm], by simp [smul_add]⟩⟩
@[simp] lemma add_apply (x : M) : (f + g) x = f x + g x := rfl
/-- The type of linear maps is an additive monoid. -/
instance : add_comm_monoid (M →ₗ[R] M₂) :=
by refine {zero := 0, add := (+), ..};
intros; ext; simp [add_comm, add_left_comm]
instance linear_map_apply_is_add_monoid_hom (a : M) :
is_add_monoid_hom (λ f : M →ₗ[R] M₂, f a) :=
{ map_add := λ f g, linear_map.add_apply f g a,
map_zero := rfl }
lemma add_comp (g : M₂ →ₗ[R] M₃) (h : M₂ →ₗ[R] M₃) :
(h + g).comp f = h.comp f + g.comp f := rfl
lemma comp_add (g : M →ₗ[R] M₂) (h : M₂ →ₗ[R] M₃) :
h.comp (f + g) = h.comp f + h.comp g := by { ext, simp }
lemma sum_apply (t : finset ι) (f : ι → M →ₗ[R] M₂) (b : M) :
(∑ d in t, f d) b = ∑ d in t, f d b :=
(t.sum_hom (λ g : M →ₗ[R] M₂, g b)).symm
/-- `λb, f b • x` is a linear map. -/
def smul_right (f : M₂ →ₗ[R] R) (x : M) : M₂ →ₗ[R] M :=
⟨λb, f b • x, by simp [add_smul], by simp [smul_smul]⟩.
@[simp] theorem smul_right_apply (f : M₂ →ₗ[R] R) (x : M) (c : M₂) :
(smul_right f x : M₂ → M) c = f c • x := rfl
instance : has_one (M →ₗ[R] M) := ⟨linear_map.id⟩
instance : has_mul (M →ₗ[R] M) := ⟨linear_map.comp⟩
lemma mul_eq_comp (f g : M →ₗ[R] M) : f * g = f.comp g := rfl
@[simp] lemma one_app (x : M) : (1 : M →ₗ[R] M) x = x := rfl
@[simp] lemma mul_app (A B : M →ₗ[R] M) (x : M) : (A * B) x = A (B x) := rfl
@[simp] theorem comp_zero : f.comp (0 : M₃ →ₗ[R] M) = 0 :=
ext $ assume c, by rw [comp_apply, zero_apply, zero_apply, f.map_zero]
@[simp] theorem zero_comp : (0 : M₂ →ₗ[R] M₃).comp f = 0 :=
rfl
@[norm_cast] lemma coe_fn_sum {ι : Type*} (t : finset ι) (f : ι → M →ₗ[R] M₂) :
⇑(∑ i in t, f i) = ∑ i in t, (f i : M → M₂) :=
add_monoid_hom.map_sum ⟨@to_fun R M M₂ _ _ _ _ _, rfl, λ x y, rfl⟩ _ _
instance : monoid (M →ₗ[R] M) :=
by refine {mul := (*), one := 1, ..}; { intros, apply linear_map.ext, simp {proj := ff} }
section
open_locale classical
/-- A linear map `f` applied to `x : ι → R` can be computed using the image under `f` of elements
of the canonical basis. -/
lemma pi_apply_eq_sum_univ [fintype ι] (f : (ι → R) →ₗ[R] M) (x : ι → R) :
f x = ∑ i, x i • (f (λj, if i = j then 1 else 0)) :=
begin
conv_lhs { rw [pi_eq_sum_univ x, f.map_sum] },
apply finset.sum_congr rfl (λl hl, _),
rw f.map_smul
end
end
section
variables (R M M₂)
/-- The first projection of a product is a linear map. -/
def fst : M × M₂ →ₗ[R] M := ⟨prod.fst, λ x y, rfl, λ x y, rfl⟩
/-- The second projection of a product is a linear map. -/
def snd : M × M₂ →ₗ[R] M₂ := ⟨prod.snd, λ x y, rfl, λ x y, rfl⟩
end
@[simp] theorem fst_apply (x : M × M₂) : fst R M M₂ x = x.1 := rfl
@[simp] theorem snd_apply (x : M × M₂) : snd R M M₂ x = x.2 := rfl
/-- The prod of two linear maps is a linear map. -/
def prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : M →ₗ[R] M₂ × M₃ :=
{ to_fun := λ x, (f x, g x),
map_add' := λ x y, by simp only [prod.mk_add_mk, map_add],
map_smul' := λ c x, by simp only [prod.smul_mk, map_smul] }
@[simp] theorem prod_apply (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) (x : M) :
prod f g x = (f x, g x) := rfl
@[simp] theorem fst_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) :
(fst R M₂ M₃).comp (prod f g) = f := by ext; refl
@[simp] theorem snd_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) :
(snd R M₂ M₃).comp (prod f g) = g := by ext; refl
@[simp] theorem pair_fst_snd : prod (fst R M M₂) (snd R M M₂) = linear_map.id :=
by ext; refl
section
variables (R M M₂)
/-- The left injection into a product is a linear map. -/
def inl : M →ₗ[R] M × M₂ := by refine ⟨add_monoid_hom.inl _ _, _, _⟩; intros; simp
/-- The right injection into a product is a linear map. -/
def inr : M₂ →ₗ[R] M × M₂ := by refine ⟨add_monoid_hom.inr _ _, _, _⟩; intros; simp
end
@[simp] theorem inl_apply (x : M) : inl R M M₂ x = (x, 0) := rfl
@[simp] theorem inr_apply (x : M₂) : inr R M M₂ x = (0, x) := rfl
theorem inl_injective : function.injective (inl R M M₂) :=
λ _, by simp
theorem inr_injective : function.injective (inr R M M₂) :=
λ _, by simp
/-- The coprod function `λ x : M × M₂, f x.1 + g x.2` is a linear map. -/
def coprod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : M × M₂ →ₗ[R] M₃ :=
{ to_fun := λ x, f x.1 + g x.2,
map_add' := λ x y, by simp only [map_add, prod.snd_add, prod.fst_add]; cc,
map_smul' := λ x y, by simp only [smul_add, prod.smul_snd, prod.smul_fst, map_smul] }
@[simp] theorem coprod_apply (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (x : M) (y : M₂) :
coprod f g (x, y) = f x + g y := rfl
@[simp] theorem coprod_inl (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) :
(coprod f g).comp (inl R M M₂) = f :=
by ext; simp only [map_zero, add_zero, coprod_apply, inl_apply, comp_apply]
@[simp] theorem coprod_inr (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) :
(coprod f g).comp (inr R M M₂) = g :=
by ext; simp only [map_zero, coprod_apply, inr_apply, zero_add, comp_apply]
@[simp] theorem coprod_inl_inr : coprod (inl R M M₂) (inr R M M₂) = linear_map.id :=
by ext ⟨x, y⟩; simp only [prod.mk_add_mk, add_zero, id_apply, coprod_apply,
inl_apply, inr_apply, zero_add]
theorem fst_eq_coprod : fst R M M₂ = coprod linear_map.id 0 := by ext ⟨x, y⟩; simp
theorem snd_eq_coprod : snd R M M₂ = coprod 0 linear_map.id := by ext ⟨x, y⟩; simp
theorem inl_eq_prod : inl R M M₂ = prod linear_map.id 0 := rfl
theorem inr_eq_prod : inr R M M₂ = prod 0 linear_map.id := rfl
/-- `prod.map` of two linear maps. -/
def prod_map (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) : (M × M₂) →ₗ[R] (M₃ × M₄) :=
(f.comp (fst R M M₂)).prod (g.comp (snd R M M₂))
@[simp] theorem prod_map_apply (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) (x) :
f.prod_map g x = (f x.1, g x.2) := rfl
end add_comm_monoid
section add_comm_group
variables [semiring R]
[add_comm_monoid M] [add_comm_group M₂] [add_comm_group M₃] [add_comm_group M₄]
[semimodule R M] [semimodule R M₂] [semimodule R M₃] [semimodule R M₄]
(f g : M →ₗ[R] M₂)
/-- The negation of a linear map is linear. -/
instance : has_neg (M →ₗ[R] M₂) :=
⟨λ f, ⟨λ b, - f b, by simp [add_comm], by simp⟩⟩
@[simp] lemma neg_apply (x : M) : (- f) x = - f x := rfl
@[simp] lemma comp_neg (g : M₂ →ₗ[R] M₃) : g.comp (- f) = - g.comp f := by { ext, simp }
/-- The type of linear maps is an additive group. -/
instance : add_comm_group (M →ₗ[R] M₂) :=
by refine {zero := 0, add := (+), neg := has_neg.neg, ..};
intros; ext; simp [add_comm, add_left_comm]
instance linear_map_apply_is_add_group_hom (a : M) :
is_add_group_hom (λ f : M →ₗ[R] M₂, f a) :=
{ map_add := λ f g, linear_map.add_apply f g a }
@[simp] lemma sub_apply (x : M) : (f - g) x = f x - g x := rfl
lemma sub_comp (g : M₂ →ₗ[R] M₃) (h : M₂ →ₗ[R] M₃) :
(g - h).comp f = g.comp f - h.comp f := rfl
lemma comp_sub (g : M →ₗ[R] M₂) (h : M₂ →ₗ[R] M₃) :
h.comp (g - f) = h.comp g - h.comp f := by { ext, simp }
end add_comm_group
section has_scalar
variables {S : Type*} [semiring R] [monoid S]
[add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃]
[semimodule R M] [semimodule R M₂] [semimodule R M₃]
[distrib_mul_action S M₂] [smul_comm_class R S M₂]
(f : M →ₗ[R] M₂)
instance : has_scalar S (M →ₗ[R] M₂) :=
⟨λ a f, ⟨λ b, a • f b, λ x y, by rw [f.map_add, smul_add],
λ c x, by simp only [f.map_smul, smul_comm c]⟩⟩
@[simp] lemma smul_apply (a : S) (x : M) : (a • f) x = a • f x := rfl
instance : distrib_mul_action S (M →ₗ[R] M₂) :=
{ one_smul := λ f, ext $ λ _, one_smul _ _,
mul_smul := λ c c' f, ext $ λ _, mul_smul _ _ _,
smul_add := λ c f g, ext $ λ x, smul_add _ _ _,
smul_zero := λ c, ext $ λ x, smul_zero _ }
theorem smul_comp (a : S) (g : M₃ →ₗ[R] M₂) (f : M →ₗ[R] M₃) : (a • g).comp f = a • (g.comp f) :=
rfl
end has_scalar
section semimodule
variables {S : Type*} [semiring R] [semiring S]
[add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃]
[semimodule R M] [semimodule R M₂] [semimodule R M₃]
[semimodule S M₂] [semimodule S M₃] [smul_comm_class R S M₂] [smul_comm_class R S M₃]
(f : M →ₗ[R] M₂)
instance : semimodule S (M →ₗ[R] M₂) :=
{ add_smul := λ a b f, ext $ λ x, add_smul _ _ _,
zero_smul := λ f, ext $ λ x, zero_smul _ _ }
variable (S)
/-- Applying a linear map at `v : M`, seen as `S`-linear map from `M →ₗ[R] M₂` to `M₂`.
See `applyₗ` for a version where `S = R` -/
def applyₗ' (v : M) : (M →ₗ[R] M₂) →ₗ[S] M₂ :=
{ to_fun := λ f, f v,
map_add' := λ f g, f.add_apply g v,
map_smul' := λ x f, f.smul_apply x v }
end semimodule
section comm_semiring
variables [comm_semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃]
variables [semimodule R M] [semimodule R M₂] [semimodule R M₃]
variables (f g : M →ₗ[R] M₂)
include R
theorem comp_smul (g : M₂ →ₗ[R] M₃) (a : R) : g.comp (a • f) = a • (g.comp f) :=
ext $ assume b, by rw [comp_apply, smul_apply, g.map_smul]; refl
/-- Composition by `f : M₂ → M₃` is a linear map from the space of linear maps `M → M₂`
to the space of linear maps `M₂ → M₃`. -/
def comp_right (f : M₂ →ₗ[R] M₃) : (M →ₗ[R] M₂) →ₗ[R] (M →ₗ[R] M₃) :=
⟨f.comp,
λ _ _, linear_map.ext $ λ _, f.2 _ _,
λ _ _, linear_map.ext $ λ _, f.3 _ _⟩
/-- Applying a linear map at `v : M`, seen as a linear map from `M →ₗ[R] M₂` to `M₂`.
See also `linear_map.applyₗ'` for a version that works with two different semirings. -/
def applyₗ (v : M) : (M →ₗ[R] M₂) →ₗ[R] M₂ :=
applyₗ' R v
end comm_semiring
section semiring
variables [semiring R] [add_comm_monoid M] [semimodule R M]
instance endomorphism_semiring : semiring (M →ₗ[R] M) :=
by refine {mul := (*), one := 1, ..linear_map.add_comm_monoid, ..};
{ intros, apply linear_map.ext, simp {proj := ff} }
lemma mul_apply (f g : M →ₗ[R] M) (x : M) : (f * g) x = f (g x) := rfl
end semiring
section ring
variables [ring R] [add_comm_group M] [semimodule R M]
instance endomorphism_ring : ring (M →ₗ[R] M) :=
{ ..linear_map.endomorphism_semiring, ..linear_map.add_comm_group }
end ring
section comm_ring
variables [comm_ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
variables [semimodule R M] [semimodule R M₂] [semimodule R M₃]
/--
The family of linear maps `M₂ → M` parameterised by `f ∈ M₂ → R`, `x ∈ M`, is linear in `f`, `x`.
-/
def smul_rightₗ : (M₂ →ₗ[R] R) →ₗ[R] M →ₗ[R] M₂ →ₗ[R] M :=
{ to_fun := λ f, {
to_fun := linear_map.smul_right f,
map_add' := λ m m', by { ext, apply smul_add, },
map_smul' := λ c m, by { ext, apply smul_comm, } },
map_add' := λ f f', by { ext, apply add_smul, },
map_smul' := λ c f, by { ext, apply mul_smul, } }
@[simp] lemma smul_rightₗ_apply (f : M₂ →ₗ[R] R) (x : M) (c : M₂) :
(smul_rightₗ : (M₂ →ₗ R) →ₗ M →ₗ M₂ →ₗ M) f x c = (f c) • x := rfl
end comm_ring
end linear_map
/-! ### Properties of submodules -/
namespace submodule
section add_comm_monoid
variables [semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃]
variables [semimodule R M] [semimodule R M₂] [semimodule R M₃]
variables (p p' : submodule R M) (q q' : submodule R M₂)
variables {r : R} {x y : M}
open set
instance : partial_order (submodule R M) :=
{ le := λ p p', ∀ ⦃x⦄, x ∈ p → x ∈ p',
..partial_order.lift (coe : submodule R M → set M) coe_injective }
variables {p p'}
lemma le_def : p ≤ p' ↔ (p : set M) ⊆ p' := iff.rfl
lemma le_def' : p ≤ p' ↔ ∀ x ∈ p, x ∈ p' := iff.rfl
lemma lt_def : p < p' ↔ (p : set M) ⊂ p' := iff.rfl
lemma not_le_iff_exists : ¬ (p ≤ p') ↔ ∃ x ∈ p, x ∉ p' := not_subset
lemma exists_of_lt {p p' : submodule R M} : p < p' → ∃ x ∈ p', x ∉ p := exists_of_ssubset
lemma lt_iff_le_and_exists : p < p' ↔ p ≤ p' ∧ ∃ x ∈ p', x ∉ p :=
by rw [lt_iff_le_not_le, not_le_iff_exists]
/-- If two submodules `p` and `p'` satisfy `p ⊆ p'`, then `of_le p p'` is the linear map version of
this inclusion. -/
def of_le (h : p ≤ p') : p →ₗ[R] p' :=
p.subtype.cod_restrict p' $ λ ⟨x, hx⟩, h hx
@[simp] theorem coe_of_le (h : p ≤ p') (x : p) :
(of_le h x : M) = x := rfl
theorem of_le_apply (h : p ≤ p') (x : p) : of_le h x = ⟨x, h x.2⟩ := rfl
variables (p p')
lemma subtype_comp_of_le (p q : submodule R M) (h : p ≤ q) :
q.subtype.comp (of_le h) = p.subtype :=
by { ext ⟨b, hb⟩, refl }
/-- The set `{0}` is the bottom element of the lattice of submodules. -/
instance : has_bot (submodule R M) :=
⟨{ carrier := {0}, smul_mem' := by simp { contextual := tt }, .. (⊥ : add_submonoid M)}⟩
instance inhabited' : inhabited (submodule R M) := ⟨⊥⟩
@[simp] lemma bot_coe : ((⊥ : submodule R M) : set M) = {0} := rfl
section
variables (R)
@[simp] lemma mem_bot : x ∈ (⊥ : submodule R M) ↔ x = 0 := mem_singleton_iff
end
lemma nonzero_mem_of_bot_lt {I : submodule R M} (bot_lt : ⊥ < I) : ∃ a : I, a ≠ 0 :=
begin
have h := (submodule.lt_iff_le_and_exists.1 bot_lt).2,
tidy,
end
instance : order_bot (submodule R M) :=
{ bot := ⊥,
bot_le := λ p x, by simp {contextual := tt},
..submodule.partial_order }
protected lemma eq_bot_iff (p : submodule R M) : p = ⊥ ↔ ∀ x ∈ p, x = (0 : M) :=
⟨ λ h, h.symm ▸ λ x hx, (mem_bot R).mp hx,
λ h, eq_bot_iff.mpr (λ x hx, (mem_bot R).mpr (h x hx)) ⟩
protected lemma ne_bot_iff (p : submodule R M) : p ≠ ⊥ ↔ ∃ x ∈ p, x ≠ (0 : M) :=
by { haveI := classical.prop_decidable, simp_rw [ne.def, p.eq_bot_iff, not_forall] }
/-- The universal set is the top element of the lattice of submodules. -/
instance : has_top (submodule R M) :=
⟨{ carrier := univ, smul_mem' := λ _ _ _, trivial, .. (⊤ : add_submonoid M)}⟩
@[simp] lemma top_coe : ((⊤ : submodule R M) : set M) = univ := rfl
@[simp] lemma mem_top : x ∈ (⊤ : submodule R M) := trivial
lemma eq_bot_of_zero_eq_one (zero_eq_one : (0 : R) = 1) : p = ⊥ :=
by ext x; simp [semimodule.eq_zero_of_zero_eq_one x zero_eq_one]
instance : order_top (submodule R M) :=
{ top := ⊤,
le_top := λ p x _, trivial,
..submodule.partial_order }
instance : has_Inf (submodule R M) :=
⟨λ S, {
carrier := ⋂ s ∈ S, (s : set M),
zero_mem' := by simp,
add_mem' := by simp [add_mem] {contextual := tt},
smul_mem' := by simp [smul_mem] {contextual := tt} }⟩
private lemma Inf_le' {S : set (submodule R M)} {p} : p ∈ S → Inf S ≤ p :=
bInter_subset_of_mem
private lemma le_Inf' {S : set (submodule R M)} {p} : (∀p' ∈ S, p ≤ p') → p ≤ Inf S :=
subset_bInter
instance : has_inf (submodule R M) :=
⟨λ p p', {
carrier := p ∩ p',
zero_mem' := by simp,
add_mem' := by simp [add_mem] {contextual := tt},
smul_mem' := by simp [smul_mem] {contextual := tt} }⟩
instance : complete_lattice (submodule R M) :=
{ sup := λ a b, Inf {x | a ≤ x ∧ b ≤ x},
le_sup_left := λ a b, le_Inf' $ λ x ⟨ha, hb⟩, ha,
le_sup_right := λ a b, le_Inf' $ λ x ⟨ha, hb⟩, hb,
sup_le := λ a b c h₁ h₂, Inf_le' ⟨h₁, h₂⟩,
inf := (⊓),
le_inf := λ a b c, subset_inter,
inf_le_left := λ a b, inter_subset_left _ _,
inf_le_right := λ a b, inter_subset_right _ _,
Sup := λtt, Inf {t | ∀t'∈tt, t' ≤ t},
le_Sup := λ s p hs, le_Inf' $ λ p' hp', hp' _ hs,
Sup_le := λ s p hs, Inf_le' hs,
Inf := Inf,
le_Inf := λ s a, le_Inf',
Inf_le := λ s a, Inf_le',
..submodule.order_top,
..submodule.order_bot }
instance add_comm_monoid_submodule : add_comm_monoid (submodule R M) :=
{ add := (⊔),
add_assoc := λ _ _ _, sup_assoc,
zero := ⊥,
zero_add := λ _, bot_sup_eq,
add_zero := λ _, sup_bot_eq,
add_comm := λ _ _, sup_comm }
@[simp] lemma add_eq_sup (p q : submodule R M) : p + q = p ⊔ q := rfl
@[simp] lemma zero_eq_bot : (0 : submodule R M) = ⊥ := rfl
lemma eq_top_iff' {p : submodule R M} : p = ⊤ ↔ ∀ x, x ∈ p :=
eq_top_iff.trans ⟨λ h x, @h x trivial, λ h x _, h x⟩
lemma bot_ne_top [nontrivial M] : (⊥ : submodule R M) ≠ ⊤ :=
λ h, let ⟨a, ha⟩ := exists_ne (0 : M) in ha $ (mem_bot R).1 $ (eq_top_iff.1 h) trivial
@[simp] theorem inf_coe : (p ⊓ p' : set M) = p ∩ p' := rfl
@[simp] theorem mem_inf {p p' : submodule R M} :
x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := iff.rfl
@[simp] theorem Inf_coe (P : set (submodule R M)) : (↑(Inf P) : set M) = ⋂ p ∈ P, ↑p := rfl
@[simp] theorem infi_coe {ι} (p : ι → submodule R M) :
(↑⨅ i, p i : set M) = ⋂ i, ↑(p i) :=
by rw [infi, Inf_coe]; ext a; simp; exact
⟨λ h i, h _ i rfl, λ h i x e, e ▸ h _⟩
@[simp] lemma mem_Inf {S : set (submodule R M)} {x : M} : x ∈ Inf S ↔ ∀ p ∈ S, x ∈ p :=
set.mem_bInter_iff
@[simp] theorem mem_infi {ι} (p : ι → submodule R M) :
x ∈ (⨅ i, p i) ↔ ∀ i, x ∈ p i :=
by rw [← mem_coe, infi_coe, mem_Inter]; refl
theorem disjoint_def {p p' : submodule R M} :
disjoint p p' ↔ ∀ x ∈ p, x ∈ p' → x = (0:M) :=
show (∀ x, x ∈ p ∧ x ∈ p' → x ∈ ({0} : set M)) ↔ _, by simp
theorem disjoint_def' {p p' : submodule R M} :
disjoint p p' ↔ ∀ (x ∈ p) (y ∈ p'), x = y → x = (0:M) :=
disjoint_def.trans ⟨λ h x hx y hy hxy, h x hx $ hxy.symm ▸ hy,
λ h x hx hx', h _ hx x hx' rfl⟩
theorem mem_right_iff_eq_zero_of_disjoint {p p' : submodule R M} (h : disjoint p p') {x : p} :
(x:M) ∈ p' ↔ x = 0 :=
⟨λ hx, coe_eq_zero.1 $ disjoint_def.1 h x x.2 hx, λ h, h.symm ▸ p'.zero_mem⟩
theorem mem_left_iff_eq_zero_of_disjoint {p p' : submodule R M} (h : disjoint p p') {x : p'} :
(x:M) ∈ p ↔ x = 0 :=
⟨λ hx, coe_eq_zero.1 $ disjoint_def.1 h x hx x.2, λ h, h.symm ▸ p.zero_mem⟩
/-- The pushforward of a submodule `p ⊆ M` by `f : M → M₂` -/
def map (f : M →ₗ[R] M₂) (p : submodule R M) : submodule R M₂ :=
{ carrier := f '' p,
smul_mem' := by rintro a _ ⟨b, hb, rfl⟩; exact ⟨_, p.smul_mem _ hb, f.map_smul _ _⟩,
.. p.to_add_submonoid.map f.to_add_monoid_hom }
@[simp] lemma map_coe (f : M →ₗ[R] M₂) (p : submodule R M) :
(map f p : set M₂) = f '' p := rfl
@[simp] lemma mem_map {f : M →ₗ[R] M₂} {p : submodule R M} {x : M₂} :
x ∈ map f p ↔ ∃ y, y ∈ p ∧ f y = x := iff.rfl
theorem mem_map_of_mem {f : M →ₗ[R] M₂} {p : submodule R M} {r} (h : r ∈ p) : f r ∈ map f p :=
set.mem_image_of_mem _ h
@[simp] lemma map_id : map linear_map.id p = p :=
submodule.ext $ λ a, by simp
lemma map_comp (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) (p : submodule R M) :
map (g.comp f) p = map g (map f p) :=
submodule.coe_injective $ by simp [map_coe]; rw ← image_comp
lemma map_mono {f : M →ₗ[R] M₂} {p p' : submodule R M} : p ≤ p' → map f p ≤ map f p' :=
image_subset _
@[simp] lemma map_zero : map (0 : M →ₗ[R] M₂) p = ⊥ :=
have ∃ (x : M), x ∈ p := ⟨0, p.zero_mem⟩,
ext $ by simp [this, eq_comm]
/-- The pullback of a submodule `p ⊆ M₂` along `f : M → M₂` -/
def comap (f : M →ₗ[R] M₂) (p : submodule R M₂) : submodule R M :=
{ carrier := f ⁻¹' p,
smul_mem' := λ a x h, by simp [p.smul_mem _ h],
.. p.to_add_submonoid.comap f.to_add_monoid_hom }
@[simp] lemma comap_coe (f : M →ₗ[R] M₂) (p : submodule R M₂) :
(comap f p : set M) = f ⁻¹' p := rfl
@[simp] lemma mem_comap {f : M →ₗ[R] M₂} {p : submodule R M₂} :
x ∈ comap f p ↔ f x ∈ p := iff.rfl
lemma comap_id : comap linear_map.id p = p :=
submodule.coe_injective rfl
lemma comap_comp (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) (p : submodule R M₃) :
comap (g.comp f) p = comap f (comap g p) := rfl
lemma comap_mono {f : M →ₗ[R] M₂} {q q' : submodule R M₂} : q ≤ q' → comap f q ≤ comap f q' :=
preimage_mono
lemma map_le_iff_le_comap {f : M →ₗ[R] M₂} {p : submodule R M} {q : submodule R M₂} :
map f p ≤ q ↔ p ≤ comap f q := image_subset_iff
lemma gc_map_comap (f : M →ₗ[R] M₂) : galois_connection (map f) (comap f)
| p q := map_le_iff_le_comap
@[simp] lemma map_bot (f : M →ₗ[R] M₂) : map f ⊥ = ⊥ :=
(gc_map_comap f).l_bot
@[simp] lemma map_sup (f : M →ₗ[R] M₂) : map f (p ⊔ p') = map f p ⊔ map f p' :=
(gc_map_comap f).l_sup
@[simp] lemma map_supr {ι : Sort*} (f : M →ₗ[R] M₂) (p : ι → submodule R M) :
map f (⨆i, p i) = (⨆i, map f (p i)) :=
(gc_map_comap f).l_supr
@[simp] lemma comap_top (f : M →ₗ[R] M₂) : comap f ⊤ = ⊤ := rfl
@[simp] lemma comap_inf (f : M →ₗ[R] M₂) : comap f (q ⊓ q') = comap f q ⊓ comap f q' := rfl
@[simp] lemma comap_infi {ι : Sort*} (f : M →ₗ[R] M₂) (p : ι → submodule R M₂) :
comap f (⨅i, p i) = (⨅i, comap f (p i)) :=
(gc_map_comap f).u_infi
@[simp] lemma comap_zero : comap (0 : M →ₗ[R] M₂) q = ⊤ :=
ext $ by simp
lemma map_comap_le (f : M →ₗ[R] M₂) (q : submodule R M₂) : map f (comap f q) ≤ q :=
(gc_map_comap f).l_u_le _
lemma le_comap_map (f : M →ₗ[R] M₂) (p : submodule R M) : p ≤ comap f (map f p) :=
(gc_map_comap f).le_u_l _
--TODO(Mario): is there a way to prove this from order properties?
lemma map_inf_eq_map_inf_comap {f : M →ₗ[R] M₂}
{p : submodule R M} {p' : submodule R M₂} :
map f p ⊓ p' = map f (p ⊓ comap f p') :=
le_antisymm
(by rintro _ ⟨⟨x, h₁, rfl⟩, h₂⟩; exact ⟨_, ⟨h₁, h₂⟩, rfl⟩)
(le_inf (map_mono inf_le_left) (map_le_iff_le_comap.2 inf_le_right))
lemma map_comap_subtype : map p.subtype (comap p.subtype p') = p ⊓ p' :=
ext $ λ x, ⟨by rintro ⟨⟨_, h₁⟩, h₂, rfl⟩; exact ⟨h₁, h₂⟩, λ ⟨h₁, h₂⟩, ⟨⟨_, h₁⟩, h₂, rfl⟩⟩
lemma eq_zero_of_bot_submodule : ∀(b : (⊥ : submodule R M)), b = 0
| ⟨b', hb⟩ := subtype.eq $ show b' = 0, from (mem_bot R).1 hb
section
variables (R)
/-- The span of a set `s ⊆ M` is the smallest submodule of M that contains `s`. -/
def span (s : set M) : submodule R M := Inf {p | s ⊆ p}
end
variables {s t : set M}
lemma mem_span : x ∈ span R s ↔ ∀ p : submodule R M, s ⊆ p → x ∈ p :=
mem_bInter_iff
lemma subset_span : s ⊆ span R s :=
λ x h, mem_span.2 $ λ p hp, hp h
lemma span_le {p} : span R s ≤ p ↔ s ⊆ p :=
⟨subset.trans subset_span, λ ss x h, mem_span.1 h _ ss⟩
lemma span_mono (h : s ⊆ t) : span R s ≤ span R t :=
span_le.2 $ subset.trans h subset_span
lemma span_eq_of_le (h₁ : s ⊆ p) (h₂ : p ≤ span R s) : span R s = p :=
le_antisymm (span_le.2 h₁) h₂
@[simp] lemma span_eq : span R (p : set M) = p :=
span_eq_of_le _ (subset.refl _) subset_span
lemma map_span (f : M →ₗ[R] M₂) (s : set M) :
(span R s).map f = span R (f '' s) :=
eq.symm $ span_eq_of_le _ (set.image_subset f subset_span) $
map_le_iff_le_comap.2 $ span_le.2 $ λ x hx, subset_span ⟨x, hx, rfl⟩
/-- An induction principle for span membership. If `p` holds for 0 and all elements of `s`, and is
preserved under addition and scalar multiplication, then `p` holds for all elements of the span of
`s`. -/
@[elab_as_eliminator] lemma span_induction {p : M → Prop} (h : x ∈ span R s)
(Hs : ∀ x ∈ s, p x) (H0 : p 0)
(H1 : ∀ x y, p x → p y → p (x + y))
(H2 : ∀ (a:R) x, p x → p (a • x)) : p x :=
(@span_le _ _ _ _ _ _ ⟨p, H0, H1, H2⟩).2 Hs h
section
variables (R M)
/-- `span` forms a Galois insertion with the coercion from submodule to set. -/
protected def gi : galois_insertion (@span R M _ _ _) coe :=
{ choice := λ s _, span R s,
gc := λ s t, span_le,
le_l_u := λ s, subset_span,
choice_eq := λ s h, rfl }
end
@[simp] lemma span_empty : span R (∅ : set M) = ⊥ :=
(submodule.gi R M).gc.l_bot
@[simp] lemma span_univ : span R (univ : set M) = ⊤ :=
eq_top_iff.2 $ le_def.2 $ subset_span
lemma span_union (s t : set M) : span R (s ∪ t) = span R s ⊔ span R t :=
(submodule.gi R M).gc.l_sup
lemma span_Union {ι} (s : ι → set M) : span R (⋃ i, s i) = ⨆ i, span R (s i) :=
(submodule.gi R M).gc.l_supr
@[simp] theorem coe_supr_of_directed {ι} [hι : nonempty ι]
(S : ι → submodule R M) (H : directed (≤) S) :
((supr S : submodule R M) : set M) = ⋃ i, S i :=
begin
refine subset.antisymm _ (Union_subset $ le_supr S),
suffices : (span R (⋃ i, (S i : set M)) : set M) ⊆ ⋃ (i : ι), ↑(S i),
by simpa only [span_Union, span_eq] using this,
refine (λ x hx, span_induction hx (λ _, id) _ _ _);
simp only [mem_Union, exists_imp_distrib],
{ exact hι.elim (λ i, ⟨i, (S i).zero_mem⟩) },
{ intros x y i hi j hj,
rcases H i j with ⟨k, ik, jk⟩,
exact ⟨k, add_mem _ (ik hi) (jk hj)⟩ },
{ exact λ a x i hi, ⟨i, smul_mem _ a hi⟩ },
end
lemma mem_sup_left {S T : submodule R M} : ∀ {x : M}, x ∈ S → x ∈ S ⊔ T :=
show S ≤ S ⊔ T, from le_sup_left
lemma mem_sup_right {S T : submodule R M} : ∀ {x : M}, x ∈ T → x ∈ S ⊔ T :=
show T ≤ S ⊔ T, from le_sup_right
lemma mem_supr_of_mem {ι : Sort*} {b : M} {p : ι → submodule R M} (i : ι) (h : b ∈ p i) :
b ∈ (⨆i, p i) :=
have p i ≤ (⨆i, p i) := le_supr p i,
@this b h
lemma mem_Sup_of_mem {S : set (submodule R M)} {s : submodule R M}
(hs : s ∈ S) : ∀ {x : M}, x ∈ s → x ∈ Sup S :=
show s ≤ Sup S, from le_Sup hs
@[simp] theorem mem_supr_of_directed {ι} [nonempty ι]
(S : ι → submodule R M) (H : directed (≤) S) {x} :
x ∈ supr S ↔ ∃ i, x ∈ S i :=
by { rw [← mem_coe, coe_supr_of_directed S H, mem_Union], refl }
theorem mem_Sup_of_directed {s : set (submodule R M)}
{z} (hs : s.nonempty) (hdir : directed_on (≤) s) :
z ∈ Sup s ↔ ∃ y ∈ s, z ∈ y :=
begin
haveI : nonempty s := hs.to_subtype,
simp only [Sup_eq_supr', mem_supr_of_directed _ hdir.directed_coe, set_coe.exists, subtype.coe_mk]
end
section
variables {p p'}
lemma mem_sup : x ∈ p ⊔ p' ↔ ∃ (y ∈ p) (z ∈ p'), y + z = x :=
⟨λ h, begin
rw [← span_eq p, ← span_eq p', ← span_union] at h,
apply span_induction h,
{ rintro y (h | h),
{ exact ⟨y, h, 0, by simp, by simp⟩ },
{ exact ⟨0, by simp, y, h, by simp⟩ } },
{ exact ⟨0, by simp, 0, by simp⟩ },
{ rintro _ _ ⟨y₁, hy₁, z₁, hz₁, rfl⟩ ⟨y₂, hy₂, z₂, hz₂, rfl⟩,
exact ⟨_, add_mem _ hy₁ hy₂, _, add_mem _ hz₁ hz₂, by simp [add_assoc]; cc⟩ },
{ rintro a _ ⟨y, hy, z, hz, rfl⟩,
exact ⟨_, smul_mem _ a hy, _, smul_mem _ a hz, by simp [smul_add]⟩ }
end,
by rintro ⟨y, hy, z, hz, rfl⟩; exact add_mem _
((le_sup_left : p ≤ p ⊔ p') hy)
((le_sup_right : p' ≤ p ⊔ p') hz)⟩
lemma mem_sup' : x ∈ p ⊔ p' ↔ ∃ (y : p) (z : p'), (y:M) + z = x :=
mem_sup.trans $ by simp only [submodule.exists, coe_mk]
end
lemma mem_span_singleton_self (x : M) : x ∈ span R ({x} : set M) := subset_span rfl
lemma nontrivial_span_singleton {x : M} (h : x ≠ 0) : nontrivial (submodule.span R ({x} : set M)) :=
⟨begin
use [0, x, submodule.mem_span_singleton_self x],
intros H,
rw [eq_comm, submodule.mk_eq_zero] at H,
exact h H
end⟩
lemma mem_span_singleton {y : M} : x ∈ span R ({y} : set M) ↔ ∃ a:R, a • y = x :=
⟨λ h, begin
apply span_induction h,
{ rintro y (rfl|⟨⟨⟩⟩), exact ⟨1, by simp⟩ },
{ exact ⟨0, by simp⟩ },
{ rintro _ _ ⟨a, rfl⟩ ⟨b, rfl⟩,
exact ⟨a + b, by simp [add_smul]⟩ },
{ rintro a _ ⟨b, rfl⟩,
exact ⟨a * b, by simp [smul_smul]⟩ }
end,
by rintro ⟨a, y, rfl⟩; exact
smul_mem _ _ (subset_span $ by simp)⟩
lemma le_span_singleton_iff {s : submodule R M} {v₀ : M} :
s ≤ span R {v₀} ↔ ∀ v ∈ s, ∃ r : R, r • v₀ = v :=
by simp_rw [le_def', mem_span_singleton]
lemma span_singleton_eq_range (y : M) : (span R ({y} : set M) : set M) = range ((• y) : R → M) :=
set.ext $ λ x, mem_span_singleton
lemma span_singleton_smul_le (r : R) (x : M) : span R ({r • x} : set M) ≤ span R {x} :=
begin
rw [span_le, set.singleton_subset_iff, mem_coe],
exact smul_mem _ _ (mem_span_singleton_self _)
end
lemma span_singleton_smul_eq {K E : Type*} [division_ring K] [add_comm_group E] [module K E]
{r : K} (x : E) (hr : r ≠ 0) : span K ({r • x} : set E) = span K {x} :=
begin
refine le_antisymm (span_singleton_smul_le r x) _,
convert span_singleton_smul_le r⁻¹ (r • x),
exact (inv_smul_smul' hr _).symm
end
lemma disjoint_span_singleton {K E : Type*} [division_ring K] [add_comm_group E] [module K E]
{s : submodule K E} {x : E} :
disjoint s (span K {x}) ↔ (x ∈ s → x = 0) :=
begin
refine disjoint_def.trans ⟨λ H hx, H x hx $ subset_span $ mem_singleton x, _⟩,
assume H y hy hyx,
obtain ⟨c, hc⟩ := mem_span_singleton.1 hyx,
subst y,
classical, by_cases hc : c = 0, by simp only [hc, zero_smul],
rw [s.smul_mem_iff hc] at hy,
rw [H hy, smul_zero]
end
lemma disjoint_span_singleton' {K E : Type*} [division_ring K] [add_comm_group E] [module K E]
{p : submodule K E} {x : E} (x0 : x ≠ 0) :
disjoint p (span K {x}) ↔ x ∉ p :=
disjoint_span_singleton.trans ⟨λ h₁ h₂, x0 (h₁ h₂), λ h₁ h₂, (h₁ h₂).elim⟩
lemma mem_span_insert {y} : x ∈ span R (insert y s) ↔ ∃ (a:R) (z ∈ span R s), x = a • y + z :=
begin
simp only [← union_singleton, span_union, mem_sup, mem_span_singleton, exists_prop,
exists_exists_eq_and],
rw [exists_comm],
simp only [eq_comm, add_comm, exists_and_distrib_left]
end
lemma span_insert_eq_span (h : x ∈ span R s) : span R (insert x s) = span R s :=
span_eq_of_le _ (set.insert_subset.mpr ⟨h, subset_span⟩) (span_mono $ subset_insert _ _)
lemma span_span : span R (span R s : set M) = span R s := span_eq _
lemma span_eq_bot : span R (s : set M) = ⊥ ↔ ∀ x ∈ s, (x:M) = 0 :=
eq_bot_iff.trans ⟨
λ H x h, (mem_bot R).1 $ H $ subset_span h,
λ H, span_le.2 (λ x h, (mem_bot R).2 $ H x h)⟩
@[simp] lemma span_singleton_eq_bot : span R ({x} : set M) = ⊥ ↔ x = 0 :=
span_eq_bot.trans $ by simp
@[simp] lemma span_zero : span R (0 : set M) = ⊥ := by rw [←singleton_zero, span_singleton_eq_bot]
@[simp] lemma span_image (f : M →ₗ[R] M₂) : span R (f '' s) = map f (span R s) :=
span_eq_of_le _ (image_subset _ subset_span) $ map_le_iff_le_comap.2 $
span_le.2 $ image_subset_iff.1 subset_span
lemma supr_eq_span {ι : Sort w} (p : ι → submodule R M) :
(⨆ (i : ι), p i) = submodule.span R (⋃ (i : ι), ↑(p i)) :=
le_antisymm
(supr_le $ assume i, subset.trans (assume m hm, set.mem_Union.mpr ⟨i, hm⟩) subset_span)
(span_le.mpr $ Union_subset_iff.mpr $ assume i m hm, mem_supr_of_mem i hm)
lemma span_singleton_le_iff_mem (m : M) (p : submodule R M) :
span R {m} ≤ p ↔ m ∈ p :=
by rw [span_le, singleton_subset_iff, mem_coe]
lemma lt_add_iff_not_mem {I : submodule R M} {a : M} : I < I + span R {a} ↔ a ∉ I :=
begin
split,
{ intro h,
by_contra akey,
have h1 : I + span R {a} ≤ I,
{ simp only [add_eq_sup, sup_le_iff],
split,
{ exact le_refl I, },
{ exact (span_singleton_le_iff_mem a I).mpr akey, } },
have h2 := gt_of_ge_of_gt h1 h,
exact lt_irrefl I h2, },
{ intro h,
apply lt_iff_le_and_exists.mpr, split,
simp only [add_eq_sup, le_sup_left],
use a,
split, swap, { assumption, },
{ have : span R {a} ≤ I + span R{a} := le_sup_right,
exact this (mem_span_singleton_self a), } },
end
lemma mem_supr {ι : Sort w} (p : ι → submodule R M) {m : M} :
(m ∈ ⨆ i, p i) ↔ (∀ N, (∀ i, p i ≤ N) → m ∈ N) :=
begin
rw [← span_singleton_le_iff_mem, le_supr_iff],
simp only [span_singleton_le_iff_mem],
end
/-- The product of two submodules is a submodule. -/
def prod : submodule R (M × M₂) :=
{ carrier := set.prod p q,
smul_mem' := by rintro a ⟨x, y⟩ ⟨hx, hy⟩; exact ⟨smul_mem _ a hx, smul_mem _ a hy⟩,
.. p.to_add_submonoid.prod q.to_add_submonoid }
@[simp] lemma prod_coe :
(prod p q : set (M × M₂)) = set.prod p q := rfl
@[simp] lemma mem_prod {p : submodule R M} {q : submodule R M₂} {x : M × M₂} :
x ∈ prod p q ↔ x.1 ∈ p ∧ x.2 ∈ q := set.mem_prod
lemma span_prod_le (s : set M) (t : set M₂) :
span R (set.prod s t) ≤ prod (span R s) (span R t) :=
span_le.2 $ set.prod_mono subset_span subset_span
@[simp] lemma prod_top : (prod ⊤ ⊤ : submodule R (M × M₂)) = ⊤ :=
by ext; simp
@[simp] lemma prod_bot : (prod ⊥ ⊥ : submodule R (M × M₂)) = ⊥ :=
by ext ⟨x, y⟩; simp [prod.zero_eq_mk]
lemma prod_mono {p p' : submodule R M} {q q' : submodule R M₂} :
p ≤ p' → q ≤ q' → prod p q ≤ prod p' q' := prod_mono
@[simp] lemma prod_inf_prod : prod p q ⊓ prod p' q' = prod (p ⊓ p') (q ⊓ q') :=
coe_injective set.prod_inter_prod
@[simp] lemma prod_sup_prod : prod p q ⊔ prod p' q' = prod (p ⊔ p') (q ⊔ q') :=
begin
refine le_antisymm (sup_le
(prod_mono le_sup_left le_sup_left)
(prod_mono le_sup_right le_sup_right)) _,
simp [le_def'], intros xx yy hxx hyy,
rcases mem_sup.1 hxx with ⟨x, hx, x', hx', rfl⟩,
rcases mem_sup.1 hyy with ⟨y, hy, y', hy', rfl⟩,
refine mem_sup.2 ⟨(x, y), ⟨hx, hy⟩, (x', y'), ⟨hx', hy'⟩, rfl⟩
end
end add_comm_monoid
variables [ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
variables [semimodule R M] [semimodule R M₂] [semimodule R M₃]
variables (p p' : submodule R M) (q q' : submodule R M₂)
variables {r : R} {x y : M}
open set
@[simp] lemma neg_coe : -(p : set M) = p := set.ext $ λ x, p.neg_mem_iff
@[simp] protected lemma map_neg (f : M →ₗ[R] M₂) : map (-f) p = map f p :=
ext $ λ y, ⟨λ ⟨x, hx, hy⟩, hy ▸ ⟨-x, neg_mem _ hx, f.map_neg x⟩,
λ ⟨x, hx, hy⟩, hy ▸ ⟨-x, neg_mem _ hx, ((-f).map_neg _).trans (neg_neg (f x))⟩⟩
@[simp] lemma span_neg (s : set M) : span R (-s) = span R s :=
calc span R (-s) = span R ((-linear_map.id : M →ₗ[R] M) '' s) : by simp
... = map (-linear_map.id) (span R s) : (map_span _ _).symm
... = span R s : by simp
lemma mem_span_insert' {y} {s : set M} : x ∈ span R (insert y s) ↔ ∃(a:R), x + a • y ∈ span R s :=
begin
rw mem_span_insert, split,
{ rintro ⟨a, z, hz, rfl⟩, exact ⟨-a, by simp [hz, add_assoc]⟩ },
{ rintro ⟨a, h⟩, exact ⟨-a, _, h, by simp [add_comm, add_left_comm]⟩ }
end
-- TODO(Mario): Factor through add_subgroup
/-- The equivalence relation associated to a submodule `p`, defined by `x ≈ y` iff `y - x ∈ p`. -/
def quotient_rel : setoid M :=
⟨λ x y, x - y ∈ p, λ x, by simp,
λ x y h, by simpa using neg_mem _ h,
λ x y z h₁ h₂, by simpa [sub_eq_add_neg, add_left_comm, add_assoc] using add_mem _ h₁ h₂⟩
/-- The quotient of a module `M` by a submodule `p ⊆ M`. -/
def quotient : Type* := quotient (quotient_rel p)
namespace quotient
/-- Map associating to an element of `M` the corresponding element of `M/p`,
when `p` is a submodule of `M`. -/
def mk {p : submodule R M} : M → quotient p := quotient.mk'
@[simp] theorem mk_eq_mk {p : submodule R M} (x : M) : (quotient.mk x : quotient p) = mk x := rfl
@[simp] theorem mk'_eq_mk {p : submodule R M} (x : M) : (quotient.mk' x : quotient p) = mk x := rfl
@[simp] theorem quot_mk_eq_mk {p : submodule R M} (x : M) : (quot.mk _ x : quotient p) = mk x := rfl
protected theorem eq {x y : M} : (mk x : quotient p) = mk y ↔ x - y ∈ p := quotient.eq'
instance : has_zero (quotient p) := ⟨mk 0⟩
instance : inhabited (quotient p) := ⟨0⟩
@[simp] theorem mk_zero : mk 0 = (0 : quotient p) := rfl
@[simp] theorem mk_eq_zero : (mk x : quotient p) = 0 ↔ x ∈ p :=
by simpa using (quotient.eq p : mk x = 0 ↔ _)
instance : has_add (quotient p) :=
⟨λ a b, quotient.lift_on₂' a b (λ a b, mk (a + b)) $
λ a₁ a₂ b₁ b₂ h₁ h₂, (quotient.eq p).2 $
by simpa [sub_eq_add_neg, add_left_comm, add_comm] using add_mem p h₁ h₂⟩
@[simp] theorem mk_add : (mk (x + y) : quotient p) = mk x + mk y := rfl
instance : has_neg (quotient p) :=
⟨λ a, quotient.lift_on' a (λ a, mk (-a)) $
λ a b h, (quotient.eq p).2 $ by simpa using neg_mem p h⟩
@[simp] theorem mk_neg : (mk (-x) : quotient p) = -mk x := rfl
instance : add_comm_group (quotient p) :=
by refine {zero := 0, add := (+), neg := has_neg.neg, ..};
repeat {rintro ⟨⟩};
simp [-mk_zero, (mk_zero p).symm, -mk_add, (mk_add p).symm, -mk_neg, (mk_neg p).symm]; cc
instance : has_scalar R (quotient p) :=
⟨λ a x, quotient.lift_on' x (λ x, mk (a • x)) $
λ x y h, (quotient.eq p).2 $ by simpa [smul_sub] using smul_mem p a h⟩
@[simp] theorem mk_smul : (mk (r • x) : quotient p) = r • mk x := rfl
instance : semimodule R (quotient p) :=
semimodule.of_core $ by refine {smul := (•), ..};
repeat {rintro ⟨⟩ <|> intro}; simp [smul_add, add_smul, smul_smul,
-mk_add, (mk_add p).symm, -mk_smul, (mk_smul p).symm]
lemma mk_surjective : function.surjective (@mk _ _ _ _ _ p) :=
by { rintros ⟨x⟩, exact ⟨x, rfl⟩ }
lemma nontrivial_of_lt_top (h : p < ⊤) : nontrivial (p.quotient) :=
begin
obtain ⟨x, _, not_mem_s⟩ := exists_of_lt h,
refine ⟨⟨mk x, 0, _⟩⟩,
simpa using not_mem_s
end
end quotient
lemma quot_hom_ext ⦃f g : quotient p →ₗ[R] M₂⦄ (h : ∀ x, f (quotient.mk x) = g (quotient.mk x)) :
f = g :=
linear_map.ext $ λ x, quotient.induction_on' x h
end submodule
namespace submodule
variables [field K]
variables [add_comm_group V] [vector_space K V]
variables [add_comm_group V₂] [vector_space K V₂]
lemma comap_smul (f : V →ₗ[K] V₂) (p : submodule K V₂) (a : K) (h : a ≠ 0) :
p.comap (a • f) = p.comap f :=
by ext b; simp only [submodule.mem_comap, p.smul_mem_iff h, linear_map.smul_apply]
lemma map_smul (f : V →ₗ[K] V₂) (p : submodule K V) (a : K) (h : a ≠ 0) :
p.map (a • f) = p.map f :=
le_antisymm
begin rw [map_le_iff_le_comap, comap_smul f _ a h, ← map_le_iff_le_comap], exact le_refl _ end
begin rw [map_le_iff_le_comap, ← comap_smul f _ a h, ← map_le_iff_le_comap], exact le_refl _ end
lemma comap_smul' (f : V →ₗ[K] V₂) (p : submodule K V₂) (a : K) :
p.comap (a • f) = (⨅ h : a ≠ 0, p.comap f) :=
by classical; by_cases a = 0; simp [h, comap_smul]
lemma map_smul' (f : V →ₗ[K] V₂) (p : submodule K V) (a : K) :
p.map (a • f) = (⨆ h : a ≠ 0, p.map f) :=
by classical; by_cases a = 0; simp [h, map_smul]
end submodule
/-! ### Properties of linear maps -/
namespace linear_map
section add_comm_monoid
variables [semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃]
variables [semimodule R M] [semimodule R M₂] [semimodule R M₃]
include R
open submodule
/-- If two linear maps are equal on a set `s`, then they are equal on `submodule.span s`.
See also `linear_map.eq_on_span'` for a version using `set.eq_on`. -/
lemma eq_on_span {s : set M} {f g : M →ₗ[R] M₂} (H : set.eq_on f g s) ⦃x⦄ (h : x ∈ span R s) :
f x = g x :=
by apply span_induction h H; simp {contextual := tt}
/-- If two linear maps are equal on a set `s`, then they are equal on `submodule.span s`.
This version uses `set.eq_on`, and the hidden argument will expand to `h : x ∈ (span R s : set M)`.
See `linear_map.eq_on_span` for a version that takes `h : x ∈ span R s` as an argument. -/
lemma eq_on_span' {s : set M} {f g : M →ₗ[R] M₂} (H : set.eq_on f g s) :
set.eq_on f g (span R s : set M) :=
eq_on_span H
/-- If `s` generates the whole semimodule and linear maps `f`, `g` are equal on `s`, then they are
equal. -/
lemma ext_on {s : set M} {f g : M →ₗ[R] M₂} (hv : span R s = ⊤) (h : set.eq_on f g s) :
f = g :=
linear_map.ext (λ x, eq_on_span h (eq_top_iff'.1 hv _))
/-- If the range of `v : ι → M` generates the whole semimodule and linear maps `f`, `g` are equal at
each `v i`, then they are equal. -/
lemma ext_on_range {v : ι → M} {f g : M →ₗ[R] M₂} (hv : span R (set.range v) = ⊤)
(h : ∀i, f (v i) = g (v i)) : f = g :=
ext_on hv (set.forall_range_iff.2 h)
@[simp] lemma finsupp_sum {γ} [has_zero γ]
(f : M →ₗ[R] M₂) {t : ι →₀ γ} {g : ι → γ → M} :
f (t.sum g) = t.sum (λi d, f (g i d)) := f.map_sum
theorem map_cod_restrict (p : submodule R M) (f : M₂ →ₗ[R] M) (h p') :
submodule.map (cod_restrict p f h) p' = comap p.subtype (p'.map f) :=
submodule.ext $ λ ⟨x, hx⟩, by simp [subtype.ext_iff_val]
theorem comap_cod_restrict (p : submodule R M) (f : M₂ →ₗ[R] M) (hf p') :
submodule.comap (cod_restrict p f hf) p' = submodule.comap f (map p.subtype p') :=
submodule.ext $ λ x, ⟨λ h, ⟨⟨_, hf x⟩, h, rfl⟩, by rintro ⟨⟨_, _⟩, h, ⟨⟩⟩; exact h⟩
/-- The range of a linear map `f : M → M₂` is a submodule of `M₂`. -/
def range (f : M →ₗ[R] M₂) : submodule R M₂ := map f ⊤
theorem range_coe (f : M →ₗ[R] M₂) : (range f : set M₂) = set.range f := set.image_univ
@[simp] theorem mem_range {f : M →ₗ[R] M₂} : ∀ {x}, x ∈ range f ↔ ∃ y, f y = x :=
set.ext_iff.1 (range_coe f)
theorem mem_range_self (f : M →ₗ[R] M₂) (x : M) : f x ∈ f.range := mem_range.2 ⟨x, rfl⟩
@[simp] theorem range_id : range (linear_map.id : M →ₗ[R] M) = ⊤ := map_id _
theorem range_comp (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : range (g.comp f) = map g (range f) :=
map_comp _ _ _
theorem range_comp_le_range (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : range (g.comp f) ≤ range g :=
by rw range_comp; exact map_mono le_top
theorem range_eq_top {f : M →ₗ[R] M₂} : range f = ⊤ ↔ surjective f :=
by rw [submodule.ext'_iff, range_coe, top_coe, set.range_iff_surjective]
lemma range_le_iff_comap {f : M →ₗ[R] M₂} {p : submodule R M₂} : range f ≤ p ↔ comap f p = ⊤ :=
by rw [range, map_le_iff_le_comap, eq_top_iff]
lemma map_le_range {f : M →ₗ[R] M₂} {p : submodule R M} : map f p ≤ range f :=
map_mono le_top
lemma range_coprod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) :
(f.coprod g).range = f.range ⊔ g.range :=
submodule.ext $ λ x, by simp [mem_sup]
lemma is_compl_range_inl_inr : is_compl (inl R M M₂).range (inr R M M₂).range :=
begin
split,
{ rintros ⟨_, _⟩ ⟨⟨x, -, hx⟩, ⟨y, -, hy⟩⟩,
simp only [prod.ext_iff, inl_apply, inr_apply, mem_bot] at hx hy ⊢,
exact ⟨hy.1.symm, hx.2.symm⟩ },
{ rintros ⟨x, y⟩ -,
simp only [mem_sup, mem_range, exists_prop],
refine ⟨(x, 0), ⟨x, rfl⟩, (0, y), ⟨y, rfl⟩, _⟩,
simp }
end
lemma sup_range_inl_inr : (inl R M M₂).range ⊔ (inr R M M₂).range = ⊤ :=
is_compl_range_inl_inr.sup_eq_top
/-- Restrict the codomain of a linear map `f` to `f.range`. -/
@[reducible] def range_restrict (f : M →ₗ[R] M₂) : M →ₗ[R] f.range :=
f.cod_restrict f.range f.mem_range_self
section
variables (R) (M)
/-- Given an element `x` of a module `M` over `R`, the natural map from
`R` to scalar multiples of `x`.-/
def to_span_singleton (x : M) : R →ₗ[R] M := linear_map.id.smul_right x
/-- The range of `to_span_singleton x` is the span of `x`.-/
lemma span_singleton_eq_range (x : M) : span R {x} = (to_span_singleton R M x).range :=
submodule.ext $ λ y, by {refine iff.trans _ mem_range.symm, exact mem_span_singleton }
lemma to_span_singleton_one (x : M) : to_span_singleton R M x 1 = x := one_smul _ _
end
/-- The kernel of a linear map `f : M → M₂` is defined to be `comap f ⊥`. This is equivalent to the
set of `x : M` such that `f x = 0`. The kernel is a submodule of `M`. -/
def ker (f : M →ₗ[R] M₂) : submodule R M := comap f ⊥
@[simp] theorem mem_ker {f : M →ₗ[R] M₂} {y} : y ∈ ker f ↔ f y = 0 := mem_bot R
@[simp] theorem ker_id : ker (linear_map.id : M →ₗ[R] M) = ⊥ := rfl
@[simp] theorem map_coe_ker (f : M →ₗ[R] M₂) (x : ker f) : f x = 0 := mem_ker.1 x.2
lemma comp_ker_subtype (f : M →ₗ[R] M₂) : f.comp f.ker.subtype = 0 :=
linear_map.ext $ λ x, suffices f x = 0, by simp [this], mem_ker.1 x.2
theorem ker_comp (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : ker (g.comp f) = comap f (ker g) := rfl
theorem ker_le_ker_comp (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : ker f ≤ ker (g.comp f) :=
by rw ker_comp; exact comap_mono bot_le
theorem disjoint_ker {f : M →ₗ[R] M₂} {p : submodule R M} :
disjoint p (ker f) ↔ ∀ x ∈ p, f x = 0 → x = 0 :=
by simp [disjoint_def]
lemma disjoint_inl_inr : disjoint (inl R M M₂).range (inr R M M₂).range :=
by simp [disjoint_def, @eq_comm M 0, @eq_comm M₂ 0] {contextual := tt}; intros; refl
theorem ker_eq_bot' {f : M →ₗ[R] M₂} :
ker f = ⊥ ↔ (∀ m, f m = 0 → m = 0) :=
by simpa [disjoint] using @disjoint_ker _ _ _ _ _ _ _ _ f ⊤
lemma le_ker_iff_map {f : M →ₗ[R] M₂} {p : submodule R M} : p ≤ ker f ↔ map f p = ⊥ :=
by rw [ker, eq_bot_iff, map_le_iff_le_comap]
lemma ker_cod_restrict (p : submodule R M) (f : M₂ →ₗ[R] M) (hf) :
ker (cod_restrict p f hf) = ker f :=
by rw [ker, comap_cod_restrict, map_bot]; refl
lemma range_cod_restrict (p : submodule R M) (f : M₂ →ₗ[R] M) (hf) :
range (cod_restrict p f hf) = comap p.subtype f.range :=
map_cod_restrict _ _ _ _
lemma ker_restrict {p : submodule R M} {f : M →ₗ[R] M} (hf : ∀ x : M, x ∈ p → f x ∈ p) :
ker (f.restrict hf) = (f.dom_restrict p).ker :=
by rw [restrict_eq_cod_restrict_dom_restrict, ker_cod_restrict]
lemma map_comap_eq (f : M →ₗ[R] M₂) (q : submodule R M₂) :
map f (comap f q) = range f ⊓ q :=
le_antisymm (le_inf (map_mono le_top) (map_comap_le _ _)) $
by rintro _ ⟨⟨x, _, rfl⟩, hx⟩; exact ⟨x, hx, rfl⟩
lemma map_comap_eq_self {f : M →ₗ[R] M₂} {q : submodule R M₂} (h : q ≤ range f) :
map f (comap f q) = q :=
by rwa [map_comap_eq, inf_eq_right]
@[simp] theorem ker_zero : ker (0 : M →ₗ[R] M₂) = ⊤ :=
eq_top_iff'.2 $ λ x, by simp
@[simp] theorem range_zero : range (0 : M →ₗ[R] M₂) = ⊥ :=
submodule.map_zero _
theorem ker_eq_top {f : M →ₗ[R] M₂} : ker f = ⊤ ↔ f = 0 :=
⟨λ h, ext $ λ x, mem_ker.1 $ h.symm ▸ trivial, λ h, h.symm ▸ ker_zero⟩
lemma range_le_bot_iff (f : M →ₗ[R] M₂) : range f ≤ ⊥ ↔ f = 0 :=
by rw [range_le_iff_comap]; exact ker_eq_top
lemma range_le_ker_iff {f : M →ₗ[R] M₂} {g : M₂ →ₗ[R] M₃} : range f ≤ ker g ↔ g.comp f = 0 :=
⟨λ h, ker_eq_top.1 $ eq_top_iff'.2 $ λ x, h $ mem_map_of_mem trivial,
λ h x hx, mem_ker.2 $ exists.elim hx $ λ y ⟨_, hy⟩, by rw [←hy, ←comp_apply, h, zero_apply]⟩
theorem comap_le_comap_iff {f : M →ₗ[R] M₂} (hf : range f = ⊤) {p p'} :
comap f p ≤ comap f p' ↔ p ≤ p' :=
⟨λ H x hx, by rcases range_eq_top.1 hf x with ⟨y, hy, rfl⟩; exact H hx, comap_mono⟩
theorem comap_injective {f : M →ₗ[R] M₂} (hf : range f = ⊤) : injective (comap f) :=
λ p p' h, le_antisymm ((comap_le_comap_iff hf).1 (le_of_eq h))
((comap_le_comap_iff hf).1 (ge_of_eq h))
theorem map_coprod_prod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃)
(p : submodule R M) (q : submodule R M₂) :
map (coprod f g) (p.prod q) = map f p ⊔ map g q :=
begin
refine le_antisymm _ (sup_le (map_le_iff_le_comap.2 _) (map_le_iff_le_comap.2 _)),
{ rw le_def', rintro _ ⟨x, ⟨h₁, h₂⟩, rfl⟩,
exact mem_sup.2 ⟨_, ⟨_, h₁, rfl⟩, _, ⟨_, h₂, rfl⟩, rfl⟩ },
{ exact λ x hx, ⟨(x, 0), by simp [hx]⟩ },
{ exact λ x hx, ⟨(0, x), by simp [hx]⟩ }
end
theorem comap_prod_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃)
(p : submodule R M₂) (q : submodule R M₃) :
comap (prod f g) (p.prod q) = comap f p ⊓ comap g q :=
submodule.ext $ λ x, iff.rfl
theorem prod_eq_inf_comap (p : submodule R M) (q : submodule R M₂) :
p.prod q = p.comap (linear_map.fst R M M₂) ⊓ q.comap (linear_map.snd R M M₂) :=
submodule.ext $ λ x, iff.rfl
theorem prod_eq_sup_map (p : submodule R M) (q : submodule R M₂) :
p.prod q = p.map (linear_map.inl R M M₂) ⊔ q.map (linear_map.inr R M M₂) :=
by rw [← map_coprod_prod, coprod_inl_inr, map_id]
lemma span_inl_union_inr {s : set M} {t : set M₂} :
span R (inl R M M₂ '' s ∪ inr R M M₂ '' t) = (span R s).prod (span R t) :=
by rw [span_union, prod_eq_sup_map, ← span_image, ← span_image]; refl
@[simp] lemma ker_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) :
ker (prod f g) = ker f ⊓ ker g :=
by rw [ker, ← prod_bot, comap_prod_prod]; refl
lemma range_prod_le (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) :
range (prod f g) ≤ (range f).prod (range g) :=
begin
simp only [le_def', prod_apply, mem_range, mem_coe, mem_prod, exists_imp_distrib],
rintro _ x rfl,
exact ⟨⟨x, rfl⟩, ⟨x, rfl⟩⟩
end
theorem ker_eq_bot_of_injective {f : M →ₗ[R] M₂} (hf : injective f) : ker f = ⊥ :=
begin
have : disjoint ⊤ f.ker, by { rw [disjoint_ker, ← map_zero f], exact λ x hx H, hf H },
simpa [disjoint]
end
end add_comm_monoid
section add_comm_group
variables [semiring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
variables [semimodule R M] [semimodule R M₂] [semimodule R M₃]
include R
open submodule
lemma comap_map_eq (f : M →ₗ[R] M₂) (p : submodule R M) :
comap f (map f p) = p ⊔ ker f :=
begin
refine le_antisymm _ (sup_le (le_comap_map _ _) (comap_mono bot_le)),
rintro x ⟨y, hy, e⟩,
exact mem_sup.2 ⟨y, hy, x - y, by simpa using sub_eq_zero.2 e.symm, by simp⟩
end
lemma comap_map_eq_self {f : M →ₗ[R] M₂} {p : submodule R M} (h : ker f ≤ p) :
comap f (map f p) = p :=
by rw [comap_map_eq, sup_of_le_left h]
theorem map_le_map_iff (f : M →ₗ[R] M₂) {p p'} : map f p ≤ map f p' ↔ p ≤ p' ⊔ ker f :=
by rw [map_le_iff_le_comap, comap_map_eq]
theorem map_le_map_iff' {f : M →ₗ[R] M₂} (hf : ker f = ⊥) {p p'} : map f p ≤ map f p' ↔ p ≤ p' :=
by rw [map_le_map_iff, hf, sup_bot_eq]
theorem map_injective {f : M →ₗ[R] M₂} (hf : ker f = ⊥) : injective (map f) :=
λ p p' h, le_antisymm ((map_le_map_iff' hf).1 (le_of_eq h)) ((map_le_map_iff' hf).1 (ge_of_eq h))
theorem map_eq_top_iff {f : M →ₗ[R] M₂} (hf : range f = ⊤) {p : submodule R M} :
p.map f = ⊤ ↔ p ⊔ f.ker = ⊤ :=
by simp_rw [← top_le_iff, ← hf, range, map_le_map_iff]
end add_comm_group
section ring
variables [ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
variables [semimodule R M] [semimodule R M₂] [semimodule R M₃]
include R
open submodule
theorem sub_mem_ker_iff {f : M →ₗ[R] M₂} {x y} : x - y ∈ f.ker ↔ f x = f y :=
by rw [mem_ker, map_sub, sub_eq_zero]
theorem disjoint_ker' {f : M →ₗ[R] M₂} {p : submodule R M} :
disjoint p (ker f) ↔ ∀ x y ∈ p, f x = f y → x = y :=
disjoint_ker.trans
⟨λ H x y hx hy h, eq_of_sub_eq_zero $ H _ (sub_mem _ hx hy) (by simp [h]),
λ H x h₁ h₂, H x 0 h₁ (zero_mem _) (by simpa using h₂)⟩
theorem inj_of_disjoint_ker {f : M →ₗ[R] M₂} {p : submodule R M}
{s : set M} (h : s ⊆ p) (hd : disjoint p (ker f)) :
∀ x y ∈ s, f x = f y → x = y :=
λ x y hx hy, disjoint_ker'.1 hd _ _ (h hx) (h hy)
theorem ker_eq_bot {f : M →ₗ[R] M₂} : ker f = ⊥ ↔ injective f :=
by simpa [disjoint] using @disjoint_ker' _ _ _ _ _ _ _ _ f ⊤
/-- If the union of the kernels `ker f` and `ker g` spans the domain, then the range of
`prod f g` is equal to the product of `range f` and `range g`. -/
lemma range_prod_eq {f : M →ₗ[R] M₂} {g : M →ₗ[R] M₃} (h : ker f ⊔ ker g = ⊤) :
range (prod f g) = (range f).prod (range g) :=
begin
refine le_antisymm (f.range_prod_le g) _,
simp only [le_def', prod_apply, mem_range, mem_coe, mem_prod, exists_imp_distrib, and_imp,
prod.forall],
rintros _ _ x rfl y rfl,
simp only [prod.mk.inj_iff, ← sub_mem_ker_iff],
have : y - x ∈ ker f ⊔ ker g, { simp only [h, mem_top] },
rcases mem_sup.1 this with ⟨x', hx', y', hy', H⟩,
refine ⟨x' + x, _, _⟩,
{ rwa add_sub_cancel },
{ rwa [← eq_sub_iff_add_eq.1 H, add_sub_add_right_eq_sub, ← neg_mem_iff, neg_sub,
add_sub_cancel'] }
end
end ring
section field
variables [field K]
variables [add_comm_group V] [vector_space K V]
variables [add_comm_group V₂] [vector_space K V₂]
lemma ker_smul (f : V →ₗ[K] V₂) (a : K) (h : a ≠ 0) : ker (a • f) = ker f :=
submodule.comap_smul f _ a h
lemma ker_smul' (f : V →ₗ[K] V₂) (a : K) : ker (a • f) = ⨅(h : a ≠ 0), ker f :=
submodule.comap_smul' f _ a
lemma range_smul (f : V →ₗ[K] V₂) (a : K) (h : a ≠ 0) : range (a • f) = range f :=
submodule.map_smul f _ a h
lemma range_smul' (f : V →ₗ[K] V₂) (a : K) : range (a • f) = ⨆(h : a ≠ 0), range f :=
submodule.map_smul' f _ a
end field
end linear_map
lemma submodule.sup_eq_range [semiring R] [add_comm_monoid M] [semimodule R M] (p q : submodule R M) :
p ⊔ q = (p.subtype.coprod q.subtype).range :=
submodule.ext $ λ x, by simp [submodule.mem_sup, submodule.exists]
namespace is_linear_map
lemma is_linear_map_add [semiring R] [add_comm_monoid M] [semimodule R M] :
is_linear_map R (λ (x : M × M), x.1 + x.2) :=
begin
apply is_linear_map.mk,
{ intros x y,
simp, cc },
{ intros x y,
simp [smul_add] }
end
lemma is_linear_map_sub {R M : Type*} [semiring R] [add_comm_group M] [semimodule R M]:
is_linear_map R (λ (x : M × M), x.1 - x.2) :=
begin
apply is_linear_map.mk,
{ intros x y,
simp [add_comm, add_left_comm, sub_eq_add_neg] },
{ intros x y,
simp [smul_sub] }
end
end is_linear_map
namespace submodule
section add_comm_monoid
variables {T : semiring R} [add_comm_monoid M] [add_comm_monoid M₂] [semimodule R M] [semimodule R M₂]
variables (p p' : submodule R M) (q : submodule R M₂)
include T
open linear_map
@[simp] theorem map_top (f : M →ₗ[R] M₂) : map f ⊤ = range f := rfl
@[simp] theorem comap_bot (f : M →ₗ[R] M₂) : comap f ⊥ = ker f := rfl
@[simp] theorem ker_subtype : p.subtype.ker = ⊥ :=
ker_eq_bot_of_injective $ λ x y, subtype.ext_val
@[simp] theorem range_subtype : p.subtype.range = p :=
by simpa using map_comap_subtype p ⊤
lemma map_subtype_le (p' : submodule R p) : map p.subtype p' ≤ p :=
by simpa using (map_mono le_top : map p.subtype p' ≤ p.subtype.range)
/-- Under the canonical linear map from a submodule `p` to the ambient space `M`, the image of the
maximal submodule of `p` is just `p `. -/
@[simp] lemma map_subtype_top : map p.subtype (⊤ : submodule R p) = p :=
by simp
@[simp] lemma comap_subtype_eq_top {p p' : submodule R M} :
comap p.subtype p' = ⊤ ↔ p ≤ p' :=
eq_top_iff.trans $ map_le_iff_le_comap.symm.trans $ by rw [map_subtype_top]
@[simp] lemma comap_subtype_self : comap p.subtype p = ⊤ :=
comap_subtype_eq_top.2 (le_refl _)
@[simp] theorem ker_of_le (p p' : submodule R M) (h : p ≤ p') : (of_le h).ker = ⊥ :=
by rw [of_le, ker_cod_restrict, ker_subtype]
lemma range_of_le (p q : submodule R M) (h : p ≤ q) : (of_le h).range = comap q.subtype p :=
by rw [← map_top, of_le, linear_map.map_cod_restrict, map_top, range_subtype]
@[simp] theorem map_inl : p.map (inl R M M₂) = prod p ⊥ :=
by { ext ⟨x, y⟩, simp only [and.left_comm, eq_comm, mem_map, prod.mk.inj_iff, inl_apply, mem_bot,
exists_eq_left', mem_prod] }
@[simp] theorem map_inr : q.map (inr R M M₂) = prod ⊥ q :=
by ext ⟨x, y⟩; simp [and.left_comm, eq_comm]
@[simp] theorem comap_fst : p.comap (fst R M M₂) = prod p ⊤ :=
by ext ⟨x, y⟩; simp
@[simp] theorem comap_snd : q.comap (snd R M M₂) = prod ⊤ q :=
by ext ⟨x, y⟩; simp
@[simp] theorem prod_comap_inl : (prod p q).comap (inl R M M₂) = p := by ext; simp
@[simp] theorem prod_comap_inr : (prod p q).comap (inr R M M₂) = q := by ext; simp
@[simp] theorem prod_map_fst : (prod p q).map (fst R M M₂) = p :=
by ext x; simp [(⟨0, zero_mem _⟩ : ∃ x, x ∈ q)]
@[simp] theorem prod_map_snd : (prod p q).map (snd R M M₂) = q :=
by ext x; simp [(⟨0, zero_mem _⟩ : ∃ x, x ∈ p)]
@[simp] theorem ker_inl : (inl R M M₂).ker = ⊥ :=
by rw [ker, ← prod_bot, prod_comap_inl]
@[simp] theorem ker_inr : (inr R M M₂).ker = ⊥ :=
by rw [ker, ← prod_bot, prod_comap_inr]
@[simp] theorem range_fst : (fst R M M₂).range = ⊤ :=
by rw [range, ← prod_top, prod_map_fst]
@[simp] theorem range_snd : (snd R M M₂).range = ⊤ :=
by rw [range, ← prod_top, prod_map_snd]
end add_comm_monoid
section ring
variables {T : ring R} [add_comm_group M] [add_comm_group M₂] [semimodule R M] [semimodule R M₂]
variables (p p' : submodule R M) (q : submodule R M₂)
include T
open linear_map
lemma disjoint_iff_comap_eq_bot {p q : submodule R M} :
disjoint p q ↔ comap p.subtype q = ⊥ :=
by rw [eq_bot_iff, ← map_le_map_iff' p.ker_subtype, map_bot, map_comap_subtype, disjoint]
/-- If `N ⊆ M` then submodules of `N` are the same as submodules of `M` contained in `N` -/
def map_subtype.rel_iso :
submodule R p ≃o {p' : submodule R M // p' ≤ p} :=
{ to_fun := λ p', ⟨map p.subtype p', map_subtype_le p _⟩,
inv_fun := λ q, comap p.subtype q,
left_inv := λ p', comap_map_eq_self $ by simp,
right_inv := λ ⟨q, hq⟩, subtype.ext_val $ by simp [map_comap_subtype p, inf_of_le_right hq],
map_rel_iff' := λ p₁ p₂, (map_le_map_iff' (ker_subtype p)).symm }
/-- If `p ⊆ M` is a submodule, the ordering of submodules of `p` is embedded in the ordering of
submodules of `M`. -/
def map_subtype.order_embedding :
submodule R p ↪o submodule R M :=
(rel_iso.to_rel_embedding $ map_subtype.rel_iso p).trans (subtype.rel_embedding _ _)
@[simp] lemma map_subtype_embedding_eq (p' : submodule R p) :
map_subtype.order_embedding p p' = map p.subtype p' := rfl
/-- The map from a module `M` to the quotient of `M` by a submodule `p` as a linear map. -/
def mkq : M →ₗ[R] p.quotient := ⟨quotient.mk, by simp, by simp⟩
@[simp] theorem mkq_apply (x : M) : p.mkq x = quotient.mk x := rfl
/-- The map from the quotient of `M` by a submodule `p` to `M₂` induced by a linear map `f : M → M₂`
vanishing on `p`, as a linear map. -/
def liftq (f : M →ₗ[R] M₂) (h : p ≤ f.ker) : p.quotient →ₗ[R] M₂ :=
⟨λ x, _root_.quotient.lift_on' x f $
λ a b (ab : a - b ∈ p), eq_of_sub_eq_zero $ by simpa using h ab,
by rintro ⟨x⟩ ⟨y⟩; exact f.map_add x y,
by rintro a ⟨x⟩; exact f.map_smul a x⟩
@[simp] theorem liftq_apply (f : M →ₗ[R] M₂) {h} (x : M) :
p.liftq f h (quotient.mk x) = f x := rfl
@[simp] theorem liftq_mkq (f : M →ₗ[R] M₂) (h) : (p.liftq f h).comp p.mkq = f :=
by ext; refl
@[simp] theorem range_mkq : p.mkq.range = ⊤ :=
eq_top_iff'.2 $ by rintro ⟨x⟩; exact ⟨x, trivial, rfl⟩
@[simp] theorem ker_mkq : p.mkq.ker = p :=
by ext; simp
lemma le_comap_mkq (p' : submodule R p.quotient) : p ≤ comap p.mkq p' :=
by simpa using (comap_mono bot_le : p.mkq.ker ≤ comap p.mkq p')
@[simp] theorem mkq_map_self : map p.mkq p = ⊥ :=
by rw [eq_bot_iff, map_le_iff_le_comap, comap_bot, ker_mkq]; exact le_refl _
@[simp] theorem comap_map_mkq : comap p.mkq (map p.mkq p') = p ⊔ p' :=
by simp [comap_map_eq, sup_comm]
@[simp] theorem map_mkq_eq_top : map p.mkq p' = ⊤ ↔ p ⊔ p' = ⊤ :=
by simp only [map_eq_top_iff p.range_mkq, sup_comm, ker_mkq]
/-- The map from the quotient of `M` by submodule `p` to the quotient of `M₂` by submodule `q` along
`f : M → M₂` is linear. -/
def mapq (f : M →ₗ[R] M₂) (h : p ≤ comap f q) : p.quotient →ₗ[R] q.quotient :=
p.liftq (q.mkq.comp f) $ by simpa [ker_comp] using h
@[simp] theorem mapq_apply (f : M →ₗ[R] M₂) {h} (x : M) :
mapq p q f h (quotient.mk x) = quotient.mk (f x) := rfl
theorem mapq_mkq (f : M →ₗ[R] M₂) {h} : (mapq p q f h).comp p.mkq = q.mkq.comp f :=
by ext x; refl
theorem comap_liftq (f : M →ₗ[R] M₂) (h) :
q.comap (p.liftq f h) = (q.comap f).map (mkq p) :=
le_antisymm
(by rintro ⟨x⟩ hx; exact ⟨_, hx, rfl⟩)
(by rw [map_le_iff_le_comap, ← comap_comp, liftq_mkq]; exact le_refl _)
theorem map_liftq (f : M →ₗ[R] M₂) (h) (q : submodule R (quotient p)) :
q.map (p.liftq f h) = (q.comap p.mkq).map f :=
le_antisymm
(by rintro _ ⟨⟨x⟩, hxq, rfl⟩; exact ⟨x, hxq, rfl⟩)
(by rintro _ ⟨x, hxq, rfl⟩; exact ⟨quotient.mk x, hxq, rfl⟩)
theorem ker_liftq (f : M →ₗ[R] M₂) (h) :
ker (p.liftq f h) = (ker f).map (mkq p) := comap_liftq _ _ _ _
theorem range_liftq (f : M →ₗ[R] M₂) (h) :
range (p.liftq f h) = range f := map_liftq _ _ _ _
theorem ker_liftq_eq_bot (f : M →ₗ[R] M₂) (h) (h' : ker f ≤ p) : ker (p.liftq f h) = ⊥ :=
by rw [ker_liftq, le_antisymm h h', mkq_map_self]
/-- The correspondence theorem for modules: there is an order isomorphism between submodules of the
quotient of `M` by `p`, and submodules of `M` larger than `p`. -/
def comap_mkq.rel_iso :
submodule R p.quotient ≃o {p' : submodule R M // p ≤ p'} :=
{ to_fun := λ p', ⟨comap p.mkq p', le_comap_mkq p _⟩,
inv_fun := λ q, map p.mkq q,
left_inv := λ p', map_comap_eq_self $ by simp,
right_inv := λ ⟨q, hq⟩, subtype.ext_val $ by simpa [comap_map_mkq p],
map_rel_iff' := λ p₁ p₂, (comap_le_comap_iff $ range_mkq _).symm }
/-- The ordering on submodules of the quotient of `M` by `p` embeds into the ordering on submodules
of `M`. -/
def comap_mkq.order_embedding :
submodule R p.quotient ↪o submodule R M :=
(rel_iso.to_rel_embedding $ comap_mkq.rel_iso p).trans (subtype.rel_embedding _ _)
@[simp] lemma comap_mkq_embedding_eq (p' : submodule R p.quotient) :
comap_mkq.order_embedding p p' = comap p.mkq p' := rfl
end ring
end submodule
namespace linear_map
variables [ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
variables [module R M] [module R M₂] [module R M₃]
lemma range_mkq_comp (f : M →ₗ[R] M₂) : f.range.mkq.comp f = 0 :=
linear_map.ext $ λ x, by simp
lemma ker_le_range_iff {f : M →ₗ[R] M₂} {g : M₂ →ₗ[R] M₃} :
g.ker ≤ f.range ↔ f.range.mkq.comp g.ker.subtype = 0 :=
by rw [←range_le_ker_iff, submodule.ker_mkq, submodule.range_subtype]
/-- A monomorphism is injective. -/
lemma ker_eq_bot_of_cancel {f : M →ₗ[R] M₂}
(h : ∀ (u v : f.ker →ₗ[R] M), f.comp u = f.comp v → u = v) : f.ker = ⊥ :=
begin
have h₁ : f.comp (0 : f.ker →ₗ[R] M) = 0 := comp_zero _,
rw [←submodule.range_subtype f.ker, ←h 0 f.ker.subtype (eq.trans h₁ (comp_ker_subtype f).symm)],
exact range_zero
end
/-- An epimorphism is surjective. -/
lemma range_eq_top_of_cancel {f : M →ₗ[R] M₂}
(h : ∀ (u v : M₂ →ₗ[R] f.range.quotient), u.comp f = v.comp f → u = v) : f.range = ⊤ :=
begin
have h₁ : (0 : M₂ →ₗ[R] f.range.quotient).comp f = 0 := zero_comp _,
rw [←submodule.ker_mkq f.range, ←h 0 f.range.mkq (eq.trans h₁ (range_mkq_comp _).symm)],
exact ker_zero
end
end linear_map
@[simp] lemma linear_map.range_range_restrict [semiring R] [add_comm_monoid M] [add_comm_monoid M₂]
[semimodule R M] [semimodule R M₂] (f : M →ₗ[R] M₂) :
f.range_restrict.range = ⊤ :=
by simp [f.range_cod_restrict _]
/-! ### Linear equivalences -/
namespace linear_equiv
section add_comm_monoid
variables [semiring R] [add_comm_monoid M] [add_comm_monoid M₂]
[add_comm_monoid M₃] [add_comm_monoid M₄]
section
variables {semimodule_M : semimodule R M} {semimodule_M₂ : semimodule R M₂}
variables (e e' : M ≃ₗ[R] M₂)
lemma map_eq_comap {p : submodule R M} : (p.map e : submodule R M₂) = p.comap e.symm :=
submodule.coe_injective $ by simp [e.image_eq_preimage]
/-- A linear equivalence of two modules restricts to a linear equivalence from any submodule
of the domain onto the image of the submodule. -/
def of_submodule (p : submodule R M) : p ≃ₗ[R] ↥(p.map ↑e : submodule R M₂) :=
{ inv_fun := λ y, ⟨e.symm y, by {
rcases y with ⟨y', hy⟩, rw submodule.mem_map at hy, rcases hy with ⟨x, hx, hxy⟩, subst hxy,
simp only [symm_apply_apply, submodule.coe_mk, coe_coe, hx], }⟩,
left_inv := λ x, by simp,
right_inv := λ y, by { apply set_coe.ext, simp, },
..((e : M →ₗ[R] M₂).dom_restrict p).cod_restrict (p.map ↑e) (λ x, ⟨x, by simp⟩) }
@[simp] lemma of_submodule_apply (p : submodule R M) (x : p) :
↑(e.of_submodule p x) = e x := rfl
@[simp] lemma of_submodule_symm_apply (p : submodule R M) (x : (p.map ↑e : submodule R M₂)) :
↑((e.of_submodule p).symm x) = e.symm x := rfl
end
section prod
variables {semimodule_M : semimodule R M} {semimodule_M₂ : semimodule R M₂}
variables {semimodule_M₃ : semimodule R M₃} {semimodule_M₄ : semimodule R M₄}
variables (e₁ : M ≃ₗ[R] M₂) (e₂ : M₃ ≃ₗ[R] M₄)
/-- Product of linear equivalences; the maps come from `equiv.prod_congr`. -/
protected def prod :
(M × M₃) ≃ₗ[R] (M₂ × M₄) :=
{ map_add' := λ x y, prod.ext (e₁.map_add _ _) (e₂.map_add _ _),
map_smul' := λ c x, prod.ext (e₁.map_smul c _) (e₂.map_smul c _),
.. equiv.prod_congr e₁.to_equiv e₂.to_equiv }
lemma prod_symm : (e₁.prod e₂).symm = e₁.symm.prod e₂.symm := rfl
@[simp] lemma prod_apply (p) :
e₁.prod e₂ p = (e₁ p.1, e₂ p.2) := rfl
@[simp, norm_cast] lemma coe_prod :
(e₁.prod e₂ : (M × M₃) →ₗ[R] (M₂ × M₄)) = (e₁ : M →ₗ[R] M₂).prod_map (e₂ : M₃ →ₗ[R] M₄) := rfl
end prod
section uncurry
variables (V V₂ R)
/-- Linear equivalence between a curried and uncurried function.
Differs from `tensor_product.curry`. -/
protected def uncurry :
(V → V₂ → R) ≃ₗ[R] (V × V₂ → R) :=
{ map_add' := λ _ _, by { ext ⟨⟩, refl },
map_smul' := λ _ _, by { ext ⟨⟩, refl },
.. equiv.arrow_arrow_equiv_prod_arrow _ _ _}
@[simp] lemma coe_uncurry : ⇑(linear_equiv.uncurry R V V₂) = uncurry := rfl
@[simp] lemma coe_uncurry_symm : ⇑(linear_equiv.uncurry R V V₂).symm = curry := rfl
end uncurry
section
variables {semimodule_M : semimodule R M} {semimodule_M₂ : semimodule R M₂}
variables (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M) (e : M ≃ₗ[R] M₂)
variables (p q : submodule R M)
/-- Linear equivalence between two equal submodules. -/
def of_eq (h : p = q) : p ≃ₗ[R] q :=
{ map_smul' := λ _ _, rfl, map_add' := λ _ _, rfl, .. equiv.set.of_eq (congr_arg _ h) }
variables {p q}
@[simp] lemma coe_of_eq_apply (h : p = q) (x : p) : (of_eq p q h x : M) = x := rfl
@[simp] lemma of_eq_symm (h : p = q) : (of_eq p q h).symm = of_eq q p h.symm := rfl
/-- A linear equivalence which maps a submodule of one module onto another, restricts to a linear
equivalence of the two submodules. -/
def of_submodules (p : submodule R M) (q : submodule R M₂) (h : p.map ↑e = q) : p ≃ₗ[R] q :=
(e.of_submodule p).trans (linear_equiv.of_eq _ _ h)
@[simp] lemma of_submodules_apply {p : submodule R M} {q : submodule R M₂}
(h : p.map ↑e = q) (x : p) : ↑(e.of_submodules p q h x) = e x := rfl
@[simp] lemma of_submodules_symm_apply {p : submodule R M} {q : submodule R M₂}
(h : p.map ↑e = q) (x : q) : ↑((e.of_submodules p q h).symm x) = e.symm x := rfl
variable (p)
/-- The top submodule of `M` is linearly equivalent to `M`. -/
def of_top (h : p = ⊤) : p ≃ₗ[R] M :=
{ inv_fun := λ x, ⟨x, h.symm ▸ trivial⟩,
left_inv := λ ⟨x, h⟩, rfl,
right_inv := λ x, rfl,
.. p.subtype }
@[simp] theorem of_top_apply {h} (x : p) : of_top p h x = x := rfl
@[simp] theorem coe_of_top_symm_apply {h} (x : M) : ((of_top p h).symm x : M) = x := rfl
theorem of_top_symm_apply {h} (x : M) : (of_top p h).symm x = ⟨x, h.symm ▸ trivial⟩ := rfl
/-- If a linear map has an inverse, it is a linear equivalence. -/
def of_linear (h₁ : f.comp g = linear_map.id) (h₂ : g.comp f = linear_map.id) : M ≃ₗ[R] M₂ :=
{ inv_fun := g,
left_inv := linear_map.ext_iff.1 h₂,
right_inv := linear_map.ext_iff.1 h₁,
..f }
@[simp] theorem of_linear_apply {h₁ h₂} (x : M) : of_linear f g h₁ h₂ x = f x := rfl
@[simp] theorem of_linear_symm_apply {h₁ h₂} (x : M₂) : (of_linear f g h₁ h₂).symm x = g x := rfl
@[simp] protected theorem range : (e : M →ₗ[R] M₂).range = ⊤ :=
linear_map.range_eq_top.2 e.to_equiv.surjective
lemma eq_bot_of_equiv [semimodule R M₂] (e : p ≃ₗ[R] (⊥ : submodule R M₂)) : p = ⊥ :=
begin
refine bot_unique (submodule.le_def'.2 $ assume b hb, (submodule.mem_bot R).2 _),
rw [← p.mk_eq_zero hb, ← e.map_eq_zero_iff],
apply submodule.eq_zero_of_bot_submodule
end
@[simp] protected theorem ker : (e : M →ₗ[R] M₂).ker = ⊥ :=
linear_map.ker_eq_bot_of_injective e.to_equiv.injective
end
end add_comm_monoid
section add_comm_group
variables [semiring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] [add_comm_group M₄]
variables {semimodule_M : semimodule R M} {semimodule_M₂ : semimodule R M₂}
variables {semimodule_M₃ : semimodule R M₃} {semimodule_M₄ : semimodule R M₄}
variables (e e₁ : M ≃ₗ[R] M₂) (e₂ : M₃ ≃ₗ[R] M₄)
@[simp] theorem map_neg (a : M) : e (-a) = -e a := e.to_linear_map.map_neg a
@[simp] theorem map_sub (a b : M) : e (a - b) = e a - e b :=
e.to_linear_map.map_sub a b
/-- Equivalence given by a block lower diagonal matrix. `e₁` and `e₂` are diagonal square blocks,
and `f` is a rectangular block below the diagonal. -/
protected def skew_prod (f : M →ₗ[R] M₄) :
(M × M₃) ≃ₗ[R] M₂ × M₄ :=
{ inv_fun := λ p : M₂ × M₄, (e₁.symm p.1, e₂.symm (p.2 - f (e₁.symm p.1))),
left_inv := λ p, by simp,
right_inv := λ p, by simp,
.. ((e₁ : M →ₗ[R] M₂).comp (linear_map.fst R M M₃)).prod
((e₂ : M₃ →ₗ[R] M₄).comp (linear_map.snd R M M₃) +
f.comp (linear_map.fst R M M₃)) }
@[simp] lemma skew_prod_apply (f : M →ₗ[R] M₄) (x) :
e₁.skew_prod e₂ f x = (e₁ x.1, e₂ x.2 + f x.1) := rfl
@[simp] lemma skew_prod_symm_apply (f : M →ₗ[R] M₄) (x) :
(e₁.skew_prod e₂ f).symm x = (e₁.symm x.1, e₂.symm (x.2 - f (e₁.symm x.1))) := rfl
end add_comm_group
section neg
variables (R) [semiring R] [add_comm_group M] [semimodule R M]
/-- `x ↦ -x` as a `linear_equiv` -/
def neg : M ≃ₗ[R] M := { .. equiv.neg M, .. (-linear_map.id : M →ₗ[R] M) }
variable {R}
@[simp] lemma coe_neg : ⇑(neg R : M ≃ₗ[R] M) = -id := rfl
lemma neg_apply (x : M) : neg R x = -x := by simp
@[simp] lemma symm_neg : (neg R : M ≃ₗ[R] M).symm = neg R := rfl
end neg
section ring
variables [ring R] [add_comm_group M] [add_comm_group M₂]
variables {semimodule_M : semimodule R M} {semimodule_M₂ : semimodule R M₂}
variables (f : M →ₗ[R] M₂) (e : M ≃ₗ[R] M₂)
/-- An `injective` linear map `f : M →ₗ[R] M₂` defines a linear equivalence
between `M` and `f.range`. -/
noncomputable def of_injective (h : f.ker = ⊥) : M ≃ₗ[R] f.range :=
{ .. (equiv.set.range f $ linear_map.ker_eq_bot.1 h).trans (equiv.set.of_eq f.range_coe.symm),
.. f.cod_restrict f.range (λ x, f.mem_range_self x) }
@[simp] theorem of_injective_apply {h : f.ker = ⊥} (x : M) :
↑(of_injective f h x) = f x := rfl
/-- A bijective linear map is a linear equivalence. Here, bijectivity is described by saying that
the kernel of `f` is `{0}` and the range is the universal set. -/
noncomputable def of_bijective (hf₁ : f.ker = ⊥) (hf₂ : f.range = ⊤) : M ≃ₗ[R] M₂ :=
(of_injective f hf₁).trans (of_top _ hf₂)
@[simp] theorem of_bijective_apply {hf₁ hf₂} (x : M) :
of_bijective f hf₁ hf₂ x = f x := rfl
end ring
section comm_ring
variables [comm_ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
variables [semimodule R M] [semimodule R M₂] [semimodule R M₃]
open linear_map
/-- Multiplying by a unit `a` of the ring `R` is a linear equivalence. -/
def smul_of_unit (a : units R) : M ≃ₗ[R] M :=
of_linear ((a:R) • 1 : M →ₗ M) (((a⁻¹ : units R) : R) • 1 : M →ₗ M)
(by rw [smul_comp, comp_smul, smul_smul, units.mul_inv, one_smul]; refl)
(by rw [smul_comp, comp_smul, smul_smul, units.inv_mul, one_smul]; refl)
/-- A linear isomorphism between the domains and codomains of two spaces of linear maps gives a
linear isomorphism between the two function spaces. -/
def arrow_congr {R M₁ M₂ M₂₁ M₂₂ : Sort*} [comm_ring R]
[add_comm_group M₁] [add_comm_group M₂] [add_comm_group M₂₁] [add_comm_group M₂₂]
[module R M₁] [module R M₂] [module R M₂₁] [module R M₂₂]
(e₁ : M₁ ≃ₗ[R] M₂) (e₂ : M₂₁ ≃ₗ[R] M₂₂) :
(M₁ →ₗ[R] M₂₁) ≃ₗ[R] (M₂ →ₗ[R] M₂₂) :=
{ to_fun := λ f, (e₂ : M₂₁ →ₗ[R] M₂₂).comp $ f.comp e₁.symm,
inv_fun := λ f, (e₂.symm : M₂₂ →ₗ[R] M₂₁).comp $ f.comp e₁,
left_inv := λ f, by { ext x, simp },
right_inv := λ f, by { ext x, simp },
map_add' := λ f g, by { ext x, simp },
map_smul' := λ c f, by { ext x, simp } }
@[simp] lemma arrow_congr_apply {R M₁ M₂ M₂₁ M₂₂ : Sort*} [comm_ring R]
[add_comm_group M₁] [add_comm_group M₂] [add_comm_group M₂₁] [add_comm_group M₂₂]
[module R M₁] [module R M₂] [module R M₂₁] [module R M₂₂]
(e₁ : M₁ ≃ₗ[R] M₂) (e₂ : M₂₁ ≃ₗ[R] M₂₂) (f : M₁ →ₗ[R] M₂₁) (x : M₂) :
arrow_congr e₁ e₂ f x = e₂ (f (e₁.symm x)) :=
rfl
@[simp] lemma arrow_congr_symm_apply {R M₁ M₂ M₂₁ M₂₂ : Sort*} [comm_ring R]
[add_comm_group M₁] [add_comm_group M₂] [add_comm_group M₂₁] [add_comm_group M₂₂]
[module R M₁] [module R M₂] [module R M₂₁] [module R M₂₂]
(e₁ : M₁ ≃ₗ[R] M₂) (e₂ : M₂₁ ≃ₗ[R] M₂₂) (f : M₂ →ₗ[R] M₂₂) (x : M₁) :
(arrow_congr e₁ e₂).symm f x = e₂.symm (f (e₁ x)) :=
rfl
lemma arrow_congr_comp {N N₂ N₃ : Sort*}
[add_comm_group N] [add_comm_group N₂] [add_comm_group N₃] [module R N] [module R N₂] [module R N₃]
(e₁ : M ≃ₗ[R] N) (e₂ : M₂ ≃ₗ[R] N₂) (e₃ : M₃ ≃ₗ[R] N₃) (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) :
arrow_congr e₁ e₃ (g.comp f) = (arrow_congr e₂ e₃ g).comp (arrow_congr e₁ e₂ f) :=
by { ext, simp only [symm_apply_apply, arrow_congr_apply, linear_map.comp_apply], }
lemma arrow_congr_trans {M₁ M₂ M₃ N₁ N₂ N₃ : Sort*}
[add_comm_group M₁] [module R M₁] [add_comm_group M₂] [module R M₂] [add_comm_group M₃] [module R M₃]
[add_comm_group N₁] [module R N₁] [add_comm_group N₂] [module R N₂] [add_comm_group N₃] [module R N₃]
(e₁ : M₁ ≃ₗ[R] M₂) (e₂ : N₁ ≃ₗ[R] N₂) (e₃ : M₂ ≃ₗ[R] M₃) (e₄ : N₂ ≃ₗ[R] N₃) :
(arrow_congr e₁ e₂).trans (arrow_congr e₃ e₄) = arrow_congr (e₁.trans e₃) (e₂.trans e₄) :=
rfl
/-- If `M₂` and `M₃` are linearly isomorphic then the two spaces of linear maps from `M` into `M₂`
and `M` into `M₃` are linearly isomorphic. -/
def congr_right (f : M₂ ≃ₗ[R] M₃) : (M →ₗ[R] M₂) ≃ₗ (M →ₗ M₃) := arrow_congr (linear_equiv.refl R M) f
/-- If `M` and `M₂` are linearly isomorphic then the two spaces of linear maps from `M` and `M₂` to
themselves are linearly isomorphic. -/
def conj (e : M ≃ₗ[R] M₂) : (module.End R M) ≃ₗ[R] (module.End R M₂) := arrow_congr e e
lemma conj_apply (e : M ≃ₗ[R] M₂) (f : module.End R M) :
e.conj f = ((↑e : M →ₗ[R] M₂).comp f).comp e.symm := rfl
lemma symm_conj_apply (e : M ≃ₗ[R] M₂) (f : module.End R M₂) :
e.symm.conj f = ((↑e.symm : M₂ →ₗ[R] M).comp f).comp e := rfl
lemma conj_comp (e : M ≃ₗ[R] M₂) (f g : module.End R M) :
e.conj (g.comp f) = (e.conj g).comp (e.conj f) :=
arrow_congr_comp e e e f g
lemma conj_trans (e₁ : M ≃ₗ[R] M₂) (e₂ : M₂ ≃ₗ[R] M₃) :
e₁.conj.trans e₂.conj = (e₁.trans e₂).conj :=
by { ext f x, refl, }
@[simp] lemma conj_id (e : M ≃ₗ[R] M₂) : e.conj linear_map.id = linear_map.id :=
by { ext, simp [conj_apply], }
end comm_ring
section field
variables [field K] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
variables [module K M] [module K M₂] [module K M₃]
variables (K) (M)
open linear_map
/-- Multiplying by a nonzero element `a` of the field `K` is a linear equivalence. -/
def smul_of_ne_zero (a : K) (ha : a ≠ 0) : M ≃ₗ[K] M :=
smul_of_unit $ units.mk0 a ha
section
noncomputable theory
open_locale classical
lemma ker_to_span_singleton {x : M} (h : x ≠ 0) : (to_span_singleton K M x).ker = ⊥ :=
begin
ext c, split,
{ intros hc, rw submodule.mem_bot, rw mem_ker at hc, by_contra hc',
have : x = 0,
calc x = c⁻¹ • (c • x) : by rw [← mul_smul, inv_mul_cancel hc', one_smul]
... = c⁻¹ • ((to_span_singleton K M x) c) : rfl
... = 0 : by rw [hc, smul_zero],
tauto },
{ rw [mem_ker, submodule.mem_bot], intros h, rw h, simp }
end
/-- Given a nonzero element `x` of a vector space `M` over a field `K`, the natural
map from `K` to the span of `x`, with invertibility check to consider it as an
isomorphism.-/
def to_span_nonzero_singleton (x : M) (h : x ≠ 0) : K ≃ₗ[K] (submodule.span K ({x} : set M)) :=
linear_equiv.trans
(linear_equiv.of_injective (to_span_singleton K M x) (ker_to_span_singleton K M h))
(of_eq (to_span_singleton K M x).range (submodule.span K {x}) (span_singleton_eq_range K M x).symm)
lemma to_span_nonzero_singleton_one (x : M) (h : x ≠ 0) : to_span_nonzero_singleton K M x h 1
= (⟨x, submodule.mem_span_singleton_self x⟩ : submodule.span K ({x} : set M)) :=
begin
apply submodule.coe_eq_coe.mp,
have : ↑(to_span_nonzero_singleton K M x h 1) = to_span_singleton K M x 1 := rfl,
rw [this, to_span_singleton_one, submodule.coe_mk],
end
/-- Given a nonzero element `x` of a vector space `M` over a field `K`, the natural map
from the span of `x` to `K`.-/
abbreviation coord (x : M) (h : x ≠ 0) : (submodule.span K ({x} : set M)) ≃ₗ[K] K :=
(to_span_nonzero_singleton K M x h).symm
lemma coord_self (x : M) (h : x ≠ 0) : (coord K M x h) ( ⟨x, submodule.mem_span_singleton_self x⟩ :
submodule.span K ({x} : set M)) = 1 :=
by rw [← to_span_nonzero_singleton_one K M x h, symm_apply_apply]
end
end field
end linear_equiv
namespace submodule
section semimodule
variables [semiring R] [add_comm_monoid M] [semimodule R M]
/-- If `s ≤ t`, then we can view `s` as a submodule of `t` by taking the comap
of `t.subtype`. -/
def comap_subtype_equiv_of_le {p q : submodule R M} (hpq : p ≤ q) :
comap q.subtype p ≃ₗ[R] p :=
{ to_fun := λ x, ⟨x, x.2⟩,
inv_fun := λ x, ⟨⟨x, hpq x.2⟩, x.2⟩,
left_inv := λ x, by simp only [coe_mk, submodule.eta, coe_coe],
right_inv := λ x, by simp only [subtype.coe_mk, submodule.eta, coe_coe],
map_add' := λ x y, rfl,
map_smul' := λ c x, rfl }
end semimodule
variables [ring R] [add_comm_group M] [module R M]
variables (p : submodule R M)
open linear_map
/-- If `p = ⊥`, then `M / p ≃ₗ[R] M`. -/
def quot_equiv_of_eq_bot (hp : p = ⊥) : p.quotient ≃ₗ[R] M :=
linear_equiv.of_linear (p.liftq id $ hp.symm ▸ bot_le) p.mkq (liftq_mkq _ _ _) $
p.quot_hom_ext $ λ x, rfl
@[simp] lemma quot_equiv_of_eq_bot_apply_mk (hp : p = ⊥) (x : M) :
p.quot_equiv_of_eq_bot hp (quotient.mk x) = x := rfl
@[simp] lemma quot_equiv_of_eq_bot_symm_apply (hp : p = ⊥) (x : M) :
(p.quot_equiv_of_eq_bot hp).symm x = quotient.mk x := rfl
@[simp] lemma coe_quot_equiv_of_eq_bot_symm (hp : p = ⊥) :
((p.quot_equiv_of_eq_bot hp).symm : M →ₗ[R] p.quotient) = p.mkq := rfl
variables (q : submodule R M)
/-- Quotienting by equal submodules gives linearly equivalent quotients. -/
def quot_equiv_of_eq (h : p = q) : p.quotient ≃ₗ[R] q.quotient :=
{ map_add' := by { rintros ⟨x⟩ ⟨y⟩, refl }, map_smul' := by { rintros x ⟨y⟩, refl },
..@quotient.congr _ _ (quotient_rel p) (quotient_rel q) (equiv.refl _) $ λ a b, by { subst h, refl } }
end submodule
namespace submodule
variables [comm_ring R] [add_comm_group M] [add_comm_group M₂] [module R M] [module R M₂]
variables (p : submodule R M) (q : submodule R M₂)
@[simp] lemma mem_map_equiv {e : M ≃ₗ[R] M₂} {x : M₂} : x ∈ p.map (e : M →ₗ[R] M₂) ↔ e.symm x ∈ p :=
begin
rw submodule.mem_map, split,
{ rintros ⟨y, hy, hx⟩, simp [←hx, hy], },
{ intros hx, refine ⟨e.symm x, hx, by simp⟩, },
end
lemma comap_le_comap_smul (f : M →ₗ[R] M₂) (c : R) :
comap f q ≤ comap (c • f) q :=
begin
rw le_def',
intros m h,
change c • (f m) ∈ q,
change f m ∈ q at h,
apply q.smul_mem _ h,
end
lemma inf_comap_le_comap_add (f₁ f₂ : M →ₗ[R] M₂) :
comap f₁ q ⊓ comap f₂ q ≤ comap (f₁ + f₂) q :=
begin
rw le_def',
intros m h,
change f₁ m + f₂ m ∈ q,
change f₁ m ∈ q ∧ f₂ m ∈ q at h,
apply q.add_mem h.1 h.2,
end
/-- Given modules `M`, `M₂` over a commutative ring, together with submodules `p ⊆ M`, `q ⊆ M₂`, the
set of maps $\\{f ∈ Hom(M, M₂) | f(p) ⊆ q \\}$ is a submodule of `Hom(M, M₂)`. -/
def compatible_maps : submodule R (M →ₗ[R] M₂) :=
{ carrier := {f | p ≤ comap f q},
zero_mem' := by { change p ≤ comap 0 q, rw comap_zero, refine le_top, },
add_mem' := λ f₁ f₂ h₁ h₂, by { apply le_trans _ (inf_comap_le_comap_add q f₁ f₂), rw le_inf_iff,
exact ⟨h₁, h₂⟩, },
smul_mem' := λ c f h, le_trans h (comap_le_comap_smul q f c), }
/-- Given modules `M`, `M₂` over a commutative ring, together with submodules `p ⊆ M`, `q ⊆ M₂`, the
natural map $\\{f ∈ Hom(M, M₂) | f(p) ⊆ q \\} \to Hom(M/p, M₂/q)$ is linear. -/
def mapq_linear : compatible_maps p q →ₗ[R] p.quotient →ₗ[R] q.quotient :=
{ to_fun := λ f, mapq _ _ f.val f.property,
map_add' := λ x y, by { ext m', apply quotient.induction_on' m', intros m, refl, },
map_smul' := λ c f, by { ext m', apply quotient.induction_on' m', intros m, refl, } }
end submodule
namespace equiv
variables [semiring R] [add_comm_monoid M] [semimodule R M] [add_comm_monoid M₂] [semimodule R M₂]
/-- An equivalence whose underlying function is linear is a linear equivalence. -/
def to_linear_equiv (e : M ≃ M₂) (h : is_linear_map R (e : M → M₂)) : M ≃ₗ[R] M₂ :=
{ .. e, .. h.mk' e}
end equiv
namespace add_equiv
variables [semiring R] [add_comm_monoid M] [semimodule R M] [add_comm_monoid M₂] [semimodule R M₂]
/-- An additive equivalence whose underlying function preserves `smul` is a linear equivalence. -/
def to_linear_equiv (e : M ≃+ M₂) (h : ∀ (c : R) x, e (c • x) = c • e x) : M ≃ₗ[R] M₂ :=
{ map_smul' := h, .. e, }
@[simp] lemma coe_to_linear_equiv (e : M ≃+ M₂) (h : ∀ (c : R) x, e (c • x) = c • e x) :
⇑(e.to_linear_equiv h) = e :=
rfl
@[simp] lemma coe_to_linear_equiv_symm (e : M ≃+ M₂) (h : ∀ (c : R) x, e (c • x) = c • e x) :
⇑(e.to_linear_equiv h).symm = e.symm :=
rfl
end add_equiv
namespace linear_map
open submodule
section isomorphism_laws
variables [ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
variables [module R M] [module R M₂] [module R M₃]
variables (f : M →ₗ[R] M₂)
/-- The first isomorphism law for modules. The quotient of `M` by the kernel of `f` is linearly
equivalent to the range of `f`. -/
noncomputable def quot_ker_equiv_range : f.ker.quotient ≃ₗ[R] f.range :=
(linear_equiv.of_injective (f.ker.liftq f $ le_refl _) $
submodule.ker_liftq_eq_bot _ _ _ (le_refl f.ker)).trans
(linear_equiv.of_eq _ _ $ submodule.range_liftq _ _ _)
@[simp] lemma quot_ker_equiv_range_apply_mk (x : M) :
(f.quot_ker_equiv_range (submodule.quotient.mk x) : M₂) = f x :=
rfl
@[simp] lemma quot_ker_equiv_range_symm_apply_image (x : M) (h : f x ∈ f.range) :
f.quot_ker_equiv_range.symm ⟨f x, h⟩ = f.ker.mkq x :=
f.quot_ker_equiv_range.symm_apply_apply (f.ker.mkq x)
/--
Canonical linear map from the quotient `p/(p ∩ p')` to `(p+p')/p'`, mapping `x + (p ∩ p')`
to `x + p'`, where `p` and `p'` are submodules of an ambient module.
-/
def quotient_inf_to_sup_quotient (p p' : submodule R M) :
(comap p.subtype (p ⊓ p')).quotient →ₗ[R] (comap (p ⊔ p').subtype p').quotient :=
(comap p.subtype (p ⊓ p')).liftq
((comap (p ⊔ p').subtype p').mkq.comp (of_le le_sup_left)) begin
rw [ker_comp, of_le, comap_cod_restrict, ker_mkq, map_comap_subtype],
exact comap_mono (inf_le_inf_right _ le_sup_left) end
/--
Second Isomorphism Law : the canonical map from `p/(p ∩ p')` to `(p+p')/p'` as a linear isomorphism.
-/
noncomputable def quotient_inf_equiv_sup_quotient (p p' : submodule R M) :
(comap p.subtype (p ⊓ p')).quotient ≃ₗ[R] (comap (p ⊔ p').subtype p').quotient :=
linear_equiv.of_bijective (quotient_inf_to_sup_quotient p p')
begin
rw [quotient_inf_to_sup_quotient, ker_liftq_eq_bot],
rw [ker_comp, ker_mkq],
exact λ ⟨x, hx1⟩ hx2, ⟨hx1, hx2⟩
end
begin
rw [quotient_inf_to_sup_quotient, range_liftq, eq_top_iff'],
rintros ⟨x, hx⟩, rcases mem_sup.1 hx with ⟨y, hy, z, hz, rfl⟩,
use [⟨y, hy⟩, trivial], apply (submodule.quotient.eq _).2,
change y - (y + z) ∈ p',
rwa [sub_add_eq_sub_sub, sub_self, zero_sub, neg_mem_iff]
end
@[simp] lemma coe_quotient_inf_to_sup_quotient (p p' : submodule R M) :
⇑(quotient_inf_to_sup_quotient p p') = quotient_inf_equiv_sup_quotient p p' := rfl
@[simp] lemma quotient_inf_equiv_sup_quotient_apply_mk (p p' : submodule R M) (x : p) :
quotient_inf_equiv_sup_quotient p p' (submodule.quotient.mk x) =
submodule.quotient.mk (of_le (le_sup_left : p ≤ p ⊔ p') x) :=
rfl
lemma quotient_inf_equiv_sup_quotient_symm_apply_left (p p' : submodule R M)
(x : p ⊔ p') (hx : (x:M) ∈ p) :
(quotient_inf_equiv_sup_quotient p p').symm (submodule.quotient.mk x) =
submodule.quotient.mk ⟨x, hx⟩ :=
(linear_equiv.symm_apply_eq _).2 $ by simp [of_le_apply]
@[simp] lemma quotient_inf_equiv_sup_quotient_symm_apply_eq_zero_iff {p p' : submodule R M}
{x : p ⊔ p'} :
(quotient_inf_equiv_sup_quotient p p').symm (submodule.quotient.mk x) = 0 ↔ (x:M) ∈ p' :=
(linear_equiv.symm_apply_eq _).trans $ by simp [of_le_apply]
lemma quotient_inf_equiv_sup_quotient_symm_apply_right (p p' : submodule R M) {x : p ⊔ p'}
(hx : (x:M) ∈ p') :
(quotient_inf_equiv_sup_quotient p p').symm (submodule.quotient.mk x) = 0 :=
quotient_inf_equiv_sup_quotient_symm_apply_eq_zero_iff.2 hx
end isomorphism_laws
section prod
lemma is_linear_map_prod_iso {R M M₂ M₃ : Type*}
[comm_semiring R] [add_comm_monoid M] [add_comm_monoid M₂]
[add_comm_group M₃] [semimodule R M] [semimodule R M₂] [semimodule R M₃] :
is_linear_map R (λ(p : (M →ₗ[R] M₂) × (M →ₗ[R] M₃)),
(linear_map.prod p.1 p.2 : (M →ₗ[R] (M₂ × M₃)))) :=
⟨λu v, rfl, λc u, rfl⟩
end prod
section pi
universe i
variables [semiring R] [add_comm_monoid M₂] [semimodule R M₂] [add_comm_monoid M₃] [semimodule R M₃]
{φ : ι → Type i} [∀i, add_comm_monoid (φ i)] [∀i, semimodule R (φ i)]
/-- `pi` construction for linear functions. From a family of linear functions it produces a linear
function into a family of modules. -/
def pi (f : Πi, M₂ →ₗ[R] φ i) : M₂ →ₗ[R] (Πi, φ i) :=
⟨λc i, f i c, λ c d, funext $ λ i, (f i).map_add _ _, λ c d, funext $ λ i, (f i).map_smul _ _⟩
@[simp] lemma pi_apply (f : Πi, M₂ →ₗ[R] φ i) (c : M₂) (i : ι) :
pi f c i = f i c := rfl
lemma ker_pi (f : Πi, M₂ →ₗ[R] φ i) : ker (pi f) = (⨅i:ι, ker (f i)) :=
by ext c; simp [funext_iff]; refl
lemma pi_eq_zero (f : Πi, M₂ →ₗ[R] φ i) : pi f = 0 ↔ (∀i, f i = 0) :=
by simp only [linear_map.ext_iff, pi_apply, funext_iff]; exact ⟨λh a b, h b a, λh a b, h b a⟩
lemma pi_zero : pi (λi, 0 : Πi, M₂ →ₗ[R] φ i) = 0 :=
by ext; refl
lemma pi_comp (f : Πi, M₂ →ₗ[R] φ i) (g : M₃ →ₗ[R] M₂) : (pi f).comp g = pi (λi, (f i).comp g) :=
rfl
/-- The projections from a family of modules are linear maps. -/
def proj (i : ι) : (Πi, φ i) →ₗ[R] φ i :=
⟨ λa, a i, assume f g, rfl, assume c f, rfl ⟩
@[simp] lemma proj_apply (i : ι) (b : Πi, φ i) : (proj i : (Πi, φ i) →ₗ[R] φ i) b = b i := rfl
lemma proj_pi (f : Πi, M₂ →ₗ[R] φ i) (i : ι) : (proj i).comp (pi f) = f i :=
ext $ assume c, rfl
lemma infi_ker_proj : (⨅i, ker (proj i) : submodule R (Πi, φ i)) = ⊥ :=
bot_unique $ submodule.le_def'.2 $ assume a h,
begin
simp only [mem_infi, mem_ker, proj_apply] at h,
exact (mem_bot _).2 (funext $ assume i, h i)
end
section
variables (R φ)
/-- If `I` and `J` are disjoint index sets, the product of the kernels of the `J`th projections of
`φ` is linearly equivalent to the product over `I`. -/
def infi_ker_proj_equiv {I J : set ι} [decidable_pred (λi, i ∈ I)]
(hd : disjoint I J) (hu : set.univ ⊆ I ∪ J) :
(⨅i ∈ J, ker (proj i) : submodule R (Πi, φ i)) ≃ₗ[R] (Πi:I, φ i) :=
begin
refine linear_equiv.of_linear
(pi $ λi, (proj (i:ι)).comp (submodule.subtype _))
(cod_restrict _ (pi $ λi, if h : i ∈ I then proj (⟨i, h⟩ : I) else 0) _) _ _,
{ assume b,
simp only [mem_infi, mem_ker, funext_iff, proj_apply, pi_apply],
assume j hjJ,
have : j ∉ I := assume hjI, hd ⟨hjI, hjJ⟩,
rw [dif_neg this, zero_apply] },
{ simp only [pi_comp, comp_assoc, subtype_comp_cod_restrict, proj_pi, dif_pos, subtype.coe_prop],
ext b ⟨j, hj⟩, refl },
{ ext1 ⟨b, hb⟩,
apply subtype.ext,
ext j,
have hb : ∀i ∈ J, b i = 0,
{ simpa only [mem_infi, mem_ker, proj_apply] using (mem_infi _).1 hb },
simp only [comp_apply, pi_apply, id_apply, proj_apply, subtype_apply, cod_restrict_apply],
split_ifs,
{ refl },
{ exact (hb _ $ (hu trivial).resolve_left h).symm } }
end
end
section
variable [decidable_eq ι]
/-- `diag i j` is the identity map if `i = j`. Otherwise it is the constant 0 map. -/
def diag (i j : ι) : φ i →ₗ[R] φ j :=
@function.update ι (λj, φ i →ₗ[R] φ j) _ 0 i id j
lemma update_apply (f : Πi, M₂ →ₗ[R] φ i) (c : M₂) (i j : ι) (b : M₂ →ₗ[R] φ i) :
(update f i b j) c = update (λi, f i c) i (b c) j :=
begin
by_cases j = i,
{ rw [h, update_same, update_same] },
{ rw [update_noteq h, update_noteq h] }
end
end
section
variable [decidable_eq ι]
variables (R φ)
/-- The standard basis of the product of `φ`. -/
def std_basis (i : ι) : φ i →ₗ[R] (Πi, φ i) := pi (diag i)
lemma std_basis_apply (i : ι) (b : φ i) : std_basis R φ i b = update 0 i b :=
by ext j; rw [std_basis, pi_apply, diag, update_apply]; refl
@[simp] lemma std_basis_same (i : ι) (b : φ i) : std_basis R φ i b i = b :=
by rw [std_basis_apply, update_same]
lemma std_basis_ne (i j : ι) (h : j ≠ i) (b : φ i) : std_basis R φ i b j = 0 :=
by rw [std_basis_apply, update_noteq h]; refl
lemma ker_std_basis (i : ι) : ker (std_basis R φ i) = ⊥ :=
ker_eq_bot_of_injective $ assume f g hfg,
have std_basis R φ i f i = std_basis R φ i g i := hfg ▸ rfl,
by simpa only [std_basis_same]
lemma proj_comp_std_basis (i j : ι) : (proj i).comp (std_basis R φ j) = diag j i :=
by rw [std_basis, proj_pi]
lemma proj_std_basis_same (i : ι) : (proj i).comp (std_basis R φ i) = id :=
by ext b; simp
lemma proj_std_basis_ne (i j : ι) (h : i ≠ j) : (proj i).comp (std_basis R φ j) = 0 :=
by ext b; simp [std_basis_ne R φ _ _ h]
lemma supr_range_std_basis_le_infi_ker_proj (I J : set ι) (h : disjoint I J) :
(⨆i∈I, range (std_basis R φ i)) ≤ (⨅i∈J, ker (proj i)) :=
begin
refine (supr_le $ assume i, supr_le $ assume hi, range_le_iff_comap.2 _),
simp only [(ker_comp _ _).symm, eq_top_iff, le_def', mem_ker, comap_infi, mem_infi],
assume b hb j hj,
have : i ≠ j := assume eq, h ⟨hi, eq.symm ▸ hj⟩,
rw [proj_std_basis_ne R φ j i this.symm, zero_apply]
end
lemma infi_ker_proj_le_supr_range_std_basis {I : finset ι} {J : set ι} (hu : set.univ ⊆ ↑I ∪ J) :
(⨅ i∈J, ker (proj i)) ≤ (⨆i∈I, range (std_basis R φ i)) :=
submodule.le_def'.2
begin
assume b hb,
simp only [mem_infi, mem_ker, proj_apply] at hb,
rw ← show ∑ i in I, std_basis R φ i (b i) = b,
{ ext i,
rw [finset.sum_apply, ← std_basis_same R φ i (b i)],
refine finset.sum_eq_single i (assume j hjI ne, std_basis_ne _ _ _ _ ne.symm _) _,
assume hiI,
rw [std_basis_same],
exact hb _ ((hu trivial).resolve_left hiI) },
exact sum_mem _ (assume i hiI, mem_supr_of_mem i $ mem_supr_of_mem hiI $
(std_basis R φ i).mem_range_self (b i))
end
lemma supr_range_std_basis_eq_infi_ker_proj {I J : set ι}
(hd : disjoint I J) (hu : set.univ ⊆ I ∪ J) (hI : set.finite I) :
(⨆i∈I, range (std_basis R φ i)) = (⨅i∈J, ker (proj i)) :=
begin
refine le_antisymm (supr_range_std_basis_le_infi_ker_proj _ _ _ _ hd) _,
have : set.univ ⊆ ↑hI.to_finset ∪ J, { rwa [hI.coe_to_finset] },
refine le_trans (infi_ker_proj_le_supr_range_std_basis R φ this) (supr_le_supr $ assume i, _),
rw [set.finite.mem_to_finset],
exact le_refl _
end
lemma supr_range_std_basis [fintype ι] : (⨆i:ι, range (std_basis R φ i)) = ⊤ :=
have (set.univ : set ι) ⊆ ↑(finset.univ : finset ι) ∪ ∅ := by rw [finset.coe_univ, set.union_empty],
begin
apply top_unique,
convert (infi_ker_proj_le_supr_range_std_basis R φ this),
exact infi_emptyset.symm,
exact (funext $ λi, (@supr_pos _ _ _ (λh, range (std_basis R φ i)) $ finset.mem_univ i).symm)
end
lemma disjoint_std_basis_std_basis (I J : set ι) (h : disjoint I J) :
disjoint (⨆i∈I, range (std_basis R φ i)) (⨆i∈J, range (std_basis R φ i)) :=
begin
refine disjoint.mono
(supr_range_std_basis_le_infi_ker_proj _ _ _ _ $ set.disjoint_compl_right I)
(supr_range_std_basis_le_infi_ker_proj _ _ _ _ $ set.disjoint_compl_right J) _,
simp only [disjoint, submodule.le_def', mem_infi, mem_inf, mem_ker, mem_bot, proj_apply,
funext_iff],
rintros b ⟨hI, hJ⟩ i,
classical,
by_cases hiI : i ∈ I,
{ by_cases hiJ : i ∈ J,
{ exact (h ⟨hiI, hiJ⟩).elim },
{ exact hJ i hiJ } },
{ exact hI i hiI }
end
lemma std_basis_eq_single {a : R} :
(λ (i : ι), (std_basis R (λ _ : ι, R) i) a) = λ (i : ι), (finsupp.single i a) :=
begin
ext i j,
rw [std_basis_apply, finsupp.single_apply],
split_ifs,
{ rw [h, function.update_same] },
{ rw [function.update_noteq (ne.symm h)], refl },
end
end
end pi
section fun_left
variables (R M) [semiring R] [add_comm_monoid M] [semimodule R M]
variables {m n p : Type*}
/-- Given an `R`-module `M` and a function `m → n` between arbitrary types,
construct a linear map `(n → M) →ₗ[R] (m → M)` -/
def fun_left (f : m → n) : (n → M) →ₗ[R] (m → M) :=
mk (∘f) (λ _ _, rfl) (λ _ _, rfl)
@[simp] theorem fun_left_apply (f : m → n) (g : n → M) (i : m) : fun_left R M f g i = g (f i) :=
rfl
@[simp] theorem fun_left_id (g : n → M) : fun_left R M _root_.id g = g :=
rfl
theorem fun_left_comp (f₁ : n → p) (f₂ : m → n) :
fun_left R M (f₁ ∘ f₂) = (fun_left R M f₂).comp (fun_left R M f₁) :=
rfl
/-- Given an `R`-module `M` and an equivalence `m ≃ n` between arbitrary types,
construct a linear equivalence `(n → M) ≃ₗ[R] (m → M)` -/
def fun_congr_left (e : m ≃ n) : (n → M) ≃ₗ[R] (m → M) :=
linear_equiv.of_linear (fun_left R M e) (fun_left R M e.symm)
(ext $ λ x, funext $ λ i,
by rw [id_apply, ← fun_left_comp, equiv.symm_comp_self, fun_left_id])
(ext $ λ x, funext $ λ i,
by rw [id_apply, ← fun_left_comp, equiv.self_comp_symm, fun_left_id])
@[simp] theorem fun_congr_left_apply (e : m ≃ n) (x : n → M) :
fun_congr_left R M e x = fun_left R M e x :=
rfl
@[simp] theorem fun_congr_left_id :
fun_congr_left R M (equiv.refl n) = linear_equiv.refl R (n → M) :=
rfl
@[simp] theorem fun_congr_left_comp (e₁ : m ≃ n) (e₂ : n ≃ p) :
fun_congr_left R M (equiv.trans e₁ e₂) =
linear_equiv.trans (fun_congr_left R M e₂) (fun_congr_left R M e₁) :=
rfl
@[simp] lemma fun_congr_left_symm (e : m ≃ n) :
(fun_congr_left R M e).symm = fun_congr_left R M e.symm :=
rfl
end fun_left
universe i
variables [semiring R] [add_comm_monoid M] [semimodule R M]
variables (R M)
instance automorphism_group : group (M ≃ₗ[R] M) :=
{ mul := λ f g, g.trans f,
one := linear_equiv.refl R M,
inv := λ f, f.symm,
mul_assoc := λ f g h, by {ext, refl},
mul_one := λ f, by {ext, refl},
one_mul := λ f, by {ext, refl},
mul_left_inv := λ f, by {ext, exact f.left_inv x} }
instance automorphism_group.to_linear_map_is_monoid_hom :
is_monoid_hom (linear_equiv.to_linear_map : (M ≃ₗ[R] M) → (M →ₗ[R] M)) :=
{ map_one := rfl,
map_mul := λ f g, rfl }
/-- The group of invertible linear maps from `M` to itself -/
@[reducible] def general_linear_group := units (M →ₗ[R] M)
namespace general_linear_group
variables {R M}
instance : has_coe_to_fun (general_linear_group R M) := by apply_instance
/-- An invertible linear map `f` determines an equivalence from `M` to itself. -/
def to_linear_equiv (f : general_linear_group R M) : (M ≃ₗ[R] M) :=
{ inv_fun := f.inv.to_fun,
left_inv := λ m, show (f.inv * f.val) m = m,
by erw f.inv_val; simp,
right_inv := λ m, show (f.val * f.inv) m = m,
by erw f.val_inv; simp,
..f.val }
/-- An equivalence from `M` to itself determines an invertible linear map. -/
def of_linear_equiv (f : (M ≃ₗ[R] M)) : general_linear_group R M :=
{ val := f,
inv := f.symm,
val_inv := linear_map.ext $ λ _, f.apply_symm_apply _,
inv_val := linear_map.ext $ λ _, f.symm_apply_apply _ }
variables (R M)
/-- The general linear group on `R` and `M` is multiplicatively equivalent to the type of linear
equivalences between `M` and itself. -/
def general_linear_equiv : general_linear_group R M ≃* (M ≃ₗ[R] M) :=
{ to_fun := to_linear_equiv,
inv_fun := of_linear_equiv,
left_inv := λ f, by { ext, refl },
right_inv := λ f, by { ext, refl },
map_mul' := λ x y, by {ext, refl} }
@[simp] lemma general_linear_equiv_to_linear_map (f : general_linear_group R M) :
(general_linear_equiv R M f : M →ₗ[R] M) = f :=
by {ext, refl}
end general_linear_group
end linear_map
|
083cfea51532945e45240a915b35eea05c646306 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/analysis/fourier/poisson_summation.lean | 7c7f257793639607644bf7609c047c42d59c70eb | [
"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 | 12,925 | lean | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import analysis.fourier.add_circle
import analysis.fourier.fourier_transform
import analysis.p_series
import analysis.schwartz_space
import measure_theory.measure.lebesgue.integral
/-!
# Poisson's summation formula
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We prove Poisson's summation formula `∑ (n : ℤ), f n = ∑ (n : ℤ), 𝓕 f n`, where `𝓕 f` is the
Fourier transform of `f`, under the following hypotheses:
* `f` is a continuous function `ℝ → ℂ`.
* The sum `∑ (n : ℤ), 𝓕 f n` is convergent.
* For all compacts `K ⊂ ℝ`, the sum `∑ (n : ℤ), sup { ‖f(x + n)‖ | x ∈ K }` is convergent.
See `real.tsum_eq_tsum_fourier_integral` for this formulation.
These hypotheses are potentially a little awkward to apply, so we also provide the less general but
easier-to-use result `real.tsum_eq_tsum_fourier_integral_of_rpow_decay`, in which we assume `f` and
`𝓕 f` both decay as `|x| ^ (-b)` for some `b > 1`, and the even more specific result
`schwartz_map.tsum_eq_tsum_fourier_integral`, where we assume that both `f` and `𝓕 f` are Schwartz
functions.
## TODO
At the moment `schwartz_map.tsum_eq_tsum_fourier_integral` requires separate proofs that both `f`
and `𝓕 f` are Schwartz functions. In fact, `𝓕 f` is automatically Schwartz if `f` is; and once
we have this lemma in the library, we should adjust the hypotheses here accordingly.
-/
noncomputable theory
open function (hiding comp_apply) complex (hiding abs_of_nonneg) real set (hiding restrict_apply)
topological_space filter measure_theory asymptotics
open_locale real big_operators filter fourier_transform
local attribute [instance] real.fact_zero_lt_one
open continuous_map
/-- The key lemma for Poisson summation: the `m`-th Fourier coefficient of the periodic function
`∑' n : ℤ, f (x + n)` is the value at `m` of the Fourier transform of `f`. -/
lemma real.fourier_coeff_tsum_comp_add {f : C(ℝ, ℂ)}
(hf : ∀ (K : compacts ℝ), summable (λ n : ℤ, ‖(f.comp (continuous_map.add_right n)).restrict K‖))
(m : ℤ) :
fourier_coeff (periodic.lift $ f.periodic_tsum_comp_add_zsmul 1) m = 𝓕 f m :=
begin
-- NB: This proof can be shortened somewhat by telescoping together some of the steps in the calc
-- block, but I think it's more legible this way. We start with preliminaries about the integrand.
let e : C(ℝ, ℂ) := (fourier (-m)).comp ⟨(coe : ℝ → unit_add_circle), continuous_quotient_mk⟩,
have neK : ∀ (K : compacts ℝ) (g : C(ℝ, ℂ)), ‖(e * g).restrict K‖ = ‖g.restrict K‖,
{ have : ∀ (x : ℝ), ‖e x‖ = 1, from λ x, abs_coe_circle _,
intros K g,
simp_rw [norm_eq_supr_norm, restrict_apply, mul_apply, norm_mul, this, one_mul] },
have eadd : ∀ (n : ℤ), e.comp (continuous_map.add_right n) = e,
{ intro n, ext1 x,
have : periodic e 1, from periodic.comp (λ x, add_circle.coe_add_period 1 x) _,
simpa only [mul_one] using this.int_mul n x },
-- Now the main argument. First unwind some definitions.
calc fourier_coeff (periodic.lift $ f.periodic_tsum_comp_add_zsmul 1) m
= ∫ x in 0..1, e x * (∑' n : ℤ, f.comp (continuous_map.add_right n)) x :
by simp_rw [fourier_coeff_eq_interval_integral _ m 0, div_one, one_smul, zero_add, comp_apply,
coe_mk, periodic.lift_coe, zsmul_one, smul_eq_mul]
-- Transform sum in C(ℝ, ℂ) evaluated at x into pointwise sum of values.
... = ∫ x in 0..1, (∑' n : ℤ, (e * f.comp (continuous_map.add_right n)) x) :
by simp_rw [coe_mul, pi.mul_apply, ←tsum_apply (summable_of_locally_summable_norm hf),
tsum_mul_left]
-- Swap sum and integral.
... = ∑' n : ℤ, ∫ x in 0..1, (e * f.comp (continuous_map.add_right n)) x :
begin
refine (interval_integral.tsum_interval_integral_eq_of_summable_norm _).symm,
convert hf ⟨uIcc 0 1, is_compact_uIcc⟩,
exact funext (λ n, neK _ _)
end
... = ∑' n : ℤ, ∫ x in 0..1, (e * f).comp (continuous_map.add_right n) x :
begin
simp only [continuous_map.comp_apply, mul_comp] at eadd ⊢,
simp_rw eadd,
end
-- Rearrange sum of interval integrals into an integral over `ℝ`.
... = ∫ x, e x * f x :
begin
suffices : integrable ⇑(e * f), from this.has_sum_interval_integral_comp_add_int.tsum_eq,
apply integrable_of_summable_norm_Icc,
convert hf ⟨Icc 0 1, is_compact_Icc⟩,
simp_rw [continuous_map.comp_apply, mul_comp] at eadd ⊢,
simp_rw eadd,
exact funext (λ n, neK ⟨Icc 0 1, is_compact_Icc⟩ _),
end
-- Minor tidying to finish
... = 𝓕 f m :
begin
rw fourier_integral_eq_integral_exp_smul,
congr' 1 with x : 1,
rw [smul_eq_mul, comp_apply, coe_mk, fourier_coe_apply],
congr' 2,
push_cast,
ring
end
end
/-- **Poisson's summation formula**, most general form. -/
theorem real.tsum_eq_tsum_fourier_integral {f : C(ℝ, ℂ)}
(h_norm : ∀ (K : compacts ℝ),
summable (λ n : ℤ, ‖(f.comp $ continuous_map.add_right n).restrict K‖))
(h_sum : summable (λ n : ℤ, 𝓕 f n)) :
∑' (n : ℤ), f n = ∑' (n : ℤ), 𝓕 f n :=
begin
let F : C(unit_add_circle, ℂ) := ⟨(f.periodic_tsum_comp_add_zsmul 1).lift,
continuous_coinduced_dom.mpr (map_continuous _)⟩,
have : summable (fourier_coeff F),
{ convert h_sum,
exact funext (λ n, real.fourier_coeff_tsum_comp_add h_norm n) },
convert (has_pointwise_sum_fourier_series_of_summable this 0).tsum_eq.symm using 1,
{ have := (has_sum_apply (summable_of_locally_summable_norm h_norm).has_sum 0).tsum_eq,
simpa only [coe_mk, ←quotient_add_group.coe_zero, periodic.lift_coe, zsmul_one, comp_apply,
coe_add_right, zero_add] using this },
{ congr' 1 with n : 1,
rw [←real.fourier_coeff_tsum_comp_add h_norm n, fourier_eval_zero, smul_eq_mul, mul_one],
refl },
end
section rpow_decay
variables {E : Type*} [normed_add_comm_group E]
/-- If `f` is `O(x ^ (-b))` at infinity, then so is the function
`λ x, ‖f.restrict (Icc (x + R) (x + S))‖` for any fixed `R` and `S`. -/
lemma is_O_norm_Icc_restrict_at_top {f : C(ℝ, E)} {b : ℝ} (hb : 0 < b)
(hf : is_O at_top f (λ x : ℝ, |x| ^ (-b))) (R S : ℝ) :
is_O at_top (λ x : ℝ, ‖f.restrict (Icc (x + R) (x + S))‖) (λ x : ℝ, |x| ^ (-b)) :=
begin
-- First establish an explicit estimate on decay of inverse powers.
-- This is logically independent of the rest of the proof, but of no mathematical interest in
-- itself, so it is proved using `async` rather than being formulated as a separate lemma.
have claim : ∀ (x : ℝ), max 0 (-2 * R) < x →
∀ (y : ℝ), x + R ≤ y → y ^ (-b) ≤ (1 / 2) ^ (-b) * x ^ (-b),
{ intros x hx y hy,
rw max_lt_iff at hx,
have hxR : 0 < x + R,
{ rcases le_or_lt 0 R with h|h,
{ exact add_pos_of_pos_of_nonneg hx.1 h },
{ rw [←sub_lt_iff_lt_add, zero_sub],
refine lt_trans _ hx.2,
rwa [neg_mul, neg_lt_neg_iff, two_mul, add_lt_iff_neg_left] } },
have hy' : 0 < y, from hxR.trans_le hy,
have : y ^ (-b) ≤ (x + R) ^ (-b),
{ rw [rpow_neg hy'.le, rpow_neg hxR.le,
inv_le_inv (rpow_pos_of_pos hy' _) (rpow_pos_of_pos hxR _)],
exact rpow_le_rpow hxR.le hy hb.le },
refine this.trans _,
rw [←mul_rpow one_half_pos.le hx.1.le, rpow_neg (mul_pos one_half_pos hx.1).le,
rpow_neg hxR.le],
refine inv_le_inv_of_le (rpow_pos_of_pos (mul_pos one_half_pos hx.1) _) _,
exact rpow_le_rpow (mul_pos one_half_pos hx.1).le (by linarith) hb.le },
-- Now the main proof.
obtain ⟨c, hc, hc'⟩ := hf.exists_pos,
simp only [is_O, is_O_with, eventually_at_top] at hc' ⊢,
obtain ⟨d, hd⟩ := hc',
refine ⟨c * (1 / 2) ^ (-b), ⟨max (1 + max 0 (-2 * R)) (d - R), λ x hx, _⟩⟩,
rw [ge_iff_le, max_le_iff] at hx,
have hx' : max 0 (-2 * R) < x, by linarith,
rw max_lt_iff at hx',
rw [norm_norm, continuous_map.norm_le _
(mul_nonneg (mul_nonneg hc.le $ rpow_nonneg_of_nonneg one_half_pos.le _) (norm_nonneg _))],
refine λ y, (hd y.1 (by linarith [hx.1, y.2.1])).trans _,
have A : ∀ (x : ℝ), 0 ≤ |x| ^ (-b), from λ x, by positivity,
rwa [mul_assoc, mul_le_mul_left hc, norm_of_nonneg (A _), norm_of_nonneg (A _)],
convert claim x (by linarith only [hx.1]) y.1 y.2.1,
{ apply abs_of_nonneg, linarith [y.2.1] },
{ exact abs_of_pos hx'.1 },
end
lemma is_O_norm_Icc_restrict_at_bot {f : C(ℝ, E)} {b : ℝ} (hb : 0 < b)
(hf : is_O at_bot f (λ x : ℝ, |x| ^ (-b))) (R S : ℝ) :
is_O at_bot (λ x : ℝ, ‖f.restrict (Icc (x + R) (x + S))‖) (λ x : ℝ, |x| ^ (-b)) :=
begin
have h1 : is_O at_top (f.comp (continuous_map.mk _ continuous_neg)) (λ x : ℝ, |x| ^ (-b)),
{ convert hf.comp_tendsto tendsto_neg_at_top_at_bot,
ext1 x, simp only [function.comp_app, abs_neg] },
have h2 := (is_O_norm_Icc_restrict_at_top hb h1 (-S) (-R)).comp_tendsto tendsto_neg_at_bot_at_top,
have : ((λ (x : ℝ), |x| ^ -b) ∘ has_neg.neg) = (λ (x : ℝ), |x| ^ -b),
{ ext1 x, simp only [function.comp_app, abs_neg] },
rw this at h2,
refine (is_O_of_le _ (λ x, _)).trans h2, -- equality holds, but less work to prove `≤` alone
rw [norm_norm, function.comp_app, norm_norm, continuous_map.norm_le _ (norm_nonneg _)],
rintro ⟨x, hx⟩,
rw [continuous_map.restrict_apply_mk],
refine (le_of_eq _).trans (continuous_map.norm_coe_le_norm _ ⟨-x, _⟩),
{ exact ⟨by linarith [hx.2], by linarith [hx.1]⟩ },
{ rw [continuous_map.restrict_apply_mk, continuous_map.comp_apply, continuous_map.coe_mk,
neg_neg] }
end
lemma is_O_norm_restrict_cocompact (f : C(ℝ, E)) {b : ℝ} (hb : 0 < b)
(hf : is_O (cocompact ℝ) f (λ x : ℝ, |x| ^ (-b))) (K : compacts ℝ) :
is_O (cocompact ℝ) (λ x, ‖(f.comp (continuous_map.add_right x)).restrict K‖) (λ x, |x| ^ (-b)) :=
begin
obtain ⟨r, hr⟩ := K.is_compact.bounded.subset_ball 0,
rw [closed_ball_eq_Icc, zero_add, zero_sub] at hr,
have : ∀ (x : ℝ), ‖(f.comp (continuous_map.add_right x)).restrict K‖ ≤
‖f.restrict (Icc (x - r) (x + r))‖,
{ intro x,
rw continuous_map.norm_le _ (norm_nonneg _),
rintro ⟨y, hy⟩,
refine (le_of_eq _).trans (continuous_map.norm_coe_le_norm _ ⟨y + x, _⟩),
exact ⟨by linarith [(hr hy).1], by linarith [(hr hy).2]⟩,
simp_rw [continuous_map.restrict_apply, continuous_map.comp_apply,
continuous_map.coe_add_right, subtype.coe_mk] },
simp_rw [cocompact_eq, is_O_sup] at hf ⊢,
split,
{ refine (is_O_of_le at_bot _).trans (is_O_norm_Icc_restrict_at_bot hb hf.1 (-r) r),
simp_rw norm_norm, exact this },
{ refine (is_O_of_le at_top _).trans (is_O_norm_Icc_restrict_at_top hb hf.2 (-r) r),
simp_rw norm_norm, exact this },
end
/-- **Poisson's summation formula**, assuming that `f` decays as
`|x| ^ (-b)` for some `1 < b` and its Fourier transform is summable. -/
lemma real.tsum_eq_tsum_fourier_integral_of_rpow_decay_of_summable {f : ℝ → ℂ} (hc : continuous f)
{b : ℝ} (hb : 1 < b) (hf : is_O (cocompact ℝ) f (λ x : ℝ, |x| ^ (-b)))
(hFf : summable (λ n : ℤ, 𝓕 f n)) :
∑' (n : ℤ), f n = ∑' (n : ℤ), 𝓕 f n :=
real.tsum_eq_tsum_fourier_integral
(λ K, summable_of_is_O (real.summable_abs_int_rpow hb)
((is_O_norm_restrict_cocompact (continuous_map.mk _ hc)
(zero_lt_one.trans hb) hf K).comp_tendsto int.tendsto_coe_cofinite)) hFf
/-- **Poisson's summation formula**, assuming that both `f` and its Fourier transform decay as
`|x| ^ (-b)` for some `1 < b`. (This is the one-dimensional case of Corollary VII.2.6 of Stein and
Weiss, *Introduction to Fourier analysis on Euclidean spaces*.) -/
lemma real.tsum_eq_tsum_fourier_integral_of_rpow_decay {f : ℝ → ℂ} (hc : continuous f)
{b : ℝ} (hb : 1 < b) (hf : is_O (cocompact ℝ) f (λ x : ℝ, |x| ^ (-b)))
(hFf : is_O (cocompact ℝ) (𝓕 f) (λ x : ℝ, |x| ^ (-b))) :
∑' (n : ℤ), f n = ∑' (n : ℤ), 𝓕 f n :=
real.tsum_eq_tsum_fourier_integral_of_rpow_decay_of_summable hc hb hf
(summable_of_is_O (real.summable_abs_int_rpow hb) (hFf.comp_tendsto int.tendsto_coe_cofinite))
end rpow_decay
section schwartz
/-- **Poisson's summation formula** for Schwartz functions. -/
lemma schwartz_map.tsum_eq_tsum_fourier_integral
(f g : schwartz_map ℝ ℂ) (hfg : 𝓕 f = g) :
∑' (n : ℤ), f n = ∑' (n : ℤ), g n :=
begin
-- We know that Schwartz functions are `O(‖x ^ (-b)‖)` for *every* `b`; for this argument we take
-- `b = 2` and work with that.
simp_rw ←hfg,
exact real.tsum_eq_tsum_fourier_integral_of_rpow_decay f.continuous one_lt_two
(f.is_O_cocompact_rpow (-2)) (by simpa only [hfg] using g.is_O_cocompact_rpow (-2))
end
end schwartz
|
9f52459759b901f2cd91aecd023fcbf22230fb13 | 7a76361040c55ae1eba5856c1a637593117a6556 | /src/homework/love01_definitions_and_statements_homework_sheet.lean | bec16fb676a5dd45f9ee2af0c0939f9767bb19c9 | [] | no_license | rgreenblatt/fpv2021 | c2cbe7b664b648cef7d240a654d6bdf97a559272 | c65d72e48c8fa827d2040ed6ea86c2be62db36fa | refs/heads/main | 1,692,245,693,819 | 1,633,364,621,000 | 1,633,364,621,000 | 407,231,487 | 0 | 0 | null | 1,631,808,608,000 | 1,631,808,608,000 | null | UTF-8 | Lean | false | false | 2,786 | lean | import ..lovelib
/-! # LoVe Homework 1: Definitions and Statements
Homework must be done individually.
Replace the placeholders (e.g., `:= sorry`) with your solutions. -/
set_option pp.beta true
set_option pp.generalized_field_notation false
namespace LoVe
/-! ## Question 1 (1 points): Snoc
1.1 (1 point). Define the function `snoc` that appends a single element to the
end of a list. Your function should be defined by recursion and not using `++`
(`list.append`). -/
def snoc {α : Type} : list α → α → list α :=
sorry
/-! 1.2 (0 point). Convince yourself that your definition of `snoc` works by
testing it on a few examples. -/
#reduce snoc [1] 2
-- invoke `#reduce` or `#eval` here
/-! ## Question 2 (3 points): Map
2.1 (1 point). Define a generic `map` function that applies a function to every
element in a list. -/
def map {α : Type} {β : Type} (f : α → β) : list α → list β :=
sorry
/-! 2.2 (2 points). State (without proving them) the so-called functorial
properties of `map` as lemmas. Schematically:
map (λx, x) xs = xs
map (λx, g (f x)) xs = map g (map f xs)
Try to give meaningful names to your lemmas. Also, make sure to state the second
property as generally as possible, for arbitrary types. -/
-- enter your lemma statements here
/-! ## Question 3 (5 points): λ-Terms
We start by declaring four new opaque types. -/
constants α β γ δ : Type
/-! 3.1 (2 points). Complete the following definitions, by providing terms with
the expected type.
Please use reasonable names for the bound variables, e.g., `a : α`, `b : β`,
`c : γ`.
Hint: A procedure for doing so systematically is described in Section 1.1.4 of
the Hitchhiker's Guide. As explained there, you can use `_` as a placeholder
while constructing a term. By hovering over `_`, you will see the current
logical context. -/
def B : (α → β) → (γ → α) → γ → β :=
sorry
def S : (α → β → γ) → (α → β) → α → γ :=
sorry
def more_nonsense : ((α → β) → γ → δ) → γ → β → δ :=
sorry
def even_more_nonsense : (α → β) → (α → γ) → α → β → γ :=
sorry
/-! 3.2 (1 point). Complete the following definition.
This one looks more difficult, but it should be fairly straightforward if you
follow the procedure described in the Hitchhiker's Guide.
Note: Peirce is pronounced like the English word "purse". -/
def weak_peirce : ((((α → β) → α) → α) → β) → β :=
sorry
/-! 3.3 (2 points). Show the typing derivation for your definition of `B` above,
using ASCII or Unicode art. You might find the characters `–` (to draw
horizontal bars) and `⊢` useful.
Feel free to introduce abbreviations to avoid repeating large contexts `Γ`. -/
-- write your solution here
end LoVe
|
6d6339b549bbd676bdbf22f90cd3c06b81bc9fea | d1a52c3f208fa42c41df8278c3d280f075eb020c | /src/Init/Data/String/Basic.lean | fd398b1d876974d563018ae466b2175936768198 | [
"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 | 17,958 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
prelude
import Init.Data.List.Basic
import Init.Data.Char.Basic
import Init.Data.Option.Basic
universe u
def List.asString (s : List Char) : String :=
⟨s⟩
namespace String
instance : LT String :=
⟨fun s₁ s₂ => s₁.data < s₂.data⟩
@[extern "lean_string_dec_lt"]
instance decLt (s₁ s₂ : @& String) : Decidable (s₁ < s₂) :=
List.hasDecidableLt s₁.data s₂.data
@[extern "lean_string_length"]
def length : (@& String) → Nat
| ⟨s⟩ => s.length
/-- The internal implementation uses dynamic arrays and will perform destructive updates
if the String is not shared. -/
@[extern "lean_string_push"]
def push : String → Char → String
| ⟨s⟩, c => ⟨s ++ [c]⟩
/-- The internal implementation uses dynamic arrays and will perform destructive updates
if the String is not shared. -/
@[extern "lean_string_append"]
def append : String → (@& String) → String
| ⟨a⟩, ⟨b⟩ => ⟨a ++ b⟩
/-- O(n) in the runtime, where n is the length of the String -/
def toList (s : String) : List Char :=
s.data
private def utf8GetAux : List Char → Pos → Pos → Char
| [], i, p => arbitrary
| c::cs, i, p => if i = p then c else utf8GetAux cs (i + csize c) p
@[extern "lean_string_utf8_get"]
def get : (@& String) → (@& Pos) → Char
| ⟨s⟩, p => utf8GetAux s 0 p
def getOp (self : String) (idx : Pos) : Char :=
self.get idx
private def utf8SetAux (c' : Char) : List Char → Pos → Pos → List Char
| [], i, p => []
| c::cs, i, p =>
if i = p then (c'::cs) else c::(utf8SetAux c' cs (i + csize c) p)
@[extern "lean_string_utf8_set"]
def set : String → (@& Pos) → Char → String
| ⟨s⟩, i, c => ⟨utf8SetAux c s 0 i⟩
def modify (s : String) (i : Pos) (f : Char → Char) : String :=
s.set i <| f <| s.get i
@[extern "lean_string_utf8_next"]
def next (s : @& String) (p : @& Pos) : Pos :=
let c := get s p
p + csize c
private def utf8PrevAux : List Char → Pos → Pos → Pos
| [], i, p => 0
| c::cs, i, p =>
let cz := csize c
let i' := i + cz
if i' = p then i else utf8PrevAux cs i' p
@[extern "lean_string_utf8_prev"]
def prev : (@& String) → (@& Pos) → Pos
| ⟨s⟩, p => if p = 0 then 0 else utf8PrevAux s 0 p
def front (s : String) : Char :=
get s 0
def back (s : String) : Char :=
get s (prev s (bsize s))
@[extern "lean_string_utf8_at_end"]
def atEnd : (@& String) → (@& Pos) → Bool
| s, p => p ≥ utf8ByteSize s
/- TODO: remove `partial` keywords after we restore the tactic
framework and wellfounded recursion support -/
partial def posOfAux (s : String) (c : Char) (stopPos : Pos) (pos : Pos) : Pos :=
if pos == stopPos then pos
else if s.get pos == c then pos
else posOfAux s c stopPos (s.next pos)
@[inline] def posOf (s : String) (c : Char) : Pos :=
posOfAux s c s.bsize 0
partial def revPosOfAux (s : String) (c : Char) (pos : Pos) : Option Pos :=
if s.get pos == c then some pos
else if pos == 0 then none
else revPosOfAux s c (s.prev pos)
def revPosOf (s : String) (c : Char) : Option Pos :=
if s.bsize == 0 then none
else revPosOfAux s c (s.prev s.bsize)
partial def findAux (s : String) (p : Char → Bool) (stopPos : Pos) (pos : Pos) : Pos :=
if pos == stopPos then pos
else if p (s.get pos) then pos
else findAux s p stopPos (s.next pos)
@[inline] def find (s : String) (p : Char → Bool) : Pos :=
findAux s p s.bsize 0
partial def revFindAux (s : String) (p : Char → Bool) (pos : Pos) : Option Pos :=
if p (s.get pos) then some pos
else if pos == 0 then none
else revFindAux s p (s.prev pos)
def revFind (s : String) (p : Char → Bool) : Option Pos :=
if s.bsize == 0 then none
else revFindAux s p (s.prev s.bsize)
/-- Returns the first position where the two strings differ. -/
partial def firstDiffPos (a b : String) : Pos :=
let stopPos := a.bsize.min b.bsize
let rec loop (i : Pos) : Pos :=
if i == stopPos || a.get i != b.get i then i
else loop (a.next i)
loop 0
private def utf8ExtractAux₂ : List Char → Pos → Pos → List Char
| [], _, _ => []
| c::cs, i, e => if i = e then [] else c :: utf8ExtractAux₂ cs (i + csize c) e
private def utf8ExtractAux₁ : List Char → Pos → Pos → Pos → List Char
| [], _, _, _ => []
| s@(c::cs), i, b, e => if i = b then utf8ExtractAux₂ s i e else utf8ExtractAux₁ cs (i + csize c) b e
@[extern "lean_string_utf8_extract"]
def extract : (@& String) → (@& Pos) → (@& Pos) → String
| ⟨s⟩, b, e => if b ≥ e then ⟨[]⟩ else ⟨utf8ExtractAux₁ s 0 b e⟩
@[specialize] partial def splitAux (s : String) (p : Char → Bool) (b : Pos) (i : Pos) (r : List String) : List String :=
if s.atEnd i then
let r := (s.extract b i)::r
r.reverse
else if p (s.get i) then
let i := s.next i
splitAux s p i i (s.extract b (i-1)::r)
else
splitAux s p b (s.next i) r
@[specialize] def split (s : String) (p : Char → Bool) : List String :=
splitAux s p 0 0 []
partial def splitOnAux (s sep : String) (b : Pos) (i : Pos) (j : Pos) (r : List String) : List String :=
if s.atEnd i then
let r := if sep.atEnd j then ""::(s.extract b (i-j))::r else (s.extract b i)::r
r.reverse
else if s.get i == sep.get j then
let i := s.next i
let j := sep.next j
if sep.atEnd j then
splitOnAux s sep i i 0 (s.extract b (i-j)::r)
else
splitOnAux s sep b i j r
else
splitOnAux s sep b (s.next i) 0 r
def splitOn (s : String) (sep : String := " ") : List String :=
if sep == "" then [s] else splitOnAux s sep 0 0 0 []
instance : Inhabited String := ⟨""⟩
instance : Append String := ⟨String.append⟩
def str : String → Char → String := push
def pushn (s : String) (c : Char) (n : Nat) : String :=
n.repeat (fun s => s.push c) s
def isEmpty (s : String) : Bool :=
s.bsize == 0
def join (l : List String) : String :=
l.foldl (fun r s => r ++ s) ""
def singleton (c : Char) : String :=
"".push c
def intercalate (s : String) : List String → String
| [] => ""
| a :: as => go a s as
where go (acc : String) (s : String) : List String → String
| a :: as => go (acc ++ s ++ a) s as
| [] => acc
structure Iterator where
s : String
i : Pos
deriving DecidableEq
def mkIterator (s : String) : Iterator :=
⟨s, 0⟩
namespace Iterator
def toString : Iterator → String
| ⟨s, _⟩ => s
def remainingBytes : Iterator → Nat
| ⟨s, i⟩ => s.bsize - i
def pos : Iterator → Pos
| ⟨s, i⟩ => i
def curr : Iterator → Char
| ⟨s, i⟩ => get s i
def next : Iterator → Iterator
| ⟨s, i⟩ => ⟨s, s.next i⟩
def prev : Iterator → Iterator
| ⟨s, i⟩ => ⟨s, s.prev i⟩
def hasNext : Iterator → Bool
| ⟨s, i⟩ => i < utf8ByteSize s
def hasPrev : Iterator → Bool
| ⟨s, i⟩ => i > 0
def setCurr : Iterator → Char → Iterator
| ⟨s, i⟩, c => ⟨s.set i c, i⟩
def toEnd : Iterator → Iterator
| ⟨s, _⟩ => ⟨s, s.bsize⟩
def extract : Iterator → Iterator → String
| ⟨s₁, b⟩, ⟨s₂, e⟩ =>
if s₁ ≠ s₂ || b > e then ""
else s₁.extract b e
def forward : Iterator → Nat → Iterator
| it, 0 => it
| it, n+1 => forward it.next n
def remainingToString : Iterator → String
| ⟨s, i⟩ => s.extract i s.bsize
def nextn : Iterator → Nat → Iterator
| it, 0 => it
| it, i+1 => nextn it.next i
def prevn : Iterator → Nat → Iterator
| it, 0 => it
| it, i+1 => prevn it.prev i
end Iterator
partial def offsetOfPosAux (s : String) (pos : Pos) (i : Pos) (offset : Nat) : Nat :=
if i == pos || s.atEnd i then
offset
else
offsetOfPosAux s pos (s.next i) (offset+1)
def offsetOfPos (s : String) (pos : Pos) : Nat :=
offsetOfPosAux s pos 0 0
@[specialize] partial def foldlAux {α : Type u} (f : α → Char → α) (s : String) (stopPos : Pos) (i : Pos) (a : α) : α :=
let rec loop (i : Pos) (a : α) :=
if i == stopPos then a
else loop (s.next i) (f a (s.get i))
loop i a
@[inline] def foldl {α : Type u} (f : α → Char → α) (init : α) (s : String) : α :=
foldlAux f s s.bsize 0 init
@[specialize] partial def foldrAux {α : Type u} (f : Char → α → α) (a : α) (s : String) (stopPos : Pos) (i : Pos) : α :=
let rec loop (i : Pos) :=
if i == stopPos then a
else f (s.get i) (loop (s.next i))
loop i
@[inline] def foldr {α : Type u} (f : Char → α → α) (init : α) (s : String) : α :=
foldrAux f init s s.bsize 0
@[specialize] partial def anyAux (s : String) (stopPos : Pos) (p : Char → Bool) (i : Pos) : Bool :=
let rec loop (i : Pos) :=
if i == stopPos then false
else if p (s.get i) then true
else loop (s.next i)
loop i
@[inline] def any (s : String) (p : Char → Bool) : Bool :=
anyAux s s.bsize p 0
@[inline] def all (s : String) (p : Char → Bool) : Bool :=
!s.any (fun c => !p c)
def contains (s : String) (c : Char) : Bool :=
s.any (fun a => a == c)
@[specialize] partial def mapAux (f : Char → Char) (i : Pos) (s : String) : String :=
if s.atEnd i then s
else
let c := f (s.get i)
let s := s.set i c
mapAux f (s.next i) s
@[inline] def map (f : Char → Char) (s : String) : String :=
mapAux f 0 s
def isNat (s : String) : Bool :=
s.all fun c => c.isDigit
def toNat? (s : String) : Option Nat :=
if s.isNat then
some <| s.foldl (fun n c => n*10 + (c.toNat - '0'.toNat)) 0
else
none
/--
Return `true` iff the substring of length `sz` starting at position `off1` in `s1` is equal to that starting at `off2` in `s2.`.
False if either substring of that length does not exist. -/
partial def substrEq (s1 : String) (off1 : String.Pos) (s2 : String) (off2 : String.Pos) (sz : Nat) : Bool :=
off1 + sz ≤ s1.bsize && off2 + sz ≤ s2.bsize && loop off1 off2 (off1 + sz)
where
loop (off1 off2 stop1 : Pos) :=
if off1 >= stop1 then true
else
let c₁ := s1.get off1
let c₂ := s2.get off2
c₁ == c₂ && loop (off1 + csize c₁) (off2 + csize c₂) stop1
/-- Return true iff `p` is a prefix of `s` -/
def isPrefixOf (p : String) (s : String) : Bool :=
substrEq p 0 s 0 p.bsize
/-- Replace all occurrences of `pattern` in `s` with `replacment`. -/
partial def replace (s pattern replacement : String) : String :=
loop "" 0 0
where
loop (acc : String) (accStop pos : String.Pos) :=
if pos + pattern.bsize > s.bsize then
acc ++ s.extract accStop s.bsize
else if s.substrEq pos pattern 0 pattern.bsize then
loop (acc ++ s.extract accStop pos ++ replacement) (pos + pattern.bsize) (pos + pattern.bsize)
else
loop acc accStop (s.next pos)
end String
namespace Substring
@[inline] def isEmpty (ss : Substring) : Bool :=
ss.bsize == 0
@[inline] def toString : Substring → String
| ⟨s, b, e⟩ => s.extract b e
@[inline] def toIterator : Substring → String.Iterator
| ⟨s, b, _⟩ => ⟨s, b⟩
/-- Return the codepoint at the given offset into the substring. -/
@[inline] def get : Substring → String.Pos → Char
| ⟨s, b, _⟩, p => s.get (b+p)
/-- Given an offset of a codepoint into the substring,
return the offset there of the next codepoint. -/
@[inline] def next : Substring → String.Pos → String.Pos
| ⟨s, b, e⟩, p =>
let absP := b+p
if absP = e then p else s.next absP - b
/-- Given an offset of a codepoint into the substring,
return the offset there of the previous codepoint. -/
@[inline] def prev : Substring → String.Pos → String.Pos
| ⟨s, b, _⟩, p =>
let absP := b+p
if absP = b then p else s.prev absP - b
def nextn : Substring → Nat → String.Pos → String.Pos
| ss, 0, p => p
| ss, i+1, p => ss.nextn i (ss.next p)
def prevn : Substring → String.Pos → Nat → String.Pos
| ss, 0, p => p
| ss, i+1, p => ss.prevn i (ss.prev p)
@[inline] def front (s : Substring) : Char :=
s.get 0
/-- Return the offset into `s` of the first occurence of `c` in `s`,
or `s.bsize` if `c` doesn't occur. -/
@[inline] def posOf (s : Substring) (c : Char) : String.Pos :=
match s with
| ⟨s, b, e⟩ => (String.posOfAux s c e b) - b
@[inline] def drop : Substring → Nat → Substring
| ss@⟨s, b, e⟩, n => ⟨s, b + ss.nextn n 0, e⟩
@[inline] def dropRight : Substring → Nat → Substring
| ss@⟨s, b, e⟩, n => ⟨s, b, b + ss.prevn n ss.bsize⟩
@[inline] def take : Substring → Nat → Substring
| ss@⟨s, b, e⟩, n => ⟨s, b, b + ss.nextn n 0⟩
@[inline] def takeRight : Substring → Nat → Substring
| ss@⟨s, b, e⟩, n => ⟨s, b + ss.prevn n ss.bsize, e⟩
@[inline] def atEnd : Substring → String.Pos → Bool
| ⟨s, b, e⟩, p => b + p == e
@[inline] def extract : Substring → String.Pos → String.Pos → Substring
| ⟨s, b, e⟩, b', e' => if b' ≥ e' then ⟨"", 0, 0⟩ else ⟨s, e.min (b+b'), e.min (b+e')⟩
partial def splitOn (s : Substring) (sep : String := " ") : List Substring :=
if sep == "" then
[s]
else
let rec loop (b i j : String.Pos) (r : List Substring) : List Substring :=
if i == s.bsize then
let r := if sep.atEnd j then
"".toSubstring :: s.extract b (i-j) :: r
else
s.extract b i :: r
r.reverse
else if s.get i == sep.get j then
let i := s.next i
let j := sep.next j
if sep.atEnd j then
loop i i 0 (s.extract b (i-j) :: r)
else
loop b i j r
else
loop b (s.next i) 0 r
loop 0 0 0 []
@[inline] def foldl {α : Type u} (f : α → Char → α) (init : α) (s : Substring) : α :=
match s with
| ⟨s, b, e⟩ => String.foldlAux f s e b init
@[inline] def foldr {α : Type u} (f : Char → α → α) (init : α) (s : Substring) : α :=
match s with
| ⟨s, b, e⟩ => String.foldrAux f init s e b
@[inline] def any (s : Substring) (p : Char → Bool) : Bool :=
match s with
| ⟨s, b, e⟩ => String.anyAux s e p b
@[inline] def all (s : Substring) (p : Char → Bool) : Bool :=
!s.any (fun c => !p c)
def contains (s : Substring) (c : Char) : Bool :=
s.any (fun a => a == c)
@[specialize] private partial def takeWhileAux (s : String) (stopPos : String.Pos) (p : Char → Bool) (i : String.Pos) : String.Pos :=
if i == stopPos then i
else if p (s.get i) then takeWhileAux s stopPos p (s.next i)
else i
@[inline] def takeWhile : Substring → (Char → Bool) → Substring
| ⟨s, b, e⟩, p =>
let e := takeWhileAux s e p b;
⟨s, b, e⟩
@[inline] def dropWhile : Substring → (Char → Bool) → Substring
| ⟨s, b, e⟩, p =>
let b := takeWhileAux s e p b;
⟨s, b, e⟩
@[specialize] private partial def takeRightWhileAux (s : String) (begPos : String.Pos) (p : Char → Bool) (i : String.Pos) : String.Pos :=
if i == begPos then i
else
let i' := s.prev i
let c := s.get i'
if !p c then i
else takeRightWhileAux s begPos p i'
@[inline] def takeRightWhile : Substring → (Char → Bool) → Substring
| ⟨s, b, e⟩, p =>
let b := takeRightWhileAux s b p e
⟨s, b, e⟩
@[inline] def dropRightWhile : Substring → (Char → Bool) → Substring
| ⟨s, b, e⟩, p =>
let e := takeRightWhileAux s b p e
⟨s, b, e⟩
@[inline] def trimLeft (s : Substring) : Substring :=
s.dropWhile Char.isWhitespace
@[inline] def trimRight (s : Substring) : Substring :=
s.dropRightWhile Char.isWhitespace
@[inline] def trim : Substring → Substring
| ⟨s, b, e⟩ =>
let b := takeWhileAux s e Char.isWhitespace b
let e := takeRightWhileAux s b Char.isWhitespace e
⟨s, b, e⟩
def isNat (s : Substring) : Bool :=
s.all fun c => c.isDigit
def toNat? (s : Substring) : Option Nat :=
if s.isNat then
some <| s.foldl (fun n c => n*10 + (c.toNat - '0'.toNat)) 0
else
none
def beq (ss1 ss2 : Substring) : Bool :=
ss1.bsize == ss2.bsize && ss1.str.substrEq ss1.startPos ss2.str ss2.startPos ss1.bsize
instance hasBeq : BEq Substring := ⟨beq⟩
end Substring
namespace String
def drop (s : String) (n : Nat) : String :=
(s.toSubstring.drop n).toString
def dropRight (s : String) (n : Nat) : String :=
(s.toSubstring.dropRight n).toString
def take (s : String) (n : Nat) : String :=
(s.toSubstring.take n).toString
def takeRight (s : String) (n : Nat) : String :=
(s.toSubstring.takeRight n).toString
def takeWhile (s : String) (p : Char → Bool) : String :=
(s.toSubstring.takeWhile p).toString
def dropWhile (s : String) (p : Char → Bool) : String :=
(s.toSubstring.dropWhile p).toString
def takeRightWhile (s : String) (p : Char → Bool) : String :=
(s.toSubstring.takeRightWhile p).toString
def dropRightWhile (s : String) (p : Char → Bool) : String :=
(s.toSubstring.dropRightWhile p).toString
def startsWith (s pre : String) : Bool :=
s.toSubstring.take pre.length == pre.toSubstring
def endsWith (s post : String) : Bool :=
s.toSubstring.takeRight post.length == post.toSubstring
def trimRight (s : String) : String :=
s.toSubstring.trimRight.toString
def trimLeft (s : String) : String :=
s.toSubstring.trimLeft.toString
def trim (s : String) : String :=
s.toSubstring.trim.toString
@[inline] def nextWhile (s : String) (p : Char → Bool) (i : String.Pos) : String.Pos :=
Substring.takeWhileAux s s.bsize p i
@[inline] def nextUntil (s : String) (p : Char → Bool) (i : String.Pos) : String.Pos :=
nextWhile s (fun c => !p c) i
def toUpper (s : String) : String :=
s.map Char.toUpper
def toLower (s : String) : String :=
s.map Char.toLower
def capitalize (s : String) :=
s.set 0 <| s.get 0 |>.toUpper
def decapitalize (s : String) :=
s.set 0 <| s.get 0 |>.toLower
end String
protected def Char.toString (c : Char) : String :=
String.singleton c
|
f5462410220ba599fa1c20d894523e94d2e91004 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/algebra/char_p/pi.lean | b3591a350372b2b9d727354d928281d74a2a35f5 | [
"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 | 969 | lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import algebra.char_p.basic
import algebra.ring.pi
/-!
# Characteristic of semirings of functions
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
-/
universes u v
namespace char_p
instance pi (ι : Type u) [hi : nonempty ι] (R : Type v) [semiring R] (p : ℕ) [char_p R p] :
char_p (ι → R) p :=
⟨λ x, let ⟨i⟩ := hi in iff.symm $ (char_p.cast_eq_zero_iff R p x).symm.trans
⟨λ h, funext $ λ j, show pi.eval_ring_hom (λ _, R) j (↑x : ι → R) = 0,
by rw [map_nat_cast, h],
λ h, map_nat_cast (pi.eval_ring_hom (λ _: ι, R) i) x ▸ by rw [h, ring_hom.map_zero]⟩⟩
-- diamonds
instance pi' (ι : Type u) [hi : nonempty ι] (R : Type v) [comm_ring R] (p : ℕ) [char_p R p] :
char_p (ι → R) p :=
char_p.pi ι R p
end char_p
|
0a9416b67d345adb3f74da1a814a70047dbc6674 | 19cc34575500ee2e3d4586c15544632aa07a8e66 | /src/analysis/normed_space/multilinear.lean | addab7ba812c10371f89769d3fbe072f22b87373 | [
"Apache-2.0"
] | permissive | LibertasSpZ/mathlib | b9fcd46625eb940611adb5e719a4b554138dade6 | 33f7870a49d7cc06d2f3036e22543e6ec5046e68 | refs/heads/master | 1,672,066,539,347 | 1,602,429,158,000 | 1,602,429,158,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 53,354 | lean | /-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import analysis.normed_space.operator_norm
import topology.algebra.multilinear
/-!
# Operator norm on the space of continuous multilinear maps
When `f` is a continuous multilinear map in finitely many variables, we define its norm `∥f∥` as the
smallest number such that `∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥` for all `m`.
We show that it is indeed a norm, and prove its basic properties.
## Main results
Let `f` be a multilinear map in finitely many variables.
* `exists_bound_of_continuous` asserts that, if `f` is continuous, then there exists `C > 0`
with `∥f m∥ ≤ C * ∏ i, ∥m i∥` for all `m`.
* `continuous_of_bound`, conversely, asserts that this bound implies continuity.
* `mk_continuous` constructs the associated continuous multilinear map.
Let `f` be a continuous multilinear map in finitely many variables.
* `∥f∥` is its norm, i.e., the smallest number such that `∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥` for
all `m`.
* `le_op_norm f m` asserts the fundamental inequality `∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥`.
* `norm_image_sub_le_of_bound f m₁ m₂` gives a control of the difference `f m₁ - f m₂` in terms of
`∥f∥` and `∥m₁ - m₂∥`.
We also register isomorphisms corresponding to currying or uncurrying variables, transforming a
continuous multilinear function `f` in `n+1` variables into a continuous linear function taking
values in continuous multilinear functions in `n` variables, and also into a continuous multilinear
function in `n` variables taking values in continuous linear functions. These operations are called
`f.curry_left` and `f.curry_right` respectively (with inverses `f.uncurry_left` and
`f.uncurry_right`). They induce continuous linear equivalences between spaces of
continuous multilinear functions in `n+1` variables and spaces of continuous linear functions into
continuous multilinear functions in `n` variables (resp. continuous multilinear functions in `n`
variables taking values in continuous linear functions), called respectively
`continuous_multilinear_curry_left_equiv` and `continuous_multilinear_curry_right_equiv`.
## Implementation notes
We mostly follow the API (and the proofs) of `operator_norm.lean`, with the additional complexity
that we should deal with multilinear maps in several variables. The currying/uncurrying
constructions are based on those in `multilinear.lean`.
From the mathematical point of view, all the results follow from the results on operator norm in
one variable, by applying them to one variable after the other through currying. However, this
is only well defined when there is an order on the variables (for instance on `fin n`) although
the final result is independent of the order. While everything could be done following this
approach, it turns out that direct proofs are easier and more efficient.
-/
noncomputable theory
open_locale classical big_operators
open finset
local attribute [instance, priority 1001]
add_comm_group.to_add_comm_monoid normed_group.to_add_comm_group normed_space.to_semimodule
universes u v w w₁ w₂ wG
variables {𝕜 : Type u} {ι : Type v} {n : ℕ}
{G : Type wG} {E : fin n.succ → Type w} {E₁ : ι → Type w₁} {E₂ : Type w₂}
[decidable_eq ι] [fintype ι] [nondiscrete_normed_field 𝕜]
[normed_group G] [∀i, normed_group (E i)] [∀i, normed_group (E₁ i)] [normed_group E₂]
[normed_space 𝕜 G] [∀i, normed_space 𝕜 (E i)] [∀i, normed_space 𝕜 (E₁ i)] [normed_space 𝕜 E₂]
/-!
### Continuity properties of multilinear maps
We relate continuity of multilinear maps to the inequality `∥f m∥ ≤ C * ∏ i, ∥m i∥`, in
both directions. Along the way, we prove useful bounds on the difference `∥f m₁ - f m₂∥`.
-/
namespace multilinear_map
variable (f : multilinear_map 𝕜 E₁ E₂)
/-- If a multilinear map in finitely many variables on normed spaces is continuous, then it
satisfies the inequality `∥f m∥ ≤ C * ∏ i, ∥m i∥`, for some `C` which can be chosen to be
positive. -/
theorem exists_bound_of_continuous (hf : continuous f) :
∃ (C : ℝ), 0 < C ∧ (∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) :=
begin
/- The proof only uses the continuity at `0`. Then, given a general point `m`, rescale each of
its coordinates to bring them to a shell of fixed width around `0`, on which one knows that `f` is
bounded, and then use the multiplicativity of `f` along each coordinate to deduce the desired
bound.-/
obtain ⟨ε, ε_pos, hε⟩ : ∃ ε > 0, ∀{m}, dist m 0 < ε → dist (f m) (f 0) < 1 :=
metric.tendsto_nhds_nhds.1 hf.continuous_at 1 zero_lt_one,
let δ := ε/2,
have δ_pos : δ > 0 := half_pos ε_pos,
/- On points of size at most `δ`, `f` is bounded (by `1 + ∥f 0∥`). -/
have H : ∀{a}, ∥a∥ ≤ δ → ∥f a∥ ≤ 1 + ∥f 0∥,
{ assume a ha,
have : dist (f a) (f 0) ≤ 1,
{ apply le_of_lt (hε _),
rw [dist_eq_norm, sub_zero],
exact lt_of_le_of_lt ha (half_lt_self ε_pos) },
calc ∥f a∥ = dist (f a) 0 : (dist_zero_right _).symm
... ≤ dist (f a) (f 0) + dist (f 0) 0 : dist_triangle _ _ _
... ≤ 1 + ∥f 0∥ : by { rw dist_zero_right, exact add_le_add_right this _ } },
obtain ⟨c, hc⟩ : ∃c : 𝕜, 1 < ∥c∥ := normed_field.exists_one_lt_norm 𝕜,
set C := (1 + ∥f 0∥) * ∏ i : ι, (δ⁻¹ * ∥c∥),
have C_pos : 0 < C :=
mul_pos (lt_of_lt_of_le zero_lt_one (by simp))
(prod_pos (λi hi, mul_pos (inv_pos.2 δ_pos) (lt_of_le_of_lt zero_le_one hc))),
refine ⟨C, C_pos, λm, _⟩,
/- Given a general point `m`, rescale each coordinate to bring it to `[δ/∥c∥, δ]` by multiplication
by a power of a scalar `c` with norm `∥c∥ > 1`.-/
by_cases h : ∃i, m i = 0,
{ rcases h with ⟨i, hi⟩,
rw [f.map_coord_zero i hi, norm_zero],
exact mul_nonneg (le_of_lt C_pos) (prod_nonneg (λi hi, norm_nonneg _)) },
{ push_neg at h,
have : ∀i, ∃d:𝕜, d ≠ 0 ∧ ∥d • m i∥ ≤ δ ∧ (δ/∥c∥ ≤ ∥d • m i∥) ∧ (∥d∥⁻¹ ≤ δ⁻¹ * ∥c∥ * ∥m i∥) :=
λi, rescale_to_shell hc δ_pos (h i),
choose d hd using this,
have A : 0 ≤ 1 + ∥f 0∥ := add_nonneg zero_le_one (norm_nonneg _),
have B : ∀ (i : ι), i ∈ univ → 0 ≤ ∥d i∥⁻¹ := λi hi, by simp,
-- use the bound on `f` on the ball of size `δ` to conclude.
calc
∥f m∥ = ∥f (λi, (d i)⁻¹ • (d i • m i))∥ :
by { unfold_coes, congr' with i, rw [← mul_smul, inv_mul_cancel (hd i).1, one_smul] }
... = ∥(∏ i, (d i)⁻¹) • f (λi, d i • m i)∥ : by rw f.map_smul_univ
... = (∏ i, ∥d i∥⁻¹) * ∥f (λi, d i • m i)∥ :
by { rw [norm_smul, normed_field.norm_prod], congr' with i, rw normed_field.norm_inv }
... ≤ (∏ i, ∥d i∥⁻¹) * (1 + ∥f 0∥) :
mul_le_mul_of_nonneg_left (H ((pi_norm_le_iff (le_of_lt δ_pos)).2 (λi, (hd i).2.1)))
(prod_nonneg B)
... ≤ (∏ i, δ⁻¹ * ∥c∥ * ∥m i∥) * (1 + ∥f 0∥) :
mul_le_mul_of_nonneg_right (prod_le_prod B (λi hi, (hd i).2.2.2)) A
... = (∏ i : ι, δ⁻¹ * ∥c∥) * (∏ i, ∥m i∥) * (1 + ∥f 0∥) :
by rw prod_mul_distrib
... = C * (∏ i, ∥m i∥) :
by rw [mul_comm, ← mul_assoc] }
end
/-- If `f` satisfies a boundedness property around `0`, one can deduce a bound on `f m₁ - f m₂`
using the multilinearity. Here, we give a precise but hard to use version. See
`norm_image_sub_le_of_bound` for a less precise but more usable version. The bound reads
`∥f m - f m'∥ ≤ C * ∥m 1 - m' 1∥ * max ∥m 2∥ ∥m' 2∥ * max ∥m 3∥ ∥m' 3∥ * ... * max ∥m n∥ ∥m' n∥ + ...`,
where the other terms in the sum are the same products where `1` is replaced by any `i`. -/
lemma norm_image_sub_le_of_bound' {C : ℝ} (hC : 0 ≤ C)
(H : ∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) (m₁ m₂ : Πi, E₁ i) :
∥f m₁ - f m₂∥ ≤
C * ∑ i, ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥ :=
begin
have A : ∀(s : finset ι), ∥f m₁ - f (s.piecewise m₂ m₁)∥
≤ C * ∑ i in s, ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥,
{ refine finset.induction (by simp) _,
assume i s his Hrec,
have I : ∥f (s.piecewise m₂ m₁) - f ((insert i s).piecewise m₂ m₁)∥
≤ C * ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥,
{ have A : ((insert i s).piecewise m₂ m₁)
= function.update (s.piecewise m₂ m₁) i (m₂ i) := s.piecewise_insert _ _ _,
have B : s.piecewise m₂ m₁ = function.update (s.piecewise m₂ m₁) i (m₁ i),
{ ext j,
by_cases h : j = i,
{ rw h, simp [his] },
{ simp [h] } },
rw [B, A, ← f.map_sub],
apply le_trans (H _) (mul_le_mul_of_nonneg_left _ hC),
refine prod_le_prod (λj hj, norm_nonneg _) (λj hj, _),
by_cases h : j = i,
{ rw h, simp },
{ by_cases h' : j ∈ s;
simp [h', h, le_refl] } },
calc ∥f m₁ - f ((insert i s).piecewise m₂ m₁)∥ ≤
∥f m₁ - f (s.piecewise m₂ m₁)∥ + ∥f (s.piecewise m₂ m₁) - f ((insert i s).piecewise m₂ m₁)∥ :
by { rw [← dist_eq_norm, ← dist_eq_norm, ← dist_eq_norm], exact dist_triangle _ _ _ }
... ≤ (C * ∑ i in s, ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥)
+ C * ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥ :
add_le_add Hrec I
... = C * ∑ i in insert i s, ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥ :
by simp [his, add_comm, left_distrib] },
convert A univ,
simp
end
/-- If `f` satisfies a boundedness property around `0`, one can deduce a bound on `f m₁ - f m₂`
using the multilinearity. Here, we give a usable but not very precise version. See
`norm_image_sub_le_of_bound'` for a more precise but less usable version. The bound is
`∥f m - f m'∥ ≤ C * card ι * ∥m - m'∥ * (max ∥m∥ ∥m'∥) ^ (card ι - 1)`. -/
lemma norm_image_sub_le_of_bound {C : ℝ} (hC : 0 ≤ C)
(H : ∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) (m₁ m₂ : Πi, E₁ i) :
∥f m₁ - f m₂∥ ≤ C * (fintype.card ι) * (max ∥m₁∥ ∥m₂∥) ^ (fintype.card ι - 1) * ∥m₁ - m₂∥ :=
begin
have A : ∀ (i : ι), ∏ j, (if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥)
≤ ∥m₁ - m₂∥ * (max ∥m₁∥ ∥m₂∥) ^ (fintype.card ι - 1),
{ assume i,
calc ∏ j, (if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥)
≤ ∏ j : ι, function.update (λ j, max ∥m₁∥ ∥m₂∥) i (∥m₁ - m₂∥) j :
begin
apply prod_le_prod,
{ assume j hj, by_cases h : j = i; simp [h, norm_nonneg] },
{ assume j hj,
by_cases h : j = i,
{ rw h, simp, exact norm_le_pi_norm (m₁ - m₂) i },
{ simp [h, max_le_max, norm_le_pi_norm] } }
end
... = ∥m₁ - m₂∥ * (max ∥m₁∥ ∥m₂∥) ^ (fintype.card ι - 1) :
by { rw prod_update_of_mem (finset.mem_univ _), simp [card_univ_diff] } },
calc
∥f m₁ - f m₂∥
≤ C * ∑ i, ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥ :
f.norm_image_sub_le_of_bound' hC H m₁ m₂
... ≤ C * ∑ i, ∥m₁ - m₂∥ * (max ∥m₁∥ ∥m₂∥) ^ (fintype.card ι - 1) :
mul_le_mul_of_nonneg_left (sum_le_sum (λi hi, A i)) hC
... = C * (fintype.card ι) * (max ∥m₁∥ ∥m₂∥) ^ (fintype.card ι - 1) * ∥m₁ - m₂∥ :
by { rw [sum_const, card_univ, nsmul_eq_mul], ring }
end
/-- If a multilinear map satisfies an inequality `∥f m∥ ≤ C * ∏ i, ∥m i∥`, then it is
continuous. -/
theorem continuous_of_bound (C : ℝ) (H : ∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) :
continuous f :=
begin
let D := max C 1,
have D_pos : 0 ≤ D := le_trans zero_le_one (le_max_right _ _),
replace H : ∀ m, ∥f m∥ ≤ D * ∏ i, ∥m i∥,
{ assume m,
apply le_trans (H m) (mul_le_mul_of_nonneg_right (le_max_left _ _) _),
exact prod_nonneg (λ(i : ι) hi, norm_nonneg (m i)) },
refine continuous_iff_continuous_at.2 (λm, _),
refine continuous_at_of_locally_lipschitz zero_lt_one
(D * (fintype.card ι) * (∥m∥ + 1) ^ (fintype.card ι - 1)) (λm' h', _),
rw [dist_eq_norm, dist_eq_norm],
have : 0 ≤ (max ∥m'∥ ∥m∥), by simp,
have : (max ∥m'∥ ∥m∥) ≤ ∥m∥ + 1,
by simp [zero_le_one, norm_le_of_mem_closed_ball (le_of_lt h'), -add_comm],
calc
∥f m' - f m∥
≤ D * (fintype.card ι) * (max ∥m'∥ ∥m∥) ^ (fintype.card ι - 1) * ∥m' - m∥ :
f.norm_image_sub_le_of_bound D_pos H m' m
... ≤ D * (fintype.card ι) * (∥m∥ + 1) ^ (fintype.card ι - 1) * ∥m' - m∥ :
by apply_rules [mul_le_mul_of_nonneg_right, mul_le_mul_of_nonneg_left, mul_nonneg,
norm_nonneg, nat.cast_nonneg, pow_le_pow_of_le_left]
end
/-- Constructing a continuous multilinear map from a multilinear map satisfying a boundedness
condition. -/
def mk_continuous (C : ℝ) (H : ∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) :
continuous_multilinear_map 𝕜 E₁ E₂ :=
{ cont := f.continuous_of_bound C H, ..f }
/-- Given a multilinear map in `n` variables, if one restricts it to `k` variables putting `z` on
the other coordinates, then the resulting restricted function satisfies an inequality
`∥f.restr v∥ ≤ C * ∥z∥^(n-k) * Π ∥v i∥` if the original function satisfies `∥f v∥ ≤ C * Π ∥v i∥`. -/
lemma restr_norm_le {k n : ℕ} (f : (multilinear_map 𝕜 (λ i : fin n, G) E₂ : _))
(s : finset (fin n)) (hk : s.card = k) (z : G) {C : ℝ}
(H : ∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) (v : fin k → G) :
∥f.restr s hk z v∥ ≤ C * ∥z∥ ^ (n - k) * ∏ i, ∥v i∥ :=
begin
rw mul_assoc,
convert H _ using 2,
simp only [apply_dite norm, fintype.prod_dite, prod_const (∥z∥), finset.card_univ,
fintype.card_of_subtype sᶜ (λ x, mem_compl), card_compl, fintype.card_fin, hk, mk_coe,
(s.mono_equiv_of_fin hk).symm.prod_comp (λ x, ∥v x∥)],
apply mul_comm
end
end multilinear_map
/-!
### Continuous multilinear maps
We define the norm `∥f∥` of a continuous multilinear map `f` in finitely many variables as the
smallest number such that `∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥` for all `m`. We show that this
defines a normed space structure on `continuous_multilinear_map 𝕜 E₁ E₂`.
-/
namespace continuous_multilinear_map
variables (c : 𝕜) (f g : continuous_multilinear_map 𝕜 E₁ E₂) (m : Πi, E₁ i)
theorem bound : ∃ (C : ℝ), 0 < C ∧ (∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) :=
f.to_multilinear_map.exists_bound_of_continuous f.2
open real
/-- The operator norm of a continuous multilinear map is the inf of all its bounds. -/
def op_norm := Inf {c | 0 ≤ (c : ℝ) ∧ ∀ m, ∥f m∥ ≤ c * ∏ i, ∥m i∥}
instance has_op_norm : has_norm (continuous_multilinear_map 𝕜 E₁ E₂) := ⟨op_norm⟩
lemma norm_def : ∥f∥ = Inf {c | 0 ≤ (c : ℝ) ∧ ∀ m, ∥f m∥ ≤ c * ∏ i, ∥m i∥} := rfl
-- So that invocations of `real.Inf_le` make sense: we show that the set of
-- bounds is nonempty and bounded below.
lemma bounds_nonempty {f : continuous_multilinear_map 𝕜 E₁ E₂} :
∃ c, c ∈ {c | 0 ≤ c ∧ ∀ m, ∥f m∥ ≤ c * ∏ i, ∥m i∥} :=
let ⟨M, hMp, hMb⟩ := f.bound in ⟨M, le_of_lt hMp, hMb⟩
lemma bounds_bdd_below {f : continuous_multilinear_map 𝕜 E₁ E₂} :
bdd_below {c | 0 ≤ c ∧ ∀ m, ∥f m∥ ≤ c * ∏ i, ∥m i∥} :=
⟨0, λ _ ⟨hn, _⟩, hn⟩
lemma op_norm_nonneg : 0 ≤ ∥f∥ :=
lb_le_Inf _ bounds_nonempty (λ _ ⟨hx, _⟩, hx)
/-- The fundamental property of the operator norm of a continuous multilinear map:
`∥f m∥` is bounded by `∥f∥` times the product of the `∥m i∥`. -/
theorem le_op_norm : ∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥ :=
begin
have A : 0 ≤ ∏ i, ∥m i∥ := prod_nonneg (λj hj, norm_nonneg _),
by_cases h : ∏ i, ∥m i∥ = 0,
{ rcases prod_eq_zero_iff.1 h with ⟨i, _, hi⟩,
rw norm_eq_zero at hi,
have : f m = 0 := f.map_coord_zero i hi,
rw [this, norm_zero],
exact mul_nonneg (op_norm_nonneg f) A },
{ have hlt : 0 < ∏ i, ∥m i∥ := lt_of_le_of_ne A (ne.symm h),
rw [← div_le_iff hlt],
apply (le_Inf _ bounds_nonempty bounds_bdd_below).2,
rintro c ⟨_, hc⟩, rw [div_le_iff hlt], apply hc }
end
lemma ratio_le_op_norm : ∥f m∥ / ∏ i, ∥m i∥ ≤ ∥f∥ :=
begin
have : 0 ≤ ∏ i, ∥m i∥ := prod_nonneg (λj hj, norm_nonneg _),
cases eq_or_lt_of_le this with h h,
{ simp [h.symm, op_norm_nonneg f] },
{ rw div_le_iff h,
exact le_op_norm f m }
end
/-- The image of the unit ball under a continuous multilinear map is bounded. -/
lemma unit_le_op_norm (h : ∥m∥ ≤ 1) : ∥f m∥ ≤ ∥f∥ :=
calc
∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥ : f.le_op_norm m
... ≤ ∥f∥ * ∏ i : ι, 1 :
mul_le_mul_of_nonneg_left (prod_le_prod (λi hi, norm_nonneg _) (λi hi, le_trans (norm_le_pi_norm _ _) h))
(op_norm_nonneg f)
... = ∥f∥ : by simp
/-- If one controls the norm of every `f x`, then one controls the norm of `f`. -/
lemma op_norm_le_bound {M : ℝ} (hMp: 0 ≤ M) (hM : ∀ m, ∥f m∥ ≤ M * ∏ i, ∥m i∥) :
∥f∥ ≤ M :=
Inf_le _ bounds_bdd_below ⟨hMp, hM⟩
/-- The operator norm satisfies the triangle inequality. -/
theorem op_norm_add_le : ∥f + g∥ ≤ ∥f∥ + ∥g∥ :=
Inf_le _ bounds_bdd_below
⟨add_nonneg (op_norm_nonneg _) (op_norm_nonneg _), λ x, by { rw add_mul,
exact norm_add_le_of_le (le_op_norm _ _) (le_op_norm _ _) }⟩
/-- A continuous linear map is zero iff its norm vanishes. -/
theorem op_norm_zero_iff : ∥f∥ = 0 ↔ f = 0 :=
begin
split,
{ assume h,
ext m,
simpa [h, norm_le_zero_iff.symm] using f.le_op_norm m },
{ assume h,
apply le_antisymm (op_norm_le_bound f (le_refl _) (λm, _)) (op_norm_nonneg _),
rw h,
simp }
end
lemma op_norm_smul_le : ∥c • f∥ ≤ ∥c∥ * ∥f∥ :=
(Inf_le _ bounds_bdd_below
⟨mul_nonneg (norm_nonneg _) (op_norm_nonneg _), λ _,
begin
erw [norm_smul, mul_assoc],
exact mul_le_mul_of_nonneg_left (le_op_norm _ _) (norm_nonneg _)
end⟩)
lemma op_norm_neg : ∥-f∥ = ∥f∥ := by { rw norm_def, apply congr_arg, ext, simp }
/-- Continuous multilinear maps themselves form a normed space with respect to
the operator norm. -/
instance to_normed_group : normed_group (continuous_multilinear_map 𝕜 E₁ E₂) :=
normed_group.of_core _ ⟨op_norm_zero_iff, op_norm_add_le, op_norm_neg⟩
instance to_normed_space : normed_space 𝕜 (continuous_multilinear_map 𝕜 E₁ E₂) :=
⟨op_norm_smul_le⟩
/-- The difference `f m₁ - f m₂` is controlled in terms of `∥f∥` and `∥m₁ - m₂∥`, precise version.
For a less precise but more usable version, see `norm_image_sub_le_of_bound`. The bound reads
`∥f m - f m'∥ ≤ ∥f∥ * ∥m 1 - m' 1∥ * max ∥m 2∥ ∥m' 2∥ * max ∥m 3∥ ∥m' 3∥ * ... * max ∥m n∥ ∥m' n∥ + ...`,
where the other terms in the sum are the same products where `1` is replaced by any `i`.-/
lemma norm_image_sub_le_of_bound' (m₁ m₂ : Πi, E₁ i) :
∥f m₁ - f m₂∥ ≤
∥f∥ * ∑ i, ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥ :=
f.to_multilinear_map.norm_image_sub_le_of_bound' (norm_nonneg _) f.le_op_norm _ _
/-- The difference `f m₁ - f m₂` is controlled in terms of `∥f∥` and `∥m₁ - m₂∥`, less precise
version. For a more precise but less usable version, see `norm_image_sub_le_of_bound'`.
The bound is `∥f m - f m'∥ ≤ ∥f∥ * card ι * ∥m - m'∥ * (max ∥m∥ ∥m'∥) ^ (card ι - 1)`.-/
lemma norm_image_sub_le_of_bound (m₁ m₂ : Πi, E₁ i) :
∥f m₁ - f m₂∥ ≤ ∥f∥ * (fintype.card ι) * (max ∥m₁∥ ∥m₂∥) ^ (fintype.card ι - 1) * ∥m₁ - m₂∥ :=
f.to_multilinear_map.norm_image_sub_le_of_bound (norm_nonneg _) f.le_op_norm _ _
/-- Applying a multilinear map to a vector is continuous in both coordinates. -/
lemma continuous_eval :
continuous (λ (p : (continuous_multilinear_map 𝕜 E₁ E₂ × (Πi, E₁ i))), p.1 p.2) :=
begin
apply continuous_iff_continuous_at.2 (λp, _),
apply continuous_at_of_locally_lipschitz zero_lt_one
((∥p∥ + 1) * (fintype.card ι) * (∥p∥ + 1) ^ (fintype.card ι - 1) + ∏ i, ∥p.2 i∥)
(λq hq, _),
have : 0 ≤ (max ∥q.2∥ ∥p.2∥), by simp,
have : 0 ≤ ∥p∥ + 1, by simp [le_trans zero_le_one],
have A : ∥q∥ ≤ ∥p∥ + 1 := norm_le_of_mem_closed_ball (le_of_lt hq),
have : (max ∥q.2∥ ∥p.2∥) ≤ ∥p∥ + 1 :=
le_trans (max_le_max (norm_snd_le q) (norm_snd_le p)) (by simp [A, -add_comm, zero_le_one]),
have : ∀ (i : ι), i ∈ univ → 0 ≤ ∥p.2 i∥ := λ i hi, norm_nonneg _,
calc dist (q.1 q.2) (p.1 p.2)
≤ dist (q.1 q.2) (q.1 p.2) + dist (q.1 p.2) (p.1 p.2) : dist_triangle _ _ _
... = ∥q.1 q.2 - q.1 p.2∥ + ∥q.1 p.2 - p.1 p.2∥ : by rw [dist_eq_norm, dist_eq_norm]
... ≤ ∥q.1∥ * (fintype.card ι) * (max ∥q.2∥ ∥p.2∥) ^ (fintype.card ι - 1) * ∥q.2 - p.2∥
+ ∥q.1 - p.1∥ * ∏ i, ∥p.2 i∥ :
add_le_add (norm_image_sub_le_of_bound _ _ _) ((q.1 - p.1).le_op_norm p.2)
... ≤ (∥p∥ + 1) * (fintype.card ι) * (∥p∥ + 1) ^ (fintype.card ι - 1) * ∥q - p∥
+ ∥q - p∥ * ∏ i, ∥p.2 i∥ :
by apply_rules [add_le_add, mul_le_mul, le_refl, le_trans (norm_fst_le q) A, nat.cast_nonneg,
mul_nonneg, pow_le_pow_of_le_left, pow_nonneg, norm_snd_le (q - p), norm_nonneg,
norm_fst_le (q - p), prod_nonneg]
... = ((∥p∥ + 1) * (fintype.card ι) * (∥p∥ + 1) ^ (fintype.card ι - 1)
+ (∏ i, ∥p.2 i∥)) * dist q p : by { rw dist_eq_norm, ring }
end
lemma continuous_eval_left (m : Π i, E₁ i) :
continuous (λ (p : (continuous_multilinear_map 𝕜 E₁ E₂)), (p : (Π i, E₁ i) → E₂) m) :=
continuous_eval.comp (continuous.prod_mk continuous_id continuous_const)
lemma has_sum_eval
{α : Type*} {p : α → continuous_multilinear_map 𝕜 E₁ E₂} {q : continuous_multilinear_map 𝕜 E₁ E₂}
(h : has_sum p q) (m : Π i, E₁ i) : has_sum (λ a, p a m) (q m) :=
begin
dsimp [has_sum] at h ⊢,
convert ((continuous_eval_left m).tendsto _).comp h,
ext s,
simp
end
open_locale topological_space
open filter
/-- If the target space is complete, the space of continuous multilinear maps with its norm is also
complete. The proof is essentially the same as for the space of continuous linear maps (modulo the
addition of `finset.prod` where needed. The duplication could be avoided by deducing the linear
case from the multilinear case via a currying isomorphism. However, this would mess up imports,
and it is more satisfactory to have the simplest case as a standalone proof. -/
instance [complete_space E₂] : complete_space (continuous_multilinear_map 𝕜 E₁ E₂) :=
begin
have nonneg : ∀ (v : Π i, E₁ i), 0 ≤ ∏ i, ∥v i∥ :=
λ v, finset.prod_nonneg (λ i hi, norm_nonneg _),
-- We show that every Cauchy sequence converges.
refine metric.complete_of_cauchy_seq_tendsto (λ f hf, _),
-- We now expand out the definition of a Cauchy sequence,
rcases cauchy_seq_iff_le_tendsto_0.1 hf with ⟨b, b0, b_bound, b_lim⟩,
-- and establish that the evaluation at any point `v : Π i, E₁ i` is Cauchy.
have cau : ∀ v, cauchy_seq (λ n, f n v),
{ assume v,
apply cauchy_seq_iff_le_tendsto_0.2 ⟨λ n, b n * ∏ i, ∥v i∥, λ n, _, _, _⟩,
{ exact mul_nonneg (b0 n) (nonneg v) },
{ assume n m N hn hm,
rw dist_eq_norm,
apply le_trans ((f n - f m).le_op_norm v) _,
exact mul_le_mul_of_nonneg_right (b_bound n m N hn hm) (nonneg v) },
{ simpa using b_lim.mul tendsto_const_nhds } },
-- We assemble the limits points of those Cauchy sequences
-- (which exist as `E₂` is complete)
-- into a function which we call `F`.
choose F hF using λv, cauchy_seq_tendsto_of_complete (cau v),
-- Next, we show that this `F` is multilinear,
let Fmult : multilinear_map 𝕜 E₁ E₂ :=
{ to_fun := F,
map_add' := λ v i x y, begin
have A := hF (function.update v i (x + y)),
have B := (hF (function.update v i x)).add (hF (function.update v i y)),
simp at A B,
exact tendsto_nhds_unique A B
end,
map_smul' := λ v i c x, begin
have A := hF (function.update v i (c • x)),
have B := filter.tendsto.smul (@tendsto_const_nhds _ ℕ _ c _) (hF (function.update v i x)),
simp at A B,
exact tendsto_nhds_unique A B
end },
-- and that `F` has norm at most `(b 0 + ∥f 0∥)`.
have Fnorm : ∀ v, ∥F v∥ ≤ (b 0 + ∥f 0∥) * ∏ i, ∥v i∥,
{ assume v,
have A : ∀ n, ∥f n v∥ ≤ (b 0 + ∥f 0∥) * ∏ i, ∥v i∥,
{ assume n,
apply le_trans ((f n).le_op_norm _) _,
apply mul_le_mul_of_nonneg_right _ (nonneg v),
calc ∥f n∥ = ∥(f n - f 0) + f 0∥ : by { congr' 1, abel }
... ≤ ∥f n - f 0∥ + ∥f 0∥ : norm_add_le _ _
... ≤ b 0 + ∥f 0∥ : begin
apply add_le_add_right,
simpa [dist_eq_norm] using b_bound n 0 0 (zero_le _) (zero_le _)
end },
exact le_of_tendsto (hF v).norm (eventually_of_forall A) },
-- Thus `F` is continuous, and we propose that as the limit point of our original Cauchy sequence.
let Fcont := Fmult.mk_continuous _ Fnorm,
use Fcont,
-- Our last task is to establish convergence to `F` in norm.
have : ∀ n, ∥f n - Fcont∥ ≤ b n,
{ assume n,
apply op_norm_le_bound _ (b0 n) (λ v, _),
have A : ∀ᶠ m in at_top, ∥(f n - f m) v∥ ≤ b n * ∏ i, ∥v i∥,
{ refine eventually_at_top.2 ⟨n, λ m hm, _⟩,
apply le_trans ((f n - f m).le_op_norm _) _,
exact mul_le_mul_of_nonneg_right (b_bound n m n (le_refl _) hm) (nonneg v) },
have B : tendsto (λ m, ∥(f n - f m) v∥) at_top (𝓝 (∥(f n - Fcont) v∥)) :=
tendsto.norm (tendsto_const_nhds.sub (hF v)),
exact le_of_tendsto B A },
erw tendsto_iff_norm_tendsto_zero,
exact squeeze_zero (λ n, norm_nonneg _) this b_lim,
end
end continuous_multilinear_map
/-- If a continuous multilinear map is constructed from a multilinear map via the constructor
`mk_continuous`, then its norm is bounded by the bound given to the constructor if it is
nonnegative. -/
lemma multilinear_map.mk_continuous_norm_le (f : multilinear_map 𝕜 E₁ E₂) {C : ℝ} (hC : 0 ≤ C)
(H : ∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) : ∥f.mk_continuous C H∥ ≤ C :=
continuous_multilinear_map.op_norm_le_bound _ hC (λm, H m)
namespace continuous_multilinear_map
/-- Given a continuous multilinear map `f` on `n` variables (parameterized by `fin n`) and a subset
`s` of `k` of these variables, one gets a new continuous multilinear map on `fin k` by varying
these variables, and fixing the other ones equal to a given value `z`. It is denoted by
`f.restr s hk z`, where `hk` is a proof that the cardinality of `s` is `k`. The implicit
identification between `fin k` and `s` that we use is the canonical (increasing) bijection. -/
def restr {k n : ℕ} (f : (G [×n]→L[𝕜] E₂ : _))
(s : finset (fin n)) (hk : s.card = k) (z : G) : G [×k]→L[𝕜] E₂ :=
(f.to_multilinear_map.restr s hk z).mk_continuous
(∥f∥ * ∥z∥^(n-k)) $ λ v, multilinear_map.restr_norm_le _ _ _ _ f.le_op_norm _
lemma norm_restr {k n : ℕ} (f : G [×n]→L[𝕜] E₂) (s : finset (fin n)) (hk : s.card = k) (z : G) :
∥f.restr s hk z∥ ≤ ∥f∥ * ∥z∥ ^ (n - k) :=
begin
apply multilinear_map.mk_continuous_norm_le,
exact mul_nonneg (norm_nonneg _) (pow_nonneg (norm_nonneg _) _)
end
variables (𝕜 ι)
/-- The canonical continuous multilinear map on `𝕜^ι`, associating to `m` the product of all the
`m i` (multiplied by a fixed reference element `z` in the target module) -/
protected def mk_pi_field (z : E₂) : continuous_multilinear_map 𝕜 (λ(i : ι), 𝕜) E₂ :=
@multilinear_map.mk_continuous 𝕜 ι (λ(i : ι), 𝕜) E₂ _ _ _ _ _ _ _
(multilinear_map.mk_pi_ring 𝕜 ι z) (∥z∥)
(λ m, by simp only [multilinear_map.mk_pi_ring_apply, norm_smul, normed_field.norm_prod, mul_comm])
variables {𝕜 ι}
@[simp] lemma mk_pi_field_apply (z : E₂) (m : ι → 𝕜) :
(continuous_multilinear_map.mk_pi_field 𝕜 ι z : (ι → 𝕜) → E₂) m = (∏ i, m i) • z := rfl
lemma mk_pi_ring_apply_one_eq_self (f : continuous_multilinear_map 𝕜 (λ(i : ι), 𝕜) E₂) :
continuous_multilinear_map.mk_pi_field 𝕜 ι (f (λi, 1)) = f :=
begin
ext m,
have : m = (λi, m i • 1), by { ext j, simp },
conv_rhs { rw [this, f.map_smul_univ] },
refl
end
variables (𝕜 ι E₂)
/-- Continuous multilinear maps on `𝕜^n` with values in `E₂` are in bijection with `E₂`, as such a
continuous multilinear map is completely determined by its value on the constant vector made of
ones. We register this bijection as a linear equivalence in
`continuous_multilinear_map.pi_field_equiv_aux`. The continuous linear equivalence is
`continuous_multilinear_map.pi_field_equiv`. -/
protected def pi_field_equiv_aux : E₂ ≃ₗ[𝕜] (continuous_multilinear_map 𝕜 (λ(i : ι), 𝕜) E₂) :=
{ to_fun := λ z, continuous_multilinear_map.mk_pi_field 𝕜 ι z,
inv_fun := λ f, f (λi, 1),
map_add' := λ z z', by { ext m, simp [smul_add] },
map_smul' := λ c z, by { ext m, simp [smul_smul, mul_comm] },
left_inv := λ z, by simp,
right_inv := λ f, f.mk_pi_ring_apply_one_eq_self }
/-- Continuous multilinear maps on `𝕜^n` with values in `E₂` are in bijection with `E₂`, as such a
continuous multilinear map is completely determined by its value on the constant vector made of
ones. We register this bijection as a continuous linear equivalence in
`continuous_multilinear_map.pi_field_equiv`. -/
protected def pi_field_equiv : E₂ ≃L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : ι), 𝕜) E₂) :=
{ continuous_to_fun := begin
refine (continuous_multilinear_map.pi_field_equiv_aux 𝕜 ι E₂).to_linear_map.continuous_of_bound
(1 : ℝ) (λz, _),
rw one_mul,
change ∥continuous_multilinear_map.mk_pi_field 𝕜 ι z∥ ≤ ∥z∥,
exact multilinear_map.mk_continuous_norm_le _ (norm_nonneg _) _
end,
continuous_inv_fun := begin
refine (continuous_multilinear_map.pi_field_equiv_aux 𝕜 ι E₂).symm.to_linear_map.continuous_of_bound
(1 : ℝ) (λf, _),
rw one_mul,
change ∥f (λi, 1)∥ ≤ ∥f∥,
apply @continuous_multilinear_map.unit_le_op_norm 𝕜 ι (λ (i : ι), 𝕜) E₂ _ _ _ _ _ _ _ f,
simp [pi_norm_le_iff zero_le_one, le_refl]
end,
.. continuous_multilinear_map.pi_field_equiv_aux 𝕜 ι E₂ }
end continuous_multilinear_map
section currying
/-!
### Currying
We associate to a continuous multilinear map in `n+1` variables (i.e., based on `fin n.succ`) two
curried functions, named `f.curry_left` (which is a continuous linear map on `E 0` taking values
in continuous multilinear maps in `n` variables) and `f.curry_right` (which is a continuous
multilinear map in `n` variables taking values in continuous linear maps on `E (last n)`).
The inverse operations are called `uncurry_left` and `uncurry_right`.
We also register continuous linear equiv versions of these correspondences, in
`continuous_multilinear_curry_left_equiv` and `continuous_multilinear_curry_right_equiv`.
-/
open fin function
lemma continuous_linear_map.norm_map_tail_le
(f : E 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.succ) E₂)) (m : Πi, E i) :
∥f (m 0) (tail m)∥ ≤ ∥f∥ * ∏ i, ∥m i∥ :=
calc
∥f (m 0) (tail m)∥ ≤ ∥f (m 0)∥ * ∏ i, ∥(tail m) i∥ : (f (m 0)).le_op_norm _
... ≤ (∥f∥ * ∥m 0∥) * ∏ i, ∥(tail m) i∥ :
mul_le_mul_of_nonneg_right (f.le_op_norm _) (prod_nonneg (λi hi, norm_nonneg _))
... = ∥f∥ * (∥m 0∥ * ∏ i, ∥(tail m) i∥) : by ring
... = ∥f∥ * ∏ i, ∥m i∥ : by { rw prod_univ_succ, refl }
lemma continuous_multilinear_map.norm_map_init_le
(f : continuous_multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →L[𝕜] E₂)) (m : Πi, E i) :
∥f (init m) (m (last n))∥ ≤ ∥f∥ * ∏ i, ∥m i∥ :=
calc
∥f (init m) (m (last n))∥ ≤ ∥f (init m)∥ * ∥m (last n)∥ : (f (init m)).le_op_norm _
... ≤ (∥f∥ * (∏ i, ∥(init m) i∥)) * ∥m (last n)∥ :
mul_le_mul_of_nonneg_right (f.le_op_norm _) (norm_nonneg _)
... = ∥f∥ * ((∏ i, ∥(init m) i∥) * ∥m (last n)∥) : mul_assoc _ _ _
... = ∥f∥ * ∏ i, ∥m i∥ : by { rw prod_univ_cast_succ, refl }
lemma continuous_multilinear_map.norm_map_cons_le
(f : continuous_multilinear_map 𝕜 E E₂) (x : E 0) (m : Π(i : fin n), E i.succ) :
∥f (cons x m)∥ ≤ ∥f∥ * ∥x∥ * ∏ i, ∥m i∥ :=
calc
∥f (cons x m)∥ ≤ ∥f∥ * ∏ i, ∥cons x m i∥ : f.le_op_norm _
... = (∥f∥ * ∥x∥) * ∏ i, ∥m i∥ : by { rw prod_univ_succ, simp [mul_assoc] }
lemma continuous_multilinear_map.norm_map_snoc_le
(f : continuous_multilinear_map 𝕜 E E₂) (m : Π(i : fin n), E i.cast_succ) (x : E (last n)) :
∥f (snoc m x)∥ ≤ ∥f∥ * (∏ i, ∥m i∥) * ∥x∥ :=
calc
∥f (snoc m x)∥ ≤ ∥f∥ * ∏ i, ∥snoc m x i∥ : f.le_op_norm _
... = ∥f∥ * (∏ i, ∥m i∥) * ∥x∥ : by { rw prod_univ_cast_succ, simp [mul_assoc] }
/-! #### Left currying -/
/-- Given a continuous linear map `f` from `E 0` to continuous multilinear maps on `n` variables,
construct the corresponding continuous multilinear map on `n+1` variables obtained by concatenating
the variables, given by `m ↦ f (m 0) (tail m)`-/
def continuous_linear_map.uncurry_left
(f : E 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.succ) E₂)) :
continuous_multilinear_map 𝕜 E E₂ :=
(@linear_map.uncurry_left 𝕜 n E E₂ _ _ _ _ _
(continuous_multilinear_map.to_multilinear_map_linear.comp f.to_linear_map)).mk_continuous
(∥f∥) (λm, continuous_linear_map.norm_map_tail_le f m)
@[simp] lemma continuous_linear_map.uncurry_left_apply
(f : E 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.succ) E₂)) (m : Πi, E i) :
f.uncurry_left m = f (m 0) (tail m) := rfl
/-- Given a continuous multilinear map `f` in `n+1` variables, split the first variable to obtain
a continuous linear map into continuous multilinear maps in `n` variables, given by
`x ↦ (m ↦ f (cons x m))`. -/
def continuous_multilinear_map.curry_left
(f : continuous_multilinear_map 𝕜 E E₂) :
E 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.succ) E₂) :=
linear_map.mk_continuous
{ -- define a linear map into `n` continuous multilinear maps from an `n+1` continuous multilinear
-- map
to_fun := λx, (f.to_multilinear_map.curry_left x).mk_continuous
(∥f∥ * ∥x∥) (f.norm_map_cons_le x),
map_add' := λx y, by { ext m, exact f.cons_add m x y },
map_smul' := λc x, by { ext m, exact f.cons_smul m c x } }
-- then register its continuity thanks to its boundedness properties.
(∥f∥) (λx, multilinear_map.mk_continuous_norm_le _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) _)
@[simp] lemma continuous_multilinear_map.curry_left_apply
(f : continuous_multilinear_map 𝕜 E E₂) (x : E 0) (m : Π(i : fin n), E i.succ) :
f.curry_left x m = f (cons x m) := rfl
@[simp] lemma continuous_linear_map.curry_uncurry_left
(f : E 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.succ) E₂)) :
f.uncurry_left.curry_left = f :=
begin
ext m x,
simp only [tail_cons, continuous_linear_map.uncurry_left_apply,
continuous_multilinear_map.curry_left_apply],
rw cons_zero
end
@[simp] lemma continuous_multilinear_map.uncurry_curry_left
(f : continuous_multilinear_map 𝕜 E E₂) : f.curry_left.uncurry_left = f :=
by { ext m, simp }
@[simp] lemma continuous_multilinear_map.curry_left_norm
(f : continuous_multilinear_map 𝕜 E E₂) : ∥f.curry_left∥ = ∥f∥ :=
begin
apply le_antisymm (linear_map.mk_continuous_norm_le _ (norm_nonneg _) _),
have : ∥f.curry_left.uncurry_left∥ ≤ ∥f.curry_left∥ :=
multilinear_map.mk_continuous_norm_le _ (norm_nonneg _) _,
simpa
end
@[simp] lemma continuous_linear_map.uncurry_left_norm
(f : E 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.succ) E₂)) :
∥f.uncurry_left∥ = ∥f∥ :=
begin
apply le_antisymm (multilinear_map.mk_continuous_norm_le _ (norm_nonneg _) _),
have : ∥f.uncurry_left.curry_left∥ ≤ ∥f.uncurry_left∥ :=
linear_map.mk_continuous_norm_le _ (norm_nonneg _) _,
simpa
end
variables (𝕜 E E₂)
/-- The space of continuous multilinear maps on `Π(i : fin (n+1)), E i` is canonically isomorphic to
the space of continuous linear maps from `E 0` to the space of continuous multilinear maps on
`Π(i : fin n), E i.succ `, by separating the first variable. We register this isomorphism as a
linear isomorphism in `continuous_multilinear_curry_left_equiv_aux 𝕜 E E₂`.
The algebraic version (without continuity assumption on the maps) is
`multilinear_curry_left_equiv 𝕜 E E₂`, and the topological isomorphism (registering
additionally that the isomorphism is continuous) is
`continuous_multilinear_curry_left_equiv 𝕜 E E₂`.
The direct and inverse maps are given by `f.uncurry_left` and `f.curry_left`. Use these
unless you need the full framework of linear equivs. -/
def continuous_multilinear_curry_left_equiv_aux :
(E 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.succ) E₂)) ≃ₗ[𝕜]
(continuous_multilinear_map 𝕜 E E₂) :=
{ to_fun := continuous_linear_map.uncurry_left,
map_add' := λf₁ f₂, by { ext m, refl },
map_smul' := λc f, by { ext m, refl },
inv_fun := continuous_multilinear_map.curry_left,
left_inv := continuous_linear_map.curry_uncurry_left,
right_inv := continuous_multilinear_map.uncurry_curry_left }
/-- The space of continuous multilinear maps on `Π(i : fin (n+1)), E i` is canonically isomorphic to
the space of continuous linear maps from `E 0` to the space of continuous multilinear maps on
`Π(i : fin n), E i.succ `, by separating the first variable. We register this isomorphism in
`continuous_multilinear_curry_left_equiv 𝕜 E E₂`. The algebraic version (without topology) is given
in `multilinear_curry_left_equiv 𝕜 E E₂`.
The direct and inverse maps are given by `f.uncurry_left` and `f.curry_left`. Use these
unless you need the full framework of continuous linear equivs. -/
def continuous_multilinear_curry_left_equiv :
(E 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.succ) E₂)) ≃L[𝕜]
(continuous_multilinear_map 𝕜 E E₂) :=
{ continuous_to_fun := begin
refine (continuous_multilinear_curry_left_equiv_aux 𝕜 E E₂).to_linear_map.continuous_of_bound
(1 : ℝ) (λf, le_of_eq _),
rw one_mul,
exact f.uncurry_left_norm
end,
continuous_inv_fun := begin
refine (continuous_multilinear_curry_left_equiv_aux 𝕜 E E₂).symm.to_linear_map.continuous_of_bound
(1 : ℝ) (λf, le_of_eq _),
rw one_mul,
exact f.curry_left_norm
end,
.. continuous_multilinear_curry_left_equiv_aux 𝕜 E E₂ }
variables {𝕜 E E₂}
@[simp] lemma continuous_multilinear_curry_left_equiv_apply
(f : E 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.succ) E₂)) (v : Π i, E i) :
continuous_multilinear_curry_left_equiv 𝕜 E E₂ f v = f (v 0) (tail v) := rfl
@[simp] lemma continuous_multilinear_curry_left_equiv_symm_apply
(f : continuous_multilinear_map 𝕜 E E₂) (x : E 0) (v : Π (i : fin n), E i.succ) :
(continuous_multilinear_curry_left_equiv 𝕜 E E₂).symm f x v = f (cons x v) := rfl
/-! #### Right currying -/
/-- Given a continuous linear map `f` from continuous multilinear maps on `n` variables to
continuous linear maps on `E 0`, construct the corresponding continuous multilinear map on `n+1`
variables obtained by concatenating the variables, given by `m ↦ f (init m) (m (last n))`. -/
def continuous_multilinear_map.uncurry_right
(f : continuous_multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →L[𝕜] E₂)) :
continuous_multilinear_map 𝕜 E E₂ :=
let f' : multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →ₗ[𝕜] E₂) :=
{ to_fun := λ m, (f m).to_linear_map,
map_add' := λ m i x y, by { simp, refl },
map_smul' := λ m i c x, by { simp, refl } } in
(@multilinear_map.uncurry_right 𝕜 n E E₂ _ _ _ _ _ f').mk_continuous
(∥f∥) (λm, f.norm_map_init_le m)
@[simp] lemma continuous_multilinear_map.uncurry_right_apply
(f : continuous_multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →L[𝕜] E₂)) (m : Πi, E i) :
f.uncurry_right m = f (init m) (m (last n)) := rfl
/-- Given a continuous multilinear map `f` in `n+1` variables, split the last variable to obtain
a continuous multilinear map in `n` variables into continuous linear maps, given by
`m ↦ (x ↦ f (snoc m x))`. -/
def continuous_multilinear_map.curry_right
(f : continuous_multilinear_map 𝕜 E E₂) :
continuous_multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →L[𝕜] E₂) :=
let f' : multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →L[𝕜] E₂) :=
{ to_fun := λm, (f.to_multilinear_map.curry_right m).mk_continuous
(∥f∥ * ∏ i, ∥m i∥) $ λx, f.norm_map_snoc_le m x,
map_add' := λ m i x y, by { simp, refl },
map_smul' := λ m i c x, by { simp, refl } } in
f'.mk_continuous (∥f∥) (λm, linear_map.mk_continuous_norm_le _
(mul_nonneg (norm_nonneg _) (prod_nonneg (λj hj, norm_nonneg _))) _)
@[simp] lemma continuous_multilinear_map.curry_right_apply
(f : continuous_multilinear_map 𝕜 E E₂) (m : Π(i : fin n), E i.cast_succ) (x : E (last n)) :
f.curry_right m x = f (snoc m x) := rfl
@[simp] lemma continuous_multilinear_map.curry_uncurry_right
(f : continuous_multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →L[𝕜] E₂)) :
f.uncurry_right.curry_right = f :=
begin
ext m x,
simp only [snoc_last, continuous_multilinear_map.curry_right_apply,
continuous_multilinear_map.uncurry_right_apply],
rw init_snoc
end
@[simp] lemma continuous_multilinear_map.uncurry_curry_right
(f : continuous_multilinear_map 𝕜 E E₂) : f.curry_right.uncurry_right = f :=
by { ext m, simp }
@[simp] lemma continuous_multilinear_map.curry_right_norm
(f : continuous_multilinear_map 𝕜 E E₂) : ∥f.curry_right∥ = ∥f∥ :=
begin
refine le_antisymm (multilinear_map.mk_continuous_norm_le _ (norm_nonneg _) _) _,
have : ∥f.curry_right.uncurry_right∥ ≤ ∥f.curry_right∥ :=
multilinear_map.mk_continuous_norm_le _ (norm_nonneg _) _,
simpa
end
@[simp] lemma continuous_multilinear_map.uncurry_right_norm
(f : continuous_multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →L[𝕜] E₂)) :
∥f.uncurry_right∥ = ∥f∥ :=
begin
refine le_antisymm (multilinear_map.mk_continuous_norm_le _ (norm_nonneg _) _) _,
have : ∥f.uncurry_right.curry_right∥ ≤ ∥f.uncurry_right∥ :=
multilinear_map.mk_continuous_norm_le _ (norm_nonneg _) _,
simpa
end
variables (𝕜 E E₂)
/-- The space of continuous multilinear maps on `Π(i : fin (n+1)), E i` is canonically isomorphic to
the space of continuous multilinear maps on `Π(i : fin n), E i.cast_succ` with values in the space
of continuous linear maps on `E (last n)`, by separating the last variable. We register this
isomorphism as a linear equiv in `continuous_multilinear_curry_right_equiv_aux 𝕜 E E₂`.
The algebraic version (without continuity assumption on the maps) is
`multilinear_curry_right_equiv 𝕜 E E₂`, and the topological isomorphism (registering
additionally that the isomorphism is continuous) is
`continuous_multilinear_curry_right_equiv 𝕜 E E₂`.
The direct and inverse maps are given by `f.uncurry_right` and `f.curry_right`. Use these
unless you need the full framework of linear equivs. -/
def continuous_multilinear_curry_right_equiv_aux :
(continuous_multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →L[𝕜] E₂)) ≃ₗ[𝕜]
(continuous_multilinear_map 𝕜 E E₂) :=
{ to_fun := continuous_multilinear_map.uncurry_right,
map_add' := λf₁ f₂, by { ext m, refl },
map_smul' := λc f, by { ext m, refl },
inv_fun := continuous_multilinear_map.curry_right,
left_inv := continuous_multilinear_map.curry_uncurry_right,
right_inv := continuous_multilinear_map.uncurry_curry_right }
/-- The space of continuous multilinear maps on `Π(i : fin (n+1)), E i` is canonically isomorphic to
the space of continuous multilinear maps on `Π(i : fin n), E i.cast_succ` with values in the space
of continuous linear maps on `E (last n)`, by separating the last variable. We register this
isomorphism as a continuous linear equiv in `continuous_multilinear_curry_right_equiv 𝕜 E E₂`.
The algebraic version (without topology) is given in `multilinear_curry_right_equiv 𝕜 E E₂`.
The direct and inverse maps are given by `f.uncurry_right` and `f.curry_right`. Use these
unless you need the full framework of continuous linear equivs. -/
def continuous_multilinear_curry_right_equiv :
(continuous_multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →L[𝕜] E₂)) ≃L[𝕜]
(continuous_multilinear_map 𝕜 E E₂) :=
{ continuous_to_fun := begin
refine (continuous_multilinear_curry_right_equiv_aux 𝕜 E E₂).to_linear_map.continuous_of_bound
(1 : ℝ) (λf, le_of_eq _),
rw one_mul,
exact f.uncurry_right_norm
end,
continuous_inv_fun := begin
refine (continuous_multilinear_curry_right_equiv_aux 𝕜 E E₂).symm.to_linear_map.continuous_of_bound
(1 : ℝ) (λf, le_of_eq _),
rw one_mul,
exact f.curry_right_norm
end,
.. continuous_multilinear_curry_right_equiv_aux 𝕜 E E₂ }
variables {𝕜 G E E₂}
@[simp] lemma continuous_multilinear_curry_right_equiv_apply
(f : (continuous_multilinear_map 𝕜 (λ(i : fin n), E i.cast_succ) (E (last n) →L[𝕜] E₂)))
(v : Π i, E i) :
(continuous_multilinear_curry_right_equiv 𝕜 E E₂) f v = f (init v) (v (last n)) := rfl
@[simp] lemma continuous_multilinear_curry_right_equiv_symm_apply
(f : continuous_multilinear_map 𝕜 E E₂)
(v : Π (i : fin n), E i.cast_succ) (x : E (last n)) :
(continuous_multilinear_curry_right_equiv 𝕜 E E₂).symm f v x = f (snoc v x) := rfl
/-!
#### Currying with `0` variables
The space of multilinear maps with `0` variables is trivial: such a multilinear map is just an
arbitrary constant (note that multilinear maps in `0` variables need not map `0` to `0`!).
Therefore, the space of continuous multilinear maps on `(fin 0) → G` with values in `E₂` is
isomorphic (and even isometric) to `E₂`. As this is the zeroth step in the construction of iterated
derivatives, we register this isomorphism. -/
variables {𝕜 G E₂}
/-- Associating to a continuous multilinear map in `0` variables the unique value it takes. -/
def continuous_multilinear_map.uncurry0
(f : continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂) : E₂ := f 0
variables (𝕜 G)
/-- Associating to an element `x` of a vector space `E₂` the continuous multilinear map in `0`
variables taking the (unique) value `x` -/
def continuous_multilinear_map.curry0 (x : E₂) :
continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂ :=
{ to_fun := λm, x,
map_add' := λ m i, fin.elim0 i,
map_smul' := λ m i, fin.elim0 i,
cont := continuous_const }
variable {G}
@[simp] lemma continuous_multilinear_map.curry0_apply (x : E₂) (m : (fin 0) → G) :
(continuous_multilinear_map.curry0 𝕜 G x : ((fin 0) → G) → E₂) m = x := rfl
variable {𝕜}
@[simp] lemma continuous_multilinear_map.uncurry0_apply
(f : continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂) :
f.uncurry0 = f 0 := rfl
@[simp] lemma continuous_multilinear_map.apply_zero_curry0
(f : continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂) {x : fin 0 → G} :
continuous_multilinear_map.curry0 𝕜 G (f x) = f :=
by { ext m, simp [(subsingleton.elim _ _ : x = m)] }
lemma continuous_multilinear_map.uncurry0_curry0
(f : continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂) :
continuous_multilinear_map.curry0 𝕜 G (f.uncurry0) = f :=
by simp
variables (𝕜 G)
@[simp] lemma continuous_multilinear_map.curry0_uncurry0 (x : E₂) :
(continuous_multilinear_map.curry0 𝕜 G x).uncurry0 = x := rfl
@[simp] lemma continuous_multilinear_map.uncurry0_norm (x : E₂) :
∥continuous_multilinear_map.curry0 𝕜 G x∥ = ∥x∥ :=
begin
apply le_antisymm,
{ exact continuous_multilinear_map.op_norm_le_bound _ (norm_nonneg _) (λm, by simp) },
{ simpa using (continuous_multilinear_map.curry0 𝕜 G x).le_op_norm 0 }
end
variables {𝕜 G}
@[simp] lemma continuous_multilinear_map.fin0_apply_norm
(f : continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂) {x : fin 0 → G} :
∥f x∥ = ∥f∥ :=
begin
have : x = 0 := subsingleton.elim _ _, subst this,
refine le_antisymm (by simpa using f.le_op_norm 0) _,
have : ∥continuous_multilinear_map.curry0 𝕜 G (f.uncurry0)∥ ≤ ∥f.uncurry0∥ :=
continuous_multilinear_map.op_norm_le_bound _ (norm_nonneg _) (λm,
by simp [-continuous_multilinear_map.apply_zero_curry0]),
simpa
end
lemma continuous_multilinear_map.curry0_norm
(f : continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂) : ∥f.uncurry0∥ = ∥f∥ :=
by simp
variables (𝕜 G E₂)
/-- The linear isomorphism between elements of a normed space, and continuous multilinear maps in
`0` variables with values in this normed space. The continuous version is given in
`continuous_multilinear_curry_fin0`.
The direct and inverse maps are `uncurry0` and `curry0`. Use these unless you need the full
framework of linear equivs. -/
def continuous_multilinear_curry_fin0_aux :
(continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂) ≃ₗ[𝕜] E₂ :=
{ to_fun := λf, continuous_multilinear_map.uncurry0 f,
inv_fun := λf, continuous_multilinear_map.curry0 𝕜 G f,
map_add' := λf g, rfl,
map_smul' := λc f, rfl,
left_inv := continuous_multilinear_map.uncurry0_curry0,
right_inv := continuous_multilinear_map.curry0_uncurry0 𝕜 G }
/-- The continuous linear isomorphism between elements of a normed space, and continuous multilinear
maps in `0` variables with values in this normed space.
The direct and inverse maps are `uncurry0` and `curry0`. Use these unless you need the full
framework of continuous linear equivs. -/
def continuous_multilinear_curry_fin0 :
(continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂) ≃L[𝕜] E₂ :=
{ continuous_to_fun := begin
change continuous (λ (f : continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂),
(f : ((fin 0) → G) → E₂) 0),
exact continuous_multilinear_map.continuous_eval.comp (continuous_id.prod_mk continuous_const)
end,
continuous_inv_fun := begin
refine (continuous_multilinear_curry_fin0_aux 𝕜 G E₂).symm.to_linear_map.continuous_of_bound
(1 : ℝ) (λf, le_of_eq _),
rw one_mul,
exact continuous_multilinear_map.uncurry0_norm _ _ _
end,
.. continuous_multilinear_curry_fin0_aux 𝕜 G E₂ }
variables {𝕜 G E₂}
@[simp] lemma continuous_multilinear_curry_fin0_apply
(f : (continuous_multilinear_map 𝕜 (λ (i : fin 0), G) E₂)) :
continuous_multilinear_curry_fin0 𝕜 G E₂ f = f 0 := rfl
@[simp] lemma continuous_multilinear_curry_fin0_symm_apply
(x : E₂) (v : (fin 0) → G) :
(continuous_multilinear_curry_fin0 𝕜 G E₂).symm x v = x := rfl
/-! #### With 1 variable -/
variables (𝕜 G E₂)
/-- Continuous multilinear maps from `G^1` to `E₂` are isomorphic with continuous linear maps from
`G` to `E₂`. -/
def continuous_multilinear_curry_fin1 :
(continuous_multilinear_map 𝕜 (λ (i : fin 1), G) E₂) ≃L[𝕜] (G →L[𝕜] E₂) :=
(continuous_multilinear_curry_right_equiv 𝕜 (λ (i : fin 1), G) E₂).symm.trans
(continuous_multilinear_curry_fin0 𝕜 G (G →L[𝕜] E₂))
variables {𝕜 G E₂}
@[simp] lemma continuous_multilinear_curry_fin1_apply
(f : (continuous_multilinear_map 𝕜 (λ (i : fin 1), G) E₂)) (x : G) :
continuous_multilinear_curry_fin1 𝕜 G E₂ f x = f (fin.snoc 0 x) := rfl
@[simp] lemma continuous_multilinear_curry_fin1_symm_apply
(f : G →L[𝕜] E₂) (v : (fin 1) → G) :
(continuous_multilinear_curry_fin1 𝕜 G E₂).symm f v = f (v 0) := rfl
end currying
|
b1352b9f00a7439e496bf70a721c8ca04ba58a16 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/dependent_seq.lean | 860c06d181daa4b1b0cfc233b5b899add80b3b1b | [
"Apache-2.0"
] | permissive | leanprover-community/lean | 12b87f69d92e614daea8bcc9d4de9a9ace089d0e | cce7990ea86a78bdb383e38ed7f9b5ba93c60ce0 | refs/heads/master | 1,687,508,156,644 | 1,684,951,104,000 | 1,684,951,104,000 | 169,960,991 | 457 | 107 | Apache-2.0 | 1,686,744,372,000 | 1,549,790,268,000 | C++ | UTF-8 | Lean | false | false | 170 | lean |
theorem test (n : nat) (h : n = n) : true := trivial
example (h : 3 = 3) : true :=
by apply test; assumption
example (h : 3 = 3) : true :=
by apply test; [assumption]
|
03e6586d3cf3188383f917c7f875954bbdb3f0c8 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/macroid.lean | 6205a2a308a69864caec234f6cdf8c69be05f6c9 | [
"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 | 575 | lean | syntax "[" ident "↦" term "]" : term
macro_rules | `([$x ↦ $v]) => `(fun $x => $v)
#check [x ↦ x + 1]
syntax "case!" ident ":" term "with" term "," term : term
macro_rules | `(case! $h : $c with $t, $e) => `((fun $h => cond $h $t $e) $c)
#check case! h : 0 == 0 with h, not h
syntax "case2!" ident ":" term "with" term "," term : term
macro_rules | `(case2! $h : $c with $t, $e) => `(let $h := $c; cond $h $t $e)
#check case2! h : 0 == 0 with h, not h
syntax "test" term : term
macro_rules | `(test $x:ident) => `(let $x := 0; $x)
#check fun (x : Nat) => test x
|
d7f42d9ed843e10a34d569d231f5de2f257ef858 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/category_theory/limits/connected.lean | c0f3710678c42d8ef0fb8b9aa36bf26b87f42db1 | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 3,798 | lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import category_theory.limits.shapes.binary_products
import category_theory.limits.shapes.equalizers
import category_theory.limits.shapes.wide_pullbacks
import category_theory.is_connected
import category_theory.limits.preserves.basic
/-!
# Connected limits
A connected limit is a limit whose shape is a connected category.
We give examples of connected categories, and prove that the functor given
by `(X × -)` preserves any connected limit. That is, any limit of shape `J`
where `J` is a connected category is preserved by the functor `(X × -)`.
-/
noncomputable theory
universes v₁ v₂ u₁ u₂
open category_theory category_theory.category category_theory.limits
namespace category_theory
section examples
instance wide_pullback_shape_connected (J : Type v₁) : is_connected (wide_pullback_shape J) :=
begin
apply is_connected.of_induct,
introv hp t,
cases j,
{ exact hp },
{ rwa t (wide_pullback_shape.hom.term j) }
end
instance wide_pushout_shape_connected (J : Type v₁) : is_connected (wide_pushout_shape J) :=
begin
apply is_connected.of_induct,
introv hp t,
cases j,
{ exact hp },
{ rwa ← t (wide_pushout_shape.hom.init j) }
end
instance parallel_pair_inhabited : inhabited walking_parallel_pair := ⟨walking_parallel_pair.one⟩
instance parallel_pair_connected : is_connected (walking_parallel_pair) :=
begin
apply is_connected.of_induct,
introv _ t,
cases j,
{ rwa t walking_parallel_pair_hom.left },
{ assumption }
end
end examples
local attribute [tidy] tactic.case_bash
variables {C : Type u₂} [category.{v₂} C]
variables [has_binary_products C]
variables {J : Type v₂} [small_category J]
namespace prod_preserves_connected_limits
/-- (Impl). The obvious natural transformation from (X × K -) to K. -/
@[simps]
def γ₂ {K : J ⥤ C} (X : C) : K ⋙ prod.functor.obj X ⟶ K :=
{ app := λ Y, limits.prod.snd }
/-- (Impl). The obvious natural transformation from (X × K -) to X -/
@[simps]
def γ₁ {K : J ⥤ C} (X : C) : K ⋙ prod.functor.obj X ⟶ (functor.const J).obj X :=
{ app := λ Y, limits.prod.fst }
/-- (Impl).
Given a cone for (X × K -), produce a cone for K using the natural transformation `γ₂` -/
@[simps]
def forget_cone {X : C} {K : J ⥤ C} (s : cone (K ⋙ prod.functor.obj X)) : cone K :=
{ X := s.X,
π := s.π ≫ γ₂ X }
end prod_preserves_connected_limits
open prod_preserves_connected_limits
/--
The functor `(X × -)` preserves any connected limit.
Note that this functor does not preserve the two most obvious disconnected limits - that is,
`(X × -)` does not preserve products or terminal object, eg `(X ⨯ A) ⨯ (X ⨯ B)` is not isomorphic to
`X ⨯ (A ⨯ B)` and `X ⨯ 1` is not isomorphic to `1`.
-/
noncomputable
def prod_preserves_connected_limits [is_connected J] (X : C) :
preserves_limits_of_shape J (prod.functor.obj X) :=
{ preserves_limit := λ K,
{ preserves := λ c l,
{ lift := λ s, prod.lift
(s.π.app (classical.arbitrary _) ≫ limits.prod.fst)
(l.lift (forget_cone s)),
fac' := λ s j,
begin
apply prod.hom_ext,
{ erw [assoc, lim_map_π, comp_id, limit.lift_π],
exact (nat_trans_from_is_connected (s.π ≫ γ₁ X) j (classical.arbitrary _)).symm },
{ simp [← l.fac (forget_cone s) j] }
end,
uniq' := λ s m L,
begin
apply prod.hom_ext,
{ erw [limit.lift_π, ← L (classical.arbitrary J), assoc, lim_map_π, comp_id],
refl },
{ rw limit.lift_π,
apply l.uniq (forget_cone s),
intro j,
simp [← L j] }
end } } }
end category_theory
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.