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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
a6bbcd901139579f203cd2f563889af5bb91f91e | fc086f79b20cf002d6f34b023749998408e94fbf | /test/forwards_reasoning.lean | 5d9602577878daaca0037abb00195b1f6c62148a | [] | no_license | semorrison/lean-tidy | f039460136b898fb282f75efedd92f2d5c5d90f8 | 6c1d46de6cff05e1c2c4c9692af812bca3e13b6c | refs/heads/master | 1,624,461,332,392 | 1,559,655,744,000 | 1,559,655,744,000 | 96,569,994 | 9 | 4 | null | 1,538,287,895,000 | 1,499,455,306,000 | Lean | UTF-8 | Lean | false | false | 981 | lean | import tidy.forwards_reasoning
lemma G (n : ℕ) : list ℕ := [n]
lemma F : ℕ := 0
section
local attribute [forward] G
example : 1 = 1 :=
begin
success_if_fail { forwards_library_reasoning },
refl
end
local attribute [forward] F
example : 1 = 1 :=
begin
forwards_library_reasoning,
forwards_library_reasoning,
success_if_fail { forwards_library_reasoning },
refl
end
example : 1 = 1 :=
begin
have p := [0],
forwards_library_reasoning,
success_if_fail { forwards_library_reasoning },
refl
end
end
section
inductive T (n : ℕ)
| t : ℕ → T
@[forward] lemma H.H {n : ℕ} (v : T n) : string := "hello"
example : 1 = 1 :=
begin
success_if_fail { forwards_library_reasoning },
have p : T 3 := T.t 3 5,
forwards_library_reasoning,
guard_hyp H_p := string, -- check that we drop namespaces
refl
end
example (P Q : Prop) (p : P) (h : P → Q): Q :=
begin
forwards_reasoning,
success_if_fail { forwards_reasoning },
exact h_p
end
end
|
eed0cced1a0ad6e2abefbd72acc3ca48bd0eada9 | 9d2e3d5a2e2342a283affd97eead310c3b528a24 | /src/solutions/thursday/afternoon/category_theory/exercise9.lean | 3d9e0a61568bcead0222574cf1ab26f626dafefc | [] | permissive | Vtec234/lftcm2020 | ad2610ab614beefe44acc5622bb4a7fff9a5ea46 | bbbd4c8162f8c2ef602300ab8fdeca231886375d | refs/heads/master | 1,668,808,098,623 | 1,594,989,081,000 | 1,594,990,079,000 | 280,423,039 | 0 | 0 | MIT | 1,594,990,209,000 | 1,594,990,209,000 | null | UTF-8 | Lean | false | false | 2,683 | lean | import category_theory.limits.shapes.biproducts
/-!
Let's show that every preadditive category embeds into a preadditive category with biproducts,
and identify a good universal property.
This is a more advanced exercise, for which I've indicated a suggested structure,
but not written a full solution. I hope this structure will work out!
-/
universes v u
variables (C : Type u)
structure additive_envelope :=
(ι : Type v)
[fintype : fintype ι]
[decidable_eq : decidable_eq ι]
(val : ι → C)
attribute [instance] additive_envelope.fintype additive_envelope.decidable_eq
variables {C}
def dmatrix {X Y : additive_envelope C} (Z : X.ι → Y.ι → Type*) := Π (i : X.ι) (j : Y.ι), Z i j
-- You may need to develop some API for `dmatrix`, parallel to that in `data.matrix.basic`.
-- One thing you'll certainly need is an "extensionality" lemma,
-- showing that you can prove two `dmatrix`s are equal by checking componentwise.
open category_theory
variables [category.{v} C] [preadditive C]
namespace family
def hom (X Y : additive_envelope C) := dmatrix (λ i j, X.val i ⟶ Y.val j)
open_locale big_operators
instance : category.{v (max u (v+1))} (additive_envelope.{v} C) :=
{ hom := hom,
id := λ X i j, if h : i = j then eq_to_hom (by subst h) else 0,
comp := λ X Y Z f g i k, ∑ (j : Y.ι), f i j ≫ g j k,
id_comp' := sorry,
comp_id' := sorry,
assoc' := sorry, }
variables (C)
@[simps]
def embedding : C ⥤ additive_envelope.{v} C :=
{ obj := λ X, ⟨punit.{v+1}, λ _, X⟩,
map := λ X Y f _ _, f,
map_id' := sorry,
map_comp' := sorry, }
lemma embedding.faithful : faithful (embedding C) :=
sorry
instance : preadditive (additive_envelope.{v} C) :=
sorry -- probably best to go back and make `dmatrix` an `add_comm_group` first.
open category_theory.limits
instance : has_finite_biproducts (additive_envelope.{v} C) :=
{ has_biproducts_of_shape := λ J _ _,
by exactI -- this makes the `fintype` and `decidable_eq` instances on `J` available
{ has_biproduct := λ F,
{ bicone :=
{ X :=
{ ι := Σ (j : J), (F j).ι,
val := λ p, (F p.1).val p.2 },
ι := sorry,
π := sorry,
ι_π := sorry, },
is_limit := sorry,
is_colimit := sorry, }}}
variables {C}
def factor {D : Type u} [category.{v} D] [preadditive D] [has_finite_biproducts D]
(F : C ⥤ D) : additive_envelope.{v} C ⥤ D :=
{ obj := λ X, ⨁ (λ i, F.obj (X.val i)),
map := sorry,
map_id' := sorry,
map_comp' := sorry, }
def factor_factorisation {D : Type u} [category.{v} D] [preadditive D] [has_finite_biproducts D]
(F : C ⥤ D) : F ≅ embedding C ⋙ factor F :=
sorry
end family
|
39a3e19c3a077e62010294ea0d770bebd6359fa1 | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/category/functor.lean | c3f703c91e6150b91b0bafda53283b0650ea912a | [
"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,290 | lean | /-
Copyright (c) 2017 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Simon Hudon
Standard identity and composition functors
-/
import tactic.ext tactic.lint category.basic
universe variables u v w
section functor
variables {F : Type u → Type v}
variables {α β γ : Type u}
variables [functor F] [is_lawful_functor F]
lemma functor.map_id : (<$>) id = (id : F α → F α) :=
by apply funext; apply id_map
lemma functor.map_comp_map (f : α → β) (g : β → γ) :
((<$>) g ∘ (<$>) f : F α → F γ) = (<$>) (g ∘ f) :=
by apply funext; intro; rw comp_map
theorem functor.ext {F} : ∀ {F1 : functor F} {F2 : functor F}
[@is_lawful_functor F F1] [@is_lawful_functor F F2]
(H : ∀ α β (f : α → β) (x : F α),
@functor.map _ F1 _ _ f x = @functor.map _ F2 _ _ f x),
F1 = F2
| ⟨m, mc⟩ ⟨m', mc'⟩ H1 H2 H :=
begin
cases show @m = @m', by funext α β f x; apply H,
congr, funext α β,
have E1 := @map_const_eq _ ⟨@m, @mc⟩ H1,
have E2 := @map_const_eq _ ⟨@m, @mc'⟩ H2,
exact E1.trans E2.symm
end
end functor
def id.mk {α : Sort u} : α → id α := id
namespace functor
@[nolint] def const (α : Type*) (β : Type*) := α
@[pattern] def const.mk {α β} (x : α) : const α β := x
def const.mk' {α} (x : α) : const α punit := x
def const.run {α β} (x : const α β) : α := x
namespace const
protected lemma ext {α β} {x y : const α β} (h : x.run = y.run) : x = y := h
@[nolint] protected def map {γ α β} (f : α → β) (x : const γ β) : const γ α := x
instance {γ} : functor (const γ) :=
{ map := @const.map γ }
instance {γ} : is_lawful_functor (const γ) :=
by constructor; intros; refl
end const
def add_const (α : Type*) := const α
@[pattern]
def add_const.mk {α β} (x : α) : add_const α β := x
def add_const.run {α β} : add_const α β → α := id
instance add_const.functor {γ} : functor (add_const γ) :=
@const.functor γ
instance add_const.is_lawful_functor {γ} : is_lawful_functor (add_const γ) :=
@const.is_lawful_functor γ
/-- `functor.comp` is a wrapper around `function.comp` for types.
It prevents Lean's type class resolution mechanism from trying
a `functor (comp F id)` when `functor F` would do. -/
def comp (F : Type u → Type w) (G : Type v → Type u) (α : Type v) : Type w :=
F $ G α
@[pattern] def comp.mk {F : Type u → Type w} {G : Type v → Type u} {α : Type v}
(x : F (G α)) : comp F G α := x
def comp.run {F : Type u → Type w} {G : Type v → Type u} {α : Type v}
(x : comp F G α) : F (G α) := x
namespace comp
variables {F : Type u → Type w} {G : Type v → Type u}
protected lemma ext
{α} {x y : comp F G α} : x.run = y.run → x = y := id
variables [functor F] [functor G]
protected def map {α β : Type v} (h : α → β) : comp F G α → comp F G β
| (comp.mk x) := comp.mk ((<$>) h <$> x)
instance : functor (comp F G) := { map := @comp.map F G _ _ }
@[functor_norm] lemma map_mk {α β} (h : α → β) (x : F (G α)) :
h <$> comp.mk x = comp.mk ((<$>) h <$> x) := rfl
@[simp] protected lemma run_map {α β} (h : α → β) (x : comp F G α) :
(h <$> x).run = (<$>) h <$> x.run := rfl
variables [is_lawful_functor F] [is_lawful_functor G]
variables {α β γ : Type v}
protected lemma id_map : ∀ (x : comp F G α), comp.map id x = x
| (comp.mk x) := by simp [comp.map, functor.map_id]
protected lemma comp_map (g' : α → β) (h : β → γ) : ∀ (x : comp F G α),
comp.map (h ∘ g') x = comp.map h (comp.map g' x)
| (comp.mk x) := by simp [comp.map, functor.map_comp_map g' h] with functor_norm
instance : is_lawful_functor (comp F G) :=
{ id_map := @comp.id_map F G _ _ _ _,
comp_map := @comp.comp_map F G _ _ _ _ }
theorem functor_comp_id {F} [AF : functor F] [is_lawful_functor F] :
@comp.functor F id _ _ = AF :=
@functor.ext F _ AF (@comp.is_lawful_functor F id _ _ _ _) _ (λ α β f x, rfl)
theorem functor_id_comp {F} [AF : functor F] [is_lawful_functor F] :
@comp.functor id F _ _ = AF :=
@functor.ext F _ AF (@comp.is_lawful_functor id F _ _ _ _) _ (λ α β f x, rfl)
end comp
end functor
namespace ulift
instance : functor ulift :=
{ map := λ α β f, up ∘ f ∘ down }
end ulift
|
e8432e18d55efd5014dd0912088ee5a9d8f40044 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/combinatorics/simple_graph/coloring.lean | 9440e95fe8aa370543e6f75cbbae0accade3fc64 | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 15,554 | lean | /-
Copyright (c) 2021 Arthur Paulino. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Arthur Paulino, Kyle Miller
-/
import combinatorics.simple_graph.subgraph
import combinatorics.simple_graph.clique
import data.nat.lattice
import data.setoid.partition
import order.antichain
/-!
# Graph Coloring
This module defines colorings of simple graphs (also known as proper
colorings in the literature). A graph coloring is the attribution of
"colors" to all of its vertices such that adjacent vertices have
different colors. A coloring can be represented as a homomorphism into
a complete graph, whose vertices represent the colors.
## Main definitions
* `G.coloring α` is the type of `α`-colorings of a simple graph `G`,
with `α` being the set of available colors. The type is defined to
be homomorphisms from `G` into the complete graph on `α`, and
colorings have a coercion to `V → α`.
* `G.colorable n` is the proposition that `G` is `n`-colorable, which
is whether there exists a coloring with at most *n* colors.
* `G.chromatic_number` is the minimal `n` such that `G` is
`n`-colorable, or `0` if it cannot be colored with finitely many
colors.
* `C.color_class c` is the set of vertices colored by `c : α` in the
coloring `C : G.coloring α`.
* `C.color_classes` is the set containing all color classes.
## Todo:
* Gather material from:
* https://github.com/leanprover-community/mathlib/blob/simple_graph_matching/src/combinatorics/simple_graph/coloring.lean
* https://github.com/kmill/lean-graphcoloring/blob/master/src/graph.lean
* Trees
* Planar graphs
* Chromatic polynomials
* develop API for partial colorings, likely as colorings of subgraphs (`H.coe.coloring α`)
-/
universes u v
namespace simple_graph
variables {V : Type u} (G : simple_graph V)
/--
An `α`-coloring of a simple graph `G` is a homomorphism of `G` into the complete graph on `α`.
This is also known as a proper coloring.
-/
abbreviation coloring (α : Type v) := G →g (⊤ : simple_graph α)
variables {G} {α : Type v} (C : G.coloring α)
lemma coloring.valid {v w : V} (h : G.adj v w) : C v ≠ C w :=
C.map_rel h
/--
Construct a term of `simple_graph.coloring` using a function that
assigns vertices to colors and a proof that it is as proper coloring.
(Note: this is a definitionally the constructor for `simple_graph.hom`,
but with a syntactically better proper coloring hypothesis.)
-/
@[pattern] def coloring.mk
(color : V → α)
(valid : ∀ {v w : V}, G.adj v w → color v ≠ color w) :
G.coloring α := ⟨color, @valid⟩
/--
The color class of a given color.
-/
def coloring.color_class (c : α) : set V := {v : V | C v = c}
/-- The set containing all color classes. -/
def coloring.color_classes : set (set V) := (setoid.ker C).classes
lemma coloring.mem_color_class (v : V) :
v ∈ C.color_class (C v) := by exact rfl
lemma coloring.color_classes_is_partition :
setoid.is_partition C.color_classes :=
setoid.is_partition_classes (setoid.ker C)
lemma coloring.mem_color_classes {v : V} : C.color_class (C v) ∈ C.color_classes :=
⟨v, rfl⟩
lemma coloring.color_classes_finite [finite α] : C.color_classes.finite :=
set.finite_coe_iff.1 $ setoid.finite_classes_ker _
lemma coloring.card_color_classes_le [fintype α] [fintype C.color_classes] :
fintype.card C.color_classes ≤ fintype.card α :=
setoid.card_classes_ker_le C
lemma coloring.not_adj_of_mem_color_class {c : α} {v w : V}
(hv : v ∈ C.color_class c) (hw : w ∈ C.color_class c) :
¬G.adj v w :=
λ h, C.valid h (eq.trans hv (eq.symm hw))
lemma coloring.color_classes_independent (c : α) :
is_antichain G.adj (C.color_class c) :=
λ v hv w hw h, C.not_adj_of_mem_color_class hv hw
-- TODO make this computable
noncomputable
instance [fintype V] [fintype α] : fintype (coloring G α) :=
begin
classical,
change fintype (rel_hom G.adj (⊤ : simple_graph α).adj),
apply fintype.of_injective _ rel_hom.coe_fn_injective,
apply_instance,
end
variables (G)
/-- Whether a graph can be colored by at most `n` colors. -/
def colorable (n : ℕ) : Prop := nonempty (G.coloring (fin n))
/-- The coloring of an empty graph. -/
def coloring_of_is_empty [is_empty V] : G.coloring α :=
coloring.mk is_empty_elim (λ v, is_empty_elim)
lemma colorable_of_is_empty [is_empty V] (n : ℕ) : G.colorable n :=
⟨G.coloring_of_is_empty⟩
lemma is_empty_of_colorable_zero (h : G.colorable 0) : is_empty V :=
begin
split,
intro v,
obtain ⟨i, hi⟩ := h.some v,
exact nat.not_lt_zero _ hi,
end
/-- The "tautological" coloring of a graph, using the vertices of the graph as colors. -/
def self_coloring : G.coloring V :=
coloring.mk id (λ v w, G.ne_of_adj)
/-- The chromatic number of a graph is the minimal number of colors needed to color it.
If `G` isn't colorable with finitely many colors, this will be 0. -/
noncomputable def chromatic_number : ℕ :=
Inf { n : ℕ | G.colorable n }
/-- Given an embedding, there is an induced embedding of colorings. -/
def recolor_of_embedding {α β : Type*} (f : α ↪ β) : G.coloring α ↪ G.coloring β :=
{ to_fun := λ C, (embedding.complete_graph f).to_hom.comp C,
inj' := begin -- this was strangely painful; seems like missing lemmas about embeddings
intros C C' h,
dsimp only at h,
ext v,
apply (embedding.complete_graph f).inj',
change ((embedding.complete_graph f).to_hom.comp C) v = _,
rw h,
refl,
end }
/-- Given an equivalence, there is an induced equivalence between colorings. -/
def recolor_of_equiv {α β : Type*} (f : α ≃ β) : G.coloring α ≃ G.coloring β :=
{ to_fun := G.recolor_of_embedding f.to_embedding,
inv_fun := G.recolor_of_embedding f.symm.to_embedding,
left_inv := λ C, by { ext v, apply equiv.symm_apply_apply },
right_inv := λ C, by { ext v, apply equiv.apply_symm_apply } }
/-- There is a noncomputable embedding of `α`-colorings to `β`-colorings if
`β` has at least as large a cardinality as `α`. -/
noncomputable def recolor_of_card_le {α β : Type*} [fintype α] [fintype β]
(hn : fintype.card α ≤ fintype.card β) :
G.coloring α ↪ G.coloring β :=
G.recolor_of_embedding $ (function.embedding.nonempty_of_card_le hn).some
variables {G}
lemma colorable.mono {n m : ℕ} (h : n ≤ m) (hc : G.colorable n) : G.colorable m :=
⟨G.recolor_of_card_le (by simp [h]) hc.some⟩
lemma coloring.to_colorable [fintype α] (C : G.coloring α) :
G.colorable (fintype.card α) :=
⟨G.recolor_of_card_le (by simp) C⟩
lemma colorable_of_fintype (G : simple_graph V) [fintype V] :
G.colorable (fintype.card V) :=
G.self_coloring.to_colorable
/-- Noncomputably get a coloring from colorability. -/
noncomputable def colorable.to_coloring [fintype α] {n : ℕ} (hc : G.colorable n)
(hn : n ≤ fintype.card α) :
G.coloring α :=
begin
rw ←fintype.card_fin n at hn,
exact G.recolor_of_card_le hn hc.some,
end
lemma colorable.of_embedding {V' : Type*} {G' : simple_graph V'}
(f : G ↪g G') {n : ℕ} (h : G'.colorable n) : G.colorable n :=
⟨(h.to_coloring (by simp)).comp f⟩
lemma colorable_iff_exists_bdd_nat_coloring (n : ℕ) :
G.colorable n ↔ ∃ (C : G.coloring ℕ), ∀ v, C v < n :=
begin
split,
{ rintro hc,
have C : G.coloring (fin n) := hc.to_coloring (by simp),
let f := embedding.complete_graph fin.coe_embedding,
use f.to_hom.comp C,
intro v,
cases C with color valid,
exact fin.is_lt (color v), },
{ rintro ⟨C, Cf⟩,
refine ⟨coloring.mk _ _⟩,
{ exact λ v, ⟨C v, Cf v⟩, },
{ rintro v w hvw,
simp only [fin.mk_eq_mk, ne.def],
exact C.valid hvw, } }
end
lemma colorable_set_nonempty_of_colorable {n : ℕ} (hc : G.colorable n) :
{n : ℕ | G.colorable n}.nonempty :=
⟨n, hc⟩
lemma chromatic_number_bdd_below : bdd_below {n : ℕ | G.colorable n} :=
⟨0, λ _ _, zero_le _⟩
lemma chromatic_number_le_of_colorable {n : ℕ} (hc : G.colorable n) :
G.chromatic_number ≤ n :=
begin
rw chromatic_number,
apply cInf_le chromatic_number_bdd_below,
fsplit,
exact classical.choice hc,
end
lemma chromatic_number_le_card [fintype α] (C : G.coloring α) :
G.chromatic_number ≤ fintype.card α :=
cInf_le chromatic_number_bdd_below C.to_colorable
lemma colorable_chromatic_number {m : ℕ} (hc : G.colorable m) :
G.colorable G.chromatic_number :=
begin
dsimp only [chromatic_number],
rw nat.Inf_def,
apply nat.find_spec,
exact colorable_set_nonempty_of_colorable hc,
end
lemma colorable_chromatic_number_of_fintype (G : simple_graph V) [finite V] :
G.colorable G.chromatic_number :=
by { casesI nonempty_fintype V, exact colorable_chromatic_number G.colorable_of_fintype }
lemma chromatic_number_le_one_of_subsingleton (G : simple_graph V) [subsingleton V] :
G.chromatic_number ≤ 1 :=
begin
rw chromatic_number,
apply cInf_le chromatic_number_bdd_below,
fsplit,
refine coloring.mk (λ _, 0) _,
intros v w,
rw subsingleton.elim v w,
simp,
end
lemma chromatic_number_eq_zero_of_isempty (G : simple_graph V) [is_empty V] :
G.chromatic_number = 0 :=
begin
rw ←nonpos_iff_eq_zero,
apply cInf_le chromatic_number_bdd_below,
apply colorable_of_is_empty,
end
lemma is_empty_of_chromatic_number_eq_zero (G : simple_graph V) [finite V]
(h : G.chromatic_number = 0) : is_empty V :=
begin
have h' := G.colorable_chromatic_number_of_fintype,
rw h at h',
exact G.is_empty_of_colorable_zero h',
end
lemma chromatic_number_pos [nonempty V] {n : ℕ} (hc : G.colorable n) :
0 < G.chromatic_number :=
begin
apply le_cInf (colorable_set_nonempty_of_colorable hc),
intros m hm,
by_contra h',
simp only [not_le, nat.lt_one_iff] at h',
subst h',
obtain ⟨i, hi⟩ := hm.some (classical.arbitrary V),
exact nat.not_lt_zero _ hi,
end
lemma colorable_of_chromatic_number_pos (h : 0 < G.chromatic_number) :
G.colorable G.chromatic_number :=
begin
obtain ⟨h, hn⟩ := nat.nonempty_of_pos_Inf h,
exact colorable_chromatic_number hn,
end
lemma colorable.mono_left {G' : simple_graph V} (h : G ≤ G') {n : ℕ}
(hc : G'.colorable n) : G.colorable n :=
⟨hc.some.comp (hom.map_spanning_subgraphs h)⟩
lemma colorable.chromatic_number_le_of_forall_imp {V' : Type*} {G' : simple_graph V'}
{m : ℕ} (hc : G'.colorable m)
(h : ∀ n, G'.colorable n → G.colorable n) :
G.chromatic_number ≤ G'.chromatic_number :=
begin
apply cInf_le chromatic_number_bdd_below,
apply h,
apply colorable_chromatic_number hc,
end
lemma colorable.chromatic_number_mono (G' : simple_graph V)
{m : ℕ} (hc : G'.colorable m) (h : G ≤ G') :
G.chromatic_number ≤ G'.chromatic_number :=
hc.chromatic_number_le_of_forall_imp (λ n, colorable.mono_left h)
lemma colorable.chromatic_number_mono_of_embedding {V' : Type*} {G' : simple_graph V'}
{n : ℕ} (h : G'.colorable n) (f : G ↪g G') :
G.chromatic_number ≤ G'.chromatic_number :=
h.chromatic_number_le_of_forall_imp (λ _, colorable.of_embedding f)
lemma chromatic_number_eq_card_of_forall_surj [fintype α] (C : G.coloring α)
(h : ∀ (C' : G.coloring α), function.surjective C') :
G.chromatic_number = fintype.card α :=
begin
apply le_antisymm,
{ apply chromatic_number_le_card C, },
{ by_contra hc,
rw not_le at hc,
obtain ⟨n, cn, hc⟩ := exists_lt_of_cInf_lt
(colorable_set_nonempty_of_colorable C.to_colorable) hc,
rw ←fintype.card_fin n at hc,
have f := (function.embedding.nonempty_of_card_le (le_of_lt hc)).some,
have C' := cn.some,
specialize h (G.recolor_of_embedding f C'),
change function.surjective (f ∘ C') at h,
have h1 : function.surjective f := function.surjective.of_comp h,
have h2 := fintype.card_le_of_surjective _ h1,
exact nat.lt_le_antisymm hc h2, },
end
lemma chromatic_number_bot [nonempty V] :
(⊥ : simple_graph V).chromatic_number = 1 :=
begin
let C : (⊥ : simple_graph V).coloring (fin 1) :=
coloring.mk (λ _, 0) (λ v w h, false.elim h),
apply le_antisymm,
{ exact chromatic_number_le_card C, },
{ exact chromatic_number_pos C.to_colorable, },
end
@[simp] lemma chromatic_number_top [fintype V] :
(⊤ : simple_graph V).chromatic_number = fintype.card V :=
begin
apply chromatic_number_eq_card_of_forall_surj (self_coloring _),
intro C,
rw ←finite.injective_iff_surjective,
intros v w,
contrapose,
intro h,
exact C.valid h,
end
lemma chromatic_number_top_eq_zero_of_infinite (V : Type*) [infinite V] :
(⊤ : simple_graph V).chromatic_number = 0 :=
begin
let n := (⊤ : simple_graph V).chromatic_number,
by_contra hc,
replace hc := pos_iff_ne_zero.mpr hc,
apply nat.not_succ_le_self n,
convert_to (⊤ : simple_graph {m | m < n + 1}).chromatic_number ≤ _,
{ simp, },
refine (colorable_of_chromatic_number_pos hc).chromatic_number_mono_of_embedding _,
apply embedding.complete_graph,
exact (function.embedding.subtype _).trans (infinite.nat_embedding V),
end
/-- The bicoloring of a complete bipartite graph using whether a vertex
is on the left or on the right. -/
def complete_bipartite_graph.bicoloring (V W : Type*) :
(complete_bipartite_graph V W).coloring bool :=
coloring.mk (λ v, v.is_right) begin
intros v w,
cases v; cases w; simp,
end
lemma complete_bipartite_graph.chromatic_number {V W : Type*} [nonempty V] [nonempty W] :
(complete_bipartite_graph V W).chromatic_number = 2 :=
begin
apply chromatic_number_eq_card_of_forall_surj (complete_bipartite_graph.bicoloring V W),
intros C b,
have v := classical.arbitrary V,
have w := classical.arbitrary W,
have h : (complete_bipartite_graph V W).adj (sum.inl v) (sum.inr w) := by simp,
have hn := C.valid h,
by_cases he : C (sum.inl v) = b,
{ exact ⟨_, he⟩ },
{ by_cases he' : C (sum.inr w) = b,
{ exact ⟨_, he'⟩ },
{ exfalso,
cases b;
simp only [eq_tt_eq_not_eq_ff, eq_ff_eq_not_eq_tt] at he he';
rw [he, he'] at hn;
contradiction }, },
end
/-! ### Cliques -/
lemma is_clique.card_le_of_coloring {s : finset V} (h : G.is_clique s)
[fintype α] (C : G.coloring α) :
s.card ≤ fintype.card α :=
begin
rw is_clique_iff_induce_eq at h,
have f : G.induce ↑s ↪g G := embedding.induce ↑s,
rw h at f,
convert fintype.card_le_of_injective _ (C.comp f.to_hom).injective_of_top_hom using 1,
simp,
end
lemma is_clique.card_le_of_colorable {s : finset V} (h : G.is_clique s)
{n : ℕ} (hc : G.colorable n) :
s.card ≤ n :=
begin
convert h.card_le_of_coloring hc.some,
simp,
end
-- TODO eliminate `finite V` constraint once chromatic numbers are refactored.
-- This is just to ensure the chromatic number exists.
lemma is_clique.card_le_chromatic_number [finite V] {s : finset V} (h : G.is_clique s) :
s.card ≤ G.chromatic_number :=
by { casesI nonempty_fintype V,
exact h.card_le_of_colorable G.colorable_chromatic_number_of_fintype }
protected
lemma colorable.clique_free {n m : ℕ} (hc : G.colorable n) (hm : n < m) : G.clique_free m :=
begin
by_contra h,
simp only [clique_free, is_n_clique_iff, not_forall, not_not] at h,
obtain ⟨s, h, rfl⟩ := h,
exact nat.lt_le_antisymm hm (h.card_le_of_colorable hc),
end
-- TODO eliminate `finite V` constraint once chromatic numbers are refactored.
-- This is just to ensure the chromatic number exists.
lemma clique_free_of_chromatic_number_lt [finite V] {n : ℕ} (hc : G.chromatic_number < n) :
G.clique_free n :=
G.colorable_chromatic_number_of_fintype.clique_free hc
end simple_graph
|
f2040f5ce39f8fac72fd92ee3cad642cb64e1d92 | b1e80085f6d9158c0b431ffc4fa9d0d53cbac8e4 | /src/contract.lean | 9fe36b27900bed5394fba6ef623345bfb5665cf3 | [] | no_license | dwarn/nielsen-schreier-2 | d73c20e4d2a8ae537fe4f8063272d0b72c58276a | e51a8c6511d374dc584698c7fa236a5be47e7dbe | refs/heads/master | 1,679,911,740,113 | 1,615,656,058,000 | 1,615,656,058,000 | 344,111,212 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,706 | lean | import free quiver misc
open_locale classical
open category_theory is_free_groupoid
universe u
variables {G : Type u} [groupoid.{u u} G] [is_free_groupoid G] [inhabited G]
(T : subquiver (symmy gpd_gens : quiver G))
def path_to_hom : Π {a : G}, (¡T).path (default G) a → ((default G) ⟶ a)
| _ quiver.path.nil := 𝟙 _
| _ (quiver.path.cons p ⟨sum.inl f, _⟩) := (path_to_hom p) ≫ (gpd_emb f)
| _ (quiver.path.cons p ⟨sum.inr f, _⟩) := (path_to_hom p) ≫ inv (gpd_emb f)
variable [is_arbor ¡T]
def favourite_hom (a : G) : (default G ⟶ a) :=
path_to_hom T (default _)
def to_End {a b : G} (p : a ⟶ b) : End (default G) :=
favourite_hom T a ≫ p ≫ inv (favourite_hom T b)
lemma favourite_hom_root : favourite_hom T (default G) = 𝟙 _ :=
begin
change path_to_hom T _ = _,
have : default ((¡T).path (default G) _) = quiver.path.nil,
{ apply unique.default_eq },
rw this, refl,
end
lemma End_to_End (p : End (default G)) : to_End T p = p :=
by {rw [to_End, favourite_hom_root], simp }
lemma to_End_eq_id {a b : G} {e : gpd_gens a b} :
(sum.inl e) ∈ T a b ∨ (sum.inr e) ∈ T b a
→ to_End T (gpd_emb e) = 𝟙 _ :=
begin
rw [to_End, ←category.assoc, is_iso.comp_inv_eq, category.id_comp,
favourite_hom, favourite_hom],
rintro (h | h),
{ set to_b : (¡T).path (default G) b :=
quiver.path.cons (default _) ⟨sum.inl e, h⟩,
have : default _ = to_b := unique.default_eq _,
rw this, refl },
{ set to_a : (¡T).path (default G) a :=
quiver.path.cons (default _) ⟨sum.inr e, h⟩,
have : default _ = to_a := unique.default_eq _,
simp only [this, path_to_hom, is_iso.inv_hom_id, category.comp_id, category.assoc] },
end
def functor_of_mul_hom {X} [group X] (f : (End (default G)) →* X) :
G ⥤ single_obj X :=
{ obj := λ _, (),
map := λ a b p, f (to_End T p),
map_id' := begin intro a, convert f.map_one, simp [to_End] end,
map_comp' := begin
intros a b c p q,
change _ = _ * _,
rw ←f.map_mul,
apply congr_arg,
simp only [to_End, is_iso.inv_hom_id_assoc, End.mul_def, category.assoc]
end }
-- an automorphism group in a free groupoid is freely generated by the
-- complement of a spanning tree.
-- conceptually, this is because
-- `(End r ⟶ X) ≃ (G ⥤ single_obj X / natural isos taking value 1 on r)`
-- `≃ functors G ⥤ single_obj X mapping spanning tree to 1 `
-- `≃ set functions on complement of spanning tree`.
def contract : is_free_group (End (default G)) :=
{ gp_gens := set.compl (tree_symmy T),
gp_emb := λ tp, to_End T (gpd_emb tp.val.edge),
gp_lift := begin
introsI X _ f,
let f' : valu gpd_gens X := λ a b e,
if h : (sum.inl e ∈ T a b ∨ sum.inr e ∈ T b a) then 1
else f ⟨⟨a, b, e⟩, h⟩,
rcases gpd_lift @f' with ⟨F, hF, uF⟩,
have F_path_to_hom : ∀ {a : G} {p : (¡T).path (default G) a},
F.map (path_to_hom T p) = 1,
{ intros a p,
induction p with b c p e ih,
{ apply F.map_id },
rcases e with ⟨e, eT⟩,
rcases e with e | e,
{ change F.map (_ ≫ _ ) = _,
rw [functor.map_comp, ih, ←hF],
change _ ≫ dite _ _ _ = _,
rw dif_pos (or.inl eT),
apply mul_one },
{ change F.map (_ ≫ inv _) = _,
rw [F.map_comp, ih, F.map_inv],
suffices : F.map (gpd_emb e) = 1,
{ rw [is_iso.comp_inv_eq, this], symmetry, apply mul_one },
rw ←hF,
change dite _ _ _ = _,
rw dif_pos (or.inr eT) } },
let ghom : (End (default G)) →* X := functor.map_End (default G) F,
have sane : functor_of_mul_hom T ghom = F,
{ apply functor.hext,
{ intro, apply unit.ext },
intros, apply heq_of_eq,
change F.map ((path_to_hom T _) ≫ _ ≫ inv (path_to_hom T _)) =
(show single_obj.star X ⟶ (), from F.map f_1),
rw [F.map_comp, F.map_comp, F.map_inv, ←category.assoc,
is_iso.comp_inv_eq, F_path_to_hom, F_path_to_hom],
change _ * _ = _ * _,
rw [mul_one, one_mul],
},
refine ⟨ghom, _, _⟩,
{ intro tp,
change f _ = (functor_of_mul_hom T ghom).map _,
rw [sane, ←hF], change f _ = dite _ _ _,
rw dif_neg,
{ apply congr_arg, ext; refl },
exact tp.property },
{ intros z zh,
have : functor_of_mul_hom T z = F,
{ apply uF, intros a b e,
change dite _ _ _ = z (to_End T _),
split_ifs,
{ rw to_End_eq_id T h, exact z.map_one.symm },
{ apply zh } },
ext,
have : (functor_of_mul_hom T z).map x = (functor_of_mul_hom T ghom).map x,
{ rw [this, sane] },
convert this; rw End_to_End },
end }
|
735f90a14bb2fb6fb3f281b2b499fabe8c495f5c | 77c5b91fae1b966ddd1db969ba37b6f0e4901e88 | /src/group_theory/p_group.lean | 9b5777106bacb3909f112b370825132c94e4f012 | [
"Apache-2.0"
] | permissive | dexmagic/mathlib | ff48eefc56e2412429b31d4fddd41a976eb287ce | 7a5d15a955a92a90e1d398b2281916b9c41270b2 | refs/heads/master | 1,693,481,322,046 | 1,633,360,193,000 | 1,633,360,193,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,495 | lean | /-
Copyright (c) 2018 . All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Thomas Browning
-/
import group_theory.index
import group_theory.perm.cycle_type
import group_theory.quotient_group
/-!
# p-groups
This file contains a proof that if `G` is a `p`-group acting on a finite set `α`,
then the number of fixed points of the action is congruent mod `p` to the cardinality of `α`.
It also contains proofs of some corollaries of this lemma about existence of fixed points.
-/
open_locale big_operators
open fintype mul_action
variables (p : ℕ) (G : Type*) [group G]
/-- A p-group is a group in which every element has prime power order -/
def is_p_group : Prop := ∀ g : G, ∃ k : ℕ, g ^ (p ^ k) = 1
variables {p} {G}
namespace is_p_group
lemma iff_order_of [hp : fact p.prime] :
is_p_group p G ↔ ∀ g : G, ∃ k : ℕ, order_of g = p ^ k :=
forall_congr (λ g, ⟨λ ⟨k, hk⟩, exists_imp_exists (by exact λ j, Exists.snd)
((nat.dvd_prime_pow hp.out).mp (order_of_dvd_of_pow_eq_one hk)),
exists_imp_exists (λ k hk, by rw [←hk, pow_order_of_eq_one])⟩)
lemma of_card [fintype G] {n : ℕ} (hG : card G = p ^ n) : is_p_group p G :=
λ g, ⟨n, by rw [←hG, pow_card_eq_one]⟩
lemma of_bot : is_p_group p (⊥ : subgroup G) :=
of_card (subgroup.card_bot.trans (pow_zero p).symm)
lemma iff_card [fact p.prime] [fintype G] :
is_p_group p G ↔ ∃ n : ℕ, card G = p ^ n :=
begin
have hG : 0 < card G := card_pos_iff.mpr has_one.nonempty,
refine ⟨λ h, _, λ ⟨n, hn⟩, of_card hn⟩,
suffices : ∀ q ∈ nat.factors (card G), q = p,
{ use (card G).factors.length,
rw [←list.prod_repeat, ←list.eq_repeat_of_mem this, nat.prod_factors hG] },
intros q hq,
obtain ⟨hq1, hq2⟩ := (nat.mem_factors hG).mp hq,
haveI : fact q.prime := ⟨hq1⟩,
obtain ⟨g, hg⟩ := equiv.perm.exists_prime_order_of_dvd_card q hq2,
obtain ⟨k, hk⟩ := (iff_order_of.mp h) g,
exact (hq1.pow_eq_iff.mp (hg.symm.trans hk).symm).1.symm,
end
section G_is_p_group
variables (hG : is_p_group p G)
include hG
lemma of_injective {H : Type*} [group H] (ϕ : H →* G) (hϕ : function.injective ϕ) :
is_p_group p H :=
begin
simp_rw [is_p_group, ←hϕ.eq_iff, ϕ.map_pow, ϕ.map_one],
exact λ h, hG (ϕ h),
end
lemma to_subgroup (H : subgroup G) : is_p_group p H :=
hG.of_injective H.subtype subtype.coe_injective
lemma of_surjective {H : Type*} [group H] (ϕ : G →* H) (hϕ : function.surjective ϕ) :
is_p_group p H :=
begin
refine λ h, exists.elim (hϕ h) (λ g hg, exists_imp_exists (λ k hk, _) (hG g)),
rw [←hg, ←ϕ.map_pow, hk, ϕ.map_one],
end
lemma to_quotient (H : subgroup G) [H.normal] :
is_p_group p (quotient_group.quotient H) :=
hG.of_surjective (quotient_group.mk' H) quotient.surjective_quotient_mk'
lemma of_equiv {H : Type*} [group H] (ϕ : G ≃* H) : is_p_group p H :=
hG.of_surjective ϕ.to_monoid_hom ϕ.surjective
variables [hp : fact p.prime]
include hp
lemma index (H : subgroup G) [fintype (quotient_group.quotient H)] :
∃ n : ℕ, H.index = p ^ n :=
begin
obtain ⟨n, hn⟩ := iff_card.mp (hG.to_quotient H.normal_core),
obtain ⟨k, hk1, hk2⟩ := (nat.dvd_prime_pow hp.out).mp ((congr_arg _
(H.normal_core.index_eq_card.trans hn)).mp (subgroup.index_dvd_of_le H.normal_core_le)),
exact ⟨k, hk2⟩,
end
variables {α : Type*} [mul_action G α]
lemma card_orbit (a : α) [fintype (orbit G a)] :
∃ n : ℕ, card (orbit G a) = p ^ n :=
begin
let ϕ := orbit_equiv_quotient_stabilizer G a,
haveI := fintype.of_equiv (orbit G a) ϕ,
rw [card_congr ϕ, ←subgroup.index_eq_card],
exact hG.index (stabilizer G a),
end
variables (α) [fintype α] [fintype (fixed_points G α)]
/-- If `G` is a `p`-group acting on a finite set `α`, then the number of fixed points
of the action is congruent mod `p` to the cardinality of `α` -/
lemma card_modeq_card_fixed_points : card α ≡ card (fixed_points G α) [MOD p] :=
begin
classical,
calc card α = card (Σ y : quotient (orbit_rel G α), {x // quotient.mk' x = y}) :
card_congr (equiv.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] : _
... = _ : by simp; refl,
rw [←zmod.eq_iff_modeq_nat p, nat.cast_sum, nat.cast_sum],
have key : ∀ x, card {y // (quotient.mk' y : quotient (orbit_rel G α)) = quotient.mk' x} =
card (orbit G x) := λ x, by simp only [quotient.eq']; congr,
refine eq.symm (finset.sum_bij_ne_zero (λ a _ _, quotient.mk' a.1) (λ _ _ _, finset.mem_univ _)
(λ a₁ a₂ _ _ _ _ h, subtype.eq ((mem_fixed_points' α).mp a₂.2 a₁.1 (quotient.exact' h)))
(λ b, quotient.induction_on' b (λ b _ hb, _)) (λ a ha _, by
{ rw [key, mem_fixed_points_iff_card_orbit_eq_one.mp a.2] })),
obtain ⟨k, hk⟩ := hG.card_orbit b,
have : k = 0 := nat.le_zero_iff.1 (nat.le_of_lt_succ (lt_of_not_ge (mt (pow_dvd_pow p)
(by rwa [pow_one, ←hk, ←nat.modeq_zero_iff_dvd, ←zmod.eq_iff_modeq_nat, ←key])))),
exact ⟨⟨b, mem_fixed_points_iff_card_orbit_eq_one.2 $ by rw [hk, this, pow_zero]⟩,
finset.mem_univ _, (ne_of_eq_of_ne nat.cast_one one_ne_zero), rfl⟩,
end
/-- If a p-group acts on `α` and the cardinality of `α` is not a multiple
of `p` then the action has a fixed point. -/
lemma nonempty_fixed_point_of_prime_not_dvd_card (hpα : ¬ p ∣ card α) :
(fixed_points G α).nonempty :=
@set.nonempty_of_nonempty_subtype _ _ begin
rw [←card_pos_iff, pos_iff_ne_zero],
contrapose! hpα,
rw [←nat.modeq_zero_iff_dvd, ←hpα],
exact hG.card_modeq_card_fixed_points α,
end
/-- If a p-group acts on `α` and the cardinality of `α` is a multiple
of `p`, and the action has one fixed point, then it has another fixed point. -/
lemma exists_fixed_point_of_prime_dvd_card_of_fixed_point
(hpα : p ∣ card α) {a : α} (ha : a ∈ fixed_points G α) :
∃ b, b ∈ fixed_points G α ∧ a ≠ b :=
have hpf : p ∣ card (fixed_points G α) :=
nat.modeq_zero_iff_dvd.mp ((hG.card_modeq_card_fixed_points α).symm.trans hpα.modeq_zero_nat),
have hα : 1 < card (fixed_points G α) :=
(fact.out p.prime).one_lt.trans_le (nat.le_of_dvd (card_pos_iff.2 ⟨⟨a, ha⟩⟩) hpf),
let ⟨⟨b, hb⟩, hba⟩ := exists_ne_of_one_lt_card hα ⟨a, ha⟩ in
⟨b, hb, λ hab, hba (by simp_rw [hab])⟩
end G_is_p_group
lemma to_le {H K : subgroup G} (hK : is_p_group p K) (hHK : H ≤ K) : is_p_group p H :=
hK.of_injective (subgroup.inclusion hHK) (λ a b h, subtype.ext (show _, from subtype.ext_iff.mp h))
lemma to_inf_left {H K : subgroup G} (hH : is_p_group p H) : is_p_group p (H ⊓ K : subgroup G) :=
hH.to_le inf_le_left
lemma to_inf_right {H K : subgroup G} (hK : is_p_group p K) : is_p_group p (H ⊓ K : subgroup G) :=
hK.to_le inf_le_right
lemma to_sup_of_normal_right {H K : subgroup G} (hH : is_p_group p H) (hK : is_p_group p K)
[K.normal] : is_p_group p (H ⊔ K : subgroup G) :=
begin
intro g,
obtain ⟨j, hj⟩ := (hH.to_quotient ((H ⊓ K).comap H.subtype)).of_equiv
(quotient_group.quotient_inf_equiv_prod_normal_quotient H K) g,
obtain ⟨k, hk⟩ := hK ⟨g ^ (p ^ j), (congr_arg (∈ K) ((H ⊔ K).coe_pow g (p ^ j))).mp
((quotient_group.eq_one_iff (g ^ (p ^ j))).mp
((quotient_group.coe_pow (K.comap (H ⊔ K).subtype) g (p ^ j)).trans hj))⟩,
rw [subtype.ext_iff, K.coe_pow, subtype.coe_mk, ←pow_mul, ←pow_add] at hk,
refine ⟨j + k, by rwa [subtype.ext_iff, (H ⊔ K).coe_pow]⟩,
end
lemma to_sup_of_normal_left {H K : subgroup G} (hH : is_p_group p H) (hK : is_p_group p K)
[H.normal] : is_p_group p (H ⊔ K : subgroup G) :=
(congr_arg (λ H : subgroup G, is_p_group p H) sup_comm).mp (to_sup_of_normal_right hK hH)
lemma to_sup_of_normal_right' {H K : subgroup G} (hH : is_p_group p H) (hK : is_p_group p K)
(hHK : H ≤ K.normalizer) : is_p_group p (H ⊔ K : subgroup G) :=
let hHK' := to_sup_of_normal_right (hH.of_equiv (subgroup.comap_subtype_equiv_of_le hHK).symm)
(hK.of_equiv (subgroup.comap_subtype_equiv_of_le subgroup.le_normalizer).symm) in
((congr_arg (λ H : subgroup K.normalizer, is_p_group p H)
(subgroup.sup_subgroup_of_eq hHK subgroup.le_normalizer)).mp hHK').of_equiv
(subgroup.comap_subtype_equiv_of_le (sup_le hHK subgroup.le_normalizer))
lemma to_sup_of_normal_left' {H K : subgroup G} (hH : is_p_group p H) (hK : is_p_group p K)
(hHK : K ≤ H.normalizer) : is_p_group p (H ⊔ K : subgroup G) :=
(congr_arg (λ H : subgroup G, is_p_group p H) sup_comm).mp (to_sup_of_normal_right' hK hH hHK)
lemma map {H : subgroup G} (hH : is_p_group p H) {K : Type*} [group K]
(ϕ : G →* K) : is_p_group p (H.map ϕ) :=
begin
rw [←H.subtype_range, monoid_hom.map_range],
exact hH.of_surjective (ϕ.restrict H).range_restrict (ϕ.restrict H).range_restrict_surjective,
end
lemma comap_injective {H : subgroup G} (hH : is_p_group p H) {K : Type*} [group K]
(ϕ : K →* G) (hϕ : function.injective ϕ) : is_p_group p (H.comap ϕ) :=
begin
refine (hH.to_le _).of_injective (ϕ.restrict (H.comap ϕ)).range_restrict _,
{ rw [monoid_hom.restrict, ←monoid_hom.map_range, subgroup.subtype_range],
exact H.map_comap_le ϕ },
{ rw [←monoid_hom.ker_eq_bot_iff, monoid_hom.range_restrict_ker, monoid_hom.ker_eq_bot_iff],
exact function.injective.comp hϕ subtype.coe_injective },
end
end is_p_group
|
2ccf694b7e64c8e31d7970435fb771f7115b00ad | 94e33a31faa76775069b071adea97e86e218a8ee | /src/topology/connected.lean | 8e4c4755dfecf5415b6b5e31d07d4f009fe12391 | [
"Apache-2.0"
] | permissive | urkud/mathlib | eab80095e1b9f1513bfb7f25b4fa82fa4fd02989 | 6379d39e6b5b279df9715f8011369a301b634e41 | refs/heads/master | 1,658,425,342,662 | 1,658,078,703,000 | 1,658,078,703,000 | 186,910,338 | 0 | 0 | Apache-2.0 | 1,568,512,083,000 | 1,557,958,709,000 | Lean | UTF-8 | Lean | false | false | 62,487 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov
-/
import data.int.succ_pred
import data.nat.succ_pred
import order.partial_sups
import order.succ_pred.relation
import topology.subset_properties
/-!
# Connected subsets of topological spaces
In this file we define connected subsets of a topological spaces and various other properties and
classes related to connectivity.
## Main definitions
We define the following properties for sets in a topological space:
* `is_connected`: a nonempty set that has no non-trivial open partition.
See also the section below in the module doc.
* `connected_component` is the connected component of an element in the space.
* `is_totally_disconnected`: all of its connected components are singletons.
* `is_totally_separated`: any two points can be separated by two disjoint opens that cover the set.
For each of these definitions, we also have a class stating that the whole space
satisfies that property:
`connected_space`, `totally_disconnected_space`, `totally_separated_space`.
## On the definition of connected sets/spaces
In informal mathematics, connected spaces are assumed to be nonempty.
We formalise the predicate without that assumption as `is_preconnected`.
In other words, the only difference is whether the empty space counts as connected.
There are good reasons to consider the empty space to be “too simple to be simple”
See also https://ncatlab.org/nlab/show/too+simple+to+be+simple,
and in particular
https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions.
-/
open set function topological_space relation
open_locale classical topological_space
universes u v
variables {α : Type u} {β : Type v} {ι : Type*} {π : ι → Type*} [topological_space α]
{s t u v : set α}
section preconnected
/-- A preconnected set is one where there is no non-trivial open partition. -/
def is_preconnected (s : set α) : Prop :=
∀ (u v : set α), is_open u → is_open v → s ⊆ u ∪ v →
(s ∩ u).nonempty → (s ∩ v).nonempty → (s ∩ (u ∩ v)).nonempty
/-- A connected set is one that is nonempty and where there is no non-trivial open partition. -/
def is_connected (s : set α) : Prop :=
s.nonempty ∧ is_preconnected s
lemma is_connected.nonempty {s : set α} (h : is_connected s) :
s.nonempty := h.1
lemma is_connected.is_preconnected {s : set α} (h : is_connected s) :
is_preconnected s := h.2
theorem is_preirreducible.is_preconnected {s : set α} (H : is_preirreducible s) :
is_preconnected s :=
λ _ _ hu hv _, H _ _ hu hv
theorem is_irreducible.is_connected {s : set α} (H : is_irreducible s) : is_connected s :=
⟨H.nonempty, H.is_preirreducible.is_preconnected⟩
theorem is_preconnected_empty : is_preconnected (∅ : set α) :=
is_preirreducible_empty.is_preconnected
theorem is_connected_singleton {x} : is_connected ({x} : set α) :=
is_irreducible_singleton.is_connected
theorem is_preconnected_singleton {x} : is_preconnected ({x} : set α) :=
is_connected_singleton.is_preconnected
theorem set.subsingleton.is_preconnected {s : set α} (hs : s.subsingleton) :
is_preconnected s :=
hs.induction_on is_preconnected_empty (λ x, is_preconnected_singleton)
/-- If any point of a set is joined to a fixed point by a preconnected subset,
then the original set is preconnected as well. -/
theorem is_preconnected_of_forall {s : set α} (x : α)
(H : ∀ y ∈ s, ∃ t ⊆ s, x ∈ t ∧ y ∈ t ∧ is_preconnected t) :
is_preconnected s :=
begin
rintros u v hu hv hs ⟨z, zs, zu⟩ ⟨y, ys, yv⟩,
have xs : x ∈ s, by { rcases H y ys with ⟨t, ts, xt, yt, ht⟩, exact ts xt },
wlog xu : x ∈ u := hs xs using [u v y z, v u z y],
rcases H y ys with ⟨t, ts, xt, yt, ht⟩,
have := ht u v hu hv(subset.trans ts hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩,
exact this.imp (λ z hz, ⟨ts hz.1, hz.2⟩)
end
/-- If any two points of a set are contained in a preconnected subset,
then the original set is preconnected as well. -/
theorem is_preconnected_of_forall_pair {s : set α}
(H : ∀ x y ∈ s, ∃ t ⊆ s, x ∈ t ∧ y ∈ t ∧ is_preconnected t) :
is_preconnected s :=
begin
rcases eq_empty_or_nonempty s with (rfl|⟨x, hx⟩),
exacts [is_preconnected_empty, is_preconnected_of_forall x $ λ y, H x hx y],
end
/-- A union of a family of preconnected sets with a common point is preconnected as well. -/
theorem is_preconnected_sUnion (x : α) (c : set (set α)) (H1 : ∀ s ∈ c, x ∈ s)
(H2 : ∀ s ∈ c, is_preconnected s) : is_preconnected (⋃₀ c) :=
begin
apply is_preconnected_of_forall x,
rintros y ⟨s, sc, ys⟩,
exact ⟨s, subset_sUnion_of_mem sc, H1 s sc, ys, H2 s sc⟩
end
theorem is_preconnected_Union {ι : Sort*} {s : ι → set α} (h₁ : (⋂ i, s i).nonempty)
(h₂ : ∀ i, is_preconnected (s i)) :
is_preconnected (⋃ i, s i) :=
exists.elim h₁ $ λ f hf, is_preconnected_sUnion f _ hf (forall_range_iff.2 h₂)
theorem is_preconnected.union (x : α) {s t : set α} (H1 : x ∈ s) (H2 : x ∈ t)
(H3 : is_preconnected s) (H4 : is_preconnected t) : is_preconnected (s ∪ t) :=
sUnion_pair s t ▸ is_preconnected_sUnion x {s, t}
(by rintro r (rfl | rfl | h); assumption)
(by rintro r (rfl | rfl | h); assumption)
theorem is_preconnected.union' {s t : set α} (H : (s ∩ t).nonempty)
(hs : is_preconnected s) (ht : is_preconnected t) : is_preconnected (s ∪ t) :=
by { rcases H with ⟨x, hxs, hxt⟩, exact hs.union x hxs hxt ht }
theorem is_connected.union {s t : set α} (H : (s ∩ t).nonempty)
(Hs : is_connected s) (Ht : is_connected t) : is_connected (s ∪ t) :=
begin
rcases H with ⟨x, hx⟩,
refine ⟨⟨x, mem_union_left t (mem_of_mem_inter_left hx)⟩, _⟩,
exact is_preconnected.union x (mem_of_mem_inter_left hx) (mem_of_mem_inter_right hx)
Hs.is_preconnected Ht.is_preconnected
end
/-- The directed sUnion of a set S of preconnected subsets is preconnected. -/
theorem is_preconnected.sUnion_directed {S : set (set α)}
(K : directed_on (⊆) S)
(H : ∀ s ∈ S, is_preconnected s) : is_preconnected (⋃₀ S) :=
begin
rintros u v hu hv Huv ⟨a, ⟨s, hsS, has⟩, hau⟩ ⟨b, ⟨t, htS, hbt⟩, hbv⟩,
obtain ⟨r, hrS, hsr, htr⟩ : ∃ r ∈ S, s ⊆ r ∧ t ⊆ r := K s hsS t htS,
have Hnuv : (r ∩ (u ∩ v)).nonempty,
from H _ hrS u v hu hv ((subset_sUnion_of_mem hrS).trans Huv)
⟨a, hsr has, hau⟩ ⟨b, htr hbt, hbv⟩,
have Kruv : r ∩ (u ∩ v) ⊆ ⋃₀ S ∩ (u ∩ v),
from inter_subset_inter_left _ (subset_sUnion_of_mem hrS),
exact Hnuv.mono Kruv
end
/-- The bUnion of a family of preconnected sets is preconnected if the graph determined by
whether two sets intersect is preconnected. -/
theorem is_preconnected.bUnion_of_refl_trans_gen {ι : Type*} {t : set ι} {s : ι → set α}
(H : ∀ i ∈ t, is_preconnected (s i))
(K : ∀ i j ∈ t, refl_trans_gen (λ i j : ι, (s i ∩ s j).nonempty ∧ i ∈ t) i j) :
is_preconnected (⋃ n ∈ t, s n) :=
begin
let R := λ i j : ι, (s i ∩ s j).nonempty ∧ i ∈ t,
have P : ∀ (i j ∈ t), refl_trans_gen R i j →
∃ (p ⊆ t), i ∈ p ∧ j ∈ p ∧ is_preconnected (⋃ j ∈ p, s j),
{ intros i hi j hj h,
induction h,
case refl
{ refine ⟨{i}, singleton_subset_iff.mpr hi, mem_singleton i, mem_singleton i, _⟩,
rw [bUnion_singleton],
exact H i hi },
case tail : j k hij hjk ih
{ obtain ⟨p, hpt, hip, hjp, hp⟩ := ih hjk.2,
refine ⟨insert k p, insert_subset.mpr ⟨hj, hpt⟩, mem_insert_of_mem k hip, mem_insert k p, _⟩,
rw [bUnion_insert],
refine (H k hj).union' _ hp,
refine hjk.1.mono _,
rw [inter_comm],
refine inter_subset_inter subset.rfl (subset_bUnion_of_mem hjp) } },
refine is_preconnected_of_forall_pair _,
intros x hx y hy,
obtain ⟨i: ι, hi : i ∈ t, hxi : x ∈ s i⟩ := mem_Union₂.1 hx,
obtain ⟨j: ι, hj : j ∈ t, hyj : y ∈ s j⟩ := mem_Union₂.1 hy,
obtain ⟨p, hpt, hip, hjp, hp⟩ := P i hi j hj (K i hi j hj),
exact ⟨⋃ j ∈ p, s j, bUnion_subset_bUnion_left hpt, mem_bUnion hip hxi, mem_bUnion hjp hyj, hp⟩
end
/-- The bUnion of a family of preconnected sets is preconnected if the graph determined by
whether two sets intersect is preconnected. -/
theorem is_connected.bUnion_of_refl_trans_gen {ι : Type*} {t : set ι} {s : ι → set α}
(ht : t.nonempty)
(H : ∀ i ∈ t, is_connected (s i))
(K : ∀ i j ∈ t, refl_trans_gen (λ i j : ι, (s i ∩ s j).nonempty ∧ i ∈ t) i j) :
is_connected (⋃ n ∈ t, s n) :=
⟨nonempty_bUnion.2 $ ⟨ht.some, ht.some_mem, (H _ ht.some_mem).nonempty⟩,
is_preconnected.bUnion_of_refl_trans_gen (λ i hi, (H i hi).is_preconnected) K⟩
/-- Preconnectedness of the Union of a family of preconnected sets
indexed by the vertices of a preconnected graph,
where two vertices are joined when the corresponding sets intersect. -/
theorem is_preconnected.Union_of_refl_trans_gen {ι : Type*} {s : ι → set α}
(H : ∀ i, is_preconnected (s i))
(K : ∀ i j, refl_trans_gen (λ i j : ι, (s i ∩ s j).nonempty) i j) :
is_preconnected (⋃ n, s n) :=
by { rw [← bUnion_univ], exact is_preconnected.bUnion_of_refl_trans_gen (λ i _, H i)
(λ i _ j _, by simpa [mem_univ] using K i j) }
theorem is_connected.Union_of_refl_trans_gen {ι : Type*} [nonempty ι] {s : ι → set α}
(H : ∀ i, is_connected (s i))
(K : ∀ i j, refl_trans_gen (λ i j : ι, (s i ∩ s j).nonempty) i j) :
is_connected (⋃ n, s n) :=
⟨nonempty_Union.2 $ nonempty.elim ‹_› $ λ i : ι, ⟨i, (H _).nonempty⟩,
is_preconnected.Union_of_refl_trans_gen (λ i, (H i).is_preconnected) K⟩
section succ_order
open order
variables [linear_order β] [succ_order β] [is_succ_archimedean β]
/-- The Union of connected sets indexed by a type with an archimedean successor (like `ℕ` or `ℤ`)
such that any two neighboring sets meet is preconnected. -/
theorem is_preconnected.Union_of_chain {s : β → set α}
(H : ∀ n, is_preconnected (s n))
(K : ∀ n, (s n ∩ s (succ n)).nonempty) :
is_preconnected (⋃ n, s n) :=
is_preconnected.Union_of_refl_trans_gen H $
λ i j, refl_trans_gen_of_succ _ (λ i _, K i) $ λ i _, by { rw inter_comm, exact K i }
/-- The Union of connected sets indexed by a type with an archimedean successor (like `ℕ` or `ℤ`)
such that any two neighboring sets meet is connected. -/
theorem is_connected.Union_of_chain [nonempty β] {s : β → set α}
(H : ∀ n, is_connected (s n))
(K : ∀ n, (s n ∩ s (succ n)).nonempty) :
is_connected (⋃ n, s n) :=
is_connected.Union_of_refl_trans_gen H $
λ i j, refl_trans_gen_of_succ _ (λ i _, K i) $ λ i _, by { rw inter_comm, exact K i }
/-- The Union of preconnected sets indexed by a subset of a type with an archimedean successor
(like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/
theorem is_preconnected.bUnion_of_chain
{s : β → set α} {t : set β} (ht : ord_connected t)
(H : ∀ n ∈ t, is_preconnected (s n))
(K : ∀ n : β, n ∈ t → succ n ∈ t → (s n ∩ s (succ n)).nonempty) :
is_preconnected (⋃ n ∈ t, s n) :=
begin
have h1 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → k ∈ t :=
λ i j k hi hj hk, ht.out hi hj (Ico_subset_Icc_self hk),
have h2 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → succ k ∈ t := λ i j k hi hj hk,
ht.out hi hj ⟨hk.1.trans $ le_succ k, succ_le_of_lt hk.2⟩,
have h3 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → (s k ∩ s (succ k)).nonempty :=
λ i j k hi hj hk, K _ (h1 hi hj hk) (h2 hi hj hk),
refine is_preconnected.bUnion_of_refl_trans_gen H (λ i hi j hj, _),
exact refl_trans_gen_of_succ _ (λ k hk, ⟨h3 hi hj hk, h1 hi hj hk⟩)
(λ k hk, ⟨by { rw [inter_comm], exact h3 hj hi hk }, h2 hj hi hk⟩),
end
/-- The Union of connected sets indexed by a subset of a type with an archimedean successor
(like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/
theorem is_connected.bUnion_of_chain
{s : β → set α} {t : set β} (hnt : t.nonempty) (ht : ord_connected t)
(H : ∀ n ∈ t, is_connected (s n))
(K : ∀ n : β, n ∈ t → succ n ∈ t → (s n ∩ s (succ n)).nonempty) :
is_connected (⋃ n ∈ t, s n) :=
⟨nonempty_bUnion.2 $ ⟨hnt.some, hnt.some_mem, (H _ hnt.some_mem).nonempty⟩,
is_preconnected.bUnion_of_chain ht (λ i hi, (H i hi).is_preconnected) K⟩
end succ_order
/-- Theorem of bark and tree :
if a set is within a (pre)connected set and its closure,
then it is (pre)connected as well. -/
theorem is_preconnected.subset_closure {s : set α} {t : set α}
(H : is_preconnected s) (Kst : s ⊆ t) (Ktcs : t ⊆ closure s) :
is_preconnected t :=
λ u v hu hv htuv ⟨y, hyt, hyu⟩ ⟨z, hzt, hzv⟩,
let ⟨p, hpu, hps⟩ := mem_closure_iff.1 (Ktcs hyt) u hu hyu,
⟨q, hqv, hqs⟩ := mem_closure_iff.1 (Ktcs hzt) v hv hzv,
⟨r, hrs, hruv⟩ := H u v hu hv (subset.trans Kst htuv) ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ in
⟨r, Kst hrs, hruv⟩
theorem is_connected.subset_closure {s : set α} {t : set α}
(H : is_connected s) (Kst : s ⊆ t) (Ktcs : t ⊆ closure s): is_connected t :=
let hsne := H.left,
ht := Kst,
htne := nonempty.mono ht hsne in
⟨nonempty.mono Kst H.left, is_preconnected.subset_closure H.right Kst Ktcs ⟩
/-- The closure of a (pre)connected set is (pre)connected as well. -/
theorem is_preconnected.closure {s : set α} (H : is_preconnected s) :
is_preconnected (closure s) :=
is_preconnected.subset_closure H subset_closure $ subset.refl $ closure s
theorem is_connected.closure {s : set α} (H : is_connected s) :
is_connected (closure s) :=
is_connected.subset_closure H subset_closure $ subset.refl $ closure s
/-- The image of a (pre)connected set is (pre)connected as well. -/
theorem is_preconnected.image [topological_space β] {s : set α} (H : is_preconnected s)
(f : α → β) (hf : continuous_on f s) : is_preconnected (f '' s) :=
begin
-- Unfold/destruct definitions in hypotheses
rintros u v hu hv huv ⟨_, ⟨x, xs, rfl⟩, xu⟩ ⟨_, ⟨y, ys, rfl⟩, yv⟩,
rcases continuous_on_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩,
rcases continuous_on_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩,
-- Reformulate `huv : f '' s ⊆ u ∪ v` in terms of `u'` and `v'`
replace huv : s ⊆ u' ∪ v',
{ rw [image_subset_iff, preimage_union] at huv,
replace huv := subset_inter huv (subset.refl _),
rw [inter_distrib_right, u'_eq, v'_eq, ← inter_distrib_right] at huv,
exact (subset_inter_iff.1 huv).1 },
-- Now `s ⊆ u' ∪ v'`, so we can apply `‹is_preconnected s›`
obtain ⟨z, hz⟩ : (s ∩ (u' ∩ v')).nonempty,
{ refine H u' v' hu' hv' huv ⟨x, _⟩ ⟨y, _⟩; rw inter_comm,
exacts [u'_eq ▸ ⟨xu, xs⟩, v'_eq ▸ ⟨yv, ys⟩] },
rw [← inter_self s, inter_assoc, inter_left_comm s u', ← inter_assoc,
inter_comm s, inter_comm s, ← u'_eq, ← v'_eq] at hz,
exact ⟨f z, ⟨z, hz.1.2, rfl⟩, hz.1.1, hz.2.1⟩
end
theorem is_connected.image [topological_space β] {s : set α} (H : is_connected s)
(f : α → β) (hf : continuous_on f s) : is_connected (f '' s) :=
⟨nonempty_image_iff.mpr H.nonempty, H.is_preconnected.image f hf⟩
theorem is_preconnected_closed_iff {s : set α} :
is_preconnected s ↔ ∀ t t', is_closed t → is_closed t' → s ⊆ t ∪ t' →
(s ∩ t).nonempty → (s ∩ t').nonempty → (s ∩ (t ∩ t')).nonempty :=
⟨begin
rintros h t t' ht ht' htt' ⟨x, xs, xt⟩ ⟨y, ys, yt'⟩,
rw [←not_disjoint_iff_nonempty_inter, ←subset_compl_iff_disjoint_right, compl_inter],
intros h',
have xt' : x ∉ t', from (h' xs).resolve_left (absurd xt),
have yt : y ∉ t, from (h' ys).resolve_right (absurd yt'),
have := h _ _ ht.is_open_compl ht'.is_open_compl h' ⟨y, ys, yt⟩ ⟨x, xs, xt'⟩,
rw ←compl_union at this,
exact this.ne_empty htt'.disjoint_compl_right.inter_eq,
end,
begin
rintros h u v hu hv huv ⟨x, xs, xu⟩ ⟨y, ys, yv⟩,
rw [←not_disjoint_iff_nonempty_inter, ←subset_compl_iff_disjoint_right, compl_inter],
intros h',
have xv : x ∉ v, from (h' xs).elim (absurd xu) id,
have yu : y ∉ u, from (h' ys).elim id (absurd yv),
have := h _ _ hu.is_closed_compl hv.is_closed_compl h' ⟨y, ys, yu⟩ ⟨x, xs, xv⟩,
rw ←compl_union at this,
exact this.ne_empty huv.disjoint_compl_right.inter_eq,
end⟩
lemma inducing.is_preconnected_image [topological_space β] {s : set α} {f : α → β}
(hf : inducing f) : is_preconnected (f '' s) ↔ is_preconnected s :=
begin
refine ⟨λ h, _, λ h, h.image _ hf.continuous.continuous_on⟩,
rintro u v hu' hv' huv ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩,
rcases hf.is_open_iff.1 hu' with ⟨u, hu, rfl⟩,
rcases hf.is_open_iff.1 hv' with ⟨v, hv, rfl⟩,
replace huv : f '' s ⊆ u ∪ v, by rwa image_subset_iff,
rcases h u v hu hv huv ⟨f x, mem_image_of_mem _ hxs, hxu⟩ ⟨f y, mem_image_of_mem _ hys, hyv⟩
with ⟨_, ⟨z, hzs, rfl⟩, hzuv⟩,
exact ⟨z, hzs, hzuv⟩
end
/- TODO: The following lemmas about connection of preimages hold more generally for strict maps
(the quotient and subspace topologies of the image agree) whose fibers are preconnected. -/
lemma is_preconnected.preimage_of_open_map [topological_space β] {s : set β}
(hs : is_preconnected s) {f : α → β} (hinj : function.injective f) (hf : is_open_map f)
(hsf : s ⊆ range f) :
is_preconnected (f ⁻¹' s) :=
λ u v hu hv hsuv hsu hsv,
begin
obtain ⟨b, hbs, hbu, hbv⟩ := hs (f '' u) (f '' v) (hf u hu) (hf v hv) _ _ _,
obtain ⟨a, rfl⟩ := hsf hbs,
rw hinj.mem_set_image at hbu hbv,
exact ⟨a, hbs, hbu, hbv⟩,
{ have := image_subset f hsuv,
rwa [set.image_preimage_eq_of_subset hsf, image_union] at this },
{ obtain ⟨x, hx1, hx2⟩ := hsu,
exact ⟨f x, hx1, x, hx2, rfl⟩ },
{ obtain ⟨y, hy1, hy2⟩ := hsv,
exact ⟨f y, hy1, y, hy2, rfl⟩ }
end
lemma is_preconnected.preimage_of_closed_map [topological_space β] {s : set β}
(hs : is_preconnected s) {f : α → β} (hinj : function.injective f) (hf : is_closed_map f)
(hsf : s ⊆ range f) :
is_preconnected (f ⁻¹' s) :=
is_preconnected_closed_iff.2 $ λ u v hu hv hsuv hsu hsv,
begin
obtain ⟨b, hbs, hbu, hbv⟩ :=
is_preconnected_closed_iff.1 hs (f '' u) (f '' v) (hf u hu) (hf v hv) _ _ _,
obtain ⟨a, rfl⟩ := hsf hbs,
rw hinj.mem_set_image at hbu hbv,
exact ⟨a, hbs, hbu, hbv⟩,
{ have := image_subset f hsuv,
rwa [set.image_preimage_eq_of_subset hsf, image_union] at this },
{ obtain ⟨x, hx1, hx2⟩ := hsu,
exact ⟨f x, hx1, x, hx2, rfl⟩ },
{ obtain ⟨y, hy1, hy2⟩ := hsv,
exact ⟨f y, hy1, y, hy2, rfl⟩ }
end
lemma is_connected.preimage_of_open_map [topological_space β] {s : set β} (hs : is_connected s)
{f : α → β} (hinj : function.injective f) (hf : is_open_map f) (hsf : s ⊆ range f) :
is_connected (f ⁻¹' s) :=
⟨hs.nonempty.preimage' hsf, hs.is_preconnected.preimage_of_open_map hinj hf hsf⟩
lemma is_connected.preimage_of_closed_map [topological_space β] {s : set β} (hs : is_connected s)
{f : α → β} (hinj : function.injective f) (hf : is_closed_map f) (hsf : s ⊆ range f) :
is_connected (f ⁻¹' s) :=
⟨hs.nonempty.preimage' hsf, hs.is_preconnected.preimage_of_closed_map hinj hf hsf⟩
lemma is_preconnected.subset_or_subset (hu : is_open u) (hv : is_open v) (huv : disjoint u v)
(hsuv : s ⊆ u ∪ v) (hs : is_preconnected s) :
s ⊆ u ∨ s ⊆ v :=
begin
specialize hs u v hu hv hsuv,
obtain hsu | hsu := (s ∩ u).eq_empty_or_nonempty,
{ exact or.inr ((set.disjoint_iff_inter_eq_empty.2 hsu).subset_right_of_subset_union hsuv) },
{ replace hs := mt (hs hsu),
simp_rw [set.not_nonempty_iff_eq_empty, ←set.disjoint_iff_inter_eq_empty,
disjoint_iff_inter_eq_empty.1 huv] at hs,
exact or.inl ((hs s.disjoint_empty).subset_left_of_subset_union hsuv) }
end
lemma is_preconnected.subset_left_of_subset_union (hu : is_open u) (hv : is_open v)
(huv : disjoint u v) (hsuv : s ⊆ u ∪ v) (hsu : (s ∩ u).nonempty) (hs : is_preconnected s) :
s ⊆ u :=
disjoint.subset_left_of_subset_union hsuv
begin
by_contra hsv,
rw not_disjoint_iff_nonempty_inter at hsv,
obtain ⟨x, _, hx⟩ := hs u v hu hv hsuv hsu hsv,
exact set.disjoint_iff.1 huv hx,
end
lemma is_preconnected.subset_right_of_subset_union (hu : is_open u) (hv : is_open v)
(huv : disjoint u v) (hsuv : s ⊆ u ∪ v) (hsv : (s ∩ v).nonempty) (hs : is_preconnected s) :
s ⊆ v :=
hs.subset_left_of_subset_union hv hu huv.symm (union_comm u v ▸ hsuv) hsv
theorem is_preconnected.prod [topological_space β] {s : set α} {t : set β}
(hs : is_preconnected s) (ht : is_preconnected t) :
is_preconnected (s ×ˢ t) :=
begin
apply is_preconnected_of_forall_pair,
rintro ⟨a₁, b₁⟩ ⟨ha₁, hb₁⟩ ⟨a₂, b₂⟩ ⟨ha₂, hb₂⟩,
refine ⟨prod.mk a₁ '' t ∪ flip prod.mk b₂ '' s, _,
or.inl ⟨b₁, hb₁, rfl⟩, or.inr ⟨a₂, ha₂, rfl⟩, _⟩,
{ rintro _ (⟨y, hy, rfl⟩|⟨x, hx, rfl⟩),
exacts [⟨ha₁, hy⟩, ⟨hx, hb₂⟩] },
{ exact (ht.image _ (continuous.prod.mk _).continuous_on).union (a₁, b₂) ⟨b₂, hb₂, rfl⟩
⟨a₁, ha₁, rfl⟩ (hs.image _ (continuous_id.prod_mk continuous_const).continuous_on) }
end
theorem is_connected.prod [topological_space β] {s : set α} {t : set β}
(hs : is_connected s) (ht : is_connected t) : is_connected (s ×ˢ t) :=
⟨hs.1.prod ht.1, hs.2.prod ht.2⟩
theorem is_preconnected_univ_pi [Π i, topological_space (π i)] {s : Π i, set (π i)}
(hs : ∀ i, is_preconnected (s i)) :
is_preconnected (pi univ s) :=
begin
rintros u v uo vo hsuv ⟨f, hfs, hfu⟩ ⟨g, hgs, hgv⟩,
rcases exists_finset_piecewise_mem_of_mem_nhds (uo.mem_nhds hfu) g with ⟨I, hI⟩,
induction I using finset.induction_on with i I hi ihI,
{ refine ⟨g, hgs, ⟨_, hgv⟩⟩, simpa using hI },
{ rw [finset.piecewise_insert] at hI,
have := I.piecewise_mem_set_pi hfs hgs,
refine (hsuv this).elim ihI (λ h, _),
set S := update (I.piecewise f g) i '' (s i),
have hsub : S ⊆ pi univ s,
{ refine image_subset_iff.2 (λ z hz, _),
rwa update_preimage_univ_pi,
exact λ j hj, this j trivial },
have hconn : is_preconnected S,
from (hs i).image _ (continuous_const.update i continuous_id).continuous_on,
have hSu : (S ∩ u).nonempty,
from ⟨_, mem_image_of_mem _ (hfs _ trivial), hI⟩,
have hSv : (S ∩ v).nonempty,
from ⟨_, ⟨_, this _ trivial, update_eq_self _ _⟩, h⟩,
refine (hconn u v uo vo (hsub.trans hsuv) hSu hSv).mono _,
exact inter_subset_inter_left _ hsub }
end
@[simp] theorem is_connected_univ_pi [Π i, topological_space (π i)] {s : Π i, set (π i)} :
is_connected (pi univ s) ↔ ∀ i, is_connected (s i) :=
begin
simp only [is_connected, ← univ_pi_nonempty_iff, forall_and_distrib, and.congr_right_iff],
refine λ hne, ⟨λ hc i, _, is_preconnected_univ_pi⟩,
rw [← eval_image_univ_pi hne],
exact hc.image _ (continuous_apply _).continuous_on
end
lemma sigma.is_connected_iff [Π i, topological_space (π i)] {s : set (Σ i, π i)} :
is_connected s ↔ ∃ i t, is_connected t ∧ s = sigma.mk i '' t :=
begin
refine ⟨λ hs, _, _⟩,
{ obtain ⟨⟨i, x⟩, hx⟩ := hs.nonempty,
have : s ⊆ range (sigma.mk i),
{ have h : range (sigma.mk i) = sigma.fst ⁻¹' {i}, by { ext, simp },
rw h,
exact is_preconnected.subset_left_of_subset_union
(is_open_sigma_fst_preimage _) (is_open_sigma_fst_preimage {x | x ≠ i})
(set.disjoint_iff.2 $ λ x hx, hx.2 hx.1)
(λ y hy, by simp [classical.em]) ⟨⟨i, x⟩, hx, rfl⟩ hs.2 },
exact ⟨i, sigma.mk i ⁻¹' s,
hs.preimage_of_open_map sigma_mk_injective is_open_map_sigma_mk this,
(set.image_preimage_eq_of_subset this).symm⟩ },
{ rintro ⟨i, t, ht, rfl⟩,
exact ht.image _ continuous_sigma_mk.continuous_on }
end
lemma sigma.is_preconnected_iff [hι : nonempty ι] [Π i, topological_space (π i)]
{s : set (Σ i, π i)} :
is_preconnected s ↔ ∃ i t, is_preconnected t ∧ s = sigma.mk i '' t :=
begin
refine ⟨λ hs, _, _⟩,
{ obtain rfl | h := s.eq_empty_or_nonempty,
{ exact ⟨classical.choice hι, ∅, is_preconnected_empty, (set.image_empty _).symm⟩ },
{ obtain ⟨a, t, ht, rfl⟩ := sigma.is_connected_iff.1 ⟨h, hs⟩,
refine ⟨a, t, ht.is_preconnected, rfl⟩ } },
{ rintro ⟨a, t, ht, rfl⟩,
exact ht.image _ continuous_sigma_mk.continuous_on }
end
lemma sum.is_connected_iff [topological_space β] {s : set (α ⊕ β)} :
is_connected s ↔
(∃ t, is_connected t ∧ s = sum.inl '' t) ∨ ∃ t, is_connected t ∧ s = sum.inr '' t :=
begin
refine ⟨λ hs, _, _⟩,
{ let u : set (α ⊕ β):= range sum.inl,
let v : set (α ⊕ β) := range sum.inr,
have hu : is_open u, exact is_open_range_inl,
obtain ⟨x | x, hx⟩ := hs.nonempty,
{ have h := is_preconnected.subset_left_of_subset_union
is_open_range_inl is_open_range_inr is_compl_range_inl_range_inr.disjoint
(show s ⊆ range sum.inl ∪ range sum.inr, by simp) ⟨sum.inl x, hx, x, rfl⟩ hs.2,
refine or.inl ⟨sum.inl ⁻¹' s, _, _⟩,
{ exact hs.preimage_of_open_map sum.inl_injective open_embedding_inl.is_open_map h },
{ exact (set.image_preimage_eq_of_subset h).symm } },
{ have h := is_preconnected.subset_right_of_subset_union
is_open_range_inl is_open_range_inr is_compl_range_inl_range_inr.disjoint
(show s ⊆ range sum.inl ∪ range sum.inr, by simp) ⟨sum.inr x, hx, x, rfl⟩ hs.2,
refine or.inr ⟨sum.inr ⁻¹' s, _, _⟩,
{ exact hs.preimage_of_open_map sum.inr_injective open_embedding_inr.is_open_map h },
{ exact (set.image_preimage_eq_of_subset h).symm } } },
{ rintro (⟨t, ht, rfl⟩ | ⟨t, ht, rfl⟩),
{ exact ht.image _ continuous_inl.continuous_on },
{ exact ht.image _ continuous_inr.continuous_on } }
end
lemma sum.is_preconnected_iff [topological_space β] {s : set (α ⊕ β)} :
is_preconnected s ↔
(∃ t, is_preconnected t ∧ s = sum.inl '' t) ∨ ∃ t, is_preconnected t ∧ s = sum.inr '' t :=
begin
refine ⟨λ hs, _, _⟩,
{ obtain rfl | h := s.eq_empty_or_nonempty,
{ exact or.inl ⟨∅, is_preconnected_empty, (set.image_empty _).symm⟩ },
obtain ⟨t, ht, rfl⟩ | ⟨t, ht, rfl⟩ := sum.is_connected_iff.1 ⟨h, hs⟩,
{ exact or.inl ⟨t, ht.is_preconnected, rfl⟩ },
{ exact or.inr ⟨t, ht.is_preconnected, rfl⟩ } },
{ rintro (⟨t, ht, rfl⟩ | ⟨t, ht, rfl⟩),
{ exact ht.image _ continuous_inl.continuous_on },
{ exact ht.image _ continuous_inr.continuous_on } }
end
/-- The connected component of a point is the maximal connected set
that contains this point. -/
def connected_component (x : α) : set α :=
⋃₀ { s : set α | is_preconnected s ∧ x ∈ s }
/-- The connected component of a point inside a set. -/
def connected_component_in (F : set α) (x : F) : set α := coe '' (connected_component x)
theorem mem_connected_component {x : α} : x ∈ connected_component x :=
mem_sUnion_of_mem (mem_singleton x) ⟨is_connected_singleton.is_preconnected, mem_singleton x⟩
theorem is_preconnected_connected_component {x : α} : is_preconnected (connected_component x) :=
is_preconnected_sUnion x _ (λ _, and.right) (λ _, and.left)
theorem is_connected_connected_component {x : α} : is_connected (connected_component x) :=
⟨⟨x, mem_connected_component⟩, is_preconnected_connected_component⟩
theorem is_preconnected.subset_connected_component {x : α} {s : set α}
(H1 : is_preconnected s) (H2 : x ∈ s) : s ⊆ connected_component x :=
λ z hz, mem_sUnion_of_mem hz ⟨H1, H2⟩
theorem is_connected.subset_connected_component {x : α} {s : set α}
(H1 : is_connected s) (H2 : x ∈ s) : s ⊆ connected_component x :=
H1.2.subset_connected_component H2
theorem connected_component_eq {x y : α} (h : y ∈ connected_component x) :
connected_component x = connected_component y :=
eq_of_subset_of_subset
(is_connected_connected_component.subset_connected_component h)
(is_connected_connected_component.subset_connected_component
(set.mem_of_mem_of_subset mem_connected_component
(is_connected_connected_component.subset_connected_component h)))
lemma connected_component_disjoint {x y : α} (h : connected_component x ≠ connected_component y) :
disjoint (connected_component x) (connected_component y) :=
set.disjoint_left.2 (λ a h1 h2, h
((connected_component_eq h1).trans (connected_component_eq h2).symm))
theorem is_closed_connected_component {x : α} :
is_closed (connected_component x) :=
closure_eq_iff_is_closed.1 $ subset.antisymm
(is_connected_connected_component.closure.subset_connected_component
(subset_closure mem_connected_component))
subset_closure
lemma continuous.image_connected_component_subset [topological_space β] {f : α → β}
(h : continuous f) (a : α) : f '' connected_component a ⊆ connected_component (f a) :=
(is_connected_connected_component.image f h.continuous_on).subset_connected_component
((mem_image f (connected_component a) (f a)).2 ⟨a, mem_connected_component, rfl⟩)
lemma continuous.maps_to_connected_component [topological_space β] {f : α → β}
(h : continuous f) (a : α) : maps_to f (connected_component a) (connected_component (f a)) :=
maps_to'.2 $ h.image_connected_component_subset a
theorem irreducible_component_subset_connected_component {x : α} :
irreducible_component x ⊆ connected_component x :=
is_irreducible_irreducible_component.is_connected.subset_connected_component
mem_irreducible_component
/-- A preconnected space is one where there is no non-trivial open partition. -/
class preconnected_space (α : Type u) [topological_space α] : Prop :=
(is_preconnected_univ : is_preconnected (univ : set α))
export preconnected_space (is_preconnected_univ)
/-- A connected space is a nonempty one where there is no non-trivial open partition. -/
class connected_space (α : Type u) [topological_space α] extends preconnected_space α : Prop :=
(to_nonempty : nonempty α)
attribute [instance, priority 50] connected_space.to_nonempty -- see Note [lower instance priority]
lemma is_connected_univ [connected_space α] : is_connected (univ : set α) :=
⟨univ_nonempty, is_preconnected_univ⟩
lemma is_preconnected_range [topological_space β] [preconnected_space α] {f : α → β}
(h : continuous f) : is_preconnected (range f) :=
@image_univ _ _ f ▸ is_preconnected_univ.image _ h.continuous_on
lemma is_connected_range [topological_space β] [connected_space α] {f : α → β} (h : continuous f) :
is_connected (range f) :=
⟨range_nonempty f, is_preconnected_range h⟩
lemma dense_range.preconnected_space [topological_space β] [preconnected_space α] {f : α → β}
(hf : dense_range f) (hc : continuous f) :
preconnected_space β :=
⟨hf.closure_eq ▸ (is_preconnected_range hc).closure⟩
lemma connected_space_iff_connected_component :
connected_space α ↔ ∃ x : α, connected_component x = univ :=
begin
split,
{ rintros ⟨h, ⟨x⟩⟩,
exactI ⟨x, eq_univ_of_univ_subset $
is_preconnected_univ.subset_connected_component (mem_univ x)⟩ },
{ rintros ⟨x, h⟩,
haveI : preconnected_space α := ⟨by { rw ← h, exact is_preconnected_connected_component }⟩,
exact ⟨⟨x⟩⟩ }
end
lemma preconnected_space_iff_connected_component :
preconnected_space α ↔ ∀ x : α, connected_component x = univ :=
begin
split,
{ intros h x,
exactI (eq_univ_of_univ_subset $
is_preconnected_univ.subset_connected_component (mem_univ x)) },
{ intros h,
casesI is_empty_or_nonempty α with hα hα,
{ exact ⟨by { rw (univ_eq_empty_iff.mpr hα), exact is_preconnected_empty }⟩ },
{ exact ⟨by { rw ← h (classical.choice hα), exact is_preconnected_connected_component }⟩ } }
end
@[simp] lemma preconnected_space.connected_component_eq_univ {X : Type*} [topological_space X]
[h : preconnected_space X] (x : X) : connected_component x = univ :=
preconnected_space_iff_connected_component.mp h x
instance [topological_space β] [preconnected_space α] [preconnected_space β] :
preconnected_space (α × β) :=
⟨by { rw ← univ_prod_univ, exact is_preconnected_univ.prod is_preconnected_univ }⟩
instance [topological_space β] [connected_space α] [connected_space β] :
connected_space (α × β) :=
⟨prod.nonempty⟩
instance [Π i, topological_space (π i)] [∀ i, preconnected_space (π i)] :
preconnected_space (Π i, π i) :=
⟨by { rw ← pi_univ univ, exact is_preconnected_univ_pi (λ i, is_preconnected_univ) }⟩
instance [Π i, topological_space (π i)] [∀ i, connected_space (π i)] : connected_space (Π i, π i) :=
⟨classical.nonempty_pi.2 $ λ i, by apply_instance⟩
@[priority 100] -- see Note [lower instance priority]
instance preirreducible_space.preconnected_space (α : Type u) [topological_space α]
[preirreducible_space α] : preconnected_space α :=
⟨(preirreducible_space.is_preirreducible_univ α).is_preconnected⟩
@[priority 100] -- see Note [lower instance priority]
instance irreducible_space.connected_space (α : Type u) [topological_space α]
[irreducible_space α] : connected_space α :=
{ to_nonempty := irreducible_space.to_nonempty α }
theorem nonempty_inter [preconnected_space α] {s t : set α} :
is_open s → is_open t → s ∪ t = univ → s.nonempty → t.nonempty → (s ∩ t).nonempty :=
by simpa only [univ_inter, univ_subset_iff] using
@preconnected_space.is_preconnected_univ α _ _ s t
theorem is_clopen_iff [preconnected_space α] {s : set α} : is_clopen s ↔ s = ∅ ∨ s = univ :=
⟨λ hs, classical.by_contradiction $ λ h,
have h1 : s ≠ ∅ ∧ sᶜ ≠ ∅, from ⟨mt or.inl h,
mt (λ h2, or.inr $ (by rw [← compl_compl s, h2, compl_empty] : s = univ)) h⟩,
let ⟨_, h2, h3⟩ := nonempty_inter hs.1 hs.2.is_open_compl (union_compl_self s)
(ne_empty_iff_nonempty.1 h1.1) (ne_empty_iff_nonempty.1 h1.2) in
h3 h2,
by rintro (rfl | rfl); [exact is_clopen_empty, exact is_clopen_univ]⟩
lemma eq_univ_of_nonempty_clopen [preconnected_space α] {s : set α}
(h : s.nonempty) (h' : is_clopen s) : s = univ :=
by { rw is_clopen_iff at h', exact h'.resolve_left h.ne_empty }
lemma frontier_eq_empty_iff [preconnected_space α] {s : set α} :
frontier s = ∅ ↔ s = ∅ ∨ s = univ :=
is_clopen_iff_frontier_eq_empty.symm.trans is_clopen_iff
lemma nonempty_frontier_iff [preconnected_space α] {s : set α} :
(frontier s).nonempty ↔ s.nonempty ∧ s ≠ univ :=
by simp only [← ne_empty_iff_nonempty, ne.def, frontier_eq_empty_iff, not_or_distrib]
lemma subtype.preconnected_space {s : set α} (h : is_preconnected s) :
preconnected_space s :=
{ is_preconnected_univ := by rwa [← embedding_subtype_coe.to_inducing.is_preconnected_image,
image_univ, subtype.range_coe] }
lemma subtype.connected_space {s : set α} (h : is_connected s) :
connected_space s :=
{ to_preconnected_space := subtype.preconnected_space h.is_preconnected,
to_nonempty := h.nonempty.to_subtype }
lemma is_preconnected_iff_preconnected_space {s : set α} :
is_preconnected s ↔ preconnected_space s :=
⟨subtype.preconnected_space,
begin
introI,
simpa using is_preconnected_univ.image (coe : s → α) continuous_subtype_coe.continuous_on
end⟩
lemma is_connected_iff_connected_space {s : set α} : is_connected s ↔ connected_space s :=
⟨subtype.connected_space,
λ h, ⟨nonempty_subtype.mp h.2, is_preconnected_iff_preconnected_space.mpr h.1⟩⟩
/-- A set `s` is preconnected if and only if
for every cover by two open sets that are disjoint on `s`,
it is contained in one of the two covering sets. -/
lemma is_preconnected_iff_subset_of_disjoint {s : set α} :
is_preconnected s ↔
∀ (u v : set α) (hu : is_open u) (hv : is_open v) (hs : s ⊆ u ∪ v) (huv : s ∩ (u ∩ v) = ∅),
s ⊆ u ∨ s ⊆ v :=
begin
split; intro h,
{ intros u v hu hv hs huv,
specialize h u v hu hv hs,
contrapose! huv,
rw ne_empty_iff_nonempty,
simp [not_subset] at huv,
rcases huv with ⟨⟨x, hxs, hxu⟩, ⟨y, hys, hyv⟩⟩,
have hxv : x ∈ v := or_iff_not_imp_left.mp (hs hxs) hxu,
have hyu : y ∈ u := or_iff_not_imp_right.mp (hs hys) hyv,
exact h ⟨y, hys, hyu⟩ ⟨x, hxs, hxv⟩ },
{ intros u v hu hv hs hsu hsv,
rw ← ne_empty_iff_nonempty,
intro H,
specialize h u v hu hv hs H,
contrapose H,
apply ne_empty_iff_nonempty.mpr,
cases h,
{ rcases hsv with ⟨x, hxs, hxv⟩, exact ⟨x, hxs, ⟨h hxs, hxv⟩⟩ },
{ rcases hsu with ⟨x, hxs, hxu⟩, exact ⟨x, hxs, ⟨hxu, h hxs⟩⟩ } }
end
/-- A set `s` is connected if and only if
for every cover by a finite collection of open sets that are pairwise disjoint on `s`,
it is contained in one of the members of the collection. -/
lemma is_connected_iff_sUnion_disjoint_open {s : set α} :
is_connected s ↔
∀ (U : finset (set α)) (H : ∀ (u v : set α), u ∈ U → v ∈ U → (s ∩ (u ∩ v)).nonempty → u = v)
(hU : ∀ u ∈ U, is_open u) (hs : s ⊆ ⋃₀ ↑U),
∃ u ∈ U, s ⊆ u :=
begin
rw [is_connected, is_preconnected_iff_subset_of_disjoint],
split; intro h,
{ intro U, apply finset.induction_on U,
{ rcases h.left,
suffices : s ⊆ ∅ → false, { simpa },
intro, solve_by_elim },
{ intros u U hu IH hs hU H,
rw [finset.coe_insert, sUnion_insert] at H,
cases h.2 u (⋃₀ ↑U) _ _ H _ with hsu hsU,
{ exact ⟨u, finset.mem_insert_self _ _, hsu⟩ },
{ rcases IH _ _ hsU with ⟨v, hvU, hsv⟩,
{ exact ⟨v, finset.mem_insert_of_mem hvU, hsv⟩ },
{ intros, apply hs; solve_by_elim [finset.mem_insert_of_mem] },
{ intros, solve_by_elim [finset.mem_insert_of_mem] } },
{ solve_by_elim [finset.mem_insert_self] },
{ apply is_open_sUnion,
intros, solve_by_elim [finset.mem_insert_of_mem] },
{ apply eq_empty_of_subset_empty,
rintro x ⟨hxs, hxu, hxU⟩,
rw mem_sUnion at hxU,
rcases hxU with ⟨v, hvU, hxv⟩,
rcases hs u v (finset.mem_insert_self _ _) (finset.mem_insert_of_mem hvU) _ with rfl,
{ contradiction },
{ exact ⟨x, hxs, hxu, hxv⟩ } } } },
{ split,
{ rw ← ne_empty_iff_nonempty,
by_contradiction hs, subst hs,
simpa using h ∅ _ _ _; simp },
intros u v hu hv hs hsuv,
rcases h {u, v} _ _ _ with ⟨t, ht, ht'⟩,
{ rw [finset.mem_insert, finset.mem_singleton] at ht,
rcases ht with rfl|rfl; tauto },
{ intros t₁ t₂ ht₁ ht₂ hst,
rw ← ne_empty_iff_nonempty at hst,
rw [finset.mem_insert, finset.mem_singleton] at ht₁ ht₂,
rcases ht₁ with rfl|rfl; rcases ht₂ with rfl|rfl,
all_goals { refl <|> contradiction <|> skip },
rw inter_comm t₁ at hst, contradiction },
{ intro t,
rw [finset.mem_insert, finset.mem_singleton],
rintro (rfl|rfl); assumption },
{ simpa using hs } }
end
/-- Preconnected sets are either contained in or disjoint to any given clopen set. -/
theorem is_preconnected.subset_clopen {s t : set α} (hs : is_preconnected s) (ht : is_clopen t)
(hne : (s ∩ t).nonempty) : s ⊆ t :=
begin
by_contra h,
have : (s ∩ tᶜ).nonempty := inter_compl_nonempty_iff.2 h,
obtain ⟨x, -, hx, hx'⟩ : (s ∩ (t ∩ tᶜ)).nonempty,
from hs t tᶜ ht.is_open ht.compl.is_open (λ x hx, em _) hne this,
exact hx' hx
end
/-- Preconnected sets are either contained in or disjoint to any given clopen set. -/
theorem disjoint_or_subset_of_clopen {s t : set α} (hs : is_preconnected s) (ht : is_clopen t) :
disjoint s t ∨ s ⊆ t :=
(disjoint_or_nonempty_inter s t).imp_right $ hs.subset_clopen ht
/-- A set `s` is preconnected if and only if
for every cover by two closed sets that are disjoint on `s`,
it is contained in one of the two covering sets. -/
theorem is_preconnected_iff_subset_of_disjoint_closed :
is_preconnected s ↔
∀ (u v : set α) (hu : is_closed u) (hv : is_closed v) (hs : s ⊆ u ∪ v) (huv : s ∩ (u ∩ v) = ∅),
s ⊆ u ∨ s ⊆ v :=
begin
split; intro h,
{ intros u v hu hv hs huv,
rw is_preconnected_closed_iff at h,
specialize h u v hu hv hs,
contrapose! huv,
rw ne_empty_iff_nonempty,
simp [not_subset] at huv,
rcases huv with ⟨⟨x, hxs, hxu⟩, ⟨y, hys, hyv⟩⟩,
have hxv : x ∈ v := or_iff_not_imp_left.mp (hs hxs) hxu,
have hyu : y ∈ u := or_iff_not_imp_right.mp (hs hys) hyv,
exact h ⟨y, hys, hyu⟩ ⟨x, hxs, hxv⟩ },
{ rw is_preconnected_closed_iff,
intros u v hu hv hs hsu hsv,
rw ← ne_empty_iff_nonempty,
intro H,
specialize h u v hu hv hs H,
contrapose H,
apply ne_empty_iff_nonempty.mpr,
cases h,
{ rcases hsv with ⟨x, hxs, hxv⟩, exact ⟨x, hxs, ⟨h hxs, hxv⟩⟩ },
{ rcases hsu with ⟨x, hxs, hxu⟩, exact ⟨x, hxs, ⟨hxu, h hxs⟩⟩ } }
end
/-- A closed set `s` is preconnected if and only if
for every cover by two closed sets that are disjoint,
it is contained in one of the two covering sets. -/
theorem is_preconnected_iff_subset_of_fully_disjoint_closed {s : set α} (hs : is_closed s) :
is_preconnected s ↔
∀ (u v : set α) (hu : is_closed u) (hv : is_closed v) (hss : s ⊆ u ∪ v) (huv : disjoint u v),
s ⊆ u ∨ s ⊆ v :=
begin
split,
{ intros h u v hu hv hss huv,
apply is_preconnected_iff_subset_of_disjoint_closed.1 h u v hu hv hss,
rw [huv.inter_eq, inter_empty] },
intro H,
rw is_preconnected_iff_subset_of_disjoint_closed,
intros u v hu hv hss huv,
have H1 := H (u ∩ s) (v ∩ s),
rw [subset_inter_iff, subset_inter_iff] at H1,
simp only [subset.refl, and_true] at H1,
apply H1 (is_closed.inter hu hs) (is_closed.inter hv hs),
{ rw ←inter_distrib_right,
exact subset_inter hss subset.rfl },
{ rwa [disjoint_iff_inter_eq_empty, ←inter_inter_distrib_right, inter_comm] }
end
lemma is_clopen.connected_component_subset {x} (hs : is_clopen s) (hx : x ∈ s) :
connected_component x ⊆ s :=
is_preconnected_connected_component.subset_clopen hs ⟨x, mem_connected_component, hx⟩
/-- The connected component of a point is always a subset of the intersection of all its clopen
neighbourhoods. -/
lemma connected_component_subset_Inter_clopen {x : α} :
connected_component x ⊆ ⋂ Z : {Z : set α // is_clopen Z ∧ x ∈ Z}, Z :=
subset_Inter $ λ Z, Z.2.1.connected_component_subset Z.2.2
/-- A clopen set is the union of its connected components. -/
lemma is_clopen.bUnion_connected_component_eq {Z : set α} (h : is_clopen Z) :
(⋃ x ∈ Z, connected_component x) = Z :=
subset.antisymm (Union₂_subset $ λ x, h.connected_component_subset) $
λ x hx, mem_Union₂_of_mem hx mem_connected_component
/-- The preimage of a connected component is preconnected if the function has connected fibers
and a subset is closed iff the preimage is. -/
lemma preimage_connected_component_connected [topological_space β] {f : α → β}
(connected_fibers : ∀ t : β, is_connected (f ⁻¹' {t}))
(hcl : ∀ (T : set β), is_closed T ↔ is_closed (f ⁻¹' T)) (t : β) :
is_connected (f ⁻¹' connected_component t) :=
begin
-- The following proof is essentially https://stacks.math.columbia.edu/tag/0377
-- although the statement is slightly different
have hf : surjective f := surjective.of_comp (λ t : β, (connected_fibers t).1),
split,
{ cases hf t with s hs,
use s,
rw [mem_preimage, hs],
exact mem_connected_component },
have hT : is_closed (f ⁻¹' connected_component t) :=
(hcl (connected_component t)).1 is_closed_connected_component,
-- To show it's preconnected we decompose (f ⁻¹' connected_component t) as a subset of two
-- closed disjoint sets in α. We want to show that it's a subset of either.
rw is_preconnected_iff_subset_of_fully_disjoint_closed hT,
intros u v hu hv huv uv_disj,
-- To do this we decompose connected_component t into T₁ and T₂
-- we will show that connected_component t is a subset of either and hence
-- (f ⁻¹' connected_component t) is a subset of u or v
let T₁ := {t' ∈ connected_component t | f ⁻¹' {t'} ⊆ u},
let T₂ := {t' ∈ connected_component t | f ⁻¹' {t'} ⊆ v},
have fiber_decomp : ∀ t' ∈ connected_component t, f ⁻¹' {t'} ⊆ u ∨ f ⁻¹' {t'} ⊆ v,
{ intros t' ht',
apply is_preconnected_iff_subset_of_disjoint_closed.1 (connected_fibers t').2 u v hu hv,
{ exact subset.trans (hf.preimage_subset_preimage_iff.2 (singleton_subset_iff.2 ht')) huv },
rw [uv_disj.inter_eq, inter_empty] },
have T₁_u : f ⁻¹' T₁ = (f ⁻¹' connected_component t) ∩ u,
{ apply eq_of_subset_of_subset,
{ rw ←bUnion_preimage_singleton,
refine Union₂_subset (λ t' ht', subset_inter _ ht'.2),
rw [hf.preimage_subset_preimage_iff, singleton_subset_iff],
exact ht'.1 },
rintros a ⟨hat, hau⟩,
constructor,
{ exact mem_preimage.1 hat },
dsimp only,
cases fiber_decomp (f a) (mem_preimage.1 hat),
{ exact h },
{ cases (nonempty_of_mem $ mem_inter hau $ h rfl).not_disjoint uv_disj } },
-- This proof is exactly the same as the above (modulo some symmetry)
have T₂_v : f ⁻¹' T₂ = (f ⁻¹' connected_component t) ∩ v,
{ apply eq_of_subset_of_subset,
{ rw ←bUnion_preimage_singleton,
refine Union₂_subset (λ t' ht', subset_inter _ ht'.2),
rw [hf.preimage_subset_preimage_iff, singleton_subset_iff],
exact ht'.1 },
rintros a ⟨hat, hav⟩,
constructor,
{ exact mem_preimage.1 hat },
dsimp only,
cases fiber_decomp (f a) (mem_preimage.1 hat),
{ cases (nonempty_of_mem (mem_inter (h rfl) hav)).not_disjoint uv_disj },
{ exact h } },
-- Now we show T₁, T₂ are closed, cover connected_component t and are disjoint.
have hT₁ : is_closed T₁ := ((hcl T₁).2 (T₁_u.symm ▸ (is_closed.inter hT hu))),
have hT₂ : is_closed T₂ := ((hcl T₂).2 (T₂_v.symm ▸ (is_closed.inter hT hv))),
have T_decomp : connected_component t ⊆ T₁ ∪ T₂,
{ intros t' ht',
rw mem_union t' T₁ T₂,
cases fiber_decomp t' ht' with htu htv,
{ left, exact ⟨ht', htu⟩ },
right, exact ⟨ht', htv⟩ },
have T_disjoint : disjoint T₁ T₂,
{ refine disjoint.of_preimage hf _,
rw [T₁_u, T₂_v, disjoint_iff_inter_eq_empty, ←inter_inter_distrib_left, uv_disj.inter_eq,
inter_empty] },
-- Now we do cases on whether (connected_component t) is a subset of T₁ or T₂ to show
-- that the preimage is a subset of u or v.
cases (is_preconnected_iff_subset_of_fully_disjoint_closed is_closed_connected_component).1
is_preconnected_connected_component T₁ T₂ hT₁ hT₂ T_decomp T_disjoint,
{ left,
rw subset.antisymm_iff at T₁_u,
suffices : f ⁻¹' connected_component t ⊆ f ⁻¹' T₁,
{ exact subset.trans (subset.trans this T₁_u.1) (inter_subset_right _ _) },
exact preimage_mono h },
right,
rw subset.antisymm_iff at T₂_v,
suffices : f ⁻¹' connected_component t ⊆ f ⁻¹' T₂,
{ exact subset.trans (subset.trans this T₂_v.1) (inter_subset_right _ _) },
exact preimage_mono h,
end
lemma quotient_map.preimage_connected_component [topological_space β] {f : α → β}
(hf : quotient_map f) (h_fibers : ∀ y : β, is_connected (f ⁻¹' {y})) (a : α) :
f ⁻¹' connected_component (f a) = connected_component a :=
((preimage_connected_component_connected h_fibers
(λ _, hf.is_closed_preimage.symm) _).subset_connected_component mem_connected_component).antisymm
(hf.continuous.maps_to_connected_component a)
lemma quotient_map.image_connected_component [topological_space β] {f : α → β}
(hf : quotient_map f) (h_fibers : ∀ y : β, is_connected (f ⁻¹' {y})) (a : α) :
f '' connected_component a = connected_component (f a) :=
by rw [← hf.preimage_connected_component h_fibers, image_preimage_eq _ hf.surjective]
end preconnected
section totally_disconnected
/-- A set `s` is called totally disconnected if every subset `t ⊆ s` which is preconnected is
a subsingleton, ie either empty or a singleton.-/
def is_totally_disconnected (s : set α) : Prop :=
∀ t, t ⊆ s → is_preconnected t → t.subsingleton
theorem is_totally_disconnected_empty : is_totally_disconnected (∅ : set α) :=
λ _ ht _ _ x_in _ _, (ht x_in).elim
theorem is_totally_disconnected_singleton {x} : is_totally_disconnected ({x} : set α) :=
λ _ ht _, subsingleton.mono subsingleton_singleton ht
/-- A space is totally disconnected if all of its connected components are singletons. -/
class totally_disconnected_space (α : Type u) [topological_space α] : Prop :=
(is_totally_disconnected_univ : is_totally_disconnected (univ : set α))
lemma is_preconnected.subsingleton [totally_disconnected_space α]
{s : set α} (h : is_preconnected s) : s.subsingleton :=
totally_disconnected_space.is_totally_disconnected_univ s (subset_univ s) h
instance pi.totally_disconnected_space {α : Type*} {β : α → Type*}
[t₂ : Πa, topological_space (β a)] [∀a, totally_disconnected_space (β a)] :
totally_disconnected_space (Π (a : α), β a) :=
⟨λ t h1 h2,
have this : ∀ a, is_preconnected ((λ x : Π a, β a, x a) '' t),
from λ a, h2.image (λ x, x a) (continuous_apply a).continuous_on,
λ x x_in y y_in, funext $ λ a, (this a).subsingleton ⟨x, x_in, rfl⟩ ⟨y, y_in, rfl⟩⟩
instance prod.totally_disconnected_space [topological_space β]
[totally_disconnected_space α] [totally_disconnected_space β] :
totally_disconnected_space (α × β) :=
⟨λ t h1 h2,
have H1 : is_preconnected (prod.fst '' t), from h2.image prod.fst continuous_fst.continuous_on,
have H2 : is_preconnected (prod.snd '' t), from h2.image prod.snd continuous_snd.continuous_on,
λ x hx y hy, prod.ext
(H1.subsingleton ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩)
(H2.subsingleton ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩)⟩
instance [topological_space β] [totally_disconnected_space α] [totally_disconnected_space β] :
totally_disconnected_space (α ⊕ β) :=
begin
refine ⟨λ s _ hs, _⟩,
obtain (⟨t, ht, rfl⟩ | ⟨t, ht, rfl⟩) := sum.is_preconnected_iff.1 hs,
{ exact ht.subsingleton.image _ },
{ exact ht.subsingleton.image _ }
end
instance [Π i, topological_space (π i)] [∀ i, totally_disconnected_space (π i)] :
totally_disconnected_space (Σ i, π i) :=
begin
refine ⟨λ s _ hs, _⟩,
obtain rfl | h := s.eq_empty_or_nonempty,
{ exact subsingleton_empty },
{ obtain ⟨a, t, ht, rfl⟩ := sigma.is_connected_iff.1 ⟨h, hs⟩,
exact ht.is_preconnected.subsingleton.image _ }
end
/-- Let `X` be a topological space, and suppose that for all distinct `x,y ∈ X`, there
is some clopen set `U` such that `x ∈ U` and `y ∉ U`. Then `X` is totally disconnected. -/
lemma is_totally_disconnected_of_clopen_set {X : Type*} [topological_space X]
(hX : ∀ {x y : X} (h_diff : x ≠ y), ∃ (U : set X) (h_clopen : is_clopen U), x ∈ U ∧ y ∉ U) :
is_totally_disconnected (set.univ : set X) :=
begin
rintro S - hS,
unfold set.subsingleton,
by_contra' h_contra,
rcases h_contra with ⟨x, hx, y, hy, hxy⟩,
obtain ⟨U, h_clopen, hxU, hyU⟩ := hX hxy,
specialize hS U Uᶜ h_clopen.1 h_clopen.compl.1 (λ a ha, em (a ∈ U)) ⟨x, hx, hxU⟩ ⟨y, hy, hyU⟩,
rw [inter_compl_self, set.inter_empty] at hS,
exact set.not_nonempty_empty hS,
end
/-- A space is totally disconnected iff its connected components are subsingletons. -/
lemma totally_disconnected_space_iff_connected_component_subsingleton :
totally_disconnected_space α ↔ ∀ x : α, (connected_component x).subsingleton :=
begin
split,
{ intros h x,
apply h.1,
{ exact subset_univ _ },
exact is_preconnected_connected_component },
intro h, constructor,
intros s s_sub hs,
rcases eq_empty_or_nonempty s with rfl | ⟨x, x_in⟩,
{ exact subsingleton_empty },
{ exact (h x).mono (hs.subset_connected_component x_in) }
end
/-- A space is totally disconnected iff its connected components are singletons. -/
lemma totally_disconnected_space_iff_connected_component_singleton :
totally_disconnected_space α ↔ ∀ x : α, connected_component x = {x} :=
begin
rw totally_disconnected_space_iff_connected_component_subsingleton,
apply forall_congr (λ x, _),
rw subsingleton_iff_singleton,
exact mem_connected_component
end
/-- The image of a connected component in a totally disconnected space is a singleton. -/
@[simp] lemma continuous.image_connected_component_eq_singleton {β : Type*} [topological_space β]
[totally_disconnected_space β] {f : α → β} (h : continuous f) (a : α) :
f '' connected_component a = {f a} :=
(set.subsingleton_iff_singleton $ mem_image_of_mem f mem_connected_component).mp
(is_preconnected_connected_component.image f h.continuous_on).subsingleton
lemma is_totally_disconnected_of_totally_disconnected_space [totally_disconnected_space α]
(s : set α) : is_totally_disconnected s :=
λ t hts ht, totally_disconnected_space.is_totally_disconnected_univ _ t.subset_univ ht
lemma is_totally_disconnected_of_image [topological_space β] {f : α → β} (hf : continuous_on f s)
(hf' : injective f) (h : is_totally_disconnected (f '' s)) : is_totally_disconnected s :=
λ t hts ht x x_in y y_in, hf' $ h _ (image_subset f hts) (ht.image f $ hf.mono hts)
(mem_image_of_mem f x_in) (mem_image_of_mem f y_in)
lemma embedding.is_totally_disconnected [topological_space β] {f : α → β} (hf : embedding f)
{s : set α} (h : is_totally_disconnected (f '' s)) : is_totally_disconnected s :=
is_totally_disconnected_of_image hf.continuous.continuous_on hf.inj h
instance subtype.totally_disconnected_space {α : Type*} {p : α → Prop} [topological_space α]
[totally_disconnected_space α] : totally_disconnected_space (subtype p) :=
⟨embedding_subtype_coe.is_totally_disconnected
(is_totally_disconnected_of_totally_disconnected_space _)⟩
end totally_disconnected
section totally_separated
/-- A set `s` is called totally separated if any two points of this set can be separated
by two disjoint open sets covering `s`. -/
def is_totally_separated (s : set α) : Prop :=
∀ x ∈ s, ∀ y ∈ s, x ≠ y → ∃ u v : set α, is_open u ∧ is_open v ∧
x ∈ u ∧ y ∈ v ∧ s ⊆ u ∪ v ∧ disjoint u v
theorem is_totally_separated_empty : is_totally_separated (∅ : set α) :=
λ x, false.elim
theorem is_totally_separated_singleton {x} : is_totally_separated ({x} : set α) :=
λ p hp q hq hpq, (hpq $ (eq_of_mem_singleton hp).symm ▸ (eq_of_mem_singleton hq).symm).elim
theorem is_totally_disconnected_of_is_totally_separated {s : set α}
(H : is_totally_separated s) : is_totally_disconnected s :=
begin
intros t hts ht x x_in y y_in,
by_contra h,
obtain ⟨u : set α, v : set α, hu : is_open u, hv : is_open v,
hxu : x ∈ u, hyv : y ∈ v, hs : s ⊆ u ∪ v, huv⟩ :=
H x (hts x_in) y (hts y_in) h,
refine (ht _ _ hu hv (hts.trans hs) ⟨x, x_in, hxu⟩ ⟨y, y_in, hyv⟩).ne_empty _,
rw [huv.inter_eq, inter_empty],
end
alias is_totally_disconnected_of_is_totally_separated ← is_totally_separated.is_totally_disconnected
/-- A space is totally separated if any two points can be separated by two disjoint open sets
covering the whole space. -/
class totally_separated_space (α : Type u) [topological_space α] : Prop :=
(is_totally_separated_univ [] : is_totally_separated (univ : set α))
@[priority 100] -- see Note [lower instance priority]
instance totally_separated_space.totally_disconnected_space (α : Type u) [topological_space α]
[totally_separated_space α] : totally_disconnected_space α :=
⟨is_totally_disconnected_of_is_totally_separated $
totally_separated_space.is_totally_separated_univ α⟩
@[priority 100] -- see Note [lower instance priority]
instance totally_separated_space.of_discrete
(α : Type*) [topological_space α] [discrete_topology α] : totally_separated_space α :=
⟨λ a _ b _ h, ⟨{b}ᶜ, {b}, is_open_discrete _, is_open_discrete _, by simpa⟩⟩
lemma exists_clopen_of_totally_separated {α : Type*} [topological_space α]
[totally_separated_space α] {x y : α} (hxy : x ≠ y) :
∃ (U : set α) (hU : is_clopen U), x ∈ U ∧ y ∈ Uᶜ :=
begin
obtain ⟨U, V, hU, hV, Ux, Vy, f, disj⟩ :=
totally_separated_space.is_totally_separated_univ α x (set.mem_univ x) y (set.mem_univ y) hxy,
have clopen_U := is_clopen_inter_of_disjoint_cover_clopen (is_clopen_univ) f hU hV disj,
rw univ_inter _ at clopen_U,
rw [←set.subset_compl_iff_disjoint_right, subset_compl_comm] at disj,
exact ⟨U, clopen_U, Ux, disj Vy⟩,
end
end totally_separated
section connected_component_setoid
/-- The setoid of connected components of a topological space -/
def connected_component_setoid (α : Type*) [topological_space α] : setoid α :=
⟨λ x y, connected_component x = connected_component y,
⟨λ x, by trivial, λ x y h1, h1.symm, λ x y z h1 h2, h1.trans h2⟩⟩
/-- The quotient of a space by its connected components -/
def connected_components (α : Type u) [topological_space α] :=
quotient (connected_component_setoid α)
instance : has_coe_t α (connected_components α) := ⟨quotient.mk'⟩
namespace connected_components
@[simp] lemma coe_eq_coe {x y : α} :
(x : connected_components α) = y ↔ connected_component x = connected_component y :=
quotient.eq'
lemma coe_ne_coe {x y : α} :
(x : connected_components α) ≠ y ↔ connected_component x ≠ connected_component y :=
not_congr coe_eq_coe
lemma coe_eq_coe' {x y : α} :
(x : connected_components α) = y ↔ x ∈ connected_component y :=
coe_eq_coe.trans ⟨λ h, h ▸ mem_connected_component, λ h, (connected_component_eq h).symm⟩
instance [inhabited α] : inhabited (connected_components α) := ⟨↑(default : α)⟩
instance : topological_space (connected_components α) :=
quotient.topological_space
lemma surjective_coe : surjective (coe : α → connected_components α) := surjective_quot_mk _
lemma quotient_map_coe : quotient_map (coe : α → connected_components α) := quotient_map_quot_mk
@[continuity]
lemma continuous_coe : continuous (coe : α → connected_components α) := quotient_map_coe.continuous
@[simp] lemma range_coe : range (coe : α → connected_components α)= univ :=
surjective_coe.range_eq
end connected_components
variables [topological_space β] [totally_disconnected_space β] {f : α → β}
lemma continuous.image_eq_of_connected_component_eq (h : continuous f) (a b : α)
(hab : connected_component a = connected_component b) : f a = f b :=
singleton_eq_singleton_iff.1 $
h.image_connected_component_eq_singleton a ▸
h.image_connected_component_eq_singleton b ▸ hab ▸ rfl
/--
The lift to `connected_components α` of a continuous map from `α` to a totally disconnected space
-/
def continuous.connected_components_lift (h : continuous f) :
connected_components α → β :=
λ x, quotient.lift_on' x f h.image_eq_of_connected_component_eq
@[continuity] lemma continuous.connected_components_lift_continuous (h : continuous f) :
continuous h.connected_components_lift :=
continuous_quotient_lift_on' h.image_eq_of_connected_component_eq h
@[simp] lemma continuous.connected_components_lift_apply_coe (h : continuous f) (x : α) :
h.connected_components_lift x = f x := rfl
@[simp] lemma continuous.connected_components_lift_comp_coe (h : continuous f) :
h.connected_components_lift ∘ coe = f := rfl
lemma connected_components_lift_unique' {β : Sort*} {g₁ g₂ : connected_components α → β}
(hg : g₁ ∘ (coe : α → connected_components α) = g₂ ∘ coe) :
g₁ = g₂ :=
connected_components.surjective_coe.injective_comp_right hg
lemma continuous.connected_components_lift_unique (h : continuous f)
(g : connected_components α → β) (hg : g ∘ coe = f) : g = h.connected_components_lift :=
connected_components_lift_unique' $ hg.trans h.connected_components_lift_comp_coe.symm
/-- The preimage of a singleton in `connected_components` is the connected component
of an element in the equivalence class. -/
lemma connected_components_preimage_singleton {x : α} :
coe ⁻¹' ({x} : set (connected_components α)) = connected_component x :=
by { ext y, simp [connected_components.coe_eq_coe'] }
/-- The preimage of the image of a set under the quotient map to `connected_components α`
is the union of the connected components of the elements in it. -/
lemma connected_components_preimage_image (U : set α) :
coe ⁻¹' (coe '' U : set (connected_components α)) = ⋃ x ∈ U, connected_component x :=
by simp only [connected_components_preimage_singleton, preimage_Union₂, image_eq_Union]
instance connected_components.totally_disconnected_space :
totally_disconnected_space (connected_components α) :=
begin
rw totally_disconnected_space_iff_connected_component_singleton,
refine connected_components.surjective_coe.forall.2 (λ x, _),
rw [← connected_components.quotient_map_coe.image_connected_component,
← connected_components_preimage_singleton,
image_preimage_eq _ connected_components.surjective_coe],
refine connected_components.surjective_coe.forall.2 (λ y, _),
rw connected_components_preimage_singleton,
exact is_connected_connected_component
end
/-- Functoriality of `connected_components` -/
def continuous.connected_components_map {β : Type*} [topological_space β] {f : α → β}
(h : continuous f) : connected_components α → connected_components β :=
continuous.connected_components_lift (continuous_quotient_mk.comp h)
lemma continuous.connected_components_map_continuous {β : Type*} [topological_space β] {f : α → β}
(h : continuous f) : continuous h.connected_components_map :=
continuous.connected_components_lift_continuous (continuous_quotient_mk.comp h)
end connected_component_setoid
|
c3af9da30603ea1703152a7756dc3c0aa6cd91e4 | d9d511f37a523cd7659d6f573f990e2a0af93c6f | /src/data/set/intervals/unordered_interval.lean | 0109a9b3352001057106e926faaf131d2f6e52bd | [
"Apache-2.0"
] | permissive | hikari0108/mathlib | b7ea2b7350497ab1a0b87a09d093ecc025a50dfa | a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901 | refs/heads/master | 1,690,483,608,260 | 1,631,541,580,000 | 1,631,541,580,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 8,911 | lean | /-
Copyright (c) 2020 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou
-/
import order.bounds
import data.set.intervals.image_preimage
/-!
# Intervals without endpoints ordering
In any decidable linear order `α`, we define the set of elements lying between two elements `a` and
`b` as `Icc (min a b) (max a b)`.
`Icc a b` requires the assumption `a ≤ b` to be meaningful, which is sometimes inconvenient. The
interval as defined in this file is always the set of things lying between `a` and `b`, regardless
of the relative order of `a` and `b`.
For real numbers, `Icc (min a b) (max a b)` is the same as `segment ℝ a b`.
## Notation
We use the localized notation `[a, b]` for `interval a b`. One can open the locale `interval` to
make the notation available.
-/
universe u
open_locale pointwise
namespace set
section linear_order
variables {α : Type u} [linear_order α] {a a₁ a₂ b b₁ b₂ x : α}
/-- `interval a b` is the set of elements lying between `a` and `b`, with `a` and `b` included. -/
def interval (a b : α) := Icc (min a b) (max a b)
localized "notation `[`a `, ` b `]` := set.interval a b" in interval
@[simp] lemma interval_of_le (h : a ≤ b) : [a, b] = Icc a b :=
by rw [interval, min_eq_left h, max_eq_right h]
@[simp] lemma interval_of_ge (h : b ≤ a) : [a, b] = Icc b a :=
by { rw [interval, min_eq_right h, max_eq_left h] }
lemma interval_swap (a b : α) : [a, b] = [b, a] :=
or.elim (le_total a b) (by simp {contextual := tt}) (by simp {contextual := tt})
lemma interval_of_lt (h : a < b) : [a, b] = Icc a b :=
interval_of_le (le_of_lt h)
lemma interval_of_gt (h : b < a) : [a, b] = Icc b a :=
interval_of_ge (le_of_lt h)
lemma interval_of_not_le (h : ¬ a ≤ b) : [a, b] = Icc b a :=
interval_of_gt (lt_of_not_ge h)
lemma interval_of_not_ge (h : ¬ b ≤ a) : [a, b] = Icc a b :=
interval_of_lt (lt_of_not_ge h)
@[simp] lemma interval_self : [a, a] = {a} :=
set.ext $ by simp [le_antisymm_iff, and_comm]
@[simp] lemma nonempty_interval : set.nonempty [a, b] :=
by { simp only [interval, min_le_iff, le_max_iff, nonempty_Icc], left, left, refl }
@[simp] lemma left_mem_interval : a ∈ [a, b] :=
by { rw [interval, mem_Icc], exact ⟨min_le_left _ _, le_max_left _ _⟩ }
@[simp] lemma right_mem_interval : b ∈ [a, b] :=
by { rw interval_swap, exact left_mem_interval }
lemma Icc_subset_interval : Icc a b ⊆ [a, b] :=
by { assume x h, rwa interval_of_le, exact le_trans h.1 h.2 }
lemma Icc_subset_interval' : Icc b a ⊆ [a, b] :=
by { rw interval_swap, apply Icc_subset_interval }
lemma mem_interval_of_le (ha : a ≤ x) (hb : x ≤ b) : x ∈ [a, b] :=
Icc_subset_interval ⟨ha, hb⟩
lemma mem_interval_of_ge (hb : b ≤ x) (ha : x ≤ a) : x ∈ [a, b] :=
Icc_subset_interval' ⟨hb, ha⟩
lemma not_mem_interval_of_lt {c : α} (ha : c < a) (hb : c < b) : c ∉ interval a b :=
not_mem_Icc_of_lt $ lt_min_iff.mpr ⟨ha, hb⟩
lemma not_mem_interval_of_gt {c : α} (ha : a < c) (hb : b < c) : c ∉ interval a b :=
not_mem_Icc_of_gt $ max_lt_iff.mpr ⟨ha, hb⟩
lemma interval_subset_interval (h₁ : a₁ ∈ [a₂, b₂]) (h₂ : b₁ ∈ [a₂, b₂]) : [a₁, b₁] ⊆ [a₂, b₂] :=
Icc_subset_Icc (le_min h₁.1 h₂.1) (max_le h₁.2 h₂.2)
lemma interval_subset_interval_iff_mem : [a₁, b₁] ⊆ [a₂, b₂] ↔ a₁ ∈ [a₂, b₂] ∧ b₁ ∈ [a₂, b₂] :=
iff.intro (λh, ⟨h left_mem_interval, h right_mem_interval⟩) (λ h, interval_subset_interval h.1 h.2)
lemma interval_subset_interval_iff_le :
[a₁, b₁] ⊆ [a₂, b₂] ↔ min a₂ b₂ ≤ min a₁ b₁ ∧ max a₁ b₁ ≤ max a₂ b₂ :=
by { rw [interval, interval, Icc_subset_Icc_iff], exact min_le_max }
lemma interval_subset_interval_right (h : x ∈ [a, b]) : [x, b] ⊆ [a, b] :=
interval_subset_interval h right_mem_interval
lemma interval_subset_interval_left (h : x ∈ [a, b]) : [a, x] ⊆ [a, b] :=
interval_subset_interval left_mem_interval h
lemma bdd_below_bdd_above_iff_subset_interval (s : set α) :
bdd_below s ∧ bdd_above s ↔ ∃ a b, s ⊆ [a, b] :=
begin
rw [bdd_below_bdd_above_iff_subset_Icc],
split,
{ rintro ⟨a, b, h⟩, exact ⟨a, b, λ x hx, Icc_subset_interval (h hx)⟩ },
{ rintro ⟨a, b, h⟩, exact ⟨min a b, max a b, h⟩ }
end
/-- The open-closed interval with unordered bounds. -/
def interval_oc : α → α → set α := λ a b, Ioc (min a b) (max a b)
-- Below is a capital iota
localized "notation `Ι` := set.interval_oc" in interval
lemma interval_oc_of_le (h : a ≤ b) : Ι a b = Ioc a b :=
by simp [interval_oc, h]
lemma interval_oc_of_lt (h : b < a) : Ι a b = Ioc b a :=
by simp [interval_oc, le_of_lt h]
lemma forall_interval_oc_iff {P : α → Prop} :
(∀ x ∈ Ι a b, P x) ↔ (∀ x ∈ Ioc a b, P x) ∧ (∀ x ∈ Ioc b a, P x) :=
by { dsimp [interval_oc], cases le_total a b with hab hab ; simp [hab] }
end linear_order
open_locale interval
section ordered_add_comm_group
variables {α : Type u} [linear_ordered_add_comm_group α] (a b c x y : α)
@[simp] lemma preimage_const_add_interval : (λ x, a + x) ⁻¹' [b, c] = [b - a, c - a] :=
by simp only [interval, preimage_const_add_Icc, min_sub_sub_right, max_sub_sub_right]
@[simp] lemma preimage_add_const_interval : (λ x, x + a) ⁻¹' [b, c] = [b - a, c - a] :=
by simpa only [add_comm] using preimage_const_add_interval a b c
@[simp] lemma preimage_neg_interval : - [a, b] = [-a, -b] :=
by simp only [interval, preimage_neg_Icc, min_neg_neg, max_neg_neg]
@[simp] lemma preimage_sub_const_interval : (λ x, x - a) ⁻¹' [b, c] = [b + a, c + a] :=
by simp [sub_eq_add_neg]
@[simp] lemma preimage_const_sub_interval : (λ x, a - x) ⁻¹' [b, c] = [a - b, a - c] :=
by { rw [interval, interval, preimage_const_sub_Icc],
simp only [sub_eq_add_neg, min_add_add_left, max_add_add_left, min_neg_neg, max_neg_neg], }
@[simp] lemma image_const_add_interval : (λ x, a + x) '' [b, c] = [a + b, a + c] :=
by simp [add_comm]
@[simp] lemma image_add_const_interval : (λ x, x + a) '' [b, c] = [b + a, c + a] :=
by simp
@[simp] lemma image_const_sub_interval : (λ x, a - x) '' [b, c] = [a - b, a - c] :=
by simp [sub_eq_add_neg, image_comp (λ x, a + x) (λ x, -x)]
@[simp] lemma image_sub_const_interval : (λ x, x - a) '' [b, c] = [b - a, c - a] :=
by simp [sub_eq_add_neg, add_comm]
lemma image_neg_interval : has_neg.neg '' [a, b] = [-a, -b] := by simp
variables {a b c x y}
/-- If `[x, y]` is a subinterval of `[a, b]`, then the distance between `x` and `y`
is less than or equal to that of `a` and `b` -/
lemma abs_sub_le_of_subinterval (h : [x, y] ⊆ [a, b]) : abs (y - x) ≤ abs (b - a) :=
begin
rw [← max_sub_min_eq_abs, ← max_sub_min_eq_abs],
rw [interval_subset_interval_iff_le] at h,
exact sub_le_sub h.2 h.1,
end
/-- If `x ∈ [a, b]`, then the distance between `a` and `x` is less than or equal to
that of `a` and `b` -/
lemma abs_sub_left_of_mem_interval (h : x ∈ [a, b]) : abs (x - a) ≤ abs (b - a) :=
abs_sub_le_of_subinterval (interval_subset_interval_left h)
/-- If `x ∈ [a, b]`, then the distance between `x` and `b` is less than or equal to
that of `a` and `b` -/
lemma abs_sub_right_of_mem_interval (h : x ∈ [a, b]) : abs (b - x) ≤ abs (b - a) :=
abs_sub_le_of_subinterval (interval_subset_interval_right h)
end ordered_add_comm_group
section linear_ordered_field
variables {k : Type u} [linear_ordered_field k] {a : k}
@[simp] lemma preimage_mul_const_interval (ha : a ≠ 0) (b c : k) :
(λ x, x * a) ⁻¹' [b, c] = [b / a, c / a] :=
(lt_or_gt_of_ne ha).elim
(λ ha, by simp [interval, ha, ha.le, min_div_div_right_of_nonpos, max_div_div_right_of_nonpos])
(λ (ha : 0 < a), by simp [interval, ha, ha.le, min_div_div_right, max_div_div_right])
@[simp] lemma preimage_const_mul_interval (ha : a ≠ 0) (b c : k) :
(λ x, a * x) ⁻¹' [b, c] = [b / a, c / a] :=
by simp only [← preimage_mul_const_interval ha, mul_comm]
@[simp] lemma preimage_div_const_interval (ha : a ≠ 0) (b c : k) :
(λ x, x / a) ⁻¹' [b, c] = [b * a, c * a] :=
by simp only [div_eq_mul_inv, preimage_mul_const_interval (inv_ne_zero ha), inv_inv']
@[simp] lemma image_mul_const_interval (a b c : k) : (λ x, x * a) '' [b, c] = [b * a, c * a] :=
if ha : a = 0 then by simp [ha] else
calc (λ x, x * a) '' [b, c] = (λ x, x * a⁻¹) ⁻¹' [b, c] :
(units.mk0 a ha).mul_right.image_eq_preimage _
... = (λ x, x / a) ⁻¹' [b, c] : by simp only [div_eq_mul_inv]
... = [b * a, c * a] : preimage_div_const_interval ha _ _
@[simp] lemma image_const_mul_interval (a b c : k) : (λ x, a * x) '' [b, c] = [a * b, a * c] :=
by simpa only [mul_comm] using image_mul_const_interval a b c
@[simp] lemma image_div_const_interval (a b c : k) : (λ x, x / a) '' [b, c] = [b / a, c / a] :=
by simp only [div_eq_mul_inv, image_mul_const_interval]
end linear_ordered_field
end set
|
96cd12b1e957e15cd1613bf75e6e91de6732334a | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/ring_theory/graded_algebra/basic.lean | 9d837835353784875b481dcd69b35c6f477be7ef | [
"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 | 11,676 | lean | /-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Kevin Buzzard, Jujian Zhang
-/
import algebra.direct_sum.algebra
import algebra.direct_sum.decomposition
import algebra.direct_sum.internal
import algebra.direct_sum.ring
import group_theory.subgroup.basic
/-!
# Internally-graded rings and algebras
This file defines the typeclass `graded_algebra 𝒜`, for working with an algebra `A` that is
internally graded by a collection of submodules `𝒜 : ι → submodule R A`.
See the docstring of that typeclass for more information.
## Main definitions
* `graded_ring 𝒜`: the typeclass, which is a combination of `set_like.graded_monoid`, and
`direct_sum.decomposition 𝒜`.
* `graded_algebra 𝒜`: A convenience alias for `graded_ring` when `𝒜` is a family of submodules.
* `direct_sum.decompose_ring_equiv 𝒜 : A ≃ₐ[R] ⨁ i, 𝒜 i`, a more bundled version of
`direct_sum.decompose 𝒜`.
* `direct_sum.decompose_alg_equiv 𝒜 : A ≃ₐ[R] ⨁ i, 𝒜 i`, a more bundled version of
`direct_sum.decompose 𝒜`.
* `graded_algebra.proj 𝒜 i` is the linear map from `A` to its degree `i : ι` component, such that
`proj 𝒜 i x = decompose 𝒜 x i`.
## Implementation notes
For now, we do not have internally-graded semirings and internally-graded rings; these can be
represented with `𝒜 : ι → submodule ℕ A` and `𝒜 : ι → submodule ℤ A` respectively, since all
`semiring`s are ℕ-algebras via `algebra_nat`, and all `ring`s are `ℤ`-algebras via `algebra_int`.
## Tags
graded algebra, graded ring, graded semiring, decomposition
-/
open_locale direct_sum big_operators
variables {ι R A σ : Type*}
section graded_ring
variables [decidable_eq ι] [add_monoid ι] [comm_semiring R] [semiring A] [algebra R A]
variables [set_like σ A] [add_submonoid_class σ A] (𝒜 : ι → σ)
include A
open direct_sum
/-- An internally-graded `R`-algebra `A` is one that can be decomposed into a collection
of `submodule R A`s indexed by `ι` such that the canonical map `A → ⨁ i, 𝒜 i` is bijective and
respects multiplication, i.e. the product of an element of degree `i` and an element of degree `j`
is an element of degree `i + j`.
Note that the fact that `A` is internally-graded, `graded_algebra 𝒜`, implies an externally-graded
algebra structure `direct_sum.galgebra R (λ i, ↥(𝒜 i))`, which in turn makes available an
`algebra R (⨁ i, 𝒜 i)` instance.
-/
class graded_ring (𝒜 : ι → σ) extends set_like.graded_monoid 𝒜, direct_sum.decomposition 𝒜.
variables [graded_ring 𝒜]
namespace direct_sum
/-- If `A` is graded by `ι` with degree `i` component `𝒜 i`, then it is isomorphic as
a ring to a direct sum of components. -/
def decompose_ring_equiv : A ≃+* ⨁ i, 𝒜 i := ring_equiv.symm
{ map_mul' := (coe_ring_hom 𝒜).map_mul,
map_add' := (coe_ring_hom 𝒜).map_add,
..(decompose_add_equiv 𝒜).symm }
@[simp] lemma decompose_one : decompose 𝒜 (1 : A) = 1 := map_one (decompose_ring_equiv 𝒜)
@[simp] lemma decompose_symm_one : (decompose 𝒜).symm 1 = (1 : A) :=
map_one (decompose_ring_equiv 𝒜).symm
@[simp] lemma decompose_mul (x y : A) : decompose 𝒜 (x * y) = decompose 𝒜 x * decompose 𝒜 y :=
map_mul (decompose_ring_equiv 𝒜) x y
@[simp] lemma decompose_symm_mul (x y : ⨁ i, 𝒜 i) :
(decompose 𝒜).symm (x * y) = (decompose 𝒜).symm x * (decompose 𝒜).symm y :=
map_mul (decompose_ring_equiv 𝒜).symm x y
end direct_sum
/-- The projection maps of a graded ring -/
def graded_ring.proj (i : ι) : A →+ A :=
(add_submonoid_class.subtype (𝒜 i)).comp $
(dfinsupp.eval_add_monoid_hom i).comp $
ring_hom.to_add_monoid_hom $ ring_equiv.to_ring_hom $ direct_sum.decompose_ring_equiv 𝒜
@[simp] lemma graded_ring.proj_apply (i : ι) (r : A) :
graded_ring.proj 𝒜 i r = (decompose 𝒜 r : ⨁ i, 𝒜 i) i := rfl
lemma graded_ring.proj_recompose (a : ⨁ i, 𝒜 i) (i : ι) :
graded_ring.proj 𝒜 i ((decompose 𝒜).symm a) =
(decompose 𝒜).symm (direct_sum.of _ i (a i)) :=
by rw [graded_ring.proj_apply, decompose_symm_of, equiv.apply_symm_apply]
lemma graded_ring.mem_support_iff [Π i (x : 𝒜 i), decidable (x ≠ 0)] (r : A) (i : ι) :
i ∈ (decompose 𝒜 r).support ↔ graded_ring.proj 𝒜 i r ≠ 0 :=
dfinsupp.mem_support_iff.trans add_submonoid_class.coe_eq_zero.not.symm
end graded_ring
section add_cancel_monoid
open direct_sum dfinsupp finset function
lemma direct_sum.coe_decompose_mul_add_of_left_mem {ι σ A}
[decidable_eq ι] [add_left_cancel_monoid ι] [semiring A]
[set_like σ A] [add_submonoid_class σ A] (𝒜 : ι → σ) [graded_ring 𝒜]
{a b : A} {i j : ι} (a_mem : a ∈ 𝒜 i) :
(decompose 𝒜 (a * b) (i + j) : A) = a * decompose 𝒜 b j :=
begin
obtain rfl | ha := eq_or_ne a 0,
{ simp },
classical,
lift a to (𝒜 i) using a_mem,
erw [decompose_mul, coe_mul_apply, decompose_coe, support_of _ i a (λ r,by subst r; exact ha rfl),
singleton_product, map_filter, sum_map],
simp_rw [comp, embedding.coe_fn_mk, add_left_cancel_iff, filter_eq'],
refine dite (decompose 𝒜 b j = 0) (λ h, by simp [if_neg (not_mem_support_iff.mpr h), h]) (λ h, _),
erw [if_pos (mem_support_iff.mpr h), finset.sum_singleton, of_eq_same],
refl,
end
lemma direct_sum.coe_decompose_mul_add_of_right_mem {ι σ A}
[decidable_eq ι] [add_right_cancel_monoid ι] [semiring A]
[set_like σ A] [add_submonoid_class σ A] (𝒜 : ι → σ) [graded_ring 𝒜]
{a b : A} {i j : ι} (b_mem : b ∈ 𝒜 j) :
(decompose 𝒜 (a * b) (i + j) : A) = (decompose 𝒜 a i) * b :=
begin
obtain rfl | hb := eq_or_ne b 0,
{ simp },
classical,
lift b to (𝒜 j) using b_mem,
erw [decompose_mul, coe_mul_apply, decompose_coe, support_of _ j b (λ r,by subst r; exact hb rfl),
product_singleton, map_filter, sum_map],
simp_rw [comp, embedding.coe_fn_mk, add_right_cancel_iff, filter_eq'],
refine dite (decompose 𝒜 a i = 0) (λ h, by simp [if_neg (not_mem_support_iff.mpr h), h]) (λ h, _),
erw [if_pos (mem_support_iff.mpr h), finset.sum_singleton, of_eq_same],
refl,
end
lemma direct_sum.decompose_mul_add_left {ι σ A}
[decidable_eq ι] [add_left_cancel_monoid ι] [semiring A]
[set_like σ A] [add_submonoid_class σ A] (𝒜 : ι → σ) [graded_ring 𝒜]
{i j : ι} (a : 𝒜 i) {b : A} :
decompose 𝒜 (↑a * b) (i + j) =
@graded_monoid.ghas_mul.mul ι (λ i, 𝒜 i) _ _ _ _ a (decompose 𝒜 b j) :=
subtype.ext $ direct_sum.coe_decompose_mul_add_of_left_mem 𝒜 a.2
lemma direct_sum.decompose_mul_add_right {ι σ A}
[decidable_eq ι] [add_right_cancel_monoid ι] [semiring A]
[set_like σ A] [add_submonoid_class σ A] (𝒜 : ι → σ) [graded_ring 𝒜]
{i j : ι} {a : A} (b : 𝒜 j) :
decompose 𝒜 (a * ↑b) (i + j) =
@graded_monoid.ghas_mul.mul ι (λ i, 𝒜 i) _ _ _ _ (decompose 𝒜 a i) b :=
subtype.ext $ direct_sum.coe_decompose_mul_add_of_right_mem 𝒜 b.2
end add_cancel_monoid
section graded_algebra
variables [decidable_eq ι] [add_monoid ι] [comm_semiring R] [semiring A] [algebra R A]
variables (𝒜 : ι → submodule R A)
/-- A special case of `graded_ring` with `σ = submodule R A`. This is useful both because it
can avoid typeclass search, and because it provides a more concise name. -/
@[reducible]
def graded_algebra := graded_ring 𝒜
/-- A helper to construct a `graded_algebra` when the `set_like.graded_monoid` structure is already
available. This makes the `left_inv` condition easier to prove, and phrases the `right_inv`
condition in a way that allows custom `@[ext]` lemmas to apply.
See note [reducible non-instances]. -/
@[reducible]
def graded_algebra.of_alg_hom [set_like.graded_monoid 𝒜] (decompose : A →ₐ[R] ⨁ i, 𝒜 i)
(right_inv : (direct_sum.coe_alg_hom 𝒜).comp decompose = alg_hom.id R A)
(left_inv : ∀ i (x : 𝒜 i), decompose (x : A) = direct_sum.of (λ i, ↥(𝒜 i)) i x) :
graded_algebra 𝒜 :=
{ decompose' := decompose,
left_inv := alg_hom.congr_fun right_inv,
right_inv := begin
suffices : decompose.comp (direct_sum.coe_alg_hom 𝒜) = alg_hom.id _ _,
from alg_hom.congr_fun this,
ext i x : 2,
exact (decompose.congr_arg $ direct_sum.coe_alg_hom_of _ _ _).trans (left_inv i x),
end}
variable [graded_algebra 𝒜]
namespace direct_sum
/-- If `A` is graded by `ι` with degree `i` component `𝒜 i`, then it is isomorphic as
an algebra to a direct sum of components. -/
@[simps]
def decompose_alg_equiv : A ≃ₐ[R] ⨁ i, 𝒜 i := alg_equiv.symm
{ map_mul' := (coe_alg_hom 𝒜).map_mul,
map_add' := (coe_alg_hom 𝒜).map_add,
commutes' := (coe_alg_hom 𝒜).commutes,
..(decompose_add_equiv 𝒜).symm }
end direct_sum
open direct_sum
/-- The projection maps of graded algebra-/
def graded_algebra.proj (𝒜 : ι → submodule R A) [graded_algebra 𝒜] (i : ι) : A →ₗ[R] A :=
(𝒜 i).subtype.comp $
(dfinsupp.lapply i).comp $
(decompose_alg_equiv 𝒜).to_alg_hom.to_linear_map
@[simp] lemma graded_algebra.proj_apply (i : ι) (r : A) :
graded_algebra.proj 𝒜 i r = (decompose 𝒜 r : ⨁ i, 𝒜 i) i := rfl
lemma graded_algebra.proj_recompose (a : ⨁ i, 𝒜 i) (i : ι) :
graded_algebra.proj 𝒜 i ((decompose 𝒜).symm a) =
(decompose 𝒜).symm (of _ i (a i)) :=
by rw [graded_algebra.proj_apply, decompose_symm_of, equiv.apply_symm_apply]
lemma graded_algebra.mem_support_iff [decidable_eq A] (r : A) (i : ι) :
i ∈ (decompose 𝒜 r).support ↔ graded_algebra.proj 𝒜 i r ≠ 0 :=
dfinsupp.mem_support_iff.trans submodule.coe_eq_zero.not.symm
end graded_algebra
section canonical_order
open graded_ring set_like.graded_monoid direct_sum
variables [semiring A] [decidable_eq ι]
variables [canonically_ordered_add_monoid ι]
variables [set_like σ A] [add_submonoid_class σ A] (𝒜 : ι → σ) [graded_ring 𝒜]
/--
If `A` is graded by a canonically ordered add monoid, then the projection map `x ↦ x₀` is a ring
homomorphism.
-/
@[simps]
def graded_ring.proj_zero_ring_hom : A →+* A :=
{ to_fun := λ a, decompose 𝒜 a 0,
map_one' := decompose_of_mem_same 𝒜 one_mem,
map_zero' := by { rw decompose_zero, refl },
map_add' := λ _ _, by { rw decompose_add, refl },
map_mul' := begin
refine direct_sum.decomposition.induction_on 𝒜 (λ x, _) _ _,
{ simp only [zero_mul, decompose_zero, zero_apply, add_submonoid_class.coe_zero] },
{ rintros i ⟨c, hc⟩,
refine direct_sum.decomposition.induction_on 𝒜 _ _ _,
{ simp only [mul_zero, decompose_zero, zero_apply, add_submonoid_class.coe_zero] },
{ rintros j ⟨c', hc'⟩,
{ simp only [subtype.coe_mk],
by_cases h : i + j = 0,
{ rw [decompose_of_mem_same 𝒜 (show c * c' ∈ 𝒜 0, from h ▸ mul_mem hc hc'),
decompose_of_mem_same 𝒜 (show c ∈ 𝒜 0, from (add_eq_zero_iff.mp h).1 ▸ hc),
decompose_of_mem_same 𝒜 (show c' ∈ 𝒜 0, from (add_eq_zero_iff.mp h).2 ▸ hc')] },
{ rw [decompose_of_mem_ne 𝒜 (mul_mem hc hc') h],
cases (show i ≠ 0 ∨ j ≠ 0, by rwa [add_eq_zero_iff, not_and_distrib] at h) with h' h',
{ simp only [decompose_of_mem_ne 𝒜 hc h', zero_mul] },
{ simp only [decompose_of_mem_ne 𝒜 hc' h', mul_zero] } } }, },
{ intros _ _ hd he,
simp only [mul_add, decompose_add, add_apply, add_mem_class.coe_add, hd, he] }, },
{ rintros _ _ ha hb _,
simp only [add_mul, decompose_add, add_apply, add_mem_class.coe_add, ha, hb], },
end }
end canonical_order
|
c1b9472284f1265a888f149a61b7d1bd8a9d54c3 | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/field_theory/perfect_closure.lean | 8df3d17a41cb3024acdfdaa57369fb6ac8a6fe0a | [
"Apache-2.0"
] | permissive | waynemunro/mathlib | e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552 | 065a70810b5480d584033f7bbf8e0409480c2118 | refs/heads/master | 1,693,417,182,397 | 1,634,644,781,000 | 1,634,644,781,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 17,396 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Yury Kudryashov
-/
import algebra.char_p.basic
import data.equiv.ring
import algebra.group_with_zero.power
import algebra.iterate_hom
/-!
# The perfect closure of a field
-/
universes u v
open function
section defs
variables (R : Type u) [comm_semiring R] (p : ℕ) [fact p.prime] [char_p R p]
/-- A perfect ring is a ring of characteristic p that has p-th root. -/
class perfect_ring : Type u :=
(pth_root' : R → R)
(frobenius_pth_root' : ∀ x, frobenius R p (pth_root' x) = x)
(pth_root_frobenius' : ∀ x, pth_root' (frobenius R p x) = x)
/-- Frobenius automorphism of a perfect ring. -/
def frobenius_equiv [perfect_ring R p] : R ≃+* R :=
{ inv_fun := perfect_ring.pth_root' p,
left_inv := perfect_ring.pth_root_frobenius',
right_inv := perfect_ring.frobenius_pth_root',
.. frobenius R p }
/-- `p`-th root of an element in a `perfect_ring` as a `ring_hom`. -/
def pth_root [perfect_ring R p] : R →+* R :=
(frobenius_equiv R p).symm
end defs
section
variables {R : Type u} [comm_semiring R] {S : Type v} [comm_semiring S] (f : R →* S) (g : R →+* S)
{p : ℕ} [fact p.prime] [char_p R p] [perfect_ring R p] [char_p S p] [perfect_ring S p]
@[simp] lemma coe_frobenius_equiv : ⇑(frobenius_equiv R p) = frobenius R p := rfl
@[simp] lemma coe_frobenius_equiv_symm : ⇑(frobenius_equiv R p).symm = pth_root R p := rfl
@[simp] theorem frobenius_pth_root (x : R) : frobenius R p (pth_root R p x) = x :=
(frobenius_equiv R p).apply_symm_apply x
@[simp] theorem pth_root_pow_p (x : R) : pth_root R p x ^ p = x :=
frobenius_pth_root x
@[simp] theorem pth_root_frobenius (x : R) : pth_root R p (frobenius R p x) = x :=
(frobenius_equiv R p).symm_apply_apply x
@[simp] theorem pth_root_pow_p' (x : R) : pth_root R p (x ^ p) = x :=
pth_root_frobenius x
theorem left_inverse_pth_root_frobenius : left_inverse (pth_root R p) (frobenius R p) :=
pth_root_frobenius
theorem right_inverse_pth_root_frobenius : function.right_inverse (pth_root R p) (frobenius R p) :=
frobenius_pth_root
theorem commute_frobenius_pth_root : function.commute (frobenius R p) (pth_root R p) :=
λ x, (frobenius_pth_root x).trans (pth_root_frobenius x).symm
theorem eq_pth_root_iff {x y : R} : x = pth_root R p y ↔ frobenius R p x = y :=
(frobenius_equiv R p).to_equiv.eq_symm_apply
theorem pth_root_eq_iff {x y : R} : pth_root R p x = y ↔ x = frobenius R p y :=
(frobenius_equiv R p).to_equiv.symm_apply_eq
theorem monoid_hom.map_pth_root (x : R) : f (pth_root R p x) = pth_root S p (f x) :=
eq_pth_root_iff.2 $ by rw [← f.map_frobenius, frobenius_pth_root]
theorem monoid_hom.map_iterate_pth_root (x : R) (n : ℕ) :
f (pth_root R p^[n] x) = (pth_root S p^[n] (f x)) :=
semiconj.iterate_right f.map_pth_root n x
theorem ring_hom.map_pth_root (x : R) :
g (pth_root R p x) = pth_root S p (g x) :=
g.to_monoid_hom.map_pth_root x
theorem ring_hom.map_iterate_pth_root (x : R) (n : ℕ) :
g (pth_root R p^[n] x) = (pth_root S p^[n] (g x)) :=
g.to_monoid_hom.map_iterate_pth_root x n
variables (p)
lemma injective_pow_p {x y : R} (hxy : x ^ p = y ^ p) : x = y :=
left_inverse_pth_root_frobenius.injective hxy
end
section
variables (K : Type u) [comm_ring K] (p : ℕ) [fact p.prime] [char_p K p]
/-- `perfect_closure K p` is the quotient by this relation. -/
@[mk_iff] inductive perfect_closure.r : (ℕ × K) → (ℕ × K) → Prop
| intro : ∀ n x, perfect_closure.r (n, x) (n+1, frobenius K p x)
/-- The perfect closure is the smallest extension that makes frobenius surjective. -/
def perfect_closure : Type u := quot (perfect_closure.r K p)
end
namespace perfect_closure
variables (K : Type u)
section ring
variables [comm_ring K] (p : ℕ) [fact p.prime] [char_p K p]
/-- Constructor for `perfect_closure`. -/
def mk (x : ℕ × K) : perfect_closure K p := quot.mk (r K p) x
@[simp] lemma quot_mk_eq_mk (x : ℕ × K) :
(quot.mk (r K p) x : perfect_closure K p) = mk K p x := rfl
variables {K p}
/-- Lift a function `ℕ × K → L` to a function on `perfect_closure K p`. -/
@[elab_as_eliminator]
def lift_on {L : Type*} (x : perfect_closure K p) (f : ℕ × K → L)
(hf : ∀ x y, r K p x y → f x = f y) : L :=
quot.lift_on x f hf
@[simp] lemma lift_on_mk {L : Sort*} (f : ℕ × K → L)
(hf : ∀ x y, r K p x y → f x = f y) (x : ℕ × K) :
(mk K p x).lift_on f hf = f x :=
rfl
@[elab_as_eliminator]
lemma induction_on (x : perfect_closure K p) {q : perfect_closure K p → Prop}
(h : ∀ x, q (mk K p x)) : q x :=
quot.induction_on x h
variables (K p)
private lemma mul_aux_left (x1 x2 y : ℕ × K) (H : r K p x1 x2) :
mk K p (x1.1 + y.1, ((frobenius K p)^[y.1] x1.2) * ((frobenius K p)^[x1.1] y.2)) =
mk K p (x2.1 + y.1, ((frobenius K p)^[y.1] x2.2) * ((frobenius K p)^[x2.1] y.2)) :=
match x1, x2, H with
| _, _, r.intro n x := quot.sound $ by rw [← iterate_succ_apply, iterate_succ',
iterate_succ', ← frobenius_mul, nat.succ_add]; apply r.intro
end
private lemma mul_aux_right (x y1 y2 : ℕ × K) (H : r K p y1 y2) :
mk K p (x.1 + y1.1, ((frobenius K p)^[y1.1] x.2) * ((frobenius K p)^[x.1] y1.2)) =
mk K p (x.1 + y2.1, ((frobenius K p)^[y2.1] x.2) * ((frobenius K p)^[x.1] y2.2)) :=
match y1, y2, H with
| _, _, r.intro n y := quot.sound $ by rw [← iterate_succ_apply, iterate_succ',
iterate_succ', ← frobenius_mul]; apply r.intro
end
instance : has_mul (perfect_closure K p) :=
⟨quot.lift (λ x:ℕ×K, quot.lift (λ y:ℕ×K, mk K p
(x.1 + y.1, ((frobenius K p)^[y.1] x.2) * ((frobenius K p)^[x.1] y.2))) (mul_aux_right K p x))
(λ x1 x2 (H : r K p x1 x2), funext $ λ e, quot.induction_on e $ λ y,
mul_aux_left K p x1 x2 y H)⟩
@[simp] lemma mk_mul_mk (x y : ℕ × K) :
mk K p x * mk K p y = mk K p
(x.1 + y.1, ((frobenius K p)^[y.1] x.2) * ((frobenius K p)^[x.1] y.2)) :=
rfl
instance : comm_monoid (perfect_closure K p) :=
{ mul_assoc := λ e f g, quot.induction_on e $ λ ⟨m, x⟩, quot.induction_on f $ λ ⟨n, y⟩,
quot.induction_on g $ λ ⟨s, z⟩, congr_arg (quot.mk _) $
by simp only [add_assoc, mul_assoc, ring_hom.iterate_map_mul,
← iterate_add_apply, add_comm, add_left_comm],
one := mk K p (0, 1),
one_mul := λ e, quot.induction_on e (λ ⟨n, x⟩, congr_arg (quot.mk _) $
by simp only [ring_hom.iterate_map_one, iterate_zero_apply, one_mul, zero_add]),
mul_one := λ e, quot.induction_on e (λ ⟨n, x⟩, congr_arg (quot.mk _) $
by simp only [ring_hom.iterate_map_one, iterate_zero_apply, mul_one, add_zero]),
mul_comm := λ e f, quot.induction_on e (λ ⟨m, x⟩, quot.induction_on f (λ ⟨n, y⟩,
congr_arg (quot.mk _) $ by simp only [add_comm, mul_comm])),
.. (infer_instance : has_mul (perfect_closure K p)) }
lemma one_def : (1 : perfect_closure K p) = mk K p (0, 1) := rfl
instance : inhabited (perfect_closure K p) := ⟨1⟩
private lemma add_aux_left (x1 x2 y : ℕ × K) (H : r K p x1 x2) :
mk K p (x1.1 + y.1, ((frobenius K p)^[y.1] x1.2) + ((frobenius K p)^[x1.1] y.2)) =
mk K p (x2.1 + y.1, ((frobenius K p)^[y.1] x2.2) + ((frobenius K p)^[x2.1] y.2)) :=
match x1, x2, H with
| _, _, r.intro n x := quot.sound $ by rw [← iterate_succ_apply, iterate_succ',
iterate_succ', ← frobenius_add, nat.succ_add]; apply r.intro
end
private lemma add_aux_right (x y1 y2 : ℕ × K) (H : r K p y1 y2) :
mk K p (x.1 + y1.1, ((frobenius K p)^[y1.1] x.2) + ((frobenius K p)^[x.1] y1.2)) =
mk K p (x.1 + y2.1, ((frobenius K p)^[y2.1] x.2) + ((frobenius K p)^[x.1] y2.2)) :=
match y1, y2, H with
| _, _, r.intro n y := quot.sound $ by rw [← iterate_succ_apply, iterate_succ',
iterate_succ', ← frobenius_add]; apply r.intro
end
instance : has_add (perfect_closure K p) :=
⟨quot.lift (λ x:ℕ×K, quot.lift (λ y:ℕ×K, mk K p
(x.1 + y.1, ((frobenius K p)^[y.1] x.2) + ((frobenius K p)^[x.1] y.2))) (add_aux_right K p x))
(λ x1 x2 (H : r K p x1 x2), funext $ λ e, quot.induction_on e $ λ y,
add_aux_left K p x1 x2 y H)⟩
@[simp] lemma mk_add_mk (x y : ℕ × K) :
mk K p x + mk K p y =
mk K p (x.1 + y.1, ((frobenius K p)^[y.1] x.2) + ((frobenius K p)^[x.1] y.2)) := rfl
instance : has_neg (perfect_closure K p) :=
⟨quot.lift (λ x:ℕ×K, mk K p (x.1, -x.2)) (λ x y (H : r K p x y), match x, y, H with
| _, _, r.intro n x := quot.sound $ by rw ← frobenius_neg; apply r.intro
end)⟩
@[simp] lemma neg_mk (x : ℕ × K) : - mk K p x = mk K p (x.1, -x.2) := rfl
instance : has_zero (perfect_closure K p) := ⟨mk K p (0, 0)⟩
lemma zero_def : (0 : perfect_closure K p) = mk K p (0, 0) := rfl
theorem mk_zero (n : ℕ) : mk K p (n, 0) = 0 :=
by induction n with n ih; [refl, rw ← ih]; symmetry; apply quot.sound;
have := r.intro n (0:K); rwa [frobenius_zero K p] at this
theorem r.sound (m n : ℕ) (x y : K) (H : frobenius K p^[m] x = y) :
mk K p (n, x) = mk K p (m + n, y) :=
by subst H; induction m with m ih; [simp only [zero_add, iterate_zero_apply],
rw [ih, nat.succ_add, iterate_succ']]; apply quot.sound; apply r.intro
instance : comm_ring (perfect_closure K p) :=
{ add_assoc := λ e f g, quot.induction_on e $ λ ⟨m, x⟩, quot.induction_on f $ λ ⟨n, y⟩,
quot.induction_on g $ λ ⟨s, z⟩, congr_arg (quot.mk _) $
by simp only [ring_hom.iterate_map_add, ← iterate_add_apply, add_assoc, add_comm s _],
zero := 0,
zero_add := λ e, quot.induction_on e (λ ⟨n, x⟩, congr_arg (quot.mk _) $
by simp only [ring_hom.iterate_map_zero, iterate_zero_apply, zero_add]),
add_zero := λ e, quot.induction_on e (λ ⟨n, x⟩, congr_arg (quot.mk _) $
by simp only [ring_hom.iterate_map_zero, iterate_zero_apply, add_zero]),
sub_eq_add_neg := λ a b, rfl,
add_left_neg := λ e, by exact quot.induction_on e (λ ⟨n, x⟩,
by simp only [quot_mk_eq_mk, neg_mk, mk_add_mk,
ring_hom.iterate_map_neg, add_left_neg, mk_zero]),
add_comm := λ e f, quot.induction_on e (λ ⟨m, x⟩, quot.induction_on f (λ ⟨n, y⟩,
congr_arg (quot.mk _) $ by simp only [add_comm])),
left_distrib := λ e f g, quot.induction_on e $ λ ⟨m, x⟩, quot.induction_on f $ λ ⟨n, y⟩,
quot.induction_on g $ λ ⟨s, z⟩, show quot.mk _ _ = quot.mk _ _,
by simp only [add_assoc, add_comm, add_left_comm]; apply r.sound;
simp only [ring_hom.iterate_map_mul, ring_hom.iterate_map_add,
← iterate_add_apply, mul_add, add_comm, add_left_comm],
right_distrib := λ e f g, quot.induction_on e $ λ ⟨m, x⟩, quot.induction_on f $ λ ⟨n, y⟩,
quot.induction_on g $ λ ⟨s, z⟩, show quot.mk _ _ = quot.mk _ _,
by simp only [add_assoc, add_comm _ s, add_left_comm _ s]; apply r.sound;
simp only [ring_hom.iterate_map_mul, ring_hom.iterate_map_add,
← iterate_add_apply, add_mul, add_comm, add_left_comm],
.. (infer_instance : has_add (perfect_closure K p)),
.. (infer_instance : has_neg (perfect_closure K p)),
.. (infer_instance : comm_monoid (perfect_closure K p)) }
theorem eq_iff' (x y : ℕ × K) : mk K p x = mk K p y ↔
∃ z, (frobenius K p^[y.1 + z] x.2) = (frobenius K p^[x.1 + z] y.2) :=
begin
split,
{ intro H,
replace H := quot.exact _ H,
induction H,
case eqv_gen.rel : x y H
{ cases H with n x, exact ⟨0, rfl⟩ },
case eqv_gen.refl : H
{ exact ⟨0, rfl⟩ },
case eqv_gen.symm : x y H ih
{ cases ih with w ih, exact ⟨w, ih.symm⟩ },
case eqv_gen.trans : x y z H1 H2 ih1 ih2
{ cases ih1 with z1 ih1,
cases ih2 with z2 ih2,
existsi z2+(y.1+z1),
rw [← add_assoc, iterate_add_apply, ih1],
rw [← iterate_add_apply, add_comm, iterate_add_apply, ih2],
rw [← iterate_add_apply],
simp only [add_comm, add_left_comm] } },
intro H,
cases x with m x,
cases y with n y,
cases H with z H, dsimp only at H,
rw [r.sound K p (n+z) m x _ rfl, r.sound K p (m+z) n y _ rfl, H],
rw [add_assoc, add_comm, add_comm z]
end
theorem nat_cast (n x : ℕ) : (x : perfect_closure K p) = mk K p (n, x) :=
begin
induction n with n ih,
{ induction x with x ih, {refl},
rw [nat.cast_succ, nat.cast_succ, ih], refl },
rw ih, apply quot.sound,
conv {congr, skip, skip, rw ← frobenius_nat_cast K p x},
apply r.intro
end
theorem int_cast (x : ℤ) : (x : perfect_closure K p) = mk K p (0, x) :=
by induction x; simp only [int.cast_of_nat, int.cast_neg_succ_of_nat, nat_cast K p 0]; refl
theorem nat_cast_eq_iff (x y : ℕ) : (x : perfect_closure K p) = y ↔ (x : K) = y :=
begin
split; intro H,
{ rw [nat_cast K p 0, nat_cast K p 0, eq_iff'] at H,
cases H with z H,
simpa only [zero_add, iterate_fixed (frobenius_nat_cast K p _)] using H },
rw [nat_cast K p 0, nat_cast K p 0, H]
end
instance : char_p (perfect_closure K p) p :=
begin
constructor, intro x, rw ← char_p.cast_eq_zero_iff K,
rw [← nat.cast_zero, nat_cast_eq_iff, nat.cast_zero]
end
theorem frobenius_mk (x : ℕ × K) :
(frobenius (perfect_closure K p) p : perfect_closure K p → perfect_closure K p)
(mk K p x) = mk _ _ (x.1, x.2^p) :=
begin
simp only [frobenius_def], cases x with n x, dsimp only,
suffices : ∀ p':ℕ, mk K p (n, x) ^ p' = mk K p (n, x ^ p'),
{ apply this },
intro p, induction p with p ih,
case nat.zero { apply r.sound, rw [(frobenius _ _).iterate_map_one, pow_zero] },
case nat.succ {
rw [pow_succ, ih],
symmetry,
apply r.sound,
simp only [pow_succ, (frobenius _ _).iterate_map_mul] }
end
/-- Embedding of `K` into `perfect_closure K p` -/
def of : K →+* perfect_closure K p :=
{ to_fun := λ x, mk _ _ (0, x),
map_one' := rfl,
map_mul' := λ x y, rfl,
map_zero' := rfl,
map_add' := λ x y, rfl }
lemma of_apply (x : K) : of K p x = mk _ _ (0, x) := rfl
end ring
theorem eq_iff [comm_ring K] [integral_domain K] (p : ℕ) [fact p.prime] [char_p K p]
(x y : ℕ × K) : quot.mk (r K p) x = quot.mk (r K p) y ↔
(frobenius K p^[y.1] x.2) = (frobenius K p^[x.1] y.2) :=
(eq_iff' K p x y).trans ⟨λ ⟨z, H⟩, (frobenius_inj K p).iterate z $
by simpa only [add_comm, iterate_add] using H,
λ H, ⟨0, H⟩⟩
section field
variables [field K] (p : ℕ) [fact p.prime] [char_p K p]
instance : has_inv (perfect_closure K p) :=
⟨quot.lift (λ x:ℕ×K, quot.mk (r K p) (x.1, x.2⁻¹)) (λ x y (H : r K p x y), match x, y, H with
| _, _, r.intro n x := quot.sound $ by { simp only [frobenius_def], rw ← inv_pow₀, apply r.intro }
end)⟩
instance : field (perfect_closure K p) :=
{ exists_pair_ne := ⟨0, 1, λ H, zero_ne_one ((eq_iff _ _ _ _).1 H)⟩,
mul_inv_cancel := λ e, induction_on e $ λ ⟨m, x⟩ H,
have _ := mt (eq_iff _ _ _ _).2 H, (eq_iff _ _ _ _).2
(by simp only [(frobenius _ _).iterate_map_one, (frobenius K p).iterate_map_zero,
iterate_zero_apply, ← (frobenius _ p).iterate_map_mul] at this ⊢;
rw [mul_inv_cancel this, (frobenius _ _).iterate_map_one]),
inv_zero := congr_arg (quot.mk (r K p)) (by rw [inv_zero]),
.. (infer_instance : has_inv (perfect_closure K p)),
.. (infer_instance : comm_ring (perfect_closure K p)) }
instance : perfect_ring (perfect_closure K p) p :=
{ pth_root' := λ e, lift_on e (λ x, mk K p (x.1 + 1, x.2)) (λ x y H,
match x, y, H with
| _, _, r.intro n x := quot.sound (r.intro _ _)
end),
frobenius_pth_root' := λ e, induction_on e (λ ⟨n, x⟩,
by { simp only [lift_on_mk, frobenius_mk], exact (quot.sound $ r.intro _ _).symm }),
pth_root_frobenius' := λ e, induction_on e (λ ⟨n, x⟩,
by { simp only [lift_on_mk, frobenius_mk], exact (quot.sound $ r.intro _ _).symm }) }
theorem eq_pth_root (x : ℕ × K) :
mk K p x = (pth_root (perfect_closure K p) p^[x.1] (of K p x.2)) :=
begin
rcases x with ⟨m, x⟩,
induction m with m ih, {refl},
rw [iterate_succ_apply', ← ih]; refl
end
/-- Given a field `K` of characteristic `p` and a perfect ring `L` of the same characteristic,
any homomorphism `K →+* L` can be lifted to `perfect_closure K p`. -/
def lift (L : Type v) [comm_semiring L] [char_p L p] [perfect_ring L p] :
(K →+* L) ≃ (perfect_closure K p →+* L) :=
begin
have := left_inverse_pth_root_frobenius.iterate,
refine_struct { .. },
field to_fun { intro f,
refine_struct { .. },
field to_fun { refine λ e, lift_on e (λ x, pth_root L p^[x.1] (f x.2)) _,
rintro a b ⟨n⟩,
simp only [f.map_frobenius, iterate_succ_apply, pth_root_frobenius] },
field map_one' { exact f.map_one },
field map_zero' { exact f.map_zero },
field map_mul' { rintro ⟨x⟩ ⟨y⟩,
simp only [quot_mk_eq_mk, lift_on_mk, mk_mul_mk, ring_hom.map_iterate_frobenius,
ring_hom.iterate_map_mul, ring_hom.map_mul],
rw [iterate_add_apply, this _ _, add_comm, iterate_add_apply, this _ _] },
field map_add' { rintro ⟨x⟩ ⟨y⟩,
simp only [quot_mk_eq_mk, lift_on_mk, mk_add_mk, ring_hom.map_iterate_frobenius,
ring_hom.iterate_map_add, ring_hom.map_add],
rw [iterate_add_apply, this _ _, add_comm x.1, iterate_add_apply, this _ _] } },
field inv_fun { exact λ f, f.comp (of K p) },
field left_inv { intro f, ext x, refl },
field right_inv { intro f, ext ⟨x⟩,
simp only [ring_hom.coe_mk, quot_mk_eq_mk, ring_hom.comp_apply, lift_on_mk],
rw [eq_pth_root, ring_hom.map_iterate_pth_root] }
end
end field
end perfect_closure
|
9dc3fa156b4372ccbaac1ebd2ef6637c9c144dbf | aa2345b30d710f7e75f13157a35845ee6d48c017 | /data/real/ennreal.lean | f174106c8bbcf6bc9855823ebab3c1b3f92f6e3f | [
"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 | 16,557 | 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
Extended non-negative reals
-/
import data.real.nnreal order.bounds
noncomputable theory
open classical set lattice
local attribute [instance] prop_decidable
variables {α : Type*} {β : Type*}
/-- The extended nonnegative real numbers. This is usually denoted [0, ∞],
and is relevant as the codomain of a measure. -/
def ennreal := with_top nnreal
local notation `∞` := (⊤ : ennreal)
namespace ennreal
variables {a b c d : ennreal} {r p q : nnreal}
instance : canonically_ordered_comm_semiring ennreal := by unfold ennreal; apply_instance
instance : decidable_linear_order ennreal := by unfold ennreal; apply_instance
instance : complete_linear_order ennreal := by unfold ennreal; apply_instance
instance : inhabited ennreal := ⟨0⟩
instance : densely_ordered ennreal := with_top.densely_ordered
instance : has_coe nnreal ennreal := ⟨ option.some ⟩
lemma none_eq_top : (none : ennreal) = (⊤ : ennreal) := rfl
lemma some_eq_coe (a : nnreal) : (some a : ennreal) = (↑a : ennreal) := rfl
/-- `to_nnreal x` returns `x` if it is real, otherwise 0. -/
protected def to_nnreal : ennreal → nnreal
| (some r) := r
| none := 0
@[simp] lemma to_nnreal_coe : (r : ennreal).to_nnreal = r := rfl
@[simp] lemma coe_to_nnreal : ∀{a:ennreal}, a ≠ ∞ → ↑(a.to_nnreal) = a
| (some r) h := rfl
| none h := (h rfl).elim
lemma coe_to_nnreal_le_self : ∀{a:ennreal}, ↑(a.to_nnreal) ≤ a
| (some r) := by rw [some_eq_coe, to_nnreal_coe]; exact le_refl _
| none := le_top
@[simp] lemma top_to_nnreal : ∞.to_nnreal = 0 := rfl
lemma forall_ennreal {p : ennreal → Prop} : (∀a, p a) ↔ (∀r:nnreal, p r) ∧ p ∞ :=
⟨assume h, ⟨assume r, h _, h _⟩,
assume ⟨h₁, h₂⟩ a, match a with some r := h₁ _ | none := h₂ end⟩
@[simp] lemma coe_zero : ↑(0 : nnreal) = (0 : ennreal) := rfl
@[simp] lemma coe_one : ↑(1 : nnreal) = (1 : ennreal) := rfl
@[simp] lemma coe_ne_top : (r : ennreal) ≠ ∞ := with_top.coe_ne_top
@[simp] lemma top_ne_coe : ∞ ≠ (r : ennreal) := with_top.top_ne_coe
@[simp] lemma zero_ne_top : 0 ≠ ∞ := coe_ne_top
@[simp] lemma top_ne_zero : ∞ ≠ 0 := top_ne_coe
@[simp] lemma one_ne_top : 1 ≠ ∞ := coe_ne_top
@[simp] lemma top_ne_one : ∞ ≠ 1 := top_ne_coe
@[simp] lemma coe_eq_coe : (↑r : ennreal) = ↑q ↔ r = q := with_top.coe_eq_coe
@[simp] lemma coe_le_coe : (↑r : ennreal) ≤ ↑q ↔ r ≤ q := with_top.coe_le_coe
@[simp] lemma coe_lt_coe : (↑r : ennreal) < ↑q ↔ r < q := with_top.coe_lt_coe
@[simp] lemma coe_eq_zero : (↑r : ennreal) = 0 ↔ r = 0 := coe_eq_coe
@[simp] lemma zero_eq_coe : 0 = (↑r : ennreal) ↔ 0 = r := coe_eq_coe
@[simp] lemma coe_eq_one : (↑r : ennreal) = 1 ↔ r = 1 := coe_eq_coe
@[simp] lemma one_eq_coe : 1 = (↑r : ennreal) ↔ 1 = r := coe_eq_coe
@[simp] lemma coe_add : ↑(r + p) = (r + p : ennreal) := with_top.coe_add
@[simp] lemma coe_mul : ↑(r * p) = (r * p : ennreal) := with_top.coe_mul
@[simp] lemma add_top : a + ∞ = ∞ := with_top.add_top
@[simp] lemma top_add : ∞ + a = ∞ := with_top.top_add
lemma coe_nat : ∀n:ℕ, (n : ennreal) = (n : nnreal)
| 0 := rfl
| (n + 1) := by simp [coe_nat n]
lemma add_eq_top : a + b = ∞ ↔ a = ∞ ∨ b = ∞ := with_top.add_eq_top _ _
lemma mul_top : a * ∞ = (if a = 0 then 0 else ∞) :=
begin split_ifs, { simp [h] }, { exact with_top.mul_top h } end
lemma top_mul : ∞ * a = (if a = 0 then 0 else ∞) :=
begin split_ifs, { simp [h] }, { exact with_top.top_mul h } end
@[simp] lemma top_mul_top : ∞ * ∞ = ∞ := with_top.top_mul_top
@[simp] lemma coe_finset_sum {s : finset α} {f : α → nnreal} : ↑(s.sum f) = (s.sum (λa, f a) : ennreal) :=
(finset.sum_hom coe coe_zero @coe_add).symm
@[simp] lemma coe_finset_prod {s : finset α} {f : α → nnreal} : ↑(s.prod f) = (s.prod (λa, f a) : ennreal) :=
(finset.prod_hom coe coe_one @coe_mul).symm
@[simp] lemma bot_eq_zero : (⊥ : ennreal) = 0 := rfl
section order
@[simp] lemma coe_lt_top : coe r < ∞ := with_top.coe_lt_top r
@[simp] lemma not_top_le_coe : ¬ (⊤:ennreal) ≤ ↑r := with_top.not_top_le_coe r
@[simp] lemma zero_lt_coe_iff : 0 < (↑p : ennreal) ↔ 0 < p := coe_lt_coe
@[simp] lemma one_le_coe_iff : (1:ennreal) ≤ ↑r ↔ 1 ≤ r := coe_le_coe
@[simp] lemma coe_le_one_iff : ↑r ≤ (1:ennreal) ↔ r ≤ 1 := coe_le_coe
@[simp] lemma coe_lt_one_iff : (↑p : ennreal) < 1 ↔ p < 1 := coe_lt_coe
@[simp] lemma one_lt_zero_iff : 1 < (↑p : ennreal) ↔ 1 < p := coe_lt_coe
lemma le_coe_iff : a ≤ ↑r ↔ (∃p:nnreal, a = p ∧ p ≤ r) := with_top.le_coe_iff r a
lemma coe_le_iff : ↑r ≤ a ↔ (∀p:nnreal, a = p → r ≤ p) := with_top.coe_le_iff r a
lemma lt_iff_exists_coe : a < b ↔ (∃p:nnreal, a = p ∧ ↑p < b) := with_top.lt_iff_exists_coe a b
-- TODO: move to canonically ordered semiring ...
protected lemma zero_lt_one : 0 < (1 : ennreal) := zero_lt_coe_iff.mpr zero_lt_one
@[simp] lemma not_lt_zero : ¬ a < 0 := by simp
lemma add_lt_add_iff_left : a < ⊤ → (a + c < a + b ↔ c < b) :=
with_top.add_lt_add_iff_left
lemma lt_add_right (ha : a < ⊤) (hb : 0 < b) : a < a + b :=
by rwa [← add_lt_add_iff_left ha, add_zero] at hb
lemma le_of_forall_epsilon_le : ∀{a b : ennreal}, (∀ε:nnreal, ε > 0 → b < ∞ → a ≤ b + ε) → a ≤ b
| a none h := le_top
| none (some a) h :=
have (⊤:ennreal) ≤ ↑a + ↑(1:nnreal), from h 1 zero_lt_one coe_lt_top,
by rw [← coe_add] at this; exact (not_top_le_coe this).elim
| (some a) (some b) h :=
by simp only [none_eq_top, some_eq_coe, coe_add.symm, coe_le_coe, coe_lt_top, true_implies_iff] at *;
exact nnreal.le_of_forall_epsilon_le h
protected lemma lt_iff_exists_rat_btwn :
a < b ↔ (∃q:ℚ, 0 ≤ q ∧ a < nnreal.of_real q ∧ (nnreal.of_real q:ennreal) < b) :=
⟨λ h,
begin
rcases lt_iff_exists_coe.1 h with ⟨p, rfl, _⟩,
rcases dense h with ⟨c, pc, cb⟩,
rcases lt_iff_exists_coe.1 cb with ⟨r, rfl, _⟩,
rcases (nnreal.lt_iff_exists_rat_btwn _ _).1 (coe_lt_coe.1 pc) with ⟨q, hq0, pq, qr⟩,
exact ⟨q, hq0, coe_lt_coe.2 pq, lt_trans (coe_lt_coe.2 qr) cb⟩
end,
λ ⟨q, q0, qa, qb⟩, lt_trans qa qb⟩
end order
section complete_lattice
lemma coe_Sup {s : set nnreal} : bdd_above s → (↑(Sup s) : ennreal) = (⨆a∈s, ↑a) := with_top.coe_Sup
lemma coe_Inf {s : set nnreal} : s ≠ ∅ → (↑(Inf s) : ennreal) = (⨅a∈s, ↑a) := with_top.coe_Inf
@[simp] lemma top_mem_upper_bounds {s : set ennreal} : ∞ ∈ upper_bounds s :=
assume x hx, le_top
lemma coe_mem_upper_bounds {s : set nnreal} :
↑r ∈ upper_bounds ((coe : nnreal → ennreal) '' s) ↔ r ∈ upper_bounds s :=
by simp [upper_bounds, ball_image_iff, -mem_image, *] {contextual := tt}
end complete_lattice
section mul
lemma mul_eq_mul_left : a ≠ 0 → a ≠ ⊤ → (a * b = a * c ↔ b = c) :=
begin
cases a; cases b; cases c;
simp [none_eq_top, some_eq_coe, mul_top, top_mul, -coe_mul, coe_mul.symm,
nnreal.mul_eq_mul_left] {contextual := tt},
end
lemma mul_le_mul_left : a ≠ 0 → a ≠ ⊤ → (a * b ≤ a * c ↔ b ≤ c) :=
begin
cases a; cases b; cases c;
simp [none_eq_top, some_eq_coe, mul_top, top_mul, -coe_mul, coe_mul.symm] {contextual := tt},
assume h, exact mul_le_mul_left (zero_lt_iff_ne_zero.2 h)
end
end mul
section sub
instance : has_sub ennreal := ⟨λa b, Inf {d | a ≤ d + b}⟩
lemma coe_sub : ↑(p - r) = (↑p:ennreal) - r :=
le_antisymm
(le_Inf $ assume b (hb : ↑p ≤ b + r), coe_le_iff.2 $
by rintros d rfl; rwa [← coe_add, coe_le_coe, ← nnreal.sub_le_iff_le_add] at hb)
(Inf_le $ show (↑p : ennreal) ≤ ↑(p - r) + ↑r,
by rw [← coe_add, coe_le_coe, ← nnreal.sub_le_iff_le_add])
@[simp] lemma top_sub_coe : ∞ - ↑r = ∞ :=
top_unique $ le_Inf $ by simp [add_eq_top]
@[simp] lemma sub_eq_zero_of_le (h : a ≤ b) : a - b = 0 :=
le_antisymm (Inf_le $ le_add_left h) (zero_le _)
@[simp] lemma zero_sub : 0 - a = 0 :=
le_antisymm (Inf_le $ zero_le _) (zero_le _)
@[simp] lemma sub_infty : a - ∞ = 0 :=
le_antisymm (Inf_le $ by simp) (zero_le _)
lemma sub_le_sub (h₁ : a ≤ b) (h₂ : d ≤ c) : a - c ≤ b - d :=
Inf_le_Inf $ assume e (h : b ≤ e + d),
calc a ≤ b : h₁
... ≤ e + d : h
... ≤ e + c : add_le_add' (le_refl _) h₂
@[simp] lemma add_sub_self : ∀{a b : ennreal}, b < ∞ → (a + b) - b = a
| a none := by simp [none_eq_top]
| none (some b) := by simp [none_eq_top, some_eq_coe]
| (some a) (some b) :=
by simp [some_eq_coe]; rw [← coe_add, ← coe_sub, coe_eq_coe, nnreal.add_sub_cancel]
@[simp] lemma add_sub_self' (h : a < ∞) : (a + b) - a = b :=
by rw [add_comm, add_sub_self h]
lemma add_left_inj (h : a < ∞) : a + b = a + c ↔ b = c :=
⟨λ e, by simpa [h] using congr_arg (λ x, x - a) e, congr_arg _⟩
lemma add_right_inj (h : a < ∞) : b + a = c + a ↔ b = c :=
by rw [add_comm, add_comm c, add_left_inj h]
@[simp] lemma sub_add_cancel_of_le : ∀{a b : ennreal}, b ≤ a → (a - b) + b = a :=
begin
simp [forall_ennreal, le_coe_iff, -add_comm] {contextual := tt},
rintros r p x rfl h,
rw [← coe_sub, ← coe_add, nnreal.sub_add_cancel_of_le h]
end
@[simp] lemma add_sub_cancel_of_le (h : b ≤ a) : b + (a - b) = a :=
by rwa [add_comm, sub_add_cancel_of_le]
lemma sub_add_self_eq_max : (a - b) + b = max a b :=
match le_total a b with
| or.inl h := by simp [h, max_eq_right]
| or.inr h := by simp [h, max_eq_left]
end
@[simp] protected lemma sub_le_iff_le_add : a - b ≤ c ↔ a ≤ c + b :=
iff.intro
(assume h : a - b ≤ c,
calc a ≤ (a - b) + b : by rw [sub_add_self_eq_max]; exact le_max_left _ _
... ≤ c + b : add_le_add' h (le_refl _))
(assume h : a ≤ c + b,
calc a - b ≤ (c + b) - b : sub_le_sub h (le_refl _)
... ≤ c : Inf_le (le_refl (c + b)))
lemma sub_le_self (a b : ennreal) : a - b ≤ a :=
ennreal.sub_le_iff_le_add.2 $ le_add_of_nonneg_right' $ zero_le _
@[simp] lemma sub_zero : a - 0 = a :=
eq.trans (add_zero (a - 0)).symm $ by simp
lemma sub_sub_cancel (h : a < ∞) (h2 : b ≤ a) : a - (a - b) = b :=
by rw [← add_right_inj (lt_of_le_of_lt (sub_le_self _ _) h),
sub_add_cancel_of_le (sub_le_self _ _), add_sub_cancel_of_le h2]
end sub
section inv
instance : has_inv ennreal := ⟨λa, Inf {b | 1 ≤ a * b}⟩
instance : has_div ennreal := ⟨λa b, a * b⁻¹⟩
lemma div_def : a / b = a * b⁻¹ := rfl
@[simp] lemma inv_zero : (0 : ennreal)⁻¹ = ∞ :=
show Inf {b : ennreal | 1 ≤ 0 * b} = ∞, by simp; refl
@[simp] lemma inv_top : (∞ : ennreal)⁻¹ = 0 :=
bot_unique $ le_of_forall_le_of_dense $ λ a (h : a > 0), Inf_le $ by simp [*, ne_of_gt h, top_mul]
@[simp] lemma inv_coe (hr : r ≠ 0) : (r : ennreal)⁻¹ = ↑(r⁻¹ : nnreal) :=
le_antisymm
(Inf_le $ by simp; rw [← coe_mul, nnreal.mul_inv_cancel hr]; exact le_refl 1)
(le_Inf $ assume b (hb : 1 ≤ ↑r * b), coe_le_iff.2 $
by rintros b rfl; rwa [← coe_mul, ← coe_one, coe_le_coe, ← nnreal.inv_le hr] at hb)
@[simp] lemma inv_eq_top : (a)⁻¹ = ∞ ↔ a = 0 :=
by by_cases a = 0; cases a; simp [*, none_eq_top, some_eq_coe] at *
lemma inv_ne_top : (a)⁻¹ ≠ ∞ ↔ a ≠ 0 := by simp
@[simp] lemma inv_eq_zero : (a)⁻¹ = 0 ↔ a = ∞ :=
by by_cases a = 0; cases a; simp [*, none_eq_top, some_eq_coe] at *
lemma inv_ne_zero : (a)⁻¹ ≠ 0 ↔ a ≠ ∞ := by simp
@[simp] lemma inv_inv : ∀{a:ennreal}, (a⁻¹)⁻¹ = a :=
forall_ennreal.mpr $ and.intro (assume r, by by_cases r = 0; simp [*, inv_pos]) (by simp)
lemma le_div_iff_mul_le : ∀{b}, b ≠ 0 → b ≠ ⊤ → (a ≤ c / b ↔ a * b ≤ c)
| none h0 ht := (ht rfl).elim
| (some r) h0 ht :=
begin
have hr : r ≠ 0, from mt coe_eq_coe.2 h0,
rw [← ennreal.mul_le_mul_left h0 ht],
suffices : ↑r * a ≤ (↑r * ↑r⁻¹) * c ↔ a * ↑r ≤ c,
{ simpa [some_eq_coe, div_def, hr, mul_left_comm, mul_comm, mul_assoc] },
rw [← coe_mul, nnreal.mul_inv_cancel hr, coe_one, one_mul, mul_comm]
end
lemma div_le_iff_le_mul (hb0 : b ≠ 0) (hbt : b ≠ ⊤) : (a / b ≤ c ↔ a ≤ c * b) :=
suffices a * b⁻¹ ≤ c ↔ a ≤ c / b⁻¹, by simpa [div_def],
(le_div_iff_mul_le (inv_ne_zero.2 hbt) (inv_ne_top.2 hb0)).symm
lemma inv_le_iff_le_mul : (b = ⊤ → a ≠ 0) → (a = ⊤ → b ≠ 0) → (a⁻¹ ≤ b ↔ 1 ≤ a * b) :=
begin
cases a; cases b; simp [none_eq_top, some_eq_coe, mul_top, top_mul] {contextual := tt},
by_cases a = 0; simp [*, -coe_mul, coe_mul.symm, nnreal.inv_le]
end
@[simp] lemma le_inv_iff_mul_le : a ≤ b⁻¹ ↔ a * b ≤ 1 :=
begin
cases b, { by_cases a = 0; simp [*, none_eq_top, mul_top] },
by_cases b = 0; simp [*, some_eq_coe, le_div_iff_mul_le],
suffices : a ≤ 1 / b ↔ a * b ≤ 1, { simpa [div_def, h] },
exact le_div_iff_mul_le (mt coe_eq_coe.1 h) coe_ne_top
end
lemma mul_inv_cancel : ∀{r : ennreal}, r ≠ 0 → r ≠ ⊤ → r * r⁻¹ = 1 :=
begin
refine forall_ennreal.2 (and.intro (assume r, _) _); simp { contextual := tt},
assume h, rw [← ennreal.coe_mul, nnreal.mul_inv_cancel h, coe_one]
end
lemma mul_le_if_le_inv {a b r : ennreal} (hr₀ : r ≠ 0) (hr₁ : r ≠ ⊤) : (r * a ≤ b ↔ a ≤ r⁻¹ * b) :=
by rw [← @ennreal.mul_le_mul_left _ a _ hr₀ hr₁, ← mul_assoc, mul_inv_cancel hr₀ hr₁, one_mul]
lemma le_of_forall_lt_one_mul_lt : ∀{x y : ennreal}, (∀a<1, a * x ≤ y) → x ≤ y :=
forall_ennreal.2 $ and.intro
(assume r, forall_ennreal.2 $ and.intro
(assume q h, coe_le_coe.2 $ nnreal.le_of_forall_lt_one_mul_lt $ assume a ha,
begin rw [← coe_le_coe, coe_mul], exact h _ (coe_lt_coe.2 ha) end)
(assume h, le_top))
(assume r hr,
have ((1 / 2 : nnreal) : ennreal) * ⊤ ≤ r :=
hr _ (coe_lt_coe.2 ((nnreal.coe_lt (1/2) 1).2 one_half_lt_one)),
have ne : ((1 / 2 : nnreal) : ennreal) ≠ 0,
begin
rw [(≠), coe_eq_zero],
refine zero_lt_iff_ne_zero.1 _,
show 0 < (1 / 2 : ℝ),
exact div_pos zero_lt_one two_pos
end,
by rwa [mul_top, if_neg ne] at this)
end inv
section infi
variables {ι : Sort*} {f g : ι → ennreal}
lemma infi_add : infi f + a = ⨅i, f i + a :=
le_antisymm
(le_infi $ assume i, add_le_add' (infi_le _ _) $ le_refl _)
(ennreal.sub_le_iff_le_add.1 $ le_infi $ assume i, ennreal.sub_le_iff_le_add.2 $ infi_le _ _)
lemma supr_sub : (⨆i, f i) - a = (⨆i, f i - a) :=
le_antisymm
(ennreal.sub_le_iff_le_add.2 $ supr_le $ assume i, ennreal.sub_le_iff_le_add.1 $ le_supr _ i)
(supr_le $ assume i, ennreal.sub_le_sub (le_supr _ _) (le_refl a))
lemma sub_infi : a - (⨅i, f i) = (⨆i, a - f i) :=
begin
refine (eq_of_forall_ge_iff $ λ c, _),
rw [ennreal.sub_le_iff_le_add, add_comm, infi_add],
simp [ennreal.sub_le_iff_le_add]
end
lemma Inf_add {s : set ennreal} : Inf s + a = ⨅b∈s, b + a :=
by simp [Inf_eq_infi, infi_add]
lemma add_infi {a : ennreal} : a + infi f = ⨅b, a + f b :=
by rw [add_comm, infi_add]; simp
lemma infi_add_infi (h : ∀i j, ∃k, f k + g k ≤ f i + g j) : infi f + infi g = (⨅a, f a + g a) :=
suffices (⨅a, f a + g a) ≤ infi f + infi g,
from le_antisymm (le_infi $ assume a, add_le_add' (infi_le _ _) (infi_le _ _)) this,
calc (⨅a, f a + g a) ≤ (⨅ a a', f a + g a') :
le_infi $ assume a, le_infi $ assume a',
let ⟨k, h⟩ := h a a' in infi_le_of_le k h
... ≤ infi f + infi g :
by simp [add_infi, infi_add, -add_comm, -le_infi_iff]; exact le_refl _
lemma infi_sum {f : ι → α → ennreal} {s : finset α} [nonempty ι]
(h : ∀(t : finset α) (i j : ι), ∃k, ∀a∈t, f k a ≤ f i a ∧ f k a ≤ f j a) :
(⨅i, s.sum (f i)) = s.sum (λa, ⨅i, f i a) :=
finset.induction_on s (by simp) $ assume a s ha ih,
have ∀ (i j : ι), ∃ (k : ι), f k a + s.sum (f k) ≤ f i a + s.sum (f j),
from assume i j,
let ⟨k, hk⟩ := h (insert a s) i j in
⟨k, add_le_add' (hk a (finset.mem_insert_self _ _)).left $ finset.sum_le_sum' $
assume a ha, (hk _ $ finset.mem_insert_of_mem ha).right⟩,
by simp [ha, ih.symm, infi_add_infi this]
end infi
section supr
lemma supr_coe_nat : (⨆n:ℕ, (n : ennreal)) = ⊤ :=
(lattice.supr_eq_top _).2 $ assume b hb,
begin
rcases lt_iff_exists_coe.1 hb with ⟨r, rfl, hb⟩,
rcases exists_nat_gt r with ⟨n, hn⟩,
refine ⟨n, _⟩,
rwa [ennreal.coe_nat, ennreal.coe_lt_coe],
end
end supr
end ennreal
|
958d8d9627a3db2d25228c7e448fb2a2f0517c93 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/data/opposite.lean | f74f353803b89439613d92ccba2b2a6cb2447fce | [
"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,729 | lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Reid Barton, Simon Hudon, Kenny Lau
-/
import logic.equiv.defs
/-!
# Opposites
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In this file we define a type synonym `opposite α := α`, denoted by `αᵒᵖ` and two synonyms for the
identity map, `op : α → αᵒᵖ` and `unop : αᵒᵖ → α`. If `α` is a category, then `αᵒᵖ` is the opposite
category, with all arrows reversed.
-/
universes v u -- morphism levels before object levels. See note [category_theory universes].
variable (α : Sort u)
/-- The type of objects of the opposite of `α`; used to define the opposite category.
In order to avoid confusion between `α` and its opposite type, we
set up the type of objects `opposite α` using the following pattern,
which will be repeated later for the morphisms.
1. Define `opposite α := α`.
2. Define the isomorphisms `op : α → opposite α`, `unop : opposite α → α`.
3. Make the definition `opposite` irreducible.
This has the following consequences.
* `opposite α` and `α` are distinct types in the elaborator, so you
must use `op` and `unop` explicitly to convert between them.
* Both `unop (op X) = X` and `op (unop X) = X` are definitional
equalities. Notably, every object of the opposite category is
definitionally of the form `op X`, which greatly simplifies the
definition of the structure of the opposite category, for example.
(If Lean supported definitional eta equality for records, we could
achieve the same goals using a structure with one field.)
-/
def opposite : Sort u := α
-- Use a high right binding power (like that of postfix ⁻¹) so that, for example,
-- `presheaf Cᵒᵖ` parses as `presheaf (Cᵒᵖ)` and not `(presheaf C)ᵒᵖ`.
notation α `ᵒᵖ`:std.prec.max_plus := opposite α
namespace opposite
variables {α}
/-- The canonical map `α → αᵒᵖ`. -/
@[pp_nodot]
def op : α → αᵒᵖ := id
/-- The canonical map `αᵒᵖ → α`. -/
@[pp_nodot]
def unop : αᵒᵖ → α := id
lemma op_injective : function.injective (op : α → αᵒᵖ) := λ _ _, id
lemma unop_injective : function.injective (unop : αᵒᵖ → α) := λ _ _, id
@[simp] lemma op_unop (x : αᵒᵖ) : op (unop x) = x := rfl
@[simp] lemma unop_op (x : α) : unop (op x) = x := rfl
attribute [irreducible] opposite
-- We could prove these by `iff.rfl`, but that would make these eligible for `dsimp`. That would be
-- a bad idea because `opposite` is irreducible.
@[simp] lemma op_inj_iff (x y : α) : op x = op y ↔ x = y := op_injective.eq_iff
@[simp] lemma unop_inj_iff (x y : αᵒᵖ) : unop x = unop y ↔ x = y := unop_injective.eq_iff
/-- The type-level equivalence between a type and its opposite. -/
def equiv_to_opposite : α ≃ αᵒᵖ :=
{ to_fun := op,
inv_fun := unop,
left_inv := unop_op,
right_inv := op_unop }
@[simp]
lemma equiv_to_opposite_coe : (equiv_to_opposite : α → αᵒᵖ) = op := rfl
@[simp]
lemma equiv_to_opposite_symm_coe : (equiv_to_opposite.symm : αᵒᵖ → α) = unop := rfl
lemma op_eq_iff_eq_unop {x : α} {y} : op x = y ↔ x = unop y :=
equiv_to_opposite.apply_eq_iff_eq_symm_apply
lemma unop_eq_iff_eq_op {x} {y : α} : unop x = y ↔ x = op y :=
equiv_to_opposite.symm.apply_eq_iff_eq_symm_apply
instance [inhabited α] : inhabited αᵒᵖ := ⟨op default⟩
/-- A recursor for `opposite`. Use as `induction x using opposite.rec`. -/
@[simp]
protected def rec {F : Π (X : αᵒᵖ), Sort v} (h : Π X, F (op X)) : Π X, F X :=
λ X, h (unop X)
end opposite
namespace tactic
open opposite
namespace op_induction
/-- Test if `e : expr` is of type `opposite α` for some `α`. -/
meta def is_opposite (e : expr) : tactic bool :=
do t ← infer_type e,
`(opposite _) ← whnf t | return ff,
return tt
/-- Find the first hypothesis of type `opposite _`. Fail if no such hypothesis exist in the local
context. -/
meta def find_opposite_hyp : tactic name :=
do lc ← local_context,
h :: _ ← lc.mfilter $ is_opposite | fail "No hypotheses of the form Xᵒᵖ",
return h.local_pp_name
end op_induction
open op_induction
/-- A version of `induction x using opposite.rec` which finds the appropriate hypothesis
automatically, for use with `local attribute [tidy] op_induction'`. This is necessary because
`induction x` is not able to deduce that `opposite.rec` should be used. -/
meta def op_induction' : tactic unit :=
do h ← find_opposite_hyp,
h' ← tactic.get_local h,
tactic.induction' h' [] `opposite.rec
end tactic
|
c08d865ea372d86ac2c8b2483d13305ea525d99c | 01ae0d022f2e2fefdaaa898938c1ac1fbce3b3ab | /categories/adjunctions/examples/fixed_points.lean | 7b4dbf340d2c332c0db335de79ad84a1f042251e | [] | no_license | PatrickMassot/lean-category-theory | 0f56a83464396a253c28a42dece16c93baf8ad74 | ef239978e91f2e1c3b8e88b6e9c64c155dc56c99 | refs/heads/master | 1,629,739,187,316 | 1,512,422,659,000 | 1,512,422,659,000 | 113,098,786 | 0 | 0 | null | 1,512,424,022,000 | 1,512,424,022,000 | null | UTF-8 | Lean | false | false | 1,028 | lean | -- Copyright (c) 2017 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Scott Morrison
import ...adjunctions
import ...full_subcategory
open categories
open categories.functor
open categories.natural_transformation
open categories.products
open categories.isomorphism
open categories.types
open categories.functor_categories
namespace categories.adjunctions
-- EXERCISE
-- cf Leinster 2.2.11
definition left_fixed_points { C D : Category } { L : Functor C D } { R : Functor D C } ( A : Adjunction L R )
: Category := FullSubcategory C (λ X, is_Isomorphism (A.unit X))
definition right_fixed_points { C D : Category } { L : Functor C D } { R : Functor D C } ( A : Adjunction L R )
: Category := FullSubcategory D (λ X, is_Isomorphism (A.counit X))
-- Now we need to express the idea that functors restrict to a full subcategory with image in another full subcategory,
-- and that these restrictions give an equivalence.
end categories.adjunctions |
1bdd14b18a511b507d78fdfb31005f03fa03d170 | 07c76fbd96ea1786cc6392fa834be62643cea420 | /hott/hit/coeq.hlean | 4fee13f54d4e3b197264fa9ce63195978ff514ab | [
"Apache-2.0"
] | permissive | fpvandoorn/lean2 | 5a430a153b570bf70dc8526d06f18fc000a60ad9 | 0889cf65b7b3cebfb8831b8731d89c2453dd1e9f | refs/heads/master | 1,592,036,508,364 | 1,545,093,958,000 | 1,545,093,958,000 | 75,436,854 | 0 | 0 | null | 1,480,718,780,000 | 1,480,718,780,000 | null | UTF-8 | Lean | false | false | 5,141 | hlean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
Declaration of the coequalizer
-/
import types.equiv .quotient
open quotient eq equiv is_trunc sigma sigma.ops
namespace coeq
section
universe u
parameters {A B : Type.{u}} (f g : A → B)
inductive coeq_rel : B → B → Type :=
| Rmk : Π(x : A), coeq_rel (f x) (g x)
open coeq_rel
local abbreviation R := coeq_rel
definition coeq : Type := quotient coeq_rel -- TODO: define this in root namespace
definition coeq_i (x : B) : coeq :=
class_of R x
/- cp is the name Coq uses. I don't know what it abbreviates, but at least it's short :-) -/
definition cp (x : A) : coeq_i (f x) = coeq_i (g x) :=
eq_of_rel coeq_rel (Rmk f g x)
protected definition rec {P : coeq → Type} (P_i : Π(x : B), P (coeq_i x))
(Pcp : Π(x : A), P_i (f x) =[cp x] P_i (g x)) (y : coeq) : P y :=
begin
induction y,
{ apply P_i},
{ cases H, apply Pcp}
end
protected definition rec_on [reducible] {P : coeq → Type} (y : coeq)
(P_i : Π(x : B), P (coeq_i x)) (Pcp : Π(x : A), P_i (f x) =[cp x] P_i (g x)) : P y :=
rec P_i Pcp y
theorem rec_cp {P : coeq → Type} (P_i : Π(x : B), P (coeq_i x))
(Pcp : Π(x : A), P_i (f x) =[cp x] P_i (g x))
(x : A) : apd (rec P_i Pcp) (cp x) = Pcp x :=
!rec_eq_of_rel
protected definition elim {P : Type} (P_i : B → P)
(Pcp : Π(x : A), P_i (f x) = P_i (g x)) (y : coeq) : P :=
rec P_i (λx, pathover_of_eq _ (Pcp x)) y
protected definition elim_on [reducible] {P : Type} (y : coeq) (P_i : B → P)
(Pcp : Π(x : A), P_i (f x) = P_i (g x)) : P :=
elim P_i Pcp y
theorem elim_cp {P : Type} (P_i : B → P) (Pcp : Π(x : A), P_i (f x) = P_i (g x))
(x : A) : ap (elim P_i Pcp) (cp x) = Pcp x :=
begin
apply inj_inv !(pathover_constant (cp x)),
rewrite [▸*,-apd_eq_pathover_of_eq_ap,↑elim,rec_cp],
end
protected definition elim_type (P_i : B → Type)
(Pcp : Π(x : A), P_i (f x) ≃ P_i (g x)) (y : coeq) : Type :=
elim P_i (λx, ua (Pcp x)) y
protected definition elim_type_on [reducible] (y : coeq) (P_i : B → Type)
(Pcp : Π(x : A), P_i (f x) ≃ P_i (g x)) : Type :=
elim_type P_i Pcp y
theorem elim_type_cp (P_i : B → Type) (Pcp : Π(x : A), P_i (f x) ≃ P_i (g x))
(x : A) : transport (elim_type P_i Pcp) (cp x) = Pcp x :=
by rewrite [tr_eq_cast_ap_fn,↑elim_type,elim_cp];apply cast_ua_fn
protected definition rec_prop {P : coeq → Type} [H : Πx, is_prop (P x)]
(P_i : Π(x : B), P (coeq_i x)) (y : coeq) : P y :=
rec P_i (λa, !is_prop.elimo) y
protected definition elim_prop {P : Type} [H : is_prop P] (P_i : B → P) (y : coeq) : P :=
elim P_i (λa, !is_prop.elim) y
end
end coeq
attribute coeq.coeq_i [constructor]
attribute coeq.rec coeq.elim [unfold 8] [recursor 8]
attribute coeq.elim_type [unfold 7]
attribute coeq.rec_on coeq.elim_on [unfold 6]
attribute coeq.elim_type_on [unfold 5]
/- Flattening -/
namespace coeq
section
open function
universe u
parameters {A B : Type.{u}} (f g : A → B) (P_i : B → Type)
(Pcp : Πx : A, P_i (f x) ≃ P_i (g x))
local abbreviation P := coeq.elim_type f g P_i Pcp
local abbreviation F : sigma (P_i ∘ f) → sigma P_i :=
λz, ⟨f z.1, z.2⟩
local abbreviation G : sigma (P_i ∘ f) → sigma P_i :=
λz, ⟨g z.1, Pcp z.1 z.2⟩
local abbreviation Pr : Π⦃b b' : B⦄,
coeq_rel f g b b' → P_i b ≃ P_i b' :=
@coeq_rel.rec A B f g _ Pcp
local abbreviation P' := quotient.elim_type P_i Pr
protected definition flattening : sigma P ≃ coeq F G :=
begin
have H : Πz, P z ≃ P' z,
begin
intro z, apply equiv_of_eq,
have H1 : coeq.elim_type f g P_i Pcp = quotient.elim_type P_i Pr,
begin
change
quotient.rec P_i
(λb b' r, coeq_rel.cases_on r (λx, pathover_of_eq _ (ua (Pcp x))))
= quotient.rec P_i
(λb b' r, pathover_of_eq _ (ua (coeq_rel.cases_on r Pcp))),
have H2 : Π⦃b b' : B⦄ (r : coeq_rel f g b b'),
coeq_rel.cases_on r (λx, pathover_of_eq _ (ua (Pcp x)))
= pathover_of_eq _ (ua (coeq_rel.cases_on r Pcp))
:> P_i b =[eq_of_rel (coeq_rel f g) r] P_i b',
begin intros b b' r, cases r, reflexivity end,
rewrite (eq_of_homotopy3 H2)
end,
apply ap10 H1
end,
apply equiv.trans (sigma_equiv_sigma_right H),
apply equiv.trans !quotient.flattening.flattening_lemma,
fapply quotient.equiv,
{ reflexivity },
{ intros bp bp',
fapply equiv.MK,
{ intro r, induction r with b b' r p,
induction r with x, exact coeq_rel.Rmk F G ⟨x, p⟩ },
{ esimp, intro r, induction r with xp,
induction xp with x p,
exact quotient.flattening.flattening_rel.mk Pr
(coeq_rel.Rmk f g x) p },
{ esimp, intro r, induction r with xp,
induction xp with x p, reflexivity },
{ intro r, induction r with b b' r p,
induction r with x, reflexivity } }
end
end
end coeq
|
3567e39717b097bc85b0259576eb35f6af9cc72c | 30b012bb72d640ec30c8fdd4c45fdfa67beb012c | /tactic/auto_cases.lean | d0da24af416a92db360854e76c83d1df394aa034 | [
"Apache-2.0"
] | permissive | kckennylau/mathlib | 21fb810b701b10d6606d9002a4004f7672262e83 | 47b3477e20ffb5a06588dd3abb01fe0fe3205646 | refs/heads/master | 1,634,976,409,281 | 1,542,042,832,000 | 1,542,319,733,000 | 109,560,458 | 0 | 0 | Apache-2.0 | 1,542,369,208,000 | 1,509,867,494,000 | Lean | UTF-8 | Lean | false | false | 1,642 | lean | -- Copyright (c) 2017 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Scott Morrison
import logic.basic
import tactic.basic
import data.option
open tactic
meta def auto_cases_at (h : expr) : tactic string :=
do t' ← infer_type h,
t' ← whnf t',
let use_cases := match t' with
| `(empty) := tt
| `(pempty) := tt
| `(unit) := tt
| `(punit) := tt
| `(ulift _) := tt
| `(plift _) := tt
| `(prod _ _) := tt
| `(and _ _) := tt
| `(sigma _) := tt
| `(subtype _) := tt
| `(Exists _) := tt
| `(fin 0) := tt
| `(sum _ _) := tt -- This is perhaps dangerous!
| `(or _ _) := tt -- This is perhaps dangerous!
| `(iff _ _) := tt -- This is perhaps dangerous!
| _ := ff
end,
if use_cases then
do cases h, pp ← pp h, return ("cases " ++ pp.to_string)
else
match t' with
-- `cases` can be dangerous on `eq` and `quot`, producing mysterious errors during type checking.
-- instead we attempt `induction`
| `(eq _ _) := do induction h, pp ← pp h, return ("induction " ++ pp.to_string)
| `(quot _) := do induction h, pp ← pp h, return ("induction " ++ pp.to_string)
| _ := failed
end
/-- Applies `cases` or `induction` on certain hypotheses. -/
meta def auto_cases : tactic string :=
do l ← local_context,
results ← successes (l.reverse.map(λ h, auto_cases_at h)),
when (results.empty) (fail "`auto_cases` did not find any hypotheses to apply `cases` or `induction` to"),
return (string.intercalate ", " results)
|
7ce3337a3cb8cd2eaac1d77a65fe1f016e440252 | 3bdd27ffdff3ffa22d4bb010eba695afcc96bc4a | /src/combinatorics/simplicial_complex/exposed.lean | f506924aa2047cf1bf631486d8d47d8583393d72 | [] | no_license | mmasdeu/brouwerfixedpoint | 684d712c982c6a8b258b4e2c6b2eab923f2f1289 | 548270f79ecf12d7e20a256806ccb9fcf57b87e2 | refs/heads/main | 1,690,539,793,996 | 1,631,801,831,000 | 1,631,801,831,000 | 368,139,809 | 4 | 3 | null | 1,624,453,250,000 | 1,621,246,034,000 | Lean | UTF-8 | Lean | false | false | 3,119 | 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 analysis.convex.exposed
import combinatorics.simplicial_complex.extreme
open_locale classical affine big_operators
open set
--TODO: Generalise to LCTVS
variables {E : Type*} [normed_group E] [normed_space ℝ E] {x : E} {A B C : set E}
{X : finset E} {l : E →L[ℝ] ℝ}
namespace is_exposed
lemma subset_frontier (hAB : is_exposed A B) (hBA : ¬ A ⊆ B) :
B ⊆ frontier A :=
hAB.is_extreme.subset_frontier hBA
lemma span_lt (hAB : is_exposed A B) (hBA : ¬ A ⊆ B) :
affine_span ℝ B < affine_span ℝ A :=
begin
apply (affine_span_mono _ hAB.subset).lt_of_ne,
rintro h,
sorry
end
end is_exposed
/-lemma is_exposed.dim_lt (hAB : is_exposed A B) (hBA : ¬ A ⊆ B) :
(affine_span ℝ B).rank < (affine_span ℝ A).rank :=
begin
end-/
lemma mem_exposed_set_iff_mem_frontier (hA₁ : convex A) (hA₂ : (interior A).nonempty) :
(∃ B : set E, is_exposed A B ∧ ¬A ⊆ B ∧ x ∈ B) ↔ x ∈ A ∧ x ∈ frontier A :=
begin
use λ ⟨B, hAB, hBA, hxB⟩, ⟨hAB.subset hxB, hAB.subset_frontier hBA hxB⟩,
rintro ⟨hxA, hxfA⟩,
obtain ⟨y, hyA⟩ := id hA₂,
obtain ⟨l, hl⟩ := geometric_hahn_banach_open_point (convex.interior hA₁) is_open_interior hxfA.2,
refine ⟨{x ∈ A | ∀ y ∈ A, l y ≤ l x}, λ _, ⟨l, rfl⟩, λ h,
not_le.2 (hl y hyA) ((h (interior_subset hyA)).2 x hxA), hxA, λ z hzA, _⟩,
suffices h : l '' closure (interior A) ⊆ closure (Iio (l x)),
{ rw [closure_Iio, ←closure_eq_closure_interior hA₁ hA₂] at h,
exact h ⟨z, subset_closure hzA, rfl⟩ },
refine subset.trans (image_closure_subset_closure_image l.continuous) (closure_mono _),
rintro _ ⟨w, hw, rfl⟩,
exact hl w hw,
end
lemma mem_extreme_set_iff_mem_frontier (hA₁ : convex A) (hA₂ : (interior A).nonempty) :
(∃ B : set E, is_extreme A B ∧ ¬A ⊆ B ∧ x ∈ B) ↔ x ∈ A ∧ x ∈ frontier A :=
begin
use λ ⟨B, hAB, hBA, hxB⟩, ⟨hAB.1 hxB, hAB.subset_frontier hBA hxB⟩,
rintro h,
obtain ⟨B, hAB, hBA, hxB⟩ := (mem_exposed_set_iff_mem_frontier hA₁ hA₂).2 h,
exact ⟨B, hAB.is_extreme, hBA, hxB⟩,
end
/-! # Harder stuff -/
/-- Eidelheit's Theorem -/
theorem eq_Inter_halfspaces (hA₁ : convex A) (hA₂ : is_closed A) :
A = ⋂ (l : E →L[ℝ] ℝ), {x | ∃ y ∈ A, l x ≤ l y} :=
begin
ext,
simp only [mem_Inter],
use λ hx l, ⟨x, hx, le_rfl⟩,
rintro hx,
by_contra,
obtain ⟨l, s, hlA, hl⟩ := geometric_hahn_banach_closed_point hA₁ hA₂ h,
obtain ⟨y, hy, hxy⟩ := hx l,
linarith [hlA y hy],
end
lemma closed_extreme_points [finite_dimensional ℝ E] (hE : finite_dimensional.finrank ℝ E = 2)
(hA₁ : convex A) (hA₂ : is_closed A) :
is_closed A.extreme_points :=
begin
sorry
end
--theorem of S. Straszewicz proved in 1935
lemma limit_exposed_points_of_extreme (hA₁ : convex A) (hA₂ : is_closed A) :
A.extreme_points ⊆ closure (A.exposed_points) :=
begin
sorry
end
|
c84caa1c4e20946501e986eafa8df995c2844fd2 | 137c667471a40116a7afd7261f030b30180468c2 | /src/topology/instances/nnreal.lean | 70afafc88ce77ac1e0c41a7b2a2a58ab58a3c3df | [
"Apache-2.0"
] | permissive | bragadeesh153/mathlib | 46bf814cfb1eecb34b5d1549b9117dc60f657792 | b577bb2cd1f96eb47031878256856020b76f73cd | refs/heads/master | 1,687,435,188,334 | 1,626,384,207,000 | 1,626,384,207,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,552 | lean | /-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import topology.algebra.infinite_sum
import topology.algebra.group_with_zero
/-!
# Topology on `ℝ≥0`
The natural topology on `ℝ≥0` (the one induced from `ℝ`), and a basic API.
## Main definitions
Instances for the following typeclasses are defined:
* `topological_space ℝ≥0`
* `topological_semiring ℝ≥0`
* `second_countable_topology ℝ≥0`
* `order_topology ℝ≥0`
* `has_continuous_sub ℝ≥0`
* `has_continuous_inv' ℝ≥0` (continuity of `x⁻¹` away from `0`)
Everything is inherited from the corresponding structures on the reals.
## Main statements
Various mathematically trivial lemmas are proved about the compatibility
of limits and sums in `ℝ≥0` and `ℝ`. For example
* `tendsto_coe {f : filter α} {m : α → ℝ≥0} {x : ℝ≥0} :
tendsto (λa, (m a : ℝ)) f (𝓝 (x : ℝ)) ↔ tendsto m f (𝓝 x)`
says that the limit of a filter along a map to `ℝ≥0` is the same in `ℝ` and `ℝ≥0`, and
* `coe_tsum {f : α → ℝ≥0} : ((∑'a, f a) : ℝ) = (∑'a, (f a : ℝ))`
says that says that a sum of elements in `ℝ≥0` is the same in `ℝ` and `ℝ≥0`.
Similarly, some mathematically trivial lemmas about infinite sums are proved,
a few of which rely on the fact that subtraction is continuous.
-/
noncomputable theory
open set topological_space metric filter
open_locale topological_space
namespace nnreal
open_locale nnreal big_operators filter
instance : topological_space ℝ≥0 := infer_instance -- short-circuit type class inference
instance : topological_semiring ℝ≥0 :=
{ continuous_mul := continuous_subtype_mk _ $
(continuous_subtype_val.comp continuous_fst).mul (continuous_subtype_val.comp continuous_snd),
continuous_add := continuous_subtype_mk _ $
(continuous_subtype_val.comp continuous_fst).add (continuous_subtype_val.comp continuous_snd) }
instance : second_countable_topology ℝ≥0 :=
topological_space.subtype.second_countable_topology _ _
instance : order_topology ℝ≥0 := @order_topology_of_ord_connected _ _ _ _ (Ici 0) _
section coe
variable {α : Type*}
open filter finset
lemma continuous_of_real : continuous real.to_nnreal :=
continuous_subtype_mk _ $ continuous_id.max continuous_const
lemma continuous_coe : continuous (coe : ℝ≥0 → ℝ) :=
continuous_subtype_val
@[simp, norm_cast] lemma tendsto_coe {f : filter α} {m : α → ℝ≥0} {x : ℝ≥0} :
tendsto (λa, (m a : ℝ)) f (𝓝 (x : ℝ)) ↔ tendsto m f (𝓝 x) :=
tendsto_subtype_rng.symm
lemma tendsto_coe' {f : filter α} [ne_bot f] {m : α → ℝ≥0} {x : ℝ} :
tendsto (λ a, m a : α → ℝ) f (𝓝 x) ↔ ∃ hx : 0 ≤ x, tendsto m f (𝓝 ⟨x, hx⟩) :=
⟨λ h, ⟨ge_of_tendsto' h (λ c, (m c).2), tendsto_coe.1 h⟩, λ ⟨hx, hm⟩, tendsto_coe.2 hm⟩
@[simp] lemma map_coe_at_top : map (coe : ℝ≥0 → ℝ) at_top = at_top :=
map_coe_Ici_at_top 0
lemma comap_coe_at_top : comap (coe : ℝ≥0 → ℝ) at_top = at_top :=
(at_top_Ici_eq 0).symm
@[simp, norm_cast] lemma tendsto_coe_at_top {f : filter α} {m : α → ℝ≥0} :
tendsto (λ a, (m a : ℝ)) f at_top ↔ tendsto m f at_top :=
tendsto_Ici_at_top.symm
lemma tendsto_of_real {f : filter α} {m : α → ℝ} {x : ℝ} (h : tendsto m f (𝓝 x)) :
tendsto (λa, real.to_nnreal (m a)) f (𝓝 (real.to_nnreal x)) :=
(continuous_of_real.tendsto _).comp h
lemma nhds_zero : 𝓝 (0 : ℝ≥0) = ⨅a ≠ 0, 𝓟 (Iio a) :=
nhds_bot_order.trans $ by simp [bot_lt_iff_ne_bot, Iio]
lemma nhds_zero_basis : (𝓝 (0 : ℝ≥0)).has_basis (λ a : ℝ≥0, 0 < a) (λ a, Iio a) :=
nhds_bot_basis
instance : has_continuous_sub ℝ≥0 :=
⟨continuous_subtype_mk _ $
((continuous_coe.comp continuous_fst).sub
(continuous_coe.comp continuous_snd)).max continuous_const⟩
instance : has_continuous_inv' ℝ≥0 :=
⟨λ x hx, tendsto_coe.1 $ (real.tendsto_inv $ nnreal.coe_ne_zero.2 hx).comp
continuous_coe.continuous_at⟩
@[norm_cast] lemma has_sum_coe {f : α → ℝ≥0} {r : ℝ≥0} :
has_sum (λa, (f a : ℝ)) (r : ℝ) ↔ has_sum f r :=
by simp only [has_sum, coe_sum.symm, tendsto_coe]
lemma has_sum_of_real_of_nonneg {f : α → ℝ} (hf_nonneg : ∀ n, 0 ≤ f n) (hf : summable f) :
has_sum (λ n, real.to_nnreal (f n)) (real.to_nnreal (∑' n, f n)) :=
begin
have h_sum : (λ s, ∑ b in s, real.to_nnreal (f b)) = λ s, real.to_nnreal (∑ b in s, f b),
from funext (λ _, (real.to_nnreal_sum_of_nonneg (λ n _, hf_nonneg n)).symm),
simp_rw [has_sum, h_sum],
exact tendsto_of_real hf.has_sum,
end
@[norm_cast] lemma summable_coe {f : α → ℝ≥0} : summable (λa, (f a : ℝ)) ↔ summable f :=
begin
split,
exact assume ⟨a, ha⟩, ⟨⟨a, has_sum_le (λa, (f a).2) has_sum_zero ha⟩, has_sum_coe.1 ha⟩,
exact assume ⟨a, ha⟩, ⟨a.1, has_sum_coe.2 ha⟩
end
open_locale classical
@[norm_cast] lemma coe_tsum {f : α → ℝ≥0} : ↑∑'a, f a = ∑'a, (f a : ℝ) :=
if hf : summable f
then (eq.symm $ (has_sum_coe.2 $ hf.has_sum).tsum_eq)
else by simp [tsum, hf, mt summable_coe.1 hf]
lemma tsum_mul_left (a : ℝ≥0) (f : α → ℝ≥0) : ∑' x, a * f x = a * ∑' x, f x :=
nnreal.eq $ by simp only [coe_tsum, nnreal.coe_mul, tsum_mul_left]
lemma tsum_mul_right (f : α → ℝ≥0) (a : ℝ≥0) : (∑' x, f x * a) = (∑' x, f x) * a :=
nnreal.eq $ by simp only [coe_tsum, nnreal.coe_mul, tsum_mul_right]
lemma summable_comp_injective {β : Type*} {f : α → ℝ≥0} (hf : summable f)
{i : β → α} (hi : function.injective i) :
summable (f ∘ i) :=
nnreal.summable_coe.1 $
show summable ((coe ∘ f) ∘ i), from (nnreal.summable_coe.2 hf).comp_injective hi
lemma summable_nat_add (f : ℕ → ℝ≥0) (hf : summable f) (k : ℕ) : summable (λ i, f (i + k)) :=
summable_comp_injective hf $ add_left_injective k
lemma summable_nat_add_iff {f : ℕ → ℝ≥0} (k : ℕ) : summable (λ i, f (i + k)) ↔ summable f :=
begin
rw [← summable_coe, ← summable_coe],
exact @summable_nat_add_iff ℝ _ _ _ (λ i, (f i : ℝ)) k,
end
lemma has_sum_nat_add_iff {f : ℕ → ℝ≥0} (k : ℕ) {a : ℝ≥0} :
has_sum (λ n, f (n + k)) a ↔ has_sum f (a + ∑ i in range k, f i) :=
by simp [← has_sum_coe, coe_sum, nnreal.coe_add, ← has_sum_nat_add_iff k]
lemma sum_add_tsum_nat_add {f : ℕ → ℝ≥0} (k : ℕ) (hf : summable f) :
∑' i, f i = (∑ i in range k, f i) + ∑' i, f (i + k) :=
by rw [←nnreal.coe_eq, coe_tsum, nnreal.coe_add, coe_sum, coe_tsum,
sum_add_tsum_nat_add k (nnreal.summable_coe.2 hf)]
lemma infi_real_pos_eq_infi_nnreal_pos [complete_lattice α] {f : ℝ → α} :
(⨅ (n : ℝ) (h : 0 < n), f n) = (⨅ (n : ℝ≥0) (h : 0 < n), f n) :=
le_antisymm
(infi_le_infi2 $ assume r, ⟨r, infi_le_infi $ assume hr, le_rfl⟩)
(le_infi $ assume r, le_infi $ assume hr, infi_le_of_le ⟨r, hr.le⟩ $ infi_le _ hr)
end coe
lemma tendsto_cofinite_zero_of_summable {α} {f : α → ℝ≥0} (hf : summable f) :
tendsto f cofinite (𝓝 0) :=
begin
have h_f_coe : f = λ n, real.to_nnreal (f n : ℝ), from funext (λ n, real.to_nnreal_coe.symm),
rw [h_f_coe, ← @real.to_nnreal_coe 0],
exact tendsto_of_real ((summable_coe.mpr hf).tendsto_cofinite_zero),
end
lemma tendsto_at_top_zero_of_summable {f : ℕ → ℝ≥0} (hf : summable f) :
tendsto f at_top (𝓝 0) :=
by { rw ←nat.cofinite_eq_at_top, exact tendsto_cofinite_zero_of_summable hf }
end nnreal
|
d66dc53fafe375bfc6751c729027b39576a9e2e5 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/tactic/reserved_notation.lean | c1acfa18f34d12796c3718990a5a2565195607b2 | [
"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 | 1,354 | lean | /-
Copyright (c) 2020 Bryan Gin-ge Chen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bryan Gin-ge Chen
-/
/-!
# Reserved notation
This file is imported by `logic.basic` and `logic.relator` to place it at the top of the
import graph.
We place all of `mathlib`'s reserved notation in this file so that users will know not to
use them as e.g. variable names without needing to import the specific file where they
are defined.
-/
-- used in `logic/relator.lean`
reserve infixr ` ⇒ `:40
-- used in `tactic/core.lean`
precedence `setup_tactic_parser`:0
reserve prefix `pformat! `:100
reserve prefix `fail! `:100
reserve prefix `trace! `:100
-- used in `tactic/localized.lean`
reserve notation `localized`
-- used in `tactic/lint/frontend.lean`
reserve notation `#lint`
reserve notation `#lint_mathlib`
reserve notation `#lint_all`
reserve notation `#list_linters`
-- used in `tactic/where.lean`
reserve prefix `#where`:max
-- used in `tactic/simps.lean`
reserve notation `initialize_simps_projections`
reserve notation `as_prefix`
-- used in `tactic/lift.lean`
reserve notation `to`
-- used in `tactic/rcases.lean`
precedence `?`:max
-- used in `order/lattice.lean`
reserve infixl ` ⊓ `:70
reserve infixl ` ⊔ `:65
-- used in `algebra/module/linear_map.lean`
reserve infix ` ≃ₗ `:25
|
07be9c54ff76de71711bbbe1b0f9d57e3a9bbf4c | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/run/rewriter3.lean | cdb82749f99fc390cfd9783f87c7acdb475bc3f0 | [
"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 | 487 | lean | import data.nat
open algebra
constant f {A : Type} : A → A → A
theorem test1 {A : Type} [s : comm_ring A] (a b c : A) (H : a + 0 = 0) : f a a = f 0 0 :=
begin
rewrite add_zero at H,
rewrite H
end
theorem test2 {A : Type} [s : comm_ring A] (a b c : A) (H : a + 0 = 0) : f a a = f 0 0 :=
begin
rewrite [add_zero at *, H],
end
theorem test3 {A : Type} [s : comm_ring A] (a b c : A) (H : a + 0 = 0 + 0) : f a a = f 0 0 :=
begin
rewrite [add_zero at H, zero_add at H, H],
end
|
ef6f0497c61cf6c673b51dc731c0363b085e4cb5 | 7007bb645068e0b6b859aab9da7cf5c1c79e98be | /library/init/data/set.lean | d7c24e0025c5c3268fdffd468cf73cbcd1af233b | [
"Apache-2.0"
] | permissive | EdAyers/lean | 7d3fb852380bc386545ebc119b7d03c128c3ce1c | be72c8dc527a062e243a408480f487a55b06cb0a | refs/heads/master | 1,624,443,179,694 | 1,592,837,958,000 | 1,592,837,958,000 | 154,972,348 | 0 | 0 | Apache-2.0 | 1,557,768,267,000 | 1,540,649,772,000 | C++ | UTF-8 | Lean | false | false | 2,336 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.meta.interactive
import init.control.lawful
universes u v
def set (α : Type u) := α → Prop
def set_of {α : Type u} (p : α → Prop) : set α :=
p
namespace set
variables {α : Type u} {β : Type v}
protected def mem (a : α) (s : set α) :=
s a
instance : has_mem α (set α) :=
⟨set.mem⟩
protected def subset (s₁ s₂ : set α) :=
∀ ⦃a⦄, a ∈ s₁ → a ∈ s₂
instance : has_subset (set α) :=
⟨set.subset⟩
protected def sep (p : α → Prop) (s : set α) : set α :=
{a | a ∈ s ∧ p a}
instance : has_sep α (set α) :=
⟨set.sep⟩
instance : has_emptyc (set α) :=
⟨λ a, false⟩
def univ : set α :=
λ a, true
protected def insert (a : α) (s : set α) : set α :=
{b | b = a ∨ b ∈ s}
instance : has_insert α (set α) :=
⟨set.insert⟩
instance : has_singleton α (set α) := ⟨λ a, {b | b = a}⟩
instance : is_lawful_singleton α (set α) :=
⟨λ a, funext $ λ b, propext $ or_false _⟩
protected def union (s₁ s₂ : set α) : set α :=
{a | a ∈ s₁ ∨ a ∈ s₂}
instance : has_union (set α) :=
⟨set.union⟩
protected def inter (s₁ s₂ : set α) : set α :=
{a | a ∈ s₁ ∧ a ∈ s₂}
instance : has_inter (set α) :=
⟨set.inter⟩
def compl (s : set α) : set α :=
{a | a ∉ s}
instance : has_neg (set α) :=
⟨compl⟩
protected def diff (s t : set α) : set α :=
{a ∈ s | a ∉ t}
instance : has_sdiff (set α) :=
⟨set.diff⟩
def powerset (s : set α) : set (set α) :=
{t | t ⊆ s}
prefix `𝒫`:100 := powerset
@[reducible]
def sUnion (s : set (set α)) : set α := {t | ∃ a ∈ s, t ∈ a}
prefix `⋃₀`:110 := sUnion
def image (f : α → β) (s : set α) : set β :=
{b | ∃ a, a ∈ s ∧ f a = b}
instance : functor set :=
{ map := @set.image }
instance : is_lawful_functor set :=
{ id_map := λ _ s, funext $ λ b, propext ⟨λ ⟨_, sb, rfl⟩, sb, λ sb, ⟨_, sb, rfl⟩⟩,
comp_map := λ _ _ _ g h s, funext $ λ c, propext
⟨λ ⟨a, ⟨h₁, h₂⟩⟩, ⟨g a, ⟨⟨a, ⟨h₁, rfl⟩⟩, h₂⟩⟩,
λ ⟨b, ⟨⟨a, ⟨h₁, h₂⟩⟩, h₃⟩⟩, ⟨a, ⟨h₁, by dsimp; cc⟩⟩⟩ }
end set
|
44a8c4c68510164deb5b881141041788a7c5cb74 | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/data/equiv/list.lean | 7c3ddc70bccee2de3987f7fc490a881b5c05205e | [
"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 | 9,197 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
Additional equiv and encodable instances for lists and finsets.
-/
import data.equiv.denumerable data.nat.pairing order.order_iso
data.array.lemmas data.fintype
open nat list
namespace encodable
variables {α : Type*}
section list
variable [encodable α]
def encode_list : list α → ℕ
| [] := 0
| (a::l) := succ (mkpair (encode a) (encode_list l))
def decode_list : ℕ → option (list α)
| 0 := some []
| (succ v) := match unpair v, unpair_le_right v with
| (v₁, v₂), h :=
have v₂ < succ v, from lt_succ_of_le h,
(::) <$> decode α v₁ <*> decode_list v₂
end
instance list : encodable (list α) :=
⟨encode_list, decode_list, λ l,
by induction l with a l IH; simp [encode_list, decode_list, unpair_mkpair, encodek, *]⟩
@[simp] theorem encode_list_nil : encode (@nil α) = 0 := rfl
@[simp] theorem encode_list_cons (a : α) (l : list α) :
encode (a :: l) = succ (mkpair (encode a) (encode l)) := rfl
@[simp] theorem decode_list_zero : decode (list α) 0 = some [] := rfl
@[simp] theorem decode_list_succ (v : ℕ) :
decode (list α) (succ v) =
(::) <$> decode α v.unpair.1 <*> decode (list α) v.unpair.2 :=
show decode_list (succ v) = _, begin
cases e : unpair v with v₁ v₂,
simp [decode_list, e], refl
end
theorem length_le_encode : ∀ (l : list α), length l ≤ encode l
| [] := _root_.zero_le _
| (a :: l) := succ_le_succ $
le_trans (length_le_encode l) (le_mkpair_right _ _)
end list
section finset
variables [encodable α]
private def enle : α → α → Prop := encode ⁻¹'o (≤)
private lemma enle.is_linear_order : is_linear_order α enle :=
(order_embedding.preimage ⟨encode, encode_injective⟩ (≤)).is_linear_order
private def decidable_enle (a b : α) : decidable (enle a b) :=
by unfold enle order.preimage; apply_instance
local attribute [instance] enle.is_linear_order decidable_enle
def encode_multiset (s : multiset α) : ℕ :=
encode (s.sort enle)
def decode_multiset (n : ℕ) : option (multiset α) :=
coe <$> decode (list α) n
instance multiset : encodable (multiset α) :=
⟨encode_multiset, decode_multiset,
λ s, by simp [encode_multiset, decode_multiset, encodek]⟩
end finset
def encodable_of_list [decidable_eq α] (l : list α) (H : ∀ x, x ∈ l) : encodable α :=
⟨λ a, index_of a l, l.nth, λ a, index_of_nth (H _)⟩
def trunc_encodable_of_fintype (α : Type*) [decidable_eq α] [fintype α] : trunc (encodable α) :=
@@quot.rec_on_subsingleton _
(λ s : multiset α, (∀ x:α, x ∈ s) → trunc (encodable α)) _
finset.univ.1
(λ l H, trunc.mk $ encodable_of_list l H)
finset.mem_univ
instance vector [encodable α] {n} : encodable (vector α n) :=
encodable.subtype
instance fin_arrow [encodable α] {n} : encodable (fin n → α) :=
of_equiv _ (equiv.vector_equiv_fin _ _).symm
instance fin_pi (n) (π : fin n → Type*) [∀i, encodable (π i)] : encodable (Πi, π i) :=
of_equiv _ (equiv.pi_equiv_subtype_sigma (fin n) π)
instance array [encodable α] {n} : encodable (array n α) :=
of_equiv _ (equiv.array_equiv_fin _ _)
instance finset [encodable α] : encodable (finset α) :=
by haveI := decidable_eq_of_encodable α; exact
of_equiv {s : multiset α // s.nodup}
⟨λ ⟨a, b⟩, ⟨a, b⟩, λ⟨a, b⟩, ⟨a, b⟩, λ ⟨a, b⟩, rfl, λ⟨a, b⟩, rfl⟩
def fintype_arrow (α : Type*) (β : Type*) [fintype α] [decidable_eq α] [encodable β] :
trunc (encodable (α → β)) :=
(fintype.equiv_fin α).map $
λf, encodable.of_equiv (fin (fintype.card α) → β) $
equiv.arrow_congr f (equiv.refl _)
def fintype_pi (α : Type*) (π : α → Type*) [fintype α] [decidable_eq α] [∀a, encodable (π a)] :
trunc (encodable (Πa, π a)) :=
(encodable.trunc_encodable_of_fintype α).bind $ λa,
(@fintype_arrow α (Σa, π a) _ _ (@encodable.sigma _ _ a _)).bind $ λf,
trunc.mk $ @encodable.of_equiv _ _ (@encodable.subtype _ _ f _) (equiv.pi_equiv_subtype_sigma α π)
end encodable
namespace denumerable
variables {α : Type*} {β : Type*} [denumerable α] [denumerable β]
open encodable
section list
theorem denumerable_list_aux : ∀ n : ℕ,
∃ a ∈ @decode_list α _ n, encode_list a = n
| 0 := ⟨_, rfl, rfl⟩
| (succ v) := begin
cases e : unpair v with v₁ v₂,
have h := unpair_le_right v,
rw e at h,
rcases have v₂ < succ v, from lt_succ_of_le h,
denumerable_list_aux v₂ with ⟨a, h₁, h₂⟩,
simp at h₁,
simp [decode_list, e, h₂, h₁, encode_list, mkpair_unpair' e]
end
instance denumerable_list : denumerable (list α) := ⟨denumerable_list_aux⟩
@[simp] theorem list_of_nat_zero : of_nat (list α) 0 = [] := rfl
@[simp] theorem list_of_nat_succ (v : ℕ) :
of_nat (list α) (succ v) =
of_nat α v.unpair.1 :: of_nat (list α) v.unpair.2 :=
of_nat_of_decode $ show decode_list (succ v) = _,
begin
cases e : unpair v with v₁ v₂,
simp [decode_list, e],
rw [show decode_list v₂ = decode (list α) v₂,
from rfl, decode_eq_of_nat]; refl
end
end list
section multiset
def lower : list ℕ → ℕ → list ℕ
| [] n := []
| (m :: l) n := (m - n) :: lower l m
def raise : list ℕ → ℕ → list ℕ
| [] n := []
| (m :: l) n := (m + n) :: raise l (m + n)
lemma lower_raise : ∀ l n, lower (raise l n) n = l
| [] n := rfl
| (m :: l) n := by simp [raise, lower, nat.add_sub_cancel, lower_raise]
lemma raise_lower : ∀ {l n}, list.sorted (≤) (n :: l) → raise (lower l n) n = l
| [] n h := rfl
| (m :: l) n h :=
have n ≤ m, from list.rel_of_sorted_cons h _ (l.mem_cons_self _),
by simp [raise, lower, nat.add_sub_cancel' this,
raise_lower (list.sorted_of_sorted_cons h)]
lemma raise_chain : ∀ l n, list.chain (≤) n (raise l n)
| [] n := list.chain.nil
| (m :: l) n := list.chain.cons (nat.le_add_left _ _) (raise_chain _ _)
lemma raise_sorted : ∀ l n, list.sorted (≤) (raise l n)
| [] n := list.sorted_nil
| (m :: l) n := (list.chain_iff_pairwise (@le_trans _ _)).1 (raise_chain _ _)
/- Warning: this is not the same encoding as used in `encodable` -/
instance multiset : denumerable (multiset α) := mk' ⟨
λ s : multiset α, encode $ lower ((s.map encode).sort (≤)) 0,
λ n, multiset.map (of_nat α) (raise (of_nat (list ℕ) n) 0),
λ s, by have := raise_lower
(list.sorted_cons.2 ⟨λ n _, zero_le n, (s.map encode).sort_sorted _⟩);
simp [-multiset.coe_map, this],
λ n, by simp [-multiset.coe_map, list.merge_sort_eq_self _ (raise_sorted _ _), lower_raise]⟩
end multiset
section finset
def lower' : list ℕ → ℕ → list ℕ
| [] n := []
| (m :: l) n := (m - n) :: lower' l (m + 1)
def raise' : list ℕ → ℕ → list ℕ
| [] n := []
| (m :: l) n := (m + n) :: raise' l (m + n + 1)
lemma lower_raise' : ∀ l n, lower' (raise' l n) n = l
| [] n := rfl
| (m :: l) n := by simp [raise', lower', nat.add_sub_cancel, lower_raise']
lemma raise_lower' : ∀ {l n}, (∀ m ∈ l, n ≤ m) → list.sorted (<) l → raise' (lower' l n) n = l
| [] n h₁ h₂ := rfl
| (m :: l) n h₁ h₂ :=
have n ≤ m, from h₁ _ (l.mem_cons_self _),
by simp [raise', lower', nat.add_sub_cancel' this, raise_lower'
(list.rel_of_sorted_cons h₂ : ∀ a ∈ l, m < a) (list.sorted_of_sorted_cons h₂)]
lemma raise'_chain : ∀ l {m n}, m < n → list.chain (<) m (raise' l n)
| [] m n h := list.chain.nil
| (a :: l) m n h := list.chain.cons
(lt_of_lt_of_le h (nat.le_add_left _ _)) (raise'_chain _ (lt_succ_self _))
lemma raise'_sorted : ∀ l n, list.sorted (<) (raise' l n)
| [] n := list.sorted_nil
| (m :: l) n := (list.chain_iff_pairwise (@lt_trans _ _)).1
(raise'_chain _ (lt_succ_self _))
def raise'_finset (l : list ℕ) (n : ℕ) : finset ℕ :=
⟨raise' l n, (raise'_sorted _ _).imp (@ne_of_lt _ _)⟩
/- Warning: this is not the same encoding as used in `encodable` -/
instance finset : denumerable (finset α) := mk' ⟨
λ s : finset α, encode $ lower' ((s.map (eqv α).to_embedding).sort (≤)) 0,
λ n, finset.map (eqv α).symm.to_embedding (raise'_finset (of_nat (list ℕ) n) 0),
λ s, finset.eq_of_veq $ by simp [-multiset.coe_map, raise'_finset,
raise_lower' (λ n _, zero_le n) (finset.sort_sorted_lt _)],
λ n, by simp [-multiset.coe_map, finset.map, raise'_finset, finset.sort,
list.merge_sort_eq_self (≤) ((raise'_sorted _ _).imp (@le_of_lt _ _)),
lower_raise']⟩
end finset
end denumerable
namespace equiv
/-- The type lists on unit is canonically equivalent to the natural numbers. -/
def list_unit_equiv : list unit ≃ ℕ :=
{ to_fun := list.length,
inv_fun := list.repeat (),
left_inv := λ u, list.injective_length (by simp),
right_inv := λ n, list.length_repeat () n }
def list_nat_equiv_nat : list ℕ ≃ ℕ := denumerable.eqv _
def list_equiv_self_of_equiv_nat {α : Type} (e : α ≃ ℕ) : list α ≃ α :=
calc list α ≃ list ℕ : list_equiv_of_equiv e
... ≃ ℕ : list_nat_equiv_nat
... ≃ α : e.symm
end equiv
|
0901afceb096bc5ce552952154ee2a4f4acfe124 | 4f643cce24b2d005aeeb5004c2316a8d6cc7f3b1 | /src/for_mathlib/boolean_subalgebra.lean | 678764f92b3d4635e359710e0b8ba3fe9728dd0d | [] | no_license | rwbarton/lean-omin | da209ed061d64db65a8f7f71f198064986f30eb9 | fd733c6d95ef6f4743aae97de5e15df79877c00e | refs/heads/master | 1,674,408,673,325 | 1,607,343,535,000 | 1,607,343,535,000 | 285,150,399 | 9 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,712 | lean | import order.boolean_algebra
import for_mathlib.closure
variables {B : Type*} [boolean_algebra B]
-- Main example of interest: B = set α, or a boolean subalgebra.
-- Other descriptions are possible (the dual one using ⊤ and ⊓, for a start);
-- we could provide alternate constructors for these.
structure is_boolean_subalgebra (s : set B) : Prop :=
(mem_bot : ⊥ ∈ s)
(mem_sup {x y} : x ∈ s → y ∈ s → x ⊔ y ∈ s)
(mem_compl {x} : x ∈ s → xᶜ ∈ s)
lemma is_boolean_subalgebra.mem_inf {s : set B} (h : is_boolean_subalgebra s)
{x y} (hx : x ∈ s) (hy : y ∈ s) : x ⊓ y ∈ s :=
begin
convert h.mem_compl (h.mem_sup (h.mem_compl hx) (h.mem_compl hy)),
simp
end
lemma is_boolean_subalgebra.mem_top {s : set B} (h : is_boolean_subalgebra s) :
⊤ ∈ s :=
begin
convert h.mem_compl h.mem_bot,
rw compl_bot
end
namespace boolean_subalgebra
/-- The smallest boolean subalgebra containing a given set `s`. -/
inductive gen (s : set B) : set B
| basic {x} : x ∈ s → gen x
| bot : gen ⊥
| sup {x y} : gen x → gen y → gen (x ⊔ y)
| compl {x} : gen x → gen (xᶜ)
lemma gen.is_boolean_subalgebra {s : set B} : is_boolean_subalgebra (gen s) :=
⟨gen.bot, λ x y, gen.sup, λ x, gen.compl⟩
-- TODO(?): These lemmas don't have quite the same shape as the constructors
-- (phrased in terms of ∈, not function application)
lemma gen.top {s : set B} : ⊤ ∈ gen s :=
gen.is_boolean_subalgebra.mem_top
lemma gen.inf {s : set B} {x y} : x ∈ gen s → y ∈ gen s → x ⊓ y ∈ gen s :=
gen.is_boolean_subalgebra.mem_inf
lemma gen_subset_iff_subset {s t : set B} (ht : is_boolean_subalgebra t) :
gen s ⊆ t ↔ s ⊆ t :=
begin
split; intro h,
{ intros x hx,
exact h (gen.basic hx) },
{ intros x₀ hx₀,
induction hx₀ with x hx x y hx hy IHx IHy x hx IHx; clear x₀,
{ exact h hx },
{ exact ht.mem_bot },
{ exact ht.mem_sup IHx IHy },
{ exact ht.mem_compl IHx } }
end
lemma gen_subset_gen_iff_subset_gen {s t : set B} :
gen s ⊆ gen t ↔ s ⊆ gen t :=
gen_subset_iff_subset gen.is_boolean_subalgebra
lemma self_subset_gen {s : set B} : s ⊆ gen s :=
by rw ←gen_subset_gen_iff_subset_gen
lemma gen_mono {s t : set B} (h : s ⊆ t) : gen s ⊆ gen t :=
begin
rw gen_subset_gen_iff_subset_gen,
exact set.subset.trans h self_subset_gen,
end
end boolean_subalgebra
variables {α : Type*}
lemma finite_union_closure_subset_gen {s : set (set α)} :
finite_union_closure s ⊆ boolean_subalgebra.gen s :=
begin
intros x hx,
induction hx with x hx x y hx hy IHx IHy,
{ exact boolean_subalgebra.gen.basic hx },
{ exact boolean_subalgebra.gen.bot },
{ exact boolean_subalgebra.gen.sup IHx IHy }
end
|
e13666865148812fb24edd4ec760f60a8181aaa9 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/measure_theory/function/special_functions.lean | a98bc5f9a6224ee9afec6fc3416b7f4f738336f6 | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,534 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import analysis.special_functions.pow
import analysis.special_functions.trigonometric.arctan
import analysis.inner_product_space.basic
import measure_theory.constructions.borel_space
/-!
# Measurability of real and complex functions
We show that most standard real and complex functions are measurable, notably `exp`, `cos`, `sin`,
`cosh`, `sinh`, `log`, `pow`, `arcsin`, `arccos`, `arctan`, and scalar products.
-/
noncomputable theory
open_locale nnreal ennreal
namespace real
@[measurability] lemma measurable_exp : measurable exp := continuous_exp.measurable
@[measurability] lemma measurable_log : measurable log :=
measurable_of_measurable_on_compl_singleton 0 $ continuous.measurable $
continuous_on_iff_continuous_restrict.1 continuous_on_log
@[measurability] lemma measurable_sin : measurable sin := continuous_sin.measurable
@[measurability] lemma measurable_cos : measurable cos := continuous_cos.measurable
@[measurability] lemma measurable_sinh : measurable sinh := continuous_sinh.measurable
@[measurability] lemma measurable_cosh : measurable cosh := continuous_cosh.measurable
@[measurability] lemma measurable_arcsin : measurable arcsin := continuous_arcsin.measurable
@[measurability] lemma measurable_arccos : measurable arccos := continuous_arccos.measurable
@[measurability] lemma measurable_arctan : measurable arctan := continuous_arctan.measurable
end real
namespace complex
@[measurability] lemma measurable_re : measurable re := continuous_re.measurable
@[measurability] lemma measurable_im : measurable im := continuous_im.measurable
@[measurability] lemma measurable_of_real : measurable (coe : ℝ → ℂ) :=
continuous_of_real.measurable
@[measurability] lemma measurable_exp : measurable exp := continuous_exp.measurable
@[measurability] lemma measurable_sin : measurable sin := continuous_sin.measurable
@[measurability] lemma measurable_cos : measurable cos := continuous_cos.measurable
@[measurability] lemma measurable_sinh : measurable sinh := continuous_sinh.measurable
@[measurability] lemma measurable_cosh : measurable cosh := continuous_cosh.measurable
@[measurability] lemma measurable_arg : measurable arg :=
have A : measurable (λ x : ℂ, real.arcsin (x.im / x.abs)),
from real.measurable_arcsin.comp (measurable_im.div measurable_norm),
have B : measurable (λ x : ℂ, real.arcsin ((-x).im / x.abs)),
from real.measurable_arcsin.comp ((measurable_im.comp measurable_neg).div measurable_norm),
measurable.ite (is_closed_le continuous_const continuous_re).measurable_set A $
measurable.ite (is_closed_le continuous_const continuous_im).measurable_set
(B.add_const _) (B.sub_const _)
@[measurability] lemma measurable_log : measurable log :=
(measurable_of_real.comp $ real.measurable_log.comp measurable_norm).add $
(measurable_of_real.comp measurable_arg).mul_const I
end complex
namespace is_R_or_C
variables {𝕜 : Type*} [is_R_or_C 𝕜] [measurable_space 𝕜] [opens_measurable_space 𝕜]
@[measurability] lemma measurable_re : measurable (re : 𝕜 → ℝ) := continuous_re.measurable
@[measurability] lemma measurable_im : measurable (im : 𝕜 → ℝ) := continuous_im.measurable
end is_R_or_C
section real_composition
open real
variables {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f)
@[measurability] lemma measurable.exp : measurable (λ x, real.exp (f x)) :=
real.measurable_exp.comp hf
@[measurability] lemma measurable.log : measurable (λ x, log (f x)) :=
measurable_log.comp hf
@[measurability] lemma measurable.cos : measurable (λ x, real.cos (f x)) :=
real.measurable_cos.comp hf
@[measurability] lemma measurable.sin : measurable (λ x, real.sin (f x)) :=
real.measurable_sin.comp hf
@[measurability] lemma measurable.cosh : measurable (λ x, real.cosh (f x)) :=
real.measurable_cosh.comp hf
@[measurability] lemma measurable.sinh : measurable (λ x, real.sinh (f x)) :=
real.measurable_sinh.comp hf
@[measurability] lemma measurable.arctan : measurable (λ x, arctan (f x)) :=
measurable_arctan.comp hf
@[measurability] lemma measurable.sqrt : measurable (λ x, sqrt (f x)) :=
continuous_sqrt.measurable.comp hf
end real_composition
section complex_composition
open complex
variables {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f)
@[measurability] lemma measurable.cexp : measurable (λ x, complex.exp (f x)) :=
complex.measurable_exp.comp hf
@[measurability] lemma measurable.ccos : measurable (λ x, complex.cos (f x)) :=
complex.measurable_cos.comp hf
@[measurability] lemma measurable.csin : measurable (λ x, complex.sin (f x)) :=
complex.measurable_sin.comp hf
@[measurability] lemma measurable.ccosh : measurable (λ x, complex.cosh (f x)) :=
complex.measurable_cosh.comp hf
@[measurability] lemma measurable.csinh : measurable (λ x, complex.sinh (f x)) :=
complex.measurable_sinh.comp hf
@[measurability] lemma measurable.carg : measurable (λ x, arg (f x)) :=
measurable_arg.comp hf
@[measurability] lemma measurable.clog : measurable (λ x, log (f x)) :=
measurable_log.comp hf
end complex_composition
section is_R_or_C_composition
variables {α 𝕜 : Type*} [is_R_or_C 𝕜] [measurable_space α] [measurable_space 𝕜]
[opens_measurable_space 𝕜] {f : α → 𝕜} {μ : measure_theory.measure α}
@[measurability] lemma measurable.re (hf : measurable f) : measurable (λ x, is_R_or_C.re (f x)) :=
is_R_or_C.measurable_re.comp hf
@[measurability] lemma ae_measurable.re (hf : ae_measurable f μ) :
ae_measurable (λ x, is_R_or_C.re (f x)) μ :=
is_R_or_C.measurable_re.comp_ae_measurable hf
@[measurability] lemma measurable.im (hf : measurable f) : measurable (λ x, is_R_or_C.im (f x)) :=
is_R_or_C.measurable_im.comp hf
@[measurability] lemma ae_measurable.im (hf : ae_measurable f μ) :
ae_measurable (λ x, is_R_or_C.im (f x)) μ :=
is_R_or_C.measurable_im.comp_ae_measurable hf
end is_R_or_C_composition
section
variables {α 𝕜 : Type*} [is_R_or_C 𝕜] [measurable_space α] [measurable_space 𝕜]
[borel_space 𝕜] {f : α → 𝕜} {μ : measure_theory.measure α}
@[measurability] lemma is_R_or_C.measurable_of_real : measurable (coe : ℝ → 𝕜) :=
is_R_or_C.continuous_of_real.measurable
lemma measurable_of_re_im
(hre : measurable (λ x, is_R_or_C.re (f x)))
(him : measurable (λ x, is_R_or_C.im (f x))) : measurable f :=
begin
convert (is_R_or_C.measurable_of_real.comp hre).add
((is_R_or_C.measurable_of_real.comp him).mul_const is_R_or_C.I),
{ ext1 x,
exact (is_R_or_C.re_add_im _).symm },
all_goals { apply_instance },
end
lemma ae_measurable_of_re_im
(hre : ae_measurable (λ x, is_R_or_C.re (f x)) μ)
(him : ae_measurable (λ x, is_R_or_C.im (f x)) μ) : ae_measurable f μ :=
begin
convert (is_R_or_C.measurable_of_real.comp_ae_measurable hre).add
((is_R_or_C.measurable_of_real.comp_ae_measurable him).mul_const is_R_or_C.I),
{ ext1 x,
exact (is_R_or_C.re_add_im _).symm },
all_goals { apply_instance },
end
end
section pow_instances
instance complex.has_measurable_pow : has_measurable_pow ℂ ℂ :=
⟨measurable.ite (measurable_fst (measurable_set_singleton 0))
(measurable.ite (measurable_snd (measurable_set_singleton 0)) measurable_one measurable_zero)
(measurable_fst.clog.mul measurable_snd).cexp⟩
instance real.has_measurable_pow : has_measurable_pow ℝ ℝ :=
⟨complex.measurable_re.comp $ ((complex.measurable_of_real.comp measurable_fst).pow
(complex.measurable_of_real.comp measurable_snd))⟩
instance nnreal.has_measurable_pow : has_measurable_pow ℝ≥0 ℝ :=
⟨(measurable_fst.coe_nnreal_real.pow measurable_snd).subtype_mk⟩
instance ennreal.has_measurable_pow : has_measurable_pow ℝ≥0∞ ℝ :=
begin
refine ⟨ennreal.measurable_of_measurable_nnreal_prod _ _⟩,
{ simp_rw ennreal.coe_rpow_def,
refine measurable.ite _ measurable_const
(measurable_fst.pow measurable_snd).coe_nnreal_ennreal,
exact measurable_set.inter (measurable_fst (measurable_set_singleton 0))
(measurable_snd measurable_set_Iio), },
{ simp_rw ennreal.top_rpow_def,
refine measurable.ite measurable_set_Ioi measurable_const _,
exact measurable.ite (measurable_set_singleton 0) measurable_const measurable_const, },
end
end pow_instances
section
variables {α : Type*} {𝕜 : Type*} {E : Type*} [is_R_or_C 𝕜] [inner_product_space 𝕜 E]
local notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ x y
@[measurability]
lemma measurable.inner [measurable_space α] [measurable_space E] [opens_measurable_space E]
[topological_space.second_countable_topology E] [measurable_space 𝕜] [borel_space 𝕜]
{f g : α → E} (hf : measurable f) (hg : measurable g) :
measurable (λ t, ⟪f t, g t⟫) :=
continuous.measurable2 continuous_inner hf hg
@[measurability]
lemma ae_measurable.inner [measurable_space α] [measurable_space E] [opens_measurable_space E]
[topological_space.second_countable_topology E] [measurable_space 𝕜] [borel_space 𝕜]
{μ : measure_theory.measure α} {f g : α → E} (hf : ae_measurable f μ) (hg : ae_measurable g μ) :
ae_measurable (λ x, ⟪f x, g x⟫) μ :=
begin
refine ⟨λ x, ⟪hf.mk f x, hg.mk g x⟫, hf.measurable_mk.inner hg.measurable_mk, _⟩,
refine hf.ae_eq_mk.mp (hg.ae_eq_mk.mono (λ x hxg hxf, _)),
dsimp only,
congr,
{ exact hxf, },
{ exact hxg, },
end
end
|
30c0e4b82af2029355a3481bd0a5430084c2542c | e151e9053bfd6d71740066474fc500a087837323 | /src/hott/init/path.lean | 7f9f454b3c325d87d7f8c01246ecfa717fc2fa5a | [
"Apache-2.0"
] | permissive | daniel-carranza/hott3 | 15bac2d90589dbb952ef15e74b2837722491963d | 913811e8a1371d3a5751d7d32ff9dec8aa6815d9 | refs/heads/master | 1,610,091,349,670 | 1,596,222,336,000 | 1,596,222,336,000 | 241,957,822 | 0 | 0 | Apache-2.0 | 1,582,222,839,000 | 1,582,222,838,000 | null | UTF-8 | Lean | false | false | 33,462 | lean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Jakob von Raumer, Floris van Doorn
Ported from Coq HoTT
-/
import .meta.support .meta.simp_attr .meta.induction .path0
universes u v w
hott_theory
namespace hott
open function
namespace eq
variables {A : Type _} {A' : Type _} {B : Type _} {B' : Type _} {C : Type _} {P : A → Type _}
{a a' a'' x y z t : A} {b b' b'' : B}
notation x = y `:>`:50 A:49 := @eq A x y
@[hott, refl, reducible, hsimp] def idp {a : A} := refl a
@[hott, reducible, hsimp] def idpath (a : A) := refl a
-- unbased path induction
@[hott]
def rec_unbased {P : Π (a b : A), (a = b) → Type v}
(H : Π (a : A), P a a idp) {a b : A} (p : a = b) : P a b p :=
eq.rec (H a) p
@[hott]
def rec_on_unbased {P : Π (a b : A), (a = b) → Type v}
{a b : A} (p : a = b) (H : Π (a : A), P a a idp) : P a b p :=
eq.rec (H a) p
/- Concatenation and inverse -/
@[trans, hott]
def concat (p : x = y) (q : y = z) : x = z :=
by hinduction q; exact p
@[symm, hott]
def inverse (p : x = y) : y = x :=
by hinduction p; reflexivity
infix ⬝ := concat
postfix ⁻¹ := inverse
--a second notation for the inverse, which is not overloaded
postfix [parsing_only] `⁻¹ᵖ`:std.prec.max_plus := inverse
/- The 1-dimensional groupoid structure -/
-- The identity path is a right unit.
@[hott, hsimp] def con_idp (p : x = y) : p ⬝ idp = p :=
idp
-- The identity path is a left unit.
@[hott, hsimp] def idp_con (p : x = y) : idp ⬝ p = p :=
by hinduction p; reflexivity
@[hott, hsimp] def idp_inv : (@idp _ x)⁻¹ = idp := idp
-- Concatenation is associative.
@[hott] def con.assoc (p : x = y) (q : y = z) (r : z = t) :
(p ⬝ q) ⬝ r = p ⬝ (q ⬝ r) :=
by hinduction r; reflexivity
@[hott] def con.assoc' (p : x = y) (q : y = z) (r : z = t) :
p ⬝ (q ⬝ r) = (p ⬝ q) ⬝ r :=
(con.assoc p q r)⁻¹
@[hott] def con.assoc5 {a₁ a₂ a₃ a₄ a₅ a₆ : A}
(p₁ : a₁ = a₂) (p₂ : a₂ = a₃) (p₃ : a₃ = a₄) (p₄ : a₄ = a₅) (p₅ : a₅ = a₆) :
p₁ ⬝ (p₂ ⬝ p₃ ⬝ p₄) ⬝ p₅ = (p₁ ⬝ p₂) ⬝ p₃ ⬝ (p₄ ⬝ p₅) :=
by hinduction p₅; hinduction p₄; hinduction p₃; reflexivity
-- The left inverse law.
@[hott, hsimp] def con.right_inv (p : x = y) : p ⬝ p⁻¹ = idp :=
by hinduction p; reflexivity
-- The right inverse law.
@[hott, hsimp] def con.left_inv (p : x = y) : p⁻¹ ⬝ p = idp :=
by hinduction p; reflexivity
/- Several auxiliary theorems about canceling inverses across associativity. These are somewhat
redundant, following from earlier theorems. -/
@[hott, hsimp] def inv_con_cancel_left (p : x = y) (q : y = z) : p⁻¹ ⬝ (p ⬝ q) = q :=
by hinduction q; hinduction p; reflexivity
@[hott, hsimp] def con_inv_cancel_left (p : x = y) (q : x = z) : p ⬝ (p⁻¹ ⬝ q) = q :=
by hinduction q; hinduction p; reflexivity
@[hott, hsimp] def con_inv_cancel_right (p : x = y) (q : y = z) : (p ⬝ q) ⬝ q⁻¹ = p :=
by hinduction q; reflexivity
@[hott, hsimp] def inv_con_cancel_right (p : x = z) (q : y = z) : (p ⬝ q⁻¹) ⬝ q = p :=
by hinduction q; reflexivity
-- Inverse distributes over concatenation
@[hott]
def con_inv (p : x = y) (q : y = z) : (p ⬝ q)⁻¹ = q⁻¹ ⬝ p⁻¹ :=
by hinduction q; hinduction p; reflexivity
@[hott]
def inv_con_inv_left (p : y = x) (q : y = z) : (p⁻¹ ⬝ q)⁻¹ = q⁻¹ ⬝ p :=
by hinduction q; hinduction p; reflexivity
@[hott]
def inv_con_inv_right (p : x = y) (q : z = y) : (p ⬝ q⁻¹)⁻¹ = q ⬝ p⁻¹ :=
by hinduction q; hinduction p; reflexivity
@[hott]
def inv_con_inv_inv (p : y = x) (q : z = y) : (p⁻¹ ⬝ q⁻¹)⁻¹ = q ⬝ p :=
by hinduction q; hinduction p; reflexivity
-- Inverse is an involution.
@[hott, hsimp] def inv_inv (p : x = y) : p⁻¹⁻¹ = p :=
by hinduction p; reflexivity
-- auxiliary def used by 'cases' tactic
@[hott]
def elim_inv_inv {A : Type u} {a b : A} {C : a = b → Type v}
(H₁ : a = b) (H₂ : C (H₁⁻¹⁻¹)) : C H₁ :=
@eq.rec_on _ _ (λ a h, C a) _ (inv_inv H₁) H₂
@[hott, induction_using] def eq.rec_symm {A : Type u} {a₀ : A} {P : Π⦃a₁⦄, a₁ = a₀ → Type v}
(H : P idp) ⦃a₁ : A⦄ (p : a₁ = a₀) : P p :=
by hinduction p; exact H
/- Theorems for moving things around in equations -/
@[hott]
def con_eq_of_eq_inv_con {p : x = z} {q : y = z} {r : y = x} :
p = r⁻¹ ⬝ q → r ⬝ p = q :=
begin
hinduction r, intro h, exact idp_con _ ⬝ h ⬝ idp_con _
end
@[hott]
def con_eq_of_eq_con_inv {p : x = z} {q : y = z} {r : y = x} :
r = q ⬝ p⁻¹ → r ⬝ p = q :=
by hinduction p; exact id
@[hott]
def inv_con_eq_of_eq_con {p : x = z} {q : y = z} {r : x = y} :
p = r ⬝ q → r⁻¹ ⬝ p = q :=
by hinduction r; intro h; exact idp_con _ ⬝ h ⬝ idp_con _
@[hott]
def con_inv_eq_of_eq_con {p : z = x} {q : y = z} {r : y = x} :
r = q ⬝ p → r ⬝ p⁻¹ = q :=
by hinduction p; exact id
@[hott] def eq_con_of_inv_con_eq {p : x = z} {q : y = z} {r : y = x} :
r⁻¹ ⬝ q = p → q = r ⬝ p :=
by hinduction r; intro h; exact (idp_con _)⁻¹ ⬝ h ⬝ (idp_con _)⁻¹
@[hott] def eq_con_of_con_inv_eq {p : x = z} {q : y = z} {r : y = x} :
q ⬝ p⁻¹ = r → q = r ⬝ p :=
by hinduction p; exact id
@[hott] def eq_inv_con_of_con_eq {p : x = z} {q : y = z} {r : x = y} :
r ⬝ q = p → q = r⁻¹ ⬝ p :=
by hinduction r; intro h; exact (idp_con _)⁻¹ ⬝ h ⬝ (idp_con _)⁻¹
@[hott] def eq_con_inv_of_con_eq {p : z = x} {q : y = z} {r : y = x} :
q ⬝ p = r → q = r ⬝ p⁻¹ :=
by hinduction p; exact id
@[hott] def eq_of_con_inv_eq_idp {p q : x = y} : p ⬝ q⁻¹ = idp → p = q :=
by hinduction q; exact id
@[hott] def eq_of_inv_con_eq_idp {p q : x = y} : q⁻¹ ⬝ p = idp → p = q :=
by hinduction q; intro h; exact (idp_con _)⁻¹ ⬝ h
@[hott] def eq_inv_of_con_eq_idp' {p : x = y} {q : y = x} : p ⬝ q = idp → p = q⁻¹ :=
by hinduction q; exact id
@[hott] def eq_inv_of_con_eq_idp {p : x = y} {q : y = x} : q ⬝ p = idp → p = q⁻¹ :=
by hinduction q; intro h; exact (idp_con _)⁻¹ ⬝ h
@[hott] def eq_of_idp_eq_inv_con {p q : x = y} : idp = p⁻¹ ⬝ q → p = q :=
by hinduction p; intro h; exact h ⬝ idp_con _
@[hott] def eq_of_idp_eq_con_inv {p q : x = y} : idp = q ⬝ p⁻¹ → p = q :=
by hinduction p; exact id
@[hott] def inv_eq_of_idp_eq_con {p : x = y} {q : y = x} : idp = q ⬝ p → p⁻¹ = q :=
by hinduction p; exact id
@[hott] def inv_eq_of_idp_eq_con' {p : x = y} {q : y = x} : idp = p ⬝ q → p⁻¹ = q :=
by hinduction p; intro h; exact h ⬝ idp_con _
@[hott] def con_inv_eq_idp {p q : x = y} (r : p = q) : p ⬝ q⁻¹ = idp :=
by hinduction r; apply con.right_inv
@[hott] def inv_con_eq_idp {p q : x = y} (r : p = q) : q⁻¹ ⬝ p = idp :=
by hinduction r; apply con.left_inv
@[hott] def con_eq_idp {p : x = y} {q : y = x} (r : p = q⁻¹) : p ⬝ q = idp :=
by hinduction q; exact r
@[hott] def idp_eq_inv_con {p q : x = y} (r : p = q) : idp = p⁻¹ ⬝ q :=
by hinduction r; exact (con.left_inv _)⁻¹
@[hott] def idp_eq_con_inv {p q : x = y} (r : p = q) : idp = q ⬝ p⁻¹ :=
by hinduction r; exact (con.right_inv _)⁻¹
@[hott] def idp_eq_con {p : x = y} {q : y = x} (r : p⁻¹ = q) : idp = q ⬝ p :=
by hinduction p; exact r
@[hott] def eq_idp_of_con_right {p : x = x} {q : x = y} (r : p ⬝ q = q) : p = idp :=
by hinduction q; exact r
@[hott] def eq_idp_of_con_left {p : x = x} {q : y = x} (r : q ⬝ p = q) : p = idp :=
by hinduction q; exact (idp_con p)⁻¹ ⬝ r
@[hott] def idp_eq_of_con_right {p : x = x} {q : x = y} (r : q = p ⬝ q) : idp = p :=
by hinduction q; exact r
@[hott] def idp_eq_of_con_left {p : x = x} {q : y = x} (r : q = q ⬝ p) : idp = p :=
by hinduction q; exact r ⬝ idp_con p
/- Transport -/
@[subst, hott, elab_simple]
def transport (P : A → Type v) {x y : A} (p : x = y)
(u : P x) : P y :=
by hinduction p; exact u
-- This idiom makes the operation right associative.
hott_theory_cmd "local infixr ` ▸ ` := hott.eq.transport _"
@[reducible, hott]
def cast {A B : Type u} (p : A = B) (a : A) : B :=
p ▸ a
@[reducible, hott]
def cast_def {A B : Type u} (p : A = B) (a : A)
: cast p a = p ▸ a :=
idp
@[reducible, hott]
def tr_rev (P : A → Type u) {x y : A} (p : x = y) (u : P y) : P x :=
p⁻¹ ▸ u
@[hott, elab_simple] def ap {{A : Type u}} {{B : Type v}} (f : A → B) {x y:A} (p : x = y) : f x = f y :=
by hinduction p; reflexivity
@[hott, hsimp] def eq_rec_ap {A B} (f : A → B) {x y : A} (p : x = y) :
(eq.rec idp p : f x = f y) = ap f p := idp
notation `ap01` [parsing_only] := ap
@[reducible, hott]
def homotopy (f g : Πx, P x) : Type _ :=
Π x : A, f x = g x
infix ~ := homotopy
@[refl, reducible, hott, hsimp]
protected def homotopy.refl (f : Πx, P x) : f ~ f :=
λ x, idp
@[hott] protected def homotopy.rfl {f : Πx, P x} : f ~ f :=
by refl
@[symm, reducible, hott, hsimp]
protected def homotopy.symm {f g : Πx, P x} (H : f ~ g)
: g ~ f :=
λ x, (H x)⁻¹
@[trans, reducible, hott, hsimp]
protected def homotopy.trans {f g h : Πx, P x}
(H1 : f ~ g) (H2 : g ~ h) : f ~ h :=
λ x, H1 x ⬝ H2 x
infix ` ⬝hty `:75 := homotopy.trans
postfix `⁻¹ʰᵗʸ`:(max+1) := homotopy.symm
@[hott] def homotopy.refl_symm {f : Π x, P x} : (homotopy.refl f).symm = homotopy.refl f :=
idp
@[hott] def hwhisker_left (g : B → C) {f f' : A → B} (H : f ~ f') :
g ∘ f ~ g ∘ f' :=
λa, ap g (H a)
@[hott] def hwhisker_right (f : A → B) {g g' : B → C} (H : g ~ g') :
g ∘ f ~ g' ∘ f :=
λa, H (f a)
@[hott, hsimp] def compose_id (f : A → B) : f ∘ id ~ f :=
by reflexivity
@[hott, hsimp] def id_compose (f : A → B) : id ∘ f ~ f :=
by reflexivity
@[hott] def compose2 {A B C : Type _} {g g' : B → C} {f f' : A → B}
(p : g ~ g') (q : f ~ f') : g ∘ f ~ g' ∘ f' :=
hwhisker_right f p ⬝hty hwhisker_left g' q
@[hott] def hassoc {A B C D : Type _} (h : C → D) (g : B → C) (f : A → B) : (h ∘ g) ∘ f ~ h ∘ (g ∘ f) :=
λa, idp
@[hott] def homotopy_of_eq {f g : Πx, P x} (H1 : f = g) : f ~ g :=
transport (λ g, f ~ g) H1 (homotopy.refl f)
@[hott, elab_simple] def apd10 {f g : Πx, P x} (H : f = g) : f ~ g :=
λx, by hinduction H; reflexivity
--the next theorem is useful if you want to write "apply (apd10' a)"
@[hott] def apd10' {f g : Πx, P x} (a : A) (H : f = g) : f a = g a :=
by hinduction H; reflexivity
--apd10 is also ap evaluation
@[hott] def apd10_eq_ap_eval {f g : Πx, P x} (H : f = g) (a : A)
: apd10 H a = ap (λs : Πx, P x, s a) H :=
by hinduction H; reflexivity
@[reducible,hott]
def ap10 {f g : A → B} (H : f = g) : f ~ g := apd10 H
@[hott, congr] def ap11 {f g : A → B} (H : f = g) {x y : A} (p : x = y) : f x = g y :=
by hinduction H; exact ap f p
-- [apd] is defined in init.pathover using pathover instead of an equality with transport.
@[hott] def apdt (f : Πa, P a) {x y : A} (p : x = y) : p ▸ f x = f y :=
by hinduction p; reflexivity
@[hott, elab_simple] def ap011 (f : A → B → C) (Ha : a = a') (Hb : b = b') : f a b = f a' b' :=
by hinduction Ha; exact ap (f a) Hb
/- More theorems for moving things around in equations -/
@[hott] def tr_eq_of_eq_inv_tr {P : A → Type v} {x y : A} {p : x = y} {u : P x} {v : P y} :
u = p⁻¹ ▸ v → p ▸ u = v :=
by hinduction p; exact id
@[hott] def inv_tr_eq_of_eq_tr {P : A → Type v} {x y : A} {p : y = x} {u : P x} {v : P y} :
u = p ▸ v → p⁻¹ ▸ u = v :=
by hinduction p; exact id
@[hott] def eq_inv_tr_of_tr_eq {P : A → Type v} {x y : A} {p : x = y} {u : P x} {v : P y} :
p ▸ u = v → u = p⁻¹ ▸ v :=
by hinduction p; exact id
@[hott] def eq_tr_of_inv_tr_eq {P : A → Type v} {x y : A} {p : y = x} {u : P x} {v : P y} :
p⁻¹ ▸ u = v → u = p ▸ v :=
by hinduction p; exact id
/- Transporting along the diagonal of a type family -/
@[hott] def tr_diag_eq_tr_tr {A : Type u} (P : A → A → Type v) {x y : A} (p : x = y) (a : P x x) :
transport (λ x, P x x) p a = transport (λ z, P y z) p (@transport _ (λ z, P z x) _ _ p a) :=
by hinduction p; reflexivity
/- Functoriality of functions -/
-- Here we prove that functions behave like functors between groupoids, and that [ap] itself is
-- functorial.
-- Functions take identity paths to identity paths
@[hott, hsimp] def ap_idp (x : A) (f : A → B) : ap f idp = idp :> (f x = f x) := idp
-- Functions commute with concatenation.
@[hott] def ap_con (f : A → B) {x y z : A} (p : x = y) (q : y = z) :
ap f (p ⬝ q) = ap f p ⬝ ap f q :=
by hinduction q; reflexivity
@[hott] def con_ap_con_eq_con_ap_con_ap (f : A → B) {w x y z : A} (r : f w = f x)
(p : x = y) (q : y = z) : r ⬝ ap f (p ⬝ q) = (r ⬝ ap f p) ⬝ ap f q :=
by hinduction q; hinduction p; reflexivity
@[hott] def ap_con_con_eq_ap_con_ap_con (f : A → B) {w x y z : A} (p : x = y) (q : y = z)
(r : f z = f w) : ap f (p ⬝ q) ⬝ r = ap f p ⬝ (ap f q ⬝ r) :=
begin hinduction q; hinduction p, exact (idp_con _)⁻¹ end
-- Functions commute with path inverses.
@[hott] def ap_inv' (f : A → B) {x y : A} (p : x = y) : (ap f p)⁻¹ = ap f p⁻¹ :=
by hinduction p; reflexivity
@[hott] def ap_inv (f : A → B) {x y : A} (p : x = y) : ap f p⁻¹ = (ap f p)⁻¹ :=
by hinduction p; reflexivity
-- [ap] itself is functorial in the first argument.
@[hott, hsimp] def ap_id (p : x = y) : ap id p = p :=
by hinduction p; reflexivity
@[hott,elab_simple] def ap_compose (g : B → C) (f : A → B) {x y : A} (p : x = y) :
ap (g ∘ f) p = (ap g (ap f p) : g (f x) = g (f y)) :=
by hinduction p; reflexivity
-- Sometimes we don't have the actual function [compose].
@[hott] def ap_compose' (g : B → C) (f : A → B) {x y : A} (p : x = y) :
ap g (ap f p) = ap (λa, g (f a)) p :=
by hinduction p; reflexivity
-- The action of constant maps.
@[hott] def ap_constant (p : x = y) (z : B) : ap (λu, z) p = idp :=
by hinduction p; reflexivity
-- Naturality of [ap].
-- see also natural_square in cubical.square
@[hott] def ap_con_eq_con_ap {f g : A → B} (p : f ~ g) {x y : A} (q : x = y) :
ap f q ⬝ p y = p x ⬝ ap g q :=
by hinduction q; apply idp_con
@[hott, hsimp] def ap_r_con_r (f : A → B) (a : A) :
ap f (refl a) ⬝ refl (f a) = refl (f a) :=
refl _
-- Naturality of [ap] at identity.
@[hott] def ap_con_eq_con {f : A → A} (p : Πx, f x = x) {x y : A} (q : x = y) :
ap f q ⬝ p y = p x ⬝ q :=
by hinduction q; apply idp_con
@[hott] def con_ap_eq_con {f : A → A} (p : Πx, x = f x) {x y : A} (q : x = y) :
p x ⬝ ap f q = q ⬝ p y :=
by hinduction q; exact (idp_con _)⁻¹
-- Naturality of [ap] with constant function
@[hott] def ap_con_eq {f : A → B} {b : B} (p : Πx, f x = b) {x y : A} (q : x = y) :
ap f q ⬝ p y = p x :=
by hinduction q; apply idp_con
-- Naturality with other paths hanging around.
@[hott] def con_ap_con_con_eq_con_con_ap_con {f g : A → B} (p : f ~ g) {x y : A} (q : x = y)
{w z : B} (r : w = f x) (s : g y = z) :
(r ⬝ ap f q) ⬝ (p y ⬝ s) = (r ⬝ p x) ⬝ (ap g q ⬝ s) :=
by hinduction s; hinduction q; reflexivity
@[hott] def con_ap_con_eq_con_con_ap {f g : A → B} (p : f ~ g) {x y : A} (q : x = y)
{w : B} (r : w = f x) :
(r ⬝ ap f q) ⬝ p y = (r ⬝ p x) ⬝ ap g q :=
by hinduction q; reflexivity
-- TODO: try this using the simplifier, and compare proofs
@[hott] def ap_con_con_eq_con_ap_con {f g : A → B} (p : f ~ g) {x y : A} (q : x = y)
{z : B} (s : g y = z) :
ap f q ⬝ (p y ⬝ s) = p x ⬝ (ap g q ⬝ s) :=
begin
hinduction s,
hinduction q,
apply idp_con
end
@[hott] def con_ap_con_con_eq_con_con_con {f : A → A} (p : f ~ id) {x y : A} (q : x = y)
{w z : A} (r : w = f x) (s : y = z) :
(r ⬝ ap f q) ⬝ (p y ⬝ s) = (r ⬝ p x) ⬝ (q ⬝ s) :=
by hinduction s; hinduction q; reflexivity
@[hott] def con_con_ap_con_eq_con_con_con {g : A → A} (p : @id A ~ g) {x y : A} (q : x = y)
{w z : A} (r : w = x) (s : g y = z) :
(r ⬝ p x) ⬝ (ap g q ⬝ s) = (r ⬝ q) ⬝ (p y ⬝ s) :=
by hinduction s; hinduction q; reflexivity
@[hott] def con_ap_con_eq_con_con {f : A → A} (p : f ~ id) {x y : A} (q : x = y)
{w : A} (r : w = f x) :
(r ⬝ ap f q) ⬝ p y = (r ⬝ p x) ⬝ q :=
by hinduction q; reflexivity
@[hott] def ap_con_con_eq_con_con {f : A → A} (p : f ~ id) {x y : A} (q : x = y)
{z : A} (s : y = z) :
ap f q ⬝ (p y ⬝ s) = p x ⬝ (q ⬝ s) :=
by hinduction s; hinduction q; apply idp_con
@[hott] def con_con_ap_eq_con_con {g : A → A} (p : @id A ~ g) {x y : A} (q : x = y)
{w : A} (r : w = x) :
(r ⬝ p x) ⬝ ap g q = (r ⬝ q) ⬝ p y :=
begin hinduction q, exact idp end
@[hott] def con_ap_con_eq_con_con' {g : A → A} (p : @id A ~ g) {x y : A} (q : x = y)
{z : A} (s : g y = z) :
p x ⬝ (ap g q ⬝ s) = q ⬝ (p y ⬝ s) :=
by hinduction s; hinduction q; exact (idp_con _)⁻¹
/- Action of [apd10] and [ap10] on paths -/
-- Application of paths between functions preserves the groupoid structure
@[hott, hsimp] def apd10_idp (f : Πx, P x) (x : A) : apd10 (refl f) x = idp := idp
@[hott] def apd10_con {f f' f'' : Πx, P x} (h : f = f') (h' : f' = f'') (x : A) :
apd10 (h ⬝ h') x = apd10 h x ⬝ apd10 h' x :=
by hinduction h; hinduction h'; reflexivity
@[hott] def apd10_inv {f g : Πx : A, P x} (h : f = g) (x : A) :
apd10 h⁻¹ x = (apd10 h x)⁻¹ :=
by hinduction h; reflexivity
@[hott, hsimp] def ap10_idp {f : A → B} (x : A) : ap10 (refl f) x = idp := idp
@[hott] def ap10_con {f f' f'' : A → B} (h : f = f') (h' : f' = f'') (x : A) :
ap10 (h ⬝ h') x = ap10 h x ⬝ ap10 h' x := apd10_con h h' x
@[hott] def ap10_inv {f g : A → B} (h : f = g) (x : A) : ap10 h⁻¹ x = (ap10 h x)⁻¹ :=
apd10_inv h x
-- [ap10] also behaves nicely on paths produced by [ap]
@[hott] def ap_ap10 (f g : A → B) (h : B → C) (p : f = g) (a : A) :
ap h (ap10 p a) = ap10 (ap (λ f' : A → B, h ∘ f') p) a:=
by hinduction p; reflexivity
/- some lemma's about ap011 -/
@[hott] def ap_eq_ap011_left (f : A → B → C) (Ha : a = a') (b : B) :
ap (λa, f a b) Ha = ap011 f Ha idp :=
by hinduction Ha; reflexivity
@[hott] def ap_eq_ap011_right (f : A → B → C) (a : A) (Hb : b = b') :
ap (f a) Hb = ap011 f idp Hb :=
by reflexivity
@[hott] def ap_ap011 {A B C D : Type _} (g : C → D) (f : A → B → C) {a a' : A} {b b' : B}
(p : a = a') (q : b = b') : ap g (ap011 f p q) = ap011 (λa b, g (f a b)) p q :=
begin
hinduction p, exact (ap_compose g (f a) q)⁻¹
end
/- Transport and the groupoid structure of paths -/
@[hott, hsimp] def idp_tr {P : A → Type u} {x : A} (u : P x) : idp ▸ u = u := idp
@[hott] def con_tr {P : A → Type w} {x y z : A} (p : x = y) (q : y = z) (u : P x) :
p ⬝ q ▸ u = q ▸ p ▸ u :=
by hinduction q; reflexivity
@[hott, hsimp] def tr_inv_tr {P : A → Type v} {x y : A} (p : x = y) (z : P y) :
p ▸ p⁻¹ ▸ z = z :=
(con_tr p⁻¹ p z)⁻¹ ⬝ ap (λr, transport P r z) (con.left_inv p)
@[hott, hsimp] def inv_tr_tr {P : A → Type v} {x y : A} (p : x = y) (z : P x) :
p⁻¹ ▸ p ▸ z = z :=
(con_tr p p⁻¹ z)⁻¹ ⬝ ap (λr, transport P r z) (con.right_inv p)
@[hott] def cast_cast_inv {A : Type u} {P : A → Type u} {x y : A} (p : x = y) (z : P y) :
cast (ap P p) (cast (ap P p⁻¹) z) = z :=
by hinduction p; reflexivity
@[hott] def cast_inv_cast {A : Type u} {P : A → Type u} {x y : A} (p : x = y) (z : P x) :
cast (ap P p⁻¹) (cast (ap P p) z) = z :=
by hinduction p; reflexivity
@[hott] def fn_tr_eq_tr_fn {P : A → Type _} {Q : A → Type _} {x y : A} (p : x = y) (f : Πx, P x → Q x) (z : P x) :
f y (p ▸ z) = p ▸ f x z :=
by hinduction p; reflexivity
@[hott] def fn_cast_eq_cast_fn {A : Type _} {P : A → Type _} {Q : A → Type _} {x y : A}
(p : x = y) (f : Πx, P x → Q x) (z : P x) : f y (cast (ap P p) z) = cast (ap Q p) (f x z) :=
by hinduction p; reflexivity
@[hott] def con_con_tr {P : A → Type u}
{x y z w : A} (p : x = y) (q : y = z) (r : z = w) (u : P x) :
ap (λe, e ▸ u) (con.assoc' p q r) ⬝ con_tr (p ⬝ q) r u ⬝
ap (transport P r) (con_tr p q u)
= con_tr p (q ⬝ r) u ⬝ con_tr q r (p ▸ u)
:> ((p ⬝ (q ⬝ r)) ▸ u = r ▸ q ▸ p ▸ u) :=
by hinduction r; hinduction q; hinduction p; reflexivity
-- Here is another coherence lemma for transport.
@[hott] def tr_inv_tr_lemma {P : A → Type v} {x y : A} (p : x = y) (z : P x) :
tr_inv_tr p (transport P p z) = ap (transport P p) (inv_tr_tr p z) :=
by hinduction p; reflexivity
/- some properties for apdt -/
@[hott, hsimp] def apdt_idp (x : A) (f : Πx, P x) : apdt f idp = idp :> (f x = f x) := idp
@[hott] def apdt_con (f : Πx, P x) {x y z : A} (p : x = y) (q : y = z)
: apdt f (p ⬝ q) = con_tr p q (f x) ⬝ ap (transport P q) (apdt f p) ⬝ apdt f q :=
by hinduction p; hinduction q; apply idp
@[hott] def apdt_inv (f : Πx, P x) {x y : A} (p : x = y)
: apdt f p⁻¹ = (eq_inv_tr_of_tr_eq (apdt f p))⁻¹ :=
by hinduction p; apply idp
-- Dependent transport in a doubly dependent type.
-- This is a special case of transporto in init.pathover
@[hott] def transportD {P : A → Type _} (Q : Πa, P a → Type _)
{a a' : A} (p : a = a') (b : P a) (z : Q a b) : Q a' (p ▸ b) :=
by hinduction p; exact z
-- In Coq the variables P, Q and b are explicit, but in Lean we can probably have them implicit
-- using the following notation
notation p ` ▸D `:65 x:64 := transportD _ p _ x
-- transporting over 2 one-dimensional paths
-- This is a special case of transporto in init.pathover
@[hott] def transport11 (P : A → B → Type _)
(p : a = a') (q : b = b') (z : P a b) : P a' b' :=
transport (P a') q (@transport _ (λ x : A, P x b) _ _ p z)
@[hott] def transport11_con (P : A → B → Type _) (p : a = a') (p' : a' = a'') (q : b = b')
(q' : b' = b'') (z : P a b) :
transport11 P (p ⬝ p') (q ⬝ q') z = transport11 P p' q' (transport11 P p q z) :=
begin hinduction p', hinduction q', refl end
@[hott] def transport11_compose (P : A' → B' → Type _) (f : A → A') (g : B → B')
(p : a = a') (q : b = b') (z : P (f a) (g b)) :
transport11 (λa b, P (f a) (g b)) p q z = transport11 P (ap f p) (ap g q) z :=
by hinduction p; hinduction q; refl
@[hott] def transport11_ap (P : A' → B' → Type _) (f : A → A') (g : B → B')
(p : a = a') (q : b = b') (z : P (f a) (g b)) :
transport11 P (ap f p) (ap g q) z =
@transport11 _ _ _ _ _ _ (λ(a : A) (b : B), P (f a) (g b)) p q z :=
(transport11_compose P f g p q z)⁻¹
@[hott] def fn_transport11_eq_transport11_fn (P : A → B → Type _)
(Q : A → B → Type _) (p : a = a') (q : b = b')
(f : Πa b, P a b → Q a b) (z : P a b) :
f a' b' (transport11 P p q z) = transport11 Q p q (f a b z) :=
by hinduction p; hinduction q; reflexivity
-- Transporting along higher-dimensional paths
@[hott] def transport2 (P : A → Type w) {x y : A} {p q : x = y} (r : p = q) (z : P x) :
p ▸ z = q ▸ z :=
ap (λp', p' ▸ z) r
notation p ` ▸2 `:65 x:64 := transport2 _ p _ x
-- An alternative definition.
@[hott] def tr2_eq_ap10 (Q : A → Type w) {x y : A} {p q : x = y} (r : p = q) (z : Q x) :
transport2 Q r z = ap10 (ap (transport Q) r) z :=
by hinduction r; reflexivity
@[hott] def tr2_con {P : A → Type w} {x y : A} {p1 p2 p3 : x = y}
(r1 : p1 = p2) (r2 : p2 = p3) (z : P x) :
transport2 P (r1 ⬝ r2) z = transport2 P r1 z ⬝ transport2 P r2 z :=
by hinduction r1; hinduction r2; reflexivity
@[hott] def tr2_inv (Q : A → Type w) {x y : A} {p q : x = y} (r : p = q) (z : Q x) :
transport2 Q r⁻¹ z = (transport2 Q r z)⁻¹ :=
by hinduction r; reflexivity
@[hott] def transportD2 {B C : A → Type _} (D : Π(a:A), B a → C a → Type _)
{x1 x2 : A} (p : x1 = x2) (y : B x1) (z : C x1) (w : D x1 y z) : D x2 (p ▸ y) (p ▸ z) :=
by hinduction p; exact w
notation p ` ▸D2 `:65 x:64 := transportD2 _ p _ _ x
@[hott] def ap_tr_con_tr2 (P : A → Type _) {x y : A} {p q : x = y} {z w : P x} (r : p = q)
(s : z = w) :
ap (transport P p) s ⬝ transport2 P r w = transport2 P r z ⬝ ap (transport P q) s :=
by hinduction r; exact (idp_con _)⁻¹
/- Transporting in particular fibrations -/
/-
From the Coq HoTT library:
One frequently needs lemmas showing that transport in a certain dependent type is equal to some
more explicitly defined operation, defined according to the structure of that dependent type.
For most dependent types, we prove these lemmas in the appropriate file in the types/
subdirectory. Here we consider only the most basic cases.
-/
-- Transporting in a constant fibration.
@[hott] def tr_constant (p : x = y) (z : B) : transport (λx, B) p z = z :=
by hinduction p; reflexivity
@[hott] def tr2_constant {p q : x = y} (r : p = q) (z : B) :
tr_constant p z = transport2 (λu, B) r z ⬝ tr_constant q z :=
by hinduction r; exact (idp_con _)⁻¹
-- Transporting in a pulled back fibration.
@[hott] def tr_compose (P : B → Type _) (f : A → B) (p : x = y) (z : P (f x)) :
transport (P ∘ f) p z = transport P (ap f p) z :=
by hinduction p; reflexivity
@[hott] def tr_ap (P : B → Type _) (f : A → B) (p : x = y) (z : P (f x)) :
transport P (ap f p) z = transport (P ∘ f) p z :=
(tr_compose P f p z)⁻¹
@[hott] def ap_precompose (f : A → B) (g g' : B → C) (p : g = g') :
ap (λh : B → C, h ∘ f) p = transport (λh : B → C, g ∘ f = h ∘ f) p idp :=
by hinduction p; reflexivity
@[hott] def apd10_ap_precompose (f : A → B) (g g' : B → C) (p : g = g') :
apd10 (ap (λh : B → C, h ∘ f) p) = λa, apd10 p (f a) :=
by hinduction p; reflexivity
@[hott] def apd10_ap_precompose_dependent {C : B → Type _}
(f : A → B) {g g' : Πb : B, C b} (p : g = g')
: apd10 (ap (λ(h : (Πb : B, C b))(a : A), h (f a)) p) = λa, apd10 p (f a) :=
by hinduction p; reflexivity
@[hott] def apd10_ap_postcompose (f : B → C) (g g' : A → B) (p : g = g') :
apd10 (ap (λh : A → B, f ∘ h) p) = λa, ap f (apd10 p a) :=
by hinduction p; reflexivity
-- A special case of [tr_compose] which seems to come up a lot.
@[hott] def tr_eq_cast_ap {P : A → Type _} {x y} (p : x = y) (u : P x) : p ▸ u = cast (ap P p) u :=
tr_compose id P p u
@[hott] def tr_eq_cast_ap_fn {P : A → Type _} {x y} (p : x = y) : transport P p = cast (ap P p) :=
by hinduction p; reflexivity
/- The behavior of [ap] and [apdt] -/
-- In a constant fibration, [apdt] reduces to [ap], modulo [transport_const].
@[hott] def apdt_eq_tr_constant_con_ap (f : A → B) (p : x = y) :
apdt f p = tr_constant p (f x) ⬝ ap f p :=
by hinduction p; reflexivity
/- The 2-dimensional groupoid structure -/
-- Horizontal composition of 2-dimensional paths.
@[hott] def concat2 {p p' : x = y} {q q' : y = z} (h : p = p') (h' : q = q')
: p ⬝ q = p' ⬝ q' :=
ap011 concat h h'
-- 2-dimensional path inversion
@[hott] def inverse2 {p q : x = y} (h : p = q) : p⁻¹ = q⁻¹ :=
ap inverse h
infixl ` ◾ `:80 := concat2
postfix `⁻²`:(max+10) := inverse2 --this notation is abusive, should we use it?
/- Whiskering -/
@[hott] def whisker_left (p : x = y) {q r : y = z} (h : q = r) : p ⬝ q = p ⬝ r :=
idp ◾ h
@[hott] def whisker_right {p q : x = y} (r : y = z) (h : p = q) : p ⬝ r = q ⬝ r :=
h ◾ idp
-- Unwhiskering, a.k.a. cancelling
@[hott] def cancel_left {x y z : A} (p : x = y) {q r : y = z} : (p ⬝ q = p ⬝ r) → (q = r) :=
λs, (inv_con_cancel_left _ _)⁻¹ ⬝ whisker_left p⁻¹ s ⬝ inv_con_cancel_left _ _
@[hott] def cancel_right {x y z : A} {p q : x = y} (r : y = z) : (p ⬝ r = q ⬝ r) → (p = q) :=
λs, (con_inv_cancel_right _ _)⁻¹ ⬝ whisker_right r⁻¹ s ⬝ con_inv_cancel_right _ _
-- Whiskering and identity paths.
@[hott, hsimp] def whisker_right_idp {p q : x = y} (h : p = q) :
whisker_right idp h = h :=
by hinduction h; hinduction p; reflexivity
@[hott, hsimp] def whisker_right_idp_left (p : x = y) (q : y = z) :
whisker_right q idp = idp :> (p ⬝ q = p ⬝ q) :=
idp
@[hott, hsimp] def whisker_left_idp_right (p : x = y) (q : y = z) :
whisker_left p idp = idp :> (p ⬝ q = p ⬝ q) :=
idp
@[hott, hsimp] def whisker_left_idp {p q : x = y} (h : p = q) :
(idp_con p)⁻¹ ⬝ whisker_left idp h ⬝ idp_con q = h :=
by hinduction h; hinduction p; reflexivity
@[hott, hsimp] def whisker_left_idp2 {A : Type u} {a : A} (p : idp = idp :> a = a) :
whisker_left idp p = p :=
begin
refine _ ⬝ whisker_left_idp p,
exact (idp_con _)⁻¹
end
@[hott] def con2_idp {p q : x = y} (h : p = q) :
h ◾ idp = whisker_right idp h :> (p ⬝ idp = q ⬝ idp) :=
idp
@[hott] def idp_con2 {p q : x = y} (h : p = q) :
idp ◾ h = whisker_left idp h :> (idp ⬝ p = idp ⬝ q) :=
idp
@[hott] def inv2_con2 {p p' : x = y} (h : p = p')
: h⁻² ◾ h = con.left_inv p ⬝ (con.left_inv p')⁻¹ :=
by hinduction h; hinduction p; reflexivity
-- The interchange law for concatenation.
@[hott] def con2_con_con2 {p p' p'' : x = y} {q q' q'' : y = z}
(a : p = p') (b : p' = p'') (c : q = q') (d : q' = q'') :
a ◾ c ⬝ b ◾ d = (a ⬝ b) ◾ (c ⬝ d) :=
by hinduction d; hinduction c; hinduction b;induction a; reflexivity
@[hott] def con2_eq_rl {A : Type _} {x y z : A} {p p' : x = y} {q q' : y = z}
(a : p = p') (b : q = q') : a ◾ b = whisker_right q a ⬝ whisker_left p' b :=
by hinduction b; hinduction a; reflexivity
@[hott] def con2_eq_lf {A : Type _} {x y z : A} {p p' : x = y} {q q' : y = z}
(a : p = p') (b : q = q') : a ◾ b = whisker_left p b ⬝ whisker_right q' a :=
by hinduction b; hinduction a; reflexivity
@[hott] def whisker_right_con_whisker_left {x y z : A} {p p' : x = y} {q q' : y = z}
(a : p = p') (b : q = q') :
(whisker_right q a) ⬝ (whisker_left p' b) = (whisker_left p b) ⬝ (whisker_right q' a) :=
by hinduction b; hinduction a; reflexivity
-- Structure corresponding to the coherence equations of a bicategory.
-- The "pentagonator": the 3-cell witnessing the associativity pentagon.
@[hott] def pentagon {v w x y z : A} (p : v = w) (q : w = x) (r : x = y) (s : y = z) :
whisker_left p (con.assoc' q r s)
⬝ con.assoc' p (q ⬝ r) s
⬝ whisker_right s (con.assoc' p q r)
= con.assoc' p q (r ⬝ s) ⬝ con.assoc' (p ⬝ q) r s :=
by hinduction s;induction r;induction q;induction p;reflexivity
-- The 3-cell witnessing the left unit triangle.
@[hott] def triangulator (p : x = y) (q : y = z) :
con.assoc' p idp q ⬝ whisker_right q (con_idp p) = whisker_left p (idp_con q) :=
by hinduction q; hinduction p; reflexivity
@[hott] def eckmann_hilton (p q : idp = idp :> a = a) : p ⬝ q = q ⬝ p :=
begin
refine (whisker_right_idp p ◾ whisker_left_idp2 q)⁻¹ᵖ ⬝ _,
refine whisker_right_con_whisker_left _ _ ⬝ _,
refine whisker_left_idp2 _ ◾ whisker_right_idp _
end
@[hott] def con_eq_con2 (p q : idp = idp :> a = a) : p ⬝ q = p ◾ q :=
begin
refine (whisker_right_idp p ◾ whisker_left_idp2 q)⁻¹ᵖ ⬝ _,
symmetry,
exact con2_eq_rl _ _
end
@[hott] def inv_eq_inv2 (p : idp = idp :> a = a) : p⁻¹ = p⁻² :=
begin
apply eq.cancel_right p,
refine con.left_inv _ ⬝ _,
refine _ ⬝ (con_eq_con2 _ _)⁻¹,
exact (inv2_con2 _)⁻¹ᵖ,
end
-- The action of functions on 2-dimensional paths
@[hott, elab_simple] def ap02 (f : A → B) {x y : A} {p q : x = y} (r : p = q)
: ap f p = ap f q :=
ap (ap f) r
@[hott] def ap02_con (f : A → B) {x y : A} {p p' p'' : x = y} (r : p = p') (r' : p' = p'') :
ap02 f (r ⬝ r') = ap02 f r ⬝ ap02 f r' :=
by hinduction r; hinduction r'; reflexivity
@[hott] def ap02_con2 (f : A → B) {x y z : A} {p p' : x = y} {q q' :y = z} (r : p = p')
(s : q = q') :
ap02 f (r ◾ s) = ap_con f p q
⬝ (ap02 f r ◾ ap02 f s)
⬝ (ap_con f p' q')⁻¹ :=
by hinduction r; hinduction s; hinduction q; hinduction p; reflexivity
@[hott] def apdt02 {p q : x = y} (f : Π x, P x) (r : p = q) :
apdt f p = transport2 P r (f x) ⬝ apdt f q :=
by hinduction r; exact (idp_con _)⁻¹
end eq
/-
an auxillary namespace for concatenation and inversion for homotopies. We put this is a separate
namespace because ⁻¹ʰ is also used as the inverse of a homomorphism
-/
open eq
end hott
|
1fa525deaec3121ae5e08151f61d816d6a27b01b | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/order/succ_pred/limit.lean | 295cf5ed677a1783a576a4c66dca305806b1fbe7 | [
"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 | 11,395 | lean | /-
Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios
-/
import order.succ_pred.basic
/-!
# Successor and predecessor limits
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We define the predicate `order.is_succ_limit` for "successor limits", values that don't cover any
others. They are so named since they can't be the successors of anything smaller. We define
`order.is_pred_limit` analogously, and prove basic results.
## Todo
The plan is to eventually replace `ordinal.is_limit` and `cardinal.is_limit` with the common
predicate `order.is_succ_limit`.
-/
variables {α : Type*}
namespace order
open function set order_dual
/-! ### Successor limits -/
section has_lt
variables [has_lt α]
/-- A successor limit is a value that doesn't cover any other.
It's so named because in a successor order, a successor limit can't be the successor of anything
smaller. -/
def is_succ_limit (a : α) : Prop := ∀ b, ¬ b ⋖ a
lemma not_is_succ_limit_iff_exists_covby (a : α) : ¬ is_succ_limit a ↔ ∃ b, b ⋖ a :=
by simp [is_succ_limit]
@[simp] lemma is_succ_limit_of_dense [densely_ordered α] (a : α) : is_succ_limit a := λ b, not_covby
end has_lt
section preorder
variables [preorder α] {a : α}
protected lemma _root_.is_min.is_succ_limit : is_min a → is_succ_limit a :=
λ h b hab, not_is_min_of_lt hab.lt h
lemma is_succ_limit_bot [order_bot α] : is_succ_limit (⊥ : α) := is_min_bot.is_succ_limit
variables [succ_order α]
protected lemma is_succ_limit.is_max (h : is_succ_limit (succ a)) : is_max a :=
by { by_contra H, exact h a (covby_succ_of_not_is_max H) }
lemma not_is_succ_limit_succ_of_not_is_max (ha : ¬ is_max a) : ¬ is_succ_limit (succ a) :=
by { contrapose! ha, exact ha.is_max }
section no_max_order
variables [no_max_order α]
lemma is_succ_limit.succ_ne (h : is_succ_limit a) (b : α) : succ b ≠ a :=
by { rintro rfl, exact not_is_max _ h.is_max }
@[simp] lemma not_is_succ_limit_succ (a : α) : ¬ is_succ_limit (succ a) := λ h, h.succ_ne _ rfl
end no_max_order
section is_succ_archimedean
variable [is_succ_archimedean α]
lemma is_succ_limit.is_min_of_no_max [no_max_order α] (h : is_succ_limit a) : is_min a :=
λ b hb, begin
rcases hb.exists_succ_iterate with ⟨_ | n, rfl⟩,
{ exact le_rfl },
{ rw iterate_succ_apply' at h,
exact (not_is_succ_limit_succ _ h).elim }
end
@[simp] lemma is_succ_limit_iff_of_no_max [no_max_order α] : is_succ_limit a ↔ is_min a :=
⟨is_succ_limit.is_min_of_no_max, is_min.is_succ_limit⟩
lemma not_is_succ_limit_of_no_max [no_min_order α] [no_max_order α] : ¬ is_succ_limit a := by simp
end is_succ_archimedean
end preorder
section partial_order
variables [partial_order α] [succ_order α] {a b : α} {C : α → Sort*}
lemma is_succ_limit_of_succ_ne (h : ∀ b, succ b ≠ a) : is_succ_limit a := λ b hba, h b hba.succ_eq
lemma not_is_succ_limit_iff : ¬ is_succ_limit a ↔ ∃ b, ¬ is_max b ∧ succ b = a :=
begin
rw not_is_succ_limit_iff_exists_covby,
refine exists_congr (λ b, ⟨λ hba, ⟨hba.lt.not_is_max, hba.succ_eq⟩, _⟩),
rintro ⟨h, rfl⟩,
exact covby_succ_of_not_is_max h
end
/-- See `not_is_succ_limit_iff` for a version that states that `a` is a successor of a value other
than itself. -/
lemma mem_range_succ_of_not_is_succ_limit (h : ¬ is_succ_limit a) : a ∈ range (@succ α _ _) :=
by { cases not_is_succ_limit_iff.1 h with b hb, exact ⟨b, hb.2⟩ }
lemma is_succ_limit_of_succ_lt (H : ∀ a < b, succ a < b) : is_succ_limit b :=
λ a hab, (H a hab.lt).ne hab.succ_eq
lemma is_succ_limit.succ_lt (hb : is_succ_limit b) (ha : a < b) : succ a < b :=
begin
by_cases h : is_max a,
{ rwa h.succ_eq },
{ rw [lt_iff_le_and_ne, succ_le_iff_of_not_is_max h],
refine ⟨ha, λ hab, _⟩,
subst hab,
exact (h hb.is_max).elim }
end
lemma is_succ_limit.succ_lt_iff (hb : is_succ_limit b) : succ a < b ↔ a < b :=
⟨λ h, (le_succ a).trans_lt h, hb.succ_lt⟩
lemma is_succ_limit_iff_succ_lt : is_succ_limit b ↔ ∀ a < b, succ a < b :=
⟨λ hb a, hb.succ_lt, is_succ_limit_of_succ_lt⟩
/-- A value can be built by building it on successors and successor limits. -/
@[elab_as_eliminator] noncomputable def is_succ_limit_rec_on (b : α)
(hs : Π a, ¬ is_max a → C (succ a)) (hl : Π a, is_succ_limit a → C a) : C b :=
begin
by_cases hb : is_succ_limit b,
{ exact hl b hb },
{ have H := classical.some_spec (not_is_succ_limit_iff.1 hb),
rw ←H.2,
exact hs _ H.1 }
end
lemma is_succ_limit_rec_on_limit (hs : Π a, ¬ is_max a → C (succ a))
(hl : Π a, is_succ_limit a → C a) (hb : is_succ_limit b) :
@is_succ_limit_rec_on α _ _ C b hs hl = hl b hb :=
by { classical, exact dif_pos hb }
lemma is_succ_limit_rec_on_succ' (hs : Π a, ¬ is_max a → C (succ a))
(hl : Π a, is_succ_limit a → C a) {b : α} (hb : ¬ is_max b) :
@is_succ_limit_rec_on α _ _ C (succ b) hs hl = hs b hb :=
begin
have hb' := not_is_succ_limit_succ_of_not_is_max hb,
have H := classical.some_spec (not_is_succ_limit_iff.1 hb'),
rw is_succ_limit_rec_on,
simp only [cast_eq_iff_heq, hb', not_false_iff, eq_mpr_eq_cast, dif_neg],
congr,
{ exact (succ_eq_succ_iff_of_not_is_max H.1 hb).1 H.2 },
{ apply proof_irrel_heq }
end
section no_max_order
variables [no_max_order α]
@[simp] lemma is_succ_limit_rec_on_succ (hs : Π a, ¬ is_max a → C (succ a))
(hl : Π a, is_succ_limit a → C a) (b : α) :
@is_succ_limit_rec_on α _ _ C (succ b) hs hl = hs b (not_is_max b) :=
is_succ_limit_rec_on_succ' _ _ _
lemma is_succ_limit_iff_succ_ne : is_succ_limit a ↔ ∀ b, succ b ≠ a :=
⟨is_succ_limit.succ_ne, is_succ_limit_of_succ_ne⟩
lemma not_is_succ_limit_iff' : ¬ is_succ_limit a ↔ a ∈ range (@succ α _ _) :=
by { simp_rw [is_succ_limit_iff_succ_ne, not_forall, not_ne_iff], refl }
end no_max_order
section is_succ_archimedean
variable [is_succ_archimedean α]
protected lemma is_succ_limit.is_min (h : is_succ_limit a) : is_min a :=
λ b hb, begin
revert h,
refine succ.rec (λ _, le_rfl) (λ c hbc H hc, _) hb,
have := hc.is_max.succ_eq,
rw this at hc ⊢,
exact H hc
end
@[simp] lemma is_succ_limit_iff : is_succ_limit a ↔ is_min a :=
⟨is_succ_limit.is_min, is_min.is_succ_limit⟩
lemma not_is_succ_limit [no_min_order α] : ¬ is_succ_limit a := by simp
end is_succ_archimedean
end partial_order
/-! ### Predecessor limits -/
section has_lt
variables [has_lt α] {a : α}
/-- A predecessor limit is a value that isn't covered by any other.
It's so named because in a predecessor order, a predecessor limit can't be the predecessor of
anything greater. -/
def is_pred_limit (a : α) : Prop := ∀ b, ¬ a ⋖ b
lemma not_is_pred_limit_iff_exists_covby (a : α) : ¬ is_pred_limit a ↔ ∃ b, a ⋖ b :=
by simp [is_pred_limit]
lemma is_pred_limit_of_dense [densely_ordered α] (a : α) : is_pred_limit a := λ b, not_covby
@[simp] lemma is_succ_limit_to_dual_iff : is_succ_limit (to_dual a) ↔ is_pred_limit a :=
by simp [is_succ_limit, is_pred_limit]
@[simp] lemma is_pred_limit_to_dual_iff : is_pred_limit (to_dual a) ↔ is_succ_limit a :=
by simp [is_succ_limit, is_pred_limit]
alias is_succ_limit_to_dual_iff ↔ _ is_pred_limit.dual
alias is_pred_limit_to_dual_iff ↔ _ is_succ_limit.dual
end has_lt
section preorder
variables [preorder α] {a : α}
protected lemma _root_.is_max.is_pred_limit : is_max a → is_pred_limit a :=
λ h b hab, not_is_max_of_lt hab.lt h
lemma is_pred_limit_top [order_top α] : is_pred_limit (⊤ : α) := is_max_top.is_pred_limit
variables [pred_order α]
protected lemma is_pred_limit.is_min (h : is_pred_limit (pred a)) : is_min a :=
by { by_contra H, exact h a (pred_covby_of_not_is_min H) }
lemma not_is_pred_limit_pred_of_not_is_min (ha : ¬ is_min a) : ¬ is_pred_limit (pred a) :=
by { contrapose! ha, exact ha.is_min }
section no_min_order
variables [no_min_order α]
lemma is_pred_limit.pred_ne (h : is_pred_limit a) (b : α) : pred b ≠ a :=
by { rintro rfl, exact not_is_min _ h.is_min }
@[simp] lemma not_is_pred_limit_pred (a : α) : ¬ is_pred_limit (pred a) := λ h, h.pred_ne _ rfl
end no_min_order
section is_pred_archimedean
variables [is_pred_archimedean α]
protected lemma is_pred_limit.is_max_of_no_min [no_min_order α] (h : is_pred_limit a) : is_max a :=
h.dual.is_min_of_no_max
@[simp] lemma is_pred_limit_iff_of_no_min [no_min_order α] : is_pred_limit a ↔ is_max a :=
is_succ_limit_to_dual_iff.symm.trans is_succ_limit_iff_of_no_max
lemma not_is_pred_limit_of_no_min [no_min_order α] [no_max_order α] : ¬ is_pred_limit a :=
by simp
end is_pred_archimedean
end preorder
section partial_order
variables [partial_order α] [pred_order α] {a b : α} {C : α → Sort*}
lemma is_pred_limit_of_pred_ne (h : ∀ b, pred b ≠ a) : is_pred_limit a := λ b hba, h b hba.pred_eq
lemma not_is_pred_limit_iff : ¬ is_pred_limit a ↔ ∃ b, ¬ is_min b ∧ pred b = a :=
by { rw ←is_succ_limit_to_dual_iff, exact not_is_succ_limit_iff }
/-- See `not_is_pred_limit_iff` for a version that states that `a` is a successor of a value other
than itself. -/
lemma mem_range_pred_of_not_is_pred_limit (h : ¬ is_pred_limit a) : a ∈ range (@pred α _ _) :=
by { cases not_is_pred_limit_iff.1 h with b hb, exact ⟨b, hb.2⟩ }
lemma is_pred_limit_of_pred_lt (H : ∀ a > b, pred a < b) : is_pred_limit b :=
λ a hab, (H a hab.lt).ne hab.pred_eq
lemma is_pred_limit.lt_pred (h : is_pred_limit a) : a < b → a < pred b := h.dual.succ_lt
lemma is_pred_limit.lt_pred_iff (h : is_pred_limit a) : a < pred b ↔ a < b := h.dual.succ_lt_iff
lemma is_pred_limit_iff_lt_pred : is_pred_limit a ↔ ∀ ⦃b⦄, a < b → a < pred b :=
is_succ_limit_to_dual_iff.symm.trans is_succ_limit_iff_succ_lt
/-- A value can be built by building it on predecessors and predecessor limits. -/
@[elab_as_eliminator] noncomputable def is_pred_limit_rec_on (b : α)
(hs : Π a, ¬ is_min a → C (pred a)) (hl : Π a, is_pred_limit a → C a) : C b :=
@is_succ_limit_rec_on αᵒᵈ _ _ _ _ hs (λ a ha, hl _ ha.dual)
lemma is_pred_limit_rec_on_limit (hs : Π a, ¬ is_min a → C (pred a))
(hl : Π a, is_pred_limit a → C a) (hb : is_pred_limit b) :
@is_pred_limit_rec_on α _ _ C b hs hl = hl b hb :=
is_succ_limit_rec_on_limit _ _ hb.dual
lemma is_pred_limit_rec_on_pred' (hs : Π a, ¬ is_min a → C (pred a))
(hl : Π a, is_pred_limit a → C a) {b : α} (hb : ¬ is_min b) :
@is_pred_limit_rec_on α _ _ C (pred b) hs hl = hs b hb :=
is_succ_limit_rec_on_succ' _ _ _
section no_min_order
variables [no_min_order α]
@[simp] theorem is_pred_limit_rec_on_pred (hs : Π a, ¬ is_min a → C (pred a))
(hl : Π a, is_pred_limit a → C a) (b : α) :
@is_pred_limit_rec_on α _ _ C (pred b) hs hl = hs b (not_is_min b) :=
is_succ_limit_rec_on_succ _ _ _
end no_min_order
section is_pred_archimedean
variable [is_pred_archimedean α]
protected lemma is_pred_limit.is_max (h : is_pred_limit a) : is_max a := h.dual.is_min
@[simp] lemma is_pred_limit_iff : is_pred_limit a ↔ is_max a :=
is_succ_limit_to_dual_iff.symm.trans is_succ_limit_iff
lemma not_is_pred_limit [no_max_order α] : ¬ is_pred_limit a := by simp
end is_pred_archimedean
end partial_order
end order
|
7c26c1bec20328ba633a76b27976ab3127d8065b | ce89339993655da64b6ccb555c837ce6c10f9ef4 | /ukikagi/top39-2.lean | e391c59a1a59a48c6ac77c5fff67f73c1c2f3034 | [] | no_license | zeptometer/LearnLean | ef32dc36a22119f18d843f548d0bb42f907bff5d | bb84d5dbe521127ba134d4dbf9559b294a80b9f7 | refs/heads/master | 1,625,710,824,322 | 1,601,382,570,000 | 1,601,382,570,000 | 195,228,870 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 329 | lean | example: (∀ P Q R, (P ↔ Q) ∨ (Q ↔ R) ∨ (R ↔ P)) → ∀ P, P ∨ ¬P
:=
begin
intros h P,
cases h true false P with h1 h23,
exfalso,
apply h1.1,
trivial,
cases h23 with h2 h3,
right,
exact h2.2,
-- case h3
left,
apply h3.2,
trivial,
end
|
dac69e0cc8ee86ee2637edf51afa727bac25e6f5 | 4efff1f47634ff19e2f786deadd394270a59ecd2 | /src/category_theory/monoidal/functor.lean | bf621d01dccc0ffe6806884fe6d3a8b18182caed | [
"Apache-2.0"
] | permissive | agjftucker/mathlib | d634cd0d5256b6325e3c55bb7fb2403548371707 | 87fe50de17b00af533f72a102d0adefe4a2285e8 | refs/heads/master | 1,625,378,131,941 | 1,599,166,526,000 | 1,599,166,526,000 | 160,748,509 | 0 | 0 | Apache-2.0 | 1,544,141,789,000 | 1,544,141,789,000 | null | UTF-8 | Lean | false | false | 7,135 | lean | /-
Copyright (c) 2018 Michael Jendrusch. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Jendrusch, Scott Morrison
-/
import category_theory.monoidal.category
open category_theory
universes v₁ v₂ v₃ u₁ u₂ u₃
open category_theory.category
open category_theory.functor
namespace category_theory
section
open monoidal_category
variables (C : Type u₁) [category.{v₁} C] [monoidal_category.{v₁} C]
(D : Type u₂) [category.{v₂} D] [monoidal_category.{v₂} D]
/-- A lax monoidal functor is a functor `F : C ⥤ D` between monoidal categories, equipped with morphisms
`ε : 𝟙 _D ⟶ F.obj (𝟙_ C)` and `μ X Y : F.obj X ⊗ F.obj Y ⟶ F.obj (X ⊗ Y)`, satisfying the
the appropriate coherences. -/
structure lax_monoidal_functor extends C ⥤ D :=
-- unit morphism
(ε : 𝟙_ D ⟶ obj (𝟙_ C))
-- tensorator
(μ : Π X Y : C, (obj X) ⊗ (obj Y) ⟶ obj (X ⊗ Y))
(μ_natural' : ∀ {X Y X' Y' : C}
(f : X ⟶ Y) (g : X' ⟶ Y'),
((map f) ⊗ (map g)) ≫ μ Y Y' = μ X X' ≫ map (f ⊗ g)
. obviously)
-- associativity of the tensorator
(associativity' : ∀ (X Y Z : C),
(μ X Y ⊗ 𝟙 (obj Z)) ≫ μ (X ⊗ Y) Z ≫ map (α_ X Y Z).hom
= (α_ (obj X) (obj Y) (obj Z)).hom ≫ (𝟙 (obj X) ⊗ μ Y Z) ≫ μ X (Y ⊗ Z)
. obviously)
-- unitality
(left_unitality' : ∀ X : C,
(λ_ (obj X)).hom
= (ε ⊗ 𝟙 (obj X)) ≫ μ (𝟙_ C) X ≫ map (λ_ X).hom
. obviously)
(right_unitality' : ∀ X : C,
(ρ_ (obj X)).hom
= (𝟙 (obj X) ⊗ ε) ≫ μ X (𝟙_ C) ≫ map (ρ_ X).hom
. obviously)
restate_axiom lax_monoidal_functor.μ_natural'
attribute [simp] lax_monoidal_functor.μ_natural
restate_axiom lax_monoidal_functor.left_unitality'
attribute [simp] lax_monoidal_functor.left_unitality
restate_axiom lax_monoidal_functor.right_unitality'
attribute [simp] lax_monoidal_functor.right_unitality
restate_axiom lax_monoidal_functor.associativity'
attribute [simp] lax_monoidal_functor.associativity
-- When `rewrite_search` lands, add @[search] attributes to
-- lax_monoidal_functor.μ_natural lax_monoidal_functor.left_unitality
-- lax_monoidal_functor.right_unitality lax_monoidal_functor.associativity
/-- A monoidal functor is a lax monoidal functor for which the tensorator and unitor as isomorphisms. -/
structure monoidal_functor
extends lax_monoidal_functor.{v₁ v₂} C D :=
(ε_is_iso : is_iso ε . obviously)
(μ_is_iso : Π X Y : C, is_iso (μ X Y) . obviously)
attribute [instance] monoidal_functor.ε_is_iso monoidal_functor.μ_is_iso
variables {C D}
def monoidal_functor.ε_iso (F : monoidal_functor.{v₁ v₂} C D) :
tensor_unit D ≅ F.obj (tensor_unit C) :=
as_iso F.ε
def monoidal_functor.μ_iso (F : monoidal_functor.{v₁ v₂} C D) (X Y : C) :
(F.obj X) ⊗ (F.obj Y) ≅ F.obj (X ⊗ Y) :=
as_iso (F.μ X Y)
end
open monoidal_category
namespace monoidal_functor
section
variables {C : Type u₁} [category.{v₁} C] [monoidal_category.{v₁} C]
variables {D : Type u₂} [category.{v₂} D] [monoidal_category.{v₂} D]
lemma map_tensor (F : monoidal_functor.{v₁ v₂} C D) {X Y X' Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y') :
F.map (f ⊗ g) = inv (F.μ X X') ≫ ((F.map f) ⊗ (F.map g)) ≫ F.μ Y Y' :=
by simp
lemma map_left_unitor (F : monoidal_functor.{v₁ v₂} C D) (X : C) :
F.map (λ_ X).hom = inv (F.μ (𝟙_ C) X) ≫ (inv F.ε ⊗ 𝟙 (F.obj X)) ≫ (λ_ (F.obj X)).hom :=
begin
simp only [lax_monoidal_functor.left_unitality],
slice_rhs 2 3 { rw ←comp_tensor_id, simp, },
simp,
end
lemma map_right_unitor (F : monoidal_functor.{v₁ v₂} C D) (X : C) :
F.map (ρ_ X).hom = inv (F.μ X (𝟙_ C)) ≫ (𝟙 (F.obj X) ⊗ inv F.ε) ≫ (ρ_ (F.obj X)).hom :=
begin
simp only [lax_monoidal_functor.right_unitality],
slice_rhs 2 3 { rw ←id_tensor_comp, simp, },
simp,
end
/-- The tensorator as a natural isomorphism. -/
def μ_nat_iso (F : monoidal_functor.{v₁ v₂} C D) :
(functor.prod F.to_functor F.to_functor) ⋙ (tensor D) ≅ (tensor C) ⋙ F.to_functor :=
nat_iso.of_components
(by { intros, apply F.μ_iso })
(by { intros, apply F.to_lax_monoidal_functor.μ_natural })
end
section
variables (C : Type u₁) [category.{v₁} C] [monoidal_category.{v₁} C]
/-- The identity monoidal functor. -/
@[simps] def id : monoidal_functor.{v₁ v₁} C C :=
{ ε := 𝟙 _,
μ := λ X Y, 𝟙 _,
.. 𝟭 C }
end
end monoidal_functor
variables {C : Type u₁} [category.{v₁} C] [monoidal_category.{v₁} C]
variables {D : Type u₂} [category.{v₂} D] [monoidal_category.{v₂} D]
variables {E : Type u₃} [category.{v₃} E] [monoidal_category.{v₃} E]
namespace lax_monoidal_functor
variables (F : lax_monoidal_functor.{v₁ v₂} C D) (G : lax_monoidal_functor.{v₂ v₃} D E)
-- The proofs here are horrendous; rewrite_search helps a lot.
/-- The composition of two lax monoidal functors is again lax monoidal. -/
@[simps] def comp : lax_monoidal_functor.{v₁ v₃} C E :=
{ ε := G.ε ≫ (G.map F.ε),
μ := λ X Y, G.μ (F.obj X) (F.obj Y) ≫ G.map (F.μ X Y),
μ_natural' := λ _ _ _ _ f g,
begin
simp only [functor.comp_map, assoc],
rw [←category.assoc, lax_monoidal_functor.μ_natural, category.assoc, ←map_comp, ←map_comp,
←lax_monoidal_functor.μ_natural]
end,
associativity' := λ X Y Z,
begin
dsimp,
rw id_tensor_comp,
slice_rhs 3 4 { rw [← G.to_functor.map_id, G.μ_natural], },
slice_rhs 1 3 { rw ←G.associativity, },
rw comp_tensor_id,
slice_lhs 2 3 { rw [← G.to_functor.map_id, G.μ_natural], },
rw [category.assoc, category.assoc, category.assoc, category.assoc, category.assoc,
←G.to_functor.map_comp, ←G.to_functor.map_comp, ←G.to_functor.map_comp, ←G.to_functor.map_comp,
F.associativity],
end,
left_unitality' := λ X,
begin
dsimp,
rw [G.left_unitality, comp_tensor_id, category.assoc, category.assoc],
apply congr_arg,
rw [F.left_unitality, map_comp, ←nat_trans.id_app, ←category.assoc,
←lax_monoidal_functor.μ_natural, nat_trans.id_app, map_id, ←category.assoc, map_comp],
end,
right_unitality' := λ X,
begin
dsimp,
rw [G.right_unitality, id_tensor_comp, category.assoc, category.assoc],
apply congr_arg,
rw [F.right_unitality, map_comp, ←nat_trans.id_app, ←category.assoc,
←lax_monoidal_functor.μ_natural, nat_trans.id_app, map_id, ←category.assoc, map_comp],
end,
.. (F.to_functor) ⋙ (G.to_functor) }.
end lax_monoidal_functor
namespace monoidal_functor
variables (F : monoidal_functor.{v₁ v₂} C D) (G : monoidal_functor.{v₂ v₃} D E)
/-- The composition of two monoidal functors is again monoidal. -/
@[simps]
def comp : monoidal_functor.{v₁ v₃} C E :=
{ ε_is_iso := by { dsimp, apply_instance },
μ_is_iso := by { dsimp, apply_instance },
.. (F.to_lax_monoidal_functor).comp (G.to_lax_monoidal_functor) }.
end monoidal_functor
end category_theory
|
7b23182d48f2fa3211ee919357b7ea80a87fb1f7 | fbf512ee44de430e3d3c5869751ad95325c938d7 | /form.lean | 367c154ae8e84c78f74633f3d96421d7a4621ec0 | [] | no_license | skbaek/clausify | 4858c9005fb86a5e410bfcaa77524f82d955f655 | d09b071bdcce7577c3fffacd0893b776285b1590 | refs/heads/master | 1,588,360,590,818 | 1,553,553,880,000 | 1,553,553,880,000 | 177,644,542 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,386 | lean | import .term tactic.basic .list .arity .tactic .logic .nat
open tactic
variables {α β : Type}
@[derive has_reflect]
inductive form : Type
| false : form
| true : form
| prd : nat → list term → form
| not : form → form
| or : form → form → form
| and : form → form → form
| fa : form → form
| ex : form → form
notation `⊤*` := form.true
notation `⊥*` := form.false
notation p `**` ts := form.prd p ts
notation `¬*` := form.not
notation p `∧*` q := form.and p q
notation p `∨*` q := form.or p q
notation `∀*` := form.fa
notation `∃*` := form.ex
-- | ⊤* := sorry
-- | ⊥* := sorry
-- | (k ** ts) := sorry
-- | (¬* p) := sorry
-- | (p ∧* q) := sorry
-- | (p ∨* q) := sorry
-- | (∀* p) := sorry
-- | (∃* p) := sorry
namespace form
meta def to_string : form → string
| ⊥* := "⊥"
| ⊤* := "⊤"
| (k ** ts) := "(" ++ (to_fmt k).to_string ++ (ts.map term.to_string).to_string ++ ")"
| (¬* φ) := "¬" ++ φ.to_string
| (φ ∨* ψ) := "(" ++ (φ.to_string) ++ " ∨ " ++ (ψ.to_string) ++ ")"
| (φ ∧* ψ) := "(" ++ (φ.to_string) ++ " ∧ " ++ (ψ.to_string) ++ ")"
| (∀* φ) := "∀" ++ φ.to_string
| (∃* φ) := "∃" ++ φ.to_string
meta instance has_to_string : has_to_string form := ⟨form.to_string⟩
meta instance has_repr : has_to_string form := ⟨form.to_string⟩
meta instance has_to_format : has_to_format form := ⟨λ f, to_string f⟩
meta def induce (t : tactic unit := skip) : tactic unit :=
`[ intro p, induction p with k ts p ih p q ihp ihq p q ihp ihq p ih p ih; t ]
meta def induce_iff (t : tactic unit := skip) : tactic unit :=
induce t >>
focus [ skip, skip, skip,
`[ apply not_iff_not_of_iff ],
`[ apply or_iff_or ],
`[ apply and_iff_and ],
`[ apply forall_iff_forall, intro ],
`[ apply exists_iff_exists, intro ] ]
@[fol] def max_idx_lt : nat → form → Prop
| k ⊥* := _root_.true
| k ⊤* := _root_.true
| k (m ** ts) := ∀ t ∈ ts, term.max_idx_lt k t
| k (¬* p) := p.max_idx_lt k
| k (p ∨* q) := p.max_idx_lt k ∧ q.max_idx_lt k
| k (p ∧* q) := p.max_idx_lt k ∧ q.max_idx_lt k
| k (∀* p) := p.max_idx_lt (k+1)
| k (∃* p) := p.max_idx_lt (k+1)
@[fol] def closed (p : form) : Prop := p.max_idx_lt 0
instance dec_max_idx_lt : ∀ p : form, ∀ k, decidable (p.max_idx_lt k) :=
begin
induce `[intro k, try {simp_fol}, try {apply_instance},
try {apply @and.decidable _ _ _ _}, try {apply ih},
try {apply ihp}, try {apply ihq}],
end
instance dec_closed (p : form) : decidable (closed p) := p.dec_max_idx_lt 0
@[fol] def holds (M : model α) : (nat → α) → form → Prop
| v ⊤* := _root_.true
| v ⊥* := _root_.false
| v (k ** ts) :=
M.rels k (ts.map (term.val M v))
| v (¬* p) := ¬(p.holds v)
| v (p ∨* q) := (p.holds v) ∨ (q.holds v)
| v (p ∧* q) := (p.holds v) ∧ (q.holds v)
| v (∀* p) := ∀ a : α, p.holds (a::v)
| v (∃* p) := ∃ a : α, p.holds (a::v)
notation M `;` v `⊨` p := holds M v p
def equiv (α p q) : Prop :=
∀ M : model α, ∀ v, ((M ; v ⊨ p) ↔ (M ; v ⊨ q))
def valid (α p) : Prop :=
∀ M : model α, ∀ v, (M ; v ⊨ p)
def sat (α p) : Prop :=
∃ M : model α, ∀ v, (M ; v ⊨ p)
def unsat (α p) : Prop := ¬ sat α p
def rvalid [inhabited α] :
list (bool × nat) → model α → form → Prop
| [] M p := M ; (λ _, @inhabited.default _ _) ⊨ p
| ((tt,k)::ars) M p := ∀ r : arity α Prop k, p.rvalid ars (r.app_list :r: M)
| ((ff,k)::ars) M p := ∀ f : arity α α k, p.rvalid ars (f.app_list :f: M)
lemma rvalid_of_valid [inhabited α] {p} (h : valid α p) :
∀ {ars : list (bool × nat)} {M : model α}, rvalid ars M p
| [] M := by apply h
| ((b,k)::as) σ :=
begin
cases b; simp [rvalid];
intro r; apply rvalid_of_valid
end
lemma holds_iff_holds_of_max_idx_lt :
∀ (p : form) (M : model α) (v w : nat → α) k, p.max_idx_lt k →
(∀ m < k, v m = w m) → ((M ; v ⊨ p) ↔ (M ; w ⊨ p)) :=
begin
induce_iff `[intros M v w m h1 h2, split_ands], trivial, trivial,
{ simp_fol, apply iff_of_eq (congr_arg _ _),
apply list.map_eq_map_of_forall_mem_eq,
intros t h4, apply term.val_eq_val_of_max_idx_lt,
apply h1 _ h4, apply h2 },
{ apply ih; assumption },
{ apply ihp; assumption },
{ apply ihq; assumption },
{ apply ihp; assumption },
{ apply ihq; assumption },
{ apply ih, apply h1, intro n, cases n with n; intro h3,
refl, apply h2, rw ← nat.succ_lt_succ_iff, assumption },
{ apply ih, apply h1, intro n, cases n with n; intro h3,
refl, apply h2, rw ← nat.succ_lt_succ_iff, assumption }
end
lemma holds_iff_holds_of_closed :
∀ (M : model α) v w p, closed p →
((M ; v ⊨ p) ↔ (M ; w ⊨ p)) :=
begin
intros M v w p h1,
apply holds_iff_holds_of_max_idx_lt,
apply h1, intros m h2, cases h2
end
lemma valid_of_closed_of_unsat_neg [inhabited α] :
∀ {p : form}, closed p → unsat α (¬* p) → valid α p :=
begin
simp only [valid, unsat, sat], intros p h1 h2 M v,
apply classical.by_contradiction, intro h3,
apply h2, refine ⟨M, _⟩, intro w,
rw holds_iff_holds_of_closed _ _ w _ h1 at h3, assumption,
end
def fv_core : nat → form → list nat
| k ⊤* := []
| k ⊥* := []
| k (m ** ts) := ⋃ (ts.map (term.fv k))
| k (¬* p) := fv_core k p
| k (p ∧* q) := list.union (fv_core k p) (fv_core k q)
| k (p ∨* q) := list.union (fv_core k p) (fv_core k q)
| k (∀* p) := fv_core (k+1) p
| k (∃* p) := fv_core (k+1) p
def fv (p) := fv_core 0 p
def fresh_func_idx : form → nat
| ⊤* := 0
| ⊥* := 0
| (m ** ts) := list.max (ts.map (term.fresh_func_idx))
| (¬* p) := fresh_func_idx p
| (p ∧* q) := max (fresh_func_idx p) (fresh_func_idx q)
| (p ∨* q) := max (fresh_func_idx p) (fresh_func_idx q)
| (∀* p) := fresh_func_idx p
| (∃* p) := fresh_func_idx p
def subst : nat → term → form → form
| k s ⊤* := ⊤*
| k s ⊥* := ⊥*
| k s (m ** ts) := m ** (ts.map (term.subst k s))
| k s (¬* p) := ¬*(subst k s p)
| k s (p ∨* q) := (subst k s p) ∨* (subst k s q)
| k s (p ∧* q) := (subst k s p) ∧* (subst k s q)
| k s (∀* p) := ∀* (subst (k+1) s.incr_vdx p)
| k s (∃* p) := ∃* (subst (k+1) s.incr_vdx p)
end form |
afae3bf16a69265f8e11d028f0905415df4e0af3 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/category_theory/essentially_small.lean | 9e43ff04afaeac421e4c25e0a9776a5f6f730d22 | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 7,541 | 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 logic.small
import category_theory.category.ulift
import category_theory.skeletal
/-!
# Essentially small categories.
A category given by `(C : Type u) [category.{v} C]` is `w`-essentially small
if there exists a `small_model C : Type w` equipped with `[small_category (small_model C)]`.
A category is `w`-locally small if every hom type is `w`-small.
The main theorem here is that a category is `w`-essentially small iff
the type `skeleton C` is `w`-small, and `C` is `w`-locally small.
-/
universes w v v' u u'
open category_theory
variables (C : Type u) [category.{v} C]
namespace category_theory
/-- A category is `essentially_small.{w}` if there exists
an equivalence to some `S : Type w` with `[small_category S]`. -/
class essentially_small (C : Type u) [category.{v} C] : Prop :=
(equiv_small_category : ∃ (S : Type w) (_ : small_category S), by exactI nonempty (C ≌ S))
/-- Constructor for `essentially_small C` from an explicit small category witness. -/
lemma essentially_small.mk' {C : Type u} [category.{v} C] {S : Type w} [small_category S]
(e : C ≌ S) : essentially_small.{w} C :=
⟨⟨S, _, ⟨e⟩⟩⟩
/--
An arbitrarily chosen small model for an essentially small category.
-/
@[nolint has_nonempty_instance]
def small_model (C : Type u) [category.{v} C] [essentially_small.{w} C] : Type w :=
classical.some (@essentially_small.equiv_small_category C _ _)
noncomputable
instance small_category_small_model
(C : Type u) [category.{v} C] [essentially_small.{w} C] : small_category (small_model C) :=
classical.some (classical.some_spec (@essentially_small.equiv_small_category C _ _))
/--
The (noncomputable) categorical equivalence between
an essentially small category and its small model.
-/
noncomputable
def equiv_small_model (C : Type u) [category.{v} C] [essentially_small.{w} C] : C ≌ small_model C :=
nonempty.some (classical.some_spec (classical.some_spec
(@essentially_small.equiv_small_category C _ _)))
lemma essentially_small_congr {C : Type u} [category.{v} C] {D : Type u'} [category.{v'} D]
(e : C ≌ D) : essentially_small.{w} C ↔ essentially_small.{w} D :=
begin
fsplit,
{ rintro ⟨S, 𝒮, ⟨f⟩⟩,
resetI,
exact essentially_small.mk' (e.symm.trans f), },
{ rintro ⟨S, 𝒮, ⟨f⟩⟩,
resetI,
exact essentially_small.mk' (e.trans f), },
end
lemma discrete.essentially_small_of_small {α : Type u} [small.{w} α] :
essentially_small.{w} (discrete α) :=
⟨⟨discrete (shrink α), ⟨infer_instance, ⟨discrete.equivalence (equiv_shrink _)⟩⟩⟩⟩
lemma essentially_small_self : essentially_small.{max w v u} C :=
essentially_small.mk' (as_small.equiv : C ≌ as_small.{w} C)
/--
A category is `w`-locally small if every hom set is `w`-small.
See `shrink_homs C` for a category instance where every hom set has been replaced by a small model.
-/
class locally_small (C : Type u) [category.{v} C] : Prop :=
(hom_small : ∀ X Y : C, small.{w} (X ⟶ Y) . tactic.apply_instance)
instance (C : Type u) [category.{v} C] [locally_small.{w} C] (X Y : C) :
small (X ⟶ Y) :=
locally_small.hom_small X Y
lemma locally_small_congr {C : Type u} [category.{v} C] {D : Type u'} [category.{v'} D]
(e : C ≌ D) : locally_small.{w} C ↔ locally_small.{w} D :=
begin
fsplit,
{ rintro ⟨L⟩,
fsplit,
intros X Y,
specialize L (e.inverse.obj X) (e.inverse.obj Y),
refine (small_congr _).mpr L,
exact equiv_of_fully_faithful e.inverse, },
{ rintro ⟨L⟩,
fsplit,
intros X Y,
specialize L (e.functor.obj X) (e.functor.obj Y),
refine (small_congr _).mpr L,
exact equiv_of_fully_faithful e.functor, },
end
@[priority 100]
instance locally_small_self (C : Type u) [category.{v} C] : locally_small.{v} C := {}
@[priority 100]
instance locally_small_of_essentially_small
(C : Type u) [category.{v} C] [essentially_small.{w} C] : locally_small.{w} C :=
(locally_small_congr (equiv_small_model C)).mpr (category_theory.locally_small_self _)
/--
We define a type alias `shrink_homs C` for `C`. When we have `locally_small.{w} C`,
we'll put a `category.{w}` instance on `shrink_homs C`.
-/
@[nolint has_nonempty_instance]
def shrink_homs (C : Type u) := C
namespace shrink_homs
section
variables {C' : Type*} -- a fresh variable with no category instance attached
/-- Help the typechecker by explicitly translating from `C` to `shrink_homs C`. -/
def to_shrink_homs {C' : Type*} (X : C') : shrink_homs C' := X
/-- Help the typechecker by explicitly translating from `shrink_homs C` to `C`. -/
def from_shrink_homs {C' : Type*} (X : shrink_homs C') : C' := X
@[simp] lemma to_from (X : C') : from_shrink_homs (to_shrink_homs X) = X := rfl
@[simp] lemma from_to (X : shrink_homs C') : to_shrink_homs (from_shrink_homs X) = X := rfl
end
variables (C) [locally_small.{w} C]
@[simps]
noncomputable
instance : category.{w} (shrink_homs C) :=
{ hom := λ X Y, shrink (from_shrink_homs X ⟶ from_shrink_homs Y),
id := λ X, equiv_shrink _ (𝟙 (from_shrink_homs X)),
comp := λ X Y Z f g,
equiv_shrink _ (((equiv_shrink _).symm f) ≫ ((equiv_shrink _).symm g)), }.
/-- Implementation of `shrink_homs.equivalence`. -/
@[simps]
noncomputable
def functor : C ⥤ shrink_homs C :=
{ obj := λ X, to_shrink_homs X,
map := λ X Y f, equiv_shrink (X ⟶ Y) f, }
/-- Implementation of `shrink_homs.equivalence`. -/
@[simps]
noncomputable
def inverse : shrink_homs C ⥤ C :=
{ obj := λ X, from_shrink_homs X,
map := λ X Y f, (equiv_shrink (from_shrink_homs X ⟶ from_shrink_homs Y)).symm f, }
/--
The categorical equivalence between `C` and `shrink_homs C`, when `C` is locally small.
-/
@[simps]
noncomputable
def equivalence : C ≌ shrink_homs C :=
equivalence.mk (functor C) (inverse C)
(nat_iso.of_components (λ X, iso.refl X) (by tidy))
(nat_iso.of_components (λ X, iso.refl X) (by tidy))
end shrink_homs
/--
A category is essentially small if and only if
the underlying type of its skeleton (i.e. the "set" of isomorphism classes) is small,
and it is locally small.
-/
theorem essentially_small_iff (C : Type u) [category.{v} C] :
essentially_small.{w} C ↔ small.{w} (skeleton C) ∧ locally_small.{w} C :=
begin
-- This theorem is the only bit of real work in this file.
fsplit,
{ intro h,
fsplit,
{ rcases h with ⟨S, 𝒮, ⟨e⟩⟩,
resetI,
refine ⟨⟨skeleton S, ⟨_⟩⟩⟩,
exact e.skeleton_equiv, },
{ resetI, apply_instance, }, },
{ rintro ⟨⟨S, ⟨e⟩⟩, L⟩,
resetI,
let e' := (shrink_homs.equivalence C).skeleton_equiv.symm,
refine ⟨⟨S, _, ⟨_⟩⟩⟩,
apply induced_category.category (e'.trans e).symm,
refine (shrink_homs.equivalence C).trans
((skeleton_equivalence _).symm.trans
((induced_functor (e'.trans e).symm).as_equivalence.symm)), },
end
/--
Any thin category is locally small.
-/
@[priority 100]
instance locally_small_of_thin {C : Type u} [category.{v} C] [∀ X Y : C, subsingleton (X ⟶ Y)] :
locally_small.{w} C := {}
/--
A thin category is essentially small if and only if the underlying type of its skeleton is small.
-/
theorem essentially_small_iff_of_thin
{C : Type u} [category.{v} C] [∀ X Y : C, subsingleton (X ⟶ Y)] :
essentially_small.{w} C ↔ small.{w} (skeleton C) :=
by simp [essentially_small_iff, category_theory.locally_small_of_thin]
end category_theory
|
0bfac6738fb86d499ea10aae958573af0950dadb | 94e33a31faa76775069b071adea97e86e218a8ee | /src/analysis/convex/stone_separation.lean | 982fa58bd1e8dcc38bc2ca665a57517e7231ad73 | [
"Apache-2.0"
] | permissive | urkud/mathlib | eab80095e1b9f1513bfb7f25b4fa82fa4fd02989 | 6379d39e6b5b279df9715f8011369a301b634e41 | refs/heads/master | 1,658,425,342,662 | 1,658,078,703,000 | 1,658,078,703,000 | 186,910,338 | 0 | 0 | Apache-2.0 | 1,568,512,083,000 | 1,557,958,709,000 | Lean | UTF-8 | Lean | false | false | 5,108 | lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import analysis.convex.join
/-!
# Stone's separation theorem
This file prove Stone's separation theorem. This tells us that any two disjoint convex sets can be
separated by a convex set whose complement is also convex.
In locally convex real topological vector spaces, the Hahn-Banach separation theorems provide
stronger statements: one may find a separating hyperplane, instead of merely a convex set whose
complement is convex.
-/
open set
open_locale big_operators
variables {𝕜 E ι : Type*} [linear_ordered_field 𝕜] [add_comm_group E] [module 𝕜 E] {s t : set E}
/-- In a tetrahedron with vertices `x`, `y`, `p`, `q`, any segment `[u, v]` joining the opposite
edges `[x, p]` and `[y, q]` passes through any triangle of vertices `p`, `q`, `z` where
`z ∈ [x, y]`. -/
lemma not_disjoint_segment_convex_hull_triple {p q u v x y z : E}
(hz : z ∈ segment 𝕜 x y) (hu : u ∈ segment 𝕜 x p) (hv : v ∈ segment 𝕜 y q) :
¬ disjoint (segment 𝕜 u v) (convex_hull 𝕜 {p, q, z}) :=
begin
rw not_disjoint_iff,
obtain ⟨az, bz, haz, hbz, habz, rfl⟩ := hz,
obtain rfl | haz' := haz.eq_or_lt,
{ rw zero_add at habz,
rw [zero_smul, zero_add, habz, one_smul],
refine ⟨v, right_mem_segment _ _ _, segment_subset_convex_hull _ _ hv⟩; simp },
obtain ⟨av, bv, hav, hbv, habv, rfl⟩ := hv,
obtain rfl | hav' := hav.eq_or_lt,
{ rw zero_add at habv,
rw [zero_smul, zero_add, habv, one_smul],
exact ⟨q, right_mem_segment _ _ _, subset_convex_hull _ _ $ by simp⟩ },
obtain ⟨au, bu, hau, hbu, habu, rfl⟩ := hu,
have hab : 0 < az * av + bz * au :=
add_pos_of_pos_of_nonneg (mul_pos haz' hav') (mul_nonneg hbz hau),
refine ⟨(az * av / (az * av + bz * au)) • (au • x + bu • p) +
(bz * au / (az * av + bz * au)) • (av • y + bv • q), ⟨_, _, _, _, _, rfl⟩, _⟩,
{ exact div_nonneg (mul_nonneg haz hav) hab.le },
{ exact div_nonneg (mul_nonneg hbz hau) hab.le },
{ rw [←add_div, div_self hab.ne'] },
rw [smul_add, smul_add, add_add_add_comm, add_comm, ←mul_smul, ←mul_smul],
classical,
let w : fin 3 → 𝕜 := ![az * av * bu, bz * au * bv, au * av],
let z : fin 3 → E := ![p, q, az • x + bz • y],
have hw₀ : ∀ i, 0 ≤ w i,
{ rintro i,
fin_cases i,
{ exact mul_nonneg (mul_nonneg haz hav) hbu },
{ exact mul_nonneg (mul_nonneg hbz hau) hbv },
{ exact mul_nonneg hau hav } },
have hw : ∑ i, w i = az * av + bz * au,
{ transitivity az * av * bu + (bz * au * bv + au * av),
{ simp [w, fin.sum_univ_succ, fin.sum_univ_zero] },
rw [←one_mul (au * av), ←habz, add_mul, ←add_assoc, add_add_add_comm, mul_assoc, ←mul_add,
mul_assoc, ←mul_add, mul_comm av, ←add_mul, ←mul_add, add_comm bu, add_comm bv, habu, habv,
one_mul, mul_one] },
have hz : ∀ i, z i ∈ ({p, q, az • x + bz • y} : set E),
{ rintro i,
fin_cases i; simp [z] },
convert finset.center_mass_mem_convex_hull (finset.univ : finset (fin 3)) (λ i _, hw₀ i)
(by rwa hw) (λ i _, hz i),
rw finset.center_mass,
simp_rw [div_eq_inv_mul, hw, mul_assoc, mul_smul (az * av + bz * au)⁻¹, ←smul_add, add_assoc,
←mul_assoc],
congr' 3,
rw [←mul_smul, ←mul_rotate, mul_right_comm, mul_smul, ←mul_smul _ av, mul_rotate, mul_smul _ bz,
←smul_add],
simp only [list.map, list.pmap, nat.add_def, add_zero, fin.mk_eq_subtype_mk, fin.mk_bit0,
fin.mk_one, list.foldr_cons, list.foldr_nil],
refl,
end
/-- **Stone's Separation Theorem** -/
lemma exists_convex_convex_compl_subset (hs : convex 𝕜 s) (ht : convex 𝕜 t) (hst : disjoint s t) :
∃ C : set E, convex 𝕜 C ∧ convex 𝕜 Cᶜ ∧ s ⊆ C ∧ t ⊆ Cᶜ :=
begin
let S : set (set E) := {C | convex 𝕜 C ∧ disjoint C t},
obtain ⟨C, hC, hsC, hCmax⟩ := zorn_subset_nonempty S
(λ c hcS hc ⟨t, ht⟩, ⟨⋃₀ c, ⟨hc.directed_on.convex_sUnion (λ s hs, (hcS hs).1),
disjoint_sUnion_left.2 $ λ c hc, (hcS hc).2⟩, λ s, subset_sUnion_of_mem⟩) s ⟨hs, hst⟩,
refine ⟨C, hC.1, convex_iff_segment_subset.2 $ λ x y hx hy z hz hzC, _, hsC,
hC.2.subset_compl_left⟩,
suffices h : ∀ c ∈ Cᶜ, ∃ a ∈ C, (segment 𝕜 c a ∩ t).nonempty,
{ obtain ⟨p, hp, u, hu, hut⟩ := h x hx,
obtain ⟨q, hq, v, hv, hvt⟩ := h y hy,
refine not_disjoint_segment_convex_hull_triple hz hu hv
(hC.2.symm.mono (ht.segment_subset hut hvt) $ convex_hull_min _ hC.1),
simp [insert_subset, hp, hq, singleton_subset_iff.2 hzC] },
rintro c hc,
by_contra' h,
suffices h : disjoint (convex_hull 𝕜 (insert c C)) t,
{ rw ←hCmax _ ⟨convex_convex_hull _ _, h⟩
((subset_insert _ _).trans $ subset_convex_hull _ _) at hc,
exact hc (subset_convex_hull _ _ $ mem_insert _ _) },
rw [convex_hull_insert ⟨z, hzC⟩, convex_join_singleton_left],
refine disjoint_Union₂_left.2 (λ a ha b hb, h a _ ⟨b, hb⟩),
rwa ←hC.1.convex_hull_eq,
end
|
ac32aee48fffffc999833f92c2f0255f02e61047 | e0f9ba56b7fedc16ef8697f6caeef5898b435143 | /src/data/prod.lean | 8b193adf68926a410ffec3bef0064d0b2659528e | [
"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 | 4,096 | 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 tactic.ext
/-!
# Extra facts about `prod`
This file defines `prod.swap : α × β → β × α` and proves various simple lemmas about `prod`.
-/
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
@[simp] theorem prod.forall {p : α × β → Prop} : (∀ x, p x) ↔ (∀ a b, p (a, b)) :=
⟨assume h a b, h (a, b), assume h ⟨a, b⟩, h a b⟩
@[simp] theorem prod.exists {p : α × β → Prop} : (∃ x, p x) ↔ (∃ a b, p (a, b)) :=
⟨assume ⟨⟨a, b⟩, h⟩, ⟨a, b, h⟩, assume ⟨a, b, h⟩, ⟨⟨a, b⟩, h⟩⟩
namespace prod
@[simp] lemma map_mk (f : α → γ) (g : β → δ) (a : α) (b : β) : map f g (a, b) = (f a, g b) := rfl
@[simp] lemma map_fst (f : α → γ) (g : β → δ) (p : α × β) : (map f g p).1 = f (p.1) := rfl
@[simp] lemma map_snd (f : α → γ) (g : β → δ) (p : α × β) : (map f g p).2 = g (p.2) := rfl
@[simp] lemma map_fst' (f : α → γ) (g : β → δ) : (prod.fst ∘ map f g) = f ∘ prod.fst :=
funext $ map_fst f g
@[simp] lemma map_snd' (f : α → γ) (g : β → δ) : (prod.snd ∘ map f g) = g ∘ prod.snd :=
funext $ map_snd f g
@[simp] theorem mk.inj_iff {a₁ a₂ : α} {b₁ b₂ : β} : (a₁, b₁) = (a₂, b₂) ↔ (a₁ = a₂ ∧ b₁ = b₂) :=
⟨prod.mk.inj, by cc⟩
lemma ext_iff {p q : α × β} : p = q ↔ p.1 = q.1 ∧ p.2 = q.2 :=
by rw [← @mk.eta _ _ p, ← @mk.eta _ _ q, mk.inj_iff]
@[ext]
lemma ext {α β} {p q : α × β} (h₁ : p.1 = q.1) (h₂ : p.2 = q.2) : p = q :=
ext_iff.2 ⟨h₁, h₂⟩
lemma map_def {f : α → γ} {g : β → δ} : prod.map f g = λ (p : α × β), (f p.1, g p.2) :=
funext (λ p, ext (map_fst f g p) (map_snd f g p))
lemma id_prod : (λ (p : α × α), (p.1, p.2)) = id :=
funext $ λ ⟨a, b⟩, rfl
lemma fst_surjective [h : nonempty β] : function.surjective (@fst α β) :=
λ x, h.elim $ λ y, ⟨⟨x, y⟩, rfl⟩
lemma snd_surjective [h : nonempty α] : function.surjective (@snd α β) :=
λ y, h.elim $ λ x, ⟨⟨x, y⟩, rfl⟩
lemma fst_injective [subsingleton β] : function.injective (@fst α β) :=
λ x y h, ext h (subsingleton.elim _ _)
lemma snd_injective [subsingleton α] : function.injective (@snd α β) :=
λ x y h, ext (subsingleton.elim _ _) h
/-- Swap the factors of a product. `swap (a, b) = (b, a)` -/
def swap : α × β → β × α := λp, (p.2, p.1)
@[simp] lemma swap_swap : ∀ x : α × β, swap (swap x) = x
| ⟨a, b⟩ := rfl
@[simp] lemma fst_swap {p : α × β} : (swap p).1 = p.2 := rfl
@[simp] lemma snd_swap {p : α × β} : (swap p).2 = p.1 := rfl
@[simp] lemma swap_prod_mk {a : α} {b : β} : swap (a, b) = (b, a) := rfl
@[simp] lemma swap_swap_eq : swap ∘ swap = @id (α × β) :=
funext swap_swap
@[simp] lemma swap_left_inverse : function.left_inverse (@swap α β) swap :=
swap_swap
@[simp] lemma swap_right_inverse : function.right_inverse (@swap α β) swap :=
swap_swap
lemma eq_iff_fst_eq_snd_eq : ∀{p q : α × β}, p = q ↔ (p.1 = q.1 ∧ p.2 = q.2)
| ⟨p₁, p₂⟩ ⟨q₁, q₂⟩ := by simp
theorem lex_def (r : α → α → Prop) (s : β → β → Prop)
{p q : α × β} : prod.lex r s p q ↔ r p.1 q.1 ∨ p.1 = q.1 ∧ s p.2 q.2 :=
⟨λ h, by cases h; simp *,
λ h, match p, q, h with
| (a, b), (c, d), or.inl h := lex.left _ _ h
| (a, b), (c, d), or.inr ⟨e, h⟩ :=
by change a = c at e; subst e; exact lex.right _ h
end⟩
instance lex.decidable [decidable_eq α]
(r : α → α → Prop) (s : β → β → Prop) [decidable_rel r] [decidable_rel s] :
decidable_rel (prod.lex r s) :=
λ p q, decidable_of_decidable_of_iff (by apply_instance) (lex_def r s).symm
end prod
open function
lemma function.injective.prod {f : α → γ} {g : β → δ} (hf : injective f) (hg : injective g) :
injective (λ p : α × β, (f p.1, g p.2)) :=
assume ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ h,
have a₁ = a₂, from hf (by cc),
have b₁ = b₂, from hg (by cc),
by cc
|
aa786ad9072ae504e7d74f5cc5d286cbce46fd34 | 3af272061d36e7f3f0521cceaa3a847ed4e03af9 | /src/modular_forms.lean | 937b578c3003f5c0faa9a6c83c6d81af32d8c68d | [] | no_license | semorrison/kbb | fdab0929d21dca880d835081814225a95f946187 | 229bd06e840bc7a7438b8fee6802a4f8024419e3 | refs/heads/master | 1,585,351,834,355 | 1,539,848,241,000 | 1,539,848,241,000 | 147,323,315 | 2 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 4,044 | lean | import tactic.ring
import group_theory.group_action
import algebra.module
import algebra.pi_instances
import linear_algebra.subtype_module
import .holomorphic_functions
import .upper_half_space
universes u v
open complex
local notation `ℍ` := upper_half_space
def is_Petersson_weight_ (k : ℕ) := { f : ℍ → ℂ | ∀ M : SL2Z, ∀ z : ℍ, f (SL2Z_H M z) = (M.c*z + M.d)^k * f z }
def is_bound_at_infinity := { f : ℍ → ℂ | ∃ (M A : ℝ), ∀ z : ℍ, im z ≥ A → abs (f z) ≤ M }
def is_zero_at_infinity := { f : ℍ → ℂ | ∀ ε : ℝ, ε > 0 → ∃ A : ℝ, ∀ z : ℍ, im z ≥ A → abs (f z) ≤ ε }
instance (k : ℕ) : is_submodule (is_Petersson_weight_ k) :=
{ zero_ := λ M z, by simp,
add_ := λ f g hf hg M z, begin
suffices : f (SL2Z_H M z) + g (SL2Z_H M z) = (↑(M.c) * ↑z + ↑(M.d)) ^ k * (f z + g z),
by simp at *; assumption,
rw [hf, hg],
ring
end,
smul := λ c f hyp M z, begin
suffices : c * f (SL2Z_H M z) = (↑(M.c) * ↑z + ↑(M.d)) ^ k * (c * f z),
by simp at *; assumption,
rw hyp M z,
ring
end }
instance : is_submodule is_bound_at_infinity :=
{ zero_ := ⟨0, ⟨0, λ z h, by simp⟩⟩,
add_ := λ f g hf hg, begin
cases hf with Mf hMf,
cases hg with Mg hMg,
cases hMf with Af hAMf,
cases hMg with Ag hAMg,
existsi (Mf + Mg),
existsi (max Af Ag),
intros z hz,
simp,
apply le_trans (complex.abs_add _ _),
apply add_le_add,
{ refine hAMf z _,
exact le_trans (le_max_left _ _) hz },
{ refine hAMg z _,
exact le_trans (le_max_right _ _) hz }
end,
smul := λ c f hyp, begin
cases hyp with M hM,
cases hM with A hAM,
existsi (abs c * M),
existsi A,
intros z hz,
simp,
apply mul_le_mul_of_nonneg_left (hAM z hz) (complex.abs_nonneg c)
end }
instance : is_submodule is_zero_at_infinity :=
{ zero_ := λ ε hε, ⟨1, λ z hz, by simp; exact le_of_lt hε⟩,
add_ := λ f g hf hg ε hε, begin
cases hf (ε/2) (half_pos hε) with Af hAf,
cases hg (ε/2) (half_pos hε) with Ag hAg,
existsi (max Af Ag),
intros z hz,
simp,
apply le_trans (complex.abs_add _ _),
rw show ε = ε / 2 + ε / 2, by simp,
apply add_le_add,
{ refine hAf z (le_trans (le_max_left _ _) hz) },
{ refine hAg z (le_trans (le_max_right _ _) hz) }
end,
smul := λ c f hyp ε hε, begin
by_cases hc : (c = 0),
{ existsi (0 : ℝ ), intros, simp [hc], exact le_of_lt hε },
{ cases hyp (ε / abs c) (lt_div_of_mul_lt (by simp [hc]) (by simp; exact hε)) with A hA,
existsi A,
intros z hz,
simp,
rw show ε = abs c * (ε / abs c),
begin
rw [mul_comm],
refine (div_mul_cancel _ _).symm,
simp [hc]
end,
apply mul_le_mul_of_nonneg_left (hA z hz) (complex.abs_nonneg c), }
end }
lemma is_bound_at_infinity_of_is_zero_at_infinity {f : ℍ → ℂ} (h : is_zero_at_infinity f) :
is_bound_at_infinity f := ⟨1, h 1 zero_lt_one⟩
-- structure is_modular_form (k : ℕ) (f : ℍ → ℂ) : Prop :=
-- (hol : is_holomorphic f)
-- (transf : ∀ M : SL2Z, ∀ z : ℍ, f (SL2Z_H M z) = (M.c*z + M.d)^k * f z)
-- (infinity : ∃ (M A : ℝ), ∀ z : ℍ, im z ≥ A → abs (f z) ≤ M)
def is_modular_form (k : ℕ) := {f : ℍ → ℂ | is_holomorphic f} ∩ (is_Petersson_weight_ k) ∩ is_bound_at_infinity
def is_cusp_form (k : ℕ) := {f : ℍ → ℂ | is_holomorphic f} ∩ (is_Petersson_weight_ k) ∩ is_zero_at_infinity
lemma is_modular_form_of_is_cusp_form {k : ℕ} (f : ℍ → ℂ) (h : is_cusp_form k f) : is_modular_form k f :=
⟨h.1, is_bound_at_infinity_of_is_zero_at_infinity h.2⟩
instance (k : ℕ) : is_submodule (is_modular_form k) := is_submodule.inter_submodule
instance (k : ℕ) : is_submodule (is_cusp_form k) := is_submodule.inter_submodule
/- def Hecke_operator {k : ℕ} (m : ℤ) : modular_forms k → modular_forms k :=
λ f,
(m^k.pred : ℂ) • (sorry : modular_forms k) -- why is this • failing?
-/
|
1845e9c7de52a0ef439ff79dc2867ed8373966c9 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/linear_algebra/affine_space/basic_auto.lean | 2f38aa87b372501aabfdfb64b7b748c7336818dc | [] | 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,767 | lean | /-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Joseph Myers
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.add_torsor
import Mathlib.PostPort
namespace Mathlib
/-!
# Affine space
In this file we introduce the following notation:
* `affine_space V P` is an alternative notation for `add_torsor V P` introduced at the end of this
file.
We tried to use an `abbreviation` instead of a `notation` but this led to hard-to-debug elaboration
errors. So, we introduce a localized notation instead. When this notation is enabled with
`open_locale affine`, Lean will use `affine_space` instead of `add_torsor` both in input and in the
proof state.
Here is an incomplete list of notions related to affine spaces, all of them are defined in other
files:
* `affine_map`: a map between affine spaces that preserves the affine structure;
* `affine_equiv`: an equivalence between affine spaces that preserves the affine structure;
* `affine_subspace`: a subset of an affine space closed w.r.t. affine combinations of points;
* `affine_combination`: an affine combination of points;
* `affine_independent`: affine independent set of points.
## TODO
Some key definitions are not yet present.
* Affine frames. An affine frame might perhaps be represented as an `affine_equiv` to a `finsupp`
(in the general case) or function type (in the finite-dimensional case) that gives the
coordinates, with appropriate proofs of existence when `k` is a field.
* Although results on affine combinations implicitly provide barycentric frames and coordinates,
there is no explicit representation of the map from a point to its coordinates.
-/
end Mathlib |
1beadbe194b17f8645ed246783825c4356485757 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/topology/fiber_bundle/constructions.lean | 4b3df9b72c90e655c360e23ceb43e24055f2818f | [
"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 | 16,737 | lean | /-
Copyright © 2022 Nicolò Cavalleri. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nicolò Cavalleri, Sébastien Gouëzel, Heather Macbeth, Floris van Doorn
-/
import topology.fiber_bundle.basic
/-!
# Standard constructions on fiber bundles
This file contains several standard constructions on fiber bundles:
* `bundle.trivial.fiber_bundle 𝕜 B F`: the trivial fiber bundle with model fibre `F` over the base
`B`
* `fiber_bundle.prod`: for fiber bundles `E₁` and `E₂` over a common base, a fiber bundle structure
on their fibrewise product `E₁ ×ᵇ E₂` (the notation stands for `λ x, E₁ x × E₂ x`).
* `fiber_bundle.pullback`: for a fiber bundle `E` over `B`, a fiber bundle structure on its
pullback `f *ᵖ E` by a map `f : B' → B` (the notation is a type synonym for `E ∘ f`).
## Tags
fiber bundle, fibre bundle, fiberwise product, pullback
-/
open topological_space filter set bundle
open_locale topological_space classical bundle
/-! ### The trivial bundle -/
namespace bundle
namespace trivial
variables (B : Type*) (F : Type*)
instance [I : topological_space F] : ∀ x : B, topological_space (trivial B F x) := λ x, I
instance [t₁ : topological_space B] [t₂ : topological_space F] :
topological_space (total_space (trivial B F)) :=
induced total_space.proj t₁ ⊓ induced (trivial.proj_snd B F) t₂
variables [topological_space B] [topological_space F]
/-- Local trivialization for trivial bundle. -/
def trivialization : trivialization F (π (bundle.trivial B F)) :=
{ to_fun := λ x, (x.fst, x.snd),
inv_fun := λ y, ⟨y.fst, y.snd⟩,
source := univ,
target := univ,
map_source' := λ x h, mem_univ (x.fst, x.snd),
map_target' := λ y h, mem_univ ⟨y.fst, y.snd⟩,
left_inv' := λ x h, sigma.eq rfl rfl,
right_inv' := λ x h, prod.ext rfl rfl,
open_source := is_open_univ,
open_target := is_open_univ,
continuous_to_fun := by { rw [←continuous_iff_continuous_on_univ, continuous_iff_le_induced],
simp only [prod.topological_space, induced_inf, induced_compose], exact le_rfl, },
continuous_inv_fun := by { rw [←continuous_iff_continuous_on_univ, continuous_iff_le_induced],
simp only [bundle.total_space.topological_space, induced_inf, induced_compose],
exact le_rfl, },
base_set := univ,
open_base_set := is_open_univ,
source_eq := rfl,
target_eq := by simp only [univ_prod_univ],
proj_to_fun := λ y hy, rfl }
@[simp]
lemma trivialization_source : (trivialization B F).source = univ := rfl
@[simp]
lemma trivialization_target : (trivialization B F).target = univ := rfl
/-- Fiber bundle instance on the trivial bundle. -/
instance fiber_bundle : fiber_bundle F (bundle.trivial B F) :=
{ trivialization_atlas := {bundle.trivial.trivialization B F},
trivialization_at := λ x, bundle.trivial.trivialization B F,
mem_base_set_trivialization_at := mem_univ,
trivialization_mem_atlas := λ x, mem_singleton _,
total_space_mk_inducing := λ b, ⟨begin
have : (λ (x : trivial B F b), x) = @id F, by { ext x, refl },
simp only [total_space.topological_space, induced_inf, induced_compose, function.comp,
total_space.proj, induced_const, top_inf_eq, trivial.proj_snd, id.def,
trivial.topological_space, this, induced_id],
end⟩ }
lemma eq_trivialization (e : _root_.trivialization F (π (bundle.trivial B F)))
[i : mem_trivialization_atlas e] :
e = trivialization B F :=
i.out
end trivial
end bundle
/-! ### Fibrewise product of two bundles -/
section prod
variables {B : Type*}
section defs
variables (E₁ : B → Type*) (E₂ : B → Type*)
variables [topological_space (total_space E₁)] [topological_space (total_space E₂)]
/-- Equip the total space of the fibrewise product of two fiber bundles `E₁`, `E₂` with
the induced topology from the diagonal embedding into `total_space E₁ × total_space E₂`. -/
instance fiber_bundle.prod.topological_space : topological_space (total_space (E₁ ×ᵇ E₂)) :=
topological_space.induced
(λ p, ((⟨p.1, p.2.1⟩ : total_space E₁), (⟨p.1, p.2.2⟩ : total_space E₂)))
(by apply_instance : topological_space (total_space E₁ × total_space E₂))
/-- The diagonal map from the total space of the fibrewise product of two fiber bundles
`E₁`, `E₂` into `total_space E₁ × total_space E₂` is `inducing`. -/
lemma fiber_bundle.prod.inducing_diag : inducing
(λ p, (⟨p.1, p.2.1⟩, ⟨p.1, p.2.2⟩) :
total_space (E₁ ×ᵇ E₂) → total_space E₁ × total_space E₂) :=
⟨rfl⟩
end defs
open fiber_bundle
variables [topological_space B]
(F₁ : Type*) [topological_space F₁] (E₁ : B → Type*) [topological_space (total_space E₁)]
(F₂ : Type*) [topological_space F₂] (E₂ : B → Type*) [topological_space (total_space E₂)]
namespace trivialization
variables {F₁ E₁ F₂ E₂} (e₁ : trivialization F₁ (π E₁)) (e₂ : trivialization F₂ (π E₂))
/-- Given trivializations `e₁`, `e₂` for fiber bundles `E₁`, `E₂` over a base `B`, the forward
function for the construction `trivialization.prod`, the induced
trivialization for the fibrewise product of `E₁` and `E₂`. -/
def prod.to_fun' : total_space (E₁ ×ᵇ E₂) → B × (F₁ × F₂) :=
λ p, ⟨p.1, (e₁ ⟨p.1, p.2.1⟩).2, (e₂ ⟨p.1, p.2.2⟩).2⟩
variables {e₁ e₂}
lemma prod.continuous_to_fun : continuous_on (prod.to_fun' e₁ e₂)
(@total_space.proj B (E₁ ×ᵇ E₂) ⁻¹' (e₁.base_set ∩ e₂.base_set)) :=
begin
let f₁ : total_space (E₁ ×ᵇ E₂) → total_space E₁ × total_space E₂ :=
λ p, ((⟨p.1, p.2.1⟩ : total_space E₁), (⟨p.1, p.2.2⟩ : total_space E₂)),
let f₂ : total_space E₁ × total_space E₂ → (B × F₁) × (B × F₂) := λ p, ⟨e₁ p.1, e₂ p.2⟩,
let f₃ : (B × F₁) × (B × F₂) → B × F₁ × F₂ := λ p, ⟨p.1.1, p.1.2, p.2.2⟩,
have hf₁ : continuous f₁ := (prod.inducing_diag E₁ E₂).continuous,
have hf₂ : continuous_on f₂ (e₁.source ×ˢ e₂.source) :=
e₁.to_local_homeomorph.continuous_on.prod_map e₂.to_local_homeomorph.continuous_on,
have hf₃ : continuous f₃ :=
(continuous_fst.comp continuous_fst).prod_mk (continuous_snd.prod_map continuous_snd),
refine ((hf₃.comp_continuous_on hf₂).comp hf₁.continuous_on _).congr _,
{ rw [e₁.source_eq, e₂.source_eq],
exact maps_to_preimage _ _ },
rintros ⟨b, v₁, v₂⟩ ⟨hb₁, hb₂⟩,
simp only [prod.to_fun', prod.mk.inj_iff, eq_self_iff_true, and_true],
rw e₁.coe_fst,
rw [e₁.source_eq, mem_preimage],
exact hb₁,
end
variables (e₁ e₂) [Π x, has_zero (E₁ x)] [∀ x, has_zero (E₂ x)]
/-- Given trivializations `e₁`, `e₂` for fiber bundles `E₁`, `E₂` over a base `B`, the inverse
function for the construction `trivialization.prod`, the induced
trivialization for the fibrewise product of `E₁` and `E₂`. -/
noncomputable def prod.inv_fun' (p : B × (F₁ × F₂)) : total_space (E₁ ×ᵇ E₂) :=
⟨p.1, e₁.symm p.1 p.2.1, e₂.symm p.1 p.2.2⟩
variables {e₁ e₂}
lemma prod.left_inv {x : total_space (E₁ ×ᵇ E₂)}
(h : x ∈ @total_space.proj B (E₁ ×ᵇ E₂) ⁻¹' (e₁.base_set ∩ e₂.base_set)) :
prod.inv_fun' e₁ e₂ (prod.to_fun' e₁ e₂ x) = x :=
begin
obtain ⟨x, v₁, v₂⟩ := x,
obtain ⟨h₁ : x ∈ e₁.base_set, h₂ : x ∈ e₂.base_set⟩ := h,
simp only [prod.to_fun', prod.inv_fun', symm_apply_apply_mk, h₁, h₂]
end
lemma prod.right_inv {x : B × F₁ × F₂}
(h : x ∈ (e₁.base_set ∩ e₂.base_set) ×ˢ (univ : set (F₁ × F₂))) :
prod.to_fun' e₁ e₂ (prod.inv_fun' e₁ e₂ x) = x :=
begin
obtain ⟨x, w₁, w₂⟩ := x,
obtain ⟨⟨h₁ : x ∈ e₁.base_set, h₂ : x ∈ e₂.base_set⟩, -⟩ := h,
simp only [prod.to_fun', prod.inv_fun', apply_mk_symm, h₁, h₂]
end
lemma prod.continuous_inv_fun :
continuous_on (prod.inv_fun' e₁ e₂) ((e₁.base_set ∩ e₂.base_set) ×ˢ univ) :=
begin
rw (prod.inducing_diag E₁ E₂).continuous_on_iff,
have H₁ : continuous (λ p : B × F₁ × F₂, ((p.1, p.2.1), (p.1, p.2.2))) :=
(continuous_id.prod_map continuous_fst).prod_mk (continuous_id.prod_map continuous_snd),
refine (e₁.continuous_on_symm.prod_map e₂.continuous_on_symm).comp H₁.continuous_on _,
exact λ x h, ⟨⟨h.1.1, mem_univ _⟩, ⟨h.1.2, mem_univ _⟩⟩
end
variables (e₁ e₂ e₁ e₂)
/-- Given trivializations `e₁`, `e₂` for bundle types `E₁`, `E₂` over a base `B`, the induced
trivialization for the fibrewise product of `E₁` and `E₂`, whose base set is
`e₁.base_set ∩ e₂.base_set`. -/
noncomputable def prod : trivialization (F₁ × F₂) (π (E₁ ×ᵇ E₂)) :=
{ to_fun := prod.to_fun' e₁ e₂,
inv_fun := prod.inv_fun' e₁ e₂,
source := (@total_space.proj B (E₁ ×ᵇ E₂)) ⁻¹' (e₁.base_set ∩ e₂.base_set),
target := (e₁.base_set ∩ e₂.base_set) ×ˢ set.univ,
map_source' := λ x h, ⟨h, set.mem_univ _⟩,
map_target' := λ x h, h.1,
left_inv' := λ x, prod.left_inv,
right_inv' := λ x, prod.right_inv,
open_source := begin
convert (e₁.open_source.prod e₂.open_source).preimage
(fiber_bundle.prod.inducing_diag E₁ E₂).continuous,
ext x,
simp only [trivialization.source_eq] with mfld_simps,
end,
open_target := (e₁.open_base_set.inter e₂.open_base_set).prod is_open_univ,
continuous_to_fun := prod.continuous_to_fun,
continuous_inv_fun := prod.continuous_inv_fun,
base_set := e₁.base_set ∩ e₂.base_set,
open_base_set := e₁.open_base_set.inter e₂.open_base_set,
source_eq := rfl,
target_eq := rfl,
proj_to_fun := λ x h, rfl }
@[simp] lemma base_set_prod : (prod e₁ e₂).base_set = e₁.base_set ∩ e₂.base_set :=
rfl
lemma prod_symm_apply (x : B) (w₁ : F₁) (w₂ : F₂) : (prod e₁ e₂).to_local_equiv.symm (x, w₁, w₂)
= ⟨x, e₁.symm x w₁, e₂.symm x w₂⟩ :=
rfl
end trivialization
open trivialization
variables [Π x, has_zero (E₁ x)] [∀ x, has_zero (E₂ x)]
[Π x : B, topological_space (E₁ x)] [Π x : B, topological_space (E₂ x)]
[fiber_bundle F₁ E₁] [fiber_bundle F₂ E₂]
/-- The product of two fiber bundles is a fiber bundle. -/
noncomputable instance fiber_bundle.prod : fiber_bundle (F₁ × F₂) (E₁ ×ᵇ E₂) :=
{ total_space_mk_inducing := λ b,
begin
rw (prod.inducing_diag E₁ E₂).inducing_iff,
exact (total_space_mk_inducing F₁ E₁ b).prod_mk (total_space_mk_inducing F₂ E₂ b),
end,
trivialization_atlas :=
{e | ∃ (e₁ : trivialization F₁ (π E₁)) (e₂ : trivialization F₂ (π E₂))
[mem_trivialization_atlas e₁] [mem_trivialization_atlas e₂], by exactI
e = trivialization.prod e₁ e₂},
trivialization_at := λ b, (trivialization_at F₁ E₁ b).prod (trivialization_at F₂ E₂ b),
mem_base_set_trivialization_at :=
λ b, ⟨mem_base_set_trivialization_at F₁ E₁ b, mem_base_set_trivialization_at F₂ E₂ b⟩,
trivialization_mem_atlas := λ b, ⟨trivialization_at F₁ E₁ b, trivialization_at F₂ E₂ b,
by apply_instance, by apply_instance, rfl⟩ }
instance {e₁ : trivialization F₁ (π E₁)} {e₂ : trivialization F₂ (π E₂)}
[mem_trivialization_atlas e₁] [mem_trivialization_atlas e₂] :
mem_trivialization_atlas (e₁.prod e₂ : trivialization (F₁ × F₂) (π (E₁ ×ᵇ E₂))) :=
{ out := ⟨e₁, e₂, by apply_instance, by apply_instance, rfl⟩ }
end prod
/-! ### Pullbacks of fibre bundles -/
section
variables {B : Type*} (F : Type*) (E : B → Type*) {B' : Type*} (f : B' → B)
instance [∀ (x : B), topological_space (E x)] : ∀ (x : B'), topological_space ((f *ᵖ E) x) :=
by delta_instance bundle.pullback
variables [topological_space B'] [topological_space (total_space E)]
/-- Definition of `pullback.total_space.topological_space`, which we make irreducible. -/
@[irreducible] def pullback_topology : topological_space (total_space (f *ᵖ E)) :=
induced total_space.proj ‹topological_space B'› ⊓
induced (pullback.lift f) ‹topological_space (total_space E)›
/-- The topology on the total space of a pullback bundle is the coarsest topology for which both
the projections to the base and the map to the original bundle are continuous. -/
instance pullback.total_space.topological_space : topological_space (total_space (f *ᵖ E)) :=
pullback_topology E f
lemma pullback.continuous_proj (f : B' → B) : continuous (@total_space.proj _ (f *ᵖ E)) :=
begin
rw [continuous_iff_le_induced, pullback.total_space.topological_space, pullback_topology],
exact inf_le_left,
end
lemma pullback.continuous_lift (f : B' → B) : continuous (@pullback.lift B E B' f) :=
begin
rw [continuous_iff_le_induced, pullback.total_space.topological_space, pullback_topology],
exact inf_le_right,
end
lemma inducing_pullback_total_space_embedding (f : B' → B) :
inducing (@pullback_total_space_embedding B E B' f) :=
begin
constructor,
simp_rw [prod.topological_space, induced_inf, induced_compose,
pullback.total_space.topological_space, pullback_topology],
refl
end
section fiber_bundle
variables (F) [topological_space F] [topological_space B]
lemma pullback.continuous_total_space_mk [∀ x, topological_space (E x)]
[fiber_bundle F E] {f : B' → B} {x : B'} :
continuous (@total_space_mk _ (f *ᵖ E) x) :=
begin
simp only [continuous_iff_le_induced, pullback.total_space.topological_space, induced_compose,
induced_inf, function.comp, total_space_mk, total_space.proj, induced_const, top_inf_eq,
pullback_topology],
exact le_of_eq (fiber_bundle.total_space_mk_inducing F E (f x)).induced,
end
variables {E F} [∀ b, has_zero (E b)] {K : Type*} [continuous_map_class K B' B]
/-- A fiber bundle trivialization can be pulled back to a trivialization on the pullback bundle. -/
noncomputable def trivialization.pullback (e : trivialization F (π E)) (f : K) :
trivialization F (π ((f : B' → B) *ᵖ E)) :=
{ to_fun := λ z, (z.proj, (e (pullback.lift f z)).2),
inv_fun := λ y, @total_space_mk _ (f *ᵖ E) y.1 (e.symm (f y.1) y.2),
source := pullback.lift f ⁻¹' e.source,
base_set := f ⁻¹' e.base_set,
target := (f ⁻¹' e.base_set) ×ˢ univ,
map_source' := λ x h, by { simp_rw [e.source_eq, mem_preimage, pullback.proj_lift] at h,
simp_rw [prod_mk_mem_set_prod_eq, mem_univ, and_true, mem_preimage, h] },
map_target' := λ y h, by { rw [mem_prod, mem_preimage] at h,
simp_rw [e.source_eq, mem_preimage, pullback.proj_lift, h.1] },
left_inv' := λ x h, by { simp_rw [mem_preimage, e.mem_source, pullback.proj_lift] at h,
simp_rw [pullback.lift, e.symm_apply_apply_mk h, total_space.eta] },
right_inv' := λ x h, by { simp_rw [mem_prod, mem_preimage, mem_univ, and_true] at h,
simp_rw [total_space.proj_mk, pullback.lift_mk, e.apply_mk_symm h, prod.mk.eta] },
open_source := by { simp_rw [e.source_eq, ← preimage_comp], exact ((map_continuous f).comp $
pullback.continuous_proj E f).is_open_preimage _ e.open_base_set },
open_target := ((map_continuous f).is_open_preimage _ e.open_base_set).prod is_open_univ,
open_base_set := (map_continuous f).is_open_preimage _ e.open_base_set,
continuous_to_fun := (pullback.continuous_proj E f).continuous_on.prod
(continuous_snd.comp_continuous_on $
e.continuous_on.comp (pullback.continuous_lift E f).continuous_on subset.rfl),
continuous_inv_fun := begin
dsimp only,
simp_rw [(inducing_pullback_total_space_embedding E f).continuous_on_iff, function.comp,
pullback_total_space_embedding, total_space.proj_mk],
dsimp only [total_space.proj_mk],
refine continuous_on_fst.prod (e.continuous_on_symm.comp
((map_continuous f).prod_map continuous_id).continuous_on subset.rfl)
end,
source_eq := by { dsimp only, rw e.source_eq, refl, },
target_eq := rfl,
proj_to_fun := λ y h, rfl }
noncomputable instance fiber_bundle.pullback [∀ x, topological_space (E x)]
[fiber_bundle F E] (f : K) : fiber_bundle F ((f : B' → B) *ᵖ E) :=
{ total_space_mk_inducing := λ x, inducing_of_inducing_compose
(pullback.continuous_total_space_mk F E) (pullback.continuous_lift E f)
(total_space_mk_inducing F E (f x)),
trivialization_atlas :=
{ef | ∃ (e : trivialization F (π E)) [mem_trivialization_atlas e], ef = e.pullback f},
trivialization_at := λ x, (trivialization_at F E (f x)).pullback f,
mem_base_set_trivialization_at := λ x, mem_base_set_trivialization_at F E (f x),
trivialization_mem_atlas := λ x, ⟨trivialization_at F E (f x), by apply_instance, rfl⟩ }
end fiber_bundle
end
|
542ce2695522c9645ad8dded2859193adbce7f3f | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/algebra/group_power/ring.lean | 41b643ef7bf7faf51a71b2a36c274462f146fe65 | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 7,525 | lean | /-
Copyright (c) 2015 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Robert Y. Lewis
-/
import algebra.group_power.basic
import algebra.hom.ring
/-!
# Power operations on monoids with zero, semirings, and rings
This file provides additional lemmas about the natural power operator on rings and semirings.
Further lemmas about ordered semirings and rings can be found in `algebra.group_power.lemmas`.
-/
variables {R S M : Type*}
section monoid_with_zero
variables [monoid_with_zero M]
lemma zero_pow : ∀ {n : ℕ}, 0 < n → (0 : M) ^ n = 0
| (n+1) _ := by rw [pow_succ, zero_mul]
@[simp] lemma zero_pow' : ∀ n : ℕ, n ≠ 0 → (0 : M) ^ n = 0
| 0 h := absurd rfl h
| (k+1) h := by { rw [pow_succ], exact zero_mul _ }
lemma zero_pow_eq (n : ℕ) : (0 : M)^n = if n = 0 then 1 else 0 :=
begin
split_ifs with h,
{ rw [h, pow_zero], },
{ rw [zero_pow (nat.pos_of_ne_zero h)] },
end
lemma pow_eq_zero_of_le {x : M} {n m : ℕ}
(hn : n ≤ m) (hx : x^n = 0) : x^m = 0 :=
by rw [← tsub_add_cancel_of_le hn, pow_add, hx, mul_zero]
theorem pow_eq_zero [no_zero_divisors M] {x : M} {n : ℕ} (H : x^n = 0) :
x = 0 :=
begin
induction n with n ih,
{ rw pow_zero at H,
rw [← mul_one x, H, mul_zero] },
{ rw pow_succ at H,
exact or.cases_on (mul_eq_zero.1 H) id ih }
end
@[simp] lemma pow_eq_zero_iff [no_zero_divisors M]
{a : M} {n : ℕ} (hn : 0 < n) :
a ^ n = 0 ↔ a = 0 :=
begin
refine ⟨pow_eq_zero, _⟩,
rintros rfl,
exact zero_pow hn,
end
lemma pow_eq_zero_iff' [no_zero_divisors M] [nontrivial M]
{a : M} {n : ℕ} :
a ^ n = 0 ↔ a = 0 ∧ n ≠ 0 :=
by cases (zero_le n).eq_or_gt; simp [*, ne_of_gt]
lemma pow_ne_zero_iff [no_zero_divisors M] {a : M} {n : ℕ} (hn : 0 < n) :
a ^ n ≠ 0 ↔ a ≠ 0 :=
(pow_eq_zero_iff hn).not
lemma ne_zero_pow {a : M} {n : ℕ} (hn : n ≠ 0) : a ^ n ≠ 0 → a ≠ 0 :=
by { contrapose!, rintro rfl, exact zero_pow' n hn }
@[field_simps] theorem pow_ne_zero [no_zero_divisors M]
{a : M} (n : ℕ) (h : a ≠ 0) : a ^ n ≠ 0 :=
mt pow_eq_zero h
theorem sq_eq_zero_iff [no_zero_divisors M] {a : M} : a ^ 2 = 0 ↔ a = 0 :=
pow_eq_zero_iff two_pos
@[simp] lemma zero_pow_eq_zero [nontrivial M] {n : ℕ} : (0 : M) ^ n = 0 ↔ 0 < n :=
begin
split; intro h,
{ rw [pos_iff_ne_zero], rintro rfl, simpa using h },
{ exact zero_pow' n h.ne.symm }
end
lemma ring.inverse_pow (r : M) : ∀ (n : ℕ), ring.inverse r ^ n = ring.inverse (r ^ n)
| 0 := by rw [pow_zero, pow_zero, ring.inverse_one]
| (n + 1) := by rw [pow_succ, pow_succ', ring.mul_inverse_rev' ((commute.refl r).pow_left n),
ring.inverse_pow]
end monoid_with_zero
section comm_monoid_with_zero
variables [comm_monoid_with_zero M] {n : ℕ} (hn : 0 < n)
include M hn
/-- We define `x ↦ x^n` (for positive `n : ℕ`) as a `monoid_with_zero_hom` -/
def pow_monoid_with_zero_hom : M →*₀ M :=
{ map_zero' := zero_pow hn,
..pow_monoid_hom n }
@[simp]
lemma coe_pow_monoid_with_zero_hom : (pow_monoid_with_zero_hom hn : M → M) = (^ n) := rfl
@[simp]
lemma pow_monoid_with_zero_hom_apply (a : M) : pow_monoid_with_zero_hom hn a = a ^ n := rfl
end comm_monoid_with_zero
lemma pow_dvd_pow_iff [cancel_comm_monoid_with_zero R]
{x : R} {n m : ℕ} (h0 : x ≠ 0) (h1 : ¬ is_unit x) :
x ^ n ∣ x ^ m ↔ n ≤ m :=
begin
split,
{ intro h, rw [← not_lt], intro hmn, apply h1,
have : x ^ m * x ∣ x ^ m * 1,
{ rw [← pow_succ', mul_one], exact (pow_dvd_pow _ (nat.succ_le_of_lt hmn)).trans h },
rwa [mul_dvd_mul_iff_left, ← is_unit_iff_dvd_one] at this, apply pow_ne_zero m h0 },
{ apply pow_dvd_pow }
end
section semiring
variables [semiring R] [semiring S]
protected lemma ring_hom.map_pow (f : R →+* S) (a) :
∀ n : ℕ, f (a ^ n) = (f a) ^ n :=
map_pow f a
lemma min_pow_dvd_add {n m : ℕ} {a b c : R} (ha : c ^ n ∣ a) (hb : c ^ m ∣ b) :
c ^ (min n m) ∣ a + b :=
begin
replace ha := (pow_dvd_pow c (min_le_left n m)).trans ha,
replace hb := (pow_dvd_pow c (min_le_right n m)).trans hb,
exact dvd_add ha hb
end
end semiring
section comm_semiring
variables [comm_semiring R]
lemma add_sq (a b : R) : (a + b) ^ 2 = a ^ 2 + 2 * a * b + b ^ 2 :=
by simp only [sq, add_mul_self_eq]
lemma add_sq' (a b : R) : (a + b) ^ 2 = a ^ 2 + b ^ 2 + 2 * a * b :=
by rw [add_sq, add_assoc, add_comm _ (b ^ 2), add_assoc]
alias add_sq ← add_pow_two
end comm_semiring
section has_distrib_neg
variables [monoid R] [has_distrib_neg R]
variables (R)
theorem neg_one_pow_eq_or : ∀ n : ℕ, (-1 : R)^n = 1 ∨ (-1 : R)^n = -1
| 0 := or.inl (pow_zero _)
| (n+1) := (neg_one_pow_eq_or n).swap.imp
(λ h, by rw [pow_succ, h, neg_one_mul, neg_neg])
(λ h, by rw [pow_succ, h, mul_one])
variables {R}
theorem neg_pow (a : R) (n : ℕ) : (- a) ^ n = (-1) ^ n * a ^ n :=
(neg_one_mul a) ▸ (commute.neg_one_left a).mul_pow n
@[simp] theorem neg_pow_bit0 (a : R) (n : ℕ) : (- a) ^ (bit0 n) = a ^ (bit0 n) :=
by rw [pow_bit0', neg_mul_neg, pow_bit0']
@[simp] theorem neg_pow_bit1 (a : R) (n : ℕ) : (- a) ^ (bit1 n) = - a ^ (bit1 n) :=
by simp only [bit1, pow_succ, neg_pow_bit0, neg_mul_eq_neg_mul]
@[simp] lemma neg_sq (a : R) : (-a) ^ 2 = a ^ 2 := by simp [sq]
@[simp] lemma neg_one_sq : (-1 : R) ^ 2 = 1 := by rw [neg_sq, one_pow]
alias neg_sq ← neg_pow_two
alias neg_one_sq ← neg_one_pow_two
end has_distrib_neg
section ring
variables [ring R] {a b : R}
protected lemma commute.sq_sub_sq (h : commute a b) : a ^ 2 - b ^ 2 = (a + b) * (a - b) :=
by rw [sq, sq, h.mul_self_sub_mul_self_eq]
@[simp]
lemma neg_one_pow_mul_eq_zero_iff {n : ℕ} {r : R} : (-1)^n * r = 0 ↔ r = 0 :=
by rcases neg_one_pow_eq_or R n; simp [h]
@[simp]
lemma mul_neg_one_pow_eq_zero_iff {n : ℕ} {r : R} : r * (-1)^n = 0 ↔ r = 0 :=
by rcases neg_one_pow_eq_or R n; simp [h]
variables [no_zero_divisors R]
protected lemma commute.sq_eq_sq_iff_eq_or_eq_neg (h : commute a b) :
a ^ 2 = b ^ 2 ↔ a = b ∨ a = -b :=
by rw [←sub_eq_zero, h.sq_sub_sq, mul_eq_zero, add_eq_zero_iff_eq_neg, sub_eq_zero, or_comm]
@[simp] lemma sq_eq_one_iff : a^2 = 1 ↔ a = 1 ∨ a = -1 :=
by rw [←(commute.one_right a).sq_eq_sq_iff_eq_or_eq_neg, one_pow]
lemma sq_ne_one_iff : a^2 ≠ 1 ↔ a ≠ 1 ∧ a ≠ -1 := sq_eq_one_iff.not.trans not_or_distrib
end ring
section comm_ring
variables [comm_ring R]
lemma sq_sub_sq (a b : R) : a ^ 2 - b ^ 2 = (a + b) * (a - b) := (commute.all a b).sq_sub_sq
alias sq_sub_sq ← pow_two_sub_pow_two
lemma sub_sq (a b : R) : (a - b) ^ 2 = a ^ 2 - 2 * a * b + b ^ 2 :=
by rw [sub_eq_add_neg, add_sq, neg_sq, mul_neg, ← sub_eq_add_neg]
alias sub_sq ← sub_pow_two
lemma sub_sq' (a b : R) : (a - b) ^ 2 = a ^ 2 + b ^ 2 - 2 * a * b :=
by rw [sub_eq_add_neg, add_sq', neg_sq, mul_neg, ← sub_eq_add_neg]
variables [no_zero_divisors R] {a b : R}
lemma sq_eq_sq_iff_eq_or_eq_neg : a ^ 2 = b ^ 2 ↔ a = b ∨ a = -b :=
(commute.all a b).sq_eq_sq_iff_eq_or_eq_neg
lemma eq_or_eq_neg_of_sq_eq_sq (a b : R) : a ^ 2 = b ^ 2 → a = b ∨ a = -b :=
sq_eq_sq_iff_eq_or_eq_neg.1
/- Copies of the above comm_ring lemmas for `units R`. -/
namespace units
protected lemma sq_eq_sq_iff_eq_or_eq_neg {a b : Rˣ} : a ^ 2 = b ^ 2 ↔ a = b ∨ a = -b :=
by simp_rw [ext_iff, coe_pow, sq_eq_sq_iff_eq_or_eq_neg, units.coe_neg]
protected lemma eq_or_eq_neg_of_sq_eq_sq (a b : Rˣ) (h : a ^ 2 = b ^ 2) : a = b ∨ a = -b :=
units.sq_eq_sq_iff_eq_or_eq_neg.1 h
end units
end comm_ring
|
dad303298edbf0374917d6d6e17d76a594d7327c | d9d511f37a523cd7659d6f573f990e2a0af93c6f | /src/linear_algebra/bilinear_form.lean | 69113f03fccfb03d28ba0fe844f5ec177b77607d | [
"Apache-2.0"
] | permissive | hikari0108/mathlib | b7ea2b7350497ab1a0b87a09d093ecc025a50dfa | a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901 | refs/heads/master | 1,690,483,608,260 | 1,631,541,580,000 | 1,631,541,580,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 66,599 | lean | /-
Copyright (c) 2018 Andreas Swerdlow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andreas Swerdlow, Kexing Ying
-/
import linear_algebra.dual
import linear_algebra.matrix.basis
import linear_algebra.matrix.nonsingular_inverse
import linear_algebra.tensor_product
/-!
# Bilinear form
This file defines a bilinear form over a module. Basic ideas
such as orthogonality are also introduced, as well as reflexivive,
symmetric, non-degenerate and alternating bilinear forms. Adjoints of
linear maps with respect to a bilinear form are also introduced.
A bilinear form on an R-(semi)module M, is a function from M x M to R,
that is linear in both arguments. Comments will typically abbreviate
"(semi)module" as just "module", but the definitions should be as general as
possible.
The result that there exists an orthogonal basis with respect to a symmetric,
nondegenerate bilinear form can be found in `quadratic_form.lean` with
`exists_orthogonal_basis`.
## Notations
Given any term B of type bilin_form, due to a coercion, can use
the notation B x y to refer to the function field, ie. B x y = B.bilin x y.
In this file we use the following type variables:
- `M`, `M'`, ... are modules over the semiring `R`,
- `M₁`, `M₁'`, ... are modules over the ring `R₁`,
- `M₂`, `M₂'`, ... are modules over the commutative semiring `R₂`,
- `M₃`, `M₃'`, ... are modules over the commutative ring `R₃`,
- `V`, ... is a vector space over the field `K`.
## References
* <https://en.wikipedia.org/wiki/Bilinear_form>
## Tags
Bilinear form,
-/
open_locale big_operators
universes u v w
/-- `bilin_form R M` is the type of `R`-bilinear functions `M → M → R`. -/
structure bilin_form (R : Type*) (M : Type*) [semiring R] [add_comm_monoid M] [module R M] :=
(bilin : M → M → R)
(bilin_add_left : ∀ (x y z : M), bilin (x + y) z = bilin x z + bilin y z)
(bilin_smul_left : ∀ (a : R) (x y : M), bilin (a • x) y = a * (bilin x y))
(bilin_add_right : ∀ (x y z : M), bilin x (y + z) = bilin x y + bilin x z)
(bilin_smul_right : ∀ (a : R) (x y : M), bilin x (a • y) = a * (bilin x y))
variables {R : Type*} {M : Type*} [semiring R] [add_comm_monoid M] [module R M]
variables {R₁ : Type*} {M₁ : Type*} [ring R₁] [add_comm_group M₁] [module R₁ M₁]
variables {R₂ : Type*} {M₂ : Type*} [comm_semiring R₂] [add_comm_monoid M₂] [module R₂ M₂]
variables {R₃ : Type*} {M₃ : Type*} [comm_ring R₃] [add_comm_group M₃] [module R₃ M₃]
variables {V : Type*} {K : Type*} [field K] [add_comm_group V] [module K V]
variables {B : bilin_form R M} {B₁ : bilin_form R₁ M₁} {B₂ : bilin_form R₂ M₂}
namespace bilin_form
instance : has_coe_to_fun (bilin_form R M) :=
⟨_, λ B, B.bilin⟩
initialize_simps_projections bilin_form (bilin -> apply)
@[simp] lemma coe_fn_mk (f : M → M → R) (h₁ h₂ h₃ h₄) :
(bilin_form.mk f h₁ h₂ h₃ h₄ : M → M → R) = f :=
rfl
lemma coe_fn_congr : Π {x x' y y' : M}, x = x' → y = y' → B x y = B x' y'
| _ _ _ _ rfl rfl := rfl
@[simp]
lemma add_left (x y z : M) : B (x + y) z = B x z + B y z := bilin_add_left B x y z
@[simp]
lemma smul_left (a : R) (x y : M) : B (a • x) y = a * (B x y) := bilin_smul_left B a x y
@[simp]
lemma add_right (x y z : M) : B x (y + z) = B x y + B x z := bilin_add_right B x y z
@[simp]
lemma smul_right (a : R) (x y : M) : B x (a • y) = a * (B x y) := bilin_smul_right B a x y
@[simp]
lemma zero_left (x : M) : B 0 x = 0 :=
by { rw [←@zero_smul R _ _ _ _ (0 : M), smul_left, zero_mul] }
@[simp]
lemma zero_right (x : M) : B x 0 = 0 :=
by rw [←@zero_smul _ _ _ _ _ (0 : M), smul_right, zero_mul]
@[simp]
lemma neg_left (x y : M₁) : B₁ (-x) y = -(B₁ x y) :=
by rw [←@neg_one_smul R₁ _ _, smul_left, neg_one_mul]
@[simp]
lemma neg_right (x y : M₁) : B₁ x (-y) = -(B₁ x y) :=
by rw [←@neg_one_smul R₁ _ _, smul_right, neg_one_mul]
@[simp]
lemma sub_left (x y z : M₁) : B₁ (x - y) z = B₁ x z - B₁ y z :=
by rw [sub_eq_add_neg, sub_eq_add_neg, add_left, neg_left]
@[simp]
lemma sub_right (x y z : M₁) : B₁ x (y - z) = B₁ x y - B₁ x z :=
by rw [sub_eq_add_neg, sub_eq_add_neg, add_right, neg_right]
variable {D : bilin_form R M}
@[ext] lemma ext (H : ∀ (x y : M), B x y = D x y) : B = D :=
by { cases B, cases D, congr, funext, exact H _ _ }
instance : add_comm_monoid (bilin_form R M) :=
{ add := λ B D, { bilin := λ x y, B x y + D x y,
bilin_add_left := λ x y z, by { rw add_left, rw add_left, ac_refl },
bilin_smul_left := λ a x y, by { rw [smul_left, smul_left, mul_add] },
bilin_add_right := λ x y z, by { rw add_right, rw add_right, ac_refl },
bilin_smul_right := λ a x y, by { rw [smul_right, smul_right, mul_add] } },
add_assoc := by { intros, ext, unfold bilin coe_fn has_coe_to_fun.coe bilin, rw add_assoc },
zero := { bilin := λ x y, 0,
bilin_add_left := λ x y z, (add_zero 0).symm,
bilin_smul_left := λ a x y, (mul_zero a).symm,
bilin_add_right := λ x y z, (zero_add 0).symm,
bilin_smul_right := λ a x y, (mul_zero a).symm },
zero_add := by { intros, ext, unfold coe_fn has_coe_to_fun.coe bilin, rw zero_add },
add_zero := by { intros, ext, unfold coe_fn has_coe_to_fun.coe bilin, rw add_zero },
add_comm := by { intros, ext, unfold coe_fn has_coe_to_fun.coe bilin, rw add_comm } }
instance : add_comm_group (bilin_form R₁ M₁) :=
{ neg := λ B, { bilin := λ x y, - (B.1 x y),
bilin_add_left := λ x y z, by rw [bilin_add_left, neg_add],
bilin_smul_left := λ a x y, by rw [bilin_smul_left, mul_neg_eq_neg_mul_symm],
bilin_add_right := λ x y z, by rw [bilin_add_right, neg_add],
bilin_smul_right := λ a x y, by rw [bilin_smul_right, mul_neg_eq_neg_mul_symm] },
add_left_neg := by { intros, ext, unfold coe_fn has_coe_to_fun.coe bilin, rw neg_add_self },
.. bilin_form.add_comm_monoid }
@[simp]
lemma add_apply (x y : M) : (B + D) x y = B x y + D x y := rfl
@[simp]
lemma zero_apply (x y : M) : (0 : bilin_form R M) x y = 0 := rfl
@[simp]
lemma neg_apply (x y : M₁) : (-B₁) x y = -(B₁ x y) := rfl
instance : inhabited (bilin_form R M) := ⟨0⟩
section
/-- `bilin_form R M` inherits the scalar action from any commutative subalgebra `R₂` of `R`.
When `R` itself is commutative, this provides an `R`-action via `algebra.id`. -/
instance [algebra R₂ R] : module R₂ (bilin_form R M) :=
{ smul := λ c B,
{ bilin := λ x y, c • B x y,
bilin_add_left := λ x y z,
by { unfold coe_fn has_coe_to_fun.coe bilin, rw [bilin_add_left, smul_add] },
bilin_smul_left := λ a x y, by { unfold coe_fn has_coe_to_fun.coe bilin,
rw [bilin_smul_left, ←algebra.mul_smul_comm] },
bilin_add_right := λ x y z, by { unfold coe_fn has_coe_to_fun.coe bilin,
rw [bilin_add_right, smul_add] },
bilin_smul_right := λ a x y, by { unfold coe_fn has_coe_to_fun.coe bilin,
rw [bilin_smul_right, ←algebra.mul_smul_comm] } },
smul_add := λ c B D, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw smul_add },
add_smul := λ c B D, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw add_smul },
mul_smul := λ a c D, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw ←smul_assoc, refl },
one_smul := λ B, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw one_smul },
zero_smul := λ B, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw zero_smul },
smul_zero := λ B, by { ext, unfold coe_fn has_coe_to_fun.coe bilin, rw smul_zero } }
@[simp] lemma smul_apply [algebra R₂ R] (B : bilin_form R M) (a : R₂) (x y : M) :
(a • B) x y = a • (B x y) :=
rfl
end
section flip
variables (R₂)
/-- Auxiliary construction for the flip of a bilinear form, obtained by exchanging the left and
right arguments. This version is a `linear_map`; it is later upgraded to a `linear_equiv`
in `flip_hom`. -/
def flip_hom_aux [algebra R₂ R] : bilin_form R M →ₗ[R₂] bilin_form R M :=
{ to_fun := λ A,
{ bilin := λ i j, A j i,
bilin_add_left := λ x y z, A.bilin_add_right z x y,
bilin_smul_left := λ a x y, A.bilin_smul_right a y x,
bilin_add_right := λ x y z, A.bilin_add_left y z x,
bilin_smul_right := λ a x y, A.bilin_smul_left a y x },
map_add' := λ A₁ A₂, by { ext, simp } ,
map_smul' := λ c A, by { ext, simp } }
variables {R₂}
lemma flip_flip_aux [algebra R₂ R] (A : bilin_form R M) :
(flip_hom_aux R₂) (flip_hom_aux R₂ A) = A :=
by { ext A x y, simp [flip_hom_aux] }
variables (R₂)
/-- The flip of a bilinear form, obtained by exchanging the left and right arguments. This is a
less structured version of the equiv which applies to general (noncommutative) rings `R` with a
distinguished commutative subring `R₂`; over a commutative ring use `flip`. -/
def flip_hom [algebra R₂ R] : bilin_form R M ≃ₗ[R₂] bilin_form R M :=
{ inv_fun := flip_hom_aux R₂,
left_inv := flip_flip_aux,
right_inv := flip_flip_aux,
.. flip_hom_aux R₂ }
variables {R₂}
@[simp] lemma flip_apply [algebra R₂ R] (A : bilin_form R M) (x y : M) :
flip_hom R₂ A x y = A y x :=
rfl
lemma flip_flip [algebra R₂ R] :
(flip_hom R₂).trans (flip_hom R₂) = linear_equiv.refl R₂ (bilin_form R M) :=
by { ext A x y, simp }
/-- The flip of a bilinear form over a ring, obtained by exchanging the left and right arguments,
here considered as an `ℕ`-linear equivalence, i.e. an additive equivalence. -/
abbreviation flip' : bilin_form R M ≃ₗ[ℕ] bilin_form R M := flip_hom ℕ
/-- The `flip` of a bilinear form over a commutative ring, obtained by exchanging the left and
right arguments. -/
abbreviation flip : bilin_form R₂ M₂ ≃ₗ[R₂] bilin_form R₂ M₂ := flip_hom R₂
end flip
section to_lin'
variables (R₂) [algebra R₂ R] [module R₂ M] [is_scalar_tower R₂ R M]
/-- The linear map obtained from a `bilin_form` by fixing the left co-ordinate and evaluating in
the right.
This is the most general version of the construction; it is `R₂`-linear for some distinguished
commutative subsemiring `R₂` of the scalar ring. Over a semiring with no particular distinguished
such subsemiring, use `to_lin'`, which is `ℕ`-linear. Over a commutative semiring, use `to_lin`,
which is linear. -/
def to_lin_hom : bilin_form R M →ₗ[R₂] M →ₗ[R₂] M →ₗ[R] R :=
{ to_fun := λ A,
{ to_fun := λ x,
{ to_fun := λ y, A x y,
map_add' := A.bilin_add_right x,
map_smul' := λ c, A.bilin_smul_right c x },
map_add' := λ x₁ x₂, by { ext, simp only [linear_map.coe_mk, linear_map.add_apply, add_left] },
map_smul' := λ c x, by { ext, simp only [← algebra_map_smul R c x, algebra.smul_def,
linear_map.coe_mk, linear_map.smul_apply, smul_left] } },
map_add' := λ A₁ A₂, by { ext, simp only [linear_map.coe_mk, linear_map.add_apply, add_apply] },
map_smul' := λ c A, by { ext, simp only [linear_map.coe_mk, linear_map.smul_apply, smul_apply] } }
variables {R₂}
@[simp] lemma to_lin'_apply (A : bilin_form R M) (x : M) :
⇑(to_lin_hom R₂ A x) = A x :=
rfl
/-- The linear map obtained from a `bilin_form` by fixing the left co-ordinate and evaluating in
the right.
Over a commutative semiring, use `to_lin`, which is linear rather than `ℕ`-linear. -/
abbreviation to_lin' : bilin_form R M →ₗ[ℕ] M →ₗ[ℕ] M →ₗ[R] R := to_lin_hom ℕ
@[simp]
lemma sum_left {α} (t : finset α) (g : α → M) (w : M) :
B (∑ i in t, g i) w = ∑ i in t, B (g i) w :=
(bilin_form.to_lin' B).map_sum₂ t g w
@[simp]
lemma sum_right {α} (t : finset α) (w : M) (g : α → M) :
B w (∑ i in t, g i) = ∑ i in t, B w (g i) :=
(bilin_form.to_lin' B w).map_sum
variables (R₂)
/-- The linear map obtained from a `bilin_form` by fixing the right co-ordinate and evaluating in
the left.
This is the most general version of the construction; it is `R₂`-linear for some distinguished
commutative subsemiring `R₂` of the scalar ring. Over semiring with no particular distinguished
such subsemiring, use `to_lin'_flip`, which is `ℕ`-linear. Over a commutative semiring, use
`to_lin_flip`, which is linear. -/
def to_lin_hom_flip : bilin_form R M →ₗ[R₂] M →ₗ[R₂] M →ₗ[R] R :=
(to_lin_hom R₂).comp (flip_hom R₂).to_linear_map
variables {R₂}
@[simp] lemma to_lin'_flip_apply (A : bilin_form R M) (x : M) :
⇑(to_lin_hom_flip R₂ A x) = λ y, A y x :=
rfl
/-- The linear map obtained from a `bilin_form` by fixing the right co-ordinate and evaluating in
the left.
Over a commutative semiring, use `to_lin_flip`, which is linear rather than `ℕ`-linear. -/
abbreviation to_lin'_flip : bilin_form R M →ₗ[ℕ] M →ₗ[ℕ] M →ₗ[R] R := to_lin_hom_flip ℕ
end to_lin'
end bilin_form
section equiv_lin
/-- A map with two arguments that is linear in both is a bilinear form.
This is an auxiliary definition for the full linear equivalence `linear_map.to_bilin`.
-/
def linear_map.to_bilin_aux (f : M₂ →ₗ[R₂] M₂ →ₗ[R₂] R₂) : bilin_form R₂ M₂ :=
{ bilin := λ x y, f x y,
bilin_add_left := λ x y z, (linear_map.map_add f x y).symm ▸ linear_map.add_apply (f x) (f y) z,
bilin_smul_left := λ a x y, by rw [linear_map.map_smul, linear_map.smul_apply, smul_eq_mul],
bilin_add_right := λ x y z, linear_map.map_add (f x) y z,
bilin_smul_right := λ a x y, linear_map.map_smul (f x) a y }
/-- Bilinear forms are linearly equivalent to maps with two arguments that are linear in both. -/
def bilin_form.to_lin : bilin_form R₂ M₂ ≃ₗ[R₂] (M₂ →ₗ[R₂] M₂ →ₗ[R₂] R₂) :=
{ inv_fun := linear_map.to_bilin_aux,
left_inv := λ B, by { ext, simp [linear_map.to_bilin_aux] },
right_inv := λ B, by { ext, simp [linear_map.to_bilin_aux] },
.. bilin_form.to_lin_hom R₂ }
/-- A map with two arguments that is linear in both is linearly equivalent to bilinear form. -/
def linear_map.to_bilin : (M₂ →ₗ[R₂] M₂ →ₗ[R₂] R₂) ≃ₗ[R₂] bilin_form R₂ M₂ :=
bilin_form.to_lin.symm
@[simp] lemma linear_map.to_bilin_aux_eq (f : M₂ →ₗ[R₂] M₂ →ₗ[R₂] R₂) :
linear_map.to_bilin_aux f = linear_map.to_bilin f :=
rfl
@[simp] lemma linear_map.to_bilin_symm :
(linear_map.to_bilin.symm : bilin_form R₂ M₂ ≃ₗ[R₂] _) = bilin_form.to_lin := rfl
@[simp] lemma bilin_form.to_lin_symm :
(bilin_form.to_lin.symm : _ ≃ₗ[R₂] bilin_form R₂ M₂) = linear_map.to_bilin :=
linear_map.to_bilin.symm_symm
@[simp, norm_cast]
lemma bilin_form.to_lin_apply (x : M₂) : ⇑(bilin_form.to_lin B₂ x) = B₂ x := rfl
end equiv_lin
namespace bilin_form
section comp
variables {M' : Type w} [add_comm_monoid M'] [module R M']
/-- Apply a linear map on the left and right argument of a bilinear form. -/
def comp (B : bilin_form R M') (l r : M →ₗ[R] M') : bilin_form R M :=
{ bilin := λ x y, B (l x) (r y),
bilin_add_left := λ x y z, by rw [linear_map.map_add, add_left],
bilin_smul_left := λ x y z, by rw [linear_map.map_smul, smul_left],
bilin_add_right := λ x y z, by rw [linear_map.map_add, add_right],
bilin_smul_right := λ x y z, by rw [linear_map.map_smul, smul_right] }
/-- Apply a linear map to the left argument of a bilinear form. -/
def comp_left (B : bilin_form R M) (f : M →ₗ[R] M) : bilin_form R M :=
B.comp f linear_map.id
/-- Apply a linear map to the right argument of a bilinear form. -/
def comp_right (B : bilin_form R M) (f : M →ₗ[R] M) : bilin_form R M :=
B.comp linear_map.id f
lemma comp_comp {M'' : Type*} [add_comm_monoid M''] [module R M'']
(B : bilin_form R M'') (l r : M →ₗ[R] M') (l' r' : M' →ₗ[R] M'') :
(B.comp l' r').comp l r = B.comp (l'.comp l) (r'.comp r) := rfl
@[simp] lemma comp_left_comp_right (B : bilin_form R M) (l r : M →ₗ[R] M) :
(B.comp_left l).comp_right r = B.comp l r := rfl
@[simp] lemma comp_right_comp_left (B : bilin_form R M) (l r : M →ₗ[R] M) :
(B.comp_right r).comp_left l = B.comp l r := rfl
@[simp] lemma comp_apply (B : bilin_form R M') (l r : M →ₗ[R] M') (v w) :
B.comp l r v w = B (l v) (r w) := rfl
@[simp] lemma comp_left_apply (B : bilin_form R M) (f : M →ₗ[R] M) (v w) :
B.comp_left f v w = B (f v) w := rfl
@[simp] lemma comp_right_apply (B : bilin_form R M) (f : M →ₗ[R] M) (v w) :
B.comp_right f v w = B v (f w) := rfl
@[simp] lemma comp_id_left (B : bilin_form R M) (r : M →ₗ[R] M) :
B.comp linear_map.id r = B.comp_right r :=
by { ext, refl }
@[simp] lemma comp_id_right (B : bilin_form R M) (l : M →ₗ[R] M) :
B.comp l linear_map.id = B.comp_left l :=
by { ext, refl }
@[simp] lemma comp_left_id (B : bilin_form R M) :
B.comp_left linear_map.id = B :=
by { ext, refl }
@[simp] lemma comp_right_id (B : bilin_form R M) :
B.comp_right linear_map.id = B :=
by { ext, refl }
-- Shortcut for `comp_id_{left,right}` followed by `comp_{right,left}_id`,
-- has to be declared after the former two to get the right priority
@[simp] lemma comp_id_id (B : bilin_form R M) :
B.comp linear_map.id linear_map.id = B :=
by { ext, refl }
lemma comp_injective (B₁ B₂ : bilin_form R M') {l r : M →ₗ[R] M'}
(hₗ : function.surjective l) (hᵣ : function.surjective r) :
B₁.comp l r = B₂.comp l r ↔ B₁ = B₂ :=
begin
split; intros h,
{ -- B₁.comp l r = B₂.comp l r → B₁ = B₂
ext,
cases hₗ x with x' hx, subst hx,
cases hᵣ y with y' hy, subst hy,
rw [←comp_apply, ←comp_apply, h], },
{ -- B₁ = B₂ → B₁.comp l r = B₂.comp l r
subst h, },
end
end comp
variables {M₂' : Type*} [add_comm_monoid M₂'] [module R₂ M₂']
section congr
/-- Apply a linear equivalence on the arguments of a bilinear form. -/
def congr (e : M₂ ≃ₗ[R₂] M₂') : bilin_form R₂ M₂ ≃ₗ[R₂] bilin_form R₂ M₂' :=
{ to_fun := λ B, B.comp e.symm e.symm,
inv_fun := λ B, B.comp e e,
left_inv :=
λ B, ext (λ x y, by simp only [comp_apply, linear_equiv.coe_coe, e.symm_apply_apply]),
right_inv :=
λ B, ext (λ x y, by simp only [comp_apply, linear_equiv.coe_coe, e.apply_symm_apply]),
map_add' := λ B B', ext (λ x y, by simp only [comp_apply, add_apply]),
map_smul' := λ B B', ext (λ x y, by simp only [comp_apply, smul_apply]) }
@[simp] lemma congr_apply (e : M₂ ≃ₗ[R₂] M₂') (B : bilin_form R₂ M₂) (x y : M₂') :
congr e B x y = B (e.symm x) (e.symm y) := rfl
@[simp] lemma congr_symm (e : M₂ ≃ₗ[R₂] M₂') :
(congr e).symm = congr e.symm :=
by { ext B x y, simp only [congr_apply, linear_equiv.symm_symm], refl }
lemma congr_comp {M₂'' : Type*} [add_comm_monoid M₂''] [module R₂ M₂'']
(e : M₂ ≃ₗ[R₂] M₂') (B : bilin_form R₂ M₂) (l r : M₂'' →ₗ[R₂] M₂') :
(congr e B).comp l r = B.comp
(linear_map.comp (e.symm : M₂' →ₗ[R₂] M₂) l)
(linear_map.comp (e.symm : M₂' →ₗ[R₂] M₂) r) :=
rfl
lemma comp_congr {M₂'' : Type*} [add_comm_monoid M₂''] [module R₂ M₂'']
(e : M₂' ≃ₗ[R₂] M₂'') (B : bilin_form R₂ M₂) (l r : M₂' →ₗ[R₂] M₂) :
congr e (B.comp l r) = B.comp
(l.comp (e.symm : M₂'' →ₗ[R₂] M₂'))
(r.comp (e.symm : M₂'' →ₗ[R₂] M₂')) :=
rfl
end congr
section lin_mul_lin
/-- `lin_mul_lin f g` is the bilinear form mapping `x` and `y` to `f x * g y` -/
def lin_mul_lin (f g : M₂ →ₗ[R₂] R₂) : bilin_form R₂ M₂ :=
{ bilin := λ x y, f x * g y,
bilin_add_left := λ x y z, by rw [linear_map.map_add, add_mul],
bilin_smul_left := λ x y z, by rw [linear_map.map_smul, smul_eq_mul, mul_assoc],
bilin_add_right := λ x y z, by rw [linear_map.map_add, mul_add],
bilin_smul_right := λ x y z, by rw [linear_map.map_smul, smul_eq_mul, mul_left_comm] }
variables {f g : M₂ →ₗ[R₂] R₂}
@[simp] lemma lin_mul_lin_apply (x y) : lin_mul_lin f g x y = f x * g y := rfl
@[simp] lemma lin_mul_lin_comp (l r : M₂' →ₗ[R₂] M₂) :
(lin_mul_lin f g).comp l r = lin_mul_lin (f.comp l) (g.comp r) :=
rfl
@[simp] lemma lin_mul_lin_comp_left (l : M₂ →ₗ[R₂] M₂) :
(lin_mul_lin f g).comp_left l = lin_mul_lin (f.comp l) g :=
rfl
@[simp] lemma lin_mul_lin_comp_right (r : M₂ →ₗ[R₂] M₂) :
(lin_mul_lin f g).comp_right r = lin_mul_lin f (g.comp r) :=
rfl
end lin_mul_lin
/-- The proposition that two elements of a bilinear form space are orthogonal. For orthogonality
of an indexed set of elements, use `bilin_form.is_Ortho`. -/
def is_ortho (B : bilin_form R M) (x y : M) : Prop :=
B x y = 0
lemma is_ortho_def {B : bilin_form R M} {x y : M} :
B.is_ortho x y ↔ B x y = 0 := iff.rfl
lemma is_ortho_zero_left (x : M) : is_ortho B (0 : M) x :=
zero_left x
lemma is_ortho_zero_right (x : M) : is_ortho B x (0 : M) :=
zero_right x
lemma ne_zero_of_not_is_ortho_self {B : bilin_form K V}
(x : V) (hx₁ : ¬ B.is_ortho x x) : x ≠ 0 :=
λ hx₂, hx₁ (hx₂.symm ▸ is_ortho_zero_left _)
/-- A set of vectors `v` is orthogonal with respect to some bilinear form `B` if and only
if for all `i ≠ j`, `B (v i) (v j) = 0`. For orthogonality between two elements, use
`bilin_form.is_ortho` -/
def is_Ortho {n : Type w} (B : bilin_form R M) (v : n → M) : Prop :=
∀ i j : n, i ≠ j → B.is_ortho (v j) (v i)
lemma is_Ortho_def {n : Type w} {B : bilin_form R M} {v : n → M} :
B.is_Ortho v ↔ ∀ i j : n, i ≠ j → B (v j) (v i) = 0 := iff.rfl
section
variables {R₄ M₄ : Type*} [domain R₄] [add_comm_group M₄] [module R₄ M₄] {G : bilin_form R₄ M₄}
@[simp]
theorem is_ortho_smul_left {x y : M₄} {a : R₄} (ha : a ≠ 0) :
is_ortho G (a • x) y ↔ is_ortho G x y :=
begin
dunfold is_ortho,
split; intro H,
{ rw [smul_left, mul_eq_zero] at H,
cases H,
{ trivial },
{ exact H }},
{ rw [smul_left, H, mul_zero] },
end
@[simp]
theorem is_ortho_smul_right {x y : M₄} {a : R₄} (ha : a ≠ 0) :
is_ortho G x (a • y) ↔ is_ortho G x y :=
begin
dunfold is_ortho,
split; intro H,
{ rw [smul_right, mul_eq_zero] at H,
cases H,
{ trivial },
{ exact H }},
{ rw [smul_right, H, mul_zero] },
end
/-- A set of orthogonal vectors `v` with respect to some bilinear form `B` is linearly independent
if for all `i`, `B (v i) (v i) ≠ 0`. -/
lemma linear_independent_of_is_Ortho
{n : Type w} {B : bilin_form K V} {v : n → V}
(hv₁ : B.is_Ortho v) (hv₂ : ∀ i, ¬ B.is_ortho (v i) (v i)) :
linear_independent K v :=
begin
classical,
rw linear_independent_iff',
intros s w hs i hi,
have : B (s.sum $ λ (i : n), w i • v i) (v i) = 0,
{ rw [hs, zero_left] },
have hsum : s.sum (λ (j : n), w j * B (v j) (v i)) =
s.sum (λ (j : n), if i = j then w j * B (v j) (v i) else 0),
{ refine finset.sum_congr rfl (λ j hj, _),
by_cases (i = j),
{ rw [if_pos h] },
{ rw [if_neg h, is_Ortho_def.1 hv₁ _ _ h, mul_zero] } },
simp_rw [sum_left, smul_left, hsum, finset.sum_ite_eq] at this,
rw [if_pos, mul_eq_zero] at this,
cases this,
{ assumption },
{ exact false.elim (hv₂ i $ this) },
{ assumption }
end
end
section basis
variables {B₃ F₃ : bilin_form R₃ M₃}
variables {ι : Type*} (b : basis ι R₃ M₃)
/-- Two bilinear forms are equal when they are equal on all basis vectors. -/
lemma ext_basis (h : ∀ i j, B₃ (b i) (b j) = F₃ (b i) (b j)) : B₃ = F₃ :=
to_lin.injective $ b.ext $ λ i, b.ext $ λ j, h i j
/-- Write out `B x y` as a sum over `B (b i) (b j)` if `b` is a basis. -/
lemma sum_repr_mul_repr_mul (x y : M₃) :
(b.repr x).sum (λ i xi, (b.repr y).sum (λ j yj, xi • yj • B₃ (b i) (b j))) = B₃ x y :=
begin
conv_rhs { rw [← b.total_repr x, ← b.total_repr y] },
simp_rw [finsupp.total_apply, finsupp.sum, sum_left, sum_right,
smul_left, smul_right, smul_eq_mul]
end
end basis
end bilin_form
section matrix
variables {n o : Type*}
open bilin_form finset linear_map matrix
open_locale matrix
/-- The map from `matrix n n R` to bilinear forms on `n → R`.
This is an auxiliary definition for the equivalence `matrix.to_bilin_form'`. -/
def matrix.to_bilin'_aux [fintype n] (M : matrix n n R₂) : bilin_form R₂ (n → R₂) :=
{ bilin := λ v w, ∑ i j, v i * M i j * w j,
bilin_add_left := λ x y z, by simp only [pi.add_apply, add_mul, sum_add_distrib],
bilin_smul_left := λ a x y, by simp only [pi.smul_apply, smul_eq_mul, mul_assoc, mul_sum],
bilin_add_right := λ x y z, by simp only [pi.add_apply, mul_add, sum_add_distrib],
bilin_smul_right := λ a x y,
by simp only [pi.smul_apply, smul_eq_mul, mul_assoc, mul_left_comm, mul_sum] }
lemma matrix.to_bilin'_aux_std_basis [fintype n] [decidable_eq n] (M : matrix n n R₂)
(i j : n) : M.to_bilin'_aux (std_basis R₂ (λ _, R₂) i 1) (std_basis R₂ (λ _, R₂) j 1) = M i j :=
begin
rw [matrix.to_bilin'_aux, coe_fn_mk, sum_eq_single i, sum_eq_single j],
{ simp only [std_basis_same, std_basis_same, one_mul, mul_one] },
{ rintros j' - hj',
apply mul_eq_zero_of_right,
exact std_basis_ne R₂ (λ _, R₂) _ _ hj' 1 },
{ intros,
have := finset.mem_univ j,
contradiction },
{ rintros i' - hi',
refine finset.sum_eq_zero (λ j _, _),
apply mul_eq_zero_of_left,
apply mul_eq_zero_of_left,
exact std_basis_ne R₂ (λ _, R₂) _ _ hi' 1 },
{ intros,
have := finset.mem_univ i,
contradiction }
end
/-- The linear map from bilinear forms to `matrix n n R` given an `n`-indexed basis.
This is an auxiliary definition for the equivalence `matrix.to_bilin_form'`. -/
def bilin_form.to_matrix_aux (b : n → M₂) : bilin_form R₂ M₂ →ₗ[R₂] matrix n n R₂ :=
{ to_fun := λ B i j, B (b i) (b j),
map_add' := λ f g, rfl,
map_smul' := λ f g, rfl }
variables [fintype n] [fintype o]
lemma to_bilin'_aux_to_matrix_aux [decidable_eq n] (B₃ : bilin_form R₃ (n → R₃)) :
matrix.to_bilin'_aux (bilin_form.to_matrix_aux (λ j, std_basis R₃ (λ _, R₃) j 1) B₃) = B₃ :=
begin
refine ext_basis (pi.basis_fun R₃ n) (λ i j, _),
rw [bilin_form.to_matrix_aux, linear_map.coe_mk, pi.basis_fun_apply, pi.basis_fun_apply,
matrix.to_bilin'_aux_std_basis]
end
section to_matrix'
/-! ### `to_matrix'` section
This section deals with the conversion between matrices and bilinear forms on `n → R₃`.
-/
variables [decidable_eq n] [decidable_eq o]
/-- The linear equivalence between bilinear forms on `n → R` and `n × n` matrices -/
def bilin_form.to_matrix' : bilin_form R₃ (n → R₃) ≃ₗ[R₃] matrix n n R₃ :=
{ inv_fun := matrix.to_bilin'_aux,
left_inv := by convert to_bilin'_aux_to_matrix_aux,
right_inv := λ M,
by { ext i j, simp only [bilin_form.to_matrix_aux, matrix.to_bilin'_aux_std_basis] },
..bilin_form.to_matrix_aux (λ j, std_basis R₃ (λ _, R₃) j 1) }
@[simp] lemma bilin_form.to_matrix_aux_std_basis (B : bilin_form R₃ (n → R₃)) :
bilin_form.to_matrix_aux (λ j, std_basis R₃ (λ _, R₃) j 1) B =
bilin_form.to_matrix' B :=
rfl
/-- The linear equivalence between `n × n` matrices and bilinear forms on `n → R` -/
def matrix.to_bilin' : matrix n n R₃ ≃ₗ[R₃] bilin_form R₃ (n → R₃) :=
bilin_form.to_matrix'.symm
@[simp] lemma matrix.to_bilin'_aux_eq (M : matrix n n R₃) :
matrix.to_bilin'_aux M = matrix.to_bilin' M :=
rfl
lemma matrix.to_bilin'_apply (M : matrix n n R₃) (x y : n → R₃) :
matrix.to_bilin' M x y = ∑ i j, x i * M i j * y j := rfl
lemma matrix.to_bilin'_apply' (M : matrix n n R₃) (v w : n → R₃) :
matrix.to_bilin' M v w = matrix.dot_product v (M.mul_vec w) :=
begin
simp_rw [matrix.to_bilin'_apply, matrix.dot_product,
matrix.mul_vec, matrix.dot_product],
refine finset.sum_congr rfl (λ _ _, _),
rw finset.mul_sum,
refine finset.sum_congr rfl (λ _ _, _),
rw ← mul_assoc,
end
@[simp] lemma matrix.to_bilin'_std_basis (M : matrix n n R₃) (i j : n) :
matrix.to_bilin' M (std_basis R₃ (λ _, R₃) i 1) (std_basis R₃ (λ _, R₃) j 1) =
M i j :=
matrix.to_bilin'_aux_std_basis M i j
@[simp] lemma bilin_form.to_matrix'_symm :
(bilin_form.to_matrix'.symm : matrix n n R₃ ≃ₗ[R₃] _) = matrix.to_bilin' :=
rfl
@[simp] lemma matrix.to_bilin'_symm :
(matrix.to_bilin'.symm : _ ≃ₗ[R₃] matrix n n R₃) = bilin_form.to_matrix' :=
bilin_form.to_matrix'.symm_symm
@[simp] lemma matrix.to_bilin'_to_matrix' (B : bilin_form R₃ (n → R₃)) :
matrix.to_bilin' (bilin_form.to_matrix' B) = B :=
matrix.to_bilin'.apply_symm_apply B
@[simp] lemma bilin_form.to_matrix'_to_bilin' (M : matrix n n R₃) :
bilin_form.to_matrix' (matrix.to_bilin' M) = M :=
bilin_form.to_matrix'.apply_symm_apply M
@[simp] lemma bilin_form.to_matrix'_apply (B : bilin_form R₃ (n → R₃)) (i j : n) :
bilin_form.to_matrix' B i j =
B (std_basis R₃ (λ _, R₃) i 1) (std_basis R₃ (λ _, R₃) j 1) :=
rfl
@[simp] lemma bilin_form.to_matrix'_comp (B : bilin_form R₃ (n → R₃))
(l r : (o → R₃) →ₗ[R₃] (n → R₃)) :
(B.comp l r).to_matrix' = l.to_matrix'ᵀ ⬝ B.to_matrix' ⬝ r.to_matrix' :=
begin
ext i j,
simp only [bilin_form.to_matrix'_apply, bilin_form.comp_apply, transpose_apply, matrix.mul_apply,
linear_map.to_matrix', linear_equiv.coe_mk, sum_mul],
rw sum_comm,
conv_lhs { rw ← sum_repr_mul_repr_mul (pi.basis_fun R₃ n) (l _) (r _) },
rw finsupp.sum_fintype,
{ apply sum_congr rfl,
rintros i' -,
rw finsupp.sum_fintype,
{ apply sum_congr rfl,
rintros j' -,
simp only [smul_eq_mul, pi.basis_fun_repr, mul_assoc, mul_comm, mul_left_comm,
pi.basis_fun_apply] },
{ intros, simp only [zero_smul, smul_zero] } },
{ intros, simp only [zero_smul, finsupp.sum_zero] }
end
lemma bilin_form.to_matrix'_comp_left (B : bilin_form R₃ (n → R₃)) (f : (n → R₃) →ₗ[R₃] (n → R₃)) :
(B.comp_left f).to_matrix' = f.to_matrix'ᵀ ⬝ B.to_matrix' :=
by simp only [bilin_form.comp_left, bilin_form.to_matrix'_comp, to_matrix'_id, matrix.mul_one]
lemma bilin_form.to_matrix'_comp_right (B : bilin_form R₃ (n → R₃)) (f : (n → R₃) →ₗ[R₃] (n → R₃)) :
(B.comp_right f).to_matrix' = B.to_matrix' ⬝ f.to_matrix' :=
by simp only [bilin_form.comp_right, bilin_form.to_matrix'_comp, to_matrix'_id,
transpose_one, matrix.one_mul]
lemma bilin_form.mul_to_matrix'_mul (B : bilin_form R₃ (n → R₃))
(M : matrix o n R₃) (N : matrix n o R₃) :
M ⬝ B.to_matrix' ⬝ N = (B.comp Mᵀ.to_lin' N.to_lin').to_matrix' :=
by simp only [B.to_matrix'_comp, transpose_transpose, to_matrix'_to_lin']
lemma bilin_form.mul_to_matrix' (B : bilin_form R₃ (n → R₃)) (M : matrix n n R₃) :
M ⬝ B.to_matrix' = (B.comp_left Mᵀ.to_lin').to_matrix' :=
by simp only [B.to_matrix'_comp_left, transpose_transpose, to_matrix'_to_lin']
lemma bilin_form.to_matrix'_mul (B : bilin_form R₃ (n → R₃)) (M : matrix n n R₃) :
B.to_matrix' ⬝ M = (B.comp_right M.to_lin').to_matrix' :=
by simp only [B.to_matrix'_comp_right, to_matrix'_to_lin']
lemma matrix.to_bilin'_comp (M : matrix n n R₃) (P Q : matrix n o R₃) :
M.to_bilin'.comp P.to_lin' Q.to_lin' = (Pᵀ ⬝ M ⬝ Q).to_bilin' :=
bilin_form.to_matrix'.injective
(by simp only [bilin_form.to_matrix'_comp, bilin_form.to_matrix'_to_bilin', to_matrix'_to_lin'])
end to_matrix'
section to_matrix
/-! ### `to_matrix` section
This section deals with the conversion between matrices and bilinear forms on
a module with a fixed basis.
-/
variables [decidable_eq n] (b : basis n R₃ M₃)
/-- `bilin_form.to_matrix b` is the equivalence between `R`-bilinear forms on `M` and
`n`-by-`n` matrices with entries in `R`, if `b` is an `R`-basis for `M`. -/
noncomputable def bilin_form.to_matrix : bilin_form R₃ M₃ ≃ₗ[R₃] matrix n n R₃ :=
(bilin_form.congr b.equiv_fun).trans bilin_form.to_matrix'
/-- `bilin_form.to_matrix b` is the equivalence between `R`-bilinear forms on `M` and
`n`-by-`n` matrices with entries in `R`, if `b` is an `R`-basis for `M`. -/
noncomputable def matrix.to_bilin : matrix n n R₃ ≃ₗ[R₃] bilin_form R₃ M₃ :=
(bilin_form.to_matrix b).symm
@[simp] lemma basis.equiv_fun_symm_std_basis (i : n) :
b.equiv_fun.symm (std_basis R₃ (λ _, R₃) i 1) = b i :=
begin
rw [b.equiv_fun_symm_apply, finset.sum_eq_single i],
{ rw [std_basis_same, one_smul] },
{ rintros j - hj,
rw [std_basis_ne _ _ _ _ hj, zero_smul] },
{ intro,
have := mem_univ i,
contradiction }
end
@[simp] lemma bilin_form.to_matrix_apply (B : bilin_form R₃ M₃) (i j : n) :
bilin_form.to_matrix b B i j = B (b i) (b j) :=
by rw [bilin_form.to_matrix, linear_equiv.trans_apply, bilin_form.to_matrix'_apply, congr_apply,
b.equiv_fun_symm_std_basis, b.equiv_fun_symm_std_basis]
@[simp] lemma matrix.to_bilin_apply (M : matrix n n R₃) (x y : M₃) :
matrix.to_bilin b M x y = ∑ i j, b.repr x i * M i j * b.repr y j :=
begin
rw [matrix.to_bilin, bilin_form.to_matrix, linear_equiv.symm_trans_apply, ← matrix.to_bilin'],
simp only [congr_symm, congr_apply, linear_equiv.symm_symm, matrix.to_bilin'_apply,
basis.equiv_fun_apply]
end
-- Not a `simp` lemma since `bilin_form.to_matrix` needs an extra argument
lemma bilinear_form.to_matrix_aux_eq (B : bilin_form R₃ M₃) :
bilin_form.to_matrix_aux b B = bilin_form.to_matrix b B :=
ext (λ i j, by rw [bilin_form.to_matrix_apply, bilin_form.to_matrix_aux, linear_map.coe_mk])
@[simp] lemma bilin_form.to_matrix_symm :
(bilin_form.to_matrix b).symm = matrix.to_bilin b :=
rfl
@[simp] lemma matrix.to_bilin_symm :
(matrix.to_bilin b).symm = bilin_form.to_matrix b :=
(bilin_form.to_matrix b).symm_symm
lemma matrix.to_bilin_basis_fun :
matrix.to_bilin (pi.basis_fun R₃ n) = matrix.to_bilin' :=
by { ext M, simp only [matrix.to_bilin_apply, matrix.to_bilin'_apply, pi.basis_fun_repr] }
lemma bilin_form.to_matrix_basis_fun :
bilin_form.to_matrix (pi.basis_fun R₃ n) = bilin_form.to_matrix' :=
by { ext B, rw [bilin_form.to_matrix_apply, bilin_form.to_matrix'_apply,
pi.basis_fun_apply, pi.basis_fun_apply] }
@[simp] lemma matrix.to_bilin_to_matrix (B : bilin_form R₃ M₃) :
matrix.to_bilin b (bilin_form.to_matrix b B) = B :=
(matrix.to_bilin b).apply_symm_apply B
@[simp] lemma bilin_form.to_matrix_to_bilin (M : matrix n n R₃) :
bilin_form.to_matrix b (matrix.to_bilin b M) = M :=
(bilin_form.to_matrix b).apply_symm_apply M
variables {M₃' : Type*} [add_comm_group M₃'] [module R₃ M₃']
variables (c : basis o R₃ M₃')
variables [decidable_eq o]
-- Cannot be a `simp` lemma because `b` must be inferred.
lemma bilin_form.to_matrix_comp
(B : bilin_form R₃ M₃) (l r : M₃' →ₗ[R₃] M₃) :
bilin_form.to_matrix c (B.comp l r) =
(to_matrix c b l)ᵀ ⬝ bilin_form.to_matrix b B ⬝ to_matrix c b r :=
begin
ext i j,
simp only [bilin_form.to_matrix_apply, bilin_form.comp_apply, transpose_apply, matrix.mul_apply,
linear_map.to_matrix', linear_equiv.coe_mk, sum_mul],
rw sum_comm,
conv_lhs { rw ← sum_repr_mul_repr_mul b },
rw finsupp.sum_fintype,
{ apply sum_congr rfl,
rintros i' -,
rw finsupp.sum_fintype,
{ apply sum_congr rfl,
rintros j' -,
simp only [smul_eq_mul, linear_map.to_matrix_apply,
basis.equiv_fun_apply, mul_assoc, mul_comm, mul_left_comm] },
{ intros, simp only [zero_smul, smul_zero] } },
{ intros, simp only [zero_smul, finsupp.sum_zero] }
end
lemma bilin_form.to_matrix_comp_left (B : bilin_form R₃ M₃) (f : M₃ →ₗ[R₃] M₃) :
bilin_form.to_matrix b (B.comp_left f) = (to_matrix b b f)ᵀ ⬝ bilin_form.to_matrix b B :=
by simp only [comp_left, bilin_form.to_matrix_comp b b, to_matrix_id, matrix.mul_one]
lemma bilin_form.to_matrix_comp_right (B : bilin_form R₃ M₃) (f : M₃ →ₗ[R₃] M₃) :
bilin_form.to_matrix b (B.comp_right f) = bilin_form.to_matrix b B ⬝ (to_matrix b b f) :=
by simp only [bilin_form.comp_right, bilin_form.to_matrix_comp b b, to_matrix_id,
transpose_one, matrix.one_mul]
@[simp]
lemma bilin_form.to_matrix_mul_basis_to_matrix (c : basis o R₃ M₃) (B : bilin_form R₃ M₃) :
(b.to_matrix c)ᵀ ⬝ bilin_form.to_matrix b B ⬝ b.to_matrix c = bilin_form.to_matrix c B :=
by rw [← linear_map.to_matrix_id_eq_basis_to_matrix, ← bilin_form.to_matrix_comp,
bilin_form.comp_id_id]
lemma bilin_form.mul_to_matrix_mul (B : bilin_form R₃ M₃)
(M : matrix o n R₃) (N : matrix n o R₃) :
M ⬝ bilin_form.to_matrix b B ⬝ N =
bilin_form.to_matrix c (B.comp (to_lin c b Mᵀ) (to_lin c b N)) :=
by simp only [B.to_matrix_comp b c, to_matrix_to_lin, transpose_transpose]
lemma bilin_form.mul_to_matrix (B : bilin_form R₃ M₃) (M : matrix n n R₃) :
M ⬝ bilin_form.to_matrix b B =
bilin_form.to_matrix b (B.comp_left (to_lin b b Mᵀ)) :=
by rw [B.to_matrix_comp_left b, to_matrix_to_lin, transpose_transpose]
lemma bilin_form.to_matrix_mul (B : bilin_form R₃ M₃) (M : matrix n n R₃) :
bilin_form.to_matrix b B ⬝ M =
bilin_form.to_matrix b (B.comp_right (to_lin b b M)) :=
by rw [B.to_matrix_comp_right b, to_matrix_to_lin]
lemma matrix.to_bilin_comp (M : matrix n n R₃) (P Q : matrix n o R₃) :
(matrix.to_bilin b M).comp (to_lin c b P) (to_lin c b Q) = matrix.to_bilin c (Pᵀ ⬝ M ⬝ Q) :=
(bilin_form.to_matrix c).injective
(by simp only [bilin_form.to_matrix_comp b c, bilin_form.to_matrix_to_bilin, to_matrix_to_lin])
end to_matrix
end matrix
namespace refl_bilin_form
open refl_bilin_form bilin_form
/-- The proposition that a bilinear form is reflexive -/
def is_refl (B : bilin_form R M) : Prop := ∀ (x y : M), B x y = 0 → B y x = 0
variable (H : is_refl B)
lemma eq_zero : ∀ {x y : M}, B x y = 0 → B y x = 0 := λ x y, H x y
lemma ortho_sym {x y : M} :
is_ortho B x y ↔ is_ortho B y x := ⟨eq_zero H, eq_zero H⟩
end refl_bilin_form
namespace sym_bilin_form
open sym_bilin_form bilin_form
/-- The proposition that a bilinear form is symmetric -/
def is_sym (B : bilin_form R M) : Prop := ∀ (x y : M), B x y = B y x
variable (H : is_sym B)
lemma sym (x y : M) : B x y = B y x := H x y
lemma is_refl : refl_bilin_form.is_refl B := λ x y H1, H x y ▸ H1
lemma ortho_sym {x y : M} :
is_ortho B x y ↔ is_ortho B y x := refl_bilin_form.ortho_sym (is_refl H)
lemma is_sym_iff_flip' [algebra R₂ R] : is_sym B ↔ flip_hom R₂ B = B :=
begin
split,
{ intros h,
ext x y,
exact h y x },
{ intros h x y,
conv_lhs { rw ← h },
simp }
end
end sym_bilin_form
namespace alt_bilin_form
open alt_bilin_form bilin_form
/-- The proposition that a bilinear form is alternating -/
def is_alt (B : bilin_form R M) : Prop := ∀ (x : M), B x x = 0
variable (H : is_alt B)
include H
lemma self_eq_zero (x : M) : B x x = 0 := H x
lemma neg (H : is_alt B₁) (x y : M₁) :
- B₁ x y = B₁ y x :=
begin
have H1 : B₁ (x + y) (x + y) = 0,
{ exact self_eq_zero H (x + y) },
rw [add_left, add_right, add_right,
self_eq_zero H, self_eq_zero H, ring.zero_add,
ring.add_zero, add_eq_zero_iff_neg_eq] at H1,
exact H1,
end
end alt_bilin_form
namespace bilin_form
section linear_adjoints
variables (B) (F : bilin_form R M)
variables {M' : Type*} [add_comm_monoid M'] [module R M']
variables (B' : bilin_form R M') (f f' : M →ₗ[R] M') (g g' : M' →ₗ[R] M)
/-- Given a pair of modules equipped with bilinear forms, this is the condition for a pair of
maps between them to be mutually adjoint. -/
def is_adjoint_pair := ∀ ⦃x y⦄, B' (f x) y = B x (g y)
variables {B B' B₂ f f' g g'}
lemma is_adjoint_pair.eq (h : is_adjoint_pair B B' f g) :
∀ {x y}, B' (f x) y = B x (g y) := h
lemma is_adjoint_pair_iff_comp_left_eq_comp_right (f g : module.End R M) :
is_adjoint_pair B F f g ↔ F.comp_left f = B.comp_right g :=
begin
split; intros h,
{ ext x y, rw [comp_left_apply, comp_right_apply], apply h, },
{ intros x y, rw [←comp_left_apply, ←comp_right_apply], rw h, },
end
lemma is_adjoint_pair_zero : is_adjoint_pair B B' 0 0 :=
λ x y, by simp only [bilin_form.zero_left, bilin_form.zero_right, linear_map.zero_apply]
lemma is_adjoint_pair_id : is_adjoint_pair B B 1 1 := λ x y, rfl
lemma is_adjoint_pair.add (h : is_adjoint_pair B B' f g) (h' : is_adjoint_pair B B' f' g') :
is_adjoint_pair B B' (f + f') (g + g') :=
λ x y, by rw [linear_map.add_apply, linear_map.add_apply, add_left, add_right, h, h']
variables {M₁' : Type*} [add_comm_group M₁'] [module R₁ M₁']
variables {B₁' : bilin_form R₁ M₁'} {f₁ f₁' : M₁ →ₗ[R₁] M₁'} {g₁ g₁' : M₁' →ₗ[R₁] M₁}
lemma is_adjoint_pair.sub (h : is_adjoint_pair B₁ B₁' f₁ g₁) (h' : is_adjoint_pair B₁ B₁' f₁' g₁') :
is_adjoint_pair B₁ B₁' (f₁ - f₁') (g₁ - g₁') :=
λ x y, by rw [linear_map.sub_apply, linear_map.sub_apply, sub_left, sub_right, h, h']
variables {M₂' : Type*} [add_comm_monoid M₂'] [module R₂ M₂']
variables {B₂' : bilin_form R₂ M₂'} {f₂ f₂' : M₂ →ₗ[R₂] M₂'} {g₂ g₂' : M₂' →ₗ[R₂] M₂}
lemma is_adjoint_pair.smul (c : R₂) (h : is_adjoint_pair B₂ B₂' f₂ g₂) :
is_adjoint_pair B₂ B₂' (c • f₂) (c • g₂) :=
λ x y, by rw [linear_map.smul_apply, linear_map.smul_apply, smul_left, smul_right, h]
variables {M'' : Type*} [add_comm_monoid M''] [module R M'']
variables (B'' : bilin_form R M'')
lemma is_adjoint_pair.comp {f' : M' →ₗ[R] M''} {g' : M'' →ₗ[R] M'}
(h : is_adjoint_pair B B' f g) (h' : is_adjoint_pair B' B'' f' g') :
is_adjoint_pair B B'' (f'.comp f) (g.comp g') :=
λ x y, by rw [linear_map.comp_apply, linear_map.comp_apply, h', h]
lemma is_adjoint_pair.mul
{f g f' g' : module.End R M} (h : is_adjoint_pair B B f g) (h' : is_adjoint_pair B B f' g') :
is_adjoint_pair B B (f * f') (g' * g) :=
λ x y, by rw [linear_map.mul_apply, linear_map.mul_apply, h, h']
variables (B B' B₁ B₂) (F₂ : bilin_form R₂ M₂)
/-- The condition for an endomorphism to be "self-adjoint" with respect to a pair of bilinear forms
on the underlying module. In the case that these two forms are identical, this is the usual concept
of self adjointness. In the case that one of the forms is the negation of the other, this is the
usual concept of skew adjointness. -/
def is_pair_self_adjoint (f : module.End R M) := is_adjoint_pair B F f f
/-- The set of pair-self-adjoint endomorphisms are a submodule of the type of all endomorphisms. -/
def is_pair_self_adjoint_submodule : submodule R₂ (module.End R₂ M₂) :=
{ carrier := { f | is_pair_self_adjoint B₂ F₂ f },
zero_mem' := is_adjoint_pair_zero,
add_mem' := λ f g hf hg, hf.add hg,
smul_mem' := λ c f h, h.smul c, }
@[simp] lemma mem_is_pair_self_adjoint_submodule (f : module.End R₂ M₂) :
f ∈ is_pair_self_adjoint_submodule B₂ F₂ ↔ is_pair_self_adjoint B₂ F₂ f :=
by refl
variables {M₃' : Type*} [add_comm_group M₃'] [module R₃ M₃']
variables (B₃ F₃ : bilin_form R₃ M₃)
lemma is_pair_self_adjoint_equiv (e : M₃' ≃ₗ[R₃] M₃) (f : module.End R₃ M₃) :
is_pair_self_adjoint B₃ F₃ f ↔
is_pair_self_adjoint (B₃.comp ↑e ↑e) (F₃.comp ↑e ↑e) (e.symm.conj f) :=
begin
have hₗ : (F₃.comp ↑e ↑e).comp_left (e.symm.conj f) = (F₃.comp_left f).comp ↑e ↑e :=
by { ext, simp [linear_equiv.symm_conj_apply], },
have hᵣ : (B₃.comp ↑e ↑e).comp_right (e.symm.conj f) = (B₃.comp_right f).comp ↑e ↑e :=
by { ext, simp [linear_equiv.conj_apply], },
have he : function.surjective (⇑(↑e : M₃' →ₗ[R₃] M₃) : M₃' → M₃) := e.surjective,
show bilin_form.is_adjoint_pair _ _ _ _ ↔ bilin_form.is_adjoint_pair _ _ _ _,
rw [is_adjoint_pair_iff_comp_left_eq_comp_right, is_adjoint_pair_iff_comp_left_eq_comp_right,
hᵣ, hₗ, comp_injective _ _ he he],
end
/-- An endomorphism of a module is self-adjoint with respect to a bilinear form if it serves as an
adjoint for itself. -/
def is_self_adjoint (f : module.End R M) := is_adjoint_pair B B f f
/-- An endomorphism of a module is skew-adjoint with respect to a bilinear form if its negation
serves as an adjoint. -/
def is_skew_adjoint (f : module.End R₁ M₁) := is_adjoint_pair B₁ B₁ f (-f)
lemma is_skew_adjoint_iff_neg_self_adjoint (f : module.End R₁ M₁) :
B₁.is_skew_adjoint f ↔ is_adjoint_pair (-B₁) B₁ f f :=
show (∀ x y, B₁ (f x) y = B₁ x ((-f) y)) ↔ ∀ x y, B₁ (f x) y = (-B₁) x (f y),
by simp only [linear_map.neg_apply, bilin_form.neg_apply, bilin_form.neg_right]
/-- The set of self-adjoint endomorphisms of a module with bilinear form is a submodule. (In fact
it is a Jordan subalgebra.) -/
def self_adjoint_submodule := is_pair_self_adjoint_submodule B₂ B₂
@[simp] lemma mem_self_adjoint_submodule (f : module.End R₂ M₂) :
f ∈ B₂.self_adjoint_submodule ↔ B₂.is_self_adjoint f := iff.rfl
/-- The set of skew-adjoint endomorphisms of a module with bilinear form is a submodule. (In fact
it is a Lie subalgebra.) -/
def skew_adjoint_submodule := is_pair_self_adjoint_submodule (-B₃) B₃
@[simp] lemma mem_skew_adjoint_submodule (f : module.End R₃ M₃) :
f ∈ B₃.skew_adjoint_submodule ↔ B₃.is_skew_adjoint f :=
by { rw is_skew_adjoint_iff_neg_self_adjoint, exact iff.rfl, }
end linear_adjoints
end bilin_form
section matrix_adjoints
open_locale matrix
variables {n : Type w} [fintype n]
variables (b : basis n R₃ M₃)
variables (J J₃ A A' : matrix n n R₃)
/-- The condition for the square matrices `A`, `A'` to be an adjoint pair with respect to the square
matrices `J`, `J₃`. -/
def matrix.is_adjoint_pair := Aᵀ ⬝ J₃ = J ⬝ A'
/-- The condition for a square matrix `A` to be self-adjoint with respect to the square matrix
`J`. -/
def matrix.is_self_adjoint := matrix.is_adjoint_pair J J A A
/-- The condition for a square matrix `A` to be skew-adjoint with respect to the square matrix
`J`. -/
def matrix.is_skew_adjoint := matrix.is_adjoint_pair J J A (-A)
@[simp] lemma is_adjoint_pair_to_bilin' [decidable_eq n] :
bilin_form.is_adjoint_pair (matrix.to_bilin' J) (matrix.to_bilin' J₃)
(matrix.to_lin' A) (matrix.to_lin' A') ↔
matrix.is_adjoint_pair J J₃ A A' :=
begin
rw bilin_form.is_adjoint_pair_iff_comp_left_eq_comp_right,
have h : ∀ (B B' : bilin_form R₃ (n → R₃)), B = B' ↔
(bilin_form.to_matrix' B) = (bilin_form.to_matrix' B'),
{ intros B B',
split; intros h,
{ rw h },
{ exact bilin_form.to_matrix'.injective h } },
rw [h, bilin_form.to_matrix'_comp_left, bilin_form.to_matrix'_comp_right,
linear_map.to_matrix'_to_lin', linear_map.to_matrix'_to_lin',
bilin_form.to_matrix'_to_bilin', bilin_form.to_matrix'_to_bilin'],
refl,
end
@[simp] lemma is_adjoint_pair_to_bilin [decidable_eq n] :
bilin_form.is_adjoint_pair (matrix.to_bilin b J) (matrix.to_bilin b J₃)
(matrix.to_lin b b A) (matrix.to_lin b b A') ↔
matrix.is_adjoint_pair J J₃ A A' :=
begin
rw bilin_form.is_adjoint_pair_iff_comp_left_eq_comp_right,
have h : ∀ (B B' : bilin_form R₃ M₃), B = B' ↔
(bilin_form.to_matrix b B) = (bilin_form.to_matrix b B'),
{ intros B B',
split; intros h,
{ rw h },
{ exact (bilin_form.to_matrix b).injective h } },
rw [h, bilin_form.to_matrix_comp_left, bilin_form.to_matrix_comp_right,
linear_map.to_matrix_to_lin, linear_map.to_matrix_to_lin,
bilin_form.to_matrix_to_bilin, bilin_form.to_matrix_to_bilin],
refl,
end
lemma matrix.is_adjoint_pair_equiv [decidable_eq n] (P : matrix n n R₃) (h : is_unit P) :
(Pᵀ ⬝ J ⬝ P).is_adjoint_pair (Pᵀ ⬝ J ⬝ P) A A' ↔
J.is_adjoint_pair J (P ⬝ A ⬝ P⁻¹) (P ⬝ A' ⬝ P⁻¹) :=
have h' : is_unit P.det := P.is_unit_iff_is_unit_det.mp h,
begin
let u := P.nonsing_inv_unit h',
let v := Pᵀ.nonsing_inv_unit (P.is_unit_det_transpose h'),
let x := Aᵀ * Pᵀ * J,
let y := J * P * A',
suffices : x * ↑u = ↑v * y ↔ ↑v⁻¹ * x = y * ↑u⁻¹,
{ dunfold matrix.is_adjoint_pair,
repeat { rw matrix.transpose_mul, },
simp only [←matrix.mul_eq_mul, ←mul_assoc, P.transpose_nonsing_inv h'],
conv_lhs { to_rhs, rw [mul_assoc, mul_assoc], congr, skip, rw ←mul_assoc, },
conv_rhs { rw [mul_assoc, mul_assoc], conv { to_lhs, congr, skip, rw ←mul_assoc }, },
exact this, },
rw units.eq_mul_inv_iff_mul_eq, conv_rhs { rw mul_assoc, }, rw v.inv_mul_eq_iff_eq_mul,
end
variables [decidable_eq n]
/-- The submodule of pair-self-adjoint matrices with respect to bilinear forms corresponding to
given matrices `J`, `J₂`. -/
def pair_self_adjoint_matrices_submodule : submodule R₃ (matrix n n R₃) :=
(bilin_form.is_pair_self_adjoint_submodule (matrix.to_bilin' J) (matrix.to_bilin' J₃)).map
(linear_map.to_matrix' : ((n → R₃) →ₗ[R₃] (n → R₃)) ≃ₗ[R₃] matrix n n R₃)
@[simp] lemma mem_pair_self_adjoint_matrices_submodule :
A ∈ (pair_self_adjoint_matrices_submodule J J₃) ↔ matrix.is_adjoint_pair J J₃ A A :=
begin
simp only [pair_self_adjoint_matrices_submodule, linear_equiv.coe_coe,
linear_map.to_matrix'_apply, submodule.mem_map, bilin_form.mem_is_pair_self_adjoint_submodule],
split,
{ rintros ⟨f, hf, hA⟩,
have hf' : f = A.to_lin' := by rw [←hA, matrix.to_lin'_to_matrix'], rw hf' at hf,
rw ← is_adjoint_pair_to_bilin',
exact hf, },
{ intros h, refine ⟨A.to_lin', _, linear_map.to_matrix'_to_lin' _⟩,
exact (is_adjoint_pair_to_bilin' _ _ _ _).mpr h, },
end
/-- The submodule of self-adjoint matrices with respect to the bilinear form corresponding to
the matrix `J`. -/
def self_adjoint_matrices_submodule : submodule R₃ (matrix n n R₃) :=
pair_self_adjoint_matrices_submodule J J
@[simp] lemma mem_self_adjoint_matrices_submodule :
A ∈ self_adjoint_matrices_submodule J ↔ J.is_self_adjoint A :=
by { erw mem_pair_self_adjoint_matrices_submodule, refl, }
/-- The submodule of skew-adjoint matrices with respect to the bilinear form corresponding to
the matrix `J`. -/
def skew_adjoint_matrices_submodule : submodule R₃ (matrix n n R₃) :=
pair_self_adjoint_matrices_submodule (-J) J
@[simp] lemma mem_skew_adjoint_matrices_submodule :
A ∈ skew_adjoint_matrices_submodule J ↔ J.is_skew_adjoint A :=
begin
erw mem_pair_self_adjoint_matrices_submodule,
simp [matrix.is_skew_adjoint, matrix.is_adjoint_pair],
end
end matrix_adjoints
namespace bilin_form
section orthogonal
/-- The orthogonal complement of a submodule `N` with respect to some bilinear form is the set of
elements `x` which are orthogonal to all elements of `N`; i.e., for all `y` in `N`, `B x y = 0`.
Note that for general (neither symmetric nor antisymmetric) bilinear forms this definition has a
chirality; in addition to this "left" orthogonal complement one could define a "right" orthogonal
complement for which, for all `y` in `N`, `B y x = 0`. This variant definition is not currently
provided in mathlib. -/
def orthogonal (B : bilin_form R M) (N : submodule R M) : submodule R M :=
{ carrier := { m | ∀ n ∈ N, is_ortho B n m },
zero_mem' := λ x _, is_ortho_zero_right x,
add_mem' := λ x y hx hy n hn,
by rw [is_ortho, add_right, show B n x = 0, by exact hx n hn,
show B n y = 0, by exact hy n hn, zero_add],
smul_mem' := λ c x hx n hn,
by rw [is_ortho, smul_right, show B n x = 0, by exact hx n hn, mul_zero] }
variables {N L : submodule R M}
@[simp] lemma mem_orthogonal_iff {N : submodule R M} {m : M} :
m ∈ B.orthogonal N ↔ ∀ n ∈ N, is_ortho B n m := iff.rfl
lemma orthogonal_le (h : N ≤ L) : B.orthogonal L ≤ B.orthogonal N :=
λ _ hn l hl, hn l (h hl)
lemma le_orthogonal_orthogonal (b : refl_bilin_form.is_refl B) :
N ≤ B.orthogonal (B.orthogonal N) :=
λ n hn m hm, b _ _ (hm n hn)
-- ↓ This lemma only applies in fields as we require `a * b = 0 → a = 0 ∨ b = 0`
lemma span_singleton_inf_orthogonal_eq_bot
{B : bilin_form K V} {x : V} (hx : ¬ B.is_ortho x x) :
(K ∙ x) ⊓ B.orthogonal (K ∙ x) = ⊥ :=
begin
rw ← finset.coe_singleton,
refine eq_bot_iff.2 (λ y h, _),
rcases mem_span_finset.1 h.1 with ⟨μ, rfl⟩,
have := h.2 x _,
{ rw finset.sum_singleton at this ⊢,
suffices hμzero : μ x = 0,
{ rw [hμzero, zero_smul, submodule.mem_bot] },
change B x (μ x • x) = 0 at this, rw [smul_right] at this,
exact or.elim (zero_eq_mul.mp this.symm) id (λ hfalse, false.elim $ hx hfalse) },
{ rw submodule.mem_span; exact λ _ hp, hp $ finset.mem_singleton_self _ }
end
-- ↓ This lemma only applies in fields since we use the `mul_eq_zero`
lemma orthogonal_span_singleton_eq_to_lin_ker {B : bilin_form K V} (x : V) :
B.orthogonal (K ∙ x) = (bilin_form.to_lin B x).ker :=
begin
ext y,
simp_rw [mem_orthogonal_iff, linear_map.mem_ker,
submodule.mem_span_singleton ],
split,
{ exact λ h, h x ⟨1, one_smul _ _⟩ },
{ rintro h _ ⟨z, rfl⟩,
rw [is_ortho, smul_left, mul_eq_zero],
exact or.intro_right _ h }
end
lemma span_singleton_sup_orthogonal_eq_top {B : bilin_form K V}
{x : V} (hx : ¬ B.is_ortho x x) :
(K ∙ x) ⊔ B.orthogonal (K ∙ x) = ⊤ :=
begin
rw orthogonal_span_singleton_eq_to_lin_ker,
exact linear_map.span_singleton_sup_ker_eq_top _ hx,
end
/-- Given a bilinear form `B` and some `x` such that `B x x ≠ 0`, the span of the singleton of `x`
is complement to its orthogonal complement. -/
lemma is_compl_span_singleton_orthogonal {B : bilin_form K V}
{x : V} (hx : ¬ B.is_ortho x x) : is_compl (K ∙ x) (B.orthogonal $ K ∙ x) :=
{ inf_le_bot := eq_bot_iff.1 $ span_singleton_inf_orthogonal_eq_bot hx,
top_le_sup := eq_top_iff.1 $ span_singleton_sup_orthogonal_eq_top hx }
end orthogonal
/-- The restriction of a bilinear form on a submodule. -/
@[simps apply]
def restrict (B : bilin_form R M) (W : submodule R M) : bilin_form R W :=
{ bilin := λ a b, B a b,
bilin_add_left := λ _ _ _, add_left _ _ _,
bilin_smul_left := λ _ _ _, smul_left _ _ _,
bilin_add_right := λ _ _ _, add_right _ _ _,
bilin_smul_right := λ _ _ _, smul_right _ _ _}
/-- The restriction of a symmetric bilinear form on a submodule is also symmetric. -/
lemma restrict_sym (B : bilin_form R M) (b : sym_bilin_form.is_sym B)
(W : submodule R M) : sym_bilin_form.is_sym $ B.restrict W :=
λ x y, b x y
/-- A nondegenerate bilinear form is a bilinear form such that the only element that is orthogonal
to every other element is `0`; i.e., for all nonzero `m` in `M`, there exists `n` in `M` with
`B m n ≠ 0`.
Note that for general (neither symmetric nor antisymmetric) bilinear forms this definition has a
chirality; in addition to this "left" nondegeneracy condition one could define a "right"
nondegeneracy condition that in the situation described, `B n m ≠ 0`. This variant definition is
not currently provided in mathlib. In finite dimension either definition implies the other. -/
def nondegenerate (B : bilin_form R M) : Prop :=
∀ m : M, (∀ n : M, B m n = 0) → m = 0
/-- A bilinear form is nondegenerate if and only if it has a trivial kernel. -/
theorem nondegenerate_iff_ker_eq_bot {B : bilin_form R₂ M₂} :
B.nondegenerate ↔ B.to_lin.ker = ⊥ :=
begin
rw linear_map.ker_eq_bot',
split; intro h,
{ refine λ m hm, h _ (λ x, _),
rw [← to_lin_apply, hm], refl },
{ intros m hm, apply h,
ext x, exact hm x }
end
lemma nondegenerate.ker_eq_bot {B : bilin_form R₂ M₂} (h : B.nondegenerate) :
B.to_lin.ker = ⊥ := nondegenerate_iff_ker_eq_bot.mp h
/-- The restriction of a nondegenerate bilinear form `B` onto a submodule `W` is
nondegenerate if `disjoint W (B.orthogonal W)`. -/
lemma nondegenerate_restrict_of_disjoint_orthogonal
(B : bilin_form R₁ M₁) (b : sym_bilin_form.is_sym B)
{W : submodule R₁ M₁} (hW : disjoint W (B.orthogonal W)) :
(B.restrict W).nondegenerate :=
begin
rintro ⟨x, hx⟩ b₁,
rw [submodule.mk_eq_zero, ← submodule.mem_bot R₁],
refine hW ⟨hx, λ y hy, _⟩,
specialize b₁ ⟨y, hy⟩,
rwa [restrict_apply, submodule.coe_mk, submodule.coe_mk, b] at b₁
end
section
lemma to_lin_restrict_ker_eq_inf_orthogonal
(B : bilin_form K V) (W : subspace K V) (b : sym_bilin_form.is_sym B) :
(B.to_lin.dom_restrict W).ker.map W.subtype = (W ⊓ B.orthogonal ⊤ : subspace K V) :=
begin
ext x, split; intro hx,
{ rcases hx with ⟨⟨x, hx⟩, hker, rfl⟩,
erw linear_map.mem_ker at hker,
split,
{ simp [hx] },
{ intros y _,
rw [is_ortho, b],
change (B.to_lin.dom_restrict W) ⟨x, hx⟩ y = 0,
rw hker, refl } },
{ simp_rw [submodule.mem_map, linear_map.mem_ker],
refine ⟨⟨x, hx.1⟩, _, rfl⟩,
ext y, change B x y = 0,
rw b,
exact hx.2 _ submodule.mem_top }
end
lemma to_lin_restrict_range_dual_annihilator_comap_eq_orthogonal
(B : bilin_form K V) (W : subspace K V) :
(B.to_lin.dom_restrict W).range.dual_annihilator_comap = B.orthogonal W :=
begin
ext x, split; rw [mem_orthogonal_iff]; intro hx,
{ intros y hy,
rw submodule.mem_dual_annihilator_comap_iff at hx,
refine hx (B.to_lin.dom_restrict W ⟨y, hy⟩) ⟨⟨y, hy⟩, rfl⟩ },
{ rw submodule.mem_dual_annihilator_comap_iff,
rintro _ ⟨⟨w, hw⟩, rfl⟩,
exact hx w hw }
end
variable [finite_dimensional K V]
open finite_dimensional
lemma finrank_add_finrank_orthogonal
{B : bilin_form K V} {W : subspace K V} (b₁ : sym_bilin_form.is_sym B) :
finrank K W + finrank K (B.orthogonal W) =
finrank K V + finrank K (W ⊓ B.orthogonal ⊤ : subspace K V) :=
begin
rw [← to_lin_restrict_ker_eq_inf_orthogonal _ _ b₁,
← to_lin_restrict_range_dual_annihilator_comap_eq_orthogonal _ _,
finrank_map_subtype_eq],
conv_rhs { rw [← @subspace.finrank_add_finrank_dual_annihilator_comap_eq K V _ _ _ _
(B.to_lin.dom_restrict W).range,
add_comm, ← add_assoc, add_comm (finrank K ↥((B.to_lin.dom_restrict W).ker)),
linear_map.finrank_range_add_finrank_ker] },
end
/-- A subspace is complement to its orthogonal complement with respect to some
bilinear form if that bilinear form restricted on to the subspace is nondegenerate. -/
lemma restrict_nondegenerate_of_is_compl_orthogonal
{B : bilin_form K V} {W : subspace K V}
(b₁ : sym_bilin_form.is_sym B) (b₂ : (B.restrict W).nondegenerate) :
is_compl W (B.orthogonal W) :=
begin
have : W ⊓ B.orthogonal W = ⊥,
{ rw eq_bot_iff,
intros x hx,
obtain ⟨hx₁, hx₂⟩ := submodule.mem_inf.1 hx,
refine subtype.mk_eq_mk.1 (b₂ ⟨x, hx₁⟩ _),
rintro ⟨n, hn⟩,
rw [restrict_apply, submodule.coe_mk, submodule.coe_mk, b₁],
exact hx₂ n hn },
refine ⟨this ▸ le_refl _, _⟩,
{ rw top_le_iff,
refine eq_top_of_finrank_eq _,
refine le_antisymm (submodule.finrank_le _) _,
conv_rhs { rw ← add_zero (finrank K _) },
rw [← finrank_bot K V, ← this, submodule.dim_sup_add_dim_inf_eq,
finrank_add_finrank_orthogonal b₁],
exact nat.le.intro rfl }
end
/-- A subspace is complement to its orthogonal complement with respect to some bilinear form
if and only if that bilinear form restricted on to the subspace is nondegenerate. -/
theorem restrict_nondegenerate_iff_is_compl_orthogonal
{B : bilin_form K V} {W : subspace K V} (b₁ : sym_bilin_form.is_sym B) :
(B.restrict W).nondegenerate ↔ is_compl W (B.orthogonal W) :=
⟨λ b₂, restrict_nondegenerate_of_is_compl_orthogonal b₁ b₂,
λ h, B.nondegenerate_restrict_of_disjoint_orthogonal b₁ h.1⟩
/-- Given a nondegenerate bilinear form `B` on a finite-dimensional vector space, `B.to_dual` is
the linear equivalence between a vector space and its dual with the underlying linear map
`B.to_lin`. -/
noncomputable def to_dual (B : bilin_form K V) (b : B.nondegenerate) :
V ≃ₗ[K] module.dual K V :=
B.to_lin.linear_equiv_of_injective
(linear_map.ker_eq_bot.mp $ b.ker_eq_bot) subspace.dual_finrank_eq.symm
lemma to_dual_def {B : bilin_form K V} (b : B.nondegenerate) {m n : V} :
B.to_dual b m n = B m n := rfl
section dual_basis
variables {ι : Type*} [decidable_eq ι] [fintype ι]
/-- The `B`-dual basis `B.dual_basis hB b` to a finite basis `b` satisfies
`B (B.dual_basis hB b i) (b j) = B (b i) (B.dual_basis hB b j) = if i = j then 1 else 0`,
where `B` is a nondegenerate (symmetric) bilinear form and `b` is a finite basis. -/
noncomputable def dual_basis (B : bilin_form K V) (hB : B.nondegenerate) (b : basis ι K V) :
basis ι K V :=
b.dual_basis.map (B.to_dual hB).symm
@[simp] lemma dual_basis_repr_apply (B : bilin_form K V) (hB : B.nondegenerate) (b : basis ι K V)
(x i) : (B.dual_basis hB b).repr x i = B x (b i) :=
by rw [dual_basis, basis.map_repr, linear_equiv.symm_symm, linear_equiv.trans_apply,
basis.dual_basis_repr, to_dual_def]
lemma apply_dual_basis_left (B : bilin_form K V) (hB : B.nondegenerate) (b : basis ι K V)
(i j) : B (B.dual_basis hB b i) (b j) = if j = i then 1 else 0 :=
by rw [dual_basis, basis.map_apply, basis.coe_dual_basis, ← to_dual_def hB,
linear_equiv.apply_symm_apply, basis.coord_apply, basis.repr_self,
finsupp.single_apply]
lemma apply_dual_basis_right (B : bilin_form K V) (hB : B.nondegenerate)
(sym : sym_bilin_form.is_sym B) (b : basis ι K V)
(i j) : B (b i) (B.dual_basis hB b j) = if i = j then 1 else 0 :=
by rw [sym, apply_dual_basis_left]
end dual_basis
end
/-! We note that we cannot use `bilin_form.restrict_nondegenerate_iff_is_compl_orthogonal` for the
lemma below since the below lemma does not require `V` to be finite dimensional. However,
`bilin_form.restrict_nondegenerate_iff_is_compl_orthogonal` does not require `B` to be nondegenerate
on the whole space. -/
/-- The restriction of a symmetric, non-degenerate bilinear form on the orthogonal complement of
the span of a singleton is also non-degenerate. -/
lemma restrict_orthogonal_span_singleton_nondegenerate (B : bilin_form K V)
(b₁ : nondegenerate B) (b₂ : sym_bilin_form.is_sym B) {x : V} (hx : ¬ B.is_ortho x x) :
nondegenerate $ B.restrict $ B.orthogonal (K ∙ x) :=
begin
refine λ m hm, submodule.coe_eq_zero.1 (b₁ m.1 (λ n, _)),
have : n ∈ (K ∙ x) ⊔ B.orthogonal (K ∙ x) :=
(span_singleton_sup_orthogonal_eq_top hx).symm ▸ submodule.mem_top,
rcases submodule.mem_sup.1 this with ⟨y, hy, z, hz, rfl⟩,
specialize hm ⟨z, hz⟩,
rw restrict at hm,
erw [add_right, show B m.1 y = 0, by rw b₂; exact m.2 y hy, hm, add_zero]
end
section linear_adjoints
lemma comp_left_injective (B : bilin_form R₁ M₁) (b : B.nondegenerate) :
function.injective B.comp_left :=
λ φ ψ h, begin
ext w,
refine eq_of_sub_eq_zero (b _ _),
intro v,
rw [sub_left, ← comp_left_apply, ← comp_left_apply, ← h, sub_self]
end
lemma is_adjoint_pair_unique_of_nondegenerate (B : bilin_form R₁ M₁) (b : B.nondegenerate)
(φ ψ₁ ψ₂ : M₁ →ₗ[R₁] M₁) (hψ₁ : is_adjoint_pair B B ψ₁ φ) (hψ₂ : is_adjoint_pair B B ψ₂ φ) :
ψ₁ = ψ₂ :=
B.comp_left_injective b $ ext $ λ v w, by rw [comp_left_apply, comp_left_apply, hψ₁, hψ₂]
variable [finite_dimensional K V]
/-- Given bilinear forms `B₁, B₂` where `B₂` is nondegenerate, `symm_comp_of_nondegenerate`
is the linear map `B₂.to_lin⁻¹ ∘ B₁.to_lin`. -/
noncomputable def symm_comp_of_nondegenerate
(B₁ B₂ : bilin_form K V) (b₂ : B₂.nondegenerate) : V →ₗ[K] V :=
(B₂.to_dual b₂).symm.to_linear_map.comp B₁.to_lin
lemma comp_symm_comp_of_nondegenerate_apply (B₁ : bilin_form K V)
{B₂ : bilin_form K V} (b₂ : B₂.nondegenerate) (v : V) :
to_lin B₂ (B₁.symm_comp_of_nondegenerate B₂ b₂ v) = to_lin B₁ v :=
by erw [symm_comp_of_nondegenerate, linear_equiv.apply_symm_apply (B₂.to_dual b₂) _]
@[simp]
lemma symm_comp_of_nondegenerate_left_apply (B₁ : bilin_form K V)
{B₂ : bilin_form K V} (b₂ : B₂.nondegenerate) (v w : V) :
B₂ (symm_comp_of_nondegenerate B₁ B₂ b₂ w) v = B₁ w v :=
begin
conv_lhs { rw [← bilin_form.to_lin_apply, comp_symm_comp_of_nondegenerate_apply] },
refl,
end
/-- Given the nondegenerate bilinear form `B` and the linear map `φ`,
`left_adjoint_of_nondegenerate` provides the left adjoint of `φ` with respect to `B`.
The lemma proving this property is `bilin_form.is_adjoint_pair_left_adjoint_of_nondegenerate`. -/
noncomputable def left_adjoint_of_nondegenerate
(B : bilin_form K V) (b : B.nondegenerate) (φ : V →ₗ[K] V) : V →ₗ[K] V :=
symm_comp_of_nondegenerate (B.comp_right φ) B b
lemma is_adjoint_pair_left_adjoint_of_nondegenerate
(B : bilin_form K V) (b : B.nondegenerate) (φ : V →ₗ[K] V) :
is_adjoint_pair B B (B.left_adjoint_of_nondegenerate b φ) φ :=
λ x y, (B.comp_right φ).symm_comp_of_nondegenerate_left_apply b y x
/-- Given the nondegenerate bilinear form `B`, the linear map `φ` has a unique left adjoint given by
`bilin_form.left_adjoint_of_nondegenerate`. -/
theorem is_adjoint_pair_iff_eq_of_nondegenerate
(B : bilin_form K V) (b : B.nondegenerate) (ψ φ : V →ₗ[K] V) :
is_adjoint_pair B B ψ φ ↔ ψ = B.left_adjoint_of_nondegenerate b φ :=
⟨λ h, B.is_adjoint_pair_unique_of_nondegenerate b φ ψ _ h
(is_adjoint_pair_left_adjoint_of_nondegenerate _ _ _),
λ h, h.symm ▸ is_adjoint_pair_left_adjoint_of_nondegenerate _ _ _⟩
end linear_adjoints
section det
open matrix
variables {A : Type*} [integral_domain A] [module A M₃] (B₃ : bilin_form A M₃)
variables {ι : Type*} [decidable_eq ι] [fintype ι]
theorem _root_.matrix.nondegenerate.to_bilin' {M : matrix ι ι R₃} (h : M.nondegenerate) :
(to_bilin' M).nondegenerate :=
λ x hx, h.eq_zero_of_ortho (λ y,
by simpa only [to_bilin'_apply, dot_product, mul_vec, finset.mul_sum, mul_assoc] using hx y)
theorem nondegenerate_of_det_ne_zero' (M : matrix ι ι A) (h : M.det ≠ 0) :
(to_bilin' M).nondegenerate :=
(matrix.nondegenerate_of_det_ne_zero h).to_bilin'
theorem nondegenerate_of_det_ne_zero (b : basis ι A M₃) (h : (to_matrix b B₃).det ≠ 0) :
B₃.nondegenerate :=
begin
intros x hx,
refine b.equiv_fun.map_eq_zero_iff.mp (nondegenerate_of_det_ne_zero' _ h _ (λ w, _)),
convert hx (b.equiv_fun.symm w),
rw [bilin_form.to_matrix, linear_equiv.trans_apply, to_bilin'_to_matrix', congr_apply,
linear_equiv.symm_apply_apply]
end
end det
end bilin_form
|
618f8b365c9b4a052d765c34c31040a52b441017 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/category_theory/sites/left_exact.lean | 6081c333e841b1daa3bfe44bf5f6c8149bf89af8 | [
"Apache-2.0"
] | permissive | urkud/mathlib | eab80095e1b9f1513bfb7f25b4fa82fa4fd02989 | 6379d39e6b5b279df9715f8011369a301b634e41 | refs/heads/master | 1,658,425,342,662 | 1,658,078,703,000 | 1,658,078,703,000 | 186,910,338 | 0 | 0 | Apache-2.0 | 1,568,512,083,000 | 1,557,958,709,000 | Lean | UTF-8 | Lean | false | false | 10,101 | 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 category_theory.sites.sheafification
import category_theory.sites.limits
import category_theory.limits.functor_category
import category_theory.limits.filtered_colimit_commutes_finite_limit
/-!
# Left exactness of sheafification
In this file we show that sheafification commutes with finite limits.
-/
open category_theory
open category_theory.limits
open opposite
universes w v u
variables {C : Type (max v u)} [category.{v} C] {J : grothendieck_topology C}
variables {D : Type w} [category.{max v u} D]
variables [∀ (P : Cᵒᵖ ⥤ D) (X : C) (S : J.cover X), has_multiequalizer (S.index P)]
noncomputable theory
namespace category_theory.grothendieck_topology
/-- An auxiliary definition to be used in the proof of the fact that
`J.diagram_functor D X` preserves limits. -/
@[simps]
def cone_comp_evaluation_of_cone_comp_diagram_functor_comp_evaluation
{X : C} {K : Type (max v u)} [small_category K]
{F : K ⥤ Cᵒᵖ ⥤ D} {W : J.cover X} (i : W.arrow)
(E : cone (F ⋙ J.diagram_functor D X ⋙ (evaluation (J.cover X)ᵒᵖ D).obj (op W))) :
cone (F ⋙ (evaluation _ _).obj (op i.Y)) :=
{ X := E.X,
π :=
{ app := λ k, E.π.app k ≫ multiequalizer.ι (W.index (F.obj k)) i,
naturality' := begin
intros a b f,
dsimp,
rw [category.id_comp, category.assoc, ← E.w f],
dsimp [diagram_nat_trans],
simp only [multiequalizer.lift_ι, category.assoc],
end } }
/-- An auxiliary definition to be used in the proof of the fact that
`J.diagram_functor D X` preserves limits. -/
abbreviation lift_to_diagram_limit_obj
{X : C} {K : Type (max v u)} [small_category K] [has_limits_of_shape K D]
{W : (J.cover X)ᵒᵖ} (F : K ⥤ Cᵒᵖ ⥤ D)
(E : cone (F ⋙ J.diagram_functor D X ⋙ (evaluation (J.cover X)ᵒᵖ D).obj W)) :
E.X ⟶ (J.diagram (limit F) X).obj W :=
multiequalizer.lift _ _ (λ i,
(is_limit_of_preserves ((evaluation _ _).obj (op i.Y)) (limit.is_limit _)).lift
(cone_comp_evaluation_of_cone_comp_diagram_functor_comp_evaluation i E))
begin
intros i,
change (_ ≫ _) ≫ _ = (_ ≫ _) ≫ _,
dsimp [evaluate_combined_cones],
erw [category.comp_id, category.comp_id, category.assoc,
category.assoc, ← (limit.lift F _).naturality, ← (limit.lift F _).naturality,
← category.assoc, ← category.assoc],
congr' 1, ext1,
erw [category.assoc, category.assoc, limit.lift_π, limit.lift_π,
limit.lift_π_assoc, limit.lift_π_assoc, category.assoc,
category.assoc, multiequalizer.condition],
refl,
end
instance (X : C) (K : Type (max v u)) [small_category K] [has_limits_of_shape K D]
(F : K ⥤ Cᵒᵖ ⥤ D) : preserves_limit F (J.diagram_functor D X) :=
preserves_limit_of_evaluation _ _ $ λ W,
preserves_limit_of_preserves_limit_cone (limit.is_limit _)
{ lift := λ E, lift_to_diagram_limit_obj F E,
fac' := begin
intros E k,
dsimp [diagram_nat_trans],
ext1,
simp only [multiequalizer.lift_ι, multiequalizer.lift_ι_assoc, category.assoc],
change (_ ≫ _) ≫ _ = _,
dsimp [evaluate_combined_cones],
erw [category.comp_id, category.assoc, ← nat_trans.comp_app, limit.lift_π, limit.lift_π],
refl,
end,
uniq' := begin
intros E m hm,
ext,
delta lift_to_diagram_limit_obj,
erw [multiequalizer.lift_ι, category.assoc],
change _ = (_ ≫ _) ≫ _,
dsimp [evaluate_combined_cones],
erw [category.comp_id, category.assoc, ← nat_trans.comp_app, limit.lift_π, limit.lift_π],
dsimp,
rw ← hm,
dsimp [diagram_nat_trans],
simp,
end } .
instance (X : C) (K : Type (max v u)) [small_category K] [has_limits_of_shape K D] :
preserves_limits_of_shape K (J.diagram_functor D X) := ⟨⟩
instance (X : C) [has_limits D] : preserves_limits (J.diagram_functor D X) := ⟨⟩
variables [∀ (X : C), has_colimits_of_shape (J.cover X)ᵒᵖ D]
variables [concrete_category.{max v u} D]
variables [∀ (X : C), preserves_colimits_of_shape (J.cover X)ᵒᵖ (forget D)]
/-- An auxiliary definition to be used in the proof that `J.plus_functor D` commutes
with finite limits. -/
def lift_to_plus_obj_limit_obj {K : Type (max v u)} [small_category K] [fin_category K]
[has_limits_of_shape K D] [preserves_limits_of_shape K (forget D)]
[reflects_limits_of_shape K (forget D)] (F : K ⥤ Cᵒᵖ ⥤ D) (X : C)
(S : cone (F ⋙ J.plus_functor D ⋙ (evaluation Cᵒᵖ D).obj (op X))) :
S.X ⟶ (J.plus_obj (limit F)).obj (op X) :=
let
e := colimit_limit_iso (F ⋙ J.diagram_functor D X),
t : J.diagram (limit F) X ≅ limit (F ⋙ J.diagram_functor D X) :=
(is_limit_of_preserves (J.diagram_functor D X) (limit.is_limit _)).cone_point_unique_up_to_iso
(limit.is_limit _),
p : (J.plus_obj (limit F)).obj (op X) ≅ colimit (limit (F ⋙ J.diagram_functor D X)) :=
has_colimit.iso_of_nat_iso t,
s : colimit (F ⋙ J.diagram_functor D X).flip ≅
F ⋙ J.plus_functor D ⋙ (evaluation Cᵒᵖ D).obj (op X) :=
nat_iso.of_components (λ k, colimit_obj_iso_colimit_comp_evaluation _ k) begin
intros i j f,
rw [← iso.eq_comp_inv, category.assoc, ← iso.inv_comp_eq],
ext w,
dsimp [plus_map],
erw [colimit.ι_map_assoc, colimit_obj_iso_colimit_comp_evaluation_ι_inv
((F ⋙ J.diagram_functor D X).flip) w j,
colimit_obj_iso_colimit_comp_evaluation_ι_inv_assoc
((F ⋙ J.diagram_functor D X).flip) w i],
rw ← (colimit.ι (F ⋙ J.diagram_functor D X).flip w).naturality,
refl
end in
limit.lift _ S ≫ (has_limit.iso_of_nat_iso s.symm).hom ≫ e.inv ≫ p.inv
-- This lemma should not be used directly. Instead, one should use the fact that
-- `J.plus_functor D` preserves finite limits, along with the fact that
-- evaluation preserves limits.
lemma lift_to_plus_obj_limit_obj_fac {K : Type (max v u)} [small_category K] [fin_category K]
[has_limits_of_shape K D] [preserves_limits_of_shape K (forget D)]
[reflects_limits_of_shape K (forget D)] (F : K ⥤ Cᵒᵖ ⥤ D) (X : C)
(S : cone (F ⋙ J.plus_functor D ⋙ (evaluation Cᵒᵖ D).obj (op X))) (k) :
lift_to_plus_obj_limit_obj F X S ≫ (J.plus_map (limit.π F k)).app (op X) = S.π.app k :=
begin
dsimp only [lift_to_plus_obj_limit_obj],
rw [← (limit.is_limit (F ⋙ J.plus_functor D ⋙ (evaluation Cᵒᵖ D).obj (op X))).fac S k,
category.assoc],
congr' 1,
dsimp,
simp only [category.assoc],
rw [← iso.eq_inv_comp, iso.inv_comp_eq, iso.inv_comp_eq],
ext,
dsimp [plus_map],
simp only [has_colimit.iso_of_nat_iso_ι_hom_assoc, ι_colim_map],
dsimp [is_limit.cone_point_unique_up_to_iso, has_limit.iso_of_nat_iso,
is_limit.map],
rw limit.lift_π,
dsimp,
rw ι_colimit_limit_iso_limit_π_assoc,
simp_rw [← nat_trans.comp_app, ← category.assoc, ← nat_trans.comp_app],
rw [limit.lift_π, category.assoc],
congr' 1,
rw ← iso.comp_inv_eq,
erw colimit.ι_desc,
refl,
end
instance (K : Type (max v u))
[small_category K] [fin_category K] [has_limits_of_shape K D]
[preserves_limits_of_shape K (forget D)]
[reflects_limits_of_shape K (forget D)] :
preserves_limits_of_shape K (J.plus_functor D) :=
begin
constructor, intros F, apply preserves_limit_of_evaluation, intros X,
apply preserves_limit_of_preserves_limit_cone (limit.is_limit F),
refine ⟨λ S, lift_to_plus_obj_limit_obj F X.unop S, _, _⟩,
{ intros S k,
apply lift_to_plus_obj_limit_obj_fac },
{ intros S m hm,
dsimp [lift_to_plus_obj_limit_obj],
simp_rw [← category.assoc, iso.eq_comp_inv, ← iso.comp_inv_eq],
ext,
simp only [limit.lift_π, category.assoc, ← hm],
congr' 1,
ext,
dsimp [plus_map, plus_obj],
erw [colimit.ι_map, colimit.ι_desc_assoc, limit.lift_π],
dsimp,
simp only [category.assoc],
rw ι_colimit_limit_iso_limit_π_assoc,
simp only [nat_iso.of_components.inv_app,
colimit_obj_iso_colimit_comp_evaluation_ι_app_hom, iso.symm_inv],
dsimp [is_limit.cone_point_unique_up_to_iso],
rw [← category.assoc, ← nat_trans.comp_app, limit.lift_π],
refl }
end
instance [has_finite_limits D] [preserves_finite_limits (forget D)]
[reflects_isomorphisms (forget D)] : preserves_finite_limits (J.plus_functor D) :=
begin
apply preserves_finite_limits_of_preserves_finite_limits_of_size.{max v u},
introsI K _ _,
haveI : reflects_limits_of_shape K (forget D) :=
reflects_limits_of_shape_of_reflects_isomorphisms,
apply_instance
end
instance (K : Type (max v u))
[small_category K] [fin_category K] [has_limits_of_shape K D]
[preserves_limits_of_shape K (forget D)]
[reflects_limits_of_shape K (forget D)] :
preserves_limits_of_shape K (J.sheafification D) :=
limits.comp_preserves_limits_of_shape _ _
instance [has_finite_limits D] [preserves_finite_limits (forget D)]
[reflects_isomorphisms (forget D)] : preserves_finite_limits (J.sheafification D) :=
limits.comp_preserves_finite_limits _ _
end category_theory.grothendieck_topology
namespace category_theory
variables [∀ (X : C), has_colimits_of_shape (J.cover X)ᵒᵖ D]
variables [concrete_category.{max v u} D]
variables [∀ (X : C), preserves_colimits_of_shape (J.cover X)ᵒᵖ (forget D)]
variables [preserves_limits (forget D)]
variables [reflects_isomorphisms (forget D)]
variables (K : Type (max v u))
variables [small_category K] [fin_category K] [has_limits_of_shape K D]
instance : preserves_limits_of_shape K (presheaf_to_Sheaf J D) :=
begin
constructor, intros F, constructor, intros S hS,
apply is_limit_of_reflects (Sheaf_to_presheaf J D),
haveI : reflects_limits_of_shape K (forget D) :=
reflects_limits_of_shape_of_reflects_isomorphisms,
apply is_limit_of_preserves (J.sheafification D) hS,
end
instance [has_finite_limits D] : preserves_finite_limits (presheaf_to_Sheaf J D) :=
begin
apply preserves_finite_limits_of_preserves_finite_limits_of_size.{max v u},
intros, resetI, apply_instance
end
end category_theory
|
350eb5cef8b939d911066a8d02e6788d94562bc0 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/order/cover.lean | 1c6491555929182acfe99f6d64bd5246726a4f12 | [
"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 | 12,863 | lean | /-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Violeta Hernández Palacios, Grayson Burton, Floris van Doorn
-/
import data.set.intervals.ord_connected
/-!
# The covering relation
This file defines the covering relation in an order. `b` is said to cover `a` if `a < b` and there
is no element in between. We say that `b` weakly covers `a` if `a ≤ b` and there is no element
between `a` and `b`. In a partial order this is equivalent to `a ⋖ b ∨ a = b`, in a preorder this
is equivalent to `a ⋖ b ∨ (a ≤ b ∧ b ≤ a)`
## Notation
* `a ⋖ b` means that `b` covers `a`.
* `a ⩿ b` means that `b` weakly covers `a`.
-/
open set order_dual
variables {α β : Type*}
section weakly_covers
section preorder
variables [preorder α] [preorder β] {a b c: α}
/-- `wcovby a b` means that `a = b` or `b` covers `a`.
This means that `a ≤ b` and there is no element in between.
-/
def wcovby (a b : α) : Prop := a ≤ b ∧ ∀ ⦃c⦄, a < c → ¬ c < b
infix ` ⩿ `:50 := wcovby
lemma wcovby.le (h : a ⩿ b) : a ≤ b := h.1
lemma wcovby.refl (a : α) : a ⩿ a := ⟨le_rfl, λ c hc, hc.not_lt⟩
lemma wcovby.rfl : a ⩿ a := wcovby.refl a
protected lemma eq.wcovby (h : a = b) : a ⩿ b := h ▸ wcovby.rfl
lemma wcovby_of_le_of_le (h1 : a ≤ b) (h2 : b ≤ a) : a ⩿ b :=
⟨h1, λ c hac hcb, (hac.trans hcb).not_le h2⟩
alias wcovby_of_le_of_le ← has_le.le.wcovby_of_le
lemma wcovby.wcovby_iff_le (hab : a ⩿ b) : b ⩿ a ↔ b ≤ a :=
⟨λ h, h.le, λ h, h.wcovby_of_le hab.le⟩
lemma wcovby_of_eq_or_eq (hab : a ≤ b) (h : ∀ c, a ≤ c → c ≤ b → c = a ∨ c = b) : a ⩿ b :=
⟨hab, λ c ha hb, (h c ha.le hb.le).elim ha.ne' hb.ne⟩
/-- If `a ≤ b`, then `b` does not cover `a` iff there's an element in between. -/
lemma not_wcovby_iff (h : a ≤ b) : ¬ a ⩿ b ↔ ∃ c, a < c ∧ c < b :=
by simp_rw [wcovby, h, true_and, not_forall, exists_prop, not_not]
instance wcovby.is_refl : is_refl α (⩿) := ⟨wcovby.refl⟩
lemma wcovby.Ioo_eq (h : a ⩿ b) : Ioo a b = ∅ :=
eq_empty_iff_forall_not_mem.2 $ λ x hx, h.2 hx.1 hx.2
lemma wcovby.of_image (f : α ↪o β) (h : f a ⩿ f b) : a ⩿ b :=
⟨f.le_iff_le.mp h.le, λ c hac hcb, h.2 (f.lt_iff_lt.mpr hac) (f.lt_iff_lt.mpr hcb)⟩
lemma wcovby.image (f : α ↪o β) (hab : a ⩿ b) (h : (range f).ord_connected) : f a ⩿ f b :=
begin
refine ⟨f.monotone hab.le, λ c ha hb, _⟩,
obtain ⟨c, rfl⟩ := h.out (mem_range_self _) (mem_range_self _) ⟨ha.le, hb.le⟩,
rw f.lt_iff_lt at ha hb,
exact hab.2 ha hb,
end
lemma set.ord_connected.apply_wcovby_apply_iff (f : α ↪o β) (h : (range f).ord_connected) :
f a ⩿ f b ↔ a ⩿ b :=
⟨λ h2, h2.of_image f, λ hab, hab.image f h⟩
@[simp] lemma apply_wcovby_apply_iff {E : Type*} [order_iso_class E α β] (e : E) :
e a ⩿ e b ↔ a ⩿ b :=
(ord_connected_range (e : α ≃o β)).apply_wcovby_apply_iff ((e : α ≃o β) : α ↪o β)
@[simp] lemma to_dual_wcovby_to_dual_iff : to_dual b ⩿ to_dual a ↔ a ⩿ b :=
and_congr_right' $ forall_congr $ λ c, forall_swap
@[simp] lemma of_dual_wcovby_of_dual_iff {a b : αᵒᵈ} :
of_dual a ⩿ of_dual b ↔ b ⩿ a :=
and_congr_right' $ forall_congr $ λ c, forall_swap
alias to_dual_wcovby_to_dual_iff ↔ _ wcovby.to_dual
alias of_dual_wcovby_of_dual_iff ↔ _ wcovby.of_dual
end preorder
section partial_order
variables [partial_order α] {a b c : α}
lemma wcovby.eq_or_eq (h : a ⩿ b) (h2 : a ≤ c) (h3 : c ≤ b) : c = a ∨ c = b :=
begin
rcases h2.eq_or_lt with h2|h2, { exact or.inl h2.symm },
rcases h3.eq_or_lt with h3|h3, { exact or.inr h3 },
exact (h.2 h2 h3).elim
end
lemma wcovby.le_and_le_iff (h : a ⩿ b) : a ≤ c ∧ c ≤ b ↔ c = a ∨ c = b :=
begin
refine ⟨λ h2, h.eq_or_eq h2.1 h2.2, _⟩, rintro (rfl|rfl), exacts [⟨le_rfl, h.le⟩, ⟨h.le, le_rfl⟩]
end
lemma wcovby.Icc_eq (h : a ⩿ b) : Icc a b = {a, b} :=
by { ext c, exact h.le_and_le_iff }
lemma wcovby.Ico_subset (h : a ⩿ b) : Ico a b ⊆ {a} :=
by rw [← Icc_diff_right, h.Icc_eq, diff_singleton_subset_iff, pair_comm]
lemma wcovby.Ioc_subset (h : a ⩿ b) : Ioc a b ⊆ {b} :=
by rw [← Icc_diff_left, h.Icc_eq, diff_singleton_subset_iff]
end partial_order
end weakly_covers
section has_lt
variables [has_lt α] {a b : α}
/-- `covby a b` means that `b` covers `a`: `a < b` and there is no element in between. -/
def covby (a b : α) : Prop := a < b ∧ ∀ ⦃c⦄, a < c → ¬ c < b
infix ` ⋖ `:50 := covby
lemma covby.lt (h : a ⋖ b) : a < b := h.1
/-- If `a < b`, then `b` does not cover `a` iff there's an element in between. -/
lemma not_covby_iff (h : a < b) : ¬a ⋖ b ↔ ∃ c, a < c ∧ c < b :=
by simp_rw [covby, h, true_and, not_forall, exists_prop, not_not]
alias not_covby_iff ↔ exists_lt_lt_of_not_covby _
alias exists_lt_lt_of_not_covby ← has_lt.lt.exists_lt_lt
/-- In a dense order, nothing covers anything. -/
lemma not_covby [densely_ordered α] : ¬ a ⋖ b :=
λ h, let ⟨c, hc⟩ := exists_between h.1 in h.2 hc.1 hc.2
lemma densely_ordered_iff_forall_not_covby : densely_ordered α ↔ ∀ a b : α, ¬ a ⋖ b :=
⟨λ h a b, @not_covby _ _ _ _ h, λ h, ⟨λ a b hab, exists_lt_lt_of_not_covby hab $ h _ _⟩⟩
@[simp] lemma to_dual_covby_to_dual_iff : to_dual b ⋖ to_dual a ↔ a ⋖ b :=
and_congr_right' $ forall_congr $ λ c, forall_swap
@[simp] lemma of_dual_covby_of_dual_iff {a b : αᵒᵈ} : of_dual a ⋖ of_dual b ↔ b ⋖ a :=
and_congr_right' $ forall_congr $ λ c, forall_swap
alias to_dual_covby_to_dual_iff ↔ _ covby.to_dual
alias of_dual_covby_of_dual_iff ↔ _ covby.of_dual
end has_lt
section preorder
variables [preorder α] [preorder β] {a b : α}
lemma covby.le (h : a ⋖ b) : a ≤ b := h.1.le
protected lemma covby.ne (h : a ⋖ b) : a ≠ b := h.lt.ne
lemma covby.ne' (h : a ⋖ b) : b ≠ a := h.lt.ne'
protected lemma covby.wcovby (h : a ⋖ b) : a ⩿ b := ⟨h.le, h.2⟩
lemma wcovby.covby_of_not_le (h : a ⩿ b) (h2 : ¬ b ≤ a) : a ⋖ b := ⟨h.le.lt_of_not_le h2, h.2⟩
lemma wcovby.covby_of_lt (h : a ⩿ b) (h2 : a < b) : a ⋖ b := ⟨h2, h.2⟩
lemma covby_iff_wcovby_and_lt : a ⋖ b ↔ a ⩿ b ∧ a < b :=
⟨λ h, ⟨h.wcovby, h.lt⟩, λ h, h.1.covby_of_lt h.2⟩
lemma covby_iff_wcovby_and_not_le : a ⋖ b ↔ a ⩿ b ∧ ¬ b ≤ a :=
⟨λ h, ⟨h.wcovby, h.lt.not_le⟩, λ h, h.1.covby_of_not_le h.2⟩
lemma wcovby_iff_covby_or_le_and_le : a ⩿ b ↔ a ⋖ b ∨ (a ≤ b ∧ b ≤ a) :=
⟨λ h, or_iff_not_imp_right.mpr $ λ h', h.covby_of_not_le $ λ hba, h' ⟨h.le, hba⟩,
λ h', h'.elim (λ h, h.wcovby) (λ h, h.1.wcovby_of_le h.2)⟩
instance : is_nonstrict_strict_order α (⩿) (⋖) :=
⟨λ a b, covby_iff_wcovby_and_not_le.trans $ and_congr_right $ λ h, h.wcovby_iff_le.not.symm⟩
instance covby.is_irrefl : is_irrefl α (⋖) := ⟨λ a ha, ha.ne rfl⟩
lemma covby.Ioo_eq (h : a ⋖ b) : Ioo a b = ∅ :=
h.wcovby.Ioo_eq
lemma covby.of_image (f : α ↪o β) (h : f a ⋖ f b) : a ⋖ b :=
⟨f.lt_iff_lt.mp h.lt, λ c hac hcb, h.2 (f.lt_iff_lt.mpr hac) (f.lt_iff_lt.mpr hcb)⟩
lemma covby.image (f : α ↪o β) (hab : a ⋖ b) (h : (range f).ord_connected) : f a ⋖ f b :=
(hab.wcovby.image f h).covby_of_lt $ f.strict_mono hab.lt
lemma set.ord_connected.apply_covby_apply_iff (f : α ↪o β) (h : (range f).ord_connected) :
f a ⋖ f b ↔ a ⋖ b :=
⟨covby.of_image f, λ hab, hab.image f h⟩
@[simp] lemma apply_covby_apply_iff {E : Type*} [order_iso_class E α β] (e : E) :
e a ⋖ e b ↔ a ⋖ b :=
(ord_connected_range (e : α ≃o β)).apply_covby_apply_iff ((e : α ≃o β) : α ↪o β)
end preorder
section partial_order
variables [partial_order α] {a b : α}
lemma wcovby.covby_of_ne (h : a ⩿ b) (h2 : a ≠ b) : a ⋖ b := ⟨h.le.lt_of_ne h2, h.2⟩
lemma covby_iff_wcovby_and_ne : a ⋖ b ↔ a ⩿ b ∧ a ≠ b :=
⟨λ h, ⟨h.wcovby, h.ne⟩, λ h, h.1.covby_of_ne h.2⟩
lemma wcovby_iff_covby_or_eq : a ⩿ b ↔ a ⋖ b ∨ a = b :=
by rw [le_antisymm_iff, wcovby_iff_covby_or_le_and_le]
lemma covby.Ico_eq (h : a ⋖ b) : Ico a b = {a} :=
by rw [←Ioo_union_left h.lt, h.Ioo_eq, empty_union]
lemma covby.Ioc_eq (h : a ⋖ b) : Ioc a b = {b} :=
by rw [←Ioo_union_right h.lt, h.Ioo_eq, empty_union]
lemma covby.Icc_eq (h : a ⋖ b) : Icc a b = {a, b} :=
h.wcovby.Icc_eq
end partial_order
section linear_order
variables [linear_order α] {a b c : α}
lemma covby.Ioi_eq (h : a ⋖ b) : Ioi a = Ici b :=
by rw [← Ioo_union_Ici_eq_Ioi h.lt, h.Ioo_eq, empty_union]
lemma covby.Iio_eq (h : a ⋖ b) : Iio b = Iic a :=
by rw [← Iic_union_Ioo_eq_Iio h.lt, h.Ioo_eq, union_empty]
lemma wcovby.le_of_lt (hab : a ⩿ b) (hcb : c < b) : c ≤ a := not_lt.1 $ λ hac, hab.2 hac hcb
lemma wcovby.ge_of_gt (hab : a ⩿ b) (hac : a < c) : b ≤ c := not_lt.1 $ hab.2 hac
lemma covby.le_of_lt (hab : a ⋖ b) : c < b → c ≤ a := hab.wcovby.le_of_lt
lemma covby.ge_of_gt (hab : a ⋖ b) : a < c → b ≤ c := hab.wcovby.ge_of_gt
lemma covby.unique_left (ha : a ⋖ c) (hb : b ⋖ c) : a = b :=
(hb.le_of_lt ha.lt).antisymm $ ha.le_of_lt hb.lt
lemma covby.unique_right (hb : a ⋖ b) (hc : a ⋖ c) : b = c :=
(hb.ge_of_gt hc.lt).antisymm $ hc.ge_of_gt hb.lt
end linear_order
namespace set
lemma wcovby_insert (x : α) (s : set α) : s ⩿ insert x s :=
begin
refine wcovby_of_eq_or_eq (subset_insert x s) (λ t hst h2t, _),
by_cases h : x ∈ t,
{ exact or.inr (subset_antisymm h2t $ insert_subset.mpr ⟨h, hst⟩) },
{ refine or.inl (subset_antisymm _ hst),
rwa [← diff_singleton_eq_self h, diff_singleton_subset_iff] }
end
lemma covby_insert {x : α} {s : set α} (hx : x ∉ s) : s ⋖ insert x s :=
(wcovby_insert x s).covby_of_lt $ ssubset_insert hx
end set
namespace prod
variables [partial_order α] [partial_order β] {a a₁ a₂ : α} {b b₁ b₂ : β} {x y : α × β}
@[simp] lemma swap_wcovby_swap : x.swap ⩿ y.swap ↔ x ⩿ y :=
apply_wcovby_apply_iff (order_iso.prod_comm : α × β ≃o β × α)
@[simp] lemma swap_covby_swap : x.swap ⋖ y.swap ↔ x ⋖ y :=
apply_covby_apply_iff (order_iso.prod_comm : α × β ≃o β × α)
lemma fst_eq_or_snd_eq_of_wcovby : x ⩿ y → x.1 = y.1 ∨ x.2 = y.2 :=
begin
refine λ h, of_not_not (λ hab, _),
push_neg at hab,
exact h.2 (mk_lt_mk.2 $ or.inl ⟨hab.1.lt_of_le h.1.1, le_rfl⟩)
(mk_lt_mk.2 $ or.inr ⟨le_rfl, hab.2.lt_of_le h.1.2⟩),
end
lemma _root_.wcovby.fst (h : x ⩿ y) : x.1 ⩿ y.1 :=
⟨h.1.1, λ c h₁ h₂, h.2 (mk_lt_mk_iff_left.2 h₁) ⟨⟨h₂.le, h.1.2⟩, λ hc, h₂.not_le hc.1⟩⟩
lemma _root_.wcovby.snd (h : x ⩿ y) : x.2 ⩿ y.2 :=
⟨h.1.2, λ c h₁ h₂, h.2 (mk_lt_mk_iff_right.2 h₁) ⟨⟨h.1.1, h₂.le⟩, λ hc, h₂.not_le hc.2⟩⟩
lemma mk_wcovby_mk_iff_left : (a₁, b) ⩿ (a₂, b) ↔ a₁ ⩿ a₂ :=
begin
refine ⟨wcovby.fst, and.imp mk_le_mk_iff_left.2 $ λ h c h₁ h₂, _⟩,
have : c.2 = b:= h₂.le.2.antisymm h₁.le.2,
rw [←@prod.mk.eta _ _ c, this, mk_lt_mk_iff_left] at h₁ h₂,
exact h h₁ h₂,
end
lemma mk_wcovby_mk_iff_right : (a, b₁) ⩿ (a, b₂) ↔ b₁ ⩿ b₂ :=
swap_wcovby_swap.trans mk_wcovby_mk_iff_left
lemma mk_covby_mk_iff_left : (a₁, b) ⋖ (a₂, b) ↔ a₁ ⋖ a₂ :=
by simp_rw [covby_iff_wcovby_and_lt, mk_wcovby_mk_iff_left, mk_lt_mk_iff_left]
lemma mk_covby_mk_iff_right : (a, b₁) ⋖ (a, b₂) ↔ b₁ ⋖ b₂ :=
by simp_rw [covby_iff_wcovby_and_lt, mk_wcovby_mk_iff_right, mk_lt_mk_iff_right]
lemma mk_wcovby_mk_iff : (a₁, b₁) ⩿ (a₂, b₂) ↔ a₁ ⩿ a₂ ∧ b₁ = b₂ ∨ b₁ ⩿ b₂ ∧ a₁ = a₂ :=
begin
refine ⟨λ h, _, _⟩,
{ obtain rfl | rfl : a₁ = a₂ ∨ b₁ = b₂ := fst_eq_or_snd_eq_of_wcovby h,
{ exact or.inr ⟨mk_wcovby_mk_iff_right.1 h, rfl⟩ },
{ exact or.inl ⟨mk_wcovby_mk_iff_left.1 h, rfl⟩ } },
{ rintro (⟨h, rfl⟩ | ⟨h, rfl⟩),
{ exact mk_wcovby_mk_iff_left.2 h },
{ exact mk_wcovby_mk_iff_right.2 h } }
end
lemma mk_covby_mk_iff : (a₁, b₁) ⋖ (a₂, b₂) ↔ a₁ ⋖ a₂ ∧ b₁ = b₂ ∨ b₁ ⋖ b₂ ∧ a₁ = a₂ :=
begin
refine ⟨λ h, _, _⟩,
{ obtain rfl | rfl : a₁ = a₂ ∨ b₁ = b₂ := fst_eq_or_snd_eq_of_wcovby h.wcovby,
{ exact or.inr ⟨mk_covby_mk_iff_right.1 h, rfl⟩ },
{ exact or.inl ⟨mk_covby_mk_iff_left.1 h, rfl⟩ } },
{ rintro (⟨h, rfl⟩ | ⟨h, rfl⟩),
{ exact mk_covby_mk_iff_left.2 h },
{ exact mk_covby_mk_iff_right.2 h } }
end
lemma wcovby_iff : x ⩿ y ↔ x.1 ⩿ y.1 ∧ x.2 = y.2 ∨ x.2 ⩿ y.2 ∧ x.1 = y.1 :=
by { cases x, cases y, exact mk_wcovby_mk_iff }
lemma covby_iff : x ⋖ y ↔ x.1 ⋖ y.1 ∧ x.2 = y.2 ∨ x.2 ⋖ y.2 ∧ x.1 = y.1 :=
by { cases x, cases y, exact mk_covby_mk_iff }
end prod
|
18a2adb92bce5c7d099b6275d3f21feb36741341 | 75c54c8946bb4203e0aaf196f918424a17b0de99 | /src/reflect_test.lean | 567c2838d395fb238f70674c6283d1f5fcc85494 | [
"Apache-2.0"
] | permissive | urkud/flypitch | 261e2a45f1038130178575406df8aea78255ba77 | 2250f5eda14b6ef9fc3e4e1f4a9ac4005634de5c | refs/heads/master | 1,653,266,469,246 | 1,577,819,679,000 | 1,577,819,679,000 | 259,862,235 | 1 | 0 | Apache-2.0 | 1,588,147,244,000 | 1,588,147,244,000 | null | UTF-8 | Lean | false | false | 7,539 | lean | import .fol .abel
universe u
-- section weekdays
-- @[derive has_reflect]
-- inductive weekday : Type
-- | monday : weekday
-- | another_day : weekday → weekday
-- open weekday
-- meta def dump_weekday (f : weekday) : tactic unit :=
-- tactic.trace $ to_string (expr.to_raw_fmt (reflect f).to_expr)
-- -- run_cmd dump_weekday (another_day (another_day monday))
-- --(app (const weekday.another_day []) (app (const weekday.another_day []) (const weekday.monday [])))
-- inductive weekday' : Type
-- | monday : weekday'
-- | another_day : weekday' → weekday'
-- open weekday'
-- meta instance has_reflect_weekday' : has_reflect weekday'
-- | weekday'.monday := `(monday)
-- | (weekday'.another_day x) := `(λ l, weekday'.another_day l).subst $
-- by haveI := has_reflect_weekday'; exact (reflect x)
-- meta def dump_weekday' (f : weekday') : tactic unit :=
-- tactic.trace $ to_string (expr.to_raw_fmt (reflect f).to_expr)
-- -- run_cmd dump_weekday' (another_day (another_day monday))
-- -- (app (const weekday'.another_day []) (app (const weekday'.another_day []) (const weekday'.monday [])))
-- end weekdays
-- -- meta instance has_reflect_preterm {L : Language.{u}} : Π{n : ℕ}, has_reflect (preterm L n)
-- -- | 0 (var k) := `(@preterm.var L).subst (reflect k)
-- -- @[derive has_reflect]
-- open fol abel
-- section preterm_aux
-- inductive preterm_aux (L : Language.{u}) : Type u
-- | var : ℕ → preterm_aux
-- | func : ∀ k : ℕ, L.functions k → preterm_aux
-- | app : preterm_aux → preterm_aux → preterm_aux
-- def to_aux {L : Language.{u}} : ∀ {l : ℕ}, preterm L l → preterm_aux L
-- | 0 (var n) := preterm_aux.var _ n
-- | k (func f) := preterm_aux.func _ f
-- | k (app t₁ t₂) := preterm_aux.app (to_aux t₁) (to_aux t₂)
-- def L_abel_plus' (t₁ t₂ : preterm L_abel 0) : preterm L_abel 0 :=
-- @term_of_function L_abel 2 (abel_functions.plus : L_abel.functions 2) t₁ t₂
-- end preterm_aux
-- local infix ` +' `:100 := L_abel_plus'
-- local notation ` zero ` := (func abel_functions.zero : preterm L_abel 0)
-- section L_abel_term_biopsy
-- def sample1 : preterm L_abel 0 := (zero +' zero)
-- def sample2 : preterm L_abel 0 := zero
-- -- #reduce sample2
-- open expr
-- meta def sample2_expr : expr :=
-- mk_app (const `preterm.func list.nil) ([(const `L_abel list.nil), `(0), const `abel_functions.zero list.nil] : list expr)
-- end L_abel_term_biopsy
-- section simpler_biopsy
-- inductive my_inductive : Type
-- | a : my_inductive
-- | b : my_inductive
-- | f : my_inductive → my_inductive
-- open my_inductive
-- def sample3 : my_inductive := f a
-- open expr
-- meta def sample3_expr : expr :=
-- app (const `my_inductive.f list.nil) (const `my_inductive.a list.nil)
-- def sample3_again : my_inductive := by tactic.exact (sample3_expr)
-- example : sample3 = sample3_again := rfl
-- end simpler_biopsy
-- namespace tactic
-- namespace interactive
-- open interactive interactive.types expr
-- def my_test_term : preterm L_abel 0 := (zero +' zero)
-- end interactive
-- end tactic
-- section test
-- -- def my_term : preterm L_abel 0 := sorry
-- -- #check tactic.interactive.rcases
-- end test
-- section sample4
-- /-- Note: this is the same as `dfin` -/
-- inductive my_indexed_family : ℕ → Type u
-- | z {} : my_indexed_family 0
-- | s : ∀ {k}, my_indexed_family k → my_indexed_family (k+1)
-- -- meta example : ∀ {n}, has_reflect (my_indexed_family n)
-- -- | 0 z := `(z)
-- open my_indexed_family
-- def sample4 : my_indexed_family 1 := s z
-- -- #check tactic.eval_expr
-- end sample4
-- section sample4
-- inductive dfin'' : ℕ → Type
-- | fz {n} : dfin'' (n+1)
-- | fs {n} : dfin'' n → dfin'' (n+1)
-- inductive dfin' : ℕ → Type u
-- | gz {n} : dfin' (n+1)
-- | gs {n} : dfin' n → dfin' (n+1)
-- open dfin dfin'
-- meta instance dfin.reflect : ∀ {n}, has_reflect (dfin'' n)
-- | _ dfin''.fz := `(dfin''.fz)
-- | _ (dfin''.fs n) := `(dfin''.fs).subst (dfin.reflect n)
-- -- /- errors all over---why doesn't reflect like universe parameters? -/
-- -- meta instance dfin'.reflect : ∀ {n}, has_reflect (dfin' n)
-- -- | _ fz := `(fz)
-- -- | _ (fs n) := `(fs).subst (dfin'.reflect n)
-- end sample4
-- section reflect_preterm
-- /- Language with a single constant symbol -/
-- inductive L_pt_functions : ℕ → Type
-- | pt : L_pt_functions 0
-- def L_pt : Language.{0} := ⟨L_pt_functions, λ _, empty⟩
-- def pt_preterm : preterm L_pt 0 := preterm.func L_pt_functions.pt
-- meta def pt_preterm_reflected : expr :=
-- expr.mk_app (expr.const `preterm.func [level.zero]) [ (expr.const `L_pt list.nil), `(0), (expr.const `L_pt_functions.pt list.nil)]
-- set_option trace.app_builder true
-- -- meta def pt_preterm_reflected' : expr := by tactic.mk_app "preterm.func" [(expr.const `L_pt []), `(0), (expr.const `L_pt_functions.pt [])]
-- #check tactic.mk_app
-- meta def pt_preterm_reflected'' : tactic expr :=
-- tactic.to_expr ```(preterm.func L_pt_functions.pt : preterm L_pt 0)
-- def pt_preterm' : preterm L_pt 0 := by pt_preterm_reflected'' >>= tactic.exact
-- -- def pt_preterm' : preterm L_pt 0 := by tactic.exact pt_preterm_reflected
-- example : pt_preterm = pt_preterm' := rfl
-- -- infer type failed, incorrect number of universe levels
-- -- want: example : pt_preterm = pt_preterm' := rfl
-- end reflect_preterm
-- namespace hewwo
-- section reflect_preterm2
-- def L_pt.pt' : L_pt.functions 0 := L_pt_functions.pt
-- #reduce (by apply_instance : reflected L_pt.pt')
-- -- `(L_pt.pt')
-- meta def pt_preterm_reflected : tactic expr :=
-- tactic.mk_app ``preterm.func [`(L_pt.pt')]
-- def pt_preterm' : preterm L_pt 0 := by pt_preterm_reflected >>= tactic.exact
-- #eval tactic.trace (@expr.to_raw_fmt tt `(L_pt.pt'))
-- #check reflect
-- end reflect_preterm2
-- end hewwo
-- section reflect_preterm3
-- inductive L_pt_func_functions : ℕ → Type
-- | pt : L_pt_func_functions 0
-- | foo : L_pt_func_functions 1
-- open L_pt_func_functions
-- def L_pt_func : Language.{0} :=
-- ⟨L_pt_func_functions, λ _, ulift empty⟩
-- -- def foo_pt_term : preterm L_pt_func 0 :=
-- -- preterm.app (preterm.func L_pt_func_functions.foo) (preterm.func L_pt_func_functions.pt)
-- -- def foo_pt_term_reflected : expr :=
-- -- begin
-- -- tactic.mk_app ``preterm.func [(by tactic.mk_app `preterm.func [`(L_pt_func_functions.foo)]), (by tactic.mk_app `preterm.func [`(L_pt_func_functions.pt)])]
-- -- end
-- -- def foo' : preterm L_pt_func 1 := preterm.func L_pt_func_functions.foo
-- -- #reduce (by apply_instance : reflected L_pt_func_functions.foo)
-- set_option trace.app_builder true
-- def my_foo : L_pt_func.functions 1 := L_pt_func_functions.foo
-- def my_pt : L_pt_func.functions 0 := L_pt_func_functions.pt
-- -- meta def foo_pt_term_reflected : tactic expr := tactic.mk_app ``preterm.func [`()]
-- meta def foo_pt_term_reflected' : tactic expr :=
-- do e₁ <- tactic.mk_app ``preterm.func [`(my_foo)],
-- e₂ <- tactic.mk_app ``preterm.func [`(my_pt)],
-- tactic.mk_app ``preterm.app [e₁, e₂]
-- -- #print foo_pt_term_reflected'
-- -- meta def bar : tactic expr :=
-- -- tactic.mk_app ``preterm.func [`(foo_mask)]
-- set_option trace.app_builder true
-- def foo_pt_term_reflected : preterm L_pt_func 0 := by (foo_pt_term_reflected' >>= tactic.exact)
-- -- #reduce foo_pt_term_reflected
-- end reflect_preterm3
|
d7826689d03cf28e83518764cd0987871ada0bbe | ece1fcd81204f318535500cde1f3c6433de98f46 | /src/abstract_V_and_I.lean | 8228668ba0e6ae32290cf921f71140d0c3f83c84 | [
"Apache-2.0"
] | permissive | stjordanis/M4P33 | ab5d90bda269428aee16885dbd33f0d21d7d2f79 | d3b56421fcb03b935d9012e5a5b35e1c1ad0b0b4 | refs/heads/master | 1,607,921,471,294 | 1,579,298,081,000 | 1,579,298,081,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,257 | lean | /-
Thoughts about how much of the 𝕍 and 𝕀 theory
goes through abstractly.
-/
-- This is set theory. But we want to do some type theory as well.
-- Types are a convenient way of gathering mathematical objects
-- into well-defined collections, such as rings.
import data.type.basic
-- We want to prove that the images of 𝕍 and 𝕀 are in natural
-- bijection with each other so we need the general theory
-- of bijections
import data.equiv.basic
-- the lattice structure on subsets (infinite unions etc)
import data.set.lattice
universes u v -- set theorists can set these both to be 0.
-- (R : Type 0) means "let R be a set".
-- Let $R$ be a set.
-- For example $R$ could be the ring `k[X₁,…,Xₙ]`
variables (R : Type u)
-- When we're talking about 𝕍 and 𝕀, we will not mention R as part
-- of the notation even though it is playing a role
{R}
-- Let $\mathbb{A}^n$ be another set.
variables (A : Type v)
-- Similarly we will not explicitly mention A most of the time
{A}
-- Let $P$ be a way of getting a true/false statement from a pair of
-- elements $f ∈ R$ and $x ∈ \mathbb{A}^n$. For example $P(f,x)$ can be
-- the statement that $f(x) = 0$. You can think of $P$ as being a subset
-- of $R\times \mathbb{A}^n$ if you like.
variable (P : R → A → Prop)
include P
-- Let $\mathbb{V}$, a function from subsets of $R$ to subsets of
-- $\mathbb{A}^n$, and $\mathbb{I}$, a function from subsets of $\mathbb{A}^n$
-- to subsets of $R$, be defined in the usual way.
-- One can think of 𝕍(S) as being the largest U such that S × U ⊆ P,
-- and 𝕀(U) as being the largest S such that S × U ⊆ P.
-- The main theorem we will prove today is
-- $\mathbf{theorem} For all $S\subseteq R$, $\V(\I(\V(S)))=\V(S)$, possibly
-- assuming some irrelevant extra hypotheses, such as the assumption
-- that $k$ is algebraically closed, or $S$ is an ideal.
def 𝕍_ (S : set R) : set A :=
{x : A | ∀ f ∈ S, P f x}
notation `𝕍`:max := 𝕍_ (by exact P)
-- Type of 𝕍_ is Π {R : Type*} {A : Type*}, (R → A → Prop) → set R → set A
-- i.e. (R → A → Prop) → (R → Prop) → (A → Prop)
def 𝕀_ (X : set A) : set R :=
{f : R | ∀ x ∈ X, P f x}
notation `𝕀`:max := 𝕀_ (by exact P)
-- restate definitions
lemma mem_𝕍_iff (S : set R) (x : A) : x ∈ 𝕍 S ↔ ∀ f ∈ S, P f x := iff.rfl
lemma mem_𝕀_iff (V : set A) (f : R) : f ∈ 𝕀 V ↔ ∀ x ∈ V, P f x := iff.rfl
-- we're going to be doing set theory
open set
/-- 𝕍(∅) is everything. -/
lemma 𝕍_empty : 𝕍 ∅ = univ :=
begin
-- It suffices to show that every x of type A is in 𝕍 ∅
rw eq_univ_iff_forall,
-- so let x be in A
intro x,
-- we need to show that every f in the empty set satisfies (f,x) ∈ P
rw mem_𝕍_iff,
-- so say f is in the empty set
intros f hf,
-- but there are no elements in the empty set so we must be done
cases hf,
end
/-- 𝕀(∅) is everything -/
lemma 𝕀_empty : 𝕀 ∅ = univ :=
-- computer science proof
eq_univ_iff_forall.2 $ λ x f, by rintro ⟨⟩
-- 𝕍 is inclusion-reversing
lemma 𝕍_antimono (S T : set R) (h : S ⊆ T) : 𝕍 T ⊆ 𝕍 S :=
begin
-- say x ∈ 𝕍(T)
intros x hx,
-- and s in S,
intros s hs,
-- We want to show P(s,x) is true, or (s,x) ∈ P or s(x) = 0 or however
-- you think about it.
-- Because x ∈ 𝕍(T), we know P(t,x) is true for all t ∈ T,
-- so it suffices to prove s ∈ T
apply hx,
-- But S ⊆ T
apply h,
-- and s ∈ S so we're done
exact hs
end
-- Here is how a computer scientist would write this proof:
lemma 𝕍_antimono' (S T : set R) (h : S ⊆ T) : 𝕍 T ⊆ 𝕍 S :=
λ x hx s hs, hx _ (h hs)
-- The advantage of writing it this way is that it also proves the converse!
lemma 𝕀_antimono (U V : set A) (h : U ⊆ V) : 𝕀 V ⊆ 𝕀 U :=
λ x hx s hs, hx _ (h hs)
-- Exercise: prove 𝕀_antimono the way a mathematician would, using only
-- intros, apply and exact. Need help? Try the natural number game.
lemma 𝕍_union (S T : set R) : 𝕍 (S ∪ T) = 𝕍 S ∩ 𝕍 T :=
begin
-- we prove both inclusions
apply set.subset.antisymm,
{ -- say x ∈ 𝕍(S ∪ T)
intros x hx,
-- we need to prove x ∈ 𝕍 S and x ∈ 𝕍 T
split,
-- both of these follow easily from 𝕍_antimono
-- exact 𝕍_antimono _ _ _ _ hx, -- TODO(kmb)
-- why is the wrong underscore marked in red??
exact 𝕍_antimono _ _ _ (subset_union_left _ _) hx,
exact 𝕍_antimono _ _ _ (subset_union_right _ _) hx,
},
{ -- say x ∈ 𝕍(S) ∩ 𝕍(T)
rintros x ⟨hxS, hxT⟩,
-- we need to prove that for all f ∈ S ∪ T, f(x) = 0
intros f hf,
-- well f is either in S or T (or both)
cases hf,
{ -- and if f ∈ S then we're done because x ∈ 𝕍(S)
exact hxS _ hf
},
{ -- whereas if f ∈ T then we're done because x ∈ 𝕍(T)
exact hxT _ hf
}
}
end
-- We prove this one in a slightly different way.
lemma 𝕀_union (W X : set A) : 𝕀 (W ∪ X) = 𝕀 W ∩ 𝕀 X :=
begin
-- By extensionality, two sets are equal iff they have the same elements
ext x,
-- To be in the intersection of two sets just means being in both of them
show _ ↔ x ∈ 𝕀 W ∧ x ∈ 𝕀 X,
-- By the definition of 𝕀,...
rw [mem_𝕀_iff, mem_𝕀_iff, mem_𝕀_iff],
--- we have to prove that
-- W ∪ X ⊆ {f : f(x) = 0} iff W ⊆ {f : f(x) = 0} and X ⊆ {f : f(x) = 0}
show W ∪ X ⊆ _ ↔ W ⊆ _ ∧ X ⊆ _, -- the underscore just means "guess the set"
-- We prove the iff by proving both directions separately
split,
{ -- Here we prove W ∪ X ⊆ Z → W ⊆ Z ∧ X ⊆ Z
intro hWX,
split,
refine set.subset.trans _ hWX, apply subset_union_left,
refine set.subset.trans _ hWX, apply subset_union_right,
},
{ -- and here we prove W ⊆ Z ∧ X ⊆ Z → W ∪ X ⊆ Z
rintros ⟨hW, hX⟩, apply union_subset; assumption
}
end
lemma 𝕍_Union (ι : Type*) (S : ι → set R) : 𝕍 (⋃ i, S i) = ⋂ i, 𝕍 (S i) :=
begin
-- two sets are equal iff they have the same elements
ext x,
-- To be in the intersection of a bunch of sets just means
-- being in all of them
rw mem_Inter,
-- By the definition of 𝕍,
rw [mem_𝕍_iff],
show (∀ (f : R), (f ∈ ⋃ (i : ι), S i) → P f x) ↔ ∀ (i : ι), ∀ f ∈ S i, P f x,
-- Now prove both inclusions separately
split,
intros,
apply a,
rw mem_Union,
use i,
assumption,
intros h f hf,
rw mem_Union at hf,
cases hf with i hi,
apply h i,
assumption,
end
-- an AI can find a proof of this too:
lemma 𝕀_Union (ι : Type*) (J : ι → set A) : 𝕀 (⋃ i, J i) = ⋂ i, 𝕀 (J i) :=
begin
ext,
simp [𝕀_],
tauto,
end
lemma 𝕍𝕀_mono (U V : set A) (h : U ⊆ V) : 𝕍 (𝕀 U) ⊆ 𝕍 (𝕀 V) :=
begin
-- 𝕍 is anti-monotonic
apply 𝕍_antimono,
-- and 𝕀 is too
apply 𝕀_antimono,
-- so we just have to prove U ⊆ V, which is an assumption
exact h
end
-- computer science proof of the other direction
lemma 𝕀𝕍_mono (S T : set R) (h : S ⊆ T) : 𝕀 (𝕍 S) ⊆ 𝕀 (𝕍 T) :=
𝕀_antimono P _ _ (𝕍_antimono P _ _ h)
-- During the lecture today (17/01/20), it was pointed out that 𝕍(S) was the
-- largest U such that S × U was a subset of P, and 𝕀(U) was the largest S
-- such that S × U was a subset of P. This geometric way of thinking
-- about things makes the next lemma trivial. Can you understand the Lean proof?
/-- U ⊆ 𝕍(𝕀(U)) -/
lemma sub_𝕍𝕀 (U : set A) : U ⊆ 𝕍 (𝕀 U) :=
begin
intros x hx,
rw mem_𝕍_iff,
intros f hf,
rw mem_𝕀_iff at hf,
apply hf,
exact hx,
end
-- Because the proofs of sub_𝕍𝕀 and sub_𝕀𝕍 are basically
-- the same, it might come as no surprise to see that you
-- can prove one of them using the other one! The trick is
-- to make sure you allow quantification over all R and A
-- so you can switch them around.
/-- S ⊆ 𝕀(𝕍(S)) -/
lemma sub_𝕀𝕍 (S : set R) : S ⊆ 𝕀 (𝕍 S) :=
sub_𝕍𝕀 _ _
-- the big theorem
lemma 𝕍𝕀𝕍_eq_𝕍 (S : set R) : 𝕍 (𝕀 (𝕍 S)) = 𝕍 S :=
begin
apply set.subset.antisymm,
{ apply 𝕍_antimono,
apply sub_𝕀𝕍
},
{ apply sub_𝕍𝕀,
}
end
-- the same theorem again (permute R and A)
lemma 𝕀𝕍𝕀_eq_𝕀 (V : set A) : (𝕀 (𝕍 (𝕀 V))) = 𝕀 V :=
𝕍𝕀𝕍_eq_𝕍 _ V -- same proof but with a different P
open set
-- this final proof is written in a very computer-science way
/-- The images of 𝕍 and of 𝕀 are naturally in bijection -/
lemma not_the_nullstellensatz : {V // ∃ J, 𝕍 J = V} ≃ {I // ∃ V, 𝕀 V = I} :=
{ to_fun := λ V, ⟨𝕀 (V.1), V, rfl⟩,
inv_fun := λ I, ⟨𝕍 I.1, I, rfl⟩,
left_inv := begin
rintro ⟨V, J, hJ⟩,
rw subtype.ext,
change 𝕍 (𝕀 V) = V,
rw ←hJ,
refine 𝕍𝕀𝕍_eq_𝕍 _ _,
end,
right_inv := begin
rintro ⟨J, V, hV⟩,
rw subtype.ext,
change 𝕀 (𝕍 J) = J,
rw ←hV,
refine 𝕀𝕍𝕀_eq_𝕀 _ _,
end
}
-- The Nullstellensatz says that the image of 𝕀 is precisely the
-- radical ideals. One inclusion is clear (which?) |
f429f879d360a7a142de5b24359d4a0b924122a2 | 2eab05920d6eeb06665e1a6df77b3157354316ad | /src/analysis/calculus/deriv.lean | 0dd18d0c7a51db3aa3dd1a52b7175a04cb4f9ec2 | [
"Apache-2.0"
] | permissive | ayush1801/mathlib | 78949b9f789f488148142221606bf15c02b960d2 | ce164e28f262acbb3de6281b3b03660a9f744e3c | refs/heads/master | 1,692,886,907,941 | 1,635,270,866,000 | 1,635,270,866,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 85,897 | lean | /-
Copyright (c) 2019 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Sébastien Gouëzel
-/
import analysis.calculus.fderiv
import data.polynomial.derivative
/-!
# One-dimensional derivatives
This file defines the derivative of a function `f : 𝕜 → F` where `𝕜` is a
normed field and `F` is a normed space over this field. The derivative of
such a function `f` at a point `x` is given by an element `f' : F`.
The theory is developed analogously to the [Fréchet
derivatives](./fderiv.lean). We first introduce predicates defined in terms
of the corresponding predicates for Fréchet derivatives:
- `has_deriv_at_filter f f' x L` states that the function `f` has the
derivative `f'` at the point `x` as `x` goes along the filter `L`.
- `has_deriv_within_at f f' s x` states that the function `f` has the
derivative `f'` at the point `x` within the subset `s`.
- `has_deriv_at f f' x` states that the function `f` has the derivative `f'`
at the point `x`.
- `has_strict_deriv_at f f' x` states that the function `f` has the derivative `f'`
at the point `x` in the sense of strict differentiability, i.e.,
`f y - f z = (y - z) • f' + o (y - z)` as `y, z → x`.
For the last two notions we also define a functional version:
- `deriv_within f s x` is a derivative of `f` at `x` within `s`. If the
derivative does not exist, then `deriv_within f s x` equals zero.
- `deriv f x` is a derivative of `f` at `x`. If the derivative does not
exist, then `deriv f x` equals zero.
The theorems `fderiv_within_deriv_within` and `fderiv_deriv` show that the
one-dimensional derivatives coincide with the general Fréchet derivatives.
We also show the existence and compute the derivatives of:
- constants
- the identity function
- linear maps
- addition
- sum of finitely many functions
- negation
- subtraction
- multiplication
- inverse `x → x⁻¹`
- multiplication of two functions in `𝕜 → 𝕜`
- multiplication of a function in `𝕜 → 𝕜` and of a function in `𝕜 → E`
- composition of a function in `𝕜 → F` with a function in `𝕜 → 𝕜`
- composition of a function in `F → E` with a function in `𝕜 → F`
- inverse function (assuming that it exists; the inverse function theorem is in `inverse.lean`)
- division
- polynomials
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.
We set up the simplifier so that it can compute the derivative of simple functions. For instance,
```lean
example (x : ℝ) : deriv (λ x, cos (sin x) * exp x) x = (cos(sin(x))-sin(sin(x))*cos(x))*exp(x) :=
by { simp, ring }
```
## Implementation notes
Most of the theorems are direct restatements of the corresponding theorems
for Fréchet derivatives.
The strategy to construct simp lemmas that give the simplifier the possibility to compute
derivatives is the same as the one for differentiability statements, as explained in `fderiv.lean`.
See the explanations there.
-/
universes u v w
noncomputable theory
open_locale classical topological_space big_operators filter ennreal
open filter asymptotics set
open continuous_linear_map (smul_right smul_right_one_eq_iff)
variables {𝕜 : Type u} [nondiscrete_normed_field 𝕜]
section
variables {F : Type v} [normed_group F] [normed_space 𝕜 F]
variables {E : Type w} [normed_group E] [normed_space 𝕜 E]
/--
`f` has the derivative `f'` at the point `x` as `x` goes along the filter `L`.
That is, `f x' = f x + (x' - x) • f' + o(x' - x)` where `x'` converges along the filter `L`.
-/
def has_deriv_at_filter (f : 𝕜 → F) (f' : F) (x : 𝕜) (L : filter 𝕜) :=
has_fderiv_at_filter f (smul_right (1 : 𝕜 →L[𝕜] 𝕜) f') x L
/--
`f` has the derivative `f'` at the point `x` within the subset `s`.
That is, `f x' = f x + (x' - x) • f' + o(x' - x)` where `x'` converges to `x` inside `s`.
-/
def has_deriv_within_at (f : 𝕜 → F) (f' : F) (s : set 𝕜) (x : 𝕜) :=
has_deriv_at_filter f f' x (𝓝[s] x)
/--
`f` has the derivative `f'` at the point `x`.
That is, `f x' = f x + (x' - x) • f' + o(x' - x)` where `x'` converges to `x`.
-/
def has_deriv_at (f : 𝕜 → F) (f' : F) (x : 𝕜) :=
has_deriv_at_filter f f' x (𝓝 x)
/-- `f` has the derivative `f'` at the point `x` in the sense of strict differentiability.
That is, `f y - f z = (y - z) • f' + o(y - z)` as `y, z → x`. -/
def has_strict_deriv_at (f : 𝕜 → F) (f' : F) (x : 𝕜) :=
has_strict_fderiv_at f (smul_right (1 : 𝕜 →L[𝕜] 𝕜) f') x
/--
Derivative of `f` at the point `x` within the set `s`, if it exists. Zero otherwise.
If the derivative exists (i.e., `∃ f', has_deriv_within_at f f' s x`), then
`f x' = f x + (x' - x) • deriv_within f s x + o(x' - x)` where `x'` converges to `x` inside `s`.
-/
def deriv_within (f : 𝕜 → F) (s : set 𝕜) (x : 𝕜) :=
fderiv_within 𝕜 f s x 1
/--
Derivative of `f` at the point `x`, if it exists. Zero otherwise.
If the derivative exists (i.e., `∃ f', has_deriv_at f f' x`), then
`f x' = f x + (x' - x) • deriv f x + o(x' - x)` where `x'` converges to `x`.
-/
def deriv (f : 𝕜 → F) (x : 𝕜) :=
fderiv 𝕜 f x 1
variables {f f₀ f₁ g : 𝕜 → F}
variables {f' f₀' f₁' g' : F}
variables {x : 𝕜}
variables {s t : set 𝕜}
variables {L L₁ L₂ : filter 𝕜}
/-- Expressing `has_fderiv_at_filter f f' x L` in terms of `has_deriv_at_filter` -/
lemma has_fderiv_at_filter_iff_has_deriv_at_filter {f' : 𝕜 →L[𝕜] F} :
has_fderiv_at_filter f f' x L ↔ has_deriv_at_filter f (f' 1) x L :=
by simp [has_deriv_at_filter]
lemma has_fderiv_at_filter.has_deriv_at_filter {f' : 𝕜 →L[𝕜] F} :
has_fderiv_at_filter f f' x L → has_deriv_at_filter f (f' 1) x L :=
has_fderiv_at_filter_iff_has_deriv_at_filter.mp
/-- Expressing `has_fderiv_within_at f f' s x` in terms of `has_deriv_within_at` -/
lemma has_fderiv_within_at_iff_has_deriv_within_at {f' : 𝕜 →L[𝕜] F} :
has_fderiv_within_at f f' s x ↔ has_deriv_within_at f (f' 1) s x :=
has_fderiv_at_filter_iff_has_deriv_at_filter
/-- Expressing `has_deriv_within_at f f' s x` in terms of `has_fderiv_within_at` -/
lemma has_deriv_within_at_iff_has_fderiv_within_at {f' : F} :
has_deriv_within_at f f' s x ↔
has_fderiv_within_at f (smul_right (1 : 𝕜 →L[𝕜] 𝕜) f') s x :=
iff.rfl
lemma has_fderiv_within_at.has_deriv_within_at {f' : 𝕜 →L[𝕜] F} :
has_fderiv_within_at f f' s x → has_deriv_within_at f (f' 1) s x :=
has_fderiv_within_at_iff_has_deriv_within_at.mp
lemma has_deriv_within_at.has_fderiv_within_at {f' : F} :
has_deriv_within_at f f' s x → has_fderiv_within_at f (smul_right (1 : 𝕜 →L[𝕜] 𝕜) f') s x :=
has_deriv_within_at_iff_has_fderiv_within_at.mp
/-- Expressing `has_fderiv_at f f' x` in terms of `has_deriv_at` -/
lemma has_fderiv_at_iff_has_deriv_at {f' : 𝕜 →L[𝕜] F} :
has_fderiv_at f f' x ↔ has_deriv_at f (f' 1) x :=
has_fderiv_at_filter_iff_has_deriv_at_filter
lemma has_fderiv_at.has_deriv_at {f' : 𝕜 →L[𝕜] F} :
has_fderiv_at f f' x → has_deriv_at f (f' 1) x :=
has_fderiv_at_iff_has_deriv_at.mp
lemma has_strict_fderiv_at_iff_has_strict_deriv_at {f' : 𝕜 →L[𝕜] F} :
has_strict_fderiv_at f f' x ↔ has_strict_deriv_at f (f' 1) x :=
by simp [has_strict_deriv_at, has_strict_fderiv_at]
protected lemma has_strict_fderiv_at.has_strict_deriv_at {f' : 𝕜 →L[𝕜] F} :
has_strict_fderiv_at f f' x → has_strict_deriv_at f (f' 1) x :=
has_strict_fderiv_at_iff_has_strict_deriv_at.mp
lemma has_strict_deriv_at_iff_has_strict_fderiv_at :
has_strict_deriv_at f f' x ↔ has_strict_fderiv_at f (smul_right (1 : 𝕜 →L[𝕜] 𝕜) f') x :=
iff.rfl
alias has_strict_deriv_at_iff_has_strict_fderiv_at ↔ has_strict_deriv_at.has_strict_fderiv_at _
/-- Expressing `has_deriv_at f f' x` in terms of `has_fderiv_at` -/
lemma has_deriv_at_iff_has_fderiv_at {f' : F} :
has_deriv_at f f' x ↔
has_fderiv_at f (smul_right (1 : 𝕜 →L[𝕜] 𝕜) f') x :=
iff.rfl
alias has_deriv_at_iff_has_fderiv_at ↔ has_deriv_at.has_fderiv_at _
lemma deriv_within_zero_of_not_differentiable_within_at
(h : ¬ differentiable_within_at 𝕜 f s x) : deriv_within f s x = 0 :=
by { unfold deriv_within, rw fderiv_within_zero_of_not_differentiable_within_at, simp, assumption }
lemma deriv_zero_of_not_differentiable_at (h : ¬ differentiable_at 𝕜 f x) : deriv f x = 0 :=
by { unfold deriv, rw fderiv_zero_of_not_differentiable_at, simp, assumption }
theorem unique_diff_within_at.eq_deriv (s : set 𝕜) (H : unique_diff_within_at 𝕜 s x)
(h : has_deriv_within_at f f' s x) (h₁ : has_deriv_within_at f f₁' s x) : f' = f₁' :=
smul_right_one_eq_iff.mp $ unique_diff_within_at.eq H h h₁
theorem has_deriv_at_filter_iff_tendsto :
has_deriv_at_filter f f' x L ↔
tendsto (λ x' : 𝕜, ∥x' - x∥⁻¹ * ∥f x' - f x - (x' - x) • f'∥) L (𝓝 0) :=
has_fderiv_at_filter_iff_tendsto
theorem has_deriv_within_at_iff_tendsto : has_deriv_within_at f f' s x ↔
tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - (x' - x) • f'∥) (𝓝[s] x) (𝓝 0) :=
has_fderiv_at_filter_iff_tendsto
theorem has_deriv_at_iff_tendsto : has_deriv_at f f' x ↔
tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - (x' - x) • f'∥) (𝓝 x) (𝓝 0) :=
has_fderiv_at_filter_iff_tendsto
theorem has_strict_deriv_at.has_deriv_at (h : has_strict_deriv_at f f' x) :
has_deriv_at f f' x :=
h.has_fderiv_at
/-- If the domain has dimension one, then Fréchet derivative is equivalent to the classical
definition with a limit. In this version we have to take the limit along the subset `-{x}`,
because for `y=x` the slope equals zero due to the convention `0⁻¹=0`. -/
lemma has_deriv_at_filter_iff_tendsto_slope {x : 𝕜} {L : filter 𝕜} :
has_deriv_at_filter f f' x L ↔
tendsto (λ y, (y - x)⁻¹ • (f y - f x)) (L ⊓ 𝓟 {x}ᶜ) (𝓝 f') :=
begin
conv_lhs { simp only [has_deriv_at_filter_iff_tendsto, (normed_field.norm_inv _).symm,
(norm_smul _ _).symm, tendsto_zero_iff_norm_tendsto_zero.symm] },
conv_rhs { rw [← nhds_translation_sub f', tendsto_comap_iff] },
refine (tendsto_inf_principal_nhds_iff_of_forall_eq $ by simp).symm.trans (tendsto_congr' _),
refine (eventually_principal.2 $ λ z hz, _).filter_mono inf_le_right,
simp only [(∘)],
rw [smul_sub, ← mul_smul, inv_mul_cancel (sub_ne_zero.2 hz), one_smul]
end
lemma has_deriv_within_at_iff_tendsto_slope :
has_deriv_within_at f f' s x ↔
tendsto (λ y, (y - x)⁻¹ • (f y - f x)) (𝓝[s \ {x}] x) (𝓝 f') :=
begin
simp only [has_deriv_within_at, nhds_within, diff_eq, inf_assoc.symm, inf_principal.symm],
exact has_deriv_at_filter_iff_tendsto_slope
end
lemma has_deriv_within_at_iff_tendsto_slope' (hs : x ∉ s) :
has_deriv_within_at f f' s x ↔
tendsto (λ y, (y - x)⁻¹ • (f y - f x)) (𝓝[s] x) (𝓝 f') :=
begin
convert ← has_deriv_within_at_iff_tendsto_slope,
exact diff_singleton_eq_self hs
end
lemma has_deriv_at_iff_tendsto_slope :
has_deriv_at f f' x ↔
tendsto (λ y, (y - x)⁻¹ • (f y - f x)) (𝓝[{x}ᶜ] x) (𝓝 f') :=
has_deriv_at_filter_iff_tendsto_slope
theorem has_deriv_within_at_congr_set {s t u : set 𝕜}
(hu : u ∈ 𝓝 x) (h : s ∩ u = t ∩ u) :
has_deriv_within_at f f' s x ↔ has_deriv_within_at f f' t x :=
by simp_rw [has_deriv_within_at, nhds_within_eq_nhds_within' hu h]
alias has_deriv_within_at_congr_set ↔ has_deriv_within_at.congr_set _
@[simp] lemma has_deriv_within_at_diff_singleton :
has_deriv_within_at f f' (s \ {x}) x ↔ has_deriv_within_at f f' s x :=
by simp only [has_deriv_within_at_iff_tendsto_slope, sdiff_idem]
@[simp] lemma has_deriv_within_at_Ioi_iff_Ici [partial_order 𝕜] :
has_deriv_within_at f f' (Ioi x) x ↔ has_deriv_within_at f f' (Ici x) x :=
by rw [← Ici_diff_left, has_deriv_within_at_diff_singleton]
alias has_deriv_within_at_Ioi_iff_Ici ↔
has_deriv_within_at.Ici_of_Ioi has_deriv_within_at.Ioi_of_Ici
@[simp] lemma has_deriv_within_at_Iio_iff_Iic [partial_order 𝕜] :
has_deriv_within_at f f' (Iio x) x ↔ has_deriv_within_at f f' (Iic x) x :=
by rw [← Iic_diff_right, has_deriv_within_at_diff_singleton]
alias has_deriv_within_at_Iio_iff_Iic ↔
has_deriv_within_at.Iic_of_Iio has_deriv_within_at.Iio_of_Iic
theorem has_deriv_within_at.Ioi_iff_Ioo [linear_order 𝕜] [order_closed_topology 𝕜] {x y : 𝕜}
(h : x < y) :
has_deriv_within_at f f' (Ioo x y) x ↔ has_deriv_within_at f f' (Ioi x) x :=
has_deriv_within_at_congr_set (is_open_Iio.mem_nhds h) $
by { rw [Ioi_inter_Iio, inter_eq_left_iff_subset], exact Ioo_subset_Iio_self }
alias has_deriv_within_at.Ioi_iff_Ioo ↔
has_deriv_within_at.Ioi_of_Ioo has_deriv_within_at.Ioo_of_Ioi
theorem has_deriv_at_iff_is_o_nhds_zero : has_deriv_at f f' x ↔
is_o (λh, f (x + h) - f x - h • f') (λh, h) (𝓝 0) :=
has_fderiv_at_iff_is_o_nhds_zero
theorem has_deriv_at_filter.mono (h : has_deriv_at_filter f f' x L₂) (hst : L₁ ≤ L₂) :
has_deriv_at_filter f f' x L₁ :=
has_fderiv_at_filter.mono h hst
theorem has_deriv_within_at.mono (h : has_deriv_within_at f f' t x) (hst : s ⊆ t) :
has_deriv_within_at f f' s x :=
has_fderiv_within_at.mono h hst
theorem has_deriv_at.has_deriv_at_filter (h : has_deriv_at f f' x) (hL : L ≤ 𝓝 x) :
has_deriv_at_filter f f' x L :=
has_fderiv_at.has_fderiv_at_filter h hL
theorem has_deriv_at.has_deriv_within_at
(h : has_deriv_at f f' x) : has_deriv_within_at f f' s x :=
has_fderiv_at.has_fderiv_within_at h
lemma has_deriv_within_at.differentiable_within_at (h : has_deriv_within_at f f' s x) :
differentiable_within_at 𝕜 f s x :=
has_fderiv_within_at.differentiable_within_at h
lemma has_deriv_at.differentiable_at (h : has_deriv_at f f' x) : differentiable_at 𝕜 f x :=
has_fderiv_at.differentiable_at h
@[simp] lemma has_deriv_within_at_univ : has_deriv_within_at f f' univ x ↔ has_deriv_at f f' x :=
has_fderiv_within_at_univ
theorem has_deriv_at.unique
(h₀ : has_deriv_at f f₀' x) (h₁ : has_deriv_at f f₁' x) : f₀' = f₁' :=
smul_right_one_eq_iff.mp $ h₀.has_fderiv_at.unique h₁
lemma has_deriv_within_at_inter' (h : t ∈ 𝓝[s] x) :
has_deriv_within_at f f' (s ∩ t) x ↔ has_deriv_within_at f f' s x :=
has_fderiv_within_at_inter' h
lemma has_deriv_within_at_inter (h : t ∈ 𝓝 x) :
has_deriv_within_at f f' (s ∩ t) x ↔ has_deriv_within_at f f' s x :=
has_fderiv_within_at_inter h
lemma has_deriv_within_at.union (hs : has_deriv_within_at f f' s x)
(ht : has_deriv_within_at f f' t x) :
has_deriv_within_at f f' (s ∪ t) x :=
begin
simp only [has_deriv_within_at, nhds_within_union],
exact hs.join ht,
end
lemma has_deriv_within_at.nhds_within (h : has_deriv_within_at f f' s x)
(ht : s ∈ 𝓝[t] x) : has_deriv_within_at f f' t x :=
(has_deriv_within_at_inter' ht).1 (h.mono (inter_subset_right _ _))
lemma has_deriv_within_at.has_deriv_at (h : has_deriv_within_at f f' s x) (hs : s ∈ 𝓝 x) :
has_deriv_at f f' x :=
has_fderiv_within_at.has_fderiv_at h hs
lemma differentiable_within_at.has_deriv_within_at (h : differentiable_within_at 𝕜 f s x) :
has_deriv_within_at f (deriv_within f s x) s x :=
h.has_fderiv_within_at.has_deriv_within_at
lemma differentiable_at.has_deriv_at (h : differentiable_at 𝕜 f x) : has_deriv_at f (deriv f x) x :=
h.has_fderiv_at.has_deriv_at
lemma differentiable_on.has_deriv_at (h : differentiable_on 𝕜 f s) (hs : s ∈ 𝓝 x) :
has_deriv_at f (deriv f x) x :=
(h.has_fderiv_at hs).has_deriv_at
lemma has_deriv_at.deriv (h : has_deriv_at f f' x) : deriv f x = f' :=
h.differentiable_at.has_deriv_at.unique h
lemma has_deriv_within_at.deriv_within
(h : has_deriv_within_at f f' s x) (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within f s x = f' :=
hxs.eq_deriv _ h.differentiable_within_at.has_deriv_within_at h
lemma fderiv_within_deriv_within : (fderiv_within 𝕜 f s x : 𝕜 → F) 1 = deriv_within f s x :=
rfl
lemma deriv_within_fderiv_within :
smul_right (1 : 𝕜 →L[𝕜] 𝕜) (deriv_within f s x) = fderiv_within 𝕜 f s x :=
by simp [deriv_within]
lemma fderiv_deriv : (fderiv 𝕜 f x : 𝕜 → F) 1 = deriv f x :=
rfl
lemma deriv_fderiv :
smul_right (1 : 𝕜 →L[𝕜] 𝕜) (deriv f x) = fderiv 𝕜 f x :=
by simp [deriv]
lemma differentiable_at.deriv_within (h : differentiable_at 𝕜 f x)
(hxs : unique_diff_within_at 𝕜 s x) : deriv_within f s x = deriv f x :=
by { unfold deriv_within deriv, rw h.fderiv_within hxs }
lemma deriv_within_subset (st : s ⊆ t) (ht : unique_diff_within_at 𝕜 s x)
(h : differentiable_within_at 𝕜 f t x) :
deriv_within f s x = deriv_within f t x :=
((differentiable_within_at.has_deriv_within_at h).mono st).deriv_within ht
@[simp] lemma deriv_within_univ : deriv_within f univ = deriv f :=
by { ext, unfold deriv_within deriv, rw fderiv_within_univ }
lemma deriv_within_inter (ht : t ∈ 𝓝 x) (hs : unique_diff_within_at 𝕜 s x) :
deriv_within f (s ∩ t) x = deriv_within f s x :=
by { unfold deriv_within, rw fderiv_within_inter ht hs }
lemma deriv_within_of_open (hs : is_open s) (hx : x ∈ s) :
deriv_within f s x = deriv f x :=
by { unfold deriv_within, rw fderiv_within_of_open hs hx, refl }
section congr
/-! ### Congruence properties of derivatives -/
theorem filter.eventually_eq.has_deriv_at_filter_iff
(h₀ : f₀ =ᶠ[L] f₁) (hx : f₀ x = f₁ x) (h₁ : f₀' = f₁') :
has_deriv_at_filter f₀ f₀' x L ↔ has_deriv_at_filter f₁ f₁' x L :=
h₀.has_fderiv_at_filter_iff hx (by simp [h₁])
lemma has_deriv_at_filter.congr_of_eventually_eq (h : has_deriv_at_filter f f' x L)
(hL : f₁ =ᶠ[L] f) (hx : f₁ x = f x) : has_deriv_at_filter f₁ f' x L :=
by rwa hL.has_deriv_at_filter_iff hx rfl
lemma has_deriv_within_at.congr_mono (h : has_deriv_within_at f f' s x) (ht : ∀x ∈ t, f₁ x = f x)
(hx : f₁ x = f x) (h₁ : t ⊆ s) : has_deriv_within_at f₁ f' t x :=
has_fderiv_within_at.congr_mono h ht hx h₁
lemma has_deriv_within_at.congr (h : has_deriv_within_at f f' s x) (hs : ∀x ∈ s, f₁ x = f x)
(hx : f₁ x = f x) : has_deriv_within_at f₁ f' s x :=
h.congr_mono hs hx (subset.refl _)
lemma has_deriv_within_at.congr_of_eventually_eq (h : has_deriv_within_at f f' s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : has_deriv_within_at f₁ f' s x :=
has_deriv_at_filter.congr_of_eventually_eq h h₁ hx
lemma has_deriv_within_at.congr_of_eventually_eq_of_mem (h : has_deriv_within_at f f' s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : has_deriv_within_at f₁ f' s x :=
h.congr_of_eventually_eq h₁ (h₁.eq_of_nhds_within hx)
lemma has_deriv_at.congr_of_eventually_eq (h : has_deriv_at f f' x)
(h₁ : f₁ =ᶠ[𝓝 x] f) : has_deriv_at f₁ f' x :=
has_deriv_at_filter.congr_of_eventually_eq h h₁ (mem_of_mem_nhds h₁ : _)
lemma filter.eventually_eq.deriv_within_eq (hs : unique_diff_within_at 𝕜 s x)
(hL : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) :
deriv_within f₁ s x = deriv_within f s x :=
by { unfold deriv_within, rw hL.fderiv_within_eq hs hx }
lemma deriv_within_congr (hs : unique_diff_within_at 𝕜 s x)
(hL : ∀y∈s, f₁ y = f y) (hx : f₁ x = f x) :
deriv_within f₁ s x = deriv_within f s x :=
by { unfold deriv_within, rw fderiv_within_congr hs hL hx }
lemma filter.eventually_eq.deriv_eq (hL : f₁ =ᶠ[𝓝 x] f) : deriv f₁ x = deriv f x :=
by { unfold deriv, rwa filter.eventually_eq.fderiv_eq }
protected lemma filter.eventually_eq.deriv (h : f₁ =ᶠ[𝓝 x] f) : deriv f₁ =ᶠ[𝓝 x] deriv f :=
h.eventually_eq_nhds.mono $ λ x h, h.deriv_eq
end congr
section id
/-! ### Derivative of the identity -/
variables (s x L)
theorem has_deriv_at_filter_id : has_deriv_at_filter id 1 x L :=
(has_fderiv_at_filter_id x L).has_deriv_at_filter
theorem has_deriv_within_at_id : has_deriv_within_at id 1 s x :=
has_deriv_at_filter_id _ _
theorem has_deriv_at_id : has_deriv_at id 1 x :=
has_deriv_at_filter_id _ _
theorem has_deriv_at_id' : has_deriv_at (λ (x : 𝕜), x) 1 x :=
has_deriv_at_filter_id _ _
theorem has_strict_deriv_at_id : has_strict_deriv_at id 1 x :=
(has_strict_fderiv_at_id x).has_strict_deriv_at
lemma deriv_id : deriv id x = 1 :=
has_deriv_at.deriv (has_deriv_at_id x)
@[simp] lemma deriv_id' : deriv (@id 𝕜) = λ _, 1 := funext deriv_id
@[simp] lemma deriv_id'' : deriv (λ x : 𝕜, x) = λ _, 1 := deriv_id'
lemma deriv_within_id (hxs : unique_diff_within_at 𝕜 s x) : deriv_within id s x = 1 :=
(has_deriv_within_at_id x s).deriv_within hxs
end id
section const
/-! ### Derivative of constant functions -/
variables (c : F) (s x L)
theorem has_deriv_at_filter_const : has_deriv_at_filter (λ x, c) 0 x L :=
(has_fderiv_at_filter_const c x L).has_deriv_at_filter
theorem has_strict_deriv_at_const : has_strict_deriv_at (λ x, c) 0 x :=
(has_strict_fderiv_at_const c x).has_strict_deriv_at
theorem has_deriv_within_at_const : has_deriv_within_at (λ x, c) 0 s x :=
has_deriv_at_filter_const _ _ _
theorem has_deriv_at_const : has_deriv_at (λ x, c) 0 x :=
has_deriv_at_filter_const _ _ _
lemma deriv_const : deriv (λ x, c) x = 0 :=
has_deriv_at.deriv (has_deriv_at_const x c)
@[simp] lemma deriv_const' : deriv (λ x:𝕜, c) = λ x, 0 :=
funext (λ x, deriv_const x c)
lemma deriv_within_const (hxs : unique_diff_within_at 𝕜 s x) : deriv_within (λ x, c) s x = 0 :=
(has_deriv_within_at_const _ _ _).deriv_within hxs
end const
section continuous_linear_map
/-! ### Derivative of continuous linear maps -/
variables (e : 𝕜 →L[𝕜] F)
protected lemma continuous_linear_map.has_deriv_at_filter : has_deriv_at_filter e (e 1) x L :=
e.has_fderiv_at_filter.has_deriv_at_filter
protected lemma continuous_linear_map.has_strict_deriv_at : has_strict_deriv_at e (e 1) x :=
e.has_strict_fderiv_at.has_strict_deriv_at
protected lemma continuous_linear_map.has_deriv_at : has_deriv_at e (e 1) x :=
e.has_deriv_at_filter
protected lemma continuous_linear_map.has_deriv_within_at : has_deriv_within_at e (e 1) s x :=
e.has_deriv_at_filter
@[simp] protected lemma continuous_linear_map.deriv : deriv e x = e 1 :=
e.has_deriv_at.deriv
protected lemma continuous_linear_map.deriv_within (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within e s x = e 1 :=
e.has_deriv_within_at.deriv_within hxs
end continuous_linear_map
section linear_map
/-! ### Derivative of bundled linear maps -/
variables (e : 𝕜 →ₗ[𝕜] F)
protected lemma linear_map.has_deriv_at_filter : has_deriv_at_filter e (e 1) x L :=
e.to_continuous_linear_map₁.has_deriv_at_filter
protected lemma linear_map.has_strict_deriv_at : has_strict_deriv_at e (e 1) x :=
e.to_continuous_linear_map₁.has_strict_deriv_at
protected lemma linear_map.has_deriv_at : has_deriv_at e (e 1) x :=
e.has_deriv_at_filter
protected lemma linear_map.has_deriv_within_at : has_deriv_within_at e (e 1) s x :=
e.has_deriv_at_filter
@[simp] protected lemma linear_map.deriv : deriv e x = e 1 :=
e.has_deriv_at.deriv
protected lemma linear_map.deriv_within (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within e s x = e 1 :=
e.has_deriv_within_at.deriv_within hxs
end linear_map
section add
/-! ### Derivative of the sum of two functions -/
theorem has_deriv_at_filter.add
(hf : has_deriv_at_filter f f' x L) (hg : has_deriv_at_filter g g' x L) :
has_deriv_at_filter (λ y, f y + g y) (f' + g') x L :=
by simpa using (hf.add hg).has_deriv_at_filter
theorem has_strict_deriv_at.add
(hf : has_strict_deriv_at f f' x) (hg : has_strict_deriv_at g g' x) :
has_strict_deriv_at (λ y, f y + g y) (f' + g') x :=
by simpa using (hf.add hg).has_strict_deriv_at
theorem has_deriv_within_at.add
(hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) :
has_deriv_within_at (λ y, f y + g y) (f' + g') s x :=
hf.add hg
theorem has_deriv_at.add
(hf : has_deriv_at f f' x) (hg : has_deriv_at g g' x) :
has_deriv_at (λ x, f x + g x) (f' + g') x :=
hf.add hg
lemma deriv_within_add (hxs : unique_diff_within_at 𝕜 s x)
(hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) :
deriv_within (λy, f y + g y) s x = deriv_within f s x + deriv_within g s x :=
(hf.has_deriv_within_at.add hg.has_deriv_within_at).deriv_within hxs
@[simp] lemma deriv_add
(hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) :
deriv (λy, f y + g y) x = deriv f x + deriv g x :=
(hf.has_deriv_at.add hg.has_deriv_at).deriv
theorem has_deriv_at_filter.add_const
(hf : has_deriv_at_filter f f' x L) (c : F) :
has_deriv_at_filter (λ y, f y + c) f' x L :=
add_zero f' ▸ hf.add (has_deriv_at_filter_const x L c)
theorem has_deriv_within_at.add_const
(hf : has_deriv_within_at f f' s x) (c : F) :
has_deriv_within_at (λ y, f y + c) f' s x :=
hf.add_const c
theorem has_deriv_at.add_const
(hf : has_deriv_at f f' x) (c : F) :
has_deriv_at (λ x, f x + c) f' x :=
hf.add_const c
lemma deriv_within_add_const (hxs : unique_diff_within_at 𝕜 s x) (c : F) :
deriv_within (λy, f y + c) s x = deriv_within f s x :=
by simp only [deriv_within, fderiv_within_add_const hxs]
lemma deriv_add_const (c : F) : deriv (λy, f y + c) x = deriv f x :=
by simp only [deriv, fderiv_add_const]
@[simp] lemma deriv_add_const' (c : F) : deriv (λ y, f y + c) = deriv f :=
funext $ λ x, deriv_add_const c
theorem has_deriv_at_filter.const_add (c : F) (hf : has_deriv_at_filter f f' x L) :
has_deriv_at_filter (λ y, c + f y) f' x L :=
zero_add f' ▸ (has_deriv_at_filter_const x L c).add hf
theorem has_deriv_within_at.const_add (c : F) (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ y, c + f y) f' s x :=
hf.const_add c
theorem has_deriv_at.const_add (c : F) (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, c + f x) f' x :=
hf.const_add c
lemma deriv_within_const_add (hxs : unique_diff_within_at 𝕜 s x) (c : F) :
deriv_within (λy, c + f y) s x = deriv_within f s x :=
by simp only [deriv_within, fderiv_within_const_add hxs]
lemma deriv_const_add (c : F) : deriv (λy, c + f y) x = deriv f x :=
by simp only [deriv, fderiv_const_add]
@[simp] lemma deriv_const_add' (c : F) : deriv (λ y, c + f y) = deriv f :=
funext $ λ x, deriv_const_add c
end add
section sum
/-! ### Derivative of a finite sum of functions -/
open_locale big_operators
variables {ι : Type*} {u : finset ι} {A : ι → (𝕜 → F)} {A' : ι → F}
theorem has_deriv_at_filter.sum (h : ∀ i ∈ u, has_deriv_at_filter (A i) (A' i) x L) :
has_deriv_at_filter (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x L :=
by simpa [continuous_linear_map.sum_apply] using (has_fderiv_at_filter.sum h).has_deriv_at_filter
theorem has_strict_deriv_at.sum (h : ∀ i ∈ u, has_strict_deriv_at (A i) (A' i) x) :
has_strict_deriv_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x :=
by simpa [continuous_linear_map.sum_apply] using (has_strict_fderiv_at.sum h).has_strict_deriv_at
theorem has_deriv_within_at.sum (h : ∀ i ∈ u, has_deriv_within_at (A i) (A' i) s x) :
has_deriv_within_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) s x :=
has_deriv_at_filter.sum h
theorem has_deriv_at.sum (h : ∀ i ∈ u, has_deriv_at (A i) (A' i) x) :
has_deriv_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x :=
has_deriv_at_filter.sum h
lemma deriv_within_sum (hxs : unique_diff_within_at 𝕜 s x)
(h : ∀ i ∈ u, differentiable_within_at 𝕜 (A i) s x) :
deriv_within (λ y, ∑ i in u, A i y) s x = ∑ i in u, deriv_within (A i) s x :=
(has_deriv_within_at.sum (λ i hi, (h i hi).has_deriv_within_at)).deriv_within hxs
@[simp] lemma deriv_sum (h : ∀ i ∈ u, differentiable_at 𝕜 (A i) x) :
deriv (λ y, ∑ i in u, A i y) x = ∑ i in u, deriv (A i) x :=
(has_deriv_at.sum (λ i hi, (h i hi).has_deriv_at)).deriv
end sum
section pi
/-! ### Derivatives of functions `f : 𝕜 → Π i, E i` -/
variables {ι : Type*} [fintype ι] {E' : ι → Type*} [Π i, normed_group (E' i)]
[Π i, normed_space 𝕜 (E' i)] {φ : 𝕜 → Π i, E' i} {φ' : Π i, E' i}
@[simp] lemma has_strict_deriv_at_pi :
has_strict_deriv_at φ φ' x ↔ ∀ i, has_strict_deriv_at (λ x, φ x i) (φ' i) x :=
has_strict_fderiv_at_pi'
@[simp] lemma has_deriv_at_filter_pi :
has_deriv_at_filter φ φ' x L ↔
∀ i, has_deriv_at_filter (λ x, φ x i) (φ' i) x L :=
has_fderiv_at_filter_pi'
lemma has_deriv_at_pi :
has_deriv_at φ φ' x ↔ ∀ i, has_deriv_at (λ x, φ x i) (φ' i) x:=
has_deriv_at_filter_pi
lemma has_deriv_within_at_pi :
has_deriv_within_at φ φ' s x ↔ ∀ i, has_deriv_within_at (λ x, φ x i) (φ' i) s x:=
has_deriv_at_filter_pi
lemma deriv_within_pi (h : ∀ i, differentiable_within_at 𝕜 (λ x, φ x i) s x)
(hs : unique_diff_within_at 𝕜 s x) :
deriv_within φ s x = λ i, deriv_within (λ x, φ x i) s x :=
(has_deriv_within_at_pi.2 (λ i, (h i).has_deriv_within_at)).deriv_within hs
lemma deriv_pi (h : ∀ i, differentiable_at 𝕜 (λ x, φ x i) x) :
deriv φ x = λ i, deriv (λ x, φ x i) x :=
(has_deriv_at_pi.2 (λ i, (h i).has_deriv_at)).deriv
end pi
section mul_vector
/-! ### Derivative of the multiplication of a scalar function and a vector function -/
variables {c : 𝕜 → 𝕜} {c' : 𝕜}
theorem has_deriv_within_at.smul
(hc : has_deriv_within_at c c' s x) (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ y, c y • f y) (c x • f' + c' • f x) s x :=
by simpa using (has_fderiv_within_at.smul hc hf).has_deriv_within_at
theorem has_deriv_at.smul
(hc : has_deriv_at c c' x) (hf : has_deriv_at f f' x) :
has_deriv_at (λ y, c y • f y) (c x • f' + c' • f x) x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hc.smul hf
end
theorem has_strict_deriv_at.smul
(hc : has_strict_deriv_at c c' x) (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ y, c y • f y) (c x • f' + c' • f x) x :=
by simpa using (hc.smul hf).has_strict_deriv_at
lemma deriv_within_smul (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (hf : differentiable_within_at 𝕜 f s x) :
deriv_within (λ y, c y • f y) s x = c x • deriv_within f s x + (deriv_within c s x) • f x :=
(hc.has_deriv_within_at.smul hf.has_deriv_within_at).deriv_within hxs
lemma deriv_smul (hc : differentiable_at 𝕜 c x) (hf : differentiable_at 𝕜 f x) :
deriv (λ y, c y • f y) x = c x • deriv f x + (deriv c x) • f x :=
(hc.has_deriv_at.smul hf.has_deriv_at).deriv
theorem has_deriv_within_at.smul_const
(hc : has_deriv_within_at c c' s x) (f : F) :
has_deriv_within_at (λ y, c y • f) (c' • f) s x :=
begin
have := hc.smul (has_deriv_within_at_const x s f),
rwa [smul_zero, zero_add] at this
end
theorem has_deriv_at.smul_const
(hc : has_deriv_at c c' x) (f : F) :
has_deriv_at (λ y, c y • f) (c' • f) x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hc.smul_const f
end
lemma deriv_within_smul_const (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (f : F) :
deriv_within (λ y, c y • f) s x = (deriv_within c s x) • f :=
(hc.has_deriv_within_at.smul_const f).deriv_within hxs
lemma deriv_smul_const (hc : differentiable_at 𝕜 c x) (f : F) :
deriv (λ y, c y • f) x = (deriv c x) • f :=
(hc.has_deriv_at.smul_const f).deriv
theorem has_deriv_within_at.const_smul
(c : 𝕜) (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ y, c • f y) (c • f') s x :=
begin
convert (has_deriv_within_at_const x s c).smul hf,
rw [zero_smul, add_zero]
end
theorem has_deriv_at.const_smul (c : 𝕜) (hf : has_deriv_at f f' x) :
has_deriv_at (λ y, c • f y) (c • f') x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hf.const_smul c
end
lemma deriv_within_const_smul (hxs : unique_diff_within_at 𝕜 s x)
(c : 𝕜) (hf : differentiable_within_at 𝕜 f s x) :
deriv_within (λ y, c • f y) s x = c • deriv_within f s x :=
(hf.has_deriv_within_at.const_smul c).deriv_within hxs
lemma deriv_const_smul (c : 𝕜) (hf : differentiable_at 𝕜 f x) :
deriv (λ y, c • f y) x = c • deriv f x :=
(hf.has_deriv_at.const_smul c).deriv
end mul_vector
section neg
/-! ### Derivative of the negative of a function -/
theorem has_deriv_at_filter.neg (h : has_deriv_at_filter f f' x L) :
has_deriv_at_filter (λ x, -f x) (-f') x L :=
by simpa using h.neg.has_deriv_at_filter
theorem has_deriv_within_at.neg (h : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, -f x) (-f') s x :=
h.neg
theorem has_deriv_at.neg (h : has_deriv_at f f' x) : has_deriv_at (λ x, -f x) (-f') x :=
h.neg
theorem has_strict_deriv_at.neg (h : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, -f x) (-f') x :=
by simpa using h.neg.has_strict_deriv_at
lemma deriv_within.neg (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λy, -f y) s x = - deriv_within f s x :=
by simp only [deriv_within, fderiv_within_neg hxs, continuous_linear_map.neg_apply]
lemma deriv.neg : deriv (λy, -f y) x = - deriv f x :=
by simp only [deriv, fderiv_neg, continuous_linear_map.neg_apply]
@[simp] lemma deriv.neg' : deriv (λy, -f y) = (λ x, - deriv f x) :=
funext $ λ x, deriv.neg
end neg
section neg2
/-! ### Derivative of the negation function (i.e `has_neg.neg`) -/
variables (s x L)
theorem has_deriv_at_filter_neg : has_deriv_at_filter has_neg.neg (-1) x L :=
has_deriv_at_filter.neg $ has_deriv_at_filter_id _ _
theorem has_deriv_within_at_neg : has_deriv_within_at has_neg.neg (-1) s x :=
has_deriv_at_filter_neg _ _
theorem has_deriv_at_neg : has_deriv_at has_neg.neg (-1) x :=
has_deriv_at_filter_neg _ _
theorem has_deriv_at_neg' : has_deriv_at (λ x, -x) (-1) x :=
has_deriv_at_filter_neg _ _
theorem has_strict_deriv_at_neg : has_strict_deriv_at has_neg.neg (-1) x :=
has_strict_deriv_at.neg $ has_strict_deriv_at_id _
lemma deriv_neg : deriv has_neg.neg x = -1 :=
has_deriv_at.deriv (has_deriv_at_neg x)
@[simp] lemma deriv_neg' : deriv (has_neg.neg : 𝕜 → 𝕜) = λ _, -1 :=
funext deriv_neg
@[simp] lemma deriv_neg'' : deriv (λ x : 𝕜, -x) x = -1 :=
deriv_neg x
lemma deriv_within_neg (hxs : unique_diff_within_at 𝕜 s x) : deriv_within has_neg.neg s x = -1 :=
(has_deriv_within_at_neg x s).deriv_within hxs
lemma differentiable_neg : differentiable 𝕜 (has_neg.neg : 𝕜 → 𝕜) :=
differentiable.neg differentiable_id
lemma differentiable_on_neg : differentiable_on 𝕜 (has_neg.neg : 𝕜 → 𝕜) s :=
differentiable_on.neg differentiable_on_id
end neg2
section sub
/-! ### Derivative of the difference of two functions -/
theorem has_deriv_at_filter.sub
(hf : has_deriv_at_filter f f' x L) (hg : has_deriv_at_filter g g' x L) :
has_deriv_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_deriv_within_at.sub
(hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) :
has_deriv_within_at (λ x, f x - g x) (f' - g') s x :=
hf.sub hg
theorem has_deriv_at.sub
(hf : has_deriv_at f f' x) (hg : has_deriv_at g g' x) :
has_deriv_at (λ x, f x - g x) (f' - g') x :=
hf.sub hg
theorem has_strict_deriv_at.sub
(hf : has_strict_deriv_at f f' x) (hg : has_strict_deriv_at g g' x) :
has_strict_deriv_at (λ x, f x - g x) (f' - g') x :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
lemma deriv_within_sub (hxs : unique_diff_within_at 𝕜 s x)
(hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) :
deriv_within (λy, f y - g y) s x = deriv_within f s x - deriv_within g s x :=
(hf.has_deriv_within_at.sub hg.has_deriv_within_at).deriv_within hxs
@[simp] lemma deriv_sub
(hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) :
deriv (λ y, f y - g y) x = deriv f x - deriv g x :=
(hf.has_deriv_at.sub hg.has_deriv_at).deriv
theorem has_deriv_at_filter.is_O_sub (h : has_deriv_at_filter f f' x L) :
is_O (λ x', f x' - f x) (λ x', x' - x) L :=
has_fderiv_at_filter.is_O_sub h
theorem has_deriv_at_filter.sub_const
(hf : has_deriv_at_filter f f' x L) (c : F) :
has_deriv_at_filter (λ x, f x - c) f' x L :=
by simpa only [sub_eq_add_neg] using hf.add_const (-c)
theorem has_deriv_within_at.sub_const
(hf : has_deriv_within_at f f' s x) (c : F) :
has_deriv_within_at (λ x, f x - c) f' s x :=
hf.sub_const c
theorem has_deriv_at.sub_const
(hf : has_deriv_at f f' x) (c : F) :
has_deriv_at (λ x, f x - c) f' x :=
hf.sub_const c
lemma deriv_within_sub_const (hxs : unique_diff_within_at 𝕜 s x) (c : F) :
deriv_within (λy, f y - c) s x = deriv_within f s x :=
by simp only [deriv_within, fderiv_within_sub_const hxs]
lemma deriv_sub_const (c : F) : deriv (λ y, f y - c) x = deriv f x :=
by simp only [deriv, fderiv_sub_const]
theorem has_deriv_at_filter.const_sub (c : F) (hf : has_deriv_at_filter f f' x L) :
has_deriv_at_filter (λ x, c - f x) (-f') x L :=
by simpa only [sub_eq_add_neg] using hf.neg.const_add c
theorem has_deriv_within_at.const_sub (c : F) (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, c - f x) (-f') s x :=
hf.const_sub c
theorem has_strict_deriv_at.const_sub (c : F) (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, c - f x) (-f') x :=
by simpa only [sub_eq_add_neg] using hf.neg.const_add c
theorem has_deriv_at.const_sub (c : F) (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, c - f x) (-f') x :=
hf.const_sub c
lemma deriv_within_const_sub (hxs : unique_diff_within_at 𝕜 s x) (c : F) :
deriv_within (λy, c - f y) s x = -deriv_within f s x :=
by simp [deriv_within, fderiv_within_const_sub hxs]
lemma deriv_const_sub (c : F) : deriv (λ y, c - f y) x = -deriv f x :=
by simp only [← deriv_within_univ, deriv_within_const_sub unique_diff_within_at_univ]
end sub
section continuous
/-! ### Continuity of a function admitting a derivative -/
theorem has_deriv_at_filter.tendsto_nhds
(hL : L ≤ 𝓝 x) (h : has_deriv_at_filter f f' x L) :
tendsto f L (𝓝 (f x)) :=
h.tendsto_nhds hL
theorem has_deriv_within_at.continuous_within_at
(h : has_deriv_within_at f f' s x) : continuous_within_at f s x :=
has_deriv_at_filter.tendsto_nhds inf_le_left h
theorem has_deriv_at.continuous_at (h : has_deriv_at f f' x) : continuous_at f x :=
has_deriv_at_filter.tendsto_nhds (le_refl _) h
protected theorem has_deriv_at.continuous_on {f f' : 𝕜 → F}
(hderiv : ∀ x ∈ s, has_deriv_at f (f' x) x) : continuous_on f s :=
λ x hx, (hderiv x hx).continuous_at.continuous_within_at
end continuous
section cartesian_product
/-! ### Derivative of the cartesian product of two functions -/
variables {G : Type w} [normed_group G] [normed_space 𝕜 G]
variables {f₂ : 𝕜 → G} {f₂' : G}
lemma has_deriv_at_filter.prod
(hf₁ : has_deriv_at_filter f₁ f₁' x L) (hf₂ : has_deriv_at_filter f₂ f₂' x L) :
has_deriv_at_filter (λ x, (f₁ x, f₂ x)) (f₁', f₂') x L :=
hf₁.prod hf₂
lemma has_deriv_within_at.prod
(hf₁ : has_deriv_within_at f₁ f₁' s x) (hf₂ : has_deriv_within_at f₂ f₂' s x) :
has_deriv_within_at (λ x, (f₁ x, f₂ x)) (f₁', f₂') s x :=
hf₁.prod hf₂
lemma has_deriv_at.prod (hf₁ : has_deriv_at f₁ f₁' x) (hf₂ : has_deriv_at f₂ f₂' x) :
has_deriv_at (λ x, (f₁ x, f₂ x)) (f₁', f₂') x :=
hf₁.prod hf₂
lemma has_strict_deriv_at.prod (hf₁ : has_strict_deriv_at f₁ f₁' x)
(hf₂ : has_strict_deriv_at f₂ f₂' x) :
has_strict_deriv_at (λ x, (f₁ x, f₂ x)) (f₁', f₂') x :=
hf₁.prod hf₂
end cartesian_product
section composition
/-!
### Derivative of the composition of a vector function and a scalar function
We use `scomp` in lemmas on composition of vector valued and scalar valued functions, and `comp`
in lemmas on composition of scalar valued functions, in analogy for `smul` and `mul` (and also
because the `comp` version with the shorter name will show up much more often in applications).
The formula for the derivative involves `smul` in `scomp` lemmas, which can be reduced to
usual multiplication in `comp` lemmas.
-/
variables {h h₁ h₂ : 𝕜 → 𝕜} {h' h₁' h₂' : 𝕜}
/- 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_deriv_at_filter.scomp
(hg : has_deriv_at_filter g g' (h x) (L.map h))
(hh : has_deriv_at_filter h h' x L) :
has_deriv_at_filter (g ∘ h) (h' • g') x L :=
by simpa using (hg.comp x hh).has_deriv_at_filter
theorem has_deriv_within_at.scomp {t : set 𝕜}
(hg : has_deriv_within_at g g' t (h x))
(hh : has_deriv_within_at h h' s x) (hst : s ⊆ h ⁻¹' t) :
has_deriv_within_at (g ∘ h) (h' • g') s x :=
has_deriv_at_filter.scomp _ (has_deriv_at_filter.mono hg $
hh.continuous_within_at.tendsto_nhds_within hst) hh
/-- The chain rule. -/
theorem has_deriv_at.scomp
(hg : has_deriv_at g g' (h x)) (hh : has_deriv_at h h' x) :
has_deriv_at (g ∘ h) (h' • g') x :=
(hg.mono hh.continuous_at).scomp x hh
theorem has_strict_deriv_at.scomp
(hg : has_strict_deriv_at g g' (h x)) (hh : has_strict_deriv_at h h' x) :
has_strict_deriv_at (g ∘ h) (h' • g') x :=
by simpa using (hg.comp x hh).has_strict_deriv_at
theorem has_deriv_at.scomp_has_deriv_within_at
(hg : has_deriv_at g g' (h x)) (hh : has_deriv_within_at h h' s x) :
has_deriv_within_at (g ∘ h) (h' • g') s x :=
begin
rw ← has_deriv_within_at_univ at hg,
exact has_deriv_within_at.scomp x hg hh subset_preimage_univ
end
lemma deriv_within.scomp
(hg : differentiable_within_at 𝕜 g t (h x)) (hh : differentiable_within_at 𝕜 h s x)
(hs : s ⊆ h ⁻¹' t) (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (g ∘ h) s x = deriv_within h s x • deriv_within g t (h x) :=
begin
apply has_deriv_within_at.deriv_within _ hxs,
exact has_deriv_within_at.scomp x (hg.has_deriv_within_at) (hh.has_deriv_within_at) hs
end
lemma deriv.scomp
(hg : differentiable_at 𝕜 g (h x)) (hh : differentiable_at 𝕜 h x) :
deriv (g ∘ h) x = deriv h x • deriv g (h x) :=
begin
apply has_deriv_at.deriv,
exact has_deriv_at.scomp x hg.has_deriv_at hh.has_deriv_at
end
/-! ### Derivative of the composition of a scalar and vector functions -/
theorem has_deriv_at_filter.comp_has_fderiv_at_filter {f : E → 𝕜} {f' : E →L[𝕜] 𝕜} (x)
{L : filter E} (hh₁ : has_deriv_at_filter h₁ h₁' (f x) (L.map f))
(hf : has_fderiv_at_filter f f' x L) :
has_fderiv_at_filter (h₁ ∘ f) (h₁' • f') x L :=
by { convert has_fderiv_at_filter.comp x hh₁ hf, ext x, simp [mul_comm] }
theorem has_strict_deriv_at.comp_has_strict_fderiv_at {f : E → 𝕜} {f' : E →L[𝕜] 𝕜} (x)
(hh₁ : has_strict_deriv_at h₁ h₁' (f x)) (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (h₁ ∘ f) (h₁' • f') x :=
by { rw has_strict_deriv_at at hh₁, convert hh₁.comp x hf, ext x, simp [mul_comm] }
theorem has_deriv_at.comp_has_fderiv_at {f : E → 𝕜} {f' : E →L[𝕜] 𝕜} (x)
(hh₁ : has_deriv_at h₁ h₁' (f x)) (hf : has_fderiv_at f f' x) :
has_fderiv_at (h₁ ∘ f) (h₁' • f') x :=
(hh₁.mono hf.continuous_at).comp_has_fderiv_at_filter x hf
theorem has_deriv_at.comp_has_fderiv_within_at {f : E → 𝕜} {f' : E →L[𝕜] 𝕜} {s} (x)
(hh₁ : has_deriv_at h₁ h₁' (f x)) (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (h₁ ∘ f) (h₁' • f') s x :=
(hh₁.mono hf.continuous_within_at).comp_has_fderiv_at_filter x hf
theorem has_deriv_within_at.comp_has_fderiv_within_at {f : E → 𝕜} {f' : E →L[𝕜] 𝕜} {s t} (x)
(hh₁ : has_deriv_within_at h₁ h₁' t (f x)) (hf : has_fderiv_within_at f f' s x)
(hst : maps_to f s t) :
has_fderiv_within_at (h₁ ∘ f) (h₁' • f') s x :=
(has_deriv_at_filter.mono hh₁ $
hf.continuous_within_at.tendsto_nhds_within hst).comp_has_fderiv_at_filter x hf
/-! ### Derivative of the composition of two scalar functions -/
theorem has_deriv_at_filter.comp
(hh₁ : has_deriv_at_filter h₁ h₁' (h₂ x) (L.map h₂))
(hh₂ : has_deriv_at_filter h₂ h₂' x L) :
has_deriv_at_filter (h₁ ∘ h₂) (h₁' * h₂') x L :=
by { rw mul_comm, exact hh₁.scomp x hh₂ }
theorem has_deriv_within_at.comp {t : set 𝕜}
(hh₁ : has_deriv_within_at h₁ h₁' t (h₂ x))
(hh₂ : has_deriv_within_at h₂ h₂' s x) (hst : s ⊆ h₂ ⁻¹' t) :
has_deriv_within_at (h₁ ∘ h₂) (h₁' * h₂') s x :=
by { rw mul_comm, exact hh₁.scomp x hh₂ hst, }
/-- The chain rule. -/
theorem has_deriv_at.comp
(hh₁ : has_deriv_at h₁ h₁' (h₂ x)) (hh₂ : has_deriv_at h₂ h₂' x) :
has_deriv_at (h₁ ∘ h₂) (h₁' * h₂') x :=
(hh₁.mono hh₂.continuous_at).comp x hh₂
theorem has_strict_deriv_at.comp
(hh₁ : has_strict_deriv_at h₁ h₁' (h₂ x)) (hh₂ : has_strict_deriv_at h₂ h₂' x) :
has_strict_deriv_at (h₁ ∘ h₂) (h₁' * h₂') x :=
by { rw mul_comm, exact hh₁.scomp x hh₂ }
theorem has_deriv_at.comp_has_deriv_within_at
(hh₁ : has_deriv_at h₁ h₁' (h₂ x)) (hh₂ : has_deriv_within_at h₂ h₂' s x) :
has_deriv_within_at (h₁ ∘ h₂) (h₁' * h₂') s x :=
begin
rw ← has_deriv_within_at_univ at hh₁,
exact has_deriv_within_at.comp x hh₁ hh₂ subset_preimage_univ
end
lemma deriv_within.comp
(hh₁ : differentiable_within_at 𝕜 h₁ t (h₂ x)) (hh₂ : differentiable_within_at 𝕜 h₂ s x)
(hs : s ⊆ h₂ ⁻¹' t) (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (h₁ ∘ h₂) s x = deriv_within h₁ t (h₂ x) * deriv_within h₂ s x :=
begin
apply has_deriv_within_at.deriv_within _ hxs,
exact has_deriv_within_at.comp x (hh₁.has_deriv_within_at) (hh₂.has_deriv_within_at) hs
end
lemma deriv.comp
(hh₁ : differentiable_at 𝕜 h₁ (h₂ x)) (hh₂ : differentiable_at 𝕜 h₂ x) :
deriv (h₁ ∘ h₂) x = deriv h₁ (h₂ x) * deriv h₂ x :=
begin
apply has_deriv_at.deriv,
exact has_deriv_at.comp x hh₁.has_deriv_at hh₂.has_deriv_at
end
protected lemma has_deriv_at_filter.iterate {f : 𝕜 → 𝕜} {f' : 𝕜}
(hf : has_deriv_at_filter f f' x L) (hL : tendsto f L L) (hx : f x = x) (n : ℕ) :
has_deriv_at_filter (f^[n]) (f'^n) x L :=
begin
have := hf.iterate hL hx n,
rwa [continuous_linear_map.smul_right_one_pow] at this
end
protected lemma has_deriv_at.iterate {f : 𝕜 → 𝕜} {f' : 𝕜}
(hf : has_deriv_at f f' x) (hx : f x = x) (n : ℕ) :
has_deriv_at (f^[n]) (f'^n) x :=
begin
have := has_fderiv_at.iterate hf hx n,
rwa [continuous_linear_map.smul_right_one_pow] at this
end
protected lemma has_deriv_within_at.iterate {f : 𝕜 → 𝕜} {f' : 𝕜}
(hf : has_deriv_within_at f f' s x) (hx : f x = x) (hs : maps_to f s s) (n : ℕ) :
has_deriv_within_at (f^[n]) (f'^n) s x :=
begin
have := has_fderiv_within_at.iterate hf hx hs n,
rwa [continuous_linear_map.smul_right_one_pow] at this
end
protected lemma has_strict_deriv_at.iterate {f : 𝕜 → 𝕜} {f' : 𝕜}
(hf : has_strict_deriv_at f f' x) (hx : f x = x) (n : ℕ) :
has_strict_deriv_at (f^[n]) (f'^n) x :=
begin
have := hf.iterate hx n,
rwa [continuous_linear_map.smul_right_one_pow] at this
end
end composition
section composition_vector
/-! ### Derivative of the composition of a function between vector spaces and a function on `𝕜` -/
open continuous_linear_map
variables {l : F → E} {l' : F →L[𝕜] E}
variable (x)
/-- The composition `l ∘ f` where `l : F → E` and `f : 𝕜 → F`, has a derivative within a set
equal to the Fréchet derivative of `l` applied to the derivative of `f`. -/
theorem has_fderiv_within_at.comp_has_deriv_within_at {t : set F}
(hl : has_fderiv_within_at l l' t (f x)) (hf : has_deriv_within_at f f' s x)
(hst : maps_to f s t) :
has_deriv_within_at (l ∘ f) (l' f') s x :=
by simpa only [one_apply, one_smul, smul_right_apply, coe_comp', (∘)]
using (hl.comp x hf.has_fderiv_within_at hst).has_deriv_within_at
theorem has_fderiv_at.comp_has_deriv_within_at
(hl : has_fderiv_at l l' (f x)) (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (l ∘ f) (l' f') s x :=
hl.has_fderiv_within_at.comp_has_deriv_within_at x hf (maps_to_univ _ _)
/-- The composition `l ∘ f` where `l : F → E` and `f : 𝕜 → F`, has a derivative equal to the
Fréchet derivative of `l` applied to the derivative of `f`. -/
theorem has_fderiv_at.comp_has_deriv_at (hl : has_fderiv_at l l' (f x)) (hf : has_deriv_at f f' x) :
has_deriv_at (l ∘ f) (l' f') x :=
has_deriv_within_at_univ.mp $ hl.comp_has_deriv_within_at x hf.has_deriv_within_at
theorem has_strict_fderiv_at.comp_has_strict_deriv_at
(hl : has_strict_fderiv_at l l' (f x)) (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (l ∘ f) (l' f') x :=
by simpa only [one_apply, one_smul, smul_right_apply, coe_comp', (∘)]
using (hl.comp x hf.has_strict_fderiv_at).has_strict_deriv_at
lemma fderiv_within.comp_deriv_within {t : set F}
(hl : differentiable_within_at 𝕜 l t (f x)) (hf : differentiable_within_at 𝕜 f s x)
(hs : maps_to f s t) (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (l ∘ f) s x = (fderiv_within 𝕜 l t (f x) : F → E) (deriv_within f s x) :=
(hl.has_fderiv_within_at.comp_has_deriv_within_at x hf.has_deriv_within_at hs).deriv_within hxs
lemma fderiv.comp_deriv
(hl : differentiable_at 𝕜 l (f x)) (hf : differentiable_at 𝕜 f x) :
deriv (l ∘ f) x = (fderiv 𝕜 l (f x) : F → E) (deriv f x) :=
(hl.has_fderiv_at.comp_has_deriv_at x hf.has_deriv_at).deriv
end composition_vector
section mul
/-! ### Derivative of the multiplication of two functions -/
variables {𝕜' 𝔸 : Type*} [normed_field 𝕜'] [normed_ring 𝔸] [normed_algebra 𝕜 𝕜']
[normed_algebra 𝕜 𝔸] {c d : 𝕜 → 𝔸} {c' d' : 𝔸} {u v : 𝕜 → 𝕜'}
theorem has_deriv_within_at.mul
(hc : has_deriv_within_at c c' s x) (hd : has_deriv_within_at d d' s x) :
has_deriv_within_at (λ y, c y * d y) (c' * d x + c x * d') s x :=
begin
have := (has_fderiv_within_at.mul' hc hd).has_deriv_within_at,
rwa [continuous_linear_map.add_apply, continuous_linear_map.smul_apply,
continuous_linear_map.smul_right_apply, continuous_linear_map.smul_right_apply,
continuous_linear_map.smul_right_apply, continuous_linear_map.one_apply,
one_smul, one_smul, add_comm] at this,
end
theorem has_deriv_at.mul (hc : has_deriv_at c c' x) (hd : has_deriv_at d d' x) :
has_deriv_at (λ y, c y * d y) (c' * d x + c x * d') x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hc.mul hd
end
theorem has_strict_deriv_at.mul
(hc : has_strict_deriv_at c c' x) (hd : has_strict_deriv_at d d' x) :
has_strict_deriv_at (λ y, c y * d y) (c' * d x + c x * d') x :=
begin
have := (has_strict_fderiv_at.mul' hc hd).has_strict_deriv_at,
rwa [continuous_linear_map.add_apply, continuous_linear_map.smul_apply,
continuous_linear_map.smul_right_apply, continuous_linear_map.smul_right_apply,
continuous_linear_map.smul_right_apply, continuous_linear_map.one_apply,
one_smul, one_smul, add_comm] at this,
end
lemma deriv_within_mul (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) :
deriv_within (λ y, c y * d y) s x = deriv_within c s x * d x + c x * deriv_within d s x :=
(hc.has_deriv_within_at.mul hd.has_deriv_within_at).deriv_within hxs
@[simp] lemma deriv_mul (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) :
deriv (λ y, c y * d y) x = deriv c x * d x + c x * deriv d x :=
(hc.has_deriv_at.mul hd.has_deriv_at).deriv
theorem has_deriv_within_at.mul_const (hc : has_deriv_within_at c c' s x) (d : 𝔸) :
has_deriv_within_at (λ y, c y * d) (c' * d) s x :=
begin
convert hc.mul (has_deriv_within_at_const x s d),
rw [mul_zero, add_zero]
end
theorem has_deriv_at.mul_const (hc : has_deriv_at c c' x) (d : 𝔸) :
has_deriv_at (λ y, c y * d) (c' * d) x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hc.mul_const d
end
theorem has_strict_deriv_at.mul_const (hc : has_strict_deriv_at c c' x) (d : 𝔸) :
has_strict_deriv_at (λ y, c y * d) (c' * d) x :=
begin
convert hc.mul (has_strict_deriv_at_const x d),
rw [mul_zero, add_zero]
end
lemma deriv_within_mul_const (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (d : 𝔸) :
deriv_within (λ y, c y * d) s x = deriv_within c s x * d :=
(hc.has_deriv_within_at.mul_const d).deriv_within hxs
lemma deriv_mul_const (hc : differentiable_at 𝕜 c x) (d : 𝔸) :
deriv (λ y, c y * d) x = deriv c x * d :=
(hc.has_deriv_at.mul_const d).deriv
lemma deriv_mul_const_field (v : 𝕜') :
deriv (λ y, u y * v) x = deriv u x * v :=
begin
by_cases hu : differentiable_at 𝕜 u x,
{ exact deriv_mul_const hu v },
{ rw [deriv_zero_of_not_differentiable_at hu, zero_mul],
rcases eq_or_ne v 0 with rfl|hd,
{ simp only [mul_zero, deriv_const] },
{ refine deriv_zero_of_not_differentiable_at (mt (λ H, _) hu),
simpa only [mul_inv_cancel_right₀ hd] using H.mul_const v⁻¹ } }
end
@[simp] lemma deriv_mul_const_field' (v : 𝕜') : deriv (λ x, u x * v) = λ x, deriv u x * v :=
funext $ λ _, deriv_mul_const_field v
theorem has_deriv_within_at.const_mul (c : 𝔸) (hd : has_deriv_within_at d d' s x) :
has_deriv_within_at (λ y, c * d y) (c * d') s x :=
begin
convert (has_deriv_within_at_const x s c).mul hd,
rw [zero_mul, zero_add]
end
theorem has_deriv_at.const_mul (c : 𝔸) (hd : has_deriv_at d d' x) :
has_deriv_at (λ y, c * d y) (c * d') x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hd.const_mul c
end
theorem has_strict_deriv_at.const_mul (c : 𝔸) (hd : has_strict_deriv_at d d' x) :
has_strict_deriv_at (λ y, c * d y) (c * d') x :=
begin
convert (has_strict_deriv_at_const _ _).mul hd,
rw [zero_mul, zero_add]
end
lemma deriv_within_const_mul (hxs : unique_diff_within_at 𝕜 s x)
(c : 𝔸) (hd : differentiable_within_at 𝕜 d s x) :
deriv_within (λ y, c * d y) s x = c * deriv_within d s x :=
(hd.has_deriv_within_at.const_mul c).deriv_within hxs
lemma deriv_const_mul (c : 𝔸) (hd : differentiable_at 𝕜 d x) :
deriv (λ y, c * d y) x = c * deriv d x :=
(hd.has_deriv_at.const_mul c).deriv
lemma deriv_const_mul_field (u : 𝕜') : deriv (λ y, u * v y) x = u * deriv v x :=
by simp only [mul_comm u, deriv_mul_const_field]
@[simp] lemma deriv_const_mul_field' (u : 𝕜') : deriv (λ x, u * v x) = λ x, u * deriv v x :=
funext (λ x, deriv_const_mul_field u)
end mul
section inverse
/-! ### Derivative of `x ↦ x⁻¹` -/
theorem has_strict_deriv_at_inv (hx : x ≠ 0) : has_strict_deriv_at has_inv.inv (-(x^2)⁻¹) x :=
begin
suffices : is_o (λ p : 𝕜 × 𝕜, (p.1 - p.2) * ((x * x)⁻¹ - (p.1 * p.2)⁻¹))
(λ (p : 𝕜 × 𝕜), (p.1 - p.2) * 1) (𝓝 (x, x)),
{ refine this.congr' _ (eventually_of_forall $ λ _, mul_one _),
refine eventually.mono (is_open.mem_nhds (is_open_ne.prod is_open_ne) ⟨hx, hx⟩) _,
rintro ⟨y, z⟩ ⟨hy, hz⟩,
simp only [mem_set_of_eq] at hy hz, -- hy : y ≠ 0, hz : z ≠ 0
field_simp [hx, hy, hz], ring, },
refine (is_O_refl (λ p : 𝕜 × 𝕜, p.1 - p.2) _).mul_is_o ((is_o_one_iff _).2 _),
rw [← sub_self (x * x)⁻¹],
exact tendsto_const_nhds.sub ((continuous_mul.tendsto (x, x)).inv₀ $ mul_ne_zero hx hx)
end
theorem has_deriv_at_inv (x_ne_zero : x ≠ 0) :
has_deriv_at (λy, y⁻¹) (-(x^2)⁻¹) x :=
(has_strict_deriv_at_inv x_ne_zero).has_deriv_at
theorem has_deriv_within_at_inv (x_ne_zero : x ≠ 0) (s : set 𝕜) :
has_deriv_within_at (λx, x⁻¹) (-(x^2)⁻¹) s x :=
(has_deriv_at_inv x_ne_zero).has_deriv_within_at
lemma differentiable_at_inv :
differentiable_at 𝕜 (λx, x⁻¹) x ↔ x ≠ 0:=
⟨λ H, normed_field.continuous_at_inv.1 H.continuous_at,
λ H, (has_deriv_at_inv H).differentiable_at⟩
lemma differentiable_within_at_inv (x_ne_zero : x ≠ 0) :
differentiable_within_at 𝕜 (λx, x⁻¹) s x :=
(differentiable_at_inv.2 x_ne_zero).differentiable_within_at
lemma differentiable_on_inv : differentiable_on 𝕜 (λx:𝕜, x⁻¹) {x | x ≠ 0} :=
λx hx, differentiable_within_at_inv hx
lemma deriv_inv : deriv (λx, x⁻¹) x = -(x^2)⁻¹ :=
begin
rcases eq_or_ne x 0 with rfl|hne,
{ simp [deriv_zero_of_not_differentiable_at (mt differentiable_at_inv.1 (not_not.2 rfl))] },
{ exact (has_deriv_at_inv hne).deriv }
end
@[simp] lemma deriv_inv' : deriv (λ x : 𝕜, x⁻¹) = λ x, -(x ^ 2)⁻¹ := funext (λ x, deriv_inv)
lemma deriv_within_inv (x_ne_zero : x ≠ 0) (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, x⁻¹) s x = -(x^2)⁻¹ :=
begin
rw differentiable_at.deriv_within (differentiable_at_inv.2 x_ne_zero) hxs,
exact deriv_inv
end
lemma has_fderiv_at_inv (x_ne_zero : x ≠ 0) :
has_fderiv_at (λx, x⁻¹) (smul_right (1 : 𝕜 →L[𝕜] 𝕜) (-(x^2)⁻¹) : 𝕜 →L[𝕜] 𝕜) x :=
has_deriv_at_inv x_ne_zero
lemma has_fderiv_within_at_inv (x_ne_zero : x ≠ 0) :
has_fderiv_within_at (λx, x⁻¹) (smul_right (1 : 𝕜 →L[𝕜] 𝕜) (-(x^2)⁻¹) : 𝕜 →L[𝕜] 𝕜) s x :=
(has_fderiv_at_inv x_ne_zero).has_fderiv_within_at
lemma fderiv_inv :
fderiv 𝕜 (λx, x⁻¹) x = smul_right (1 : 𝕜 →L[𝕜] 𝕜) (-(x^2)⁻¹) :=
by rw [← deriv_fderiv, deriv_inv]
lemma fderiv_within_inv (x_ne_zero : x ≠ 0) (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (λx, x⁻¹) s x = smul_right (1 : 𝕜 →L[𝕜] 𝕜) (-(x^2)⁻¹) :=
begin
rw differentiable_at.fderiv_within (differentiable_at_inv.2 x_ne_zero) hxs,
exact fderiv_inv
end
variables {c : 𝕜 → 𝕜} {c' : 𝕜}
lemma has_deriv_within_at.inv
(hc : has_deriv_within_at c c' s x) (hx : c x ≠ 0) :
has_deriv_within_at (λ y, (c y)⁻¹) (- c' / (c x)^2) s x :=
begin
convert (has_deriv_at_inv hx).comp_has_deriv_within_at x hc,
field_simp
end
lemma has_deriv_at.inv (hc : has_deriv_at c c' x) (hx : c x ≠ 0) :
has_deriv_at (λ y, (c y)⁻¹) (- c' / (c x)^2) x :=
begin
rw ← has_deriv_within_at_univ at *,
exact hc.inv hx
end
lemma differentiable_within_at.inv (hc : differentiable_within_at 𝕜 c s x) (hx : c x ≠ 0) :
differentiable_within_at 𝕜 (λx, (c x)⁻¹) s x :=
(hc.has_deriv_within_at.inv hx).differentiable_within_at
@[simp] lemma differentiable_at.inv (hc : differentiable_at 𝕜 c x) (hx : c x ≠ 0) :
differentiable_at 𝕜 (λx, (c x)⁻¹) x :=
(hc.has_deriv_at.inv hx).differentiable_at
lemma differentiable_on.inv (hc : differentiable_on 𝕜 c s) (hx : ∀ x ∈ s, c x ≠ 0) :
differentiable_on 𝕜 (λx, (c x)⁻¹) s :=
λx h, (hc x h).inv (hx x h)
@[simp] lemma differentiable.inv (hc : differentiable 𝕜 c) (hx : ∀ x, c x ≠ 0) :
differentiable 𝕜 (λx, (c x)⁻¹) :=
λx, (hc x).inv (hx x)
lemma deriv_within_inv' (hc : differentiable_within_at 𝕜 c s x) (hx : c x ≠ 0)
(hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, (c x)⁻¹) s x = - (deriv_within c s x) / (c x)^2 :=
(hc.has_deriv_within_at.inv hx).deriv_within hxs
@[simp] lemma deriv_inv'' (hc : differentiable_at 𝕜 c x) (hx : c x ≠ 0) :
deriv (λx, (c x)⁻¹) x = - (deriv c x) / (c x)^2 :=
(hc.has_deriv_at.inv hx).deriv
end inverse
section division
/-! ### Derivative of `x ↦ c x / d x` -/
variables {c d : 𝕜 → 𝕜} {c' d' : 𝕜}
lemma has_deriv_within_at.div
(hc : has_deriv_within_at c c' s x) (hd : has_deriv_within_at d d' s x) (hx : d x ≠ 0) :
has_deriv_within_at (λ y, c y / d y) ((c' * d x - c x * d') / (d x)^2) s x :=
begin
convert hc.mul ((has_deriv_at_inv hx).comp_has_deriv_within_at x hd),
{ simp only [div_eq_mul_inv] },
{ field_simp, ring }
end
lemma has_strict_deriv_at.div (hc : has_strict_deriv_at c c' x) (hd : has_strict_deriv_at d d' x)
(hx : d x ≠ 0) :
has_strict_deriv_at (λ y, c y / d y) ((c' * d x - c x * d') / (d x)^2) x :=
begin
convert hc.mul ((has_strict_deriv_at_inv hx).comp x hd),
{ simp only [div_eq_mul_inv] },
{ field_simp, ring }
end
lemma has_deriv_at.div (hc : has_deriv_at c c' x) (hd : has_deriv_at d d' x) (hx : d x ≠ 0) :
has_deriv_at (λ y, c y / d y) ((c' * d x - c x * d') / (d x)^2) x :=
begin
rw ← has_deriv_within_at_univ at *,
exact hc.div hd hx
end
lemma differentiable_within_at.div
(hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) (hx : d x ≠ 0) :
differentiable_within_at 𝕜 (λx, c x / d x) s x :=
((hc.has_deriv_within_at).div (hd.has_deriv_within_at) hx).differentiable_within_at
@[simp] lemma differentiable_at.div
(hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) (hx : d x ≠ 0) :
differentiable_at 𝕜 (λx, c x / d x) x :=
((hc.has_deriv_at).div (hd.has_deriv_at) hx).differentiable_at
lemma differentiable_on.div
(hc : differentiable_on 𝕜 c s) (hd : differentiable_on 𝕜 d s) (hx : ∀ x ∈ s, d x ≠ 0) :
differentiable_on 𝕜 (λx, c x / d x) s :=
λx h, (hc x h).div (hd x h) (hx x h)
@[simp] lemma differentiable.div
(hc : differentiable 𝕜 c) (hd : differentiable 𝕜 d) (hx : ∀ x, d x ≠ 0) :
differentiable 𝕜 (λx, c x / d x) :=
λx, (hc x).div (hd x) (hx x)
lemma deriv_within_div
(hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) (hx : d x ≠ 0)
(hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, c x / d x) s x
= ((deriv_within c s x) * d x - c x * (deriv_within d s x)) / (d x)^2 :=
((hc.has_deriv_within_at).div (hd.has_deriv_within_at) hx).deriv_within hxs
@[simp] lemma deriv_div
(hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) (hx : d x ≠ 0) :
deriv (λx, c x / d x) x = ((deriv c x) * d x - c x * (deriv d x)) / (d x)^2 :=
((hc.has_deriv_at).div (hd.has_deriv_at) hx).deriv
lemma differentiable_within_at.div_const (hc : differentiable_within_at 𝕜 c s x) {d : 𝕜} :
differentiable_within_at 𝕜 (λx, c x / d) s x :=
by simp [div_eq_inv_mul, differentiable_within_at.const_mul, hc]
@[simp] lemma differentiable_at.div_const (hc : differentiable_at 𝕜 c x) {d : 𝕜} :
differentiable_at 𝕜 (λ x, c x / d) x :=
by simpa only [div_eq_mul_inv] using (hc.has_deriv_at.mul_const d⁻¹).differentiable_at
lemma differentiable_on.div_const (hc : differentiable_on 𝕜 c s) {d : 𝕜} :
differentiable_on 𝕜 (λx, c x / d) s :=
by simp [div_eq_inv_mul, differentiable_on.const_mul, hc]
@[simp] lemma differentiable.div_const (hc : differentiable 𝕜 c) {d : 𝕜} :
differentiable 𝕜 (λx, c x / d) :=
by simp [div_eq_inv_mul, differentiable.const_mul, hc]
lemma deriv_within_div_const (hc : differentiable_within_at 𝕜 c s x) {d : 𝕜}
(hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, c x / d) s x = (deriv_within c s x) / d :=
by simp [div_eq_inv_mul, deriv_within_const_mul, hc, hxs]
@[simp] lemma deriv_div_const (d : 𝕜) :
deriv (λx, c x / d) x = (deriv c x) / d :=
by simp only [div_eq_mul_inv, deriv_mul_const_field]
end division
section clm_comp_apply
/-! ### Derivative of the pointwise composition/application of continuous linear maps -/
open continuous_linear_map
variables {G : Type*} [normed_group G] [normed_space 𝕜 G] {c : 𝕜 → F →L[𝕜] G} {c' : F →L[𝕜] G}
{d : 𝕜 → E →L[𝕜] F} {d' : E →L[𝕜] F} {u : 𝕜 → F} {u' : F}
lemma has_strict_deriv_at.clm_comp (hc : has_strict_deriv_at c c' x)
(hd : has_strict_deriv_at d d' x) :
has_strict_deriv_at (λ y, (c y).comp (d y)) (c'.comp (d x) + (c x).comp d') x :=
begin
have := (hc.has_strict_fderiv_at.clm_comp hd.has_strict_fderiv_at).has_strict_deriv_at,
rwa [add_apply, comp_apply, comp_apply, smul_right_apply, smul_right_apply, one_apply, one_smul,
one_smul, add_comm] at this,
end
lemma has_deriv_within_at.clm_comp (hc : has_deriv_within_at c c' s x)
(hd : has_deriv_within_at d d' s x) :
has_deriv_within_at (λ y, (c y).comp (d y)) (c'.comp (d x) + (c x).comp d') s x :=
begin
have := (hc.has_fderiv_within_at.clm_comp hd.has_fderiv_within_at).has_deriv_within_at,
rwa [add_apply, comp_apply, comp_apply, smul_right_apply, smul_right_apply, one_apply, one_smul,
one_smul, add_comm] at this,
end
lemma has_deriv_at.clm_comp (hc : has_deriv_at c c' x) (hd : has_deriv_at d d' x) :
has_deriv_at (λ y, (c y).comp (d y))
(c'.comp (d x) + (c x).comp d') x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hc.clm_comp hd
end
lemma deriv_within_clm_comp (hc : differentiable_within_at 𝕜 c s x)
(hd : differentiable_within_at 𝕜 d s x) (hxs : unique_diff_within_at 𝕜 s x):
deriv_within (λ y, (c y).comp (d y)) s x =
((deriv_within c s x).comp (d x) + (c x).comp (deriv_within d s x)) :=
(hc.has_deriv_within_at.clm_comp hd.has_deriv_within_at).deriv_within hxs
lemma deriv_clm_comp (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) :
deriv (λ y, (c y).comp (d y)) x =
((deriv c x).comp (d x) + (c x).comp (deriv d x)) :=
(hc.has_deriv_at.clm_comp hd.has_deriv_at).deriv
lemma has_strict_deriv_at.clm_apply (hc : has_strict_deriv_at c c' x)
(hu : has_strict_deriv_at u u' x) :
has_strict_deriv_at (λ y, (c y) (u y)) (c' (u x) + c x u') x :=
begin
have := (hc.has_strict_fderiv_at.clm_apply hu.has_strict_fderiv_at).has_strict_deriv_at,
rwa [add_apply, comp_apply, flip_apply, smul_right_apply, smul_right_apply, one_apply, one_smul,
one_smul, add_comm] at this,
end
lemma has_deriv_within_at.clm_apply (hc : has_deriv_within_at c c' s x)
(hu : has_deriv_within_at u u' s x) :
has_deriv_within_at (λ y, (c y) (u y)) (c' (u x) + c x u') s x :=
begin
have := (hc.has_fderiv_within_at.clm_apply hu.has_fderiv_within_at).has_deriv_within_at,
rwa [add_apply, comp_apply, flip_apply, smul_right_apply, smul_right_apply, one_apply, one_smul,
one_smul, add_comm] at this,
end
lemma has_deriv_at.clm_apply (hc : has_deriv_at c c' x) (hu : has_deriv_at u u' x) :
has_deriv_at (λ y, (c y) (u y)) (c' (u x) + c x u') x :=
begin
have := (hc.has_fderiv_at.clm_apply hu.has_fderiv_at).has_deriv_at,
rwa [add_apply, comp_apply, flip_apply, smul_right_apply, smul_right_apply, one_apply, one_smul,
one_smul, add_comm] at this,
end
lemma deriv_within_clm_apply (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (hu : differentiable_within_at 𝕜 u s x) :
deriv_within (λ y, (c y) (u y)) s x = (deriv_within c s x (u x) + c x (deriv_within u s x)) :=
(hc.has_deriv_within_at.clm_apply hu.has_deriv_within_at).deriv_within hxs
lemma deriv_clm_apply (hc : differentiable_at 𝕜 c x) (hu : differentiable_at 𝕜 u x) :
deriv (λ y, (c y) (u y)) x = (deriv c x (u x) + c x (deriv u x)) :=
(hc.has_deriv_at.clm_apply hu.has_deriv_at).deriv
end clm_comp_apply
theorem has_strict_deriv_at.has_strict_fderiv_at_equiv {f : 𝕜 → 𝕜} {f' x : 𝕜}
(hf : has_strict_deriv_at f f' x) (hf' : f' ≠ 0) :
has_strict_fderiv_at f
(continuous_linear_equiv.units_equiv_aut 𝕜 (units.mk0 f' hf') : 𝕜 →L[𝕜] 𝕜) x :=
hf
theorem has_deriv_at.has_fderiv_at_equiv {f : 𝕜 → 𝕜} {f' x : 𝕜}
(hf : has_deriv_at f f' x) (hf' : f' ≠ 0) :
has_fderiv_at f
(continuous_linear_equiv.units_equiv_aut 𝕜 (units.mk0 f' hf') : 𝕜 →L[𝕜] 𝕜) x :=
hf
/-- 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_deriv_at.of_local_left_inverse {f g : 𝕜 → 𝕜} {f' a : 𝕜}
(hg : continuous_at g a) (hf : has_strict_deriv_at f f' (g a)) (hf' : f' ≠ 0)
(hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) :
has_strict_deriv_at g f'⁻¹ a :=
(hf.has_strict_fderiv_at_equiv hf').of_local_left_inverse hg hfg
/-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has a
nonzero derivative `f'` at `f.symm a` in the strict sense, then `f.symm` 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. -/
lemma local_homeomorph.has_strict_deriv_at_symm (f : local_homeomorph 𝕜 𝕜) {a f' : 𝕜}
(ha : a ∈ f.target) (hf' : f' ≠ 0) (htff' : has_strict_deriv_at f f' (f.symm a)) :
has_strict_deriv_at f.symm f'⁻¹ a :=
htff'.of_local_left_inverse (f.symm.continuous_at ha) hf' (f.eventually_right_inverse ha)
/-- 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_deriv_at.of_local_left_inverse {f g : 𝕜 → 𝕜} {f' a : 𝕜}
(hg : continuous_at g a) (hf : has_deriv_at f f' (g a)) (hf' : f' ≠ 0)
(hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) :
has_deriv_at g f'⁻¹ a :=
(hf.has_fderiv_at_equiv hf').of_local_left_inverse hg hfg
/-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has an
nonzero 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_deriv_at_symm (f : local_homeomorph 𝕜 𝕜) {a f' : 𝕜}
(ha : a ∈ f.target) (hf' : f' ≠ 0) (htff' : has_deriv_at f f' (f.symm a)) :
has_deriv_at f.symm f'⁻¹ a :=
htff'.of_local_left_inverse (f.symm.continuous_at ha) hf' (f.eventually_right_inverse ha)
lemma has_deriv_at.eventually_ne (h : has_deriv_at f f' x) (hf' : f' ≠ 0) :
∀ᶠ z in 𝓝[{x}ᶜ] x, f z ≠ f x :=
(has_deriv_at_iff_has_fderiv_at.1 h).eventually_ne
⟨∥f'∥⁻¹, λ z, by field_simp [norm_smul, mt norm_eq_zero.1 hf']⟩
theorem not_differentiable_within_at_of_local_left_inverse_has_deriv_within_at_zero
{f g : 𝕜 → 𝕜} {a : 𝕜} {s t : set 𝕜} (ha : a ∈ s) (hsu : unique_diff_within_at 𝕜 s a)
(hf : has_deriv_within_at f 0 t (g a)) (hst : maps_to g s t) (hfg : f ∘ g =ᶠ[𝓝[s] a] id) :
¬differentiable_within_at 𝕜 g s a :=
begin
intro hg,
have := (hf.comp a hg.has_deriv_within_at hst).congr_of_eventually_eq_of_mem hfg.symm ha,
simpa using hsu.eq_deriv _ this (has_deriv_within_at_id _ _)
end
theorem not_differentiable_at_of_local_left_inverse_has_deriv_at_zero
{f g : 𝕜 → 𝕜} {a : 𝕜} (hf : has_deriv_at f 0 (g a)) (hfg : f ∘ g =ᶠ[𝓝 a] id) :
¬differentiable_at 𝕜 g a :=
begin
intro hg,
have := (hf.comp a hg.has_deriv_at).congr_of_eventually_eq hfg.symm,
simpa using this.unique (has_deriv_at_id a)
end
end
namespace polynomial
/-! ### Derivative of a polynomial -/
variables {x : 𝕜} {s : set 𝕜}
variable (p : polynomial 𝕜)
/-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/
protected lemma has_strict_deriv_at (x : 𝕜) :
has_strict_deriv_at (λx, p.eval x) (p.derivative.eval x) x :=
begin
apply p.induction_on,
{ simp [has_strict_deriv_at_const] },
{ assume p q hp hq,
convert hp.add hq;
simp },
{ assume n a h,
convert h.mul (has_strict_deriv_at_id x),
{ ext y, simp [pow_add, mul_assoc] },
{ simp [pow_add], ring } }
end
/-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/
protected lemma has_deriv_at (x : 𝕜) : has_deriv_at (λx, p.eval x) (p.derivative.eval x) x :=
(p.has_strict_deriv_at x).has_deriv_at
protected theorem has_deriv_within_at (x : 𝕜) (s : set 𝕜) :
has_deriv_within_at (λx, p.eval x) (p.derivative.eval x) s x :=
(p.has_deriv_at x).has_deriv_within_at
protected lemma differentiable_at : differentiable_at 𝕜 (λx, p.eval x) x :=
(p.has_deriv_at x).differentiable_at
protected lemma differentiable_within_at : differentiable_within_at 𝕜 (λx, p.eval x) s x :=
p.differentiable_at.differentiable_within_at
protected lemma differentiable : differentiable 𝕜 (λx, p.eval x) :=
λx, p.differentiable_at
protected lemma differentiable_on : differentiable_on 𝕜 (λx, p.eval x) s :=
p.differentiable.differentiable_on
@[simp] protected lemma deriv : deriv (λx, p.eval x) x = p.derivative.eval x :=
(p.has_deriv_at x).deriv
protected lemma deriv_within (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, p.eval x) s x = p.derivative.eval x :=
begin
rw differentiable_at.deriv_within p.differentiable_at hxs,
exact p.deriv
end
protected lemma has_fderiv_at (x : 𝕜) :
has_fderiv_at (λx, p.eval x) (smul_right (1 : 𝕜 →L[𝕜] 𝕜) (p.derivative.eval x)) x :=
p.has_deriv_at x
protected lemma has_fderiv_within_at (x : 𝕜) :
has_fderiv_within_at (λx, p.eval x) (smul_right (1 : 𝕜 →L[𝕜] 𝕜) (p.derivative.eval x)) s x :=
(p.has_fderiv_at x).has_fderiv_within_at
@[simp] protected lemma fderiv :
fderiv 𝕜 (λx, p.eval x) x = smul_right (1 : 𝕜 →L[𝕜] 𝕜) (p.derivative.eval x) :=
(p.has_fderiv_at x).fderiv
protected lemma fderiv_within (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (λx, p.eval x) s x = smul_right (1 : 𝕜 →L[𝕜] 𝕜) (p.derivative.eval x) :=
(p.has_fderiv_within_at x).fderiv_within hxs
end polynomial
section pow
/-! ### Derivative of `x ↦ x^n` for `n : ℕ` -/
variables {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} {c' : 𝕜}
variable {n : ℕ }
lemma has_strict_deriv_at_pow (n : ℕ) (x : 𝕜) :
has_strict_deriv_at (λx, x^n) ((n : 𝕜) * x^(n-1)) x :=
begin
convert (polynomial.C (1 : 𝕜) * (polynomial.X)^n).has_strict_deriv_at x,
{ simp },
{ rw [polynomial.derivative_C_mul_X_pow], simp }
end
lemma has_deriv_at_pow (n : ℕ) (x : 𝕜) : has_deriv_at (λx, x^n) ((n : 𝕜) * x^(n-1)) x :=
(has_strict_deriv_at_pow n x).has_deriv_at
theorem has_deriv_within_at_pow (n : ℕ) (x : 𝕜) (s : set 𝕜) :
has_deriv_within_at (λx, x^n) ((n : 𝕜) * x^(n-1)) s x :=
(has_deriv_at_pow n x).has_deriv_within_at
lemma differentiable_at_pow : differentiable_at 𝕜 (λx, x^n) x :=
(has_deriv_at_pow n x).differentiable_at
lemma differentiable_within_at_pow : differentiable_within_at 𝕜 (λx, x^n) s x :=
differentiable_at_pow.differentiable_within_at
lemma differentiable_pow : differentiable 𝕜 (λx:𝕜, x^n) :=
λx, differentiable_at_pow
lemma differentiable_on_pow : differentiable_on 𝕜 (λx, x^n) s :=
differentiable_pow.differentiable_on
lemma deriv_pow : deriv (λx, x^n) x = (n : 𝕜) * x^(n-1) :=
(has_deriv_at_pow n x).deriv
@[simp] lemma deriv_pow' : deriv (λx, x^n) = λ x, (n : 𝕜) * x^(n-1) :=
funext $ λ x, deriv_pow
lemma deriv_within_pow (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, x^n) s x = (n : 𝕜) * x^(n-1) :=
(has_deriv_within_at_pow n x s).deriv_within hxs
lemma has_deriv_within_at.pow (hc : has_deriv_within_at c c' s x) :
has_deriv_within_at (λ y, (c y)^n) ((n : 𝕜) * (c x)^(n-1) * c') s x :=
(has_deriv_at_pow n (c x)).comp_has_deriv_within_at x hc
lemma has_deriv_at.pow (hc : has_deriv_at c c' x) :
has_deriv_at (λ y, (c y)^n) ((n : 𝕜) * (c x)^(n-1) * c') x :=
by { rw ← has_deriv_within_at_univ at *, exact hc.pow }
lemma differentiable_within_at.pow (hc : differentiable_within_at 𝕜 c s x) :
differentiable_within_at 𝕜 (λx, (c x)^n) s x :=
hc.has_deriv_within_at.pow.differentiable_within_at
@[simp] lemma differentiable_at.pow (hc : differentiable_at 𝕜 c x) :
differentiable_at 𝕜 (λx, (c x)^n) x :=
hc.has_deriv_at.pow.differentiable_at
lemma differentiable_on.pow (hc : differentiable_on 𝕜 c s) :
differentiable_on 𝕜 (λx, (c x)^n) s :=
λx h, (hc x h).pow
@[simp] lemma differentiable.pow (hc : differentiable 𝕜 c) :
differentiable 𝕜 (λx, (c x)^n) :=
λx, (hc x).pow
lemma deriv_within_pow' (hc : differentiable_within_at 𝕜 c s x)
(hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, (c x)^n) s x = (n : 𝕜) * (c x)^(n-1) * (deriv_within c s x) :=
hc.has_deriv_within_at.pow.deriv_within hxs
@[simp] lemma deriv_pow'' (hc : differentiable_at 𝕜 c x) :
deriv (λx, (c x)^n) x = (n : 𝕜) * (c x)^(n-1) * (deriv c x) :=
hc.has_deriv_at.pow.deriv
end pow
section fpow
/-! ### Derivative of `x ↦ x^m` for `m : ℤ` -/
variables {x : 𝕜} {s : set 𝕜} {m : ℤ}
lemma has_strict_deriv_at_fpow (m : ℤ) (x : 𝕜) (h : x ≠ 0 ∨ 0 ≤ m) :
has_strict_deriv_at (λx, x^m) ((m : 𝕜) * x^(m-1)) x :=
begin
have : ∀ m : ℤ, 0 < m → has_strict_deriv_at (λx, x^m) ((m:𝕜) * x^(m-1)) x,
{ assume m hm,
lift m to ℕ using (le_of_lt hm),
simp only [gpow_coe_nat, int.cast_coe_nat],
convert has_strict_deriv_at_pow _ _ using 2,
rw [← int.coe_nat_one, ← int.coe_nat_sub, gpow_coe_nat],
norm_cast at hm,
exact nat.succ_le_of_lt hm },
rcases lt_trichotomy m 0 with hm|hm|hm,
{ have hx : x ≠ 0, from h.resolve_right hm.not_le,
have := (has_strict_deriv_at_inv _).scomp _ (this (-m) (neg_pos.2 hm));
[skip, exact fpow_ne_zero_of_ne_zero hx _],
simp only [(∘), fpow_neg, one_div, inv_inv₀, smul_eq_mul] at this,
convert this using 1,
rw [sq, mul_inv₀, inv_inv₀, int.cast_neg, ← neg_mul_eq_neg_mul, neg_mul_neg,
← fpow_add hx, mul_assoc, ← fpow_add hx], congr, abel },
{ simp only [hm, gpow_zero, int.cast_zero, zero_mul, has_strict_deriv_at_const] },
{ exact this m hm }
end
lemma has_deriv_at_fpow (m : ℤ) (x : 𝕜) (h : x ≠ 0 ∨ 0 ≤ m) :
has_deriv_at (λx, x^m) ((m : 𝕜) * x^(m-1)) x :=
(has_strict_deriv_at_fpow m x h).has_deriv_at
theorem has_deriv_within_at_fpow (m : ℤ) (x : 𝕜) (h : x ≠ 0 ∨ 0 ≤ m) (s : set 𝕜) :
has_deriv_within_at (λx, x^m) ((m : 𝕜) * x^(m-1)) s x :=
(has_deriv_at_fpow m x h).has_deriv_within_at
lemma differentiable_at_fpow : differentiable_at 𝕜 (λx, x^m) x ↔ x ≠ 0 ∨ 0 ≤ m :=
⟨λ H, normed_field.continuous_at_fpow.1 H.continuous_at,
λ H, (has_deriv_at_fpow m x H).differentiable_at⟩
lemma differentiable_within_at_fpow (m : ℤ) (x : 𝕜) (h : x ≠ 0 ∨ 0 ≤ m) :
differentiable_within_at 𝕜 (λx, x^m) s x :=
(differentiable_at_fpow.mpr h).differentiable_within_at
lemma differentiable_on_fpow (m : ℤ) (s : set 𝕜) (h : (0 : 𝕜) ∉ s ∨ 0 ≤ m) :
differentiable_on 𝕜 (λx, x^m) s :=
λ x hxs, differentiable_within_at_fpow m x $ h.imp_left $ ne_of_mem_of_not_mem hxs
lemma deriv_fpow (m : ℤ) (x : 𝕜) : deriv (λ x, x ^ m) x = m * x ^ (m - 1) :=
begin
by_cases H : x ≠ 0 ∨ 0 ≤ m,
{ exact (has_deriv_at_fpow m x H).deriv },
{ rw deriv_zero_of_not_differentiable_at (mt differentiable_at_fpow.1 H),
push_neg at H, rcases H with ⟨rfl, hm⟩,
rw [zero_fpow _ ((sub_one_lt _).trans hm).ne, mul_zero] }
end
@[simp] lemma deriv_fpow' (m : ℤ) : deriv (λ x : 𝕜, x ^ m) = λ x, m * x ^ (m - 1) :=
funext $ deriv_fpow m
lemma deriv_within_fpow (hxs : unique_diff_within_at 𝕜 s x) (h : x ≠ 0 ∨ 0 ≤ m) :
deriv_within (λx, x^m) s x = (m : 𝕜) * x^(m-1) :=
(has_deriv_within_at_fpow m x h s).deriv_within hxs
@[simp] lemma iter_deriv_fpow' (m : ℤ) (k : ℕ) :
deriv^[k] (λ x : 𝕜, x ^ m) = λ x, (∏ i in finset.range k, (m - i)) * x ^ (m - k) :=
begin
induction k with k ihk,
{ simp only [one_mul, int.coe_nat_zero, id, sub_zero, finset.prod_range_zero,
function.iterate_zero] },
{ simp only [function.iterate_succ_apply', ihk, deriv_const_mul_field', deriv_fpow',
finset.prod_range_succ, int.coe_nat_succ, ← sub_sub, int.cast_sub, int.cast_coe_nat,
mul_assoc], }
end
lemma iter_deriv_fpow (m : ℤ) (x : 𝕜) (k : ℕ) :
deriv^[k] (λ y, y ^ m) x = (∏ i in finset.range k, (m - i)) * x ^ (m - k) :=
congr_fun (iter_deriv_fpow' m k) x
lemma iter_deriv_pow (n : ℕ) (x : 𝕜) (k : ℕ) :
deriv^[k] (λx:𝕜, x^n) x = (∏ i in finset.range k, (n - i)) * x^(n-k) :=
begin
simp only [← gpow_coe_nat, iter_deriv_fpow, int.cast_coe_nat],
cases le_or_lt k n with hkn hnk,
{ rw int.coe_nat_sub hkn },
{ have : ∏ i in finset.range k, (n - i : 𝕜) = 0,
from finset.prod_eq_zero (finset.mem_range.2 hnk) (sub_self _),
simp only [this, zero_mul] }
end
@[simp] lemma iter_deriv_pow' (n k : ℕ) :
deriv^[k] (λ x : 𝕜, x ^ n) = λ x, (∏ i in finset.range k, (n - i)) * x ^ (n - k) :=
funext $ λ x, iter_deriv_pow n x k
lemma iter_deriv_inv (k : ℕ) (x : 𝕜) :
deriv^[k] has_inv.inv x = (∏ i in finset.range k, (-1 - i)) * x ^ (-1 - k : ℤ) :=
by simpa only [fpow_neg_one, int.cast_neg, int.cast_one] using iter_deriv_fpow (-1) x k
@[simp] lemma iter_deriv_inv' (k : ℕ) :
deriv^[k] has_inv.inv = λ x : 𝕜, (∏ i in finset.range k, (-1 - i)) * x ^ (-1 - k : ℤ) :=
funext (iter_deriv_inv k)
end fpow
/-! ### Upper estimates on liminf and limsup -/
section real
variables {f : ℝ → ℝ} {f' : ℝ} {s : set ℝ} {x : ℝ} {r : ℝ}
lemma has_deriv_within_at.limsup_slope_le (hf : has_deriv_within_at f f' s x) (hr : f' < r) :
∀ᶠ z in 𝓝[s \ {x}] x, (z - x)⁻¹ * (f z - f x) < r :=
has_deriv_within_at_iff_tendsto_slope.1 hf (is_open.mem_nhds is_open_Iio hr)
lemma has_deriv_within_at.limsup_slope_le' (hf : has_deriv_within_at f f' s x)
(hs : x ∉ s) (hr : f' < r) :
∀ᶠ z in 𝓝[s] x, (z - x)⁻¹ * (f z - f x) < r :=
(has_deriv_within_at_iff_tendsto_slope' hs).1 hf (is_open.mem_nhds is_open_Iio hr)
lemma has_deriv_within_at.liminf_right_slope_le
(hf : has_deriv_within_at f f' (Ici x) x) (hr : f' < r) :
∃ᶠ z in 𝓝[Ioi x] x, (z - x)⁻¹ * (f z - f x) < r :=
(hf.Ioi_of_Ici.limsup_slope_le' (lt_irrefl x) hr).frequently
end real
section real_space
open metric
variables {E : Type u} [normed_group E] [normed_space ℝ E] {f : ℝ → E} {f' : E} {s : set ℝ}
{x r : ℝ}
/-- If `f` has derivative `f'` within `s` at `x`, then for any `r > ∥f'∥` the ratio
`∥f z - f x∥ / ∥z - x∥` is less than `r` in some neighborhood of `x` within `s`.
In other words, the limit superior of this ratio as `z` tends to `x` along `s`
is less than or equal to `∥f'∥`. -/
lemma has_deriv_within_at.limsup_norm_slope_le
(hf : has_deriv_within_at f f' s x) (hr : ∥f'∥ < r) :
∀ᶠ z in 𝓝[s] x, ∥z - x∥⁻¹ * ∥f z - f x∥ < r :=
begin
have hr₀ : 0 < r, from lt_of_le_of_lt (norm_nonneg f') hr,
have A : ∀ᶠ z in 𝓝[s \ {x}] x, ∥(z - x)⁻¹ • (f z - f x)∥ ∈ Iio r,
from (has_deriv_within_at_iff_tendsto_slope.1 hf).norm (is_open.mem_nhds is_open_Iio hr),
have B : ∀ᶠ z in 𝓝[{x}] x, ∥(z - x)⁻¹ • (f z - f x)∥ ∈ Iio r,
from mem_of_superset self_mem_nhds_within
(singleton_subset_iff.2 $ by simp [hr₀]),
have C := mem_sup.2 ⟨A, B⟩,
rw [← nhds_within_union, diff_union_self, nhds_within_union, mem_sup] at C,
filter_upwards [C.1],
simp only [norm_smul, mem_Iio, normed_field.norm_inv],
exact λ _, id
end
/-- If `f` has derivative `f'` within `s` at `x`, then for any `r > ∥f'∥` the ratio
`(∥f z∥ - ∥f x∥) / ∥z - x∥` is less than `r` in some neighborhood of `x` within `s`.
In other words, the limit superior of this ratio as `z` tends to `x` along `s`
is less than or equal to `∥f'∥`.
This lemma is a weaker version of `has_deriv_within_at.limsup_norm_slope_le`
where `∥f z∥ - ∥f x∥` is replaced by `∥f z - f x∥`. -/
lemma has_deriv_within_at.limsup_slope_norm_le
(hf : has_deriv_within_at f f' s x) (hr : ∥f'∥ < r) :
∀ᶠ z in 𝓝[s] x, ∥z - x∥⁻¹ * (∥f z∥ - ∥f x∥) < r :=
begin
apply (hf.limsup_norm_slope_le hr).mono,
assume z hz,
refine lt_of_le_of_lt (mul_le_mul_of_nonneg_left (norm_sub_norm_le _ _) _) hz,
exact inv_nonneg.2 (norm_nonneg _)
end
/-- If `f` has derivative `f'` within `(x, +∞)` at `x`, then for any `r > ∥f'∥` the ratio
`∥f z - f x∥ / ∥z - x∥` is frequently less than `r` as `z → x+0`.
In other words, the limit inferior of this ratio as `z` tends to `x+0`
is less than or equal to `∥f'∥`. See also `has_deriv_within_at.limsup_norm_slope_le`
for a stronger version using limit superior and any set `s`. -/
lemma has_deriv_within_at.liminf_right_norm_slope_le
(hf : has_deriv_within_at f f' (Ici x) x) (hr : ∥f'∥ < r) :
∃ᶠ z in 𝓝[Ioi x] x, ∥z - x∥⁻¹ * ∥f z - f x∥ < r :=
(hf.Ioi_of_Ici.limsup_norm_slope_le hr).frequently
/-- If `f` has derivative `f'` within `(x, +∞)` at `x`, then for any `r > ∥f'∥` the ratio
`(∥f z∥ - ∥f x∥) / (z - x)` is frequently less than `r` as `z → x+0`.
In other words, the limit inferior of this ratio as `z` tends to `x+0`
is less than or equal to `∥f'∥`.
See also
* `has_deriv_within_at.limsup_norm_slope_le` for a stronger version using
limit superior and any set `s`;
* `has_deriv_within_at.liminf_right_norm_slope_le` for a stronger version using
`∥f z - f x∥` instead of `∥f z∥ - ∥f x∥`. -/
lemma has_deriv_within_at.liminf_right_slope_norm_le
(hf : has_deriv_within_at f f' (Ici x) x) (hr : ∥f'∥ < r) :
∃ᶠ z in 𝓝[Ioi x] x, (z - x)⁻¹ * (∥f z∥ - ∥f x∥) < r :=
begin
have := (hf.Ioi_of_Ici.limsup_slope_norm_le hr).frequently,
refine this.mp (eventually.mono self_mem_nhds_within _),
assume z hxz hz,
rwa [real.norm_eq_abs, abs_of_pos (sub_pos_of_lt hxz)] at hz
end
end real_space
|
251bdc077f8bede927a4134bcbc24aa075759e1a | 6e8de6b43162bef473b4a0bd93b71db886df98ce | /src/pregeom/basis_family.lean | 941cb1ac5c4f96641b4647c4c21c1ac0f86557b9 | [
"Unlicense"
] | permissive | adamtopaz/comb_geom | 38ec6fde8d2543f56227ec50cdfb86cac6ac33c1 | e16b629d6de3fbdea54a528755e7305dfb51e902 | refs/heads/master | 1,668,613,552,530 | 1,593,199,940,000 | 1,593,199,940,000 | 269,824,442 | 6 | 0 | Unlicense | 1,593,119,545,000 | 1,591,404,975,000 | Lean | UTF-8 | Lean | false | false | 3,292 | lean | import data.set
import .basis
import .basic
/-!
# What is going on here?
Here we define the notion of spanning, independence, and basis for a family of terms in a pregeometry.
By a family, we just mean a function `ι : S → T` from some other type `S`.
The following lemmas help in going back and forth between the definitions here and those in `src/pregeom/basis.lean`:
1. `spanning_iff_range_spanning` says that `ι` spans if and only if its image does.
2. `indep_iff_injective_range_indep` says that `ι` is independent if and only if `ι` is injective and its image is independent.
3. `basis_iff_injective_range_basis` says that `ι` is a basis if and only if `ι` is injective and its image is a basis.
-/
open_locale classical
variables {T : Type*}
variables {S : Type*} (ι : S → T)
namespace pregeom
namespace basis_family
open set
open function
/-- The restriction of ι to the complemenet of {x}. -/
def res (x : S) : {y : S // y ≠ x} → T := λ ⟨y,_⟩, ι y
/-- Independence for a family. -/
def is_indep [has_cl T] : Prop := ∀ x : S, ι x ∉ cl (range $ res ι x)
/-- Spanning condition for a family. -/
def is_spanning [has_cl T] : Prop := ∀ t : T, t ∈ cl (range ι)
/-- Definition of a basis for a family. -/
def is_basis [has_cl T] : Prop := is_indep ι ∧ is_spanning ι
variable {ι}
/-- If ι is injective, then the image of the restriction of ι to the complement of s is
the complement of ι s in the image of ι. -/
lemma range_res_eq_sub_range_of_injective {s : S} : injective ι → range (res ι s) = range ι \ {ι s} :=
begin
intro h,
ext, refine ⟨by tidy, _⟩,
rintro ⟨⟨y,rfl⟩,h2⟩,
use y,
repeat {finish},
end
variable [pregeom T]
/-- If ι is independence, then ι is injective. -/
theorem injective_of_indep : is_indep ι → injective ι :=
begin
intro indep,
intros y x h,
by_contradiction contra,
replace indep := indep x,
have : ι y ∈ range (res ι x), by exact ⟨⟨y,contra⟩, by finish⟩,
rw h at this,
replace this := inclusive this,
contradiction,
end
/-- ι spans if and only if its image spans. -/
theorem spanning_iff_range_spanning : is_spanning ι ↔ basis.is_spanning (range ι) := by tauto
/-- ι is independent if and only if ι is injective and its image is independent. -/
theorem indep_iff_injective_range_indep : is_indep ι ↔ injective ι ∧ basis.is_indep (range ι) :=
begin
split,
{ intro h,
have c1 := injective_of_indep h,
refine ⟨c1,_⟩,
rintros _ ⟨y,rfl⟩,
replace h := h y,
change _ ∉ cl (range ι \ _),
rwa ←range_res_eq_sub_range_of_injective c1, },
{ rintros ⟨h1,h2⟩,
intro s,
rw range_res_eq_sub_range_of_injective h1,
apply h2,
use s, }
end
/-- ι is a basis if and only if ι is injective and its image is a basis.
This can be used to go back and forth between the definition of bases for sets and for families.
-/
theorem basis_iff_injective_range_basis : is_basis ι ↔ injective ι ∧ basis.is_basis (range ι) :=
begin
split,
{ rintro ⟨h1,h2⟩,
rw indep_iff_injective_range_indep at h1,
exact ⟨h1.1,⟨h1.2,h2⟩⟩, },
{ rintro ⟨h1,h2,h3⟩,
refine ⟨_,h3⟩,
rw indep_iff_injective_range_indep,
finish, }
end
end basis_family
end pregeom |
39ad7d44cb229a28687ad2f90430c30a5116b4d0 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/ring_theory/polynomial/content.lean | d35c17b4bf2d85015355601409f8c53f1ba23851 | [] | 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 | 9,028 | 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.data.finset.gcd
import Mathlib.data.polynomial.default
import Mathlib.data.polynomial.erase_lead
import Mathlib.data.polynomial.cancel_leads
import Mathlib.PostPort
universes u_1
namespace Mathlib
/-!
# GCD structures on polynomials
Definitions and basic results about polynomials over GCD domains, particularly their contents
and primitive polynomials.
## Main Definitions
Let `p : polynomial R`.
- `p.content` is the `gcd` of the coefficients of `p`.
- `p.is_primitive` indicates that `p.content = 1`.
## Main Results
- `polynomial.content_mul`:
If `p q : polynomial R`, then `(p * q).content = p.content * q.content`.
- `polynomial.gcd_monoid`:
The polynomial ring of a GCD domain is itself a GCD domain.
-/
namespace polynomial
/-- `p.content` is the `gcd` of the coefficients of `p`. -/
def content {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : R :=
finset.gcd (finsupp.support p) (coeff p)
theorem content_dvd_coeff {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} (n : ℕ) : content p ∣ coeff p n := sorry
@[simp] theorem content_C {R : Type u_1} [integral_domain R] [gcd_monoid R] {r : R} : content (coe_fn C r) = coe_fn normalize r := sorry
@[simp] theorem content_zero {R : Type u_1} [integral_domain R] [gcd_monoid R] : content 0 = 0 :=
eq.mpr (id (Eq._oldrec (Eq.refl (content 0 = 0)) (Eq.symm C_0)))
(eq.mpr (id (Eq._oldrec (Eq.refl (content (coe_fn C 0) = 0)) content_C))
(eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn normalize 0 = 0)) normalize_zero)) (Eq.refl 0)))
@[simp] theorem content_one {R : Type u_1} [integral_domain R] [gcd_monoid R] : content 1 = 1 :=
eq.mpr (id (Eq._oldrec (Eq.refl (content 1 = 1)) (Eq.symm C_1)))
(eq.mpr (id (Eq._oldrec (Eq.refl (content (coe_fn C 1) = 1)) content_C))
(eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn normalize 1 = 1)) normalize_one)) (Eq.refl 1)))
theorem content_X_mul {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} : content (X * p) = content p := sorry
@[simp] theorem content_X_pow {R : Type u_1} [integral_domain R] [gcd_monoid R] {k : ℕ} : content (X ^ k) = 1 := sorry
@[simp] theorem content_X {R : Type u_1} [integral_domain R] [gcd_monoid R] : content X = 1 :=
eq.mpr (id (Eq._oldrec (Eq.refl (content X = 1)) (Eq.symm (mul_one X))))
(eq.mpr (id (Eq._oldrec (Eq.refl (content (X * 1) = 1)) content_X_mul))
(eq.mpr (id (Eq._oldrec (Eq.refl (content 1 = 1)) content_one)) (Eq.refl 1)))
theorem content_C_mul {R : Type u_1} [integral_domain R] [gcd_monoid R] (r : R) (p : polynomial R) : content (coe_fn C r * p) = coe_fn normalize r * content p := sorry
@[simp] theorem content_monomial {R : Type u_1} [integral_domain R] [gcd_monoid R] {r : R} {k : ℕ} : content (coe_fn (monomial k) r) = coe_fn normalize r := sorry
theorem content_eq_zero_iff {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} : content p = 0 ↔ p = 0 := sorry
@[simp] theorem normalize_content {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} : coe_fn normalize (content p) = content p :=
finset.normalize_gcd
theorem content_eq_gcd_range_of_lt {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) (n : ℕ) (h : nat_degree p < n) : content p = finset.gcd (finset.range n) (coeff p) := sorry
theorem content_eq_gcd_range_succ {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : content p = finset.gcd (finset.range (Nat.succ (nat_degree p))) (coeff p) :=
content_eq_gcd_range_of_lt p (Nat.succ (nat_degree p)) (nat.lt_succ_self (nat_degree p))
theorem content_eq_gcd_leading_coeff_content_erase_lead {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : content p = gcd (leading_coeff p) (content (erase_lead p)) := sorry
theorem dvd_content_iff_C_dvd {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} {r : R} : r ∣ content p ↔ coe_fn C r ∣ p := sorry
theorem C_content_dvd {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : coe_fn C (content p) ∣ p :=
iff.mp dvd_content_iff_C_dvd (dvd_refl (content p))
/-- A polynomial over a GCD domain is primitive when the `gcd` of its coefficients is 1 -/
def is_primitive {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) :=
content p = 1
@[simp] theorem is_primitive_one {R : Type u_1} [integral_domain R] [gcd_monoid R] : is_primitive 1 := sorry
theorem monic.is_primitive {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} (hp : monic p) : is_primitive p := sorry
theorem is_primitive.ne_zero {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} (hp : is_primitive p) : p ≠ 0 := sorry
theorem is_primitive.content_eq_one {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} (hp : is_primitive p) : content p = 1 :=
hp
theorem is_primitive_iff_is_unit_of_C_dvd {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} : is_primitive p ↔ ∀ (r : R), coe_fn C r ∣ p → is_unit r := sorry
/-- The primitive part of a polynomial `p` is the primitive polynomial gained by dividing `p` by
`p.content`. If `p = 0`, then `p.prim_part = 1`. -/
def prim_part {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : polynomial R :=
ite (p = 0) 1 (classical.some (C_content_dvd p))
theorem eq_C_content_mul_prim_part {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : p = coe_fn C (content p) * prim_part p := sorry
@[simp] theorem prim_part_zero {R : Type u_1} [integral_domain R] [gcd_monoid R] : prim_part 0 = 1 :=
if_pos rfl
theorem is_primitive_prim_part {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : is_primitive (prim_part p) := sorry
theorem content_prim_part {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : content (prim_part p) = 1 :=
is_primitive_prim_part p
theorem prim_part_ne_zero {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : prim_part p ≠ 0 :=
is_primitive.ne_zero (is_primitive_prim_part p)
theorem nat_degree_prim_part {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : nat_degree (prim_part p) = nat_degree p := sorry
@[simp] theorem is_primitive.prim_part_eq {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} (hp : is_primitive p) : prim_part p = p := sorry
theorem is_unit_prim_part_C {R : Type u_1} [integral_domain R] [gcd_monoid R] (r : R) : is_unit (prim_part (coe_fn C r)) := sorry
theorem prim_part_dvd {R : Type u_1} [integral_domain R] [gcd_monoid R] (p : polynomial R) : prim_part p ∣ p :=
dvd.intro_left (coe_fn C (content p)) (Eq.symm (eq_C_content_mul_prim_part p))
theorem gcd_content_eq_of_dvd_sub {R : Type u_1} [integral_domain R] [gcd_monoid R] {a : R} {p : polynomial R} {q : polynomial R} (h : coe_fn C a ∣ p - q) : gcd a (content p) = gcd a (content q) := sorry
theorem content_mul_aux {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} {q : polynomial R} : gcd (content (erase_lead (p * q))) (leading_coeff p) = gcd (content (erase_lead p * q)) (leading_coeff p) := sorry
@[simp] theorem content_mul {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} {q : polynomial R} : content (p * q) = content p * content q := sorry
theorem is_primitive.mul {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} {q : polynomial R} (hp : is_primitive p) (hq : is_primitive q) : is_primitive (p * q) := sorry
@[simp] theorem prim_part_mul {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} {q : polynomial R} (h0 : p * q ≠ 0) : prim_part (p * q) = prim_part p * prim_part q := sorry
theorem is_primitive.is_primitive_of_dvd {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} {q : polynomial R} (hp : is_primitive p) (hdvd : q ∣ p) : is_primitive q := sorry
theorem is_primitive.dvd_prim_part_iff_dvd {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} {q : polynomial R} (hp : is_primitive p) (hq : q ≠ 0) : p ∣ prim_part q ↔ p ∣ q := sorry
theorem exists_primitive_lcm_of_is_primitive {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} {q : polynomial R} (hp : is_primitive p) (hq : is_primitive q) : ∃ (r : polynomial R), is_primitive r ∧ ∀ (s : polynomial R), p ∣ s ∧ q ∣ s ↔ r ∣ s := sorry
theorem dvd_iff_content_dvd_content_and_prim_part_dvd_prim_part {R : Type u_1} [integral_domain R] [gcd_monoid R] {p : polynomial R} {q : polynomial R} (hq : q ≠ 0) : p ∣ q ↔ content p ∣ content q ∧ prim_part p ∣ prim_part q := sorry
protected instance gcd_monoid {R : Type u_1} [integral_domain R] [gcd_monoid R] : gcd_monoid (polynomial R) :=
gcd_monoid_of_exists_lcm sorry
|
9021c94b7971f05f96010a2115de36350dbababf | 6dc0c8ce7a76229dd81e73ed4474f15f88a9e294 | /tests/bench/binarytrees.lean | 32a0a143db88d11d847de9f570cdf4a54faaf384 | [
"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 | 1,706 | lean | inductive Tree
| Nil
| Node (l r : Tree) : Tree
open Tree
instance : Inhabited Tree := ⟨Nil⟩
-- This Function has an extra argument to suppress the
-- common sub-expression elimination optimization
partial def make' : UInt32 -> UInt32 -> Tree
| n, d =>
if d = 0 then Node Nil Nil
else Node (make' n (d - 1)) (make' (n + 1) (d - 1))
-- build a tree
def make (d : UInt32) := make' d d
def check : Tree → UInt32
| Nil => 0
| Node l r => 1 + check l + check r
def minN := 4
def out (s : String) (n : Nat) (t : UInt32) : IO Unit :=
IO.println (s ++ " of depth " ++ toString n ++ "\t check: " ++ toString t)
-- allocate and check lots of trees
partial def sumT : UInt32 -> UInt32 -> UInt32 -> UInt32
| d, i, t =>
if i = 0 then t
else
let a := check (make d);
sumT d (i-1) (t + a)
-- generate many trees
partial def depth : Nat -> Nat -> List (Nat × Nat × Task UInt32)
| d, m => if d ≤ m then
let n := 2 ^ (m - d + minN);
(n, d, Task.spawn (fun _ => sumT (UInt32.ofNat d) (UInt32.ofNat n) 0)) :: depth (d+2) m
else []
def main : List String → IO UInt32
| [s] => do
let n := s.toNat!;
let maxN := Nat.max (minN + 2) n;
let stretchN := maxN + 1;
-- stretch memory tree
let c := check (make $ UInt32.ofNat stretchN);
out "stretch tree" stretchN c;
-- allocate a long lived tree
let long := make $ UInt32.ofNat maxN;
-- allocate, walk, and deallocate many bottom-up binary trees
let vs := (depth minN maxN); -- `using` (parList $ evalTuple3 r0 r0 rseq)
vs.forM (fun (m, d, i) => out (toString m ++ "\t trees") d i.get);
-- confirm the the long-lived binary tree still exists
out "long lived tree" maxN (check long);
pure 0
| _ => pure 1
|
3fdd4de040b86fe520e7da81842c9d622eb41d3b | 432d948a4d3d242fdfb44b81c9e1b1baacd58617 | /src/field_theory/polynomial_galois_group.lean | 17e89b869e37b3289eeccf0b02b65f41cfbf40e1 | [
"Apache-2.0"
] | permissive | JLimperg/aesop3 | 306cc6570c556568897ed2e508c8869667252e8a | a4a116f650cc7403428e72bd2e2c4cda300fe03f | refs/heads/master | 1,682,884,916,368 | 1,620,320,033,000 | 1,620,320,033,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 19,236 | lean | /-
Copyright (c) 2020 Thomas Browning, Patrick Lutz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning, Patrick Lutz
-/
import analysis.complex.polynomial
import field_theory.galois
import group_theory.perm.cycle_type
import ring_theory.eisenstein_criterion
/-!
# Galois Groups of Polynomials
In this file we introduce the Galois group of a polynomial, defined as
the automorphism group of the splitting field.
## Main definitions
- `gal p`: the Galois group of a polynomial p.
- `restrict p E`: the restriction homomorphism `(E ≃ₐ[F] E) → gal p`.
- `gal_action p E`: the action of `gal p` on the roots of `p` in `E`.
## Main results
- `restrict_smul`: `restrict p E` is compatible with `gal_action p E`.
- `gal_action_hom_injective`: the action of `gal p` on the roots of `p` in `E` is faithful.
- `restrict_prod_inj`: `gal (p * q)` embeds as a subgroup of `gal p × gal q`.
- `gal_action_hom_bijective_of_prime_degree`: An irreducible polynomial of prime degree
with two non-real roots has full Galois group
-/
noncomputable theory
open_locale classical
open finite_dimensional
namespace polynomial
variables {F : Type*} [field F] (p q : polynomial F) (E : Type*) [field E] [algebra F E]
/-- The Galois group of a polynomial -/
@[derive [has_coe_to_fun, group, fintype]]
def gal := p.splitting_field ≃ₐ[F] p.splitting_field
namespace gal
@[ext] lemma ext {σ τ : p.gal} (h : ∀ x ∈ p.root_set p.splitting_field, σ x = τ x) : σ = τ :=
begin
refine alg_equiv.ext (λ x, (alg_hom.mem_equalizer σ.to_alg_hom τ.to_alg_hom x).mp
((set_like.ext_iff.mp _ x).mpr algebra.mem_top)),
rwa [eq_top_iff, ←splitting_field.adjoin_roots, algebra.adjoin_le_iff],
end
instance [h : fact (p.splits (ring_hom.id F))] : unique p.gal :=
{ default := 1,
uniq := λ f, alg_equiv.ext (λ x, by { obtain ⟨y, rfl⟩ := algebra.mem_bot.mp
((set_like.ext_iff.mp ((is_splitting_field.splits_iff _ p).mp h.1) x).mp algebra.mem_top),
rw [alg_equiv.commutes, alg_equiv.commutes] }) }
/-- If `p` splits in `F` then the `p.gal` is trivial. -/
def unique_gal_of_splits (h : p.splits (ring_hom.id F)) : unique p.gal :=
{ default := 1,
uniq := λ f, alg_equiv.ext (λ x, by { obtain ⟨y, rfl⟩ := algebra.mem_bot.mp
((set_like.ext_iff.mp ((is_splitting_field.splits_iff _ p).mp h) x).mp algebra.mem_top),
rw [alg_equiv.commutes, alg_equiv.commutes] }) }
instance unique_gal_zero : unique (0 : polynomial F).gal :=
unique_gal_of_splits _ (splits_zero _)
instance unique_gal_one : unique (1 : polynomial F).gal :=
unique_gal_of_splits _ (splits_one _)
instance unique_gal_C (x : F) : unique (C x).gal :=
unique_gal_of_splits _ (splits_C _ _)
instance unique_gal_X : unique (X : polynomial F).gal :=
unique_gal_of_splits _ (splits_X _)
instance unique_gal_X_sub_C (x : F) : unique (X - C x).gal :=
unique_gal_of_splits _ (splits_X_sub_C _)
instance unique_gal_X_pow (n : ℕ) : unique (X ^ n : polynomial F).gal :=
unique_gal_of_splits _ (splits_X_pow _ _)
instance [h : fact (p.splits (algebra_map F E))] : algebra p.splitting_field E :=
(is_splitting_field.lift p.splitting_field p h.1).to_ring_hom.to_algebra
instance [h : fact (p.splits (algebra_map F E))] : is_scalar_tower F p.splitting_field E :=
is_scalar_tower.of_algebra_map_eq
(λ x, ((is_splitting_field.lift p.splitting_field p h.1).commutes x).symm)
/-- The restriction homomorphism -/
def restrict [fact (p.splits (algebra_map F E))] : (E ≃ₐ[F] E) →* p.gal :=
alg_equiv.restrict_normal_hom p.splitting_field
lemma restrict_surjective [fact (p.splits (algebra_map F E))] [normal F E] :
function.surjective (restrict p E) :=
alg_equiv.restrict_normal_hom_surjective E
section roots_action
/-- The function from `roots p p.splitting_field` to `roots p E` -/
def map_roots [fact (p.splits (algebra_map F E))] :
root_set p p.splitting_field → root_set p E :=
λ x, ⟨is_scalar_tower.to_alg_hom F p.splitting_field E x, begin
have key := subtype.mem x,
by_cases p = 0,
{ simp only [h, root_set_zero] at key,
exact false.rec _ key },
{ rw [mem_root_set h, aeval_alg_hom_apply, (mem_root_set h).mp key, alg_hom.map_zero] } end⟩
lemma map_roots_bijective [h : fact (p.splits (algebra_map F E))] :
function.bijective (map_roots p E) :=
begin
split,
{ exact λ _ _ h, subtype.ext (ring_hom.injective _ (subtype.ext_iff.mp h)) },
{ intro y,
have key := roots_map
(is_scalar_tower.to_alg_hom F p.splitting_field E : p.splitting_field →+* E)
((splits_id_iff_splits _).mpr (is_splitting_field.splits p.splitting_field p)),
rw [map_map, alg_hom.comp_algebra_map] at key,
have hy := subtype.mem y,
simp only [root_set, finset.mem_coe, multiset.mem_to_finset, key, multiset.mem_map] at hy,
rcases hy with ⟨x, hx1, hx2⟩,
exact ⟨⟨x, multiset.mem_to_finset.mpr hx1⟩, subtype.ext hx2⟩ }
end
/-- The bijection between `root_set p p.splitting_field` and `root_set p E` -/
def roots_equiv_roots [fact (p.splits (algebra_map F E))] :
(root_set p p.splitting_field) ≃ (root_set p E) :=
equiv.of_bijective (map_roots p E) (map_roots_bijective p E)
instance gal_action_aux : mul_action p.gal (root_set p p.splitting_field) :=
{ smul := λ ϕ x, ⟨ϕ x, begin
have key := subtype.mem x,
--simp only [root_set, finset.mem_coe, multiset.mem_to_finset] at *,
by_cases p = 0,
{ simp only [h, root_set_zero] at key,
exact false.rec _ key },
{ rw mem_root_set h,
change aeval (ϕ.to_alg_hom x) p = 0,
rw [aeval_alg_hom_apply, (mem_root_set h).mp key, alg_hom.map_zero] } end⟩,
one_smul := λ _, by { ext, refl },
mul_smul := λ _ _ _, by { ext, refl } }
instance gal_action [fact (p.splits (algebra_map F E))] : mul_action p.gal (root_set p E) :=
{ smul := λ ϕ x, roots_equiv_roots p E (ϕ • ((roots_equiv_roots p E).symm x)),
one_smul := λ _, by simp only [equiv.apply_symm_apply, one_smul],
mul_smul := λ _ _ _, by simp only [equiv.apply_symm_apply, equiv.symm_apply_apply, mul_smul] }
variables {p E}
@[simp] lemma restrict_smul [fact (p.splits (algebra_map F E))]
(ϕ : E ≃ₐ[F] E) (x : root_set p E) : ↑((restrict p E ϕ) • x) = ϕ x :=
begin
let ψ := alg_equiv.of_injective_field (is_scalar_tower.to_alg_hom F p.splitting_field E),
change ↑(ψ (ψ.symm _)) = ϕ x,
rw alg_equiv.apply_symm_apply ψ,
change ϕ (roots_equiv_roots p E ((roots_equiv_roots p E).symm x)) = ϕ x,
rw equiv.apply_symm_apply (roots_equiv_roots p E),
end
variables (p E)
/-- `gal_action` as a permutation representation -/
def gal_action_hom [fact (p.splits (algebra_map F E))] : p.gal →* equiv.perm (root_set p E) :=
{ to_fun := λ ϕ, equiv.mk (λ x, ϕ • x) (λ x, ϕ⁻¹ • x)
(λ x, inv_smul_smul ϕ x) (λ x, smul_inv_smul ϕ x),
map_one' := by { ext1 x, exact mul_action.one_smul x },
map_mul' := λ x y, by { ext1 z, exact mul_action.mul_smul x y z } }
lemma gal_action_hom_restrict [fact (p.splits (algebra_map F E))]
(ϕ : E ≃ₐ[F] E) (x : root_set p E) : ↑(gal_action_hom p E (restrict p E ϕ) x) = ϕ x :=
restrict_smul ϕ x
lemma gal_action_hom_injective [fact (p.splits (algebra_map F E))] :
function.injective (gal_action_hom p E) :=
begin
rw monoid_hom.injective_iff,
intros ϕ hϕ,
let equalizer := alg_hom.equalizer ϕ.to_alg_hom (alg_hom.id F p.splitting_field),
suffices : equalizer = ⊤,
{ exact alg_equiv.ext (λ x, (set_like.ext_iff.mp this x).mpr algebra.mem_top) },
rw [eq_top_iff, ←splitting_field.adjoin_roots, algebra.adjoin_le_iff],
intros x hx,
have key := equiv.perm.ext_iff.mp hϕ (roots_equiv_roots p E ⟨x, hx⟩),
change roots_equiv_roots p E (ϕ • (roots_equiv_roots p E).symm
(roots_equiv_roots p E ⟨x, hx⟩)) = roots_equiv_roots p E ⟨x, hx⟩ at key,
rw equiv.symm_apply_apply at key,
exact subtype.ext_iff.mp (equiv.injective (roots_equiv_roots p E) key),
end
end roots_action
variables {p q}
/-- The restriction homomorphism between Galois groups -/
def restrict_dvd (hpq : p ∣ q) : q.gal →* p.gal :=
if hq : q = 0 then 1 else @restrict F _ p _ _ _
⟨splits_of_splits_of_dvd (algebra_map F q.splitting_field) hq (splitting_field.splits q) hpq⟩
lemma restrict_dvd_surjective (hpq : p ∣ q) (hq : q ≠ 0) :
function.surjective (restrict_dvd hpq) :=
by simp only [restrict_dvd, dif_neg hq, restrict_surjective]
variables (p q)
/-- The Galois group of a product embeds into the product of the Galois groups -/
def restrict_prod : (p * q).gal →* p.gal × q.gal :=
monoid_hom.prod (restrict_dvd (dvd_mul_right p q)) (restrict_dvd (dvd_mul_left q p))
lemma restrict_prod_injective : function.injective (restrict_prod p q) :=
begin
by_cases hpq : (p * q) = 0,
{ haveI : unique (p * q).gal := by { rw hpq, apply_instance },
exact λ f g h, eq.trans (unique.eq_default f) (unique.eq_default g).symm },
intros f g hfg,
dsimp only [restrict_prod, restrict_dvd] at hfg,
simp only [dif_neg hpq, monoid_hom.prod_apply, prod.mk.inj_iff] at hfg,
suffices : alg_hom.equalizer f.to_alg_hom g.to_alg_hom = ⊤,
{ exact alg_equiv.ext (λ x, (set_like.ext_iff.mp this x).mpr algebra.mem_top) },
rw [eq_top_iff, ←splitting_field.adjoin_roots, algebra.adjoin_le_iff],
intros x hx,
rw [map_mul, polynomial.roots_mul] at hx,
cases multiset.mem_add.mp (multiset.mem_to_finset.mp hx) with h h,
{ change f x = g x,
haveI : fact (p.splits (algebra_map F (p * q).splitting_field)) :=
⟨splits_of_splits_of_dvd _ hpq (splitting_field.splits (p * q)) (dvd_mul_right p q)⟩,
have key : x = algebra_map (p.splitting_field) (p * q).splitting_field
((roots_equiv_roots p _).inv_fun ⟨x, multiset.mem_to_finset.mpr h⟩) :=
subtype.ext_iff.mp (equiv.apply_symm_apply (roots_equiv_roots p _) ⟨x, _⟩).symm,
rw [key, ←alg_equiv.restrict_normal_commutes, ←alg_equiv.restrict_normal_commutes],
exact congr_arg _ (alg_equiv.ext_iff.mp hfg.1 _) },
{ change f x = g x,
haveI : fact (q.splits (algebra_map F (p * q).splitting_field)) :=
⟨splits_of_splits_of_dvd _ hpq (splitting_field.splits (p * q)) (dvd_mul_left q p)⟩,
have key : x = algebra_map (q.splitting_field) (p * q).splitting_field
((roots_equiv_roots q _).inv_fun ⟨x, multiset.mem_to_finset.mpr h⟩) :=
subtype.ext_iff.mp (equiv.apply_symm_apply (roots_equiv_roots q _) ⟨x, _⟩).symm,
rw [key, ←alg_equiv.restrict_normal_commutes, ←alg_equiv.restrict_normal_commutes],
exact congr_arg _ (alg_equiv.ext_iff.mp hfg.2 _) },
{ rwa [ne.def, mul_eq_zero, map_eq_zero, map_eq_zero, ←mul_eq_zero] }
end
lemma mul_splits_in_splitting_field_of_mul {p₁ q₁ p₂ q₂ : polynomial F}
(hq₁ : q₁ ≠ 0) (hq₂ : q₂ ≠ 0) (h₁ : p₁.splits (algebra_map F q₁.splitting_field))
(h₂ : p₂.splits (algebra_map F q₂.splitting_field)) :
(p₁ * p₂).splits (algebra_map F (q₁ * q₂).splitting_field) :=
begin
apply splits_mul,
{ rw ← (splitting_field.lift q₁ (splits_of_splits_of_dvd _
(mul_ne_zero hq₁ hq₂) (splitting_field.splits _) (dvd_mul_right q₁ q₂))).comp_algebra_map,
exact splits_comp_of_splits _ _ h₁, },
{ rw ← (splitting_field.lift q₂ (splits_of_splits_of_dvd _
(mul_ne_zero hq₁ hq₂) (splitting_field.splits _) (dvd_mul_left q₂ q₁))).comp_algebra_map,
exact splits_comp_of_splits _ _ h₂, },
end
lemma splits_in_splitting_field_of_comp (hq : q.nat_degree ≠ 0) :
p.splits (algebra_map F (p.comp q).splitting_field) :=
begin
let P : polynomial F → Prop := λ r, r.splits (algebra_map F (r.comp q).splitting_field),
have key1 : ∀ {r : polynomial F}, irreducible r → P r,
{ intros r hr,
by_cases hr' : nat_degree r = 0,
{ exact splits_of_nat_degree_le_one _ (le_trans (le_of_eq hr') zero_le_one) },
obtain ⟨x, hx⟩ := exists_root_of_splits _ (splitting_field.splits (r.comp q))
(λ h, hr' ((mul_eq_zero.mp (nat_degree_comp.symm.trans
(nat_degree_eq_of_degree_eq_some h))).resolve_right hq)),
rw [←aeval_def, aeval_comp] at hx,
have h_normal : normal F (r.comp q).splitting_field := splitting_field.normal (r.comp q),
have qx_int := normal.is_integral h_normal (aeval x q),
exact splits_of_splits_of_dvd _
(minpoly.ne_zero qx_int)
(normal.splits h_normal _)
(dvd_symm_of_irreducible (minpoly.irreducible qx_int) hr (minpoly.dvd F _ hx)) },
have key2 : ∀ {p₁ p₂ : polynomial F}, P p₁ → P p₂ → P (p₁ * p₂),
{ intros p₁ p₂ hp₁ hp₂,
by_cases h₁ : p₁.comp q = 0,
{ cases comp_eq_zero_iff.mp h₁ with h h,
{ rw [h, zero_mul],
exact splits_zero _ },
{ exact false.rec _ (hq (by rw [h.2, nat_degree_C])) } },
by_cases h₂ : p₂.comp q = 0,
{ cases comp_eq_zero_iff.mp h₂ with h h,
{ rw [h, mul_zero],
exact splits_zero _ },
{ exact false.rec _ (hq (by rw [h.2, nat_degree_C])) } },
have key := mul_splits_in_splitting_field_of_mul h₁ h₂ hp₁ hp₂,
rwa ← mul_comp at key },
exact wf_dvd_monoid.induction_on_irreducible p (splits_zero _)
(λ _, splits_of_is_unit _) (λ _ _ _ h, key2 (key1 h)),
end
/-- The restriction homomorphism from the Galois group of a homomorphism -/
def restrict_comp (hq : q.nat_degree ≠ 0) : (p.comp q).gal →* p.gal :=
@restrict F _ p _ _ _ ⟨splits_in_splitting_field_of_comp p q hq⟩
lemma restrict_comp_surjective (hq : q.nat_degree ≠ 0) :
function.surjective (restrict_comp p q hq) :=
by simp only [restrict_comp, restrict_surjective]
variables {p q}
lemma card_of_separable (hp : p.separable) :
fintype.card p.gal = finrank F p.splitting_field :=
begin
haveI : is_galois F p.splitting_field := is_galois.of_separable_splitting_field hp,
exact is_galois.card_aut_eq_finrank F p.splitting_field,
end
lemma prime_degree_dvd_card [char_zero F] (p_irr : irreducible p) (p_deg : p.nat_degree.prime) :
p.nat_degree ∣ fintype.card p.gal :=
begin
rw gal.card_of_separable p_irr.separable,
have hp : p.degree ≠ 0 :=
λ h, nat.prime.ne_zero p_deg (nat_degree_eq_zero_iff_degree_le_zero.mpr (le_of_eq h)),
let α : p.splitting_field := root_of_splits (algebra_map F p.splitting_field)
(splitting_field.splits p) hp,
have hα : is_integral F α :=
(is_algebraic_iff_is_integral F).mp (algebra.is_algebraic_of_finite α),
use finite_dimensional.finrank F⟮α⟯ p.splitting_field,
suffices : (minpoly F α).nat_degree = p.nat_degree,
{ rw [←finite_dimensional.finrank_mul_finrank F F⟮α⟯ p.splitting_field,
intermediate_field.adjoin.finrank hα, this] },
suffices : minpoly F α ∣ p,
{ have key := dvd_symm_of_irreducible (minpoly.irreducible hα) p_irr this,
apply le_antisymm,
{ exact nat_degree_le_of_dvd this p_irr.ne_zero },
{ exact nat_degree_le_of_dvd key (minpoly.ne_zero hα) } },
apply minpoly.dvd F α,
rw [aeval_def, map_root_of_splits _ (splitting_field.splits p) hp],
end
lemma splits_ℚ_ℂ {p : polynomial ℚ} : fact (p.splits (algebra_map ℚ ℂ)) :=
⟨is_alg_closed.splits_codomain p⟩
local attribute [instance] splits_ℚ_ℂ
/-- The number of complex roots equals the number of real roots plus
the number of roots not fixed by complex conjugation -/
lemma gal_action_hom_bijective_of_prime_degree_aux {p : polynomial ℚ} :
(p.root_set ℂ).to_finset.card = (p.root_set ℝ).to_finset.card +
(gal_action_hom p ℂ (restrict p ℂ (complex.conj_alg_equiv.restrict_scalars ℚ))).support.card :=
begin
by_cases hp : p = 0,
{ simp_rw [hp, root_set_zero, set.to_finset_eq_empty_iff.mpr rfl, finset.card_empty, zero_add],
refine eq.symm (nat.le_zero_iff.mp ((finset.card_le_univ _).trans (le_of_eq _))),
simp_rw [hp, root_set_zero, fintype.card_eq_zero_iff],
exact λ h, (set.mem_empty_eq h.val).mp h.mem },
have inj : function.injective (is_scalar_tower.to_alg_hom ℚ ℝ ℂ) := (algebra_map ℝ ℂ).injective,
rw [←finset.card_image_of_injective _ subtype.coe_injective,
←finset.card_image_of_injective _ inj],
let a : finset ℂ := _,
let b : finset ℂ := _,
let c : finset ℂ := _,
change a.card = b.card + c.card,
have ha : ∀ z : ℂ, z ∈ a ↔ aeval z p = 0 :=
λ z, by rw [set.mem_to_finset, mem_root_set hp],
have hb : ∀ z : ℂ, z ∈ b ↔ aeval z p = 0 ∧ z.im = 0,
{ intro z,
simp_rw [finset.mem_image, exists_prop, set.mem_to_finset, mem_root_set hp],
split,
{ rintros ⟨w, hw, rfl⟩,
exact ⟨by rw [aeval_alg_hom_apply, hw, alg_hom.map_zero], rfl⟩ },
{ rintros ⟨hz1, hz2⟩,
have key : is_scalar_tower.to_alg_hom ℚ ℝ ℂ z.re = z := by { ext, refl, rw hz2, refl },
exact ⟨z.re, inj (by rwa [←aeval_alg_hom_apply, key, alg_hom.map_zero]), key⟩ } },
have hc0 : ∀ w : p.root_set ℂ, gal_action_hom p ℂ
(restrict p ℂ (complex.conj_alg_equiv.restrict_scalars ℚ)) w = w ↔ w.val.im = 0,
{ intro w,
rw [subtype.ext_iff, gal_action_hom_restrict],
exact complex.eq_conj_iff_im },
have hc : ∀ z : ℂ, z ∈ c ↔ aeval z p = 0 ∧ z.im ≠ 0,
{ intro z,
simp_rw [finset.mem_image, exists_prop],
split,
{ rintros ⟨w, hw, rfl⟩,
exact ⟨(mem_root_set hp).mp w.2, mt (hc0 w).mpr (equiv.perm.mem_support.mp hw)⟩ },
{ rintros ⟨hz1, hz2⟩,
exact ⟨⟨z, (mem_root_set hp).mpr hz1⟩,
equiv.perm.mem_support.mpr (mt (hc0 _).mp hz2), rfl⟩ } },
rw ← finset.card_disjoint_union,
{ apply congr_arg finset.card,
simp_rw [finset.ext_iff, finset.mem_union, ha, hb, hc],
tauto },
{ intro z,
rw [finset.inf_eq_inter, finset.mem_inter, hb, hc],
tauto },
{ apply_instance },
end
/-- An irreducible polynomial of prime degree with two non-real roots has full Galois group -/
lemma gal_action_hom_bijective_of_prime_degree
{p : polynomial ℚ} (p_irr : irreducible p) (p_deg : p.nat_degree.prime)
(p_roots : fintype.card (p.root_set ℂ) = fintype.card (p.root_set ℝ) + 2) :
function.bijective (gal_action_hom p ℂ) :=
begin
have h1 : fintype.card (p.root_set ℂ) = p.nat_degree,
{ simp_rw [root_set_def, fintype.card_coe],
rw [multiset.to_finset_card_of_nodup, ←nat_degree_eq_card_roots],
{ exact is_alg_closed.splits_codomain p },
{ exact nodup_roots ((separable_map (algebra_map ℚ ℂ)).mpr p_irr.separable) } },
have h2 : fintype.card p.gal = fintype.card (gal_action_hom p ℂ).range :=
fintype.card_congr (monoid_hom.of_injective (gal_action_hom_injective p ℂ)).to_equiv,
let conj := restrict p ℂ (complex.conj_alg_equiv.restrict_scalars ℚ),
refine ⟨gal_action_hom_injective p ℂ, λ x, (congr_arg (has_mem.mem x)
(show (gal_action_hom p ℂ).range = ⊤, from _)).mpr (subgroup.mem_top x)⟩,
apply equiv.perm.subgroup_eq_top_of_swap_mem,
{ rwa h1 },
{ rw [h1, ←h2],
exact prime_degree_dvd_card p_irr p_deg },
{ exact ⟨conj, rfl⟩ },
{ rw ← equiv.perm.card_support_eq_two,
apply nat.add_left_cancel,
rw [←p_roots, ←set.to_finset_card (root_set p ℝ), ←set.to_finset_card (root_set p ℂ)],
exact gal_action_hom_bijective_of_prime_degree_aux.symm },
end
end gal
end polynomial
|
88369a5903a02fbde13f2b7b1fe1f78f31d045c3 | 367134ba5a65885e863bdc4507601606690974c1 | /src/linear_algebra/tensor_algebra.lean | 205075040de9773caf9b24b0a2c336771a1b42c4 | [
"Apache-2.0"
] | permissive | kodyvajjha/mathlib | 9bead00e90f68269a313f45f5561766cfd8d5cad | b98af5dd79e13a38d84438b850a2e8858ec21284 | refs/heads/master | 1,624,350,366,310 | 1,615,563,062,000 | 1,615,563,062,000 | 162,666,963 | 0 | 0 | Apache-2.0 | 1,545,367,651,000 | 1,545,367,651,000 | null | UTF-8 | Lean | false | false | 7,206 | lean | /-
Copyright (c) 2020 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Adam Topaz.
-/
import algebra.free_algebra
import algebra.ring_quot
import algebra.triv_sq_zero_ext
/-!
# Tensor Algebras
Given a commutative semiring `R`, and an `R`-module `M`, we construct the tensor algebra of `M`.
This is the free `R`-algebra generated (`R`-linearly) by the module `M`.
## Notation
1. `tensor_algebra R M` is the tensor algebra itself. It is endowed with an R-algebra structure.
2. `tensor_algebra.ι R` is the canonical R-linear map `M → tensor_algebra R M`.
3. Given a linear map `f : M → A` to an R-algebra `A`, `lift R f` is the lift of `f` to an
`R`-algebra morphism `tensor_algebra R M → A`.
## Theorems
1. `ι_comp_lift` states that the composition `(lift R f) ∘ (ι R)` is identical to `f`.
2. `lift_unique` states that whenever an R-algebra morphism `g : tensor_algebra R M → A` is
given whose composition with `ι R` is `f`, then one has `g = lift R f`.
3. `hom_ext` is a variant of `lift_unique` in the form of an extensionality theorem.
4. `lift_comp_ι` is a combination of `ι_comp_lift` and `lift_unique`. It states that the lift
of the composition of an algebra morphism with `ι` is the algebra morphism itself.
## Implementation details
As noted above, the tensor algebra of `M` is constructed as the free `R`-algebra generated by `M`,
modulo the additional relations making the inclusion of `M` into an `R`-linear map.
-/
variables (R : Type*) [comm_semiring R]
variables (M : Type*) [add_comm_monoid M] [semimodule R M]
namespace tensor_algebra
/--
An inductively defined relation on `pre R M` used to force the initial algebra structure on
the associated quotient.
-/
inductive rel : free_algebra R M → free_algebra R M → Prop
-- force `ι` to be linear
| add {a b : M} :
rel (free_algebra.ι R (a+b)) (free_algebra.ι R a + free_algebra.ι R b)
| smul {r : R} {a : M} :
rel (free_algebra.ι R (r • a)) (algebra_map R (free_algebra R M) r * free_algebra.ι R a)
end tensor_algebra
/--
The tensor algebra of the module `M` over the commutative semiring `R`.
-/
@[derive [inhabited, semiring, algebra R]]
def tensor_algebra := ring_quot (tensor_algebra.rel R M)
namespace tensor_algebra
instance {S : Type*} [comm_ring S] [semimodule S M] : ring (tensor_algebra S M) :=
ring_quot.ring (rel S M)
variables {M}
/--
The canonical linear map `M →ₗ[R] tensor_algebra R M`.
-/
def ι : M →ₗ[R] (tensor_algebra R M) :=
{ to_fun := λ m, (ring_quot.mk_alg_hom R _ (free_algebra.ι R m)),
map_add' := λ x y, by { rw [←alg_hom.map_add], exact ring_quot.mk_alg_hom_rel R rel.add, },
map_smul' := λ r x, by { rw [←alg_hom.map_smul], exact ring_quot.mk_alg_hom_rel R rel.smul, } }
lemma ring_quot_mk_alg_hom_free_algebra_ι_eq_ι (m : M) :
ring_quot.mk_alg_hom R (rel R M) (free_algebra.ι R m) = ι R m := rfl
/--
Given a linear map `f : M → A` where `A` is an `R`-algebra, `lift R f` is the unique lift
of `f` to a morphism of `R`-algebras `tensor_algebra R M → A`.
-/
@[simps symm_apply]
def lift {A : Type*} [semiring A] [algebra R A] : (M →ₗ[R] A) ≃ (tensor_algebra R M →ₐ[R] A) :=
{ to_fun := ring_quot.lift_alg_hom R ∘ λ f,
⟨free_algebra.lift R ⇑f, λ x y (h : rel R M x y), by induction h; simp [algebra.smul_def]⟩,
inv_fun := λ F, F.to_linear_map.comp (ι R),
left_inv := λ f, by { ext, simp [ι], },
right_inv := λ F, by { ext, simp [ι], } }
variables {R}
@[simp]
theorem ι_comp_lift {A : Type*} [semiring A] [algebra R A] (f : M →ₗ[R] A) :
(lift R f).to_linear_map.comp (ι R) = f := (lift R).symm_apply_apply f
@[simp]
theorem lift_ι_apply {A : Type*} [semiring A] [algebra R A] (f : M →ₗ[R] A) (x) :
lift R f (ι R x) = f x := by { dsimp [lift, ι], refl, }
@[simp]
theorem lift_unique {A : Type*} [semiring A] [algebra R A] (f : M →ₗ[R] A)
(g : tensor_algebra R M →ₐ[R] A) : g.to_linear_map.comp (ι R) = f ↔ g = lift R f :=
(lift R).symm_apply_eq
-- Marking `tensor_algebra` irreducible makes `ring` instances inaccessible on quotients.
-- https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/algebra.2Esemiring_to_ring.20breaks.20semimodule.20typeclass.20lookup/near/212580241
-- For now, we avoid this by not marking it irreducible.
attribute [irreducible] ι lift
@[simp]
theorem lift_comp_ι {A : Type*} [semiring A] [algebra R A] (g : tensor_algebra R M →ₐ[R] A) :
lift R (g.to_linear_map.comp (ι R)) = g :=
by { rw ←lift_symm_apply, exact (lift R).apply_symm_apply g }
/-- See note [partially-applied ext lemmas]. -/
@[ext]
theorem hom_ext {A : Type*} [semiring A] [algebra R A] {f g : tensor_algebra R M →ₐ[R] A}
(w : f.to_linear_map.comp (ι R) = g.to_linear_map.comp (ι R)) : f = g :=
begin
rw [←lift_symm_apply, ←lift_symm_apply] at w,
exact (lift R).symm.injective w,
end
/-- If `C` holds for the `algebra_map` of `r : R` into `tensor_algebra R M`, the `ι` of `x : M`,
and is preserved under addition and muliplication, then it holds for all of `tensor_algebra R M`.
-/
-- This proof closely follows `free_algebra.induction`
@[elab_as_eliminator]
lemma induction {C : tensor_algebra R M → Prop}
(h_grade0 : ∀ r, C (algebra_map R (tensor_algebra R M) r))
(h_grade1 : ∀ x, C (ι R x))
(h_mul : ∀ a b, C a → C b → C (a * b))
(h_add : ∀ a b, C a → C b → C (a + b))
(a : tensor_algebra R M) :
C a :=
begin
-- the arguments are enough to construct a subalgebra, and a mapping into it from M
let s : subalgebra R (tensor_algebra R M) := {
carrier := C,
mul_mem' := h_mul,
add_mem' := h_add,
algebra_map_mem' := h_grade0, },
let of : M →ₗ[R] s := (ι R).cod_restrict s.to_submodule h_grade1,
-- the mapping through the subalgebra is the identity
have of_id : alg_hom.id R (tensor_algebra R M) = s.val.comp (lift R of),
{ ext,
simp [of], },
-- finding a proof is finding an element of the subalgebra
convert subtype.prop (lift R of a),
exact alg_hom.congr_fun of_id a,
end
/-- The left-inverse of `algebra_map`. -/
def algebra_map_inv : tensor_algebra R M →ₐ[R] R :=
lift R (0 : M →ₗ[R] R)
lemma algebra_map_left_inverse :
function.left_inverse algebra_map_inv (algebra_map R $ tensor_algebra R M) :=
λ x, by simp [algebra_map_inv]
/-- The left-inverse of `ι`.
As an implementation detail, we implement this using `triv_sq_zero_ext` which has a suitable
algebra structure. -/
def ι_inv : tensor_algebra R M →ₗ[R] M :=
(triv_sq_zero_ext.snd_hom R M).comp (lift R (triv_sq_zero_ext.inr_hom R M)).to_linear_map
lemma ι_left_inverse : function.left_inverse ι_inv (ι R : M → tensor_algebra R M) :=
λ x, by simp [ι_inv]
end tensor_algebra
namespace free_algebra
variables {R M}
/-- The canonical image of the `free_algebra` in the `tensor_algebra`, which maps
`free_algebra.ι R x` to `tensor_algebra.ι R x`. -/
def to_tensor : free_algebra R M →ₐ[R] tensor_algebra R M :=
free_algebra.lift R (tensor_algebra.ι R)
@[simp] lemma to_tensor_ι (m : M) : (free_algebra.ι R m).to_tensor = tensor_algebra.ι R m :=
by simp [to_tensor]
end free_algebra
|
2abf682cfb147ea847c6c0f6b18614d3e8aebba1 | 05f637fa14ac28031cb1ea92086a0f4eb23ff2b1 | /tests/lean/eq4.lean | 7767741f5d3ad5af785ab02a6632c2d95184cdee | [
"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 | 58 | lean | import Int
import Real
eval 1 = 1.0
eval 1 = nat_to_int 1
|
4e361c73b4d18b1b2b5ec5a0c149dd3926dc426c | 5d166a16ae129621cb54ca9dde86c275d7d2b483 | /tests/lean/interactive/my_tac_class.lean | ee2707c7f05ed6c8d854bd8e20e6386a5c315fa2 | [
"Apache-2.0"
] | permissive | jcarlson23/lean | b00098763291397e0ac76b37a2dd96bc013bd247 | 8de88701247f54d325edd46c0eed57aeacb64baf | refs/heads/master | 1,611,571,813,719 | 1,497,020,963,000 | 1,497,021,515,000 | 93,882,536 | 1 | 0 | null | 1,497,029,896,000 | 1,497,029,896,000 | null | UTF-8 | Lean | false | false | 1,774 | lean | meta def mytac :=
state_t nat tactic
meta instance : monad mytac :=
state_t.monad _ _
meta instance : monad.has_monad_lift tactic mytac :=
monad.monad_transformer_lift (state_t nat) tactic
meta instance (α : Type) : has_coe (tactic α) (mytac α) :=
⟨monad.monad_lift⟩
namespace mytac
meta def step {α : Type} (t : mytac α) : mytac unit :=
t >> return ()
meta def istep {α : Type} (line0 col0 line col : nat) (t : mytac α) : mytac unit :=
λ v s, result.cases_on (@scope_trace _ line col (t v s))
(λ ⟨a, v⟩ new_s, result.success ((), v) new_s)
(λ opt_msg_thunk e new_s, match opt_msg_thunk with
| some msg_thunk :=
let msg := λ _ : unit, msg_thunk () ++ format.line ++ to_fmt "value: " ++ to_fmt v ++ format.line ++ to_fmt "state:" ++ format.line ++ new_s^.to_format in
interaction_monad.result.exception (some msg) (some ⟨line, col⟩) new_s
| none := interaction_monad.silent_fail new_s
end)
meta def execute (tac : mytac unit) : tactic unit :=
tac 0 >> return ()
meta def save_info (p : pos) : mytac unit :=
do v ← state_t.read,
s ← tactic.read,
tactic.save_info_thunk p
(λ _, to_fmt "Custom state: " ++ to_fmt v ++ format.line ++
tactic_state.to_format s)
namespace interactive
meta def intros : mytac unit :=
tactic.intros >> return ()
meta def constructor : mytac unit :=
tactic.constructor
meta def trace (s : string) : mytac unit :=
tactic.trace s
meta def assumption : mytac unit :=
tactic.assumption
meta def inc : mytac unit :=
do v ← state_t.read, state_t.write (v+1)
end interactive
end mytac
example (p q : Prop) : p → q → p ∧ q :=
begin [mytac]
intros,
inc,
trace "test",
constructor,
inc,
assumption,
--^ "command": "info"
assumption
end
|
08c2ec40a8440c3934151bb3b608b5616b4444a3 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/category_theory/opposites_auto.lean | 248a59511e324df907947863dd786cd47c7eb30d | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 16,128 | 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 Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.category_theory.types
import Mathlib.category_theory.equivalence
import Mathlib.data.opposite
import Mathlib.PostPort
universes v₁ u₁ u₂ v₂ v
namespace Mathlib
namespace category_theory
/-- The hom types of the opposite of a category (or graph).
As with the objects, we'll make this irreducible below.
Use `f.op` and `f.unop` to convert between morphisms of C
and morphisms of Cᵒᵖ.
-/
protected instance has_hom.opposite {C : Type u₁} [has_hom C] : has_hom (Cᵒᵖ) :=
has_hom.mk fun (X Y : Cᵒᵖ) => opposite.unop Y ⟶ opposite.unop X
/--
The opposite of a morphism in `C`.
-/
/--
def has_hom.hom.op {C : Type u₁} [has_hom C] {X : C} {Y : C} (f : X ⟶ Y) :
opposite.op Y ⟶ opposite.op X :=
f
Given a morphism in `Cᵒᵖ`, we can take the "unopposite" back in `C`.
-/
def has_hom.hom.unop {C : Type u₁} [has_hom C] {X : Cᵒᵖ} {Y : Cᵒᵖ} (f : X ⟶ Y) :
opposite.unop Y ⟶ opposite.unop X :=
f
theorem has_hom.hom.op_inj {C : Type u₁} [has_hom C] {X : C} {Y : C} :
function.injective has_hom.hom.op :=
fun (_x _x_1 : X ⟶ Y) (H : has_hom.hom.op _x = has_hom.hom.op _x_1) =>
congr_arg has_hom.hom.unop H
theorem has_hom.hom.unop_inj {C : Type u₁} [has_hom C] {X : Cᵒᵖ} {Y : Cᵒᵖ} :
function.injective has_hom.hom.unop :=
fun (_x _x_1 : X ⟶ Y) (H : has_hom.hom.unop _x = has_hom.hom.unop _x_1) =>
congr_arg has_hom.hom.op H
@[simp] theorem has_hom.hom.unop_op {C : Type u₁} [has_hom C] {X : C} {Y : C} {f : X ⟶ Y} :
has_hom.hom.unop (has_hom.hom.op f) = f :=
rfl
@[simp] theorem has_hom.hom.op_unop {C : Type u₁} [has_hom C] {X : Cᵒᵖ} {Y : Cᵒᵖ} {f : X ⟶ Y} :
has_hom.hom.op (has_hom.hom.unop f) = f :=
rfl
/--
The opposite category.
See https://stacks.math.columbia.edu/tag/001M.
-/
protected instance category.opposite {C : Type u₁} [category C] : category (Cᵒᵖ) := category.mk
@[simp] theorem op_comp {C : Type u₁} [category C] {X : C} {Y : C} {Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} :
has_hom.hom.op (f ≫ g) = has_hom.hom.op g ≫ has_hom.hom.op f :=
rfl
@[simp] theorem op_id {C : Type u₁} [category C] {X : C} : has_hom.hom.op 𝟙 = 𝟙 := rfl
@[simp] theorem unop_comp {C : Type u₁} [category C] {X : Cᵒᵖ} {Y : Cᵒᵖ} {Z : Cᵒᵖ} {f : X ⟶ Y}
{g : Y ⟶ Z} : has_hom.hom.unop (f ≫ g) = has_hom.hom.unop g ≫ has_hom.hom.unop f :=
rfl
@[simp] theorem unop_id {C : Type u₁} [category C] {X : Cᵒᵖ} : has_hom.hom.unop 𝟙 = 𝟙 := rfl
@[simp] theorem unop_id_op {C : Type u₁} [category C] {X : C} : has_hom.hom.unop 𝟙 = 𝟙 := rfl
@[simp] theorem op_id_unop {C : Type u₁} [category C] {X : Cᵒᵖ} : has_hom.hom.op 𝟙 = 𝟙 := rfl
/-- The functor from the double-opposite of a category to the underlying category. -/
def op_op (C : Type u₁) [category C] : Cᵒᵖᵒᵖ ⥤ C :=
functor.mk (fun (X : Cᵒᵖᵒᵖ) => opposite.unop (opposite.unop X))
fun (X Y : Cᵒᵖᵒᵖ) (f : X ⟶ Y) => has_hom.hom.unop (has_hom.hom.unop f)
/-- The functor from a category to its double-opposite. -/
def unop_unop (C : Type u₁) [category C] : C ⥤ (Cᵒᵖᵒᵖ) :=
functor.mk (fun (X : C) => opposite.op (opposite.op X))
fun (X Y : C) (f : X ⟶ Y) => has_hom.hom.op (has_hom.hom.op f)
/-- The double opposite category is equivalent to the original. -/
@[simp] theorem op_op_equivalence_inverse (C : Type u₁) [category C] :
equivalence.inverse (op_op_equivalence C) = unop_unop C :=
Eq.refl (equivalence.inverse (op_op_equivalence C))
/--
If `f.op` is an isomorphism `f` must be too.
(This cannot be an instance as it would immediately loop!)
-/
def is_iso_of_op {C : Type u₁} [category C] {X : C} {Y : C} (f : X ⟶ Y)
[is_iso (has_hom.hom.op f)] : is_iso f :=
is_iso.mk (has_hom.hom.unop (inv (has_hom.hom.op f)))
namespace functor
/--
The opposite of a functor, i.e. considering a functor `F : C ⥤ D` as a functor `Cᵒᵖ ⥤ Dᵒᵖ`.
In informal mathematics no distinction is made between these.
-/
@[simp] theorem op_obj {C : Type u₁} [category C] {D : Type u₂} [category D] (F : C ⥤ D) (X : Cᵒᵖ) :
obj (functor.op F) X = opposite.op (obj F (opposite.unop X)) :=
Eq.refl (obj (functor.op F) X)
/--
Given a functor `F : Cᵒᵖ ⥤ Dᵒᵖ` we can take the "unopposite" functor `F : C ⥤ D`.
In informal mathematics no distinction is made between these.
-/
protected def unop {C : Type u₁} [category C] {D : Type u₂} [category D] (F : Cᵒᵖ ⥤ (Dᵒᵖ)) :
C ⥤ D :=
mk (fun (X : C) => opposite.unop (obj F (opposite.op X)))
fun (X Y : C) (f : X ⟶ Y) => has_hom.hom.unop (map F (has_hom.hom.op f))
/-- The isomorphism between `F.op.unop` and `F`. -/
def op_unop_iso {C : Type u₁} [category C] {D : Type u₂} [category D] (F : C ⥤ D) :
functor.unop (functor.op F) ≅ F :=
nat_iso.of_components (fun (X : C) => iso.refl (obj (functor.unop (functor.op F)) X)) sorry
/-- The isomorphism between `F.unop.op` and `F`. -/
def unop_op_iso {C : Type u₁} [category C] {D : Type u₂} [category D] (F : Cᵒᵖ ⥤ (Dᵒᵖ)) :
functor.op (functor.unop F) ≅ F :=
nat_iso.of_components (fun (X : Cᵒᵖ) => iso.refl (obj (functor.op (functor.unop F)) X)) sorry
/--
Taking the opposite of a functor is functorial.
-/
@[simp] theorem op_hom_obj (C : Type u₁) [category C] (D : Type u₂) [category D] (F : C ⥤ Dᵒᵖ) :
obj (op_hom C D) F = functor.op (opposite.unop F) :=
Eq.refl (obj (op_hom C D) F)
/--
Take the "unopposite" of a functor is functorial.
-/
@[simp] theorem op_inv_obj (C : Type u₁) [category C] (D : Type u₂) [category D] (F : Cᵒᵖ ⥤ (Dᵒᵖ)) :
obj (op_inv C D) F = opposite.op (functor.unop F) :=
Eq.refl (obj (op_inv C D) F)
-- TODO show these form an equivalence
/--
Another variant of the opposite of functor, turning a functor `C ⥤ Dᵒᵖ` into a functor `Cᵒᵖ ⥤ D`.
In informal mathematics no distinction is made.
-/
@[simp] theorem left_op_map {C : Type u₁} [category C] {D : Type u₂} [category D] (F : C ⥤ (Dᵒᵖ))
(X : Cᵒᵖ) (Y : Cᵒᵖ) (f : X ⟶ Y) :
map (functor.left_op F) f = has_hom.hom.unop (map F (has_hom.hom.unop f)) :=
Eq.refl (map (functor.left_op F) f)
/--
Another variant of the opposite of functor, turning a functor `Cᵒᵖ ⥤ D` into a functor `C ⥤ Dᵒᵖ`.
In informal mathematics no distinction is made.
-/
@[simp] theorem right_op_obj {C : Type u₁} [category C] {D : Type u₂} [category D] (F : Cᵒᵖ ⥤ D)
(X : C) : obj (functor.right_op F) X = opposite.op (obj F (opposite.op X)) :=
Eq.refl (obj (functor.right_op F) X)
-- TODO show these form an equivalence
protected instance op.category_theory.full {C : Type u₁} [category C] {D : Type u₂} [category D]
{F : C ⥤ D} [full F] : full (functor.op F) :=
full.mk
fun (X Y : Cᵒᵖ) (f : obj (functor.op F) X ⟶ obj (functor.op F) Y) =>
has_hom.hom.op (preimage F (has_hom.hom.unop f))
protected instance op.category_theory.faithful {C : Type u₁} [category C] {D : Type u₂} [category D]
{F : C ⥤ D} [faithful F] : faithful (functor.op F) :=
faithful.mk
/-- If F is faithful then the right_op of F is also faithful. -/
protected instance right_op_faithful {C : Type u₁} [category C] {D : Type u₂} [category D]
{F : Cᵒᵖ ⥤ D} [faithful F] : faithful (functor.right_op F) :=
faithful.mk
/-- If F is faithful then the left_op of F is also faithful. -/
protected instance left_op_faithful {C : Type u₁} [category C] {D : Type u₂} [category D]
{F : C ⥤ (Dᵒᵖ)} [faithful F] : faithful (functor.left_op F) :=
faithful.mk
end functor
namespace nat_trans
/-- The opposite of a natural transformation. -/
@[simp] theorem op_app {C : Type u₁} [category C] {D : Type u₂} [category D] {F : C ⥤ D} {G : C ⥤ D}
(α : F ⟶ G) (X : Cᵒᵖ) : app (nat_trans.op α) X = has_hom.hom.op (app α (opposite.unop X)) :=
Eq.refl (app (nat_trans.op α) X)
@[simp] theorem op_id {C : Type u₁} [category C] {D : Type u₂} [category D] (F : C ⥤ D) :
nat_trans.op 𝟙 = 𝟙 :=
rfl
/-- The "unopposite" of a natural transformation. -/
@[simp] theorem unop_app {C : Type u₁} [category C] {D : Type u₂} [category D] {F : Cᵒᵖ ⥤ (Dᵒᵖ)}
{G : Cᵒᵖ ⥤ (Dᵒᵖ)} (α : F ⟶ G) (X : C) :
app (nat_trans.unop α) X = has_hom.hom.unop (app α (opposite.op X)) :=
Eq.refl (app (nat_trans.unop α) X)
@[simp] theorem unop_id {C : Type u₁} [category C] {D : Type u₂} [category D] (F : Cᵒᵖ ⥤ (Dᵒᵖ)) :
nat_trans.unop 𝟙 = 𝟙 :=
rfl
/--
Given a natural transformation `α : F.op ⟶ G.op`,
we can take the "unopposite" of each component obtaining a natural transformation `G ⟶ F`.
-/
protected def remove_op {C : Type u₁} [category C] {D : Type u₂} [category D] {F : C ⥤ D}
{G : C ⥤ D} (α : functor.op F ⟶ functor.op G) : G ⟶ F :=
mk fun (X : C) => has_hom.hom.unop (app α (opposite.op X))
@[simp] theorem remove_op_id {C : Type u₁} [category C] {D : Type u₂} [category D] (F : C ⥤ D) :
nat_trans.remove_op 𝟙 = 𝟙 :=
rfl
/--
Given a natural transformation `α : F ⟶ G`, for `F G : C ⥤ Dᵒᵖ`,
taking `unop` of each component gives a natural transformation `G.left_op ⟶ F.left_op`.
-/
protected def left_op {C : Type u₁} [category C] {D : Type u₂} [category D] {F : C ⥤ (Dᵒᵖ)}
{G : C ⥤ (Dᵒᵖ)} (α : F ⟶ G) : functor.left_op G ⟶ functor.left_op F :=
mk fun (X : Cᵒᵖ) => has_hom.hom.unop (app α (opposite.unop X))
@[simp] theorem left_op_app {C : Type u₁} [category C] {D : Type u₂} [category D] {F : C ⥤ (Dᵒᵖ)}
{G : C ⥤ (Dᵒᵖ)} (α : F ⟶ G) (X : Cᵒᵖ) :
app (nat_trans.left_op α) X = has_hom.hom.unop (app α (opposite.unop X)) :=
rfl
/--
Given a natural transformation `α : F.left_op ⟶ G.left_op`, for `F G : C ⥤ Dᵒᵖ`,
taking `op` of each component gives a natural transformation `G ⟶ F`.
-/
protected def remove_left_op {C : Type u₁} [category C] {D : Type u₂} [category D] {F : C ⥤ (Dᵒᵖ)}
{G : C ⥤ (Dᵒᵖ)} (α : functor.left_op F ⟶ functor.left_op G) : G ⟶ F :=
mk fun (X : C) => has_hom.hom.op (app α (opposite.op X))
@[simp] theorem remove_left_op_app {C : Type u₁} [category C] {D : Type u₂} [category D]
{F : C ⥤ (Dᵒᵖ)} {G : C ⥤ (Dᵒᵖ)} (α : functor.left_op F ⟶ functor.left_op G) (X : C) :
app (nat_trans.remove_left_op α) X = has_hom.hom.op (app α (opposite.op X)) :=
rfl
end nat_trans
namespace iso
/--
The opposite isomorphism.
-/
protected def op {C : Type u₁} [category C] {X : C} {Y : C} (α : X ≅ Y) :
opposite.op Y ≅ opposite.op X :=
mk (has_hom.hom.op (hom α)) (has_hom.hom.op (inv α))
@[simp] theorem op_hom {C : Type u₁} [category C] {X : C} {Y : C} {α : X ≅ Y} :
hom (iso.op α) = has_hom.hom.op (hom α) :=
rfl
@[simp] theorem op_inv {C : Type u₁} [category C] {X : C} {Y : C} {α : X ≅ Y} :
inv (iso.op α) = has_hom.hom.op (inv α) :=
rfl
end iso
namespace nat_iso
/-- The natural isomorphism between opposite functors `G.op ≅ F.op` induced by a natural
isomorphism between the original functors `F ≅ G`. -/
protected def op {C : Type u₁} [category C] {D : Type u₂} [category D] {F : C ⥤ D} {G : C ⥤ D}
(α : F ≅ G) : functor.op G ≅ functor.op F :=
iso.mk (nat_trans.op (iso.hom α)) (nat_trans.op (iso.inv α))
@[simp] theorem op_hom {C : Type u₁} [category C] {D : Type u₂} [category D] {F : C ⥤ D} {G : C ⥤ D}
(α : F ≅ G) : iso.hom (nat_iso.op α) = nat_trans.op (iso.hom α) :=
rfl
@[simp] theorem op_inv {C : Type u₁} [category C] {D : Type u₂} [category D] {F : C ⥤ D} {G : C ⥤ D}
(α : F ≅ G) : iso.inv (nat_iso.op α) = nat_trans.op (iso.inv α) :=
rfl
/-- The natural isomorphism between functors `G ≅ F` induced by a natural isomorphism
between the opposite functors `F.op ≅ G.op`. -/
protected def remove_op {C : Type u₁} [category C] {D : Type u₂} [category D] {F : C ⥤ D}
{G : C ⥤ D} (α : functor.op F ≅ functor.op G) : G ≅ F :=
iso.mk (nat_trans.remove_op (iso.hom α)) (nat_trans.remove_op (iso.inv α))
@[simp] theorem remove_op_hom {C : Type u₁} [category C] {D : Type u₂} [category D] {F : C ⥤ D}
{G : C ⥤ D} (α : functor.op F ≅ functor.op G) :
iso.hom (nat_iso.remove_op α) = nat_trans.remove_op (iso.hom α) :=
rfl
@[simp] theorem remove_op_inv {C : Type u₁} [category C] {D : Type u₂} [category D] {F : C ⥤ D}
{G : C ⥤ D} (α : functor.op F ≅ functor.op G) :
iso.inv (nat_iso.remove_op α) = nat_trans.remove_op (iso.inv α) :=
rfl
/-- The natural isomorphism between functors `G.unop ≅ F.unop` induced by a natural isomorphism
between the original functors `F ≅ G`. -/
protected def unop {C : Type u₁} [category C] {D : Type u₂} [category D] {F : Cᵒᵖ ⥤ (Dᵒᵖ)}
{G : Cᵒᵖ ⥤ (Dᵒᵖ)} (α : F ≅ G) : functor.unop G ≅ functor.unop F :=
iso.mk (nat_trans.unop (iso.hom α)) (nat_trans.unop (iso.inv α))
@[simp] theorem unop_hom {C : Type u₁} [category C] {D : Type u₂} [category D] {F : Cᵒᵖ ⥤ (Dᵒᵖ)}
{G : Cᵒᵖ ⥤ (Dᵒᵖ)} (α : F ≅ G) : iso.hom (nat_iso.unop α) = nat_trans.unop (iso.hom α) :=
rfl
@[simp] theorem unop_inv {C : Type u₁} [category C] {D : Type u₂} [category D] {F : Cᵒᵖ ⥤ (Dᵒᵖ)}
{G : Cᵒᵖ ⥤ (Dᵒᵖ)} (α : F ≅ G) : iso.inv (nat_iso.unop α) = nat_trans.unop (iso.inv α) :=
rfl
end nat_iso
namespace equivalence
/--
An equivalence between categories gives an equivalence between the opposite categories.
-/
@[simp] theorem op_inverse {C : Type u₁} [category C] {D : Type u₂} [category D] (e : C ≌ D) :
inverse (op e) = functor.op (inverse e) :=
Eq.refl (inverse (op e))
/--
An equivalence between opposite categories gives an equivalence between the original categories.
-/
@[simp] theorem unop_unit_iso {C : Type u₁} [category C] {D : Type u₂} [category D]
(e : Cᵒᵖ ≌ (Dᵒᵖ)) : unit_iso (unop e) = iso.symm (nat_iso.unop (unit_iso e)) :=
Eq.refl (unit_iso (unop e))
end equivalence
/-- The equivalence between arrows of the form `A ⟶ B` and `B.unop ⟶ A.unop`. Useful for building
adjunctions.
Note that this (definitionally) gives variants
```
def op_equiv' (A : C) (B : Cᵒᵖ) : (opposite.op A ⟶ B) ≃ (B.unop ⟶ A) :=
op_equiv _ _
def op_equiv'' (A : Cᵒᵖ) (B : C) : (A ⟶ opposite.op B) ≃ (B ⟶ A.unop) :=
op_equiv _ _
def op_equiv''' (A B : C) : (opposite.op A ⟶ opposite.op B) ≃ (B ⟶ A) :=
op_equiv _ _
```
-/
def op_equiv {C : Type u₁} [category C] (A : Cᵒᵖ) (B : Cᵒᵖ) :
(A ⟶ B) ≃ (opposite.unop B ⟶ opposite.unop A) :=
equiv.mk (fun (f : A ⟶ B) => has_hom.hom.unop f)
(fun (g : opposite.unop B ⟶ opposite.unop A) => has_hom.hom.op g) sorry sorry
-- These two are made by hand rather than by simps because simps generates
-- `(op_equiv _ _).to_fun f = ...` rather than the coercion version.
@[simp] theorem op_equiv_apply {C : Type u₁} [category C] (A : Cᵒᵖ) (B : Cᵒᵖ) (f : A ⟶ B) :
coe_fn (op_equiv A B) f = has_hom.hom.unop f :=
rfl
@[simp] theorem op_equiv_symm_apply {C : Type u₁} [category C] (A : Cᵒᵖ) (B : Cᵒᵖ)
(f : opposite.unop B ⟶ opposite.unop A) :
coe_fn (equiv.symm (op_equiv A B)) f = has_hom.hom.op f :=
rfl
/-- Construct a morphism in the opposite of a preorder category from an inequality. -/
def op_hom_of_le {α : Type v} [preorder α] {U : αᵒᵖ} {V : αᵒᵖ}
(h : opposite.unop V ≤ opposite.unop U) : U ⟶ V :=
has_hom.hom.op (hom_of_le h)
theorem le_of_op_hom {α : Type v} [preorder α] {U : αᵒᵖ} {V : αᵒᵖ} (h : U ⟶ V) :
opposite.unop V ≤ opposite.unop U :=
le_of_hom (has_hom.hom.unop h)
end Mathlib |
4ca1febcb3e4963f90199a4bf9585a064584096f | 88fb7558b0636ec6b181f2a548ac11ad3919f8a5 | /tests/lean/run/dunfold3.lean | 3684d94daa0e072ac8beb685cd30d7bf201155fe | [
"Apache-2.0"
] | permissive | moritayasuaki/lean | 9f666c323cb6fa1f31ac597d777914aed41e3b7a | ae96ebf6ee953088c235ff7ae0e8c95066ba8001 | refs/heads/master | 1,611,135,440,814 | 1,493,852,869,000 | 1,493,852,869,000 | 90,269,903 | 0 | 0 | null | 1,493,906,291,000 | 1,493,906,291,000 | null | UTF-8 | Lean | false | false | 887 | lean | open tactic
def g : nat → nat := λ x, x + 5
example (a b : nat) (p : nat → Prop) (h : p (g (nat.succ (nat.succ a)))) : p (g (a + 2)) :=
begin
unfold g at h,
do { h ← get_local `h >>= infer_type, t ← to_expr `(p (nat.succ (nat.succ a) + 5)), guard (h = t) },
unfold has_add.add bit0 has_one.one nat.add,
unfold g,
do { t ← target, h ← get_local `h >>= infer_type, guard (t = h) },
assumption
end
meta def check_expected (p : pexpr) : tactic unit :=
do t ← target, ex ← to_expr p, guard (t = ex)
example (a b c : nat) (f : nat → nat → nat) (h : false) : f (g a) (g b) = (g c) :=
begin
unfold_occs g [2],
check_expected `(f (g a) (b + 5) = g c),
contradiction
end
example (a b c : nat) (f : nat → nat → nat) (h : false) : f (g a) (g b) = (g c) :=
begin
unfold_occs g [1, 3],
check_expected `(f (a + 5) (g b) = c + 5),
contradiction
end
|
f4942c8052a0d05a6ea4111698c3c052a9874ff7 | ea6a4a10943d0b1966364cc23dbea151403b12cb | /src/transport.lean | 440a976e11a3d91e6ad81d5e73eecb635ae7a73b | [] | no_license | cipher1024/transport | 4ec290275f540261dd6ae86247eecc99abe0218a | 147a1ba17c1e4c0b19b7625a1a70f87458a7f705 | refs/heads/master | 1,584,163,354,251 | 1,530,778,876,000 | 1,530,778,876,000 | 131,463,521 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 24,268 | lean | import data.list.basic
import data.equiv.basic
import tactic
import meta.expr
import tactic.refine
universes u v w
open function
class canonical_equiv (α : Sort*) (β : Sort*) extends equiv α β.
def equiv.injective {α : Sort*} {β : Sort*} (eq : α ≃ β) :
injective eq :=
injective_of_left_inverse eq.left_inv
#print prefix equiv.injective
#print equiv.injective.equations._eqn_1
variables (f : Type u → Prop)
variables (on_equiv : Π {α β : Type u} (e : equiv α β), equiv (f α) (f β))
section
open tactic.interactive
meta def prove_on_equiv_law' (n := `on_equiv) :=
do intros [],
eqv ← tactic.resolve_name n,
`[dsimp [equiv.refl,equiv.trans]],
generalize none () (``(%%eqv _),`k),
`[cases k, refl]
meta def prove_on_equiv_law := prove_on_equiv_law'
end
class transportable (f : Type u → Type v) :=
(on_equiv : Π {α β : Type u} (e : equiv α β), equiv (f α) (f β))
(on_refl : Π (α : Type u), on_equiv (equiv.refl α) = equiv.refl (f α) . prove_on_equiv_law)
(on_trans : Π {α β γ : Type u} (d : equiv α β) (e : equiv β γ), on_equiv (equiv.trans d e) = equiv.trans (on_equiv d) (on_equiv e) . prove_on_equiv_law)
-- Finally a command like: `initialize_transport group` would create the next two declarations automagically:
open transportable
definition equiv_mul {α β : Type u} : equiv α β → equiv (has_mul α) (has_mul β) := λ E,
{ to_fun := λ αmul,⟨λ b1 b2, E.to_fun (@has_mul.mul α αmul (E.inv_fun b1) (E.inv_fun b2))⟩,
inv_fun := λ βmul,⟨λ a1 a2, E.inv_fun (@has_mul.mul β βmul (E.to_fun a1) (E.to_fun a2))⟩, -- didn't I just write that?
-- should we introduce E-dual?
left_inv := λ f, begin
cases f, simp, -- aargh why do I struggle
congr,
-- suffices : (λ (a1 a2 : α), E.inv_fun (E.to_fun (f _ _))) = (λ a1 a2, f a1 a2),
-- by rw this,
funext,
simp [E.left_inv _,E.right_inv _], -- got there in the end
end,
right_inv := -- I can't even do this in term mode so I just copy out the entire tactic mode proof again.
λ g, begin
cases g, simp, -- aargh why do I struggle
suffices : (λ (b1 b2 : β), E.to_fun (E.inv_fun (g _ _))) = (λ b1 b2, g b1 b2),
by rw this,
funext,
simp [E.left_inv _,E.right_inv _], -- got there in the end
end, -- didn't I just write that?
}
namespace tactic
namespace interactive
open interactive function
#check @rfl
meta def eqn_lemma_type : expr → expr → expr → tactic (expr × expr)
| (expr.pi n bi d b) fn arg :=
do v ← mk_local' n bi d,
arg ← head_beta (arg v),
prod.map (expr.pis [v]) (expr.lambdas [v]) <$> eqn_lemma_type (b.instantiate_var v) (fn v) arg
| _ fn arg :=
prod.mk <$> to_expr ``(%%fn = %%arg) <*> to_expr ``(@rfl _ %%arg)
meta def eq_lemma_name (n : name) := n <.> "equations" <.> "_eqn_1"
meta def abstract_def (suffix : name) (t : expr) (tac : tactic unit) : tactic name :=
do (_,v) ← solve_aux t tac,
n ← (++ suffix) <$> decl_name,
v ← instantiate_mvars v,
t ← instantiate_mvars t,
add_decl $ mk_definition n t.collect_univ_params t v,
defn ← mk_const n,
(t,p) ← eqn_lemma_type t defn v,
add_decl $ declaration.thm (eq_lemma_name n) t.collect_univ_params t (return p),
set_basic_attribute `_refl_lemma (eq_lemma_name n),
return n
meta def build_aux_decl_with (c : name) (type : pexpr) (is_lemma : bool) (tac : tactic unit) : tactic expr :=
do type' ← to_expr type,
((),v) ← solve_aux type' tac,
add_aux_decl c type' v is_lemma
open functor
def strip_prefix (n : name) : name :=
name.update_prefix n name.anonymous
-- #check @equiv.injective
-- #print injective
meta def all_field_names : tactic (list name) :=
do gs ← get_goals,
gs.mmap (λ g, set_goals [g] >> get_current_field)
<* set_goals gs
-- meta def mk_app' (e : expr) (es : list expr) : tactic expr :=
meta def mk_to_fun (n : name) : tactic name :=
do env ← get_env,
decl ← env.get n,
let univs := decl.univ_params,
e ← resolve_name n,
fields ← qualified_field_list n,
t ← to_expr ``(Π α β : Type u, α ≃ β → %%e α → %%e β),
abstract_def (n <.> "transport" <.> "to_fun") t
(do α ← tactic.intro `α, β ← tactic.intro `β, eq_ ← tactic.intro `eqv,
eqv ← to_expr ``(@coe_fn _ equiv.has_coe_to_fun (%%eq_)),
eqv_symm ← to_expr ``(@coe_fn _ equiv.has_coe_to_fun (%%eq_).symm),
x ← tactic.intro `x,
[v] ← get_goals,
refine_struct ``( { .. } ),
let unfold_more := [`has_one.one,`has_zero.zero,`has_mul.mul,`has_add.add
,`semigroup.mul,`group.mul],
fs ← all_field_names >>= mmap resolve_name ∘ list.append unfold_more,
all_goals (do
fl ← get_current_field,
xs ← tactic.intros,
p ← mk_const fl >>= infer_type >>= pp,
xs' ← mmap (λ x, eqv_symm <$>
mcond (is_proof x)
(mk_mvar)
(pure x)) xs,
e ← mk_app fl (map eqv_symm xs) <|>
((flip expr.mk_app xs' <$> mk_mapp fl [none,some x]) >>= to_expr ∘ to_pexpr) <|>
fail format!"{fl} - {xs'} :: {p}",
infer_type e >>= trace,
trace "a",
tactic.exact (eqv e) <|>
(do refine ``((equiv.apply_eq_iff_eq (%%eq_).symm _ _).1 _) <|>
refine ``((not_iff_not_of_iff $ equiv.apply_eq_iff_eq (%%eq_).symm _ _).1 _),
trace "b",
g ← mk_mvar,
refine ``(iff.elim_left (eq.to_iff %%g) %%e),
-- tactic.type_check e,
num_goals >>= trace,
gs ← get_goals, set_goals $ g :: gs.diff [g],
num_goals >>= trace,
solve1 (do
-- simp (some ()) ff (map simp_arg_type.expr $ ``(@equiv.inverse_apply_apply) :: fs) [] (loc.ns [none]),
-- simp (some ()) ff (map simp_arg_type.expr $ fs) [] (loc.ns [none]),
-- repeat $ dsimp ff (map simp_arg_type.expr $ fs ++ [``(@equiv.inverse_apply_apply)]) [] (loc.ns [none]),
trace "c",
-- infer_type e >>= trace,
simp (some ()) tt (map simp_arg_type.expr $ fs ++ [``(@equiv.inverse_apply_apply),``(id)]) [] (loc.ns [none]),
-- try $ simp (some ()) ff (map simp_arg_type.expr $ fs ++ [``(@has_mul.mul),``(@equiv.inverse_apply_apply)]) [] (loc.ns [none]),
-- repeat `[rw [equiv.inverse_apply_apply]],
trace_state,
trace "d",
done <|> refl <|> (congr; done <|> refl)),
trace "e",
done <|> solve1 (do
trace "f",
target >>= infer_type >>= trace,
target >>= instantiate_mvars >>= tactic.change,
target >>= trace,
done )) <|>
(do refine ``((not_iff_not_of_iff $ equiv.apply_eq_iff_eq (%%eq_).symm _ _).1 _),
refine ``(iff.elim_left _ %%e),
refine ``(not_iff_not_of_iff _),
refine ``(eq.to_iff _),
simp (some ()) tt (map simp_arg_type.expr $ fs ++ [``(@equiv.inverse_apply_apply),``(id)]) [] (loc.ns [none]),
done) <|>
(do -- trace_state,
infer_type e >>= trace,
trace "dude",
done)))
-- set_option pp.universes true
-- set_option pp.notation false
-- set_option pp.implicit true
-- run_cmd add_interactive [`mk_to_fun]
-- run_cmd mk_to_fun `group
-- #print prefix _run_command.group
meta def mk_on_equiv (n to_fun : name) : tactic name :=
do f ← resolve_name n,
fn ← resolve_name to_fun,
t ← to_expr ``(Π (α β : Type u), α ≃ β → %%f α ≃ %%f β),
abstract_def (n ++ `on_eqv) t $
do tactic.intron 2,
eqv ← tactic.intro1,
refine ``( { to_fun := %%fn _ _ %%eqv,
inv_fun := %%fn _ _ (%%eqv).symm,
.. } );
abstract none (
dunfold [`function.left_inverse,`function.right_inverse] (loc.ns [none]);
(do x ← tactic.intro1, tactic.cases x,
dunfold [to_fun] (loc.ns [none]),
congr; tactic.funext;
`[ simp only [equiv.inverse_apply_apply,equiv.apply_inverse_apply,id] ],
return ()))
meta def mk_transportable_instance (n : name) : tactic unit :=
do d ← decl_name,
-- let to_fun := d ++ `group.transport.to_fun,
to_fun ← mk_to_fun n,
to_fun_lmm ← resolve_name $ eq_lemma_name to_fun,
on_eqv_n ← mk_on_equiv n to_fun,
on_eqv ← resolve_name on_eqv_n,
on_eqv_lmm ← resolve_name $ eq_lemma_name on_eqv_n,
fs ← expanded_field_list n,
env ← get_env,
decl ← env.get n,
let univs := decl.univ_params,
let e := @expr.const tt n $ univs.map level.param,
t ← to_expr ``(transportable %%e),
let goal := (loc.ns [none]),
(_,d) ← solve_aux t
(do refine ``( { on_equiv := %%on_eqv, on_refl := _, on_trans := _ } ),
-- cleanup,
abstract (some $ n ++ `on_refl) (do
intro1,
fs' ← fs.mmap (resolve_name ∘ uncurry (flip name.update_prefix)),
-- simp (some ()) ff (map simp_arg_type.expr $ [``(equiv.refl),``(equiv.symm),on_eqv_lmm,to_fun_lmm]) [] goal,
dsimp ff (map simp_arg_type.expr $
[``(equiv.refl),``(equiv.symm),on_eqv_lmm,to_fun_lmm]) [] goal,
-- done,
-- dunfold [``equiv.refl,on_eqv_n,to_fun] goal,
-- num_goals >>= trace,
-- done,
try congr; tactic.funext; cases (none,```(x)) [];
dunfold [`id,to_fun] goal;refl ),
abstract (some $ n ++ `on_trans) (do
intro1,
fs' ← fs.mmap (resolve_name ∘ uncurry (flip name.update_prefix)),
dsimp ff (map simp_arg_type.expr $
[``(function.comp),``(equiv.to_fun),``(equiv.inv_fun),``(equiv.trans),
``(equiv.symm),on_eqv_lmm,to_fun_lmm ]) [] goal,
-- num_goals >>= trace,
-- dunfold [on_eqv_n,`function.comp,`equiv.to_fun,`equiv.inv_fun,``equiv.trans] goal,
-- dunfold [`id] goal,
-- num_goals >>= trace,
intron 4,
try congr; tactic.funext; cases (none,```(x)) [];
dunfold [`id,to_fun] goal;refl ),
-- num_goals >>= trace,
-- dunfold [`id,to_fun] goal,
-- num_goals >>= trace,
-- target >>= trace,
-- num_goals >>= trace,
-- dsimp ff (map simp_arg_type.expr fs') [] goal,
-- num_goals >>= trace,
-- trace_state,
-- target >>= trace,
-- prove_on_equiv_law,
-- prove_on_equiv_law,
done),
d ← instantiate_mvars d,
let def_name := n <.> "transportable",
add_decl $ mk_definition def_name univs t d,
set_basic_attribute `instance def_name tt
set_option profiler true
set_option formatter.hide_full_terms false
set_option pp.delayed_abstraction false
set_option pp.universes true
-- run_cmd do
-- mk_transportable_instance `group
set_option profiler false
-- example : Π {α β : Type u} (e : equiv α β), equiv (group α) (group β) :=
-- begin
-- introv eqv,
-- refine_struct { to_fun := @group.transport.to_fun _ _ eqv
-- , inv_fun := @group.transport.to_fun _ _ eqv.symm
-- , .. };
-- dsimp [left_inverse,function.right_inverse];
-- intro x ; dunfold group.transport.to_fun;
-- cases x; congr; funext;
-- simp only [equiv.inverse_apply_apply,equiv.apply_inverse_apply,id],
-- end
#check congr_arg
-- #print group.transport.to_fun
-- meta def mk_transportable (n : name) (e : expr) : tactic unit :=
-- do [v] ← get_goals,
-- trace "begin mk_transportable",
-- trace "-- | TO_FUN",
-- fields ← qualified_field_list n,
-- to_fun ← to_expr ``(Π α β : Type u, α ≃ β → %%e α → %%e β)
-- >>= define ( `to_fun),
-- solve1
-- (do α ← tactic.intro `α,
-- β ← tactic.intro `β,
-- eq ← tactic.intro `eqv,
-- eqv ← to_expr ``(@coe_fn _ equiv.has_coe_to_fun (%%eq)),
-- eqv_symm ← to_expr ``(@coe_fn _ equiv.has_coe_to_fun (%%eq).symm),
-- x ← tactic.intro `x,
-- [v] ← get_goals,
-- refine_struct ``( { .. } ),
-- -- trace_state,
-- all_goals (do
-- tgt ← target,
-- p ← is_prop tgt,
-- if p then do
-- trace "A",
-- current ← get_current_field <|> fail "get_current_field",
-- vs ← tactic.intros,
-- h ← mk_mapp current ( [α,x] ++ vs.map (some ∘ eqv_symm) ) >>= note `h none
-- <|> fail "mk_mapp",
-- unfold (fields) (loc.ns [none,h.local_pp_name]), -- h.local_pp_name]),
-- h ← get_local h.local_pp_name,
-- infer_type h >>= trace,
-- -- tactic.revert h,
-- fs ← mmap (resolve_name ∘ strip_prefix) fields,
-- simp (some ()) tt (map simp_arg_type.expr $ [``(equiv.apply_inverse_apply),``(equiv.inverse_apply_apply)] ++ fs) [] (loc.ns [none,h.local_pp_name]), -- ,h.local_pp_name
-- -- h ← get_local h.local_pp_name,
-- -- infer_type h >>= trace,
-- trace_state,
-- -- target >>= trace,
-- -- tactic.exact h,
-- done,
-- trace "C",
-- return ()
-- else do
-- trace "B",
-- -- target >>= trace,
-- -- [v] ← get_goals,
-- current ← get_current_field,
-- trace current,
-- vs ← tactic.intros,
-- -- infer_type eqv_symm >>= trace,
-- -- refine ``(%%eqv _) <|> fail "refine",
-- trace eqv_symm,
-- -- trace vs,
-- -- instantiate_mvars v >>= trace,
-- let vs' := map (some ∘ eqv_symm) vs,
-- e ← mk_mapp current ( [α,x] ++ vs' ),
-- e ← to_expr ``(@coe_fn _ equiv.has_coe_to_fun %%eq %%e),
-- trace "to_expr",
-- trace e,
-- tactic.exact e,
-- trace "C",
-- -- trace_state,
-- return () ),
-- -- instantiate_mvars v >>= trace,
-- trace_state,
-- return () ),
-- -- inv_fun ← build_aux_decl_with ( (`inv_fun).update_prefix n)
-- -- ``(Π {α β}, %%e β → %%e α) ff
-- -- (do trace_state >> admit),
-- trace "-- | EQUIV",
-- is_inv ← to_expr ``(∀ α β (eqv : equiv α β),
-- left_inverse (%%to_fun β α eqv.symm) (%%to_fun α β eqv))
-- >>= assert `is_inv,
-- solve1 (do
-- α ← tactic.intro `α,
-- β ← tactic.intro `β,
-- eq ← tactic.intro `eqv,
-- x ← tactic.intro `x,
-- tactic.cases x,
-- -- trace_state,
-- `[simp only [to_fun]],
-- congr ; funext [] ; dunfold fields (loc.ns [none]) ;
-- `[simp! only [_root_.eq.mpr,equiv.apply_inverse_apply,equiv.inverse_apply_apply]],
-- -- trace_state,
-- return () ),
-- fn ← to_expr ``(Π α β, equiv α β → equiv (%%e α) (%%e β))
-- >>= define ( (`on_equiv).update_prefix n),
-- solve1
-- (do α ← tactic.intro `α,
-- β ← tactic.intro `β,
-- eq ← tactic.intro `eqv,
-- refine_struct ``( { to_fun := %%to_fun %%α %%β %%eq,
-- inv_fun := %%to_fun %%β %%α (%%eq).symm,
-- left_inv := %%is_inv %%α %%β %%eq }),
-- admit ),
-- -- | transport
-- trace "-- | TRANSPORT",
-- refine_struct ``( { on_equiv := %%fn, .. } ), -- (some `duh),
-- admit <|> fail "admit A",
-- admit <|> fail "admit B",
-- trace_state <|> fail "here",
-- -- instantiate_mvars v >>= trace ,
-- trace "end (mk_transportable)"
meta def instance_derive_handler' (univ_poly := tt)
(modify_target : name → list expr → expr → tactic expr := λ _ _, pure) : derive_handler :=
λ p n, do
let cls := `transportable,
if p.is_constant_of cls then
do decl ← get_decl n,
cls_decl ← get_decl cls,
env ← get_env,
-- guard (env.is_inductive n) <|> fail format!"failed to derive '{cls}', '{n}' is not an inductive type",
let ls := decl.univ_params.map $ λ n, if univ_poly then level.param n else level.zero,
-- incrementally build up target expression `Π (hp : p) [cls hp] ..., cls (n.{ls} hp ...)`
-- where `p ...` are the inductive parameter types of `n`
let tgt : expr := expr.const n ls,
⟨params, _⟩ ← mk_local_pis (decl.type.instantiate_univ_params (decl.univ_params.zip ls)),
(type,tgt) ← params.inits.any_of (λ param, do
let tgt := tgt.mk_app param,
prod.mk tgt <$> mk_app cls [tgt]),
tgt ← modify_target n [] tgt,
-- tgt ← params.enum.mfoldr (λ ⟨i, param⟩ tgt,
-- do -- add typeclass hypothesis for each inductive parameter
-- tgt ← do {
-- guard $ i < env.inductive_num_params n,
-- param_cls ← mk_app cls [param] <|> fail "fart",
-- -- TODO(sullrich): omit some typeclass parameters based on usage of `param`?
-- pure $ expr.pi `a binder_info.inst_implicit param_cls tgt
-- } <|> pure tgt,
-- pure $ tgt.bind_pi param
-- ) tgt,
mk_transportable_instance n,
pure true
else pure false
@[derive_handler]
meta def transportable_handler : derive_handler :=
instance_derive_handler' tt $
λ n params, pure
-- -- ``(transportable) _
end interactive
end tactic
-- namespace group
-- variables {α β : Type u}
-- variables (eq : equiv α β)
-- @[simp] def tr₀ : α → β := eq
-- @[simp] def tr₁ (f : α → α) : β → β := λ x : β, eq (f $ eq.symm x)
-- @[simp] def tr₂ (f : α → α → α) : β → β → β := λ (x y : β), eq $ f (eq.symm x) (eq.symm y)
-- -- def etr₀ : β → α := eq.inv_fun
-- -- def etr₁ (f : β → β) (x : α) : α := eq.inv_fun (f $ eq.to_fun x)
-- -- def etr₂ (f : β → β → β) (x y : α) : α := eq.inv_fun $ f (eq.to_fun x) (eq.to_fun y)
-- -- @[simp]
-- -- lemma inv_fun_tr₀ (f : α) :
-- -- eq.inv_fun (tr₀ eq f) = f :=
-- -- by simp [tr₀,equiv.left_inv eq _]
-- -- @[simp]
-- -- lemma inv_fun_tr₁ (f : α → α) (x : β) :
-- -- eq.inv_fun (tr₁ eq f x) = f (eq.inv_fun x) :=
-- -- by simp [tr₁,equiv.left_inv eq _]
-- -- @[simp]
-- -- lemma inv_fun_tr₂ (f : α → α → α) (x y : β) :
-- -- eq.inv_fun (tr₂ eq f x y) = f (eq.inv_fun x) (eq.inv_fun y) :=
-- -- by simp [tr₂,equiv.left_inv eq _]
-- local attribute [simp] equiv.left_inv equiv.right_inv
-- -- @[simp]
-- -- lemma symm_inv_fun :
-- -- eq.symm.inv_fun = eq.to_fun :=
-- -- by cases eq ; refl
-- -- @[simp]
-- -- lemma symm_to_fun :
-- -- eq.symm.to_fun = eq.inv_fun :=
-- -- by cases eq ; refl
-- -- @[simp]
-- -- lemma inv_fun_etr₀ (f : β) :
-- -- eq.to_fun (etr₀ eq f) = f :=
-- -- by simp [etr₀,equiv.right_inv eq _]
-- -- @[simp]
-- -- lemma inv_fun_etr₁ (f : β → β) (x : α) :
-- -- eq.to_fun (etr₁ eq f x) = f (eq.to_fun x) :=
-- -- by simp [etr₁,equiv.left_inv eq _]
-- -- @[simp]
-- -- lemma inv_fun_etr₂ (f : α → α → α) (x y : β) :
-- -- eq.inv_fun (etr₂ eq f x y) = f (eq.inv_fun x) (eq.inv_fun y) :=
-- -- by simp [tr₂,equiv.left_inv eq _]
-- lemma inj {x y : β}
-- (h : eq.symm x = eq.symm y)
-- : x = y := sorry
-- -- @[simp]
-- -- def on_equiv.to_fun [group α] : group β :=
-- -- { one := tr₀ eq (one α)
-- -- , mul := tr₂ eq mul
-- -- , inv := tr₁ eq inv
-- -- , mul_left_inv := by { intros, apply inj eq, simp, apply mul_left_inv }
-- -- , one_mul := by { intros, apply inj eq, simp, apply one_mul }
-- -- , mul_one := by { intros, apply inj eq, simp [has_mul.mul], apply mul_one }
-- -- , mul_assoc := by { intros, apply inj eq, simp, apply mul_assoc } }
-- -- @[simp]
-- -- def on_equiv.inv_fun [group β] : group α :=
-- -- { one := tr₀ eq.symm (one _)
-- -- , mul := tr₂ eq.symm mul
-- -- , inv := tr₁ eq.symm inv
-- -- , mul_left_inv := by { intros, apply inj eq.symm, simp, apply mul_left_inv }
-- -- , one_mul := by { intros, apply inj eq.symm, simp, apply one_mul }
-- -- , mul_one := by { intros, apply inj eq.symm, simp [has_mul.mul], apply mul_one }
-- -- , mul_assoc := by { intros, apply inj eq.symm, simp, apply mul_assoc } }
-- -- def on_equiv' : group α ≃ group β :=
-- -- { to_fun := @on_equiv.to_fun _ _ eq,
-- -- inv_fun := @on_equiv.inv_fun _ _ eq,
-- -- right_inv :=
-- -- by { intro x, cases x, simp,
-- -- congr ;
-- -- funext ;
-- -- dsimp [mul,one,inv] ;
-- -- simp!, },
-- -- left_inv :=
-- -- by { intro x, cases x, simp,
-- -- congr ;
-- -- funext ;
-- -- dsimp [mul,one,inv] ;
-- -- simp!, } }
-- -- def transportable' : transportable group :=
-- -- begin
-- -- refine { on_equiv := @on_equiv', .. }
-- -- ; intros ; simp [on_equiv',equiv.refl,equiv.trans]
-- -- ; split ; funext x ; cases x ; refl,
-- -- end
-- -- set_option formatter.hide_full_terms false
-- set_option pp.all true
-- -- set_option trace.app_builder true
-- -- #check equiv.has_coe_to_fun
-- -- set_option profiler true
-- -- attribute [derive transportable] group monoid ring field --
-- -- attribute [derive transportable] monoid
-- -- attribute [derive transportable] has_add
-- -- ⊢ Π (α β : Type u), α ≃ β → group α → group β
-- -- α β : Type u,
-- -- eq : α ≃ β
-- -- ⊢ group α ≃ group β
-- -- on_equiv
-- -- 2 goals
-- -- case on_refl
-- -- ⊢ ∀ (α : Type u), on_equiv α α (equiv.refl α) = equiv.refl (group α)
-- -- case on_trans
-- -- ⊢ ∀ {α β γ : Type u} (d : α ≃ β) (e : β ≃ γ),
-- -- on_equiv α γ (equiv.trans d e) = equiv.trans (on_equiv α β d) (on_equiv β γ e)
-- -- [_field, on_refl]
-- -- [_field, on_trans]
-- -- def transportable' : transportable group :=
-- end group
-- -- #check derive_attr
-- instance group.transport {α β : Type u} [R : group α] [e : canonical_equiv α β] : group β :=
-- sorry
-- -- (@transportable.on_equiv group group.transportable _ _ e.to_equiv).to_fun R
-- -- class transportable (f : Type u → Type v) :=
-- -- (on_equiv : Π {α β : Type u} (e : equiv α β), equiv (f α) (f β))
-- -- (on_refl : Π (α : Type u), on_equiv (equiv.refl α) = equiv.refl (f α))
-- -- (on_trans : Π {α β γ : Type u} (d : equiv α β) (e : equiv β γ), on_equiv (equiv.trans d e) = equiv.trans (on_equiv d) (on_equiv e))
-- -- -- Our goal is an automagic proof of the following
-- -- theorem group.transportable : transportable group := sorry
-- -- These we might need to define and prove by hand
-- def Const : Type u → Type v := λ α, punit
-- def Fun : Type u → Type v → Type (max u v) := λ α β, α → β
-- def Prod : Type u → Type v → Type (max u v) := λ α β, α × β
-- def Swap : Type u → Type v → Type (max u v) := λ α β, β × α
-- lemma Const.transportable (α : Type u) : (transportable Const) := sorry
-- lemma Fun.transportable (α : Type u) : (transportable (Fun α)) := sorry
-- lemma Prod.transportable (α : Type u) : (transportable (Prod α)) := sorry
-- lemma Swap.transportable (α : Type u) : (transportable (Swap α)) := sorry
-- -- And then we can define
-- def Hom1 (α : Type u) : Type v → Type (max u v) := λ β, α → β
-- def Hom2 (β : Type v) : Type u → Type (max u v) := λ α, α → β
-- def Aut : Type u → Type u := λ α, α → α
-- -- And hopefully automagically derive
-- lemma Hom1.transportable (α : Type u) : (transportable (Hom1 α)) := sorry
-- lemma Hom2.transportable (β : Type v) : (transportable (Hom1 β)) := sorry
-- lemma Aut.transportable (α : Type u) : (transportable Aut) := sorry
-- -- If we have all these in place...
-- -- A bit of magic might actually be able to derive `group.transportable` on line 11.
-- -- After all, a group just is a type plus some functions... and we can now transport functions.
|
1af73a2c3a0d478c972fa0faf3a800f2d584af5a | 5e3548e65f2c037cb94cd5524c90c623fbd6d46a | /AIME_2021_3.lean | c14917f25ddb99d5e3f37699ff7406c288da68ad | [] | 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 | 166 | lean | import data.finset.basic
theorem AIME_2021_3 (S:finset ℕ)(h:∀(n:ℕ), n∈S ↔ (n≤ 1000 ∧ ∃ (a b :ℕ),n=2^a-2^b)): finset.card S=50 :=
begin
sorry
end |
738f1c88839afba3964ed4573ffd0e5fa2d4f432 | da3a76c514d38801bae19e8a9e496dc31f8e5866 | /tests/lean/interactive/my_tac_class.lean | 057712882f711dd9cd86ab9ab51d199f5a12bbdd | [
"Apache-2.0"
] | permissive | cipher1024/lean | 270c1ac5781e6aee12f5c8d720d267563a164beb | f5cbdff8932dd30c6dd8eec68f3059393b4f8b3a | refs/heads/master | 1,611,223,459,029 | 1,487,566,573,000 | 1,487,566,573,000 | 83,356,543 | 0 | 0 | null | 1,488,229,336,000 | 1,488,229,336,000 | null | UTF-8 | Lean | false | false | 1,755 | lean | meta def mytac :=
state_t nat tactic
meta instance : monad mytac :=
state_t.monad _ _
meta instance : monad.has_monad_lift tactic mytac :=
monad.monad_transformer_lift (state_t nat) tactic
meta instance (α : Type) : has_coe (tactic α) (mytac α) :=
⟨monad.monad_lift⟩
namespace mytac
meta def step {α : Type} (t : mytac α) : mytac unit :=
t >> return ()
meta def rstep {α : Type} (line : nat) (col : nat) (t : mytac α) : mytac unit :=
λ v s, result.cases_on (@scope_trace _ line col (t v s))
(λ ⟨a, v⟩ new_s, result.success ((), v) new_s)
(λ opt_msg_thunk e new_s, match opt_msg_thunk with
| some msg_thunk := let msg := msg_thunk () ++ format.line ++ to_fmt "value: " ++ to_fmt v ++ format.line ++ to_fmt "state:" ++ format.line ++ new_s^.to_format in
(tactic.report_error line col msg >> interaction_monad.silent_fail) new_s | none := interaction_monad.silent_fail new_s end)
meta def execute (tac : mytac unit) : tactic unit :=
tac 0 >> return ()
meta def save_info (line col : nat) : mytac unit :=
do v ← state_t.read,
s ← tactic.read,
tactic.save_info_thunk line col
(λ _, to_fmt "Custom state: " ++ to_fmt v ++ format.line ++
tactic_state.to_format s)
namespace interactive
meta def intros : mytac unit :=
tactic.intros >> return ()
meta def constructor : mytac unit :=
tactic.constructor
meta def trace (s : string) : mytac unit :=
tactic.trace s
meta def assumption : mytac unit :=
tactic.assumption
meta def inc : mytac unit :=
do v ← state_t.read, state_t.write (v+1)
end interactive
end mytac
example (p q : Prop) : p → q → p ∧ q :=
begin [mytac]
intros,
inc,
trace "test",
constructor,
inc,
assumption,
--^ "command": "info"
assumption
end
|
e4b9ab6b4bc210b77a71a8689c3dfdd6c56cd9c8 | 4fa161becb8ce7378a709f5992a594764699e268 | /src/topology/basic.lean | d77c03b91517362d24c80fe41d17fd5baa233d19 | [
"Apache-2.0"
] | permissive | laughinggas/mathlib | e4aa4565ae34e46e834434284cb26bd9d67bc373 | 86dcd5cda7a5017c8b3c8876c89a510a19d49aad | refs/heads/master | 1,669,496,232,688 | 1,592,831,995,000 | 1,592,831,995,000 | 274,155,979 | 0 | 0 | Apache-2.0 | 1,592,835,190,000 | 1,592,835,189,000 | null | UTF-8 | Lean | false | false | 37,554 | 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, Jeremy Avigad
-/
import order.filter.ultrafilter
import order.filter.partial
import order.filter.bases
/-!
# Basic theory of topological spaces.
The main definition is the type class `topological space α` which endows a type `α` with a topology.
Then `set α` gets predicates `is_open`, `is_closed` and functions `interior`, `closure` and
`frontier`. Each point `x` of `α` gets a neighborhood filter `𝓝 x`.
This file also defines locally finite families of subsets of `α`.
For topological spaces `α` and `β`, a function `f : α → β` and a point `a : α`,
`continuous_at f a` means `f` is continuous at `a`, and global continuity is
`continuous f`. There is also a version of continuity `pcontinuous` for
partially defined functions.
## Implementation notes
Topology in mathlib heavily uses filters (even more than in Bourbaki). See explanations in
<https://leanprover-community.github.io/theories/topology.html>.
## References
* [N. Bourbaki, *General Topology*][bourbaki1966]
* [I. M. James, *Topologies and Uniformities*][james1999]
## Tags
topological space, interior, closure, frontier, neighborhood, continuity, continuous function
-/
open set filter classical
open_locale classical
universes u v w
/-- A topology on `α`. -/
@[protect_proj] structure topological_space (α : Type u) :=
(is_open : set α → Prop)
(is_open_univ : is_open univ)
(is_open_inter : ∀s t, is_open s → is_open t → is_open (s ∩ t))
(is_open_sUnion : ∀s, (∀t∈s, is_open t) → is_open (⋃₀ s))
attribute [class] topological_space
/-- A constructor for topologies by specifying the closed sets,
and showing that they satisfy the appropriate conditions. -/
def topological_space.of_closed {α : Type u} (T : set (set α))
(empty_mem : ∅ ∈ T) (sInter_mem : ∀ A ⊆ T, ⋂₀ A ∈ T) (union_mem : ∀ A B ∈ T, A ∪ B ∈ T) :
topological_space α :=
{ is_open := λ X, -X ∈ T,
is_open_univ := by simp [empty_mem],
is_open_inter := λ s t hs ht, by simpa [set.compl_inter] using union_mem (-s) (-t) hs ht,
is_open_sUnion := λ s hs,
by rw set.compl_sUnion; exact sInter_mem (set.compl '' s)
(λ z ⟨y, hy, hz⟩, by simpa [hz.symm] using hs y hy) }
section topological_space
variables {α : Type u} {β : Type v} {ι : Sort w} {a : α} {s s₁ s₂ : set α} {p p₁ p₂ : α → Prop}
@[ext]
lemma topological_space_eq : ∀ {f g : topological_space α}, f.is_open = g.is_open → f = g
| ⟨a, _, _, _⟩ ⟨b, _, _, _⟩ rfl := rfl
section
variables [t : topological_space α]
include t
/-- `is_open s` means that `s` is open in the ambient topological space on `α` -/
def is_open (s : set α) : Prop := topological_space.is_open t s
@[simp]
lemma is_open_univ : is_open (univ : set α) := topological_space.is_open_univ t
lemma is_open_inter (h₁ : is_open s₁) (h₂ : is_open s₂) : is_open (s₁ ∩ s₂) :=
topological_space.is_open_inter t s₁ s₂ h₁ h₂
lemma is_open_sUnion {s : set (set α)} (h : ∀t ∈ s, is_open t) : is_open (⋃₀ s) :=
topological_space.is_open_sUnion t s h
end
lemma is_open_fold {s : set α} {t : topological_space α} : t.is_open s = @is_open α t s :=
rfl
variables [topological_space α]
lemma is_open_Union {f : ι → set α} (h : ∀i, is_open (f i)) : is_open (⋃i, f i) :=
is_open_sUnion $ by rintro _ ⟨i, rfl⟩; exact h i
lemma is_open_bUnion {s : set β} {f : β → set α} (h : ∀i∈s, is_open (f i)) :
is_open (⋃i∈s, f i) :=
is_open_Union $ assume i, is_open_Union $ assume hi, h i hi
lemma is_open_union (h₁ : is_open s₁) (h₂ : is_open s₂) : is_open (s₁ ∪ s₂) :=
by rw union_eq_Union; exact is_open_Union (bool.forall_bool.2 ⟨h₂, h₁⟩)
@[simp] lemma is_open_empty : is_open (∅ : set α) :=
by rw ← sUnion_empty; exact is_open_sUnion (assume a, false.elim)
lemma is_open_sInter {s : set (set α)} (hs : finite s) : (∀t ∈ s, is_open t) → is_open (⋂₀ s) :=
finite.induction_on hs (λ _, by rw sInter_empty; exact is_open_univ) $
λ a s has hs ih h, by rw sInter_insert; exact
is_open_inter (h _ $ mem_insert _ _) (ih $ λ t, h t ∘ mem_insert_of_mem _)
lemma is_open_bInter {s : set β} {f : β → set α} (hs : finite s) :
(∀i∈s, is_open (f i)) → is_open (⋂i∈s, f i) :=
finite.induction_on hs
(λ _, by rw bInter_empty; exact is_open_univ)
(λ a s has hs ih h, by rw bInter_insert; exact
is_open_inter (h a (mem_insert _ _)) (ih (λ i hi, h i (mem_insert_of_mem _ hi))))
lemma is_open_Inter [fintype β] {s : β → set α}
(h : ∀ i, is_open (s i)) : is_open (⋂ i, s i) :=
suffices is_open (⋂ (i : β) (hi : i ∈ @univ β), s i), by simpa,
is_open_bInter finite_univ (λ i _, h i)
lemma is_open_Inter_prop {p : Prop} {s : p → set α}
(h : ∀ h : p, is_open (s h)) : is_open (Inter s) :=
by by_cases p; simp *
lemma is_open_const {p : Prop} : is_open {a : α | p} :=
by_cases
(assume : p, begin simp only [this]; exact is_open_univ end)
(assume : ¬ p, begin simp only [this]; exact is_open_empty end)
lemma is_open_and : is_open {a | p₁ a} → is_open {a | p₂ a} → is_open {a | p₁ a ∧ p₂ a} :=
is_open_inter
/-- A set is closed if its complement is open -/
def is_closed (s : set α) : Prop := is_open (-s)
@[simp] lemma is_closed_empty : is_closed (∅ : set α) :=
by unfold is_closed; rw compl_empty; exact is_open_univ
@[simp] lemma is_closed_univ : is_closed (univ : set α) :=
by unfold is_closed; rw compl_univ; exact is_open_empty
lemma is_closed_union : is_closed s₁ → is_closed s₂ → is_closed (s₁ ∪ s₂) :=
λ h₁ h₂, by unfold is_closed; rw compl_union; exact is_open_inter h₁ h₂
lemma is_closed_sInter {s : set (set α)} : (∀t ∈ s, is_closed t) → is_closed (⋂₀ s) :=
by simp only [is_closed, compl_sInter, sUnion_image]; exact assume h, is_open_Union $ assume t, is_open_Union $ assume ht, h t ht
lemma is_closed_Inter {f : ι → set α} (h : ∀i, is_closed (f i)) : is_closed (⋂i, f i ) :=
is_closed_sInter $ assume t ⟨i, (heq : f i = t)⟩, heq ▸ h i
@[simp] lemma is_open_compl_iff {s : set α} : is_open (-s) ↔ is_closed s := iff.rfl
@[simp] lemma is_closed_compl_iff {s : set α} : is_closed (-s) ↔ is_open s :=
by rw [←is_open_compl_iff, compl_compl]
lemma is_open_diff {s t : set α} (h₁ : is_open s) (h₂ : is_closed t) : is_open (s \ t) :=
is_open_inter h₁ $ is_open_compl_iff.mpr h₂
lemma is_closed_inter (h₁ : is_closed s₁) (h₂ : is_closed s₂) : is_closed (s₁ ∩ s₂) :=
by rw [is_closed, compl_inter]; exact is_open_union h₁ h₂
lemma is_closed_bUnion {s : set β} {f : β → set α} (hs : finite s) :
(∀i∈s, is_closed (f i)) → is_closed (⋃i∈s, f i) :=
finite.induction_on hs
(λ _, by rw bUnion_empty; exact is_closed_empty)
(λ a s has hs ih h, by rw bUnion_insert; exact
is_closed_union (h a (mem_insert _ _)) (ih (λ i hi, h i (mem_insert_of_mem _ hi))))
lemma is_closed_Union [fintype β] {s : β → set α}
(h : ∀ i, is_closed (s i)) : is_closed (Union s) :=
suffices is_closed (⋃ (i : β) (hi : i ∈ @univ β), s i),
by convert this; simp [set.ext_iff],
is_closed_bUnion finite_univ (λ i _, h i)
lemma is_closed_Union_prop {p : Prop} {s : p → set α}
(h : ∀ h : p, is_closed (s h)) : is_closed (Union s) :=
by by_cases p; simp *
lemma is_closed_imp {p q : α → Prop} (hp : is_open {x | p x})
(hq : is_closed {x | q x}) : is_closed {x | p x → q x} :=
have {x | p x → q x} = (- {x | p x}) ∪ {x | q x}, from set.ext $ λ x, imp_iff_not_or,
by rw [this]; exact is_closed_union (is_closed_compl_iff.mpr hp) hq
lemma is_open_neg : is_closed {a | p a} → is_open {a | ¬ p a} :=
is_open_compl_iff.mpr
/-- The interior of a set `s` is the largest open subset of `s`. -/
def interior (s : set α) : set α := ⋃₀ {t | is_open t ∧ t ⊆ s}
lemma mem_interior {s : set α} {x : α} :
x ∈ interior s ↔ ∃ t ⊆ s, is_open t ∧ x ∈ t :=
by simp only [interior, mem_set_of_eq, exists_prop, and_assoc, and.left_comm]
@[simp] lemma is_open_interior {s : set α} : is_open (interior s) :=
is_open_sUnion $ assume t ⟨h₁, h₂⟩, h₁
lemma interior_subset {s : set α} : interior s ⊆ s :=
sUnion_subset $ assume t ⟨h₁, h₂⟩, h₂
lemma interior_maximal {s t : set α} (h₁ : t ⊆ s) (h₂ : is_open t) : t ⊆ interior s :=
subset_sUnion_of_mem ⟨h₂, h₁⟩
lemma interior_eq_of_open {s : set α} (h : is_open s) : interior s = s :=
subset.antisymm interior_subset (interior_maximal (subset.refl s) h)
lemma interior_eq_iff_open {s : set α} : interior s = s ↔ is_open s :=
⟨assume h, h ▸ is_open_interior, interior_eq_of_open⟩
lemma subset_interior_iff_open {s : set α} : s ⊆ interior s ↔ is_open s :=
by simp only [interior_eq_iff_open.symm, subset.antisymm_iff, interior_subset, true_and]
lemma subset_interior_iff_subset_of_open {s t : set α} (h₁ : is_open s) :
s ⊆ interior t ↔ s ⊆ t :=
⟨assume h, subset.trans h interior_subset, assume h₂, interior_maximal h₂ h₁⟩
lemma interior_mono {s t : set α} (h : s ⊆ t) : interior s ⊆ interior t :=
interior_maximal (subset.trans interior_subset h) is_open_interior
@[simp] lemma interior_empty : interior (∅ : set α) = ∅ :=
interior_eq_of_open is_open_empty
@[simp] lemma interior_univ : interior (univ : set α) = univ :=
interior_eq_of_open is_open_univ
@[simp] lemma interior_interior {s : set α} : interior (interior s) = interior s :=
interior_eq_of_open is_open_interior
@[simp] lemma interior_inter {s t : set α} : interior (s ∩ t) = interior s ∩ interior t :=
subset.antisymm
(subset_inter (interior_mono $ inter_subset_left s t) (interior_mono $ inter_subset_right s t))
(interior_maximal (inter_subset_inter interior_subset interior_subset) $ is_open_inter is_open_interior is_open_interior)
lemma interior_union_is_closed_of_interior_empty {s t : set α} (h₁ : is_closed s) (h₂ : interior t = ∅) :
interior (s ∪ t) = interior s :=
have interior (s ∪ t) ⊆ s, from
assume x ⟨u, ⟨(hu₁ : is_open u), (hu₂ : u ⊆ s ∪ t)⟩, (hx₁ : x ∈ u)⟩,
classical.by_contradiction $ assume hx₂ : x ∉ s,
have u \ s ⊆ t,
from assume x ⟨h₁, h₂⟩, or.resolve_left (hu₂ h₁) h₂,
have u \ s ⊆ interior t,
by rwa subset_interior_iff_subset_of_open (is_open_diff hu₁ h₁),
have u \ s ⊆ ∅,
by rwa h₂ at this,
this ⟨hx₁, hx₂⟩,
subset.antisymm
(interior_maximal this is_open_interior)
(interior_mono $ subset_union_left _ _)
lemma is_open_iff_forall_mem_open : is_open s ↔ ∀ x ∈ s, ∃ t ⊆ s, is_open t ∧ x ∈ t :=
by rw ← subset_interior_iff_open; simp only [subset_def, mem_interior]
/-- The closure of `s` is the smallest closed set containing `s`. -/
def closure (s : set α) : set α := ⋂₀ {t | is_closed t ∧ s ⊆ t}
@[simp] lemma is_closed_closure {s : set α} : is_closed (closure s) :=
is_closed_sInter $ assume t ⟨h₁, h₂⟩, h₁
lemma subset_closure {s : set α} : s ⊆ closure s :=
subset_sInter $ assume t ⟨h₁, h₂⟩, h₂
lemma closure_minimal {s t : set α} (h₁ : s ⊆ t) (h₂ : is_closed t) : closure s ⊆ t :=
sInter_subset_of_mem ⟨h₂, h₁⟩
lemma closure_eq_of_is_closed {s : set α} (h : is_closed s) : closure s = s :=
subset.antisymm (closure_minimal (subset.refl s) h) subset_closure
lemma closure_eq_iff_is_closed {s : set α} : closure s = s ↔ is_closed s :=
⟨assume h, h ▸ is_closed_closure, closure_eq_of_is_closed⟩
lemma closure_subset_iff_subset_of_is_closed {s t : set α} (h₁ : is_closed t) :
closure s ⊆ t ↔ s ⊆ t :=
⟨subset.trans subset_closure, assume h, closure_minimal h h₁⟩
lemma closure_mono {s t : set α} (h : s ⊆ t) : closure s ⊆ closure t :=
closure_minimal (subset.trans h subset_closure) is_closed_closure
lemma monotone_closure (α : Type*) [topological_space α] : monotone (@closure α _) :=
λ _ _, closure_mono
lemma closure_inter_subset_inter_closure (s t : set α) :
closure (s ∩ t) ⊆ closure s ∩ closure t :=
(monotone_closure α).map_inf_le s t
lemma is_closed_of_closure_subset {s : set α} (h : closure s ⊆ s) : is_closed s :=
by rw subset.antisymm subset_closure h; exact is_closed_closure
@[simp] lemma closure_empty : closure (∅ : set α) = ∅ :=
closure_eq_of_is_closed is_closed_empty
lemma closure_empty_iff (s : set α) : closure s = ∅ ↔ s = ∅ :=
⟨subset_eq_empty subset_closure, λ h, h.symm ▸ closure_empty⟩
lemma set.nonempty.closure {s : set α} (h : s.nonempty) :
set.nonempty (closure s) :=
let ⟨x, hx⟩ := h in ⟨x, subset_closure hx⟩
@[simp] lemma closure_univ : closure (univ : set α) = univ :=
closure_eq_of_is_closed is_closed_univ
@[simp] lemma closure_closure {s : set α} : closure (closure s) = closure s :=
closure_eq_of_is_closed is_closed_closure
@[simp] lemma closure_union {s t : set α} : closure (s ∪ t) = closure s ∪ closure t :=
subset.antisymm
(closure_minimal (union_subset_union subset_closure subset_closure) $ is_closed_union is_closed_closure is_closed_closure)
((monotone_closure α).le_map_sup s t)
lemma interior_subset_closure {s : set α} : interior s ⊆ closure s :=
subset.trans interior_subset subset_closure
lemma closure_eq_compl_interior_compl {s : set α} : closure s = - interior (- s) :=
begin
unfold interior closure is_closed,
rw [compl_sUnion, compl_image_set_of],
simp only [compl_subset_compl]
end
@[simp] lemma interior_compl {s : set α} : interior (- s) = - closure s :=
by simp [closure_eq_compl_interior_compl]
@[simp] lemma closure_compl {s : set α} : closure (- s) = - interior s :=
by simp [closure_eq_compl_interior_compl]
theorem mem_closure_iff {s : set α} {a : α} :
a ∈ closure s ↔ ∀ o, is_open o → a ∈ o → (o ∩ s).nonempty :=
⟨λ h o oo ao, classical.by_contradiction $ λ os,
have s ⊆ -o, from λ x xs xo, os ⟨x, xo, xs⟩,
closure_minimal this (is_closed_compl_iff.2 oo) h ao,
λ H c ⟨h₁, h₂⟩, classical.by_contradiction $ λ nc,
let ⟨x, hc, hs⟩ := (H _ h₁ nc) in hc (h₂ hs)⟩
lemma dense_iff_inter_open {s : set α} :
closure s = univ ↔ ∀ U, is_open U → U.nonempty → (U ∩ s).nonempty :=
begin
split ; intro h,
{ rintros U U_op ⟨x, x_in⟩,
exact mem_closure_iff.1 (by simp only [h]) U U_op x_in },
{ apply eq_univ_of_forall, intro x,
rw mem_closure_iff,
intros U U_op x_in,
exact h U U_op ⟨_, x_in⟩ },
end
lemma dense_of_subset_dense {s₁ s₂ : set α} (h : s₁ ⊆ s₂) (hd : closure s₁ = univ) :
closure s₂ = univ :=
by { rw [← univ_subset_iff, ← hd], exact closure_mono h }
/-- The frontier of a set is the set of points between the closure and interior. -/
def frontier (s : set α) : set α := closure s \ interior s
lemma frontier_eq_closure_inter_closure {s : set α} :
frontier s = closure s ∩ closure (- s) :=
by rw [closure_compl, frontier, diff_eq]
/-- The complement of a set has the same frontier as the original set. -/
@[simp] lemma frontier_compl (s : set α) : frontier (-s) = frontier s :=
by simp only [frontier_eq_closure_inter_closure, compl_compl, inter_comm]
lemma frontier_inter_subset (s t : set α) :
frontier (s ∩ t) ⊆ (frontier s ∩ closure t) ∪ (closure s ∩ frontier t) :=
begin
simp only [frontier_eq_closure_inter_closure, compl_inter, closure_union],
convert inter_subset_inter_left _ (closure_inter_subset_inter_closure s t),
simp only [inter_distrib_left, inter_distrib_right, inter_assoc],
congr' 2,
apply inter_comm
end
lemma frontier_union_subset (s t : set α) :
frontier (s ∪ t) ⊆ (frontier s ∩ closure (-t)) ∪ (closure (-s) ∩ frontier t) :=
by simpa only [frontier_compl, (compl_union _ _).symm]
using frontier_inter_subset (-s) (-t)
lemma is_closed.frontier_eq {s : set α} (hs : is_closed s) : frontier s = s \ interior s :=
by rw [frontier, closure_eq_of_is_closed hs]
lemma is_open.frontier_eq {s : set α} (hs : is_open s) : frontier s = closure s \ s :=
by rw [frontier, interior_eq_of_open hs]
/-- The frontier of a set is closed. -/
lemma is_closed_frontier {s : set α} : is_closed (frontier s) :=
by rw frontier_eq_closure_inter_closure; exact is_closed_inter is_closed_closure is_closed_closure
/-- The frontier of a set has no interior point. -/
lemma interior_frontier {s : set α} (h : is_closed s) : interior (frontier s) = ∅ :=
begin
have A : frontier s = s \ interior s, from h.frontier_eq,
have B : interior (frontier s) ⊆ interior s, by rw A; exact interior_mono (diff_subset _ _),
have C : interior (frontier s) ⊆ frontier s := interior_subset,
have : interior (frontier s) ⊆ (interior s) ∩ (s \ interior s) :=
subset_inter B (by simpa [A] using C),
rwa [inter_diff_self, subset_empty_iff] at this,
end
/-- neighbourhood filter -/
def nhds (a : α) : filter α := (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, principal s)
localized "notation `𝓝` := nhds" in topological_space
lemma nhds_def (a : α) : 𝓝 a = (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, principal s) := rfl
lemma nhds_basis_opens (a : α) : (𝓝 a).has_basis (λ s : set α, a ∈ s ∧ is_open s) (λ x, x) :=
has_basis_binfi_principal
(λ s ⟨has, hs⟩ t ⟨hat, ht⟩, ⟨s ∩ t, ⟨⟨has, hat⟩, is_open_inter hs ht⟩,
⟨inter_subset_left _ _, inter_subset_right _ _⟩⟩)
⟨univ, ⟨mem_univ a, is_open_univ⟩⟩
lemma le_nhds_iff {f a} : f ≤ 𝓝 a ↔ ∀ s : set α, a ∈ s → is_open s → s ∈ f :=
by simp [nhds_def]
lemma nhds_le_of_le {f a} {s : set α} (h : a ∈ s) (o : is_open s) (sf : principal s ≤ f) : 𝓝 a ≤ f :=
by rw nhds_def; exact infi_le_of_le s (infi_le_of_le ⟨h, o⟩ sf)
lemma mem_nhds_sets_iff {a : α} {s : set α} :
s ∈ 𝓝 a ↔ ∃t⊆s, is_open t ∧ a ∈ t :=
(nhds_basis_opens a).mem_iff.trans
⟨λ ⟨t, ⟨hat, ht⟩, hts⟩, ⟨t, hts, ht, hat⟩, λ ⟨t, hts, ht, hat⟩, ⟨t, ⟨hat, ht⟩, hts⟩⟩
lemma map_nhds {a : α} {f : α → β} :
map f (𝓝 a) = (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, principal (image f s)) :=
((nhds_basis_opens a).map f).eq_binfi
attribute [irreducible] nhds
lemma mem_of_nhds {a : α} {s : set α} : s ∈ 𝓝 a → a ∈ s :=
λ H, let ⟨t, ht, _, hs⟩ := mem_nhds_sets_iff.1 H in ht hs
lemma filter.eventually.self_of_nhds {p : α → Prop} {a : α}
(h : ∀ᶠ y in 𝓝 a, p y) : p a :=
mem_of_nhds h
lemma mem_nhds_sets {a : α} {s : set α} (hs : is_open s) (ha : a ∈ s) :
s ∈ 𝓝 a :=
mem_nhds_sets_iff.2 ⟨s, subset.refl _, hs, ha⟩
theorem all_mem_nhds (x : α) (P : set α → Prop) (hP : ∀ s t, s ⊆ t → P s → P t) :
(∀ s ∈ 𝓝 x, P s) ↔ (∀ s, is_open s → x ∈ s → P s) :=
iff.intro
(λ h s os xs, h s (mem_nhds_sets os xs))
(λ h t,
begin
change t ∈ 𝓝 x → P t,
rw mem_nhds_sets_iff,
rintros ⟨s, hs, opens, xs⟩,
exact hP _ _ hs (h s opens xs),
end)
theorem all_mem_nhds_filter (x : α) (f : set α → set β) (hf : ∀ s t, s ⊆ t → f s ⊆ f t)
(l : filter β) :
(∀ s ∈ 𝓝 x, f s ∈ l) ↔ (∀ s, is_open s → x ∈ s → f s ∈ l) :=
all_mem_nhds _ _ (λ s t ssubt h, mem_sets_of_superset h (hf s t ssubt))
theorem rtendsto_nhds {r : rel β α} {l : filter β} {a : α} :
rtendsto r l (𝓝 a) ↔ (∀ s, is_open s → a ∈ s → r.core s ∈ l) :=
all_mem_nhds_filter _ _ (λ s t, id) _
theorem rtendsto'_nhds {r : rel β α} {l : filter β} {a : α} :
rtendsto' r l (𝓝 a) ↔ (∀ s, is_open s → a ∈ s → r.preimage s ∈ l) :=
by { rw [rtendsto'_def], apply all_mem_nhds_filter, apply rel.preimage_mono }
theorem ptendsto_nhds {f : β →. α} {l : filter β} {a : α} :
ptendsto f l (𝓝 a) ↔ (∀ s, is_open s → a ∈ s → f.core s ∈ l) :=
rtendsto_nhds
theorem ptendsto'_nhds {f : β →. α} {l : filter β} {a : α} :
ptendsto' f l (𝓝 a) ↔ (∀ s, is_open s → a ∈ s → f.preimage s ∈ l) :=
rtendsto'_nhds
theorem tendsto_nhds {f : β → α} {l : filter β} {a : α} :
tendsto f l (𝓝 a) ↔ (∀ s, is_open s → a ∈ s → f ⁻¹' s ∈ l) :=
all_mem_nhds_filter _ _ (λ s t h, preimage_mono h) _
lemma tendsto_const_nhds {a : α} {f : filter β} : tendsto (λb:β, a) f (𝓝 a) :=
tendsto_nhds.mpr $ assume s hs ha, univ_mem_sets' $ assume _, ha
lemma pure_le_nhds : pure ≤ (𝓝 : α → filter α) :=
assume a s hs, mem_pure_sets.2 $ mem_of_nhds hs
lemma tendsto_pure_nhds {α : Type*} [topological_space β] (f : α → β) (a : α) :
tendsto f (pure a) (𝓝 (f a)) :=
begin
rw [tendsto, filter.map_pure],
exact pure_le_nhds (f a)
end
@[simp] lemma nhds_ne_bot {a : α} : 𝓝 a ≠ ⊥ :=
ne_bot_of_le_ne_bot pure_ne_bot (pure_le_nhds a)
lemma interior_eq_nhds {s : set α} : interior s = {a | 𝓝 a ≤ principal s} :=
set.ext $ λ x, by simp only [mem_interior, le_principal_iff, mem_nhds_sets_iff]; refl
lemma mem_interior_iff_mem_nhds {s : set α} {a : α} :
a ∈ interior s ↔ s ∈ 𝓝 a :=
by simp only [interior_eq_nhds, le_principal_iff]; refl
lemma is_open_iff_nhds {s : set α} : is_open s ↔ ∀a∈s, 𝓝 a ≤ principal s :=
calc is_open s ↔ s ⊆ interior s : subset_interior_iff_open.symm
... ↔ (∀a∈s, 𝓝 a ≤ principal s) : by rw [interior_eq_nhds]; refl
lemma is_open_iff_mem_nhds {s : set α} : is_open s ↔ ∀a∈s, s ∈ 𝓝 a :=
is_open_iff_nhds.trans $ forall_congr $ λ _, imp_congr_right $ λ _, le_principal_iff
lemma closure_eq_nhds {s : set α} : closure s = {a | 𝓝 a ⊓ principal s ≠ ⊥} :=
calc closure s = - interior (- s) : closure_eq_compl_interior_compl
... = {a | ¬ 𝓝 a ≤ principal (-s)} : by rw [interior_eq_nhds]; refl
... = {a | 𝓝 a ⊓ principal s ≠ ⊥} : set.ext $ assume a, not_congr
(inf_eq_bot_iff_le_compl
(show principal s ⊔ principal (-s) = ⊤, by simp only [sup_principal, union_compl_self, principal_univ])
(by simp only [inf_principal, inter_compl_self, principal_empty])).symm
theorem mem_closure_iff_nhds {s : set α} {a : α} :
a ∈ closure s ↔ ∀ t ∈ 𝓝 a, (t ∩ s).nonempty :=
mem_closure_iff.trans
⟨λ H t ht, nonempty.mono
(inter_subset_inter_left _ interior_subset)
(H _ is_open_interior (mem_interior_iff_mem_nhds.2 ht)),
λ H o oo ao, H _ (mem_nhds_sets oo ao)⟩
theorem mem_closure_iff_nhds_basis {a : α} {p : β → Prop} {s : β → set α} (h : (𝓝 a).has_basis p s)
{t : set α} :
a ∈ closure t ↔ ∀ i, p i → ∃ y ∈ t, y ∈ s i :=
mem_closure_iff_nhds.trans
⟨λ H i hi, let ⟨x, hx⟩ := (H _ $ h.mem_of_mem hi) in ⟨x, hx.2, hx.1⟩,
λ H t' ht', let ⟨i, hi, hit⟩ := h.mem_iff.1 ht', ⟨x, xt, hx⟩ := H i hi in
⟨x, hit hx, xt⟩⟩
/-- `x` belongs to the closure of `s` if and only if some ultrafilter
supported on `s` converges to `x`. -/
lemma mem_closure_iff_ultrafilter {s : set α} {x : α} :
x ∈ closure s ↔ ∃ (u : ultrafilter α), s ∈ u.val ∧ u.val ≤ 𝓝 x :=
begin
rw closure_eq_nhds, change 𝓝 x ⊓ principal s ≠ ⊥ ↔ _, symmetry,
convert exists_ultrafilter_iff _, ext u,
rw [←le_principal_iff, inf_comm, le_inf_iff]
end
lemma is_closed_iff_nhds {s : set α} : is_closed s ↔ ∀a, 𝓝 a ⊓ principal s ≠ ⊥ → a ∈ s :=
calc is_closed s ↔ closure s = s : by rw [closure_eq_iff_is_closed]
... ↔ closure s ⊆ s : ⟨assume h, by rw h, assume h, subset.antisymm h subset_closure⟩
... ↔ (∀a, 𝓝 a ⊓ principal s ≠ ⊥ → a ∈ s) : by rw [closure_eq_nhds]; refl
lemma closure_inter_open {s t : set α} (h : is_open s) : s ∩ closure t ⊆ closure (s ∩ t) :=
assume a ⟨hs, ht⟩,
have s ∈ 𝓝 a, from mem_nhds_sets h hs,
have 𝓝 a ⊓ principal s = 𝓝 a, by rwa [inf_eq_left, le_principal_iff],
have 𝓝 a ⊓ principal (s ∩ t) ≠ ⊥,
from calc 𝓝 a ⊓ principal (s ∩ t) = 𝓝 a ⊓ (principal s ⊓ principal t) : by rw inf_principal
... = 𝓝 a ⊓ principal t : by rw [←inf_assoc, this]
... ≠ ⊥ : by rw [closure_eq_nhds] at ht; assumption,
by rwa [closure_eq_nhds]
lemma closure_diff {s t : set α} : closure s - closure t ⊆ closure (s - t) :=
calc closure s \ closure t = (- closure t) ∩ closure s : by simp only [diff_eq, inter_comm]
... ⊆ closure (- closure t ∩ s) : closure_inter_open $ is_open_compl_iff.mpr $ is_closed_closure
... = closure (s \ closure t) : by simp only [diff_eq, inter_comm]
... ⊆ closure (s \ t) : closure_mono $ diff_subset_diff (subset.refl s) subset_closure
lemma mem_of_closed_of_tendsto {f : β → α} {b : filter β} {a : α} {s : set α}
(hb : b ≠ ⊥) (hf : tendsto f b (𝓝 a)) (hs : is_closed s) (h : f ⁻¹' s ∈ b) : a ∈ s :=
have b.map f ≤ 𝓝 a ⊓ principal s,
from le_trans (le_inf (le_refl _) (le_principal_iff.mpr h)) (inf_le_inf_right _ hf),
is_closed_iff_nhds.mp hs a $ ne_bot_of_le_ne_bot (map_ne_bot hb) this
lemma mem_of_closed_of_tendsto' {f : β → α} {x : filter β} {a : α} {s : set α}
(hf : tendsto f x (𝓝 a)) (hs : is_closed s) (h : x ⊓ principal (f ⁻¹' s) ≠ ⊥) : a ∈ s :=
is_closed_iff_nhds.mp hs _ $ ne_bot_of_le_ne_bot (@map_ne_bot _ _ _ f h) $
le_inf (le_trans (map_mono $ inf_le_left) hf) $
le_trans (map_mono $ inf_le_right_of_le $
by simp only [comap_principal, le_principal_iff]; exact subset.refl _) (@map_comap_le _ _ _ f)
lemma mem_closure_of_tendsto {f : β → α} {b : filter β} {a : α} {s : set α}
(hb : b ≠ ⊥) (hf : tendsto f b (𝓝 a)) (h : ∀ᶠ x in b, f x ∈ s) : a ∈ closure s :=
mem_of_closed_of_tendsto hb hf (is_closed_closure) $
filter.mem_sets_of_superset h (preimage_mono subset_closure)
/-- Suppose that `f` sends the complement to `s` to a single point `a`, and `l` is some filter.
Then `f` tends to `a` along `l` restricted to `s` if and only it tends to `a` along `l`. -/
lemma tendsto_inf_principal_nhds_iff_of_forall_eq {f : β → α} {l : filter β} {s : set β}
{a : α} (h : ∀ x ∉ s, f x = a) :
tendsto f (l ⊓ principal s) (𝓝 a) ↔ tendsto f l (𝓝 a) :=
begin
rw [tendsto_iff_comap, tendsto_iff_comap],
replace h : principal (-s) ≤ comap f (𝓝 a),
{ rintros U ⟨t, ht, htU⟩ x hx,
have : f x ∈ t, from (h x hx).symm ▸ mem_of_nhds ht,
exact htU this },
refine ⟨λ h', _, le_trans inf_le_left⟩,
have := sup_le h' h,
rw [sup_inf_right, sup_principal, union_compl_self, principal_univ,
inf_top_eq, sup_le_iff] at this,
exact this.1
end
section lim
/-- If `f` is a filter, then `Lim f` is a limit of the filter, if it exists. -/
noncomputable def Lim [nonempty α] (f : filter α) : α := epsilon $ λa, f ≤ 𝓝 a
/-- If `f` is a filter in `β` and `g : β → α` is a function, then `lim f` is a limit of `g` at `f`,
if it exists. -/
noncomputable def lim [nonempty α] (f : filter β) (g : β → α) : α :=
Lim (f.map g)
/-- If a filter `f` is majorated by some `𝓝 a`, then it is majorated by `𝓝 (Lim f)`. We formulate
this lemma with a `[nonempty α]` argument of `Lim` derived from `h` to make it useful for types
without a `[nonempty α]` instance. Because of the built-in proof irrelevance, Lean will unify
this instance with any other instance. -/
lemma Lim_spec {f : filter α} (h : ∃a, f ≤ 𝓝 a) : f ≤ 𝓝 (@Lim _ _ (nonempty_of_exists h) f) :=
epsilon_spec h
/-- If `g` tends to some `𝓝 a` along `f`, then it tends to `𝓝 (lim f g)`. We formulate
this lemma with a `[nonempty α]` argument of `lim` derived from `h` to make it useful for types
without a `[nonempty α]` instance. Because of the built-in proof irrelevance, Lean will unify
this instance with any other instance. -/
lemma lim_spec {f : filter β} {g : β → α} (h : ∃ a, tendsto g f (𝓝 a)) :
tendsto g f (𝓝 $ @lim _ _ _ (nonempty_of_exists h) f g) :=
Lim_spec h
end lim
/- locally finite family [General Topology (Bourbaki, 1995)] -/
section locally_finite
/-- A family of sets in `set α` is locally finite if at every point `x:α`,
there is a neighborhood of `x` which meets only finitely many sets in the family -/
def locally_finite (f : β → set α) :=
∀x:α, ∃t ∈ 𝓝 x, finite {i | (f i ∩ t).nonempty }
lemma locally_finite_of_finite {f : β → set α} (h : finite (univ : set β)) : locally_finite f :=
assume x, ⟨univ, univ_mem_sets, finite_subset h $ subset_univ _⟩
lemma locally_finite_subset
{f₁ f₂ : β → set α} (hf₂ : locally_finite f₂) (hf : ∀b, f₁ b ⊆ f₂ b) : locally_finite f₁ :=
assume a,
let ⟨t, ht₁, ht₂⟩ := hf₂ a in
⟨t, ht₁, finite_subset ht₂ $ assume i hi,
hi.mono $ inter_subset_inter (hf i) $ subset.refl _⟩
lemma is_closed_Union_of_locally_finite {f : β → set α}
(h₁ : locally_finite f) (h₂ : ∀i, is_closed (f i)) : is_closed (⋃i, f i) :=
is_open_iff_nhds.mpr $ assume a, assume h : a ∉ (⋃i, f i),
have ∀i, a ∈ -f i,
from assume i hi, h $ mem_Union.2 ⟨i, hi⟩,
have ∀i, - f i ∈ (𝓝 a),
by simp only [mem_nhds_sets_iff]; exact assume i, ⟨- f i, subset.refl _, h₂ i, this i⟩,
let ⟨t, h_sets, (h_fin : finite {i | (f i ∩ t).nonempty })⟩ := h₁ a in
calc 𝓝 a ≤ principal (t ∩ (⋂ i∈{i | (f i ∩ t).nonempty }, - f i)) :
begin
rw [le_principal_iff],
apply @filter.inter_mem_sets _ (𝓝 a) _ _ h_sets,
apply @filter.Inter_mem_sets _ (𝓝 a) _ _ _ h_fin,
exact assume i h, this i
end
... ≤ principal (- ⋃i, f i) :
begin
simp only [principal_mono, subset_def, mem_compl_eq, mem_inter_eq,
mem_Inter, mem_set_of_eq, mem_Union, and_imp, not_exists,
exists_imp_distrib, ne_empty_iff_nonempty, set.nonempty],
exact assume x xt ht i xfi, ht i x xfi xt xfi
end
end locally_finite
end topological_space
section continuous
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
variables [topological_space α] [topological_space β] [topological_space γ]
open_locale topological_space
/-- A function between topological spaces is continuous if the preimage
of every open set is open. -/
def continuous (f : α → β) := ∀s, is_open s → is_open (f ⁻¹' s)
/-- A function between topological spaces is continuous at a point `x₀`
if `f x` tends to `f x₀` when `x` tends to `x₀`. -/
def continuous_at (f : α → β) (x : α) := tendsto f (𝓝 x) (𝓝 (f x))
lemma continuous_at.tendsto {f : α → β} {x : α} (h : continuous_at f x) :
tendsto f (𝓝 x) (𝓝 (f x)) :=
h
lemma continuous_at.preimage_mem_nhds {f : α → β} {x : α} {t : set β} (h : continuous_at f x)
(ht : t ∈ 𝓝 (f x)) : f ⁻¹' t ∈ 𝓝 x :=
h ht
lemma preimage_interior_subset_interior_preimage {f : α → β} {s : set β}
(hf : continuous f) : f⁻¹' (interior s) ⊆ interior (f⁻¹' s) :=
interior_maximal (preimage_mono interior_subset) (hf _ is_open_interior)
lemma continuous_id : continuous (id : α → α) :=
assume s h, h
lemma continuous.comp {g : β → γ} {f : α → β} (hg : continuous g) (hf : continuous f) :
continuous (g ∘ f) :=
assume s h, hf _ (hg s h)
lemma continuous.iterate {f : α → α} (h : continuous f) (n : ℕ) : continuous (f^[n]) :=
nat.rec_on n continuous_id (λ n ihn, ihn.comp h)
lemma continuous_at.comp {g : β → γ} {f : α → β} {x : α}
(hg : continuous_at g (f x)) (hf : continuous_at f x) :
continuous_at (g ∘ f) x :=
hg.comp hf
lemma continuous.tendsto {f : α → β} (hf : continuous f) (x) :
tendsto f (𝓝 x) (𝓝 (f x)) :=
((nhds_basis_opens x).tendsto_iff $ nhds_basis_opens $ f x).2 $
λ t ⟨hxt, ht⟩, ⟨f ⁻¹' t, ⟨hxt, hf _ ht⟩, subset.refl _⟩
lemma continuous.continuous_at {f : α → β} {x : α} (h : continuous f) :
continuous_at f x :=
h.tendsto x
lemma continuous_iff_continuous_at {f : α → β} : continuous f ↔ ∀ x, continuous_at f x :=
⟨continuous.tendsto,
assume hf : ∀x, tendsto f (𝓝 x) (𝓝 (f x)),
assume s, assume hs : is_open s,
have ∀a, f a ∈ s → s ∈ 𝓝 (f a),
from λ a ha, mem_nhds_sets hs ha,
show is_open (f ⁻¹' s),
from is_open_iff_nhds.2 $ λ a ha, le_principal_iff.2 $ hf _ (this a ha)⟩
lemma continuous_const {b : β} : continuous (λa:α, b) :=
continuous_iff_continuous_at.mpr $ assume a, tendsto_const_nhds
lemma continuous_at_const {x : α} {b : β} : continuous_at (λ a:α, b) x :=
continuous_const.continuous_at
lemma continuous_at_id {x : α} : continuous_at id x :=
continuous_id.continuous_at
lemma continuous_at.iterate {f : α → α} {x : α} (hf : continuous_at f x) (hx : f x = x) (n : ℕ) :
continuous_at (f^[n]) x :=
nat.rec_on n continuous_at_id $ λ n ihn,
show continuous_at (f^[n] ∘ f) x,
from continuous_at.comp (hx.symm ▸ ihn) hf
lemma continuous_iff_is_closed {f : α → β} :
continuous f ↔ (∀s, is_closed s → is_closed (f ⁻¹' s)) :=
⟨assume hf s hs, hf (-s) hs,
assume hf s, by rw [←is_closed_compl_iff, ←is_closed_compl_iff]; exact hf _⟩
lemma continuous_at_iff_ultrafilter {f : α → β} (x) : continuous_at f x ↔
∀ g, is_ultrafilter g → g ≤ 𝓝 x → g.map f ≤ 𝓝 (f x) :=
tendsto_iff_ultrafilter f (𝓝 x) (𝓝 (f x))
lemma continuous_iff_ultrafilter {f : α → β} :
continuous f ↔ ∀ x g, is_ultrafilter g → g ≤ 𝓝 x → g.map f ≤ 𝓝 (f x) :=
by simp only [continuous_iff_continuous_at, continuous_at_iff_ultrafilter]
/-- A piecewise defined function `if p then f else g` is continuous, if both `f` and `g`
are continuous, and they coincide on the frontier (boundary) of the set `{a | p a}`. -/
lemma continuous_if {p : α → Prop} {f g : α → β} {h : ∀a, decidable (p a)}
(hp : ∀a∈frontier {a | p a}, f a = g a) (hf : continuous f) (hg : continuous g) :
continuous (λa, @ite (p a) (h a) β (f a) (g a)) :=
continuous_iff_is_closed.mpr $
assume s hs,
have (λa, ite (p a) (f a) (g a)) ⁻¹' s =
(closure {a | p a} ∩ f ⁻¹' s) ∪ (closure {a | ¬ p a} ∩ g ⁻¹' s),
from set.ext $ assume a,
classical.by_cases
(assume : a ∈ frontier {a | p a},
have hac : a ∈ closure {a | p a}, from this.left,
have hai : a ∈ closure {a | ¬ p a},
from have a ∈ - interior {a | p a}, from this.right, by rwa [←closure_compl] at this,
by by_cases p a; simp [h, hp a this, hac, hai, iff_def] {contextual := tt})
(assume hf : a ∈ - frontier {a | p a},
classical.by_cases
(assume : p a,
have hc : a ∈ closure {a | p a}, from subset_closure this,
have hnc : a ∉ closure {a | ¬ p a},
by show a ∉ closure (- {a | p a}); rw [closure_compl]; simpa [frontier, hc] using hf,
by simp [this, hc, hnc])
(assume : ¬ p a,
have hc : a ∈ closure {a | ¬ p a}, from subset_closure this,
have hnc : a ∉ closure {a | p a},
begin
have hc : a ∈ closure (- {a | p a}), from hc,
simp [closure_compl] at hc,
simpa [frontier, hc] using hf
end,
by simp [this, hc, hnc])),
by rw [this]; exact is_closed_union
(is_closed_inter is_closed_closure $ continuous_iff_is_closed.mp hf s hs)
(is_closed_inter is_closed_closure $ continuous_iff_is_closed.mp hg s hs)
/- Continuity and partial functions -/
/-- Continuity of a partial function -/
def pcontinuous (f : α →. β) := ∀ s, is_open s → is_open (f.preimage s)
lemma open_dom_of_pcontinuous {f : α →. β} (h : pcontinuous f) : is_open f.dom :=
by rw [←pfun.preimage_univ]; exact h _ is_open_univ
lemma pcontinuous_iff' {f : α →. β} :
pcontinuous f ↔ ∀ {x y} (h : y ∈ f x), ptendsto' f (𝓝 x) (𝓝 y) :=
begin
split,
{ intros h x y h',
simp only [ptendsto'_def, mem_nhds_sets_iff],
rintros s ⟨t, tsubs, opent, yt⟩,
exact ⟨f.preimage t, pfun.preimage_mono _ tsubs, h _ opent, ⟨y, yt, h'⟩⟩
},
intros hf s os,
rw is_open_iff_nhds,
rintros x ⟨y, ys, fxy⟩ t,
rw [mem_principal_sets],
assume h : f.preimage s ⊆ t,
change t ∈ 𝓝 x,
apply mem_sets_of_superset _ h,
have h' : ∀ s ∈ 𝓝 y, f.preimage s ∈ 𝓝 x,
{ intros s hs,
have : ptendsto' f (𝓝 x) (𝓝 y) := hf fxy,
rw ptendsto'_def at this,
exact this s hs },
show f.preimage s ∈ 𝓝 x,
apply h', rw mem_nhds_sets_iff, exact ⟨s, set.subset.refl _, os, ys⟩
end
lemma image_closure_subset_closure_image {f : α → β} {s : set α} (h : continuous f) :
f '' closure s ⊆ closure (f '' s) :=
have ∀ (a : α), 𝓝 a ⊓ principal s ≠ ⊥ → 𝓝 (f a) ⊓ principal (f '' s) ≠ ⊥,
from assume a ha,
have h₁ : ¬ map f (𝓝 a ⊓ principal s) = ⊥,
by rwa[map_eq_bot_iff],
have h₂ : map f (𝓝 a ⊓ principal s) ≤ 𝓝 (f a) ⊓ principal (f '' s),
from le_inf
(le_trans (map_mono inf_le_left) $ by rw [continuous_iff_continuous_at] at h; exact h a)
(le_trans (map_mono inf_le_right) $ by simp; exact subset.refl _),
ne_bot_of_le_ne_bot h₁ h₂,
by simp [image_subset_iff, closure_eq_nhds]; assumption
lemma mem_closure {s : set α} {t : set β} {f : α → β} {a : α}
(hf : continuous f) (ha : a ∈ closure s) (ht : ∀a∈s, f a ∈ t) : f a ∈ closure t :=
subset.trans (image_closure_subset_closure_image hf) (closure_mono $ image_subset_iff.2 ht) $
(mem_image_of_mem f ha)
end continuous
|
986ecf299df86f311a47d00a2b6123dfdd90b5e0 | 05b503addd423dd68145d68b8cde5cd595d74365 | /src/linear_algebra/multilinear.lean | decbd85148de6d2c4b61d2a7b0a1a33162ae6fa2 | [
"Apache-2.0"
] | permissive | aestriplex/mathlib | 77513ff2b176d74a3bec114f33b519069788811d | e2fa8b2b1b732d7c25119229e3cdfba8370cb00f | refs/heads/master | 1,621,969,960,692 | 1,586,279,279,000 | 1,586,279,279,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 32,998 | lean | /-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import linear_algebra.basic tactic.omega data.fintype.card
/-!
# Multilinear maps
We define multilinear maps as maps from `Π(i : ι), M₁ i` to `M₂` which are linear in each
coordinate. Here, `M₁ i` and `M₂` are modules over a ring `R`, and `ι` is an arbitrary type
(although some statements will require it to be a fintype). This space, denoted by
`multilinear_map R M₁ M₂`, inherits a module structure by pointwise addition and multiplication.
## Main definitions
* `multilinear_map R M₁ M₂` is the space of multilinear maps from `Π(i : ι), M₁ i` to `M₂`.
* `f.map_smul` is the multiplicativity of the multilinear map `f` along each coordinate.
* `f.map_add` is the additivity of the multilinear map `f` along each coordinate.
* `f.map_smul_univ` expresses the multiplicativity of `f` over all coordinates at the same time,
writing `f (λi, c i • m i)` as `univ.prod c • f m`.
* `f.map_add_univ` expresses the additivity of `f` over all coordinates at the same time, writing
`f (m + m')` as the sum over all subsets `s` of `ι` of `f (s.piecewise m m')`.
* `f.map_sum` expresses `f (Σ_{j₁} g₁ j₁, ..., Σ_{jₙ} gₙ jₙ)` as the sum of
`f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all possible functions.
We also register isomorphisms corresponding to currying or uncurrying variables, transforming a
multilinear function `f` on `n+1` variables into a linear function taking values in multilinear
functions in `n` variables, and into a multilinear function in `n` variables taking values in linear
functions. These operations are called `f.curry_left` and `f.curry_right` respectively
(with inverses `f.uncurry_left` and `f.uncurry_right`). These operations induce linear equivalences
between spaces of multilinear functions in `n+1` variables and spaces of linear functions into
multilinear functions in `n` variables (resp. multilinear functions in `n` variables taking values
in linear functions), called respectively `multilinear_curry_left_equiv` and
`multilinear_curry_right_equiv`.
## Implementation notes
Expressing that a map is linear along the `i`-th coordinate when all other coordinates are fixed
can be done in two (equivalent) different ways:
* fixing a vector `m : Π(j : ι - i), M₁ j.val`, and then choosing separately the `i`-th coordinate
* fixing a vector `m : Πj, M₁ j`, and then modifying its `i`-th coordinate
The second way is more artificial as the value of `m` at `i` is not relevant, but it has the
advantage of avoiding subtype inclusion issues. This is the definition we use, based on
`function.update` that allows to change the value of `m` at `i`.
-/
open function fin set
universes u v v' v₁ v₂ v₃ w u'
variables {R : Type u} {ι : Type u'} {n : ℕ}
{M : fin n.succ → Type v} {M₁ : ι → Type v₁} {M₂ : Type v₂} {M₃ : Type v₃} {M' : Type v'}
[decidable_eq ι]
/-- Multilinear maps over the ring `R`, from `Πi, M₁ i` to `M₂` where `M₁ i` and `M₂` are modules
over `R`. -/
structure multilinear_map (R : Type u) {ι : Type u'} (M₁ : ι → Type v) (M₂ : Type w)
[decidable_eq ι] [ring R] [∀i, add_comm_group (M₁ i)] [add_comm_group M₂] [∀i, module R (M₁ i)]
[module R M₂] :=
(to_fun : (Πi, M₁ i) → M₂)
(add : ∀(m : Πi, M₁ i) (i : ι) (x y : M₁ i),
to_fun (update m i (x + y)) = to_fun (update m i x) + to_fun (update m i y))
(smul : ∀(m : Πi, M₁ i) (i : ι) (c : R) (x : M₁ i),
to_fun (update m i (c • x)) = c • to_fun (update m i x))
namespace multilinear_map
section ring
variables [ring R]
[∀i, add_comm_group (M i)] [∀i, add_comm_group (M₁ i)] [add_comm_group M₂] [add_comm_group M₃]
[add_comm_group M']
[∀i, module R (M i)] [∀i, module R (M₁ i)] [module R M₂] [module R M₃] [module R M']
(f f' : multilinear_map R M₁ M₂)
instance : has_coe_to_fun (multilinear_map R M₁ M₂) := ⟨_, to_fun⟩
@[ext] theorem ext {f f' : multilinear_map R M₁ M₂} (H : ∀ x, f x = f' x) : f = f' :=
by cases f; cases f'; congr'; exact funext H
@[simp] lemma map_add (m : Πi, M₁ i) (i : ι) (x y : M₁ i) :
f (update m i (x + y)) = f (update m i x) + f (update m i y) :=
f.add m i x y
@[simp] lemma map_smul (m : Πi, M₁ i) (i : ι) (c : R) (x : M₁ i) :
f (update m i (c • x)) = c • f (update m i x) :=
f.smul m i c x
@[simp] lemma map_sub (m : Πi, M₁ i) (i : ι) (x y : M₁ i) :
f (update m i (x - y)) = f (update m i x) - f (update m i y) :=
by { simp only [map_add, add_left_inj, sub_eq_add_neg, (neg_one_smul R y).symm, map_smul], simp }
lemma map_coord_zero {m : Πi, M₁ i} (i : ι) (h : m i = 0) : f m = 0 :=
begin
have : (0 : R) • (0 : M₁ i) = 0, by simp,
rw [← update_eq_self i m, h, ← this, f.map_smul, zero_smul]
end
@[simp] lemma map_zero [nonempty ι] : f 0 = 0 :=
begin
obtain ⟨i, _⟩ : ∃i:ι, i ∈ set.univ := set.exists_mem_of_nonempty ι,
exact map_coord_zero f i rfl
end
instance : has_add (multilinear_map R M₁ M₂) :=
⟨λf f', ⟨λx, f x + f' x, λm i x y, by simp [add_left_comm], λm i c x, by simp [smul_add]⟩⟩
@[simp] lemma add_apply (m : Πi, M₁ i) : (f + f') m = f m + f' m := rfl
instance : has_neg (multilinear_map R M₁ M₂) :=
⟨λ f, ⟨λ m, - f m, λm i x y, by simp [add_comm], λm i c x, by simp⟩⟩
@[simp] lemma neg_apply (m : Πi, M₁ i) : (-f) m = - (f m) := rfl
instance : has_zero (multilinear_map R M₁ M₂) :=
⟨⟨λ _, 0, λm i x y, by simp, λm i c x, by simp⟩⟩
instance : inhabited (multilinear_map R M₁ M₂) := ⟨0⟩
@[simp] lemma zero_apply (m : Πi, M₁ i) : (0 : multilinear_map R M₁ M₂) m = 0 := rfl
instance : add_comm_group (multilinear_map R M₁ M₂) :=
by refine {zero := 0, add := (+), neg := has_neg.neg, ..};
intros; ext; simp [add_comm, add_left_comm]
@[simp] lemma sum_apply {α : Type*} [decidable_eq α] (f : α → multilinear_map R M₁ M₂)
(m : Πi, M₁ i) : ∀ {s : finset α}, (s.sum f) m = s.sum (λ a, f a m) :=
begin
apply finset.induction,
{ rw finset.sum_empty, simp },
{ assume a s has H, rw finset.sum_insert has, simp [H, has] }
end
/-- If `f` is a multilinear map, then `f.to_linear_map m i` is the linear map obtained by fixing all
coordinates but `i` equal to those of `m`, and varying the `i`-th coordinate. -/
def to_linear_map (m : Πi, M₁ i) (i : ι) : M₁ i →ₗ[R] M₂ :=
{ to_fun := λx, f (update m i x),
add := λx y, by simp,
smul := λc x, by simp }
/-- The cartesian product of two multilinear maps, as a multilinear map. -/
def prod (f : multilinear_map R M₁ M₂) (g : multilinear_map R M₁ M₃) :
multilinear_map R M₁ (M₂ × M₃) :=
{ to_fun := λ m, (f m, g m),
add := λ m i x y, by simp,
smul := λ m i c x, by simp }
/-- Given a multilinear map `f` on `n` variables (parameterized by `fin n`) and a subset `s` of `k`
of these variables, one gets a new multilinear map on `fin k` by varying these variables, and fixing
the other ones equal to a given value `z`. It is denoted by `f.restr s hk z`, where `hk` is a
proof that the cardinality of `s` is `k`. The implicit identification between `fin k` and `s` that
we use is the canonical (increasing) bijection. -/
noncomputable def restr {k n : ℕ} (f : multilinear_map R (λ i : fin n, M') M₂) (s : finset (fin n))
(hk : s.card = k) (z : M') :
multilinear_map R (λ i : fin k, M') M₂ :=
{ to_fun := λ v, f (λ j, if h : j ∈ s then v ((s.mono_equiv_of_fin hk).symm ⟨j, h⟩) else z),
add := λ v i x y,
by { erw [dite_comp_equiv_update, dite_comp_equiv_update, dite_comp_equiv_update], simp },
smul := λ v i c x, by { erw [dite_comp_equiv_update, dite_comp_equiv_update], simp } }
variable {R}
/-- In the specific case of multilinear maps on spaces indexed by `fin (n+1)`, where one can build
an element of `Π(i : fin (n+1)), M i` using `cons`, one can express directly the additivity of a
multilinear map along the first variable. -/
lemma cons_add (f : multilinear_map R M M₂) (m : Π(i : fin n), M i.succ) (x y : M 0) :
f (cons (x+y) m) = f (cons x m) + f (cons y m) :=
by rw [← update_cons_zero x m (x+y), f.map_add, update_cons_zero, update_cons_zero]
/-- In the specific case of multilinear maps on spaces indexed by `fin (n+1)`, where one can build
an element of `Π(i : fin (n+1)), M i` using `cons`, one can express directly the multiplicativity
of a multilinear map along the first variable. -/
lemma cons_smul (f : multilinear_map R M M₂) (m : Π(i : fin n), M i.succ) (c : R) (x : M 0) :
f (cons (c • x) m) = c • f (cons x m) :=
by rw [← update_cons_zero x m (c • x), f.map_smul, update_cons_zero]
/-- In the specific case of multilinear maps on spaces indexed by `fin (n+1)`, where one can build
an element of `Π(i : fin (n+1)), M i` using `snoc`, one can express directly the additivity of a
multilinear map along the first variable. -/
lemma snoc_add (f : multilinear_map R M M₂) (m : Π(i : fin n), M i.cast_succ) (x y : M (last n)) :
f (snoc m (x+y)) = f (snoc m x) + f (snoc m y) :=
by rw [← update_snoc_last x m (x+y), f.map_add, update_snoc_last, update_snoc_last]
/-- In the specific case of multilinear maps on spaces indexed by `fin (n+1)`, where one can build
an element of `Π(i : fin (n+1)), M i` using `cons`, one can express directly the multiplicativity
of a multilinear map along the first variable. -/
lemma snoc_smul (f : multilinear_map R M M₂)
(m : Π(i : fin n), M i.cast_succ) (c : R) (x : M (last n)) :
f (snoc m (c • x)) = c • f (snoc m x) :=
by rw [← update_snoc_last x m (c • x), f.map_smul, update_snoc_last]
/-- If `g` is multilinear and `f` is linear, then `g (f m₁, ..., f mₙ)` is again a multilinear
function, that we call `g.comp_linear_map f`. -/
def comp_linear_map (g : multilinear_map R (λ (i : ι), M₂) M₃) (f : M' →ₗ[R] M₂) :
multilinear_map R (λ (i : ι), M') M₃ :=
{ to_fun := λ m, g (f ∘ m),
add := λ m i x y, by simp [comp_update],
smul := λ m i c x, by simp [comp_update] }
/-- If one adds to a vector `m'` another vector `m`, but only for coordinates in a finset `t`, then
the image under a multilinear map `f` is the sum of `f (s.piecewise m m')` along all subsets `s` of
`t`. This is mainly an auxiliary statement to prove the result when `t = univ`, given in
`map_add_univ`, although it can be useful in its own right as it does not require the index set `ι`
to be finite.-/
lemma map_piecewise_add (m m' : Πi, M₁ i) (t : finset ι) :
f (t.piecewise (m + m') m') = t.powerset.sum (λs, f (s.piecewise m m')) :=
begin
revert m',
refine finset.induction_on t (by simp) _,
assume i t hit Hrec m',
have A : (insert i t).piecewise (m + m') m' = update (t.piecewise (m + m') m') i (m i + m' i) :=
t.piecewise_insert _ _ _,
have B : update (t.piecewise (m + m') m') i (m' i) = t.piecewise (m + m') m',
{ ext j,
by_cases h : j = i,
{ rw h, simp [hit] },
{ simp [h] } },
let m'' := update m' i (m i),
have C : update (t.piecewise (m + m') m') i (m i) = t.piecewise (m + m'') m'',
{ ext j,
by_cases h : j = i,
{ rw h, simp [m'', hit] },
{ by_cases h' : j ∈ t; simp [h, hit, m'', h'] } },
rw [A, f.map_add, B, C, finset.sum_powerset_insert hit, Hrec, Hrec, add_comm],
congr' 1,
apply finset.sum_congr rfl (λs hs, _),
have : (insert i s).piecewise m m' = s.piecewise m m'',
{ ext j,
by_cases h : j = i,
{ rw h, simp [m'', finset.not_mem_of_mem_powerset_of_not_mem hs hit] },
{ by_cases h' : j ∈ s; simp [h, m'', h'] } },
rw this
end
/-- Additivity of a multilinear map along all coordinates at the same time,
writing `f (m + m')` as the sum of `f (s.piecewise m m')` over all sets `s`. -/
lemma map_add_univ [fintype ι] (m m' : Πi, M₁ i) :
f (m + m') = (finset.univ : finset (finset ι)).sum (λs, f (s.piecewise m m')) :=
by simpa using f.map_piecewise_add m m' finset.univ
section apply_sum
variables {α : ι → Type*} [fintype ι] (g : Π i, α i → M₁ i) (A : Π i, finset (α i))
open_locale classical
open fintype finset
/-- If `f` is multilinear, then `f (Σ_{j₁ ∈ A₁} g₁ j₁, ..., Σ_{jₙ ∈ Aₙ} gₙ jₙ)` is the sum of
`f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions with `r 1 ∈ A₁`, ...,
`r n ∈ Aₙ`. This follows from multilinearity by expanding successively with respect to each
coordinate. Here, we give an auxiliary statement tailored for an inductive proof. Use instead
`map_sum_finset`. -/
lemma map_sum_finset_aux {n : ℕ} (h : finset.univ.sum (λ i, (A i).card) = n) :
f (λ i, (A i).sum (g i)) = (pi_finset A).sum (λ r, f (λ i, g i (r i))) :=
begin
unfreezeI,
induction n using nat.strong_induction_on with n IH generalizing A,
-- If one of the sets is empty, then all the sums are zero
by_cases Ai_empty : ∃ i, A i = ∅,
{ rcases Ai_empty with ⟨i, hi⟩,
have : (A i).sum (λ j, g i j) = 0, by convert sum_empty,
rw f.map_coord_zero i this,
have : pi_finset A = ∅,
{ apply finset.eq_empty_of_forall_not_mem (λ r hr, _),
have : r i ∈ A i := mem_pi_finset.mp hr i,
rwa hi at this },
convert sum_empty.symm },
push_neg at Ai_empty,
-- Otherwise, if all sets are at most singletons, then they are exactly singletons and the result
-- is again straightforward
by_cases Ai_singleton : ∀ i, (A i).card ≤ 1,
{ have Ai_card : ∀ i, (A i).card = 1,
{ assume i,
have : finset.card (A i) ≠ 0, by simp [finset.card_eq_zero, Ai_empty i],
have : finset.card (A i) ≤ 1 := Ai_singleton i,
omega },
have : ∀ (r : Π i, α i), r ∈ pi_finset A → f (λ i, g i (r i)) = f (λ i, (A i).sum (λ j, g i j)),
{ assume r hr,
unfold_coes,
congr,
ext i,
have : ∀ j ∈ A i, g i j = g i (r i),
{ assume j hj,
congr,
apply finset.card_le_one_iff.1 (Ai_singleton i) hj,
exact mem_pi_finset.mp hr i },
simp only [finset.sum_congr rfl this, finset.mem_univ, finset.sum_const, Ai_card i,
add_monoid.one_smul] },
simp only [sum_congr rfl this, Ai_card, card_pi_finset, prod_const_one, add_monoid.one_smul,
sum_const] },
-- Remains the interesting case where one of the `A i`, say `A i₀`, has cardinality at least 2.
-- We will split into two parts `B i₀` and `C i₀` of smaller cardinality, let `B i = C i = A i`
-- for `i ≠ i₀`, apply the inductive assumption to `B` and `C`, and add up the corresponding
-- parts to get the sum for `A`.
push_neg at Ai_singleton,
obtain ⟨i₀, hi₀⟩ : ∃ i, 1 < (A i).card := Ai_singleton,
obtain ⟨j₁, j₂, hj₁, hj₂, j₁_ne_j₂⟩ : ∃ j₁ j₂, (j₁ ∈ A i₀) ∧ (j₂ ∈ A i₀) ∧ j₁ ≠ j₂ :=
finset.one_lt_card_iff.1 hi₀,
let B := function.update A i₀ (A i₀ \ finset.singleton j₂),
let C := function.update A i₀ (finset.singleton j₂),
have B_subset_A : ∀ i, B i ⊆ A i,
{ assume i,
by_cases hi : i = i₀,
{ rw hi, simp only [B, sdiff_subset, update_same]},
{ simp only [hi, B, update_noteq, ne.def, not_false_iff, finset.subset.refl] } },
have C_subset_A : ∀ i, C i ⊆ A i,
{ assume i,
by_cases hi : i = i₀,
{ rw hi, simp only [C, hj₂, finset.singleton_subset_iff, update_same] },
{ simp only [hi, C, update_noteq, ne.def, not_false_iff, finset.subset.refl] } },
-- split the sum at `i₀` as the sum over `B i₀` plus the sum over `C i₀`, to use additivity.
have A_eq_BC : (λ i, (A i).sum (g i)) =
function.update (λ i, (A i).sum (g i)) i₀ ((B i₀).sum (g i₀) + (C i₀).sum (g i₀)),
{ ext i,
by_cases hi : i = i₀,
{ rw [hi],
simp only [function.update_same],
have : A i₀ = B i₀ ∪ C i₀,
{ simp only [B, C, function.update_same, finset.insert_empty_eq_singleton,
finset.sdiff_union_self_eq_union],
symmetry,
simp only [hj₂, finset.singleton_subset_iff, union_eq_left_iff_subset] },
rw this,
apply finset.sum_union,
apply finset.disjoint_right.2 (λ j hj, _),
have : j = j₂, by { dsimp [C] at hj, simpa using hj },
rw this,
dsimp [B],
simp only [mem_sdiff, eq_self_iff_true, not_true, not_false_iff, finset.mem_singleton,
update_same, and_false] },
{ simp [hi] } },
have Beq : function.update (λ i, (A i).sum (g i)) i₀ ((B i₀).sum (g i₀)) =
(λ i, finset.sum (B i) (g i)),
{ ext i,
by_cases hi : i = i₀,
{ rw hi, simp only [update_same] },
{ simp only [hi, B, update_noteq, ne.def, not_false_iff] } },
have Ceq : function.update (λ i, (A i).sum (g i)) i₀ ((C i₀).sum (g i₀)) =
(λ i, finset.sum (C i) (g i)),
{ ext i,
by_cases hi : i = i₀,
{ rw hi, simp only [update_same] },
{ simp only [hi, C, update_noteq, ne.def, not_false_iff] } },
-- Express the inductive assumption for `B`
have Brec : f (λ i, finset.sum (B i) (g i)) = (pi_finset B).sum (λ r, f (λ i, g i (r i))),
{ have : finset.univ.sum (λ i, finset.card (B i)) < finset.univ.sum (λ i, finset.card (A i)),
{ refine finset.sum_lt_sum (λ i hi, finset.card_le_of_subset (B_subset_A i))
⟨i₀, finset.mem_univ _, _⟩,
have : finset.singleton j₂ ⊆ A i₀, by simp [hj₂],
simp only [B, finset.card_sdiff this, function.update_same, finset.insert_empty_eq_singleton,
finset.card_singleton],
exact nat.pred_lt (ne_of_gt (lt_trans zero_lt_one hi₀)) },
rw h at this,
exact IH _ this B rfl },
-- Express the inductive assumption for `C`
have Crec : f (λ i, finset.sum (C i) (g i)) = (pi_finset C).sum (λ r, f (λ i, g i (r i))),
{ have : finset.univ.sum (λ i, finset.card (C i)) < finset.univ.sum (λ i, finset.card (A i)) :=
finset.sum_lt_sum (λ i hi, finset.card_le_of_subset (C_subset_A i))
⟨i₀, finset.mem_univ _, by simp [C, hi₀]⟩,
rw h at this,
exact IH _ this C rfl },
have D : disjoint (pi_finset B) (pi_finset C),
{ have : disjoint (B i₀) (C i₀), by simp [B, C],
exact pi_finset_disjoint_of_disjoint B C this },
have pi_BC : pi_finset A = pi_finset B ∪ pi_finset C,
{ apply finset.subset.antisymm,
{ assume r hr,
by_cases hri₀ : r i₀ = j₂,
{ apply finset.mem_union_right,
apply mem_pi_finset.2 (λ i, _),
by_cases hi : i = i₀,
{ have : r i₀ ∈ C i₀, by simp [C, hri₀],
convert this },
{ simp [C, hi, mem_pi_finset.1 hr i] } },
{ apply finset.mem_union_left,
apply mem_pi_finset.2 (λ i, _),
by_cases hi : i = i₀,
{ have : r i₀ ∈ B i₀,
by simp [B, hri₀, mem_pi_finset.1 hr i₀],
convert this },
{ simp [B, hi, mem_pi_finset.1 hr i] } } },
{ exact finset.union_subset (pi_finset_subset _ _ (λ i, B_subset_A i))
(pi_finset_subset _ _ (λ i, C_subset_A i)) } },
rw A_eq_BC,
simp only [multilinear_map.map_add, Beq, Ceq, Brec, Crec, pi_BC],
rw ← finset.sum_union D,
end
/-- If `f` is multilinear, then `f (Σ_{j₁ ∈ A₁} g₁ j₁, ..., Σ_{jₙ ∈ Aₙ} gₙ jₙ)` is the sum of
`f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions with `r 1 ∈ A₁`, ...,
`r n ∈ Aₙ`. This follows from multilinearity by expanding successively with respect to each
coordinate. -/
lemma map_sum_finset :
f (λ i, (A i).sum (g i)) = (pi_finset A).sum (λ r, f (λ i, g i (r i))) :=
f.map_sum_finset_aux _ _ rfl
/-- If `f` is multilinear, then `f (Σ_{j₁} g₁ j₁, ..., Σ_{jₙ} gₙ jₙ)` is the sum of
`f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions `r`. This follows from
multilinearity by expanding successively with respect to each coordinate. -/
lemma map_sum [∀ i, fintype (α i)] :
f (λ i, finset.univ.sum (g i)) = finset.univ.sum (λ (r : Π i, α i), f (λ i, g i (r i))) :=
f.map_sum_finset g (λ i, finset.univ)
end apply_sum
end ring
section comm_ring
variables [comm_ring R] [∀i, add_comm_group (M₁ i)] [∀i, add_comm_group (M i)] [add_comm_group M₂]
[∀i, module R (M i)] [∀i, module R (M₁ i)] [module R M₂]
(f f' : multilinear_map R M₁ M₂)
/-- If one multiplies by `c i` the coordinates in a finset `s`, then the image under a multilinear
map is multiplied by `s.prod c`. This is mainly an auxiliary statement to prove the result when
`s = univ`, given in `map_smul_univ`, although it can be useful in its own right as it does not
require the index set `ι` to be finite. -/
lemma map_piecewise_smul (c : ι → R) (m : Πi, M₁ i) (s : finset ι) :
f (s.piecewise (λi, c i • m i) m) = s.prod c • f m :=
begin
refine s.induction_on (by simp) _,
assume j s j_not_mem_s Hrec,
have A : function.update (s.piecewise (λi, c i • m i) m) j (m j) =
s.piecewise (λi, c i • m i) m,
{ ext i,
by_cases h : i = j,
{ rw h, simp [j_not_mem_s] },
{ simp [h] } },
rw [s.piecewise_insert, f.map_smul, A, Hrec],
simp [j_not_mem_s, mul_smul]
end
/-- Multiplicativity of a multilinear map along all coordinates at the same time,
writing `f (λi, c i • m i)` as `univ.prod c • f m`. -/
lemma map_smul_univ [fintype ι] (c : ι → R) (m : Πi, M₁ i) :
f (λi, c i • m i) = finset.univ.prod c • f m :=
by simpa using map_piecewise_smul f c m finset.univ
instance : has_scalar R (multilinear_map R M₁ M₂) := ⟨λ c f,
⟨λ m, c • f m, λm i x y, by simp [smul_add], λl i x d, by simp [smul_smul, mul_comm]⟩⟩
@[simp] lemma smul_apply (c : R) (m : Πi, M₁ i) : (c • f) m = c • f m := rfl
/-- The space of multilinear maps is a module over `R`, for the pointwise addition and scalar
multiplication. -/
instance : module R (multilinear_map R M₁ M₂) :=
module.of_core $ by refine { smul := (•), ..};
intros; ext; simp [smul_add, add_smul, smul_smul]
variables (R ι)
/-- The canonical multilinear map on `R^ι` when `ι` is finite, associating to `m` the product of
all the `m i` (multiplied by a fixed reference element `z` in the target module) -/
protected def mk_pi_ring [fintype ι] (z : M₂) : multilinear_map R (λ(i : ι), R) M₂ :=
{ to_fun := λm, finset.univ.prod m • z,
add := λ m i x y, by simp [finset.prod_update_of_mem, add_mul, add_smul],
smul := λ m i c x, by { rw [smul_eq_mul], simp [finset.prod_update_of_mem, smul_smul, mul_assoc] } }
variables {R ι}
@[simp] lemma mk_pi_ring_apply [fintype ι] (z : M₂) (m : ι → R) :
(multilinear_map.mk_pi_ring R ι z : (ι → R) → M₂) m = finset.univ.prod m • z := rfl
lemma mk_pi_ring_apply_one_eq_self [fintype ι] (f : multilinear_map R (λ(i : ι), R) M₂) :
multilinear_map.mk_pi_ring R ι (f (λi, 1)) = f :=
begin
ext m,
have : m = (λi, m i • 1), by { ext j, simp },
conv_rhs { rw [this, f.map_smul_univ] },
refl
end
variables (R ι M₂)
/-- When `ι` is finite, multilinear maps on `R^ι` with values in `M₂` are in bijection with `M₂`,
as such a multilinear map is completely determined by its value on the constant vector made of ones.
We register this bijection as a linear equivalence in `multilinear_map.pi_ring_equiv`. -/
protected def pi_ring_equiv [fintype ι] : M₂ ≃ₗ[R] (multilinear_map R (λ(i : ι), R) M₂) :=
{ to_fun := λ z, multilinear_map.mk_pi_ring R ι z,
inv_fun := λ f, f (λi, 1),
add := λ z z', by { ext m, simp [smul_add] },
smul := λ c z, by { ext m, simp [smul_smul, mul_comm] },
left_inv := λ z, by simp,
right_inv := λ f, f.mk_pi_ring_apply_one_eq_self }
end comm_ring
end multilinear_map
namespace linear_map
variables [ring R] [∀i, add_comm_group (M₁ i)] [add_comm_group M₂] [add_comm_group M₃]
[∀i, module R (M₁ i)] [module R M₂] [module R M₃]
/-- Composing a multilinear map with a linear map gives again a multilinear map. -/
def comp_multilinear_map (g : M₂ →ₗ[R] M₃) (f : multilinear_map R M₁ M₂) : multilinear_map R M₁ M₃ :=
{ to_fun := λ m, g (f m),
add := λ m i x y, by simp,
smul := λ m i c x, by simp }
end linear_map
section currying
/-!
### Currying
We associate to a multilinear map in `n+1` variables (i.e., based on `fin n.succ`) two
curried functions, named `f.curry_left` (which is a linear map on `E 0` taking values
in multilinear maps in `n` variables) and `f.curry_right` (wich is a multilinear map in `n`
variables taking values in linear maps on `E 0`). In both constructions, the variable that is
singled out is `0`, to take advantage of the operations `cons` and `tail` on `fin n`.
The inverse operations are called `uncurry_left` and `uncurry_right`.
We also register linear equiv versions of these correspondences, in
`multilinear_curry_left_equiv` and `multilinear_curry_right_equiv`.
-/
open multilinear_map
variables {R M M₂}
[comm_ring R] [∀i, add_comm_group (M i)] [add_comm_group M'] [add_comm_group M₂]
[∀i, module R (M i)] [module R M'] [module R M₂]
/-! #### Left currying -/
/-- Given a linear map `f` from `M 0` to multilinear maps on `n` variables,
construct the corresponding multilinear map on `n+1` variables obtained by concatenating
the variables, given by `m ↦ f (m 0) (tail m)`-/
def linear_map.uncurry_left
(f : M 0 →ₗ[R] (multilinear_map R (λ(i : fin n), M i.succ) M₂)) :
multilinear_map R M M₂ :=
{ to_fun := λm, f (m 0) (tail m),
add := λm i x y, begin
by_cases h : i = 0,
{ revert x y,
rw h,
assume x y,
rw [update_same, update_same, update_same, f.map_add, add_apply,
tail_update_zero, tail_update_zero, tail_update_zero] },
{ rw [update_noteq (ne.symm h), update_noteq (ne.symm h), update_noteq (ne.symm h)],
revert x y,
rw ← succ_pred i h,
assume x y,
rw [tail_update_succ, map_add, tail_update_succ, tail_update_succ] }
end,
smul := λm i c x, begin
by_cases h : i = 0,
{ revert x,
rw h,
assume x,
rw [update_same, update_same, tail_update_zero, tail_update_zero,
← smul_apply, f.map_smul] },
{ rw [update_noteq (ne.symm h), update_noteq (ne.symm h)],
revert x,
rw ← succ_pred i h,
assume x,
rw [tail_update_succ, tail_update_succ, map_smul] }
end }
@[simp] lemma linear_map.uncurry_left_apply
(f : M 0 →ₗ[R] (multilinear_map R (λ(i : fin n), M i.succ) M₂)) (m : Πi, M i) :
f.uncurry_left m = f (m 0) (tail m) := rfl
/-- Given a multilinear map `f` in `n+1` variables, split the first variable to obtain
a linear map into multilinear maps in `n` variables, given by `x ↦ (m ↦ f (cons x m))`. -/
def multilinear_map.curry_left
(f : multilinear_map R M M₂) :
M 0 →ₗ[R] (multilinear_map R (λ(i : fin n), M i.succ) M₂) :=
{ to_fun := λx,
{ to_fun := λm, f (cons x m),
add := λm i y y', by simp,
smul := λm i y c, by simp },
add := λx y, by { ext m, exact cons_add f m x y },
smul := λc x, by { ext m, exact cons_smul f m c x } }
@[simp] lemma multilinear_map.curry_left_apply
(f : multilinear_map R M M₂) (x : M 0) (m : Π(i : fin n), M i.succ) :
f.curry_left x m = f (cons x m) := rfl
@[simp] lemma linear_map.curry_uncurry_left
(f : M 0 →ₗ[R] (multilinear_map R (λ(i : fin n), M i.succ) M₂)) :
f.uncurry_left.curry_left = f :=
begin
ext m x,
simp only [tail_cons, linear_map.uncurry_left_apply, multilinear_map.curry_left_apply],
rw cons_zero
end
@[simp] lemma multilinear_map.uncurry_curry_left
(f : multilinear_map R M M₂) :
f.curry_left.uncurry_left = f :=
by { ext m, simp }
variables (R M M₂)
/-- The space of multilinear maps on `Π(i : fin (n+1)), M i` is canonically isomorphic to
the space of linear maps from `M 0` to the space of multilinear maps on
`Π(i : fin n), M i.succ `, by separating the first variable. We register this isomorphism as a
linear isomorphism in `multilinear_curry_left_equiv R M M₂`.
The direct and inverse maps are given by `f.uncurry_left` and `f.curry_left`. Use these
unless you need the full framework of linear equivs. -/
def multilinear_curry_left_equiv :
(M 0 →ₗ[R] (multilinear_map R (λ(i : fin n), M i.succ) M₂)) ≃ₗ[R] (multilinear_map R M M₂) :=
{ to_fun := linear_map.uncurry_left,
add := λf₁ f₂, by { ext m, refl },
smul := λc f, by { ext m, refl },
inv_fun := multilinear_map.curry_left,
left_inv := linear_map.curry_uncurry_left,
right_inv := multilinear_map.uncurry_curry_left }
variables {R M M₂}
/-! #### Right currying -/
/-- Given a multilinear map `f` in `n` variables to the space of linear maps from `M (last n)` to
`M₂`, construct the corresponding multilinear map on `n+1` variables obtained by concatenating
the variables, given by `m ↦ f (init m) (m (last n))`-/
def multilinear_map.uncurry_right
(f : (multilinear_map R (λ(i : fin n), M i.cast_succ) (M (last n) →ₗ[R] M₂))) :
multilinear_map R M M₂ :=
{ to_fun := λm, f (init m) (m (last n)),
add := λm i x y, begin
by_cases h : i.val < n,
{ have : last n ≠ i := ne.symm (ne_of_lt h),
rw [update_noteq this, update_noteq this, update_noteq this],
revert x y,
rw [(cast_succ_cast_lt i h).symm],
assume x y,
rw [init_update_cast_succ, map_add, init_update_cast_succ, init_update_cast_succ,
linear_map.add_apply] },
{ revert x y,
rw eq_last_of_not_lt h,
assume x y,
rw [init_update_last, init_update_last, init_update_last,
update_same, update_same, update_same, linear_map.map_add] }
end,
smul := λm i c x, begin
by_cases h : i.val < n,
{ have : last n ≠ i := ne.symm (ne_of_lt h),
rw [update_noteq this, update_noteq this],
revert x,
rw [(cast_succ_cast_lt i h).symm],
assume x,
rw [init_update_cast_succ, init_update_cast_succ, map_smul, linear_map.smul_apply] },
{ revert x,
rw eq_last_of_not_lt h,
assume x,
rw [update_same, update_same, init_update_last, init_update_last,
linear_map.map_smul] }
end }
@[simp] lemma multilinear_map.uncurry_right_apply
(f : (multilinear_map R (λ(i : fin n), M i.cast_succ) ((M (last n)) →ₗ[R] M₂))) (m : Πi, M i) :
f.uncurry_right m = f (init m) (m (last n)) := rfl
/-- Given a multilinear map `f` in `n+1` variables, split the last variable to obtain
a multilinear map in `n` variables taking values in linear maps from `M (last n)` to `M₂`, given by
`m ↦ (x ↦ f (snoc m x))`. -/
def multilinear_map.curry_right (f : multilinear_map R M M₂) :
multilinear_map R (λ(i : fin n), M (fin.cast_succ i)) ((M (last n)) →ₗ[R] M₂) :=
{ to_fun := λm,
{ to_fun := λx, f (snoc m x),
add := λx y, by rw f.snoc_add,
smul := λc x, by rw f.snoc_smul },
add := λm i x y, begin
ext z,
change f (snoc (update m i (x + y)) z)
= f (snoc (update m i x) z) + f (snoc (update m i y) z),
rw [snoc_update, snoc_update, snoc_update, f.map_add]
end,
smul := λm i c x, begin
ext z,
change f (snoc (update m i (c • x)) z) = c • f (snoc (update m i x) z),
rw [snoc_update, snoc_update, f.map_smul]
end }
@[simp] lemma multilinear_map.curry_right_apply
(f : multilinear_map R M M₂) (m : Π(i : fin n), M i.cast_succ) (x : M (last n)) :
f.curry_right m x = f (snoc m x) := rfl
@[simp] lemma multilinear_map.curry_uncurry_right
(f : (multilinear_map R (λ(i : fin n), M i.cast_succ) ((M (last n)) →ₗ[R] M₂))) :
f.uncurry_right.curry_right = f :=
begin
ext m x,
simp only [snoc_last, multilinear_map.curry_right_apply, multilinear_map.uncurry_right_apply],
rw init_snoc
end
@[simp] lemma multilinear_map.uncurry_curry_right
(f : multilinear_map R M M₂) : f.curry_right.uncurry_right = f :=
by { ext m, simp }
variables (R M M₂)
/-- The space of multilinear maps on `Π(i : fin (n+1)), M i` is canonically isomorphic to
the space of linear maps from the space of multilinear maps on `Π(i : fin n), M i.cast_succ` to the
space of linear maps on `M (last n)`, by separating the last variable. We register this isomorphism
as a linear isomorphism in `multilinear_curry_right_equiv R M M₂`.
The direct and inverse maps are given by `f.uncurry_right` and `f.curry_right`. Use these
unless you need the full framework of linear equivs. -/
def multilinear_curry_right_equiv :
(multilinear_map R (λ(i : fin n), M i.cast_succ) ((M (last n)) →ₗ[R] M₂))
≃ₗ[R] (multilinear_map R M M₂) :=
{ to_fun := multilinear_map.uncurry_right,
add := λf₁ f₂, by { ext m, refl },
smul := λc f, by { ext m, rw [smul_apply], refl },
inv_fun := multilinear_map.curry_right,
left_inv := multilinear_map.curry_uncurry_right,
right_inv := multilinear_map.uncurry_curry_right }
end currying
|
3f7bfdf8a8abd0a660e5fbeb707d45791431b36e | 94e33a31faa76775069b071adea97e86e218a8ee | /src/topology/algebra/module/basic.lean | f3289be68a0ebdad5ee3adb5bfd01f09ba62c739 | [
"Apache-2.0"
] | permissive | urkud/mathlib | eab80095e1b9f1513bfb7f25b4fa82fa4fd02989 | 6379d39e6b5b279df9715f8011369a301b634e41 | refs/heads/master | 1,658,425,342,662 | 1,658,078,703,000 | 1,658,078,703,000 | 186,910,338 | 0 | 0 | Apache-2.0 | 1,568,512,083,000 | 1,557,958,709,000 | Lean | UTF-8 | Lean | false | false | 88,585 | lean | /-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jan-David Salchow, Sébastien Gouëzel, Jean Lo, Yury Kudryashov, Frédéric Dupuis,
Heather Macbeth
-/
import topology.algebra.ring
import topology.algebra.mul_action
import topology.algebra.uniform_group
import topology.uniform_space.uniform_embedding
import algebra.algebra.basic
import linear_algebra.projection
import linear_algebra.pi
import linear_algebra.determinant
/-!
# Theory of topological modules and continuous linear maps.
We use the class `has_continuous_smul` for topological (semi) modules and topological vector spaces.
In this file we define continuous (semi-)linear maps, as semilinear maps between topological
modules which are continuous. The set of continuous semilinear maps between the topological
`R₁`-module `M` and `R₂`-module `M₂` with respect to the `ring_hom` `σ` is denoted by `M →SL[σ] M₂`.
Plain linear maps are denoted by `M →L[R] M₂` and star-linear maps by `M →L⋆[R] M₂`.
The corresponding notation for equivalences is `M ≃SL[σ] M₂`, `M ≃L[R] M₂` and `M ≃L⋆[R] M₂`.
-/
open filter
open_locale topological_space big_operators filter
universes u v w u'
section
variables {R : Type*} {M : Type*}
[ring R] [topological_space R]
[topological_space M] [add_comm_group M]
[module R M]
lemma has_continuous_smul.of_nhds_zero [topological_ring R] [topological_add_group M]
(hmul : tendsto (λ p : R × M, p.1 • p.2) (𝓝 0 ×ᶠ (𝓝 0)) (𝓝 0))
(hmulleft : ∀ m : M, tendsto (λ a : R, a • m) (𝓝 0) (𝓝 0))
(hmulright : ∀ a : R, tendsto (λ m : M, a • m) (𝓝 0) (𝓝 0)) : has_continuous_smul R M :=
⟨begin
rw continuous_iff_continuous_at,
rintros ⟨a₀, m₀⟩,
have key : ∀ p : R × M,
p.1 • p.2 = a₀ • m₀ + ((p.1 - a₀) • m₀ + a₀ • (p.2 - m₀) + (p.1 - a₀) • (p.2 - m₀)),
{ rintro ⟨a, m⟩,
simp [sub_smul, smul_sub],
abel },
rw funext key, clear key,
refine tendsto_const_nhds.add (tendsto.add (tendsto.add _ _) _),
{ rw [sub_self, zero_smul],
apply (hmulleft m₀).comp,
rw [show (λ p : R × M, p.1 - a₀) = (λ a, a - a₀) ∘ prod.fst, by {ext, refl }, nhds_prod_eq],
have : tendsto (λ a, a - a₀) (𝓝 a₀) (𝓝 0),
{ rw ← sub_self a₀,
exact tendsto_id.sub tendsto_const_nhds },
exact this.comp tendsto_fst },
{ rw [sub_self, smul_zero],
apply (hmulright a₀).comp,
rw [show (λ p : R × M, p.2 - m₀) = (λ m, m - m₀) ∘ prod.snd, by {ext, refl }, nhds_prod_eq],
have : tendsto (λ m, m - m₀) (𝓝 m₀) (𝓝 0),
{ rw ← sub_self m₀,
exact tendsto_id.sub tendsto_const_nhds },
exact this.comp tendsto_snd },
{ rw [sub_self, zero_smul, nhds_prod_eq,
show (λ p : R × M, (p.fst - a₀) • (p.snd - m₀)) =
(λ p : R × M, p.1 • p.2) ∘ (prod.map (λ a, a - a₀) (λ m, m - m₀)), by { ext, refl }],
apply hmul.comp (tendsto.prod_map _ _);
{ rw ← sub_self ,
exact tendsto_id.sub tendsto_const_nhds } },
end⟩
end
section
variables {R : Type*} {M : Type*}
[ring R] [topological_space R]
[topological_space M] [add_comm_group M] [has_continuous_add M]
[module R M] [has_continuous_smul R M]
/-- If `M` is a topological module over `R` and `0` is a limit of invertible elements of `R`, then
`⊤` is the only submodule of `M` with a nonempty interior.
This is the case, e.g., if `R` is a nondiscrete normed field. -/
lemma submodule.eq_top_of_nonempty_interior'
[ne_bot (𝓝[{x : R | is_unit x}] 0)]
(s : submodule R M) (hs : (interior (s:set M)).nonempty) :
s = ⊤ :=
begin
rcases hs with ⟨y, hy⟩,
refine (submodule.eq_top_iff'.2 $ λ x, _),
rw [mem_interior_iff_mem_nhds] at hy,
have : tendsto (λ c:R, y + c • x) (𝓝[{x : R | is_unit x}] 0) (𝓝 (y + (0:R) • x)),
from tendsto_const_nhds.add ((tendsto_nhds_within_of_tendsto_nhds tendsto_id).smul
tendsto_const_nhds),
rw [zero_smul, add_zero] at this,
obtain ⟨_, hu : y + _ • _ ∈ s, u, rfl⟩ :=
nonempty_of_mem (inter_mem (mem_map.1 (this hy)) self_mem_nhds_within),
have hy' : y ∈ ↑s := mem_of_mem_nhds hy,
rwa [s.add_mem_iff_right hy', ←units.smul_def, s.smul_mem_iff' u] at hu,
end
variables (R M)
/-- Let `R` be a topological ring such that zero is not an isolated point (e.g., a nondiscrete
normed field, see `normed_field.punctured_nhds_ne_bot`). Let `M` be a nontrivial module over `R`
such that `c • x = 0` implies `c = 0 ∨ x = 0`. Then `M` has no isolated points. We formulate this
using `ne_bot (𝓝[≠] x)`.
This lemma is not an instance because Lean would need to find `[has_continuous_smul ?m_1 M]` with
unknown `?m_1`. We register this as an instance for `R = ℝ` in `real.punctured_nhds_module_ne_bot`.
One can also use `haveI := module.punctured_nhds_ne_bot R M` in a proof.
-/
lemma module.punctured_nhds_ne_bot [nontrivial M] [ne_bot (𝓝[≠] (0 : R))]
[no_zero_smul_divisors R M] (x : M) :
ne_bot (𝓝[≠] x) :=
begin
rcases exists_ne (0 : M) with ⟨y, hy⟩,
suffices : tendsto (λ c : R, x + c • y) (𝓝[≠] 0) (𝓝[≠] x), from this.ne_bot,
refine tendsto.inf _ (tendsto_principal_principal.2 $ _),
{ convert tendsto_const_nhds.add ((@tendsto_id R _).smul_const y),
rw [zero_smul, add_zero] },
{ intros c hc,
simpa [hy] using hc }
end
end
section lattice_ops
variables {ι R M₁ M₂ : Type*} [semiring R] [add_comm_monoid M₁] [add_comm_monoid M₂]
[module R M₁] [module R M₂] [u : topological_space R] {t : topological_space M₂}
[has_continuous_smul R M₂] (f : M₁ →ₗ[R] M₂)
lemma has_continuous_smul_induced :
@has_continuous_smul R M₁ _ u (t.induced f) :=
{ continuous_smul :=
begin
letI : topological_space M₁ := t.induced f,
refine continuous_induced_rng _,
simp_rw [function.comp, f.map_smul],
refine continuous_fst.smul (continuous_induced_dom.comp continuous_snd)
end }
end lattice_ops
namespace submodule
variables {α β : Type*} [topological_space β]
instance [topological_space α] [semiring α] [add_comm_monoid β] [module α β]
[has_continuous_smul α β] (S : submodule α β) :
has_continuous_smul α S :=
{ continuous_smul :=
begin
rw embedding_subtype_coe.to_inducing.continuous_iff,
exact continuous_fst.smul
(continuous_subtype_coe.comp continuous_snd)
end }
instance [ring α] [add_comm_group β] [module α β] [topological_add_group β] (S : submodule α β) :
topological_add_group S :=
S.to_add_subgroup.topological_add_group
end submodule
section closure
variables {R : Type u} {M : Type v}
[semiring R] [topological_space R]
[topological_space M] [add_comm_monoid M]
[module R M] [has_continuous_smul R M]
lemma submodule.closure_smul_self_subset (s : submodule R M) :
(λ p : R × M, p.1 • p.2) '' ((set.univ : set R) ×ˢ closure (s : set M))
⊆ closure (s : set M) :=
calc
(λ p : R × M, p.1 • p.2) '' ((set.univ : set R) ×ˢ closure (s : set M))
= (λ p : R × M, p.1 • p.2) '' (closure ((set.univ : set R) ×ˢ (s : set M))) :
by simp [closure_prod_eq]
... ⊆ closure ((λ p : R × M, p.1 • p.2) '' ((set.univ : set R) ×ˢ (s : set M))) :
image_closure_subset_closure_image continuous_smul
... = closure s : begin
congr,
ext x,
refine ⟨_, λ hx, ⟨⟨1, x⟩, ⟨set.mem_univ _, hx⟩, one_smul R _⟩⟩,
rintros ⟨⟨c, y⟩, ⟨hc, hy⟩, rfl⟩,
simp [s.smul_mem c hy]
end
lemma submodule.closure_smul_self_eq (s : submodule R M) :
(λ p : R × M, p.1 • p.2) '' ((set.univ : set R) ×ˢ closure (s : set M))
= closure (s : set M) :=
set.subset.antisymm s.closure_smul_self_subset
(λ x hx, ⟨⟨1, x⟩, ⟨set.mem_univ _, hx⟩, one_smul R _⟩)
variables [has_continuous_add M]
/-- The (topological-space) closure of a submodule of a topological `R`-module `M` is itself
a submodule. -/
def submodule.topological_closure (s : submodule R M) : submodule R M :=
{ carrier := closure (s : set M),
smul_mem' := λ c x hx, s.closure_smul_self_subset ⟨⟨c, x⟩, ⟨set.mem_univ _, hx⟩, rfl⟩,
..s.to_add_submonoid.topological_closure }
@[simp] lemma submodule.topological_closure_coe (s : submodule R M) :
(s.topological_closure : set M) = closure (s : set M) :=
rfl
instance submodule.topological_closure_has_continuous_smul (s : submodule R M) :
has_continuous_smul R (s.topological_closure) :=
{ continuous_smul :=
begin
apply continuous_induced_rng,
change continuous (λ p : R × s.topological_closure, p.1 • (p.2 : M)),
continuity,
end,
..s.to_add_submonoid.topological_closure_has_continuous_add }
lemma submodule.submodule_topological_closure (s : submodule R M) :
s ≤ s.topological_closure :=
subset_closure
lemma submodule.is_closed_topological_closure (s : submodule R M) :
is_closed (s.topological_closure : set M) :=
by convert is_closed_closure
lemma submodule.topological_closure_minimal
(s : submodule R M) {t : submodule R M} (h : s ≤ t) (ht : is_closed (t : set M)) :
s.topological_closure ≤ t :=
closure_minimal h ht
lemma submodule.topological_closure_mono {s : submodule R M} {t : submodule R M} (h : s ≤ t) :
s.topological_closure ≤ t.topological_closure :=
s.topological_closure_minimal (h.trans t.submodule_topological_closure)
t.is_closed_topological_closure
/-- The topological closure of a closed submodule `s` is equal to `s`. -/
lemma is_closed.submodule_topological_closure_eq {s : submodule R M} (hs : is_closed (s : set M)) :
s.topological_closure = s :=
le_antisymm (s.topological_closure_minimal rfl.le hs) s.submodule_topological_closure
/-- A subspace is dense iff its topological closure is the entire space. -/
lemma submodule.dense_iff_topological_closure_eq_top {s : submodule R M} :
dense (s : set M) ↔ s.topological_closure = ⊤ :=
by { rw [←set_like.coe_set_eq, dense_iff_closure_eq], simp }
end closure
/-- Continuous linear maps between modules. We only put the type classes that are necessary for the
definition, although in applications `M` and `M₂` will be topological modules over the topological
ring `R`. -/
structure continuous_linear_map
{R : Type*} {S : Type*} [semiring R] [semiring S] (σ : R →+* S)
(M : Type*) [topological_space M] [add_comm_monoid M]
(M₂ : Type*) [topological_space M₂] [add_comm_monoid M₂]
[module R M] [module S M₂]
extends M →ₛₗ[σ] M₂ :=
(cont : continuous to_fun . tactic.interactive.continuity')
notation M ` →SL[`:25 σ `] ` M₂ := continuous_linear_map σ M M₂
notation M ` →L[`:25 R `] ` M₂ := continuous_linear_map (ring_hom.id R) M M₂
notation M ` →L⋆[`:25 R `] ` M₂ := continuous_linear_map (star_ring_end R) M M₂
set_option old_structure_cmd true
/-- `continuous_semilinear_map_class F σ M M₂` asserts `F` is a type of bundled continuous
`σ`-semilinear maps `M → M₂`. See also `continuous_linear_map_class F R M M₂` for the case where
`σ` is the identity map on `R`. A map `f` between an `R`-module and an `S`-module over a ring
homomorphism `σ : R →+* S` is semilinear if it satisfies the two properties `f (x + y) = f x + f y`
and `f (c • x) = (σ c) • f x`. -/
class continuous_semilinear_map_class (F : Type*) {R S : out_param Type*} [semiring R] [semiring S]
(σ : out_param $ R →+* S) (M : out_param Type*) [topological_space M] [add_comm_monoid M]
(M₂ : out_param Type*) [topological_space M₂] [add_comm_monoid M₂] [module R M] [module S M₂]
extends semilinear_map_class F σ M M₂, continuous_map_class F M M₂
-- `σ`, `R` and `S` become metavariables, but they are all outparams so it's OK
attribute [nolint dangerous_instance] continuous_semilinear_map_class.to_continuous_map_class
set_option old_structure_cmd false
/-- `continuous_linear_map_class F R M M₂` asserts `F` is a type of bundled continuous
`R`-linear maps `M → M₂`. This is an abbreviation for
`continuous_semilinear_map_class F (ring_hom.id R) M M₂`. -/
abbreviation continuous_linear_map_class (F : Type*)
(R : out_param Type*) [semiring R]
(M : out_param Type*) [topological_space M] [add_comm_monoid M]
(M₂ : out_param Type*) [topological_space M₂] [add_comm_monoid M₂]
[module R M] [module R M₂] :=
continuous_semilinear_map_class F (ring_hom.id R) M M₂
/-- Continuous linear equivalences between modules. We only put the type classes that are necessary
for the definition, although in applications `M` and `M₂` will be topological modules over the
topological semiring `R`. -/
@[nolint has_inhabited_instance]
structure continuous_linear_equiv
{R : Type*} {S : Type*} [semiring R] [semiring S] (σ : R →+* S)
{σ' : S →+* R} [ring_hom_inv_pair σ σ'] [ring_hom_inv_pair σ' σ]
(M : Type*) [topological_space M] [add_comm_monoid M]
(M₂ : Type*) [topological_space M₂] [add_comm_monoid M₂]
[module R M] [module S M₂]
extends M ≃ₛₗ[σ] M₂ :=
(continuous_to_fun : continuous to_fun . tactic.interactive.continuity')
(continuous_inv_fun : continuous inv_fun . tactic.interactive.continuity')
notation M ` ≃SL[`:50 σ `] ` M₂ := continuous_linear_equiv σ M M₂
notation M ` ≃L[`:50 R `] ` M₂ := continuous_linear_equiv (ring_hom.id R) M M₂
notation M ` ≃L⋆[`:50 R `] ` M₂ := continuous_linear_equiv (star_ring_end R) M M₂
section pointwise_limits
variables
{M₁ M₂ α R S : Type*}
[topological_space M₂] [t2_space M₂] [semiring R] [semiring S]
[add_comm_monoid M₁] [add_comm_monoid M₂] [module R M₁] [module S M₂]
[has_continuous_const_smul S M₂]
section
variables (M₁ M₂) (σ : R →+* S)
lemma is_closed_set_of_map_smul : is_closed {f : M₁ → M₂ | ∀ c x, f (c • x) = σ c • f x} :=
begin
simp only [set.set_of_forall],
exact is_closed_Inter (λ c, is_closed_Inter (λ x, is_closed_eq (continuous_apply _)
((continuous_apply _).const_smul _)))
end
end
variables [has_continuous_add M₂] {σ : R →+* S} {l : filter α}
/-- Constructs a bundled linear map from a function and a proof that this function belongs to the
closure of the set of linear maps. -/
@[simps { fully_applied := ff }] def linear_map_of_mem_closure_range_coe (f : M₁ → M₂)
(hf : f ∈ closure (set.range (coe_fn : (M₁ →ₛₗ[σ] M₂) → (M₁ → M₂)))) :
M₁ →ₛₗ[σ] M₂ :=
{ to_fun := f,
map_smul' := (is_closed_set_of_map_smul M₁ M₂ σ).closure_subset_iff.2
(set.range_subset_iff.2 linear_map.map_smulₛₗ) hf,
.. add_monoid_hom_of_mem_closure_range_coe f hf }
/-- Construct a bundled linear map from a pointwise limit of linear maps -/
@[simps { fully_applied := ff }]
def linear_map_of_tendsto (f : M₁ → M₂) (g : α → M₁ →ₛₗ[σ] M₂) [l.ne_bot]
(h : tendsto (λ a x, g a x) l (𝓝 f)) : M₁ →ₛₗ[σ] M₂ :=
linear_map_of_mem_closure_range_coe f $ mem_closure_of_tendsto h $
eventually_of_forall $ λ a, set.mem_range_self _
variables (M₁ M₂ σ)
lemma linear_map.is_closed_range_coe :
is_closed (set.range (coe_fn : (M₁ →ₛₗ[σ] M₂) → (M₁ → M₂))) :=
is_closed_of_closure_subset $ λ f hf, ⟨linear_map_of_mem_closure_range_coe f hf, rfl⟩
end pointwise_limits
namespace continuous_linear_map
section semiring
/-!
### Properties that hold for non-necessarily commutative semirings.
-/
variables
{R₁ : Type*} {R₂ : Type*} {R₃ : Type*} [semiring R₁] [semiring R₂] [semiring R₃]
{σ₁₂ : R₁ →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R₁ →+* R₃}
{M₁ : Type*} [topological_space M₁] [add_comm_monoid M₁]
{M'₁ : Type*} [topological_space M'₁] [add_comm_monoid M'₁]
{M₂ : Type*} [topological_space M₂] [add_comm_monoid M₂]
{M₃ : Type*} [topological_space M₃] [add_comm_monoid M₃]
{M₄ : Type*} [topological_space M₄] [add_comm_monoid M₄]
[module R₁ M₁] [module R₁ M'₁] [module R₂ M₂] [module R₃ M₃]
/-- Coerce continuous linear maps to linear maps. -/
instance : has_coe (M₁ →SL[σ₁₂] M₂) (M₁ →ₛₗ[σ₁₂] M₂) := ⟨to_linear_map⟩
-- make the coercion the preferred form
@[simp] lemma to_linear_map_eq_coe (f : M₁ →SL[σ₁₂] M₂) : f.to_linear_map = f := rfl
theorem coe_injective : function.injective (coe : (M₁ →SL[σ₁₂] M₂) → (M₁ →ₛₗ[σ₁₂] M₂)) :=
by { intros f g H, cases f, cases g, congr' }
instance : continuous_semilinear_map_class (M₁ →SL[σ₁₂] M₂) σ₁₂ M₁ M₂ :=
{ coe := λ f, f.to_fun,
coe_injective' := λ f g h, coe_injective (fun_like.coe_injective h),
map_add := λ f, map_add f.to_linear_map,
map_continuous := λ f, f.2,
map_smulₛₗ := λ f, f.to_linear_map.map_smul' }
/-- Coerce continuous linear maps to functions. -/
-- see Note [function coercion]
instance to_fun : has_coe_to_fun (M₁ →SL[σ₁₂] M₂) (λ _, M₁ → M₂) := ⟨λ f, f.to_fun⟩
@[simp] lemma coe_mk (f : M₁ →ₛₗ[σ₁₂] M₂) (h) : (mk f h : M₁ →ₛₗ[σ₁₂] M₂) = f := rfl
@[simp] lemma coe_mk' (f : M₁ →ₛₗ[σ₁₂] M₂) (h) : (mk f h : M₁ → M₂) = f := rfl
@[continuity]
protected lemma continuous (f : M₁ →SL[σ₁₂] M₂) : continuous f := f.2
protected lemma uniform_continuous {E₁ E₂ : Type*} [uniform_space E₁] [uniform_space E₂]
[add_comm_group E₁] [add_comm_group E₂] [module R₁ E₁] [module R₂ E₂]
[uniform_add_group E₁] [uniform_add_group E₂] (f : E₁ →SL[σ₁₂] E₂) :
uniform_continuous f :=
uniform_continuous_add_monoid_hom_of_continuous f.continuous
@[simp, norm_cast] lemma coe_inj {f g : M₁ →SL[σ₁₂] M₂} :
(f : M₁ →ₛₗ[σ₁₂] M₂) = g ↔ f = g :=
coe_injective.eq_iff
theorem coe_fn_injective : @function.injective (M₁ →SL[σ₁₂] M₂) (M₁ → M₂) coe_fn :=
fun_like.coe_injective
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def simps.apply (h : M₁ →SL[σ₁₂] M₂) : M₁ → M₂ := h
/-- See Note [custom simps projection]. -/
def simps.coe (h : M₁ →SL[σ₁₂] M₂) : M₁ →ₛₗ[σ₁₂] M₂ := h
initialize_simps_projections continuous_linear_map
(to_linear_map_to_fun → apply, to_linear_map → coe)
@[ext] theorem ext {f g : M₁ →SL[σ₁₂] M₂} (h : ∀ x, f x = g x) : f = g :=
fun_like.ext f g h
theorem ext_iff {f g : M₁ →SL[σ₁₂] M₂} : f = g ↔ ∀ x, f x = g x :=
fun_like.ext_iff
/-- Copy of a `continuous_linear_map` with a new `to_fun` equal to the old one. Useful to fix
definitional equalities. -/
protected def copy (f : M₁ →SL[σ₁₂] M₂) (f' : M₁ → M₂) (h : f' = ⇑f) : M₁ →SL[σ₁₂] M₂ :=
{ to_linear_map := f.to_linear_map.copy f' h,
cont := show continuous f', from h.symm ▸ f.continuous }
-- make some straightforward lemmas available to `simp`.
protected lemma map_zero (f : M₁ →SL[σ₁₂] M₂) : f (0 : M₁) = 0 := map_zero f
protected lemma map_add (f : M₁ →SL[σ₁₂] M₂) (x y : M₁) : f (x + y) = f x + f y := map_add f x y
@[simp]
protected lemma map_smulₛₗ (f : M₁ →SL[σ₁₂] M₂) (c : R₁) (x : M₁) :
f (c • x) = (σ₁₂ c) • f x := (to_linear_map _).map_smulₛₗ _ _
@[simp]
protected lemma map_smul [module R₁ M₂] (f : M₁ →L[R₁] M₂)(c : R₁) (x : M₁) : f (c • x) = c • f x :=
by simp only [ring_hom.id_apply, continuous_linear_map.map_smulₛₗ]
@[simp, priority 900]
lemma map_smul_of_tower {R S : Type*} [semiring S] [has_smul R M₁]
[module S M₁] [has_smul R M₂] [module S M₂]
[linear_map.compatible_smul M₁ M₂ R S] (f : M₁ →L[S] M₂) (c : R) (x : M₁) :
f (c • x) = c • f x :=
linear_map.compatible_smul.map_smul f c x
protected lemma map_sum {ι : Type*} (f : M₁ →SL[σ₁₂] M₂) (s : finset ι) (g : ι → M₁) :
f (∑ i in s, g i) = ∑ i in s, f (g i) := f.to_linear_map.map_sum
@[simp, norm_cast] lemma coe_coe (f : M₁ →SL[σ₁₂] M₂) : ⇑(f : M₁ →ₛₗ[σ₁₂] M₂) = f := rfl
@[ext] theorem ext_ring [topological_space R₁] {f g : R₁ →L[R₁] M₁} (h : f 1 = g 1) : f = g :=
coe_inj.1 $ linear_map.ext_ring h
theorem ext_ring_iff [topological_space R₁] {f g : R₁ →L[R₁] M₁} : f = g ↔ f 1 = g 1 :=
⟨λ h, h ▸ rfl, ext_ring⟩
/-- If two continuous linear maps are equal on a set `s`, then they are equal on the closure
of the `submodule.span` of this set. -/
lemma eq_on_closure_span [t2_space M₂] {s : set M₁} {f g : M₁ →SL[σ₁₂] M₂} (h : set.eq_on f g s) :
set.eq_on f g (closure (submodule.span R₁ s : set M₁)) :=
(linear_map.eq_on_span' h).closure f.continuous g.continuous
/-- If the submodule generated by a set `s` is dense in the ambient module, then two continuous
linear maps equal on `s` are equal. -/
lemma ext_on [t2_space M₂] {s : set M₁} (hs : dense (submodule.span R₁ s : set M₁))
{f g : M₁ →SL[σ₁₂] M₂} (h : set.eq_on f g s) :
f = g :=
ext $ λ x, eq_on_closure_span h (hs x)
/-- Under a continuous linear map, the image of the `topological_closure` of a submodule is
contained in the `topological_closure` of its image. -/
lemma _root_.submodule.topological_closure_map [ring_hom_surjective σ₁₂] [topological_space R₁]
[topological_space R₂] [has_continuous_smul R₁ M₁] [has_continuous_add M₁]
[has_continuous_smul R₂ M₂] [has_continuous_add M₂] (f : M₁ →SL[σ₁₂] M₂) (s : submodule R₁ M₁) :
(s.topological_closure.map (f : M₁ →ₛₗ[σ₁₂] M₂))
≤ (s.map (f : M₁ →ₛₗ[σ₁₂] M₂)).topological_closure :=
image_closure_subset_closure_image f.continuous
/-- Under a dense continuous linear map, a submodule whose `topological_closure` is `⊤` is sent to
another such submodule. That is, the image of a dense set under a map with dense range is dense.
-/
lemma _root_.dense_range.topological_closure_map_submodule [ring_hom_surjective σ₁₂]
[topological_space R₁] [topological_space R₂] [has_continuous_smul R₁ M₁] [has_continuous_add M₁]
[has_continuous_smul R₂ M₂] [has_continuous_add M₂] {f : M₁ →SL[σ₁₂] M₂} (hf' : dense_range f)
{s : submodule R₁ M₁} (hs : s.topological_closure = ⊤) :
(s.map (f : M₁ →ₛₗ[σ₁₂] M₂)).topological_closure = ⊤ :=
begin
rw set_like.ext'_iff at hs ⊢,
simp only [submodule.topological_closure_coe, submodule.top_coe, ← dense_iff_closure_eq] at hs ⊢,
exact hf'.dense_image f.continuous hs
end
section smul_monoid
variables {S₂ T₂ : Type*} [monoid S₂] [monoid T₂]
variables [distrib_mul_action S₂ M₂] [smul_comm_class R₂ S₂ M₂] [has_continuous_const_smul S₂ M₂]
variables [distrib_mul_action T₂ M₂] [smul_comm_class R₂ T₂ M₂] [has_continuous_const_smul T₂ M₂]
instance : mul_action S₂ (M₁ →SL[σ₁₂] M₂) :=
{ smul := λ c f, ⟨c • f, (f.2.const_smul _ : continuous (λ x, c • f x))⟩,
one_smul := λ f, ext $ λ x, one_smul _ _,
mul_smul := λ a b f, ext $ λ x, mul_smul _ _ _ }
lemma smul_apply (c : S₂) (f : M₁ →SL[σ₁₂] M₂) (x : M₁) : (c • f) x = c • (f x) := rfl
@[simp, norm_cast]
lemma coe_smul (c : S₂) (f : M₁ →SL[σ₁₂] M₂) : (↑(c • f) : M₁ →ₛₗ[σ₁₂] M₂) = c • f := rfl
@[simp, norm_cast] lemma coe_smul' (c : S₂) (f : M₁ →SL[σ₁₂] M₂) : ⇑(c • f) = c • f := rfl
instance [has_smul S₂ T₂] [is_scalar_tower S₂ T₂ M₂] : is_scalar_tower S₂ T₂ (M₁ →SL[σ₁₂] M₂) :=
⟨λ a b f, ext $ λ x, smul_assoc a b (f x)⟩
instance [smul_comm_class S₂ T₂ M₂] : smul_comm_class S₂ T₂ (M₁ →SL[σ₁₂] M₂) :=
⟨λ a b f, ext $ λ x, smul_comm a b (f x)⟩
end smul_monoid
/-- The continuous map that is constantly zero. -/
instance: has_zero (M₁ →SL[σ₁₂] M₂) := ⟨⟨0, continuous_zero⟩⟩
instance : inhabited (M₁ →SL[σ₁₂] M₂) := ⟨0⟩
@[simp] lemma default_def : (default : M₁ →SL[σ₁₂] M₂) = 0 := rfl
@[simp] lemma zero_apply (x : M₁) : (0 : M₁ →SL[σ₁₂] M₂) x = 0 := rfl
@[simp, norm_cast] lemma coe_zero : ((0 : M₁ →SL[σ₁₂] M₂) : M₁ →ₛₗ[σ₁₂] M₂) = 0 := rfl
/- no simp attribute on the next line as simp does not always simplify `0 x` to `0`
when `0` is the zero function, while it does for the zero continuous linear map,
and this is the most important property we care about. -/
@[norm_cast] lemma coe_zero' : ⇑(0 : M₁ →SL[σ₁₂] M₂) = 0 := rfl
instance unique_of_left [subsingleton M₁] : unique (M₁ →SL[σ₁₂] M₂) :=
coe_injective.unique
instance unique_of_right [subsingleton M₂] : unique (M₁ →SL[σ₁₂] M₂) :=
coe_injective.unique
lemma exists_ne_zero {f : M₁ →SL[σ₁₂] M₂} (hf : f ≠ 0) : ∃ x, f x ≠ 0 :=
by { by_contra' h, exact hf (continuous_linear_map.ext h) }
section
variables (R₁ M₁)
/-- the identity map as a continuous linear map. -/
def id : M₁ →L[R₁] M₁ :=
⟨linear_map.id, continuous_id⟩
end
instance : has_one (M₁ →L[R₁] M₁) := ⟨id R₁ M₁⟩
lemma one_def : (1 : M₁ →L[R₁] M₁) = id R₁ M₁ := rfl
lemma id_apply (x : M₁) : id R₁ M₁ x = x := rfl
@[simp, norm_cast] lemma coe_id : (id R₁ M₁ : M₁ →ₗ[R₁] M₁) = linear_map.id := rfl
@[simp, norm_cast] lemma coe_id' : ⇑(id R₁ M₁) = _root_.id := rfl
@[simp, norm_cast] lemma coe_eq_id {f : M₁ →L[R₁] M₁} :
(f : M₁ →ₗ[R₁] M₁) = linear_map.id ↔ f = id _ _ :=
by rw [← coe_id, coe_inj]
@[simp] lemma one_apply (x : M₁) : (1 : M₁ →L[R₁] M₁) x = x := rfl
section add
variables [has_continuous_add M₂]
instance : has_add (M₁ →SL[σ₁₂] M₂) :=
⟨λ f g, ⟨f + g, f.2.add g.2⟩⟩
@[simp] lemma add_apply (f g : M₁ →SL[σ₁₂] M₂) (x : M₁) : (f + g) x = f x + g x := rfl
@[simp, norm_cast] lemma coe_add (f g : M₁ →SL[σ₁₂] M₂) : (↑(f + g) : M₁ →ₛₗ[σ₁₂] M₂) = f + g := rfl
@[norm_cast] lemma coe_add' (f g : M₁ →SL[σ₁₂] M₂) : ⇑(f + g) = f + g := rfl
instance : add_comm_monoid (M₁ →SL[σ₁₂] M₂) :=
{ zero := (0 : M₁ →SL[σ₁₂] M₂),
add := (+),
zero_add := by intros; ext; apply_rules [zero_add, add_assoc, add_zero, add_left_neg, add_comm],
add_zero := by intros; ext; apply_rules [zero_add, add_assoc, add_zero, add_left_neg, add_comm],
add_comm := by intros; ext; apply_rules [zero_add, add_assoc, add_zero, add_left_neg, add_comm],
add_assoc := by intros; ext; apply_rules [zero_add, add_assoc, add_zero, add_left_neg, add_comm],
nsmul := (•),
nsmul_zero' := λ f, by { ext, simp },
nsmul_succ' := λ n f, by { ext, simp [nat.succ_eq_one_add, add_smul] } }
@[simp, norm_cast] lemma coe_sum {ι : Type*} (t : finset ι) (f : ι → M₁ →SL[σ₁₂] M₂) :
↑(∑ d in t, f d) = (∑ d in t, f d : M₁ →ₛₗ[σ₁₂] M₂) :=
(add_monoid_hom.mk (coe : (M₁ →SL[σ₁₂] M₂) → (M₁ →ₛₗ[σ₁₂] M₂)) rfl (λ _ _, rfl)).map_sum _ _
@[simp, norm_cast] lemma coe_sum' {ι : Type*} (t : finset ι) (f : ι → M₁ →SL[σ₁₂] M₂) :
⇑(∑ d in t, f d) = ∑ d in t, f d :=
by simp only [← coe_coe, coe_sum, linear_map.coe_fn_sum]
lemma sum_apply {ι : Type*} (t : finset ι) (f : ι → M₁ →SL[σ₁₂] M₂) (b : M₁) :
(∑ d in t, f d) b = ∑ d in t, f d b :=
by simp only [coe_sum', finset.sum_apply]
end add
variables [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃]
/-- Composition of bounded linear maps. -/
def comp (g : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) : M₁ →SL[σ₁₃] M₃ :=
⟨(g : M₂ →ₛₗ[σ₂₃] M₃).comp ↑f, g.2.comp f.2⟩
infixr ` ∘L `:80 := @continuous_linear_map.comp _ _ _ _ _ _
(ring_hom.id _) (ring_hom.id _) (ring_hom.id _) _ _ _ _ _ _ _ _ _ _ _ _ ring_hom_comp_triple.ids
@[simp, norm_cast] lemma coe_comp (h : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) :
(h.comp f : M₁ →ₛₗ[σ₁₃] M₃) = (h : M₂ →ₛₗ[σ₂₃] M₃).comp (f : M₁ →ₛₗ[σ₁₂] M₂) := rfl
include σ₁₃
@[simp, norm_cast] lemma coe_comp' (h : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) :
⇑(h.comp f) = h ∘ f := rfl
lemma comp_apply (g : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) (x : M₁) : (g.comp f) x = g (f x) := rfl
omit σ₁₃
@[simp] theorem comp_id (f : M₁ →SL[σ₁₂] M₂) : f.comp (id R₁ M₁) = f :=
ext $ λ x, rfl
@[simp] theorem id_comp (f : M₁ →SL[σ₁₂] M₂) : (id R₂ M₂).comp f = f :=
ext $ λ x, rfl
include σ₁₃
@[simp] theorem comp_zero (g : M₂ →SL[σ₂₃] M₃) : g.comp (0 : M₁ →SL[σ₁₂] M₂) = 0 :=
by { ext, simp }
@[simp] theorem zero_comp (f : M₁ →SL[σ₁₂] M₂) : (0 : M₂ →SL[σ₂₃] M₃).comp f = 0 :=
by { ext, simp }
@[simp] lemma comp_add [has_continuous_add M₂] [has_continuous_add M₃]
(g : M₂ →SL[σ₂₃] M₃) (f₁ f₂ : M₁ →SL[σ₁₂] M₂) :
g.comp (f₁ + f₂) = g.comp f₁ + g.comp f₂ :=
by { ext, simp }
@[simp] lemma add_comp [has_continuous_add M₃]
(g₁ g₂ : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) :
(g₁ + g₂).comp f = g₁.comp f + g₂.comp f :=
by { ext, simp }
omit σ₁₃
theorem comp_assoc {R₄ : Type*} [semiring R₄] [module R₄ M₄] {σ₁₄ : R₁ →+* R₄} {σ₂₄ : R₂ →+* R₄}
{σ₃₄ : R₃ →+* R₄} [ring_hom_comp_triple σ₁₃ σ₃₄ σ₁₄] [ring_hom_comp_triple σ₂₃ σ₃₄ σ₂₄]
[ring_hom_comp_triple σ₁₂ σ₂₄ σ₁₄] (h : M₃ →SL[σ₃₄] M₄) (g : M₂ →SL[σ₂₃] M₃)
(f : M₁ →SL[σ₁₂] M₂) :
(h.comp g).comp f = h.comp (g.comp f) :=
rfl
instance : has_mul (M₁ →L[R₁] M₁) := ⟨comp⟩
lemma mul_def (f g : M₁ →L[R₁] M₁) : f * g = f.comp g := rfl
@[simp] lemma coe_mul (f g : M₁ →L[R₁] M₁) : ⇑(f * g) = f ∘ g := rfl
lemma mul_apply (f g : M₁ →L[R₁] M₁) (x : M₁) : (f * g) x = f (g x) := rfl
instance : monoid_with_zero (M₁ →L[R₁] M₁) :=
{ mul := (*),
one := 1,
zero := 0,
mul_zero := λ f, ext $ λ _, map_zero f,
zero_mul := λ _, ext $ λ _, rfl,
mul_one := λ _, ext $ λ _, rfl,
one_mul := λ _, ext $ λ _, rfl,
mul_assoc := λ _ _ _, ext $ λ _, rfl, }
instance [has_continuous_add M₁] : semiring (M₁ →L[R₁] M₁) :=
{ mul := (*),
one := 1,
left_distrib := λ f g h, ext $ λ x, map_add f (g x) (h x),
right_distrib := λ _ _ _, ext $ λ _, linear_map.add_apply _ _ _,
..continuous_linear_map.monoid_with_zero,
..continuous_linear_map.add_comm_monoid }
/-- `continuous_linear_map.to_linear_map` as a `ring_hom`.-/
@[simps]
def to_linear_map_ring_hom [has_continuous_add M₁] : (M₁ →L[R₁] M₁) →+* (M₁ →ₗ[R₁] M₁) :=
{ to_fun := to_linear_map,
map_zero' := rfl,
map_one' := rfl,
map_add' := λ _ _, rfl,
map_mul' := λ _ _, rfl }
section apply_action
variables [has_continuous_add M₁]
/-- The tautological action by `M₁ →L[R₁] M₁` on `M`.
This generalizes `function.End.apply_mul_action`. -/
instance apply_module : module (M₁ →L[R₁] M₁) M₁ :=
module.comp_hom _ to_linear_map_ring_hom
@[simp] protected lemma smul_def (f : M₁ →L[R₁] M₁) (a : M₁) : f • a = f a := rfl
/-- `continuous_linear_map.apply_module` is faithful. -/
instance apply_has_faithful_smul : has_faithful_smul (M₁ →L[R₁] M₁) M₁ :=
⟨λ _ _, continuous_linear_map.ext⟩
instance apply_smul_comm_class : smul_comm_class R₁ (M₁ →L[R₁] M₁) M₁ :=
{ smul_comm := λ r e m, (e.map_smul r m).symm }
instance apply_smul_comm_class' : smul_comm_class (M₁ →L[R₁] M₁) R₁ M₁ :=
{ smul_comm := continuous_linear_map.map_smul }
instance : has_continuous_const_smul (M₁ →L[R₁] M₁) M₁ :=
⟨continuous_linear_map.continuous⟩
end apply_action
/-- The cartesian product of two bounded linear maps, as a bounded linear map. -/
protected def prod [module R₁ M₂] [module R₁ M₃] (f₁ : M₁ →L[R₁] M₂) (f₂ : M₁ →L[R₁] M₃) :
M₁ →L[R₁] (M₂ × M₃) :=
⟨(f₁ : M₁ →ₗ[R₁] M₂).prod f₂, f₁.2.prod_mk f₂.2⟩
@[simp, norm_cast] lemma coe_prod [module R₁ M₂] [module R₁ M₃] (f₁ : M₁ →L[R₁] M₂)
(f₂ : M₁ →L[R₁] M₃) :
(f₁.prod f₂ : M₁ →ₗ[R₁] M₂ × M₃) = linear_map.prod f₁ f₂ :=
rfl
@[simp, norm_cast] lemma prod_apply [module R₁ M₂] [module R₁ M₃] (f₁ : M₁ →L[R₁] M₂)
(f₂ : M₁ →L[R₁] M₃) (x : M₁) :
f₁.prod f₂ x = (f₁ x, f₂ x) :=
rfl
section
variables (R₁ M₁ M₂)
/-- The left injection into a product is a continuous linear map. -/
def inl [module R₁ M₂] : M₁ →L[R₁] M₁ × M₂ := (id R₁ M₁).prod 0
/-- The right injection into a product is a continuous linear map. -/
def inr [module R₁ M₂] : M₂ →L[R₁] M₁ × M₂ := (0 : M₂ →L[R₁] M₁).prod (id R₁ M₂)
end
@[simp] lemma inl_apply [module R₁ M₂] (x : M₁) : inl R₁ M₁ M₂ x = (x, 0) := rfl
@[simp] lemma inr_apply [module R₁ M₂] (x : M₂) : inr R₁ M₁ M₂ x = (0, x) := rfl
@[simp, norm_cast] lemma coe_inl [module R₁ M₂] :
(inl R₁ M₁ M₂ : M₁ →ₗ[R₁] M₁ × M₂) = linear_map.inl R₁ M₁ M₂ := rfl
@[simp, norm_cast] lemma coe_inr [module R₁ M₂] :
(inr R₁ M₁ M₂ : M₂ →ₗ[R₁] M₁ × M₂) = linear_map.inr R₁ M₁ M₂ := rfl
/-- Kernel of a continuous linear map. -/
def ker (f : M₁ →SL[σ₁₂] M₂) : submodule R₁ M₁ := (f : M₁ →ₛₗ[σ₁₂] M₂).ker
@[norm_cast] lemma ker_coe (f : M₁ →SL[σ₁₂] M₂) : (f : M₁ →ₛₗ[σ₁₂] M₂).ker = f.ker := rfl
@[simp] lemma mem_ker {f : M₁ →SL[σ₁₂] M₂} {x} : x ∈ f.ker ↔ f x = 0 := linear_map.mem_ker
lemma is_closed_ker [t1_space M₂] (f : M₁ →SL[σ₁₂] M₂) : is_closed (f.ker : set M₁) :=
continuous_iff_is_closed.1 f.cont _ is_closed_singleton
@[simp] lemma apply_ker (f : M₁ →SL[σ₁₂] M₂) (x : f.ker) : f x = 0 := mem_ker.1 x.2
lemma is_complete_ker {M' : Type*} [uniform_space M'] [complete_space M'] [add_comm_monoid M']
[module R₁ M'] [t1_space M₂] (f : M' →SL[σ₁₂] M₂) :
is_complete (f.ker : set M') :=
f.is_closed_ker.is_complete
instance complete_space_ker {M' : Type*} [uniform_space M'] [complete_space M'] [add_comm_monoid M']
[module R₁ M'] [t1_space M₂] (f : M' →SL[σ₁₂] M₂) :
complete_space f.ker :=
f.is_closed_ker.complete_space_coe
@[simp] lemma ker_prod [module R₁ M₂] [module R₁ M₃] (f : M₁ →L[R₁] M₂) (g : M₁ →L[R₁] M₃) :
ker (f.prod g) = ker f ⊓ ker g :=
linear_map.ker_prod f g
/-- Range of a continuous linear map. -/
def range [ring_hom_surjective σ₁₂] (f : M₁ →SL[σ₁₂] M₂) : submodule R₂ M₂ :=
(f : M₁ →ₛₗ[σ₁₂] M₂).range
lemma range_coe [ring_hom_surjective σ₁₂] (f : M₁ →SL[σ₁₂] M₂) : (f.range : set M₂) = set.range f :=
linear_map.range_coe _
lemma mem_range [ring_hom_surjective σ₁₂] {f : M₁ →SL[σ₁₂] M₂} {y} : y ∈ f.range ↔ ∃ x, f x = y :=
linear_map.mem_range
lemma mem_range_self [ring_hom_surjective σ₁₂] (f : M₁ →SL[σ₁₂] M₂) (x : M₁) : f x ∈ f.range :=
mem_range.2 ⟨x, rfl⟩
lemma range_prod_le [module R₁ M₂] [module R₁ M₃] (f : M₁ →L[R₁] M₂) (g : M₁ →L[R₁] M₃) :
range (f.prod g) ≤ (range f).prod (range g) :=
(f : M₁ →ₗ[R₁] M₂).range_prod_le g
/-- Restrict codomain of a continuous linear map. -/
def cod_restrict (f : M₁ →SL[σ₁₂] M₂) (p : submodule R₂ M₂) (h : ∀ x, f x ∈ p) :
M₁ →SL[σ₁₂] p :=
{ cont := continuous_subtype_mk h f.continuous,
to_linear_map := (f : M₁ →ₛₗ[σ₁₂] M₂).cod_restrict p h}
@[norm_cast] lemma coe_cod_restrict (f : M₁ →SL[σ₁₂] M₂) (p : submodule R₂ M₂) (h : ∀ x, f x ∈ p) :
(f.cod_restrict p h : M₁ →ₛₗ[σ₁₂] p) = (f : M₁ →ₛₗ[σ₁₂] M₂).cod_restrict p h :=
rfl
@[simp] lemma coe_cod_restrict_apply (f : M₁ →SL[σ₁₂] M₂) (p : submodule R₂ M₂) (h : ∀ x, f x ∈ p)
(x) :
(f.cod_restrict p h x : M₂) = f x :=
rfl
@[simp] lemma ker_cod_restrict (f : M₁ →SL[σ₁₂] M₂) (p : submodule R₂ M₂) (h : ∀ x, f x ∈ p) :
ker (f.cod_restrict p h) = ker f :=
(f : M₁ →ₛₗ[σ₁₂] M₂).ker_cod_restrict p h
/-- Embedding of a submodule into the ambient space as a continuous linear map. -/
def subtype_val (p : submodule R₁ M₁) : p →L[R₁] M₁ :=
{ cont := continuous_subtype_val,
to_linear_map := p.subtype }
@[simp, norm_cast] lemma coe_subtype_val (p : submodule R₁ M₁) :
(subtype_val p : p →ₗ[R₁] M₁) = p.subtype :=
rfl
@[simp, norm_cast] lemma subtype_val_apply (p : submodule R₁ M₁) (x : p) :
(subtype_val p : p → M₁) x = x :=
rfl
variables (R₁ M₁ M₂)
/-- `prod.fst` as a `continuous_linear_map`. -/
def fst [module R₁ M₂] : M₁ × M₂ →L[R₁] M₁ :=
{ cont := continuous_fst, to_linear_map := linear_map.fst R₁ M₁ M₂ }
/-- `prod.snd` as a `continuous_linear_map`. -/
def snd [module R₁ M₂] : M₁ × M₂ →L[R₁] M₂ :=
{ cont := continuous_snd, to_linear_map := linear_map.snd R₁ M₁ M₂ }
variables {R₁ M₁ M₂}
@[simp, norm_cast] lemma coe_fst [module R₁ M₂] : ↑(fst R₁ M₁ M₂) = linear_map.fst R₁ M₁ M₂ := rfl
@[simp, norm_cast] lemma coe_fst' [module R₁ M₂] : ⇑(fst R₁ M₁ M₂) = prod.fst := rfl
@[simp, norm_cast] lemma coe_snd [module R₁ M₂] : ↑(snd R₁ M₁ M₂) = linear_map.snd R₁ M₁ M₂ := rfl
@[simp, norm_cast] lemma coe_snd' [module R₁ M₂] : ⇑(snd R₁ M₁ M₂) = prod.snd := rfl
@[simp] lemma fst_prod_snd [module R₁ M₂] : (fst R₁ M₁ M₂).prod (snd R₁ M₁ M₂) = id R₁ (M₁ × M₂) :=
ext $ λ ⟨x, y⟩, rfl
@[simp] lemma fst_comp_prod [module R₁ M₂] [module R₁ M₃] (f : M₁ →L[R₁] M₂) (g : M₁ →L[R₁] M₃) :
(fst R₁ M₂ M₃).comp (f.prod g) = f :=
ext $ λ x, rfl
@[simp] lemma snd_comp_prod [module R₁ M₂] [module R₁ M₃] (f : M₁ →L[R₁] M₂) (g : M₁ →L[R₁] M₃) :
(snd R₁ M₂ M₃).comp (f.prod g) = g :=
ext $ λ x, rfl
/-- `prod.map` of two continuous linear maps. -/
def prod_map [module R₁ M₂] [module R₁ M₃] [module R₁ M₄] (f₁ : M₁ →L[R₁] M₂) (f₂ : M₃ →L[R₁] M₄) :
(M₁ × M₃) →L[R₁] (M₂ × M₄) :=
(f₁.comp (fst R₁ M₁ M₃)).prod (f₂.comp (snd R₁ M₁ M₃))
@[simp, norm_cast] lemma coe_prod_map [module R₁ M₂] [module R₁ M₃] [module R₁ M₄]
(f₁ : M₁ →L[R₁] M₂) (f₂ : M₃ →L[R₁] M₄) :
↑(f₁.prod_map f₂) = ((f₁ : M₁ →ₗ[R₁] M₂).prod_map (f₂ : M₃ →ₗ[R₁] M₄)) :=
rfl
@[simp, norm_cast] lemma coe_prod_map' [module R₁ M₂] [module R₁ M₃] [module R₁ M₄]
(f₁ : M₁ →L[R₁] M₂) (f₂ : M₃ →L[R₁] M₄) :
⇑(f₁.prod_map f₂) = prod.map f₁ f₂ :=
rfl
/-- The continuous linear map given by `(x, y) ↦ f₁ x + f₂ y`. -/
def coprod [module R₁ M₂] [module R₁ M₃] [has_continuous_add M₃] (f₁ : M₁ →L[R₁] M₃)
(f₂ : M₂ →L[R₁] M₃) :
(M₁ × M₂) →L[R₁] M₃ :=
⟨linear_map.coprod f₁ f₂, (f₁.cont.comp continuous_fst).add (f₂.cont.comp continuous_snd)⟩
@[norm_cast, simp] lemma coe_coprod [module R₁ M₂] [module R₁ M₃] [has_continuous_add M₃]
(f₁ : M₁ →L[R₁] M₃) (f₂ : M₂ →L[R₁] M₃) :
(f₁.coprod f₂ : (M₁ × M₂) →ₗ[R₁] M₃) = linear_map.coprod f₁ f₂ :=
rfl
@[simp] lemma coprod_apply [module R₁ M₂] [module R₁ M₃] [has_continuous_add M₃]
(f₁ : M₁ →L[R₁] M₃) (f₂ : M₂ →L[R₁] M₃) (x) :
f₁.coprod f₂ x = f₁ x.1 + f₂ x.2 := rfl
lemma range_coprod [module R₁ M₂] [module R₁ M₃] [has_continuous_add M₃] (f₁ : M₁ →L[R₁] M₃)
(f₂ : M₂ →L[R₁] M₃) :
(f₁.coprod f₂).range = f₁.range ⊔ f₂.range :=
linear_map.range_coprod _ _
section
variables {R S : Type*} [semiring R] [semiring S] [module R M₁] [module R M₂] [module R S]
[module S M₂] [is_scalar_tower R S M₂] [topological_space S] [has_continuous_smul S M₂]
/-- The linear map `λ x, c x • f`. Associates to a scalar-valued linear map and an element of
`M₂` the `M₂`-valued linear map obtained by multiplying the two (a.k.a. tensoring by `M₂`).
See also `continuous_linear_map.smul_rightₗ` and `continuous_linear_map.smul_rightL`. -/
def smul_right (c : M₁ →L[R] S) (f : M₂) : M₁ →L[R] M₂ :=
{ cont := c.2.smul continuous_const,
..c.to_linear_map.smul_right f }
@[simp]
lemma smul_right_apply {c : M₁ →L[R] S} {f : M₂} {x : M₁} :
(smul_right c f : M₁ → M₂) x = c x • f :=
rfl
end
variables [module R₁ M₂] [topological_space R₁] [has_continuous_smul R₁ M₂]
@[simp]
lemma smul_right_one_one (c : R₁ →L[R₁] M₂) : smul_right (1 : R₁ →L[R₁] R₁) (c 1) = c :=
by ext; simp [← continuous_linear_map.map_smul_of_tower]
@[simp]
lemma smul_right_one_eq_iff {f f' : M₂} :
smul_right (1 : R₁ →L[R₁] R₁) f = smul_right (1 : R₁ →L[R₁] R₁) f' ↔ f = f' :=
by simp only [ext_ring_iff, smul_right_apply, one_apply, one_smul]
lemma smul_right_comp [has_continuous_mul R₁] {x : M₂} {c : R₁} :
(smul_right (1 : R₁ →L[R₁] R₁) x).comp (smul_right (1 : R₁ →L[R₁] R₁) c) =
smul_right (1 : R₁ →L[R₁] R₁) (c • x) :=
by { ext, simp [mul_smul] }
end semiring
section pi
variables
{R : Type*} [semiring R]
{M : Type*} [topological_space M] [add_comm_monoid M] [module R M]
{M₂ : Type*} [topological_space M₂] [add_comm_monoid M₂] [module R M₂]
{ι : Type*} {φ : ι → Type*} [∀i, topological_space (φ i)] [∀i, add_comm_monoid (φ i)]
[∀i, module R (φ i)]
/-- `pi` construction for continuous linear functions. From a family of continuous linear functions
it produces a continuous linear function into a family of topological modules. -/
def pi (f : Πi, M →L[R] φ i) : M →L[R] (Πi, φ i) :=
⟨linear_map.pi (λ i, f i), continuous_pi (λ i, (f i).continuous)⟩
@[simp] lemma coe_pi' (f : Π i, M →L[R] φ i) : ⇑(pi f) = λ c i, f i c := rfl
@[simp] lemma coe_pi (f : Π i, M →L[R] φ i) :
(pi f : M →ₗ[R] Π i, φ i) = linear_map.pi (λ i, f i) :=
rfl
lemma pi_apply (f : Πi, M →L[R] φ i) (c : M) (i : ι) :
pi f c i = f i c := rfl
lemma pi_eq_zero (f : Πi, M →L[R] φ i) : pi f = 0 ↔ (∀i, f i = 0) :=
by { simp only [ext_iff, pi_apply, function.funext_iff], exact forall_swap }
lemma pi_zero : pi (λi, 0 : Πi, M →L[R] φ i) = 0 := ext $ λ _, rfl
lemma pi_comp (f : Πi, M →L[R] φ i) (g : M₂ →L[R] M) : (pi f).comp g = pi (λi, (f i).comp g) := rfl
/-- The projections from a family of topological modules are continuous linear maps. -/
def proj (i : ι) : (Πi, φ i) →L[R] φ i :=
⟨linear_map.proj i, continuous_apply _⟩
@[simp] lemma proj_apply (i : ι) (b : Πi, φ i) : (proj i : (Πi, φ i) →L[R] φ i) b = b i := rfl
lemma proj_pi (f : Πi, M₂ →L[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)) = ⊥ :=
linear_map.infi_ker_proj
variables (R φ)
/-- If `I` and `J` are complementary 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)) ≃L[R] (Πi:I, φ i) :=
⟨ linear_map.infi_ker_proj_equiv R φ hd hu,
continuous_pi (λ i, begin
have := @continuous_subtype_coe _ _ (λ x, x ∈ (⨅i ∈ J, ker (proj i) : submodule R (Πi, φ i))),
have := continuous.comp (by exact continuous_apply i) this,
exact this
end),
continuous_subtype_mk _ (continuous_pi (λ i, begin
dsimp, split_ifs; [apply continuous_apply, exact continuous_zero]
end)) ⟩
end pi
section ring
variables
{R : Type*} [ring R] {R₂ : Type*} [ring R₂]
{M : Type*} [topological_space M] [add_comm_group M]
{M₂ : Type*} [topological_space M₂] [add_comm_group M₂]
{M₃ : Type*} [topological_space M₃] [add_comm_group M₃]
{M₄ : Type*} [topological_space M₄] [add_comm_group M₄]
[module R M] [module R₂ M₂]
{σ₁₂ : R →+* R₂}
section
protected lemma map_neg (f : M →SL[σ₁₂] M₂) (x : M) : f (-x) = - (f x) := map_neg _ _
protected lemma map_sub (f : M →SL[σ₁₂] M₂) (x y : M) : f (x - y) = f x - f y := map_sub _ _ _
@[simp] lemma sub_apply' (f g : M →SL[σ₁₂] M₂) (x : M) : ((f : M →ₛₗ[σ₁₂] M₂) - g) x = f x - g x :=
rfl
end
section
variables [module R M₂] [module R M₃] [module R M₄]
lemma range_prod_eq {f : M →L[R] M₂} {g : M →L[R] M₃} (h : ker f ⊔ ker g = ⊤) :
range (f.prod g) = (range f).prod (range g) :=
linear_map.range_prod_eq h
lemma ker_prod_ker_le_ker_coprod [has_continuous_add M₃]
(f : M →L[R] M₃) (g : M₂ →L[R] M₃) :
(ker f).prod (ker g) ≤ ker (f.coprod g) :=
linear_map.ker_prod_ker_le_ker_coprod f.to_linear_map g.to_linear_map
lemma ker_coprod_of_disjoint_range [has_continuous_add M₃]
(f : M →L[R] M₃) (g : M₂ →L[R] M₃) (hd : disjoint f.range g.range) :
ker (f.coprod g) = (ker f).prod (ker g) :=
linear_map.ker_coprod_of_disjoint_range f.to_linear_map g.to_linear_map hd
end
section
variables [topological_add_group M₂]
instance : has_neg (M →SL[σ₁₂] M₂) := ⟨λ f, ⟨-f, f.2.neg⟩⟩
@[simp] lemma neg_apply (f : M →SL[σ₁₂] M₂) (x : M) : (-f) x = - (f x) := rfl
@[simp, norm_cast] lemma coe_neg (f : M →SL[σ₁₂] M₂) : (↑(-f) : M →ₛₗ[σ₁₂] M₂) = -f := rfl
@[norm_cast] lemma coe_neg' (f : M →SL[σ₁₂] M₂) : ⇑(-f) = -f := rfl
instance : has_sub (M →SL[σ₁₂] M₂) := ⟨λ f g, ⟨f - g, f.2.sub g.2⟩⟩
instance : add_comm_group (M →SL[σ₁₂] M₂) :=
by refine
{ zero := 0,
add := (+),
neg := has_neg.neg,
sub := has_sub.sub,
sub_eq_add_neg := _,
nsmul := (•),
zsmul := (•),
zsmul_zero' := λ f, by { ext, simp },
zsmul_succ' := λ n f, by { ext, simp [add_smul, add_comm] },
zsmul_neg' := λ n f, by { ext, simp [nat.succ_eq_add_one, add_smul] },
.. continuous_linear_map.add_comm_monoid, .. };
intros; ext; apply_rules [zero_add, add_assoc, add_zero, add_left_neg, add_comm, sub_eq_add_neg]
lemma sub_apply (f g : M →SL[σ₁₂] M₂) (x : M) : (f - g) x = f x - g x := rfl
@[simp, norm_cast] lemma coe_sub (f g : M →SL[σ₁₂] M₂) : (↑(f - g) : M →ₛₗ[σ₁₂] M₂) = f - g := rfl
@[simp, norm_cast] lemma coe_sub' (f g : M →SL[σ₁₂] M₂) : ⇑(f - g) = f - g := rfl
end
instance [topological_add_group M] : ring (M →L[R] M) :=
{ mul := (*),
one := 1,
..continuous_linear_map.semiring,
..continuous_linear_map.add_comm_group }
lemma smul_right_one_pow [topological_space R] [topological_ring R] (c : R) (n : ℕ) :
(smul_right (1 : R →L[R] R) c)^n = smul_right (1 : R →L[R] R) (c^n) :=
begin
induction n with n ihn,
{ ext, simp },
{ rw [pow_succ, ihn, mul_def, smul_right_comp, smul_eq_mul, pow_succ'] }
end
section
variables {σ₂₁ : R₂ →+* R} [ring_hom_inv_pair σ₁₂ σ₂₁]
/-- Given a right inverse `f₂ : M₂ →L[R] M` to `f₁ : M →L[R] M₂`,
`proj_ker_of_right_inverse f₁ f₂ h` is the projection `M →L[R] f₁.ker` along `f₂.range`. -/
def proj_ker_of_right_inverse [topological_add_group M] (f₁ : M →SL[σ₁₂] M₂) (f₂ : M₂ →SL[σ₂₁] M)
(h : function.right_inverse f₂ f₁) :
M →L[R] f₁.ker :=
(id R M - f₂.comp f₁).cod_restrict f₁.ker $ λ x, by simp [h (f₁ x)]
@[simp] lemma coe_proj_ker_of_right_inverse_apply [topological_add_group M]
(f₁ : M →SL[σ₁₂] M₂) (f₂ : M₂ →SL[σ₂₁] M) (h : function.right_inverse f₂ f₁) (x : M) :
(f₁.proj_ker_of_right_inverse f₂ h x : M) = x - f₂ (f₁ x) :=
rfl
@[simp] lemma proj_ker_of_right_inverse_apply_idem [topological_add_group M]
(f₁ : M →SL[σ₁₂] M₂) (f₂ : M₂ →SL[σ₂₁] M) (h : function.right_inverse f₂ f₁) (x : f₁.ker) :
f₁.proj_ker_of_right_inverse f₂ h x = x :=
subtype.ext_iff_val.2 $ by simp
@[simp] lemma proj_ker_of_right_inverse_comp_inv [topological_add_group M]
(f₁ : M →SL[σ₁₂] M₂) (f₂ : M₂ →SL[σ₂₁] M) (h : function.right_inverse f₂ f₁) (y : M₂) :
f₁.proj_ker_of_right_inverse f₂ h (f₂ y) = 0 :=
subtype.ext_iff_val.2 $ by simp [h y]
end
end ring
section division_monoid
variables {R M : Type*}
/-- A nonzero continuous linear functional is open. -/
protected lemma is_open_map_of_ne_zero [topological_space R] [division_ring R]
[has_continuous_sub R] [add_comm_group M] [topological_space M] [has_continuous_add M]
[module R M] [has_continuous_smul R M] (f : M →L[R] R) (hf : f ≠ 0) : is_open_map f :=
let ⟨x, hx⟩ := exists_ne_zero hf in is_open_map.of_sections $ λ y,
⟨λ a, y + (a - f y) • (f x)⁻¹ • x, continuous.continuous_at $ by continuity,
by simp, λ a, by simp [hx]⟩
end division_monoid
section smul_monoid
-- The M's are used for semilinear maps, and the N's for plain linear maps
variables {R R₂ R₃ S S₃ : Type*} [semiring R] [semiring R₂] [semiring R₃]
[monoid S] [monoid S₃]
{M : Type*} [topological_space M] [add_comm_monoid M] [module R M]
{M₂ : Type*} [topological_space M₂] [add_comm_monoid M₂] [module R₂ M₂]
{M₃ : Type*} [topological_space M₃] [add_comm_monoid M₃] [module R₃ M₃]
{N₂ : Type*} [topological_space N₂] [add_comm_monoid N₂] [module R N₂]
{N₃ : Type*} [topological_space N₃] [add_comm_monoid N₃] [module R N₃]
[distrib_mul_action S₃ M₃] [smul_comm_class R₃ S₃ M₃] [has_continuous_const_smul S₃ M₃]
[distrib_mul_action S N₃] [smul_comm_class R S N₃] [has_continuous_const_smul S N₃]
{σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃} [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃]
include σ₁₃
@[simp] lemma smul_comp (c : S₃) (h : M₂ →SL[σ₂₃] M₃) (f : M →SL[σ₁₂] M₂) :
(c • h).comp f = c • (h.comp f) := rfl
omit σ₁₃
variables [distrib_mul_action S₃ M₂] [has_continuous_const_smul S₃ M₂] [smul_comm_class R₂ S₃ M₂]
variables [distrib_mul_action S N₂] [has_continuous_const_smul S N₂] [smul_comm_class R S N₂]
@[simp] lemma comp_smul [linear_map.compatible_smul N₂ N₃ S R]
(hₗ : N₂ →L[R] N₃) (c : S) (fₗ : M →L[R] N₂) :
hₗ.comp (c • fₗ) = c • (hₗ.comp fₗ) :=
by { ext x, exact hₗ.map_smul_of_tower c (fₗ x) }
include σ₁₃
@[simp] lemma comp_smulₛₗ [smul_comm_class R₂ R₂ M₂] [smul_comm_class R₃ R₃ M₃]
[has_continuous_const_smul R₂ M₂] [has_continuous_const_smul R₃ M₃]
(h : M₂ →SL[σ₂₃] M₃) (c : R₂) (f : M →SL[σ₁₂] M₂) :
h.comp (c • f) = (σ₂₃ c) • (h.comp f) :=
by { ext x, simp only [coe_smul', coe_comp', function.comp_app, pi.smul_apply,
continuous_linear_map.map_smulₛₗ] }
omit σ₁₃
instance [has_continuous_add M₂] : distrib_mul_action S₃ (M →SL[σ₁₂] M₂) :=
{ smul_add := λ a f g, ext $ λ x, smul_add a (f x) (g x),
smul_zero := λ a, ext $ λ x, smul_zero _ }
end smul_monoid
section smul
-- The M's are used for semilinear maps, and the N's for plain linear maps
variables {R R₂ R₃ S S₃ : Type*} [semiring R] [semiring R₂] [semiring R₃]
[semiring S] [semiring S₃]
{M : Type*} [topological_space M] [add_comm_monoid M] [module R M]
{M₂ : Type*} [topological_space M₂] [add_comm_monoid M₂] [module R₂ M₂]
{M₃ : Type*} [topological_space M₃] [add_comm_monoid M₃] [module R₃ M₃]
{N₂ : Type*} [topological_space N₂] [add_comm_monoid N₂] [module R N₂]
{N₃ : Type*} [topological_space N₃] [add_comm_monoid N₃] [module R N₃]
[module S₃ M₃] [smul_comm_class R₃ S₃ M₃] [has_continuous_const_smul S₃ M₃]
[module S N₂] [has_continuous_const_smul S N₂] [smul_comm_class R S N₂]
[module S N₃] [smul_comm_class R S N₃] [has_continuous_const_smul S N₃]
{σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃} [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃]
(c : S) (h : M₂ →SL[σ₂₃] M₃) (f g : M →SL[σ₁₂] M₂) (x y z : M)
/-- `continuous_linear_map.prod` as an `equiv`. -/
@[simps apply] def prod_equiv : ((M →L[R] N₂) × (M →L[R] N₃)) ≃ (M →L[R] N₂ × N₃) :=
{ to_fun := λ f, f.1.prod f.2,
inv_fun := λ f, ⟨(fst _ _ _).comp f, (snd _ _ _).comp f⟩,
left_inv := λ f, by ext; refl,
right_inv := λ f, by ext; refl }
lemma prod_ext_iff {f g : M × N₂ →L[R] N₃} :
f = g ↔ f.comp (inl _ _ _) = g.comp (inl _ _ _) ∧ f.comp (inr _ _ _) = g.comp (inr _ _ _) :=
by { simp only [← coe_inj, linear_map.prod_ext_iff], refl }
@[ext] lemma prod_ext {f g : M × N₂ →L[R] N₃} (hl : f.comp (inl _ _ _) = g.comp (inl _ _ _))
(hr : f.comp (inr _ _ _) = g.comp (inr _ _ _)) : f = g :=
prod_ext_iff.2 ⟨hl, hr⟩
variables [has_continuous_add M₂] [has_continuous_add M₃] [has_continuous_add N₂]
instance : module S₃ (M →SL[σ₁₃] M₃) :=
{ zero_smul := λ _, ext $ λ _, zero_smul _ _,
add_smul := λ _ _ _, ext $ λ _, add_smul _ _ _ }
instance [module S₃ᵐᵒᵖ M₃] [is_central_scalar S₃ M₃] : is_central_scalar S₃ (M →SL[σ₁₃] M₃) :=
{ op_smul_eq_smul := λ _ _, ext $ λ _, op_smul_eq_smul _ _ }
variables (S) [has_continuous_add N₃]
/-- `continuous_linear_map.prod` as a `linear_equiv`. -/
@[simps apply] def prodₗ : ((M →L[R] N₂) × (M →L[R] N₃)) ≃ₗ[S] (M →L[R] N₂ × N₃) :=
{ map_add' := λ f g, rfl,
map_smul' := λ c f, rfl,
.. prod_equiv }
/-- The coercion from `M →L[R] M₂` to `M →ₗ[R] M₂`, as a linear map. -/
@[simps]
def coe_lm : (M →L[R] N₃) →ₗ[S] (M →ₗ[R] N₃) :=
{ to_fun := coe,
map_add' := λ f g, coe_add f g,
map_smul' := λ c f, coe_smul c f }
variables {S} (σ₁₃)
/-- The coercion from `M →SL[σ] M₂` to `M →ₛₗ[σ] M₂`, as a linear map. -/
@[simps]
def coe_lmₛₗ : (M →SL[σ₁₃] M₃) →ₗ[S₃] (M →ₛₗ[σ₁₃] M₃) :=
{ to_fun := coe,
map_add' := λ f g, coe_add f g,
map_smul' := λ c f, coe_smul c f }
variables {σ₁₃}
end smul
section smul_rightₗ
variables {R S T M M₂ : Type*} [semiring R] [semiring S] [semiring T] [module R S]
[add_comm_monoid M₂] [module R M₂] [module S M₂] [is_scalar_tower R S M₂]
[topological_space S] [topological_space M₂] [has_continuous_smul S M₂]
[topological_space M] [add_comm_monoid M] [module R M] [has_continuous_add M₂]
[module T M₂] [has_continuous_const_smul T M₂]
[smul_comm_class R T M₂] [smul_comm_class S T M₂]
/-- Given `c : E →L[𝕜] 𝕜`, `c.smul_rightₗ` is the linear map from `F` to `E →L[𝕜] F`
sending `f` to `λ e, c e • f`. See also `continuous_linear_map.smul_rightL`. -/
def smul_rightₗ (c : M →L[R] S) : M₂ →ₗ[T] (M →L[R] M₂) :=
{ to_fun := c.smul_right,
map_add' := λ x y, by { ext e, apply smul_add },
map_smul' := λ a x, by { ext e, dsimp, apply smul_comm } }
@[simp] lemma coe_smul_rightₗ (c : M →L[R] S) :
⇑(smul_rightₗ c : M₂ →ₗ[T] (M →L[R] M₂)) = c.smul_right := rfl
end smul_rightₗ
section comm_ring
/-- The determinant of a continuous linear map, mainly as a convenience device to be able to
write `A.det` instead of `(A : M →ₗ[R] M).det`. -/
@[reducible] noncomputable def det {R : Type*} [comm_ring R]
{M : Type*} [topological_space M] [add_comm_group M] [module R M] (A : M →L[R] M) : R :=
linear_map.det (A : M →ₗ[R] M)
variables
{R : Type*} [comm_ring R]
{M : Type*} [topological_space M] [add_comm_group M]
{M₂ : Type*} [topological_space M₂] [add_comm_group M₂]
{M₃ : Type*} [topological_space M₃] [add_comm_group M₃]
[module R M] [module R M₂] [module R M₃] [has_continuous_const_smul R M₃]
variables [topological_add_group M₂] [has_continuous_const_smul R M₂]
instance : algebra R (M₂ →L[R] M₂) :=
algebra.of_module smul_comp (λ _ _ _, comp_smul _ _ _)
end comm_ring
section restrict_scalars
variables {A M M₂ : Type*} [ring A] [add_comm_group M] [add_comm_group M₂]
[module A M] [module A M₂] [topological_space M] [topological_space M₂]
(R : Type*) [ring R] [module R M] [module R M₂] [linear_map.compatible_smul M M₂ R A]
/-- If `A` is an `R`-algebra, then a continuous `A`-linear map can be interpreted as a continuous
`R`-linear map. We assume `linear_map.compatible_smul M M₂ R A` to match assumptions of
`linear_map.map_smul_of_tower`. -/
def restrict_scalars (f : M →L[A] M₂) : M →L[R] M₂ :=
⟨(f : M →ₗ[A] M₂).restrict_scalars R, f.continuous⟩
variable {R}
@[simp, norm_cast] lemma coe_restrict_scalars (f : M →L[A] M₂) :
(f.restrict_scalars R : M →ₗ[R] M₂) = (f : M →ₗ[A] M₂).restrict_scalars R := rfl
@[simp] lemma coe_restrict_scalars' (f : M →L[A] M₂) : ⇑(f.restrict_scalars R) = f := rfl
@[simp] lemma restrict_scalars_zero : (0 : M →L[A] M₂).restrict_scalars R = 0 := rfl
section
variable [topological_add_group M₂]
@[simp] lemma restrict_scalars_add (f g : M →L[A] M₂) :
(f + g).restrict_scalars R = f.restrict_scalars R + g.restrict_scalars R := rfl
@[simp] lemma restrict_scalars_neg (f : M →L[A] M₂) :
(-f).restrict_scalars R = -f.restrict_scalars R := rfl
end
variables {S : Type*} [ring S] [module S M₂] [has_continuous_const_smul S M₂]
[smul_comm_class A S M₂] [smul_comm_class R S M₂]
@[simp] lemma restrict_scalars_smul (c : S) (f : M →L[A] M₂) :
(c • f).restrict_scalars R = c • f.restrict_scalars R := rfl
variables (A M M₂ R S) [topological_add_group M₂]
/-- `continuous_linear_map.restrict_scalars` as a `linear_map`. See also
`continuous_linear_map.restrict_scalarsL`. -/
def restrict_scalarsₗ : (M →L[A] M₂) →ₗ[S] (M →L[R] M₂) :=
{ to_fun := restrict_scalars R,
map_add' := restrict_scalars_add,
map_smul' := restrict_scalars_smul }
variables {A M M₂ R S}
@[simp] lemma coe_restrict_scalarsₗ : ⇑(restrict_scalarsₗ A M M₂ R S) = restrict_scalars R := rfl
end restrict_scalars
end continuous_linear_map
namespace continuous_linear_equiv
section add_comm_monoid
variables {R₁ : Type*} {R₂ : Type*} {R₃ : Type*} [semiring R₁] [semiring R₂] [semiring R₃]
{σ₁₂ : R₁ →+* R₂} {σ₂₁ : R₂ →+* R₁} [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂]
{σ₂₃ : R₂ →+* R₃} {σ₃₂ : R₃ →+* R₂} [ring_hom_inv_pair σ₂₃ σ₃₂] [ring_hom_inv_pair σ₃₂ σ₂₃]
{σ₁₃ : R₁ →+* R₃} {σ₃₁ : R₃ →+* R₁} [ring_hom_inv_pair σ₁₃ σ₃₁] [ring_hom_inv_pair σ₃₁ σ₁₃]
[ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃] [ring_hom_comp_triple σ₃₂ σ₂₁ σ₃₁]
{M₁ : Type*} [topological_space M₁] [add_comm_monoid M₁]
{M'₁ : Type*} [topological_space M'₁] [add_comm_monoid M'₁]
{M₂ : Type*} [topological_space M₂] [add_comm_monoid M₂]
{M₃ : Type*} [topological_space M₃] [add_comm_monoid M₃]
{M₄ : Type*} [topological_space M₄] [add_comm_monoid M₄]
[module R₁ M₁] [module R₁ M'₁] [module R₂ M₂] [module R₃ M₃]
include σ₂₁
/-- A continuous linear equivalence induces a continuous linear map. -/
def to_continuous_linear_map (e : M₁ ≃SL[σ₁₂] M₂) : M₁ →SL[σ₁₂] M₂ :=
{ cont := e.continuous_to_fun,
..e.to_linear_equiv.to_linear_map }
/-- Coerce continuous linear equivs to continuous linear maps. -/
instance : has_coe (M₁ ≃SL[σ₁₂] M₂) (M₁ →SL[σ₁₂] M₂) := ⟨to_continuous_linear_map⟩
/-- Coerce continuous linear equivs to maps. -/
-- see Note [function coercion]
instance : has_coe_to_fun (M₁ ≃SL[σ₁₂] M₂) (λ _, M₁ → M₂) := ⟨λ f, f⟩
@[simp] theorem coe_def_rev (e : M₁ ≃SL[σ₁₂] M₂) : e.to_continuous_linear_map = e := rfl
theorem coe_apply (e : M₁ ≃SL[σ₁₂] M₂) (b : M₁) : (e : M₁ →SL[σ₁₂] M₂) b = e b := rfl
@[simp] lemma coe_to_linear_equiv (f : M₁ ≃SL[σ₁₂] M₂) : ⇑f.to_linear_equiv = f := rfl
@[simp, norm_cast] lemma coe_coe (e : M₁ ≃SL[σ₁₂] M₂) : ⇑(e : M₁ →SL[σ₁₂] M₂) = e := rfl
lemma to_linear_equiv_injective :
function.injective (to_linear_equiv : (M₁ ≃SL[σ₁₂] M₂) → (M₁ ≃ₛₗ[σ₁₂] M₂))
| ⟨e, _, _⟩ ⟨e', _, _⟩ rfl := rfl
@[ext] lemma ext {f g : M₁ ≃SL[σ₁₂] M₂} (h : (f : M₁ → M₂) = g) : f = g :=
to_linear_equiv_injective $ linear_equiv.ext $ congr_fun h
lemma coe_injective : function.injective (coe : (M₁ ≃SL[σ₁₂] M₂) → (M₁ →SL[σ₁₂] M₂)) :=
λ e e' h, ext $ funext $ continuous_linear_map.ext_iff.1 h
@[simp, norm_cast] lemma coe_inj {e e' : M₁ ≃SL[σ₁₂] M₂} : (e : M₁ →SL[σ₁₂] M₂) = e' ↔ e = e' :=
coe_injective.eq_iff
/-- A continuous linear equivalence induces a homeomorphism. -/
def to_homeomorph (e : M₁ ≃SL[σ₁₂] M₂) : M₁ ≃ₜ M₂ := { to_equiv := e.to_linear_equiv.to_equiv, ..e }
@[simp] lemma coe_to_homeomorph (e : M₁ ≃SL[σ₁₂] M₂) : ⇑e.to_homeomorph = e := rfl
lemma image_closure (e : M₁ ≃SL[σ₁₂] M₂) (s : set M₁) : e '' closure s = closure (e '' s) :=
e.to_homeomorph.image_closure s
lemma preimage_closure (e : M₁ ≃SL[σ₁₂] M₂) (s : set M₂) : e ⁻¹' closure s = closure (e ⁻¹' s) :=
e.to_homeomorph.preimage_closure s
@[simp] lemma is_closed_image (e : M₁ ≃SL[σ₁₂] M₂) {s : set M₁} :
is_closed (e '' s) ↔ is_closed s :=
e.to_homeomorph.is_closed_image
lemma map_nhds_eq (e : M₁ ≃SL[σ₁₂] M₂) (x : M₁) : map e (𝓝 x) = 𝓝 (e x) :=
e.to_homeomorph.map_nhds_eq x
-- Make some straightforward lemmas available to `simp`.
@[simp] lemma map_zero (e : M₁ ≃SL[σ₁₂] M₂) : e (0 : M₁) = 0 := (e : M₁ →SL[σ₁₂] M₂).map_zero
@[simp] lemma map_add (e : M₁ ≃SL[σ₁₂] M₂) (x y : M₁) : e (x + y) = e x + e y :=
(e : M₁ →SL[σ₁₂] M₂).map_add x y
@[simp] lemma map_smulₛₗ (e : M₁ ≃SL[σ₁₂] M₂) (c : R₁) (x : M₁) : e (c • x) = σ₁₂ c • (e x) :=
(e : M₁ →SL[σ₁₂] M₂).map_smulₛₗ c x
omit σ₂₁
@[simp] lemma map_smul [module R₁ M₂] (e : M₁ ≃L[R₁] M₂) (c : R₁) (x : M₁) :
e (c • x) = c • (e x) :=
(e : M₁ →L[R₁] M₂).map_smul c x
include σ₂₁
@[simp] lemma map_eq_zero_iff (e : M₁ ≃SL[σ₁₂] M₂) {x : M₁} : e x = 0 ↔ x = 0 :=
e.to_linear_equiv.map_eq_zero_iff
attribute [continuity]
continuous_linear_equiv.continuous_to_fun continuous_linear_equiv.continuous_inv_fun
@[continuity]
protected lemma continuous (e : M₁ ≃SL[σ₁₂] M₂) : continuous (e : M₁ → M₂) :=
e.continuous_to_fun
protected lemma continuous_on (e : M₁ ≃SL[σ₁₂] M₂) {s : set M₁} : continuous_on (e : M₁ → M₂) s :=
e.continuous.continuous_on
protected lemma continuous_at (e : M₁ ≃SL[σ₁₂] M₂) {x : M₁} : continuous_at (e : M₁ → M₂) x :=
e.continuous.continuous_at
protected lemma continuous_within_at (e : M₁ ≃SL[σ₁₂] M₂) {s : set M₁} {x : M₁} :
continuous_within_at (e : M₁ → M₂) s x :=
e.continuous.continuous_within_at
lemma comp_continuous_on_iff
{α : Type*} [topological_space α] (e : M₁ ≃SL[σ₁₂] M₂) {f : α → M₁} {s : set α} :
continuous_on (e ∘ f) s ↔ continuous_on f s :=
e.to_homeomorph.comp_continuous_on_iff _ _
lemma comp_continuous_iff
{α : Type*} [topological_space α] (e : M₁ ≃SL[σ₁₂] M₂) {f : α → M₁} :
continuous (e ∘ f) ↔ continuous f :=
e.to_homeomorph.comp_continuous_iff
omit σ₂₁
/-- An extensionality lemma for `R ≃L[R] M`. -/
lemma ext₁ [topological_space R₁] {f g : R₁ ≃L[R₁] M₁} (h : f 1 = g 1) : f = g :=
ext $ funext $ λ x, mul_one x ▸ by rw [← smul_eq_mul, map_smul, h, map_smul]
section
variables (R₁ M₁)
/-- The identity map as a continuous linear equivalence. -/
@[refl] protected def refl : M₁ ≃L[R₁] M₁ :=
{ continuous_to_fun := continuous_id,
continuous_inv_fun := continuous_id,
.. linear_equiv.refl R₁ M₁ }
end
@[simp, norm_cast] lemma coe_refl :
↑(continuous_linear_equiv.refl R₁ M₁) = continuous_linear_map.id R₁ M₁ := rfl
@[simp, norm_cast] lemma coe_refl' : ⇑(continuous_linear_equiv.refl R₁ M₁) = id := rfl
/-- The inverse of a continuous linear equivalence as a continuous linear equivalence-/
@[symm] protected def symm (e : M₁ ≃SL[σ₁₂] M₂) : M₂ ≃SL[σ₂₁] M₁ :=
{ continuous_to_fun := e.continuous_inv_fun,
continuous_inv_fun := e.continuous_to_fun,
.. e.to_linear_equiv.symm }
include σ₂₁
@[simp] lemma symm_to_linear_equiv (e : M₁ ≃SL[σ₁₂] M₂) :
e.symm.to_linear_equiv = e.to_linear_equiv.symm :=
by { ext, refl }
@[simp] lemma symm_to_homeomorph (e : M₁ ≃SL[σ₁₂] M₂) :
e.to_homeomorph.symm = e.symm.to_homeomorph :=
rfl
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def simps.apply (h : M₁ ≃SL[σ₁₂] M₂) : M₁ → M₂ := h
/-- See Note [custom simps projection] -/
def simps.symm_apply (h : M₁ ≃SL[σ₁₂] M₂) : M₂ → M₁ := h.symm
initialize_simps_projections continuous_linear_equiv
(to_linear_equiv_to_fun → apply, to_linear_equiv_inv_fun → symm_apply)
lemma symm_map_nhds_eq (e : M₁ ≃SL[σ₁₂] M₂) (x : M₁) : map e.symm (𝓝 (e x)) = 𝓝 x :=
e.to_homeomorph.symm_map_nhds_eq x
omit σ₂₁
include σ₂₁ σ₃₂ σ₃₁
/-- The composition of two continuous linear equivalences as a continuous linear equivalence. -/
@[trans] protected def trans (e₁ : M₁ ≃SL[σ₁₂] M₂) (e₂ : M₂ ≃SL[σ₂₃] M₃) : M₁ ≃SL[σ₁₃] M₃ :=
{ continuous_to_fun := e₂.continuous_to_fun.comp e₁.continuous_to_fun,
continuous_inv_fun := e₁.continuous_inv_fun.comp e₂.continuous_inv_fun,
.. e₁.to_linear_equiv.trans e₂.to_linear_equiv }
include σ₁₃
@[simp] lemma trans_to_linear_equiv (e₁ : M₁ ≃SL[σ₁₂] M₂) (e₂ : M₂ ≃SL[σ₂₃] M₃) :
(e₁.trans e₂).to_linear_equiv = e₁.to_linear_equiv.trans e₂.to_linear_equiv :=
by { ext, refl }
omit σ₁₃ σ₂₁ σ₃₂ σ₃₁
/-- Product of two continuous linear equivalences. The map comes from `equiv.prod_congr`. -/
def prod [module R₁ M₂] [module R₁ M₃] [module R₁ M₄] (e : M₁ ≃L[R₁] M₂) (e' : M₃ ≃L[R₁] M₄) :
(M₁ × M₃) ≃L[R₁] (M₂ × M₄) :=
{ continuous_to_fun := e.continuous_to_fun.prod_map e'.continuous_to_fun,
continuous_inv_fun := e.continuous_inv_fun.prod_map e'.continuous_inv_fun,
.. e.to_linear_equiv.prod e'.to_linear_equiv }
@[simp, norm_cast] lemma prod_apply [module R₁ M₂] [module R₁ M₃] [module R₁ M₄] (e : M₁ ≃L[R₁] M₂)
(e' : M₃ ≃L[R₁] M₄) (x) :
e.prod e' x = (e x.1, e' x.2) := rfl
@[simp, norm_cast] lemma coe_prod [module R₁ M₂] [module R₁ M₃] [module R₁ M₄] (e : M₁ ≃L[R₁] M₂)
(e' : M₃ ≃L[R₁] M₄) :
(e.prod e' : (M₁ × M₃) →L[R₁] (M₂ × M₄)) = (e : M₁ →L[R₁] M₂).prod_map (e' : M₃ →L[R₁] M₄) :=
rfl
include σ₂₁
theorem bijective (e : M₁ ≃SL[σ₁₂] M₂) : function.bijective e :=
e.to_linear_equiv.to_equiv.bijective
theorem injective (e : M₁ ≃SL[σ₁₂] M₂) : function.injective e :=
e.to_linear_equiv.to_equiv.injective
theorem surjective (e : M₁ ≃SL[σ₁₂] M₂) : function.surjective e :=
e.to_linear_equiv.to_equiv.surjective
include σ₃₂ σ₃₁ σ₁₃
@[simp] theorem trans_apply (e₁ : M₁ ≃SL[σ₁₂] M₂) (e₂ : M₂ ≃SL[σ₂₃] M₃) (c : M₁) :
(e₁.trans e₂) c = e₂ (e₁ c) :=
rfl
omit σ₃₂ σ₃₁ σ₁₃
@[simp] theorem apply_symm_apply (e : M₁ ≃SL[σ₁₂] M₂) (c : M₂) : e (e.symm c) = c :=
e.1.right_inv c
@[simp] theorem symm_apply_apply (e : M₁ ≃SL[σ₁₂] M₂) (b : M₁) : e.symm (e b) = b := e.1.left_inv b
include σ₁₂ σ₂₃ σ₁₃ σ₃₁
@[simp] theorem symm_trans_apply (e₁ : M₂ ≃SL[σ₂₁] M₁) (e₂ : M₃ ≃SL[σ₃₂] M₂) (c : M₁) :
(e₂.trans e₁).symm c = e₂.symm (e₁.symm c) :=
rfl
omit σ₁₂ σ₂₃ σ₁₃ σ₃₁
@[simp] theorem symm_image_image (e : M₁ ≃SL[σ₁₂] M₂) (s : set M₁) : e.symm '' (e '' s) = s :=
e.to_linear_equiv.to_equiv.symm_image_image s
@[simp] theorem image_symm_image (e : M₁ ≃SL[σ₁₂] M₂) (s : set M₂) : e '' (e.symm '' s) = s :=
e.symm.symm_image_image s
include σ₃₂ σ₃₁
@[simp, norm_cast]
lemma comp_coe (f : M₁ ≃SL[σ₁₂] M₂) (f' : M₂ ≃SL[σ₂₃] M₃) :
(f' : M₂ →SL[σ₂₃] M₃).comp (f : M₁ →SL[σ₁₂] M₂) = (f.trans f' : M₁ →SL[σ₁₃] M₃) :=
rfl
omit σ₃₂ σ₃₁ σ₂₁
@[simp] theorem coe_comp_coe_symm (e : M₁ ≃SL[σ₁₂] M₂) :
(e : M₁ →SL[σ₁₂] M₂).comp (e.symm : M₂ →SL[σ₂₁] M₁) = continuous_linear_map.id R₂ M₂ :=
continuous_linear_map.ext e.apply_symm_apply
@[simp] theorem coe_symm_comp_coe (e : M₁ ≃SL[σ₁₂] M₂) :
(e.symm : M₂ →SL[σ₂₁] M₁).comp (e : M₁ →SL[σ₁₂] M₂) = continuous_linear_map.id R₁ M₁ :=
continuous_linear_map.ext e.symm_apply_apply
include σ₂₁
@[simp] lemma symm_comp_self (e : M₁ ≃SL[σ₁₂] M₂) :
(e.symm : M₂ → M₁) ∘ (e : M₁ → M₂) = id :=
by{ ext x, exact symm_apply_apply e x }
@[simp] lemma self_comp_symm (e : M₁ ≃SL[σ₁₂] M₂) :
(e : M₁ → M₂) ∘ (e.symm : M₂ → M₁) = id :=
by{ ext x, exact apply_symm_apply e x }
@[simp] theorem symm_symm (e : M₁ ≃SL[σ₁₂] M₂) : e.symm.symm = e :=
by { ext x, refl }
omit σ₂₁
@[simp] lemma refl_symm :
(continuous_linear_equiv.refl R₁ M₁).symm = continuous_linear_equiv.refl R₁ M₁ :=
rfl
include σ₂₁
theorem symm_symm_apply (e : M₁ ≃SL[σ₁₂] M₂) (x : M₁) : e.symm.symm x = e x :=
rfl
lemma symm_apply_eq (e : M₁ ≃SL[σ₁₂] M₂) {x y} : e.symm x = y ↔ x = e y :=
e.to_linear_equiv.symm_apply_eq
lemma eq_symm_apply (e : M₁ ≃SL[σ₁₂] M₂) {x y} : y = e.symm x ↔ e y = x :=
e.to_linear_equiv.eq_symm_apply
protected lemma image_eq_preimage (e : M₁ ≃SL[σ₁₂] M₂) (s : set M₁) : e '' s = e.symm ⁻¹' s :=
e.to_linear_equiv.to_equiv.image_eq_preimage s
protected lemma image_symm_eq_preimage (e : M₁ ≃SL[σ₁₂] M₂) (s : set M₂) : e.symm '' s = e ⁻¹' s :=
by rw [e.symm.image_eq_preimage, e.symm_symm]
@[simp] protected lemma symm_preimage_preimage (e : M₁ ≃SL[σ₁₂] M₂) (s : set M₂) :
e.symm ⁻¹' (e ⁻¹' s) = s := e.to_linear_equiv.to_equiv.symm_preimage_preimage s
@[simp] protected lemma preimage_symm_preimage (e : M₁ ≃SL[σ₁₂] M₂) (s : set M₁) :
e ⁻¹' (e.symm ⁻¹' s) = s := e.symm.symm_preimage_preimage s
protected lemma uniform_embedding {E₁ E₂ : Type*} [uniform_space E₁] [uniform_space E₂]
[add_comm_group E₁] [add_comm_group E₂] [module R₁ E₁] [module R₂ E₂]
[uniform_add_group E₁] [uniform_add_group E₂]
(e : E₁ ≃SL[σ₁₂] E₂) :
uniform_embedding e :=
e.to_linear_equiv.to_equiv.uniform_embedding
e.to_continuous_linear_map.uniform_continuous
e.symm.to_continuous_linear_map.uniform_continuous
protected lemma _root_.linear_equiv.uniform_embedding {E₁ E₂ : Type*} [uniform_space E₁]
[uniform_space E₂] [add_comm_group E₁] [add_comm_group E₂] [module R₁ E₁] [module R₂ E₂]
[uniform_add_group E₁] [uniform_add_group E₂]
(e : E₁ ≃ₛₗ[σ₁₂] E₂) (h₁ : continuous e) (h₂ : continuous e.symm) :
uniform_embedding e :=
continuous_linear_equiv.uniform_embedding
({ continuous_to_fun := h₁,
continuous_inv_fun := h₂,
.. e } : E₁ ≃SL[σ₁₂] E₂)
omit σ₂₁
/-- Create a `continuous_linear_equiv` from two `continuous_linear_map`s that are
inverse of each other. -/
def equiv_of_inverse (f₁ : M₁ →SL[σ₁₂] M₂) (f₂ : M₂ →SL[σ₂₁] M₁) (h₁ : function.left_inverse f₂ f₁)
(h₂ : function.right_inverse f₂ f₁) :
M₁ ≃SL[σ₁₂] M₂ :=
{ to_fun := f₁,
continuous_to_fun := f₁.continuous,
inv_fun := f₂,
continuous_inv_fun := f₂.continuous,
left_inv := h₁,
right_inv := h₂,
.. f₁ }
include σ₂₁
@[simp] lemma equiv_of_inverse_apply (f₁ : M₁ →SL[σ₁₂] M₂) (f₂ h₁ h₂ x) :
equiv_of_inverse f₁ f₂ h₁ h₂ x = f₁ x :=
rfl
@[simp] lemma symm_equiv_of_inverse (f₁ : M₁ →SL[σ₁₂] M₂) (f₂ h₁ h₂) :
(equiv_of_inverse f₁ f₂ h₁ h₂).symm = equiv_of_inverse f₂ f₁ h₂ h₁ :=
rfl
omit σ₂₁
variable (M₁)
/-- The continuous linear equivalences from `M` to itself form a group under composition. -/
instance automorphism_group : group (M₁ ≃L[R₁] M₁) :=
{ mul := λ f g, g.trans f,
one := continuous_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} }
variables {M₁} {R₄ : Type*} [semiring R₄] [module R₄ M₄]
{σ₃₄ : R₃ →+* R₄} {σ₄₃ : R₄ →+* R₃} [ring_hom_inv_pair σ₃₄ σ₄₃] [ring_hom_inv_pair σ₄₃ σ₃₄]
{σ₂₄ : R₂ →+* R₄} {σ₁₄ : R₁ →+* R₄}
[ring_hom_comp_triple σ₂₁ σ₁₄ σ₂₄] [ring_hom_comp_triple σ₂₄ σ₄₃ σ₂₃]
[ring_hom_comp_triple σ₁₃ σ₃₄ σ₁₄]
include σ₂₁ σ₃₄ σ₂₃ σ₂₄ σ₁₃
/-- A pair of continuous (semi)linear equivalences generates an equivalence between the spaces of
continuous linear maps. See also `continuous_linear_equiv.arrow_congr`. -/
@[simps] def arrow_congr_equiv (e₁₂ : M₁ ≃SL[σ₁₂] M₂) (e₄₃ : M₄ ≃SL[σ₄₃] M₃) :
(M₁ →SL[σ₁₄] M₄) ≃ (M₂ →SL[σ₂₃] M₃) :=
{ to_fun := λ f, (e₄₃ : M₄ →SL[σ₄₃] M₃).comp (f.comp (e₁₂.symm : M₂ →SL[σ₂₁] M₁)),
inv_fun := λ f, (e₄₃.symm : M₃ →SL[σ₃₄] M₄).comp (f.comp (e₁₂ : M₁ →SL[σ₁₂] M₂)),
left_inv := λ f, continuous_linear_map.ext $ λ x,
by simp only [continuous_linear_map.comp_apply, symm_apply_apply, coe_coe],
right_inv := λ f, continuous_linear_map.ext $ λ x,
by simp only [continuous_linear_map.comp_apply, apply_symm_apply, coe_coe] }
end add_comm_monoid
section add_comm_group
variables {R : Type*} [semiring R]
{M : Type*} [topological_space M] [add_comm_group M]
{M₂ : Type*} [topological_space M₂] [add_comm_group M₂]
{M₃ : Type*} [topological_space M₃] [add_comm_group M₃]
{M₄ : Type*} [topological_space M₄] [add_comm_group M₄]
[module R M] [module R M₂] [module R M₃] [module R M₄]
variables [topological_add_group M₄]
/-- Equivalence given by a block lower diagonal matrix. `e` and `e'` are diagonal square blocks,
and `f` is a rectangular block below the diagonal. -/
def skew_prod (e : M ≃L[R] M₂) (e' : M₃ ≃L[R] M₄) (f : M →L[R] M₄) :
(M × M₃) ≃L[R] M₂ × M₄ :=
{ continuous_to_fun := (e.continuous_to_fun.comp continuous_fst).prod_mk
((e'.continuous_to_fun.comp continuous_snd).add $ f.continuous.comp continuous_fst),
continuous_inv_fun := (e.continuous_inv_fun.comp continuous_fst).prod_mk
(e'.continuous_inv_fun.comp $ continuous_snd.sub $ f.continuous.comp $
e.continuous_inv_fun.comp continuous_fst),
.. e.to_linear_equiv.skew_prod e'.to_linear_equiv ↑f }
@[simp] lemma skew_prod_apply (e : M ≃L[R] M₂) (e' : M₃ ≃L[R] M₄) (f : M →L[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 (e : M ≃L[R] M₂) (e' : M₃ ≃L[R] M₄) (f : M →L[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 ring
variables {R : Type*} [ring R] {R₂ : Type*} [ring R₂]
{M : Type*} [topological_space M] [add_comm_group M] [module R M]
{M₂ : Type*} [topological_space M₂] [add_comm_group M₂] [module R₂ M₂]
variables {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R} [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂]
include σ₂₁
@[simp] lemma map_sub (e : M ≃SL[σ₁₂] M₂) (x y : M) : e (x - y) = e x - e y :=
(e : M →SL[σ₁₂] M₂).map_sub x y
@[simp] lemma map_neg (e : M ≃SL[σ₁₂] M₂) (x : M) : e (-x) = -e x := (e : M →SL[σ₁₂] M₂).map_neg x
omit σ₂₁
section
/-! The next theorems cover the identification between `M ≃L[𝕜] M`and the group of units of the ring
`M →L[R] M`. -/
variables [topological_add_group M]
/-- An invertible continuous linear map `f` determines a continuous equivalence from `M` to itself.
-/
def of_unit (f : (M →L[R] M)ˣ) : (M ≃L[R] M) :=
{ to_linear_equiv :=
{ to_fun := f.val,
map_add' := by simp,
map_smul' := by simp,
inv_fun := f.inv,
left_inv := λ x, show (f.inv * f.val) x = x, by {rw f.inv_val, simp},
right_inv := λ x, show (f.val * f.inv) x = x, by {rw f.val_inv, simp}, },
continuous_to_fun := f.val.continuous,
continuous_inv_fun := f.inv.continuous }
/-- A continuous equivalence from `M` to itself determines an invertible continuous linear map. -/
def to_unit (f : (M ≃L[R] M)) : (M →L[R] M)ˣ :=
{ val := f,
inv := f.symm,
val_inv := by {ext, simp},
inv_val := by {ext, simp} }
variables (R M)
/-- The units of the algebra of continuous `R`-linear endomorphisms of `M` is multiplicatively
equivalent to the type of continuous linear equivalences between `M` and itself. -/
def units_equiv : (M →L[R] M)ˣ ≃* (M ≃L[R] M) :=
{ to_fun := of_unit,
inv_fun := to_unit,
left_inv := λ f, by {ext, refl},
right_inv := λ f, by {ext, refl},
map_mul' := λ x y, by {ext, refl} }
@[simp] lemma units_equiv_apply (f : (M →L[R] M)ˣ) (x : M) :
units_equiv R M f x = f x := rfl
end
section
variables (R) [topological_space R] [has_continuous_mul R]
/-- Continuous linear equivalences `R ≃L[R] R` are enumerated by `Rˣ`. -/
def units_equiv_aut : Rˣ ≃ (R ≃L[R] R) :=
{ to_fun := λ u, equiv_of_inverse
(continuous_linear_map.smul_right (1 : R →L[R] R) ↑u)
(continuous_linear_map.smul_right (1 : R →L[R] R) ↑u⁻¹)
(λ x, by simp) (λ x, by simp),
inv_fun := λ e, ⟨e 1, e.symm 1,
by rw [← smul_eq_mul, ← map_smul, smul_eq_mul, mul_one, symm_apply_apply],
by rw [← smul_eq_mul, ← map_smul, smul_eq_mul, mul_one, apply_symm_apply]⟩,
left_inv := λ u, units.ext $ by simp,
right_inv := λ e, ext₁ $ by simp }
variable {R}
@[simp] lemma units_equiv_aut_apply (u : Rˣ) (x : R) : units_equiv_aut R u x = x * u := rfl
@[simp] lemma units_equiv_aut_apply_symm (u : Rˣ) (x : R) :
(units_equiv_aut R u).symm x = x * ↑u⁻¹ := rfl
@[simp] lemma units_equiv_aut_symm_apply (e : R ≃L[R] R) :
↑((units_equiv_aut R).symm e) = e 1 :=
rfl
end
variables [module R M₂] [topological_add_group M]
open _root_.continuous_linear_map (id fst snd subtype_val mem_ker)
/-- A pair of continuous linear maps such that `f₁ ∘ f₂ = id` generates a continuous
linear equivalence `e` between `M` and `M₂ × f₁.ker` such that `(e x).2 = x` for `x ∈ f₁.ker`,
`(e x).1 = f₁ x`, and `(e (f₂ y)).2 = 0`. The map is given by `e x = (f₁ x, x - f₂ (f₁ x))`. -/
def equiv_of_right_inverse (f₁ : M →L[R] M₂) (f₂ : M₂ →L[R] M) (h : function.right_inverse f₂ f₁) :
M ≃L[R] M₂ × f₁.ker :=
equiv_of_inverse (f₁.prod (f₁.proj_ker_of_right_inverse f₂ h)) (f₂.coprod (subtype_val f₁.ker))
(λ x, by simp)
(λ ⟨x, y⟩, by simp [h x])
@[simp] lemma fst_equiv_of_right_inverse (f₁ : M →L[R] M₂) (f₂ : M₂ →L[R] M)
(h : function.right_inverse f₂ f₁) (x : M) :
(equiv_of_right_inverse f₁ f₂ h x).1 = f₁ x := rfl
@[simp] lemma snd_equiv_of_right_inverse (f₁ : M →L[R] M₂) (f₂ : M₂ →L[R] M)
(h : function.right_inverse f₂ f₁) (x : M) :
((equiv_of_right_inverse f₁ f₂ h x).2 : M) = x - f₂ (f₁ x) := rfl
@[simp] lemma equiv_of_right_inverse_symm_apply (f₁ : M →L[R] M₂) (f₂ : M₂ →L[R] M)
(h : function.right_inverse f₂ f₁) (y : M₂ × f₁.ker) :
(equiv_of_right_inverse f₁ f₂ h).symm y = f₂ y.1 + y.2 := rfl
end ring
section
variables (ι R M : Type*) [unique ι] [semiring R] [add_comm_monoid M] [module R M]
[topological_space M]
/-- If `ι` has a unique element, then `ι → M` is continuously linear equivalent to `M`. -/
def fun_unique : (ι → M) ≃L[R] M :=
{ to_linear_equiv := linear_equiv.fun_unique ι R M,
.. homeomorph.fun_unique ι M }
variables {ι R M}
@[simp] lemma coe_fun_unique : ⇑(fun_unique ι R M) = function.eval default := rfl
@[simp] lemma coe_fun_unique_symm : ⇑(fun_unique ι R M).symm = function.const ι := rfl
variables (R M)
/-- Continuous linear equivalence between dependent functions `Π i : fin 2, M i` and `M 0 × M 1`. -/
@[simps { fully_applied := ff }]
def pi_fin_two (M : fin 2 → Type*) [Π i, add_comm_monoid (M i)] [Π i, module R (M i)]
[Π i, topological_space (M i)] :
(Π i, M i) ≃L[R] M 0 × M 1 :=
{ to_linear_equiv := linear_equiv.pi_fin_two R M, .. homeomorph.pi_fin_two M }
/-- Continuous linear equivalence between vectors in `M² = fin 2 → M` and `M × M`. -/
@[simps { fully_applied := ff }]
def fin_two_arrow : (fin 2 → M) ≃L[R] M × M :=
{ to_linear_equiv := linear_equiv.fin_two_arrow R M, .. pi_fin_two R (λ _, M) }
end
@[simp] lemma det_coe_symm {R : Type*} [field R]
{M : Type*} [topological_space M] [add_comm_group M] [module R M] (A : M ≃L[R] M) :
(A.symm : M →L[R] M).det = (A : M →L[R] M).det ⁻¹ :=
linear_equiv.det_coe_symm A.to_linear_equiv
end continuous_linear_equiv
namespace continuous_linear_map
open_locale classical
variables {R : Type*} {M : Type*} {M₂ : Type*} [topological_space M] [topological_space M₂]
section
variables [semiring R]
variables [add_comm_monoid M₂] [module R M₂]
variables [add_comm_monoid M] [module R M]
/-- Introduce a function `inverse` from `M →L[R] M₂` to `M₂ →L[R] M`, which sends `f` to `f.symm` if
`f` is a continuous linear equivalence and to `0` otherwise. This definition is somewhat ad hoc,
but one needs a fully (rather than partially) defined inverse function for some purposes, including
for calculus. -/
noncomputable def inverse : (M →L[R] M₂) → (M₂ →L[R] M) :=
λ f, if h : ∃ (e : M ≃L[R] M₂), (e : M →L[R] M₂) = f then ((classical.some h).symm : M₂ →L[R] M)
else 0
/-- By definition, if `f` is invertible then `inverse f = f.symm`. -/
@[simp] lemma inverse_equiv (e : M ≃L[R] M₂) : inverse (e : M →L[R] M₂) = e.symm :=
begin
have h : ∃ (e' : M ≃L[R] M₂), (e' : M →L[R] M₂) = ↑e := ⟨e, rfl⟩,
simp only [inverse, dif_pos h],
congr,
exact_mod_cast (classical.some_spec h)
end
/-- By definition, if `f` is not invertible then `inverse f = 0`. -/
@[simp] lemma inverse_non_equiv (f : M →L[R] M₂) (h : ¬∃ (e' : M ≃L[R] M₂), ↑e' = f) :
inverse f = 0 :=
dif_neg h
end
section
variables [ring R]
variables [add_comm_group M] [topological_add_group M] [module R M]
variables [add_comm_group M₂] [module R M₂]
@[simp] lemma ring_inverse_equiv (e : M ≃L[R] M) :
ring.inverse ↑e = inverse (e : M →L[R] M) :=
begin
suffices :
ring.inverse ((((continuous_linear_equiv.units_equiv _ _).symm e) : M →L[R] M)) = inverse ↑e,
{ convert this },
simp,
refl,
end
/-- The function `continuous_linear_equiv.inverse` can be written in terms of `ring.inverse` for the
ring of self-maps of the domain. -/
lemma to_ring_inverse (e : M ≃L[R] M₂) (f : M →L[R] M₂) :
inverse f = (ring.inverse ((e.symm : (M₂ →L[R] M)).comp f)) ∘L ↑e.symm :=
begin
by_cases h₁ : ∃ (e' : M ≃L[R] M₂), ↑e' = f,
{ obtain ⟨e', he'⟩ := h₁,
rw ← he',
change _ = (ring.inverse ↑(e'.trans e.symm)) ∘L ↑e.symm,
ext,
simp },
{ suffices : ¬is_unit ((e.symm : M₂ →L[R] M).comp f),
{ simp [this, h₁] },
contrapose! h₁,
rcases h₁ with ⟨F, hF⟩,
use (continuous_linear_equiv.units_equiv _ _ F).trans e,
ext,
dsimp, rw [coe_fn_coe_base' F, hF], simp }
end
lemma ring_inverse_eq_map_inverse : ring.inverse = @inverse R M M _ _ _ _ _ _ _ :=
begin
ext,
simp [to_ring_inverse (continuous_linear_equiv.refl R M)],
end
end
end continuous_linear_map
namespace submodule
variables
{R : Type*} [ring R]
{M : Type*} [topological_space M] [add_comm_group M] [module R M]
{M₂ : Type*} [topological_space M₂] [add_comm_group M₂] [module R M₂]
open continuous_linear_map
/-- A submodule `p` is called *complemented* if there exists a continuous projection `M →ₗ[R] p`. -/
def closed_complemented (p : submodule R M) : Prop := ∃ f : M →L[R] p, ∀ x : p, f x = x
lemma closed_complemented.has_closed_complement {p : submodule R M} [t1_space p]
(h : closed_complemented p) :
∃ (q : submodule R M) (hq : is_closed (q : set M)), is_compl p q :=
exists.elim h $ λ f hf, ⟨f.ker, f.is_closed_ker, linear_map.is_compl_of_proj hf⟩
protected lemma closed_complemented.is_closed [topological_add_group M] [t1_space M]
{p : submodule R M} (h : closed_complemented p) :
is_closed (p : set M) :=
begin
rcases h with ⟨f, hf⟩,
have : ker (id R M - (subtype_val p).comp f) = p := linear_map.ker_id_sub_eq_of_proj hf,
exact this ▸ (is_closed_ker _)
end
@[simp] lemma closed_complemented_bot : closed_complemented (⊥ : submodule R M) :=
⟨0, λ x, by simp only [zero_apply, eq_zero_of_bot_submodule x]⟩
@[simp] lemma closed_complemented_top : closed_complemented (⊤ : submodule R M) :=
⟨(id R M).cod_restrict ⊤ (λ x, trivial), λ x, subtype.ext_iff_val.2 $ by simp⟩
end submodule
lemma continuous_linear_map.closed_complemented_ker_of_right_inverse {R : Type*} [ring R]
{M : Type*} [topological_space M] [add_comm_group M]
{M₂ : Type*} [topological_space M₂] [add_comm_group M₂] [module R M] [module R M₂]
[topological_add_group M] (f₁ : M →L[R] M₂) (f₂ : M₂ →L[R] M)
(h : function.right_inverse f₂ f₁) :
f₁.ker.closed_complemented :=
⟨f₁.proj_ker_of_right_inverse f₂ h, f₁.proj_ker_of_right_inverse_apply_idem f₂ h⟩
section quotient
namespace submodule
variables {R M : Type*} [ring R] [add_comm_group M] [module R M] [topological_space M]
(S : submodule R M)
lemma is_open_map_mkq [topological_add_group M] : is_open_map S.mkq :=
quotient_add_group.is_open_map_coe S.to_add_subgroup
instance topological_add_group_quotient [topological_add_group M] :
topological_add_group (M ⧸ S) :=
topological_add_group_quotient S.to_add_subgroup
instance has_continuous_smul_quotient [topological_space R] [topological_add_group M]
[has_continuous_smul R M] :
has_continuous_smul R (M ⧸ S) :=
begin
split,
have quot : quotient_map (λ au : R × M, (au.1, S.mkq au.2)),
from is_open_map.to_quotient_map
(is_open_map.id.prod S.is_open_map_mkq)
(continuous_id.prod_map continuous_quot_mk)
(function.surjective_id.prod_map $ surjective_quot_mk _),
rw quot.continuous_iff,
exact continuous_quot_mk.comp continuous_smul
end
instance t3_quotient_of_is_closed [topological_add_group M] [is_closed (S : set M)] :
t3_space (M ⧸ S) :=
begin
letI : is_closed (S.to_add_subgroup : set M) := ‹_›,
exact S.to_add_subgroup.t3_quotient_of_is_closed
end
end submodule
end quotient
|
79be8cbfb5c5b21d85352adeb1a23c628851ab65 | b147e1312077cdcfea8e6756207b3fa538982e12 | /tactic/rcases.lean | cfa1d7776739b8bc0d86d6538a8d1f3048d05d67 | [
"Apache-2.0"
] | permissive | SzJS/mathlib | 07836ee708ca27cd18347e1e11ce7dd5afb3e926 | 23a5591fca0d43ee5d49d89f6f0ee07a24a6ca29 | refs/heads/master | 1,584,980,332,064 | 1,532,063,841,000 | 1,532,063,841,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,688 | 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 tactic.cache
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.
-/
@[reducible] def list_Sigma := list
@[reducible] def list_Pi := list
local notation `listΣ` := list_Sigma
local notation `listΠ` := list_Pi
@[reducible] meta def goals := list expr
inductive rcases_patt : Type
| one : name → rcases_patt
| many : listΣ (listΠ rcases_patt) → rcases_patt
instance rcases_patt.inhabited : inhabited rcases_patt :=
⟨rcases_patt.one `_⟩
def rcases_patt.name : rcases_patt → name
| (rcases_patt.one n) := n
| _ := `_
meta instance rcases_patt.has_reflect : has_reflect rcases_patt
| (rcases_patt.one n) := `(_)
| (rcases_patt.many l) := `(λ l, rcases_patt.many l).subst $
by haveI := rcases_patt.has_reflect; exact list.reflect l
/--
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 ids := ([], [])
| 1 [] := ([`_], [default _])
| 1 [id] := ([id.name], [id])
-- 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 ids := ([`_], [rcases_patt.many [ids]])
| (n+1) ids :=
let (ns, ps) := rcases.process_constructor n ids.tail,
p := ids.head in
(p.name :: ns, p :: ps)
meta def rcases.process_constructors (params : nat) :
listΣ name → listΣ (listΠ rcases_patt) →
tactic (dlist name × listΣ (name × listΠ rcases_patt))
| [] ids := pure (dlist.empty, [])
| (c::cs) ids := do
fn ← mk_const c,
n ← get_arity fn,
let (h, t) := by from match cs, ids.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.many ids], [])
| _, _ := (ids.head, ids.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)
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)
| _ _ := []
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))
meta mutual def rcases_core, rcases.continue
with rcases_core : listΣ (listΠ rcases_patt) → expr → tactic goals
| ids e := do
(t, e) ← get_local_and_type e,
t ← whnf t,
env ← get_env,
let I := t.get_app_fn.const_name,
when (¬env.is_inductive I) $
fail format!"rcases tactic failed, {e} 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 ids,
l ← cases_core e ids.to_list,
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.
list.join <$> (align (λ (a : name × _) (b : _ × name × _), a.1 = b.2.1) r (gs.zip l)).mmap
(λ⟨⟨_, ps⟩, g, _, hs, _⟩,
set_goals [g] >> rcases.continue (ps.zip hs))
with rcases.continue : listΠ (rcases_patt × expr) → tactic goals
| [] := get_goals
| ((rcases_patt.many ids, e) :: l) := do
gs ← rcases_core ids e,
list.join <$> gs.mmap (λ g, set_goals [g] >> rcases.continue l)
| ((rcases_patt.one `rfl, e) :: l) := do
(t, e) ← get_local_and_type e,
subst e,
rcases.continue l
-- 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.
| (_ :: l) := rcases.continue l
meta def rcases (p : pexpr) (ids : list (list rcases_patt)) : tactic unit :=
do e ← i_to_expr p,
if e.is_local_constant then
focus1 (rcases_core ids e >>= set_goals)
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,
return ()),
h ← tactic.intro1,
focus1 (rcases_core ids h >>= set_goals)
meta def rintro (ids : list rcases_patt) : tactic unit :=
do l ← ids.mmap (λ id, do
e ← intro id.name,
return (id, e)),
focus1 (rcases.continue l >>= set_goals)
end tactic
|
8814437e87fb74c1e845341a422fd06fc4fd84a9 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/tactic/transform_decl.lean | d76cd58479a3d621f55181fd32b5fda88e9b91f7 | [
"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 | 7,898 | lean | /-
Copyright (c) 2017 Mario Carneiro All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn
-/
import tactic.core
namespace tactic
/-- `copy_attribute' attr_name src tgt p d_name` copy (user) attribute `attr_name` from
`src` to `tgt` if it is defined for `src`; unlike `copy_attribute` the primed version also copies
the parameter of the user attribute, in the user attribute case. Make it persistent if `p` is
`tt`; if `p` is `none`, the copied attribute is made persistent iff it is persistent on `src` -/
meta def copy_attribute' (attr_name : name) (src : name) (tgt : name) (p : option bool := none) :
tactic unit := do
get_decl tgt <|> fail!"unknown declaration {tgt}",
-- if the source doesn't have the attribute we do not error and simply return
mwhen (succeeds (has_attribute attr_name src)) $
do (p', prio) ← has_attribute attr_name src,
let p := p.get_or_else p',
s ← try_or_report_error (set_basic_attribute attr_name tgt p prio),
sum.inr msg ← return s | skip,
if msg =
(format!("set_basic_attribute tactic failed, '{attr_name}' " ++
"is not a basic attribute")).to_string
then do
user_attr_const ← (get_user_attribute_name attr_name >>= mk_const),
tac ← eval_pexpr (tactic unit)
``(user_attribute.get_param_untyped %%user_attr_const %%src >>=
λ x, user_attribute.set_untyped %%user_attr_const %%tgt x %%p %%prio),
tac
else fail msg
open expr
/-- Auxilliary function for `additive_test`. The bool argument *only* matters when applied
to exactly a constant. -/
meta def additive_test_aux (f : name → option name) (ignore : name_map $ list ℕ) :
bool → expr → bool
| b (var n) := tt
| b (sort l) := tt
| b (const n ls) := b || (f n).is_some
| b (mvar n m t) := tt
| b (local_const n m bi t) := tt
| b (app e f) := additive_test_aux tt e &&
-- this might be inefficient.
-- If it becomes a performance problem: we can give this info for the recursive call to `e`.
match ignore.find e.get_app_fn.const_name with
| some l := if e.get_app_num_args + 1 ∈ l then tt else additive_test_aux ff f
| none := additive_test_aux ff f
end
| b (lam n bi e t) := additive_test_aux ff t
| b (pi n bi e t) := additive_test_aux ff t
| b (elet n g e f) := additive_test_aux ff e && additive_test_aux ff f
| b (macro d args) := tt
/--
`additive_test f replace_all ignore e` tests whether the expression `e` contains no constant
`nm` that is not applied to any arguments, and such that `f nm = none`.
This is used in `@[to_additive]` for deciding which subexpressions to transform: we only transform
constants if `additive_test` applied to their first argument returns `tt`.
This means we will replace expression applied to e.g. `α` or `α × β`, but not when applied to
e.g. `ℕ` or `ℝ × α`.
`f` is the dictionary of declarations that are in the `to_additive` dictionary.
We ignore all arguments specified in the `name_map` `ignore`.
If `replace_all` is `tt` the test always return `tt`.
-/
meta def additive_test (f : name → option name) (replace_all : bool) (ignore : name_map $ list ℕ)
(e : expr) : bool :=
if replace_all then tt else additive_test_aux f ignore ff e
/-- transform the declaration `src` and all declarations `pre._proof_i` occurring in `src`
using the dictionary `f`.
`replace_all`, `trace`, `ignore` and `reorder` are configuration options.
`pre` is the declaration that got the `@[to_additive]` attribute and `tgt_pre` is the target of this
declaration. -/
meta def transform_decl_with_prefix_fun_aux (f : name → option name)
(replace_all trace : bool) (relevant : name_map ℕ) (ignore reorder : name_map $ list ℕ)
(pre tgt_pre : name) : name → command :=
λ src,
do
-- if this declaration is not `pre` or an internal declaration, we do nothing.
tt ← return (src = pre ∨ src.is_internal : bool) |
if (f src).is_some then skip else fail!("@[to_additive] failed.
The declaration {pre} depends on the declaration {src} which is in the namespace {pre}, but " ++
"does not have the `@[to_additive]` attribute. This is not supported. Workaround: move {src} to " ++
"a different namespace."),
env ← get_env,
-- we find the additive name of `src`
let tgt := src.map_prefix (λ n, if n = pre then some tgt_pre else none),
-- we skip if we already transformed this declaration before
ff ← return $ env.contains tgt | skip,
decl ← get_decl src,
-- we first transform all the declarations of the form `pre._proof_i`
(decl.type.list_names_with_prefix pre).mfold () (λ n _, transform_decl_with_prefix_fun_aux n),
(decl.value.list_names_with_prefix pre).mfold () (λ n _, transform_decl_with_prefix_fun_aux n),
-- we transform `decl` using `f` and the configuration options.
let decl :=
decl.update_with_fun env (name.map_prefix f) (additive_test f replace_all ignore)
relevant reorder tgt,
-- o ← get_options, set_options $ o.set_bool `pp.all tt, -- print with pp.all (for debugging)
pp_decl ← pp decl,
when trace $ trace!"[to_additive] > generating\n{pp_decl}",
decorate_error (format!"@[to_additive] failed. Type mismatch in additive declaration.
For help, see the docstring of `to_additive.attr`, section `Troubleshooting`.
Failed to add declaration\n{pp_decl}
Nested error message:\n").to_string $ do
{ if env.is_protected src then add_protected_decl decl else add_decl decl,
-- we test that the declaration value type-checks, so that we get the decorated error message
-- without this line, the type-checking might fail outside the `decorate_error`.
decorate_error "proof doesn't type-check. " $ type_check decl.value }
/--
Make a new copy of a declaration,
replacing fragments of the names of identifiers in the type and the body using the function `f`.
This is used to implement `@[to_additive]`.
-/
meta def transform_decl_with_prefix_fun (f : name → option name) (replace_all trace : bool)
(relevant : name_map ℕ) (ignore reorder : name_map $ list ℕ) (src tgt : name) (attrs : list name)
: command :=
do -- In order to ensure that attributes are copied correctly we must transform declarations and
-- attributes in the right order:
-- first generate the transformed main declaration
transform_decl_with_prefix_fun_aux f replace_all trace relevant ignore reorder src tgt src,
ls ← get_eqn_lemmas_for tt src,
-- now transform all of the equational lemmas
ls.mmap' $
transform_decl_with_prefix_fun_aux f replace_all trace relevant ignore reorder src tgt,
-- copy attributes for the equational lemmas so that they know if they are refl lemmas
ls.mmap' (λ src_eqn, do
let tgt_eqn := src_eqn.map_prefix (λ n, if n = src then some tgt else none),
attrs.mmap' (λ n, copy_attribute' n src_eqn tgt_eqn)),
-- set the transformed equation lemmas as equation lemmas for the new declaration
ls.mmap' (λ src_eqn, do
e ← get_env,
let tgt_eqn := src_eqn.map_prefix (λ n, if n = src then some tgt else none),
set_env (e.add_eqn_lemma tgt_eqn)),
-- copy attributes for the main declaration, this needs the equational lemmas to exist already
attrs.mmap' (λ n, copy_attribute' n src tgt)
/--
Make a new copy of a declaration, replacing fragments of the names of identifiers in the type and
the body using the dictionary `dict`.
This is used to implement `@[to_additive]`.
-/
meta def transform_decl_with_prefix_dict (dict : name_map name) (replace_all trace : bool)
(relevant : name_map ℕ) (ignore reorder : name_map $ list ℕ) (src tgt : name) (attrs : list name)
: command :=
transform_decl_with_prefix_fun dict.find replace_all trace relevant ignore reorder src tgt attrs
end tactic
|
a4443b88802776d807c49299dedd812287ffdaa2 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/algebra/category/CommRing/pushout.lean | 1dbada8e8df6463d38531c07bf0e940f0368e724 | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,199 | lean | /-
Copyright (c) 2020 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import category_theory.limits.shapes.pullbacks
import ring_theory.tensor_product
import algebra.category.CommRing.basic
/-!
# Explicit pushout cocone for CommRing
In this file we prove that tensor product is indeed the fibered coproduct in `CommRing`, and
provide the explicit pushout cocone.
-/
universe u
open category_theory
open_locale tensor_product
variables {R A B : CommRing.{u}} (f : R ⟶ A) (g : R ⟶ B)
namespace CommRing
/-- The explicit cocone with tensor products as the fibered product in `CommRing`. -/
def pushout_cocone : limits.pushout_cocone f g :=
begin
letI := ring_hom.to_algebra f,
letI := ring_hom.to_algebra g,
apply limits.pushout_cocone.mk,
show CommRing, from CommRing.of (A ⊗[R] B),
show A ⟶ _, from algebra.tensor_product.include_left.to_ring_hom,
show B ⟶ _, from algebra.tensor_product.include_right.to_ring_hom,
ext r,
transitivity algebra_map R (A ⊗[R] B) r,
exact algebra.tensor_product.include_left.commutes r,
exact (algebra.tensor_product.include_right.commutes r).symm,
end
@[simp]
lemma pushout_cocone_inl : (pushout_cocone f g).inl = (by {
letI := f.to_algebra, letI := g.to_algebra,
exactI algebra.tensor_product.include_left.to_ring_hom
}) := rfl
@[simp]
lemma pushout_cocone_inr : (pushout_cocone f g).inr = (by {
letI := f.to_algebra, letI := g.to_algebra,
exactI algebra.tensor_product.include_right.to_ring_hom
}) := rfl
@[simp]
lemma pushout_cocone_X : (pushout_cocone f g).X = (by {
letI := f.to_algebra, letI := g.to_algebra,
exactI CommRing.of (A ⊗[R] B)
}) := rfl
/-- Verify that the `pushout_cocone` is indeed the colimit. -/
def pushout_cocone_is_colimit : limits.is_colimit (pushout_cocone f g) :=
limits.pushout_cocone.is_colimit_aux' _ (λ s,
begin
letI := ring_hom.to_algebra f,
letI := ring_hom.to_algebra g,
letI := ring_hom.to_algebra (f ≫ s.inl),
let f' : A →ₐ[R] s.X := { commutes' := λ r, by {
change s.inl.to_fun (f r) = (f ≫ s.inl) r, refl
}, ..s.inl },
let g' : B →ₐ[R] s.X := { commutes' := λ r, by {
change (g ≫ s.inr) r = (f ≫ s.inl) r,
congr' 1,
exact (s.ι.naturality limits.walking_span.hom.snd).trans
(s.ι.naturality limits.walking_span.hom.fst).symm
}, ..s.inr },
/- The factor map is a ⊗ b ↦ f(a) * g(b). -/
use alg_hom.to_ring_hom (algebra.tensor_product.product_map f' g'),
simp only [pushout_cocone_inl, pushout_cocone_inr],
split, { ext x, exact algebra.tensor_product.product_map_left_apply _ _ x, },
split, { ext x, exact algebra.tensor_product.product_map_right_apply _ _ x, },
intros h eq1 eq2,
let h' : (A ⊗[R] B) →ₐ[R] s.X :=
{ commutes' := λ r, by {
change h ((f r) ⊗ₜ[R] 1) = s.inl (f r),
rw ← eq1, simp }, ..h },
suffices : h' = algebra.tensor_product.product_map f' g',
{ ext x,
change h' x = algebra.tensor_product.product_map f' g' x,
rw this },
apply algebra.tensor_product.ext,
intros a b,
simp [← eq1, ← eq2, ← h.map_mul],
end)
end CommRing
|
f4a04b06616219fc914fd4d5dd878b2185f30a42 | 8d65764a9e5f0923a67fc435eb1a5a1d02fd80e3 | /src/linear_algebra/free_module_pid.lean | 7c202dddbfc12d71edeb78f7490647ebc89b6316 | [
"Apache-2.0"
] | permissive | troyjlee/mathlib | e18d4b8026e32062ab9e89bc3b003a5d1cfec3f5 | 45e7eb8447555247246e3fe91c87066506c14875 | refs/heads/master | 1,689,248,035,046 | 1,629,470,528,000 | 1,629,470,528,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 36,622 | lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import linear_algebra.basis
import linear_algebra.finsupp_vector_space
import ring_theory.principal_ideal_domain
import ring_theory.finiteness
/-! # Free modules over PID
A free `R`-module `M` is a module with a basis over `R`,
equivalently it is an `R`-module linearly equivalent to `ι →₀ R` for some `ι`.
This file proves a submodule of a free `R`-module of finite rank is also
a free `R`-module of finite rank, if `R` is a principal ideal domain (PID),
i.e. we have instances `[integral_domain R] [is_principal_ideal_ring R]`.
We express "free `R`-module of finite rank" as a module `M` which has a basis
`b : ι → R`, where `ι` is a `fintype`.
We call the cardinality of `ι` the rank of `M` in this file;
it would be equal to `finrank R M` if `R` is a field and `M` is a vector space.
## Main results
In this section, `M` is a free and finitely generated `R`-module, and
`N` is a submodule of `M`.
- `submodule.induction_on_rank`: if `P` holds for `⊥ : submodule R M` and if
`P N` follows from `P N'` for all `N'` that are of lower rank, then `P` holds
on all submodules
- `submodule.exists_basis_of_pid`: if `R` is a PID, then `N : submodule R M` is
free and finitely generated. This is the first part of the structure theorem
for modules.
- `submodule.smith_normal_form`: if `R` is a PID, then `M` has a basis
`bM` and `N` has a basis `bN` such that `bN i = a i • bM i`.
Equivalently, a linear map `f : M →ₗ M` with `range f = N` can be written as
a matrix in Smith normal form, a diagonal matrix with the coefficients `a i`
along the diagonal.
## Tags
free module, finitely generated module, rank, structure theorem
-/
open_locale big_operators
section comm_ring
universes u v
variables {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M]
variables {ι : Type*} (b : basis ι R M)
open submodule.is_principal
lemma eq_bot_of_rank_eq_zero [no_zero_divisors R] (b : basis ι R M) (N : submodule R M)
(rank_eq : ∀ {m : ℕ} (v : fin m → N),
linear_independent R (coe ∘ v : fin m → M) → m = 0) :
N = ⊥ :=
begin
rw submodule.eq_bot_iff,
intros x hx,
contrapose! rank_eq with x_ne,
refine ⟨1, λ _, ⟨x, hx⟩, _, one_ne_zero⟩,
rw fintype.linear_independent_iff,
rintros g sum_eq i,
fin_cases i,
simp only [function.const_apply, fin.default_eq_zero, submodule.coe_mk, univ_unique,
function.comp_const, finset.sum_singleton] at sum_eq,
exact (b.smul_eq_zero.mp sum_eq).resolve_right x_ne
end
open submodule
lemma eq_bot_of_generator_maximal_map_eq_zero (b : basis ι R M) {N : submodule R M}
{ϕ : M →ₗ[R] R} (hϕ : ∀ (ψ : M →ₗ[R] R), N.map ϕ ≤ N.map ψ → N.map ψ = N.map ϕ)
[(N.map ϕ).is_principal] (hgen : generator (N.map ϕ) = 0) : N = ⊥ :=
begin
rw submodule.eq_bot_iff,
intros x hx,
refine b.ext_elem (λ i, _),
rw (eq_bot_iff_generator_eq_zero _).mpr hgen at hϕ,
rw [linear_equiv.map_zero, finsupp.zero_apply],
exact (submodule.eq_bot_iff _).mp (hϕ ((finsupp.lapply i).comp b.repr) bot_le) _ ⟨x, hx, rfl⟩
end
/-- `(ϕ : O →ₗ M').submodule_image N` is `ϕ(N)` as a submodule of `M'` -/
def linear_map.submodule_image {M' : Type*} [add_comm_group M'] [module R M']
{O : submodule R M} (ϕ : O →ₗ[R] M') (N : submodule R M) : submodule R M' :=
(N.comap O.subtype).map ϕ
@[simp] lemma linear_map.mem_submodule_image {M' : Type*} [add_comm_group M'] [module R M']
{O : submodule R M} {ϕ : O →ₗ[R] M'} {N : submodule R M} {x : M'} :
x ∈ ϕ.submodule_image N ↔ ∃ y (yO : y ∈ O) (yN : y ∈ N), ϕ ⟨y, yO⟩ = x :=
begin
refine submodule.mem_map.trans ⟨_, _⟩; simp_rw submodule.mem_comap,
{ rintro ⟨⟨y, yO⟩, (yN : y ∈ N), h⟩,
exact ⟨y, yO, yN, h⟩ },
{ rintro ⟨y, yO, yN, h⟩,
exact ⟨⟨y, yO⟩, yN, h⟩ }
end
lemma linear_map.mem_submodule_image_of_le {M' : Type*} [add_comm_group M'] [module R M']
{O : submodule R M} {ϕ : O →ₗ[R] M'} {N : submodule R M} (hNO : N ≤ O) {x : M'} :
x ∈ ϕ.submodule_image N ↔ ∃ y (yN : y ∈ N), ϕ ⟨y, hNO yN⟩ = x :=
begin
refine linear_map.mem_submodule_image.trans ⟨_, _⟩,
{ rintro ⟨y, yO, yN, h⟩,
exact ⟨y, yN, h⟩ },
{ rintro ⟨y, yN, h⟩,
exact ⟨y, hNO yN, yN, h⟩ }
end
lemma linear_map.submodule_image_apply_of_le {M' : Type*} [add_comm_group M'] [module R M']
{O : submodule R M} (ϕ : O →ₗ[R] M') (N : submodule R M) (hNO : N ≤ O) :
ϕ.submodule_image N = (ϕ.comp (of_le hNO)).range :=
by rw [linear_map.submodule_image, linear_map.range_comp, range_of_le]
lemma eq_bot_of_generator_maximal_submodule_image_eq_zero {N O : submodule R M} (b : basis ι R O)
(hNO : N ≤ O)
{ϕ : O →ₗ[R] R} (hϕ : ∀ (ψ : O →ₗ[R] R), ϕ.submodule_image N ≤ ψ.submodule_image N →
ψ.submodule_image N = ϕ.submodule_image N)
[(ϕ.submodule_image N).is_principal] (hgen : generator (ϕ.submodule_image N) = 0) :
N = ⊥ :=
begin
rw submodule.eq_bot_iff,
intros x hx,
refine congr_arg coe (show (⟨x, hNO hx⟩ : O) = 0, from b.ext_elem (λ i, _)),
rw (eq_bot_iff_generator_eq_zero _).mpr hgen at hϕ,
rw [linear_equiv.map_zero, finsupp.zero_apply],
refine (submodule.eq_bot_iff _).mp (hϕ ((finsupp.lapply i).comp b.repr) bot_le) _ _,
exact (linear_map.mem_submodule_image_of_le hNO).mpr ⟨x, hx, rfl⟩
end
-- Note that the converse may not hold if `ϕ` is not injective.
lemma generator_map_dvd_of_mem {N : submodule R M}
(ϕ : M →ₗ[R] R) [(N.map ϕ).is_principal] {x : M} (hx : x ∈ N) :
generator (N.map ϕ) ∣ ϕ x :=
by { rw [← mem_iff_generator_dvd, submodule.mem_map], exact ⟨x, hx, rfl⟩ }
-- Note that the converse may not hold if `ϕ` is not injective.
lemma generator_submodule_image_dvd_of_mem {N O : submodule R M} (hNO : N ≤ O)
(ϕ : O →ₗ[R] R) [(ϕ.submodule_image N).is_principal] {x : M} (hx : x ∈ N) :
generator (ϕ.submodule_image N) ∣ ϕ ⟨x, hNO hx⟩ :=
by { rw [← mem_iff_generator_dvd, linear_map.mem_submodule_image_of_le hNO], exact ⟨x, hx, rfl⟩ }
end comm_ring
section integral_domain
variables {ι : Type*} {R : Type*} [integral_domain R]
variables {M : Type*} [add_comm_group M] [module R M] {b : ι → M}
lemma not_mem_of_ortho {x : M} {N : submodule R M}
(ortho : ∀ (c : R) (y ∈ N), c • x + y = (0 : M) → c = 0) :
x ∉ N :=
by { intro hx, simpa using ortho (-1) x hx }
lemma ne_zero_of_ortho {x : M} {N : submodule R M}
(ortho : ∀ (c : R) (y ∈ N), c • x + y = (0 : M) → c = 0) :
x ≠ 0 :=
mt (λ h, show x ∈ N, from h.symm ▸ N.zero_mem) (not_mem_of_ortho ortho)
/-- If `N` is a submodule with finite rank, do induction on adjoining a linear independent
element to a submodule. -/
def submodule.induction_on_rank_aux (b : basis ι R M) (P : submodule R M → Sort*)
(ih : ∀ (N : submodule R M),
(∀ (N' ≤ N) (x ∈ N), (∀ (c : R) (y ∈ N'), c • x + y = (0 : M) → c = 0) → P N') → P N)
(n : ℕ) (N : submodule R M)
(rank_le : ∀ {m : ℕ} (v : fin m → N),
linear_independent R (coe ∘ v : fin m → M) → m ≤ n) :
P N :=
begin
haveI : decidable_eq M := classical.dec_eq M,
have Pbot : P ⊥,
{ apply ih,
intros N N_le x x_mem x_ortho,
exfalso,
simpa using x_ortho 1 0 N.zero_mem },
induction n with n rank_ih generalizing N,
{ suffices : N = ⊥,
{ rwa this },
apply eq_bot_of_rank_eq_zero b _ (λ m v hv, nat.le_zero_iff.mp (rank_le v hv)) },
apply ih,
intros N' N'_le x x_mem x_ortho,
apply rank_ih,
intros m v hli,
refine nat.succ_le_succ_iff.mp (rank_le (fin.cons ⟨x, x_mem⟩ (λ i, ⟨v i, N'_le (v i).2⟩)) _),
convert hli.fin_cons' x _ _,
{ ext i, refine fin.cases _ _ i; simp },
{ intros c y hcy,
refine x_ortho c y (submodule.span_le.mpr _ y.2) hcy,
rintros _ ⟨z, rfl⟩,
exact (v z).2 }
end
/-- In an `n`-dimensional space, the rank is at most `m`. -/
lemma basis.card_le_card_of_linear_independent_aux
{R : Type*} [integral_domain R]
(n : ℕ) {m : ℕ} (v : fin m → fin n → R) :
linear_independent R v → m ≤ n :=
begin
revert m,
refine nat.rec_on n _ _,
{ intros m v hv,
cases m, { refl },
exfalso,
have : v 0 = 0,
{ ext i, exact fin_zero_elim i },
have := hv.ne_zero 0,
contradiction },
intros n ih m v hv,
cases m,
{ exact nat.zero_le _ },
-- Induction: try deleting a dimension and a vector.
suffices : ∃ (v' : fin m → fin n → R), linear_independent R v',
{ obtain ⟨v', hv'⟩ := this,
exact nat.succ_le_succ (ih v' hv') },
-- Either the `0`th dimension is irrelevant...
by_cases this : linear_independent R (λ i, v i ∘ fin.succ),
{ exact ⟨_, this.comp fin.succ (fin.succ_injective _)⟩ },
-- ... or we can write (x, 0, 0, ...) = ∑ i, c i • v i where c i ≠ 0 for some i.
simp only [fintype.linear_independent_iff, not_forall, not_imp] at this,
obtain ⟨c, hc, i, hi⟩ := this,
have hc : ∀ (j : fin n), ∑ (i : fin m.succ), c i * v i j.succ = 0,
{ intro j,
convert congr_fun hc j,
rw [@finset.sum_apply (fin n) (λ _, R) _ _ _],
simp },
set x := ∑ i', c i' * v i' 0 with x_eq,
-- We'll show each equation of the form (y, 0, 0, ...) = ∑ i', c' i' • v i' must have c' i ≠ 0.
use λ i' j', v (i.succ_above i') j'.succ,
rw fintype.linear_independent_iff at ⊢ hv,
-- Assume that ∑ i, c' i • v i = (y, 0, 0, ...).
intros c' hc' i',
set y := ∑ i', c' i' * v (i.succ_above i') 0 with y_eq,
have hc' : ∀ (j : fin n), (∑ (i' : fin m), c' i' * v (i.succ_above i') j.succ) = 0,
{ intro j,
convert congr_fun hc' j,
rw [@finset.sum_apply (fin n) (λ _, R) _ _ _],
simp },
-- Combine these equations to get a linear dependence on the full space.
have : ∑ i', (y * c i' - x * (@fin.insert_nth _ (λ _, R) i 0 c') i') • v i' = 0,
{ simp only [sub_smul, mul_smul, finset.sum_sub_distrib, ← finset.smul_sum],
ext j,
rw [pi.zero_apply, @pi.sub_apply (fin n.succ) (λ _, R) _ _ _ _],
simp only [finset.sum_apply, pi.smul_apply, smul_eq_mul, sub_eq_zero],
symmetry,
rw [fin.sum_univ_succ_above _ i, fin.insert_nth_apply_same, zero_mul, zero_add, mul_comm],
simp only [fin.insert_nth_apply_succ_above],
refine fin.cases _ _ j,
{ simp },
{ intro j,
rw [hc', hc, zero_mul, mul_zero] } },
have hyc := hv _ this i,
simp only [fin.insert_nth_apply_same, mul_zero, sub_zero, mul_eq_zero] at hyc,
-- Therefore, either `c i = 0` (which contradicts the assumption on `i`) or `y = 0`.
have hy := hyc.resolve_right hi,
-- If `y = 0`, then we can extend `c'` to a linear dependence on the full space,
-- which implies `c'` is trivial.
convert hv (@fin.insert_nth _ (λ _, R) i 0 c') _ (i.succ_above i'),
{ rw fin.insert_nth_apply_succ_above },
ext j,
-- After a bit of calculation, we find that `∑ i, c' i • v i = (y, 0, 0, ...) = 0` as promised.
rw [@finset.sum_apply (fin n.succ) (λ _, R) _ _ _, pi.zero_apply],
simp only [pi.smul_apply, smul_eq_mul],
rw [fin.sum_univ_succ_above _ i, fin.insert_nth_apply_same, zero_mul, zero_add],
simp only [fin.insert_nth_apply_succ_above],
refine fin.cases _ _ j,
{ rw [← y_eq, hy] },
{ exact hc' },
end
lemma basis.card_le_card_of_linear_independent
{R : Type*} [integral_domain R] [module R M]
{ι : Type*} [fintype ι] (b : basis ι R M)
{ι' : Type*} [fintype ι'] {v : ι' → M} (hv : linear_independent R v) :
fintype.card ι' ≤ fintype.card ι :=
begin
haveI := classical.dec_eq ι,
haveI := classical.dec_eq ι',
let e := fintype.equiv_fin ι,
let e' := fintype.equiv_fin ι',
let b := b.reindex e,
have hv := (linear_independent_equiv e'.symm).mpr hv,
have hv := hv.map' _ b.equiv_fun.ker,
exact basis.card_le_card_of_linear_independent_aux (fintype.card ι) _ hv,
end
lemma basis.card_le_card_of_submodule
{R : Type*} [integral_domain R] [module R M] (N : submodule R M)
{ι : Type*} [fintype ι] (b : basis ι R M)
{ι' : Type*} [fintype ι'] (b' : basis ι' R N) :
fintype.card ι' ≤ fintype.card ι :=
b.card_le_card_of_linear_independent (b'.linear_independent.map' N.subtype N.ker_subtype)
lemma basis.card_le_card_of_le
{R : Type*} [integral_domain R] [module R M] {N O : submodule R M} (hNO : N ≤ O)
{ι : Type*} [fintype ι] (b : basis ι R O)
{ι' : Type*} [fintype ι'] (b' : basis ι' R N) :
fintype.card ι' ≤ fintype.card ι :=
b.card_le_card_of_linear_independent
(b'.linear_independent.map' (submodule.of_le hNO) (N.ker_of_le O _))
/-- If we have two bases on the same space, their indices are in bijection. -/
noncomputable def basis.index_equiv {R ι ι' : Type*} [integral_domain R] [module R M]
[fintype ι] [fintype ι'] (b : basis ι R M) (b' : basis ι' R M) :
ι ≃ ι' :=
(fintype.card_eq.mp (le_antisymm
(b'.card_le_card_of_linear_independent b.linear_independent)
(b.card_le_card_of_linear_independent b'.linear_independent))).some
/-- If `N` is a submodule in a free, finitely generated module,
do induction on adjoining a linear independent element to a submodule. -/
def submodule.induction_on_rank [fintype ι] (b : basis ι R M) (P : submodule R M → Sort*)
(ih : ∀ (N : submodule R M),
(∀ (N' ≤ N) (x ∈ N), (∀ (c : R) (y ∈ N'), c • x + y = (0 : M) → c = 0) → P N') →
P N)
(N : submodule R M) : P N :=
submodule.induction_on_rank_aux b P ih (fintype.card ι) N (λ s hs hli,
by simpa using b.card_le_card_of_linear_independent hli)
open submodule.is_principal set submodule
lemma dvd_generator_iff {I : ideal R} [I.is_principal] {x : R} (hx : x ∈ I) :
x ∣ generator I ↔ I = ideal.span {x} :=
begin
conv_rhs { rw [← span_singleton_generator I] },
erw [ideal.span_singleton_eq_span_singleton, ← dvd_dvd_iff_associated, ← mem_iff_generator_dvd],
exact ⟨λ h, ⟨hx, h⟩, λ h, h.2⟩
end
/-- If `S` a finite-dimensional ring extension of `R` which is free as an `R`-module,
then the rank of an ideal `I` of `S` over `R` is the same as the rank of `S`.
-/
lemma ideal.rank_eq {S : Type*} [domain S] [algebra R S]
{n m : Type*} [fintype n] [fintype m]
(b : basis n R S) {I : ideal S} (hI : I ≠ ⊥) (c : basis m R I) :
fintype.card m = fintype.card n :=
begin
obtain ⟨a, ha⟩ := submodule.nonzero_mem_of_bot_lt (bot_lt_iff_ne_bot.mpr hI),
have : linear_independent R (λ i, b i • a),
{ have hb := b.linear_independent,
rw fintype.linear_independent_iff at ⊢ hb,
intros g hg,
apply hb g,
simp only [← smul_assoc, ← finset.sum_smul, smul_eq_zero] at hg,
exact hg.resolve_right ha },
exact le_antisymm
(b.card_le_card_of_linear_independent (c.linear_independent.map' (submodule.subtype I)
(linear_map.ker_eq_bot.mpr subtype.coe_injective)))
(c.card_le_card_of_linear_independent this),
end
end integral_domain
section principal_ideal_domain
open submodule.is_principal set submodule
variables {ι : Type*} {R : Type*} [integral_domain R] [is_principal_ideal_ring R]
variables {M : Type*} [add_comm_group M] [module R M] {b : ι → M}
open submodule.is_principal
lemma generator_maximal_submodule_image_dvd {N O : submodule R M} (hNO : N ≤ O)
{ϕ : O →ₗ[R] R} (hϕ : ∀ (ψ : O →ₗ[R] R), ϕ.submodule_image N ≤ ψ.submodule_image N →
ψ.submodule_image N = ϕ.submodule_image N)
[(ϕ.submodule_image N).is_principal]
(y : M) (yN : y ∈ N) (ϕy_eq : ϕ ⟨y, hNO yN⟩ = generator (ϕ.submodule_image N))
(ψ : O →ₗ[R] R) : generator (ϕ.submodule_image N) ∣ ψ ⟨y, hNO yN⟩ :=
begin
let a : R := generator (ϕ.submodule_image N),
let d : R := is_principal.generator (submodule.span R {a, ψ ⟨y, hNO yN⟩}),
have d_dvd_left : d ∣ a := (mem_iff_generator_dvd _).mp
(subset_span (mem_insert _ _)),
have d_dvd_right : d ∣ ψ ⟨y, hNO yN⟩ := (mem_iff_generator_dvd _).mp
(subset_span (mem_insert_of_mem _ (mem_singleton _))),
refine dvd_trans _ d_dvd_right,
rw [dvd_generator_iff, ideal.span,
← span_singleton_generator (submodule.span R {a, ψ ⟨y, hNO yN⟩})],
obtain ⟨r₁, r₂, d_eq⟩ : ∃ r₁ r₂ : R, d = r₁ * a + r₂ * ψ ⟨y, hNO yN⟩,
{ obtain ⟨r₁, r₂', hr₂', hr₁⟩ := mem_span_insert.mp (is_principal.generator_mem
(submodule.span R {a, ψ ⟨y, hNO yN⟩})),
obtain ⟨r₂, rfl⟩ := mem_span_singleton.mp hr₂',
exact ⟨r₁, r₂, hr₁⟩ },
let ψ' : O →ₗ[R] R := r₁ • ϕ + r₂ • ψ,
have : span R {d} ≤ ψ'.submodule_image N,
{ rw [span_le, singleton_subset_iff, set_like.mem_coe, linear_map.mem_submodule_image_of_le hNO],
refine ⟨y, yN, _⟩,
change r₁ * ϕ ⟨y, hNO yN⟩ + r₂ * ψ ⟨y, hNO yN⟩ = d,
rw [d_eq, ϕy_eq] },
refine le_antisymm (this.trans (le_of_eq _))
(ideal.span_singleton_le_span_singleton.mpr d_dvd_left),
rw span_singleton_generator,
refine hϕ ψ' (le_trans _ this),
rw [← span_singleton_generator (ϕ.submodule_image N)],
exact ideal.span_singleton_le_span_singleton.mpr d_dvd_left,
{ exact subset_span (mem_insert _ _) }
end
/-- The induction hypothesis of `submodule.basis_of_pid` and `submodule.smith_normal_form`.
Basically, it says: let `N ≤ M` be a pair of submodules, then we can find a pair of
submodules `N' ≤ M'` of strictly smaller rank, whose basis we can extend to get a basis
of `N` and `M`. Moreover, if the basis for `M'` is up to scalars a basis for `N'`,
then the basis we find for `M` is up to scalars a basis for `N`.
For `basis_of_pid` we only need the first half and can fix `M = ⊤`,
for `smith_normal_form` we need the full statement,
but must also feed in a basis for `M` using `basis_of_pid` to keep the induction going.
-/
lemma submodule.basis_of_pid_aux [fintype ι] {O : Type*} [add_comm_group O] [module R O]
(M N : submodule R O) (b'M : basis ι R M) (N_bot : N ≠ ⊥) (N_le_M : N ≤ M) :
∃ (y ∈ M) (a : R) (hay : a • y ∈ N) (M' ≤ M) (N' ≤ N) (N'_le_M' : N' ≤ M')
(y_ortho_M' : ∀ (c : R) (z : O), z ∈ M' → c • y + z = 0 → c = 0)
(ay_ortho_N' : ∀ (c : R) (z : O), z ∈ N' → c • a • y + z = 0 → c = 0),
∀ (n') (bN' : basis (fin n') R N'), ∃ (bN : basis (fin (n' + 1)) R N),
∀ (m') (hn'm' : n' ≤ m') (bM' : basis (fin m') R M'),
∃ (hnm : (n' + 1) ≤ (m' + 1)) (bM : basis (fin (m' + 1)) R M),
∀ (as : fin n' → R) (h : ∀ (i : fin n'), (bN' i : O) = as i • (bM' (fin.cast_le hn'm' i) : O)),
∃ (as' : fin (n' + 1) → R),
∀ (i : fin (n' + 1)), (bN i : O) = as' i • (bM (fin.cast_le hnm i) : O) :=
begin
-- Let `ϕ` be a maximal projection of `M` onto `R`, in the sense that there is
-- no `ψ` whose image of `N` is larger than `ϕ`'s image of `N`.
have : ∃ ϕ : M →ₗ[R] R, ∀ (ψ : M →ₗ[R] R),
ϕ.submodule_image N ≤ ψ.submodule_image N → ψ.submodule_image N = ϕ.submodule_image N,
{ obtain ⟨P, P_eq, P_max⟩ := set_has_maximal_iff_noetherian.mpr
(infer_instance : is_noetherian R R) _
(show (set.range (λ ψ : M →ₗ[R] R, ψ.submodule_image N)).nonempty,
from ⟨_, set.mem_range.mpr ⟨0, rfl⟩⟩),
obtain ⟨ϕ, rfl⟩ := set.mem_range.mp P_eq,
use ϕ,
intros ψ hψ,
exact P_max _ ⟨_, rfl⟩ hψ },
let ϕ := this.some,
have ϕ_max := this.some_spec,
-- Since `ϕ(N)` is a `R`-submodule of the PID `R`,
-- it is principal and generated by some `a`.
let a := generator (ϕ.submodule_image N),
have a_mem : a ∈ ϕ.submodule_image N := generator_mem _,
-- If `a` is zero, then the submodule is trivial. So let's assume `a ≠ 0`, `N ≠ ⊥`.
by_cases a_zero : a = 0,
{ have := eq_bot_of_generator_maximal_submodule_image_eq_zero b'M N_le_M ϕ_max a_zero,
contradiction },
-- We claim that `ϕ⁻¹ a = y` can be taken as basis element of `N`.
obtain ⟨y, yN, ϕy_eq⟩ := (linear_map.mem_submodule_image_of_le N_le_M).mp a_mem,
have ϕy_ne_zero : ϕ ⟨y, N_le_M yN⟩ ≠ 0 := λ h, a_zero (ϕy_eq.symm.trans h),
-- Write `y` as `a • y'` for some `y'`.
have hdvd : ∀ i, a ∣ b'M.coord i ⟨y, N_le_M yN⟩ :=
λ i, generator_maximal_submodule_image_dvd N_le_M ϕ_max y yN ϕy_eq (b'M.coord i),
choose c hc using hdvd,
let y' : O := ∑ i, c i • b'M i,
have y'M : y' ∈ M := M.sum_mem (λ i _, M.smul_mem (c i) (b'M i).2),
have mk_y' : (⟨y', y'M⟩ : M) = ∑ i, c i • b'M i :=
subtype.ext (show y' = M.subtype _,
by { simp only [linear_map.map_sum, linear_map.map_smul], refl }),
have a_smul_y' : a • y' = y,
{ refine congr_arg coe (show (a • ⟨y', y'M⟩ : M) = ⟨y, N_le_M yN⟩, from _),
rw [← b'M.sum_repr ⟨y, N_le_M yN⟩, mk_y', finset.smul_sum],
refine finset.sum_congr rfl (λ i _, _),
rw [← mul_smul, ← hc], refl },
-- We found an `y` and an `a`!
refine ⟨y', y'M, a, a_smul_y'.symm ▸ yN, _⟩,
have ϕy'_eq : ϕ ⟨y', y'M⟩ = 1 := mul_left_cancel' a_zero
(calc a • ϕ ⟨y', y'M⟩ = ϕ ⟨a • y', _⟩ : (ϕ.map_smul a ⟨y', y'M⟩).symm
... = ϕ ⟨y, N_le_M yN⟩ : by simp only [a_smul_y']
... = a : ϕy_eq
... = a * 1 : (mul_one a).symm),
have ϕy'_ne_zero : ϕ ⟨y', y'M⟩ ≠ 0 := by simpa only [ϕy'_eq] using one_ne_zero,
-- `M' := ker (ϕ : M → R)` is smaller than `M` and `N' := ker (ϕ : N → R)` is smaller than `N`.
let M' : submodule R O := ϕ.ker.map M.subtype,
let N' : submodule R O := (ϕ.comp (of_le N_le_M)).ker.map N.subtype,
have M'_le_M : M' ≤ M := M.map_subtype_le ϕ.ker,
have N'_le_M' : N' ≤ M',
{ intros x hx,
simp only [mem_map, linear_map.mem_ker] at hx ⊢,
obtain ⟨⟨x, xN⟩, hx, rfl⟩ := hx,
exact ⟨⟨x, N_le_M xN⟩, hx, rfl⟩ },
have N'_le_N : N' ≤ N := N.map_subtype_le (ϕ.comp (of_le N_le_M)).ker,
-- So fill in those results as well.
refine ⟨M', M'_le_M, N', N'_le_N, N'_le_M', _⟩,
-- Note that `y'` is orthogonal to `M'`.
have y'_ortho_M' : ∀ (c : R) z ∈ M', c • y' + z = 0 → c = 0,
{ intros c x xM' hc,
obtain ⟨⟨x, xM⟩, hx', rfl⟩ := submodule.mem_map.mp xM',
rw linear_map.mem_ker at hx',
have hc' : (c • ⟨y', y'M⟩ + ⟨x, xM⟩ : M) = 0 := subtype.coe_injective hc,
simpa only [linear_map.map_add, linear_map.map_zero, linear_map.map_smul, smul_eq_mul, add_zero,
mul_eq_zero, ϕy'_ne_zero, hx', or_false] using congr_arg ϕ hc' },
-- And `a • y'` is orthogonal to `N'`.
have ay'_ortho_N' : ∀ (c : R) z ∈ N', c • a • y' + z = 0 → c = 0,
{ intros c z zN' hc,
refine (mul_eq_zero.mp (y'_ortho_M' (a * c) z (N'_le_M' zN') _)).resolve_left a_zero,
rw [mul_comm, mul_smul, hc] },
-- So we can extend a basis for `N'` with `y`
refine ⟨y'_ortho_M', ay'_ortho_N', λ n' bN', ⟨_, _⟩⟩,
{ refine basis.mk_fin_cons_of_le y yN bN' N'_le_N _ _,
{ intros c z zN' hc,
refine ay'_ortho_N' c z zN' _,
rwa ← a_smul_y' at hc },
{ intros z zN,
obtain ⟨b, hb⟩ : _ ∣ ϕ ⟨z, N_le_M zN⟩ := generator_submodule_image_dvd_of_mem N_le_M ϕ zN,
refine ⟨-b, submodule.mem_map.mpr ⟨⟨_, N.sub_mem zN (N.smul_mem b yN)⟩, _, _⟩⟩,
{ refine linear_map.mem_ker.mpr (show ϕ (⟨z, N_le_M zN⟩ - b • ⟨y, N_le_M yN⟩) = 0, from _),
rw [linear_map.map_sub, linear_map.map_smul, hb, ϕy_eq, smul_eq_mul,
mul_comm, sub_self] },
{ simp only [sub_eq_add_neg, neg_smul], refl } } },
-- And extend a basis for `M'` with `y'`
intros m' hn'm' bM',
refine ⟨nat.succ_le_succ hn'm', _, _⟩,
{ refine basis.mk_fin_cons_of_le y' y'M bM' M'_le_M y'_ortho_M' _,
intros z zM,
refine ⟨-ϕ ⟨z, zM⟩, ⟨⟨z, zM⟩ - (ϕ ⟨z, zM⟩) • ⟨y', y'M⟩, linear_map.mem_ker.mpr _, _⟩⟩,
{ rw [linear_map.map_sub, linear_map.map_smul, ϕy'_eq, smul_eq_mul, mul_one, sub_self] },
{ rw [linear_map.map_sub, linear_map.map_smul, sub_eq_add_neg, neg_smul], refl } },
-- It remains to show the extended bases are compatible with each other.
intros as h,
refine ⟨fin.cons a as, _⟩,
intro i,
rw [basis.coe_mk_fin_cons_of_le, basis.coe_mk_fin_cons_of_le],
refine fin.cases _ (λ i, _) i,
{ simp only [fin.cons_zero, fin.cast_le_zero],
exact a_smul_y'.symm },
{ rw fin.cast_le_succ, simp only [fin.cons_succ, coe_of_le, h i] }
end
/-- A submodule of a free `R`-module of finite rank is also a free `R`-module of finite rank,
if `R` is a principal ideal domain.
This is a `lemma` to make the induction a bit easier. To actually access the basis,
see `submodule.basis_of_pid`.
See also the stronger version `submodule.smith_normal_form`.
-/
lemma submodule.nonempty_basis_of_pid {ι : Type*} [fintype ι]
(b : basis ι R M) (N : submodule R M) :
∃ (n : ℕ), nonempty (basis (fin n) R N) :=
begin
haveI := classical.dec_eq M,
refine N.induction_on_rank b _ _,
intros N ih,
let b' := (b.reindex (fintype.equiv_fin ι)).map (linear_equiv.of_top _ rfl).symm,
by_cases N_bot : N = ⊥,
{ subst N_bot, exact ⟨0, ⟨basis.empty _⟩⟩ },
obtain ⟨y, -, a, hay, M', -, N', N'_le_N, -, -, ay_ortho, h'⟩ :=
submodule.basis_of_pid_aux ⊤ N b' N_bot le_top,
obtain ⟨n', ⟨bN'⟩⟩ := ih N' N'_le_N _ hay ay_ortho,
obtain ⟨bN, hbN⟩ := h' n' bN',
exact ⟨n' + 1, ⟨bN⟩⟩
end
/-- A submodule of a free `R`-module of finite rank is also a free `R`-module of finite rank,
if `R` is a principal ideal domain.
See also the stronger version `submodule.smith_normal_form`.
-/
noncomputable def submodule.basis_of_pid {ι : Type*} [fintype ι]
(b : basis ι R M) (N : submodule R M) :
Σ (n : ℕ), (basis (fin n) R N) :=
⟨_, (N.nonempty_basis_of_pid b).some_spec.some⟩
lemma submodule.basis_of_pid_bot {ι : Type*} [fintype ι] (b : basis ι R M) :
submodule.basis_of_pid b ⊥ = ⟨0, basis.empty _⟩ :=
begin
obtain ⟨n, b'⟩ := submodule.basis_of_pid b ⊥,
let e : fin n ≃ fin 0 := b'.index_equiv (basis.empty _ : basis (fin 0) R (⊥ : submodule R M)),
have : n = 0 := by simpa using fintype.card_eq.mpr ⟨e⟩,
subst this,
exact sigma.eq rfl (basis.eq_of_apply_eq $ fin_zero_elim)
end
/-- A submodule inside a free `R`-submodule of finite rank is also a free `R`-module of finite rank,
if `R` is a principal ideal domain.
See also the stronger version `submodule.smith_normal_form_of_le`.
-/
noncomputable def submodule.basis_of_pid_of_le {ι : Type*} [fintype ι]
{N O : submodule R M} (hNO : N ≤ O) (b : basis ι R O) :
Σ (n : ℕ), basis (fin n) R N :=
let ⟨n, bN'⟩ := submodule.basis_of_pid b (N.comap O.subtype)
in ⟨n, bN'.map (submodule.comap_subtype_equiv_of_le hNO)⟩
/-- A submodule inside the span of a linear independent family is a free `R`-module of finite rank,
if `R` is a principal ideal domain. -/
noncomputable def submodule.basis_of_pid_of_le_span
{ι : Type*} [fintype ι] {b : ι → M} (hb : linear_independent R b)
{N : submodule R M} (le : N ≤ submodule.span R (set.range b)) :
Σ (n : ℕ), basis (fin n) R N :=
submodule.basis_of_pid_of_le le (basis.span hb)
variable {M}
/-- A finite type torsion free module over a PID is free. -/
noncomputable def module.free_of_finite_type_torsion_free [fintype ι] {s : ι → M}
(hs : span R (range s) = ⊤) [no_zero_smul_divisors R M] :
Σ (n : ℕ), basis (fin n) R M :=
begin
classical,
-- We define `N` as the submodule spanned by a maximal linear independent subfamily of `s`
have := exists_maximal_independent R s,
let I : set ι := this.some,
obtain ⟨indepI : linear_independent R (s ∘ coe : I → M),
hI : ∀ i ∉ I, ∃ a : R, a ≠ 0 ∧ a • s i ∈ span R (s '' I)⟩ := this.some_spec,
let N := span R (range $ (s ∘ coe : I → M)), -- same as `span R (s '' I)` but more convenient
let sI : I → N := λ i, ⟨s i.1, subset_span (mem_range_self i)⟩, -- `s` restricted to `I`
let sI_basis : basis I R N, -- `s` restricted to `I` is a basis of `N`
from basis.span indepI,
-- Our first goal is to build `A ≠ 0` such that `A • M ⊆ N`
have exists_a : ∀ i : ι, ∃ a : R, a ≠ 0 ∧ a • s i ∈ N,
{ intro i,
by_cases hi : i ∈ I,
{ use [1, zero_ne_one.symm],
rw one_smul,
exact subset_span (mem_range_self (⟨i, hi⟩ : I)) },
{ simpa [image_eq_range s I] using hI i hi } },
choose a ha ha' using exists_a,
let A := ∏ i, a i,
have hA : A ≠ 0,
{ rw finset.prod_ne_zero_iff,
simpa using ha },
-- `M ≃ A • M` because `M` is torsion free and `A ≠ 0`
let φ : M →ₗ[R] M := linear_map.lsmul R M A,
have : φ.ker = ⊥,
from linear_map.ker_lsmul hA,
let ψ : M ≃ₗ[R] φ.range := linear_equiv.of_injective φ this,
have : φ.range ≤ N, -- as announced, `A • M ⊆ N`
{ suffices : ∀ i, φ (s i) ∈ N,
{ rw [linear_map.range_eq_map, ← hs, φ.map_span_le],
rintros _ ⟨i, rfl⟩, apply this },
intro i,
calc (∏ j, a j) • s i = (∏ j in {i}ᶜ, a j) • a i • s i :
by rw [fintype.prod_eq_prod_compl_mul i, mul_smul]
... ∈ N : N.smul_mem _ (ha' i) },
-- Since a submodule of a free `R`-module is free, we get that `A • M` is free
obtain ⟨n, b : basis (fin n) R φ.range⟩ := submodule.basis_of_pid_of_le this sI_basis,
-- hence `M` is free.
exact ⟨n, b.map ψ.symm⟩
end
/-- A finite type torsion free module over a PID is free. -/
noncomputable def module.free_of_finite_type_torsion_free' [module.finite R M]
[no_zero_smul_divisors R M] :
Σ (n : ℕ), basis (fin n) R M :=
module.free_of_finite_type_torsion_free module.finite.exists_fin.some_spec.some_spec
section smith_normal
/-- A Smith normal form basis for a submodule `N` of a module `M` consists of
bases for `M` and `N` such that the inclusion map `N → M` can be written as a
(rectangular) matrix with `a` along the diagonal: in Smith normal form. -/
@[nolint has_inhabited_instance]
structure basis.smith_normal_form (N : submodule R M) (ι : Type*) (n : ℕ) :=
(bM : basis ι R M)
(bN : basis (fin n) R N)
(f : fin n ↪ ι)
(a : fin n → R)
(snf : ∀ i, (bN i : M) = a i • bM (f i))
/-- If `M` is finite free over a PID `R`, then any submodule `N` is free
and we can find a basis for `M` and `N` such that the inclusion map is a diagonal matrix
in Smith normal form.
See `submodule.smith_normal_form_of_le` for a version of this theorem that returns
a `basis.smith_normal_form`.
This is a strengthening of `submodule.basis_of_pid_of_le`.
-/
theorem submodule.exists_smith_normal_form_of_le [fintype ι]
(b : basis ι R M) (N O : submodule R M) (N_le_O : N ≤ O) :
∃ (n o : ℕ) (hno : n ≤ o) (bO : basis (fin o) R O) (bN : basis (fin n) R N) (a : fin n → R),
∀ i, (bN i : M) = a i • bO (fin.cast_le hno i) :=
begin
revert N,
refine induction_on_rank b _ _ O,
intros M ih N N_le_M,
obtain ⟨m, b'M⟩ := M.basis_of_pid b,
by_cases N_bot : N = ⊥,
{ subst N_bot,
exact ⟨0, m, nat.zero_le _, b'M, basis.empty _, fin_zero_elim, fin_zero_elim⟩ },
obtain ⟨y, hy, a, hay, M', M'_le_M, N', N'_le_N, N'_le_M', y_ortho, ay_ortho, h⟩ :=
submodule.basis_of_pid_aux M N b'M N_bot N_le_M,
obtain ⟨n', m', hn'm', bM', bN', as', has'⟩ := ih M' M'_le_M y hy y_ortho N' N'_le_M',
obtain ⟨bN, h'⟩ := h n' bN',
obtain ⟨hmn, bM, h''⟩ := h' m' hn'm' bM',
obtain ⟨as, has⟩ := h'' as' has',
exact ⟨_, _, hmn, bM, bN, as, has⟩
end
/-- If `M` is finite free over a PID `R`, then any submodule `N` is free
and we can find a basis for `M` and `N` such that the inclusion map is a diagonal matrix
in Smith normal form.
See `submodule.exists_smith_normal_form_of_le` for a version of this theorem that doesn't
need to map `N` into a submodule of `O`.
This is a strengthening of `submodule.basis_of_pid_of_le`.
-/
noncomputable def submodule.smith_normal_form_of_le [fintype ι]
(b : basis ι R M) (N O : submodule R M) (N_le_O : N ≤ O) :
Σ (o n : ℕ), basis.smith_normal_form (N.comap O.subtype) (fin o) n :=
begin
choose n o hno bO bN a snf using N.exists_smith_normal_form_of_le b O N_le_O,
refine ⟨o, n, bO, bN.map (comap_subtype_equiv_of_le N_le_O).symm, (fin.cast_le hno).to_embedding,
a, λ i, _⟩,
ext,
simp only [snf, basis.map_apply, submodule.comap_subtype_equiv_of_le_symm_apply_coe_coe,
submodule.coe_smul_of_tower, rel_embedding.coe_fn_to_embedding]
end
/-- If `M` is finite free over a PID `R`, then any submodule `N` is free
and we can find a basis for `M` and `N` such that the inclusion map is a diagonal matrix
in Smith normal form.
This is a strengthening of `submodule.basis_of_pid`.
See also `ideal.smith_normal_form`, which moreover proves that the dimension of
an ideal is the same as the dimension of the whole ring.
-/
noncomputable def submodule.smith_normal_form [fintype ι] (b : basis ι R M) (N : submodule R M) :
Σ (n : ℕ), basis.smith_normal_form N ι n :=
let ⟨m, n, bM, bN, f, a, snf⟩ := N.smith_normal_form_of_le b ⊤ le_top,
bM' := bM.map (linear_equiv.of_top _ rfl),
e := bM'.index_equiv b in
⟨n, bM'.reindex e, bN.map (comap_subtype_equiv_of_le le_top), f.trans e.to_embedding, a,
λ i, by simp only [snf, basis.map_apply, linear_equiv.of_top_apply, submodule.coe_smul_of_tower,
submodule.comap_subtype_equiv_of_le_apply_coe, coe_coe, basis.reindex_apply,
equiv.to_embedding_apply, function.embedding.trans_apply,
equiv.symm_apply_apply]⟩
/-- If `S` a finite-dimensional ring extension of a PID `R` which is free as an `R`-module,
then any nonzero `S`-ideal `I` is free as an `R`-submodule of `S`, and we can
find a basis for `S` and `I` such that the inclusion map is a square diagonal
matrix.
See `ideal.exists_smith_normal_form` for a version of this theorem that doesn't
need to map `I` into a submodule of `R`.
This is a strengthening of `submodule.basis_of_pid`.
-/
noncomputable def ideal.smith_normal_form [fintype ι] {S : Type*} [integral_domain S] [algebra R S]
(b : basis ι R S) (I : ideal S) (hI : I ≠ ⊥) :
basis.smith_normal_form (I.restrict_scalars R) ι (fintype.card ι) :=
let ⟨n, bS, bI, f, a, snf⟩ := (I.restrict_scalars R).smith_normal_form b in
have eq : _ := ideal.rank_eq bS hI (bI.map ((restrict_scalars_equiv R S S I).restrict_scalars _)),
let e : fin n ≃ fin (fintype.card ι) := fintype.equiv_of_card_eq (by rw [eq, fintype.card_fin]) in
⟨bS, bI.reindex e, e.symm.to_embedding.trans f, a ∘ e.symm, λ i,
by simp only [snf, basis.coe_reindex, function.embedding.trans_apply, equiv.to_embedding_apply]⟩
/-- If `S` a finite-dimensional ring extension of a PID `R` which is free as an `R`-module,
then any nonzero `S`-ideal `I` is free as an `R`-submodule of `S`, and we can
find a basis for `S` and `I` such that the inclusion map is a square diagonal
matrix.
See also `ideal.smith_normal_form` for a version of this theorem that returns
a `basis.smith_normal_form`.
-/
theorem ideal.exists_smith_normal_form [fintype ι] {S : Type*} [integral_domain S] [algebra R S]
(b : basis ι R S) (I : ideal S) (hI : I ≠ ⊥) :
∃ (b' : basis ι R S) (a : ι → R) (ab' : basis ι R I),
∀ i, (ab' i : S) = a i • b' i :=
let ⟨bS, bI, f, a, snf⟩ := I.smith_normal_form b hI,
e : fin (fintype.card ι) ≃ ι := equiv.of_bijective f
((fintype.bijective_iff_injective_and_card f).mpr ⟨f.injective, fintype.card_fin _⟩) in
have fe : ∀ i, f (e.symm i) = i := e.apply_symm_apply,
⟨bS, a ∘ e.symm, (bI.reindex e).map ((restrict_scalars_equiv _ _ _ _).restrict_scalars R), λ i,
by simp only [snf, fe, basis.map_apply, linear_equiv.restrict_scalars_apply,
submodule.restrict_scalars_equiv_apply, basis.coe_reindex]⟩
end smith_normal
end principal_ideal_domain
/-- A set of linearly independent vectors in a module `M` over a semiring `S` is also linearly
independent over a subring `R` of `K`. -/
lemma linear_independent.restrict_scalars_algebras {R S M ι : Type*} [comm_semiring R] [semiring S]
[add_comm_monoid M] [algebra R S] [module R M] [module S M] [is_scalar_tower R S M]
(hinj : function.injective (algebra_map R S)) {v : ι → M} (li : linear_independent S v) :
linear_independent R v :=
linear_independent.restrict_scalars (by rwa algebra.algebra_map_eq_smul_one' at hinj) li
|
dfd9156e53897bf2b522b94d57c9bb5fab05a062 | f00cc9c04d77f9621aa57d1406d35c522c3ff82c | /tests/lean/structure_segfault.lean | 7c0dc2a0cda2d505f47f3d6b33ecaebb822d87d4 | [
"Apache-2.0"
] | permissive | shonfeder/lean | 444c66a74676d74fb3ef682d88cd0f5c1bf928a5 | 24d5a1592d80cefe86552d96410c51bb07e6d411 | refs/heads/master | 1,619,338,440,905 | 1,512,842,340,000 | 1,512,842,340,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 250 | lean | universes u
namespace hide
structure group (α : Type u) : Type u
structure T (α : extends group α := ()
structure ring (α : Type u) : Type u
class T (α : Type*) extends ring x α
class S (α : Type*) extends ((λ x, group x) α)
end hide
|
6e1d1d6fa443a309d4ba52f2e8c950d99c94666a | 892c0ca8b8ddfe17a2c64fb7b721f9e2d9287539 | /partial_fun.lean | 676a4bf466aa844d26ce9a24e8ff1a4f0f8346e3 | [] | no_license | ssomayyajula/stlc | f7ef96de541f9519b00912337332366317282dce | cf92bf387b4418f9a6261c7ea4876db4e4280dd2 | refs/heads/master | 1,630,729,373,254 | 1,516,045,347,000 | 1,516,045,347,000 | 115,835,353 | 5 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,243 | lean | def partial_fun (α β) := α → option β
universes u v
variables {α : Type u} {β : Type v}
def emptyf : partial_fun α β
| _ := none
instance : has_emptyc (partial_fun α β) :=
⟨emptyf⟩
inductive dom (f : partial_fun α β) : set α
| intro (a) (b) : f a = some b → dom a
variable [decidable_eq α]
-- Destructive addition to a context
@[irreducible]
def extend (f : partial_fun α β) (x : α) (y : β) : partial_fun α β
| x' := if x' = x then y else f x'
instance : has_insert (α × β) (partial_fun α β) :=
⟨λ ⟨a, b⟩ f, extend f a b⟩
variable (f : partial_fun α β)
lemma extend_same (x : α) (y : β) : extend f x y x = y :=
by unfold extend; simp
lemma extend_diff {x x' : α} (y : β) :
x' ≠ x → extend f x y x' = f x' :=
by intro h; unfold extend; simp [h]
lemma extend_comm {x₁ x₂ : α} (y₁ y₂ : β) : x₁ ≠ x₂ →
extend (extend f x₁ y₁) x₂ y₂ = extend (extend f x₂ y₂) x₁ y₁ :=
begin
intro h,
apply funext,
intro x,
by_cases x = x₁ with h',
simp [h', extend_same,
extend_diff _ _ h],
rw extend_diff _ _ h',
by_cases x = x₂ with h'',
simp [h'', extend_same],
simp [extend_diff _ _ h',
extend_diff _ _ h'']
end
|
79c8314d7207d40e27734b5fb573674c093a8373 | ec5a7ae10c533e1b1f4b0bc7713e91ecf829a3eb | /ijcar16/examples/cc10.lean | 2c261c40c0c969503684e3eb1a3f1b9faef78c9c | [
"MIT"
] | permissive | leanprover/leanprover.github.io | cf248934af7c7e9aeff17cf8df3c12c5e7e73f1a | 071a20d2e059a2c3733e004c681d3949cac3c07a | refs/heads/master | 1,692,621,047,417 | 1,691,396,994,000 | 1,691,396,994,000 | 19,366,263 | 18 | 27 | MIT | 1,693,989,071,000 | 1,399,006,345,000 | Lean | UTF-8 | Lean | false | false | 413 | lean | /-
Example/test file for the congruence closure procedure described in the paper:
"Congruence Closure for Intensional Type Theory"
Daniel Selsam and Leonardo de Moura
The tactic `by blast` has been configured in this file to use just
the congruence closure procedure using the command
set_option blast.strategy "cc"
-/
set_option blast.strategy "cc"
example (a b : nat) : (a = b ↔ a = b) :=
by blast
|
bcab737d47262e04b4f4e2f9459254895f1b437e | 9c1ad797ec8a5eddb37d34806c543602d9a6bf70 | /universal/transport.lean | 7eb85ca08e68a33a41f0e335ea5725de3da50070 | [] | no_license | timjb/lean-category-theory | 816eefc3a0582c22c05f4ee1c57ed04e57c0982f | 12916cce261d08bb8740bc85e0175b75fb2a60f4 | refs/heads/master | 1,611,078,926,765 | 1,492,080,000,000 | 1,492,080,000,000 | 88,348,246 | 0 | 0 | null | 1,492,262,499,000 | 1,492,262,498,000 | null | UTF-8 | Lean | false | false | 624 | lean | set_option pp.all true
#check prod.rec
lemma transport_refl { α : Type } ( a b : α ) ( p : a = b ) : @eq.rec α a _ (eq.refl a) b p = eq.refl b :=
begin
simp
end
lemma transport_refl' { α : Type } ( a b c : α ) ( p : b = c ) : @eq.rec α b _ (eq.refl (a, b)) c p = eq.refl (a, c) :=
begin
simp
end
lemma transport_Prop ( P Q : Prop ) ( a : P ) ( p : P = Q ) : @eq.rec Prop P (λ T, T) a Q p = eq.mp p a := begin
reflexivity
end
--(eq.rec (eq.refl (prod.mk fst)) p)
lemma foo { α β : Type } ( a b : α ) ( p : a = b ) : @eq.rec α a _ (eq.refl (@prod.mk α β a)) b p = eq.refl (@prod.mk α β b) := by simp |
377a32c9748420bd4a195c0228037343acf471c3 | 55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5 | /src/topology/subset_properties.lean | 7c059119adb5df9a7d49d816efd1949ac01bd3fa | [
"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 | 54,818 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov
-/
import topology.continuous_on
import data.finset.order
/-!
# Properties of subsets of topological spaces
## Main definitions
`compact`, `is_clopen`, `is_irreducible`, `is_connected`, `is_totally_disconnected`,
`is_totally_separated`
TODO: write better docs
## On the definition of irreducible and connected sets/spaces
In informal mathematics, irreducible and connected spaces are assumed to be nonempty.
We formalise the predicate without that assumption
as `is_preirreducible` and `is_preconnected` respectively.
In other words, the only difference is whether the empty space
counts as irreducible and/or connected.
There are good reasons to consider the empty space to be “too simple to be simple”
See also https://ncatlab.org/nlab/show/too+simple+to+be+simple,
and in particular
https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions.
-/
open set filter classical
open_locale classical topological_space filter
universes u v
variables {α : Type u} {β : Type v} [topological_space α]
/- compact sets -/
section compact
/-- A set `s` is compact if for every filter `f` that contains `s`,
every set of `f` also meets every neighborhood of some `a ∈ s`. -/
def is_compact (s : set α) := ∀ ⦃f⦄ [ne_bot f], f ≤ 𝓟 s → ∃a∈s, cluster_pt a f
lemma is_compact.inter_right {s t : set α} (hs : is_compact s) (ht : is_closed t) :
is_compact (s ∩ t) :=
begin
introsI f hnf hstf,
obtain ⟨a, hsa, ha⟩ : ∃ a ∈ s, cluster_pt a f :=
hs (le_trans hstf (le_principal_iff.2 (inter_subset_left _ _))),
have : a ∈ t :=
(ht.mem_of_nhds_within_ne_bot $ ha.mono $
le_trans hstf (le_principal_iff.2 (inter_subset_right _ _))),
exact ⟨a, ⟨hsa, this⟩, ha⟩
end
lemma is_compact.inter_left {s t : set α} (ht : is_compact t) (hs : is_closed s) : is_compact (s ∩ t) :=
inter_comm t s ▸ ht.inter_right hs
lemma compact_diff {s t : set α} (hs : is_compact s) (ht : is_open t) : is_compact (s \ t) :=
hs.inter_right (is_closed_compl_iff.mpr ht)
lemma compact_of_is_closed_subset {s t : set α}
(hs : is_compact s) (ht : is_closed t) (h : t ⊆ s) : is_compact t :=
inter_eq_self_of_subset_right h ▸ hs.inter_right ht
lemma is_compact.adherence_nhdset {s t : set α} {f : filter α}
(hs : is_compact s) (hf₂ : f ≤ 𝓟 s) (ht₁ : is_open t) (ht₂ : ∀a∈s, cluster_pt a f → a ∈ t) :
t ∈ f :=
classical.by_cases mem_sets_of_eq_bot $
assume : f ⊓ 𝓟 tᶜ ≠ ⊥,
let ⟨a, ha, (hfa : cluster_pt a $ f ⊓ 𝓟 tᶜ)⟩ := @@hs this $ inf_le_left_of_le hf₂ in
have a ∈ t,
from ht₂ a ha (hfa.of_inf_left),
have tᶜ ∩ t ∈ nhds_within a (tᶜ),
from inter_mem_nhds_within _ (mem_nhds_sets ht₁ this),
have A : nhds_within a tᶜ = ⊥,
from empty_in_sets_eq_bot.1 $ compl_inter_self t ▸ this,
have nhds_within a tᶜ ≠ ⊥,
from hfa.of_inf_right,
absurd A this
lemma compact_iff_ultrafilter_le_nhds {s : set α} :
is_compact s ↔ (∀f, is_ultrafilter f → f ≤ 𝓟 s → ∃a∈s, f ≤ 𝓝 a) :=
⟨assume hs : is_compact s, assume f hf hfs,
let ⟨a, ha, h⟩ := @hs _ hf.left hfs in
⟨a, ha, le_of_ultrafilter hf h⟩,
assume hs : (∀f, is_ultrafilter f → f ≤ 𝓟 s → ∃a∈s, f ≤ 𝓝 a),
assume f hf hfs,
let ⟨a, ha, (h : ultrafilter_of f ≤ 𝓝 a)⟩ :=
hs (ultrafilter_of f) (ultrafilter_ultrafilter_of' hf) (le_trans ultrafilter_of_le hfs) in
have cluster_pt a (ultrafilter_of f),
from cluster_pt.of_le_nhds' h (ultrafilter_ultrafilter_of' hf).left,
⟨a, ha, this.mono ultrafilter_of_le⟩⟩
/-- For every open cover of a compact set, there exists a finite subcover. -/
lemma is_compact.elim_finite_subcover {s : set α} {ι : Type v} (hs : is_compact s)
(U : ι → set α) (hUo : ∀i, is_open (U i)) (hsU : s ⊆ ⋃ i, U i) :
∃ t : finset ι, s ⊆ ⋃ i ∈ t, U i :=
begin
by_contra h, push_neg at h,
set f : filter α := ⨅ t : finset ι, 𝓟 (s \ ⋃ i ∈ t, U i),
haveI hf : ne_bot f := infi_ne_bot_of_directed'
(directed_of_sup $ λ t₁ t₂ ht, principal_mono.2 $ diff_subset_diff_right $
bUnion_subset_bUnion_left ht)
(λ t, principal_ne_bot_iff.2 $ nonempty_of_not_subset (h t)),
have : f ≤ 𝓟 s := infi_le_of_le ∅ (le_principal_iff.2 (diff_subset _ _)),
obtain ⟨a, ha, h⟩ : ∃ a ∈ s, cluster_pt a f := hs this,
obtain ⟨_, ⟨i, rfl⟩, ha⟩ := hsU ha,
suffices : a ∈ (U i)ᶜ, from this ha,
have hfi : f ≤ 𝓟 (U i)ᶜ := infi_le_of_le {i} (principal_mono.2 $ by simp [diff_subset_iff]),
have hic : is_closed (U i)ᶜ := is_closed_compl_iff.2 (hUo i),
exact hic.mem_of_nhds_within_ne_bot (h.mono hfi),
end
/-- For every family of closed sets whose intersection avoids a compact set,
there exists a finite subfamily whose intersection avoids this compact set. -/
lemma is_compact.elim_finite_subfamily_closed {s : set α} {ι : Type v} (hs : is_compact s)
(Z : ι → set α) (hZc : ∀i, is_closed (Z i)) (hsZ : s ∩ (⋂ i, Z i) = ∅) :
∃ t : finset ι, s ∩ (⋂ i ∈ t, Z i) = ∅ :=
let ⟨t, ht⟩ := hs.elim_finite_subcover (λ i, (Z i)ᶜ) hZc
(by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, set.mem_Union,
exists_prop, set.mem_inter_eq, not_and, iff_self, set.mem_Inter, set.mem_compl_eq] using hsZ)
in
⟨t, by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, set.mem_Union,
exists_prop, set.mem_inter_eq, not_and, iff_self, set.mem_Inter, set.mem_compl_eq] using ht⟩
/-- Cantor's intersection theorem:
the intersection of a directed family of nonempty compact closed sets is nonempty. -/
lemma is_compact.nonempty_Inter_of_directed_nonempty_compact_closed
{ι : Type v} [hι : nonempty ι] (Z : ι → set α) (hZd : directed (⊇) Z)
(hZn : ∀ i, (Z i).nonempty) (hZc : ∀ i, is_compact (Z i)) (hZcl : ∀ i, is_closed (Z i)) :
(⋂ i, Z i).nonempty :=
begin
apply hι.elim,
intro i₀,
let Z' := λ i, Z i ∩ Z i₀,
suffices : (⋂ i, Z' i).nonempty,
{ exact nonempty.mono (Inter_subset_Inter $ assume i, inter_subset_left (Z i) (Z i₀)) this },
rw ← ne_empty_iff_nonempty,
intro H,
obtain ⟨t, ht⟩ : ∃ (t : finset ι), ((Z i₀) ∩ ⋂ (i ∈ t), Z' i) = ∅,
from (hZc i₀).elim_finite_subfamily_closed Z'
(assume i, is_closed_inter (hZcl i) (hZcl i₀)) (by rw [H, inter_empty]),
obtain ⟨i₁, hi₁⟩ : ∃ i₁ : ι, Z i₁ ⊆ Z i₀ ∧ ∀ i ∈ t, Z i₁ ⊆ Z' i,
{ rcases directed.finset_le hι hZd t with ⟨i, hi⟩,
rcases hZd i i₀ with ⟨i₁, hi₁, hi₁₀⟩,
use [i₁, hi₁₀],
intros j hj,
exact subset_inter (subset.trans hi₁ (hi j hj)) hi₁₀ },
suffices : ((Z i₀) ∩ ⋂ (i ∈ t), Z' i).nonempty,
{ rw ← ne_empty_iff_nonempty at this, contradiction },
refine nonempty.mono _ (hZn i₁),
exact subset_inter hi₁.left (subset_bInter hi₁.right)
end
/-- Cantor's intersection theorem for sequences indexed by `ℕ`:
the intersection of a decreasing sequence of nonempty compact closed sets is nonempty. -/
lemma is_compact.nonempty_Inter_of_sequence_nonempty_compact_closed
(Z : ℕ → set α) (hZd : ∀ i, Z (i+1) ⊆ Z i)
(hZn : ∀ i, (Z i).nonempty) (hZ0 : is_compact (Z 0)) (hZcl : ∀ i, is_closed (Z i)) :
(⋂ i, Z i).nonempty :=
have Zmono : _, from @monotone_of_monotone_nat (order_dual _) _ Z hZd,
have hZd : directed (⊇) Z, from directed_of_sup Zmono,
have ∀ i, Z i ⊆ Z 0, from assume i, Zmono $ zero_le i,
have hZc : ∀ i, is_compact (Z i), from assume i, compact_of_is_closed_subset hZ0 (hZcl i) (this i),
is_compact.nonempty_Inter_of_directed_nonempty_compact_closed Z hZd hZn hZc hZcl
/-- For every open cover of a compact set, there exists a finite subcover. -/
lemma is_compact.elim_finite_subcover_image {s : set α} {b : set β} {c : β → set α}
(hs : is_compact s) (hc₁ : ∀i∈b, is_open (c i)) (hc₂ : s ⊆ ⋃i∈b, c i) :
∃b'⊆b, finite b' ∧ s ⊆ ⋃i∈b', c i :=
begin
rcases hs.elim_finite_subcover (λ i, c i.1 : b → set α) _ _ with ⟨d, hd⟩,
refine ⟨↑(d.image subtype.val), _, finset.finite_to_set _, _⟩,
{ intros i hi,
erw finset.mem_image at hi,
rcases hi with ⟨s, hsd, rfl⟩,
exact s.property },
{ refine subset.trans hd _,
rintros x ⟨_, ⟨s, rfl⟩, ⟨_, ⟨hsd, rfl⟩, H⟩⟩,
refine ⟨c s.val, ⟨s.val, _⟩, H⟩,
simp [finset.mem_image_of_mem subtype.val hsd] },
{ rintro ⟨i, hi⟩, exact hc₁ i hi },
{ refine subset.trans hc₂ _,
rintros x ⟨_, ⟨i, rfl⟩, ⟨_, ⟨hib, rfl⟩, H⟩⟩,
exact ⟨_, ⟨⟨i, hib⟩, rfl⟩, H⟩ },
end
/-- A set `s` is compact if for every family of closed sets whose intersection avoids `s`,
there exists a finite subfamily whose intersection avoids `s`. -/
theorem compact_of_finite_subfamily_closed {s : set α}
(h : Π {ι : Type u} (Z : ι → (set α)), (∀ i, is_closed (Z i)) →
s ∩ (⋂ i, Z i) = ∅ → (∃ (t : finset ι), s ∩ (⋂ i ∈ t, Z i) = ∅)) :
is_compact s :=
assume f hfn hfs, classical.by_contradiction $ assume : ¬ (∃x∈s, cluster_pt x f),
have hf : ∀x∈s, 𝓝 x ⊓ f = ⊥,
by simpa only [cluster_pt, not_exists, not_not, ne_bot],
have ¬ ∃x∈s, ∀t∈f.sets, x ∈ closure t,
from assume ⟨x, hxs, hx⟩,
have ∅ ∈ 𝓝 x ⊓ f, by rw [empty_in_sets_eq_bot, hf x hxs],
let ⟨t₁, ht₁, t₂, ht₂, ht⟩ := by rw [mem_inf_sets] at this; exact this in
have ∅ ∈ 𝓝 x ⊓ 𝓟 t₂,
from (𝓝 x ⊓ 𝓟 t₂).sets_of_superset (inter_mem_inf_sets ht₁ (subset.refl t₂)) ht,
have 𝓝 x ⊓ 𝓟 t₂ = ⊥,
by rwa [empty_in_sets_eq_bot] at this,
by simp only [closure_eq_cluster_pts] at hx; exact hx t₂ ht₂ this,
let ⟨t, ht⟩ := h (λ i : f.sets, closure i.1) (λ i, is_closed_closure)
(by simpa [eq_empty_iff_forall_not_mem, not_exists]) in
have (⋂i∈t, subtype.val i) ∈ f,
from Inter_mem_sets t.finite_to_set $ assume i hi, i.2,
have s ∩ (⋂i∈t, subtype.val i) ∈ f,
from inter_mem_sets (le_principal_iff.1 hfs) this,
have ∅ ∈ f,
from mem_sets_of_superset this $ assume x ⟨hxs, hx⟩,
let ⟨i, hit, hxi⟩ := (show ∃i ∈ t, x ∉ closure (subtype.val i),
by { rw [eq_empty_iff_forall_not_mem] at ht, simpa [hxs, not_forall] using ht x }) in
have x ∈ closure i.val, from subset_closure (mem_bInter_iff.mp hx i hit),
show false, from hxi this,
hfn $ by rwa [empty_in_sets_eq_bot] at this
/-- A set `s` is compact if for every open cover of `s`, there exists a finite subcover. -/
lemma compact_of_finite_subcover {s : set α}
(h : Π {ι : Type u} (U : ι → (set α)), (∀ i, is_open (U i)) →
s ⊆ (⋃ i, U i) → (∃ (t : finset ι), s ⊆ (⋃ i ∈ t, U i))) :
is_compact s :=
compact_of_finite_subfamily_closed $
assume ι Z hZc hsZ,
let ⟨t, ht⟩ := h (λ i, (Z i)ᶜ) (assume i, is_open_compl_iff.mpr $ hZc i)
(by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, set.mem_Union,
exists_prop, set.mem_inter_eq, not_and, iff_self, set.mem_Inter, set.mem_compl_eq] using hsZ)
in
⟨t, by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, set.mem_Union,
exists_prop, set.mem_inter_eq, not_and, iff_self, set.mem_Inter, set.mem_compl_eq] using ht⟩
/-- A set `s` is compact if and only if
for every open cover of `s`, there exists a finite subcover. -/
lemma compact_iff_finite_subcover {s : set α} :
is_compact s ↔ (Π {ι : Type u} (U : ι → (set α)), (∀ i, is_open (U i)) →
s ⊆ (⋃ i, U i) → (∃ (t : finset ι), s ⊆ (⋃ i ∈ t, U i))) :=
⟨assume hs ι, hs.elim_finite_subcover, compact_of_finite_subcover⟩
/-- A set `s` is compact if and only if
for every family of closed sets whose intersection avoids `s`,
there exists a finite subfamily whose intersection avoids `s`. -/
theorem compact_iff_finite_subfamily_closed {s : set α} :
is_compact s ↔ (Π {ι : Type u} (Z : ι → (set α)), (∀ i, is_closed (Z i)) →
s ∩ (⋂ i, Z i) = ∅ → (∃ (t : finset ι), s ∩ (⋂ i ∈ t, Z i) = ∅)) :=
⟨assume hs ι, hs.elim_finite_subfamily_closed, compact_of_finite_subfamily_closed⟩
@[simp]
lemma compact_empty : is_compact (∅ : set α) :=
assume f hnf hsf, not.elim hnf $
empty_in_sets_eq_bot.1 $ le_principal_iff.1 hsf
@[simp]
lemma compact_singleton {a : α} : is_compact ({a} : set α) :=
compact_of_finite_subcover $ assume ι U hUo hsU,
let ⟨i, hai⟩ := (show ∃i : ι, a ∈ U i, from mem_Union.1 $ singleton_subset_iff.1 hsU) in
⟨{i}, singleton_subset_iff.2 (by simpa only [finset.bUnion_singleton])⟩
lemma set.finite.compact_bUnion {s : set β} {f : β → set α} (hs : finite s)
(hf : ∀i ∈ s, is_compact (f i)) :
is_compact (⋃i ∈ s, f i) :=
compact_of_finite_subcover $ assume ι U hUo hsU,
have ∀i : subtype s, ∃t : finset ι, f i ⊆ (⋃ j ∈ t, U j), from
assume ⟨i, hi⟩, (hf i hi).elim_finite_subcover _ hUo
(calc f i ⊆ ⋃i ∈ s, f i : subset_bUnion_of_mem hi
... ⊆ ⋃j, U j : hsU),
let ⟨finite_subcovers, h⟩ := axiom_of_choice this in
by haveI : fintype (subtype s) := hs.fintype; exact
let t := finset.bind finset.univ finite_subcovers in
have (⋃i ∈ s, f i) ⊆ (⋃ i ∈ t, U i), from bUnion_subset $
assume i hi, calc
f i ⊆ (⋃ j ∈ finite_subcovers ⟨i, hi⟩, U j) : (h ⟨i, hi⟩)
... ⊆ (⋃ j ∈ t, U j) : bUnion_subset_bUnion_left $
assume j hj, finset.mem_bind.mpr ⟨_, finset.mem_univ _, hj⟩,
⟨t, this⟩
lemma compact_Union {f : β → set α} [fintype β]
(h : ∀i, is_compact (f i)) : is_compact (⋃i, f i) :=
by rw ← bUnion_univ; exact finite_univ.compact_bUnion (λ i _, h i)
lemma set.finite.is_compact {s : set α} (hs : finite s) : is_compact s :=
bUnion_of_singleton s ▸ hs.compact_bUnion (λ _ _, compact_singleton)
lemma is_compact.union {s t : set α} (hs : is_compact s) (ht : is_compact t) : is_compact (s ∪ t) :=
by rw union_eq_Union; exact compact_Union (λ b, by cases b; assumption)
section tube_lemma
variables [topological_space β]
/-- `nhds_contain_boxes s t` means that any open neighborhood of `s × t` in `α × β` includes
a product of an open neighborhood of `s` by an open neighborhood of `t`. -/
def nhds_contain_boxes (s : set α) (t : set β) : Prop :=
∀ (n : set (α × β)) (hn : is_open n) (hp : set.prod s t ⊆ n),
∃ (u : set α) (v : set β), is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ set.prod u v ⊆ n
lemma nhds_contain_boxes.symm {s : set α} {t : set β} :
nhds_contain_boxes s t → nhds_contain_boxes t s :=
assume H n hn hp,
let ⟨u, v, uo, vo, su, tv, p⟩ :=
H (prod.swap ⁻¹' n)
(continuous_swap n hn)
(by rwa [←image_subset_iff, prod.swap, image_swap_prod]) in
⟨v, u, vo, uo, tv, su,
by rwa [←image_subset_iff, prod.swap, image_swap_prod] at p⟩
lemma nhds_contain_boxes.comm {s : set α} {t : set β} :
nhds_contain_boxes s t ↔ nhds_contain_boxes t s :=
iff.intro nhds_contain_boxes.symm nhds_contain_boxes.symm
lemma nhds_contain_boxes_of_singleton {x : α} {y : β} :
nhds_contain_boxes ({x} : set α) ({y} : set β) :=
assume n hn hp,
let ⟨u, v, uo, vo, xu, yv, hp'⟩ :=
is_open_prod_iff.mp hn x y (hp $ by simp) in
⟨u, v, uo, vo, by simpa, by simpa, hp'⟩
lemma nhds_contain_boxes_of_compact {s : set α} (hs : is_compact s) (t : set β)
(H : ∀ x ∈ s, nhds_contain_boxes ({x} : set α) t) : nhds_contain_boxes s t :=
assume n hn hp,
have ∀x : subtype s, ∃uv : set α × set β,
is_open uv.1 ∧ is_open uv.2 ∧ {↑x} ⊆ uv.1 ∧ t ⊆ uv.2 ∧ set.prod uv.1 uv.2 ⊆ n,
from assume ⟨x, hx⟩,
have set.prod {x} t ⊆ n, from
subset.trans (prod_mono (by simpa) (subset.refl _)) hp,
let ⟨ux,vx,H1⟩ := H x hx n hn this in ⟨⟨ux,vx⟩,H1⟩,
let ⟨uvs, h⟩ := classical.axiom_of_choice this in
have us_cover : s ⊆ ⋃i, (uvs i).1, from
assume x hx, set.subset_Union _ ⟨x,hx⟩ (by simpa using (h ⟨x,hx⟩).2.2.1),
let ⟨s0, s0_cover⟩ :=
hs.elim_finite_subcover _ (λi, (h i).1) us_cover in
let u := ⋃(i ∈ s0), (uvs i).1 in
let v := ⋂(i ∈ s0), (uvs i).2 in
have is_open u, from is_open_bUnion (λi _, (h i).1),
have is_open v, from is_open_bInter s0.finite_to_set (λi _, (h i).2.1),
have t ⊆ v, from subset_bInter (λi _, (h i).2.2.2.1),
have set.prod u v ⊆ n, from assume ⟨x',y'⟩ ⟨hx',hy'⟩,
have ∃i ∈ s0, x' ∈ (uvs i).1, by simpa using hx',
let ⟨i,is0,hi⟩ := this in
(h i).2.2.2.2 ⟨hi, (bInter_subset_of_mem is0 : v ⊆ (uvs i).2) hy'⟩,
⟨u, v, ‹is_open u›, ‹is_open v›, s0_cover, ‹t ⊆ v›, ‹set.prod u v ⊆ n›⟩
lemma generalized_tube_lemma {s : set α} (hs : is_compact s) {t : set β} (ht : is_compact t)
{n : set (α × β)} (hn : is_open n) (hp : set.prod s t ⊆ n) :
∃ (u : set α) (v : set β), is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ set.prod u v ⊆ n :=
have _, from
nhds_contain_boxes_of_compact hs t $ assume x _, nhds_contain_boxes.symm $
nhds_contain_boxes_of_compact ht {x} $ assume y _, nhds_contain_boxes_of_singleton,
this n hn hp
end tube_lemma
/-- Type class for compact spaces. Separation is sometimes included in the definition, especially
in the French literature, but we do not include it here. -/
class compact_space (α : Type*) [topological_space α] : Prop :=
(compact_univ : is_compact (univ : set α))
lemma compact_univ [h : compact_space α] : is_compact (univ : set α) := h.compact_univ
lemma cluster_point_of_compact [compact_space α]
(f : filter α) [ne_bot f] : ∃ x, cluster_pt x f :=
by simpa using compact_univ (by simpa using f.univ_sets)
theorem compact_space_of_finite_subfamily_closed {α : Type u} [topological_space α]
(h : Π {ι : Type u} (Z : ι → (set α)), (∀ i, is_closed (Z i)) →
(⋂ i, Z i) = ∅ → (∃ (t : finset ι), (⋂ i ∈ t, Z i) = ∅)) :
compact_space α :=
{ compact_univ :=
begin
apply compact_of_finite_subfamily_closed,
intros ι Z, specialize h Z,
simpa using h
end }
lemma is_closed.compact [compact_space α] {s : set α} (h : is_closed s) :
is_compact s :=
compact_of_is_closed_subset compact_univ h (subset_univ _)
variables [topological_space β]
lemma is_compact.image_of_continuous_on {s : set α} {f : α → β} (hs : is_compact s)
(hf : continuous_on f s) : is_compact (f '' s) :=
begin
intros l lne ls,
have : ne_bot (l.comap f ⊓ 𝓟 s) :=
comap_inf_principal_ne_bot_of_image_mem lne (le_principal_iff.1 ls),
obtain ⟨a, has, ha⟩ : ∃ a ∈ s, cluster_pt a (l.comap f ⊓ 𝓟 s) := @@hs this inf_le_right,
use [f a, mem_image_of_mem f has],
have : tendsto f (𝓝 a ⊓ (comap f l ⊓ 𝓟 s)) (𝓝 (f a) ⊓ l),
{ convert (hf a has).inf (@tendsto_comap _ _ f l) using 1,
rw nhds_within,
ac_refl },
exact @@tendsto.ne_bot _ this ha,
end
lemma is_compact.image {s : set α} {f : α → β} (hs : is_compact s) (hf : continuous f) :
is_compact (f '' s) :=
hs.image_of_continuous_on hf.continuous_on
lemma compact_range [compact_space α] {f : α → β} (hf : continuous f) :
is_compact (range f) :=
by rw ← image_univ; exact compact_univ.image hf
local notation `𝓟` := principal
/-- If X is is_compact then pr₂ : X × Y → Y is a closed map -/
theorem is_closed_proj_of_compact
{X : Type*} [topological_space X] [compact_space X]
{Y : Type*} [topological_space Y] :
is_closed_map (prod.snd : X × Y → Y) :=
begin
set πX := (prod.fst : X × Y → X),
set πY := (prod.snd : X × Y → Y),
assume C (hC : is_closed C),
rw is_closed_iff_cluster_pt at hC ⊢,
assume y (y_closure : cluster_pt y $ 𝓟 (πY '' C)),
have : ne_bot (map πX (comap πY (𝓝 y) ⊓ 𝓟 C)),
{ suffices : ne_bot (map πY (comap πY (𝓝 y) ⊓ 𝓟 C)),
by simpa only [map_ne_bot_iff],
calc map πY (comap πY (𝓝 y) ⊓ 𝓟 C) =
𝓝 y ⊓ map πY (𝓟 C) : filter.push_pull' _ _ _
... = 𝓝 y ⊓ 𝓟 (πY '' C) : by rw map_principal
... ≠ ⊥ : y_closure },
resetI,
obtain ⟨x, hx⟩ : ∃ x, cluster_pt x (map πX (comap πY (𝓝 y) ⊓ 𝓟 C)),
from cluster_point_of_compact _,
refine ⟨⟨x, y⟩, _, by simp [πY]⟩,
apply hC,
rw [cluster_pt, ← filter.map_ne_bot_iff πX],
calc map πX (𝓝 (x, y) ⊓ 𝓟 C)
= map πX (comap πX (𝓝 x) ⊓ comap πY (𝓝 y) ⊓ 𝓟 C) : by rw [nhds_prod_eq, filter.prod]
... = map πX (comap πY (𝓝 y) ⊓ 𝓟 C ⊓ comap πX (𝓝 x)) : by ac_refl
... = map πX (comap πY (𝓝 y) ⊓ 𝓟 C) ⊓ 𝓝 x : by rw filter.push_pull
... = 𝓝 x ⊓ map πX (comap πY (𝓝 y) ⊓ 𝓟 C) : by rw inf_comm
... ≠ ⊥ : hx,
end
lemma embedding.compact_iff_compact_image {s : set α} {f : α → β} (hf : embedding f) :
is_compact s ↔ is_compact (f '' s) :=
iff.intro (assume h, h.image hf.continuous) $ assume h, begin
rw compact_iff_ultrafilter_le_nhds at ⊢ h,
intros u hu us',
let u' : filter β := map f u,
have : u' ≤ 𝓟 (f '' s), begin
rw [map_le_iff_le_comap, comap_principal], convert us',
exact preimage_image_eq _ hf.inj
end,
rcases h u' (ultrafilter_map hu) this with ⟨_, ⟨a, ha, ⟨⟩⟩, _⟩,
refine ⟨a, ha, _⟩,
rwa [hf.induced, nhds_induced, ←map_le_iff_le_comap]
end
lemma compact_iff_compact_in_subtype {p : α → Prop} {s : set {a // p a}} :
is_compact s ↔ is_compact ((coe : _ → α) '' s) :=
embedding_subtype_coe.compact_iff_compact_image
lemma compact_iff_compact_univ {s : set α} : is_compact s ↔ is_compact (univ : set s) :=
by rw [compact_iff_compact_in_subtype, image_univ, subtype.range_coe]; refl
lemma compact_iff_compact_space {s : set α} : is_compact s ↔ compact_space s :=
compact_iff_compact_univ.trans ⟨λ h, ⟨h⟩, @compact_space.compact_univ _ _⟩
lemma is_compact.prod {s : set α} {t : set β} (hs : is_compact s) (ht : is_compact t) :
is_compact (set.prod s t) :=
begin
rw compact_iff_ultrafilter_le_nhds at hs ht ⊢,
intros f hf hfs,
rw le_principal_iff at hfs,
rcases hs (map prod.fst f) (ultrafilter_map hf)
(le_principal_iff.2 (mem_map_sets_iff.2
⟨_, hfs, image_subset_iff.2 (λ s h, h.1)⟩)) with ⟨a, sa, ha⟩,
rcases ht (map prod.snd f) (ultrafilter_map hf)
(le_principal_iff.2 (mem_map_sets_iff.2
⟨_, hfs, image_subset_iff.2 (λ s h, h.2)⟩)) with ⟨b, tb, hb⟩,
rw map_le_iff_le_comap at ha hb,
refine ⟨⟨a, b⟩, ⟨sa, tb⟩, _⟩,
rw nhds_prod_eq, exact le_inf ha hb
end
/-- Finite topological spaces are compact. -/
@[priority 100] instance fintype.compact_space [fintype α] : compact_space α :=
{ compact_univ := set.finite_univ.is_compact }
/-- The product of two compact spaces is compact. -/
instance [compact_space α] [compact_space β] : compact_space (α × β) :=
⟨by { rw ← univ_prod_univ, exact compact_univ.prod compact_univ }⟩
/-- The disjoint union of two compact spaces is compact. -/
instance [compact_space α] [compact_space β] : compact_space (α ⊕ β) :=
⟨begin
rw ← range_inl_union_range_inr,
exact (compact_range continuous_inl).union (compact_range continuous_inr)
end⟩
section tychonoff
variables {ι : Type*} {π : ι → Type*} [∀i, topological_space (π i)]
/-- Tychonoff's theorem -/
lemma compact_pi_infinite {s : Πi:ι, set (π i)} :
(∀i, is_compact (s i)) → is_compact {x : Πi:ι, π i | ∀i, x i ∈ s i} :=
begin
simp [compact_iff_ultrafilter_le_nhds, nhds_pi],
exact assume h f hf hfs,
let p : Πi:ι, filter (π i) := λi, map (λx:Πi:ι, π i, x i) f in
have ∀i:ι, ∃a, a∈s i ∧ p i ≤ 𝓝 a,
from assume i, h i (p i) (ultrafilter_map hf) $
show (λx:Πi:ι, π i, x i) ⁻¹' s i ∈ f.sets,
from mem_sets_of_superset hfs $ assume x (hx : ∀i, x i ∈ s i), hx i,
let ⟨a, ha⟩ := classical.axiom_of_choice this in
⟨a, assume i, (ha i).left, assume i, map_le_iff_le_comap.mp $ (ha i).right⟩
end
/-- A version of Tychonoff's theorem that uses `set.pi`. -/
lemma compact_univ_pi {s : Πi:ι, set (π i)} (h : ∀i, is_compact (s i)) : is_compact (set.pi set.univ s) :=
by { convert compact_pi_infinite h, simp only [pi, forall_prop_of_true, mem_univ] }
instance pi.compact [∀i:ι, compact_space (π i)] : compact_space (Πi, π i) :=
⟨begin
have A : is_compact {x : Πi:ι, π i | ∀i, x i ∈ (univ : set (π i))} :=
compact_pi_infinite (λi, compact_univ),
have : {x : Πi:ι, π i | ∀i, x i ∈ (univ : set (π i))} = univ := by ext; simp,
rwa this at A,
end⟩
end tychonoff
instance quot.compact_space {r : α → α → Prop} [compact_space α] :
compact_space (quot r) :=
⟨by { rw ← range_quot_mk, exact compact_range continuous_quot_mk }⟩
instance quotient.compact_space {s : setoid α} [compact_space α] :
compact_space (quotient s) :=
quot.compact_space
/-- There are various definitions of "locally compact space" in the literature, which agree for
Hausdorff spaces but not in general. This one is the precise condition on X needed for the
evaluation `map C(X, Y) × X → Y` to be continuous for all `Y` when `C(X, Y)` is given the
compact-open topology. -/
class locally_compact_space (α : Type*) [topological_space α] : Prop :=
(local_compact_nhds : ∀ (x : α) (n ∈ 𝓝 x), ∃ s ∈ 𝓝 x, s ⊆ n ∧ is_compact s)
/-- A reformulation of the definition of locally compact space: In a locally compact space,
every open set containing `x` has a compact subset containing `x` in its interior. -/
lemma exists_compact_subset [locally_compact_space α] {x : α} {U : set α}
(hU : is_open U) (hx : x ∈ U) : ∃ (K : set α), is_compact K ∧ x ∈ interior K ∧ K ⊆ U :=
begin
rcases locally_compact_space.local_compact_nhds x U _ with ⟨K, h1K, h2K, h3K⟩,
{ refine ⟨K, h3K, _, h2K⟩, rwa [ mem_interior_iff_mem_nhds] },
rwa [← mem_interior_iff_mem_nhds, interior_eq_of_open hU]
end
end compact
section clopen
/-- A set is clopen if it is both open and closed. -/
def is_clopen (s : set α) : Prop :=
is_open s ∧ is_closed s
theorem is_clopen_union {s t : set α} (hs : is_clopen s) (ht : is_clopen t) : is_clopen (s ∪ t) :=
⟨is_open_union hs.1 ht.1, is_closed_union hs.2 ht.2⟩
theorem is_clopen_inter {s t : set α} (hs : is_clopen s) (ht : is_clopen t) : is_clopen (s ∩ t) :=
⟨is_open_inter hs.1 ht.1, is_closed_inter hs.2 ht.2⟩
@[simp] theorem is_clopen_empty : is_clopen (∅ : set α) :=
⟨is_open_empty, is_closed_empty⟩
@[simp] theorem is_clopen_univ : is_clopen (univ : set α) :=
⟨is_open_univ, is_closed_univ⟩
theorem is_clopen_compl {s : set α} (hs : is_clopen s) : is_clopen sᶜ :=
⟨hs.2, is_closed_compl_iff.2 hs.1⟩
@[simp] theorem is_clopen_compl_iff {s : set α} : is_clopen sᶜ ↔ is_clopen s :=
⟨λ h, compl_compl s ▸ is_clopen_compl h, is_clopen_compl⟩
theorem is_clopen_diff {s t : set α} (hs : is_clopen s) (ht : is_clopen t) : is_clopen (s \ t) :=
is_clopen_inter hs (is_clopen_compl ht)
end clopen
section preirreducible
/-- A preirreducible set `s` is one where there is no non-trivial pair of disjoint opens on `s`. -/
def is_preirreducible (s : set α) : Prop :=
∀ (u v : set α), is_open u → is_open v →
(s ∩ u).nonempty → (s ∩ v).nonempty → (s ∩ (u ∩ v)).nonempty
/-- An irreducible set `s` is one that is nonempty and
where there is no non-trivial pair of disjoint opens on `s`. -/
def is_irreducible (s : set α) : Prop :=
s.nonempty ∧ is_preirreducible s
lemma is_irreducible.nonempty {s : set α} (h : is_irreducible s) :
s.nonempty := h.1
lemma is_irreducible.is_preirreducible {s : set α} (h : is_irreducible s) :
is_preirreducible s := h.2
theorem is_preirreducible_empty : is_preirreducible (∅ : set α) :=
λ _ _ _ _ _ ⟨x, h1, h2⟩, h1.elim
theorem is_irreducible_singleton {x} : is_irreducible ({x} : set α) :=
⟨singleton_nonempty x,
λ u v _ _ ⟨y, h1, h2⟩ ⟨z, h3, h4⟩, by rw mem_singleton_iff at h1 h3;
substs y z; exact ⟨x, rfl, h2, h4⟩⟩
theorem is_preirreducible.closure {s : set α} (H : is_preirreducible s) :
is_preirreducible (closure s) :=
λ u v hu hv ⟨y, hycs, hyu⟩ ⟨z, hzcs, hzv⟩,
let ⟨p, hpu, hps⟩ := mem_closure_iff.1 hycs u hu hyu in
let ⟨q, hqv, hqs⟩ := mem_closure_iff.1 hzcs v hv hzv in
let ⟨r, hrs, hruv⟩ := H u v hu hv ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ in
⟨r, subset_closure hrs, hruv⟩
lemma is_irreducible.closure {s : set α} (h : is_irreducible s) :
is_irreducible (closure s) :=
⟨h.nonempty.closure, h.is_preirreducible.closure⟩
theorem exists_preirreducible (s : set α) (H : is_preirreducible s) :
∃ t : set α, is_preirreducible t ∧ s ⊆ t ∧ ∀ u, is_preirreducible u → t ⊆ u → u = t :=
let ⟨m, hm, hsm, hmm⟩ := zorn.zorn_subset₀ {t : set α | is_preirreducible t}
(λ c hc hcc hcn, let ⟨t, htc⟩ := hcn in
⟨⋃₀ c, λ u v hu hv ⟨y, hy, hyu⟩ ⟨z, hz, hzv⟩,
let ⟨p, hpc, hyp⟩ := mem_sUnion.1 hy,
⟨q, hqc, hzq⟩ := mem_sUnion.1 hz in
or.cases_on (zorn.chain.total hcc hpc hqc)
(assume hpq : p ⊆ q, let ⟨x, hxp, hxuv⟩ := hc hqc u v hu hv
⟨y, hpq hyp, hyu⟩ ⟨z, hzq, hzv⟩ in
⟨x, mem_sUnion_of_mem hxp hqc, hxuv⟩)
(assume hqp : q ⊆ p, let ⟨x, hxp, hxuv⟩ := hc hpc u v hu hv
⟨y, hyp, hyu⟩ ⟨z, hqp hzq, hzv⟩ in
⟨x, mem_sUnion_of_mem hxp hpc, hxuv⟩),
λ x hxc, set.subset_sUnion_of_mem hxc⟩) s H in
⟨m, hm, hsm, λ u hu hmu, hmm _ hu hmu⟩
/-- A maximal irreducible set that contains a given point. -/
def irreducible_component (x : α) : set α :=
classical.some (exists_preirreducible {x} is_irreducible_singleton.is_preirreducible)
lemma irreducible_component_property (x : α) :
is_preirreducible (irreducible_component x) ∧ {x} ⊆ (irreducible_component x) ∧
∀ u, is_preirreducible u → (irreducible_component x) ⊆ u → u = (irreducible_component x) :=
classical.some_spec (exists_preirreducible {x} is_irreducible_singleton.is_preirreducible)
theorem mem_irreducible_component {x : α} : x ∈ irreducible_component x :=
singleton_subset_iff.1 (irreducible_component_property x).2.1
theorem is_irreducible_irreducible_component {x : α} : is_irreducible (irreducible_component x) :=
⟨⟨x, mem_irreducible_component⟩, (irreducible_component_property x).1⟩
theorem eq_irreducible_component {x : α} :
∀ {s : set α}, is_preirreducible s → irreducible_component x ⊆ s → s = irreducible_component x :=
(irreducible_component_property x).2.2
theorem is_closed_irreducible_component {x : α} :
is_closed (irreducible_component x) :=
closure_eq_iff_is_closed.1 $ eq_irreducible_component
is_irreducible_irreducible_component.is_preirreducible.closure
subset_closure
/-- A preirreducible space is one where there is no non-trivial pair of disjoint opens. -/
class preirreducible_space (α : Type u) [topological_space α] : Prop :=
(is_preirreducible_univ [] : is_preirreducible (univ : set α))
section prio
set_option default_priority 100 -- see Note [default priority]
/-- An irreducible space is one that is nonempty
and where there is no non-trivial pair of disjoint opens. -/
class irreducible_space (α : Type u) [topological_space α] extends preirreducible_space α : Prop :=
(to_nonempty [] : nonempty α)
end prio
attribute [instance, priority 50] irreducible_space.to_nonempty -- see Note [lower instance priority]
theorem nonempty_preirreducible_inter [preirreducible_space α] {s t : set α} :
is_open s → is_open t → s.nonempty → t.nonempty → (s ∩ t).nonempty :=
by simpa only [univ_inter, univ_subset_iff] using
@preirreducible_space.is_preirreducible_univ α _ _ s t
theorem is_preirreducible.image [topological_space β] {s : set α} (H : is_preirreducible s)
(f : α → β) (hf : continuous_on f s) : is_preirreducible (f '' s) :=
begin
rintros u v hu hv ⟨_, ⟨⟨x, hx, rfl⟩, hxu⟩⟩ ⟨_, ⟨⟨y, hy, rfl⟩, hyv⟩⟩,
rw ← set.mem_preimage at hxu hyv,
rcases continuous_on_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩,
rcases continuous_on_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩,
have := H u' v' hu' hv',
rw [set.inter_comm s u', ← u'_eq] at this,
rw [set.inter_comm s v', ← v'_eq] at this,
rcases this ⟨x, hxu, hx⟩ ⟨y, hyv, hy⟩ with ⟨z, hzs, hzu', hzv'⟩,
refine ⟨f z, mem_image_of_mem f hzs, _, _⟩,
all_goals
{ rw ← set.mem_preimage,
apply set.mem_of_mem_inter_left,
show z ∈ _ ∩ s,
simp [*] }
end
theorem is_irreducible.image [topological_space β] {s : set α} (H : is_irreducible s)
(f : α → β) (hf : continuous_on f s) : is_irreducible (f '' s) :=
⟨nonempty_image_iff.mpr H.nonempty, H.is_preirreducible.image f hf⟩
lemma subtype.preirreducible_space {s : set α} (h : is_preirreducible s) :
preirreducible_space s :=
{ is_preirreducible_univ :=
begin
intros u v hu hv hsu hsv,
rw is_open_induced_iff at hu hv,
rcases hu with ⟨u, hu, rfl⟩,
rcases hv with ⟨v, hv, rfl⟩,
rcases hsu with ⟨⟨x, hxs⟩, hxs', hxu⟩,
rcases hsv with ⟨⟨y, hys⟩, hys', hyv⟩,
rcases h u v hu hv ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩ with ⟨z, hzs, ⟨hzu, hzv⟩⟩,
exact ⟨⟨z, hzs⟩, ⟨set.mem_univ _, ⟨hzu, hzv⟩⟩⟩
end }
lemma subtype.irreducible_space {s : set α} (h : is_irreducible s) :
irreducible_space s :=
{ is_preirreducible_univ :=
(subtype.preirreducible_space h.is_preirreducible).is_preirreducible_univ,
to_nonempty := h.nonempty.to_subtype }
/-- A set `s` is irreducible if and only if
for every finite collection of open sets all of whose members intersect `s`,
`s` also intersects the intersection of the entire collection
(i.e., there is an element of `s` contained in every member of the collection). -/
lemma is_irreducible_iff_sInter {s : set α} :
is_irreducible s ↔
∀ (U : finset (set α)) (hU : ∀ u ∈ U, is_open u) (H : ∀ u ∈ U, (s ∩ u).nonempty),
(s ∩ ⋂₀ ↑U).nonempty :=
begin
split; intro h,
{ intro U, apply finset.induction_on U,
{ intros, simpa using h.nonempty },
{ intros u U hu IH hU H,
rw [finset.coe_insert, sInter_insert],
apply h.2,
{ solve_by_elim [finset.mem_insert_self] },
{ apply is_open_sInter (finset.finite_to_set U),
intros, solve_by_elim [finset.mem_insert_of_mem] },
{ solve_by_elim [finset.mem_insert_self] },
{ apply IH,
all_goals { intros, solve_by_elim [finset.mem_insert_of_mem] } } } },
{ split,
{ simpa using h ∅ _ _; intro u; simp },
intros u v hu hv hu' hv',
simpa using h {u,v} _ _,
all_goals
{ intro t,
rw [finset.mem_insert, finset.mem_singleton],
rintro (rfl|rfl); assumption } }
end
/-- A set is preirreducible if and only if
for every cover by two closed sets, it is contained in one of the two covering sets. -/
lemma is_preirreducible_iff_closed_union_closed {s : set α} :
is_preirreducible s ↔
∀ (z₁ z₂ : set α), is_closed z₁ → is_closed z₂ → s ⊆ z₁ ∪ z₂ → s ⊆ z₁ ∨ s ⊆ z₂ :=
begin
split,
all_goals
{ intros h t₁ t₂ ht₁ ht₂,
specialize h t₁ᶜ t₂ᶜ,
simp only [is_open_compl_iff, is_closed_compl_iff] at h,
specialize h ht₁ ht₂ },
{ contrapose!, simp only [not_subset],
rintro ⟨⟨x, hx, hx'⟩, ⟨y, hy, hy'⟩⟩,
rcases h ⟨x, hx, hx'⟩ ⟨y, hy, hy'⟩ with ⟨z, hz, hz'⟩,
rw ← compl_union at hz',
exact ⟨z, hz, hz'⟩ },
{ rintro ⟨x, hx, hx'⟩ ⟨y, hy, hy'⟩,
rw ← compl_inter at h,
delta set.nonempty,
rw imp_iff_not_or at h,
contrapose! h,
split,
{ intros z hz hz', exact h z ⟨hz, hz'⟩ },
{ split; intro H; refine H _ ‹_›; assumption } }
end
/-- A set is irreducible if and only if
for every cover by a finite collection of closed sets,
it is contained in one of the members of the collection. -/
lemma is_irreducible_iff_sUnion_closed {s : set α} :
is_irreducible s ↔
∀ (Z : finset (set α)) (hZ : ∀ z ∈ Z, is_closed z) (H : s ⊆ ⋃₀ ↑Z),
∃ z ∈ Z, s ⊆ z :=
begin
rw [is_irreducible, is_preirreducible_iff_closed_union_closed],
split; intro h,
{ intro Z, apply finset.induction_on Z,
{ intros, rw [finset.coe_empty, sUnion_empty] at H,
rcases h.1 with ⟨x, hx⟩,
exfalso, tauto },
{ intros z Z hz IH hZ H,
cases h.2 z (⋃₀ ↑Z) _ _ _
with h' h',
{ exact ⟨z, finset.mem_insert_self _ _, h'⟩ },
{ rcases IH _ h' with ⟨z', hz', hsz'⟩,
{ exact ⟨z', finset.mem_insert_of_mem hz', hsz'⟩ },
{ intros, solve_by_elim [finset.mem_insert_of_mem] } },
{ solve_by_elim [finset.mem_insert_self] },
{ rw sUnion_eq_bUnion,
apply is_closed_bUnion (finset.finite_to_set Z),
{ intros, solve_by_elim [finset.mem_insert_of_mem] } },
{ simpa using H } } },
{ split,
{ by_contradiction hs,
simpa using h ∅ _ _,
{ intro z, simp },
{ simpa [set.nonempty] using hs } },
intros z₁ z₂ hz₁ hz₂ H,
have := h {z₁, z₂} _ _,
simp only [exists_prop, finset.mem_insert, finset.mem_singleton] at this,
{ rcases this with ⟨z, rfl|rfl, hz⟩; tauto },
{ intro t,
rw [finset.mem_insert, finset.mem_singleton],
rintro (rfl|rfl); assumption },
{ simpa using H } }
end
end preirreducible
section preconnected
/-- A preconnected set is one where there is no non-trivial open partition. -/
def is_preconnected (s : set α) : Prop :=
∀ (u v : set α), is_open u → is_open v → s ⊆ u ∪ v →
(s ∩ u).nonempty → (s ∩ v).nonempty → (s ∩ (u ∩ v)).nonempty
/-- A connected set is one that is nonempty and where there is no non-trivial open partition. -/
def is_connected (s : set α) : Prop :=
s.nonempty ∧ is_preconnected s
lemma is_connected.nonempty {s : set α} (h : is_connected s) :
s.nonempty := h.1
lemma is_connected.is_preconnected {s : set α} (h : is_connected s) :
is_preconnected s := h.2
theorem is_preirreducible.is_preconnected {s : set α} (H : is_preirreducible s) :
is_preconnected s :=
λ _ _ hu hv _, H _ _ hu hv
theorem is_irreducible.is_connected {s : set α} (H : is_irreducible s) : is_connected s :=
⟨H.nonempty, H.is_preirreducible.is_preconnected⟩
theorem is_preconnected_empty : is_preconnected (∅ : set α) :=
is_preirreducible_empty.is_preconnected
theorem is_connected_singleton {x} : is_connected ({x} : set α) :=
is_irreducible_singleton.is_connected
/-- If any point of a set is joined to a fixed point by a preconnected subset,
then the original set is preconnected as well. -/
theorem is_preconnected_of_forall {s : set α} (x : α)
(H : ∀ y ∈ s, ∃ t ⊆ s, x ∈ t ∧ y ∈ t ∧ is_preconnected t) :
is_preconnected s :=
begin
rintros u v hu hv hs ⟨z, zs, zu⟩ ⟨y, ys, yv⟩,
have xs : x ∈ s, by { rcases H y ys with ⟨t, ts, xt, yt, ht⟩, exact ts xt },
wlog xu : x ∈ u := hs xs using [u v y z, v u z y],
rcases H y ys with ⟨t, ts, xt, yt, ht⟩,
have := ht u v hu hv(subset.trans ts hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩,
exact this.imp (λ z hz, ⟨ts hz.1, hz.2⟩)
end
/-- If any two points of a set are contained in a preconnected subset,
then the original set is preconnected as well. -/
theorem is_preconnected_of_forall_pair {s : set α}
(H : ∀ x y ∈ s, ∃ t ⊆ s, x ∈ t ∧ y ∈ t ∧ is_preconnected t) :
is_preconnected s :=
begin
rintros u v hu hv hs ⟨x, xs, xu⟩ ⟨y, ys, yv⟩,
rcases H x y xs ys with ⟨t, ts, xt, yt, ht⟩,
have := ht u v hu hv(subset.trans ts hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩,
exact this.imp (λ z hz, ⟨ts hz.1, hz.2⟩)
end
/-- A union of a family of preconnected sets with a common point is preconnected as well. -/
theorem is_preconnected_sUnion (x : α) (c : set (set α)) (H1 : ∀ s ∈ c, x ∈ s)
(H2 : ∀ s ∈ c, is_preconnected s) : is_preconnected (⋃₀ c) :=
begin
apply is_preconnected_of_forall x,
rintros y ⟨s, sc, ys⟩,
exact ⟨s, subset_sUnion_of_mem sc, H1 s sc, ys, H2 s sc⟩
end
theorem is_preconnected.union (x : α) {s t : set α} (H1 : x ∈ s) (H2 : x ∈ t)
(H3 : is_preconnected s) (H4 : is_preconnected t) : is_preconnected (s ∪ t) :=
sUnion_pair s t ▸ is_preconnected_sUnion x {s, t}
(by rintro r (rfl | rfl | h); assumption)
(by rintro r (rfl | rfl | h); assumption)
theorem is_connected.union {s t : set α} (H : (s ∩ t).nonempty)
(Hs : is_connected s) (Ht : is_connected t) : is_connected (s ∪ t) :=
begin
rcases H with ⟨x, hx⟩,
refine ⟨⟨x, mem_union_left t (mem_of_mem_inter_left hx)⟩, _⟩,
exact is_preconnected.union x (mem_of_mem_inter_left hx) (mem_of_mem_inter_right hx)
Hs.is_preconnected Ht.is_preconnected
end
theorem is_preconnected.closure {s : set α} (H : is_preconnected s) :
is_preconnected (closure s) :=
λ u v hu hv hcsuv ⟨y, hycs, hyu⟩ ⟨z, hzcs, hzv⟩,
let ⟨p, hpu, hps⟩ := mem_closure_iff.1 hycs u hu hyu in
let ⟨q, hqv, hqs⟩ := mem_closure_iff.1 hzcs v hv hzv in
let ⟨r, hrs, hruv⟩ := H u v hu hv (subset.trans subset_closure hcsuv) ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ in
⟨r, subset_closure hrs, hruv⟩
theorem is_connected.closure {s : set α} (H : is_connected s) :
is_connected (closure s) :=
⟨H.nonempty.closure, H.is_preconnected.closure⟩
theorem is_preconnected.image [topological_space β] {s : set α} (H : is_preconnected s)
(f : α → β) (hf : continuous_on f s) : is_preconnected (f '' s) :=
begin
-- Unfold/destruct definitions in hypotheses
rintros u v hu hv huv ⟨_, ⟨x, xs, rfl⟩, xu⟩ ⟨_, ⟨y, ys, rfl⟩, yv⟩,
rcases continuous_on_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩,
rcases continuous_on_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩,
-- Reformulate `huv : f '' s ⊆ u ∪ v` in terms of `u'` and `v'`
replace huv : s ⊆ u' ∪ v',
{ rw [image_subset_iff, preimage_union] at huv,
replace huv := subset_inter huv (subset.refl _),
rw [inter_distrib_right, u'_eq, v'_eq, ← inter_distrib_right] at huv,
exact (subset_inter_iff.1 huv).1 },
-- Now `s ⊆ u' ∪ v'`, so we can apply `‹is_preconnected s›`
obtain ⟨z, hz⟩ : (s ∩ (u' ∩ v')).nonempty,
{ refine H u' v' hu' hv' huv ⟨x, _⟩ ⟨y, _⟩; rw inter_comm,
exacts [u'_eq ▸ ⟨xu, xs⟩, v'_eq ▸ ⟨yv, ys⟩] },
rw [← inter_self s, inter_assoc, inter_left_comm s u', ← inter_assoc,
inter_comm s, inter_comm s, ← u'_eq, ← v'_eq] at hz,
exact ⟨f z, ⟨z, hz.1.2, rfl⟩, hz.1.1, hz.2.1⟩
end
theorem is_connected.image [topological_space β] {s : set α} (H : is_connected s)
(f : α → β) (hf : continuous_on f s) : is_connected (f '' s) :=
⟨nonempty_image_iff.mpr H.nonempty, H.is_preconnected.image f hf⟩
theorem is_preconnected_closed_iff {s : set α} :
is_preconnected s ↔ ∀ t t', is_closed t → is_closed t' → s ⊆ t ∪ t' →
(s ∩ t).nonempty → (s ∩ t').nonempty → (s ∩ (t ∩ t')).nonempty :=
⟨begin
rintros h t t' ht ht' htt' ⟨x, xs, xt⟩ ⟨y, ys, yt'⟩,
by_contradiction h',
rw [← ne_empty_iff_nonempty, ne.def, not_not, ← subset_compl_iff_disjoint, compl_inter] at h',
have xt' : x ∉ t', from (h' xs).elim (absurd xt) id,
have yt : y ∉ t, from (h' ys).elim id (absurd yt'),
have := ne_empty_iff_nonempty.2 (h tᶜ t'ᶜ (is_open_compl_iff.2 ht)
(is_open_compl_iff.2 ht') h' ⟨y, ys, yt⟩ ⟨x, xs, xt'⟩),
rw [ne.def, ← compl_union, ← subset_compl_iff_disjoint, compl_compl] at this,
contradiction
end,
begin
rintros h u v hu hv huv ⟨x, xs, xu⟩ ⟨y, ys, yv⟩,
by_contradiction h',
rw [← ne_empty_iff_nonempty, ne.def, not_not,
← subset_compl_iff_disjoint, compl_inter] at h',
have xv : x ∉ v, from (h' xs).elim (absurd xu) id,
have yu : y ∉ u, from (h' ys).elim id (absurd yv),
have := ne_empty_iff_nonempty.2 (h uᶜ vᶜ (is_closed_compl_iff.2 hu)
(is_closed_compl_iff.2 hv) h' ⟨y, ys, yu⟩ ⟨x, xs, xv⟩),
rw [ne.def, ← compl_union, ← subset_compl_iff_disjoint, compl_compl] at this,
contradiction
end⟩
/-- The connected component of a point is the maximal connected set
that contains this point. -/
def connected_component (x : α) : set α :=
⋃₀ { s : set α | is_preconnected s ∧ x ∈ s }
theorem mem_connected_component {x : α} : x ∈ connected_component x :=
mem_sUnion_of_mem (mem_singleton x) ⟨is_connected_singleton.is_preconnected, mem_singleton x⟩
theorem is_connected_connected_component {x : α} : is_connected (connected_component x) :=
⟨⟨x, mem_connected_component⟩, is_preconnected_sUnion x _ (λ _, and.right) (λ _, and.left)⟩
theorem subset_connected_component {x : α} {s : set α} (H1 : is_preconnected s) (H2 : x ∈ s) :
s ⊆ connected_component x :=
λ z hz, mem_sUnion_of_mem hz ⟨H1, H2⟩
theorem is_closed_connected_component {x : α} :
is_closed (connected_component x) :=
closure_eq_iff_is_closed.1 $ subset.antisymm
(subset_connected_component
is_connected_connected_component.closure.is_preconnected
(subset_closure mem_connected_component))
subset_closure
theorem irreducible_component_subset_connected_component {x : α} :
irreducible_component x ⊆ connected_component x :=
subset_connected_component
is_irreducible_irreducible_component.is_connected.is_preconnected
mem_irreducible_component
/-- A preconnected space is one where there is no non-trivial open partition. -/
class preconnected_space (α : Type u) [topological_space α] : Prop :=
(is_preconnected_univ : is_preconnected (univ : set α))
export preconnected_space (is_preconnected_univ)
section prio
set_option default_priority 100 -- see Note [default priority]
/-- A connected space is a nonempty one where there is no non-trivial open partition. -/
class connected_space (α : Type u) [topological_space α] extends preconnected_space α : Prop :=
(to_nonempty : nonempty α)
end prio
attribute [instance, priority 50] connected_space.to_nonempty -- see Note [lower instance priority]
@[priority 100] -- see Note [lower instance priority]
instance preirreducible_space.preconnected_space (α : Type u) [topological_space α]
[preirreducible_space α] : preconnected_space α :=
⟨(preirreducible_space.is_preirreducible_univ α).is_preconnected⟩
@[priority 100] -- see Note [lower instance priority]
instance irreducible_space.connected_space (α : Type u) [topological_space α]
[irreducible_space α] : connected_space α :=
{ to_nonempty := irreducible_space.to_nonempty α }
theorem nonempty_inter [preconnected_space α] {s t : set α} :
is_open s → is_open t → s ∪ t = univ → s.nonempty → t.nonempty → (s ∩ t).nonempty :=
by simpa only [univ_inter, univ_subset_iff] using
@preconnected_space.is_preconnected_univ α _ _ s t
theorem is_clopen_iff [preconnected_space α] {s : set α} : is_clopen s ↔ s = ∅ ∨ s = univ :=
⟨λ hs, classical.by_contradiction $ λ h,
have h1 : s ≠ ∅ ∧ sᶜ ≠ ∅, from ⟨mt or.inl h,
mt (λ h2, or.inr $ (by rw [← compl_compl s, h2, compl_empty] : s = univ)) h⟩,
let ⟨_, h2, h3⟩ := nonempty_inter hs.1 hs.2 (union_compl_self s)
(ne_empty_iff_nonempty.1 h1.1) (ne_empty_iff_nonempty.1 h1.2) in
h3 h2,
by rintro (rfl | rfl); [exact is_clopen_empty, exact is_clopen_univ]⟩
lemma subtype.preconnected_space {s : set α} (h : is_preconnected s) :
preconnected_space s :=
{ is_preconnected_univ :=
begin
intros u v hu hv hs hsu hsv,
rw is_open_induced_iff at hu hv,
rcases hu with ⟨u, hu, rfl⟩,
rcases hv with ⟨v, hv, rfl⟩,
rcases hsu with ⟨⟨x, hxs⟩, hxs', hxu⟩,
rcases hsv with ⟨⟨y, hys⟩, hys', hyv⟩,
rcases h u v hu hv _ ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩ with ⟨z, hzs, ⟨hzu, hzv⟩⟩,
exact ⟨⟨z, hzs⟩, ⟨set.mem_univ _, ⟨hzu, hzv⟩⟩⟩,
intros z hz,
rcases hs (set.mem_univ ⟨z, hz⟩) with hzu|hzv,
{ left, assumption },
{ right, assumption }
end }
lemma subtype.connected_space {s : set α} (h : is_connected s) :
connected_space s :=
{ is_preconnected_univ :=
(subtype.preconnected_space h.is_preconnected).is_preconnected_univ,
to_nonempty := h.nonempty.to_subtype }
/-- A set `s` is preconnected if and only if
for every cover by two open sets that are disjoint on `s`,
it is contained in one of the two covering sets. -/
lemma is_preconnected_iff_subset_of_disjoint {s : set α} :
is_preconnected s ↔
∀ (u v : set α) (hu : is_open u) (hv : is_open v) (hs : s ⊆ u ∪ v) (huv : s ∩ (u ∩ v) = ∅),
s ⊆ u ∨ s ⊆ v :=
begin
split; intro h,
{ intros u v hu hv hs huv,
specialize h u v hu hv hs,
contrapose! huv,
rw ne_empty_iff_nonempty,
simp [not_subset] at huv,
rcases huv with ⟨⟨x, hxs, hxu⟩, ⟨y, hys, hyv⟩⟩,
have hxv : x ∈ v := classical.or_iff_not_imp_left.mp (hs hxs) hxu,
have hyu : y ∈ u := classical.or_iff_not_imp_right.mp (hs hys) hyv,
exact h ⟨y, hys, hyu⟩ ⟨x, hxs, hxv⟩ },
{ intros u v hu hv hs hsu hsv,
rw ← ne_empty_iff_nonempty,
intro H,
specialize h u v hu hv hs H,
contrapose H,
apply ne_empty_iff_nonempty.mpr,
cases h,
{ rcases hsv with ⟨x, hxs, hxv⟩, exact ⟨x, hxs, ⟨h hxs, hxv⟩⟩ },
{ rcases hsu with ⟨x, hxs, hxu⟩, exact ⟨x, hxs, ⟨hxu, h hxs⟩⟩ } }
end
/-- A set `s` is connected if and only if
for every cover by a finite collection of open sets that are pairwise disjoint on `s`,
it is contained in one of the members of the collection. -/
lemma is_connected_iff_sUnion_disjoint_open {s : set α} :
is_connected s ↔
∀ (U : finset (set α)) (H : ∀ (u v : set α), u ∈ U → v ∈ U → (s ∩ (u ∩ v)).nonempty → u = v)
(hU : ∀ u ∈ U, is_open u) (hs : s ⊆ ⋃₀ ↑U),
∃ u ∈ U, s ⊆ u :=
begin
rw [is_connected, is_preconnected_iff_subset_of_disjoint],
split; intro h,
{ intro U, apply finset.induction_on U,
{ rcases h.left,
suffices : s ⊆ ∅ → false, { simpa },
intro, solve_by_elim },
{ intros u U hu IH hs hU H,
rw [finset.coe_insert, sUnion_insert] at H,
cases h.2 u (⋃₀ ↑U) _ _ H _ with hsu hsU,
{ exact ⟨u, finset.mem_insert_self _ _, hsu⟩ },
{ rcases IH _ _ hsU with ⟨v, hvU, hsv⟩,
{ exact ⟨v, finset.mem_insert_of_mem hvU, hsv⟩ },
{ intros, apply hs; solve_by_elim [finset.mem_insert_of_mem] },
{ intros, solve_by_elim [finset.mem_insert_of_mem] } },
{ solve_by_elim [finset.mem_insert_self] },
{ apply is_open_sUnion,
intros, solve_by_elim [finset.mem_insert_of_mem] },
{ apply eq_empty_of_subset_empty,
rintro x ⟨hxs, hxu, hxU⟩,
rw mem_sUnion at hxU,
rcases hxU with ⟨v, hvU, hxv⟩,
rcases hs u v (finset.mem_insert_self _ _) (finset.mem_insert_of_mem hvU) _ with rfl,
{ contradiction },
{ exact ⟨x, hxs, hxu, hxv⟩ } } } },
{ split,
{ rw ← ne_empty_iff_nonempty,
by_contradiction hs, push_neg at hs, subst hs,
simpa using h ∅ _ _ _; simp },
intros u v hu hv hs hsuv,
rcases h {u, v} _ _ _ with ⟨t, ht, ht'⟩,
{ rw [finset.mem_insert, finset.mem_singleton] at ht,
rcases ht with rfl|rfl; tauto },
{ intros t₁ t₂ ht₁ ht₂ hst,
rw ← ne_empty_iff_nonempty at hst,
rw [finset.mem_insert, finset.mem_singleton] at ht₁ ht₂,
rcases ht₁ with rfl|rfl; rcases ht₂ with rfl|rfl,
all_goals { refl <|> contradiction <|> skip },
rw inter_comm t₁ at hst, contradiction },
{ intro t,
rw [finset.mem_insert, finset.mem_singleton],
rintro (rfl|rfl); assumption },
{ simpa using hs } }
end
end preconnected
section totally_disconnected
/-- A set is called totally disconnected if all of its connected components are singletons. -/
def is_totally_disconnected (s : set α) : Prop :=
∀ t, t ⊆ s → is_preconnected t → subsingleton t
theorem is_totally_disconnected_empty : is_totally_disconnected (∅ : set α) :=
λ t ht _, ⟨λ ⟨_, h⟩, (ht h).elim⟩
theorem is_totally_disconnected_singleton {x} : is_totally_disconnected ({x} : set α) :=
λ t ht _, ⟨λ ⟨p, hp⟩ ⟨q, hq⟩, subtype.eq $ show p = q,
from (eq_of_mem_singleton (ht hp)).symm ▸ (eq_of_mem_singleton (ht hq)).symm⟩
/-- A space is totally disconnected if all of its connected components are singletons. -/
class totally_disconnected_space (α : Type u) [topological_space α] : Prop :=
(is_totally_disconnected_univ : is_totally_disconnected (univ : set α))
end totally_disconnected
section totally_separated
/-- A set `s` is called totally separated if any two points of this set can be separated
by two disjoint open sets covering `s`. -/
def is_totally_separated (s : set α) : Prop :=
∀ x ∈ s, ∀ y ∈ s, x ≠ y → ∃ u v : set α, is_open u ∧ is_open v ∧
x ∈ u ∧ y ∈ v ∧ s ⊆ u ∪ v ∧ u ∩ v = ∅
theorem is_totally_separated_empty : is_totally_separated (∅ : set α) :=
λ x, false.elim
theorem is_totally_separated_singleton {x} : is_totally_separated ({x} : set α) :=
λ p hp q hq hpq, (hpq $ (eq_of_mem_singleton hp).symm ▸ (eq_of_mem_singleton hq).symm).elim
theorem is_totally_disconnected_of_is_totally_separated {s : set α}
(H : is_totally_separated s) : is_totally_disconnected s :=
λ t hts ht, ⟨λ ⟨x, hxt⟩ ⟨y, hyt⟩, subtype.eq $ classical.by_contradiction $
assume hxy : x ≠ y, let ⟨u, v, hu, hv, hxu, hyv, hsuv, huv⟩ := H x (hts hxt) y (hts hyt) hxy in
let ⟨r, hrt, hruv⟩ := ht u v hu hv (subset.trans hts hsuv) ⟨x, hxt, hxu⟩ ⟨y, hyt, hyv⟩ in
(ext_iff.1 huv r).1 hruv⟩
/-- A space is totally separated if any two points can be separated by two disjoint open sets
covering the whole space. -/
class totally_separated_space (α : Type u) [topological_space α] : Prop :=
(is_totally_separated_univ [] : is_totally_separated (univ : set α))
@[priority 100] -- see Note [lower instance priority]
instance totally_separated_space.totally_disconnected_space (α : Type u) [topological_space α]
[totally_separated_space α] : totally_disconnected_space α :=
⟨is_totally_disconnected_of_is_totally_separated $ totally_separated_space.is_totally_separated_univ α⟩
end totally_separated
|
e91257453b3fb4111e8a3b0723742fbf39552d21 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/group_theory/submonoid/operations.lean | 23efc1e7ead18821d59e061139cde90c5308eedd | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 35,691 | lean | /-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Kenny Lau, Johan Commelin, Mario Carneiro, Kevin Buzzard,
Amelia Livingston, Yury Kudryashov
-/
import group_theory.submonoid.basic
import data.equiv.mul_add
import algebra.group.prod
import algebra.group.inj_surj
/-!
# Operations on `submonoid`s
In this file we define various operations on `submonoid`s and `monoid_hom`s.
## Main definitions
### Conversion between multiplicative and additive definitions
* `submonoid.to_add_submonoid`, `submonoid.to_add_submonoid'`, `add_submonoid.to_submonoid`,
`add_submonoid.to_submonoid'`: convert between multiplicative and additive submonoids of `M`,
`multiplicative M`, and `additive M`. These are stated as `order_iso`s.
### (Commutative) monoid structure on a submonoid
* `submonoid.to_monoid`, `submonoid.to_comm_monoid`: a submonoid inherits a (commutative) monoid
structure.
### Group actions by submonoids
* `submonoid.mul_action`, `submonoid.distrib_mul_action`: a submonoid inherits (distributive)
multiplicative actions.
### Operations on submonoids
* `submonoid.comap`: preimage of a submonoid under a monoid homomorphism as a submonoid of the
domain;
* `submonoid.map`: image of a submonoid under a monoid homomorphism as a submonoid of the codomain;
* `submonoid.prod`: product of two submonoids `s : submonoid M` and `t : submonoid N` as a submonoid
of `M × N`;
### Monoid homomorphisms between submonoid
* `submonoid.subtype`: embedding of a submonoid into the ambient monoid.
* `submonoid.inclusion`: given two submonoids `S`, `T` such that `S ≤ T`, `S.inclusion T` is the
inclusion of `S` into `T` as a monoid homomorphism;
* `mul_equiv.submonoid_congr`: converts a proof of `S = T` into a monoid isomorphism between `S`
and `T`.
* `submonoid.prod_equiv`: monoid isomorphism between `s.prod t` and `s × t`;
### Operations on `monoid_hom`s
* `monoid_hom.mrange`: range of a monoid homomorphism as a submonoid of the codomain;
* `monoid_hom.mker`: kernel of a monoid homomorphism as a submonoid of the domain;
* `monoid_hom.mrestrict`: restrict a monoid homomorphism to a submonoid;
* `monoid_hom.cod_mrestrict`: restrict the codomain of a monoid homomorphism to a submonoid;
* `monoid_hom.mrange_restrict`: restrict a monoid homomorphism to its range;
## Tags
submonoid, range, product, map, comap
-/
variables {M N P : Type*} [mul_one_class M] [mul_one_class N] [mul_one_class P] (S : submonoid M)
/-!
### Conversion to/from `additive`/`multiplicative`
-/
section
/-- Submonoids of monoid `M` are isomorphic to additive submonoids of `additive M`. -/
@[simps]
def submonoid.to_add_submonoid : submonoid M ≃o add_submonoid (additive M) :=
{ to_fun := λ S,
{ carrier := additive.to_mul ⁻¹' S,
zero_mem' := S.one_mem',
add_mem' := S.mul_mem' },
inv_fun := λ S,
{ carrier := additive.of_mul ⁻¹' S,
one_mem' := S.zero_mem',
mul_mem' := S.add_mem' },
left_inv := λ x, by cases x; refl,
right_inv := λ x, by cases x; refl,
map_rel_iff' := λ a b, iff.rfl, }
/-- Additive submonoids of an additive monoid `additive M` are isomorphic to submonoids of `M`. -/
abbreviation add_submonoid.to_submonoid' : add_submonoid (additive M) ≃o submonoid M :=
submonoid.to_add_submonoid.symm
lemma submonoid.to_add_submonoid_closure (S : set M) :
(submonoid.closure S).to_add_submonoid = add_submonoid.closure (additive.to_mul ⁻¹' S) :=
le_antisymm
(submonoid.to_add_submonoid.le_symm_apply.1 $
submonoid.closure_le.2 add_submonoid.subset_closure)
(add_submonoid.closure_le.2 submonoid.subset_closure)
lemma add_submonoid.to_submonoid'_closure (S : set (additive M)) :
(add_submonoid.closure S).to_submonoid' = submonoid.closure (multiplicative.of_add ⁻¹' S) :=
le_antisymm
(add_submonoid.to_submonoid'.le_symm_apply.1 $
add_submonoid.closure_le.2 submonoid.subset_closure)
(submonoid.closure_le.2 add_submonoid.subset_closure)
end
section
variables {A : Type*} [add_zero_class A]
/-- Additive submonoids of an additive monoid `A` are isomorphic to
multiplicative submonoids of `multiplicative A`. -/
@[simps]
def add_submonoid.to_submonoid : add_submonoid A ≃o submonoid (multiplicative A) :=
{ to_fun := λ S,
{ carrier := multiplicative.to_add ⁻¹' S,
one_mem' := S.zero_mem',
mul_mem' := S.add_mem' },
inv_fun := λ S,
{ carrier := multiplicative.of_add ⁻¹' S,
zero_mem' := S.one_mem',
add_mem' := S.mul_mem' },
left_inv := λ x, by cases x; refl,
right_inv := λ x, by cases x; refl,
map_rel_iff' := λ a b, iff.rfl, }
/-- Submonoids of a monoid `multiplicative A` are isomorphic to additive submonoids of `A`. -/
abbreviation submonoid.to_add_submonoid' : submonoid (multiplicative A) ≃o add_submonoid A :=
add_submonoid.to_submonoid.symm
lemma add_submonoid.to_submonoid_closure (S : set A) :
(add_submonoid.closure S).to_submonoid = submonoid.closure (multiplicative.to_add ⁻¹' S) :=
le_antisymm
(add_submonoid.to_submonoid.to_galois_connection.l_le $
add_submonoid.closure_le.2 submonoid.subset_closure)
(submonoid.closure_le.2 add_submonoid.subset_closure)
lemma submonoid.to_add_submonoid'_closure (S : set (multiplicative A)) :
(submonoid.closure S).to_add_submonoid' = add_submonoid.closure (additive.of_mul ⁻¹' S) :=
le_antisymm
(submonoid.to_add_submonoid'.to_galois_connection.l_le $
submonoid.closure_le.2 add_submonoid.subset_closure)
(add_submonoid.closure_le.2 submonoid.subset_closure)
end
namespace submonoid
open set
/-!
### `comap` and `map`
-/
/-- The preimage of a submonoid along a monoid homomorphism is a submonoid. -/
@[to_additive "The preimage of an `add_submonoid` along an `add_monoid` homomorphism is an
`add_submonoid`."]
def comap (f : M →* N) (S : submonoid N) : submonoid M :=
{ carrier := (f ⁻¹' S),
one_mem' := show f 1 ∈ S, by rw f.map_one; exact S.one_mem,
mul_mem' := λ a b ha hb,
show f (a * b) ∈ S, by rw f.map_mul; exact S.mul_mem ha hb }
@[simp, to_additive]
lemma coe_comap (S : submonoid N) (f : M →* N) : (S.comap f : set M) = f ⁻¹' S := rfl
@[simp, to_additive]
lemma mem_comap {S : submonoid N} {f : M →* N} {x : M} : x ∈ S.comap f ↔ f x ∈ S := iff.rfl
@[to_additive]
lemma comap_comap (S : submonoid P) (g : N →* P) (f : M →* N) :
(S.comap g).comap f = S.comap (g.comp f) :=
rfl
@[simp, to_additive]
lemma comap_id (S : submonoid P) : S.comap (monoid_hom.id _) = S :=
ext (by simp)
/-- The image of a submonoid along a monoid homomorphism is a submonoid. -/
@[to_additive "The image of an `add_submonoid` along an `add_monoid` homomorphism is
an `add_submonoid`."]
def map (f : M →* N) (S : submonoid M) : submonoid N :=
{ carrier := (f '' S),
one_mem' := ⟨1, S.one_mem, f.map_one⟩,
mul_mem' := begin rintros _ _ ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩, exact ⟨x * y, S.mul_mem hx hy,
by rw f.map_mul; refl⟩ end }
@[simp, to_additive]
lemma coe_map (f : M →* N) (S : submonoid M) :
(S.map f : set N) = f '' S := rfl
@[simp, to_additive]
lemma mem_map {f : M →* N} {S : submonoid M} {y : N} :
y ∈ S.map f ↔ ∃ x ∈ S, f x = y :=
mem_image_iff_bex
@[to_additive]
lemma mem_map_of_mem (f : M →* N) {S : submonoid M} {x : M} (hx : x ∈ S) : f x ∈ S.map f :=
mem_image_of_mem f hx
@[to_additive]
lemma apply_coe_mem_map (f : M →* N) (S : submonoid M) (x : S) : f x ∈ S.map f :=
mem_map_of_mem f x.prop
@[to_additive]
lemma map_map (g : N →* P) (f : M →* N) : (S.map f).map g = S.map (g.comp f) :=
set_like.coe_injective $ image_image _ _ _
@[to_additive]
lemma mem_map_iff_mem {f : M →* N} (hf : function.injective f) {S : submonoid M} {x : M} :
f x ∈ S.map f ↔ x ∈ S :=
hf.mem_set_image
@[to_additive]
lemma map_le_iff_le_comap {f : M →* N} {S : submonoid M} {T : submonoid N} :
S.map f ≤ T ↔ S ≤ T.comap f :=
image_subset_iff
@[to_additive]
lemma gc_map_comap (f : M →* N) : galois_connection (map f) (comap f) :=
λ S T, map_le_iff_le_comap
@[to_additive]
lemma map_le_of_le_comap {T : submonoid N} {f : M →* N} : S ≤ T.comap f → S.map f ≤ T :=
(gc_map_comap f).l_le
@[to_additive]
lemma le_comap_of_map_le {T : submonoid N} {f : M →* N} : S.map f ≤ T → S ≤ T.comap f :=
(gc_map_comap f).le_u
@[to_additive]
lemma le_comap_map {f : M →* N} : S ≤ (S.map f).comap f :=
(gc_map_comap f).le_u_l _
@[to_additive]
lemma map_comap_le {S : submonoid N} {f : M →* N} : (S.comap f).map f ≤ S :=
(gc_map_comap f).l_u_le _
@[to_additive]
lemma monotone_map {f : M →* N} : monotone (map f) :=
(gc_map_comap f).monotone_l
@[to_additive]
lemma monotone_comap {f : M →* N} : monotone (comap f) :=
(gc_map_comap f).monotone_u
@[simp, to_additive]
lemma map_comap_map {f : M →* N} : ((S.map f).comap f).map f = S.map f :=
(gc_map_comap f).l_u_l_eq_l _
@[simp, to_additive]
lemma comap_map_comap {S : submonoid N} {f : M →* N} : ((S.comap f).map f).comap f = S.comap f :=
(gc_map_comap f).u_l_u_eq_u _
@[to_additive]
lemma map_sup (S T : submonoid M) (f : M →* N) : (S ⊔ T).map f = S.map f ⊔ T.map f :=
(gc_map_comap f).l_sup
@[to_additive]
lemma map_supr {ι : Sort*} (f : M →* N) (s : ι → submonoid M) :
(supr s).map f = ⨆ i, (s i).map f :=
(gc_map_comap f).l_supr
@[to_additive]
lemma comap_inf (S T : submonoid N) (f : M →* N) : (S ⊓ T).comap f = S.comap f ⊓ T.comap f :=
(gc_map_comap f).u_inf
@[to_additive]
lemma comap_infi {ι : Sort*} (f : M →* N) (s : ι → submonoid N) :
(infi s).comap f = ⨅ i, (s i).comap f :=
(gc_map_comap f).u_infi
@[simp, to_additive] lemma map_bot (f : M →* N) : (⊥ : submonoid M).map f = ⊥ :=
(gc_map_comap f).l_bot
@[simp, to_additive] lemma comap_top (f : M →* N) : (⊤ : submonoid N).comap f = ⊤ :=
(gc_map_comap f).u_top
@[simp, to_additive] lemma map_id (S : submonoid M) : S.map (monoid_hom.id M) = S :=
ext (λ x, ⟨λ ⟨_, h, rfl⟩, h, λ h, ⟨_, h, rfl⟩⟩)
section galois_coinsertion
variables {ι : Type*} {f : M →* N} (hf : function.injective f)
include hf
/-- `map f` and `comap f` form a `galois_coinsertion` when `f` is injective. -/
@[to_additive /-" `map f` and `comap f` form a `galois_coinsertion` when `f` is injective. "-/]
def gci_map_comap : galois_coinsertion (map f) (comap f) :=
(gc_map_comap f).to_galois_coinsertion
(λ S x, by simp [mem_comap, mem_map, hf.eq_iff])
@[to_additive]
lemma comap_map_eq_of_injective (S : submonoid M) : (S.map f).comap f = S :=
(gci_map_comap hf).u_l_eq _
@[to_additive]
lemma comap_surjective_of_injective : function.surjective (comap f) :=
(gci_map_comap hf).u_surjective
@[to_additive]
lemma map_injective_of_injective : function.injective (map f) :=
(gci_map_comap hf).l_injective
@[to_additive]
lemma comap_inf_map_of_injective (S T : submonoid M) : (S.map f ⊓ T.map f).comap f = S ⊓ T :=
(gci_map_comap hf).u_inf_l _ _
@[to_additive]
lemma comap_infi_map_of_injective (S : ι → submonoid M) : (⨅ i, (S i).map f).comap f = infi S :=
(gci_map_comap hf).u_infi_l _
@[to_additive]
lemma comap_sup_map_of_injective (S T : submonoid M) : (S.map f ⊔ T.map f).comap f = S ⊔ T :=
(gci_map_comap hf).u_sup_l _ _
@[to_additive]
lemma comap_supr_map_of_injective (S : ι → submonoid M) : (⨆ i, (S i).map f).comap f = supr S :=
(gci_map_comap hf).u_supr_l _
@[to_additive]
lemma map_le_map_iff_of_injective {S T : submonoid M} : S.map f ≤ T.map f ↔ S ≤ T :=
(gci_map_comap hf).l_le_l_iff
@[to_additive]
lemma map_strict_mono_of_injective : strict_mono (map f) :=
(gci_map_comap hf).strict_mono_l
end galois_coinsertion
section galois_insertion
variables {ι : Type*} {f : M →* N} (hf : function.surjective f)
include hf
/-- `map f` and `comap f` form a `galois_insertion` when `f` is surjective. -/
@[to_additive /-" `map f` and `comap f` form a `galois_insertion` when `f` is surjective. "-/]
def gi_map_comap : galois_insertion (map f) (comap f) :=
(gc_map_comap f).to_galois_insertion
(λ S x h, let ⟨y, hy⟩ := hf x in mem_map.2 ⟨y, by simp [hy, h]⟩)
@[to_additive]
lemma map_comap_eq_of_surjective (S : submonoid N) : (S.comap f).map f = S :=
(gi_map_comap hf).l_u_eq _
@[to_additive]
lemma map_surjective_of_surjective : function.surjective (map f) :=
(gi_map_comap hf).l_surjective
@[to_additive]
lemma comap_injective_of_surjective : function.injective (comap f) :=
(gi_map_comap hf).u_injective
@[to_additive]
lemma map_inf_comap_of_surjective (S T : submonoid N) : (S.comap f ⊓ T.comap f).map f = S ⊓ T :=
(gi_map_comap hf).l_inf_u _ _
@[to_additive]
lemma map_infi_comap_of_surjective (S : ι → submonoid N) : (⨅ i, (S i).comap f).map f = infi S :=
(gi_map_comap hf).l_infi_u _
@[to_additive]
lemma map_sup_comap_of_surjective (S T : submonoid N) : (S.comap f ⊔ T.comap f).map f = S ⊔ T :=
(gi_map_comap hf).l_sup_u _ _
@[to_additive]
lemma map_supr_comap_of_surjective (S : ι → submonoid N) : (⨆ i, (S i).comap f).map f = supr S :=
(gi_map_comap hf).l_supr_u _
@[to_additive]
lemma comap_le_comap_iff_of_surjective {S T : submonoid N} : S.comap f ≤ T.comap f ↔ S ≤ T :=
(gi_map_comap hf).u_le_u_iff
@[to_additive]
lemma comap_strict_mono_of_surjective : strict_mono (comap f) :=
(gi_map_comap hf).strict_mono_u
end galois_insertion
/-- A submonoid of a monoid inherits a multiplication. -/
@[to_additive "An `add_submonoid` of an `add_monoid` inherits an addition."]
instance has_mul : has_mul S := ⟨λ a b, ⟨a.1 * b.1, S.mul_mem a.2 b.2⟩⟩
/-- A submonoid of a monoid inherits a 1. -/
@[to_additive "An `add_submonoid` of an `add_monoid` inherits a zero."]
instance has_one : has_one S := ⟨⟨_, S.one_mem⟩⟩
@[simp, norm_cast, to_additive] lemma coe_mul (x y : S) : (↑(x * y) : M) = ↑x * ↑y := rfl
@[simp, norm_cast, to_additive] lemma coe_one : ((1 : S) : M) = 1 := rfl
@[simp, to_additive] lemma mk_mul_mk (x y : M) (hx : x ∈ S) (hy : y ∈ S) :
(⟨x, hx⟩ : S) * ⟨y, hy⟩ = ⟨x * y, S.mul_mem hx hy⟩ := rfl
@[to_additive] lemma mul_def (x y : S) : x * y = ⟨x * y, S.mul_mem x.2 y.2⟩ := rfl
@[to_additive] lemma one_def : (1 : S) = ⟨1, S.one_mem⟩ := rfl
/-- A submonoid of a unital magma inherits a unital magma structure. -/
@[to_additive "An `add_submonoid` of an unital additive magma inherits an unital additive magma
structure."]
instance to_mul_one_class {M : Type*} [mul_one_class M] (S : submonoid M) : mul_one_class S :=
subtype.coe_injective.mul_one_class coe rfl (λ _ _, rfl)
/-- A submonoid of a monoid inherits a monoid structure. -/
@[to_additive "An `add_submonoid` of an `add_monoid` inherits an `add_monoid`
structure."]
instance to_monoid {M : Type*} [monoid M] (S : submonoid M) : monoid S :=
subtype.coe_injective.monoid coe rfl (λ _ _, rfl)
/-- A submonoid of a `comm_monoid` is a `comm_monoid`. -/
@[to_additive "An `add_submonoid` of an `add_comm_monoid` is
an `add_comm_monoid`."]
instance to_comm_monoid {M} [comm_monoid M] (S : submonoid M) : comm_monoid S :=
subtype.coe_injective.comm_monoid coe rfl (λ _ _, rfl)
/-- A submonoid of an `ordered_comm_monoid` is an `ordered_comm_monoid`. -/
@[to_additive "An `add_submonoid` of an `ordered_add_comm_monoid` is
an `ordered_add_comm_monoid`."]
instance to_ordered_comm_monoid {M} [ordered_comm_monoid M] (S : submonoid M) :
ordered_comm_monoid S :=
subtype.coe_injective.ordered_comm_monoid coe rfl (λ _ _, rfl)
/-- A submonoid of a `linear_ordered_comm_monoid` is a `linear_ordered_comm_monoid`. -/
@[to_additive "An `add_submonoid` of a `linear_ordered_add_comm_monoid` is
a `linear_ordered_add_comm_monoid`."]
instance to_linear_ordered_comm_monoid {M} [linear_ordered_comm_monoid M] (S : submonoid M) :
linear_ordered_comm_monoid S :=
subtype.coe_injective.linear_ordered_comm_monoid coe rfl (λ _ _, rfl)
/-- A submonoid of an `ordered_cancel_comm_monoid` is an `ordered_cancel_comm_monoid`. -/
@[to_additive "An `add_submonoid` of an `ordered_cancel_add_comm_monoid` is
an `ordered_cancel_add_comm_monoid`."]
instance to_ordered_cancel_comm_monoid {M} [ordered_cancel_comm_monoid M] (S : submonoid M) :
ordered_cancel_comm_monoid S :=
subtype.coe_injective.ordered_cancel_comm_monoid coe rfl (λ _ _, rfl)
/-- A submonoid of a `linear_ordered_cancel_comm_monoid` is a `linear_ordered_cancel_comm_monoid`.
-/
@[to_additive "An `add_submonoid` of a `linear_ordered_cancel_add_comm_monoid` is
a `linear_ordered_cancel_add_comm_monoid`."]
instance to_linear_ordered_cancel_comm_monoid {M} [linear_ordered_cancel_comm_monoid M]
(S : submonoid M) : linear_ordered_cancel_comm_monoid S :=
subtype.coe_injective.linear_ordered_cancel_comm_monoid coe rfl (λ _ _, rfl)
/-- The natural monoid hom from a submonoid of monoid `M` to `M`. -/
@[to_additive "The natural monoid hom from an `add_submonoid` of `add_monoid` `M` to `M`."]
def subtype : S →* M := ⟨coe, rfl, λ _ _, rfl⟩
@[simp, to_additive] theorem coe_subtype : ⇑S.subtype = coe := rfl
/-- A submonoid is isomorphic to its image under an injective function -/
@[to_additive "An additive submonoid is isomorphic to its image under an injective function"]
noncomputable def equiv_map_of_injective
(f : M →* N) (hf : function.injective f) : S ≃* S.map f :=
{ map_mul' := λ _ _, subtype.ext (f.map_mul _ _), ..equiv.set.image f S hf }
@[simp, to_additive] lemma coe_equiv_map_of_injective_apply
(f : M →* N) (hf : function.injective f) (x : S) :
(equiv_map_of_injective S f hf x : N) = f x := rfl
/-- An induction principle on elements of the type `submonoid.closure s`.
If `p` holds for `1` and all elements of `s`, and is preserved under multiplication, then `p`
holds for all elements of the closure of `s`.
The difference with `submonoid.closure_induction` is that this acts on the subtype.
-/
@[elab_as_eliminator, to_additive "An induction principle on elements of the type
`add_submonoid.closure s`. If `p` holds for `0` and all elements of `s`, and is preserved under
addition, then `p` holds for all elements of the closure of `s`.
The difference with `add_submonoid.closure_induction` is that this acts on the subtype."]
lemma closure_induction' (s : set M) {p : closure s → Prop}
(Hs : ∀ x (h : x ∈ s), p ⟨x, subset_closure h⟩)
(H1 : p 1)
(Hmul : ∀ x y, p x → p y → p (x * y))
(x : closure s) :
p x :=
subtype.rec_on x $ λ x hx, begin
refine exists.elim _ (λ (hx : x ∈ closure s) (hc : p ⟨x, hx⟩), hc),
exact closure_induction hx
(λ x hx, ⟨subset_closure hx, Hs x hx⟩)
⟨one_mem _, H1⟩
(λ x y hx hy, exists.elim hx $ λ hx' hx, exists.elim hy $ λ hy' hy,
⟨mul_mem _ hx' hy', Hmul _ _ hx hy⟩),
end
/-- Given `submonoid`s `s`, `t` of monoids `M`, `N` respectively, `s × t` as a submonoid
of `M × N`. -/
@[to_additive prod "Given `add_submonoid`s `s`, `t` of `add_monoid`s `A`, `B` respectively, `s × t`
as an `add_submonoid` of `A × B`."]
def prod (s : submonoid M) (t : submonoid N) : submonoid (M × N) :=
{ carrier := (s : set M).prod t,
one_mem' := ⟨s.one_mem, t.one_mem⟩,
mul_mem' := λ p q hp hq, ⟨s.mul_mem hp.1 hq.1, t.mul_mem hp.2 hq.2⟩ }
@[to_additive coe_prod]
lemma coe_prod (s : submonoid M) (t : submonoid N) :
(s.prod t : set (M × N)) = (s : set M).prod (t : set N) :=
rfl
@[to_additive mem_prod]
lemma mem_prod {s : submonoid M} {t : submonoid N} {p : M × N} :
p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t := iff.rfl
@[to_additive prod_mono]
lemma prod_mono {s₁ s₂ : submonoid M} {t₁ t₂ : submonoid N} (hs : s₁ ≤ s₂) (ht : t₁ ≤ t₂) :
s₁.prod t₁ ≤ s₂.prod t₂ :=
set.prod_mono hs ht
@[to_additive prod_top]
lemma prod_top (s : submonoid M) :
s.prod (⊤ : submonoid N) = s.comap (monoid_hom.fst M N) :=
ext $ λ x, by simp [mem_prod, monoid_hom.coe_fst]
@[to_additive top_prod]
lemma top_prod (s : submonoid N) :
(⊤ : submonoid M).prod s = s.comap (monoid_hom.snd M N) :=
ext $ λ x, by simp [mem_prod, monoid_hom.coe_snd]
@[simp, to_additive top_prod_top]
lemma top_prod_top : (⊤ : submonoid M).prod (⊤ : submonoid N) = ⊤ :=
(top_prod _).trans $ comap_top _
@[to_additive] lemma bot_prod_bot : (⊥ : submonoid M).prod (⊥ : submonoid N) = ⊥ :=
set_like.coe_injective $ by simp [coe_prod, prod.one_eq_mk]
/-- The product of submonoids is isomorphic to their product as monoids. -/
@[to_additive prod_equiv "The product of additive submonoids is isomorphic to their product
as additive monoids"]
def prod_equiv (s : submonoid M) (t : submonoid N) : s.prod t ≃* s × t :=
{ map_mul' := λ x y, rfl, .. equiv.set.prod ↑s ↑t }
open monoid_hom
@[to_additive]
lemma map_inl (s : submonoid M) : s.map (inl M N) = s.prod ⊥ :=
ext $ λ p, ⟨λ ⟨x, hx, hp⟩, hp ▸ ⟨hx, set.mem_singleton 1⟩,
λ ⟨hps, hp1⟩, ⟨p.1, hps, prod.ext rfl $ (set.eq_of_mem_singleton hp1).symm⟩⟩
@[to_additive]
lemma map_inr (s : submonoid N) : s.map (inr M N) = prod ⊥ s :=
ext $ λ p, ⟨λ ⟨x, hx, hp⟩, hp ▸ ⟨set.mem_singleton 1, hx⟩,
λ ⟨hp1, hps⟩, ⟨p.2, hps, prod.ext (set.eq_of_mem_singleton hp1).symm rfl⟩⟩
@[simp, to_additive prod_bot_sup_bot_prod]
lemma prod_bot_sup_bot_prod (s : submonoid M) (t : submonoid N) :
(s.prod ⊥) ⊔ (prod ⊥ t) = s.prod t :=
le_antisymm (sup_le (prod_mono (le_refl s) bot_le) (prod_mono bot_le (le_refl t))) $
assume p hp, prod.fst_mul_snd p ▸ mul_mem _
((le_sup_left : s.prod ⊥ ≤ s.prod ⊥ ⊔ prod ⊥ t) ⟨hp.1, set.mem_singleton 1⟩)
((le_sup_right : prod ⊥ t ≤ s.prod ⊥ ⊔ prod ⊥ t) ⟨set.mem_singleton 1, hp.2⟩)
@[to_additive]
lemma mem_map_equiv {f : M ≃* N} {K : submonoid M} {x : N} :
x ∈ K.map f.to_monoid_hom ↔ f.symm x ∈ K :=
@set.mem_image_equiv _ _ ↑K f.to_equiv x
@[to_additive]
lemma map_equiv_eq_comap_symm (f : M ≃* N) (K : submonoid M) :
K.map f.to_monoid_hom = K.comap f.symm.to_monoid_hom :=
set_like.coe_injective (f.to_equiv.image_eq_preimage K)
@[to_additive]
lemma comap_equiv_eq_map_symm (f : N ≃* M) (K : submonoid M) :
K.comap f.to_monoid_hom = K.map f.symm.to_monoid_hom :=
(map_equiv_eq_comap_symm f.symm K).symm
end submonoid
namespace monoid_hom
open submonoid
/-- For many categories (monoids, modules, rings, ...) the set-theoretic image of a morphism `f` is
a subobject of the codomain. When this is the case, it is useful to define the range of a morphism
in such a way that the underlying carrier set of the range subobject is definitionally
`set.range f`. In particular this means that the types `↥(set.range f)` and `↥f.range` are
interchangeable without proof obligations.
A convenient candidate definition for range which is mathematically correct is `map ⊤ f`, just as
`set.range` could have been defined as `f '' set.univ`. However, this lacks the desired definitional
convenience, in that it both does not match `set.range`, and that it introduces a redudant `x ∈ ⊤`
term which clutters proofs. In such a case one may resort to the `copy`
pattern. A `copy` function converts the definitional problem for the carrier set of a subobject
into a one-off propositional proof obligation which one discharges while writing the definition of
the definitionally convenient range (the parameter `hs` in the example below).
A good example is the case of a morphism of monoids. A convenient definition for
`monoid_hom.mrange` would be `(⊤ : submonoid M).map f`. However since this lacks the required
definitional convenience, we first define `submonoid.copy` as follows:
```lean
protected def copy (S : submonoid M) (s : set M) (hs : s = S) : submonoid M :=
{ carrier := s,
one_mem' := hs.symm ▸ S.one_mem',
mul_mem' := hs.symm ▸ S.mul_mem' }
```
and then finally define:
```lean
def mrange (f : M →* N) : submonoid N :=
((⊤ : submonoid M).map f).copy (set.range f) set.image_univ.symm
```
-/
library_note "range copy pattern"
/-- The range of a monoid homomorphism is a submonoid. See Note [range copy pattern]. -/
@[to_additive "The range of an `add_monoid_hom` is an `add_submonoid`."]
def mrange (f : M →* N) : submonoid N :=
((⊤ : submonoid M).map f).copy (set.range f) set.image_univ.symm
@[simp, to_additive]
lemma coe_mrange (f : M →* N) :
(f.mrange : set N) = set.range f :=
rfl
@[simp, to_additive] lemma mem_mrange {f : M →* N} {y : N} :
y ∈ f.mrange ↔ ∃ x, f x = y :=
iff.rfl
@[to_additive] lemma mrange_eq_map (f : M →* N) : f.mrange = (⊤ : submonoid M).map f :=
copy_eq _
@[to_additive]
lemma map_mrange (g : N →* P) (f : M →* N) : f.mrange.map g = (g.comp f).mrange :=
by simpa only [mrange_eq_map] using (⊤ : submonoid M).map_map g f
@[to_additive]
lemma mrange_top_iff_surjective {N} [mul_one_class N] {f : M →* N} :
f.mrange = (⊤ : submonoid N) ↔ function.surjective f :=
set_like.ext'_iff.trans $ iff.trans (by rw [coe_mrange, coe_top]) set.range_iff_surjective
/-- The range of a surjective monoid hom is the whole of the codomain. -/
@[to_additive "The range of a surjective `add_monoid` hom is the whole of the codomain."]
lemma mrange_top_of_surjective {N} [mul_one_class N] (f : M →* N) (hf : function.surjective f) :
f.mrange = (⊤ : submonoid N) :=
mrange_top_iff_surjective.2 hf
@[to_additive]
lemma mclosure_preimage_le (f : M →* N) (s : set N) :
closure (f ⁻¹' s) ≤ (closure s).comap f :=
closure_le.2 $ λ x hx, set_like.mem_coe.2 $ mem_comap.2 $ subset_closure hx
/-- The image under a monoid hom of the submonoid generated by a set equals the submonoid generated
by the image of the set. -/
@[to_additive "The image under an `add_monoid` hom of the `add_submonoid` generated by a set equals
the `add_submonoid` generated by the image of the set."]
lemma map_mclosure (f : M →* N) (s : set M) :
(closure s).map f = closure (f '' s) :=
le_antisymm
(map_le_iff_le_comap.2 $ le_trans (closure_mono $ set.subset_preimage_image _ _)
(mclosure_preimage_le _ _))
(closure_le.2 $ set.image_subset _ subset_closure)
/-- Restriction of a monoid hom to a submonoid of the domain. -/
@[to_additive "Restriction of an add_monoid hom to an `add_submonoid` of the domain."]
def mrestrict {N : Type*} [mul_one_class N] (f : M →* N) (S : submonoid M) : S →* N :=
f.comp S.subtype
@[simp, to_additive]
lemma mrestrict_apply {N : Type*} [mul_one_class N] (f : M →* N) (x : S) : f.mrestrict S x = f x :=
rfl
/-- Restriction of a monoid hom to a submonoid of the codomain. -/
@[to_additive "Restriction of an `add_monoid` hom to an `add_submonoid` of the codomain.", simps]
def cod_mrestrict (f : M →* N) (S : submonoid N) (h : ∀ x, f x ∈ S) : M →* S :=
{ to_fun := λ n, ⟨f n, h n⟩,
map_one' := subtype.eq f.map_one,
map_mul' := λ x y, subtype.eq (f.map_mul x y) }
/-- Restriction of a monoid hom to its range interpreted as a submonoid. -/
@[to_additive "Restriction of an `add_monoid` hom to its range interpreted as a submonoid."]
def mrange_restrict {N} [mul_one_class N] (f : M →* N) : M →* f.mrange :=
f.cod_mrestrict f.mrange $ λ x, ⟨x, rfl⟩
@[simp, to_additive]
lemma coe_mrange_restrict {N} [mul_one_class N] (f : M →* N) (x : M) :
(f.mrange_restrict x : N) = f x :=
rfl
/-- The multiplicative kernel of a monoid homomorphism is the submonoid of elements `x : G` such
that `f x = 1` -/
@[to_additive "The additive kernel of an `add_monoid` homomorphism is the `add_submonoid` of
elements such that `f x = 0`"]
def mker (f : M →* N) : submonoid M := (⊥ : submonoid N).comap f
@[to_additive]
lemma mem_mker (f : M →* N) {x : M} : x ∈ f.mker ↔ f x = 1 := iff.rfl
@[to_additive]
lemma coe_mker (f : M →* N) : (f.mker : set M) = (f : M → N) ⁻¹' {1} := rfl
@[to_additive]
instance decidable_mem_mker [decidable_eq N] (f : M →* N) :
decidable_pred (∈ f.mker) :=
λ x, decidable_of_iff (f x = 1) f.mem_mker
@[to_additive]
lemma comap_mker (g : N →* P) (f : M →* N) : g.mker.comap f = (g.comp f).mker := rfl
@[simp, to_additive] lemma comap_bot' (f : M →* N) :
(⊥ : submonoid N).comap f = f.mker := rfl
@[to_additive] lemma range_restrict_mker (f : M →* N) : mker (mrange_restrict f) = mker f :=
begin
ext,
change (⟨f x, _⟩ : mrange f) = ⟨1, _⟩ ↔ f x = 1,
simp only [],
end
@[simp, to_additive]
lemma mker_one : (1 : M →* N).mker = ⊤ :=
by { ext, simp [mem_mker] }
@[to_additive]
lemma prod_map_comap_prod' {M' : Type*} {N' : Type*} [mul_one_class M'] [mul_one_class N']
(f : M →* N) (g : M' →* N') (S : submonoid N) (S' : submonoid N') :
(S.prod S').comap (prod_map f g) = (S.comap f).prod (S'.comap g) :=
set_like.coe_injective $ set.preimage_prod_map_prod f g _ _
@[to_additive]
lemma mker_prod_map {M' : Type*} {N' : Type*} [mul_one_class M'] [mul_one_class N'] (f : M →* N)
(g : M' →* N') : (prod_map f g).mker = f.mker.prod g.mker :=
by rw [←comap_bot', ←comap_bot', ←comap_bot', ←prod_map_comap_prod', bot_prod_bot]
end monoid_hom
namespace submonoid
open monoid_hom
@[to_additive]
lemma mrange_inl : (inl M N).mrange = prod ⊤ ⊥ :=
by simpa only [mrange_eq_map] using map_inl ⊤
@[to_additive]
lemma mrange_inr : (inr M N).mrange = prod ⊥ ⊤ :=
by simpa only [mrange_eq_map] using map_inr ⊤
@[to_additive]
lemma mrange_inl' : (inl M N).mrange = comap (snd M N) ⊥ := mrange_inl.trans (top_prod _)
@[to_additive]
lemma mrange_inr' : (inr M N).mrange = comap (fst M N) ⊥ := mrange_inr.trans (prod_top _)
@[simp, to_additive]
lemma mrange_fst : (fst M N).mrange = ⊤ :=
(fst M N).mrange_top_of_surjective $ @prod.fst_surjective _ _ ⟨1⟩
@[simp, to_additive]
lemma mrange_snd : (snd M N).mrange = ⊤ :=
(snd M N).mrange_top_of_surjective $ @prod.snd_surjective _ _ ⟨1⟩
@[simp, to_additive]
lemma mrange_inl_sup_mrange_inr : (inl M N).mrange ⊔ (inr M N).mrange = ⊤ :=
by simp only [mrange_inl, mrange_inr, prod_bot_sup_bot_prod, top_prod_top]
/-- The monoid hom associated to an inclusion of submonoids. -/
@[to_additive "The `add_monoid` hom associated to an inclusion of submonoids."]
def inclusion {S T : submonoid M} (h : S ≤ T) : S →* T :=
S.subtype.cod_mrestrict _ (λ x, h x.2)
@[simp, to_additive]
lemma range_subtype (s : submonoid M) : s.subtype.mrange = s :=
set_like.coe_injective $ (coe_mrange _).trans $ subtype.range_coe
@[to_additive] lemma eq_top_iff' : S = ⊤ ↔ ∀ x : M, x ∈ S :=
eq_top_iff.trans ⟨λ h m, h $ mem_top m, λ h m _, h m⟩
@[to_additive] lemma eq_bot_iff_forall : S = ⊥ ↔ ∀ x ∈ S, x = (1 : M) :=
set_like.ext_iff.trans $ by simp [iff_def, S.one_mem] { contextual := tt }
@[to_additive] lemma nontrivial_iff_exists_ne_one (S : submonoid M) :
nontrivial S ↔ ∃ x ∈ S, x ≠ (1:M) :=
calc nontrivial S ↔ ∃ x : S, x ≠ 1 : nontrivial_iff_exists_ne 1
... ↔ ∃ x (hx : x ∈ S), (⟨x, hx⟩ : S) ≠ ⟨1, S.one_mem⟩ : subtype.exists
... ↔ ∃ x ∈ S, x ≠ (1 : M) : by simp only [ne.def]
/-- A submonoid is either the trivial submonoid or nontrivial. -/
@[to_additive] lemma bot_or_nontrivial (S : submonoid M) : S = ⊥ ∨ nontrivial S :=
by simp only [eq_bot_iff_forall, nontrivial_iff_exists_ne_one, ← not_forall, classical.em]
/-- A submonoid is either the trivial submonoid or contains a nonzero element. -/
@[to_additive] lemma bot_or_exists_ne_one (S : submonoid M) : S = ⊥ ∨ ∃ x ∈ S, x ≠ (1:M) :=
S.bot_or_nontrivial.imp_right S.nontrivial_iff_exists_ne_one.mp
end submonoid
namespace mul_equiv
variables {S} {T : submonoid M}
/-- Makes the identity isomorphism from a proof that two submonoids of a multiplicative
monoid are equal. -/
@[to_additive "Makes the identity additive isomorphism from a proof two
submonoids of an additive monoid are equal."]
def submonoid_congr (h : S = T) : S ≃* T :=
{ map_mul' := λ _ _, rfl, ..equiv.set_congr $ congr_arg _ h }
-- this name is primed so that the version to `f.range` instead of `f.mrange` can be unprimed.
/-- A monoid homomorphism `f : M →* N` with a left-inverse `g : N → M` defines a multiplicative
equivalence between `M` and `f.mrange`.
This is a bidirectional version of `monoid_hom.mrange_restrict`. -/
@[to_additive /-"
An additive monoid homomorphism `f : M →+ N` with a left-inverse `g : N → M` defines an additive
equivalence between `M` and `f.mrange`.
This is a bidirectional version of `add_monoid_hom.mrange_restrict`. "-/, simps {simp_rhs := tt}]
def of_left_inverse' (f : M →* N) {g : N → M} (h : function.left_inverse g f) : M ≃* f.mrange :=
{ to_fun := f.mrange_restrict,
inv_fun := g ∘ f.mrange.subtype,
left_inv := h,
right_inv := λ x, subtype.ext $
let ⟨x', hx'⟩ := monoid_hom.mem_mrange.mp x.prop in
show f (g x) = x, by rw [←hx', h x'],
.. f.mrange_restrict }
/-- A `mul_equiv` `φ` between two monoids `M` and `N` induces a `mul_equiv` between
a submonoid `S ≤ M` and the submonoid `φ(S) ≤ N`. -/
@[to_additive "An `add_equiv` `φ` between two additive monoids `M` and `N` induces an `add_equiv`
between a submonoid `S ≤ M` and the submonoid `φ(S) ≤ N`. ", simps]
def submonoid_equiv_map (e : M ≃* N) (S : submonoid M) : S ≃* S.map e.to_monoid_hom :=
{ to_fun := λ x, ⟨e x, _⟩,
inv_fun := λ x, ⟨e.symm x, _⟩, -- we restate this for `simps` to avoid `⇑e.symm.to_equiv x`
map_mul' := λ _ _, subtype.ext (e.map_mul _ _), ..equiv.image e.to_equiv S }
end mul_equiv
section actions
/-! ### Actions by `submonoid`s
These instances tranfer the action by an element `m : M` of a monoid `M` written as `m • a` onto the
action by an element `s : S` of a submonoid `S : submonoid M` such that `s • a = (s : M) • a`.
These instances work particularly well in conjunction with `monoid.to_mul_action`, enabling
`s • m` as an alias for `↑s * m`.
-/
namespace submonoid
variables {M' : Type*} {α β : Type*} [monoid M']
/-- The action by a submonoid is the action by the underlying monoid. -/
@[to_additive /-"The additive action by an add_submonoid is the action by the underlying
add_monoid. "-/]
instance [mul_action M' α] (S : submonoid M') : mul_action S α :=
mul_action.comp_hom _ S.subtype
@[to_additive]
lemma smul_def [mul_action M' α] {S : submonoid M'} (g : S) (m : α) : g • m = (g : M') • m := rfl
/-- The action by a submonoid is the action by the underlying monoid. -/
instance [add_monoid α] [distrib_mul_action M' α] (S : submonoid M') : distrib_mul_action S α :=
distrib_mul_action.comp_hom _ S.subtype
/-- The action by a submonoid is the action by the underlying monoid. -/
instance [monoid α] [mul_distrib_mul_action M' α] (S : submonoid M') : mul_distrib_mul_action S α :=
mul_distrib_mul_action.comp_hom _ S.subtype
@[to_additive]
instance smul_comm_class_left
[mul_action M' β] [has_scalar α β] [smul_comm_class M' α β] (S : submonoid M') :
smul_comm_class S α β :=
⟨λ a, (smul_comm (a : M') : _)⟩
@[to_additive]
instance smul_comm_class_right
[has_scalar α β] [mul_action M' β] [smul_comm_class α M' β] (S : submonoid M') :
smul_comm_class α S β :=
⟨λ a s, (smul_comm a (s : M') : _)⟩
/-- Note that this provides `is_scalar_tower S M' M'` which is needed by `smul_mul_assoc`. -/
instance
[has_scalar α β] [mul_action M' α] [mul_action M' β] [is_scalar_tower M' α β] (S : submonoid M') :
is_scalar_tower S α β :=
⟨λ a, (smul_assoc (a : M') : _)⟩
example {S : submonoid M'} : is_scalar_tower S M' M' := by apply_instance
instance [mul_action M' α] [has_faithful_scalar M' α] (S : submonoid M') :
has_faithful_scalar S α :=
{ eq_of_smul_eq_smul := λ x y h, subtype.ext (eq_of_smul_eq_smul h) }
end submonoid
end actions
|
9bcf3b98efc44da7c18d3f6fcadff98efe5762ee | 9028d228ac200bbefe3a711342514dd4e4458bff | /src/data/num/bitwise.lean | 604f03d7bd4bbfcaf80ed1efa35dacefb906b72a | [
"Apache-2.0"
] | permissive | mcncm/mathlib | 8d25099344d9d2bee62822cb9ed43aa3e09fa05e | fde3d78cadeec5ef827b16ae55664ef115e66f57 | refs/heads/master | 1,672,743,316,277 | 1,602,618,514,000 | 1,602,618,514,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,784 | lean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
-/
import data.num.basic
import data.bitvec.core
/-!
# Bitwise operations using binary representation of integers
## Definitions
* bitwise operations for `pos_num` and `num`,
* `snum`, a type that represents integers as a bit string with a sign bit at the end,
* arithmetic operations for `snum`.
-/
namespace pos_num
def lor : pos_num → pos_num → pos_num
| 1 (bit0 q) := bit1 q
| 1 q := q
| (bit0 p) 1 := bit1 p
| p 1 := p
| (bit0 p) (bit0 q) := bit0 (lor p q)
| (bit0 p) (bit1 q) := bit1 (lor p q)
| (bit1 p) (bit0 q) := bit1 (lor p q)
| (bit1 p) (bit1 q) := bit1 (lor p q)
def land : pos_num → pos_num → num
| 1 (bit0 q) := 0
| 1 _ := 1
| (bit0 p) 1 := 0
| _ 1 := 1
| (bit0 p) (bit0 q) := num.bit0 (land p q)
| (bit0 p) (bit1 q) := num.bit0 (land p q)
| (bit1 p) (bit0 q) := num.bit0 (land p q)
| (bit1 p) (bit1 q) := num.bit1 (land p q)
def ldiff : pos_num → pos_num → num
| 1 (bit0 q) := 1
| 1 _ := 0
| (bit0 p) 1 := num.pos (bit0 p)
| (bit1 p) 1 := num.pos (bit0 p)
| (bit0 p) (bit0 q) := num.bit0 (ldiff p q)
| (bit0 p) (bit1 q) := num.bit0 (ldiff p q)
| (bit1 p) (bit0 q) := num.bit1 (ldiff p q)
| (bit1 p) (bit1 q) := num.bit0 (ldiff p q)
def lxor : pos_num → pos_num → num
| 1 1 := 0
| 1 (bit0 q) := num.pos (bit1 q)
| 1 (bit1 q) := num.pos (bit0 q)
| (bit0 p) 1 := num.pos (bit1 p)
| (bit1 p) 1 := num.pos (bit0 p)
| (bit0 p) (bit0 q) := num.bit0 (lxor p q)
| (bit0 p) (bit1 q) := num.bit1 (lxor p q)
| (bit1 p) (bit0 q) := num.bit1 (lxor p q)
| (bit1 p) (bit1 q) := num.bit0 (lxor p q)
def test_bit : pos_num → nat → bool
| 1 0 := tt
| 1 (n+1) := ff
| (bit0 p) 0 := ff
| (bit0 p) (n+1) := test_bit p n
| (bit1 p) 0 := tt
| (bit1 p) (n+1) := test_bit p n
def one_bits : pos_num → nat → list nat
| 1 d := [d]
| (bit0 p) d := one_bits p (d+1)
| (bit1 p) d := d :: one_bits p (d+1)
def shiftl (p : pos_num) : nat → pos_num
| 0 := p
| (n+1) := bit0 (shiftl n)
def shiftr : pos_num → nat → num
| p 0 := num.pos p
| 1 (n+1) := 0
| (bit0 p) (n+1) := shiftr p n
| (bit1 p) (n+1) := shiftr p n
end pos_num
namespace num
def lor : num → num → num
| 0 q := q
| p 0 := p
| (pos p) (pos q) := pos (p.lor q)
def land : num → num → num
| 0 q := 0
| p 0 := 0
| (pos p) (pos q) := p.land q
def ldiff : num → num → num
| 0 q := 0
| p 0 := p
| (pos p) (pos q) := p.ldiff q
def lxor : num → num → num
| 0 q := q
| p 0 := p
| (pos p) (pos q) := p.lxor q
def shiftl : num → nat → num
| 0 n := 0
| (pos p) n := pos (p.shiftl n)
def shiftr : num → nat → num
| 0 n := 0
| (pos p) n := p.shiftr n
def test_bit : num → nat → bool
| 0 n := ff
| (pos p) n := p.test_bit n
def one_bits : num → list nat
| 0 := []
| (pos p) := p.one_bits 0
end num
/-- See `snum`. -/
@[derive has_reflect, derive decidable_eq]
inductive nzsnum : Type
| msb : bool → nzsnum
| bit : bool → nzsnum → nzsnum
/-- Alternative representation of integers using a sign bit at the end.
The convention on sign here is to have the argument to `msb` denote
the sign of the MSB itself, with all higher bits set to the negation
of this sign. The result is interpreted in two's complement.
13 = ..0001101(base 2) = nz (bit1 (bit0 (bit1 (msb tt))))
-13 = ..1110011(base 2) = nz (bit1 (bit1 (bit0 (msb ff))))
As with `num`, a special case must be added for zero, which has no msb,
but by two's complement symmetry there is a second special case for -1.
Here the `bool` field indicates the sign of the number.
0 = ..0000000(base 2) = zero ff
-1 = ..1111111(base 2) = zero tt -/
@[derive has_reflect, derive decidable_eq]
inductive snum : Type
| zero : bool → snum
| nz : nzsnum → snum
instance : has_coe nzsnum snum := ⟨snum.nz⟩
instance : has_zero snum := ⟨snum.zero ff⟩
instance : has_one nzsnum := ⟨nzsnum.msb tt⟩
instance : has_one snum := ⟨snum.nz 1⟩
instance : inhabited nzsnum := ⟨1⟩
instance : inhabited snum := ⟨0⟩
/-!
The `snum` representation uses a bit string, essentially a list of 0 (`ff`) and 1 (`tt`) bits,
and the negation of the MSB is sign-extended to all higher bits.
-/
namespace nzsnum
notation a :: b := bit a b
def sign : nzsnum → bool
| (msb b) := bnot b
| (b :: p) := sign p
@[pattern] def not : nzsnum → nzsnum
| (msb b) := msb (bnot b)
| (b :: p) := bnot b :: not p
prefix ~ := not
def bit0 : nzsnum → nzsnum := bit ff
def bit1 : nzsnum → nzsnum := bit tt
def head : nzsnum → bool
| (msb b) := b
| (b :: p) := b
def tail : nzsnum → snum
| (msb b) := snum.zero (bnot b)
| (b :: p) := p
end nzsnum
namespace snum
open nzsnum
def sign : snum → bool
| (zero z) := z
| (nz p) := p.sign
@[pattern] def not : snum → snum
| (zero z) := zero (bnot z)
| (nz p) := ~p
prefix ~ := not
@[pattern] def bit : bool → snum → snum
| b (zero z) := if b = z then zero b else msb b
| b (nz p) := p.bit b
notation a :: b := bit a b
def bit0 : snum → snum := bit ff
def bit1 : snum → snum := bit tt
theorem bit_zero (b) : b :: zero b = zero b := by cases b; refl
theorem bit_one (b) : b :: zero (bnot b) = msb b := by cases b; refl
end snum
namespace nzsnum
open snum
def drec' {C : snum → Sort*} (z : Π b, C (snum.zero b))
(s : Π b p, C p → C (b :: p)) : Π p : nzsnum, C p
| (msb b) := by rw ←bit_one; exact s b (snum.zero (bnot b)) (z (bnot b))
| (bit b p) := s b p (drec' p)
end nzsnum
namespace snum
open nzsnum
def head : snum → bool
| (zero z) := z
| (nz p) := p.head
def tail : snum → snum
| (zero z) := zero z
| (nz p) := p.tail
def drec' {C : snum → Sort*} (z : Π b, C (snum.zero b))
(s : Π b p, C p → C (b :: p)) : Π p, C p
| (zero b) := z b
| (nz p) := p.drec' z s
def rec' {α} (z : bool → α) (s : bool → snum → α → α) : snum → α :=
drec' z s
def test_bit : nat → snum → bool
| 0 p := head p
| (n+1) p := test_bit n (tail p)
def succ : snum → snum :=
rec' (λ b, cond b 0 1) (λb p succp, cond b (ff :: succp) (tt :: p))
def pred : snum → snum :=
rec' (λ b, cond b (~1) ~0) (λb p predp, cond b (ff :: p) (tt :: predp))
protected def neg (n : snum) : snum := succ ~n
instance : has_neg snum := ⟨snum.neg⟩
-- First bit is 0 or 1 (`tt`), second bit is 0 or -1 (`tt`)
def czadd : bool → bool → snum → snum
| ff ff p := p
| ff tt p := pred p
| tt ff p := succ p
| tt tt p := p
end snum
namespace snum
def bits : snum → Π n, vector bool n
| p 0 := vector.nil
| p (n+1) := head p ::ᵥ bits (tail p) n
def cadd : snum → snum → bool → snum :=
rec' (λ a p c, czadd c a p) $ λa p IH,
rec' (λb c, czadd c b (a :: p)) $ λb q _ c,
bitvec.xor3 a b c :: IH q (bitvec.carry a b c)
protected def add (a b : snum) : snum := cadd a b ff
instance : has_add snum := ⟨snum.add⟩
protected def sub (a b : snum) : snum := a + -b
instance : has_sub snum := ⟨snum.sub⟩
protected def mul (a : snum) : snum → snum :=
rec' (λ b, cond b (-a) 0) $ λb q IH,
cond b (bit0 IH + a) (bit0 IH)
instance : has_mul snum := ⟨snum.mul⟩
end snum
|
30ed36f71b9bf778fe97dbd4f9e9a6f6f689bfa5 | 624f6f2ae8b3b1adc5f8f67a365c51d5126be45a | /stage0/src/Init/Lean/Elab/Term.lean | f35c18a14ae6db34b2d2729fffea7f8444f1e2f2 | [
"Apache-2.0"
] | permissive | mhuisi/lean4 | 28d35a4febc2e251c7f05492e13f3b05d6f9b7af | dda44bc47f3e5d024508060dac2bcb59fd12e4c0 | refs/heads/master | 1,621,225,489,283 | 1,585,142,689,000 | 1,585,142,689,000 | 250,590,438 | 0 | 2 | Apache-2.0 | 1,602,443,220,000 | 1,585,327,814,000 | C | UTF-8 | Lean | false | false | 54,827 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Lean.Util.Sorry
import Init.Lean.Structure
import Init.Lean.Meta.ExprDefEq
import Init.Lean.Meta.AppBuilder
import Init.Lean.Meta.SynthInstance
import Init.Lean.Meta.Tactic.Util
import Init.Lean.Hygiene
import Init.Lean.Util.RecDepth
import Init.Lean.Elab.Log
import Init.Lean.Elab.Alias
import Init.Lean.Elab.ResolveName
import Init.Lean.Elab.Level
namespace Lean
namespace Elab
namespace Term
structure Context extends Meta.Context :=
(fileName : String)
(fileMap : FileMap)
(cmdPos : String.Pos)
(currNamespace : Name)
(declName? : Option Name := none)
(levelNames : List Name := [])
(openDecls : List OpenDecl := [])
(macroStack : MacroStack := [])
(currMacroScope : MacroScope := firstFrontendMacroScope)
/- When `mayPostpone == true`, an elaboration function may interrupt its execution by throwing `Exception.postpone`.
The function `elabTerm` catches this exception and creates fresh synthetic metavariable `?m`, stores `?m` in
the list of pending synthetic metavariables, and returns `?m`. -/
(mayPostpone : Bool := true)
(errToSorry : Bool := true)
/- If `macroStackAtErr == true`, we include it in error messages. -/
(macroStackAtErr : Bool := true)
/-- We use synthetic metavariables as placeholders for pending elaboration steps. -/
inductive SyntheticMVarKind
-- typeclass instance search
| typeClass
-- Similar to typeClass, but error messages are different,
-- we use "type mismatch" or "application type mismatch" (when `f?` is some) instead of "failed to synthesize"
| coe (expectedType : Expr) (eType : Expr) (e : Expr) (f? : Option Expr)
-- tactic block execution
| tactic (tacticCode : Syntax)
-- `elabTerm` call that threw `Exception.postpone` (input is stored at `SyntheticMVarDecl.ref`)
| postponed (macroStack : MacroStack)
-- type defaulting (currently: defaulting numeric literals to `Nat`)
| withDefault (defaultVal : Expr)
structure SyntheticMVarDecl :=
(mvarId : MVarId) (ref : Syntax) (kind : SyntheticMVarKind)
structure State extends Meta.State :=
(syntheticMVars : List SyntheticMVarDecl := [])
(messages : MessageLog := {})
(instImplicitIdx : Nat := 1)
(anonymousIdx : Nat := 1)
(nextMacroScope : Nat := firstFrontendMacroScope + 1)
instance State.inhabited : Inhabited State := ⟨{ env := arbitrary _ }⟩
/-
The Term elaborator monad has a special kind of exception `Exception.postpone` which is used by
an elaboration function to notify the main driver that it should be tried later.
Remark: `Exception.postpone` is used only when `mayPostpone == true` in the `Context`. -/
inductive Exception
| ex : Elab.Exception → Exception
| postpone : Exception
instance Exception.inhabited : Inhabited Exception := ⟨Exception.postpone⟩
instance Exception.hasToString : HasToString Exception :=
⟨fun ex => match ex with | Exception.postpone => "postponed" | Exception.ex ex => toString ex⟩
/-
Term elaborator Monad. In principle, we could track statically which methods
may postpone or not by having adding a Boolean parameter `mayPostpone` to
`TermElabM`. This would be useful to ensure that `Exception.postpone` does not leak
to `CommandElabM`, but we abandoned this design because it adds unnecessary complexity. -/
abbrev TermElabM := ReaderT Context (EStateM Exception State)
abbrev TermElab := Syntax → Option Expr → TermElabM Expr
instance TermElabM.inhabited {α} : Inhabited (TermElabM α) :=
⟨throw $ Exception.postpone⟩
abbrev TermElabResult := EStateM.Result Message State Expr
instance TermElabResult.inhabited : Inhabited TermElabResult := ⟨EStateM.Result.ok (arbitrary _) (arbitrary _)⟩
/--
Execute `x`, save resulting expression and new state.
If `x` fails, then it also stores exception and new state.
Remark: we do not capture `Exception.postpone`. -/
@[inline] def observing (x : TermElabM Expr) : TermElabM TermElabResult :=
fun ctx s =>
match x ctx s with
| EStateM.Result.error (Exception.ex (Elab.Exception.error errMsg)) newS => EStateM.Result.ok (EStateM.Result.error errMsg newS) s
| EStateM.Result.error Exception.postpone _ => EStateM.Result.error Exception.postpone s
| EStateM.Result.error ex newS => EStateM.Result.error ex newS
| EStateM.Result.ok e newS => EStateM.Result.ok (EStateM.Result.ok e newS) s
/--
Apply the result/exception and state captured with `observing`.
We use this method to implement overloaded notation and symbols. -/
def applyResult (result : TermElabResult) : TermElabM Expr :=
match result with
| EStateM.Result.ok e s => do set s; pure e
| EStateM.Result.error errMsg s => do set s; throw (Exception.ex (Elab.Exception.error errMsg))
def getEnv : TermElabM Environment := do s ← get; pure s.env
def getMCtx : TermElabM MetavarContext := do s ← get; pure s.mctx
def getLCtx : TermElabM LocalContext := do ctx ← read; pure ctx.lctx
def getLocalInsts : TermElabM LocalInstances := do ctx ← read; pure ctx.localInstances
def getOptions : TermElabM Options := do ctx ← read; pure ctx.config.opts
def setEnv (env : Environment) : TermElabM Unit := modify $ fun s => { env := env, .. s }
def setMCtx (mctx : MetavarContext) : TermElabM Unit := modify $ fun s => { mctx := mctx, .. s }
def addContext (msg : MessageData) : TermElabM MessageData := do
env ← getEnv; mctx ← getMCtx; lctx ← getLCtx; opts ← getOptions;
pure (MessageData.withContext { env := env, mctx := mctx, lctx := lctx, opts := opts } msg)
instance monadLog : MonadLog TermElabM :=
{ getCmdPos := do ctx ← read; pure ctx.cmdPos,
getFileMap := do ctx ← read; pure ctx.fileMap,
getFileName := do ctx ← read; pure ctx.fileName,
addContext := addContext,
logMessage := fun msg => modify $ fun s => { messages := s.messages.add msg, .. s } }
/--
Throws an error with the given `msgData` and extracting position information from `ref`.
If `ref` does not contain position information, then use `cmdPos` -/
def throwError {α} (ref : Syntax) (msgData : MessageData) : TermElabM α := do
ctx ← read;
let ref := getBetterRef ref ctx.macroStack;
let msgData := if ctx.macroStackAtErr then addMacroStack msgData ctx.macroStack else msgData;
msg ← mkMessage msgData MessageSeverity.error ref;
throw (Exception.ex (Elab.Exception.error msg))
def throwUnsupportedSyntax {α} : TermElabM α :=
throw (Exception.ex Elab.Exception.unsupportedSyntax)
@[inline] def withIncRecDepth {α} (ref : Syntax) (x : TermElabM α) : TermElabM α := do
ctx ← read;
when (ctx.currRecDepth == ctx.maxRecDepth) $ throwError ref maxRecDepthErrorMessage;
adaptReader (fun (ctx : Context) => { currRecDepth := ctx.currRecDepth + 1, .. ctx }) x
protected def getCurrMacroScope : TermElabM MacroScope := do ctx ← read; pure ctx.currMacroScope
protected def getMainModule : TermElabM Name := do env ← getEnv; pure env.mainModule
@[inline] protected def withFreshMacroScope {α} (x : TermElabM α) : TermElabM α := do
fresh ← modifyGet (fun st => (st.nextMacroScope, { st with nextMacroScope := st.nextMacroScope + 1 }));
adaptReader (fun (ctx : Context) => { ctx with currMacroScope := fresh }) x
instance monadQuotation : MonadQuotation TermElabM := {
getCurrMacroScope := Term.getCurrMacroScope,
getMainModule := Term.getMainModule,
withFreshMacroScope := @Term.withFreshMacroScope
}
unsafe def mkTermElabAttribute : IO (KeyedDeclsAttribute TermElab) :=
mkElabAttribute TermElab `Lean.Elab.Term.termElabAttribute `builtinTermElab `termElab `Lean.Parser.Term `Lean.Elab.Term.TermElab "term"
@[init mkTermElabAttribute] constant termElabAttribute : KeyedDeclsAttribute TermElab := arbitrary _
/--
Auxiliary datatatype for presenting a Lean lvalue modifier.
We represent a unelaborated lvalue as a `Syntax` (or `Expr`) and `List LVal`.
Example: `a.foo[i].1` is represented as the `Syntax` `a` and the list
`[LVal.fieldName "foo", LVal.getOp i, LVal.fieldIdx 1]`.
Recall that the notation `a[i]` is not just for accessing arrays in Lean. -/
inductive LVal
| fieldIdx (i : Nat)
| fieldName (name : String)
| getOp (idx : Syntax)
instance LVal.hasToString : HasToString LVal :=
⟨fun p => match p with | LVal.fieldIdx i => toString i | LVal.fieldName n => n | LVal.getOp idx => "[" ++ toString idx ++ "]"⟩
def getDeclName? : TermElabM (Option Name) := do ctx ← read; pure ctx.declName?
def getCurrNamespace : TermElabM Name := do ctx ← read; pure ctx.currNamespace
def getOpenDecls : TermElabM (List OpenDecl) := do ctx ← read; pure ctx.openDecls
def getTraceState : TermElabM TraceState := do s ← get; pure s.traceState
def setTraceState (traceState : TraceState) : TermElabM Unit := modify $ fun s => { traceState := traceState, .. s }
def isExprMVarAssigned (mvarId : MVarId) : TermElabM Bool := do mctx ← getMCtx; pure $ mctx.isExprAssigned mvarId
def getMVarDecl (mvarId : MVarId) : TermElabM MetavarDecl := do mctx ← getMCtx; pure $ mctx.getDecl mvarId
def assignExprMVar (mvarId : MVarId) (val : Expr) : TermElabM Unit := modify $ fun s => { mctx := s.mctx.assignExpr mvarId val, .. s }
def logTrace (cls : Name) (ref : Syntax) (msg : MessageData) : TermElabM Unit := do
ctx ← read;
s ← get;
logInfo ref $
MessageData.withContext { env := s.env, mctx := s.mctx, lctx := ctx.lctx, opts := ctx.config.opts } $
MessageData.tagged cls msg
@[inline] def trace (cls : Name) (ref : Syntax) (msg : Unit → MessageData) : TermElabM Unit := do
opts ← getOptions;
when (checkTraceOption opts cls) $ logTrace cls ref (msg ())
def logDbgTrace (msg : MessageData) : TermElabM Unit := do
trace `Elab.debug Syntax.missing $ fun _ => msg
/-- For testing `TermElabM` methods. The #eval command will sign the error. -/
def throwErrorIfErrors : TermElabM Unit := do
s ← get;
when s.messages.hasErrors $
throwError Syntax.missing "Error(s)"
@[inline] def traceAtCmdPos (cls : Name) (msg : Unit → MessageData) : TermElabM Unit :=
trace cls Syntax.missing msg
def dbgTrace {α} [HasToString α] (a : α) : TermElabM Unit :=
_root_.dbgTrace (toString a) $ fun _ => pure ()
/-- Auxiliary function for `liftMetaM` -/
private def mkMessageAux (ctx : Context) (ref : Syntax) (msgData : MessageData) (severity : MessageSeverity) : Message :=
mkMessageCore ctx.fileName ctx.fileMap msgData severity (ref.getPos.getD ctx.cmdPos)
/-- Auxiliary function for `liftMetaM` -/
private def fromMetaException (ctx : Context) (ref : Syntax) (ex : Meta.Exception) : Exception :=
Exception.ex $ Elab.Exception.error $ mkMessageAux ctx ref ex.toMessageData MessageSeverity.error
/-- Auxiliary function for `liftMetaM` -/
private def fromMetaState (ref : Syntax) (ctx : Context) (s : State) (newS : Meta.State) (oldTraceState : TraceState) : State :=
let traces := newS.traceState.traces;
let messages := traces.foldl (fun (messages : MessageLog) trace => messages.add (mkMessageAux ctx ref trace MessageSeverity.information)) s.messages;
{ toState := { traceState := oldTraceState, .. newS },
messages := messages,
.. s }
@[inline] def liftMetaM {α} (ref : Syntax) (x : MetaM α) : TermElabM α :=
fun ctx s =>
let oldTraceState := s.traceState;
match x ctx.toContext { traceState := {}, .. s.toState } with
| EStateM.Result.ok a newS => EStateM.Result.ok a (fromMetaState ref ctx s newS oldTraceState)
| EStateM.Result.error ex newS => EStateM.Result.error (fromMetaException ctx ref ex) (fromMetaState ref ctx s newS oldTraceState)
def ppGoal (ref : Syntax) (mvarId : MVarId) : TermElabM Format := liftMetaM ref $ Meta.ppGoal mvarId
def isType (ref : Syntax) (e : Expr) : TermElabM Bool := liftMetaM ref $ Meta.isType e
def isTypeFormer (ref : Syntax) (e : Expr) : TermElabM Bool := liftMetaM ref $ Meta.isTypeFormer e
def isDefEqNoConstantApprox (ref : Syntax) (t s : Expr) : TermElabM Bool := liftMetaM ref $ Meta.approxDefEq $ Meta.isDefEq t s
def isDefEq (ref : Syntax) (t s : Expr) : TermElabM Bool := liftMetaM ref $ Meta.fullApproxDefEq $ Meta.isDefEq t s
def inferType (ref : Syntax) (e : Expr) : TermElabM Expr := liftMetaM ref $ Meta.inferType e
def whnf (ref : Syntax) (e : Expr) : TermElabM Expr := liftMetaM ref $ Meta.whnf e
def whnfForall (ref : Syntax) (e : Expr) : TermElabM Expr := liftMetaM ref $ Meta.whnfForall e
def whnfCore (ref : Syntax) (e : Expr) : TermElabM Expr := liftMetaM ref $ Meta.whnfCore e
def unfoldDefinition? (ref : Syntax) (e : Expr) : TermElabM (Option Expr) := liftMetaM ref $ Meta.unfoldDefinition? e
def instantiateMVars (ref : Syntax) (e : Expr) : TermElabM Expr := liftMetaM ref $ Meta.instantiateMVars e
def isClass (ref : Syntax) (t : Expr) : TermElabM (Option Name) := liftMetaM ref $ Meta.isClass t
def mkFreshLevelMVar (ref : Syntax) : TermElabM Level := liftMetaM ref $ Meta.mkFreshLevelMVar
def mkFreshExprMVar (ref : Syntax) (type? : Option Expr := none) (kind : MetavarKind := MetavarKind.natural) (userName? : Name := Name.anonymous) : TermElabM Expr :=
match type? with
| some type => liftMetaM ref $ Meta.mkFreshExprMVar type userName? kind
| none => liftMetaM ref $ do u ← Meta.mkFreshLevelMVar; type ← Meta.mkFreshExprMVar (mkSort u); Meta.mkFreshExprMVar type userName? kind
def mkFreshTypeMVar (ref : Syntax) (kind : MetavarKind := MetavarKind.natural) (userName? : Name := Name.anonymous) : TermElabM Expr :=
liftMetaM ref $ do u ← Meta.mkFreshLevelMVar; Meta.mkFreshExprMVar (mkSort u) userName? kind
def getLevel (ref : Syntax) (type : Expr) : TermElabM Level := liftMetaM ref $ Meta.getLevel type
def mkForall (ref : Syntax) (xs : Array Expr) (e : Expr) : TermElabM Expr := liftMetaM ref $ Meta.mkForall xs e
def mkForallUsedOnly (ref : Syntax) (xs : Array Expr) (e : Expr) : TermElabM (Expr × Nat) := liftMetaM ref $ Meta.mkForallUsedOnly xs e
def mkLambda (ref : Syntax) (xs : Array Expr) (e : Expr) : TermElabM Expr := liftMetaM ref $ Meta.mkLambda xs e
def mkLet (ref : Syntax) (x : Expr) (e : Expr) : TermElabM Expr := mkLambda ref #[x] e
def trySynthInstance (ref : Syntax) (type : Expr) : TermElabM (LOption Expr) := liftMetaM ref $ Meta.trySynthInstance type
def mkAppM (ref : Syntax) (constName : Name) (args : Array Expr) : TermElabM Expr := liftMetaM ref $ Meta.mkAppM constName args
def mkExpectedTypeHint (ref : Syntax) (e : Expr) (expectedType : Expr) : TermElabM Expr := liftMetaM ref $ Meta.mkExpectedTypeHint e expectedType
def decLevel? (ref : Syntax) (u : Level) : TermElabM (Option Level) := liftMetaM ref $ Meta.decLevel? u
def decLevel (ref : Syntax) (u : Level) : TermElabM Level := do
u? ← decLevel? ref u;
match u? with
| some u => pure u
| none => throwError ref ("invalid universe level, " ++ u ++ " is not greater than 0")
/- This function is useful for inferring universe level parameters for function that take arguments such as `{α : Type u}`.
Recall that `Type u` is `Sort (u+1)` in Lean. Thus, given `α`, we must infer its universe level,
and then decrement 1 to obtain `u`. -/
def getDecLevel (ref : Syntax) (type : Expr) : TermElabM Level := do
u ← getLevel ref type;
decLevel ref u
@[inline] def savingMCtx {α} (x : TermElabM α) : TermElabM α := do
mctx ← getMCtx;
finally x (modify $ fun s => { mctx := mctx, .. s })
def liftLevelM {α} (x : LevelElabM α) : TermElabM α :=
fun ctx s =>
match (x { .. ctx }).run { .. s } with
| EStateM.Result.ok a newS => EStateM.Result.ok a { mctx := newS.mctx, ngen := newS.ngen, .. s }
| EStateM.Result.error ex newS => EStateM.Result.error (Exception.ex ex) s
def elabLevel (stx : Syntax) : TermElabM Level :=
liftLevelM $ Level.elabLevel stx
@[inline] def withConfig {α} (f : Meta.Config → Meta.Config) (x : TermElabM α) : TermElabM α :=
adaptReader (fun (ctx : Context) => { config := f ctx.config, .. ctx }) x
@[inline] def withTransparency {α} (mode : Meta.TransparencyMode) (x : TermElabM α) : TermElabM α :=
withConfig (fun config => { transparency := mode, .. config }) x
@[inline] def withReducible {α} (x : TermElabM α) : TermElabM α :=
withTransparency Meta.TransparencyMode.reducible x
/- Elaborate `x` with `stx` on the macro stack -/
@[inline] def withMacroExpansion {α} (beforeStx afterStx : Syntax) (x : TermElabM α) : TermElabM α :=
adaptReader (fun (ctx : Context) => { macroStack := { before := beforeStx, after := afterStx } :: ctx.macroStack, .. ctx }) x
/-
Add the given metavariable to the list of pending synthetic metavariables.
The method `synthesizeSyntheticMVars` is used to process the metavariables on this list. -/
def registerSyntheticMVar (ref : Syntax) (mvarId : MVarId) (kind : SyntheticMVarKind) : TermElabM Unit :=
modify $ fun s => { syntheticMVars := { mvarId := mvarId, ref := ref, kind := kind } :: s.syntheticMVars, .. s }
/-
Execute `x` without allowing it to postpone elaboration tasks.
That is, `tryPostpone` is a noop. -/
@[inline] def withoutPostponing {α} (x : TermElabM α) : TermElabM α :=
adaptReader (fun (ctx : Context) => { mayPostpone := false, .. ctx }) x
/-- Creates syntax for `(` <ident> `:` <type> `)` -/
def mkExplicitBinder (ident : Syntax) (type : Syntax) : Syntax :=
mkNode `Lean.Parser.Term.explicitBinder #[mkAtom "(", mkNullNode #[ident], mkNullNode #[mkAtom ":", type], mkNullNode, mkAtom ")"]
/-- Convert unassigned universe level metavariables into parameters. -/
def levelMVarToParam (e : Expr) : TermElabM Expr := do
ctx ← read;
mctx ← getMCtx;
let r := mctx.levelMVarToParam (fun n => ctx.levelNames.elem n) e;
modify $ fun s => { mctx := r.mctx, .. s };
pure r.expr
/--
Auxiliary method for creating fresh binder names.
Do not confuse with the method for creating fresh free/meta variable ids. -/
def mkFreshAnonymousName : TermElabM Name := do
s ← get;
let anonymousIdx := s.anonymousIdx;
modify $ fun s => { anonymousIdx := s.anonymousIdx + 1, .. s};
pure $ (`_a).appendIndexAfter anonymousIdx
/--
Auxiliary method for creating a `Syntax.ident` containing
a fresh name. This method is intended for creating fresh binder names.
It is just a thin layer on top of `mkFreshAnonymousName`. -/
def mkFreshAnonymousIdent (ref : Syntax) : TermElabM Syntax := do
n ← mkFreshAnonymousName;
pure $ mkIdentFrom ref n
/--
Auxiliary method for creating binder names for local instances.
Users expect them to be named as `_inst_<idx>`. -/
def mkFreshInstanceName : TermElabM Name := do
s ← get;
let instIdx := s.instImplicitIdx;
modify $ fun s => { instImplicitIdx := s.instImplicitIdx + 1, .. s};
pure $ (`_inst).appendIndexAfter instIdx
private partial def hasCDot : Syntax → Bool
| Syntax.node k args =>
if k == `Lean.Parser.Term.paren then false
else if k == `Lean.Parser.Term.cdot then true
else args.any hasCDot
| _ => false
/--
Auxiliary function for expandind the `·` notation.
The extra state `Array Syntax` contains the new binder names.
If `stx` is a `·`, we create a fresh identifier, store in the
extra state, and return it. Otherwise, we just return `stx`. -/
private partial def expandCDot : Syntax → StateT (Array Syntax) MacroM Syntax
| stx@(Syntax.node k args) =>
if k == `Lean.Parser.Term.paren then pure stx
else if k == `Lean.Parser.Term.cdot then withFreshMacroScope $ do
id ← `(a);
modify $ fun s => s.push id;
pure id
else do
args ← args.mapM expandCDot;
pure $ Syntax.node k args
| stx => pure stx
/--
Return `some` if succeeded expanding `·` notation occurring in
the given syntax. Otherwise, return `none`.
Examples:
- `· + 1` => `fun _a_1 => _a_1 + 1`
- `f · · b` => `fun _a_1 _a_2 => f _a_1 _a_2 b` -/
def expandCDot? (stx : Syntax) : MacroM (Option Syntax) :=
if hasCDot stx then do
(newStx, binders) ← (expandCDot stx).run #[];
`(fun $binders* => $newStx)
else
pure none
def mkFreshFVarId : TermElabM Name := do
s ← get;
let id := s.ngen.curr;
modify $ fun s => { ngen := s.ngen.next, .. s };
pure id
def withLocalDecl {α} (ref : Syntax) (n : Name) (binderInfo : BinderInfo) (type : Expr) (k : Expr → TermElabM α) : TermElabM α := do
fvarId ← mkFreshFVarId;
ctx ← read;
let lctx := ctx.lctx.mkLocalDecl fvarId n type binderInfo;
let localInsts := ctx.localInstances;
let fvar := mkFVar fvarId;
c? ← isClass ref type;
match c? with
| some c => adaptReader (fun (ctx : Context) => { lctx := lctx, localInstances := localInsts.push { className := c, fvar := fvar }, .. ctx }) $ k fvar
| none => adaptReader (fun (ctx : Context) => { lctx := lctx, .. ctx }) $ k fvar
def withLetDecl {α} (ref : Syntax) (n : Name) (type : Expr) (val : Expr) (k : Expr → TermElabM α) : TermElabM α := do
fvarId ← mkFreshFVarId;
ctx ← read;
let lctx := ctx.lctx.mkLetDecl fvarId n type val;
let localInsts := ctx.localInstances;
let fvar := mkFVar fvarId;
c? ← isClass ref type;
match c? with
| some c => adaptReader (fun (ctx : Context) => { lctx := lctx, localInstances := localInsts.push { className := c, fvar := fvar }, .. ctx }) $ k fvar
| none => adaptReader (fun (ctx : Context) => { lctx := lctx, .. ctx }) $ k fvar
def throwTypeMismatchError {α} (ref : Syntax) (expectedType : Expr) (eType : Expr) (e : Expr)
(f? : Option Expr := none) (extraMsg? : Option MessageData := none) : TermElabM α :=
let extraMsg : MessageData := match extraMsg? with
| none => Format.nil
| some extraMsg => Format.line ++ extraMsg;
match f? with
| none =>
let msg : MessageData :=
"type mismatch" ++ indentExpr e
++ Format.line ++ "has type" ++ indentExpr eType
++ Format.line ++ "but it is expected to have type" ++ indentExpr expectedType
++ extraMsg;
throwError ref msg
| some f => do
env ← getEnv; mctx ← getMCtx; lctx ← getLCtx; opts ← getOptions;
throwError ref $ Meta.Exception.mkAppTypeMismatchMessage f e { env := env, mctx := mctx, lctx := lctx, opts := opts } ++ extraMsg
@[inline] def withoutMacroStackAtErr {α} (x : TermElabM α) : TermElabM α :=
adaptReader (fun (ctx : Context) => { macroStackAtErr := false, .. ctx }) x
/- Try to synthesize metavariable using type class resolution.
This method assumes the local context and local instances of `instMVar` coincide
with the current local context and local instances.
Return `true` if the instance was synthesized successfully, and `false` if
the instance contains unassigned metavariables that are blocking the type class
resolution procedure. Throw an exception if resolution or assignment irrevocably fails. -/
def synthesizeInstMVarCore (ref : Syntax) (instMVar : MVarId) : TermElabM Bool := do
instMVarDecl ← getMVarDecl instMVar;
let type := instMVarDecl.type;
type ← instantiateMVars ref type;
result ← trySynthInstance ref type;
match result with
| LOption.some val => do
condM (isExprMVarAssigned instMVar)
(do oldVal ← instantiateMVars ref (mkMVar instMVar);
unlessM (isDefEq ref oldVal val) $
throwError ref $
"synthesized type class instance is not definitionally equal to expression "
++ "inferred by typing rules, synthesized" ++ indentExpr val
++ Format.line ++ "inferred" ++ indentExpr oldVal)
(assignExprMVar instMVar val);
pure true
| LOption.undef => pure false -- we will try later
| LOption.none => throwError ref ("failed to synthesize instance" ++ indentExpr type)
/--
Try to apply coercion to make sure `e` has type `expectedType`.
Relevant definitions:
```
class CoeT (α : Sort u) (a : α) (β : Sort v)
abbrev coe {α : Sort u} {β : Sort v} (a : α) [CoeT α a β] : β
``` -/
def tryCoe (ref : Syntax) (expectedType : Expr) (eType : Expr) (e : Expr) (f? : Option Expr) : TermElabM Expr :=
condM (isDefEq ref expectedType eType) (pure e) $ do
u ← getLevel ref eType;
v ← getLevel ref expectedType;
let coeTInstType := mkAppN (mkConst `CoeT [u, v]) #[eType, e, expectedType];
mvar ← mkFreshExprMVar ref coeTInstType MetavarKind.synthetic;
let eNew := mkAppN (mkConst `coe [u, v]) #[eType, expectedType, e, mvar];
let mvarId := mvar.mvarId!;
catch
(withoutMacroStackAtErr $ do
unlessM (synthesizeInstMVarCore ref mvarId) $
registerSyntheticMVar ref mvarId (SyntheticMVarKind.coe expectedType eType e f?);
pure eNew)
(fun ex =>
match ex with
| Exception.ex (Elab.Exception.error errMsg) => throwTypeMismatchError ref expectedType eType e f? errMsg.data
| _ => throwTypeMismatchError ref expectedType eType e f?)
private def isTypeApp? (ref : Syntax) (type : Expr) : TermElabM (Option (Expr × Expr)) := do
type ← withReducible $ whnf ref type;
match type with
| Expr.app m α _ => pure (some (m, α))
| _ => pure none
structure IsMonadResult :=
(m : Expr)
(α : Expr)
(inst : Expr)
private def isMonad? (ref : Syntax) (type : Expr) : TermElabM (Option IsMonadResult) := do
type ← withReducible $ whnf ref type;
match type with
| Expr.app m α _ =>
catch
(do
monadType ← mkAppM ref `Monad #[m];
result ← trySynthInstance ref monadType;
match result with
| LOption.some inst => pure (some { m := m, α := α, inst := inst })
| _ => pure none)
(fun _ => pure none)
| _ => pure none
def synthesizeInst (ref : Syntax) (type : Expr) : TermElabM Expr := do
type ← instantiateMVars ref type;
result ← trySynthInstance ref type;
match result with
| LOption.some val => pure val
| LOption.undef => throwError ref ("failed to synthesize instance" ++ indentExpr type)
| LOption.none => throwError ref ("failed to synthesize instance" ++ indentExpr type)
/-
Try coercions and monad lifts to make sure `e` has type `expectedType`.
If `expectedType` is of the form `n β` where `n` is a Monad, we try monad lifts and other extensions.
Otherwise, we just use the basic `tryCoe`.
Extensions for monads.
Given an expected type of the form `n β` and a given type `eType` is of the form `m α`. We use the following approaches.
1- Try to unify `n` and `m`. If it succeeds, then we rely on `tryCoe`, and
the instances
```
instance coeMethod {m : Type u → Type v} {α β : Type u} [∀ a, CoeT α a β] [Monad m] : Coe (m α) (m β)
instance pureCoeDepProp {m : Type → Type v} [HasPure m] {p : Prop} [Decidable p] : CoeDep (m Prop) (pure p) (m Bool)
```
2- If there is monad lift from `m` to `n` and we can unify `α` and `β`, we use
```
liftM : ∀ {m : Type u_1 → Type u_2} {n : Type u_1 → Type u_3} [self : HasMonadLiftT m n] {α : Type u_1}, m α → n α
```
3- If there is a monad lif from `m` to `n` and a coercion from `α` to `β`, we use
```
liftCoeM {m : Type u → Type v} {n : Type u → Type w} {α β : Type u} [HasMonadLiftT m n] [∀ a, CoeT α a β] [Monad n] (x : m α) : n β
```
Note that approach 3 does not subsume 1 because it is only applicable if there is a coercion from `α` to `β` for all values in `α`.
This is not the case for example for `pure $ x > 0` when the expected type is `IO Bool`. The given type is `IO Prop`, and
we only have a coercion from decidable propositions. Approach 1 works because it constructs the coercion `CoeT (m Prop) (pure $ x > 0) (m Bool)`
using the instance `pureCoeDepProp`.
Note that, approach 2 is more powerful than `tryCoe`.
Recall that type class resolution never assigns metavariables created by other modules.
Now, consider the following scenario
```lean
def g (x : Nat) : IO Nat := ...
deg h (x : Nat) : StateT Nat IO Nat := do
v ← g x;
IO.Println v;
...
```
Let's assume there is no other occurrence of `v` in `h`.
Thus, we have that the expected of `g x` is `StateT Nat IO ?α`,
and the given type is `IO Nat`. So, even if we add a coercion.
```
instance {α m n} [HasLiftT m n] {α} : Coe (m α) (n α) := ...
```
It is not applicable because TC would have to assign `?α := Nat`.
On the other hand, TC can easily solve `[HasLiftT IO (StateT Nat IO)]`
since this goal does not contain any metavariables. And then, we
convert `g x` into `liftM $ g x`.
-/
def tryLiftAndCoe (ref : Syntax) (expectedType : Expr) (eType : Expr) (e : Expr) (f? : Option Expr) : TermElabM Expr := do
some ⟨n, β, monadInst⟩ ← isMonad? ref expectedType | tryCoe ref expectedType eType e f?;
some (m, α) ← isTypeApp? ref eType | tryCoe ref expectedType eType e f?;
condM (isDefEq ref m n) (tryCoe ref expectedType eType e f?) $
catch
(do
-- Construct lift from `m` to `n`
hasMonadLiftType ← mkAppM ref `HasMonadLiftT #[m, n];
hasMonadLiftVal ← synthesizeInst ref hasMonadLiftType;
u_1 ← getDecLevel ref α;
u_2 ← getDecLevel ref eType;
u_3 ← getDecLevel ref expectedType;
let eNew := mkAppN (Lean.mkConst `liftM [u_1, u_2, u_3]) #[m, n, hasMonadLiftVal, α, e];
eNewType ← inferType ref eNew;
condM (isDefEq ref expectedType eNewType)
(pure eNew) -- approach 2 worked
(do
u ← getLevel ref α;
v ← getLevel ref β;
let coeTInstType := Lean.mkForall `a BinderInfo.default α $ mkAppN (mkConst `CoeT [u, v]) #[α, mkBVar 0, β];
coeTInstVal ← synthesizeInst ref coeTInstType;
let eNew := mkAppN (Lean.mkConst `liftCoeM [u_1, u_2, u_3]) #[m, n, α, β, hasMonadLiftVal, coeTInstVal, monadInst, e];
eNewType ← inferType ref eNew;
condM (isDefEq ref expectedType eNewType)
(pure eNew) -- approach 3 worked
(throwTypeMismatchError ref expectedType eType e f?)))
(fun _ => throwTypeMismatchError ref expectedType eType e f?)
/--
If `expectedType?` is `some t`, then ensure `t` and `eType` are definitionally equal.
If they are not, then try coercions.
Argument `f?` is used only for generating error messages. -/
def ensureHasTypeAux (ref : Syntax) (expectedType? : Option Expr) (eType : Expr) (e : Expr) (f? : Option Expr := none) : TermElabM Expr :=
match expectedType? with
| none => pure e
| some expectedType =>
/-
Recall that constant approximation is used to solve constraint of the form
```
?m t =?= s
```
where `t` is an arbitrary term, by assigning `?m := fun _ => s`
This approximation when not used carefully produces bad solutions, and may prevent coercions from being tried.
For example, consider the term `pure (x > 0)` with inferred type `?m Prop` and expected type `IO Bool`. In this situation, the
elaborator generates the unification constraint
```
?m Prop =?= IO Bool
```
It is not a higher-order pattern, not first-order approximation is applicable. However, constant approximation
produces the bogus solution `?m := fun _ => IO Bool`, and prevents the system from using the coercion from
the decidable proposition `x > 0` to `Bool`.
On the other hand, the constant approximation is desirable for elaborating the term
```
let f (x : _) := pure 0; f ()
```
with expected type `StateT Nat Id Nat`.
In this example, the following unification contraint is generated.
```
?m () (?n ()) =?= StateT Nat Id Nat
```
It is not a higher-order pattern, and first-order approximation fails.
However, constant approximation solves it by assigning
```
?m := fun _ => StateT Nat Id
?n := fun _ => Nat
```
Note that `f`s type is `(x : ?α) -> ?m x (?n x)`. The metavariables `?m` and `?n` may depend on `x`.
The `isDefEqNoConstantApprox` fails to unify the expected and inferred types. Then, `tryLiftAndCoe` first tries
the monadic extensions, and then falls back to `isDefEq` which enables all approximations.
-/
condM (isDefEqNoConstantApprox ref eType expectedType)
(pure e)
(tryLiftAndCoe ref expectedType eType e f?)
/--
If `expectedType?` is `some t`, then ensure `t` and type of `e` are definitionally equal.
If they are not, then try coercions. -/
def ensureHasType (ref : Syntax) (expectedType? : Option Expr) (e : Expr) : TermElabM Expr :=
match expectedType? with
| none => pure e
| _ => do eType ← inferType ref e; ensureHasTypeAux ref expectedType? eType e
private def exceptionToSorry (ref : Syntax) (errMsg : Message) (expectedType? : Option Expr) : TermElabM Expr := do
expectedType : Expr ← match expectedType? with
| none => mkFreshTypeMVar ref
| some expectedType => pure expectedType;
u ← getLevel ref expectedType;
-- TODO: should be `(sorryAx.{$u} $expectedType true) when we support antiquotations at that place
let syntheticSorry := mkApp2 (mkConst `sorryAx [u]) expectedType (mkConst `Bool.true);
unless errMsg.data.hasSyntheticSorry $ logMessage errMsg;
pure syntheticSorry
/-- If `mayPostpone == true`, throw `Expection.postpone`. -/
def tryPostpone : TermElabM Unit := do
ctx ← read;
when ctx.mayPostpone $ throw Exception.postpone
/-- If `mayPostpone == true` and `e`'s head is a metavariable, throw `Exception.postpone`. -/
def tryPostponeIfMVar (e : Expr) : TermElabM Unit := do
when e.getAppFn.isMVar $ tryPostpone
def tryPostponeIfNoneOrMVar (e? : Option Expr) : TermElabM Unit :=
match e? with
| some e => tryPostponeIfMVar e
| none => tryPostpone
private def postponeElabTerm (stx : Syntax) (expectedType? : Option Expr) : TermElabM Expr := do
trace `Elab.postpone stx $ fun _ => stx ++ " : " ++ expectedType?;
mvar ← mkFreshExprMVar stx expectedType? MetavarKind.syntheticOpaque;
ctx ← read;
registerSyntheticMVar stx mvar.mvarId! (SyntheticMVarKind.postponed ctx.macroStack);
pure mvar
/-
Helper function for `elabTerm` is tries the registered elaboration functions for `stxNode` kind until it finds one that supports the syntax or
an error is found. -/
private def elabTermUsing (s : State) (stx : Syntax) (expectedType? : Option Expr) (catchExPostpone : Bool)
: List TermElab → TermElabM Expr
| [] => do
let refFmt := stx.prettyPrint;
throwError stx ("unexpected syntax" ++ MessageData.nest 2 (Format.line ++ refFmt))
| (elabFn::elabFns) => catch (elabFn stx expectedType?)
(fun ex => match ex with
| Exception.ex (Elab.Exception.error errMsg) => do ctx ← read; if ctx.errToSorry then exceptionToSorry stx errMsg expectedType? else throw ex
| Exception.ex Elab.Exception.unsupportedSyntax => do set s; elabTermUsing elabFns
| Exception.postpone =>
if catchExPostpone then do
/- If `elab` threw `Exception.postpone`, we reset any state modifications.
For example, we want to make sure pending synthetic metavariables created by `elab` before
it threw `Exception.postpone` are discarded.
Note that we are also discarding the messages created by `elab`.
For example, consider the expression.
`((f.x a1).x a2).x a3`
Now, suppose the elaboration of `f.x a1` produces an `Exception.postpone`.
Then, a new metavariable `?m` is created. Then, `?m.x a2` also throws `Exception.postpone`
because the type of `?m` is not yet known. Then another, metavariable `?n` is created, and
finally `?n.x a3` also throws `Exception.postpone`. If we did not restore the state, we would
keep "dead" metavariables `?m` and `?n` on the pending synthetic metavariable list. This is
wasteful because when we resume the elaboration of `((f.x a1).x a2).x a3`, we start it from scratch
and new metavariables are created for the nested functions. -/
set s;
postponeElabTerm stx expectedType?
else
throw ex)
instance : MonadMacroAdapter TermElabM :=
{ getEnv := getEnv,
getCurrMacroScope := getCurrMacroScope,
getNextMacroScope := do s ← get; pure s.nextMacroScope,
setNextMacroScope := fun next => modify $ fun s => { nextMacroScope := next, .. s },
throwError := @throwError,
throwUnsupportedSyntax := @throwUnsupportedSyntax}
/- Main loop for `elabTerm` -/
partial def elabTermAux (expectedType? : Option Expr) (catchExPostpone := true) : Syntax → TermElabM Expr
| stx => withFreshMacroScope $ withIncRecDepth stx $ do
trace `Elab.step stx $ fun _ => expectedType? ++ " " ++ stx;
s ← get;
stxNew? ← catch
(do newStx ← adaptMacro (getMacros s.env) stx; pure (some newStx))
(fun ex => match ex with
| Exception.ex Elab.Exception.unsupportedSyntax => pure none
| _ => throw ex);
match stxNew? with
| some stxNew => withMacroExpansion stx stxNew $ elabTermAux stxNew
| _ =>
let table := (termElabAttribute.ext.getState s.env).table;
let k := stx.getKind;
match table.find? k with
| some elabFns => elabTermUsing s stx expectedType? catchExPostpone elabFns
| none => throwError stx ("elaboration function for '" ++ toString k ++ "' has not been implemented")
private def isExplicit (stx : Syntax) : Bool :=
match_syntax stx with
| `(@$f) => true
| _ => false
private def isExplicitApp (stx : Syntax) : Bool :=
stx.getKind == `Lean.Parser.Term.app && isExplicit (stx.getArg 0)
/--
Return true with `expectedType` is of the form `{a : α} → β` or `[a : α] → β`, and
`stx` is not `@f` nor `@f arg1 ...` -/
def useImplicitLambda? (stx : Syntax) (expectedType? : Option Expr) : TermElabM (Option Expr) :=
if isExplicit stx || isExplicitApp stx then pure none
else match expectedType? with
| some expectedType => do
expectedType ← whnfForall stx expectedType;
match expectedType with
| Expr.forallE _ _ _ c => pure $ if c.binderInfo.isExplicit then none else some expectedType
| _ => pure $ none
| _ => pure $ none
def elabImplicitLambdaAux (stx : Syntax) (catchExPostpone : Bool) (expectedType : Expr) (fvars : Array Expr) : TermElabM Expr := do
body ← elabTermAux expectedType catchExPostpone stx;
-- body ← ensureHasType stx expectedType body;
r ← mkLambda stx fvars body;
trace `Elab.implicitForall stx $ fun _ => r;
pure r
partial def elabImplicitLambda (stx : Syntax) (catchExPostpone : Bool) : Expr → Array Expr → TermElabM Expr
| type@(Expr.forallE n d b c), fvars =>
if c.binderInfo.isExplicit then
elabImplicitLambdaAux stx catchExPostpone type fvars
else withFreshMacroScope $ do
n ← MonadQuotation.addMacroScope n;
withLocalDecl stx n c.binderInfo d $ fun fvar => do
type ← whnfForall stx (b.instantiate1 fvar);
elabImplicitLambda type (fvars.push fvar)
| type, fvars =>
elabImplicitLambdaAux stx catchExPostpone type fvars
/--
Main function for elaborating terms.
It extracts the elaboration methods from the environment using the node kind.
Recall that the environment has a mapping from `SyntaxNodeKind` to `TermElab` methods.
It creates a fresh macro scope for executing the elaboration method.
All unlogged trace messages produced by the elaboration method are logged using
the position information at `stx`. If the elaboration method throws an `Exception.error` and `errToSorry == true`,
the error is logged and a synthetic sorry expression is returned.
If the elaboration throws `Exception.postpone` and `catchExPostpone == true`,
a new synthetic metavariable of kind `SyntheticMVarKind.postponed` is created, registered,
and returned.
The option `catchExPostpone == false` is used to implement `resumeElabTerm`
to prevent the creation of another synthetic metavariable when resuming the elaboration. -/
def elabTerm (stx : Syntax) (expectedType? : Option Expr) (catchExPostpone := true) : TermElabM Expr := do
implicit? ← useImplicitLambda? stx expectedType?;
match implicit? with
| some expectedType => elabImplicitLambda stx catchExPostpone expectedType #[]
| none => elabTermAux expectedType? catchExPostpone stx
/-- Adapt a syntax transformation to a regular, term-producing elaborator. -/
def adaptExpander (exp : Syntax → TermElabM Syntax) : TermElab :=
fun stx expectedType? => do
stx' ← exp stx;
withMacroExpansion stx stx' $ elabTerm stx' expectedType?
@[inline] def withLCtx {α} (lctx : LocalContext) (localInsts : LocalInstances) (x : TermElabM α) : TermElabM α :=
adaptReader (fun (ctx : Context) => { lctx := lctx, localInstances := localInsts, .. ctx }) x
def resetSynthInstanceCache : TermElabM Unit :=
modify $ fun s => { cache := { synthInstance := {}, .. s.cache }, .. s }
@[inline] def resettingSynthInstanceCache {α} (x : TermElabM α) : TermElabM α := do
s ← get;
let savedSythInstance := s.cache.synthInstance;
resetSynthInstanceCache;
finally x (modify $ fun s => { cache := { synthInstance := savedSythInstance, .. s.cache }, .. s })
@[inline] def resettingSynthInstanceCacheWhen {α} (b : Bool) (x : TermElabM α) : TermElabM α :=
if b then resettingSynthInstanceCache x else x
/--
Execute `x` using the given metavariable's `LocalContext` and `LocalInstances`.
The type class resolution cache is flushed when executing `x` if its `LocalInstances` are
different from the current ones. -/
def withMVarContext {α} (mvarId : MVarId) (x : TermElabM α) : TermElabM α := do
mvarDecl ← getMVarDecl mvarId;
ctx ← read;
let needReset := ctx.localInstances == mvarDecl.localInstances;
withLCtx mvarDecl.lctx mvarDecl.localInstances $ resettingSynthInstanceCacheWhen needReset x
def mkInstMVar (ref : Syntax) (type : Expr) : TermElabM Expr := do
mvar ← mkFreshExprMVar ref type MetavarKind.synthetic;
let mvarId := mvar.mvarId!;
unlessM (synthesizeInstMVarCore ref mvarId) $
registerSyntheticMVar ref mvarId SyntheticMVarKind.typeClass;
pure mvar
/-
Relevant definitions:
```
class CoeSort (α : Sort u) (β : outParam (Sort v))
abbrev coeSort {α : Sort u} {β : Sort v} (a : α) [CoeSort α β] : β
``` -/
private def tryCoeSort (ref : Syntax) (α : Expr) (a : Expr) : TermElabM Expr := do
β ← mkFreshTypeMVar ref;
u ← getLevel ref α;
v ← getLevel ref β;
let coeSortInstType := mkAppN (Lean.mkConst `CoeSort [u, v]) #[α, β];
mvar ← mkFreshExprMVar ref coeSortInstType MetavarKind.synthetic;
let mvarId := mvar.mvarId!;
catch
(withoutMacroStackAtErr $ condM (synthesizeInstMVarCore ref mvarId)
(pure $ mkAppN (Lean.mkConst `coeSort [u, v]) #[α, β, a, mvar])
(throwError ref "type expected"))
(fun ex =>
match ex with
| Exception.ex (Elab.Exception.error errMsg) => throwError ref ("type expected" ++ Format.line ++ errMsg.data)
| _ => throwError ref "type expected")
/--
Make sure `e` is a type by inferring its type and making sure it is a `Expr.sort`
or is unifiable with `Expr.sort`, or can be coerced into one. -/
def ensureType (ref : Syntax) (e : Expr) : TermElabM Expr :=
condM (isType ref e)
(pure e)
(do
eType ← inferType ref e;
u ← mkFreshLevelMVar ref;
condM (isDefEq ref eType (mkSort u))
(pure e)
(tryCoeSort ref eType e))
/-- Elaborate `stx` and ensure result is a type. -/
def elabType (stx : Syntax) : TermElabM Expr := do
u ← mkFreshLevelMVar stx;
type ← elabTerm stx (mkSort u);
ensureType stx type
def addDecl (ref : Syntax) (decl : Declaration) : TermElabM Unit := do
env ← getEnv;
match env.addDecl decl with
| Except.ok env => setEnv env
| Except.error kex => do opts ← getOptions; throwError ref (kex.toMessageData opts)
def compileDecl (ref : Syntax) (decl : Declaration) : TermElabM Unit := do
env ← getEnv;
opts ← getOptions;
match env.compileDecl opts decl with
| Except.ok env => setEnv env
| Except.error kex => throwError ref (kex.toMessageData opts)
private partial def mkAuxNameAux (env : Environment) (base : Name) : Nat → Name
| i =>
let candidate := base.appendIndexAfter i;
if env.contains candidate then
mkAuxNameAux (i+1)
else
candidate
def mkAuxName (ref : Syntax) (suffix : Name) : TermElabM Name := do
env ← getEnv;
ctx ← read;
match ctx.declName? with
| none => throwError ref "auxiliary declaration cannot be created when declaration name is not available"
| some declName => pure $ mkAuxNameAux env (declName ++ suffix) 1
/- =======================================
Builtin elaboration functions
======================================= -/
@[builtinTermElab «prop»] def elabProp : TermElab :=
fun _ _ => pure $ mkSort levelZero
@[builtinTermElab «sort»] def elabSort : TermElab :=
fun _ _ => pure $ mkSort levelZero
@[builtinTermElab «type»] def elabTypeStx : TermElab :=
fun _ _ => pure $ mkSort levelOne
@[builtinTermElab «hole»] def elabHole : TermElab :=
fun stx expectedType? => mkFreshExprMVar stx expectedType?
@[builtinTermElab «namedHole»] def elabNamedHole : TermElab :=
fun stx expectedType? =>
let name := stx.getIdAt 1;
mkFreshExprMVar stx expectedType? MetavarKind.syntheticOpaque name
def mkTacticMVar (ref : Syntax) (type : Expr) (tacticCode : Syntax) : TermElabM Expr := do
mvar ← mkFreshExprMVar ref type MetavarKind.syntheticOpaque `main;
let mvarId := mvar.mvarId!;
registerSyntheticMVar ref mvarId $ SyntheticMVarKind.tactic tacticCode;
pure mvar
@[builtinTermElab tacticBlock] def elabTacticBlock : TermElab :=
fun stx expectedType? =>
match expectedType? with
| some expectedType => mkTacticMVar stx expectedType (stx.getArg 1)
| none => throwError stx ("invalid tactic block, expected type has not been provided")
@[builtinTermElab byTactic] def elabByTactic : TermElab :=
fun stx expectedType? =>
match expectedType? with
| some expectedType => mkTacticMVar stx expectedType (stx.getArg 1)
| none => throwError stx ("invalid 'by' tactic, expected type has not been provided")
/-- Main loop for `mkPairs`. -/
private partial def mkPairsAux (elems : Array Syntax) : Nat → Syntax → MacroM Syntax
| i, acc =>
if i > 0 then do
let i := i - 1;
let elem := elems.get! i;
acc ← `(Prod.mk $elem $acc);
mkPairsAux i acc
else
pure acc
/-- Return syntax `Prod.mk elems[0] (Prod.mk elems[1] ... (Prod.mk elems[elems.size - 2] elems[elems.size - 1])))` -/
def mkPairs (elems : Array Syntax) : MacroM Syntax :=
mkPairsAux elems (elems.size - 1) elems.back
/--
Try to expand `·` notation, and if successful elaborate result.
This method is used to elaborate the Lean parentheses notation.
Recall that in Lean the `·` notation must be surrounded by parentheses.
We may change this is the future, but right now, here are valid examples
- `(· + 1)`
- `(f ⟨·, 1⟩ ·)`
- `(· + ·)`
- `(f · a b)` -/
private def elabCDot (stx : Syntax) (expectedType? : Option Expr) : TermElabM Expr := do
stx? ← liftMacroM $ expandCDot? stx;
match stx? with
| some stx' => withMacroExpansion stx stx' (elabTerm stx' expectedType?)
| none => elabTerm stx expectedType?
@[builtinTermElab paren] def elabParen : TermElab :=
fun stx expectedType? =>
let ref := stx;
match_syntax ref with
| `(()) => pure $ Lean.mkConst `Unit.unit
| `(($e : $type)) => do
type ← elabType type;
e ← elabCDot e type;
ensureHasType ref type e
| `(($e)) => elabCDot e expectedType?
| `(($e, $es*)) => do
pairs ← liftMacroM $ mkPairs (#[e] ++ es.getEvenElems);
withMacroExpansion stx pairs (elabTerm pairs expectedType?)
| _ => throwError stx "unexpected parentheses notation"
@[builtinTermElab «listLit»] def elabListLit : TermElab :=
fun stx expectedType? => do
let openBkt := stx.getArg 0;
let args := stx.getArg 1;
let closeBkt := stx.getArg 2;
let consId := mkTermIdFrom openBkt `List.cons;
let nilId := mkTermIdFrom closeBkt `List.nil;
let newStx := args.foldSepRevArgs (fun arg r => mkAppStx consId #[arg, r]) nilId;
withMacroExpansion stx newStx $ elabTerm newStx expectedType?
@[builtinTermElab «arrayLit»] def elabArrayLit : TermElab :=
fun stx expectedType? => do
match_syntax stx with
| `(#[$args*]) => do
newStx ← `(List.toArray [$args*]);
withMacroExpansion stx newStx (elabTerm newStx expectedType?)
| _ => throwError stx "unexpected array literal syntax"
private partial def resolveLocalNameAux (lctx : LocalContext) : Name → List String → Option (Expr × List String)
| n, projs =>
match lctx.findFromUserName? n with
| some decl => some (decl.toExpr, projs)
| none => match n with
| Name.str pre s _ => resolveLocalNameAux pre (s::projs)
| _ => none
private def resolveLocalName (n : Name) : TermElabM (Option (Expr × List String)) := do
lctx ← getLCtx;
pure $ resolveLocalNameAux lctx n []
/- Return true iff `stx` is a `Term.id`, and it is local variable. -/
def isLocalTermId? (stx : Syntax) (relaxed : Bool := false) : TermElabM (Option Expr) :=
match stx.isTermId? relaxed with
| some (Syntax.ident _ _ val _, _) => do
r? ← resolveLocalName val;
match r? with
| some (fvar, []) => pure (some fvar)
| _ => pure none
| _ => pure none
private def mkFreshLevelMVars (ref : Syntax) (num : Nat) : TermElabM (List Level) :=
num.foldM (fun _ us => do u ← mkFreshLevelMVar ref; pure $ u::us) []
/--
Create an `Expr.const` using the given name and explicit levels.
Remark: fresh universe metavariables are created if the constant has more universe
parameters than `explicitLevels`. -/
def mkConst (ref : Syntax) (constName : Name) (explicitLevels : List Level := []) : TermElabM Expr := do
env ← getEnv;
match env.find? constName with
| none => throwError ref ("unknown constant '" ++ constName ++ "'")
| some cinfo =>
if explicitLevels.length > cinfo.lparams.length then
throwError ref ("too many explicit universe levels")
else do
let numMissingLevels := cinfo.lparams.length - explicitLevels.length;
us ← mkFreshLevelMVars ref numMissingLevels;
pure $ Lean.mkConst constName (explicitLevels ++ us)
private def mkConsts (ref : Syntax) (candidates : List (Name × List String)) (explicitLevels : List Level) : TermElabM (List (Expr × List String)) := do
env ← getEnv;
candidates.foldlM
(fun result ⟨constName, projs⟩ => do
-- TODO: better suppor for `mkConst` failure. We may want to cache the failures, and report them if all candidates fail.
const ← mkConst ref constName explicitLevels;
pure $ (const, projs) :: result)
[]
def resolveGlobalName (n : Name) : TermElabM (List (Name × List String)) := do
env ← getEnv;
currNamespace ← getCurrNamespace;
openDecls ← getOpenDecls;
pure (Lean.Elab.resolveGlobalName env currNamespace openDecls n)
def resolveName (ref : Syntax) (n : Name) (preresolved : List (Name × List String)) (explicitLevels : List Level) : TermElabM (List (Expr × List String)) := do
result? ← resolveLocalName n;
match result? with
| some (e, projs) => do
unless explicitLevels.isEmpty $
throwError ref ("invalid use of explicit universe parameters, '" ++ toString e.fvarId! ++ "' is a local");
pure [(e, projs)]
| none =>
let process (candidates : List (Name × List String)) : TermElabM (List (Expr × List String)) := do {
when candidates.isEmpty $ do {
mainModule ← getMainModule;
let view := extractMacroScopes n;
throwError ref ("unknown identifier '" ++ view.format mainModule ++ "'")
};
mkConsts ref candidates explicitLevels
};
if preresolved.isEmpty then do
r ← resolveGlobalName n;
process r
else
process preresolved
@[builtinTermElab cdot] def elabBadCDot : TermElab :=
fun stx _ => throwError stx "invalid occurrence of `·` notation, it must be surrounded by parentheses (e.g. `(· + 1)`)"
/-
A raw literal is not a valid term, but it is nice to have a handler for them because it allows `macros` to insert them into terms.
TODO: check whether we still need wrapper nodes around literals. -/
@[builtinTermElab strLit] def elabRawStrLit : TermElab :=
fun stx _ => do
match stx.isStrLit? with
| some val => pure $ mkStrLit val
| none => throwError stx "ill-formed syntax"
@[builtinTermElab str] def elabStr : TermElab :=
fun stx expectedType? => elabRawStrLit (stx.getArg 0) expectedType?
/- See `elabRawStrLit` -/
@[builtinTermElab numLit] def elabRawNumLit : TermElab :=
fun stx expectedType? => do
let ref := stx;
val ← match stx.isNatLit? with
| some val => pure (mkNatLit val)
| none => throwError stx "ill-formed syntax";
typeMVar ← mkFreshTypeMVar ref MetavarKind.synthetic;
registerSyntheticMVar ref typeMVar.mvarId! (SyntheticMVarKind.withDefault (Lean.mkConst `Nat));
match expectedType? with
| some expectedType => do isDefEq ref expectedType typeMVar; pure ()
| _ => pure ();
u ← getLevel ref typeMVar;
u ← decLevel ref u;
mvar ← mkInstMVar ref (mkApp (Lean.mkConst `HasOfNat [u]) typeMVar);
pure $ mkApp3 (Lean.mkConst `HasOfNat.ofNat [u]) typeMVar mvar val
@[builtinTermElab num] def elabNum : TermElab :=
fun stx expectedType? => elabRawNumLit (stx.getArg 0) expectedType?
/- See `elabRawStrLit` -/
@[builtinTermElab charLit] def elabRawCharLit : TermElab :=
fun stx _ => do
match stx.isCharLit? with
| some val => pure $ mkApp (Lean.mkConst `Char.ofNat) (mkNatLit val.toNat)
| none => throwError stx "ill-formed syntax"
@[builtinTermElab char] def elabChar : TermElab :=
fun stx expectedType? => elabRawCharLit (stx.getArg 0) expectedType?
@[builtinTermElab quotedName] def elabQuotedName : TermElab :=
fun stx _ =>
match (stx.getArg 0).isNameLit? with
| some val => pure $ toExpr val
| none => throwError stx "ill-formed syntax"
instance MetaHasEval {α} [MetaHasEval α] : MetaHasEval (TermElabM α) :=
⟨fun env opts x _ => do
let ctx : Context := {
config := { opts := opts },
fileName := "<TermElabM>",
fileMap := arbitrary _,
cmdPos := 0,
currNamespace := Name.anonymous,
currRecDepth := 0,
maxRecDepth := getMaxRecDepth opts
};
let showMessages (s : State) : IO Unit := do {
s.messages.forM $ fun m => IO.println $ format m
};
match x ctx { env := env } with
| EStateM.Result.ok a s => do
showMessages s;
MetaHasEval.eval s.env opts a
| EStateM.Result.error (Exception.ex (Elab.Exception.error err)) s => do
showMessages s;
throw (IO.userError (toString (format err)))
| EStateM.Result.error (Exception.ex Elab.Exception.unsupportedSyntax) s => do
showMessages s;
throw (IO.userError "error: unsupported syntax")
| EStateM.Result.error Exception.postpone s => do
showMessages s;
throw (IO.userError "error: elaborator postponed")⟩
end Term
@[init] private def regTraceClasses : IO Unit := do
registerTraceClass `Elab.postpone;
registerTraceClass `Elab.coe;
registerTraceClass `Elab.debug;
pure ()
export Term (TermElabM)
end Elab
end Lean
|
f232ba84a65ae7987b5f0e5313ba993a25f6ca9e | 5fbbd711f9bfc21ee168f46a4be146603ece8835 | /lean/natural_number_game/inequality/09.lean | 28b49cefb0a366549b66fb1cea292a077db47e11 | [
"LicenseRef-scancode-warranty-disclaimer"
] | no_license | goedel-gang/maths | 22596f71e3fde9c088e59931f128a3b5efb73a2c | a20a6f6a8ce800427afd595c598a5ad43da1408d | refs/heads/master | 1,623,055,941,960 | 1,621,599,441,000 | 1,621,599,441,000 | 169,335,840 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 288 | lean | theorem le_total (a b : mynat) : a ≤ b ∨ b ≤ a :=
begin
-- this feels too long
induction b with n hn,
right,
exact zero_le a,
cases hn,
left,
exact le_succ a n hn,
cases hn with d hd,
cases d with t,
left,
use succ 0,
rw hd,
ring,
right,
use t,
end
|
71c6b17744baf9bafe0d3c86e3900917b4a70fdb | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/algebra/char_p/algebra.lean | c7467d2660728c0b7ea2e71717b4ea58c15eb7a0 | [
"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,662 | lean | /-
Copyright (c) 2021 Jon Eugster. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jon Eugster, Eric Wieser
-/
import algebra.char_p.basic
import ring_theory.localization
import algebra.free_algebra
/-!
# Characteristics of algebras
In this file we describe the characteristic of `R`-algebras.
In particular we are interested in the characteristic of free algebras over `R`
and the fraction field `fraction_ring R`.
## Main results
- `char_p_of_injective_algebra_map` If `R →+* A` is an injective algebra map
then `A` has the same characteristic as `R`.
Instances constructed from this result:
- Any `free_algebra R X` has the same characteristic as `R`.
- The `fraction_ring R` of an integral domain `R` has the same characteristic as `R`.
-/
/-- If the algebra map `R →+* A` is injective then `A` has the same characteristic as `R`. -/
lemma char_p_of_injective_algebra_map {R A : Type*} [comm_semiring R] [semiring A] [algebra R A]
(h : function.injective (algebra_map R A)) (p : ℕ) [char_p R p] : char_p A p :=
{ cast_eq_zero_iff := λx,
begin
rw ←char_p.cast_eq_zero_iff R p x,
change algebra_map ℕ A x = 0 ↔ algebra_map ℕ R x = 0,
rw is_scalar_tower.algebra_map_apply ℕ R A x,
refine iff.trans _ h.eq_iff,
rw ring_hom.map_zero,
end }
/-- If the algebra map `R →+* A` is injective and `R` has characteristic zero then so does `A`. -/
lemma char_zero_of_injective_algebra_map {R A : Type*} [comm_semiring R] [semiring A] [algebra R A]
(h : function.injective (algebra_map R A)) [char_zero R] : char_zero A :=
{ cast_injective := λ x y hxy,
begin
change algebra_map ℕ A x = algebra_map ℕ A y at hxy,
rw is_scalar_tower.algebra_map_apply ℕ R A x at hxy,
rw is_scalar_tower.algebra_map_apply ℕ R A y at hxy,
exact char_zero.cast_injective (h hxy),
end }
-- `char_p.char_p_to_char_zero A _ (char_p_of_injective_algebra_map h 0)` does not work
-- here as it would require `ring A`.
section
variables (K L : Type*) [field K] [comm_semiring L] [nontrivial L] [algebra K L]
lemma algebra.char_p_iff (p : ℕ) : char_p K p ↔ char_p L p :=
(algebra_map K L).char_p_iff_char_p p
end
namespace free_algebra
variables {R X : Type*} [comm_semiring R] (p : ℕ)
/-- If `R` has characteristic `p`, then so does `free_algebra R X`. -/
instance char_p [char_p R p] : char_p (free_algebra R X) p :=
char_p_of_injective_algebra_map free_algebra.algebra_map_left_inverse.injective p
/-- If `R` has characteristic `0`, then so does `free_algebra R X`. -/
instance char_zero [char_zero R] : char_zero (free_algebra R X) :=
char_zero_of_injective_algebra_map free_algebra.algebra_map_left_inverse.injective
end free_algebra
namespace is_fraction_ring
variables (R : Type*) {K : Type*} [comm_ring R]
[field K] [algebra R K] [is_fraction_ring R K]
variables (p : ℕ)
/-- If `R` has characteristic `p`, then so does Frac(R). -/
lemma char_p_of_is_fraction_ring [char_p R p] : char_p K p :=
char_p_of_injective_algebra_map (is_fraction_ring.injective R K) p
/-- If `R` has characteristic `0`, then so does Frac(R). -/
lemma char_zero_of_is_fraction_ring [char_zero R] : char_zero K :=
@char_p.char_p_to_char_zero K _ (char_p_of_is_fraction_ring R 0)
variables [is_domain R]
/-- If `R` has characteristic `p`, then so does `fraction_ring R`. -/
instance char_p [char_p R p] : char_p (fraction_ring R) p :=
char_p_of_is_fraction_ring R p
/-- If `R` has characteristic `0`, then so does `fraction_ring R`. -/
instance char_zero [char_zero R] : char_zero (fraction_ring R) :=
char_zero_of_is_fraction_ring R
end is_fraction_ring
|
4ba8135dd8beda61cc4769e613dfb6fbdcb97038 | 6dc0c8ce7a76229dd81e73ed4474f15f88a9e294 | /tests/lean/run/monadControl.lean | d007ab27d05600f56a33306fb1ee8d6d8a7257d3 | [
"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 | 1,214 | lean |
@[inline] def f {α} (s : String) (x : IO α) : IO α := do
IO.println "started";
IO.println s;
let a ← x;
IO.println ("ended");
pure a
@[inline] def f'' {α m} [MonadControlT IO m] [Monad m] (msg : String) (x : m α) : m α := do
controlAt IO fun runInBase => f msg (runInBase x)
abbrev M := StateT Bool $ ExceptT String $ StateT String $ ReaderT Nat $ StateT Nat IO
def tst : M Nat := do
let a ← f'' "hello" do { let s ← getThe Nat; let ctx ← read; modifyThe Nat fun s => s + ctx; when (s > 10) $ throw "ERROR"; getThe Nat };
modifyThe Nat Nat.succ;
pure a
#eval (((tst.run true).run "world").run 1000).run 11
@[inline] def g {α} (s : String) (x : Nat → IO α) : IO α := do
IO.println "started";
IO.println s;
let a ← x s.length;
IO.println ("ended");
pure a
@[inline] def g' {α m} [MonadControlT IO m] [Monad m] (msg : String) (x : Nat → m α) : m α := do
controlAt IO fun runInBase => g msg (fun n => runInBase (x n))
def tst2 : M Nat := do
let a ← g' "hello" fun x => do { let s ← getThe Nat; let ctx ← read; modifyThe Nat fun s => s + ctx + x; when (s > 10) $ throw "ERROR"; getThe Nat };
modifyThe Nat Nat.succ;
pure a
#eval (((tst2.run true).run "world").run 1000).run 10
|
31b8fe02863d5749c2edd1625c4b3877385ac3e1 | 69d4931b605e11ca61881fc4f66db50a0a875e39 | /src/algebra/homology/homological_complex.lean | d498bcd9b470fb4d3daaa12e9f0eebcabbc3fe59 | [
"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 | 29,952 | lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Scott Morrison
-/
import algebra.homology.complex_shape
import category_theory.subobject.limits
/-!
# Homological complexes.
A `homological_complex V c` with a "shape" controlled by `c : complex_shape ι`
has chain groups `X i` (objects in `V`) indexed by `i : ι`,
and a differential `d i j` whenever `c.rel i j`.
We in fact ask for differentials `d i j` for all `i j : ι`,
but have a field `shape'` requiring that these are zero when not allowed by `c`.
This avoids a lot of dependent type theory hell!
The composite of any two differentials `d i j ≫ d j k` must be zero.
We provide `chain_complex V α` for
`α`-indexed chain complexes in which `d i j ≠ 0` only if `j + 1 = i`,
and similarly `cochain_complex V α`, with `i = j + 1`.
There is a category structure, where morphisms are chain maps.
For `C : homological_complex V c`, we define `C.X_next i`, which is either `C.X j` for some
arbitrarily chosen `j` such that `c.r i j`, or the zero object if there is no such `j`.
Similarly we have `C.X_prev j`.
Defined in terms of these we have `C.d_from i : C.X i ⟶ C.X_next i` and
`C.d_to j : C.X_prev j ⟶ C.X j`, which are either defined as `C.d i j`, or zero, as needed.
-/
universes v u
open category_theory category_theory.limits
variables {ι : Type*}
variables (V : Type u) [category.{v} V] [has_zero_morphisms V]
/--
A `homological_complex V c` with a "shape" controlled by `c : complex_shape ι`
has chain groups `X i` (objects in `V`) indexed by `i : ι`,
and a differential `d i j` whenever `c.rel i j`.
We in fact ask for differentials `d i j` for all `i j : ι`,
but have a field `shape'` requiring that these are zero when not allowed by `c`.
This avoids a lot of dependent type theory hell!
The composite of any two differentials `d i j ≫ d j k` must be zero.
-/
structure homological_complex (c : complex_shape ι) :=
(X : ι → V)
(d : Π i j, X i ⟶ X j)
(shape' : ∀ i j, ¬ c.rel i j → d i j = 0 . obviously)
(d_comp_d' : ∀ i j k, c.rel i j → c.rel j k → d i j ≫ d j k = 0 . obviously)
namespace homological_complex
restate_axiom shape'
attribute [simp] shape
variables {V} {c : complex_shape ι}
@[simp, reassoc] lemma d_comp_d (C : homological_complex V c) (i j k : ι) :
C.d i j ≫ C.d j k = 0 :=
begin
by_cases hij : c.rel i j,
{ by_cases hjk : c.rel j k,
{ exact C.d_comp_d' i j k hij hjk },
{ rw [C.shape j k hjk, comp_zero] } },
{ rw [C.shape i j hij, zero_comp] }
end
end homological_complex
/--
An `α`-indexed chain complex is a `homological_complex`
in which `d i j ≠ 0` only if `j + 1 = i`.
-/
abbreviation chain_complex (α : Type*) [add_right_cancel_semigroup α] [has_one α] : Type* :=
homological_complex V (complex_shape.down α)
/--
An `α`-indexed cochain complex is a `homological_complex`
in which `d i j ≠ 0` only if `i + 1 = j`.
-/
abbreviation cochain_complex (α : Type*) [add_right_cancel_semigroup α] [has_one α] : Type* :=
homological_complex V (complex_shape.up α)
namespace chain_complex
@[simp] lemma prev (α : Type*) [add_right_cancel_semigroup α] [has_one α] (i : α) :
(complex_shape.down α).prev i = some ⟨i+1, rfl⟩ :=
option.choice_eq _
@[simp] lemma next (α : Type*) [add_group α] [has_one α] (i : α) :
(complex_shape.down α).next i = some ⟨i-1, sub_add_cancel i 1⟩ :=
option.choice_eq _
@[simp] lemma next_nat_zero :
(complex_shape.down ℕ).next 0 = none :=
@option.choice_eq_none _ ⟨by rintro ⟨j, ⟨⟩⟩⟩
@[simp] lemma next_nat_succ (i : ℕ) :
(complex_shape.down ℕ).next (i+1) = some ⟨i, rfl⟩ :=
option.choice_eq _
end chain_complex
namespace cochain_complex
@[simp] lemma prev (α : Type*) [add_group α] [has_one α] (i : α) :
(complex_shape.up α).prev i = some ⟨i-1, sub_add_cancel i 1⟩ :=
option.choice_eq _
@[simp] lemma next (α : Type*) [add_right_cancel_semigroup α] [has_one α] (i : α) :
(complex_shape.up α).next i = some ⟨i+1, rfl⟩ :=
option.choice_eq _
@[simp] lemma prev_nat_zero :
(complex_shape.up ℕ).prev 0 = none :=
@option.choice_eq_none _ ⟨by rintro ⟨j, ⟨⟩⟩⟩
@[simp] lemma prev_nat_succ (i : ℕ) :
(complex_shape.up ℕ).prev (i+1) = some ⟨i, rfl⟩ :=
option.choice_eq _
end cochain_complex
namespace homological_complex
variables {V} {c : complex_shape ι} (C : homological_complex V c)
/--
A morphism of homological complexes consists of maps between the chain groups,
commuting with the differentials.
-/
@[ext] structure hom (A B : homological_complex V c) :=
(f : ∀ i, A.X i ⟶ B.X i)
(comm' : ∀ i j, c.rel i j → f i ≫ B.d i j = A.d i j ≫ f j . obviously)
@[simp, reassoc]
lemma hom.comm {A B : homological_complex V c} (f : A.hom B) (i j : ι) :
f.f i ≫ B.d i j = A.d i j ≫ f.f j :=
begin
by_cases hij : c.rel i j,
{ exact f.comm' i j hij },
rw [A.shape i j hij, B.shape i j hij, comp_zero, zero_comp],
end
instance (A B : homological_complex V c) : inhabited (hom A B) :=
⟨{ f := λ i, 0 }⟩
/-- Identity chain map. -/
def id (A : homological_complex V c) : hom A A :=
{ f := λ _, 𝟙 _ }
/-- Composition of chain maps. -/
def comp (A B C : homological_complex V c) (φ : hom A B) (ψ : hom B C) : hom A C :=
{ f := λ i, φ.f i ≫ ψ.f i }
section
local attribute [simp] id comp
instance : category (homological_complex V c) :=
{ hom := hom,
id := id,
comp := comp }
end
@[simp] lemma id_f (C : homological_complex V c) (i : ι) : hom.f (𝟙 C) i = 𝟙 (C.X i) := rfl
@[simp] lemma comp_f {C₁ C₂ C₃ : homological_complex V c} (f : C₁ ⟶ C₂) (g : C₂ ⟶ C₃) (i : ι) :
(f ≫ g).f i = f.f i ≫ g.f i :=
rfl
-- We'll use this later to show that `homological_complex V c` is preadditive when `V` is.
lemma hom_f_injective {C₁ C₂ : homological_complex V c} :
function.injective (λ f : hom C₁ C₂, f.f) :=
by tidy
instance : has_zero_morphisms (homological_complex V c) :=
{ has_zero := λ C D, ⟨{ f := λ i, 0 }⟩ }
@[simp] lemma zero_apply (C D : homological_complex V c) (i : ι) :
(0 : C ⟶ D).f i = 0 := rfl
open_locale zero_object
instance [has_zero_object V] : has_zero_object (homological_complex V c) :=
{ zero :=
{ X := λ i, 0,
d := λ i j, 0 },
unique_from := λ C, ⟨⟨0⟩, λ f, by ext⟩,
unique_to := λ C, ⟨⟨0⟩, λ f, by ext⟩ }
instance [has_zero_object V] : inhabited (homological_complex V c) := ⟨0⟩
lemma congr_hom {C D : homological_complex V c} {f g : C ⟶ D} (w : f = g) (i : ι) : f.f i = g.f i :=
congr_fun (congr_arg hom.f w) i
/--
Picking out the `i`-th object, as a functor.
-/
def eval_at (i : ι) : homological_complex V c ⥤ V :=
{ obj := λ C, C.X i,
map := λ C D f, f.f i }
open_locale classical
noncomputable theory
/--
If `C.d i j` and `C.d i j'` are both allowed, then we must have `j = j'`,
and so the differentials only differ by an `eq_to_hom`.
-/
@[simp] lemma d_comp_eq_to_hom {i j j' : ι} (rij : c.rel i j) (rij' : c.rel i j') :
C.d i j' ≫ eq_to_hom (congr_arg C.X (c.next_eq rij' rij)) = C.d i j :=
begin
have P : ∀ h : j' = j, C.d i j' ≫ eq_to_hom (congr_arg C.X h) = C.d i j,
{ rintro rfl, simp },
apply P,
end
/--
If `C.d i j` and `C.d i' j` are both allowed, then we must have `i = i'`,
and so the differentials only differ by an `eq_to_hom`.
-/
@[simp] lemma eq_to_hom_comp_d {i i' j : ι} (rij : c.rel i j) (rij' : c.rel i' j) :
eq_to_hom (congr_arg C.X (c.prev_eq rij rij')) ≫ C.d i' j = C.d i j :=
begin
have P : ∀ h : i = i', eq_to_hom (congr_arg C.X h) ≫ C.d i' j = C.d i j,
{ rintro rfl, simp },
apply P,
end
lemma kernel_eq_kernel [has_kernels V] {i j j' : ι} (r : c.rel i j) (r' : c.rel i j') :
kernel_subobject (C.d i j) = kernel_subobject (C.d i j') :=
begin
rw ←d_comp_eq_to_hom C r r',
apply kernel_subobject_comp_mono,
end
lemma image_eq_image [has_images V] [has_equalizers V]
{i i' j : ι} (r : c.rel i j) (r' : c.rel i' j) :
image_subobject (C.d i j) = image_subobject (C.d i' j) :=
begin
rw ←eq_to_hom_comp_d C r r',
apply image_subobject_iso_comp,
end
section
variables [has_zero_object V]
open_locale zero_object
/-- Either `C.X i`, if there is some `i` with `c.rel i j`, or the zero object. -/
def X_prev (j : ι) : V :=
match c.prev j with
| none := 0
| (some ⟨i,_⟩) := C.X i
end
/-- If `c.rel i j`, then `C.X_prev j` is isomorphic to `C.X i`. -/
def X_prev_iso {i j : ι} (r : c.rel i j) :
C.X_prev j ≅ C.X i :=
eq_to_iso begin
dsimp [X_prev],
rw c.prev_eq_some r,
refl,
end
/-- If there is no `i` so `c.rel i j`, then `C.X_prev j` is isomorphic to `0`. -/
def X_prev_iso_zero {j : ι} (h : c.prev j = none) :
C.X_prev j ≅ 0 :=
eq_to_iso begin
dsimp [X_prev],
rw h,
refl,
end
/-- Either `C.X j`, if there is some `j` with `c.rel i j`, or the zero object. -/
def X_next (i : ι) : V :=
match c.next i with
| none := 0
| (some ⟨j,_⟩) := C.X j
end
/-- If `c.rel i j`, then `C.X_next i` is isomorphic to `C.X j`. -/
def X_next_iso {i j : ι} (r : c.rel i j) :
C.X_next i ≅ C.X j :=
eq_to_iso begin
dsimp [X_next],
rw c.next_eq_some r,
refl,
end
/-- If there is no `j` so `c.rel i j`, then `C.X_next i` is isomorphic to `0`. -/
def X_next_iso_zero {i : ι} (h : c.next i = none) :
C.X_next i ≅ 0 :=
eq_to_iso begin
dsimp [X_next],
rw h,
refl,
end
/--
The differential mapping into `C.X j`, or zero if there isn't one.
-/
def d_to (j : ι) : C.X_prev j ⟶ C.X j :=
match c.prev j with
| none := (0 : C.X_prev j ⟶ C.X j)
| (some ⟨i, w⟩) := (C.X_prev_iso w).hom ≫ C.d i j
end
/--
The differential mapping out of `C.X i`, or zero if there isn't one.
-/
def d_from (i : ι) : C.X i ⟶ C.X_next i :=
match c.next i with
| none := (0 : C.X i ⟶ C.X_next i)
| (some ⟨j, w⟩) := C.d i j ≫ (C.X_next_iso w).inv
end
lemma d_to_eq {i j : ι} (r : c.rel i j) :
C.d_to j = (C.X_prev_iso r).hom ≫ C.d i j :=
begin
dsimp [d_to, X_prev_iso],
rw c.prev_eq_some r,
refl,
end
@[simp]
lemma d_to_eq_zero {j : ι} (h : c.prev j = none) :
C.d_to j = 0 :=
begin
dsimp [d_to],
rw h, refl,
end
lemma d_from_eq {i j : ι} (r : c.rel i j) :
C.d_from i = C.d i j ≫ (C.X_next_iso r).inv :=
begin
dsimp [d_from, X_next_iso],
rw c.next_eq_some r,
refl,
end
@[simp]
lemma d_from_eq_zero {i : ι} (h : c.next i = none) :
C.d_from i = 0 :=
begin
dsimp [d_from],
rw h, refl,
end
@[simp, reassoc] lemma X_prev_iso_comp_d_to {i j : ι} (r : c.rel i j) :
(C.X_prev_iso r).inv ≫ C.d_to j = C.d i j :=
by simp [C.d_to_eq r]
@[simp, reassoc] lemma X_prev_iso_zero_comp_d_to {j : ι} (h : c.prev j = none) :
(C.X_prev_iso_zero h).inv ≫ C.d_to j = 0 :=
by simp [h]
@[simp, reassoc] lemma d_from_comp_X_next_iso {i j : ι} (r : c.rel i j) :
C.d_from i ≫ (C.X_next_iso r).hom = C.d i j :=
by simp [C.d_from_eq r]
@[simp, reassoc] lemma d_from_comp_X_next_iso_zero {i : ι} (h : c.next i = none) :
C.d_from i ≫ (C.X_next_iso_zero h).hom = 0 :=
by simp [h]
@[simp]
lemma d_to_comp_d_from (j : ι) : C.d_to j ≫ C.d_from j = 0 :=
begin
rcases h₁ : c.next j with _ | ⟨k,w₁⟩,
{ rw [d_from_eq_zero _ h₁], simp },
{ rw [d_from_eq _ w₁],
rcases h₂ : c.prev j with _ | ⟨i,w₂⟩,
{ rw [d_to_eq_zero _ h₂], simp },
{ rw [d_to_eq _ w₂], simp } }
end
lemma kernel_from_eq_kernel [has_kernels V] {i j : ι} (r : c.rel i j) :
kernel_subobject (C.d_from i) = kernel_subobject (C.d i j) :=
begin
rw C.d_from_eq r,
apply kernel_subobject_comp_mono,
end
lemma image_to_eq_image [has_images V] [has_equalizers V]
{i j : ι} (r : c.rel i j) :
image_subobject (C.d_to j) = image_subobject (C.d i j) :=
begin
rw C.d_to_eq r,
apply image_subobject_iso_comp,
end
end
namespace hom
variables {C₁ C₂ C₃ : homological_complex V c}
variables [has_zero_object V]
open_locale zero_object
/-! Lemmas relating chain maps and `d_to`/`d_from`. -/
/-- `f.prev j` is `f.f i` if there is some `r i j`, and zero otherwise. -/
def prev (f : hom C₁ C₂) (j : ι) : C₁.X_prev j ⟶ C₂.X_prev j :=
match c.prev j with
| none := 0
| some ⟨i,w⟩ := (C₁.X_prev_iso w).hom ≫ f.f i ≫ (C₂.X_prev_iso w).inv
end
lemma prev_eq (f : hom C₁ C₂) {i j : ι} (w : c.rel i j) :
f.prev j = (C₁.X_prev_iso w).hom ≫ f.f i ≫ (C₂.X_prev_iso w).inv :=
begin
dsimp [prev],
rw c.prev_eq_some w,
refl,
end
/-- `f.next i` is `f.f j` if there is some `r i j`, and zero otherwise. -/
def next (f : hom C₁ C₂) (i : ι) : C₁.X_next i ⟶ C₂.X_next i :=
match c.next i with
| none := 0
| some ⟨j,w⟩ := (C₁.X_next_iso w).hom ≫ f.f j ≫ (C₂.X_next_iso w).inv
end
lemma next_eq (f : hom C₁ C₂) {i j : ι} (w : c.rel i j) :
f.next i = (C₁.X_next_iso w).hom ≫ f.f j ≫ (C₂.X_next_iso w).inv :=
begin
dsimp [next],
rw c.next_eq_some w,
refl,
end
@[simp, reassoc]
lemma comm_from (f : hom C₁ C₂) (i : ι) :
f.f i ≫ C₂.d_from i = C₁.d_from i ≫ f.next i :=
begin
rcases h : c.next i with _ | ⟨j,w⟩,
{ simp [h] },
{ simp [d_from_eq _ w, next_eq _ w] }
end
@[simp, reassoc]
lemma comm_to (f : hom C₁ C₂) (j : ι) :
f.prev j ≫ C₂.d_to j = C₁.d_to j ≫ f.f j :=
begin
rcases h : c.prev j with _ | ⟨j,w⟩,
{ simp [h] },
{ simp [d_to_eq _ w, prev_eq _ w] }
end
/--
A morphism of chain complexes
induces a morphism of arrows of the differentials out of each object.
-/
def sq_from (f : hom C₁ C₂) (i : ι) : arrow.mk (C₁.d_from i) ⟶ arrow.mk (C₂.d_from i) :=
arrow.hom_mk (f.comm_from i)
@[simp] lemma sq_from_left (f : hom C₁ C₂) (i : ι) : (f.sq_from i).left = f.f i := rfl
@[simp] lemma sq_from_right (f : hom C₁ C₂) (i : ι) : (f.sq_from i).right = f.next i := rfl
@[simp] lemma sq_from_id (C₁ : homological_complex V c) (i : ι) : sq_from (𝟙 C₁) i = 𝟙 _ :=
begin
rcases h : c.next i with _ | ⟨j,w⟩,
{ ext,
{ refl },
{ dsimp, simp only [next, h],
symmetry,
apply zero_of_target_iso_zero,
exact X_next_iso_zero _ h } },
{ ext, refl, dsimp, simp [next, h] }
end
@[simp] lemma sq_from_comp (f : C₁ ⟶ C₂) (g : C₂ ⟶ C₃) (i : ι) :
sq_from (f ≫ g) i = sq_from f i ≫ sq_from g i :=
begin
rcases h : c.next i with _ | ⟨j,w⟩,
{ ext,
{ refl },
{ dsimp, simp only [next, h],
symmetry,
apply zero_of_target_iso_zero,
exact X_next_iso_zero _ h } },
{ ext, refl, dsimp, simp [next, h] }
end
/--
A morphism of chain complexes
induces a morphism of arrows of the differentials into each object.
-/
def sq_to (f : hom C₁ C₂) (j : ι) : arrow.mk (C₁.d_to j) ⟶ arrow.mk (C₂.d_to j) :=
arrow.hom_mk (f.comm_to j)
@[simp] lemma sq_to_left (f : hom C₁ C₂) (j : ι) : (f.sq_to j).left = f.prev j := rfl
@[simp] lemma sq_to_right (f : hom C₁ C₂) (j : ι) : (f.sq_to j).right = f.f j := rfl
end hom
end homological_complex
namespace chain_complex
section of
variables {V} {α : Type*} [add_right_cancel_semigroup α] [has_one α] [decidable_eq α]
/--
Construct an `α`-indexed chain complex from a dependently-typed differential.
-/
def of (X : α → V) (d : Π n, X (n+1) ⟶ X n) (sq : ∀ n, d (n+1) ≫ d n = 0) : chain_complex V α :=
{ X := X,
d := λ i j, if h : i = j + 1 then
eq_to_hom (by subst h) ≫ d j
else
0,
shape' := λ i j w, by rw dif_neg (ne.symm w),
d_comp_d' := λ i j k hij hjk,
begin
dsimp at hij hjk, substs hij hjk,
simp only [category.id_comp, dif_pos rfl, eq_to_hom_refl],
exact sq k,
end }
variables (X : α → V) (d : Π n, X (n+1) ⟶ X n) (sq : ∀ n, d (n+1) ≫ d n = 0)
@[simp] lemma of_X (n : α) : (of X d sq).X n = X n := rfl
@[simp] lemma of_d (j : α) : (of X d sq).d (j+1) j = d j :=
by { dsimp [of], rw [if_pos rfl, category.id_comp] }
lemma of_d_ne {i j : α} (h : i ≠ j + 1) : (of X d sq).d i j = 0 :=
by { dsimp [of], rw [dif_neg h], }
end of
section of_hom
variables {V} {α : Type*} [add_right_cancel_semigroup α] [has_one α] [decidable_eq α]
variables (X : α → V) (d_X : Π n, X (n+1) ⟶ X n) (sq_X : ∀ n, d_X (n+1) ≫ d_X n = 0)
(Y : α → V) (d_Y : Π n, Y (n+1) ⟶ Y n) (sq_Y : ∀ n, d_Y (n+1) ≫ d_Y n = 0)
/--
A constructor for chain maps between `α`-indexed chain complexes built using `chain_complex.of`,
from a dependently typed collection of morphisms.
-/
@[simps] def of_hom (f : Π i : α, X i ⟶ Y i) (comm : ∀ i : α, f (i+1) ≫ d_Y i = d_X i ≫ f i) :
of X d_X sq_X ⟶ of Y d_Y sq_Y :=
{ f := f,
comm' := λ n m,
begin
by_cases h : n = m + 1,
{ subst h,
simpa using comm m, },
{ rw [of_d_ne X _ _ h, of_d_ne Y _ _ h], simp }
end }
end of_hom
section mk
/--
Auxiliary structure for setting up the recursion in `mk`.
This is purely an implementation detail: for some reason just using the dependent 6-tuple directly
results in `mk_aux` taking much longer (well over the `-T100000` limit) to elaborate.
-/
@[nolint has_inhabited_instance]
structure mk_struct :=
(X₀ X₁ X₂ : V)
(d₀ : X₁ ⟶ X₀)
(d₁ : X₂ ⟶ X₁)
(s : d₁ ≫ d₀ = 0)
variables {V}
/-- Flatten to a tuple. -/
def mk_struct.flat (t : mk_struct V) :
Σ' (X₀ X₁ X₂ : V) (d₀ : X₁ ⟶ X₀) (d₁ : X₂ ⟶ X₁), d₁ ≫ d₀ = 0 :=
⟨t.X₀, t.X₁, t.X₂, t.d₀, t.d₁, t.s⟩
variables (X₀ X₁ X₂ : V) (d₀ : X₁ ⟶ X₀) (d₁ : X₂ ⟶ X₁) (s : d₁ ≫ d₀ = 0)
(succ : Π (t : Σ' (X₀ X₁ X₂ : V) (d₀ : X₁ ⟶ X₀) (d₁ : X₂ ⟶ X₁), d₁ ≫ d₀ = 0),
Σ' (X₃ : V) (d₂ : X₃ ⟶ t.2.2.1), d₂ ≫ t.2.2.2.2.1 = 0)
/-- Auxiliary definition for `mk`. -/
def mk_aux :
Π n : ℕ, mk_struct V
| 0 := ⟨X₀, X₁, X₂, d₀, d₁, s⟩
| (n+1) :=
let p := mk_aux n in
⟨p.X₁, p.X₂, (succ p.flat).1, p.d₁, (succ p.flat).2.1, (succ p.flat).2.2⟩
/--
A inductive constructor for `ℕ`-indexed chain complexes.
You provide explicitly the first two differentials,
then a function which takes two differentials and the fact they compose to zero,
and returns the next object, its differential, and the fact it composes appropiately to zero.
See also `mk'`, which only sees the previous differential in the inductive step.
-/
def mk : chain_complex V ℕ :=
of (λ n, (mk_aux X₀ X₁ X₂ d₀ d₁ s succ n).X₀) (λ n, (mk_aux X₀ X₁ X₂ d₀ d₁ s succ n).d₀)
(λ n, (mk_aux X₀ X₁ X₂ d₀ d₁ s succ n).s)
@[simp] lemma mk_X_0 : (mk X₀ X₁ X₂ d₀ d₁ s succ).X 0 = X₀ := rfl
@[simp] lemma mk_X_1 : (mk X₀ X₁ X₂ d₀ d₁ s succ).X 1 = X₁ := rfl
@[simp] lemma mk_X_2 : (mk X₀ X₁ X₂ d₀ d₁ s succ).X 2 = X₂ := rfl
@[simp] lemma mk_d_1_0 : (mk X₀ X₁ X₂ d₀ d₁ s succ).d 1 0 = d₀ :=
by { change ite (1 = 0 + 1) (𝟙 X₁ ≫ d₀) 0 = d₀, rw [if_pos rfl, category.id_comp] }
@[simp] lemma mk_d_2_0 : (mk X₀ X₁ X₂ d₀ d₁ s succ).d 2 1 = d₁ :=
by { change ite (2 = 1 + 1) (𝟙 X₂ ≫ d₁) 0 = d₁, rw [if_pos rfl, category.id_comp] }
-- TODO simp lemmas for the inductive steps? It's not entirely clear that they are needed.
/--
A simpler inductive constructor for `ℕ`-indexed chain complexes.
You provide explicitly the first differential,
then a function which takes a differential,
and returns the next object, its differential, and the fact it composes appropriately to zero.
-/
def mk' (X₀ X₁ : V) (d : X₁ ⟶ X₀)
(succ' : Π (t : Σ (X₀ X₁ : V), X₁ ⟶ X₀), Σ' (X₂ : V) (d : X₂ ⟶ t.2.1), d ≫ t.2.2 = 0) :
chain_complex V ℕ :=
mk X₀ X₁ (succ' ⟨X₀, X₁, d⟩).1 d (succ' ⟨X₀, X₁, d⟩).2.1 (succ' ⟨X₀, X₁, d⟩).2.2
(λ t, succ' ⟨t.2.1, t.2.2.1, t.2.2.2.2.1⟩)
variables (succ' : Π (t : Σ (X₀ X₁ : V), X₁ ⟶ X₀), Σ' (X₂ : V) (d : X₂ ⟶ t.2.1), d ≫ t.2.2 = 0)
@[simp] lemma mk'_X_0 : (mk' X₀ X₁ d₀ succ').X 0 = X₀ := rfl
@[simp] lemma mk'_X_1 : (mk' X₀ X₁ d₀ succ').X 1 = X₁ := rfl
@[simp] lemma mk'_d_1_0 : (mk' X₀ X₁ d₀ succ').d 1 0 = d₀ :=
by { change ite (1 = 0 + 1) (𝟙 X₁ ≫ d₀) 0 = d₀, rw [if_pos rfl, category.id_comp] }
-- TODO simp lemmas for the inductive steps? It's not entirely clear that they are needed.
end mk
section mk_hom
variables {V} (P Q : chain_complex V ℕ)
(zero : P.X 0 ⟶ Q.X 0)
(one : P.X 1 ⟶ Q.X 1)
(one_zero_comm : one ≫ Q.d 1 0 = P.d 1 0 ≫ zero)
(succ : ∀ (n : ℕ)
(p : Σ' (f : P.X n ⟶ Q.X n) (f' : P.X (n+1) ⟶ Q.X (n+1)), f' ≫ Q.d (n+1) n = P.d (n+1) n ≫ f),
Σ' f'' : P.X (n+2) ⟶ Q.X (n+2), f'' ≫ Q.d (n+2) (n+1) = P.d (n+2) (n+1) ≫ p.2.1)
/--
An auxiliary construction for `mk_hom`.
Here we build by induction a family of commutative squares,
but don't require at the type level that these successive commutative squares actually agree.
They do in fact agree, and we then capture that at the type level (i.e. by constructing a chain map)
in `mk_hom`.
-/
def mk_hom_aux :
Π n, Σ' (f : P.X n ⟶ Q.X n) (f' : P.X (n+1) ⟶ Q.X (n+1)), f' ≫ Q.d (n+1) n = P.d (n+1) n ≫ f
| 0 := ⟨zero, one, one_zero_comm⟩
| (n+1) := ⟨(mk_hom_aux n).2.1,
(succ n (mk_hom_aux n)).1, (succ n (mk_hom_aux n)).2⟩
/--
A constructor for chain maps between `ℕ`-indexed chain complexes,
working by induction on commutative squares.
You need to provide the components of the chain map in degrees 0 and 1,
show that these form a commutative square,
and then give a construction of each component,
and the fact that it forms a commutative square with the previous component,
using as an inductive hypothesis the data (and commutativity) of the previous two components.
-/
def mk_hom : P ⟶ Q :=
{ f := λ n, (mk_hom_aux P Q zero one one_zero_comm succ n).1,
comm' := λ n m,
begin
rintro (rfl : m + 1 = n),
exact (mk_hom_aux P Q zero one one_zero_comm succ m).2.2,
end }
@[simp] lemma mk_hom_f_0 : (mk_hom P Q zero one one_zero_comm succ).f 0 = zero := rfl
@[simp] lemma mk_hom_f_1 : (mk_hom P Q zero one one_zero_comm succ).f 1 = one := rfl
@[simp] lemma mk_hom_f_succ_succ (n : ℕ) :
(mk_hom P Q zero one one_zero_comm succ).f (n+2) =
(succ n ⟨(mk_hom P Q zero one one_zero_comm succ).f n,
(mk_hom P Q zero one one_zero_comm succ).f (n+1),
(mk_hom P Q zero one one_zero_comm succ).comm (n+1) n⟩).1 :=
begin
dsimp [mk_hom, mk_hom_aux],
induction n; congr,
end
end mk_hom
end chain_complex
namespace cochain_complex
section of
variables {V} {α : Type*} [add_right_cancel_semigroup α] [has_one α] [decidable_eq α]
/--
Construct an `α`-indexed cochain complex from a dependently-typed differential.
-/
def of (X : α → V) (d : Π n, X n ⟶ X (n+1)) (sq : ∀ n, d n ≫ d (n+1) = 0) : cochain_complex V α :=
{ X := X,
d := λ i j, if h : i + 1 = j then
d _ ≫ eq_to_hom (by subst h)
else
0,
shape' := λ i j w, by {rw dif_neg, exact w},
d_comp_d' := λ i j k,
begin
split_ifs with h h' h',
{ substs h h',
simp [sq] },
all_goals { simp },
end }
variables (X : α → V) (d : Π n, X n ⟶ X (n+1)) (sq : ∀ n, d n ≫ d (n+1) = 0)
@[simp] lemma of_X (n : α) : (of X d sq).X n = X n := rfl
@[simp] lemma of_d (j : α) : (of X d sq).d j (j+1) = d j :=
by { dsimp [of], rw [if_pos rfl, category.comp_id] }
lemma of_d_ne {i j : α} (h : i + 1 ≠ j) : (of X d sq).d i j = 0 :=
by { dsimp [of], rw [dif_neg h] }
end of
section of_hom
variables {V} {α : Type*} [add_right_cancel_semigroup α] [has_one α] [decidable_eq α]
variables (X : α → V) (d_X : Π n, X n ⟶ X (n+1)) (sq_X : ∀ n, d_X n ≫ d_X (n+1) = 0)
(Y : α → V) (d_Y : Π n, Y n ⟶ Y (n+1)) (sq_Y : ∀ n, d_Y n ≫ d_Y (n+1) = 0)
/--
A constructor for chain maps between `α`-indexed cochain complexes built using `cochain_complex.of`,
from a dependently typed collection of morphisms.
-/
@[simps] def of_hom (f : Π i : α, X i ⟶ Y i) (comm : ∀ i : α, f i ≫ d_Y i = d_X i ≫ f (i+1)) :
of X d_X sq_X ⟶ of Y d_Y sq_Y :=
{ f := f,
comm' := λ n m,
begin
by_cases h : n + 1 = m,
{ subst h,
simpa using comm n },
{ rw [of_d_ne X _ _ h, of_d_ne Y _ _ h], simp }
end }
end of_hom
section mk
/--
Auxiliary structure for setting up the recursion in `mk`.
This is purely an implementation detail: for some reason just using the dependent 6-tuple directly
results in `mk_aux` taking much longer (well over the `-T100000` limit) to elaborate.
-/
@[nolint has_inhabited_instance]
structure mk_struct :=
(X₀ X₁ X₂ : V)
(d₀ : X₀ ⟶ X₁)
(d₁ : X₁ ⟶ X₂)
(s : d₀ ≫ d₁ = 0)
variables {V}
/-- Flatten to a tuple. -/
def mk_struct.flat (t : mk_struct V) :
Σ' (X₀ X₁ X₂ : V) (d₀ : X₀ ⟶ X₁) (d₁ : X₁ ⟶ X₂), d₀ ≫ d₁ = 0 :=
⟨t.X₀, t.X₁, t.X₂, t.d₀, t.d₁, t.s⟩
variables (X₀ X₁ X₂ : V) (d₀ : X₀ ⟶ X₁) (d₁ : X₁ ⟶ X₂) (s : d₀ ≫ d₁ = 0)
(succ : Π (t : Σ' (X₀ X₁ X₂ : V) (d₀ : X₀ ⟶ X₁) (d₁ : X₁ ⟶ X₂), d₀ ≫ d₁ = 0),
Σ' (X₃ : V) (d₂ : t.2.2.1 ⟶ X₃), t.2.2.2.2.1 ≫ d₂ = 0)
/-- Auxiliary definition for `mk`. -/
def mk_aux :
Π n : ℕ, mk_struct V
| 0 := ⟨X₀, X₁, X₂, d₀, d₁, s⟩
| (n+1) :=
let p := mk_aux n in
⟨p.X₁, p.X₂, (succ p.flat).1, p.d₁, (succ p.flat).2.1, (succ p.flat).2.2⟩
/--
A inductive constructor for `ℕ`-indexed cochain complexes.
You provide explicitly the first two differentials,
then a function which takes two differentials and the fact they compose to zero,
and returns the next object, its differential, and the fact it composes appropiately to zero.
See also `mk'`, which only sees the previous differential in the inductive step.
-/
def mk : cochain_complex V ℕ :=
of (λ n, (mk_aux X₀ X₁ X₂ d₀ d₁ s succ n).X₀) (λ n, (mk_aux X₀ X₁ X₂ d₀ d₁ s succ n).d₀)
(λ n, (mk_aux X₀ X₁ X₂ d₀ d₁ s succ n).s)
@[simp] lemma mk_X_0 : (mk X₀ X₁ X₂ d₀ d₁ s succ).X 0 = X₀ := rfl
@[simp] lemma mk_X_1 : (mk X₀ X₁ X₂ d₀ d₁ s succ).X 1 = X₁ := rfl
@[simp] lemma mk_X_2 : (mk X₀ X₁ X₂ d₀ d₁ s succ).X 2 = X₂ := rfl
@[simp] lemma mk_d_1_0 : (mk X₀ X₁ X₂ d₀ d₁ s succ).d 0 1 = d₀ :=
by { change ite (1 = 0 + 1) (d₀ ≫ 𝟙 X₁) 0 = d₀, rw [if_pos rfl, category.comp_id] }
@[simp] lemma mk_d_2_0 : (mk X₀ X₁ X₂ d₀ d₁ s succ).d 1 2 = d₁ :=
by { change ite (2 = 1 + 1) (d₁ ≫ 𝟙 X₂) 0 = d₁, rw [if_pos rfl, category.comp_id] }
-- TODO simp lemmas for the inductive steps? It's not entirely clear that they are needed.
/--
A simpler inductive constructor for `ℕ`-indexed cochain complexes.
You provide explicitly the first differential,
then a function which takes a differential,
and returns the next object, its differential, and the fact it composes appropriately to zero.
-/
def mk' (X₀ X₁ : V) (d : X₀ ⟶ X₁)
(succ' : Π (t : Σ (X₀ X₁ : V), X₀ ⟶ X₁), Σ' (X₂ : V) (d : t.2.1 ⟶ X₂), t.2.2 ≫ d = 0) :
cochain_complex V ℕ :=
mk X₀ X₁ (succ' ⟨X₀, X₁, d⟩).1 d (succ' ⟨X₀, X₁, d⟩).2.1 (succ' ⟨X₀, X₁, d⟩).2.2
(λ t, succ' ⟨t.2.1, t.2.2.1, t.2.2.2.2.1⟩)
variables (succ' : Π (t : Σ (X₀ X₁ : V), X₀ ⟶ X₁), Σ' (X₂ : V) (d : t.2.1 ⟶ X₂), t.2.2 ≫ d = 0)
@[simp] lemma mk'_X_0 : (mk' X₀ X₁ d₀ succ').X 0 = X₀ := rfl
@[simp] lemma mk'_X_1 : (mk' X₀ X₁ d₀ succ').X 1 = X₁ := rfl
@[simp] lemma mk'_d_1_0 : (mk' X₀ X₁ d₀ succ').d 0 1 = d₀ :=
by { change ite (1 = 0 + 1) (d₀ ≫ 𝟙 X₁) 0 = d₀, rw [if_pos rfl, category.comp_id] }
-- TODO simp lemmas for the inductive steps? It's not entirely clear that they are needed.
end mk
section mk_hom
variables {V} (P Q : cochain_complex V ℕ)
(zero : P.X 0 ⟶ Q.X 0)
(one : P.X 1 ⟶ Q.X 1)
(one_zero_comm : zero ≫ Q.d 0 1 = P.d 0 1 ≫ one)
(succ : ∀ (n : ℕ)
(p : Σ' (f : P.X n ⟶ Q.X n) (f' : P.X (n+1) ⟶ Q.X (n+1)), f ≫ Q.d n (n+1) = P.d n (n+1) ≫ f'),
Σ' f'' : P.X (n+2) ⟶ Q.X (n+2), p.2.1 ≫ Q.d (n+1) (n+2) = P.d (n+1) (n+2) ≫ f'')
/--
An auxiliary construction for `mk_hom`.
Here we build by induction a family of commutative squares,
but don't require at the type level that these successive commutative squares actually agree.
They do in fact agree, and we then capture that at the type level (i.e. by constructing a chain map)
in `mk_hom`.
-/
def mk_hom_aux :
Π n, Σ' (f : P.X n ⟶ Q.X n) (f' : P.X (n+1) ⟶ Q.X (n+1)), f ≫ Q.d n (n+1) = P.d n (n+1) ≫ f'
| 0 := ⟨zero, one, one_zero_comm⟩
| (n+1) := ⟨(mk_hom_aux n).2.1,
(succ n (mk_hom_aux n)).1, (succ n (mk_hom_aux n)).2⟩
/--
A constructor for chain maps between `ℕ`-indexed cochain complexes,
working by induction on commutative squares.
You need to provide the components of the chain map in degrees 0 and 1,
show that these form a commutative square,
and then give a construction of each component,
and the fact that it forms a commutative square with the previous component,
using as an inductive hypothesis the data (and commutativity) of the previous two components.
-/
def mk_hom : P ⟶ Q :=
{ f := λ n, (mk_hom_aux P Q zero one one_zero_comm succ n).1,
comm' := λ n m,
begin
rintro (rfl : n + 1 = m),
exact (mk_hom_aux P Q zero one one_zero_comm succ n).2.2,
end }
@[simp] lemma mk_hom_f_0 : (mk_hom P Q zero one one_zero_comm succ).f 0 = zero := rfl
@[simp] lemma mk_hom_f_1 : (mk_hom P Q zero one one_zero_comm succ).f 1 = one := rfl
@[simp] lemma mk_hom_f_succ_succ (n : ℕ) :
(mk_hom P Q zero one one_zero_comm succ).f (n+2) =
(succ n ⟨(mk_hom P Q zero one one_zero_comm succ).f n,
(mk_hom P Q zero one one_zero_comm succ).f (n+1),
(mk_hom P Q zero one one_zero_comm succ).comm n (n+1)⟩).1 :=
begin
dsimp [mk_hom, mk_hom_aux],
induction n; congr,
end
end mk_hom
end cochain_complex
|
43a7103c432e1c9cfc6bcc74d3e1e3da1e88531a | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/data/rat/order_auto.lean | e6dc440afc40717ea3864aec57e8bd3b94fa56f2 | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,072 | lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.rat.basic
import Mathlib.PostPort
namespace Mathlib
/-!
# Order for Rational Numbers
## Summary
We define the order on `ℚ`, prove that `ℚ` is a discrete, linearly ordered field, and define
functions such as `abs` and `sqrt` that depend on this order.
## Notations
- `/.` is infix notation for `rat.mk`.
## Tags
rat, rationals, field, ℚ, numerator, denominator, num, denom, order, ordering, sqrt, abs
-/
namespace rat
protected def nonneg : ℚ → Prop := sorry
@[simp] theorem mk_nonneg (a : ℤ) {b : ℤ} (h : 0 < b) : rat.nonneg (mk a b) ↔ 0 ≤ a := sorry
protected theorem nonneg_add {a : ℚ} {b : ℚ} : rat.nonneg a → rat.nonneg b → rat.nonneg (a + b) :=
sorry
protected theorem nonneg_mul {a : ℚ} {b : ℚ} : rat.nonneg a → rat.nonneg b → rat.nonneg (a * b) :=
sorry
protected theorem nonneg_antisymm {a : ℚ} : rat.nonneg a → rat.nonneg (-a) → a = 0 := sorry
protected theorem nonneg_total (a : ℚ) : rat.nonneg a ∨ rat.nonneg (-a) :=
cases_on a
fun (n : ℤ) (a_denom : ℕ) (a_pos : 0 < a_denom) (a_cop : nat.coprime (int.nat_abs n) a_denom) =>
or.imp_right neg_nonneg_of_nonpos (le_total 0 n)
protected instance decidable_nonneg (a : ℚ) : Decidable (rat.nonneg a) :=
cases_on a
fun (a_num : ℤ) (a_denom : ℕ) (a_pos : 0 < a_denom)
(a_cop : nat.coprime (int.nat_abs a_num) a_denom) => eq.mpr sorry (int.decidable_le 0 a_num)
protected def le (a : ℚ) (b : ℚ) := rat.nonneg (b - a)
protected instance has_le : HasLessEq ℚ := { LessEq := rat.le }
protected instance decidable_le : DecidableRel LessEq := sorry
protected theorem le_def {a : ℤ} {b : ℤ} {c : ℤ} {d : ℤ} (b0 : 0 < b) (d0 : 0 < d) :
mk a b ≤ mk c d ↔ a * d ≤ c * b :=
sorry
protected theorem le_refl (a : ℚ) : a ≤ a :=
(fun (this : rat.nonneg (a - a)) => this)
(eq.mpr (id (Eq._oldrec (Eq.refl (rat.nonneg (a - a))) (sub_self a))) (le_refl 0))
protected theorem le_total (a : ℚ) (b : ℚ) : a ≤ b ∨ b ≤ a :=
eq.mp (Eq._oldrec (Eq.refl (rat.nonneg (b - a) ∨ rat.nonneg (-(b - a)))) (neg_sub b a))
(rat.nonneg_total (b - a))
protected theorem le_antisymm {a : ℚ} {b : ℚ} (hab : a ≤ b) (hba : b ≤ a) : a = b := sorry
protected theorem le_trans {a : ℚ} {b : ℚ} {c : ℚ} (hab : a ≤ b) (hbc : b ≤ c) : a ≤ c := sorry
protected instance linear_order : linear_order ℚ :=
linear_order.mk rat.le (partial_order.lt._default rat.le) rat.le_refl rat.le_trans rat.le_antisymm
rat.le_total (fun (a b : ℚ) => rat.decidable_nonneg (b - a))
(fun (a b : ℚ) => rat.decidable_eq a b) Mathlib.decidable_lt_of_decidable_le
/- Extra instances to short-circuit type class resolution -/
protected instance has_lt : HasLess ℚ := preorder.to_has_lt ℚ
protected instance distrib_lattice : distrib_lattice ℚ := Mathlib.distrib_lattice_of_linear_order
protected instance lattice : lattice ℚ := Mathlib.lattice_of_linear_order
protected instance semilattice_inf : semilattice_inf ℚ := lattice.to_semilattice_inf ℚ
protected instance semilattice_sup : semilattice_sup ℚ := lattice.to_semilattice_sup ℚ
protected instance has_inf : has_inf ℚ := semilattice_inf.to_has_inf ℚ
protected instance has_sup : has_sup ℚ := semilattice_sup.to_has_sup ℚ
protected instance partial_order : partial_order ℚ := semilattice_inf.to_partial_order ℚ
protected instance preorder : preorder ℚ := directed_order.to_preorder
protected theorem le_def' {p : ℚ} {q : ℚ} : p ≤ q ↔ num p * ↑(denom q) ≤ num q * ↑(denom p) := sorry
protected theorem lt_def {p : ℚ} {q : ℚ} : p < q ↔ num p * ↑(denom q) < num q * ↑(denom p) := sorry
theorem nonneg_iff_zero_le {a : ℚ} : rat.nonneg a ↔ 0 ≤ a := sorry
theorem num_nonneg_iff_zero_le {a : ℚ} : 0 ≤ num a ↔ 0 ≤ a :=
cases_on a
fun (a_num : ℤ) (a_denom : ℕ) (a_pos : 0 < a_denom)
(a_cop : nat.coprime (int.nat_abs a_num) a_denom) =>
idRhs (rat.nonneg (mk' a_num a_denom a_pos a_cop) ↔ 0 ≤ mk' a_num a_denom a_pos a_cop)
nonneg_iff_zero_le
protected theorem add_le_add_left {a : ℚ} {b : ℚ} {c : ℚ} : c + a ≤ c + b ↔ a ≤ b := sorry
protected theorem mul_nonneg {a : ℚ} {b : ℚ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b :=
eq.mpr (id (Eq._oldrec (Eq.refl (0 ≤ a * b)) (Eq.symm (propext nonneg_iff_zero_le))))
(rat.nonneg_mul (eq.mp (Eq._oldrec (Eq.refl (0 ≤ a)) (Eq.symm (propext nonneg_iff_zero_le))) ha)
(eq.mp (Eq._oldrec (Eq.refl (0 ≤ b)) (Eq.symm (propext nonneg_iff_zero_le))) hb))
protected instance linear_ordered_field : linear_ordered_field ℚ :=
linear_ordered_field.mk field.add field.add_assoc field.zero field.zero_add field.add_zero
field.neg field.sub field.add_left_neg field.add_comm field.mul field.mul_assoc field.one
field.one_mul field.mul_one field.left_distrib field.right_distrib linear_order.le
linear_order.lt linear_order.le_refl linear_order.le_trans linear_order.le_antisymm sorry sorry
sorry linear_order.le_total linear_order.decidable_le linear_order.decidable_eq
linear_order.decidable_lt field.exists_pair_ne field.mul_comm field.inv field.mul_inv_cancel
field.inv_zero
/- Extra instances to short-circuit type class resolution -/
protected instance linear_ordered_comm_ring : linear_ordered_comm_ring ℚ :=
linear_ordered_field.to_linear_ordered_comm_ring ℚ
protected instance linear_ordered_ring : linear_ordered_ring ℚ :=
linear_ordered_comm_ring.to_linear_ordered_ring ℚ
protected instance ordered_ring : ordered_ring ℚ := linear_ordered_ring.to_ordered_ring ℚ
protected instance linear_ordered_semiring : linear_ordered_semiring ℚ :=
linear_ordered_comm_ring.to_linear_ordered_semiring
protected instance ordered_semiring : ordered_semiring ℚ := ordered_ring.to_ordered_semiring
protected instance linear_ordered_add_comm_group : linear_ordered_add_comm_group ℚ :=
linear_ordered_ring.to_linear_ordered_add_comm_group
protected instance ordered_add_comm_group : ordered_add_comm_group ℚ :=
ordered_ring.to_ordered_add_comm_group ℚ
protected instance ordered_cancel_add_comm_monoid : ordered_cancel_add_comm_monoid ℚ :=
ordered_semiring.to_ordered_cancel_add_comm_monoid ℚ
protected instance ordered_add_comm_monoid : ordered_add_comm_monoid ℚ :=
ordered_cancel_add_comm_monoid.to_ordered_add_comm_monoid
theorem num_pos_iff_pos {a : ℚ} : 0 < num a ↔ 0 < a := sorry
theorem div_lt_div_iff_mul_lt_mul {a : ℤ} {b : ℤ} {c : ℤ} {d : ℤ} (b_pos : 0 < b) (d_pos : 0 < d) :
↑a / ↑b < ↑c / ↑d ↔ a * d < c * b :=
sorry
theorem lt_one_iff_num_lt_denom {q : ℚ} : q < 1 ↔ num q < ↑(denom q) := sorry
theorem abs_def (q : ℚ) : abs q = mk ↑(int.nat_abs (num q)) ↑(denom q) := sorry
end Mathlib |
ba694cd6485d9db437e306bd1a385aa4c62708e3 | 5d166a16ae129621cb54ca9dde86c275d7d2b483 | /tests/lean/run/dsimp_test.lean | fd8d3c5571666341d4407426038fbf6aac978e13 | [
"Apache-2.0"
] | permissive | jcarlson23/lean | b00098763291397e0ac76b37a2dd96bc013bd247 | 8de88701247f54d325edd46c0eed57aeacb64baf | refs/heads/master | 1,611,571,813,719 | 1,497,020,963,000 | 1,497,021,515,000 | 93,882,536 | 1 | 0 | null | 1,497,029,896,000 | 1,497,029,896,000 | null | UTF-8 | Lean | false | false | 1,414 | lean | def f : nat → nat
| 0 := 10
| (n+1) := 20 + n
open list tactic
local attribute [-simp] map head
example (a b c : nat) : head (map f [1, 2, 3]) = 20 :=
begin
dsimp [map],
guard_target head [f 1, f 2, f 3] = 20,
dsimp [f],
guard_target head [20 + 0, 20 + 1, 20 + 2] = 20,
dsimp [head],
guard_target 20 + 0 = 20,
reflexivity
end
example (a b c : nat) : head (map f [1, 2, 3]) = 20 :=
begin
dsimp [map, f, head],
guard_target 20 + 0 = 20,
reflexivity
end
@[simp] lemma succ_zero_eq_one : nat.succ 0 = 1 :=
rfl
def g : nat × nat → nat
| (a, b) := a + b
lemma gax (x y) : g (x, y) = x + y :=
rfl
attribute [simp] gax
example (a b c : nat) : g (f 1, f 2) = 41 :=
begin
dsimp,
guard_target f 1 + f 2 = 41,
dsimp [f],
reflexivity
end
example (a b c : nat) : g (f 1, f 2) = 41 :=
begin
dsimp [f],
guard_target 20 + 0 + (20 + 1) = 41,
reflexivity
end
example (a b c : nat) : g (f 1, f 2) = 41 :=
begin
dsimp [f] without gax,
guard_target g (20 + 0, 20 + 1) = 41,
dsimp [g],
guard_target 20 + 0 + (20 + 1) = 41,
reflexivity
end
local attribute [-simp] gax
example (a b c : nat) : g (f 1, f 2) = 41 :=
begin
dsimp [f],
guard_target g (20 + 0, 20 + 1) = 41,
dsimp [gax],
guard_target 20 + 0 + (20 + 1) = 41,
reflexivity
end
example (a b c : nat) : g (f 1, f 2) = 41 :=
begin
dsimp [f, gax],
guard_target 20 + 0 + (20 + 1) = 41,
reflexivity
end
|
c1d00d27ec21ac058c1181efafb519405f495864 | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/category_theory/preadditive/default.lean | e15f25d832c62986b5d12d4c38932a1508b2663c | [
"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 | 7,845 | lean | /-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import algebra.group.hom
import category_theory.limits.shapes.kernels
import algebra.big_operators.basic
/-!
# Preadditive categories
A preadditive category is a category in which `X ⟶ Y` is an abelian group in such a way that
composition of morphisms is linear in both variables.
This file contains a definition of preadditive category that directly encodes the definition given
above. The definition could also be phrased as follows: A preadditive category is a category
enriched over the category of Abelian groups. Once the general framework to state this in Lean is
available, the contents of this file should become obsolete.
## Main results
* Definition of preadditive categories and basic properties
* In a preadditive category, `f : Q ⟶ R` is mono if and only if `g ≫ f = 0 → g = 0` for all
composable `g`.
* A preadditive category with kernels has equalizers.
## Implementation notes
The simp normal form for negation and composition is to push negations as far as possible to
the outside. For example, `f ≫ (-g)` and `(-f) ≫ g` both become `-(f ≫ g)`, and `(-f) ≫ (-g)`
is simplified to `f ≫ g`.
## References
* [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2]
## Tags
additive, preadditive, Hom group, Ab-category, Ab-enriched
-/
universes v u
open category_theory.limits
open add_monoid_hom
namespace category_theory
variables (C : Type u) [category.{v} C]
/-- A category is called preadditive if `P ⟶ Q` is an abelian group such that composition is
linear in both variables. -/
class preadditive :=
(hom_group : Π P Q : C, add_comm_group (P ⟶ Q) . tactic.apply_instance)
(add_comp' : ∀ (P Q R : C) (f f' : P ⟶ Q) (g : Q ⟶ R),
(f + f') ≫ g = f ≫ g + f' ≫ g . obviously)
(comp_add' : ∀ (P Q R : C) (f : P ⟶ Q) (g g' : Q ⟶ R),
f ≫ (g + g') = f ≫ g + f ≫ g' . obviously)
attribute [instance] preadditive.hom_group
restate_axiom preadditive.add_comp'
restate_axiom preadditive.comp_add'
attribute [simp,reassoc] preadditive.add_comp
attribute [reassoc] preadditive.comp_add -- (the linter doesn't like `simp` on this lemma)
attribute [simp] preadditive.comp_add
end category_theory
open category_theory
namespace category_theory.preadditive
section preadditive
variables {C : Type u} [category.{v} C] [preadditive C]
/-- Composition by a fixed left argument as a group homomorphism -/
def left_comp {P Q : C} (R : C) (f : P ⟶ Q) : (Q ⟶ R) →+ (P ⟶ R) :=
mk' (λ g, f ≫ g) $ λ g g', by simp
/-- Composition by a fixed right argument as a group homomorphism -/
def right_comp (P : C) {Q R : C} (g : Q ⟶ R) : (P ⟶ Q) →+ (P ⟶ R) :=
mk' (λ f, f ≫ g) $ λ f f', by simp
@[simp, reassoc] lemma sub_comp {P Q R : C} (f f' : P ⟶ Q) (g : Q ⟶ R) :
(f - f') ≫ g = f ≫ g - f' ≫ g :=
map_sub (right_comp P g) f f'
-- The redundant simp lemma linter says that simp can prove the reassoc version of this lemma.
@[reassoc, simp] lemma comp_sub {P Q R : C} (f : P ⟶ Q) (g g' : Q ⟶ R) :
f ≫ (g - g') = f ≫ g - f ≫ g' :=
map_sub (left_comp R f) g g'
@[simp, reassoc] lemma neg_comp {P Q R : C} (f : P ⟶ Q) (g : Q ⟶ R) : (-f) ≫ g = -(f ≫ g) :=
map_neg (right_comp _ _) _
/- The redundant simp lemma linter says that simp can prove the reassoc version of this lemma. -/
@[reassoc, simp] lemma comp_neg {P Q R : C} (f : P ⟶ Q) (g : Q ⟶ R) : f ≫ (-g) = -(f ≫ g) :=
map_neg (left_comp _ _) _
@[reassoc] lemma neg_comp_neg {P Q R : C} (f : P ⟶ Q) (g : Q ⟶ R) : (-f) ≫ (-g) = f ≫ g :=
by simp
section big_operators
open_locale big_operators
@[reassoc] lemma comp_sum {P Q R : C} {J : Type*} {s : finset J} (f : P ⟶ Q) (g : J → (Q ⟶ R)) :
f ≫ ∑ j in s, g j = ∑ j in s, f ≫ g j :=
begin
change left_comp R f _ = _,
rw [add_monoid_hom.map_sum],
refl,
end
@[reassoc] lemma sum_comp {P Q R : C} {J : Type*} {s : finset J} (f : J → (P ⟶ Q)) (g : Q ⟶ R) :
(∑ j in s, f j) ≫ g = ∑ j in s, f j ≫ g :=
begin
change right_comp P g _ = _,
rw [add_monoid_hom.map_sum],
refl,
end
end big_operators
instance {P Q : C} {f : P ⟶ Q} [epi f] : epi (-f) :=
⟨λ R g g' H, by rwa [neg_comp, neg_comp, ←comp_neg, ←comp_neg, cancel_epi, neg_inj] at H⟩
instance {P Q : C} {f : P ⟶ Q} [mono f] : mono (-f) :=
⟨λ R g g' H, by rwa [comp_neg, comp_neg, ←neg_comp, ←neg_comp, cancel_mono, neg_inj] at H⟩
@[priority 100]
instance preadditive_has_zero_morphisms : has_zero_morphisms C :=
{ has_zero := infer_instance,
comp_zero' := λ P Q f R, map_zero $ left_comp R f,
zero_comp' := λ P Q R f, map_zero $ right_comp P f }
lemma mono_of_cancel_zero {Q R : C} (f : Q ⟶ R) (h : ∀ {P : C} (g : P ⟶ Q), g ≫ f = 0 → g = 0) :
mono f :=
⟨λ P g g' hg, sub_eq_zero.1 $ h _ $ (map_sub (right_comp P f) g g').trans $ sub_eq_zero.2 hg⟩
lemma mono_iff_cancel_zero {Q R : C} (f : Q ⟶ R) :
mono f ↔ ∀ (P : C) (g : P ⟶ Q), g ≫ f = 0 → g = 0 :=
⟨λ m P g, by exactI zero_of_comp_mono _, mono_of_cancel_zero f⟩
lemma mono_of_kernel_zero {X Y : C} {f : X ⟶ Y} [has_limit (parallel_pair f 0)]
(w : kernel.ι f = 0) : mono f :=
mono_of_cancel_zero f (λ P g h, by rw [←kernel.lift_ι f g h, w, comp_zero])
lemma epi_of_cancel_zero {P Q : C} (f : P ⟶ Q) (h : ∀ {R : C} (g : Q ⟶ R), f ≫ g = 0 → g = 0) :
epi f :=
⟨λ R g g' hg, sub_eq_zero.1 $ h _ $ (map_sub (left_comp R f) g g').trans $ sub_eq_zero.2 hg⟩
lemma epi_iff_cancel_zero {P Q : C} (f : P ⟶ Q) :
epi f ↔ ∀ (R : C) (g : Q ⟶ R), f ≫ g = 0 → g = 0 :=
⟨λ e R g, by exactI zero_of_epi_comp _, epi_of_cancel_zero f⟩
lemma epi_of_cokernel_zero {X Y : C} (f : X ⟶ Y) [has_colimit (parallel_pair f 0 )]
(w : cokernel.π f = 0) : epi f :=
epi_of_cancel_zero f (λ P g h, by rw [←cokernel.π_desc f g h, w, zero_comp])
end preadditive
section equalizers
variables {C : Type u} [category.{v} C] [preadditive C]
section
variables {X Y : C} (f : X ⟶ Y) (g : X ⟶ Y)
/-- A kernel of `f - g` is an equalizer of `f` and `g`. -/
lemma has_limit_parallel_pair [has_kernel (f - g)] :
has_limit (parallel_pair f g) :=
has_limit.mk { cone := fork.of_ι (kernel.ι (f - g)) (sub_eq_zero.1 $
by { rw ←comp_sub, exact kernel.condition _ }),
is_limit := fork.is_limit.mk _
(λ s, kernel.lift (f - g) (fork.ι s) $
by { rw comp_sub, apply sub_eq_zero.2, exact fork.condition _ })
(λ s, by simp)
(λ s m h, by { ext, simpa using h walking_parallel_pair.zero }) }
end
section
/-- If a preadditive category has all kernels, then it also has all equalizers. -/
lemma has_equalizers_of_has_kernels [has_kernels C] : has_equalizers C :=
@has_equalizers_of_has_limit_parallel_pair _ _ (λ _ _ f g, has_limit_parallel_pair f g)
end
section
variables {X Y : C} (f : X ⟶ Y) (g : X ⟶ Y)
/-- A cokernel of `f - g` is a coequalizer of `f` and `g`. -/
lemma has_colimit_parallel_pair [has_cokernel (f - g)] :
has_colimit (parallel_pair f g) :=
has_colimit.mk { cocone := cofork.of_π (cokernel.π (f - g)) (sub_eq_zero.1 $
by { rw ←sub_comp, exact cokernel.condition _ }),
is_colimit := cofork.is_colimit.mk _
(λ s, cokernel.desc (f - g) (cofork.π s) $
by { rw sub_comp, apply sub_eq_zero.2, exact cofork.condition _ })
(λ s, by simp)
(λ s m h, by { ext, simpa using h walking_parallel_pair.one }) }
end
section
/-- If a preadditive category has all cokernels, then it also has all coequalizers. -/
lemma has_coequalizers_of_has_cokernels [has_cokernels C] : has_coequalizers C :=
@has_coequalizers_of_has_colimit_parallel_pair _ _ (λ _ _ f g, has_colimit_parallel_pair f g)
end
end equalizers
end category_theory.preadditive
|
17816311989633016ba26e8d9bfb2394a4678b09 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/lake/Lake/CLI/Help.lean | f94491a5c1696ed620695e3972de546c2d47c78b | [
"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 | 8,239 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Sebastian Ullrich, Mac Malone
-/
import Lake.Version
namespace Lake
def usage :=
uiVersionString ++ "
USAGE:
lake [OPTIONS] <COMMAND>
OPTIONS:
--version print version and exit
--help, -h print help of the program or a command and exit
--dir, -d=file use the package configuration in a specific directory
--file, -f=file use a specific file for the package configuration
--quiet, -q hide progress messages
--verbose, -v show verbose information (command invocations)
--lean=cmd specify the `lean` command used by Lake
-K key[=value] set the configuration file option named key
--old only rebuild modified modules (ignore transitive deps)
--update, -U update manifest before building
COMMANDS:
new <name> <temp> create a Lean package in a new directory
init <name> <temp> create a Lean package in the current directory
build <targets>... build targets
update update dependencies and save them to the manifest
upload <tag> upload build artifacts to a GitHub release
clean remove build outputs
script manage and run workspace scripts
scripts shorthand for `lake script list`
run <script> shorthand for `lake script run`
serve start the Lean language server
env <cmd> <args>... execute a command in Lake's environment
exe <exe> <args>... build an exe and run it in Lake's environment
See `lake help <command>` for more information on a specific command."
def templateHelp :=
s!"The initial configuration and starter files are based on the template:
std library and executable; default
exe executable only
lib library only
math library only with a mathlib dependency"
def helpNew :=
s!"Create a Lean package in a new directory
USAGE:
lake new <name> [<template>]
{templateHelp}"
def helpInit :=
s!"Create a Lean package in the current directory
USAGE:
lake init <name> [<template>]
{templateHelp}"
def helpBuild :=
"Build targets
USAGE:
lake build [<targets>...]
A target is specified with a string of the form:
[[@]<package>/][<target>|[+]<module>][:<facet>]
The optional `@` and `+` markers can be used to disambiguate packages
and modules from other kinds of targets (i.e., executables and libraries).
LIBRARY FACETS: build the library's ...
lean (default) Lean binaries (*.olean, *.ilean files)
static static binary (*.a file)
shared shared binary (*.so, *.dll, or *.dylib file)
MODULE FACETS: build the module's ...
deps transitive local imports & shared library dependencies
bin (default) Lean binaries (*.olean, *.ilean files) and *.c file
o *.o object file (of its C file)
dynlib shared library (e.g., for `--load-dynlib`)
TARGET EXAMPLES: build the ...
a default facet of target `a`
@a default target(s) of package `a`
+A olean and .ilean files of module `A`
a/b default facet of target `b` of package `a`
a/+A:c C file of module `A` of package `a`
:foo facet `foo` of the root package
A bare `lake build` command will build the default facet of the root package.
Package dependencies are not updated during a build."
def helpUpdate :=
"Update dependencies and save them to the manifest
USAGE:
lake update [<package>...]
Updates the Lake package manifest (i.e., `lake-manifest.json`),
downloading and upgrading packages as needed. For each new (transitive) git
dependency, the appropriate commit is cloned into a subdirectory of
`packagesDir`. No copy is made of local dependencies.
If a set of packages are specified, said dependencies are upgraded to
the latest version compatible with the package's configuration (or removed if
removed from the configuration). If there are dependencies on multiple versions
of the same package, the version materialized is undefined.
A bare `lake update` will upgrade all dependencies."
def helpUpload :=
"Upload build artifacts to a GitHub release
USAGE:
lake upload <tag>
Packs the root package's `buildDir` into a `tar.gz` archive using `tar` and
then uploads the asset to the pre-existing GitHub release `tag` using `gh`."
def helpClean :=
"Remove build outputs
USAGE:
lake clean [<package>...]
If no package is specified, deletes the build directories of every package in
the workspace. Otherwise, just deletes those of the specified packages."
def helpScriptCli :=
"Manage Lake scripts
USAGE:
lake script <COMMAND>
COMMANDS:
list list available scripts
run <script> run a script
doc <script> print the docstring of a given script
See `lake help <command>` for more information on a specific command."
def helpScriptList :=
"List available scripts
USAGE:
lake script list
This command prints the list of all available scripts in the workspace."
def helpScriptRun :=
"Run a script
USAGE:
lake script run [[<package>/]<script>] [<args>...]
This command runs the given `script` from `package`, passing `args` to it.
Defaults to the root package.
A bare `lake run` command will run the default script(s) of the root package
(with no arguments)."
def helpScriptDoc :=
"Print a script's docstring
USAGE:
lake script doc [<package>/]<script>
Print the docstring of `script` in `package`. Defaults to the root package."
def helpServe :=
"Start the Lean language server
USAGE:
lake serve [-- <args>...]
Run the language server of the Lean installation (i.e., via `lean --server`)
with the package configuration's `moreServerArgs` field and `args`.
"
def helpEnv :=
"Execute a command in Lake's environment
USAGE:
lake env [<cmd>] [<args>...]
Spawns a new process executing `cmd` with the given `args` and with
the environment set based on the detected Lean/Lake installations and
the workspace configuration (if it exists).
Specifically, this command sets the following environment variables:
LAKE set to the detected Lake executable
LAKE_HOME set to the detected Lake home
LEAN_SYSROOT set to the detected Lean toolchain directory
LEAN_AR set to the detected Lean `ar` binary
LEAN_CC set to the detected `cc` (if not using the bundled one)
LEAN_PATH adds Lake's and the workspace's Lean library dirs
LEAN_SRC_PATH adds Lake's and the workspace's source dirs
PATH adds Lean's, Lake's, and the workspace's binary dirs
PATH adds Lean's and the workspace's library dirs (Windows)
DYLD_LIBRARY_PATH adds Lean's and the workspace's library dirs (MacOS)
LD_LIBRARY_PATH adds Lean's and the workspace's library dirs (other)
A bare `lake env` will print out the variables set and their values,
using the form NAME=VALUE like the POSIX `env` command."
def helpExe :=
"Build an executable target and run it in Lake's environment
USAGE:
lake exe <exe-target> [<args>...]
Looks for the executable target in the workspace (see `lake help build` to
learn how to specify targets), builds it if it is out of date, and then runs
it with the given `args` in Lake's environment (see `lake help env` for how
the environment is set up)."
def helpScript : (cmd : String) → String
| "list" => helpScriptList
| "run" => helpScriptRun
| "doc" => helpScriptDoc
| _ => helpScriptCli
def help : (cmd : String) → String
| "new" => helpNew
| "init" => helpInit
| "build" => helpBuild
| "update" => helpUpdate
| "upload" => helpUpload
| "clean" => helpClean
| "script" => helpScriptCli
| "scripts" => helpScriptList
| "run" => helpScriptRun
| "serve" => helpServe
| "env" => helpEnv
| "exe" => helpExe
| _ => usage
|
812c4c6149883659a8cc2794d0cec08187992e0e | 271e26e338b0c14544a889c31c30b39c989f2e0f | /tests/lean/run/typeclass_coerce.lean | 4c669381dc338ae43e4edfe2f9928a9bb2a57dc0 | [
"Apache-2.0"
] | permissive | dgorokho/lean4 | 805f99b0b60c545b64ac34ab8237a8504f89d7d4 | e949a052bad59b1c7b54a82d24d516a656487d8a | refs/heads/master | 1,607,061,363,851 | 1,578,006,086,000 | 1,578,006,086,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,809 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Daniel Selsam, Leonardo de Moura
Declare new, simpler coercion class without the special support for transitivity.
Test that new tabled typeclass resolution deals with loops and diamonds correctly.
-/
#exit
class HasCoerce (a b : Type) :=
(coerce : a → b)
def coerce {a b : Type} [HasCoerce a b] : a → b :=
@HasCoerce.coerce a b _
instance coerceTrans {a b c : Type} [HasCoerce b c] [HasCoerce a b] : HasCoerce a c :=
⟨fun x => coerce (coerce x : b)⟩
instance coerceBoolToProp : HasCoerce Bool Prop :=
⟨fun y => y = true⟩
instance coerceDecidableEq (x : Bool) : Decidable (coerce x) :=
inferInstanceAs (Decidable (x = true))
instance coerceSubtype {a : Type} {p : a → Prop} : HasCoerce {x // p x} a :=
⟨Subtype.val⟩
instance liftCoerceFn {a₁ a₂ b₁ b₂ : Type} [HasCoerce a₂ a₁] [HasCoerce b₁ b₂] : HasCoerce (a₁ → b₁) (a₂ → b₂) :=
⟨fun f x => coerce (f (coerce x))⟩
instance liftCoerceFnRange {a b₁ b₂ : Type} [HasCoerce b₁ b₂] : HasCoerce (a → b₁) (a → b₂) :=
⟨fun f x => coerce (f x)⟩
instance liftCoerceFnDom {a₁ a₂ b : Type} [HasCoerce a₂ a₁] : HasCoerce (a₁ → b) (a₂ → b) :=
⟨fun f x => f (coerce x)⟩
instance liftCoercePair {a₁ a₂ b₁ b₂ : Type} [HasCoerce a₁ a₂] [HasCoerce b₁ b₂] : HasCoerce (a₁ × b₁) (a₂ × b₂) :=
⟨fun p => Prod.casesOn p (fun x y => (coerce x, coerce y))⟩
instance liftCoercePair₁ {a₁ a₂ b : Type} [HasCoerce a₁ a₂] : HasCoerce (a₁ × b) (a₂ × b) :=
⟨fun p => Prod.casesOn p (fun x y => (coerce x, y))⟩
instance liftCoercePair₂ {a b₁ b₂ : Type} [HasCoerce b₁ b₂] : HasCoerce (a × b₁) (a × b₂) :=
⟨fun p => Prod.casesOn p (fun x y => (x, coerce y))⟩
instance liftCoerceList {a b : Type} [HasCoerce a b] : HasCoerce (List a) (List b) :=
⟨fun l => List.map (@coerce a b _) l⟩
-- Tests
axiom Bot (α : Type) (n : Nat) : Type
axiom Left (α : Type) (n : Nat) : Type
axiom Right (α : Type) (n : Nat) : Type
axiom Top (α : Type) (n : Nat) : Type
@[instance] axiom BotToTopSucc (α : Type) (n : Nat) : HasCoerce (Bot α n) (Top α n.succ)
@[instance] axiom TopSuccToBot (α : Type) (n : Nat) : HasCoerce (Top α n.succ) (Bot α n)
@[instance] axiom TopToRight (α : Type) (n : Nat) : HasCoerce (Top α n) (Right α n)
@[instance] axiom TopToLeft (α : Type) (n : Nat) : HasCoerce (Top α n) (Left α n)
@[instance] axiom LeftToTop (α : Type) (n : Nat) : HasCoerce (Left α n) (Top α n)
@[instance] axiom RightToTop (α : Type) (n : Nat) : HasCoerce (Right α n) (Top α n)
@[instance] axiom LeftToBot (α : Type) (n : Nat) : HasCoerce (Left α n) (Bot α n)
@[instance] axiom RightToBot (α : Type) (n : Nat) : HasCoerce (Right α n) (Bot α n)
@[instance] axiom BotToLeft (α : Type) (n : Nat) : HasCoerce (Bot α n) (Left α n)
@[instance] axiom BotToRight (α : Type) (n : Nat) : HasCoerce (Bot α n) (Right α n)
#synth HasCoerce (Top Unit Nat.zero)
(Top Unit Nat.zero.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ)
#synth HasCoerce (Top Unit Nat.zero × Top Unit Nat.zero × Top Unit Nat.zero)
(Top Unit Nat.zero.succ.succ.succ.succ.succ.succ.succ.succ
× Top Unit Nat.zero.succ.succ.succ.succ.succ.succ.succ.succ
× Top Unit Nat.zero.succ.succ.succ.succ.succ.succ.succ.succ)
#exit -- TODO: enable following test
#synth HasCoerce (Top Unit Nat.zero.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ → Top Unit Nat.zero)
(Top Unit Nat.zero → Top Unit Nat.zero.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ)
|
732a4eca2bb325fb0b0128594691cb5186d4826d | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/data/nat/choose/bounds.lean | 113353b97d516449f8af342a10d171fab24a4da9 | [
"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 | 1,295 | lean | /-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Eric Rodriguez
-/
import algebra.group_power.lemmas
import algebra.order.field
import data.nat.cast
import data.nat.choose.basic
/-!
# Inequalities for binomial coefficients
This file proves exponential bounds on binomial coefficients. We might want to add here the
bounds `n^r/r^r ≤ n.choose r ≤ e^r n^r/r^r` in the future.
## Main declarations
* `nat.choose_le_pow`: `n.choose r ≤ n^r / r!`
* `nat.pow_le_choose`: `(n + 1 - r)^r / r! ≤ n.choose r`. Beware of the fishy ℕ-subtraction.
-/
open_locale nat
variables {α : Type*} [linear_ordered_semifield α]
namespace nat
lemma choose_le_pow (r n : ℕ) : (n.choose r : α) ≤ n^r / r! :=
begin
rw le_div_iff',
{ norm_cast,
rw ←nat.desc_factorial_eq_factorial_mul_choose,
exact n.desc_factorial_le_pow r },
exact_mod_cast r.factorial_pos,
end
-- horrific casting is due to ℕ-subtraction
lemma pow_le_choose (r n : ℕ) : ((n + 1 - r : ℕ)^r : α) / r! ≤ n.choose r :=
begin
rw div_le_iff',
{ norm_cast,
rw [←nat.desc_factorial_eq_factorial_mul_choose],
exact n.pow_sub_le_desc_factorial r },
exact_mod_cast r.factorial_pos,
end
end nat
|
fb8f13efdffebfca7081d93be9ccbfa4fe39c42e | 46125763b4dbf50619e8846a1371029346f4c3db | /src/topology/metric_space/antilipschitz.lean | 59b7c1d1f20f633b381b093ea0696a49b62e57f3 | [
"Apache-2.0"
] | permissive | thjread/mathlib | a9d97612cedc2c3101060737233df15abcdb9eb1 | 7cffe2520a5518bba19227a107078d83fa725ddc | refs/heads/master | 1,615,637,696,376 | 1,583,953,063,000 | 1,583,953,063,000 | 246,680,271 | 0 | 0 | Apache-2.0 | 1,583,960,875,000 | 1,583,960,875,000 | null | UTF-8 | Lean | false | false | 4,060 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import topology.metric_space.lipschitz
/-!
# Antilipschitz functions
We say that a map `f : α → β` between two (extended) metric spaces is
`antilipschitz_with K`, `K ≥ 0`, if for all `x, y` we have `edist x y ≤ K * edist (f x) (f y)`.
For a metric space, the latter inequality is equivalent to `dist x y ≤ K * dist (f x) (f y)`.
## Implementation notes
The parameter `K` has type `nnreal`. This way we avoid conjuction in the definition and have
coercions both to `ℝ` and `ennreal`. We do not require `0 < K` in the definition, mostly because
we do not have a `posreal` type.
-/
variables {α : Type*} {β : Type*} {γ : Type*}
open_locale nnreal
/-- We say that `f : α → β` is `antilipschitz_with K` if for any two points `x`, `y` we have
`K * edist x y ≤ edist (f x) (f y)`. -/
def antilipschitz_with [emetric_space α] [emetric_space β] (K : ℝ≥0) (f : α → β) :=
∀ x y, edist x y ≤ K * edist (f x) (f y)
lemma antilipschitz_with_iff_le_mul_dist [metric_space α] [metric_space β] {K : ℝ≥0} {f : α → β} :
antilipschitz_with K f ↔ ∀ x y, dist x y ≤ K * dist (f x) (f y) :=
by { simp only [antilipschitz_with, edist_nndist, dist_nndist], norm_cast }
alias antilipschitz_with_iff_le_mul_dist ↔ antilipschitz_with.le_mul_dist
antilipschitz_with.of_le_mul_dist
lemma antilipschitz_with.mul_le_dist [metric_space α] [metric_space β] {K : ℝ≥0} {f : α → β}
(hf : antilipschitz_with K f) (x y : α) :
↑K⁻¹ * dist x y ≤ dist (f x) (f y) :=
begin
by_cases hK : K = 0, by simp [hK, dist_nonneg],
rw [nnreal.coe_inv, ← div_eq_inv_mul],
apply div_le_of_le_mul (nnreal.coe_pos.2 $ zero_lt_iff_ne_zero.2 hK),
exact hf.le_mul_dist x y
end
namespace antilipschitz_with
variables [emetric_space α] [emetric_space β] [emetric_space γ] {K : ℝ≥0} {f : α → β}
protected lemma injective (hf : antilipschitz_with K f) :
function.injective f :=
λ x y h, by simpa only [h, edist_self, mul_zero, edist_le_zero] using hf x y
lemma mul_le_edist (hf : antilipschitz_with K f) (x y : α) :
↑K⁻¹ * edist x y ≤ edist (f x) (f y) :=
begin
by_cases hK : K = 0, by simp [hK],
rw [ennreal.coe_inv hK, mul_comm, ← ennreal.div_def],
apply ennreal.div_le_of_le_mul,
rw mul_comm,
exact hf x y
end
lemma id : antilipschitz_with 1 (id : α → α) :=
λ x y, by simp only [ennreal.coe_one, one_mul, id, le_refl]
lemma comp {Kg : ℝ≥0} {g : β → γ} (hg : antilipschitz_with Kg g)
{Kf : ℝ≥0} {f : α → β} (hf : antilipschitz_with Kf f) :
antilipschitz_with (Kf * Kg) (g ∘ f) :=
λ x y,
calc edist x y ≤ Kf * edist (f x) (f y) : hf x y
... ≤ Kf * (Kg * edist (g (f x)) (g (f y))) : ennreal.mul_left_mono (hg _ _)
... = _ : by rw [ennreal.coe_mul, mul_assoc]
lemma to_inverse (hf : antilipschitz_with K f) {g : β → α} (hg : function.right_inverse g f) :
lipschitz_with K g :=
begin
intros x y,
have := hf (g x) (g y),
rwa [hg x, hg y] at this
end
lemma uniform_embedding (hf : antilipschitz_with K f) (hfc : uniform_continuous f) :
uniform_embedding f :=
begin
refine emetric.uniform_embedding_iff.2 ⟨hf.injective, hfc, λ δ δ0, _⟩,
by_cases hK : K = 0,
{ refine ⟨1, ennreal.zero_lt_one, λ x y _, lt_of_le_of_lt _ δ0⟩,
simpa only [hK, ennreal.coe_zero, zero_mul] using hf x y },
{ refine ⟨K⁻¹ * δ, _, λ x y hxy, lt_of_le_of_lt (hf x y) _⟩,
{ exact canonically_ordered_semiring.mul_pos.2 ⟨ennreal.inv_pos.2 ennreal.coe_ne_top, δ0⟩ },
{ rw [mul_comm, ← ennreal.div_def] at hxy,
have := ennreal.mul_lt_of_lt_div hxy,
rwa mul_comm } }
end
end antilipschitz_with
lemma lipschitz_with.to_inverse [emetric_space α] [emetric_space β] {K : ℝ≥0} {f : α → β}
(hf : lipschitz_with K f) {g : β → α} (hg : function.right_inverse g f) :
antilipschitz_with K g :=
λ x y, by simpa only [hg _] using hf (g x) (g y)
|
a543610020add948981cc17a9c144ac2697c4118 | 2fbe653e4bc441efde5e5d250566e65538709888 | /src/analysis/asymptotics.lean | 40e6c19cea94ac4acbb23fd4da4c791d3a6d42df | [
"Apache-2.0"
] | permissive | aceg00/mathlib | 5e15e79a8af87ff7eb8c17e2629c442ef24e746b | 8786ea6d6d46d6969ac9a869eb818bf100802882 | refs/heads/master | 1,649,202,698,930 | 1,580,924,783,000 | 1,580,924,783,000 | 149,197,272 | 0 | 0 | Apache-2.0 | 1,537,224,208,000 | 1,537,224,207,000 | null | UTF-8 | Lean | false | false | 40,162 | lean | /-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Yury Kudryashov
-/
import analysis.normed_space.basic tactic.alias
/-!
# Asymptotics
We introduce these relations:
* `is_O_with c f g l` : "f is big O of g along l with constant c";
* `is_O f g l` : "f is big O of g along l";
* `is_o f g l` : "f is little o of g along l".
Here `l` is any filter on the domain of `f` and `g`, which are assumed to be the same. The codomains
of `f` and `g` do not need to be the same; all that is needed that there is a norm associated with
these types, and it is the norm that is compared asymptotically.
The relation `is_O_with c` is introduced to factor out common algebraic arguments in the proofs of
similar properties of `is_O` and `is_o`. Usually proofs outside of this file should use `is_O`
instead.
Often the ranges of `f` and `g` will be the real numbers, in which case the norm is the absolute
value. In general, we have
`is_O f g l ↔ is_O (λ x, ∥f x∥) (λ x, ∥g x∥) l`,
and similarly for `is_o`. But our setup allows us to use the notions e.g. with functions
to the integers, rationals, complex numbers, or any normed vector space without mentioning the
norm explicitly.
If `f` and `g` are functions to a normed field like the reals or complex numbers and `g` is always
nonzero, we have
`is_o f g l ↔ tendsto (λ x, f x / (g x)) l (𝓝 0)`.
In fact, the right-to-left direction holds without the hypothesis on `g`, and in the other direction
it suffices to assume that `f` is zero wherever `g` is. (This generalization is useful in defining
the Fréchet derivative.)
-/
open filter set
open_locale topological_space
namespace asymptotics
variables {α : Type*} {β : Type*} {E : Type*} {F : Type*} {G : Type*}
{E' : Type*} {F' : Type*} {G' : Type*} {R : Type*} {R' : Type*} {𝕜 : Type*} {𝕜' : Type*}
variables [has_norm E] [has_norm F] [has_norm G] [normed_group E'] [normed_group F']
[normed_group G'] [normed_ring R] [normed_ring R'] [normed_field 𝕜] [normed_field 𝕜']
{c c' : ℝ} {f : α → E} {g : α → F} {k : α → G} {f' : α → E'} {g' : α → F'} {k' : α → G'}
{l l' : filter α}
section defs
/-! ### Definitions -/
/-- This version of the Landau notation `is_O_with C f g l` where `f` and `g` are two functions on
a type `α` and `l` is a filter on `α`, means that eventually for `l`, `∥f∥` is bounded by `C * ∥g∥`.
In other words, `∥f∥ / ∥g∥` is eventually bounded by `C`, modulo division by zero issues that are
avoided by this definition. Probably you want to use `is_O` instead of this relation. -/
def is_O_with (c : ℝ) (f : α → E) (g : α → F) (l : filter α) : Prop :=
∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥
/-- The Landau notation `is_O f g l` where `f` and `g` are two functions on a type `α` and `l` is
a filter on `α`, means that eventually for `l`, `∥f∥` is bounded by a constant multiple of `∥g∥`.
In other words, `∥f∥ / ∥g∥` is eventually bounded, modulo division by zero issues that are avoided
by this definition. -/
def is_O (f : α → E) (g : α → F) (l : filter α) : Prop := ∃ c : ℝ, is_O_with c f g l
/-- The Landau notation `is_o f g l` where `f` and `g` are two functions on a type `α` and `l` is
a filter on `α`, means that eventually for `l`, `∥f∥` is bounded by an arbitrarily small constant
multiple of `∥g∥`. In other words, `∥f∥ / ∥g∥` tends to `0` along `l`, modulo division by zero
issues that are avoided by this definition. -/
def is_o (f : α → E) (g : α → F) (l : filter α) : Prop := ∀ ⦃c : ℝ⦄, 0 < c → is_O_with c f g l
end defs
/-! ### Conversions -/
theorem is_O_with.is_O (h : is_O_with c f g l) : is_O f g l := ⟨c, h⟩
theorem is_o.is_O_with (hgf : is_o f g l) : is_O_with 1 f g l := hgf zero_lt_one
theorem is_o.is_O (hgf : is_o f g l) : is_O f g l := hgf.is_O_with.is_O
theorem is_O_with.weaken (h : is_O_with c f g' l) (hc : c ≤ c') : is_O_with c' f g' l :=
mem_sets_of_superset h $ λ x hx,
calc ∥f x∥ ≤ c * ∥g' x∥ : hx
... ≤ _ : mul_le_mul_of_nonneg_right hc (norm_nonneg _)
theorem is_O_with.exists_pos (h : is_O_with c f g' l) :
∃ c' (H : 0 < c'), is_O_with c' f g' l :=
⟨max c 1, lt_of_lt_of_le zero_lt_one (le_max_right c 1), h.weaken $ le_max_left c 1⟩
theorem is_O.exists_pos (h : is_O f g' l) : ∃ c (H : 0 < c), is_O_with c f g' l :=
let ⟨c, hc⟩ := h in hc.exists_pos
theorem is_O_with.exists_nonneg (h : is_O_with c f g' l) :
∃ c' (H : 0 ≤ c'), is_O_with c' f g' l :=
let ⟨c, cpos, hc⟩ := h.exists_pos in ⟨c, le_of_lt cpos, hc⟩
theorem is_O.exists_nonneg (h : is_O f g' l) :
∃ c (H : 0 ≤ c), is_O_with c f g' l :=
let ⟨c, hc⟩ := h in hc.exists_nonneg
/-! ### Congruence -/
theorem is_O_with_congr {c₁ c₂} {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hc : c₁ = c₂) (hf : ∀ᶠ x in l, f₁ x = f₂ x) (hg : ∀ᶠ x in l, g₁ x = g₂ x) :
is_O_with c₁ f₁ g₁ l ↔ is_O_with c₂ f₂ g₂ l :=
begin
subst c₂,
apply filter.congr_sets,
filter_upwards [hf, hg],
assume x e₁ e₂,
dsimp at e₁ e₂ ⊢,
rw [e₁, e₂]
end
theorem is_O_with.congr' {c₁ c₂} {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hc : c₁ = c₂) (hf : ∀ᶠ x in l, f₁ x = f₂ x) (hg : ∀ᶠ x in l, g₁ x = g₂ x) :
is_O_with c₁ f₁ g₁ l → is_O_with c₂ f₂ g₂ l :=
(is_O_with_congr hc hf hg).mp
theorem is_O_with.congr {c₁ c₂} {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hc : c₁ = c₂) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) :
is_O_with c₁ f₁ g₁ l → is_O_with c₂ f₂ g₂ l :=
λ h, h.congr' hc (univ_mem_sets' hf) (univ_mem_sets' hg)
theorem is_O_with.congr_left {f₁ f₂ : α → E} {l : filter α} (hf : ∀ x, f₁ x = f₂ x) :
is_O_with c f₁ g l → is_O_with c f₂ g l :=
is_O_with.congr rfl hf (λ _, rfl)
theorem is_O_with.congr_right {g₁ g₂ : α → F} {l : filter α} (hg : ∀ x, g₁ x = g₂ x) :
is_O_with c f g₁ l → is_O_with c f g₂ l :=
is_O_with.congr rfl (λ _, rfl) hg
theorem is_O_with.congr_const {c₁ c₂} {l : filter α} (hc : c₁ = c₂) :
is_O_with c₁ f g l → is_O_with c₂ f g l :=
is_O_with.congr hc (λ _, rfl) (λ _, rfl)
theorem is_O_congr {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hf : ∀ᶠ x in l, f₁ x = f₂ x) (hg : ∀ᶠ x in l, g₁ x = g₂ x) :
is_O f₁ g₁ l ↔ is_O f₂ g₂ l :=
exists_congr $ λ c, is_O_with_congr rfl hf hg
theorem is_O.congr' {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hf : ∀ᶠ x in l, f₁ x = f₂ x) (hg : ∀ᶠ x in l, g₁ x = g₂ x) :
is_O f₁ g₁ l → is_O f₂ g₂ l :=
(is_O_congr hf hg).mp
theorem is_O.congr {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) :
is_O f₁ g₁ l → is_O f₂ g₂ l :=
λ h, h.congr' (univ_mem_sets' hf) (univ_mem_sets' hg)
theorem is_O.congr_left {f₁ f₂ : α → E} {l : filter α} (hf : ∀ x, f₁ x = f₂ x) :
is_O f₁ g l → is_O f₂ g l :=
is_O.congr hf (λ _, rfl)
theorem is_O.congr_right {g₁ g₂ : α → E} {l : filter α} (hg : ∀ x, g₁ x = g₂ x) :
is_O f g₁ l → is_O f g₂ l :=
is_O.congr (λ _, rfl) hg
theorem is_o_congr {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hf : ∀ᶠ x in l, f₁ x = f₂ x) (hg : ∀ᶠ x in l, g₁ x = g₂ x) :
is_o f₁ g₁ l ↔ is_o f₂ g₂ l :=
ball_congr (λ c hc, is_O_with_congr (eq.refl c) hf hg)
theorem is_o.congr' {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hf : ∀ᶠ x in l, f₁ x = f₂ x) (hg : ∀ᶠ x in l, g₁ x = g₂ x) :
is_o f₁ g₁ l → is_o f₂ g₂ l :=
(is_o_congr hf hg).mp
theorem is_o.congr {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) :
is_o f₁ g₁ l → is_o f₂ g₂ l :=
λ h, h.congr' (univ_mem_sets' hf) (univ_mem_sets' hg)
theorem is_o.congr_left {f₁ f₂ : α → E} {l : filter α} (hf : ∀ x, f₁ x = f₂ x) :
is_o f₁ g l → is_o f₂ g l :=
is_o.congr hf (λ _, rfl)
theorem is_o.congr_right {g₁ g₂ : α → E} {l : filter α} (hg : ∀ x, g₁ x = g₂ x) :
is_o f g₁ l → is_o f g₂ l :=
is_o.congr (λ _, rfl) hg
/-! ### Filter operations and transitivity -/
theorem is_O_with.comp_tendsto (hcfg : is_O_with c f g l)
{k : β → α} {l' : filter β} (hk : tendsto k l' l):
is_O_with c (f ∘ k) (g ∘ k) l' :=
hk hcfg
theorem is_O.comp_tendsto (hfg : is_O f g l) {k : β → α} {l' : filter β} (hk : tendsto k l' l) :
is_O (f ∘ k) (g ∘ k) l' :=
hfg.imp (λ c h, h.comp_tendsto hk)
theorem is_o.comp_tendsto (hfg : is_o f g l) {k : β → α} {l' : filter β} (hk : tendsto k l' l) :
is_o (f ∘ k) (g ∘ k) l' :=
λ c cpos, (hfg cpos).comp_tendsto hk
theorem is_O_with.mono (h : is_O_with c f g l') (hl : l ≤ l') : is_O_with c f g l :=
hl h
theorem is_O.mono (h : is_O f g l') (hl : l ≤ l') : is_O f g l :=
h.imp (λ c h, h.mono hl)
theorem is_o.mono (h : is_o f g l') (hl : l ≤ l') : is_o f g l :=
λ c cpos, (h cpos).mono hl
theorem is_O_with.trans (hfg : is_O_with c f g l) (hgk : is_O_with c' g k l) (hc : 0 ≤ c) :
is_O_with (c * c') f k l :=
begin
filter_upwards [hfg, hgk],
assume x hx hx',
calc ∥f x∥ ≤ c * ∥g x∥ : hx
... ≤ c * (c' * ∥k x∥) : mul_le_mul_of_nonneg_left hx' hc
... = c * c' * ∥k x∥ : (mul_assoc _ _ _).symm
end
theorem is_O.trans (hfg : is_O f g' l) (hgk : is_O g' k l) : is_O f k l :=
let ⟨c, cnonneg, hc⟩ := hfg.exists_nonneg, ⟨c', hc'⟩ := hgk in (hc.trans hc' cnonneg).is_O
theorem is_o.trans_is_O_with (hfg : is_o f g l) (hgk : is_O_with c g k l) (hc : 0 < c) :
is_o f k l :=
begin
intros c' c'pos,
have : 0 < c' / c, from div_pos c'pos hc,
exact ((hfg this).trans hgk (le_of_lt this)).congr_const (div_mul_cancel _ (ne_of_gt hc))
end
theorem is_o.trans_is_O (hfg : is_o f g l) (hgk : is_O g k' l) : is_o f k' l :=
let ⟨c, cpos, hc⟩ := hgk.exists_pos in hfg.trans_is_O_with hc cpos
theorem is_O_with.trans_is_o (hfg : is_O_with c f g l) (hgk : is_o g k l) (hc : 0 < c) :
is_o f k l :=
begin
intros c' c'pos,
have : 0 < c' / c, from div_pos c'pos hc,
exact (hfg.trans (hgk this) (le_of_lt hc)).congr_const (mul_div_cancel' _ (ne_of_gt hc))
end
theorem is_O.trans_is_o (hfg : is_O f g' l) (hgk : is_o g' k l) : is_o f k l :=
let ⟨c, cpos, hc⟩ := hfg.exists_pos in hc.trans_is_o hgk cpos
theorem is_o.trans (hfg : is_o f g l) (hgk : is_o g k' l) : is_o f k' l :=
hfg.trans_is_O hgk.is_O
theorem is_o.trans' (hfg : is_o f g' l) (hgk : is_o g' k l) : is_o f k l :=
hfg.is_O.trans_is_o hgk
section
variable (l)
theorem is_O_with_of_le' (hfg : ∀ x, ∥f x∥ ≤ c * ∥g x∥) : is_O_with c f g l :=
univ_mem_sets' hfg
theorem is_O_with_of_le (hfg : ∀ x, ∥f x∥ ≤ ∥g x∥) : is_O_with 1 f g l :=
is_O_with_of_le' l $ λ x, by { rw one_mul, exact hfg x }
theorem is_O_of_le' (hfg : ∀ x, ∥f x∥ ≤ c * ∥g x∥) : is_O f g l :=
(is_O_with_of_le' l hfg).is_O
theorem is_O_of_le (hfg : ∀ x, ∥f x∥ ≤ ∥g x∥) : is_O f g l :=
(is_O_with_of_le l hfg).is_O
end
theorem is_O_with_refl (f : α → E) (l : filter α) : is_O_with 1 f f l :=
is_O_with_of_le l $ λ _, le_refl _
theorem is_O_refl (f : α → E) (l : filter α) : is_O f f l := (is_O_with_refl f l).is_O
theorem is_O_with.trans_le (hfg : is_O_with c f g l) (hgk : ∀ x, ∥g x∥ ≤ ∥k x∥) (hc : 0 ≤ c) :
is_O_with c f k l :=
(hfg.trans (is_O_with_of_le l hgk) hc).congr_const $ mul_one c
theorem is_O.trans_le (hfg : is_O f g' l) (hgk : ∀ x, ∥g' x∥ ≤ ∥k x∥) :
is_O f k l :=
hfg.trans (is_O_of_le l hgk)
section bot
variables (c f g)
theorem is_O_with_bot : is_O_with c f g ⊥ := trivial
theorem is_O_bot : is_O f g ⊥ := (is_O_with_bot c f g).is_O
theorem is_o_bot : is_o f g ⊥ := λ c _, is_O_with_bot c f g
end bot
theorem is_O_with.join (h : is_O_with c f g l) (h' : is_O_with c f g l') :
is_O_with c f g (l ⊔ l') :=
mem_sup_sets.2 ⟨h, h'⟩
theorem is_O_with.join' (h : is_O_with c f g' l) (h' : is_O_with c' f g' l') :
is_O_with (max c c') f g' (l ⊔ l') :=
mem_sup_sets.2 ⟨(h.weaken $ le_max_left c c'), (h'.weaken $ le_max_right c c')⟩
theorem is_O.join (h : is_O f g' l) (h' : is_O f g' l') : is_O f g' (l ⊔ l') :=
let ⟨c, hc⟩ := h, ⟨c', hc'⟩ := h' in (hc.join' hc').is_O
theorem is_o.join (h : is_o f g l) (h' : is_o f g l') :
is_o f g (l ⊔ l') :=
λ c cpos, (h cpos).join (h' cpos)
/-! ### Simplification : norm -/
@[simp] theorem is_O_with_norm_right : is_O_with c f (λ x, ∥g' x∥) l ↔ is_O_with c f g' l :=
by simp only [is_O_with, norm_norm]
alias is_O_with_norm_right ↔ asymptotics.is_O_with.of_norm_right asymptotics.is_O_with.norm_right
@[simp] theorem is_O_norm_right : is_O f (λ x, ∥g' x∥) l ↔ is_O f g' l :=
exists_congr $ λ _, is_O_with_norm_right
alias is_O_norm_right ↔ asymptotics.is_O.of_norm_right asymptotics.is_O.norm_right
@[simp] theorem is_o_norm_right : is_o f (λ x, ∥g' x∥) l ↔ is_o f g' l :=
forall_congr $ λ _, forall_congr $ λ _, is_O_with_norm_right
alias is_o_norm_right ↔ asymptotics.is_o.of_norm_right asymptotics.is_o.norm_right
@[simp] theorem is_O_with_norm_left : is_O_with c (λ x, ∥f' x∥) g l ↔ is_O_with c f' g l :=
by simp only [is_O_with, norm_norm]
alias is_O_with_norm_left ↔ asymptotics.is_O_with.of_norm_left asymptotics.is_O_with.norm_left
@[simp] theorem is_O_norm_left : is_O (λ x, ∥f' x∥) g l ↔ is_O f' g l :=
exists_congr $ λ _, is_O_with_norm_left
alias is_O_norm_left ↔ asymptotics.is_O.of_norm_left asymptotics.is_O.norm_left
@[simp] theorem is_o_norm_left : is_o (λ x, ∥f' x∥) g l ↔ is_o f' g l :=
forall_congr $ λ _, forall_congr $ λ _, is_O_with_norm_left
alias is_o_norm_left ↔ asymptotics.is_o.of_norm_left asymptotics.is_o.norm_left
theorem is_O_with_norm_norm :
is_O_with c (λ x, ∥f' x∥) (λ x, ∥g' x∥) l ↔ is_O_with c f' g' l :=
is_O_with_norm_left.trans is_O_with_norm_right
alias is_O_with_norm_norm ↔ asymptotics.is_O_with.of_norm_norm asymptotics.is_O_with.norm_norm
theorem is_O_norm_norm :
is_O (λ x, ∥f' x∥) (λ x, ∥g' x∥) l ↔ is_O f' g' l :=
is_O_norm_left.trans is_O_norm_right
alias is_O_norm_norm ↔ asymptotics.is_O.of_norm_norm asymptotics.is_O.norm_norm
theorem is_o_norm_norm :
is_o (λ x, ∥f' x∥) (λ x, ∥g' x∥) l ↔ is_o f' g' l :=
is_o_norm_left.trans is_o_norm_right
alias is_o_norm_norm ↔ asymptotics.is_o.of_norm_norm asymptotics.is_o.norm_norm
/-! ### Simplification: negate -/
@[simp] theorem is_O_with_neg_right : is_O_with c f (λ x, -(g' x)) l ↔ is_O_with c f g' l :=
by simp only [is_O_with, norm_neg]
alias is_O_with_neg_right ↔ asymptotics.is_O_with.of_neg_right asymptotics.is_O_with.neg_right
@[simp] theorem is_O_neg_right : is_O f (λ x, -(g' x)) l ↔ is_O f g' l :=
exists_congr $ λ _, is_O_with_neg_right
alias is_O_neg_right ↔ asymptotics.is_O.of_neg_right asymptotics.is_O.neg_right
@[simp] theorem is_o_neg_right : is_o f (λ x, -(g' x)) l ↔ is_o f g' l :=
forall_congr $ λ _, forall_congr $ λ _, is_O_with_neg_right
alias is_o_neg_right ↔ asymptotics.is_o.of_neg_right asymptotics.is_o.neg_right
@[simp] theorem is_O_with_neg_left : is_O_with c (λ x, -(f' x)) g l ↔ is_O_with c f' g l :=
by simp only [is_O_with, norm_neg]
alias is_O_with_neg_left ↔ asymptotics.is_O_with.of_neg_left asymptotics.is_O_with.neg_left
@[simp] theorem is_O_neg_left : is_O (λ x, -(f' x)) g l ↔ is_O f' g l :=
exists_congr $ λ _, is_O_with_neg_left
alias is_O_neg_left ↔ asymptotics.is_O.of_neg_left asymptotics.is_O.neg_left
@[simp] theorem is_o_neg_left : is_o (λ x, -(f' x)) g l ↔ is_o f' g l :=
forall_congr $ λ _, forall_congr $ λ _, is_O_with_neg_left
alias is_o_neg_left ↔ asymptotics.is_o.of_neg_right asymptotics.is_o.neg_left
/-! ### Product of functions (right) -/
lemma is_O_with_fst_prod : is_O_with 1 f' (λ x, (f' x, g' x)) l :=
is_O_with_of_le l $ λ x, le_max_left _ _
lemma is_O_with_snd_prod : is_O_with 1 g' (λ x, (f' x, g' x)) l :=
is_O_with_of_le l $ λ x, le_max_right _ _
lemma is_O_fst_prod : is_O f' (λ x, (f' x, g' x)) l := is_O_with_fst_prod.is_O
lemma is_O_snd_prod : is_O g' (λ x, (f' x, g' x)) l := is_O_with_snd_prod.is_O
section
variables (f' k')
lemma is_O_with.prod_rightl (h : is_O_with c f g' l) (hc : 0 ≤ c) :
is_O_with c f (λ x, (g' x, k' x)) l :=
(h.trans is_O_with_fst_prod hc).congr_const (mul_one c)
lemma is_O.prod_rightl (h : is_O f g' l) : is_O f (λx, (g' x, k' x)) l :=
let ⟨c, cnonneg, hc⟩ := h.exists_nonneg in (hc.prod_rightl k' cnonneg).is_O
lemma is_o.prod_rightl (h : is_o f g' l) : is_o f (λ x, (g' x, k' x)) l :=
λ c cpos, (h cpos).prod_rightl k' (le_of_lt cpos)
lemma is_O_with.prod_rightr (h : is_O_with c f g' l) (hc : 0 ≤ c) :
is_O_with c f (λ x, (f' x, g' x)) l :=
(h.trans is_O_with_snd_prod hc).congr_const (mul_one c)
lemma is_O.prod_rightr (h : is_O f g' l) : is_O f (λx, (f' x, g' x)) l :=
let ⟨c, cnonneg, hc⟩ := h.exists_nonneg in (hc.prod_rightr f' cnonneg).is_O
lemma is_o.prod_rightr (h : is_o f g' l) : is_o f (λx, (f' x, g' x)) l :=
λ c cpos, (h cpos).prod_rightr f' (le_of_lt cpos)
end
lemma is_O_with.prod_left_same (hf : is_O_with c f' k' l) (hg : is_O_with c g' k' l) :
is_O_with c (λ x, (f' x, g' x)) k' l :=
begin
filter_upwards [hf, hg],
simp only [mem_set_of_eq],
exact λ x, max_le
end
lemma is_O_with.prod_left (hf : is_O_with c f' k' l) (hg : is_O_with c' g' k' l) :
is_O_with (max c c') (λ x, (f' x, g' x)) k' l :=
(hf.weaken $ le_max_left c c').prod_left_same (hg.weaken $ le_max_right c c')
lemma is_O_with.prod_left_fst (h : is_O_with c (λ x, (f' x, g' x)) k' l) :
is_O_with c f' k' l :=
(is_O_with_fst_prod.trans h zero_le_one).congr_const $ one_mul c
lemma is_O_with.prod_left_snd (h : is_O_with c (λ x, (f' x, g' x)) k' l) :
is_O_with c g' k' l :=
(is_O_with_snd_prod.trans h zero_le_one).congr_const $ one_mul c
lemma is_O_with_prod_left :
is_O_with c (λ x, (f' x, g' x)) k' l ↔ is_O_with c f' k' l ∧ is_O_with c g' k' l :=
⟨λ h, ⟨h.prod_left_fst, h.prod_left_snd⟩, λ h, h.1.prod_left_same h.2⟩
lemma is_O.prod_left (hf : is_O f' k' l) (hg : is_O g' k' l) : is_O (λ x, (f' x, g' x)) k' l :=
let ⟨c, hf⟩ := hf, ⟨c', hg⟩ := hg in (hf.prod_left hg).is_O
lemma is_O.prod_left_fst (h : is_O (λ x, (f' x, g' x)) k' l) : is_O f' k' l :=
is_O_fst_prod.trans h
lemma is_O.prod_left_snd (h : is_O (λ x, (f' x, g' x)) k' l) : is_O g' k' l :=
is_O_snd_prod.trans h
@[simp] lemma is_O_prod_left :
is_O (λ x, (f' x, g' x)) k' l ↔ is_O f' k' l ∧ is_O g' k' l :=
⟨λ h, ⟨h.prod_left_fst, h.prod_left_snd⟩, λ h, h.1.prod_left h.2⟩
lemma is_o.prod_left (hf : is_o f' k' l) (hg : is_o g' k' l) : is_o (λ x, (f' x, g' x)) k' l :=
λ c hc, (hf hc).prod_left_same (hg hc)
lemma is_o.prod_left_fst (h : is_o (λ x, (f' x, g' x)) k' l) : is_o f' k' l :=
is_O_fst_prod.trans_is_o h
lemma is_o.prod_left_snd (h : is_o (λ x, (f' x, g' x)) k' l) : is_o g' k' l :=
is_O_snd_prod.trans_is_o h
@[simp] lemma is_o_prod_left :
is_o (λ x, (f' x, g' x)) k' l ↔ is_o f' k' l ∧ is_o g' k' l :=
⟨λ h, ⟨h.prod_left_fst, h.prod_left_snd⟩, λ h, h.1.prod_left h.2⟩
/-! ### Addition and subtraction -/
section add_sub
variables {c₁ c₂ : ℝ} {f₁ f₂ : α → E'}
theorem is_O_with.add (h₁ : is_O_with c₁ f₁ g l) (h₂ : is_O_with c₂ f₂ g l) :
is_O_with (c₁ + c₂) (λ x, f₁ x + f₂ x) g l :=
by filter_upwards [h₁, h₂] λ x hx₁ hx₂,
calc ∥f₁ x + f₂ x∥ ≤ c₁ * ∥g x∥ + c₂ * ∥g x∥ : norm_add_le_of_le hx₁ hx₂
... = (c₁ + c₂) * ∥g x∥ : (add_mul _ _ _).symm
theorem is_O.add : is_O f₁ g l → is_O f₂ g l → is_O (λ x, f₁ x + f₂ x) g l
| ⟨c₁, hc₁⟩ ⟨c₂, hc₂⟩ := (hc₁.add hc₂).is_O
theorem is_o.add (h₁ : is_o f₁ g l) (h₂ : is_o f₂ g l) : is_o (λ x, f₁ x + f₂ x) g l :=
λ c cpos, ((h₁ $ half_pos cpos).add (h₂ $ half_pos cpos)).congr_const (add_halves c)
theorem is_O.add_is_o (h₁ : is_O f₁ g l) (h₂ : is_o f₂ g l) : is_O (λ x, f₁ x + f₂ x) g l :=
h₁.add h₂.is_O
theorem is_o.add_is_O (h₁ : is_o f₁ g l) (h₂ : is_O f₂ g l) : is_O (λ x, f₁ x + f₂ x) g l :=
h₁.is_O.add h₂
theorem is_O_with.add_is_o (h₁ : is_O_with c₁ f₁ g l) (h₂ : is_o f₂ g l) (hc : c₁ < c₂) :
is_O_with c₂ (λx, f₁ x + f₂ x) g l :=
(h₁.add (h₂ (sub_pos.2 hc))).congr_const (add_sub_cancel'_right _ _)
theorem is_o.add_is_O_with (h₁ : is_o f₁ g l) (h₂ : is_O_with c₁ f₂ g l) (hc : c₁ < c₂) :
is_O_with c₂ (λx, f₁ x + f₂ x) g l :=
(h₂.add_is_o h₁ hc).congr_left $ λ _, add_comm _ _
theorem is_O_with.sub (h₁ : is_O_with c₁ f₁ g l) (h₂ : is_O_with c₂ f₂ g l) :
is_O_with (c₁ + c₂) (λ x, f₁ x - f₂ x) g l :=
h₁.add h₂.neg_left
theorem is_O_with.sub_is_o (h₁ : is_O_with c₁ f₁ g l) (h₂ : is_o f₂ g l) (hc : c₁ < c₂) :
is_O_with c₂ (λ x, f₁ x - f₂ x) g l :=
h₁.add_is_o h₂.neg_left hc
theorem is_O.sub (h₁ : is_O f₁ g l) (h₂ : is_O f₂ g l) : is_O (λ x, f₁ x - f₂ x) g l :=
h₁.add h₂.neg_left
theorem is_o.sub (h₁ : is_o f₁ g l) (h₂ : is_o f₂ g l) : is_o (λ x, f₁ x - f₂ x) g l :=
h₁.add h₂.neg_left
end add_sub
/-! ### Lemmas about `is_O (f₁ - f₂) g l` / `is_o (f₁ - f₂) g l` treated as a binary relation -/
section is_oO_as_rel
variables {f₁ f₂ f₃ : α → E'}
theorem is_O_with.symm (h : is_O_with c (λ x, f₁ x - f₂ x) g l) :
is_O_with c (λ x, f₂ x - f₁ x) g l :=
h.neg_left.congr_left $ λ x, neg_sub _ _
theorem is_O_with_comm :
is_O_with c (λ x, f₁ x - f₂ x) g l ↔ is_O_with c (λ x, f₂ x - f₁ x) g l :=
⟨is_O_with.symm, is_O_with.symm⟩
theorem is_O.symm (h : is_O (λ x, f₁ x - f₂ x) g l) : is_O (λ x, f₂ x - f₁ x) g l :=
h.neg_left.congr_left $ λ x, neg_sub _ _
theorem is_O_comm : is_O (λ x, f₁ x - f₂ x) g l ↔ is_O (λ x, f₂ x - f₁ x) g l :=
⟨is_O.symm, is_O.symm⟩
theorem is_o.symm (h : is_o (λ x, f₁ x - f₂ x) g l) : is_o (λ x, f₂ x - f₁ x) g l :=
by simpa only [neg_sub] using h.neg_left
theorem is_o_comm : is_o (λ x, f₁ x - f₂ x) g l ↔ is_o (λ x, f₂ x - f₁ x) g l :=
⟨is_o.symm, is_o.symm⟩
theorem is_O_with.triangle (h₁ : is_O_with c (λ x, f₁ x - f₂ x) g l)
(h₂ : is_O_with c' (λ x, f₂ x - f₃ x) g l) :
is_O_with (c + c') (λ x, f₁ x - f₃ x) g l :=
(h₁.add h₂).congr_left $ λ x, sub_add_sub_cancel _ _ _
theorem is_O.triangle (h₁ : is_O (λ x, f₁ x - f₂ x) g l) (h₂ : is_O (λ x, f₂ x - f₃ x) g l) :
is_O (λ x, f₁ x - f₃ x) g l :=
(h₁.add h₂).congr_left $ λ x, sub_add_sub_cancel _ _ _
theorem is_o.triangle (h₁ : is_o (λ x, f₁ x - f₂ x) g l) (h₂ : is_o (λ x, f₂ x - f₃ x) g l) :
is_o (λ x, f₁ x - f₃ x) g l :=
(h₁.add h₂).congr_left $ λ x, sub_add_sub_cancel _ _ _
theorem is_O.congr_of_sub (h : is_O (λ x, f₁ x - f₂ x) g l) :
is_O f₁ g l ↔ is_O f₂ g l :=
⟨λ h', (h'.sub h).congr_left (λ x, sub_sub_cancel _ _),
λ h', (h.add h').congr_left (λ x, sub_add_cancel _ _)⟩
theorem is_o.congr_of_sub (h : is_o (λ x, f₁ x - f₂ x) g l) :
is_o f₁ g l ↔ is_o f₂ g l :=
⟨λ h', (h'.sub h).congr_left (λ x, sub_sub_cancel _ _),
λ h', (h.add h').congr_left (λ x, sub_add_cancel _ _)⟩
end is_oO_as_rel
/-! ### Zero, one, and other constants -/
section zero_const
variables (g' l)
theorem is_o_zero : is_o (λ x, (0 : E')) g' l :=
λ c hc, univ_mem_sets' $ λ x, by simpa using mul_nonneg (le_of_lt hc) (norm_nonneg $ g' x)
theorem is_O_with_zero (hc : 0 < c) : is_O_with c (λ x, (0 : E')) g' l :=
(is_o_zero g' l) hc
theorem is_O_zero : is_O (λ x, (0 : E')) g' l := (is_o_zero g' l).is_O
theorem is_O_refl_left : is_O (λ x, f' x - f' x) g' l :=
(is_O_zero g' l).congr_left $ λ x, (sub_self _).symm
theorem is_o_refl_left : is_o (λ x, f' x - f' x) g' l :=
(is_o_zero g' l).congr_left $ λ x, (sub_self _).symm
variables {g' l}
theorem is_O_with_zero_right_iff :
is_O_with c f' (λ x, (0 : F')) l ↔ ∀ᶠ x in l, f' x = 0 :=
by simp only [is_O_with, exists_prop, true_and, norm_zero, mul_zero, norm_le_zero_iff]
theorem is_O_zero_right_iff : is_O f' (λ x, (0 : F')) l ↔ ∀ᶠ x in l, f' x = 0 :=
⟨λ h, let ⟨c, hc⟩ := h in (is_O_with_zero_right_iff).1 hc,
λ h, (is_O_with_zero_right_iff.2 h : is_O_with 1 _ _ _).is_O⟩
theorem is_o_zero_right_iff :
is_o f' (λ x, (0 : F')) l ↔ ∀ᶠ x in l, f' x = 0 :=
⟨λ h, is_O_zero_right_iff.1 h.is_O,
λ h c hc, is_O_with_zero_right_iff.2 h⟩
theorem is_O_with_const_const (c : E) {c' : F'} (hc' : c' ≠ 0) (l : filter α) :
is_O_with (∥c∥ / ∥c'∥) (λ x : α, c) (λ x, c') l :=
begin
apply univ_mem_sets',
intro x,
rw [mem_set_of_eq, div_mul_cancel],
rwa [ne.def, norm_eq_zero]
end
theorem is_O_const_const (c : E) {c' : F'} (hc' : c' ≠ 0) (l : filter α) :
is_O (λ x : α, c) (λ x, c') l :=
(is_O_with_const_const c hc' l).is_O
end zero_const
theorem is_O_with_const_one (c : E) (l : filter α) : is_O_with ∥c∥ (λ x : α, c) (λ x, (1 : 𝕜)) l :=
begin
refine (is_O_with_const_const c _ l).congr_const _,
{ rw [normed_field.norm_one, div_one] },
{ exact one_ne_zero }
end
theorem is_O_const_one (c : E) (l : filter α) : is_O (λ x : α, c) (λ x, (1 : 𝕜)) l :=
(is_O_with_const_one c l).is_O
section
variable (𝕜)
theorem is_o_const_iff_is_o_one {c : F'} (hc : c ≠ 0) :
is_o f (λ x, c) l ↔ is_o f (λ x, (1:𝕜)) l :=
⟨λ h, h.trans_is_O $ is_O_const_one c l, λ h, h.trans_is_O $ is_O_const_const _ hc _⟩
end
theorem is_o_const_iff {c : F'} (hc : c ≠ 0) :
is_o f' (λ x, c) l ↔ tendsto f' l (𝓝 0) :=
(is_o_const_iff_is_o_one ℝ hc).trans
begin
clear hc c,
simp only [is_o, is_O_with, normed_field.norm_one, mul_one, normed_group.tendsto_nhds_zero],
-- Now the only difference is `≤` vs `<`
split,
{ intros h ε hε0,
apply mem_sets_of_superset (h (half_pos hε0)),
intros x hx,
simp only [mem_set_of_eq] at hx ⊢,
exact lt_of_le_of_lt hx (half_lt_self hε0) },
{ intros h ε hε0,
apply mem_sets_of_superset (h ε hε0),
intros x hx,
simp only [mem_set_of_eq] at hx ⊢,
exact le_of_lt hx }
end
theorem is_O_const_of_tendsto {y : E'} (h : tendsto f' l (𝓝 y)) {c : F'} (hc : c ≠ 0) :
is_O f' (λ x, c) l :=
begin
refine is_O.trans _ (is_O_const_const (∥y∥ + 1) hc l),
use 1,
simp only [is_O_with, one_mul],
have : tendsto (λx, ∥f' x∥) l (𝓝 ∥y∥), from (continuous_norm.tendsto _).comp h,
have Iy : ∥y∥ < ∥∥y∥ + 1∥, from lt_of_lt_of_le (lt_add_one _) (le_abs_self _),
exact this (ge_mem_nhds Iy)
end
section
variable (𝕜)
theorem is_o_one_iff : is_o f' (λ x, (1 : 𝕜)) l ↔ tendsto f' l (𝓝 0) :=
is_o_const_iff one_ne_zero
theorem is_O_one_of_tendsto {y : E'} (h : tendsto f' l (𝓝 y)) :
is_O f' (λ x, (1:𝕜)) l :=
is_O_const_of_tendsto h one_ne_zero
theorem is_O.trans_tendsto_nhds (hfg : is_O f g' l) {y : F'} (hg : tendsto g' l (𝓝 y)) :
is_O f (λ x, (1:𝕜)) l :=
hfg.trans $ is_O_one_of_tendsto 𝕜 hg
end
theorem is_O.trans_tendsto (hfg : is_O f' g' l) (hg : tendsto g' l (𝓝 0)) :
tendsto f' l (𝓝 0) :=
(is_o_one_iff ℝ).1 $ hfg.trans_is_o $ (is_o_one_iff ℝ).2 hg
theorem is_o.trans_tendsto (hfg : is_o f' g' l) (hg : tendsto g' l (𝓝 0)) :
tendsto f' l (𝓝 0) :=
hfg.is_O.trans_tendsto hg
/-! ### Multiplication by a constant -/
theorem is_O_with_const_mul_self (c : R) (f : α → R) (l : filter α) :
is_O_with ∥c∥ (λ x, c * f x) f l :=
is_O_with_of_le' _ $ λ x, norm_mul_le _ _
theorem is_O_const_mul_self (c : R) (f : α → R) (l : filter α) :
is_O (λ x, c * f x) f l :=
(is_O_with_const_mul_self c f l).is_O
theorem is_O_with.const_mul_left {f : α → R} (h : is_O_with c f g l) (c' : R) :
is_O_with (∥c'∥ * c) (λ x, c' * f x) g l :=
(is_O_with_const_mul_self c' f l).trans h (norm_nonneg c')
theorem is_O.const_mul_left {f : α → R} (h : is_O f g l) (c' : R) :
is_O (λ x, c' * f x) g l :=
let ⟨c, hc⟩ := h in (hc.const_mul_left c').is_O
theorem is_O_with_self_const_mul' (u : units R) (f : α → R) (l : filter α) :
is_O_with ∥(↑u⁻¹:R)∥ f (λ x, ↑u * f x) l :=
(is_O_with_const_mul_self ↑u⁻¹ _ l).congr_left $ λ x, u.inv_mul_cancel_left (f x)
theorem is_O_with_self_const_mul (c : 𝕜) (hc : c ≠ 0) (f : α → 𝕜) (l : filter α) :
is_O_with ∥c∥⁻¹ f (λ x, c * f x) l :=
(is_O_with_self_const_mul' (units.mk0 c hc) f l).congr_const $
normed_field.norm_inv c
theorem is_O_self_const_mul' {c : R} (hc : is_unit c) (f : α → R) (l : filter α) :
is_O f (λ x, c * f x) l :=
let ⟨u, hu⟩ := hc in hu.symm ▸ (is_O_with_self_const_mul' u f l).is_O
theorem is_O_self_const_mul (c : 𝕜) (hc : c ≠ 0) (f : α → 𝕜) (l : filter α) :
is_O f (λ x, c * f x) l :=
is_O_self_const_mul' (is_unit.mk0 c hc) f l
theorem is_O_const_mul_left_iff' {f : α → R} {c : R} (hc : is_unit c) :
is_O (λ x, c * f x) g l ↔ is_O f g l :=
⟨(is_O_self_const_mul' hc f l).trans, λ h, h.const_mul_left c⟩
theorem is_O_const_mul_left_iff {f : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) :
is_O (λ x, c * f x) g l ↔ is_O f g l :=
is_O_const_mul_left_iff' $ is_unit.mk0 c hc
theorem is_o.const_mul_left {f : α → R} (h : is_o f g l) (c : R) :
is_o (λ x, c * f x) g l :=
(is_O_const_mul_self c f l).trans_is_o h
theorem is_o_const_mul_left_iff' {f : α → R} {c : R} (hc : is_unit c) :
is_o (λ x, c * f x) g l ↔ is_o f g l :=
⟨(is_O_self_const_mul' hc f l).trans_is_o, λ h, h.const_mul_left c⟩
theorem is_o_const_mul_left_iff {f : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) :
is_o (λ x, c * f x) g l ↔ is_o f g l :=
is_o_const_mul_left_iff' $ is_unit.mk0 c hc
theorem is_O_with.of_const_mul_right {g : α → R} {c : R} (hc' : 0 ≤ c')
(h : is_O_with c' f (λ x, c * g x) l) :
is_O_with (c' * ∥c∥) f g l :=
h.trans (is_O_with_const_mul_self c g l) hc'
theorem is_O.of_const_mul_right {g : α → R} {c : R}
(h : is_O f (λ x, c * g x) l) :
is_O f g l :=
let ⟨c, cnonneg, hc⟩ := h.exists_nonneg in (hc.of_const_mul_right cnonneg).is_O
theorem is_O_with.const_mul_right' {g : α → R} {u : units R} {c' : ℝ} (hc' : 0 ≤ c')
(h : is_O_with c' f g l) :
is_O_with (c' * ∥(↑u⁻¹:R)∥) f (λ x, ↑u * g x) l :=
h.trans (is_O_with_self_const_mul' _ _ _) hc'
theorem is_O_with.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0)
{c' : ℝ} (hc' : 0 ≤ c') (h : is_O_with c' f g l) :
is_O_with (c' * ∥c∥⁻¹) f (λ x, c * g x) l :=
h.trans (is_O_with_self_const_mul c hc g l) hc'
theorem is_O.const_mul_right' {g : α → R} {c : R} (hc : is_unit c) (h : is_O f g l) :
is_O f (λ x, c * g x) l :=
h.trans (is_O_self_const_mul' hc g l)
theorem is_O.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) (h : is_O f g l) :
is_O f (λ x, c * g x) l :=
h.const_mul_right' $ is_unit.mk0 c hc
theorem is_O_const_mul_right_iff' {g : α → R} {c : R} (hc : is_unit c) :
is_O f (λ x, c * g x) l ↔ is_O f g l :=
⟨λ h, h.of_const_mul_right, λ h, h.const_mul_right' hc⟩
theorem is_O_const_mul_right_iff {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) :
is_O f (λ x, c * g x) l ↔ is_O f g l :=
is_O_const_mul_right_iff' $ is_unit.mk0 c hc
theorem is_o.of_const_mul_right {g : α → R} {c : R} (h : is_o f (λ x, c * g x) l) :
is_o f g l :=
h.trans_is_O (is_O_const_mul_self c g l)
theorem is_o.const_mul_right' {g : α → R} {c : R} (hc : is_unit c) (h : is_o f g l) :
is_o f (λ x, c * g x) l :=
h.trans_is_O (is_O_self_const_mul' hc g l)
theorem is_o.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) (h : is_o f g l) :
is_o f (λ x, c * g x) l :=
h.const_mul_right' $ is_unit.mk0 c hc
theorem is_o_const_mul_right_iff' {g : α → R} {c : R} (hc : is_unit c) :
is_o f (λ x, c * g x) l ↔ is_o f g l :=
⟨λ h, h.of_const_mul_right, λ h, h.const_mul_right' hc⟩
theorem is_o_const_mul_right_iff {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) :
is_o f (λ x, c * g x) l ↔ is_o f g l :=
is_o_const_mul_right_iff' $ is_unit.mk0 c hc
/-! ### Multiplication -/
theorem is_O_with.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} {c₁ c₂ : ℝ}
(h₁ : is_O_with c₁ f₁ g₁ l) (h₂ : is_O_with c₂ f₂ g₂ l) :
is_O_with (c₁ * c₂) (λ x, f₁ x * f₂ x) (λ x, g₁ x * g₂ x) l :=
begin
filter_upwards [h₁, h₂], simp only [mem_set_of_eq],
intros x hx₁ hx₂,
apply le_trans (norm_mul_le _ _),
convert mul_le_mul hx₁ hx₂ (norm_nonneg _) (le_trans (norm_nonneg _) hx₁) using 1,
rw normed_field.norm_mul,
ac_refl
end
theorem is_O.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜}
(h₁ : is_O f₁ g₁ l) (h₂ : is_O f₂ g₂ l) :
is_O (λ x, f₁ x * f₂ x) (λ x, g₁ x * g₂ x) l :=
let ⟨c, hc⟩ := h₁, ⟨c', hc'⟩ := h₂ in (hc.mul hc').is_O
theorem is_O.mul_is_o {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜}
(h₁ : is_O f₁ g₁ l) (h₂ : is_o f₂ g₂ l) :
is_o (λ x, f₁ x * f₂ x) (λ x, g₁ x * g₂ x) l :=
begin
intros c cpos,
rcases h₁.exists_pos with ⟨c', c'pos, hc'⟩,
exact (hc'.mul (h₂ (div_pos cpos c'pos))).congr_const (mul_div_cancel' _ (ne_of_gt c'pos))
end
theorem is_o.mul_is_O {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜}
(h₁ : is_o f₁ g₁ l) (h₂ : is_O f₂ g₂ l) :
is_o (λ x, f₁ x * f₂ x) (λ x, g₁ x * g₂ x) l :=
begin
intros c cpos,
rcases h₂.exists_pos with ⟨c', c'pos, hc'⟩,
exact ((h₁ (div_pos cpos c'pos)).mul hc').congr_const (div_mul_cancel _ (ne_of_gt c'pos))
end
theorem is_o.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : is_o f₁ g₁ l) (h₂ : is_o f₂ g₂ l) :
is_o (λ x, f₁ x * f₂ x) (λ x, g₁ x * g₂ x) l :=
h₁.mul_is_O h₂.is_O
/-! ### Scalar multiplication -/
section smul_const
variables [normed_space 𝕜 E']
theorem is_O_with.const_smul_left (h : is_O_with c f' g l) (c' : 𝕜) :
is_O_with (∥c'∥ * c) (λ x, c' • f' x) g l :=
by refine ((h.norm_left.const_mul_left (∥c'∥)).congr _ _ (λ _, rfl)).of_norm_left;
intros; simp only [norm_norm, norm_smul]
theorem is_O_const_smul_left_iff {c : 𝕜} (hc : c ≠ 0) :
is_O (λ x, c • f' x) g l ↔ is_O f' g l :=
begin
have cne0 : ∥c∥ ≠ 0, from mt (norm_eq_zero _).mp hc,
rw [←is_O_norm_left], simp only [norm_smul],
rw [is_O_const_mul_left_iff cne0, is_O_norm_left],
end
theorem is_o_const_smul_left (h : is_o f' g l) (c : 𝕜) :
is_o (λ x, c • f' x) g l :=
begin
refine ((h.norm_left.const_mul_left (∥c∥)).congr_left _).of_norm_left,
exact λ x, (norm_smul _ _).symm
end
theorem is_o_const_smul_left_iff {c : 𝕜} (hc : c ≠ 0) :
is_o (λ x, c • f' x) g l ↔ is_o f' g l :=
begin
have cne0 : ∥c∥ ≠ 0, from mt (norm_eq_zero _).mp hc,
rw [←is_o_norm_left], simp only [norm_smul],
rw [is_o_const_mul_left_iff cne0, is_o_norm_left]
end
theorem is_O_const_smul_right {c : 𝕜} (hc : c ≠ 0) :
is_O f (λ x, c • f' x) l ↔ is_O f f' l :=
begin
have cne0 : ∥c∥ ≠ 0, from mt (norm_eq_zero _).mp hc,
rw [←is_O_norm_right], simp only [norm_smul],
rw [is_O_const_mul_right_iff cne0, is_O_norm_right]
end
theorem is_o_const_smul_right {c : 𝕜} (hc : c ≠ 0) :
is_o f (λ x, c • f' x) l ↔ is_o f f' l :=
begin
have cne0 : ∥c∥ ≠ 0, from mt (norm_eq_zero _).mp hc,
rw [←is_o_norm_right], simp only [norm_smul],
rw [is_o_const_mul_right_iff cne0, is_o_norm_right]
end
end smul_const
section smul
variables [normed_space 𝕜 E'] [normed_space 𝕜 F']
theorem is_O_with.smul {k₁ k₂ : α → 𝕜} (h₁ : is_O_with c k₁ k₂ l) (h₂ : is_O_with c' f' g' l) :
is_O_with (c * c') (λ x, k₁ x • f' x) (λ x, k₂ x • g' x) l :=
by refine ((h₁.norm_norm.mul h₂.norm_norm).congr rfl _ _).of_norm_norm;
by intros; simp only [norm_smul]
theorem is_O.smul {k₁ k₂ : α → 𝕜} (h₁ : is_O k₁ k₂ l) (h₂ : is_O f' g' l) :
is_O (λ x, k₁ x • f' x) (λ x, k₂ x • g' x) l :=
by refine ((h₁.norm_norm.mul h₂.norm_norm).congr _ _).of_norm_norm;
by intros; simp only [norm_smul]
theorem is_O.smul_is_o {k₁ k₂ : α → 𝕜} (h₁ : is_O k₁ k₂ l) (h₂ : is_o f' g' l) :
is_o (λ x, k₁ x • f' x) (λ x, k₂ x • g' x) l :=
by refine ((h₁.norm_norm.mul_is_o h₂.norm_norm).congr _ _).of_norm_norm;
by intros; simp only [norm_smul]
theorem is_o.smul_is_O {k₁ k₂ : α → 𝕜} (h₁ : is_o k₁ k₂ l) (h₂ : is_O f' g' l) :
is_o (λ x, k₁ x • f' x) (λ x, k₂ x • g' x) l :=
by refine ((h₁.norm_norm.mul_is_O h₂.norm_norm).congr _ _).of_norm_norm;
by intros; simp only [norm_smul]
theorem is_o.smul {k₁ k₂ : α → 𝕜} (h₁ : is_o k₁ k₂ l) (h₂ : is_o f' g' l) :
is_o (λ x, k₁ x • f' x) (λ x, k₂ x • g' x) l :=
by refine ((h₁.norm_norm.mul h₂.norm_norm).congr _ _).of_norm_norm;
by intros; simp only [norm_smul]
end smul
/-! ### Relation between `f = o(g)` and `f / g → 0` -/
theorem is_o.tendsto_0 {f g : α → 𝕜} {l : filter α} (h : is_o f g l) :
tendsto (λ x, f x / (g x)) l (𝓝 0) :=
have eq₁ : is_o (λ x, f x / g x) (λ x, g x / g x) l,
from h.mul_is_O (is_O_refl _ _),
have eq₂ : is_O (λ x, g x / g x) (λ x, (1 : 𝕜)) l,
from is_O_of_le _ (λ x, by by_cases h : ∥g x∥ = 0; simp [h, zero_le_one]),
(is_o_one_iff 𝕜).mp (eq₁.trans_is_O eq₂)
private theorem is_o_of_tendsto {f g : α → 𝕜} {l : filter α}
(hgf : ∀ x, g x = 0 → f x = 0) (h : tendsto (λ x, f x / (g x)) l (𝓝 0)) :
is_o f g l :=
have eq₁ : is_o (λ x, f x / (g x)) (λ x, (1 : 𝕜)) l,
from (is_o_one_iff _).mpr h,
have eq₂ : is_o (λ x, f x / g x * g x) g l,
by convert eq₁.mul_is_O (is_O_refl _ _); simp,
have eq₃ : is_O f (λ x, f x / g x * g x) l,
begin
refine is_O_of_le _ (λ x, _),
by_cases H : g x = 0,
{ simp only [H, hgf _ H, mul_zero] },
{ simp only [div_mul_cancel _ H] }
end,
eq₃.trans_is_o eq₂
theorem is_o_iff_tendsto {f g : α → 𝕜} {l : filter α}
(hgf : ∀ x, g x = 0 → f x = 0) :
is_o f g l ↔ tendsto (λ x, f x / (g x)) l (𝓝 0) :=
iff.intro is_o.tendsto_0 (is_o_of_tendsto hgf)
/-! ### Miscellanous lemmas -/
theorem is_o_pow_pow {m n : ℕ} (h : m < n) :
is_o (λ(x : 𝕜), x^n) (λx, x^m) (𝓝 0) :=
begin
let p := n - m,
have nmp : n = m + p := (nat.add_sub_cancel' (le_of_lt h)).symm,
have : (λ(x : 𝕜), x^m) = (λx, x^m * 1), by simp only [mul_one],
simp only [this, pow_add, nmp],
refine is_O.mul_is_o (is_O_refl _ _) ((is_o_one_iff _).2 _),
convert (continuous_pow p).tendsto (0 : 𝕜),
exact (zero_pow (nat.sub_pos_of_lt h)).symm
end
theorem is_o_pow_id {n : ℕ} (h : 1 < n) :
is_o (λ(x : 𝕜), x^n) (λx, x) (𝓝 0) :=
by { convert is_o_pow_pow h, simp only [pow_one] }
theorem is_O_with.right_le_sub_of_lt_1 {f₁ f₂ : α → E'} (h : is_O_with c f₁ f₂ l) (hc : c < 1) :
is_O_with (1 / (1 - c)) f₂ (λx, f₂ x - f₁ x) l :=
mem_sets_of_superset h $ λ x hx,
begin
simp only [mem_set_of_eq] at hx ⊢,
rw [mul_comm, one_div_eq_inv, ← div_eq_mul_inv, le_div_iff, mul_sub, mul_one, mul_comm],
{ exact le_trans (sub_le_sub_left hx _) (norm_sub_norm_le _ _) },
{ exact sub_pos.2 hc }
end
theorem is_O_with.right_le_add_of_lt_1 {f₁ f₂ : α → E'} (h : is_O_with c f₁ f₂ l) (hc : c < 1) :
is_O_with (1 / (1 - c)) f₂ (λx, f₁ x + f₂ x) l :=
(h.neg_right.right_le_sub_of_lt_1 hc).neg_right.neg_left.congr rfl (λ x, neg_neg _)
(λ x, by rw [neg_sub, sub_neg_eq_add])
end asymptotics
|
3a5dcaf67326e5ddfbcb1cbbc74f81207d39f679 | 64874bd1010548c7f5a6e3e8902efa63baaff785 | /tests/lean/run/class5.lean | 23a89b7f6f5578ebd5fe19714a4b6fc6dc9e98c5 | [
"Apache-2.0"
] | permissive | tjiaqi/lean | 4634d729795c164664d10d093f3545287c76628f | d0ce4cf62f4246b0600c07e074d86e51f2195e30 | refs/heads/master | 1,622,323,796,480 | 1,422,643,069,000 | 1,422,643,069,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,359 | lean | import logic
namespace experiment
namespace algebra
inductive mul_struct [class] (A : Type) : Type :=
mk : (A → A → A) → mul_struct A
definition mul {A : Type} [s : mul_struct A] (a b : A)
:= mul_struct.rec (λ f, f) s a b
infixl `*` := mul
end algebra
open algebra
namespace nat
inductive nat : Type :=
zero : nat,
succ : nat → nat
constant mul : nat → nat → nat
constant add : nat → nat → nat
definition mul_struct [instance] : algebra.mul_struct nat
:= algebra.mul_struct.mk mul
end nat
section
open algebra nat
variables a b c : nat
check a * b * c
definition tst1 : nat := a * b * c
end
section
open [notation] algebra
open nat
-- check mul_struct nat << This is an error, we opened only the notation from algebra
variables a b c : nat
check a * b * c
definition tst2 : nat := a * b * c
end
section
open nat
-- check mul_struct nat << This is an error, we opened only the notation from algebra
variables a b c : nat
check a*b*c
definition tst3 : nat := #nat a*b*c
end
section
open nat
set_option pp.implicit true
definition add_struct [instance] : algebra.mul_struct nat
:= algebra.mul_struct.mk add
variables a b c : nat
check #experiment.algebra a*b*c -- << is open add instead of mul
definition tst4 : nat := #experiment.algebra a*b*c
end
end experiment
|
514c7e9ab044b85a8f063f16daaae284fde301d9 | c86b74188c4b7a462728b1abd659ab4e5828dd61 | /stage0/src/Init/Data/Hashable.lean | 4a4188851444b489661c3864d4cc69fb3fc4032e | [
"Apache-2.0"
] | permissive | cwb96/lean4 | 75e1f92f1ba98bbaa6b34da644b3dfab2ce7bf89 | b48831cda76e64f13dd1c0edde7ba5fb172ed57a | refs/heads/master | 1,686,347,881,407 | 1,624,483,842,000 | 1,624,483,842,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,039 | 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.UInt
import Init.Data.String
universes u
instance : Hashable Nat where
hash n := UInt64.ofNat n
instance [Hashable α] [Hashable β] : Hashable (α × β) where
hash | (a, b) => mixHash (hash a) (hash b)
instance : Hashable Bool where
hash
| true => 11
| false => 13
instance [Hashable α] : Hashable (Option α) where
hash
| none => 11
| some a => mixHash (hash a) 13
instance [Hashable α] : Hashable (List α) where
hash as := as.foldl (fun r a => mixHash r (hash a)) 7
instance : Hashable UInt32 where
hash n := n.toUInt64
instance : Hashable UInt64 where
hash n := n
instance : Hashable USize where
hash n := n.toUInt64
instance : Hashable Int where
hash
| Int.ofNat n => UInt64.ofNat (2 * n)
| Int.negSucc n => UInt64.ofNat (2 * n + 1)
instance (P : Prop) : Hashable P where
hash p := 0
|
a4174685b6bed307e62c9562be34f5a5e9297052 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/algebra/algebra/basic.lean | 9194f766831e193704e3a29130d8497a02bfbde3 | [
"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 | 71,959 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Yury Kudryashov
-/
import algebra.module.basic
import algebra.module.ulift
import algebra.ne_zero
import algebra.ring.aut
import algebra.ring.ulift
import algebra.char_zero.lemmas
import linear_algebra.span
import tactic.abel
/-!
# Algebras over commutative semirings
In this file we define associative unital `algebra`s over commutative (semi)rings, algebra
homomorphisms `alg_hom`, and algebra equivalences `alg_equiv`.
`subalgebra`s are defined in `algebra.algebra.subalgebra`.
For the category of `R`-algebras, denoted `Algebra R`, see the file
`algebra/category/Algebra/basic.lean`.
See the implementation notes for remarks about non-associative and non-unital algebras.
## Main definitions:
* `algebra R A`: the algebra typeclass.
* `alg_hom R A B`: the type of `R`-algebra morphisms from `A` to `B`.
* `alg_equiv R A B`: the type of `R`-algebra isomorphisms between `A` to `B`.
* `algebra_map R A : R →+* A`: the canonical map from `R` to `A`, as a `ring_hom`. This is the
preferred spelling of this map.
* `algebra.linear_map R A : R →ₗ[R] A`: the canonical map from `R` to `A`, as a `linear_map`.
* `algebra.of_id R A : R →ₐ[R] A`: the canonical map from `R` to `A`, as n `alg_hom`.
* Instances of `algebra` in this file:
* `algebra.id`
* `pi.algebra`
* `prod.algebra`
* `algebra_nat`
* `algebra_int`
* `algebra_rat`
* `mul_opposite.algebra`
* `module.End.algebra`
## Notations
* `A →ₐ[R] B` : `R`-algebra homomorphism from `A` to `B`.
* `A ≃ₐ[R] B` : `R`-algebra equivalence from `A` to `B`.
## Implementation notes
Given a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a
(possibly noncommutative) (semi)ring `A`:
* By endowing `A` with a morphism of rings `R →+* A` denoted `algebra_map R A` which lands in the
center of `A`.
* By requiring `A` be an `R`-module such that the action associates and commutes with multiplication
as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`.
We define `algebra R A` in a way that subsumes both definitions, by extending `has_smul R A` and
requiring that this scalar action `r • x` must agree with left multiplication by the image of the
structure morphism `algebra_map R A r * x`.
As a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring:
1. ```lean
variables [comm_semiring R] [semiring A]
variables [algebra R A]
```
2. ```lean
variables [comm_semiring R] [semiring A]
variables [module R A] [smul_comm_class R A A] [is_scalar_tower R A A]
```
The first approach implies the second via typeclass search; so any lemma stated with the second set
of arguments will automatically apply to the first set. Typeclass search does not know that the
second approach implies the first, but this can be shown with:
```lean
example {R A : Type*} [comm_semiring R] [semiring A]
[module R A] [smul_comm_class R A A] [is_scalar_tower R A A] : algebra R A :=
algebra.of_module smul_mul_assoc mul_smul_comm
```
The advantage of the first approach is that `algebra_map R A` is available, and `alg_hom R A B` and
`subalgebra R A` can be used. For concrete `R` and `A`, `algebra_map R A` is often definitionally
convenient.
The advantage of the second approach is that `comm_semiring R`, `semiring A`, and `module R A` can
all be relaxed independently; for instance, this allows us to:
* Replace `semiring A` with `non_unital_non_assoc_semiring A` in order to describe non-unital and/or
non-associative algebras.
* Replace `comm_semiring R` and `module R A` with `comm_group R'` and `distrib_mul_action R' A`,
which when `R' = Rˣ` lets us talk about the "algebra-like" action of `Rˣ` on an
`R`-algebra `A`.
While `alg_hom R A B` cannot be used in the second approach, `non_unital_alg_hom R A B` still can.
You should always use the first approach when working with associative unital algebras, and mimic
the second approach only when you need to weaken a condition on either `R` or `A`.
-/
universes u v w u₁ v₁
open_locale big_operators
section prio
-- We set this priority to 0 later in this file
set_option extends_priority 200 /- control priority of
`instance [algebra R A] : has_smul R A` -/
/--
An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`.
See the implementation notes in this file for discussion of the details of this definition.
-/
@[nolint has_nonempty_instance]
class algebra (R : Type u) (A : Type v) [comm_semiring R] [semiring A]
extends has_smul R A, R →+* A :=
(commutes' : ∀ r x, to_fun r * x = x * to_fun r)
(smul_def' : ∀ r x, r • x = to_fun r * x)
end prio
/-- Embedding `R →+* A` given by `algebra` structure. -/
def algebra_map (R : Type u) (A : Type v) [comm_semiring R] [semiring A] [algebra R A] : R →+* A :=
algebra.to_ring_hom
namespace algebra_map
def has_lift_t (R A : Type*) [comm_semiring R] [semiring A] [algebra R A] :
has_lift_t R A := ⟨λ r, algebra_map R A r⟩
attribute [instance, priority 900] algebra_map.has_lift_t
section comm_semiring_semiring
variables {R A : Type*} [comm_semiring R] [semiring A] [algebra R A]
@[simp, norm_cast] lemma coe_zero : (↑(0 : R) : A) = 0 := map_zero (algebra_map R A)
@[simp, norm_cast] lemma coe_one : (↑(1 : R) : A) = 1 := map_one (algebra_map R A)
@[norm_cast] lemma coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b :=
map_add (algebra_map R A) a b
@[norm_cast] lemma coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b :=
map_mul (algebra_map R A) a b
@[norm_cast] lemma coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = ↑a ^ n :=
map_pow (algebra_map R A) _ _
end comm_semiring_semiring
section comm_ring_ring
variables {R A : Type*} [comm_ring R] [ring A] [algebra R A]
@[norm_cast] lemma coe_neg (x : R) : (↑(-x : R) : A) = -↑x :=
map_neg (algebra_map R A) x
end comm_ring_ring
section comm_semiring_comm_semiring
variables {R A : Type*} [comm_semiring R] [comm_semiring A] [algebra R A]
open_locale big_operators
-- direct to_additive fails because of some mix-up with polynomials
@[norm_cast] lemma coe_prod {ι : Type*} {s : finset ι} (a : ι → R) :
(↑( ∏ (i : ι) in s, a i : R) : A) = ∏ (i : ι) in s, (↑(a i) : A) :=
map_prod (algebra_map R A) a s
-- to_additive fails for some reason
@[norm_cast] lemma coe_sum {ι : Type*} {s : finset ι} (a : ι → R) :
↑(( ∑ (i : ι) in s, a i)) = ∑ (i : ι) in s, (↑(a i) : A) :=
map_sum (algebra_map R A) a s
attribute [to_additive] coe_prod
end comm_semiring_comm_semiring
section field_nontrivial
variables {R A : Type*} [field R] [comm_semiring A] [nontrivial A] [algebra R A]
@[norm_cast, simp] lemma coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b :=
⟨λ h, (algebra_map R A).injective h, by rintro rfl; refl⟩
@[norm_cast, simp] lemma lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 :=
begin
rw (show (0 : A) = ↑(0 : R), from (map_zero (algebra_map R A)).symm),
norm_cast,
end
end field_nontrivial
end algebra_map
/-- Creating an algebra from a morphism to the center of a semiring. -/
def ring_hom.to_algebra' {R S} [comm_semiring R] [semiring S] (i : R →+* S)
(h : ∀ c x, i c * x = x * i c) :
algebra R S :=
{ smul := λ c x, i c * x,
commutes' := h,
smul_def' := λ c x, rfl,
to_ring_hom := i}
/-- Creating an algebra from a morphism to a commutative semiring. -/
def ring_hom.to_algebra {R S} [comm_semiring R] [comm_semiring S] (i : R →+* S) :
algebra R S :=
i.to_algebra' $ λ _, mul_comm _
lemma ring_hom.algebra_map_to_algebra {R S} [comm_semiring R] [comm_semiring S]
(i : R →+* S) :
@algebra_map R S _ _ i.to_algebra = i :=
rfl
namespace algebra
variables {R : Type u} {S : Type v} {A : Type w} {B : Type*}
/-- Let `R` be a commutative semiring, let `A` be a semiring with a `module R` structure.
If `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `algebra`
over `R`.
See note [reducible non-instances]. -/
@[reducible]
def of_module' [comm_semiring R] [semiring A] [module R A]
(h₁ : ∀ (r : R) (x : A), (r • 1) * x = r • x)
(h₂ : ∀ (r : R) (x : A), x * (r • 1) = r • x) : algebra R A :=
{ to_fun := λ r, r • 1,
map_one' := one_smul _ _,
map_mul' := λ r₁ r₂, by rw [h₁, mul_smul],
map_zero' := zero_smul _ _,
map_add' := λ r₁ r₂, add_smul r₁ r₂ 1,
commutes' := λ r x, by simp only [h₁, h₂],
smul_def' := λ r x, by simp only [h₁] }
/-- Let `R` be a commutative semiring, let `A` be a semiring with a `module R` structure.
If `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`
is an `algebra` over `R`.
See note [reducible non-instances]. -/
@[reducible]
def of_module [comm_semiring R] [semiring A] [module R A]
(h₁ : ∀ (r : R) (x y : A), (r • x) * y = r • (x * y))
(h₂ : ∀ (r : R) (x y : A), x * (r • y) = r • (x * y)) : algebra R A :=
of_module' (λ r x, by rw [h₁, one_mul]) (λ r x, by rw [h₂, mul_one])
section semiring
variables [comm_semiring R] [comm_semiring S]
variables [semiring A] [algebra R A] [semiring B] [algebra R B]
/-- We keep this lemma private because it picks up the `algebra.to_has_smul` instance
which we set to priority 0 shortly. See `smul_def` below for the public version. -/
private lemma smul_def'' (r : R) (x : A) : r • x = algebra_map R A r * x :=
algebra.smul_def' r x
/--
To prove two algebra structures on a fixed `[comm_semiring R] [semiring A]` agree,
it suffices to check the `algebra_map`s agree.
-/
-- We'll later use this to show `algebra ℤ M` is a subsingleton.
@[ext]
lemma algebra_ext {R : Type*} [comm_semiring R] {A : Type*} [semiring A] (P Q : algebra R A)
(w : ∀ (r : R), by { haveI := P, exact algebra_map R A r } =
by { haveI := Q, exact algebra_map R A r }) :
P = Q :=
begin
unfreezingI { rcases P with @⟨⟨P⟩⟩, rcases Q with @⟨⟨Q⟩⟩ },
congr,
{ funext r a,
replace w := congr_arg (λ s, s * a) (w r),
simp only [←smul_def''] at w,
apply w, },
{ ext r,
exact w r, },
{ apply proof_irrel_heq, },
{ apply proof_irrel_heq, },
end
@[priority 200] -- see Note [lower instance priority]
instance to_module : module R A :=
{ one_smul := by simp [smul_def''],
mul_smul := by simp [smul_def'', mul_assoc],
smul_add := by simp [smul_def'', mul_add],
smul_zero := by simp [smul_def''],
add_smul := by simp [smul_def'', add_mul],
zero_smul := by simp [smul_def''] }
-- From now on, we don't want to use the following instance anymore.
-- Unfortunately, leaving it in place causes deterministic timeouts later in mathlib.
attribute [instance, priority 0] algebra.to_has_smul
lemma smul_def (r : R) (x : A) : r • x = algebra_map R A r * x :=
algebra.smul_def' r x
lemma algebra_map_eq_smul_one (r : R) : algebra_map R A r = r • 1 :=
calc algebra_map R A r = algebra_map R A r * 1 : (mul_one _).symm
... = r • 1 : (algebra.smul_def r 1).symm
lemma algebra_map_eq_smul_one' : ⇑(algebra_map R A) = λ r, r • (1 : A) :=
funext algebra_map_eq_smul_one
/-- `mul_comm` for `algebra`s when one element is from the base ring. -/
theorem commutes (r : R) (x : A) : algebra_map R A r * x = x * algebra_map R A r :=
algebra.commutes' r x
/-- `mul_left_comm` for `algebra`s when one element is from the base ring. -/
theorem left_comm (x : A) (r : R) (y : A) :
x * (algebra_map R A r * y) = algebra_map R A r * (x * y) :=
by rw [← mul_assoc, ← commutes, mul_assoc]
/-- `mul_right_comm` for `algebra`s when one element is from the base ring. -/
theorem right_comm (x : A) (r : R) (y : A) :
(x * algebra_map R A r) * y = (x * y) * algebra_map R A r :=
by rw [mul_assoc, commutes, ←mul_assoc]
instance _root_.is_scalar_tower.right : is_scalar_tower R A A :=
⟨λ x y z, by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩
/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass
search (and was here first). -/
@[simp] protected lemma mul_smul_comm (s : R) (x y : A) :
x * (s • y) = s • (x * y) :=
-- TODO: set up `is_scalar_tower.smul_comm_class` earlier so that we can actually prove this using
-- `mul_smul_comm s x y`.
by rw [smul_def, smul_def, left_comm]
/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass
search (and was here first). -/
@[simp] protected lemma smul_mul_assoc (r : R) (x y : A) :
(r • x) * y = r • (x * y) :=
smul_mul_assoc r x y
@[simp]
lemma _root_.smul_algebra_map {α : Type*} [monoid α] [mul_distrib_mul_action α A]
[smul_comm_class α R A] (a : α) (r : R) : a • algebra_map R A r = algebra_map R A r :=
by rw [algebra_map_eq_smul_one, smul_comm a r (1 : A), smul_one]
section
variables {r : R} {a : A}
@[simp] lemma bit0_smul_one : bit0 r • (1 : A) = bit0 (r • (1 : A)) :=
by simp [bit0, add_smul]
lemma bit0_smul_one' : bit0 r • (1 : A) = r • 2 :=
by simp [bit0, add_smul, smul_add]
@[simp] lemma bit0_smul_bit0 : bit0 r • bit0 a = r • (bit0 (bit0 a)) :=
by simp [bit0, add_smul, smul_add]
@[simp] lemma bit0_smul_bit1 : bit0 r • bit1 a = r • (bit0 (bit1 a)) :=
by simp [bit0, add_smul, smul_add]
@[simp] lemma bit1_smul_one : bit1 r • (1 : A) = bit1 (r • (1 : A)) :=
by simp [bit1, add_smul]
lemma bit1_smul_one' : bit1 r • (1 : A) = r • 2 + 1 :=
by simp [bit1, bit0, add_smul, smul_add]
@[simp] lemma bit1_smul_bit0 : bit1 r • bit0 a = r • (bit0 (bit0 a)) + bit0 a :=
by simp [bit1, add_smul, smul_add]
@[simp] lemma bit1_smul_bit1 : bit1 r • bit1 a = r • (bit0 (bit1 a)) + bit1 a :=
by { simp only [bit0, bit1, add_smul, smul_add, one_smul], abel }
end
variables (R A)
/--
The canonical ring homomorphism `algebra_map R A : R →* A` for any `R`-algebra `A`,
packaged as an `R`-linear map.
-/
protected def linear_map : R →ₗ[R] A :=
{ map_smul' := λ x y, by simp [algebra.smul_def],
..algebra_map R A }
@[simp]
lemma linear_map_apply (r : R) : algebra.linear_map R A r = algebra_map R A r := rfl
lemma coe_linear_map : ⇑(algebra.linear_map R A) = algebra_map R A := rfl
instance id : algebra R R := (ring_hom.id R).to_algebra
variables {R A}
namespace id
@[simp] lemma map_eq_id : algebra_map R R = ring_hom.id _ := rfl
lemma map_eq_self (x : R) : algebra_map R R x = x := rfl
@[simp] lemma smul_eq_mul (x y : R) : x • y = x * y := rfl
end id
section punit
instance _root_.punit.algebra : algebra R punit :=
{ to_fun := λ x, punit.star,
map_one' := rfl,
map_mul' := λ _ _, rfl,
map_zero' := rfl,
map_add' := λ _ _, rfl,
commutes' := λ _ _, rfl,
smul_def' := λ _ _, rfl }
@[simp] lemma algebra_map_punit (r : R) : algebra_map R punit r = punit.star := rfl
end punit
section ulift
instance _root_.ulift.algebra : algebra R (ulift A) :=
{ to_fun := λ r, ulift.up (algebra_map R A r),
commutes' := λ r x, ulift.down_injective $ algebra.commutes r x.down,
smul_def' := λ r x, ulift.down_injective $ algebra.smul_def' r x.down,
.. ulift.module',
.. (ulift.ring_equiv : ulift A ≃+* A).symm.to_ring_hom.comp (algebra_map R A) }
lemma _root_.ulift.algebra_map_eq (r : R) :
algebra_map R (ulift A) r = ulift.up (algebra_map R A r) := rfl
@[simp] lemma _root_.ulift.down_algebra_map (r : R) :
(algebra_map R (ulift A) r).down = algebra_map R A r := rfl
end ulift
section prod
variables (R A B)
instance _root_.prod.algebra : algebra R (A × B) :=
{ commutes' := by { rintro r ⟨a, b⟩, dsimp, rw [commutes r a, commutes r b] },
smul_def' := by { rintro r ⟨a, b⟩, dsimp, rw [smul_def r a, smul_def r b] },
.. prod.module,
.. ring_hom.prod (algebra_map R A) (algebra_map R B) }
variables {R A B}
@[simp] lemma algebra_map_prod_apply (r : R) :
algebra_map R (A × B) r = (algebra_map R A r, algebra_map R B r) := rfl
end prod
/-- Algebra over a subsemiring. This builds upon `subsemiring.module`. -/
instance of_subsemiring (S : subsemiring R) : algebra S A :=
{ smul := (•),
commutes' := λ r x, algebra.commutes r x,
smul_def' := λ r x, algebra.smul_def r x,
.. (algebra_map R A).comp S.subtype }
lemma algebra_map_of_subsemiring (S : subsemiring R) :
(algebra_map S R : S →+* R) = subsemiring.subtype S := rfl
lemma coe_algebra_map_of_subsemiring (S : subsemiring R) :
(algebra_map S R : S → R) = subtype.val := rfl
lemma algebra_map_of_subsemiring_apply (S : subsemiring R) (x : S) :
algebra_map S R x = x := rfl
/-- Algebra over a subring. This builds upon `subring.module`. -/
instance of_subring {R A : Type*} [comm_ring R] [ring A] [algebra R A]
(S : subring R) : algebra S A :=
{ smul := (•),
.. algebra.of_subsemiring S.to_subsemiring,
.. (algebra_map R A).comp S.subtype }
lemma algebra_map_of_subring {R : Type*} [comm_ring R] (S : subring R) :
(algebra_map S R : S →+* R) = subring.subtype S := rfl
lemma coe_algebra_map_of_subring {R : Type*} [comm_ring R] (S : subring R) :
(algebra_map S R : S → R) = subtype.val := rfl
lemma algebra_map_of_subring_apply {R : Type*} [comm_ring R] (S : subring R) (x : S) :
algebra_map S R x = x := rfl
/-- Explicit characterization of the submonoid map in the case of an algebra.
`S` is made explicit to help with type inference -/
def algebra_map_submonoid (S : Type*) [semiring S] [algebra R S]
(M : submonoid R) : submonoid S :=
M.map (algebra_map R S)
lemma mem_algebra_map_submonoid_of_mem {S : Type*} [semiring S] [algebra R S] {M : submonoid R}
(x : M) : (algebra_map R S x) ∈ algebra_map_submonoid S M :=
set.mem_image_of_mem (algebra_map R S) x.2
end semiring
section comm_semiring
variables [comm_semiring R]
lemma mul_sub_algebra_map_commutes [ring A] [algebra R A] (x : A) (r : R) :
x * (x - algebra_map R A r) = (x - algebra_map R A r) * x :=
by rw [mul_sub, ←commutes, sub_mul]
lemma mul_sub_algebra_map_pow_commutes [ring A] [algebra R A] (x : A) (r : R) (n : ℕ) :
x * (x - algebra_map R A r) ^ n = (x - algebra_map R A r) ^ n * x :=
begin
induction n with n ih,
{ simp },
{ rw [pow_succ, ←mul_assoc, mul_sub_algebra_map_commutes, mul_assoc, ih, ←mul_assoc] }
end
end comm_semiring
section ring
variables [comm_ring R]
variables (R)
/-- A `semiring` that is an `algebra` over a commutative ring carries a natural `ring` structure.
See note [reducible non-instances]. -/
@[reducible]
def semiring_to_ring [semiring A] [algebra R A] : ring A :=
{ ..module.add_comm_monoid_to_add_comm_group R,
..(infer_instance : semiring A) }
end ring
end algebra
namespace mul_opposite
variables {R A : Type*} [comm_semiring R] [semiring A] [algebra R A]
instance : algebra R Aᵐᵒᵖ :=
{ to_ring_hom := (algebra_map R A).to_opposite $ λ x y, algebra.commutes _ _,
smul_def' := λ c x, unop_injective $
by { dsimp, simp only [op_mul, algebra.smul_def, algebra.commutes, op_unop] },
commutes' := λ r, mul_opposite.rec $ λ x, by dsimp; simp only [← op_mul, algebra.commutes],
.. mul_opposite.has_smul A R }
@[simp] lemma algebra_map_apply (c : R) : algebra_map R Aᵐᵒᵖ c = op (algebra_map R A c) := rfl
end mul_opposite
namespace module
variables (R : Type u) (M : Type v) [comm_semiring R] [add_comm_monoid M] [module R M]
instance : algebra R (module.End R M) :=
algebra.of_module smul_mul_assoc (λ r f g, (smul_comm r f g).symm)
lemma algebra_map_End_eq_smul_id (a : R) :
(algebra_map R (End R M)) a = a • linear_map.id := rfl
@[simp] lemma algebra_map_End_apply (a : R) (m : M) :
(algebra_map R (End R M)) a m = a • m := rfl
@[simp] lemma ker_algebra_map_End (K : Type u) (V : Type v)
[field K] [add_comm_group V] [module K V] (a : K) (ha : a ≠ 0) :
((algebra_map K (End K V)) a).ker = ⊥ :=
linear_map.ker_smul _ _ ha
section
variables {R M}
lemma End_is_unit_apply_inv_apply_of_is_unit {f : module.End R M} (h : is_unit f) (x : M) :
f (h.unit.inv x) = x :=
show (f * h.unit.inv) x = x, by simp
lemma End_is_unit_inv_apply_apply_of_is_unit {f : module.End R M} (h : is_unit f) (x : M) :
h.unit.inv (f x) = x :=
(by simp : (h.unit.inv * f) x = x)
lemma End_is_unit_iff (f : module.End R M) :
is_unit f ↔ function.bijective f :=
⟨λ h, function.bijective_iff_has_inverse.mpr $
⟨h.unit.inv, ⟨End_is_unit_inv_apply_apply_of_is_unit h,
End_is_unit_apply_inv_apply_of_is_unit h⟩⟩,
λ H, let e : M ≃ₗ[R] M := { ..f, ..(equiv.of_bijective f H)} in
⟨⟨_, e.symm, linear_map.ext e.right_inv, linear_map.ext e.left_inv⟩, rfl⟩⟩
lemma End_algebra_map_is_unit_inv_apply_eq_iff
{x : R} (h : is_unit (algebra_map R (module.End R M) x)) (m m' : M) :
h.unit⁻¹ m = m' ↔ m = x • m' :=
{ mp := λ H, ((congr_arg h.unit H).symm.trans (End_is_unit_apply_inv_apply_of_is_unit h _)).symm,
mpr := λ H, H.symm ▸
begin
apply_fun h.unit using ((module.End_is_unit_iff _).mp h).injective,
erw [End_is_unit_apply_inv_apply_of_is_unit],
refl,
end }
lemma End_algebra_map_is_unit_inv_apply_eq_iff'
{x : R} (h : is_unit (algebra_map R (module.End R M) x)) (m m' : M) :
m' = h.unit⁻¹ m ↔ m = x • m' :=
{ mp := λ H, ((congr_arg h.unit H).trans (End_is_unit_apply_inv_apply_of_is_unit h _)).symm,
mpr := λ H, H.symm ▸
begin
apply_fun h.unit using ((module.End_is_unit_iff _).mp h).injective,
erw [End_is_unit_apply_inv_apply_of_is_unit],
refl,
end }
end
end module
namespace linear_map
variables {R : Type*} {A : Type*} {B : Type*} [comm_semiring R] [semiring A] [semiring B]
[algebra R A] [algebra R B]
/-- An alternate statement of `linear_map.map_smul` for when `algebra_map` is more convenient to
work with than `•`. -/
lemma map_algebra_map_mul (f : A →ₗ[R] B) (a : A) (r : R) :
f (algebra_map R A r * a) = algebra_map R B r * f a :=
by rw [←algebra.smul_def, ←algebra.smul_def, map_smul]
lemma map_mul_algebra_map (f : A →ₗ[R] B) (a : A) (r : R) :
f (a * algebra_map R A r) = f a * algebra_map R B r :=
by rw [←algebra.commutes, ←algebra.commutes, map_algebra_map_mul]
end linear_map
set_option old_structure_cmd true
/-- Defining the homomorphism in the category R-Alg. -/
@[nolint has_nonempty_instance]
structure alg_hom (R : Type u) (A : Type v) (B : Type w)
[comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B] extends ring_hom A B :=
(commutes' : ∀ r : R, to_fun (algebra_map R A r) = algebra_map R B r)
run_cmd tactic.add_doc_string `alg_hom.to_ring_hom "Reinterpret an `alg_hom` as a `ring_hom`"
infixr ` →ₐ `:25 := alg_hom _
notation A ` →ₐ[`:25 R `] ` B := alg_hom R A B
/-- `alg_hom_class F R A B` asserts `F` is a type of bundled algebra homomorphisms
from `A` to `B`. -/
class alg_hom_class (F : Type*) (R : out_param Type*) (A : out_param Type*) (B : out_param Type*)
[comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B]
extends ring_hom_class F A B :=
(commutes : ∀ (f : F) (r : R), f (algebra_map R A r) = algebra_map R B r)
-- `R` becomes a metavariable but that's fine because it's an `out_param`
attribute [nolint dangerous_instance] alg_hom_class.to_ring_hom_class
attribute [simp] alg_hom_class.commutes
namespace alg_hom_class
variables {R : Type*} {A : Type*} {B : Type*} [comm_semiring R] [semiring A] [semiring B]
[algebra R A] [algebra R B]
@[priority 100] -- see Note [lower instance priority]
instance {F : Type*} [alg_hom_class F R A B] : linear_map_class F R A B :=
{ map_smulₛₗ := λ f r x, by simp only [algebra.smul_def, map_mul, commutes, ring_hom.id_apply],
..‹alg_hom_class F R A B› }
instance {F : Type*} [alg_hom_class F R A B] : has_coe_t F (A →ₐ[R] B) :=
{ coe := λ f,
{ to_fun := f,
commutes' := alg_hom_class.commutes f,
.. (f : A →+* B) } }
end alg_hom_class
namespace alg_hom
variables {R : Type u} {A : Type v} {B : Type w} {C : Type u₁} {D : Type v₁}
section semiring
variables [comm_semiring R] [semiring A] [semiring B] [semiring C] [semiring D]
variables [algebra R A] [algebra R B] [algebra R C] [algebra R D]
instance : has_coe_to_fun (A →ₐ[R] B) (λ _, A → B) := ⟨alg_hom.to_fun⟩
initialize_simps_projections alg_hom (to_fun → apply)
@[simp, protected] lemma coe_coe {F : Type*} [alg_hom_class F R A B] (f : F) :
⇑(f : A →ₐ[R] B) = f := rfl
@[simp] lemma to_fun_eq_coe (f : A →ₐ[R] B) : f.to_fun = f := rfl
instance : alg_hom_class (A →ₐ[R] B) R A B :=
{ coe := to_fun,
coe_injective' := λ f g h, by { cases f, cases g, congr' },
map_add := map_add',
map_zero := map_zero',
map_mul := map_mul',
map_one := map_one',
commutes := λ f, f.commutes' }
instance coe_ring_hom : has_coe (A →ₐ[R] B) (A →+* B) := ⟨alg_hom.to_ring_hom⟩
instance coe_monoid_hom : has_coe (A →ₐ[R] B) (A →* B) := ⟨λ f, ↑(f : A →+* B)⟩
instance coe_add_monoid_hom : has_coe (A →ₐ[R] B) (A →+ B) := ⟨λ f, ↑(f : A →+* B)⟩
@[simp, norm_cast] lemma coe_mk {f : A → B} (h₁ h₂ h₃ h₄ h₅) :
⇑(⟨f, h₁, h₂, h₃, h₄, h₅⟩ : A →ₐ[R] B) = f := rfl
-- make the coercion the simp-normal form
@[simp] lemma to_ring_hom_eq_coe (f : A →ₐ[R] B) : f.to_ring_hom = f := rfl
@[simp, norm_cast] lemma coe_to_ring_hom (f : A →ₐ[R] B) : ⇑(f : A →+* B) = f := rfl
@[simp, norm_cast] lemma coe_to_monoid_hom (f : A →ₐ[R] B) : ⇑(f : A →* B) = f := rfl
@[simp, norm_cast] lemma coe_to_add_monoid_hom (f : A →ₐ[R] B) : ⇑(f : A →+ B) = f := rfl
variables (φ : A →ₐ[R] B)
theorem coe_fn_injective : @function.injective (A →ₐ[R] B) (A → B) coe_fn := fun_like.coe_injective
theorem coe_fn_inj {φ₁ φ₂ : A →ₐ[R] B} : (φ₁ : A → B) = φ₂ ↔ φ₁ = φ₂ := fun_like.coe_fn_eq
theorem coe_ring_hom_injective : function.injective (coe : (A →ₐ[R] B) → (A →+* B)) :=
λ φ₁ φ₂ H, coe_fn_injective $ show ((φ₁ : (A →+* B)) : A → B) = ((φ₂ : (A →+* B)) : A → B),
from congr_arg _ H
theorem coe_monoid_hom_injective : function.injective (coe : (A →ₐ[R] B) → (A →* B)) :=
ring_hom.coe_monoid_hom_injective.comp coe_ring_hom_injective
theorem coe_add_monoid_hom_injective : function.injective (coe : (A →ₐ[R] B) → (A →+ B)) :=
ring_hom.coe_add_monoid_hom_injective.comp coe_ring_hom_injective
protected lemma congr_fun {φ₁ φ₂ : A →ₐ[R] B} (H : φ₁ = φ₂) (x : A) : φ₁ x = φ₂ x :=
fun_like.congr_fun H x
protected lemma congr_arg (φ : A →ₐ[R] B) {x y : A} (h : x = y) : φ x = φ y :=
fun_like.congr_arg φ h
@[ext]
theorem ext {φ₁ φ₂ : A →ₐ[R] B} (H : ∀ x, φ₁ x = φ₂ x) : φ₁ = φ₂ := fun_like.ext _ _ H
theorem ext_iff {φ₁ φ₂ : A →ₐ[R] B} : φ₁ = φ₂ ↔ ∀ x, φ₁ x = φ₂ x := fun_like.ext_iff
@[simp] theorem mk_coe {f : A →ₐ[R] B} (h₁ h₂ h₃ h₄ h₅) :
(⟨f, h₁, h₂, h₃, h₄, h₅⟩ : A →ₐ[R] B) = f := ext $ λ _, rfl
@[simp]
theorem commutes (r : R) : φ (algebra_map R A r) = algebra_map R B r := φ.commutes' r
theorem comp_algebra_map : (φ : A →+* B).comp (algebra_map R A) = algebra_map R B :=
ring_hom.ext $ φ.commutes
protected lemma map_add (r s : A) : φ (r + s) = φ r + φ s := map_add _ _ _
protected lemma map_zero : φ 0 = 0 := map_zero _
protected lemma map_mul (x y) : φ (x * y) = φ x * φ y := map_mul _ _ _
protected lemma map_one : φ 1 = 1 := map_one _
protected lemma map_pow (x : A) (n : ℕ) : φ (x ^ n) = (φ x) ^ n := map_pow _ _ _
@[simp] protected lemma map_smul (r : R) (x : A) : φ (r • x) = r • φ x := map_smul _ _ _
protected lemma map_sum {ι : Type*} (f : ι → A) (s : finset ι) :
φ (∑ x in s, f x) = ∑ x in s, φ (f x) := map_sum _ _ _
protected lemma map_finsupp_sum {α : Type*} [has_zero α] {ι : Type*} (f : ι →₀ α) (g : ι → α → A) :
φ (f.sum g) = f.sum (λ i a, φ (g i a)) := map_finsupp_sum _ _ _
protected lemma map_bit0 (x) : φ (bit0 x) = bit0 (φ x) := map_bit0 _ _
protected lemma map_bit1 (x) : φ (bit1 x) = bit1 (φ x) := map_bit1 _ _
/-- If a `ring_hom` is `R`-linear, then it is an `alg_hom`. -/
def mk' (f : A →+* B) (h : ∀ (c : R) x, f (c • x) = c • f x) : A →ₐ[R] B :=
{ to_fun := f,
commutes' := λ c, by simp only [algebra.algebra_map_eq_smul_one, h, f.map_one],
.. f }
@[simp] lemma coe_mk' (f : A →+* B) (h : ∀ (c : R) x, f (c • x) = c • f x) : ⇑(mk' f h) = f := rfl
section
variables (R A)
/-- Identity map as an `alg_hom`. -/
protected def id : A →ₐ[R] A :=
{ commutes' := λ _, rfl,
..ring_hom.id A }
@[simp] lemma coe_id : ⇑(alg_hom.id R A) = id := rfl
@[simp] lemma id_to_ring_hom : (alg_hom.id R A : A →+* A) = ring_hom.id _ := rfl
end
lemma id_apply (p : A) : alg_hom.id R A p = p := rfl
/-- Composition of algebra homeomorphisms. -/
def comp (φ₁ : B →ₐ[R] C) (φ₂ : A →ₐ[R] B) : A →ₐ[R] C :=
{ commutes' := λ r : R, by rw [← φ₁.commutes, ← φ₂.commutes]; refl,
.. φ₁.to_ring_hom.comp ↑φ₂ }
@[simp] lemma coe_comp (φ₁ : B →ₐ[R] C) (φ₂ : A →ₐ[R] B) : ⇑(φ₁.comp φ₂) = φ₁ ∘ φ₂ := rfl
lemma comp_apply (φ₁ : B →ₐ[R] C) (φ₂ : A →ₐ[R] B) (p : A) : φ₁.comp φ₂ p = φ₁ (φ₂ p) := rfl
lemma comp_to_ring_hom (φ₁ : B →ₐ[R] C) (φ₂ : A →ₐ[R] B) :
(φ₁.comp φ₂ : A →+* C) = (φ₁ : B →+* C).comp ↑φ₂ := rfl
@[simp] theorem comp_id : φ.comp (alg_hom.id R A) = φ :=
ext $ λ x, rfl
@[simp] theorem id_comp : (alg_hom.id R B).comp φ = φ :=
ext $ λ x, rfl
theorem comp_assoc (φ₁ : C →ₐ[R] D) (φ₂ : B →ₐ[R] C) (φ₃ : A →ₐ[R] B) :
(φ₁.comp φ₂).comp φ₃ = φ₁.comp (φ₂.comp φ₃) :=
ext $ λ x, rfl
/-- R-Alg ⥤ R-Mod -/
def to_linear_map : A →ₗ[R] B :=
{ to_fun := φ,
map_add' := map_add _,
map_smul' := map_smul _ }
@[simp] lemma to_linear_map_apply (p : A) : φ.to_linear_map p = φ p := rfl
theorem to_linear_map_injective : function.injective (to_linear_map : _ → (A →ₗ[R] B)) :=
λ φ₁ φ₂ h, ext $ linear_map.congr_fun h
@[simp] lemma comp_to_linear_map (f : A →ₐ[R] B) (g : B →ₐ[R] C) :
(g.comp f).to_linear_map = g.to_linear_map.comp f.to_linear_map := rfl
@[simp] lemma to_linear_map_id : to_linear_map (alg_hom.id R A) = linear_map.id :=
linear_map.ext $ λ _, rfl
/-- Promote a `linear_map` to an `alg_hom` by supplying proofs about the behavior on `1` and `*`. -/
@[simps]
def of_linear_map (f : A →ₗ[R] B) (map_one : f 1 = 1) (map_mul : ∀ x y, f (x * y) = f x * f y) :
A →ₐ[R] B :=
{ to_fun := f,
map_one' := map_one,
map_mul' := map_mul,
commutes' := λ c, by simp only [algebra.algebra_map_eq_smul_one, f.map_smul, map_one],
.. f.to_add_monoid_hom }
@[simp] lemma of_linear_map_to_linear_map (map_one) (map_mul) :
of_linear_map φ.to_linear_map map_one map_mul = φ :=
by { ext, refl }
@[simp] lemma to_linear_map_of_linear_map (f : A →ₗ[R] B) (map_one) (map_mul) :
to_linear_map (of_linear_map f map_one map_mul) = f :=
by { ext, refl }
@[simp] lemma of_linear_map_id (map_one) (map_mul) :
of_linear_map linear_map.id map_one map_mul = alg_hom.id R A :=
ext $ λ _, rfl
lemma map_smul_of_tower {R'} [has_smul R' A] [has_smul R' B]
[linear_map.compatible_smul A B R' R] (r : R') (x : A) : φ (r • x) = r • φ x :=
φ.to_linear_map.map_smul_of_tower r x
lemma map_list_prod (s : list A) :
φ s.prod = (s.map φ).prod :=
φ.to_ring_hom.map_list_prod s
@[simps mul one {attrs := []}] instance End : monoid (A →ₐ[R] A) :=
{ mul := comp,
mul_assoc := λ ϕ ψ χ, rfl,
one := alg_hom.id R A,
one_mul := λ ϕ, ext $ λ x, rfl,
mul_one := λ ϕ, ext $ λ x, rfl }
@[simp] lemma one_apply (x : A) : (1 : A →ₐ[R] A) x = x := rfl
@[simp] lemma mul_apply (φ ψ : A →ₐ[R] A) (x : A) : (φ * ψ) x = φ (ψ x) := rfl
section prod
variables (R A B)
/-- First projection as `alg_hom`. -/
def fst : A × B →ₐ[R] A :=
{ commutes' := λ r, rfl, .. ring_hom.fst A B}
/-- Second projection as `alg_hom`. -/
def snd : A × B →ₐ[R] B :=
{ commutes' := λ r, rfl, .. ring_hom.snd A B}
variables {R A B}
/-- The `pi.prod` of two morphisms is a morphism. -/
@[simps] def prod (f : A →ₐ[R] B) (g : A →ₐ[R] C) : (A →ₐ[R] B × C) :=
{ commutes' := λ r, by simp only [to_ring_hom_eq_coe, ring_hom.to_fun_eq_coe, ring_hom.prod_apply,
coe_to_ring_hom, commutes, algebra.algebra_map_prod_apply],
.. (f.to_ring_hom.prod g.to_ring_hom) }
lemma coe_prod (f : A →ₐ[R] B) (g : A →ₐ[R] C) : ⇑(f.prod g) = pi.prod f g := rfl
@[simp] theorem fst_prod (f : A →ₐ[R] B) (g : A →ₐ[R] C) :
(fst R B C).comp (prod f g) = f := by ext; refl
@[simp] theorem snd_prod (f : A →ₐ[R] B) (g : A →ₐ[R] C) :
(snd R B C).comp (prod f g) = g := by ext; refl
@[simp] theorem prod_fst_snd : prod (fst R A B) (snd R A B) = 1 :=
fun_like.coe_injective pi.prod_fst_snd
/-- Taking the product of two maps with the same domain is equivalent to taking the product of
their codomains. -/
@[simps] def prod_equiv : ((A →ₐ[R] B) × (A →ₐ[R] C)) ≃ (A →ₐ[R] B × C) :=
{ to_fun := λ f, f.1.prod f.2,
inv_fun := λ f, ((fst _ _ _).comp f, (snd _ _ _).comp f),
left_inv := λ f, by ext; refl,
right_inv := λ f, by ext; refl }
end prod
lemma algebra_map_eq_apply (f : A →ₐ[R] B) {y : R} {x : A} (h : algebra_map R A y = x) :
algebra_map R B y = f x :=
h ▸ (f.commutes _).symm
end semiring
section comm_semiring
variables [comm_semiring R] [comm_semiring A] [comm_semiring B]
variables [algebra R A] [algebra R B] (φ : A →ₐ[R] B)
protected lemma map_multiset_prod (s : multiset A) :
φ s.prod = (s.map φ).prod := map_multiset_prod _ _
protected lemma map_prod {ι : Type*} (f : ι → A) (s : finset ι) :
φ (∏ x in s, f x) = ∏ x in s, φ (f x) := map_prod _ _ _
protected lemma map_finsupp_prod {α : Type*} [has_zero α] {ι : Type*} (f : ι →₀ α) (g : ι → α → A) :
φ (f.prod g) = f.prod (λ i a, φ (g i a)) := map_finsupp_prod _ _ _
end comm_semiring
section ring
variables [comm_semiring R] [ring A] [ring B]
variables [algebra R A] [algebra R B] (φ : A →ₐ[R] B)
protected lemma map_neg (x) : φ (-x) = -φ x := map_neg _ _
protected lemma map_sub (x y) : φ (x - y) = φ x - φ y := map_sub _ _ _
end ring
end alg_hom
@[simp] lemma rat.smul_one_eq_coe {A : Type*} [division_ring A] [algebra ℚ A] (m : ℚ) :
@@has_smul.smul algebra.to_has_smul m (1 : A) = ↑m :=
by rw [algebra.smul_def, mul_one, eq_rat_cast]
set_option old_structure_cmd true
/-- An equivalence of algebras is an equivalence of rings commuting with the actions of scalars. -/
structure alg_equiv (R : Type u) (A : Type v) (B : Type w)
[comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B]
extends A ≃ B, A ≃* B, A ≃+ B, A ≃+* B :=
(commutes' : ∀ r : R, to_fun (algebra_map R A r) = algebra_map R B r)
attribute [nolint doc_blame] alg_equiv.to_ring_equiv
attribute [nolint doc_blame] alg_equiv.to_equiv
attribute [nolint doc_blame] alg_equiv.to_add_equiv
attribute [nolint doc_blame] alg_equiv.to_mul_equiv
notation A ` ≃ₐ[`:50 R `] ` A' := alg_equiv R A A'
/-- `alg_equiv_class F R A B` states that `F` is a type of algebra structure preserving
equivalences. You should extend this class when you extend `alg_equiv`. -/
class alg_equiv_class (F : Type*) (R A B : out_param Type*)
[comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B]
extends ring_equiv_class F A B :=
(commutes : ∀ (f : F) (r : R), f (algebra_map R A r) = algebra_map R B r)
-- `R` becomes a metavariable but that's fine because it's an `out_param`
attribute [nolint dangerous_instance] alg_equiv_class.to_ring_equiv_class
namespace alg_equiv_class
@[priority 100] -- See note [lower instance priority]
instance to_alg_hom_class (F R A B : Type*)
[comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B]
[h : alg_equiv_class F R A B] : alg_hom_class F R A B :=
{ coe := coe_fn,
coe_injective' := fun_like.coe_injective,
map_zero := map_zero,
map_one := map_one,
.. h }
@[priority 100]
instance to_linear_equiv_class (F R A B : Type*)
[comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B]
[h : alg_equiv_class F R A B] : linear_equiv_class F R A B :=
{ map_smulₛₗ := λ f, map_smulₛₗ f,
..h }
instance (F R A B : Type*) [comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B]
[h : alg_equiv_class F R A B] : has_coe_t F (A ≃ₐ[R] B) :=
{ coe := λ f,
{ to_fun := f,
inv_fun := equiv_like.inv f,
commutes' := alg_hom_class.commutes f,
.. (f : A ≃+* B) } }
end alg_equiv_class
namespace alg_equiv
variables {R : Type u} {A₁ : Type v} {A₂ : Type w} {A₃ : Type u₁}
section semiring
variables [comm_semiring R] [semiring A₁] [semiring A₂] [semiring A₃]
variables [algebra R A₁] [algebra R A₂] [algebra R A₃]
variables (e : A₁ ≃ₐ[R] A₂)
instance : alg_equiv_class (A₁ ≃ₐ[R] A₂) R A₁ A₂ :=
{ coe := to_fun,
inv := inv_fun,
coe_injective' := λ f g h₁ h₂, by { cases f, cases g, congr' },
map_add := map_add',
map_mul := map_mul',
commutes := commutes',
left_inv := left_inv,
right_inv := right_inv }
/-- Helper instance for when there's too many metavariables to apply
`fun_like.has_coe_to_fun` directly. -/
instance : has_coe_to_fun (A₁ ≃ₐ[R] A₂) (λ _, A₁ → A₂) := ⟨alg_equiv.to_fun⟩
@[simp, protected] lemma coe_coe {F : Type*} [alg_equiv_class F R A₁ A₂] (f : F) :
⇑(f : A₁ ≃ₐ[R] A₂) = f := rfl
@[ext]
lemma ext {f g : A₁ ≃ₐ[R] A₂} (h : ∀ a, f a = g a) : f = g := fun_like.ext f g h
protected lemma congr_arg {f : A₁ ≃ₐ[R] A₂} {x x' : A₁} : x = x' → f x = f x' :=
fun_like.congr_arg f
protected lemma congr_fun {f g : A₁ ≃ₐ[R] A₂} (h : f = g) (x : A₁) : f x = g x :=
fun_like.congr_fun h x
protected lemma ext_iff {f g : A₁ ≃ₐ[R] A₂} : f = g ↔ ∀ x, f x = g x := fun_like.ext_iff
lemma coe_fun_injective : @function.injective (A₁ ≃ₐ[R] A₂) (A₁ → A₂) (λ e, (e : A₁ → A₂)) :=
fun_like.coe_injective
instance has_coe_to_ring_equiv : has_coe (A₁ ≃ₐ[R] A₂) (A₁ ≃+* A₂) := ⟨alg_equiv.to_ring_equiv⟩
@[simp] lemma coe_mk {to_fun inv_fun left_inv right_inv map_mul map_add commutes} :
⇑(⟨to_fun, inv_fun, left_inv, right_inv, map_mul, map_add, commutes⟩ : A₁ ≃ₐ[R] A₂) = to_fun :=
rfl
@[simp] theorem mk_coe (e : A₁ ≃ₐ[R] A₂) (e' h₁ h₂ h₃ h₄ h₅) :
(⟨e, e', h₁, h₂, h₃, h₄, h₅⟩ : A₁ ≃ₐ[R] A₂) = e := ext $ λ _, rfl
@[simp] lemma to_fun_eq_coe (e : A₁ ≃ₐ[R] A₂) : e.to_fun = e := rfl
@[simp] lemma to_equiv_eq_coe : e.to_equiv = e := rfl
@[simp] lemma to_ring_equiv_eq_coe : e.to_ring_equiv = e := rfl
@[simp, norm_cast] lemma coe_ring_equiv : ((e : A₁ ≃+* A₂) : A₁ → A₂) = e := rfl
lemma coe_ring_equiv' : (e.to_ring_equiv : A₁ → A₂) = e := rfl
lemma coe_ring_equiv_injective : function.injective (coe : (A₁ ≃ₐ[R] A₂) → (A₁ ≃+* A₂)) :=
λ e₁ e₂ h, ext $ ring_equiv.congr_fun h
protected lemma map_add : ∀ x y, e (x + y) = e x + e y := map_add e
protected lemma map_zero : e 0 = 0 := map_zero e
protected lemma map_mul : ∀ x y, e (x * y) = (e x) * (e y) := map_mul e
protected lemma map_one : e 1 = 1 := map_one e
@[simp] lemma commutes : ∀ (r : R), e (algebra_map R A₁ r) = algebra_map R A₂ r :=
e.commutes'
@[simp] lemma map_smul (r : R) (x : A₁) : e (r • x) = r • e x :=
by simp only [algebra.smul_def, map_mul, commutes]
lemma map_sum {ι : Type*} (f : ι → A₁) (s : finset ι) :
e (∑ x in s, f x) = ∑ x in s, e (f x) :=
e.to_add_equiv.map_sum f s
lemma map_finsupp_sum {α : Type*} [has_zero α] {ι : Type*} (f : ι →₀ α) (g : ι → α → A₁) :
e (f.sum g) = f.sum (λ i b, e (g i b)) :=
e.map_sum _ _
/-- Interpret an algebra equivalence as an algebra homomorphism.
This definition is included for symmetry with the other `to_*_hom` projections.
The `simp` normal form is to use the coercion of the `alg_hom_class.has_coe_t` instance. -/
def to_alg_hom : A₁ →ₐ[R] A₂ :=
{ map_one' := e.map_one, map_zero' := e.map_zero, ..e }
@[simp] lemma to_alg_hom_eq_coe : e.to_alg_hom = e := rfl
@[simp, norm_cast] lemma coe_alg_hom : ((e : A₁ →ₐ[R] A₂) : A₁ → A₂) = e :=
rfl
lemma coe_alg_hom_injective : function.injective (coe : (A₁ ≃ₐ[R] A₂) → (A₁ →ₐ[R] A₂)) :=
λ e₁ e₂ h, ext $ alg_hom.congr_fun h
/-- The two paths coercion can take to a `ring_hom` are equivalent -/
lemma coe_ring_hom_commutes : ((e : A₁ →ₐ[R] A₂) : A₁ →+* A₂) = ((e : A₁ ≃+* A₂) : A₁ →+* A₂) :=
rfl
protected lemma map_pow : ∀ (x : A₁) (n : ℕ), e (x ^ n) = (e x) ^ n := map_pow _
protected lemma injective : function.injective e := equiv_like.injective e
protected lemma surjective : function.surjective e := equiv_like.surjective e
protected lemma bijective : function.bijective e := equiv_like.bijective e
/-- Algebra equivalences are reflexive. -/
@[refl] def refl : A₁ ≃ₐ[R] A₁ := {commutes' := λ r, rfl, ..(1 : A₁ ≃+* A₁)}
instance : inhabited (A₁ ≃ₐ[R] A₁) := ⟨refl⟩
@[simp] lemma refl_to_alg_hom : ↑(refl : A₁ ≃ₐ[R] A₁) = alg_hom.id R A₁ := rfl
@[simp] lemma coe_refl : ⇑(refl : A₁ ≃ₐ[R] A₁) = id := rfl
/-- Algebra equivalences are symmetric. -/
@[symm]
def symm (e : A₁ ≃ₐ[R] A₂) : A₂ ≃ₐ[R] A₁ :=
{ commutes' := λ r, by { rw ←e.to_ring_equiv.symm_apply_apply (algebra_map R A₁ r), congr,
change _ = e _, rw e.commutes, },
..e.to_ring_equiv.symm, }
/-- See Note [custom simps projection] -/
def simps.symm_apply (e : A₁ ≃ₐ[R] A₂) : A₂ → A₁ := e.symm
initialize_simps_projections alg_equiv (to_fun → apply, inv_fun → symm_apply)
@[simp] lemma coe_apply_coe_coe_symm_apply {F : Type*} [alg_equiv_class F R A₁ A₂]
(f : F) (x : A₂) : f ((f : A₁ ≃ₐ[R] A₂).symm x) = x := equiv_like.right_inv f x
@[simp] lemma coe_coe_symm_apply_coe_apply {F : Type*} [alg_equiv_class F R A₁ A₂]
(f : F) (x : A₁) : (f : A₁ ≃ₐ[R] A₂).symm (f x) = x := equiv_like.left_inv f x
@[simp] lemma inv_fun_eq_symm {e : A₁ ≃ₐ[R] A₂} : e.inv_fun = e.symm := rfl
@[simp] lemma symm_symm (e : A₁ ≃ₐ[R] A₂) : e.symm.symm = e :=
by { ext, refl, }
lemma symm_bijective : function.bijective (symm : (A₁ ≃ₐ[R] A₂) → (A₂ ≃ₐ[R] A₁)) :=
equiv.bijective ⟨symm, symm, symm_symm, symm_symm⟩
@[simp] lemma mk_coe' (e : A₁ ≃ₐ[R] A₂) (f h₁ h₂ h₃ h₄ h₅) :
(⟨f, e, h₁, h₂, h₃, h₄, h₅⟩ : A₂ ≃ₐ[R] A₁) = e.symm :=
symm_bijective.injective $ ext $ λ x, rfl
@[simp] theorem symm_mk (f f') (h₁ h₂ h₃ h₄ h₅) :
(⟨f, f', h₁, h₂, h₃, h₄, h₅⟩ : A₁ ≃ₐ[R] A₂).symm =
{ to_fun := f', inv_fun := f,
..(⟨f, f', h₁, h₂, h₃, h₄, h₅⟩ : A₁ ≃ₐ[R] A₂).symm } := rfl
@[simp] theorem refl_symm : (alg_equiv.refl : A₁ ≃ₐ[R] A₁).symm = alg_equiv.refl := rfl
--this should be a simp lemma but causes a lint timeout
lemma to_ring_equiv_symm (f : A₁ ≃ₐ[R] A₁) : (f : A₁ ≃+* A₁).symm = f.symm := rfl
@[simp] lemma symm_to_ring_equiv : (e.symm : A₂ ≃+* A₁) = (e : A₁ ≃+* A₂).symm := rfl
/-- Algebra equivalences are transitive. -/
@[trans]
def trans (e₁ : A₁ ≃ₐ[R] A₂) (e₂ : A₂ ≃ₐ[R] A₃) : A₁ ≃ₐ[R] A₃ :=
{ commutes' := λ r, show e₂.to_fun (e₁.to_fun _) = _, by rw [e₁.commutes', e₂.commutes'],
..(e₁.to_ring_equiv.trans e₂.to_ring_equiv), }
@[simp] lemma apply_symm_apply (e : A₁ ≃ₐ[R] A₂) : ∀ x, e (e.symm x) = x :=
e.to_equiv.apply_symm_apply
@[simp] lemma symm_apply_apply (e : A₁ ≃ₐ[R] A₂) : ∀ x, e.symm (e x) = x :=
e.to_equiv.symm_apply_apply
@[simp] lemma symm_trans_apply (e₁ : A₁ ≃ₐ[R] A₂) (e₂ : A₂ ≃ₐ[R] A₃) (x : A₃) :
(e₁.trans e₂).symm x = e₁.symm (e₂.symm x) := rfl
@[simp] lemma coe_trans (e₁ : A₁ ≃ₐ[R] A₂) (e₂ : A₂ ≃ₐ[R] A₃) :
⇑(e₁.trans e₂) = e₂ ∘ e₁ := rfl
@[simp] lemma trans_apply (e₁ : A₁ ≃ₐ[R] A₂) (e₂ : A₂ ≃ₐ[R] A₃) (x : A₁) :
(e₁.trans e₂) x = e₂ (e₁ x) := rfl
@[simp] lemma comp_symm (e : A₁ ≃ₐ[R] A₂) :
alg_hom.comp (e : A₁ →ₐ[R] A₂) ↑e.symm = alg_hom.id R A₂ :=
by { ext, simp }
@[simp] lemma symm_comp (e : A₁ ≃ₐ[R] A₂) :
alg_hom.comp ↑e.symm (e : A₁ →ₐ[R] A₂) = alg_hom.id R A₁ :=
by { ext, simp }
theorem left_inverse_symm (e : A₁ ≃ₐ[R] A₂) : function.left_inverse e.symm e := e.left_inv
theorem right_inverse_symm (e : A₁ ≃ₐ[R] A₂) : function.right_inverse e.symm e := e.right_inv
/-- If `A₁` is equivalent to `A₁'` and `A₂` is equivalent to `A₂'`, then the type of maps
`A₁ →ₐ[R] A₂` is equivalent to the type of maps `A₁' →ₐ[R] A₂'`. -/
def arrow_congr {A₁' A₂' : Type*} [semiring A₁'] [semiring A₂'] [algebra R A₁'] [algebra R A₂']
(e₁ : A₁ ≃ₐ[R] A₁') (e₂ : A₂ ≃ₐ[R] A₂') : (A₁ →ₐ[R] A₂) ≃ (A₁' →ₐ[R] A₂') :=
{ to_fun := λ f, (e₂.to_alg_hom.comp f).comp e₁.symm.to_alg_hom,
inv_fun := λ f, (e₂.symm.to_alg_hom.comp f).comp e₁.to_alg_hom,
left_inv := λ f, by { simp only [alg_hom.comp_assoc, to_alg_hom_eq_coe, symm_comp],
simp only [←alg_hom.comp_assoc, symm_comp, alg_hom.id_comp, alg_hom.comp_id] },
right_inv := λ f, by { simp only [alg_hom.comp_assoc, to_alg_hom_eq_coe, comp_symm],
simp only [←alg_hom.comp_assoc, comp_symm, alg_hom.id_comp, alg_hom.comp_id] } }
lemma arrow_congr_comp {A₁' A₂' A₃' : Type*} [semiring A₁'] [semiring A₂'] [semiring A₃']
[algebra R A₁'] [algebra R A₂'] [algebra R A₃'] (e₁ : A₁ ≃ₐ[R] A₁') (e₂ : A₂ ≃ₐ[R] A₂')
(e₃ : A₃ ≃ₐ[R] A₃') (f : A₁ →ₐ[R] A₂) (g : A₂ →ₐ[R] A₃) :
arrow_congr e₁ e₃ (g.comp f) = (arrow_congr e₂ e₃ g).comp (arrow_congr e₁ e₂ f) :=
by { ext, simp only [arrow_congr, equiv.coe_fn_mk, alg_hom.comp_apply],
congr, exact (e₂.symm_apply_apply _).symm }
@[simp] lemma arrow_congr_refl :
arrow_congr alg_equiv.refl alg_equiv.refl = equiv.refl (A₁ →ₐ[R] A₂) :=
by { ext, refl }
@[simp] lemma arrow_congr_trans {A₁' A₂' A₃' : Type*} [semiring A₁'] [semiring A₂'] [semiring A₃']
[algebra R A₁'] [algebra R A₂'] [algebra R A₃'] (e₁ : A₁ ≃ₐ[R] A₂) (e₁' : A₁' ≃ₐ[R] A₂')
(e₂ : A₂ ≃ₐ[R] A₃) (e₂' : A₂' ≃ₐ[R] A₃') :
arrow_congr (e₁.trans e₂) (e₁'.trans e₂') = (arrow_congr e₁ e₁').trans (arrow_congr e₂ e₂') :=
by { ext, refl }
@[simp] lemma arrow_congr_symm {A₁' A₂' : Type*} [semiring A₁'] [semiring A₂']
[algebra R A₁'] [algebra R A₂'] (e₁ : A₁ ≃ₐ[R] A₁') (e₂ : A₂ ≃ₐ[R] A₂') :
(arrow_congr e₁ e₂).symm = arrow_congr e₁.symm e₂.symm :=
by { ext, refl }
/-- If an algebra morphism has an inverse, it is a algebra isomorphism. -/
def of_alg_hom (f : A₁ →ₐ[R] A₂) (g : A₂ →ₐ[R] A₁) (h₁ : f.comp g = alg_hom.id R A₂)
(h₂ : g.comp f = alg_hom.id R A₁) : A₁ ≃ₐ[R] A₂ :=
{ to_fun := f,
inv_fun := g,
left_inv := alg_hom.ext_iff.1 h₂,
right_inv := alg_hom.ext_iff.1 h₁,
..f }
lemma coe_alg_hom_of_alg_hom (f : A₁ →ₐ[R] A₂) (g : A₂ →ₐ[R] A₁) (h₁ h₂) :
↑(of_alg_hom f g h₁ h₂) = f := alg_hom.ext $ λ _, rfl
@[simp]
lemma of_alg_hom_coe_alg_hom (f : A₁ ≃ₐ[R] A₂) (g : A₂ →ₐ[R] A₁) (h₁ h₂) :
of_alg_hom ↑f g h₁ h₂ = f := ext $ λ _, rfl
lemma of_alg_hom_symm (f : A₁ →ₐ[R] A₂) (g : A₂ →ₐ[R] A₁) (h₁ h₂) :
(of_alg_hom f g h₁ h₂).symm = of_alg_hom g f h₂ h₁ := rfl
/-- Promotes a bijective algebra homomorphism to an algebra equivalence. -/
noncomputable def of_bijective (f : A₁ →ₐ[R] A₂) (hf : function.bijective f) : A₁ ≃ₐ[R] A₂ :=
{ .. ring_equiv.of_bijective (f : A₁ →+* A₂) hf, .. f }
@[simp] lemma coe_of_bijective {f : A₁ →ₐ[R] A₂} {hf : function.bijective f} :
(alg_equiv.of_bijective f hf : A₁ → A₂) = f := rfl
lemma of_bijective_apply {f : A₁ →ₐ[R] A₂} {hf : function.bijective f} (a : A₁) :
(alg_equiv.of_bijective f hf) a = f a := rfl
/-- Forgetting the multiplicative structures, an equivalence of algebras is a linear equivalence. -/
@[simps apply] def to_linear_equiv (e : A₁ ≃ₐ[R] A₂) : A₁ ≃ₗ[R] A₂ :=
{ to_fun := e,
map_smul' := e.map_smul,
inv_fun := e.symm,
.. e }
@[simp] lemma to_linear_equiv_refl :
(alg_equiv.refl : A₁ ≃ₐ[R] A₁).to_linear_equiv = linear_equiv.refl R A₁ := rfl
@[simp] lemma to_linear_equiv_symm (e : A₁ ≃ₐ[R] A₂) :
e.to_linear_equiv.symm = e.symm.to_linear_equiv := rfl
@[simp] lemma to_linear_equiv_trans (e₁ : A₁ ≃ₐ[R] A₂) (e₂ : A₂ ≃ₐ[R] A₃) :
(e₁.trans e₂).to_linear_equiv = e₁.to_linear_equiv.trans e₂.to_linear_equiv := rfl
theorem to_linear_equiv_injective : function.injective (to_linear_equiv : _ → (A₁ ≃ₗ[R] A₂)) :=
λ e₁ e₂ h, ext $ linear_equiv.congr_fun h
/-- Interpret an algebra equivalence as a linear map. -/
def to_linear_map : A₁ →ₗ[R] A₂ :=
e.to_alg_hom.to_linear_map
@[simp] lemma to_alg_hom_to_linear_map :
(e : A₁ →ₐ[R] A₂).to_linear_map = e.to_linear_map := rfl
@[simp] lemma to_linear_equiv_to_linear_map :
e.to_linear_equiv.to_linear_map = e.to_linear_map := rfl
@[simp] lemma to_linear_map_apply (x : A₁) : e.to_linear_map x = e x := rfl
theorem to_linear_map_injective : function.injective (to_linear_map : _ → (A₁ →ₗ[R] A₂)) :=
λ e₁ e₂ h, ext $ linear_map.congr_fun h
@[simp] lemma trans_to_linear_map (f : A₁ ≃ₐ[R] A₂) (g : A₂ ≃ₐ[R] A₃) :
(f.trans g).to_linear_map = g.to_linear_map.comp f.to_linear_map := rfl
section of_linear_equiv
variables (l : A₁ ≃ₗ[R] A₂)
(map_mul : ∀ x y : A₁, l (x * y) = l x * l y)
(commutes : ∀ r : R, l (algebra_map R A₁ r) = algebra_map R A₂ r)
/--
Upgrade a linear equivalence to an algebra equivalence,
given that it distributes over multiplication and action of scalars.
-/
@[simps apply]
def of_linear_equiv : A₁ ≃ₐ[R] A₂ :=
{ to_fun := l,
inv_fun := l.symm,
map_mul' := map_mul,
commutes' := commutes,
..l }
@[simp]
lemma of_linear_equiv_symm :
(of_linear_equiv l map_mul commutes).symm = of_linear_equiv l.symm
((of_linear_equiv l map_mul commutes).symm.map_mul)
((of_linear_equiv l map_mul commutes).symm.commutes) :=
rfl
@[simp] lemma of_linear_equiv_to_linear_equiv (map_mul) (commutes) :
of_linear_equiv e.to_linear_equiv map_mul commutes = e :=
by { ext, refl }
@[simp] lemma to_linear_equiv_of_linear_equiv :
to_linear_equiv (of_linear_equiv l map_mul commutes) = l :=
by { ext, refl }
end of_linear_equiv
section of_ring_equiv
/-- Promotes a linear ring_equiv to an alg_equiv. -/
@[simps]
def of_ring_equiv {f : A₁ ≃+* A₂}
(hf : ∀ x, f (algebra_map R A₁ x) = algebra_map R A₂ x) : A₁ ≃ₐ[R] A₂ :=
{ to_fun := f,
inv_fun := f.symm,
commutes' := hf,
.. f }
end of_ring_equiv
@[simps mul one {attrs := []}] instance aut : group (A₁ ≃ₐ[R] A₁) :=
{ mul := λ ϕ ψ, ψ.trans ϕ,
mul_assoc := λ ϕ ψ χ, rfl,
one := refl,
one_mul := λ ϕ, ext $ λ x, rfl,
mul_one := λ ϕ, ext $ λ x, rfl,
inv := symm,
mul_left_inv := λ ϕ, ext $ symm_apply_apply ϕ }
@[simp] lemma one_apply (x : A₁) : (1 : A₁ ≃ₐ[R] A₁) x = x := rfl
@[simp] lemma mul_apply (e₁ e₂ : A₁ ≃ₐ[R] A₁) (x : A₁) : (e₁ * e₂) x = e₁ (e₂ x) := rfl
/-- An algebra isomorphism induces a group isomorphism between automorphism groups -/
@[simps apply]
def aut_congr (ϕ : A₁ ≃ₐ[R] A₂) : (A₁ ≃ₐ[R] A₁) ≃* (A₂ ≃ₐ[R] A₂) :=
{ to_fun := λ ψ, ϕ.symm.trans (ψ.trans ϕ),
inv_fun := λ ψ, ϕ.trans (ψ.trans ϕ.symm),
left_inv := λ ψ, by { ext, simp_rw [trans_apply, symm_apply_apply] },
right_inv := λ ψ, by { ext, simp_rw [trans_apply, apply_symm_apply] },
map_mul' := λ ψ χ, by { ext, simp only [mul_apply, trans_apply, symm_apply_apply] } }
@[simp] lemma aut_congr_refl : aut_congr (alg_equiv.refl) = mul_equiv.refl (A₁ ≃ₐ[R] A₁) :=
by { ext, refl }
@[simp] lemma aut_congr_symm (ϕ : A₁ ≃ₐ[R] A₂) : (aut_congr ϕ).symm = aut_congr ϕ.symm := rfl
@[simp] lemma aut_congr_trans (ϕ : A₁ ≃ₐ[R] A₂) (ψ : A₂ ≃ₐ[R] A₃) :
(aut_congr ϕ).trans (aut_congr ψ) = aut_congr (ϕ.trans ψ) := rfl
/-- The tautological action by `A₁ ≃ₐ[R] A₁` on `A₁`.
This generalizes `function.End.apply_mul_action`. -/
instance apply_mul_semiring_action : mul_semiring_action (A₁ ≃ₐ[R] A₁) A₁ :=
{ smul := ($),
smul_zero := alg_equiv.map_zero,
smul_add := alg_equiv.map_add,
smul_one := alg_equiv.map_one,
smul_mul := alg_equiv.map_mul,
one_smul := λ _, rfl,
mul_smul := λ _ _ _, rfl }
@[simp] protected lemma smul_def (f : A₁ ≃ₐ[R] A₁) (a : A₁) : f • a = f a := rfl
instance apply_has_faithful_smul : has_faithful_smul (A₁ ≃ₐ[R] A₁) A₁ :=
⟨λ _ _, alg_equiv.ext⟩
instance apply_smul_comm_class : smul_comm_class R (A₁ ≃ₐ[R] A₁) A₁ :=
{ smul_comm := λ r e a, (e.map_smul r a).symm }
instance apply_smul_comm_class' : smul_comm_class (A₁ ≃ₐ[R] A₁) R A₁ :=
{ smul_comm := λ e r a, (e.map_smul r a) }
@[simp] lemma algebra_map_eq_apply (e : A₁ ≃ₐ[R] A₂) {y : R} {x : A₁} :
(algebra_map R A₂ y = e x) ↔ (algebra_map R A₁ y = x) :=
⟨λ h, by simpa using e.symm.to_alg_hom.algebra_map_eq_apply h,
λ h, e.to_alg_hom.algebra_map_eq_apply h⟩
end semiring
section comm_semiring
variables [comm_semiring R] [comm_semiring A₁] [comm_semiring A₂]
variables [algebra R A₁] [algebra R A₂] (e : A₁ ≃ₐ[R] A₂)
lemma map_prod {ι : Type*} (f : ι → A₁) (s : finset ι) :
e (∏ x in s, f x) = ∏ x in s, e (f x) :=
map_prod _ f s
lemma map_finsupp_prod {α : Type*} [has_zero α] {ι : Type*} (f : ι →₀ α) (g : ι → α → A₁) :
e (f.prod g) = f.prod (λ i a, e (g i a)) :=
map_finsupp_prod _ f g
end comm_semiring
section ring
variables [comm_semiring R] [ring A₁] [ring A₂]
variables [algebra R A₁] [algebra R A₂] (e : A₁ ≃ₐ[R] A₂)
protected lemma map_neg (x) : e (-x) = -e x := map_neg e x
protected lemma map_sub (x y) : e (x - y) = e x - e y := map_sub e x y
end ring
end alg_equiv
namespace mul_semiring_action
variables {M G : Type*} (R A : Type*) [comm_semiring R] [semiring A] [algebra R A]
section
variables [monoid M] [mul_semiring_action M A] [smul_comm_class M R A]
/-- Each element of the monoid defines a algebra homomorphism.
This is a stronger version of `mul_semiring_action.to_ring_hom` and
`distrib_mul_action.to_linear_map`. -/
@[simps]
def to_alg_hom (m : M) : A →ₐ[R] A :=
{ to_fun := λ a, m • a,
commutes' := smul_algebra_map _,
..mul_semiring_action.to_ring_hom _ _ m }
theorem to_alg_hom_injective [has_faithful_smul M A] :
function.injective (mul_semiring_action.to_alg_hom R A : M → A →ₐ[R] A) :=
λ m₁ m₂ h, eq_of_smul_eq_smul $ λ r, alg_hom.ext_iff.1 h r
end
section
variables [group G] [mul_semiring_action G A] [smul_comm_class G R A]
/-- Each element of the group defines a algebra equivalence.
This is a stronger version of `mul_semiring_action.to_ring_equiv` and
`distrib_mul_action.to_linear_equiv`. -/
@[simps]
def to_alg_equiv (g : G) : A ≃ₐ[R] A :=
{ .. mul_semiring_action.to_ring_equiv _ _ g,
.. mul_semiring_action.to_alg_hom R A g }
theorem to_alg_equiv_injective [has_faithful_smul G A] :
function.injective (mul_semiring_action.to_alg_equiv R A : G → A ≃ₐ[R] A) :=
λ m₁ m₂ h, eq_of_smul_eq_smul $ λ r, alg_equiv.ext_iff.1 h r
end
end mul_semiring_action
section nat
variables {R : Type*} [semiring R]
-- Lower the priority so that `algebra.id` is picked most of the time when working with
-- `ℕ`-algebras. This is only an issue since `algebra.id` and `algebra_nat` are not yet defeq.
-- TODO: fix this by adding an `of_nat` field to semirings.
/-- Semiring ⥤ ℕ-Alg -/
@[priority 99] instance algebra_nat : algebra ℕ R :=
{ commutes' := nat.cast_commute,
smul_def' := λ _ _, nsmul_eq_mul _ _,
to_ring_hom := nat.cast_ring_hom R }
instance nat_algebra_subsingleton : subsingleton (algebra ℕ R) :=
⟨λ P Q, by { ext, simp, }⟩
end nat
namespace ring_hom
variables {R S : Type*}
/-- Reinterpret a `ring_hom` as an `ℕ`-algebra homomorphism. -/
def to_nat_alg_hom [semiring R] [semiring S] (f : R →+* S) :
R →ₐ[ℕ] S :=
{ to_fun := f, commutes' := λ n, by simp, .. f }
/-- Reinterpret a `ring_hom` as a `ℤ`-algebra homomorphism. -/
def to_int_alg_hom [ring R] [ring S] [algebra ℤ R] [algebra ℤ S] (f : R →+* S) :
R →ₐ[ℤ] S :=
{ commutes' := λ n, by simp, .. f }
-- note that `R`, `S` could be `semiring`s but this is useless mathematically speaking -
-- a ℚ-algebra is a ring. furthermore, this change probably slows down elaboration.
@[simp] lemma map_rat_algebra_map [ring R] [ring S] [algebra ℚ R] [algebra ℚ S]
(f : R →+* S) (r : ℚ) : f (algebra_map ℚ R r) = algebra_map ℚ S r :=
ring_hom.ext_iff.1 (subsingleton.elim (f.comp (algebra_map ℚ R)) (algebra_map ℚ S)) r
/-- Reinterpret a `ring_hom` as a `ℚ`-algebra homomorphism. This actually yields an equivalence,
see `ring_hom.equiv_rat_alg_hom`. -/
def to_rat_alg_hom [ring R] [ring S] [algebra ℚ R] [algebra ℚ S] (f : R →+* S) :
R →ₐ[ℚ] S :=
{ commutes' := f.map_rat_algebra_map, .. f }
@[simp]
lemma to_rat_alg_hom_to_ring_hom [ring R] [ring S] [algebra ℚ R] [algebra ℚ S]
(f : R →+* S) : ↑f.to_rat_alg_hom = f :=
ring_hom.ext $ λ x, rfl
end ring_hom
section
variables {R S : Type*}
@[simp]
lemma alg_hom.to_ring_hom_to_rat_alg_hom [ring R] [ring S] [algebra ℚ R] [algebra ℚ S]
(f : R →ₐ[ℚ] S) : (f : R →+* S).to_rat_alg_hom = f :=
alg_hom.ext $ λ x, rfl
/-- The equivalence between `ring_hom` and `ℚ`-algebra homomorphisms. -/
@[simps]
def ring_hom.equiv_rat_alg_hom [ring R] [ring S] [algebra ℚ R] [algebra ℚ S] :
(R →+* S) ≃ (R →ₐ[ℚ] S) :=
{ to_fun := ring_hom.to_rat_alg_hom,
inv_fun := alg_hom.to_ring_hom,
left_inv := ring_hom.to_rat_alg_hom_to_ring_hom,
right_inv := alg_hom.to_ring_hom_to_rat_alg_hom, }
end
section rat
instance algebra_rat {α} [division_ring α] [char_zero α] : algebra ℚ α :=
{ smul := (•),
smul_def' := division_ring.qsmul_eq_mul',
to_ring_hom := rat.cast_hom α,
commutes' := rat.cast_commute }
/-- The two `algebra ℚ ℚ` instances should coincide. -/
example : algebra_rat = algebra.id ℚ := rfl
@[simp] theorem algebra_map_rat_rat : algebra_map ℚ ℚ = ring_hom.id ℚ :=
subsingleton.elim _ _
instance algebra_rat_subsingleton {α} [semiring α] :
subsingleton (algebra ℚ α) :=
⟨λ x y, algebra.algebra_ext x y $ ring_hom.congr_fun $ subsingleton.elim _ _⟩
end rat
namespace algebra
open module
variables (R : Type u) (A : Type v)
variables [comm_semiring R] [semiring A] [algebra R A]
/-- `algebra_map` as an `alg_hom`. -/
def of_id : R →ₐ[R] A :=
{ commutes' := λ _, rfl, .. algebra_map R A }
variables {R}
theorem of_id_apply (r) : of_id R A r = algebra_map R A r := rfl
end algebra
section int
variables (R : Type*) [ring R]
-- Lower the priority so that `algebra.id` is picked most of the time when working with
-- `ℤ`-algebras. This is only an issue since `algebra.id ℤ` and `algebra_int ℤ` are not yet defeq.
-- TODO: fix this by adding an `of_int` field to rings.
/-- Ring ⥤ ℤ-Alg -/
@[priority 99] instance algebra_int : algebra ℤ R :=
{ commutes' := int.cast_commute,
smul_def' := λ _ _, zsmul_eq_mul _ _,
to_ring_hom := int.cast_ring_hom R }
/-- A special case of `eq_int_cast'` that happens to be true definitionally -/
@[simp] lemma algebra_map_int_eq : algebra_map ℤ R = int.cast_ring_hom R := rfl
variables {R}
instance int_algebra_subsingleton : subsingleton (algebra ℤ R) :=
⟨λ P Q, by { ext, simp, }⟩
end int
namespace no_zero_smul_divisors
variables {R A : Type*}
open algebra
/-- If `algebra_map R A` is injective and `A` has no zero divisors,
`R`-multiples in `A` are zero only if one of the factors is zero.
Cannot be an instance because there is no `injective (algebra_map R A)` typeclass.
-/
lemma of_algebra_map_injective
[comm_semiring R] [semiring A] [algebra R A] [no_zero_divisors A]
(h : function.injective (algebra_map R A)) : no_zero_smul_divisors R A :=
⟨λ c x hcx, (mul_eq_zero.mp ((smul_def c x).symm.trans hcx)).imp_left
(map_eq_zero_iff (algebra_map R A) h).mp⟩
variables (R A)
lemma algebra_map_injective [comm_ring R] [ring A] [nontrivial A]
[algebra R A] [no_zero_smul_divisors R A] :
function.injective (algebra_map R A) :=
suffices function.injective (λ (c : R), c • (1 : A)),
by { convert this, ext, rw [algebra.smul_def, mul_one] },
smul_left_injective R one_ne_zero
lemma _root_.ne_zero.of_no_zero_smul_divisors (n : ℕ) [comm_ring R] [ne_zero (n : R)] [ring A]
[nontrivial A] [algebra R A] [no_zero_smul_divisors R A] : ne_zero (n : A) :=
ne_zero.nat_of_injective $ no_zero_smul_divisors.algebra_map_injective R A
variables {R A}
lemma iff_algebra_map_injective [comm_ring R] [ring A] [is_domain A] [algebra R A] :
no_zero_smul_divisors R A ↔ function.injective (algebra_map R A) :=
⟨@@no_zero_smul_divisors.algebra_map_injective R A _ _ _ _,
no_zero_smul_divisors.of_algebra_map_injective⟩
@[priority 100] -- see note [lower instance priority]
instance char_zero.no_zero_smul_divisors_nat [semiring R] [no_zero_divisors R] [char_zero R] :
no_zero_smul_divisors ℕ R :=
no_zero_smul_divisors.of_algebra_map_injective $ (algebra_map ℕ R).injective_nat
@[priority 100] -- see note [lower instance priority]
instance char_zero.no_zero_smul_divisors_int [ring R] [no_zero_divisors R] [char_zero R] :
no_zero_smul_divisors ℤ R :=
no_zero_smul_divisors.of_algebra_map_injective $ (algebra_map ℤ R).injective_int
section field
variables [field R] [semiring A] [algebra R A]
@[priority 100] -- see note [lower instance priority]
instance algebra.no_zero_smul_divisors [nontrivial A] [no_zero_divisors A] :
no_zero_smul_divisors R A :=
no_zero_smul_divisors.of_algebra_map_injective (algebra_map R A).injective
end field
end no_zero_smul_divisors
/-!
The R-algebra structure on `Π i : I, A i` when each `A i` is an R-algebra.
We couldn't set this up back in `algebra.pi_instances` because this file imports it.
-/
namespace pi
variable {I : Type u} -- The indexing type
variable {R : Type*} -- The scalar type
variable {f : I → Type v} -- The family of types already equipped with instances
variables (x y : Π i, f i) (i : I)
variables (I f)
instance algebra {r : comm_semiring R}
[s : ∀ i, semiring (f i)] [∀ i, algebra R (f i)] :
algebra R (Π i : I, f i) :=
{ commutes' := λ a f, begin ext, simp [algebra.commutes], end,
smul_def' := λ a f, begin ext, simp [algebra.smul_def], end,
..(pi.ring_hom (λ i, algebra_map R (f i)) : R →+* Π i : I, f i) }
lemma algebra_map_def {r : comm_semiring R}
[s : ∀ i, semiring (f i)] [∀ i, algebra R (f i)] (a : R) :
algebra_map R (Π i, f i) a = (λ i, algebra_map R (f i) a) := rfl
@[simp] lemma algebra_map_apply {r : comm_semiring R}
[s : ∀ i, semiring (f i)] [∀ i, algebra R (f i)] (a : R) (i : I) :
algebra_map R (Π i, f i) a i = algebra_map R (f i) a := rfl
-- One could also build a `Π i, R i`-algebra structure on `Π i, A i`,
-- when each `A i` is an `R i`-algebra, although I'm not sure that it's useful.
variables {I} (R) (f)
/-- `function.eval` as an `alg_hom`. The name matches `pi.eval_ring_hom`, `pi.eval_monoid_hom`,
etc. -/
@[simps]
def eval_alg_hom {r : comm_semiring R} [Π i, semiring (f i)] [Π i, algebra R (f i)] (i : I) :
(Π i, f i) →ₐ[R] f i :=
{ to_fun := λ f, f i, commutes' := λ r, rfl, .. pi.eval_ring_hom f i}
variables (A B : Type*) [comm_semiring R] [semiring B] [algebra R B]
/-- `function.const` as an `alg_hom`. The name matches `pi.const_ring_hom`, `pi.const_monoid_hom`,
etc. -/
@[simps]
def const_alg_hom : B →ₐ[R] (A → B) :=
{ to_fun := function.const _,
commutes' := λ r, rfl,
.. pi.const_ring_hom A B}
/-- When `R` is commutative and permits an `algebra_map`, `pi.const_ring_hom` is equal to that
map. -/
@[simp] lemma const_ring_hom_eq_algebra_map : const_ring_hom A R = algebra_map R (A → R) :=
rfl
@[simp] lemma const_alg_hom_eq_algebra_of_id : const_alg_hom R A R = algebra.of_id R (A → R) :=
rfl
end pi
/-- A special case of `pi.algebra` for non-dependent types. Lean struggles to elaborate
definitions elsewhere in the library without this, -/
instance function.algebra {R : Type*} (I : Type*) (A : Type*) [comm_semiring R]
[semiring A] [algebra R A] : algebra R (I → A) :=
pi.algebra _ _
namespace alg_equiv
/-- A family of algebra equivalences `Π j, (A₁ j ≃ₐ A₂ j)` generates a
multiplicative equivalence between `Π j, A₁ j` and `Π j, A₂ j`.
This is the `alg_equiv` version of `equiv.Pi_congr_right`, and the dependent version of
`alg_equiv.arrow_congr`.
-/
@[simps apply]
def Pi_congr_right {R ι : Type*} {A₁ A₂ : ι → Type*} [comm_semiring R]
[Π i, semiring (A₁ i)] [Π i, semiring (A₂ i)] [Π i, algebra R (A₁ i)] [Π i, algebra R (A₂ i)]
(e : Π i, A₁ i ≃ₐ[R] A₂ i) : (Π i, A₁ i) ≃ₐ[R] Π i, A₂ i :=
{ to_fun := λ x j, e j (x j),
inv_fun := λ x j, (e j).symm (x j),
commutes' := λ r, by { ext i, simp },
.. @ring_equiv.Pi_congr_right ι A₁ A₂ _ _ (λ i, (e i).to_ring_equiv) }
@[simp]
lemma Pi_congr_right_refl {R ι : Type*} {A : ι → Type*} [comm_semiring R]
[Π i, semiring (A i)] [Π i, algebra R (A i)] :
Pi_congr_right (λ i, (alg_equiv.refl : A i ≃ₐ[R] A i)) = alg_equiv.refl := rfl
@[simp]
lemma Pi_congr_right_symm {R ι : Type*} {A₁ A₂ : ι → Type*} [comm_semiring R]
[Π i, semiring (A₁ i)] [Π i, semiring (A₂ i)] [Π i, algebra R (A₁ i)] [Π i, algebra R (A₂ i)]
(e : Π i, A₁ i ≃ₐ[R] A₂ i) : (Pi_congr_right e).symm = (Pi_congr_right $ λ i, (e i).symm) := rfl
@[simp]
lemma Pi_congr_right_trans {R ι : Type*} {A₁ A₂ A₃ : ι → Type*} [comm_semiring R]
[Π i, semiring (A₁ i)] [Π i, semiring (A₂ i)] [Π i, semiring (A₃ i)]
[Π i, algebra R (A₁ i)] [Π i, algebra R (A₂ i)] [Π i, algebra R (A₃ i)]
(e₁ : Π i, A₁ i ≃ₐ[R] A₂ i) (e₂ : Π i, A₂ i ≃ₐ[R] A₃ i) :
(Pi_congr_right e₁).trans (Pi_congr_right e₂) = (Pi_congr_right $ λ i, (e₁ i).trans (e₂ i)) :=
rfl
end alg_equiv
section is_scalar_tower
variables {R : Type*} [comm_semiring R]
variables (A : Type*) [semiring A] [algebra R A]
variables {M : Type*} [add_comm_monoid M] [module A M] [module R M] [is_scalar_tower R A M]
variables {N : Type*} [add_comm_monoid N] [module A N] [module R N] [is_scalar_tower R A N]
lemma algebra_compatible_smul (r : R) (m : M) : r • m = ((algebra_map R A) r) • m :=
by rw [←(one_smul A m), ←smul_assoc, algebra.smul_def, mul_one, one_smul]
@[simp] lemma algebra_map_smul (r : R) (m : M) : ((algebra_map R A) r) • m = r • m :=
(algebra_compatible_smul A r m).symm
lemma int_cast_smul {k V : Type*} [comm_ring k] [add_comm_group V] [module k V] (r : ℤ) (x : V) :
(r : k) • x = r • x :=
algebra_map_smul k r x
lemma no_zero_smul_divisors.trans (R A M : Type*) [comm_ring R] [ring A] [is_domain A] [algebra R A]
[add_comm_group M] [module R M] [module A M] [is_scalar_tower R A M] [no_zero_smul_divisors R A]
[no_zero_smul_divisors A M] : no_zero_smul_divisors R M :=
begin
refine ⟨λ r m h, _⟩,
rw [algebra_compatible_smul A r m] at h,
cases smul_eq_zero.1 h with H H,
{ have : function.injective (algebra_map R A) :=
no_zero_smul_divisors.iff_algebra_map_injective.1 infer_instance,
left,
exact (injective_iff_map_eq_zero _).1 this _ H },
{ right,
exact H }
end
variable {A}
@[priority 100] -- see Note [lower instance priority]
instance is_scalar_tower.to_smul_comm_class : smul_comm_class R A M :=
⟨λ r a m, by rw [algebra_compatible_smul A r (a • m), smul_smul, algebra.commutes, mul_smul,
←algebra_compatible_smul]⟩
@[priority 100] -- see Note [lower instance priority]
instance is_scalar_tower.to_smul_comm_class' : smul_comm_class A R M :=
smul_comm_class.symm _ _ _
lemma smul_algebra_smul_comm (r : R) (a : A) (m : M) : a • r • m = r • a • m :=
smul_comm _ _ _
namespace linear_map
instance coe_is_scalar_tower : has_coe (M →ₗ[A] N) (M →ₗ[R] N) :=
⟨restrict_scalars R⟩
variables (R) {A M N}
@[simp, norm_cast squash] lemma coe_restrict_scalars_eq_coe (f : M →ₗ[A] N) :
(f.restrict_scalars R : M → N) = f := rfl
@[simp, norm_cast squash] lemma coe_coe_is_scalar_tower (f : M →ₗ[A] N) :
((f : M →ₗ[R] N) : M → N) = f := rfl
/-- `A`-linearly coerce a `R`-linear map from `M` to `A` to a function, given an algebra `A` over
a commutative semiring `R` and `M` a module over `R`. -/
def lto_fun (R : Type u) (M : Type v) (A : Type w)
[comm_semiring R] [add_comm_monoid M] [module R M] [comm_ring A] [algebra R A] :
(M →ₗ[R] A) →ₗ[A] (M → A) :=
{ to_fun := linear_map.to_fun,
map_add' := λ f g, rfl,
map_smul' := λ c f, rfl }
end linear_map
end is_scalar_tower
/-! TODO: The following lemmas no longer involve `algebra` at all, and could be moved closer
to `algebra/module/submodule.lean`. Currently this is tricky because `ker`, `range`, `⊤`, and `⊥`
are all defined in `linear_algebra/basic.lean`. -/
section module
open module
variables (R S M N : Type*) [semiring R] [semiring S] [has_smul R S]
variables [add_comm_monoid M] [module R M] [module S M] [is_scalar_tower R S M]
variables [add_comm_monoid N] [module R N] [module S N] [is_scalar_tower R S N]
variables {S M N}
@[simp]
lemma linear_map.ker_restrict_scalars (f : M →ₗ[S] N) :
(f.restrict_scalars R).ker = f.ker.restrict_scalars R :=
rfl
end module
namespace submodule
variables (R A M : Type*)
variables [comm_semiring R] [semiring A] [algebra R A] [add_comm_monoid M]
variables [module R M] [module A M] [is_scalar_tower R A M]
/-- If `A` is an `R`-algebra such that the induced morhpsim `R →+* A` is surjective, then the
`R`-module generated by a set `X` equals the `A`-module generated by `X`. -/
lemma span_eq_restrict_scalars (X : set M) (hsur : function.surjective (algebra_map R A)) :
span R X = restrict_scalars R (span A X) :=
begin
apply (span_le_restrict_scalars R A X).antisymm (λ m hm, _),
refine span_induction hm subset_span (zero_mem _) (λ _ _, add_mem) (λ a m hm, _),
obtain ⟨r, rfl⟩ := hsur a,
simpa [algebra_map_smul] using smul_mem _ r hm
end
end submodule
namespace alg_hom
variables {R : Type u} {A : Type v} {B : Type w} {I : Type*}
variables [comm_semiring R] [semiring A] [semiring B]
variables [algebra R A] [algebra R B]
/-- `R`-algebra homomorphism between the function spaces `I → A` and `I → B`, induced by an
`R`-algebra homomorphism `f` between `A` and `B`. -/
@[simps] protected def comp_left (f : A →ₐ[R] B) (I : Type*) : (I → A) →ₐ[R] (I → B) :=
{ to_fun := λ h, f ∘ h,
commutes' := λ c, by { ext, exact f.commutes' c },
.. f.to_ring_hom.comp_left I }
end alg_hom
example {R A} [comm_semiring R] [semiring A]
[module R A] [smul_comm_class R A A] [is_scalar_tower R A A] : algebra R A :=
algebra.of_module smul_mul_assoc mul_smul_comm
|
0ab2d3ee10c4301bb8cace4681cb9b95195ecf10 | 82e44445c70db0f03e30d7be725775f122d72f3e | /test/lift.lean | a9461a9d43227141d513ae5577f59af42cc32192 | [
"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 | 3,795 | lean | import tactic.lift
import data.set.basic
import data.int.basic
/-! Some tests of the `lift` tactic. -/
example (n m k x z u : ℤ) (hn : 0 < n) (hk : 0 ≤ k + n) (hu : 0 ≤ u)
(h : k + n = 2 + x) (f : false) :
k + n = m + x :=
begin
lift n to ℕ using le_of_lt hn,
guard_target (k + ↑n = m + x), guard_hyp hn : (0 : ℤ) < ↑n,
lift m to ℕ,
guard_target (k + ↑n = ↑m + x), tactic.swap, guard_target (0 ≤ m), tactic.swap,
tactic.num_goals >>= λ n, guard (n = 2),
lift (k + n) to ℕ using hk with l hl,
guard_hyp l : ℕ, guard_hyp hl : ↑l = k + ↑n, guard_target (↑l = ↑m + x),
tactic.success_if_fail (tactic.get_local `hk),
lift x to ℕ with y hy,
guard_hyp y : ℕ, guard_hyp hy : ↑y = x, guard_target (↑l = ↑m + x),
lift z to ℕ with w,
guard_hyp w : ℕ, tactic.success_if_fail (tactic.get_local `z),
lift u to ℕ using hu with u rfl hu,
guard_hyp hu : (0 : ℤ) ≤ ↑u,
all_goals { exfalso, assumption },
end
-- test lift of functions
example (α : Type*) (f : α → ℤ) (hf : ∀ a, 0 ≤ f a) (hf' : ∀ a, f a < 1) (a : α) : 0 ≤ 2 * f a :=
begin
lift f to α → ℕ using hf,
guard_target ((0:ℤ) ≤ 2 * (λ i : α, (f i : ℤ)) a),
guard_hyp hf' : ∀ a, ((λ i : α, (f i:ℤ)) a) < 1,
exact int.coe_nat_nonneg _
end
-- fail gracefully when the lifted variable is a local definition
example : let n : ℤ := 3 in n = n :=
begin
intro n,
success_if_fail_with_msg { lift n to ℕ }
("Cannot substitute variable n, it is a local definition. " ++
"If you really want to do this, use `clear_value` first."),
refl
end
instance can_lift_unit : can_lift unit unit :=
⟨id, λ x, true, λ x _, ⟨x, rfl⟩⟩
/- test whether new instances of `can_lift` are added as simp lemmas -/
run_cmd do l ← can_lift_attr.get_cache, guard (`can_lift_unit ∈ l)
/- test error messages -/
example (n : ℤ) (hn : 0 < n) : true :=
begin
success_if_fail_with_msg {lift n to ℕ using hn} "lift tactic failed.
invalid type ascription, term has type\n 0 < n\nbut is expected to have type\n 0 ≤ n",
success_if_fail_with_msg {lift (n : option ℤ) to ℕ}
"Failed to find a lift from option ℤ to ℕ. Provide an instance of\n can_lift (option ℤ) ℕ",
trivial
end
example (n : ℤ) : ℕ :=
begin
success_if_fail_with_msg {lift n to ℕ}
"lift tactic failed. Tactic is only applicable when the target is a proposition.",
exact 0
end
instance can_lift_subtype (R : Type*) (P : R → Prop) : can_lift R {x // P x} :=
{ coe := coe,
cond := λ x, P x,
prf := λ x hx, ⟨⟨x, hx⟩, rfl⟩ }
instance can_lift_set (R : Type*) (s : set R) : can_lift R s :=
{ coe := coe,
cond := λ x, x ∈ s,
prf := λ x hx, ⟨⟨x, hx⟩, rfl⟩ }
example {R : Type*} {P : R → Prop} (x : R) (hx : P x) : true :=
by { lift x to {x // P x} using hx with y, trivial }
/-! Test that `lift` elaborates `s` as a type, not as a set. -/
example {R : Type*} {s : set R} (x : R) (hx : x ∈ s) : true :=
by { lift x to s using hx with y, trivial }
example (n : ℤ) (hn : 0 ≤ n) : true :=
by { lift n to ℕ, trivial, exact hn }
example (n : ℤ) (hn : 0 ≤ n) : true :=
by { lift n to ℕ using hn, trivial }
example (n : ℤ) (hn : n ≥ 0) : true :=
by { lift n to ℕ using ge.le _, trivial, guard_target (n ≥ 0), exact hn }
example (n : ℤ) (hn : 0 ≤ 1 * n) : true :=
begin
lift n to ℕ using by { simpa [int.one_mul] using hn } with k,
-- the above braces are optional, but it would be bad style to remove them (see next example)
guard_hyp hn : 0 ≤ 1 * ((k : ℕ) : ℤ),
trivial
end
example (n : ℤ) (hn : 0 ≤ n ↔ true) : true :=
begin
lift n to ℕ using by { simp [hn] } with k, -- the braces are not optional here
trivial
end
|
28139232eedda28a608c4d47c0be3f9f7dc9d16a | b074a51e20fdb737b2d4c635dd292fc54685e010 | /src/analysis/convex.lean | a5f41b295721c3d8e6bb31f5f7b091d2534b0acb | [
"Apache-2.0"
] | permissive | minchaowu/mathlib | 2daf6ffdb5a56eeca403e894af88bcaaf65aec5e | 879da1cf04c2baa9eaa7bd2472100bc0335e5c73 | refs/heads/master | 1,609,628,676,768 | 1,564,310,105,000 | 1,564,310,105,000 | 99,461,307 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 27,711 | lean | /-
Copyright (c) 2019 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp
Convex sets and functions on real vector spaces
-/
import analysis.normed_space.basic
import data.complex.basic
import data.set.intervals
import tactic.interactive
import tactic.linarith
import linear_algebra.basic
import ring_theory.algebra
local attribute [instance] classical.prop_decidable
open set
section vector_space
variables {α : Type*} {β : Type*} {ι : Sort _}
[add_comm_group α] [vector_space ℝ α] [add_comm_group β] [vector_space ℝ β]
(A : set α) (B : set α) (x : α)
/-- Convexity of sets -/
def convex (A : set α) :=
∀ (x y : α) (a b : ℝ), x ∈ A → y ∈ A → 0 ≤ a → 0 ≤ b → a + b = 1 →
a • x + b • y ∈ A
/-- Alternative definition of set convexity -/
lemma convex_iff:
convex A ↔ ∀ {x y : α} {θ : ℝ},
x ∈ A → y ∈ A → 0 ≤ θ → θ ≤ 1 → θ • x + (1 - θ) • y ∈ A :=
⟨begin
assume h x y θ hx hy hθ₁ hθ₂,
have hθ₂ : 0 ≤ 1 - θ, by linarith,
exact (h _ _ _ _ hx hy hθ₁ hθ₂ (by linarith))
end,
begin
assume h x y a b hx hy ha hb hab,
have ha' : a ≤ 1, by linarith,
have hb' : b = 1 - a, by linarith,
rw hb',
exact h hx hy ha ha'
end⟩
/-- Another alternative definition of set convexity -/
lemma convex_iff_div:
convex A ↔ ∀ {x y : α} {a : ℝ} {b : ℝ},
x ∈ A → y ∈ A → 0 ≤ a → 0 ≤ b → 0 < a + b → (a/(a+b)) • x + (b/(a+b)) • y ∈ A :=
⟨begin
assume h x y a b hx hy ha hb hab,
apply h _ _ _ _ hx hy,
have ha', from mul_le_mul_of_nonneg_left ha (le_of_lt (inv_pos hab)),
rwa [mul_zero, ←div_eq_inv_mul] at ha',
have hb', from mul_le_mul_of_nonneg_left hb (le_of_lt (inv_pos hab)),
rwa [mul_zero, ←div_eq_inv_mul] at hb',
rw [←add_div],
exact div_self (ne_of_lt hab).symm
end,
begin
assume h x y a b hx hy ha hb hab,
have h', from h hx hy ha hb,
rw [hab, div_one, div_one] at h',
exact h' zero_lt_one
end⟩
local notation `I` := (Icc 0 1 : set ℝ)
/-- Segments in a vector space -/
def segment (x y : α) := {z : α | ∃ l : ℝ, l ∈ I ∧ z - x = l•(y-x)}
local notation `[`x `, ` y `]` := segment x y
lemma left_mem_segment (x y : α) : x ∈ [x, y] := ⟨0, ⟨⟨le_refl _, zero_le_one⟩, by simp⟩⟩
lemma right_mem_segment (x y : α) : y ∈ [x, y] := ⟨1, ⟨⟨zero_le_one, le_refl _⟩, by simp⟩⟩
lemma mem_segment_iff {x y z : α} : z ∈ [x, y] ↔ ∃ l ∈ I, z = x + l•(y - x) :=
by split; rintro ⟨l, l_in, H⟩; use [l, l_in]; try { rw sub_eq_iff_eq_add at H }; rw H; abel
lemma mem_segment_iff' {x y z : α} : z ∈ [x, y] ↔ ∃ l ∈ I, z = ((1:ℝ)-l)•x + l•y :=
begin
split; rintro ⟨l, l_in, H⟩; use [l, l_in]; try { rw sub_eq_iff_eq_add at H }; rw H;
simp only [smul_sub, sub_smul, one_smul]; abel,
end
lemma segment_symm (x y : α) : [x, y] = [y, x] :=
begin
ext z,
rw [mem_segment_iff', mem_segment_iff'],
split,
all_goals {
rintro ⟨l, ⟨hl₀, hl₁⟩, h⟩,
use (1-l),
split,
split; linarith,
rw [h]; simp },
end
lemma segment_eq_Icc {a b : ℝ} (h : a ≤ b) : [a, b] = Icc a b :=
begin
ext z,
rw mem_segment_iff,
split,
{ rintro ⟨l, ⟨hl₀, hl₁⟩, H⟩,
rw smul_eq_mul at H,
have hba : 0 ≤ b - a, by linarith,
split ; rw H,
{ have := mul_le_mul (le_refl l) hba (le_refl _) hl₀,
simpa using this, },
{ have := mul_le_mul hl₁ (le_refl (b-a)) hba zero_le_one,
rw one_mul at this,
apply le_trans (add_le_add (le_refl a) this),
convert le_refl _,
show b = a + (b-a), by ring } },
{ rintro ⟨hza, hzb⟩,
by_cases hba : b-a = 0,
{ use [(0:ℝ), ⟨le_refl 0, zero_le_one⟩],
rw zero_smul, linarith },
{ have : (z-a)/(b-a) ∈ I,
{ change b -a ≠ 0 at hba,
have : 0 < b - a, from lt_of_le_of_ne (by linarith) hba.symm,
split,
apply div_nonneg ; linarith,
apply (div_le_iff this).2,
simp, convert hzb },
use [(z-a)/(b-a), this],
rw [smul_eq_mul, div_mul_cancel],
ring,
exact hba } }
end
lemma segment_translate (a b c x : α) (hx : x ∈ [b, c]) : a + x ∈ [a + b, a + c] :=
begin
refine exists.elim hx (λθ hθ, ⟨θ, ⟨hθ.1, _⟩⟩),
simp only [smul_sub, smul_add] at *,
simp [smul_add, (add_eq_of_eq_sub hθ.2.symm).symm]
end
lemma segment_translate_image (a b c: α) : (λx, a + x) '' [b, c] = [a + b, a + c] :=
begin
apply subset.antisymm,
{ intros z hz,
apply exists.elim hz,
intros x hx,
convert segment_translate a b c x _,
{ exact hx.2.symm },
{ exact hx.1 } },
{ intros z hz,
apply exists.elim hz,
intros θ hθ,
use z - a,
apply and.intro,
{ convert segment_translate (-a) (a + b) (a + c) z hz; simp },
{ simp only [add_sub_cancel'_right] } }
end
lemma image_Icc_zero_one_eq_segment {x y : α} :
(λ (t : ℝ), x + t • (y - x)) '' Icc 0 1 = segment x y :=
begin
apply subset.antisymm,
{ intros z hz,
apply exists.elim hz,
intros x hx,
use x,
simp [hx.2.symm, hx.1] },
{ intros z hz,
apply exists.elim hz,
intros a ha,
exact ⟨a, ha.1, add_eq_of_eq_sub' (eq.symm ha.2)⟩ }
end
/-- Alternative defintion of set convexity using segments -/
lemma convex_segment_iff : convex A ↔ ∀ x y ∈ A, [x, y] ⊆ A :=
begin
apply iff.intro,
{ intros hA x y hx hy z hseg,
apply exists.elim hseg,
intros l hl,
have hz : z = l • y + (1-l) • x,
{ rw sub_eq_iff_eq_add.1 hl.2,
rw [smul_sub, sub_smul, one_smul],
simp },
rw hz,
apply (convex_iff A).1 hA hy hx hl.1.1 hl.1.2 },
{ intros hA,
rw convex_iff,
intros x y θ hx hy hθ₀ hθ₁,
apply hA y x hy hx,
use θ,
apply and.intro,
{ exact and.intro hθ₀ hθ₁ },
{ simp only [smul_sub, sub_smul, one_smul],
simp } }
end
/- Examples of convex sets -/
lemma convex_empty : convex (∅ : set α) := by finish
lemma convex_singleton (a : α) : convex ({a} : set α) :=
begin
intros x y a b hx hy ha hb hab,
rw [set.eq_of_mem_singleton hx, set.eq_of_mem_singleton hy, ←add_smul, hab],
simp
end
lemma convex_univ : convex (set.univ : set α) := by finish
lemma convex_inter (hA: convex A) (hB: convex B) : convex (A ∩ B) :=
λ x y a b (hx : x ∈ A ∩ B) (hy : y ∈ A ∩ B) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1),
⟨hA _ _ _ _ hx.left hy.left ha hb hab, hB _ _ _ _ hx.right hy.right ha hb hab⟩
lemma convex_Inter {s: ι → set α} (h: ∀ i : ι, convex (s i)) : convex (Inter s) :=
begin
intros x y a b hx hy ha hb hab,
apply mem_Inter.2,
exact λi, h i _ _ _ _ (mem_Inter.1 hx i) (mem_Inter.1 hy i) ha hb hab
end
lemma convex_prod {A : set α} {B : set β} (hA : convex A) (hB : convex B) :
convex (set.prod A B) :=
begin
intros x y a b hx hy ha hb hab,
apply mem_prod.2,
exact ⟨hA _ _ _ _ (mem_prod.1 hx).1 (mem_prod.1 hy).1 ha hb hab,
hB _ _ _ _ (mem_prod.1 hx).2 (mem_prod.1 hy).2 ha hb hab⟩
end
lemma convex_linear_image (f : α → β) (hf : is_linear_map ℝ f) (hA : convex A) : convex (image f A) :=
begin
intros x y a b hx hy ha hb hab,
apply exists.elim hx,
intros x' hx',
apply exists.elim hy,
intros y' hy',
use a • x' + b • y',
split,
{ apply hA _ _ _ _ hx'.1 hy'.1 ha hb hab },
{ simp [hx',hy',hf.add,hf.smul] }
end
lemma convex_linear_image' (f : α →ₗ[ℝ] β) (hA : convex A) : convex (image f A) :=
convex_linear_image A f.to_fun (linear_map.is_linear f) hA
lemma convex_linear_preimage (A : set β) (f : α → β) (hf : is_linear_map ℝ f) (hA : convex A) :
convex (preimage f A) :=
begin
intros x y a b hx hy ha hb hab,
simp [hf.add, hf.smul],
exact hA (f x) (f y) a b hx hy ha hb hab
end
lemma convex_linear_preimage' (A : set β) (f : α →ₗ[ℝ] β) (hA : convex A) :
convex (preimage f A) :=
convex_linear_preimage A f.to_fun (linear_map.is_linear f) hA
lemma convex_neg : convex A → convex ((λ z, -z) '' A) :=
convex_linear_image _ _ is_linear_map.is_linear_map_neg
lemma convex_neg_preimage : convex A → convex ((λ z, -z) ⁻¹' A) :=
convex_linear_preimage _ _ is_linear_map.is_linear_map_neg
lemma convex_smul (c : ℝ) : convex A → convex ((λ z, c • z) '' A) :=
convex_linear_image _ _ (is_linear_map.is_linear_map_smul c)
lemma convex_smul_preimage (c : ℝ) : convex A → convex ((λ z, c • z) ⁻¹' A) :=
convex_linear_preimage _ _ (is_linear_map.is_linear_map_smul _)
lemma convex_add (hA : convex A) (hB : convex B) :
convex ((λx : α × α, x.1 + x.2) '' (set.prod A B)) :=
begin
apply convex_linear_image (set.prod A B) (λx : α × α, x.1 + x.2) is_linear_map.is_linear_map_add,
exact convex_prod hA hB
end
lemma convex_sub (hA : convex A) (hB : convex B) :
convex ((λx : α × α, x.1 - x.2) '' (set.prod A B)) :=
begin
apply convex_linear_image (set.prod A B) (λx : α × α, x.1 - x.2) is_linear_map.is_linear_map_sub,
exact convex_prod hA hB
end
lemma convex_translation (z : α) (hA : convex A) : convex ((λx, z + x) '' A) :=
begin
have h : convex ((λ (x : α × α), x.fst + x.snd) '' set.prod (insert z ∅) A),
from convex_add {z} A (convex_singleton z) hA,
show convex ((λx, z + x) '' A),
{ rw [@insert_prod _ _ z ∅ A, set.empty_prod, set.union_empty, ←image_comp] at h,
simp at h,
exact h }
end
lemma convex_affinity (z : α) (c : ℝ) (hA : convex A) : convex ((λx, z + c • x) '' A) :=
begin
have h : convex ((λ (x : α), z + x) '' ((λ (z : α), c • z) '' A)),
from convex_translation _ z (convex_smul A c hA),
show convex ((λx, z + c • x) '' A),
{ rw [←image_comp] at h,
simp at h,
exact h }
end
lemma convex_Iio (r : ℝ) : convex (Iio r) :=
begin
intros x y a b hx hy ha hb hab,
wlog h : x ≤ y using [x y a b, y x b a],
exact le_total _ _,
calc
a * x + b * y ≤ a * y + b * y : add_le_add_right (mul_le_mul_of_nonneg_left h ha) _
... = y : by rw [←add_mul a b y, hab, one_mul]
... < r : hy
end
lemma convex_Iic (r : ℝ) : convex (Iic r) :=
begin
intros x y a b hx hy ha hb hab,
wlog h : x ≤ y using [x y a b, y x b a],
exact le_total _ _,
calc
a * x + b * y ≤ a * y + b * y : add_le_add_right (mul_le_mul_of_nonneg_left h ha) _
... = y : by rw [←add_mul a b y, hab, one_mul]
... ≤ r : hy
end
lemma convex_Ioi (r : ℝ) : convex (Ioi r) :=
begin
rw [← neg_neg r],
rw (image_neg_Iio (-r)).symm,
unfold convex,
intros x y a b hx hy ha hb hab,
exact convex_linear_image _ _ is_linear_map.is_linear_map_neg (convex_Iio (-r)) _ _ _ _ hx hy ha hb hab
end
lemma convex_Ici (r : ℝ) : convex (Ici r) :=
begin
rw [← neg_neg r],
rw (image_neg_Iic (-r)).symm,
unfold convex,
intros x y a b hx hy ha hb hab,
exact convex_linear_image _ _ is_linear_map.is_linear_map_neg (convex_Iic (-r)) _ _ _ _ hx hy ha hb hab
end
lemma convex_Ioo (r : ℝ) (s : ℝ) : convex (Ioo r s) :=
convex_inter _ _ (convex_Ioi _) (convex_Iio _)
lemma convex_Ico (r : ℝ) (s : ℝ) : convex (Ico r s) :=
convex_inter _ _ (convex_Ici _) (convex_Iio _)
lemma convex_Ioc (r : ℝ) (s : ℝ) : convex (Ioc r s) :=
convex_inter _ _ (convex_Ioi _) (convex_Iic _)
lemma convex_Icc (r : ℝ) (s : ℝ) : convex (Icc r s) :=
convex_inter _ _ (convex_Ici _) (convex_Iic _)
lemma convex_segment (a b : α) : convex [a, b] :=
begin
have : (λ (t : ℝ), a + t • (b - a)) = (λz : α, a + z) ∘ (λt:ℝ, t • (b - a)) := rfl,
rw [← image_Icc_zero_one_eq_segment, this, image_comp],
apply convex_translation _ _ (convex_linear_image _ _ _ (convex_Icc _ _)),
exact is_linear_map.is_linear_map_smul' _
end
lemma convex_halfspace_lt (f : α → ℝ) (h : is_linear_map ℝ f) (r : ℝ) :
convex {w | f w < r} :=
begin
assume x y a b hx hy ha hb hab,
simp,
rw [is_linear_map.add ℝ f, is_linear_map.smul f a, is_linear_map.smul f b],
apply convex_Iio _ _ _ _ _ hx hy ha hb hab
end
lemma convex_halfspace_le (f : α → ℝ) (h : is_linear_map ℝ f) (r : ℝ) :
convex {w | f w ≤ r} :=
begin
assume x y a b hx hy ha hb hab,
simp,
rw [is_linear_map.add ℝ f, is_linear_map.smul f a, is_linear_map.smul f b],
apply convex_Iic _ _ _ _ _ hx hy ha hb hab
end
lemma convex_halfspace_gt (f : α → ℝ) (h : is_linear_map ℝ f) (r : ℝ) :
convex {w | r < f w} :=
begin
assume x y a b hx hy ha hb hab,
simp,
rw [is_linear_map.add ℝ f, is_linear_map.smul f a, is_linear_map.smul f b],
apply convex_Ioi _ _ _ _ _ hx hy ha hb hab
end
lemma convex_halfspace_ge (f : α → ℝ) (h : is_linear_map ℝ f) (r : ℝ) :
convex {w | r ≤ f w} :=
begin
assume x y a b hx hy ha hb hab,
simp,
rw [is_linear_map.add ℝ f, is_linear_map.smul f a, is_linear_map.smul f b],
apply convex_Ici _ _ _ _ _ hx hy ha hb hab
end
lemma convex_halfplane (f : α → ℝ) (h : is_linear_map ℝ f) (r : ℝ) :
convex {w | f w = r} :=
begin
assume x y a b hx hy ha hb hab,
simp at *,
rw [is_linear_map.add ℝ f, is_linear_map.smul f a, is_linear_map.smul f b],
rw [hx, hy, (add_smul a b r).symm, hab, one_smul]
end
lemma convex_halfspace_re_lt (r : ℝ) : convex {c : ℂ | c.re < r} :=
convex_halfspace_lt _ (is_linear_map.mk complex.add_re complex.smul_re) _
lemma convex_halfspace_re_le (r : ℝ) : convex {c : ℂ | c.re ≤ r} :=
convex_halfspace_le _ (is_linear_map.mk complex.add_re complex.smul_re) _
lemma convex_halfspace_re_gt (r : ℝ) : convex {c : ℂ | r < c.re } :=
convex_halfspace_gt _ (is_linear_map.mk complex.add_re complex.smul_re) _
lemma convex_halfspace_re_lge (r : ℝ) : convex {c : ℂ | r ≤ c.re} :=
convex_halfspace_ge _ (is_linear_map.mk complex.add_re complex.smul_re) _
lemma convex_halfspace_im_lt (r : ℝ) : convex {c : ℂ | c.im < r} :=
convex_halfspace_lt _ (is_linear_map.mk complex.add_im complex.smul_im) _
lemma convex_halfspace_im_le (r : ℝ) : convex {c : ℂ | c.im ≤ r} :=
convex_halfspace_le _ (is_linear_map.mk complex.add_im complex.smul_im) _
lemma convex_halfspace_im_gt (r : ℝ) : convex {c : ℂ | r < c.im } :=
convex_halfspace_gt _ (is_linear_map.mk complex.add_im complex.smul_im) _
lemma convex_halfspace_im_lge (r : ℝ) : convex {c : ℂ | r ≤ c.im} :=
convex_halfspace_ge _ (is_linear_map.mk complex.add_im complex.smul_im) _
lemma convex_sum {γ : Type*} (hA : convex A) (z : γ → α) (s : finset γ) :
∀ a : γ → ℝ, s.sum a = 1 → (∀ i ∈ s, 0 ≤ a i) → (∀ i ∈ s, z i ∈ A) → s.sum (λi, a i • z i) ∈ A :=
begin
refine finset.induction _ _ s,
{ intros _ h_sum,
simp at h_sum,
exact false.elim h_sum },
{ intros k s hks ih a h_sum ha hz,
by_cases h_cases : s.sum a = 0,
{ have hak : a k = 1,
by rwa [finset.sum_insert hks, h_cases, add_zero] at h_sum,
have ha': ∀ i ∈ s, 0 ≤ a i,
from λ i hi, ha i (finset.mem_insert_of_mem hi),
have h_a0: ∀ i ∈ s, a i = 0,
from (finset.sum_eq_zero_iff_of_nonneg ha').1 h_cases,
have h_az0: ∀ i ∈ s, a i • z i = 0,
{ intros i hi,
rw h_a0 i hi,
exact zero_smul _ (z i) },
show finset.sum (insert k s) (λ (i : γ), a i • z i) ∈ A,
{ rw [finset.sum_insert hks, hak, finset.sum_eq_zero h_az0],
simp,
exact hz k (finset.mem_insert_self k s) } },
{ have h_sum_nonneg : 0 ≤ s.sum a,
{ apply finset.zero_le_sum',
intros i hi,
apply ha _ (finset.mem_insert_of_mem hi) },
have h_div_in_A: s.sum (λ (i : γ), ((s.sum a)⁻¹ * a i) • z i) ∈ A,
{ apply ih,
{ rw finset.mul_sum.symm,
exact division_ring.inv_mul_cancel h_cases },
{ intros i hi,
exact zero_le_mul (inv_nonneg.2 h_sum_nonneg) (ha i (finset.mem_insert_of_mem hi))},
{ intros i hi,
exact hz i (finset.mem_insert_of_mem hi) } },
have h_sum_in_A: a k • z k
+ finset.sum s a • finset.sum s (λ (i : γ), ((finset.sum s a)⁻¹ * a i) • z i) ∈ A,
{ apply hA,
exact hz k (finset.mem_insert_self k s),
exact h_div_in_A,
exact ha k (finset.mem_insert_self k s),
exact h_sum_nonneg,
rw (finset.sum_insert hks).symm,
exact h_sum },
show finset.sum (insert k s) (λ (i : γ), a i • z i) ∈ A,
{ rw finset.sum_insert hks,
rw finset.smul_sum at h_sum_in_A,
simp [smul_smul, (mul_assoc (s.sum a) _ _).symm] at h_sum_in_A,
conv
begin
congr,
congr,
skip,
congr, skip, funext,
rw (one_mul (a _)).symm,
rw (field.mul_inv_cancel h_cases).symm,
end,
exact h_sum_in_A } } }
end
lemma convex_sum_iff :
convex A ↔
(∀ (s : finset α) (as : α → ℝ),
s.sum as = 1 → (∀ i ∈ s, 0 ≤ as i) → (∀ x ∈ s, x ∈ A) → s.sum (λx, as x • x) ∈ A ) :=
begin
apply iff.intro,
{ intros hA s as h_sum has hs,
exact convex_sum A hA id s _ h_sum has hs },
{ intros h,
intros x y a b hx hy ha hb hab,
by_cases h_cases: x = y,
{ rw [h_cases, ←add_smul, hab, one_smul], exact hy },
{ let s := insert x (finset.singleton y),
have h_sum_eq_add : finset.sum s (λ z, ite (x = z) a b • z) = a • x + b • y,
{ rw [finset.sum_insert (finset.not_mem_singleton.2 h_cases),
finset.sum_singleton],
simp [h_cases] },
rw h_sum_eq_add.symm,
apply h s,
{ rw [finset.sum_insert (finset.not_mem_singleton.2 h_cases),
finset.sum_singleton],
simp [h_cases],
exact hab },
{ intros k hk,
by_cases h_cases : x = k,
{ simp [h_cases], exact ha },
{ simp [h_cases], exact hb } },
{ intros z hz,
apply or.elim (finset.mem_insert.1 hz),
{ intros h_eq, rw h_eq, exact hx },
{ intros h_eq, rw finset.mem_singleton at h_eq, rw h_eq, exact hy } } } }
end
variables (D: set α) (D': set α) (f : α → ℝ) (g : α → ℝ)
/-- Convexity of functions -/
def convex_on (f : α → ℝ) : Prop :=
convex D ∧
∀ (x y : α) (a b : ℝ), x ∈ D → y ∈ D → 0 ≤ a → 0 ≤ b → a + b = 1 →
f (a • x + b • y) ≤ a * f x + b * f y
lemma convex_on_iff :
convex_on D f ↔ convex D ∧ ∀ {x y : α} {θ : ℝ},
x ∈ D → y ∈ D → 0 ≤ θ → θ ≤ 1 → f (θ • x + (1 - θ) • y) ≤ θ * f x + (1 - θ) * f y :=
⟨begin
intro h,
apply and.intro h.1,
intros x y θ hx hy hθ₁ hθ₂,
have hθ₂: 0 ≤ 1 - θ, by linarith,
exact (h.2 _ _ _ _ hx hy hθ₁ hθ₂ (by linarith))
end,
begin
intro h,
apply and.intro h.1,
assume x y a b hx hy ha hb hab,
have ha': a ≤ 1, by linarith,
have hb': b = 1 - a, by linarith,
rw hb',
exact (h.2 hx hy ha ha')
end⟩
lemma convex_on_iff_div:
convex_on D f ↔ convex D ∧ ∀ {x y : α} {a : ℝ} {b : ℝ},
x ∈ D → y ∈ D → 0 ≤ a → 0 ≤ b → 0 < a + b →
f ((a/(a+b)) • x + (b/(a+b)) • y) ≤ (a/(a+b)) * f x + (b/(a+b)) * f y :=
⟨begin
intro h,
apply and.intro h.1,
intros x y a b hx hy ha hb hab,
apply h.2 _ _ _ _ hx hy,
have ha', from mul_le_mul_of_nonneg_left ha (le_of_lt (inv_pos hab)),
rwa [mul_zero, ←div_eq_inv_mul] at ha',
have hb', from mul_le_mul_of_nonneg_left hb (le_of_lt (inv_pos hab)),
rwa [mul_zero, ←div_eq_inv_mul] at hb',
rw [←add_div],
exact div_self (ne_of_lt hab).symm
end,
begin
intro h,
apply and.intro h.1,
intros x y a b hx hy ha hb hab,
have h', from h.2 hx hy ha hb,
rw [hab, div_one, div_one] at h',
exact h' zero_lt_one
end⟩
lemma convex_on_sum {γ : Type} (s : finset γ) (z : γ → α) (hs : s ≠ ∅) :
∀ (a : γ → ℝ), convex_on D f → (∀ i ∈ s, 0 ≤ a i) → (∀ i ∈ s, z i ∈ D) → s.sum a = 1 →
f (s.sum (λi, a i • z i)) ≤ s.sum (λi, a i • f (z i)) :=
begin
refine finset.induction (by simp) _ s,
intros k s hks ih a hf ha hz h_sum,
by_cases h_cases : s.sum a = 0,
{ have hak : a k = 1,
by rwa [finset.sum_insert hks, h_cases, add_zero] at h_sum,
have ha': ∀ i ∈ s, 0 ≤ a i,
from λ i hi, ha i (finset.mem_insert_of_mem hi),
have h_a0: ∀ i ∈ s, a i = 0,
from (finset.sum_eq_zero_iff_of_nonneg ha').1 h_cases,
have h_az0: ∀ i ∈ s, a i • z i = 0,
{ intros i hi,
rw h_a0 i hi,
exact zero_smul _ _ },
have h_afz0: ∀ i ∈ s, a i • f (z i) = 0,
{ intros i hi,
rw h_a0 i hi,
exact zero_smul _ _ },
show f (finset.sum (insert k s) (λi, a i • z i)) ≤ finset.sum (insert k s) (λi, a i • f (z i)),
{ rw [finset.sum_insert hks, hak, finset.sum_eq_zero h_az0],
rw [finset.sum_insert hks, hak, finset.sum_eq_zero h_afz0],
simp } },
{ have h_sum_nonneg : 0 ≤ s.sum a ,
{ apply finset.zero_le_sum',
intros i hi,
apply ha _ (finset.mem_insert_of_mem hi) },
have ih_div: f (s.sum (λ (i : γ), ((s.sum a)⁻¹ * a i) • z i))
≤ s.sum (λ (i : γ), ((s.sum a)⁻¹ * a i) • f (z i)),
{ apply ih _ hf,
{ intros i hi,
exact zero_le_mul (inv_nonneg.2 h_sum_nonneg) (ha i (finset.mem_insert_of_mem hi))},
{ intros i hi,
exact hz i (finset.mem_insert_of_mem hi) },
{ rw finset.mul_sum.symm,
exact division_ring.inv_mul_cancel h_cases } },
have h_div_in_D: s.sum (λ (i : γ), ((s.sum a)⁻¹ * a i) • z i) ∈ D,
{ apply convex_sum _ hf.1,
{ rw finset.mul_sum.symm,
exact division_ring.inv_mul_cancel h_cases },
{ intros i hi,
exact zero_le_mul (inv_nonneg.2 h_sum_nonneg) (ha i (finset.mem_insert_of_mem hi))},
{ intros i hi,
exact hz i (finset.mem_insert_of_mem hi) } },
have hf': f (a k • z k + s.sum a • s.sum (λ (i : γ), ((finset.sum s a)⁻¹ * a i) • z i))
≤ a k • f (z k) + s.sum a • f (s.sum (λ (i : γ), ((finset.sum s a)⁻¹ * a i) • z i)),
{ apply hf.2,
exact hz k (finset.mem_insert_self k s),
exact h_div_in_D,
exact ha k (finset.mem_insert_self k s),
exact h_sum_nonneg,
rw (finset.sum_insert hks).symm,
exact h_sum },
have ih_div': f (a k • z k + s.sum a • s.sum (λ (i : γ), ((finset.sum s a)⁻¹ * a i) • z i))
≤ a k • f (z k) + s.sum a • s.sum (λ (i : γ), ((finset.sum s a)⁻¹ * a i) • f (z i)),
from trans hf' (add_le_add_left (mul_le_mul_of_nonneg_left ih_div h_sum_nonneg) _),
show f (finset.sum (insert k s) (λ (i : γ), a i • z i))
≤ finset.sum (insert k s) (λ (i : γ), a i • f (z i)),
{ simp [finset.sum_insert hks],
simp [finset.smul_sum] at ih_div',
simp [smul_smul, (mul_assoc (s.sum a) _ _).symm] at ih_div',
convert ih_div',
repeat { apply funext,
intro i,
rw [field.mul_inv_cancel, one_mul],
exact h_cases } } }
end
lemma convex_on_linorder [hα : linear_order α] (f : α → ℝ) : convex_on D f ↔
convex D ∧ ∀ (x y : α) (a b : ℝ), x ∈ D → y ∈ D → x < y → a ≥ 0 → b ≥ 0 → a + b = 1 →
f (a • x + b • y) ≤ a * f x + b * f y :=
begin
apply iff.intro,
{ intro h,
apply and.intro h.1,
intros x y a b hx hy hxy ha hb hab,
exact h.2 x y a b hx hy ha hb hab },
{ intro h,
apply and.intro h.1,
intros x y a b hx hy ha hb hab,
wlog hxy : x<=y using [x y a b, y x b a],
exact le_total _ _,
apply or.elim (lt_or_eq_of_le hxy),
{ intros hxy, exact h.2 x y a b hx hy hxy ha hb hab },
{ intros hxy, rw [hxy,←add_smul, hab, one_smul,←add_mul,hab,one_mul] } }
end
lemma convex_on_subset (h_convex_on : convex_on D f) (h_subset : A ⊆ D) (h_convex : convex A) :
convex_on A f :=
begin
apply and.intro h_convex,
intros x y a b hx hy,
exact h_convex_on.2 x y a b (h_subset hx) (h_subset hy),
end
lemma convex_on_add (hf : convex_on D f) (hg : convex_on D g) : convex_on D (λx, f x + g x) :=
begin
apply and.intro hf.1,
intros x y a b hx hy ha hb hab,
calc
f (a • x + b • y) + g (a • x + b • y) ≤ (a * f x + b * f y) + (a * g x + b * g y)
: add_le_add (hf.2 x y a b hx hy ha hb hab) (hg.2 x y a b hx hy ha hb hab)
... = a * f x + a * g x + b * f y + b * g y : by linarith
... = a * (f x + g x) + b * (f y + g y) : by simp [mul_add]
end
lemma convex_on_smul (c : ℝ) (hc : 0 ≤ c) (hf : convex_on D f) : convex_on D (λx, c * f x) :=
begin
apply and.intro hf.1,
intros x y a b hx hy ha hb hab,
calc
c * f (a • x + b • y) ≤ c * (a * f x + b * f y)
: mul_le_mul_of_nonneg_left (hf.2 x y a b hx hy ha hb hab) hc
... = a * (c * f x) + b * (c * f y) : by rw mul_add; ac_refl
end
lemma convex_le_of_convex_on (hf : convex_on D f) (r : ℝ) : convex {x ∈ D | f x ≤ r} :=
begin
intros x y a b hx hy ha hb hab,
simp at *,
apply and.intro,
{ exact hf.1 x y a b hx.1 hy.1 ha hb hab },
{ apply le_trans (hf.2 x y a b hx.1 hy.1 ha hb hab),
wlog h_wlog : f x ≤ f y using [x y a b, y x b a],
apply le_total,
calc
a * f x + b * f y ≤ a * f y + b * f y :
add_le_add (mul_le_mul_of_nonneg_left h_wlog ha) (le_refl _)
... = (a + b) * f y : (add_mul _ _ _).symm
... ≤ r : by rw [hab, one_mul]; exact hy.2 }
end
lemma convex_lt_of_convex_on (hf : convex_on D f) (r : ℝ) : convex {x ∈ D | f x < r} :=
begin
intros x y a b hx hy ha hb hab,
simp at *,
apply and.intro,
{ exact hf.1 x y a b hx.1 hy.1 ha hb hab },
{ apply lt_of_le_of_lt (hf.2 x y a b hx.1 hy.1 ha hb hab),
wlog h_wlog : f x ≤ f y using [x y a b, y x b a],
apply le_total,
calc
a * f x + b * f y ≤ a * f y + b * f y :
add_le_add (mul_le_mul_of_nonneg_left h_wlog ha) (le_refl _)
... = (a + b) * f y : (add_mul _ _ _).symm
... < r : by rw [hab, one_mul]; exact hy.2 }
end
lemma le_on_interval_of_convex_on (x y : α) (a b : ℝ)
(hf : convex_on D f) (hx : x ∈ D) (hy : y ∈ D) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) :
f (a • x + b • y) ≤ max (f x) (f y) :=
calc
f (a • x + b • y) ≤ a * f x + b * f y : hf.2 x y a b hx hy ha hb hab
... ≤ a * max (f x) (f y) + b * max (f x) (f y) :
add_le_add (mul_le_mul_of_nonneg_left (le_max_left _ _) ha) (mul_le_mul_of_nonneg_left (le_max_right _ _) hb)
... ≤ max (f x) (f y) : by rw [←add_mul, hab, one_mul]
end vector_space
section normed_space
variables {α : Type*} [normed_group α] [normed_space ℝ α]
lemma convex_on_dist (z : α) (D : set α) (hD : convex D) :
convex_on D (λz', dist z' z) :=
begin
apply and.intro hD,
intros x y a b hx hy ha hb hab,
calc
dist (a • x + b • y) z = ∥ (a • x + b • y) - (a + b) • z ∥ :
by rw [hab, one_smul, normed_group.dist_eq]
... = ∥a • (x - z) + b • (y - z)∥ :
by rw [add_smul, smul_sub, smul_sub]; simp
... ≤ ∥a • (x - z)∥ + ∥b • (y - z)∥ :
norm_triangle (a • (x - z)) (b • (y - z))
... = a * dist x z + b * dist y z :
by simp [norm_smul, normed_group.dist_eq, real.norm_eq_abs, abs_of_nonneg ha, abs_of_nonneg hb]
end
lemma convex_ball (a : α) (r : ℝ) : convex (metric.ball a r) :=
by simpa using convex_lt_of_convex_on univ (λb, dist b a) (convex_on_dist _ _ convex_univ) r
lemma convex_closed_ball (a : α) (r : ℝ) : convex (metric.closed_ball a r) :=
by simpa using convex_le_of_convex_on univ (λb, dist b a) (convex_on_dist _ _ convex_univ) r
end normed_space
|
23a12734916ddb71b879f75fa2e65f9dbc692cfa | e1da55f4222dac91b940ca052928eaace09762da | /src/witness.lean | 8ef553a2aaea1362bd67cbc48f17f5bc917c8e3e | [] | no_license | b-mehta/regularity-lemma | c5826e22c280d0b073a4e62dba731f4dd3d1b69f | cf26082b0c88fa54276e6fdc3338c15e607c52c6 | refs/heads/master | 1,658,209,524,267 | 1,644,406,456,000 | 1,644,406,456,000 | 457,327,371 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,528 | 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 .mathlib
/-!
# Witnesses of non uniformity
-/
open_locale classical
variables {α : Type*}
namespace simple_graph
variables (G : simple_graph α)
lemma not_witness_prop {G : simple_graph α} {ε : ℝ} {U V : finset α} (h : ¬G.is_uniform ε U V) :
∃ U', U' ⊆ U ∧ ∃ V', V' ⊆ V ∧ ↑U.card * ε ≤ U'.card ∧ ↑V.card * ε ≤ V'.card ∧
ε ≤ |G.edge_density U' V' - G.edge_density U V| :=
by { rw [is_uniform] at h, push_neg at h, exact h }
/-- Extracts a witness of the non-uniformity of `(U, V)`. Witnesses for `(U, V)` and `(V, U)` don't
necessarily match. Hence the motivation to define `witness_aux`. -/
noncomputable def witness_aux (ε : ℝ) (U V : finset α) : finset α × finset α :=
if h : ¬G.is_uniform ε U V
then ((not_witness_prop h).some, (not_witness_prop h).some_spec.2.some)
else (U, V)
/-- Extracts a witness of the non-uniformity of `(U, V)`. It uses an arbitrary ordering of
`finset α` (`well_ordering_rel`) to ensure that the witnesses of `(U, V)` and `(V, U)` are related
(the existentials don't ensure we would take the same from `¬G.is_uniform ε U V` and
`¬G.is_uniform ε V U`). -/
noncomputable def witness (ε : ℝ) (U V : finset α) : finset α :=
ite (well_ordering_rel U V) (G.witness_aux ε U V).1 (G.witness_aux ε V U).2
variables (G) {ε : ℝ} {U V : finset α}
lemma left_witness_aux_subset (h : ¬G.is_uniform ε U V) : (G.witness_aux ε U V).1 ⊆ U :=
by { rw [witness_aux, dif_pos h], apply (not_witness_prop h).some_spec.1 }
lemma left_witness_aux_card (h : ¬ G.is_uniform ε U V) :
(U.card : ℝ) * ε ≤ (G.witness_aux ε U V).1.card :=
by { rw [witness_aux, dif_pos h], apply (not_witness_prop h).some_spec.2.some_spec.2.1 }
lemma right_witness_aux_subset (h : ¬ G.is_uniform ε U V) : (G.witness_aux ε U V).2 ⊆ V :=
by { rw [witness_aux, dif_pos h], apply (not_witness_prop h).some_spec.2.some_spec.1 }
lemma right_witness_aux_card (h : ¬ G.is_uniform ε U V) :
(V.card : ℝ) * ε ≤ (G.witness_aux ε U V).2.card :=
by { rw [witness_aux, dif_pos h], apply (not_witness_prop h).some_spec.2.some_spec.2.2.1 }
lemma witness_aux_pair_spec (h : ¬ G.is_uniform ε U V) :
ε ≤ |G.edge_density (G.witness_aux ε U V).1 (G.witness_aux ε U V).2 - G.edge_density U V| :=
by { rw [witness_aux, dif_pos h], apply (not_witness_prop h).some_spec.2.some_spec.2.2.2 }
lemma witness_subset (h : ¬ G.is_uniform ε U V) : G.witness ε U V ⊆ U :=
begin
dsimp [witness],
split_ifs,
{ apply G.left_witness_aux_subset h },
{ apply G.right_witness_aux_subset (λ i, h i.symm) },
end
lemma witness_card (h : ¬ G.is_uniform ε U V) : (U.card : ℝ) * ε ≤ (G.witness ε U V).card :=
begin
dsimp [witness],
split_ifs,
{ apply G.left_witness_aux_card h },
{ apply G.right_witness_aux_card (λ i, h i.symm) }
end
lemma witness_pair_spec (h₁ : U ≠ V) (h₂ : ¬ G.is_uniform ε U V) :
ε ≤ |G.edge_density (G.witness ε U V) (G.witness ε V U) - G.edge_density U V| :=
begin
unfold witness,
rcases trichotomous_of well_ordering_rel U V with lt | rfl | gt,
{ rw [if_pos lt, if_neg (asymm lt)],
exact G.witness_aux_pair_spec h₂ },
{ cases h₁ rfl },
{ rw [if_neg (asymm gt), if_pos gt, edge_density_comm, edge_density_comm _ U],
apply G.witness_aux_pair_spec (λ i, h₂ i.symm) }
end
end simple_graph
|
e5cee6cc6c2999f7974142be1109ae4a555d5d78 | d7189ea2ef694124821b033e533f18905b5e87ef | /galois/list/filter_some.lean | 85be4577d5f14184293cccf8035110d81215b693 | [
"Apache-2.0"
] | permissive | digama0/lean-protocol-support | eaa7e6f8b8e0d5bbfff1f7f52bfb79a3b11b0f59 | cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda | refs/heads/master | 1,625,421,450,627 | 1,506,035,462,000 | 1,506,035,462,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 551 | lean | universes u
namespace list
def filter_some {A : Type u} : list (option A) → list A
| [] := []
| (mx :: xs) := (match mx with
| none := λ l, l
| some x := list.cons x
end) (filter_some xs)
lemma map_filter_some {A B} (f : A → B) (xs : list (option A))
: filter_some (map (option.map f) xs)
= map f (filter_some xs)
:= begin
induction xs; dsimp [list.map, option.map, option.bind, filter_some],
{ reflexivity },
{ induction a; dsimp [option.map, option.bind, function.comp, filter_some],
{ assumption },
{ rw ih_1 }
}
end
end list |
faa55138b3e27e052fcf341152031551cb910d4d | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/data/polynomial/laurent.lean | d89c24a6a75f0aba250c86c3751d40a96576c425 | [
"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,134 | lean | /-
Copyright (c) 2022 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import data.polynomial.algebra_map
import ring_theory.localization.basic
/-! # Laurent polynomials
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We introduce Laurent polynomials over a semiring `R`. Mathematically, they are expressions of the
form
$$
\sum_{i \in \mathbb{Z}} a_i T ^ i
$$
where the sum extends over a finite subset of `ℤ`. Thus, negative exponents are allowed. The
coefficients come from the semiring `R` and the variable `T` commutes with everything.
Since we are going to convert back and forth between polynomials and Laurent polynomials, we
decided to maintain some distinction by using the symbol `T`, rather than `X`, as the variable for
Laurent polynomials
## Notation
The symbol `R[T;T⁻¹]` stands for `laurent_polynomial R`. We also define
* `C : R →+* R[T;T⁻¹]` the inclusion of constant polynomials, analogous to the one for `R[X]`;
* `T : ℤ → R[T;T⁻¹]` the sequence of powers of the variable `T`.
## Implementation notes
We define Laurent polynomials as `add_monoid_algebra R ℤ`.
Thus, they are essentially `finsupp`s `ℤ →₀ R`.
This choice differs from the current irreducible design of `polynomial`, that instead shields away
the implementation via `finsupp`s. It is closer to the original definition of polynomials.
As a consequence, `laurent_polynomial` plays well with polynomials, but there is a little roughness
in establishing the API, since the `finsupp` implementation of `R[X]` is well-shielded.
Unlike the case of polynomials, I felt that the exponent notation was not too easy to use, as only
natural exponents would be allowed. Moreover, in the end, it seems likely that we should aim to
perform computations on exponents in `ℤ` anyway and separating this via the symbol `T` seems
convenient.
I made a *heavy* use of `simp` lemmas, aiming to bring Laurent polynomials to the form `C a * T n`.
Any comments or suggestions for improvements is greatly appreciated!
## Future work
Lots is missing!
-- (Riccardo) add inclusion into Laurent series.
-- (Riccardo) giving a morphism (as `R`-alg, so in the commutative case)
from `R[T,T⁻¹]` to `S` is the same as choosing a unit of `S`.
-- A "better" definition of `trunc` would be as an `R`-linear map. This works:
-- ```
-- def trunc : R[T;T⁻¹] →[R] R[X] :=
-- begin
-- refine (_ : add_monoid_algebra R ℕ →[R] R[X]).comp _,
-- { exact ⟨(to_finsupp_iso R).symm, by simp⟩ },
-- { refine ⟨λ r, comap_domain _ r (set.inj_on_of_injective (λ a b ab, int.of_nat.inj ab) _), _⟩,
-- exact λ r f, comap_domain_smul _ _ _ }
-- end
-- ```
-- but it would make sense to bundle the maps better, for a smoother user experience.
-- I (DT) did not have the strength to embark on this (possibly short!) journey, after getting to
-- this stage of the Laurent process!
-- This would likely involve adding a `comap_domain` analogue of
-- `add_monoid_algebra.map_domain_alg_hom` and an `R`-linear version of
-- `polynomial.to_finsupp_iso`.
-- Add `degree, int_degree, int_trailing_degree, leading_coeff, trailing_coeff,...`.
-/
open_locale polynomial big_operators
open polynomial add_monoid_algebra finsupp
noncomputable theory
variables {R : Type*}
/-- The semiring of Laurent polynomials with coefficients in the semiring `R`.
We denote it by `R[T;T⁻¹]`.
The ring homomorphism `C : R →+* R[T;T⁻¹]` includes `R` as the constant polynomials. -/
abbreviation laurent_polynomial (R : Type*) [semiring R] := add_monoid_algebra R ℤ
local notation R`[T;T⁻¹]`:9000 := laurent_polynomial R
/-- The ring homomorphism, taking a polynomial with coefficients in `R` to a Laurent polynomial
with coefficients in `R`. -/
def polynomial.to_laurent [semiring R] : R[X] →+* R[T;T⁻¹] :=
(map_domain_ring_hom R int.of_nat_hom).comp (to_finsupp_iso R)
/-- This is not a simp lemma, as it is usually preferable to use the lemmas about `C` and `X`
instead. -/
lemma polynomial.to_laurent_apply [semiring R] (p : R[X]) :
p.to_laurent = p.to_finsupp.map_domain coe := rfl
/-- The `R`-algebra map, taking a polynomial with coefficients in `R` to a Laurent polynomial
with coefficients in `R`. -/
def polynomial.to_laurent_alg [comm_semiring R] :
R[X] →ₐ[R] R[T;T⁻¹] :=
begin
refine alg_hom.comp _ (to_finsupp_iso_alg R).to_alg_hom,
exact (map_domain_alg_hom R R int.of_nat_hom),
end
@[simp]
lemma polynomial.to_laurent_alg_apply [comm_semiring R] (f : R[X]) :
f.to_laurent_alg = f.to_laurent := rfl
namespace laurent_polynomial
section semiring
variables [semiring R]
lemma single_zero_one_eq_one : (single 0 1 : R[T;T⁻¹]) = (1 : R[T;T⁻¹]) := rfl
/-! ### The functions `C` and `T`. -/
/-- The ring homomorphism `C`, including `R` into the ring of Laurent polynomials over `R` as
the constant Laurent polynomials. -/
def C : R →+* R[T;T⁻¹] :=
single_zero_ring_hom
lemma algebra_map_apply {R A : Type*} [comm_semiring R] [semiring A] [algebra R A] (r : R) :
algebra_map R (laurent_polynomial A) r = C (algebra_map R A r) :=
rfl
/--
When we have `[comm_semiring R]`, the function `C` is the same as `algebra_map R R[T;T⁻¹]`.
(But note that `C` is defined when `R` is not necessarily commutative, in which case
`algebra_map` is not available.)
-/
lemma C_eq_algebra_map {R : Type*} [comm_semiring R] (r : R) :
C r = algebra_map R R[T;T⁻¹] r :=
rfl
lemma single_eq_C (r : R) : single 0 r = C r := rfl
/-- The function `n ↦ T ^ n`, implemented as a sequence `ℤ → R[T;T⁻¹]`.
Using directly `T ^ n` does not work, since we want the exponents to be of Type `ℤ` and there
is no `ℤ`-power defined on `R[T;T⁻¹]`. Using that `T` is a unit introduces extra coercions.
For these reasons, the definition of `T` is as a sequence. -/
def T (n : ℤ) : R[T;T⁻¹] := single n 1
@[simp]
lemma T_zero : (T 0 : R[T;T⁻¹]) = 1 := rfl
lemma T_add (m n : ℤ) : (T (m + n) : R[T;T⁻¹]) = T m * T n :=
by { convert single_mul_single.symm, simp [T] }
lemma T_sub (m n : ℤ) : (T (m - n) : R[T;T⁻¹]) = T m * T (-n) :=
by rw [← T_add, sub_eq_add_neg]
@[simp]
lemma T_pow (m : ℤ) (n : ℕ) : (T m ^ n : R[T;T⁻¹]) = T (n * m) :=
by rw [T, T, single_pow n, one_pow, nsmul_eq_mul]
/-- The `simp` version of `mul_assoc`, in the presence of `T`'s. -/
@[simp]
lemma mul_T_assoc (f : R[T;T⁻¹]) (m n : ℤ) : f * T m * T n = f * T (m + n) :=
by simp [← T_add, mul_assoc]
@[simp]
lemma single_eq_C_mul_T (r : R) (n : ℤ) :
(single n r : R[T;T⁻¹]) = (C r * T n : R[T;T⁻¹]) :=
by convert single_mul_single.symm; simp
-- This lemma locks in the right changes and is what Lean proved directly.
-- The actual `simp`-normal form of a Laurent monomial is `C a * T n`, whenever it can be reached.
@[simp]
lemma _root_.polynomial.to_laurent_C_mul_T (n : ℕ) (r : R) :
((polynomial.monomial n r).to_laurent : R[T;T⁻¹]) = C r * T n :=
show map_domain coe (monomial n r).to_finsupp = (C r * T n : R[T;T⁻¹]),
by rw [to_finsupp_monomial, map_domain_single, single_eq_C_mul_T]
@[simp]
lemma _root_.polynomial.to_laurent_C (r : R) : (polynomial.C r).to_laurent = C r :=
begin
convert polynomial.to_laurent_C_mul_T 0 r,
simp only [int.coe_nat_zero, T_zero, mul_one],
end
@[simp]
lemma _root_.polynomial.to_laurent_X : (polynomial.X.to_laurent : R[T;T⁻¹]) = T 1 :=
begin
have : (polynomial.X : R[X]) = monomial 1 1,
{ simp [← C_mul_X_pow_eq_monomial] },
simp [this, polynomial.to_laurent_C_mul_T],
end
@[simp] lemma _root_.polynomial.to_laurent_one : (polynomial.to_laurent : R[X] → R[T;T⁻¹]) 1 = 1 :=
map_one polynomial.to_laurent
@[simp]
lemma _root_.polynomial.to_laurent_C_mul_eq (r : R) (f : R[X]) :
(polynomial.C r * f).to_laurent = C r * f.to_laurent :=
by simp only [_root_.map_mul, polynomial.to_laurent_C]
@[simp]
lemma _root_.polynomial.to_laurent_X_pow (n : ℕ) : (X ^ n : R[X]).to_laurent = T n :=
by simp only [map_pow, polynomial.to_laurent_X, T_pow, mul_one]
@[simp]
lemma _root_.polynomial.to_laurent_C_mul_X_pow (n : ℕ) (r : R) :
(polynomial.C r * X ^ n).to_laurent = C r * T n :=
by simp only [_root_.map_mul, polynomial.to_laurent_C, polynomial.to_laurent_X_pow]
instance invertible_T (n : ℤ) : invertible (T n : R[T;T⁻¹]) :=
{ inv_of := T (- n),
inv_of_mul_self := by rw [← T_add, add_left_neg, T_zero],
mul_inv_of_self := by rw [← T_add, add_right_neg, T_zero] }
@[simp]
lemma inv_of_T (n : ℤ) : ⅟ (T n : R[T;T⁻¹]) = T (- n) := rfl
lemma is_unit_T (n : ℤ) : is_unit (T n : R[T;T⁻¹]) :=
is_unit_of_invertible _
@[elab_as_eliminator] protected lemma induction_on {M : R[T;T⁻¹] → Prop} (p : R[T;T⁻¹])
(h_C : ∀ a, M (C a))
(h_add : ∀ {p q}, M p → M q → M (p + q))
(h_C_mul_T : ∀ (n : ℕ) (a : R), M (C a * T n) → M (C a * T (n + 1)))
(h_C_mul_T_Z : ∀ (n : ℕ) (a : R), M (C a * T (- n)) → M (C a * T (- n - 1))) :
M p :=
begin
have A : ∀ {n : ℤ} {a : R}, M (C a * T n),
{ assume n a,
apply n.induction_on,
{ simpa only [T_zero, mul_one] using h_C a },
{ exact λ m, h_C_mul_T m a },
{ exact λ m, h_C_mul_T_Z m a } },
have B : ∀ (s : finset ℤ), M (s.sum (λ (n : ℤ), C (p.to_fun n) * T n)),
{ apply finset.induction,
{ convert h_C 0, simp only [finset.sum_empty, _root_.map_zero] },
{ assume n s ns ih, rw finset.sum_insert ns, exact h_add A ih } },
convert B p.support,
ext a,
simp_rw [← single_eq_C_mul_T, finset.sum_apply', single_apply, finset.sum_ite_eq'],
split_ifs with h h,
{ refl },
{ exact finsupp.not_mem_support_iff.mp h }
end
/-- To prove something about Laurent polynomials, it suffices to show that
* the condition is closed under taking sums, and
* it holds for monomials.
-/
@[elab_as_eliminator] protected lemma induction_on' {M : R[T;T⁻¹] → Prop} (p : R[T;T⁻¹])
(h_add : ∀p q, M p → M q → M (p + q))
(h_C_mul_T : ∀(n : ℤ) (a : R), M (C a * T n)) :
M p :=
begin
refine p.induction_on (λ a, _) h_add _ _;
try { exact λ n f _, h_C_mul_T _ f },
convert h_C_mul_T 0 a,
exact (mul_one _).symm,
end
lemma commute_T (n : ℤ) (f : R[T;T⁻¹]) : commute (T n) f :=
f.induction_on' (λ p q Tp Tq, commute.add_right Tp Tq) $ λ m a,
show T n * _ = _, by
{ rw [T, T, ← single_eq_C, single_mul_single, single_mul_single, single_mul_single],
simp [add_comm] }
@[simp]
lemma T_mul (n : ℤ) (f : R[T;T⁻¹]) : T n * f = f * T n :=
(commute_T n f).eq
/-- `trunc : R[T;T⁻¹] →+ R[X]` maps a Laurent polynomial `f` to the polynomial whose terms of
nonnegative degree coincide with the ones of `f`. The terms of negative degree of `f` "vanish".
`trunc` is a left-inverse to `polynomial.to_laurent`. -/
def trunc : R[T;T⁻¹] →+ R[X] :=
((to_finsupp_iso R).symm.to_add_monoid_hom).comp $
comap_domain.add_monoid_hom $ λ a b, int.of_nat.inj
@[simp]
lemma trunc_C_mul_T (n : ℤ) (r : R) : trunc (C r * T n) = ite (0 ≤ n) (monomial n.to_nat r) 0 :=
begin
apply (to_finsupp_iso R).injective,
rw [← single_eq_C_mul_T, trunc, add_monoid_hom.coe_comp, function.comp_app,
comap_domain.add_monoid_hom_apply, to_finsupp_iso_apply],
by_cases n0 : 0 ≤ n,
{ lift n to ℕ using n0,
erw [comap_domain_single, to_finsupp_iso_symm_apply],
simp only [int.coe_nat_nonneg, int.to_nat_coe_nat, if_true, to_finsupp_iso_apply,
to_finsupp_monomial] },
{ lift (- n) to ℕ using (neg_pos.mpr (not_le.mp n0)).le with m,
rw [to_finsupp_iso_apply, to_finsupp_inj, if_neg n0],
erw to_finsupp_iso_symm_apply,
ext a,
have := ((not_le.mp n0).trans_le (int.coe_zero_le a)).ne',
simp only [coeff, comap_domain_apply, int.of_nat_eq_coe, coeff_zero, single_apply_eq_zero, this,
is_empty.forall_iff] }
end
@[simp] lemma left_inverse_trunc_to_laurent :
function.left_inverse (trunc : R[T;T⁻¹] → R[X]) polynomial.to_laurent :=
begin
refine λ f, f.induction_on' _ _,
{ exact λ f g hf hg, by simp only [hf, hg, _root_.map_add] },
{ exact λ n r, by simp only [polynomial.to_laurent_C_mul_T, trunc_C_mul_T, int.coe_nat_nonneg,
int.to_nat_coe_nat, if_true] }
end
@[simp] lemma _root_.polynomial.trunc_to_laurent (f : R[X]) : trunc f.to_laurent = f :=
left_inverse_trunc_to_laurent _
lemma _root_.polynomial.to_laurent_injective :
function.injective (polynomial.to_laurent : R[X] → R[T;T⁻¹]) :=
left_inverse_trunc_to_laurent.injective
@[simp] lemma _root_.polynomial.to_laurent_inj (f g : R[X]) :
f.to_laurent = g.to_laurent ↔ f = g :=
⟨λ h, polynomial.to_laurent_injective h, congr_arg _⟩
lemma _root_.polynomial.to_laurent_ne_zero {f : R[X]} :
f ≠ 0 ↔ f.to_laurent ≠ 0 :=
(map_ne_zero_iff _ (by exact polynomial.to_laurent_injective)).symm
lemma exists_T_pow (f : R[T;T⁻¹]) :
∃ (n : ℕ) (f' : R[X]), f'.to_laurent = f * T n :=
begin
apply f.induction_on' _ (λ n a, _); clear f,
{ rintros f g ⟨m, fn, hf⟩ ⟨n, gn, hg⟩,
refine ⟨m + n, fn * X ^ n + gn * X ^ m, _⟩,
simp only [hf, hg, add_mul, add_comm (n : ℤ), map_add, map_mul, polynomial.to_laurent_X_pow,
mul_T_assoc, int.coe_nat_add] },
{ cases n with n n,
{ exact ⟨0, polynomial.C a * X ^ n, by simp⟩ },
{ refine ⟨n + 1, polynomial.C a, _⟩,
simp only [int.neg_succ_of_nat_eq, polynomial.to_laurent_C, int.coe_nat_succ, mul_T_assoc,
add_left_neg, T_zero, mul_one] } }
end
/-- This is a version of `exists_T_pow` stated as an induction principle. -/
@[elab_as_eliminator] lemma induction_on_mul_T {Q : R[T;T⁻¹] → Prop} (f : R[T;T⁻¹])
(Qf : ∀ {f : R[X]} {n : ℕ}, Q (f.to_laurent * T (- n))) :
Q f :=
begin
rcases f.exists_T_pow with ⟨n, f', hf⟩,
rw [← mul_one f, ← T_zero, ← nat.cast_zero, ← nat.sub_self n, nat.cast_sub rfl.le, T_sub,
← mul_assoc, ← hf],
exact Qf,
end
/-- Suppose that `Q` is a statement about Laurent polynomials such that
* `Q` is true on *ordinary* polynomials;
* `Q (f * T)` implies `Q f`;
it follow that `Q` is true on all Laurent polynomials. -/
lemma reduce_to_polynomial_of_mul_T (f : R[T;T⁻¹]) {Q : R[T;T⁻¹] → Prop}
(Qf : ∀ (f : R[X]), Q f.to_laurent)
(QT : ∀ f, Q (f * T 1) → Q f) :
Q f :=
begin
induction f using laurent_polynomial.induction_on_mul_T with f n,
induction n with n hn,
{ simpa only [int.coe_nat_zero, neg_zero, T_zero, mul_one] using Qf _ },
{ convert QT _ _,
simpa using hn }
end
section support
lemma support_C_mul_T (a : R) (n : ℤ) : (C a * T n).support ⊆ {n} :=
by simpa only [← single_eq_C_mul_T] using support_single_subset
lemma support_C_mul_T_of_ne_zero {a : R} (a0 : a ≠ 0) (n : ℤ) : (C a * T n).support = {n} :=
begin
rw ← single_eq_C_mul_T,
exact support_single_ne_zero _ a0,
end
/-- The support of a polynomial `f` is a finset in `ℕ`. The lemma `to_laurent_support f`
shows that the support of `f.to_laurent` is the same finset, but viewed in `ℤ` under the natural
inclusion `ℕ ↪ ℤ`. -/
lemma to_laurent_support (f : R[X]) :
f.to_laurent.support = f.support.map nat.cast_embedding :=
begin
generalize' hd : f.support = s,
revert f,
refine finset.induction_on s _ _; clear s,
{ simp only [polynomial.support_eq_empty, map_zero, finsupp.support_zero, eq_self_iff_true,
implies_true_iff, finset.map_empty] {contextual := tt} },
{ intros a s as hf f fs,
have : (erase a f).to_laurent.support = s.map nat.cast_embedding := hf (f.erase a) (by simp only
[fs, finset.erase_eq_of_not_mem as, polynomial.support_erase, finset.erase_insert_eq_erase]),
rw [← monomial_add_erase f a, finset.map_insert, ← this, map_add,
polynomial.to_laurent_C_mul_T, support_add_eq, finset.insert_eq],
{ congr,
exact support_C_mul_T_of_ne_zero (polynomial.mem_support_iff.mp (by simp [fs])) _ },
{ rw this,
exact disjoint.mono_left (support_C_mul_T _ _) (by simpa) } }
end
end support
section degrees
/-- The degree of a Laurent polynomial takes values in `with_bot ℤ`.
If `f : R[T;T⁻¹]` is a Laurent polynomial, then `f.degree` is the maximum of its support of `f`,
or `⊥`, if `f = 0`. -/
def degree (f : R[T;T⁻¹]) : with_bot ℤ := f.support.max
@[simp] lemma degree_zero : degree (0 : R[T;T⁻¹]) = ⊥ := rfl
@[simp] lemma degree_eq_bot_iff {f : R[T;T⁻¹]} : f.degree = ⊥ ↔ f = 0 :=
begin
refine ⟨λ h, _, λ h, by rw [h, degree_zero]⟩,
rw [degree, finset.max_eq_sup_with_bot] at h,
ext n,
refine not_not.mp (λ f0, _),
simp_rw [finset.sup_eq_bot_iff, finsupp.mem_support_iff, ne.def, with_bot.coe_ne_bot] at h,
exact h n f0,
end
section exact_degrees
open_locale classical
@[simp] lemma degree_C_mul_T (n : ℤ) (a : R) (a0 : a ≠ 0) : (C a * T n).degree = n :=
begin
rw degree,
convert finset.max_singleton,
refine support_eq_singleton.mpr _,
simp only [← single_eq_C_mul_T, single_eq_same, a0, ne.def, not_false_iff, eq_self_iff_true,
and_self],
end
lemma degree_C_mul_T_ite (n : ℤ) (a : R) : (C a * T n).degree = ite (a = 0) ⊥ n :=
by split_ifs with h h;
simp only [h, map_zero, zero_mul, degree_zero, degree_C_mul_T, ne.def, not_false_iff]
@[simp] lemma degree_T [nontrivial R] (n : ℤ) : (T n : R[T;T⁻¹]).degree = n :=
begin
rw [← one_mul (T n), ← map_one C],
exact degree_C_mul_T n 1 (one_ne_zero : (1 : R) ≠ 0),
end
lemma degree_C {a : R} (a0 : a ≠ 0) : (C a).degree = 0 :=
begin
rw [← mul_one (C a), ← T_zero],
exact degree_C_mul_T 0 a a0
end
lemma degree_C_ite (a : R) : (C a).degree = ite (a = 0) ⊥ 0 :=
by split_ifs with h h;
simp only [h, map_zero, degree_zero, degree_C, ne.def, not_false_iff]
end exact_degrees
section degree_bounds
lemma degree_C_mul_T_le (n : ℤ) (a : R) : (C a * T n).degree ≤ n :=
begin
by_cases a0 : a = 0,
{ simp only [a0, map_zero, zero_mul, degree_zero, bot_le] },
{ exact (degree_C_mul_T n a a0).le }
end
lemma degree_T_le (n : ℤ) : (T n : R[T;T⁻¹]).degree ≤ n :=
(le_of_eq (by rw [map_one, one_mul])).trans (degree_C_mul_T_le n (1 : R))
lemma degree_C_le (a : R) : (C a).degree ≤ 0 :=
(le_of_eq (by rw [T_zero, mul_one])).trans (degree_C_mul_T_le 0 a)
end degree_bounds
end degrees
instance : module R[X] R[T;T⁻¹] :=
module.comp_hom _ polynomial.to_laurent
instance (R : Type*) [semiring R] : is_scalar_tower R[X] R[X] R[T;T⁻¹] :=
{ smul_assoc := λ x y z, by simp only [has_smul.smul, has_smul.comp.smul, map_mul, mul_assoc] }
end semiring
section comm_semiring
variable [comm_semiring R]
instance algebra_polynomial (R : Type*) [comm_semiring R] : algebra R[X] R[T;T⁻¹] :=
{ commutes' := λ f l, by simp [mul_comm],
smul_def' := λ f l, rfl,
.. polynomial.to_laurent }
lemma algebra_map_X_pow (n : ℕ) : algebra_map R[X] R[T;T⁻¹] (X ^ n) = T n :=
polynomial.to_laurent_X_pow n
@[simp]
lemma algebra_map_eq_to_laurent (f : R[X]) : algebra_map R[X] R[T;T⁻¹] f = f.to_laurent :=
rfl
lemma is_localization : is_localization (submonoid.closure ({X} : set R[X])) R[T;T⁻¹] :=
{ map_units := λ t, begin
cases t with t ht,
rcases submonoid.mem_closure_singleton.mp ht with ⟨n, rfl⟩,
simp only [is_unit_T n, set_like.coe_mk, algebra_map_eq_to_laurent, polynomial.to_laurent_X_pow]
end,
surj := λ f, begin
induction f using laurent_polynomial.induction_on_mul_T with f n,
have := (submonoid.closure ({X} : set R[X])).pow_mem submonoid.mem_closure_singleton_self n,
refine ⟨(f, ⟨_, this⟩), _⟩,
simp only [set_like.coe_mk, algebra_map_eq_to_laurent, polynomial.to_laurent_X_pow, mul_T_assoc,
add_left_neg, T_zero, mul_one],
end,
eq_iff_exists := λ f g, begin
rw [algebra_map_eq_to_laurent, algebra_map_eq_to_laurent, polynomial.to_laurent_inj],
refine ⟨_, _⟩,
{ rintro rfl,
exact ⟨1, rfl⟩ },
{ rintro ⟨⟨h, hX⟩, h⟩,
rcases submonoid.mem_closure_singleton.mp hX with ⟨n, rfl⟩,
exact mul_X_pow_injective n h }
end }
end comm_semiring
end laurent_polynomial
|
d5544724e00354465b83f381ca6e5e3303140776 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/category_theory/preadditive/eilenberg_moore.lean | 6f7c657336dc473a99b2b58ac1a472ef59255075 | [
"Apache-2.0"
] | permissive | urkud/mathlib | eab80095e1b9f1513bfb7f25b4fa82fa4fd02989 | 6379d39e6b5b279df9715f8011369a301b634e41 | refs/heads/master | 1,658,425,342,662 | 1,658,078,703,000 | 1,658,078,703,000 | 186,910,338 | 0 | 0 | Apache-2.0 | 1,568,512,083,000 | 1,557,958,709,000 | Lean | UTF-8 | Lean | false | false | 3,177 | lean | /-
Copyright (c) 2022 Julian Kuelshammer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Julian Kuelshammer
-/
import category_theory.preadditive.default
import category_theory.monad.algebra
import category_theory.preadditive.additive_functor
/-!
# Preadditive structure on algebras over a monad
If `C` is a preadditive categories and `T` is an additive monad on `C` then `algebra T` is also
preadditive. Dually, if `U` is an additive comonad on `C` then `coalgebra U` is preadditive as well.
-/
universes v₁ u₁ -- morphism levels before object levels. See note [category_theory universes].
namespace category_theory
variables (C : Type u₁) [category.{v₁} C] [preadditive C] (T : monad C)
[functor.additive (T : C ⥤ C)]
open category_theory.limits preadditive
/-- The category of algebras over an additive monad on a preadditive category is preadditive. -/
@[simps]
instance monad.algebra_preadditive : preadditive (monad.algebra T) :=
{ hom_group := λ F G,
{ add := λ α β,
{ f := α.f + β.f,
h' := by simp only [functor.map_add, add_comp, monad.algebra.hom.h, comp_add] },
zero :=
{ f := 0,
h' := by simp only [functor.map_zero, zero_comp, comp_zero] },
neg := λ α,
{ f := -α.f,
h' := by simp only [functor.map_neg, neg_comp, monad.algebra.hom.h, comp_neg] },
sub := λ α β,
{ f := α.f - β.f,
h' := by simp only [functor.map_sub, sub_comp, monad.algebra.hom.h, comp_sub] },
add_assoc := by { intros, ext, apply add_assoc },
zero_add := by { intros, ext, apply zero_add },
add_zero := by { intros, ext, apply add_zero },
sub_eq_add_neg := by { intros, ext, apply sub_eq_add_neg },
add_left_neg := by { intros, ext, apply add_left_neg },
add_comm := by { intros, ext, apply add_comm } },
add_comp' := by { intros, ext, apply add_comp },
comp_add' := by { intros, ext, apply comp_add } }
variables (U : comonad C) [functor.additive (U : C ⥤ C)]
/-- The category of coalgebras over an additive comonad on a preadditive category is preadditive. -/
@[simps]
instance comonad.coalgebra_preadditive : preadditive (comonad.coalgebra U) :=
{ hom_group := λ F G,
{ add := λ α β,
{ f := α.f + β.f,
h' := by simp only [functor.map_add, comp_add, comonad.coalgebra.hom.h, add_comp] },
zero :=
{ f := 0,
h' := by simp only [functor.map_zero, comp_zero, zero_comp] },
neg := λ α,
{ f := -α.f,
h' := by simp only [functor.map_neg, comp_neg, comonad.coalgebra.hom.h, neg_comp] },
sub := λ α β,
{ f := α.f - β.f,
h' := by simp only [functor.map_sub, comp_sub, comonad.coalgebra.hom.h, sub_comp] },
add_assoc := by { intros, ext, apply add_assoc },
zero_add := by { intros, ext, apply zero_add },
add_zero := by { intros, ext, apply add_zero },
sub_eq_add_neg := by { intros, ext, apply sub_eq_add_neg },
add_left_neg := by { intros, ext, apply add_left_neg },
add_comm := by { intros, ext, apply add_comm } },
add_comp' := by { intros, ext, apply add_comp },
comp_add' := by { intros, ext, apply comp_add } }
end category_theory
|
0740bb019fbd057c46815d95a0fd4ea4377320df | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/ring_theory/roots_of_unity/basic.lean | 1af2919d9c7438e9be87b658d6b223e42a4fa6cb | [
"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 | 38,044 | lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import algebra.char_p.two
import algebra.ne_zero
import algebra.gcd_monoid.integrally_closed
import data.polynomial.ring_division
import field_theory.finite.basic
import field_theory.separable
import group_theory.specific_groups.cyclic
import number_theory.divisors
import ring_theory.integral_domain
import tactic.zify
/-!
# Roots of unity and primitive roots of unity
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We define roots of unity in the context of an arbitrary commutative monoid,
as a subgroup of the group of units. We also define a predicate `is_primitive_root` on commutative
monoids, expressing that an element is a primitive root of unity.
## Main definitions
* `roots_of_unity n M`, for `n : ℕ+` is the subgroup of the units of a commutative monoid `M`
consisting of elements `x` that satisfy `x ^ n = 1`.
* `is_primitive_root ζ k`: an element `ζ` is a primitive `k`-th root of unity if `ζ ^ k = 1`,
and if `l` satisfies `ζ ^ l = 1` then `k ∣ l`.
* `primitive_roots k R`: the finset of primitive `k`-th roots of unity in an integral domain `R`.
* `is_primitive_root.aut_to_pow`: the monoid hom that takes an automorphism of a ring to the power
it sends that specific primitive root, as a member of `(zmod n)ˣ`.
## Main results
* `roots_of_unity.is_cyclic`: the roots of unity in an integral domain form a cyclic group.
* `is_primitive_root.zmod_equiv_zpowers`: `zmod k` is equivalent to
the subgroup generated by a primitive `k`-th root of unity.
* `is_primitive_root.zpowers_eq`: in an integral domain, the subgroup generated by
a primitive `k`-th root of unity is equal to the `k`-th roots of unity.
* `is_primitive_root.card_primitive_roots`: if an integral domain
has a primitive `k`-th root of unity, then it has `φ k` of them.
## Implementation details
It is desirable that `roots_of_unity` is a subgroup,
and it will mainly be applied to rings (e.g. the ring of integers in a number field) and fields.
We therefore implement it as a subgroup of the units of a commutative monoid.
We have chosen to define `roots_of_unity n` for `n : ℕ+`, instead of `n : ℕ`,
because almost all lemmas need the positivity assumption,
and in particular the type class instances for `fintype` and `is_cyclic`.
On the other hand, for primitive roots of unity, it is desirable to have a predicate
not just on units, but directly on elements of the ring/field.
For example, we want to say that `exp (2 * pi * I / n)` is a primitive `n`-th root of unity
in the complex numbers, without having to turn that number into a unit first.
This creates a little bit of friction, but lemmas like `is_primitive_root.is_unit` and
`is_primitive_root.coe_units_iff` should provide the necessary glue.
-/
open_locale classical big_operators polynomial
noncomputable theory
open polynomial
open finset
variables {M N G R S F : Type*}
variables [comm_monoid M] [comm_monoid N] [division_comm_monoid G]
section roots_of_unity
variables {k l : ℕ+}
/-- `roots_of_unity k M` is the subgroup of elements `m : Mˣ` that satisfy `m ^ k = 1` -/
def roots_of_unity (k : ℕ+) (M : Type*) [comm_monoid M] : subgroup Mˣ :=
{ carrier := { ζ | ζ ^ (k : ℕ) = 1 },
one_mem' := one_pow _,
mul_mem' := λ ζ ξ hζ hξ, by simp only [*, set.mem_set_of_eq, mul_pow, one_mul] at *,
inv_mem' := λ ζ hζ, by simp only [*, set.mem_set_of_eq, inv_pow, inv_one] at * }
@[simp] lemma mem_roots_of_unity (k : ℕ+) (ζ : Mˣ) :
ζ ∈ roots_of_unity k M ↔ ζ ^ (k : ℕ) = 1 := iff.rfl
lemma mem_roots_of_unity' (k : ℕ+) (ζ : Mˣ) :
ζ ∈ roots_of_unity k M ↔ (ζ : M) ^ (k : ℕ) = 1 :=
by { rw [mem_roots_of_unity], norm_cast }
lemma roots_of_unity.coe_injective {n : ℕ+} : function.injective (coe : (roots_of_unity n M) → M) :=
units.ext.comp (λ x y, subtype.ext)
/-- Make an element of `roots_of_unity` from a member of the base ring, and a proof that it has
a positive power equal to one. -/
@[simps coe_coe] def roots_of_unity.mk_of_pow_eq (ζ : M) {n : ℕ+} (h : ζ ^ (n : ℕ) = 1) :
roots_of_unity n M :=
⟨units.of_pow_eq_one ζ n h n.ne_zero, units.pow_of_pow_eq_one _ _⟩
@[simp] lemma roots_of_unity.coe_mk_of_pow_eq {ζ : M} {n : ℕ+}
(h : ζ ^ (n : ℕ) = 1) : (roots_of_unity.mk_of_pow_eq _ h : M) = ζ := rfl
lemma roots_of_unity_le_of_dvd (h : k ∣ l) : roots_of_unity k M ≤ roots_of_unity l M :=
begin
obtain ⟨d, rfl⟩ := h,
intros ζ h,
simp only [mem_roots_of_unity, pnat.mul_coe, pow_mul, one_pow, *] at *,
end
lemma map_roots_of_unity (f : Mˣ →* Nˣ) (k : ℕ+) :
(roots_of_unity k M).map f ≤ roots_of_unity k N :=
begin
rintros _ ⟨ζ, h, rfl⟩,
simp only [←map_pow, *, mem_roots_of_unity, set_like.mem_coe, monoid_hom.map_one] at *
end
@[norm_cast] lemma roots_of_unity.coe_pow [comm_monoid R] (ζ : roots_of_unity k R) (m : ℕ) :
↑(ζ ^ m) = (ζ ^ m : R) :=
begin
change ↑(↑(ζ ^ m) : Rˣ) = ↑(ζ : Rˣ) ^ m,
rw [subgroup.coe_pow, units.coe_pow],
end
section comm_semiring
variables [comm_semiring R] [comm_semiring S]
/-- Restrict a ring homomorphism to the nth roots of unity -/
def restrict_roots_of_unity [ring_hom_class F R S] (σ : F) (n : ℕ+) :
roots_of_unity n R →* roots_of_unity n S :=
let h : ∀ ξ : roots_of_unity n R, (σ ξ) ^ (n : ℕ) = 1 := λ ξ, by
{ change (σ (ξ : Rˣ)) ^ (n : ℕ) = 1,
rw [←map_pow, ←units.coe_pow, show ((ξ : Rˣ) ^ (n : ℕ) = 1), from ξ.2,
units.coe_one, map_one σ] } in
{ to_fun := λ ξ, ⟨@unit_of_invertible _ _ _ (invertible_of_pow_eq_one _ _ (h ξ) n.ne_zero),
by { ext, rw units.coe_pow, exact h ξ }⟩,
map_one' := by { ext, exact map_one σ },
map_mul' := λ ξ₁ ξ₂, by { ext, rw [subgroup.coe_mul, units.coe_mul], exact map_mul σ _ _ } }
@[simp] lemma restrict_roots_of_unity_coe_apply [ring_hom_class F R S] (σ : F)
(ζ : roots_of_unity k R) : ↑(restrict_roots_of_unity σ k ζ) = σ ↑ζ :=
rfl
/-- Restrict a ring isomorphism to the nth roots of unity -/
def ring_equiv.restrict_roots_of_unity (σ : R ≃+* S) (n : ℕ+) :
roots_of_unity n R ≃* roots_of_unity n S :=
{ to_fun := restrict_roots_of_unity σ.to_ring_hom n,
inv_fun :=restrict_roots_of_unity σ.symm.to_ring_hom n,
left_inv := λ ξ, by { ext, exact σ.symm_apply_apply ξ },
right_inv := λ ξ, by { ext, exact σ.apply_symm_apply ξ },
map_mul' := (restrict_roots_of_unity _ n).map_mul }
@[simp] lemma ring_equiv.restrict_roots_of_unity_coe_apply (σ : R ≃+* S) (ζ : roots_of_unity k R) :
↑(σ.restrict_roots_of_unity k ζ) = σ ↑ζ :=
rfl
@[simp] lemma ring_equiv.restrict_roots_of_unity_symm (σ : R ≃+* S) :
(σ.restrict_roots_of_unity k).symm = σ.symm.restrict_roots_of_unity k :=
rfl
end comm_semiring
section is_domain
variables [comm_ring R] [is_domain R]
lemma mem_roots_of_unity_iff_mem_nth_roots {ζ : Rˣ} :
ζ ∈ roots_of_unity k R ↔ (ζ : R) ∈ nth_roots k (1 : R) :=
by simp only [mem_roots_of_unity, mem_nth_roots k.pos, units.ext_iff, units.coe_one, units.coe_pow]
variables (k R)
/-- Equivalence between the `k`-th roots of unity in `R` and the `k`-th roots of `1`.
This is implemented as equivalence of subtypes,
because `roots_of_unity` is a subgroup of the group of units,
whereas `nth_roots` is a multiset. -/
def roots_of_unity_equiv_nth_roots :
roots_of_unity k R ≃ {x // x ∈ nth_roots k (1 : R)} :=
begin
refine
{ to_fun := λ x, ⟨x, mem_roots_of_unity_iff_mem_nth_roots.mp x.2⟩,
inv_fun := λ x, ⟨⟨x, x ^ (k - 1 : ℕ), _, _⟩, _⟩,
left_inv := _,
right_inv := _ },
swap 4, { rintro ⟨x, hx⟩, ext, refl },
swap 4, { rintro ⟨x, hx⟩, ext, refl },
all_goals
{ rcases x with ⟨x, hx⟩, rw [mem_nth_roots k.pos] at hx,
simp only [subtype.coe_mk, ← pow_succ, ← pow_succ', hx,
tsub_add_cancel_of_le (show 1 ≤ (k : ℕ), from k.one_le)] },
{ show (_ : Rˣ) ^ (k : ℕ) = 1,
simp only [units.ext_iff, hx, units.coe_mk, units.coe_one, subtype.coe_mk, units.coe_pow] }
end
variables {k R}
@[simp] lemma roots_of_unity_equiv_nth_roots_apply (x : roots_of_unity k R) :
(roots_of_unity_equiv_nth_roots R k x : R) = x :=
rfl
@[simp] lemma roots_of_unity_equiv_nth_roots_symm_apply (x : {x // x ∈ nth_roots k (1 : R)}) :
((roots_of_unity_equiv_nth_roots R k).symm x : R) = x :=
rfl
variables (k R)
instance roots_of_unity.fintype : fintype (roots_of_unity k R) :=
fintype.of_equiv {x // x ∈ nth_roots k (1 : R)} $ (roots_of_unity_equiv_nth_roots R k).symm
instance roots_of_unity.is_cyclic : is_cyclic (roots_of_unity k R) :=
is_cyclic_of_subgroup_is_domain ((units.coe_hom R).comp (roots_of_unity k R).subtype)
(units.ext.comp subtype.val_injective)
lemma card_roots_of_unity : fintype.card (roots_of_unity k R) ≤ k :=
calc fintype.card (roots_of_unity k R)
= fintype.card {x // x ∈ nth_roots k (1 : R)} :
fintype.card_congr (roots_of_unity_equiv_nth_roots R k)
... ≤ (nth_roots k (1 : R)).attach.card : multiset.card_le_of_le (multiset.dedup_le _)
... = (nth_roots k (1 : R)).card : multiset.card_attach
... ≤ k : card_nth_roots k 1
variables {k R}
lemma map_root_of_unity_eq_pow_self [ring_hom_class F R R] (σ : F) (ζ : roots_of_unity k R) :
∃ m : ℕ, σ ζ = ζ ^ m :=
begin
obtain ⟨m, hm⟩ := monoid_hom.map_cyclic (restrict_roots_of_unity σ k),
rw [←restrict_roots_of_unity_coe_apply, hm, zpow_eq_mod_order_of, ←int.to_nat_of_nonneg
(m.mod_nonneg (int.coe_nat_ne_zero.mpr (pos_iff_ne_zero.mp (order_of_pos ζ)))),
zpow_coe_nat, roots_of_unity.coe_pow],
exact ⟨(m % (order_of ζ)).to_nat, rfl⟩,
end
end is_domain
section reduced
variables (R) [comm_ring R] [is_reduced R]
@[simp] lemma mem_roots_of_unity_prime_pow_mul_iff (p k : ℕ) (m : ℕ+) [hp : fact p.prime]
[char_p R p] {ζ : Rˣ} :
ζ ∈ roots_of_unity (⟨p, hp.1.pos⟩ ^ k * m) R ↔ ζ ∈ roots_of_unity m R :=
by simp [mem_roots_of_unity']
end reduced
end roots_of_unity
/-- An element `ζ` is a primitive `k`-th root of unity if `ζ ^ k = 1`,
and if `l` satisfies `ζ ^ l = 1` then `k ∣ l`. -/
structure is_primitive_root (ζ : M) (k : ℕ) : Prop :=
(pow_eq_one : ζ ^ (k : ℕ) = 1)
(dvd_of_pow_eq_one : ∀ l : ℕ, ζ ^ l = 1 → k ∣ l)
/-- Turn a primitive root μ into a member of the `roots_of_unity` subgroup. -/
@[simps] def is_primitive_root.to_roots_of_unity {μ : M} {n : ℕ+} (h : is_primitive_root μ n) :
roots_of_unity n M := roots_of_unity.mk_of_pow_eq μ h.pow_eq_one
section primitive_roots
variables {k : ℕ}
/-- `primitive_roots k R` is the finset of primitive `k`-th roots of unity
in the integral domain `R`. -/
def primitive_roots (k : ℕ) (R : Type*) [comm_ring R] [is_domain R] : finset R :=
(nth_roots k (1 : R)).to_finset.filter (λ ζ, is_primitive_root ζ k)
variables [comm_ring R] [is_domain R]
@[simp] lemma mem_primitive_roots {ζ : R} (h0 : 0 < k) :
ζ ∈ primitive_roots k R ↔ is_primitive_root ζ k :=
begin
rw [primitive_roots, mem_filter, multiset.mem_to_finset, mem_nth_roots h0, and_iff_right_iff_imp],
exact is_primitive_root.pow_eq_one
end
@[simp] lemma primitive_roots_zero : primitive_roots 0 R = ∅ :=
by rw [primitive_roots, nth_roots_zero, multiset.to_finset_zero, finset.filter_empty]
lemma is_primitive_root_of_mem_primitive_roots {ζ : R} (h : ζ ∈ primitive_roots k R) :
is_primitive_root ζ k :=
k.eq_zero_or_pos.elim (λ hk, false.elim $ by simpa [hk] using h)
(λ hk, (mem_primitive_roots hk).1 h)
end primitive_roots
namespace is_primitive_root
variables {k l : ℕ}
lemma iff_def (ζ : M) (k : ℕ) :
is_primitive_root ζ k ↔ (ζ ^ k = 1) ∧ (∀ l : ℕ, ζ ^ l = 1 → k ∣ l) :=
⟨λ ⟨h1, h2⟩, ⟨h1, h2⟩, λ ⟨h1, h2⟩, ⟨h1, h2⟩⟩
lemma mk_of_lt (ζ : M) (hk : 0 < k) (h1 : ζ ^ k = 1) (h : ∀ l : ℕ, 0 < l → l < k → ζ ^ l ≠ 1) :
is_primitive_root ζ k :=
begin
refine ⟨h1, λ l hl, _⟩,
suffices : k.gcd l = k, { exact this ▸ k.gcd_dvd_right l },
rw eq_iff_le_not_lt,
refine ⟨nat.le_of_dvd hk (k.gcd_dvd_left l), _⟩,
intro h', apply h _ (nat.gcd_pos_of_pos_left _ hk) h',
exact pow_gcd_eq_one _ h1 hl
end
section comm_monoid
variables {ζ : M} {f : F} (h : is_primitive_root ζ k)
@[nontriviality] lemma of_subsingleton [subsingleton M] (x : M) : is_primitive_root x 1 :=
⟨subsingleton.elim _ _, λ _ _, one_dvd _⟩
lemma pow_eq_one_iff_dvd (l : ℕ) : ζ ^ l = 1 ↔ k ∣ l :=
⟨h.dvd_of_pow_eq_one l,
by { rintro ⟨i, rfl⟩, simp only [pow_mul, h.pow_eq_one, one_pow, pnat.mul_coe] }⟩
lemma is_unit (h : is_primitive_root ζ k) (h0 : 0 < k) : is_unit ζ :=
begin
apply is_unit_of_mul_eq_one ζ (ζ ^ (k - 1)),
rw [← pow_succ, tsub_add_cancel_of_le h0.nat_succ_le, h.pow_eq_one]
end
lemma pow_ne_one_of_pos_of_lt (h0 : 0 < l) (hl : l < k) : ζ ^ l ≠ 1 :=
mt (nat.le_of_dvd h0 ∘ h.dvd_of_pow_eq_one _) $ not_le_of_lt hl
lemma ne_one (hk : 1 < k) : ζ ≠ 1 :=
h.pow_ne_one_of_pos_of_lt zero_lt_one hk ∘ (pow_one ζ).trans
lemma pow_inj (h : is_primitive_root ζ k) ⦃i j : ℕ⦄ (hi : i < k) (hj : j < k) (H : ζ ^ i = ζ ^ j) :
i = j :=
begin
wlog hij : i ≤ j generalizing i j,
{ exact (this hj hi H.symm (le_of_not_le hij)).symm },
apply le_antisymm hij,
rw ← tsub_eq_zero_iff_le,
apply nat.eq_zero_of_dvd_of_lt _ (lt_of_le_of_lt tsub_le_self hj),
apply h.dvd_of_pow_eq_one,
rw [← ((h.is_unit (lt_of_le_of_lt (nat.zero_le _) hi)).pow i).mul_left_inj,
← pow_add, tsub_add_cancel_of_le hij, H, one_mul]
end
lemma one : is_primitive_root (1 : M) 1 :=
{ pow_eq_one := pow_one _,
dvd_of_pow_eq_one := λ l hl, one_dvd _ }
@[simp] lemma one_right_iff : is_primitive_root ζ 1 ↔ ζ = 1 :=
begin
split,
{ intro h, rw [← pow_one ζ, h.pow_eq_one] },
{ rintro rfl, exact one }
end
@[simp] lemma coe_submonoid_class_iff {M B : Type*} [comm_monoid M] [set_like B M]
[submonoid_class B M] {N : B} {ζ : N} : is_primitive_root (ζ : M) k ↔ is_primitive_root ζ k :=
by simp [iff_def, ← submonoid_class.coe_pow]
@[simp] lemma coe_units_iff {ζ : Mˣ} :
is_primitive_root (ζ : M) k ↔ is_primitive_root ζ k :=
by simp only [iff_def, units.ext_iff, units.coe_pow, units.coe_one]
lemma pow_of_coprime (h : is_primitive_root ζ k) (i : ℕ) (hi : i.coprime k) :
is_primitive_root (ζ ^ i) k :=
begin
by_cases h0 : k = 0,
{ subst k, simp only [*, pow_one, nat.coprime_zero_right] at * },
rcases h.is_unit (nat.pos_of_ne_zero h0) with ⟨ζ, rfl⟩,
rw [← units.coe_pow],
rw coe_units_iff at h ⊢,
refine
{ pow_eq_one := by rw [← pow_mul', pow_mul, h.pow_eq_one, one_pow],
dvd_of_pow_eq_one := _ },
intros l hl,
apply h.dvd_of_pow_eq_one,
rw [← pow_one ζ, ← zpow_coe_nat ζ, ← hi.gcd_eq_one, nat.gcd_eq_gcd_ab, zpow_add,
mul_pow, ← zpow_coe_nat, ← zpow_mul, mul_right_comm],
simp only [zpow_mul, hl, h.pow_eq_one, one_zpow, one_pow, one_mul, zpow_coe_nat]
end
lemma pow_of_prime (h : is_primitive_root ζ k) {p : ℕ} (hprime : nat.prime p) (hdiv : ¬ p ∣ k) :
is_primitive_root (ζ ^ p) k :=
h.pow_of_coprime p (hprime.coprime_iff_not_dvd.2 hdiv)
lemma pow_iff_coprime (h : is_primitive_root ζ k) (h0 : 0 < k) (i : ℕ) :
is_primitive_root (ζ ^ i) k ↔ i.coprime k :=
begin
refine ⟨_, h.pow_of_coprime i⟩,
intro hi,
obtain ⟨a, ha⟩ := i.gcd_dvd_left k,
obtain ⟨b, hb⟩ := i.gcd_dvd_right k,
suffices : b = k,
{ rwa [this, ← one_mul k, mul_left_inj' h0.ne', eq_comm] at hb { occs := occurrences.pos [1] } },
rw [ha] at hi,
rw [mul_comm] at hb,
apply nat.dvd_antisymm ⟨i.gcd k, hb⟩ (hi.dvd_of_pow_eq_one b _),
rw [← pow_mul', ← mul_assoc, ← hb, pow_mul, h.pow_eq_one, one_pow]
end
protected lemma order_of (ζ : M) : is_primitive_root ζ (order_of ζ) :=
⟨pow_order_of_eq_one ζ, λ l, order_of_dvd_of_pow_eq_one⟩
lemma unique {ζ : M} (hk : is_primitive_root ζ k) (hl : is_primitive_root ζ l) : k = l :=
nat.dvd_antisymm (hk.2 _ hl.1) (hl.2 _ hk.1)
lemma eq_order_of : k = order_of ζ := h.unique (is_primitive_root.order_of ζ)
protected lemma iff (hk : 0 < k) :
is_primitive_root ζ k ↔ ζ ^ k = 1 ∧ ∀ l : ℕ, 0 < l → l < k → ζ ^ l ≠ 1 :=
begin
refine ⟨λ h, ⟨h.pow_eq_one, λ l hl' hl, _⟩, λ ⟨hζ, hl⟩, is_primitive_root.mk_of_lt ζ hk hζ hl⟩,
rw h.eq_order_of at hl,
exact pow_ne_one_of_lt_order_of' hl'.ne' hl,
end
protected lemma not_iff : ¬ is_primitive_root ζ k ↔ order_of ζ ≠ k :=
⟨λ h hk, h $ hk ▸ is_primitive_root.order_of ζ,
λ h hk, h.symm $ hk.unique $ is_primitive_root.order_of ζ⟩
lemma pow_of_dvd (h : is_primitive_root ζ k) {p : ℕ} (hp : p ≠ 0) (hdiv : p ∣ k) :
is_primitive_root (ζ ^ p) (k / p) :=
begin
suffices : order_of (ζ ^ p) = k / p,
{ exact this ▸ is_primitive_root.order_of (ζ ^ p) },
rw [order_of_pow' _ hp, ← eq_order_of h, nat.gcd_eq_right hdiv]
end
protected
lemma mem_roots_of_unity {ζ : Mˣ} {n : ℕ+} (h : is_primitive_root ζ n) : ζ ∈ roots_of_unity n M :=
h.pow_eq_one
/-- If there is a `n`-th primitive root of unity in `R` and `b` divides `n`,
then there is a `b`-th primitive root of unity in `R`. -/
lemma pow {n : ℕ} {a b : ℕ} (hn : 0 < n) (h : is_primitive_root ζ n) (hprod : n = a * b) :
is_primitive_root (ζ ^ a) b :=
begin
subst n,
simp only [iff_def, ← pow_mul, h.pow_eq_one, eq_self_iff_true, true_and],
intros l hl,
have ha0 : a ≠ 0, { rintro rfl, simpa only [nat.not_lt_zero, zero_mul] using hn },
rwa ← mul_dvd_mul_iff_left ha0,
exact h.dvd_of_pow_eq_one _ hl
end
section maps
open function
lemma map_of_injective [monoid_hom_class F M N] (h : is_primitive_root ζ k) (hf : injective f) :
is_primitive_root (f ζ) k :=
{ pow_eq_one := by rw [←map_pow, h.pow_eq_one, _root_.map_one],
dvd_of_pow_eq_one := begin
rw h.eq_order_of,
intros l hl,
rw [←map_pow, ←map_one f] at hl,
exact order_of_dvd_of_pow_eq_one (hf hl)
end }
lemma of_map_of_injective [monoid_hom_class F M N] (h : is_primitive_root (f ζ) k)
(hf : injective f) : is_primitive_root ζ k :=
{ pow_eq_one := by { apply_fun f, rw [map_pow, _root_.map_one, h.pow_eq_one] },
dvd_of_pow_eq_one := begin
rw h.eq_order_of,
intros l hl,
apply_fun f at hl,
rw [map_pow, _root_.map_one] at hl,
exact order_of_dvd_of_pow_eq_one hl
end }
lemma map_iff_of_injective [monoid_hom_class F M N] (hf : injective f) :
is_primitive_root (f ζ) k ↔ is_primitive_root ζ k :=
⟨λ h, h.of_map_of_injective hf, λ h, h.map_of_injective hf⟩
end maps
end comm_monoid
section comm_monoid_with_zero
variables {M₀ : Type*} [comm_monoid_with_zero M₀]
lemma zero [nontrivial M₀] : is_primitive_root (0 : M₀) 0 :=
⟨pow_zero 0, λ l hl, by simpa [zero_pow_eq, show ∀ p, ¬p → false ↔ p, from @not_not] using hl⟩
protected lemma ne_zero [nontrivial M₀] {ζ : M₀} (h : is_primitive_root ζ k) : k ≠ 0 → ζ ≠ 0 :=
mt $ λ hn, h.unique (hn.symm ▸ is_primitive_root.zero)
end comm_monoid_with_zero
section division_comm_monoid
variables {ζ : G}
lemma zpow_eq_one (h : is_primitive_root ζ k) : ζ ^ (k : ℤ) = 1 :=
by { rw zpow_coe_nat, exact h.pow_eq_one }
lemma zpow_eq_one_iff_dvd (h : is_primitive_root ζ k) (l : ℤ) :
ζ ^ l = 1 ↔ (k : ℤ) ∣ l :=
begin
by_cases h0 : 0 ≤ l,
{ lift l to ℕ using h0, rw [zpow_coe_nat], norm_cast, exact h.pow_eq_one_iff_dvd l },
{ have : 0 ≤ -l, { simp only [not_le, neg_nonneg] at h0 ⊢, exact le_of_lt h0 },
lift -l to ℕ using this with l' hl',
rw [← dvd_neg, ← hl'],
norm_cast,
rw [← h.pow_eq_one_iff_dvd, ← inv_inj, ← zpow_neg, ← hl', zpow_coe_nat, inv_one] }
end
lemma inv (h : is_primitive_root ζ k) : is_primitive_root ζ⁻¹ k :=
{ pow_eq_one := by simp only [h.pow_eq_one, inv_one, eq_self_iff_true, inv_pow],
dvd_of_pow_eq_one :=
begin
intros l hl,
apply h.dvd_of_pow_eq_one l,
rw [← inv_inj, ← inv_pow, hl, inv_one]
end }
@[simp] lemma inv_iff : is_primitive_root ζ⁻¹ k ↔ is_primitive_root ζ k :=
by { refine ⟨_, λ h, inv h⟩, intro h, rw [← inv_inv ζ], exact inv h }
lemma zpow_of_gcd_eq_one (h : is_primitive_root ζ k) (i : ℤ) (hi : i.gcd k = 1) :
is_primitive_root (ζ ^ i) k :=
begin
by_cases h0 : 0 ≤ i,
{ lift i to ℕ using h0,
rw zpow_coe_nat,
exact h.pow_of_coprime i hi },
have : 0 ≤ -i, { simp only [not_le, neg_nonneg] at h0 ⊢, exact le_of_lt h0 },
lift -i to ℕ using this with i' hi',
rw [← inv_iff, ← zpow_neg, ← hi', zpow_coe_nat],
apply h.pow_of_coprime,
rw [int.gcd, ← int.nat_abs_neg, ← hi'] at hi,
exact hi
end
end division_comm_monoid
section is_domain
variables {ζ : R}
variables [comm_ring R] [is_domain R]
@[simp] lemma primitive_roots_one : primitive_roots 1 R = {(1 : R)} :=
begin
apply finset.eq_singleton_iff_unique_mem.2,
split,
{ simp only [is_primitive_root.one_right_iff, mem_primitive_roots zero_lt_one] },
{ intros x hx,
rw [mem_primitive_roots zero_lt_one, is_primitive_root.one_right_iff] at hx,
exact hx }
end
lemma ne_zero' {n : ℕ+} (hζ : is_primitive_root ζ n) : ne_zero ((n : ℕ) : R) :=
begin
let p := ring_char R,
have hfin := (multiplicity.finite_nat_iff.2 ⟨char_p.char_ne_one R p, n.pos⟩),
obtain ⟨m, hm⟩ := multiplicity.exists_eq_pow_mul_and_not_dvd hfin,
by_cases hp : p ∣ n,
{ obtain ⟨k, hk⟩ := nat.exists_eq_succ_of_ne_zero (multiplicity.pos_of_dvd hfin hp).ne',
haveI : ne_zero p := ne_zero.of_pos (nat.pos_of_dvd_of_pos hp n.pos),
haveI hpri : fact p.prime := char_p.char_is_prime_of_pos R p,
have := hζ.pow_eq_one,
rw [hm.1, hk, pow_succ, mul_assoc, pow_mul', ← frobenius_def, ← frobenius_one p] at this,
exfalso,
have hpos : 0 < p ^ k * m,
{ refine (mul_pos (pow_pos hpri.1.pos _) (nat.pos_of_ne_zero (λ h, _))),
have H := hm.1,
rw [h] at H,
simpa using H },
refine hζ.pow_ne_one_of_pos_of_lt hpos _ (frobenius_inj R p this),
{ rw [hm.1, hk, pow_succ, mul_assoc, mul_comm p],
exact lt_mul_of_one_lt_right hpos hpri.1.one_lt } },
{ exact ne_zero.of_not_dvd R hp }
end
lemma mem_nth_roots_finset (hζ : is_primitive_root ζ k) (hk : 0 < k) :
ζ ∈ nth_roots_finset k R :=
(mem_nth_roots_finset hk).2 hζ.pow_eq_one
end is_domain
section is_domain
variables [comm_ring R]
variables {ζ : Rˣ} (h : is_primitive_root ζ k)
lemma eq_neg_one_of_two_right [no_zero_divisors R] {ζ : R} (h : is_primitive_root ζ 2) : ζ = -1 :=
begin
apply (eq_or_eq_neg_of_sq_eq_sq ζ 1 _).resolve_left,
{ rw [← pow_one ζ], apply h.pow_ne_one_of_pos_of_lt; dec_trivial },
{ simp only [h.pow_eq_one, one_pow] }
end
lemma neg_one (p : ℕ) [nontrivial R] [h : char_p R p] (hp : p ≠ 2) : is_primitive_root (-1 : R) 2 :=
begin
convert is_primitive_root.order_of (-1 : R),
rw [order_of_neg_one, if_neg],
rwa ring_char.eq_iff.mpr h
end
/-- If `1 < k` then `(∑ i in range k, ζ ^ i) = 0`. -/
lemma geom_sum_eq_zero [is_domain R] {ζ : R} (hζ : is_primitive_root ζ k) (hk : 1 < k) :
(∑ i in range k, ζ ^ i) = 0 :=
begin
refine eq_zero_of_ne_zero_of_mul_left_eq_zero (sub_ne_zero_of_ne (hζ.ne_one hk).symm) _,
rw [mul_neg_geom_sum, hζ.pow_eq_one, sub_self]
end
/-- If `1 < k`, then `ζ ^ k.pred = -(∑ i in range k.pred, ζ ^ i)`. -/
lemma pow_sub_one_eq [is_domain R] {ζ : R} (hζ : is_primitive_root ζ k) (hk : 1 < k) :
ζ ^ k.pred = -(∑ i in range k.pred, ζ ^ i) :=
by rw [eq_neg_iff_add_eq_zero, add_comm, ←sum_range_succ, ←nat.succ_eq_add_one,
nat.succ_pred_eq_of_pos (pos_of_gt hk), hζ.geom_sum_eq_zero hk]
/-- The (additive) monoid equivalence between `zmod k`
and the powers of a primitive root of unity `ζ`. -/
def zmod_equiv_zpowers (h : is_primitive_root ζ k) : zmod k ≃+ additive (subgroup.zpowers ζ) :=
add_equiv.of_bijective
(add_monoid_hom.lift_of_right_inverse (int.cast_add_hom $ zmod k) _ zmod.int_cast_right_inverse
⟨{ to_fun := λ i, additive.of_mul (⟨_, i, rfl⟩ : subgroup.zpowers ζ),
map_zero' := by { simp only [zpow_zero], refl },
map_add' := by { intros i j, simp only [zpow_add], refl } },
(λ i hi,
begin
simp only [add_monoid_hom.mem_ker, char_p.int_cast_eq_zero_iff (zmod k) k,
add_monoid_hom.coe_mk, int.coe_cast_add_hom] at hi ⊢,
obtain ⟨i, rfl⟩ := hi,
simp only [zpow_mul, h.pow_eq_one, one_zpow, zpow_coe_nat],
refl
end)⟩)
begin
split,
{ rw injective_iff_map_eq_zero,
intros i hi,
rw subtype.ext_iff at hi,
have := (h.zpow_eq_one_iff_dvd _).mp hi,
rw [← (char_p.int_cast_eq_zero_iff (zmod k) k _).mpr this, eq_comm],
exact zmod.int_cast_right_inverse i },
{ rintro ⟨ξ, i, rfl⟩,
refine ⟨int.cast_add_hom _ i, _⟩,
rw [add_monoid_hom.lift_of_right_inverse_comp_apply],
refl }
end
@[simp] lemma zmod_equiv_zpowers_apply_coe_int (i : ℤ) :
h.zmod_equiv_zpowers i = additive.of_mul (⟨ζ ^ i, i, rfl⟩ : subgroup.zpowers ζ) :=
add_monoid_hom.lift_of_right_inverse_comp_apply _ _ zmod.int_cast_right_inverse _ _
@[simp] lemma zmod_equiv_zpowers_apply_coe_nat (i : ℕ) :
h.zmod_equiv_zpowers i = additive.of_mul (⟨ζ ^ i, i, rfl⟩ : subgroup.zpowers ζ) :=
begin
have : (i : zmod k) = (i : ℤ), by norm_cast,
simp only [this, zmod_equiv_zpowers_apply_coe_int, zpow_coe_nat],
refl
end
@[simp] lemma zmod_equiv_zpowers_symm_apply_zpow (i : ℤ) :
h.zmod_equiv_zpowers.symm (additive.of_mul (⟨ζ ^ i, i, rfl⟩ : subgroup.zpowers ζ)) = i :=
by rw [← h.zmod_equiv_zpowers.symm_apply_apply i, zmod_equiv_zpowers_apply_coe_int]
@[simp] lemma zmod_equiv_zpowers_symm_apply_zpow' (i : ℤ) :
h.zmod_equiv_zpowers.symm ⟨ζ ^ i, i, rfl⟩ = i :=
h.zmod_equiv_zpowers_symm_apply_zpow i
@[simp] lemma zmod_equiv_zpowers_symm_apply_pow (i : ℕ) :
h.zmod_equiv_zpowers.symm (additive.of_mul (⟨ζ ^ i, i, rfl⟩ : subgroup.zpowers ζ)) = i :=
by rw [← h.zmod_equiv_zpowers.symm_apply_apply i, zmod_equiv_zpowers_apply_coe_nat]
@[simp] lemma zmod_equiv_zpowers_symm_apply_pow' (i : ℕ) :
h.zmod_equiv_zpowers.symm ⟨ζ ^ i, i, rfl⟩ = i :=
h.zmod_equiv_zpowers_symm_apply_pow i
variables [is_domain R]
lemma zpowers_eq {k : ℕ+} {ζ : Rˣ} (h : is_primitive_root ζ k) :
subgroup.zpowers ζ = roots_of_unity k R :=
begin
apply set_like.coe_injective,
haveI F : fintype (subgroup.zpowers ζ) := fintype.of_equiv _ (h.zmod_equiv_zpowers).to_equiv,
refine @set.eq_of_subset_of_card_le Rˣ (subgroup.zpowers ζ) (roots_of_unity k R)
F (roots_of_unity.fintype R k)
(subgroup.zpowers_le_of_mem $ show ζ ∈ roots_of_unity k R, from h.pow_eq_one) _,
calc fintype.card (roots_of_unity k R)
≤ k : card_roots_of_unity R k
... = fintype.card (zmod k) : (zmod.card k).symm
... = fintype.card (subgroup.zpowers ζ) : fintype.card_congr (h.zmod_equiv_zpowers).to_equiv
end
lemma eq_pow_of_mem_roots_of_unity {k : ℕ+} {ζ ξ : Rˣ}
(h : is_primitive_root ζ k) (hξ : ξ ∈ roots_of_unity k R) :
∃ (i : ℕ) (hi : i < k), ζ ^ i = ξ :=
begin
obtain ⟨n, rfl⟩ : ∃ n : ℤ, ζ ^ n = ξ, by rwa [← h.zpowers_eq] at hξ,
have hk0 : (0 : ℤ) < k := by exact_mod_cast k.pos,
let i := n % k,
have hi0 : 0 ≤ i := int.mod_nonneg _ (ne_of_gt hk0),
lift i to ℕ using hi0 with i₀ hi₀,
refine ⟨i₀, _, _⟩,
{ zify, rw [hi₀], exact int.mod_lt_of_pos _ hk0 },
{ have aux := h.zpow_eq_one, rw [← coe_coe] at aux,
rw [← zpow_coe_nat, hi₀, ← int.mod_add_div n k, zpow_add, zpow_mul,
aux, one_zpow, mul_one] }
end
lemma eq_pow_of_pow_eq_one {k : ℕ} {ζ ξ : R}
(h : is_primitive_root ζ k) (hξ : ξ ^ k = 1) (h0 : 0 < k) :
∃ i < k, ζ ^ i = ξ :=
begin
lift ζ to Rˣ using h.is_unit h0,
lift ξ to Rˣ using is_unit_of_pow_eq_one hξ h0.ne',
lift k to ℕ+ using h0,
simp only [← units.coe_pow, ← units.ext_iff],
rw coe_units_iff at h,
apply h.eq_pow_of_mem_roots_of_unity,
rw [mem_roots_of_unity, units.ext_iff, units.coe_pow, hξ, units.coe_one]
end
lemma is_primitive_root_iff' {k : ℕ+} {ζ ξ : Rˣ} (h : is_primitive_root ζ k) :
is_primitive_root ξ k ↔ ∃ (i < (k : ℕ)) (hi : i.coprime k), ζ ^ i = ξ :=
begin
split,
{ intro hξ,
obtain ⟨i, hik, rfl⟩ := h.eq_pow_of_mem_roots_of_unity hξ.pow_eq_one,
rw h.pow_iff_coprime k.pos at hξ,
exact ⟨i, hik, hξ, rfl⟩ },
{ rintro ⟨i, -, hi, rfl⟩, exact h.pow_of_coprime i hi }
end
lemma is_primitive_root_iff {k : ℕ} {ζ ξ : R} (h : is_primitive_root ζ k) (h0 : 0 < k) :
is_primitive_root ξ k ↔ ∃ (i < k) (hi : i.coprime k), ζ ^ i = ξ :=
begin
split,
{ intro hξ,
obtain ⟨i, hik, rfl⟩ := h.eq_pow_of_pow_eq_one hξ.pow_eq_one h0,
rw h.pow_iff_coprime h0 at hξ,
exact ⟨i, hik, hξ, rfl⟩ },
{ rintro ⟨i, -, hi, rfl⟩, exact h.pow_of_coprime i hi }
end
lemma card_roots_of_unity' {n : ℕ+} (h : is_primitive_root ζ n) :
fintype.card (roots_of_unity n R) = n :=
begin
let e := h.zmod_equiv_zpowers,
haveI F : fintype (subgroup.zpowers ζ) := fintype.of_equiv _ e.to_equiv,
calc fintype.card (roots_of_unity n R)
= fintype.card (subgroup.zpowers ζ) : fintype.card_congr $ by rw h.zpowers_eq
... = fintype.card (zmod n) : fintype.card_congr e.to_equiv.symm
... = n : zmod.card n
end
lemma card_roots_of_unity {ζ : R} {n : ℕ+} (h : is_primitive_root ζ n) :
fintype.card (roots_of_unity n R) = n :=
begin
obtain ⟨ζ, hζ⟩ := h.is_unit n.pos,
rw [← hζ, is_primitive_root.coe_units_iff] at h,
exact h.card_roots_of_unity'
end
/-- The cardinality of the multiset `nth_roots ↑n (1 : R)` is `n`
if there is a primitive root of unity in `R`. -/
lemma card_nth_roots {ζ : R} {n : ℕ} (h : is_primitive_root ζ n) :
(nth_roots n (1 : R)).card = n :=
begin
cases nat.eq_zero_or_pos n with hzero hpos,
{ simp only [hzero, multiset.card_zero, nth_roots_zero] },
rw eq_iff_le_not_lt,
use card_nth_roots n 1,
{ rw [not_lt],
have hcard : fintype.card {x // x ∈ nth_roots n (1 : R)}
≤ (nth_roots n (1 : R)).attach.card := multiset.card_le_of_le (multiset.dedup_le _),
rw multiset.card_attach at hcard,
rw ← pnat.to_pnat'_coe hpos at hcard h ⊢,
set m := nat.to_pnat' n,
rw [← fintype.card_congr (roots_of_unity_equiv_nth_roots R m), card_roots_of_unity h] at hcard,
exact hcard }
end
/-- The multiset `nth_roots ↑n (1 : R)` has no repeated elements
if there is a primitive root of unity in `R`. -/
lemma nth_roots_nodup {ζ : R} {n : ℕ} (h : is_primitive_root ζ n) : (nth_roots n (1 : R)).nodup :=
begin
cases nat.eq_zero_or_pos n with hzero hpos,
{ simp only [hzero, multiset.nodup_zero, nth_roots_zero] },
apply (@multiset.dedup_eq_self R _ _).1,
rw eq_iff_le_not_lt,
split,
{ exact multiset.dedup_le (nth_roots n (1 : R)) },
{ by_contra ha,
replace ha := multiset.card_lt_of_lt ha,
rw card_nth_roots h at ha,
have hrw : (nth_roots n (1 : R)).dedup.card =
fintype.card {x // x ∈ (nth_roots n (1 : R))},
{ set fs := (⟨(nth_roots n (1 : R)).dedup, multiset.nodup_dedup _⟩ : finset R),
rw [← finset.card_mk, ← fintype.card_of_subtype fs _],
intro x,
simp only [multiset.mem_dedup, finset.mem_mk] },
rw ← pnat.to_pnat'_coe hpos at h hrw ha,
set m := nat.to_pnat' n,
rw [hrw, ← fintype.card_congr (roots_of_unity_equiv_nth_roots R m),
card_roots_of_unity h] at ha,
exact nat.lt_asymm ha ha }
end
@[simp] lemma card_nth_roots_finset {ζ : R} {n : ℕ} (h : is_primitive_root ζ n) :
(nth_roots_finset n R).card = n :=
by rw [nth_roots_finset, ← multiset.to_finset_eq (nth_roots_nodup h), card_mk, h.card_nth_roots]
open_locale nat
/-- If an integral domain has a primitive `k`-th root of unity, then it has `φ k` of them. -/
lemma card_primitive_roots {ζ : R} {k : ℕ} (h : is_primitive_root ζ k) :
(primitive_roots k R).card = φ k :=
begin
by_cases h0 : k = 0,
{ simp [h0], },
symmetry,
refine finset.card_congr (λ i _, ζ ^ i) _ _ _,
{ simp only [true_and, and_imp, mem_filter, mem_range, mem_univ],
rintro i - hi,
rw mem_primitive_roots (nat.pos_of_ne_zero h0),
exact h.pow_of_coprime i hi.symm },
{ simp only [true_and, and_imp, mem_filter, mem_range, mem_univ],
rintro i j hi - hj - H,
exact h.pow_inj hi hj H },
{ simp only [exists_prop, true_and, mem_filter, mem_range, mem_univ],
intros ξ hξ,
rw [mem_primitive_roots (nat.pos_of_ne_zero h0),
h.is_primitive_root_iff (nat.pos_of_ne_zero h0)] at hξ,
rcases hξ with ⟨i, hin, hi, H⟩,
exact ⟨i, ⟨hin, hi.symm⟩, H⟩ }
end
/-- The sets `primitive_roots k R` are pairwise disjoint. -/
lemma disjoint {k l : ℕ} (h : k ≠ l) :
disjoint (primitive_roots k R) (primitive_roots l R) :=
finset.disjoint_left.2 $ λ z hk hl, h $ (is_primitive_root_of_mem_primitive_roots hk).unique $
is_primitive_root_of_mem_primitive_roots hl
/-- `nth_roots n` as a `finset` is equal to the union of `primitive_roots i R` for `i ∣ n`
if there is a primitive root of unity in `R`.
This holds for any `nat`, not just `pnat`, see `nth_roots_one_eq_bUnion_primitive_roots`. -/
lemma nth_roots_one_eq_bUnion_primitive_roots' {ζ : R} {n : ℕ+} (h : is_primitive_root ζ n) :
nth_roots_finset n R = (nat.divisors ↑n).bUnion (λ i, (primitive_roots i R)) :=
begin
symmetry,
apply finset.eq_of_subset_of_card_le,
{ intros x,
simp only [nth_roots_finset, ← multiset.to_finset_eq (nth_roots_nodup h),
exists_prop, finset.mem_bUnion, finset.mem_filter, finset.mem_range, mem_nth_roots,
finset.mem_mk, nat.mem_divisors, and_true, ne.def, pnat.ne_zero, pnat.pos, not_false_iff],
rintro ⟨a, ⟨d, hd⟩, ha⟩,
have hazero : 0 < a,
{ contrapose! hd with ha0,
simp only [nonpos_iff_eq_zero, zero_mul, *] at *,
exact n.ne_zero },
rw mem_primitive_roots hazero at ha,
rw [hd, pow_mul, ha.pow_eq_one, one_pow] },
{ apply le_of_eq,
rw [h.card_nth_roots_finset, finset.card_bUnion],
{ nth_rewrite_lhs 0 ← nat.sum_totient n,
refine sum_congr rfl _,
simp only [nat.mem_divisors],
rintro k ⟨⟨d, hd⟩, -⟩,
rw mul_comm at hd,
rw (h.pow n.pos hd).card_primitive_roots },
{ intros i hi j hj hdiff,
exact disjoint hdiff } }
end
/-- `nth_roots n` as a `finset` is equal to the union of `primitive_roots i R` for `i ∣ n`
if there is a primitive root of unity in `R`. -/
lemma nth_roots_one_eq_bUnion_primitive_roots {ζ : R} {n : ℕ}
(h : is_primitive_root ζ n) :
nth_roots_finset n R = (nat.divisors n).bUnion (λ i, (primitive_roots i R)) :=
begin
by_cases hn : n = 0,
{ simp [hn], },
exact @nth_roots_one_eq_bUnion_primitive_roots' _ _ _ _ ⟨n, nat.pos_of_ne_zero hn⟩ h
end
end is_domain
section automorphisms
variables {S} [comm_ring S] [is_domain S] {μ : S} {n : ℕ+} (hμ : is_primitive_root μ n)
(R) [comm_ring R] [algebra R S]
/-- The `monoid_hom` that takes an automorphism to the power of μ that μ gets mapped to under it. -/
noncomputable def aut_to_pow : (S ≃ₐ[R] S) →* (zmod n)ˣ :=
let μ' := hμ.to_roots_of_unity in
have ho : order_of μ' = n :=
by rw [hμ.eq_order_of, ←hμ.coe_to_roots_of_unity_coe, order_of_units, order_of_subgroup],
monoid_hom.to_hom_units
{ to_fun := λ σ, (map_root_of_unity_eq_pow_self σ.to_alg_hom μ').some,
map_one' := begin
generalize_proofs h1,
have h := h1.some_spec,
dsimp only [alg_equiv.one_apply, alg_equiv.to_ring_equiv_eq_coe, ring_equiv.to_ring_hom_eq_coe,
ring_equiv.coe_to_ring_hom, alg_equiv.coe_ring_equiv] at *,
replace h : μ' = μ' ^ h1.some := roots_of_unity.coe_injective
(by simpa only [roots_of_unity.coe_pow] using h),
rw ←pow_one μ' at h {occs := occurrences.pos [1]},
rw [←@nat.cast_one $ zmod n, zmod.nat_coe_eq_nat_coe_iff, ←ho, ←pow_eq_pow_iff_modeq μ', h]
end,
map_mul' := begin
generalize_proofs hxy' hx' hy',
have hxy := hxy'.some_spec,
have hx := hx'.some_spec,
have hy := hy'.some_spec,
dsimp only [alg_equiv.to_ring_equiv_eq_coe, ring_equiv.to_ring_hom_eq_coe,
ring_equiv.coe_to_ring_hom, alg_equiv.coe_ring_equiv, alg_equiv.mul_apply] at *,
replace hxy : x (↑μ' ^ hy'.some) = ↑μ' ^ hxy'.some := hy ▸ hxy,
rw x.map_pow at hxy,
replace hxy : ((μ' : S) ^ hx'.some) ^ hy'.some = μ' ^ hxy'.some := hx ▸ hxy,
rw ←pow_mul at hxy,
replace hxy : μ' ^ (hx'.some * hy'.some) = μ' ^ hxy'.some := roots_of_unity.coe_injective
(by simpa only [roots_of_unity.coe_pow] using hxy),
rw [←nat.cast_mul, zmod.nat_coe_eq_nat_coe_iff, ←ho, ←pow_eq_pow_iff_modeq μ', hxy]
end }
-- We are not using @[simps] in aut_to_pow to avoid a timeout.
lemma coe_aut_to_pow_apply (f : S ≃ₐ[R] S) : (aut_to_pow R hμ f : zmod n) =
((map_root_of_unity_eq_pow_self f hμ.to_roots_of_unity).some : zmod n) := rfl
@[simp] lemma aut_to_pow_spec (f : S ≃ₐ[R] S) :
μ ^ (hμ.aut_to_pow R f : zmod n).val = f μ :=
begin
rw is_primitive_root.coe_aut_to_pow_apply,
generalize_proofs h,
have := h.some_spec,
dsimp only [alg_equiv.to_alg_hom_eq_coe, alg_equiv.coe_alg_hom] at this,
refine (_ : ↑hμ.to_roots_of_unity ^ _ = _).trans this.symm,
rw [←roots_of_unity.coe_pow, ←roots_of_unity.coe_pow],
congr' 1,
rw [pow_eq_pow_iff_modeq, ←order_of_subgroup, ←order_of_units, hμ.coe_to_roots_of_unity_coe,
←hμ.eq_order_of, zmod.val_nat_cast],
exact nat.mod_modeq _ _
end
end automorphisms
end is_primitive_root
|
0ef0e0776e103a32adf06aee4fe4b3fb7400aca0 | b00eb947a9c4141624aa8919e94ce6dcd249ed70 | /stage0/src/Init/Core.lean | bf0495da2c68d5f475fe02dc54f4c49b5626bff2 | [
"Apache-2.0"
] | permissive | gebner/lean4-old | a4129a041af2d4d12afb3a8d4deedabde727719b | ee51cdfaf63ee313c914d83264f91f414a0e3b6e | refs/heads/master | 1,683,628,606,745 | 1,622,651,300,000 | 1,622,654,405,000 | 142,608,821 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 34,931 | lean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
notation, basic datatypes and type classes
-/
prelude
import Init.Prelude
import Init.SizeOf
universes u v w
def inline {α : Sort u} (a : α) : α := a
@[inline] def flip {α : Sort u} {β : Sort v} {φ : Sort w} (f : α → β → φ) : β → α → φ :=
fun b a => f a b
/--
Thunks are "lazy" values that are evaluated when first accessed using `Thunk.get/map/bind`.
The value is then stored and not recomputed for all further accesses. -/
-- NOTE: the runtime has special support for the `Thunk` type to implement this behavior
structure Thunk (α : Type u) : Type u where
-- TODO: make private
fn : Unit → α
attribute [extern "lean_mk_thunk"] Thunk.mk
/-- Store a value in a thunk. Note that the value has already been computed, so there is no laziness. -/
@[extern "lean_thunk_pure"] protected def Thunk.pure (a : α) : Thunk α :=
⟨fun _ => a⟩
-- NOTE: we use `Thunk.get` instead of `Thunk.fn` as the accessor primitive as the latter has an additional `Unit` argument
@[extern "lean_thunk_get_own"] protected def Thunk.get (x : @& Thunk α) : α :=
x.fn ()
@[inline] protected def Thunk.map (f : α → β) (x : Thunk α) : Thunk β :=
⟨fun _ => f x.get⟩
@[inline] protected def Thunk.bind (x : Thunk α) (f : α → Thunk β) : Thunk β :=
⟨fun _ => (f x.get).get⟩
abbrev Eq.ndrecOn.{u1, u2} {α : Sort u2} {a : α} {motive : α → Sort u1} {b : α} (h : a = b) (m : motive a) : motive b :=
Eq.ndrec m h
structure Iff (a b : Prop) : Prop where
intro :: (mp : a → b) (mpr : b → a)
infix:20 " <-> " => Iff
infix:20 " ↔ " => Iff
inductive Sum (α : Type u) (β : Type v) where
| inl (val : α) : Sum α β
| inr (val : β) : Sum α β
inductive PSum (α : Sort u) (β : Sort v) where
| inl (val : α) : PSum α β
| inr (val : β) : PSum α β
structure Sigma {α : Type u} (β : α → Type v) where
fst : α
snd : β fst
attribute [unbox] Sigma
structure PSigma {α : Sort u} (β : α → Sort v) where
fst : α
snd : β fst
inductive Exists {α : Sort u} (p : α → Prop) : Prop where
| intro (w : α) (h : p w) : Exists p
/- Auxiliary type used to compile `for x in xs` notation. -/
inductive ForInStep (α : Type u) where
| done : α → ForInStep α
| yield : α → ForInStep α
class ForIn (m : Type u₁ → Type u₂) (ρ : Type u) (α : outParam (Type v)) where
forIn {β} [Monad m] (x : ρ) (b : β) (f : α → β → m (ForInStep β)) : m β
export ForIn (forIn)
/- Auxiliary type used to compile `do` notation. -/
inductive DoResultPRBC (α β σ : Type u) where
| «pure» : α → σ → DoResultPRBC α β σ
| «return» : β → σ → DoResultPRBC α β σ
| «break» : σ → DoResultPRBC α β σ
| «continue» : σ → DoResultPRBC α β σ
/- Auxiliary type used to compile `do` notation. -/
inductive DoResultPR (α β σ : Type u) where
| «pure» : α → σ → DoResultPR α β σ
| «return» : β → σ → DoResultPR α β σ
/- Auxiliary type used to compile `do` notation. -/
inductive DoResultBC (σ : Type u) where
| «break» : σ → DoResultBC σ
| «continue» : σ → DoResultBC σ
/- Auxiliary type used to compile `do` notation. -/
inductive DoResultSBC (α σ : Type u) where
| «pureReturn» : α → σ → DoResultSBC α σ
| «break» : σ → DoResultSBC α σ
| «continue» : σ → DoResultSBC α σ
class HasEquiv (α : Sort u) where
Equiv : α → α → Sort v
infix:50 " ≈ " => HasEquiv.Equiv
class EmptyCollection (α : Type u) where
emptyCollection : α
notation "{" "}" => EmptyCollection.emptyCollection
notation "∅" => EmptyCollection.emptyCollection
/- Remark: tasks have an efficient implementation in the runtime. -/
structure Task (α : Type u) : Type u where
pure :: (get : α)
attribute [extern "lean_task_pure"] Task.pure
attribute [extern "lean_task_get_own"] Task.get
namespace Task
/-- Task priority. Tasks with higher priority will always be scheduled before ones with lower priority. -/
abbrev Priority := Nat
def Priority.default : Priority := 0
-- see `LEAN_MAX_PRIO`
def Priority.max : Priority := 8
/--
Any priority higher than `Task.Priority.max` will result in the task being scheduled immediately on a dedicated thread.
This is particularly useful for long-running and/or I/O-bound tasks since Lean will by default allocate no more
non-dedicated workers than the number of cores to reduce context switches. -/
def Priority.dedicated : Priority := 9
@[noinline, extern "lean_task_spawn"]
protected def spawn {α : Type u} (fn : Unit → α) (prio := Priority.default) : Task α :=
⟨fn ()⟩
@[noinline, extern "lean_task_map"]
protected def map {α : Type u} {β : Type v} (f : α → β) (x : Task α) (prio := Priority.default) : Task β :=
⟨f x.get⟩
@[noinline, extern "lean_task_bind"]
protected def bind {α : Type u} {β : Type v} (x : Task α) (f : α → Task β) (prio := Priority.default) : Task β :=
⟨(f x.get).get⟩
end Task
/- Some type that is not a scalar value in our runtime. -/
structure NonScalar where
val : Nat
/- Some type that is not a scalar value in our runtime and is universe polymorphic. -/
inductive PNonScalar : Type u where
| mk (v : Nat) : PNonScalar
theorem natAddZero (n : Nat) : n + 0 = n := rfl
theorem optParamEq (α : Sort u) (default : α) : optParam α default = α := rfl
/- Boolean operators -/
@[extern c inline "#1 || #2"] def strictOr (b₁ b₂ : Bool) := b₁ || b₂
@[extern c inline "#1 && #2"] def strictAnd (b₁ b₂ : Bool) := b₁ && b₂
@[inline] def bne {α : Type u} [BEq α] (a b : α) : Bool :=
!(a == b)
infix:50 " != " => bne
/- Logical connectives an equality -/
def implies (a b : Prop) := a → b
theorem implies.trans {p q r : Prop} (h₁ : implies p q) (h₂ : implies q r) : implies p r :=
fun hp => h₂ (h₁ hp)
def trivial : True := ⟨⟩
theorem mt {a b : Prop} (h₁ : a → b) (h₂ : ¬b) : ¬a :=
fun ha => h₂ (h₁ ha)
theorem notFalse : ¬False := id
-- proof irrelevance is built in
theorem proofIrrel {a : Prop} (h₁ h₂ : a) : h₁ = h₂ := rfl
theorem id.def {α : Sort u} (a : α) : id a = a := rfl
@[macroInline] def Eq.mp {α β : Sort u} (h : α = β) (a : α) : β :=
h ▸ a
@[macroInline] def Eq.mpr {α β : Sort u} (h : α = β) (b : β) : α :=
h ▸ b
theorem Eq.substr {α : Sort u} {p : α → Prop} {a b : α} (h₁ : b = a) (h₂ : p a) : p b :=
h₁ ▸ h₂
theorem castEq {α : Sort u} (h : α = α) (a : α) : cast h a = a :=
rfl
@[reducible] def Ne {α : Sort u} (a b : α) :=
¬(a = b)
infix:50 " ≠ " => Ne
section Ne
variable {α : Sort u}
variable {a b : α} {p : Prop}
theorem Ne.intro (h : a = b → False) : a ≠ b := h
theorem Ne.elim (h : a ≠ b) : a = b → False := h
theorem Ne.irrefl (h : a ≠ a) : False := h rfl
theorem Ne.symm (h : a ≠ b) : b ≠ a :=
fun h₁ => h (h₁.symm)
theorem falseOfNe : a ≠ a → False := Ne.irrefl
theorem neFalseOfSelf : p → p ≠ False :=
fun (hp : p) (h : p = False) => h ▸ hp
theorem neTrueOfNot : ¬p → p ≠ True :=
fun (hnp : ¬p) (h : p = True) =>
have : ¬True := h ▸ hnp
this trivial
theorem trueNeFalse : ¬True = False :=
neFalseOfSelf trivial
end Ne
section
variable {α β φ : Sort u} {a a' : α} {b b' : β} {c : φ}
theorem HEq.ndrec.{u1, u2} {α : Sort u2} {a : α} {motive : {β : Sort u2} → β → Sort u1} (m : motive a) {β : Sort u2} {b : β} (h : a ≅ b) : motive b :=
@HEq.rec α a (fun b _ => motive b) m β b h
theorem HEq.ndrecOn.{u1, u2} {α : Sort u2} {a : α} {motive : {β : Sort u2} → β → Sort u1} {β : Sort u2} {b : β} (h : a ≅ b) (m : motive a) : motive b :=
@HEq.rec α a (fun b _ => motive b) m β b h
theorem HEq.elim {α : Sort u} {a : α} {p : α → Sort v} {b : α} (h₁ : a ≅ b) (h₂ : p a) : p b :=
eqOfHEq h₁ ▸ h₂
theorem HEq.subst {p : (T : Sort u) → T → Prop} (h₁ : a ≅ b) (h₂ : p α a) : p β b :=
HEq.ndrecOn h₁ h₂
theorem HEq.symm (h : a ≅ b) : b ≅ a :=
HEq.ndrecOn (motive := fun x => x ≅ a) h (HEq.refl a)
theorem heqOfEq (h : a = a') : a ≅ a' :=
Eq.subst h (HEq.refl a)
theorem HEq.trans (h₁ : a ≅ b) (h₂ : b ≅ c) : a ≅ c :=
HEq.subst h₂ h₁
theorem heqOfHEqOfEq (h₁ : a ≅ b) (h₂ : b = b') : a ≅ b' :=
HEq.trans h₁ (heqOfEq h₂)
theorem heqOfEqOfHEq (h₁ : a = a') (h₂ : a' ≅ b) : a ≅ b :=
HEq.trans (heqOfEq h₁) h₂
def typeEqOfHEq (h : a ≅ b) : α = β :=
HEq.ndrecOn (motive := @fun (x : Sort u) _ => α = x) h (Eq.refl α)
end
theorem eqRecHEq {α : Sort u} {φ : α → Sort v} {a a' : α} : (h : a = a') → (p : φ a) → (Eq.recOn (motive := fun x _ => φ x) h p) ≅ p
| rfl, p => HEq.refl p
theorem heqOfEqRecEq {α β : Sort u} {a : α} {b : β} (h₁ : α = β) (h₂ : Eq.rec (motive := fun α _ => α) a h₁ = b) : a ≅ b := by
subst h₁
apply heqOfEq
exact h₂
theorem castHEq {α β : Sort u} : (h : α = β) → (a : α) → cast h a ≅ a
| rfl, a => HEq.refl a
variable {a b c d : Prop}
theorem iffIffImpliesAndImplies (a b : Prop) : (a ↔ b) ↔ (a → b) ∧ (b → a) :=
Iff.intro (fun h => And.intro h.mp h.mpr) (fun h => Iff.intro h.left h.right)
theorem Iff.refl (a : Prop) : a ↔ a :=
Iff.intro (fun h => h) (fun h => h)
theorem Iff.rfl {a : Prop} : a ↔ a :=
Iff.refl a
theorem Iff.trans (h₁ : a ↔ b) (h₂ : b ↔ c) : a ↔ c :=
Iff.intro
(fun ha => Iff.mp h₂ (Iff.mp h₁ ha))
(fun hc => Iff.mpr h₁ (Iff.mpr h₂ hc))
theorem Iff.symm (h : a ↔ b) : b ↔ a :=
Iff.intro (Iff.mpr h) (Iff.mp h)
theorem Iff.comm : (a ↔ b) ↔ (b ↔ a) :=
Iff.intro Iff.symm Iff.symm
/- Exists -/
theorem Exists.elim {α : Sort u} {p : α → Prop} {b : Prop}
(h₁ : Exists (fun x => p x)) (h₂ : ∀ (a : α), p a → b) : b :=
h₂ h₁.1 h₁.2
/- Decidable -/
theorem decideTrueEqTrue (h : Decidable True) : @decide True h = true :=
match h with
| isTrue h => rfl
| isFalse h => False.elim <| h ⟨⟩
theorem decideFalseEqFalse (h : Decidable False) : @decide False h = false :=
match h with
| isFalse h => rfl
| isTrue h => False.elim h
/-- Similar to `decide`, but uses an explicit instance -/
@[inline] def toBoolUsing {p : Prop} (d : Decidable p) : Bool :=
decide p (h := d)
theorem toBoolUsingEqTrue {p : Prop} (d : Decidable p) (h : p) : toBoolUsing d = true :=
decideEqTrue (s := d) h
theorem ofBoolUsingEqTrue {p : Prop} {d : Decidable p} (h : toBoolUsing d = true) : p :=
ofDecideEqTrue (s := d) h
theorem ofBoolUsingEqFalse {p : Prop} {d : Decidable p} (h : toBoolUsing d = false) : ¬ p :=
ofDecideEqFalse (s := d) h
instance : Decidable True :=
isTrue trivial
instance : Decidable False :=
isFalse notFalse
namespace Decidable
variable {p q : Prop}
@[macroInline] def byCases {q : Sort u} [dec : Decidable p] (h1 : p → q) (h2 : ¬p → q) : q :=
match dec with
| isTrue h => h1 h
| isFalse h => h2 h
theorem em (p : Prop) [Decidable p] : p ∨ ¬p :=
byCases Or.inl Or.inr
theorem byContradiction [dec : Decidable p] (h : ¬p → False) : p :=
byCases id (fun np => False.elim (h np))
theorem ofNotNot [Decidable p] : ¬ ¬ p → p :=
fun hnn => byContradiction (fun hn => absurd hn hnn)
theorem notAndIffOrNot (p q : Prop) [d₁ : Decidable p] [d₂ : Decidable q] : ¬ (p ∧ q) ↔ ¬ p ∨ ¬ q :=
Iff.intro
(fun h => match d₁, d₂ with
| isTrue h₁, isTrue h₂ => absurd (And.intro h₁ h₂) h
| _, isFalse h₂ => Or.inr h₂
| isFalse h₁, _ => Or.inl h₁)
(fun (h) ⟨hp, hq⟩ => match h with
| Or.inl h => h hp
| Or.inr h => h hq)
end Decidable
section
variable {p q : Prop}
@[inline] def decidableOfDecidableOfIff (hp : Decidable p) (h : p ↔ q) : Decidable q :=
if hp : p then
isTrue (Iff.mp h hp)
else
isFalse fun hq => absurd (Iff.mpr h hq) hp
@[inline] def decidableOfDecidableOfEq (hp : Decidable p) (h : p = q) : Decidable q :=
h ▸ hp
end
@[macroInline] instance {p q} [Decidable p] [Decidable q] : Decidable (p → q) :=
if hp : p then
if hq : q then isTrue (fun h => hq)
else isFalse (fun h => absurd (h hp) hq)
else isTrue (fun h => absurd h hp)
instance {p q} [Decidable p] [Decidable q] : Decidable (p ↔ q) :=
if hp : p then
if hq : q then
isTrue ⟨fun _ => hq, fun _ => hp⟩
else
isFalse fun h => hq (h.1 hp)
else
if hq : q then
isFalse fun h => hp (h.2 hq)
else
isTrue ⟨fun h => absurd h hp, fun h => absurd h hq⟩
/- if-then-else expression theorems -/
theorem ifPos {c : Prop} [h : Decidable c] (hc : c) {α : Sort u} {t e : α} : (ite c t e) = t :=
match h with
| isTrue hc => rfl
| isFalse hnc => absurd hc hnc
theorem ifNeg {c : Prop} [h : Decidable c] (hnc : ¬c) {α : Sort u} {t e : α} : (ite c t e) = e :=
match h with
| isTrue hc => absurd hc hnc
| isFalse hnc => rfl
theorem difPos {c : Prop} [h : Decidable c] (hc : c) {α : Sort u} {t : c → α} {e : ¬ c → α} : (dite c t e) = t hc :=
match h with
| isTrue hc => rfl
| isFalse hnc => absurd hc hnc
theorem difNeg {c : Prop} [h : Decidable c] (hnc : ¬c) {α : Sort u} {t : c → α} {e : ¬ c → α} : (dite c t e) = e hnc :=
match h with
| isTrue hc => absurd hc hnc
| isFalse hnc => rfl
-- Remark: dite and ite are "defally equal" when we ignore the proofs.
theorem difEqIf (c : Prop) [h : Decidable c] {α : Sort u} (t : α) (e : α) : dite c (fun h => t) (fun h => e) = ite c t e :=
match h with
| isTrue hc => rfl
| isFalse hnc => rfl
instance {c t e : Prop} [dC : Decidable c] [dT : Decidable t] [dE : Decidable e] : Decidable (if c then t else e) :=
match dC with
| isTrue hc => dT
| isFalse hc => dE
instance {c : Prop} {t : c → Prop} {e : ¬c → Prop} [dC : Decidable c] [dT : ∀ h, Decidable (t h)] [dE : ∀ h, Decidable (e h)] : Decidable (if h : c then t h else e h) :=
match dC with
| isTrue hc => dT hc
| isFalse hc => dE hc
/- Inhabited -/
instance : Inhabited Prop where
default := True
deriving instance Inhabited for NonScalar, PNonScalar, True, ForInStep
class inductive Nonempty (α : Sort u) : Prop where
| intro (val : α) : Nonempty α
protected def Nonempty.elim {α : Sort u} {p : Prop} (h₁ : Nonempty α) (h₂ : α → p) : p :=
h₂ h₁.1
instance {α : Sort u} [Inhabited α] : Nonempty α where
val := arbitrary
theorem nonemptyOfExists {α : Sort u} {p : α → Prop} : Exists (fun x => p x) → Nonempty α
| ⟨w, h⟩ => ⟨w⟩
/- Subsingleton -/
class Subsingleton (α : Sort u) : Prop where
intro :: allEq : (a b : α) → a = b
protected def Subsingleton.elim {α : Sort u} [h : Subsingleton α] : (a b : α) → a = b :=
h.allEq
protected def Subsingleton.helim {α β : Sort u} [h₁ : Subsingleton α] (h₂ : α = β) (a : α) (b : β) : a ≅ b := by
subst h₂
apply heqOfEq
apply Subsingleton.elim
instance (p : Prop) : Subsingleton p :=
⟨fun a b => proofIrrel a b⟩
instance (p : Prop) : Subsingleton (Decidable p) :=
Subsingleton.intro fun
| isTrue t₁ => fun
| isTrue t₂ => rfl
| isFalse f₂ => absurd t₁ f₂
| isFalse f₁ => fun
| isTrue t₂ => absurd t₂ f₁
| isFalse f₂ => rfl
theorem recSubsingleton
{p : Prop} [h : Decidable p]
{h₁ : p → Sort u}
{h₂ : ¬p → Sort u}
[h₃ : ∀ (h : p), Subsingleton (h₁ h)]
[h₄ : ∀ (h : ¬p), Subsingleton (h₂ h)]
: Subsingleton (Decidable.casesOn (motive := fun _ => Sort u) h h₂ h₁) :=
match h with
| isTrue h => h₃ h
| isFalse h => h₄ h
structure Equivalence {α : Sort u} (r : α → α → Prop) : Prop where
refl : ∀ x, r x x
symm : ∀ {x y}, r x y → r y x
trans : ∀ {x y z}, r x y → r y z → r x z
def emptyRelation {α : Sort u} (a₁ a₂ : α) : Prop :=
False
def Subrelation {α : Sort u} (q r : α → α → Prop) :=
∀ {x y}, q x y → r x y
def InvImage {α : Sort u} {β : Sort v} (r : β → β → Prop) (f : α → β) : α → α → Prop :=
fun a₁ a₂ => r (f a₁) (f a₂)
inductive TC {α : Sort u} (r : α → α → Prop) : α → α → Prop where
| base : ∀ a b, r a b → TC r a b
| trans : ∀ a b c, TC r a b → TC r b c → TC r a c
/- Subtype -/
namespace Subtype
def existsOfSubtype {α : Type u} {p : α → Prop} : { x // p x } → Exists (fun x => p x)
| ⟨a, h⟩ => ⟨a, h⟩
variable {α : Type u} {p : α → Prop}
protected theorem eq : ∀ {a1 a2 : {x // p x}}, val a1 = val a2 → a1 = a2
| ⟨x, h1⟩, ⟨_, _⟩, rfl => rfl
theorem eta (a : {x // p x}) (h : p (val a)) : mk (val a) h = a := by
cases a
exact rfl
instance {α : Type u} {p : α → Prop} {a : α} (h : p a) : Inhabited {x // p x} where
default := ⟨a, h⟩
instance {α : Type u} {p : α → Prop} [DecidableEq α] : DecidableEq {x : α // p x} :=
fun ⟨a, h₁⟩ ⟨b, h₂⟩ =>
if h : a = b then isTrue (by subst h; exact rfl)
else isFalse (fun h' => Subtype.noConfusion h' (fun h' => absurd h' h))
end Subtype
/- Sum -/
section
variable {α : Type u} {β : Type v}
instance Sum.inhabitedLeft [h : Inhabited α] : Inhabited (Sum α β) where
default := Sum.inl arbitrary
instance Sum.inhabitedRight [h : Inhabited β] : Inhabited (Sum α β) where
default := Sum.inr arbitrary
instance {α : Type u} {β : Type v} [DecidableEq α] [DecidableEq β] : DecidableEq (Sum α β) := fun a b =>
match a, b with
| Sum.inl a, Sum.inl b =>
if h : a = b then isTrue (h ▸ rfl)
else isFalse fun h' => Sum.noConfusion h' fun h' => absurd h' h
| Sum.inr a, Sum.inr b =>
if h : a = b then isTrue (h ▸ rfl)
else isFalse fun h' => Sum.noConfusion h' fun h' => absurd h' h
| Sum.inr a, Sum.inl b => isFalse fun h => Sum.noConfusion h
| Sum.inl a, Sum.inr b => isFalse fun h => Sum.noConfusion h
end
/- Product -/
instance [Inhabited α] [Inhabited β] : Inhabited (α × β) where
default := (arbitrary, arbitrary)
instance [DecidableEq α] [DecidableEq β] : DecidableEq (α × β) :=
fun (a, b) (a', b') =>
match decEq a a' with
| isTrue e₁ =>
match decEq b b' with
| isTrue e₂ => isTrue (e₁ ▸ e₂ ▸ rfl)
| isFalse n₂ => isFalse fun h => Prod.noConfusion h fun e₁' e₂' => absurd e₂' n₂
| isFalse n₁ => isFalse fun h => Prod.noConfusion h fun e₁' e₂' => absurd e₁' n₁
instance [BEq α] [BEq β] : BEq (α × β) where
beq := fun (a₁, b₁) (a₂, b₂) => a₁ == a₂ && b₁ == b₂
instance [LT α] [LT β] : LT (α × β) where
lt s t := s.1 < t.1 ∨ (s.1 = t.1 ∧ s.2 < t.2)
instance prodHasDecidableLt
[LT α] [LT β] [DecidableEq α] [DecidableEq β]
[(a b : α) → Decidable (a < b)] [(a b : β) → Decidable (a < b)]
: (s t : α × β) → Decidable (s < t) :=
fun t s => inferInstanceAs (Decidable (_ ∨ _))
theorem Prod.ltDef [LT α] [LT β] (s t : α × β) : (s < t) = (s.1 < t.1 ∨ (s.1 = t.1 ∧ s.2 < t.2)) :=
rfl
theorem Prod.ext (p : α × β) : (p.1, p.2) = p := by
cases p; rfl
def Prod.map {α₁ : Type u₁} {α₂ : Type u₂} {β₁ : Type v₁} {β₂ : Type v₂}
(f : α₁ → α₂) (g : β₁ → β₂) : α₁ × β₁ → α₂ × β₂
| (a, b) => (f a, g b)
/- Dependent products -/
theorem exOfPsig {α : Type u} {p : α → Prop} : (PSigma (fun x => p x)) → Exists (fun x => p x)
| ⟨x, hx⟩ => ⟨x, hx⟩
protected theorem PSigma.eta {α : Sort u} {β : α → Sort v} {a₁ a₂ : α} {b₁ : β a₁} {b₂ : β a₂}
(h₁ : a₁ = a₂) (h₂ : Eq.ndrec b₁ h₁ = b₂) : PSigma.mk a₁ b₁ = PSigma.mk a₂ b₂ := by
subst h₁
subst h₂
exact rfl
/- Universe polymorphic unit -/
theorem PUnit.subsingleton (a b : PUnit) : a = b := by
cases a; cases b; exact rfl
@[simp] theorem PUnit.eq_punit (a : PUnit) : a = ⟨⟩ :=
PUnit.subsingleton a ⟨⟩
instance : Subsingleton PUnit :=
Subsingleton.intro PUnit.subsingleton
instance : Inhabited PUnit where
default := ⟨⟩
instance : DecidableEq PUnit :=
fun a b => isTrue (PUnit.subsingleton a b)
/- Setoid -/
class Setoid (α : Sort u) where
r : α → α → Prop
iseqv {} : Equivalence r
instance {α : Sort u} [Setoid α] : HasEquiv α :=
⟨Setoid.r⟩
namespace Setoid
variable {α : Sort u} [Setoid α]
theorem refl (a : α) : a ≈ a :=
(Setoid.iseqv α).refl a
theorem symm {a b : α} (hab : a ≈ b) : b ≈ a :=
(Setoid.iseqv α).symm hab
theorem trans {a b c : α} (hab : a ≈ b) (hbc : b ≈ c) : a ≈ c :=
(Setoid.iseqv α).trans hab hbc
end Setoid
/- Propositional extensionality -/
axiom propext {a b : Prop} : (a ↔ b) → a = b
theorem Eq.propIntro {a b : Prop} (h₁ : a → b) (h₂ : b → a) : a = b :=
propext <| Iff.intro h₁ h₂
gen_injective_theorems% Prod
gen_injective_theorems% PProd
gen_injective_theorems% MProd
gen_injective_theorems% Subtype
gen_injective_theorems% Fin
gen_injective_theorems% Array
gen_injective_theorems% Sum
gen_injective_theorems% PSum
gen_injective_theorems% Nat
gen_injective_theorems% Option
gen_injective_theorems% List
gen_injective_theorems% Except
gen_injective_theorems% EStateM.Result
gen_injective_theorems% Lean.Name
gen_injective_theorems% Lean.Syntax
/- Quotients -/
-- Iff can now be used to do substitutions in a calculation
theorem iffSubst {a b : Prop} {p : Prop → Prop} (h₁ : a ↔ b) (h₂ : p a) : p b :=
Eq.subst (propext h₁) h₂
namespace Quot
axiom sound : ∀ {α : Sort u} {r : α → α → Prop} {a b : α}, r a b → Quot.mk r a = Quot.mk r b
protected theorem liftBeta {α : Sort u} {r : α → α → Prop} {β : Sort v}
(f : α → β)
(c : (a b : α) → r a b → f a = f b)
(a : α)
: lift f c (Quot.mk r a) = f a :=
rfl
protected theorem indBeta {α : Sort u} {r : α → α → Prop} {motive : Quot r → Prop}
(p : (a : α) → motive (Quot.mk r a))
(a : α)
: (ind p (Quot.mk r a) : motive (Quot.mk r a)) = p a :=
rfl
protected abbrev liftOn {α : Sort u} {β : Sort v} {r : α → α → Prop} (q : Quot r) (f : α → β) (c : (a b : α) → r a b → f a = f b) : β :=
lift f c q
protected theorem inductionOn {α : Sort u} {r : α → α → Prop} {motive : Quot r → Prop}
(q : Quot r)
(h : (a : α) → motive (Quot.mk r a))
: motive q :=
ind h q
theorem existsRep {α : Sort u} {r : α → α → Prop} (q : Quot r) : Exists (fun a => (Quot.mk r a) = q) :=
Quot.inductionOn (motive := fun q => Exists (fun a => (Quot.mk r a) = q)) q (fun a => ⟨a, rfl⟩)
section
variable {α : Sort u}
variable {r : α → α → Prop}
variable {motive : Quot r → Sort v}
@[reducible, macroInline]
protected def indep (f : (a : α) → motive (Quot.mk r a)) (a : α) : PSigma motive :=
⟨Quot.mk r a, f a⟩
protected theorem indepCoherent
(f : (a : α) → motive (Quot.mk r a))
(h : (a b : α) → (p : r a b) → Eq.ndrec (f a) (sound p) = f b)
: (a b : α) → r a b → Quot.indep f a = Quot.indep f b :=
fun a b e => PSigma.eta (sound e) (h a b e)
protected theorem liftIndepPr1
(f : (a : α) → motive (Quot.mk r a))
(h : ∀ (a b : α) (p : r a b), Eq.ndrec (f a) (sound p) = f b)
(q : Quot r)
: (lift (Quot.indep f) (Quot.indepCoherent f h) q).1 = q := by
induction q using Quot.ind
exact rfl
protected abbrev rec
(f : (a : α) → motive (Quot.mk r a))
(h : (a b : α) → (p : r a b) → Eq.ndrec (f a) (sound p) = f b)
(q : Quot r) : motive q :=
Eq.ndrecOn (Quot.liftIndepPr1 f h q) ((lift (Quot.indep f) (Quot.indepCoherent f h) q).2)
protected abbrev recOn
(q : Quot r)
(f : (a : α) → motive (Quot.mk r a))
(h : (a b : α) → (p : r a b) → Eq.ndrec (f a) (sound p) = f b)
: motive q :=
Quot.rec f h q
protected abbrev recOnSubsingleton
[h : (a : α) → Subsingleton (motive (Quot.mk r a))]
(q : Quot r)
(f : (a : α) → motive (Quot.mk r a))
: motive q := by
induction q using Quot.rec
apply f
apply Subsingleton.elim
protected abbrev hrecOn
(q : Quot r)
(f : (a : α) → motive (Quot.mk r a))
(c : (a b : α) → (p : r a b) → f a ≅ f b)
: motive q :=
Quot.recOn q f fun a b p => eqOfHEq <|
have p₁ : Eq.ndrec (f a) (sound p) ≅ f a := eqRecHEq (sound p) (f a)
HEq.trans p₁ (c a b p)
end
end Quot
def Quotient {α : Sort u} (s : Setoid α) :=
@Quot α Setoid.r
namespace Quotient
@[inline]
protected def mk {α : Sort u} [s : Setoid α] (a : α) : Quotient s :=
Quot.mk Setoid.r a
def sound {α : Sort u} [s : Setoid α] {a b : α} : a ≈ b → Quotient.mk a = Quotient.mk b :=
Quot.sound
protected abbrev lift {α : Sort u} {β : Sort v} [s : Setoid α] (f : α → β) : ((a b : α) → a ≈ b → f a = f b) → Quotient s → β :=
Quot.lift f
protected theorem ind {α : Sort u} [s : Setoid α] {motive : Quotient s → Prop} : ((a : α) → motive (Quotient.mk a)) → (q : Quot Setoid.r) → motive q :=
Quot.ind
protected abbrev liftOn {α : Sort u} {β : Sort v} [s : Setoid α] (q : Quotient s) (f : α → β) (c : (a b : α) → a ≈ b → f a = f b) : β :=
Quot.liftOn q f c
protected theorem inductionOn {α : Sort u} [s : Setoid α] {motive : Quotient s → Prop}
(q : Quotient s)
(h : (a : α) → motive (Quotient.mk a))
: motive q :=
Quot.inductionOn q h
theorem existsRep {α : Sort u} [s : Setoid α] (q : Quotient s) : Exists (fun (a : α) => Quotient.mk a = q) :=
Quot.existsRep q
section
variable {α : Sort u}
variable [s : Setoid α]
variable {motive : Quotient s → Sort v}
@[inline]
protected def rec
(f : (a : α) → motive (Quotient.mk a))
(h : (a b : α) → (p : a ≈ b) → Eq.ndrec (f a) (Quotient.sound p) = f b)
(q : Quotient s)
: motive q :=
Quot.rec f h q
protected abbrev recOn
(q : Quotient s)
(f : (a : α) → motive (Quotient.mk a))
(h : (a b : α) → (p : a ≈ b) → Eq.ndrec (f a) (Quotient.sound p) = f b)
: motive q :=
Quot.recOn q f h
protected abbrev recOnSubsingleton
[h : (a : α) → Subsingleton (motive (Quotient.mk a))]
(q : Quotient s)
(f : (a : α) → motive (Quotient.mk a))
: motive q :=
Quot.recOnSubsingleton (h := h) q f
protected abbrev hrecOn
(q : Quotient s)
(f : (a : α) → motive (Quotient.mk a))
(c : (a b : α) → (p : a ≈ b) → f a ≅ f b)
: motive q :=
Quot.hrecOn q f c
end
section
universes uA uB uC
variable {α : Sort uA} {β : Sort uB} {φ : Sort uC}
variable [s₁ : Setoid α] [s₂ : Setoid β]
protected abbrev lift₂
(f : α → β → φ)
(c : (a₁ : α) → (b₁ : β) → (a₂ : α) → (b₂ : β) → a₁ ≈ a₂ → b₁ ≈ b₂ → f a₁ b₁ = f a₂ b₂)
(q₁ : Quotient s₁) (q₂ : Quotient s₂)
: φ := by
apply Quotient.lift (fun (a₁ : α) => Quotient.lift (f a₁) (fun (a b : β) => c a₁ a a₁ b (Setoid.refl a₁)) q₂) _ q₁
intros
induction q₂ using Quotient.ind
apply c; assumption; apply Setoid.refl
protected abbrev liftOn₂
(q₁ : Quotient s₁)
(q₂ : Quotient s₂)
(f : α → β → φ)
(c : (a₁ : α) → (b₁ : β) → (a₂ : α) → (b₂ : β) → a₁ ≈ a₂ → b₁ ≈ b₂ → f a₁ b₁ = f a₂ b₂)
: φ :=
Quotient.lift₂ f c q₁ q₂
protected theorem ind₂
{motive : Quotient s₁ → Quotient s₂ → Prop}
(h : (a : α) → (b : β) → motive (Quotient.mk a) (Quotient.mk b))
(q₁ : Quotient s₁)
(q₂ : Quotient s₂)
: motive q₁ q₂ := by
induction q₁ using Quotient.ind
induction q₂ using Quotient.ind
apply h
protected theorem inductionOn₂
{motive : Quotient s₁ → Quotient s₂ → Prop}
(q₁ : Quotient s₁)
(q₂ : Quotient s₂)
(h : (a : α) → (b : β) → motive (Quotient.mk a) (Quotient.mk b))
: motive q₁ q₂ := by
induction q₁ using Quotient.ind
induction q₂ using Quotient.ind
apply h
protected theorem inductionOn₃
[s₃ : Setoid φ]
{motive : Quotient s₁ → Quotient s₂ → Quotient s₃ → Prop}
(q₁ : Quotient s₁)
(q₂ : Quotient s₂)
(q₃ : Quotient s₃)
(h : (a : α) → (b : β) → (c : φ) → motive (Quotient.mk a) (Quotient.mk b) (Quotient.mk c))
: motive q₁ q₂ q₃ := by
induction q₁ using Quotient.ind
induction q₂ using Quotient.ind
induction q₃ using Quotient.ind
apply h
end
section Exact
variable {α : Sort u}
private def rel [s : Setoid α] (q₁ q₂ : Quotient s) : Prop :=
Quotient.liftOn₂ q₁ q₂
(fun a₁ a₂ => a₁ ≈ a₂)
(fun a₁ a₂ b₁ b₂ a₁b₁ a₂b₂ =>
propext (Iff.intro
(fun a₁a₂ => Setoid.trans (Setoid.symm a₁b₁) (Setoid.trans a₁a₂ a₂b₂))
(fun b₁b₂ => Setoid.trans a₁b₁ (Setoid.trans b₁b₂ (Setoid.symm a₂b₂)))))
private theorem rel.refl [s : Setoid α] (q : Quotient s) : rel q q :=
Quot.inductionOn (motive := fun q => rel q q) q (fun a => Setoid.refl a)
private theorem eqImpRel [s : Setoid α] {q₁ q₂ : Quotient s} : q₁ = q₂ → rel q₁ q₂ :=
fun h => Eq.ndrecOn h (rel.refl q₁)
theorem exact [s : Setoid α] {a b : α} : Quotient.mk a = Quotient.mk b → a ≈ b :=
fun h => eqImpRel h
end Exact
section
universes uA uB uC
variable {α : Sort uA} {β : Sort uB}
variable [s₁ : Setoid α] [s₂ : Setoid β]
protected abbrev recOnSubsingleton₂
{motive : Quotient s₁ → Quotient s₂ → Sort uC}
[s : (a : α) → (b : β) → Subsingleton (motive (Quotient.mk a) (Quotient.mk b))]
(q₁ : Quotient s₁)
(q₂ : Quotient s₂)
(g : (a : α) → (b : β) → motive (Quotient.mk a) (Quotient.mk b))
: motive q₁ q₂ := by
induction q₁ using Quot.recOnSubsingleton
induction q₂ using Quot.recOnSubsingleton
apply g
intro a; apply s
induction q₂ using Quot.recOnSubsingleton
intro a; apply s
inferInstance
end
end Quotient
section
variable {α : Type u}
variable (r : α → α → Prop)
instance {α : Sort u} {s : Setoid α} [d : ∀ (a b : α), Decidable (a ≈ b)] : DecidableEq (Quotient s) :=
fun (q₁ q₂ : Quotient s) =>
Quotient.recOnSubsingleton₂ (motive := fun a b => Decidable (a = b)) q₁ q₂
fun a₁ a₂ =>
match d a₁ a₂ with
| isTrue h₁ => isTrue (Quotient.sound h₁)
| isFalse h₂ => isFalse fun h => absurd (Quotient.exact h) h₂
/- Function extensionality -/
namespace Function
variable {α : Sort u} {β : α → Sort v}
def Equiv (f₁ f₂ : ∀ (x : α), β x) : Prop := ∀ x, f₁ x = f₂ x
protected theorem Equiv.refl (f : ∀ (x : α), β x) : Equiv f f :=
fun x => rfl
protected theorem Equiv.symm {f₁ f₂ : ∀ (x : α), β x} : Equiv f₁ f₂ → Equiv f₂ f₁ :=
fun h x => Eq.symm (h x)
protected theorem Equiv.trans {f₁ f₂ f₃ : ∀ (x : α), β x} : Equiv f₁ f₂ → Equiv f₂ f₃ → Equiv f₁ f₃ :=
fun h₁ h₂ x => Eq.trans (h₁ x) (h₂ x)
protected theorem Equiv.isEquivalence (α : Sort u) (β : α → Sort v) : Equivalence (@Function.Equiv α β) := {
refl := Equiv.refl
symm := Equiv.symm
trans := Equiv.trans
}
end Function
section
open Quotient
variable {α : Sort u} {β : α → Sort v}
@[instance]
private def funSetoid (α : Sort u) (β : α → Sort v) : Setoid (∀ (x : α), β x) :=
Setoid.mk (@Function.Equiv α β) (Function.Equiv.isEquivalence α β)
private def extfunApp (f : Quotient <| funSetoid α β) (x : α) : β x :=
Quot.liftOn f
(fun (f : ∀ (x : α), β x) => f x)
(fun f₁ f₂ h => h x)
theorem funext {f₁ f₂ : ∀ (x : α), β x} (h : ∀ x, f₁ x = f₂ x) : f₁ = f₂ := by
show extfunApp (Quotient.mk f₁) = extfunApp (Quotient.mk f₂)
apply congrArg
apply Quotient.sound
exact h
end
instance {α : Sort u} {β : α → Sort v} [∀ a, Subsingleton (β a)] : Subsingleton (∀ a, β a) where
allEq f₁ f₂ :=
funext (fun a => Subsingleton.elim (f₁ a) (f₂ a))
/- Squash -/
def Squash (α : Type u) := Quot (fun (a b : α) => True)
def Squash.mk {α : Type u} (x : α) : Squash α := Quot.mk _ x
theorem Squash.ind {α : Type u} {motive : Squash α → Prop} (h : ∀ (a : α), motive (Squash.mk a)) : ∀ (q : Squash α), motive q :=
Quot.ind h
@[inline] def Squash.lift {α β} [Subsingleton β] (s : Squash α) (f : α → β) : β :=
Quot.lift f (fun a b _ => Subsingleton.elim _ _) s
instance : Subsingleton (Squash α) where
allEq a b := by
induction a using Squash.ind
induction b using Squash.ind
apply Quot.sound
trivial
namespace Lean
/- Kernel reduction hints -/
/--
When the kernel tries to reduce a term `Lean.reduceBool c`, it will invoke the Lean interpreter to evaluate `c`.
The kernel will not use the interpreter if `c` is not a constant.
This feature is useful for performing proofs by reflection.
Remark: the Lean frontend allows terms of the from `Lean.reduceBool t` where `t` is a term not containing
free variables. The frontend automatically declares a fresh auxiliary constant `c` and replaces the term with
`Lean.reduceBool c`. The main motivation is that the code for `t` will be pre-compiled.
Warning: by using this feature, the Lean compiler and interpreter become part of your trusted code base.
This is extra 30k lines of code. More importantly, you will probably not be able to check your developement using
external type checkers (e.g., Trepplein) that do not implement this feature.
Keep in mind that if you are using Lean as programming language, you are already trusting the Lean compiler and interpreter.
So, you are mainly losing the capability of type checking your developement using external checkers.
Recall that the compiler trusts the correctness of all `[implementedBy ...]` and `[extern ...]` annotations.
If an extern function is executed, then the trusted code base will also include the implementation of the associated
foreign function.
-/
constant reduceBool (b : Bool) : Bool := b
/--
Similar to `Lean.reduceBool` for closed `Nat` terms.
Remark: we do not have plans for supporting a generic `reduceValue {α} (a : α) : α := a`.
The main issue is that it is non-trivial to convert an arbitrary runtime object back into a Lean expression.
We believe `Lean.reduceBool` enables most interesting applications (e.g., proof by reflection). -/
constant reduceNat (n : Nat) : Nat := n
axiom ofReduceBool (a b : Bool) (h : reduceBool a = b) : a = b
axiom ofReduceNat (a b : Nat) (h : reduceNat a = b) : a = b
end Lean
|
93425f0e57d52060192174097d5d085f8f880788 | 246309748072bf9f8da313401699689ebbecd94d | /src/linear_algebra/affine_space/finite_dimensional.lean | 28de424121529caf6e96b3c575ff81e0d4bf5b67 | [
"Apache-2.0"
] | permissive | YJMD/mathlib | b703a641e5f32a996f7842f7c0043bab2b462ee2 | 7310eab9fa8c1b1229dca42682f1fa6bfb7dbbf9 | refs/heads/master | 1,670,714,479,314 | 1,599,035,445,000 | 1,599,035,445,000 | 292,279,930 | 0 | 0 | null | 1,599,050,561,000 | 1,599,050,560,000 | null | UTF-8 | Lean | false | false | 4,321 | lean | /-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Joseph Myers.
-/
import linear_algebra.affine_space.independent
import linear_algebra.finite_dimensional
noncomputable theory
open_locale big_operators
open_locale classical
/-!
# Finite-dimensional subspaces of affine spaces.
This file provides a few results relating to finite-dimensional
subspaces of affine spaces.
-/
section affine_space'
variables (k : Type*) {V : Type*} {P : Type*} [field k] [add_comm_group V] [module k V]
[affine_space V P]
variables {ι : Type*}
include V
open finite_dimensional
/-- The `vector_span` of a finite set is finite-dimensional. -/
lemma finite_dimensional_vector_span_of_finite {s : set P} (h : set.finite s) :
finite_dimensional k (vector_span k s) :=
span_of_finite k $ vsub_set_finite_of_finite h
/-- The direction of the affine span of a finite set is
finite-dimensional. -/
lemma finite_dimensional_direction_affine_span_of_finite {s : set P} (h : set.finite s) :
finite_dimensional k (affine_span k s).direction :=
(direction_affine_span k s).symm ▸ finite_dimensional_vector_span_of_finite k h
/-- The direction of the affine span of a family indexed by a
`fintype` is finite-dimensional. -/
instance finite_dimensional_direction_affine_span_of_fintype [fintype ι] (p : ι → P) :
finite_dimensional k (affine_span k (set.range p)).direction :=
finite_dimensional_direction_affine_span_of_finite k (set.finite_range _)
variables {k}
/-- The `vector_span` of a finite affinely independent family has
dimension one less than its cardinality. -/
lemma findim_vector_span_of_affine_independent [fintype ι] {p : ι → P}
(hi : affine_independent k p) {n : ℕ} (hc : fintype.card ι = n + 1) :
findim k (vector_span k (set.range p)) = n :=
begin
have hi' := affine_independent_set_of_affine_independent hi,
have hc' : fintype.card (set.range p) = n + 1,
by rwa set.card_range_of_injective (injective_of_affine_independent hi),
have hn : (set.range p).nonempty,
{ refine set.range_nonempty_iff_nonempty.2 (fintype.card_pos_iff.1 _),
simp [hc] },
rcases hn with ⟨p₁, hp₁⟩,
rw affine_independent_set_iff_linear_independent_vsub k hp₁ at hi',
have hfr : (set.range p \ {p₁}).finite := (set.finite_range _).subset (set.diff_subset _ _),
haveI := hfr.fintype,
have hf : set.finite ((λ (p : P), p -ᵥ p₁) '' (set.range p \ {p₁})) := hfr.image _,
haveI := hf.fintype,
have hc : hf.to_finset.card = n,
{ rw [hf.card_to_finset,
set.card_image_of_injective (set.range p \ {p₁}) (vsub_left_injective _)],
have hd : insert p₁ (set.range p \ {p₁}) = set.range p,
{ rw [set.insert_diff_singleton, set.insert_eq_of_mem hp₁] },
have hc'' : fintype.card ↥(insert p₁ (set.range p \ {p₁})) = n + 1,
{ convert hc' },
rw set.card_insert (set.range p \ {p₁}) (λ h, ((set.mem_diff p₁).2 h).2 rfl) at hc'',
simpa using hc'' },
rw [vector_span_eq_span_vsub_set_right_ne k hp₁, findim_span_set_eq_card _ hi', ←hc],
congr
end
/-- The `vector_span` of a finite affinely independent family whose
cardinality is one more than that of the finite-dimensional space is
`⊤`. -/
lemma vector_span_eq_top_of_affine_independent_of_card_eq_findim_add_one [finite_dimensional k V]
[fintype ι] {p : ι → P} (hi : affine_independent k p) (hc : fintype.card ι = findim k V + 1) :
vector_span k (set.range p) = ⊤ :=
eq_top_of_findim_eq $ findim_vector_span_of_affine_independent hi hc
/-- The `affine_span` of a finite affinely independent family whose
cardinality is one more than that of the finite-dimensional space is
`⊤`. -/
lemma affine_span_eq_top_of_affine_independent_of_card_eq_findim_add_one [finite_dimensional k V]
[fintype ι] {p : ι → P} (hi : affine_independent k p) (hc : fintype.card ι = findim k V + 1) :
affine_span k (set.range p) = ⊤ :=
begin
have hn : (set.range p).nonempty,
{ refine set.range_nonempty_iff_nonempty.2 (fintype.card_pos_iff.1 _),
simp [hc] },
rw [←affine_subspace.direction_eq_top_iff_of_nonempty ((affine_span_nonempty k _).2 hn),
direction_affine_span],
exact vector_span_eq_top_of_affine_independent_of_card_eq_findim_add_one hi hc
end
end affine_space'
|
5582dec3c3994b5dec52951818f36b05d9d303d2 | 9dd3f3912f7321eb58ee9aa8f21778ad6221f87c | /tests/lean/run/opt_param_cc.lean | 1d1596b92ba161b67308d52be7f06cea10ce9266 | [
"Apache-2.0"
] | permissive | bre7k30/lean | de893411bcfa7b3c5572e61b9e1c52951b310aa4 | 5a924699d076dab1bd5af23a8f910b433e598d7a | refs/heads/master | 1,610,900,145,817 | 1,488,006,845,000 | 1,488,006,845,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 733 | lean | def f (a : nat) (b : nat := a) (c : nat := a) :=
a + b + c
lemma ex1 (a a' b c d : nat) (h : b = c) (h2 : a = a') : f a b d = f a' c d :=
by cc
lemma ex2 (a a' b c d : nat) (h : b = c) (h2 : a = a') : f a b d = f a' c d :=
by rw [h, h2]
set_option pp.beta true
set_option pp.all true
lemma ex3 (a a' b c d : nat) (h : b = c) (h2 : a = a') : f a b d = f a' c d :=
begin
simp [h, h2],
end
open tactic
run_command do c ← mk_const `f, get_fun_info c >>= trace
run_command do c ← mk_const `eq, get_fun_info c >>= trace
run_command do c ← mk_const `id, get_fun_info c >>= trace
set_option trace.congr_lemma true
set_option trace.app_builder true
run_command do h ← mk_const `f, l ← mk_congr_lemma_simp h, trace l^.type
|
deebf6891efe4f308f5a34c6a5d6856eee0d1e3f | 618003631150032a5676f229d13a079ac875ff77 | /src/linear_algebra/basis.lean | ee2099716466801292c0ba9b19744b317d8e2640 | [
"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 | 53,189 | 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, Alexander Bentkamp
-/
import linear_algebra.finsupp
import linear_algebra.projection
import order.zorn
import data.fintype.card
/-!
# Linear independence and bases
This file defines linear independence and bases in a module or vector space.
It is inspired by Isabelle/HOL's linear algebra, and hence indirectly by HOL Light.
## Main definitions
All definitions are given for families of vectors, i.e. `v : ι → M` where `M` is the module or
vector space and `ι : Type*` is an arbitrary indexing type.
* `linear_independent R v` states that the elements of the family `v` are linearly independent.
* `linear_independent.repr hv x` returns the linear combination representing `x : span R (range v)`
on the linearly independent vectors `v`, given `hv : linear_independent R v`
(using classical choice). `linear_independent.repr hv` is provided as a linear map.
* `is_basis R v` states that the vector family `v` is a basis, i.e. it is linearly independent and
spans the entire space.
* `is_basis.repr hv x` is the basis version of `linear_independent.repr hv x`. It returns the
linear combination representing `x : M` on a basis `v` of `M` (using classical choice).
The argument `hv` must be a proof that `is_basis R v`. `is_basis.repr hv` is given as a linear
map as well.
* `is_basis.constr hv f` constructs a linear map `M₁ →ₗ[R] M₂` given the values `f : ι → M₂` at the
basis `v : ι → M₁`, given `hv : is_basis R v`.
## Main statements
* `is_basis.ext` states that two linear maps are equal if they coincide on a basis.
* `exists_is_basis` states that every vector space has a basis.
## Implementation notes
We use families instead of sets because it allows us to say that two identical vectors are linearly
dependent. For bases, this is useful as well because we can easily derive ordered bases by using an
ordered index type `ι`.
If you want to use sets, use the family `(λ x, x : s → M)` given a set `s : set M`. The lemmas
`linear_independent.to_subtype_range` and `linear_independent.of_subtype_range` connect those two
worlds.
## Tags
linearly dependent, linear dependence, linearly independent, linear independence, basis
-/
noncomputable theory
open function set submodule
open_locale classical
variables {ι : Type*} {ι' : Type*} {R : Type*} {K : Type*}
{M : Type*} {M' : Type*} {V : Type*} {V' : Type*}
section module
variables {v : ι → M}
variables [ring R] [add_comm_group M] [add_comm_group M']
variables [module R M] [module R M']
variables {a b : R} {x y : M}
variables (R) (v)
/-- Linearly independent family of vectors -/
def linear_independent : Prop := (finsupp.total ι M R v).ker = ⊥
variables {R} {v}
theorem linear_independent_iff : linear_independent R v ↔
∀l, finsupp.total ι M R v l = 0 → l = 0 :=
by simp [linear_independent, linear_map.ker_eq_bot']
theorem linear_independent_iff' : linear_independent R v ↔
∀ s : finset ι, ∀ g : ι → R, s.sum (λ i, g i • v i) = 0 → ∀ i ∈ s, g i = 0 :=
linear_independent_iff.trans
⟨λ hf s g hg i his, have h : _ := hf (s.sum $ λ i, finsupp.single i (g i)) $
by simpa only [linear_map.map_sum, finsupp.total_single] using hg, calc
g i = (finsupp.lapply i : (ι →₀ R) →ₗ[R] R) (finsupp.single i (g i)) :
by rw [finsupp.lapply_apply, finsupp.single_eq_same]
... = s.sum (λ j, (finsupp.lapply i : (ι →₀ R) →ₗ[R] R) (finsupp.single j (g j))) :
eq.symm $ finset.sum_eq_single i
(λ j hjs hji, by rw [finsupp.lapply_apply, finsupp.single_eq_of_ne hji])
(λ hnis, hnis.elim his)
... = s.sum (λ j, finsupp.single j (g j)) i : (finsupp.lapply i : (ι →₀ R) →ₗ[R] R).map_sum.symm
... = 0 : finsupp.ext_iff.1 h i,
λ hf l hl, finsupp.ext $ λ i, classical.by_contradiction $ λ hni, hni $ hf _ _ hl _ $
finsupp.mem_support_iff.2 hni⟩
lemma linear_independent_empty_type (h : ¬ nonempty ι) : linear_independent R v :=
begin
rw [linear_independent_iff],
intros,
ext i,
exact false.elim (not_nonempty_iff_imp_false.1 h i)
end
lemma linear_independent.ne_zero
{i : ι} (ne : 0 ≠ (1:R)) (hv : linear_independent R v) : v i ≠ 0 :=
λ h, ne $ eq.symm begin
suffices : (finsupp.single i 1 : ι →₀ R) i = 0, {simpa},
rw linear_independent_iff.1 hv (finsupp.single i 1),
{simp},
{simp [h]}
end
lemma linear_independent.comp
(h : linear_independent R v) (f : ι' → ι) (hf : injective f) : linear_independent R (v ∘ f) :=
begin
rw [linear_independent_iff, finsupp.total_comp],
intros l hl,
have h_map_domain : ∀ x, (finsupp.map_domain f l) (f x) = 0,
by rw linear_independent_iff.1 h (finsupp.map_domain f l) hl; simp,
ext,
convert h_map_domain a,
simp only [finsupp.map_domain_apply hf],
end
lemma linear_independent_of_zero_eq_one (zero_eq_one : (0 : R) = 1) : linear_independent R v :=
linear_independent_iff.2 (λ l hl, finsupp.eq_zero_of_zero_eq_one zero_eq_one _)
lemma linear_independent.unique (hv : linear_independent R v) {l₁ l₂ : ι →₀ R} :
finsupp.total ι M R v l₁ = finsupp.total ι M R v l₂ → l₁ = l₂ :=
by apply linear_map.ker_eq_bot.1 hv
lemma linear_independent.injective (zero_ne_one : (0 : R) ≠ 1) (hv : linear_independent R v) :
injective v :=
begin
intros i j hij,
let l : ι →₀ R := finsupp.single i (1 : R) - finsupp.single j 1,
have h_total : finsupp.total ι M R v l = 0,
{ rw finsupp.total_apply,
rw finsupp.sum_sub_index,
{ simp [finsupp.sum_single_index, hij] },
{ intros, apply sub_smul } },
have h_single_eq : finsupp.single i (1 : R) = finsupp.single j 1,
{ rw linear_independent_iff at hv,
simp [eq_add_of_sub_eq' (hv l h_total)] },
show i = j,
{ apply or.elim ((finsupp.single_eq_single_iff _ _ _ _).1 h_single_eq),
simp,
exact λ h, false.elim (zero_ne_one.symm h.1) }
end
lemma linear_independent_span (hs : linear_independent R v) :
@linear_independent ι R (span R (range v))
(λ i : ι, ⟨v i, subset_span (mem_range_self i)⟩) _ _ _ :=
begin
rw linear_independent_iff at *,
intros l hl,
apply hs l,
have := congr_arg (submodule.subtype (span R (range v))) hl,
convert this,
rw [finsupp.total_apply, finsupp.total_apply],
unfold finsupp.sum,
rw linear_map.map_sum (submodule.subtype (span R (range v))),
simp
end
section subtype
/-! The following lemmas use the subtype defined by a set in `M` as the index set `ι`. -/
theorem linear_independent_comp_subtype {s : set ι} :
linear_independent R (v ∘ subtype.val : s → M) ↔
∀ l ∈ (finsupp.supported R R s), (finsupp.total ι M R v) l = 0 → l = 0 :=
begin
rw [linear_independent_iff, finsupp.total_comp],
simp only [linear_map.comp_apply],
split,
{ intros h l hl₁ hl₂,
have h_bij : bij_on subtype.val (subtype.val ⁻¹' ↑l.support : set s) ↑l.support,
{ apply bij_on.mk,
{ unfold maps_to },
{ apply subtype.val_injective.inj_on },
intros i hi,
rw [image_preimage_eq_inter_range, subtype.range_val],
exact ⟨hi, (finsupp.mem_supported _ _).1 hl₁ hi⟩ },
show l = 0,
{ apply finsupp.eq_zero_of_comap_domain_eq_zero (subtype.val : s → ι) _ h_bij,
apply h,
convert hl₂,
rw [finsupp.lmap_domain_apply, finsupp.map_domain_comap_domain],
exact subtype.val_injective,
rw subtype.range_val,
exact (finsupp.mem_supported _ _).1 hl₁ } },
{ intros h l hl,
have hl' : finsupp.total ι M R v (finsupp.emb_domain ⟨subtype.val, subtype.val_injective⟩ l) = 0,
{ rw finsupp.emb_domain_eq_map_domain ⟨subtype.val, subtype.val_injective⟩ l,
apply hl },
apply finsupp.emb_domain_inj.1,
rw [h (finsupp.emb_domain ⟨subtype.val, subtype.val_injective⟩ l) _ hl',
finsupp.emb_domain_zero],
rw [finsupp.mem_supported, finsupp.support_emb_domain],
intros x hx,
rw [finset.mem_coe, finset.mem_map] at hx,
rcases hx with ⟨i, x', hx'⟩,
rw ←hx',
simp }
end
theorem linear_independent_subtype {s : set M} :
linear_independent R (λ x, x : s → M) ↔
∀ l ∈ (finsupp.supported R R s), (finsupp.total M M R id) l = 0 → l = 0 :=
by apply @linear_independent_comp_subtype _ _ _ id
theorem linear_independent_comp_subtype_disjoint {s : set ι} :
linear_independent R (v ∘ subtype.val : s → M) ↔
disjoint (finsupp.supported R R s) (finsupp.total ι M R v).ker :=
by rw [linear_independent_comp_subtype, linear_map.disjoint_ker]
theorem linear_independent_subtype_disjoint {s : set M} :
linear_independent R (λ x, x : s → M) ↔
disjoint (finsupp.supported R R s) (finsupp.total M M R id).ker :=
by apply @linear_independent_comp_subtype_disjoint _ _ _ id
theorem linear_independent_iff_total_on {s : set M} :
linear_independent R (λ x, x : s → M) ↔ (finsupp.total_on M M R id s).ker = ⊥ :=
by rw [finsupp.total_on, linear_map.ker, linear_map.comap_cod_restrict, map_bot, comap_bot,
linear_map.ker_comp, linear_independent_subtype_disjoint, disjoint, ← map_comap_subtype,
map_le_iff_le_comap, comap_bot, ker_subtype, le_bot_iff]
lemma linear_independent.to_subtype_range
(hv : linear_independent R v) : linear_independent R (λ x, x : range v → M) :=
begin
by_cases zero_eq_one : (0 : R) = 1,
{ apply linear_independent_of_zero_eq_one zero_eq_one },
rw linear_independent_subtype,
intros l hl₁ hl₂,
have h_bij : bij_on v (v ⁻¹' ↑l.support) ↑l.support,
{ apply bij_on.mk,
{ unfold maps_to },
{ apply (linear_independent.injective zero_eq_one hv).inj_on },
intros x hx,
rcases mem_range.1 (((finsupp.mem_supported _ _).1 hl₁ : ↑(l.support) ⊆ range v) hx)
with ⟨i, hi⟩,
rw mem_image,
use i,
rw [mem_preimage, hi],
exact ⟨hx, rfl⟩ },
apply finsupp.eq_zero_of_comap_domain_eq_zero v l,
apply linear_independent_iff.1 hv,
rw [finsupp.total_comap_domain, finset.sum_preimage v l.support h_bij (λ (x : M), l x • x)],
rw [finsupp.total_apply, finsupp.sum] at hl₂,
apply hl₂
end
lemma linear_independent.of_subtype_range (hv : injective v)
(h : linear_independent R (λ x, x : range v → M)) : linear_independent R v :=
begin
rw linear_independent_iff,
intros l hl,
apply finsupp.injective_map_domain hv,
apply linear_independent_subtype.1 h (l.map_domain v),
{ rw finsupp.mem_supported,
intros x hx,
have := finset.mem_coe.2 (finsupp.map_domain_support hx),
rw finset.coe_image at this,
apply set.image_subset_range _ _ this, },
{ rwa [finsupp.total_map_domain _ _ hv, left_id] }
end
lemma linear_independent.restrict_of_comp_subtype {s : set ι}
(hs : linear_independent R (v ∘ subtype.val : s → M)) :
linear_independent R (s.restrict v) :=
begin
have h_restrict : restrict v s = v ∘ (λ x, x.val) := rfl,
rw [linear_independent_iff, h_restrict, finsupp.total_comp],
intros l hl,
have h_map_domain_subtype_eq_0 : l.map_domain subtype.val = 0,
{ rw linear_independent_comp_subtype at hs,
apply hs (finsupp.lmap_domain R R (λ x : subtype s, x.val) l) _ hl,
rw finsupp.mem_supported,
simp,
intros x hx,
have := finset.mem_coe.2 (finsupp.map_domain_support (finset.mem_coe.1 hx)),
rw finset.coe_image at this,
exact subtype.val_image_subset _ _ this },
apply @finsupp.injective_map_domain _ (subtype s) ι,
{ apply subtype.val_injective },
{ simpa },
end
variables (R M)
lemma linear_independent_empty : linear_independent R (λ x, x : (∅ : set M) → M) :=
by simp [linear_independent_subtype_disjoint]
variables {R M}
lemma linear_independent.mono {t s : set M} (h : t ⊆ s) :
linear_independent R (λ x, x : s → M) → linear_independent R (λ x, x : t → M) :=
begin
simp only [linear_independent_subtype_disjoint],
exact (disjoint.mono_left (finsupp.supported_mono h))
end
lemma linear_independent.union {s t : set M}
(hs : linear_independent R (λ x, x : s → M)) (ht : linear_independent R (λ x, x : t → M))
(hst : disjoint (span R s) (span R t)) :
linear_independent R (λ x, x : (s ∪ t) → M) :=
begin
rw [linear_independent_subtype_disjoint, disjoint_def, finsupp.supported_union],
intros l h₁ h₂, rw mem_sup at h₁,
rcases h₁ with ⟨ls, hls, lt, hlt, rfl⟩,
have h_ls_mem_t : finsupp.total M M R id ls ∈ span R t,
{ rw [← image_id t, finsupp.span_eq_map_total],
apply (add_mem_iff_left (map _ _) (mem_image_of_mem _ hlt)).1,
rw [← linear_map.map_add, linear_map.mem_ker.1 h₂],
apply zero_mem },
have h_lt_mem_s : finsupp.total M M R id lt ∈ span R s,
{ rw [← image_id s, finsupp.span_eq_map_total],
apply (add_mem_iff_left (map _ _) (mem_image_of_mem _ hls)).1,
rw [← linear_map.map_add, add_comm, linear_map.mem_ker.1 h₂],
apply zero_mem },
have h_ls_mem_s : (finsupp.total M M R id) ls ∈ span R s,
{ rw ← image_id s,
apply (finsupp.mem_span_iff_total _).2 ⟨ls, hls, rfl⟩ },
have h_lt_mem_t : (finsupp.total M M R id) lt ∈ span R t,
{ rw ← image_id t,
apply (finsupp.mem_span_iff_total _).2 ⟨lt, hlt, rfl⟩ },
have h_ls_0 : ls = 0 :=
disjoint_def.1 (linear_independent_subtype_disjoint.1 hs) _ hls
(linear_map.mem_ker.2 $ disjoint_def.1 hst (finsupp.total M M R id ls) h_ls_mem_s h_ls_mem_t),
have h_lt_0 : lt = 0 :=
disjoint_def.1 (linear_independent_subtype_disjoint.1 ht) _ hlt
(linear_map.mem_ker.2 $ disjoint_def.1 hst (finsupp.total M M R id lt) h_lt_mem_s h_lt_mem_t),
show ls + lt = 0,
by simp [h_ls_0, h_lt_0],
end
lemma linear_independent_of_finite (s : set M)
(H : ∀ t ⊆ s, finite t → linear_independent R (λ x, x : t → M)) :
linear_independent R (λ x, x : s → M) :=
linear_independent_subtype.2 $
λ l hl, linear_independent_subtype.1 (H _ hl (finset.finite_to_set _)) l (subset.refl _)
lemma linear_independent_Union_of_directed {η : Type*}
{s : η → set M} (hs : directed (⊆) s)
(h : ∀ i, linear_independent R (λ x, x : s i → M)) :
linear_independent R (λ x, x : (⋃ i, s i) → M) :=
begin
by_cases hη : nonempty η,
{ refine linear_independent_of_finite (⋃ i, s i) (λ t ht ft, _),
rcases finite_subset_Union ft ht with ⟨I, fi, hI⟩,
rcases hs.finset_le hη fi.to_finset with ⟨i, hi⟩,
exact (h i).mono (subset.trans hI $ bUnion_subset $
λ j hj, hi j (finite.mem_to_finset.2 hj)) },
{ refine (linear_independent_empty _ _).mono _,
rintro _ ⟨_, ⟨i, _⟩, _⟩, exact hη ⟨i⟩ }
end
lemma linear_independent_sUnion_of_directed {s : set (set M)}
(hs : directed_on (⊆) s)
(h : ∀ a ∈ s, linear_independent R (λ x, x : (a : set M) → M)) :
linear_independent R (λ x, x : (⋃₀ s) → M) :=
by rw sUnion_eq_Union; exact
linear_independent_Union_of_directed
((directed_on_iff_directed _).1 hs) (by simpa using h)
lemma linear_independent_bUnion_of_directed {η} {s : set η} {t : η → set M}
(hs : directed_on (t ⁻¹'o (⊆)) s) (h : ∀a∈s, linear_independent R (λ x, x : t a → M)) :
linear_independent R (λ x, x : (⋃a∈s, t a) → M) :=
by rw bUnion_eq_Union; exact
linear_independent_Union_of_directed
((directed_comp _ _ _).2 $ (directed_on_iff_directed _).1 hs)
(by simpa using h)
lemma linear_independent_Union_finite_subtype {ι : Type*} {f : ι → set M}
(hl : ∀i, linear_independent R (λ x, x : f i → M))
(hd : ∀i, ∀t:set ι, finite t → i ∉ t → disjoint (span R (f i)) (⨆i∈t, span R (f i))) :
linear_independent R (λ x, x : (⋃i, f i) → M) :=
begin
rw [Union_eq_Union_finset f],
apply linear_independent_Union_of_directed,
apply directed_of_sup,
exact (assume t₁ t₂ ht, Union_subset_Union $ assume i, Union_subset_Union_const $ assume h, ht h),
assume t, rw [set.Union, ← finset.sup_eq_supr],
refine t.induction_on _ _,
{ rw finset.sup_empty,
apply linear_independent_empty_type (not_nonempty_iff_imp_false.2 _),
exact λ x, set.not_mem_empty x (subtype.mem x) },
{ rintros ⟨i⟩ s his ih,
rw [finset.sup_insert],
refine (hl _).union ih _,
rw [finset.sup_eq_supr],
refine (hd i _ _ his).mono_right _,
{ simp only [(span_Union _).symm],
refine span_mono (@supr_le_supr2 (set M) _ _ _ _ _ _),
rintros ⟨i⟩, exact ⟨i, le_refl _⟩ },
{ change finite (plift.up ⁻¹' ↑s),
exact finite_preimage (assume i j _ _, plift.up.inj) s.finite_to_set } }
end
lemma linear_independent_Union_finite {η : Type*} {ιs : η → Type*}
{f : Π j : η, ιs j → M}
(hindep : ∀j, linear_independent R (f j))
(hd : ∀i, ∀t:set η, finite t → i ∉ t →
disjoint (span R (range (f i))) (⨆i∈t, span R (range (f i)))) :
linear_independent R (λ ji : Σ j, ιs j, f ji.1 ji.2) :=
begin
by_cases zero_eq_one : (0 : R) = 1,
{ apply linear_independent_of_zero_eq_one zero_eq_one },
apply linear_independent.of_subtype_range,
{ rintros ⟨x₁, x₂⟩ ⟨y₁, y₂⟩ hxy,
by_cases h_cases : x₁ = y₁,
subst h_cases,
{ apply sigma.eq,
rw linear_independent.injective zero_eq_one (hindep _) hxy,
refl },
{ have h0 : f x₁ x₂ = 0,
{ apply disjoint_def.1 (hd x₁ {y₁} (finite_singleton y₁)
(λ h, h_cases (eq_of_mem_singleton h))) (f x₁ x₂) (subset_span (mem_range_self _)),
rw supr_singleton,
simp only [] at hxy,
rw hxy,
exact (subset_span (mem_range_self y₂)) },
exact false.elim ((hindep x₁).ne_zero zero_eq_one h0) } },
rw range_sigma_eq_Union_range,
apply linear_independent_Union_finite_subtype (λ j, (hindep j).to_subtype_range) hd,
end
end subtype
section repr
variables (hv : linear_independent R v)
/-- Canonical isomorphism between linear combinations and the span of linearly independent vectors.
-/
def linear_independent.total_equiv (hv : linear_independent R v) :
(ι →₀ R) ≃ₗ[R] span R (range v) :=
begin
apply linear_equiv.of_bijective
(linear_map.cod_restrict (span R (range v)) (finsupp.total ι M R v) _),
{ rw linear_map.ker_cod_restrict,
apply hv },
{ rw [linear_map.range, linear_map.map_cod_restrict, ← linear_map.range_le_iff_comap,
range_subtype, map_top],
rw finsupp.range_total,
apply le_refl (span R (range v)) },
{ intro l,
rw ← finsupp.range_total,
rw linear_map.mem_range,
apply mem_range_self l }
end
/-- Linear combination representing a vector in the span of linearly independent vectors.
Given a family of linearly independent vectors, we can represent any vector in their span as
a linear combination of these vectors. These are provided by this linear map.
It is simply one direction of `linear_independent.total_equiv`. -/
def linear_independent.repr (hv : linear_independent R v) :
span R (range v) →ₗ[R] ι →₀ R := hv.total_equiv.symm
lemma linear_independent.total_repr (x) : finsupp.total ι M R v (hv.repr x) = x :=
subtype.coe_ext.1 (linear_equiv.apply_symm_apply hv.total_equiv x)
lemma linear_independent.total_comp_repr :
(finsupp.total ι M R v).comp hv.repr = submodule.subtype _ :=
linear_map.ext $ hv.total_repr
lemma linear_independent.repr_ker : hv.repr.ker = ⊥ :=
by rw [linear_independent.repr, linear_equiv.ker]
lemma linear_independent.repr_range : hv.repr.range = ⊤ :=
by rw [linear_independent.repr, linear_equiv.range]
lemma linear_independent.repr_eq
{l : ι →₀ R} {x} (eq : finsupp.total ι M R v l = ↑x) :
hv.repr x = l :=
begin
have : ↑((linear_independent.total_equiv hv : (ι →₀ R) →ₗ[R] span R (range v)) l)
= finsupp.total ι M R v l := rfl,
have : (linear_independent.total_equiv hv : (ι →₀ R) →ₗ[R] span R (range v)) l = x,
{ rw eq at this,
exact subtype.coe_ext.2 this },
rw ←linear_equiv.symm_apply_apply hv.total_equiv l,
rw ←this,
refl,
end
lemma linear_independent.repr_eq_single (i) (x) (hx : ↑x = v i) :
hv.repr x = finsupp.single i 1 :=
begin
apply hv.repr_eq,
simp [finsupp.total_single, hx]
end
-- TODO: why is this so slow?
lemma linear_independent_iff_not_smul_mem_span :
linear_independent R v ↔ (∀ (i : ι) (a : R), a • (v i) ∈ span R (v '' (univ \ {i})) → a = 0) :=
⟨ λ hv i a ha, begin
rw [finsupp.span_eq_map_total, mem_map] at ha,
rcases ha with ⟨l, hl, e⟩,
rw sub_eq_zero.1 (linear_independent_iff.1 hv (l - finsupp.single i a) (by simp [e])) at hl,
by_contra hn,
exact (not_mem_of_mem_diff (hl $ by simp [hn])) (mem_singleton _),
end, λ H, linear_independent_iff.2 $ λ l hl, begin
ext i, simp only [finsupp.zero_apply],
by_contra hn,
refine hn (H i _ _),
refine (finsupp.mem_span_iff_total _).2 ⟨finsupp.single i (l i) - l, _, _⟩,
{ rw finsupp.mem_supported',
intros j hj,
have hij : j = i :=
classical.not_not.1
(λ hij : j ≠ i, hj ((mem_diff _).2 ⟨mem_univ _, λ h, hij (eq_of_mem_singleton h)⟩)),
simp [hij] },
{ simp [hl] }
end⟩
end repr
lemma surjective_of_linear_independent_of_span
(hv : linear_independent R v) (f : ι' ↪ ι)
(hss : range v ⊆ span R (range (v ∘ f))) (zero_ne_one : 0 ≠ (1 : R)):
surjective f :=
begin
intros i,
let repr : (span R (range (v ∘ f)) : Type*) → ι' →₀ R := (hv.comp f f.inj).repr,
let l := (repr ⟨v i, hss (mem_range_self i)⟩).map_domain f,
have h_total_l : finsupp.total ι M R v l = v i,
{ dsimp only [l],
rw finsupp.total_map_domain,
rw (hv.comp f f.inj).total_repr,
{ refl },
{ exact f.inj } },
have h_total_eq : (finsupp.total ι M R v) l = (finsupp.total ι M R v) (finsupp.single i 1),
by rw [h_total_l, finsupp.total_single, one_smul],
have l_eq : l = _ := linear_map.ker_eq_bot.1 hv h_total_eq,
dsimp only [l] at l_eq,
rw ←finsupp.emb_domain_eq_map_domain at l_eq,
rcases finsupp.single_of_emb_domain_single (repr ⟨v i, _⟩) f i (1 : R) zero_ne_one.symm l_eq
with ⟨i', hi'⟩,
use i',
exact hi'.2
end
lemma eq_of_linear_independent_of_span_subtype {s t : set M} (zero_ne_one : (0 : R) ≠ 1)
(hs : linear_independent R (λ x, x : s → M)) (h : t ⊆ s) (hst : s ⊆ span R t) : s = t :=
begin
let f : t ↪ s := ⟨λ x, ⟨x.1, h x.2⟩, λ a b hab, subtype.val_injective (subtype.mk.inj hab)⟩,
have h_surj : surjective f,
{ apply surjective_of_linear_independent_of_span hs f _ zero_ne_one,
convert hst; simp [f, comp], },
show s = t,
{ apply subset.antisymm _ h,
intros x hx,
rcases h_surj ⟨x, hx⟩ with ⟨y, hy⟩,
convert y.mem,
rw ← subtype.mk.inj hy,
refl }
end
open linear_map
lemma linear_independent.image (hv : linear_independent R v) {f : M →ₗ M'}
(hf_inj : disjoint (span R (range v)) f.ker) : linear_independent R (f ∘ v) :=
begin
rw [disjoint, ← set.image_univ, finsupp.span_eq_map_total, map_inf_eq_map_inf_comap,
map_le_iff_le_comap, comap_bot, finsupp.supported_univ, top_inf_eq] at hf_inj,
unfold linear_independent at hv,
rw hv at hf_inj,
haveI : inhabited M := ⟨0⟩,
rw [linear_independent, finsupp.total_comp],
rw [@finsupp.lmap_domain_total _ _ R _ _ _ _ _ _ _ _ _ _ f, ker_comp, eq_bot_iff],
apply hf_inj,
exact λ _, rfl,
end
lemma linear_independent.image_subtype {s : set M} {f : M →ₗ M'}
(hs : linear_independent R (λ x, x : s → M))
(hf_inj : disjoint (span R s) f.ker) : linear_independent R (λ x, x : f '' s → M') :=
begin
rw [disjoint, ← set.image_id s, finsupp.span_eq_map_total, map_inf_eq_map_inf_comap,
map_le_iff_le_comap, comap_bot] at hf_inj,
haveI : inhabited M := ⟨0⟩,
rw [linear_independent_subtype_disjoint, disjoint, ← finsupp.lmap_domain_supported _ _ f, map_inf_eq_map_inf_comap,
map_le_iff_le_comap, ← ker_comp],
rw [@finsupp.lmap_domain_total _ _ R _ _ _, ker_comp],
{ exact le_trans (le_inf inf_le_left hf_inj)
(le_trans (linear_independent_subtype_disjoint.1 hs) bot_le) },
{ simp }
end
lemma linear_independent.inl_union_inr {s : set M} {t : set M'}
(hs : linear_independent R (λ x, x : s → M))
(ht : linear_independent R (λ x, x : t → M')) :
linear_independent R (λ x, x : inl R M M' '' s ∪ inr R M M' '' t → M × M') :=
begin
refine (hs.image_subtype _).union (ht.image_subtype _) _; [simp, simp, skip],
simp only [span_image],
simp [disjoint_iff, prod_inf_prod]
end
lemma linear_independent_inl_union_inr' {v : ι → M} {v' : ι' → M'}
(hv : linear_independent R v) (hv' : linear_independent R v') :
linear_independent R (sum.elim (inl R M M' ∘ v) (inr R M M' ∘ v')) :=
begin
by_cases zero_eq_one : (0 : R) = 1,
{ apply linear_independent_of_zero_eq_one zero_eq_one },
have inj_v : injective v := (linear_independent.injective zero_eq_one hv),
have inj_v' : injective v' := (linear_independent.injective zero_eq_one hv'),
apply linear_independent.of_subtype_range,
{ apply sum.elim_injective,
{ exact prod.injective_inl.comp inj_v },
{ exact prod.injective_inr.comp inj_v' },
{ intros, simp [hv.ne_zero zero_eq_one] } },
{ rw sum.elim_range,
refine (hv.image _).to_subtype_range.union (hv'.image _).to_subtype_range _;
[simp, simp, skip],
apply disjoint_inl_inr.mono _ _;
simp only [set.range_comp, span_image, linear_map.map_le_range] }
end
/-- Dedekind's linear independence of characters -/
-- See, for example, Keith Conrad's note <https://kconrad.math.uconn.edu/blurbs/galoistheory/linearchar.pdf>
theorem linear_independent_monoid_hom (G : Type*) [monoid G] (L : Type*) [integral_domain L] :
@linear_independent _ L (G → L) (λ f, f : (G →* L) → (G → L)) _ _ _ :=
by letI := classical.dec_eq (G →* L);
letI : mul_action L L := distrib_mul_action.to_mul_action;
-- We prove linear independence by showing that only the trivial linear combination vanishes.
exact linear_independent_iff'.2
-- To do this, we use `finset` induction,
(λ s, finset.induction_on s (λ g hg i, false.elim) $ λ a s has ih g hg,
-- Here
-- * `a` is a new character we will insert into the `finset` of characters `s`,
-- * `ih` is the fact that only the trivial linear combination of characters in `s` is zero
-- * `hg` is the fact that `g` are the coefficients of a linear combination summing to zero
-- and it remains to prove that `g` vanishes on `insert a s`.
-- We now make the key calculation:
-- For any character `i` in the original `finset`, we have `g i • i = g i • a` as functions on the monoid `G`.
have h1 : ∀ i ∈ s, (g i • i : G → L) = g i • a, from λ i his, funext $ λ x : G,
-- We prove these expressions are equal by showing
-- the differences of their values on each monoid element `x` is zero
eq_of_sub_eq_zero $ ih (λ j, g j * j x - g j * a x)
(funext $ λ y : G, calc
-- After that, it's just a chase scene.
s.sum (λ i, ((g i * i x - g i * a x) • i : G → L)) y
= s.sum (λ i, (g i * i x - g i * a x) * i y) : pi.finset_sum_apply _ _ _
... = s.sum (λ i, g i * i x * i y - g i * a x * i y) : finset.sum_congr rfl
(λ _ _, sub_mul _ _ _)
... = s.sum (λ i, g i * i x * i y) - s.sum (λ i, g i * a x * i y) : finset.sum_sub_distrib
... = (g a * a x * a y + s.sum (λ i, g i * i x * i y))
- (g a * a x * a y + s.sum (λ i, g i * a x * i y)) : by rw add_sub_add_left_eq_sub
... = (insert a s).sum (λ i, g i * i x * i y) - (insert a s).sum (λ i, g i * a x * i y) :
by rw [finset.sum_insert has, finset.sum_insert has]
... = (insert a s).sum (λ i, g i * i (x * y)) - (insert a s).sum (λ i, a x * (g i * i y)) :
congr (congr_arg has_sub.sub (finset.sum_congr rfl $ λ i _, by rw [i.map_mul, mul_assoc]))
(finset.sum_congr rfl $ λ _ _, by rw [mul_assoc, mul_left_comm])
... = (insert a s).sum (λ i, (g i • i : G → L)) (x * y)
- a x * (insert a s).sum (λ i, (g i • i : G → L)) y :
by rw [pi.finset_sum_apply, pi.finset_sum_apply, finset.mul_sum]; refl
... = 0 - a x * 0 : by rw hg; refl
... = 0 : by rw [mul_zero, sub_zero])
i
his,
-- On the other hand, since `a` is not already in `s`, for any character `i ∈ s`
-- there is some element of the monoid on which it differs from `a`.
have h2 : ∀ i : G →* L, i ∈ s → ∃ y, i y ≠ a y, from λ i his,
classical.by_contradiction $ λ h,
have hia : i = a, from monoid_hom.ext $ λ y, classical.by_contradiction $ λ hy, h ⟨y, hy⟩,
has $ hia ▸ his,
-- From these two facts we deduce that `g` actually vanishes on `s`,
have h3 : ∀ i ∈ s, g i = 0, from λ i his, let ⟨y, hy⟩ := h2 i his in
have h : g i • i y = g i • a y, from congr_fun (h1 i his) y,
or.resolve_right (mul_eq_zero.1 $ by rw [mul_sub, sub_eq_zero]; exact h) (sub_ne_zero_of_ne hy),
-- And so, using the fact that the linear combination over `s` and over `insert a s` both vanish,
-- we deduce that `g a = 0`.
have h4 : g a = 0, from calc
g a = g a * 1 : (mul_one _).symm
... = (g a • a : G → L) 1 : by rw ← a.map_one; refl
... = (insert a s).sum (λ i, (g i • i : G → L)) 1 : begin
rw finset.sum_eq_single a,
{ intros i his hia, rw finset.mem_insert at his, rw [h3 i (his.resolve_left hia), zero_smul] },
{ intros haas, exfalso, apply haas, exact finset.mem_insert_self a s }
end
... = 0 : by rw hg; refl,
-- Now we're done; the last two facts together imply that `g` vanishes on every element of `insert a s`.
(finset.forall_mem_insert _ _ _).2 ⟨h4, h3⟩)
lemma le_of_span_le_span {s t u: set M} (zero_ne_one : (0 : R) ≠ 1)
(hl : linear_independent R (subtype.val : u → M )) (hsu : s ⊆ u) (htu : t ⊆ u)
(hst : span R s ≤ span R t) : s ⊆ t :=
begin
have := eq_of_linear_independent_of_span_subtype zero_ne_one
(hl.mono (set.union_subset hsu htu))
(set.subset_union_right _ _)
(set.union_subset (set.subset.trans subset_span hst) subset_span),
rw ← this, apply set.subset_union_left
end
lemma span_le_span_iff {s t u: set M} (zero_ne_one : (0 : R) ≠ 1)
(hl : linear_independent R (subtype.val : u → M )) (hsu : s ⊆ u) (htu : t ⊆ u) :
span R s ≤ span R t ↔ s ⊆ t :=
⟨le_of_span_le_span zero_ne_one hl hsu htu, span_mono⟩
variables (R) (v)
/-- A family of vectors is a basis if it is linearly independent and all vectors are in the span. -/
def is_basis := linear_independent R v ∧ span R (range v) = ⊤
variables {R} {v}
section is_basis
variables {s t : set M} (hv : is_basis R v)
lemma is_basis.mem_span (hv : is_basis R v) : ∀ x, x ∈ span R (range v) := eq_top_iff'.1 hv.2
lemma is_basis.comp (hv : is_basis R v) (f : ι' → ι) (hf : bijective f) :
is_basis R (v ∘ f) :=
begin
split,
{ apply hv.1.comp f hf.1 },
{ rw[set.range_comp, range_iff_surjective.2 hf.2, image_univ, hv.2] }
end
lemma is_basis.injective (hv : is_basis R v) (zero_ne_one : (0 : R) ≠ 1) : injective v :=
λ x y h, linear_independent.injective zero_ne_one hv.1 h
/-- Given a basis, any vector can be written as a linear combination of the basis vectors. They are
given by this linear map. This is one direction of `module_equiv_finsupp`. -/
def is_basis.repr : M →ₗ (ι →₀ R) :=
(hv.1.repr).comp (linear_map.id.cod_restrict _ hv.mem_span)
lemma is_basis.total_repr (x) : finsupp.total ι M R v (hv.repr x) = x :=
hv.1.total_repr ⟨x, _⟩
lemma is_basis.total_comp_repr : (finsupp.total ι M R v).comp hv.repr = linear_map.id :=
linear_map.ext hv.total_repr
lemma is_basis.repr_ker : hv.repr.ker = ⊥ :=
linear_map.ker_eq_bot.2 $ left_inverse.injective hv.total_repr
lemma is_basis.repr_range : hv.repr.range = finsupp.supported R R univ :=
by rw [is_basis.repr, linear_map.range, submodule.map_comp,
linear_map.map_cod_restrict, submodule.map_id, comap_top, map_top, hv.1.repr_range,
finsupp.supported_univ]
lemma is_basis.repr_total (x : ι →₀ R) (hx : x ∈ finsupp.supported R R (univ : set ι)) :
hv.repr (finsupp.total ι M R v x) = x :=
begin
rw [← hv.repr_range, linear_map.mem_range] at hx,
cases hx with w hw,
rw [← hw, hv.total_repr],
end
lemma is_basis.repr_eq_single {i} : hv.repr (v i) = finsupp.single i 1 :=
by apply hv.1.repr_eq_single; simp
/-- Construct a linear map given the value at the basis. -/
def is_basis.constr (f : ι → M') : M →ₗ[R] M' :=
(finsupp.total M' M' R id).comp $ (finsupp.lmap_domain R R f).comp hv.repr
theorem is_basis.constr_apply (f : ι → M') (x : M) :
(hv.constr f : M → M') x = (hv.repr x).sum (λb a, a • f b) :=
by dsimp [is_basis.constr];
rw [finsupp.total_apply, finsupp.sum_map_domain_index]; simp [add_smul]
lemma is_basis.ext {f g : M →ₗ[R] M'} (hv : is_basis R v) (h : ∀i, f (v i) = g (v i)) : f = g :=
begin
apply linear_map.ext (λ x, linear_eq_on (range v) _ (hv.mem_span x)),
exact (λ y hy, exists.elim (set.mem_range.1 hy) (λ i hi, by rw ←hi; exact h i))
end
@[simp] lemma constr_basis {f : ι → M'} {i : ι} (hv : is_basis R v) :
(hv.constr f : M → M') (v i) = f i :=
by simp [is_basis.constr_apply, hv.repr_eq_single, finsupp.sum_single_index]
lemma constr_eq {g : ι → M'} {f : M →ₗ[R] M'} (hv : is_basis R v)
(h : ∀i, g i = f (v i)) : hv.constr g = f :=
hv.ext $ λ i, (constr_basis hv).trans (h i)
lemma constr_self (f : M →ₗ[R] M') : hv.constr (λ i, f (v i)) = f :=
constr_eq hv $ λ x, rfl
lemma constr_zero (hv : is_basis R v) : hv.constr (λi, (0 : M')) = 0 :=
constr_eq hv $ λ x, rfl
lemma constr_add {g f : ι → M'} (hv : is_basis R v) :
hv.constr (λi, f i + g i) = hv.constr f + hv.constr g :=
constr_eq hv $ λ b, by simp
lemma constr_neg {f : ι → M'} (hv : is_basis R v) : hv.constr (λi, - f i) = - hv.constr f :=
constr_eq hv $ λ b, by simp
lemma constr_sub {g f : ι → M'} (hs : is_basis R v) :
hv.constr (λi, f i - g i) = hs.constr f - hs.constr g :=
by simp [sub_eq_add_neg, constr_add, constr_neg]
-- this only works on functions if `R` is a commutative ring
lemma constr_smul {ι R M} [comm_ring R] [add_comm_group M] [module R M]
{v : ι → R} {f : ι → M} {a : R} (hv : is_basis R v) :
hv.constr (λb, a • f b) = a • hv.constr f :=
constr_eq hv $ by simp [constr_basis hv] {contextual := tt}
lemma constr_range [nonempty ι] (hv : is_basis R v) {f : ι → M'} :
(hv.constr f).range = span R (range f) :=
by rw [is_basis.constr, linear_map.range_comp, linear_map.range_comp, is_basis.repr_range,
finsupp.lmap_domain_supported, ←set.image_univ, ←finsupp.span_eq_map_total, image_id]
/-- Canonical equivalence between a module and the linear combinations of basis vectors. -/
def module_equiv_finsupp (hv : is_basis R v) : M ≃ₗ[R] ι →₀ R :=
(hv.1.total_equiv.trans (linear_equiv.of_top _ hv.2)).symm
/-- Isomorphism between the two modules, given two modules `M` and `M'` with respective bases
`v` and `v'` and a bijection between the indexing sets of the two bases. -/
def equiv_of_is_basis {v : ι → M} {v' : ι' → M'} (hv : is_basis R v) (hv' : is_basis R v')
(e : ι ≃ ι') : M ≃ₗ[R] M' :=
{ inv_fun := hv'.constr (v ∘ e.symm),
left_inv := have (hv'.constr (v ∘ e.symm)).comp (hv.constr (v' ∘ e)) = linear_map.id,
from hv.ext $ by simp,
λ x, congr_arg (λ h : M →ₗ[R] M, h x) this,
right_inv := have (hv.constr (v' ∘ e)).comp (hv'.constr (v ∘ e.symm)) = linear_map.id,
from hv'.ext $ by simp,
λ y, congr_arg (λ h : M' →ₗ[R] M', h y) this,
..hv.constr (v' ∘ e) }
/-- Isomorphism between the two modules, given two modules `M` and `M'` with respective bases
`v` and `v'` and a bijection between the two bases. -/
def equiv_of_is_basis' {v : ι → M} {v' : ι' → M'} (f : M → M') (g : M' → M)
(hv : is_basis R v) (hv' : is_basis R v')
(hf : ∀i, f (v i) ∈ range v') (hg : ∀i, g (v' i) ∈ range v)
(hgf : ∀i, g (f (v i)) = v i) (hfg : ∀i, f (g (v' i)) = v' i) :
M ≃ₗ M' :=
{ inv_fun := hv'.constr (g ∘ v'),
left_inv :=
have (hv'.constr (g ∘ v')).comp (hv.constr (f ∘ v)) = linear_map.id,
from hv.ext $ λ i, exists.elim (hf i)
(λ i' hi', by simp [constr_basis, hi'.symm]; rw [hi', hgf]),
λ x, congr_arg (λ h:M →ₗ[R] M, h x) this,
right_inv :=
have (hv.constr (f ∘ v)).comp (hv'.constr (g ∘ v')) = linear_map.id,
from hv'.ext $ λ i', exists.elim (hg i')
(λ i hi, by simp [constr_basis, hi.symm]; rw [hi, hfg]),
λ y, congr_arg (λ h:M' →ₗ[R] M', h y) this,
..hv.constr (f ∘ v) }
lemma is_basis_inl_union_inr {v : ι → M} {v' : ι' → M'}
(hv : is_basis R v) (hv' : is_basis R v') :
is_basis R (sum.elim (inl R M M' ∘ v) (inr R M M' ∘ v')) :=
begin
split,
apply linear_independent_inl_union_inr' hv.1 hv'.1,
rw [sum.elim_range, span_union,
set.range_comp, span_image (inl R M M'), hv.2, map_top,
set.range_comp, span_image (inr R M M'), hv'.2, map_top],
exact linear_map.sup_range_inl_inr
end
end is_basis
lemma is_basis_singleton_one (R : Type*) [unique ι] [ring R] :
is_basis R (λ (_ : ι), (1 : R)) :=
begin
split,
{ refine linear_independent_iff.2 (λ l, _),
rw [finsupp.unique_single l, finsupp.total_single, smul_eq_mul, mul_one],
intro hi,
simp [hi] },
{ refine top_unique (λ _ _, _),
simp [submodule.mem_span_singleton] }
end
protected lemma linear_equiv.is_basis (hs : is_basis R v)
(f : M ≃ₗ[R] M') : is_basis R (f ∘ v) :=
begin
split,
{ apply @linear_independent.image _ _ _ _ _ _ _ _ _ _ hs.1 (f : M →ₗ[R] M'),
simp [linear_equiv.ker f] },
{ rw set.range_comp,
have : span R ((f : M →ₗ[R] M') '' range v) = ⊤,
{ rw [span_image (f : M →ₗ[R] M'), hs.2],
simp },
exact this }
end
lemma is_basis_span (hs : linear_independent R v) :
@is_basis ι R (span R (range v)) (λ i : ι, ⟨v i, subset_span (mem_range_self _)⟩) _ _ _ :=
begin
split,
{ apply linear_independent_span hs },
{ rw eq_top_iff',
intro x,
have h₁ : subtype.val '' set.range (λ i, subtype.mk (v i) _) = range v,
by rw ←set.range_comp,
have h₂ : map (submodule.subtype _) (span R (set.range (λ i, subtype.mk (v i) _)))
= span R (range v),
by rw [←span_image, submodule.subtype_eq_val, h₁],
have h₃ : (x : M) ∈ map (submodule.subtype _) (span R (set.range (λ i, subtype.mk (v i) _))),
by rw h₂; apply subtype.mem x,
rcases mem_map.1 h₃ with ⟨y, hy₁, hy₂⟩,
have h_x_eq_y : x = y,
by rw [subtype.coe_ext, ← hy₂]; simp,
rw h_x_eq_y,
exact hy₁ }
end
lemma is_basis_empty (h_empty : ¬ nonempty ι) (h : ∀x:M, x = 0) : is_basis R (λ x : ι, (0 : M)) :=
⟨ linear_independent_empty_type h_empty,
eq_top_iff'.2 $ assume x, (h x).symm ▸ submodule.zero_mem _ ⟩
lemma is_basis_empty_bot (h_empty : ¬ nonempty ι) :
is_basis R (λ _ : ι, (0 : (⊥ : submodule R M))) :=
begin
apply is_basis_empty h_empty,
intro x,
apply subtype.ext.2,
exact (submodule.mem_bot R).1 (subtype.mem x),
end
open fintype
variables [fintype ι] (h : is_basis R v)
/-- A module over `R` with a finite basis is linearly equivalent to functions from its basis to `R`.
-/
def equiv_fun_basis : M ≃ₗ[R] (ι → R) :=
linear_equiv.trans (module_equiv_finsupp h)
{ to_fun := finsupp.to_fun,
add := λ x y, by ext; exact finsupp.add_apply,
smul := λ x y, by ext; exact finsupp.smul_apply,
..finsupp.equiv_fun_on_fintype }
/-- A module over a finite ring that admits a finite basis is finite. -/
def module.fintype_of_fintype [fintype R] : fintype M :=
fintype.of_equiv _ (equiv_fun_basis h).to_equiv.symm
theorem module.card_fintype [fintype R] [fintype M] :
card M = (card R) ^ (card ι) :=
calc card M = card (ι → R) : card_congr (equiv_fun_basis h).to_equiv
... = card R ^ card ι : card_fun
/-- Given a basis `v` indexed by `ι`, the canonical linear equivalence between `ι → R` and `M` maps
a function `x : ι → R` to the linear combination `∑_i x i • v i`. -/
@[simp] lemma equiv_fun_basis_symm_apply (x : ι → R) :
(equiv_fun_basis h).symm x = finset.sum finset.univ (λi, x i • v i) :=
begin
change finsupp.sum
((finsupp.equiv_fun_on_fintype.symm : (ι → R) ≃ (ι →₀ R)) x) (λ (i : ι) (a : R), a • v i)
= finset.sum finset.univ (λi, x i • v i),
dsimp [finsupp.equiv_fun_on_fintype, finsupp.sum],
rw finset.sum_filter,
refine finset.sum_congr rfl (λi hi, _),
by_cases H : x i = 0,
{ simp [H] },
{ simp [H], refl }
end
end module
section vector_space
variables
{v : ι → V}
[field K] [add_comm_group V] [add_comm_group V']
[vector_space K V] [vector_space K V']
{s t : set V} {x y z : V}
include K
open submodule
/- TODO: some of the following proofs can generalized with a zero_ne_one predicate type class
(instead of a data containing type class) -/
section
lemma mem_span_insert_exchange : x ∈ span K (insert y s) → x ∉ span K s → y ∈ span K (insert x s) :=
begin
simp [mem_span_insert],
rintro a z hz rfl h,
refine ⟨a⁻¹, -a⁻¹ • z, smul_mem _ _ hz, _⟩,
have a0 : a ≠ 0, {rintro rfl, simp * at *},
simp [a0, smul_add, smul_smul]
end
end
lemma linear_independent_iff_not_mem_span :
linear_independent K v ↔ (∀i, v i ∉ span K (v '' (univ \ {i}))) :=
begin
apply linear_independent_iff_not_smul_mem_span.trans,
split,
{ intros h i h_in_span,
apply one_ne_zero (h i 1 (by simp [h_in_span])) },
{ intros h i a ha,
by_contradiction ha',
exact false.elim (h _ ((smul_mem_iff _ ha').1 ha)) }
end
lemma linear_independent_unique [unique ι] (h : v (default ι) ≠ 0): linear_independent K v :=
begin
rw linear_independent_iff,
intros l hl,
ext i,
rw [unique.eq_default i, finsupp.zero_apply],
by_contra hc,
have := smul_smul (l (default ι))⁻¹ (l (default ι)) (v (default ι)),
rw [finsupp.unique_single l, finsupp.total_single] at hl,
rw [hl, inv_mul_cancel hc, smul_zero, one_smul] at this,
exact h this.symm
end
lemma linear_independent_singleton {x : V} (hx : x ≠ 0) :
linear_independent K (λ x, x : ({x} : set V) → V) :=
begin
apply @linear_independent_unique _ _ _ _ _ _ _ _ _,
apply set.unique_singleton,
apply hx,
end
lemma disjoint_span_singleton {p : submodule K V} {x : V} (x0 : x ≠ 0) :
disjoint p (span K {x}) ↔ x ∉ p :=
⟨λ H xp, x0 (disjoint_def.1 H _ xp (singleton_subset_iff.1 subset_span:_)),
begin
simp [disjoint_def, mem_span_singleton],
rintro xp y yp a rfl,
by_cases a0 : a = 0, {simp [a0]},
exact xp.elim ((smul_mem_iff p a0).1 yp),
end⟩
lemma linear_independent.insert (hs : linear_independent K (λ b, b : s → V)) (hx : x ∉ span K s) :
linear_independent K (λ b, b : insert x s → V) :=
begin
rw ← union_singleton,
have x0 : x ≠ 0 := mt (by rintro rfl; apply zero_mem _) hx,
apply hs.union (linear_independent_singleton x0),
rwa [disjoint_span_singleton x0]
end
lemma exists_linear_independent (hs : linear_independent K (λ x, x : s → V)) (hst : s ⊆ t) :
∃b⊆t, s ⊆ b ∧ t ⊆ span K b ∧ linear_independent K (λ x, x : b → V) :=
begin
rcases zorn.zorn_subset₀ {b | b ⊆ t ∧ linear_independent K (λ x, x : b → V)} _ _
⟨hst, hs⟩ with ⟨b, ⟨bt, bi⟩, sb, h⟩,
{ refine ⟨b, bt, sb, λ x xt, _, bi⟩,
by_contra hn,
apply hn,
rw ← h _ ⟨insert_subset.2 ⟨xt, bt⟩, bi.insert hn⟩ (subset_insert _ _),
exact subset_span (mem_insert _ _) },
{ refine λ c hc cc c0, ⟨⋃₀ c, ⟨_, _⟩, λ x, _⟩,
{ exact sUnion_subset (λ x xc, (hc xc).1) },
{ exact linear_independent_sUnion_of_directed cc.directed_on (λ x xc, (hc xc).2) },
{ exact subset_sUnion_of_mem } }
end
lemma exists_subset_is_basis (hs : linear_independent K (λ x, x : s → V)) :
∃b, s ⊆ b ∧ is_basis K (coe : b → V) :=
let ⟨b, hb₀, hx, hb₂, hb₃⟩ := exists_linear_independent hs (@subset_univ _ _) in
⟨ b, hx,
@linear_independent.restrict_of_comp_subtype _ _ _ id _ _ _ _ hb₃,
by simp; exact eq_top_iff.2 hb₂⟩
variables (K V)
lemma exists_is_basis : ∃b : set V, is_basis K (λ i, i : b → V) :=
let ⟨b, _, hb⟩ := exists_subset_is_basis (linear_independent_empty K V : _) in ⟨b, hb⟩
variables {K V}
-- TODO(Mario): rewrite?
lemma exists_of_linear_independent_of_finite_span {t : finset V}
(hs : linear_independent K (λ x, x : s → V)) (hst : s ⊆ (span K ↑t : submodule K V)) :
∃t':finset V, ↑t' ⊆ s ∪ ↑t ∧ s ⊆ ↑t' ∧ t'.card = t.card :=
have ∀t, ∀(s' : finset V), ↑s' ⊆ s → s ∩ ↑t = ∅ → s ⊆ (span K ↑(s' ∪ t) : submodule K V) →
∃t':finset V, ↑t' ⊆ s ∪ ↑t ∧ s ⊆ ↑t' ∧ t'.card = (s' ∪ t).card :=
assume t, finset.induction_on t
(assume s' hs' _ hss',
have s = ↑s',
from eq_of_linear_independent_of_span_subtype zero_ne_one hs hs' $
by simpa using hss',
⟨s', by simp [this]⟩)
(assume b₁ t hb₁t ih s' hs' hst hss',
have hb₁s : b₁ ∉ s,
from assume h,
have b₁ ∈ s ∩ ↑(insert b₁ t), from ⟨h, finset.mem_insert_self _ _⟩,
by rwa [hst] at this,
have hb₁s' : b₁ ∉ s', from assume h, hb₁s $ hs' h,
have hst : s ∩ ↑t = ∅,
from eq_empty_of_subset_empty $ subset.trans
(by simp [inter_subset_inter, subset.refl]) (le_of_eq hst),
classical.by_cases
(assume : s ⊆ (span K ↑(s' ∪ t) : submodule K V),
let ⟨u, hust, hsu, eq⟩ := ih _ hs' hst this in
have hb₁u : b₁ ∉ u, from assume h, (hust h).elim hb₁s hb₁t,
⟨insert b₁ u, by simp [insert_subset_insert hust],
subset.trans hsu (by simp), by simp [eq, hb₁t, hb₁s', hb₁u]⟩)
(assume : ¬ s ⊆ (span K ↑(s' ∪ t) : submodule K V),
let ⟨b₂, hb₂s, hb₂t⟩ := not_subset.mp this in
have hb₂t' : b₂ ∉ s' ∪ t, from assume h, hb₂t $ subset_span h,
have s ⊆ (span K ↑(insert b₂ s' ∪ t) : submodule K V), from
assume b₃ hb₃,
have ↑(s' ∪ insert b₁ t) ⊆ insert b₁ (insert b₂ ↑(s' ∪ t) : set V),
by simp [insert_eq, -singleton_union, -union_singleton, union_subset_union, subset.refl, subset_union_right],
have hb₃ : b₃ ∈ span K (insert b₁ (insert b₂ ↑(s' ∪ t) : set V)),
from span_mono this (hss' hb₃),
have s ⊆ (span K (insert b₁ ↑(s' ∪ t)) : submodule K V),
by simpa [insert_eq, -singleton_union, -union_singleton] using hss',
have hb₁ : b₁ ∈ span K (insert b₂ ↑(s' ∪ t)),
from mem_span_insert_exchange (this hb₂s) hb₂t,
by rw [span_insert_eq_span hb₁] at hb₃; simpa using hb₃,
let ⟨u, hust, hsu, eq⟩ := ih _ (by simp [insert_subset, hb₂s, hs']) hst this in
⟨u, subset.trans hust $ union_subset_union (subset.refl _) (by simp [subset_insert]),
hsu, by simp [eq, hb₂t', hb₁t, hb₁s']⟩)),
begin
have eq : t.filter (λx, x ∈ s) ∪ t.filter (λx, x ∉ s) = t,
{ apply finset.ext.mpr,
intro x,
by_cases x ∈ s; simp * },
apply exists.elim (this (t.filter (λx, x ∉ s)) (t.filter (λx, x ∈ s))
(by simp [set.subset_def]) (by simp [set.ext_iff] {contextual := tt}) (by rwa [eq])),
intros u h,
exact ⟨u, subset.trans h.1 (by simp [subset_def, and_imp, or_imp_distrib] {contextual:=tt}),
h.2.1, by simp only [h.2.2, eq]⟩
end
lemma exists_finite_card_le_of_finite_of_linear_independent_of_span
(ht : finite t) (hs : linear_independent K (λ x, x : s → V)) (hst : s ⊆ span K t) :
∃h : finite s, h.to_finset.card ≤ ht.to_finset.card :=
have s ⊆ (span K ↑(ht.to_finset) : submodule K V), by simp; assumption,
let ⟨u, hust, hsu, eq⟩ := exists_of_linear_independent_of_finite_span hs this in
have finite s, from finite_subset u.finite_to_set hsu,
⟨this, by rw [←eq]; exact (finset.card_le_of_subset $ finset.coe_subset.mp $ by simp [hsu])⟩
lemma linear_map.exists_left_inverse_of_injective (f : V →ₗ[K] V')
(hf_inj : f.ker = ⊥) : ∃g:V' →ₗ V, g.comp f = linear_map.id :=
begin
rcases exists_is_basis K V with ⟨B, hB⟩,
have hB₀ : _ := hB.1.to_subtype_range,
have : linear_independent K (λ x, x : f '' B → V'),
{ have h₁ := hB₀.image_subtype
(show disjoint (span K (range (λ i : B, i.val))) (linear_map.ker f), by simp [hf_inj]),
rwa B.range_coe_subtype at h₁ },
rcases exists_subset_is_basis this with ⟨C, BC, hC⟩,
haveI : inhabited V := ⟨0⟩,
use hC.constr (C.restrict (inv_fun f)),
refine hB.ext (λ b, _),
rw image_subset_iff at BC,
have : f b = (⟨f b, BC b.2⟩ : C) := rfl,
dsimp,
rw [this, constr_basis hC],
exact left_inverse_inv_fun (linear_map.ker_eq_bot.1 hf_inj) _
end
lemma submodule.exists_is_compl (p : submodule K V) : ∃ q : submodule K V, is_compl p q :=
let ⟨f, hf⟩ := p.subtype.exists_left_inverse_of_injective p.ker_subtype in
⟨f.ker, linear_map.is_compl_of_proj $ linear_map.ext_iff.1 hf⟩
lemma linear_map.exists_right_inverse_of_surjective (f : V →ₗ[K] V')
(hf_surj : f.range = ⊤) : ∃g:V' →ₗ V, f.comp g = linear_map.id :=
begin
rcases exists_is_basis K V' with ⟨C, hC⟩,
haveI : inhabited V := ⟨0⟩,
use hC.constr (C.restrict (inv_fun f)),
refine hC.ext (λ c, _),
simp [constr_basis hC, right_inverse_inv_fun (linear_map.range_eq_top.1 hf_surj) c]
end
open submodule linear_map
theorem quotient_prod_linear_equiv (p : submodule K V) :
nonempty ((p.quotient × p) ≃ₗ[K] V) :=
let ⟨q, hq⟩ := p.exists_is_compl in nonempty.intro $
((quotient_equiv_of_is_compl p q hq).prod (linear_equiv.refl _ _)).trans
(prod_equiv_of_is_compl q p hq.symm)
open fintype
theorem vector_space.card_fintype [fintype K] [fintype V] :
∃ n : ℕ, card V = (card K) ^ n :=
exists.elim (exists_is_basis K V) $ λ b hb, ⟨card b, module.card_fintype hb⟩
end vector_space
namespace pi
open set linear_map
section module
variables {η : Type*} {ιs : η → Type*} {Ms : η → Type*}
variables [ring R] [∀i, add_comm_group (Ms i)] [∀i, module R (Ms i)]
lemma linear_independent_std_basis
(v : Πj, ιs j → (Ms j)) (hs : ∀i, linear_independent R (v i)) :
linear_independent R (λ (ji : Σ j, ιs j), std_basis R Ms ji.1 (v ji.1 ji.2)) :=
begin
have hs' : ∀j : η, linear_independent R (λ i : ιs j, std_basis R Ms j (v j i)),
{ intro j,
apply linear_independent.image (hs j),
simp [ker_std_basis] },
apply linear_independent_Union_finite hs',
{ assume j J _ hiJ,
simp [(set.Union.equations._eqn_1 _).symm, submodule.span_image, submodule.span_Union],
have h₀ : ∀ j, span R (range (λ (i : ιs j), std_basis R Ms j (v j i)))
≤ range (std_basis R Ms j),
{ intro j,
rw [span_le, linear_map.range_coe],
apply range_comp_subset_range },
have h₁ : span R (range (λ (i : ιs j), std_basis R Ms j (v j i)))
≤ ⨆ i ∈ {j}, range (std_basis R Ms i),
{ rw @supr_singleton _ _ _ (λ i, linear_map.range (std_basis R (λ (j : η), Ms j) i)),
apply h₀ },
have h₂ : (⨆ j ∈ J, span R (range (λ (i : ιs j), std_basis R Ms j (v j i)))) ≤
⨆ j ∈ J, range (std_basis R (λ (j : η), Ms j) j) :=
supr_le_supr (λ i, supr_le_supr (λ H, h₀ i)),
have h₃ : disjoint (λ (i : η), i ∈ {j}) J,
{ convert set.disjoint_singleton_left.2 hiJ,
rw ←@set_of_mem_eq _ {j},
refl },
exact (disjoint_std_basis_std_basis _ _ _ _ h₃).mono h₁ h₂ }
end
variable [fintype η]
lemma is_basis_std_basis (s : Πj, ιs j → (Ms j)) (hs : ∀j, is_basis R (s j)) :
is_basis R (λ (ji : Σ j, ιs j), std_basis R Ms ji.1 (s ji.1 ji.2)) :=
begin
split,
{ apply linear_independent_std_basis _ (assume i, (hs i).1) },
have h₁ : Union (λ j, set.range (std_basis R Ms j ∘ s j))
⊆ range (λ (ji : Σ (j : η), ιs j), (std_basis R Ms (ji.fst)) (s (ji.fst) (ji.snd))),
{ apply Union_subset, intro i,
apply range_comp_subset_range (λ x : ιs i, (⟨i, x⟩ : Σ (j : η), ιs j))
(λ (ji : Σ (j : η), ιs j), std_basis R Ms (ji.fst) (s (ji.fst) (ji.snd))) },
have h₂ : ∀ i, span R (range (std_basis R Ms i ∘ s i)) = range (std_basis R Ms i),
{ intro i,
rw [set.range_comp, submodule.span_image, (assume i, (hs i).2), submodule.map_top] },
apply eq_top_mono,
apply span_mono h₁,
rw span_Union,
simp only [h₂],
apply supr_range_std_basis
end
section
variables (R η)
lemma is_basis_fun₀ : is_basis R
(λ (ji : Σ (j : η), unit),
(std_basis R (λ (i : η), R) (ji.fst)) 1) :=
@is_basis_std_basis R η (λi:η, unit) (λi:η, R) _ _ _ _ (λ _ _, (1 : R))
(assume i, @is_basis_singleton_one _ _ _ _)
lemma is_basis_fun : is_basis R (λ i, std_basis R (λi:η, R) i 1) :=
begin
apply (is_basis_fun₀ R η).comp (λ i, ⟨i, punit.star⟩),
apply bijective_iff_has_inverse.2,
use sigma.fst,
suffices : ∀ (a : η) (b : unit), punit.star = b,
{ simpa [function.left_inverse, function.right_inverse] },
exact λ _, punit_eq _
end
end
end module
end pi
|
3426ce3ef56adb25e649f8fe9055317baff88b3d | d1bbf1801b3dcb214451d48214589f511061da63 | /src/analysis/specific_limits.lean | 1447b2ff4f7a3ca68e06241d9c07b2c6623c71b6 | [
"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 | 29,354 | 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.geom_sum
import order.filter.archimedean
import order.iterate
import topology.instances.ennreal
import tactic.ring_exp
import analysis.asymptotics
/-!
# A collection of specific limit computations
-/
noncomputable theory
open classical set function filter finset metric asymptotics
open_locale classical topological_space nat big_operators uniformity nnreal
variables {α : Type*} {β : Type*} {ι : Type*}
lemma tendsto_norm_at_top_at_top : tendsto (norm : ℝ → ℝ) at_top at_top :=
tendsto_abs_at_top_at_top
lemma summable_of_absolute_convergence_real {f : ℕ → ℝ} :
(∃r, tendsto (λn, (∑ i in range n, abs (f i))) at_top (𝓝 r)) → summable f
| ⟨r, hr⟩ :=
begin
refine summable_of_summable_norm ⟨r, (has_sum_iff_tendsto_nat_of_nonneg _ _).2 _⟩,
exact assume i, norm_nonneg _,
simpa only using hr
end
lemma tendsto_inverse_at_top_nhds_0_nat : tendsto (λ n : ℕ, (n : ℝ)⁻¹) at_top (𝓝 0) :=
tendsto_inv_at_top_zero.comp tendsto_coe_nat_at_top_at_top
lemma tendsto_const_div_at_top_nhds_0_nat (C : ℝ) : tendsto (λ n : ℕ, C / n) at_top (𝓝 0) :=
by simpa only [mul_zero] using tendsto_const_nhds.mul tendsto_inverse_at_top_nhds_0_nat
lemma nnreal.tendsto_inverse_at_top_nhds_0_nat : tendsto (λ n : ℕ, (n : ℝ≥0)⁻¹) at_top (𝓝 0) :=
by { rw ← nnreal.tendsto_coe, convert tendsto_inverse_at_top_nhds_0_nat, simp }
lemma nnreal.tendsto_const_div_at_top_nhds_0_nat (C : ℝ≥0) :
tendsto (λ n : ℕ, C / n) at_top (𝓝 0) :=
by simpa using tendsto_const_nhds.mul nnreal.tendsto_inverse_at_top_nhds_0_nat
lemma tendsto_one_div_add_at_top_nhds_0_nat :
tendsto (λ n : ℕ, 1 / ((n : ℝ) + 1)) at_top (𝓝 0) :=
suffices tendsto (λ n : ℕ, 1 / (↑(n + 1) : ℝ)) at_top (𝓝 0), by simpa,
(tendsto_add_at_top_iff_nat 1).2 (tendsto_const_div_at_top_nhds_0_nat 1)
/-! ### Powers -/
lemma tendsto_add_one_pow_at_top_at_top_of_pos [linear_ordered_semiring α] [archimedean α] {r : α}
(h : 0 < r) :
tendsto (λ n:ℕ, (r + 1)^n) at_top at_top :=
tendsto_at_top_at_top_of_monotone' (λ n m, pow_le_pow (le_add_of_nonneg_left (le_of_lt h))) $
not_bdd_above_iff.2 $ λ x, set.exists_range_iff.2 $ add_one_pow_unbounded_of_pos _ h
lemma tendsto_pow_at_top_at_top_of_one_lt [linear_ordered_ring α] [archimedean α]
{r : α} (h : 1 < r) :
tendsto (λn:ℕ, r ^ n) at_top at_top :=
sub_add_cancel r 1 ▸ tendsto_add_one_pow_at_top_at_top_of_pos (sub_pos.2 h)
lemma nat.tendsto_pow_at_top_at_top_of_one_lt {m : ℕ} (h : 1 < m) :
tendsto (λn:ℕ, m ^ n) at_top at_top :=
nat.sub_add_cancel (le_of_lt h) ▸
tendsto_add_one_pow_at_top_at_top_of_pos (nat.sub_pos_of_lt h)
lemma tendsto_norm_zero' {𝕜 : Type*} [normed_group 𝕜] :
tendsto (norm : 𝕜 → ℝ) (𝓝[{x | x ≠ 0}] 0) (𝓝[set.Ioi 0] 0) :=
tendsto_norm_zero.inf $ tendsto_principal_principal.2 $ λ x hx, norm_pos_iff.2 hx
lemma normed_field.tendsto_norm_inverse_nhds_within_0_at_top {𝕜 : Type*} [normed_field 𝕜] :
tendsto (λ x:𝕜, ∥x⁻¹∥) (𝓝[{x | x ≠ 0}] 0) at_top :=
(tendsto_inv_zero_at_top.comp tendsto_norm_zero').congr $ λ x, (normed_field.norm_inv x).symm
lemma tendsto_pow_at_top_nhds_0_of_lt_1 {𝕜 : Type*} [linear_ordered_field 𝕜] [archimedean 𝕜]
[topological_space 𝕜] [order_topology 𝕜] {r : 𝕜} (h₁ : 0 ≤ r) (h₂ : r < 1) :
tendsto (λn:ℕ, r^n) at_top (𝓝 0) :=
h₁.eq_or_lt.elim
(assume : 0 = r, (tendsto_add_at_top_iff_nat 1).mp $ by simp [pow_succ, ← this, tendsto_const_nhds])
(assume : 0 < r,
have tendsto (λn, (r⁻¹ ^ n)⁻¹) at_top (𝓝 0),
from tendsto_inv_at_top_zero.comp
(tendsto_pow_at_top_at_top_of_one_lt $ one_lt_inv this h₂),
this.congr (λ n, by simp))
lemma tendsto_pow_at_top_nhds_within_0_of_lt_1 {𝕜 : Type*} [linear_ordered_field 𝕜] [archimedean 𝕜]
[topological_space 𝕜] [order_topology 𝕜] {r : 𝕜} (h₁ : 0 < r) (h₂ : r < 1) :
tendsto (λn:ℕ, r^n) at_top (𝓝[Ioi 0] 0) :=
tendsto_inf.2 ⟨tendsto_pow_at_top_nhds_0_of_lt_1 h₁.le h₂,
tendsto_principal.2 $ eventually_of_forall $ λ n, pow_pos h₁ _⟩
lemma is_o_pow_pow_of_lt_left {r₁ r₂ : ℝ} (h₁ : 0 ≤ r₁) (h₂ : r₁ < r₂) :
is_o (λ n : ℕ, r₁ ^ n) (λ n, r₂ ^ n) at_top :=
have H : 0 < r₂ := h₁.trans_lt h₂,
is_o_of_tendsto (λ n hn, false.elim $ H.ne' $ pow_eq_zero hn) $
(tendsto_pow_at_top_nhds_0_of_lt_1 (div_nonneg h₁ (h₁.trans h₂.le)) ((div_lt_one H).2 h₂)).congr
(λ n, div_pow _ _ _)
lemma is_O_pow_pow_of_le_left {r₁ r₂ : ℝ} (h₁ : 0 ≤ r₁) (h₂ : r₁ ≤ r₂) :
is_O (λ n : ℕ, r₁ ^ n) (λ n, r₂ ^ n) at_top :=
h₂.eq_or_lt.elim (λ h, h ▸ is_O_refl _ _) (λ h, (is_o_pow_pow_of_lt_left h₁ h).is_O)
lemma is_o_pow_pow_of_abs_lt_left {r₁ r₂ : ℝ} (h : abs r₁ < abs r₂) :
is_o (λ n : ℕ, r₁ ^ n) (λ n, r₂ ^ n) at_top :=
begin
refine (is_o.of_norm_left _).of_norm_right,
exact (is_o_pow_pow_of_lt_left (abs_nonneg r₁) h).congr (pow_abs r₁) (pow_abs r₂)
end
/-- Various statements equivalent to the fact that `f n` grows exponentially slower than `R ^ n`.
* 0: $f n = o(a ^ n)$ for some $-R < a < R$;
* 1: $f n = o(a ^ n)$ for some $0 < a < R$;
* 2: $f n = O(a ^ n)$ for some $-R < a < R$;
* 3: $f n = O(a ^ n)$ for some $0 < a < R$;
* 4: there exist `a < R` and `C` such that one of `C` and `R` is positive and $|f n| ≤ Ca^n$
for all `n`;
* 5: there exists `0 < a < R` and a positive `C` such that $|f n| ≤ Ca^n$ for all `n`;
* 6: there exists `a < R` such that $|f n| ≤ a ^ n$ for sufficiently large `n`;
* 7: there exists `0 < a < R` such that $|f n| ≤ a ^ n$ for sufficiently large `n`.
NB: For backwards compatibility, if you add more items to the list, please append them at the end of
the list. -/
lemma tfae_exists_lt_is_o_pow (f : ℕ → ℝ) (R : ℝ) :
tfae [∃ a ∈ Ioo (-R) R, is_o f (pow a) at_top,
∃ a ∈ Ioo 0 R, is_o f (pow a) at_top,
∃ a ∈ Ioo (-R) R, is_O f (pow a) at_top,
∃ a ∈ Ioo 0 R, is_O f (pow a) at_top,
∃ (a < R) C (h₀ : 0 < C ∨ 0 < R), ∀ n, abs (f n) ≤ C * a ^ n,
∃ (a ∈ Ioo 0 R) (C > 0), ∀ n, abs (f n) ≤ C * a ^ n,
∃ a < R, ∀ᶠ n in at_top, abs (f n) ≤ a ^ n,
∃ a ∈ Ioo 0 R, ∀ᶠ n in at_top, abs (f n) ≤ a ^ n] :=
begin
have A : Ico 0 R ⊆ Ioo (-R) R,
from λ x hx, ⟨(neg_lt_zero.2 (hx.1.trans_lt hx.2)).trans_le hx.1, hx.2⟩,
have B : Ioo 0 R ⊆ Ioo (-R) R := subset.trans Ioo_subset_Ico_self A,
-- First we prove that 1-4 are equivalent using 2 → 3 → 4, 1 → 3, and 2 → 1
tfae_have : 1 → 3, from λ ⟨a, ha, H⟩, ⟨a, ha, H.is_O⟩,
tfae_have : 2 → 1, from λ ⟨a, ha, H⟩, ⟨a, B ha, H⟩,
tfae_have : 3 → 2,
{ rintro ⟨a, ha, H⟩,
rcases exists_between (abs_lt.2 ha) with ⟨b, hab, hbR⟩,
exact ⟨b, ⟨(abs_nonneg a).trans_lt hab, hbR⟩,
H.trans_is_o (is_o_pow_pow_of_abs_lt_left (hab.trans_le (le_abs_self b)))⟩ },
tfae_have : 2 → 4, from λ ⟨a, ha, H⟩, ⟨a, ha, H.is_O⟩,
tfae_have : 4 → 3, from λ ⟨a, ha, H⟩, ⟨a, B ha, H⟩,
-- Add 5 and 6 using 4 → 6 → 5 → 3
tfae_have : 4 → 6,
{ rintro ⟨a, ha, H⟩,
rcases bound_of_is_O_nat_at_top H with ⟨C, hC₀, hC⟩,
refine ⟨a, ha, C, hC₀, λ n, _⟩,
simpa only [real.norm_eq_abs, abs_pow, abs_of_nonneg ha.1.le]
using hC (pow_ne_zero n ha.1.ne') },
tfae_have : 6 → 5, from λ ⟨a, ha, C, H₀, H⟩, ⟨a, ha.2, C, or.inl H₀, H⟩,
tfae_have : 5 → 3,
{ rintro ⟨a, ha, C, h₀, H⟩,
rcases sign_cases_of_C_mul_pow_nonneg (λ n, (abs_nonneg _).trans (H n)) with rfl | ⟨hC₀, ha₀⟩,
{ obtain rfl : f = 0, by { ext n, simpa using H n },
simp only [lt_irrefl, false_or] at h₀,
exact ⟨0, ⟨neg_lt_zero.2 h₀, h₀⟩, is_O_zero _ _⟩ },
exact ⟨a, A ⟨ha₀, ha⟩,
is_O_of_le' _ (λ n, (H n).trans $ mul_le_mul_of_nonneg_left (le_abs_self _) hC₀.le)⟩ },
-- Add 7 and 8 using 2 → 8 → 7 → 3
tfae_have : 2 → 8,
{ rintro ⟨a, ha, H⟩,
refine ⟨a, ha, (H.def zero_lt_one).mono (λ n hn, _)⟩,
rwa [real.norm_eq_abs, real.norm_eq_abs, one_mul, abs_pow, abs_of_pos ha.1] at hn },
tfae_have : 8 → 7, from λ ⟨a, ha, H⟩, ⟨a, ha.2, H⟩,
tfae_have : 7 → 3,
{ rintro ⟨a, ha, H⟩,
have : 0 ≤ a, from nonneg_of_eventually_pow_nonneg (H.mono $ λ n, (abs_nonneg _).trans),
refine ⟨a, A ⟨this, ha⟩, is_O.of_bound 1 _⟩,
simpa only [real.norm_eq_abs, one_mul, abs_pow, abs_of_nonneg this] },
tfae_finish
end
lemma uniformity_basis_dist_pow_of_lt_1 {α : Type*} [metric_space α]
{r : ℝ} (h₀ : 0 < r) (h₁ : r < 1) :
(𝓤 α).has_basis (λ k : ℕ, true) (λ k, {p : α × α | dist p.1 p.2 < r ^ k}) :=
metric.mk_uniformity_basis (λ i _, pow_pos h₀ _) $ λ ε ε0,
(exists_pow_lt_of_lt_one ε0 h₁).imp $ λ k hk, ⟨trivial, hk.le⟩
lemma geom_lt {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) {n : ℕ} (hn : 0 < n)
(h : ∀ k < n, c * u k < u (k + 1)) :
c ^ n * u 0 < u n :=
(monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_le_of_lt hn (by simp)
(λ k hk, by simp [pow_succ, mul_assoc]) h
lemma geom_le {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) (n : ℕ) (h : ∀ k < n, c * u k ≤ u (k + 1)) :
c ^ n * u 0 ≤ u n :=
by refine (monotone_mul_left_of_nonneg hc).seq_le_seq n _ _ h; simp [pow_succ, mul_assoc, le_refl]
/-- If a sequence `v` of real numbers satisfies `k * v n ≤ v (n+1)` with `1 < k`,
then it goes to +∞. -/
lemma tendsto_at_top_of_geom_le {v : ℕ → ℝ} {c : ℝ} (h₀ : 0 < v 0) (hc : 1 < c)
(hu : ∀ n, c * v n ≤ v (n + 1)) : tendsto v at_top at_top :=
tendsto_at_top_mono (λ n, geom_le (zero_le_one.trans hc.le) n (λ k hk, hu k)) $
(tendsto_pow_at_top_at_top_of_one_lt hc).at_top_mul_const h₀
lemma nnreal.tendsto_pow_at_top_nhds_0_of_lt_1 {r : ℝ≥0} (hr : r < 1) :
tendsto (λ n:ℕ, r^n) at_top (𝓝 0) :=
nnreal.tendsto_coe.1 $ by simp only [nnreal.coe_pow, nnreal.coe_zero,
tendsto_pow_at_top_nhds_0_of_lt_1 r.coe_nonneg hr]
lemma ennreal.tendsto_pow_at_top_nhds_0_of_lt_1 {r : ennreal} (hr : r < 1) :
tendsto (λ n:ℕ, r^n) at_top (𝓝 0) :=
begin
rcases ennreal.lt_iff_exists_coe.1 hr with ⟨r, rfl, hr'⟩,
rw [← ennreal.coe_zero],
norm_cast at *,
apply nnreal.tendsto_pow_at_top_nhds_0_of_lt_1 hr
end
/-- In a normed ring, the powers of an element x with `∥x∥ < 1` tend to zero. -/
lemma tendsto_pow_at_top_nhds_0_of_norm_lt_1 {R : Type*} [normed_ring R] {x : R}
(h : ∥x∥ < 1) : tendsto (λ (n : ℕ), x ^ n) at_top (𝓝 0) :=
begin
apply squeeze_zero_norm' (eventually_norm_pow_le x),
exact tendsto_pow_at_top_nhds_0_of_lt_1 (norm_nonneg _) h,
end
lemma tendsto_pow_at_top_nhds_0_of_abs_lt_1 {r : ℝ} (h : abs r < 1) :
tendsto (λn:ℕ, r^n) at_top (𝓝 0) :=
tendsto_pow_at_top_nhds_0_of_norm_lt_1 h
/-! ### Geometric series-/
section geometric
lemma has_sum_geometric_of_lt_1 {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) :
has_sum (λn:ℕ, r ^ n) (1 - r)⁻¹ :=
have r ≠ 1, from ne_of_lt h₂,
have tendsto (λn, (r ^ n - 1) * (r - 1)⁻¹) at_top (𝓝 ((0 - 1) * (r - 1)⁻¹)),
from ((tendsto_pow_at_top_nhds_0_of_lt_1 h₁ h₂).sub tendsto_const_nhds).mul tendsto_const_nhds,
have (λ n, (∑ i in range n, r ^ i)) = (λ n, geom_series r n) := rfl,
(has_sum_iff_tendsto_nat_of_nonneg (pow_nonneg h₁) _).mpr $
by simp [neg_inv, geom_sum, div_eq_mul_inv, *] at *
lemma summable_geometric_of_lt_1 {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) : summable (λn:ℕ, r ^ n) :=
⟨_, has_sum_geometric_of_lt_1 h₁ h₂⟩
lemma tsum_geometric_of_lt_1 {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) : ∑'n:ℕ, r ^ n = (1 - r)⁻¹ :=
(has_sum_geometric_of_lt_1 h₁ h₂).tsum_eq
lemma has_sum_geometric_two : has_sum (λn:ℕ, ((1:ℝ)/2) ^ n) 2 :=
by convert has_sum_geometric_of_lt_1 _ _; norm_num
lemma summable_geometric_two : summable (λn:ℕ, ((1:ℝ)/2) ^ n) :=
⟨_, has_sum_geometric_two⟩
lemma tsum_geometric_two : ∑'n:ℕ, ((1:ℝ)/2) ^ n = 2 :=
has_sum_geometric_two.tsum_eq
lemma sum_geometric_two_le (n : ℕ) : ∑ (i : ℕ) in range n, (1 / (2 : ℝ)) ^ i ≤ 2 :=
begin
have : ∀ i, 0 ≤ (1 / (2 : ℝ)) ^ i,
{ intro i, apply pow_nonneg, norm_num },
convert sum_le_tsum (range n) (λ i _, this i) summable_geometric_two,
exact tsum_geometric_two.symm
end
lemma has_sum_geometric_two' (a : ℝ) : has_sum (λn:ℕ, (a / 2) / 2 ^ n) a :=
begin
convert has_sum.mul_left (a / 2) (has_sum_geometric_of_lt_1
(le_of_lt one_half_pos) one_half_lt_one),
{ funext n, simp, refl, },
{ norm_num }
end
lemma summable_geometric_two' (a : ℝ) : summable (λ n:ℕ, (a / 2) / 2 ^ n) :=
⟨a, has_sum_geometric_two' a⟩
lemma tsum_geometric_two' (a : ℝ) : ∑' n:ℕ, (a / 2) / 2^n = a :=
(has_sum_geometric_two' a).tsum_eq
lemma nnreal.has_sum_geometric {r : ℝ≥0} (hr : r < 1) :
has_sum (λ n : ℕ, r ^ n) (1 - r)⁻¹ :=
begin
apply nnreal.has_sum_coe.1,
push_cast,
rw [nnreal.coe_sub (le_of_lt hr)],
exact has_sum_geometric_of_lt_1 r.coe_nonneg hr
end
lemma nnreal.summable_geometric {r : ℝ≥0} (hr : r < 1) : summable (λn:ℕ, r ^ n) :=
⟨_, nnreal.has_sum_geometric hr⟩
lemma tsum_geometric_nnreal {r : ℝ≥0} (hr : r < 1) : ∑'n:ℕ, r ^ n = (1 - r)⁻¹ :=
(nnreal.has_sum_geometric hr).tsum_eq
/-- The series `pow r` converges to `(1-r)⁻¹`. For `r < 1` the RHS is a finite number,
and for `1 ≤ r` the RHS equals `∞`. -/
lemma ennreal.tsum_geometric (r : ennreal) : ∑'n:ℕ, r ^ n = (1 - r)⁻¹ :=
begin
cases lt_or_le r 1 with hr hr,
{ rcases ennreal.lt_iff_exists_coe.1 hr with ⟨r, rfl, hr'⟩,
norm_cast at *,
convert ennreal.tsum_coe_eq (nnreal.has_sum_geometric hr),
rw [ennreal.coe_inv $ ne_of_gt $ nnreal.sub_pos.2 hr] },
{ rw [ennreal.sub_eq_zero_of_le hr, ennreal.inv_zero, ennreal.tsum_eq_supr_nat, supr_eq_top],
refine λ a ha, (ennreal.exists_nat_gt (lt_top_iff_ne_top.1 ha)).imp
(λ n hn, lt_of_lt_of_le hn _),
have : ∀ k:ℕ, 1 ≤ r^k, by simpa using canonically_ordered_semiring.pow_le_pow_of_le_left hr,
calc (n:ennreal) = (∑ i in range n, 1) : by rw [sum_const, nsmul_one, card_range]
... ≤ ∑ i in range n, r ^ i : sum_le_sum (λ k _, this k) }
end
variables {K : Type*} [normed_field K] {ξ : K}
lemma has_sum_geometric_of_norm_lt_1 (h : ∥ξ∥ < 1) : has_sum (λn:ℕ, ξ ^ n) (1 - ξ)⁻¹ :=
begin
have xi_ne_one : ξ ≠ 1, by { contrapose! h, simp [h] },
have A : tendsto (λn, (ξ ^ n - 1) * (ξ - 1)⁻¹) at_top (𝓝 ((0 - 1) * (ξ - 1)⁻¹)),
from ((tendsto_pow_at_top_nhds_0_of_norm_lt_1 h).sub tendsto_const_nhds).mul tendsto_const_nhds,
have B : (λ n, (∑ i in range n, ξ ^ i)) = (λ n, geom_series ξ n) := rfl,
rw [has_sum_iff_tendsto_nat_of_summable_norm, B],
{ simpa [geom_sum, xi_ne_one, neg_inv] using A },
{ simp [normed_field.norm_pow, summable_geometric_of_lt_1 (norm_nonneg _) h] }
end
lemma summable_geometric_of_norm_lt_1 (h : ∥ξ∥ < 1) : summable (λn:ℕ, ξ ^ n) :=
⟨_, has_sum_geometric_of_norm_lt_1 h⟩
lemma tsum_geometric_of_norm_lt_1 (h : ∥ξ∥ < 1) : ∑'n:ℕ, ξ ^ n = (1 - ξ)⁻¹ :=
(has_sum_geometric_of_norm_lt_1 h).tsum_eq
lemma has_sum_geometric_of_abs_lt_1 {r : ℝ} (h : abs r < 1) : has_sum (λn:ℕ, r ^ n) (1 - r)⁻¹ :=
has_sum_geometric_of_norm_lt_1 h
lemma summable_geometric_of_abs_lt_1 {r : ℝ} (h : abs r < 1) : summable (λn:ℕ, r ^ n) :=
summable_geometric_of_norm_lt_1 h
lemma tsum_geometric_of_abs_lt_1 {r : ℝ} (h : abs r < 1) : ∑'n:ℕ, r ^ n = (1 - r)⁻¹ :=
tsum_geometric_of_norm_lt_1 h
/-- A geometric series in a normed field is summable iff the norm of the common ratio is less than
one. -/
@[simp] lemma summable_geometric_iff_norm_lt_1 : summable (λ n : ℕ, ξ ^ n) ↔ ∥ξ∥ < 1 :=
begin
refine ⟨λ h, _, summable_geometric_of_norm_lt_1⟩,
obtain ⟨k : ℕ, hk : dist (ξ ^ k) 0 < 1⟩ :=
(h.tendsto_cofinite_zero.eventually (ball_mem_nhds _ zero_lt_one)).exists,
simp only [normed_field.norm_pow, dist_zero_right] at hk,
rw [← one_pow k] at hk,
exact lt_of_pow_lt_pow _ zero_le_one hk
end
end geometric
/-!
### Sequences with geometrically decaying distance in metric spaces
In this paragraph, we discuss sequences in metric spaces or emetric spaces for which the distance
between two consecutive terms decays geometrically. We show that such sequences are Cauchy
sequences, and bound their distances to the limit. We also discuss series with geometrically
decaying terms.
-/
section edist_le_geometric
variables [emetric_space α] (r C : ennreal) (hr : r < 1) (hC : C ≠ ⊤) {f : ℕ → α}
(hu : ∀n, edist (f n) (f (n+1)) ≤ C * r^n)
include hr hC hu
/-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, `C ≠ ∞`, `r < 1`,
then `f` is a Cauchy sequence.-/
lemma cauchy_seq_of_edist_le_geometric : cauchy_seq f :=
begin
refine cauchy_seq_of_edist_le_of_tsum_ne_top _ hu _,
rw [ennreal.tsum_mul_left, ennreal.tsum_geometric],
refine ennreal.mul_ne_top hC (ennreal.inv_ne_top.2 _),
exact ne_of_gt (ennreal.zero_lt_sub_iff_lt.2 hr)
end
omit hr hC
/-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, then the distance from
`f n` to the limit of `f` is bounded above by `C * r^n / (1 - r)`. -/
lemma edist_le_of_edist_le_geometric_of_tendsto {a : α} (ha : tendsto f at_top (𝓝 a)) (n : ℕ) :
edist (f n) a ≤ (C * r^n) / (1 - r) :=
begin
convert edist_le_tsum_of_edist_le_of_tendsto _ hu ha _,
simp only [pow_add, ennreal.tsum_mul_left, ennreal.tsum_geometric, div_eq_mul_inv, mul_assoc]
end
/-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, then the distance from
`f 0` to the limit of `f` is bounded above by `C / (1 - r)`. -/
lemma edist_le_of_edist_le_geometric_of_tendsto₀ {a : α} (ha : tendsto f at_top (𝓝 a)) :
edist (f 0) a ≤ C / (1 - r) :=
by simpa only [pow_zero, mul_one] using edist_le_of_edist_le_geometric_of_tendsto r C hu ha 0
end edist_le_geometric
section edist_le_geometric_two
variables [emetric_space α] (C : ennreal) (hC : C ≠ ⊤) {f : ℕ → α}
(hu : ∀n, edist (f n) (f (n+1)) ≤ C / 2^n) {a : α} (ha : tendsto f at_top (𝓝 a))
include hC hu
/-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then `f` is a Cauchy sequence.-/
lemma cauchy_seq_of_edist_le_geometric_two : cauchy_seq f :=
begin
simp only [div_eq_mul_inv, ennreal.inv_pow] at hu,
refine cauchy_seq_of_edist_le_geometric 2⁻¹ C _ hC hu,
simp [ennreal.one_lt_two]
end
omit hC
include ha
/-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then the distance from
`f n` to the limit of `f` is bounded above by `2 * C * 2^-n`. -/
lemma edist_le_of_edist_le_geometric_two_of_tendsto (n : ℕ) :
edist (f n) a ≤ 2 * C / 2^n :=
begin
simp only [div_eq_mul_inv, ennreal.inv_pow] at *,
rw [mul_assoc, mul_comm],
convert edist_le_of_edist_le_geometric_of_tendsto 2⁻¹ C hu ha n,
rw [ennreal.one_sub_inv_two, ennreal.inv_inv]
end
/-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then the distance from
`f 0` to the limit of `f` is bounded above by `2 * C`. -/
lemma edist_le_of_edist_le_geometric_two_of_tendsto₀: edist (f 0) a ≤ 2 * C :=
by simpa only [pow_zero, div_eq_mul_inv, ennreal.inv_one, mul_one]
using edist_le_of_edist_le_geometric_two_of_tendsto C hu ha 0
end edist_le_geometric_two
section le_geometric
variables [metric_space α] {r C : ℝ} (hr : r < 1) {f : ℕ → α}
(hu : ∀n, dist (f n) (f (n+1)) ≤ C * r^n)
include hr hu
lemma aux_has_sum_of_le_geometric : has_sum (λ n : ℕ, C * r^n) (C / (1 - r)) :=
begin
rcases sign_cases_of_C_mul_pow_nonneg (λ n, dist_nonneg.trans (hu n)) with rfl | ⟨C₀, r₀⟩,
{ simp [has_sum_zero] },
{ refine has_sum.mul_left C _,
simpa using has_sum_geometric_of_lt_1 r₀ hr }
end
variables (r C)
/-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then `f` is a Cauchy sequence.
Note that this lemma does not assume `0 ≤ C` or `0 ≤ r`. -/
lemma cauchy_seq_of_le_geometric : cauchy_seq f :=
cauchy_seq_of_dist_le_of_summable _ hu ⟨_, aux_has_sum_of_le_geometric hr hu⟩
/-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then the distance from
`f n` to the limit of `f` is bounded above by `C * r^n / (1 - r)`. -/
lemma dist_le_of_le_geometric_of_tendsto₀ {a : α} (ha : tendsto f at_top (𝓝 a)) :
dist (f 0) a ≤ C / (1 - r) :=
(aux_has_sum_of_le_geometric hr hu).tsum_eq ▸
dist_le_tsum_of_dist_le_of_tendsto₀ _ hu ⟨_, aux_has_sum_of_le_geometric hr hu⟩ ha
/-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then the distance from
`f 0` to the limit of `f` is bounded above by `C / (1 - r)`. -/
lemma dist_le_of_le_geometric_of_tendsto {a : α} (ha : tendsto f at_top (𝓝 a)) (n : ℕ) :
dist (f n) a ≤ (C * r^n) / (1 - r) :=
begin
have := aux_has_sum_of_le_geometric hr hu,
convert dist_le_tsum_of_dist_le_of_tendsto _ hu ⟨_, this⟩ ha n,
simp only [pow_add, mul_left_comm C, mul_div_right_comm],
rw [mul_comm],
exact (this.mul_left _).tsum_eq.symm
end
omit hr hu
variable (hu₂ : ∀ n, dist (f n) (f (n+1)) ≤ (C / 2) / 2^n)
/-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then `f` is a Cauchy sequence. -/
lemma cauchy_seq_of_le_geometric_two : cauchy_seq f :=
cauchy_seq_of_dist_le_of_summable _ hu₂ $ ⟨_, has_sum_geometric_two' C⟩
/-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then the distance from
`f 0` to the limit of `f` is bounded above by `C`. -/
lemma dist_le_of_le_geometric_two_of_tendsto₀ {a : α} (ha : tendsto f at_top (𝓝 a)) :
dist (f 0) a ≤ C :=
(tsum_geometric_two' C) ▸ dist_le_tsum_of_dist_le_of_tendsto₀ _ hu₂ (summable_geometric_two' C) ha
include hu₂
/-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then the distance from
`f n` to the limit of `f` is bounded above by `C / 2^n`. -/
lemma dist_le_of_le_geometric_two_of_tendsto {a : α} (ha : tendsto f at_top (𝓝 a)) (n : ℕ) :
dist (f n) a ≤ C / 2^n :=
begin
convert dist_le_tsum_of_dist_le_of_tendsto _ hu₂ (summable_geometric_two' C) ha n,
simp only [add_comm n, pow_add, ← div_div_eq_div_mul],
symmetry,
exact ((has_sum_geometric_two' C).div_const _).tsum_eq
end
end le_geometric
section summable_le_geometric
variables [normed_group α] {r C : ℝ} {f : ℕ → α}
lemma dist_partial_sum_le_of_le_geometric (hf : ∀n, ∥f n∥ ≤ C * r^n) (n : ℕ) :
dist (∑ i in range n, f i) (∑ i in range (n+1), f i) ≤ C * r ^ n :=
begin
rw [sum_range_succ, dist_eq_norm, ← norm_neg],
convert hf n,
rw [neg_sub, add_sub_cancel]
end
/-- If `∥f n∥ ≤ C * r ^ n` for all `n : ℕ` and some `r < 1`, then the partial sums of `f` form a
Cauchy sequence. This lemma does not assume `0 ≤ r` or `0 ≤ C`. -/
lemma cauchy_seq_finset_of_geometric_bound (hr : r < 1) (hf : ∀n, ∥f n∥ ≤ C * r^n) :
cauchy_seq (λ s : finset (ℕ), ∑ x in s, f x) :=
cauchy_seq_finset_of_norm_bounded _
(aux_has_sum_of_le_geometric hr (dist_partial_sum_le_of_le_geometric hf)).summable hf
/-- If `∥f n∥ ≤ C * r ^ n` for all `n : ℕ` and some `r < 1`, then the partial sums of `f` are within
distance `C * r ^ n / (1 - r)` of the sum of the series. This lemma does not assume `0 ≤ r` or
`0 ≤ C`. -/
lemma norm_sub_le_of_geometric_bound_of_has_sum (hr : r < 1) (hf : ∀n, ∥f n∥ ≤ C * r^n)
{a : α} (ha : has_sum f a) (n : ℕ) :
∥(∑ x in finset.range n, f x) - a∥ ≤ (C * r ^ n) / (1 - r) :=
begin
rw ← dist_eq_norm,
apply dist_le_of_le_geometric_of_tendsto r C hr (dist_partial_sum_le_of_le_geometric hf),
exact ha.tendsto_sum_nat
end
end summable_le_geometric
section normed_ring_geometric
variables {R : Type*} [normed_ring R] [complete_space R]
open normed_space
/-- A geometric series in a complete normed ring is summable.
Proved above (same name, different namespace) for not-necessarily-complete normed fields. -/
lemma normed_ring.summable_geometric_of_norm_lt_1
(x : R) (h : ∥x∥ < 1) : summable (λ (n:ℕ), x ^ n) :=
begin
have h1 : summable (λ (n:ℕ), ∥x∥ ^ n) := summable_geometric_of_lt_1 (norm_nonneg _) h,
refine summable_of_norm_bounded_eventually _ h1 _,
rw nat.cofinite_eq_at_top,
exact eventually_norm_pow_le x,
end
/-- Bound for the sum of a geometric series in a normed ring. This formula does not assume that the
normed ring satisfies the axiom `∥1∥ = 1`. -/
lemma normed_ring.tsum_geometric_of_norm_lt_1
(x : R) (h : ∥x∥ < 1) : ∥∑' n:ℕ, x ^ n∥ ≤ ∥(1:R)∥ - 1 + (1 - ∥x∥)⁻¹ :=
begin
rw tsum_eq_zero_add (normed_ring.summable_geometric_of_norm_lt_1 x h),
simp only [pow_zero],
refine le_trans (norm_add_le _ _) _,
have : ∥∑' b : ℕ, (λ n, x ^ (n + 1)) b∥ ≤ (1 - ∥x∥)⁻¹ - 1,
{ refine tsum_of_norm_bounded _ (λ b, norm_pow_le' _ (nat.succ_pos b)),
convert (has_sum_nat_add_iff' 1).mpr (has_sum_geometric_of_lt_1 (norm_nonneg x) h),
simp },
linarith
end
lemma geom_series_mul_neg (x : R) (h : ∥x∥ < 1) :
(∑' i:ℕ, x ^ i) * (1 - x) = 1 :=
begin
have := ((normed_ring.summable_geometric_of_norm_lt_1 x h).has_sum.mul_right (1 - x)),
refine tendsto_nhds_unique this.tendsto_sum_nat _,
have : tendsto (λ (n : ℕ), 1 - x ^ n) at_top (𝓝 1),
{ simpa using tendsto_const_nhds.sub (tendsto_pow_at_top_nhds_0_of_norm_lt_1 h) },
convert ← this,
ext n,
rw [←geom_sum_mul_neg, geom_series_def, finset.sum_mul],
end
lemma mul_neg_geom_series (x : R) (h : ∥x∥ < 1) :
(1 - x) * ∑' i:ℕ, x ^ i = 1 :=
begin
have := (normed_ring.summable_geometric_of_norm_lt_1 x h).has_sum.mul_left (1 - x),
refine tendsto_nhds_unique this.tendsto_sum_nat _,
have : tendsto (λ (n : ℕ), 1 - x ^ n) at_top (nhds 1),
{ simpa using tendsto_const_nhds.sub
(tendsto_pow_at_top_nhds_0_of_norm_lt_1 h) },
convert ← this,
ext n,
rw [←mul_neg_geom_sum, geom_series_def, finset.mul_sum]
end
end normed_ring_geometric
/-! ### Positive sequences with small sums on encodable types -/
/-- For any positive `ε`, define on an encodable type a positive sequence with sum less than `ε` -/
def pos_sum_of_encodable {ε : ℝ} (hε : 0 < ε)
(ι) [encodable ι] : {ε' : ι → ℝ // (∀ i, 0 < ε' i) ∧ ∃ c, has_sum ε' c ∧ c ≤ ε} :=
begin
let f := λ n, (ε / 2) / 2 ^ n,
have hf : has_sum f ε := has_sum_geometric_two' _,
have f0 : ∀ n, 0 < f n := λ n, div_pos (half_pos hε) (pow_pos zero_lt_two _),
refine ⟨f ∘ encodable.encode, λ i, f0 _, _⟩,
rcases hf.summable.comp_injective (@encodable.encode_injective ι _) with ⟨c, hg⟩,
refine ⟨c, hg, has_sum_le_inj _ (@encodable.encode_injective ι _) _ _ hg hf⟩,
{ assume i _, exact le_of_lt (f0 _) },
{ assume n, exact le_refl _ }
end
namespace nnreal
theorem exists_pos_sum_of_encodable {ε : ℝ≥0} (hε : 0 < ε) (ι) [encodable ι] :
∃ ε' : ι → ℝ≥0, (∀ i, 0 < ε' i) ∧ ∃c, has_sum ε' c ∧ c < ε :=
let ⟨a, a0, aε⟩ := exists_between hε in
let ⟨ε', hε', c, hc, hcε⟩ := pos_sum_of_encodable a0 ι in
⟨ λi, ⟨ε' i, le_of_lt $ hε' i⟩, assume i, nnreal.coe_lt_coe.2 $ hε' i,
⟨c, has_sum_le (assume i, le_of_lt $ hε' i) has_sum_zero hc ⟩, nnreal.has_sum_coe.1 hc,
lt_of_le_of_lt (nnreal.coe_le_coe.1 hcε) aε ⟩
end nnreal
namespace ennreal
theorem exists_pos_sum_of_encodable {ε : ennreal} (hε : 0 < ε) (ι) [encodable ι] :
∃ ε' : ι → ℝ≥0, (∀ i, 0 < ε' i) ∧ ∑' i, (ε' i : ennreal) < ε :=
begin
rcases exists_between hε with ⟨r, h0r, hrε⟩,
rcases lt_iff_exists_coe.1 hrε with ⟨x, rfl, hx⟩,
rcases nnreal.exists_pos_sum_of_encodable (coe_lt_coe.1 h0r) ι with ⟨ε', hp, c, hc, hcr⟩,
exact ⟨ε', hp, (ennreal.tsum_coe_eq hc).symm ▸ lt_trans (coe_lt_coe.2 hcr) hrε⟩
end
end ennreal
/-!
### Factorial
-/
lemma factorial_tendsto_at_top : tendsto nat.factorial at_top at_top :=
tendsto_at_top_at_top_of_monotone nat.monotone_factorial (λ n, ⟨n, n.self_le_factorial⟩)
lemma tendsto_factorial_div_pow_self_at_top : tendsto (λ n, n! / n^n : ℕ → ℝ) at_top (𝓝 0) :=
tendsto_of_tendsto_of_tendsto_of_le_of_le'
tendsto_const_nhds
(tendsto_const_div_at_top_nhds_0_nat 1)
(eventually_of_forall $ λ n, div_nonneg (by exact_mod_cast n.factorial_pos.le)
(pow_nonneg (by exact_mod_cast n.zero_le) _))
begin
refine (eventually_gt_at_top 0).mono (λ n hn, _),
rcases nat.exists_eq_succ_of_ne_zero hn.ne.symm with ⟨k, rfl⟩,
rw [← prod_range_add_one_eq_factorial, pow_eq_prod_const, div_eq_mul_inv, ← inv_eq_one_div,
prod_nat_cast, nat.cast_succ, ← prod_inv_distrib', ← prod_mul_distrib,
finset.prod_range_succ'],
simp only [prod_range_succ', one_mul, nat.cast_add, zero_add, nat.cast_one],
refine mul_le_of_le_one_left (inv_nonneg.mpr $ by exact_mod_cast hn.le) (prod_le_one _ _);
intros x hx; rw finset.mem_range at hx,
{ refine mul_nonneg _ (inv_nonneg.mpr _); norm_cast; linarith },
{ refine (div_le_one $ by exact_mod_cast hn).mpr _, norm_cast, linarith }
end
|
1f18574a833e6151c35ca08a7d3351fea5a45509 | fe84e287c662151bb313504482b218a503b972f3 | /src/algebra/convolution.lean | 7f72dc07b26de705633a835edf3d0bbeaf87f38e | [] | no_license | NeilStrickland/lean_lib | 91e163f514b829c42fe75636407138b5c75cba83 | 6a9563de93748ace509d9db4302db6cd77d8f92c | refs/heads/master | 1,653,408,198,261 | 1,652,996,419,000 | 1,652,996,419,000 | 181,006,067 | 4 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 19,351 | lean | /-
Copyright (c) 2019 Neil Strickland. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Neil Strickland
This file sets up a framework for convolution. The first ingredient
is an additive monoid `M` with the property that for any `m ∈ M`, the
set `{⟨x,y⟩ : x + y = m}` is finite. If `M` has this property and `R`
is a ring and `f,g : M → R` then we can define `(f * g) m` to be the
sum of `(f x) * (g y)` for all pairs `⟨x,y⟩` with `x + y = m`. If
`M = ℕ` then this rule gives us the power series ring `R[[x]]`.
The first part of this file defines a typeclass `sum_set M` for
additive monoids `M` with the finiteness property mentioned above,
and derives some additional properties of such monoids.
We then define convolution. In order to cover some additional
applications, we work in a context slightly more general than outlined
above. First, we define `convolution.map M P := M → P`, and attach
the convolution structure to the name `convolution.map`. This is
intended to accomodate the fact that we might want to use pointwise
products on `M → P` in some other contexts. I am not sure whether
this is the best way to address that issue. Also, we will assume
that we have a biadditive map `m₁₂ : P₁ → P₂ → P₁₂` of additive
commutative monoids, and we will use it to define a convolution
operation `map M P₁ → map M P₂ → map M P₁₂`. We can recover the
ring structure on `map M R` by taking `P₁ = P₂ = P₁₂ = R`.
-/
import data.fintype.basic data.finsupp algebra.big_operators data.pi.algebra
import data.list_extra
import algebra.biadditive
import algebra.prod_equiv
import tactic.pi_instances
import tactic.squeeze
namespace convolution
open finset
class sum_set (M : Type*) [add_monoid M] :=
(els : M → finset (M × M))
(mem_els : forall (m : M) (xy : M × M), xy ∈ els m ↔ xy.1 + xy.2 = m)
namespace sum_set
variables {M : Type*} [add_monoid M] [decidable_eq M] [sum_set M]
variable (m : M)
def incl (x : M) : (M × M) ↪ (M × M × M) :=
⟨prod.mk x,λ yz₀ yz₁ e, by {injection e}⟩
def incr (z : M) : (M × M) ↪ (M × M × M) :=
⟨λ xy, ⟨xy.1,xy.2,z⟩,λ ⟨x₀,y₀⟩ ⟨x₁,y₁⟩ e,
by {injection e with ex eyz,injection eyz with ey ez,
change x₀ = x₁ at ex,change y₀ = y₁ at ey,rw[ex,ey],}⟩
variable (M)
def twist : M × M ↪ M × M :=
⟨λ xy, ⟨xy.2,xy.1⟩,
λ ⟨x₀,y₀⟩ ⟨x₁,y₁⟩ e,
by {injection e with hy hx,
change x₀ = x₁ at hx, change y₀ = y₁ at hy, rw[hx,hy],}⟩
variable {M}
def els3 : finset (M × M × M) :=
(els m).bUnion (λ xv,(els xv.2).map (incl xv.1))
def els3' : finset (M × M × M) :=
(els m).bUnion (λ uz,(els uz.1).map (incr uz.2))
lemma els3_disjoint (m : M)
(xv₁ : M × M) (h₁ : xv₁ ∈ els m) (xv₂ : M × M) (h₂ : xv₂ ∈ els m)
(h : xv₁ ≠ xv₂) :
disjoint ((els xv₁.2).map (incl xv₁.1)) ((els xv₂.2).map (incl xv₂.1)) :=
begin
rcases xv₁ with ⟨x₁,v₁⟩,
rcases xv₂ with ⟨x₂,v₂⟩,
dsimp [disjoint], rw[subset_empty],
apply eq_empty_iff_forall_not_mem.mpr,intros w hw,apply h,
rcases (mem_inter.mp hw) with ⟨hw₁,hw₂⟩,
rcases mem_map.mp hw₁ with ⟨yz₁,⟨w_sum₁,w_eq₁⟩⟩,
rcases mem_map.mp hw₂ with ⟨yz₂,⟨w_sum₂,w_eq₂⟩⟩,
injection (w_eq₁.trans w_eq₂.symm) with ex eyz,
change x₁ = x₂ at ex,
replace w_sum₁ := (mem_els v₁ _).mp w_sum₁,
replace w_sum₂ := (mem_els v₂ _).mp w_sum₂,
rw[eyz] at w_sum₁,
have ev : v₁ = v₂ := w_sum₁.symm.trans w_sum₂,
rw[ex,ev],
end
lemma els3'_disjoint (m : M)
(uz₁ : M × M) (h₁ : uz₁ ∈ els m) (uz₂ : M × M) (h₂ : uz₂ ∈ els m)
(h : uz₁ ≠ uz₂) :
disjoint ((els uz₁.1).map (incr uz₁.2)) ((els uz₂.1).map (incr uz₂.2)) :=
begin
rcases uz₁ with ⟨u₁,z₁⟩,
rcases uz₂ with ⟨u₂,z₂⟩,
dsimp [disjoint], rw[subset_empty],
apply eq_empty_iff_forall_not_mem.mpr,intros w hw,apply h,
rcases (mem_inter.mp hw) with ⟨hw₁,hw₂⟩,
rcases mem_map.mp hw₁ with ⟨xy₁,⟨w_sum₁,w_eq₁⟩⟩,
rcases mem_map.mp hw₂ with ⟨xy₂,⟨w_sum₂,w_eq₂⟩⟩,
injection (w_eq₁.trans w_eq₂.symm) with ex eyz,
injection eyz with ey ez,
change z₁ = z₂ at ez,
replace w_sum₁ := (mem_els u₁ _).mp w_sum₁,
replace w_sum₂ := (mem_els u₂ _).mp w_sum₂,
rw[ex,ey] at w_sum₁,
have eu : u₁ = u₂ := w_sum₁.symm.trans w_sum₂,
rw[eu,ez],
end
lemma mem_els3 (xyz : M × M × M) :
xyz ∈ els3 m ↔ xyz.1 + xyz.2.1 + xyz.2.2 = m :=
begin
rcases xyz with ⟨x,y,z⟩,
change (⟨x,y,z⟩ : M × M × M) ∈ els3 m ↔ x + y + z = m,
split,
{intro hw,
rcases mem_bUnion.mp hw with ⟨xv,⟨hxv,h⟩⟩,
replace hxv := (mem_els m xv).mp hxv,
rcases mem_map.mp h with ⟨yz,⟨hyz,h'⟩⟩,
replace hyz := (mem_els _ yz).mp hyz,
injection h' with ex eyz, rw[eyz] at hyz,
rw[← hyz,ex,← add_assoc] at hxv,exact hxv,
},
{intro e,
apply mem_bUnion.mpr,
use ⟨x,y + z⟩,
have : x + (y + z) = m := by {rw[← add_assoc,e]},
use (mem_els m ⟨x,y + z⟩).mpr this,
apply mem_map.mpr,
use ⟨y,z⟩, use (mem_els _ _).mpr rfl,refl,
}
end
lemma els3_assoc : els3 m = els3' m :=
begin
ext ⟨x,y,z⟩,rw[mem_els3],
change x + y + z = m ↔ (⟨x,y,z⟩ : M × M × M) ∈ els3' m,
split,
{intro e,
apply mem_bUnion.mpr,use ⟨x + y,z⟩,use (mem_els m _).mpr e,
apply mem_map.mpr,
use ⟨x,y⟩, use (mem_els _ _).mpr rfl,refl,
},
{intro hw,
rcases mem_bUnion.mp hw with ⟨uz,⟨huz,h⟩⟩,
replace huz := (mem_els m uz).mp huz,
rcases mem_map.mp h with ⟨xy,⟨hxy,h'⟩⟩,
replace hxy := (mem_els _ xy).mp hxy,
injection h' with hx hyz,injection hyz with hy hz,
rw[hx,hy] at hxy, rw[← hxy,hz] at huz,
exact huz,
}
end
lemma els_zero_left :
(els m).filter (λ xy, 0 = xy.1) = singleton ⟨0,m⟩ :=
begin
ext ⟨x,y⟩,
rw[mem_filter,mem_els,mem_singleton],
split,
{rintro ⟨h,h'⟩,change x + y = m at h, change 0 = x at h',
rw[← h'] at h ⊢,rw[zero_add] at h,rw[h],
},{
intro e,injection e with ex ey,rw[ex,ey],
split,{change 0 + m = m,rw[zero_add],},{refl}
}
end
lemma els_zero_right :
(els m).filter (λ xy, 0 = xy.2) = singleton ⟨m,0⟩ :=
begin
ext ⟨x,y⟩,
rw[mem_filter,mem_els,mem_singleton],
split,
{rintro ⟨h,h'⟩,change x + y = m at h, change 0 = y at h',
rw[← h'] at h ⊢,rw[add_zero] at h,rw[h],
},{
intro e,injection e with ex ey,rw[ex,ey],
split,{change m + 0 = m,rw[add_zero],},{refl}
}
end
instance : sum_set ℕ := {
els := λ m, (range m.succ).image (λ i, ⟨i,m - i⟩),
mem_els := λ m ⟨x,y⟩, begin
split,
{intro h,rcases mem_image.mp h with ⟨i,⟨i_is_le,e⟩⟩,
replace i_is_le : i ≤ m := mem_range_succ.mp i_is_le,
injection e with ex ey,rw[← ex,← ey],
exact nat.add_sub_of_le i_is_le,
},
{intro e,rw[mem_image],use x,
use mem_range_succ.mpr (e ▸ (nat.le_add_right x y)),congr,
exact norm_num.sub_nat_pos _ _ _ e,
}
end
}
def shuffle (M₁ : Type*) (M₂ : Type*) :
(M₁ × M₁) × (M₂ × M₂) ↪ (M₁ × M₂) × (M₁ × M₂) := {
to_fun := λ x, ⟨⟨x.1.1,x.2.1⟩,⟨x.1.2,x.2.2⟩⟩,
inj' := begin
rintros ⟨⟨x₁,x₂⟩,⟨x₃,x₄⟩⟩ ⟨⟨y₁,y₂⟩,⟨y₃,y₄⟩⟩ e,
injection e with e₁₃ e₂₄,
injection e₁₃ with e₁ e₃, injection e₂₄ with e₂ e₄,
change x₁ = y₁ at e₁, change x₂ = y₂ at e₂,
change x₃ = y₃ at e₃, change x₄ = y₄ at e₄,
rw[e₁,e₂,e₃,e₄],
end
}
instance product
(M₁ : Type*) [add_monoid M₁] [sum_set M₁]
(M₂ : Type*) [add_monoid M₂] [sum_set M₂] : sum_set (M₁ × M₂) := {
els := λ m, (finset.product (els m.1) (els m.2)).map (shuffle M₁ M₂),
mem_els := begin
rintros ⟨m₁,m₂⟩ ⟨⟨x₁,x₃⟩,⟨x₂,x₄⟩⟩,
simp only[],split,
{intro h₁,rcases (mem_map.mp h₁) with ⟨⟨⟨y₁,y₂⟩,⟨y₃,y₄⟩⟩,⟨h₂,e⟩⟩,
dsimp[shuffle] at e,injection e with e₁₃ e₂₄,
injection e₁₃ with e₁ e₃, injection e₂₄ with e₂ e₄,
rw[← e₁,← e₂,← e₃,← e₄],
change prod.mk (y₁ + y₂) (y₃ + y₄) = prod.mk m₁ m₂,
rcases mem_product.mp h₂ with ⟨h₃,h₄⟩,
replace h₃ : y₁ + y₂ = m₁ := (mem_els _ _).mp h₃,
replace h₄ : y₃ + y₄ = m₂ := (mem_els _ _).mp h₄,
rw[h₃,h₄],
},{
intro e,injection e with e₁ e₂,
apply mem_map.mpr, use ⟨⟨x₁,x₂⟩,⟨x₃,x₄⟩⟩,
have h₁ : (prod.mk x₁ x₂) ∈ els m₁ := (mem_els _ _).mpr e₁,
have h₂ : (prod.mk x₃ x₄) ∈ els m₂ := (mem_els _ _).mpr e₂,
use mem_product.mpr ⟨h₁,h₂⟩,refl,
}
end
}
end sum_set
namespace sum_set
variables {M : Type*} [add_comm_monoid M] [decidable_eq M] [sum_set M]
variable (m : M)
lemma els_twist :
(els m).map (twist M) = els m :=
begin
ext ⟨x,y⟩,rw[mem_els],split,
{intro h,rcases mem_map.mp h with ⟨⟨y',x'⟩,⟨yx_sum,e⟩⟩,
change (⟨x',y'⟩ : M × M) = ⟨x,y⟩ at e,injection e with ex ey,
replace yx_sum : y' + x' = m := (mem_els _ _).mp yx_sum,
rw[ex,ey,add_comm y x] at yx_sum,exact yx_sum,
},{
intro e,rw[add_comm] at e,change y + x = m at e,
apply mem_map.mpr,use ⟨y,x⟩,
use (mem_els _ _).mpr e,refl,
}
end
end sum_set
def map (M : Type*) (P : Type*) := M → P
namespace map
variables (M : Type*) (P : Type*)
instance : has_coe_to_fun (map M P) (λ _, M → P) := ⟨ id ⟩
variables {M} {P}
instance [has_zero P] : has_zero (map M P) :=
by {dsimp[map],apply_instance}
@[simp]
lemma zero_apply [has_zero P] {m : M} :
(0 : map M P) m = 0 := rfl
instance [has_add P] : has_add (map M P) :=
by {dsimp[map],apply_instance}
@[simp]
lemma add_apply [has_add P] {a₁ a₂ : map M P} {m : M} :
(a₁ + a₂) m = a₁ m + a₂ m := rfl
instance [add_semigroup P] : add_semigroup (map M P) :=
by {dsimp[map],apply_instance}
instance [add_comm_semigroup P] : add_comm_semigroup (map M P) :=
by {dsimp[map],apply_instance}
instance [add_monoid P] : add_monoid (map M P) :=
by {dsimp[map],apply_instance}
instance [add_comm_monoid P] : add_comm_monoid (map M P) :=
by {dsimp[map],apply_instance}
instance [add_group P] : add_group (map M P) :=
by {dsimp[map],apply_instance}
instance [add_comm_group P] : add_comm_group (map M P) :=
by {dsimp[map],apply_instance}
instance [has_zero M] [decidable_eq M] [has_zero P] [has_one P] : has_one (map M P) :=
⟨λ m, ite (m = 0) 1 0⟩
@[simp]
lemma one_apply [has_zero M] [decidable_eq M] [has_zero P] [has_one P] (m : M) :
(1 : map M P) m = ite (m = 0) 1 0 := rfl
@[simp]
lemma one_apply_zero [has_zero M] [decidable_eq M] [has_zero P] [has_one P] :
(1 : map M P) 0 = 1 := by { dsimp[has_one.one],rw[if_pos rfl] }
lemma one_apply_nz [has_zero M] [decidable_eq M] [has_zero P] [has_one P]
{m : M} (h : m ≠ 0) : (1 : map M P) m = 0 :=
by { dsimp[has_one.one],rw[if_neg h] }
@[ext]
lemma ext : ∀ {a₁ a₂ : map M P}, (∀ m, a₁ m = a₂ m) → a₁ = a₂ := @funext _ _
section single
variables [decidable_eq M]
def single [has_zero P] (m : M) (p : P) : (map M P) :=
λ x, ite (m = x) p (0 : P)
lemma single_apply [has_zero P] {m : M} {p : P} (x : M) :
(single m p) x = ite (m = x) p 0 := rfl
@[simp] lemma single_eq_same [has_zero P] {m : M} {p : P} :
(single m p) m = p := if_pos rfl
@[simp] lemma single_eq_of_ne [has_zero P] {m x : M} {p : P} (h : m ≠ x) :
(single m p) x = 0 := if_neg h
@[simp] lemma single_zero [has_zero P] {m : M} : single m (0 : P) = 0 :=
by {ext x,dsimp[single],split_ifs; refl}
lemma single_add [add_monoid P] {m : M} {p₁ p₂ : P} :
single m (p₁ + p₂) = single m p₁ + single m p₂ :=
by {ext x,dsimp[single],split_ifs,refl,rw[zero_add],}
def delta [has_zero P] [has_zero M] (p : P) : map M P := single (0 : M) p
lemma delta_apply [has_zero P] [has_zero M] {p : P} {x : M} :
(delta p) x = ite ((0 : M) = x) p (0 : P) := rfl
lemma delta_eq_zero [has_zero P] [has_zero M] {p : P} :
(delta p) (0 : M) = p := if_pos rfl
lemma delta_eq_of_ne [has_zero P] [has_zero M] {p : P} {x : M} (h : 0 ≠ x) :
(delta p) x = 0 := single_eq_of_ne h
lemma delta_zero [has_zero P] [has_zero M] :
((delta (0 : P)) : map M P) = 0 := single_zero
lemma delta_add [add_monoid P] [has_zero M] {p₁ p₂ : P} :
(delta (p₁ + p₂) : map M P) = delta p₁ + delta p₂ := single_add
end single
end map
section convolve
variables {M : Type*} [add_monoid M] [decidable_eq M] [sum_set M]
open sum_set
open map
variables {P₁ : Type*} {P₂ : Type*} {P₃ : Type*}
variables {P₁₂ : Type*} {P₂₃ : Type*} {P₁₂₃ : Type*}
variables [add_comm_monoid P₁] [add_comm_monoid P₂] [add_comm_monoid P₃]
variables [add_comm_monoid P₁₂] [add_comm_monoid P₂₃] [add_comm_monoid P₁₂₃]
variables (m₁₂ : P₁ → P₂ → P₁₂) [is_biadditive m₁₂]
variables (m₂₃ : P₂ → P₃ → P₂₃) [is_biadditive m₂₃]
variables (m₁₂₃ : P₁₂ → P₃ → P₁₂₃) [is_biadditive m₁₂₃]
variables (m'₁₂₃ : P₁ → P₂₃ → P₁₂₃) [is_biadditive m'₁₂₃]
def convolve (u₁ : map M P₁) (u₂ : map M P₂) : (map M P₁₂) :=
λ m, (els m).sum (λ x, m₁₂ (u₁ x.1) (u₂ x.2))
lemma zero_convolve (p₂ : map M P₂) : convolve m₁₂ 0 p₂ = 0 := begin
ext m,dsimp[convolve],
have : (els m).sum (λ x, (0 : P₁₂)) = 0 := sum_const_zero,
rw[← this],congr,funext x,rw[is_biadditive.zero_mul m₁₂]
end
lemma convolve_zero (p₁ : map M P₁) : convolve m₁₂ p₁ 0 = 0 := begin
ext m,dsimp[convolve],
have : (els m).sum (λ x, (0 : P₁₂)) = 0 := sum_const_zero,
rw[← this],congr,funext x,rw[is_biadditive.mul_zero m₁₂],
end
lemma add_convolve (p₁ q₁ : map M P₁) (p₂ : map M P₂) :
convolve m₁₂ (p₁ + q₁) p₂ = convolve m₁₂ p₁ p₂ + convolve m₁₂ q₁ p₂ := begin
ext m,
dsimp[convolve],rw[← sum_add_distrib],congr,funext x,
rw[is_biadditive.add_mul m₁₂],
end
lemma convolve_add (p₁ : map M P₁) (p₂ q₂ : map M P₂) :
convolve m₁₂ p₁ (p₂ + q₂) = convolve m₁₂ p₁ p₂ + convolve m₁₂ p₁ q₂ := begin
ext m,
dsimp[convolve],rw[← sum_add_distrib],congr,funext x,
rw[is_biadditive.mul_add m₁₂],
end
instance biadditive_convolve:
is_biadditive (convolve m₁₂ : (map M P₁) → (map M P₂) → (map M P₁₂)) := {
zero_mul' := zero_convolve m₁₂,
add_mul' := add_convolve m₁₂,
mul_zero' := convolve_zero m₁₂,
mul_add' := convolve_add m₁₂,
}
lemma convolve_assoc (p₁ : map M P₁) (p₂ : map M P₂) (p₃ : map M P₃)
(m_assoc : ∀ (p₁ : P₁) (p₂ : P₂) (p₃ : P₃), m₁₂₃ (m₁₂ p₁ p₂) p₃ = m'₁₂₃ p₁ (m₂₃ p₂ p₃)) :
convolve m₁₂₃ (convolve m₁₂ p₁ p₂) p₃ =
convolve m'₁₂₃ p₁ (convolve m₂₃ p₂ p₃) :=
begin
ext m,
let f' : M × M × M → P₁₂₃ := λ x, m₁₂₃ (m₁₂ (p₁ x.1) (p₂ x.2.1)) (p₃ x.2.2),
let f : M × M × M → P₁₂₃ := λ x, m'₁₂₃ (p₁ x.1) (m₂₃ (p₂ x.2.1) (p₃ x.2.2)),
have ef : f' = f := by {funext x,apply m_assoc},
have em' : (els3' m).sum f' = (convolve m₁₂₃ (convolve m₁₂ p₁ p₂) p₃) m :=
begin
dsimp[convolve,els3'],
have hh := els3'_disjoint m,
have hhh := @sum_bUnion (M × M),
let ee := els m,
rw[sum_bUnion (els3'_disjoint m)],
congr,ext ⟨x,v⟩,
rw[is_biadditive.sum_mul m₁₂₃,sum_map],congr,
end,
have em : (els3 m).sum f = (convolve m'₁₂₃ p₁ (convolve m₂₃ p₂ p₃)) m :=
begin
dsimp[convolve,els3],
rw[sum_bUnion (els3_disjoint m)],congr,ext ⟨u,z⟩,
rw[is_biadditive.mul_sum m'₁₂₃,sum_map],congr,
end,
rw[← em,← em',ef,els3_assoc],
end
lemma delta_convolve (p₁ : P₁) (u₂ : map M P₂) (m : M) :
(convolve m₁₂ (delta p₁) u₂) m = m₁₂ p₁ (u₂ m) :=
begin
dsimp[convolve],
let f : M × M → P₁₂ := λ x, m₁₂ (delta p₁ x.1) (u₂ x.2),
let f' : M × M → P₁₂ := λ x, ite (0 = x.1) (f x) 0,
have ef : f = f' :=
by {ext x,dsimp[f,f'],
split_ifs with hx,{refl},{rw[delta_eq_of_ne hx,is_biadditive.zero_mul m₁₂]}},
change (els m).sum f = m₁₂ p₁ (u₂ m),
rw[ef],
have : ((els m).filter (λ (x : M × M), 0 = x.1)).sum f = (els m).sum f' :=
sum_filter (λ (x : M × M), 0 = x.1) f,
rw[← this],rw[els_zero_left,sum_singleton],
dsimp[f],rw[delta_eq_zero],
end
lemma convolve_delta (u₁ : M → P₁) (p₂ : P₂) (m : M) :
(convolve m₁₂ u₁ (delta p₂)) m = m₁₂ (u₁ m) p₂ :=
begin
dsimp[convolve],
let f : M × M → P₁₂ := λ x, m₁₂ (u₁ x.1) (delta p₂ x.2),
let f' : M × M → P₁₂ := λ x, ite (0 = x.2) (f x) 0,
have ef : f = f' :=
by {ext x,dsimp[f,f'],
split_ifs with hx,{refl},{rw[delta_eq_of_ne hx,is_biadditive.mul_zero m₁₂]}},
change (els m).sum f = m₁₂ (u₁ m) p₂,
rw[ef],
have : ((els m).filter (λ (x : M × M), 0 = x.2)).sum f = (els m).sum f' :=
sum_filter (λ x, 0 = x.2) f,
rw[← this,els_zero_right,sum_singleton],
dsimp[f],rw[delta_eq_zero],
end
lemma delta_convolve_delta (p₁ : P₁) (p₂ : P₂) :
(convolve m₁₂ (delta p₁) (delta p₂) : map M P₁₂) = delta (m₁₂ p₁ p₂) :=
by { ext m, rw[delta_convolve,delta_apply,delta_apply],
split_ifs,refl,rw[is_biadditive.mul_zero m₁₂]}
end convolve
namespace map
variables {M : Type*} [add_monoid M] [decidable_eq M] [sum_set M]
instance to_semiring {R : Type*} [semiring R] : semiring (map M R) := {
one := delta (1 : R),
mul := convolve ((*) : R → R → R),
zero_mul := λ a, zero_convolve (*) a,
mul_zero := λ a, convolve_zero (*) a,
one_mul := λ a, begin
ext m,
change convolve (*) (delta (1 : R)) a m = a m,
rw[delta_convolve,one_mul],
end,
mul_one := λ a, begin
ext m,
change convolve (*) a (delta (1 : R)) m = a m,
rw[convolve_delta,mul_one],
end,
mul_assoc := λ a b c, convolve_assoc (*) (*) (*) (*) a b c (mul_assoc),
left_distrib := λ a b c, convolve_add (*) a b c,
right_distrib := λ a b c, add_convolve (*) a b c,
.. (by apply_instance : add_comm_monoid (map M R))
}
instance to_ring {R : Type*} [ring R] : ring (map M R) := {
.. (by apply_instance : add_comm_group (map M R)),
.. (by apply_instance : semiring (map M R))
}
end map
namespace map
open sum_set
variables {M : Type*} [add_comm_monoid M] [decidable_eq M] [sum_set M]
instance to_comm_semiring {R : Type*} [comm_semiring R] : comm_semiring (map M R) := {
mul_comm := λ a₁ a₂, begin
let f : M × M → R := λ x, (a₁ x.1) * (a₂ x.2),
let f' : M × M → R := λ x, (a₂ x.1) * (a₁ x.2),
have ef : (λ x, f (twist M x)) = f' := by {
ext x,dsimp[f,f',twist],rw[mul_comm],
},
ext m, change (els m).sum f = (els m).sum f',
rw[← ef, ← sum_map (els m) (twist M) f,els_twist],
end,
.. map.to_semiring
}
instance to_comm_ring {R : Type*} [comm_ring R] : comm_ring (map M R) := {
.. (by apply_instance : add_comm_group (map M R)),
.. (by apply_instance : comm_semiring (map M R))
}
end map
end convolution
|
dfa548da9ebe15be9d38c40b4a9ff38be8cc9e2a | 0c0281448f624a53333195786d9730b1592ee3ac | /Relation.lean | 90eee9756ac2cb4381bad08bc6168e9c04b273ff | [] | no_license | kindaro/lean_study | ce788f8dd1adaef2e12d6f94ab88685da34b0877 | 8219865eb9f068f132fe4ce0ae4a2fb76b1f5865 | refs/heads/master | 1,693,155,825,536 | 1,634,312,849,000 | 1,634,312,849,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,668 | lean | import Automation
open tactic
def ℙ := Prop
class Same (φ: Type) := (same: φ → φ → ℙ)
notation x `≡` y := Same.same x y
instance Same_arrow (α β: Type) [Same β]: Same (α → β) := Same.mk (λ f₁ f₂, ∀ x, f₁ x ≡ f₂ x)
instance Same_proposition: Same ℙ := Same.mk (λ p q, p ↔ q)
notation α `~` β := α → β → ℙ
def identity {α}: α ~ α := λ x y, x = y
def compose {α β γ}
: (α ~ β) → (β ~ γ) → (α ~ γ)
:= λ r₁ r₂, λ x z, ∃ y, (r₁ x y ∧ r₂ y z)
local notation r₂ `∘` r₁ := compose r₁ r₂
theorem has_left_identity (α β: Type): ∀ (r: α ~ β), identity ∘ r ≡ r :=
begin
intros, unfold identity, unfold compose,
dsimp {md := transparency.instances},
crush,
end
theorem has_right_identity (α β: Type): ∀ (r: α ~ β), r ∘ identity ≡ r :=
begin
intros, unfold identity, unfold compose,
dsimp {md := transparency.instances},
crush,
end
theorem has_identity (α β: Type): ∀ (r: α ~ β), (identity ∘ r ≡ r) ∧ (r ∘ identity ≡ r) :=
begin
intros, unfold identity, unfold compose,
dsimp {md := transparency.instances},
crush,
end
theorem exists_identity (α β: Type): ∀ (r: α ~ β), ∃ (ε: ∀ (type: Type), type ~ type), (ε β ∘ r ≡ r) ∧ (r ∘ ε α ≡ r) :=
begin
intros, unfold compose,
dsimp {md := transparency.instances},
existsi (λ τ x y, x = y), crush,
end
theorem compose_is_associative (α β γ δ: Type)
: ∀ (r₁: α ~ β) (r₂: β ~ γ) (r₃: γ ~ δ)
, (r₃ ∘ r₂) ∘ r₁ ≡ r₃ ∘ (r₂ ∘ r₁) :=
begin
intros, unfold compose,
dsimp {md := transparency.instances},
crush,
end |
64207b3d51c19c9246a8e4e84ebe040059d88a6f | 206422fb9edabf63def0ed2aa3f489150fb09ccb | /src/data/zmod/basic.lean | a756c365694b1a09beddca5f1f6a69f09c93ff5b | [
"Apache-2.0"
] | permissive | hamdysalah1/mathlib | b915f86b2503feeae268de369f1b16932321f097 | 95454452f6b3569bf967d35aab8d852b1ddf8017 | refs/heads/master | 1,677,154,116,545 | 1,611,797,994,000 | 1,611,797,994,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 28,034 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Chris Hughes
-/
import data.int.modeq
import algebra.char_p.basic
import data.nat.totient
import ring_theory.ideal.operations
/-!
# Integers mod `n`
Definition of the integers mod n, and the field structure on the integers mod p.
## Definitions
* `zmod n`, which is for integers modulo a nat `n : ℕ`
* `val a` is defined as a natural number:
- for `a : zmod 0` it is the absolute value of `a`
- for `a : zmod n` with `0 < n` it is the least natural number in the equivalence class
* `val_min_abs` returns the integer closest to zero in the equivalence class.
* A coercion `cast` is defined from `zmod n` into any ring.
This is a ring hom if the ring has characteristic dividing `n`
-/
namespace fin
/-!
## Ring structure on `fin n`
We define a commutative ring structure on `fin n`, but we do not register it as instance.
Afterwords, when we define `zmod n` in terms of `fin n`, we use these definitions
to register the ring structure on `zmod n` as type class instance.
-/
open nat nat.modeq int
/-- Negation on `fin n` -/
def has_neg (n : ℕ) : has_neg (fin n) :=
⟨λ a, ⟨nat_mod (-(a.1 : ℤ)) n,
begin
have npos : 0 < n := lt_of_le_of_lt (nat.zero_le _) a.2,
have h : (n : ℤ) ≠ 0 := int.coe_nat_ne_zero_iff_pos.2 npos,
have := int.mod_lt (-(a.1 : ℤ)) h,
rw [(abs_of_nonneg (int.coe_nat_nonneg n))] at this,
rwa [← int.coe_nat_lt, nat_mod, to_nat_of_nonneg (int.mod_nonneg _ h)]
end⟩⟩
/-- Multiplicative commutative semigroup structure on `fin (n+1)`. -/
def comm_semigroup (n : ℕ) : comm_semigroup (fin (n+1)) :=
{ mul_assoc := λ ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩, fin.eq_of_veq
(calc ((a * b) % (n+1) * c) ≡ a * b * c [MOD (n+1)] : modeq_mul (nat.mod_mod _ _) rfl
... ≡ a * (b * c) [MOD (n+1)] : by rw mul_assoc
... ≡ a * (b * c % (n+1)) [MOD (n+1)] : modeq_mul rfl (nat.mod_mod _ _).symm),
mul_comm := λ ⟨a, _⟩ ⟨b, _⟩,
fin.eq_of_veq (show (a * b) % (n+1) = (b * a) % (n+1), by rw mul_comm),
..fin.has_mul }
local attribute [instance] fin.comm_semigroup
private lemma one_mul_aux (n : ℕ) (a : fin (n+1)) : (1 : fin (n+1)) * a = a :=
begin
cases n with n,
{ exact subsingleton.elim _ _ },
{ have h₁ : (a : ℕ) % n.succ.succ = a := nat.mod_eq_of_lt a.2,
apply fin.ext,
simp only [coe_mul, coe_one, h₁, one_mul], }
end
private lemma left_distrib_aux (n : ℕ) : ∀ a b c : fin (n+1), a * (b + c) = a * b + a * c :=
λ ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩, fin.eq_of_veq
(calc a * ((b + c) % (n+1)) ≡ a * (b + c) [MOD (n+1)] : modeq_mul rfl (nat.mod_mod _ _)
... ≡ a * b + a * c [MOD (n+1)] : by rw mul_add
... ≡ (a * b) % (n+1) + (a * c) % (n+1) [MOD (n+1)] :
modeq_add (nat.mod_mod _ _).symm (nat.mod_mod _ _).symm)
/-- Commutative ring structure on `fin (n+1)`. -/
def comm_ring (n : ℕ) : comm_ring (fin (n+1)) :=
{ add_left_neg :=
λ ⟨a, ha⟩, fin.eq_of_veq (show (((-a : ℤ) % (n+1)).to_nat + a) % (n+1) = 0,
from int.coe_nat_inj
begin
have npos : 0 < n+1 := lt_of_le_of_lt (nat.zero_le _) ha,
have hn : ((n+1) : ℤ) ≠ 0 := (ne_of_lt (int.coe_nat_lt.2 npos)).symm,
rw [int.coe_nat_mod, int.coe_nat_add, to_nat_of_nonneg (int.mod_nonneg _ hn), add_comm],
simp,
end),
one_mul := fin.one_mul,
mul_one := fin.mul_one,
left_distrib := left_distrib_aux n,
right_distrib := λ a b c, by rw [mul_comm, left_distrib_aux, mul_comm _ b, mul_comm]; refl,
..fin.has_one,
..fin.has_neg (n+1),
..fin.add_comm_monoid n,
..fin.comm_semigroup n }
end fin
/-- The integers modulo `n : ℕ`. -/
def zmod : ℕ → Type
| 0 := ℤ
| (n+1) := fin (n+1)
namespace zmod
instance fintype : Π (n : ℕ) [fact (0 < n)], fintype (zmod n)
| 0 _ := false.elim $ nat.not_lt_zero 0 ‹0 < 0›
| (n+1) _ := fin.fintype (n+1)
lemma card (n : ℕ) [fact (0 < n)] : fintype.card (zmod n) = n :=
begin
casesI n,
{ exfalso, exact nat.not_lt_zero 0 ‹0 < 0› },
{ exact fintype.card_fin (n+1) }
end
instance decidable_eq : Π (n : ℕ), decidable_eq (zmod n)
| 0 := int.decidable_eq
| (n+1) := fin.decidable_eq _
instance has_repr : Π (n : ℕ), has_repr (zmod n)
| 0 := int.has_repr
| (n+1) := fin.has_repr _
instance comm_ring : Π (n : ℕ), comm_ring (zmod n)
| 0 := int.comm_ring
| (n+1) := fin.comm_ring n
instance inhabited (n : ℕ) : inhabited (zmod n) := ⟨0⟩
/-- `val a` is a natural number defined as:
- for `a : zmod 0` it is the absolute value of `a`
- for `a : zmod n` with `0 < n` it is the least natural number in the equivalence class
See `zmod.val_min_abs` for a variant that takes values in the integers.
-/
def val : Π {n : ℕ}, zmod n → ℕ
| 0 := int.nat_abs
| (n+1) := (coe : fin (n + 1) → ℕ)
lemma val_lt {n : ℕ} [fact (0 < n)] (a : zmod n) : a.val < n :=
begin
casesI n,
{ exfalso, exact nat.not_lt_zero 0 ‹0 < 0› },
exact fin.is_lt a
end
@[simp] lemma val_zero : ∀ {n}, (0 : zmod n).val = 0
| 0 := rfl
| (n+1) := rfl
lemma val_cast_nat {n : ℕ} (a : ℕ) : (a : zmod n).val = a % n :=
begin
casesI n,
{ rw [nat.mod_zero, int.nat_cast_eq_coe_nat],
exact int.nat_abs_of_nat a, },
rw ← fin.of_nat_eq_coe,
refl
end
instance (n : ℕ) : char_p (zmod n) n :=
{ cast_eq_zero_iff :=
begin
intro k,
cases n,
{ simp only [int.nat_cast_eq_coe_nat, zero_dvd_iff, int.coe_nat_eq_zero], },
rw [fin.eq_iff_veq],
show (k : zmod (n+1)).val = (0 : zmod (n+1)).val ↔ _,
rw [val_cast_nat, val_zero, nat.dvd_iff_mod_eq_zero],
end }
@[simp] lemma cast_self (n : ℕ) : (n : zmod n) = 0 :=
char_p.cast_eq_zero (zmod n) n
@[simp] lemma cast_self' (n : ℕ) : (n + 1 : zmod (n + 1)) = 0 :=
by rw [← nat.cast_add_one, cast_self (n + 1)]
section universal_property
variables {n : ℕ} {R : Type*}
section
variables [has_zero R] [has_one R] [has_add R] [has_neg R]
/-- Cast an integer modulo `n` to another semiring.
This function is a morphism if the characteristic of `R` divides `n`.
See `zmod.cast_hom` for a bundled version. -/
def cast : Π {n : ℕ}, zmod n → R
| 0 := int.cast
| (n+1) := λ i, i.val
-- see Note [coercion into rings]
@[priority 900] instance (n : ℕ) : has_coe_t (zmod n) R := ⟨cast⟩
@[simp] lemma cast_zero : ((0 : zmod n) : R) = 0 :=
by { cases n; refl }
end
lemma nat_cast_surjective [fact (0 < n)] :
function.surjective (coe : ℕ → zmod n) :=
begin
assume i,
casesI n,
{ exfalso, exact nat.not_lt_zero 0 ‹0 < 0› },
{ change fin (n + 1) at i,
refine ⟨i, _⟩,
rw [fin.ext_iff, fin.coe_coe_eq_self] }
end
lemma int_cast_surjective :
function.surjective (coe : ℤ → zmod n) :=
begin
assume i,
cases n,
{ exact ⟨i, int.cast_id i⟩ },
{ rcases nat_cast_surjective i with ⟨k, rfl⟩,
refine ⟨k, _⟩, norm_cast }
end
lemma cast_val {n : ℕ} [fact (0 < n)] (a : zmod n) :
(a.val : zmod n) = a :=
begin
rcases nat_cast_surjective a with ⟨k, rfl⟩,
symmetry,
rw [val_cast_nat, ← sub_eq_zero, ← nat.cast_sub, char_p.cast_eq_zero_iff (zmod n) n],
{ apply nat.dvd_sub_mod },
{ apply nat.mod_le }
end
@[simp, norm_cast]
lemma cast_id : ∀ n (i : zmod n), ↑i = i
| 0 i := int.cast_id i
| (n+1) i := cast_val i
variables [ring R]
@[simp] lemma nat_cast_val [fact (0 < n)] (i : zmod n) :
(i.val : R) = i :=
begin
casesI n,
{ exfalso, exact nat.not_lt_zero 0 ‹0 < 0› },
refl
end
section char_dvd
/-! If the characteristic of `R` divides `n`, then `cast` is a homomorphism. -/
variables {n} {m : ℕ} [char_p R m]
@[simp] lemma cast_one (h : m ∣ n) : ((1 : zmod n) : R) = 1 :=
begin
casesI n,
{ exact int.cast_one },
show ((1 % (n+1) : ℕ) : R) = 1,
cases n, { rw [nat.dvd_one] at h, substI m, apply subsingleton.elim },
rw nat.mod_eq_of_lt,
{ exact nat.cast_one },
exact nat.lt_of_sub_eq_succ rfl
end
lemma cast_add (h : m ∣ n) (a b : zmod n) : ((a + b : zmod n) : R) = a + b :=
begin
casesI n,
{ apply int.cast_add },
simp only [coe_coe],
symmetry,
erw [fin.coe_add, ← nat.cast_add, ← sub_eq_zero, ← nat.cast_sub (nat.mod_le _ _),
@char_p.cast_eq_zero_iff R _ m],
exact dvd_trans h (nat.dvd_sub_mod _),
end
lemma cast_mul (h : m ∣ n) (a b : zmod n) : ((a * b : zmod n) : R) = a * b :=
begin
casesI n,
{ apply int.cast_mul },
simp only [coe_coe],
symmetry,
erw [fin.coe_mul, ← nat.cast_mul, ← sub_eq_zero, ← nat.cast_sub (nat.mod_le _ _),
@char_p.cast_eq_zero_iff R _ m],
exact dvd_trans h (nat.dvd_sub_mod _),
end
/-- The canonical ring homomorphism from `zmod n` to a ring of characteristic `n`. -/
def cast_hom (h : m ∣ n) (R : Type*) [ring R] [char_p R m] : zmod n →+* R :=
{ to_fun := coe,
map_zero' := cast_zero,
map_one' := cast_one h,
map_add' := cast_add h,
map_mul' := cast_mul h }
@[simp] lemma cast_hom_apply {h : m ∣ n} (i : zmod n) : cast_hom h R i = i := rfl
@[simp, norm_cast]
lemma cast_sub (h : m ∣ n) (a b : zmod n) : ((a - b : zmod n) : R) = a - b :=
(cast_hom h R).map_sub a b
@[simp, norm_cast]
lemma cast_neg (h : m ∣ n) (a : zmod n) : ((-a : zmod n) : R) = -a :=
(cast_hom h R).map_neg a
@[simp, norm_cast]
lemma cast_pow (h : m ∣ n) (a : zmod n) (k : ℕ) : ((a ^ k : zmod n) : R) = a ^ k :=
(cast_hom h R).map_pow a k
@[simp, norm_cast]
lemma cast_nat_cast (h : m ∣ n) (k : ℕ) : ((k : zmod n) : R) = k :=
(cast_hom h R).map_nat_cast k
@[simp, norm_cast]
lemma cast_int_cast (h : m ∣ n) (k : ℤ) : ((k : zmod n) : R) = k :=
(cast_hom h R).map_int_cast k
end char_dvd
section char_eq
/-! Some specialised simp lemmas which apply when `R` has characteristic `n`. -/
variable [char_p R n]
@[simp] lemma cast_one' : ((1 : zmod n) : R) = 1 :=
cast_one (dvd_refl _)
@[simp] lemma cast_add' (a b : zmod n) : ((a + b : zmod n) : R) = a + b :=
cast_add (dvd_refl _) a b
@[simp] lemma cast_mul' (a b : zmod n) : ((a * b : zmod n) : R) = a * b :=
cast_mul (dvd_refl _) a b
@[simp] lemma cast_sub' (a b : zmod n) : ((a - b : zmod n) : R) = a - b :=
cast_sub (dvd_refl _) a b
@[simp] lemma cast_pow' (a : zmod n) (k : ℕ) : ((a ^ k : zmod n) : R) = a ^ k :=
cast_pow (dvd_refl _) a k
@[simp, norm_cast]
lemma cast_nat_cast' (k : ℕ) : ((k : zmod n) : R) = k :=
cast_nat_cast (dvd_refl _) k
@[simp, norm_cast]
lemma cast_int_cast' (k : ℤ) : ((k : zmod n) : R) = k :=
cast_int_cast (dvd_refl _) k
instance (R : Type*) [comm_ring R] [char_p R n] : algebra (zmod n) R :=
(zmod.cast_hom (dvd_refl n) R).to_algebra
variables (R)
lemma cast_hom_injective : function.injective (zmod.cast_hom (dvd_refl n) R) :=
begin
rw ring_hom.injective_iff,
intro x,
obtain ⟨k, rfl⟩ := zmod.int_cast_surjective x,
rw [ring_hom.map_int_cast, char_p.int_cast_eq_zero_iff R n, char_p.int_cast_eq_zero_iff (zmod n) n],
exact id
end
lemma cast_hom_bijective [fintype R] (h : fintype.card R = n) :
function.bijective (zmod.cast_hom (dvd_refl n) R) :=
begin
haveI : fact (0 < n) :=
begin
rw [pos_iff_ne_zero],
unfreezingI { rintro rfl },
exact fintype.card_eq_zero_iff.mp h 0
end,
rw [fintype.bijective_iff_injective_and_card, zmod.card, h, eq_self_iff_true, and_true],
apply zmod.cast_hom_injective
end
/-- The unique ring isomorphism between `zmod n` and a ring `R`
of characteristic `n` and cardinality `n`. -/
noncomputable def ring_equiv [fintype R] (h : fintype.card R = n) : zmod n ≃+* R :=
ring_equiv.of_bijective _ (zmod.cast_hom_bijective R h)
end char_eq
end universal_property
lemma int_coe_eq_int_coe_iff (a b : ℤ) (c : ℕ) :
(a : zmod c) = (b : zmod c) ↔ a ≡ b [ZMOD c] :=
char_p.int_coe_eq_int_coe_iff (zmod c) c a b
lemma nat_coe_eq_nat_coe_iff (a b c : ℕ) :
(a : zmod c) = (b : zmod c) ↔ a ≡ b [MOD c] :=
begin
convert zmod.int_coe_eq_int_coe_iff a b c,
simp [nat.modeq.modeq_iff_dvd, int.modeq.modeq_iff_dvd],
end
lemma int_coe_zmod_eq_zero_iff_dvd (a : ℤ) (b : ℕ) : (a : zmod b) = 0 ↔ (b : ℤ) ∣ a :=
begin
change (a : zmod b) = ((0 : ℤ) : zmod b) ↔ (b : ℤ) ∣ a,
rw [zmod.int_coe_eq_int_coe_iff, int.modeq.modeq_zero_iff],
end
lemma nat_coe_zmod_eq_zero_iff_dvd (a b : ℕ) : (a : zmod b) = 0 ↔ b ∣ a :=
begin
change (a : zmod b) = ((0 : ℕ) : zmod b) ↔ b ∣ a,
rw [zmod.nat_coe_eq_nat_coe_iff, nat.modeq.modeq_zero_iff],
end
@[push_cast, simp]
lemma cast_mod_int (a : ℤ) (b : ℕ) : ((a % b : ℤ) : zmod b) = (a : zmod b) :=
begin
rw zmod.int_coe_eq_int_coe_iff,
apply int.modeq.mod_modeq,
end
local attribute [semireducible] int.nonneg
@[simp] lemma coe_to_nat (p : ℕ) :
∀ {z : ℤ} (h : 0 ≤ z), (z.to_nat : zmod p) = z
| (n : ℕ) h := by simp only [int.cast_coe_nat, int.to_nat_coe_nat]
| -[1+n] h := false.elim h
lemma val_injective (n : ℕ) [fact (0 < n)] :
function.injective (zmod.val : zmod n → ℕ) :=
begin
casesI n,
{ exfalso, exact nat.not_lt_zero 0 ‹_› },
assume a b h,
ext,
exact h
end
lemma val_one_eq_one_mod (n : ℕ) : (1 : zmod n).val = 1 % n :=
by rw [← nat.cast_one, val_cast_nat]
lemma val_one (n : ℕ) [fact (1 < n)] : (1 : zmod n).val = 1 :=
by { rw val_one_eq_one_mod, exact nat.mod_eq_of_lt ‹1 < n› }
lemma val_add {n : ℕ} [fact (0 < n)] (a b : zmod n) : (a + b).val = (a.val + b.val) % n :=
begin
casesI n,
{ exfalso, exact nat.not_lt_zero 0 ‹0 < 0› },
{ apply fin.val_add }
end
lemma val_mul {n : ℕ} (a b : zmod n) : (a * b).val = (a.val * b.val) % n :=
begin
cases n,
{ rw nat.mod_zero, apply int.nat_abs_mul },
{ apply fin.val_mul }
end
instance nontrivial (n : ℕ) [fact (1 < n)] : nontrivial (zmod n) :=
⟨⟨0, 1, assume h, zero_ne_one $
calc 0 = (0 : zmod n).val : by rw val_zero
... = (1 : zmod n).val : congr_arg zmod.val h
... = 1 : val_one n ⟩⟩
/-- The inversion on `zmod n`.
It is setup in such a way that `a * a⁻¹` is equal to `gcd a.val n`.
In particular, if `a` is coprime to `n`, and hence a unit, `a * a⁻¹ = 1`. -/
def inv : Π (n : ℕ), zmod n → zmod n
| 0 i := int.sign i
| (n+1) i := nat.gcd_a i.val (n+1)
instance (n : ℕ) : has_inv (zmod n) := ⟨inv n⟩
lemma inv_zero : ∀ (n : ℕ), (0 : zmod n)⁻¹ = 0
| 0 := int.sign_zero
| (n+1) := show (nat.gcd_a _ (n+1) : zmod (n+1)) = 0,
by { rw val_zero, unfold nat.gcd_a nat.xgcd nat.xgcd_aux, refl }
lemma mul_inv_eq_gcd {n : ℕ} (a : zmod n) :
a * a⁻¹ = nat.gcd a.val n :=
begin
cases n,
{ calc a * a⁻¹ = a * int.sign a : rfl
... = a.nat_abs : by rw [int.mul_sign, int.nat_cast_eq_coe_nat]
... = a.val.gcd 0 : by rw nat.gcd_zero_right; refl },
{ set k := n.succ,
calc a * a⁻¹ = a * a⁻¹ + k * nat.gcd_b (val a) k : by rw [cast_self, zero_mul, add_zero]
... = ↑(↑a.val * nat.gcd_a (val a) k + k * nat.gcd_b (val a) k) :
by { push_cast, rw cast_val, refl }
... = nat.gcd a.val k : (congr_arg coe (nat.gcd_eq_gcd_ab a.val k)).symm, }
end
@[simp] lemma cast_mod_nat (n : ℕ) (a : ℕ) : ((a % n : ℕ) : zmod n) = a :=
by conv {to_rhs, rw ← nat.mod_add_div a n}; simp
lemma eq_iff_modeq_nat (n : ℕ) {a b : ℕ} : (a : zmod n) = b ↔ a ≡ b [MOD n] :=
begin
cases n,
{ simp only [nat.modeq, int.coe_nat_inj', nat.mod_zero, int.nat_cast_eq_coe_nat], },
{ rw [fin.ext_iff, nat.modeq, ← val_cast_nat, ← val_cast_nat], exact iff.rfl, }
end
lemma coe_mul_inv_eq_one {n : ℕ} (x : ℕ) (h : nat.coprime x n) :
(x * x⁻¹ : zmod n) = 1 :=
begin
rw [nat.coprime, nat.gcd_comm, nat.gcd_rec] at h,
rw [mul_inv_eq_gcd, val_cast_nat, h, nat.cast_one],
end
/-- `unit_of_coprime` makes an element of `units (zmod n)` given
a natural number `x` and a proof that `x` is coprime to `n` -/
def unit_of_coprime {n : ℕ} (x : ℕ) (h : nat.coprime x n) : units (zmod n) :=
⟨x, x⁻¹, coe_mul_inv_eq_one x h, by rw [mul_comm, coe_mul_inv_eq_one x h]⟩
@[simp] lemma cast_unit_of_coprime {n : ℕ} (x : ℕ) (h : nat.coprime x n) :
(unit_of_coprime x h : zmod n) = x := rfl
lemma val_coe_unit_coprime {n : ℕ} (u : units (zmod n)) :
nat.coprime (u : zmod n).val n :=
begin
cases n,
{ rcases int.units_eq_one_or u with rfl|rfl; exact dec_trivial },
apply nat.modeq.coprime_of_mul_modeq_one ((u⁻¹ : units (zmod (n+1))) : zmod (n+1)).val,
have := units.ext_iff.1 (mul_right_inv u),
rw [units.coe_one] at this,
rw [← eq_iff_modeq_nat, nat.cast_one, ← this], clear this,
rw [← cast_val ((u * u⁻¹ : units (zmod (n+1))) : zmod (n+1))],
rw [units.coe_mul, val_mul, cast_mod_nat],
end
@[simp] lemma inv_coe_unit {n : ℕ} (u : units (zmod n)) :
(u : zmod n)⁻¹ = (u⁻¹ : units (zmod n)) :=
begin
have := congr_arg (coe : ℕ → zmod n) (val_coe_unit_coprime u),
rw [← mul_inv_eq_gcd, nat.cast_one] at this,
let u' : units (zmod n) := ⟨u, (u : zmod n)⁻¹, this, by rwa mul_comm⟩,
have h : u = u', { apply units.ext, refl },
rw h,
refl
end
lemma mul_inv_of_unit {n : ℕ} (a : zmod n) (h : is_unit a) :
a * a⁻¹ = 1 :=
begin
rcases h with ⟨u, rfl⟩,
rw [inv_coe_unit, u.mul_inv],
end
lemma inv_mul_of_unit {n : ℕ} (a : zmod n) (h : is_unit a) :
a⁻¹ * a = 1 :=
by rw [mul_comm, mul_inv_of_unit a h]
/-- Equivalence between the units of `zmod n` and
the subtype of terms `x : zmod n` for which `x.val` is comprime to `n` -/
def units_equiv_coprime {n : ℕ} [fact (0 < n)] :
units (zmod n) ≃ {x : zmod n // nat.coprime x.val n} :=
{ to_fun := λ x, ⟨x, val_coe_unit_coprime x⟩,
inv_fun := λ x, unit_of_coprime x.1.val x.2,
left_inv := λ ⟨_, _, _, _⟩, units.ext (cast_val _),
right_inv := λ ⟨_, _⟩, by simp }
section totient
open_locale nat
@[simp] lemma card_units_eq_totient (n : ℕ) [fact (0 < n)] :
fintype.card (units (zmod n)) = φ n :=
calc fintype.card (units (zmod n)) = fintype.card {x : zmod n // x.val.coprime n} :
fintype.card_congr zmod.units_equiv_coprime
... = φ n :
begin
apply finset.card_congr (λ (a : {x : zmod n // x.val.coprime n}) _, a.1.val),
{ intro a, simp [(a : zmod n).val_lt, a.prop.symm] {contextual := tt} },
{ intros _ _ _ _ h, rw subtype.ext_iff_val, apply val_injective, exact h, },
{ intros b hb,
rw [finset.mem_filter, finset.mem_range] at hb,
refine ⟨⟨b, _⟩, finset.mem_univ _, _⟩,
{ let u := unit_of_coprime b hb.2.symm,
exact val_coe_unit_coprime u },
{ show zmod.val (b : zmod n) = b,
rw [val_cast_nat, nat.mod_eq_of_lt hb.1], } }
end
end totient
instance subsingleton_units : subsingleton (units (zmod 2)) :=
⟨λ x y, begin
cases x with x xi,
cases y with y yi,
revert x y xi yi,
exact dec_trivial
end⟩
lemma le_div_two_iff_lt_neg (n : ℕ) [hn : fact ((n : ℕ) % 2 = 1)]
{x : zmod n} (hx0 : x ≠ 0) : x.val ≤ (n / 2 : ℕ) ↔ (n / 2 : ℕ) < (-x).val :=
begin
haveI npos : fact (0 < n) := by
{ apply (nat.eq_zero_or_pos n).resolve_left,
unfreezingI { rintro rfl },
simpa [fact] using hn, },
have hn2 : (n : ℕ) / 2 < n := nat.div_lt_of_lt_mul ((lt_mul_iff_one_lt_left npos).2 dec_trivial),
have hn2' : (n : ℕ) - n / 2 = n / 2 + 1,
{ conv {to_lhs, congr, rw [← nat.succ_sub_one n, nat.succ_sub npos]},
rw [← nat.two_mul_odd_div_two hn, two_mul, ← nat.succ_add, nat.add_sub_cancel], },
have hxn : (n : ℕ) - x.val < n,
{ rw [nat.sub_lt_iff (le_of_lt x.val_lt) (le_refl _), nat.sub_self],
rw ← zmod.cast_val x at hx0,
exact nat.pos_of_ne_zero (λ h, by simpa [h] using hx0) },
by conv {to_rhs, rw [← nat.succ_le_iff, nat.succ_eq_add_one, ← hn2', ← zero_add (- x),
← zmod.cast_self, ← sub_eq_add_neg, ← zmod.cast_val x, ← nat.cast_sub (le_of_lt x.val_lt),
zmod.val_cast_nat, nat.mod_eq_of_lt hxn, nat.sub_le_sub_left_iff (le_of_lt x.val_lt)] }
end
lemma ne_neg_self (n : ℕ) [hn : fact ((n : ℕ) % 2 = 1)] {a : zmod n} (ha : a ≠ 0) : a ≠ -a :=
λ h, have a.val ≤ n / 2 ↔ (n : ℕ) / 2 < (-a).val := le_div_two_iff_lt_neg n ha,
by rwa [← h, ← not_lt, not_iff_self] at this
lemma neg_one_ne_one {n : ℕ} [fact (2 < n)] :
(-1 : zmod n) ≠ 1 :=
char_p.neg_one_ne_one (zmod n) n
@[simp] lemma neg_eq_self_mod_two : ∀ (a : zmod 2), -a = a := dec_trivial
@[simp] lemma nat_abs_mod_two (a : ℤ) : (a.nat_abs : zmod 2) = a :=
begin
cases a,
{ simp only [int.nat_abs_of_nat, int.cast_coe_nat, int.of_nat_eq_coe] },
{ simp only [neg_eq_self_mod_two, nat.cast_succ, int.nat_abs, int.cast_neg_succ_of_nat] }
end
@[simp] lemma val_eq_zero : ∀ {n : ℕ} (a : zmod n), a.val = 0 ↔ a = 0
| 0 a := int.nat_abs_eq_zero
| (n+1) a := by { rw fin.ext_iff, exact iff.rfl }
lemma val_cast_of_lt {n : ℕ} {a : ℕ} (h : a < n) : (a : zmod n).val = a :=
by rw [val_cast_nat, nat.mod_eq_of_lt h]
lemma neg_val' {n : ℕ} [fact (0 < n)] (a : zmod n) : (-a).val = (n - a.val) % n :=
begin
have : ((-a).val + a.val) % n = (n - a.val + a.val) % n,
{ rw [←val_add, add_left_neg, nat.sub_add_cancel (le_of_lt a.val_lt), nat.mod_self, val_zero], },
calc (-a).val = val (-a) % n : by rw nat.mod_eq_of_lt ((-a).val_lt)
... = (n - val a) % n : nat.modeq.modeq_add_cancel_right rfl this
end
lemma neg_val {n : ℕ} [fact (0 < n)] (a : zmod n) : (-a).val = if a = 0 then 0 else n - a.val :=
begin
rw neg_val',
by_cases h : a = 0, { rw [if_pos h, h, val_zero, nat.sub_zero, nat.mod_self] },
rw if_neg h,
apply nat.mod_eq_of_lt,
apply nat.sub_lt ‹0 < n›,
contrapose! h,
rwa [nat.le_zero_iff, val_eq_zero] at h,
end
/-- `val_min_abs x` returns the integer in the same equivalence class as `x` that is closest to `0`,
The result will be in the interval `(-n/2, n/2]`. -/
def val_min_abs : Π {n : ℕ}, zmod n → ℤ
| 0 x := x
| n@(_+1) x := if x.val ≤ n / 2 then x.val else (x.val : ℤ) - n
@[simp] lemma val_min_abs_def_zero (x : zmod 0) : val_min_abs x = x := rfl
lemma val_min_abs_def_pos {n : ℕ} [fact (0 < n)] (x : zmod n) :
val_min_abs x = if x.val ≤ n / 2 then x.val else x.val - n :=
begin
casesI n,
{ exfalso, exact nat.not_lt_zero 0 ‹0 < 0› },
{ refl }
end
@[simp] lemma coe_val_min_abs : ∀ {n : ℕ} (x : zmod n), (x.val_min_abs : zmod n) = x
| 0 x := int.cast_id x
| k@(n+1) x :=
begin
rw val_min_abs_def_pos,
split_ifs,
{ rw [int.cast_coe_nat, cast_val] },
{ rw [int.cast_sub, int.cast_coe_nat, cast_val, int.cast_coe_nat, cast_self, sub_zero], }
end
lemma nat_abs_val_min_abs_le {n : ℕ} [fact (0 < n)] (x : zmod n) : x.val_min_abs.nat_abs ≤ n / 2 :=
begin
rw zmod.val_min_abs_def_pos,
split_ifs with h, { exact h },
have : (x.val - n : ℤ) ≤ 0,
{ rw [sub_nonpos, int.coe_nat_le], exact le_of_lt x.val_lt, },
rw [← int.coe_nat_le, int.of_nat_nat_abs_of_nonpos this, neg_sub],
conv_lhs { congr, rw [← nat.mod_add_div n 2, int.coe_nat_add, int.coe_nat_mul,
int.coe_nat_bit0, int.coe_nat_one] },
suffices : ((n % 2 : ℕ) + (n / 2) : ℤ) ≤ (val x),
{ rw ← sub_nonneg at this ⊢, apply le_trans this (le_of_eq _), ring },
norm_cast,
calc (n : ℕ) % 2 + n / 2 ≤ 1 + n / 2 :
nat.add_le_add_right (nat.le_of_lt_succ (nat.mod_lt _ dec_trivial)) _
... ≤ x.val :
by { rw add_comm, exact nat.succ_le_of_lt (lt_of_not_ge h) }
end
@[simp] lemma val_min_abs_zero : ∀ n, (0 : zmod n).val_min_abs = 0
| 0 := by simp only [val_min_abs_def_zero]
| (n+1) := by simp only [val_min_abs_def_pos, if_true, int.coe_nat_zero, zero_le, val_zero]
@[simp] lemma val_min_abs_eq_zero {n : ℕ} (x : zmod n) :
x.val_min_abs = 0 ↔ x = 0 :=
begin
cases n, { simp },
split,
{ simp only [val_min_abs_def_pos, int.coe_nat_succ],
split_ifs with h h; assume h0,
{ apply val_injective, rwa [int.coe_nat_eq_zero] at h0, },
{ apply absurd h0, rw sub_eq_zero, apply ne_of_lt, exact_mod_cast x.val_lt } },
{ rintro rfl, rw val_min_abs_zero }
end
lemma cast_nat_abs_val_min_abs {n : ℕ} [fact (0 < n)] (a : zmod n) :
(a.val_min_abs.nat_abs : zmod n) = if a.val ≤ (n : ℕ) / 2 then a else -a :=
begin
have : (a.val : ℤ) - n ≤ 0,
by { erw [sub_nonpos, int.coe_nat_le], exact le_of_lt a.val_lt, },
rw [zmod.val_min_abs_def_pos],
split_ifs,
{ rw [int.nat_abs_of_nat, cast_val] },
{ rw [← int.cast_coe_nat, int.of_nat_nat_abs_of_nonpos this, int.cast_neg, int.cast_sub],
rw [int.cast_coe_nat, int.cast_coe_nat, cast_self, sub_zero, cast_val], }
end
@[simp] lemma nat_abs_val_min_abs_neg {n : ℕ} (a : zmod n) :
(-a).val_min_abs.nat_abs = a.val_min_abs.nat_abs :=
begin
cases n, { simp only [int.nat_abs_neg, val_min_abs_def_zero], },
by_cases ha0 : a = 0, { rw [ha0, neg_zero] },
by_cases haa : -a = a, { rw [haa] },
suffices hpa : (n+1 : ℕ) - a.val ≤ (n+1) / 2 ↔ (n+1 : ℕ) / 2 < a.val,
{ rw [val_min_abs_def_pos, val_min_abs_def_pos],
rw ← not_le at hpa,
simp only [if_neg ha0, neg_val, hpa, int.coe_nat_sub (le_of_lt a.val_lt)],
split_ifs,
all_goals { rw [← int.nat_abs_neg], congr' 1, ring } },
suffices : (((n+1 : ℕ) % 2) + 2 * ((n + 1) / 2)) - a.val ≤ (n+1) / 2 ↔ (n+1 : ℕ) / 2 < a.val,
by rwa [nat.mod_add_div] at this,
suffices : (n + 1) % 2 + (n + 1) / 2 ≤ val a ↔ (n + 1) / 2 < val a,
by rw [nat.sub_le_iff, two_mul, ← add_assoc, nat.add_sub_cancel, this],
cases (n + 1 : ℕ).mod_two_eq_zero_or_one with hn0 hn1,
{ split,
{ assume h,
apply lt_of_le_of_ne (le_trans (nat.le_add_left _ _) h),
contrapose! haa,
rw [← zmod.cast_val a, ← haa, neg_eq_iff_add_eq_zero, ← nat.cast_add],
rw [char_p.cast_eq_zero_iff (zmod (n+1)) (n+1)],
rw [← two_mul, ← zero_add (2 * _), ← hn0, nat.mod_add_div] },
{ rw [hn0, zero_add], exact le_of_lt } },
{ rw [hn1, add_comm, nat.succ_le_iff] }
end
lemma val_eq_ite_val_min_abs {n : ℕ} [fact (0 < n)] (a : zmod n) :
(a.val : ℤ) = a.val_min_abs + if a.val ≤ n / 2 then 0 else n :=
by { rw [zmod.val_min_abs_def_pos], split_ifs; simp only [add_zero, sub_add_cancel] }
lemma prime_ne_zero (p q : ℕ) [hp : fact p.prime] [hq : fact q.prime] (hpq : p ≠ q) :
(q : zmod p) ≠ 0 :=
by rwa [← nat.cast_zero, ne.def, eq_iff_modeq_nat, nat.modeq.modeq_zero_iff,
← hp.coprime_iff_not_dvd, nat.coprime_primes hp hq]
end zmod
namespace zmod
variables (p : ℕ) [fact p.prime]
private lemma mul_inv_cancel_aux (a : zmod p) (h : a ≠ 0) : a * a⁻¹ = 1 :=
begin
obtain ⟨k, rfl⟩ := nat_cast_surjective a,
apply coe_mul_inv_eq_one,
apply nat.coprime.symm,
rwa [nat.prime.coprime_iff_not_dvd ‹p.prime›, ← char_p.cast_eq_zero_iff (zmod p)]
end
/-- Field structure on `zmod p` if `p` is prime. -/
instance : field (zmod p) :=
{ mul_inv_cancel := mul_inv_cancel_aux p,
inv_zero := inv_zero p,
.. zmod.comm_ring p,
.. zmod.has_inv p,
.. zmod.nontrivial p }
end zmod
lemma ring_hom.ext_zmod {n : ℕ} {R : Type*} [semiring R] (f g : (zmod n) →+* R) : f = g :=
begin
ext a,
obtain ⟨k, rfl⟩ := zmod.int_cast_surjective a,
let φ : ℤ →+* R := f.comp (int.cast_ring_hom (zmod n)),
let ψ : ℤ →+* R := g.comp (int.cast_ring_hom (zmod n)),
show φ k = ψ k,
rw φ.ext_int ψ,
end
namespace zmod
variables {n : ℕ} {R : Type*}
instance subsingleton_ring_hom [semiring R] : subsingleton ((zmod n) →+* R) :=
⟨ring_hom.ext_zmod⟩
instance subsingleton_ring_equiv [semiring R] : subsingleton (zmod n ≃+* R) :=
⟨λ f g, by { rw ring_equiv.coe_ring_hom_inj_iff, apply ring_hom.ext_zmod _ _ }⟩
lemma ring_hom_surjective [ring R] (f : R →+* (zmod n)) :
function.surjective f :=
begin
intros k,
rcases zmod.int_cast_surjective k with ⟨n, rfl⟩,
refine ⟨n, f.map_int_cast n⟩
end
lemma ring_hom_eq_of_ker_eq [comm_ring R] (f g : R →+* (zmod n))
(h : f.ker = g.ker) : f = g :=
by rw [← f.lift_of_surjective_comp (zmod.ring_hom_surjective f) g (le_of_eq h),
ring_hom.ext_zmod (f.lift_of_surjective _ _ _) (ring_hom.id _),
ring_hom.id_comp]
end zmod
|
c350376f1d88a7c23b3292c44c2d6b06ddf1e9b5 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/tactic/norm_num.lean | 9da27cf51910fe19ca6349d60415082e10ad1bf7 | [] | 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 | 25,188 | lean | /-
Copyright (c) 2017 Simon Hudon All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Mario Carneiro
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.rat.cast
import Mathlib.data.rat.meta_defs
import Mathlib.PostPort
universes u_1 u
namespace Mathlib
/-!
# `norm_num`
Evaluating arithmetic expressions including `*`, `+`, `-`, `^`, `≤`.
-/
namespace tactic
/-- Reflexivity conversion: given `e` returns `(e, ⊢ e = e)` -/
/-- Transitivity conversion: given two conversions (which take an
expression `e` and returns `(e', ⊢ e = e')`), produces another
conversion that combines them with transitivity, treating failures
as reflexivity conversions. -/
namespace instance_cache
/-- Faster version of `mk_app ``bit0 [e]`. -/
/-- Faster version of `mk_app ``bit1 [e]`. -/
end instance_cache
end tactic
namespace norm_num
theorem subst_into_add {α : Type u_1} [Add α] (l : α) (r : α) (tl : α) (tr : α) (t : α) (prl : l = tl) (prr : r = tr) (prt : tl + tr = t) : l + r = t :=
eq.mpr (id (Eq._oldrec (Eq.refl (l + r = t)) prl))
(eq.mpr (id (Eq._oldrec (Eq.refl (tl + r = t)) prr))
(eq.mpr (id (Eq._oldrec (Eq.refl (tl + tr = t)) prt)) (Eq.refl t)))
theorem subst_into_mul {α : Type u_1} [Mul α] (l : α) (r : α) (tl : α) (tr : α) (t : α) (prl : l = tl) (prr : r = tr) (prt : tl * tr = t) : l * r = t :=
eq.mpr (id (Eq._oldrec (Eq.refl (l * r = t)) prl))
(eq.mpr (id (Eq._oldrec (Eq.refl (tl * r = t)) prr))
(eq.mpr (id (Eq._oldrec (Eq.refl (tl * tr = t)) prt)) (Eq.refl t)))
theorem subst_into_neg {α : Type u_1} [Neg α] (a : α) (ta : α) (t : α) (pra : a = ta) (prt : -ta = t) : -a = t := sorry
/-- The result type of `match_numeral`, either `0`, `1`, or a top level
decomposition of `bit0 e` or `bit1 e`. The `other` case means it is not a numeral. -/
/-- Unfold the top level constructor of the numeral expression. -/
theorem zero_succ {α : Type u_1} [semiring α] : 0 + 1 = 1 :=
zero_add 1
theorem one_succ {α : Type u_1} [semiring α] : 1 + 1 = bit0 1 :=
rfl
theorem bit0_succ {α : Type u_1} [semiring α] (a : α) : bit0 a + 1 = bit1 a :=
rfl
theorem bit1_succ {α : Type u_1} [semiring α] (a : α) (b : α) (h : a + 1 = b) : bit1 a + 1 = bit0 b := sorry
/-- Given `a`, `b` natural numerals, proves `⊢ a + 1 = b`, assuming that this is provable.
(It may prove garbage instead of failing if `a + 1 = b` is false.) -/
theorem zero_adc {α : Type u_1} [semiring α] (a : α) (b : α) (h : a + 1 = b) : 0 + a + 1 = b :=
eq.mpr (id (Eq._oldrec (Eq.refl (0 + a + 1 = b)) (zero_add a))) h
theorem adc_zero {α : Type u_1} [semiring α] (a : α) (b : α) (h : a + 1 = b) : a + 0 + 1 = b :=
eq.mpr (id (Eq._oldrec (Eq.refl (a + 0 + 1 = b)) (add_zero a))) h
theorem one_add {α : Type u_1} [semiring α] (a : α) (b : α) (h : a + 1 = b) : 1 + a = b :=
eq.mpr (id (Eq._oldrec (Eq.refl (1 + a = b)) (add_comm 1 a))) h
theorem add_bit0_bit0 {α : Type u_1} [semiring α] (a : α) (b : α) (c : α) (h : a + b = c) : bit0 a + bit0 b = bit0 c := sorry
theorem add_bit0_bit1 {α : Type u_1} [semiring α] (a : α) (b : α) (c : α) (h : a + b = c) : bit0 a + bit1 b = bit1 c := sorry
theorem add_bit1_bit0 {α : Type u_1} [semiring α] (a : α) (b : α) (c : α) (h : a + b = c) : bit1 a + bit0 b = bit1 c := sorry
theorem add_bit1_bit1 {α : Type u_1} [semiring α] (a : α) (b : α) (c : α) (h : a + b + 1 = c) : bit1 a + bit1 b = bit0 c := sorry
theorem adc_one_one {α : Type u_1} [semiring α] : 1 + 1 + 1 = bit1 1 :=
rfl
theorem adc_bit0_one {α : Type u_1} [semiring α] (a : α) (b : α) (h : a + 1 = b) : bit0 a + 1 + 1 = bit0 b := sorry
theorem adc_one_bit0 {α : Type u_1} [semiring α] (a : α) (b : α) (h : a + 1 = b) : 1 + bit0 a + 1 = bit0 b := sorry
theorem adc_bit1_one {α : Type u_1} [semiring α] (a : α) (b : α) (h : a + 1 = b) : bit1 a + 1 + 1 = bit1 b := sorry
theorem adc_one_bit1 {α : Type u_1} [semiring α] (a : α) (b : α) (h : a + 1 = b) : 1 + bit1 a + 1 = bit1 b := sorry
theorem adc_bit0_bit0 {α : Type u_1} [semiring α] (a : α) (b : α) (c : α) (h : a + b = c) : bit0 a + bit0 b + 1 = bit1 c := sorry
theorem adc_bit1_bit0 {α : Type u_1} [semiring α] (a : α) (b : α) (c : α) (h : a + b + 1 = c) : bit1 a + bit0 b + 1 = bit0 c := sorry
theorem adc_bit0_bit1 {α : Type u_1} [semiring α] (a : α) (b : α) (c : α) (h : a + b + 1 = c) : bit0 a + bit1 b + 1 = bit0 c := sorry
theorem adc_bit1_bit1 {α : Type u_1} [semiring α] (a : α) (b : α) (c : α) (h : a + b + 1 = c) : bit1 a + bit1 b + 1 = bit1 c := sorry
/-- Given `a`,`b`,`r` natural numerals, proves `⊢ a + b = r`. -/
/-- Given `a`,`b`,`r` natural numerals, proves `⊢ a + b + 1 = r`. -/
/-- Given `a`,`b` natural numerals, returns `(r, ⊢ a + b = r)`. -/
theorem bit0_mul {α : Type u_1} [semiring α] (a : α) (b : α) (c : α) (h : a * b = c) : bit0 a * b = bit0 c := sorry
theorem mul_bit0' {α : Type u_1} [semiring α] (a : α) (b : α) (c : α) (h : a * b = c) : a * bit0 b = bit0 c := sorry
theorem mul_bit0_bit0 {α : Type u_1} [semiring α] (a : α) (b : α) (c : α) (h : a * b = c) : bit0 a * bit0 b = bit0 (bit0 c) :=
bit0_mul a (bit0 b) (bit0 c) (mul_bit0' a b c h)
theorem mul_bit1_bit1 {α : Type u_1} [semiring α] (a : α) (b : α) (c : α) (d : α) (e : α) (hc : a * b = c) (hd : a + b = d) (he : bit0 c + d = e) : bit1 a * bit1 b = bit1 e := sorry
/-- Given `a`,`b` natural numerals, returns `(r, ⊢ a * b = r)`. -/
/-- Given `a` a positive natural numeral, returns `⊢ 0 < a`. -/
/-- Given `a` a rational numeral, returns `⊢ 0 < a`. -/
/-- `match_neg (- e) = some e`, otherwise `none` -/
/-- `match_sign (- e) = inl e`, `match_sign 0 = inr ff`, otherwise `inr tt` -/
theorem ne_zero_of_pos {α : Type u_1} [ordered_add_comm_group α] (a : α) : 0 < a → a ≠ 0 :=
ne_of_gt
theorem ne_zero_neg {α : Type u_1} [add_group α] (a : α) : a ≠ 0 → -a ≠ 0 :=
mt (iff.mp neg_eq_zero)
/-- Given `a` a rational numeral, returns `⊢ a ≠ 0`. -/
theorem clear_denom_div {α : Type u_1} [division_ring α] (a : α) (b : α) (b' : α) (c : α) (d : α) (h₀ : b ≠ 0) (h₁ : b * b' = d) (h₂ : a * b' = c) : a / b * d = c :=
eq.mpr (id (Eq._oldrec (Eq.refl (a / b * d = c)) (Eq.symm h₁)))
(eq.mpr (id (Eq._oldrec (Eq.refl (a / b * (b * b') = c)) (Eq.symm (mul_assoc (a / b) b b'))))
(eq.mpr (id (Eq._oldrec (Eq.refl (a / b * b * b' = c)) (div_mul_cancel a h₀))) h₂))
/-- Given `a` nonnegative rational and `d` a natural number, returns `(b, ⊢ a * d = b)`.
(`d` should be a multiple of the denominator of `a`, so that `b` is a natural number.) -/
theorem nonneg_pos {α : Type u_1} [ordered_cancel_add_comm_monoid α] (a : α) : 0 < a → 0 ≤ a :=
le_of_lt
theorem lt_one_bit0 {α : Type u_1} [linear_ordered_semiring α] (a : α) (h : 1 ≤ a) : 1 < bit0 a :=
lt_of_lt_of_le one_lt_two (iff.mpr bit0_le_bit0 h)
theorem lt_one_bit1 {α : Type u_1} [linear_ordered_semiring α] (a : α) (h : 0 < a) : 1 < bit1 a :=
iff.mpr one_lt_bit1 h
theorem lt_bit0_bit0 {α : Type u_1} [linear_ordered_semiring α] (a : α) (b : α) : a < b → bit0 a < bit0 b :=
iff.mpr bit0_lt_bit0
theorem lt_bit0_bit1 {α : Type u_1} [linear_ordered_semiring α] (a : α) (b : α) (h : a ≤ b) : bit0 a < bit1 b :=
lt_of_le_of_lt (iff.mpr bit0_le_bit0 h) (lt_add_one (bit0 b))
theorem lt_bit1_bit0 {α : Type u_1} [linear_ordered_semiring α] (a : α) (b : α) (h : a + 1 ≤ b) : bit1 a < bit0 b := sorry
theorem lt_bit1_bit1 {α : Type u_1} [linear_ordered_semiring α] (a : α) (b : α) : a < b → bit1 a < bit1 b :=
iff.mpr bit1_lt_bit1
theorem le_one_bit0 {α : Type u_1} [linear_ordered_semiring α] (a : α) (h : 1 ≤ a) : 1 ≤ bit0 a :=
le_of_lt (lt_one_bit0 a h)
-- deliberately strong hypothesis because bit1 0 is not a numeral
theorem le_one_bit1 {α : Type u_1} [linear_ordered_semiring α] (a : α) (h : 0 < a) : 1 ≤ bit1 a :=
le_of_lt (lt_one_bit1 a h)
theorem le_bit0_bit0 {α : Type u_1} [linear_ordered_semiring α] (a : α) (b : α) : a ≤ b → bit0 a ≤ bit0 b :=
iff.mpr bit0_le_bit0
theorem le_bit0_bit1 {α : Type u_1} [linear_ordered_semiring α] (a : α) (b : α) (h : a ≤ b) : bit0 a ≤ bit1 b :=
le_of_lt (lt_bit0_bit1 a b h)
theorem le_bit1_bit0 {α : Type u_1} [linear_ordered_semiring α] (a : α) (b : α) (h : a + 1 ≤ b) : bit1 a ≤ bit0 b :=
le_of_lt (lt_bit1_bit0 a b h)
theorem le_bit1_bit1 {α : Type u_1} [linear_ordered_semiring α] (a : α) (b : α) : a ≤ b → bit1 a ≤ bit1 b :=
iff.mpr bit1_le_bit1
theorem sle_one_bit0 {α : Type u_1} [linear_ordered_semiring α] (a : α) : 1 ≤ a → 1 + 1 ≤ bit0 a :=
iff.mpr bit0_le_bit0
theorem sle_one_bit1 {α : Type u_1} [linear_ordered_semiring α] (a : α) : 1 ≤ a → 1 + 1 ≤ bit1 a :=
le_bit0_bit1 1 a
theorem sle_bit0_bit0 {α : Type u_1} [linear_ordered_semiring α] (a : α) (b : α) : a + 1 ≤ b → bit0 a + 1 ≤ bit0 b :=
le_bit1_bit0 a b
theorem sle_bit0_bit1 {α : Type u_1} [linear_ordered_semiring α] (a : α) (b : α) (h : a ≤ b) : bit0 a + 1 ≤ bit1 b :=
iff.mpr bit1_le_bit1 h
theorem sle_bit1_bit0 {α : Type u_1} [linear_ordered_semiring α] (a : α) (b : α) (h : a + 1 ≤ b) : bit1 a + 1 ≤ bit0 b :=
Eq.symm (bit1_succ a (a + 1) rfl) ▸ iff.mpr bit0_le_bit0 h
theorem sle_bit1_bit1 {α : Type u_1} [linear_ordered_semiring α] (a : α) (b : α) (h : a + 1 ≤ b) : bit1 a + 1 ≤ bit1 b :=
Eq.symm (bit1_succ a (a + 1) rfl) ▸ le_bit0_bit1 (a + 1) b h
/-- Given `a` a rational numeral, returns `⊢ 0 ≤ a`. -/
/-- Given `a` a rational numeral, returns `⊢ 1 ≤ a`. -/
/-- Given `a`,`b` natural numerals, proves `⊢ a ≤ b`. -/
/-- Given `a`,`b` natural numerals, proves `⊢ a + 1 ≤ b`. -/
/-- Given `a`,`b` natural numerals, proves `⊢ a < b`. -/
theorem clear_denom_lt {α : Type u_1} [linear_ordered_semiring α] (a : α) (a' : α) (b : α) (b' : α) (d : α) (h₀ : 0 < d) (ha : a * d = a') (hb : b * d = b') (h : a' < b') : a < b :=
lt_of_mul_lt_mul_right
(eq.mpr (id (Eq._oldrec (Eq.refl (a * d < b * d)) ha)) (eq.mpr (id (Eq._oldrec (Eq.refl (a' < b * d)) hb)) h))
(le_of_lt h₀)
/-- Given `a`,`b` nonnegative rational numerals, proves `⊢ a < b`. -/
theorem lt_neg_pos {α : Type u_1} [ordered_add_comm_group α] (a : α) (b : α) (ha : 0 < a) (hb : 0 < b) : -a < b :=
lt_trans (neg_neg_of_pos ha) hb
/-- Given `a`,`b` rational numerals, proves `⊢ a < b`. -/
theorem clear_denom_le {α : Type u_1} [linear_ordered_semiring α] (a : α) (a' : α) (b : α) (b' : α) (d : α) (h₀ : 0 < d) (ha : a * d = a') (hb : b * d = b') (h : a' ≤ b') : a ≤ b :=
le_of_mul_le_mul_right
(eq.mpr (id (Eq._oldrec (Eq.refl (a * d ≤ b * d)) ha)) (eq.mpr (id (Eq._oldrec (Eq.refl (a' ≤ b * d)) hb)) h)) h₀
/-- Given `a`,`b` nonnegative rational numerals, proves `⊢ a ≤ b`. -/
theorem le_neg_pos {α : Type u_1} [ordered_add_comm_group α] (a : α) (b : α) (ha : 0 ≤ a) (hb : 0 ≤ b) : -a ≤ b :=
le_trans (neg_nonpos_of_nonneg ha) hb
/-- Given `a`,`b` rational numerals, proves `⊢ a ≤ b`. -/
/-- Given `a`,`b` rational numerals, proves `⊢ a ≠ b`. This version tries to prove
`⊢ a < b` or `⊢ b < a`, and so is not appropriate for types without an order relation. -/
theorem nat_cast_zero {α : Type u_1} [semiring α] : ↑0 = 0 :=
nat.cast_zero
theorem nat_cast_one {α : Type u_1} [semiring α] : ↑1 = 1 :=
nat.cast_one
theorem nat_cast_bit0 {α : Type u_1} [semiring α] (a : ℕ) (a' : α) (h : ↑a = a') : ↑(bit0 a) = bit0 a' :=
h ▸ nat.cast_bit0 a
theorem nat_cast_bit1 {α : Type u_1} [semiring α] (a : ℕ) (a' : α) (h : ↑a = a') : ↑(bit1 a) = bit1 a' :=
h ▸ nat.cast_bit1 a
theorem int_cast_zero {α : Type u_1} [ring α] : ↑0 = 0 :=
int.cast_zero
theorem int_cast_one {α : Type u_1} [ring α] : ↑1 = 1 :=
int.cast_one
theorem int_cast_bit0 {α : Type u_1} [ring α] (a : ℤ) (a' : α) (h : ↑a = a') : ↑(bit0 a) = bit0 a' :=
h ▸ int.cast_bit0 a
theorem int_cast_bit1 {α : Type u_1} [ring α] (a : ℤ) (a' : α) (h : ↑a = a') : ↑(bit1 a) = bit1 a' :=
h ▸ int.cast_bit1 a
theorem rat_cast_bit0 {α : Type u_1} [division_ring α] [char_zero α] (a : ℚ) (a' : α) (h : ↑a = a') : ↑(bit0 a) = bit0 a' :=
h ▸ rat.cast_bit0 a
theorem rat_cast_bit1 {α : Type u_1} [division_ring α] [char_zero α] (a : ℚ) (a' : α) (h : ↑a = a') : ↑(bit1 a) = bit1 a' :=
h ▸ rat.cast_bit1 a
/-- Given `a' : α` a natural numeral, returns `(a : ℕ, ⊢ ↑a = a')`.
(Note that the returned value is on the left of the equality.) -/
/-- Given `a' : α` a natural numeral, returns `(a : ℤ, ⊢ ↑a = a')`.
(Note that the returned value is on the left of the equality.) -/
/-- Given `a' : α` a natural numeral, returns `(a : ℚ, ⊢ ↑a = a')`.
(Note that the returned value is on the left of the equality.) -/
theorem rat_cast_div {α : Type u_1} [division_ring α] [char_zero α] (a : ℚ) (b : ℚ) (a' : α) (b' : α) (ha : ↑a = a') (hb : ↑b = b') : ↑(a / b) = a' / b' :=
ha ▸ hb ▸ rat.cast_div a b
/-- Given `a' : α` a nonnegative rational numeral, returns `(a : ℚ, ⊢ ↑a = a')`.
(Note that the returned value is on the left of the equality.) -/
theorem int_cast_neg {α : Type u_1} [ring α] (a : ℤ) (a' : α) (h : ↑a = a') : ↑(-a) = -a' :=
h ▸ int.cast_neg a
theorem rat_cast_neg {α : Type u_1} [division_ring α] (a : ℚ) (a' : α) (h : ↑a = a') : ↑(-a) = -a' :=
h ▸ rat.cast_neg a
/-- Given `a' : α` an integer numeral, returns `(a : ℤ, ⊢ ↑a = a')`.
(Note that the returned value is on the left of the equality.) -/
/-- Given `a' : α` a rational numeral, returns `(a : ℚ, ⊢ ↑a = a')`.
(Note that the returned value is on the left of the equality.) -/
theorem nat_cast_ne {α : Type u_1} [semiring α] [char_zero α] (a : ℕ) (b : ℕ) (a' : α) (b' : α) (ha : ↑a = a') (hb : ↑b = b') (h : a ≠ b) : a' ≠ b' :=
ha ▸ hb ▸ mt (iff.mp nat.cast_inj) h
theorem int_cast_ne {α : Type u_1} [ring α] [char_zero α] (a : ℤ) (b : ℤ) (a' : α) (b' : α) (ha : ↑a = a') (hb : ↑b = b') (h : a ≠ b) : a' ≠ b' :=
ha ▸ hb ▸ mt (iff.mp int.cast_inj) h
theorem rat_cast_ne {α : Type u_1} [division_ring α] [char_zero α] (a : ℚ) (b : ℚ) (a' : α) (b' : α) (ha : ↑a = a') (hb : ↑b = b') (h : a ≠ b) : a' ≠ b' :=
ha ▸ hb ▸ mt (iff.mp rat.cast_inj) h
/-- Given `a`,`b` rational numerals, proves `⊢ a ≠ b`. Currently it tries two methods:
* Prove `⊢ a < b` or `⊢ b < a`, if the base type has an order
* Embed `↑(a':ℚ) = a` and `↑(b':ℚ) = b`, and then prove `a' ≠ b'`.
This requires that the base type be `char_zero`, and also that it be a `division_ring`
so that the coercion from `ℚ` is well defined.
We may also add coercions to `ℤ` and `ℕ` as well in order to support `char_zero`
rings and semirings. -/
/-- Given `a` a rational numeral, returns `⊢ a ≠ 0`. -/
/-- Given `a` nonnegative rational and `d` a natural number, returns `(b, ⊢ a * d = b)`.
(`d` should be a multiple of the denominator of `a`, so that `b` is a natural number.) -/
theorem clear_denom_add {α : Type u_1} [division_ring α] (a : α) (a' : α) (b : α) (b' : α) (c : α) (c' : α) (d : α) (h₀ : d ≠ 0) (ha : a * d = a') (hb : b * d = b') (hc : c * d = c') (h : a' + b' = c') : a + b = c := sorry
/-- Given `a`,`b`,`c` nonnegative rational numerals, returns `⊢ a + b = c`. -/
theorem add_pos_neg_pos {α : Type u_1} [add_group α] (a : α) (b : α) (c : α) (h : c + b = a) : a + -b = c := sorry
theorem add_pos_neg_neg {α : Type u_1} [add_group α] (a : α) (b : α) (c : α) (h : c + a = b) : a + -b = -c := sorry
theorem add_neg_pos_pos {α : Type u_1} [add_group α] (a : α) (b : α) (c : α) (h : a + c = b) : -a + b = c := sorry
theorem add_neg_pos_neg {α : Type u_1} [add_group α] (a : α) (b : α) (c : α) (h : b + c = a) : -a + b = -c := sorry
theorem add_neg_neg {α : Type u_1} [add_group α] (a : α) (b : α) (c : α) (h : b + a = c) : -a + -b = -c := sorry
/-- Given `a`,`b`,`c` rational numerals, returns `⊢ a + b = c`. -/
/-- Given `a`,`b` rational numerals, returns `(c, ⊢ a + b = c)`. -/
theorem clear_denom_simple_nat {α : Type u_1} [division_ring α] (a : α) : 1 ≠ 0 ∧ a * 1 = a :=
{ left := one_ne_zero, right := mul_one a }
theorem clear_denom_simple_div {α : Type u_1} [division_ring α] (a : α) (b : α) (h : b ≠ 0) : b ≠ 0 ∧ a / b * b = a :=
{ left := h, right := div_mul_cancel a h }
/-- Given `a` a nonnegative rational numeral, returns `(b, c, ⊢ a * b = c)`
where `b` and `c` are natural numerals. (`b` will be the denominator of `a`.) -/
theorem clear_denom_mul {α : Type u_1} [field α] (a : α) (a' : α) (b : α) (b' : α) (c : α) (c' : α) (d₁ : α) (d₂ : α) (d : α) (ha : d₁ ≠ 0 ∧ a * d₁ = a') (hb : d₂ ≠ 0 ∧ b * d₂ = b') (hc : c * d = c') (hd : d₁ * d₂ = d) (h : a' * b' = c') : a * b = c := sorry
/-- Given `a`,`b` nonnegative rational numerals, returns `(c, ⊢ a * b = c)`. -/
theorem mul_neg_pos {α : Type u_1} [ring α] (a : α) (b : α) (c : α) (h : a * b = c) : -a * b = -c := sorry
theorem mul_pos_neg {α : Type u_1} [ring α] (a : α) (b : α) (c : α) (h : a * b = c) : a * -b = -c := sorry
theorem mul_neg_neg {α : Type u_1} [ring α] (a : α) (b : α) (c : α) (h : a * b = c) : -a * -b = c := sorry
/-- Given `a`,`b` rational numerals, returns `(c, ⊢ a * b = c)`. -/
theorem inv_neg {α : Type u_1} [division_ring α] (a : α) (b : α) (h : a⁻¹ = b) : -a⁻¹ = -b := sorry
theorem inv_one {α : Type u_1} [division_ring α] : 1⁻¹ = 1 :=
inv_one
theorem inv_one_div {α : Type u_1} [division_ring α] (a : α) : 1 / a⁻¹ = a :=
eq.mpr (id (Eq._oldrec (Eq.refl (1 / a⁻¹ = a)) (one_div a)))
(eq.mpr (id (Eq._oldrec (Eq.refl (a⁻¹⁻¹ = a)) (inv_inv' a))) (Eq.refl a))
theorem inv_div_one {α : Type u_1} [division_ring α] (a : α) : a⁻¹ = 1 / a :=
inv_eq_one_div a
theorem inv_div {α : Type u_1} [division_ring α] (a : α) (b : α) : a / b⁻¹ = b / a := sorry
/-- Given `a` a rational numeral, returns `(b, ⊢ a⁻¹ = b)`. -/
theorem div_eq {α : Type u_1} [division_ring α] (a : α) (b : α) (b' : α) (c : α) (hb : b⁻¹ = b') (h : a * b' = c) : a / b = c :=
eq.mp (Eq._oldrec (Eq.refl (a * (b⁻¹) = c)) (Eq.symm (div_eq_mul_inv a b)))
(eq.mp (Eq._oldrec (Eq.refl (a * b' = c)) (Eq.symm hb)) h)
/-- Given `a`,`b` rational numerals, returns `(c, ⊢ a / b = c)`. -/
/-- Given `a` a rational numeral, returns `(b, ⊢ -a = b)`. -/
theorem sub_pos {α : Type u_1} [add_group α] (a : α) (b : α) (b' : α) (c : α) (hb : -b = b') (h : a + b' = c) : a - b = c :=
eq.mp (Eq._oldrec (Eq.refl (a + -b = c)) (Eq.symm (sub_eq_add_neg a b)))
(eq.mp (Eq._oldrec (Eq.refl (a + b' = c)) (Eq.symm hb)) h)
theorem sub_neg {α : Type u_1} [add_group α] (a : α) (b : α) (c : α) (h : a + b = c) : a - -b = c :=
eq.mpr (id (Eq._oldrec (Eq.refl (a - -b = c)) (sub_neg_eq_add a b))) h
/-- Given `a`,`b` rational numerals, returns `(c, ⊢ a - b = c)`. -/
theorem sub_nat_pos (a : ℕ) (b : ℕ) (c : ℕ) (h : b + c = a) : a - b = c :=
h ▸ nat.add_sub_cancel_left b c
theorem sub_nat_neg (a : ℕ) (b : ℕ) (c : ℕ) (h : a + c = b) : a - b = 0 :=
nat.sub_eq_zero_of_le (h ▸ nat.le_add_right a c)
/-- Given `a : nat`,`b : nat` natural numerals, returns `(c, ⊢ a - b = c)`. -/
/-- Evaluates the basic field operations `+`,`neg`,`-`,`*`,`inv`,`/` on numerals.
Also handles nat subtraction. Does not do recursive simplification; that is,
`1 + 1 + 1` will not simplify but `2 + 1` will. This is handled by the top level
`simp` call in `norm_num.derive`. -/
theorem pow_bit0 {α : Type u} [monoid α] (a : α) (c' : α) (c : α) (b : ℕ) (h : a ^ b = c') (h₂ : c' * c' = c) : a ^ bit0 b = c := sorry
theorem pow_bit1 {α : Type u} [monoid α] (a : α) (c₁ : α) (c₂ : α) (c : α) (b : ℕ) (h : a ^ b = c₁) (h₂ : c₁ * c₁ = c₂) (h₃ : c₂ * a = c) : a ^ bit1 b = c := sorry
/-- Given `a` a rational numeral and `b : nat`, returns `(c, ⊢ a ^ b = c)`. -/
/-- Evaluates expressions of the form `a ^ b`, `monoid.pow a b` or `nat.pow a b`. -/
/-- Given `⊢ p`, returns `(true, ⊢ p = true)`. -/
/-- Given `⊢ ¬ p`, returns `(false, ⊢ p = false)`. -/
theorem not_refl_false_intro {α : Sort u_1} (a : α) : a ≠ a = False :=
eq_false_intro (not_not_intro rfl)
/-- Evaluates the inequality operations `=`,`<`,`>`,`≤`,`≥`,`≠` on numerals. -/
theorem nat_succ_eq (a : ℕ) (b : ℕ) (c : ℕ) (h₁ : a = b) (h₂ : b + 1 = c) : Nat.succ a = c :=
eq.mpr (id (Eq._oldrec (Eq.refl (Nat.succ a = c)) h₁)) h₂
/-- Evaluates the expression `nat.succ ... (nat.succ n)` where `n` is a natural numeral.
(We could also just handle `nat.succ n` here and rely on `simp` to work bottom up, but we figure
that towers of successors coming from e.g. `induction` are a common case.) -/
theorem nat_div (a : ℕ) (b : ℕ) (q : ℕ) (r : ℕ) (m : ℕ) (hm : q * b = m) (h : r + m = a) (h₂ : r < b) : a / b = q := sorry
theorem int_div (a : ℤ) (b : ℤ) (q : ℤ) (r : ℤ) (m : ℤ) (hm : q * b = m) (h : r + m = a) (h₁ : 0 ≤ r) (h₂ : r < b) : a / b = q := sorry
theorem nat_mod (a : ℕ) (b : ℕ) (q : ℕ) (r : ℕ) (m : ℕ) (hm : q * b = m) (h : r + m = a) (h₂ : r < b) : a % b = r := sorry
theorem int_mod (a : ℤ) (b : ℤ) (q : ℤ) (r : ℤ) (m : ℤ) (hm : q * b = m) (h : r + m = a) (h₁ : 0 ≤ r) (h₂ : r < b) : a % b = r := sorry
theorem int_div_neg (a : ℤ) (b : ℤ) (c' : ℤ) (c : ℤ) (h : a / b = c') (h₂ : -c' = c) : a / -b = c :=
h₂ ▸ h ▸ int.div_neg a b
theorem int_mod_neg (a : ℤ) (b : ℤ) (c : ℤ) (h : a % b = c) : a % -b = c :=
Eq.trans (int.mod_neg a b) h
/-- Given `a`,`b` numerals in `nat` or `int`,
* `prove_div_mod ic a b ff` returns `(c, ⊢ a / b = c)`
* `prove_div_mod ic a b tt` returns `(c, ⊢ a % b = c)`
-/
theorem dvd_eq_nat (a : ℕ) (b : ℕ) (c : ℕ) (p : Prop) (h₁ : b % a = c) (h₂ : c = 0 = p) : a ∣ b = p := sorry
theorem dvd_eq_int (a : ℤ) (b : ℤ) (c : ℤ) (p : Prop) (h₁ : b % a = c) (h₂ : c = 0 = p) : a ∣ b = p := sorry
/-- Evaluates some extra numeric operations on `nat` and `int`, specifically
`nat.succ`, `/` and `%`, and `∣` (divisibility). -/
/-- This version of `derive` does not fail when the input is already a numeral -/
/-- An attribute for adding additional extensions to `norm_num`. To use this attribute, put
`@[norm_num]` on a tactic of type `expr → tactic (expr × expr)`; the tactic will be called on
subterms by `norm_num`, and it is responsible for identifying that the expression is a numerical
function applied to numerals, for example `nat.fib 17`, and should return the reduced numerical
expression (which must be in `norm_num`-normal form: a natural or rational numeral, i.e. `37`,
`12 / 7` or `-(2 / 3)`, although this can be an expression in any type), and the proof that the
original expression is equal to the rewritten expression.
Failure is used to indicate that this tactic does not apply to the term. For performance reasons,
it is best to detect non-applicability as soon as possible so that the next tactic can have a go,
so generally it will start with a pattern match and then checking that the arguments to the term
are numerals or of the appropriate form, followed by proof construction, which should not fail.
Propositions are treated like any other term. The normal form for propositions is `true` or
`false`, so it should produce a proof of the form `p = true` or `p = false`. `eq_true_intro` can be
used to help here.
-/
/-- Look up the `norm_num` extensions in the cache and return a tactic extending `derive.step` with
additional reduction procedures. -/
/-- Simplify an expression bottom-up using `step` to simplify the subexpressions. -/
/-- Simplify an expression bottom-up using the default `norm_num` set to simplify the
subexpressions. -/
end norm_num
/-- Basic version of `norm_num` that does not call `simp`. It uses the provided `step` tactic
to simplify the expression; use `get_step` to get the default `norm_num` set and `derive.step` for
the basic builtin set of simplifications. -/
/-- Normalize numerical expressions. It uses the provided `step` tactic to simplify the expression;
use `get_step` to get the default `norm_num` set and `derive.step` for the basic builtin set of
simplifications. -/
namespace tactic.interactive
/-- Basic version of `norm_num` that does not call `simp`. -/
/-- Normalize numerical expressions. Supports the operations
`+` `-` `*` `/` `^` and `%` over numerical types such as
`ℕ`, `ℤ`, `ℚ`, `ℝ`, `ℂ` and some general algebraic types,
and can prove goals of the form `A = B`, `A ≠ B`, `A < B` and `A ≤ B`,
where `A` and `B` are numerical expressions.
It also has a relatively simple primality prover. -/
/-- Normalizes a numerical expression and tries to close the goal with the result. -/
/--
Normalises numerical expressions. It supports the operations `+` `-` `*` `/` `^` and `%` over
|
a24c0c7d9ca1f97329613b6833e764c32b4cfd67 | 437dc96105f48409c3981d46fb48e57c9ac3a3e4 | /src/ring_theory/power_series.lean | f9e84ec9ebe7e81fceeafbcbfdcbcd05b8811900 | [
"Apache-2.0"
] | permissive | dan-c-k/mathlib | 08efec79bd7481ee6da9cc44c24a653bff4fbe0d | 96efc220f6225bc7a5ed8349900391a33a38cc56 | refs/heads/master | 1,658,082,847,093 | 1,589,013,201,000 | 1,589,013,201,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 57,842 | lean | /-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kenny Lau
-/
import data.mv_polynomial
import ring_theory.ideal_operations
import tactic.linarith
/-!
# Formal power series
This file defines (multivariate) formal power series
and develops the basic properties of these objects.
A formal power series is to a polynomial like an infinite sum is to a finite sum.
We provide the natural inclusion from polynomials to formal power series.
## Generalities
The file starts with setting up the (semi)ring structure on multivariate power series.
`trunc n φ` truncates a formal power series to the polynomial
that has the same coefficients as φ, for all m ≤ n, and 0 otherwise.
If the constant coefficient of a formal power series is invertible,
then this formal power series is invertible.
Formal power series over a local ring form a local ring.
## Formal power series in one variable
We prove that if the ring of coefficients is an integral domain,
then formal power series in one variable form an integral domain.
The `order` of a formal power series `φ` is the multiplicity of the variable `X` in `φ`.
If the coefficients form an integral domain, then `order` is a valuation
(`order_mul`, `order_add_ge`).
## Implementation notes
In this file we define multivariate formal power series with
variables indexed by `σ` and coefficients in `α` as
mv_power_series σ α := (σ →₀ ℕ) → α.
Unfortunately there is not yet enough API to show that they are the completion
of the ring of multivariate polynomials. However, we provide most of the infrastructure
that is needed to do this. Once I-adic completion (topological or algebraic) is available
it should not be hard to fill in the details.
Formal power series in one variable are defined as
power_series α := mv_power_series unit α.
This allows us to port a lot of proofs and properties
from the multivariate case to the single variable case.
However, it means that formal power series are indexed by (unit →₀ ℕ),
which is of course canonically isomorphic to ℕ.
We then build some glue to treat formal power series as if they are indexed by ℕ.
Occasionally this leads to proofs that are uglier than expected.
-/
noncomputable theory
open_locale classical
/-- Multivariate formal power series, where `σ` is the index set of the variables
and `α` is the coefficient ring.-/
def mv_power_series (σ : Type*) (α : Type*) := (σ →₀ ℕ) → α
namespace mv_power_series
open finsupp
variables {σ : Type*} {α : Type*}
instance [inhabited α] : inhabited (mv_power_series σ α) := ⟨λ _, default _⟩
instance [has_zero α] : has_zero (mv_power_series σ α) := pi.has_zero
instance [add_monoid α] : add_monoid (mv_power_series σ α) := pi.add_monoid
instance [add_group α] : add_group (mv_power_series σ α) := pi.add_group
instance [add_comm_monoid α] : add_comm_monoid (mv_power_series σ α) := pi.add_comm_monoid
instance [add_comm_group α] : add_comm_group (mv_power_series σ α) := pi.add_comm_group
section add_monoid
variables [add_monoid α]
variables (α)
/-- The `n`th monomial with coefficient `a` as multivariate formal power series.-/
def monomial (n : σ →₀ ℕ) : α →+ mv_power_series σ α :=
{ to_fun := λ a m, if m = n then a else 0,
map_zero' := funext $ λ m, by { split_ifs; refl },
map_add' := λ a b, funext $ λ m,
show (if m = n then a + b else 0) = (if m = n then a else 0) + (if m = n then b else 0),
from if h : m = n then by simp only [if_pos h] else by simp only [if_neg h, add_zero] }
/-- The `n`th coefficient of a multivariate formal power series.-/
def coeff (n : σ →₀ ℕ) : (mv_power_series σ α) →+ α :=
{ to_fun := λ φ, φ n,
map_zero' := rfl,
map_add' := λ _ _, rfl }
variables {α}
/-- Two multivariate formal power series are equal if all their coefficients are equal.-/
@[ext] lemma ext {φ ψ} (h : ∀ (n : σ →₀ ℕ), coeff α n φ = coeff α n ψ) :
φ = ψ :=
funext h
/-- Two multivariate formal power series are equal
if and only if all their coefficients are equal.-/
lemma ext_iff {φ ψ : mv_power_series σ α} :
φ = ψ ↔ (∀ (n : σ →₀ ℕ), coeff α n φ = coeff α n ψ) :=
⟨λ h n, congr_arg (coeff α n) h, ext⟩
lemma coeff_monomial (m n : σ →₀ ℕ) (a : α) :
coeff α m (monomial α n a) = if m = n then a else 0 := rfl
@[simp] lemma coeff_monomial' (n : σ →₀ ℕ) (a : α) :
coeff α n (monomial α n a) = a := if_pos rfl
@[simp] lemma coeff_comp_monomial (n : σ →₀ ℕ) :
(coeff α n).comp (monomial α n) = add_monoid_hom.id α :=
add_monoid_hom.ext $ coeff_monomial' n
@[simp] lemma coeff_zero (n : σ →₀ ℕ) : coeff α n (0 : mv_power_series σ α) = 0 := rfl
end add_monoid
section semiring
variables [semiring α] (n : σ →₀ ℕ) (φ ψ : mv_power_series σ α)
instance : has_one (mv_power_series σ α) := ⟨monomial α (0 : σ →₀ ℕ) 1⟩
lemma coeff_one :
coeff α n (1 : mv_power_series σ α) = if n = 0 then 1 else 0 := rfl
lemma coeff_zero_one : coeff α (0 : σ →₀ ℕ) 1 = 1 :=
coeff_monomial' 0 1
instance : has_mul (mv_power_series σ α) :=
⟨λ φ ψ n, (finsupp.antidiagonal n).support.sum (λ p, φ p.1 * ψ p.2)⟩
lemma coeff_mul : coeff α n (φ * ψ) =
(finsupp.antidiagonal n).support.sum (λ p, coeff α p.1 φ * coeff α p.2 ψ) := rfl
protected lemma zero_mul : (0 : mv_power_series σ α) * φ = 0 :=
ext $ λ n, by simp [coeff_mul]
protected lemma mul_zero : φ * 0 = 0 :=
ext $ λ n, by simp [coeff_mul]
protected lemma one_mul : (1 : mv_power_series σ α) * φ = φ :=
ext $ λ n,
begin
rw [coeff_mul, finset.sum_eq_single ((0 : σ →₀ ℕ), n)];
simp [mem_antidiagonal_support, coeff_one],
show ∀ (i j : σ →₀ ℕ), i + j = n → (i = 0 → j ≠ n) →
(if i = 0 then coeff α j φ else 0) = 0,
intros i j hij h,
rw [if_neg],
contrapose! h,
simpa [h] using hij,
end
protected lemma mul_one : φ * 1 = φ :=
ext $ λ n,
begin
rw [coeff_mul, finset.sum_eq_single (n, (0 : σ →₀ ℕ))],
rotate,
{ rintros ⟨i, j⟩ hij h,
rw [coeff_one, if_neg, mul_zero],
rw mem_antidiagonal_support at hij,
contrapose! h,
simpa [h] using hij },
all_goals { simp [mem_antidiagonal_support, coeff_one] }
end
protected lemma mul_add (φ₁ φ₂ φ₃ : mv_power_series σ α) :
φ₁ * (φ₂ + φ₃) = φ₁ * φ₂ + φ₁ * φ₃ :=
ext $ λ n, by simp only [coeff_mul, mul_add, finset.sum_add_distrib, add_monoid_hom.map_add]
protected lemma add_mul (φ₁ φ₂ φ₃ : mv_power_series σ α) :
(φ₁ + φ₂) * φ₃ = φ₁ * φ₃ + φ₂ * φ₃ :=
ext $ λ n, by simp only [coeff_mul, add_mul, finset.sum_add_distrib, add_monoid_hom.map_add]
protected lemma mul_assoc (φ₁ φ₂ φ₃ : mv_power_series σ α) :
(φ₁ * φ₂) * φ₃ = φ₁ * (φ₂ * φ₃) :=
ext $ λ n,
begin
simp only [coeff_mul],
have := @finset.sum_sigma ((σ →₀ ℕ) × (σ →₀ ℕ)) α _ _ (antidiagonal n).support
(λ p, (antidiagonal (p.1)).support) (λ x, coeff α x.2.1 φ₁ * coeff α x.2.2 φ₂ * coeff α x.1.2 φ₃),
convert this.symm using 1; clear this,
{ apply finset.sum_congr rfl,
intros p hp, exact finset.sum_mul },
have := @finset.sum_sigma ((σ →₀ ℕ) × (σ →₀ ℕ)) α _ _ (antidiagonal n).support
(λ p, (antidiagonal (p.2)).support) (λ x, coeff α x.1.1 φ₁ * (coeff α x.2.1 φ₂ * coeff α x.2.2 φ₃)),
convert this.symm using 1; clear this,
{ apply finset.sum_congr rfl, intros p hp, rw finset.mul_sum },
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_antidiagonal_support] at H ⊢, finish },
{ 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_antidiagonal_support,
and_imp, prod.mk.inj_iff, add_comm, heq_iff_eq] at H₁ H₂ ⊢,
finish },
{ rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H, refine ⟨⟨(i+k, l), (i, k)⟩, _, _⟩;
{ simp only [finset.mem_sigma, mem_antidiagonal_support] at H ⊢, finish } }
end
instance : semiring (mv_power_series σ α) :=
{ mul_one := mv_power_series.mul_one,
one_mul := mv_power_series.one_mul,
mul_assoc := mv_power_series.mul_assoc,
mul_zero := mv_power_series.mul_zero,
zero_mul := mv_power_series.zero_mul,
left_distrib := mv_power_series.mul_add,
right_distrib := mv_power_series.add_mul,
.. mv_power_series.has_one,
.. mv_power_series.has_mul,
.. mv_power_series.add_comm_monoid }
end semiring
instance [comm_semiring α] : comm_semiring (mv_power_series σ α) :=
{ mul_comm := λ φ ψ, ext $ λ n, finset.sum_bij (λ p hp, p.swap)
(λ p hp, swap_mem_antidiagonal_support hp)
(λ p hp, mul_comm _ _)
(λ p q hp hq H, by simpa using congr_arg prod.swap H)
(λ p hp, ⟨p.swap, swap_mem_antidiagonal_support hp, p.swap_swap.symm⟩),
.. mv_power_series.semiring }
instance [ring α] : ring (mv_power_series σ α) :=
{ .. mv_power_series.semiring,
.. mv_power_series.add_comm_group }
instance [comm_ring α] : comm_ring (mv_power_series σ α) :=
{ .. mv_power_series.comm_semiring,
.. mv_power_series.add_comm_group }
section semiring
variables [semiring α]
lemma monomial_mul_monomial (m n : σ →₀ ℕ) (a b : α) :
monomial α m a * monomial α n b = monomial α (m + n) (a * b) :=
begin
ext k, rw [coeff_mul, coeff_monomial], split_ifs with h,
{ rw [h, finset.sum_eq_single (m,n)],
{ rw [coeff_monomial', coeff_monomial'] },
{ rintros ⟨i,j⟩ hij hne,
rw [ne.def, prod.mk.inj_iff, not_and] at hne,
by_cases H : i = m,
{ rw [coeff_monomial j n b, if_neg (hne H), mul_zero] },
{ rw [coeff_monomial, if_neg H, zero_mul] } },
{ intro H, rw finsupp.mem_antidiagonal_support at H,
exfalso, exact H rfl } },
{ rw [finset.sum_eq_zero], rintros ⟨i,j⟩ hij,
rw finsupp.mem_antidiagonal_support at hij,
by_cases H : i = m,
{ subst i, have : j ≠ n, { rintro rfl, exact h hij.symm },
{ rw [coeff_monomial j n b, if_neg this, mul_zero] } },
{ rw [coeff_monomial, if_neg H, zero_mul] } }
end
variables (σ) (α)
/-- The constant multivariate formal power series.-/
def C : α →+* mv_power_series σ α :=
{ map_one' := rfl,
map_mul' := λ a b, (monomial_mul_monomial 0 0 a b).symm,
.. monomial α (0 : σ →₀ ℕ) }
variables {σ} {α}
@[simp] lemma monomial_zero_eq_C : monomial α (0 : σ →₀ ℕ) = C σ α := rfl
lemma monomial_zero_eq_C_apply (a : α) : monomial α (0 : σ →₀ ℕ) a = C σ α a := rfl
lemma coeff_C (n : σ →₀ ℕ) (a : α) :
coeff α n (C σ α a) = if n = 0 then a else 0 := rfl
lemma coeff_zero_C (a : α) : coeff α (0 : σ →₀ℕ) (C σ α a) = a :=
coeff_monomial' 0 a
/-- The variables of the multivariate formal power series ring.-/
def X (s : σ) : mv_power_series σ α := monomial α (single s 1) 1
lemma coeff_X (n : σ →₀ ℕ) (s : σ) :
coeff α n (X s : mv_power_series σ α) = if n = (single s 1) then 1 else 0 := rfl
lemma coeff_index_single_X (s t : σ) :
coeff α (single t 1) (X s : mv_power_series σ α) = if t = s then 1 else 0 :=
by { simp only [coeff_X, single_right_inj one_ne_zero], split_ifs; refl }
@[simp] lemma coeff_index_single_self_X (s : σ) :
coeff α (single s 1) (X s : mv_power_series σ α) = 1 :=
if_pos rfl
lemma coeff_zero_X (s : σ) : coeff α (0 : σ →₀ ℕ) (X s : mv_power_series σ α) = 0 :=
by { rw [coeff_X, if_neg], intro h, exact one_ne_zero (single_eq_zero.mp h.symm) }
lemma X_def (s : σ) : X s = monomial α (single s 1) 1 := rfl
lemma X_pow_eq (s : σ) (n : ℕ) :
(X s : mv_power_series σ α)^n = monomial α (single s n) 1 :=
begin
induction n with n ih,
{ rw [pow_zero, finsupp.single_zero], refl },
{ rw [pow_succ', ih, nat.succ_eq_add_one, finsupp.single_add, X, monomial_mul_monomial, one_mul] }
end
lemma coeff_X_pow (m : σ →₀ ℕ) (s : σ) (n : ℕ) :
coeff α m ((X s : mv_power_series σ α)^n) = if m = single s n then 1 else 0 :=
by rw [X_pow_eq s n, coeff_monomial]
@[simp] lemma coeff_mul_C (n : σ →₀ ℕ) (φ : mv_power_series σ α) (a : α) :
coeff α n (φ * (C σ α a)) = (coeff α n φ) * a :=
begin
rw [coeff_mul n φ], rw [finset.sum_eq_single (n,(0 : σ →₀ ℕ))],
{ rw [coeff_C, if_pos rfl] },
{ rintro ⟨i,j⟩ hij hne,
rw finsupp.mem_antidiagonal_support at hij,
by_cases hj : j = 0,
{ subst hj, simp at *, contradiction },
{ rw [coeff_C, if_neg hj, mul_zero] } },
{ intro h, exfalso, apply h,
rw finsupp.mem_antidiagonal_support,
apply add_zero }
end
lemma coeff_zero_mul_X (φ : mv_power_series σ α) (s : σ) :
coeff α (0 : σ →₀ ℕ) (φ * X s) = 0 :=
begin
rw [coeff_mul _ φ, finset.sum_eq_zero],
rintro ⟨i,j⟩ hij,
obtain ⟨rfl, rfl⟩ : i = 0 ∧ j = 0,
{ rw finsupp.mem_antidiagonal_support at hij,
simpa using hij },
simp [coeff_zero_X]
end
variables (σ) (α)
/-- The constant coefficient of a formal power series.-/
def constant_coeff : (mv_power_series σ α) →+* α :=
{ to_fun := coeff α (0 : σ →₀ ℕ),
map_one' := coeff_zero_one,
map_mul' := λ φ ψ, by simp [coeff_mul, support_single_ne_zero],
.. coeff α (0 : σ →₀ ℕ) }
variables {σ} {α}
@[simp] lemma coeff_zero_eq_constant_coeff :
coeff α (0 : σ →₀ ℕ) = constant_coeff σ α := rfl
lemma coeff_zero_eq_constant_coeff_apply (φ : mv_power_series σ α) :
coeff α (0 : σ →₀ ℕ) φ = constant_coeff σ α φ := rfl
@[simp] lemma constant_coeff_C (a : α) : constant_coeff σ α (C σ α a) = a := rfl
@[simp] lemma constant_coeff_comp_C :
(constant_coeff σ α).comp (C σ α) = ring_hom.id α := rfl
@[simp] lemma constant_coeff_zero : constant_coeff σ α 0 = 0 := rfl
@[simp] lemma constant_coeff_one : constant_coeff σ α 1 = 1 := rfl
@[simp] lemma constant_coeff_X (s : σ) : constant_coeff σ α (X s) = 0 := coeff_zero_X s
/-- If a multivariate formal power series is invertible,
then so is its constant coefficient.-/
lemma is_unit_constant_coeff (φ : mv_power_series σ α) (h : is_unit φ) :
is_unit (constant_coeff σ α φ) :=
h.map' (constant_coeff σ α)
instance : semimodule α (mv_power_series σ α) :=
{ smul := λ a φ, C σ α a * φ,
one_smul := λ φ, one_mul _,
mul_smul := λ a b φ, by simp [ring_hom.map_mul, mul_assoc],
smul_add := λ a φ ψ, mul_add _ _ _,
smul_zero := λ a, mul_zero _,
add_smul := λ a b φ, by simp only [ring_hom.map_add, add_mul],
zero_smul := λ φ, by simp only [zero_mul, ring_hom.map_zero] }
end semiring
instance [ring α] : module α (mv_power_series σ α) :=
{ ..mv_power_series.semimodule }
instance [comm_ring α] : algebra α (mv_power_series σ α) :=
{ commutes' := λ _ _, mul_comm _ _,
smul_def' := λ c p, rfl,
.. C σ α, .. mv_power_series.module }
section map
variables {β : Type*} {γ : Type*} [semiring α] [semiring β] [semiring γ]
variables (f : α →+* β) (g : β →+* γ)
variable (σ)
/-- The map between multivariate formal power series induced by a map on the coefficients.-/
def map : mv_power_series σ α →+* mv_power_series σ β :=
{ to_fun := λ φ n, f $ coeff α n φ,
map_zero' := ext $ λ n, f.map_zero,
map_one' := ext $ λ n, show f ((coeff α n) 1) = (coeff β n) 1,
by { rw [coeff_one, coeff_one], split_ifs; simp [f.map_one, f.map_zero] },
map_add' := λ φ ψ, ext $ λ n,
show f ((coeff α n) (φ + ψ)) = f ((coeff α n) φ) + f ((coeff α n) ψ), by simp,
map_mul' := λ φ ψ, ext $ λ n, show f _ = _,
begin
rw [coeff_mul, ← finset.sum_hom _ f, coeff_mul, finset.sum_congr rfl],
rintros ⟨i,j⟩ hij, rw [f.map_mul], refl,
end }
variable {σ}
@[simp] lemma map_id : map σ (ring_hom.id α) = ring_hom.id _ := rfl
lemma map_comp : map σ (g.comp f) = (map σ g).comp (map σ f) := rfl
@[simp] lemma coeff_map (n : σ →₀ ℕ) (φ : mv_power_series σ α) :
coeff β n (map σ f φ) = f (coeff α n φ) := rfl
@[simp] lemma constant_coeff_map (φ : mv_power_series σ α) :
constant_coeff σ β (map σ f φ) = f (constant_coeff σ α φ) := rfl
end map
section trunc
variables [comm_semiring α] (n : σ →₀ ℕ)
-- Auxiliary definition for the truncation function.
def trunc_fun (φ : mv_power_series σ α) : mv_polynomial σ α :=
{ support := (n.antidiagonal.support.image prod.fst).filter (λ m, coeff α m φ ≠ 0),
to_fun := λ m, if m ≤ n then coeff α m φ else 0,
mem_support_to_fun := λ m,
begin
suffices : m ∈ finset.image prod.fst ((antidiagonal n).support) ↔ m ≤ n,
{ rw [finset.mem_filter, this], split,
{ intro h, rw [if_pos h.1], exact h.2 },
{ intro h, split_ifs at h with H H,
{ exact ⟨H, h⟩ },
{ exfalso, exact h rfl } } },
rw finset.mem_image, split,
{ rintros ⟨⟨i,j⟩, h, rfl⟩ s,
rw finsupp.mem_antidiagonal_support at h,
rw ← h, exact nat.le_add_right _ _ },
{ intro h, refine ⟨(m, n-m), _, rfl⟩,
rw finsupp.mem_antidiagonal_support, ext s, exact nat.add_sub_of_le (h s) }
end }
variable (α)
/-- The `n`th truncation of a multivariate formal power series to a multivariate polynomial -/
def trunc : mv_power_series σ α →+ mv_polynomial σ α :=
{ to_fun := trunc_fun n,
map_zero' := mv_polynomial.ext _ _ $ λ m, by { change ite _ _ _ = _, split_ifs; refl },
map_add' := λ φ ψ, mv_polynomial.ext _ _ $ λ m,
begin
rw mv_polynomial.coeff_add,
change ite _ _ _ = ite _ _ _ + ite _ _ _,
split_ifs with H, {refl}, {rw [zero_add]}
end }
variable {α}
lemma coeff_trunc (m : σ →₀ ℕ) (φ : mv_power_series σ α) :
mv_polynomial.coeff m (trunc α n φ) =
if m ≤ n then coeff α m φ else 0 := rfl
@[simp] lemma trunc_one : trunc α n 1 = 1 :=
mv_polynomial.ext _ _ $ λ m,
begin
rw [coeff_trunc, coeff_one],
split_ifs with H H' H',
{ subst m, erw mv_polynomial.coeff_C 0, simp },
{ symmetry, erw mv_polynomial.coeff_monomial, convert if_neg (ne.elim (ne.symm H')), },
{ symmetry, erw mv_polynomial.coeff_monomial, convert if_neg _,
intro H', apply H, subst m, intro s, exact nat.zero_le _ }
end
@[simp] lemma trunc_C (a : α) : trunc α n (C σ α a) = mv_polynomial.C a :=
mv_polynomial.ext _ _ $ λ m,
begin
rw [coeff_trunc, coeff_C, mv_polynomial.coeff_C],
split_ifs with H; refl <|> try {simp * at *},
exfalso, apply H, subst m, intro s, exact nat.zero_le _
end
end trunc
section comm_semiring
variable [comm_semiring α]
lemma X_pow_dvd_iff {s : σ} {n : ℕ} {φ : mv_power_series σ α} :
(X s : mv_power_series σ α)^n ∣ φ ↔ ∀ m : σ →₀ ℕ, m s < n → coeff α m φ = 0 :=
begin
split,
{ rintros ⟨φ, rfl⟩ m h,
rw [coeff_mul, finset.sum_eq_zero],
rintros ⟨i,j⟩ hij, rw [coeff_X_pow, if_neg, zero_mul],
contrapose! h, subst i, rw finsupp.mem_antidiagonal_support at hij,
rw [← hij, finsupp.add_apply, finsupp.single_eq_same], exact nat.le_add_right n _ },
{ intro h, refine ⟨λ m, coeff α (m + (single s n)) φ, _⟩,
ext m, by_cases H : m - single s n + single s n = m,
{ rw [coeff_mul, finset.sum_eq_single (single s n, m - single s n)],
{ rw [coeff_X_pow, if_pos rfl, one_mul],
simpa using congr_arg (λ (m : σ →₀ ℕ), coeff α m φ) H.symm },
{ rintros ⟨i,j⟩ hij hne, rw finsupp.mem_antidiagonal_support at hij,
rw coeff_X_pow, split_ifs with hi,
{ exfalso, apply hne, rw [← hij, ← hi, prod.mk.inj_iff], refine ⟨rfl, _⟩,
ext t, simp only [nat.add_sub_cancel_left, finsupp.add_apply, finsupp.nat_sub_apply] },
{ exact zero_mul _ } },
{ intro hni, exfalso, apply hni, rwa [finsupp.mem_antidiagonal_support, add_comm] } },
{ rw [h, coeff_mul, finset.sum_eq_zero],
{ rintros ⟨i,j⟩ hij, rw finsupp.mem_antidiagonal_support at hij,
rw coeff_X_pow, split_ifs with hi,
{ exfalso, apply H, rw [← hij, hi], ext, simp, cc },
{ exact zero_mul _ } },
{ classical, contrapose! H, ext t,
by_cases hst : s = t,
{ subst t, simpa using nat.sub_add_cancel H },
{ simp [finsupp.single_apply, hst] } } } }
end
lemma X_dvd_iff {s : σ} {φ : mv_power_series σ α} :
(X s : mv_power_series σ α) ∣ φ ↔ ∀ m : σ →₀ ℕ, m s = 0 → coeff α m φ = 0 :=
begin
rw [← pow_one (X s : mv_power_series σ α), X_pow_dvd_iff],
split; intros h m hm,
{ exact h m (hm.symm ▸ zero_lt_one) },
{ exact h m (nat.eq_zero_of_le_zero $ nat.le_of_succ_le_succ hm) }
end
end comm_semiring
section ring
variables [ring α]
/-
The inverse of a multivariate formal power series is defined by
well-founded recursion on the coeffients of the inverse.
-/
/-- Auxiliary definition that unifies
the totalised inverse formal power series `(_)⁻¹` and
the inverse formal power series that depends on
an inverse of the constant coefficient `inv_of_unit`.-/
protected noncomputable def inv.aux (a : α) (φ : mv_power_series σ α) : mv_power_series σ α
| n := if n = 0 then a else
- a * n.antidiagonal.support.sum (λ (x : (σ →₀ ℕ) × (σ →₀ ℕ)),
if h : x.2 < n then coeff α x.1 φ * inv.aux x.2 else 0)
using_well_founded
{ rel_tac := λ _ _, `[exact ⟨_, finsupp.lt_wf σ⟩],
dec_tac := tactic.assumption }
lemma coeff_inv_aux (n : σ →₀ ℕ) (a : α) (φ : mv_power_series σ α) :
coeff α n (inv.aux a φ) = if n = 0 then a else
- a * n.antidiagonal.support.sum (λ (x : (σ →₀ ℕ) × (σ →₀ ℕ)),
if x.2 < n then coeff α x.1 φ * coeff α x.2 (inv.aux a φ) else 0) :=
show inv.aux a φ n = _, by { rw inv.aux, refl }
/-- A multivariate formal power series is invertible if the constant coefficient is invertible.-/
def inv_of_unit (φ : mv_power_series σ α) (u : units α) : mv_power_series σ α :=
inv.aux (↑u⁻¹) φ
lemma coeff_inv_of_unit (n : σ →₀ ℕ) (φ : mv_power_series σ α) (u : units α) :
coeff α n (inv_of_unit φ u) = if n = 0 then ↑u⁻¹ else
- ↑u⁻¹ * n.antidiagonal.support.sum (λ (x : (σ →₀ ℕ) × (σ →₀ ℕ)),
if x.2 < n then coeff α x.1 φ * coeff α x.2 (inv_of_unit φ u) else 0) :=
coeff_inv_aux n (↑u⁻¹) φ
@[simp] lemma constant_coeff_inv_of_unit (φ : mv_power_series σ α) (u : units α) :
constant_coeff σ α (inv_of_unit φ u) = ↑u⁻¹ :=
by rw [← coeff_zero_eq_constant_coeff_apply, coeff_inv_of_unit, if_pos rfl]
lemma mul_inv_of_unit (φ : mv_power_series σ α) (u : units α) (h : constant_coeff σ α φ = u) :
φ * inv_of_unit φ u = 1 :=
ext $ λ n, if H : n = 0 then by { rw H, simp [coeff_mul, support_single_ne_zero, h], }
else
begin
have : ((0 : σ →₀ ℕ), n) ∈ n.antidiagonal.support,
{ rw [finsupp.mem_antidiagonal_support, zero_add] },
rw [coeff_one, if_neg H, coeff_mul,
← finset.insert_erase this, finset.sum_insert (finset.not_mem_erase _ _),
coeff_zero_eq_constant_coeff_apply, h, coeff_inv_of_unit, if_neg H,
neg_mul_eq_neg_mul_symm, mul_neg_eq_neg_mul_symm, units.mul_inv_cancel_left,
← finset.insert_erase this, finset.sum_insert (finset.not_mem_erase _ _),
finset.insert_erase this, if_neg (not_lt_of_ge $ le_refl _), zero_add, add_comm,
← sub_eq_add_neg, sub_eq_zero, finset.sum_congr rfl],
rintros ⟨i,j⟩ hij, rw [finset.mem_erase, finsupp.mem_antidiagonal_support] at hij,
cases hij with h₁ h₂,
subst n, rw if_pos,
suffices : (0 : _) + j < i + j, {simpa},
apply add_lt_add_right,
split,
{ intro s, exact nat.zero_le _ },
{ intro H, apply h₁,
suffices : i = 0, {simp [this]},
ext1 s, exact nat.eq_zero_of_le_zero (H s) }
end
end ring
section comm_ring
variable [comm_ring α]
/-- Multivariate formal power series over a local ring form a local ring.-/
lemma is_local_ring (h : is_local_ring α) : is_local_ring (mv_power_series σ α) :=
begin
split,
{ have H : (0:α) ≠ 1 := ‹is_local_ring α›.1, contrapose! H,
simpa using congr_arg (constant_coeff σ α) H },
{ intro φ, rcases ‹is_local_ring α›.2 (constant_coeff σ α φ) with ⟨u,h⟩|⟨u,h⟩; [left, right];
{ refine is_unit_of_mul_eq_one _ _ (mul_inv_of_unit _ u _),
simpa using h } }
end
-- TODO(jmc): once adic topology lands, show that this is complete
end comm_ring
section nonzero_comm_ring
variables [nonzero_comm_ring α]
instance : nonzero_comm_ring (mv_power_series σ α) :=
{ zero_ne_one := assume h, zero_ne_one $ show (0:α) = 1, from congr_arg (constant_coeff σ α) h,
.. mv_power_series.comm_ring }
lemma X_inj {s t : σ} : (X s : mv_power_series σ α) = X t ↔ s = t :=
⟨begin
intro h, replace h := congr_arg (coeff α (single s 1)) h, rw [coeff_X, if_pos rfl, coeff_X] at h,
split_ifs at h with H,
{ rw finsupp.single_eq_single_iff at H,
cases H, { exact H.1 }, { exfalso, exact one_ne_zero H.1 } },
{ exfalso, exact one_ne_zero h }
end, congr_arg X⟩
end nonzero_comm_ring
section local_ring
variables {β : Type*} [local_ring α] [local_ring β] (f : α →+* β) [is_local_ring_hom f]
instance : local_ring (mv_power_series σ α) :=
local_of_is_local_ring $ is_local_ring ⟨zero_ne_one, local_ring.is_local⟩
instance map.is_local_ring_hom : is_local_ring_hom (map σ f) :=
⟨begin
rintros φ ⟨ψ, h⟩,
replace h := congr_arg (constant_coeff σ β) h,
rw constant_coeff_map at h,
have : is_unit (constant_coeff σ β ↑ψ) := @is_unit_constant_coeff σ β _ (↑ψ) (is_unit_unit ψ),
rw ← h at this,
rcases is_unit_of_map_unit f _ this with ⟨c, hc⟩,
exact is_unit_of_mul_eq_one φ (inv_of_unit φ c) (mul_inv_of_unit φ c hc)
end⟩
end local_ring
section field
variables [field α]
protected def inv (φ : mv_power_series σ α) : mv_power_series σ α :=
inv.aux (constant_coeff σ α φ)⁻¹ φ
instance : has_inv (mv_power_series σ α) := ⟨mv_power_series.inv⟩
lemma coeff_inv (n : σ →₀ ℕ) (φ : mv_power_series σ α) :
coeff α n (φ⁻¹) = if n = 0 then (constant_coeff σ α φ)⁻¹ else
- (constant_coeff σ α φ)⁻¹ * n.antidiagonal.support.sum (λ (x : (σ →₀ ℕ) × (σ →₀ ℕ)),
if x.2 < n then coeff α x.1 φ * coeff α x.2 (φ⁻¹) else 0) :=
coeff_inv_aux n _ φ
@[simp] lemma constant_coeff_inv (φ : mv_power_series σ α) :
constant_coeff σ α (φ⁻¹) = (constant_coeff σ α φ)⁻¹ :=
by rw [← coeff_zero_eq_constant_coeff_apply, coeff_inv, if_pos rfl]
lemma inv_eq_zero {φ : mv_power_series σ α} :
φ⁻¹ = 0 ↔ constant_coeff σ α φ = 0 :=
⟨λ h, by simpa using congr_arg (constant_coeff σ α) h,
λ h, ext $ λ n, by { rw coeff_inv, split_ifs;
simp only [h, mv_power_series.coeff_zero, zero_mul, inv_zero, neg_zero] }⟩
@[simp, priority 1100] lemma inv_of_unit_eq (φ : mv_power_series σ α) (h : constant_coeff σ α φ ≠ 0) :
inv_of_unit φ (units.mk0 _ h) = φ⁻¹ := rfl
@[simp] lemma inv_of_unit_eq' (φ : mv_power_series σ α) (u : units α) (h : constant_coeff σ α φ = u) :
inv_of_unit φ u = φ⁻¹ :=
begin
rw ← inv_of_unit_eq φ (h.symm ▸ u.ne_zero),
congr' 1, rw [units.ext_iff], exact h.symm,
end
@[simp] protected lemma mul_inv (φ : mv_power_series σ α) (h : constant_coeff σ α φ ≠ 0) :
φ * φ⁻¹ = 1 :=
by rw [← inv_of_unit_eq φ h, mul_inv_of_unit φ (units.mk0 _ h) rfl]
@[simp] protected lemma inv_mul (φ : mv_power_series σ α) (h : constant_coeff σ α φ ≠ 0) :
φ⁻¹ * φ = 1 :=
by rw [mul_comm, φ.mul_inv h]
end field
end mv_power_series
namespace mv_polynomial
open finsupp
variables {σ : Type*} {α : Type*} [comm_semiring α]
/-- The natural inclusion from multivariate polynomials into multivariate formal power series.-/
instance coe_to_mv_power_series : has_coe (mv_polynomial σ α) (mv_power_series σ α) :=
⟨λ φ n, coeff n φ⟩
@[simp, norm_cast] lemma coeff_coe (φ : mv_polynomial σ α) (n : σ →₀ ℕ) :
mv_power_series.coeff α n ↑φ = coeff n φ := rfl
@[simp, norm_cast] lemma coe_monomial (n : σ →₀ ℕ) (a : α) :
(monomial n a : mv_power_series σ α) = mv_power_series.monomial α n a :=
mv_power_series.ext $ λ m,
begin
rw [coeff_coe, coeff_monomial, mv_power_series.coeff_monomial],
split_ifs with h₁ h₂; refl <|> subst m; contradiction
end
@[simp, norm_cast] lemma coe_zero : ((0 : mv_polynomial σ α) : mv_power_series σ α) = 0 := rfl
@[simp, norm_cast] lemma coe_one : ((1 : mv_polynomial σ α) : mv_power_series σ α) = 1 :=
coe_monomial _ _
@[simp, norm_cast] lemma coe_add (φ ψ : mv_polynomial σ α) :
((φ + ψ : mv_polynomial σ α) : mv_power_series σ α) = φ + ψ := rfl
@[simp, norm_cast] lemma coe_mul (φ ψ : mv_polynomial σ α) :
((φ * ψ : mv_polynomial σ α) : mv_power_series σ α) = φ * ψ :=
mv_power_series.ext $ λ n,
by simp only [coeff_coe, mv_power_series.coeff_mul, coeff_mul]
@[simp, norm_cast] lemma coe_C (a : α) :
((C a : mv_polynomial σ α) : mv_power_series σ α) = mv_power_series.C σ α a :=
coe_monomial _ _
@[simp, norm_cast] lemma coe_X (s : σ) :
((X s : mv_polynomial σ α) : mv_power_series σ α) = mv_power_series.X s :=
coe_monomial _ _
namespace coe_to_mv_power_series
instance : is_semiring_hom (coe : mv_polynomial σ α → mv_power_series σ α) :=
{ map_zero := coe_zero,
map_one := coe_one,
map_add := coe_add,
map_mul := coe_mul }
end coe_to_mv_power_series
end mv_polynomial
/-- Formal power series over the coefficient ring `α`.-/
def power_series (α : Type*) := mv_power_series unit α
namespace power_series
open finsupp (single)
variable {α : Type*}
instance [inhabited α] : inhabited (power_series α) := by delta power_series; apply_instance
instance [add_monoid α] : add_monoid (power_series α) := by delta power_series; apply_instance
instance [add_group α] : add_group (power_series α) := by delta power_series; apply_instance
instance [add_comm_monoid α] : add_comm_monoid (power_series α) := by delta power_series; apply_instance
instance [add_comm_group α] : add_comm_group (power_series α) := by delta power_series; apply_instance
instance [semiring α] : semiring (power_series α) := by delta power_series; apply_instance
instance [comm_semiring α] : comm_semiring (power_series α) := by delta power_series; apply_instance
instance [ring α] : ring (power_series α) := by delta power_series; apply_instance
instance [comm_ring α] : comm_ring (power_series α) := by delta power_series; apply_instance
instance [nonzero_comm_ring α] : nonzero_comm_ring (power_series α) := by delta power_series; apply_instance
instance [semiring α] : semimodule α (power_series α) := by delta power_series; apply_instance
instance [ring α] : module α (power_series α) := by delta power_series; apply_instance
instance [comm_ring α] : algebra α (power_series α) := by delta power_series; apply_instance
section add_monoid
variables (α) [add_monoid α]
/-- The `n`th coefficient of a formal power series.-/
def coeff (n : ℕ) : power_series α →+ α := mv_power_series.coeff α (single () n)
/-- The `n`th monomial with coefficient `a` as formal power series.-/
def monomial (n : ℕ) : α →+ power_series α := mv_power_series.monomial α (single () n)
variables {α}
lemma coeff_def {s : unit →₀ ℕ} {n : ℕ} (h : s () = n) :
coeff α n = mv_power_series.coeff α s :=
by erw [coeff, ← h, ← finsupp.unique_single s]
/-- Two formal power series are equal if all their coefficients are equal.-/
@[ext] lemma ext {φ ψ : power_series α} (h : ∀ n, coeff α n φ = coeff α n ψ) :
φ = ψ :=
mv_power_series.ext $ λ n,
by { rw ← coeff_def, { apply h }, refl }
/-- Two formal power series are equal if all their coefficients are equal.-/
lemma ext_iff {φ ψ : power_series α} : φ = ψ ↔ (∀ n, coeff α n φ = coeff α n ψ) :=
⟨λ h n, congr_arg (coeff α n) h, ext⟩
/-- Constructor for formal power series.-/
def mk {α} (f : ℕ → α) : power_series α := λ s, f (s ())
@[simp] lemma coeff_mk (n : ℕ) (f : ℕ → α) : coeff α n (mk f) = f n :=
congr_arg f finsupp.single_eq_same
lemma coeff_monomial (m n : ℕ) (a : α) :
coeff α m (monomial α n a) = if m = n then a else 0 :=
calc coeff α m (monomial α n a) = _ : mv_power_series.coeff_monomial _ _ _
... = if m = n then a else 0 :
by { simp only [finsupp.unique_single_eq_iff], split_ifs; refl }
lemma monomial_eq_mk (n : ℕ) (a : α) :
monomial α n a = mk (λ m, if m = n then a else 0) :=
ext $ λ m, by { rw [coeff_monomial, coeff_mk] }
@[simp] lemma coeff_monomial' (n : ℕ) (a : α) :
coeff α n (monomial α n a) = a :=
by convert if_pos rfl
@[simp] lemma coeff_comp_monomial (n : ℕ) :
(coeff α n).comp (monomial α n) = add_monoid_hom.id α :=
add_monoid_hom.ext $ coeff_monomial' n
end add_monoid
section semiring
variable [semiring α]
variable (α)
/--The constant coefficient of a formal power series. -/
def constant_coeff : power_series α →+* α := mv_power_series.constant_coeff unit α
/-- The constant formal power series.-/
def C : α →+* power_series α := mv_power_series.C unit α
variable {α}
/-- The variable of the formal power series ring.-/
def X : power_series α := mv_power_series.X ()
@[simp] lemma coeff_zero_eq_constant_coeff :
coeff α 0 = constant_coeff α :=
begin
rw [constant_coeff, ← mv_power_series.coeff_zero_eq_constant_coeff, coeff_def], refl
end
lemma coeff_zero_eq_constant_coeff_apply (φ : power_series α) :
coeff α 0 φ = constant_coeff α φ :=
by rw [coeff_zero_eq_constant_coeff]; refl
@[simp] lemma monomial_zero_eq_C : monomial α 0 = C α :=
by rw [monomial, finsupp.single_zero, mv_power_series.monomial_zero_eq_C, C]
lemma monomial_zero_eq_C_apply (a : α) : monomial α 0 a = C α a :=
by simp
lemma coeff_C (n : ℕ) (a : α) :
coeff α n (C α a : power_series α) = if n = 0 then a else 0 :=
by rw [← monomial_zero_eq_C_apply, coeff_monomial]
lemma coeff_zero_C (a : α) : coeff α 0 (C α a) = a :=
by rw [← monomial_zero_eq_C_apply, coeff_monomial' 0 a]
lemma X_eq : (X : power_series α) = monomial α 1 1 := rfl
lemma coeff_X (n : ℕ) :
coeff α n (X : power_series α) = if n = 1 then 1 else 0 :=
by rw [X_eq, coeff_monomial]
lemma coeff_zero_X : coeff α 0 (X : power_series α) = 0 :=
by rw [coeff, finsupp.single_zero, X, mv_power_series.coeff_zero_X]
@[simp] lemma coeff_one_X : coeff α 1 (X : power_series α) = 1 :=
by rw [coeff_X, if_pos rfl]
lemma X_pow_eq (n : ℕ) : (X : power_series α)^n = monomial α n 1 :=
mv_power_series.X_pow_eq _ n
lemma coeff_X_pow (m n : ℕ) :
coeff α m ((X : power_series α)^n) = if m = n then 1 else 0 :=
by rw [X_pow_eq, coeff_monomial]
@[simp] lemma coeff_X_pow_self (n : ℕ) :
coeff α n ((X : power_series α)^n) = 1 :=
by rw [coeff_X_pow, if_pos rfl]
@[simp] lemma coeff_one (n : ℕ) :
coeff α n (1 : power_series α) = if n = 0 then 1 else 0 :=
calc coeff α n (1 : power_series α) = _ : mv_power_series.coeff_one _
... = if n = 0 then 1 else 0 :
by { simp only [finsupp.single_eq_zero], split_ifs; refl }
lemma coeff_zero_one : coeff α 0 (1 : power_series α) = 1 :=
coeff_zero_C 1
lemma coeff_mul (n : ℕ) (φ ψ : power_series α) :
coeff α n (φ * ψ) = (finset.nat.antidiagonal n).sum (λ p, coeff α p.1 φ * coeff α p.2 ψ) :=
begin
symmetry,
apply finset.sum_bij (λ (p : ℕ × ℕ) h, (single () p.1, single () p.2)),
{ rintros ⟨i,j⟩ hij, rw finset.nat.mem_antidiagonal at hij,
rw [finsupp.mem_antidiagonal_support, ← finsupp.single_add, hij], },
{ rintros ⟨i,j⟩ hij, refl },
{ rintros ⟨i,j⟩ ⟨k,l⟩ hij hkl,
simpa only [prod.mk.inj_iff, finsupp.unique_single_eq_iff] using id },
{ rintros ⟨f,g⟩ hfg,
refine ⟨(f (), g ()), _, _⟩,
{ rw finsupp.mem_antidiagonal_support at hfg,
rw [finset.nat.mem_antidiagonal, ← finsupp.add_apply, hfg, finsupp.single_eq_same] },
{ rw prod.mk.inj_iff, dsimp,
exact ⟨finsupp.unique_single f, finsupp.unique_single g⟩ } }
end
@[simp] lemma coeff_mul_C (n : ℕ) (φ : power_series α) (a : α) :
coeff α n (φ * (C α a)) = (coeff α n φ) * a :=
mv_power_series.coeff_mul_C _ φ a
@[simp] lemma coeff_succ_mul_X (n : ℕ) (φ : power_series α) :
coeff α (n+1) (φ * X) = coeff α n φ :=
begin
rw [coeff_mul _ φ, finset.sum_eq_single (n,1)],
{ rw [coeff_X, if_pos rfl, mul_one] },
{ rintro ⟨i,j⟩ hij hne,
by_cases hj : j = 1,
{ subst hj, simp at *, contradiction },
{ simp [coeff_X, hj] } },
{ intro h, exfalso, apply h, simp },
end
@[simp] lemma constant_coeff_C (a : α) : constant_coeff α (C α a) = a := rfl
@[simp] lemma constant_coeff_comp_C :
(constant_coeff α).comp (C α) = ring_hom.id α := rfl
@[simp] lemma constant_coeff_zero : constant_coeff α 0 = 0 := rfl
@[simp] lemma constant_coeff_one : constant_coeff α 1 = 1 := rfl
@[simp] lemma constant_coeff_X : constant_coeff α X = 0 := mv_power_series.coeff_zero_X _
lemma coeff_zero_mul_X (φ : power_series α) : coeff α 0 (φ * X) = 0 := by simp
/-- If a formal power series is invertible, then so is its constant coefficient.-/
lemma is_unit_constant_coeff (φ : power_series α) (h : is_unit φ) :
is_unit (constant_coeff α φ) :=
mv_power_series.is_unit_constant_coeff φ h
section map
variables {β : Type*} {γ : Type*} [semiring β] [semiring γ]
variables (f : α →+* β) (g : β →+* γ)
/-- The map between formal power series induced by a map on the coefficients.-/
def map : power_series α →+* power_series β :=
mv_power_series.map _ f
@[simp] lemma map_id : (map (ring_hom.id α) :
power_series α → power_series α) = id := rfl
lemma map_comp : map (g.comp f) = (map g).comp (map f) := rfl
@[simp] lemma coeff_map (n : ℕ) (φ : power_series α) :
coeff β n (map f φ) = f (coeff α n φ) := rfl
end map
end semiring
section comm_semiring
variables [comm_semiring α]
lemma X_pow_dvd_iff {n : ℕ} {φ : power_series α} :
(X : power_series α)^n ∣ φ ↔ ∀ m, m < n → coeff α m φ = 0 :=
begin
convert @mv_power_series.X_pow_dvd_iff unit α _ () n φ, apply propext,
classical, split; intros h m hm,
{ rw finsupp.unique_single m, convert h _ hm },
{ apply h, simpa only [finsupp.single_eq_same] using hm }
end
lemma X_dvd_iff {φ : power_series α} :
(X : power_series α) ∣ φ ↔ constant_coeff α φ = 0 :=
begin
rw [← pow_one (X : power_series α), X_pow_dvd_iff, ← coeff_zero_eq_constant_coeff_apply],
split; intro h,
{ exact h 0 zero_lt_one },
{ intros m hm, rwa nat.eq_zero_of_le_zero (nat.le_of_succ_le_succ hm) }
end
section trunc
/-- The `n`th truncation of a formal power series to a polynomial -/
def trunc (n : ℕ) (φ : power_series α) : polynomial α :=
{ support := ((finset.nat.antidiagonal n).image prod.fst).filter (λ m, coeff α m φ ≠ 0),
to_fun := λ m, if m ≤ n then coeff α m φ else 0,
mem_support_to_fun := λ m,
begin
suffices : m ∈ ((finset.nat.antidiagonal n).image prod.fst) ↔ m ≤ n,
{ rw [finset.mem_filter, this], split,
{ intro h, rw [if_pos h.1], exact h.2 },
{ intro h, split_ifs at h with H H,
{ exact ⟨H, h⟩ },
{ exfalso, exact h rfl } } },
rw finset.mem_image, split,
{ rintros ⟨⟨i,j⟩, h, rfl⟩,
rw finset.nat.mem_antidiagonal at h,
rw ← h, exact nat.le_add_right _ _ },
{ intro h, refine ⟨(m, n-m), _, rfl⟩,
rw finset.nat.mem_antidiagonal, exact nat.add_sub_of_le h }
end }
lemma coeff_trunc (m) (n) (φ : power_series α) :
polynomial.coeff (trunc n φ) m = if m ≤ n then coeff α m φ else 0 := rfl
@[simp] lemma trunc_zero (n) : trunc n (0 : power_series α) = 0 :=
polynomial.ext $ λ m,
begin
rw [coeff_trunc, add_monoid_hom.map_zero, polynomial.coeff_zero],
split_ifs; refl
end
@[simp] lemma trunc_one (n) : trunc n (1 : power_series α) = 1 :=
polynomial.ext $ λ m,
begin
rw [coeff_trunc, coeff_one],
split_ifs with H H' H'; rw [polynomial.coeff_one],
{ subst m, rw [if_pos rfl] },
{ symmetry, exact if_neg (ne.elim (ne.symm H')) },
{ symmetry, refine if_neg _,
intro H', apply H, subst m, exact nat.zero_le _ }
end
@[simp] lemma trunc_C (n) (a : α) : trunc n (C α a) = polynomial.C a :=
polynomial.ext $ λ m,
begin
rw [coeff_trunc, coeff_C, polynomial.coeff_C],
split_ifs with H; refl <|> try {simp * at *}
end
@[simp] lemma trunc_add (n) (φ ψ : power_series α) :
trunc n (φ + ψ) = trunc n φ + trunc n ψ :=
polynomial.ext $ λ m,
begin
simp only [coeff_trunc, add_monoid_hom.map_add, polynomial.coeff_add],
split_ifs with H, {refl}, {rw [zero_add]}
end
end trunc
end comm_semiring
section ring
variables [ring α]
protected def inv.aux : α → power_series α → power_series α :=
mv_power_series.inv.aux
lemma coeff_inv_aux (n : ℕ) (a : α) (φ : power_series α) :
coeff α n (inv.aux a φ) = if n = 0 then a else
- a * (finset.nat.antidiagonal n).sum (λ (x : ℕ × ℕ),
if x.2 < n then coeff α x.1 φ * coeff α x.2 (inv.aux a φ) else 0) :=
begin
rw [coeff, inv.aux, mv_power_series.coeff_inv_aux],
simp only [finsupp.single_eq_zero],
split_ifs, {refl},
congr' 1,
symmetry,
apply finset.sum_bij (λ (p : ℕ × ℕ) h, (single () p.1, single () p.2)),
{ rintros ⟨i,j⟩ hij, rw finset.nat.mem_antidiagonal at hij,
rw [finsupp.mem_antidiagonal_support, ← finsupp.single_add, hij], },
{ rintros ⟨i,j⟩ hij,
by_cases H : j < n,
{ rw [if_pos H, if_pos], {refl},
split,
{ rintro ⟨⟩, simpa [finsupp.single_eq_same] using le_of_lt H },
{ intro hh, rw lt_iff_not_ge at H, apply H,
simpa [finsupp.single_eq_same] using hh () } },
{ rw [if_neg H, if_neg], rintro ⟨h₁, h₂⟩, apply h₂, rintro ⟨⟩,
simpa [finsupp.single_eq_same] using not_lt.1 H } },
{ rintros ⟨i,j⟩ ⟨k,l⟩ hij hkl,
simpa only [prod.mk.inj_iff, finsupp.unique_single_eq_iff] using id },
{ rintros ⟨f,g⟩ hfg,
refine ⟨(f (), g ()), _, _⟩,
{ rw finsupp.mem_antidiagonal_support at hfg,
rw [finset.nat.mem_antidiagonal, ← finsupp.add_apply, hfg, finsupp.single_eq_same] },
{ rw prod.mk.inj_iff, dsimp,
exact ⟨finsupp.unique_single f, finsupp.unique_single g⟩ } }
end
/-- A formal power series is invertible if the constant coefficient is invertible.-/
def inv_of_unit (φ : power_series α) (u : units α) : power_series α :=
mv_power_series.inv_of_unit φ u
lemma coeff_inv_of_unit (n : ℕ) (φ : power_series α) (u : units α) :
coeff α n (inv_of_unit φ u) = if n = 0 then ↑u⁻¹ else
- ↑u⁻¹ * (finset.nat.antidiagonal n).sum (λ (x : ℕ × ℕ),
if x.2 < n then coeff α x.1 φ * coeff α x.2 (inv_of_unit φ u) else 0) :=
coeff_inv_aux n ↑u⁻¹ φ
@[simp] lemma constant_coeff_inv_of_unit (φ : power_series α) (u : units α) :
constant_coeff α (inv_of_unit φ u) = ↑u⁻¹ :=
by rw [← coeff_zero_eq_constant_coeff_apply, coeff_inv_of_unit, if_pos rfl]
lemma mul_inv_of_unit (φ : power_series α) (u : units α) (h : constant_coeff α φ = u) :
φ * inv_of_unit φ u = 1 :=
mv_power_series.mul_inv_of_unit φ u $ h
end ring
section integral_domain
variable [integral_domain α]
lemma eq_zero_or_eq_zero_of_mul_eq_zero (φ ψ : power_series α) (h : φ * ψ = 0) :
φ = 0 ∨ ψ = 0 :=
begin
rw classical.or_iff_not_imp_left, intro H,
have ex : ∃ m, coeff α m φ ≠ 0, { contrapose! H, exact ext H },
let P : ℕ → Prop := λ k, coeff α k φ ≠ 0,
let m := nat.find ex,
have hm₁ : coeff α m φ ≠ 0 := nat.find_spec ex,
have hm₂ : ∀ k < m, ¬coeff α k φ ≠ 0 := λ k, nat.find_min ex,
ext n, rw (coeff α n).map_zero, apply nat.strong_induction_on n,
clear n, intros n ih,
replace h := congr_arg (coeff α (m + n)) h,
rw [add_monoid_hom.map_zero, coeff_mul, finset.sum_eq_single (m,n)] at h,
{ replace h := eq_zero_or_eq_zero_of_mul_eq_zero h,
rw or_iff_not_imp_left at h, exact h hm₁ },
{ rintro ⟨i,j⟩ hij hne,
by_cases hj : j < n, { rw [ih j hj, mul_zero] },
by_cases hi : i < m,
{ specialize hm₂ _ hi, push_neg at hm₂, rw [hm₂, zero_mul] },
rw finset.nat.mem_antidiagonal at hij,
push_neg at hi hj,
suffices : m < i,
{ have : m + n < i + j := add_lt_add_of_lt_of_le this hj,
exfalso, exact ne_of_lt this hij.symm },
contrapose! hne, have : i = m := le_antisymm hne hi, subst i, clear hi hne,
simpa [ne.def, prod.mk.inj_iff] using (add_left_inj m).mp hij },
{ contrapose!, intro h, rw finset.nat.mem_antidiagonal }
end
instance : integral_domain (power_series α) :=
{ eq_zero_or_eq_zero_of_mul_eq_zero := eq_zero_or_eq_zero_of_mul_eq_zero,
.. power_series.nonzero_comm_ring }
/-- The ideal spanned by the variable in the power series ring
over an integral domain is a prime ideal.-/
lemma span_X_is_prime : (ideal.span ({X} : set (power_series α))).is_prime :=
begin
suffices : ideal.span ({X} : set (power_series α)) = (constant_coeff α).ker,
{ rw this, exact ring_hom.ker_is_prime _ },
apply ideal.ext, intro φ,
rw [ring_hom.mem_ker, ideal.mem_span_singleton, X_dvd_iff]
end
/-- The variable of the power series ring over an integral domain is prime.-/
lemma X_prime : prime (X : power_series α) :=
begin
rw ← ideal.span_singleton_prime,
{ exact span_X_is_prime },
{ intro h, simpa using congr_arg (coeff α 1) h }
end
end integral_domain
section local_ring
variables [comm_ring α]
lemma is_local_ring (h : is_local_ring α) :
is_local_ring (power_series α) :=
mv_power_series.is_local_ring h
end local_ring
section local_ring
variables {β : Type*} [local_ring α] [local_ring β] (f : α →+* β) [is_local_ring_hom f]
instance : local_ring (power_series α) :=
mv_power_series.local_ring
instance map.is_local_ring_hom :
is_local_ring_hom (map f) :=
mv_power_series.map.is_local_ring_hom f
end local_ring
section field
variables [field α]
protected def inv : power_series α → power_series α :=
mv_power_series.inv
instance : has_inv (power_series α) := ⟨power_series.inv⟩
lemma inv_eq_inv_aux (φ : power_series α) :
φ⁻¹ = inv.aux (constant_coeff α φ)⁻¹ φ := rfl
lemma coeff_inv (n) (φ : power_series α) :
coeff α n (φ⁻¹) = if n = 0 then (constant_coeff α φ)⁻¹ else
- (constant_coeff α φ)⁻¹ * (finset.nat.antidiagonal n).sum (λ (x : ℕ × ℕ),
if x.2 < n then coeff α x.1 φ * coeff α x.2 (φ⁻¹) else 0) :=
by rw [inv_eq_inv_aux, coeff_inv_aux n (constant_coeff α φ)⁻¹ φ]
@[simp] lemma constant_coeff_inv (φ : power_series α) :
constant_coeff α (φ⁻¹) = (constant_coeff α φ)⁻¹ :=
mv_power_series.constant_coeff_inv φ
lemma inv_eq_zero {φ : power_series α} :
φ⁻¹ = 0 ↔ constant_coeff α φ = 0 :=
mv_power_series.inv_eq_zero
@[simp, priority 1100] lemma inv_of_unit_eq (φ : power_series α) (h : constant_coeff α φ ≠ 0) :
inv_of_unit φ (units.mk0 _ h) = φ⁻¹ :=
mv_power_series.inv_of_unit_eq _ _
@[simp] lemma inv_of_unit_eq' (φ : power_series α) (u : units α) (h : constant_coeff α φ = u) :
inv_of_unit φ u = φ⁻¹ :=
mv_power_series.inv_of_unit_eq' φ _ h
@[simp] protected lemma mul_inv (φ : power_series α) (h : constant_coeff α φ ≠ 0) :
φ * φ⁻¹ = 1 :=
mv_power_series.mul_inv φ h
@[simp] protected lemma inv_mul (φ : power_series α) (h : constant_coeff α φ ≠ 0) :
φ⁻¹ * φ = 1 :=
mv_power_series.inv_mul φ h
end field
end power_series
namespace power_series
variable {α : Type*}
local attribute [instance, priority 1] classical.prop_decidable
noncomputable theory
section order_basic
open multiplicity
variables [comm_semiring α]
/-- The order of a formal power series `φ` is the smallest `n : enat`
such that `X^n` divides `φ`. The order is `⊤` if and only if `φ = 0`. -/
@[reducible] def order (φ : power_series α) : enat :=
multiplicity X φ
lemma order_finite_of_coeff_ne_zero (φ : power_series α) (h : ∃ n, coeff α n φ ≠ 0) :
(order φ).dom :=
begin
cases h with n h, refine ⟨n, _⟩,
rw X_pow_dvd_iff, push_neg, exact ⟨n, lt_add_one n, h⟩
end
/-- If the order of a formal power series is finite,
then the coefficient indexed by the order is nonzero.-/
lemma coeff_order (φ : power_series α) (h : (order φ).dom) :
coeff α (φ.order.get h) φ ≠ 0 :=
begin
have H := nat.find_spec h, contrapose! H, rw X_pow_dvd_iff,
intros m hm, by_cases Hm : m < nat.find h,
{ have := nat.find_min h Hm, push_neg at this,
rw X_pow_dvd_iff at this, exact this m (lt_add_one m) },
have : m = nat.find h, {linarith}, {rwa this}
end
/-- If the `n`th coefficient of a formal power series is nonzero,
then the order of the power series is less than or equal to `n`.-/
lemma order_le (φ : power_series α) (n : ℕ) (h : coeff α n φ ≠ 0) :
order φ ≤ n :=
begin
have h : ¬ X^(n+1) ∣ φ,
{ rw X_pow_dvd_iff, push_neg, exact ⟨n, lt_add_one n, h⟩ },
have : (order φ).dom := ⟨n, h⟩,
rw [← enat.coe_get this, enat.coe_le_coe],
refine nat.find_min' this h
end
/-- The `n`th coefficient of a formal power series is `0` if `n` is strictly
smaller than the order of the power series.-/
lemma coeff_of_lt_order (φ : power_series α) (n : ℕ) (h: ↑n < order φ) :
coeff α n φ = 0 :=
by { contrapose! h, exact order_le _ _ h }
/-- The `0` power series is the unique power series with infinite order.-/
lemma order_eq_top {φ : power_series α} :
φ.order = ⊤ ↔ φ = 0 :=
begin
rw multiplicity.eq_top_iff,
split,
{ intro h, ext n, specialize h (n+1), rw X_pow_dvd_iff at h, exact h n (lt_add_one _) },
{ rintros rfl n, exact dvd_zero _ }
end
/-- The order of the `0` power series is infinite.-/
@[simp] lemma order_zero : order (0 : power_series α) = ⊤ :=
multiplicity.zero _
/-- The order of a formal power series is at least `n` if
the `i`th coefficient is `0` for all `i < n`.-/
lemma order_ge_nat (φ : power_series α) (n : ℕ) (h : ∀ i < n, coeff α i φ = 0) :
order φ ≥ n :=
begin
by_contra H, rw not_le at H,
have : (order φ).dom := enat.dom_of_le_some (le_of_lt H),
rw [← enat.coe_get this, enat.coe_lt_coe] at H,
exact coeff_order _ this (h _ H)
end
/-- The order of a formal power series is at least `n` if
the `i`th coefficient is `0` for all `i < n`.-/
lemma order_ge (φ : power_series α) (n : enat) (h : ∀ i : ℕ, ↑i < n → coeff α i φ = 0) :
order φ ≥ n :=
begin
induction n using enat.cases_on,
{ show _ ≤ _, rw [top_le_iff, order_eq_top],
ext i, exact h _ (enat.coe_lt_top i) },
{ apply order_ge_nat, simpa only [enat.coe_lt_coe] using h }
end
/-- The order of a formal power series is exactly `n` if the `n`th coefficient is nonzero,
and the `i`th coefficient is `0` for all `i < n`.-/
lemma order_eq_nat {φ : power_series α} {n : ℕ} :
order φ = n ↔ (coeff α n φ ≠ 0) ∧ (∀ i, i < n → coeff α i φ = 0) :=
begin
simp only [eq_some_iff, X_pow_dvd_iff], push_neg,
split,
{ rintros ⟨h₁, m, hm₁, hm₂⟩, refine ⟨_, h₁⟩,
suffices : n = m, { rwa this },
suffices : m ≥ n, { linarith },
contrapose! hm₂, exact h₁ _ hm₂ },
{ rintros ⟨h₁, h₂⟩, exact ⟨h₂, n, lt_add_one n, h₁⟩ }
end
/-- The order of a formal power series is exactly `n` if the `n`th coefficient is nonzero,
and the `i`th coefficient is `0` for all `i < n`.-/
lemma order_eq {φ : power_series α} {n : enat} :
order φ = n ↔ (∀ i:ℕ, ↑i = n → coeff α i φ ≠ 0) ∧ (∀ i:ℕ, ↑i < n → coeff α i φ = 0) :=
begin
induction n using enat.cases_on,
{ rw order_eq_top, split,
{ rintro rfl, split; intros,
{ exfalso, exact enat.coe_ne_top ‹_› ‹_› },
{ exact (coeff _ _).map_zero } },
{ rintro ⟨h₁, h₂⟩, ext i, exact h₂ i (enat.coe_lt_top i) } },
{ simpa [enat.coe_inj] using order_eq_nat }
end
/-- The order of the sum of two formal power series
is at least the minimum of their orders.-/
lemma order_add_ge (φ ψ : power_series α) :
order (φ + ψ) ≥ min (order φ) (order ψ) :=
multiplicity.min_le_multiplicity_add
private lemma order_add_of_order_eq.aux (φ ψ : power_series α)
(h : order φ ≠ order ψ) (H : order φ < order ψ) :
order (φ + ψ) ≤ order φ ⊓ order ψ :=
begin
suffices : order (φ + ψ) = order φ,
{ rw [le_inf_iff, this], exact ⟨le_refl _, le_of_lt H⟩ },
{ rw order_eq, split,
{ intros i hi, rw [(coeff _ _).map_add, coeff_of_lt_order ψ i (hi.symm ▸ H), add_zero],
exact (order_eq_nat.1 hi.symm).1 },
{ intros i hi,
rw [(coeff _ _).map_add, coeff_of_lt_order φ i hi,
coeff_of_lt_order ψ i (lt_trans hi H), zero_add] } }
end
/-- The order of the sum of two formal power series
is the minimum of their orders if their orders differ.-/
lemma order_add_of_order_eq (φ ψ : power_series α) (h : order φ ≠ order ψ) :
order (φ + ψ) = order φ ⊓ order ψ :=
begin
refine le_antisymm _ (order_add_ge _ _),
by_cases H₁ : order φ < order ψ,
{ apply order_add_of_order_eq.aux _ _ h H₁ },
by_cases H₂ : order ψ < order φ,
{ simpa only [add_comm, inf_comm] using order_add_of_order_eq.aux _ _ h.symm H₂ },
exfalso, exact h (le_antisymm (not_lt.1 H₂) (not_lt.1 H₁))
end
/-- The order of the product of two formal power series
is at least the sum of their orders.-/
lemma order_mul_ge (φ ψ : power_series α) :
order (φ * ψ) ≥ order φ + order ψ :=
begin
apply order_ge,
intros n hn, rw [coeff_mul, finset.sum_eq_zero],
rintros ⟨i,j⟩ hij,
by_cases hi : ↑i < order φ,
{ rw [coeff_of_lt_order φ i hi, zero_mul] },
by_cases hj : ↑j < order ψ,
{ rw [coeff_of_lt_order ψ j hj, mul_zero] },
rw not_lt at hi hj, rw finset.nat.mem_antidiagonal at hij,
exfalso,
apply ne_of_lt (lt_of_lt_of_le hn $ add_le_add' hi hj),
rw [← enat.coe_add, hij]
end
/-- The order of the monomial `a*X^n` is infinite if `a = 0` and `n` otherwise.-/
lemma order_monomial (n : ℕ) (a : α) :
order (monomial α n a) = if a = 0 then ⊤ else n :=
begin
split_ifs with h,
{ rw [h, order_eq_top, add_monoid_hom.map_zero] },
{ rw [order_eq], split; intros i hi,
{ rw [enat.coe_inj] at hi, rwa [hi, coeff_monomial'] },
{ rw [enat.coe_lt_coe] at hi, rw [coeff_monomial, if_neg], exact ne_of_lt hi } }
end
/-- The order of the monomial `a*X^n` is `n` if `a ≠ 0`.-/
lemma order_monomial_of_ne_zero (n : ℕ) (a : α) (h : a ≠ 0) :
order (monomial α n a) = n :=
by rw [order_monomial, if_neg h]
end order_basic
section order_zero_ne_one
variables [nonzero_comm_ring α]
/-- The order of the formal power series `1` is `0`.-/
@[simp] lemma order_one : order (1 : power_series α) = 0 :=
by simpa using order_monomial_of_ne_zero 0 (1:α) one_ne_zero
/-- The order of the formal power series `X` is `1`.-/
@[simp] lemma order_X : order (X : power_series α) = 1 :=
order_monomial_of_ne_zero 1 (1:α) one_ne_zero
/-- The order of the formal power series `X^n` is `n`.-/
@[simp] lemma order_X_pow (n : ℕ) : order ((X : power_series α)^n) = n :=
by { rw [X_pow_eq, order_monomial_of_ne_zero], exact one_ne_zero }
end order_zero_ne_one
section order_integral_domain
variables [integral_domain α]
/-- The order of the product of two formal power series over an integral domain
is the sum of their orders.-/
lemma order_mul (φ ψ : power_series α) :
order (φ * ψ) = order φ + order ψ :=
multiplicity.mul (X_prime)
end order_integral_domain
end power_series
namespace polynomial
open finsupp
variables {σ : Type*} {α : Type*} [comm_semiring α]
/-- The natural inclusion from polynomials into formal power series.-/
instance coe_to_power_series : has_coe (polynomial α) (power_series α) :=
⟨λ φ, power_series.mk $ λ n, coeff φ n⟩
@[simp, norm_cast] lemma coeff_coe (φ : polynomial α) (n) :
power_series.coeff α n φ = coeff φ n :=
congr_arg (coeff φ) (finsupp.single_eq_same)
@[simp, norm_cast] lemma coe_monomial (n : ℕ) (a : α) :
(monomial n a : power_series α) = power_series.monomial α n a :=
power_series.ext $ λ m,
begin
rw [coeff_coe, power_series.coeff_monomial],
simp only [@eq_comm _ m n],
convert finsupp.single_apply,
end
@[simp, norm_cast] lemma coe_zero : ((0 : polynomial α) : power_series α) = 0 := rfl
@[simp, norm_cast] lemma coe_one : ((1 : polynomial α) : power_series α) = 1 :=
begin
have := coe_monomial 0 (1:α),
rwa power_series.monomial_zero_eq_C_apply at this,
end
@[simp, norm_cast] lemma coe_add (φ ψ : polynomial α) :
((φ + ψ : polynomial α) : power_series α) = φ + ψ := rfl
@[simp, norm_cast] lemma coe_mul (φ ψ : polynomial α) :
((φ * ψ : polynomial α) : power_series α) = φ * ψ :=
power_series.ext $ λ n,
by simp only [coeff_coe, power_series.coeff_mul, coeff_mul]
@[simp, norm_cast] lemma coe_C (a : α) :
((C a : polynomial α) : power_series α) = power_series.C α a :=
begin
have := coe_monomial 0 a,
rwa power_series.monomial_zero_eq_C_apply at this,
end
@[simp, norm_cast] lemma coe_X :
((X : polynomial α) : power_series α) = power_series.X :=
coe_monomial _ _
namespace coe_to_mv_power_series
instance : is_semiring_hom (coe : polynomial α → power_series α) :=
{ map_zero := coe_zero,
map_one := coe_one,
map_add := coe_add,
map_mul := coe_mul }
end coe_to_mv_power_series
end polynomial
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.