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
1a272a6df1086ca35e76762e6f80a973e1c9801b
bb31430994044506fa42fd667e2d556327e18dfe
/src/data/multiset/nodup.lean
1d1b639604903a19da583fbe8ab48df616af3010
[ "Apache-2.0" ]
permissive
sgouezel/mathlib
0cb4e5335a2ba189fa7af96d83a377f83270e503
00638177efd1b2534fc5269363ebf42a7871df9a
refs/heads/master
1,674,527,483,042
1,673,665,568,000
1,673,665,568,000
119,598,202
0
0
null
1,517,348,647,000
1,517,348,646,000
null
UTF-8
Lean
false
false
9,302
lean
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import data.list.nodup import data.multiset.bind import data.multiset.range /-! # The `nodup` predicate for multisets without duplicate elements. -/ namespace multiset open function list variables {α β γ : Type*} {r : α → α → Prop} {s t : multiset α} {a : α} /- nodup -/ /-- `nodup s` means that `s` has no duplicates, i.e. the multiplicity of any element is at most 1. -/ def nodup (s : multiset α) : Prop := quot.lift_on s nodup (λ s t p, propext p.nodup_iff) @[simp] theorem coe_nodup {l : list α} : @nodup α l ↔ l.nodup := iff.rfl @[simp] theorem nodup_zero : @nodup α 0 := pairwise.nil @[simp] theorem nodup_cons {a : α} {s : multiset α} : nodup (a ::ₘ s) ↔ a ∉ s ∧ nodup s := quot.induction_on s $ λ l, nodup_cons lemma nodup.cons (m : a ∉ s) (n : nodup s) : nodup (a ::ₘ s) := nodup_cons.2 ⟨m, n⟩ @[simp] theorem nodup_singleton : ∀ a : α, nodup ({a} : multiset α) := nodup_singleton lemma nodup.of_cons (h : nodup (a ::ₘ s)) : nodup s := (nodup_cons.1 h).2 theorem nodup.not_mem (h : nodup (a ::ₘ s)) : a ∉ s := (nodup_cons.1 h).1 theorem nodup_of_le {s t : multiset α} (h : s ≤ t) : nodup t → nodup s := le_induction_on h $ λ l₁ l₂, nodup.sublist theorem not_nodup_pair : ∀ a : α, ¬ nodup (a ::ₘ a ::ₘ 0) := not_nodup_pair theorem nodup_iff_le {s : multiset α} : nodup s ↔ ∀ a : α, ¬ a ::ₘ a ::ₘ 0 ≤ s := quot.induction_on s $ λ l, nodup_iff_sublist.trans $ forall_congr $ λ a, not_congr (@repeat_le_coe _ a 2 _).symm lemma nodup_iff_ne_cons_cons {s : multiset α} : s.nodup ↔ ∀ a t, s ≠ a ::ₘ a ::ₘ t := nodup_iff_le.trans ⟨λ h a t s_eq, h a (s_eq.symm ▸ cons_le_cons a (cons_le_cons a (zero_le _))), λ h a le, let ⟨t, s_eq⟩ := le_iff_exists_add.mp le in h a t (by rwa [cons_add, cons_add, zero_add] at s_eq )⟩ theorem nodup_iff_count_le_one [decidable_eq α] {s : multiset α} : nodup s ↔ ∀ a, count a s ≤ 1 := quot.induction_on s $ λ l, nodup_iff_count_le_one @[simp] theorem count_eq_one_of_mem [decidable_eq α] {a : α} {s : multiset α} (d : nodup s) (h : a ∈ s) : count a s = 1 := le_antisymm (nodup_iff_count_le_one.1 d a) (count_pos.2 h) lemma count_eq_of_nodup [decidable_eq α] {a : α} {s : multiset α} (d : nodup s) : count a s = if a ∈ s then 1 else 0 := begin split_ifs with h, { exact count_eq_one_of_mem d h }, { exact count_eq_zero_of_not_mem h }, end lemma nodup_iff_pairwise {α} {s : multiset α} : nodup s ↔ pairwise (≠) s := quotient.induction_on s $ λ l, (pairwise_coe_iff_pairwise (by exact λ a b, ne.symm)).symm protected lemma nodup.pairwise : (∀ a ∈ s, ∀ b ∈ s, a ≠ b → r a b) → nodup s → pairwise r s := quotient.induction_on s $ assume l h hl, ⟨l, rfl, hl.imp_of_mem $ assume a b ha hb, h a ha b hb⟩ lemma pairwise.forall (H : symmetric r) (hs : pairwise r s) : ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → a ≠ b → r a b := let ⟨l, hl₁, hl₂⟩ := hs in hl₁.symm ▸ hl₂.forall H theorem nodup_add {s t : multiset α} : nodup (s + t) ↔ nodup s ∧ nodup t ∧ disjoint s t := quotient.induction_on₂ s t $ λ l₁ l₂, nodup_append theorem disjoint_of_nodup_add {s t : multiset α} (d : nodup (s + t)) : disjoint s t := (nodup_add.1 d).2.2 lemma nodup.add_iff (d₁ : nodup s) (d₂ : nodup t) : nodup (s + t) ↔ disjoint s t := by simp [nodup_add, d₁, d₂] lemma nodup.of_map (f : α → β) : nodup (map f s) → nodup s := quot.induction_on s $ λ l, nodup.of_map f lemma nodup.map_on {f : α → β} : (∀ x ∈ s, ∀ y ∈ s, f x = f y → x = y) → nodup s → nodup (map f s) := quot.induction_on s $ λ l, nodup.map_on lemma nodup.map {f : α → β} {s : multiset α} (hf : injective f) : nodup s → nodup (map f s) := nodup.map_on (λ x _ y _ h, hf h) theorem inj_on_of_nodup_map {f : α → β} {s : multiset α} : nodup (map f s) → ∀ (x ∈ s) (y ∈ s), f x = f y → x = y := quot.induction_on s $ λ l, inj_on_of_nodup_map theorem nodup_map_iff_inj_on {f : α → β} {s : multiset α} (d : nodup s) : nodup (map f s) ↔ (∀ (x ∈ s) (y ∈ s), f x = f y → x = y) := ⟨inj_on_of_nodup_map, λ h, d.map_on h⟩ lemma nodup.filter (p : α → Prop) [decidable_pred p] {s} : nodup s → nodup (filter p s) := quot.induction_on s $ λ l, nodup.filter p @[simp] theorem nodup_attach {s : multiset α} : nodup (attach s) ↔ nodup s := quot.induction_on s $ λ l, nodup_attach lemma nodup.pmap {p : α → Prop} {f : Π a, p a → β} {s : multiset α} {H} (hf : ∀ a ha b hb, f a ha = f b hb → a = b) : nodup s → nodup (pmap f s H) := quot.induction_on s (λ l H, nodup.pmap hf) H instance nodup_decidable [decidable_eq α] (s : multiset α) : decidable (nodup s) := quotient.rec_on_subsingleton s $ λ l, l.nodup_decidable lemma nodup.erase_eq_filter [decidable_eq α] (a : α) {s} : nodup s → s.erase a = filter (≠ a) s := quot.induction_on s $ λ l d, congr_arg coe $ d.erase_eq_filter a lemma nodup.erase [decidable_eq α] (a : α) {l} : nodup l → nodup (l.erase a) := nodup_of_le (erase_le _ _) lemma nodup.mem_erase_iff [decidable_eq α] {a b : α} {l} (d : nodup l) : a ∈ l.erase b ↔ a ≠ b ∧ a ∈ l := by rw [d.erase_eq_filter b, mem_filter, and_comm] lemma nodup.not_mem_erase [decidable_eq α] {a : α} {s} (h : nodup s) : a ∉ s.erase a := λ ha, (h.mem_erase_iff.1 ha).1 rfl protected lemma nodup.product {t : multiset β} : nodup s → nodup t → nodup (product s t) := quotient.induction_on₂ s t $ λ l₁ l₂ d₁ d₂, by simp [d₁.product d₂] protected lemma nodup.sigma {σ : α → Type*} {t : Π a, multiset (σ a)} : nodup s → (∀ a, nodup (t a)) → nodup (s.sigma t) := quot.induction_on s $ assume l₁, begin choose f hf using assume a, quotient.exists_rep (t a), rw show t = λ a, f a, from (eq.symm $ funext $ λ a, hf a), simpa using nodup.sigma end protected lemma nodup.filter_map (f : α → option β) (H : ∀ a a' b, b ∈ f a → b ∈ f a' → a = a') : nodup s → nodup (filter_map f s) := quot.induction_on s $ λ l, nodup.filter_map H theorem nodup_range (n : ℕ) : nodup (range n) := nodup_range _ lemma nodup.inter_left [decidable_eq α] (t) : nodup s → nodup (s ∩ t) := nodup_of_le $ inter_le_left _ _ lemma nodup.inter_right [decidable_eq α] (s) : nodup t → nodup (s ∩ t) := nodup_of_le $ inter_le_right _ _ @[simp] theorem nodup_union [decidable_eq α] {s t : multiset α} : nodup (s ∪ t) ↔ nodup s ∧ nodup t := ⟨λ h, ⟨nodup_of_le (le_union_left _ _) h, nodup_of_le (le_union_right _ _) h⟩, λ ⟨h₁, h₂⟩, nodup_iff_count_le_one.2 $ λ a, by rw [count_union]; exact max_le (nodup_iff_count_le_one.1 h₁ a) (nodup_iff_count_le_one.1 h₂ a)⟩ @[simp] lemma nodup_bind {s : multiset α} {t : α → multiset β} : nodup (bind s t) ↔ ((∀a∈s, nodup (t a)) ∧ (s.pairwise (λa b, disjoint (t a) (t b)))) := have h₁ : ∀a, ∃l:list β, t a = l, from assume a, quot.induction_on (t a) $ assume l, ⟨l, rfl⟩, let ⟨t', h'⟩ := classical.axiom_of_choice h₁ in have t = λa, t' a, from funext h', have hd : symmetric (λa b, list.disjoint (t' a) (t' b)), from assume a b h, h.symm, quot.induction_on s $ by simp [this, list.nodup_bind, pairwise_coe_iff_pairwise hd] lemma nodup.ext {s t : multiset α} : nodup s → nodup t → (s = t ↔ ∀ a, a ∈ s ↔ a ∈ t) := quotient.induction_on₂ s t $ λ l₁ l₂ d₁ d₂, quotient.eq.trans $ perm_ext d₁ d₂ theorem le_iff_subset {s t : multiset α} : nodup s → (s ≤ t ↔ s ⊆ t) := quotient.induction_on₂ s t $ λ l₁ l₂ d, ⟨subset_of_le, d.subperm⟩ theorem range_le {m n : ℕ} : range m ≤ range n ↔ m ≤ n := (le_iff_subset (nodup_range _)).trans range_subset theorem mem_sub_of_nodup [decidable_eq α] {a : α} {s t : multiset α} (d : nodup s) : a ∈ s - t ↔ a ∈ s ∧ a ∉ t := ⟨λ h, ⟨mem_of_le tsub_le_self h, λ h', by refine count_eq_zero.1 _ h; rw [count_sub a s t, tsub_eq_zero_iff_le]; exact le_trans (nodup_iff_count_le_one.1 d _) (count_pos.2 h')⟩, λ ⟨h₁, h₂⟩, or.resolve_right (mem_add.1 $ mem_of_le le_tsub_add h₁) h₂⟩ lemma map_eq_map_of_bij_of_nodup (f : α → γ) (g : β → γ) {s : multiset α} {t : multiset β} (hs : s.nodup) (ht : t.nodup) (i : Πa∈s, β) (hi : ∀a ha, i a ha ∈ t) (h : ∀a ha, f a = g (i a ha)) (i_inj : ∀a₁ a₂ ha₁ ha₂, i a₁ ha₁ = i a₂ ha₂ → a₁ = a₂) (i_surj : ∀b∈t, ∃a ha, b = i a ha) : s.map f = t.map g := have t = s.attach.map (λ x, i x x.2), from (ht.ext $ (nodup_attach.2 hs).map $ show injective (λ x : {x // x ∈ s}, i x x.2), from λ x y hxy, subtype.ext $ i_inj x y x.2 y.2 hxy).2 (λ x, by simp only [mem_map, true_and, subtype.exists, eq_comm, mem_attach]; exact ⟨i_surj _, λ ⟨y, hy⟩, hy.snd.symm ▸ hi _ _⟩), calc s.map f = s.pmap (λ x _, f x) (λ _, id) : by rw [pmap_eq_map] ... = s.attach.map (λ x, f x) : by rw [pmap_eq_map_attach] ... = t.map g : by rw [this, multiset.map_map]; exact map_congr rfl (λ x _, h _ _) end multiset
c0a0aebcc3a8c16412233178e1796746d939158c
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
/tests/lean/trace1.lean
d1d140930d02dce76de78291d52b0dcff3a2576b
[ "Apache-2.0" ]
permissive
soonhokong/lean-osx
4a954262c780e404c1369d6c06516161d07fcb40
3670278342d2f4faa49d95b46d86642d7875b47c
refs/heads/master
1,611,410,334,552
1,474,425,686,000
1,474,425,686,000
12,043,103
5
1
null
null
null
null
UTF-8
Lean
false
false
296
lean
open tactic example : true := by do when_tracing `app_builder $ do { trace "hello", trace "world" }, constructor set_option trace.app_builder true print "------------" example : true := by do when_tracing `app_builder $ do { trace "hello", trace "world" }, constructor
f68542955afd8822f5ad44992c1bbd9a7901a8c2
57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d
/tests/lean/interactive/plainGoal.lean
9d94d59d9a2a61e361d6eece9e63d4530f112479
[ "Apache-2.0" ]
permissive
collares/lean4
861a9269c4592bce49b71059e232ff0bfe4594cc
52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee
refs/heads/master
1,691,419,031,324
1,618,678,138,000
1,618,678,138,000
358,989,750
0
0
Apache-2.0
1,618,696,333,000
1,618,696,333,000
null
UTF-8
Lean
false
false
89
lean
example : α → α := by intro a --^ $/lean/plainGoal --^ $/lean/plainGoal apply a
f433c139d85e0e8ab36a9049a776f22b4ea0147d
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/number_theory/zsqrtd/gaussian_int.lean
408f76723e7cabebd9ff57c3ca66e638b84fc959
[ "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
12,543
lean
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import number_theory.zsqrtd.basic import data.complex.basic import ring_theory.principal_ideal_domain import number_theory.quadratic_reciprocity /-! # Gaussian integers The Gaussian integers are complex integer, complex numbers whose real and imaginary parts are both integers. ## Main definitions The Euclidean domain structure on `ℤ[i]` is defined in this file. The homomorphism `to_complex` into the complex numbers is also defined in this file. ## Main statements `prime_iff_mod_four_eq_three_of_nat_prime` A prime natural number is prime in `ℤ[i]` if and only if it is `3` mod `4` ## Notations This file uses the local notation `ℤ[i]` for `gaussian_int` ## Implementation notes Gaussian integers are implemented using the more general definition `zsqrtd`, the type of integers adjoined a square root of `d`, in this case `-1`. The definition is reducible, so that properties and definitions about `zsqrtd` can easily be used. -/ open zsqrtd complex @[reducible] def gaussian_int : Type := zsqrtd (-1) local notation `ℤ[i]` := gaussian_int namespace gaussian_int instance : has_repr ℤ[i] := ⟨λ x, "⟨" ++ repr x.re ++ ", " ++ repr x.im ++ "⟩"⟩ instance : comm_ring ℤ[i] := zsqrtd.comm_ring section local attribute [-instance] complex.field -- Avoid making things noncomputable unnecessarily. /-- The embedding of the Gaussian integers into the complex numbers, as a ring homomorphism. -/ def to_complex : ℤ[i] →+* ℂ := zsqrtd.lift ⟨I, by simp⟩ end instance : has_coe (ℤ[i]) ℂ := ⟨to_complex⟩ lemma to_complex_def (x : ℤ[i]) : (x : ℂ) = x.re + x.im * I := rfl lemma to_complex_def' (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ) = x + y * I := by simp [to_complex_def] lemma to_complex_def₂ (x : ℤ[i]) : (x : ℂ) = ⟨x.re, x.im⟩ := by apply complex.ext; simp [to_complex_def] @[simp] lemma to_real_re (x : ℤ[i]) : ((x.re : ℤ) : ℝ) = (x : ℂ).re := by simp [to_complex_def] @[simp] lemma to_real_im (x : ℤ[i]) : ((x.im : ℤ) : ℝ) = (x : ℂ).im := by simp [to_complex_def] @[simp] lemma to_complex_re (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ).re = x := by simp [to_complex_def] @[simp] lemma to_complex_im (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ).im = y := by simp [to_complex_def] @[simp] lemma to_complex_add (x y : ℤ[i]) : ((x + y : ℤ[i]) : ℂ) = x + y := to_complex.map_add _ _ @[simp] lemma to_complex_mul (x y : ℤ[i]) : ((x * y : ℤ[i]) : ℂ) = x * y := to_complex.map_mul _ _ @[simp] lemma to_complex_one : ((1 : ℤ[i]) : ℂ) = 1 := to_complex.map_one @[simp] lemma to_complex_zero : ((0 : ℤ[i]) : ℂ) = 0 := to_complex.map_zero @[simp] lemma to_complex_neg (x : ℤ[i]) : ((-x : ℤ[i]) : ℂ) = -x := to_complex.map_neg _ @[simp] lemma to_complex_sub (x y : ℤ[i]) : ((x - y : ℤ[i]) : ℂ) = x - y := to_complex.map_sub _ _ @[simp] lemma to_complex_inj {x y : ℤ[i]} : (x : ℂ) = y ↔ x = y := by cases x; cases y; simp [to_complex_def₂] @[simp] lemma to_complex_eq_zero {x : ℤ[i]} : (x : ℂ) = 0 ↔ x = 0 := by rw [← to_complex_zero, to_complex_inj] @[simp] lemma nat_cast_real_norm (x : ℤ[i]) : (x.norm : ℝ) = (x : ℂ).norm_sq := by rw [norm, norm_sq]; simp @[simp] lemma nat_cast_complex_norm (x : ℤ[i]) : (x.norm : ℂ) = (x : ℂ).norm_sq := by cases x; rw [norm, norm_sq]; simp lemma norm_nonneg (x : ℤ[i]) : 0 ≤ norm x := norm_nonneg (by norm_num) _ @[simp] lemma norm_eq_zero {x : ℤ[i]} : norm x = 0 ↔ x = 0 := by rw [← @int.cast_inj ℝ _ _ _]; simp lemma norm_pos {x : ℤ[i]} : 0 < norm x ↔ x ≠ 0 := by rw [lt_iff_le_and_ne, ne.def, eq_comm, norm_eq_zero]; simp [norm_nonneg] @[simp] lemma coe_nat_abs_norm (x : ℤ[i]) : (x.norm.nat_abs : ℤ) = x.norm := int.nat_abs_of_nonneg (norm_nonneg _) @[simp] lemma nat_cast_nat_abs_norm {α : Type*} [ring α] (x : ℤ[i]) : (x.norm.nat_abs : α) = x.norm := by rw [← int.cast_coe_nat, coe_nat_abs_norm] lemma nat_abs_norm_eq (x : ℤ[i]) : x.norm.nat_abs = x.re.nat_abs * x.re.nat_abs + x.im.nat_abs * x.im.nat_abs := int.coe_nat_inj $ begin simp, simp [norm] end protected def div (x y : ℤ[i]) : ℤ[i] := let n := (rat.of_int (norm y))⁻¹ in let c := y.conj in ⟨round (rat.of_int (x * c).re * n : ℚ), round (rat.of_int (x * c).im * n : ℚ)⟩ instance : has_div ℤ[i] := ⟨gaussian_int.div⟩ lemma div_def (x y : ℤ[i]) : x / y = ⟨round ((x * conj y).re / norm y : ℚ), round ((x * conj y).im / norm y : ℚ)⟩ := show zsqrtd.mk _ _ = _, by simp [rat.of_int_eq_mk, rat.mk_eq_div, div_eq_mul_inv] lemma to_complex_div_re (x y : ℤ[i]) : ((x / y : ℤ[i]) : ℂ).re = round ((x / y : ℂ).re) := by rw [div_def, ← @rat.round_cast ℝ _ _]; simp [-rat.round_cast, mul_assoc, div_eq_mul_inv, mul_add, add_mul] lemma to_complex_div_im (x y : ℤ[i]) : ((x / y : ℤ[i]) : ℂ).im = round ((x / y : ℂ).im) := by rw [div_def, ← @rat.round_cast ℝ _ _, ← @rat.round_cast ℝ _ _]; simp [-rat.round_cast, mul_assoc, div_eq_mul_inv, mul_add, add_mul] lemma norm_sq_le_norm_sq_of_re_le_of_im_le {x y : ℂ} (hre : |x.re| ≤ |y.re|) (him : |x.im| ≤ |y.im|) : x.norm_sq ≤ y.norm_sq := by rw [norm_sq_apply, norm_sq_apply, ← _root_.abs_mul_self, _root_.abs_mul, ← _root_.abs_mul_self y.re, _root_.abs_mul y.re, ← _root_.abs_mul_self x.im, _root_.abs_mul x.im, ← _root_.abs_mul_self y.im, _root_.abs_mul y.im]; exact (add_le_add (mul_self_le_mul_self (abs_nonneg _) hre) (mul_self_le_mul_self (abs_nonneg _) him)) lemma norm_sq_div_sub_div_lt_one (x y : ℤ[i]) : ((x / y : ℂ) - ((x / y : ℤ[i]) : ℂ)).norm_sq < 1 := calc ((x / y : ℂ) - ((x / y : ℤ[i]) : ℂ)).norm_sq = ((x / y : ℂ).re - ((x / y : ℤ[i]) : ℂ).re + ((x / y : ℂ).im - ((x / y : ℤ[i]) : ℂ).im) * I : ℂ).norm_sq : congr_arg _ $ by apply complex.ext; simp ... ≤ (1 / 2 + 1 / 2 * I).norm_sq : have |(2⁻¹ : ℝ)| = 2⁻¹, from _root_.abs_of_nonneg (by norm_num), norm_sq_le_norm_sq_of_re_le_of_im_le (by rw [to_complex_div_re]; simp [norm_sq, this]; simpa using abs_sub_round (x / y : ℂ).re) (by rw [to_complex_div_im]; simp [norm_sq, this]; simpa using abs_sub_round (x / y : ℂ).im) ... < 1 : by simp [norm_sq]; norm_num protected def mod (x y : ℤ[i]) : ℤ[i] := x - y * (x / y) instance : has_mod ℤ[i] := ⟨gaussian_int.mod⟩ lemma mod_def (x y : ℤ[i]) : x % y = x - y * (x / y) := rfl lemma norm_mod_lt (x : ℤ[i]) {y : ℤ[i]} (hy : y ≠ 0) : (x % y).norm < y.norm := have (y : ℂ) ≠ 0, by rwa [ne.def, ← to_complex_zero, to_complex_inj], (@int.cast_lt ℝ _ _ _ _).1 $ calc ↑(norm (x % y)) = (x - y * (x / y : ℤ[i]) : ℂ).norm_sq : by simp [mod_def] ... = (y : ℂ).norm_sq * (((x / y) - (x / y : ℤ[i])) : ℂ).norm_sq : by rw [← norm_sq_mul, mul_sub, mul_div_cancel' _ this] ... < (y : ℂ).norm_sq * 1 : mul_lt_mul_of_pos_left (norm_sq_div_sub_div_lt_one _ _) (norm_sq_pos.2 this) ... = norm y : by simp lemma nat_abs_norm_mod_lt (x : ℤ[i]) {y : ℤ[i]} (hy : y ≠ 0) : (x % y).norm.nat_abs < y.norm.nat_abs := int.coe_nat_lt.1 (by simp [-int.coe_nat_lt, norm_mod_lt x hy]) lemma norm_le_norm_mul_left (x : ℤ[i]) {y : ℤ[i]} (hy : y ≠ 0) : (norm x).nat_abs ≤ (norm (x * y)).nat_abs := by rw [norm_mul, int.nat_abs_mul]; exact le_mul_of_one_le_right (nat.zero_le _) (int.coe_nat_le.1 (by rw [coe_nat_abs_norm]; exact int.add_one_le_of_lt (norm_pos.2 hy))) instance : nontrivial ℤ[i] := ⟨⟨0, 1, dec_trivial⟩⟩ instance : euclidean_domain ℤ[i] := { quotient := (/), remainder := (%), quotient_zero := by { simp [div_def], refl }, quotient_mul_add_remainder_eq := λ _ _, by simp [mod_def], r := _, r_well_founded := measure_wf (int.nat_abs ∘ norm), remainder_lt := nat_abs_norm_mod_lt, mul_left_not_lt := λ a b hb0, not_lt_of_ge $ norm_le_norm_mul_left a hb0, .. gaussian_int.comm_ring, .. gaussian_int.nontrivial } open principal_ideal_ring lemma mod_four_eq_three_of_nat_prime_of_prime (p : ℕ) [hp : fact p.prime] (hpi : prime (p : ℤ[i])) : p % 4 = 3 := hp.1.eq_two_or_odd.elim (λ hp2, absurd hpi (mt irreducible_iff_prime.2 $ λ ⟨hu, h⟩, begin have := h ⟨1, 1⟩ ⟨1, -1⟩ (hp2.symm ▸ rfl), rw [← norm_eq_one_iff, ← norm_eq_one_iff] at this, exact absurd this dec_trivial end)) (λ hp1, by_contradiction $ λ hp3 : p % 4 ≠ 3, have hp41 : p % 4 = 1, begin rw [← nat.mod_mul_left_mod p 2 2, show 2 * 2 = 4, from rfl] at hp1, have := nat.mod_lt p (show 0 < 4, from dec_trivial), revert this hp3 hp1, generalize : p % 4 = m, dec_trivial!, end, let ⟨k, hk⟩ := (zmod.exists_sq_eq_neg_one_iff_mod_four_ne_three p).2 $ by rw hp41; exact dec_trivial in begin obtain ⟨k, k_lt_p, rfl⟩ : ∃ (k' : ℕ) (h : k' < p), (k' : zmod p) = k, { refine ⟨k.val, k.val_lt, zmod.nat_cast_zmod_val k⟩ }, have hpk : p ∣ k ^ 2 + 1, by rw [← char_p.cast_eq_zero_iff (zmod p) p]; simp *, have hkmul : (k ^ 2 + 1 : ℤ[i]) = ⟨k, 1⟩ * ⟨k, -1⟩ := by simp [sq, zsqrtd.ext], have hpne1 : p ≠ 1 := ne_of_gt hp.1.one_lt, have hkltp : 1 + k * k < p * p, from calc 1 + k * k ≤ k + k * k : add_le_add_right (nat.pos_of_ne_zero (λ hk0, by clear_aux_decl; simp [*, pow_succ'] at *)) _ ... = k * (k + 1) : by simp [add_comm, mul_add] ... < p * p : mul_lt_mul k_lt_p k_lt_p (nat.succ_pos _) (nat.zero_le _), have hpk₁ : ¬ (p : ℤ[i]) ∣ ⟨k, -1⟩ := λ ⟨x, hx⟩, lt_irrefl (p * x : ℤ[i]).norm.nat_abs $ calc (norm (p * x : ℤ[i])).nat_abs = (norm ⟨k, -1⟩).nat_abs : by rw hx ... < (norm (p : ℤ[i])).nat_abs : by simpa [add_comm, norm] using hkltp ... ≤ (norm (p * x : ℤ[i])).nat_abs : norm_le_norm_mul_left _ (λ hx0, (show (-1 : ℤ) ≠ 0, from dec_trivial) $ by simpa [hx0] using congr_arg zsqrtd.im hx), have hpk₂ : ¬ (p : ℤ[i]) ∣ ⟨k, 1⟩ := λ ⟨x, hx⟩, lt_irrefl (p * x : ℤ[i]).norm.nat_abs $ calc (norm (p * x : ℤ[i])).nat_abs = (norm ⟨k, 1⟩).nat_abs : by rw hx ... < (norm (p : ℤ[i])).nat_abs : by simpa [add_comm, norm] using hkltp ... ≤ (norm (p * x : ℤ[i])).nat_abs : norm_le_norm_mul_left _ (λ hx0, (show (1 : ℤ) ≠ 0, from dec_trivial) $ by simpa [hx0] using congr_arg zsqrtd.im hx), have hpu : ¬ is_unit (p : ℤ[i]), from mt norm_eq_one_iff.2 (by rw [norm_nat_cast, int.nat_abs_mul, nat.mul_eq_one_iff]; exact λ h, (ne_of_lt hp.1.one_lt).symm h.1), obtain ⟨y, hy⟩ := hpk, have := hpi.2.2 ⟨k, 1⟩ ⟨k, -1⟩ ⟨y, by rw [← hkmul, ← nat.cast_mul p, ← hy]; simp⟩, clear_aux_decl, tauto end) lemma sq_add_sq_of_nat_prime_of_not_irreducible (p : ℕ) [hp : fact p.prime] (hpi : ¬irreducible (p : ℤ[i])) : ∃ a b, a^2 + b^2 = p := have hpu : ¬ is_unit (p : ℤ[i]), from mt norm_eq_one_iff.2 $ by rw [norm_nat_cast, int.nat_abs_mul, nat.mul_eq_one_iff]; exact λ h, (ne_of_lt hp.1.one_lt).symm h.1, have hab : ∃ a b, (p : ℤ[i]) = a * b ∧ ¬ is_unit a ∧ ¬ is_unit b, by simpa [irreducible_iff, hpu, not_forall, not_or_distrib] using hpi, let ⟨a, b, hpab, hau, hbu⟩ := hab in have hnap : (norm a).nat_abs = p, from ((hp.1.mul_eq_prime_sq_iff (mt norm_eq_one_iff.1 hau) (mt norm_eq_one_iff.1 hbu)).1 $ by rw [← int.coe_nat_inj', int.coe_nat_pow, sq, ← @norm_nat_cast (-1), hpab]; simp).1, ⟨a.re.nat_abs, a.im.nat_abs, by simpa [nat_abs_norm_eq, sq] using hnap⟩ lemma prime_of_nat_prime_of_mod_four_eq_three (p : ℕ) [hp : fact p.prime] (hp3 : p % 4 = 3) : prime (p : ℤ[i]) := irreducible_iff_prime.1 $ classical.by_contradiction $ λ hpi, let ⟨a, b, hab⟩ := sq_add_sq_of_nat_prime_of_not_irreducible p hpi in have ∀ a b : zmod 4, a^2 + b^2 ≠ p, by erw [← zmod.nat_cast_mod 4 p, hp3]; exact dec_trivial, this a b (hab ▸ by simp) /-- A prime natural number is prime in `ℤ[i]` if and only if it is `3` mod `4` -/ lemma prime_iff_mod_four_eq_three_of_nat_prime (p : ℕ) [hp : fact p.prime] : prime (p : ℤ[i]) ↔ p % 4 = 3 := ⟨mod_four_eq_three_of_nat_prime_of_prime p, prime_of_nat_prime_of_mod_four_eq_three p⟩ end gaussian_int
e213cf9d14c490ef61c9786dee00114976e87260
4727251e0cd73359b15b664c3170e5d754078599
/src/analysis/complex/liouville.lean
1a5aaddacc0163ea90fd4cc25fc3ad8ce22fa1e3
[ "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
5,711
lean
/- Copyright (c) 2022 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import analysis.complex.cauchy_integral import analysis.calculus.fderiv_analytic import analysis.normed_space.completion /-! # Liouville's theorem In this file we prove Liouville's theorem: if `f : E → F` is complex differentiable on the whole space and its range is bounded, then the function is a constant. Various versions of this theorem are formalized in `differentiable.apply_eq_apply_of_bounded`, `differentiable.exists_const_forall_eq_of_bounded`, and `differentiable.exists_eq_const_of_bounded`. The proof is based on the Cauchy integral formula for the derivative of an analytic function, see `complex.deriv_eq_smul_circle_integral`. -/ open topological_space metric set filter asymptotics function measure_theory open_locale topological_space filter nnreal real universes u v variables {E : Type u} [normed_group E] [normed_space ℂ E] {F : Type v} [normed_group F] [normed_space ℂ F] local postfix `̂`:100 := uniform_space.completion namespace complex /-- If `f` is complex differentiable on an open disc with center `c` and radius `R > 0` and is continuous on its closure, then `f' c` can be represented as an integral over the corresponding circle. TODO: add a version for `w ∈ metric.ball c R`. TODO: add a version for higher derivatives. -/ lemma deriv_eq_smul_circle_integral [complete_space F] {R : ℝ} {c : ℂ} {f : ℂ → F} (hR : 0 < R) (hf : diff_cont_on_cl ℂ f (ball c R)) : deriv f c = (2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - c) ^ (-2 : ℤ) • f z := begin lift R to ℝ≥0 using hR.le, refine (hf.has_fpower_series_on_ball hR).has_fpower_series_at.deriv.trans _, simp only [cauchy_power_series_apply, one_div, zpow_neg₀, pow_one, smul_smul, zpow_two, mul_inv] end lemma norm_deriv_le_aux [complete_space F] {c : ℂ} {R C : ℝ} {f : ℂ → F} (hR : 0 < R) (hf : diff_cont_on_cl ℂ f (ball c R)) (hC : ∀ z ∈ sphere c R, ∥f z∥ ≤ C) : ∥deriv f c∥ ≤ C / R := begin have : ∀ z ∈ sphere c R, ∥(z - c) ^ (-2 : ℤ) • f z∥ ≤ C / (R * R), from λ z (hz : abs (z - c) = R), by simpa [-mul_inv_rev, norm_smul, hz, zpow_two, ←div_eq_inv_mul] using (div_le_div_right (mul_pos hR hR)).2 (hC z hz), calc ∥deriv f c∥ = ∥(2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - c) ^ (-2 : ℤ) • f z∥ : congr_arg norm (deriv_eq_smul_circle_integral hR hf) ... ≤ R * (C / (R * R)) : circle_integral.norm_two_pi_I_inv_smul_integral_le_of_norm_le_const hR.le this ... = C / R : by rw [mul_div_left_comm, div_self_mul_self', div_eq_mul_inv] end /-- If `f` is complex differentiable on an open disc of radius `R > 0`, is continuous on its closure, and its values on the boundary circle of this disc are bounded from above by `C`, then the norm of its derivative at the center is at most `C / R`. -/ lemma norm_deriv_le_of_forall_mem_sphere_norm_le {c : ℂ} {R C : ℝ} {f : ℂ → F} (hR : 0 < R) (hd : diff_cont_on_cl ℂ f (ball c R)) (hC : ∀ z ∈ sphere c R, ∥f z∥ ≤ C) : ∥deriv f c∥ ≤ C / R := begin set e : F →L[ℂ] F̂ := uniform_space.completion.to_complL, have : has_deriv_at (e ∘ f) (e (deriv f c)) c, from e.has_fderiv_at.comp_has_deriv_at c (hd.differentiable_at is_open_ball $ mem_ball_self hR).has_deriv_at, calc ∥deriv f c∥ = ∥deriv (e ∘ f) c∥ : by { rw this.deriv, exact (uniform_space.completion.norm_coe _).symm } ... ≤ C / R : norm_deriv_le_aux hR (e.differentiable.comp_diff_cont_on_cl hd) (λ z hz, (uniform_space.completion.norm_coe _).trans_le (hC z hz)) end /-- An auxiliary lemma for Liouville's theorem `differentiable.apply_eq_apply_of_bounded`. -/ lemma liouville_theorem_aux {f : ℂ → F} (hf : differentiable ℂ f) (hb : bounded (range f)) (z w : ℂ) : f z = f w := begin suffices : ∀ c, deriv f c = 0, from is_const_of_deriv_eq_zero hf this z w, clear z w, intro c, obtain ⟨C, C₀, hC⟩ : ∃ C > (0 : ℝ), ∀ z, ∥f z∥ ≤ C, { rcases bounded_iff_forall_norm_le.1 hb with ⟨C, hC⟩, exact ⟨max C 1, lt_max_iff.2 (or.inr zero_lt_one), λ z, (hC (f z) (mem_range_self _)).trans (le_max_left _ _)⟩ }, refine norm_le_zero_iff.1 (le_of_forall_le_of_dense $ λ ε ε₀, _), calc ∥deriv f c∥ ≤ C / (C / ε) : norm_deriv_le_of_forall_mem_sphere_norm_le (div_pos C₀ ε₀) hf.diff_cont_on_cl (λ z _, hC z) ... = ε : div_div_cancel' C₀.lt.ne' end end complex namespace differentiable open complex /-- **Liouville's theorem**: a complex differentiable bounded function `f : E → F` is a constant. -/ lemma apply_eq_apply_of_bounded {f : E → F} (hf : differentiable ℂ f) (hb : bounded (range f)) (z w : E) : f z = f w := begin set g : ℂ → F := f ∘ (λ t : ℂ, t • (w - z) + z), suffices : g 0 = g 1, by simpa [g], apply liouville_theorem_aux, exacts [hf.comp ((differentiable_id.smul_const (w - z)).add_const z), hb.mono (range_comp_subset_range _ _)] end /-- **Liouville's theorem**: a complex differentiable bounded function is a constant. -/ lemma exists_const_forall_eq_of_bounded {f : E → F} (hf : differentiable ℂ f) (hb : bounded (range f)) : ∃ c, ∀ z, f z = c := ⟨f 0, λ z, hf.apply_eq_apply_of_bounded hb _ _⟩ /-- **Liouville's theorem**: a complex differentiable bounded function is a constant. -/ lemma exists_eq_const_of_bounded {f : E → F} (hf : differentiable ℂ f) (hb : bounded (range f)) : ∃ c, f = const E c := (hf.exists_const_forall_eq_of_bounded hb).imp $ λ c, funext end differentiable
bf844fcec6578816744bc09d7abc0b58aa02b6bd
ed27983dd289b3bcad416f0b1927105d6ef19db8
/src/assignments/assignment_6/field_rename.lean
2792ab6bbfa5bd1ee94c373d07e57c5322ff31d7
[]
no_license
liuxin-James/complogic-s21
0d55b76dbe25024473d31d98b5b83655c365f811
13e03e0114626643b44015c654151fb651603486
refs/heads/master
1,681,109,264,463
1,618,848,261,000
1,618,848,261,000
337,599,491
0
0
null
1,613,141,619,000
1,612,925,555,000
null
UTF-8
Lean
false
false
1,061
lean
import inClassNotes.typeclasses.algebra set_option old_structure_cmd true /- Inheriting two fields with same name -/ open alg -- need to enable "old_structure" option here class another_two_muls (A : Type) extends mul_groupoid A renaming a_mul → mul1 mul_groupoid A renaming a_mul → mul2 instance another_two_muls_nat : another_two_muls nat := ⟨ nat.mul, nat.add ⟩ def nat_nat_mul1 [another_two_muls nat] (a b : ℕ) := another_two_muls.mul2 a b #reduce nat_nat_mul1 2 3 /- Inheriting same field twice -/ class inh_mul1 (A : Type) extends mul_groupoid A := (n : ℕ) instance inh_mul1_nat : inh_mul1 nat := ⟨ nat.mul, 3 ⟩ class inh_mul2 (A : Type) extends mul_groupoid A := (b : bool) instance inh_mul2_nat : inh_mul2 nat := ⟨ nat.add, tt ⟩ class inh_mul_twice (A : Type) extends inh_mul1 A, inh_mul2 A := (s : string) instance inh_mul_twice_nat : inh_mul_twice nat := ⟨ nat.mul, 5, ff, "Hi" ⟩ instance inh_mul_twice_nat2 : inh_mul_twice nat := ⟨ inh_mul2.mul, 5, ff, "Hi" ⟩
12b1dfc9c49680d37a9a65c56873bbc09a74e323
ce6917c5bacabee346655160b74a307b4a5ab620
/src/ch2/ex0701.lean
f25e4623edc3bed263e25941f92100db04db0226
[]
no_license
Ailrun/Theorem_Proving_in_Lean
ae6a23f3c54d62d401314d6a771e8ff8b4132db2
2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68
refs/heads/master
1,609,838,270,467
1,586,846,743,000
1,586,846,743,000
240,967,761
1
0
null
null
null
null
UTF-8
Lean
false
false
400
lean
namespace foo def a : ℕ := 5 def f (x : ℕ) : ℕ := x + 7 def fa : ℕ := f a def ffa : ℕ := f (f a) #print "inside foo" #check a #check f #check fa #check ffa #check foo.fa end foo #print "outside the namespace" -- #check a -- #check f #check foo.a #check foo.f #check foo.fa #check foo.ffa open foo #print "opened foo" #check a #check f #check fa #check foo.fa
5bd337b3fb45d982ea15f59237a48ee1266de25a
302c785c90d40ad3d6be43d33bc6a558354cc2cf
/src/data/equiv/fintype.lean
46bf9c9ef9ce8d2e0c7f2d98279c97c70d351370
[ "Apache-2.0" ]
permissive
ilitzroth/mathlib
ea647e67f1fdfd19a0f7bdc5504e8acec6180011
5254ef14e3465f6504306132fe3ba9cec9ffff16
refs/heads/master
1,680,086,661,182
1,617,715,647,000
1,617,715,647,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
3,168
lean
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import data.equiv.basic import data.fintype.basic import group_theory.perm.sign /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `fintype`s. # Main definitions - `function.embedding.to_equiv_range`: computably turn an embedding of a fintype into an `equiv` of the domain to its range - `equiv.perm.via_embedding : perm α → (α ↪ β) → perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `function.embedding.to_equiv_range` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `fintype`s. -/ variables {α β : Type*} [fintype α] [decidable_eq β] (e : equiv.perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ set.range f`, if `α` is a `fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `equiv.of_left_inverse'` or `equiv.of_left_inverse` instead. This is the computable version of `equiv.of_injective`. -/ def function.embedding.to_equiv_range : α ≃ set.range f := ⟨λ a, ⟨f a, set.mem_range_self a⟩, f.inv_of_mem_range, λ _, by simp, λ _, by simp⟩ @[simp] lemma function.embedding.to_equiv_range_apply (a : α) : f.to_equiv_range a = ⟨f a, set.mem_range_self a⟩ := rfl @[simp] lemma function.embedding.to_equiv_range_symm_apply_self (a : α) : f.to_equiv_range.symm ⟨f a, set.mem_range_self a⟩ = a := by simp [equiv.symm_apply_eq] lemma function.embedding.to_equiv_range_eq_of_injective : f.to_equiv_range = equiv.of_injective f f.injective := by { ext, simp } /-- Extend the domain of `e : equiv.perm α`, mapping it through `f : α ↪ β`. Everything outside of `set.range f` is kept fixed. Has poor computational performance, due to exhaustive searching in constructed inverse due to using `function.embedding.to_equiv_range`. When a better `α ≃ set.range f` is known, use `equiv.perm.via_set_range`. -/ def equiv.perm.via_embedding : equiv.perm β := e.extend_domain f.to_equiv_range @[simp] lemma equiv.perm.via_embedding_apply_image (a : α) : e.via_embedding f (f a) = f (e a) := begin rw equiv.perm.via_embedding, convert equiv.perm.extend_domain_apply_image e _ _ end lemma equiv.perm.via_embedding_apply_mem_range {b : β} (h : b ∈ set.range f) : e.via_embedding f b = f (e (f.inv_of_mem_range ⟨b, h⟩)) := by simpa [equiv.perm.via_embedding, equiv.perm.extend_domain_apply_subtype, h] lemma equiv.perm.via_embedding_apply_not_mem_range {b : β} (h : b ∉ set.range f) : e.via_embedding f b = b := by rwa [equiv.perm.via_embedding, equiv.perm.extend_domain_apply_not_subtype] @[simp] lemma equiv.perm.via_embedding_sign [decidable_eq α] [fintype β] : equiv.perm.sign (e.via_embedding f) = equiv.perm.sign e := by simp [equiv.perm.via_embedding]
cdd1848923e4f15e21cc5374b105561b36066525
ebb7367fa8ab324601b5abf705720fd4cc0e8598
/homotopy/sample.hlean
54a787cad3a8422d336041f63f43d292fde79398
[ "Apache-2.0" ]
permissive
radams78/Spectral
3e34916d9bbd0939ee6a629e36744827ff27bfc2
c8145341046cfa2b4960ef3cc5a1117d12c43f63
refs/heads/master
1,610,421,583,830
1,481,232,014,000
1,481,232,014,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
6,372
hlean
/- Copyright (c) 2015 Ulrik Buchholtz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ulrik Buchholtz -/ import types.trunc types.arrow_2 types.fiber homotopy.susp open eq is_trunc is_equiv nat equiv trunc function fiber namespace homotopy definition is_conn [reducible] (n : trunc_index) (A : Type) : Type := is_contr (trunc n A) definition is_conn_equiv_closed (n : trunc_index) {A B : Type} : A ≃ B → is_conn n A → is_conn n B := begin intros H C, fapply @is_contr_equiv_closed (trunc n A) _, apply trunc_equiv_trunc, assumption end definition is_conn_fun (n : trunc_index) {A B : Type} (f : A → B) : Type := Πb : B, is_conn n (fiber f b) namespace is_conn_fun section parameters {n : trunc_index} {A B : Type} {h : A → B} (H : is_conn_fun n h) (P : B → n -Type) private definition helper : (Πa : A, P (h a)) → Πb : B, trunc n (fiber h b) → P b := λt b, trunc.rec (λx, point_eq x ▸ t (point x)) private definition g : (Πa : A, P (h a)) → (Πb : B, P b) := λt b, helper t b (@center (trunc n (fiber h b)) (H b)) -- induction principle for n-connected maps (Lemma 7.5.7) definition rec : is_equiv (λs : Πb : B, P b, λa : A, s (h a)) := adjointify (λs a, s (h a)) g begin intro t, apply eq_of_homotopy, intro a, unfold g, unfold helper, rewrite [@center_eq _ (H (h a)) (tr (fiber.mk a idp))], end begin intro k, apply eq_of_homotopy, intro b, unfold g, generalize (@center _ (H b)), apply trunc.rec, apply fiber.rec, intros a p, induction p, reflexivity end definition elim : (Πa : A, P (h a)) → (Πb : B, P b) := @is_equiv.inv _ _ (λs a, s (h a)) rec definition elim_β : Πf : (Πa : A, P (h a)), Πa : A, elim f (h a) = f a := λf, apd10 (@is_equiv.right_inv _ _ (λs a, s (h a)) rec f) end section universe variables u v parameters {n : trunc_index} {A : Type.{u}} {B : Type.{v}} {h : A → B} parameter sec : ΠP : B → trunctype.{max u v} n, is_retraction (λs : (Πb : B, P b), λ a, s (h a)) private definition s := sec (λb, trunctype.mk' n (trunc n (fiber h b))) include sec -- the other half of Lemma 7.5.7 definition intro : is_conn_fun n h := begin intro b, apply is_contr.mk (@is_retraction.sect _ _ _ s (λa, tr (fiber.mk a idp)) b), esimp, apply trunc.rec, apply fiber.rec, intros a p, apply transport (λz : (Σy, h a = y), @sect _ _ _ s (λa, tr (mk a idp)) (sigma.pr1 z) = tr (fiber.mk a (sigma.pr2 z))) (@center_eq _ (is_contr_sigma_eq (h a)) (sigma.mk b p)), exact apd10 (@right_inverse _ _ _ s (λa, tr (fiber.mk a idp))) a end end end is_conn_fun -- Connectedness is related to maps to and from the unit type, first to section parameters (n : trunc_index) (A : Type) definition is_conn_of_map_to_unit : is_conn_fun n (λx : A, unit.star) → is_conn n A := begin intro H, unfold is_conn_fun at H, rewrite [-(ua (fiber.fiber_star_equiv A))], exact (H unit.star) end -- now maps from unit definition is_conn_of_map_from_unit (a₀ : A) (H : is_conn_fun n (const unit a₀)) : is_conn n .+1 A := is_contr.mk (tr a₀) begin apply trunc.rec, intro a, exact trunc.elim (λz : fiber (const unit a₀) a, ap tr (point_eq z)) (@center _ (H a)) end definition is_conn_fun_from_unit (a₀ : A) [H : is_conn n .+1 A] : is_conn_fun n (const unit a₀) := begin intro a, apply is_conn_equiv_closed n (equiv.symm (fiber_const_equiv A a₀ a)), apply @is_contr_equiv_closed _ _ (tr_eq_tr_equiv n a₀ a), end end -- Lemma 7.5.2 definition minus_one_conn_of_surjective {A B : Type} (f : A → B) : is_surjective f → is_conn_fun -1 f := begin intro H, intro b, exact @is_contr_of_inhabited_prop (∥fiber f b∥) (is_trunc_trunc -1 (fiber f b)) (H b), end definition is_surjection_of_minus_one_conn {A B : Type} (f : A → B) : is_conn_fun -1 f → is_surjective f := begin intro H, intro b, exact @center (∥fiber f b∥) (H b), end definition merely_of_minus_one_conn {A : Type} : is_conn -1 A → ∥A∥ := λH, @center (∥A∥) H definition minus_one_conn_of_merely {A : Type} : ∥A∥ → is_conn -1 A := @is_contr_of_inhabited_prop (∥A∥) (is_trunc_trunc -1 A) section open arrow variables {f g : arrow} -- Lemma 7.5.4 definition retract_of_conn_is_conn [instance] (r : arrow_hom f g) [H : is_retraction r] (n : trunc_index) [K : is_conn_fun n f] : is_conn_fun n g := begin intro b, unfold is_conn, apply is_contr_retract (trunc_functor n (retraction_on_fiber r b)), exact K (on_cod (arrow.is_retraction.sect r) b) end end -- Corollary 7.5.5 definition is_conn_homotopy (n : trunc_index) {A B : Type} {f g : A → B} (p : f ~ g) (H : is_conn_fun n f) : is_conn_fun n g := @retract_of_conn_is_conn _ _ (arrow.arrow_hom_of_homotopy p) (arrow.is_retraction_arrow_hom_of_homotopy p) n H -- all types are -2-connected definition minus_two_conn [instance] (A : Type) : is_conn -2 A := _ -- Theorem 8.2.1 open susp definition is_conn_susp [instance] (n : trunc_index) (A : Type) [H : is_conn n A] : is_conn (n .+1) (susp A) := is_contr.mk (tr north) begin apply trunc.rec, fapply susp.rec, { reflexivity }, { exact (trunc.rec (λa, ap tr (merid a)) (center (trunc n A))) }, { intro a, generalize (center (trunc n A)), apply trunc.rec, intro a', apply pathover_of_tr_eq, rewrite [eq_transport_Fr,idp_con], revert H, induction n with [n, IH], { intro H, apply is_prop.elim }, { intros H, change ap (@tr n .+2 (susp A)) (merid a) = ap tr (merid a'), generalize a', apply is_conn_fun.elim (is_conn_fun_from_unit n A a) (λx : A, trunctype.mk' n (ap (@tr n .+2 (susp A)) (merid a) = ap tr (merid x))), intros, change ap (@tr n .+2 (susp A)) (merid a) = ap tr (merid a), reflexivity } } end end homotopy
0d4b41b203e47b2173ca4701aa086af5d8f504e7
64874bd1010548c7f5a6e3e8902efa63baaff785
/library/data/sigma.lean
c8c095b99a1be17b028dab7cd4181441eaa62b05
[ "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
3,431
lean
-- Copyright (c) 2014 Microsoft Corporation. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Author: Leonardo de Moura, Jeremy Avigad, Floris van Doorn import logic.cast open inhabited eq.ops sigma.ops namespace sigma universe variables u v variables {A A' : Type.{u}} {B : A → Type.{v}} {B' : A' → Type.{v}} definition unpack {C : (Σa, B a) → Type} {u : Σa, B a} (H : C ⟨u.1 , u.2⟩) : C u := destruct u (λx y H, H) H theorem dpair_eq {a₁ a₂ : A} {b₁ : B a₁} {b₂ : B a₂} (H₁ : a₁ = a₂) (H₂ : eq.rec_on H₁ b₁ = b₂) : ⟨a₁, b₁⟩ = ⟨a₂, b₂⟩ := dcongr_arg2 mk H₁ H₂ theorem dpair_heq {a : A} {a' : A'} {b : B a} {b' : B' a'} (HB : B == B') (Ha : a == a') (Hb : b == b') : ⟨a, b⟩ == ⟨a', b'⟩ := hcongr_arg4 @mk (heq.type_eq Ha) HB Ha Hb protected theorem equal {p₁ p₂ : Σa : A, B a} : ∀(H₁ : p₁.1 = p₂.1) (H₂ : eq.rec_on H₁ p₁.2 = p₂.2), p₁ = p₂ := destruct p₁ (take a₁ b₁, destruct p₂ (take a₂ b₂ H₁ H₂, dpair_eq H₁ H₂)) protected theorem hequal {p : Σa : A, B a} {p' : Σa' : A', B' a'} (HB : B == B') : ∀(H₁ : p.1 == p'.1) (H₂ : p.2 == p'.2), p == p' := destruct p (take a₁ b₁, destruct p' (take a₂ b₂ H₁ H₂, dpair_heq HB H₁ H₂)) protected definition is_inhabited [instance] (H₁ : inhabited A) (H₂ : inhabited (B (default A))) : inhabited (sigma B) := inhabited.destruct H₁ (λa, inhabited.destruct H₂ (λb, inhabited.mk ⟨default A, b⟩)) theorem eq_rec_dpair_commute {C : Πa, B a → Type} {a a' : A} (H : a = a') (b : B a) (c : C a b) : eq.rec_on H ⟨b, c⟩ = ⟨eq.rec_on H b, eq.rec_on (dcongr_arg2 C H rfl) c⟩ := eq.drec_on H (dpair_eq rfl (!eq.rec_on_id⁻¹)) variables {C : Πa, B a → Type} {D : Πa b, C a b → Type} definition dtrip (a : A) (b : B a) (c : C a b) := ⟨a, b, c⟩ definition dquad (a : A) (b : B a) (c : C a b) (d : D a b c) := ⟨a, b, c, d⟩ definition pr1' [reducible] (x : Σ a, B a) := x.1 definition pr2' [reducible] (x : Σ a b, C a b) := x.2.1 definition pr3 [reducible] (x : Σ a b, C a b) := x.2.2 definition pr3' [reducible] (x : Σ a b c, D a b c) := x.2.2.1 definition pr4 [reducible] (x : Σ a b c, D a b c) := x.2.2.2 theorem dtrip_eq {a₁ a₂ : A} {b₁ : B a₁} {b₂ : B a₂} {c₁ : C a₁ b₁} {c₂ : C a₂ b₂} (H₁ : a₁ = a₂) (H₂ : eq.rec_on H₁ b₁ = b₂) (H₃ : cast (dcongr_arg2 C H₁ H₂) c₁ = c₂) : ⟨a₁, b₁, c₁⟩ = ⟨a₂, b₂, c₂⟩ := dcongr_arg3 dtrip H₁ H₂ H₃ theorem ndtrip_eq {A B : Type} {C : A → B → Type} {a₁ a₂ : A} {b₁ b₂ : B} {c₁ : C a₁ b₁} {c₂ : C a₂ b₂} (H₁ : a₁ = a₂) (H₂ : b₁ = b₂) (H₃ : cast (congr_arg2 C H₁ H₂) c₁ = c₂) : ⟨a₁, b₁, c₁⟩ = ⟨a₂, b₂, c₂⟩ := hdcongr_arg3 dtrip H₁ (heq.of_eq H₂) H₃ theorem ndtrip_equal {A B : Type} {C : A → B → Type} {p₁ p₂ : Σa b, C a b} : ∀(H₁ : pr1 p₁ = pr1 p₂) (H₂ : pr2' p₁ = pr2' p₂) (H₃ : eq.rec_on (congr_arg2 C H₁ H₂) (pr3 p₁) = pr3 p₂), p₁ = p₂ := destruct p₁ (take a₁ q₁, destruct q₁ (take b₁ c₁, destruct p₂ (take a₂ q₂, destruct q₂ (take b₂ c₂ H₁ H₂ H₃, ndtrip_eq H₁ H₂ H₃)))) end sigma
d575e225902f7742b09f0c91d4db2fe8b5b21f96
26ac254ecb57ffcb886ff709cf018390161a9225
/src/analysis/special_functions/trigonometric.lean
660186f77d5d6ed16db0f172660ebaba68ef3198
[ "Apache-2.0" ]
permissive
eric-wieser/mathlib
42842584f584359bbe1fc8b88b3ff937c8acd72d
d0df6b81cd0920ad569158c06a3fd5abb9e63301
refs/heads/master
1,669,546,404,255
1,595,254,668,000
1,595,254,668,000
281,173,504
0
0
Apache-2.0
1,595,263,582,000
1,595,263,581,000
null
UTF-8
Lean
false
false
65,365
lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne -/ import analysis.special_functions.exp_log /-! # Trigonometric functions ## Main definitions This file contains the following definitions: * π, arcsin, arccos, arctan * argument of a complex number * logarithm on complex numbers ## Main statements Many basic inequalities on trigonometric functions are established. The continuity and differentiability of the usual trigonometric functions are proved, and their derivatives are computed. ## Tags log, sin, cos, tan, arcsin, arccos, arctan, angle, argument -/ noncomputable theory open_locale classical namespace complex /-- The complex sine function is everywhere differentiable, with the derivative `cos x`. -/ lemma has_deriv_at_sin (x : ℂ) : has_deriv_at sin (cos x) x := begin simp only [cos, div_eq_mul_inv], convert ((((has_deriv_at_id x).neg.mul_const I).cexp.sub ((has_deriv_at_id x).mul_const I).cexp).mul_const I).mul_const (2:ℂ)⁻¹, simp only [function.comp, id], rw [sub_mul, mul_assoc, mul_assoc, I_mul_I, neg_one_mul, neg_neg, mul_one, one_mul, mul_assoc, I_mul_I, mul_neg_one, sub_neg_eq_add, add_comm] end lemma differentiable_sin : differentiable ℂ sin := λx, (has_deriv_at_sin x).differentiable_at lemma differentiable_at_sin {x : ℂ} : differentiable_at ℂ sin x := differentiable_sin x @[simp] lemma deriv_sin : deriv sin = cos := funext $ λ x, (has_deriv_at_sin x).deriv lemma continuous_sin : continuous sin := differentiable_sin.continuous /-- The complex cosine function is everywhere differentiable, with the derivative `-sin x`. -/ lemma has_deriv_at_cos (x : ℂ) : has_deriv_at cos (-sin x) x := begin simp only [sin, div_eq_mul_inv, neg_mul_eq_neg_mul], convert (((has_deriv_at_id x).mul_const I).cexp.add ((has_deriv_at_id x).neg.mul_const I).cexp).mul_const (2:ℂ)⁻¹, simp only [function.comp, id], ring end lemma differentiable_cos : differentiable ℂ cos := λx, (has_deriv_at_cos x).differentiable_at lemma differentiable_at_cos {x : ℂ} : differentiable_at ℂ cos x := differentiable_cos x lemma deriv_cos {x : ℂ} : deriv cos x = -sin x := (has_deriv_at_cos x).deriv @[simp] lemma deriv_cos' : deriv cos = (λ x, -sin x) := funext $ λ x, deriv_cos lemma continuous_cos : continuous cos := differentiable_cos.continuous lemma continuous_tan : continuous (λ x : {x // cos x ≠ 0}, tan x) := (continuous_sin.comp continuous_subtype_val).mul (continuous.inv subtype.property (continuous_cos.comp continuous_subtype_val)) /-- The complex hyperbolic sine function is everywhere differentiable, with the derivative `sinh x`. -/ lemma has_deriv_at_sinh (x : ℂ) : has_deriv_at sinh (cosh x) x := begin simp only [cosh, div_eq_mul_inv], convert ((has_deriv_at_exp x).sub (has_deriv_at_id x).neg.cexp).mul_const (2:ℂ)⁻¹, rw [id, mul_neg_one, neg_neg] end lemma differentiable_sinh : differentiable ℂ sinh := λx, (has_deriv_at_sinh x).differentiable_at lemma differentiable_at_sinh {x : ℂ} : differentiable_at ℂ sinh x := differentiable_sinh x @[simp] lemma deriv_sinh : deriv sinh = cosh := funext $ λ x, (has_deriv_at_sinh x).deriv lemma continuous_sinh : continuous sinh := differentiable_sinh.continuous /-- The complex hyperbolic cosine function is everywhere differentiable, with the derivative `cosh x`. -/ lemma has_deriv_at_cosh (x : ℂ) : has_deriv_at cosh (sinh x) x := begin simp only [sinh, div_eq_mul_inv], convert ((has_deriv_at_exp x).add (has_deriv_at_id x).neg.cexp).mul_const (2:ℂ)⁻¹, rw [id, mul_neg_one, sub_eq_add_neg] end lemma differentiable_cosh : differentiable ℂ cosh := λx, (has_deriv_at_cosh x).differentiable_at lemma differentiable_at_cosh {x : ℂ} : differentiable_at ℂ cos x := differentiable_cos x @[simp] lemma deriv_cosh : deriv cosh = sinh := funext $ λ x, (has_deriv_at_cosh x).deriv lemma continuous_cosh : continuous cosh := differentiable_cosh.continuous end complex section /-! Register lemmas for the derivatives of the composition of `complex.cos`, `complex.sin`, `complex.cosh` and `complex.sinh` with a differentiable function, for standalone use and use with `simp`. -/ variables {f : ℂ → ℂ} {f' x : ℂ} {s : set ℂ} /-! `complex.cos`-/ lemma has_deriv_at.ccos (hf : has_deriv_at f f' x) : has_deriv_at (λ x, complex.cos (f x)) (- complex.sin (f x) * f') x := (complex.has_deriv_at_cos (f x)).comp x hf lemma has_deriv_within_at.ccos (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, complex.cos (f x)) (- complex.sin (f x) * f') s x := (complex.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf lemma differentiable_within_at.ccos (hf : differentiable_within_at ℂ f s x) : differentiable_within_at ℂ (λ x, complex.cos (f x)) s x := hf.has_deriv_within_at.ccos.differentiable_within_at @[simp] lemma differentiable_at.ccos (hc : differentiable_at ℂ f x) : differentiable_at ℂ (λx, complex.cos (f x)) x := hc.has_deriv_at.ccos.differentiable_at lemma differentiable_on.ccos (hc : differentiable_on ℂ f s) : differentiable_on ℂ (λx, complex.cos (f x)) s := λx h, (hc x h).ccos @[simp] lemma differentiable.ccos (hc : differentiable ℂ f) : differentiable ℂ (λx, complex.cos (f x)) := λx, (hc x).ccos lemma deriv_within_ccos (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : deriv_within (λx, complex.cos (f x)) s x = - complex.sin (f x) * (deriv_within f s x) := hf.has_deriv_within_at.ccos.deriv_within hxs @[simp] lemma deriv_ccos (hc : differentiable_at ℂ f x) : deriv (λx, complex.cos (f x)) x = - complex.sin (f x) * (deriv f x) := hc.has_deriv_at.ccos.deriv /-! `complex.sin`-/ lemma has_deriv_at.csin (hf : has_deriv_at f f' x) : has_deriv_at (λ x, complex.sin (f x)) (complex.cos (f x) * f') x := (complex.has_deriv_at_sin (f x)).comp x hf lemma has_deriv_within_at.csin (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, complex.sin (f x)) (complex.cos (f x) * f') s x := (complex.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf lemma differentiable_within_at.csin (hf : differentiable_within_at ℂ f s x) : differentiable_within_at ℂ (λ x, complex.sin (f x)) s x := hf.has_deriv_within_at.csin.differentiable_within_at @[simp] lemma differentiable_at.csin (hc : differentiable_at ℂ f x) : differentiable_at ℂ (λx, complex.sin (f x)) x := hc.has_deriv_at.csin.differentiable_at lemma differentiable_on.csin (hc : differentiable_on ℂ f s) : differentiable_on ℂ (λx, complex.sin (f x)) s := λx h, (hc x h).csin @[simp] lemma differentiable.csin (hc : differentiable ℂ f) : differentiable ℂ (λx, complex.sin (f x)) := λx, (hc x).csin lemma deriv_within_csin (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : deriv_within (λx, complex.sin (f x)) s x = complex.cos (f x) * (deriv_within f s x) := hf.has_deriv_within_at.csin.deriv_within hxs @[simp] lemma deriv_csin (hc : differentiable_at ℂ f x) : deriv (λx, complex.sin (f x)) x = complex.cos (f x) * (deriv f x) := hc.has_deriv_at.csin.deriv /-! `complex.cosh`-/ lemma has_deriv_at.ccosh (hf : has_deriv_at f f' x) : has_deriv_at (λ x, complex.cosh (f x)) (complex.sinh (f x) * f') x := (complex.has_deriv_at_cosh (f x)).comp x hf lemma has_deriv_within_at.ccosh (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, complex.cosh (f x)) (complex.sinh (f x) * f') s x := (complex.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf lemma differentiable_within_at.ccosh (hf : differentiable_within_at ℂ f s x) : differentiable_within_at ℂ (λ x, complex.cosh (f x)) s x := hf.has_deriv_within_at.ccosh.differentiable_within_at @[simp] lemma differentiable_at.ccosh (hc : differentiable_at ℂ f x) : differentiable_at ℂ (λx, complex.cosh (f x)) x := hc.has_deriv_at.ccosh.differentiable_at lemma differentiable_on.ccosh (hc : differentiable_on ℂ f s) : differentiable_on ℂ (λx, complex.cosh (f x)) s := λx h, (hc x h).ccosh @[simp] lemma differentiable.ccosh (hc : differentiable ℂ f) : differentiable ℂ (λx, complex.cosh (f x)) := λx, (hc x).ccosh lemma deriv_within_ccosh (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : deriv_within (λx, complex.cosh (f x)) s x = complex.sinh (f x) * (deriv_within f s x) := hf.has_deriv_within_at.ccosh.deriv_within hxs @[simp] lemma deriv_ccosh (hc : differentiable_at ℂ f x) : deriv (λx, complex.cosh (f x)) x = complex.sinh (f x) * (deriv f x) := hc.has_deriv_at.ccosh.deriv /-! `complex.sinh`-/ lemma has_deriv_at.csinh (hf : has_deriv_at f f' x) : has_deriv_at (λ x, complex.sinh (f x)) (complex.cosh (f x) * f') x := (complex.has_deriv_at_sinh (f x)).comp x hf lemma has_deriv_within_at.csinh (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, complex.sinh (f x)) (complex.cosh (f x) * f') s x := (complex.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf lemma differentiable_within_at.csinh (hf : differentiable_within_at ℂ f s x) : differentiable_within_at ℂ (λ x, complex.sinh (f x)) s x := hf.has_deriv_within_at.csinh.differentiable_within_at @[simp] lemma differentiable_at.csinh (hc : differentiable_at ℂ f x) : differentiable_at ℂ (λx, complex.sinh (f x)) x := hc.has_deriv_at.csinh.differentiable_at lemma differentiable_on.csinh (hc : differentiable_on ℂ f s) : differentiable_on ℂ (λx, complex.sinh (f x)) s := λx h, (hc x h).csinh @[simp] lemma differentiable.csinh (hc : differentiable ℂ f) : differentiable ℂ (λx, complex.sinh (f x)) := λx, (hc x).csinh lemma deriv_within_csinh (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : deriv_within (λx, complex.sinh (f x)) s x = complex.cosh (f x) * (deriv_within f s x) := hf.has_deriv_within_at.csinh.deriv_within hxs @[simp] lemma deriv_csinh (hc : differentiable_at ℂ f x) : deriv (λx, complex.sinh (f x)) x = complex.cosh (f x) * (deriv f x) := hc.has_deriv_at.csinh.deriv end namespace real variables {x y z : ℝ} lemma has_deriv_at_sin (x : ℝ) : has_deriv_at sin (cos x) x := has_deriv_at_real_of_complex (complex.has_deriv_at_sin x) lemma differentiable_sin : differentiable ℝ sin := λx, (has_deriv_at_sin x).differentiable_at lemma differentiable_at_sin : differentiable_at ℝ sin x := differentiable_sin x @[simp] lemma deriv_sin : deriv sin = cos := funext $ λ x, (has_deriv_at_sin x).deriv lemma continuous_sin : continuous sin := differentiable_sin.continuous lemma has_deriv_at_cos (x : ℝ) : has_deriv_at cos (-sin x) x := (has_deriv_at_real_of_complex (complex.has_deriv_at_cos x) : _) lemma differentiable_cos : differentiable ℝ cos := λx, (has_deriv_at_cos x).differentiable_at lemma differentiable_at_cos : differentiable_at ℝ cos x := differentiable_cos x lemma deriv_cos : deriv cos x = - sin x := (has_deriv_at_cos x).deriv @[simp] lemma deriv_cos' : deriv cos = (λ x, - sin x) := funext $ λ _, deriv_cos lemma continuous_cos : continuous cos := differentiable_cos.continuous lemma continuous_tan : continuous (λ x : {x // cos x ≠ 0}, tan x) := by simp only [tan_eq_sin_div_cos]; exact (continuous_sin.comp continuous_subtype_val).mul (continuous.inv subtype.property (continuous_cos.comp continuous_subtype_val)) lemma has_deriv_at_sinh (x : ℝ) : has_deriv_at sinh (cosh x) x := has_deriv_at_real_of_complex (complex.has_deriv_at_sinh x) lemma differentiable_sinh : differentiable ℝ sinh := λx, (has_deriv_at_sinh x).differentiable_at lemma differentiable_at_sinh : differentiable_at ℝ sinh x := differentiable_sinh x @[simp] lemma deriv_sinh : deriv sinh = cosh := funext $ λ x, (has_deriv_at_sinh x).deriv lemma continuous_sinh : continuous sinh := differentiable_sinh.continuous lemma has_deriv_at_cosh (x : ℝ) : has_deriv_at cosh (sinh x) x := has_deriv_at_real_of_complex (complex.has_deriv_at_cosh x) lemma differentiable_cosh : differentiable ℝ cosh := λx, (has_deriv_at_cosh x).differentiable_at lemma differentiable_at_cosh : differentiable_at ℝ cosh x := differentiable_cosh x @[simp] lemma deriv_cosh : deriv cosh = sinh := funext $ λ x, (has_deriv_at_cosh x).deriv lemma continuous_cosh : continuous cosh := differentiable_cosh.continuous end real section /-! Register lemmas for the derivatives of the composition of `real.exp`, `real.cos`, `real.sin`, `real.cosh` and `real.sinh` with a differentiable function, for standalone use and use with `simp`. -/ variables {f : ℝ → ℝ} {f' x : ℝ} {s : set ℝ} /-! `real.cos`-/ lemma has_deriv_at.cos (hf : has_deriv_at f f' x) : has_deriv_at (λ x, real.cos (f x)) (- real.sin (f x) * f') x := (real.has_deriv_at_cos (f x)).comp x hf lemma has_deriv_within_at.cos (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, real.cos (f x)) (- real.sin (f x) * f') s x := (real.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf lemma differentiable_within_at.cos (hf : differentiable_within_at ℝ f s x) : differentiable_within_at ℝ (λ x, real.cos (f x)) s x := hf.has_deriv_within_at.cos.differentiable_within_at @[simp] lemma differentiable_at.cos (hc : differentiable_at ℝ f x) : differentiable_at ℝ (λx, real.cos (f x)) x := hc.has_deriv_at.cos.differentiable_at lemma differentiable_on.cos (hc : differentiable_on ℝ f s) : differentiable_on ℝ (λx, real.cos (f x)) s := λx h, (hc x h).cos @[simp] lemma differentiable.cos (hc : differentiable ℝ f) : differentiable ℝ (λx, real.cos (f x)) := λx, (hc x).cos lemma deriv_within_cos (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : deriv_within (λx, real.cos (f x)) s x = - real.sin (f x) * (deriv_within f s x) := hf.has_deriv_within_at.cos.deriv_within hxs @[simp] lemma deriv_cos (hc : differentiable_at ℝ f x) : deriv (λx, real.cos (f x)) x = - real.sin (f x) * (deriv f x) := hc.has_deriv_at.cos.deriv /-! `real.sin`-/ lemma has_deriv_at.sin (hf : has_deriv_at f f' x) : has_deriv_at (λ x, real.sin (f x)) (real.cos (f x) * f') x := (real.has_deriv_at_sin (f x)).comp x hf lemma has_deriv_within_at.sin (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, real.sin (f x)) (real.cos (f x) * f') s x := (real.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf lemma differentiable_within_at.sin (hf : differentiable_within_at ℝ f s x) : differentiable_within_at ℝ (λ x, real.sin (f x)) s x := hf.has_deriv_within_at.sin.differentiable_within_at @[simp] lemma differentiable_at.sin (hc : differentiable_at ℝ f x) : differentiable_at ℝ (λx, real.sin (f x)) x := hc.has_deriv_at.sin.differentiable_at lemma differentiable_on.sin (hc : differentiable_on ℝ f s) : differentiable_on ℝ (λx, real.sin (f x)) s := λx h, (hc x h).sin @[simp] lemma differentiable.sin (hc : differentiable ℝ f) : differentiable ℝ (λx, real.sin (f x)) := λx, (hc x).sin lemma deriv_within_sin (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : deriv_within (λx, real.sin (f x)) s x = real.cos (f x) * (deriv_within f s x) := hf.has_deriv_within_at.sin.deriv_within hxs @[simp] lemma deriv_sin (hc : differentiable_at ℝ f x) : deriv (λx, real.sin (f x)) x = real.cos (f x) * (deriv f x) := hc.has_deriv_at.sin.deriv /-! `real.cosh`-/ lemma has_deriv_at.cosh (hf : has_deriv_at f f' x) : has_deriv_at (λ x, real.cosh (f x)) (real.sinh (f x) * f') x := (real.has_deriv_at_cosh (f x)).comp x hf lemma has_deriv_within_at.cosh (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, real.cosh (f x)) (real.sinh (f x) * f') s x := (real.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf lemma differentiable_within_at.cosh (hf : differentiable_within_at ℝ f s x) : differentiable_within_at ℝ (λ x, real.cosh (f x)) s x := hf.has_deriv_within_at.cosh.differentiable_within_at @[simp] lemma differentiable_at.cosh (hc : differentiable_at ℝ f x) : differentiable_at ℝ (λx, real.cosh (f x)) x := hc.has_deriv_at.cosh.differentiable_at lemma differentiable_on.cosh (hc : differentiable_on ℝ f s) : differentiable_on ℝ (λx, real.cosh (f x)) s := λx h, (hc x h).cosh @[simp] lemma differentiable.cosh (hc : differentiable ℝ f) : differentiable ℝ (λx, real.cosh (f x)) := λx, (hc x).cosh lemma deriv_within_cosh (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : deriv_within (λx, real.cosh (f x)) s x = real.sinh (f x) * (deriv_within f s x) := hf.has_deriv_within_at.cosh.deriv_within hxs @[simp] lemma deriv_cosh (hc : differentiable_at ℝ f x) : deriv (λx, real.cosh (f x)) x = real.sinh (f x) * (deriv f x) := hc.has_deriv_at.cosh.deriv /-! `real.sinh`-/ lemma has_deriv_at.sinh (hf : has_deriv_at f f' x) : has_deriv_at (λ x, real.sinh (f x)) (real.cosh (f x) * f') x := (real.has_deriv_at_sinh (f x)).comp x hf lemma has_deriv_within_at.sinh (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (λ x, real.sinh (f x)) (real.cosh (f x) * f') s x := (real.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf lemma differentiable_within_at.sinh (hf : differentiable_within_at ℝ f s x) : differentiable_within_at ℝ (λ x, real.sinh (f x)) s x := hf.has_deriv_within_at.sinh.differentiable_within_at @[simp] lemma differentiable_at.sinh (hc : differentiable_at ℝ f x) : differentiable_at ℝ (λx, real.sinh (f x)) x := hc.has_deriv_at.sinh.differentiable_at lemma differentiable_on.sinh (hc : differentiable_on ℝ f s) : differentiable_on ℝ (λx, real.sinh (f x)) s := λx h, (hc x h).sinh @[simp] lemma differentiable.sinh (hc : differentiable ℝ f) : differentiable ℝ (λx, real.sinh (f x)) := λx, (hc x).sinh lemma deriv_within_sinh (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : deriv_within (λx, real.sinh (f x)) s x = real.cosh (f x) * (deriv_within f s x) := hf.has_deriv_within_at.sinh.deriv_within hxs @[simp] lemma deriv_sinh (hc : differentiable_at ℝ f x) : deriv (λx, real.sinh (f x)) x = real.cosh (f x) * (deriv f x) := hc.has_deriv_at.sinh.deriv end namespace real lemma exists_cos_eq_zero : 0 ∈ cos '' set.Icc (1:ℝ) 2 := intermediate_value_Icc' (by norm_num) continuous_cos.continuous_on ⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩ /-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from which one can derive all its properties. For explicit bounds on π, see `data.real.pi`. -/ noncomputable def pi : ℝ := 2 * classical.some exists_cos_eq_zero localized "notation `π` := real.pi" in real @[simp] lemma cos_pi_div_two : cos (π / 2) = 0 := by rw [pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)]; exact (classical.some_spec exists_cos_eq_zero).2 lemma one_le_pi_div_two : (1 : ℝ) ≤ π / 2 := by rw [pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)]; exact (classical.some_spec exists_cos_eq_zero).1.1 lemma pi_div_two_le_two : π / 2 ≤ 2 := by rw [pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)]; exact (classical.some_spec exists_cos_eq_zero).1.2 lemma two_le_pi : (2 : ℝ) ≤ π := (div_le_div_right (show (0 : ℝ) < 2, by norm_num)).1 (by rw div_self (@two_ne_zero' ℝ _ _ _); exact one_le_pi_div_two) lemma pi_le_four : π ≤ 4 := (div_le_div_right (show (0 : ℝ) < 2, by norm_num)).1 (calc π / 2 ≤ 2 : pi_div_two_le_two ... = 4 / 2 : by norm_num) lemma pi_pos : 0 < π := lt_of_lt_of_le (by norm_num) two_le_pi lemma pi_div_two_pos : 0 < π / 2 := half_pos pi_pos lemma two_pi_pos : 0 < 2 * π := by linarith [pi_pos] @[simp] lemma sin_pi : sin π = 0 := by rw [← mul_div_cancel_left pi (@two_ne_zero ℝ _), two_mul, add_div, sin_add, cos_pi_div_two]; simp @[simp] lemma cos_pi : cos π = -1 := by rw [← mul_div_cancel_left pi (@two_ne_zero ℝ _), mul_div_assoc, cos_two_mul, cos_pi_div_two]; simp [bit0, pow_add] @[simp] lemma sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add] @[simp] lemma cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add] lemma sin_add_pi (x : ℝ) : sin (x + π) = -sin x := by simp [sin_add] lemma sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x := by simp [sin_add_pi, sin_add, sin_two_pi, cos_two_pi] lemma cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x := by simp [cos_add, cos_two_pi, sin_two_pi] lemma sin_pi_sub (x : ℝ) : sin (π - x) = sin x := by simp [sub_eq_add_neg, sin_add] lemma cos_add_pi (x : ℝ) : cos (x + π) = -cos x := by simp [cos_add] lemma cos_pi_sub (x : ℝ) : cos (π - x) = -cos x := by simp [sub_eq_add_neg, cos_add] lemma sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x := if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2 else have (2 : ℝ) + 2 = 4, from rfl, have π - x ≤ 2, from sub_le_iff_le_add.2 (le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _)), sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this lemma sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x := match lt_or_eq_of_le h0x with | or.inl h0x := (lt_or_eq_of_le hxp).elim (le_of_lt ∘ sin_pos_of_pos_of_lt_pi h0x) (λ hpx, by simp [hpx]) | or.inr h0x := by simp [h0x.symm] end lemma sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 := neg_pos.1 $ sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx) lemma sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 := neg_nonneg.1 $ sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx) @[simp] lemma sin_pi_div_two : sin (π / 2) = 1 := have sin (π / 2) = 1 ∨ sin (π / 2) = -1 := by simpa [pow_two, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2), this.resolve_right (λ h, (show ¬(0 : ℝ) < -1, by norm_num) $ h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos)) lemma sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x := by simp [sin_add] lemma sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add] lemma sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add] lemma cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x := by simp [cos_add] lemma cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x := by simp [sub_eq_add_neg, cos_add] lemma cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x := by rw [← cos_neg, neg_sub, cos_sub_pi_div_two] lemma cos_pos_of_neg_pi_div_two_lt_of_lt_pi_div_two {x : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) : 0 < cos x := sin_add_pi_div_two x ▸ sin_pos_of_pos_of_lt_pi (by linarith) (by linarith) lemma cos_nonneg_of_neg_pi_div_two_le_of_le_pi_div_two {x : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : 0 ≤ cos x := match lt_or_eq_of_le hx₁, lt_or_eq_of_le hx₂ with | or.inl hx₁, or.inl hx₂ := le_of_lt (cos_pos_of_neg_pi_div_two_lt_of_lt_pi_div_two hx₁ hx₂) | or.inl hx₁, or.inr hx₂ := by simp [hx₂] | or.inr hx₁, _ := by simp [hx₁.symm] end lemma cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) : cos x < 0 := neg_pos.1 $ cos_pi_sub x ▸ cos_pos_of_neg_pi_div_two_lt_of_lt_pi_div_two (by linarith) (by linarith) lemma cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≤ x) (hx₂ : x ≤ π + π / 2) : cos x ≤ 0 := neg_nonneg.1 $ cos_pi_sub x ▸ cos_nonneg_of_neg_pi_div_two_le_of_le_pi_div_two (by linarith) (by linarith) lemma sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 := by induction n; simp [add_mul, sin_add, *] lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 := by cases n; simp [add_mul, sin_add, *, sin_nat_mul_pi] lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 := by induction n; simp [*, mul_add, cos_add, add_mul, cos_two_pi, sin_two_pi] lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 := by cases n; simp only [cos_nat_mul_two_pi, int.of_nat_eq_coe, int.neg_succ_of_nat_coe, int.cast_coe_nat, int.cast_neg, (neg_mul_eq_neg_mul _ _).symm, cos_neg] lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 := by simp [cos_add, sin_add, cos_int_mul_two_pi] lemma sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -π < x) (hx₂ : x < π) : sin x = 0 ↔ x = 0 := ⟨λ h, le_antisymm (le_of_not_gt (λ h0, lt_irrefl (0 : ℝ) $ calc 0 < sin x : sin_pos_of_pos_of_lt_pi h0 hx₂ ... = 0 : h)) (le_of_not_gt (λ h0, lt_irrefl (0 : ℝ) $ calc 0 = sin x : h.symm ... < 0 : sin_neg_of_neg_of_neg_pi_lt h0 hx₁)), λ h, by simp [h]⟩ lemma sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : ℤ, (n : ℝ) * π = x := ⟨λ h, ⟨⌊x / π⌋, le_antisymm (sub_nonneg.1 (sub_floor_div_mul_nonneg _ pi_pos)) (sub_nonpos.1 $ le_of_not_gt $ λ h₃, ne_of_lt (sin_pos_of_pos_of_lt_pi h₃ (sub_floor_div_mul_lt _ pi_pos)) (by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩, λ ⟨n, hn⟩, hn ▸ sin_int_mul_pi _⟩ lemma sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 := by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x, pow_two, pow_two, ← sub_eq_iff_eq_add, sub_self]; exact ⟨λ h, by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ eq.symm⟩ theorem sin_sub_sin (θ ψ : ℝ) : sin θ - sin ψ = 2 * sin((θ - ψ)/2) * cos((θ + ψ)/2) := begin have s1 := sin_add ((θ + ψ) / 2) ((θ - ψ) / 2), have s2 := sin_sub ((θ + ψ) / 2) ((θ - ψ) / 2), rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel, add_self_div_two] at s1, rw [div_sub_div_same, ←sub_add, add_sub_cancel', add_self_div_two] at s2, rw [s1, s2, ←sub_add, add_sub_cancel', ← two_mul, ← mul_assoc, mul_right_comm] end lemma cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : ℤ, (n : ℝ) * (2 * π) = x := ⟨λ h, let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (or.inl h)) in ⟨n / 2, (int.mod_two_eq_zero_or_one n).elim (λ hn0, by rwa [← mul_assoc, ← @int.cast_two ℝ, ← int.cast_mul, int.div_mul_cancel ((int.dvd_iff_mod_eq_zero _ _).2 hn0)]) (λ hn1, by rw [← int.mod_add_div n 2, hn1, int.cast_add, int.cast_one, add_mul, one_mul, add_comm, mul_comm (2 : ℤ), int.cast_mul, mul_assoc, int.cast_two] at hn; rw [← hn, cos_int_mul_two_pi_add_pi] at h; exact absurd h (by norm_num))⟩, λ ⟨n, hn⟩, hn ▸ cos_int_mul_two_pi _⟩ theorem cos_eq_zero_iff {θ : ℝ} : cos θ = 0 ↔ ∃ k : ℤ, θ = (2 * k + 1) * pi / 2 := begin rw [←real.sin_pi_div_two_sub, sin_eq_zero_iff], split, { rintro ⟨n, hn⟩, existsi -n, rw [int.cast_neg, add_mul, add_div, mul_assoc, mul_div_cancel_left _ (@two_ne_zero ℝ _), one_mul, ←neg_mul_eq_neg_mul, hn, neg_sub, sub_add_cancel] }, { rintro ⟨n, hn⟩, existsi -n, rw [hn, add_mul, one_mul, add_div, mul_assoc, mul_div_cancel_left _ (@two_ne_zero ℝ _), sub_add_eq_sub_sub_swap, sub_self, zero_sub, neg_mul_eq_neg_mul, int.cast_neg] } end lemma cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x < 2 * π) : cos x = 1 ↔ x = 0 := ⟨λ h, let ⟨n, hn⟩ := (cos_eq_one_iff x).1 h in begin clear _let_match, subst hn, rw [mul_lt_iff_lt_one_left two_pi_pos, ← int.cast_one, int.cast_lt, ← int.le_sub_one_iff, sub_self] at hx₂, rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos, neg_lt, ← int.cast_one, ← int.cast_neg, int.cast_lt, ← int.add_one_le_iff, neg_add_self] at hx₁, exact mul_eq_zero.2 (or.inl (int.cast_eq_zero.2 (le_antisymm hx₂ hx₁))), end, λ h, by simp [h]⟩ theorem cos_sub_cos (θ ψ : ℝ) : cos θ - cos ψ = -2 * sin((θ + ψ)/2) * sin((θ - ψ)/2) := by rw [← sin_pi_div_two_sub, ← sin_pi_div_two_sub, sin_sub_sin, sub_sub_sub_cancel_left, add_sub, sub_add_eq_add_sub, add_halves, sub_sub, sub_div π, cos_pi_div_two_sub, ← neg_sub, neg_div, sin_neg, ← neg_mul_eq_mul_neg, neg_mul_eq_neg_mul, mul_right_comm] lemma cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π / 2) (hxy : x < y) : cos y < cos x := calc cos y = cos x * cos (y - x) - sin x * sin (y - x) : by rw [← cos_add, add_sub_cancel'_right] ... < (cos x * 1) - sin x * sin (y - x) : sub_lt_sub_right ((mul_lt_mul_left (cos_pos_of_neg_pi_div_two_lt_of_lt_pi_div_two (lt_of_lt_of_le (neg_neg_of_pos pi_div_two_pos) hx₁) (lt_of_lt_of_le hxy hy₂))).2 (lt_of_le_of_ne (cos_le_one _) (mt (cos_eq_one_iff_of_lt_of_lt (show -(2 * π) < y - x, by linarith) (show y - x < 2 * π, by linarith)).1 (sub_ne_zero.2 (ne_of_lt hxy).symm)))) _ ... ≤ _ : by rw mul_one; exact sub_le_self _ (mul_nonneg (sin_nonneg_of_nonneg_of_le_pi hx₁ (by linarith)) (sin_nonneg_of_nonneg_of_le_pi (by linarith) (by linarith))) lemma cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x < y) : cos y < cos x := match (le_total x (π / 2) : x ≤ π / 2 ∨ π / 2 ≤ x), le_total y (π / 2) with | or.inl hx, or.inl hy := cos_lt_cos_of_nonneg_of_le_pi_div_two hx₁ hy hxy | or.inl hx, or.inr hy := (lt_or_eq_of_le hx).elim (λ hx, calc cos y ≤ 0 : cos_nonpos_of_pi_div_two_le_of_le hy (by linarith [pi_pos]) ... < cos x : cos_pos_of_neg_pi_div_two_lt_of_lt_pi_div_two (by linarith) hx) (λ hx, calc cos y < 0 : cos_neg_of_pi_div_two_lt_of_lt (by linarith) (by linarith [pi_pos]) ... = cos x : by rw [hx, cos_pi_div_two]) | or.inr hx, or.inl hy := by linarith | or.inr hx, or.inr hy := neg_lt_neg_iff.1 (by rw [← cos_pi_sub, ← cos_pi_sub]; apply cos_lt_cos_of_nonneg_of_le_pi_div_two; linarith) end lemma cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x ≤ y) : cos y ≤ cos x := (lt_or_eq_of_le hxy).elim (le_of_lt ∘ cos_lt_cos_of_nonneg_of_le_pi hx₁ hy₂) (λ h, h ▸ le_refl _) lemma sin_lt_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2) (hxy : x < y) : sin x < sin y := by rw [← cos_sub_pi_div_two, ← cos_sub_pi_div_two, ← cos_neg (x - _), ← cos_neg (y - _)]; apply cos_lt_cos_of_nonneg_of_le_pi; linarith lemma sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2) (hxy : x ≤ y) : sin x ≤ sin y := (lt_or_eq_of_le hxy).elim (le_of_lt ∘ sin_lt_sin_of_le_of_le_pi_div_two hx₁ hy₂) (λ h, h ▸ le_refl _) lemma sin_inj_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) (hy₁ : -(π / 2) ≤ y) (hy₂ : y ≤ π / 2) (hxy : sin x = sin y) : x = y := match lt_trichotomy x y with | or.inl h := absurd (sin_lt_sin_of_le_of_le_pi_div_two hx₁ hy₂ h) (by rw hxy; exact lt_irrefl _) | or.inr (or.inl h) := h | or.inr (or.inr h) := absurd (sin_lt_sin_of_le_of_le_pi_div_two hy₁ hx₂ h) (by rw hxy; exact lt_irrefl _) end lemma cos_inj_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π) (hy₁ : 0 ≤ y) (hy₂ : y ≤ π) (hxy : cos x = cos y) : x = y := begin rw [← sin_pi_div_two_sub, ← sin_pi_div_two_sub] at hxy, refine (sub_right_inj).1 (sin_inj_of_le_of_le_pi_div_two _ _ _ _ hxy); linarith end lemma exists_sin_eq : set.Icc (-1:ℝ) 1 ⊆ sin '' set.Icc (-(π / 2)) (π / 2) := by convert intermediate_value_Icc (le_trans (neg_nonpos.2 (le_of_lt pi_div_two_pos)) (le_of_lt pi_div_two_pos)) continuous_sin.continuous_on; simp only [sin_neg, sin_pi_div_two] lemma sin_lt {x : ℝ} (h : 0 < x) : sin x < x := begin cases le_or_gt x 1 with h' h', { have hx : abs x = x := abs_of_nonneg (le_of_lt h), have : abs x ≤ 1, rwa [hx], have := sin_bound this, rw [abs_le] at this, have := this.2, rw [sub_le_iff_le_add', hx] at this, apply lt_of_le_of_lt this, rw [sub_add], apply lt_of_lt_of_le _ (le_of_eq (sub_zero x)), apply sub_lt_sub_left, rw sub_pos, apply mul_lt_mul', { rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)), rw mul_le_mul_right, exact h', apply pow_pos h }, norm_num, norm_num, apply pow_pos h }, exact lt_of_le_of_lt (sin_le_one x) h' end /- note 1: this inequality is not tight, the tighter inequality is sin x > x - x ^ 3 / 6. note 2: this is also true for x > 1, but it's nontrivial for x just above 1. -/ lemma sin_gt_sub_cube {x : ℝ} (h : 0 < x) (h' : x ≤ 1) : x - x ^ 3 / 4 < sin x := begin have hx : abs x = x := abs_of_nonneg (le_of_lt h), have : abs x ≤ 1, rwa [hx], have := sin_bound this, rw [abs_le] at this, have := this.1, rw [le_sub_iff_add_le, hx] at this, refine lt_of_lt_of_le _ this, rw [add_comm, sub_add, sub_neg_eq_add], apply sub_lt_sub_left, apply add_lt_of_lt_sub_left, rw (show x ^ 3 / 4 - x ^ 3 / 6 = x ^ 3 / 12, by simp [div_eq_mul_inv, (mul_sub _ _ _).symm, -sub_eq_add_neg]; congr; norm_num), apply mul_lt_mul', { rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)), rw mul_le_mul_right, exact h', apply pow_pos h }, norm_num, norm_num, apply pow_pos h end /-- The type of angles -/ def angle : Type := quotient_add_group.quotient (gmultiples (2 * π)) namespace angle instance angle.add_comm_group : add_comm_group angle := quotient_add_group.add_comm_group _ instance : inhabited angle := ⟨0⟩ instance angle.has_coe : has_coe ℝ angle := ⟨quotient.mk'⟩ instance angle.is_add_group_hom : @is_add_group_hom ℝ angle _ _ (coe : ℝ → angle) := @quotient_add_group.is_add_group_hom _ _ _ (normal_add_subgroup_of_add_comm_group _) @[simp] lemma coe_zero : ↑(0 : ℝ) = (0 : angle) := rfl @[simp] lemma coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : angle) := rfl @[simp] lemma coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : angle) := rfl @[simp] lemma coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : angle) := rfl @[simp, norm_cast] lemma coe_nat_mul_eq_nsmul (x : ℝ) (n : ℕ) : ↑((n : ℝ) * x) = n •ℕ (↑x : angle) := by simpa using add_monoid_hom.map_nsmul ⟨coe, coe_zero, coe_add⟩ _ _ @[simp, norm_cast] lemma coe_int_mul_eq_gsmul (x : ℝ) (n : ℤ) : ↑((n : ℝ) * x : ℝ) = n •ℤ (↑x : angle) := by simpa using add_monoid_hom.map_gsmul ⟨coe, coe_zero, coe_add⟩ _ _ @[simp] lemma coe_two_pi : ↑(2 * π : ℝ) = (0 : angle) := quotient.sound' ⟨-1, by dsimp only; rw [neg_one_gsmul, add_zero]⟩ lemma angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k := by simp only [quotient_add_group.eq, gmultiples, set.mem_range, gsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] theorem cos_eq_iff_eq_or_eq_neg {θ ψ : ℝ} : cos θ = cos ψ ↔ (θ : angle) = ψ ∨ (θ : angle) = -ψ := begin split, { intro Hcos, rw [←sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero, eq_false_intro two_ne_zero, false_or, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos, rcases Hcos with ⟨n, hn⟩ | ⟨n, hn⟩, { right, rw [eq_div_iff_mul_eq (@two_ne_zero ℝ _), ← sub_eq_iff_eq_add] at hn, rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc, coe_int_mul_eq_gsmul, mul_comm, coe_two_pi, gsmul_zero] }, { left, rw [eq_div_iff_mul_eq (@two_ne_zero ℝ _), eq_sub_iff_add_eq] at hn, rw [← hn, coe_add, mul_assoc, coe_int_mul_eq_gsmul, mul_comm, coe_two_pi, gsmul_zero, zero_add] } }, { rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub], rintro (⟨k, H⟩ | ⟨k, H⟩), rw [← sub_eq_zero_iff_eq, cos_sub_cos, H, mul_assoc 2 π k, mul_div_cancel_left _ (@two_ne_zero ℝ _), mul_comm π _, sin_int_mul_pi, mul_zero], rw [←sub_eq_zero_iff_eq, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k, mul_div_cancel_left _ (@two_ne_zero ℝ _), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] } end theorem sin_eq_iff_eq_or_add_eq_pi {θ ψ : ℝ} : sin θ = sin ψ ↔ (θ : angle) = ψ ∨ (θ : angle) + ψ = π := begin split, { intro Hsin, rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin, cases cos_eq_iff_eq_or_eq_neg.mp Hsin with h h, { left, rw coe_sub at h, exact sub_right_inj.1 h }, right, rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub, sub_add_eq_add_sub, ← coe_add, add_halves, sub_sub, sub_eq_zero] at h, exact h.symm }, { rw [angle_eq_iff_two_pi_dvd_sub, ←eq_sub_iff_add_eq, ←coe_sub, angle_eq_iff_two_pi_dvd_sub], rintro (⟨k, H⟩ | ⟨k, H⟩), rw [← sub_eq_zero_iff_eq, sin_sub_sin, H, mul_assoc 2 π k, mul_div_cancel_left _ (@two_ne_zero ℝ _), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul], have H' : θ + ψ = (2 * k) * π + π := by rwa [←sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add, mul_assoc, mul_comm π _, ←mul_assoc] at H, rw [← sub_eq_zero_iff_eq, sin_sub_sin, H', add_div, mul_assoc 2 _ π, mul_div_cancel_left _ (@two_ne_zero ℝ _), cos_add_pi_div_two, sin_int_mul_pi, neg_zero, mul_zero] } end theorem cos_sin_inj {θ ψ : ℝ} (Hcos : cos θ = cos ψ) (Hsin : sin θ = sin ψ) : (θ : angle) = ψ := begin cases cos_eq_iff_eq_or_eq_neg.mp Hcos with hc hc, { exact hc }, cases sin_eq_iff_eq_or_add_eq_pi.mp Hsin with hs hs, { exact hs }, rw [eq_neg_iff_add_eq_zero, hs] at hc, cases quotient.exact' hc with n hn, dsimp only at hn, rw [← neg_one_mul, add_zero, ← sub_eq_zero_iff_eq, gsmul_eq_mul, ← mul_assoc, ← sub_mul, mul_eq_zero, eq_false_intro (ne_of_gt pi_pos), or_false, sub_neg_eq_add, ← int.cast_zero, ← int.cast_one, ← int.cast_bit0, ← int.cast_mul, ← int.cast_add, int.cast_inj] at hn, have : (n * 2 + 1) % (2:ℤ) = 0 % (2:ℤ) := congr_arg (%(2:ℤ)) hn, rw [add_comm, int.add_mul_mod_self] at this, exact absurd this one_ne_zero end end angle /-- Inverse of the `sin` function, returns values in the range `-π / 2 ≤ arcsin x` and `arcsin x ≤ π / 2`. If the argument is not between `-1` and `1` it defaults to `0` -/ noncomputable def arcsin (x : ℝ) : ℝ := if hx : -1 ≤ x ∧ x ≤ 1 then classical.some (exists_sin_eq hx) else 0 lemma arcsin_le_pi_div_two (x : ℝ) : arcsin x ≤ π / 2 := if hx : -1 ≤ x ∧ x ≤ 1 then by rw [arcsin, dif_pos hx]; exact (classical.some_spec (exists_sin_eq hx)).1.2 else by rw [arcsin, dif_neg hx]; exact le_of_lt pi_div_two_pos lemma neg_pi_div_two_le_arcsin (x : ℝ) : -(π / 2) ≤ arcsin x := if hx : -1 ≤ x ∧ x ≤ 1 then by rw [arcsin, dif_pos hx]; exact (classical.some_spec (exists_sin_eq hx)).1.1 else by rw [arcsin, dif_neg hx]; exact neg_nonpos.2 (le_of_lt pi_div_two_pos) lemma sin_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arcsin x) = x := by rw [arcsin, dif_pos (and.intro hx₁ hx₂)]; exact (classical.some_spec (exists_sin_eq ⟨hx₁, hx₂⟩)).2 lemma arcsin_sin {x : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : arcsin (sin x) = x := sin_inj_of_le_of_le_pi_div_two (neg_pi_div_two_le_arcsin _) (arcsin_le_pi_div_two _) hx₁ hx₂ (by rw sin_arcsin (neg_one_le_sin _) (sin_le_one _)) lemma arcsin_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) (hxy : arcsin x = arcsin y) : x = y := by rw [← sin_arcsin hx₁ hx₂, ← sin_arcsin hy₁ hy₂, hxy] @[simp] lemma arcsin_zero : arcsin 0 = 0 := sin_inj_of_le_of_le_pi_div_two (neg_pi_div_two_le_arcsin _) (arcsin_le_pi_div_two _) (neg_nonpos.2 (le_of_lt pi_div_two_pos)) (le_of_lt pi_div_two_pos) (by rw [sin_arcsin, sin_zero]; norm_num) @[simp] lemma arcsin_one : arcsin 1 = π / 2 := sin_inj_of_le_of_le_pi_div_two (neg_pi_div_two_le_arcsin _) (arcsin_le_pi_div_two _) (by linarith [pi_pos]) (le_refl _) (by rw [sin_arcsin, sin_pi_div_two]; norm_num) @[simp] lemma arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x := if h : -1 ≤ x ∧ x ≤ 1 then have -1 ≤ -x ∧ -x ≤ 1, by rwa [neg_le_neg_iff, neg_le, and.comm], sin_inj_of_le_of_le_pi_div_two (neg_pi_div_two_le_arcsin _) (arcsin_le_pi_div_two _) (neg_le_neg (arcsin_le_pi_div_two _)) (neg_le.1 (neg_pi_div_two_le_arcsin _)) (by rw [sin_arcsin this.1 this.2, sin_neg, sin_arcsin h.1 h.2]) else have ¬(-1 ≤ -x ∧ -x ≤ 1) := by rwa [neg_le_neg_iff, neg_le, and.comm], by rw [arcsin, arcsin, dif_neg h, dif_neg this, neg_zero] @[simp] lemma arcsin_neg_one : arcsin (-1) = -(π / 2) := by simp lemma arcsin_nonneg {x : ℝ} (hx : 0 ≤ x) : 0 ≤ arcsin x := if hx₁ : x ≤ 1 then not_lt.1 (λ h, not_lt.2 hx begin have := sin_lt_sin_of_le_of_le_pi_div_two (neg_pi_div_two_le_arcsin _) (le_of_lt pi_div_two_pos) h, rw [real.sin_arcsin, sin_zero] at this; linarith end) else by rw [arcsin, dif_neg]; simp [hx₁] lemma arcsin_eq_zero_iff {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : arcsin x = 0 ↔ x = 0 := ⟨λ h, have sin (arcsin x) = 0, by simp [h], by rwa [sin_arcsin hx₁ hx₂] at this, λ h, by simp [h]⟩ lemma arcsin_pos {x : ℝ} (hx₁ : 0 < x) (hx₂ : x ≤ 1) : 0 < arcsin x := lt_of_le_of_ne (arcsin_nonneg (le_of_lt hx₁)) (ne.symm (mt (arcsin_eq_zero_iff (by linarith) hx₂).1 (ne_of_lt hx₁).symm)) lemma arcsin_nonpos {x : ℝ} (hx : x ≤ 0) : arcsin x ≤ 0 := neg_nonneg.1 (arcsin_neg x ▸ arcsin_nonneg (neg_nonneg.2 hx)) /-- Inverse of the `cos` function, returns values in the range `0 ≤ arccos x` and `arccos x ≤ π`. If the argument is not between `-1` and `1` it defaults to `π / 2` -/ noncomputable def arccos (x : ℝ) : ℝ := π / 2 - arcsin x lemma arccos_eq_pi_div_two_sub_arcsin (x : ℝ) : arccos x = π / 2 - arcsin x := rfl lemma arcsin_eq_pi_div_two_sub_arccos (x : ℝ) : arcsin x = π / 2 - arccos x := by simp [sub_eq_add_neg, arccos] lemma arccos_le_pi (x : ℝ) : arccos x ≤ π := by unfold arccos; linarith [neg_pi_div_two_le_arcsin x] lemma arccos_nonneg (x : ℝ) : 0 ≤ arccos x := by unfold arccos; linarith [arcsin_le_pi_div_two x] lemma cos_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arccos x) = x := by rw [arccos, cos_pi_div_two_sub, sin_arcsin hx₁ hx₂] lemma arccos_cos {x : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π) : arccos (cos x) = x := by rw [arccos, ← sin_pi_div_two_sub, arcsin_sin]; simp [sub_eq_add_neg]; linarith lemma arccos_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) (hxy : arccos x = arccos y) : x = y := arcsin_inj hx₁ hx₂ hy₁ hy₂ $ by simp [arccos, *] at * @[simp] lemma arccos_zero : arccos 0 = π / 2 := by simp [arccos] @[simp] lemma arccos_one : arccos 1 = 0 := by simp [arccos] @[simp] lemma arccos_neg_one : arccos (-1) = π := by simp [arccos, add_halves] lemma arccos_neg (x : ℝ) : arccos (-x) = π - arccos x := by rw [← add_halves π, arccos, arcsin_neg, arccos, add_sub_assoc, sub_sub_self]; simp lemma cos_arcsin_nonneg (x : ℝ) : 0 ≤ cos (arcsin x) := cos_nonneg_of_neg_pi_div_two_le_of_le_pi_div_two (neg_pi_div_two_le_arcsin _) (arcsin_le_pi_div_two _) lemma cos_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arcsin x) = sqrt (1 - x ^ 2) := have sin (arcsin x) ^ 2 + cos (arcsin x) ^ 2 = 1 := sin_sq_add_cos_sq (arcsin x), begin rw [← eq_sub_iff_add_eq', ← sqrt_inj (pow_two_nonneg _) (sub_nonneg.2 (sin_sq_le_one (arcsin x))), pow_two, sqrt_mul_self (cos_arcsin_nonneg _)] at this, rw [this, sin_arcsin hx₁ hx₂], end lemma sin_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arccos x) = sqrt (1 - x ^ 2) := by rw [arccos_eq_pi_div_two_sub_arcsin, sin_pi_div_two_sub, cos_arcsin hx₁ hx₂] lemma abs_div_sqrt_one_add_lt (x : ℝ) : abs (x / sqrt (1 + x ^ 2)) < 1 := have h₁ : 0 < 1 + x ^ 2, from add_pos_of_pos_of_nonneg zero_lt_one (pow_two_nonneg _), have h₂ : 0 < sqrt (1 + x ^ 2), from sqrt_pos.2 h₁, by rw [abs_div, div_lt_iff (abs_pos_of_pos h₂), one_mul, mul_self_lt_mul_self_iff (abs_nonneg x) (abs_nonneg _), ← abs_mul, ← abs_mul, mul_self_sqrt (add_nonneg zero_le_one (pow_two_nonneg _)), abs_of_nonneg (mul_self_nonneg x), abs_of_nonneg (le_of_lt h₁), pow_two, add_comm]; exact lt_add_one _ lemma div_sqrt_one_add_lt_one (x : ℝ) : x / sqrt (1 + x ^ 2) < 1 := (abs_lt.1 (abs_div_sqrt_one_add_lt _)).2 lemma neg_one_lt_div_sqrt_one_add (x : ℝ) : -1 < x / sqrt (1 + x ^ 2) := (abs_lt.1 (abs_div_sqrt_one_add_lt _)).1 lemma tan_pos_of_pos_of_lt_pi_div_two {x : ℝ} (h0x : 0 < x) (hxp : x < π / 2) : 0 < tan x := by rw tan_eq_sin_div_cos; exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith)) (cos_pos_of_neg_pi_div_two_lt_of_lt_pi_div_two (by linarith) hxp) lemma tan_nonneg_of_nonneg_of_le_pi_div_two {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π / 2) : 0 ≤ tan x := match lt_or_eq_of_le h0x, lt_or_eq_of_le hxp with | or.inl hx0, or.inl hxp := le_of_lt (tan_pos_of_pos_of_lt_pi_div_two hx0 hxp) | or.inl hx0, or.inr hxp := by simp [hxp, tan_eq_sin_div_cos] | or.inr hx0, _ := by simp [hx0.symm] end lemma tan_neg_of_neg_of_pi_div_two_lt {x : ℝ} (hx0 : x < 0) (hpx : -(π / 2) < x) : tan x < 0 := neg_pos.1 (tan_neg x ▸ tan_pos_of_pos_of_lt_pi_div_two (by linarith) (by linarith [pi_pos])) lemma tan_nonpos_of_nonpos_of_neg_pi_div_two_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -(π / 2) ≤ x) : tan x ≤ 0 := neg_nonneg.1 (tan_neg x ▸ tan_nonneg_of_nonneg_of_le_pi_div_two (by linarith) (by linarith [pi_pos])) lemma tan_lt_tan_of_nonneg_of_lt_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y := begin rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos], exact div_lt_div (sin_lt_sin_of_le_of_le_pi_div_two (by linarith) (le_of_lt hy₂) hxy) (cos_le_cos_of_nonneg_of_le_pi hx₁ (by linarith) (le_of_lt hxy)) (sin_nonneg_of_nonneg_of_le_pi (by linarith) (by linarith)) (cos_pos_of_neg_pi_div_two_lt_of_lt_pi_div_two (by linarith) hy₂) end lemma tan_lt_tan_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y := match le_total x 0, le_total y 0 with | or.inl hx0, or.inl hy0 := neg_lt_neg_iff.1 $ by rw [← tan_neg, ← tan_neg]; exact tan_lt_tan_of_nonneg_of_lt_pi_div_two (neg_nonneg.2 hy0) (neg_lt.2 hx₁) (neg_lt_neg hxy) | or.inl hx0, or.inr hy0 := (lt_or_eq_of_le hy0).elim (λ hy0, calc tan x ≤ 0 : tan_nonpos_of_nonpos_of_neg_pi_div_two_le hx0 (le_of_lt hx₁) ... < tan y : tan_pos_of_pos_of_lt_pi_div_two hy0 hy₂) (λ hy0, by rw [← hy0, tan_zero]; exact tan_neg_of_neg_of_pi_div_two_lt (hy0.symm ▸ hxy) hx₁) | or.inr hx0, or.inl hy0 := by linarith | or.inr hx0, or.inr hy0 := tan_lt_tan_of_nonneg_of_lt_pi_div_two hx0 hy₂ hxy end lemma tan_inj_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) (hy₁ : -(π / 2) < y) (hy₂ : y < π / 2) (hxy : tan x = tan y) : x = y := match lt_trichotomy x y with | or.inl h := absurd (tan_lt_tan_of_lt_of_lt_pi_div_two hx₁ hy₂ h) (by rw hxy; exact lt_irrefl _) | or.inr (or.inl h) := h | or.inr (or.inr h) := absurd (tan_lt_tan_of_lt_of_lt_pi_div_two hy₁ hx₂ h) (by rw hxy; exact lt_irrefl _) end /-- Inverse of the `tan` function, returns values in the range `-π / 2 < arctan x` and `arctan x < π / 2` -/ noncomputable def arctan (x : ℝ) : ℝ := arcsin (x / sqrt (1 + x ^ 2)) lemma sin_arctan (x : ℝ) : sin (arctan x) = x / sqrt (1 + x ^ 2) := sin_arcsin (le_of_lt (neg_one_lt_div_sqrt_one_add _)) (le_of_lt (div_sqrt_one_add_lt_one _)) lemma cos_arctan (x : ℝ) : cos (arctan x) = 1 / sqrt (1 + x ^ 2) := have h₁ : (0 : ℝ) < 1 + x ^ 2, from add_pos_of_pos_of_nonneg zero_lt_one (pow_two_nonneg _), have h₂ : (x / sqrt (1 + x ^ 2)) ^ 2 < 1, by rw [pow_two, ← abs_mul_self, _root_.abs_mul]; exact mul_lt_one_of_nonneg_of_lt_one_left (abs_nonneg _) (abs_div_sqrt_one_add_lt _) (le_of_lt (abs_div_sqrt_one_add_lt _)), by rw [arctan, cos_arcsin (le_of_lt (neg_one_lt_div_sqrt_one_add _)) (le_of_lt (div_sqrt_one_add_lt_one _)), one_div_eq_inv, ← sqrt_inv, sqrt_inj (sub_nonneg.2 (le_of_lt h₂)) (inv_nonneg.2 (le_of_lt h₁)), div_pow, pow_two (sqrt _), mul_self_sqrt (le_of_lt h₁), ← mul_right_inj' (ne.symm (ne_of_lt h₁)), mul_sub, mul_div_cancel' _ (ne.symm (ne_of_lt h₁)), mul_inv_cancel (ne.symm (ne_of_lt h₁))]; simp lemma tan_arctan (x : ℝ) : tan (arctan x) = x := by rw [tan_eq_sin_div_cos, sin_arctan, cos_arctan, div_div_div_div_eq, mul_one, mul_div_assoc, div_self (mt sqrt_eq_zero'.1 (not_le_of_gt (add_pos_of_pos_of_nonneg zero_lt_one (pow_two_nonneg x)))), mul_one] lemma arctan_lt_pi_div_two (x : ℝ) : arctan x < π / 2 := lt_of_le_of_ne (arcsin_le_pi_div_two _) (λ h, ne_of_lt (div_sqrt_one_add_lt_one x) $ by rw [← sin_arcsin (le_of_lt (neg_one_lt_div_sqrt_one_add _)) (le_of_lt (div_sqrt_one_add_lt_one _)), ← arctan, h, sin_pi_div_two]) lemma neg_pi_div_two_lt_arctan (x : ℝ) : -(π / 2) < arctan x := lt_of_le_of_ne (neg_pi_div_two_le_arcsin _) (λ h, ne_of_lt (neg_one_lt_div_sqrt_one_add x) $ by rw [← sin_arcsin (le_of_lt (neg_one_lt_div_sqrt_one_add _)) (le_of_lt (div_sqrt_one_add_lt_one _)), ← arctan, ← h, sin_neg, sin_pi_div_two]) lemma tan_surjective : function.surjective tan := function.right_inverse.surjective tan_arctan lemma arctan_tan {x : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) : arctan (tan x) = x := tan_inj_of_lt_of_lt_pi_div_two (neg_pi_div_two_lt_arctan _) (arctan_lt_pi_div_two _) hx₁ hx₂ (by rw tan_arctan) @[simp] lemma arctan_zero : arctan 0 = 0 := by simp [arctan] @[simp] lemma arctan_neg (x : ℝ) : arctan (-x) = - arctan x := by simp [arctan, neg_div] end real namespace complex open_locale real /-- `arg` returns values in the range (-π, π], such that for `x ≠ 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`, `arg 0` defaults to `0` -/ noncomputable def arg (x : ℂ) : ℝ := if 0 ≤ x.re then real.arcsin (x.im / x.abs) else if 0 ≤ x.im then real.arcsin ((-x).im / x.abs) + π else real.arcsin ((-x).im / x.abs) - π lemma arg_le_pi (x : ℂ) : arg x ≤ π := if hx₁ : 0 ≤ x.re then by rw [arg, if_pos hx₁]; exact le_trans (real.arcsin_le_pi_div_two _) (le_of_lt (half_lt_self real.pi_pos)) else have hx : x ≠ 0, from λ h, by simpa [h, lt_irrefl] using hx₁, if hx₂ : 0 ≤ x.im then by rw [arg, if_neg hx₁, if_pos hx₂]; exact le_sub_iff_add_le.1 (by rw sub_self; exact real.arcsin_nonpos (by rw [neg_im, neg_div, neg_nonpos]; exact div_nonneg hx₂ (abs_pos.2 hx))) else by rw [arg, if_neg hx₁, if_neg hx₂]; exact sub_le_iff_le_add.2 (le_trans (real.arcsin_le_pi_div_two _) (by linarith [real.pi_pos])) lemma neg_pi_lt_arg (x : ℂ) : -π < arg x := if hx₁ : 0 ≤ x.re then by rw [arg, if_pos hx₁]; exact lt_of_lt_of_le (neg_lt_neg (half_lt_self real.pi_pos)) (real.neg_pi_div_two_le_arcsin _) else have hx : x ≠ 0, from λ h, by simpa [h, lt_irrefl] using hx₁, if hx₂ : 0 ≤ x.im then by rw [arg, if_neg hx₁, if_pos hx₂]; exact sub_lt_iff_lt_add.1 (lt_of_lt_of_le (by linarith [real.pi_pos]) (real.neg_pi_div_two_le_arcsin _)) else by rw [arg, if_neg hx₁, if_neg hx₂]; exact lt_sub_iff_add_lt.2 (by rw neg_add_self; exact real.arcsin_pos (by rw [neg_im]; exact div_pos (neg_pos.2 (lt_of_not_ge hx₂)) (abs_pos.2 hx)) (by rw [← abs_neg x]; exact (abs_le.1 (abs_im_div_abs_le_one _)).2)) lemma arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg {x : ℂ} (hxr : x.re < 0) (hxi : 0 ≤ x.im) : arg x = arg (-x) + π := have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos], by rw [arg, arg, if_neg (not_le.2 hxr), if_pos this, if_pos hxi, abs_neg] lemma arg_eq_arg_neg_sub_pi_of_im_neg_of_re_neg {x : ℂ} (hxr : x.re < 0) (hxi : x.im < 0) : arg x = arg (-x) - π := have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos], by rw [arg, arg, if_neg (not_le.2 hxr), if_neg (not_le.2 hxi), if_pos this, abs_neg] @[simp] lemma arg_zero : arg 0 = 0 := by simp [arg, le_refl] @[simp] lemma arg_one : arg 1 = 0 := by simp [arg, zero_le_one] @[simp] lemma arg_neg_one : arg (-1) = π := by simp [arg, le_refl, not_le.2 (@zero_lt_one ℝ _)] @[simp] lemma arg_I : arg I = π / 2 := by simp [arg, le_refl] @[simp] lemma arg_neg_I : arg (-I) = -(π / 2) := by simp [arg, le_refl] lemma sin_arg (x : ℂ) : real.sin (arg x) = x.im / x.abs := by unfold arg; split_ifs; simp [sub_eq_add_neg, arg, real.sin_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1 (abs_le.1 (abs_im_div_abs_le_one x)).2, real.sin_add, neg_div, real.arcsin_neg, real.sin_neg] private lemma cos_arg_of_re_nonneg {x : ℂ} (hx : x ≠ 0) (hxr : 0 ≤ x.re) : real.cos (arg x) = x.re / x.abs := have 0 ≤ 1 - (x.im / abs x) ^ 2, from sub_nonneg.2 $ by rw [pow_two, ← _root_.abs_mul_self, _root_.abs_mul, ← pow_two]; exact pow_le_one _ (_root_.abs_nonneg _) (abs_im_div_abs_le_one _), by rw [eq_div_iff_mul_eq (mt abs_eq_zero.1 hx), ← real.mul_self_sqrt (abs_nonneg x), arg, if_pos hxr, real.cos_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1 (abs_le.1 (abs_im_div_abs_le_one x)).2, ← real.sqrt_mul (abs_nonneg _), ← real.sqrt_mul this, sub_mul, div_pow, ← pow_two, div_mul_cancel _ (pow_ne_zero 2 (mt abs_eq_zero.1 hx)), one_mul, pow_two, mul_self_abs, norm_sq, pow_two, add_sub_cancel, real.sqrt_mul_self hxr] lemma cos_arg {x : ℂ} (hx : x ≠ 0) : real.cos (arg x) = x.re / x.abs := if hxr : 0 ≤ x.re then cos_arg_of_re_nonneg hx hxr else have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos] using hxr, if hxi : 0 ≤ x.im then have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos] using hxr, by rw [arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg (not_le.1 hxr) hxi, real.cos_add_pi, cos_arg_of_re_nonneg (neg_ne_zero.2 hx) this]; simp [neg_div] else by rw [arg_eq_arg_neg_sub_pi_of_im_neg_of_re_neg (not_le.1 hxr) (not_le.1 hxi)]; simp [sub_eq_add_neg, real.cos_add, neg_div, cos_arg_of_re_nonneg (neg_ne_zero.2 hx) this] lemma tan_arg {x : ℂ} : real.tan (arg x) = x.im / x.re := begin by_cases h : x = 0, { simp only [h, euclidean_domain.zero_div, complex.zero_im, complex.arg_zero, real.tan_zero, complex.zero_re] }, rw [real.tan_eq_sin_div_cos, sin_arg, cos_arg h, div_div_div_cancel_right _ (mt abs_eq_zero.1 h)] end lemma arg_cos_add_sin_mul_I {x : ℝ} (hx₁ : -π < x) (hx₂ : x ≤ π) : arg (cos x + sin x * I) = x := if hx₃ : -(π / 2) ≤ x ∧ x ≤ π / 2 then have hx₄ : 0 ≤ (cos x + sin x * I).re, by simp; exact real.cos_nonneg_of_neg_pi_div_two_le_of_le_pi_div_two hx₃.1 hx₃.2, by rw [arg, if_pos hx₄]; simp [abs_cos_add_sin_mul_I, sin_of_real_re, real.arcsin_sin hx₃.1 hx₃.2] else if hx₄ : x < -(π / 2) then have hx₅ : ¬0 ≤ (cos x + sin x * I).re := suffices ¬ 0 ≤ real.cos x, by simpa, not_le.2 $ by rw ← real.cos_neg; apply real.cos_neg_of_pi_div_two_lt_of_lt; linarith, have hx₆ : ¬0 ≤ (cos ↑x + sin ↑x * I).im := suffices real.sin x < 0, by simpa, by apply real.sin_neg_of_neg_of_neg_pi_lt; linarith, suffices -π + -real.arcsin (real.sin x) = x, by rw [arg, if_neg hx₅, if_neg hx₆]; simpa [sub_eq_add_neg, add_comm, abs_cos_add_sin_mul_I, sin_of_real_re], by rw [← real.arcsin_neg, ← real.sin_add_pi, real.arcsin_sin]; try {simp [add_left_comm]}; linarith else have hx₅ : π / 2 < x, by cases not_and_distrib.1 hx₃; linarith, have hx₆ : ¬0 ≤ (cos x + sin x * I).re := suffices ¬0 ≤ real.cos x, by simpa, not_le.2 $ by apply real.cos_neg_of_pi_div_two_lt_of_lt; linarith, have hx₇ : 0 ≤ (cos x + sin x * I).im := suffices 0 ≤ real.sin x, by simpa, by apply real.sin_nonneg_of_nonneg_of_le_pi; linarith, suffices π - real.arcsin (real.sin x) = x, by rw [arg, if_neg hx₆, if_pos hx₇]; simpa [sub_eq_add_neg, add_comm, abs_cos_add_sin_mul_I, sin_of_real_re], by rw [← real.sin_pi_sub, real.arcsin_sin]; simp [sub_eq_add_neg]; linarith lemma arg_eq_arg_iff {x y : ℂ} (hx : x ≠ 0) (hy : y ≠ 0) : arg x = arg y ↔ (abs y / abs x : ℂ) * x = y := have hax : abs x ≠ 0, from (mt abs_eq_zero.1 hx), have hay : abs y ≠ 0, from (mt abs_eq_zero.1 hy), ⟨λ h, begin have hcos := congr_arg real.cos h, rw [cos_arg hx, cos_arg hy, div_eq_div_iff hax hay] at hcos, have hsin := congr_arg real.sin h, rw [sin_arg, sin_arg, div_eq_div_iff hax hay] at hsin, apply complex.ext, { rw [mul_re, ← of_real_div, of_real_re, of_real_im, zero_mul, sub_zero, mul_comm, ← mul_div_assoc, hcos, mul_div_cancel _ hax] }, { rw [mul_im, ← of_real_div, of_real_re, of_real_im, zero_mul, add_zero, mul_comm, ← mul_div_assoc, hsin, mul_div_cancel _ hax] } end, λ h, have hre : abs (y / x) * x.re = y.re, by rw ← of_real_div at h; simpa [-of_real_div] using congr_arg re h, have hre' : abs (x / y) * y.re = x.re, by rw [← hre, abs_div, abs_div, ← mul_assoc, div_mul_div, mul_comm (abs _), div_self (mul_ne_zero hay hax), one_mul], have him : abs (y / x) * x.im = y.im, by rw ← of_real_div at h; simpa [-of_real_div] using congr_arg im h, have him' : abs (x / y) * y.im = x.im, by rw [← him, abs_div, abs_div, ← mul_assoc, div_mul_div, mul_comm (abs _), div_self (mul_ne_zero hay hax), one_mul], have hxya : x.im / abs x = y.im / abs y, by rw [← him, abs_div, mul_comm, ← mul_div_comm, mul_div_cancel_left _ hay], have hnxya : (-x).im / abs x = (-y).im / abs y, by rw [neg_im, neg_im, neg_div, neg_div, hxya], if hxr : 0 ≤ x.re then have hyr : 0 ≤ y.re, from hre ▸ mul_nonneg (abs_nonneg _) hxr, by simp [arg, *] at * else have hyr : ¬ 0 ≤ y.re, from λ hyr, hxr $ hre' ▸ mul_nonneg (abs_nonneg _) hyr, if hxi : 0 ≤ x.im then have hyi : 0 ≤ y.im, from him ▸ mul_nonneg (abs_nonneg _) hxi, by simp [arg, *] at * else have hyi : ¬ 0 ≤ y.im, from λ hyi, hxi $ him' ▸ mul_nonneg (abs_nonneg _) hyi, by simp [arg, *] at *⟩ lemma arg_real_mul (x : ℂ) {r : ℝ} (hr : 0 < r) : arg (r * x) = arg x := if hx : x = 0 then by simp [hx] else (arg_eq_arg_iff (mul_ne_zero (of_real_ne_zero.2 (ne_of_lt hr).symm) hx) hx).2 $ by rw [abs_mul, abs_of_nonneg (le_of_lt hr), ← mul_assoc, of_real_mul, mul_comm (r : ℂ), ← div_div_eq_div_mul, div_mul_cancel _ (of_real_ne_zero.2 (ne_of_lt hr).symm), div_self (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), one_mul] lemma ext_abs_arg {x y : ℂ} (h₁ : x.abs = y.abs) (h₂ : x.arg = y.arg) : x = y := if hy : y = 0 then by simp * at * else have hx : x ≠ 0, from λ hx, by simp [*, eq_comm] at *, by rwa [arg_eq_arg_iff hx hy, h₁, div_self (of_real_ne_zero.2 (mt abs_eq_zero.1 hy)), one_mul] at h₂ lemma arg_of_real_of_nonneg {x : ℝ} (hx : 0 ≤ x) : arg x = 0 := by simp [arg, hx] lemma arg_of_real_of_neg {x : ℝ} (hx : x < 0) : arg x = π := by rw [arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg, ← of_real_neg, arg_of_real_of_nonneg]; simp [*, le_iff_eq_or_lt, lt_neg] /-- Inverse of the `exp` function. Returns values such that `(log x).im > - π` and `(log x).im ≤ π`. `log 0 = 0`-/ noncomputable def log (x : ℂ) : ℂ := x.abs.log + arg x * I lemma log_re (x : ℂ) : x.log.re = x.abs.log := by simp [log] lemma log_im (x : ℂ) : x.log.im = x.arg := by simp [log] lemma exp_log {x : ℂ} (hx : x ≠ 0) : exp (log x) = x := by rw [log, exp_add_mul_I, ← of_real_sin, sin_arg, ← of_real_cos, cos_arg hx, ← of_real_exp, real.exp_log (abs_pos.2 hx), mul_add, of_real_div, of_real_div, mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), ← mul_assoc, mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), re_add_im] lemma exp_inj_of_neg_pi_lt_of_le_pi {x y : ℂ} (hx₁ : -π < x.im) (hx₂ : x.im ≤ π) (hy₁ : - π < y.im) (hy₂ : y.im ≤ π) (hxy : exp x = exp y) : x = y := by rw [exp_eq_exp_re_mul_sin_add_cos, exp_eq_exp_re_mul_sin_add_cos y] at hxy; exact complex.ext (real.exp_injective $ by simpa [abs_mul, abs_cos_add_sin_mul_I] using congr_arg complex.abs hxy) (by simpa [(of_real_exp _).symm, - of_real_exp, arg_real_mul _ (real.exp_pos _), arg_cos_add_sin_mul_I hx₁ hx₂, arg_cos_add_sin_mul_I hy₁ hy₂] using congr_arg arg hxy) lemma log_exp {x : ℂ} (hx₁ : -π < x.im) (hx₂: x.im ≤ π) : log (exp x) = x := exp_inj_of_neg_pi_lt_of_le_pi (by rw log_im; exact neg_pi_lt_arg _) (by rw log_im; exact arg_le_pi _) hx₁ hx₂ (by rw [exp_log (exp_ne_zero _)]) lemma of_real_log {x : ℝ} (hx : 0 ≤ x) : (x.log : ℂ) = log x := complex.ext (by rw [log_re, of_real_re, abs_of_nonneg hx]) (by rw [of_real_im, log_im, arg_of_real_of_nonneg hx]) lemma log_of_real_re (x : ℝ) : (log (x : ℂ)).re = real.log x := by simp [log_re] @[simp] lemma log_zero : log 0 = 0 := by simp [log] @[simp] lemma log_one : log 1 = 0 := by simp [log] lemma log_neg_one : log (-1) = π * I := by simp [log] lemma log_I : log I = π / 2 * I := by simp [log] lemma log_neg_I : log (-I) = -(π / 2) * I := by simp [log] lemma exp_eq_one_iff {x : ℂ} : exp x = 1 ↔ ∃ n : ℤ, x = n * ((2 * π) * I) := have real.exp (x.re) * real.cos (x.im) = 1 → real.cos x.im ≠ -1, from λ h₁ h₂, begin rw [h₂, mul_neg_eq_neg_mul_symm, mul_one, neg_eq_iff_neg_eq] at h₁, have := real.exp_pos x.re, rw ← h₁ at this, exact absurd this (by norm_num) end, calc exp x = 1 ↔ (exp x).re = 1 ∧ (exp x).im = 0 : by simp [complex.ext_iff] ... ↔ real.cos x.im = 1 ∧ real.sin x.im = 0 ∧ x.re = 0 : begin rw exp_eq_exp_re_mul_sin_add_cos, simp [complex.ext_iff, cos_of_real_re, sin_of_real_re, exp_of_real_re, real.exp_ne_zero], split; finish [real.sin_eq_zero_iff_cos_eq] end ... ↔ (∃ n : ℤ, ↑n * (2 * π) = x.im) ∧ (∃ n : ℤ, ↑n * π = x.im) ∧ x.re = 0 : by rw [real.sin_eq_zero_iff, real.cos_eq_one_iff] ... ↔ ∃ n : ℤ, x = n * ((2 * π) * I) : ⟨λ ⟨⟨n, hn⟩, ⟨m, hm⟩, h⟩, ⟨n, by simp [complex.ext_iff, hn.symm, h]⟩, λ ⟨n, hn⟩, ⟨⟨n, by simp [hn]⟩, ⟨2 * n, by simp [hn, mul_comm, mul_assoc, mul_left_comm]⟩, by simp [hn]⟩⟩ lemma exp_eq_exp_iff_exp_sub_eq_one {x y : ℂ} : exp x = exp y ↔ exp (x - y) = 1 := by rw [exp_sub, div_eq_one_iff_eq (exp_ne_zero _)] lemma exp_eq_exp_iff_exists_int {x y : ℂ} : exp x = exp y ↔ ∃ n : ℤ, x = y + n * ((2 * π) * I) := by simp only [exp_eq_exp_iff_exp_sub_eq_one, exp_eq_one_iff, sub_eq_iff_eq_add'] @[simp] lemma cos_pi_div_two : cos (π / 2) = 0 := calc cos (π / 2) = real.cos (π / 2) : by rw [of_real_cos]; simp ... = 0 : by simp @[simp] lemma sin_pi_div_two : sin (π / 2) = 1 := calc sin (π / 2) = real.sin (π / 2) : by rw [of_real_sin]; simp ... = 1 : by simp @[simp] lemma sin_pi : sin π = 0 := by rw [← of_real_sin, real.sin_pi]; simp @[simp] lemma cos_pi : cos π = -1 := by rw [← of_real_cos, real.cos_pi]; simp @[simp] lemma sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add] @[simp] lemma cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add] lemma sin_add_pi (x : ℝ) : sin (x + π) = -sin x := by simp [sin_add] lemma sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x := by simp [sin_add_pi, sin_add, sin_two_pi, cos_two_pi] lemma cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x := by simp [cos_add, cos_two_pi, sin_two_pi] lemma sin_pi_sub (x : ℝ) : sin (π - x) = sin x := by simp [sub_eq_add_neg, sin_add] lemma cos_add_pi (x : ℝ) : cos (x + π) = -cos x := by simp [cos_add] lemma cos_pi_sub (x : ℝ) : cos (π - x) = -cos x := by simp [sub_eq_add_neg, cos_add] lemma sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x := by simp [sin_add] lemma sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add] lemma sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add] lemma cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x := by simp [cos_add] lemma cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x := by simp [sub_eq_add_neg, cos_add] lemma cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x := by rw [← cos_neg, neg_sub, cos_sub_pi_div_two] lemma sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 := by induction n; simp [add_mul, sin_add, *] lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 := by cases n; simp [add_mul, sin_add, *, sin_nat_mul_pi] lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 := by induction n; simp [*, mul_add, cos_add, add_mul, cos_two_pi, sin_two_pi] lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 := by cases n; simp only [cos_nat_mul_two_pi, int.of_nat_eq_coe, int.neg_succ_of_nat_coe, int.cast_coe_nat, int.cast_neg, (neg_mul_eq_neg_mul _ _).symm, cos_neg] lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 := by simp [cos_add, sin_add, cos_int_mul_two_pi] end complex
d131d071dd0c5ded037b59f83c9901844de39263
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/src/topology/fiber_bundle.lean
d3be6e4d9ed65f75527567f321dd193102af28f1
[ "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
57,961
lean
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import topology.local_homeomorph import topology.algebra.ordered.basic import data.bundle /-! # Fiber bundles A topological fiber bundle with fiber `F` over a base `B` is a space projecting on `B` for which the fibers are all homeomorphic to `F`, such that the local situation around each point is a direct product. We define a predicate `is_topological_fiber_bundle F p` saying that `p : Z → B` is a topological fiber bundle with fiber `F`. It is in general nontrivial to construct a fiber bundle. A way is to start from the knowledge of how changes of local trivializations act on the fiber. From this, one can construct the total space of the bundle and its topology by a suitable gluing construction. The main content of this file is an implementation of this construction: starting from an object of type `topological_fiber_bundle_core` registering the trivialization changes, one gets the corresponding fiber bundle and projection. Similarly we implement the object `topological_fiber_prebundle` which allows to define a topological fiber bundle from trivializations given as local equivalences with minimum additional properties. ## Main definitions ### Basic definitions * `trivialization F p` : structure extending local homeomorphisms, defining a local trivialization of a topological space `Z` with projection `p` and fiber `F`. * `is_topological_fiber_bundle F p` : Prop saying that the map `p` between topological spaces is a fiber bundle with fiber `F`. * `is_trivial_topological_fiber_bundle F p` : Prop saying that the map `p : Z → B` between topological spaces is a trivial topological fiber bundle, i.e., there exists a homeomorphism `h : Z ≃ₜ B × F` such that `proj x = (h x).1`. ### Operations on bundles We provide the following operations on `trivialization`s. * `trivialization.comap`: given a local trivialization `e` of a fiber bundle `p : Z → B`, a continuous map `f : B' → B` and a point `b' : B'` such that `f b' ∈ e.base_set`, `e.comap f hf b' hb'` is a trivialization of the pullback bundle. The pullback bundle (a.k.a., the induced bundle) has total space `{(x, y) : B' × Z | f x = p y}`, and is given by `λ ⟨(x, y), h⟩, x`. * `is_topological_fiber_bundle.comap`: if `p : Z → B` is a topological fiber bundle, then its pullback along a continuous map `f : B' → B` is a topological fiber bundle as well. * `trivialization.comp_homeomorph`: given a local trivialization `e` of a fiber bundle `p : Z → B` and a homeomorphism `h : Z' ≃ₜ Z`, returns a local trivialization of the fiber bundle `p ∘ h`. * `is_topological_fiber_bundle.comp_homeomorph`: if `p : Z → B` is a topological fiber bundle and `h : Z' ≃ₜ Z` is a homeomorphism, then `p ∘ h : Z' → B` is a topological fiber bundle with the same fiber. ### Construction of a bundle from trivializations * `bundle.total_space E` is a type synonym for `Σ (x : B), E x`, that we can endow with a suitable topology. * `topological_fiber_bundle_core ι B F` : structure registering how changes of coordinates act on the fiber `F` above open subsets of `B`, where local trivializations are indexed by `ι`. Let `Z : topological_fiber_bundle_core ι B F`. Then we define * `Z.fiber x` : the fiber above `x`, homeomorphic to `F` (and defeq to `F` as a type). * `Z.total_space` : the total space of `Z`, defined as a `Type` as `Σ (b : B), F`, but with a twisted topology coming from the fiber bundle structure. It is (reducibly) the same as `bundle.total_space Z.fiber`. * `Z.proj` : projection from `Z.total_space` to `B`. It is continuous. * `Z.local_triv i`: for `i : ι`, bundle trivialization above the set `Z.base_set i`, which is an open set in `B`. * `pretrivialization F proj` : trivialization as a local equivalence, mainly used when the topology on the total space has not yet been defined. * `topological_fiber_prebundle F proj` : structure registering a cover of prebundle trivializations and requiring that the relative transition maps are local homeomorphisms. * `topological_fiber_prebundle.total_space_topology a` : natural topology of the total space, making the prebundle into a bundle. ## Implementation notes A topological fiber bundle with fiber `F` over a base `B` is a family of spaces isomorphic to `F`, indexed by `B`, which is locally trivial in the following sense: there is a covering of `B` by open sets such that, on each such open set `s`, the bundle is isomorphic to `s × F`. To construct a fiber bundle formally, the main data is what happens when one changes trivializations from `s × F` to `s' × F` on `s ∩ s'`: one should get a family of homeomorphisms of `F`, depending continuously on the base point, satisfying basic compatibility conditions (cocycle property). Useful classes of bundles can then be specified by requiring that these homeomorphisms of `F` belong to some subgroup, preserving some structure (the "structure group of the bundle"): then these structures are inherited by the fibers of the bundle. Given such trivialization change data (encoded below in a structure called `topological_fiber_bundle_core`), one can construct the fiber bundle. The intrinsic canonical mathematical construction is the following. The fiber above `x` is the disjoint union of `F` over all trivializations, modulo the gluing identifications: one gets a fiber which is isomorphic to `F`, but non-canonically (each choice of one of the trivializations around `x` gives such an isomorphism). Given a trivialization over a set `s`, one gets an isomorphism between `s × F` and `proj^{-1} s`, by using the identification corresponding to this trivialization. One chooses the topology on the bundle that makes all of these into homeomorphisms. For the practical implementation, it turns out to be more convenient to avoid completely the gluing and quotienting construction above, and to declare above each `x` that the fiber is `F`, but thinking that it corresponds to the `F` coming from the choice of one trivialization around `x`. This has several practical advantages: * without any work, one gets a topological space structure on the fiber. And if `F` has more structure it is inherited for free by the fiber. * In the case of the tangent bundle of manifolds, this implies that on vector spaces the derivative (from `F` to `F`) and the manifold derivative (from `tangent_space I x` to `tangent_space I' (f x)`) are equal. A drawback is that some silly constructions will typecheck: in the case of the tangent bundle, one can add two vectors in different tangent spaces (as they both are elements of `F` from the point of view of Lean). To solve this, one could mark the tangent space as irreducible, but then one would lose the identification of the tangent space to `F` with `F`. There is however a big advantage of this situation: even if Lean can not check that two basepoints are defeq, it will accept the fact that the tangent spaces are the same. For instance, if two maps `f` and `g` are locally inverse to each other, one can express that the composition of their derivatives is the identity of `tangent_space I x`. One could fear issues as this composition goes from `tangent_space I x` to `tangent_space I (g (f x))` (which should be the same, but should not be obvious to Lean as it does not know that `g (f x) = x`). As these types are the same to Lean (equal to `F`), there are in fact no dependent type difficulties here! For this construction of a fiber bundle from a `topological_fiber_bundle_core`, we should thus choose for each `x` one specific trivialization around it. We include this choice in the definition of the `topological_fiber_bundle_core`, as it makes some constructions more functorial and it is a nice way to say that the trivializations cover the whole space `B`. With this definition, the type of the fiber bundle space constructed from the core data is just `Σ (b : B), F `, but the topology is not the product one, in general. We also take the indexing type (indexing all the trivializations) as a parameter to the fiber bundle core: it could always be taken as a subtype of all the maps from open subsets of `B` to continuous maps of `F`, but in practice it will sometimes be something else. For instance, on a manifold, one will use the set of charts as a good parameterization for the trivializations of the tangent bundle. Or for the pullback of a `topological_fiber_bundle_core`, the indexing type will be the same as for the initial bundle. ## Tags Fiber bundle, topological bundle, local trivialization, structure group -/ variables {ι : Type*} {B : Type*} {F : Type*} open topological_space filter set open_locale topological_space classical /-! ### General definition of topological fiber bundles -/ section topological_fiber_bundle variables (F) {Z : Type*} [topological_space B] [topological_space F] {proj : Z → B} /-- This structure contains the information left for a local trivialization (which is implemented below as `trivialization F proj`) if the total space has not been given a topology, but we have a topology on both the fiber and the base space. Through the construction `topological_fiber_prebundle F proj` it will be possible to promote a `pretrivialization F proj` to a `trivialization F proj`. -/ @[nolint has_inhabited_instance] structure topological_fiber_bundle.pretrivialization (proj : Z → B) extends local_equiv Z (B × F) := (open_target : is_open target) (base_set : set B) (open_base_set : is_open base_set) (source_eq : source = proj ⁻¹' base_set) (target_eq : target = set.prod base_set univ) (proj_to_fun : ∀ p ∈ source, (to_fun p).1 = proj p) open topological_fiber_bundle namespace topological_fiber_bundle.pretrivialization instance : has_coe_to_fun (pretrivialization F proj) (λ _, Z → (B × F)) := ⟨λ e, e.to_fun⟩ variables {F} (e : pretrivialization F proj) {x : Z} @[simp, mfld_simps] lemma coe_coe : ⇑e.to_local_equiv = e := rfl @[simp, mfld_simps] lemma coe_fst (ex : x ∈ e.source) : (e x).1 = proj x := e.proj_to_fun x ex lemma mem_source : x ∈ e.source ↔ proj x ∈ e.base_set := by rw [e.source_eq, mem_preimage] lemma coe_fst' (ex : proj x ∈ e.base_set) : (e x).1 = proj x := e.coe_fst (e.mem_source.2 ex) protected lemma eq_on : eq_on (prod.fst ∘ e) proj e.source := λ x hx, e.coe_fst hx lemma mk_proj_snd (ex : x ∈ e.source) : (proj x, (e x).2) = e x := prod.ext (e.coe_fst ex).symm rfl lemma mk_proj_snd' (ex : proj x ∈ e.base_set) : (proj x, (e x).2) = e x := prod.ext (e.coe_fst' ex).symm rfl /-- Composition of inverse and coercion from the subtype of the target. -/ def set_symm : e.target → Z := set.restrict e.to_local_equiv.symm e.target lemma mem_target {x : B × F} : x ∈ e.target ↔ x.1 ∈ e.base_set := by rw [e.target_eq, prod_univ, mem_preimage] lemma proj_symm_apply {x : B × F} (hx : x ∈ e.target) : proj (e.to_local_equiv.symm x) = x.1 := begin have := (e.coe_fst (e.to_local_equiv.map_target hx)).symm, rwa [← e.coe_coe, e.to_local_equiv.right_inv hx] at this end lemma proj_symm_apply' {b : B} {x : F} (hx : b ∈ e.base_set) : proj (e.to_local_equiv.symm (b, x)) = b := e.proj_symm_apply (e.mem_target.2 hx) lemma apply_symm_apply {x : B × F} (hx : x ∈ e.target) : e (e.to_local_equiv.symm x) = x := e.to_local_equiv.right_inv hx lemma apply_symm_apply' {b : B} {x : F} (hx : b ∈ e.base_set) : e (e.to_local_equiv.symm (b, x)) = (b, x) := e.apply_symm_apply (e.mem_target.2 hx) @[simp, mfld_simps] lemma symm_apply_mk_proj {x : Z} (ex : x ∈ e.source) : e.to_local_equiv.symm (proj x, (e x).2) = x := by rw [← e.coe_fst ex, prod.mk.eta, ← e.coe_coe, e.to_local_equiv.left_inv ex] @[simp, mfld_simps] lemma preimage_symm_proj_base_set : (e.to_local_equiv.symm ⁻¹' (proj ⁻¹' e.base_set)) ∩ e.target = e.target := begin refine inter_eq_right_iff_subset.mpr (λ x hx, _), simp only [mem_preimage, local_equiv.inv_fun_as_coe, e.proj_symm_apply hx], exact e.mem_target.mp hx, end @[simp, mfld_simps] lemma preimage_symm_proj_inter (s : set B) : (e.to_local_equiv.symm ⁻¹' (proj ⁻¹' s)) ∩ e.base_set.prod univ = (s ∩ e.base_set).prod univ := begin refine subset.antisymm_iff.mpr ⟨(λ x hx, _), (λ x hx, mem_inter _ _)⟩, { rw [←e.target_eq] at hx, simp only [mem_inter_iff, mem_preimage, e.proj_symm_apply hx.2] at hx, simp only [mem_inter_eq, and_true, mem_univ, mem_prod], exact ⟨hx.1, e.mem_target.mp hx.2⟩, }, { simp only [mem_inter_eq, and_true, mem_univ, mem_prod, e.mem_target.symm] at hx, simp only [mem_preimage, e.proj_symm_apply hx.2], exact hx.1, }, { rw [←inter_univ univ, ←prod_inter_prod, mem_inter_eq] at hx, exact hx.2, } end end topological_fiber_bundle.pretrivialization variable [topological_space Z] /-- A structure extending local homeomorphisms, defining a local trivialization of a projection `proj : Z → B` with fiber `F`, as a local homeomorphism between `Z` and `B × F` defined between two sets of the form `proj ⁻¹' base_set` and `base_set × F`, acting trivially on the first coordinate. -/ @[nolint has_inhabited_instance] structure topological_fiber_bundle.trivialization (proj : Z → B) extends local_homeomorph Z (B × F) := (base_set : set B) (open_base_set : is_open base_set) (source_eq : source = proj ⁻¹' base_set) (target_eq : target = set.prod base_set univ) (proj_to_fun : ∀ p ∈ source, (to_local_homeomorph p).1 = proj p) open topological_fiber_bundle namespace topological_fiber_bundle.trivialization variables {F} (e : trivialization F proj) {x : Z} /-- Natural identification as a `pretrivialization`. -/ def to_pretrivialization : topological_fiber_bundle.pretrivialization F proj := { ..e } instance : has_coe_to_fun (trivialization F proj) (λ _, Z → B × F) := ⟨λ e, e.to_fun⟩ instance : has_coe (trivialization F proj) (pretrivialization F proj) := ⟨to_pretrivialization⟩ @[simp, mfld_simps] lemma coe_coe : ⇑e.to_local_homeomorph = e := rfl @[simp, mfld_simps] lemma coe_fst (ex : x ∈ e.source) : (e x).1 = proj x := e.proj_to_fun x ex protected lemma eq_on : eq_on (prod.fst ∘ e) proj e.source := λ x hx, e.coe_fst hx lemma mem_source : x ∈ e.source ↔ proj x ∈ e.base_set := by rw [e.source_eq, mem_preimage] lemma coe_fst' (ex : proj x ∈ e.base_set) : (e x).1 = proj x := e.coe_fst (e.mem_source.2 ex) lemma mk_proj_snd (ex : x ∈ e.source) : (proj x, (e x).2) = e x := prod.ext (e.coe_fst ex).symm rfl lemma mk_proj_snd' (ex : proj x ∈ e.base_set) : (proj x, (e x).2) = e x := prod.ext (e.coe_fst' ex).symm rfl lemma source_inter_preimage_target_inter (s : set (B × F)) : e.source ∩ (e ⁻¹' (e.target ∩ s)) = e.source ∩ (e ⁻¹' s) := e.to_local_homeomorph.source_inter_preimage_target_inter s @[simp, mfld_simps] lemma coe_mk (e : local_homeomorph Z (B × F)) (i j k l m) (x : Z) : (trivialization.mk e i j k l m : trivialization F proj) x = e x := rfl lemma mem_target {x : B × F} : x ∈ e.target ↔ x.1 ∈ e.base_set := e.to_pretrivialization.mem_target lemma map_target {x : B × F} (hx : x ∈ e.target) : e.to_local_homeomorph.symm x ∈ e.source := e.to_local_homeomorph.map_target hx lemma proj_symm_apply {x : B × F} (hx : x ∈ e.target) : proj (e.to_local_homeomorph.symm x) = x.1 := e.to_pretrivialization.proj_symm_apply hx lemma proj_symm_apply' {b : B} {x : F} (hx : b ∈ e.base_set) : proj (e.to_local_homeomorph.symm (b, x)) = b := e.to_pretrivialization.proj_symm_apply' hx lemma apply_symm_apply {x : B × F} (hx : x ∈ e.target) : e (e.to_local_homeomorph.symm x) = x := e.to_local_homeomorph.right_inv hx lemma apply_symm_apply' {b : B} {x : F} (hx : b ∈ e.base_set) : e (e.to_local_homeomorph.symm (b, x)) = (b, x) := e.to_pretrivialization.apply_symm_apply' hx @[simp, mfld_simps] lemma symm_apply_mk_proj (ex : x ∈ e.source) : e.to_local_homeomorph.symm (proj x, (e x).2) = x := e.to_pretrivialization.symm_apply_mk_proj ex lemma coe_fst_eventually_eq_proj (ex : x ∈ e.source) : prod.fst ∘ e =ᶠ[𝓝 x] proj := mem_nhds_iff.2 ⟨e.source, λ y hy, e.coe_fst hy, e.open_source, ex⟩ lemma coe_fst_eventually_eq_proj' (ex : proj x ∈ e.base_set) : prod.fst ∘ e =ᶠ[𝓝 x] proj := e.coe_fst_eventually_eq_proj (e.mem_source.2 ex) lemma map_proj_nhds (ex : x ∈ e.source) : map proj (𝓝 x) = 𝓝 (proj x) := by rw [← e.coe_fst ex, ← map_congr (e.coe_fst_eventually_eq_proj ex), ← map_map, ← e.coe_coe, e.to_local_homeomorph.map_nhds_eq ex, map_fst_nhds] /-- In the domain of a bundle trivialization, the projection is continuous-/ lemma continuous_at_proj (ex : x ∈ e.source) : continuous_at proj x := (e.map_proj_nhds ex).le /-- Composition of a `trivialization` and a `homeomorph`. -/ def comp_homeomorph {Z' : Type*} [topological_space Z'] (h : Z' ≃ₜ Z) : trivialization F (proj ∘ h) := { to_local_homeomorph := h.to_local_homeomorph.trans e.to_local_homeomorph, base_set := e.base_set, open_base_set := e.open_base_set, source_eq := by simp [e.source_eq, preimage_preimage], target_eq := by simp [e.target_eq], proj_to_fun := λ p hp, have hp : h p ∈ e.source, by simpa using hp, by simp [hp] } end topological_fiber_bundle.trivialization /-- A topological fiber bundle with fiber `F` over a base `B` is a space projecting on `B` for which the fibers are all homeomorphic to `F`, such that the local situation around each point is a direct product. -/ def is_topological_fiber_bundle (proj : Z → B) : Prop := ∀ x : B, ∃e : trivialization F proj, x ∈ e.base_set /-- A trivial topological fiber bundle with fiber `F` over a base `B` is a space `Z` projecting on `B` for which there exists a homeomorphism to `B × F` that sends `proj` to `prod.fst`. -/ def is_trivial_topological_fiber_bundle (proj : Z → B) : Prop := ∃ e : Z ≃ₜ (B × F), ∀ x, (e x).1 = proj x variables {F} lemma is_trivial_topological_fiber_bundle.is_topological_fiber_bundle (h : is_trivial_topological_fiber_bundle F proj) : is_topological_fiber_bundle F proj := let ⟨e, he⟩ := h in λ x, ⟨⟨e.to_local_homeomorph, univ, is_open_univ, rfl, univ_prod_univ.symm, λ x _, he x⟩, mem_univ x⟩ /-- The projection from a topological fiber bundle to its base is continuous. -/ lemma is_topological_fiber_bundle.continuous_proj (h : is_topological_fiber_bundle F proj) : continuous proj := begin rw continuous_iff_continuous_at, assume x, rcases h (proj x) with ⟨e, ex⟩, apply e.continuous_at_proj, rwa e.source_eq end /-- The projection from a topological fiber bundle to its base is an open map. -/ lemma is_topological_fiber_bundle.is_open_map_proj (h : is_topological_fiber_bundle F proj) : is_open_map proj := begin refine is_open_map_iff_nhds_le.2 (λ x, _), rcases h (proj x) with ⟨e, ex⟩, refine (e.map_proj_nhds _).ge, rwa e.source_eq end /-- The first projection in a product is a trivial topological fiber bundle. -/ lemma is_trivial_topological_fiber_bundle_fst : is_trivial_topological_fiber_bundle F (prod.fst : B × F → B) := ⟨homeomorph.refl _, λ x, rfl⟩ /-- The first projection in a product is a topological fiber bundle. -/ lemma is_topological_fiber_bundle_fst : is_topological_fiber_bundle F (prod.fst : B × F → B) := is_trivial_topological_fiber_bundle_fst.is_topological_fiber_bundle /-- The second projection in a product is a trivial topological fiber bundle. -/ lemma is_trivial_topological_fiber_bundle_snd : is_trivial_topological_fiber_bundle F (prod.snd : F × B → B) := ⟨homeomorph.prod_comm _ _, λ x, rfl⟩ /-- The second projection in a product is a topological fiber bundle. -/ lemma is_topological_fiber_bundle_snd : is_topological_fiber_bundle F (prod.snd : F × B → B) := is_trivial_topological_fiber_bundle_snd.is_topological_fiber_bundle lemma is_topological_fiber_bundle.comp_homeomorph {Z' : Type*} [topological_space Z'] (e : is_topological_fiber_bundle F proj) (h : Z' ≃ₜ Z) : is_topological_fiber_bundle F (proj ∘ h) := λ x, let ⟨e, he⟩ := e x in ⟨e.comp_homeomorph h, by simpa [topological_fiber_bundle.trivialization.comp_homeomorph] using he⟩ namespace topological_fiber_bundle.trivialization /-- If `e` is a `trivialization` of `proj : Z → B` with fiber `F` and `h` is a homeomorphism `F ≃ₜ F'`, then `e.trans_fiber_homeomorph h` is the trivialization of `proj` with the fiber `F'` that sends `p : Z` to `((e p).1, h (e p).2)`. -/ def trans_fiber_homeomorph {F' : Type*} [topological_space F'] (e : trivialization F proj) (h : F ≃ₜ F') : trivialization F' proj := { to_local_homeomorph := e.to_local_homeomorph.trans ((homeomorph.refl _).prod_congr h).to_local_homeomorph, base_set := e.base_set, open_base_set := e.open_base_set, source_eq := by simp [e.source_eq], target_eq := by { ext, simp [e.target_eq] }, proj_to_fun := λ p hp, have p ∈ e.source, by simpa using hp, by simp [this] } @[simp] lemma trans_fiber_homeomorph_apply {F' : Type*} [topological_space F'] (e : trivialization F proj) (h : F ≃ₜ F') (x : Z) : e.trans_fiber_homeomorph h x = ((e x).1, h (e x).2) := rfl /-- Coordinate transformation in the fiber induced by a pair of bundle trivializations. See also `trivialization.coord_change_homeomorph` for a version bundled as `F ≃ₜ F`. -/ def coord_change (e₁ e₂ : trivialization F proj) (b : B) (x : F) : F := (e₂ $ e₁.to_local_homeomorph.symm (b, x)).2 lemma mk_coord_change (e₁ e₂ : trivialization F proj) {b : B} (h₁ : b ∈ e₁.base_set) (h₂ : b ∈ e₂.base_set) (x : F) : (b, e₁.coord_change e₂ b x) = e₂ (e₁.to_local_homeomorph.symm (b, x)) := begin refine prod.ext _ rfl, rw [e₂.coe_fst', ← e₁.coe_fst', e₁.apply_symm_apply' h₁], { rwa [e₁.proj_symm_apply' h₁] }, { rwa [e₁.proj_symm_apply' h₁] } end lemma coord_change_apply_snd (e₁ e₂ : trivialization F proj) {p : Z} (h : proj p ∈ e₁.base_set) : e₁.coord_change e₂ (proj p) (e₁ p).snd = (e₂ p).snd := by rw [coord_change, e₁.symm_apply_mk_proj (e₁.mem_source.2 h)] lemma coord_change_same_apply (e : trivialization F proj) {b : B} (h : b ∈ e.base_set) (x : F) : e.coord_change e b x = x := by rw [coord_change, e.apply_symm_apply' h] lemma coord_change_same (e : trivialization F proj) {b : B} (h : b ∈ e.base_set) : e.coord_change e b = id := funext $ e.coord_change_same_apply h lemma coord_change_coord_change (e₁ e₂ e₃ : trivialization F proj) {b : B} (h₁ : b ∈ e₁.base_set) (h₂ : b ∈ e₂.base_set) (x : F) : e₂.coord_change e₃ b (e₁.coord_change e₂ b x) = e₁.coord_change e₃ b x := begin rw [coord_change, e₁.mk_coord_change _ h₁ h₂, ← e₂.coe_coe, e₂.to_local_homeomorph.left_inv, coord_change], rwa [e₂.mem_source, e₁.proj_symm_apply' h₁] end lemma continuous_coord_change (e₁ e₂ : trivialization F proj) {b : B} (h₁ : b ∈ e₁.base_set) (h₂ : b ∈ e₂.base_set) : continuous (e₁.coord_change e₂ b) := begin refine continuous_snd.comp (e₂.to_local_homeomorph.continuous_on.comp_continuous (e₁.to_local_homeomorph.continuous_on_symm.comp_continuous _ _) _), { exact continuous_const.prod_mk continuous_id }, { exact λ x, e₁.mem_target.2 h₁ }, { intro x, rwa [e₂.mem_source, e₁.proj_symm_apply' h₁] } end /-- Coordinate transformation in the fiber induced by a pair of bundle trivializations, as a homeomorphism. -/ def coord_change_homeomorph (e₁ e₂ : trivialization F proj) {b : B} (h₁ : b ∈ e₁.base_set) (h₂ : b ∈ e₂.base_set) : F ≃ₜ F := { to_fun := e₁.coord_change e₂ b, inv_fun := e₂.coord_change e₁ b, left_inv := λ x, by simp only [*, coord_change_coord_change, coord_change_same_apply], right_inv := λ x, by simp only [*, coord_change_coord_change, coord_change_same_apply], continuous_to_fun := e₁.continuous_coord_change e₂ h₁ h₂, continuous_inv_fun := e₂.continuous_coord_change e₁ h₂ h₁ } @[simp] lemma coord_change_homeomorph_coe (e₁ e₂ : trivialization F proj) {b : B} (h₁ : b ∈ e₁.base_set) (h₂ : b ∈ e₂.base_set) : ⇑(e₁.coord_change_homeomorph e₂ h₁ h₂) = e₁.coord_change e₂ b := rfl end topological_fiber_bundle.trivialization section comap open_locale classical variables {B' : Type*} [topological_space B'] /-- Given a bundle trivialization of `proj : Z → B` and a continuous map `f : B' → B`, construct a bundle trivialization of `φ : {p : B' × Z | f p.1 = proj p.2} → B'` given by `φ x = (x : B' × Z).1`. -/ noncomputable def topological_fiber_bundle.trivialization.comap (e : trivialization F proj) (f : B' → B) (hf : continuous f) (b' : B') (hb' : f b' ∈ e.base_set) : trivialization F (λ x : {p : B' × Z | f p.1 = proj p.2}, (x : B' × Z).1) := { to_fun := λ p, ((p : B' × Z).1, (e (p : B' × Z).2).2), inv_fun := λ p, if h : f p.1 ∈ e.base_set then ⟨⟨p.1, e.to_local_homeomorph.symm (f p.1, p.2)⟩, by simp [e.proj_symm_apply' h]⟩ else ⟨⟨b', e.to_local_homeomorph.symm (f b', p.2)⟩, by simp [e.proj_symm_apply' hb']⟩, source := {p | f (p : B' × Z).1 ∈ e.base_set}, target := {p | f p.1 ∈ e.base_set}, map_source' := λ p hp, hp, map_target' := λ p (hp : f p.1 ∈ e.base_set), by simp [hp], left_inv' := begin rintro ⟨⟨b, x⟩, hbx⟩ hb, dsimp at *, have hx : x ∈ e.source, from e.mem_source.2 (hbx ▸ hb), ext; simp * end, right_inv' := λ p (hp : f p.1 ∈ e.base_set), by simp [*, e.apply_symm_apply'], open_source := e.open_base_set.preimage (hf.comp $ continuous_fst.comp continuous_subtype_coe), open_target := e.open_base_set.preimage (hf.comp continuous_fst), continuous_to_fun := ((continuous_fst.comp continuous_subtype_coe).continuous_on).prod $ continuous_snd.comp_continuous_on $ e.continuous_to_fun.comp (continuous_snd.comp continuous_subtype_coe).continuous_on $ by { rintro ⟨⟨b, x⟩, (hbx : f b = proj x)⟩ (hb : f b ∈ e.base_set), rw hbx at hb, exact e.mem_source.2 hb }, continuous_inv_fun := begin rw [embedding_subtype_coe.continuous_on_iff], suffices : continuous_on (λ p : B' × F, (p.1, e.to_local_homeomorph.symm (f p.1, p.2))) {p : B' × F | f p.1 ∈ e.base_set}, { refine this.congr (λ p (hp : f p.1 ∈ e.base_set), _), simp [hp] }, { refine continuous_on_fst.prod (e.to_local_homeomorph.symm.continuous_on.comp _ _), { exact ((hf.comp continuous_fst).prod_mk continuous_snd).continuous_on }, { exact λ p hp, e.mem_target.2 hp } } end, base_set := f ⁻¹' e.base_set, source_eq := rfl, target_eq := by { ext, simp }, open_base_set := e.open_base_set.preimage hf, proj_to_fun := λ _ _, rfl } /-- If `proj : Z → B` is a topological fiber bundle with fiber `F` and `f : B' → B` is a continuous map, then the pullback bundle (a.k.a. induced bundle) is the topological bundle with the total space `{(x, y) : B' × Z | f x = proj y}` given by `λ ⟨(x, y), h⟩, x`. -/ lemma is_topological_fiber_bundle.comap (h : is_topological_fiber_bundle F proj) {f : B' → B} (hf : continuous f) : is_topological_fiber_bundle F (λ x : {p : B' × Z | f p.1 = proj p.2}, (x : B' × Z).1) := λ x, let ⟨e, he⟩ := h (f x) in ⟨e.comap f hf x he, he⟩ end comap namespace topological_fiber_bundle.trivialization lemma is_image_preimage_prod (e : trivialization F proj) (s : set B) : e.to_local_homeomorph.is_image (proj ⁻¹' s) (s.prod univ) := λ x hx, by simp [e.coe_fst', hx] /-- Restrict a `trivialization` to an open set in the base. `-/ def restr_open (e : trivialization F proj) (s : set B) (hs : is_open s) : trivialization F proj := { to_local_homeomorph := ((e.is_image_preimage_prod s).symm.restr (is_open.inter e.open_target (hs.prod is_open_univ))).symm, base_set := e.base_set ∩ s, open_base_set := is_open.inter e.open_base_set hs, source_eq := by simp [e.source_eq], target_eq := by simp [e.target_eq, prod_univ], proj_to_fun := λ p hp, e.proj_to_fun p hp.1 } section piecewise lemma frontier_preimage (e : trivialization F proj) (s : set B) : e.source ∩ frontier (proj ⁻¹' s) = proj ⁻¹' (e.base_set ∩ frontier s) := by rw [← (e.is_image_preimage_prod s).frontier.preimage_eq, frontier_prod_univ_eq, (e.is_image_preimage_prod _).preimage_eq, e.source_eq, preimage_inter] /-- Given two bundle trivializations `e`, `e'` of `proj : Z → B` and a set `s : set B` such that the base sets of `e` and `e'` intersect `frontier s` on the same set and `e p = e' p` whenever `proj p ∈ e.base_set ∩ frontier s`, `e.piecewise e' s Hs Heq` is the bundle trivialization over `set.ite s e.base_set e'.base_set` that is equal to `e` on `proj ⁻¹ s` and is equal to `e'` otherwise. -/ noncomputable def piecewise (e e' : trivialization F proj) (s : set B) (Hs : e.base_set ∩ frontier s = e'.base_set ∩ frontier s) (Heq : eq_on e e' $ proj ⁻¹' (e.base_set ∩ frontier s)) : trivialization F proj := { to_local_homeomorph := e.to_local_homeomorph.piecewise e'.to_local_homeomorph (proj ⁻¹' s) (s.prod univ) (e.is_image_preimage_prod s) (e'.is_image_preimage_prod s) (by rw [e.frontier_preimage, e'.frontier_preimage, Hs]) (by rwa e.frontier_preimage), base_set := s.ite e.base_set e'.base_set, open_base_set := e.open_base_set.ite e'.open_base_set Hs, source_eq := by simp [e.source_eq, e'.source_eq], target_eq := by simp [e.target_eq, e'.target_eq, prod_univ], proj_to_fun := by rintro p (⟨he, hs⟩|⟨he, hs⟩); simp * } /-- Given two bundle trivializations `e`, `e'` of a topological fiber bundle `proj : Z → B` over a linearly ordered base `B` and a point `a ∈ e.base_set ∩ e'.base_set` such that `e` equals `e'` on `proj ⁻¹' {a}`, `e.piecewise_le_of_eq e' a He He' Heq` is the bundle trivialization over `set.ite (Iic a) e.base_set e'.base_set` that is equal to `e` on points `p` such that `proj p ≤ a` and is equal to `e'` otherwise. -/ noncomputable def piecewise_le_of_eq [linear_order B] [order_topology B] (e e' : trivialization F proj) (a : B) (He : a ∈ e.base_set) (He' : a ∈ e'.base_set) (Heq : ∀ p, proj p = a → e p = e' p) : trivialization F proj := e.piecewise e' (Iic a) (set.ext $ λ x, and.congr_left_iff.2 $ λ hx, by simp [He, He', mem_singleton_iff.1 (frontier_Iic_subset _ hx)]) (λ p hp, Heq p $ frontier_Iic_subset _ hp.2) /-- Given two bundle trivializations `e`, `e'` of a topological fiber bundle `proj : Z → B` over a linearly ordered base `B` and a point `a ∈ e.base_set ∩ e'.base_set`, `e.piecewise_le e' a He He'` is the bundle trivialization over `set.ite (Iic a) e.base_set e'.base_set` that is equal to `e` on points `p` such that `proj p ≤ a` and is equal to `((e' p).1, h (e' p).2)` otherwise, where `h = `e'.coord_change_homeomorph e _ _` is the homeomorphism of the fiber such that `h (e' p).2 = (e p).2` whenever `e p = a`. -/ noncomputable def piecewise_le [linear_order B] [order_topology B] (e e' : trivialization F proj) (a : B) (He : a ∈ e.base_set) (He' : a ∈ e'.base_set) : trivialization F proj := e.piecewise_le_of_eq (e'.trans_fiber_homeomorph (e'.coord_change_homeomorph e He' He)) a He He' $ by { unfreezingI {rintro p rfl }, ext1, { simp [e.coe_fst', e'.coe_fst', *] }, { simp [e'.coord_change_apply_snd, *] } } /-- Given two bundle trivializations `e`, `e'` over disjoint sets, `e.disjoint_union e' H` is the bundle trivialization over the union of the base sets that agrees with `e` and `e'` over their base sets. -/ noncomputable def disjoint_union (e e' : trivialization F proj) (H : disjoint e.base_set e'.base_set) : trivialization F proj := { to_local_homeomorph := e.to_local_homeomorph.disjoint_union e'.to_local_homeomorph (λ x hx, by { rw [e.source_eq, e'.source_eq] at hx, exact H hx }) (λ x hx, by { rw [e.target_eq, e'.target_eq] at hx, exact H ⟨hx.1.1, hx.2.1⟩ }), base_set := e.base_set ∪ e'.base_set, open_base_set := is_open.union e.open_base_set e'.open_base_set, source_eq := congr_arg2 (∪) e.source_eq e'.source_eq, target_eq := (congr_arg2 (∪) e.target_eq e'.target_eq).trans union_prod.symm, proj_to_fun := begin rintro p (hp|hp'), { show (e.source.piecewise e e' p).1 = proj p, rw [piecewise_eq_of_mem, e.coe_fst]; exact hp }, { show (e.source.piecewise e e' p).1 = proj p, rw [piecewise_eq_of_not_mem, e'.coe_fst hp'], simp only [e.source_eq, e'.source_eq] at hp' ⊢, exact λ h, H ⟨h, hp'⟩ } end } /-- If `h` is a topological fiber bundle over a conditionally complete linear order, then it is trivial over any closed interval. -/ lemma _root_.is_topological_fiber_bundle.exists_trivialization_Icc_subset [conditionally_complete_linear_order B] [order_topology B] (h : is_topological_fiber_bundle F proj) (a b : B) : ∃ e : trivialization F proj, Icc a b ⊆ e.base_set := begin classical, obtain ⟨ea, hea⟩ : ∃ ea : trivialization F proj, a ∈ ea.base_set := h a, -- If `a < b`, then `[a, b] = ∅`, and the statement is trivial cases le_or_lt a b with hab hab; [skip, exact ⟨ea, by simp *⟩], /- Let `s` be the set of points `x ∈ [a, b]` such that `proj` is trivializable over `[a, x]`. We need to show that `b ∈ s`. Let `c = Sup s`. We will show that `c ∈ s` and `c = b`. -/ set s : set B := {x ∈ Icc a b | ∃ e : trivialization F proj, Icc a x ⊆ e.base_set}, have ha : a ∈ s, from ⟨left_mem_Icc.2 hab, ea, by simp [hea]⟩, have sne : s.nonempty := ⟨a, ha⟩, have hsb : b ∈ upper_bounds s, from λ x hx, hx.1.2, have sbd : bdd_above s := ⟨b, hsb⟩, set c := Sup s, have hsc : is_lub s c, from is_lub_cSup sne sbd, have hc : c ∈ Icc a b, from ⟨hsc.1 ha, hsc.2 hsb⟩, obtain ⟨-, ec : trivialization F proj, hec : Icc a c ⊆ ec.base_set⟩ : c ∈ s, { cases hc.1.eq_or_lt with heq hlt, { rwa ← heq }, refine ⟨hc, _⟩, /- In order to show that `c ∈ s`, consider a trivialization `ec` of `proj` over a neighborhood of `c`. Its base set includes `(c', c]` for some `c' ∈ [a, c)`. -/ rcases h c with ⟨ec, hc⟩, obtain ⟨c', hc', hc'e⟩ : ∃ c' ∈ Ico a c, Ioc c' c ⊆ ec.base_set := (mem_nhds_within_Iic_iff_exists_mem_Ico_Ioc_subset hlt).1 (mem_nhds_within_of_mem_nhds $ is_open.mem_nhds ec.open_base_set hc), /- Since `c' < c = Sup s`, there exists `d ∈ s ∩ (c', c]`. Let `ead` be a trivialization of `proj` over `[a, d]`. Then we can glue `ead` and `ec` into a trivialization over `[a, c]`. -/ obtain ⟨d, ⟨hdab, ead, had⟩, hd⟩ : ∃ d ∈ s, d ∈ Ioc c' c := hsc.exists_between hc'.2, refine ⟨ead.piecewise_le ec d (had ⟨hdab.1, le_rfl⟩) (hc'e hd), subset_ite.2 _⟩, refine ⟨λ x hx, had ⟨hx.1.1, hx.2⟩, λ x hx, hc'e ⟨hd.1.trans (not_le.1 hx.2), hx.1.2⟩⟩ }, /- So, `c ∈ s`. Let `ec` be a trivialization of `proj` over `[a, c]`. If `c = b`, then we are done. Otherwise we show that `proj` can be trivialized over a larger interval `[a, d]`, `d ∈ (c, b]`, hence `c` is not an upper bound of `s`. -/ cases hc.2.eq_or_lt with heq hlt, { exact ⟨ec, heq ▸ hec⟩ }, suffices : ∃ (d ∈ Ioc c b) (e : trivialization F proj), Icc a d ⊆ e.base_set, { rcases this with ⟨d, hdcb, hd⟩, exact ((hsc.1 ⟨⟨hc.1.trans hdcb.1.le, hdcb.2⟩, hd⟩).not_lt hdcb.1).elim }, /- Since the base set of `ec` is open, it includes `[c, d)` (hence, `[a, d)`) for some `d ∈ (c, b]`. -/ obtain ⟨d, hdcb, hd⟩ : ∃ d ∈ Ioc c b, Ico c d ⊆ ec.base_set := (mem_nhds_within_Ici_iff_exists_mem_Ioc_Ico_subset hlt).1 (mem_nhds_within_of_mem_nhds $ is_open.mem_nhds ec.open_base_set (hec ⟨hc.1, le_rfl⟩)), have had : Ico a d ⊆ ec.base_set, from subset.trans Ico_subset_Icc_union_Ico (union_subset hec hd), by_cases he : disjoint (Iio d) (Ioi c), { /- If `(c, d) = ∅`, then let `ed` be a trivialization of `proj` over a neighborhood of `d`. Then the disjoint union of `ec` restricted to `(-∞, d)` and `ed` restricted to `(c, ∞)` is a trivialization over `[a, d]`. -/ rcases h d with ⟨ed, hed⟩, refine ⟨d, hdcb, (ec.restr_open (Iio d) is_open_Iio).disjoint_union (ed.restr_open (Ioi c) is_open_Ioi) (he.mono (inter_subset_right _ _) (inter_subset_right _ _)), λ x hx, _⟩, rcases hx.2.eq_or_lt with rfl|hxd, exacts [or.inr ⟨hed, hdcb.1⟩, or.inl ⟨had ⟨hx.1, hxd⟩, hxd⟩] }, { /- If `(c, d)` is nonempty, then take `d' ∈ (c, d)`. Since the base set of `ec` includes `[a, d)`, it includes `[a, d'] ⊆ [a, d)` as well. -/ rw [disjoint_left] at he, push_neg at he, rcases he with ⟨d', hdd' : d' < d, hd'c⟩, exact ⟨d', ⟨hd'c, hdd'.le.trans hdcb.2⟩, ec, subset.trans (Icc_subset_Ico_right hdd') had⟩ } end end piecewise end topological_fiber_bundle.trivialization end topological_fiber_bundle /-! ### Constructing topological fiber bundles -/ namespace bundle variable (E : B → Type*) attribute [mfld_simps] proj total_space_mk coe_fst coe_snd_map_apply coe_snd_map_smul 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)) := topological_space.induced (proj (trivial B F)) t₁ ⊓ topological_space.induced (trivial.proj_snd B F) t₂ end bundle /-- Core data defining a locally trivial topological bundle with fiber `F` over a topological space `B`. Note that "bundle" is used in its mathematical sense. This is the (computer science) bundled version, i.e., all the relevant data is contained in the following structure. A family of local trivializations is indexed by a type `ι`, on open subsets `base_set i` for each `i : ι`. Trivialization changes from `i` to `j` are given by continuous maps `coord_change i j` from `base_set i ∩ base_set j` to the set of homeomorphisms of `F`, but we express them as maps `B → F → F` and require continuity on `(base_set i ∩ base_set j) × F` to avoid the topology on the space of continuous maps on `F`. -/ @[nolint has_inhabited_instance] structure topological_fiber_bundle_core (ι : Type*) (B : Type*) [topological_space B] (F : Type*) [topological_space F] := (base_set : ι → set B) (is_open_base_set : ∀ i, is_open (base_set i)) (index_at : B → ι) (mem_base_set_at : ∀ x, x ∈ base_set (index_at x)) (coord_change : ι → ι → B → F → F) (coord_change_self : ∀ i, ∀ x ∈ base_set i, ∀ v, coord_change i i x v = v) (coord_change_continuous : ∀ i j, continuous_on (λp : B × F, coord_change i j p.1 p.2) (set.prod ((base_set i) ∩ (base_set j)) univ)) (coord_change_comp : ∀ i j k, ∀ x ∈ (base_set i) ∩ (base_set j) ∩ (base_set k), ∀ v, (coord_change j k x) (coord_change i j x v) = coord_change i k x v) namespace topological_fiber_bundle_core variables [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F) include Z /-- The index set of a topological fiber bundle core, as a convenience function for dot notation -/ @[nolint unused_arguments has_inhabited_instance] def index := ι /-- The base space of a topological fiber bundle core, as a convenience function for dot notation -/ @[nolint unused_arguments, reducible] def base := B /-- The fiber of a topological fiber bundle core, as a convenience function for dot notation and typeclass inference -/ @[nolint unused_arguments has_inhabited_instance] def fiber (x : B) := F section fiber_instances local attribute [reducible] fiber instance topological_space_fiber (x : B) : topological_space (Z.fiber x) := by apply_instance end fiber_instances /-- The total space of the topological fiber bundle, as a convenience function for dot notation. It is by definition equal to `bundle.total_space Z.fiber`, a.k.a. `Σ x, Z.fiber x` but with a different name for typeclass inference. -/ @[nolint unused_arguments, reducible] def total_space := bundle.total_space Z.fiber /-- The projection from the total space of a topological fiber bundle core, on its base. -/ @[reducible, simp, mfld_simps] def proj : Z.total_space → B := bundle.proj Z.fiber /-- Local homeomorphism version of the trivialization change. -/ def triv_change (i j : ι) : local_homeomorph (B × F) (B × F) := { source := set.prod (Z.base_set i ∩ Z.base_set j) univ, target := set.prod (Z.base_set i ∩ Z.base_set j) univ, to_fun := λp, ⟨p.1, Z.coord_change i j p.1 p.2⟩, inv_fun := λp, ⟨p.1, Z.coord_change j i p.1 p.2⟩, map_source' := λp hp, by simpa using hp, map_target' := λp hp, by simpa using hp, left_inv' := begin rintros ⟨x, v⟩ hx, simp only [prod_mk_mem_set_prod_eq, mem_inter_eq, and_true, mem_univ] at hx, rw [Z.coord_change_comp, Z.coord_change_self], { exact hx.1 }, { simp [hx] } end, right_inv' := begin rintros ⟨x, v⟩ hx, simp only [prod_mk_mem_set_prod_eq, mem_inter_eq, and_true, mem_univ] at hx, rw [Z.coord_change_comp, Z.coord_change_self], { exact hx.2 }, { simp [hx] }, end, open_source := (is_open.inter (Z.is_open_base_set i) (Z.is_open_base_set j)).prod is_open_univ, open_target := (is_open.inter (Z.is_open_base_set i) (Z.is_open_base_set j)).prod is_open_univ, continuous_to_fun := continuous_on.prod continuous_fst.continuous_on (Z.coord_change_continuous i j), continuous_inv_fun := by simpa [inter_comm] using continuous_on.prod continuous_fst.continuous_on (Z.coord_change_continuous j i) } @[simp, mfld_simps] lemma mem_triv_change_source (i j : ι) (p : B × F) : p ∈ (Z.triv_change i j).source ↔ p.1 ∈ Z.base_set i ∩ Z.base_set j := by { erw [mem_prod], simp } /-- Associate to a trivialization index `i : ι` the corresponding trivialization, i.e., a bijection between `proj ⁻¹ (base_set i)` and `base_set i × F`. As the fiber above `x` is `F` but read in the chart with index `index_at x`, the trivialization in the fiber above x is by definition the coordinate change from i to `index_at x`, so it depends on `x`. The local trivialization will ultimately be a local homeomorphism. For now, we only introduce the local equiv version, denoted with a prime. In further developments, avoid this auxiliary version, and use `Z.local_triv` instead. -/ def local_triv_as_local_equiv (i : ι) : local_equiv Z.total_space (B × F) := { source := Z.proj ⁻¹' (Z.base_set i), target := set.prod (Z.base_set i) univ, inv_fun := λp, ⟨p.1, Z.coord_change i (Z.index_at p.1) p.1 p.2⟩, to_fun := λp, ⟨p.1, Z.coord_change (Z.index_at p.1) i p.1 p.2⟩, map_source' := λp hp, by simpa only [set.mem_preimage, and_true, set.mem_univ, set.prod_mk_mem_set_prod_eq] using hp, map_target' := λp hp, by simpa only [set.mem_preimage, and_true, set.mem_univ, set.mem_prod] using hp, left_inv' := begin rintros ⟨x, v⟩ hx, change x ∈ Z.base_set i at hx, dsimp only, rw [Z.coord_change_comp, Z.coord_change_self], { exact Z.mem_base_set_at _ }, { simp only [hx, mem_inter_eq, and_self, mem_base_set_at] } end, right_inv' := begin rintros ⟨x, v⟩ hx, simp only [prod_mk_mem_set_prod_eq, and_true, mem_univ] at hx, rw [Z.coord_change_comp, Z.coord_change_self], { exact hx }, { simp only [hx, mem_inter_eq, and_self, mem_base_set_at] } end } variable (i : ι) lemma mem_local_triv_as_local_equiv_source (p : Z.total_space) : p ∈ (Z.local_triv_as_local_equiv i).source ↔ p.1 ∈ Z.base_set i := iff.rfl lemma mem_local_triv_as_local_equiv_target (p : B × F) : p ∈ (Z.local_triv_as_local_equiv i).target ↔ p.1 ∈ Z.base_set i := by { erw [mem_prod], simp only [and_true, mem_univ] } lemma local_triv_as_local_equiv_apply (p : Z.total_space) : (Z.local_triv_as_local_equiv i) p = ⟨p.1, Z.coord_change (Z.index_at p.1) i p.1 p.2⟩ := rfl /-- The composition of two local trivializations is the trivialization change Z.triv_change i j. -/ lemma local_triv_as_local_equiv_trans (i j : ι) : (Z.local_triv_as_local_equiv i).symm.trans (Z.local_triv_as_local_equiv j) ≈ (Z.triv_change i j).to_local_equiv := begin split, { ext x, simp only [mem_local_triv_as_local_equiv_target] with mfld_simps, refl, }, { rintros ⟨x, v⟩ hx, simp only [triv_change, local_triv_as_local_equiv, local_equiv.symm, true_and, prod.mk.inj_iff, prod_mk_mem_set_prod_eq, local_equiv.trans_source, mem_inter_eq, and_true, mem_preimage, proj, mem_univ, local_equiv.coe_mk, eq_self_iff_true, local_equiv.coe_trans, bundle.proj] at hx ⊢, simp only [Z.coord_change_comp, hx, mem_inter_eq, and_self, mem_base_set_at], } end variable (ι) /-- Topological structure on the total space of a topological bundle created from core, designed so that all the local trivialization are continuous. -/ instance to_topological_space : topological_space (bundle.total_space Z.fiber) := topological_space.generate_from $ ⋃ (i : ι) (s : set (B × F)) (s_open : is_open s), {(Z.local_triv_as_local_equiv i).source ∩ (Z.local_triv_as_local_equiv i) ⁻¹' s} variable {ι} lemma open_source' (i : ι) : is_open (Z.local_triv_as_local_equiv i).source := begin apply topological_space.generate_open.basic, simp only [exists_prop, mem_Union, mem_singleton_iff], refine ⟨i, set.prod (Z.base_set i) univ, (Z.is_open_base_set i).prod is_open_univ, _⟩, ext p, simp only [local_triv_as_local_equiv_apply, prod_mk_mem_set_prod_eq, mem_inter_eq, and_self, mem_local_triv_as_local_equiv_source, and_true, mem_univ, mem_preimage], end open topological_fiber_bundle /-- Extended version of the local trivialization of a fiber bundle constructed from core, registering additionally in its type that it is a local bundle trivialization. -/ def local_triv (i : ι) : trivialization F Z.proj := { base_set := Z.base_set i, open_base_set := Z.is_open_base_set i, source_eq := rfl, target_eq := rfl, proj_to_fun := λ p hp, by { simp only with mfld_simps, refl }, open_source := Z.open_source' i, open_target := (Z.is_open_base_set i).prod is_open_univ, continuous_to_fun := begin rw continuous_on_open_iff (Z.open_source' i), assume s s_open, apply topological_space.generate_open.basic, simp only [exists_prop, mem_Union, mem_singleton_iff], exact ⟨i, s, s_open, rfl⟩ end, continuous_inv_fun := begin apply continuous_on_open_of_generate_from ((Z.is_open_base_set i).prod is_open_univ), assume t ht, simp only [exists_prop, mem_Union, mem_singleton_iff] at ht, obtain ⟨j, s, s_open, ts⟩ : ∃ j s, is_open s ∧ t = (local_triv_as_local_equiv Z j).source ∩ (local_triv_as_local_equiv Z j) ⁻¹' s := ht, rw ts, simp only [local_equiv.right_inv, preimage_inter, local_equiv.left_inv], let e := Z.local_triv_as_local_equiv i, let e' := Z.local_triv_as_local_equiv j, let f := e.symm.trans e', have : is_open (f.source ∩ f ⁻¹' s), { rw [(Z.local_triv_as_local_equiv_trans i j).source_inter_preimage_eq], exact (continuous_on_open_iff (Z.triv_change i j).open_source).1 ((Z.triv_change i j).continuous_on) _ s_open }, convert this using 1, dsimp [local_equiv.trans_source], rw [← preimage_comp, inter_assoc], refl, end, to_local_equiv := Z.local_triv_as_local_equiv i } /-- A topological fiber bundle constructed from core is indeed a topological fiber bundle. -/ protected theorem is_topological_fiber_bundle : is_topological_fiber_bundle F Z.proj := λx, ⟨Z.local_triv (Z.index_at x), Z.mem_base_set_at x⟩ /-- The projection on the base of a topological bundle created from core is continuous -/ lemma continuous_proj : continuous Z.proj := Z.is_topological_fiber_bundle.continuous_proj /-- The projection on the base of a topological bundle created from core is an open map -/ lemma is_open_map_proj : is_open_map Z.proj := Z.is_topological_fiber_bundle.is_open_map_proj /-- Preferred local trivialization of a fiber bundle constructed from core, at a given point, as a bundle trivialization -/ def local_triv_at (b : B) : trivialization F Z.proj := Z.local_triv (Z.index_at b) @[simp, mfld_simps] lemma local_triv_at_def (b : B) : Z.local_triv (Z.index_at b) = Z.local_triv_at b := rfl /-- If an element of `F` is invariant under all coordinate changes, then one can define a corresponding section of the fiber bundle, which is continuous. This applies in particular to the zero section of a vector bundle. Another example (not yet defined) would be the identity section of the endomorphism bundle of a vector bundle. -/ lemma continuous_const_section (v : F) (h : ∀ i j, ∀ x ∈ (Z.base_set i) ∩ (Z.base_set j), Z.coord_change i j x v = v) : continuous (show B → Z.total_space, from λ x, ⟨x, v⟩) := begin apply continuous_iff_continuous_at.2 (λ x, _), have A : Z.base_set (Z.index_at x) ∈ 𝓝 x := is_open.mem_nhds (Z.is_open_base_set (Z.index_at x)) (Z.mem_base_set_at x), apply ((Z.local_triv_at x).to_local_homeomorph.continuous_at_iff_continuous_at_comp_left _).2, { simp only [(∘)] with mfld_simps, apply continuous_at_id.prod, have : continuous_on (λ (y : B), v) (Z.base_set (Z.index_at x)) := continuous_on_const, apply (this.congr _).continuous_at A, assume y hy, simp only [h, hy, mem_base_set_at] with mfld_simps }, { exact A } end @[simp, mfld_simps] lemma local_triv_as_local_equiv_coe : ⇑(Z.local_triv_as_local_equiv i) = Z.local_triv i := rfl @[simp, mfld_simps] lemma local_triv_as_local_equiv_source : (Z.local_triv_as_local_equiv i).source = (Z.local_triv i).source := rfl @[simp, mfld_simps] lemma local_triv_as_local_equiv_target : (Z.local_triv_as_local_equiv i).target = (Z.local_triv i).target := rfl @[simp, mfld_simps] lemma local_triv_as_local_equiv_symm : (Z.local_triv_as_local_equiv i).symm = (Z.local_triv i).to_local_equiv.symm := rfl @[simp, mfld_simps] lemma base_set_at : Z.base_set i = (Z.local_triv i).base_set := rfl @[simp, mfld_simps] lemma local_triv_apply (p : Z.total_space) : (Z.local_triv i) p = ⟨p.1, Z.coord_change (Z.index_at p.1) i p.1 p.2⟩ := rfl @[simp, mfld_simps] lemma mem_local_triv_source (p : Z.total_space) : p ∈ (Z.local_triv i).source ↔ p.1 ∈ (Z.local_triv i).base_set := iff.rfl @[simp, mfld_simps] lemma mem_local_triv_target (p : B × F) : p ∈ (Z.local_triv i).target ↔ p.1 ∈ (Z.local_triv i).base_set := trivialization.mem_target _ @[simp, mfld_simps] lemma local_triv_symm_fst (p : B × F) : (Z.local_triv i).to_local_homeomorph.symm p = ⟨p.1, Z.coord_change i (Z.index_at p.1) p.1 p.2⟩ := rfl @[simp, mfld_simps] lemma local_triv_at_apply (b : B) (a : F) : ((Z.local_triv_at b) ⟨b, a⟩) = ⟨b, a⟩ := by { rw [local_triv_at, local_triv_apply, coord_change_self], exact Z.mem_base_set_at b } @[simp, mfld_simps] lemma mem_local_triv_at_base_set (b : B) : b ∈ (Z.local_triv_at b).base_set := by { rw [local_triv_at, ←base_set_at], exact Z.mem_base_set_at b, } open bundle /-- The inclusion of a fiber into the total space is a continuous map. -/ lemma continuous_total_space_mk (b : B) : continuous (λ a, total_space_mk Z.fiber b a) := begin rw [continuous_iff_le_induced, topological_fiber_bundle_core.to_topological_space], apply le_induced_generate_from, simp only [total_space_mk, mem_Union, mem_singleton_iff, local_triv_as_local_equiv_source, local_triv_as_local_equiv_coe], rintros s ⟨i, t, ht, rfl⟩, rw [←((Z.local_triv i).source_inter_preimage_target_inter t), preimage_inter, ←preimage_comp, trivialization.source_eq], apply is_open.inter, { simp only [bundle.proj, proj, ←preimage_comp], by_cases (b ∈ (Z.local_triv i).base_set), { rw preimage_const_of_mem h, exact is_open_univ, }, { rw preimage_const_of_not_mem h, exact is_open_empty, }}, { simp only [function.comp, local_triv_apply], rw [preimage_inter, preimage_comp], by_cases (b ∈ Z.base_set i), { have hc : continuous (λ (x : Z.fiber b), (Z.coord_change (Z.index_at b) i b) x) := begin rw continuous_iff_continuous_on_univ, refine ((Z.coord_change_continuous (Z.index_at b) i).comp ((continuous_const).prod_mk continuous_id).continuous_on) (by { convert (subset_univ univ), exact mk_preimage_prod_right (mem_inter (Z.mem_base_set_at b) h), }) end, exact hc.is_open_preimage _ ((continuous.prod.mk b).is_open_preimage _ ((Z.local_triv i).open_target.inter ht)), }, { rw [(Z.local_triv i).target_eq, ←base_set_at, mk_preimage_prod_right_eq_empty h, preimage_empty, empty_inter], exact is_open_empty, }} end end topological_fiber_bundle_core variables (F) {Z : Type*} [topological_space B] [topological_space F] {proj : Z → B} open topological_fiber_bundle /-- This structure permits to define a fiber bundle when trivializations are given as local equivalences but there is not yet a topology on the total space. The total space is hence given a topology in such a way that there is a fiber bundle structure for which the local equivalences are also local homeomorphism and hence local trivializations. -/ @[nolint has_inhabited_instance] structure topological_fiber_prebundle (proj : Z → B) := (pretrivialization_at : B → pretrivialization F proj) (mem_base_pretrivialization_at : ∀ x : B, x ∈ (pretrivialization_at x).base_set) (continuous_triv_change : ∀ x y : B, continuous_on ((pretrivialization_at x) ∘ (pretrivialization_at y).to_local_equiv.symm) ((pretrivialization_at y).target ∩ ((pretrivialization_at y).to_local_equiv.symm ⁻¹' (pretrivialization_at x).source))) namespace topological_fiber_prebundle variables {F} (a : topological_fiber_prebundle F proj) (x : B) /-- Topology on the total space that will make the prebundle into a bundle. -/ def total_space_topology (a : topological_fiber_prebundle F proj) : topological_space Z := ⨆ x : B, coinduced (a.pretrivialization_at x).set_symm (subtype.topological_space) lemma continuous_symm_pretrivialization_at : @continuous_on _ _ _ a.total_space_topology (a.pretrivialization_at x).to_local_equiv.symm (a.pretrivialization_at x).target := begin refine id (λ z H, id (λ U h, preimage_nhds_within_coinduced' H (a.pretrivialization_at x).open_target (le_def.1 (nhds_mono _) U h))), exact le_supr _ x, end lemma is_open_source_pretrivialization_at : @is_open _ a.total_space_topology (a.pretrivialization_at x).source := begin letI := a.total_space_topology, refine is_open_supr_iff.mpr (λ y, is_open_coinduced.mpr (is_open_induced_iff.mpr ⟨(a.pretrivialization_at x).target, (a.pretrivialization_at x).open_target, _⟩)), rw [pretrivialization.set_symm, restrict, (a.pretrivialization_at x).target_eq, (a.pretrivialization_at x).source_eq, preimage_comp, subtype.preimage_coe_eq_preimage_coe_iff, (a.pretrivialization_at y).target_eq, prod_inter_prod, inter_univ, pretrivialization.preimage_symm_proj_inter], end lemma is_open_target_pretrivialization_at_inter (x y : B) : is_open ((a.pretrivialization_at y).to_local_equiv.target ∩ (a.pretrivialization_at y).to_local_equiv.symm ⁻¹' (a.pretrivialization_at x).source) := begin letI := a.total_space_topology, obtain ⟨u, hu1, hu2⟩ := continuous_on_iff'.mp (a.continuous_symm_pretrivialization_at y) (a.pretrivialization_at x).source (a.is_open_source_pretrivialization_at x), rw [inter_comm, hu2], exact hu1.inter (a.pretrivialization_at y).open_target, end /-- Promotion from a `pretrivialization` to a `trivialization`. -/ def trivialization_at (a : topological_fiber_prebundle F proj) (x : B) : @trivialization B F Z _ _ a.total_space_topology proj := { open_source := a.is_open_source_pretrivialization_at x, continuous_to_fun := begin letI := a.total_space_topology, refine continuous_on_iff'.mpr (λ s hs, ⟨(a.pretrivialization_at x) ⁻¹' s ∩ (a.pretrivialization_at x).source, (is_open_supr_iff.mpr (λ y, _)), by { rw [inter_assoc, inter_self], refl }⟩), rw [is_open_coinduced, is_open_induced_iff], obtain ⟨u, hu1, hu2⟩ := continuous_on_iff'.mp (a.continuous_triv_change x y) s hs, have hu3 := congr_arg (λ s, (λ x : (a.pretrivialization_at y).target, (x : B × F)) ⁻¹' s) hu2, simp only [subtype.coe_preimage_self, preimage_inter, univ_inter] at hu3, refine ⟨u ∩ (a.pretrivialization_at y).to_local_equiv.target ∩ ((a.pretrivialization_at y).to_local_equiv.symm ⁻¹' (a.pretrivialization_at x).source), _, by { simp only [preimage_inter, inter_univ, subtype.coe_preimage_self, hu3.symm], refl }⟩, rw inter_assoc, exact hu1.inter (a.is_open_target_pretrivialization_at_inter x y), end, continuous_inv_fun := a.continuous_symm_pretrivialization_at x, ..(a.pretrivialization_at x) } lemma is_topological_fiber_bundle : @is_topological_fiber_bundle B F Z _ _ a.total_space_topology proj := λ x, ⟨a.trivialization_at x, a.mem_base_pretrivialization_at x ⟩ lemma continuous_proj : @continuous _ _ a.total_space_topology _ proj := by { letI := a.total_space_topology, exact a.is_topological_fiber_bundle.continuous_proj, } end topological_fiber_prebundle
9d7acd07f6ce6d25cebd1ee2cb30c22477ac6b08
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/src/analysis/inner_product_space/calculus.lean
2af8f6f4df23179b12520ed588146356e7253d3e
[ "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
11,404
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.inner_product_space.basic import analysis.special_functions.sqrt /-! # Derivative of the inner product In this file we prove that the inner product and square of the norm in an inner space are infinitely `ℝ`-smooth. In order to state these results, we need a `normed_space ℝ E` instance. Though we can deduce this structure from `inner_product_space 𝕜 E`, this instance may be not definitionally equal to some other “natural” instance. So, we assume `[normed_space ℝ E]` and `[is_scalar_tower ℝ 𝕜 E]`. In both interesting cases `𝕜 = ℝ` and `𝕜 = ℂ` we have these instances. -/ noncomputable theory open is_R_or_C real filter open_locale big_operators classical topological_space variables {𝕜 E F : Type*} [is_R_or_C 𝕜] variables [inner_product_space 𝕜 E] [inner_product_space ℝ F] local notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ x y variables [normed_space ℝ E] [is_scalar_tower ℝ 𝕜 E] /-- Derivative of the inner product. -/ def fderiv_inner_clm (p : E × E) : E × E →L[ℝ] 𝕜 := is_bounded_bilinear_map_inner.deriv p @[simp] lemma fderiv_inner_clm_apply (p x : E × E) : fderiv_inner_clm p x = ⟪p.1, x.2⟫ + ⟪x.1, p.2⟫ := rfl lemma times_cont_diff_inner {n} : times_cont_diff ℝ n (λ p : E × E, ⟪p.1, p.2⟫) := is_bounded_bilinear_map_inner.times_cont_diff lemma times_cont_diff_at_inner {p : E × E} {n} : times_cont_diff_at ℝ n (λ p : E × E, ⟪p.1, p.2⟫) p := times_cont_diff_inner.times_cont_diff_at lemma differentiable_inner : differentiable ℝ (λ p : E × E, ⟪p.1, p.2⟫) := is_bounded_bilinear_map_inner.differentiable_at variables {G : Type*} [normed_group G] [normed_space ℝ G] {f g : G → E} {f' g' : G →L[ℝ] E} {s : set G} {x : G} {n : with_top ℕ} include 𝕜 lemma times_cont_diff_within_at.inner (hf : times_cont_diff_within_at ℝ n f s x) (hg : times_cont_diff_within_at ℝ n g s x) : times_cont_diff_within_at ℝ n (λ x, ⟪f x, g x⟫) s x := times_cont_diff_at_inner.comp_times_cont_diff_within_at x (hf.prod hg) lemma times_cont_diff_at.inner (hf : times_cont_diff_at ℝ n f x) (hg : times_cont_diff_at ℝ n g x) : times_cont_diff_at ℝ n (λ x, ⟪f x, g x⟫) x := hf.inner hg lemma times_cont_diff_on.inner (hf : times_cont_diff_on ℝ n f s) (hg : times_cont_diff_on ℝ n g s) : times_cont_diff_on ℝ n (λ x, ⟪f x, g x⟫) s := λ x hx, (hf x hx).inner (hg x hx) lemma times_cont_diff.inner (hf : times_cont_diff ℝ n f) (hg : times_cont_diff ℝ n g) : times_cont_diff ℝ n (λ x, ⟪f x, g x⟫) := times_cont_diff_inner.comp (hf.prod hg) lemma has_fderiv_within_at.inner (hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at g g' s x) : has_fderiv_within_at (λ t, ⟪f t, g t⟫) ((fderiv_inner_clm (f x, g x)).comp $ f'.prod g') s x := (is_bounded_bilinear_map_inner.has_fderiv_at (f x, g x)).comp_has_fderiv_within_at x (hf.prod hg) lemma has_strict_fderiv_at.inner (hf : has_strict_fderiv_at f f' x) (hg : has_strict_fderiv_at g g' x) : has_strict_fderiv_at (λ t, ⟪f t, g t⟫) ((fderiv_inner_clm (f x, g x)).comp $ f'.prod g') x := (is_bounded_bilinear_map_inner.has_strict_fderiv_at (f x, g x)).comp x (hf.prod hg) lemma has_fderiv_at.inner (hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x) : has_fderiv_at (λ t, ⟪f t, g t⟫) ((fderiv_inner_clm (f x, g x)).comp $ f'.prod g') x := (is_bounded_bilinear_map_inner.has_fderiv_at (f x, g x)).comp x (hf.prod hg) lemma has_deriv_within_at.inner {f g : ℝ → E} {f' g' : E} {s : set ℝ} {x : ℝ} (hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) : has_deriv_within_at (λ t, ⟪f t, g t⟫) (⟪f x, g'⟫ + ⟪f', g x⟫) s x := by simpa using (hf.has_fderiv_within_at.inner hg.has_fderiv_within_at).has_deriv_within_at lemma has_deriv_at.inner {f g : ℝ → E} {f' g' : E} {x : ℝ} : has_deriv_at f f' x → has_deriv_at g g' x → has_deriv_at (λ t, ⟪f t, g t⟫) (⟪f x, g'⟫ + ⟪f', g x⟫) x := by simpa only [← has_deriv_within_at_univ] using has_deriv_within_at.inner lemma differentiable_within_at.inner (hf : differentiable_within_at ℝ f s x) (hg : differentiable_within_at ℝ g s x) : differentiable_within_at ℝ (λ x, ⟪f x, g x⟫) s x := ((differentiable_inner _).has_fderiv_at.comp_has_fderiv_within_at x (hf.prod hg).has_fderiv_within_at).differentiable_within_at lemma differentiable_at.inner (hf : differentiable_at ℝ f x) (hg : differentiable_at ℝ g x) : differentiable_at ℝ (λ x, ⟪f x, g x⟫) x := (differentiable_inner _).comp x (hf.prod hg) lemma differentiable_on.inner (hf : differentiable_on ℝ f s) (hg : differentiable_on ℝ g s) : differentiable_on ℝ (λ x, ⟪f x, g x⟫) s := λ x hx, (hf x hx).inner (hg x hx) lemma differentiable.inner (hf : differentiable ℝ f) (hg : differentiable ℝ g) : differentiable ℝ (λ x, ⟪f x, g x⟫) := λ x, (hf x).inner (hg x) lemma fderiv_inner_apply (hf : differentiable_at ℝ f x) (hg : differentiable_at ℝ g x) (y : G) : fderiv ℝ (λ t, ⟪f t, g t⟫) x y = ⟪f x, fderiv ℝ g x y⟫ + ⟪fderiv ℝ f x y, g x⟫ := by { rw [(hf.has_fderiv_at.inner hg.has_fderiv_at).fderiv], refl } lemma deriv_inner_apply {f g : ℝ → E} {x : ℝ} (hf : differentiable_at ℝ f x) (hg : differentiable_at ℝ g x) : deriv (λ t, ⟪f t, g t⟫) x = ⟪f x, deriv g x⟫ + ⟪deriv f x, g x⟫ := (hf.has_deriv_at.inner hg.has_deriv_at).deriv lemma times_cont_diff_norm_sq : times_cont_diff ℝ n (λ x : E, ∥x∥ ^ 2) := begin simp only [sq, ← inner_self_eq_norm_mul_norm], exact (re_clm : 𝕜 →L[ℝ] ℝ).times_cont_diff.comp (times_cont_diff_id.inner times_cont_diff_id) end lemma times_cont_diff.norm_sq (hf : times_cont_diff ℝ n f) : times_cont_diff ℝ n (λ x, ∥f x∥ ^ 2) := times_cont_diff_norm_sq.comp hf lemma times_cont_diff_within_at.norm_sq (hf : times_cont_diff_within_at ℝ n f s x) : times_cont_diff_within_at ℝ n (λ y, ∥f y∥ ^ 2) s x := times_cont_diff_norm_sq.times_cont_diff_at.comp_times_cont_diff_within_at x hf lemma times_cont_diff_at.norm_sq (hf : times_cont_diff_at ℝ n f x) : times_cont_diff_at ℝ n (λ y, ∥f y∥ ^ 2) x := hf.norm_sq lemma times_cont_diff_at_norm {x : E} (hx : x ≠ 0) : times_cont_diff_at ℝ n norm x := have ∥id x∥ ^ 2 ≠ 0, from pow_ne_zero _ (norm_pos_iff.2 hx).ne', by simpa only [id, sqrt_sq, norm_nonneg] using times_cont_diff_at_id.norm_sq.sqrt this lemma times_cont_diff_at.norm (hf : times_cont_diff_at ℝ n f x) (h0 : f x ≠ 0) : times_cont_diff_at ℝ n (λ y, ∥f y∥) x := (times_cont_diff_at_norm h0).comp x hf lemma times_cont_diff_at.dist (hf : times_cont_diff_at ℝ n f x) (hg : times_cont_diff_at ℝ n g x) (hne : f x ≠ g x) : times_cont_diff_at ℝ n (λ y, dist (f y) (g y)) x := by { simp only [dist_eq_norm], exact (hf.sub hg).norm (sub_ne_zero.2 hne) } lemma times_cont_diff_within_at.norm (hf : times_cont_diff_within_at ℝ n f s x) (h0 : f x ≠ 0) : times_cont_diff_within_at ℝ n (λ y, ∥f y∥) s x := (times_cont_diff_at_norm h0).comp_times_cont_diff_within_at x hf lemma times_cont_diff_within_at.dist (hf : times_cont_diff_within_at ℝ n f s x) (hg : times_cont_diff_within_at ℝ n g s x) (hne : f x ≠ g x) : times_cont_diff_within_at ℝ n (λ y, dist (f y) (g y)) s x := by { simp only [dist_eq_norm], exact (hf.sub hg).norm (sub_ne_zero.2 hne) } lemma times_cont_diff_on.norm_sq (hf : times_cont_diff_on ℝ n f s) : times_cont_diff_on ℝ n (λ y, ∥f y∥ ^ 2) s := (λ x hx, (hf x hx).norm_sq) lemma times_cont_diff_on.norm (hf : times_cont_diff_on ℝ n f s) (h0 : ∀ x ∈ s, f x ≠ 0) : times_cont_diff_on ℝ n (λ y, ∥f y∥) s := λ x hx, (hf x hx).norm (h0 x hx) lemma times_cont_diff_on.dist (hf : times_cont_diff_on ℝ n f s) (hg : times_cont_diff_on ℝ n g s) (hne : ∀ x ∈ s, f x ≠ g x) : times_cont_diff_on ℝ n (λ y, dist (f y) (g y)) s := λ x hx, (hf x hx).dist (hg x hx) (hne x hx) lemma times_cont_diff.norm (hf : times_cont_diff ℝ n f) (h0 : ∀ x, f x ≠ 0) : times_cont_diff ℝ n (λ y, ∥f y∥) := times_cont_diff_iff_times_cont_diff_at.2 $ λ x, hf.times_cont_diff_at.norm (h0 x) lemma times_cont_diff.dist (hf : times_cont_diff ℝ n f) (hg : times_cont_diff ℝ n g) (hne : ∀ x, f x ≠ g x) : times_cont_diff ℝ n (λ y, dist (f y) (g y)) := times_cont_diff_iff_times_cont_diff_at.2 $ λ x, hf.times_cont_diff_at.dist hg.times_cont_diff_at (hne x) omit 𝕜 lemma has_strict_fderiv_at_norm_sq (x : F) : has_strict_fderiv_at (λ x, ∥x∥ ^ 2) (bit0 (inner_right x)) x := begin simp only [sq, ← inner_self_eq_norm_mul_norm], convert (has_strict_fderiv_at_id x).inner (has_strict_fderiv_at_id x), ext y, simp [bit0, real_inner_comm], end include 𝕜 lemma differentiable_at.norm_sq (hf : differentiable_at ℝ f x) : differentiable_at ℝ (λ y, ∥f y∥ ^ 2) x := (times_cont_diff_at_id.norm_sq.differentiable_at le_rfl).comp x hf lemma differentiable_at.norm (hf : differentiable_at ℝ f x) (h0 : f x ≠ 0) : differentiable_at ℝ (λ y, ∥f y∥) x := ((times_cont_diff_at_norm h0).differentiable_at le_rfl).comp x hf lemma differentiable_at.dist (hf : differentiable_at ℝ f x) (hg : differentiable_at ℝ g x) (hne : f x ≠ g x) : differentiable_at ℝ (λ y, dist (f y) (g y)) x := by { simp only [dist_eq_norm], exact (hf.sub hg).norm (sub_ne_zero.2 hne) } lemma differentiable.norm_sq (hf : differentiable ℝ f) : differentiable ℝ (λ y, ∥f y∥ ^ 2) := λ x, (hf x).norm_sq lemma differentiable.norm (hf : differentiable ℝ f) (h0 : ∀ x, f x ≠ 0) : differentiable ℝ (λ y, ∥f y∥) := λ x, (hf x).norm (h0 x) lemma differentiable.dist (hf : differentiable ℝ f) (hg : differentiable ℝ g) (hne : ∀ x, f x ≠ g x) : differentiable ℝ (λ y, dist (f y) (g y)) := λ x, (hf x).dist (hg x) (hne x) lemma differentiable_within_at.norm_sq (hf : differentiable_within_at ℝ f s x) : differentiable_within_at ℝ (λ y, ∥f y∥ ^ 2) s x := (times_cont_diff_at_id.norm_sq.differentiable_at le_rfl).comp_differentiable_within_at x hf lemma differentiable_within_at.norm (hf : differentiable_within_at ℝ f s x) (h0 : f x ≠ 0) : differentiable_within_at ℝ (λ y, ∥f y∥) s x := ((times_cont_diff_at_id.norm h0).differentiable_at le_rfl).comp_differentiable_within_at x hf lemma differentiable_within_at.dist (hf : differentiable_within_at ℝ f s x) (hg : differentiable_within_at ℝ g s x) (hne : f x ≠ g x) : differentiable_within_at ℝ (λ y, dist (f y) (g y)) s x := by { simp only [dist_eq_norm], exact (hf.sub hg).norm (sub_ne_zero.2 hne) } lemma differentiable_on.norm_sq (hf : differentiable_on ℝ f s) : differentiable_on ℝ (λ y, ∥f y∥ ^ 2) s := λ x hx, (hf x hx).norm_sq lemma differentiable_on.norm (hf : differentiable_on ℝ f s) (h0 : ∀ x ∈ s, f x ≠ 0) : differentiable_on ℝ (λ y, ∥f y∥) s := λ x hx, (hf x hx).norm (h0 x hx) lemma differentiable_on.dist (hf : differentiable_on ℝ f s) (hg : differentiable_on ℝ g s) (hne : ∀ x ∈ s, f x ≠ g x) : differentiable_on ℝ (λ y, dist (f y) (g y)) s := λ x hx, (hf x hx).dist (hg x hx) (hne x hx)
53a4c135335fd9ceaf2c0b6e4015e2dc25c9fccd
690889011852559ee5ac4dfea77092de8c832e7e
/src/analysis/calculus/deriv.lean
96940cc0db793ad37f80fe9a87d82836d2cef972
[ "Apache-2.0" ]
permissive
williamdemeo/mathlib
f6df180148f8acc91de9ba5e558976ab40a872c7
1fa03c29f9f273203bbffb79d10d31f696b3d317
refs/heads/master
1,584,785,260,929
1,572,195,914,000
1,572,195,913,000
138,435,193
0
0
Apache-2.0
1,529,789,739,000
1,529,789,739,000
null
UTF-8
Lean
false
false
52,597
lean
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Sébastien Gouëzel The Fréchet derivative. Let `E` and `F` be normed spaces, `f : E → F`, and `f' : E →L[𝕜] F` a continuous 𝕜-linear map, where `𝕜` is a non-discrete normed field. Then `has_fderiv_within_at f f' s x` says that `f` has derivative `f'` at `x`, where the domain of interest is restricted to `s`. We also have `has_fderiv_at f f' x := has_fderiv_within_at f f' x univ` The derivative is defined in terms of the `is_o` relation, but also characterized in terms of the `tendsto` relation. We also introduce predicates `differentiable_within_at 𝕜 f s x` (where `𝕜` is the base field, `f` the function to be differentiated, `x` the point at which the derivative is asserted to exist, and `s` the set along which the derivative is defined), as well as `differentiable_at 𝕜 f x`, `differentiable_on 𝕜 f s` and `differentiable 𝕜 f` to express the existence of a derivative. To be able to compute with derivatives, we write `fderiv_within 𝕜 f s x` and `fderiv 𝕜 f x` for some choice of a derivative if it exists, and the zero function otherwise. This choice only behaves well along sets for which the derivative is unique, i.e., those for which the tangent directions span a dense subset of the whole space. The predicates `unique_diff_within_at s x` and `unique_diff_on s`, defined in `tangent_cone.lean` express this property. We prove that indeed they imply the uniqueness of the derivative. This is satisfied for open subsets, and in particular for `univ`. This uniqueness only holds when the field is non-discrete, which we request at the very beginning: otherwise, a derivative can be defined, but it has no interesting properties whatsoever. In addition to the definition and basic properties of the derivative, this file contains the usual formulas (and existence assertions) for the derivative of * constants * the identity * bounded linear maps * bounded bilinear maps * sum of two functions * multiplication of a function by a scalar constant * negative of a function * subtraction of two functions * multiplication of a function by a scalar function * multiplication of two scalar functions * composition of functions (the chain rule) -/ import analysis.asymptotics analysis.calculus.tangent_cone open filter asymptotics continuous_linear_map set noncomputable theory local attribute [instance, priority 10] classical.decidable_inhabited classical.prop_decidable set_option class.instance_max_depth 90 section variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜] variables {E : Type*} [normed_group E] [normed_space 𝕜 E] variables {F : Type*} [normed_group F] [normed_space 𝕜 F] variables {G : Type*} [normed_group G] [normed_space 𝕜 G] def has_fderiv_at_filter (f : E → F) (f' : E →L[𝕜] F) (x : E) (L : filter E) := is_o (λ x', f x' - f x - f' (x' - x)) (λ x', x' - x) L def has_fderiv_within_at (f : E → F) (f' : E →L[𝕜] F) (s : set E) (x : E) := has_fderiv_at_filter f f' x (nhds_within x s) def has_fderiv_at (f : E → F) (f' : E →L[𝕜] F) (x : E) := has_fderiv_at_filter f f' x (nhds x) variables (𝕜) def differentiable_within_at (f : E → F) (s : set E) (x : E) := ∃f' : E →L[𝕜] F, has_fderiv_within_at f f' s x def differentiable_at (f : E → F) (x : E) := ∃f' : E →L[𝕜] F, has_fderiv_at f f' x def fderiv_within (f : E → F) (s : set E) (x : E) : E →L[𝕜] F := if h : ∃f', has_fderiv_within_at f f' s x then classical.some h else 0 def fderiv (f : E → F) (x : E) : E →L[𝕜] F := if h : ∃f', has_fderiv_at f f' x then classical.some h else 0 def differentiable_on (f : E → F) (s : set E) := ∀x ∈ s, differentiable_within_at 𝕜 f s x def differentiable (f : E → F) := ∀x, differentiable_at 𝕜 f x variables {𝕜} variables {f f₀ f₁ g : E → F} variables {f' f₀' f₁' g' : E →L[𝕜] F} variables {x : E} variables {s t : set E} variables {L L₁ L₂ : filter E} section derivative_uniqueness /- In this section, we discuss the uniqueness of the derivative. We prove that the definitions `unique_diff_within_at` and `unique_diff_on` indeed imply the uniqueness of the derivative. -/ /-- If a function f has a derivative f' at x, a rescaled version of f around x converges to f', i.e., `n (f (x + (1/n) v) - f x)` converges to `f' v`. More generally, if `c n` tends to infinity and `c n * d n` tends to `v`, then `c n * (f (x + d n) - f x)` tends to `f' v`. This lemma expresses this fact, for functions having a derivative within a set. Its specific formulation is useful for tangent cone related discussions. -/ theorem has_fderiv_within_at.lim (h : has_fderiv_within_at f f' s x) {c : ℕ → 𝕜} {d : ℕ → E} {v : E} (dtop : {n : ℕ | x + d n ∈ s} ∈ (at_top : filter ℕ)) (clim : tendsto (λ (n : ℕ), ∥c n∥) at_top at_top) (cdlim : tendsto (λ (n : ℕ), c n • d n) at_top (nhds v)) : tendsto (λn, c n • (f (x + d n) - f x)) at_top (nhds (f' v)) := begin have at_top_is_finer : at_top ≤ comap (λ (n : ℕ), x + d n) (nhds_within x s), { conv in (nhds_within x s) { rw ← add_zero x }, rw [← tendsto_iff_comap, nhds_within, tendsto_inf], split, { apply tendsto_add tendsto_const_nhds (tangent_cone_at.lim_zero clim cdlim) }, { rwa tendsto_principal } }, have : is_o (λ y, f y - f x - f' (y - x)) (λ y, y - x) (nhds_within x s) := h, have : is_o (λ n:ℕ, f (x + d n) - f x - f' ((x + d n) - x)) (λ n, (x + d n) - x) ((nhds_within x s).comap (λn, x+ d n)) := is_o.comp this _, have : is_o (λ n:ℕ, f (x + d n) - f x - f' (d n)) d ((nhds_within x s).comap (λn, x + d n)) := by simpa, have : is_o (λn:ℕ, f (x + d n) - f x - f' (d n)) d at_top := is_o.mono at_top_is_finer this, have : is_o (λn:ℕ, c n • (f (x + d n) - f x - f' (d n))) (λn, c n • d n) at_top := is_o_smul this, have : is_o (λn:ℕ, c n • (f (x + d n) - f x - f' (d n))) (λn, (1:ℝ)) at_top := this.trans_is_O (is_O_one_of_tendsto cdlim), have L1 : tendsto (λn:ℕ, c n • (f (x + d n) - f x - f' (d n))) at_top (nhds 0) := is_o_one_iff.1 this, have L2 : tendsto (λn:ℕ, f' (c n • d n)) at_top (nhds (f' v)) := tendsto.comp f'.cont.continuous_at cdlim, have L3 : tendsto (λn:ℕ, (c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n))) at_top (nhds (0 + f' v)) := tendsto_add L1 L2, have : (λn:ℕ, (c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n))) = (λn: ℕ, c n • (f (x + d n) - f x)), by { ext n, simp [smul_add] }, rwa [this, zero_add] at L3 end /-- `unique_diff_within_at` achieves its goal: it implies the uniqueness of the derivative. -/ theorem unique_diff_within_at.eq (H : unique_diff_within_at 𝕜 s x) (h : has_fderiv_within_at f f' s x) (h₁ : has_fderiv_within_at f f₁' s x) : f' = f₁' := begin have A : ∀y ∈ tangent_cone_at 𝕜 s x, f' y = f₁' y, { rintros y ⟨c, d, dtop, clim, cdlim⟩, exact tendsto_nhds_unique (by simp) (h.lim dtop clim cdlim) (h₁.lim dtop clim cdlim) }, have B : ∀y ∈ submodule.span 𝕜 (tangent_cone_at 𝕜 s x), f' y = f₁' y, { assume y hy, apply submodule.span_induction hy, { exact λy hy, A y hy }, { simp only [continuous_linear_map.map_zero] }, { simp {contextual := tt} }, { simp {contextual := tt} } }, have C : ∀y ∈ closure ((submodule.span 𝕜 (tangent_cone_at 𝕜 s x)) : set E), f' y = f₁' y, { assume y hy, let K := {y | f' y = f₁' y}, have : (submodule.span 𝕜 (tangent_cone_at 𝕜 s x) : set E) ⊆ K := B, have : closure (submodule.span 𝕜 (tangent_cone_at 𝕜 s x) : set E) ⊆ closure K := closure_mono this, have : y ∈ closure K := this hy, rwa closure_eq_of_is_closed (is_closed_eq f'.continuous f₁'.continuous) at this }, rw H.1 at C, ext y, exact C y (mem_univ _) end theorem unique_diff_on.eq (H : unique_diff_on 𝕜 s) (hx : x ∈ s) (h : has_fderiv_within_at f f' s x) (h₁ : has_fderiv_within_at f f₁' s x) : f' = f₁' := unique_diff_within_at.eq (H x hx) h h₁ end derivative_uniqueness /- Basic properties of the derivative -/ section fderiv_properties theorem has_fderiv_at_filter_iff_tendsto : has_fderiv_at_filter f f' x L ↔ tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) L (nhds 0) := have h : ∀ x', ∥x' - x∥ = 0 → ∥f x' - f x - f' (x' - x)∥ = 0, from λ x' hx', by { rw [sub_eq_zero.1 ((norm_eq_zero (x' - x)).1 hx')], simp }, begin unfold has_fderiv_at_filter, rw [←is_o_norm_left, ←is_o_norm_right, is_o_iff_tendsto h], exact tendsto.congr'r (λ _, div_eq_inv_mul), end theorem has_fderiv_within_at_iff_tendsto : has_fderiv_within_at f f' s x ↔ tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) (nhds_within x s) (nhds 0) := has_fderiv_at_filter_iff_tendsto theorem has_fderiv_at_iff_tendsto : has_fderiv_at f f' x ↔ tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) (nhds x) (nhds 0) := has_fderiv_at_filter_iff_tendsto theorem has_fderiv_at_filter.mono (h : has_fderiv_at_filter f f' x L₂) (hst : L₁ ≤ L₂) : has_fderiv_at_filter f f' x L₁ := is_o.mono hst h theorem has_fderiv_within_at.mono (h : has_fderiv_within_at f f' t x) (hst : s ⊆ t) : has_fderiv_within_at f f' s x := h.mono (nhds_within_mono _ hst) theorem has_fderiv_at.has_fderiv_at_filter (h : has_fderiv_at f f' x) (hL : L ≤ nhds x) : has_fderiv_at_filter f f' x L := h.mono hL theorem has_fderiv_at.has_fderiv_within_at (h : has_fderiv_at f f' x) : has_fderiv_within_at f f' s x := h.has_fderiv_at_filter lattice.inf_le_left lemma has_fderiv_within_at.differentiable_within_at (h : has_fderiv_within_at f f' s x) : differentiable_within_at 𝕜 f s x := ⟨f', h⟩ lemma has_fderiv_at.differentiable_at (h : has_fderiv_at f f' x) : differentiable_at 𝕜 f x := ⟨f', h⟩ @[simp] lemma has_fderiv_within_at_univ : has_fderiv_within_at f f' univ x ↔ has_fderiv_at f f' x := by { simp only [has_fderiv_within_at, nhds_within_univ], refl } theorem has_fderiv_at_unique (h₀ : has_fderiv_at f f₀' x) (h₁ : has_fderiv_at f f₁' x) : f₀' = f₁' := begin rw ← has_fderiv_within_at_univ at h₀ h₁, exact unique_diff_within_at_univ.eq h₀ h₁ end lemma has_fderiv_within_at_inter' (h : t ∈ nhds_within x s) : has_fderiv_within_at f f' (s ∩ t) x ↔ has_fderiv_within_at f f' s x := by simp [has_fderiv_within_at, nhds_within_restrict'' s h] lemma has_fderiv_within_at_inter (h : t ∈ nhds x) : has_fderiv_within_at f f' (s ∩ t) x ↔ has_fderiv_within_at f f' s x := by simp [has_fderiv_within_at, nhds_within_restrict' s h] lemma differentiable_within_at.has_fderiv_within_at (h : differentiable_within_at 𝕜 f s x) : has_fderiv_within_at f (fderiv_within 𝕜 f s x) s x := begin dunfold fderiv_within, dunfold differentiable_within_at at h, rw dif_pos h, exact classical.some_spec h end lemma differentiable_at.has_fderiv_at (h : differentiable_at 𝕜 f x) : has_fderiv_at f (fderiv 𝕜 f x) x := begin dunfold fderiv, dunfold differentiable_at at h, rw dif_pos h, exact classical.some_spec h end lemma has_fderiv_at.fderiv (h : has_fderiv_at f f' x) : fderiv 𝕜 f x = f' := by { ext, rw has_fderiv_at_unique h h.differentiable_at.has_fderiv_at } lemma has_fderiv_within_at.fderiv_within (h : has_fderiv_within_at f f' s x) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 f s x = f' := by { ext, rw hxs.eq h h.differentiable_within_at.has_fderiv_within_at } lemma differentiable_within_at.mono (h : differentiable_within_at 𝕜 f t x) (st : s ⊆ t) : differentiable_within_at 𝕜 f s x := begin rcases h with ⟨f', hf'⟩, exact ⟨f', hf'.mono st⟩ end lemma differentiable_within_at_univ : differentiable_within_at 𝕜 f univ x ↔ differentiable_at 𝕜 f x := begin simp [differentiable_within_at, has_fderiv_within_at, nhds_within_univ], refl end lemma differentiable_within_at_inter (ht : t ∈ nhds x) : differentiable_within_at 𝕜 f (s ∩ t) x ↔ differentiable_within_at 𝕜 f s x := by simp only [differentiable_within_at, has_fderiv_within_at, has_fderiv_at_filter, nhds_within_restrict' s ht] lemma differentiable_within_at_inter' (ht : t ∈ nhds_within x s) : differentiable_within_at 𝕜 f (s ∩ t) x ↔ differentiable_within_at 𝕜 f s x := by simp only [differentiable_within_at, has_fderiv_within_at, has_fderiv_at_filter, nhds_within_restrict'' s ht] lemma differentiable_at.differentiable_within_at (h : differentiable_at 𝕜 f x) : differentiable_within_at 𝕜 f s x := (differentiable_within_at_univ.2 h).mono (subset_univ _) lemma differentiable_within_at.differentiable_at (h : differentiable_within_at 𝕜 f s x) (hs : s ∈ nhds x) : differentiable_at 𝕜 f x := begin have : s = univ ∩ s, by rw univ_inter, rwa [this, differentiable_within_at_inter hs, differentiable_within_at_univ] at h end lemma differentiable.fderiv_within (h : differentiable_at 𝕜 f x) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 f s x = fderiv 𝕜 f x := begin apply has_fderiv_within_at.fderiv_within _ hxs, exact h.has_fderiv_at.has_fderiv_within_at end lemma differentiable_on.mono (h : differentiable_on 𝕜 f t) (st : s ⊆ t) : differentiable_on 𝕜 f s := λx hx, (h x (st hx)).mono st lemma differentiable_on_univ : differentiable_on 𝕜 f univ ↔ differentiable 𝕜 f := by { simp [differentiable_on, differentiable_within_at_univ], refl } lemma differentiable.differentiable_on (h : differentiable 𝕜 f) : differentiable_on 𝕜 f s := (differentiable_on_univ.2 h).mono (subset_univ _) lemma differentiable_on_of_locally_differentiable_on (h : ∀x∈s, ∃u, is_open u ∧ x ∈ u ∧ differentiable_on 𝕜 f (s ∩ u)) : differentiable_on 𝕜 f s := begin assume x xs, rcases h x xs with ⟨t, t_open, xt, ht⟩, exact (differentiable_within_at_inter (mem_nhds_sets t_open xt)).1 (ht x ⟨xs, xt⟩) end lemma fderiv_within_subset (st : s ⊆ t) (ht : unique_diff_within_at 𝕜 s x) (h : differentiable_within_at 𝕜 f t x) : fderiv_within 𝕜 f s x = fderiv_within 𝕜 f t x := ((differentiable_within_at.has_fderiv_within_at h).mono st).fderiv_within ht @[simp] lemma fderiv_within_univ : fderiv_within 𝕜 f univ = fderiv 𝕜 f := begin ext x : 1, by_cases h : differentiable_at 𝕜 f x, { apply has_fderiv_within_at.fderiv_within _ (is_open_univ.unique_diff_within_at (mem_univ _)), rw has_fderiv_within_at_univ, apply h.has_fderiv_at }, { have : fderiv 𝕜 f x = 0, by { unfold differentiable_at at h, simp [fderiv, h] }, rw this, have : ¬(differentiable_within_at 𝕜 f univ x), by rwa differentiable_within_at_univ, unfold differentiable_within_at at this, simp [fderiv_within, this, -has_fderiv_within_at_univ] } end lemma fderiv_within_inter (ht : t ∈ nhds x) (hs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 f (s ∩ t) x = fderiv_within 𝕜 f s x := begin by_cases h : differentiable_within_at 𝕜 f (s ∩ t) x, { apply fderiv_within_subset (inter_subset_left _ _) _ ((differentiable_within_at_inter ht).1 h), apply hs.inter ht }, { have : fderiv_within 𝕜 f (s ∩ t) x = 0, by { unfold differentiable_within_at at h, simp [fderiv_within, h] }, rw this, rw differentiable_within_at_inter ht at h, have : fderiv_within 𝕜 f s x = 0, by { unfold differentiable_within_at at h, simp [fderiv_within, h] }, rw this } end end fderiv_properties /- Congr -/ section congr theorem has_fderiv_at_filter_congr_of_mem_sets (hx : f₀ x = f₁ x) (h₀ : {x | f₀ x = f₁ x} ∈ L) (h₁ : ∀ x, f₀' x = f₁' x) : has_fderiv_at_filter f₀ f₀' x L ↔ has_fderiv_at_filter f₁ f₁' x L := by { rw (ext h₁), exact is_o_congr (by filter_upwards [h₀] λ x (h : _ = _), by simp [h, hx]) (univ_mem_sets' $ λ _, rfl) } lemma has_fderiv_at_filter.congr_of_mem_sets (h : has_fderiv_at_filter f f' x L) (hL : {x | f₁ x = f x} ∈ L) (hx : f₁ x = f x) : has_fderiv_at_filter f₁ f' x L := begin apply (has_fderiv_at_filter_congr_of_mem_sets hx hL _).2 h, exact λx, rfl end lemma has_fderiv_within_at.congr_mono (h : has_fderiv_within_at f f' s x) (ht : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (h₁ : t ⊆ s) : has_fderiv_within_at f₁ f' t x := has_fderiv_at_filter.congr_of_mem_sets (h.mono h₁) (filter.mem_inf_sets_of_right ht) hx lemma has_fderiv_within_at.congr_of_mem_nhds_within (h : has_fderiv_within_at f f' s x) (h₁ : {y | f₁ y = f y} ∈ nhds_within x s) (hx : f₁ x = f x) : has_fderiv_within_at f₁ f' s x := has_fderiv_at_filter.congr_of_mem_sets h h₁ hx lemma has_fderiv_at.congr_of_mem_nhds (h : has_fderiv_at f f' x) (h₁ : {y | f₁ y = f y} ∈ nhds x) : has_fderiv_at f₁ f' x := has_fderiv_at_filter.congr_of_mem_sets h h₁ (mem_of_nhds h₁ : _) lemma differentiable_within_at.congr_mono (h : differentiable_within_at 𝕜 f s x) (ht : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (h₁ : t ⊆ s) : differentiable_within_at 𝕜 f₁ t x := (has_fderiv_within_at.congr_mono h.has_fderiv_within_at ht hx h₁).differentiable_within_at lemma differentiable_within_at.congr (h : differentiable_within_at 𝕜 f s x) (ht : ∀x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : differentiable_within_at 𝕜 f₁ s x := differentiable_within_at.congr_mono h ht hx (subset.refl _) lemma differentiable_within_at.congr_of_mem_nhds_within (h : differentiable_within_at 𝕜 f s x) (h₁ : {y | f₁ y = f y} ∈ nhds_within x s) (hx : f₁ x = f x) : differentiable_within_at 𝕜 f₁ s x := (h.has_fderiv_within_at.congr_of_mem_nhds_within h₁ hx).differentiable_within_at lemma differentiable_on.congr_mono (h : differentiable_on 𝕜 f s) (h' : ∀x ∈ t, f₁ x = f x) (h₁ : t ⊆ s) : differentiable_on 𝕜 f₁ t := λ x hx, (h x (h₁ hx)).congr_mono h' (h' x hx) h₁ lemma differentiable_on.congr (h : differentiable_on 𝕜 f s) (h' : ∀x ∈ s, f₁ x = f x) : differentiable_on 𝕜 f₁ s := λ x hx, (h x hx).congr h' (h' x hx) lemma differentiable_at.congr_of_mem_nhds (h : differentiable_at 𝕜 f x) (hL : {y | f₁ y = f y} ∈ nhds x) : differentiable_at 𝕜 f₁ x := has_fderiv_at.differentiable_at (has_fderiv_at_filter.congr_of_mem_sets h.has_fderiv_at hL (mem_of_nhds hL : _)) lemma differentiable_within_at.fderiv_within_congr_mono (h : differentiable_within_at 𝕜 f s x) (hs : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (hxt : unique_diff_within_at 𝕜 t x) (h₁ : t ⊆ s) : fderiv_within 𝕜 f₁ t x = fderiv_within 𝕜 f s x := (has_fderiv_within_at.congr_mono h.has_fderiv_within_at hs hx h₁).fderiv_within hxt lemma fderiv_within_congr_of_mem_nhds_within (hs : unique_diff_within_at 𝕜 s x) (hL : {y | f₁ y = f y} ∈ nhds_within x s) (hx : f₁ x = f x) : fderiv_within 𝕜 f₁ s x = fderiv_within 𝕜 f s x := begin by_cases h : differentiable_within_at 𝕜 f s x ∨ differentiable_within_at 𝕜 f₁ s x, { cases h, { apply has_fderiv_within_at.fderiv_within _ hs, exact has_fderiv_at_filter.congr_of_mem_sets h.has_fderiv_within_at hL hx }, { symmetry, apply has_fderiv_within_at.fderiv_within _ hs, apply has_fderiv_at_filter.congr_of_mem_sets h.has_fderiv_within_at _ hx.symm, convert hL, ext y, exact eq_comm } }, { push_neg at h, have A : fderiv_within 𝕜 f s x = 0, by { unfold differentiable_within_at at h, simp [fderiv_within, h] }, have A₁ : fderiv_within 𝕜 f₁ s x = 0, by { unfold differentiable_within_at at h, simp [fderiv_within, h] }, rw [A, A₁] } end lemma fderiv_within_congr (hs : unique_diff_within_at 𝕜 s x) (hL : ∀y∈s, f₁ y = f y) (hx : f₁ x = f x) : fderiv_within 𝕜 f₁ s x = fderiv_within 𝕜 f s x := begin apply fderiv_within_congr_of_mem_nhds_within hs _ hx, apply mem_sets_of_superset self_mem_nhds_within, exact hL end lemma fderiv_congr_of_mem_nhds (hL : {y | f₁ y = f y} ∈ nhds x) : fderiv 𝕜 f₁ x = fderiv 𝕜 f x := begin have A : f₁ x = f x := (mem_of_nhds hL : _), rw [← fderiv_within_univ, ← fderiv_within_univ], rw ← nhds_within_univ at hL, exact fderiv_within_congr_of_mem_nhds_within unique_diff_within_at_univ hL A end end congr /- id -/ section id theorem has_fderiv_at_filter_id (x : E) (L : filter E) : has_fderiv_at_filter id (id : E →L[𝕜] E) x L := (is_o_zero _ _).congr_left $ by simp theorem has_fderiv_within_at_id (x : E) (s : set E) : has_fderiv_within_at id (id : E →L[𝕜] E) s x := has_fderiv_at_filter_id _ _ theorem has_fderiv_at_id (x : E) : has_fderiv_at id (id : E →L[𝕜] E) x := has_fderiv_at_filter_id _ _ lemma differentiable_at_id : differentiable_at 𝕜 id x := (has_fderiv_at_id x).differentiable_at lemma differentiable_within_at_id : differentiable_within_at 𝕜 id s x := differentiable_at_id.differentiable_within_at lemma differentiable_id : differentiable 𝕜 (id : E → E) := λx, differentiable_at_id lemma differentiable_on_id : differentiable_on 𝕜 id s := differentiable_id.differentiable_on lemma fderiv_id : fderiv 𝕜 id x = id := has_fderiv_at.fderiv (has_fderiv_at_id x) lemma fderiv_within_id (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 id s x = id := begin rw differentiable.fderiv_within (differentiable_at_id) hxs, exact fderiv_id end end id /- constants -/ section const theorem has_fderiv_at_filter_const (c : F) (x : E) (L : filter E) : has_fderiv_at_filter (λ x, c) (0 : E →L[𝕜] F) x L := (is_o_zero _ _).congr_left $ λ _, by simp only [zero_apply, sub_self] theorem has_fderiv_within_at_const (c : F) (x : E) (s : set E) : has_fderiv_within_at (λ x, c) (0 : E →L[𝕜] F) s x := has_fderiv_at_filter_const _ _ _ theorem has_fderiv_at_const (c : F) (x : E) : has_fderiv_at (λ x, c) (0 : E →L[𝕜] F) x := has_fderiv_at_filter_const _ _ _ lemma differentiable_at_const (c : F) : differentiable_at 𝕜 (λx, c) x := ⟨0, has_fderiv_at_const c x⟩ lemma differentiable_within_at_const (c : F) : differentiable_within_at 𝕜 (λx, c) s x := differentiable_at.differentiable_within_at (differentiable_at_const _) lemma fderiv_const (c : F) : fderiv 𝕜 (λy, c) x = 0 := has_fderiv_at.fderiv (has_fderiv_at_const c x) lemma fderiv_within_const (c : F) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (λy, c) s x = 0 := begin rw differentiable.fderiv_within (differentiable_at_const _) hxs, exact fderiv_const _ end lemma differentiable_const (c : F) : differentiable 𝕜 (λx : E, c) := λx, differentiable_at_const _ lemma differentiable_on_const (c : F) : differentiable_on 𝕜 (λx, c) s := (differentiable_const _).differentiable_on end const /- Bounded linear maps -/ section is_bounded_linear_map lemma is_bounded_linear_map.has_fderiv_at_filter (h : is_bounded_linear_map 𝕜 f) : has_fderiv_at_filter f h.to_continuous_linear_map x L := begin have : (λ (x' : E), f x' - f x - h.to_continuous_linear_map (x' - x)) = λx', 0, { ext, have : ∀a, h.to_continuous_linear_map a = f a := λa, rfl, simp, simp [this] }, rw [has_fderiv_at_filter, this], exact asymptotics.is_o_zero _ _ end lemma is_bounded_linear_map.has_fderiv_within_at (h : is_bounded_linear_map 𝕜 f) : has_fderiv_within_at f h.to_continuous_linear_map s x := h.has_fderiv_at_filter lemma is_bounded_linear_map.has_fderiv_at (h : is_bounded_linear_map 𝕜 f) : has_fderiv_at f h.to_continuous_linear_map x := h.has_fderiv_at_filter lemma is_bounded_linear_map.differentiable_at (h : is_bounded_linear_map 𝕜 f) : differentiable_at 𝕜 f x := h.has_fderiv_at.differentiable_at lemma is_bounded_linear_map.differentiable_within_at (h : is_bounded_linear_map 𝕜 f) : differentiable_within_at 𝕜 f s x := h.differentiable_at.differentiable_within_at lemma is_bounded_linear_map.fderiv (h : is_bounded_linear_map 𝕜 f) : fderiv 𝕜 f x = h.to_continuous_linear_map := has_fderiv_at.fderiv (h.has_fderiv_at) lemma is_bounded_linear_map.fderiv_within (h : is_bounded_linear_map 𝕜 f) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 f s x = h.to_continuous_linear_map := begin rw differentiable.fderiv_within h.differentiable_at hxs, exact h.fderiv end lemma is_bounded_linear_map.differentiable (h : is_bounded_linear_map 𝕜 f) : differentiable 𝕜 f := λx, h.differentiable_at lemma is_bounded_linear_map.differentiable_on (h : is_bounded_linear_map 𝕜 f) : differentiable_on 𝕜 f s := h.differentiable.differentiable_on end is_bounded_linear_map /- multiplication by a constant -/ section smul_const theorem has_fderiv_at_filter.smul (h : has_fderiv_at_filter f f' x L) (c : 𝕜) : has_fderiv_at_filter (λ x, c • f x) (c • f') x L := (is_o_const_smul_left h c).congr_left $ λ x, by simp [smul_neg, smul_add] theorem has_fderiv_within_at.smul (h : has_fderiv_within_at f f' s x) (c : 𝕜) : has_fderiv_within_at (λ x, c • f x) (c • f') s x := h.smul c theorem has_fderiv_at.smul (h : has_fderiv_at f f' x) (c : 𝕜) : has_fderiv_at (λ x, c • f x) (c • f') x := h.smul c lemma differentiable_within_at.smul (h : differentiable_within_at 𝕜 f s x) (c : 𝕜) : differentiable_within_at 𝕜 (λy, c • f y) s x := (h.has_fderiv_within_at.smul c).differentiable_within_at lemma differentiable_at.smul (h : differentiable_at 𝕜 f x) (c : 𝕜) : differentiable_at 𝕜 (λy, c • f y) x := (h.has_fderiv_at.smul c).differentiable_at lemma differentiable_on.smul (h : differentiable_on 𝕜 f s) (c : 𝕜) : differentiable_on 𝕜 (λy, c • f y) s := λx hx, (h x hx).smul c lemma differentiable.smul (h : differentiable 𝕜 f) (c : 𝕜) : differentiable 𝕜 (λy, c • f y) := λx, (h x).smul c lemma fderiv_within_smul (hxs : unique_diff_within_at 𝕜 s x) (h : differentiable_within_at 𝕜 f s x) (c : 𝕜) : fderiv_within 𝕜 (λy, c • f y) s x = c • fderiv_within 𝕜 f s x := (h.has_fderiv_within_at.smul c).fderiv_within hxs lemma fderiv_smul (h : differentiable_at 𝕜 f x) (c : 𝕜) : fderiv 𝕜 (λy, c • f y) x = c • fderiv 𝕜 f x := (h.has_fderiv_at.smul c).fderiv end smul_const /- add -/ section add theorem has_fderiv_at_filter.add (hf : has_fderiv_at_filter f f' x L) (hg : has_fderiv_at_filter g g' x L) : has_fderiv_at_filter (λ y, f y + g y) (f' + g') x L := (hf.add hg).congr_left $ λ _, by simp theorem has_fderiv_within_at.add (hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at g g' s x) : has_fderiv_within_at (λ y, f y + g y) (f' + g') s x := hf.add hg theorem has_fderiv_at.add (hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x) : has_fderiv_at (λ x, f x + g x) (f' + g') x := hf.add hg lemma differentiable_within_at.add (hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) : differentiable_within_at 𝕜 (λ y, f y + g y) s x := (hf.has_fderiv_within_at.add hg.has_fderiv_within_at).differentiable_within_at lemma differentiable_at.add (hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) : differentiable_at 𝕜 (λ y, f y + g y) x := (hf.has_fderiv_at.add hg.has_fderiv_at).differentiable_at lemma differentiable_on.add (hf : differentiable_on 𝕜 f s) (hg : differentiable_on 𝕜 g s) : differentiable_on 𝕜 (λy, f y + g y) s := λx hx, (hf x hx).add (hg x hx) lemma differentiable.add (hf : differentiable 𝕜 f) (hg : differentiable 𝕜 g) : differentiable 𝕜 (λy, f y + g y) := λx, (hf x).add (hg x) lemma fderiv_within_add (hxs : unique_diff_within_at 𝕜 s x) (hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) : fderiv_within 𝕜 (λy, f y + g y) s x = fderiv_within 𝕜 f s x + fderiv_within 𝕜 g s x := (hf.has_fderiv_within_at.add hg.has_fderiv_within_at).fderiv_within hxs lemma fderiv_add (hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) : fderiv 𝕜 (λy, f y + g y) x = fderiv 𝕜 f x + fderiv 𝕜 g x := (hf.has_fderiv_at.add hg.has_fderiv_at).fderiv end add /- neg -/ section neg theorem has_fderiv_at_filter.neg (h : has_fderiv_at_filter f f' x L) : has_fderiv_at_filter (λ x, -f x) (-f') x L := (h.smul (-1:𝕜)).congr (by simp) (by simp) theorem has_fderiv_within_at.neg (h : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, -f x) (-f') s x := h.neg theorem has_fderiv_at.neg (h : has_fderiv_at f f' x) : has_fderiv_at (λ x, -f x) (-f') x := h.neg lemma differentiable_within_at.neg (h : differentiable_within_at 𝕜 f s x) : differentiable_within_at 𝕜 (λy, -f y) s x := h.has_fderiv_within_at.neg.differentiable_within_at lemma differentiable_at.neg (h : differentiable_at 𝕜 f x) : differentiable_at 𝕜 (λy, -f y) x := h.has_fderiv_at.neg.differentiable_at lemma differentiable_on.neg (h : differentiable_on 𝕜 f s) : differentiable_on 𝕜 (λy, -f y) s := λx hx, (h x hx).neg lemma differentiable.neg (h : differentiable 𝕜 f) : differentiable 𝕜 (λy, -f y) := λx, (h x).neg lemma fderiv_within_neg (hxs : unique_diff_within_at 𝕜 s x) (h : differentiable_within_at 𝕜 f s x) : fderiv_within 𝕜 (λy, -f y) s x = - fderiv_within 𝕜 f s x := h.has_fderiv_within_at.neg.fderiv_within hxs lemma fderiv_neg (h : differentiable_at 𝕜 f x) : fderiv 𝕜 (λy, -f y) x = - fderiv 𝕜 f x := h.has_fderiv_at.neg.fderiv end neg /- sub -/ section sub theorem has_fderiv_at_filter.sub (hf : has_fderiv_at_filter f f' x L) (hg : has_fderiv_at_filter g g' x L) : has_fderiv_at_filter (λ x, f x - g x) (f' - g') x L := hf.add hg.neg theorem has_fderiv_within_at.sub (hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at g g' s x) : has_fderiv_within_at (λ x, f x - g x) (f' - g') s x := hf.sub hg theorem has_fderiv_at.sub (hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x) : has_fderiv_at (λ x, f x - g x) (f' - g') x := hf.sub hg lemma differentiable_within_at.sub (hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) : differentiable_within_at 𝕜 (λ y, f y - g y) s x := (hf.has_fderiv_within_at.sub hg.has_fderiv_within_at).differentiable_within_at lemma differentiable_at.sub (hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) : differentiable_at 𝕜 (λ y, f y - g y) x := (hf.has_fderiv_at.sub hg.has_fderiv_at).differentiable_at lemma differentiable_on.sub (hf : differentiable_on 𝕜 f s) (hg : differentiable_on 𝕜 g s) : differentiable_on 𝕜 (λy, f y - g y) s := λx hx, (hf x hx).sub (hg x hx) lemma differentiable.sub (hf : differentiable 𝕜 f) (hg : differentiable 𝕜 g) : differentiable 𝕜 (λy, f y - g y) := λx, (hf x).sub (hg x) lemma fderiv_within_sub (hxs : unique_diff_within_at 𝕜 s x) (hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) : fderiv_within 𝕜 (λy, f y - g y) s x = fderiv_within 𝕜 f s x - fderiv_within 𝕜 g s x := (hf.has_fderiv_within_at.sub hg.has_fderiv_within_at).fderiv_within hxs lemma fderiv_sub (hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) : fderiv 𝕜 (λy, f y - g y) x = fderiv 𝕜 f x - fderiv 𝕜 g x := (hf.has_fderiv_at.sub hg.has_fderiv_at).fderiv theorem has_fderiv_at_filter.is_O_sub (h : has_fderiv_at_filter f f' x L) : is_O (λ x', f x' - f x) (λ x', x' - x) L := h.to_is_O.congr_of_sub.2 (f'.is_O_sub _ _) end sub /- Continuity -/ section continuous theorem has_fderiv_at_filter.tendsto_nhds (hL : L ≤ nhds x) (h : has_fderiv_at_filter f f' x L) : tendsto f L (nhds (f x)) := begin have : tendsto (λ x', f x' - f x) L (nhds 0), { refine h.is_O_sub.trans_tendsto (tendsto_le_left hL _), rw ← sub_self x, exact tendsto_sub tendsto_id tendsto_const_nhds }, have := tendsto_add this tendsto_const_nhds, rw zero_add (f x) at this, exact this.congr (by simp) end theorem has_fderiv_within_at.continuous_within_at (h : has_fderiv_within_at f f' s x) : continuous_within_at f s x := has_fderiv_at_filter.tendsto_nhds lattice.inf_le_left h theorem has_fderiv_at.continuous_at (h : has_fderiv_at f f' x) : continuous_at f x := has_fderiv_at_filter.tendsto_nhds (le_refl _) h lemma differentiable_within_at.continuous_within_at (h : differentiable_within_at 𝕜 f s x) : continuous_within_at f s x := let ⟨f', hf'⟩ := h in hf'.continuous_within_at lemma differentiable_at.continuous_at (h : differentiable_at 𝕜 f x) : continuous_at f x := let ⟨f', hf'⟩ := h in hf'.continuous_at lemma differentiable_on.continuous_on (h : differentiable_on 𝕜 f s) : continuous_on f s := λx hx, (h x hx).continuous_within_at lemma differentiable.continuous (h : differentiable 𝕜 f) : continuous f := continuous_iff_continuous_at.2 $ λx, (h x).continuous_at end continuous /- Bounded bilinear maps -/ section bilinear_map variables {b : E × F → G} {u : set (E × F) } open normed_field lemma is_bounded_bilinear_map.has_fderiv_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) : has_fderiv_at b (h.deriv p) p := begin have : (λ (x : E × F), b x - b p - (h.deriv p) (x - p)) = (λx, b (x.1 - p.1, x.2 - p.2)), { ext x, delta is_bounded_bilinear_map.deriv, change b x - b p - (b (p.1, x.2-p.2) + b (x.1-p.1, p.2)) = b (x.1 - p.1, x.2 - p.2), have : b x = b (x.1, x.2), by { cases x, refl }, rw this, have : b p = b (p.1, p.2), by { cases p, refl }, rw this, simp only [h.map_sub_left, h.map_sub_right], abel }, rw [has_fderiv_at, has_fderiv_at_filter, this], rcases h.bound with ⟨C, Cpos, hC⟩, have A : asymptotics.is_O (λx : E × F, b (x.1 - p.1, x.2 - p.2)) (λx, ∥x - p∥ * ∥x - p∥) (nhds p) := ⟨C, Cpos, filter.univ_mem_sets' (λx, begin simp only [mem_set_of_eq, norm_mul, norm_norm], calc ∥b (x.1 - p.1, x.2 - p.2)∥ ≤ C * ∥x.1 - p.1∥ * ∥x.2 - p.2∥ : hC _ _ ... ≤ C * ∥x-p∥ * ∥x-p∥ : by apply_rules [mul_le_mul, le_max_left, le_max_right, norm_nonneg, le_of_lt Cpos, le_refl, mul_nonneg, norm_nonneg, norm_nonneg] ... = C * (∥x-p∥ * ∥x-p∥) : mul_assoc _ _ _ end)⟩, have B : asymptotics.is_o (λ (x : E × F), ∥x - p∥ * ∥x - p∥) (λx, 1 * ∥x - p∥) (nhds p), { apply asymptotics.is_o_mul_right _ (asymptotics.is_O_refl _ _), rw [asymptotics.is_o_iff_tendsto], { simp only [div_one], have : 0 = ∥p - p∥, by simp, rw this, have : continuous (λx, ∥x-p∥) := continuous_norm.comp (continuous_sub continuous_id continuous_const), exact this.tendsto p }, simp only [forall_prop_of_false, not_false_iff, one_ne_zero, forall_true_iff] }, simp only [one_mul, asymptotics.is_o_norm_right] at B, exact A.trans_is_o B end lemma is_bounded_bilinear_map.has_fderiv_within_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) : has_fderiv_within_at b (h.deriv p) u p := (h.has_fderiv_at p).has_fderiv_within_at lemma is_bounded_bilinear_map.differentiable_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) : differentiable_at 𝕜 b p := (h.has_fderiv_at p).differentiable_at lemma is_bounded_bilinear_map.differentiable_within_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) : differentiable_within_at 𝕜 b u p := (h.differentiable_at p).differentiable_within_at lemma is_bounded_bilinear_map.fderiv (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) : fderiv 𝕜 b p = h.deriv p := has_fderiv_at.fderiv (h.has_fderiv_at p) lemma is_bounded_bilinear_map.fderiv_within (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) (hxs : unique_diff_within_at 𝕜 u p) : fderiv_within 𝕜 b u p = h.deriv p := begin rw differentiable.fderiv_within (h.differentiable_at p) hxs, exact h.fderiv p end lemma is_bounded_bilinear_map.differentiable (h : is_bounded_bilinear_map 𝕜 b) : differentiable 𝕜 b := λx, h.differentiable_at x lemma is_bounded_bilinear_map.differentiable_on (h : is_bounded_bilinear_map 𝕜 b) : differentiable_on 𝕜 b u := h.differentiable.differentiable_on lemma is_bounded_bilinear_map.continuous (h : is_bounded_bilinear_map 𝕜 b) : continuous b := h.differentiable.continuous end bilinear_map /- Cartesian products -/ section cartesian_product variables {f₂ : E → G} {f₂' : E →L[𝕜] G} lemma has_fderiv_at_filter.prod (hf₁ : has_fderiv_at_filter f₁ f₁' x L) (hf₂ : has_fderiv_at_filter f₂ f₂' x L) : has_fderiv_at_filter (λx, (f₁ x, f₂ x)) (continuous_linear_map.prod f₁' f₂') x L := begin have : (λ (x' : E), (f₁ x', f₂ x') - (f₁ x, f₂ x) - (continuous_linear_map.prod f₁' f₂') (x' -x)) = (λ (x' : E), (f₁ x' - f₁ x - f₁' (x' - x), f₂ x' - f₂ x - f₂' (x' - x))) := rfl, rw [has_fderiv_at_filter, this], rw [asymptotics.is_o_prod_left], exact ⟨hf₁, hf₂⟩ end lemma has_fderiv_within_at.prod (hf₁ : has_fderiv_within_at f₁ f₁' s x) (hf₂ : has_fderiv_within_at f₂ f₂' s x) : has_fderiv_within_at (λx, (f₁ x, f₂ x)) (continuous_linear_map.prod f₁' f₂') s x := hf₁.prod hf₂ lemma has_fderiv_at.prod (hf₁ : has_fderiv_at f₁ f₁' x) (hf₂ : has_fderiv_at f₂ f₂' x) : has_fderiv_at (λx, (f₁ x, f₂ x)) (continuous_linear_map.prod f₁' f₂') x := hf₁.prod hf₂ lemma differentiable_within_at.prod (hf₁ : differentiable_within_at 𝕜 f₁ s x) (hf₂ : differentiable_within_at 𝕜 f₂ s x) : differentiable_within_at 𝕜 (λx:E, (f₁ x, f₂ x)) s x := (hf₁.has_fderiv_within_at.prod hf₂.has_fderiv_within_at).differentiable_within_at lemma differentiable_at.prod (hf₁ : differentiable_at 𝕜 f₁ x) (hf₂ : differentiable_at 𝕜 f₂ x) : differentiable_at 𝕜 (λx:E, (f₁ x, f₂ x)) x := (hf₁.has_fderiv_at.prod hf₂.has_fderiv_at).differentiable_at lemma differentiable_on.prod (hf₁ : differentiable_on 𝕜 f₁ s) (hf₂ : differentiable_on 𝕜 f₂ s) : differentiable_on 𝕜 (λx:E, (f₁ x, f₂ x)) s := λx hx, differentiable_within_at.prod (hf₁ x hx) (hf₂ x hx) lemma differentiable.prod (hf₁ : differentiable 𝕜 f₁) (hf₂ : differentiable 𝕜 f₂) : differentiable 𝕜 (λx:E, (f₁ x, f₂ x)) := λ x, differentiable_at.prod (hf₁ x) (hf₂ x) lemma differentiable_at.fderiv_prod (hf₁ : differentiable_at 𝕜 f₁ x) (hf₂ : differentiable_at 𝕜 f₂ x) : fderiv 𝕜 (λx:E, (f₁ x, f₂ x)) x = continuous_linear_map.prod (fderiv 𝕜 f₁ x) (fderiv 𝕜 f₂ x) := has_fderiv_at.fderiv (has_fderiv_at.prod hf₁.has_fderiv_at hf₂.has_fderiv_at) lemma differentiable_at.fderiv_within_prod (hf₁ : differentiable_within_at 𝕜 f₁ s x) (hf₂ : differentiable_within_at 𝕜 f₂ s x) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (λx:E, (f₁ x, f₂ x)) s x = continuous_linear_map.prod (fderiv_within 𝕜 f₁ s x) (fderiv_within 𝕜 f₂ s x) := begin apply has_fderiv_within_at.fderiv_within _ hxs, exact has_fderiv_within_at.prod hf₁.has_fderiv_within_at hf₂.has_fderiv_within_at end end cartesian_product /- Composition -/ section composition /- For composition lemmas, we put x explicit to help the elaborator, as otherwise Lean tends to get confused since there are too many possibilities for composition -/ variable (x) theorem has_fderiv_at_filter.comp {g : F → G} {g' : F →L[𝕜] G} (hg : has_fderiv_at_filter g g' (f x) (L.map f)) (hf : has_fderiv_at_filter f f' x L) : has_fderiv_at_filter (g ∘ f) (g'.comp f') x L := let eq₁ := (g'.is_O_comp _ _).trans_is_o hf in let eq₂ := ((hg.comp f).mono le_comap_map).trans_is_O hf.is_O_sub in by { refine eq₂.tri (eq₁.congr_left (λ x', _)), simp } /- A readable version of the previous theorem, a general form of the chain rule. -/ example {g : F → G} {g' : F →L[𝕜] G} (hg : has_fderiv_at_filter g g' (f x) (L.map f)) (hf : has_fderiv_at_filter f f' x L) : has_fderiv_at_filter (g ∘ f) (g'.comp f') x L := begin unfold has_fderiv_at_filter at hg, have : is_o (λ x', g (f x') - g (f x) - g' (f x' - f x)) (λ x', f x' - f x) L, from (hg.comp f).mono le_comap_map, have eq₁ : is_o (λ x', g (f x') - g (f x) - g' (f x' - f x)) (λ x', x' - x) L, from this.trans_is_O hf.is_O_sub, have eq₂ : is_o (λ x', f x' - f x - f' (x' - x)) (λ x', x' - x) L, from hf, have : is_O (λ x', g' (f x' - f x - f' (x' - x))) (λ x', f x' - f x - f' (x' - x)) L, from g'.is_O_comp _ _, have : is_o (λ x', g' (f x' - f x - f' (x' - x))) (λ x', x' - x) L, from this.trans_is_o eq₂, have eq₃ : is_o (λ x', g' (f x' - f x) - (g' (f' (x' - x)))) (λ x', x' - x) L, by { refine this.congr_left _, simp}, exact eq₁.tri eq₃ end theorem has_fderiv_within_at.comp {g : F → G} {g' : F →L[𝕜] G} {t : set F} (hg : has_fderiv_within_at g g' t (f x)) (hf : has_fderiv_within_at f f' s x) (hst : s ⊆ f ⁻¹' t) : has_fderiv_within_at (g ∘ f) (g'.comp f') s x := begin apply has_fderiv_at_filter.comp _ (has_fderiv_at_filter.mono hg _) hf, calc map f (nhds_within x s) ≤ nhds_within (f x) (f '' s) : hf.continuous_within_at.tendsto_nhds_within_image ... ≤ nhds_within (f x) t : nhds_within_mono _ (image_subset_iff.mpr hst) end /-- The chain rule. -/ theorem has_fderiv_at.comp {g : F → G} {g' : F →L[𝕜] G} (hg : has_fderiv_at g g' (f x)) (hf : has_fderiv_at f f' x) : has_fderiv_at (g ∘ f) (g'.comp f') x := (hg.mono hf.continuous_at).comp x hf theorem has_fderiv_at.comp_has_fderiv_within_at {g : F → G} {g' : F →L[𝕜] G} (hg : has_fderiv_at g g' (f x)) (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (g ∘ f) (g'.comp f') s x := begin rw ← has_fderiv_within_at_univ at hg, exact has_fderiv_within_at.comp x hg hf subset_preimage_univ end lemma differentiable_within_at.comp {g : F → G} {t : set F} (hg : differentiable_within_at 𝕜 g t (f x)) (hf : differentiable_within_at 𝕜 f s x) (h : s ⊆ f ⁻¹' t) : differentiable_within_at 𝕜 (g ∘ f) s x := begin rcases hf with ⟨f', hf'⟩, rcases hg with ⟨g', hg'⟩, exact ⟨continuous_linear_map.comp g' f', hg'.comp x hf' h⟩ end lemma differentiable_at.comp {g : F → G} (hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_at 𝕜 f x) : differentiable_at 𝕜 (g ∘ f) x := (hg.has_fderiv_at.comp x hf.has_fderiv_at).differentiable_at lemma fderiv_within.comp {g : F → G} {t : set F} (hg : differentiable_within_at 𝕜 g t (f x)) (hf : differentiable_within_at 𝕜 f s x) (h : s ⊆ f ⁻¹' t) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (g ∘ f) s x = continuous_linear_map.comp (fderiv_within 𝕜 g t (f x)) (fderiv_within 𝕜 f s x) := begin apply has_fderiv_within_at.fderiv_within _ hxs, exact has_fderiv_within_at.comp x (hg.has_fderiv_within_at) (hf.has_fderiv_within_at) h end lemma fderiv.comp {g : F → G} (hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_at 𝕜 f x) : fderiv 𝕜 (g ∘ f) x = continuous_linear_map.comp (fderiv 𝕜 g (f x)) (fderiv 𝕜 f x) := begin apply has_fderiv_at.fderiv, exact has_fderiv_at.comp x hg.has_fderiv_at hf.has_fderiv_at end lemma differentiable_on.comp {g : F → G} {t : set F} (hg : differentiable_on 𝕜 g t) (hf : differentiable_on 𝕜 f s) (st : s ⊆ f ⁻¹' t) : differentiable_on 𝕜 (g ∘ f) s := λx hx, differentiable_within_at.comp x (hg (f x) (st hx)) (hf x hx) st lemma differentiable.comp {g : F → G} (hg : differentiable 𝕜 g) (hf : differentiable 𝕜 f) : differentiable 𝕜 (g ∘ f) := λx, differentiable_at.comp x (hg (f x)) (hf x) end composition /- Multiplication by a scalar function -/ section smul variables {c : E → 𝕜} {c' : E →L[𝕜] 𝕜} theorem has_fderiv_within_at.smul' (hc : has_fderiv_within_at c c' s x) (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ y, c y • f y) (c x • f' + c'.scalar_prod_space_iso (f x)) s x := begin have : is_bounded_bilinear_map 𝕜 (λ (p : 𝕜 × F), p.1 • p.2) := is_bounded_bilinear_map_smul, exact has_fderiv_at.comp_has_fderiv_within_at x (this.has_fderiv_at (c x, f x)) (hc.prod hf) end theorem has_fderiv_at.smul' (hc : has_fderiv_at c c' x) (hf : has_fderiv_at f f' x) : has_fderiv_at (λ y, c y • f y) (c x • f' + c'.scalar_prod_space_iso (f x)) x := begin have : is_bounded_bilinear_map 𝕜 (λ (p : 𝕜 × F), p.1 • p.2) := is_bounded_bilinear_map_smul, exact has_fderiv_at.comp x (this.has_fderiv_at (c x, f x)) (hc.prod hf) end lemma differentiable_within_at.smul' (hc : differentiable_within_at 𝕜 c s x) (hf : differentiable_within_at 𝕜 f s x) : differentiable_within_at 𝕜 (λ y, c y • f y) s x := (hc.has_fderiv_within_at.smul' hf.has_fderiv_within_at).differentiable_within_at lemma differentiable_at.smul' (hc : differentiable_at 𝕜 c x) (hf : differentiable_at 𝕜 f x) : differentiable_at 𝕜 (λ y, c y • f y) x := (hc.has_fderiv_at.smul' hf.has_fderiv_at).differentiable_at lemma differentiable_on.smul' (hc : differentiable_on 𝕜 c s) (hf : differentiable_on 𝕜 f s) : differentiable_on 𝕜 (λ y, c y • f y) s := λx hx, (hc x hx).smul' (hf x hx) lemma differentiable.smul' (hc : differentiable 𝕜 c) (hf : differentiable 𝕜 f) : differentiable 𝕜 (λ y, c y • f y) := λx, (hc x).smul' (hf x) lemma fderiv_within_smul' (hxs : unique_diff_within_at 𝕜 s x) (hc : differentiable_within_at 𝕜 c s x) (hf : differentiable_within_at 𝕜 f s x) : fderiv_within 𝕜 (λ y, c y • f y) s x = c x • fderiv_within 𝕜 f s x + (fderiv_within 𝕜 c s x).scalar_prod_space_iso (f x) := (hc.has_fderiv_within_at.smul' hf.has_fderiv_within_at).fderiv_within hxs lemma fderiv_smul' (hc : differentiable_at 𝕜 c x) (hf : differentiable_at 𝕜 f x) : fderiv 𝕜 (λ y, c y • f y) x = c x • fderiv 𝕜 f x + (fderiv 𝕜 c x).scalar_prod_space_iso (f x) := (hc.has_fderiv_at.smul' hf.has_fderiv_at).fderiv end smul /- Multiplication of scalar functions -/ section mul set_option class.instance_max_depth 120 variables {c d : E → 𝕜} {c' d' : E →L[𝕜] 𝕜} theorem has_fderiv_within_at.mul (hc : has_fderiv_within_at c c' s x) (hd : has_fderiv_within_at d d' s x) : has_fderiv_within_at (λ y, c y * d y) (c x • d' + d x • c') s x := begin have : is_bounded_bilinear_map 𝕜 (λ (p : 𝕜 × 𝕜), p.1 * p.2) := is_bounded_bilinear_map_mul, convert has_fderiv_at.comp_has_fderiv_within_at x (this.has_fderiv_at (c x, d x)) (hc.prod hd), ext z, change c x * d' z + d x * c' z = c x * d' z + c' z * d x, ring end theorem has_fderiv_at.mul (hc : has_fderiv_at c c' x) (hd : has_fderiv_at d d' x) : has_fderiv_at (λ y, c y * d y) (c x • d' + d x • c') x := begin have : is_bounded_bilinear_map 𝕜 (λ (p : 𝕜 × 𝕜), p.1 * p.2) := is_bounded_bilinear_map_mul, convert has_fderiv_at.comp x (this.has_fderiv_at (c x, d x)) (hc.prod hd), ext z, change c x * d' z + d x * c' z = c x * d' z + c' z * d x, ring end lemma differentiable_within_at.mul (hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) : differentiable_within_at 𝕜 (λ y, c y * d y) s x := (hc.has_fderiv_within_at.mul hd.has_fderiv_within_at).differentiable_within_at lemma differentiable_at.mul (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) : differentiable_at 𝕜 (λ y, c y * d y) x := (hc.has_fderiv_at.mul hd.has_fderiv_at).differentiable_at lemma differentiable_on.mul (hc : differentiable_on 𝕜 c s) (hd : differentiable_on 𝕜 d s) : differentiable_on 𝕜 (λ y, c y * d y) s := λx hx, (hc x hx).mul (hd x hx) lemma differentiable.mul (hc : differentiable 𝕜 c) (hd : differentiable 𝕜 d) : differentiable 𝕜 (λ y, c y * d y) := λx, (hc x).mul (hd x) lemma fderiv_within_mul (hxs : unique_diff_within_at 𝕜 s x) (hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) : fderiv_within 𝕜 (λ y, c y * d y) s x = c x • fderiv_within 𝕜 d s x + d x • fderiv_within 𝕜 c s x := (hc.has_fderiv_within_at.mul hd.has_fderiv_within_at).fderiv_within hxs lemma fderiv_mul (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) : fderiv 𝕜 (λ y, c y * d y) x = c x • fderiv 𝕜 d x + d x • fderiv 𝕜 c x := (hc.has_fderiv_at.mul hd.has_fderiv_at).fderiv end mul end /- In the special case of a normed space over the reals, we can use scalar multiplication in the `tendsto` characterization of the Fréchet derivative. -/ section variables {E : Type*} [normed_group E] [normed_space ℝ E] variables {F : Type*} [normed_group F] [normed_space ℝ F] variables {G : Type*} [normed_group G] [normed_space ℝ G] theorem has_fderiv_at_filter_real_equiv {f : E → F} {f' : E →L[ℝ] F} {x : E} {L : filter E} : tendsto (λ x' : E, ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) L (nhds 0) ↔ tendsto (λ x' : E, ∥x' - x∥⁻¹ • (f x' - f x - f' (x' - x))) L (nhds 0) := begin symmetry, rw [tendsto_iff_norm_tendsto_zero], refine tendsto.congr'r (λ x', _), have : ∥x' + -x∥⁻¹ ≥ 0, from inv_nonneg.mpr (norm_nonneg _), simp [norm_smul, real.norm_eq_abs, abs_of_nonneg this] end end section tangent_cone variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜] {E : Type*} [normed_group E] [normed_space 𝕜 E] {F : Type*} [normed_group F] [normed_space 𝕜 F] {f : E → F} {s : set E} {f' : E →L[𝕜] F} /-- The image of a tangent cone under the differential of a map is included in the tangent cone to the image. -/ lemma has_fderiv_within_at.image_tangent_cone_subset {x : E} (h : has_fderiv_within_at f f' s x) : f' '' (tangent_cone_at 𝕜 s x) ⊆ tangent_cone_at 𝕜 (f '' s) (f x) := begin rw image_subset_iff, rintros v ⟨c, d, dtop, clim, cdlim⟩, refine ⟨c, (λn, f (x + d n) - f x), mem_sets_of_superset dtop _, clim, h.lim dtop clim cdlim⟩, simp [-mem_image, mem_image_of_mem] {contextual := tt} end /-- If a set has the unique differentiability property at a point x, then the image of this set under a map with onto derivative has also the unique differentiability property at the image point. -/ lemma has_fderiv_within_at.unique_diff_within_at {x : E} (h : has_fderiv_within_at f f' s x) (hs : unique_diff_within_at 𝕜 s x) (h' : closure (range f') = univ) : unique_diff_within_at 𝕜 (f '' s) (f x) := begin have A : ∀v ∈ tangent_cone_at 𝕜 s x, f' v ∈ tangent_cone_at 𝕜 (f '' s) (f x), { assume v hv, have := h.image_tangent_cone_subset, rw image_subset_iff at this, exact this hv }, have B : ∀v ∈ (submodule.span 𝕜 (tangent_cone_at 𝕜 s x) : set E), f' v ∈ (submodule.span 𝕜 (tangent_cone_at 𝕜 (f '' s) (f x)) : set F), { assume v hv, apply submodule.span_induction hv, { exact λ w hw, submodule.subset_span (A w hw) }, { simp }, { assume w₁ w₂ hw₁ hw₂, rw continuous_linear_map.map_add, exact submodule.add_mem (submodule.span 𝕜 (tangent_cone_at 𝕜 (f '' s) (f x))) hw₁ hw₂ }, { assume a w hw, rw continuous_linear_map.map_smul, exact submodule.smul_mem (submodule.span 𝕜 (tangent_cone_at 𝕜 (f '' s) (f x))) _ hw } }, rw [unique_diff_within_at, ← univ_subset_iff], split, show f x ∈ closure (f '' s), from h.continuous_within_at.mem_closure_image hs.2, show univ ⊆ closure ↑(submodule.span 𝕜 (tangent_cone_at 𝕜 (f '' s) (f x))), from calc univ ⊆ closure (range f') : univ_subset_iff.2 h' ... = closure (f' '' univ) : by rw image_univ ... = closure (f' '' (closure (submodule.span 𝕜 (tangent_cone_at 𝕜 s x) : set E))) : by rw hs.1 ... ⊆ closure (closure (f' '' (submodule.span 𝕜 (tangent_cone_at 𝕜 s x) : set E))) : closure_mono (image_closure_subset_closure_image f'.cont) ... = closure (f' '' (submodule.span 𝕜 (tangent_cone_at 𝕜 s x) : set E)) : closure_closure ... ⊆ closure (submodule.span 𝕜 (tangent_cone_at 𝕜 (f '' s) (f x)) : set F) : closure_mono (image_subset_iff.mpr B) end end tangent_cone
cdb925978a5877bbfb720a0d6e5eaf65f4e89681
d9d511f37a523cd7659d6f573f990e2a0af93c6f
/src/algebraic_geometry/structure_sheaf.lean
28074fcfb787d68de90d8193d30c2fe966cf4e3b
[ "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
44,252
lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Scott Morrison -/ import algebraic_geometry.prime_spectrum import algebra.category.CommRing.colimits import algebra.category.CommRing.limits import topology.sheaves.local_predicate import ring_theory.localization import ring_theory.subring /-! # The structure sheaf on `prime_spectrum R`. We define the structure sheaf on `Top.of (prime_spectrum R)`, for a commutative ring `R` and prove basic properties about it. We define this as a subsheaf of the sheaf of dependent functions into the localizations, cut out by the condition that the function must be locally equal to a ratio of elements of `R`. Because the condition "is equal to a fraction" passes to smaller open subsets, the subset of functions satisfying this condition is automatically a subpresheaf. Because the condition "is locally equal to a fraction" is local, it is also a subsheaf. (It may be helpful to refer back to `topology.sheaves.sheaf_of_functions`, where we show that dependent functions into any type family form a sheaf, and also `topology.sheaves.local_predicate`, where we characterise the predicates which pick out sub-presheaves and sub-sheaves of these sheaves.) We also set up the ring structure, obtaining `structure_sheaf R : sheaf CommRing (Top.of (prime_spectrum R))`. We then construct two basic isomorphisms, relating the structure sheaf to the underlying ring `R`. First, `structure_sheaf.stalk_iso` gives an isomorphism between the stalk of the structure sheaf at a point `p` and the localization of `R` at the prime ideal `p`. Second, `structure_sheaf.basic_open_iso` gives an isomorphism between the structure sheaf on `basic_open f` and the localization of `R` at the submonoid of powers of `f`. ## References * [Robin Hartshorne, *Algebraic Geometry*][Har77] -/ universe u noncomputable theory variables (R : Type u) [comm_ring R] open Top open topological_space open category_theory open opposite namespace algebraic_geometry /-- The prime spectrum, just as a topological space. -/ def prime_spectrum.Top : Top := Top.of (prime_spectrum R) namespace structure_sheaf /-- The type family over `prime_spectrum R` consisting of the localization over each point. -/ @[derive [comm_ring, local_ring]] def localizations (P : prime_spectrum.Top R) : Type u := localization.at_prime P.as_ideal instance (P : prime_spectrum.Top R) : inhabited (localizations R P) := ⟨1⟩ instance (U : opens (prime_spectrum.Top R)) (x : U) : algebra R (localizations R x) := localization.algebra instance (U : opens (prime_spectrum.Top R)) (x : U) : is_localization.at_prime (localizations R x) (x : prime_spectrum.Top R).as_ideal := localization.is_localization variables {R} /-- The predicate saying that a dependent function on an open `U` is realised as a fixed fraction `r / s` in each of the stalks (which are localizations at various prime ideals). -/ def is_fraction {U : opens (prime_spectrum.Top R)} (f : Π x : U, localizations R x) : Prop := ∃ (r s : R), ∀ x : U, ¬ (s ∈ x.1.as_ideal) ∧ f x * algebra_map _ _ s = algebra_map _ _ r lemma is_fraction.eq_mk' {U : opens (prime_spectrum.Top R)} {f : Π x : U, localizations R x} (hf : is_fraction f) : ∃ (r s : R) , ∀ x : U, ∃ (hs : s ∉ x.1.as_ideal), f x = is_localization.mk' (localization.at_prime _) r (⟨s, hs⟩ : (x : prime_spectrum.Top R).as_ideal.prime_compl) := begin rcases hf with ⟨r, s, h⟩, refine ⟨r, s, λ x, ⟨(h x).1, (is_localization.mk'_eq_iff_eq_mul.mpr _).symm⟩⟩, exact (h x).2.symm, end variables (R) /-- The predicate `is_fraction` is "prelocal", in the sense that if it holds on `U` it holds on any open subset `V` of `U`. -/ def is_fraction_prelocal : prelocal_predicate (localizations R) := { pred := λ U f, is_fraction f, res := by { rintro V U i f ⟨r, s, w⟩, exact ⟨r, s, λ x, w (i x)⟩ } } /-- We will define the structure sheaf as the subsheaf of all dependent functions in `Π x : U, localizations R x` consisting of those functions which can locally be expressed as a ratio of (the images in the localization of) elements of `R`. Quoting Hartshorne: For an open set $U ⊆ Spec A$, we define $𝒪(U)$ to be the set of functions $s : U → ⨆_{𝔭 ∈ U} A_𝔭$, such that $s(𝔭) ∈ A_𝔭$ for each $𝔭$, and such that $s$ is locally a quotient of elements of $A$: to be precise, we require that for each $𝔭 ∈ U$, there is a neighborhood $V$ of $𝔭$, contained in $U$, and elements $a, f ∈ A$, such that for each $𝔮 ∈ V, f ∉ 𝔮$, and $s(𝔮) = a/f$ in $A_𝔮$. Now Hartshorne had the disadvantage of not knowing about dependent functions, so we replace his circumlocution about functions into a disjoint union with `Π x : U, localizations x`. -/ def is_locally_fraction : local_predicate (localizations R) := (is_fraction_prelocal R).sheafify @[simp] lemma is_locally_fraction_pred {U : opens (prime_spectrum.Top R)} (f : Π x : U, localizations R x) : (is_locally_fraction R).pred f = ∀ x : U, ∃ (V) (m : x.1 ∈ V) (i : V ⟶ U), ∃ (r s : R), ∀ y : V, ¬ (s ∈ y.1.as_ideal) ∧ f (i y : U) * algebra_map _ _ s = algebra_map _ _ r := rfl /-- The functions satisfying `is_locally_fraction` form a subring. -/ def sections_subring (U : (opens (prime_spectrum.Top R))ᵒᵖ) : subring (Π x : unop U, localizations R x) := { carrier := { f | (is_locally_fraction R).pred f }, zero_mem' := begin refine λ x, ⟨unop U, x.2, 𝟙 _, 0, 1, λ y, ⟨_, _⟩⟩, { rw ←ideal.ne_top_iff_one, exact y.1.is_prime.1, }, { simp, }, end, one_mem' := begin refine λ x, ⟨unop U, x.2, 𝟙 _, 1, 1, λ y, ⟨_, _⟩⟩, { rw ←ideal.ne_top_iff_one, exact y.1.is_prime.1, }, { simp, }, end, add_mem' := begin intros a b ha hb x, rcases ha x with ⟨Va, ma, ia, ra, sa, wa⟩, rcases hb x with ⟨Vb, mb, ib, rb, sb, wb⟩, refine ⟨Va ⊓ Vb, ⟨ma, mb⟩, opens.inf_le_left _ _ ≫ ia, ra * sb + rb * sa, sa * sb, _⟩, intro y, rcases wa (opens.inf_le_left _ _ y) with ⟨nma, wa⟩, rcases wb (opens.inf_le_right _ _ y) with ⟨nmb, wb⟩, fsplit, { intro H, cases y.1.is_prime.mem_or_mem H; contradiction, }, { simp only [add_mul, ring_hom.map_add, pi.add_apply, ring_hom.map_mul], erw [←wa, ←wb], simp only [mul_assoc], congr' 2, rw [mul_comm], refl, } end, neg_mem' := begin intros a ha x, rcases ha x with ⟨V, m, i, r, s, w⟩, refine ⟨V, m, i, -r, s, _⟩, intro y, rcases w y with ⟨nm, w⟩, fsplit, { exact nm, }, { simp only [ring_hom.map_neg, pi.neg_apply], erw [←w], simp only [neg_mul_eq_neg_mul_symm], } end, mul_mem' := begin intros a b ha hb x, rcases ha x with ⟨Va, ma, ia, ra, sa, wa⟩, rcases hb x with ⟨Vb, mb, ib, rb, sb, wb⟩, refine ⟨Va ⊓ Vb, ⟨ma, mb⟩, opens.inf_le_left _ _ ≫ ia, ra * rb, sa * sb, _⟩, intro y, rcases wa (opens.inf_le_left _ _ y) with ⟨nma, wa⟩, rcases wb (opens.inf_le_right _ _ y) with ⟨nmb, wb⟩, fsplit, { intro H, cases y.1.is_prime.mem_or_mem H; contradiction, }, { simp only [pi.mul_apply, ring_hom.map_mul], erw [←wa, ←wb], simp only [mul_left_comm, mul_assoc, mul_comm], refl, } end, } end structure_sheaf open structure_sheaf /-- The structure sheaf (valued in `Type`, not yet `CommRing`) is the subsheaf consisting of functions satisfying `is_locally_fraction`. -/ def structure_sheaf_in_Type : sheaf (Type u) (prime_spectrum.Top R):= subsheaf_to_Types (is_locally_fraction R) instance comm_ring_structure_sheaf_in_Type_obj (U : (opens (prime_spectrum.Top R))ᵒᵖ) : comm_ring ((structure_sheaf_in_Type R).presheaf.obj U) := (sections_subring R U).to_comm_ring open prime_spectrum /-- The structure presheaf, valued in `CommRing`, constructed by dressing up the `Type` valued structure presheaf. -/ @[simps] def structure_presheaf_in_CommRing : presheaf CommRing (prime_spectrum.Top R) := { obj := λ U, CommRing.of ((structure_sheaf_in_Type R).presheaf.obj U), map := λ U V i, { to_fun := ((structure_sheaf_in_Type R).presheaf.map i), map_zero' := rfl, map_add' := λ x y, rfl, map_one' := rfl, map_mul' := λ x y, rfl, }, } /-- Some glue, verifying that that structure presheaf valued in `CommRing` agrees with the `Type` valued structure presheaf. -/ def structure_presheaf_comp_forget : structure_presheaf_in_CommRing R ⋙ (forget CommRing) ≅ (structure_sheaf_in_Type R).presheaf := nat_iso.of_components (λ U, iso.refl _) (by tidy) open Top.presheaf /-- The structure sheaf on $Spec R$, valued in `CommRing`. This is provided as a bundled `SheafedSpace` as `Spec.SheafedSpace R` later. -/ def structure_sheaf : sheaf CommRing (prime_spectrum.Top R) := { presheaf := structure_presheaf_in_CommRing R, sheaf_condition := -- We check the sheaf condition under `forget CommRing`. (sheaf_condition_equiv_sheaf_condition_comp _ _).symm (sheaf_condition_equiv_of_iso (structure_presheaf_comp_forget R).symm (structure_sheaf_in_Type R).sheaf_condition), } namespace structure_sheaf @[simp] lemma res_apply (U V : opens (prime_spectrum.Top R)) (i : V ⟶ U) (s : (structure_sheaf R).presheaf.obj (op U)) (x : V) : ((structure_sheaf R).presheaf.map i.op s).1 x = (s.1 (i x) : _) := rfl /- Notation in this comment X = Spec R OX = structure sheaf In the following we construct an isomorphism between OX_p and R_p given any point p corresponding to a prime ideal in R. We do this via 8 steps: 1. def const (f g : R) (V) (hv : V ≤ D_g) : OX(V) [for api] 2. def to_open (U) : R ⟶ OX(U) 3. [2] def to_stalk (p : Spec R) : R ⟶ OX_p 4. [2] def to_basic_open (f : R) : R_f ⟶ OX(D_f) 5. [3] def localization_to_stalk (p : Spec R) : R_p ⟶ OX_p 6. def open_to_localization (U) (p) (hp : p ∈ U) : OX(U) ⟶ R_p 7. [6] def stalk_to_fiber_ring_hom (p : Spec R) : OX_p ⟶ R_p 8. [5,7] def stalk_iso (p : Spec R) : OX_p ≅ R_p In the square brackets we list the dependencies of a construction on the previous steps. -/ /-- The section of `structure_sheaf R` on an open `U` sending each `x ∈ U` to the element `f/g` in the localization of `R` at `x`. -/ def const (f g : R) (U : opens (prime_spectrum.Top R)) (hu : ∀ x ∈ U, g ∈ (x : prime_spectrum.Top R).as_ideal.prime_compl) : (structure_sheaf R).presheaf.obj (op U) := ⟨λ x, is_localization.mk' _ f ⟨g, hu x x.2⟩, λ x, ⟨U, x.2, 𝟙 _, f, g, λ y, ⟨hu y y.2, is_localization.mk'_spec _ _ _⟩⟩⟩ @[simp] lemma const_apply (f g : R) (U : opens (prime_spectrum.Top R)) (hu : ∀ x ∈ U, g ∈ (x : prime_spectrum.Top R).as_ideal.prime_compl) (x : U) : (const R f g U hu).1 x = is_localization.mk' _ f ⟨g, hu x x.2⟩ := rfl lemma const_apply' (f g : R) (U : opens (prime_spectrum.Top R)) (hu : ∀ x ∈ U, g ∈ (x : prime_spectrum.Top R).as_ideal.prime_compl) (x : U) (hx : g ∈ (as_ideal (x : prime_spectrum.Top R)).prime_compl) : (const R f g U hu).1 x = is_localization.mk' _ f ⟨g, hx⟩ := rfl lemma exists_const (U) (s : (structure_sheaf R).presheaf.obj (op U)) (x : prime_spectrum.Top R) (hx : x ∈ U) : ∃ (V : opens (prime_spectrum.Top R)) (hxV : x ∈ V) (i : V ⟶ U) (f g : R) hg, const R f g V hg = (structure_sheaf R).presheaf.map i.op s := let ⟨V, hxV, iVU, f, g, hfg⟩ := s.2 ⟨x, hx⟩ in ⟨V, hxV, iVU, f, g, λ y hyV, (hfg ⟨y, hyV⟩).1, subtype.eq $ funext $ λ y, is_localization.mk'_eq_iff_eq_mul.2 $ eq.symm $ (hfg y).2⟩ @[simp] lemma res_const (f g : R) (U hu V hv i) : (structure_sheaf R).presheaf.map i (const R f g U hu) = const R f g V hv := rfl lemma res_const' (f g : R) (V hv) : (structure_sheaf R).presheaf.map (hom_of_le hv).op (const R f g (basic_open g) (λ _, id)) = const R f g V hv := rfl lemma const_zero (f : R) (U hu) : const R 0 f U hu = 0 := subtype.eq $ funext $ λ x, is_localization.mk'_eq_iff_eq_mul.2 $ by erw [ring_hom.map_zero, subtype.val_eq_coe, subring.coe_zero, pi.zero_apply, zero_mul] lemma const_self (f : R) (U hu) : const R f f U hu = 1 := subtype.eq $ funext $ λ x, is_localization.mk'_self _ _ lemma const_one (U) : const R 1 1 U (λ p _, submonoid.one_mem _) = 1 := const_self R 1 U _ lemma const_add (f₁ f₂ g₁ g₂ : R) (U hu₁ hu₂) : const R f₁ g₁ U hu₁ + const R f₂ g₂ U hu₂ = const R (f₁ * g₂ + f₂ * g₁) (g₁ * g₂) U (λ x hx, submonoid.mul_mem _ (hu₁ x hx) (hu₂ x hx)) := subtype.eq $ funext $ λ x, eq.symm $ by convert is_localization.mk'_add f₁ f₂ ⟨g₁, hu₁ x x.2⟩ ⟨g₂, hu₂ x x.2⟩ lemma const_mul (f₁ f₂ g₁ g₂ : R) (U hu₁ hu₂) : const R f₁ g₁ U hu₁ * const R f₂ g₂ U hu₂ = const R (f₁ * f₂) (g₁ * g₂) U (λ x hx, submonoid.mul_mem _ (hu₁ x hx) (hu₂ x hx)) := subtype.eq $ funext $ λ x, eq.symm $ by convert is_localization.mk'_mul _ f₁ f₂ ⟨g₁, hu₁ x x.2⟩ ⟨g₂, hu₂ x x.2⟩ lemma const_ext {f₁ f₂ g₁ g₂ : R} {U hu₁ hu₂} (h : f₁ * g₂ = f₂ * g₁) : const R f₁ g₁ U hu₁ = const R f₂ g₂ U hu₂ := subtype.eq $ funext $ λ x, is_localization.mk'_eq_of_eq h.symm lemma const_congr {f₁ f₂ g₁ g₂ : R} {U hu} (hf : f₁ = f₂) (hg : g₁ = g₂) : const R f₁ g₁ U hu = const R f₂ g₂ U (hg ▸ hu) := by substs hf hg lemma const_mul_rev (f g : R) (U hu₁ hu₂) : const R f g U hu₁ * const R g f U hu₂ = 1 := by rw [const_mul, const_congr R rfl (mul_comm g f), const_self] lemma const_mul_cancel (f g₁ g₂ : R) (U hu₁ hu₂) : const R f g₁ U hu₁ * const R g₁ g₂ U hu₂ = const R f g₂ U hu₂ := by { rw [const_mul, const_ext], rw mul_assoc } lemma const_mul_cancel' (f g₁ g₂ : R) (U hu₁ hu₂) : const R g₁ g₂ U hu₂ * const R f g₁ U hu₁ = const R f g₂ U hu₂ := by rw [mul_comm, const_mul_cancel] /-- The canonical ring homomorphism interpreting an element of `R` as a section of the structure sheaf. -/ def to_open (U : opens (prime_spectrum.Top R)) : CommRing.of R ⟶ (structure_sheaf R).presheaf.obj (op U) := { to_fun := λ f, ⟨λ x, algebra_map R _ f, λ x, ⟨U, x.2, 𝟙 _, f, 1, λ y, ⟨(ideal.ne_top_iff_one _).1 y.1.2.1, by { rw [ring_hom.map_one, mul_one], refl } ⟩⟩⟩, map_one' := subtype.eq $ funext $ λ x, ring_hom.map_one _, map_mul' := λ f g, subtype.eq $ funext $ λ x, ring_hom.map_mul _ _ _, map_zero' := subtype.eq $ funext $ λ x, ring_hom.map_zero _, map_add' := λ f g, subtype.eq $ funext $ λ x, ring_hom.map_add _ _ _ } @[simp] lemma to_open_res (U V : opens (prime_spectrum.Top R)) (i : V ⟶ U) : to_open R U ≫ (structure_sheaf R).presheaf.map i.op = to_open R V := rfl @[simp] lemma to_open_apply (U : opens (prime_spectrum.Top R)) (f : R) (x : U) : (to_open R U f).1 x = algebra_map _ _ f := rfl lemma to_open_eq_const (U : opens (prime_spectrum.Top R)) (f : R) : to_open R U f = const R f 1 U (λ x _, (ideal.ne_top_iff_one _).1 x.2.1) := subtype.eq $ funext $ λ x, eq.symm $ is_localization.mk'_one _ f /-- The canonical ring homomorphism interpreting an element of `R` as an element of the stalk of `structure_sheaf R` at `x`. -/ def to_stalk (x : prime_spectrum.Top R) : CommRing.of R ⟶ (structure_sheaf R).presheaf.stalk x := (to_open R ⊤ ≫ (structure_sheaf R).presheaf.germ ⟨x, ⟨⟩⟩ : _) @[simp] lemma to_open_germ (U : opens (prime_spectrum.Top R)) (x : U) : to_open R U ≫ (structure_sheaf R).presheaf.germ x = to_stalk R x := by { rw [← to_open_res R ⊤ U (hom_of_le le_top : U ⟶ ⊤), category.assoc, presheaf.germ_res], refl } @[simp] lemma germ_to_open (U : opens (prime_spectrum.Top R)) (x : U) (f : R) : (structure_sheaf R).presheaf.germ x (to_open R U f) = to_stalk R x f := by { rw ← to_open_germ, refl } lemma germ_to_top (x : prime_spectrum.Top R) (f : R) : (structure_sheaf R).presheaf.germ (⟨x, trivial⟩ : (⊤ : opens (prime_spectrum.Top R))) (to_open R ⊤ f) = to_stalk R x f := rfl lemma is_unit_to_basic_open_self (f : R) : is_unit (to_open R (basic_open f) f) := is_unit_of_mul_eq_one _ (const R 1 f (basic_open f) (λ _, id)) $ by rw [to_open_eq_const, const_mul_rev] lemma is_unit_to_stalk (x : prime_spectrum.Top R) (f : x.as_ideal.prime_compl) : is_unit (to_stalk R x (f : R)) := by { erw ← germ_to_open R (basic_open (f : R)) ⟨x, f.2⟩ (f : R), exact ring_hom.is_unit_map _ (is_unit_to_basic_open_self R f) } /-- The canonical ring homomorphism from the localization of `R` at `p` to the stalk of the structure sheaf at the point `p`. -/ def localization_to_stalk (x : prime_spectrum.Top R) : CommRing.of (localization.at_prime x.as_ideal) ⟶ (structure_sheaf R).presheaf.stalk x := show localization.at_prime x.as_ideal →+* _, from is_localization.lift (is_unit_to_stalk R x) @[simp] lemma localization_to_stalk_of (x : prime_spectrum.Top R) (f : R) : localization_to_stalk R x (algebra_map _ (localization _) f) = to_stalk R x f := is_localization.lift_eq _ f @[simp] lemma localization_to_stalk_mk' (x : prime_spectrum.Top R) (f : R) (s : (as_ideal x).prime_compl) : localization_to_stalk R x (is_localization.mk' _ f s : localization _) = (structure_sheaf R).presheaf.germ (⟨x, s.2⟩ : basic_open (s : R)) (const R f s (basic_open s) (λ _, id)) := (is_localization.lift_mk'_spec _ _ _ _).2 $ by erw [← germ_to_open R (basic_open s) ⟨x, s.2⟩, ← germ_to_open R (basic_open s) ⟨x, s.2⟩, ← ring_hom.map_mul, to_open_eq_const, to_open_eq_const, const_mul_cancel'] /-- The ring homomorphism that takes a section of the structure sheaf of `R` on the open set `U`, implemented as a subtype of dependent functions to localizations at prime ideals, and evaluates the section on the point corresponding to a given prime ideal. -/ def open_to_localization (U : opens (prime_spectrum.Top R)) (x : prime_spectrum.Top R) (hx : x ∈ U) : (structure_sheaf R).presheaf.obj (op U) ⟶ CommRing.of (localization.at_prime x.as_ideal) := { to_fun := λ s, (s.1 ⟨x, hx⟩ : _), map_one' := rfl, map_mul' := λ _ _, rfl, map_zero' := rfl, map_add' := λ _ _, rfl } @[simp] lemma coe_open_to_localization (U : opens (prime_spectrum.Top R)) (x : prime_spectrum.Top R) (hx : x ∈ U) : (open_to_localization R U x hx : (structure_sheaf R).presheaf.obj (op U) → localization.at_prime x.as_ideal) = (λ s, (s.1 ⟨x, hx⟩ : _)) := rfl lemma open_to_localization_apply (U : opens (prime_spectrum.Top R)) (x : prime_spectrum.Top R) (hx : x ∈ U) (s : (structure_sheaf R).presheaf.obj (op U)) : open_to_localization R U x hx s = (s.1 ⟨x, hx⟩ : _) := rfl /-- The ring homomorphism from the stalk of the structure sheaf of `R` at a point corresponding to a prime ideal `p` to the localization of `R` at `p`, formed by gluing the `open_to_localization` maps. -/ def stalk_to_fiber_ring_hom (x : prime_spectrum.Top R) : (structure_sheaf R).presheaf.stalk x ⟶ CommRing.of (localization.at_prime x.as_ideal) := limits.colimit.desc (((open_nhds.inclusion x).op) ⋙ (structure_sheaf R).presheaf) { X := _, ι := { app := λ U, open_to_localization R ((open_nhds.inclusion _).obj (unop U)) x (unop U).2, } } @[simp] lemma germ_comp_stalk_to_fiber_ring_hom (U : opens (prime_spectrum.Top R)) (x : U) : (structure_sheaf R).presheaf.germ x ≫ stalk_to_fiber_ring_hom R x = open_to_localization R U x x.2 := limits.colimit.ι_desc _ _ @[simp] lemma stalk_to_fiber_ring_hom_germ' (U : opens (prime_spectrum.Top R)) (x : prime_spectrum.Top R) (hx : x ∈ U) (s : (structure_sheaf R).presheaf.obj (op U)) : stalk_to_fiber_ring_hom R x ((structure_sheaf R).presheaf.germ ⟨x, hx⟩ s) = (s.1 ⟨x, hx⟩ : _) := ring_hom.ext_iff.1 (germ_comp_stalk_to_fiber_ring_hom R U ⟨x, hx⟩ : _) s @[simp] lemma stalk_to_fiber_ring_hom_germ (U : opens (prime_spectrum.Top R)) (x : U) (s : (structure_sheaf R).presheaf.obj (op U)) : stalk_to_fiber_ring_hom R x ((structure_sheaf R).presheaf.germ x s) = s.1 x := by { cases x, exact stalk_to_fiber_ring_hom_germ' R U _ _ _ } @[simp] lemma to_stalk_comp_stalk_to_fiber_ring_hom (x : prime_spectrum.Top R) : to_stalk R x ≫ stalk_to_fiber_ring_hom R x = (algebra_map _ _ : R →+* localization _) := by { erw [to_stalk, category.assoc, germ_comp_stalk_to_fiber_ring_hom], refl } @[simp] lemma stalk_to_fiber_ring_hom_to_stalk (x : prime_spectrum.Top R) (f : R) : stalk_to_fiber_ring_hom R x (to_stalk R x f) = algebra_map _ (localization _) f := ring_hom.ext_iff.1 (to_stalk_comp_stalk_to_fiber_ring_hom R x) _ /-- The ring isomorphism between the stalk of the structure sheaf of `R` at a point `p` corresponding to a prime ideal in `R` and the localization of `R` at `p`. -/ @[simps] def stalk_iso (x : prime_spectrum.Top R) : (structure_sheaf R).presheaf.stalk x ≅ CommRing.of (localization.at_prime x.as_ideal) := { hom := stalk_to_fiber_ring_hom R x, inv := localization_to_stalk R x, hom_inv_id' := (structure_sheaf R).presheaf.stalk_hom_ext $ λ U hxU, begin ext s, simp only [comp_apply], rw [id_apply, stalk_to_fiber_ring_hom_germ'], obtain ⟨V, hxV, iVU, f, g, hg, hs⟩ := exists_const _ _ s x hxU, erw [← res_apply R U V iVU s ⟨x, hxV⟩, ← hs, const_apply, localization_to_stalk_mk'], refine (structure_sheaf R).presheaf.germ_ext V hxV (hom_of_le hg) iVU _, erw [← hs, res_const'] end, inv_hom_id' := @is_localization.ring_hom_ext R _ x.as_ideal.prime_compl (localization.at_prime x.as_ideal) _ _ (localization.at_prime x.as_ideal) _ _ (ring_hom.comp (stalk_to_fiber_ring_hom R x) (localization_to_stalk R x)) (ring_hom.id (localization.at_prime _)) $ by { ext f, simp only [ring_hom.comp_apply, ring_hom.id_apply, localization_to_stalk_of, stalk_to_fiber_ring_hom_to_stalk] } } /-- The canonical ring homomorphism interpreting `s ∈ R_f` as a section of the structure sheaf on the basic open defined by `f ∈ R`. -/ def to_basic_open (f : R) : localization.away f →+* (structure_sheaf R).presheaf.obj (op $ basic_open f) := is_localization.away.lift f (is_unit_to_basic_open_self R f) @[simp] lemma to_basic_open_mk' (s f : R) (g : submonoid.powers s) : to_basic_open R s (is_localization.mk' (localization.away s) f g) = const R f g (basic_open s) (λ x hx, submonoid.powers_subset hx g.2) := (is_localization.lift_mk'_spec _ _ _ _).2 $ by rw [to_open_eq_const, to_open_eq_const, const_mul_cancel'] @[simp] lemma localization_to_basic_open (f : R) : ring_hom.comp (to_basic_open R f) (algebra_map R (localization.away f)) = to_open R (basic_open f) := ring_hom.ext $ λ g, by rw [to_basic_open, is_localization.away.lift, ring_hom.comp_apply, is_localization.lift_eq] @[simp] lemma to_basic_open_to_map (s f : R) : to_basic_open R s (algebra_map R (localization.away s) f) = const R f 1 (basic_open s) (λ _ _, submonoid.one_mem _) := (is_localization.lift_eq _ _).trans $ to_open_eq_const _ _ _ -- The proof here follows the argument in Hartshorne's Algebraic Geometry, Proposition II.2.2. lemma to_basic_open_injective (f : R) : function.injective (to_basic_open R f) := begin intros s t h_eq, obtain ⟨a, ⟨b, hb⟩, rfl⟩ := is_localization.mk'_surjective (submonoid.powers f) s, obtain ⟨c, ⟨d, hd⟩, rfl⟩ := is_localization.mk'_surjective (submonoid.powers f) t, simp only [to_basic_open_mk'] at h_eq, rw is_localization.eq, -- We know that the fractions `a/b` and `c/d` are equal as sections of the structure sheaf on -- `basic_open f`. We need to show that they agree as elements in the localization of `R` at `f`. -- This amounts showing that `a * d * r = c * b * r`, for some power `r = f ^ n` of `f`. -- We define `I` as the ideal of *all* elements `r` satisfying the above equation. let I : ideal R := { carrier := {r : R | a * d * r = c * b * r}, zero_mem' := by simp only [set.mem_set_of_eq, mul_zero], add_mem' := λ r₁ r₂ hr₁ hr₂, by { dsimp at hr₁ hr₂ ⊢, simp only [mul_add, hr₁, hr₂] }, smul_mem' := λ r₁ r₂ hr₂, by { dsimp at hr₂ ⊢, simp only [mul_comm r₁ r₂, ← mul_assoc, hr₂] }}, -- Our claim now reduces to showing that `f` is contained in the radical of `I` suffices : f ∈ I.radical, { cases this with n hn, exact ⟨⟨f ^ n, n, rfl⟩, hn⟩ }, rw [← vanishing_ideal_zero_locus_eq_radical, mem_vanishing_ideal], intros p hfp, contrapose hfp, rw [mem_zero_locus, set.not_subset], have := congr_fun (congr_arg subtype.val h_eq) ⟨p,hfp⟩, rw [const_apply, const_apply, is_localization.eq] at this, cases this with r hr, exact ⟨r.1, hr, r.2⟩ end /- Auxiliary lemma for surjectivity of `to_basic_open`. Every section can locally be represented on basic opens `basic_opens g` as a fraction `f/g` -/ lemma locally_const_basic_open (U : opens (prime_spectrum.Top R)) (s : (structure_sheaf R).presheaf.obj (op U)) (x : U) : ∃ (f g : R) (i : basic_open g ⟶ U), x.1 ∈ basic_open g ∧ const R f g (basic_open g) (λ y hy, hy) = (structure_sheaf R).presheaf.map i.op s := begin -- First, any section `s` can be represented as a fraction `f/g` on some open neighborhood of `x` -- and we may pass to a `basic_open h`, since these form a basis obtain ⟨V, (hxV : x.1 ∈ V.1), iVU, f, g, (hVDg : V ⊆ basic_open g), s_eq⟩ := exists_const R U s x.1 x.2, obtain ⟨_, ⟨h, rfl⟩, hxDh, (hDhV : basic_open h ⊆ V)⟩ := is_topological_basis_basic_opens.exists_subset_of_mem_open hxV V.2, -- The problem is of course, that `g` and `h` don't need to coincide. -- But, since `basic_open h ≤ basic_open g`, some power of `h` must be a multiple of `g` cases (basic_open_le_basic_open_iff h g).mp (set.subset.trans hDhV hVDg) with n hn, -- Actually, we will need a *nonzero* power of `h`. -- This is because we will need the equality `basic_open (h ^ n) = basic_open h`, which only -- holds for a nonzero power `n`. We therefore artificially increase `n` by one. replace hn := ideal.mul_mem_left (ideal.span {g}) h hn, rw [← pow_succ, ideal.mem_span_singleton'] at hn, cases hn with c hc, have basic_opens_eq := basic_open_pow h (n+1) (by linarith), have i_basic_open := eq_to_hom basic_opens_eq ≫ hom_of_le hDhV, -- We claim that `(f * c) / h ^ (n+1)` is our desired representation use [f * c, h ^ (n+1), i_basic_open ≫ iVU, (basic_opens_eq.symm.le : _) hxDh], rw [op_comp, functor.map_comp, comp_apply, ← s_eq, res_const], -- Note that the last rewrite here generated an additional goal, which was a parameter -- of `res_const`. We prove this goal first swap, { intros y hy, rw basic_opens_eq at hy, exact (set.subset.trans hDhV hVDg : _) hy }, -- All that is left is a simple calculation apply const_ext, rw [mul_assoc f c g, hc], end /- Auxiliary lemma for surjectivity of `to_basic_open`. A local representation of a section `s` as fractions `a i / h i` on finitely many basic opens `basic_open (h i)` can be "normalized" in such a way that `a i * h j = h i * a j` for all `i, j` -/ lemma normalize_finite_fraction_representation (U : opens (prime_spectrum.Top R)) (s : (structure_sheaf R).presheaf.obj (op U)) {ι : Type*} (t : finset ι) (a h : ι → R) (iDh : Π i : ι, basic_open (h i) ⟶ U) (h_cover : U.1 ⊆ ⋃ i ∈ t, (basic_open (h i)).1) (hs : ∀ i : ι, const R (a i) (h i) (basic_open (h i)) (λ y hy, hy) = (structure_sheaf R).presheaf.map (iDh i).op s) : ∃ (a' h' : ι → R) (iDh' : Π i : ι, (basic_open (h' i)) ⟶ U), (U.1 ⊆ ⋃ i ∈ t, (basic_open (h' i)).1) ∧ (∀ i j ∈ t, a' i * h' j = h' i * a' j) ∧ (∀ i ∈ t, (structure_sheaf R).presheaf.map (iDh' i).op s = const R (a' i) (h' i) (basic_open (h' i)) (λ y hy, hy)) := begin -- First we show that the fractions `(a i * h j) / (h i * h j)` and `(h i * a j) / (h i * h j)` -- coincide in the localization of `R` at `h i * h j` have fractions_eq : ∀ (i j : ι), is_localization.mk' (localization.away _) (a i * h j) ⟨h i * h j, submonoid.mem_powers _⟩ = is_localization.mk' _ (h i * a j) ⟨h i * h j, submonoid.mem_powers _⟩, { intros i j, let D := basic_open (h i * h j), let iDi : D ⟶ basic_open (h i) := hom_of_le (basic_open_mul_le_left _ _), let iDj : D ⟶ basic_open (h j) := hom_of_le (basic_open_mul_le_right _ _), -- Crucially, we need injectivity of `to_basic_open` apply to_basic_open_injective R (h i * h j), rw [to_basic_open_mk', to_basic_open_mk'], simp only [set_like.coe_mk], -- Here, both sides of the equation are equal to a restriction of `s` transitivity, convert congr_arg ((structure_sheaf R).presheaf.map iDj.op) (hs j).symm using 1, convert congr_arg ((structure_sheaf R).presheaf.map iDi.op) (hs i) using 1, swap, all_goals { rw res_const, apply const_ext, ring }, -- The remaining two goals were generated during the rewrite of `res_const` -- These can be solved immediately exacts [basic_open_mul_le_right _ _, basic_open_mul_le_left _ _] }, -- From the equality in the localization, we obtain for each `(i,j)` some power `(h i * h j) ^ n` -- which equalizes `a i * h j` and `h i * a j` have exists_power : ∀ (i j : ι), ∃ n : ℕ, a i * h j * (h i * h j) ^ n = h i * a j * (h i * h j) ^ n, { intros i j, obtain ⟨⟨c, n, rfl⟩, hc⟩ := is_localization.eq.mp (fractions_eq i j), use (n+1), rw pow_succ, dsimp at hc, convert hc using 1 ; ring }, let n := λ (p : ι × ι), (exists_power p.1 p.2).some, have n_spec := λ (p : ι × ι), (exists_power p.fst p.snd).some_spec, -- We need one power `(h i * h j) ^ N` that works for *all* pairs `(i,j)` -- Since there are only finitely many indices involved, we can pick the supremum. let N := (t.product t).sup n, have basic_opens_eq : ∀ i : ι, basic_open ((h i) ^ (N+1)) = basic_open (h i) := λ i, basic_open_pow _ _ (by linarith), -- Expanding the fraction `a i / h i` by the power `(h i) ^ N` gives the desired normalization refine ⟨(λ i, a i * (h i) ^ N), (λ i, (h i) ^ (N + 1)), (λ i, eq_to_hom (basic_opens_eq i) ≫ iDh i), _, _, _⟩, { simpa only [basic_opens_eq] using h_cover }, { intros i j hi hj, -- Here we need to show that our new fractions `a i / h i` satisfy the normalization condition -- Of course, the power `N` we used to expand the fractions might be bigger than the power -- `n (i, j)` which was originally chosen. We denote their difference by `k` have n_le_N : n (i, j) ≤ N := finset.le_sup (finset.mem_product.mpr ⟨hi, hj⟩), cases nat.le.dest n_le_N with k hk, simp only [← hk, pow_add, pow_one], -- To accommodate for the difference `k`, we multiply both sides of the equation `n_spec (i, j)` -- by `(h i * h j) ^ k` convert congr_arg (λ z, z * (h i * h j) ^ k) (n_spec (i, j)) using 1 ; { simp only [n, mul_pow], ring } }, -- Lastly, we need to show that the new fractions still represent our original `s` intros i hi, rw [op_comp, functor.map_comp, comp_apply, ← hs, res_const], -- additional goal spit out by `res_const` swap, exact (basic_opens_eq i).le, apply const_ext, rw pow_succ, ring end open_locale classical open_locale big_operators -- The proof here follows the argument in Hartshorne's Algebraic Geometry, Proposition II.2.2. lemma to_basic_open_surjective (f : R) : function.surjective (to_basic_open R f) := begin intro s, -- In this proof, `basic_open f` will play two distinct roles: Firstly, it is an open set in the -- prime spectrum. Secondly, it is used as an indexing type for various families of objects -- (open sets, ring elements, ...). In order to make the distinction clear, we introduce a type -- alias `ι` that is used whenever we want think of it as an indexing type. let ι : Type u := basic_open f, -- First, we pick some cover of basic opens, on which we can represent `s` as a fraction choose a' h' iDh' hxDh' s_eq' using locally_const_basic_open R (basic_open f) s, -- Since basic opens are compact, we can pass to a finite subcover obtain ⟨t, ht_cover'⟩ := (is_compact_basic_open f).elim_finite_subcover (λ (i : ι), (basic_open (h' i)).1) (λ i, is_open_basic_open) (λ x hx, _), swap, { -- Here, we need to show that our basic opens actually form a cover of `basic_open f` rw set.mem_Union, exact ⟨⟨x,hx⟩, hxDh' ⟨x, hx⟩⟩ }, -- We use the normalization lemma from above to obtain the relation `a i * h j = h i * a j` obtain ⟨a, h, iDh, ht_cover, ah_ha, s_eq⟩ := normalize_finite_fraction_representation R (basic_open f) s t a' h' iDh' ht_cover' s_eq', clear s_eq' iDh' hxDh' ht_cover' a' h', -- Next we show that some power of `f` is a linear combination of the `h i` obtain ⟨n, hn⟩ : f ∈ (ideal.span (h '' ↑t)).radical, { rw [← vanishing_ideal_zero_locus_eq_radical, zero_locus_span], simp_rw [subtype.val_eq_coe, basic_open_eq_zero_locus_compl] at ht_cover, rw set.compl_subset_comm at ht_cover, -- Why doesn't `simp_rw` do this? simp_rw [set.compl_Union, compl_compl, ← zero_locus_Union, ← finset.set_bUnion_coe, ← set.image_eq_Union ] at ht_cover, apply vanishing_ideal_anti_mono ht_cover, exact subset_vanishing_ideal_zero_locus {f} (set.mem_singleton f) }, replace hn := ideal.mul_mem_left _ f hn, erw [←pow_succ, finsupp.mem_span_image_iff_total] at hn, rcases hn with ⟨b, b_supp, hb⟩, rw finsupp.total_apply_of_mem_supported R b_supp at hb, dsimp at hb, -- Finally, we have all the ingredients. -- We claim that our preimage is given by `(∑ (i : ι) in t, b i * a i) / f ^ (n+1)` use is_localization.mk' (localization.away f) (∑ (i : ι) in t, b i * a i) (⟨f ^ (n+1), n+1, rfl⟩ : submonoid.powers _), rw to_basic_open_mk', -- Since the structure sheaf is a sheaf, we can show the desired equality locally. -- Annoyingly, `sheaf.eq_of_locally_eq` requires an open cover indexed by a *type*, so we need to -- coerce our finset `t` to a type first. let tt := ((t : set (basic_open f)) : Type u), apply (structure_sheaf R).eq_of_locally_eq' (λ i : tt, basic_open (h i)) (basic_open f) (λ i : tt, iDh i), { -- This feels a little redundant, since already have `ht_cover` as a hypothesis -- Unfortunately, `ht_cover` uses a bounded union over the set `t`, while here we have the -- Union indexed by the type `tt`, so we need some boilerplate to translate one to the other intros x hx, erw topological_space.opens.mem_supr, have := ht_cover hx, rw [← finset.set_bUnion_coe, set.mem_bUnion_iff] at this, rcases this with ⟨i, i_mem, x_mem⟩, use [i, i_mem] }, rintro ⟨i, hi⟩, dsimp, change (structure_sheaf R).presheaf.map _ _ = (structure_sheaf R).presheaf.map _ _, rw [s_eq i hi, res_const], -- Again, `res_const` spits out an additional goal swap, { intros y hy, change y ∈ basic_open (f ^ (n+1)), rw basic_open_pow f (n+1) (by linarith), exact (le_of_hom (iDh i) : _) hy }, -- The rest of the proof is just computation apply const_ext, rw [← hb, finset.sum_mul, finset.mul_sum], apply finset.sum_congr rfl, intros j hj, rw [mul_assoc, ah_ha j i hj hi], ring end instance is_iso_to_basic_open (f : R) : is_iso (show CommRing.of _ ⟶ _, from to_basic_open R f) := begin haveI : is_iso ((forget CommRing).map (show CommRing.of _ ⟶ _, from to_basic_open R f)) := (is_iso_iff_bijective _).mpr ⟨to_basic_open_injective R f, to_basic_open_surjective R f⟩, exact is_iso_of_reflects_iso _ (forget CommRing), end /-- The ring isomorphism between the structure sheaf on `basic_open f` and the localization of `R` at the submonoid of powers of `f`. -/ def basic_open_iso (f : R) : (structure_sheaf R).presheaf.obj (op (basic_open f)) ≅ CommRing.of (localization.away f) := (as_iso (show CommRing.of _ ⟶ _, from to_basic_open R f)).symm section comap variables {R} {S : Type u} [comm_ring S] {P : Type u} [comm_ring P] /-- Given a ring homomorphism `f : R →+* S`, an open set `U` of the prime spectrum of `R` and an open set `V` of the prime spectrum of `S`, such that `V ⊆ (comap f) ⁻¹' U`, we can push a section `s` on `U` to a section on `V`, by composing with `localization.local_ring_hom _ _ f` from the left and `comap f` from the right. Explicitly, if `s` evaluates on `comap f p` to `a / b`, its image on `V` evaluates on `p` to `f(a) / f(b)`. At the moment, we work with arbitrary dependent functions `s : Π x : U, localizations R x`. Below, we prove the predicate `is_locally_fraction` is preserved by this map, hence it can be extended to a morphism between the structure sheaves of `R` and `S`. -/ def comap_fun (f : R →+* S) (U : opens (prime_spectrum.Top R)) (V : opens (prime_spectrum.Top S)) (hUV : V.1 ⊆ (prime_spectrum.comap f) ⁻¹' U.1) (s : Π x : U, localizations R x) (y : V) : localizations S y := localization.local_ring_hom (prime_spectrum.comap f y.1).as_ideal _ f rfl (s ⟨(prime_spectrum.comap f y.1), hUV y.2⟩ : _) lemma comap_fun_is_locally_fraction (f : R →+* S) (U : opens (prime_spectrum.Top R)) (V : opens (prime_spectrum.Top S)) (hUV : V.1 ⊆ (prime_spectrum.comap f) ⁻¹' U.1) (s : Π x : U, localizations R x) (hs : (is_locally_fraction R).to_prelocal_predicate.pred s) : (is_locally_fraction S).to_prelocal_predicate.pred (comap_fun f U V hUV s) := begin rintro ⟨p, hpV⟩, -- Since `s` is locally fraction, we can find a neighborhood `W` of `prime_spectrum.comap f p` -- in `U`, such that `s = a / b` on `W`, for some ring elements `a, b : R`. rcases hs ⟨prime_spectrum.comap f p, hUV hpV⟩ with ⟨W, m, iWU, a, b, h_frac⟩, -- We claim that we can write our new section as the fraction `f a / f b` on the neighborhood -- `(comap f) ⁻¹ W ⊓ V` of `p`. refine ⟨opens.comap (comap_continuous f) W ⊓ V, ⟨m, hpV⟩, opens.inf_le_right _ _, f a, f b, _⟩, rintro ⟨q, ⟨hqW, hqV⟩⟩, specialize h_frac ⟨prime_spectrum.comap f q, hqW⟩, refine ⟨h_frac.1, _⟩, dsimp only [comap_fun], erw [← localization.local_ring_hom_to_map ((prime_spectrum.comap f q).as_ideal), ← ring_hom.map_mul, h_frac.2, localization.local_ring_hom_to_map], refl, end /-- For a ring homomorphism `f : R →+* S` and open sets `U` and `V` of the prime spectra of `R` and `S` such that `V ⊆ (comap f) ⁻¹ U`, the induced ring homomorphism from the structure sheaf of `R` at `U` to the structure sheaf of `S` at `V`. Explicitly, this map is given as follows: For a point `p : V`, if the section `s` evaluates on `p` to the fraction `a / b`, its image on `V` evaluates on `p` to the fraction `f(a) / f(b)`. -/ def comap (f : R →+* S) (U : opens (prime_spectrum.Top R)) (V : opens (prime_spectrum.Top S)) (hUV : V.1 ⊆ (prime_spectrum.comap f) ⁻¹' U.1) : (structure_sheaf R).presheaf.obj (op U) →+* (structure_sheaf S).presheaf.obj (op V) := { to_fun := λ s, ⟨comap_fun f U V hUV s.1, comap_fun_is_locally_fraction f U V hUV s.1 s.2⟩, map_one' := subtype.ext $ funext $ λ p, by { rw [subtype.coe_mk, subtype.val_eq_coe, comap_fun, (sections_subring R (op U)).coe_one, pi.one_apply, ring_hom.map_one], refl }, map_zero' := subtype.ext $ funext $ λ p, by { rw [subtype.coe_mk, subtype.val_eq_coe, comap_fun, (sections_subring R (op U)).coe_zero, pi.zero_apply, ring_hom.map_zero], refl }, map_add' := λ s t, subtype.ext $ funext $ λ p, by { rw [subtype.coe_mk, subtype.val_eq_coe, comap_fun, (sections_subring R (op U)).coe_add, pi.add_apply, ring_hom.map_add], refl }, map_mul' := λ s t, subtype.ext $ funext $ λ p, by { rw [subtype.coe_mk, subtype.val_eq_coe, comap_fun, (sections_subring R (op U)).coe_mul, pi.mul_apply, ring_hom.map_mul], refl } } @[simp] lemma comap_apply (f : R →+* S) (U : opens (prime_spectrum.Top R)) (V : opens (prime_spectrum.Top S)) (hUV : V.1 ⊆ (prime_spectrum.comap f) ⁻¹' U.1) (s : (structure_sheaf R).presheaf.obj (op U)) (p : V) : (comap f U V hUV s).1 p = localization.local_ring_hom (prime_spectrum.comap f p.1).as_ideal _ f rfl (s.1 ⟨(prime_spectrum.comap f p.1), hUV p.2⟩ : _) := rfl lemma comap_const (f : R →+* S) (U : opens (prime_spectrum.Top R)) (V : opens (prime_spectrum.Top S)) (hUV : V.1 ⊆ (prime_spectrum.comap f) ⁻¹' U.1) (a b : R) (hb : ∀ x : prime_spectrum R, x ∈ U → b ∈ x.as_ideal.prime_compl) : comap f U V hUV (const R a b U hb) = const S (f a) (f b) V (λ p hpV, hb (prime_spectrum.comap f p) (hUV hpV)) := subtype.eq $ funext $ λ p, begin rw [comap_apply, const_apply, const_apply], erw localization.local_ring_hom_mk', refl, end /-- For an inclusion `i : V ⟶ U` between open sets of the prime spectrum of `R`, the comap of the identity from OO_X(U) to OO_X(V) equals as the restriction map of the structure sheaf. This is a generalization of the fact that, for fixed `U`, the comap of the identity from OO_X(U) to OO_X(U) is the identity. -/ lemma comap_id_eq_map (U V : opens (prime_spectrum.Top R)) (iVU : V ⟶ U) : comap (ring_hom.id R) U V (λ p hpV, le_of_hom iVU $ by rwa prime_spectrum.comap_id) = (structure_sheaf R).presheaf.map iVU.op := ring_hom.ext $ λ s, subtype.eq $ funext $ λ p, begin rw comap_apply, -- Unfortunately, we cannot use `localization.local_ring_hom_id` here, because -- `prime_spectrum.comap (ring_hom.id R) p` is not *definitionally* equal to `p`. Instead, we use -- that we can write `s` as a fraction `a/b` in a small neighborhood around `p`. Since -- `prime_spectrum.comap (ring_hom.id R) p` equals `p`, it is also contained in the same -- neighborhood, hence `s` equals `a/b` there too. obtain ⟨W, hpW, iWU, h⟩ := s.2 (iVU p), obtain ⟨a, b, h'⟩ := h.eq_mk', obtain ⟨hb₁, s_eq₁⟩ := h' ⟨p, hpW⟩, obtain ⟨hb₂, s_eq₂⟩ := h' ⟨prime_spectrum.comap (ring_hom.id _) p.1, by rwa prime_spectrum.comap_id⟩, dsimp only at s_eq₁ s_eq₂, erw [s_eq₂, localization.local_ring_hom_mk', ← s_eq₁, ← res_apply], end /-- The comap of the identity is the identity. In this variant of the lemma, two open subsets `U` and `V` are given as arguments, together with a proof that `U = V`. This is be useful when `U` and `V` are not definitionally equal. -/ lemma comap_id (U V : opens (prime_spectrum.Top R)) (hUV : U = V) : comap (ring_hom.id R) U V (λ p hpV, by rwa [hUV, prime_spectrum.comap_id]) = eq_to_hom (show (structure_sheaf R).presheaf.obj (op U) = _, by rw hUV) := by erw [comap_id_eq_map U V (eq_to_hom hUV.symm), eq_to_hom_op, eq_to_hom_map] @[simp] lemma comap_id' (U : opens (prime_spectrum.Top R)) : comap (ring_hom.id R) U U (λ p hpU, by rwa prime_spectrum.comap_id) = ring_hom.id _ := by { rw comap_id U U rfl, refl } lemma comap_comp (f : R →+* S) (g : S →+* P) (U : opens (prime_spectrum.Top R)) (V : opens (prime_spectrum.Top S)) (W : opens (prime_spectrum.Top P)) (hUV : ∀ p ∈ V, prime_spectrum.comap f p ∈ U) (hVW : ∀ p ∈ W, prime_spectrum.comap g p ∈ V) : comap (g.comp f) U W (λ p hpW, hUV (prime_spectrum.comap g p) (hVW p hpW)) = (comap g V W hVW).comp (comap f U V hUV) := ring_hom.ext $ λ s, subtype.eq $ funext $ λ p, begin rw comap_apply, erw localization.local_ring_hom_comp _ (prime_spectrum.comap g p.1).as_ideal, -- refl works here, because `prime_spectrum.comap (g.comp f) p` is defeq to -- `prime_spectrum.comap f (prime_spectrum.comap g p)` refl, end @[elementwise, reassoc] lemma to_open_comp_comap (f : R →+* S) : to_open R ⊤ ≫ comap f ⊤ ⊤ (λ p hpV, trivial) = @category_theory.category_struct.comp _ _ (CommRing.of R) (CommRing.of S) _ f (to_open S ⊤) := ring_hom.ext $ λ s, subtype.eq $ funext $ λ p, begin simp_rw [comp_apply, comap_apply, subtype.val_eq_coe], erw localization.local_ring_hom_to_map, refl, end end comap end structure_sheaf end algebraic_geometry
db1db7f856c7d507c74f66d0cfb466f549abb77b
54c9ed381c63410c9b6af3b0a1722c41152f037f
/Lib4/PrePort.lean
7c3de66c200c018821f7dd2c26353dde4a40ae36
[ "Apache-2.0" ]
permissive
dselsam/binport
0233f1aa961a77c4fc96f0dccc780d958c5efc6c
aef374df0e169e2c3f1dc911de240c076315805c
refs/heads/master
1,687,453,448,108
1,627,483,296,000
1,627,483,296,000
333,825,622
0
0
null
null
null
null
UTF-8
Lean
false
false
183
lean
/- Copyright (c) 2020 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Daniel Selsam -/ import PrePort.Numbers
2249ff5c1494c327c4ebd2e92a6e7ecbe2d6aab1
280e37a1b98242171ef310909eae7a9811cc5303
/src/regex.lean
555479eae4c6ebda92eaddaf81de0a53d317f828
[]
no_license
foxthomson/regular
6655d19258f80272e0740f4f19152e9dc2514d3b
6c7c691eb226eb0e33a0995b027ba8641f1611bf
refs/heads/master
1,672,642,114,346
1,603,122,446,000
1,603,122,446,000
300,912,418
0
1
null
null
null
null
UTF-8
Lean
false
false
2,889
lean
import data.fintype.basic import data.finset.basic import NFA universe u inductive regex (α : Type u) : Type (u+1) | RZero : regex | RNull : regex | RChar : α → regex | RStar : regex → regex | RPlus : regex → regex → regex | RComp : regex → regex → regex namespace regex def match_null {α : Type u} : regex α → bool | RZero := ff | RNull := tt | (RChar _) := ff | (RStar M) := tt | (RPlus M N) := M.match_null || N.match_null | (RComp M N) := M.match_null && N.match_null def feed {α : Type u} [decidable_eq α] : regex α → α → regex α | RZero _ := RZero | RNull _ := RZero | (RChar a₁) a₂ := ite (a₁ = a₂) RNull RZero | (RStar M) a := RComp (feed M a) (RStar M) | (RPlus M N) a := RPlus (feed M a) (feed N a) | (RComp M N) a := ite M.match_null (RPlus (RComp (feed M a) N) (feed N a)) (RComp (feed M a) N) def bmatch {α : Type u} [decidable_eq α] : regex α → list α → bool | M [] := match_null M | M (a::as) := bmatch (M.feed a) as def ε_NFA_of_regex {α : Type u} [fintype α] [h : decidable_eq α] : regex α → ε_NFA α | RZero := { state := pempty, step := λ _ _, ∅, start := ∅, accept_states := ∅ } | RNull := { state := punit, step := λ _ _, ∅, start := {punit.star}, accept_states := {punit.star} } | (RChar a) := { state := bool, step := λ S b, b.cases_on' ∅ (λ b, ite S (ite (a = b) {ff} ∅) ∅), start := {tt}, accept_states := {ff} } | (RStar P) := begin let P := P.ε_NFA_of_regex, haveI := P.state_dec, exact { state := P.state, state_fintype := P.state_fintype, step := λ S b, b.cases_on' (ite (S ∈ P.accept_states) (P.start ∪ (P.step S b)) (P.step S none)) (λ b, P.step S b), start := P.start, accept_states := P.accept_states } end | (RPlus P Q) := begin let P := P.ε_NFA_of_regex, let Q := Q.ε_NFA_of_regex, haveI := P.state_fintype, haveI := Q.state_fintype, haveI := P.state_dec, haveI := Q.state_dec, exact { state := P.state × Q.state, step := λ S b, finset.product (P.step S.1 b) (Q.step S.2 b), start := finset.product P.start Q.start, accept_states := finset.product P.start finset.univ ∪ finset.product finset.univ Q.start } end | (RComp P Q) := begin let P := P.ε_NFA_of_regex, let Q := Q.ε_NFA_of_regex, haveI := P.state_fintype, haveI := Q.state_fintype, haveI := P.state_dec, haveI := Q.state_dec, exact { state := P.state ⊕ Q.state, step := λ S b, sum.elim (λ S₁, ite (S₁ ∈ P.accept_states) (finset.image sum.inr Q.start ∪ finset.image sum.inl (P.step S₁ b)) (finset.image sum.inl (P.step S₁ b))) (λ S₂, finset.image sum.inr (Q.step S₂ b)) S, start := finset.image sum.inl P.start, accept_states := finset.image sum.inr Q.accept_states } end end regex
ca9ff6389cd09dadaa8caa6a713ce1b070157197
5719a16e23dfc08cdea7a5bf035b81690f307965
/src/Init/Lean/Elab/Tactic/Basic.lean
4f7b361dbd12a88ceb06b6e10eff22ababe3fd0f
[ "Apache-2.0" ]
permissive
postmasters/lean4
488b03969a371e1507e1e8a4df9ebf63c7cbe7ac
f3976fc53a883ac7606fc59357d43f4b51016ca7
refs/heads/master
1,655,582,707,480
1,588,682,595,000
1,588,682,595,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
17,742
lean
/- Copyright (c) 2020 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Sebastian Ullrich -/ prelude import Init.Lean.Util.CollectMVars import Init.Lean.Meta.Tactic.Assumption import Init.Lean.Meta.Tactic.Intro import Init.Lean.Meta.Tactic.Clear import Init.Lean.Meta.Tactic.Revert import Init.Lean.Meta.Tactic.Subst import Init.Lean.Elab.Util import Init.Lean.Elab.Term namespace Lean namespace Elab def goalsToMessageData (goals : List MVarId) : MessageData := MessageData.joinSep (goals.map $ MessageData.ofGoal) (Format.line ++ Format.line) def Term.reportUnsolvedGoals (ref : Syntax) (goals : List MVarId) : TermElabM Unit := let tailRef := ref.getTailWithInfo.getD ref; Term.throwError tailRef $ "unsolved goals" ++ Format.line ++ goalsToMessageData goals namespace Tactic structure Context extends toTermCtx : Term.Context := (main : MVarId) (ref : Syntax) structure State extends toTermState : Term.State := (goals : List MVarId) instance State.inhabited : Inhabited State := ⟨{ goals := [], toTermState := arbitrary _ }⟩ structure BacktrackableState := (env : Environment) (mctx : MetavarContext) (goals : List MVarId) abbrev Exception := Elab.Exception abbrev TacticM := ReaderT Context (EStateM Exception State) abbrev Tactic := Syntax → TacticM Unit protected def save (s : State) : BacktrackableState := { .. s } protected def restore (s : State) (bs : BacktrackableState) : State := { env := bs.env, mctx := bs.mctx, goals := bs.goals, .. s } instance : EStateM.Backtrackable BacktrackableState State := { save := Tactic.save, restore := Tactic.restore } def liftTermElabM {α} (x : TermElabM α) : TacticM α := fun ctx s => match x ctx.toTermCtx s.toTermState with | EStateM.Result.ok a newS => EStateM.Result.ok a { toTermState := newS, .. s } | EStateM.Result.error (Term.Exception.ex ex) newS => EStateM.Result.error ex { toTermState := newS, .. s } | EStateM.Result.error Term.Exception.postpone _ => unreachable! def liftMetaM {α} (ref : Syntax) (x : MetaM α) : TacticM α := liftTermElabM $ Term.liftMetaM ref x def getEnv : TacticM Environment := do s ← get; pure s.env def getMCtx : TacticM MetavarContext := do s ← get; pure s.mctx @[inline] def modifyMCtx (f : MetavarContext → MetavarContext) : TacticM Unit := modify $ fun s => { mctx := f s.mctx, .. s } def getLCtx : TacticM LocalContext := do ctx ← read; pure ctx.lctx def getLocalInsts : TacticM LocalInstances := do ctx ← read; pure ctx.localInstances def getOptions : TacticM Options := do ctx ← read; pure ctx.config.opts def getMVarDecl (mvarId : MVarId) : TacticM MetavarDecl := do mctx ← getMCtx; pure $ mctx.getDecl mvarId def instantiateMVars (ref : Syntax) (e : Expr) : TacticM Expr := liftTermElabM $ Term.instantiateMVars ref e def addContext (msg : MessageData) : TacticM MessageData := liftTermElabM $ Term.addContext msg def isExprMVarAssigned (mvarId : MVarId) : TacticM Bool := liftTermElabM $ Term.isExprMVarAssigned mvarId def assignExprMVar (mvarId : MVarId) (val : Expr) : TacticM Unit := liftTermElabM $ Term.assignExprMVar mvarId val def ensureHasType (ref : Syntax) (expectedType? : Option Expr) (e : Expr) : TacticM Expr := liftTermElabM $ Term.ensureHasType ref expectedType? e def reportUnsolvedGoals (ref : Syntax) (goals : List MVarId) : TacticM Unit := liftTermElabM $ Term.reportUnsolvedGoals ref goals def inferType (ref : Syntax) (e : Expr) : TacticM Expr := liftTermElabM $ Term.inferType ref e def whnf (ref : Syntax) (e : Expr) : TacticM Expr := liftTermElabM $ Term.whnf ref e def whnfCore (ref : Syntax) (e : Expr) : TacticM Expr := liftTermElabM $ Term.whnfCore ref e def unfoldDefinition? (ref : Syntax) (e : Expr) : TacticM (Option Expr) := liftTermElabM $ Term.unfoldDefinition? ref e def resolveGlobalName (n : Name) : TacticM (List (Name × List String)) := liftTermElabM $ Term.resolveGlobalName n /-- Collect unassigned metavariables -/ def collectMVars (ref : Syntax) (e : Expr) : TacticM (List MVarId) := do e ← instantiateMVars ref e; let s := Lean.collectMVars {} e; pure s.result.toList instance monadLog : MonadLog TacticM := { 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 } } def throwError {α} (ref : Syntax) (msgData : MessageData) : TacticM α := do ref ← if ref.getPos.isNone then do ctx ← read; pure ctx.ref else pure ref; liftTermElabM $ Term.throwError ref msgData def throwUnsupportedSyntax {α} : TacticM α := liftTermElabM $ Term.throwUnsupportedSyntax @[inline] def withIncRecDepth {α} (ref : Syntax) (x : TacticM α) : TacticM α := do ctx ← read; when (ctx.currRecDepth == ctx.maxRecDepth) $ throwError ref maxRecDepthErrorMessage; adaptReader (fun (ctx : Context) => { currRecDepth := ctx.currRecDepth + 1, .. ctx }) x protected def getCurrMacroScope : TacticM MacroScope := do ctx ← read; pure ctx.currMacroScope protected def getMainModule : TacticM Name := do env ← getEnv; pure env.mainModule @[inline] protected def withFreshMacroScope {α} (x : TacticM α) : TacticM α := 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 TacticM := { getCurrMacroScope := Tactic.getCurrMacroScope, getMainModule := Tactic.getMainModule, withFreshMacroScope := @Tactic.withFreshMacroScope } unsafe def mkTacticAttribute : IO (KeyedDeclsAttribute Tactic) := mkElabAttribute Tactic `Lean.Elab.Tactic.tacticElabAttribute `builtinTactic `tactic `Lean.Parser.Tactic `Lean.Elab.Tactic.Tactic "tactic" @[init mkTacticAttribute] constant tacticElabAttribute : KeyedDeclsAttribute Tactic := arbitrary _ def logTrace (cls : Name) (ref : Syntax) (msg : MessageData) : TacticM Unit := liftTermElabM $ Term.logTrace cls ref msg @[inline] def trace (cls : Name) (ref : Syntax) (msg : Unit → MessageData) : TacticM Unit := liftTermElabM $ Term.trace cls ref msg @[inline] def traceAtCmdPos (cls : Name) (msg : Unit → MessageData) : TacticM Unit := liftTermElabM $ Term.traceAtCmdPos cls msg def dbgTrace {α} [HasToString α] (a : α) : TacticM Unit :=_root_.dbgTrace (toString a) $ fun _ => pure () private def evalTacticUsing (s : State) (stx : Syntax) : List Tactic → TacticM Unit | [] => do let refFmt := stx.prettyPrint; throwError stx ("unexpected syntax" ++ MessageData.nest 2 (Format.line ++ refFmt)) | (evalFn::evalFns) => catch (evalFn stx) (fun ex => match ex with | Exception.error _ => match evalFns with | [] => throw ex | _ => do set s; evalTacticUsing evalFns | Exception.unsupportedSyntax => do set s; evalTacticUsing evalFns) /- Elaborate `x` with `stx` on the macro stack -/ @[inline] def withMacroExpansion {α} (beforeStx afterStx : Syntax) (x : TacticM α) : TacticM α := adaptReader (fun (ctx : Context) => { macroStack := { before := beforeStx, after := afterStx } :: ctx.macroStack, .. ctx }) x instance : MonadMacroAdapter TacticM := { getEnv := getEnv, getCurrMacroScope := getCurrMacroScope, getNextMacroScope := do s ← get; pure s.nextMacroScope, setNextMacroScope := fun next => modify $ fun s => { nextMacroScope := next, .. s }, throwError := @throwError, throwUnsupportedSyntax := @throwUnsupportedSyntax } @[specialize] private def expandTacticMacroFns (evalTactic : Syntax → TacticM Unit) (stx : Syntax) : List Macro → TacticM Unit | [] => throwError stx ("tactic '" ++ toString stx.getKind ++ "' has not been implemented") | m::ms => do scp ← getCurrMacroScope; catch (do stx' ← adaptMacro m stx; evalTactic stx') (fun ex => match ms with | [] => throw ex | _ => expandTacticMacroFns ms) @[inline] def expandTacticMacro (evalTactic : Syntax → TacticM Unit) (stx : Syntax) : TacticM Unit := do env ← getEnv; let k := stx.getKind; let table := (macroAttribute.ext.getState env).table; let macroFns := (table.find? k).getD []; expandTacticMacroFns evalTactic stx macroFns partial def evalTactic : Syntax → TacticM Unit | stx => withIncRecDepth stx $ withFreshMacroScope $ match stx with | Syntax.node k args => if k == nullKind then -- list of tactics separated by `;` => evaluate in order -- Syntax quotations can return multiple ones stx.forSepArgsM evalTactic else do trace `Elab.step stx $ fun _ => stx; s ← get; let table := (tacticElabAttribute.ext.getState s.env).table; let k := stx.getKind; match table.find? k with | some evalFns => evalTacticUsing s stx evalFns | none => expandTacticMacro evalTactic stx | _ => throwError stx "unexpected command" /-- Adapt a syntax transformation to a regular tactic evaluator. -/ def adaptExpander (exp : Syntax → TacticM Syntax) : Tactic := fun stx => do stx' ← exp stx; withMacroExpansion stx stx' $ evalTactic stx' @[inline] def withLCtx {α} (lctx : LocalContext) (localInsts : LocalInstances) (x : TacticM α) : TacticM α := adaptReader (fun (ctx : Context) => { lctx := lctx, localInstances := localInsts, .. ctx }) x def resetSynthInstanceCache : TacticM Unit := liftTermElabM Term.resetSynthInstanceCache @[inline] def resettingSynthInstanceCache {α} (x : TacticM α) : TacticM α := 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 : TacticM α) : TacticM α := if b then resettingSynthInstanceCache x else x def withMVarContext {α} (mvarId : MVarId) (x : TacticM α) : TacticM α := do mvarDecl ← getMVarDecl mvarId; ctx ← read; let needReset := ctx.localInstances == mvarDecl.localInstances; withLCtx mvarDecl.lctx mvarDecl.localInstances $ resettingSynthInstanceCacheWhen needReset x def getGoals : TacticM (List MVarId) := do s ← get; pure s.goals def setGoals (gs : List MVarId) : TacticM Unit := modify $ fun s => { goals := gs, .. s } def appendGoals (gs : List MVarId) : TacticM Unit := modify $ fun s => { goals := s.goals ++ gs, .. s } def pruneSolvedGoals : TacticM Unit := do gs ← getGoals; gs ← gs.filterM $ fun g => not <$> isExprMVarAssigned g; setGoals gs def getUnsolvedGoals : TacticM (List MVarId) := do pruneSolvedGoals; getGoals def getMainGoal (ref : Syntax) : TacticM (MVarId × List MVarId) := do (g::gs) ← getUnsolvedGoals | throwError ref "no goals to be solved"; pure (g, gs) def ensureHasNoMVars (ref : Syntax) (e : Expr) : TacticM Unit := do e ← instantiateMVars ref e; when e.hasMVar $ throwError ref ("tactic failed, resulting expression contains metavariables" ++ indentExpr e) def withMainMVarContext {α} (ref : Syntax) (x : TacticM α) : TacticM α := do (mvarId, _) ← getMainGoal ref; withMVarContext mvarId x @[inline] def liftMetaMAtMain {α} (ref : Syntax) (x : MVarId → MetaM α) : TacticM α := do (g, _) ← getMainGoal ref; withMVarContext g $ liftMetaM ref $ x g @[inline] def liftMetaTacticAux {α} (ref : Syntax) (tactic : MVarId → MetaM (α × List MVarId)) : TacticM α := do (g, gs) ← getMainGoal ref; withMVarContext g $ do (a, gs') ← liftMetaM ref $ tactic g; setGoals (gs' ++ gs); pure a @[inline] def liftMetaTactic (ref : Syntax) (tactic : MVarId → MetaM (List MVarId)) : TacticM Unit := liftMetaTacticAux ref (fun mvarId => do gs ← tactic mvarId; pure ((), gs)) def done (ref : Syntax) : TacticM Unit := do gs ← getUnsolvedGoals; unless gs.isEmpty $ reportUnsolvedGoals ref gs def focusAux {α} (ref : Syntax) (tactic : TacticM α) : TacticM α := do (g, gs) ← getMainGoal ref; setGoals [g]; a ← tactic; gs' ← getGoals; setGoals (gs' ++ gs); pure a def focus {α} (ref : Syntax) (tactic : TacticM α) : TacticM α := focusAux ref (do a ← tactic; done ref; pure a) /-- Use `parentTag` to tag untagged goals at `newGoals`. If there are multiple new goals, they are named using `<parentTag>.<newSuffix>_<idx>` where `idx > 0`. If there is only one new goal, then we just use `parentTag` -/ def tagUntaggedGoals (parentTag : Name) (newSuffix : Name) (newGoals : List MVarId) : TacticM Unit := do mctx ← getMCtx; match newGoals with | [g] => modifyMCtx $ fun mctx => if mctx.isAnonymousMVar g then mctx.renameMVar g parentTag else mctx | _ => modifyMCtx $ fun mctx => let (mctx, _) := newGoals.foldl (fun (acc : MetavarContext × Nat) (g : MVarId) => let (mctx, idx) := acc; if mctx.isAnonymousMVar g then (mctx.renameMVar g (parentTag ++ newSuffix.appendIndexAfter idx), idx+1) else acc) (mctx, 1); mctx @[builtinTactic seq] def evalSeq : Tactic := fun stx => (stx.getArg 0).forSepArgsM evalTactic partial def evalChoiceAux (tactics : Array Syntax) : Nat → TacticM Unit | i => if h : i < tactics.size then let tactic := tactics.get ⟨i, h⟩; catch (evalTactic tactic) (fun ex => match ex with | Exception.unsupportedSyntax => evalChoiceAux (i+1) | _ => throw ex) else throwUnsupportedSyntax @[builtinTactic choice] def evalChoice : Tactic := fun stx => evalChoiceAux stx.getArgs 0 @[builtinTactic skip] def evalSkip : Tactic := fun stx => pure () @[builtinTactic failIfSuccess] def evalFailIfSuccess : Tactic := fun stx => let tactic := stx.getArg 1; whenM (catch (do evalTactic tactic; pure true) (fun _ => pure false)) (throwError stx ("tactic succeeded")) @[builtinTactic traceState] def evalTraceState : Tactic := fun stx => do gs ← getUnsolvedGoals; logInfo stx (goalsToMessageData gs) @[builtinTactic «assumption»] def evalAssumption : Tactic := fun stx => liftMetaTactic stx $ fun mvarId => do Meta.assumption mvarId; pure [] @[builtinTactic «intro»] def evalIntro : Tactic := fun stx => match_syntax stx with | `(tactic| intro) => liftMetaTactic stx $ fun mvarId => do (_, mvarId) ← Meta.intro1 mvarId; pure [mvarId] | `(tactic| intro $h) => liftMetaTactic stx $ fun mvarId => do (_, mvarId) ← Meta.intro mvarId h.getId; pure [mvarId] | _ => throwUnsupportedSyntax private def getIntrosSize : Expr → Nat | Expr.forallE _ _ b _ => getIntrosSize b + 1 | Expr.letE _ _ _ b _ => getIntrosSize b + 1 | _ => 0 @[builtinTactic «intros»] def evalIntros : Tactic := fun stx => match_syntax stx with | `(tactic| intros) => liftMetaTactic stx $ fun mvarId => do type ← Meta.getMVarType mvarId; type ← Meta.instantiateMVars type; let n := getIntrosSize type; (_, mvarId) ← Meta.introN mvarId n; pure [mvarId] | `(tactic| intros $ids*) => liftMetaTactic stx $ fun mvarId => do (_, mvarId) ← Meta.introN mvarId ids.size (ids.map Syntax.getId).toList; pure [mvarId] | _ => throwUnsupportedSyntax def getFVarId (id : Syntax) : TacticM FVarId := do fvar? ← liftTermElabM $ Term.isLocalTermId? id true; match fvar? with | some fvar => pure fvar.fvarId! | none => throwError id ("unknown variable '" ++ toString id.getId ++ "'") def getFVarIds (ids : Array Syntax) : TacticM (Array FVarId) := ids.mapM getFVarId @[builtinTactic «revert»] def evalRevert : Tactic := fun stx => match_syntax stx with | `(tactic| revert $hs*) => do (g, gs) ← getMainGoal stx; withMVarContext g $ do fvarIds ← getFVarIds hs; (_, g) ← liftMetaM stx $ Meta.revert g fvarIds; setGoals (g :: gs) | _ => throwUnsupportedSyntax def forEachVar (ref : Syntax) (hs : Array Syntax) (tac : MVarId → FVarId → MetaM MVarId) : TacticM Unit := hs.forM $ fun h => do (g, gs) ← getMainGoal ref; withMVarContext g $ do fvarId ← getFVarId h; g ← liftMetaM ref $ tac g fvarId; setGoals (g :: gs) @[builtinTactic «clear»] def evalClear : Tactic := fun stx => match_syntax stx with | `(tactic| clear $hs*) => forEachVar stx hs Meta.clear | _ => throwUnsupportedSyntax @[builtinTactic «subst»] def evalSubst : Tactic := fun stx => match_syntax stx with | `(tactic| subst $hs*) => forEachVar stx hs Meta.subst | _ => throwUnsupportedSyntax @[builtinTactic paren] def evalParen : Tactic := fun stx => evalTactic (stx.getArg 1) @[builtinTactic nestedTacticBlock] def evalNestedTacticBlock : Tactic := fun stx => focus stx (evalTactic (stx.getArg 1)) @[builtinTactic nestedTacticBlockCurly] def evalNestedTacticBlockCurly : Tactic := evalNestedTacticBlock @[builtinTactic «case»] def evalCase : Tactic := fun stx => match_syntax stx with | `(tactic| case $tag $tac) => do let tag := tag.getId; gs ← getUnsolvedGoals; some g ← gs.findM? (fun g => do mvarDecl ← getMVarDecl g; pure $ tag.isSuffixOf mvarDecl.userName) | throwError stx "tag not found"; let gs := gs.erase g; setGoals [g]; evalTactic tac; done stx; setGoals gs | _ => throwUnsupportedSyntax @[builtinTactic «orelse»] def evalOrelse : Tactic := fun stx => match_syntax stx with | `(tactic| $tac1 <|> $tac2) => evalTactic tac1 <|> evalTactic tac2 | _ => throwUnsupportedSyntax @[init] private def regTraceClasses : IO Unit := do registerTraceClass `Elab.tactic; pure () end Tactic end Elab end Lean
de40109c0367dae4ab2448ca7320f8bccd2674cc
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/algebra/ring/basic.lean
db475cd2577069c282512f7277c6155133ad17fd
[]
no_license
AurelienSaue/Mathlib4_auto
f538cfd0980f65a6361eadea39e6fc639e9dae14
590df64109b08190abe22358fabc3eae000943f2
refs/heads/master
1,683,906,849,776
1,622,564,669,000
1,622,564,669,000
371,723,747
0
0
null
null
null
null
UTF-8
Lean
false
false
46,571
lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Amelia Livingston, Yury Kudryashov, Neil Strickland -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.algebra.divisibility import Mathlib.data.set.basic import Mathlib.PostPort universes u_1 l x u v u_2 w namespace Mathlib /-! # Properties and homomorphisms of semirings and rings This file proves simple properties of semirings, rings and domains and their unit groups. It also defines bundled homomorphisms of semirings and rings. As with monoid and groups, we use the same structure `ring_hom a β`, a.k.a. `α →+* β`, for both homomorphism types. The unbundled homomorphisms are defined in `deprecated/ring`. They are deprecated and the plan is to slowly remove them from mathlib. ## Main definitions ring_hom, nonzero, domain, integral_domain ## Notations →+* for bundled ring homs (also use for semiring homs) ## Implementation notes There's a coercion from bundled homs to fun, and the canonical notation is to use the bundled hom as a function via this coercion. There is no `semiring_hom` -- the idea is that `ring_hom` is used. The constructor for a `ring_hom` between semirings needs a proof of `map_zero`, `map_one` and `map_add` as well as `map_mul`; a separate constructor `ring_hom.mk'` will construct ring homs between rings from monoid homs given only a proof that addition is preserved. ## Tags `ring_hom`, `semiring_hom`, `semiring`, `comm_semiring`, `ring`, `comm_ring`, `domain`, `integral_domain`, `nonzero`, `units` -/ /-! ### `distrib` class -/ /-- A typeclass stating that multiplication is left and right distributive over addition. -/ class distrib (R : Type u_1) extends Mul R, Add R where left_distrib : ∀ (a b c : R), a * (b + c) = a * b + a * c right_distrib : ∀ (a b c : R), (a + b) * c = a * c + b * c theorem left_distrib {R : Type x} [distrib R] (a : R) (b : R) (c : R) : a * (b + c) = a * b + a * c := distrib.left_distrib a b c theorem mul_add {R : Type x} [distrib R] (a : R) (b : R) (c : R) : a * (b + c) = a * b + a * c := left_distrib theorem right_distrib {R : Type x} [distrib R] (a : R) (b : R) (c : R) : (a + b) * c = a * c + b * c := distrib.right_distrib a b c theorem add_mul {R : Type x} [distrib R] (a : R) (b : R) (c : R) : (a + b) * c = a * c + b * c := right_distrib /-- Pullback a `distrib` instance along an injective function. -/ protected def function.injective.distrib {R : Type x} {S : Type u_1} [Mul R] [Add R] [distrib S] (f : R → S) (hf : function.injective f) (add : ∀ (x y : R), f (x + y) = f x + f y) (mul : ∀ (x y : R), f (x * y) = f x * f y) : distrib R := distrib.mk Mul.mul Add.add sorry sorry /-- Pushforward a `distrib` instance along a surjective function. -/ protected def function.surjective.distrib {R : Type x} {S : Type u_1} [distrib R] [Add S] [Mul S] (f : R → S) (hf : function.surjective f) (add : ∀ (x y : R), f (x + y) = f x + f y) (mul : ∀ (x y : R), f (x * y) = f x * f y) : distrib S := distrib.mk Mul.mul Add.add sorry sorry /-! ### Semirings -/ /-- A semiring is a type with the following structures: additive commutative monoid (`add_comm_monoid`), multiplicative monoid (`monoid`), distributive laws (`distrib`), and multiplication by zero law (`mul_zero_class`). The actual definition extends `monoid_with_zero` instead of `monoid` and `mul_zero_class`. -/ class semiring (α : Type u) extends monoid_with_zero α, distrib α, add_comm_monoid α where /-- Pullback a `semiring` instance along an injective function. -/ protected def function.injective.semiring {α : Type u} {β : Type v} [semiring α] [HasZero β] [HasOne β] [Add β] [Mul β] (f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ (x y : β), f (x + y) = f x + f y) (mul : ∀ (x y : β), f (x * y) = f x * f y) : semiring β := semiring.mk add_comm_monoid.add sorry monoid_with_zero.zero sorry sorry sorry monoid_with_zero.mul sorry monoid_with_zero.one sorry sorry sorry sorry sorry sorry /-- Pullback a `semiring` instance along an injective function. -/ protected def function.surjective.semiring {α : Type u} {β : Type v} [semiring α] [HasZero β] [HasOne β] [Add β] [Mul β] (f : α → β) (hf : function.surjective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ (x y : α), f (x + y) = f x + f y) (mul : ∀ (x y : α), f (x * y) = f x * f y) : semiring β := semiring.mk add_comm_monoid.add sorry monoid_with_zero.zero sorry sorry sorry monoid_with_zero.mul sorry monoid_with_zero.one sorry sorry sorry sorry sorry sorry theorem one_add_one_eq_two {α : Type u} [semiring α] : 1 + 1 = bit0 1 := sorry theorem two_mul {α : Type u} [semiring α] (n : α) : bit0 1 * n = n + n := sorry theorem distrib_three_right {α : Type u} [semiring α] (a : α) (b : α) (c : α) (d : α) : (a + b + c) * d = a * d + b * d + c * d := sorry theorem mul_two {α : Type u} [semiring α] (n : α) : n * bit0 1 = n + n := sorry theorem bit0_eq_two_mul {α : Type u} [semiring α] (n : α) : bit0 n = bit0 1 * n := Eq.symm (two_mul n) theorem add_ite {α : Type u_1} [Add α] (P : Prop) [Decidable P] (a : α) (b : α) (c : α) : a + ite P b c = ite P (a + b) (a + c) := sorry @[simp] theorem ite_mul {α : Type u_1} [Mul α] (P : Prop) [Decidable P] (a : α) (b : α) (c : α) : ite P a b * c = ite P (a * c) (b * c) := sorry -- We make `mul_ite` and `ite_mul` simp lemmas, -- but not `add_ite` or `ite_add`. -- The problem we're trying to avoid is dealing with -- summations of the form `∑ x in s, (f x + ite P 1 0)`, -- in which `add_ite` followed by `sum_ite` would needlessly slice up -- the `f x` terms according to whether `P` holds at `x`. -- There doesn't appear to be a corresponding difficulty so far with -- `mul_ite` and `ite_mul`. @[simp] theorem mul_boole {α : Type u_1} [semiring α] (P : Prop) [Decidable P] (a : α) : a * ite P 1 0 = ite P a 0 := sorry @[simp] theorem boole_mul {α : Type u_1} [semiring α] (P : Prop) [Decidable P] (a : α) : ite P 1 0 * a = ite P a 0 := sorry theorem ite_mul_zero_left {α : Type u_1} [mul_zero_class α] (P : Prop) [Decidable P] (a : α) (b : α) : ite P (a * b) 0 = ite P a 0 * b := sorry theorem ite_mul_zero_right {α : Type u_1} [mul_zero_class α] (P : Prop) [Decidable P] (a : α) (b : α) : ite P (a * b) 0 = a * ite P b 0 := sorry /-- An element `a` of a semiring is even if there exists `k` such `a = 2*k`. -/ def even {α : Type u} [semiring α] (a : α) := ∃ (k : α), a = bit0 1 * k theorem even_iff_two_dvd {α : Type u} [semiring α] {a : α} : even a ↔ bit0 1 ∣ a := iff.rfl /-- An element `a` of a semiring is odd if there exists `k` such `a = 2*k + 1`. -/ def odd {α : Type u} [semiring α] (a : α) := ∃ (k : α), a = bit0 1 * k + 1 theorem dvd_add {α : Type u} [semiring α] {a : α} {b : α} {c : α} (h₁ : a ∣ b) (h₂ : a ∣ c) : a ∣ b + c := sorry namespace add_monoid_hom /-- Left multiplication by an element of a (semi)ring is an `add_monoid_hom` -/ def mul_left {R : Type u_1} [semiring R] (r : R) : R →+ R := mk (Mul.mul r) sorry sorry @[simp] theorem coe_mul_left {R : Type u_1} [semiring R] (r : R) : ⇑(mul_left r) = Mul.mul r := rfl /-- Right multiplication by an element of a (semi)ring is an `add_monoid_hom` -/ def mul_right {R : Type u_1} [semiring R] (r : R) : R →+ R := mk (fun (a : R) => a * r) sorry sorry @[simp] theorem coe_mul_right {R : Type u_1} [semiring R] (r : R) : ⇑(mul_right r) = fun (_x : R) => _x * r := rfl theorem mul_right_apply {R : Type u_1} [semiring R] (a : R) (r : R) : coe_fn (mul_right r) a = a * r := rfl end add_monoid_hom /-- Bundled semiring homomorphisms; use this for bundled ring homomorphisms too. This extends from both `monoid_hom` and `monoid_with_zero_hom` in order to put the fields in a sensible order, even though `monoid_with_zero_hom` already extends `monoid_hom`. -/ structure ring_hom (α : Type u_1) (β : Type u_2) [semiring α] [semiring β] extends monoid_with_zero_hom α β, α →* β, α →+ β where infixr:25 " →+* " => Mathlib.ring_hom /-- Reinterpret a ring homomorphism `f : R →+* S` as a `monoid_with_zero_hom R S`. The `simp`-normal form is `(f : monoid_with_zero_hom R S)`. -/ /-- Reinterpret a ring homomorphism `f : R →+* S` as a monoid homomorphism `R →* S`. The `simp`-normal form is `(f : R →* S)`. -/ /-- Reinterpret a ring homomorphism `f : R →+* S` as an additive monoid homomorphism `R →+ S`. The `simp`-normal form is `(f : R →+ S)`. -/ namespace ring_hom /-! Throughout this section, some `semiring` arguments are specified with `{}` instead of `[]`. See note [implicit instance arguments]. -/ protected instance has_coe_to_fun {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} : has_coe_to_fun (α →+* β) := has_coe_to_fun.mk (fun (x : α →+* β) => α → β) to_fun @[simp] theorem to_fun_eq_coe {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β) : to_fun f = ⇑f := rfl @[simp] theorem coe_mk {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α → β) (h₁ : f 1 = 1) (h₂ : ∀ (x y : α), f (x * y) = f x * f y) (h₃ : f 0 = 0) (h₄ : ∀ (x y : α), f (x + y) = f x + f y) : ⇑(mk f h₁ h₂ h₃ h₄) = f := rfl protected instance has_coe_monoid_hom {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} : has_coe (α →+* β) (α →* β) := has_coe.mk to_monoid_hom @[simp] theorem coe_monoid_hom {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β) : ⇑↑f = ⇑f := rfl @[simp] theorem to_monoid_hom_eq_coe {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β) : to_monoid_hom f = ↑f := rfl @[simp] theorem coe_monoid_hom_mk {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α → β) (h₁ : f 1 = 1) (h₂ : ∀ (x y : α), f (x * y) = f x * f y) (h₃ : f 0 = 0) (h₄ : ∀ (x y : α), f (x + y) = f x + f y) : ↑(mk f h₁ h₂ h₃ h₄) = monoid_hom.mk f h₁ h₂ := rfl protected instance has_coe_add_monoid_hom {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} : has_coe (α →+* β) (α →+ β) := has_coe.mk to_add_monoid_hom @[simp] theorem coe_add_monoid_hom {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β) : ⇑↑f = ⇑f := rfl @[simp] theorem to_add_monoid_hom_eq_coe {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β) : to_add_monoid_hom f = ↑f := rfl @[simp] theorem coe_add_monoid_hom_mk {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α → β) (h₁ : f 1 = 1) (h₂ : ∀ (x y : α), f (x * y) = f x * f y) (h₃ : f 0 = 0) (h₄ : ∀ (x y : α), f (x + y) = f x + f y) : ↑(mk f h₁ h₂ h₃ h₄) = add_monoid_hom.mk f h₃ h₄ := rfl theorem congr_fun {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} {f : α →+* β} {g : α →+* β} (h : f = g) (x : α) : coe_fn f x = coe_fn g x := congr_arg (fun (h : α →+* β) => coe_fn h x) h theorem congr_arg {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β) {x : α} {y : α} (h : x = y) : coe_fn f x = coe_fn f y := congr_arg (fun (x : α) => coe_fn f x) h theorem coe_inj {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} {f : α →+* β} {g : α →+* β} (h : ⇑f = ⇑g) : f = g := sorry theorem ext {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} {f : α →+* β} {g : α →+* β} (h : ∀ (x : α), coe_fn f x = coe_fn g x) : f = g := coe_inj (funext h) theorem ext_iff {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} {f : α →+* β} {g : α →+* β} : f = g ↔ ∀ (x : α), coe_fn f x = coe_fn g x := { mp := fun (h : f = g) (x : α) => h ▸ rfl, mpr := fun (h : ∀ (x : α), coe_fn f x = coe_fn g x) => ext h } @[simp] theorem mk_coe {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β) (h₁ : coe_fn f 1 = 1) (h₂ : ∀ (x y : α), coe_fn f (x * y) = coe_fn f x * coe_fn f y) (h₃ : coe_fn f 0 = 0) (h₄ : ∀ (x y : α), coe_fn f (x + y) = coe_fn f x + coe_fn f y) : mk (⇑f) h₁ h₂ h₃ h₄ = f := ext fun (_x : α) => rfl theorem coe_add_monoid_hom_injective {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} : function.injective coe := fun (f g : α →+* β) (h : ↑f = ↑g) => ext fun (x : α) => add_monoid_hom.congr_fun h x theorem coe_monoid_hom_injective {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} : function.injective coe := fun (f g : α →+* β) (h : ↑f = ↑g) => ext fun (x : α) => monoid_hom.congr_fun h x /-- Ring homomorphisms map zero to zero. -/ @[simp] theorem map_zero {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β) : coe_fn f 0 = 0 := map_zero' f /-- Ring homomorphisms map one to one. -/ @[simp] theorem map_one {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β) : coe_fn f 1 = 1 := map_one' f /-- Ring homomorphisms preserve addition. -/ @[simp] theorem map_add {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β) (a : α) (b : α) : coe_fn f (a + b) = coe_fn f a + coe_fn f b := map_add' f a b /-- Ring homomorphisms preserve multiplication. -/ @[simp] theorem map_mul {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β) (a : α) (b : α) : coe_fn f (a * b) = coe_fn f a * coe_fn f b := map_mul' f a b /-- Ring homomorphisms preserve `bit0`. -/ @[simp] theorem map_bit0 {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β) (a : α) : coe_fn f (bit0 a) = bit0 (coe_fn f a) := map_add f a a /-- Ring homomorphisms preserve `bit1`. -/ @[simp] theorem map_bit1 {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β) (a : α) : coe_fn f (bit1 a) = bit1 (coe_fn f a) := sorry /-- `f : R →+* S` has a trivial codomain iff `f 1 = 0`. -/ theorem codomain_trivial_iff_map_one_eq_zero {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β) : 0 = 1 ↔ coe_fn f 1 = 0 := eq.mpr (id (Eq._oldrec (Eq.refl (0 = 1 ↔ coe_fn f 1 = 0)) (map_one f))) (eq.mpr (id (Eq._oldrec (Eq.refl (0 = 1 ↔ 1 = 0)) (propext eq_comm))) (iff.refl (1 = 0))) /-- `f : R →+* S` has a trivial codomain iff it has a trivial range. -/ theorem codomain_trivial_iff_range_trivial {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β) : 0 = 1 ↔ ∀ (x : α), coe_fn f x = 0 := sorry /-- `f : R →+* S` has a trivial codomain iff its range is `{0}`. -/ theorem codomain_trivial_iff_range_eq_singleton_zero {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β) : 0 = 1 ↔ set.range ⇑f = singleton 0 := sorry /-- `f : R →+* S` doesn't map `1` to `0` if `S` is nontrivial -/ theorem map_one_ne_zero {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β) [nontrivial β] : coe_fn f 1 ≠ 0 := mt (iff.mpr (codomain_trivial_iff_map_one_eq_zero f)) zero_ne_one /-- If there is a homomorphism `f : R →+* S` and `S` is nontrivial, then `R` is nontrivial. -/ theorem domain_nontrivial {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β) [nontrivial β] : nontrivial α := sorry theorem is_unit_map {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β) {a : α} (h : is_unit a) : is_unit (coe_fn f a) := is_unit.map (to_monoid_hom f) h /-- The identity ring homomorphism from a semiring to itself. -/ def id (α : Type u_1) [semiring α] : α →+* α := mk id sorry sorry sorry sorry protected instance inhabited {α : Type u} [rα : semiring α] : Inhabited (α →+* α) := { default := id α } @[simp] theorem id_apply {α : Type u} [rα : semiring α] (x : α) : coe_fn (id α) x = x := rfl /-- Composition of ring homomorphisms is a ring homomorphism. -/ def comp {α : Type u} {β : Type v} {γ : Type w} [rα : semiring α] [rβ : semiring β] {rγ : semiring γ} (hnp : β →+* γ) (hmn : α →+* β) : α →+* γ := mk (⇑hnp ∘ ⇑hmn) sorry sorry sorry sorry /-- Composition of semiring homomorphisms is associative. -/ theorem comp_assoc {α : Type u} {β : Type v} {γ : Type w} [rα : semiring α] [rβ : semiring β] {rγ : semiring γ} {δ : Type u_1} {rδ : semiring δ} (f : α →+* β) (g : β →+* γ) (h : γ →+* δ) : comp (comp h g) f = comp h (comp g f) := rfl @[simp] theorem coe_comp {α : Type u} {β : Type v} {γ : Type w} [rα : semiring α] [rβ : semiring β] {rγ : semiring γ} (hnp : β →+* γ) (hmn : α →+* β) : ⇑(comp hnp hmn) = ⇑hnp ∘ ⇑hmn := rfl theorem comp_apply {α : Type u} {β : Type v} {γ : Type w} [rα : semiring α] [rβ : semiring β] {rγ : semiring γ} (hnp : β →+* γ) (hmn : α →+* β) (x : α) : coe_fn (comp hnp hmn) x = coe_fn hnp (coe_fn hmn x) := rfl @[simp] theorem comp_id {α : Type u} {β : Type v} [rα : semiring α] [rβ : semiring β] (f : α →+* β) : comp f (id α) = f := ext fun (x : α) => rfl @[simp] theorem id_comp {α : Type u} {β : Type v} [rα : semiring α] [rβ : semiring β] (f : α →+* β) : comp (id β) f = f := ext fun (x : α) => rfl protected instance monoid {α : Type u} [rα : semiring α] : monoid (α →+* α) := monoid.mk comp sorry (id α) id_comp comp_id theorem one_def {α : Type u} [rα : semiring α] : 1 = id α := rfl @[simp] theorem coe_one {α : Type u} [rα : semiring α] : ⇑1 = id := rfl theorem mul_def {α : Type u} [rα : semiring α] (f : α →+* α) (g : α →+* α) : f * g = comp f g := rfl @[simp] theorem coe_mul {α : Type u} [rα : semiring α] (f : α →+* α) (g : α →+* α) : ⇑(f * g) = ⇑f ∘ ⇑g := rfl theorem cancel_right {α : Type u} {β : Type v} {γ : Type w} [rα : semiring α] [rβ : semiring β] {rγ : semiring γ} {g₁ : β →+* γ} {g₂ : β →+* γ} {f : α →+* β} (hf : function.surjective ⇑f) : comp g₁ f = comp g₂ f ↔ g₁ = g₂ := { mp := fun (h : comp g₁ f = comp g₂ f) => ext (iff.mp (forall_iff_forall_surj hf) (iff.mp ext_iff h)), mpr := fun (h : g₁ = g₂) => h ▸ rfl } theorem cancel_left {α : Type u} {β : Type v} {γ : Type w} [rα : semiring α] [rβ : semiring β] {rγ : semiring γ} {g : β →+* γ} {f₁ : α →+* β} {f₂ : α →+* β} (hg : function.injective ⇑g) : comp g f₁ = comp g f₂ ↔ f₁ = f₂ := sorry end ring_hom /-- A commutative semiring is a `semiring` with commutative multiplication. In other words, it is a type with the following structures: additive commutative monoid (`add_comm_monoid`), multiplicative commutative monoid (`comm_monoid`), distributive laws (`distrib`), and multiplication by zero law (`mul_zero_class`). -/ class comm_semiring (α : Type u) extends semiring α, comm_monoid α where protected instance comm_semiring.to_comm_monoid_with_zero {α : Type u} [comm_semiring α] : comm_monoid_with_zero α := comm_monoid_with_zero.mk comm_monoid.mul sorry comm_monoid.one sorry sorry sorry semiring.zero sorry sorry /-- Pullback a `semiring` instance along an injective function. -/ protected def function.injective.comm_semiring {α : Type u} {γ : Type w} [comm_semiring α] [HasZero γ] [HasOne γ] [Add γ] [Mul γ] (f : γ → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ (x y : γ), f (x + y) = f x + f y) (mul : ∀ (x y : γ), f (x * y) = f x * f y) : comm_semiring γ := comm_semiring.mk semiring.add sorry semiring.zero sorry sorry sorry semiring.mul sorry semiring.one sorry sorry sorry sorry sorry sorry sorry /-- Pullback a `semiring` instance along an injective function. -/ protected def function.surjective.comm_semiring {α : Type u} {γ : Type w} [comm_semiring α] [HasZero γ] [HasOne γ] [Add γ] [Mul γ] (f : α → γ) (hf : function.surjective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ (x y : α), f (x + y) = f x + f y) (mul : ∀ (x y : α), f (x * y) = f x * f y) : comm_semiring γ := comm_semiring.mk semiring.add sorry semiring.zero sorry sorry sorry semiring.mul sorry semiring.one sorry sorry sorry sorry sorry sorry sorry theorem add_mul_self_eq {α : Type u} [comm_semiring α] (a : α) (b : α) : (a + b) * (a + b) = a * a + bit0 1 * a * b + b * b := sorry @[simp] theorem two_dvd_bit0 {α : Type u} [comm_semiring α] {a : α} : bit0 1 ∣ bit0 a := Exists.intro a (bit0_eq_two_mul a) theorem ring_hom.map_dvd {α : Type u} {β : Type v} [comm_semiring α] [comm_semiring β] (f : α →+* β) {a : α} {b : α} : a ∣ b → coe_fn f a ∣ coe_fn f b := sorry /-! ### Rings -/ /-- A ring is a type with the following structures: additive commutative group (`add_comm_group`), multiplicative monoid (`monoid`), and distributive laws (`distrib`). Equivalently, a ring is a `semiring` with a negation operation making it an additive group. -/ class ring (α : Type u) extends monoid α, distrib α, add_comm_group α where /- The instance from `ring` to `semiring` happens often in linear algebra, for which all the basic definitions are given in terms of semirings, but many applications use rings or fields. We increase a little bit its priority above 100 to try it quickly, but remaining below the default 1000 so that more specific instances are tried first. -/ protected instance ring.to_semiring {α : Type u} [ring α] : semiring α := semiring.mk ring.add ring.add_assoc ring.zero ring.zero_add ring.add_zero ring.add_comm ring.mul ring.mul_assoc ring.one ring.one_mul ring.mul_one sorry sorry ring.left_distrib ring.right_distrib /-- Pullback a `ring` instance along an injective function. -/ protected def function.injective.ring {α : Type u} {β : Type v} [ring α] [HasZero β] [HasOne β] [Add β] [Mul β] [Neg β] (f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ (x y : β), f (x + y) = f x + f y) (mul : ∀ (x y : β), f (x * y) = f x * f y) (neg : ∀ (x : β), f (-x) = -f x) : ring β := ring.mk add_comm_group.add sorry add_comm_group.zero sorry sorry add_comm_group.neg add_comm_group.sub sorry sorry monoid.mul sorry monoid.one sorry sorry sorry sorry /-- Pullback a `ring` instance along an injective function, with a subtraction (`-`) that is not necessarily defeq to `a + -b`. -/ protected def function.injective.ring_sub {α : Type u} {β : Type v} [ring α] [HasZero β] [HasOne β] [Add β] [Mul β] [Neg β] [Sub β] (f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ (x y : β), f (x + y) = f x + f y) (mul : ∀ (x y : β), f (x * y) = f x * f y) (neg : ∀ (x : β), f (-x) = -f x) (sub : ∀ (x y : β), f (x - y) = f x - f y) : ring β := ring.mk add_comm_group.add sorry add_comm_group.zero sorry sorry add_comm_group.neg add_comm_group.sub sorry sorry monoid.mul sorry monoid.one sorry sorry sorry sorry /-- Pullback a `ring` instance along an injective function. -/ protected def function.surjective.ring {α : Type u} {β : Type v} [ring α] [HasZero β] [HasOne β] [Add β] [Mul β] [Neg β] (f : α → β) (hf : function.surjective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ (x y : α), f (x + y) = f x + f y) (mul : ∀ (x y : α), f (x * y) = f x * f y) (neg : ∀ (x : α), f (-x) = -f x) : ring β := ring.mk add_comm_group.add sorry add_comm_group.zero sorry sorry add_comm_group.neg add_comm_group.sub sorry sorry monoid.mul sorry monoid.one sorry sorry sorry sorry /-- Pullback a `ring` instance along an injective function, with a subtraction (`-`) that is not necessarily defeq to `a + -b`. -/ protected def function.surjective.ring_sub {α : Type u} {β : Type v} [ring α] [HasZero β] [HasOne β] [Add β] [Mul β] [Neg β] [Sub β] (f : α → β) (hf : function.surjective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ (x y : α), f (x + y) = f x + f y) (mul : ∀ (x y : α), f (x * y) = f x * f y) (neg : ∀ (x : α), f (-x) = -f x) (sub : ∀ (x y : α), f (x - y) = f x - f y) : ring β := ring.mk add_comm_group.add sorry add_comm_group.zero sorry sorry add_comm_group.neg add_comm_group.sub sorry sorry monoid.mul sorry monoid.one sorry sorry sorry sorry theorem neg_mul_eq_neg_mul {α : Type u} [ring α] (a : α) (b : α) : -(a * b) = -a * b := sorry theorem neg_mul_eq_mul_neg {α : Type u} [ring α] (a : α) (b : α) : -(a * b) = a * -b := sorry @[simp] theorem neg_mul_eq_neg_mul_symm {α : Type u} [ring α] (a : α) (b : α) : -a * b = -(a * b) := Eq.symm (neg_mul_eq_neg_mul a b) @[simp] theorem mul_neg_eq_neg_mul_symm {α : Type u} [ring α] (a : α) (b : α) : a * -b = -(a * b) := Eq.symm (neg_mul_eq_mul_neg a b) theorem neg_mul_neg {α : Type u} [ring α] (a : α) (b : α) : -a * -b = a * b := sorry theorem neg_mul_comm {α : Type u} [ring α] (a : α) (b : α) : -a * b = a * -b := sorry theorem neg_eq_neg_one_mul {α : Type u} [ring α] (a : α) : -a = -1 * a := sorry theorem mul_sub_left_distrib {α : Type u} [ring α] (a : α) (b : α) (c : α) : a * (b - c) = a * b - a * c := sorry theorem mul_sub {α : Type u} [ring α] (a : α) (b : α) (c : α) : a * (b - c) = a * b - a * c := mul_sub_left_distrib theorem mul_sub_right_distrib {α : Type u} [ring α] (a : α) (b : α) (c : α) : (a - b) * c = a * c - b * c := sorry theorem sub_mul {α : Type u} [ring α] (a : α) (b : α) (c : α) : (a - b) * c = a * c - b * c := mul_sub_right_distrib /-- An element of a ring multiplied by the additive inverse of one is the element's additive inverse. -/ theorem mul_neg_one {α : Type u} [ring α] (a : α) : a * -1 = -a := sorry /-- The additive inverse of one multiplied by an element of a ring is the element's additive inverse. -/ theorem neg_one_mul {α : Type u} [ring α] (a : α) : -1 * a = -a := sorry /-- An iff statement following from right distributivity in rings and the definition of subtraction. -/ theorem mul_add_eq_mul_add_iff_sub_mul_add_eq {α : Type u} [ring α] {a : α} {b : α} {c : α} {d : α} {e : α} : a * e + c = b * e + d ↔ (a - b) * e + c = d := sorry /-- A simplification of one side of an equation exploiting right distributivity in rings and the definition of subtraction. -/ theorem sub_mul_add_eq_of_mul_add_eq_mul_add {α : Type u} [ring α] {a : α} {b : α} {c : α} {d : α} {e : α} : a * e + c = b * e + d → (a - b) * e + c = d := sorry namespace units /-- Each element of the group of units of a ring has an additive inverse. -/ protected instance has_neg {α : Type u} [ring α] : Neg (units α) := { neg := fun (u : units α) => mk (-↑u) (-↑(u⁻¹)) sorry sorry } /-- Representing an element of a ring's unit group as an element of the ring commutes with mapping this element to its additive inverse. -/ @[simp] protected theorem coe_neg {α : Type u} [ring α] (u : units α) : ↑(-u) = -↑u := rfl @[simp] protected theorem coe_neg_one {α : Type u} [ring α] : ↑(-1) = -1 := rfl /-- Mapping an element of a ring's unit group to its inverse commutes with mapping this element to its additive inverse. -/ @[simp] protected theorem neg_inv {α : Type u} [ring α] (u : units α) : -u⁻¹ = -(u⁻¹) := rfl /-- An element of a ring's unit group equals the additive inverse of its additive inverse. -/ @[simp] protected theorem neg_neg {α : Type u} [ring α] (u : units α) : --u = u := ext (neg_neg ↑u) /-- Multiplication of elements of a ring's unit group commutes with mapping the first argument to its additive inverse. -/ @[simp] protected theorem neg_mul {α : Type u} [ring α] (u₁ : units α) (u₂ : units α) : -u₁ * u₂ = -(u₁ * u₂) := ext (neg_mul_eq_neg_mul_symm (↑u₁) (val u₂)) /-- Multiplication of elements of a ring's unit group commutes with mapping the second argument to its additive inverse. -/ @[simp] protected theorem mul_neg {α : Type u} [ring α] (u₁ : units α) (u₂ : units α) : u₁ * -u₂ = -(u₁ * u₂) := ext (Eq.symm (neg_mul_eq_mul_neg (val u₁) ↑u₂)) /-- Multiplication of the additive inverses of two elements of a ring's unit group equals multiplication of the two original elements. -/ @[simp] protected theorem neg_mul_neg {α : Type u} [ring α] (u₁ : units α) (u₂ : units α) : -u₁ * -u₂ = u₁ * u₂ := sorry /-- The additive inverse of an element of a ring's unit group equals the additive inverse of one times the original element. -/ protected theorem neg_eq_neg_one_mul {α : Type u} [ring α] (u : units α) : -u = -1 * u := sorry end units namespace ring_hom /-- Ring homomorphisms preserve additive inverse. -/ @[simp] theorem map_neg {α : Type u_1} {β : Type u_2} [ring α] [ring β] (f : α →+* β) (x : α) : coe_fn f (-x) = -coe_fn f x := add_monoid_hom.map_neg (↑f) x /-- Ring homomorphisms preserve subtraction. -/ @[simp] theorem map_sub {α : Type u_1} {β : Type u_2} [ring α] [ring β] (f : α →+* β) (x : α) (y : α) : coe_fn f (x - y) = coe_fn f x - coe_fn f y := add_monoid_hom.map_sub (↑f) x y /-- A ring homomorphism is injective iff its kernel is trivial. -/ theorem injective_iff {α : Type u_1} {β : Type u_2} [ring α] [semiring β] (f : α →+* β) : function.injective ⇑f ↔ ∀ (a : α), coe_fn f a = 0 → a = 0 := add_monoid_hom.injective_iff ↑f /-- Makes a ring homomorphism from a monoid homomorphism of rings which preserves addition. -/ def mk' {α : Type u} {γ : Type u_1} [semiring α] [ring γ] (f : α →* γ) (map_add : ∀ (a b : α), coe_fn f (a + b) = coe_fn f a + coe_fn f b) : α →+* γ := mk ⇑f sorry sorry sorry sorry end ring_hom /-- A commutative ring is a `ring` with commutative multiplication. -/ class comm_ring (α : Type u) extends ring α, comm_semigroup α where protected instance comm_ring.to_comm_semiring {α : Type u} [s : comm_ring α] : comm_semiring α := comm_semiring.mk comm_ring.add comm_ring.add_assoc comm_ring.zero comm_ring.zero_add comm_ring.add_zero comm_ring.add_comm comm_ring.mul comm_ring.mul_assoc comm_ring.one comm_ring.one_mul comm_ring.mul_one sorry sorry comm_ring.left_distrib comm_ring.right_distrib comm_ring.mul_comm /-- Pullback a `comm_ring` instance along an injective function. -/ protected def function.injective.comm_ring {α : Type u} {β : Type v} [comm_ring α] [HasZero β] [HasOne β] [Add β] [Mul β] [Neg β] (f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ (x y : β), f (x + y) = f x + f y) (mul : ∀ (x y : β), f (x * y) = f x * f y) (neg : ∀ (x : β), f (-x) = -f x) : comm_ring β := comm_ring.mk ring.add sorry ring.zero sorry sorry ring.neg ring.sub sorry sorry ring.mul sorry ring.one sorry sorry sorry sorry sorry /-- Pullback a `comm_ring` instance along an injective function, with a subtraction (`-`) that is not necessarily defeq to `a + -b`. -/ protected def function.injective.comm_ring_sub {α : Type u} {β : Type v} [comm_ring α] [HasZero β] [HasOne β] [Add β] [Mul β] [Neg β] [Sub β] (f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ (x y : β), f (x + y) = f x + f y) (mul : ∀ (x y : β), f (x * y) = f x * f y) (neg : ∀ (x : β), f (-x) = -f x) (sub : ∀ (x y : β), f (x - y) = f x - f y) : comm_ring β := comm_ring.mk ring.add sorry ring.zero sorry sorry ring.neg ring.sub sorry sorry ring.mul sorry ring.one sorry sorry sorry sorry sorry /-- Pullback a `comm_ring` instance along an injective function. -/ protected def function.surjective.comm_ring {α : Type u} {β : Type v} [comm_ring α] [HasZero β] [HasOne β] [Add β] [Mul β] [Neg β] (f : α → β) (hf : function.surjective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ (x y : α), f (x + y) = f x + f y) (mul : ∀ (x y : α), f (x * y) = f x * f y) (neg : ∀ (x : α), f (-x) = -f x) : comm_ring β := comm_ring.mk ring.add sorry ring.zero sorry sorry ring.neg ring.sub sorry sorry ring.mul sorry ring.one sorry sorry sorry sorry sorry /-- Pullback a `comm_ring` instance along an injective function, with a subtraction (`-`) that is not necessarily defeq to `a + -b`. -/ protected def function.surjective.comm_ring_sub {α : Type u} {β : Type v} [comm_ring α] [HasZero β] [HasOne β] [Add β] [Mul β] [Neg β] [Sub β] (f : α → β) (hf : function.surjective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ (x y : α), f (x + y) = f x + f y) (mul : ∀ (x y : α), f (x * y) = f x * f y) (neg : ∀ (x : α), f (-x) = -f x) (sub : ∀ (x y : α), f (x - y) = f x - f y) : comm_ring β := comm_ring.mk ring.add sorry ring.zero sorry sorry ring.neg ring.sub sorry sorry ring.mul sorry ring.one sorry sorry sorry sorry sorry theorem dvd_neg_of_dvd {α : Type u} [comm_ring α] {a : α} {b : α} (h : a ∣ b) : a ∣ -b := sorry theorem dvd_of_dvd_neg {α : Type u} [comm_ring α] {a : α} {b : α} (h : a ∣ -b) : a ∣ b := let t : a ∣ --b := dvd_neg_of_dvd h; eq.mp (Eq._oldrec (Eq.refl (a ∣ --b)) (neg_neg b)) t theorem dvd_neg_iff_dvd {α : Type u} [comm_ring α] (a : α) (b : α) : a ∣ -b ↔ a ∣ b := { mp := dvd_of_dvd_neg, mpr := dvd_neg_of_dvd } theorem neg_dvd_of_dvd {α : Type u} [comm_ring α] {a : α} {b : α} (h : a ∣ b) : -a ∣ b := sorry theorem dvd_of_neg_dvd {α : Type u} [comm_ring α] {a : α} {b : α} (h : -a ∣ b) : a ∣ b := let t : --a ∣ b := neg_dvd_of_dvd h; eq.mp (Eq._oldrec (Eq.refl ( --a ∣ b)) (neg_neg a)) t theorem neg_dvd_iff_dvd {α : Type u} [comm_ring α] (a : α) (b : α) : -a ∣ b ↔ a ∣ b := { mp := dvd_of_neg_dvd, mpr := neg_dvd_of_dvd } theorem dvd_sub {α : Type u} [comm_ring α] {a : α} {b : α} {c : α} (h₁ : a ∣ b) (h₂ : a ∣ c) : a ∣ b - c := eq.mpr (id (Eq._oldrec (Eq.refl (a ∣ b - c)) (sub_eq_add_neg b c))) (dvd_add h₁ (dvd_neg_of_dvd h₂)) theorem dvd_add_iff_left {α : Type u} [comm_ring α] {a : α} {b : α} {c : α} (h : a ∣ c) : a ∣ b ↔ a ∣ b + c := { mp := fun (h₂ : a ∣ b) => dvd_add h₂ h, mpr := fun (H : a ∣ b + c) => eq.mp (Eq._oldrec (Eq.refl (a ∣ b + c - c)) (add_sub_cancel b c)) (dvd_sub H h) } theorem dvd_add_iff_right {α : Type u} [comm_ring α] {a : α} {b : α} {c : α} (h : a ∣ b) : a ∣ c ↔ a ∣ b + c := eq.mpr (id (Eq._oldrec (Eq.refl (a ∣ c ↔ a ∣ b + c)) (add_comm b c))) (dvd_add_iff_left h) theorem two_dvd_bit1 {α : Type u} [comm_ring α] {a : α} : bit0 1 ∣ bit1 a ↔ bit0 1 ∣ 1 := iff.symm (dvd_add_iff_right two_dvd_bit0) /-- Representation of a difference of two squares in a commutative ring as a product. -/ theorem mul_self_sub_mul_self {α : Type u} [comm_ring α] (a : α) (b : α) : a * a - b * b = (a + b) * (a - b) := sorry theorem mul_self_sub_one {α : Type u} [comm_ring α] (a : α) : a * a - 1 = (a + 1) * (a - 1) := eq.mpr (id (Eq._oldrec (Eq.refl (a * a - 1 = (a + 1) * (a - 1))) (Eq.symm (mul_self_sub_mul_self a 1)))) (eq.mpr (id (Eq._oldrec (Eq.refl (a * a - 1 = a * a - 1 * 1)) (mul_one 1))) (Eq.refl (a * a - 1))) /-- An element a of a commutative ring divides the additive inverse of an element b iff a divides b. -/ @[simp] theorem dvd_neg {α : Type u} [comm_ring α] (a : α) (b : α) : a ∣ -b ↔ a ∣ b := { mp := dvd_of_dvd_neg, mpr := dvd_neg_of_dvd } /-- The additive inverse of an element a of a commutative ring divides another element b iff a divides b. -/ @[simp] theorem neg_dvd {α : Type u} [comm_ring α] (a : α) (b : α) : -a ∣ b ↔ a ∣ b := { mp := dvd_of_neg_dvd, mpr := neg_dvd_of_dvd } /-- If an element a divides another element c in a commutative ring, a divides the sum of another element b with c iff a divides b. -/ theorem dvd_add_left {α : Type u} [comm_ring α] {a : α} {b : α} {c : α} (h : a ∣ c) : a ∣ b + c ↔ a ∣ b := iff.symm (dvd_add_iff_left h) /-- If an element a divides another element b in a commutative ring, a divides the sum of b and another element c iff a divides c. -/ theorem dvd_add_right {α : Type u} [comm_ring α] {a : α} {b : α} {c : α} (h : a ∣ b) : a ∣ b + c ↔ a ∣ c := iff.symm (dvd_add_iff_right h) /-- An element a divides the sum a + b if and only if a divides b.-/ @[simp] theorem dvd_add_self_left {α : Type u} [comm_ring α] {a : α} {b : α} : a ∣ a + b ↔ a ∣ b := dvd_add_right (dvd_refl a) /-- An element a divides the sum b + a if and only if a divides b.-/ @[simp] theorem dvd_add_self_right {α : Type u} [comm_ring α] {a : α} {b : α} : a ∣ b + a ↔ a ∣ b := dvd_add_left (dvd_refl a) /-- Vieta's formula for a quadratic equation, relating the coefficients of the polynomial with its roots. This particular version states that if we have a root `x` of a monic quadratic polynomial, then there is another root `y` such that `x + y` is negative the `a_1` coefficient and `x * y` is the `a_0` coefficient. -/ theorem Vieta_formula_quadratic {α : Type u} [comm_ring α] {b : α} {c : α} {x : α} (h : x * x - b * x + c = 0) : ∃ (y : α), y * y - b * y + c = 0 ∧ x + y = b ∧ x * y = c := sorry theorem dvd_mul_sub_mul {α : Type u} [comm_ring α] {k : α} {a : α} {b : α} {x : α} {y : α} (hab : k ∣ a - b) (hxy : k ∣ x - y) : k ∣ a * x - b * y := sorry theorem dvd_iff_dvd_of_dvd_sub {α : Type u} [comm_ring α] {a : α} {b : α} {c : α} (h : a ∣ b - c) : a ∣ b ↔ a ∣ c := sorry theorem succ_ne_self {α : Type u} [ring α] [nontrivial α] (a : α) : a + 1 ≠ a := sorry theorem pred_ne_self {α : Type u} [ring α] [nontrivial α] (a : α) : a - 1 ≠ a := sorry /-- A domain is a ring with no zero divisors, i.e. satisfying the condition `a * b = 0 ↔ a = 0 ∨ b = 0`. Alternatively, a domain is an integral domain without assuming commutativity of multiplication. -/ class domain (α : Type u) extends ring α, nontrivial α where eq_zero_or_eq_zero_of_mul_eq_zero : ∀ (a b : α), a * b = 0 → a = 0 ∨ b = 0 protected instance domain.to_no_zero_divisors {α : Type u} [domain α] : no_zero_divisors α := no_zero_divisors.mk domain.eq_zero_or_eq_zero_of_mul_eq_zero protected instance domain.to_cancel_monoid_with_zero {α : Type u} [domain α] : cancel_monoid_with_zero α := cancel_monoid_with_zero.mk semiring.mul sorry semiring.one sorry sorry semiring.zero sorry sorry sorry sorry /-- Pullback a `domain` instance along an injective function. -/ protected def function.injective.domain {α : Type u} {β : Type v} [domain α] [HasZero β] [HasOne β] [Add β] [Mul β] [Neg β] (f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ (x y : β), f (x + y) = f x + f y) (mul : ∀ (x y : β), f (x * y) = f x * f y) (neg : ∀ (x : β), f (-x) = -f x) : domain β := domain.mk ring.add sorry ring.zero sorry sorry ring.neg ring.sub sorry sorry ring.mul sorry ring.one sorry sorry sorry sorry sorry sorry /-! ### Integral domains -/ /-- An integral domain is a commutative ring with no zero divisors, i.e. satisfying the condition `a * b = 0 ↔ a = 0 ∨ b = 0`. Alternatively, an integral domain is a domain with commutative multiplication. -/ class integral_domain (α : Type u) extends comm_ring α, domain α where protected instance integral_domain.to_comm_cancel_monoid_with_zero {α : Type u} [integral_domain α] : comm_cancel_monoid_with_zero α := comm_cancel_monoid_with_zero.mk comm_monoid_with_zero.mul sorry comm_monoid_with_zero.one sorry sorry sorry comm_monoid_with_zero.zero sorry sorry sorry sorry /-- Pullback an `integral_domain` instance along an injective function. -/ protected def function.injective.integral_domain {α : Type u} {β : Type v} [integral_domain α] [HasZero β] [HasOne β] [Add β] [Mul β] [Neg β] (f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ (x y : β), f (x + y) = f x + f y) (mul : ∀ (x y : β), f (x * y) = f x * f y) (neg : ∀ (x : β), f (-x) = -f x) : integral_domain β := integral_domain.mk comm_ring.add sorry comm_ring.zero sorry sorry comm_ring.neg comm_ring.sub sorry sorry comm_ring.mul sorry comm_ring.one sorry sorry sorry sorry sorry sorry sorry theorem mul_self_eq_mul_self_iff {α : Type u} [integral_domain α] {a : α} {b : α} : a * a = b * b ↔ a = b ∨ a = -b := sorry theorem mul_self_eq_one_iff {α : Type u} [integral_domain α] {a : α} : a * a = 1 ↔ a = 1 ∨ a = -1 := eq.mpr (id (Eq._oldrec (Eq.refl (a * a = 1 ↔ a = 1 ∨ a = -1)) (Eq.symm (propext mul_self_eq_mul_self_iff)))) (eq.mpr (id (Eq._oldrec (Eq.refl (a * a = 1 ↔ a * a = 1 * 1)) (one_mul 1))) (iff.refl (a * a = 1))) /-- In the unit group of an integral domain, a unit is its own inverse iff the unit is one or one's additive inverse. -/ theorem units.inv_eq_self_iff {α : Type u} [integral_domain α] (u : units α) : u⁻¹ = u ↔ u = 1 ∨ u = -1 := sorry namespace ring /-- Introduce a function `inverse` on a ring `R`, which sends `x` to `x⁻¹` if `x` is invertible 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. -/ def inverse {R : Type x} [ring R] : R → R := fun (x : R) => dite (is_unit x) (fun (h : is_unit x) => ↑(classical.some h⁻¹)) fun (h : ¬is_unit x) => 0 /-- By definition, if `x` is invertible then `inverse x = x⁻¹`. -/ @[simp] theorem inverse_unit {R : Type x} [ring R] (a : units R) : inverse ↑a = ↑(a⁻¹) := sorry /-- By definition, if `x` is not invertible then `inverse x = 0`. -/ @[simp] theorem inverse_non_unit {R : Type x} [ring R] (x : R) (h : ¬is_unit x) : inverse x = 0 := dif_neg h end ring /-- A predicate to express that a ring is an integral domain. This is mainly useful because such a predicate does not contain data, and can therefore be easily transported along ring isomorphisms. -/ structure is_integral_domain (R : Type u) [ring R] extends nontrivial R where mul_comm : ∀ (x y : R), x * y = y * x eq_zero_or_eq_zero_of_mul_eq_zero : ∀ (x y : R), x * y = 0 → x = 0 ∨ y = 0 -- The linter does not recognize that is_integral_domain.to_nontrivial is a structure -- projection, disable it /-- Every integral domain satisfies the predicate for integral domains. -/ theorem integral_domain.to_is_integral_domain (R : Type u) [integral_domain R] : is_integral_domain R := is_integral_domain.mk integral_domain.exists_pair_ne integral_domain.mul_comm integral_domain.eq_zero_or_eq_zero_of_mul_eq_zero /-- If a ring satisfies the predicate for integral domains, then it can be endowed with an `integral_domain` instance whose data is definitionally equal to the existing data. -/ def is_integral_domain.to_integral_domain (R : Type u) [ring R] (h : is_integral_domain R) : integral_domain R := integral_domain.mk ring.add ring.add_assoc ring.zero ring.zero_add ring.add_zero ring.neg ring.sub ring.add_left_neg ring.add_comm ring.mul ring.mul_assoc ring.one ring.one_mul ring.mul_one ring.left_distrib ring.right_distrib (is_integral_domain.mul_comm h) (is_integral_domain.exists_pair_ne h) (is_integral_domain.eq_zero_or_eq_zero_of_mul_eq_zero h) namespace semiconj_by @[simp] theorem add_right {R : Type x} [distrib R] {a : R} {x : R} {y : R} {x' : R} {y' : R} (h : semiconj_by a x y) (h' : semiconj_by a x' y') : semiconj_by a (x + x') (y + y') := sorry @[simp] theorem add_left {R : Type x} [distrib R] {a : R} {b : R} {x : R} {y : R} (ha : semiconj_by a x y) (hb : semiconj_by b x y) : semiconj_by (a + b) x y := sorry theorem neg_right {R : Type x} [ring R] {a : R} {x : R} {y : R} (h : semiconj_by a x y) : semiconj_by a (-x) (-y) := sorry @[simp] theorem neg_right_iff {R : Type x} [ring R] {a : R} {x : R} {y : R} : semiconj_by a (-x) (-y) ↔ semiconj_by a x y := { mp := fun (h : semiconj_by a (-x) (-y)) => neg_neg x ▸ neg_neg y ▸ neg_right h, mpr := neg_right } theorem neg_left {R : Type x} [ring R] {a : R} {x : R} {y : R} (h : semiconj_by a x y) : semiconj_by (-a) x y := sorry @[simp] theorem neg_left_iff {R : Type x} [ring R] {a : R} {x : R} {y : R} : semiconj_by (-a) x y ↔ semiconj_by a x y := { mp := fun (h : semiconj_by (-a) x y) => neg_neg a ▸ neg_left h, mpr := neg_left } @[simp] theorem neg_one_right {R : Type x} [ring R] (a : R) : semiconj_by a (-1) (-1) := neg_right (one_right a) @[simp] theorem neg_one_left {R : Type x} [ring R] (x : R) : semiconj_by (-1) x x := neg_left (one_left x) @[simp] theorem sub_right {R : Type x} [ring R] {a : R} {x : R} {y : R} {x' : R} {y' : R} (h : semiconj_by a x y) (h' : semiconj_by a x' y') : semiconj_by a (x - x') (y - y') := sorry @[simp] theorem sub_left {R : Type x} [ring R] {a : R} {b : R} {x : R} {y : R} (ha : semiconj_by a x y) (hb : semiconj_by b x y) : semiconj_by (a - b) x y := sorry end semiconj_by namespace commute @[simp] theorem add_right {R : Type x} [distrib R] {a : R} {b : R} {c : R} : commute a b → commute a c → commute a (b + c) := semiconj_by.add_right @[simp] theorem add_left {R : Type x} [distrib R] {a : R} {b : R} {c : R} : commute a c → commute b c → commute (a + b) c := semiconj_by.add_left theorem neg_right {R : Type x} [ring R] {a : R} {b : R} : commute a b → commute a (-b) := semiconj_by.neg_right @[simp] theorem neg_right_iff {R : Type x} [ring R] {a : R} {b : R} : commute a (-b) ↔ commute a b := semiconj_by.neg_right_iff theorem neg_left {R : Type x} [ring R] {a : R} {b : R} : commute a b → commute (-a) b := semiconj_by.neg_left @[simp] theorem neg_left_iff {R : Type x} [ring R] {a : R} {b : R} : commute (-a) b ↔ commute a b := semiconj_by.neg_left_iff @[simp] theorem neg_one_right {R : Type x} [ring R] (a : R) : commute a (-1) := semiconj_by.neg_one_right a @[simp] theorem neg_one_left {R : Type x} [ring R] (a : R) : commute (-1) a := semiconj_by.neg_one_left a @[simp] theorem sub_right {R : Type x} [ring R] {a : R} {b : R} {c : R} : commute a b → commute a c → commute a (b - c) := semiconj_by.sub_right @[simp] theorem sub_left {R : Type x} [ring R] {a : R} {b : R} {c : R} : commute a c → commute b c → commute (a - b) c := semiconj_by.sub_left
81177b8276444c387219deb95f4a64738410cd5b
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/import_middle.lean
123c4c9a29fbe4cd62bfc5e7ddac58cef7a955c8
[ "Apache-2.0" ]
permissive
leanprover-community/lean
12b87f69d92e614daea8bcc9d4de9a9ace089d0e
cce7990ea86a78bdb383e38ed7f9b5ba93c60ce0
refs/heads/master
1,687,508,156,644
1,684,951,104,000
1,684,951,104,000
169,960,991
457
107
Apache-2.0
1,686,744,372,000
1,549,790,268,000
C++
UTF-8
Lean
false
false
54
lean
import data.buffer #print "hello" import data.dlist
5019380d6b27f245ef77511a0567595bb5fb6730
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/src/topology/sheaves/sheaf_condition/unique_gluing.lean
b550cdebad637a0c84905be5d99f405af77caf3d
[ "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
10,802
lean
/- Copyright (c) 2021 Justus Springer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Justus Springer -/ import algebra.category.CommRing.limits import topology.sheaves.forget import topology.sheaves.sheaf import category_theory.limits.shapes.types import category_theory.types /-! # The sheaf condition in terms of unique gluings We provide an alternative formulation of the sheaf condition in terms of unique gluings. We work with sheaves valued in a concrete category `C` admitting all limits, whose forgetful functor `C ⥤ Type` preserves limits and reflects isomorphisms. The usual categories of algebraic structures, such as `Mon`, `AddCommGroup`, `Ring`, `CommRing` etc. are all examples of this kind of category. A presheaf `F : presheaf C X` satisfies the sheaf condition if and only if, for every compatible family of sections `sf : Π i : ι, F.obj (op (U i))`, there exists a unique gluing `s : F.obj (op (supr U))`. Here, the family `sf` is called compatible, if for all `i j : ι`, the restrictions of `sf i` and `sf j` to `U i ⊓ U j` agree. A section `s : F.obj (op (supr U))` is a gluing for the family `sf`, if `s` restricts to `sf i` on `U i` for all `i : ι` We show that the sheaf condition in terms of unique gluings is equivalent to the definition in terms of equalizers. Our approach is as follows: First, we show them to be equivalent for `Type`-valued presheaves. Then we use that composing a presheaf with a limit-preserving and isomorphism-reflecting functor leaves the sheaf condition invariant, as shown in `topology/sheaves/forget.lean`. -/ noncomputable theory open Top open Top.presheaf open Top.presheaf.sheaf_condition_equalizer_products open category_theory open category_theory.limits open topological_space open topological_space.opens open opposite universes u v variables {C : Type u} [category.{v} C] [concrete_category.{v} C] namespace Top namespace presheaf section local attribute [instance] concrete_category.has_coe_to_sort concrete_category.has_coe_to_fun variables {X : Top.{v}} (F : presheaf C X) {ι : Type v} (U : ι → opens X) /-- A family of sections `sf` is compatible, if the restrictions of `sf i` and `sf j` to `U i ⊓ U j` agree, for all `i` and `j` -/ def is_compatible (sf : Π i : ι, F.obj (op (U i))) : Prop := ∀ i j : ι, F.map (inf_le_left (U i) (U j)).op (sf i) = F.map (inf_le_right (U i) (U j)).op (sf j) /-- A section `s` is a gluing for a family of sections `sf` if it restricts to `sf i` on `U i`, for all `i` -/ def is_gluing (sf : Π i : ι, F.obj (op (U i))) (s : F.obj (op (supr U))) : Prop := ∀ i : ι, F.map (opens.le_supr U i).op s = sf i /-- The sheaf condition in terms of unique gluings. A presheaf `F : presheaf C X` satisfies this sheaf condition if and only if, for every compatible family of sections `sf : Π i : ι, F.obj (op (U i))`, there exists a unique gluing `s : F.obj (op (supr U))`. We prove this to be equivalent to the usual one below in `is_sheaf_iff_is_sheaf_unique_gluing` -/ def is_sheaf_unique_gluing : Prop := ∀ ⦃ι : Type v⦄ (U : ι → opens X) (sf : Π i : ι, F.obj (op (U i))), is_compatible F U sf → ∃! s : F.obj (op (supr U)), is_gluing F U sf s end section type_valued variables {X : Top.{v}} (F : presheaf (Type v) X) {ι : Type v} (U : ι → opens X) /-- For presheaves of types, terms of `pi_opens F U` are just families of sections. -/ def pi_opens_iso_sections_family : pi_opens F U ≅ Π i : ι, F.obj (op (U i)) := limits.is_limit.cone_point_unique_up_to_iso (limit.is_limit (discrete.functor (λ i : ι, F.obj (op (U i))))) ((types.product_limit_cone (λ i : ι, F.obj (op (U i)))).is_limit) /-- Under the isomorphism `pi_opens_iso_sections_family`, compatibility of sections is the same as being equalized by the arrows `left_res` and `right_res` of the equalizer diagram. -/ lemma compatible_iff_left_res_eq_right_res (sf : pi_opens F U) : is_compatible F U ((pi_opens_iso_sections_family F U).hom sf) ↔ left_res F U sf = right_res F U sf := begin split ; intros h, { ext ⟨i, j⟩, rw [left_res, types.limit.lift_π_apply, fan.mk_π_app, right_res, types.limit.lift_π_apply, fan.mk_π_app], exact h i j, }, { intros i j, convert congr_arg (limits.pi.π (λ p : ι × ι, F.obj (op (U p.1 ⊓ U p.2))) (i,j)) h, { rw [left_res, types.pi_lift_π_apply], refl }, { rw [right_res, types.pi_lift_π_apply], refl } } end /-- Under the isomorphism `pi_opens_iso_sections_family`, being a gluing of a family of sections `sf` is the same as lying in the preimage of `res` (the leftmost arrow of the equalizer diagram). -/ @[simp] lemma is_gluing_iff_eq_res (sf : pi_opens F U) (s : F.obj (op (supr U))): is_gluing F U ((pi_opens_iso_sections_family F U).hom sf) s ↔ res F U s = sf := begin split ; intros h, { ext i, rw [res, types.limit.lift_π_apply, fan.mk_π_app], exact h i, }, { intro i, convert congr_arg (limits.pi.π (λ i : ι, F.obj (op (U i))) i) h, rw [res, types.pi_lift_π_apply], refl }, end /-- The "equalizer" sheaf condition can be obtained from the sheaf condition in terms of unique gluings. -/ lemma is_sheaf_of_is_sheaf_unique_gluing_types (Fsh : F.is_sheaf_unique_gluing) : F.is_sheaf := begin intros ι U, refine ⟨fork.is_limit.mk' _ _⟩, intro s, have h_compatible : ∀ x : s.X, F.is_compatible U ((F.pi_opens_iso_sections_family U).hom (s.ι x)), { intro x, rw compatible_iff_left_res_eq_right_res, convert congr_fun s.condition x, }, choose m m_spec m_uniq using λ x : s.X, Fsh U ((pi_opens_iso_sections_family F U).hom (s.ι x)) (h_compatible x), refine ⟨m, _, _⟩, { ext i x, simp [res], exact m_spec x i, }, { intros l hl, ext x, apply m_uniq, rw is_gluing_iff_eq_res, exact congr_fun hl x }, end /-- The sheaf condition in terms of unique gluings can be obtained from the usual "equalizer" sheaf condition. -/ lemma is_sheaf_unique_gluing_of_is_sheaf_types (Fsh : F.is_sheaf) : F.is_sheaf_unique_gluing := begin intros ι U sf hsf, let sf' := (pi_opens_iso_sections_family F U).inv sf, have hsf' : left_res F U sf' = right_res F U sf', { rwa [← compatible_iff_left_res_eq_right_res F U sf', inv_hom_id_apply] }, choose s s_spec s_uniq using types.unique_of_type_equalizer _ _ (Fsh U).some sf' hsf', use s, dsimp, split, { convert (is_gluing_iff_eq_res F U sf' _).mpr s_spec, rw inv_hom_id_apply }, { intros y hy, apply s_uniq, rw ← is_gluing_iff_eq_res F U, convert hy, rw inv_hom_id_apply, }, end /-- For type-valued presheaves, the sheaf condition in terms of unique gluings is equivalent to the usual sheaf condition in terms of equalizer diagrams. -/ lemma is_sheaf_iff_is_sheaf_unique_gluing_types : F.is_sheaf ↔ F.is_sheaf_unique_gluing := iff.intro (is_sheaf_unique_gluing_of_is_sheaf_types F) (is_sheaf_of_is_sheaf_unique_gluing_types F) end type_valued section local attribute [instance] concrete_category.has_coe_to_sort concrete_category.has_coe_to_fun variables [has_limits C] [reflects_isomorphisms (forget C)] [preserves_limits (forget C)] variables {X : Top.{v}} (F : presheaf C X) {ι : Type v} (U : ι → opens X) /-- For presheaves valued in a concrete category, whose forgetful functor reflects isomorphisms and preserves limits, the sheaf condition in terms of unique gluings is equivalent to the usual one in terms of equalizer diagrams. -/ lemma is_sheaf_iff_is_sheaf_unique_gluing : F.is_sheaf ↔ F.is_sheaf_unique_gluing := iff.trans (is_sheaf_iff_is_sheaf_comp (forget C) F) (is_sheaf_iff_is_sheaf_unique_gluing_types (F ⋙ forget C)) end end presheaf namespace sheaf open presheaf open category_theory section local attribute [instance] concrete_category.has_coe_to_sort concrete_category.has_coe_to_fun variables [has_limits C] [reflects_isomorphisms (concrete_category.forget C)] variables [preserves_limits (concrete_category.forget C)] variables {X : Top.{v}} (F : sheaf C X) {ι : Type v} (U : ι → opens X) /-- A more convenient way of obtaining a unique gluing of sections for a sheaf. -/ lemma exists_unique_gluing (sf : Π i : ι, F.1.obj (op (U i))) (h : is_compatible F.1 U sf ) : ∃! s : F.1.obj (op (supr U)), is_gluing F.1 U sf s := (is_sheaf_iff_is_sheaf_unique_gluing F.1).mp F.property U sf h /-- In this version of the lemma, the inclusion homs `iUV` can be specified directly by the user, which can be more convenient in practice. -/ lemma exists_unique_gluing' (V : opens X) (iUV : Π i : ι, U i ⟶ V) (hcover : V ≤ supr U) (sf : Π i : ι, F.1.obj (op (U i))) (h : is_compatible F.1 U sf) : ∃! s : F.1.obj (op V), ∀ i : ι, F.1.map (iUV i).op s = sf i := begin have V_eq_supr_U : V = supr U := le_antisymm hcover (supr_le (λ i, (iUV i).le)), obtain ⟨gl, gl_spec, gl_uniq⟩ := F.exists_unique_gluing U sf h, refine ⟨F.1.map (eq_to_hom V_eq_supr_U).op gl, _, _⟩, { intro i, rw [← comp_apply, ← F.1.map_comp], exact gl_spec i }, { intros gl' gl'_spec, convert congr_arg _ (gl_uniq (F.1.map (eq_to_hom V_eq_supr_U.symm).op gl') (λ i,_)) ; rw [← comp_apply, ← F.1.map_comp], { rw [eq_to_hom_op, eq_to_hom_op, eq_to_hom_trans, eq_to_hom_refl, F.1.map_id, id_apply] }, { convert gl'_spec i } } end @[ext] lemma eq_of_locally_eq (s t : F.1.obj (op (supr U))) (h : ∀ i, F.1.map (opens.le_supr U i).op s = F.1.map (opens.le_supr U i).op t) : s = t := begin let sf : Π i : ι, F.1.obj (op (U i)) := λ i, F.1.map (opens.le_supr U i).op s, have sf_compatible : is_compatible _ U sf, { intros i j, simp_rw [← comp_apply, ← F.1.map_comp], refl }, obtain ⟨gl, -, gl_uniq⟩ := F.exists_unique_gluing U sf sf_compatible, transitivity gl, { apply gl_uniq, intro i, refl }, { symmetry, apply gl_uniq, intro i, rw ← h }, end /-- In this version of the lemma, the inclusion homs `iUV` can be specified directly by the user, which can be more convenient in practice. -/ lemma eq_of_locally_eq' (V : opens X) (iUV : Π i : ι, U i ⟶ V) (hcover : V ≤ supr U) (s t : F.1.obj (op V)) (h : ∀ i, F.1.map (iUV i).op s = F.1.map (iUV i).op t) : s = t := begin have V_eq_supr_U : V = supr U := le_antisymm hcover (supr_le (λ i, (iUV i).le)), suffices : F.1.map (eq_to_hom V_eq_supr_U.symm).op s = F.1.map (eq_to_hom V_eq_supr_U.symm).op t, { convert congr_arg (F.1.map (eq_to_hom V_eq_supr_U).op) this ; rw [← comp_apply, ← F.1.map_comp, eq_to_hom_op, eq_to_hom_op, eq_to_hom_trans, eq_to_hom_refl, F.1.map_id, id_apply] }, apply eq_of_locally_eq, intro i, rw [← comp_apply, ← comp_apply, ← F.1.map_comp], convert h i, end end end sheaf end Top
c52288d0b271a31459569126c5051b4255d2b3fa
9b9a16fa2cb737daee6b2785474678b6fa91d6d4
/src/order/complete_lattice.lean
e0ce590b77b5d1b4dc896bd8cb63e90453bb4f1b
[ "Apache-2.0" ]
permissive
johoelzl/mathlib
253f46daa30b644d011e8e119025b01ad69735c4
592e3c7a2dfbd5826919b4605559d35d4d75938f
refs/heads/master
1,625,657,216,488
1,551,374,946,000
1,551,374,946,000
98,915,829
0
0
Apache-2.0
1,522,917,267,000
1,501,524,499,000
Lean
UTF-8
Lean
false
false
33,344
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl Theory of complete lattices. -/ import order.bounded_lattice data.set.basic tactic.pi_instances set_option old_structure_cmd true open set namespace lattice universes u v w w₂ variables {α : Type u} {β : Type v} {ι : Sort w} {ι₂ : Sort w₂} /-- class for the `Sup` operator -/ class has_Sup (α : Type u) := (Sup : set α → α) /-- class for the `Inf` operator -/ class has_Inf (α : Type u) := (Inf : set α → α) /-- Supremum of a set -/ def Sup [has_Sup α] : set α → α := has_Sup.Sup /-- Infimum of a set -/ def Inf [has_Inf α] : set α → α := has_Inf.Inf /-- Indexed supremum -/ def supr [has_Sup α] (s : ι → α) : α := Sup (range s) /-- Indexed infimum -/ def infi [has_Inf α] (s : ι → α) : α := Inf (range s) def has_Inf_to_nonempty (α) [has_Inf α] : nonempty α := ⟨Inf ∅⟩ def has_Sup_to_nonempty (α) [has_Sup α] : nonempty α := ⟨Sup ∅⟩ notation `⨆` binders `, ` r:(scoped f, supr f) := r notation `⨅` binders `, ` r:(scoped f, infi f) := r /-- A complete lattice is a bounded lattice which has suprema and infima for every subset. -/ class complete_lattice (α : Type u) extends bounded_lattice α, has_Sup α, has_Inf α := (le_Sup : ∀s, ∀a∈s, a ≤ Sup s) (Sup_le : ∀s a, (∀b∈s, b ≤ a) → Sup s ≤ a) (Inf_le : ∀s, ∀a∈s, Inf s ≤ a) (le_Inf : ∀s a, (∀b∈s, a ≤ b) → a ≤ Inf s) /-- A complete linear order is a linear order whose lattice structure is complete. -/ class complete_linear_order (α : Type u) extends complete_lattice α, decidable_linear_order α section variables [complete_lattice α] {s t : set α} {a b : α} @[ematch] theorem le_Sup : a ∈ s → a ≤ Sup s := complete_lattice.le_Sup s a theorem Sup_le : (∀b∈s, b ≤ a) → Sup s ≤ a := complete_lattice.Sup_le s a @[ematch] theorem Inf_le : a ∈ s → Inf s ≤ a := complete_lattice.Inf_le s a theorem le_Inf : (∀b∈s, a ≤ b) → a ≤ Inf s := complete_lattice.le_Inf s a theorem le_Sup_of_le (hb : b ∈ s) (h : a ≤ b) : a ≤ Sup s := le_trans h (le_Sup hb) theorem Inf_le_of_le (hb : b ∈ s) (h : b ≤ a) : Inf s ≤ a := le_trans (Inf_le hb) h theorem Sup_le_Sup (h : s ⊆ t) : Sup s ≤ Sup t := Sup_le (assume a, assume ha : a ∈ s, le_Sup $ h ha) theorem Inf_le_Inf (h : s ⊆ t) : Inf t ≤ Inf s := le_Inf (assume a, assume ha : a ∈ s, Inf_le $ h ha) @[simp] theorem Sup_le_iff : Sup s ≤ a ↔ (∀b ∈ s, b ≤ a) := ⟨assume : Sup s ≤ a, assume b, assume : b ∈ s, le_trans (le_Sup ‹b ∈ s›) ‹Sup s ≤ a›, Sup_le⟩ @[simp] theorem le_Inf_iff : a ≤ Inf s ↔ (∀b ∈ s, a ≤ b) := ⟨assume : a ≤ Inf s, assume b, assume : b ∈ s, le_trans ‹a ≤ Inf s› (Inf_le ‹b ∈ s›), le_Inf⟩ -- how to state this? instead a parameter `a`, use `∃a, a ∈ s` or `s ≠ ∅`? theorem Inf_le_Sup (h : a ∈ s) : Inf s ≤ Sup s := by have := le_Sup h; finish --Inf_le_of_le h (le_Sup h) -- TODO: it is weird that we have to add union_def theorem Sup_union {s t : set α} : Sup (s ∪ t) = Sup s ⊔ Sup t := le_antisymm (by finish) (sup_le (Sup_le_Sup $ subset_union_left _ _) (Sup_le_Sup $ subset_union_right _ _)) /- old proof: le_antisymm (Sup_le $ assume a h, or.rec_on h (le_sup_left_of_le ∘ le_Sup) (le_sup_right_of_le ∘ le_Sup)) (sup_le (Sup_le_Sup $ subset_union_left _ _) (Sup_le_Sup $ subset_union_right _ _)) -/ theorem Sup_inter_le {s t : set α} : Sup (s ∩ t) ≤ Sup s ⊓ Sup t := by finish /- Sup_le (assume a ⟨a_s, a_t⟩, le_inf (le_Sup a_s) (le_Sup a_t)) -/ theorem Inf_union {s t : set α} : Inf (s ∪ t) = Inf s ⊓ Inf t := le_antisymm (le_inf (Inf_le_Inf $ subset_union_left _ _) (Inf_le_Inf $ subset_union_right _ _)) (by finish) /- old proof: le_antisymm (le_inf (Inf_le_Inf $ subset_union_left _ _) (Inf_le_Inf $ subset_union_right _ _)) (le_Inf $ assume a h, or.rec_on h (inf_le_left_of_le ∘ Inf_le) (inf_le_right_of_le ∘ Inf_le)) -/ theorem le_Inf_inter {s t : set α} : Inf s ⊔ Inf t ≤ Inf (s ∩ t) := by finish /- le_Inf (assume a ⟨a_s, a_t⟩, sup_le (Inf_le a_s) (Inf_le a_t)) -/ @[simp] theorem Sup_empty : Sup ∅ = (⊥ : α) := le_antisymm (by finish) (by finish) -- le_antisymm (Sup_le (assume _, false.elim)) bot_le @[simp] theorem Inf_empty : Inf ∅ = (⊤ : α) := le_antisymm (by finish) (by finish) --le_antisymm le_top (le_Inf (assume _, false.elim)) @[simp] theorem Sup_univ : Sup univ = (⊤ : α) := le_antisymm (by finish) (le_Sup ⟨⟩) -- finish fails because ⊤ ≤ a simplifies to a = ⊤ --le_antisymm le_top (le_Sup ⟨⟩) @[simp] theorem Inf_univ : Inf univ = (⊥ : α) := le_antisymm (Inf_le ⟨⟩) bot_le -- TODO(Jeremy): get this automatically @[simp] theorem Sup_insert {a : α} {s : set α} : Sup (insert a s) = a ⊔ Sup s := have Sup {b | b = a} = a, from le_antisymm (Sup_le $ assume b b_eq, b_eq ▸ le_refl _) (le_Sup rfl), calc Sup (insert a s) = Sup {b | b = a} ⊔ Sup s : Sup_union ... = a ⊔ Sup s : by rw [this] @[simp] theorem Inf_insert {a : α} {s : set α} : Inf (insert a s) = a ⊓ Inf s := have Inf {b | b = a} = a, from le_antisymm (Inf_le rfl) (le_Inf $ assume b b_eq, b_eq ▸ le_refl _), calc Inf (insert a s) = Inf {b | b = a} ⊓ Inf s : Inf_union ... = a ⊓ Inf s : by rw [this] @[simp] theorem Sup_singleton {a : α} : Sup {a} = a := by finish [singleton_def] --eq.trans Sup_insert $ by simp @[simp] theorem Inf_singleton {a : α} : Inf {a} = a := by finish [singleton_def] --eq.trans Inf_insert $ by simp @[simp] theorem Inf_eq_top : Inf s = ⊤ ↔ (∀a∈s, a = ⊤) := iff.intro (assume h a ha, top_unique $ h ▸ Inf_le ha) (assume h, top_unique $ le_Inf $ assume a ha, top_le_iff.2 $ h a ha) @[simp] theorem Sup_eq_bot : Sup s = ⊥ ↔ (∀a∈s, a = ⊥) := iff.intro (assume h a ha, bot_unique $ h ▸ le_Sup ha) (assume h, bot_unique $ Sup_le $ assume a ha, le_bot_iff.2 $ h a ha) end section complete_linear_order variables [complete_linear_order α] {s t : set α} {a b : α} lemma Inf_lt_iff : Inf s < b ↔ (∃a∈s, a < b) := iff.intro (assume : Inf s < b, classical.by_contradiction $ assume : ¬ (∃a∈s, a < b), have b ≤ Inf s, from le_Inf $ assume a ha, le_of_not_gt $ assume h, this ⟨a, ha, h⟩, lt_irrefl b (lt_of_le_of_lt ‹b ≤ Inf s› ‹Inf s < b›)) (assume ⟨a, ha, h⟩, lt_of_le_of_lt (Inf_le ha) h) lemma lt_Sup_iff : b < Sup s ↔ (∃a∈s, b < a) := iff.intro (assume : b < Sup s, classical.by_contradiction $ assume : ¬ (∃a∈s, b < a), have Sup s ≤ b, from Sup_le $ assume a ha, le_of_not_gt $ assume h, this ⟨a, ha, h⟩, lt_irrefl b (lt_of_lt_of_le ‹b < Sup s› ‹Sup s ≤ b›)) (assume ⟨a, ha, h⟩, lt_of_lt_of_le h $ le_Sup ha) lemma Sup_eq_top : Sup s = ⊤ ↔ (∀b<⊤, ∃a∈s, b < a) := iff.intro (assume (h : Sup s = ⊤) b hb, by rwa [←h, lt_Sup_iff] at hb) (assume h, top_unique $ le_of_not_gt $ assume h', let ⟨a, ha, h⟩ := h _ h' in lt_irrefl a $ lt_of_le_of_lt (le_Sup ha) h) lemma Inf_eq_bot : Inf s = ⊥ ↔ (∀b>⊥, ∃a∈s, a < b) := iff.intro (assume (h : Inf s = ⊥) b (hb : ⊥ < b), by rwa [←h, Inf_lt_iff] at hb) (assume h, bot_unique $ le_of_not_gt $ assume h', let ⟨a, ha, h⟩ := h _ h' in lt_irrefl a $ lt_of_lt_of_le h (Inf_le ha)) lemma lt_supr_iff {ι : Sort*} {f : ι → α} : a < supr f ↔ (∃i, a < f i) := iff.trans lt_Sup_iff $ iff.intro (assume ⟨a', ⟨i, rfl⟩, ha⟩, ⟨i, ha⟩) (assume ⟨i, hi⟩, ⟨f i, ⟨i, rfl⟩, hi⟩) lemma infi_lt_iff {ι : Sort*} {f : ι → α} : infi f < a ↔ (∃i, f i < a) := iff.trans Inf_lt_iff $ iff.intro (assume ⟨a', ⟨i, rfl⟩, ha⟩, ⟨i, ha⟩) (assume ⟨i, hi⟩, ⟨f i, ⟨i, rfl⟩, hi⟩) end complete_linear_order /- supr & infi -/ section variables [complete_lattice α] {s t : ι → α} {a b : α} -- TODO: this declaration gives error when starting smt state --@[ematch] theorem le_supr (s : ι → α) (i : ι) : s i ≤ supr s := le_Sup ⟨i, rfl⟩ @[ematch] theorem le_supr' (s : ι → α) (i : ι) : (: s i ≤ supr s :) := le_Sup ⟨i, rfl⟩ /- TODO: this version would be more powerful, but, alas, the pattern matcher doesn't accept it. @[ematch] theorem le_supr' (s : ι → α) (i : ι) : (: s i :) ≤ (: supr s :) := le_Sup ⟨i, rfl⟩ -/ theorem le_supr_of_le (i : ι) (h : a ≤ s i) : a ≤ supr s := le_trans h (le_supr _ i) theorem supr_le (h : ∀i, s i ≤ a) : supr s ≤ a := Sup_le $ assume b ⟨i, eq⟩, eq ▸ h i theorem supr_le_supr (h : ∀i, s i ≤ t i) : supr s ≤ supr t := supr_le $ assume i, le_supr_of_le i (h i) theorem supr_le_supr2 {t : ι₂ → α} (h : ∀i, ∃j, s i ≤ t j) : supr s ≤ supr t := supr_le $ assume j, exists.elim (h j) le_supr_of_le theorem supr_le_supr_const (h : ι → ι₂) : (⨆ i:ι, a) ≤ (⨆ j:ι₂, a) := supr_le $ le_supr _ ∘ h @[simp] theorem supr_le_iff : supr s ≤ a ↔ (∀i, s i ≤ a) := ⟨assume : supr s ≤ a, assume i, le_trans (le_supr _ _) this, supr_le⟩ -- TODO: finish doesn't do well here. @[congr] theorem supr_congr_Prop {α : Type u} [has_Sup α] {p q : Prop} {f₁ : p → α} {f₂ : q → α} (pq : p ↔ q) (f : ∀x, f₁ (pq.mpr x) = f₂ x) : supr f₁ = supr f₂ := begin unfold supr, apply congr_arg, ext, simp, split, exact λ⟨h, W⟩, ⟨pq.1 h, eq.trans (f (pq.1 h)).symm W⟩, exact λ⟨h, W⟩, ⟨pq.2 h, eq.trans (f h) W⟩ end theorem infi_le (s : ι → α) (i : ι) : infi s ≤ s i := Inf_le ⟨i, rfl⟩ @[ematch] theorem infi_le' (s : ι → α) (i : ι) : (: infi s ≤ s i :) := Inf_le ⟨i, rfl⟩ /- I wanted to see if this would help for infi_comm; it doesn't. @[ematch] theorem infi_le₂' (s : ι → ι₂ → α) (i : ι) (j : ι₂): (: ⨅ i j, s i j :) ≤ (: s i j :) := begin transitivity, apply (infi_le (λ i, ⨅ j, s i j) i), apply infi_le end -/ theorem infi_le_of_le (i : ι) (h : s i ≤ a) : infi s ≤ a := le_trans (infi_le _ i) h theorem le_infi (h : ∀i, a ≤ s i) : a ≤ infi s := le_Inf $ assume b ⟨i, eq⟩, eq ▸ h i theorem infi_le_infi (h : ∀i, s i ≤ t i) : infi s ≤ infi t := le_infi $ assume i, infi_le_of_le i (h i) theorem infi_le_infi2 {t : ι₂ → α} (h : ∀j, ∃i, s i ≤ t j) : infi s ≤ infi t := le_infi $ assume j, exists.elim (h j) infi_le_of_le theorem infi_le_infi_const (h : ι₂ → ι) : (⨅ i:ι, a) ≤ (⨅ j:ι₂, a) := le_infi $ infi_le _ ∘ h @[simp] theorem le_infi_iff : a ≤ infi s ↔ (∀i, a ≤ s i) := ⟨assume : a ≤ infi s, assume i, le_trans this (infi_le _ _), le_infi⟩ @[congr] theorem infi_congr_Prop {α : Type u} [has_Inf α] {p q : Prop} {f₁ : p → α} {f₂ : q → α} (pq : p ↔ q) (f : ∀x, f₁ (pq.mpr x) = f₂ x) : infi f₁ = infi f₂ := begin unfold infi, apply congr_arg, ext, simp, split, exact λ⟨h, W⟩, ⟨pq.1 h, eq.trans (f (pq.1 h)).symm W⟩, exact λ⟨h, W⟩, ⟨pq.2 h, eq.trans (f h) W⟩ end @[simp] theorem infi_const {a : α} : ∀[nonempty ι], (⨅ b:ι, a) = a | ⟨i⟩ := le_antisymm (Inf_le ⟨i, rfl⟩) (by finish) @[simp] theorem supr_const {a : α} : ∀[nonempty ι], (⨆ b:ι, a) = a | ⟨i⟩ := le_antisymm (by finish) (le_Sup ⟨i, rfl⟩) @[simp] lemma infi_top : (⨅i:ι, ⊤ : α) = ⊤ := top_unique $ le_infi $ assume i, le_refl _ @[simp] lemma supr_bot : (⨆i:ι, ⊥ : α) = ⊥ := bot_unique $ supr_le $ assume i, le_refl _ @[simp] lemma infi_eq_top : infi s = ⊤ ↔ (∀i, s i = ⊤) := iff.intro (assume eq i, top_unique $ eq ▸ infi_le _ _) (assume h, top_unique $ le_infi $ assume i, top_le_iff.2 $ h i) @[simp] lemma supr_eq_bot : supr s = ⊥ ↔ (∀i, s i = ⊥) := iff.intro (assume eq i, bot_unique $ eq ▸ le_supr _ _) (assume h, bot_unique $ supr_le $ assume i, le_bot_iff.2 $ h i) @[simp] lemma infi_pos {p : Prop} {f : p → α} (hp : p) : (⨅ h : p, f h) = f hp := le_antisymm (infi_le _ _) (le_infi $ assume h, le_refl _) @[simp] lemma infi_neg {p : Prop} {f : p → α} (hp : ¬ p) : (⨅ h : p, f h) = ⊤ := le_antisymm le_top $ le_infi $ assume h, (hp h).elim @[simp] lemma supr_pos {p : Prop} {f : p → α} (hp : p) : (⨆ h : p, f h) = f hp := le_antisymm (supr_le $ assume h, le_refl _) (le_supr _ _) @[simp] lemma supr_neg {p : Prop} {f : p → α} (hp : ¬ p) : (⨆ h : p, f h) = ⊥ := le_antisymm (supr_le $ assume h, (hp h).elim) bot_le lemma supr_eq_dif {p : Prop} [decidable p] (a : p → α) : (⨆h:p, a h) = (if h : p then a h else ⊥) := by by_cases p; simp [h] lemma supr_eq_if {p : Prop} [decidable p] (a : α) : (⨆h:p, a) = (if p then a else ⊥) := by rw [supr_eq_dif, dif_eq_if] lemma infi_eq_dif {p : Prop} [decidable p] (a : p → α) : (⨅h:p, a h) = (if h : p then a h else ⊤) := by by_cases p; simp [h] lemma infi_eq_if {p : Prop} [decidable p] (a : α) : (⨅h:p, a) = (if p then a else ⊤) := by rw [infi_eq_dif, dif_eq_if] -- TODO: should this be @[simp]? theorem infi_comm {f : ι → ι₂ → α} : (⨅i, ⨅j, f i j) = (⨅j, ⨅i, f i j) := le_antisymm (le_infi $ assume i, le_infi $ assume j, infi_le_of_le j $ infi_le _ i) (le_infi $ assume j, le_infi $ assume i, infi_le_of_le i $ infi_le _ j) /- TODO: this is strange. In the proof below, we get exactly the desired among the equalities, but close does not get it. begin apply @le_antisymm, simp, intros, begin [smt] ematch, ematch, ematch, trace_state, have := le_refl (f i_1 i), trace_state, close end end -/ -- TODO: should this be @[simp]? theorem supr_comm {f : ι → ι₂ → α} : (⨆i, ⨆j, f i j) = (⨆j, ⨆i, f i j) := le_antisymm (supr_le $ assume i, supr_le $ assume j, le_supr_of_le j $ le_supr _ i) (supr_le $ assume j, supr_le $ assume i, le_supr_of_le i $ le_supr _ j) @[simp] theorem infi_infi_eq_left {b : β} {f : Πx:β, x = b → α} : (⨅x, ⨅h:x = b, f x h) = f b rfl := le_antisymm (infi_le_of_le b $ infi_le _ rfl) (le_infi $ assume b', le_infi $ assume eq, match b', eq with ._, rfl := le_refl _ end) @[simp] theorem infi_infi_eq_right {b : β} {f : Πx:β, b = x → α} : (⨅x, ⨅h:b = x, f x h) = f b rfl := le_antisymm (infi_le_of_le b $ infi_le _ rfl) (le_infi $ assume b', le_infi $ assume eq, match b', eq with ._, rfl := le_refl _ end) @[simp] theorem supr_supr_eq_left {b : β} {f : Πx:β, x = b → α} : (⨆x, ⨆h : x = b, f x h) = f b rfl := le_antisymm (supr_le $ assume b', supr_le $ assume eq, match b', eq with ._, rfl := le_refl _ end) (le_supr_of_le b $ le_supr _ rfl) @[simp] theorem supr_supr_eq_right {b : β} {f : Πx:β, b = x → α} : (⨆x, ⨆h : b = x, f x h) = f b rfl := le_antisymm (supr_le $ assume b', supr_le $ assume eq, match b', eq with ._, rfl := le_refl _ end) (le_supr_of_le b $ le_supr _ rfl) attribute [ematch] le_refl theorem infi_inf_eq {f g : ι → α} : (⨅ x, f x ⊓ g x) = (⨅ x, f x) ⊓ (⨅ x, g x) := le_antisymm (le_inf (le_infi $ assume i, infi_le_of_le i inf_le_left) (le_infi $ assume i, infi_le_of_le i inf_le_right)) (le_infi $ assume i, le_inf (inf_le_left_of_le $ infi_le _ _) (inf_le_right_of_le $ infi_le _ _)) /- TODO: here is another example where more flexible pattern matching might help. begin apply @le_antisymm, safe, pose h := f a ⊓ g a, begin [smt] ematch, ematch end end -/ lemma infi_inf {f : ι → α} {a : α} (i : ι) : (⨅x, f x) ⊓ a = (⨅ x, f x ⊓ a) := le_antisymm (le_infi $ assume i, le_inf (inf_le_left_of_le $ infi_le _ _) inf_le_right) (le_inf (infi_le_infi $ assume i, inf_le_left) (infi_le_of_le i inf_le_right)) lemma inf_infi {f : ι → α} {a : α} (i : ι) : a ⊓ (⨅x, f x) = (⨅ x, a ⊓ f x) := by rw [inf_comm, infi_inf i]; simp [inf_comm] lemma binfi_inf {ι : Sort*} {p : ι → Prop} {f : Πi, p i → α} {a : α} {i : ι} (hi : p i) : (⨅i (h : p i), f i h) ⊓ a = (⨅ i (h : p i), f i h ⊓ a) := le_antisymm (le_infi $ assume i, le_infi $ assume hi, le_inf (inf_le_left_of_le $ infi_le_of_le i $ infi_le _ _) inf_le_right) (le_inf (infi_le_infi $ assume i, infi_le_infi $ assume hi, inf_le_left) (infi_le_of_le i $ infi_le_of_le hi $ inf_le_right)) theorem supr_sup_eq {f g : β → α} : (⨆ x, f x ⊔ g x) = (⨆ x, f x) ⊔ (⨆ x, g x) := le_antisymm (supr_le $ assume i, sup_le (le_sup_left_of_le $ le_supr _ _) (le_sup_right_of_le $ le_supr _ _)) (sup_le (supr_le $ assume i, le_supr_of_le i le_sup_left) (supr_le $ assume i, le_supr_of_le i le_sup_right)) /- supr and infi under Prop -/ @[simp] theorem infi_false {s : false → α} : infi s = ⊤ := le_antisymm le_top (le_infi $ assume i, false.elim i) @[simp] theorem supr_false {s : false → α} : supr s = ⊥ := le_antisymm (supr_le $ assume i, false.elim i) bot_le @[simp] theorem infi_true {s : true → α} : infi s = s trivial := le_antisymm (infi_le _ _) (le_infi $ assume ⟨⟩, le_refl _) @[simp] theorem supr_true {s : true → α} : supr s = s trivial := le_antisymm (supr_le $ assume ⟨⟩, le_refl _) (le_supr _ _) @[simp] theorem infi_exists {p : ι → Prop} {f : Exists p → α} : (⨅ x, f x) = (⨅ i, ⨅ h:p i, f ⟨i, h⟩) := le_antisymm (le_infi $ assume i, le_infi $ assume : p i, infi_le _ _) (le_infi $ assume ⟨i, h⟩, infi_le_of_le i $ infi_le _ _) @[simp] theorem supr_exists {p : ι → Prop} {f : Exists p → α} : (⨆ x, f x) = (⨆ i, ⨆ h:p i, f ⟨i, h⟩) := le_antisymm (supr_le $ assume ⟨i, h⟩, le_supr_of_le i $ le_supr (λh:p i, f ⟨i, h⟩) _) (supr_le $ assume i, supr_le $ assume : p i, le_supr _ _) theorem infi_and {p q : Prop} {s : p ∧ q → α} : infi s = (⨅ h₁ h₂, s ⟨h₁, h₂⟩) := le_antisymm (le_infi $ assume i, le_infi $ assume j, infi_le _ _) (le_infi $ assume ⟨i, h⟩, infi_le_of_le i $ infi_le _ _) theorem supr_and {p q : Prop} {s : p ∧ q → α} : supr s = (⨆ h₁ h₂, s ⟨h₁, h₂⟩) := le_antisymm (supr_le $ assume ⟨i, h⟩, le_supr_of_le i $ le_supr (λj, s ⟨i, j⟩) _) (supr_le $ assume i, supr_le $ assume j, le_supr _ _) theorem infi_or {p q : Prop} {s : p ∨ q → α} : infi s = (⨅ h : p, s (or.inl h)) ⊓ (⨅ h : q, s (or.inr h)) := le_antisymm (le_inf (infi_le_infi2 $ assume j, ⟨_, le_refl _⟩) (infi_le_infi2 $ assume j, ⟨_, le_refl _⟩)) (le_infi $ assume i, match i with | or.inl i := inf_le_left_of_le $ infi_le _ _ | or.inr j := inf_le_right_of_le $ infi_le _ _ end) theorem supr_or {p q : Prop} {s : p ∨ q → α} : (⨆ x, s x) = (⨆ i, s (or.inl i)) ⊔ (⨆ j, s (or.inr j)) := le_antisymm (supr_le $ assume s, match s with | or.inl i := le_sup_left_of_le $ le_supr _ i | or.inr j := le_sup_right_of_le $ le_supr _ j end) (sup_le (supr_le_supr2 $ assume i, ⟨or.inl i, le_refl _⟩) (supr_le_supr2 $ assume j, ⟨or.inr j, le_refl _⟩)) theorem Inf_eq_infi {s : set α} : Inf s = (⨅a ∈ s, a) := le_antisymm (le_infi $ assume b, le_infi $ assume h, Inf_le h) (le_Inf $ assume b h, infi_le_of_le b $ infi_le _ h) theorem Sup_eq_supr {s : set α} : Sup s = (⨆a ∈ s, a) := le_antisymm (Sup_le $ assume b h, le_supr_of_le b $ le_supr _ h) (supr_le $ assume b, supr_le $ assume h, le_Sup h) lemma Sup_range {α : Type u} [has_Sup α] {f : ι → α} : Sup (range f) = supr f := rfl lemma Inf_range {α : Type u} [has_Inf α] {f : ι → α} : Inf (range f) = infi f := rfl lemma supr_range {g : β → α} {f : ι → β} : (⨆b∈range f, g b) = (⨆i, g (f i)) := le_antisymm (supr_le $ assume b, supr_le $ assume ⟨i, (h : f i = b)⟩, h ▸ le_supr _ i) (supr_le $ assume i, le_supr_of_le (f i) $ le_supr (λp, g (f i)) (mem_range_self _)) lemma infi_range {g : β → α} {f : ι → β} : (⨅b∈range f, g b) = (⨅i, g (f i)) := le_antisymm (le_infi $ assume i, infi_le_of_le (f i) $ infi_le (λp, g (f i)) (mem_range_self _)) (le_infi $ assume b, le_infi $ assume ⟨i, (h : f i = b)⟩, h ▸ infi_le _ i) theorem Inf_image {s : set β} {f : β → α} : Inf (f '' s) = (⨅ a ∈ s, f a) := calc Inf (set.image f s) = (⨅a, ⨅h : ∃b, b ∈ s ∧ f b = a, a) : Inf_eq_infi ... = (⨅a, ⨅b, ⨅h : f b = a ∧ b ∈ s, a) : by simp [and_comm] ... = (⨅a, ⨅b, ⨅h : a = f b, ⨅h : b ∈ s, a) : by simp [infi_and, eq_comm] ... = (⨅b, ⨅a, ⨅h : a = f b, ⨅h : b ∈ s, a) : by rw [infi_comm] ... = (⨅a∈s, f a) : congr_arg infi $ by funext x; rw [infi_infi_eq_left] theorem Sup_image {s : set β} {f : β → α} : Sup (f '' s) = (⨆ a ∈ s, f a) := calc Sup (set.image f s) = (⨆a, ⨆h : ∃b, b ∈ s ∧ f b = a, a) : Sup_eq_supr ... = (⨆a, ⨆b, ⨆h : f b = a ∧ b ∈ s, a) : by simp [and_comm] ... = (⨆a, ⨆b, ⨆h : a = f b, ⨆h : b ∈ s, a) : by simp [supr_and, eq_comm] ... = (⨆b, ⨆a, ⨆h : a = f b, ⨆h : b ∈ s, a) : by rw [supr_comm] ... = (⨆a∈s, f a) : congr_arg supr $ by funext x; rw [supr_supr_eq_left] /- supr and infi under set constructions -/ /- should work using the simplifier! -/ @[simp] theorem infi_emptyset {f : β → α} : (⨅ x ∈ (∅ : set β), f x) = ⊤ := le_antisymm le_top (le_infi $ assume x, le_infi false.elim) @[simp] theorem supr_emptyset {f : β → α} : (⨆ x ∈ (∅ : set β), f x) = ⊥ := le_antisymm (supr_le $ assume x, supr_le false.elim) bot_le @[simp] theorem infi_univ {f : β → α} : (⨅ x ∈ (univ : set β), f x) = (⨅ x, f x) := show (⨅ (x : β) (H : true), f x) = ⨅ (x : β), f x, from congr_arg infi $ funext $ assume x, infi_const @[simp] theorem supr_univ {f : β → α} : (⨆ x ∈ (univ : set β), f x) = (⨆ x, f x) := show (⨆ (x : β) (H : true), f x) = ⨆ (x : β), f x, from congr_arg supr $ funext $ assume x, supr_const @[simp] theorem infi_union {f : β → α} {s t : set β} : (⨅ x ∈ s ∪ t, f x) = (⨅x∈s, f x) ⊓ (⨅x∈t, f x) := calc (⨅ x ∈ s ∪ t, f x) = (⨅ x, (⨅h : x∈s, f x) ⊓ (⨅h : x∈t, f x)) : congr_arg infi $ funext $ assume x, infi_or ... = (⨅x∈s, f x) ⊓ (⨅x∈t, f x) : infi_inf_eq @[simp] theorem supr_union {f : β → α} {s t : set β} : (⨆ x ∈ s ∪ t, f x) = (⨆x∈s, f x) ⊔ (⨆x∈t, f x) := calc (⨆ x ∈ s ∪ t, f x) = (⨆ x, (⨆h : x∈s, f x) ⊔ (⨆h : x∈t, f x)) : congr_arg supr $ funext $ assume x, supr_or ... = (⨆x∈s, f x) ⊔ (⨆x∈t, f x) : supr_sup_eq @[simp] theorem insert_of_has_insert (x : α) (a : set α) : has_insert.insert x a = insert x a := rfl @[simp] theorem infi_insert {f : β → α} {s : set β} {b : β} : (⨅ x ∈ insert b s, f x) = f b ⊓ (⨅x∈s, f x) := eq.trans infi_union $ congr_arg (λx:α, x ⊓ (⨅x∈s, f x)) infi_infi_eq_left @[simp] theorem supr_insert {f : β → α} {s : set β} {b : β} : (⨆ x ∈ insert b s, f x) = f b ⊔ (⨆x∈s, f x) := eq.trans supr_union $ congr_arg (λx:α, x ⊔ (⨆x∈s, f x)) supr_supr_eq_left @[simp] theorem infi_singleton {f : β → α} {b : β} : (⨅ x ∈ (singleton b : set β), f x) = f b := show (⨅ x ∈ insert b (∅ : set β), f x) = f b, by simp @[simp] theorem supr_singleton {f : β → α} {b : β} : (⨆ x ∈ (singleton b : set β), f x) = f b := show (⨆ x ∈ insert b (∅ : set β), f x) = f b, by simp lemma infi_image {γ} {f : β → γ} {g : γ → α} {t : set β} : (⨅ c ∈ f '' t, g c) = (⨅ b ∈ t, g (f b)) := le_antisymm (le_infi $ assume b, le_infi $ assume hbt, infi_le_of_le (f b) $ infi_le (λ_, g (f b)) (mem_image_of_mem f hbt)) (le_infi $ assume c, le_infi $ assume ⟨b, hbt, eq⟩, eq ▸ infi_le_of_le b $ infi_le (λ_, g (f b)) hbt) lemma supr_image {γ} {f : β → γ} {g : γ → α} {t : set β} : (⨆ c ∈ f '' t, g c) = (⨆ b ∈ t, g (f b)) := le_antisymm (supr_le $ assume c, supr_le $ assume ⟨b, hbt, eq⟩, eq ▸ le_supr_of_le b $ le_supr (λ_, g (f b)) hbt) (supr_le $ assume b, supr_le $ assume hbt, le_supr_of_le (f b) $ le_supr (λ_, g (f b)) (mem_image_of_mem f hbt)) /- supr and infi under Type -/ @[simp] theorem infi_empty {s : empty → α} : infi s = ⊤ := le_antisymm le_top (le_infi $ assume i, empty.rec_on _ i) @[simp] theorem supr_empty {s : empty → α} : supr s = ⊥ := le_antisymm (supr_le $ assume i, empty.rec_on _ i) bot_le @[simp] theorem infi_unit {f : unit → α} : (⨅ x, f x) = f () := le_antisymm (infi_le _ _) (le_infi $ assume ⟨⟩, le_refl _) @[simp] theorem supr_unit {f : unit → α} : (⨆ x, f x) = f () := le_antisymm (supr_le $ assume ⟨⟩, le_refl _) (le_supr _ _) lemma supr_bool_eq {f : bool → α} : (⨆b:bool, f b) = f tt ⊔ f ff := le_antisymm (supr_le $ assume b, match b with tt := le_sup_left | ff := le_sup_right end) (sup_le (le_supr _ _) (le_supr _ _)) lemma infi_bool_eq {f : bool → α} : (⨅b:bool, f b) = f tt ⊓ f ff := le_antisymm (le_inf (infi_le _ _) (infi_le _ _)) (le_infi $ assume b, match b with tt := inf_le_left | ff := inf_le_right end) theorem infi_subtype {p : ι → Prop} {f : subtype p → α} : (⨅ x, f x) = (⨅ i (h:p i), f ⟨i, h⟩) := le_antisymm (le_infi $ assume i, le_infi $ assume : p i, infi_le _ _) (le_infi $ assume ⟨i, h⟩, infi_le_of_le i $ infi_le _ _) theorem supr_subtype {p : ι → Prop} {f : subtype p → α} : (⨆ x, f x) = (⨆ i (h:p i), f ⟨i, h⟩) := le_antisymm (supr_le $ assume ⟨i, h⟩, le_supr_of_le i $ le_supr (λh:p i, f ⟨i, h⟩) _) (supr_le $ assume i, supr_le $ assume : p i, le_supr _ _) theorem infi_sigma {p : β → Type w} {f : sigma p → α} : (⨅ x, f x) = (⨅ i (h:p i), f ⟨i, h⟩) := le_antisymm (le_infi $ assume i, le_infi $ assume : p i, infi_le _ _) (le_infi $ assume ⟨i, h⟩, infi_le_of_le i $ infi_le _ _) theorem supr_sigma {p : β → Type w} {f : sigma p → α} : (⨆ x, f x) = (⨆ i (h:p i), f ⟨i, h⟩) := le_antisymm (supr_le $ assume ⟨i, h⟩, le_supr_of_le i $ le_supr (λh:p i, f ⟨i, h⟩) _) (supr_le $ assume i, supr_le $ assume : p i, le_supr _ _) theorem infi_prod {γ : Type w} {f : β × γ → α} : (⨅ x, f x) = (⨅ i j, f (i, j)) := le_antisymm (le_infi $ assume i, le_infi $ assume j, infi_le _ _) (le_infi $ assume ⟨i, h⟩, infi_le_of_le i $ infi_le _ _) theorem supr_prod {γ : Type w} {f : β × γ → α} : (⨆ x, f x) = (⨆ i j, f (i, j)) := le_antisymm (supr_le $ assume ⟨i, h⟩, le_supr_of_le i $ le_supr (λj, f ⟨i, j⟩) _) (supr_le $ assume i, supr_le $ assume j, le_supr _ _) theorem infi_sum {γ : Type w} {f : β ⊕ γ → α} : (⨅ x, f x) = (⨅ i, f (sum.inl i)) ⊓ (⨅ j, f (sum.inr j)) := le_antisymm (le_inf (infi_le_infi2 $ assume i, ⟨_, le_refl _⟩) (infi_le_infi2 $ assume j, ⟨_, le_refl _⟩)) (le_infi $ assume s, match s with | sum.inl i := inf_le_left_of_le $ infi_le _ _ | sum.inr j := inf_le_right_of_le $ infi_le _ _ end) theorem supr_sum {γ : Type w} {f : β ⊕ γ → α} : (⨆ x, f x) = (⨆ i, f (sum.inl i)) ⊔ (⨆ j, f (sum.inr j)) := le_antisymm (supr_le $ assume s, match s with | sum.inl i := le_sup_left_of_le $ le_supr _ i | sum.inr j := le_sup_right_of_le $ le_supr _ j end) (sup_le (supr_le_supr2 $ assume i, ⟨sum.inl i, le_refl _⟩) (supr_le_supr2 $ assume j, ⟨sum.inr j, le_refl _⟩)) end section complete_linear_order variables [complete_linear_order α] lemma supr_eq_top (f : ι → α) : supr f = ⊤ ↔ (∀b<⊤, ∃i, b < f i) := by rw [← Sup_range, Sup_eq_top]; from forall_congr (assume b, forall_congr (assume hb, set.exists_range_iff)) lemma infi_eq_bot (f : ι → α) : infi f = ⊥ ↔ (∀b>⊥, ∃i, b > f i) := by rw [← Inf_range, Inf_eq_bot]; from forall_congr (assume b, forall_congr (assume hb, set.exists_range_iff)) end complete_linear_order /- Instances -/ instance complete_lattice_Prop : complete_lattice Prop := { Sup := λs, ∃a∈s, a, le_Sup := assume s a h p, ⟨a, h, p⟩, Sup_le := assume s a h ⟨b, h', p⟩, h b h' p, Inf := λs, ∀a:Prop, a∈s → a, Inf_le := assume s a h p, p a h, le_Inf := assume s a h p b hb, h b hb p, ..lattice.bounded_lattice_Prop } lemma Inf_Prop_eq {s : set Prop} : Inf s = (∀p ∈ s, p) := rfl lemma Sup_Prop_eq {s : set Prop} : Sup s = (∃p ∈ s, p) := rfl lemma infi_Prop_eq {ι : Sort*} {p : ι → Prop} : (⨅i, p i) = (∀i, p i) := le_antisymm (assume h i, h _ ⟨i, rfl⟩ ) (assume h p ⟨i, eq⟩, eq ▸ h i) lemma supr_Prop_eq {ι : Sort*} {p : ι → Prop} : (⨆i, p i) = (∃i, p i) := le_antisymm (assume ⟨q, ⟨i, (eq : p i = q)⟩, hq⟩, ⟨i, eq.symm ▸ hq⟩) (assume ⟨i, hi⟩, ⟨p i, ⟨i, rfl⟩, hi⟩) instance pi.complete_lattice {α : Type u} {β : α → Type v} [∀ i, complete_lattice (β i)] : complete_lattice (Π i, β i) := by { pi_instance; { intros, intro, apply_field, intros, simp at H, rcases H with ⟨ x, H₀, H₁ ⟩, subst b, apply a_1 _ H₀ i, } } lemma Inf_apply {α : Type u} {β : α → Type v} [∀ i, complete_lattice (β i)] {s : set (Πa, β a)} {a : α} : (Inf s) a = (⨅f∈s, (f : Πa, β a) a) := by rw [← Inf_image]; refl lemma infi_apply {α : Type u} {β : α → Type v} {ι : Sort*} [∀ i, complete_lattice (β i)] {f : ι → Πa, β a} {a : α} : (⨅i, f i) a = (⨅i, f i a) := by erw [← Inf_range, Inf_apply, infi_range] lemma Sup_apply {α : Type u} {β : α → Type v} [∀ i, complete_lattice (β i)] {s : set (Πa, β a)} {a : α} : (Sup s) a = (⨆f∈s, (f : Πa, β a) a) := by rw [← Sup_image]; refl lemma supr_apply {α : Type u} {β : α → Type v} {ι : Sort*} [∀ i, complete_lattice (β i)] {f : ι → Πa, β a} {a : α} : (⨆i, f i) a = (⨆i, f i a) := by erw [← Sup_range, Sup_apply, supr_range] section complete_lattice variables [preorder α] [complete_lattice β] theorem monotone_Sup_of_monotone {s : set (α → β)} (m_s : ∀f∈s, monotone f) : monotone (Sup s) := assume x y h, Sup_le $ assume x' ⟨f, f_in, fx_eq⟩, le_Sup_of_le ⟨f, f_in, rfl⟩ $ fx_eq ▸ m_s _ f_in h theorem monotone_Inf_of_monotone {s : set (α → β)} (m_s : ∀f∈s, monotone f) : monotone (Inf s) := assume x y h, le_Inf $ assume x' ⟨f, f_in, fx_eq⟩, Inf_le_of_le ⟨f, f_in, rfl⟩ $ fx_eq ▸ m_s _ f_in h end complete_lattice section ord_continuous open lattice variables [complete_lattice α] [complete_lattice β] /-- A function `f` between complete lattices is order-continuous if it preserves all suprema. -/ def ord_continuous (f : α → β) := ∀s : set α, f (Sup s) = (⨆i∈s, f i) lemma ord_continuous_sup {f : α → β} {a₁ a₂ : α} (hf : ord_continuous f) : f (a₁ ⊔ a₂) = f a₁ ⊔ f a₂ := have h : f (Sup {a₁, a₂}) = (⨆i∈({a₁, a₂} : set α), f i), from hf _, have h₁ : {a₁, a₂} = (insert a₂ {a₁} : set α), from rfl, begin rw [h₁, Sup_insert, Sup_singleton, sup_comm] at h, rw [h, supr_insert, supr_singleton, sup_comm] end lemma ord_continuous_mono {f : α → β} (hf : ord_continuous f) : monotone f := assume a₁ a₂ h, calc f a₁ ≤ f a₁ ⊔ f a₂ : le_sup_left ... = f (a₁ ⊔ a₂) : (ord_continuous_sup hf).symm ... = _ : by rw [sup_of_le_right h] end ord_continuous end lattice namespace order_dual open lattice variable (α : Type*) instance [has_Inf α] : has_Sup (order_dual α) := ⟨(Inf : set α → α)⟩ instance [has_Sup α] : has_Inf (order_dual α) := ⟨(Sup : set α → α)⟩ instance [complete_lattice α] : complete_lattice (order_dual α) := { le_Sup := @complete_lattice.Inf_le α _, Sup_le := @complete_lattice.le_Inf α _, Inf_le := @complete_lattice.le_Sup α _, le_Inf := @complete_lattice.Sup_le α _, .. order_dual.lattice.bounded_lattice α, ..order_dual.lattice.has_Sup α, ..order_dual.lattice.has_Inf α } instance [complete_linear_order α] : complete_linear_order (order_dual α) := { .. order_dual.lattice.complete_lattice α, .. order_dual.decidable_linear_order α } end order_dual namespace prod open lattice variables (α : Type*) (β : Type*) instance [has_Inf α] [has_Inf β] : has_Inf (α × β) := ⟨λs, (Inf (prod.fst '' s), Inf (prod.snd '' s))⟩ instance [has_Sup α] [has_Sup β] : has_Sup (α × β) := ⟨λs, (Sup (prod.fst '' s), Sup (prod.snd '' s))⟩ instance [complete_lattice α] [complete_lattice β] : complete_lattice (α × β) := { le_Sup := assume s p hab, ⟨le_Sup $ mem_image_of_mem _ hab, le_Sup $ mem_image_of_mem _ hab⟩, Sup_le := assume s p h, ⟨ Sup_le $ ball_image_of_ball $ assume p hp, (h p hp).1, Sup_le $ ball_image_of_ball $ assume p hp, (h p hp).2⟩, Inf_le := assume s p hab, ⟨Inf_le $ mem_image_of_mem _ hab, Inf_le $ mem_image_of_mem _ hab⟩, le_Inf := assume s p h, ⟨ le_Inf $ ball_image_of_ball $ assume p hp, (h p hp).1, le_Inf $ ball_image_of_ball $ assume p hp, (h p hp).2⟩, .. prod.lattice.bounded_lattice α β, .. prod.lattice.has_Sup α β, .. prod.lattice.has_Inf α β } end prod
734aea32adbcd0a43dc4357d078ad2ea1458506c
4727251e0cd73359b15b664c3170e5d754078599
/src/algebra/homology/homological_complex.lean
7c4851e060cc362dad54dc45b02479f6e3fc693e
[ "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
32,651
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 import category_theory.graded_object /-! # 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.category 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 lemma ext {C₁ C₂ : homological_complex V c} (h_X : C₁.X = C₂.X) (h_d : ∀ (i j : ι), c.rel i j → C₁.d i j ≫ eq_to_hom (congr_fun h_X j) = eq_to_hom (congr_fun h_X i) ≫ C₂.d i j) : C₁ = C₂ := begin cases C₁, cases C₂, dsimp at h_X, subst h_X, simp only [true_and, eq_self_iff_true, heq_iff_eq], ext i j, by_cases hij : c.rel i j, { simpa only [id_comp, eq_to_hom_refl, comp_id] using h_d i j hij, }, { rw [C₁_shape' i j hij, C₂_shape' i j hij], } 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 @[simp] lemma eq_to_hom_f {C₁ C₂ : homological_complex V c} (h : C₁ = C₂) (n : ι) : homological_complex.hom.f (eq_to_hom h) n = eq_to_hom (congr_fun (congr_arg homological_complex.X h) n) := by { subst h, refl, } -- 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 /-- The zero complex -/ noncomputable def zero [has_zero_object V] : homological_complex V c := { X := λ i, 0, d := λ i j, 0 } lemma is_zero_zero [has_zero_object V] : is_zero (zero : homological_complex V c) := by { refine ⟨λ X, ⟨⟨⟨0⟩, λ f, _⟩⟩, λ X, ⟨⟨⟨0⟩, λ f, _⟩⟩⟩; ext, } instance [has_zero_object V] : has_zero_object (homological_complex V c) := ⟨⟨zero, is_zero_zero⟩⟩ noncomputable instance [has_zero_object V] : inhabited (homological_complex V c) := ⟨zero⟩ 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 section variables (V c) /-- The functor picking out the `i`-th object of a complex. -/ @[simps] def eval (i : ι) : homological_complex V c ⥤ V := { obj := λ C, C.X i, map := λ C D f, f.f i, } /-- The functor forgetting the differential in a complex, obtaining a graded object. -/ @[simps] def forget : homological_complex V c ⥤ graded_object ι V := { obj := λ C, C.X, map := λ _ _ f, f.f } /-- Forgetting the differentials than picking out the `i`-th object is the same as just picking out the `i`-th object. -/ @[simps] def forget_eval (i : ι) : forget V c ⋙ graded_object.eval i ≅ eval V c i := nat_iso.of_components (λ X, iso.refl _) (by tidy) end 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} /-- The `i`-th component of an isomorphism of chain complexes. -/ @[simps] def iso_app (f : C₁ ≅ C₂) (i : ι) : C₁.X i ≅ C₂.X i := (eval V c i).map_iso f /-- Construct an isomorphism of chain complexes from isomorphism of the objects which commute with the differentials. -/ @[simps] def iso_of_components (f : Π i, C₁.X i ≅ C₂.X i) (hf : ∀ i j, c.rel i j → (f i).hom ≫ C₂.d i j = C₁.d i j ≫ (f j).hom) : C₁ ≅ C₂ := { hom := { f := λ i, (f i).hom, comm' := hf }, inv := { f := λ i, (f i).inv, comm' := λ i j hij, calc (f i).inv ≫ C₁.d i j = (f i).inv ≫ (C₁.d i j ≫ (f j).hom) ≫ (f j).inv : by simp ... = (f i).inv ≫ ((f i).hom ≫ C₂.d i j) ≫ (f j).inv : by rw hf i j hij ... = C₂.d i j ≫ (f j).inv : by simp }, hom_inv_id' := by { ext i, exact (f i).hom_inv_id }, inv_hom_id' := by { ext i, exact (f i).inv_hom_id } } @[simp] lemma iso_of_components_app (f : Π i, C₁.X i ≅ C₂.X i) (hf : ∀ i j, c.rel i j → (f i).hom ≫ C₂.d i j = C₁.d i j ≫ (f j).hom) (i : ι) : iso_app (iso_of_components f hf) i = f i := by { ext, simp, } 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, elementwise] 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, elementwise] 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
45fd3106531cc365f749f35ff880ddc926e0c6ed
a45212b1526d532e6e83c44ddca6a05795113ddc
/src/algebra/group.lean
41ad93fbb1b7e08039f628c70aa47e892256c035
[ "Apache-2.0" ]
permissive
fpvandoorn/mathlib
b21ab4068db079cbb8590b58fda9cc4bc1f35df4
b3433a51ea8bc07c4159c1073838fc0ee9b8f227
refs/heads/master
1,624,791,089,608
1,556,715,231,000
1,556,715,231,000
165,722,980
5
0
Apache-2.0
1,552,657,455,000
1,547,494,646,000
Lean
UTF-8
Lean
false
false
39,217
lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura Various multiplicative and additive structures. -/ import tactic.interactive data.option.defs section pending_1857 /- Transport multiplicative to additive -/ section transport open tactic @[user_attribute] meta def to_additive_attr : user_attribute (name_map name) name := { name := `to_additive, descr := "Transport multiplicative to additive", cache_cfg := ⟨λ ns, ns.mfoldl (λ dict n, do val ← to_additive_attr.get_param n, pure $ dict.insert n val) mk_name_map, []⟩, parser := lean.parser.ident, after_set := some $ λ src _ _, do env ← get_env, dict ← to_additive_attr.get_cache, tgt ← to_additive_attr.get_param src, (get_decl tgt >> skip) <|> transport_with_dict dict src tgt } end transport /- map operations -/ attribute [to_additive has_add.add] has_mul.mul attribute [to_additive has_zero.zero] has_one.one attribute [to_additive has_neg.neg] has_inv.inv attribute [to_additive has_add] has_mul attribute [to_additive has_zero] has_one attribute [to_additive has_neg] has_inv /- map constructors -/ attribute [to_additive has_add.mk] has_mul.mk attribute [to_additive has_zero.mk] has_one.mk attribute [to_additive has_neg.mk] has_inv.mk /- map structures -/ attribute [to_additive add_semigroup] semigroup attribute [to_additive add_semigroup.mk] semigroup.mk attribute [to_additive add_semigroup.to_has_add] semigroup.to_has_mul attribute [to_additive add_semigroup.add_assoc] semigroup.mul_assoc attribute [to_additive add_semigroup.add] semigroup.mul attribute [to_additive add_comm_semigroup] comm_semigroup attribute [to_additive add_comm_semigroup.mk] comm_semigroup.mk attribute [to_additive add_comm_semigroup.to_add_semigroup] comm_semigroup.to_semigroup attribute [to_additive add_comm_semigroup.add_comm] comm_semigroup.mul_comm attribute [to_additive add_left_cancel_semigroup] left_cancel_semigroup attribute [to_additive add_left_cancel_semigroup.mk] left_cancel_semigroup.mk attribute [to_additive add_left_cancel_semigroup.to_add_semigroup] left_cancel_semigroup.to_semigroup attribute [to_additive add_left_cancel_semigroup.add_left_cancel] left_cancel_semigroup.mul_left_cancel attribute [to_additive add_right_cancel_semigroup] right_cancel_semigroup attribute [to_additive add_right_cancel_semigroup.mk] right_cancel_semigroup.mk attribute [to_additive add_right_cancel_semigroup.to_add_semigroup] right_cancel_semigroup.to_semigroup attribute [to_additive add_right_cancel_semigroup.add_right_cancel] right_cancel_semigroup.mul_right_cancel attribute [to_additive add_monoid] monoid attribute [to_additive add_monoid.mk] monoid.mk attribute [to_additive add_monoid.to_has_zero] monoid.to_has_one attribute [to_additive add_monoid.to_add_semigroup] monoid.to_semigroup attribute [to_additive add_monoid.add] monoid.mul attribute [to_additive add_monoid.add_assoc] monoid.mul_assoc attribute [to_additive add_monoid.zero] monoid.one attribute [to_additive add_monoid.zero_add] monoid.one_mul attribute [to_additive add_monoid.add_zero] monoid.mul_one attribute [to_additive add_comm_monoid] comm_monoid attribute [to_additive add_comm_monoid.mk] comm_monoid.mk attribute [to_additive add_comm_monoid.to_add_monoid] comm_monoid.to_monoid attribute [to_additive add_comm_monoid.to_add_comm_semigroup] comm_monoid.to_comm_semigroup attribute [to_additive add_group] group attribute [to_additive add_group.mk] group.mk attribute [to_additive add_group.to_has_neg] group.to_has_inv attribute [to_additive add_group.to_add_monoid] group.to_monoid attribute [to_additive add_group.add_left_neg] group.mul_left_inv attribute [to_additive add_group.add] group.mul attribute [to_additive add_group.add_assoc] group.mul_assoc attribute [to_additive add_group.zero] group.one attribute [to_additive add_group.zero_add] group.one_mul attribute [to_additive add_group.add_zero] group.mul_one attribute [to_additive add_group.neg] group.inv attribute [to_additive add_comm_group] comm_group attribute [to_additive add_comm_group.mk] comm_group.mk attribute [to_additive add_comm_group.to_add_group] comm_group.to_group attribute [to_additive add_comm_group.to_add_comm_monoid] comm_group.to_comm_monoid /- map theorems -/ attribute [to_additive add_assoc] mul_assoc attribute [to_additive add_semigroup_to_is_associative] semigroup_to_is_associative attribute [to_additive add_comm] mul_comm attribute [to_additive add_comm_semigroup_to_is_commutative] comm_semigroup_to_is_commutative attribute [to_additive add_left_comm] mul_left_comm attribute [to_additive add_right_comm] mul_right_comm attribute [to_additive add_left_cancel] mul_left_cancel attribute [to_additive add_right_cancel] mul_right_cancel attribute [to_additive add_left_cancel_iff] mul_left_cancel_iff attribute [to_additive add_right_cancel_iff] mul_right_cancel_iff attribute [to_additive zero_add] one_mul attribute [to_additive add_zero] mul_one attribute [to_additive add_left_neg] mul_left_inv attribute [to_additive neg_add_self] inv_mul_self attribute [to_additive neg_add_cancel_left] inv_mul_cancel_left attribute [to_additive neg_add_cancel_right] inv_mul_cancel_right attribute [to_additive neg_eq_of_add_eq_zero] inv_eq_of_mul_eq_one attribute [to_additive neg_zero] one_inv attribute [to_additive neg_neg] inv_inv attribute [to_additive add_right_neg] mul_right_inv attribute [to_additive add_neg_self] mul_inv_self attribute [to_additive neg_inj] inv_inj attribute [to_additive add_group.add_left_cancel] group.mul_left_cancel attribute [to_additive add_group.add_right_cancel] group.mul_right_cancel attribute [to_additive add_group.to_left_cancel_add_semigroup] group.to_left_cancel_semigroup attribute [to_additive add_group.to_right_cancel_add_semigroup] group.to_right_cancel_semigroup attribute [to_additive add_neg_cancel_left] mul_inv_cancel_left attribute [to_additive add_neg_cancel_right] mul_inv_cancel_right attribute [to_additive neg_add_rev] mul_inv_rev attribute [to_additive eq_neg_of_eq_neg] eq_inv_of_eq_inv attribute [to_additive eq_neg_of_add_eq_zero] eq_inv_of_mul_eq_one attribute [to_additive eq_add_neg_of_add_eq] eq_mul_inv_of_mul_eq attribute [to_additive eq_neg_add_of_add_eq] eq_inv_mul_of_mul_eq attribute [to_additive neg_add_eq_of_eq_add] inv_mul_eq_of_eq_mul attribute [to_additive add_neg_eq_of_eq_add] mul_inv_eq_of_eq_mul attribute [to_additive eq_add_of_add_neg_eq] eq_mul_of_mul_inv_eq attribute [to_additive eq_add_of_neg_add_eq] eq_mul_of_inv_mul_eq attribute [to_additive add_eq_of_eq_neg_add] mul_eq_of_eq_inv_mul attribute [to_additive add_eq_of_eq_add_neg] mul_eq_of_eq_mul_inv attribute [to_additive neg_add] mul_inv end pending_1857 instance monoid_to_is_left_id {α : Type*} [monoid α] : is_left_id α (*) 1 := ⟨ monoid.one_mul ⟩ instance monoid_to_is_right_id {α : Type*} [monoid α] : is_right_id α (*) 1 := ⟨ monoid.mul_one ⟩ instance add_monoid_to_is_left_id {α : Type*} [add_monoid α] : is_left_id α (+) 0 := ⟨ add_monoid.zero_add ⟩ instance add_monoid_to_is_right_id {α : Type*} [add_monoid α] : is_right_id α (+) 0 := ⟨ add_monoid.add_zero ⟩ universes u v variables {α : Type u} {β : Type v} def additive (α : Type*) := α def multiplicative (α : Type*) := α instance [semigroup α] : add_semigroup (additive α) := { add := ((*) : α → α → α), add_assoc := @mul_assoc _ _ } instance [add_semigroup α] : semigroup (multiplicative α) := { mul := ((+) : α → α → α), mul_assoc := @add_assoc _ _ } instance [comm_semigroup α] : add_comm_semigroup (additive α) := { add_comm := @mul_comm _ _, ..additive.add_semigroup } instance [add_comm_semigroup α] : comm_semigroup (multiplicative α) := { mul_comm := @add_comm _ _, ..multiplicative.semigroup } instance [left_cancel_semigroup α] : add_left_cancel_semigroup (additive α) := { add_left_cancel := @mul_left_cancel _ _, ..additive.add_semigroup } instance [add_left_cancel_semigroup α] : left_cancel_semigroup (multiplicative α) := { mul_left_cancel := @add_left_cancel _ _, ..multiplicative.semigroup } instance [right_cancel_semigroup α] : add_right_cancel_semigroup (additive α) := { add_right_cancel := @mul_right_cancel _ _, ..additive.add_semigroup } instance [add_right_cancel_semigroup α] : right_cancel_semigroup (multiplicative α) := { mul_right_cancel := @add_right_cancel _ _, ..multiplicative.semigroup } @[simp, to_additive add_left_inj] theorem mul_left_inj [left_cancel_semigroup α] (a : α) {b c : α} : a * b = a * c ↔ b = c := ⟨mul_left_cancel, congr_arg _⟩ @[simp, to_additive add_right_inj] theorem mul_right_inj [right_cancel_semigroup α] (a : α) {b c : α} : b * a = c * a ↔ b = c := ⟨mul_right_cancel, congr_arg _⟩ structure units (α : Type u) [monoid α] := (val : α) (inv : α) (val_inv : val * inv = 1) (inv_val : inv * val = 1) namespace units variables [monoid α] {a b c : units α} instance : has_coe (units α) α := ⟨val⟩ @[extensionality] theorem ext : ∀ {a b : units α}, (a : α) = b → a = b | ⟨v, i₁, vi₁, iv₁⟩ ⟨v', i₂, vi₂, iv₂⟩ e := by change v = v' at e; subst v'; congr; simpa only [iv₂, vi₁, one_mul, mul_one] using mul_assoc i₂ v i₁ theorem ext_iff {a b : units α} : a = b ↔ (a : α) = b := ⟨congr_arg _, ext⟩ instance [decidable_eq α] : decidable_eq (units α) | a b := decidable_of_iff' _ ext_iff protected def mul (u₁ u₂ : units α) : units α := ⟨u₁.val * u₂.val, u₂.inv * u₁.inv, have u₁.val * (u₂.val * u₂.inv) * u₁.inv = 1, by rw [u₂.val_inv]; rw [mul_one, u₁.val_inv], by simpa only [mul_assoc], have u₂.inv * (u₁.inv * u₁.val) * u₂.val = 1, by rw [u₁.inv_val]; rw [mul_one, u₂.inv_val], by simpa only [mul_assoc]⟩ protected def inv' (u : units α) : units α := ⟨u.inv, u.val, u.inv_val, u.val_inv⟩ instance : has_mul (units α) := ⟨units.mul⟩ instance : has_one (units α) := ⟨⟨1, 1, mul_one 1, one_mul 1⟩⟩ instance : has_inv (units α) := ⟨units.inv'⟩ variables (a b) @[simp] lemma coe_mul : (↑(a * b) : α) = a * b := rfl @[simp] lemma coe_one : ((1 : units α) : α) = 1 := rfl lemma val_coe : (↑a : α) = a.val := rfl lemma coe_inv : ((a⁻¹ : units α) : α) = a.inv := rfl @[simp] lemma inv_mul : (↑a⁻¹ * a : α) = 1 := inv_val _ @[simp] lemma mul_inv : (a * ↑a⁻¹ : α) = 1 := val_inv _ @[simp] lemma mul_inv_cancel_left (a : units α) (b : α) : (a:α) * (↑a⁻¹ * b) = b := by rw [← mul_assoc, mul_inv, one_mul] @[simp] lemma inv_mul_cancel_left (a : units α) (b : α) : (↑a⁻¹:α) * (a * b) = b := by rw [← mul_assoc, inv_mul, one_mul] @[simp] lemma mul_inv_cancel_right (a : α) (b : units α) : a * b * ↑b⁻¹ = a := by rw [mul_assoc, mul_inv, mul_one] @[simp] lemma inv_mul_cancel_right (a : α) (b : units α) : a * ↑b⁻¹ * b = a := by rw [mul_assoc, inv_mul, mul_one] instance : group (units α) := by refine {mul := (*), one := 1, inv := has_inv.inv, ..}; { intros, apply ext, simp only [coe_mul, coe_one, mul_assoc, one_mul, mul_one, inv_mul] } instance {α} [comm_monoid α] : comm_group (units α) := { mul_comm := λ u₁ u₂, ext $ mul_comm _ _, ..units.group } instance [has_repr α] : has_repr (units α) := ⟨repr ∘ val⟩ @[simp] theorem mul_left_inj (a : units α) {b c : α} : (a:α) * b = a * c ↔ b = c := ⟨λ h, by simpa only [inv_mul_cancel_left] using congr_arg ((*) ↑(a⁻¹ : units α)) h, congr_arg _⟩ @[simp] theorem mul_right_inj (a : units α) {b c : α} : b * a = c * a ↔ b = c := ⟨λ h, by simpa only [mul_inv_cancel_right] using congr_arg (* ↑(a⁻¹ : units α)) h, congr_arg _⟩ end units theorem nat.units_eq_one (u : units ℕ) : u = 1 := units.ext $ nat.eq_one_of_dvd_one ⟨u.inv, u.val_inv.symm⟩ def units.mk_of_mul_eq_one [comm_monoid α] (a b : α) (hab : a * b = 1) : units α := ⟨a, b, hab, (mul_comm b a).trans hab⟩ instance [monoid α] : add_monoid (additive α) := { zero := (1 : α), zero_add := @one_mul _ _, add_zero := @mul_one _ _, ..additive.add_semigroup } instance [add_monoid α] : monoid (multiplicative α) := { one := (0 : α), one_mul := @zero_add _ _, mul_one := @add_zero _ _, ..multiplicative.semigroup } def free_monoid (α) := list α instance {α} : monoid (free_monoid α) := { one := [], mul := λ x y, (x ++ y : list α), mul_one := by intros; apply list.append_nil, one_mul := by intros; refl, mul_assoc := by intros; apply list.append_assoc } @[simp] lemma free_monoid.one_def {α} : (1 : free_monoid α) = [] := rfl @[simp] lemma free_monoid.mul_def {α} (xs ys : list α) : (xs * ys : free_monoid α) = (xs ++ ys : list α) := rfl def free_add_monoid (α) := list α instance {α} : add_monoid (free_add_monoid α) := { zero := [], add := λ x y, (x ++ y : list α), add_zero := by intros; apply list.append_nil, zero_add := by intros; refl, add_assoc := by intros; apply list.append_assoc } @[simp] lemma free_add_monoid.zero_def {α} : (1 : free_monoid α) = [] := rfl @[simp] lemma free_add_monoid.add_def {α} (xs ys : list α) : (xs * ys : free_monoid α) = (xs ++ ys : list α) := rfl section monoid variables [monoid α] {a b c : α} /-- Partial division. It is defined when the second argument is invertible, and unlike the division operator in `division_ring` it is not totalized at zero. -/ def divp (a : α) (u) : α := a * (u⁻¹ : units α) infix ` /ₚ `:70 := divp @[simp] theorem divp_self (u : units α) : (u : α) /ₚ u = 1 := units.mul_inv _ @[simp] theorem divp_one (a : α) : a /ₚ 1 = a := mul_one _ theorem divp_assoc (a b : α) (u : units α) : a * b /ₚ u = a * (b /ₚ u) := mul_assoc _ _ _ @[simp] theorem divp_mul_cancel (a : α) (u : units α) : a /ₚ u * u = a := (mul_assoc _ _ _).trans $ by rw [units.inv_mul, mul_one] @[simp] theorem mul_divp_cancel (a : α) (u : units α) : (a * u) /ₚ u = a := (mul_assoc _ _ _).trans $ by rw [units.mul_inv, mul_one] @[simp] theorem divp_right_inj (u : units α) {a b : α} : a /ₚ u = b /ₚ u ↔ a = b := units.mul_right_inj _ theorem divp_eq_one (a : α) (u : units α) : a /ₚ u = 1 ↔ a = u := (units.mul_right_inj u).symm.trans $ by rw [divp_mul_cancel, one_mul] @[simp] theorem one_divp (u : units α) : 1 /ₚ u = ↑u⁻¹ := one_mul _ end monoid instance [comm_monoid α] : add_comm_monoid (additive α) := { add_comm := @mul_comm α _, ..additive.add_monoid } instance [add_comm_monoid α] : comm_monoid (multiplicative α) := { mul_comm := @add_comm α _, ..multiplicative.monoid } instance [group α] : add_group (additive α) := { neg := @has_inv.inv α _, add_left_neg := @mul_left_inv _ _, ..additive.add_monoid } instance [add_group α] : group (multiplicative α) := { inv := @has_neg.neg α _, mul_left_inv := @add_left_neg _ _, ..multiplicative.monoid } section group variables [group α] {a b c : α} instance : has_lift α (units α) := ⟨λ a, ⟨a, a⁻¹, mul_inv_self _, inv_mul_self _⟩⟩ @[simp, to_additive neg_inj'] theorem inv_inj' : a⁻¹ = b⁻¹ ↔ a = b := ⟨λ h, by rw [← inv_inv a, h, inv_inv], congr_arg _⟩ @[to_additive eq_of_neg_eq_neg] theorem eq_of_inv_eq_inv : a⁻¹ = b⁻¹ → a = b := inv_inj'.1 @[simp, to_additive add_self_iff_eq_zero] theorem mul_self_iff_eq_one : a * a = a ↔ a = 1 := by have := @mul_left_inj _ _ a a 1; rwa mul_one at this @[simp, to_additive neg_eq_zero] theorem inv_eq_one : a⁻¹ = 1 ↔ a = 1 := by rw [← @inv_inj' _ _ a 1, one_inv] @[simp, to_additive neg_ne_zero] theorem inv_ne_one : a⁻¹ ≠ 1 ↔ a ≠ 1 := not_congr inv_eq_one @[to_additive left_inverse_neg] theorem left_inverse_inv (α) [group α] : function.left_inverse (λ a : α, a⁻¹) (λ a, a⁻¹) := assume a, inv_inv a attribute [simp] mul_inv_cancel_left add_neg_cancel_left mul_inv_cancel_right add_neg_cancel_right @[to_additive eq_neg_iff_eq_neg] theorem eq_inv_iff_eq_inv : a = b⁻¹ ↔ b = a⁻¹ := ⟨eq_inv_of_eq_inv, eq_inv_of_eq_inv⟩ @[to_additive neg_eq_iff_neg_eq] theorem inv_eq_iff_inv_eq : a⁻¹ = b ↔ b⁻¹ = a := by rw [eq_comm, @eq_comm _ _ a, eq_inv_iff_eq_inv] @[to_additive add_eq_zero_iff_eq_neg] theorem mul_eq_one_iff_eq_inv : a * b = 1 ↔ a = b⁻¹ := by simpa [mul_left_inv, -mul_right_inj] using @mul_right_inj _ _ b a (b⁻¹) @[to_additive add_eq_zero_iff_neg_eq] theorem mul_eq_one_iff_inv_eq : a * b = 1 ↔ a⁻¹ = b := by rw [mul_eq_one_iff_eq_inv, eq_inv_iff_eq_inv, eq_comm] @[to_additive eq_neg_iff_add_eq_zero] theorem eq_inv_iff_mul_eq_one : a = b⁻¹ ↔ a * b = 1 := mul_eq_one_iff_eq_inv.symm @[to_additive neg_eq_iff_add_eq_zero] theorem inv_eq_iff_mul_eq_one : a⁻¹ = b ↔ a * b = 1 := mul_eq_one_iff_inv_eq.symm @[to_additive eq_add_neg_iff_add_eq] theorem eq_mul_inv_iff_mul_eq : a = b * c⁻¹ ↔ a * c = b := ⟨λ h, by rw [h, inv_mul_cancel_right], λ h, by rw [← h, mul_inv_cancel_right]⟩ @[to_additive eq_neg_add_iff_add_eq] theorem eq_inv_mul_iff_mul_eq : a = b⁻¹ * c ↔ b * a = c := ⟨λ h, by rw [h, mul_inv_cancel_left], λ h, by rw [← h, inv_mul_cancel_left]⟩ @[to_additive neg_add_eq_iff_eq_add] theorem inv_mul_eq_iff_eq_mul : a⁻¹ * b = c ↔ b = a * c := ⟨λ h, by rw [← h, mul_inv_cancel_left], λ h, by rw [h, inv_mul_cancel_left]⟩ @[to_additive add_neg_eq_iff_eq_add] theorem mul_inv_eq_iff_eq_mul : a * b⁻¹ = c ↔ a = c * b := ⟨λ h, by rw [← h, inv_mul_cancel_right], λ h, by rw [h, mul_inv_cancel_right]⟩ @[to_additive add_neg_eq_zero] theorem mul_inv_eq_one {a b : α} : a * b⁻¹ = 1 ↔ a = b := by rw [mul_eq_one_iff_eq_inv, inv_inv] @[to_additive neg_comm_of_comm] theorem inv_comm_of_comm {a b : α} (H : a * b = b * a) : a⁻¹ * b = b * a⁻¹ := begin have : a⁻¹ * (b * a) * a⁻¹ = a⁻¹ * (a * b) * a⁻¹ := congr_arg (λ x:α, a⁻¹ * x * a⁻¹) H.symm, rwa [inv_mul_cancel_left, mul_assoc, mul_inv_cancel_right] at this end end group instance [comm_group α] : add_comm_group (additive α) := { add_comm := @mul_comm α _, ..additive.add_group } instance [add_comm_group α] : comm_group (multiplicative α) := { mul_comm := @add_comm α _, ..multiplicative.group } section add_monoid variables [add_monoid α] {a b c : α} @[simp] lemma bit0_zero : bit0 (0 : α) = 0 := add_zero _ @[simp] lemma bit1_zero [has_one α] : bit1 (0 : α) = 1 := show 0+0+1=(1:α), by rw [zero_add, zero_add] end add_monoid section add_group variables [add_group α] {a b c : α} local attribute [simp] sub_eq_add_neg def sub_sub_cancel := @sub_sub_self @[simp] lemma sub_left_inj : a - b = a - c ↔ b = c := (add_left_inj _).trans neg_inj' @[simp] lemma sub_right_inj : b - a = c - a ↔ b = c := add_right_inj _ lemma sub_add_sub_cancel (a b c : α) : (a - b) + (b - c) = a - c := by rw [← add_sub_assoc, sub_add_cancel] lemma sub_sub_sub_cancel_right (a b c : α) : (a - c) - (b - c) = a - b := by rw [← neg_sub c b, sub_neg_eq_add, sub_add_sub_cancel] theorem sub_eq_zero : a - b = 0 ↔ a = b := ⟨eq_of_sub_eq_zero, λ h, by rw [h, sub_self]⟩ theorem sub_ne_zero : a - b ≠ 0 ↔ a ≠ b := not_congr sub_eq_zero theorem eq_sub_iff_add_eq : a = b - c ↔ a + c = b := eq_add_neg_iff_add_eq theorem sub_eq_iff_eq_add : a - b = c ↔ a = c + b := add_neg_eq_iff_eq_add theorem eq_iff_eq_of_sub_eq_sub {a b c d : α} (H : a - b = c - d) : a = b ↔ c = d := by rw [← sub_eq_zero, H, sub_eq_zero] theorem left_inverse_sub_add_left (c : α) : function.left_inverse (λ x, x - c) (λ x, x + c) := assume x, add_sub_cancel x c theorem left_inverse_add_left_sub (c : α) : function.left_inverse (λ x, x + c) (λ x, x - c) := assume x, sub_add_cancel x c theorem left_inverse_add_right_neg_add (c : α) : function.left_inverse (λ x, c + x) (λ x, - c + x) := assume x, add_neg_cancel_left c x theorem left_inverse_neg_add_add_right (c : α) : function.left_inverse (λ x, - c + x) (λ x, c + x) := assume x, neg_add_cancel_left c x end add_group section add_comm_group variables [add_comm_group α] {a b c : α} lemma sub_eq_neg_add (a b : α) : a - b = -b + a := add_comm _ _ theorem neg_add' (a b : α) : -(a + b) = -a - b := neg_add a b lemma neg_sub_neg (a b : α) : -a - -b = b - a := by simp lemma eq_sub_iff_add_eq' : a = b - c ↔ c + a = b := by rw [eq_sub_iff_add_eq, add_comm] lemma sub_eq_iff_eq_add' : a - b = c ↔ a = b + c := by rw [sub_eq_iff_eq_add, add_comm] lemma add_sub_cancel' (a b : α) : a + b - a = b := by rw [sub_eq_neg_add, neg_add_cancel_left] lemma add_sub_cancel'_right (a b : α) : a + (b - a) = b := by rw [← add_sub_assoc, add_sub_cancel'] lemma sub_right_comm (a b c : α) : a - b - c = a - c - b := add_right_comm _ _ _ lemma sub_add_sub_cancel' (a b c : α) : (a - b) + (c - a) = c - b := by rw add_comm; apply sub_add_sub_cancel lemma sub_sub_sub_cancel_left (a b c : α) : (c - a) - (c - b) = b - a := by rw [← neg_sub b c, sub_neg_eq_add, add_comm, sub_add_sub_cancel] lemma sub_eq_sub_iff_sub_eq_sub {d : α} : a - b = c - d ↔ a - c = b - d := ⟨λ h, by rw eq_add_of_sub_eq h; simp, λ h, by rw eq_add_of_sub_eq h; simp⟩ end add_comm_group section is_conj variables [group α] [group β] def is_conj (a b : α) := ∃ c : α, c * a * c⁻¹ = b @[refl] lemma is_conj_refl (a : α) : is_conj a a := ⟨1, by rw [one_mul, one_inv, mul_one]⟩ @[symm] lemma is_conj_symm {a b : α} : is_conj a b → is_conj b a | ⟨c, hc⟩ := ⟨c⁻¹, by rw [← hc, mul_assoc, mul_inv_cancel_right, inv_mul_cancel_left]⟩ @[trans] lemma is_conj_trans {a b c : α} : is_conj a b → is_conj b c → is_conj a c | ⟨c₁, hc₁⟩ ⟨c₂, hc₂⟩ := ⟨c₂ * c₁, by rw [← hc₂, ← hc₁, mul_inv_rev]; simp only [mul_assoc]⟩ @[simp] lemma is_conj_one_right {a : α} : is_conj 1 a ↔ a = 1 := ⟨by simp [is_conj, is_conj_refl] {contextual := tt}, by simp [is_conj_refl] {contextual := tt}⟩ @[simp] lemma is_conj_one_left {a : α} : is_conj a 1 ↔ a = 1 := calc is_conj a 1 ↔ is_conj 1 a : ⟨is_conj_symm, is_conj_symm⟩ ... ↔ a = 1 : is_conj_one_right @[simp] lemma is_conj_iff_eq {α : Type*} [comm_group α] {a b : α} : is_conj a b ↔ a = b := ⟨λ ⟨c, hc⟩, by rw [← hc, mul_right_comm, mul_inv_self, one_mul], λ h, by rw h⟩ end is_conj class is_mul_hom {α β : Type*} [has_mul α] [has_mul β] (f : α → β) : Prop := (map_mul : ∀ {x y}, f (x * y) = f x * f y) class is_add_hom {α β : Type*} [has_add α] [has_add β] (f : α → β) : Prop := (map_add : ∀ {x y}, f (x + y) = f x + f y) attribute [to_additive is_add_hom] is_mul_hom attribute [to_additive is_add_hom.cases_on] is_mul_hom.cases_on attribute [to_additive is_add_hom.dcases_on] is_mul_hom.dcases_on attribute [to_additive is_add_hom.drec] is_mul_hom.drec attribute [to_additive is_add_hom.drec_on] is_mul_hom.drec_on attribute [to_additive is_add_hom.map_add] is_mul_hom.map_mul attribute [to_additive is_add_hom.mk] is_mul_hom.mk attribute [to_additive is_add_hom.rec] is_mul_hom.rec attribute [to_additive is_add_hom.rec_on] is_mul_hom.rec_on namespace is_mul_hom variables [has_mul α] [has_mul β] {γ : Type*} [has_mul γ] @[to_additive is_add_hom.id] lemma id : is_mul_hom (id : α → α) := {map_mul := λ _ _, rfl} @[to_additive is_add_hom.comp] lemma comp {f : α → β} {g : β → γ} (hf : is_mul_hom f) (hg : is_mul_hom g) : is_mul_hom (g ∘ f) := ⟨λ x y, by show _ = g _ * g _; rw [←hg.map_mul, ←hf.map_mul]⟩ @[to_additive is_add_hom.comp'] lemma comp' {f : α → β} {g : β → γ} (hf : is_mul_hom f) (hg : is_mul_hom g) : is_mul_hom (λ x, g (f x)) := ⟨λ x y, by rw [←hg.map_mul, ←hf.map_mul]⟩ end is_mul_hom class is_monoid_hom [monoid α] [monoid β] (f : α → β) extends is_mul_hom f : Prop := (map_one : f 1 = 1) class is_add_monoid_hom [add_monoid α] [add_monoid β] (f : α → β) extends is_add_hom f : Prop := (map_zero : f 0 = 0) attribute [to_additive is_add_monoid_hom] is_monoid_hom attribute [to_additive is_add_monoid_hom.mk] is_monoid_hom.mk attribute [to_additive is_add_monoid_hom.cases_on] is_monoid_hom.cases_on attribute [to_additive is_add_monoid_hom.dcases_on] is_monoid_hom.dcases_on attribute [to_additive is_add_monoid_hom.rec] is_monoid_hom.rec attribute [to_additive is_add_monoid_hom.drec] is_monoid_hom.drec attribute [to_additive is_add_monoid_hom.rec_on] is_monoid_hom.rec_on attribute [to_additive is_add_monoid_hom.drec_on] is_monoid_hom.drec_on attribute [to_additive is_add_monoid_hom.map_zero] is_monoid_hom.map_one namespace is_monoid_hom variables [monoid α] [monoid β] (f : α → β) [is_monoid_hom f] lemma map_mul {x y} : f (x * y) = f x * f y := is_mul_hom.map_mul f end is_monoid_hom namespace is_add_monoid_hom variables [add_monoid α] [add_monoid β] (f : α → β) [is_add_monoid_hom f] lemma map_add {x y} : f (x + y) = f x + f y := is_add_hom.map_add f attribute [to_additive is_add_monoid_hom.map_add] is_monoid_hom.map_mul end is_add_monoid_hom namespace is_monoid_hom variables [monoid α] [monoid β] (f : α → β) [is_monoid_hom f] @[to_additive is_add_monoid_hom.id] instance id : is_monoid_hom (@id α) := by refine {..}; intros; refl @[to_additive is_add_monoid_hom.comp] instance comp {γ} [monoid γ] (g : β → γ) [is_monoid_hom g] : is_monoid_hom (g ∘ f) := { map_mul := λ x y, show g _ = g _ * g _, by rw [map_mul f, map_mul g], map_one := show g _ = 1, by rw [map_one f, map_one g] } end is_monoid_hom namespace is_add_monoid_hom variables [add_monoid α] [add_monoid β] (f : α → β) [is_add_monoid_hom f] instance is_add_monoid_hom_mul_left {γ : Type*} [semiring γ] (x : γ) : is_add_monoid_hom (λ y : γ, x * y) := { map_zero := mul_zero x, map_add := λ y z, mul_add x y z } instance is_add_monoid_hom_mul_right {γ : Type*} [semiring γ] (x : γ) : is_add_monoid_hom (λ y : γ, y * x) := { map_zero := zero_mul x, map_add := λ y z, add_mul y z x } end is_add_monoid_hom /-- Predicate for group homomorphism. -/ class is_group_hom [group α] [group β] (f : α → β) : Prop := (map_mul : ∀ a b : α, f (a * b) = f a * f b) class is_add_group_hom [add_group α] [add_group β] (f : α → β) : Prop := (map_add : ∀ a b, f (a + b) = f a + f b) attribute [to_additive is_add_group_hom] is_group_hom attribute [to_additive is_add_group_hom.cases_on] is_group_hom.cases_on attribute [to_additive is_add_group_hom.dcases_on] is_group_hom.dcases_on attribute [to_additive is_add_group_hom.rec] is_group_hom.rec attribute [to_additive is_add_group_hom.drec] is_group_hom.drec attribute [to_additive is_add_group_hom.rec_on] is_group_hom.rec_on attribute [to_additive is_add_group_hom.drec_on] is_group_hom.drec_on attribute [to_additive is_add_group_hom.map_add] is_group_hom.map_mul attribute [to_additive is_add_group_hom.mk] is_group_hom.mk instance additive.is_add_group_hom [group α] [group β] (f : α → β) [is_group_hom f] : @is_add_group_hom (additive α) (additive β) _ _ f := ⟨@is_group_hom.map_mul α β _ _ f _⟩ instance multiplicative.is_group_hom [add_group α] [add_group β] (f : α → β) [is_add_group_hom f] : @is_group_hom (multiplicative α) (multiplicative β) _ _ f := ⟨@is_add_group_hom.map_add α β _ _ f _⟩ attribute [to_additive additive.is_add_group_hom] multiplicative.is_group_hom namespace is_group_hom variables [group α] [group β] (f : α → β) [is_group_hom f] @[to_additive is_add_group_hom.map_zero] theorem map_one : f 1 = 1 := mul_self_iff_eq_one.1 $ by rw [← map_mul f, one_mul] @[to_additive is_add_group_hom.map_neg] theorem map_inv (a : α) : f a⁻¹ = (f a)⁻¹ := eq_inv_of_mul_eq_one $ by rw [← map_mul f, inv_mul_self, map_one f] @[to_additive is_add_group_hom.id] instance id : is_group_hom (@id α) := ⟨λ _ _, rfl⟩ @[to_additive is_add_group_hom.comp] instance comp {γ} [group γ] (g : β → γ) [is_group_hom g] : is_group_hom (g ∘ f) := ⟨λ x y, show g _ = g _ * g _, by rw [map_mul f, map_mul g]⟩ protected lemma is_conj (f : α → β) [is_group_hom f] {a b : α} : is_conj a b → is_conj (f a) (f b) | ⟨c, hc⟩ := ⟨f c, by rw [← is_group_hom.map_mul f, ← is_group_hom.map_inv f, ← is_group_hom.map_mul f, hc]⟩ @[to_additive is_add_group_hom.to_is_add_monoid_hom] lemma to_is_monoid_hom (f : α → β) [is_group_hom f] : is_monoid_hom f := { map_one := is_group_hom.map_one f, map_mul := is_group_hom.map_mul f } @[to_additive is_add_group_hom.injective_iff] lemma injective_iff (f : α → β) [is_group_hom f] : function.injective f ↔ (∀ a, f a = 1 → a = 1) := ⟨λ h _, by rw ← is_group_hom.map_one f; exact @h _ _, λ h x y hxy, by rw [← inv_inv (f x), inv_eq_iff_mul_eq_one, ← is_group_hom.map_inv f, ← is_group_hom.map_mul f] at hxy; simpa using inv_eq_of_mul_eq_one (h _ hxy)⟩ attribute [instance] is_group_hom.to_is_monoid_hom is_add_group_hom.to_is_add_monoid_hom end is_group_hom @[to_additive is_add_group_hom.add] lemma is_group_hom.mul {α β} [group α] [comm_group β] (f g : α → β) [is_group_hom f] [is_group_hom g] : is_group_hom (λa, f a * g a) := ⟨assume a b, by simp only [is_group_hom.map_mul f, is_group_hom.map_mul g, mul_comm, mul_assoc, mul_left_comm]⟩ attribute [instance] is_group_hom.mul is_add_group_hom.add @[to_additive is_add_group_hom.neg] lemma is_group_hom.inv {α β} [group α] [comm_group β] (f : α → β) [is_group_hom f] : is_group_hom (λa, (f a)⁻¹) := ⟨assume a b, by rw [is_group_hom.map_mul f, mul_inv]⟩ attribute [instance] is_group_hom.inv is_add_group_hom.neg @[to_additive neg.is_add_group_hom] lemma inv.is_group_hom [comm_group α] : is_group_hom (has_inv.inv : α → α) := ⟨by simp [mul_inv_rev, mul_comm]⟩ attribute [instance] inv.is_group_hom neg.is_add_group_hom /-- Predicate for group anti-homomorphism, or a homomorphism into the opposite group. -/ class is_group_anti_hom {β : Type*} [group α] [group β] (f : α → β) : Prop := (map_mul : ∀ a b : α, f (a * b) = f b * f a) namespace is_group_anti_hom variables [group α] [group β] (f : α → β) [w : is_group_anti_hom f] include w theorem map_one : f 1 = 1 := mul_self_iff_eq_one.1 $ by rw [← map_mul f, one_mul] theorem map_inv (a : α) : f a⁻¹ = (f a)⁻¹ := eq_inv_of_mul_eq_one $ by rw [← map_mul f, mul_inv_self, map_one f] end is_group_anti_hom theorem inv_is_group_anti_hom [group α] : is_group_anti_hom (λ x : α, x⁻¹) := ⟨mul_inv_rev⟩ namespace is_add_group_hom variables [add_group α] [add_group β] (f : α → β) [is_add_group_hom f] lemma map_sub (a b) : f (a - b) = f a - f b := calc f (a - b) = f (a + -b) : rfl ... = f a + f (-b) : map_add f _ _ ... = f a - f b : by simp[map_neg f] end is_add_group_hom lemma is_add_group_hom.sub {α β} [add_group α] [add_comm_group β] (f g : α → β) [is_add_group_hom f] [is_add_group_hom g] : is_add_group_hom (λa, f a - g a) := is_add_group_hom.add f (λa, - g a) attribute [instance] is_add_group_hom.sub namespace units variables {γ : Type*} [monoid α] [monoid β] [monoid γ] (f : α → β) (g : β → γ) [is_monoid_hom f] [is_monoid_hom g] definition map : units α → units β := λ u, ⟨f u.val, f u.inv, by rw [← is_monoid_hom.map_mul f, u.val_inv, is_monoid_hom.map_one f], by rw [← is_monoid_hom.map_mul f, u.inv_val, is_monoid_hom.map_one f] ⟩ instance : is_group_hom (units.map f) := ⟨λ a b, by ext; exact is_monoid_hom.map_mul f ⟩ instance : is_monoid_hom (coe : units α → α) := { map_one := rfl, map_mul := by simp } @[simp] lemma coe_map (u : units α) : (map f u : β) = f u := rfl @[simp] lemma map_id : map (id : α → α) = id := by ext; refl lemma map_comp : map (g ∘ f) = map g ∘ map f := rfl lemma map_comp' : map (λ x, g (f x)) = λ x, map g (map f x) := rfl end units @[to_additive with_zero] def with_one (α) := option α @[to_additive with_zero.monad] instance : monad with_one := option.monad @[to_additive with_zero.has_zero] instance : has_one (with_one α) := ⟨none⟩ @[to_additive with_zero.has_coe_t] instance : has_coe_t α (with_one α) := ⟨some⟩ @[simp, to_additive with_zero.zero_ne_coe] lemma with_one.one_ne_coe {a : α} : (1 : with_one α) ≠ a := λ h, option.no_confusion h @[simp, to_additive with_zero.coe_ne_zero] lemma with_one.coe_ne_one {a : α} : (a : with_one α) ≠ (1 : with_one α) := λ h, option.no_confusion h @[to_additive with_zero.ne_zero_iff_exists] lemma with_one.ne_one_iff_exists : ∀ {x : with_one α}, x ≠ 1 ↔ ∃ (a : α), x = a | 1 := ⟨λ h, false.elim $ h rfl, by { rintros ⟨a,ha⟩ h, simpa using h }⟩ | (a : α) := ⟨λ h, ⟨a, rfl⟩, λ h, with_one.coe_ne_one⟩ @[to_additive with_zero.coe_inj] lemma with_one.coe_inj {a b : α} : (a : with_one α) = b ↔ a = b := option.some_inj @[elab_as_eliminator, to_additive with_zero.cases_on] protected lemma with_one.cases_on (P : with_one α → Prop) : ∀ (x : with_one α), P 1 → (∀ a : α, P a) → P x := option.cases_on attribute [to_additive with_zero.has_zero.equations._eqn_1] with_one.has_one.equations._eqn_1 @[to_additive with_zero.has_add] instance [has_mul α] : has_mul (with_one α) := { mul := option.lift_or_get (*) } @[simp, to_additive with_zero.add_coe] lemma with_one.mul_coe [has_mul α] (a b : α) : (a : with_one α) * b = (a * b : α) := rfl attribute [to_additive with_zero.has_add.equations._eqn_1] with_one.has_mul.equations._eqn_1 instance [semigroup α] : monoid (with_one α) := { mul_assoc := (option.lift_or_get_assoc _).1, one_mul := (option.lift_or_get_is_left_id _).1, mul_one := (option.lift_or_get_is_right_id _).1, ..with_one.has_one, ..with_one.has_mul } attribute [to_additive with_zero.add_monoid._proof_1] with_one.monoid._proof_1 attribute [to_additive with_zero.add_monoid._proof_2] with_one.monoid._proof_2 attribute [to_additive with_zero.add_monoid._proof_3] with_one.monoid._proof_3 attribute [to_additive with_zero.add_monoid] with_one.monoid attribute [to_additive with_zero.add_monoid.equations._eqn_1] with_one.monoid.equations._eqn_1 instance [comm_semigroup α] : comm_monoid (with_one α) := { mul_comm := (option.lift_or_get_comm _).1, ..with_one.monoid } instance [add_comm_semigroup α] : add_comm_monoid (with_zero α) := { add_comm := (option.lift_or_get_comm _).1, ..with_zero.add_monoid } attribute [to_additive with_zero.add_comm_monoid] with_one.comm_monoid namespace with_zero instance [one : has_one α] : has_one (with_zero α) := { ..one } instance [has_one α] : zero_ne_one_class (with_zero α) := { zero_ne_one := λ h, option.no_confusion h, ..with_zero.has_zero, ..with_zero.has_one } lemma coe_one [has_one α] : ((1 : α) : with_zero α) = 1 := rfl instance [has_mul α] : mul_zero_class (with_zero α) := { mul := λ o₁ o₂, o₁.bind (λ a, o₂.map (λ b, a * b)), zero_mul := λ a, rfl, mul_zero := λ a, by cases a; refl, ..with_zero.has_zero } @[simp] lemma mul_coe [has_mul α] (a b : α) : (a : with_zero α) * b = (a * b : α) := rfl instance [semigroup α] : semigroup (with_zero α) := { mul_assoc := λ a b c, match a, b, c with | none, _, _ := rfl | some a, none, _ := rfl | some a, some b, none := rfl | some a, some b, some c := congr_arg some (mul_assoc _ _ _) end, ..with_zero.mul_zero_class } instance [comm_semigroup α] : comm_semigroup (with_zero α) := { mul_comm := λ a b, match a, b with | none, _ := (mul_zero _).symm | some a, none := rfl | some a, some b := congr_arg some (mul_comm _ _) end, ..with_zero.semigroup } instance [monoid α] : monoid (with_zero α) := { one_mul := λ a, match a with | none := rfl | some a := congr_arg some $ one_mul _ end, mul_one := λ a, match a with | none := rfl | some a := congr_arg some $ mul_one _ end, ..with_zero.zero_ne_one_class, ..with_zero.semigroup } instance [comm_monoid α] : comm_monoid (with_zero α) := { ..with_zero.monoid, ..with_zero.comm_semigroup } definition inv [has_inv α] (x : with_zero α) : with_zero α := do a ← x, return a⁻¹ instance [has_inv α] : has_inv (with_zero α) := ⟨with_zero.inv⟩ @[simp] lemma inv_coe [has_inv α] (a : α) : (a : with_zero α)⁻¹ = (a⁻¹ : α) := rfl @[simp] lemma inv_zero [has_inv α] : (0 : with_zero α)⁻¹ = 0 := rfl section group variables [group α] @[simp] lemma inv_one : (1 : with_zero α)⁻¹ = 1 := show ((1⁻¹ : α) : with_zero α) = 1, by simp [coe_one] definition with_zero.div (x y : with_zero α) : with_zero α := x * y⁻¹ instance : has_div (with_zero α) := ⟨with_zero.div⟩ @[simp] lemma zero_div (a : with_zero α) : 0 / a = 0 := rfl @[simp] lemma div_zero (a : with_zero α) : a / 0 = 0 := by change a * _ = _; simp lemma div_coe (a b : α) : (a : with_zero α) / b = (a * b⁻¹ : α) := rfl lemma one_div (x : with_zero α) : 1 / x = x⁻¹ := one_mul _ @[simp] lemma div_one : ∀ (x : with_zero α), x / 1 = x | 0 := rfl | (a : α) := show _ * _ = _, by simp @[simp] lemma mul_right_inv : ∀ (x : with_zero α) (h : x ≠ 0), x * x⁻¹ = 1 | 0 h := false.elim $ h rfl | (a : α) h := by simp [coe_one] @[simp] lemma mul_left_inv : ∀ (x : with_zero α) (h : x ≠ 0), x⁻¹ * x = 1 | 0 h := false.elim $ h rfl | (a : α) h := by simp [coe_one] @[simp] lemma mul_inv_rev : ∀ (x y : with_zero α), (x * y)⁻¹ = y⁻¹ * x⁻¹ | 0 0 := rfl | 0 (b : α) := rfl | (a : α) 0 := rfl | (a : α) (b : α) := by simp @[simp] lemma mul_div_cancel {a b : with_zero α} (hb : b ≠ 0) : a * b / b = a := show _ * _ * _ = _, by simp [mul_assoc, hb] @[simp] lemma div_mul_cancel {a b : with_zero α} (hb : b ≠ 0) : a / b * b = a := show _ * _ * _ = _, by simp [mul_assoc, hb] lemma div_eq_iff_mul_eq {a b c : with_zero α} (hb : b ≠ 0) : a / b = c ↔ c * b = a := by split; intro h; simp [h.symm, hb] end group section comm_group variables [comm_group α] {a b c d : with_zero α} lemma div_eq_div (hb : b ≠ 0) (hd : d ≠ 0) : a / b = c / d ↔ a * d = b * c := begin rw ne_zero_iff_exists at hb hd, rcases hb with ⟨b, rfl⟩, rcases hd with ⟨d, rfl⟩, induction a using with_zero.cases_on; induction c using with_zero.cases_on, { refl }, { simp [div_coe] }, { simp [div_coe] }, erw [with_zero.coe_inj, with_zero.coe_inj], show a * b⁻¹ = c * d⁻¹ ↔ a * d = b * c, split; intro H, { rw mul_inv_eq_iff_eq_mul at H, rw [H, mul_right_comm, inv_mul_cancel_right, mul_comm] }, { rw [mul_inv_eq_iff_eq_mul, mul_right_comm, mul_comm c, ← H, mul_inv_cancel_right] } end end comm_group end with_zero
1c98be3015120decdfe156a1eb8b0782d9fce6bd
e37bb385769d6f4ac9931236fd07b708397e086b
/src/exercises/src_35_algebraic_axioms.lean
3c14302df16a1ca1b00e9ba34ea1687964b7eebc
[]
no_license
gihanmarasingha/ems_reals
5f5d5b9d9dfb5a10da465046336d74995132dff6
9df527742db69d0a389add44b506538fdb4d0800
refs/heads/master
1,675,327,747,064
1,608,036,820,000
1,608,036,820,000
315,825,726
0
0
null
null
null
null
UTF-8
Lean
false
false
8,462
lean
import ..library.src_field import tactic namespace mth1001 namespace myreal section grouplaws variables {R : Type} [comm_group R] /- The following six lemmas are 'user-friendly' variants of the first four axioms of the real number system. I have split each of the additive identity and additive inverse axioms into two lemmas.begin For example, `zero_add` and `add_zero` together constitute the additive identity axiom. -/ lemma add_comm (x y : R) : x + y = y + x := comm_group.add_comm x y lemma add_assoc (x y z : R) : (x + y) + z = x + (y + z) := comm_group.add_assoc x y z lemma add_zero (x : R) : x + 0 = x := comm_group.add_zero x lemma zero_add (x : R) : 0 + x = x := by {rw [add_comm, add_zero]} lemma add_neg (x : R) : x + (-x) = 0 := comm_group.add_inv x lemma neg_add (x : R) : (-x) + x = 0 := by {rw [add_comm, add_neg]} -- We define what it means for `u` to be an additive identity. def add_identity (u : R) := ∀ x : R, (x + u = x) ∧ (u + x = x) -- `0` is an additive identity. example : add_identity (0 : R) := begin intro x, exact and.intro (add_zero x) (zero_add x), end -- The additive identity is unique. theorem add_identity_unique {a b : R} (h₁ : add_identity a) (h₂ : add_identity b) : a = b := begin specialize h₁ b, -- `h₁ : (b + a = b) ∧ (a + b = b)` specialize h₂ a, -- `h₂ : (a + b = a) ∧ (b + a = a)` calc a = a + b : h₂.left.symm -- If `h : x = y`, then `h.symm : y = x`. ... = b : h₁.right end -- Definition of additive inverse. def add_inverse (y x : R) := (x + y = 0) ∧ (y + x = 0) -- Every real number has an additive inverse. lemma has_add_inverse : ∀ a : R, ∃ b : R, add_inverse b a := begin intro a, use (-a), exact and.intro (add_neg a) (neg_add a) end -- The additive inverse is unique. theorem add_inverse_unique {a b x : R} (h₁ : add_inverse a x) (h₂ : add_inverse b x) : a = b := calc a = a + 0 : (add_zero a).symm ... = a + (x + b) : by rw h₂.left ... = (a + x) + b : by rw add_assoc ... = 0 + b : by rw h₁.right ... = b : zero_add b -- Exercise 001: -- Complete the following with a `calc` style proof. lemma add_left_eq_self_mp {x a : R} : x + a = a → x = 0 := begin intro h, sorry end -- Exercise 002: lemma add_left_eq_self_mpr {x a : R} : x = 0 → x + a = a := begin sorry end -- Exercise 003: theorem add_left_eq_self (x a : R) : x + a = a ↔ x = 0:= begin split, { exact add_left_eq_self_mp, }, { sorry, }, end -- Exercise 004: -- Use `split` as above. theorem add_left_inj (x a b : R) : a + x = b + x ↔ a = b := begin sorry end lemma sub_eq_add_neg (x y : R) : x - y = x + (-y) := rfl -- Exercise 005: -- You can do the following with two rewrites. Use `add_zero` and `neg_add` lemma neg_zero : -(0 : R) = 0 := sorry -- Exercise 006: lemma sub_zero (a : R) : a - 0 = a := sorry -- Exercise 007: -- The following can be proved in one line as a sequences of rewrites. theorem sub_eq_zero_iff_eq (x y : R) : x - y = 0 ↔ x = y := sorry -- Exercise 008: -- The following can be proved in one line as a sequences of rewrites. theorem neg_neg (x : R) : - - x = x := sorry -- Exercise 009: -- Do the following using proof by calculation. lemma neg_add_eq_neg_add_neg (x y : R) : -(x + y) = -y + - x := sorry end grouplaws section fieldlaws variables {R : Type} [myfield R] /- The following lemmas encapsulate the remaining algebraic axioms of the real number type. -/ lemma mul_comm (x y : R) : x * y = y * x := myfield.mul_comm x y lemma mul_assoc (x y z : R) : (x * y) * z = x * (y * z) := myfield.mul_assoc x y z lemma mul_one (x : R) : x * 1 = x := myfield.mul_one x lemma one_mul (x : R) : 1 * x = x := by { rw [mul_comm, mul_one] } lemma mul_inv (x : R) : x ≠ 0 → x * x⁻¹ = 1 := myfield.mul_inv x lemma inv_mul (x : R) : x ≠ 0 → x⁻¹ * x = 1 := by {intro h, rw [mul_comm, mul_inv x h], } lemma mul_add (x y z : R) : x * (y + z) = x * y + x * z := myfield.mul_add x y z lemma zero_ne_one : (0 : R) ≠ (1 : R) := myfield.zero_ne_one def mul_identity (u : R) := ∀ x : R, (x * u = x) ∧ (u * x = x) -- Exercise 010: -- Use `add_mul` and `add_comm` to prove the following. theorem add_mul (x y z : R) : (x + y) * z = x * z + y * z := begin sorry end -- Exercise 011: theorem mul_identity_unique {a b : R} (h₁ : mul_identity a) (h₂ : mul_identity b) : a = b := begin sorry end def mul_inverse (y x : R) := (x * y = 1) ∧ (y * x = 1) -- Exercise 012: theorem mul_inverse_unique {a b x : R} (h₁ : mul_inverse a x) (h₂ : mul_inverse b x) : a = b := sorry -- Exercise 013: -- This exercise is somewhat challenging. theorem mul_zero {x : R} : x * (0 : R) = (0 : R) := begin have h₁ : x * 0 = x * 0 + x * 0, calc x * 0 = x * (0 + 0) : by rw add_zero (0 : R) ... = x * 0 + x * 0 : by rw mul_add, sorry end -- Exercise 014: -- Whereas the next result is a simple consequence of the previous result. theorem zero_mul {x : R} : (0 : R) * x = (0 : R) := begin sorry end -- Exercise 015: theorem neg_one_mul (x : R) : (-1) * x = -x := begin sorry end -- Exercise 016: -- Use the result above to prove this lemma. lemma neg_one_mul_neg_one : (-(1 : R)) * (-1) = 1 := sorry -- Exercise 017: lemma neg_mul_eq_mul_neg (x y : R) : -(x * y) = x * (-y) := sorry lemma neg_mul_neg_self (x : R) : (-x)*(-x) = x * x := by rw [←neg_one_mul, mul_assoc, mul_comm x _, ←mul_assoc, ←mul_assoc, neg_one_mul_neg_one, one_mul] -- Exercise 018: lemma neg_mul_neg (x y : R) : (-x) * (-y) = x * y := begin sorry end -- Exercise 019: lemma one_inv : (1 : R)⁻¹ = (1 : R) := sorry -- Exercise 020: theorem mul_sub (x y z : R) : x * (y - z) = x * y - x * z := begin sorry end -- Exercise 021: theorem mul_left_inj' (x a b : R) (h₁ : x ≠ 0): a * x = b * x ↔ a = b := begin sorry end open_locale classical -- Exercise 022: -- This is a challenging exercise. -- Hint 1. Do a `by_cases` proof, depending on whether `x = 0` or not. -- Hint 2. Use the fact that a non-zero real number has a multiplicative inverse. lemma eq_zero_of_not_eq_zero_of_mul_not_eq_zero (x b : R) (h₁ : b ≠ 0) (h₂ : x * b = 0) : x = 0 := begin sorry end -- Exercise 023: -- The following is a corollary of the result above. lemma eq_zero_or_eq_zero_of_mul_eq_zero (x y : R) (h : x * y = 0) : x = 0 ∨ y = 0 := begin sorry end -- Exercise 024: lemma mul_inv' (x y : R) (h₁ : x ≠ 0) (h₂ : y ≠ 0) : (x * y)⁻¹ = y⁻¹ * x⁻¹ := begin have h : x * y ≠ 0, { sorry, }, rw ←(mul_left_inj' _ _ _ h₁), sorry end -- Exercise 025: theorem inv_ne_zero {a : R} : a ≠ 0 → a⁻¹ ≠ 0 := begin sorry end -- Exercise 026: theorem inv_inv' (a : R) (h : a ≠ 0 ) : (a⁻¹)⁻¹ = a := begin sorry end end fieldlaws section powers variables {R : Type} [myfield R] -- The following lemma is essentially the definition of exponentiation. lemma pow_succ (x : R) (n : ℕ) : x^(n+1) = x * x^n := rfl -- We have a couple of fundamental results. lemma pow_zero (x : R) : x ^ 0 = 1 := rfl lemma pow_one (x : R) : x ^ 1 = x := by rw [pow_succ, pow_zero, mul_one] lemma pow_succ' (x : R) (n : ℕ) : x^(n+1) = x^n * x := by rw [pow_succ, mul_comm] -- Exercise 027: -- Rewrite using the above lemmas to prove this result. lemma pow_two (x : R) : x ^ 2 = x * x := begin sorry end -- Exercise 028: -- Prove the following by induction on `n`. theorem pow_ne_zero {x : R} (n : ℕ) (h : x ≠ 0) : x ^ n ≠ 0 := begin sorry end -- Exercise 029: -- Use induction. Make use of `nat.add_zero` and `nat.add_succ` theorem pow_add (x : R) (m n : ℕ) : x ^ (m + n) = (x ^ m) * (x ^ n) := begin sorry end -- Exercise 030: -- Use induction. Make use of `nat.mul_zero`, `nat.succ_eq_add_one`, and `nat.mul_one`. -- You'll need `left_distrib`, a synonym of `mul_add` for `ℕ`. theorem pow_mul (x : R) (m n : ℕ) : x ^ (m*n) = (x ^ m) ^ n := begin sorry end example (m n : ℕ) (h : m ≤ n) : n - m + m = n := nat.sub_add_cancel h -- Exercise 031: -- Use `nat.sub_add_cancel` (as demonstrated above). theorem pow_sub_mul_pow (x : R) {m n : ℕ} (h : m ≤ n) : x ^ (n - m) * x ^ m = x ^ n := begin rw [←pow_add, nat.sub_add_cancel h], end -- Exercise 032: theorem pow_sub' (x : R) (m n : ℕ) (h : m ≤ n) (ne0 : x ≠ 0) : x ^ (n - m) = (x ^ n) * (x ^ m)⁻¹ := begin sorry end end powers end myreal end mth1001
0b6cffb3816379b5e732e527a1a3c987107e8b48
ea5678cc400c34ff95b661fa26d15024e27ea8cd
/test5.lean
2e0b5dadebd5056ad5e6f695f43bef6107260841
[]
no_license
ChrisHughes24/leanstuff
dca0b5349c3ed893e8792ffbd98cbcadaff20411
9efa85f72efaccd1d540385952a6acc18fce8687
refs/heads/master
1,654,883,241,759
1,652,873,885,000
1,652,873,885,000
134,599,537
1
0
null
null
null
null
UTF-8
Lean
false
false
546
lean
import data.real.cardinality group_theory.quotient_group instance rat_cast_is_add_group_hom : is_add_group_hom (coe : ℚ → ℝ) := { to_is_add_hom := { map_add := by simp } } noncomputable lemma real_equiv_real_mod_rat : ℝ ≃ quotient_add_group.quotient (set.range (coe : ℚ → ℝ)) := calc ℝ ≃ quotient_add_group.quotient (set.range (coe : ℚ → ℝ)) × (set.range (coe : ℚ → ℝ)) : is_add_subgroup.add_group_equiv_quotient_times_subgroup _ ... ≃ _ : quotient_add_group.quotient (set.range (coe : ℚ → ℝ)) #exit
f0aad9a620918fd4a635899cbbf1db956d196e20
55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5
/src/number_theory/bernoulli.lean
bf28b0906ff3e086d1963c18993584ca973545eb
[ "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
2,899
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 data.rat import data.fintype.card /-! # Bernoulli numbers The Bernoulli numbers are a sequence of numbers that frequently show up in number theory. For example, they show up in the Taylor series of many trigonometric and hyperbolic functions, and also as (integral multiples of products of powers of `π` and) special values of the Riemann zeta function. (Note: these facts are not yet available in mathlib) In this file, we provide the definition, and the basic fact (`sum_bernoulli`) that $$ \sum_{k < n} \binom{n}{k} * B_k = n, $$ where $B_k$ denotes the the $k$-th Bernoulli number. -/ open_locale big_operators /-- The Bernoulli numbers: the $n$-th Bernoulli number $B_n$ is defined recursively via $$B_n = \sum_{k < n} \binom{n}{k} * \frac{B_k}{n+1-k}$$ -/ def bernoulli : ℕ → ℚ := well_founded.fix nat.lt_wf (λ n bernoulli, 1 - ∑ k : fin n, (n.choose k) * bernoulli k k.2 / (n + 1 - k)) lemma bernoulli_def' (n : ℕ) : bernoulli n = 1 - ∑ k : fin n, (n.choose k) * (bernoulli k) / (n + 1 - k) := well_founded.fix_eq _ _ _ lemma bernoulli_def (n : ℕ) : bernoulli n = 1 - ∑ k in finset.range n, (n.choose k) * (bernoulli k) / (n + 1 - k) := by { rw [bernoulli_def', finset.range_sum_eq_univ_sum], refl } @[simp] lemma bernoulli_zero : bernoulli 0 = 1 := rfl @[simp] lemma bernoulli_one : bernoulli 1 = 1/2 := begin rw [bernoulli_def], repeat { try { rw [finset.sum_range_succ] }, try { rw [nat.choose_succ_succ] }, simp, norm_num1 } end @[simp] lemma bernoulli_two : bernoulli 2 = 1/6 := begin rw [bernoulli_def], repeat { try { rw [finset.sum_range_succ] }, try { rw [nat.choose_succ_succ] }, simp, norm_num1 } end @[simp] lemma bernoulli_three : bernoulli 3 = 0 := begin rw [bernoulli_def], repeat { try { rw [finset.sum_range_succ] }, try { rw [nat.choose_succ_succ] }, simp, norm_num1 } end @[simp] lemma bernoulli_four : bernoulli 4 = -1/30 := begin rw [bernoulli_def], repeat { try { rw [finset.sum_range_succ] }, try { rw [nat.choose_succ_succ] }, simp, norm_num1 } end @[simp] lemma sum_bernoulli (n : ℕ) : ∑ k in finset.range n, (n.choose k : ℚ) * bernoulli k = n := begin induction n with n ih, { simp }, rw [finset.sum_range_succ], rw [nat.choose_succ_self_right], rw [bernoulli_def, mul_sub, mul_one, sub_add_eq_add_sub, sub_eq_iff_eq_add], rw [add_left_cancel_iff, finset.mul_sum, finset.sum_congr rfl], intros k hk, rw finset.mem_range at hk, rw [mul_div_right_comm, ← mul_assoc], congr' 1, rw [← mul_div_assoc, eq_div_iff], { rw [mul_comm ((n+1 : ℕ) : ℚ)], have hk' : k ≤ n + 1, by linarith, rw_mod_cast nat.choose_mul_succ_eq n k }, { contrapose! hk with H, rw sub_eq_zero at H, norm_cast at H, linarith } end
bff2d02a6633d9d8b3e7a68646982cac712c4eed
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/src/Lean/Elab/InheritDoc.lean
b629a9e12429e3a9b90bb808fd158dbb9096f6ad
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
leanprover/lean4
4bdf9790294964627eb9be79f5e8f6157780b4cc
f1f9dc0f2f531af3312398999d8b8303fa5f096b
refs/heads/master
1,693,360,665,786
1,693,350,868,000
1,693,350,868,000
129,571,436
2,827
311
Apache-2.0
1,694,716,156,000
1,523,760,560,000
Lean
UTF-8
Lean
false
false
1,193
lean
/- Copyright (c) 2022 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Lean.Elab.InfoTree.Main import Lean.DocString namespace Lean builtin_initialize registerBuiltinAttribute { name := `inherit_doc descr := "inherit documentation from a specified declaration" add := fun decl stx kind => do unless kind == AttributeKind.global do throwError "invalid `[inherit_doc]` attribute, must be global" match stx with | `(attr| inherit_doc $[$id?:ident]?) => withRef stx[0] do let some id := id? | throwError "invalid `[inherit_doc]` attribute, could not infer doc source" let declName ← Elab.resolveGlobalConstNoOverloadWithInfo id if (← findDocString? (← getEnv) decl).isSome then logWarning m!"{← mkConstWithLevelParams decl} already has a doc string" let some doc ← findDocString? (← getEnv) declName | logWarningAt id m!"{← mkConstWithLevelParams declName} does not have a doc string" addDocString decl doc | _ => throwError "invalid `[inherit_doc]` attribute" }
d728534c5e58aa3b49b6c59d1522f26481116566
1437b3495ef9020d5413178aa33c0a625f15f15f
/category_theory/examples/monoids.lean
84f53780e9188ca363fb4a780e85fc63b355a689
[ "Apache-2.0" ]
permissive
jean002/mathlib
c66bbb2d9fdc9c03ae07f869acac7ddbfce67a30
dc6c38a765799c99c4d9c8d5207d9e6c9e0e2cfd
refs/heads/master
1,587,027,806,375
1,547,306,358,000
1,547,306,358,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
1,664
lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison Introduce Mon -- the category of monoids. Currently only the basic setup. -/ import category_theory.fully_faithful import algebra.ring universes u v open category_theory namespace category_theory.examples /-- The category of monoids and monoid morphisms. -/ @[reducible] def Mon : Type (u+1) := bundled monoid instance (x : Mon) : monoid x := x.str instance concrete_is_monoid_hom : concrete_category @is_monoid_hom := ⟨by introsI α ia; apply_instance, by introsI α β γ ia ib ic f g hf hg; apply_instance⟩ instance Mon_hom_is_monoid_hom {R S : Mon} (f : R ⟶ S) : is_monoid_hom (f : R → S) := f.2 /-- The category of commutative monoids and monoid morphisms. -/ @[reducible] def CommMon : Type (u+1) := bundled comm_monoid instance (x : CommMon) : comm_monoid x := x.str @[reducible] def is_comm_monoid_hom {α β} [comm_monoid α] [comm_monoid β] (f : α → β) : Prop := is_monoid_hom f instance concrete_is_comm_monoid_hom : concrete_category @is_comm_monoid_hom := ⟨by introsI α ia; apply_instance, by introsI α β γ ia ib ic f g hf hg; apply_instance⟩ instance CommMon_hom_is_comm_monoid_hom {R S : CommMon} (f : R ⟶ S) : is_comm_monoid_hom (f : R → S) := f.2 namespace CommMon /-- The forgetful functor from commutative monoids to monoids. -/ def forget_to_Mon : CommMon ⥤ Mon := concrete_functor (by intros _ c; exact { ..c }) (by introsI _ _ _ _ f i; exact { ..i }) instance : faithful (forget_to_Mon) := {} end CommMon end category_theory.examples
1687731879c584ab5cfb48a7798d9517d31ee920
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/category_theory/limits/constructions/filtered.lean
42c8ea4d848019647342b67b385c54a5e4d12121
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
3,667
lean
/- Copyright (c) 2022 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import category_theory.limits.constructions.limits_of_products_and_equalizers import category_theory.limits.opposites /-! # Constructing colimits from finite colimits and filtered colimits > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. We construct colimits of size `w` from finite colimits and filtered colimits of size `w`. Since `w`-sized colimits are constructured from coequalizers and `w`-sized coproducts, it suffices to construct `w`-sized coproducts from finite coproducts and `w`-sized filtered colimits. The idea is simple: to construct coproducts of shape `α`, we take the colimit of the filtered diagram of all coproducts of finite subsets of `α`. We also deduce the dual statement by invoking the original statement in `Cᵒᵖ`. -/ universes w v u noncomputable theory open category_theory variables {C : Type u} [category.{v} C] {α : Type w} namespace category_theory.limits namespace coproducts_from_finite_filtered local attribute [tidy] tactic.case_bash /-- If `C` has finite coproducts, a functor `discrete α ⥤ C` lifts to a functor `finset (discrete α) ⥤ C` by taking coproducts. -/ @[simps] def lift_to_finset [has_finite_coproducts C] (F : discrete α ⥤ C) : finset (discrete α) ⥤ C := { obj := λ s, ∐ λ x : s, F.obj x, map := λ s t h, sigma.desc (λ y, sigma.ι (λ x : t, F.obj x) ⟨y, h.down.down y.2⟩) } /-- If `C` has finite coproducts and filtered colimits, we can construct arbitrary coproducts by taking the colimit of the diagram formed by the coproducts of finite sets over the indexing type. -/ @[simps] def lift_to_finset_colimit_cocone [has_finite_coproducts C] [has_filtered_colimits_of_size.{w w} C] [decidable_eq α] (F : discrete α ⥤ C) : colimit_cocone F := { cocone := { X := colimit (lift_to_finset F), ι := discrete.nat_trans $ λ j, @sigma.ι _ _ _ (λ x : ({j} : finset (discrete α)), F.obj x) _ ⟨j, by simp⟩ ≫ colimit.ι (lift_to_finset F) {j} }, is_colimit := { desc := λ s, colimit.desc (lift_to_finset F) { X := s.X, ι := { app := λ t, sigma.desc (λ x, s.ι.app x) } }, uniq' := λ s m h, begin ext t ⟨⟨j, hj⟩⟩, convert h j using 1, { simp [← colimit.w (lift_to_finset F) ⟨⟨finset.singleton_subset_iff.2 hj⟩⟩], refl }, { tidy } end } } end coproducts_from_finite_filtered open coproducts_from_finite_filtered lemma has_coproducts_of_finite_and_filtered [has_finite_coproducts C] [has_filtered_colimits_of_size.{w w} C] : has_coproducts.{w} C := λ α, by { classical, exactI ⟨λ F, has_colimit.mk (lift_to_finset_colimit_cocone F)⟩ } lemma has_colimits_of_finite_and_filtered [has_finite_colimits C] [has_filtered_colimits_of_size.{w w} C] : has_colimits_of_size.{w w} C := have has_coproducts.{w} C, from has_coproducts_of_finite_and_filtered, by exactI has_colimits_of_has_coequalizers_and_coproducts lemma has_products_of_finite_and_cofiltered [has_finite_products C] [has_cofiltered_limits_of_size.{w w} C] : has_products.{w} C := have has_coproducts.{w} Cᵒᵖ, from has_coproducts_of_finite_and_filtered, by exactI has_products_of_opposite lemma has_limits_of_finite_and_cofiltered [has_finite_limits C] [has_cofiltered_limits_of_size.{w w} C] : has_limits_of_size.{w w} C := have has_products.{w} C, from has_products_of_finite_and_cofiltered, by exactI has_limits_of_has_equalizers_and_products end category_theory.limits
43a0333404de5c7afb55459c5c45b0e9fee8fbb6
398b53a5e02ce35196531591f84bb2f6b034ce5a
/tpil/chapter5.lean
4e6a85f52ec5145ffd2b19542acdcfc6f5cb6cea
[ "MIT" ]
permissive
crockeo/math-exercises
64f07a9371a72895bbd97f49a854dcb6821b18ab
cf9150ef9e025f1b7929ba070a783e7a71f24f31
refs/heads/master
1,607,910,221,030
1,581,231,762,000
1,581,231,762,000
234,595,189
0
0
null
null
null
null
UTF-8
Lean
false
false
575
lean
-- Exercise 1 -- -- Go back to the exercises in Chapter 3 and Chapter 4 and redo as many as you -- can now with tactic proofs, using also rw and simp as appropriate. -- NOTE: I had alreadty been doing this, so I don't think I need to go back and -- do them again... oops. -- Exercise 2 -- -- Use tactic combinators to obtain a one line proof of the following: example (p q r : Prop) (hp : p) : (p ∨ q ∨ r) ∧ (q ∨ p ∨ r) ∧ (q ∨ r ∨ p) := by { repeat {split}, repeat { { left, assumption } <|> right <|> assumption } }
c58ae7015a7f2e41205ed06882bcff518fce224e
64874bd1010548c7f5a6e3e8902efa63baaff785
/hott/default.hlean
d6dda5b5cf51b4378f9f6a1773690ced578eba58
[ "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
244
hlean
-- Copyright (c) 2014 Jeremy Avigad. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Author: Jeremy Avigad, Jakob von Raumer -- hott.default -- ============ -- A library for homotopy type theory
927205bc78f999a1357cb6cf4e3975c36a17dcb7
80cc5bf14c8ea85ff340d1d747a127dcadeb966f
/src/algebra/group_power/basic.lean
fae1bb920ec844df536cff391dab6e08fc1e441e
[ "Apache-2.0" ]
permissive
lacker/mathlib
f2439c743c4f8eb413ec589430c82d0f73b2d539
ddf7563ac69d42cfa4a1bfe41db1fed521bd795f
refs/heads/master
1,671,948,326,773
1,601,479,268,000
1,601,479,268,000
298,686,743
0
0
Apache-2.0
1,601,070,794,000
1,601,070,794,000
null
UTF-8
Lean
false
false
20,312
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.order_functions import deprecated.group /-! # Power operations on monoids and groups The power operation on monoids and groups. We separate this from group, because it depends on `ℕ`, which in turn depends on other parts of algebra. This module contains the definitions of `monoid.pow` and `group.pow` and their additive counterparts `nsmul` and `gsmul`, along with a few lemmas. Further lemmas can be found in `algebra.group_power.lemmas`. ## Notation The class `has_pow α β` provides the notation `a^b` for powers. We define instances of `has_pow M ℕ`, for monoids `M`, and `has_pow G ℤ` for groups `G`. We also define infix operators `•ℕ` and `•ℤ` for scalar multiplication by a natural and an integer numbers, respectively. ## Implementation details We adopt the convention that `0^0 = 1`. This module provides the instance `has_pow ℕ ℕ` (via `monoid.has_pow`) and is imported by `data.nat.basic`, so it has to live low in the import hierarchy. Not all of its imports are needed yet; the intent is to move more lemmas here from `.lemmas` so that they are available in `data.nat.basic`, and the imports will be required then. -/ universes u v w x y z u₁ u₂ variables {M : Type u} {N : Type v} {G : Type w} {H : Type x} {A : Type y} {B : Type z} {R : Type u₁} {S : Type u₂} /-- The power operation in a monoid. `a^n = a*a*...*a` n times. -/ def monoid.pow [has_mul M] [has_one M] (a : M) : ℕ → M | 0 := 1 | (n+1) := a * monoid.pow n /-- The scalar multiplication in an additive monoid. `n •ℕ a = a+a+...+a` n times. -/ def nsmul [has_add A] [has_zero A] (n : ℕ) (a : A) : A := @monoid.pow (multiplicative A) _ { one := (0 : A) } a n infix ` •ℕ `:70 := nsmul @[priority 5] instance monoid.has_pow [monoid M] : has_pow M ℕ := ⟨monoid.pow⟩ /-! ### Commutativity First we prove some facts about `semiconj_by` and `commute`. They do not require any theory about `pow` and/or `nsmul` and will be useful later in this file. -/ namespace semiconj_by variables [monoid M] @[simp] lemma pow_right {a x y : M} (h : semiconj_by a x y) (n : ℕ) : semiconj_by a (x^n) (y^n) := nat.rec_on n (one_right a) $ λ n ihn, h.mul_right ihn end semiconj_by namespace commute variables [monoid M] {a b : M} @[simp] theorem pow_right (h : commute a b) (n : ℕ) : commute a (b ^ n) := h.pow_right n @[simp] theorem pow_left (h : commute a b) (n : ℕ) : commute (a ^ n) b := (h.symm.pow_right n).symm @[simp] theorem pow_pow (h : commute a b) (m n : ℕ) : commute (a ^ m) (b ^ n) := (h.pow_left m).pow_right n @[simp] theorem self_pow (a : M) (n : ℕ) : commute a (a ^ n) := (commute.refl a).pow_right n @[simp] theorem pow_self (a : M) (n : ℕ) : commute (a ^ n) a := (commute.refl a).pow_left n @[simp] theorem pow_pow_self (a : M) (m n : ℕ) : commute (a ^ m) (a ^ n) := (commute.refl a).pow_pow m n end commute section monoid variables [monoid M] [monoid N] [add_monoid A] [add_monoid B] @[simp] theorem pow_zero (a : M) : a^0 = 1 := rfl @[simp] theorem zero_nsmul (a : A) : 0 •ℕ a = 0 := rfl theorem pow_succ (a : M) (n : ℕ) : a^(n+1) = a * a^n := rfl theorem succ_nsmul (a : A) (n : ℕ) : (n+1) •ℕ a = a + n •ℕ a := rfl theorem pow_two (a : M) : a^2 = a * a := show a*(a*1)=a*a, by rw mul_one theorem two_nsmul (a : A) : 2 •ℕ a = a + a := @pow_two (multiplicative A) _ a theorem pow_mul_comm' (a : M) (n : ℕ) : a^n * a = a * a^n := commute.pow_self a n theorem nsmul_add_comm' : ∀ (a : A) (n : ℕ), n •ℕ a + a = a + n •ℕ a := @pow_mul_comm' (multiplicative A) _ theorem pow_succ' (a : M) (n : ℕ) : a^(n+1) = a^n * a := by rw [pow_succ, pow_mul_comm'] theorem succ_nsmul' (a : A) (n : ℕ) : (n+1) •ℕ a = n •ℕ a + a := @pow_succ' (multiplicative A) _ _ _ theorem pow_add (a : M) (m n : ℕ) : a^(m + n) = a^m * a^n := by induction n with n ih; [rw [nat.add_zero, pow_zero, mul_one], rw [pow_succ', ← mul_assoc, ← ih, ← pow_succ', nat.add_assoc]] theorem add_nsmul : ∀ (a : A) (m n : ℕ), (m + n) •ℕ a = m •ℕ a + n •ℕ a := @pow_add (multiplicative A) _ @[simp] theorem pow_one (a : M) : a^1 = a := mul_one _ @[simp] theorem one_nsmul (a : A) : 1 •ℕ a = a := add_zero _ @[simp] lemma pow_ite (P : Prop) [decidable P] (a : M) (b c : ℕ) : a ^ (if P then b else c) = if P then a ^ b else a ^ c := by split_ifs; refl @[simp] lemma ite_pow (P : Prop) [decidable P] (a b : M) (c : ℕ) : (if P then a else b) ^ c = if P then a ^ c else b ^ c := by split_ifs; refl @[simp] lemma pow_boole (P : Prop) [decidable P] (a : M) : a ^ (if P then 1 else 0) = if P then a else 1 := by simp @[simp] theorem one_pow (n : ℕ) : (1 : M)^n = 1 := by induction n with n ih; [refl, rw [pow_succ, ih, one_mul]] @[simp] theorem nsmul_zero (n : ℕ) : n •ℕ (0 : A) = 0 := by induction n with n ih; [refl, rw [succ_nsmul, ih, zero_add]] theorem pow_mul (a : M) (m n : ℕ) : a^(m * n) = (a^m)^n := by induction n with n ih; [rw nat.mul_zero, rw [nat.mul_succ, pow_add, pow_succ', ih]]; refl theorem mul_nsmul' : ∀ (a : A) (m n : ℕ), m * n •ℕ a = n •ℕ (m •ℕ a) := @pow_mul (multiplicative A) _ theorem pow_mul' (a : M) (m n : ℕ) : a^(m * n) = (a^n)^m := by rw [nat.mul_comm, pow_mul] theorem mul_nsmul (a : A) (m n : ℕ) : m * n •ℕ a = m •ℕ (n •ℕ a) := @pow_mul' (multiplicative A) _ a m n theorem pow_mul_pow_sub (a : M) {m n : ℕ} (h : m ≤ n) : a ^ m * a ^ (n - m) = a ^ n := by rw [←pow_add, nat.add_comm, nat.sub_add_cancel h] theorem nsmul_add_sub_nsmul (a : A) {m n : ℕ} (h : m ≤ n) : (m •ℕ a) + ((n - m) •ℕ a) = n •ℕ a := @pow_mul_pow_sub (multiplicative A) _ _ _ _ h theorem pow_sub_mul_pow (a : M) {m n : ℕ} (h : m ≤ n) : a ^ (n - m) * a ^ m = a ^ n := by rw [←pow_add, nat.sub_add_cancel h] theorem sub_nsmul_nsmul_add (a : A) {m n : ℕ} (h : m ≤ n) : ((n - m) •ℕ a) + (m •ℕ a) = n •ℕ a := @pow_sub_mul_pow (multiplicative A) _ _ _ _ h theorem pow_bit0 (a : M) (n : ℕ) : a ^ bit0 n = a^n * a^n := pow_add _ _ _ theorem bit0_nsmul (a : A) (n : ℕ) : bit0 n •ℕ a = n •ℕ a + n •ℕ a := add_nsmul _ _ _ theorem pow_bit1 (a : M) (n : ℕ) : a ^ bit1 n = a^n * a^n * a := by rw [bit1, pow_succ', pow_bit0] theorem bit1_nsmul : ∀ (a : A) (n : ℕ), bit1 n •ℕ a = n •ℕ a + n •ℕ a + a := @pow_bit1 (multiplicative A) _ theorem pow_mul_comm (a : M) (m n : ℕ) : a^m * a^n = a^n * a^m := commute.pow_pow_self a m n theorem nsmul_add_comm : ∀ (a : A) (m n : ℕ), m •ℕ a + n •ℕ a = n •ℕ a + m •ℕ a := @pow_mul_comm (multiplicative A) _ theorem monoid_hom.map_pow (f : M →* N) (a : M) : ∀(n : ℕ), f (a ^ n) = (f a) ^ n | 0 := f.map_one | (n+1) := by rw [pow_succ, pow_succ, f.map_mul, monoid_hom.map_pow] theorem add_monoid_hom.map_nsmul (f : A →+ B) (a : A) (n : ℕ) : f (n •ℕ a) = n •ℕ f a := f.to_multiplicative.map_pow a n theorem is_monoid_hom.map_pow (f : M → N) [is_monoid_hom f] (a : M) : ∀(n : ℕ), f (a ^ n) = (f a) ^ n := (monoid_hom.of f).map_pow a theorem is_add_monoid_hom.map_nsmul (f : A → B) [is_add_monoid_hom f] (a : A) (n : ℕ) : f (n •ℕ a) = n •ℕ f a := (add_monoid_hom.of f).map_nsmul a n lemma commute.mul_pow {a b : M} (h : commute a b) (n : ℕ) : (a * b) ^ n = a ^ n * b ^ n := nat.rec_on n (by simp) $ λ n ihn, by simp only [pow_succ, ihn, ← mul_assoc, (h.pow_left n).right_comm] theorem neg_pow [ring R] (a : R) (n : ℕ) : (- a) ^ n = (-1) ^ n * a ^ n := (neg_one_mul a) ▸ (commute.neg_one_left a).mul_pow n end monoid /-! ### Commutative (additive) monoid -/ section comm_monoid variables [comm_monoid M] [add_comm_monoid A] theorem mul_pow (a b : M) (n : ℕ) : (a * b)^n = a^n * b^n := (commute.all a b).mul_pow n theorem nsmul_add : ∀ (a b : A) (n : ℕ), n •ℕ (a + b) = n •ℕ a + n •ℕ b := @mul_pow (multiplicative A) _ instance pow.is_monoid_hom (n : ℕ) : is_monoid_hom ((^ n) : M → M) := { map_mul := λ _ _, mul_pow _ _ _, map_one := one_pow _ } instance nsmul.is_add_monoid_hom (n : ℕ) : is_add_monoid_hom (nsmul n : A → A) := { map_add := λ _ _, nsmul_add _ _ _, map_zero := nsmul_zero _ } lemma dvd_pow {x y : M} : ∀ {n : ℕ} (hxy : x ∣ y) (hn : n ≠ 0), x ∣ y^n | 0 hxy hn := (hn rfl).elim | (n+1) hxy hn := by { rw [pow_succ], exact dvd_mul_of_dvd_left hxy _ } end comm_monoid section group variables [group G] [group H] [add_group A] [add_group B] open int /-- The power operation in a group. This extends `monoid.pow` to negative integers with the definition `a^(-n) = (a^n)⁻¹`. -/ def gpow (a : G) : ℤ → G | (of_nat n) := a^n | -[1+n] := (a^(nat.succ n))⁻¹ /-- The scalar multiplication by integers on an additive group. This extends `nsmul` to negative integers with the definition `(-n) •ℤ a = -(n •ℕ a)`. -/ def gsmul (n : ℤ) (a : A) : A := @gpow (multiplicative A) _ a n @[priority 10] instance group.has_pow : has_pow G ℤ := ⟨gpow⟩ infix ` •ℤ `:70 := gsmul section nat @[simp] theorem inv_pow (a : G) (n : ℕ) : (a⁻¹)^n = (a^n)⁻¹ := by induction n with n ih; [exact one_inv.symm, rw [pow_succ', pow_succ, ih, mul_inv_rev]] @[simp] theorem neg_nsmul : ∀ (a : A) (n : ℕ), n •ℕ (-a) = -(n •ℕ a) := @inv_pow (multiplicative A) _ theorem pow_sub (a : G) {m n : ℕ} (h : n ≤ m) : a^(m - n) = a^m * (a^n)⁻¹ := have h1 : m - n + n = m, from nat.sub_add_cancel h, have h2 : a^(m - n) * a^n = a^m, by rw [←pow_add, h1], eq_mul_inv_of_mul_eq h2 theorem nsmul_sub : ∀ (a : A) {m n : ℕ}, n ≤ m → (m - n) •ℕ a = m •ℕ a - n •ℕ a := @pow_sub (multiplicative A) _ theorem pow_inv_comm (a : G) (m n : ℕ) : (a⁻¹)^m * a^n = a^n * (a⁻¹)^m := (commute.refl a).inv_left.pow_pow m n theorem nsmul_neg_comm : ∀ (a : A) (m n : ℕ), m •ℕ (-a) + n •ℕ a = n •ℕ a + m •ℕ (-a) := @pow_inv_comm (multiplicative A) _ end nat @[simp] theorem gpow_coe_nat (a : G) (n : ℕ) : a ^ (n:ℤ) = a ^ n := rfl @[simp] theorem gsmul_coe_nat (a : A) (n : ℕ) : n •ℤ a = n •ℕ a := rfl theorem gpow_of_nat (a : G) (n : ℕ) : a ^ of_nat n = a ^ n := rfl theorem gsmul_of_nat (a : A) (n : ℕ) : of_nat n •ℤ a = n •ℕ a := rfl @[simp] theorem gpow_neg_succ_of_nat (a : G) (n : ℕ) : a ^ -[1+n] = (a ^ n.succ)⁻¹ := rfl @[simp] theorem gsmul_neg_succ_of_nat (a : A) (n : ℕ) : -[1+n] •ℤ a = - (n.succ •ℕ a) := rfl @[simp] theorem gpow_zero (a : G) : a ^ (0:ℤ) = 1 := rfl @[simp] theorem zero_gsmul (a : A) : (0:ℤ) •ℤ a = 0 := rfl @[simp] theorem gpow_one (a : G) : a ^ (1:ℤ) = a := pow_one a @[simp] theorem one_gsmul (a : A) : (1:ℤ) •ℤ a = a := add_zero _ @[simp] theorem one_gpow : ∀ (n : ℤ), (1 : G) ^ n = 1 | (n : ℕ) := one_pow _ | -[1+ n] := show _⁻¹=(1:G), by rw [one_pow, one_inv] @[simp] theorem gsmul_zero : ∀ (n : ℤ), n •ℤ (0 : A) = 0 := @one_gpow (multiplicative A) _ @[simp] theorem gpow_neg (a : G) : ∀ (n : ℤ), a ^ -n = (a ^ n)⁻¹ | (n+1:ℕ) := rfl | 0 := one_inv.symm | -[1+ n] := (inv_inv _).symm lemma mul_gpow_neg_one (a b : G) : (a*b)^(-(1:ℤ)) = b^(-(1:ℤ))*a^(-(1:ℤ)) := by simp only [mul_inv_rev, gpow_one, gpow_neg] @[simp] theorem neg_gsmul : ∀ (a : A) (n : ℤ), -n •ℤ a = -(n •ℤ a) := @gpow_neg (multiplicative A) _ theorem gpow_neg_one (x : G) : x ^ (-1:ℤ) = x⁻¹ := congr_arg has_inv.inv $ pow_one x theorem neg_one_gsmul (x : A) : (-1:ℤ) •ℤ x = -x := congr_arg has_neg.neg $ one_nsmul x theorem inv_gpow (a : G) : ∀n:ℤ, a⁻¹ ^ n = (a ^ n)⁻¹ | (n : ℕ) := inv_pow a n | -[1+ n] := congr_arg has_inv.inv $ inv_pow a (n+1) theorem gsmul_neg (a : A) (n : ℤ) : gsmul n (- a) = - gsmul n a := @inv_gpow (multiplicative A) _ a n theorem commute.mul_gpow {a b : G} (h : commute a b) : ∀ n : ℤ, (a * b) ^ n = a ^ n * b ^ n | (n : ℕ) := h.mul_pow n | -[1+n] := by simp [h.mul_pow, (h.pow_pow n.succ n.succ).inv_inv.symm.eq] end group section comm_group variables [comm_group G] [add_comm_group A] theorem mul_gpow (a b : G) (n : ℤ) : (a * b)^n = a^n * b^n := (commute.all a b).mul_gpow n theorem gsmul_add : ∀ (a b : A) (n : ℤ), n •ℤ (a + b) = n •ℤ a + n •ℤ b := @mul_gpow (multiplicative A) _ theorem gsmul_sub (a b : A) (n : ℤ) : gsmul n (a - b) = gsmul n a - gsmul n b := by simp only [gsmul_add, gsmul_neg, sub_eq_add_neg] instance gpow.is_group_hom (n : ℤ) : is_group_hom ((^ n) : G → G) := { map_mul := λ _ _, mul_gpow _ _ n } instance gsmul.is_add_group_hom (n : ℤ) : is_add_group_hom (gsmul n : A → A) := { map_add := λ _ _, gsmul_add _ _ n } end comm_group lemma zero_pow [monoid_with_zero R] : ∀ {n : ℕ}, 0 < n → (0 : R) ^ n = 0 | (n+1) _ := zero_mul _ namespace ring_hom variables [semiring R] [semiring S] @[simp] lemma map_pow (f : R →+* S) (a) : ∀ n : ℕ, f (a ^ n) = (f a) ^ n := f.to_monoid_hom.map_pow a end ring_hom theorem neg_one_pow_eq_or [ring R] : ∀ n : ℕ, (-1 : R)^n = 1 ∨ (-1 : R)^n = -1 | 0 := or.inl rfl | (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]) lemma pow_dvd_pow [monoid R] (a : R) {m n : ℕ} (h : m ≤ n) : a ^ m ∣ a ^ n := ⟨a ^ (n - m), by rw [← pow_add, nat.add_comm, nat.sub_add_cancel h]⟩ theorem pow_dvd_pow_of_dvd [comm_monoid R] {a b : R} (h : a ∣ b) : ∀ n : ℕ, a ^ n ∣ b ^ n | 0 := dvd_refl _ | (n+1) := mul_dvd_mul h (pow_dvd_pow_of_dvd n) lemma pow_two_sub_pow_two {R : Type*} [comm_ring R] (a b : R) : a ^ 2 - b ^ 2 = (a + b) * (a - b) := by simp only [pow_two, mul_sub, add_mul, sub_sub, add_sub, mul_comm, sub_add_cancel] lemma eq_or_eq_neg_of_pow_two_eq_pow_two [integral_domain R] (a b : R) (h : a ^ 2 = b ^ 2) : a = b ∨ a = -b := by rwa [← add_eq_zero_iff_eq_neg, ← sub_eq_zero, or_comm, ← mul_eq_zero, ← pow_two_sub_pow_two a b, sub_eq_zero] theorem sq_sub_sq [comm_ring R] (a b : R) : a ^ 2 - b ^ 2 = (a + b) * (a - b) := by rw [pow_two, pow_two, mul_self_sub_mul_self] theorem pow_eq_zero [monoid_with_zero R] [no_zero_divisors R] {x : R} {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] }, exact or.cases_on (mul_eq_zero.1 H) id ih end @[field_simps] theorem pow_ne_zero [monoid_with_zero R] [no_zero_divisors R] {a : R} (n : ℕ) (h : a ≠ 0) : a ^ n ≠ 0 := mt pow_eq_zero h theorem nsmul_nonneg [ordered_add_comm_monoid R] {a : R} (H : 0 ≤ a) : ∀ n : ℕ, 0 ≤ n •ℕ a | 0 := le_refl _ | (n+1) := add_nonneg H (nsmul_nonneg n) lemma pow_abs [decidable_linear_ordered_comm_ring R] (a : R) (n : ℕ) : (abs a)^n = abs (a^n) := by induction n with n ih; [exact (abs_one).symm, rw [pow_succ, pow_succ, ih, abs_mul]] lemma abs_neg_one_pow [decidable_linear_ordered_comm_ring R] (n : ℕ) : abs ((-1 : R)^n) = 1 := by rw [←pow_abs, abs_neg, abs_one, one_pow] section add_monoid variable [ordered_add_comm_monoid A] theorem nsmul_le_nsmul {a : A} {n m : ℕ} (ha : 0 ≤ a) (h : n ≤ m) : n •ℕ a ≤ m •ℕ a := let ⟨k, hk⟩ := nat.le.dest h in calc n •ℕ a = n •ℕ a + 0 : (add_zero _).symm ... ≤ n •ℕ a + k •ℕ a : add_le_add_left (nsmul_nonneg ha _) _ ... = m •ℕ a : by rw [← hk, add_nsmul] lemma nsmul_le_nsmul_of_le_right {a b : A} (hab : a ≤ b) : ∀ i : ℕ, i •ℕ a ≤ i •ℕ b | 0 := by simp | (k+1) := add_le_add hab (nsmul_le_nsmul_of_le_right _) end add_monoid namespace canonically_ordered_semiring variable [canonically_ordered_comm_semiring R] theorem pow_pos {a : R} (H : 0 < a) : ∀ n : ℕ, 0 < a ^ n | 0 := canonically_ordered_semiring.zero_lt_one | (n+1) := canonically_ordered_semiring.mul_pos.2 ⟨H, pow_pos n⟩ lemma pow_le_pow_of_le_left {a b : R} (hab : a ≤ b) : ∀ i : ℕ, a^i ≤ b^i | 0 := by simp | (k+1) := canonically_ordered_semiring.mul_le_mul hab (pow_le_pow_of_le_left k) theorem one_le_pow_of_one_le {a : R} (H : 1 ≤ a) (n : ℕ) : 1 ≤ a ^ n := by simpa only [one_pow] using pow_le_pow_of_le_left H n theorem pow_le_one {a : R} (H : a ≤ 1) (n : ℕ) : a ^ n ≤ 1:= by simpa only [one_pow] using pow_le_pow_of_le_left H n end canonically_ordered_semiring section linear_ordered_semiring variable [linear_ordered_semiring R] theorem pow_pos {a : R} (H : 0 < a) : ∀ (n : ℕ), 0 < a ^ n | 0 := zero_lt_one | (n+1) := mul_pos H (pow_pos _) theorem pow_nonneg {a : R} (H : 0 ≤ a) : ∀ (n : ℕ), 0 ≤ a ^ n | 0 := zero_le_one | (n+1) := mul_nonneg H (pow_nonneg _) theorem pow_lt_pow_of_lt_left {x y : R} {n : ℕ} (Hxy : x < y) (Hxpos : 0 ≤ x) (Hnpos : 0 < n) : x ^ n < y ^ n := begin cases lt_or_eq_of_le Hxpos, { rw ←nat.sub_add_cancel Hnpos, induction (n - 1), { simpa only [pow_one] }, rw [pow_add, pow_add, nat.succ_eq_add_one, pow_one, pow_one], apply mul_lt_mul ih (le_of_lt Hxy) h (le_of_lt (pow_pos (lt_trans h Hxy) _)) }, { rw [←h, zero_pow Hnpos], apply pow_pos (by rwa ←h at Hxy : 0 < y),} end theorem pow_left_inj {x y : R} {n : ℕ} (Hxpos : 0 ≤ x) (Hypos : 0 ≤ y) (Hnpos : 0 < n) (Hxyn : x ^ n = y ^ n) : x = y := begin rcases lt_trichotomy x y with hxy | rfl | hyx, { exact absurd Hxyn (ne_of_lt (pow_lt_pow_of_lt_left hxy Hxpos Hnpos)) }, { refl }, { exact absurd Hxyn (ne_of_gt (pow_lt_pow_of_lt_left hyx Hypos Hnpos)) }, end theorem one_le_pow_of_one_le {a : R} (H : 1 ≤ a) : ∀ (n : ℕ), 1 ≤ a ^ n | 0 := le_refl _ | (n+1) := by simpa only [mul_one] using mul_le_mul H (one_le_pow_of_one_le n) zero_le_one (le_trans zero_le_one H) theorem pow_le_pow {a : R} {n m : ℕ} (ha : 1 ≤ a) (h : n ≤ m) : a ^ n ≤ a ^ m := let ⟨k, hk⟩ := nat.le.dest h in calc a ^ n = a ^ n * 1 : (mul_one _).symm ... ≤ a ^ n * a ^ k : mul_le_mul_of_nonneg_left (one_le_pow_of_one_le ha _) (pow_nonneg (le_trans zero_le_one ha) _) ... = a ^ m : by rw [←hk, pow_add] lemma pow_lt_pow {a : R} {n m : ℕ} (h : 1 < a) (h2 : n < m) : a ^ n < a ^ m := begin have h' : 1 ≤ a := le_of_lt h, have h'' : 0 < a := lt_trans zero_lt_one h, cases m, cases h2, rw [pow_succ, ←one_mul (a ^ n)], exact mul_lt_mul h (pow_le_pow h' (nat.le_of_lt_succ h2)) (pow_pos h'' _) (le_of_lt h'') end lemma pow_le_pow_of_le_left {a b : R} (ha : 0 ≤ a) (hab : a ≤ b) : ∀ i : ℕ, a^i ≤ b^i | 0 := by simp | (k+1) := mul_le_mul hab (pow_le_pow_of_le_left _) (pow_nonneg ha _) (le_trans ha hab) lemma lt_of_pow_lt_pow {a b : R} (n : ℕ) (hb : 0 ≤ b) (h : a ^ n < b ^ n) : a < b := lt_of_not_ge $ λ hn, not_lt_of_ge (pow_le_pow_of_le_left hb hn _) h end linear_ordered_semiring theorem pow_two_nonneg [linear_ordered_ring R] (a : R) : 0 ≤ a ^ 2 := by { rw pow_two, exact mul_self_nonneg _ } theorem pow_two_pos_of_ne_zero [linear_ordered_ring R] (a : R) (h : a ≠ 0) : 0 < a ^ 2 := lt_of_le_of_ne (pow_two_nonneg a) (pow_ne_zero 2 h).symm @[simp] lemma neg_square {α} [ring α] (z : α) : (-z)^2 = z^2 := by simp [pow, monoid.pow] lemma of_add_nsmul [add_monoid A] (x : A) (n : ℕ) : multiplicative.of_add (n •ℕ x) = (multiplicative.of_add x)^n := rfl lemma of_add_gsmul [add_group A] (x : A) (n : ℤ) : multiplicative.of_add (n •ℤ x) = (multiplicative.of_add x)^n := rfl @[simp] lemma semiconj_by.gpow_right [group G] {a x y : G} (h : semiconj_by a x y) : ∀ m : ℤ, semiconj_by a (x^m) (y^m) | (n : ℕ) := h.pow_right n | -[1+n] := (h.pow_right n.succ).inv_right namespace commute variables [group G] {a b : G} @[simp] lemma gpow_right (h : commute a b) (m : ℤ) : commute a (b^m) := h.gpow_right m @[simp] lemma gpow_left (h : commute a b) (m : ℤ) : commute (a^m) b := (h.symm.gpow_right m).symm lemma gpow_gpow (h : commute a b) (m n : ℤ) : commute (a^m) (b^n) := (h.gpow_left m).gpow_right n variables (a) (m n : ℕ) @[simp] theorem self_gpow : commute a (a ^ n) := (commute.refl a).gpow_right n @[simp] theorem gpow_self : commute (a ^ n) a := (commute.refl a).gpow_left n @[simp] theorem gpow_gpow_self : commute (a ^ m) (a ^ n) := (commute.refl a).gpow_gpow m n end commute
0e465fb7f6d718ff56821a9a8522260a97dab077
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/algebra/indicator_function.lean
c28ce86dcc9d06704aa80b4c7f2057c5ef3942e3
[ "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
26,382
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 algebra.support /-! # Indicator function - `indicator (s : set α) (f : α → β) (a : α)` is `f a` if `a ∈ s` and is `0` otherwise. - `mul_indicator (s : set α) (f : α → β) (a : α)` is `f a` if `a ∈ s` and is `1` otherwise. ## Implementation note In mathematics, an indicator function or a characteristic function is a function used to indicate membership of an element in a set `s`, having the value `1` for all elements of `s` and the value `0` otherwise. But since it is usually used to restrict a function to a certain set `s`, we let the indicator function take the value `f x` for some function `f`, instead of `1`. If the usual indicator function is needed, just set `f` to be the constant function `λx, 1`. The indicator function is implemented non-computably, to avoid having to pass around `decidable` arguments. This is in contrast with the design of `pi.single` or `set.piecewise`. ## Tags indicator, characteristic -/ open_locale big_operators open function variables {α β ι M N : Type*} namespace set section has_one variables [has_one M] [has_one N] {s t : set α} {f g : α → M} {a : α} /-- `indicator s f a` is `f a` if `a ∈ s`, `0` otherwise. -/ noncomputable def indicator {M} [has_zero M] (s : set α) (f : α → M) : α → M | x := by haveI := classical.dec_pred (∈ s); exact if x ∈ s then f x else 0 /-- `mul_indicator s f a` is `f a` if `a ∈ s`, `1` otherwise. -/ @[to_additive] noncomputable def mul_indicator (s : set α) (f : α → M) : α → M | x := by haveI := classical.dec_pred (∈ s); exact if x ∈ s then f x else 1 @[simp, to_additive] lemma piecewise_eq_mul_indicator [decidable_pred (∈ s)] : s.piecewise f 1 = s.mul_indicator f := funext $ λ x, @if_congr _ _ _ _ (id _) _ _ _ _ iff.rfl rfl rfl @[to_additive] lemma mul_indicator_apply (s : set α) (f : α → M) (a : α) [decidable (a ∈ s)] : mul_indicator s f a = if a ∈ s then f a else 1 := by convert rfl @[simp, to_additive] lemma mul_indicator_of_mem (h : a ∈ s) (f : α → M) : mul_indicator s f a = f a := by { letI := classical.dec (a ∈ s), exact if_pos h } @[simp, to_additive] lemma mul_indicator_of_not_mem (h : a ∉ s) (f : α → M) : mul_indicator s f a = 1 := by { letI := classical.dec (a ∈ s), exact if_neg h } @[to_additive] lemma mul_indicator_eq_one_or_self (s : set α) (f : α → M) (a : α) : mul_indicator s f a = 1 ∨ mul_indicator s f a = f a := begin by_cases h : a ∈ s, { exact or.inr (mul_indicator_of_mem h f) }, { exact or.inl (mul_indicator_of_not_mem h f) } end @[simp, to_additive] lemma mul_indicator_apply_eq_self : s.mul_indicator f a = f a ↔ (a ∉ s → f a = 1) := by letI := classical.dec (a ∈ s); exact ite_eq_left_iff.trans (by rw [@eq_comm _ (f a)]) @[simp, to_additive] lemma mul_indicator_eq_self : s.mul_indicator f = f ↔ mul_support f ⊆ s := by simp only [funext_iff, subset_def, mem_mul_support, mul_indicator_apply_eq_self, not_imp_comm] @[to_additive] lemma mul_indicator_eq_self_of_superset (h1 : s.mul_indicator f = f) (h2 : s ⊆ t) : t.mul_indicator f = f := by { rw mul_indicator_eq_self at h1 ⊢, exact subset.trans h1 h2 } @[simp, to_additive] lemma mul_indicator_apply_eq_one : mul_indicator s f a = 1 ↔ (a ∈ s → f a = 1) := by letI := classical.dec (a ∈ s); exact ite_eq_right_iff @[simp, to_additive] lemma mul_indicator_eq_one : mul_indicator s f = (λ x, 1) ↔ disjoint (mul_support f) s := by simp only [funext_iff, mul_indicator_apply_eq_one, set.disjoint_left, mem_mul_support, not_imp_not] @[simp, to_additive] lemma mul_indicator_eq_one' : mul_indicator s f = 1 ↔ disjoint (mul_support f) s := mul_indicator_eq_one @[to_additive] lemma mul_indicator_apply_ne_one {a : α} : s.mul_indicator f a ≠ 1 ↔ a ∈ s ∩ mul_support f := by simp only [ne.def, mul_indicator_apply_eq_one, not_imp, mem_inter_iff, mem_mul_support] @[simp, to_additive] lemma mul_support_mul_indicator : function.mul_support (s.mul_indicator f) = s ∩ function.mul_support f := ext $ λ x, by simp [function.mem_mul_support, mul_indicator_apply_eq_one] /-- If a multiplicative indicator function is not equal to `1` at a point, then that point is in the set. -/ @[to_additive "If an additive indicator function is not equal to `0` at a point, then that point is in the set."] lemma mem_of_mul_indicator_ne_one (h : mul_indicator s f a ≠ 1) : a ∈ s := not_imp_comm.1 (λ hn, mul_indicator_of_not_mem hn f) h @[to_additive] lemma eq_on_mul_indicator : eq_on (mul_indicator s f) f s := λ x hx, mul_indicator_of_mem hx f @[to_additive] lemma mul_support_mul_indicator_subset : mul_support (s.mul_indicator f) ⊆ s := λ x hx, hx.imp_symm (λ h, mul_indicator_of_not_mem h f) @[simp, to_additive] lemma mul_indicator_mul_support : mul_indicator (mul_support f) f = f := mul_indicator_eq_self.2 subset.rfl @[simp, to_additive] lemma mul_indicator_range_comp {ι : Sort*} (f : ι → α) (g : α → M) : mul_indicator (range f) g ∘ f = g ∘ f := by letI := classical.dec_pred (∈ range f); exact piecewise_range_comp _ _ _ @[to_additive] lemma mul_indicator_congr (h : eq_on f g s) : mul_indicator s f = mul_indicator s g := funext $ λx, by { simp only [mul_indicator], split_ifs, { exact h h_1 }, refl } @[simp, to_additive] lemma mul_indicator_univ (f : α → M) : mul_indicator (univ : set α) f = f := mul_indicator_eq_self.2 $ subset_univ _ @[simp, to_additive] lemma mul_indicator_empty (f : α → M) : mul_indicator (∅ : set α) f = λa, 1 := mul_indicator_eq_one.2 $ disjoint_empty _ @[to_additive] lemma mul_indicator_empty' (f : α → M) : mul_indicator (∅ : set α) f = 1 := mul_indicator_empty f variable (M) @[simp, to_additive] lemma mul_indicator_one (s : set α) : mul_indicator s (λx, (1:M)) = λx, (1:M) := mul_indicator_eq_one.2 $ by simp only [mul_support_one, empty_disjoint] @[simp, to_additive] lemma mul_indicator_one' {s : set α} : s.mul_indicator (1 : α → M) = 1 := mul_indicator_one M s variable {M} @[to_additive] lemma mul_indicator_mul_indicator (s t : set α) (f : α → M) : mul_indicator s (mul_indicator t f) = mul_indicator (s ∩ t) f := funext $ λx, by { simp only [mul_indicator], split_ifs, repeat {simp * at * {contextual := tt}} } @[simp, to_additive] lemma mul_indicator_inter_mul_support (s : set α) (f : α → M) : mul_indicator (s ∩ mul_support f) f = mul_indicator s f := by rw [← mul_indicator_mul_indicator, mul_indicator_mul_support] @[to_additive] lemma comp_mul_indicator (h : M → β) (f : α → M) {s : set α} {x : α} [decidable_pred (∈ s)] : h (s.mul_indicator f x) = s.piecewise (h ∘ f) (const α (h 1)) x := by letI := classical.dec_pred (∈ s); convert s.apply_piecewise f (const α 1) (λ _, h) @[to_additive] lemma mul_indicator_comp_right {s : set α} (f : β → α) {g : α → M} {x : β} : mul_indicator (f ⁻¹' s) (g ∘ f) x = mul_indicator s g (f x) := by { simp only [mul_indicator], split_ifs; refl } @[to_additive] lemma mul_indicator_image {s : set α} {f : β → M} {g : α → β} (hg : injective g) {x : α} : mul_indicator (g '' s) f (g x) = mul_indicator s (f ∘ g) x := by rw [← mul_indicator_comp_right, preimage_image_eq _ hg] @[to_additive] lemma mul_indicator_comp_of_one {g : M → N} (hg : g 1 = 1) : mul_indicator s (g ∘ f) = g ∘ (mul_indicator s f) := begin funext, simp only [mul_indicator], split_ifs; simp [*] end @[to_additive] lemma comp_mul_indicator_const (c : M) (f : M → N) (hf : f 1 = 1) : (λ x, f (s.mul_indicator (λ x, c) x)) = s.mul_indicator (λ x, f c) := (mul_indicator_comp_of_one hf).symm @[to_additive] lemma mul_indicator_preimage (s : set α) (f : α → M) (B : set M) : (mul_indicator s f)⁻¹' B = s.ite (f ⁻¹' B) (1 ⁻¹' B) := by letI := classical.dec_pred (∈ s); exact piecewise_preimage s f 1 B @[to_additive] lemma mul_indicator_one_preimage (s : set M) : t.mul_indicator 1 ⁻¹' s ∈ ({set.univ, ∅} : set (set α)) := begin classical, rw [mul_indicator_one', preimage_one], split_ifs; simp end @[to_additive] lemma mul_indicator_const_preimage_eq_union (U : set α) (s : set M) (a : M) [decidable (a ∈ s)] [decidable ((1 : M) ∈ s)] : U.mul_indicator (λ x, a) ⁻¹' s = (if a ∈ s then U else ∅) ∪ (if (1 : M) ∈ s then Uᶜ else ∅) := begin rw [mul_indicator_preimage, preimage_one, preimage_const], split_ifs; simp [← compl_eq_univ_diff] end @[to_additive] lemma mul_indicator_const_preimage (U : set α) (s : set M) (a : M) : U.mul_indicator (λ x, a) ⁻¹' s ∈ ({set.univ, U, Uᶜ, ∅} : set (set α)) := begin classical, rw [mul_indicator_const_preimage_eq_union], split_ifs; simp end lemma indicator_one_preimage [has_zero M] (U : set α) (s : set M) : U.indicator 1 ⁻¹' s ∈ ({set.univ, U, Uᶜ, ∅} : set (set α)) := indicator_const_preimage _ _ 1 @[to_additive] lemma mul_indicator_preimage_of_not_mem (s : set α) (f : α → M) {t : set M} (ht : (1:M) ∉ t) : (mul_indicator s f)⁻¹' t = f ⁻¹' t ∩ s := by simp [mul_indicator_preimage, pi.one_def, set.preimage_const_of_not_mem ht] @[to_additive] lemma mem_range_mul_indicator {r : M} {s : set α} {f : α → M} : r ∈ range (mul_indicator s f) ↔ (r = 1 ∧ s ≠ univ) ∨ (r ∈ f '' s) := by simp [mul_indicator, ite_eq_iff, exists_or_distrib, eq_univ_iff_forall, and_comm, or_comm, @eq_comm _ r 1] @[to_additive] lemma mul_indicator_rel_mul_indicator {r : M → M → Prop} (h1 : r 1 1) (ha : a ∈ s → r (f a) (g a)) : r (mul_indicator s f a) (mul_indicator s g a) := by { simp only [mul_indicator], split_ifs with has has, exacts [ha has, h1] } end has_one section monoid variables [mul_one_class M] {s t : set α} {f g : α → M} {a : α} @[to_additive] lemma mul_indicator_union_mul_inter_apply (f : α → M) (s t : set α) (a : α) : mul_indicator (s ∪ t) f a * mul_indicator (s ∩ t) f a = mul_indicator s f a * mul_indicator t f a := by by_cases hs : a ∈ s; by_cases ht : a ∈ t; simp * @[to_additive] lemma mul_indicator_union_mul_inter (f : α → M) (s t : set α) : mul_indicator (s ∪ t) f * mul_indicator (s ∩ t) f = mul_indicator s f * mul_indicator t f := funext $ mul_indicator_union_mul_inter_apply f s t @[to_additive] lemma mul_indicator_union_of_not_mem_inter (h : a ∉ s ∩ t) (f : α → M) : mul_indicator (s ∪ t) f a = mul_indicator s f a * mul_indicator t f a := by rw [← mul_indicator_union_mul_inter_apply f s t, mul_indicator_of_not_mem h, mul_one] @[to_additive] lemma mul_indicator_union_of_disjoint (h : disjoint s t) (f : α → M) : mul_indicator (s ∪ t) f = λa, mul_indicator s f a * mul_indicator t f a := funext $ λa, mul_indicator_union_of_not_mem_inter (λ ha, h.le_bot ha) _ @[to_additive] lemma mul_indicator_mul (s : set α) (f g : α → M) : mul_indicator s (λa, f a * g a) = λa, mul_indicator s f a * mul_indicator s g a := by { funext, simp only [mul_indicator], split_ifs, { refl }, rw mul_one } @[to_additive] lemma mul_indicator_mul' (s : set α) (f g : α → M) : mul_indicator s (f * g) = mul_indicator s f * mul_indicator s g := mul_indicator_mul s f g @[simp, to_additive] lemma mul_indicator_compl_mul_self_apply (s : set α) (f : α → M) (a : α) : mul_indicator sᶜ f a * mul_indicator s f a = f a := classical.by_cases (λ ha : a ∈ s, by simp [ha]) (λ ha, by simp [ha]) @[simp, to_additive] lemma mul_indicator_compl_mul_self (s : set α) (f : α → M) : mul_indicator sᶜ f * mul_indicator s f = f := funext $ mul_indicator_compl_mul_self_apply s f @[simp, to_additive] lemma mul_indicator_self_mul_compl_apply (s : set α) (f : α → M) (a : α) : mul_indicator s f a * mul_indicator sᶜ f a = f a := classical.by_cases (λ ha : a ∈ s, by simp [ha]) (λ ha, by simp [ha]) @[simp, to_additive] lemma mul_indicator_self_mul_compl (s : set α) (f : α → M) : mul_indicator s f * mul_indicator sᶜ f = f := funext $ mul_indicator_self_mul_compl_apply s f @[to_additive] lemma mul_indicator_mul_eq_left {f g : α → M} (h : disjoint (mul_support f) (mul_support g)) : (mul_support f).mul_indicator (f * g) = f := begin refine (mul_indicator_congr $ λ x hx, _).trans mul_indicator_mul_support, have : g x = 1, from nmem_mul_support.1 (disjoint_left.1 h hx), rw [pi.mul_apply, this, mul_one] end @[to_additive] lemma mul_indicator_mul_eq_right {f g : α → M} (h : disjoint (mul_support f) (mul_support g)) : (mul_support g).mul_indicator (f * g) = g := begin refine (mul_indicator_congr $ λ x hx, _).trans mul_indicator_mul_support, have : f x = 1, from nmem_mul_support.1 (disjoint_right.1 h hx), rw [pi.mul_apply, this, one_mul] end @[to_additive] lemma mul_indicator_mul_compl_eq_piecewise [decidable_pred (∈ s)] (f g : α → M) : s.mul_indicator f * sᶜ.mul_indicator g = s.piecewise f g := begin ext x, by_cases h : x ∈ s, { rw [piecewise_eq_of_mem _ _ _ h, pi.mul_apply, set.mul_indicator_of_mem h, set.mul_indicator_of_not_mem (set.not_mem_compl_iff.2 h), mul_one] }, { rw [piecewise_eq_of_not_mem _ _ _ h, pi.mul_apply, set.mul_indicator_of_not_mem h, set.mul_indicator_of_mem (set.mem_compl h), one_mul] }, end /-- `set.mul_indicator` as a `monoid_hom`. -/ @[to_additive "`set.indicator` as an `add_monoid_hom`."] noncomputable def mul_indicator_hom {α} (M) [mul_one_class M] (s : set α) : (α → M) →* (α → M) := { to_fun := mul_indicator s, map_one' := mul_indicator_one M s, map_mul' := mul_indicator_mul s } end monoid section distrib_mul_action variables {A : Type*} [add_monoid A] [monoid M] [distrib_mul_action M A] lemma indicator_smul_apply (s : set α) (r : α → M) (f : α → A) (x : α) : indicator s (λ x, r x • f x) x = r x • indicator s f x := by { dunfold indicator, split_ifs, exacts [rfl, (smul_zero (r x)).symm] } lemma indicator_smul (s : set α) (r : α → M) (f : α → A) : indicator s (λ (x : α), r x • f x) = λ (x : α), r x • indicator s f x := funext $ indicator_smul_apply s r f lemma indicator_const_smul_apply (s : set α) (r : M) (f : α → A) (x : α) : indicator s (λ x, r • f x) x = r • indicator s f x := indicator_smul_apply s (λ x, r) f x lemma indicator_const_smul (s : set α) (r : M) (f : α → A) : indicator s (λ (x : α), r • f x) = λ (x : α), r • indicator s f x := funext $ indicator_const_smul_apply s r f end distrib_mul_action section group variables {G : Type*} [group G] {s t : set α} {f g : α → G} {a : α} @[to_additive] lemma mul_indicator_inv' (s : set α) (f : α → G) : mul_indicator s (f⁻¹) = (mul_indicator s f)⁻¹ := (mul_indicator_hom G s).map_inv f @[to_additive] lemma mul_indicator_inv (s : set α) (f : α → G) : mul_indicator s (λa, (f a)⁻¹) = λa, (mul_indicator s f a)⁻¹ := mul_indicator_inv' s f @[to_additive] lemma mul_indicator_div (s : set α) (f g : α → G) : mul_indicator s (λ a, f a / g a) = λ a, mul_indicator s f a / mul_indicator s g a := (mul_indicator_hom G s).map_div f g @[to_additive] lemma mul_indicator_div' (s : set α) (f g : α → G) : mul_indicator s (f / g) = mul_indicator s f / mul_indicator s g := mul_indicator_div s f g @[to_additive indicator_compl'] lemma mul_indicator_compl (s : set α) (f : α → G) : mul_indicator sᶜ f = f * (mul_indicator s f)⁻¹ := eq_mul_inv_of_mul_eq $ s.mul_indicator_compl_mul_self f lemma indicator_compl {G} [add_group G] (s : set α) (f : α → G) : indicator sᶜ f = f - indicator s f := by rw [sub_eq_add_neg, indicator_compl'] @[to_additive indicator_diff'] lemma mul_indicator_diff (h : s ⊆ t) (f : α → G) : mul_indicator (t \ s) f = mul_indicator t f * (mul_indicator s f)⁻¹ := eq_mul_inv_of_mul_eq $ by rw [pi.mul_def, ← mul_indicator_union_of_disjoint disjoint_diff.symm f, diff_union_self, union_eq_self_of_subset_right h] lemma indicator_diff {G : Type*} [add_group G] {s t : set α} (h : s ⊆ t) (f : α → G) : indicator (t \ s) f = indicator t f - indicator s f := by rw [indicator_diff' h, sub_eq_add_neg] end group section comm_monoid variables [comm_monoid M] /-- Consider a product of `g i (f i)` over a `finset`. Suppose `g` is a function such as `pow`, which maps a second argument of `1` to `1`. Then if `f` is replaced by the corresponding multiplicative indicator function, the `finset` may be replaced by a possibly larger `finset` without changing the value of the sum. -/ @[to_additive] lemma prod_mul_indicator_subset_of_eq_one [has_one N] (f : α → N) (g : α → N → M) {s t : finset α} (h : s ⊆ t) (hg : ∀ a, g a 1 = 1) : ∏ i in s, g i (f i) = ∏ i in t, g i (mul_indicator ↑s f i) := begin rw ← finset.prod_subset h _, { apply finset.prod_congr rfl, intros i hi, congr, symmetry, exact mul_indicator_of_mem hi _ }, { refine λ i hi hn, _, convert hg i, exact mul_indicator_of_not_mem hn _ } end /-- Consider a sum of `g i (f i)` over a `finset`. Suppose `g` is a function such as multiplication, which maps a second argument of 0 to 0. (A typical use case would be a weighted sum of `f i * h i` or `f i • h i`, where `f` gives the weights that are multiplied by some other function `h`.) Then if `f` is replaced by the corresponding indicator function, the `finset` may be replaced by a possibly larger `finset` without changing the value of the sum. -/ add_decl_doc set.sum_indicator_subset_of_eq_zero /-- Taking the product of an indicator function over a possibly larger `finset` is the same as taking the original function over the original `finset`. -/ @[to_additive "Summing an indicator function over a possibly larger `finset` is the same as summing the original function over the original `finset`."] lemma prod_mul_indicator_subset (f : α → M) {s t : finset α} (h : s ⊆ t) : ∏ i in s, f i = ∏ i in t, mul_indicator ↑s f i := prod_mul_indicator_subset_of_eq_one _ (λ a b, b) h (λ _, rfl) @[to_additive] lemma _root_.finset.prod_mul_indicator_eq_prod_filter (s : finset ι) (f : ι → α → M) (t : ι → set α) (g : ι → α) [decidable_pred (λ i, g i ∈ t i)]: ∏ i in s, mul_indicator (t i) (f i) (g i) = ∏ i in s.filter (λ i, g i ∈ t i), f i (g i) := begin refine (finset.prod_filter_mul_prod_filter_not s (λ i, g i ∈ t i) _).symm.trans _, refine eq.trans _ (mul_one _), exact congr_arg2 (*) (finset.prod_congr rfl $ λ x hx, mul_indicator_of_mem (finset.mem_filter.1 hx).2 _) (finset.prod_eq_one $ λ x hx, mul_indicator_of_not_mem (finset.mem_filter.1 hx).2 _) end @[to_additive] lemma mul_indicator_finset_prod (I : finset ι) (s : set α) (f : ι → α → M) : mul_indicator s (∏ i in I, f i) = ∏ i in I, mul_indicator s (f i) := (mul_indicator_hom M s).map_prod _ _ @[to_additive] lemma mul_indicator_finset_bUnion {ι} (I : finset ι) (s : ι → set α) {f : α → M} : (∀ (i ∈ I) (j ∈ I), i ≠ j → disjoint (s i) (s j)) → mul_indicator (⋃ i ∈ I, s i) f = λ a, ∏ i in I, mul_indicator (s i) f a := begin classical, refine finset.induction_on I _ _, { intro h, funext, simp }, assume a I haI ih hI, funext, rw [finset.prod_insert haI, finset.set_bUnion_insert, mul_indicator_union_of_not_mem_inter, ih _], { assume i hi j hj hij, exact hI i (finset.mem_insert_of_mem hi) j (finset.mem_insert_of_mem hj) hij }, simp only [not_exists, exists_prop, mem_Union, mem_inter_iff, not_and], assume hx a' ha', refine disjoint_left.1 (hI a (finset.mem_insert_self _ _) a' (finset.mem_insert_of_mem ha') _) hx, exact (ne_of_mem_of_not_mem ha' haI).symm end @[to_additive] lemma mul_indicator_finset_bUnion_apply {ι} (I : finset ι) (s : ι → set α) {f : α → M} (h : ∀ (i ∈ I) (j ∈ I), i ≠ j → disjoint (s i) (s j)) (x : α) : mul_indicator (⋃ i ∈ I, s i) f x = ∏ i in I, mul_indicator (s i) f x := by rw set.mul_indicator_finset_bUnion I s h end comm_monoid section mul_zero_class variables [mul_zero_class M] {s t : set α} {f g : α → M} {a : α} lemma indicator_mul (s : set α) (f g : α → M) : indicator s (λa, f a * g a) = λa, indicator s f a * indicator s g a := by { funext, simp only [indicator], split_ifs, { refl }, rw mul_zero } lemma indicator_mul_left (s : set α) (f g : α → M) : indicator s (λa, f a * g a) a = indicator s f a * g a := by { simp only [indicator], split_ifs, { refl }, rw [zero_mul] } lemma indicator_mul_right (s : set α) (f g : α → M) : indicator s (λa, f a * g a) a = f a * indicator s g a := by { simp only [indicator], split_ifs, { refl }, rw [mul_zero] } lemma inter_indicator_mul {t1 t2 : set α} (f g : α → M) (x : α) : (t1 ∩ t2).indicator (λ x, f x * g x) x = t1.indicator f x * t2.indicator g x := by { rw [← set.indicator_indicator], simp [indicator] } end mul_zero_class section mul_zero_one_class variables [mul_zero_one_class M] lemma inter_indicator_one {s t : set α} : (s ∩ t).indicator (1 : _ → M) = s.indicator 1 * t.indicator 1 := funext (λ _, by simpa only [← inter_indicator_mul, pi.mul_apply, pi.one_apply, one_mul]) lemma indicator_prod_one {s : set α} {t : set β} {x : α} {y : β} : (s ×ˢ t).indicator (1 : _ → M) (x, y) = s.indicator 1 x * t.indicator 1 y := by { classical, simp [indicator_apply, ←ite_and] } variables (M) [nontrivial M] lemma indicator_eq_zero_iff_not_mem {U : set α} {x : α} : indicator U 1 x = (0 : M) ↔ x ∉ U := by { classical, simp [indicator_apply, imp_false] } lemma indicator_eq_one_iff_mem {U : set α} {x : α} : indicator U 1 x = (1 : M) ↔ x ∈ U := by { classical, simp [indicator_apply, imp_false] } lemma indicator_one_inj {U V : set α} (h : indicator U (1 : α → M) = indicator V 1) : U = V := by { ext, simp_rw [← indicator_eq_one_iff_mem M, h] } end mul_zero_one_class section order variables [has_one M] {s t : set α} {f g : α → M} {a : α} {y : M} section variables [has_le M] @[to_additive] lemma mul_indicator_apply_le' (hfg : a ∈ s → f a ≤ y) (hg : a ∉ s → 1 ≤ y) : mul_indicator s f a ≤ y := begin by_cases ha : a ∈ s, { simpa [ha] using hfg ha }, { simpa [ha] using hg ha }, end @[to_additive] lemma mul_indicator_le' (hfg : ∀ a ∈ s, f a ≤ g a) (hg : ∀ a ∉ s, 1 ≤ g a) : mul_indicator s f ≤ g := λ a, mul_indicator_apply_le' (hfg _) (hg _) @[to_additive] lemma le_mul_indicator_apply {y} (hfg : a ∈ s → y ≤ g a) (hf : a ∉ s → y ≤ 1) : y ≤ mul_indicator s g a := @mul_indicator_apply_le' α Mᵒᵈ ‹_› _ _ _ _ _ hfg hf @[to_additive] lemma le_mul_indicator (hfg : ∀ a ∈ s, f a ≤ g a) (hf : ∀ a ∉ s, f a ≤ 1) : f ≤ mul_indicator s g := λ a, le_mul_indicator_apply (hfg _) (hf _) end variables [preorder M] @[to_additive indicator_apply_nonneg] lemma one_le_mul_indicator_apply (h : a ∈ s → 1 ≤ f a) : 1 ≤ mul_indicator s f a := le_mul_indicator_apply h (λ _, le_rfl) @[to_additive indicator_nonneg] lemma one_le_mul_indicator (h : ∀ a ∈ s, 1 ≤ f a) (a : α) : 1 ≤ mul_indicator s f a := one_le_mul_indicator_apply (h a) @[to_additive] lemma mul_indicator_apply_le_one (h : a ∈ s → f a ≤ 1) : mul_indicator s f a ≤ 1 := mul_indicator_apply_le' h (λ _, le_rfl) @[to_additive] lemma mul_indicator_le_one (h : ∀ a ∈ s, f a ≤ 1) (a : α) : mul_indicator s f a ≤ 1 := mul_indicator_apply_le_one (h a) @[to_additive] lemma mul_indicator_le_mul_indicator (h : f a ≤ g a) : mul_indicator s f a ≤ mul_indicator s g a := mul_indicator_rel_mul_indicator le_rfl (λ _, h) attribute [mono] mul_indicator_le_mul_indicator indicator_le_indicator @[to_additive] lemma mul_indicator_le_mul_indicator_of_subset (h : s ⊆ t) (hf : ∀ a, 1 ≤ f a) (a : α) : mul_indicator s f a ≤ mul_indicator t f a := mul_indicator_apply_le' (λ ha, le_mul_indicator_apply (λ _, le_rfl) (λ hat, (hat $ h ha).elim)) (λ ha, one_le_mul_indicator_apply (λ _, hf _)) @[to_additive] lemma mul_indicator_le_self' (hf : ∀ x ∉ s, 1 ≤ f x) : mul_indicator s f ≤ f := mul_indicator_le' (λ _ _, le_rfl) hf @[to_additive] lemma mul_indicator_Union_apply {ι M} [complete_lattice M] [has_one M] (h1 : (⊥:M) = 1) (s : ι → set α) (f : α → M) (x : α) : mul_indicator (⋃ i, s i) f x = ⨆ i, mul_indicator (s i) f x := begin by_cases hx : x ∈ ⋃ i, s i, { rw [mul_indicator_of_mem hx], rw [mem_Union] at hx, refine le_antisymm _ (supr_le $ λ i, mul_indicator_le_self' (λ x hx, h1 ▸ bot_le) x), rcases hx with ⟨i, hi⟩, exact le_supr_of_le i (ge_of_eq $ mul_indicator_of_mem hi _) }, { rw [mul_indicator_of_not_mem hx], simp only [mem_Union, not_exists] at hx, simp [hx, ← h1] } end end order section canonically_ordered_monoid variables [canonically_ordered_monoid M] @[to_additive] lemma mul_indicator_le_self (s : set α) (f : α → M) : mul_indicator s f ≤ f := mul_indicator_le_self' $ λ _ _, one_le _ @[to_additive] lemma mul_indicator_apply_le {a : α} {s : set α} {f g : α → M} (hfg : a ∈ s → f a ≤ g a) : mul_indicator s f a ≤ g a := mul_indicator_apply_le' hfg $ λ _, one_le _ @[to_additive] lemma mul_indicator_le {s : set α} {f g : α → M} (hfg : ∀ a ∈ s, f a ≤ g a) : mul_indicator s f ≤ g := mul_indicator_le' hfg $ λ _ _, one_le _ end canonically_ordered_monoid lemma indicator_le_indicator_nonneg {β} [linear_order β] [has_zero β] (s : set α) (f : α → β) : s.indicator f ≤ {x | 0 ≤ f x}.indicator f := begin intro x, classical, simp_rw indicator_apply, split_ifs, { exact le_rfl, }, { exact (not_le.mp h_1).le, }, { exact h_1, }, { exact le_rfl, }, end lemma indicator_nonpos_le_indicator {β} [linear_order β] [has_zero β] (s : set α) (f : α → β) : {x | f x ≤ 0}.indicator f ≤ s.indicator f := @indicator_le_indicator_nonneg α βᵒᵈ _ _ s f end set @[to_additive] lemma monoid_hom.map_mul_indicator {M N : Type*} [mul_one_class M] [mul_one_class N] (f : M →* N) (s : set α) (g : α → M) (x : α) : f (s.mul_indicator g x) = s.mul_indicator (f ∘ g) x := congr_fun (set.mul_indicator_comp_of_one f.map_one).symm x
60178e0c4ca76dcd49ac0bf38d7376fbdd8ced99
c8b4b578b2fe61d500fbca7480e506f6603ea698
/src/number_theory/cyclotomic/galois_action_on_cyclo.lean
82901c84ec87f72cc3b8eaf7944d57da66303fb1
[]
no_license
leanprover-community/flt-regular
aa7e564f2679dfd2e86015a5a9674a6e1197f7cc
67fb3e176584bbc03616c221a7be6fa28c5ccd32
refs/heads/master
1,692,188,905,751
1,691,766,312,000
1,691,766,312,000
421,021,216
19
4
null
1,694,532,115,000
1,635,166,136,000
Lean
UTF-8
Lean
false
false
4,601
lean
import number_theory.cyclotomic.cyclotomic_units import number_theory.cyclotomic.gal universes u open finite_dimensional open_locale number_field theorem power_basis.rat_hom_ext {S S' : Type*} [comm_ring S] [hS : algebra ℚ S] [ring S'] [hS' : algebra ℚ S'] (pb : power_basis ℚ S) ⦃f g : S →+* S'⦄ (h : f pb.gen = g pb.gen) : f = g := let f' := f.to_rat_alg_hom, g' := g.to_rat_alg_hom in fun_like.ext f g $ by convert fun_like.ext_iff.mp (pb.alg_hom_ext (show f' pb.gen = g' pb.gen, from h)) variables (K : Type*) (p : ℕ+) [field K] [char_zero K] [is_cyclotomic_extension {p} ℚ K] variables {ζ : K} (hζ : is_primitive_root ζ p) local notation `RR` := 𝓞 K -- @Chris: you mentioned "checking automorphisms agree only on a generator" - -- what you want is `power_basis.alg_hom_ext` open_locale number_field cyclotomic open is_cyclotomic_extension polynomial noncomputable theory /-- complex conjugation as a Galois automorphism -/ def gal_conj : K ≃ₐ[ℚ] K := ((aut_equiv_pow K (cyclotomic.irreducible_rat p.pos)).symm (-1)) variables {K p} lemma zmod.val_neg_one' : ∀ {n : ℕ}, 0 < n → (-1 : zmod n).val = n - 1 | (n + 1) _ := zmod.val_neg_one _ lemma gal_conj_zeta : gal_conj K p (zeta p ℚ K) = (zeta p ℚ K)⁻¹ := begin let hζ := zeta_spec p ℚ K, simp only [gal_conj, units.coe_neg_one, aut_equiv_pow_symm_apply, alg_equiv.coe_alg_hom, power_basis.equiv_of_minpoly_apply], convert (hζ.power_basis ℚ).lift_gen _ _, rw [is_primitive_root.power_basis_gen, zmod.val_neg_one' p.pos, pow_sub₀ _ (hζ.ne_zero p.ne_zero) p.pos, pow_one, hζ.pow_eq_one, one_mul] end include hζ @[simp] lemma gal_conj_zeta_runity : gal_conj K p ζ = ζ⁻¹ := begin obtain ⟨t, ht, rfl⟩ := (zeta_spec p ℚ K).eq_pow_of_pow_eq_one hζ.pow_eq_one p.pos, rw [map_pow, gal_conj_zeta, inv_pow] end lemma gal_conj_zeta_runity_pow (n : ℕ) : gal_conj K p (ζ^n) = (ζ⁻¹)^n := by rw [map_pow, gal_conj_zeta_runity hζ] omit hζ open_locale complex_conjugate lemma conj_norm_one (x : ℂ) (h : complex.abs x = 1) : conj x = x⁻¹ := by rw [←complex.abs_mul_exp_arg_mul_I x, h, complex.of_real_one, one_mul, ←complex.exp_conj, ←complex.exp_neg, map_mul, complex.conj_I, mul_neg, complex.conj_of_real] include hζ @[simp] lemma embedding_conj (x : K) (φ : K →+* ℂ) : conj (φ x) = φ (gal_conj K p x) := begin -- dependent type theory is my favourite change (ring_hom.comp conj φ x) = (φ.comp $ ↑(gal_conj K p)) x, revert x, suffices : φ (gal_conj K p ζ) = conj (φ ζ), { rw ←function.funext_iff, dsimp only, congr' 1, apply (hζ.power_basis ℚ).rat_hom_ext, { exact this.symm }, { exact algebra_rat } }, rw [conj_norm_one, gal_conj_zeta_runity hζ, map_inv₀], refine complex.norm_eq_one_of_pow_eq_one _ p.ne_zero, rw [←map_pow, hζ.pow_eq_one, map_one] end omit hζ -- this proof makes me happy inside lemma gal_conj_idempotent : (gal_conj K p).trans (gal_conj K p) = alg_equiv.refl := begin rw [←alg_equiv.aut_mul, gal_conj, ←map_mul, neg_one_mul, neg_neg, map_one], refl, end variable (p) --generalize this lemma gal_map_mem {x : K} (hx : x ∈ RR) (σ : K →ₐ[ℚ] K) : σ x ∈ RR := map_is_integral (σ.restrict_scalars ℤ) hx lemma gal_map_mem_subtype (σ : K →ₐ[ℚ] K) (x : RR) : σ x ∈ RR := by simp [gal_map_mem] /-- Restriction of `σ : K →ₐ[ℚ] K` to the ring of integers. -/ def int_gal (σ : K →ₐ[ℚ] K) : RR →ₐ[ℤ] RR := ((σ.restrict_scalars ℤ).restrict_domain RR).cod_restrict RR (gal_map_mem_subtype σ) @[simp] lemma int_gal_apply_coe (σ : K →ₐ[ℚ] K) (x : RR) : (int_gal σ x : K) = σ x := rfl /-- Restriction of `σ : K →ₐ[ℚ] K` to the units of the ring of integers. -/ def units_gal (σ : K →ₐ[ℚ] K) : RRˣ →* RRˣ := units.map $ int_gal σ /-- `unit_gal_conj` as a bundled hom. -/ def unit_gal_conj : RRˣ →* RRˣ := units_gal (gal_conj K p) lemma unit_gal_conj_spec (u : RRˣ) : gal_conj K p (u : 𝓞 K) = ↑(unit_gal_conj K p u : 𝓞 K) := rfl lemma unit_lemma_val_one (u : RRˣ) (φ : K →+* ℂ) : complex.abs (φ (u * (unit_gal_conj K p u)⁻¹)) = 1 := begin rw [map_mul, complex.abs.is_absolute_value.abv_mul, map_inv₀, coe_coe (unit_gal_conj K p u), ←unit_gal_conj_spec, ←embedding_conj $ zeta_spec p ℚ K], simp only [coe_coe, map_inv₀, complex.abs_conj], rw [mul_inv_eq_one₀], intro h, simp only [_root_.map_eq_zero] at h, rw [← subalgebra.coe_zero (𝓞 K), subtype.coe_inj] at h, refine units.ne_zero _ h end
c89eb7924a81c77c6569ec99460e681741d6d11f
9dc8cecdf3c4634764a18254e94d43da07142918
/src/analysis/convex/cone/basic.lean
92aea1081b836da0c2c798605de3712f45f2794d
[ "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
34,844
lean
/- Copyright (c) 2020 Yury Kudryashov All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Frédéric Dupuis -/ import analysis.inner_product_space.projection /-! # Convex cones In a `𝕜`-module `E`, we define a convex cone as a set `s` such that `a • x + b • y ∈ s` whenever `x, y ∈ s` and `a, b > 0`. We prove that convex cones form a `complete_lattice`, and define their images (`convex_cone.map`) and preimages (`convex_cone.comap`) under linear maps. We define pointed, blunt, flat and salient cones, and prove the correspondence between convex cones and ordered modules. We define `convex.to_cone` to be the minimal cone that includes a given convex set. We define `set.inner_dual_cone` to be the cone consisting of all points `y` such that for all points `x` in a given set `0 ≤ ⟪ x, y ⟫`. ## Main statements We prove two extension theorems: * `riesz_extension`: [M. Riesz extension theorem](https://en.wikipedia.org/wiki/M._Riesz_extension_theorem) says that if `s` is a convex cone in a real vector space `E`, `p` is a submodule of `E` such that `p + s = E`, and `f` is a linear function `p → ℝ` which is nonnegative on `p ∩ s`, then there exists a globally defined linear function `g : E → ℝ` that agrees with `f` on `p`, and is nonnegative on `s`. * `exists_extension_of_le_sublinear`: Hahn-Banach theorem: if `N : E → ℝ` is a sublinear map, `f` is a linear map defined on a subspace of `E`, and `f x ≤ N x` for all `x` in the domain of `f`, then `f` can be extended to the whole space to a linear map `g` such that `g x ≤ N x` for all `x` We prove the following theorems: * `convex_cone.hyperplane_separation_of_nonempty_of_is_closed_of_nmem`: This variant of the [hyperplane separation theorem](https://en.wikipedia.org/wiki/Hyperplane_separation_theorem) states that given a nonempty, closed, convex cone `K` in a complete, real inner product space `H` and a point `b` disjoint from it, there is a vector `y` which separates `b` from `K` in the sense that for all points `x` in `K`, `0 ≤ ⟪x, y⟫_ℝ` and `⟪y, b⟫_ℝ < 0`. This is also a geometric interpretation of the [Farkas lemma](https://en.wikipedia.org/wiki/Farkas%27_lemma#Geometric_interpretation). * `convex_cone.inner_dual_cone_of_inner_dual_cone_eq_self`: The `inner_dual_cone` of the `inner_dual_cone` of a nonempty, closed, convex cone is itself. ## Implementation notes While `convex 𝕜` is a predicate on sets, `convex_cone 𝕜 E` is a bundled convex cone. ## References * https://en.wikipedia.org/wiki/Convex_cone * [Stephen P. Boyd and Lieven Vandenberghe, *Convex Optimization*][boydVandenberghe2004] * [Emo Welzl and Bernd Gärtner, *Cone Programming*][welzl_garter] -/ open set linear_map open_locale classical pointwise variables {𝕜 E F G : Type*} /-! ### Definition of `convex_cone` and basic properties -/ section definitions variables (𝕜 E) [ordered_semiring 𝕜] /-- A convex cone is a subset `s` of a `𝕜`-module such that `a • x + b • y ∈ s` whenever `a, b > 0` and `x, y ∈ s`. -/ structure convex_cone [add_comm_monoid E] [has_smul 𝕜 E] := (carrier : set E) (smul_mem' : ∀ ⦃c : 𝕜⦄, 0 < c → ∀ ⦃x : E⦄, x ∈ carrier → c • x ∈ carrier) (add_mem' : ∀ ⦃x⦄ (hx : x ∈ carrier) ⦃y⦄ (hy : y ∈ carrier), x + y ∈ carrier) end definitions variables {𝕜 E} namespace convex_cone section ordered_semiring variables [ordered_semiring 𝕜] [add_comm_monoid E] section has_smul variables [has_smul 𝕜 E] (S T : convex_cone 𝕜 E) instance : set_like (convex_cone 𝕜 E) E := { coe := carrier, coe_injective' := λ S T h, by cases S; cases T; congr' } @[simp] lemma coe_mk {s : set E} {h₁ h₂} : ↑(@mk 𝕜 _ _ _ _ s h₁ h₂) = s := rfl @[simp] lemma mem_mk {s : set E} {h₁ h₂ x} : x ∈ @mk 𝕜 _ _ _ _ s h₁ h₂ ↔ x ∈ s := iff.rfl /-- Two `convex_cone`s are equal if they have the same elements. -/ @[ext] theorem ext {S T : convex_cone 𝕜 E} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := set_like.ext h lemma smul_mem {c : 𝕜} {x : E} (hc : 0 < c) (hx : x ∈ S) : c • x ∈ S := S.smul_mem' hc hx lemma add_mem ⦃x⦄ (hx : x ∈ S) ⦃y⦄ (hy : y ∈ S) : x + y ∈ S := S.add_mem' hx hy instance : add_mem_class (convex_cone 𝕜 E) E := { add_mem := λ c a b ha hb, add_mem c ha hb } instance : has_inf (convex_cone 𝕜 E) := ⟨λ S T, ⟨S ∩ T, λ c hc x hx, ⟨S.smul_mem hc hx.1, T.smul_mem hc hx.2⟩, λ x hx y hy, ⟨S.add_mem hx.1 hy.1, T.add_mem hx.2 hy.2⟩⟩⟩ @[simp] lemma coe_inf : ((S ⊓ T : convex_cone 𝕜 E) : set E) = ↑S ∩ ↑T := rfl lemma mem_inf {x} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := iff.rfl instance : has_Inf (convex_cone 𝕜 E) := ⟨λ S, ⟨⋂ s ∈ S, ↑s, λ c hc x hx, mem_bInter $ λ s hs, s.smul_mem hc $ mem_Inter₂.1 hx s hs, λ x hx y hy, mem_bInter $ λ s hs, s.add_mem (mem_Inter₂.1 hx s hs) (mem_Inter₂.1 hy s hs)⟩⟩ @[simp] lemma coe_Inf (S : set (convex_cone 𝕜 E)) : ↑(Inf S) = ⋂ s ∈ S, (s : set E) := rfl lemma mem_Inf {x : E} {S : set (convex_cone 𝕜 E)} : x ∈ Inf S ↔ ∀ s ∈ S, x ∈ s := mem_Inter₂ @[simp] lemma coe_infi {ι : Sort*} (f : ι → convex_cone 𝕜 E) : ↑(infi f) = ⋂ i, (f i : set E) := by simp [infi] lemma mem_infi {ι : Sort*} {x : E} {f : ι → convex_cone 𝕜 E} : x ∈ infi f ↔ ∀ i, x ∈ f i := mem_Inter₂.trans $ by simp variables (𝕜) instance : has_bot (convex_cone 𝕜 E) := ⟨⟨∅, λ c hc x, false.elim, λ x, false.elim⟩⟩ lemma mem_bot (x : E) : x ∈ (⊥ : convex_cone 𝕜 E) = false := rfl @[simp] lemma coe_bot : ↑(⊥ : convex_cone 𝕜 E) = (∅ : set E) := rfl instance : has_top (convex_cone 𝕜 E) := ⟨⟨univ, λ c hc x hx, mem_univ _, λ x hx y hy, mem_univ _⟩⟩ lemma mem_top (x : E) : x ∈ (⊤ : convex_cone 𝕜 E) := mem_univ x @[simp] lemma coe_top : ↑(⊤ : convex_cone 𝕜 E) = (univ : set E) := rfl instance : complete_lattice (convex_cone 𝕜 E) := { le := (≤), lt := (<), bot := (⊥), bot_le := λ S x, false.elim, top := (⊤), le_top := λ S x hx, mem_top 𝕜 x, inf := (⊓), Inf := has_Inf.Inf, sup := λ a b, Inf {x | a ≤ x ∧ b ≤ x}, Sup := λ s, Inf {T | ∀ S ∈ s, S ≤ T}, le_sup_left := λ a b, λ x hx, mem_Inf.2 $ λ s hs, hs.1 hx, le_sup_right := λ a b, λ x hx, mem_Inf.2 $ λ s hs, hs.2 hx, sup_le := λ a b c ha hb x hx, mem_Inf.1 hx c ⟨ha, hb⟩, le_inf := λ a b c ha hb x hx, ⟨ha hx, hb hx⟩, inf_le_left := λ a b x, and.left, inf_le_right := λ a b x, and.right, le_Sup := λ s p hs x hx, mem_Inf.2 $ λ t ht, ht p hs hx, Sup_le := λ s p hs x hx, mem_Inf.1 hx p hs, le_Inf := λ s a ha x hx, mem_Inf.2 $ λ t ht, ha t ht hx, Inf_le := λ s a ha x hx, mem_Inf.1 hx _ ha, .. set_like.partial_order } instance : inhabited (convex_cone 𝕜 E) := ⟨⊥⟩ end has_smul section module variables [module 𝕜 E] (S : convex_cone 𝕜 E) protected lemma convex : convex 𝕜 (S : set E) := convex_iff_forall_pos.2 $ λ x hx y hy a b ha hb _, S.add_mem (S.smul_mem ha hx) (S.smul_mem hb hy) end module end ordered_semiring section linear_ordered_field variables [linear_ordered_field 𝕜] section add_comm_monoid variables [add_comm_monoid E] [add_comm_monoid F] [add_comm_monoid G] section mul_action variables [mul_action 𝕜 E] (S : convex_cone 𝕜 E) lemma smul_mem_iff {c : 𝕜} (hc : 0 < c) {x : E} : c • x ∈ S ↔ x ∈ S := ⟨λ h, inv_smul_smul₀ hc.ne' x ▸ S.smul_mem (inv_pos.2 hc) h, S.smul_mem hc⟩ end mul_action section module variables [module 𝕜 E] [module 𝕜 F] [module 𝕜 G] /-- The image of a convex cone under a `𝕜`-linear map is a convex cone. -/ def map (f : E →ₗ[𝕜] F) (S : convex_cone 𝕜 E) : convex_cone 𝕜 F := { carrier := f '' S, smul_mem' := λ c hc y ⟨x, hx, hy⟩, hy ▸ f.map_smul c x ▸ mem_image_of_mem f (S.smul_mem hc hx), add_mem' := λ y₁ ⟨x₁, hx₁, hy₁⟩ y₂ ⟨x₂, hx₂, hy₂⟩, hy₁ ▸ hy₂ ▸ f.map_add x₁ x₂ ▸ mem_image_of_mem f (S.add_mem hx₁ hx₂) } @[simp] lemma mem_map {f : E →ₗ[𝕜] F} {S : convex_cone 𝕜 E} {y : F} : y ∈ S.map f ↔ ∃ x ∈ S, f x = y := mem_image_iff_bex lemma map_map (g : F →ₗ[𝕜] G) (f : E →ₗ[𝕜] F) (S : convex_cone 𝕜 E) : (S.map f).map g = S.map (g.comp f) := set_like.coe_injective $ image_image g f S @[simp] lemma map_id (S : convex_cone 𝕜 E) : S.map linear_map.id = S := set_like.coe_injective $ image_id _ /-- The preimage of a convex cone under a `𝕜`-linear map is a convex cone. -/ def comap (f : E →ₗ[𝕜] F) (S : convex_cone 𝕜 F) : convex_cone 𝕜 E := { carrier := f ⁻¹' S, smul_mem' := λ c hc x hx, by { rw [mem_preimage, f.map_smul c], exact S.smul_mem hc hx }, add_mem' := λ x hx y hy, by { rw [mem_preimage, f.map_add], exact S.add_mem hx hy } } @[simp] lemma coe_comap (f : E →ₗ[𝕜] F) (S : convex_cone 𝕜 F) : (S.comap f : set E) = f ⁻¹' S := rfl @[simp] lemma comap_id (S : convex_cone 𝕜 E) : S.comap linear_map.id = S := set_like.coe_injective preimage_id lemma comap_comap (g : F →ₗ[𝕜] G) (f : E →ₗ[𝕜] F) (S : convex_cone 𝕜 G) : (S.comap g).comap f = S.comap (g.comp f) := set_like.coe_injective $ preimage_comp.symm @[simp] lemma mem_comap {f : E →ₗ[𝕜] F} {S : convex_cone 𝕜 F} {x : E} : x ∈ S.comap f ↔ f x ∈ S := iff.rfl end module end add_comm_monoid section ordered_add_comm_group variables [ordered_add_comm_group E] [module 𝕜 E] /-- Constructs an ordered module given an `ordered_add_comm_group`, a cone, and a proof that the order relation is the one defined by the cone. -/ lemma to_ordered_smul (S : convex_cone 𝕜 E) (h : ∀ x y : E, x ≤ y ↔ y - x ∈ S) : ordered_smul 𝕜 E := ordered_smul.mk' begin intros x y z xy hz, rw [h (z • x) (z • y), ←smul_sub z y x], exact smul_mem S hz ((h x y).mp xy.le), end end ordered_add_comm_group end linear_ordered_field /-! ### Convex cones with extra properties -/ section ordered_semiring variables [ordered_semiring 𝕜] section add_comm_monoid variables [add_comm_monoid E] [has_smul 𝕜 E] (S : convex_cone 𝕜 E) /-- A convex cone is pointed if it includes `0`. -/ def pointed (S : convex_cone 𝕜 E) : Prop := (0 : E) ∈ S /-- A convex cone is blunt if it doesn't include `0`. -/ def blunt (S : convex_cone 𝕜 E) : Prop := (0 : E) ∉ S lemma pointed_iff_not_blunt (S : convex_cone 𝕜 E) : S.pointed ↔ ¬S.blunt := ⟨λ h₁ h₂, h₂ h₁, not_not.mp⟩ lemma blunt_iff_not_pointed (S : convex_cone 𝕜 E) : S.blunt ↔ ¬S.pointed := by rw [pointed_iff_not_blunt, not_not] lemma pointed.mono {S T : convex_cone 𝕜 E} (h : S ≤ T) : S.pointed → T.pointed := @h _ lemma blunt.anti {S T : convex_cone 𝕜 E} (h : T ≤ S) : S.blunt → T.blunt := (∘ @@h) end add_comm_monoid section add_comm_group variables [add_comm_group E] [has_smul 𝕜 E] (S : convex_cone 𝕜 E) /-- A convex cone is flat if it contains some nonzero vector `x` and its opposite `-x`. -/ def flat : Prop := ∃ x ∈ S, x ≠ (0 : E) ∧ -x ∈ S /-- A convex cone is salient if it doesn't include `x` and `-x` for any nonzero `x`. -/ def salient : Prop := ∀ x ∈ S, x ≠ (0 : E) → -x ∉ S lemma salient_iff_not_flat (S : convex_cone 𝕜 E) : S.salient ↔ ¬S.flat := begin split, { rintros h₁ ⟨x, xs, H₁, H₂⟩, exact h₁ x xs H₁ H₂ }, { intro h, unfold flat at h, push_neg at h, exact h } end lemma flat.mono {S T : convex_cone 𝕜 E} (h : S ≤ T) : S.flat → T.flat | ⟨x, hxS, hx, hnxS⟩ := ⟨x, h hxS, hx, h hnxS⟩ lemma salient.anti {S T : convex_cone 𝕜 E} (h : T ≤ S) : S.salient → T.salient := λ hS x hxT hx hnT, hS x (h hxT) hx (h hnT) /-- A flat cone is always pointed (contains `0`). -/ lemma flat.pointed {S : convex_cone 𝕜 E} (hS : S.flat) : S.pointed := begin obtain ⟨x, hx, _, hxneg⟩ := hS, rw [pointed, ←add_neg_self x], exact add_mem S hx hxneg, end /-- A blunt cone (one not containing `0`) is always salient. -/ lemma blunt.salient {S : convex_cone 𝕜 E} : S.blunt → S.salient := begin rw [salient_iff_not_flat, blunt_iff_not_pointed], exact mt flat.pointed, end /-- A pointed convex cone defines a preorder. -/ def to_preorder (h₁ : S.pointed) : preorder E := { le := λ x y, y - x ∈ S, le_refl := λ x, by change x - x ∈ S; rw [sub_self x]; exact h₁, le_trans := λ x y z xy zy, by simpa using add_mem S zy xy } /-- A pointed and salient cone defines a partial order. -/ def to_partial_order (h₁ : S.pointed) (h₂ : S.salient) : partial_order E := { le_antisymm := begin intros a b ab ba, by_contradiction h, have h' : b - a ≠ 0 := λ h'', h (eq_of_sub_eq_zero h'').symm, have H := h₂ (b-a) ab h', rw neg_sub b a at H, exact H ba, end, ..to_preorder S h₁ } /-- A pointed and salient cone defines an `ordered_add_comm_group`. -/ def to_ordered_add_comm_group (h₁ : S.pointed) (h₂ : S.salient) : ordered_add_comm_group E := { add_le_add_left := begin intros a b hab c, change c + b - (c + a) ∈ S, rw add_sub_add_left_eq_sub, exact hab, end, ..to_partial_order S h₁ h₂, ..show add_comm_group E, by apply_instance } end add_comm_group section module variables [add_comm_monoid E] [module 𝕜 E] instance : has_zero (convex_cone 𝕜 E) := ⟨⟨0, λ _ _, by simp, λ _, by simp⟩⟩ @[simp] lemma mem_zero (x : E) : x ∈ (0 : convex_cone 𝕜 E) ↔ x = 0 := iff.rfl @[simp] lemma coe_zero : ((0 : convex_cone 𝕜 E) : set E) = 0 := rfl lemma pointed_zero : (0 : convex_cone 𝕜 E).pointed := by rw [pointed, mem_zero] end module end ordered_semiring /-! ### Positive cone of an ordered module -/ section positive_cone variables (𝕜 E) [ordered_semiring 𝕜] [ordered_add_comm_group E] [module 𝕜 E] [ordered_smul 𝕜 E] /-- The positive cone is the convex cone formed by the set of nonnegative elements in an ordered module. -/ def positive : convex_cone 𝕜 E := { carrier := set.Ici 0, smul_mem' := λ c hc x (hx : _ ≤ _), smul_nonneg hc.le hx, add_mem' := λ x (hx : _ ≤ _) y (hy : _ ≤ _), add_nonneg hx hy } @[simp] lemma mem_positive {x : E} : x ∈ positive 𝕜 E ↔ 0 ≤ x := iff.rfl @[simp] lemma coe_positive : ↑(positive 𝕜 E) = set.Ici (0 : E) := rfl /-- The positive cone of an ordered module is always salient. -/ lemma salient_positive : salient (positive 𝕜 E) := λ x xs hx hx', lt_irrefl (0 : E) (calc 0 < x : lt_of_le_of_ne xs hx.symm ... ≤ x + (-x) : le_add_of_nonneg_right hx' ... = 0 : add_neg_self x) /-- The positive cone of an ordered module is always pointed. -/ lemma pointed_positive : pointed (positive 𝕜 E) := le_refl 0 /-- The cone of strictly positive elements. Note that this naming diverges from the mathlib convention of `pos` and `nonneg` due to "positive cone" (`convex_cone.positive`) being established terminology for the non-negative elements. -/ def strictly_positive : convex_cone 𝕜 E := { carrier := set.Ioi 0, smul_mem' := λ c hc x (hx : _ < _), smul_pos hc hx, add_mem' := λ x hx y hy, add_pos hx hy } @[simp] lemma mem_strictly_positive {x : E} : x ∈ strictly_positive 𝕜 E ↔ 0 < x := iff.rfl @[simp] lemma coe_strictly_positive : ↑(strictly_positive 𝕜 E) = set.Ioi (0 : E) := rfl lemma positive_le_strictly_positive : strictly_positive 𝕜 E ≤ positive 𝕜 E := λ x, le_of_lt /-- The strictly positive cone of an ordered module is always salient. -/ lemma salient_strictly_positive : salient (strictly_positive 𝕜 E) := (salient_positive 𝕜 E).anti $ positive_le_strictly_positive 𝕜 E /-- The strictly positive cone of an ordered module is always blunt. -/ lemma blunt_strictly_positive : blunt (strictly_positive 𝕜 E) := lt_irrefl 0 end positive_cone end convex_cone /-! ### Cone over a convex set -/ section cone_from_convex variables [linear_ordered_field 𝕜] [add_comm_group E] [module 𝕜 E] namespace convex /-- The set of vectors proportional to those in a convex set forms a convex cone. -/ def to_cone (s : set E) (hs : convex 𝕜 s) : convex_cone 𝕜 E := begin apply convex_cone.mk (⋃ (c : 𝕜) (H : 0 < c), c • s); simp only [mem_Union, mem_smul_set], { rintros c c_pos _ ⟨c', c'_pos, x, hx, rfl⟩, exact ⟨c * c', mul_pos c_pos c'_pos, x, hx, (smul_smul _ _ _).symm⟩ }, { rintros _ ⟨cx, cx_pos, x, hx, rfl⟩ _ ⟨cy, cy_pos, y, hy, rfl⟩, have : 0 < cx + cy, from add_pos cx_pos cy_pos, refine ⟨_, this, _, convex_iff_div.1 hs hx hy cx_pos.le cy_pos.le this, _⟩, simp only [smul_add, smul_smul, mul_div_assoc', mul_div_cancel_left _ this.ne'] } end variables {s : set E} (hs : convex 𝕜 s) {x : E} lemma mem_to_cone : x ∈ hs.to_cone s ↔ ∃ (c : 𝕜), 0 < c ∧ ∃ y ∈ s, c • y = x := by simp only [to_cone, convex_cone.mem_mk, mem_Union, mem_smul_set, eq_comm, exists_prop] lemma mem_to_cone' : x ∈ hs.to_cone s ↔ ∃ (c : 𝕜), 0 < c ∧ c • x ∈ s := begin refine hs.mem_to_cone.trans ⟨_, _⟩, { rintros ⟨c, hc, y, hy, rfl⟩, exact ⟨c⁻¹, inv_pos.2 hc, by rwa [smul_smul, inv_mul_cancel hc.ne', one_smul]⟩ }, { rintros ⟨c, hc, hcx⟩, exact ⟨c⁻¹, inv_pos.2 hc, _, hcx, by rw [smul_smul, inv_mul_cancel hc.ne', one_smul]⟩ } end lemma subset_to_cone : s ⊆ hs.to_cone s := λ x hx, hs.mem_to_cone'.2 ⟨1, zero_lt_one, by rwa one_smul⟩ /-- `hs.to_cone s` is the least cone that includes `s`. -/ lemma to_cone_is_least : is_least { t : convex_cone 𝕜 E | s ⊆ t } (hs.to_cone s) := begin refine ⟨hs.subset_to_cone, λ t ht x hx, _⟩, rcases hs.mem_to_cone.1 hx with ⟨c, hc, y, hy, rfl⟩, exact t.smul_mem hc (ht hy) end lemma to_cone_eq_Inf : hs.to_cone s = Inf { t : convex_cone 𝕜 E | s ⊆ t } := hs.to_cone_is_least.is_glb.Inf_eq.symm end convex lemma convex_hull_to_cone_is_least (s : set E) : is_least {t : convex_cone 𝕜 E | s ⊆ t} ((convex_convex_hull 𝕜 s).to_cone _) := begin convert (convex_convex_hull 𝕜 s).to_cone_is_least, ext t, exact ⟨λ h, convex_hull_min h t.convex, (subset_convex_hull 𝕜 s).trans⟩, end lemma convex_hull_to_cone_eq_Inf (s : set E) : (convex_convex_hull 𝕜 s).to_cone _ = Inf {t : convex_cone 𝕜 E | s ⊆ t} := eq.symm $ is_glb.Inf_eq $ is_least.is_glb $ convex_hull_to_cone_is_least s end cone_from_convex /-! ### M. Riesz extension theorem Given a convex cone `s` in a vector space `E`, a submodule `p`, and a linear `f : p → ℝ`, assume that `f` is nonnegative on `p ∩ s` and `p + s = E`. Then there exists a globally defined linear function `g : E → ℝ` that agrees with `f` on `p`, and is nonnegative on `s`. We prove this theorem using Zorn's lemma. `riesz_extension.step` is the main part of the proof. It says that if the domain `p` of `f` is not the whole space, then `f` can be extended to a larger subspace `p ⊔ span ℝ {y}` without breaking the non-negativity condition. In `riesz_extension.exists_top` we use Zorn's lemma to prove that we can extend `f` to a linear map `g` on `⊤ : submodule E`. Mathematically this is the same as a linear map on `E` but in Lean `⊤ : submodule E` is isomorphic but is not equal to `E`. In `riesz_extension` we use this isomorphism to prove the theorem. -/ variables [add_comm_group E] [module ℝ E] namespace riesz_extension open submodule variables (s : convex_cone ℝ E) (f : E →ₗ.[ℝ] ℝ) /-- Induction step in M. Riesz extension theorem. Given a convex cone `s` in a vector space `E`, a partially defined linear map `f : f.domain → ℝ`, assume that `f` is nonnegative on `f.domain ∩ p` and `p + s = E`. If `f` is not defined on the whole `E`, then we can extend it to a larger submodule without breaking the non-negativity condition. -/ lemma step (nonneg : ∀ x : f.domain, (x : E) ∈ s → 0 ≤ f x) (dense : ∀ y, ∃ x : f.domain, (x : E) + y ∈ s) (hdom : f.domain ≠ ⊤) : ∃ g, f < g ∧ ∀ x : g.domain, (x : E) ∈ s → 0 ≤ g x := begin obtain ⟨y, -, hy⟩ : ∃ (y : E) (h : y ∈ ⊤), y ∉ f.domain, { exact @set_like.exists_of_lt (submodule ℝ E) _ _ _ _ (lt_top_iff_ne_top.2 hdom) }, obtain ⟨c, le_c, c_le⟩ : ∃ c, (∀ x : f.domain, -(x:E) - y ∈ s → f x ≤ c) ∧ (∀ x : f.domain, (x:E) + y ∈ s → c ≤ f x), { set Sp := f '' {x : f.domain | (x:E) + y ∈ s}, set Sn := f '' {x : f.domain | -(x:E) - y ∈ s}, suffices : (upper_bounds Sn ∩ lower_bounds Sp).nonempty, by simpa only [set.nonempty, upper_bounds, lower_bounds, ball_image_iff] using this, refine exists_between_of_forall_le (nonempty.image f _) (nonempty.image f (dense y)) _, { rcases (dense (-y)) with ⟨x, hx⟩, rw [← neg_neg x, add_subgroup_class.coe_neg, ← sub_eq_add_neg] at hx, exact ⟨_, hx⟩ }, rintros a ⟨xn, hxn, rfl⟩ b ⟨xp, hxp, rfl⟩, have := s.add_mem hxp hxn, rw [add_assoc, add_sub_cancel'_right, ← sub_eq_add_neg, ← add_subgroup_class.coe_sub] at this, replace := nonneg _ this, rwa [f.map_sub, sub_nonneg] at this }, have hy' : y ≠ 0, from λ hy₀, hy (hy₀.symm ▸ zero_mem _), refine ⟨f.sup_span_singleton y (-c) hy, _, _⟩, { refine lt_iff_le_not_le.2 ⟨f.left_le_sup _ _, λ H, _⟩, replace H := linear_pmap.domain_mono.monotone H, rw [linear_pmap.domain_sup_span_singleton, sup_le_iff, span_le, singleton_subset_iff] at H, exact hy H.2 }, { rintros ⟨z, hz⟩ hzs, rcases mem_sup.1 hz with ⟨x, hx, y', hy', rfl⟩, rcases mem_span_singleton.1 hy' with ⟨r, rfl⟩, simp only [subtype.coe_mk] at hzs, erw [linear_pmap.sup_span_singleton_apply_mk _ _ _ _ _ hx, smul_neg, ← sub_eq_add_neg, sub_nonneg], rcases lt_trichotomy r 0 with hr|hr|hr, { have : -(r⁻¹ • x) - y ∈ s, by rwa [← s.smul_mem_iff (neg_pos.2 hr), smul_sub, smul_neg, neg_smul, neg_neg, smul_smul, mul_inv_cancel hr.ne, one_smul, sub_eq_add_neg, neg_smul, neg_neg], replace := le_c (r⁻¹ • ⟨x, hx⟩) this, rwa [← mul_le_mul_left (neg_pos.2 hr), neg_mul, neg_mul, neg_le_neg_iff, f.map_smul, smul_eq_mul, ← mul_assoc, mul_inv_cancel hr.ne, one_mul] at this }, { subst r, simp only [zero_smul, add_zero] at hzs ⊢, apply nonneg, exact hzs }, { have : r⁻¹ • x + y ∈ s, by rwa [← s.smul_mem_iff hr, smul_add, smul_smul, mul_inv_cancel hr.ne', one_smul], replace := c_le (r⁻¹ • ⟨x, hx⟩) this, rwa [← mul_le_mul_left hr, f.map_smul, smul_eq_mul, ← mul_assoc, mul_inv_cancel hr.ne', one_mul] at this } } end theorem exists_top (p : E →ₗ.[ℝ] ℝ) (hp_nonneg : ∀ x : p.domain, (x : E) ∈ s → 0 ≤ p x) (hp_dense : ∀ y, ∃ x : p.domain, (x : E) + y ∈ s) : ∃ q ≥ p, q.domain = ⊤ ∧ ∀ x : q.domain, (x : E) ∈ s → 0 ≤ q x := begin replace hp_nonneg : p ∈ { p | _ }, by { rw mem_set_of_eq, exact hp_nonneg }, obtain ⟨q, hqs, hpq, hq⟩ := zorn_nonempty_partial_order₀ _ _ _ hp_nonneg, { refine ⟨q, hpq, _, hqs⟩, contrapose! hq, rcases step s q hqs _ hq with ⟨r, hqr, hr⟩, { exact ⟨r, hr, hqr.le, hqr.ne'⟩ }, { exact λ y, let ⟨x, hx⟩ := hp_dense y in ⟨of_le hpq.left x, hx⟩ } }, { intros c hcs c_chain y hy, clear hp_nonneg hp_dense p, have cne : c.nonempty := ⟨y, hy⟩, refine ⟨linear_pmap.Sup c c_chain.directed_on, _, λ _, linear_pmap.le_Sup c_chain.directed_on⟩, rintros ⟨x, hx⟩ hxs, have hdir : directed_on (≤) (linear_pmap.domain '' c), from directed_on_image.2 (c_chain.directed_on.mono linear_pmap.domain_mono.monotone), rcases (mem_Sup_of_directed (cne.image _) hdir).1 hx with ⟨_, ⟨f, hfc, rfl⟩, hfx⟩, have : f ≤ linear_pmap.Sup c c_chain.directed_on, from linear_pmap.le_Sup _ hfc, convert ← hcs hfc ⟨x, hfx⟩ hxs, apply this.2, refl } end end riesz_extension /-- M. **Riesz extension theorem**: given a convex cone `s` in a vector space `E`, a submodule `p`, and a linear `f : p → ℝ`, assume that `f` is nonnegative on `p ∩ s` and `p + s = E`. Then there exists a globally defined linear function `g : E → ℝ` that agrees with `f` on `p`, and is nonnegative on `s`. -/ theorem riesz_extension (s : convex_cone ℝ E) (f : E →ₗ.[ℝ] ℝ) (nonneg : ∀ x : f.domain, (x : E) ∈ s → 0 ≤ f x) (dense : ∀ y, ∃ x : f.domain, (x : E) + y ∈ s) : ∃ g : E →ₗ[ℝ] ℝ, (∀ x : f.domain, g x = f x) ∧ (∀ x ∈ s, 0 ≤ g x) := begin rcases riesz_extension.exists_top s f nonneg dense with ⟨⟨g_dom, g⟩, ⟨hpg, hfg⟩, htop, hgs⟩, clear hpg, refine ⟨g ∘ₗ ↑(linear_equiv.of_top _ htop).symm, _, _⟩; simp only [comp_apply, linear_equiv.coe_coe, linear_equiv.of_top_symm_apply], { exact λ x, (hfg (submodule.coe_mk _ _).symm).symm }, { exact λ x hx, hgs ⟨x, _⟩ hx } end /-- **Hahn-Banach theorem**: if `N : E → ℝ` is a sublinear map, `f` is a linear map defined on a subspace of `E`, and `f x ≤ N x` for all `x` in the domain of `f`, then `f` can be extended to the whole space to a linear map `g` such that `g x ≤ N x` for all `x`. -/ theorem exists_extension_of_le_sublinear (f : E →ₗ.[ℝ] ℝ) (N : E → ℝ) (N_hom : ∀ (c : ℝ), 0 < c → ∀ x, N (c • x) = c * N x) (N_add : ∀ x y, N (x + y) ≤ N x + N y) (hf : ∀ x : f.domain, f x ≤ N x) : ∃ g : E →ₗ[ℝ] ℝ, (∀ x : f.domain, g x = f x) ∧ (∀ x, g x ≤ N x) := begin let s : convex_cone ℝ (E × ℝ) := { carrier := {p : E × ℝ | N p.1 ≤ p.2 }, smul_mem' := λ c hc p hp, calc N (c • p.1) = c * N p.1 : N_hom c hc p.1 ... ≤ c * p.2 : mul_le_mul_of_nonneg_left hp hc.le, add_mem' := λ x hx y hy, (N_add _ _).trans (add_le_add hx hy) }, obtain ⟨g, g_eq, g_nonneg⟩ := riesz_extension s ((-f).coprod (linear_map.id.to_pmap ⊤)) _ _; try { simp only [linear_pmap.coprod_apply, to_pmap_apply, id_apply, linear_pmap.neg_apply, ← sub_eq_neg_add, sub_nonneg, subtype.coe_mk] at * }, replace g_eq : ∀ (x : f.domain) (y : ℝ), g (x, y) = y - f x, { intros x y, simpa only [subtype.coe_mk, subtype.coe_eta] using g_eq ⟨(x, y), ⟨x.2, trivial⟩⟩ }, { refine ⟨-g.comp (inl ℝ E ℝ), _, _⟩; simp only [neg_apply, inl_apply, comp_apply], { intro x, simp [g_eq x 0] }, { intro x, have A : (x, N x) = (x, 0) + (0, N x), by simp, have B := g_nonneg ⟨x, N x⟩ (le_refl (N x)), rw [A, map_add, ← neg_le_iff_add_nonneg'] at B, have C := g_eq 0 (N x), simp only [submodule.coe_zero, f.map_zero, sub_zero] at C, rwa ← C } }, { exact λ x hx, le_trans (hf _) hx }, { rintros ⟨x, y⟩, refine ⟨⟨(0, N x - y), ⟨f.domain.zero_mem, trivial⟩⟩, _⟩, simp only [convex_cone.mem_mk, mem_set_of_eq, subtype.coe_mk, prod.fst_add, prod.snd_add, zero_add, sub_add_cancel] } end /-! ### The dual cone -/ section dual variables {H : Type*} [inner_product_space ℝ H] (s t : set H) open_locale real_inner_product_space /-- The dual cone is the cone consisting of all points `y` such that for all points `x` in a given set `0 ≤ ⟪ x, y ⟫`. -/ def set.inner_dual_cone (s : set H) : convex_cone ℝ H := { carrier := { y | ∀ x ∈ s, 0 ≤ ⟪ x, y ⟫ }, smul_mem' := λ c hc y hy x hx, begin rw real_inner_smul_right, exact mul_nonneg hc.le (hy x hx) end, add_mem' := λ u hu v hv x hx, begin rw inner_add_right, exact add_nonneg (hu x hx) (hv x hx) end } @[simp] lemma mem_inner_dual_cone (y : H) (s : set H) : y ∈ s.inner_dual_cone ↔ ∀ x ∈ s, 0 ≤ ⟪ x, y ⟫ := iff.rfl @[simp] lemma inner_dual_cone_empty : (∅ : set H).inner_dual_cone = ⊤ := eq_top_iff.mpr $ λ x hy y, false.elim /-- Dual cone of the convex cone {0} is the total space. -/ @[simp] lemma inner_dual_cone_zero : (0 : set H).inner_dual_cone = ⊤ := eq_top_iff.mpr $ λ x hy y (hy : y = 0), hy.symm ▸ inner_zero_left.ge /-- Dual cone of the total space is the convex cone {0}. -/ @[simp] lemma inner_dual_cone_univ : (univ : set H).inner_dual_cone = 0 := begin suffices : ∀ x : H, x ∈ (univ : set H).inner_dual_cone → x = 0, { apply set_like.coe_injective, exact eq_singleton_iff_unique_mem.mpr ⟨λ x hx, inner_zero_right.ge, this⟩ }, exact λ x hx, by simpa [←real_inner_self_nonpos] using hx (-x) (mem_univ _), end lemma inner_dual_cone_le_inner_dual_cone (h : t ⊆ s) : s.inner_dual_cone ≤ t.inner_dual_cone := λ y hy x hx, hy x (h hx) lemma pointed_inner_dual_cone : s.inner_dual_cone.pointed := λ x hx, by rw inner_zero_right /-- The inner dual cone of a singleton is given by the preimage of the positive cone under the linear map `λ y, ⟪x, y⟫`. -/ lemma inner_dual_cone_singleton (x : H) : ({x} : set H).inner_dual_cone = (convex_cone.positive ℝ ℝ).comap (innerₛₗ x) := convex_cone.ext $ λ i, forall_eq lemma inner_dual_cone_union (s t : set H) : (s ∪ t).inner_dual_cone = s.inner_dual_cone ⊓ t.inner_dual_cone := le_antisymm (le_inf (λ x hx y hy, hx _ $ or.inl hy) (λ x hx y hy, hx _ $ or.inr hy)) (λ x hx y, or.rec (hx.1 _) (hx.2 _)) lemma inner_dual_cone_insert (x : H) (s : set H) : (insert x s).inner_dual_cone = set.inner_dual_cone {x} ⊓ s.inner_dual_cone := by rw [insert_eq, inner_dual_cone_union] lemma inner_dual_cone_Union {ι : Sort*} (f : ι → set H) : (⋃ i, f i).inner_dual_cone = ⨅ i, (f i).inner_dual_cone := begin refine le_antisymm (le_infi $ λ i x hx y hy, hx _ $ mem_Union_of_mem _ hy) _, intros x hx y hy, rw [convex_cone.mem_infi] at hx, obtain ⟨j, hj⟩ := mem_Union.mp hy, exact hx _ _ hj, end lemma inner_dual_cone_sUnion (S : set (set H)) : (⋃₀ S).inner_dual_cone = Inf (set.inner_dual_cone '' S) := by simp_rw [Inf_image, sUnion_eq_bUnion, inner_dual_cone_Union] /-- The dual cone of `s` equals the intersection of dual cones of the points in `s`. -/ lemma inner_dual_cone_eq_Inter_inner_dual_cone_singleton : (s.inner_dual_cone : set H) = ⋂ i : s, (({i} : set H).inner_dual_cone : set H) := by rw [←convex_cone.coe_infi, ←inner_dual_cone_Union, Union_of_singleton_coe] lemma is_closed_inner_dual_cone : is_closed (s.inner_dual_cone : set H) := begin -- reduce the problem to showing that dual cone of a singleton `{x}` is closed rw inner_dual_cone_eq_Inter_inner_dual_cone_singleton, apply is_closed_Inter, intros x, -- the dual cone of a singleton `{x}` is the preimage of `[0, ∞)` under `inner x` have h : ↑({x} : set H).inner_dual_cone = (inner x : H → ℝ) ⁻¹' set.Ici 0, { rw [inner_dual_cone_singleton, convex_cone.coe_comap, convex_cone.coe_positive, innerₛₗ_apply_coe] }, -- the preimage is closed as `inner x` is continuous and `[0, ∞)` is closed rw h, exact is_closed_Ici.preimage (by continuity), end lemma convex_cone.pointed_of_nonempty_of_is_closed (K : convex_cone ℝ H) (ne : (K : set H).nonempty) (hc : is_closed (K : set H)) : K.pointed := begin obtain ⟨x, hx⟩ := ne, let f : ℝ → H := (• x), -- f (0, ∞) is a subset of K have fI : f '' set.Ioi 0 ⊆ (K : set H), { rintro _ ⟨_, h, rfl⟩, exact K.smul_mem (set.mem_Ioi.1 h) hx }, -- closure of f (0, ∞) is a subset of K have clf : closure (f '' set.Ioi 0) ⊆ (K : set H) := hc.closure_subset_iff.2 fI, -- f is continuous at 0 from the right have fc : continuous_within_at f (set.Ioi (0 : ℝ)) 0 := (continuous_id.smul continuous_const).continuous_within_at, -- 0 belongs to the closure of the f (0, ∞) have mem₀ := fc.mem_closure_image (by rw [closure_Ioi (0 : ℝ), mem_Ici]), -- as 0 ∈ closure f (0, ∞) and closure f (0, ∞) ⊆ K, 0 ∈ K. have f₀ : f 0 = 0 := zero_smul ℝ x, simpa only [f₀, convex_cone.pointed, ← set_like.mem_coe] using mem_of_subset_of_mem clf mem₀, end section complete_space variables [complete_space H] /-- This is a stronger version of the Hahn-Banach separation theorem for closed convex cones. This is also the geometric interpretation of Farkas' lemma. -/ theorem convex_cone.hyperplane_separation_of_nonempty_of_is_closed_of_nmem (K : convex_cone ℝ H) (ne : (K : set H).nonempty) (hc : is_closed (K : set H)) {b : H} (disj : b ∉ K) : ∃ (y : H), (∀ x : H, x ∈ K → 0 ≤ ⟪x, y⟫_ℝ) ∧ ⟪y, b⟫_ℝ < 0 := begin -- let `z` be the point in `K` closest to `b` obtain ⟨z, hzK, infi⟩ := exists_norm_eq_infi_of_complete_convex ne hc.is_complete K.convex b, -- for any `w` in `K`, we have `⟪b - z, w - z⟫_ℝ ≤ 0` have hinner := (norm_eq_infi_iff_real_inner_le_zero K.convex hzK).1 infi, -- set `y := z - b` use z - b, split, { -- the rest of the proof is a straightforward calculation rintros x hxK, specialize hinner _ (K.add_mem hxK hzK), rwa [add_sub_cancel, real_inner_comm, ← neg_nonneg, neg_eq_neg_one_mul, ← real_inner_smul_right, neg_smul, one_smul, neg_sub] at hinner }, { -- as `K` is closed and non-empty, it is pointed have hinner₀ := hinner 0 (K.pointed_of_nonempty_of_is_closed ne hc), -- the rest of the proof is a straightforward calculation rw [zero_sub, inner_neg_right, right.neg_nonpos_iff] at hinner₀, have hbz : b - z ≠ 0 := by { rw sub_ne_zero, contrapose! hzK, rwa ← hzK }, rw [← neg_zero, lt_neg, ← neg_one_mul, ← real_inner_smul_left, smul_sub, neg_smul, one_smul, neg_smul, neg_sub_neg, one_smul], calc 0 < ⟪b - z, b - z⟫_ℝ : lt_of_not_le ((iff.not real_inner_self_nonpos).2 hbz) ... = ⟪b - z, b - z⟫_ℝ + 0 : (add_zero _).symm ... ≤ ⟪b - z, b - z⟫_ℝ + ⟪b - z, z⟫_ℝ : add_le_add rfl.ge hinner₀ ... = ⟪b - z, b - z + z⟫_ℝ : inner_add_right.symm ... = ⟪b - z, b⟫_ℝ : by rw sub_add_cancel }, end /-- The inner dual of inner dual of a non-empty, closed convex cone is itself. -/ theorem convex_cone.inner_dual_cone_of_inner_dual_cone_eq_self (K : convex_cone ℝ H) (ne : (K : set H).nonempty) (hc : is_closed (K : set H)) : ((K : set H).inner_dual_cone : set H).inner_dual_cone = K := begin ext x, split, { rw [mem_inner_dual_cone, ← set_like.mem_coe], contrapose!, exact K.hyperplane_separation_of_nonempty_of_is_closed_of_nmem ne hc }, { rintro hxK y h, specialize h x hxK, rwa real_inner_comm }, end end complete_space end dual
a379476f2d71c350a5880b1d83cedf2f35794adc
a4673261e60b025e2c8c825dfa4ab9108246c32e
/src/Lean/Data/Lsp.lean
b33f8bfce339d85041698413969361eab3a039da
[ "Apache-2.0" ]
permissive
jcommelin/lean4
c02dec0cc32c4bccab009285475f265f17d73228
2909313475588cc20ac0436e55548a4502050d0a
refs/heads/master
1,674,129,550,893
1,606,415,348,000
1,606,415,348,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
450
lean
/- Copyright (c) 2020 Marc Huisinga. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Marc Huisinga, Wojciech Nawrocki -/ import Lean.Data.Lsp.Basic import Lean.Data.Lsp.Capabilities import Lean.Data.Lsp.Communication import Lean.Data.Lsp.Diagnostics import Lean.Data.Lsp.Hover import Lean.Data.Lsp.InitShutdown import Lean.Data.Lsp.TextSync import Lean.Data.Lsp.Utf16 import Lean.Data.Lsp.Workspace
70e393bb669b895bf46b988588ae13eba0412554
e151e9053bfd6d71740066474fc500a087837323
/src/hott/types/nat/div.lean
b74ca09c9bd23540f2d8a52f6974e48cca82b1da
[ "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
26,655
lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura Definitions prod properties of div prod mod. Much of the development follows Isabelle's library. -/ #exit import .sub universes u v w hott_theory namespace hott open hott.algebra -- open well_founded decidable prod algebra namespace nat /- div -/ -- auxiliary lemma used to justify div private @[hott] def div_rec_lemma {x y : nat} : 0 < y × y ≤ x → x - y < x := prod.rec (λ ypos ylex, sub_lt (lt_of_lt_of_le ypos ylex) ypos) private @[hott] def div.F (x : nat) (f : Π x₁, x₁ < x → nat → nat) (y : nat) : nat := if H : 0 < y × y ≤ x then f (x - y) (div_rec_lemma H) y + 1 else zero @[hott] protected def div := fix div.F @[hott] def nat_has_divide [reducible] [instance] [priority nat.prio] : has_div nat := has_div.mk nat.div @[hott] theorem div_def (x y : nat) : div x y = if 0 < y × y ≤ x then div (x - y) y + 1 else 0 := congr_fun (fix_eq div.F x) y @[hott] protected theorem div_zero [simp] (a : ℕ) : a / 0 = 0 := div_def a 0 ⬝ if_neg (!not_prod_of_not_left (lt.irrefl 0)) @[hott] theorem div_eq_zero_of_lt {a b : ℕ} (h : a < b) : a / b = 0 := div_def a b ⬝ if_neg (!not_prod_of_not_right (not_le_of_gt h)) @[hott] protected theorem zero_div [simp] (b : ℕ) : 0 / b = 0 := div_def 0 b ⬝ if_neg (prod.rec not_le_of_gt) @[hott] theorem div_eq_succ_sub_div {a b : ℕ} (h₁ : b > 0) (h₂ : a ≥ b) : a / b = succ ((a - b) / b) := div_def a b ⬝ if_pos (pair h₁ h₂) @[hott] theorem add_div_self (x : ℕ) {z : ℕ} (H : z > 0) : (x + z) / z = succ (x / z) := calc (x + z) / z = if 0 < z × z ≤ x + z then (x + z - z) / z + 1 else 0 : !div_def ... = (x + z - z) / z + 1 : if_pos (pair H (le_add_left z x)) ... = succ (x / z) : {!nat.add_sub_cancel} @[hott] theorem add_div_self_left {x : ℕ} (z : ℕ) (H : x > 0) : (x + z) / x = succ (z / x) := by rewrite add.comm; exact !add_div_self H local attribute succ_mul [simp] @[hott] theorem add_mul_div_self {x y z : ℕ} (H : z > 0) : (x + y * z) / z = x / z + y := nat.rec_on y (by rewrite [zero_mul]) (take y, assume IH : (x + y * z) / z = x / z + y, calc (x + succ y * z) / z = (x + y * z + z) / z : by rewrite [succ_mul, add.assoc] ... = succ ((x + y * z) / z) : !add_div_self H ... = succ (x / z + y) : IH) @[hott] theorem add_mul_div_self_left (x z : ℕ) {y : ℕ} (H : y > 0) : (x + y * z) / y = x / y + z := !mul.comm ▸ add_mul_div_self H @[hott] protected theorem mul_div_cancel (m : ℕ) {n : ℕ} (H : n > 0) : m * n / n = m := calc m * n / n = (0 + m * n) / n : by rewrite [zero_add] ... = 0 / n + m : add_mul_div_self H ... = m : by rewrite [nat.zero_div, zero_add] @[hott] protected theorem mul_div_cancel_left {m : ℕ} (n : ℕ) (H : m > 0) : m * n / m = n := !mul.comm ▸ !nat.mul_div_cancel H /- mod -/ private @[hott] def mod.F (x : nat) (f : Π x₁, x₁ < x → nat → nat) (y : nat) : nat := if H : 0 < y × y ≤ x then f (x - y) (div_rec_@[hott] lemma H) y else x @[hott] protected def mod := fix mod.F @[hott] def nat_has_mod [reducible] [instance] [priority nat.prio] : has_mod nat := has_mod.mk nat.mod notation [priority nat.prio] a ≡ b `[mod `:0 c:0 `]` := a % c = b % c @[hott] theorem mod_def (x y : nat) : mod x y = if 0 < y × y ≤ x then mod (x - y) y else x := congr_fun (fix_eq mod.F x) y @[hott] theorem mod_zero [simp] (a : ℕ) : a % 0 = a := mod_def a 0 ⬝ if_neg (!not_prod_of_not_left (lt.irrefl 0)) @[hott] theorem mod_eq_of_lt {a b : ℕ} (h : a < b) : a % b = a := mod_def a b ⬝ if_neg (!not_prod_of_not_right (not_le_of_gt h)) @[hott] theorem zero_mod [simp] (b : ℕ) : 0 % b = 0 := mod_def 0 b ⬝ if_neg (λ h, prod.rec_on h (λ l r, absurd (lt_of_lt_of_le l r) (lt.irrefl 0))) @[hott] theorem mod_eq_sub_mod {a b : ℕ} (h₁ : b > 0) (h₂ : a ≥ b) : a % b = (a - b) % b := mod_def a b ⬝ if_pos (pair h₁ h₂) @[hott] theorem add_mod_self [simp] (x z : ℕ) : (x + z) % z = x % z := by_cases_zero_pos z (by rewrite add_zero) (take z, assume H : z > 0, calc (x + z) % z = if 0 < z × z ≤ x + z then (x + z - z) % z else _ : mod_def ... = (x + z - z) % z : if_pos (pair H (le_add_left z x)) ... = x % z : nat.add_sub_cancel) @[hott] theorem add_mod_self_left [simp] (x z : ℕ) : (x + z) % x = z % x := by rewrite add.comm; apply add_mod_self local attribute succ_mul [simp] @[hott] theorem add_mul_mod_self [simp] (x y z : ℕ) : (x + y * z) % z = x % z := nat.rec_on y (by rewrite [zero_mul, add_zero]) (by intros y IH; rewrite [succ_mul, -add.assoc, add_mod_self, IH]) @[hott] theorem add_mul_mod_self_left [simp] (x y z : ℕ) : (x + y * z) % y = x % y := by rewrite [mul.comm, add_mul_mod_self] @[hott] theorem mul_mod_left [simp] (m n : ℕ) : (m * n) % n = 0 := calc (m * n) % n = (0 + m * n) % n : by rewrite [zero_add] ... = 0 : by rewrite [add_mul_mod_self, zero_mod] @[hott] theorem mul_mod_right [simp] (m n : ℕ) : (m * n) % m = 0 := by rewrite [mul.comm, mul_mod_left] @[hott] theorem mod_lt (x : ℕ) {y : ℕ} (H : y > 0) : x % y < y := nat.case_strong_rec_on x (show 0 % y < y, from !zero_mod⁻¹ ▸ H) (take x, assume IH : Πx', x' ≤ x → x' % y < y, show succ x % y < y, from by_cases -- (succ x < y) (assume H1 : succ x < y, have succ x % y = succ x, from mod_eq_of_lt H1, show succ x % y < y, from this⁻¹ ▸ H1) (assume H1 : ¬ succ x < y, have y ≤ succ x, from le_of_not_gt H1, have h : succ x % y = (succ x - y) % y, from mod_eq_sub_mod H this, have succ x - y < succ x, from sub_lt !succ_pos H, have succ x - y ≤ x, from le_of_lt_succ this, show succ x % y < y, from h⁻¹ ▸ IH _ this)) @[hott] theorem mod_one (n : ℕ) : n % 1 = 0 := have H1 : n % 1 < 1, from !mod_lt !succ_pos, eq_zero_of_le_zero (le_of_lt_succ H1) /- properties of div prod mod -/ -- the quotient - remainder theorem @[hott] theorem eq_div_mul_add_mod (x y : ℕ) : x = x / y * y + x % y := begin eapply by_cases_zero_pos y, show x = x / 0 * 0 + x % 0, from (calc x / 0 * 0 + x % 0 = 0 + x % 0 : mul_zero ... = x % 0 : zero_add ... = x : mod_zero)⁻¹, intros y H, show x = x / y * y + x % y, begin eapply nat.case_strong_rec_on x, show 0 = (0 / y) * y + 0 % y, by rewrite [zero_mod, add_zero, nat.zero_div, zero_mul], intros x IH, show succ x = succ x / y * y + succ x % y, from if H1 : succ x < y then have H2 : succ x / y = 0, from div_eq_zero_of_lt H1, have H3 : succ x % y = succ x, from mod_eq_of_lt H1, begin rewrite [H2, H3, zero_mul, zero_add] end else have H2 : y ≤ succ x, from le_of_not_gt H1, have H3 : succ x / y = succ ((succ x - y) / y), from div_eq_succ_sub_div H H2, have H4 : succ x % y = (succ x - y) % y, from mod_eq_sub_mod H H2, have H5 : succ x - y < succ x, from sub_lt !succ_pos H, have H6 : succ x - y ≤ x, from le_of_lt_succ H5, (calc succ x / y * y + succ x % y = succ ((succ x - y) / y) * y + succ x % y : by rewrite H3 ... = ((succ x - y) / y) * y + y + succ x % y : by rewrite succ_mul ... = ((succ x - y) / y) * y + y + (succ x - y) % y : by rewrite H4 ... = ((succ x - y) / y) * y + (succ x - y) % y + y : add.right_comm ... = succ x - y + y : by rewrite -(IH _ H6) ... = succ x : nat.sub_add_cancel H2)⁻¹ end end @[hott] theorem mod_eq_sub_div_mul (x y : ℕ) : x % y = x - x / y * y := nat.eq_sub_of_add_eq (!add.comm ▸ !eq_div_mul_add_mod)⁻¹ @[hott] theorem mod_add_mod (m n k : ℕ) : (m % n + k) % n = (m + k) % n := by rewrite [eq_div_mul_add_mod m n at {2}, add.assoc, add.comm (m / n * n), add_mul_mod_self] @[hott] theorem add_mod_mod (m n k : ℕ) : (m + n % k) % k = (m + n) % k := by rewrite [add.comm, mod_add_mod, add.comm] @[hott] theorem add_mod_eq_add_mod_right {m n k : ℕ} (i : ℕ) (H : m % n = k % n) : (m + i) % n = (k + i) % n := by rewrite [-mod_add_mod, -mod_add_mod k, H] @[hott] theorem add_mod_eq_add_mod_left {m n k : ℕ} (i : ℕ) (H : m % n = k % n) : (i + m) % n = (i + k) % n := by rewrite [add.comm, add_mod_eq_add_mod_right _ H, add.comm] @[hott] theorem mod_eq_mod_of_add_mod_eq_add_mod_right {m n k i : ℕ} : (m + i) % n = (k + i) % n → m % n = k % n := by_cases_zero_pos n (by rewrite [*mod_zero]; apply eq_of_add_eq_add_right) (take n, assume npos : n > 0, assume H1 : (m + i) % n = (k + i) % n, have H2 : (m + i % n) % n = (k + i % n) % n, by rewrite [*add_mod_mod, H1], have H3 : (m + i % n + (n - i % n)) % n = (k + i % n + (n - i % n)) % n, from add_mod_eq_add_mod_right _ H2, begin revert H3, rewrite [*add.assoc, add_sub_of_le (le_of_lt (!mod_lt npos)), *add_mod_self], intros, assumption end) @[hott] theorem mod_eq_mod_of_add_mod_eq_add_mod_left {m n k i : ℕ} : (i + m) % n = (i + k) % n → m % n = k % n := by rewrite [add.comm i m, add.comm i k]; apply mod_eq_mod_of_add_mod_eq_add_mod_right @[hott] theorem mod_le {x y : ℕ} : x % y ≤ x := !eq_div_mul_add_mod⁻¹ ▸ !le_add_left @[hott] theorem eq_remainder {q1 r1 q2 r2 y : ℕ} (H1 : r1 < y) (H2 : r2 < y) (H3 : q1 * y + r1 = q2 * y + r2) : r1 = r2 := calc r1 = r1 % y : mod_eq_of_lt H1 ... = (r1 + q1 * y) % y : !add_mul_mod_self⁻¹ ... = (q1 * y + r1) % y : add.comm ... = (r2 + q2 * y) % y : by rewrite [H3, add.comm] ... = r2 % y : !add_mul_mod_self ... = r2 : mod_eq_of_lt H2 @[hott] theorem eq_quotient {q1 r1 q2 r2 y : ℕ} (H1 : r1 < y) (H2 : r2 < y) (H3 : q1 * y + r1 = q2 * y + r2) : q1 = q2 := have H4 : q1 * y + r2 = q2 * y + r2, from (eq_remainder H1 H2 H3) ▸ H3, have H5 : q1 * y = q2 * y, from add.right_cancel H4, have H6 : y > 0, from lt_of_le_of_lt !zero_le H1, show q1 = q2, from eq_of_mul_eq_mul_right H6 H5 @[hott] protected theorem mul_div_mul_left {z : ℕ} (x y : ℕ) (zpos : z > 0) : (z * x) / (z * y) = x / y := if H : y = 0 then by rewrite [H, mul_zero, *nat.div_zero] else have ypos : y > 0, from pos_of_ne_zero H, have zypos : z * y > 0, from mul_pos zpos ypos, have H1 : (z * x) % (z * y) < z * y, from !mod_lt zypos, have H2 : z * (x % y) < z * y, from mul_lt_mul_of_pos_left (!mod_lt ypos) zpos, eq_quotient H1 H2 (calc ((z * x) / (z * y)) * (z * y) + (z * x) % (z * y) = z * x : eq_div_mul_add_mod ... = z * (x / y * y + x % y) : eq_div_mul_add_mod ... = z * (x / y * y) + z * (x % y) : left_distrib ... = (x / y) * (z * y) + z * (x % y) : mul.left_comm) @[hott] protected theorem mul_div_mul_right {x z y : ℕ} (zpos : z > 0) : (x * z) / (y * z) = x / y := !mul.comm ▸ !mul.comm ▸ !nat.mul_div_mul_left zpos @[hott] theorem mul_mod_mul_left (z x y : ℕ) : (z * x) % (z * y) = z * (x % y) := sum.elim (eq_zero_sum_pos z) (assume H : z = 0, H⁻¹ ▸ calc (0 * x) % (z * y) = 0 % (z * y) : zero_mul ... = 0 : zero_mod ... = 0 * (x % y) : zero_mul) (assume zpos : z > 0, sum.elim (eq_zero_sum_pos y) (assume H : y = 0, by rewrite [H, mul_zero, *mod_zero]) (assume ypos : y > 0, have zypos : z * y > 0, from mul_pos zpos ypos, have H1 : (z * x) % (z * y) < z * y, from !mod_lt zypos, have H2 : z * (x % y) < z * y, from mul_lt_mul_of_pos_left (!mod_lt ypos) zpos, eq_remainder H1 H2 (calc ((z * x) / (z * y)) * (z * y) + (z * x) % (z * y) = z * x : eq_div_mul_add_mod ... = z * (x / y * y + x % y) : eq_div_mul_add_mod ... = z * (x / y * y) + z * (x % y) : left_distrib ... = (x / y) * (z * y) + z * (x % y) : mul.left_comm))) @[hott] theorem mul_mod_mul_right (x z y : ℕ) : (x * z) % (y * z) = (x % y) * z := mul.comm z x ▸ mul.comm z y ▸ !mul.comm ▸ !mul_mod_mul_left @[hott] theorem mod_self (n : ℕ) : n % n = 0 := nat.cases_on n (by rewrite zero_mod) (take n, by rewrite [-zero_add (succ n) at {1}, add_mod_self]) @[hott] theorem mul_mod_eq_mod_mul_mod (m n k : nat) : (m * n) % k = ((m % k) * n) % k := calc (m * n) % k = (((m / k) * k + m % k) * n) % k : eq_div_mul_add_mod ... = ((m % k) * n) % k : by rewrite [right_distrib, mul.right_comm, add.comm, add_mul_mod_self] @[hott] theorem mul_mod_eq_mul_mod_mod (m n k : nat) : (m * n) % k = (m * (n % k)) % k := !mul.comm ▸ !mul.comm ▸ !mul_mod_eq_mod_mul_mod @[hott] protected theorem div_one (n : ℕ) : n / 1 = n := have n / 1 * 1 + n % 1 = n, from !eq_div_mul_add_mod⁻¹, begin rewrite [-this at {2}, mul_one, mod_one] end @[hott] protected theorem div_self {n : ℕ} (H : n > 0) : n / n = 1 := have (n * 1) / (n * 1) = 1 / 1, from !nat.mul_div_mul_left H, by rewrite [nat.div_one at this, -this, *mul_one] @[hott] theorem div_mul_cancel_of_mod_eq_zero {m n : ℕ} (H : m % n = 0) : m / n * n = m := by rewrite [eq_div_mul_add_mod m n at {2}, H, add_zero] @[hott] theorem mul_div_cancel_of_mod_eq_zero {m n : ℕ} (H : m % n = 0) : n * (m / n) = m := !mul.comm ▸ div_mul_cancel_of_mod_eq_zero H /- dvd -/ @[hott] theorem dvd_of_mod_eq_zero {m n : ℕ} (H : n % m = 0) : m ∣ n := dvd.intro (!mul.comm ▸ div_mul_cancel_of_mod_eq_zero H) @[hott] theorem mod_eq_zero_of_dvd {m n : ℕ} (H : m ∣ n) : n % m = 0 := dvd.elim H (take z, assume H1 : n = m * z, H1⁻¹ ▸ !mul_mod_right) @[hott] theorem dvd_iff_mod_eq_zero (m n : ℕ) : m ∣ n ↔ n % m = 0 := iff.intro mod_eq_zero_of_dvd dvd_of_mod_eq_zero @[hott] def dvd.decidable_rel [instance] : decidable_rel dvd := take m n, decidable_of_decidable_of_iff _ (iff.symm !dvd_iff_mod_eq_zero) @[hott] protected theorem div_mul_cancel {m n : ℕ} (H : n ∣ m) : m / n * n = m := div_mul_cancel_of_mod_eq_zero (mod_eq_zero_of_dvd H) @[hott] protected theorem mul_div_cancel' {m n : ℕ} (H : n ∣ m) : n * (m / n) = m := !mul.comm ▸ nat.div_mul_cancel H @[hott] theorem dvd_of_dvd_add_left {m n₁ n₂ : ℕ} (H₁ : m ∣ n₁ + n₂) (H₂ : m ∣ n₁) : m ∣ n₂ := obtain (c₁ : nat) (Hc₁ : n₁ + n₂ = m * c₁), from H₁, obtain (c₂ : nat) (Hc₂ : n₁ = m * c₂), from H₂, have aux : m * (c₁ - c₂) = n₂, from calc m * (c₁ - c₂) = m * c₁ - m * c₂ : nat.mul_sub_left_distrib ... = n₁ + n₂ - m * c₂ : Hc₁ ... = n₁ + n₂ - n₁ : Hc₂ ... = n₂ : nat.add_sub_cancel_left, dvd.intro aux @[hott] theorem dvd_of_dvd_add_right {m n₁ n₂ : ℕ} (H : m ∣ n₁ + n₂) : m ∣ n₂ → m ∣ n₁ := nat.dvd_of_dvd_add_left (!add.comm ▸ H) @[hott] theorem dvd_sub {m n₁ n₂ : ℕ} (H1 : m ∣ n₁) (H2 : m ∣ n₂) : m ∣ n₁ - n₂ := by_cases (assume H3 : n₁ ≥ n₂, have H4 : n₁ = n₁ - n₂ + n₂, from (nat.sub_add_cancel H3)⁻¹, show m ∣ n₁ - n₂, from nat.dvd_of_dvd_add_right (H4 ▸ H1) H2) (assume H3 : ¬ (n₁ ≥ n₂), have H4 : n₁ - n₂ = 0, from sub_eq_zero_of_le (le_of_lt (lt_of_not_ge H3)), show m ∣ n₁ - n₂, from H4⁻¹ ▸ dvd_zero _) @[hott] theorem dvd.antisymm {m n : ℕ} : m ∣ n → n ∣ m → m = n := by_cases_zero_pos n (assume H1, assume H2 : 0 ∣ m, eq_zero_of_zero_dvd H2) (take n, assume Hpos : n > 0, assume H1 : m ∣ n, assume H2 : n ∣ m, obtain k (Hk : n = m * k), from exists_eq_mul_right_of_dvd H1, obtain l (Hl : m = n * l), from exists_eq_mul_right_of_dvd H2, have n * (l * k) = n, from !mul.assoc ▸ Hl ▸ Hk⁻¹, have l * k = 1, from eq_one_of_mul_eq_self_right Hpos this, have k = 1, from eq_one_of_mul_eq_one_left this, show m = n, from (mul_one m)⁻¹ ⬝ (this ▸ Hk⁻¹)) @[hott] protected theorem mul_div_assoc (m : ℕ) {n k : ℕ} (H : k ∣ n) : m * n / k = m * (n / k) := sum.elim (eq_zero_sum_pos k) (assume H1 : k = 0, calc m * n / k = m * n / 0 : H1 ... = 0 : nat.div_zero ... = m * 0 : mul_zero m ... = m * (n / 0) : nat.div_zero ... = m * (n / k) : H1) (assume H1 : k > 0, have H2 : n = n / k * k, from (nat.div_mul_cancel H)⁻¹, calc m * n / k = m * (n / k * k) / k : H2 ... = m * (n / k) * k / k : mul.assoc ... = m * (n / k) : nat.mul_div_cancel _ H1) @[hott] theorem dvd_of_mul_dvd_mul_left {m n k : ℕ} (kpos : k > 0) (H : k * m ∣ k * n) : m ∣ n := dvd.elim H (take l, assume H1 : k * n = k * m * l, have H2 : n = m * l, from eq_of_mul_eq_mul_left kpos (H1 ⬝ !mul.assoc), dvd.intro H2⁻¹) @[hott] theorem dvd_of_mul_dvd_mul_right {m n k : ℕ} (kpos : k > 0) (H : m * k ∣ n * k) : m ∣ n := nat.dvd_of_mul_dvd_mul_left kpos (!mul.comm ▸ !mul.comm ▸ H) @[hott] lemma dvd_of_eq_mul (i j n : nat) : n = j*i → j ∣ n := begin intros, subst n, apply dvd_mul_right end @[hott] theorem div_dvd_div {k m n : ℕ} (H1 : k ∣ m) (H2 : m ∣ n) : m / k ∣ n / k := have H3 : m = m / k * k, from (nat.div_mul_cancel H1)⁻¹, have H4 : n = n / k * k, from (nat.div_mul_cancel (dvd.trans H1 H2))⁻¹, sum.elim (eq_zero_sum_pos k) (assume H5 : k = 0, have H6: n / k = 0, from (ap _ H5 ⬝ !nat.div_zero), H6⁻¹ ▸ !dvd_zero) (assume H5 : k > 0, nat.dvd_of_mul_dvd_mul_right H5 (H3 ▸ H4 ▸ H2)) @[hott] protected theorem div_eq_iff_eq_mul_right {m n : ℕ} (k : ℕ) (H : n > 0) (H' : n ∣ m) : m / n = k ↔ m = n * k := iff.intro (assume H1, by rewrite [-H1, nat.mul_div_cancel' H']) (assume H1, by rewrite [H1, !nat.mul_div_cancel_left H]) @[hott] protected theorem div_eq_iff_eq_mul_left {m n : ℕ} (k : ℕ) (H : n > 0) (H' : n ∣ m) : m / n = k ↔ m = k * n := !mul.comm ▸ !nat.div_eq_iff_eq_mul_right H H' @[hott] protected theorem eq_mul_of_div_eq_right {m n k : ℕ} (H1 : n ∣ m) (H2 : m / n = k) : m = n * k := calc m = n * (m / n) : nat.mul_div_cancel' H1 ... = n * k : H2 @[hott] protected theorem div_eq_of_eq_mul_right {m n k : ℕ} (H1 : n > 0) (H2 : m = n * k) : m / n = k := calc m / n = n * k / n : H2 ... = k : !nat.mul_div_cancel_left H1 @[hott] protected theorem eq_mul_of_div_eq_left {m n k : ℕ} (H1 : n ∣ m) (H2 : m / n = k) : m = k * n := !mul.comm ▸ !nat.eq_mul_of_div_eq_right H1 H2 @[hott] protected theorem div_eq_of_eq_mul_left {m n k : ℕ} (H1 : n > 0) (H2 : m = k * n) : m / n = k := !nat.div_eq_of_eq_mul_right H1 (!mul.comm ▸ H2) @[hott] lemma add_mod_eq_of_dvd (i j n : nat) : n ∣ j → (i + j) % n = i % n := assume h, obtain k (hk : j = n * k), from exists_eq_mul_right_of_dvd h, begin subst j, rewrite mul.comm, apply add_mul_mod_self end /- / prod ordering -/ @[hott] lemma le_of_dvd {m n : nat} : n > 0 → m ∣ n → m ≤ n := assume (h₁ : n > 0) (h₂ : m ∣ n), have h₃ : n % m = 0, from mod_eq_zero_of_dvd h₂, by_contradiction (λ nle : ¬ m ≤ n, have h₄ : m > n, from lt_of_not_ge nle, have h₅ : n % m = n, from mod_eq_of_lt h₄, begin rewrite h₃ at h₅, subst n, exact absurd h₁ (lt.irrefl 0) end) @[hott] theorem div_mul_le (m n : ℕ) : m / n * n ≤ m := calc m = m / n * n + m % n : eq_div_mul_add_mod ... ≥ m / n * n : le_add_right @[hott] protected theorem div_le_of_le_mul {m n k : ℕ} (H : m ≤ n * k) : m / k ≤ n := sum.elim (eq_zero_sum_pos k) (assume H1 : k = 0, calc m / k = m / 0 : H1 ... = 0 : nat.div_zero ... ≤ n : zero_le) (assume H1 : k > 0, le_of_mul_le_mul_right (calc m / k * k ≤ m / k * k + m % k : le_add_right ... = m : eq_div_mul_add_mod ... ≤ n * k : H) H1) @[hott] protected theorem div_le_self (m n : ℕ) : m / n ≤ m := nat.cases_on n (!nat.div_zero⁻¹ ▸ !zero_le) take n, have H : m ≤ m * succ n, from calc m = m * 1 : mul_one ... ≤ m * succ n : !mul_le_mul_left (succ_le_succ !zero_le), nat.div_le_of_le_mul H @[hott] protected theorem mul_le_of_le_div {m n k : ℕ} (H : m ≤ n / k) : m * k ≤ n := calc m * k ≤ n / k * k : !mul_le_mul_right H ... ≤ n : div_mul_le @[hott] protected theorem le_div_of_mul_le {m n k : ℕ} (H1 : k > 0) (H2 : m * k ≤ n) : m ≤ n / k := have H3 : m * k < (succ (n / k)) * k, from calc m * k ≤ n : H2 ... = n / k * k + n % k : eq_div_mul_add_mod ... < n / k * k + k : add_lt_add_left (!mod_lt H1) ... = (succ (n / k)) * k : succ_mul, le_of_lt_succ (lt_of_mul_lt_mul_right H3) @[hott] protected theorem le_div_iff_mul_le {m n k : ℕ} (H : k > 0) : m ≤ n / k ↔ m * k ≤ n := iff.intro !nat.mul_le_of_le_div (!nat.le_div_of_mul_le H) @[hott] protected theorem div_le_div {m n : ℕ} (k : ℕ) (H : m ≤ n) : m / k ≤ n / k := by_cases_zero_pos k (by rewrite [*nat.div_zero]) (take k, assume H1 : k > 0, nat.le_div_of_mul_le H1 (le.trans !div_mul_le H)) @[hott] protected theorem div_lt_of_lt_mul {m n k : ℕ} (H : m < n * k) : m / k < n := lt_of_mul_lt_mul_right (calc m / k * k ≤ m / k * k + m % k : le_add_right ... = m : eq_div_mul_add_mod ... < n * k : H) @[hott] protected theorem lt_mul_of_div_lt {m n k : ℕ} (H1 : k > 0) (H2 : m / k < n) : m < n * k := have H3 : succ (m / k) * k ≤ n * k, from !mul_le_mul_right (succ_le_of_lt H2), have H4 : m / k * k + k ≤ n * k, by rewrite [succ_mul at H3]; apply H3, calc m = m / k * k + m % k : eq_div_mul_add_mod ... < m / k * k + k : add_lt_add_left (!mod_lt H1) ... ≤ n * k : H4 @[hott] protected theorem div_lt_iff_lt_mul {m n k : ℕ} (H : k > 0) : m / k < n ↔ m < n * k := iff.intro (!nat.lt_mul_of_div_lt H) !nat.div_lt_of_lt_mul @[hott] protected theorem div_le_iff_le_mul_of_div {m n : ℕ} (k : ℕ) (H : n > 0) (H' : n ∣ m) : m / n ≤ k ↔ m ≤ k * n := by refine iff.trans (!le_iff_mul_le_mul_right H) _; rewrite [!nat.div_mul_cancel H'] @[hott] protected theorem le_mul_of_div_le_of_div {m n k : ℕ} (H1 : n > 0) (H2 : n ∣ m) (H3 : m / n ≤ k) : m ≤ k * n := iff.mp (!nat.div_le_iff_le_mul_of_div H1 H2) H3 -- needed for integer division @[hott] theorem mul_sub_div_of_lt {m n k : ℕ} (H : k < m * n) : (m * n - (k + 1)) / m = n - k / m - 1 := begin have H1 : k / m < n, from nat.div_lt_of_lt_mul (!mul.comm ▸ H), have H2 : n - k / m ≥ 1, from nat.le_sub_of_add_le (calc 1 + k / m = succ (k / m) : add.comm ... ≤ n : succ_le_of_lt H1), have H3 : n - k / m = n - k / m - 1 + 1, from (nat.sub_add_cancel H2)⁻¹, have H4 : m > 0, from pos_of_ne_zero (assume H': m = 0, not_lt_zero k (begin rewrite [H' at H, zero_mul at H], exact H end)), have H5 : k % m + 1 ≤ m, from succ_le_of_lt (!mod_lt H4), have H6 : m - (k % m + 1) < m, from nat.sub_lt_self H4 !succ_pos, calc (m * n - (k + 1)) / m = (m * n - (k / m * m + k % m + 1)) / m : eq_div_mul_add_mod ... = (m * n - k / m * m - (k % m + 1)) / m : by rewrite [*nat.sub_sub] ... = ((n - k / m) * m - (k % m + 1)) / m : by rewrite [mul.comm m, nat.mul_sub_right_distrib] ... = ((n - k / m - 1) * m + m - (k % m + 1)) / m : by rewrite [H3 at {1}, right_distrib, nat.one_mul] ... = ((n - k / m - 1) * m + (m - (k % m + 1))) / m : {nat.add_sub_assoc H5 _} ... = (m - (k % m + 1)) / m + (n - k / m - 1) : by rewrite [add.comm, (add_mul_div_self H4)] ... = n - k / m - 1 : by rewrite [div_eq_zero_of_lt H6, zero_add] end private @[hott] lemma div_div_aux (a b c : nat) : b > 0 → c > 0 → (a / b) / c = a / (b * c) := suppose b > 0, suppose c > 0, nat.strong_rec_on a (λ a ih, let k₁ := a / (b*c) in let k₂ := a %(b*c) in have bc_pos : b*c > 0, from mul_pos `b > 0` `c > 0`, have k₂ < b * c, from mod_lt _ bc_pos, have k₂ ≤ a, from !mod_le, sum.elim (eq_sum_lt_of_le this) (suppose k₂ = a, have i₁ : a < b * c, by rewrite -this; assumption, have k₁ = 0, from div_eq_zero_of_lt i₁, have a / b < c, by rewrite [mul.comm at i₁]; exact nat.div_lt_of_lt_mul i₁, begin rewrite [`k₁ = 0`], show (a / b) / c = 0, from div_eq_zero_of_lt `a / b < c` end) (suppose k₂ < a, have a = k₁*(b*c) + k₂, from eq_div_mul_add_mod a (b*c), have a / b = k₁*c + k₂ / b, by rewrite [this at {1}, mul.comm b c at {2}, -mul.assoc, add.comm, add_mul_div_self `b > 0`, add.comm], have e₁ : (a / b) / c = k₁ + (k₂ / b) / c, by rewrite [this, add.comm, add_mul_div_self `c > 0`, add.comm], have e₂ : (k₂ / b) / c = k₂ / (b * c), from ih k₂ `k₂ < a`, have e₃ : k₂ / (b * c) = 0, from div_eq_zero_of_lt `k₂ < b * c`, have (k₂ / b) / c = 0, by rewrite [e₂, e₃], show (a / b) / c = k₁, by rewrite [e₁, this])) @[hott] protected lemma div_div_eq_div_mul (a b c : nat) : (a / b) / c = a / (b * c) := begin cases b with b, rewrite [zero_mul, *nat.div_zero, nat.zero_div], cases c with c, rewrite [mul_zero, *nat.div_zero], apply div_div_aux a (succ b) (succ c) dec_star dec_star end @[hott] lemma div_lt_of_ne_zero : Π {n : nat}, n ≠ 0 → n / 2 < n | 0 h := absurd rfl h | (succ n) h := begin apply nat.div_lt_of_lt_mul, rewrite [-add_one, right_distrib], change n + 1 < (n * 1 + n) + (1 + 1), rewrite [mul_one, -add.assoc], apply add_lt_add_right, show n < n + n + 1, begin rewrite [add.assoc, -add_zero n at {1}], apply add_lt_add_left, apply zero_lt_succ end end end nat end hott
504f374794ce2b941f0ac1cf0eda6d3ddbe47213
94e33a31faa76775069b071adea97e86e218a8ee
/src/order/rel_classes.lean
edd890a81faed8f3de10daebe3b24d95439cb4b9
[ "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
24,225
lean
/- Copyright (c) 2020 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Mario Carneiro, Yury G. Kudryashov -/ import order.basic import logic.is_empty /-! # Unbundled relation classes In this file we prove some properties of `is_*` classes defined in `init.algebra.classes`. The main difference between these classes and the usual order classes (`preorder` etc) is that usual classes extend `has_le` and/or `has_lt` while these classes take a relation as an explicit argument. -/ universes u v variables {α : Type u} {β : Type v} {r : α → α → Prop} {s : β → β → Prop} open function lemma of_eq [is_refl α r] : ∀ {a b}, a = b → r a b | _ _ ⟨h⟩ := refl _ lemma comm [is_symm α r] {a b : α} : r a b ↔ r b a := ⟨symm, symm⟩ lemma antisymm' [is_antisymm α r] {a b : α} : r a b → r b a → b = a := λ h h', antisymm h' h lemma antisymm_iff [is_refl α r] [is_antisymm α r] {a b : α} : r a b ∧ r b a ↔ a = b := ⟨λ h, antisymm h.1 h.2, by { rintro rfl, exact ⟨refl _, refl _⟩ }⟩ /-- A version of `antisymm` with `r` explicit. This lemma matches the lemmas from lean core in `init.algebra.classes`, but is missing there. -/ @[elab_simple] lemma antisymm_of (r : α → α → Prop) [is_antisymm α r] {a b : α} : r a b → r b a → a = b := antisymm /-- A version of `antisymm'` with `r` explicit. This lemma matches the lemmas from lean core in `init.algebra.classes`, but is missing there. -/ @[elab_simple] lemma antisymm_of' (r : α → α → Prop) [is_antisymm α r] {a b : α} : r a b → r b a → b = a := antisymm' /-- A version of `comm` with `r` explicit. This lemma matches the lemmas from lean core in `init.algebra.classes`, but is missing there. -/ lemma comm_of (r : α → α → Prop) [is_symm α r] {a b : α} : r a b ↔ r b a := comm theorem is_refl.swap (r) [is_refl α r] : is_refl α (swap r) := ⟨refl_of r⟩ theorem is_irrefl.swap (r) [is_irrefl α r] : is_irrefl α (swap r) := ⟨irrefl_of r⟩ theorem is_trans.swap (r) [is_trans α r] : is_trans α (swap r) := ⟨λ a b c h₁ h₂, trans_of r h₂ h₁⟩ theorem is_antisymm.swap (r) [is_antisymm α r] : is_antisymm α (swap r) := ⟨λ a b h₁ h₂, antisymm h₂ h₁⟩ theorem is_asymm.swap (r) [is_asymm α r] : is_asymm α (swap r) := ⟨λ a b h₁ h₂, asymm_of r h₂ h₁⟩ theorem is_total.swap (r) [is_total α r] : is_total α (swap r) := ⟨λ a b, (total_of r a b).swap⟩ theorem is_trichotomous.swap (r) [is_trichotomous α r] : is_trichotomous α (swap r) := ⟨λ a b, by simpa [swap, or.comm, or.left_comm] using trichotomous_of r a b⟩ theorem is_preorder.swap (r) [is_preorder α r] : is_preorder α (swap r) := {..@is_refl.swap α r _, ..@is_trans.swap α r _} theorem is_strict_order.swap (r) [is_strict_order α r] : is_strict_order α (swap r) := {..@is_irrefl.swap α r _, ..@is_trans.swap α r _} theorem is_partial_order.swap (r) [is_partial_order α r] : is_partial_order α (swap r) := {..@is_preorder.swap α r _, ..@is_antisymm.swap α r _} theorem is_total_preorder.swap (r) [is_total_preorder α r] : is_total_preorder α (swap r) := {..@is_preorder.swap α r _, ..@is_total.swap α r _} theorem is_linear_order.swap (r) [is_linear_order α r] : is_linear_order α (swap r) := {..@is_partial_order.swap α r _, ..@is_total.swap α r _} protected theorem is_asymm.is_antisymm (r) [is_asymm α r] : is_antisymm α r := ⟨λ x y h₁ h₂, (asymm h₁ h₂).elim⟩ protected theorem is_asymm.is_irrefl [is_asymm α r] : is_irrefl α r := ⟨λ a h, asymm h h⟩ protected theorem is_total.is_trichotomous (r) [is_total α r] : is_trichotomous α r := ⟨λ a b, or.left_comm.1 (or.inr $ total_of r a b)⟩ @[priority 100] -- see Note [lower instance priority] instance is_total.to_is_refl (r) [is_total α r] : is_refl α r := ⟨λ a, (or_self _).1 $ total_of r a a⟩ lemma ne_of_irrefl {r} [is_irrefl α r] : ∀ {x y : α}, r x y → x ≠ y | _ _ h rfl := irrefl _ h lemma ne_of_irrefl' {r} [is_irrefl α r] : ∀ {x y : α}, r x y → y ≠ x | _ _ h rfl := irrefl _ h lemma not_rel_of_subsingleton (r) [is_irrefl α r] [subsingleton α] (x y) : ¬ r x y := subsingleton.elim x y ▸ irrefl x lemma rel_of_subsingleton (r) [is_refl α r] [subsingleton α] (x y) : r x y := subsingleton.elim x y ▸ refl x @[simp] lemma empty_relation_apply (a b : α) : empty_relation a b ↔ false := iff.rfl lemma eq_empty_relation (r) [is_irrefl α r] [subsingleton α] : r = empty_relation := funext₂ $ by simpa using not_rel_of_subsingleton r instance : is_irrefl α empty_relation := ⟨λ a, id⟩ lemma trans_trichotomous_left [is_trans α r] [is_trichotomous α r] {a b c : α} : ¬r b a → r b c → r a c := begin intros h₁ h₂, rcases trichotomous_of r a b with h₃|h₃|h₃, exact trans h₃ h₂, rw h₃, exact h₂, exfalso, exact h₁ h₃ end lemma trans_trichotomous_right [is_trans α r] [is_trichotomous α r] {a b c : α} : r a b → ¬r c b → r a c := begin intros h₁ h₂, rcases trichotomous_of r b c with h₃|h₃|h₃, exact trans h₁ h₃, rw ←h₃, exact h₁, exfalso, exact h₂ h₃ end lemma transitive_of_trans (r : α → α → Prop) [is_trans α r] : transitive r := λ _ _ _, trans /-- Construct a partial order from a `is_strict_order` relation. See note [reducible non-instances]. -/ @[reducible] def partial_order_of_SO (r) [is_strict_order α r] : partial_order α := { le := λ x y, x = y ∨ r x y, lt := r, le_refl := λ x, or.inl rfl, le_trans := λ x y z h₁ h₂, match y, z, h₁, h₂ with | _, _, or.inl rfl, h₂ := h₂ | _, _, h₁, or.inl rfl := h₁ | _, _, or.inr h₁, or.inr h₂ := or.inr (trans h₁ h₂) end, le_antisymm := λ x y h₁ h₂, match y, h₁, h₂ with | _, or.inl rfl, h₂ := rfl | _, h₁, or.inl rfl := rfl | _, or.inr h₁, or.inr h₂ := (asymm h₁ h₂).elim end, lt_iff_le_not_le := λ x y, ⟨λ h, ⟨or.inr h, not_or (λ e, by rw e at h; exact irrefl _ h) (asymm h)⟩, λ ⟨h₁, h₂⟩, h₁.resolve_left (λ e, h₂ $ e ▸ or.inl rfl)⟩ } /-- This is basically the same as `is_strict_total_order`, but that definition has a redundant assumption `is_incomp_trans α lt`. -/ @[algebra] class is_strict_total_order' (α : Type u) (lt : α → α → Prop) extends is_trichotomous α lt, is_strict_order α lt : Prop. /-- Construct a linear order from an `is_strict_total_order'` relation. See note [reducible non-instances]. -/ @[reducible] def linear_order_of_STO' (r) [is_strict_total_order' α r] [Π x y, decidable (¬ r x y)] : linear_order α := { le_total := λ x y, match y, trichotomous_of r x y with | y, or.inl h := or.inl (or.inr h) | _, or.inr (or.inl rfl) := or.inl (or.inl rfl) | _, or.inr (or.inr h) := or.inr (or.inr h) end, decidable_le := λ x y, decidable_of_iff (¬ r y x) ⟨λ h, ((trichotomous_of r y x).resolve_left h).imp eq.symm id, λ h, h.elim (λ h, h ▸ irrefl_of _ _) (asymm_of r)⟩, ..partial_order_of_SO r } theorem is_strict_total_order'.swap (r) [is_strict_total_order' α r] : is_strict_total_order' α (swap r) := {..is_trichotomous.swap r, ..is_strict_order.swap r} /-! ### Order connection -/ /-- A connected order is one satisfying the condition `a < c → a < b ∨ b < c`. This is recognizable as an intuitionistic substitute for `a ≤ b ∨ b ≤ a` on the constructive reals, and is also known as negative transitivity, since the contrapositive asserts transitivity of the relation `¬ a < b`. -/ @[algebra] class is_order_connected (α : Type u) (lt : α → α → Prop) : Prop := (conn : ∀ a b c, lt a c → lt a b ∨ lt b c) theorem is_order_connected.neg_trans {r : α → α → Prop} [is_order_connected α r] {a b c} (h₁ : ¬ r a b) (h₂ : ¬ r b c) : ¬ r a c := mt (is_order_connected.conn a b c) $ by simp [h₁, h₂] theorem is_strict_weak_order_of_is_order_connected [is_asymm α r] [is_order_connected α r] : is_strict_weak_order α r := { trans := λ a b c h₁ h₂, (is_order_connected.conn _ c _ h₁).resolve_right (asymm h₂), incomp_trans := λ a b c ⟨h₁, h₂⟩ ⟨h₃, h₄⟩, ⟨is_order_connected.neg_trans h₁ h₃, is_order_connected.neg_trans h₄ h₂⟩, ..@is_asymm.is_irrefl α r _ } @[priority 100] -- see Note [lower instance priority] instance is_order_connected_of_is_strict_total_order' [is_strict_total_order' α r] : is_order_connected α r := ⟨λ a b c h, (trichotomous _ _).imp_right (λ o, o.elim (λ e, e ▸ h) (λ h', trans h' h))⟩ @[priority 100] -- see Note [lower instance priority] instance is_strict_total_order_of_is_strict_total_order' [is_strict_total_order' α r] : is_strict_total_order α r := {..is_strict_weak_order_of_is_order_connected} /-! ### Extensional relation -/ /-- An extensional relation is one in which an element is determined by its set of predecessors. It is named for the `x ∈ y` relation in set theory, whose extensionality is one of the first axioms of ZFC. -/ @[algebra] class is_extensional (α : Type u) (r : α → α → Prop) : Prop := (ext : ∀ a b, (∀ x, r x a ↔ r x b) → a = b) @[priority 100] -- see Note [lower instance priority] instance is_extensional_of_is_strict_total_order' [is_strict_total_order' α r] : is_extensional α r := ⟨λ a b H, ((@trichotomous _ r _ a b) .resolve_left $ mt (H _).2 (irrefl a)) .resolve_right $ mt (H _).1 (irrefl b)⟩ /-! ### Well-order -/ /-- A well order is a well-founded linear order. -/ @[algebra] class is_well_order (α : Type u) (r : α → α → Prop) extends is_strict_total_order' α r : Prop := (wf : well_founded r) @[priority 100] -- see Note [lower instance priority] instance is_well_order.is_strict_total_order {α} (r : α → α → Prop) [is_well_order α r] : is_strict_total_order α r := by apply_instance @[priority 100] -- see Note [lower instance priority] instance is_well_order.is_extensional {α} (r : α → α → Prop) [is_well_order α r] : is_extensional α r := by apply_instance @[priority 100] -- see Note [lower instance priority] instance is_well_order.is_trichotomous {α} (r : α → α → Prop) [is_well_order α r] : is_trichotomous α r := by apply_instance @[priority 100] -- see Note [lower instance priority] instance is_well_order.is_trans {α} (r : α → α → Prop) [is_well_order α r] : is_trans α r := by apply_instance @[priority 100] -- see Note [lower instance priority] instance is_well_order.is_irrefl {α} (r : α → α → Prop) [is_well_order α r] : is_irrefl α r := by apply_instance @[priority 100] -- see Note [lower instance priority] instance is_well_order.is_asymm {α} (r : α → α → Prop) [is_well_order α r] : is_asymm α r := by apply_instance /-- Construct a decidable linear order from a well-founded linear order. -/ noncomputable def is_well_order.linear_order (r : α → α → Prop) [is_well_order α r] : linear_order α := by { letI := λ x y, classical.dec (¬r x y), exact linear_order_of_STO' r } /-- Derive a `has_well_founded` instance from a `is_well_order` instance. -/ def is_well_order.to_has_well_founded [has_lt α] [hwo : is_well_order α (<)] : has_well_founded α := { r := (<), wf := hwo.wf } -- This isn't made into an instance as it loops with `is_irrefl α r`. theorem subsingleton.is_well_order [subsingleton α] (r : α → α → Prop) [hr : is_irrefl α r] : is_well_order α r := { trichotomous := λ a b, or.inr $ or.inl $ subsingleton.elim a b, trans := λ a b c h, (not_rel_of_subsingleton r a b h).elim, wf := ⟨λ a, ⟨_, λ y h, (not_rel_of_subsingleton r y a h).elim⟩⟩, ..hr } instance empty_relation.is_well_order [subsingleton α] : is_well_order α empty_relation := subsingleton.is_well_order _ @[priority 100] instance is_empty.is_well_order [is_empty α] (r : α → α → Prop) : is_well_order α r := { trichotomous := is_empty_elim, irrefl := is_empty_elim, trans := is_empty_elim, wf := well_founded_of_empty r } instance prod.lex.is_well_order [is_well_order α r] [is_well_order β s] : is_well_order (α × β) (prod.lex r s) := { trichotomous := λ ⟨a₁, a₂⟩ ⟨b₁, b₂⟩, match @trichotomous _ r _ a₁ b₁ with | or.inl h₁ := or.inl $ prod.lex.left _ _ h₁ | or.inr (or.inr h₁) := or.inr $ or.inr $ prod.lex.left _ _ h₁ | or.inr (or.inl e) := e ▸ match @trichotomous _ s _ a₂ b₂ with | or.inl h := or.inl $ prod.lex.right _ h | or.inr (or.inr h) := or.inr $ or.inr $ prod.lex.right _ h | or.inr (or.inl e) := e ▸ or.inr $ or.inl rfl end end, irrefl := λ ⟨a₁, a₂⟩ h, by cases h with _ _ _ _ h _ _ _ h; [exact irrefl _ h, exact irrefl _ h], trans := λ a b c h₁ h₂, begin cases h₁ with a₁ a₂ b₁ b₂ ab a₁ b₁ b₂ ab; cases h₂ with _ _ c₁ c₂ bc _ _ c₂ bc, { exact prod.lex.left _ _ (trans ab bc) }, { exact prod.lex.left _ _ ab }, { exact prod.lex.left _ _ bc }, { exact prod.lex.right _ (trans ab bc) } end, wf := prod.lex_wf is_well_order.wf is_well_order.wf } namespace set /-- An unbounded or cofinal set. -/ def unbounded (r : α → α → Prop) (s : set α) : Prop := ∀ a, ∃ b ∈ s, ¬ r b a /-- A bounded or final set. Not to be confused with `metric.bounded`. -/ def bounded (r : α → α → Prop) (s : set α) : Prop := ∃ a, ∀ b ∈ s, r b a @[simp] lemma not_bounded_iff {r : α → α → Prop} (s : set α) : ¬bounded r s ↔ unbounded r s := by simp only [bounded, unbounded, not_forall, not_exists, exists_prop, not_and, not_not] @[simp] lemma not_unbounded_iff {r : α → α → Prop} (s : set α) : ¬unbounded r s ↔ bounded r s := by rw [not_iff_comm, not_bounded_iff] lemma unbounded_of_is_empty [is_empty α] {r : α → α → Prop} (s : set α) : unbounded r s := is_empty_elim end set namespace prod instance is_refl_preimage_fst {r : α → α → Prop} [h : is_refl α r] : is_refl (α × α) (prod.fst ⁻¹'o r) := ⟨λ a, refl_of r a.1⟩ instance is_refl_preimage_snd {r : α → α → Prop} [h : is_refl α r] : is_refl (α × α) (prod.snd ⁻¹'o r) := ⟨λ a, refl_of r a.2⟩ instance is_trans_preimage_fst {r : α → α → Prop} [h : is_trans α r] : is_trans (α × α) (prod.fst ⁻¹'o r) := ⟨λ _ _ _, trans_of r⟩ instance is_trans_preimage_snd {r : α → α → Prop} [h : is_trans α r] : is_trans (α × α) (prod.snd ⁻¹'o r) := ⟨λ _ _ _, trans_of r⟩ end prod /-! ### Strict-non strict relations -/ /-- An unbundled relation class stating that `r` is the nonstrict relation corresponding to the strict relation `s`. Compare `preorder.lt_iff_le_not_le`. This is mostly meant to provide dot notation on `(⊆)` and `(⊂)`. -/ class is_nonstrict_strict_order (α : Type*) (r s : α → α → Prop) := (right_iff_left_not_left (a b : α) : s a b ↔ r a b ∧ ¬ r b a) lemma right_iff_left_not_left {r s : α → α → Prop} [is_nonstrict_strict_order α r s] {a b : α} : s a b ↔ r a b ∧ ¬ r b a := is_nonstrict_strict_order.right_iff_left_not_left _ _ /-- A version of `right_iff_left_not_left` with explicit `r` and `s`. -/ lemma right_iff_left_not_left_of (r s : α → α → Prop) [is_nonstrict_strict_order α r s] {a b : α} : s a b ↔ r a b ∧ ¬ r b a := right_iff_left_not_left -- The free parameter `r` is strictly speaking not uniquely determined by `s`, but in practice it -- always has a unique instance, so this is not dangerous. @[priority 100, nolint dangerous_instance] -- see Note [lower instance priority] instance is_nonstrict_strict_order.to_is_irrefl {r : α → α → Prop} {s : α → α → Prop} [is_nonstrict_strict_order α r s] : is_irrefl α s := ⟨λ a h, ((right_iff_left_not_left_of r s).1 h).2 ((right_iff_left_not_left_of r s).1 h).1⟩ /-! #### `⊆` and `⊂` -/ section subset variables [has_subset α] {a b c : α} @[refl] lemma subset_refl [is_refl α (⊆)] (a : α) : a ⊆ a := refl _ lemma subset_rfl [is_refl α (⊆)] : a ⊆ a := refl _ lemma subset_of_eq [is_refl α (⊆)] : a = b → a ⊆ b := λ h, h ▸ subset_rfl lemma superset_of_eq [is_refl α (⊆)] : a = b → b ⊆ a := λ h, h ▸ subset_rfl lemma ne_of_not_subset [is_refl α (⊆)] : ¬ a ⊆ b → a ≠ b := mt subset_of_eq lemma ne_of_not_superset [is_refl α (⊆)] : ¬ a ⊆ b → b ≠ a := mt superset_of_eq @[trans] lemma subset_trans [is_trans α (⊆)] {a b c : α} : a ⊆ b → b ⊆ c → a ⊆ c := trans lemma subset_antisymm [is_antisymm α (⊆)] (h : a ⊆ b) (h' : b ⊆ a) : a = b := antisymm h h' lemma superset_antisymm [is_antisymm α (⊆)] (h : a ⊆ b) (h' : b ⊆ a) : b = a := antisymm' h h' alias subset_of_eq ← eq.subset' --TODO: Fix it and kill `eq.subset` alias superset_of_eq ← eq.superset alias subset_trans ← has_subset.subset.trans alias subset_antisymm ← has_subset.subset.antisymm alias superset_antisymm ← has_subset.subset.antisymm' lemma subset_antisymm_iff [is_refl α (⊆)] [is_antisymm α (⊆)] : a = b ↔ a ⊆ b ∧ b ⊆ a := ⟨λ h, ⟨h.subset', h.superset⟩, λ h, h.1.antisymm h.2⟩ lemma superset_antisymm_iff [is_refl α (⊆)] [is_antisymm α (⊆)] : a = b ↔ b ⊆ a ∧ a ⊆ b := ⟨λ h, ⟨h.superset, h.subset'⟩, λ h, h.1.antisymm' h.2⟩ end subset section ssubset variables [has_ssubset α] lemma ssubset_irrefl [is_irrefl α (⊂)] (a : α) : ¬ a ⊂ a := irrefl _ lemma ssubset_irrfl [is_irrefl α (⊂)] {a : α} : ¬ a ⊂ a := irrefl _ lemma ne_of_ssubset [is_irrefl α (⊂)] {a b : α} : a ⊂ b → a ≠ b := ne_of_irrefl lemma ne_of_ssuperset [is_irrefl α (⊂)] {a b : α} : a ⊂ b → b ≠ a := ne_of_irrefl' @[trans] lemma ssubset_trans [is_trans α (⊂)] {a b c : α} : a ⊂ b → b ⊂ c → a ⊂ c := trans lemma ssubset_asymm [is_asymm α (⊂)] {a b : α} (h : a ⊂ b) : ¬ b ⊂ a := asymm h alias ssubset_irrfl ← has_ssubset.ssubset.false alias ne_of_ssubset ← has_ssubset.ssubset.ne alias ne_of_ssuperset ← has_ssubset.ssubset.ne' alias ssubset_trans ← has_ssubset.ssubset.trans alias ssubset_asymm ← has_ssubset.ssubset.asymm end ssubset section subset_ssubset variables [has_subset α] [has_ssubset α] [is_nonstrict_strict_order α (⊆) (⊂)] {a b c : α} lemma ssubset_iff_subset_not_subset : a ⊂ b ↔ a ⊆ b ∧ ¬ b ⊆ a := right_iff_left_not_left lemma subset_of_ssubset (h : a ⊂ b) : a ⊆ b := (ssubset_iff_subset_not_subset.1 h).1 lemma not_subset_of_ssubset (h : a ⊂ b) : ¬ b ⊆ a := (ssubset_iff_subset_not_subset.1 h).2 lemma not_ssubset_of_subset (h : a ⊆ b) : ¬ b ⊂ a := λ h', not_subset_of_ssubset h' h lemma ssubset_of_subset_not_subset (h₁ : a ⊆ b) (h₂ : ¬ b ⊆ a) : a ⊂ b := ssubset_iff_subset_not_subset.2 ⟨h₁, h₂⟩ alias subset_of_ssubset ← has_ssubset.ssubset.subset alias not_subset_of_ssubset ← has_ssubset.ssubset.not_subset alias not_ssubset_of_subset ← has_subset.subset.not_ssubset alias ssubset_of_subset_not_subset ← has_subset.subset.ssubset_of_not_subset lemma ssubset_of_subset_of_ssubset [is_trans α (⊆)] (h₁ : a ⊆ b) (h₂ : b ⊂ c) : a ⊂ c := (h₁.trans h₂.subset).ssubset_of_not_subset $ λ h, h₂.not_subset $ h.trans h₁ lemma ssubset_of_ssubset_of_subset [is_trans α (⊆)] (h₁ : a ⊂ b) (h₂ : b ⊆ c) : a ⊂ c := (h₁.subset.trans h₂).ssubset_of_not_subset $ λ h, h₁.not_subset $ h₂.trans h lemma ssubset_of_subset_of_ne [is_antisymm α (⊆)] (h₁ : a ⊆ b) (h₂ : a ≠ b) : a ⊂ b := h₁.ssubset_of_not_subset $ mt h₁.antisymm h₂ lemma ssubset_of_ne_of_subset [is_antisymm α (⊆)] (h₁ : a ≠ b) (h₂ : a ⊆ b) : a ⊂ b := ssubset_of_subset_of_ne h₂ h₁ lemma eq_or_ssubset_of_subset [is_antisymm α (⊆)] (h : a ⊆ b) : a = b ∨ a ⊂ b := (em (b ⊆ a)).imp h.antisymm h.ssubset_of_not_subset lemma ssubset_or_eq_of_subset [is_antisymm α (⊆)] (h : a ⊆ b) : a ⊂ b ∨ a = b := (eq_or_ssubset_of_subset h).swap alias ssubset_of_subset_of_ssubset ← has_subset.subset.trans_ssubset alias ssubset_of_ssubset_of_subset ← has_ssubset.ssubset.trans_subset alias ssubset_of_subset_of_ne ← has_subset.subset.ssubset_of_ne alias ssubset_of_ne_of_subset ← ne.ssubset_of_subset alias eq_or_ssubset_of_subset ← has_subset.subset.eq_or_ssubset alias ssubset_or_eq_of_subset ← has_subset.subset.ssubset_or_eq lemma ssubset_iff_subset_ne [is_antisymm α (⊆)] : a ⊂ b ↔ a ⊆ b ∧ a ≠ b := ⟨λ h, ⟨h.subset, h.ne⟩, λ h, h.1.ssubset_of_ne h.2⟩ lemma subset_iff_ssubset_or_eq [is_refl α (⊆)] [is_antisymm α (⊆)] : a ⊆ b ↔ a ⊂ b ∨ a = b := ⟨λ h, h.ssubset_or_eq, λ h, h.elim subset_of_ssubset subset_of_eq⟩ end subset_ssubset /-! ### Conversion of bundled order typeclasses to unbundled relation typeclasses -/ instance [preorder α] : is_refl α (≤) := ⟨le_refl⟩ instance [preorder α] : is_refl α (≥) := is_refl.swap _ instance [preorder α] : is_trans α (≤) := ⟨@le_trans _ _⟩ instance [preorder α] : is_trans α (≥) := is_trans.swap _ instance [preorder α] : is_preorder α (≤) := {} instance [preorder α] : is_preorder α (≥) := {} instance [preorder α] : is_irrefl α (<) := ⟨lt_irrefl⟩ instance [preorder α] : is_irrefl α (>) := is_irrefl.swap _ instance [preorder α] : is_trans α (<) := ⟨@lt_trans _ _⟩ instance [preorder α] : is_trans α (>) := is_trans.swap _ instance [preorder α] : is_asymm α (<) := ⟨@lt_asymm _ _⟩ instance [preorder α] : is_asymm α (>) := is_asymm.swap _ instance [preorder α] : is_antisymm α (<) := is_asymm.is_antisymm _ instance [preorder α] : is_antisymm α (>) := is_asymm.is_antisymm _ instance [preorder α] : is_strict_order α (<) := {} instance [preorder α] : is_strict_order α (>) := {} instance [preorder α] : is_nonstrict_strict_order α (≤) (<) := ⟨@lt_iff_le_not_le _ _⟩ instance [partial_order α] : is_antisymm α (≤) := ⟨@le_antisymm _ _⟩ instance [partial_order α] : is_antisymm α (≥) := is_antisymm.swap _ instance [partial_order α] : is_partial_order α (≤) := {} instance [partial_order α] : is_partial_order α (≥) := {} instance [linear_order α] : is_total α (≤) := ⟨le_total⟩ instance [linear_order α] : is_total α (≥) := is_total.swap _ instance linear_order.is_total_preorder [linear_order α] : is_total_preorder α (≤) := by apply_instance instance [linear_order α] : is_total_preorder α (≥) := {} instance [linear_order α] : is_linear_order α (≤) := {} instance [linear_order α] : is_linear_order α (≥) := {} instance [linear_order α] : is_trichotomous α (<) := ⟨lt_trichotomy⟩ instance [linear_order α] : is_trichotomous α (>) := is_trichotomous.swap _ instance [linear_order α] : is_trichotomous α (≤) := is_total.is_trichotomous _ instance [linear_order α] : is_trichotomous α (≥) := is_total.is_trichotomous _ instance [linear_order α] : is_strict_total_order α (<) := by apply_instance instance [linear_order α] : is_strict_total_order' α (<) := {} instance [linear_order α] : is_order_connected α (<) := by apply_instance instance [linear_order α] : is_incomp_trans α (<) := by apply_instance instance [linear_order α] : is_strict_weak_order α (<) := by apply_instance lemma transitive_le [preorder α] : transitive (@has_le.le α _) := transitive_of_trans _ lemma transitive_lt [preorder α] : transitive (@has_lt.lt α _) := transitive_of_trans _ lemma transitive_ge [preorder α] : transitive (@ge α _) := transitive_of_trans _ lemma transitive_gt [preorder α] : transitive (@gt α _) := transitive_of_trans _ instance order_dual.is_total_le [has_le α] [is_total α (≤)] : is_total αᵒᵈ (≤) := @is_total.swap α _ _ instance nat.lt.is_well_order : is_well_order ℕ (<) := ⟨nat.lt_wf⟩ instance [linear_order α] [h : is_well_order α (<)] : is_well_order αᵒᵈ (>) := h instance [linear_order α] [h : is_well_order α (>)] : is_well_order αᵒᵈ (<) := h
5d8d6c96640f5dede71764593cc39d63a5295953
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/category_theory/epi_mono.lean
b23311392e635c090e358cc657dca495c5c9475d
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
9,331
lean
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Scott Morrison -/ import category_theory.opposites import category_theory.groupoid /-! # Facts about epimorphisms and monomorphisms. > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. The definitions of `epi` and `mono` are in `category_theory.category`, since they are used by some lemmas for `iso`, which is used everywhere. -/ universes v₁ v₂ u₁ u₂ namespace category_theory variables {C : Type u₁} [category.{v₁} C] instance unop_mono_of_epi {A B : Cᵒᵖ} (f : A ⟶ B) [epi f] : mono f.unop := ⟨λ Z g h eq, quiver.hom.op_inj ((cancel_epi f).1 (quiver.hom.unop_inj eq))⟩ instance unop_epi_of_mono {A B : Cᵒᵖ} (f : A ⟶ B) [mono f] : epi f.unop := ⟨λ Z g h eq, quiver.hom.op_inj ((cancel_mono f).1 (quiver.hom.unop_inj eq))⟩ instance op_mono_of_epi {A B : C} (f : A ⟶ B) [epi f] : mono f.op := ⟨λ Z g h eq, quiver.hom.unop_inj ((cancel_epi f).1 (quiver.hom.op_inj eq))⟩ instance op_epi_of_mono {A B : C} (f : A ⟶ B) [mono f] : epi f.op := ⟨λ Z g h eq, quiver.hom.unop_inj ((cancel_mono f).1 (quiver.hom.op_inj eq))⟩ /-- A split monomorphism is a morphism `f : X ⟶ Y` with a given retraction `retraction f : Y ⟶ X` such that `f ≫ retraction f = 𝟙 X`. Every split monomorphism is a monomorphism. -/ @[ext, nolint has_nonempty_instance] structure split_mono {X Y : C} (f : X ⟶ Y) := (retraction : Y ⟶ X) (id' : f ≫ retraction = 𝟙 X . obviously) restate_axiom split_mono.id' attribute [simp, reassoc] split_mono.id /-- `is_split_mono f` is the assertion that `f` admits a retraction -/ class is_split_mono {X Y : C} (f : X ⟶ Y) : Prop := (exists_split_mono : nonempty (split_mono f)) /-- A constructor for `is_split_mono f` taking a `split_mono f` as an argument -/ lemma is_split_mono.mk' {X Y : C} {f : X ⟶ Y} (sm : split_mono f) : is_split_mono f := ⟨nonempty.intro sm⟩ /-- A split epimorphism is a morphism `f : X ⟶ Y` with a given section `section_ f : Y ⟶ X` such that `section_ f ≫ f = 𝟙 Y`. (Note that `section` is a reserved keyword, so we append an underscore.) Every split epimorphism is an epimorphism. -/ @[ext, nolint has_nonempty_instance] structure split_epi {X Y : C} (f : X ⟶ Y) := (section_ : Y ⟶ X) (id' : section_ ≫ f = 𝟙 Y . obviously) restate_axiom split_epi.id' attribute [simp, reassoc] split_epi.id /-- `is_split_epi f` is the assertion that `f` admits a section -/ class is_split_epi {X Y : C} (f : X ⟶ Y) : Prop := (exists_split_epi : nonempty (split_epi f)) /-- A constructor for `is_split_epi f` taking a `split_epi f` as an argument -/ lemma is_split_epi.mk' {X Y : C} {f : X ⟶ Y} (se : split_epi f) : is_split_epi f := ⟨nonempty.intro se⟩ /-- The chosen retraction of a split monomorphism. -/ noncomputable def retraction {X Y : C} (f : X ⟶ Y) [hf : is_split_mono f] : Y ⟶ X := hf.exists_split_mono.some.retraction @[simp, reassoc] lemma is_split_mono.id {X Y : C} (f : X ⟶ Y) [hf : is_split_mono f] : f ≫ retraction f = 𝟙 X := hf.exists_split_mono.some.id /-- The retraction of a split monomorphism has an obvious section. -/ def split_mono.split_epi {X Y : C} {f : X ⟶ Y} (sm : split_mono f) : split_epi (sm.retraction) := { section_ := f, } /-- The retraction of a split monomorphism is itself a split epimorphism. -/ instance retraction_is_split_epi {X Y : C} (f : X ⟶ Y) [hf : is_split_mono f] : is_split_epi (retraction f) := is_split_epi.mk' (split_mono.split_epi _) /-- A split mono which is epi is an iso. -/ lemma is_iso_of_epi_of_is_split_mono {X Y : C} (f : X ⟶ Y) [is_split_mono f] [epi f] : is_iso f := ⟨⟨retraction f, ⟨by simp, by simp [← cancel_epi f]⟩⟩⟩ /-- The chosen section of a split epimorphism. (Note that `section` is a reserved keyword, so we append an underscore.) -/ noncomputable def section_ {X Y : C} (f : X ⟶ Y) [hf : is_split_epi f] : Y ⟶ X := hf.exists_split_epi.some.section_ @[simp, reassoc] lemma is_split_epi.id {X Y : C} (f : X ⟶ Y) [hf : is_split_epi f] : section_ f ≫ f = 𝟙 Y := hf.exists_split_epi.some.id /-- The section of a split epimorphism has an obvious retraction. -/ def split_epi.split_mono {X Y : C} {f : X ⟶ Y} (se : split_epi f) : split_mono (se.section_) := { retraction := f, } /-- The section of a split epimorphism is itself a split monomorphism. -/ instance section_is_split_mono {X Y : C} (f : X ⟶ Y) [hf : is_split_epi f] : is_split_mono (section_ f) := is_split_mono.mk' (split_epi.split_mono _) /-- A split epi which is mono is an iso. -/ lemma is_iso_of_mono_of_is_split_epi {X Y : C} (f : X ⟶ Y) [mono f] [is_split_epi f] : is_iso f := ⟨⟨section_ f, ⟨by simp [← cancel_mono f], by simp⟩⟩⟩ /-- Every iso is a split mono. -/ @[priority 100] instance is_split_mono.of_iso {X Y : C} (f : X ⟶ Y) [is_iso f] : is_split_mono f := is_split_mono.mk' { retraction := inv f } /-- Every iso is a split epi. -/ @[priority 100] instance is_split_epi.of_iso {X Y : C} (f : X ⟶ Y) [is_iso f] : is_split_epi f := is_split_epi.mk' { section_ := inv f } lemma split_mono.mono {X Y : C} {f : X ⟶ Y} (sm : split_mono f) : mono f := { right_cancellation := λ Z g h w, begin replace w := w =≫ sm.retraction, simpa using w, end } /-- Every split mono is a mono. -/ @[priority 100] instance is_split_mono.mono {X Y : C} (f : X ⟶ Y) [hf : is_split_mono f] : mono f := hf.exists_split_mono.some.mono lemma split_epi.epi {X Y : C} {f : X ⟶ Y} (se : split_epi f) : epi f := { left_cancellation := λ Z g h w, begin replace w := se.section_ ≫= w, simpa using w, end } /-- Every split epi is an epi. -/ @[priority 100] instance is_split_epi.epi {X Y : C} (f : X ⟶ Y) [hf : is_split_epi f] : epi f := hf.exists_split_epi.some.epi /-- Every split mono whose retraction is mono is an iso. -/ lemma is_iso.of_mono_retraction' {X Y : C} {f : X ⟶ Y} (hf : split_mono f) [mono $ hf.retraction] : is_iso f := ⟨⟨hf.retraction, ⟨by simp, (cancel_mono_id $ hf.retraction).mp (by simp)⟩⟩⟩ /-- Every split mono whose retraction is mono is an iso. -/ lemma is_iso.of_mono_retraction {X Y : C} (f : X ⟶ Y) [hf : is_split_mono f] [hf' : mono $ retraction f] : is_iso f := @is_iso.of_mono_retraction' _ _ _ _ _ hf.exists_split_mono.some hf' /-- Every split epi whose section is epi is an iso. -/ lemma is_iso.of_epi_section' {X Y : C} {f : X ⟶ Y} (hf : split_epi f) [epi $ hf.section_] : is_iso f := ⟨⟨hf.section_, ⟨(cancel_epi_id $ hf.section_).mp (by simp), by simp⟩⟩⟩ /-- Every split epi whose section is epi is an iso. -/ lemma is_iso.of_epi_section {X Y : C} (f : X ⟶ Y) [hf : is_split_epi f] [hf' : epi $ section_ f] : is_iso f := @is_iso.of_epi_section' _ _ _ _ _ hf.exists_split_epi.some hf' /-- A category where every morphism has a `trunc` retraction is computably a groupoid. -/ -- FIXME this has unnecessarily become noncomputable! noncomputable def groupoid.of_trunc_split_mono (all_split_mono : ∀ {X Y : C} (f : X ⟶ Y), trunc (is_split_mono f)) : groupoid.{v₁} C := begin apply groupoid.of_is_iso, intros X Y f, trunc_cases all_split_mono f, trunc_cases all_split_mono (retraction f), apply is_iso.of_mono_retraction, end section variables (C) /-- A split mono category is a category in which every monomorphism is split. -/ class split_mono_category := (is_split_mono_of_mono : ∀ {X Y : C} (f : X ⟶ Y) [mono f], is_split_mono f) /-- A split epi category is a category in which every epimorphism is split. -/ class split_epi_category := (is_split_epi_of_epi : ∀ {X Y : C} (f : X ⟶ Y) [epi f], is_split_epi f) end /-- In a category in which every monomorphism is split, every monomorphism splits. This is not an instance because it would create an instance loop. -/ lemma is_split_mono_of_mono [split_mono_category C] {X Y : C} (f : X ⟶ Y) [mono f] : is_split_mono f := split_mono_category.is_split_mono_of_mono _ /-- In a category in which every epimorphism is split, every epimorphism splits. This is not an instance because it would create an instance loop. -/ lemma is_split_epi_of_epi [split_epi_category C] {X Y : C} (f : X ⟶ Y) [epi f] : is_split_epi f := split_epi_category.is_split_epi_of_epi _ section variables {D : Type u₂} [category.{v₂} D] /-- Split monomorphisms are also absolute monomorphisms. -/ @[simps] def split_mono.map {X Y : C} {f : X ⟶ Y} (sm : split_mono f) (F : C ⥤ D ) : split_mono (F.map f) := { retraction := F.map (sm.retraction), id' := by { rw [←functor.map_comp, split_mono.id, functor.map_id], } } /-- Split epimorphisms are also absolute epimorphisms. -/ @[simps] def split_epi.map {X Y : C} {f : X ⟶ Y} (se : split_epi f) (F : C ⥤ D ) : split_epi (F.map f) := { section_ := F.map (se.section_), id' := by { rw [←functor.map_comp, split_epi.id, functor.map_id], } } instance {X Y : C} (f : X ⟶ Y) [hf : is_split_mono f] (F : C ⥤ D) : is_split_mono (F.map f) := is_split_mono.mk' (hf.exists_split_mono.some.map F) instance {X Y : C} (f : X ⟶ Y) [hf : is_split_epi f] (F : C ⥤ D) : is_split_epi (F.map f) := is_split_epi.mk' (hf.exists_split_epi.some.map F) end end category_theory
c18ad0b6e872a6c59652f1b3c13bac079fd770b0
69d4931b605e11ca61881fc4f66db50a0a875e39
/src/topology/continuous_on.lean
206afc241cc2c8a43087bf39a153733ae1c10ed3
[ "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
44,633
lean
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import topology.constructions /-! # Neighborhoods and continuity relative to a subset This file defines relative versions * `nhds_within` of `nhds` * `continuous_on` of `continuous` * `continuous_within_at` of `continuous_at` and proves their basic properties, including the relationships between these restricted notions and the corresponding notions for the subtype equipped with the subspace topology. ## Notation * `𝓝 x`: the filter of neighborhoods of a point `x`; * `𝓟 s`: the principal filter of a set `s`; * `𝓝[s] x`: the filter `nhds_within x s` of neighborhoods of a point `x` within a set `s`. -/ open set filter open_locale topological_space filter variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} variables [topological_space α] @[simp] lemma nhds_bind_nhds_within {a : α} {s : set α} : (𝓝 a).bind (λ x, 𝓝[s] x) = 𝓝[s] a := bind_inf_principal.trans $ congr_arg2 _ nhds_bind_nhds rfl @[simp] lemma eventually_nhds_nhds_within {a : α} {s : set α} {p : α → Prop} : (∀ᶠ y in 𝓝 a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := filter.ext_iff.1 nhds_bind_nhds_within {x | p x} lemma eventually_nhds_within_iff {a : α} {s : set α} {p : α → Prop} : (∀ᶠ x in 𝓝[s] a, p x) ↔ ∀ᶠ x in 𝓝 a, x ∈ s → p x := eventually_inf_principal @[simp] lemma eventually_nhds_within_nhds_within {a : α} {s : set α} {p : α → Prop} : (∀ᶠ y in 𝓝[s] a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := begin refine ⟨λ h, _, λ h, (eventually_nhds_nhds_within.2 h).filter_mono inf_le_left⟩, simp only [eventually_nhds_within_iff] at h ⊢, exact h.mono (λ x hx hxs, (hx hxs).self_of_nhds hxs) end theorem nhds_within_eq (a : α) (s : set α) : 𝓝[s] a = ⨅ t ∈ {t : set α | a ∈ t ∧ is_open t}, 𝓟 (t ∩ s) := ((nhds_basis_opens a).inf_principal s).eq_binfi theorem nhds_within_univ (a : α) : 𝓝[set.univ] a = 𝓝 a := by rw [nhds_within, principal_univ, inf_top_eq] lemma nhds_within_has_basis {p : β → Prop} {s : β → set α} {a : α} (h : (𝓝 a).has_basis p s) (t : set α) : (𝓝[t] a).has_basis p (λ i, s i ∩ t) := h.inf_principal t lemma nhds_within_basis_open (a : α) (t : set α) : (𝓝[t] a).has_basis (λ u, a ∈ u ∧ is_open u) (λ u, u ∩ t) := nhds_within_has_basis (nhds_basis_opens a) t theorem mem_nhds_within {t : set α} {a : α} {s : set α} : t ∈ 𝓝[s] a ↔ ∃ u, is_open u ∧ a ∈ u ∧ u ∩ s ⊆ t := by simpa only [exists_prop, and_assoc, and_comm] using (nhds_within_basis_open a s).mem_iff lemma mem_nhds_within_iff_exists_mem_nhds_inter {t : set α} {a : α} {s : set α} : t ∈ 𝓝[s] a ↔ ∃ u ∈ 𝓝 a, u ∩ s ⊆ t := (nhds_within_has_basis (𝓝 a).basis_sets s).mem_iff lemma diff_mem_nhds_within_compl {X : Type*} [topological_space X] {x : X} {s : set X} (hs : s ∈ 𝓝 x) (t : set X) : s \ t ∈ 𝓝[tᶜ] x := diff_mem_inf_principal_compl hs t lemma nhds_of_nhds_within_of_nhds {s t : set α} {a : α} (h1 : s ∈ 𝓝 a) (h2 : t ∈ 𝓝[s] a) : (t ∈ 𝓝 a) := begin rcases mem_nhds_within_iff_exists_mem_nhds_inter.mp h2 with ⟨_, Hw, hw⟩, exact (nhds a).sets_of_superset ((nhds a).inter_sets Hw h1) hw, end lemma mem_nhds_within_of_mem_nhds {s t : set α} {a : α} (h : s ∈ 𝓝 a) : s ∈ 𝓝[t] a := mem_inf_sets_of_left h theorem self_mem_nhds_within {a : α} {s : set α} : s ∈ 𝓝[s] a := mem_inf_sets_of_right (mem_principal_self s) theorem inter_mem_nhds_within (s : set α) {t : set α} {a : α} (h : t ∈ 𝓝 a) : s ∩ t ∈ 𝓝[s] a := inter_mem_sets self_mem_nhds_within (mem_inf_sets_of_left h) theorem nhds_within_mono (a : α) {s t : set α} (h : s ⊆ t) : 𝓝[s] a ≤ 𝓝[t] a := inf_le_inf_left _ (principal_mono.mpr h) lemma pure_le_nhds_within {a : α} {s : set α} (ha : a ∈ s) : pure a ≤ 𝓝[s] a := le_inf (pure_le_nhds a) (le_principal_iff.2 ha) lemma mem_of_mem_nhds_within {a : α} {s t : set α} (ha : a ∈ s) (ht : t ∈ 𝓝[s] a) : a ∈ t := pure_le_nhds_within ha ht lemma filter.eventually.self_of_nhds_within {p : α → Prop} {s : set α} {x : α} (h : ∀ᶠ y in 𝓝[s] x, p y) (hx : x ∈ s) : p x := mem_of_mem_nhds_within hx h lemma tendsto_const_nhds_within {l : filter β} {s : set α} {a : α} (ha : a ∈ s) : tendsto (λ x : β, a) l (𝓝[s] a) := tendsto_const_pure.mono_right $ pure_le_nhds_within ha theorem nhds_within_restrict'' {a : α} (s : set α) {t : set α} (h : t ∈ 𝓝[s] a) : 𝓝[s] a = 𝓝[s ∩ t] a := le_antisymm (le_inf inf_le_left (le_principal_iff.mpr (inter_mem_sets self_mem_nhds_within h))) (inf_le_inf_left _ (principal_mono.mpr (set.inter_subset_left _ _))) theorem nhds_within_restrict' {a : α} (s : set α) {t : set α} (h : t ∈ 𝓝 a) : 𝓝[s] a = 𝓝[s ∩ t] a := nhds_within_restrict'' s $ mem_inf_sets_of_left h theorem nhds_within_restrict {a : α} (s : set α) {t : set α} (h₀ : a ∈ t) (h₁ : is_open t) : 𝓝[s] a = 𝓝[s ∩ t] a := nhds_within_restrict' s (is_open.mem_nhds h₁ h₀) theorem nhds_within_le_of_mem {a : α} {s t : set α} (h : s ∈ 𝓝[t] a) : 𝓝[t] a ≤ 𝓝[s] a := begin rcases mem_nhds_within.1 h with ⟨u, u_open, au, uts⟩, have : 𝓝[t] a = 𝓝[t ∩ u] a := nhds_within_restrict _ au u_open, rw [this, inter_comm], exact nhds_within_mono _ uts end theorem nhds_within_le_nhds {a : α} {s : set α} : 𝓝[s] a ≤ 𝓝 a := by { rw ← nhds_within_univ, apply nhds_within_le_of_mem, exact univ_mem_sets } theorem nhds_within_eq_nhds_within {a : α} {s t u : set α} (h₀ : a ∈ s) (h₁ : is_open s) (h₂ : t ∩ s = u ∩ s) : 𝓝[t] a = 𝓝[u] a := by rw [nhds_within_restrict t h₀ h₁, nhds_within_restrict u h₀ h₁, h₂] theorem nhds_within_eq_of_open {a : α} {s : set α} (h₀ : a ∈ s) (h₁ : is_open s) : 𝓝[s] a = 𝓝 a := inf_eq_left.2 $ le_principal_iff.2 $ is_open.mem_nhds h₁ h₀ @[simp] theorem nhds_within_empty (a : α) : 𝓝[∅] a = ⊥ := by rw [nhds_within, principal_empty, inf_bot_eq] theorem nhds_within_union (a : α) (s t : set α) : 𝓝[s ∪ t] a = 𝓝[s] a ⊔ 𝓝[t] a := by { delta nhds_within, rw [←inf_sup_left, sup_principal] } theorem nhds_within_inter (a : α) (s t : set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓝[t] a := by { delta nhds_within, rw [inf_left_comm, inf_assoc, inf_principal, ←inf_assoc, inf_idem] } theorem nhds_within_inter' (a : α) (s t : set α) : 𝓝[s ∩ t] a = (𝓝[s] a) ⊓ 𝓟 t := by { delta nhds_within, rw [←inf_principal, inf_assoc] } theorem nhds_within_inter_of_mem {a : α} {s t : set α} (h : s ∈ 𝓝[t] a) : 𝓝[s ∩ t] a = 𝓝[t] a := by { rw [nhds_within_inter, inf_eq_right], exact nhds_within_le_of_mem h } @[simp] theorem nhds_within_singleton (a : α) : 𝓝[{a}] a = pure a := by rw [nhds_within, principal_singleton, inf_eq_right.2 (pure_le_nhds a)] @[simp] theorem nhds_within_insert (a : α) (s : set α) : 𝓝[insert a s] a = pure a ⊔ 𝓝[s] a := by rw [← singleton_union, nhds_within_union, nhds_within_singleton] lemma mem_nhds_within_insert {a : α} {s t : set α} : t ∈ 𝓝[insert a s] a ↔ a ∈ t ∧ t ∈ 𝓝[s] a := by simp lemma insert_mem_nhds_within_insert {a : α} {s t : set α} (h : t ∈ 𝓝[s] a) : insert a t ∈ 𝓝[insert a s] a := by simp [mem_sets_of_superset h] lemma nhds_within_prod_eq {α : Type*} [topological_space α] {β : Type*} [topological_space β] (a : α) (b : β) (s : set α) (t : set β) : 𝓝[s.prod t] (a, b) = 𝓝[s] a ×ᶠ 𝓝[t] b := by { delta nhds_within, rw [nhds_prod_eq, ←filter.prod_inf_prod, filter.prod_principal_principal] } lemma nhds_within_prod {α : Type*} [topological_space α] {β : Type*} [topological_space β] {s u : set α} {t v : set β} {a : α} {b : β} (hu : u ∈ 𝓝[s] a) (hv : v ∈ 𝓝[t] b) : (u.prod v) ∈ 𝓝[s.prod t] (a, b) := by { rw nhds_within_prod_eq, exact prod_mem_prod hu hv, } lemma nhds_within_pi_eq' {ι : Type*} {α : ι → Type*} [Π i, topological_space (α i)] {I : set ι} (hI : finite I) (s : Π i, set (α i)) (x : Π i, α i) : 𝓝[pi I s] x = ⨅ i, comap (λ x, x i) (𝓝 (x i) ⊓ ⨅ (hi : i ∈ I), 𝓟 (s i)) := by simp only [nhds_within, nhds_pi, comap_inf, comap_infi, pi_def, comap_principal, ← infi_principal_finite hI, ← infi_inf_eq] lemma nhds_within_pi_eq {ι : Type*} {α : ι → Type*} [Π i, topological_space (α i)] {I : set ι} (hI : finite I) (s : Π i, set (α i)) (x : Π i, α i) : 𝓝[pi I s] x = (⨅ i ∈ I, comap (λ x, x i) (𝓝[s i] (x i))) ⊓ ⨅ (i ∉ I), comap (λ x, x i) (𝓝 (x i)) := begin simp only [nhds_within, nhds_pi, pi_def, ← infi_principal_finite hI, comap_inf, comap_principal, function.eval], rw [infi_split _ (λ i, i ∈ I), inf_right_comm], simp only [infi_inf_eq] end lemma nhds_within_pi_univ_eq {ι : Type*} {α : ι → Type*} [fintype ι] [Π i, topological_space (α i)] (s : Π i, set (α i)) (x : Π i, α i) : 𝓝[pi univ s] x = ⨅ i, comap (λ x, x i) 𝓝[s i] (x i) := by simpa [nhds_within] using nhds_within_pi_eq finite_univ s x lemma nhds_within_pi_univ_eq_bot {ι : Type*} {α : ι → Type*} [Π i, topological_space (α i)] {s : Π i, set (α i)} {x : Π i, α i} : 𝓝[pi univ s] x = ⊥ ↔ ∃ i, 𝓝[s i] (x i) = ⊥ := begin classical, split, { haveI : Π i, inhabited (α i) := λ i, ⟨x i⟩, simp only [nhds_within, nhds_pi, inf_principal_eq_bot, mem_infi_iff', mem_comap_sets], rintro ⟨I, hIf, V, hV, hVs⟩, choose! t htx htV using hV, contrapose! hVs, change ∀ i, ∃ᶠ y in 𝓝 (x i), y ∈ s i at hVs, have : ∀ i ∈ I, (s i ∩ t i).nonempty, from λ i hi, ((hVs i).and_eventually (htx i hi)).exists, choose! y hys hyt, choose z hzs using λ i, (hVs i).exists, suffices : I.piecewise y z ∈ (⋂ i ∈ I, V i) ∩ (pi univ s), from λ H, H this.1 this.2, refine ⟨mem_bInter $ λ i hi, htV i hi _, λ i hi', _⟩, { simp only [mem_preimage, piecewise_eq_of_mem _ _ _ hi, hyt i hi] }, { by_cases hi : i ∈ I; simp * } }, { rintro ⟨i, eq⟩, rw [← @map_eq_bot_iff _ _ _ (λ x : Π i, α i, x i)], refine eq_bot_mono _ eq, exact ((continuous_apply i).tendsto x).inf (tendsto_principal_principal.2 $ λ y hy, hy i trivial) } end lemma nhds_within_pi_eq_bot {ι : Type*} {α : ι → Type*} [Π i, topological_space (α i)] {I : set ι} {s : Π i, set (α i)} {x : Π i, α i} : 𝓝[pi I s] x = ⊥ ↔ ∃ i ∈ I, 𝓝[s i] (x i) = ⊥ := begin classical, rw [← univ_pi_piecewise I, nhds_within_pi_univ_eq_bot], refine exists_congr (λ i, _), by_cases hi : i ∈ I; simp [*, nhds_within_univ, nhds_ne_bot.ne] end lemma nhds_within_pi_ne_bot {ι : Type*} {α : ι → Type*} [Π i, topological_space (α i)] {I : set ι} {s : Π i, set (α i)} {x : Π i, α i} : (𝓝[pi I s] x).ne_bot ↔ ∀ i ∈ I, (𝓝[s i] (x i)).ne_bot := by simp [ne_bot_iff, nhds_within_pi_eq_bot] theorem filter.tendsto.piecewise_nhds_within {f g : α → β} {t : set α} [∀ x, decidable (x ∈ t)] {a : α} {s : set α} {l : filter β} (h₀ : tendsto f (𝓝[s ∩ t] a) l) (h₁ : tendsto g (𝓝[s ∩ tᶜ] a) l) : tendsto (piecewise t f g) (𝓝[s] a) l := by apply tendsto.piecewise; rwa ← nhds_within_inter' theorem filter.tendsto.if_nhds_within {f g : α → β} {p : α → Prop} [decidable_pred p] {a : α} {s : set α} {l : filter β} (h₀ : tendsto f (𝓝[s ∩ {x | p x}] a) l) (h₁ : tendsto g (𝓝[s ∩ {x | ¬ p x}] a) l) : tendsto (λ x, if p x then f x else g x) (𝓝[s] a) l := h₀.piecewise_nhds_within h₁ lemma map_nhds_within (f : α → β) (a : α) (s : set α) : map f (𝓝[s] a) = ⨅ t ∈ {t : set α | a ∈ t ∧ is_open t}, 𝓟 (f '' (t ∩ s)) := ((nhds_within_basis_open a s).map f).eq_binfi theorem tendsto_nhds_within_mono_left {f : α → β} {a : α} {s t : set α} {l : filter β} (hst : s ⊆ t) (h : tendsto f (𝓝[t] a) l) : tendsto f (𝓝[s] a) l := h.mono_left $ nhds_within_mono a hst theorem tendsto_nhds_within_mono_right {f : β → α} {l : filter β} {a : α} {s t : set α} (hst : s ⊆ t) (h : tendsto f l (𝓝[s] a)) : tendsto f l (𝓝[t] a) := h.mono_right (nhds_within_mono a hst) theorem tendsto_nhds_within_of_tendsto_nhds {f : α → β} {a : α} {s : set α} {l : filter β} (h : tendsto f (𝓝 a) l) : tendsto f (𝓝[s] a) l := h.mono_left inf_le_left theorem principal_subtype {α : Type*} (s : set α) (t : set {x // x ∈ s}) : 𝓟 t = comap coe (𝓟 ((coe : s → α) '' t)) := by rw [comap_principal, set.preimage_image_eq _ subtype.coe_injective] lemma mem_closure_iff_nhds_within_ne_bot {s : set α} {x : α} : x ∈ closure s ↔ ne_bot (𝓝[s] x) := mem_closure_iff_cluster_pt lemma nhds_within_ne_bot_of_mem {s : set α} {x : α} (hx : x ∈ s) : ne_bot (𝓝[s] x) := mem_closure_iff_nhds_within_ne_bot.1 $ subset_closure hx lemma is_closed.mem_of_nhds_within_ne_bot {s : set α} (hs : is_closed s) {x : α} (hx : ne_bot $ 𝓝[s] x) : x ∈ s := by simpa only [hs.closure_eq] using mem_closure_iff_nhds_within_ne_bot.2 hx lemma dense_range.nhds_within_ne_bot {ι : Type*} {f : ι → α} (h : dense_range f) (x : α) : ne_bot (𝓝[range f] x) := mem_closure_iff_cluster_pt.1 (h x) lemma mem_closure_pi {ι : Type*} {α : ι → Type*} [Π i, topological_space (α i)] {I : set ι} {s : Π i, set (α i)} {x : Π i, α i} : x ∈ closure (pi I s) ↔ ∀ i ∈ I, x i ∈ closure (s i) := by simp only [mem_closure_iff_nhds_within_ne_bot, nhds_within_pi_ne_bot] lemma closure_pi_set {ι : Type*} {α : ι → Type*} [Π i, topological_space (α i)] (I : set ι) (s : Π i, set (α i)) : closure (pi I s) = pi I (λ i, closure (s i)) := set.ext $ λ x, mem_closure_pi lemma dense_pi {ι : Type*} {α : ι → Type*} [Π i, topological_space (α i)] {s : Π i, set (α i)} (I : set ι) (hs : ∀ i ∈ I, dense (s i)) : dense (pi I s) := by simp only [dense_iff_closure_eq, closure_pi_set, pi_congr rfl (λ i hi, (hs i hi).closure_eq), pi_univ] lemma eventually_eq_nhds_within_iff {f g : α → β} {s : set α} {a : α} : (f =ᶠ[𝓝[s] a] g) ↔ ∀ᶠ x in 𝓝 a, x ∈ s → f x = g x := mem_inf_principal lemma eventually_eq_nhds_within_of_eq_on {f g : α → β} {s : set α} {a : α} (h : eq_on f g s) : f =ᶠ[𝓝[s] a] g := mem_inf_sets_of_right h lemma set.eq_on.eventually_eq_nhds_within {f g : α → β} {s : set α} {a : α} (h : eq_on f g s) : f =ᶠ[𝓝[s] a] g := eventually_eq_nhds_within_of_eq_on h lemma tendsto_nhds_within_congr {f g : α → β} {s : set α} {a : α} {l : filter β} (hfg : ∀ x ∈ s, f x = g x) (hf : tendsto f (𝓝[s] a) l) : tendsto g (𝓝[s] a) l := (tendsto_congr' $ eventually_eq_nhds_within_of_eq_on hfg).1 hf lemma eventually_nhds_with_of_forall {s : set α} {a : α} {p : α → Prop} (h : ∀ x ∈ s, p x) : ∀ᶠ x in 𝓝[s] a, p x := mem_inf_sets_of_right h lemma tendsto_nhds_within_of_tendsto_nhds_of_eventually_within {a : α} {l : filter β} {s : set α} (f : β → α) (h1 : tendsto f l (𝓝 a)) (h2 : ∀ᶠ x in l, f x ∈ s) : tendsto f l (𝓝[s] a) := tendsto_inf.2 ⟨h1, tendsto_principal.2 h2⟩ @[simp] lemma tendsto_nhds_within_range {a : α} {l : filter β} {f : β → α} : tendsto f l (𝓝[range f] a) ↔ tendsto f l (𝓝 a) := ⟨λ h, h.mono_right inf_le_left, λ h, tendsto_inf.2 ⟨h, tendsto_principal.2 $ eventually_of_forall mem_range_self⟩⟩ lemma filter.eventually_eq.eq_of_nhds_within {s : set α} {f g : α → β} {a : α} (h : f =ᶠ[𝓝[s] a] g) (hmem : a ∈ s) : f a = g a := h.self_of_nhds_within hmem lemma eventually_nhds_within_of_eventually_nhds {α : Type*} [topological_space α] {s : set α} {a : α} {p : α → Prop} (h : ∀ᶠ x in 𝓝 a, p x) : ∀ᶠ x in 𝓝[s] a, p x := mem_nhds_within_of_mem_nhds h /-! ### `nhds_within` and subtypes -/ theorem mem_nhds_within_subtype {s : set α} {a : {x // x ∈ s}} {t u : set {x // x ∈ s}} : t ∈ 𝓝[u] a ↔ t ∈ comap (coe : s → α) (𝓝[coe '' u] a) := by rw [nhds_within, nhds_subtype, principal_subtype, ←comap_inf, ←nhds_within] theorem nhds_within_subtype (s : set α) (a : {x // x ∈ s}) (t : set {x // x ∈ s}) : 𝓝[t] a = comap (coe : s → α) (𝓝[coe '' t] a) := filter.ext $ λ u, mem_nhds_within_subtype theorem nhds_within_eq_map_subtype_coe {s : set α} {a : α} (h : a ∈ s) : 𝓝[s] a = map (coe : s → α) (𝓝 ⟨a, h⟩) := by simpa only [subtype.range_coe] using (embedding_subtype_coe.map_nhds_eq ⟨a, h⟩).symm theorem tendsto_nhds_within_iff_subtype {s : set α} {a : α} (h : a ∈ s) (f : α → β) (l : filter β) : tendsto f (𝓝[s] a) l ↔ tendsto (s.restrict f) (𝓝 ⟨a, h⟩) l := by simp only [tendsto, nhds_within_eq_map_subtype_coe h, filter.map_map, restrict] variables [topological_space β] [topological_space γ] [topological_space δ] /-- A function between topological spaces is continuous at a point `x₀` within a subset `s` if `f x` tends to `f x₀` when `x` tends to `x₀` while staying within `s`. -/ def continuous_within_at (f : α → β) (s : set α) (x : α) : Prop := tendsto f (𝓝[s] x) (𝓝 (f x)) /-- If a function is continuous within `s` at `x`, then it tends to `f x` within `s` by definition. We register this fact for use with the dot notation, especially to use `tendsto.comp` as `continuous_within_at.comp` will have a different meaning. -/ lemma continuous_within_at.tendsto {f : α → β} {s : set α} {x : α} (h : continuous_within_at f s x) : tendsto f (𝓝[s] x) (𝓝 (f x)) := h /-- A function between topological spaces is continuous on a subset `s` when it's continuous at every point of `s` within `s`. -/ def continuous_on (f : α → β) (s : set α) : Prop := ∀ x ∈ s, continuous_within_at f s x lemma continuous_on.continuous_within_at {f : α → β} {s : set α} {x : α} (hf : continuous_on f s) (hx : x ∈ s) : continuous_within_at f s x := hf x hx theorem continuous_within_at_univ (f : α → β) (x : α) : continuous_within_at f set.univ x ↔ continuous_at f x := by rw [continuous_at, continuous_within_at, nhds_within_univ] theorem continuous_within_at_iff_continuous_at_restrict (f : α → β) {x : α} {s : set α} (h : x ∈ s) : continuous_within_at f s x ↔ continuous_at (s.restrict f) ⟨x, h⟩ := tendsto_nhds_within_iff_subtype h f _ theorem continuous_within_at.tendsto_nhds_within {f : α → β} {x : α} {s : set α} {t : set β} (h : continuous_within_at f s x) (ht : maps_to f s t) : tendsto f (𝓝[s] x) (𝓝[t] (f x)) := tendsto_inf.2 ⟨h, tendsto_principal.2 $ mem_inf_sets_of_right $ mem_principal_sets.2 $ ht⟩ theorem continuous_within_at.tendsto_nhds_within_image {f : α → β} {x : α} {s : set α} (h : continuous_within_at f s x) : tendsto f (𝓝[s] x) (𝓝[f '' s] (f x)) := h.tendsto_nhds_within (maps_to_image _ _) lemma continuous_within_at.prod_map {f : α → γ} {g : β → δ} {s : set α} {t : set β} {x : α} {y : β} (hf : continuous_within_at f s x) (hg : continuous_within_at g t y) : continuous_within_at (prod.map f g) (s.prod t) (x, y) := begin unfold continuous_within_at at *, rw [nhds_within_prod_eq, prod.map, nhds_prod_eq], exact hf.prod_map hg, end lemma continuous_within_at_pi {ι : Type*} {π : ι → Type*} [∀ i, topological_space (π i)] {f : α → Π i, π i} {s : set α} {x : α} : continuous_within_at f s x ↔ ∀ i, continuous_within_at (λ y, f y i) s x := tendsto_pi lemma continuous_on_pi {ι : Type*} {π : ι → Type*} [∀ i, topological_space (π i)] {f : α → Π i, π i} {s : set α} : continuous_on f s ↔ ∀ i, continuous_on (λ y, f y i) s := ⟨λ h i x hx, tendsto_pi.1 (h x hx) i, λ h x hx, tendsto_pi.2 (λ i, h i x hx)⟩ theorem continuous_on_iff {f : α → β} {s : set α} : continuous_on f s ↔ ∀ x ∈ s, ∀ t : set β, is_open t → f x ∈ t → ∃ u, is_open u ∧ x ∈ u ∧ u ∩ s ⊆ f ⁻¹' t := by simp only [continuous_on, continuous_within_at, tendsto_nhds, mem_nhds_within] theorem continuous_on_iff_continuous_restrict {f : α → β} {s : set α} : continuous_on f s ↔ continuous (s.restrict f) := begin rw [continuous_on, continuous_iff_continuous_at], split, { rintros h ⟨x, xs⟩, exact (continuous_within_at_iff_continuous_at_restrict f xs).mp (h x xs) }, intros h x xs, exact (continuous_within_at_iff_continuous_at_restrict f xs).mpr (h ⟨x, xs⟩) end theorem continuous_on_iff' {f : α → β} {s : set α} : continuous_on f s ↔ ∀ t : set β, is_open t → ∃ u, is_open u ∧ f ⁻¹' t ∩ s = u ∩ s := have ∀ t, is_open (s.restrict f ⁻¹' t) ↔ ∃ (u : set α), is_open u ∧ f ⁻¹' t ∩ s = u ∩ s, begin intro t, rw [is_open_induced_iff, set.restrict_eq, set.preimage_comp], simp only [subtype.preimage_coe_eq_preimage_coe_iff], split; { rintros ⟨u, ou, useq⟩, exact ⟨u, ou, useq.symm⟩ } end, by rw [continuous_on_iff_continuous_restrict, continuous_def]; simp only [this] theorem continuous_on_iff_is_closed {f : α → β} {s : set α} : continuous_on f s ↔ ∀ t : set β, is_closed t → ∃ u, is_closed u ∧ f ⁻¹' t ∩ s = u ∩ s := have ∀ t, is_closed (s.restrict f ⁻¹' t) ↔ ∃ (u : set α), is_closed u ∧ f ⁻¹' t ∩ s = u ∩ s, begin intro t, rw [is_closed_induced_iff, set.restrict_eq, set.preimage_comp], simp only [subtype.preimage_coe_eq_preimage_coe_iff, eq_comm] end, by rw [continuous_on_iff_continuous_restrict, continuous_iff_is_closed]; simp only [this] lemma continuous_on.prod_map {f : α → γ} {g : β → δ} {s : set α} {t : set β} (hf : continuous_on f s) (hg : continuous_on g t) : continuous_on (prod.map f g) (s.prod t) := λ ⟨x, y⟩ ⟨hx, hy⟩, continuous_within_at.prod_map (hf x hx) (hg y hy) lemma continuous_on_empty (f : α → β) : continuous_on f ∅ := λ x, false.elim theorem nhds_within_le_comap {x : α} {s : set α} {f : α → β} (ctsf : continuous_within_at f s x) : 𝓝[s] x ≤ comap f (𝓝[f '' s] (f x)) := map_le_iff_le_comap.1 ctsf.tendsto_nhds_within_image theorem continuous_within_at_iff_ptendsto_res (f : α → β) {x : α} {s : set α} : continuous_within_at f s x ↔ ptendsto (pfun.res f s) (𝓝 x) (𝓝 (f x)) := tendsto_iff_ptendsto _ _ _ _ lemma continuous_iff_continuous_on_univ {f : α → β} : continuous f ↔ continuous_on f univ := by simp [continuous_iff_continuous_at, continuous_on, continuous_at, continuous_within_at, nhds_within_univ] lemma continuous_within_at.mono {f : α → β} {s t : set α} {x : α} (h : continuous_within_at f t x) (hs : s ⊆ t) : continuous_within_at f s x := h.mono_left (nhds_within_mono x hs) lemma continuous_within_at.mono_of_mem {f : α → β} {s t : set α} {x : α} (h : continuous_within_at f t x) (hs : t ∈ 𝓝[s] x) : continuous_within_at f s x := h.mono_left (nhds_within_le_of_mem hs) lemma continuous_within_at_inter' {f : α → β} {s t : set α} {x : α} (h : t ∈ 𝓝[s] x) : continuous_within_at f (s ∩ t) x ↔ continuous_within_at f s x := by simp [continuous_within_at, nhds_within_restrict'' s h] lemma continuous_within_at_inter {f : α → β} {s t : set α} {x : α} (h : t ∈ 𝓝 x) : continuous_within_at f (s ∩ t) x ↔ continuous_within_at f s x := by simp [continuous_within_at, nhds_within_restrict' s h] lemma continuous_within_at_union {f : α → β} {s t : set α} {x : α} : continuous_within_at f (s ∪ t) x ↔ continuous_within_at f s x ∧ continuous_within_at f t x := by simp only [continuous_within_at, nhds_within_union, tendsto_sup] lemma continuous_within_at.union {f : α → β} {s t : set α} {x : α} (hs : continuous_within_at f s x) (ht : continuous_within_at f t x) : continuous_within_at f (s ∪ t) x := continuous_within_at_union.2 ⟨hs, ht⟩ lemma continuous_within_at.mem_closure_image {f : α → β} {s : set α} {x : α} (h : continuous_within_at f s x) (hx : x ∈ closure s) : f x ∈ closure (f '' s) := by haveI := (mem_closure_iff_nhds_within_ne_bot.1 hx); exact (mem_closure_of_tendsto h $ mem_sets_of_superset self_mem_nhds_within (subset_preimage_image f s)) lemma continuous_within_at.mem_closure {f : α → β} {s : set α} {x : α} {A : set β} (h : continuous_within_at f s x) (hx : x ∈ closure s) (hA : s ⊆ f⁻¹' A) : f x ∈ closure A := closure_mono (image_subset_iff.2 hA) (h.mem_closure_image hx) lemma continuous_within_at.image_closure {f : α → β} {s : set α} (hf : ∀ x ∈ closure s, continuous_within_at f s x) : f '' (closure s) ⊆ closure (f '' s) := begin rintros _ ⟨x, hx, rfl⟩, exact (hf x hx).mem_closure_image hx end lemma continuous_on.image_closure {f : α → β} {s : set α} (hf : continuous_on f (closure s)) : f '' (closure s) ⊆ closure (f '' s) := continuous_within_at.image_closure $ λ x hx, (hf x hx).mono subset_closure @[simp] lemma continuous_within_at_singleton {f : α → β} {x : α} : continuous_within_at f {x} x := by simp only [continuous_within_at, nhds_within_singleton, tendsto_pure_nhds] @[simp] lemma continuous_within_at_insert_self {f : α → β} {x : α} {s : set α} : continuous_within_at f (insert x s) x ↔ continuous_within_at f s x := by simp only [← singleton_union, continuous_within_at_union, continuous_within_at_singleton, true_and] alias continuous_within_at_insert_self ↔ _ continuous_within_at.insert_self lemma continuous_within_at.diff_iff {f : α → β} {s t : set α} {x : α} (ht : continuous_within_at f t x) : continuous_within_at f (s \ t) x ↔ continuous_within_at f s x := ⟨λ h, (h.union ht).mono $ by simp only [diff_union_self, subset_union_left], λ h, h.mono (diff_subset _ _)⟩ @[simp] lemma continuous_within_at_diff_self {f : α → β} {s : set α} {x : α} : continuous_within_at f (s \ {x}) x ↔ continuous_within_at f s x := continuous_within_at_singleton.diff_iff theorem is_open_map.continuous_on_image_of_left_inv_on {f : α → β} {s : set α} (h : is_open_map (s.restrict f)) {finv : β → α} (hleft : left_inv_on finv f s) : continuous_on finv (f '' s) := begin refine continuous_on_iff'.2 (λ t ht, ⟨f '' (t ∩ s), _, _⟩), { rw ← image_restrict, exact h _ (ht.preimage continuous_subtype_coe) }, { rw [inter_eq_self_of_subset_left (image_subset f (inter_subset_right t s)), hleft.image_inter'] }, end theorem is_open_map.continuous_on_range_of_left_inverse {f : α → β} (hf : is_open_map f) {finv : β → α} (hleft : function.left_inverse finv f) : continuous_on finv (range f) := begin rw [← image_univ], exact (hf.restrict is_open_univ).continuous_on_image_of_left_inv_on (λ x _, hleft x) end lemma continuous_on.congr_mono {f g : α → β} {s s₁ : set α} (h : continuous_on f s) (h' : eq_on g f s₁) (h₁ : s₁ ⊆ s) : continuous_on g s₁ := begin assume x hx, unfold continuous_within_at, have A := (h x (h₁ hx)).mono h₁, unfold continuous_within_at at A, rw ← h' hx at A, exact A.congr' h'.eventually_eq_nhds_within.symm end lemma continuous_on.congr {f g : α → β} {s : set α} (h : continuous_on f s) (h' : eq_on g f s) : continuous_on g s := h.congr_mono h' (subset.refl _) lemma continuous_on_congr {f g : α → β} {s : set α} (h' : eq_on g f s) : continuous_on g s ↔ continuous_on f s := ⟨λ h, continuous_on.congr h h'.symm, λ h, h.congr h'⟩ lemma continuous_at.continuous_within_at {f : α → β} {s : set α} {x : α} (h : continuous_at f x) : continuous_within_at f s x := continuous_within_at.mono ((continuous_within_at_univ f x).2 h) (subset_univ _) lemma continuous_within_at.continuous_at {f : α → β} {s : set α} {x : α} (h : continuous_within_at f s x) (hs : s ∈ 𝓝 x) : continuous_at f x := begin have : s = univ ∩ s, by rw univ_inter, rwa [this, continuous_within_at_inter hs, continuous_within_at_univ] at h end lemma continuous_on.continuous_at {f : α → β} {s : set α} {x : α} (h : continuous_on f s) (hx : s ∈ 𝓝 x) : continuous_at f x := (h x (mem_of_mem_nhds hx)).continuous_at hx lemma continuous_at.continuous_on {f : α → β} {s : set α} (hcont : ∀ x ∈ s, continuous_at f x) : continuous_on f s := λ x hx, (hcont x hx).continuous_within_at lemma continuous_within_at.comp {g : β → γ} {f : α → β} {s : set α} {t : set β} {x : α} (hg : continuous_within_at g t (f x)) (hf : continuous_within_at f s x) (h : s ⊆ f ⁻¹' t) : continuous_within_at (g ∘ f) s x := hg.tendsto.comp (hf.tendsto_nhds_within h) lemma continuous_within_at.comp' {g : β → γ} {f : α → β} {s : set α} {t : set β} {x : α} (hg : continuous_within_at g t (f x)) (hf : continuous_within_at f s x) : continuous_within_at (g ∘ f) (s ∩ f⁻¹' t) x := hg.comp (hf.mono (inter_subset_left _ _)) (inter_subset_right _ _) lemma continuous_on.comp {g : β → γ} {f : α → β} {s : set α} {t : set β} (hg : continuous_on g t) (hf : continuous_on f s) (h : s ⊆ f ⁻¹' t) : continuous_on (g ∘ f) s := λx hx, continuous_within_at.comp (hg _ (h hx)) (hf x hx) h lemma continuous_on.mono {f : α → β} {s t : set α} (hf : continuous_on f s) (h : t ⊆ s) : continuous_on f t := λx hx, (hf x (h hx)).mono_left (nhds_within_mono _ h) lemma continuous_on.comp' {g : β → γ} {f : α → β} {s : set α} {t : set β} (hg : continuous_on g t) (hf : continuous_on f s) : continuous_on (g ∘ f) (s ∩ f⁻¹' t) := hg.comp (hf.mono (inter_subset_left _ _)) (inter_subset_right _ _) lemma continuous.continuous_on {f : α → β} {s : set α} (h : continuous f) : continuous_on f s := begin rw continuous_iff_continuous_on_univ at h, exact h.mono (subset_univ _) end lemma continuous.continuous_within_at {f : α → β} {s : set α} {x : α} (h : continuous f) : continuous_within_at f s x := h.continuous_at.continuous_within_at lemma continuous.comp_continuous_on {g : β → γ} {f : α → β} {s : set α} (hg : continuous g) (hf : continuous_on f s) : continuous_on (g ∘ f) s := hg.continuous_on.comp hf subset_preimage_univ lemma continuous_on.comp_continuous {g : β → γ} {f : α → β} {s : set β} (hg : continuous_on g s) (hf : continuous f) (hs : ∀ x, f x ∈ s) : continuous (g ∘ f) := begin rw continuous_iff_continuous_on_univ at *, exact hg.comp hf (λ x _, hs x), end lemma continuous_within_at.preimage_mem_nhds_within {f : α → β} {x : α} {s : set α} {t : set β} (h : continuous_within_at f s x) (ht : t ∈ 𝓝 (f x)) : f ⁻¹' t ∈ 𝓝[s] x := h ht lemma set.left_inv_on.map_nhds_within_eq {f : α → β} {g : β → α} {x : β} {s : set β} (h : left_inv_on f g s) (hx : f (g x) = x) (hf : continuous_within_at f (g '' s) (g x)) (hg : continuous_within_at g s x) : map g (𝓝[s] x) = 𝓝[g '' s] (g x) := begin apply le_antisymm, { exact hg.tendsto_nhds_within (maps_to_image _ _) }, { have A : g ∘ f =ᶠ[𝓝[g '' s] (g x)] id, from h.right_inv_on_image.eq_on.eventually_eq_of_mem self_mem_nhds_within, refine le_map_of_right_inverse A _, simpa only [hx] using hf.tendsto_nhds_within (h.maps_to (surj_on_image _ _)) } end lemma function.left_inverse.map_nhds_eq {f : α → β} {g : β → α} {x : β} (h : function.left_inverse f g) (hf : continuous_within_at f (range g) (g x)) (hg : continuous_at g x) : map g (𝓝 x) = 𝓝[range g] (g x) := by simpa only [nhds_within_univ, image_univ] using (h.left_inv_on univ).map_nhds_within_eq (h x) (by rwa image_univ) hg.continuous_within_at lemma continuous_within_at.preimage_mem_nhds_within' {f : α → β} {x : α} {s : set α} {t : set β} (h : continuous_within_at f s x) (ht : t ∈ 𝓝[f '' s] (f x)) : f ⁻¹' t ∈ 𝓝[s] x := h.tendsto_nhds_within (maps_to_image _ _) ht lemma continuous_within_at.congr_of_eventually_eq {f f₁ : α → β} {s : set α} {x : α} (h : continuous_within_at f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : continuous_within_at f₁ s x := by rwa [continuous_within_at, filter.tendsto, hx, filter.map_congr h₁] lemma continuous_within_at.congr {f f₁ : α → β} {s : set α} {x : α} (h : continuous_within_at f s x) (h₁ : ∀y∈s, f₁ y = f y) (hx : f₁ x = f x) : continuous_within_at f₁ s x := h.congr_of_eventually_eq (mem_sets_of_superset self_mem_nhds_within h₁) hx lemma continuous_within_at.congr_mono {f g : α → β} {s s₁ : set α} {x : α} (h : continuous_within_at f s x) (h' : eq_on g f s₁) (h₁ : s₁ ⊆ s) (hx : g x = f x): continuous_within_at g s₁ x := (h.mono h₁).congr h' hx lemma continuous_on_const {s : set α} {c : β} : continuous_on (λx, c) s := continuous_const.continuous_on lemma continuous_within_at_const {b : β} {s : set α} {x : α} : continuous_within_at (λ _:α, b) s x := continuous_const.continuous_within_at lemma continuous_on_id {s : set α} : continuous_on id s := continuous_id.continuous_on lemma continuous_within_at_id {s : set α} {x : α} : continuous_within_at id s x := continuous_id.continuous_within_at lemma continuous_on_open_iff {f : α → β} {s : set α} (hs : is_open s) : continuous_on f s ↔ (∀t, is_open t → is_open (s ∩ f⁻¹' t)) := begin rw continuous_on_iff', split, { assume h t ht, rcases h t ht with ⟨u, u_open, hu⟩, rw [inter_comm, hu], apply is_open.inter u_open hs }, { assume h t ht, refine ⟨s ∩ f ⁻¹' t, h t ht, _⟩, rw [@inter_comm _ s (f ⁻¹' t), inter_assoc, inter_self] } end lemma continuous_on.preimage_open_of_open {f : α → β} {s : set α} {t : set β} (hf : continuous_on f s) (hs : is_open s) (ht : is_open t) : is_open (s ∩ f⁻¹' t) := (continuous_on_open_iff hs).1 hf t ht lemma continuous_on.preimage_closed_of_closed {f : α → β} {s : set α} {t : set β} (hf : continuous_on f s) (hs : is_closed s) (ht : is_closed t) : is_closed (s ∩ f⁻¹' t) := begin rcases continuous_on_iff_is_closed.1 hf t ht with ⟨u, hu⟩, rw [inter_comm, hu.2], apply is_closed.inter hu.1 hs end lemma continuous_on.preimage_interior_subset_interior_preimage {f : α → β} {s : set α} {t : set β} (hf : continuous_on f s) (hs : is_open s) : s ∩ f⁻¹' (interior t) ⊆ s ∩ interior (f⁻¹' t) := calc s ∩ f ⁻¹' (interior t) ⊆ interior (s ∩ f ⁻¹' t) : interior_maximal (inter_subset_inter (subset.refl _) (preimage_mono interior_subset)) (hf.preimage_open_of_open hs is_open_interior) ... = s ∩ interior (f ⁻¹' t) : by rw [interior_inter, hs.interior_eq] lemma continuous_on_of_locally_continuous_on {f : α → β} {s : set α} (h : ∀x∈s, ∃t, is_open t ∧ x ∈ t ∧ continuous_on f (s ∩ t)) : continuous_on f s := begin assume x xs, rcases h x xs with ⟨t, open_t, xt, ct⟩, have := ct x ⟨xs, xt⟩, rwa [continuous_within_at, ← nhds_within_restrict _ xt open_t] at this end lemma continuous_on_open_of_generate_from {β : Type*} {s : set α} {T : set (set β)} {f : α → β} (hs : is_open s) (h : ∀t ∈ T, is_open (s ∩ f⁻¹' t)) : @continuous_on α β _ (topological_space.generate_from T) f s := begin rw continuous_on_open_iff, assume t ht, induction ht with u hu u v Tu Tv hu hv U hU hU', { exact h u hu }, { simp only [preimage_univ, inter_univ], exact hs }, { have : s ∩ f ⁻¹' (u ∩ v) = (s ∩ f ⁻¹' u) ∩ (s ∩ f ⁻¹' v), by { ext x, simp, split, finish, finish }, rw this, exact is_open.inter hu hv }, { rw [preimage_sUnion, inter_bUnion], exact is_open_bUnion hU' }, { exact hs } end lemma continuous_within_at.prod {f : α → β} {g : α → γ} {s : set α} {x : α} (hf : continuous_within_at f s x) (hg : continuous_within_at g s x) : continuous_within_at (λx, (f x, g x)) s x := hf.prod_mk_nhds hg lemma continuous_on.prod {f : α → β} {g : α → γ} {s : set α} (hf : continuous_on f s) (hg : continuous_on g s) : continuous_on (λx, (f x, g x)) s := λx hx, continuous_within_at.prod (hf x hx) (hg x hx) lemma inducing.continuous_on_iff {f : α → β} {g : β → γ} (hg : inducing g) {s : set α} : continuous_on f s ↔ continuous_on (g ∘ f) s := begin simp only [continuous_on_iff_continuous_restrict, restrict_eq], conv_rhs { rw [function.comp.assoc, ← (inducing.continuous_iff hg)] }, end lemma embedding.continuous_on_iff {f : α → β} {g : β → γ} (hg : embedding g) {s : set α} : continuous_on f s ↔ continuous_on (g ∘ f) s := inducing.continuous_on_iff hg.1 lemma continuous_within_at_of_not_mem_closure {f : α → β} {s : set α} {x : α} : x ∉ closure s → continuous_within_at f s x := begin intros hx, rw [mem_closure_iff_nhds_within_ne_bot, ne_bot_iff, not_not] at hx, rw [continuous_within_at, hx], exact tendsto_bot, end lemma continuous_on.piecewise' {s t : set α} {f g : α → β} [∀ a, decidable (a ∈ t)] (hpf : ∀ a ∈ s ∩ frontier t, tendsto f (𝓝[s ∩ t] a) (𝓝 (piecewise t f g a))) (hpg : ∀ a ∈ s ∩ frontier t, tendsto g (𝓝[s ∩ tᶜ] a) (𝓝 (piecewise t f g a))) (hf : continuous_on f $ s ∩ t) (hg : continuous_on g $ s ∩ tᶜ) : continuous_on (piecewise t f g) s := begin intros x hx, by_cases hx' : x ∈ frontier t, { exact (hpf x ⟨hx, hx'⟩).piecewise_nhds_within (hpg x ⟨hx, hx'⟩) }, { rw [← inter_univ s, ← union_compl_self t, inter_union_distrib_left] at hx ⊢, cases hx, { apply continuous_within_at.union, { exact (hf x hx).congr (λ y hy, piecewise_eq_of_mem _ _ _ hy.2) (piecewise_eq_of_mem _ _ _ hx.2) }, { have : x ∉ closure tᶜ, from λ h, hx' ⟨subset_closure hx.2, by rwa closure_compl at h⟩, exact continuous_within_at_of_not_mem_closure (λ h, this (closure_inter_subset_inter_closure _ _ h).2) } }, { apply continuous_within_at.union, { have : x ∉ closure t, from (λ h, hx' ⟨h, (λ (h' : x ∈ interior t), hx.2 (interior_subset h'))⟩), exact continuous_within_at_of_not_mem_closure (λ h, this (closure_inter_subset_inter_closure _ _ h).2) }, { exact (hg x hx).congr (λ y hy, piecewise_eq_of_not_mem _ _ _ hy.2) (piecewise_eq_of_not_mem _ _ _ hx.2) } } } end lemma continuous_on.if' {s : set α} {p : α → Prop} {f g : α → β} [∀ a, decidable (p a)] (hpf : ∀ a ∈ s ∩ frontier {a | p a}, tendsto f (𝓝[s ∩ {a | p a}] a) (𝓝 $ if p a then f a else g a)) (hpg : ∀ a ∈ s ∩ frontier {a | p a}, tendsto g (𝓝[s ∩ {a | ¬p a}] a) (𝓝 $ if p a then f a else g a)) (hf : continuous_on f $ s ∩ {a | p a}) (hg : continuous_on g $ s ∩ {a | ¬p a}) : continuous_on (λ a, if p a then f a else g a) s := hf.piecewise' hpf hpg hg lemma continuous_on.if {α β : Type*} [topological_space α] [topological_space β] {p : α → Prop} [∀ a, decidable (p a)] {s : set α} {f g : α → β} (hp : ∀ a ∈ s ∩ frontier {a | p a}, f a = g a) (hf : continuous_on f $ s ∩ closure {a | p a}) (hg : continuous_on g $ s ∩ closure {a | ¬ p a}) : continuous_on (λa, if p a then f a else g a) s := begin apply continuous_on.if', { rintros a ha, simp only [← hp a ha, if_t_t], apply tendsto_nhds_within_mono_left (inter_subset_inter_right s subset_closure), exact hf a ⟨ha.1, ha.2.1⟩ }, { rintros a ha, simp only [hp a ha, if_t_t], apply tendsto_nhds_within_mono_left (inter_subset_inter_right s subset_closure), rcases ha with ⟨has, ⟨_, ha⟩⟩, rw [← mem_compl_iff, ← closure_compl] at ha, apply hg a ⟨has, ha⟩ }, { exact hf.mono (inter_subset_inter_right s subset_closure) }, { exact hg.mono (inter_subset_inter_right s subset_closure) } end lemma continuous_on.piecewise {s t : set α} {f g : α → β} [∀ a, decidable (a ∈ t)] (ht : ∀ a ∈ s ∩ frontier t, f a = g a) (hf : continuous_on f $ s ∩ closure t) (hg : continuous_on g $ s ∩ closure tᶜ) : continuous_on (piecewise t f g) s := hf.if ht hg lemma continuous_if' {p : α → Prop} {f g : α → β} [∀ a, decidable (p a)] (hpf : ∀ a ∈ frontier {x | p x}, tendsto f (𝓝[{x | p x}] a) (𝓝 $ ite (p a) (f a) (g a))) (hpg : ∀ a ∈ frontier {x | p x}, tendsto g (𝓝[{x | ¬p x}] a) (𝓝 $ ite (p a) (f a) (g a))) (hf : continuous_on f {x | p x}) (hg : continuous_on g {x | ¬p x}) : continuous (λ a, ite (p a) (f a) (g a)) := begin rw continuous_iff_continuous_on_univ, apply continuous_on.if'; simp *; assumption end lemma continuous_if {p : α → Prop} {f g : α → β} [∀ a, decidable (p a)] (hp : ∀ a ∈ frontier {x | p x}, f a = g a) (hf : continuous_on f (closure {x | p x})) (hg : continuous_on g (closure {x | ¬p x})) : continuous (λ a, if p a then f a else g a) := begin rw continuous_iff_continuous_on_univ, apply continuous_on.if; simp; assumption end lemma continuous.if {p : α → Prop} {f g : α → β} [∀ a, decidable (p a)] (hp : ∀ a ∈ frontier {x | p x}, f a = g a) (hf : continuous f) (hg : continuous g) : continuous (λ a, if p a then f a else g a) := continuous_if hp hf.continuous_on hg.continuous_on lemma continuous_piecewise {s : set α} {f g : α → β} [∀ a, decidable (a ∈ s)] (hs : ∀ a ∈ frontier s, f a = g a) (hf : continuous_on f (closure s)) (hg : continuous_on g (closure sᶜ)) : continuous (piecewise s f g) := continuous_if hs hf hg lemma continuous.piecewise {s : set α} {f g : α → β} [∀ a, decidable (a ∈ s)] (hs : ∀ a ∈ frontier s, f a = g a) (hf : continuous f) (hg : continuous g) : continuous (piecewise s f g) := hf.if hs hg lemma is_open.ite' {s s' t : set α} (hs : is_open s) (hs' : is_open s') (ht : ∀ x ∈ frontier t, x ∈ s ↔ x ∈ s') : is_open (t.ite s s') := begin classical, simp only [is_open_iff_continuous_mem, set.ite] at *, convert continuous_piecewise (λ x hx, propext (ht x hx)) hs.continuous_on hs'.continuous_on, ext x, by_cases hx : x ∈ t; simp [hx] end lemma is_open.ite {s s' t : set α} (hs : is_open s) (hs' : is_open s') (ht : s ∩ frontier t = s' ∩ frontier t) : is_open (t.ite s s') := hs.ite' hs' $ λ x hx, by simpa [hx] using ext_iff.1 ht x lemma ite_inter_closure_eq_of_inter_frontier_eq {s s' t : set α} (ht : s ∩ frontier t = s' ∩ frontier t) : t.ite s s' ∩ closure t = s ∩ closure t := by rw [closure_eq_self_union_frontier, inter_union_distrib_left, inter_union_distrib_left, ite_inter_self, ite_inter_of_inter_eq _ ht] lemma ite_inter_closure_compl_eq_of_inter_frontier_eq {s s' t : set α} (ht : s ∩ frontier t = s' ∩ frontier t) : t.ite s s' ∩ closure tᶜ = s' ∩ closure tᶜ := by { rw [← ite_compl, ite_inter_closure_eq_of_inter_frontier_eq], rwa [frontier_compl, eq_comm] } lemma continuous_on_piecewise_ite' {s s' t : set α} {f f' : α → β} [∀ x, decidable (x ∈ t)] (h : continuous_on f (s ∩ closure t)) (h' : continuous_on f' (s' ∩ closure tᶜ)) (H : s ∩ frontier t = s' ∩ frontier t) (Heq : eq_on f f' (s ∩ frontier t)) : continuous_on (t.piecewise f f') (t.ite s s') := begin apply continuous_on.piecewise, { rwa ite_inter_of_inter_eq _ H }, { rwa ite_inter_closure_eq_of_inter_frontier_eq H }, { rwa ite_inter_closure_compl_eq_of_inter_frontier_eq H } end lemma continuous_on_piecewise_ite {s s' t : set α} {f f' : α → β} [∀ x, decidable (x ∈ t)] (h : continuous_on f s) (h' : continuous_on f' s') (H : s ∩ frontier t = s' ∩ frontier t) (Heq : eq_on f f' (s ∩ frontier t)) : continuous_on (t.piecewise f f') (t.ite s s') := continuous_on_piecewise_ite' (h.mono (inter_subset_left _ _)) (h'.mono (inter_subset_left _ _)) H Heq lemma continuous_on_fst {s : set (α × β)} : continuous_on prod.fst s := continuous_fst.continuous_on lemma continuous_within_at_fst {s : set (α × β)} {p : α × β} : continuous_within_at prod.fst s p := continuous_fst.continuous_within_at lemma continuous_on_snd {s : set (α × β)} : continuous_on prod.snd s := continuous_snd.continuous_on lemma continuous_within_at_snd {s : set (α × β)} {p : α × β} : continuous_within_at prod.snd s p := continuous_snd.continuous_within_at
dcca8385d53047b7f9a2c2bb8a3d12d9bbe4ddce
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/algebra/char_p/quotient.lean
286bada40ccd08c3f4bd592fa7f8abe20e9ee876
[ "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
1,455
lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Eric Wieser -/ import algebra.char_p.basic import ring_theory.ideal.quotient /-! # Characteristic of quotients rings -/ universes u v namespace char_p theorem quotient (R : Type u) [comm_ring R] (p : ℕ) [hp1 : fact p.prime] (hp2 : ↑p ∈ nonunits R) : char_p (R ⧸ (ideal.span {p} : ideal R)) p := have hp0 : (p : R ⧸ (ideal.span {p} : ideal R)) = 0, from map_nat_cast (ideal.quotient.mk (ideal.span {p} : ideal R)) p ▸ ideal.quotient.eq_zero_iff_mem.2 (ideal.subset_span $ set.mem_singleton _), ring_char.of_eq $ or.resolve_left ((nat.dvd_prime hp1.1).1 $ ring_char.dvd hp0) $ λ h1, hp2 $ is_unit_iff_dvd_one.2 $ ideal.mem_span_singleton.1 $ ideal.quotient.eq_zero_iff_mem.1 $ @@subsingleton.elim (@@char_p.subsingleton _ $ ring_char.of_eq h1) _ _ /-- If an ideal does not contain any coercions of natural numbers other than zero, then its quotient inherits the characteristic of the underlying ring. -/ lemma quotient' {R : Type*} [comm_ring R] (p : ℕ) [char_p R p] (I : ideal R) (h : ∀ x : ℕ, (x : R) ∈ I → (x : R) = 0) : char_p (R ⧸ I) p := ⟨λ x, begin rw [←cast_eq_zero_iff R p x, ←map_nat_cast (ideal.quotient.mk I)], refine quotient.eq'.trans (_ : ↑x - 0 ∈ I ↔ _), rw sub_zero, exact ⟨h x, λ h', h'.symm ▸ I.zero_mem⟩, end⟩ end char_p
8d55a017a87d614557ecc95139a8fd31d5e46fcb
b3fced0f3ff82d577384fe81653e47df68bb2fa1
/src/ring_theory/power_series.lean
8d03fea7c30d7db8beaccc95ee8390b327f91cac
[ "Apache-2.0" ]
permissive
ratmice/mathlib
93b251ef5df08b6fd55074650ff47fdcc41a4c75
3a948a6a4cd5968d60e15ed914b1ad2f4423af8d
refs/heads/master
1,599,240,104,318
1,572,981,183,000
1,572,981,183,000
219,830,178
0
0
Apache-2.0
1,572,980,897,000
1,572,980,896,000
null
UTF-8
Lean
false
false
56,770
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.finsupp order.complete_lattice algebra.ordered_group data.mv_polynomial import algebra.order_functions import ring_theory.ideal_operations /-! # 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 [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.-/ @[extensionality] 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 @[simp] 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 1 else 0) * (coeff α j) φ = 0, intros i j hij h, rw [if_neg, zero_mul], 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, rw 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 @[simp] 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 @[simp] 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 @[simp] 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] 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 @[simp] 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 σ α) := { to_fun := C σ α, commutes' := λ _ _, mul_comm _ _, smul_def' := λ c p, rfl, .. 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 t, simp only [nat.add_sub_cancel_left, add_comm, finsupp.add_apply, add_right_inj, finsupp.nat_sub_apply] }, { exact zero_mul _ } }, { classical, contrapose! H, ext t, by_cases hst : s = t, { subst t, simpa using nat.add_sub_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_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 : mv_power_series σ α → mv_power_series σ β) := { map_one := (map σ f).map_one, map_mul := (map σ f).map_mul, map_add := (map σ f).map_add, map_nonunit := 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_one φ (inv_of_unit φ c) (mul_inv_of_unit φ c hc) end } end local_ring section discrete_field variables [discrete_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] 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 discrete_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, elim_cast] lemma coeff_coe (φ : mv_polynomial σ α) (n : σ →₀ ℕ) : mv_power_series.coeff α n ↑φ = coeff n φ := rfl @[simp, elim_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, elim_cast] lemma coe_zero : ((0 : mv_polynomial σ α) : mv_power_series σ α) = 0 := rfl @[simp, elim_cast] lemma coe_one : ((1 : mv_polynomial σ α) : mv_power_series σ α) = 1 := coe_monomial _ _ @[simp, elim_cast] lemma coe_add (φ ψ : mv_polynomial σ α) : ((φ + ψ : mv_polynomial σ α) : mv_power_series σ α) = φ + ψ := rfl @[simp, elim_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, elim_cast] lemma coe_C (a : α) : ((C a : mv_polynomial σ α) : mv_power_series σ α) = mv_power_series.C σ α a := coe_monomial _ _ @[simp, elim_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 [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.-/ @[extensionality] 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 @[simp] 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] @[simp] lemma monomial_zero_eq_C_apply (a : α) : monomial α 0 a = C α a := by rw [monomial_zero_eq_C]; refl 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] @[simp] 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] @[simp] 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 } @[simp] 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 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 _ /-- 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 α)) = is_ring_hom.ker (constant_coeff α), { rw this, exact is_ring_hom.ker_is_prime _ }, apply ideal.ext, intro φ, rw [is_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 discrete_field variables [discrete_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] 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 discrete_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 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 [lattice.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 [lattice.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, lattice.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, elim_cast] lemma coeff_coe (φ : polynomial α) (n) : power_series.coeff α n φ = coeff φ n := congr_arg (coeff φ) (finsupp.single_eq_same) @[reducible] def monomial (n : ℕ) (a : α) : polynomial α := single n a @[simp, elim_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, elim_cast] lemma coe_zero : ((0 : polynomial α) : power_series α) = 0 := rfl @[simp, elim_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, elim_cast] lemma coe_add (φ ψ : polynomial α) : ((φ + ψ : polynomial α) : power_series α) = φ + ψ := rfl @[simp, elim_cast] lemma coe_mul (φ ψ : polynomial α) : ((φ * ψ : polynomial α) : power_series α) = φ * ψ := power_series.ext $ λ n, by simp only [coeff_coe, power_series.coeff_mul, coeff_mul] @[simp, elim_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, elim_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
618a0c0e59207602049c134dd81b60221f89c230
9dc8cecdf3c4634764a18254e94d43da07142918
/src/measure_theory/function/locally_integrable.lean
68bd275ea26476fce224bacc3f93d1e7ed143846
[ "Apache-2.0" ]
permissive
jcommelin/mathlib
d8456447c36c176e14d96d9e76f39841f69d2d9b
ee8279351a2e434c2852345c51b728d22af5a156
refs/heads/master
1,664,782,136,488
1,663,638,983,000
1,663,638,983,000
132,563,656
0
0
Apache-2.0
1,663,599,929,000
1,525,760,539,000
Lean
UTF-8
Lean
false
false
8,051
lean
/- Copyright (c) 2022 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import measure_theory.integral.integrable_on /-! # Locally integrable functions A function is called *locally integrable* (`measure_theory.locally_integrable`) if it is integrable on every compact subset of its domain. This file contains properties of locally integrable functions and of integrability results on compact sets. ## Main statements * `continuous.locally_integrable`: A continuous function is locally integrable. -/ open measure_theory measure_theory.measure set function topological_space open_locale topological_space interval variables {X Y E : Type*} [measurable_space X] [topological_space X] variables [measurable_space Y] [topological_space Y] variables [normed_add_comm_group E] {f : X → E} {μ : measure X} namespace measure_theory /-- A function `f : X → E` is locally integrable if it is integrable on all compact sets. See `measure_theory.locally_integrable_iff` for the justification of this name. -/ def locally_integrable (f : X → E) (μ : measure X . volume_tac) : Prop := ∀ ⦃K⦄, is_compact K → integrable_on f K μ lemma integrable.locally_integrable (hf : integrable f μ) : locally_integrable f μ := λ K hK, hf.integrable_on lemma locally_integrable.ae_strongly_measurable [sigma_compact_space X] (hf : locally_integrable f μ) : ae_strongly_measurable f μ := begin rw [← @restrict_univ _ _ μ, ← Union_compact_covering, ae_strongly_measurable_Union_iff], exact λ i, (hf $ is_compact_compact_covering X i).ae_strongly_measurable end lemma locally_integrable_iff [locally_compact_space X] : locally_integrable f μ ↔ ∀ x : X, ∃ U ∈ 𝓝 x, integrable_on f U μ := begin refine ⟨λ hf x, _, λ hf K hK, _⟩, { obtain ⟨K, hK, h2K⟩ := exists_compact_mem_nhds x, exact ⟨K, h2K, hf hK⟩ }, { refine is_compact.induction_on hK integrable_on_empty (λ s t hst h, h.mono_set hst) (λ s t hs ht, integrable_on_union.mpr ⟨hs, ht⟩) (λ x hx, _), obtain ⟨K, hK, h2K⟩ := hf x, exact ⟨K, nhds_within_le_nhds hK, h2K⟩ } end section real variables [opens_measurable_space X] {A K : set X} {g g' : X → ℝ} lemma integrable_on.mul_continuous_on_of_subset (hg : integrable_on g A μ) (hg' : continuous_on g' K) (hA : measurable_set A) (hK : is_compact K) (hAK : A ⊆ K) : integrable_on (λ x, g x * g' x) A μ := begin rcases is_compact.exists_bound_of_continuous_on hK hg' with ⟨C, hC⟩, rw [integrable_on, ← mem_ℒp_one_iff_integrable] at hg ⊢, have : ∀ᵐ x ∂(μ.restrict A), ∥g x * g' x∥ ≤ C * ∥g x∥, { filter_upwards [ae_restrict_mem hA] with x hx, rw [real.norm_eq_abs, abs_mul, mul_comm, real.norm_eq_abs], apply mul_le_mul_of_nonneg_right (hC x (hAK hx)) (abs_nonneg _), }, exact mem_ℒp.of_le_mul hg (hg.ae_strongly_measurable.ae_measurable.mul ((hg'.mono hAK).ae_measurable hA)).ae_strongly_measurable this, end lemma integrable_on.mul_continuous_on [t2_space X] (hg : integrable_on g K μ) (hg' : continuous_on g' K) (hK : is_compact K) : integrable_on (λ x, g x * g' x) K μ := hg.mul_continuous_on_of_subset hg' hK.measurable_set hK (subset.refl _) lemma integrable_on.continuous_on_mul_of_subset (hg : continuous_on g K) (hg' : integrable_on g' A μ) (hK : is_compact K) (hA : measurable_set A) (hAK : A ⊆ K) : integrable_on (λ x, g x * g' x) A μ := by simpa [mul_comm] using hg'.mul_continuous_on_of_subset hg hA hK hAK lemma integrable_on.continuous_on_mul [t2_space X] (hg : continuous_on g K) (hg' : integrable_on g' K μ) (hK : is_compact K) : integrable_on (λ x, g x * g' x) K μ := integrable_on.continuous_on_mul_of_subset hg hg' hK hK.measurable_set subset.rfl end real end measure_theory open measure_theory /-- If a function is integrable at `𝓝[s] x` for each point `x` of a compact set `s`, then it is integrable on `s`. -/ lemma is_compact.integrable_on_of_nhds_within {K : set X} (hK : is_compact K) (hf : ∀ x ∈ K, integrable_at_filter f (𝓝[K] x) μ) : integrable_on f K μ := is_compact.induction_on hK integrable_on_empty (λ s t hst ht, ht.mono_set hst) (λ s t hs ht, hs.union ht) hf section borel variables [opens_measurable_space X] [metrizable_space X] [is_locally_finite_measure μ] variables {K : set X} {a b : X} /-- A function `f` continuous on a compact set `K` is integrable on this set with respect to any locally finite measure. -/ lemma continuous_on.integrable_on_compact (hK : is_compact K) (hf : continuous_on f K) : integrable_on f K μ := begin letI := metrizable_space_metric X, apply hK.integrable_on_of_nhds_within (λ x hx, _), exact hf.integrable_at_nhds_within_of_is_separable hK.measurable_set hK.is_separable hx, end /-- A continuous function `f` is locally integrable with respect to any locally finite measure. -/ lemma continuous.locally_integrable (hf : continuous f) : locally_integrable f μ := λ s hs, hf.continuous_on.integrable_on_compact hs lemma continuous_on.integrable_on_Icc [preorder X] [compact_Icc_space X] (hf : continuous_on f (Icc a b)) : integrable_on f (Icc a b) μ := hf.integrable_on_compact is_compact_Icc lemma continuous.integrable_on_Icc [preorder X] [compact_Icc_space X] (hf : continuous f) : integrable_on f (Icc a b) μ := hf.locally_integrable is_compact_Icc lemma continuous.integrable_on_Ioc [preorder X] [compact_Icc_space X] (hf : continuous f) : integrable_on f (Ioc a b) μ := hf.integrable_on_Icc.mono_set Ioc_subset_Icc_self lemma continuous_on.integrable_on_interval [linear_order X] [compact_Icc_space X] (hf : continuous_on f [a, b]) : integrable_on f [a, b] μ := hf.integrable_on_Icc lemma continuous.integrable_on_interval [linear_order X] [compact_Icc_space X] (hf : continuous f) : integrable_on f [a, b] μ := hf.integrable_on_Icc lemma continuous.integrable_on_interval_oc [linear_order X] [compact_Icc_space X] (hf : continuous f) : integrable_on f (Ι a b) μ := hf.integrable_on_Ioc /-- A continuous function with compact support is integrable on the whole space. -/ lemma continuous.integrable_of_has_compact_support (hf : continuous f) (hcf : has_compact_support f) : integrable f μ := (integrable_on_iff_integable_of_support_subset (subset_tsupport f) measurable_set_closure).mp $ hf.locally_integrable hcf end borel section monotone variables [borel_space X] [metrizable_space X] [conditionally_complete_linear_order X] [conditionally_complete_linear_order E] [order_topology X] [order_topology E] [second_countable_topology E] [is_locally_finite_measure μ] {s : set X} lemma monotone_on.integrable_on_compact (hs : is_compact s) (hmono : monotone_on f s) : integrable_on f s μ := begin borelize E, obtain rfl | h := s.eq_empty_or_nonempty, { exact integrable_on_empty }, have hbelow : bdd_below (f '' s) := ⟨f (Inf s), λ x ⟨y, hy, hyx⟩, hyx ▸ hmono (hs.Inf_mem h) hy (cInf_le hs.bdd_below hy)⟩, have habove : bdd_above (f '' s) := ⟨f (Sup s), λ x ⟨y, hy, hyx⟩, hyx ▸ hmono hy (hs.Sup_mem h) (le_cSup hs.bdd_above hy)⟩, have : metric.bounded (f '' s) := metric.bounded_of_bdd_above_of_bdd_below habove hbelow, rcases bounded_iff_forall_norm_le.mp this with ⟨C, hC⟩, refine integrable.mono' (continuous_const.locally_integrable hs) (ae_measurable_restrict_of_monotone_on hs.measurable_set hmono).ae_strongly_measurable ((ae_restrict_iff' hs.measurable_set).mpr $ ae_of_all _ $ λ y hy, hC (f y) (mem_image_of_mem f hy)), end lemma antitone_on.integrable_on_compact (hs : is_compact s) (hanti : antitone_on f s) : integrable_on f s μ := hanti.dual_right.integrable_on_compact hs lemma monotone.locally_integrable (hmono : monotone f) : locally_integrable f μ := λ s hs, (hmono.monotone_on _).integrable_on_compact hs lemma antitone.locally_integrable (hanti : antitone f) : locally_integrable f μ := hanti.dual_right.locally_integrable end monotone
6e3ebd0151837f8069979dead6beeaa3d415043d
618003631150032a5676f229d13a079ac875ff77
/test/wlog.lean
b225dd563431ab9b813d941abfe5246344d6ca63
[ "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
3,111
lean
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import tactic.wlog section wlog example {x y : ℕ} (a : x = 1) : true := begin suffices : false, trivial, wlog h : x = y, { guard_target x = y ∨ y = x, admit }, { guard_hyp h := x = y, guard_hyp a := x = 1, admit } end example {x y : ℕ} : true := begin suffices : false, trivial, wlog h : x ≤ y, { guard_hyp h := x ≤ y, guard_target false, admit } end example {x y z : ℕ} : true := begin suffices : false, trivial, wlog : x ≤ y + z using x y, { guard_target x ≤ y + z ∨ y ≤ x + z, admit }, { guard_hyp case := x ≤ y + z, guard_target false, admit }, end example {x : ℕ} (S₀ S₁ : set ℕ) (P : ℕ → Prop) (h : x ∈ S₀ ∪ S₁) : true := begin suffices : false, trivial, wlog h' : x ∈ S₀ using S₀ S₁, { guard_target x ∈ S₀ ∨ x ∈ S₁, admit }, { guard_hyp h := x ∈ S₀ ∪ S₁, guard_hyp h' := x ∈ S₀, admit } end example {n m i : ℕ} {p : ℕ → ℕ → ℕ → Prop} : true := begin suffices : false, trivial, wlog : p n m i using [n m i, n i m, i n m], { guard_target p n m i ∨ p n i m ∨ p i n m, admit }, { guard_hyp case := p n m i, admit } end example {n m i : ℕ} {p : ℕ → Prop} : true := begin suffices : false, trivial, wlog : p n using [n m i, m n i, i n m], { guard_target p n ∨ p m ∨ p i, admit }, { guard_hyp case := p n, admit } end example {n m i : ℕ} {p : ℕ → ℕ → Prop} {q : ℕ → ℕ → ℕ → Prop} : true := begin suffices : q n m i, trivial, have h : p n i ∨ p i m ∨ p m i, from sorry, wlog : p n i := h using n m i, { guard_hyp h := p n i, guard_target q n m i, admit }, { guard_hyp h := p i m, guard_hyp this := q i m n, guard_target q n m i, admit }, { guard_hyp h := p m i, guard_hyp this := q m i n, guard_target q n m i, admit }, end example (X : Type) (A B C : set X) : A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) := begin ext x, split, { intro hyp, cases hyp, wlog x_in : x ∈ B using B C, { assumption }, { exact or.inl ⟨hyp_left, x_in⟩ } }, { intro hyp, wlog x_in : x ∈ A ∩ B using B C, { assumption }, { exact ⟨x_in.left, or.inl x_in.right⟩ } } end example (X : Type) (A B C : set X) : A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) := begin ext x, split, { intro hyp, wlog x_in : x ∈ B := hyp.2 using B C, { exact or.inl ⟨hyp.1, x_in⟩ } }, { intro hyp, wlog x_in : x ∈ A ∩ B := hyp using B C, { exact ⟨x_in.left, or.inl x_in.right⟩ } } end example (X : Type) (A B C : set X) : A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) := begin ext x, split, { intro hyp, cases hyp, wlog x_in : x ∈ B := hyp_right using B C, { exact or.inl ⟨hyp_left, x_in⟩ }, }, { intro hyp, wlog x_in : x ∈ A ∩ B := hyp using B C, { exact ⟨x_in.left, or.inl x_in.right⟩ } } end end wlog
74c01473f4f62011d70f73a31459f0df2fe1829c
4bcaca5dc83d49803f72b7b5920b75b6e7d9de2d
/src/Lean/Parser/Command.lean
82a797c355645cb53cb276fb09ff2de8873197bd
[ "Apache-2.0" ]
permissive
subfish-zhou/leanprover-zh_CN.github.io
30b9fba9bd790720bd95764e61ae796697d2f603
8b2985d4a3d458ceda9361ac454c28168d920d3f
refs/heads/master
1,689,709,967,820
1,632,503,056,000
1,632,503,056,000
409,962,097
1
0
null
null
null
null
UTF-8
Lean
false
false
10,972
lean
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Sebastian Ullrich -/ import Lean.Parser.Term import Lean.Parser.Do namespace Lean namespace Parser /-- Syntax quotation for terms and (lists of) commands. We prefer terms, so ambiguous quotations like `` `($x $y) `` will be parsed as an application, not two commands. Use `` `($x:command $y:command) `` instead. Multiple command will be put in a `` `null `` node, but a single command will not (so that you can directly match against a quotation in a command kind's elaborator). -/ -- TODO: use two separate quotation parsers with parser priorities instead @[builtinTermParser] def Term.quot := leading_parser "`(" >> incQuotDepth (termParser <|> many1Unbox commandParser) >> ")" @[builtinTermParser] def Term.precheckedQuot := leading_parser "`" >> Term.quot namespace Command -- A mutual block may be broken in different cliques, we identify them using an `ident` (an element of the clique) def terminationByMany := leading_parser atomic (lookahead (ident >> " => ")) >> many1Indent (group (ppLine >> ident >> " => " >> termParser >> optional ";")) -- Simpler syntax for mutual blocks containing single clique that requires well-founded recursion. def terminationBy1 := leading_parser termParser def terminationBy := leading_parser "termination_by " >> (terminationByMany <|> terminationBy1) @[builtinCommandParser] def moduleDoc := leading_parser ppDedent $ "/-!" >> commentBody >> ppLine def namedPrio := leading_parser (atomic ("(" >> nonReservedSymbol "priority") >> " := " >> priorityParser >> ")") def optNamedPrio := optional namedPrio def «private» := leading_parser "private " def «protected» := leading_parser "protected " def visibility := «private» <|> «protected» def «noncomputable» := leading_parser "noncomputable " def «unsafe» := leading_parser "unsafe " def «partial» := leading_parser "partial " def «nonrec» := leading_parser "nonrec " def declModifiers (inline : Bool) := leading_parser optional docComment >> optional (Term.«attributes» >> if inline then skip else ppDedent ppLine) >> optional visibility >> optional «noncomputable» >> optional «unsafe» >> optional («partial» <|> «nonrec») def declId := leading_parser ident >> optional (".{" >> sepBy1 ident ", " >> "}") def declSig := leading_parser many (ppSpace >> (Term.simpleBinderWithoutType <|> Term.bracketedBinder)) >> Term.typeSpec def optDeclSig := leading_parser many (ppSpace >> (Term.simpleBinderWithoutType <|> Term.bracketedBinder)) >> Term.optType def declValSimple := leading_parser " :=\n" >> termParser >> optional Term.whereDecls def declValEqns := leading_parser Term.matchAltsWhereDecls def declVal := declValSimple <|> declValEqns <|> Term.whereDecls def «abbrev» := leading_parser "abbrev " >> declId >> optDeclSig >> declVal def optDefDeriving := optional (atomic ("deriving " >> notSymbol "instance") >> sepBy1 ident ", ") def «def» := leading_parser "def " >> declId >> optDeclSig >> declVal >> optDefDeriving >> optional terminationBy def «theorem» := leading_parser "theorem " >> declId >> declSig >> declVal >> optional terminationBy def «constant» := leading_parser "constant " >> declId >> declSig >> optional declValSimple def «instance» := leading_parser Term.attrKind >> "instance " >> optNamedPrio >> optional declId >> declSig >> declVal >> optional terminationBy def «axiom» := leading_parser "axiom " >> declId >> declSig def «example» := leading_parser "example " >> declSig >> declVal def inferMod := leading_parser atomic (symbol "{" >> "}") def ctor := leading_parser "\n| " >> declModifiers true >> ident >> optional inferMod >> optDeclSig def derivingClasses := sepBy1 (group (ident >> optional (" with " >> Term.structInst))) ", " def optDeriving := leading_parser optional (atomic ("deriving " >> notSymbol "instance") >> derivingClasses) def «inductive» := leading_parser "inductive " >> declId >> optDeclSig >> optional (symbol ":=" <|> "where") >> many ctor >> optDeriving def classInductive := leading_parser atomic (group (symbol "class " >> "inductive ")) >> declId >> optDeclSig >> optional (symbol ":=" <|> "where") >> many ctor >> optDeriving def structExplicitBinder := leading_parser atomic (declModifiers true >> "(") >> many1 ident >> optional inferMod >> optDeclSig >> optional (Term.binderTactic <|> Term.binderDefault) >> ")" def structImplicitBinder := leading_parser atomic (declModifiers true >> "{") >> many1 ident >> optional inferMod >> declSig >> "}" def structInstBinder := leading_parser atomic (declModifiers true >> "[") >> many1 ident >> optional inferMod >> declSig >> "]" def structSimpleBinder := leading_parser atomic (declModifiers true >> ident) >> optional inferMod >> optDeclSig >> optional (Term.binderTactic <|> Term.binderDefault) def structFields := leading_parser manyIndent (ppLine >> checkColGe >>(structExplicitBinder <|> structImplicitBinder <|> structInstBinder <|> structSimpleBinder)) def structCtor := leading_parser atomic (declModifiers true >> ident >> optional inferMod >> " :: ") def structureTk := leading_parser "structure " def classTk := leading_parser "class " def «extends» := leading_parser " extends " >> sepBy1 termParser ", " def «structure» := leading_parser (structureTk <|> classTk) >> declId >> many Term.bracketedBinder >> optional «extends» >> Term.optType >> optional ((symbol " := " <|> " where ") >> optional structCtor >> structFields) >> optDeriving @[builtinCommandParser] def declaration := leading_parser declModifiers false >> («abbrev» <|> «def» <|> «theorem» <|> «constant» <|> «instance» <|> «axiom» <|> «example» <|> «inductive» <|> classInductive <|> «structure») @[builtinCommandParser] def «deriving» := leading_parser "deriving " >> "instance " >> derivingClasses >> " for " >> sepBy1 ident ", " @[builtinCommandParser] def «section» := leading_parser "section " >> optional ident @[builtinCommandParser] def «namespace» := leading_parser "namespace " >> ident @[builtinCommandParser] def «end» := leading_parser "end " >> optional ident @[builtinCommandParser] def «variable» := leading_parser "variable" >> many1 Term.bracketedBinder @[builtinCommandParser] def «universe» := leading_parser "universe " >> many1 ident @[builtinCommandParser] def check := leading_parser "#check " >> termParser @[builtinCommandParser] def check_failure := leading_parser "#check_failure " >> termParser -- Like `#check`, but succeeds only if term does not type check @[builtinCommandParser] def reduce := leading_parser "#reduce " >> termParser @[builtinCommandParser] def eval := leading_parser "#eval " >> termParser @[builtinCommandParser] def synth := leading_parser "#synth " >> termParser @[builtinCommandParser] def exit := leading_parser "#exit" @[builtinCommandParser] def print := leading_parser "#print " >> (ident <|> strLit) @[builtinCommandParser] def printAxioms := leading_parser "#print " >> nonReservedSymbol "axioms " >> ident @[builtinCommandParser] def «resolve_name» := leading_parser "#resolve_name " >> ident @[builtinCommandParser] def «init_quot» := leading_parser "init_quot" def optionValue := nonReservedSymbol "true" <|> nonReservedSymbol "false" <|> strLit <|> numLit @[builtinCommandParser] def «set_option» := leading_parser "set_option " >> ident >> ppSpace >> optionValue def eraseAttr := leading_parser "-" >> rawIdent @[builtinCommandParser] def «attribute» := leading_parser "attribute " >> "[" >> sepBy1 (eraseAttr <|> Term.attrInstance) ", " >> "] " >> many1 ident @[builtinCommandParser] def «export» := leading_parser "export " >> ident >> "(" >> many1 ident >> ")" def openHiding := leading_parser atomic (ident >> "hiding") >> many1 (checkColGt >> ident) def openRenamingItem := leading_parser ident >> unicodeSymbol "→" "->" >> checkColGt >> ident def openRenaming := leading_parser atomic (ident >> "renaming") >> sepBy1 openRenamingItem ", " def openOnly := leading_parser atomic (ident >> "(") >> many1 ident >> ")" def openSimple := leading_parser many1 (checkColGt >> ident) def openScoped := leading_parser "scoped " >> many1 (checkColGt >> ident) def openDecl := openHiding <|> openRenaming <|> openOnly <|> openSimple <|> openScoped @[builtinCommandParser] def «open» := leading_parser withPosition ("open " >> openDecl) @[builtinCommandParser] def «mutual» := leading_parser "mutual " >> many1 (ppLine >> notSymbol "end" >> commandParser) >> ppDedent (ppLine >> "end") >> optional terminationBy @[builtinCommandParser] def «initialize» := leading_parser optional visibility >> "initialize " >> optional (atomic (ident >> Term.typeSpec >> Term.leftArrow)) >> Term.doSeq @[builtinCommandParser] def «builtin_initialize» := leading_parser optional visibility >> "builtin_initialize " >> optional (atomic (ident >> Term.typeSpec >> Term.leftArrow)) >> Term.doSeq @[builtinCommandParser] def «in» := trailing_parser withOpen (" in " >> commandParser) /- This is an auxiliary command for generation constructor injectivity theorems for inductive types defined at `Prelude.lean`. It is meant for bootstrapping purposes only. -/ @[builtinCommandParser] def genInjectiveTheorems := leading_parser "gen_injective_theorems% " >> ident @[runBuiltinParserAttributeHooks] abbrev declModifiersF := declModifiers false @[runBuiltinParserAttributeHooks] abbrev declModifiersT := declModifiers true builtin_initialize register_parser_alias "declModifiers" declModifiersF register_parser_alias "nestedDeclModifiers" declModifiersT register_parser_alias declId register_parser_alias declSig register_parser_alias declVal register_parser_alias optDeclSig register_parser_alias openDecl end Command namespace Term @[builtinTermParser] def «open» := leading_parser:leadPrec "open " >> Command.openDecl >> withOpenDecl (" in " >> termParser) @[builtinTermParser] def «set_option» := leading_parser:leadPrec "set_option " >> ident >> ppSpace >> Command.optionValue >> " in " >> termParser end Term namespace Tactic @[builtinTacticParser] def «open» := leading_parser:leadPrec "open " >> Command.openDecl >> withOpenDecl (" in " >> tacticSeq) @[builtinTacticParser] def «set_option» := leading_parser:leadPrec "set_option " >> ident >> ppSpace >> Command.optionValue >> " in " >> tacticSeq end Tactic end Parser end Lean
c4274ad56005b09c4bca5181b460de999f70184b
ee8cdbabf07f77e7be63a449b8483ce308d37218
/lean/src/valid/mathd-algebra-28.lean
fc3aea02e6e3cdf7c6f766c7921f16f38a9858e0
[ "MIT", "Apache-2.0" ]
permissive
zeta1999/miniF2F
6d66c75d1c18152e224d07d5eed57624f731d4b7
c1ba9629559c5273c92ec226894baa0c1ce27861
refs/heads/main
1,681,897,460,642
1,620,646,361,000
1,620,646,361,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
308
lean
/- Copyright (c) 2021 OpenAI. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kunhao Zheng -/ import data.real.basic example (c : ℝ) (f : ℝ → ℝ) (h₀ : ∀ x, f x = 2 * x ^ 2 + 5 * x + c) (h₁ : ∃ x, f x ≤ 0) : c ≤ 25/8 := begin sorry end
9d2c3f573171f741fb75acfe9b14b3ca5de2b5a9
df561f413cfe0a88b1056655515399c546ff32a5
/6-advanced-addition-world/l9.lean
419a5350ee7bde6335086b2243f61ea3ee1a972c
[]
no_license
nicholaspun/natural-number-game-solutions
31d5158415c6f582694680044c5c6469032c2a06
1e2aed86d2e76a3f4a275c6d99e795ad30cf6df0
refs/heads/main
1,675,123,625,012
1,607,633,548,000
1,607,633,548,000
318,933,860
3
1
null
null
null
null
UTF-8
Lean
false
false
93
lean
theorem succ_ne_zero (a : mynat) : succ a ≠ 0 := begin symmetry, exact zero_ne_succ a, end
4f183af41a366b45404594c54acea95246846fab
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/algebra/continued_fractions/basic.lean
c44bfc93f32a1f040b4cfbbdadbe02e70d4d2115
[]
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
14,692
lean
/- Copyright (c) 2019 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.seq.seq import Mathlib.algebra.field import Mathlib.PostPort universes u_1 l u_2 namespace Mathlib /-! # Basic Definitions/Theorems for Continued Fractions ## Summary We define generalised, simple, and regular continued fractions and functions to evaluate their convergents. We follow the naming conventions from Wikipedia and [wall2018analytic], Chapter 1. ## Main definitions 1. Generalised continued fractions (gcfs) 2. Simple continued fractions (scfs) 3. (Regular) continued fractions ((r)cfs) 4. Computation of convergents using the recurrence relation in `convergents`. 5. Computation of convergents by directly evaluating the fraction described by the gcf in `convergents'`. ## Implementation notes 1. The most commonly used kind of continued fractions in the literature are regular continued fractions. We hence just call them `continued_fractions` in the library. 2. We use sequences from `data.seq` to encode potentially infinite sequences. ## References - <https://en.wikipedia.org/wiki/Generalized_continued_fraction> - [Wall, H.S., *Analytic Theory of Continued Fractions*][wall2018analytic] ## Tags numerics, number theory, approximations, fractions -/ -- Fix a carrier `α`. /-- We collect a partial numerator `aᵢ` and partial denominator `bᵢ` in a pair `⟨aᵢ,bᵢ⟩`. -/ structure generalized_continued_fraction.pair (α : Type u_1) where a : α b : α /- Interlude: define some expected coercions and instances. -/ namespace generalized_continued_fraction.pair /-- Make a `gcf.pair` printable. -/ protected instance has_repr {α : Type u_1} [has_repr α] : has_repr (pair α) := sorry /-- Maps a function `f` on both components of a given pair. -/ def map {α : Type u_1} {β : Type u_2} (f : α → β) (gp : pair α) : pair β := mk (f (a gp)) (f (b gp)) /-! Interlude: define some expected coercions. -/ /- Fix another type `β` which we will convert to. -/ /-- Coerce a pair by elementwise coercion. -/ protected instance has_coe_to_generalized_continued_fraction_pair {α : Type u_1} {β : Type u_2} [has_coe α β] : has_coe (pair α) (pair β) := has_coe.mk (map coe) @[simp] theorem coe_to_generalized_continued_fraction_pair {α : Type u_1} {β : Type u_2} [has_coe α β] {a : α} {b : α} : ↑(mk a b) = mk ↑a ↑b := rfl end generalized_continued_fraction.pair /-- A *generalised continued fraction* (gcf) is a potentially infinite expression of the form a₀ h + --------------------------- a₁ b₀ + -------------------- a₂ b₁ + -------------- a₃ b₂ + -------- b₃ + ... where `h` is called the *head term* or *integer part*, the `aᵢ` are called the *partial numerators* and the `bᵢ` the *partial denominators* of the gcf. We store the sequence of partial numerators and denominators in a sequence of generalized_continued_fraction.pairs `s`. For convenience, one often writes `[h; (a₀, b₀), (a₁, b₁), (a₂, b₂),...]`. -/ structure generalized_continued_fraction (α : Type u_1) where h : α s : seq (generalized_continued_fraction.pair α) namespace generalized_continued_fraction /-- Constructs a generalized continued fraction without fractional part. -/ def of_integer {α : Type u_1} (a : α) : generalized_continued_fraction α := mk a seq.nil protected instance inhabited {α : Type u_1} [Inhabited α] : Inhabited (generalized_continued_fraction α) := { default := of_integer Inhabited.default } /-- Returns the sequence of partial numerators `aᵢ` of `g`. -/ /-- Returns the sequence of partial denominators `bᵢ` of `g`. -/ def partial_numerators {α : Type u_1} (g : generalized_continued_fraction α) : seq α := seq.map pair.a (s g) def partial_denominators {α : Type u_1} (g : generalized_continued_fraction α) : seq α := seq.map pair.b (s g) /-- A gcf terminated at position `n` if its sequence terminates at position `n`. -/ def terminated_at {α : Type u_1} (g : generalized_continued_fraction α) (n : ℕ) := seq.terminated_at (s g) n /-- It is decidable whether a gcf terminated at a given position. -/ protected instance terminated_at_decidable {α : Type u_1} (g : generalized_continued_fraction α) (n : ℕ) : Decidable (terminated_at g n) := eq.mpr sorry (seq.terminated_at_decidable (s g) n) /-- A gcf terminates if its sequence terminates. -/ def terminates {α : Type u_1} (g : generalized_continued_fraction α) := seq.terminates (s g) /-! Interlude: define some expected coercions. -/ /- Fix another type `β` which we will convert to. -/ /-- Coerce a gcf by elementwise coercion. -/ protected instance has_coe_to_generalized_continued_fraction {α : Type u_1} {β : Type u_2} [has_coe α β] : has_coe (generalized_continued_fraction α) (generalized_continued_fraction β) := has_coe.mk fun (g : generalized_continued_fraction α) => mk (↑(h g)) (seq.map coe (s g)) @[simp] theorem coe_to_generalized_continued_fraction {α : Type u_1} {β : Type u_2} [has_coe α β] {g : generalized_continued_fraction α} : ↑g = mk (↑(h g)) (seq.map coe (s g)) := rfl end generalized_continued_fraction /-- A generalized continued fraction is a *simple continued fraction* if all partial numerators are equal to one. 1 h + --------------------------- 1 b₀ + -------------------- 1 b₁ + -------------- 1 b₂ + -------- b₃ + ... -/ def generalized_continued_fraction.is_simple_continued_fraction {α : Type u_1} (g : generalized_continued_fraction α) [HasOne α] := ∀ (n : ℕ) (aₙ : α), seq.nth (generalized_continued_fraction.partial_numerators g) n = some aₙ → aₙ = 1 /-- A *simple continued fraction* (scf) is a generalized continued fraction (gcf) whose partial numerators are equal to one. 1 h + --------------------------- 1 b₀ + -------------------- 1 b₁ + -------------- 1 b₂ + -------- b₃ + ... For convenience, one often writes `[h; b₀, b₁, b₂,...]`. It is encoded as the subtype of gcfs that satisfy `generalized_continued_fraction.is_simple_continued_fraction`. -/ def simple_continued_fraction (α : Type u_1) [HasOne α] := Subtype fun (g : generalized_continued_fraction α) => generalized_continued_fraction.is_simple_continued_fraction g /- Interlude: define some expected coercions. -/ namespace simple_continued_fraction /-- Constructs a simple continued fraction without fractional part. -/ def of_integer {α : Type u_1} [HasOne α] (a : α) : simple_continued_fraction α := { val := generalized_continued_fraction.of_integer a, property := sorry } protected instance inhabited {α : Type u_1} [HasOne α] : Inhabited (simple_continued_fraction α) := { default := of_integer 1 } /-- Lift a scf to a gcf using the inclusion map. -/ protected instance has_coe_to_generalized_continued_fraction {α : Type u_1} [HasOne α] : has_coe (simple_continued_fraction α) (generalized_continued_fraction α) := eq.mpr sorry Mathlib.coe_subtype theorem coe_to_generalized_continued_fraction {α : Type u_1} [HasOne α] {s : simple_continued_fraction α} : ↑s = subtype.val s := rfl end simple_continued_fraction /-- A simple continued fraction is a *(regular) continued fraction* ((r)cf) if all partial denominators `bᵢ` are positive, i.e. `0 < bᵢ`. -/ def simple_continued_fraction.is_regular_continued_fraction {α : Type u_1} [HasOne α] [HasZero α] [HasLess α] (s : simple_continued_fraction α) := ∀ (n : ℕ) (bₙ : α), seq.nth (generalized_continued_fraction.partial_denominators ↑s) n = some bₙ → 0 < bₙ /-- A *(regular) continued fraction* ((r)cf) is a simple continued fraction (scf) whose partial denominators are all positive. It is the subtype of scfs that satisfy `simple_continued_fraction.is_regular_continued_fraction`. -/ def continued_fraction (α : Type u_1) [HasOne α] [HasZero α] [HasLess α] := Subtype fun (s : simple_continued_fraction α) => simple_continued_fraction.is_regular_continued_fraction s /- Interlude: define some expected coercions. -/ namespace continued_fraction /-- Constructs a continued fraction without fractional part. -/ def of_integer {α : Type u_1} [HasOne α] [HasZero α] [HasLess α] (a : α) : continued_fraction α := { val := simple_continued_fraction.of_integer a, property := sorry } protected instance inhabited {α : Type u_1} [HasOne α] [HasZero α] [HasLess α] : Inhabited (continued_fraction α) := { default := of_integer 0 } /-- Lift a cf to a scf using the inclusion map. -/ protected instance has_coe_to_simple_continued_fraction {α : Type u_1} [HasOne α] [HasZero α] [HasLess α] : has_coe (continued_fraction α) (simple_continued_fraction α) := eq.mpr sorry Mathlib.coe_subtype theorem coe_to_simple_continued_fraction {α : Type u_1} [HasOne α] [HasZero α] [HasLess α] {c : continued_fraction α} : ↑c = subtype.val c := rfl /-- Lift a cf to a scf using the inclusion map. -/ protected instance has_coe_to_generalized_continued_fraction {α : Type u_1} [HasOne α] [HasZero α] [HasLess α] : has_coe (continued_fraction α) (generalized_continued_fraction α) := has_coe.mk fun (c : continued_fraction α) => ↑↑c theorem coe_to_generalized_continued_fraction {α : Type u_1} [HasOne α] [HasZero α] [HasLess α] {c : continued_fraction α} : ↑c = ↑(subtype.val c) := rfl end continued_fraction /- We now define how to compute the convergents of a gcf. There are two standard ways to do this: directly evaluating the (infinite) fraction described by the gcf or using a recurrence relation. For (r)cfs, these computations are equivalent as shown in `algebra.continued_fractions.convergents_equiv`. -/ namespace generalized_continued_fraction -- Fix a division ring for the computations. /- We start with the definition of the recurrence relation. Given a gcf `g`, for all `n ≥ 1`, we define - `A₋₁ = 1, A₀ = h, Aₙ = bₙ₋₁ * Aₙ₋₁ + aₙ₋₁ * Aₙ₋₂`, and - `B₋₁ = 0, B₀ = 1, Bₙ = bₙ₋₁ * Bₙ₋₁ + aₙ₋₁ * Bₙ₋₂`. `Aₙ, `Bₙ` are called the *nth continuants*, Aₙ the *nth numerator*, and `Bₙ` the *nth denominator* of `g`. The *nth convergent* of `g` is given by `Aₙ / Bₙ`. -/ /-- Returns the next numerator `Aₙ = bₙ₋₁ * Aₙ₋₁ + aₙ₋₁ * Aₙ₋₂`, where `predA` is `Aₙ₋₁`, `ppredA` is `Aₙ₋₂`, `a` is `aₙ₋₁`, and `b` is `bₙ₋₁`. -/ def next_numerator {K : Type u_2} [division_ring K] (a : K) (b : K) (ppredA : K) (predA : K) : K := b * predA + a * ppredA /-- Returns the next denominator `Bₙ = bₙ₋₁ * Bₙ₋₁ + aₙ₋₁ * Bₙ₋₂``, where `predB` is `Bₙ₋₁` and `ppredB` is `Bₙ₋₂`, `a` is `aₙ₋₁`, and `b` is `bₙ₋₁`. -/ def next_denominator {K : Type u_2} [division_ring K] (aₙ : K) (bₙ : K) (ppredB : K) (predB : K) : K := bₙ * predB + aₙ * ppredB /-- Returns the next continuants `⟨Aₙ, Bₙ⟩` using `next_numerator` and `next_denominator`, where `pred` is `⟨Aₙ₋₁, Bₙ₋₁⟩`, `ppred` is `⟨Aₙ₋₂, Bₙ₋₂⟩`, `a` is `aₙ₋₁`, and `b` is `bₙ₋₁`. -/ def next_continuants {K : Type u_2} [division_ring K] (a : K) (b : K) (ppred : pair K) (pred : pair K) : pair K := pair.mk (next_numerator a b (pair.a ppred) (pair.a pred)) (next_denominator a b (pair.b ppred) (pair.b pred)) /-- Returns the continuants `⟨Aₙ₋₁, Bₙ₋₁⟩` of `g`. -/ def continuants_aux {K : Type u_2} [division_ring K] (g : generalized_continued_fraction K) : stream (pair K) := sorry /-- Returns the continuants `⟨Aₙ, Bₙ⟩` of `g`. -/ def continuants {K : Type u_2} [division_ring K] (g : generalized_continued_fraction K) : stream (pair K) := stream.tail (continuants_aux g) /-- Returns the numerators `Aₙ` of `g`. -/ def numerators {K : Type u_2} [division_ring K] (g : generalized_continued_fraction K) : stream K := stream.map pair.a (continuants g) /-- Returns the denominators `Bₙ` of `g`. -/ def denominators {K : Type u_2} [division_ring K] (g : generalized_continued_fraction K) : stream K := stream.map pair.b (continuants g) /-- Returns the convergents `Aₙ / Bₙ` of `g`, where `Aₙ, Bₙ` are the nth continuants of `g`. -/ def convergents {K : Type u_2} [division_ring K] (g : generalized_continued_fraction K) : stream K := fun (n : ℕ) => numerators g n / denominators g n /-- Returns the approximation of the fraction described by the given sequence up to a given position n. For example, `convergents'_aux [(1, 2), (3, 4), (5, 6)] 2 = 1 / (2 + 3 / 4)` and `convergents'_aux [(1, 2), (3, 4), (5, 6)] 0 = 0`. -/ def convergents'_aux {K : Type u_2} [division_ring K] : seq (pair K) → ℕ → K := sorry /-- Returns the convergents of `g` by evaluating the fraction described by `g` up to a given position `n`. For example, `convergents' [9; (1, 2), (3, 4), (5, 6)] 2 = 9 + 1 / (2 + 3 / 4)` and `convergents' [9; (1, 2), (3, 4), (5, 6)] 0 = 9` -/ def convergents' {K : Type u_2} [division_ring K] (g : generalized_continued_fraction K) (n : ℕ) : K := h g + convergents'_aux (s g) n end generalized_continued_fraction -- Now, some basic, general theorems namespace generalized_continued_fraction /-- Two gcfs `g` and `g'` are equal if and only if their components are equal. -/ protected theorem ext_iff {α : Type u_1} {g : generalized_continued_fraction α} {g' : generalized_continued_fraction α} : g = g' ↔ h g = h g' ∧ s g = s g' := sorry protected theorem ext {α : Type u_1} {g : generalized_continued_fraction α} {g' : generalized_continued_fraction α} (hyp : h g = h g' ∧ s g = s g') : g = g' := iff.elim_right generalized_continued_fraction.ext_iff hyp
aca07ae8f489d6c2dbb7380d1ded1d7fdfd61dbd
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/archive/imo/imo1962_q1.lean
bd586605533fb542a76d73810b01e0795700349d
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
5,591
lean
/- Copyright (c) 2020 Kevin Lacker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Lacker -/ import data.nat.digits /-! # IMO 1962 Q1 > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. Find the smallest natural number $n$ which has the following properties: (a) Its decimal representation has 6 as the last digit. (b) If the last digit 6 is erased and placed in front of the remaining digits, the resulting number is four times as large as the original number $n$. Since Lean does not explicitly express problems of the form "find the smallest number satisfying X", we define the problem as a predicate, and then prove a particular number is the smallest member of a set satisfying it. -/ namespace imo1962_q1 open nat def problem_predicate (n : ℕ) : Prop := (digits 10 n).head = 6 ∧ of_digits 10 ((digits 10 n).tail.concat 6) = 4 * n /-! First, it's inconvenient to work with digits, so let's simplify them out of the problem. -/ abbreviation problem_predicate' (c n : ℕ) : Prop := n = 10 * c + 6 ∧ 6 * 10 ^ (digits 10 c).length + c = 4 * n lemma without_digits {n : ℕ} (h1 : problem_predicate n) : ∃ c : ℕ, problem_predicate' c n := begin use n / 10, cases n, { have h2 : ¬ problem_predicate 0, by norm_num [problem_predicate], contradiction }, { rw [problem_predicate, digits_def' (dec_trivial : 2 ≤ 10) n.succ_pos, list.head, list.tail_cons, list.concat_eq_append] at h1, split, { rw [← h1.left, div_add_mod (n+1) 10], }, { rw [← h1.right, of_digits_append, of_digits_digits, of_digits_singleton, add_comm, mul_comm], }, }, end /-! Now we can eliminate possibilities for `(digits 10 c).length` until we get to the one that works. -/ lemma case_0_digit {c n : ℕ} (h1 : (digits 10 c).length = 0) : ¬ problem_predicate' c n := begin intro h2, have h3 : 6 * 10 ^ 0 + c = 6 * 10 ^ (digits 10 c).length + c, by rw h1, have h4 : 6 * 10 ^ 0 + c = 4 * (10 * c + 6), by rw [h3, h2.right, h2.left], linarith, end lemma case_1_digit {c n : ℕ} (h1 : (digits 10 c).length = 1) : ¬ problem_predicate' c n := begin intro h2, have h3 : 6 * 10 ^ 1 + c = 6 * 10 ^ (digits 10 c).length + c, by rw h1, have h4 : 6 * 10 ^ 1 + c = 4 * (10 * c + 6), by rw [h3, h2.right, h2.left], have h6 : c > 0, by linarith, linarith, end lemma case_2_digit {c n : ℕ} (h1 : (digits 10 c).length = 2) : ¬ problem_predicate' c n := begin intro h2, have h3 : 6 * 10 ^ 2 + c = 6 * 10 ^ (digits 10 c).length + c, by rw h1, have h4 : 6 * 10 ^ 2 + c = 4 * (10 * c + 6), by rw [h3, h2.right, h2.left], have h5 : c > 14, by linarith, linarith end lemma case_3_digit {c n : ℕ} (h1 : (digits 10 c).length = 3) : ¬ problem_predicate' c n := begin intro h2, have h3 : 6 * 10 ^ 3 + c = 6 * 10 ^ (digits 10 c).length + c, by rw h1, have h4 : 6 * 10 ^ 3 + c = 4 * (10 * c + 6), by rw [h3, h2.right, h2.left], have h5 : c > 153, by linarith, linarith end lemma case_4_digit {c n : ℕ} (h1 : (digits 10 c).length = 4) : ¬ problem_predicate' c n := begin intro h2, have h3 : 6 * 10 ^ 4 + c = 6 * 10 ^ (digits 10 c).length + c, by rw h1, have h4 : 6 * 10 ^ 4 + c = 4 * (10 * c + 6), by rw [h3, h2.right, h2.left], have h5 : c > 1537, by linarith, linarith end /-- Putting this inline causes a deep recursion error, so we separate it out. -/ lemma helper_5_digit {c : ℤ} (h : 6 * 10 ^ 5 + c = 4 * (10 * c + 6)) : c = 15384 := by linarith lemma case_5_digit {c n : ℕ} (h1 : (digits 10 c).length = 5) (h2 : problem_predicate' c n) : c = 15384 := begin have h3 : 6 * 10 ^ 5 + c = 6 * 10 ^ (digits 10 c).length + c, by rw h1, have h4 : 6 * 10 ^ 5 + c = 4 * (10 * c + 6), by rw [h3, h2.right, h2.left], zify at *, exact helper_5_digit h4 end /-- `linarith` fails on numbers this large, so this lemma spells out some of the arithmetic that normally would be automated. -/ lemma case_more_digits {c n : ℕ} (h1 : (digits 10 c).length ≥ 6) (h2 : problem_predicate' c n) : n ≥ 153846 := begin have h3 : c ≠ 0, { intro h4, have h5 : (digits 10 c).length = 0, by simp [h4], exact case_0_digit h5 h2 }, have h6 : 2 ≤ 10, from dec_trivial, calc n ≥ 10 * c : le.intro h2.left.symm ... ≥ 10 ^ (digits 10 c).length : base_pow_length_digits_le 10 c h6 h3 ... ≥ 10 ^ 6 : (pow_le_iff_le_right h6).mpr h1 ... ≥ 153846 : by norm_num, end /-! Now we combine these cases to show that 153846 is the smallest solution. -/ lemma satisfied_by_153846 : problem_predicate 153846 := by norm_num [problem_predicate, digits_def', of_digits] lemma no_smaller_solutions (n : ℕ) (h1 : problem_predicate n) : n ≥ 153846 := begin cases without_digits h1 with c h2, have h3 : (digits 10 c).length < 6 ∨ (digits 10 c).length ≥ 6, by apply lt_or_ge, cases h3, case or.inr { exact case_more_digits h3 h2, }, case or.inl { interval_cases (digits 10 c).length with h, { exfalso, exact case_0_digit h h2 }, { exfalso, exact case_1_digit h h2 }, { exfalso, exact case_2_digit h h2 }, { exfalso, exact case_3_digit h h2 }, { exfalso, exact case_4_digit h h2 }, { have h4 : c = 15384, from case_5_digit h h2, have h5 : n = 10 * 15384 + 6, from h4 ▸ h2.left, norm_num at h5, exact h5.ge, }, }, end end imo1962_q1 open imo1962_q1 theorem imo1962_q1 : is_least {n | problem_predicate n} 153846 := ⟨satisfied_by_153846, no_smaller_solutions⟩
bbacd4a8188e941516cad471b36acf4de4f28f8f
5ae26df177f810c5006841e9c73dc56e01b978d7
/src/tactic/algebra.lean
099afdee506badcbcd3db91acc2da43bb8370b4b
[ "Apache-2.0" ]
permissive
ChrisHughes24/mathlib
98322577c460bc6b1fe5c21f42ce33ad1c3e5558
a2a867e827c2a6702beb9efc2b9282bd801d5f9a
refs/heads/master
1,583,848,251,477
1,565,164,247,000
1,565,164,247,000
129,409,993
0
1
Apache-2.0
1,565,164,817,000
1,523,628,059,000
Lean
UTF-8
Lean
false
false
1,854
lean
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import tactic.core open lean.parser namespace tactic @[user_attribute] meta def ancestor_attr : user_attribute unit (list name) := { name := `ancestor, descr := "ancestor of old structures", parser := many ident } meta def get_ancestors (cl : name) : tactic (list name) := (++) <$> (prod.fst <$> subobject_names cl <|> pure []) <*> (user_attribute.get_param ancestor_attr cl <|> pure []) meta def find_ancestors : name → expr → tactic (list expr) | cl arg := do cs ← get_ancestors cl, r ← cs.mmap $ λ c, list.ret <$> (mk_app c [arg] >>= mk_instance) <|> find_ancestors c arg, return r.join end tactic attribute [ancestor has_mul] semigroup attribute [ancestor semigroup has_one] monoid attribute [ancestor monoid has_inv] group attribute [ancestor group has_comm] comm_group attribute [ancestor has_add] add_semigroup attribute [ancestor add_semigroup has_zero] add_monoid attribute [ancestor add_monoid has_neg] add_group attribute [ancestor add_group has_add_comm] add_comm_group attribute [ancestor ring has_inv zero_ne_one_class] division_ring attribute [ancestor division_ring comm_ring] field attribute [ancestor field] discrete_field attribute [ancestor has_mul has_add] distrib attribute [ancestor has_mul has_zero] mul_zero_class attribute [ancestor has_zero has_one] zero_ne_one_class attribute [ancestor add_comm_monoid monoid distrib mul_zero_class] semiring attribute [ancestor semiring comm_monoid] comm_semiring attribute [ancestor add_comm_group monoid distrib] ring attribute [ancestor ring comm_semigroup] comm_ring attribute [ancestor has_mul has_zero] no_zero_divisors attribute [ancestor comm_ring no_zero_divisors zero_ne_one_class] integral_domain
2c8534fd7feca9131431086805076514346b35e1
82e44445c70db0f03e30d7be725775f122d72f3e
/src/algebra/category/Module/adjunctions.lean
721fc2c6e4e0f3887b3f4d5b47ccd22f929b074e
[ "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
10,193
lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Johan Commelin -/ import algebra.category.Module.monoidal import category_theory.monoidal.functorial import category_theory.monoidal.types import linear_algebra.direct_sum.finsupp import category_theory.linear.linear_functor /-! The functor of forming finitely supported functions on a type with values in a `[ring R]` is the left adjoint of the forgetful functor from `R`-modules to types. -/ noncomputable theory open category_theory namespace Module universe u open_locale classical variables (R : Type u) section variables [ring R] /-- The free functor `Type u ⥤ Module R` sending a type `X` to the free `R`-module with generators `x : X`, implemented as the type `X →₀ R`. -/ @[simps] def free : Type u ⥤ Module R := { obj := λ X, Module.of R (X →₀ R), map := λ X Y f, finsupp.lmap_domain _ _ f, map_id' := by { intros, exact finsupp.lmap_domain_id _ _ }, map_comp' := by { intros, exact finsupp.lmap_domain_comp _ _ _ _, } } /-- The free-forgetful adjunction for R-modules. -/ def adj : free R ⊣ forget (Module.{u} R) := adjunction.mk_of_hom_equiv { hom_equiv := λ X M, (finsupp.lift M R X).to_equiv.symm, hom_equiv_naturality_left_symm' := λ _ _ M f g, finsupp.lhom_ext' (λ x, linear_map.ext_ring (finsupp.sum_map_domain_index_add_monoid_hom (λ y, ((smul_add_hom R ↥M).flip) (g y))).symm) } instance : is_right_adjoint (forget (Module.{u} R)) := ⟨_, adj R⟩ end namespace free variables [comm_ring R] /-- The free R-module functor is lax monoidal. -/ -- In fact, it's strong monoidal, but we don't yet have a typeclass for that. instance : lax_monoidal.{u} (free R).obj := { -- Send `R` to `punit →₀ R` ε := finsupp.lsingle punit.star, -- Send `(α →₀ R) ⊗ (β →₀ R)` to `α × β →₀ R` μ := λ α β, (finsupp_tensor_finsupp' R α β).to_linear_map, μ_natural' := begin intros, ext x x' ⟨y, y'⟩, -- This is rather tedious: it's a terminal simp, with no arguments, -- but between the four of them it is too slow. simp only [tensor_product.mk_apply, mul_one, tensor_apply, monoidal_category.hom_apply, Module.free_map, Module.coe_comp, map_functorial_obj, linear_map.compr₂_apply, linear_equiv.coe_to_linear_map, linear_map.comp_apply, function.comp_app, finsupp.lmap_domain_apply, finsupp.map_domain_single, finsupp_tensor_finsupp'_single_tmul_single, finsupp.lsingle_apply], end, left_unitality' := begin intros, ext, simp only [tensor_product.mk_apply, mul_one, Module.id_apply, Module.free_map, Module.coe_comp, map_functorial_obj, Module.monoidal_category.hom_apply, left_unitor_hom_apply, Module.monoidal_category.left_unitor_hom_apply, linear_map.compr₂_apply, linear_equiv.coe_to_linear_map, linear_map.comp_apply, function.comp_app, finsupp.lmap_domain_apply, finsupp.smul_single', finsupp.map_domain_single, finsupp_tensor_finsupp'_single_tmul_single, finsupp.lsingle_apply], end, right_unitality' := begin intros, ext, simp only [tensor_product.mk_apply, mul_one, Module.id_apply, Module.free_map, Module.coe_comp, map_functorial_obj, Module.monoidal_category.hom_apply, right_unitor_hom_apply, Module.monoidal_category.right_unitor_hom_apply, linear_map.compr₂_apply, linear_equiv.coe_to_linear_map, linear_map.comp_apply, function.comp_app, finsupp.lmap_domain_apply, finsupp.smul_single', finsupp.map_domain_single, finsupp_tensor_finsupp'_single_tmul_single, finsupp.lsingle_apply], end, associativity' := begin intros, ext, simp only [tensor_product.mk_apply, mul_one, Module.id_apply, Module.free_map, Module.coe_comp, map_functorial_obj, Module.monoidal_category.hom_apply, associator_hom_apply, Module.monoidal_category.associator_hom_apply, linear_map.compr₂_apply, linear_equiv.coe_to_linear_map, linear_map.comp_apply, function.comp_app, finsupp.lmap_domain_apply, finsupp.smul_single', finsupp.map_domain_single, finsupp_tensor_finsupp'_single_tmul_single, finsupp.lsingle_apply], end, } end free end Module namespace category_theory universes v u /-- `Free R C` is a type synonym for `C`, which, given `[comm_ring R]` and `[category C]`, we will equip with a category structure where the morphisms are formal `R`-linear combinations of the morphisms in `C`. -/ @[nolint unused_arguments has_inhabited_instance] def Free (R : Type*) (C : Type u) := C /-- Consider an object of `C` as an object of the `R`-linear completion. -/ def Free.of (R : Type*) {C : Type u} (X : C) : Free R C := X variables (R : Type*) [comm_ring R] (C : Type u) [category.{v} C] open finsupp -- Conceptually, it would be nice to construct this via "transport of enrichment", -- using the fact that `Module.free R : Type ⥤ Module R` and `Module.forget` are both lax monoidal. -- This still seems difficult, so we just do it by hand. instance category_Free : category (Free R C) := { hom := λ (X Y : C), (X ⟶ Y) →₀ R, id := λ (X : C), finsupp.single (𝟙 X) 1, comp := λ (X Y Z : C) f g, f.sum (λ f' s, g.sum (λ g' t, finsupp.single (f' ≫ g') (s * t))), assoc' := λ W X Y Z f g h, begin dsimp, -- This imitates the proof of associativity for `monoid_algebra`. simp only [sum_sum_index, sum_single_index, single_zero, single_add, eq_self_iff_true, forall_true_iff, forall_3_true_iff, add_mul, mul_add, category.assoc, mul_assoc, zero_mul, mul_zero, sum_zero, sum_add], end }. namespace Free section local attribute [simp] category_theory.category_Free @[simp] lemma single_comp_single {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (r s : R) : (single f r ≫ single g s : (Free.of R X) ⟶ (Free.of R Z)) = single (f ≫ g) (r * s) := by { dsimp, simp, } instance : preadditive (Free R C) := { hom_group := λ X Y, finsupp.add_comm_group, add_comp' := λ X Y Z f f' g, begin dsimp, rw [finsupp.sum_add_index]; { simp [add_mul], } end, comp_add' := λ X Y Z f g g', begin dsimp, rw ← finsupp.sum_add, congr, ext r h, rw [finsupp.sum_add_index]; { simp [mul_add], }, end, } instance : linear R (Free R C) := { hom_module := λ X Y, finsupp.module (X ⟶ Y) R, smul_comp' := λ X Y Z r f g, begin dsimp, rw [finsupp.sum_smul_index]; simp [finsupp.smul_sum, mul_assoc], end, comp_smul' := λ X Y Z f r g, begin dsimp, simp_rw [finsupp.smul_sum], congr, ext h s, rw [finsupp.sum_smul_index]; simp [finsupp.smul_sum, mul_left_comm], end, } end /-- A category embeds into its `R`-linear completion. -/ @[simps] def embedding : C ⥤ Free R C := { obj := λ X, X, map := λ X Y f, finsupp.single f 1, map_id' := λ X, rfl, map_comp' := λ X Y Z f g, by simp, } variables (R) {C} {D : Type u} [category.{v} D] [preadditive D] [linear R D] open preadditive linear /-- A functor to a preadditive category lifts to a functor from its `R`-linear completion. -/ @[simps] def lift (F : C ⥤ D) : Free R C ⥤ D := { obj := λ X, F.obj X, map := λ X Y f, f.sum (λ f' r, r • (F.map f')), map_id' := by { dsimp [category_theory.category_Free], simp }, map_comp' := λ X Y Z f g, begin apply finsupp.induction_linear f, { simp, }, { intros f₁ f₂ w₁ w₂, rw add_comp, rw [finsupp.sum_add_index, finsupp.sum_add_index], { simp [w₁, w₂, add_comp], }, { simp, }, { intros, simp only [add_smul], }, { simp, }, { intros, simp only [add_smul], }, }, { intros f' r, apply finsupp.induction_linear g, { simp, }, { intros f₁ f₂ w₁ w₂, rw comp_add, rw [finsupp.sum_add_index, finsupp.sum_add_index], { simp [w₁, w₂, add_comp], }, { simp, }, { intros, simp only [add_smul], }, { simp, }, { intros, simp only [add_smul], }, }, { intros g' s, erw single_comp_single, simp [mul_comm r s, mul_smul], } } end, } @[simp] lemma lift_map_single (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) (r : R) : (lift R F).map (single f r) = r • F.map f := by simp instance lift_additive (F : C ⥤ D) : (lift R F).additive := { map_zero' := by simp, map_add' := λ X Y f g, begin dsimp, rw finsupp.sum_add_index; simp [add_smul] end, } instance lift_linear (F : C ⥤ D) : (lift R F).linear R := { map_smul' := λ X Y f r, begin dsimp, rw finsupp.sum_smul_index; simp [finsupp.smul_sum, mul_smul], end, } /-- The embedding into the `R`-linear completion, followed by the lift, is isomorphic to the original functor. -/ def embedding_lift_iso (F : C ⥤ D) : embedding R C ⋙ lift R F ≅ F := nat_iso.of_components (λ X, iso.refl _) (by tidy) /-- Two `R`-linear functors out of the `R`-linear completion are isomorphic iff their compositions with the embedding functor are isomorphic. -/ @[ext] def ext {F G : Free R C ⥤ D} [F.additive] [F.linear R] [G.additive] [G.linear R] (α : embedding R C ⋙ F ≅ embedding R C ⋙ G) : F ≅ G := nat_iso.of_components (λ X, α.app X) begin intros X Y f, apply finsupp.induction_linear f, { simp, }, { intros f₁ f₂ w₁ w₂, simp only [F.map_add, G.map_add, add_comp, comp_add, w₁, w₂], }, { intros f' r, rw [iso.app_hom, iso.app_hom, ←smul_single_one, F.map_smul, G.map_smul, smul_comp, comp_smul], change r • (embedding R C ⋙ F).map f' ≫ _ = r • _ ≫ (embedding R C ⋙ G).map f', rw α.hom.naturality f', apply_instance, -- Why are these not picked up automatically when we rewrite? apply_instance, } end /-- `Free.lift` is unique amongst `R`-linear functors `Free R C ⥤ D` which compose with `embedding ℤ C` to give the original functor. -/ def lift_unique (F : C ⥤ D) (L : Free R C ⥤ D) [L.additive] [L.linear R] (α : embedding R C ⋙ L ≅ F) : L ≅ lift R F := ext R (α.trans (embedding_lift_iso R F).symm) end Free end category_theory
970e5d83d86c8c779645f517fdb7fb6f3d3b9e5c
c777c32c8e484e195053731103c5e52af26a25d1
/src/topology/sheaves/punit.lean
c036317c91fdfa6482263d18cc8f878f5efe5882
[ "Apache-2.0" ]
permissive
kbuzzard/mathlib
2ff9e85dfe2a46f4b291927f983afec17e946eb8
58537299e922f9c77df76cb613910914a479c1f7
refs/heads/master
1,685,313,702,744
1,683,974,212,000
1,683,974,212,000
128,185,277
1
0
null
1,522,920,600,000
1,522,920,600,000
null
UTF-8
Lean
false
false
2,030
lean
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang -/ import topology.sheaves.sheaf_condition.sites /-! # Presheaves on punit Presheaves on punit satisfy sheaf condition iff its value at empty set is a terminal object. -/ namespace Top.presheaf universes u v w open category_theory category_theory.limits Top opposite variables {C : Type u} [category.{v} C] lemma is_sheaf_of_is_terminal_of_indiscrete {X : Top.{w}} (hind : X.str = ⊤) (F : presheaf C X) (it : is_terminal $ F.obj $ op ⊥) : F.is_sheaf := λ c U s hs, begin obtain rfl | hne := eq_or_ne U ⊥, { intros _ _, rw @exists_unique_iff_exists _ ⟨λ _ _, _⟩, { refine ⟨it.from _, λ U hU hs, is_terminal.hom_ext _ _ _⟩, rwa le_bot_iff.1 hU.le }, { apply it.hom_ext } }, { convert presieve.is_sheaf_for_top_sieve _, rw ←sieve.id_mem_iff_eq_top, have := (U.eq_bot_or_top hind).resolve_left hne, subst this, obtain he | ⟨⟨x⟩⟩ := is_empty_or_nonempty X, { exact (hne $ set_like.ext'_iff.2 $ set.univ_eq_empty_iff.2 he).elim }, obtain ⟨U, f, hf, hm⟩ := hs x trivial, obtain rfl | rfl := U.eq_bot_or_top hind, { cases hm }, { convert hf } }, end lemma is_sheaf_iff_is_terminal_of_indiscrete {X : Top.{w}} (hind : X.str = ⊤) (F : presheaf C X) : F.is_sheaf ↔ nonempty (is_terminal $ F.obj $ op ⊥) := ⟨λ h, ⟨sheaf.is_terminal_of_empty ⟨F, h⟩⟩, λ ⟨it⟩, is_sheaf_of_is_terminal_of_indiscrete hind F it⟩ lemma is_sheaf_on_punit_of_is_terminal (F : presheaf C (Top.of punit)) (it : is_terminal $ F.obj $ op ⊥) : F.is_sheaf := is_sheaf_of_is_terminal_of_indiscrete (@subsingleton.elim (topological_space punit) _ _ _) F it lemma is_sheaf_on_punit_iff_is_terminal (F : presheaf C (Top.of punit)) : F.is_sheaf ↔ nonempty (is_terminal $ F.obj $ op ⊥) := ⟨λ h, ⟨sheaf.is_terminal_of_empty ⟨F, h⟩⟩, λ ⟨it⟩, is_sheaf_on_punit_of_is_terminal F it⟩ end Top.presheaf
1441cd307db45bd752ff96040dd0cb443785eaf2
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/analysis/normed_space/M_structure.lean
6f38dbc4af33565e32e0125402c449aa13a733f9
[ "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
13,587
lean
/- Copyright (c) 2022 Christopher Hoskin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christopher Hoskin -/ import algebra.ring.idempotents import tactic.noncomm_ring import analysis.normed.group.basic /-! # M-structure A projection P on a normed space X is said to be an L-projection (`is_Lprojection`) if, for all `x` in `X`, $\|x\| = \|P x\| + \|(1 - P) x\|$. A projection P on a normed space X is said to be an M-projection if, for all `x` in `X`, $\|x\| = max(\|P x\|,\|(1 - P) x\|)$. The L-projections on `X` form a Boolean algebra (`is_Lprojection.subtype.boolean_algebra`). ## TODO (Motivational background) The M-projections on a normed space form a Boolean algebra. The range of an L-projection on a normed space `X` is said to be an L-summand of `X`. The range of an M-projection is said to be an M-summand of `X`. When `X` is a Banach space, the Boolean algebra of L-projections is complete. Let `X` be a normed space with dual `X^*`. A closed subspace `M` of `X` is said to be an M-ideal if the topological annihilator `M^∘` is an L-summand of `X^*`. M-ideal, M-summands and L-summands were introduced by Alfsen and Effros in [alfseneffros1972] to study the structure of general Banach spaces. When `A` is a JB*-triple, the M-ideals of `A` are exactly the norm-closed ideals of `A`. When `A` is a JBW*-triple with predual `X`, the M-summands of `A` are exactly the weak*-closed ideals, and their pre-duals can be identified with the L-summands of `X`. In the special case when `A` is a C*-algebra, the M-ideals are exactly the norm-closed two-sided ideals of `A`, when `A` is also a W*-algebra the M-summands are exactly the weak*-closed two-sided ideals of `A`. ## Implementation notes The approach to showing that the L-projections form a Boolean algebra is inspired by `measure_theory.measurable_space`. Instead of using `P : X →L[𝕜] X` to represent projections, we use an arbitrary ring `M` with a faithful action on `X`. `continuous_linear_map.apply_module` can be used to recover the `X →L[𝕜] X` special case. ## References * [Behrends, M-structure and the Banach-Stone Theorem][behrends1979] * [Harmand, Werner, Werner, M-ideals in Banach spaces and Banach algebras][harmandwernerwerner1993] ## Tags M-summand, M-projection, L-summand, L-projection, M-ideal, M-structure -/ variables (X : Type*) [normed_add_comm_group X] variables {M : Type} [ring M] [module M X] /-- A projection on a normed space `X` is said to be an L-projection if, for all `x` in `X`, $\|x\| = \|P x\| + \|(1 - P) x\|$. Note that we write `P • x` instead of `P x` for reasons described in the module docstring. -/ structure is_Lprojection (P : M) : Prop := (proj : is_idempotent_elem P) (Lnorm : ∀ (x : X), ‖x‖ = ‖P • x‖ + ‖(1 - P) • x‖) /-- A projection on a normed space `X` is said to be an M-projection if, for all `x` in `X`, $\|x\| = max(\|P x\|,\|(1 - P) x\|)$. Note that we write `P • x` instead of `P x` for reasons described in the module docstring. -/ structure is_Mprojection (P : M) : Prop := (proj : is_idempotent_elem P) (Mnorm : ∀ (x : X), ‖x‖ = (max ‖P • x‖ ‖(1 - P) • x‖)) variables {X} namespace is_Lprojection lemma Lcomplement {P : M} (h: is_Lprojection X P) : is_Lprojection X (1 - P) := ⟨h.proj.one_sub, λ x, by { rw [add_comm, sub_sub_cancel], exact h.Lnorm x }⟩ lemma Lcomplement_iff (P : M) : is_Lprojection X P ↔ is_Lprojection X (1 - P) := ⟨Lcomplement, λ h, sub_sub_cancel 1 P ▸ h.Lcomplement⟩ lemma commute [has_faithful_smul M X] {P Q : M} (h₁ : is_Lprojection X P) (h₂ : is_Lprojection X Q) : commute P Q := begin have PR_eq_RPR : ∀ R : M, is_Lprojection X R → P * R = R * P * R := λ R h₃, begin refine @eq_of_smul_eq_smul _ X _ _ _ _ (λ x, _), rw ← norm_sub_eq_zero_iff, have e1 : ‖R • x‖ ≥ ‖R • x‖ + 2 • ‖ (P * R) • x - (R * P * R) • x‖ := calc ‖R • x‖ = ‖R • (P • (R • x))‖ + ‖(1 - R) • (P • (R • x))‖ + (‖(R * R) • x - R • (P • (R • x))‖ + ‖(1 - R) • ((1 - P) • (R • x))‖) : by rw [h₁.Lnorm, h₃.Lnorm, h₃.Lnorm ((1 - P) • (R • x)), sub_smul 1 P, one_smul, smul_sub, mul_smul] ... = ‖R • (P • (R • x))‖ + ‖(1 - R) • (P • (R • x))‖ + (‖R • x - R • (P • (R • x))‖ + ‖((1 - R) * R) • x - (1 - R) • (P • (R • x))‖) : by rw [h₃.proj.eq, sub_smul 1 P, one_smul, smul_sub, mul_smul] ... = ‖R • (P • (R • x))‖ + ‖(1 - R) • (P • (R • x))‖ + (‖R • x - R • (P • (R • x))‖ + ‖(1 - R) • (P • (R • x))‖) : by rw [sub_mul, h₃.proj.eq, one_mul, sub_self, zero_smul, zero_sub, norm_neg] ... = ‖R • (P • (R • x))‖ + ‖R • x - R • (P • (R • x))‖ + 2•‖(1 - R) • (P • (R • x))‖ : by abel ... ≥ ‖R • x‖ + 2 • ‖ (P * R) • x - (R * P * R) • x‖ : by { rw ge, have := add_le_add_right (norm_le_insert' (R • x) (R • (P • (R • x)))) (2•‖(1 - R) • (P • (R • x))‖), simpa only [mul_smul, sub_smul, one_smul] using this }, rw ge at e1, nth_rewrite_rhs 0 ← add_zero (‖R • x‖) at e1, rw [add_le_add_iff_left, two_smul, ← two_mul] at e1, rw le_antisymm_iff, refine ⟨_, norm_nonneg _⟩, rwa [←mul_zero (2 : ℝ), mul_le_mul_left (show (0 : ℝ) < 2, by norm_num)] at e1 end, have QP_eq_QPQ : Q * P = Q * P * Q, { have e1 : P * (1 - Q) = P * (1 - Q) - (Q * P - Q * P * Q) := calc P * (1 - Q) = (1 - Q) * P * (1 - Q) : by rw PR_eq_RPR (1 - Q) h₂.Lcomplement ... = P * (1 - Q) - (Q * P - Q * P * Q) : by noncomm_ring, rwa [eq_sub_iff_add_eq, add_right_eq_self, sub_eq_zero] at e1 }, show P * Q = Q * P, by rw [QP_eq_QPQ, PR_eq_RPR Q h₂] end lemma mul [has_faithful_smul M X] {P Q : M} (h₁ : is_Lprojection X P) (h₂ : is_Lprojection X Q) : is_Lprojection X (P * Q) := begin refine ⟨is_idempotent_elem.mul_of_commute (h₁.commute h₂) h₁.proj h₂.proj, _⟩, intro x, refine le_antisymm _ _, { calc ‖ x ‖ = ‖(P * Q) • x + (x - (P * Q) • x)‖ : by rw add_sub_cancel'_right ((P * Q) • x) x ... ≤ ‖(P * Q) • x‖ + ‖ x - (P * Q) • x ‖ : by apply norm_add_le ... = ‖(P * Q) • x‖ + ‖(1 - P * Q) • x‖ : by rw [sub_smul, one_smul] }, { calc ‖x‖ = ‖P • (Q • x)‖ + (‖Q • x - P • (Q • x)‖ + ‖x - Q • x‖) : by rw [h₂.Lnorm x, h₁.Lnorm (Q • x), sub_smul, one_smul, sub_smul, one_smul, add_assoc] ... ≥ ‖P • (Q • x)‖ + ‖(Q • x - P • (Q • x)) + (x - Q • x)‖ : (add_le_add_iff_left (‖P • (Q • x)‖)).mpr (norm_add_le (Q • x - P • (Q • x)) (x - Q • x)) ... = ‖(P * Q) • x‖ + ‖(1 - P * Q) • x‖ : by rw [sub_add_sub_cancel', sub_smul, one_smul, mul_smul] } end lemma join [has_faithful_smul M X] {P Q : M} (h₁ : is_Lprojection X P) (h₂ : is_Lprojection X Q) : is_Lprojection X (P + Q - P * Q) := begin convert (Lcomplement_iff _).mp (h₁.Lcomplement.mul h₂.Lcomplement) using 1, noncomm_ring, end instance : has_compl { f : M // is_Lprojection X f } := ⟨λ P, ⟨1 - P, P.prop.Lcomplement⟩⟩ @[simp] lemma coe_compl (P : {P : M // is_Lprojection X P}) : ↑(Pᶜ) = (1 : M) - ↑P := rfl instance [has_faithful_smul M X] : has_inf {P : M // is_Lprojection X P} := ⟨λ P Q, ⟨P * Q, P.prop.mul Q.prop⟩ ⟩ @[simp] lemma coe_inf [has_faithful_smul M X] (P Q : {P : M // is_Lprojection X P}) : ↑(P ⊓ Q) = ((↑P : (M)) * ↑Q) := rfl instance [has_faithful_smul M X] : has_sup {P : M // is_Lprojection X P} := ⟨λ P Q, ⟨P + Q - P * Q, P.prop.join Q.prop⟩ ⟩ @[simp] lemma coe_sup [has_faithful_smul M X] (P Q : {P : M // is_Lprojection X P}) : ↑(P ⊔ Q) = ((↑P : M) + ↑Q - ↑P * ↑Q) := rfl instance [has_faithful_smul M X] : has_sdiff {P : M // is_Lprojection X P} := ⟨λ P Q, ⟨P * (1 - Q), by exact P.prop.mul Q.prop.Lcomplement ⟩⟩ @[simp] lemma coe_sdiff [has_faithful_smul M X] (P Q : {P : M // is_Lprojection X P}) : ↑(P \ Q) = (↑P : M) * (1 - ↑Q) := rfl instance [has_faithful_smul M X] : partial_order {P : M // is_Lprojection X P} := { le := λ P Q, (↑P : M) = ↑(P ⊓ Q), le_refl := λ P, by simpa only [coe_inf, ←sq] using (P.prop.proj.eq).symm, le_trans := λ P Q R h₁ h₂, by { simp only [coe_inf] at ⊢ h₁ h₂, rw [h₁, mul_assoc, ←h₂] }, le_antisymm := λ P Q h₁ h₂, subtype.eq (by convert (P.prop.commute Q.prop).eq) } lemma le_def [has_faithful_smul M X] (P Q : {P : M // is_Lprojection X P}) : P ≤ Q ↔ (P : M) = ↑(P ⊓ Q) := iff.rfl instance : has_zero {P : M // is_Lprojection X P} := ⟨⟨0, ⟨by rw [is_idempotent_elem, zero_mul], λ x, by simp only [zero_smul, norm_zero, sub_zero, one_smul, zero_add]⟩⟩⟩ @[simp] lemma coe_zero : ↑(0 : {P : M // is_Lprojection X P}) = (0 : M) := rfl instance : has_one {P : M // is_Lprojection X P} := ⟨⟨1, sub_zero (1 : M) ▸ (0 : {P : M // is_Lprojection X P}).prop.Lcomplement⟩⟩ @[simp] lemma coe_one : ↑(1 : {P : M // is_Lprojection X P}) = (1 : M) := rfl instance [has_faithful_smul M X] : bounded_order {P : M // is_Lprojection X P} := { top := 1, le_top := λ P, (mul_one (P : M)).symm, bot := 0, bot_le := λ P, (zero_mul (P : M)).symm, } @[simp] lemma coe_bot [has_faithful_smul M X] : ↑(bounded_order.bot : {P : M // is_Lprojection X P}) = (0 : M) := rfl @[simp] lemma coe_top [has_faithful_smul M X] : ↑(bounded_order.top : {P : M // is_Lprojection X P}) = (1 : M) := rfl lemma compl_mul {P : {P : M // is_Lprojection X P}} {Q : M} : ↑Pᶜ * Q = Q - ↑P * Q := by rw [coe_compl, sub_mul, one_mul] lemma mul_compl_self {P : {P : M // is_Lprojection X P}} : (↑P : M) * (↑Pᶜ) = 0 := by rw [coe_compl, mul_sub, mul_one, P.prop.proj.eq, sub_self] lemma distrib_lattice_lemma [has_faithful_smul M X] {P Q R : {P : M // is_Lprojection X P}} : ((↑P : M) + ↑Pᶜ * R) * (↑P + ↑Q * ↑R * ↑Pᶜ) = (↑P + ↑Q * ↑R * ↑Pᶜ) := by rw [add_mul, mul_add, mul_add, mul_assoc ↑Pᶜ ↑R (↑Q * ↑R * ↑Pᶜ), ← mul_assoc ↑R (↑Q * ↑R) ↑Pᶜ, ← coe_inf Q, (Pᶜ.prop.commute R.prop).eq, ((Q ⊓ R).prop.commute Pᶜ.prop).eq, (R.prop.commute (Q ⊓ R).prop).eq, coe_inf Q, mul_assoc ↑Q, ← mul_assoc, mul_assoc ↑R, (Pᶜ.prop.commute P.prop).eq, mul_compl_self, zero_mul, mul_zero, zero_add, add_zero, ← mul_assoc, P.prop.proj.eq, R.prop.proj.eq, ← coe_inf Q, mul_assoc, ((Q ⊓ R).prop.commute Pᶜ.prop).eq, ← mul_assoc, Pᶜ.prop.proj.eq] instance [has_faithful_smul M X] : distrib_lattice {P : M // is_Lprojection X P} := { le_sup_left := λ P Q, by rw [le_def, coe_inf, coe_sup, ← add_sub, mul_add, mul_sub, ← mul_assoc, P.prop.proj.eq, sub_self, add_zero], le_sup_right := λ P Q, begin rw [le_def, coe_inf, coe_sup, ← add_sub, mul_add, mul_sub, commute.eq (commute P.prop Q.prop), ← mul_assoc, Q.prop.proj.eq, add_sub_cancel'_right], end, sup_le := λ P Q R, begin rw [le_def, le_def, le_def, coe_inf, coe_inf, coe_sup, coe_inf, coe_sup, ← add_sub, add_mul, sub_mul, mul_assoc], intros h₁ h₂, rw [← h₂, ← h₁], end, inf_le_left := λ P Q, by rw [le_def, coe_inf, coe_inf, coe_inf, mul_assoc, (Q.prop.commute P.prop).eq, ← mul_assoc, P.prop.proj.eq], inf_le_right := λ P Q, by rw [le_def, coe_inf, coe_inf, coe_inf, mul_assoc, Q.prop.proj.eq], le_inf := λ P Q R, begin rw [le_def, le_def, le_def, coe_inf, coe_inf, coe_inf, coe_inf, ← mul_assoc], intros h₁ h₂, rw [← h₁, ← h₂], end, le_sup_inf := λ P Q R, begin have e₁: ↑((P ⊔ Q) ⊓ (P ⊔ R)) = ↑P + ↑Q * ↑R * ↑Pᶜ := by rw [coe_inf, coe_sup, coe_sup, ← add_sub, ← add_sub, ←compl_mul, ←compl_mul, add_mul, mul_add, (Pᶜ.prop.commute Q.prop).eq, mul_add, ← mul_assoc, mul_assoc ↑Q, (Pᶜ.prop.commute P.prop).eq, mul_compl_self, zero_mul, mul_zero, zero_add, add_zero, ← mul_assoc, mul_assoc ↑Q, P.prop.proj.eq, Pᶜ.prop.proj.eq, mul_assoc, (Pᶜ.prop.commute R.prop).eq, ← mul_assoc], have e₂ : ↑((P ⊔ Q) ⊓ (P ⊔ R)) * ↑(P ⊔ Q ⊓ R) = ↑P + ↑Q * ↑R * ↑Pᶜ := by rw [coe_inf, coe_sup, coe_sup, coe_sup, ← add_sub, ← add_sub, ← add_sub, ←compl_mul, ←compl_mul, ←compl_mul, (Pᶜ.prop.commute (Q⊓R).prop).eq, coe_inf, mul_assoc, distrib_lattice_lemma, (Q.prop.commute R.prop).eq, distrib_lattice_lemma], rw [le_def, e₁, coe_inf, e₂], end, .. is_Lprojection.subtype.has_inf, .. is_Lprojection.subtype.has_sup, .. is_Lprojection.subtype.partial_order } instance [has_faithful_smul M X] : boolean_algebra {P : M // is_Lprojection X P} := { inf_compl_le_bot := λ P, (subtype.ext (by rw [coe_inf, coe_compl, coe_bot, ← coe_compl, mul_compl_self])).le, top_le_sup_compl := λ P, (subtype.ext(by rw [coe_top, coe_sup, coe_compl, add_sub_cancel'_right, ← coe_compl, mul_compl_self, sub_zero])).le, sdiff_eq := λ P Q, subtype.ext $ by rw [coe_sdiff, ← coe_compl, coe_inf], .. is_Lprojection.subtype.has_compl, .. is_Lprojection.subtype.has_sdiff, .. is_Lprojection.subtype.bounded_order, .. is_Lprojection.subtype.distrib_lattice } end is_Lprojection
a10d80d6b84538cde51486888cf4356e7e3b23d5
94e33a31faa76775069b071adea97e86e218a8ee
/src/analysis/normed_space/ball_action.lean
c30e8f1deec4e65616eeebcac919eb85fc3306bd
[ "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
4,175
lean
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Heather Macbeth -/ import analysis.normed.field.unit_ball import analysis.normed_space.basic /-! # Multiplicative actions of/on balls and spheres Let `E` be a normed vector space over a normed field `𝕜`. In this file we define the following multiplicative actions. - The closed unit ball in `𝕜` acts on open balls and closed balls centered at `0` in `E`. - The unit sphere in `𝕜` acts on open balls, closed balls, and spheres centered at `0` in `E`. -/ open metric set variables {𝕜 E : Type*} [normed_field 𝕜] [semi_normed_group E] [normed_space 𝕜 E] {r : ℝ} section closed_ball instance mul_action_closed_ball_ball : mul_action (closed_ball (0 : 𝕜) 1) (ball (0 : E) r) := { smul := λ c x, ⟨(c : 𝕜) • x, mem_ball_zero_iff.2 $ by simpa only [norm_smul, one_mul] using mul_lt_mul' (mem_closed_ball_zero_iff.1 c.2) (mem_ball_zero_iff.1 x.2) (norm_nonneg _) one_pos⟩, one_smul := λ x, subtype.ext $ one_smul 𝕜 _, mul_smul := λ c₁ c₂ x, subtype.ext $ mul_smul _ _ _ } instance has_continuous_smul_closed_ball_ball : has_continuous_smul (closed_ball (0 : 𝕜) 1) (ball (0 : E) r) := ⟨continuous_subtype_mk _ $ (continuous_subtype_val.comp continuous_fst).smul (continuous_subtype_val.comp continuous_snd)⟩ instance mul_action_closed_ball_closed_ball : mul_action (closed_ball (0 : 𝕜) 1) (closed_ball (0 : E) r) := { smul := λ c x, ⟨(c : 𝕜) • x, mem_closed_ball_zero_iff.2 $ by simpa only [norm_smul, one_mul] using mul_le_mul (mem_closed_ball_zero_iff.1 c.2) (mem_closed_ball_zero_iff.1 x.2) (norm_nonneg _) zero_le_one⟩, one_smul := λ x, subtype.ext $ one_smul 𝕜 _, mul_smul := λ c₁ c₂ x, subtype.ext $ mul_smul _ _ _ } instance has_continuous_smul_closed_ball_closed_ball : has_continuous_smul (closed_ball (0 : 𝕜) 1) (closed_ball (0 : E) r) := ⟨continuous_subtype_mk _ $ (continuous_subtype_val.comp continuous_fst).smul (continuous_subtype_val.comp continuous_snd)⟩ end closed_ball section sphere instance mul_action_sphere_ball : mul_action (sphere (0 : 𝕜) 1) (ball (0 : E) r) := { smul := λ c x, inclusion sphere_subset_closed_ball c • x, one_smul := λ x, subtype.ext $ one_smul _ _, mul_smul := λ c₁ c₂ x, subtype.ext $ mul_smul _ _ _ } instance has_continuous_smul_sphere_ball : has_continuous_smul (sphere (0 : 𝕜) 1) (ball (0 : E) r) := ⟨continuous_subtype_mk _ $ (continuous_subtype_val.comp continuous_fst).smul (continuous_subtype_val.comp continuous_snd)⟩ instance mul_action_sphere_closed_ball : mul_action (sphere (0 : 𝕜) 1) (closed_ball (0 : E) r) := { smul := λ c x, inclusion sphere_subset_closed_ball c • x, one_smul := λ x, subtype.ext $ one_smul _ _, mul_smul := λ c₁ c₂ x, subtype.ext $ mul_smul _ _ _ } instance has_continuous_smul_sphere_closed_ball : has_continuous_smul (sphere (0 : 𝕜) 1) (closed_ball (0 : E) r) := ⟨continuous_subtype_mk _ $ (continuous_subtype_val.comp continuous_fst).smul (continuous_subtype_val.comp continuous_snd)⟩ instance mul_action_sphere_sphere : mul_action (sphere (0 : 𝕜) 1) (sphere (0 : E) r) := { smul := λ c x, ⟨(c : 𝕜) • x, mem_sphere_zero_iff_norm.2 $ by rw [norm_smul, mem_sphere_zero_iff_norm.1 c.coe_prop, mem_sphere_zero_iff_norm.1 x.coe_prop, one_mul]⟩, one_smul := λ x, subtype.ext $ one_smul _ _, mul_smul := λ c₁ c₂ x, subtype.ext $ mul_smul _ _ _ } instance has_continuous_smul_sphere_sphere : has_continuous_smul (sphere (0 : 𝕜) 1) (sphere (0 : E) r) := ⟨continuous_subtype_mk _ $ (continuous_subtype_val.comp continuous_fst).smul (continuous_subtype_val.comp continuous_snd)⟩ end sphere variables (𝕜) [char_zero 𝕜] lemma ne_neg_of_mem_sphere {r : ℝ} (hr : r ≠ 0) (x : sphere (0:E) r) : x ≠ - x := λ h, ne_zero_of_mem_sphere hr x ((self_eq_neg 𝕜 _).mp (by { conv_lhs {rw h}, simp })) lemma ne_neg_of_mem_unit_sphere (x : sphere (0:E) 1) : x ≠ - x := ne_neg_of_mem_sphere 𝕜 one_ne_zero x
4c9172b0b9f69aa1d475b284a81fa20eacca2583
9dc8cecdf3c4634764a18254e94d43da07142918
/src/logic/equiv/basic.lean
af1fdde196ec5cbe660cbde99f62d364adc7f171
[ "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
95,788
lean
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Mario Carneiro -/ import data.fun_like.equiv import data.option.basic import data.prod.basic import data.quot import data.sigma.basic import data.subtype import data.sum.basic import logic.function.conjugate import logic.unique import tactic.norm_cast import tactic.simps /-! # Equivalence between types In this file we define two types: * `equiv α β` a.k.a. `α ≃ β`: a bijective map `α → β` bundled with its inverse map; we use this (and not equality!) to express that various `Type`s or `Sort`s are equivalent. * `equiv.perm α`: the group of permutations `α ≃ α`. More lemmas about `equiv.perm` can be found in `group_theory/perm`. Then we define * canonical isomorphisms between various types: e.g., - `equiv.refl α` is the identity map interpreted as `α ≃ α`; - `equiv.sum_equiv_sigma_bool` is the canonical equivalence between the sum of two types `α ⊕ β` and the sigma-type `Σ b : bool, cond b α β`; - `equiv.prod_sum_distrib : α × (β ⊕ γ) ≃ (α × β) ⊕ (α × γ)` shows that type product and type sum satisfy the distributive law up to a canonical equivalence; * operations on equivalences: e.g., - `equiv.symm e : β ≃ α` is the inverse of `e : α ≃ β`; - `equiv.trans e₁ e₂ : α ≃ γ` is the composition of `e₁ : α ≃ β` and `e₂ : β ≃ γ` (note the order of the arguments!); - `equiv.prod_congr ea eb : α₁ × β₁ ≃ α₂ × β₂`: combine two equivalences `ea : α₁ ≃ α₂` and `eb : β₁ ≃ β₂` using `prod.map`. * definitions that transfer some instances along an equivalence. By convention, we transfer instances from right to left. - `equiv.inhabited` takes `e : α ≃ β` and `[inhabited β]` and returns `inhabited α`; - `equiv.unique` takes `e : α ≃ β` and `[unique β]` and returns `unique α`; - `equiv.decidable_eq` takes `e : α ≃ β` and `[decidable_eq β]` and returns `decidable_eq α`. More definitions of this kind can be found in other files. E.g., `data/equiv/transfer_instance` does it for many algebraic type classes like `group`, `module`, etc. ## Tags equivalence, congruence, bijective map -/ open function universes u v w z variables {α : Sort u} {β : Sort v} {γ : Sort w} /-- `α ≃ β` is the type of functions from `α → β` with a two-sided inverse. -/ structure equiv (α : Sort*) (β : Sort*) := (to_fun : α → β) (inv_fun : β → α) (left_inv : left_inverse inv_fun to_fun) (right_inv : right_inverse inv_fun to_fun) infix ` ≃ `:25 := equiv instance {F} [equiv_like F α β] : has_coe_t F (α ≃ β) := ⟨λ f, { to_fun := f, inv_fun := equiv_like.inv f, left_inv := equiv_like.left_inv f, right_inv := equiv_like.right_inv f }⟩ /-- `perm α` is the type of bijections from `α` to itself. -/ @[reducible] def equiv.perm (α : Sort*) := equiv α α namespace equiv instance : equiv_like (α ≃ β) α β := { coe := to_fun, inv := inv_fun, left_inv := left_inv, right_inv := right_inv, coe_injective' := λ e₁ e₂ h₁ h₂, by { cases e₁, cases e₂, congr' } } instance : has_coe_to_fun (α ≃ β) (λ _, α → β) := ⟨to_fun⟩ @[simp] theorem coe_fn_mk (f : α → β) (g l r) : (equiv.mk f g l r : α → β) = f := rfl /-- The map `coe_fn : (r ≃ s) → (r → s)` is injective. -/ theorem coe_fn_injective : @function.injective (α ≃ β) (α → β) coe_fn := fun_like.coe_injective protected lemma coe_inj {e₁ e₂ : α ≃ β} : (e₁ : α → β) = e₂ ↔ e₁ = e₂ := fun_like.coe_fn_eq @[ext] lemma ext {f g : equiv α β} (H : ∀ x, f x = g x) : f = g := fun_like.ext f g H protected lemma congr_arg {f : equiv α β} {x x' : α} : x = x' → f x = f x' := fun_like.congr_arg f protected lemma congr_fun {f g : equiv α β} (h : f = g) (x : α) : f x = g x := fun_like.congr_fun h x lemma ext_iff {f g : equiv α β} : f = g ↔ ∀ x, f x = g x := fun_like.ext_iff @[ext] lemma perm.ext {σ τ : equiv.perm α} (H : ∀ x, σ x = τ x) : σ = τ := equiv.ext H protected lemma perm.congr_arg {f : equiv.perm α} {x x' : α} : x = x' → f x = f x' := equiv.congr_arg protected lemma perm.congr_fun {f g : equiv.perm α} (h : f = g) (x : α) : f x = g x := equiv.congr_fun h x lemma perm.ext_iff {σ τ : equiv.perm α} : σ = τ ↔ ∀ x, σ x = τ x := ext_iff /-- Any type is equivalent to itself. -/ @[refl] protected def refl (α : Sort*) : α ≃ α := ⟨id, id, λ x, rfl, λ x, rfl⟩ instance inhabited' : inhabited (α ≃ α) := ⟨equiv.refl α⟩ /-- Inverse of an equivalence `e : α ≃ β`. -/ @[symm] protected def symm (e : α ≃ β) : β ≃ α := ⟨e.inv_fun, e.to_fun, e.right_inv, e.left_inv⟩ /-- See Note [custom simps projection] -/ def simps.symm_apply (e : α ≃ β) : β → α := e.symm initialize_simps_projections equiv (to_fun → apply, inv_fun → symm_apply) /-- Composition of equivalences `e₁ : α ≃ β` and `e₂ : β ≃ γ`. -/ @[trans] protected def trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ := ⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm, e₂.left_inv.comp e₁.left_inv, e₂.right_inv.comp e₁.right_inv⟩ @[simp] lemma to_fun_as_coe (e : α ≃ β) : e.to_fun = e := rfl @[simp] lemma inv_fun_as_coe (e : α ≃ β) : e.inv_fun = e.symm := rfl protected theorem injective (e : α ≃ β) : injective e := equiv_like.injective e protected theorem surjective (e : α ≃ β) : surjective e := equiv_like.surjective e protected theorem bijective (e : α ≃ β) : bijective e := equiv_like.bijective e protected theorem subsingleton (e : α ≃ β) [subsingleton β] : subsingleton α := e.injective.subsingleton protected theorem subsingleton.symm (e : α ≃ β) [subsingleton α] : subsingleton β := e.symm.injective.subsingleton lemma subsingleton_congr (e : α ≃ β) : subsingleton α ↔ subsingleton β := ⟨λ h, by exactI e.symm.subsingleton, λ h, by exactI e.subsingleton⟩ instance equiv_subsingleton_cod [subsingleton β] : subsingleton (α ≃ β) := ⟨λ f g, equiv.ext $ λ x, subsingleton.elim _ _⟩ instance equiv_subsingleton_dom [subsingleton α] : subsingleton (α ≃ β) := ⟨λ f g, equiv.ext $ λ x, @subsingleton.elim _ (equiv.subsingleton.symm f) _ _⟩ instance perm_unique [subsingleton α] : unique (perm α) := unique_of_subsingleton (equiv.refl α) lemma perm.subsingleton_eq_refl [subsingleton α] (e : perm α) : e = equiv.refl α := subsingleton.elim _ _ /-- Transfer `decidable_eq` across an equivalence. -/ protected def decidable_eq (e : α ≃ β) [decidable_eq β] : decidable_eq α := e.injective.decidable_eq lemma nonempty_congr (e : α ≃ β) : nonempty α ↔ nonempty β := nonempty.congr e e.symm protected lemma nonempty (e : α ≃ β) [nonempty β] : nonempty α := e.nonempty_congr.mpr ‹_› /-- If `α ≃ β` and `β` is inhabited, then so is `α`. -/ protected def inhabited [inhabited β] (e : α ≃ β) : inhabited α := ⟨e.symm default⟩ /-- If `α ≃ β` and `β` is a singleton type, then so is `α`. -/ protected def unique [unique β] (e : α ≃ β) : unique α := e.symm.surjective.unique /-- Equivalence between equal types. -/ protected def cast {α β : Sort*} (h : α = β) : α ≃ β := ⟨cast h, cast h.symm, λ x, by { cases h, refl }, λ x, by { cases h, refl }⟩ @[simp] theorem coe_fn_symm_mk (f : α → β) (g l r) : ((equiv.mk f g l r).symm : β → α) = g := rfl @[simp] theorem coe_refl : ⇑(equiv.refl α) = id := rfl /-- This cannot be a `simp` lemmas as it incorrectly matches against `e : α ≃ synonym α`, when `synonym α` is semireducible. This makes a mess of `multiplicative.of_add` etc. -/ theorem perm.coe_subsingleton {α : Type*} [subsingleton α] (e : perm α) : ⇑(e) = id := by rw [perm.subsingleton_eq_refl e, coe_refl] theorem refl_apply (x : α) : equiv.refl α x = x := rfl @[simp] theorem coe_trans (f : α ≃ β) (g : β ≃ γ) : ⇑(f.trans g) = g ∘ f := rfl theorem trans_apply (f : α ≃ β) (g : β ≃ γ) (a : α) : (f.trans g) a = g (f a) := rfl @[simp] theorem apply_symm_apply (e : α ≃ β) (x : β) : e (e.symm x) = x := e.right_inv x @[simp] theorem symm_apply_apply (e : α ≃ β) (x : α) : e.symm (e x) = x := e.left_inv x @[simp] theorem symm_comp_self (e : α ≃ β) : e.symm ∘ e = id := funext e.symm_apply_apply @[simp] theorem self_comp_symm (e : α ≃ β) : e ∘ e.symm = id := funext e.apply_symm_apply @[simp] lemma symm_trans_apply (f : α ≃ β) (g : β ≃ γ) (a : γ) : (f.trans g).symm a = f.symm (g.symm a) := rfl -- The `simp` attribute is needed to make this a `dsimp` lemma. -- `simp` will always rewrite with `equiv.symm_symm` before this has a chance to fire. @[simp, nolint simp_nf] theorem symm_symm_apply (f : α ≃ β) (b : α) : f.symm.symm b = f b := rfl theorem apply_eq_iff_eq (f : α ≃ β) {x y : α} : f x = f y ↔ x = y := equiv_like.apply_eq_iff_eq f theorem apply_eq_iff_eq_symm_apply {α β : Sort*} (f : α ≃ β) {x : α} {y : β} : f x = y ↔ x = f.symm y := begin conv_lhs { rw ←apply_symm_apply f y, }, rw apply_eq_iff_eq, end @[simp] theorem cast_apply {α β} (h : α = β) (x : α) : equiv.cast h x = cast h x := rfl @[simp] theorem cast_symm {α β} (h : α = β) : (equiv.cast h).symm = equiv.cast h.symm := rfl @[simp] theorem cast_refl {α} (h : α = α := rfl) : equiv.cast h = equiv.refl α := rfl @[simp] theorem cast_trans {α β γ} (h : α = β) (h2 : β = γ) : (equiv.cast h).trans (equiv.cast h2) = equiv.cast (h.trans h2) := ext $ λ x, by { substs h h2, refl } lemma cast_eq_iff_heq {α β} (h : α = β) {a : α} {b : β} : equiv.cast h a = b ↔ a == b := by { subst h, simp } lemma symm_apply_eq {α β} (e : α ≃ β) {x y} : e.symm x = y ↔ x = e y := ⟨λ H, by simp [H.symm], λ H, by simp [H]⟩ lemma eq_symm_apply {α β} (e : α ≃ β) {x y} : y = e.symm x ↔ e y = x := (eq_comm.trans e.symm_apply_eq).trans eq_comm @[simp] theorem symm_symm (e : α ≃ β) : e.symm.symm = e := by { cases e, refl } @[simp] theorem trans_refl (e : α ≃ β) : e.trans (equiv.refl β) = e := by { cases e, refl } @[simp] theorem refl_symm : (equiv.refl α).symm = equiv.refl α := rfl @[simp] theorem refl_trans (e : α ≃ β) : (equiv.refl α).trans e = e := by { cases e, refl } @[simp] theorem symm_trans_self (e : α ≃ β) : e.symm.trans e = equiv.refl β := ext (by simp) @[simp] theorem self_trans_symm (e : α ≃ β) : e.trans e.symm = equiv.refl α := ext (by simp) lemma trans_assoc {δ} (ab : α ≃ β) (bc : β ≃ γ) (cd : γ ≃ δ) : (ab.trans bc).trans cd = ab.trans (bc.trans cd) := equiv.ext $ assume a, rfl theorem left_inverse_symm (f : equiv α β) : left_inverse f.symm f := f.left_inv theorem right_inverse_symm (f : equiv α β) : function.right_inverse f.symm f := f.right_inv lemma injective_comp (e : α ≃ β) (f : β → γ) : injective (f ∘ e) ↔ injective f := equiv_like.injective_comp e f lemma comp_injective (f : α → β) (e : β ≃ γ) : injective (e ∘ f) ↔ injective f := equiv_like.comp_injective f e lemma surjective_comp (e : α ≃ β) (f : β → γ) : surjective (f ∘ e) ↔ surjective f := equiv_like.surjective_comp e f lemma comp_surjective (f : α → β) (e : β ≃ γ) : surjective (e ∘ f) ↔ surjective f := equiv_like.comp_surjective f e lemma bijective_comp (e : α ≃ β) (f : β → γ) : bijective (f ∘ e) ↔ bijective f := equiv_like.bijective_comp e f lemma comp_bijective (f : α → β) (e : β ≃ γ) : bijective (e ∘ f) ↔ bijective f := equiv_like.comp_bijective f e /-- If `α` is equivalent to `β` and `γ` is equivalent to `δ`, then the type of equivalences `α ≃ γ` is equivalent to the type of equivalences `β ≃ δ`. -/ def equiv_congr {δ} (ab : α ≃ β) (cd : γ ≃ δ) : (α ≃ γ) ≃ (β ≃ δ) := ⟨ λac, (ab.symm.trans ac).trans cd, λbd, ab.trans $ bd.trans $ cd.symm, assume ac, by { ext x, simp }, assume ac, by { ext x, simp } ⟩ @[simp] lemma equiv_congr_refl {α β} : (equiv.refl α).equiv_congr (equiv.refl β) = equiv.refl (α ≃ β) := by { ext, refl } @[simp] lemma equiv_congr_symm {δ} (ab : α ≃ β) (cd : γ ≃ δ) : (ab.equiv_congr cd).symm = ab.symm.equiv_congr cd.symm := by { ext, refl } @[simp] lemma equiv_congr_trans {δ ε ζ} (ab : α ≃ β) (de : δ ≃ ε) (bc : β ≃ γ) (ef : ε ≃ ζ) : (ab.equiv_congr de).trans (bc.equiv_congr ef) = (ab.trans bc).equiv_congr (de.trans ef) := by { ext, refl } @[simp] lemma equiv_congr_refl_left {α β γ} (bg : β ≃ γ) (e : α ≃ β) : (equiv.refl α).equiv_congr bg e = e.trans bg := rfl @[simp] lemma equiv_congr_refl_right {α β} (ab e : α ≃ β) : ab.equiv_congr (equiv.refl β) e = ab.symm.trans e := rfl @[simp] lemma equiv_congr_apply_apply {δ} (ab : α ≃ β) (cd : γ ≃ δ) (e : α ≃ γ) (x) : ab.equiv_congr cd e x = cd (e (ab.symm x)) := rfl section perm_congr variables {α' β' : Type*} (e : α' ≃ β') /-- If `α` is equivalent to `β`, then `perm α` is equivalent to `perm β`. -/ def perm_congr : perm α' ≃ perm β' := equiv_congr e e lemma perm_congr_def (p : equiv.perm α') : e.perm_congr p = (e.symm.trans p).trans e := rfl @[simp] lemma perm_congr_refl : e.perm_congr (equiv.refl _) = equiv.refl _ := by simp [perm_congr_def] @[simp] lemma perm_congr_symm : e.perm_congr.symm = e.symm.perm_congr := rfl @[simp] lemma perm_congr_apply (p : equiv.perm α') (x) : e.perm_congr p x = e (p (e.symm x)) := rfl lemma perm_congr_symm_apply (p : equiv.perm β') (x) : e.perm_congr.symm p x = e.symm (p (e x)) := rfl lemma perm_congr_trans (p p' : equiv.perm α') : (e.perm_congr p).trans (e.perm_congr p') = e.perm_congr (p.trans p') := by { ext, simp } end perm_congr /-- Two empty types are equivalent. -/ def equiv_of_is_empty (α β : Sort*) [is_empty α] [is_empty β] : α ≃ β := ⟨is_empty_elim, is_empty_elim, is_empty_elim, is_empty_elim⟩ /-- If `α` is an empty type, then it is equivalent to the `empty` type. -/ def equiv_empty (α : Sort u) [is_empty α] : α ≃ empty := equiv_of_is_empty α _ /-- If `α` is an empty type, then it is equivalent to the `pempty` type in any universe. -/ def equiv_pempty (α : Sort v) [is_empty α] : α ≃ pempty.{u} := equiv_of_is_empty α _ /-- `α` is equivalent to an empty type iff `α` is empty. -/ def equiv_empty_equiv (α : Sort u) : (α ≃ empty) ≃ is_empty α := ⟨λ e, function.is_empty e, @equiv_empty α, λ e, ext $ λ x, (e x).elim, λ p, rfl⟩ /-- The `Sort` of proofs of a false proposition is equivalent to `pempty`. -/ def prop_equiv_pempty {p : Prop} (h : ¬p) : p ≃ pempty := @equiv_pempty p $ is_empty.prop_iff.2 h /-- If both `α` and `β` have a unique element, then `α ≃ β`. -/ def equiv_of_unique (α β : Sort*) [unique α] [unique β] : α ≃ β := { to_fun := default, inv_fun := default, left_inv := λ _, subsingleton.elim _ _, right_inv := λ _, subsingleton.elim _ _ } /-- If `α` has a unique element, then it is equivalent to any `punit`. -/ def equiv_punit (α : Sort*) [unique α] : α ≃ punit.{v} := equiv_of_unique α _ /-- The `Sort` of proofs of a true proposition is equivalent to `punit`. -/ def prop_equiv_punit {p : Prop} (h : p) : p ≃ punit := @equiv_punit p $ unique_prop h /-- `ulift α` is equivalent to `α`. -/ @[simps apply symm_apply {fully_applied := ff}] protected def ulift {α : Type v} : ulift.{u} α ≃ α := ⟨ulift.down, ulift.up, ulift.up_down, λ a, rfl⟩ /-- `plift α` is equivalent to `α`. -/ @[simps apply symm_apply {fully_applied := ff}] protected def plift : plift α ≃ α := ⟨plift.down, plift.up, plift.up_down, plift.down_up⟩ /-- `pprod α β` is equivalent to `α × β` -/ @[simps apply symm_apply] def pprod_equiv_prod {α β : Type*} : pprod α β ≃ α × β := { to_fun := λ x, (x.1, x.2), inv_fun := λ x, ⟨x.1, x.2⟩, left_inv := λ ⟨x, y⟩, rfl, right_inv := λ ⟨x, y⟩, rfl } /-- Product of two equivalences, in terms of `pprod`. If `α ≃ β` and `γ ≃ δ`, then `pprod α γ ≃ pprod β δ`. -/ @[congr, simps apply] def pprod_congr {δ : Sort z} (e₁ : α ≃ β) (e₂ : γ ≃ δ) : pprod α γ ≃ pprod β δ := { to_fun := λ x, ⟨e₁ x.1, e₂ x.2⟩, inv_fun := λ x, ⟨e₁.symm x.1, e₂.symm x.2⟩, left_inv := λ ⟨x, y⟩, by simp, right_inv := λ ⟨x, y⟩, by simp } /-- Combine two equivalences using `pprod` in the domain and `prod` in the codomain. -/ @[simps apply symm_apply] def pprod_prod {α₁ β₁ : Sort*} {α₂ β₂ : Type*} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : pprod α₁ β₁ ≃ α₂ × β₂ := (ea.pprod_congr eb).trans pprod_equiv_prod /-- Combine two equivalences using `pprod` in the codomain and `prod` in the domain. -/ @[simps apply symm_apply] def prod_pprod {α₁ β₁ : Type*} {α₂ β₂ : Sort*} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : α₁ × β₁ ≃ pprod α₂ β₂ := (ea.symm.pprod_prod eb.symm).symm /-- `pprod α β` is equivalent to `plift α × plift β` -/ @[simps apply symm_apply] def pprod_equiv_prod_plift {α β : Sort*} : pprod α β ≃ plift α × plift β := equiv.plift.symm.pprod_prod equiv.plift.symm /-- equivalence of propositions is the same as iff -/ def of_iff {P Q : Prop} (h : P ↔ Q) : P ≃ Q := { to_fun := h.mp, inv_fun := h.mpr, left_inv := λ x, rfl, right_inv := λ y, rfl } /-- If `α₁` is equivalent to `α₂` and `β₁` is equivalent to `β₂`, then the type of maps `α₁ → β₁` is equivalent to the type of maps `α₂ → β₂`. -/ @[congr, simps apply] def arrow_congr {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : (α₁ → β₁) ≃ (α₂ → β₂) := { to_fun := λ f, e₂ ∘ f ∘ e₁.symm, inv_fun := λ f, e₂.symm ∘ f ∘ e₁, left_inv := λ f, funext $ λ x, by simp, right_inv := λ f, funext $ λ x, by simp } lemma arrow_congr_comp {α₁ β₁ γ₁ α₂ β₂ γ₂ : Sort*} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) (ec : γ₁ ≃ γ₂) (f : α₁ → β₁) (g : β₁ → γ₁) : arrow_congr ea ec (g ∘ f) = (arrow_congr eb ec g) ∘ (arrow_congr ea eb f) := by { ext, simp only [comp, arrow_congr_apply, eb.symm_apply_apply] } @[simp] lemma arrow_congr_refl {α β : Sort*} : arrow_congr (equiv.refl α) (equiv.refl β) = equiv.refl (α → β) := rfl @[simp] lemma arrow_congr_trans {α₁ β₁ α₂ β₂ α₃ β₃ : Sort*} (e₁ : α₁ ≃ α₂) (e₁' : β₁ ≃ β₂) (e₂ : α₂ ≃ α₃) (e₂' : β₂ ≃ β₃) : arrow_congr (e₁.trans e₂) (e₁'.trans e₂') = (arrow_congr e₁ e₁').trans (arrow_congr e₂ e₂') := rfl @[simp] lemma arrow_congr_symm {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : (arrow_congr e₁ e₂).symm = arrow_congr e₁.symm e₂.symm := rfl /-- A version of `equiv.arrow_congr` in `Type`, rather than `Sort`. The `equiv_rw` tactic is not able to use the default `Sort` level `equiv.arrow_congr`, because Lean's universe rules will not unify `?l_1` with `imax (1 ?m_1)`. -/ @[congr, simps apply] def arrow_congr' {α₁ β₁ α₂ β₂ : Type*} (hα : α₁ ≃ α₂) (hβ : β₁ ≃ β₂) : (α₁ → β₁) ≃ (α₂ → β₂) := equiv.arrow_congr hα hβ @[simp] lemma arrow_congr'_refl {α β : Type*} : arrow_congr' (equiv.refl α) (equiv.refl β) = equiv.refl (α → β) := rfl @[simp] lemma arrow_congr'_trans {α₁ β₁ α₂ β₂ α₃ β₃ : Type*} (e₁ : α₁ ≃ α₂) (e₁' : β₁ ≃ β₂) (e₂ : α₂ ≃ α₃) (e₂' : β₂ ≃ β₃) : arrow_congr' (e₁.trans e₂) (e₁'.trans e₂') = (arrow_congr' e₁ e₁').trans (arrow_congr' e₂ e₂') := rfl @[simp] lemma arrow_congr'_symm {α₁ β₁ α₂ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : (arrow_congr' e₁ e₂).symm = arrow_congr' e₁.symm e₂.symm := rfl /-- Conjugate a map `f : α → α` by an equivalence `α ≃ β`. -/ @[simps apply] def conj (e : α ≃ β) : (α → α) ≃ (β → β) := arrow_congr e e @[simp] lemma conj_refl : conj (equiv.refl α) = equiv.refl (α → α) := rfl @[simp] lemma conj_symm (e : α ≃ β) : e.conj.symm = e.symm.conj := rfl @[simp] lemma conj_trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : (e₁.trans e₂).conj = e₁.conj.trans e₂.conj := rfl -- This should not be a simp lemma as long as `(∘)` is reducible: -- when `(∘)` is reducible, Lean can unify `f₁ ∘ f₂` with any `g` using -- `f₁ := g` and `f₂ := λ x, x`. This causes nontermination. lemma conj_comp (e : α ≃ β) (f₁ f₂ : α → α) : e.conj (f₁ ∘ f₂) = (e.conj f₁) ∘ (e.conj f₂) := by apply arrow_congr_comp lemma eq_comp_symm {α β γ} (e : α ≃ β) (f : β → γ) (g : α → γ) : f = g ∘ e.symm ↔ f ∘ e = g := (e.arrow_congr (equiv.refl γ)).symm_apply_eq.symm lemma comp_symm_eq {α β γ} (e : α ≃ β) (f : β → γ) (g : α → γ) : g ∘ e.symm = f ↔ g = f ∘ e := (e.arrow_congr (equiv.refl γ)).eq_symm_apply.symm lemma eq_symm_comp {α β γ} (e : α ≃ β) (f : γ → α) (g : γ → β) : f = e.symm ∘ g ↔ e ∘ f = g := ((equiv.refl γ).arrow_congr e).eq_symm_apply lemma symm_comp_eq {α β γ} (e : α ≃ β) (f : γ → α) (g : γ → β) : e.symm ∘ g = f ↔ g = e ∘ f := ((equiv.refl γ).arrow_congr e).symm_apply_eq section binary_op variables {α₁ β₁ : Type*} (e : α₁ ≃ β₁) (f : α₁ → α₁ → α₁) lemma semiconj_conj (f : α₁ → α₁) : semiconj e f (e.conj f) := λ x, by simp lemma semiconj₂_conj : semiconj₂ e f (e.arrow_congr e.conj f) := λ x y, by simp instance [is_associative α₁ f] : is_associative β₁ (e.arrow_congr (e.arrow_congr e) f) := (e.semiconj₂_conj f).is_associative_right e.surjective instance [is_idempotent α₁ f] : is_idempotent β₁ (e.arrow_congr (e.arrow_congr e) f) := (e.semiconj₂_conj f).is_idempotent_right e.surjective instance [is_left_cancel α₁ f] : is_left_cancel β₁ (e.arrow_congr (e.arrow_congr e) f) := ⟨e.surjective.forall₃.2 $ λ x y z, by simpa using @is_left_cancel.left_cancel _ f _ x y z⟩ instance [is_right_cancel α₁ f] : is_right_cancel β₁ (e.arrow_congr (e.arrow_congr e) f) := ⟨e.surjective.forall₃.2 $ λ x y z, by simpa using @is_right_cancel.right_cancel _ f _ x y z⟩ end binary_op /-- `punit` sorts in any two universes are equivalent. -/ def punit_equiv_punit : punit.{v} ≃ punit.{w} := ⟨λ _, punit.star, λ _, punit.star, λ u, by { cases u, refl }, λ u, by { cases u, reflexivity }⟩ section /-- The sort of maps to `punit.{v}` is equivalent to `punit.{w}`. -/ def arrow_punit_equiv_punit (α : Sort*) : (α → punit.{v}) ≃ punit.{w} := ⟨λ f, punit.star, λ u f, punit.star, λ f, by { funext x, cases f x, refl }, λ u, by { cases u, reflexivity }⟩ /-- If `α` is `subsingleton` and `a : α`, then the type of dependent functions `Π (i : α), β i` is equivalent to `β i`. -/ @[simps] def Pi_subsingleton {α} (β : α → Sort*) [subsingleton α] (a : α) : (Π a', β a') ≃ β a := { to_fun := eval a, inv_fun := λ x b, cast (congr_arg β $ subsingleton.elim a b) x, left_inv := λ f, funext $ λ b, by { rw subsingleton.elim b a, reflexivity }, right_inv := λ b, rfl } /-- If `α` has a unique term, then the type of function `α → β` is equivalent to `β`. -/ @[simps { fully_applied := ff }] def fun_unique (α β) [unique α] : (α → β) ≃ β := Pi_subsingleton _ default /-- The sort of maps from `punit` is equivalent to the codomain. -/ def punit_arrow_equiv (α : Sort*) : (punit.{u} → α) ≃ α := fun_unique _ _ /-- The sort of maps from `true` is equivalent to the codomain. -/ def true_arrow_equiv (α : Sort*) : (true → α) ≃ α := fun_unique _ _ /-- The sort of maps from a type that `is_empty` is equivalent to `punit`. -/ def arrow_punit_of_is_empty (α β : Sort*) [is_empty α] : (α → β) ≃ punit.{u} := ⟨λ f, punit.star, λ u, is_empty_elim, λ f, funext is_empty_elim, λ u, by { cases u, refl }⟩ /-- The sort of maps from `empty` is equivalent to `punit`. -/ def empty_arrow_equiv_punit (α : Sort*) : (empty → α) ≃ punit.{u} := arrow_punit_of_is_empty _ _ /-- The sort of maps from `pempty` is equivalent to `punit`. -/ def pempty_arrow_equiv_punit (α : Sort*) : (pempty → α) ≃ punit.{u} := arrow_punit_of_is_empty _ _ /-- The sort of maps from `false` is equivalent to `punit`. -/ def false_arrow_equiv_punit (α : Sort*) : (false → α) ≃ punit.{u} := arrow_punit_of_is_empty _ _ end /-- Product of two equivalences. If `α₁ ≃ α₂` and `β₁ ≃ β₂`, then `α₁ × β₁ ≃ α₂ × β₂`. This is `prod.map` as an equivalence. -/ @[congr, simps apply] def prod_congr {α₁ β₁ α₂ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : α₁ × β₁ ≃ α₂ × β₂ := ⟨prod.map e₁ e₂, prod.map e₁.symm e₂.symm, λ ⟨a, b⟩, by simp, λ ⟨a, b⟩, by simp⟩ @[simp] theorem prod_congr_symm {α₁ β₁ α₂ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : (prod_congr e₁ e₂).symm = prod_congr e₁.symm e₂.symm := rfl /-- Type product is commutative up to an equivalence: `α × β ≃ β × α`. This is `prod.swap` as an equivalence.-/ @[simps apply] def prod_comm (α β : Type*) : α × β ≃ β × α := ⟨prod.swap, prod.swap, λ ⟨a, b⟩, rfl, λ ⟨a, b⟩, rfl⟩ @[simp] lemma prod_comm_symm (α β) : (prod_comm α β).symm = prod_comm β α := rfl /-- Type product is associative up to an equivalence. -/ @[simps] def prod_assoc (α β γ : Sort*) : (α × β) × γ ≃ α × (β × γ) := ⟨λ p, (p.1.1, p.1.2, p.2), λ p, ((p.1, p.2.1), p.2.2), λ ⟨⟨a, b⟩, c⟩, rfl, λ ⟨a, ⟨b, c⟩⟩, rfl⟩ /-- Functions on `α × β` are equivalent to functions `α → β → γ`. -/ @[simps {fully_applied := ff}] def curry (α β γ : Type*) : (α × β → γ) ≃ (α → β → γ) := { to_fun := curry, inv_fun := uncurry, left_inv := uncurry_curry, right_inv := curry_uncurry } section /-- `punit` is a right identity for type product up to an equivalence. -/ @[simps] def prod_punit (α : Type*) : α × punit.{u+1} ≃ α := ⟨λ p, p.1, λ a, (a, punit.star), λ ⟨_, punit.star⟩, rfl, λ a, rfl⟩ /-- `punit` is a left identity for type product up to an equivalence. -/ @[simps] def punit_prod (α : Type*) : punit.{u+1} × α ≃ α := calc punit × α ≃ α × punit : prod_comm _ _ ... ≃ α : prod_punit _ /-- Any `unique` type is a right identity for type product up to equivalence. -/ def prod_unique (α β : Type*) [unique β] : α × β ≃ α := ((equiv.refl α).prod_congr $ equiv_punit β).trans $ prod_punit α @[simp] lemma coe_prod_unique {α β : Type*} [unique β] : ⇑(prod_unique α β) = prod.fst := rfl lemma prod_unique_apply {α β : Type*} [unique β] (x : α × β) : prod_unique α β x = x.1 := rfl @[simp] lemma prod_unique_symm_apply {α β : Type*} [unique β] (x : α) : (prod_unique α β).symm x = (x, default) := rfl /-- Any `unique` type is a left identity for type product up to equivalence. -/ def unique_prod (α β : Type*) [unique β] : β × α ≃ α := ((equiv_punit β).prod_congr $ equiv.refl α).trans $ punit_prod α @[simp] lemma coe_unique_prod {α β : Type*} [unique β] : ⇑(unique_prod α β) = prod.snd := rfl lemma unique_prod_apply {α β : Type*} [unique β] (x : β × α) : unique_prod α β x = x.2 := rfl @[simp] lemma unique_prod_symm_apply {α β : Type*} [unique β] (x : α) : (unique_prod α β).symm x = (default, x) := rfl /-- `empty` type is a right absorbing element for type product up to an equivalence. -/ def prod_empty (α : Type*) : α × empty ≃ empty := equiv_empty _ /-- `empty` type is a left absorbing element for type product up to an equivalence. -/ def empty_prod (α : Type*) : empty × α ≃ empty := equiv_empty _ /-- `pempty` type is a right absorbing element for type product up to an equivalence. -/ def prod_pempty (α : Type*) : α × pempty ≃ pempty := equiv_pempty _ /-- `pempty` type is a left absorbing element for type product up to an equivalence. -/ def pempty_prod (α : Type*) : pempty × α ≃ pempty := equiv_pempty _ end section open sum /-- `psum` is equivalent to `sum`. -/ def psum_equiv_sum (α β : Type*) : psum α β ≃ α ⊕ β := { to_fun := λ s, psum.cases_on s inl inr, inv_fun := sum.elim psum.inl psum.inr, left_inv := λ s, by cases s; refl, right_inv := λ s, by cases s; refl } /-- If `α ≃ α'` and `β ≃ β'`, then `α ⊕ β ≃ α' ⊕ β'`. This is `sum.map` as an equivalence. -/ @[simps apply] def sum_congr {α₁ β₁ α₂ β₂ : Type*} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : α₁ ⊕ β₁ ≃ α₂ ⊕ β₂ := ⟨sum.map ea eb, sum.map ea.symm eb.symm, λ x, by simp, λ x, by simp⟩ /-- If `α ≃ α'` and `β ≃ β'`, then `psum α β ≃ psum α' β'`. -/ def psum_congr {δ : Sort z} (e₁ : α ≃ β) (e₂ : γ ≃ δ) : psum α γ ≃ psum β δ := { to_fun := λ x, psum.cases_on x (psum.inl ∘ e₁) (psum.inr ∘ e₂), inv_fun := λ x, psum.cases_on x (psum.inl ∘ e₁.symm) (psum.inr ∘ e₂.symm), left_inv := by rintro (x|x); simp, right_inv := by rintro (x|x); simp } /-- Combine two `equiv`s using `psum` in the domain and `sum` in the codomain. -/ def psum_sum {α₁ β₁ : Sort*} {α₂ β₂ : Type*} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : psum α₁ β₁ ≃ α₂ ⊕ β₂ := (ea.psum_congr eb).trans (psum_equiv_sum _ _) /-- Combine two `equiv`s using `sum` in the domain and `psum` in the codomain. -/ def sum_psum {α₁ β₁ : Type*} {α₂ β₂ : Sort*} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : α₁ ⊕ β₁ ≃ psum α₂ β₂ := (ea.symm.psum_sum eb.symm).symm @[simp] lemma sum_congr_trans {α₁ α₂ β₁ β₂ γ₁ γ₂ : Sort*} (e : α₁ ≃ β₁) (f : α₂ ≃ β₂) (g : β₁ ≃ γ₁) (h : β₂ ≃ γ₂) : (equiv.sum_congr e f).trans (equiv.sum_congr g h) = (equiv.sum_congr (e.trans g) (f.trans h)) := by { ext i, cases i; refl } @[simp] lemma sum_congr_symm {α β γ δ : Sort*} (e : α ≃ β) (f : γ ≃ δ) : (equiv.sum_congr e f).symm = (equiv.sum_congr (e.symm) (f.symm)) := rfl @[simp] lemma sum_congr_refl {α β : Sort*} : equiv.sum_congr (equiv.refl α) (equiv.refl β) = equiv.refl (α ⊕ β) := by { ext i, cases i; refl } namespace perm /-- Combine a permutation of `α` and of `β` into a permutation of `α ⊕ β`. -/ @[reducible] def sum_congr {α β : Type*} (ea : equiv.perm α) (eb : equiv.perm β) : equiv.perm (α ⊕ β) := equiv.sum_congr ea eb @[simp] lemma sum_congr_apply {α β : Type*} (ea : equiv.perm α) (eb : equiv.perm β) (x : α ⊕ β) : sum_congr ea eb x = sum.map ⇑ea ⇑eb x := equiv.sum_congr_apply ea eb x @[simp] lemma sum_congr_trans {α β : Sort*} (e : equiv.perm α) (f : equiv.perm β) (g : equiv.perm α) (h : equiv.perm β) : (sum_congr e f).trans (sum_congr g h) = sum_congr (e.trans g) (f.trans h) := equiv.sum_congr_trans e f g h @[simp] lemma sum_congr_symm {α β : Sort*} (e : equiv.perm α) (f : equiv.perm β) : (sum_congr e f).symm = sum_congr (e.symm) (f.symm) := equiv.sum_congr_symm e f @[simp] lemma sum_congr_refl {α β : Sort*} : sum_congr (equiv.refl α) (equiv.refl β) = equiv.refl (α ⊕ β) := equiv.sum_congr_refl end perm /-- `bool` is equivalent the sum of two `punit`s. -/ def bool_equiv_punit_sum_punit : bool ≃ punit.{u+1} ⊕ punit.{v+1} := ⟨λ b, cond b (inr punit.star) (inl punit.star), sum.elim (λ _, ff) (λ _, tt), λ b, by cases b; refl, λ s, by rcases s with ⟨⟨⟩⟩ | ⟨⟨⟩⟩; refl⟩ /-- `Prop` is noncomputably equivalent to `bool`. -/ noncomputable def Prop_equiv_bool : Prop ≃ bool := ⟨λ p, @to_bool p (classical.prop_decidable _), λ b, b, λ p, by simp, λ b, by simp⟩ /-- Sum of types is commutative up to an equivalence. This is `sum.swap` as an equivalence. -/ @[simps apply {fully_applied := ff}] def sum_comm (α β : Type*) : α ⊕ β ≃ β ⊕ α := ⟨sum.swap, sum.swap, sum.swap_swap, sum.swap_swap⟩ @[simp] lemma sum_comm_symm (α β) : (sum_comm α β).symm = sum_comm β α := rfl /-- Sum of types is associative up to an equivalence. -/ def sum_assoc (α β γ : Type*) : (α ⊕ β) ⊕ γ ≃ α ⊕ (β ⊕ γ) := ⟨sum.elim (sum.elim sum.inl (sum.inr ∘ sum.inl)) (sum.inr ∘ sum.inr), sum.elim (sum.inl ∘ sum.inl) $ sum.elim (sum.inl ∘ sum.inr) sum.inr, by rintros (⟨_ | _⟩ | _); refl, by rintros (_ | ⟨_ | _⟩); refl⟩ @[simp] lemma sum_assoc_apply_inl_inl {α β γ} (a) : sum_assoc α β γ (inl (inl a)) = inl a := rfl @[simp] lemma sum_assoc_apply_inl_inr {α β γ} (b) : sum_assoc α β γ (inl (inr b)) = inr (inl b) := rfl @[simp] lemma sum_assoc_apply_inr {α β γ} (c) : sum_assoc α β γ (inr c) = inr (inr c) := rfl @[simp] lemma sum_assoc_symm_apply_inl {α β γ} (a) : (sum_assoc α β γ).symm (inl a) = inl (inl a) := rfl @[simp] lemma sum_assoc_symm_apply_inr_inl {α β γ} (b) : (sum_assoc α β γ).symm (inr (inl b)) = inl (inr b) := rfl @[simp] lemma sum_assoc_symm_apply_inr_inr {α β γ} (c) : (sum_assoc α β γ).symm (inr (inr c)) = inr c := rfl /-- Sum with `empty` is equivalent to the original type. -/ @[simps symm_apply] def sum_empty (α β : Type*) [is_empty β] : α ⊕ β ≃ α := ⟨sum.elim id is_empty_elim, inl, λ s, by { rcases s with _ | x, refl, exact is_empty_elim x }, λ a, rfl⟩ @[simp] lemma sum_empty_apply_inl {α β : Type*} [is_empty β] (a : α) : sum_empty α β (sum.inl a) = a := rfl /-- The sum of `empty` with any `Sort*` is equivalent to the right summand. -/ @[simps symm_apply] def empty_sum (α β : Type*) [is_empty α] : α ⊕ β ≃ β := (sum_comm _ _).trans $ sum_empty _ _ @[simp] lemma empty_sum_apply_inr {α β : Type*} [is_empty α] (b : β) : empty_sum α β (sum.inr b) = b := rfl /-- `option α` is equivalent to `α ⊕ punit` -/ def option_equiv_sum_punit (α : Type*) : option α ≃ α ⊕ punit.{u+1} := ⟨λ o, o.elim (inr punit.star) inl, λ s, s.elim some (λ _, none), λ o, by cases o; refl, λ s, by rcases s with _ | ⟨⟨⟩⟩; refl⟩ @[simp] lemma option_equiv_sum_punit_none {α} : option_equiv_sum_punit α none = sum.inr punit.star := rfl @[simp] lemma option_equiv_sum_punit_some {α} (a) : option_equiv_sum_punit α (some a) = sum.inl a := rfl @[simp] lemma option_equiv_sum_punit_coe {α} (a : α) : option_equiv_sum_punit α a = sum.inl a := rfl @[simp] lemma option_equiv_sum_punit_symm_inl {α} (a) : (option_equiv_sum_punit α).symm (sum.inl a) = a := rfl @[simp] lemma option_equiv_sum_punit_symm_inr {α} (a) : (option_equiv_sum_punit α).symm (sum.inr a) = none := rfl /-- The set of `x : option α` such that `is_some x` is equivalent to `α`. -/ @[simps] def option_is_some_equiv (α : Type*) : {x : option α // x.is_some} ≃ α := { to_fun := λ o, option.get o.2, inv_fun := λ x, ⟨some x, dec_trivial⟩, left_inv := λ o, subtype.eq $ option.some_get _, right_inv := λ x, option.get_some _ _ } /-- The product over `option α` of `β a` is the binary product of the product over `α` of `β (some α)` and `β none` -/ @[simps] def pi_option_equiv_prod {α : Type*} {β : option α → Type*} : (Π a : option α, β a) ≃ (β none × Π a : α, β (some a)) := { to_fun := λ f, (f none, λ a, f (some a)), inv_fun := λ x a, option.cases_on a x.fst x.snd, left_inv := λ f, funext $ λ a, by cases a; refl, right_inv := λ x, by simp } /-- `α ⊕ β` is equivalent to a `sigma`-type over `bool`. Note that this definition assumes `α` and `β` to be types from the same universe, so it cannot by used directly to transfer theorems about sigma types to theorems about sum types. In many cases one can use `ulift` to work around this difficulty. -/ def sum_equiv_sigma_bool (α β : Type u) : α ⊕ β ≃ (Σ b: bool, cond b α β) := ⟨λ s, s.elim (λ x, ⟨tt, x⟩) (λ x, ⟨ff, x⟩), λ s, match s with ⟨tt, a⟩ := inl a | ⟨ff, b⟩ := inr b end, λ s, by cases s; refl, λ s, by rcases s with ⟨_|_, _⟩; refl⟩ /-- `sigma_fiber_equiv f` for `f : α → β` is the natural equivalence between the type of all fibres of `f` and the total space `α`. -/ -- See also `equiv.sigma_preimage_equiv`. @[simps] def sigma_fiber_equiv {α β : Type*} (f : α → β) : (Σ y : β, {x // f x = y}) ≃ α := ⟨λ x, ↑x.2, λ x, ⟨f x, x, rfl⟩, λ ⟨y, x, rfl⟩, rfl, λ x, rfl⟩ end section sum_compl /-- For any predicate `p` on `α`, the sum of the two subtypes `{a // p a}` and its complement `{a // ¬ p a}` is naturally equivalent to `α`. See `subtype_or_equiv` for sum types over subtypes `{x // p x}` and `{x // q x}` that are not necessarily `is_compl p q`. -/ def sum_compl {α : Type*} (p : α → Prop) [decidable_pred p] : {a // p a} ⊕ {a // ¬ p a} ≃ α := { to_fun := sum.elim coe coe, inv_fun := λ a, if h : p a then sum.inl ⟨a, h⟩ else sum.inr ⟨a, h⟩, left_inv := by { rintros (⟨x,hx⟩|⟨x,hx⟩); dsimp; [rw dif_pos, rw dif_neg], }, right_inv := λ a, by { dsimp, split_ifs; refl } } @[simp] lemma sum_compl_apply_inl {α : Type*} (p : α → Prop) [decidable_pred p] (x : {a // p a}) : sum_compl p (sum.inl x) = x := rfl @[simp] lemma sum_compl_apply_inr {α : Type*} (p : α → Prop) [decidable_pred p] (x : {a // ¬ p a}) : sum_compl p (sum.inr x) = x := rfl @[simp] lemma sum_compl_apply_symm_of_pos {α : Type*} (p : α → Prop) [decidable_pred p] (a : α) (h : p a) : (sum_compl p).symm a = sum.inl ⟨a, h⟩ := dif_pos h @[simp] lemma sum_compl_apply_symm_of_neg {α : Type*} (p : α → Prop) [decidable_pred p] (a : α) (h : ¬ p a) : (sum_compl p).symm a = sum.inr ⟨a, h⟩ := dif_neg h /-- Combines an `equiv` between two subtypes with an `equiv` between their complements to form a permutation. -/ def subtype_congr {α : Type*} {p q : α → Prop} [decidable_pred p] [decidable_pred q] (e : {x // p x} ≃ {x // q x}) (f : {x // ¬p x} ≃ {x // ¬q x}) : perm α := (sum_compl p).symm.trans ((sum_congr e f).trans (sum_compl q)) open equiv variables {ε : Type*} {p : ε → Prop} [decidable_pred p] variables (ep ep' : perm {a // p a}) (en en' : perm {a // ¬ p a}) /-- Combining permutations on `ε` that permute only inside or outside the subtype split induced by `p : ε → Prop` constructs a permutation on `ε`. -/ def perm.subtype_congr : equiv.perm ε := perm_congr (sum_compl p) (sum_congr ep en) lemma perm.subtype_congr.apply (a : ε) : ep.subtype_congr en a = if h : p a then ep ⟨a, h⟩ else en ⟨a, h⟩ := by { by_cases h : p a; simp [perm.subtype_congr, h] } @[simp] lemma perm.subtype_congr.left_apply {a : ε} (h : p a) : ep.subtype_congr en a = ep ⟨a, h⟩ := by simp [perm.subtype_congr.apply, h] @[simp] lemma perm.subtype_congr.left_apply_subtype (a : {a // p a}) : ep.subtype_congr en a = ep a := by { convert perm.subtype_congr.left_apply _ _ a.property, simp } @[simp] lemma perm.subtype_congr.right_apply {a : ε} (h : ¬ p a) : ep.subtype_congr en a = en ⟨a, h⟩ := by simp [perm.subtype_congr.apply, h] @[simp] lemma perm.subtype_congr.right_apply_subtype (a : {a // ¬ p a}) : ep.subtype_congr en a = en a := by { convert perm.subtype_congr.right_apply _ _ a.property, simp } @[simp] lemma perm.subtype_congr.refl : perm.subtype_congr (equiv.refl {a // p a}) (equiv.refl {a // ¬ p a}) = equiv.refl ε := by { ext x, by_cases h : p x; simp [h] } @[simp] lemma perm.subtype_congr.symm : (ep.subtype_congr en).symm = perm.subtype_congr ep.symm en.symm := begin ext x, by_cases h : p x, { have : p (ep.symm ⟨x, h⟩) := subtype.property _, simp [perm.subtype_congr.apply, h, symm_apply_eq, this] }, { have : ¬ p (en.symm ⟨x, h⟩) := subtype.property (en.symm _), simp [perm.subtype_congr.apply, h, symm_apply_eq, this] } end @[simp] lemma perm.subtype_congr.trans : (ep.subtype_congr en).trans (ep'.subtype_congr en') = perm.subtype_congr (ep.trans ep') (en.trans en') := begin ext x, by_cases h : p x, { have : p (ep ⟨x, h⟩) := subtype.property _, simp [perm.subtype_congr.apply, h, this] }, { have : ¬ p (en ⟨x, h⟩) := subtype.property (en _), simp [perm.subtype_congr.apply, h, symm_apply_eq, this] } end end sum_compl section subtype_preimage variables (p : α → Prop) [decidable_pred p] (x₀ : {a // p a} → β) /-- For a fixed function `x₀ : {a // p a} → β` defined on a subtype of `α`, the subtype of functions `x : α → β` that agree with `x₀` on the subtype `{a // p a}` is naturally equivalent to the type of functions `{a // ¬ p a} → β`. -/ @[simps] def subtype_preimage : {x : α → β // x ∘ coe = x₀} ≃ ({a // ¬ p a} → β) := { to_fun := λ (x : {x : α → β // x ∘ coe = x₀}) a, (x : α → β) a, inv_fun := λ x, ⟨λ a, if h : p a then x₀ ⟨a, h⟩ else x ⟨a, h⟩, funext $ λ ⟨a, h⟩, dif_pos h⟩, left_inv := λ ⟨x, hx⟩, subtype.val_injective $ funext $ λ a, (by { dsimp, split_ifs; [ rw ← hx, skip ]; refl }), right_inv := λ x, funext $ λ ⟨a, h⟩, show dite (p a) _ _ = _, by { dsimp, rw [dif_neg h] } } lemma subtype_preimage_symm_apply_coe_pos (x : {a // ¬ p a} → β) (a : α) (h : p a) : ((subtype_preimage p x₀).symm x : α → β) a = x₀ ⟨a, h⟩ := dif_pos h lemma subtype_preimage_symm_apply_coe_neg (x : {a // ¬ p a} → β) (a : α) (h : ¬ p a) : ((subtype_preimage p x₀).symm x : α → β) a = x ⟨a, h⟩ := dif_neg h end subtype_preimage section /-- A family of equivalences `Π a, β₁ a ≃ β₂ a` generates an equivalence between `Π a, β₁ a` and `Π a, β₂ a`. -/ def Pi_congr_right {α} {β₁ β₂ : α → Sort*} (F : Π a, β₁ a ≃ β₂ a) : (Π a, β₁ a) ≃ (Π a, β₂ a) := ⟨λ H a, F a (H a), λ H a, (F a).symm (H a), λ H, funext $ by simp, λ H, funext $ by simp⟩ /-- Given `φ : α → β → Sort*`, we have an equivalence between `Π a b, φ a b` and `Π b a, φ a b`. This is `function.swap` as an `equiv`. -/ @[simps apply] def Pi_comm {α β} (φ : α → β → Sort*) : (Π a b, φ a b) ≃ (Π b a, φ a b) := ⟨swap, swap, λ x, rfl, λ y, rfl⟩ @[simp] lemma Pi_comm_symm {α β} {φ : α → β → Sort*} : (Pi_comm φ).symm = (Pi_comm $ swap φ) := rfl /-- Dependent `curry` equivalence: the type of dependent functions on `Σ i, β i` is equivalent to the type of dependent functions of two arguments (i.e., functions to the space of functions). This is `sigma.curry` and `sigma.uncurry` together as an equiv. -/ def Pi_curry {α} {β : α → Sort*} (γ : Π a, β a → Sort*) : (Π x : Σ i, β i, γ x.1 x.2) ≃ (Π a b, γ a b) := { to_fun := sigma.curry, inv_fun := sigma.uncurry, left_inv := sigma.uncurry_curry, right_inv := sigma.curry_uncurry } end section /-- A `psigma`-type is equivalent to the corresponding `sigma`-type. -/ @[simps apply symm_apply] def psigma_equiv_sigma {α} (β : α → Type*) : (Σ' i, β i) ≃ Σ i, β i := ⟨λ a, ⟨a.1, a.2⟩, λ a, ⟨a.1, a.2⟩, λ ⟨a, b⟩, rfl, λ ⟨a, b⟩, rfl⟩ /-- A `psigma`-type is equivalent to the corresponding `sigma`-type. -/ @[simps apply symm_apply] def psigma_equiv_sigma_plift {α} (β : α → Sort*) : (Σ' i, β i) ≃ Σ i : plift α, plift (β i.down) := ⟨λ a, ⟨plift.up a.1, plift.up a.2⟩, λ a, ⟨a.1.down, a.2.down⟩, λ ⟨a, b⟩, rfl, λ ⟨⟨a⟩, ⟨b⟩⟩, rfl⟩ /-- A family of equivalences `Π a, β₁ a ≃ β₂ a` generates an equivalence between `Σ' a, β₁ a` and `Σ' a, β₂ a`. -/ @[simps apply] def psigma_congr_right {α} {β₁ β₂ : α → Sort*} (F : Π a, β₁ a ≃ β₂ a) : (Σ' a, β₁ a) ≃ Σ' a, β₂ a := ⟨λ a, ⟨a.1, F a.1 a.2⟩, λ a, ⟨a.1, (F a.1).symm a.2⟩, λ ⟨a, b⟩, congr_arg (psigma.mk a) $ symm_apply_apply (F a) b, λ ⟨a, b⟩, congr_arg (psigma.mk a) $ apply_symm_apply (F a) b⟩ @[simp] lemma psigma_congr_right_trans {α} {β₁ β₂ β₃ : α → Sort*} (F : Π a, β₁ a ≃ β₂ a) (G : Π a, β₂ a ≃ β₃ a) : (psigma_congr_right F).trans (psigma_congr_right G) = psigma_congr_right (λ a, (F a).trans (G a)) := by { ext1 x, cases x, refl } @[simp] lemma psigma_congr_right_symm {α} {β₁ β₂ : α → Sort*} (F : Π a, β₁ a ≃ β₂ a) : (psigma_congr_right F).symm = psigma_congr_right (λ a, (F a).symm) := by { ext1 x, cases x, refl } @[simp] lemma psigma_congr_right_refl {α} {β : α → Sort*} : (psigma_congr_right (λ a, equiv.refl (β a))) = equiv.refl (Σ' a, β a) := by { ext1 x, cases x, refl } /-- A family of equivalences `Π a, β₁ a ≃ β₂ a` generates an equivalence between `Σ a, β₁ a` and `Σ a, β₂ a`. -/ @[simps apply] def sigma_congr_right {α} {β₁ β₂ : α → Type*} (F : Π a, β₁ a ≃ β₂ a) : (Σ a, β₁ a) ≃ Σ a, β₂ a := ⟨λ a, ⟨a.1, F a.1 a.2⟩, λ a, ⟨a.1, (F a.1).symm a.2⟩, λ ⟨a, b⟩, congr_arg (sigma.mk a) $ symm_apply_apply (F a) b, λ ⟨a, b⟩, congr_arg (sigma.mk a) $ apply_symm_apply (F a) b⟩ @[simp] lemma sigma_congr_right_trans {α} {β₁ β₂ β₃ : α → Type*} (F : Π a, β₁ a ≃ β₂ a) (G : Π a, β₂ a ≃ β₃ a) : (sigma_congr_right F).trans (sigma_congr_right G) = sigma_congr_right (λ a, (F a).trans (G a)) := by { ext1 x, cases x, refl } @[simp] lemma sigma_congr_right_symm {α} {β₁ β₂ : α → Type*} (F : Π a, β₁ a ≃ β₂ a) : (sigma_congr_right F).symm = sigma_congr_right (λ a, (F a).symm) := by { ext1 x, cases x, refl } @[simp] lemma sigma_congr_right_refl {α} {β : α → Type*} : (sigma_congr_right (λ a, equiv.refl (β a))) = equiv.refl (Σ a, β a) := by { ext1 x, cases x, refl } /-- A `psigma` with `Prop` fibers is equivalent to the subtype. -/ def psigma_equiv_subtype {α : Type v} (P : α → Prop) : (Σ' i, P i) ≃ subtype P := { to_fun := λ x, ⟨x.1, x.2⟩, inv_fun := λ x, ⟨x.1, x.2⟩, left_inv := λ x, by { cases x, refl, }, right_inv := λ x, by { cases x, refl, }, } /-- A `sigma` with `plift` fibers is equivalent to the subtype. -/ def sigma_plift_equiv_subtype {α : Type v} (P : α → Prop) : (Σ i, plift (P i)) ≃ subtype P := ((psigma_equiv_sigma _).symm.trans (psigma_congr_right (λ a, equiv.plift))).trans (psigma_equiv_subtype P) /-- A `sigma` with `λ i, ulift (plift (P i))` fibers is equivalent to `{ x // P x }`. Variant of `sigma_plift_equiv_subtype`. -/ def sigma_ulift_plift_equiv_subtype {α : Type v} (P : α → Prop) : (Σ i, ulift (plift (P i))) ≃ subtype P := (sigma_congr_right (λ a, equiv.ulift)).trans (sigma_plift_equiv_subtype P) namespace perm /-- A family of permutations `Π a, perm (β a)` generates a permuation `perm (Σ a, β₁ a)`. -/ @[reducible] def sigma_congr_right {α} {β : α → Sort*} (F : Π a, perm (β a)) : perm (Σ a, β a) := equiv.sigma_congr_right F @[simp] lemma sigma_congr_right_trans {α} {β : α → Sort*} (F : Π a, perm (β a)) (G : Π a, perm (β a)) : (sigma_congr_right F).trans (sigma_congr_right G) = sigma_congr_right (λ a, (F a).trans (G a)) := equiv.sigma_congr_right_trans F G @[simp] lemma sigma_congr_right_symm {α} {β : α → Sort*} (F : Π a, perm (β a)) : (sigma_congr_right F).symm = sigma_congr_right (λ a, (F a).symm) := equiv.sigma_congr_right_symm F @[simp] lemma sigma_congr_right_refl {α} {β : α → Sort*} : (sigma_congr_right (λ a, equiv.refl (β a))) = equiv.refl (Σ a, β a) := equiv.sigma_congr_right_refl end perm /-- An equivalence `f : α₁ ≃ α₂` generates an equivalence between `Σ a, β (f a)` and `Σ a, β a`. -/ @[simps apply] def sigma_congr_left {α₁ α₂} {β : α₂ → Sort*} (e : α₁ ≃ α₂) : (Σ a:α₁, β (e a)) ≃ (Σ a:α₂, β a) := ⟨λ a, ⟨e a.1, a.2⟩, λ a, ⟨e.symm a.1, @@eq.rec β a.2 (e.right_inv a.1).symm⟩, λ ⟨a, b⟩, match e.symm (e a), e.left_inv a : ∀ a' (h : a' = a), @sigma.mk _ (β ∘ e) _ (@@eq.rec β b (congr_arg e h.symm)) = ⟨a, b⟩ with | _, rfl := rfl end, λ ⟨a, b⟩, match e (e.symm a), _ : ∀ a' (h : a' = a), sigma.mk a' (@@eq.rec β b h.symm) = ⟨a, b⟩ with | _, rfl := rfl end⟩ /-- Transporting a sigma type through an equivalence of the base -/ def sigma_congr_left' {α₁ α₂} {β : α₁ → Sort*} (f : α₁ ≃ α₂) : (Σ a:α₁, β a) ≃ (Σ a:α₂, β (f.symm a)) := (sigma_congr_left f.symm).symm /-- Transporting a sigma type through an equivalence of the base and a family of equivalences of matching fibers -/ def sigma_congr {α₁ α₂} {β₁ : α₁ → Sort*} {β₂ : α₂ → Sort*} (f : α₁ ≃ α₂) (F : ∀ a, β₁ a ≃ β₂ (f a)) : sigma β₁ ≃ sigma β₂ := (sigma_congr_right F).trans (sigma_congr_left f) /-- `sigma` type with a constant fiber is equivalent to the product. -/ @[simps apply symm_apply] def sigma_equiv_prod (α β : Type*) : (Σ_:α, β) ≃ α × β := ⟨λ a, ⟨a.1, a.2⟩, λ a, ⟨a.1, a.2⟩, λ ⟨a, b⟩, rfl, λ ⟨a, b⟩, rfl⟩ /-- If each fiber of a `sigma` type is equivalent to a fixed type, then the sigma type is equivalent to the product. -/ def sigma_equiv_prod_of_equiv {α β} {β₁ : α → Sort*} (F : Π a, β₁ a ≃ β) : sigma β₁ ≃ α × β := (sigma_congr_right F).trans (sigma_equiv_prod α β) /-- Dependent product of types is associative up to an equivalence. -/ def sigma_assoc {α : Type*} {β : α → Type*} (γ : Π (a : α), β a → Type*) : (Σ (ab : Σ (a : α), β a), γ ab.1 ab.2) ≃ Σ (a : α), (Σ (b : β a), γ a b) := { to_fun := λ x, ⟨x.1.1, ⟨x.1.2, x.2⟩⟩, inv_fun := λ x, ⟨⟨x.1, x.2.1⟩, x.2.2⟩, left_inv := λ ⟨⟨a, b⟩, c⟩, rfl, right_inv := λ ⟨a, ⟨b, c⟩⟩, rfl } end section prod_congr variables {α₁ β₁ β₂ : Type*} (e : α₁ → β₁ ≃ β₂) /-- A family of equivalences `Π (a : α₁), β₁ ≃ β₂` generates an equivalence between `β₁ × α₁` and `β₂ × α₁`. -/ def prod_congr_left : β₁ × α₁ ≃ β₂ × α₁ := { to_fun := λ ab, ⟨e ab.2 ab.1, ab.2⟩, inv_fun := λ ab, ⟨(e ab.2).symm ab.1, ab.2⟩, left_inv := by { rintros ⟨a, b⟩, simp }, right_inv := by { rintros ⟨a, b⟩, simp } } @[simp] lemma prod_congr_left_apply (b : β₁) (a : α₁) : prod_congr_left e (b, a) = (e a b, a) := rfl lemma prod_congr_refl_right (e : β₁ ≃ β₂) : prod_congr e (equiv.refl α₁) = prod_congr_left (λ _, e) := by { ext ⟨a, b⟩ : 1, simp } /-- A family of equivalences `Π (a : α₁), β₁ ≃ β₂` generates an equivalence between `α₁ × β₁` and `α₁ × β₂`. -/ def prod_congr_right : α₁ × β₁ ≃ α₁ × β₂ := { to_fun := λ ab, ⟨ab.1, e ab.1 ab.2⟩, inv_fun := λ ab, ⟨ab.1, (e ab.1).symm ab.2⟩, left_inv := by { rintros ⟨a, b⟩, simp }, right_inv := by { rintros ⟨a, b⟩, simp } } @[simp] lemma prod_congr_right_apply (a : α₁) (b : β₁) : prod_congr_right e (a, b) = (a, e a b) := rfl lemma prod_congr_refl_left (e : β₁ ≃ β₂) : prod_congr (equiv.refl α₁) e = prod_congr_right (λ _, e) := by { ext ⟨a, b⟩ : 1, simp } @[simp] lemma prod_congr_left_trans_prod_comm : (prod_congr_left e).trans (prod_comm _ _) = (prod_comm _ _).trans (prod_congr_right e) := by { ext ⟨a, b⟩ : 1, simp } @[simp] lemma prod_congr_right_trans_prod_comm : (prod_congr_right e).trans (prod_comm _ _) = (prod_comm _ _).trans (prod_congr_left e) := by { ext ⟨a, b⟩ : 1, simp } lemma sigma_congr_right_sigma_equiv_prod : (sigma_congr_right e).trans (sigma_equiv_prod α₁ β₂) = (sigma_equiv_prod α₁ β₁).trans (prod_congr_right e) := by { ext ⟨a, b⟩ : 1, simp } lemma sigma_equiv_prod_sigma_congr_right : (sigma_equiv_prod α₁ β₁).symm.trans (sigma_congr_right e) = (prod_congr_right e).trans (sigma_equiv_prod α₁ β₂).symm := by { ext ⟨a, b⟩ : 1, simp } /-- A family of equivalences between fibers gives an equivalence between domains. -/ -- See also `equiv.of_preimage_equiv`. @[simps] def of_fiber_equiv {α β γ : Type*} {f : α → γ} {g : β → γ} (e : Π c, {a // f a = c} ≃ {b // g b = c}) : α ≃ β := (sigma_fiber_equiv f).symm.trans $ (equiv.sigma_congr_right e).trans (sigma_fiber_equiv g) lemma of_fiber_equiv_map {α β γ} {f : α → γ} {g : β → γ} (e : Π c, {a // f a = c} ≃ {b // g b = c}) (a : α) : g (of_fiber_equiv e a) = f a := (_ : {b // g b = _}).prop /-- A variation on `equiv.prod_congr` where the equivalence in the second component can depend on the first component. A typical example is a shear mapping, explaining the name of this declaration. -/ @[simps {fully_applied := ff}] def prod_shear {α₁ β₁ α₂ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : α₁ → β₁ ≃ β₂) : α₁ × β₁ ≃ α₂ × β₂ := { to_fun := λ x : α₁ × β₁, (e₁ x.1, e₂ x.1 x.2), inv_fun := λ y : α₂ × β₂, (e₁.symm y.1, (e₂ $ e₁.symm y.1).symm y.2), left_inv := by { rintro ⟨x₁, y₁⟩, simp only [symm_apply_apply] }, right_inv := by { rintro ⟨x₁, y₁⟩, simp only [apply_symm_apply] } } end prod_congr namespace perm variables {α₁ β₁ β₂ : Type*} [decidable_eq α₁] (a : α₁) (e : perm β₁) /-- `prod_extend_right a e` extends `e : perm β` to `perm (α × β)` by sending `(a, b)` to `(a, e b)` and keeping the other `(a', b)` fixed. -/ def prod_extend_right : perm (α₁ × β₁) := { to_fun := λ ab, if ab.fst = a then (a, e ab.snd) else ab, inv_fun := λ ab, if ab.fst = a then (a, e.symm ab.snd) else ab, left_inv := by { rintros ⟨k', x⟩, dsimp only, split_ifs with h; simp [h] }, right_inv := by { rintros ⟨k', x⟩, dsimp only, split_ifs with h; simp [h] } } @[simp] lemma prod_extend_right_apply_eq (b : β₁) : prod_extend_right a e (a, b) = (a, e b) := if_pos rfl lemma prod_extend_right_apply_ne {a a' : α₁} (h : a' ≠ a) (b : β₁) : prod_extend_right a e (a', b) = (a', b) := if_neg h lemma eq_of_prod_extend_right_ne {e : perm β₁} {a a' : α₁} {b : β₁} (h : prod_extend_right a e (a', b) ≠ (a', b)) : a' = a := by { contrapose! h, exact prod_extend_right_apply_ne _ h _ } @[simp] lemma fst_prod_extend_right (ab : α₁ × β₁) : (prod_extend_right a e ab).fst = ab.fst := begin rw [prod_extend_right, coe_fn_mk], split_ifs with h, { rw h }, { refl } end end perm section /-- The type of functions to a product `α × β` is equivalent to the type of pairs of functions `γ → α` and `γ → β`. -/ def arrow_prod_equiv_prod_arrow (α β γ : Type*) : (γ → α × β) ≃ (γ → α) × (γ → β) := ⟨λ f, (λ c, (f c).1, λ c, (f c).2), λ p c, (p.1 c, p.2 c), λ f, funext $ λ c, prod.mk.eta, λ p, by { cases p, refl }⟩ open sum /-- The type of functions on a sum type `α ⊕ β` is equivalent to the type of pairs of functions on `α` and on `β`. -/ def sum_arrow_equiv_prod_arrow (α β γ : Type*) : ((α ⊕ β) → γ) ≃ (α → γ) × (β → γ) := ⟨λ f, (f ∘ inl, f ∘ inr), λ p, sum.elim p.1 p.2, λ f, by { ext ⟨⟩; refl }, λ p, by { cases p, refl }⟩ @[simp] lemma sum_arrow_equiv_prod_arrow_apply_fst {α β γ} (f : (α ⊕ β) → γ) (a : α) : (sum_arrow_equiv_prod_arrow α β γ f).1 a = f (inl a) := rfl @[simp] lemma sum_arrow_equiv_prod_arrow_apply_snd {α β γ} (f : (α ⊕ β) → γ) (b : β) : (sum_arrow_equiv_prod_arrow α β γ f).2 b = f (inr b) := rfl @[simp] lemma sum_arrow_equiv_prod_arrow_symm_apply_inl {α β γ} (f : α → γ) (g : β → γ) (a : α) : ((sum_arrow_equiv_prod_arrow α β γ).symm (f, g)) (inl a) = f a := rfl @[simp] lemma sum_arrow_equiv_prod_arrow_symm_apply_inr {α β γ} (f : α → γ) (g : β → γ) (b : β) : ((sum_arrow_equiv_prod_arrow α β γ).symm (f, g)) (inr b) = g b := rfl /-- Type product is right distributive with respect to type sum up to an equivalence. -/ def sum_prod_distrib (α β γ : Sort*) : (α ⊕ β) × γ ≃ (α × γ) ⊕ (β × γ) := ⟨λ p, p.1.map (λ x, (x, p.2)) (λ x, (x, p.2)), λ s, s.elim (prod.map inl id) (prod.map inr id), by rintro ⟨_ | _, _⟩; refl, by rintro (⟨_, _⟩ | ⟨_, _⟩); refl⟩ @[simp] theorem sum_prod_distrib_apply_left {α β γ} (a : α) (c : γ) : sum_prod_distrib α β γ (sum.inl a, c) = sum.inl (a, c) := rfl @[simp] theorem sum_prod_distrib_apply_right {α β γ} (b : β) (c : γ) : sum_prod_distrib α β γ (sum.inr b, c) = sum.inr (b, c) := rfl @[simp] theorem sum_prod_distrib_symm_apply_left {α β γ} (a : α × γ) : (sum_prod_distrib α β γ).symm (inl a) = (inl a.1, a.2) := rfl @[simp] theorem sum_prod_distrib_symm_apply_right {α β γ} (b : β × γ) : (sum_prod_distrib α β γ).symm (inr b) = (inr b.1, b.2) := rfl /-- Type product is left distributive with respect to type sum up to an equivalence. -/ def prod_sum_distrib (α β γ : Sort*) : α × (β ⊕ γ) ≃ (α × β) ⊕ (α × γ) := calc α × (β ⊕ γ) ≃ (β ⊕ γ) × α : prod_comm _ _ ... ≃ (β × α) ⊕ (γ × α) : sum_prod_distrib _ _ _ ... ≃ (α × β) ⊕ (α × γ) : sum_congr (prod_comm _ _) (prod_comm _ _) @[simp] theorem prod_sum_distrib_apply_left {α β γ} (a : α) (b : β) : prod_sum_distrib α β γ (a, sum.inl b) = sum.inl (a, b) := rfl @[simp] theorem prod_sum_distrib_apply_right {α β γ} (a : α) (c : γ) : prod_sum_distrib α β γ (a, sum.inr c) = sum.inr (a, c) := rfl @[simp] theorem prod_sum_distrib_symm_apply_left {α β γ} (a : α × β) : (prod_sum_distrib α β γ).symm (inl a) = (a.1, inl a.2) := rfl @[simp] theorem prod_sum_distrib_symm_apply_right {α β γ} (a : α × γ) : (prod_sum_distrib α β γ).symm (inr a) = (a.1, inr a.2) := rfl /-- An indexed sum of disjoint sums of types is equivalent to the sum of the indexed sums. -/ @[simps] def sigma_sum_distrib {ι : Type*} (α β : ι → Type*) : (Σ i, α i ⊕ β i) ≃ (Σ i, α i) ⊕ Σ i, β i := ⟨λ p, p.2.map (sigma.mk p.1) (sigma.mk p.1), sum.elim (sigma.map id (λ _, sum.inl)) (sigma.map id (λ _, sum.inr)), λ p, by { rcases p with ⟨i, (a | b)⟩; refl }, λ p, by { rcases p with (⟨i, a⟩ | ⟨i, b⟩); refl }⟩ /-- The product of an indexed sum of types (formally, a `sigma`-type `Σ i, α i`) by a type `β` is equivalent to the sum of products `Σ i, (α i × β)`. -/ def sigma_prod_distrib {ι : Type*} (α : ι → Type*) (β : Type*) : ((Σ i, α i) × β) ≃ (Σ i, (α i × β)) := ⟨λ p, ⟨p.1.1, (p.1.2, p.2)⟩, λ p, (⟨p.1, p.2.1⟩, p.2.2), λ p, by { rcases p with ⟨⟨_, _⟩, _⟩, refl }, λ p, by { rcases p with ⟨_, ⟨_, _⟩⟩, refl }⟩ /-- An equivalence that separates out the 0th fiber of `(Σ (n : ℕ), f n)`. -/ def sigma_nat_succ (f : ℕ → Type u) : (Σ n, f n) ≃ f 0 ⊕ Σ n, f (n + 1) := ⟨λ x, @sigma.cases_on ℕ f (λ _, f 0 ⊕ Σ n, f (n + 1)) x (λ n, @nat.cases_on (λ i, f i → (f 0 ⊕ Σ (n : ℕ), f (n + 1))) n (λ (x : f 0), sum.inl x) (λ (n : ℕ) (x : f n.succ), sum.inr ⟨n, x⟩)), sum.elim (sigma.mk 0) (sigma.map nat.succ (λ _, id)), by { rintro ⟨(n | n), x⟩; refl }, by { rintro (x | ⟨n, x⟩); refl }⟩ /-- The product `bool × α` is equivalent to `α ⊕ α`. -/ @[simps] def bool_prod_equiv_sum (α : Type u) : bool × α ≃ α ⊕ α := { to_fun := λ p, cond p.1 (inr p.2) (inl p.2), inv_fun := sum.elim (prod.mk ff) (prod.mk tt), left_inv := by rintro ⟨(_|_), _⟩; refl, right_inv := by rintro (_|_); refl } /-- The function type `bool → α` is equivalent to `α × α`. -/ @[simps] def bool_arrow_equiv_prod (α : Type u) : (bool → α) ≃ α × α := { to_fun := λ f, (f tt, f ff), inv_fun := λ p b, cond b p.1 p.2, left_inv := λ f, funext $ bool.forall_bool.2 ⟨rfl, rfl⟩, right_inv := λ ⟨x, y⟩, rfl } end section open sum nat /-- The set of natural numbers is equivalent to `ℕ ⊕ punit`. -/ def nat_equiv_nat_sum_punit : ℕ ≃ ℕ ⊕ punit.{u+1} := { to_fun := λ n, nat.cases_on n (inr punit.star) inl, inv_fun := sum.elim nat.succ (λ _, 0), left_inv := λ n, by cases n; refl, right_inv := by rintro (_|_|_); refl } /-- `ℕ ⊕ punit` is equivalent to `ℕ`. -/ def nat_sum_punit_equiv_nat : ℕ ⊕ punit.{u+1} ≃ ℕ := nat_equiv_nat_sum_punit.symm /-- The type of integer numbers is equivalent to `ℕ ⊕ ℕ`. -/ def int_equiv_nat_sum_nat : ℤ ≃ ℕ ⊕ ℕ := { to_fun := λ z, int.cases_on z inl inr, inv_fun := sum.elim coe int.neg_succ_of_nat, left_inv := by rintro (m|n); refl, right_inv := by rintro (m|n); refl } end /-- An equivalence between `α` and `β` generates an equivalence between `list α` and `list β`. -/ def list_equiv_of_equiv {α β : Type*} (e : α ≃ β) : list α ≃ list β := { to_fun := list.map e, inv_fun := list.map e.symm, left_inv := λ l, by rw [list.map_map, e.symm_comp_self, list.map_id], right_inv := λ l, by rw [list.map_map, e.self_comp_symm, list.map_id] } /-- If `α` is equivalent to `β`, then `unique α` is equivalent to `unique β`. -/ def unique_congr (e : α ≃ β) : unique α ≃ unique β := { to_fun := λ h, @equiv.unique _ _ h e.symm, inv_fun := λ h, @equiv.unique _ _ h e, left_inv := λ _, subsingleton.elim _ _, right_inv := λ _, subsingleton.elim _ _ } /-- If `α` is equivalent to `β`, then `is_empty α` is equivalent to `is_empty β`. -/ lemma is_empty_congr (e : α ≃ β) : is_empty α ↔ is_empty β := ⟨λ h, @function.is_empty _ _ h e.symm, λ h, @function.is_empty _ _ h e⟩ protected lemma is_empty (e : α ≃ β) [is_empty β] : is_empty α := e.is_empty_congr.mpr ‹_› section open subtype /-- If `α` is equivalent to `β` and the predicates `p : α → Prop` and `q : β → Prop` are equivalent at corresponding points, then `{a // p a}` is equivalent to `{b // q b}`. For the statement where `α = β`, that is, `e : perm α`, see `perm.subtype_perm`. -/ def subtype_equiv {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ a, p a ↔ q (e a)) : {a : α // p a} ≃ {b : β // q b} := { to_fun := λ a, ⟨e a, (h _).mp a.prop⟩, inv_fun := λ b, ⟨e.symm b, (h _).mpr ((e.apply_symm_apply b).symm ▸ b.prop)⟩, left_inv := λ a, subtype.ext $ by simp, right_inv := λ b, subtype.ext $ by simp } @[simp] lemma subtype_equiv_refl {p : α → Prop} (h : ∀ a, p a ↔ p (equiv.refl _ a) := λ a, iff.rfl) : (equiv.refl α).subtype_equiv h = equiv.refl {a : α // p a} := by { ext, refl } @[simp] lemma subtype_equiv_symm {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ (a : α), p a ↔ q (e a)) : (e.subtype_equiv h).symm = e.symm.subtype_equiv (λ a, by { convert (h $ e.symm a).symm, exact (e.apply_symm_apply a).symm }) := rfl @[simp] lemma subtype_equiv_trans {p : α → Prop} {q : β → Prop} {r : γ → Prop} (e : α ≃ β) (f : β ≃ γ) (h : ∀ (a : α), p a ↔ q (e a)) (h' : ∀ (b : β), q b ↔ r (f b)): (e.subtype_equiv h).trans (f.subtype_equiv h') = (e.trans f).subtype_equiv (λ a, (h a).trans (h' $ e a)) := rfl @[simp] lemma subtype_equiv_apply {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ (a : α), p a ↔ q (e a)) (x : {x // p x}) : e.subtype_equiv h x = ⟨e x, (h _).1 x.2⟩ := rfl /-- If two predicates `p` and `q` are pointwise equivalent, then `{x // p x}` is equivalent to `{x // q x}`. -/ @[simps] def subtype_equiv_right {p q : α → Prop} (e : ∀x, p x ↔ q x) : {x // p x} ≃ {x // q x} := subtype_equiv (equiv.refl _) e /-- If `α ≃ β`, then for any predicate `p : β → Prop` the subtype `{a // p (e a)}` is equivalent to the subtype `{b // p b}`. -/ def subtype_equiv_of_subtype {p : β → Prop} (e : α ≃ β) : {a : α // p (e a)} ≃ {b : β // p b} := subtype_equiv e $ by simp /-- If `α ≃ β`, then for any predicate `p : α → Prop` the subtype `{a // p a}` is equivalent to the subtype `{b // p (e.symm b)}`. This version is used by `equiv_rw`. -/ def subtype_equiv_of_subtype' {p : α → Prop} (e : α ≃ β) : {a : α // p a} ≃ {b : β // p (e.symm b)} := e.symm.subtype_equiv_of_subtype.symm /-- If two predicates are equal, then the corresponding subtypes are equivalent. -/ def subtype_equiv_prop {α : Type*} {p q : α → Prop} (h : p = q) : subtype p ≃ subtype q := subtype_equiv (equiv.refl α) (assume a, h ▸ iff.rfl) /-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. This version allows the “inner” predicate to depend on `h : p a`. -/ @[simps] def subtype_subtype_equiv_subtype_exists {α : Type u} (p : α → Prop) (q : subtype p → Prop) : subtype q ≃ {a : α // ∃h:p a, q ⟨a, h⟩ } := ⟨λ a, ⟨a, a.1.2, by { rcases a with ⟨⟨a, hap⟩, haq⟩, exact haq }⟩, λ a, ⟨⟨a, a.2.fst⟩, a.2.snd⟩, assume ⟨⟨a, ha⟩, h⟩, rfl, assume ⟨a, h₁, h₂⟩, rfl⟩ /-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. -/ @[simps] def subtype_subtype_equiv_subtype_inter {α : Type u} (p q : α → Prop) : {x : subtype p // q x.1} ≃ subtype (λ x, p x ∧ q x) := (subtype_subtype_equiv_subtype_exists p _).trans $ subtype_equiv_right $ λ x, exists_prop /-- If the outer subtype has more restrictive predicate than the inner one, then we can drop the latter. -/ @[simps] def subtype_subtype_equiv_subtype {α : Type u} {p q : α → Prop} (h : ∀ {x}, q x → p x) : {x : subtype p // q x.1} ≃ subtype q := (subtype_subtype_equiv_subtype_inter p _).trans $ subtype_equiv_right $ λ x, and_iff_right_of_imp h /-- If a proposition holds for all elements, then the subtype is equivalent to the original type. -/ @[simps apply symm_apply] def subtype_univ_equiv {α : Type u} {p : α → Prop} (h : ∀ x, p x) : subtype p ≃ α := ⟨λ x, x, λ x, ⟨x, h x⟩, λ x, subtype.eq rfl, λ x, rfl⟩ /-- A subtype of a sigma-type is a sigma-type over a subtype. -/ def subtype_sigma_equiv {α : Type u} (p : α → Type v) (q : α → Prop) : { y : sigma p // q y.1 } ≃ Σ(x : subtype q), p x.1 := ⟨λ x, ⟨⟨x.1.1, x.2⟩, x.1.2⟩, λ x, ⟨⟨x.1.1, x.2⟩, x.1.2⟩, λ ⟨⟨x, h⟩, y⟩, rfl, λ ⟨⟨x, y⟩, h⟩, rfl⟩ /-- A sigma type over a subtype is equivalent to the sigma set over the original type, if the fiber is empty outside of the subset -/ def sigma_subtype_equiv_of_subset {α : Type u} (p : α → Type v) (q : α → Prop) (h : ∀ x, p x → q x) : (Σ x : subtype q, p x) ≃ Σ x : α, p x := (subtype_sigma_equiv p q).symm.trans $ subtype_univ_equiv $ λ x, h x.1 x.2 /-- If a predicate `p : β → Prop` is true on the range of a map `f : α → β`, then `Σ y : {y // p y}, {x // f x = y}` is equivalent to `α`. -/ def sigma_subtype_fiber_equiv {α : Type u} {β : Type v} (f : α → β) (p : β → Prop) (h : ∀ x, p (f x)) : (Σ y : subtype p, {x : α // f x = y}) ≃ α := calc _ ≃ Σ y : β, {x : α // f x = y} : sigma_subtype_equiv_of_subset _ p (λ y ⟨x, h'⟩, h' ▸ h x) ... ≃ α : sigma_fiber_equiv f /-- If for each `x` we have `p x ↔ q (f x)`, then `Σ y : {y // q y}, f ⁻¹' {y}` is equivalent to `{x // p x}`. -/ def sigma_subtype_fiber_equiv_subtype {α : Type u} {β : Type v} (f : α → β) {p : α → Prop} {q : β → Prop} (h : ∀ x, p x ↔ q (f x)) : (Σ y : subtype q, {x : α // f x = y}) ≃ subtype p := calc (Σ y : subtype q, {x : α // f x = y}) ≃ Σ y : subtype q, {x : subtype p // subtype.mk (f x) ((h x).1 x.2) = y} : begin apply sigma_congr_right, assume y, symmetry, refine (subtype_subtype_equiv_subtype_exists _ _).trans (subtype_equiv_right _), assume x, exact ⟨λ ⟨hp, h'⟩, congr_arg subtype.val h', λ h', ⟨(h x).2 (h'.symm ▸ y.2), subtype.eq h'⟩⟩ end ... ≃ subtype p : sigma_fiber_equiv (λ x : subtype p, (⟨f x, (h x).1 x.property⟩ : subtype q)) /-- A sigma type over an `option` is equivalent to the sigma set over the original type, if the fiber is empty at none. -/ def sigma_option_equiv_of_some {α : Type u} (p : option α → Type v) (h : p none → false) : (Σ x : option α, p x) ≃ (Σ x : α, p (some x)) := begin have h' : ∀ x, p x → x.is_some, { intro x, cases x, { intro n, exfalso, exact h n }, { intro s, exact rfl } }, exact (sigma_subtype_equiv_of_subset _ _ h').symm.trans (sigma_congr_left' (option_is_some_equiv α)), end /-- The `pi`-type `Π i, π i` is equivalent to the type of sections `f : ι → Σ i, π i` of the `sigma` type such that for all `i` we have `(f i).fst = i`. -/ def pi_equiv_subtype_sigma (ι : Type*) (π : ι → Type*) : (Π i, π i) ≃ {f : ι → Σ i, π i // ∀ i, (f i).1 = i } := ⟨ λf, ⟨λi, ⟨i, f i⟩, assume i, rfl⟩, λf i, begin rw ← f.2 i, exact (f.1 i).2 end, assume f, funext $ assume i, rfl, assume ⟨f, hf⟩, subtype.eq $ funext $ assume i, sigma.eq (hf i).symm $ eq_of_heq $ rec_heq_of_heq _ $ rec_heq_of_heq _ $ heq.refl _⟩ /-- The set of functions `f : Π a, β a` such that for all `a` we have `p a (f a)` is equivalent to the set of functions `Π a, {b : β a // p a b}`. -/ def subtype_pi_equiv_pi {α : Sort u} {β : α → Sort v} {p : Πa, β a → Prop} : {f : Πa, β a // ∀a, p a (f a) } ≃ Πa, { b : β a // p a b } := ⟨λf a, ⟨f.1 a, f.2 a⟩, λf, ⟨λa, (f a).1, λa, (f a).2⟩, by { rintro ⟨f, h⟩, refl }, by { rintro f, funext a, exact subtype.ext_val rfl }⟩ /-- A subtype of a product defined by componentwise conditions is equivalent to a product of subtypes. -/ def subtype_prod_equiv_prod {α : Type u} {β : Type v} {p : α → Prop} {q : β → Prop} : {c : α × β // p c.1 ∧ q c.2} ≃ ({a // p a} × {b // q b}) := ⟨λ x, ⟨⟨x.1.1, x.2.1⟩, ⟨x.1.2, x.2.2⟩⟩, λ x, ⟨⟨x.1.1, x.2.1⟩, ⟨x.1.2, x.2.2⟩⟩, λ ⟨⟨_, _⟩, ⟨_, _⟩⟩, rfl, λ ⟨⟨_, _⟩, ⟨_, _⟩⟩, rfl⟩ /-- A subtype of a `prod` is equivalent to a sigma type whose fibers are subtypes. -/ def subtype_prod_equiv_sigma_subtype {α β : Type*} (p : α → β → Prop) : {x : α × β // p x.1 x.2} ≃ Σ a, {b : β // p a b} := { to_fun := λ x, ⟨x.1.1, x.1.2, x.prop⟩, inv_fun := λ x, ⟨⟨x.1, x.2⟩, x.2.prop⟩, left_inv := λ x, by ext; refl, right_inv := λ ⟨a, b, pab⟩, rfl } /-- The type `Π (i : α), β i` can be split as a product by separating the indices in `α` depending on whether they satisfy a predicate `p` or not. -/ @[simps] def pi_equiv_pi_subtype_prod {α : Type*} (p : α → Prop) (β : α → Type*) [decidable_pred p] : (Π (i : α), β i) ≃ (Π (i : {x // p x}), β i) × (Π (i : {x // ¬ p x}), β i) := { to_fun := λ f, (λ x, f x, λ x, f x), inv_fun := λ f x, if h : p x then f.1 ⟨x, h⟩ else f.2 ⟨x, h⟩, right_inv := begin rintros ⟨f, g⟩, ext1; { ext y, rcases y, simp only [y_property, dif_pos, dif_neg, not_false_iff, subtype.coe_mk], refl }, end, left_inv := λ f, begin ext x, by_cases h : p x; { simp only [h, dif_neg, dif_pos, not_false_iff], refl }, end } end section subtype_equiv_codomain variables {X : Type*} {Y : Type*} [decidable_eq X] {x : X} /-- The type of all functions `X → Y` with prescribed values for all `x' ≠ x` is equivalent to the codomain `Y`. -/ def subtype_equiv_codomain (f : {x' // x' ≠ x} → Y) : {g : X → Y // g ∘ coe = f} ≃ Y := (subtype_preimage _ f).trans $ @fun_unique {x' // ¬ x' ≠ x} _ $ show unique {x' // ¬ x' ≠ x}, from @equiv.unique _ _ (show unique {x' // x' = x}, from { default := ⟨x, rfl⟩, uniq := λ ⟨x', h⟩, subtype.val_injective h }) (subtype_equiv_right $ λ a, not_not) @[simp] lemma coe_subtype_equiv_codomain (f : {x' // x' ≠ x} → Y) : (subtype_equiv_codomain f : {g : X → Y // g ∘ coe = f} → Y) = λ g, (g : X → Y) x := rfl @[simp] lemma subtype_equiv_codomain_apply (f : {x' // x' ≠ x} → Y) (g : {g : X → Y // g ∘ coe = f}) : subtype_equiv_codomain f g = (g : X → Y) x := rfl lemma coe_subtype_equiv_codomain_symm (f : {x' // x' ≠ x} → Y) : ((subtype_equiv_codomain f).symm : Y → {g : X → Y // g ∘ coe = f}) = λ y, ⟨λ x', if h : x' ≠ x then f ⟨x', h⟩ else y, by { funext x', dsimp, erw [dif_pos x'.2, subtype.coe_eta] }⟩ := rfl @[simp] lemma subtype_equiv_codomain_symm_apply (f : {x' // x' ≠ x} → Y) (y : Y) (x' : X) : ((subtype_equiv_codomain f).symm y : X → Y) x' = if h : x' ≠ x then f ⟨x', h⟩ else y := rfl @[simp] lemma subtype_equiv_codomain_symm_apply_eq (f : {x' // x' ≠ x} → Y) (y : Y) : ((subtype_equiv_codomain f).symm y : X → Y) x = y := dif_neg (not_not.mpr rfl) lemma subtype_equiv_codomain_symm_apply_ne (f : {x' // x' ≠ x} → Y) (y : Y) (x' : X) (h : x' ≠ x) : ((subtype_equiv_codomain f).symm y : X → Y) x' = f ⟨x', h⟩ := dif_pos h end subtype_equiv_codomain /-- If `f` is a bijective function, then its domain is equivalent to its codomain. -/ @[simps apply] noncomputable def of_bijective (f : α → β) (hf : bijective f) : α ≃ β := { to_fun := f, inv_fun := function.surj_inv hf.surjective, left_inv := function.left_inverse_surj_inv hf, right_inv := function.right_inverse_surj_inv _} lemma of_bijective_apply_symm_apply (f : α → β) (hf : bijective f) (x : β) : f ((of_bijective f hf).symm x) = x := (of_bijective f hf).apply_symm_apply x @[simp] lemma of_bijective_symm_apply_apply (f : α → β) (hf : bijective f) (x : α) : (of_bijective f hf).symm (f x) = x := (of_bijective f hf).symm_apply_apply x instance : can_lift (α → β) (α ≃ β) := { coe := coe_fn, cond := bijective, prf := λ f hf, ⟨of_bijective f hf, rfl⟩ } section variables {α' β' : Type*} (e : perm α') {p : β' → Prop} [decidable_pred p] (f : α' ≃ subtype p) /-- Extend the domain of `e : equiv.perm α` to one that is over `β` via `f : α → subtype p`, where `p : β → Prop`, permuting only the `b : β` that satisfy `p b`. This can be used to extend the domain across a function `f : α → β`, keeping everything outside of `set.range f` fixed. For this use-case `equiv` given by `f` can be constructed by `equiv.of_left_inverse'` or `equiv.of_left_inverse` when there is a known inverse, or `equiv.of_injective` in the general case.`. -/ def perm.extend_domain : perm β' := (perm_congr f e).subtype_congr (equiv.refl _) @[simp] lemma perm.extend_domain_apply_image (a : α') : e.extend_domain f (f a) = f (e a) := by simp [perm.extend_domain] lemma perm.extend_domain_apply_subtype {b : β'} (h : p b) : e.extend_domain f b = f (e (f.symm ⟨b, h⟩)) := by simp [perm.extend_domain, h] lemma perm.extend_domain_apply_not_subtype {b : β'} (h : ¬ p b) : e.extend_domain f b = b := by simp [perm.extend_domain, h] @[simp] lemma perm.extend_domain_refl : perm.extend_domain (equiv.refl _) f = equiv.refl _ := by simp [perm.extend_domain] @[simp] lemma perm.extend_domain_symm : (e.extend_domain f).symm = perm.extend_domain e.symm f := rfl lemma perm.extend_domain_trans (e e' : perm α') : (e.extend_domain f).trans (e'.extend_domain f) = perm.extend_domain (e.trans e') f := by simp [perm.extend_domain, perm_congr_trans] end /-- Subtype of the quotient is equivalent to the quotient of the subtype. Let `α` be a setoid with equivalence relation `~`. Let `p₂` be a predicate on the quotient type `α/~`, and `p₁` be the lift of this predicate to `α`: `p₁ a ↔ p₂ ⟦a⟧`. Let `~₂` be the restriction of `~` to `{x // p₁ x}`. Then `{x // p₂ x}` is equivalent to the quotient of `{x // p₁ x}` by `~₂`. -/ def subtype_quotient_equiv_quotient_subtype (p₁ : α → Prop) [s₁ : setoid α] [s₂ : setoid (subtype p₁)] (p₂ : quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧) (h : ∀ x y : subtype p₁, @setoid.r _ s₂ x y ↔ (x : α) ≈ y) : {x // p₂ x} ≃ quotient s₂ := { to_fun := λ a, quotient.hrec_on a.1 (λ a h, ⟦⟨a, (hp₂ _).2 h⟩⟧) (λ a b hab, hfunext (by rw quotient.sound hab) (λ h₁ h₂ _, heq_of_eq (quotient.sound ((h _ _).2 hab)))) a.2, inv_fun := λ a, quotient.lift_on a (λ a, (⟨⟦a.1⟧, (hp₂ _).1 a.2⟩ : {x // p₂ x})) (λ a b hab, subtype.ext_val (quotient.sound ((h _ _).1 hab))), left_inv := λ ⟨a, ha⟩, quotient.induction_on a (λ a ha, rfl) ha, right_inv := λ a, quotient.induction_on a (λ ⟨a, ha⟩, rfl) } @[simp] lemma subtype_quotient_equiv_quotient_subtype_mk (p₁ : α → Prop) [s₁ : setoid α] [s₂ : setoid (subtype p₁)] (p₂ : quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧) (h : ∀ x y : subtype p₁, @setoid.r _ s₂ x y ↔ (x : α) ≈ y) (x hx) : subtype_quotient_equiv_quotient_subtype p₁ p₂ hp₂ h ⟨⟦x⟧, hx⟩ = ⟦⟨x, (hp₂ _).2 hx⟩⟧ := rfl @[simp] lemma subtype_quotient_equiv_quotient_subtype_symm_mk (p₁ : α → Prop) [s₁ : setoid α] [s₂ : setoid (subtype p₁)] (p₂ : quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧) (h : ∀ x y : subtype p₁, @setoid.r _ s₂ x y ↔ (x : α) ≈ y) (x) : (subtype_quotient_equiv_quotient_subtype p₁ p₂ hp₂ h).symm ⟦x⟧ = ⟨⟦x⟧, (hp₂ _).1 x.prop⟩ := rfl section swap variable [decidable_eq α] /-- A helper function for `equiv.swap`. -/ def swap_core (a b r : α) : α := if r = a then b else if r = b then a else r theorem swap_core_self (r a : α) : swap_core a a r = r := by { unfold swap_core, split_ifs; cc } theorem swap_core_swap_core (r a b : α) : swap_core a b (swap_core a b r) = r := by { unfold swap_core, split_ifs; cc } theorem swap_core_comm (r a b : α) : swap_core a b r = swap_core b a r := by { unfold swap_core, split_ifs; cc } /-- `swap a b` is the permutation that swaps `a` and `b` and leaves other values as is. -/ def swap (a b : α) : perm α := ⟨swap_core a b, swap_core a b, λr, swap_core_swap_core r a b, λr, swap_core_swap_core r a b⟩ @[simp] theorem swap_self (a : α) : swap a a = equiv.refl _ := ext $ λ r, swap_core_self r a theorem swap_comm (a b : α) : swap a b = swap b a := ext $ λ r, swap_core_comm r _ _ theorem swap_apply_def (a b x : α) : swap a b x = if x = a then b else if x = b then a else x := rfl @[simp] theorem swap_apply_left (a b : α) : swap a b a = b := if_pos rfl @[simp] theorem swap_apply_right (a b : α) : swap a b b = a := by { by_cases h : b = a; simp [swap_apply_def, h], } theorem swap_apply_of_ne_of_ne {a b x : α} : x ≠ a → x ≠ b → swap a b x = x := by simp [swap_apply_def] {contextual := tt} @[simp] theorem swap_swap (a b : α) : (swap a b).trans (swap a b) = equiv.refl _ := ext $ λ x, swap_core_swap_core _ _ _ @[simp] lemma symm_swap (a b : α) : (swap a b).symm = swap a b := rfl @[simp] lemma swap_eq_refl_iff {x y : α} : swap x y = equiv.refl _ ↔ x = y := begin refine ⟨λ h, (equiv.refl _).injective _, λ h, h ▸ (swap_self _)⟩, rw [←h, swap_apply_left, h, refl_apply] end theorem swap_comp_apply {a b x : α} (π : perm α) : π.trans (swap a b) x = if π x = a then b else if π x = b then a else π x := by { cases π, refl } lemma swap_eq_update (i j : α) : (equiv.swap i j : α → α) = update (update id j i) i j := funext $ λ x, by rw [update_apply _ i j, update_apply _ j i, equiv.swap_apply_def, id.def] lemma comp_swap_eq_update (i j : α) (f : α → β) : f ∘ equiv.swap i j = update (update f j (f i)) i (f j) := by rw [swap_eq_update, comp_update, comp_update, comp.right_id] @[simp] lemma symm_trans_swap_trans [decidable_eq β] (a b : α) (e : α ≃ β) : (e.symm.trans (swap a b)).trans e = swap (e a) (e b) := equiv.ext (λ x, begin have : ∀ a, e.symm x = a ↔ x = e a := λ a, by { rw @eq_comm _ (e.symm x), split; intros; simp * at * }, simp [swap_apply_def, this], split_ifs; simp end) @[simp] lemma trans_swap_trans_symm [decidable_eq β] (a b : β) (e : α ≃ β) : (e.trans (swap a b)).trans e.symm = swap (e.symm a) (e.symm b) := symm_trans_swap_trans a b e.symm @[simp] lemma swap_apply_self (i j a : α) : swap i j (swap i j a) = a := by rw [← equiv.trans_apply, equiv.swap_swap, equiv.refl_apply] /-- A function is invariant to a swap if it is equal at both elements -/ lemma apply_swap_eq_self {v : α → β} {i j : α} (hv : v i = v j) (k : α) : v (swap i j k) = v k := begin by_cases hi : k = i, { rw [hi, swap_apply_left, hv] }, by_cases hj : k = j, { rw [hj, swap_apply_right, hv] }, rw swap_apply_of_ne_of_ne hi hj, end lemma swap_apply_eq_iff {x y z w : α} : swap x y z = w ↔ z = swap x y w := by rw [apply_eq_iff_eq_symm_apply, symm_swap] lemma swap_apply_ne_self_iff {a b x : α} : swap a b x ≠ x ↔ a ≠ b ∧ (x = a ∨ x = b) := begin by_cases hab : a = b, { simp [hab] }, by_cases hax : x = a, { simp [hax, eq_comm] }, by_cases hbx : x = b, { simp [hbx] }, simp [hab, hax, hbx, swap_apply_of_ne_of_ne] end namespace perm @[simp] lemma sum_congr_swap_refl {α β : Sort*} [decidable_eq α] [decidable_eq β] (i j : α) : equiv.perm.sum_congr (equiv.swap i j) (equiv.refl β) = equiv.swap (sum.inl i) (sum.inl j) := begin ext x, cases x, { simp [sum.map, swap_apply_def], split_ifs; refl}, { simp [sum.map, swap_apply_of_ne_of_ne] }, end @[simp] lemma sum_congr_refl_swap {α β : Sort*} [decidable_eq α] [decidable_eq β] (i j : β) : equiv.perm.sum_congr (equiv.refl α) (equiv.swap i j) = equiv.swap (sum.inr i) (sum.inr j) := begin ext x, cases x, { simp [sum.map, swap_apply_of_ne_of_ne] }, { simp [sum.map, swap_apply_def], split_ifs; refl}, end end perm /-- Augment an equivalence with a prescribed mapping `f a = b` -/ def set_value (f : α ≃ β) (a : α) (b : β) : α ≃ β := (swap a (f.symm b)).trans f @[simp] theorem set_value_eq (f : α ≃ β) (a : α) (b : β) : set_value f a b a = b := by { dsimp [set_value], simp [swap_apply_left] } end swap end equiv namespace function.involutive /-- Convert an involutive function `f` to a permutation with `to_fun = inv_fun = f`. -/ def to_perm (f : α → α) (h : involutive f) : equiv.perm α := ⟨f, f, h.left_inverse, h.right_inverse⟩ @[simp] lemma coe_to_perm {f : α → α} (h : involutive f) : (h.to_perm f : α → α) = f := rfl @[simp] lemma to_perm_symm {f : α → α} (h : involutive f) : (h.to_perm f).symm = h.to_perm f := rfl lemma to_perm_involutive {f : α → α} (h : involutive f) : involutive (h.to_perm f) := h end function.involutive lemma plift.eq_up_iff_down_eq {x : plift α} {y : α} : x = plift.up y ↔ x.down = y := equiv.plift.eq_symm_apply lemma function.injective.map_swap {α β : Type*} [decidable_eq α] [decidable_eq β] {f : α → β} (hf : function.injective f) (x y z : α) : f (equiv.swap x y z) = equiv.swap (f x) (f y) (f z) := begin conv_rhs { rw equiv.swap_apply_def }, split_ifs with h₁ h₂, { rw [hf h₁, equiv.swap_apply_left] }, { rw [hf h₂, equiv.swap_apply_right] }, { rw [equiv.swap_apply_of_ne_of_ne (mt (congr_arg f) h₁) (mt (congr_arg f) h₂)] } end namespace equiv protected lemma exists_unique_congr {p : α → Prop} {q : β → Prop} (f : α ≃ β) (h : ∀{x}, p x ↔ q (f x)) : (∃! x, p x) ↔ ∃! y, q y := begin split, { rintro ⟨a, ha₁, ha₂⟩, exact ⟨f a, h.1 ha₁, λ b hb, f.symm_apply_eq.1 (ha₂ (f.symm b) (h.2 (by simpa using hb)))⟩ }, { rintro ⟨b, hb₁, hb₂⟩, exact ⟨f.symm b, h.2 (by simpa using hb₁), λ y hy, (eq_symm_apply f).2 (hb₂ _ (h.1 hy))⟩ } end protected lemma exists_unique_congr_left' {p : α → Prop} (f : α ≃ β) : (∃! x, p x) ↔ (∃! y, p (f.symm y)) := equiv.exists_unique_congr f (λx, by simp) protected lemma exists_unique_congr_left {p : β → Prop} (f : α ≃ β) : (∃! x, p (f x)) ↔ (∃! y, p y) := (equiv.exists_unique_congr_left' f.symm).symm protected lemma forall_congr {p : α → Prop} {q : β → Prop} (f : α ≃ β) (h : ∀{x}, p x ↔ q (f x)) : (∀x, p x) ↔ (∀y, q y) := begin split; intros h₂ x, { rw [←f.right_inv x], apply h.mp, apply h₂ }, apply h.mpr, apply h₂ end protected lemma forall_congr' {p : α → Prop} {q : β → Prop} (f : α ≃ β) (h : ∀{x}, p (f.symm x) ↔ q x) : (∀x, p x) ↔ (∀y, q y) := (equiv.forall_congr f.symm (λ x, h.symm)).symm -- We next build some higher arity versions of `equiv.forall_congr`. -- Although they appear to just be repeated applications of `equiv.forall_congr`, -- unification of metavariables works better with these versions. -- In particular, they are necessary in `equiv_rw`. -- (Stopping at ternary functions seems reasonable: at least in 1-categorical mathematics, -- it's rare to have axioms involving more than 3 elements at once.) universes ua1 ua2 ub1 ub2 ug1 ug2 variables {α₁ : Sort ua1} {α₂ : Sort ua2} {β₁ : Sort ub1} {β₂ : Sort ub2} {γ₁ : Sort ug1} {γ₂ : Sort ug2} protected lemma forall₂_congr {p : α₁ → β₁ → Prop} {q : α₂ → β₂ → Prop} (eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (h : ∀{x y}, p x y ↔ q (eα x) (eβ y)) : (∀x y, p x y) ↔ (∀x y, q x y) := begin apply equiv.forall_congr, intros, apply equiv.forall_congr, intros, apply h, end protected lemma forall₂_congr' {p : α₁ → β₁ → Prop} {q : α₂ → β₂ → Prop} (eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (h : ∀{x y}, p (eα.symm x) (eβ.symm y) ↔ q x y) : (∀x y, p x y) ↔ (∀x y, q x y) := (equiv.forall₂_congr eα.symm eβ.symm (λ x y, h.symm)).symm protected lemma forall₃_congr {p : α₁ → β₁ → γ₁ → Prop} {q : α₂ → β₂ → γ₂ → Prop} (eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (eγ : γ₁ ≃ γ₂) (h : ∀{x y z}, p x y z ↔ q (eα x) (eβ y) (eγ z)) : (∀x y z, p x y z) ↔ (∀x y z, q x y z) := begin apply equiv.forall₂_congr, intros, apply equiv.forall_congr, intros, apply h, end protected lemma forall₃_congr' {p : α₁ → β₁ → γ₁ → Prop} {q : α₂ → β₂ → γ₂ → Prop} (eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (eγ : γ₁ ≃ γ₂) (h : ∀{x y z}, p (eα.symm x) (eβ.symm y) (eγ.symm z) ↔ q x y z) : (∀x y z, p x y z) ↔ (∀x y z, q x y z) := (equiv.forall₃_congr eα.symm eβ.symm eγ.symm (λ x y z, h.symm)).symm protected lemma forall_congr_left' {p : α → Prop} (f : α ≃ β) : (∀x, p x) ↔ (∀y, p (f.symm y)) := equiv.forall_congr f (λx, by simp) protected lemma forall_congr_left {p : β → Prop} (f : α ≃ β) : (∀x, p (f x)) ↔ (∀y, p y) := (equiv.forall_congr_left' f.symm).symm protected lemma exists_congr_left {α β} (f : α ≃ β) {p : α → Prop} : (∃ a, p a) ↔ (∃ b, p (f.symm b)) := ⟨λ ⟨a, h⟩, ⟨f a, by simpa using h⟩, λ ⟨b, h⟩, ⟨_, h⟩⟩ section variables (P : α → Sort w) (e : α ≃ β) /-- Transport dependent functions through an equivalence of the base space. -/ @[simps] def Pi_congr_left' : (Π a, P a) ≃ (Π b, P (e.symm b)) := { to_fun := λ f x, f (e.symm x), inv_fun := λ f x, begin rw [← e.symm_apply_apply x], exact f (e x) end, left_inv := λ f, funext $ λ x, eq_of_heq ((eq_rec_heq _ _).trans (by { dsimp, rw e.symm_apply_apply })), right_inv := λ f, funext $ λ x, eq_of_heq ((eq_rec_heq _ _).trans (by { rw e.apply_symm_apply })) } end section variables (P : β → Sort w) (e : α ≃ β) /-- Transporting dependent functions through an equivalence of the base, expressed as a "simplification". -/ def Pi_congr_left : (Π a, P (e a)) ≃ (Π b, P b) := (Pi_congr_left' P e.symm).symm end section variables {W : α → Sort w} {Z : β → Sort z} (h₁ : α ≃ β) (h₂ : Π a : α, (W a ≃ Z (h₁ a))) /-- Transport dependent functions through an equivalence of the base spaces and a family of equivalences of the matching fibers. -/ def Pi_congr : (Π a, W a) ≃ (Π b, Z b) := (equiv.Pi_congr_right h₂).trans (equiv.Pi_congr_left _ h₁) @[simp] lemma coe_Pi_congr_symm : ((h₁.Pi_congr h₂).symm : (Π b, Z b) → (Π a, W a)) = λ f a, (h₂ a).symm (f (h₁ a)) := rfl lemma Pi_congr_symm_apply (f : Π b, Z b) : (h₁.Pi_congr h₂).symm f = λ a, (h₂ a).symm (f (h₁ a)) := rfl @[simp] lemma Pi_congr_apply_apply (f : Π a, W a) (a : α) : h₁.Pi_congr h₂ f (h₁ a) = h₂ a (f a) := begin change cast _ ((h₂ (h₁.symm (h₁ a))) (f (h₁.symm (h₁ a)))) = (h₂ a) (f a), generalize_proofs hZa, revert hZa, rw h₁.symm_apply_apply a, simp, end end section variables {W : α → Sort w} {Z : β → Sort z} (h₁ : α ≃ β) (h₂ : Π b : β, (W (h₁.symm b) ≃ Z b)) /-- Transport dependent functions through an equivalence of the base spaces and a family of equivalences of the matching fibres. -/ def Pi_congr' : (Π a, W a) ≃ (Π b, Z b) := (Pi_congr h₁.symm (λ b, (h₂ b).symm)).symm @[simp] lemma coe_Pi_congr' : (h₁.Pi_congr' h₂ : (Π a, W a) → (Π b, Z b)) = λ f b, h₂ b $ f $ h₁.symm b := rfl lemma Pi_congr'_apply (f : Π a, W a) : h₁.Pi_congr' h₂ f = λ b, h₂ b $ f $ h₁.symm b := rfl @[simp] lemma Pi_congr'_symm_apply_symm_apply (f : Π b, Z b) (b : β) : (h₁.Pi_congr' h₂).symm f (h₁.symm b) = (h₂ b).symm (f b) := begin change cast _ ((h₂ (h₁ (h₁.symm b))).symm (f (h₁ (h₁.symm b)))) = (h₂ b).symm (f b), generalize_proofs hWb, revert hWb, generalize hb : h₁ (h₁.symm b) = b', rw h₁.apply_symm_apply b at hb, subst hb, simp, end end end equiv lemma function.injective.swap_apply [decidable_eq α] [decidable_eq β] {f : α → β} (hf : function.injective f) (x y z : α) : equiv.swap (f x) (f y) (f z) = f (equiv.swap x y z) := begin by_cases hx : z = x, by simp [hx], by_cases hy : z = y, by simp [hy], rw [equiv.swap_apply_of_ne_of_ne hx hy, equiv.swap_apply_of_ne_of_ne (hf.ne hx) (hf.ne hy)] end lemma function.injective.swap_comp [decidable_eq α] [decidable_eq β] {f : α → β} (hf : function.injective f) (x y : α) : equiv.swap (f x) (f y) ∘ f = f ∘ equiv.swap x y := funext $ λ z, hf.swap_apply _ _ _ /-- If `α` is a subsingleton, then it is equivalent to `α × α`. -/ def subsingleton_prod_self_equiv {α : Type*} [subsingleton α] : α × α ≃ α := { to_fun := λ p, p.1, inv_fun := λ a, (a, a), left_inv := λ p, subsingleton.elim _ _, right_inv := λ p, subsingleton.elim _ _, } /-- To give an equivalence between two subsingleton types, it is sufficient to give any two functions between them. -/ def equiv_of_subsingleton_of_subsingleton [subsingleton α] [subsingleton β] (f : α → β) (g : β → α) : α ≃ β := { to_fun := f, inv_fun := g, left_inv := λ _, subsingleton.elim _ _, right_inv := λ _, subsingleton.elim _ _ } /-- A nonempty subsingleton type is (noncomputably) equivalent to `punit`. -/ noncomputable def equiv.punit_of_nonempty_of_subsingleton {α : Sort*} [h : nonempty α] [subsingleton α] : α ≃ punit.{v} := equiv_of_subsingleton_of_subsingleton (λ _, punit.star) (λ _, h.some) /-- `unique (unique α)` is equivalent to `unique α`. -/ def unique_unique_equiv : unique (unique α) ≃ unique α := equiv_of_subsingleton_of_subsingleton (λ h, h.default) (λ h, { default := h, uniq := λ _, subsingleton.elim _ _ }) namespace quot /-- An equivalence `e : α ≃ β` generates an equivalence between quotient spaces, if `ra a₁ a₂ ↔ rb (e a₁) (e a₂). -/ protected def congr {ra : α → α → Prop} {rb : β → β → Prop} (e : α ≃ β) (eq : ∀a₁ a₂, ra a₁ a₂ ↔ rb (e a₁) (e a₂)) : quot ra ≃ quot rb := { to_fun := quot.map e (assume a₁ a₂, (eq a₁ a₂).1), inv_fun := quot.map e.symm (assume b₁ b₂ h, (eq (e.symm b₁) (e.symm b₂)).2 ((e.apply_symm_apply b₁).symm ▸ (e.apply_symm_apply b₂).symm ▸ h)), left_inv := by { rintros ⟨a⟩, dunfold quot.map, simp only [equiv.symm_apply_apply] }, right_inv := by { rintros ⟨a⟩, dunfold quot.map, simp only [equiv.apply_symm_apply] } } @[simp] lemma congr_mk {ra : α → α → Prop} {rb : β → β → Prop} (e : α ≃ β) (eq : ∀ (a₁ a₂ : α), ra a₁ a₂ ↔ rb (e a₁) (e a₂)) (a : α) : quot.congr e eq (quot.mk ra a) = quot.mk rb (e a) := rfl /-- Quotients are congruent on equivalences under equality of their relation. An alternative is just to use rewriting with `eq`, but then computational proofs get stuck. -/ protected def congr_right {r r' : α → α → Prop} (eq : ∀a₁ a₂, r a₁ a₂ ↔ r' a₁ a₂) : quot r ≃ quot r' := quot.congr (equiv.refl α) eq /-- An equivalence `e : α ≃ β` generates an equivalence between the quotient space of `α` by a relation `ra` and the quotient space of `β` by the image of this relation under `e`. -/ protected def congr_left {r : α → α → Prop} (e : α ≃ β) : quot r ≃ quot (λ b b', r (e.symm b) (e.symm b')) := @quot.congr α β r (λ b b', r (e.symm b) (e.symm b')) e (λ a₁ a₂, by simp only [e.symm_apply_apply]) end quot namespace quotient /-- An equivalence `e : α ≃ β` generates an equivalence between quotient spaces, if `ra a₁ a₂ ↔ rb (e a₁) (e a₂). -/ protected def congr {ra : setoid α} {rb : setoid β} (e : α ≃ β) (eq : ∀a₁ a₂, @setoid.r α ra a₁ a₂ ↔ @setoid.r β rb (e a₁) (e a₂)) : quotient ra ≃ quotient rb := quot.congr e eq @[simp] lemma congr_mk {ra : setoid α} {rb : setoid β} (e : α ≃ β) (eq : ∀ (a₁ a₂ : α), setoid.r a₁ a₂ ↔ setoid.r (e a₁) (e a₂)) (a : α): quotient.congr e eq (quotient.mk a) = quotient.mk (e a) := rfl /-- Quotients are congruent on equivalences under equality of their relation. An alternative is just to use rewriting with `eq`, but then computational proofs get stuck. -/ protected def congr_right {r r' : setoid α} (eq : ∀a₁ a₂, @setoid.r α r a₁ a₂ ↔ @setoid.r α r' a₁ a₂) : quotient r ≃ quotient r' := quot.congr_right eq end quotient namespace function lemma update_comp_equiv {α β α' : Sort*} [decidable_eq α'] [decidable_eq α] (f : α → β) (g : α' ≃ α) (a : α) (v : β) : update f a v ∘ g = update (f ∘ g) (g.symm a) v := by rw [← update_comp_eq_of_injective _ g.injective, g.apply_symm_apply] lemma update_apply_equiv_apply {α β α' : Sort*} [decidable_eq α'] [decidable_eq α] (f : α → β) (g : α' ≃ α) (a : α) (v : β) (a' : α') : update f a v (g a') = update (f ∘ g) (g.symm a) v a' := congr_fun (update_comp_equiv f g a v) a' lemma Pi_congr_left'_update [decidable_eq α] [decidable_eq β] (P : α → Sort*) (e : α ≃ β) (f : Π a, P a) (b : β) (x : P (e.symm b)) : e.Pi_congr_left' P (update f (e.symm b) x) = update (e.Pi_congr_left' P f) b x := begin ext b', rcases eq_or_ne b' b with rfl | h, { simp, }, { simp [h], }, end lemma Pi_congr_left'_symm_update [decidable_eq α] [decidable_eq β] (P : α → Sort*) (e : α ≃ β) (f : Π b, P (e.symm b)) (b : β) (x : P (e.symm b)) : (e.Pi_congr_left' P).symm (update f b x) = update ((e.Pi_congr_left' P).symm f) (e.symm b) x := by simp [(e.Pi_congr_left' P).symm_apply_eq, Pi_congr_left'_update] end function
832b3140afadc167f9351f406434732c645688d7
2272e503179a58556187901b8698b789fad7e0c4
/src/examples.lean
8293339cc04858c58020dc287df43e8f9fdb90b1
[]
no_license
kckennylau/category-theory
f15e582be862379453a5341d83b8cd5ebc686729
b24962838c7370b5257e38b7648040aec95922bb
refs/heads/master
1,583,605,043,449
1,525,154,882,000
1,525,154,882,000
127,633,452
0
0
null
null
null
null
UTF-8
Lean
false
false
7,096
lean
import .basic .group_action .free_group universes u v namespace category namespace examples @[reducible] def Set : category (Type u) := { Mor := λ S T, S → T, Comp := λ S T U, (∘), Id := @id, Hid_left := λ S T f, rfl, Hid_right := λ S T f, rfl, Hassoc := λ S T U V f g h, rfl } @[reducible] def InvSet : category Σ α : Type u, inv_type α := { Mor := λ S T, { f : S.1 → T.1 // by letI := S.2; letI := T.2; from ∀ x, f x⁻¹ = (f x)⁻¹ }, Comp := λ S T U f g, ⟨f.1 ∘ g.1, λ x, by dsimp; rw [g.2, f.2]⟩, Id := λ S, ⟨@id S.1, λ x, rfl⟩, Hid_left := λ S T f, subtype.eq rfl, Hid_right := λ S T f, subtype.eq rfl, Hassoc := λ S T U V f g h, subtype.eq rfl } @[reducible] def set : category Σ α : Type u, fintype α := { Mor := λ S T, S.1 → T.1, Comp := λ S T U, (∘), Id := λ S, @id S.1, Hid_left := λ S T f, rfl, Hid_right := λ S T f, rfl, Hassoc := λ S T U V f g h, rfl } @[reducible] def Mon : category Σ α : Type u, monoid α := { Mor := λ G H, { f : G.1 → H.1 // by letI := G.2; letI := H.2; exact (∀ x y, f (x * y) = f x * f y) ∧ f 1 = 1 }, Comp := λ G H K f g, ⟨f.1 ∘ g.1, λ x y, by dsimp; rw [g.2.1, f.2.1], by dsimp; rw [g.2.2, f.2.2]⟩, Id := λ G, ⟨id, λ x y, rfl, rfl⟩, Hid_left := λ G H f, subtype.eq rfl, Hid_right := λ G H f, subtype.eq rfl, Hassoc := λ G H K N f g h, subtype.eq rfl } @[reducible] def InvMon : category Σ α : Type u, inv_mon α := { Mor := λ G H, { f : G.1 → H.1 // by letI := G.2; letI := H.2; exact inv_mon.is_hom G.1 H.1 f }, Comp := λ G H K f g, by letI := G.2; letI := H.2; letI := K.2; from ⟨f.1 ∘ g.1, λ x y, by dsimp; rw [g.2.1, f.2.1], by dsimp; rw [g.2.2, f.2.2], λ x, by dsimp; rw [g.2.3, f.2.3]⟩, Id := λ G, by letI := G.2; from ⟨id, λ x y, rfl, rfl, λ x, rfl⟩, Hid_left := λ G H f, subtype.eq rfl, Hid_right := λ G H f, subtype.eq rfl, Hassoc := λ G H K N f g h, subtype.eq rfl } @[reducible] def Grp : category Σ α : Type u, group α := { Mor := λ G H, { f : G.1 → H.1 // @is_group_hom _ _ G.2 H.2 f }, Comp := λ G H K f g, ⟨f.1 ∘ g.1, λ x y, calc f.1 (g.1 _) = f.1 _ : congr_arg f.1 (g.2 x y) ... = _ : f.2 _ _⟩, Id := λ G, ⟨id, λ x y, rfl⟩, Hid_left := λ G H f, subtype.eq rfl, Hid_right := λ G H f, subtype.eq rfl, Hassoc := λ G H K N f g h, subtype.eq rfl } @[reducible] def GSet (G : Type u) [group G] : category Σ X : Type v, group_action G X := { Mor := λ X Y, { f : X.1 → Y.1 // @group_action.is_hom G _ _ X.2 _ Y.2 f }, Comp := λ X Y Z f g, ⟨f.1 ∘ g.1, by letI := X.2; letI := Y.2; letI := Z.2; from group_action.is_hom.comp G f.1 f.2 g.1 g.2⟩, Id := λ X, ⟨id, @group_action.is_hom.id G _ X.1 X.2⟩, Hid_left := λ X Y f, subtype.eq rfl, Hid_right := λ X Y f, subtype.eq rfl, Hassoc := λ X Y Z W f g h, subtype.eq rfl } @[reducible] def Top : category Σ α : Type u, topological_space α := { Mor := λ X Y, { f : X.1 → Y.1 // @continuous _ _ X.2 Y.2 f }, Comp := λ X Y Z f g, ⟨f.1 ∘ g.1, @continuous.comp X.1 Y.1 Z.1 X.2 Y.2 Z.2 g.1 f.1 g.2 f.2⟩, Id := λ X, ⟨id, @continuous_id X.1 X.2⟩, Hid_left := λ x y f, subtype.eq rfl, Hid_right := λ x y f, subtype.eq rfl, Hassoc := λ x y z w f g h, subtype.eq rfl } @[reducible] def Ab : category Σ α : Type u, add_comm_group α := { Mor := λ G H, { f : G.1 → H.1 // by letI := G.2; letI := H.2; exact ∀ x y, f (x + y) = f x + f y }, Comp := λ G H K f g, ⟨f.1 ∘ g.1, λ x y, calc f.1 (g.1 _) = f.1 _ : congr_arg f.1 (g.2 x y) ... = _ : f.2 _ _⟩, Id := λ G, ⟨id, λ x y, rfl⟩, Hid_left := λ G H f, subtype.eq rfl, Hid_right := λ G H f, subtype.eq rfl, Hassoc := λ G H K N f g h, subtype.eq rfl } @[reducible] def Mod (α : Type u) [ring α] : category Σ β : Type v, module α β := { Mor := λ M N, @linear_map _ M.1 N.1 _ M.2 N.2, Comp := λ M N P f g, ⟨f.1 ∘ g.1, @is_linear_map.comp _ N.1 P.1 M.1 _ N.2 P.2 M.2 f.1 g.1 f.2 g.2⟩, Id := λ M, ⟨id, @is_linear_map.id _ M.1 _ M.2⟩, Hid_left := λ G H f, subtype.eq rfl, Hid_right := λ G H f, subtype.eq rfl, Hassoc := λ G H K N f g h, subtype.eq rfl } @[reducible] def of_poset (α : Type u) [partial_order α] : category α := { Mor := λ x y, plift $ x ≤ y, Comp := λ x y z hyz hxy, plift.up $ le_trans hxy.down hyz.down, Id := λ x, plift.up $ le_refl x, Hid_left := λ x y ⟨hxy⟩, rfl, Hid_right := λ x y ⟨hxy⟩, rfl, Hassoc := λ x y z w hzw hyz hxy, rfl } @[reducible] def Preord : category Σ α : Type u, preorder α := { Mor := λ S T, { f : S.1 → T.1 // @monotone S.1 T.1 S.2 T.2 f }, Comp := λ S T U f g, ⟨f.1 ∘ g.1, @monotone_comp S.1 T.1 U.1 S.2 T.2 U.2 g.1 f.1 g.2 f.2⟩, Id := λ S, ⟨id, @monotone_id S.1 S.2⟩, Hid_left := λ S T f, subtype.eq rfl, Hid_right := λ S T f, subtype.eq rfl, Hassoc := λ S T U V f g h, subtype.eq rfl } @[reducible] def zero : category empty := discrete empty @[reducible] def one : category unit := discrete unit @[reducible] def of_monoid (α : Type u) [monoid α] : category unit := { Mor := λ _ _, α, Comp := λ _ _ _, (*), Id := λ _, 1, Hid_left := λ _ _, one_mul, Hid_right := λ _ _, mul_one, Hassoc := λ _ _ _ _, mul_assoc } @[reducible] def to_monoid {α : Type u} (C: category α) (x : α) : monoid (C.Mor x x) := { mul := C.Comp _ _ _, mul_assoc := C.Hassoc x x x x, one := C.Id x, one_mul := C.Hid_left x x, mul_one := C.Hid_right x x } @[reducible] def two : category bool := { Mor := λ x y, plift $ x → y, Comp := λ _ _ _ f g, plift.up $ f.down ∘ g.down, Id := λ x, plift.up $ @id x, Hid_left := λ _ _ ⟨_⟩, rfl, Hid_right := λ _ _ ⟨_⟩, rfl, Hassoc := λ _ _ _ _ _ _ _, rfl } namespace par variable α : Type u inductive Mor : bool → bool → Type u | id : ∀ b, Mor b b | par : α → Mor ff tt @[reducible] def Comp : Π x y z, Mor α y z → Mor α x y → Mor α x z | ff ff _ f _ := f | _ tt tt _ g := g @[reducible] def Hid_left : ∀ x y f, Comp α x y y (Mor.id α y) f = f | ff ff (Mor.id α b) := rfl | ff tt _ := rfl | tt tt (Mor.id α b) := rfl @[reducible] def Hid_right : ∀ x y f, Comp α x x y f (Mor.id α x) = f | ff ff (Mor.id α b) := rfl | ff tt _ := rfl | tt tt (Mor.id α b) := rfl @[reducible] def Hassoc : ∀ x y z w f g h, Comp α x y w (Comp α y z w f g) h = Comp α x z w f (Comp α x y z g h) | ff ff _ _ _ _ _ := rfl | ff tt tt tt _ _ _ := rfl | tt tt tt tt _ _ _ := rfl end par @[reducible] def par (α : Type u) : category bool := { Mor := par.Mor α, Comp := par.Comp α, Id := par.Mor.id α, Hid_left := par.Hid_left α, Hid_right := par.Hid_right α, Hassoc := par.Hassoc α } @[reducible] def two_mor : category bool := par bool end examples end category
b3c80e8f0440e156a38b169efbbfb0e528f32b89
f5f7e6fae601a5fe3cac7cc3ed353ed781d62419
/src/category_theory/types.lean
9eca6f87183b6333b0e9fe6c00962f78f4622425
[ "Apache-2.0" ]
permissive
EdAyers/mathlib
9ecfb2f14bd6caad748b64c9c131befbff0fb4e0
ca5d4c1f16f9c451cf7170b10105d0051db79e1b
refs/heads/master
1,626,189,395,845
1,555,284,396,000
1,555,284,396,000
144,004,030
0
0
Apache-2.0
1,533,727,664,000
1,533,727,663,000
null
UTF-8
Lean
false
false
3,109
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, Johannes Hölzl import category_theory.functor_category import category_theory.fully_faithful namespace category_theory universes v v' w u u' -- declare the `v`'s first; see `category_theory.category` for an explanation instance types : large_category (Sort u) := { hom := λ a b, (a → b), id := λ a, id, comp := λ _ _ _ f g, g ∘ f } @[simp] lemma types_hom {α β : Sort u} : (α ⟶ β) = (α → β) := rfl @[simp] lemma types_id {α : Sort u} (a : α) : (𝟙 α : α → α) a = a := rfl @[simp] lemma types_comp {α β γ : Sort u} (f : α → β) (g : β → γ) (a : α) : (((f : α ⟶ β) ≫ (g : β ⟶ γ)) : α ⟶ γ) a = g (f a) := rfl namespace functor_to_types variables {C : Sort u} [𝒞 : category.{v} C] (F G H : C ⥤ Sort w) {X Y Z : C} include 𝒞 variables (σ : F ⟶ G) (τ : G ⟶ H) @[simp] lemma map_comp (f : X ⟶ Y) (g : Y ⟶ Z) (a : F.obj X) : (F.map (f ≫ g)) a = (F.map g) ((F.map f) a) := by simp @[simp] lemma map_id (a : F.obj X) : (F.map (𝟙 X)) a = a := by simp lemma naturality (f : X ⟶ Y) (x : F.obj X) : σ.app Y ((F.map f) x) = (G.map f) (σ.app X x) := congr_fun (σ.naturality f) x @[simp] lemma comp (x : F.obj X) : (σ ≫ τ).app X x = τ.app X (σ.app X x) := rfl variables {D : Sort u'} [𝒟 : category.{u'} D] (I J : D ⥤ C) (ρ : I ⟶ J) {W : D} @[simp] lemma hcomp (x : (I ⋙ F).obj W) : (ρ ◫ σ).app W x = (G.map (ρ.app W)) (σ.app (I.obj W) x) := rfl end functor_to_types def ulift_trivial (V : Type u) : ulift.{u} V ≅ V := by tidy def ulift_functor : Type u ⥤ Type (max u v) := { obj := λ X, ulift.{v} X, map := λ X Y f, λ x : ulift.{v} X, ulift.up (f x.down) } @[simp] lemma ulift_functor.map {X Y : Type u} (f : X ⟶ Y) (x : ulift.{v} X) : ulift_functor.map f x = ulift.up (f x.down) := rfl instance ulift_functor_faithful : fully_faithful ulift_functor := { preimage := λ X Y f x, (f (ulift.up x)).down, injectivity' := λ X Y f g p, funext $ λ x, congr_arg ulift.down ((congr_fun p (ulift.up x)) : ((ulift.up (f x)) = (ulift.up (g x)))) } end category_theory -- Isomorphisms in Type and equivalences. namespace equiv universe u variables {X Y : Sort u} def to_iso (e : X ≃ Y) : X ≅ Y := { hom := e.to_fun, inv := e.inv_fun, hom_inv_id' := funext e.left_inv, inv_hom_id' := funext e.right_inv } @[simp] lemma to_iso_hom {e : X ≃ Y} : e.to_iso.hom = e := rfl @[simp] lemma to_iso_inv {e : X ≃ Y} : e.to_iso.inv = e.symm := rfl end equiv namespace category_theory.iso universe u variables {X Y : Sort u} def to_equiv (i : X ≅ Y) : X ≃ Y := { to_fun := i.hom, inv_fun := i.inv, left_inv := λ x, congr_fun i.hom_inv_id x, right_inv := λ y, congr_fun i.inv_hom_id y } @[simp] lemma to_equiv_fun (i : X ≅ Y) : (i.to_equiv : X → Y) = i.hom := rfl @[simp] lemma to_equiv_symm_fun (i : X ≅ Y) : (i.to_equiv.symm : Y → X) = i.inv := rfl end category_theory.iso
bb77d97e1d89471570e19c6d550237df8f46a3e0
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/data/equiv/fintype.lean
ad9243600b0be64bfcc58ea9375cda0715b9c331
[ "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
5,401
lean
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import data.equiv.basic import data.set.finite import group_theory.perm.sign /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `fintype`s. # Main definitions - `function.embedding.to_equiv_range`: computably turn an embedding of a fintype into an `equiv` of the domain to its range - `equiv.perm.via_fintype_embedding : perm α → (α ↪ β) → perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `function.embedding.to_equiv_range` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `fintype`s. -/ variables {α β : Type*} [fintype α] [decidable_eq β] (e : equiv.perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ set.range f`, if `α` is a `fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `equiv.of_left_inverse'` or `equiv.of_left_inverse` instead. This is the computable version of `equiv.of_injective`. -/ def function.embedding.to_equiv_range : α ≃ set.range f := ⟨λ a, ⟨f a, set.mem_range_self a⟩, f.inv_of_mem_range, λ _, by simp, λ _, by simp⟩ @[simp] lemma function.embedding.to_equiv_range_apply (a : α) : f.to_equiv_range a = ⟨f a, set.mem_range_self a⟩ := rfl @[simp] lemma function.embedding.to_equiv_range_symm_apply_self (a : α) : f.to_equiv_range.symm ⟨f a, set.mem_range_self a⟩ = a := by simp [equiv.symm_apply_eq] lemma function.embedding.to_equiv_range_eq_of_injective : f.to_equiv_range = equiv.of_injective f f.injective := by { ext, simp } /-- Extend the domain of `e : equiv.perm α`, mapping it through `f : α ↪ β`. Everything outside of `set.range f` is kept fixed. Has poor computational performance, due to exhaustive searching in constructed inverse due to using `function.embedding.to_equiv_range`. When a better `α ≃ set.range f` is known, use `equiv.perm.via_set_range`. When `[fintype α]` is not available, a noncomputable version is available as `equiv.perm.via_embedding`. -/ def equiv.perm.via_fintype_embedding : equiv.perm β := e.extend_domain f.to_equiv_range @[simp] lemma equiv.perm.via_fintype_embedding_apply_image (a : α) : e.via_fintype_embedding f (f a) = f (e a) := begin rw equiv.perm.via_fintype_embedding, convert equiv.perm.extend_domain_apply_image e _ _ end lemma equiv.perm.via_fintype_embedding_apply_mem_range {b : β} (h : b ∈ set.range f) : e.via_fintype_embedding f b = f (e (f.inv_of_mem_range ⟨b, h⟩)) := by simpa [equiv.perm.via_fintype_embedding, equiv.perm.extend_domain_apply_subtype, h] lemma equiv.perm.via_fintype_embedding_apply_not_mem_range {b : β} (h : b ∉ set.range f) : e.via_fintype_embedding f b = b := by rwa [equiv.perm.via_fintype_embedding, equiv.perm.extend_domain_apply_not_subtype] @[simp] lemma equiv.perm.via_fintype_embedding_sign [decidable_eq α] [fintype β] : equiv.perm.sign (e.via_fintype_embedding f) = equiv.perm.sign e := by simp [equiv.perm.via_fintype_embedding] namespace equiv variables {p q : α → Prop} [decidable_pred p] [decidable_pred q] /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.to_compl` is an equivalence between the complement of those subtypes. See also `equiv.compl`, for a computable version when a term of type `{e' : α ≃ α // ∀ x : {x // p x}, e' x = e x}` is known. -/ noncomputable def to_compl (e : {x // p x} ≃ {x // q x}) : {x // ¬ p x} ≃ {x // ¬ q x} := classical.choice (fintype.card_eq.mp (fintype.card_compl_eq_card_compl (fintype.card_congr e))) /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.extend_subtype` is a permutation of `α` acting like `e` on the subtypes and doing something arbitrary outside. Note that when `p = q`, `equiv.perm.subtype_congr e (equiv.refl _)` can be used instead. -/ noncomputable abbreviation extend_subtype (e : {x // p x} ≃ {x // q x}) : perm α := subtype_congr e e.to_compl lemma extend_subtype_apply_of_mem (e : {x // p x} ≃ {x // q x}) (x) (hx : p x) : e.extend_subtype x = e ⟨x, hx⟩ := by { dunfold extend_subtype, simp only [subtype_congr, equiv.trans_apply, equiv.sum_congr_apply], rw [sum_compl_apply_symm_of_pos _ _ hx, sum.map_inl, sum_compl_apply_inl] } lemma extend_subtype_mem (e : {x // p x} ≃ {x // q x}) (x) (hx : p x) : q (e.extend_subtype x) := by { convert (e ⟨x, hx⟩).2, rw [e.extend_subtype_apply_of_mem _ hx, subtype.val_eq_coe] } lemma extend_subtype_apply_of_not_mem (e : {x // p x} ≃ {x // q x}) (x) (hx : ¬ p x) : e.extend_subtype x = e.to_compl ⟨x, hx⟩ := by { dunfold extend_subtype, simp only [subtype_congr, equiv.trans_apply, equiv.sum_congr_apply], rw [sum_compl_apply_symm_of_neg _ _ hx, sum.map_inr, sum_compl_apply_inr] } lemma extend_subtype_not_mem (e : {x // p x} ≃ {x // q x}) (x) (hx : ¬ p x) : ¬ q (e.extend_subtype x) := by { convert (e.to_compl ⟨x, hx⟩).2, rw [e.extend_subtype_apply_of_not_mem _ hx, subtype.val_eq_coe] } end equiv
86c8f547e81432bd017ec0e472690e2ea3137cc2
dfbb669f3f58ceb57cb207dcfab5726a07425b03
/vscode-lean4/test/test-fixtures/lean3/Main.lean
7cd8891b15bb64a888ae7059c74f9c4a1e365966
[ "Apache-2.0" ]
permissive
leanprover/vscode-lean4
8bcf7f06867b3c1d42007fe6da863a7a17444dbb
6ef0bfa668bdeaad0979e6df10551d42fcc01094
refs/heads/master
1,692,247,771,767
1,691,608,804,000
1,691,608,804,000
325,845,305
64
24
Apache-2.0
1,694,176,429,000
1,609,435,614,000
TypeScript
UTF-8
Lean
false
false
341
lean
-- Live WebAssembly version of Lean #eval let v := lean.version in let s := lean.special_version_desc in string.join ["Lean (version ", v.1.repr, ".", v.2.1.repr, ".", v.2.2.repr, ", ", if s ≠ "" then s ++ ", " else s, "commit ", (lean.githash.to_list.take 12).as_string, ")"] example (m n : ℕ) : m + n = n + m := by simp [nat.add_comm]
1b90624a4a733eee450357363e774a604047a475
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/tactic/chain_auto.lean
6945a779488b48866587019b21bbd473e124dfb7
[]
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
903
lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Mario Carneiro -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.tactic.ext import Mathlib.PostPort universes l namespace Mathlib namespace tactic /- This file defines a `chain` tactic, which takes a list of tactics, and exhaustively tries to apply them to the goals, until no tactic succeeds on any goal. Along the way, it generates auxiliary declarations, in order to speed up elaboration time of the resulting (sometimes long!) proofs. This tactic is used by the `tidy` tactic. -/ -- α is the return type of our tactics. When `chain` is called by `tidy`, this is string, -- describing what that tactic did as an interactive tactic. def tactic_script (α : Type) := _nest_1_1.tactic.tactic_script end Mathlib
a2c622a2d1bd592d463fc3e1f947edb40c616ddf
42610cc2e5db9c90269470365e6056df0122eaa0
/hott/homotopy/sphere2.hlean
e7ef858975c772a618bc826db7c9a90ccd255e8c
[ "Apache-2.0" ]
permissive
tomsib2001/lean
2ab59bfaebd24a62109f800dcf4a7139ebd73858
eb639a7d53fb40175bea5c8da86b51d14bb91f76
refs/heads/master
1,586,128,387,740
1,468,968,950,000
1,468,968,950,000
61,027,234
0
0
null
1,465,813,585,000
1,465,813,585,000
null
UTF-8
Lean
false
false
5,044
hlean
/- Copyright (c) 2016 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn Calculating homotopy groups of spheres. In this file we calculate π₂(S²) = Z πₙ(S²) = πₙ(S³) for n > 2 πₙ(Sⁿ) = Z for n > 0 π₂(S³) = Z -/ import .homotopy_group .freudenthal open eq group algebra is_equiv equiv fin prod chain_complex pointed fiber nat is_trunc trunc_index sphere.ops trunc is_conn susp namespace sphere /- Corollaries of the complex hopf fibration combined with the LES of homotopy groups -/ open sphere sphere.ops int circle hopf definition π2S2 : πg[1+1] (S. 2) ≃g gℤ := begin refine _ ⬝g fundamental_group_of_circle, refine _ ⬝g homotopy_group_isomorphism_of_pequiv _ pfiber_complex_phopf, fapply isomorphism_of_equiv, { fapply equiv.mk, { exact cc_to_fn (LES_of_homotopy_groups complex_phopf) (1, 2)}, { refine @is_equiv_of_trivial _ _ _ (is_exact_LES_of_homotopy_groups _ (1, 1)) (is_exact_LES_of_homotopy_groups _ (1, 2)) _ _ (@pgroup_of_group _ (group_LES_of_homotopy_groups complex_phopf _ _) idp) (@pgroup_of_group _ (group_LES_of_homotopy_groups complex_phopf _ _) idp) _, { rewrite [LES_of_homotopy_groups_1, ▸*], have H : 1 ≤[ℕ] 2, from !one_le_succ, apply trivial_homotopy_group_of_is_conn, exact H, rexact is_conn_psphere 3}, { refine tr_rev (λx, is_contr (ptrunctype._trans_of_to_pType x)) (LES_of_homotopy_groups_1 complex_phopf 2) _, apply trivial_homotopy_group_of_is_conn, apply le.refl, rexact is_conn_psphere 3}, { exact homomorphism.struct (homomorphism_LES_of_homotopy_groups_fun _ (0, 2))}}}, { exact homomorphism.struct (homomorphism_LES_of_homotopy_groups_fun _ (0, 2))} end open circle definition πnS3_eq_πnS2 (n : ℕ) : πg[n+2 +1] (S. 3) ≃g πg[n+2 +1] (S. 2) := begin fapply isomorphism_of_equiv, { fapply equiv.mk, { exact cc_to_fn (LES_of_homotopy_groups complex_phopf) (n+3, 0)}, { have H : is_trunc 1 (pfiber complex_phopf), from @(is_trunc_equiv_closed_rev _ pfiber_complex_phopf) is_trunc_circle, refine @is_equiv_of_trivial _ _ _ (is_exact_LES_of_homotopy_groups _ (n+2, 2)) (is_exact_LES_of_homotopy_groups _ (n+3, 0)) _ _ (@pgroup_of_group _ (group_LES_of_homotopy_groups complex_phopf _ _) idp) (@pgroup_of_group _ (group_LES_of_homotopy_groups complex_phopf _ _) idp) _, { rewrite [▸*, LES_of_homotopy_groups_2 _ (n +[ℕ] 2)], have H : 1 ≤[ℕ] n + 1, from !one_le_succ, apply trivial_homotopy_group_of_is_trunc _ _ _ H}, { refine tr_rev (λx, is_contr (ptrunctype._trans_of_to_pType x)) (LES_of_homotopy_groups_2 complex_phopf _) _, have H : 1 ≤[ℕ] n + 2, from !one_le_succ, apply trivial_homotopy_group_of_is_trunc _ _ _ H}, { exact homomorphism.struct (homomorphism_LES_of_homotopy_groups_fun _ (n+2, 0))}}}, { exact homomorphism.struct (homomorphism_LES_of_homotopy_groups_fun _ (n+2, 0))} end definition sphere_stability_pequiv (k n : ℕ) (H : k + 2 ≤ 2 * n) : π*[k + 1] (S. (n+1)) ≃* π*[k] (S. n) := begin rewrite [+ psphere_eq_iterate_susp], exact iterate_susp_stability_pequiv empty H end definition stability_isomorphism (k n : ℕ) (H : k + 3 ≤ 2 * n) : πg[k+1 +1] (S. (n+1)) ≃g πg[k+1] (S. n) := begin rewrite [+ psphere_eq_iterate_susp], exact iterate_susp_stability_isomorphism empty H end open int circle hopf definition πnSn (n : ℕ) : πg[n+1] (S. (succ n)) ≃g gℤ := begin cases n with n IH, { exact fundamental_group_of_circle}, { induction n with n IH, { exact π2S2}, { refine _ ⬝g IH, apply stability_isomorphism, rexact add_mul_le_mul_add n 1 2}} end theorem not_is_trunc_sphere (n : ℕ) : ¬is_trunc n (S. (succ n)) := begin intro H, note H2 := trivial_homotopy_group_of_is_trunc (S. (succ n)) n n !le.refl, have H3 : is_contr ℤ, from is_trunc_equiv_closed _ (equiv_of_isomorphism (πnSn n)), have H4 : (0 : ℤ) ≠ (1 : ℤ), from dec_star, apply H4, apply is_prop.elim, end section open sphere_index definition not_is_trunc_sphere' (n : ℕ₋₁) : ¬is_trunc n (S (n.+1)) := begin cases n with n, { esimp [sphere.ops.S, sphere], intro H, have H2 : is_prop bool, from @(is_trunc_equiv_closed -1 sphere_equiv_bool) H, have H3 : bool.tt ≠ bool.ff, from dec_star, apply H3, apply is_prop.elim}, { intro H, apply not_is_trunc_sphere (add_one n), rewrite [▸*, trunc_index_of_nat_add_one, -add_one_succ, sphere_index_of_nat_add_one], exact H} end end definition π3S2 : πg[2+1] (S. 2) ≃g gℤ := (πnS3_eq_πnS2 0)⁻¹ᵍ ⬝g πnSn 2 end sphere
f7c07852db0f4741a336780d9bf3739bea833dd6
63abd62053d479eae5abf4951554e1064a4c45b4
/src/tactic/lint/simp.lean
18f00af9eb1c62e35cb3487f0bb6806a21f705d9
[ "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
9,305
lean
/- Copyright (c) 2020 Gabriel Ebner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner -/ import tactic.lint.basic /-! # Linter for simplification lemmas This files defines several linters that prevent common mistakes when declaring simp lemmas: * `simp_nf` checks that the left-hand side of a simp lemma is not simplified by a different lemma. * `simp_var_head` checks that the head symbol of the left-hand side is not a variable. * `simp_comm` checks that commutativity lemmas are not marked as simplification lemmas. -/ open tactic expr /-- `simp_lhs_rhs ty` returns the left-hand and right-hand side of a simp lemma with type `ty`. -/ private meta def simp_lhs_rhs : expr → tactic (expr × expr) | ty := do ty ← head_beta ty, -- We only detect a fixed set of simp relations here. -- This is somewhat justified since for a custom simp relation R, -- the simp lemma `R a b` is implicitly converted to `R a b ↔ true` as well. match ty with | `(¬ %%lhs) := pure (lhs, `(false)) | `(%%lhs = %%rhs) := pure (lhs, rhs) | `(%%lhs ↔ %%rhs) := pure (lhs, rhs) | (expr.pi n bi a b) := do l ← mk_local' n bi a, simp_lhs_rhs (b.instantiate_var l) | ty := pure (ty, `(true)) end /-- `simp_lhs ty` returns the left-hand side of a simp lemma with type `ty`. -/ private meta def simp_lhs (ty : expr): tactic expr := prod.fst <$> simp_lhs_rhs ty /-- `simp_is_conditional_core ty` returns `none` if `ty` is a conditional simp lemma, and `some lhs` otherwise. -/ private meta def simp_is_conditional_core : expr → tactic (option expr) | ty := do ty ← head_beta ty, match ty with | `(¬ %%lhs) := pure lhs | `(%%lhs = _) := pure lhs | `(%%lhs ↔ _) := pure lhs | (expr.pi n bi a b) := do l ← mk_local' n bi a, some lhs ← simp_is_conditional_core (b.instantiate_var l) | pure none, if bi ≠ binder_info.inst_implicit ∧ ¬ (lhs.abstract_local l.local_uniq_name).has_var then pure none else pure lhs | ty := pure ty end /-- `simp_is_conditional ty` returns true iff the simp lemma with type `ty` is conditional. -/ private meta def simp_is_conditional (ty : expr) : tactic bool := option.is_none <$> simp_is_conditional_core ty private meta def heuristic_simp_lemma_extraction (prf : expr) : tactic (list name) := prf.list_constant.to_list.mfilter is_simp_lemma /-- Checks whether two expressions are equal for the simplifier. That is, they are reducibly-definitional equal, and they have the same head symbol. -/ meta def is_simp_eq (a b : expr) : tactic bool := if a.get_app_fn.const_name ≠ b.get_app_fn.const_name then pure ff else succeeds $ is_def_eq a b transparency.reducible /-- Reports declarations that are simp lemmas whose left-hand side is not in simp-normal form. -/ meta def simp_nf_linter (timeout := 200000) (d : declaration) : tactic (option string) := do tt ← is_simp_lemma d.to_name | pure none, -- Sometimes, a definition is tagged @[simp] to add the equational lemmas to the simp set. -- In this case, ignore the declaration if it is not a valid simp lemma by itself. tt ← is_valid_simp_lemma_cnst d.to_name | pure none, [] ← get_eqn_lemmas_for ff d.to_name | pure none, try_for timeout $ retrieve $ do g ← mk_meta_var d.type, set_goals [g], unfreezing intros, (lhs, rhs) ← target >>= simp_lhs_rhs, sls ← simp_lemmas.mk_default, let sls' := sls.erase [d.to_name], (lhs', prf1) ← decorate_error "simplify fails on left-hand side:" $ simplify sls [] lhs {fail_if_unchanged := ff}, prf1_lems ← heuristic_simp_lemma_extraction prf1, if d.to_name ∈ prf1_lems then pure none else do is_cond ← simp_is_conditional d.type, (rhs', prf2) ← decorate_error "simplify fails on right-hand side:" $ simplify sls [] rhs {fail_if_unchanged := ff}, lhs'_eq_rhs' ← is_simp_eq lhs' rhs', lhs_in_nf ← is_simp_eq lhs' lhs, if lhs'_eq_rhs' then do used_lemmas ← heuristic_simp_lemma_extraction (prf1 prf2), pure $ pure $ "simp can prove this:\n" ++ " by simp only " ++ to_string used_lemmas ++ "\n" ++ "One of the lemmas above could be a duplicate.\n" ++ "If that's not the case try reordering lemmas or adding @[priority].\n" else if ¬ lhs_in_nf then do lhs ← pp lhs, lhs' ← pp lhs', pure $ format.to_string $ to_fmt "Left-hand side simplifies from" ++ lhs.group.indent 2 ++ format.line ++ "to" ++ lhs'.group.indent 2 ++ format.line ++ "using " ++ (to_fmt prf1_lems).group.indent 2 ++ format.line ++ "Try to change the left-hand side to the simplified term!\n" else if ¬ is_cond ∧ lhs = lhs' then do pure "Left-hand side does not simplify.\nYou need to debug this yourself using `set_option trace.simplify.rewrite true`" else pure none /-- This note gives you some tips to debug any errors that the simp-normal form linter raises The reason that a lemma was considered faulty is because its left-hand side is not in simp-normal form. These lemmas are hence never used by the simplifier. This linter gives you a list of other simp lemmas, look at them! Here are some tips depending on the error raised by the linter: 1. 'the left-hand side reduces to XYZ': you should probably use XYZ as the left-hand side. 2. 'simp can prove this': This typically means that lemma is a duplicate, or is shadowed by another lemma: 2a. Always put more general lemmas after specific ones: @[simp] lemma zero_add_zero : 0 + 0 = 0 := rfl @[simp] lemma add_zero : x + 0 = x := rfl And not the other way around! The simplifier always picks the last matching lemma. 2b. You can also use @[priority] instead of moving simp-lemmas around in the file. Tip: the default priority is 1000. Use `@[priority 1100]` instead of moving a lemma down, and `@[priority 900]` instead of moving a lemma up. 2c. Conditional simp lemmas are tried last, if they are shadowed just remove the simp attribute. 2d. If two lemmas are duplicates, the linter will complain about the first one. Try to fix the second one instead! (You can find it among the other simp lemmas the linter prints out!) 3. 'try_for tactic failed, timeout': This typically means that there is a loop of simp lemmas. Try to apply squeeze_simp to the right-hand side (removing this lemma from the simp set) to see what lemmas might be causing the loop. Another trick is to `set_option trace.simplify.rewrite true` and then apply `try_for 10000 { simp }` to the right-hand side. You will see a periodic sequence of lemma applications in the trace message. -/ library_note "simp-normal form" /-- A linter for simp lemmas whose lhs is not in simp-normal form, and which hence never fire. -/ @[linter] meta def linter.simp_nf : linter := { test := simp_nf_linter, auto_decls := tt, no_errors_found := "All left-hand sides of simp lemmas are in simp-normal form", errors_found := "SOME SIMP LEMMAS ARE NOT IN SIMP-NORMAL FORM. see note [simp-normal form] for tips how to debug this. https://leanprover-community.github.io/mathlib_docs/notes.html#simp-normal%20form " } private meta def simp_var_head (d : declaration) : tactic (option string) := do tt ← is_simp_lemma d.to_name | pure none, -- Sometimes, a definition is tagged @[simp] to add the equational lemmas to the simp set. -- In this case, ignore the declaration if it is not a valid simp lemma by itself. tt ← is_valid_simp_lemma_cnst d.to_name | pure none, lhs ← simp_lhs d.type, head_sym@(expr.local_const _ _ _ _) ← pure lhs.get_app_fn | pure none, head_sym ← pp head_sym, pure $ format.to_string $ "Left-hand side has variable as head symbol: " ++ head_sym /-- A linter for simp lemmas whose lhs has a variable as head symbol, and which hence never fire. -/ @[linter] meta def linter.simp_var_head : linter := { test := simp_var_head, auto_decls := tt, no_errors_found := "No left-hand sides of a simp lemma has a variable as head symbol", errors_found := "LEFT-HAND SIDE HAS VARIABLE AS HEAD SYMBOL.\n" ++ "Some simp lemmas have a variable as head symbol of the left-hand side" } private meta def simp_comm (d : declaration) : tactic (option string) := do tt ← is_simp_lemma d.to_name | pure none, -- Sometimes, a definition is tagged @[simp] to add the equational lemmas to the simp set. -- In this case, ignore the declaration if it is not a valid simp lemma by itself. tt ← is_valid_simp_lemma_cnst d.to_name | pure none, (lhs, rhs) ← simp_lhs_rhs d.type, if lhs.get_app_fn.const_name ≠ rhs.get_app_fn.const_name then pure none else do (lhs', rhs') ← (prod.snd <$> open_pis_metas d.type) >>= simp_lhs_rhs, tt ← succeeds $ unify rhs lhs' transparency.reducible | pure none, tt ← succeeds $ is_def_eq rhs lhs' transparency.reducible | pure none, -- ensure that the second application makes progress: ff ← succeeds $ unify lhs' rhs' transparency.reducible | pure none, pure $ "should not be marked simp" /-- A linter for commutativity lemmas that are marked simp. -/ @[linter] meta def linter.simp_comm : linter := { test := simp_comm, auto_decls := tt, no_errors_found := "No commutativity lemma is marked simp", errors_found := "COMMUTATIVITY LEMMA IS SIMP.\n" ++ "Some commutativity lemmas are simp lemmas" }
ea6d62c8bf26ddf65a0167eac0a1521b952eabd1
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
/tests/lean/run/ind6.lean
52faaf33efc06da42525332945257bf52ad51425
[ "Apache-2.0" ]
permissive
soonhokong/lean-osx
4a954262c780e404c1369d6c06516161d07fcb40
3670278342d2f4faa49d95b46d86642d7875b47c
refs/heads/master
1,611,410,334,552
1,474,425,686,000
1,474,425,686,000
12,043,103
5
1
null
null
null
null
UTF-8
Lean
false
false
287
lean
exit inductive tree.{u} (A : Type.{u}) : Type.{max u 1} := | node : A → forest.{u} A → tree.{u} A with forest : Type.{max u 1} := | nil : forest.{u} A | cons : tree.{u} A → forest.{u} A → forest.{u} A check tree.{1} check forest.{1} check tree.rec.{1 1} check forest.rec.{1 1}
301107cbcc399a57415f270de5ea2ec7172e8dd7
0533ebfa09b11cf8a29da118dd1b86b94949511e
/src/riemann_zeta.lean
20e4e3eaf646da535fd93927808901c44e60380e
[ "MIT" ]
permissive
wudcscheme/Lean-RH
89e9055aac68703876e750c23fb5327979a09822
870f78cc7c0715d03466d1211b0f032b425ec984
refs/heads/main
1,679,188,429,923
1,602,701,790,000
1,602,701,790,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
8,227
lean
/- ------------------------------------------------------------------------- -| | @project: riemann_hypothesis | | @file: riemann_zeta.lean | | @author: Brandon H. Gomes and Alex Kontorovich | | @affil: Rutgers University | |- ------------------------------------------------------------------------- -/ import .cauchy /-! -/ namespace riemann_hypothesis --——————————————————————————————————————————————————————————-- namespace riemann_zeta --————————————————————————————————————————————————————————————————-- variables {ℝ : Type*} [has_lift_t nat ℝ] [preorder ℝ] [has_zero ℝ] [has_one ℝ] [has_neg ℝ] [has_add ℝ] [has_sub ℝ] [has_mul ℝ] [has_inv ℝ] open algebra /-- -/ def term {α β γ} [has_zero α] [has_lt α] [has_lift_t nat α] [has_lift_zero_same nat α] [has_lift_lt_comm nat α] [has_neg β] (pow : Π a : α, 0 < a → β → γ) (s n) := pow ↑(nat.succ n) (nat.lift.succ_pos α _) (-s) namespace term --——————————————————————————————————————————————————————————————————————————-- /-- `ζ` Series Term for Real Inputs `ζₙ(σ) := (n+1) ^ -σ` -/ def on_reals [has_lift_zero_same nat ℝ] [has_lift_lt_comm nat ℝ] (ℯ : ExpLog ℝ ℝ) (σ n) := term ℯ.pow σ n /-- -/ def on_reals.nonneg [has_lift_zero_same nat ℝ] [has_lift_lt_comm nat ℝ] (ℯ : ExpLog ℝ ℝ) (σ n) : 0 ≤ on_reals ℯ σ n := le_of_lt (ExpLog.exp_positive _ _) /-- -/ def on_reals.non_increasing [has_left_unit ℝ] [has_mul_zero_is_zero ℝ] [has_left_sub_distributivity ℝ] [has_inv_reverses_lt ℝ] [has_lt_pos_mul_preserves_right ℝ] [has_zero_sub_is_neg ℝ] [has_lift_lt_comm nat ℝ] [has_lift_zero_same nat ℝ] (ℯ : ExpLog ℝ ℝ) (σ σpos) : non_increasing (on_reals ℯ σ) := begin intros _, rw [on_reals, on_reals, term, term], rw ← has_zero_sub_is_neg.eq, rw [ExpLog.pow_neg_exponent_inverts, ExpLog.pow_neg_exponent_inverts], refine le_of_lt (has_inv_reverses_lt.lt (ExpLog.pow_monotonic _ _ _ σpos (has_lift_lt_comm.lt (nat.lt_succ_self _)))), end /-- -/ def on_reals.rewrite.pow_reduction [has_left_add_distributivity ℝ] [has_right_add_distributivity ℝ] [has_left_sub_distributivity ℝ] [has_left_unit ℝ] [has_right_unit ℝ] [has_zero_mul_is_zero ℝ] [has_mul_zero_is_zero ℝ] [has_zero_sub_is_neg ℝ] [has_mul_pos ℝ] [has_lift_one_same nat ℝ] [has_lift_zero_same nat ℝ] [has_lift_add_comm nat ℝ] [has_lift_mul_comm nat ℝ] [has_lift_lt_comm nat ℝ] [has_lift_le_comm nat ℝ] (ℯ : ExpLog ℝ ℝ) (σ) (n : nat) : ↑(2 ^ n) * on_reals ℯ σ (2 ^ n - 1) = ℯ.pow (ℯ.pow ↑2 _ (1 - σ)) (ℯ.pow_positivity _ (nat.lift.succ_pos ℝ _) _) ↑n := begin have lifted_pow2_pos : Π k : nat, 0 < (↑(2 ^ k) : ℝ), intros k, refine (lt_of_lt_of_le (nat.lift.zero_lt_one ℝ) _), rw one_is_lifted_one_lemma nat ℝ, refine has_lift_le_comm.le (nat.pow_two_ge_one _), rw [on_reals, term], rw ← ℯ.pow_id_at_one ↑(_) (lifted_pow2_pos _), rw ExpLog.pow_domain_irrel _ ↑(nat.succ (2 ^ n - 1)) _ _ (lifted_pow2_pos _) _ (by rw [nat.succ_eq_add_one, nat.sub_add_cancel (nat.pow_two_ge_one _)]), rw ℯ.pow_homomorphism_inv_from_neg, induction n with n hn, rw has_lift_zero_same.eq, rw ExpLog.pow_homomorphism_zero, rw ExpLog.pow_domain_irrel _ ↑(2 ^ 0) _ (1 : ℝ) _ _ (by rw [nat.pow_zero, has_lift_one_same.eq]), rw ExpLog.pow_homomorphism_one, rw ℯ.pow_succ_reduce _ (ℯ.pow_positivity _ (nat.lift.succ_pos ℝ _) _), have scaled_pow_ineq : 0 < (↑(2 ^ n) * ↑2 : ℝ), rw zero_is_lifted_zero_lemma nat ℝ, rw ← has_lift_mul_comm.eq, rw ← nat.pow_succ, refine has_lift_lt_comm.lt (lt_of_lt_of_le (nat.zero_lt_one) (nat.pow_two_ge_one _)), rw ExpLog.pow_domain_irrel _ ↑(2 ^ n.succ) _ _ scaled_pow_ineq _ (by rw [nat.pow_succ, has_lift_mul_comm.eq]), rw ℯ.pow_homomorphism_mul _ (lifted_pow2_pos _) _ (nat.lift.succ_pos ℝ _) _, rw hn, end end term --——————————————————————————————————————————————————————————————————————————————-- /-- `ζ` Series Partial Sum for Real Inputs -/ def partial.on_reals [has_lift_zero_same nat ℝ] [has_lift_lt_comm nat ℝ] (ℯ : ExpLog ℝ ℝ) := partial_sum ∘ (term.on_reals ℯ) /-- -/ def partial.on_reals.is_cauchy [has_add_le_add ℝ] [has_add_lt_add ℝ] [has_add_nonneg ℝ] [has_add_sub_assoc ℝ] [has_le_add_of_nonneg_of_le ℝ] [has_left_add_distributivity ℝ] [has_left_sub_distributivity ℝ] [has_lt_sub_neg ℝ] [has_mul_assoc ℝ] [has_pos_mul_neg_is_neg ℝ] [has_zero_right_add_cancel ℝ] [has_right_add_distributivity ℝ] [has_left_unit ℝ] [has_right_unit ℝ] [has_lift_one_same nat ℝ] [has_lift_zero_same nat ℝ] [has_lift_mul_comm nat ℝ] [has_lift_add_comm nat ℝ] [has_lift_lt_comm nat ℝ] [has_lift_le_comm nat ℝ] [has_sub_add_sub_cancel ℝ] [has_sub_self_is_zero ℝ] [has_sub_sub ℝ] [has_sub_ne_zero_of_ne ℝ] [has_zero_left_add_cancel ℝ] [has_zero_mul_is_zero ℝ] [has_mul_zero_is_zero ℝ] [has_inv_mul_right_cancel_self ℝ] [has_right_sub_distributivity ℝ] [has_add_sub_exchange ℝ] [has_inv_right_mul_lt_pos ℝ] [has_left_mul_inv_lt_neg ℝ] [has_zero_sub_is_neg ℝ] [has_inv_reverses_lt ℝ] [has_lt_pos_mul_preserves_right ℝ] [has_mul_pos ℝ] [has_sub_pos ℝ] (ℯ : ExpLog ℝ ℝ) (abs) (abs_zero abs_one abs_add abs_sub abs_mul abs_inv abs_ge_zero ge_zero_to_abs) (half ceil) (σ σ_gt_1) : is_cauchy abs (partial.on_reals ℯ σ) := begin refine condensation.cauchy_test _ abs_zero abs_ge_zero abs_add ge_zero_to_abs _ (term.on_reals.nonneg _ _) (term.on_reals.non_increasing _ _ (lt_trans (nat.lift.zero_lt_one _) σ_gt_1)) _, rw funext (term.on_reals.rewrite.pow_reduction ℯ _), refine geometric.series.is_cauchy _ abs_one abs_inv abs_sub abs_add abs_mul ge_zero_to_abs _ half ceil _ _ (ExpLog.exp_lt_zero_is_lt_one _ (has_pos_mul_neg_is_neg.lt (ExpLog.log_gt_one_is_gt_zero _ (nat.lift.succ_pos ℝ _) _) (has_lt_sub_neg.lt σ_gt_1))), rw one_is_lifted_one_lemma nat ℝ, refine has_lift_lt_comm.lt (nat.lt_succ_self _), end end riemann_zeta --——————————————————————————————————————————————————————————————————————-- end riemann_hypothesis --————————————————————————————————————————————————————————————————--
1683d4bc36f710ccb31be0c5aaa9ce0bf7efcf8e
9dc8cecdf3c4634764a18254e94d43da07142918
/src/analysis/special_functions/trigonometric/chebyshev.lean
78ddae6ca6b6f5046b29bc049dc27ff8f3a74b3e
[ "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
3,396
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 analysis.complex.basic import data.complex.exponential import data.polynomial.algebra_map import ring_theory.polynomial.chebyshev /-! # Multiple angle formulas in terms of Chebyshev polynomials This file gives the trigonometric characterizations of Chebyshev polynomials, for both the real (`real.cos`) and complex (`complex.cos`) cosine. -/ namespace polynomial.chebyshev open polynomial variables {R A : Type*} [comm_ring R] [comm_ring A] [algebra R A] @[simp] lemma aeval_T (x : A) (n : ℕ) : aeval x (T R n) = (T A n).eval x := by rw [aeval_def, eval₂_eq_eval_map, map_T] @[simp] lemma aeval_U (x : A) (n : ℕ) : aeval x (U R n) = (U A n).eval x := by rw [aeval_def, eval₂_eq_eval_map, map_U] @[simp] lemma algebra_map_eval_T (x : R) (n : ℕ) : algebra_map R A ((T R n).eval x) = (T A n).eval (algebra_map R A x) := by rw [←aeval_algebra_map_apply, aeval_T] @[simp] lemma algebra_map_eval_U (x : R) (n : ℕ) : algebra_map R A ((U R n).eval x) = (U A n).eval (algebra_map R A x) := by rw [←aeval_algebra_map_apply, aeval_U] @[simp, norm_cast] lemma complex_of_real_eval_T : ∀ x n, ((T ℝ n).eval x : ℂ) = (T ℂ n).eval x := @algebra_map_eval_T ℝ ℂ _ _ _ @[simp, norm_cast] lemma complex_of_real_eval_U : ∀ x n, ((U ℝ n).eval x : ℂ) = (U ℂ n).eval x := @algebra_map_eval_U ℝ ℂ _ _ _ /-! ### Complex versions -/ section complex open complex variable (θ : ℂ) /-- The `n`-th Chebyshev polynomial of the first kind evaluates on `cos θ` to the value `cos (n * θ)`. -/ @[simp] lemma T_complex_cos : ∀ n, (T ℂ n).eval (cos θ) = cos (n * θ) | 0 := by simp only [T_zero, eval_one, nat.cast_zero, zero_mul, cos_zero] | 1 := by simp only [eval_X, one_mul, T_one, nat.cast_one] | (n + 2) := begin simp only [eval_X, eval_one, T_add_two, eval_sub, eval_bit0, nat.cast_succ, eval_mul], rw [T_complex_cos (n + 1), T_complex_cos n], have aux : sin θ * sin θ = 1 - cos θ * cos θ, { rw ← sin_sq_add_cos_sq θ, ring, }, simp only [nat.cast_add, nat.cast_one, add_mul, cos_add, one_mul, sin_add, mul_assoc, aux], ring, end /-- The `n`-th Chebyshev polynomial of the second kind evaluates on `cos θ` to the value `sin ((n + 1) * θ) / sin θ`. -/ @[simp] lemma U_complex_cos (n : ℕ) : (U ℂ n).eval (cos θ) * sin θ = sin ((n + 1) * θ) := begin induction n with d hd, { simp only [U_zero, nat.cast_zero, eval_one, mul_one, zero_add, one_mul] }, { rw U_eq_X_mul_U_add_T, simp only [eval_add, eval_mul, eval_X, T_complex_cos, add_mul, mul_assoc, hd, one_mul], conv_rhs { rw [sin_add, mul_comm] }, push_cast, simp only [add_mul, one_mul] } end end complex /- ### Real versions -/ section real open real variables (θ : ℝ) (n : ℕ) /-- The `n`-th Chebyshev polynomial of the first kind evaluates on `cos θ` to the value `cos (n * θ)`. -/ @[simp] lemma T_real_cos : (T ℝ n).eval (cos θ) = cos (n * θ) := by exact_mod_cast T_complex_cos θ n /-- The `n`-th Chebyshev polynomial of the second kind evaluates on `cos θ` to the value `sin ((n + 1) * θ) / sin θ`. -/ @[simp] lemma U_real_cos : (U ℝ n).eval (cos θ) * sin θ = sin ((n + 1) * θ) := by exact_mod_cast U_complex_cos θ n end real end polynomial.chebyshev
9e35d36ee4d9431584c55a384fb7c0420ab9784e
75db7e3219bba2fbf41bf5b905f34fcb3c6ca3f2
/hott/init/trunc.hlean
d78e5953822f3ab5b3a5a647dcd5b89db1d9632d
[ "Apache-2.0" ]
permissive
jroesch/lean
30ef0860fa905d35b9ad6f76de1a4f65c9af6871
3de4ec1a6ce9a960feb2a48eeea8b53246fa34f2
refs/heads/master
1,586,090,835,348
1,455,142,203,000
1,455,142,277,000
51,536,958
1
0
null
1,455,215,811,000
1,455,215,811,000
null
UTF-8
Lean
false
false
13,178
hlean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Floris van Doorn Definition of is_trunc (n-truncatedness) Ported from Coq HoTT. -/ --TODO: can we replace some definitions with a hprop as codomain by theorems? prelude import .nat .logic .equiv .pathover open eq nat sigma unit --set_option class.force_new true namespace is_trunc /- Truncation levels -/ inductive trunc_index : Type₀ := | minus_two : trunc_index | succ : trunc_index → trunc_index open trunc_index definition has_zero_trunc_index [instance] [reducible] : has_zero trunc_index := has_zero.mk (succ (succ minus_two)) definition has_one_trunc_index [instance] [reducible] : has_one trunc_index := has_one.mk (succ (succ (succ minus_two))) /- notation for trunc_index is -2, -1, 0, 1, ... from 0 and up this comes from a coercion from num to trunc_index (via nat) -/ notation `-1` := trunc_index.succ trunc_index.minus_two -- ISSUE: -1 gets printed as -2.+1? notation `-2` := trunc_index.minus_two postfix ` .+1`:(max+1) := trunc_index.succ postfix ` .+2`:(max+1) := λn, (n .+1 .+1) notation `ℕ₋₂` := trunc_index -- input using \N-2 namespace trunc_index --addition, where we add two to the result definition add_plus_two [reducible] (n m : trunc_index) : trunc_index := trunc_index.rec_on m n (λ k l, l .+1) -- addition of trunc_indices, where results smaller than -2 are changed to -2 definition tr_add (n m : trunc_index) : trunc_index := trunc_index.cases_on m (trunc_index.cases_on n -2 (λn', (trunc_index.cases_on n' -2 id))) (λm', trunc_index.cases_on m' (trunc_index.cases_on n -2 id) (trunc_index.rec n (λn' r, succ r))) definition leq [reducible] (n m : trunc_index) : Type₀ := trunc_index.rec_on n (λm, unit) (λ n p m, trunc_index.rec_on m (λ p, empty) (λ m q p, p m) p) m definition has_le_trunc_index [instance] [reducible] : has_le trunc_index := has_le.mk leq end trunc_index attribute trunc_index.tr_add [reducible] infix `+2+`:65 := trunc_index.add_plus_two definition has_add_trunc_index [instance] [reducible] : has_add ℕ₋₂ := has_add.mk trunc_index.tr_add namespace trunc_index definition succ_le_succ {n m : trunc_index} (H : n ≤ m) : n.+1 ≤ m.+1 := proof H qed definition le_of_succ_le_succ {n m : trunc_index} (H : n.+1 ≤ m.+1) : n ≤ m := proof H qed definition minus_two_le (n : trunc_index) : -2 ≤ n := star definition le.refl (n : trunc_index) : n ≤ n := by induction n with n IH; exact star; exact IH definition empty_of_succ_le_minus_two {n : trunc_index} (H : n .+1 ≤ -2) : empty := H end trunc_index definition trunc_index.of_nat [coercion] [reducible] (n : nat) : trunc_index := (nat.rec_on n -2 (λ n k, k.+1)).+2 definition sub_two [reducible] (n : nat) : trunc_index := nat.rec_on n -2 (λ n k, k.+1) postfix ` .-2`:(max+1) := sub_two /- truncated types -/ /- Just as in Coq HoTT we define an internal version of contractibility and is_trunc, but we only use `is_trunc` and `is_contr` -/ structure contr_internal (A : Type) := (center : A) (center_eq : Π(a : A), center = a) definition is_trunc_internal (n : trunc_index) : Type → Type := trunc_index.rec_on n (λA, contr_internal A) (λn trunc_n A, (Π(x y : A), trunc_n (x = y))) end is_trunc open is_trunc structure is_trunc [class] (n : trunc_index) (A : Type) := (to_internal : is_trunc_internal n A) open nat num is_trunc.trunc_index namespace is_trunc abbreviation is_contr := is_trunc -2 abbreviation is_hprop := is_trunc -1 abbreviation is_hset := is_trunc 0 variables {A B : Type} definition is_trunc_succ_intro (A : Type) (n : trunc_index) [H : ∀x y : A, is_trunc n (x = y)] : is_trunc n.+1 A := is_trunc.mk (λ x y, !is_trunc.to_internal) definition is_trunc_eq [instance] [priority 1200] (n : trunc_index) [H : is_trunc (n.+1) A] (x y : A) : is_trunc n (x = y) := is_trunc.mk (is_trunc.to_internal (n.+1) A x y) /- contractibility -/ definition is_contr.mk (center : A) (center_eq : Π(a : A), center = a) : is_contr A := is_trunc.mk (contr_internal.mk center center_eq) definition center (A : Type) [H : is_contr A] : A := contr_internal.center (is_trunc.to_internal -2 A) definition center_eq [H : is_contr A] (a : A) : !center = a := contr_internal.center_eq (is_trunc.to_internal -2 A) a definition eq_of_is_contr [H : is_contr A] (x y : A) : x = y := (center_eq x)⁻¹ ⬝ (center_eq y) definition hprop_eq_of_is_contr {A : Type} [H : is_contr A] {x y : A} (p q : x = y) : p = q := have K : ∀ (r : x = y), eq_of_is_contr x y = r, from (λ r, eq.rec_on r !con.left_inv), (K p)⁻¹ ⬝ K q theorem is_contr_eq {A : Type} [H : is_contr A] (x y : A) : is_contr (x = y) := is_contr.mk !eq_of_is_contr (λ p, !hprop_eq_of_is_contr) local attribute is_contr_eq [instance] /- truncation is upward close -/ -- n-types are also (n+1)-types theorem is_trunc_succ [instance] [priority 900] (A : Type) (n : trunc_index) [H : is_trunc n A] : is_trunc (n.+1) A := trunc_index.rec_on n (λ A (H : is_contr A), !is_trunc_succ_intro) (λ n IH A (H : is_trunc (n.+1) A), @is_trunc_succ_intro _ _ (λ x y, IH _ _)) A H --in the proof the type of H is given explicitly to make it available for class inference theorem is_trunc_of_leq.{l} (A : Type.{l}) {n m : trunc_index} (Hnm : n ≤ m) [Hn : is_trunc n A] : is_trunc m A := have base : ∀k A, k ≤ -2 → is_trunc k A → (is_trunc -2 A), from λ k A, trunc_index.cases_on k (λh1 h2, h2) (λk h1 h2, empty.elim (trunc_index.empty_of_succ_le_minus_two h1)), have step : Π (m : trunc_index) (IHm : Π (n : trunc_index) (A : Type), n ≤ m → is_trunc n A → is_trunc m A) (n : trunc_index) (A : Type) (Hnm : n ≤ m .+1) (Hn : is_trunc n A), is_trunc m .+1 A, from λm IHm n, trunc_index.rec_on n (λA Hnm Hn, @is_trunc_succ A m (IHm -2 A star Hn)) (λn IHn A Hnm (Hn : is_trunc n.+1 A), @is_trunc_succ_intro A m (λx y, IHm n (x = y) (trunc_index.le_of_succ_le_succ Hnm) _)), trunc_index.rec_on m base step n A Hnm Hn definition is_trunc_of_imp_is_trunc {n : trunc_index} (H : A → is_trunc (n.+1) A) : is_trunc (n.+1) A := @is_trunc_succ_intro _ _ (λx y, @is_trunc_eq _ _ (H x) x y) definition is_trunc_of_imp_is_trunc_of_leq {n : trunc_index} (Hn : -1 ≤ n) (H : A → is_trunc n A) : is_trunc n A := trunc_index.rec_on n (λHn H, empty.rec _ Hn) (λn IH Hn, is_trunc_of_imp_is_trunc) Hn H -- these must be definitions, because we need them to compute sometimes definition is_trunc_of_is_contr (A : Type) (n : trunc_index) [H : is_contr A] : is_trunc n A := trunc_index.rec_on n H (λn H, _) definition is_trunc_succ_of_is_hprop (A : Type) (n : trunc_index) [H : is_hprop A] : is_trunc (n.+1) A := is_trunc_of_leq A (show -1 ≤ n.+1, from star) definition is_trunc_succ_succ_of_is_hset (A : Type) (n : trunc_index) [H : is_hset A] : is_trunc (n.+2) A := @(is_trunc_of_leq A (show 0 ≤ n.+2, from proof star qed)) H /- hprops -/ definition is_hprop.elim [H : is_hprop A] (x y : A) : x = y := !center definition is_contr_of_inhabited_hprop {A : Type} [H : is_hprop A] (x : A) : is_contr A := is_contr.mk x (λy, !is_hprop.elim) theorem is_hprop_of_imp_is_contr {A : Type} (H : A → is_contr A) : is_hprop A := @is_trunc_succ_intro A -2 (λx y, have H2 [visible] : is_contr A, from H x, !is_contr_eq) theorem is_hprop.mk {A : Type} (H : ∀x y : A, x = y) : is_hprop A := is_hprop_of_imp_is_contr (λ x, is_contr.mk x (H x)) theorem is_hprop_elim_self {A : Type} {H : is_hprop A} (x : A) : is_hprop.elim x x = idp := !is_hprop.elim /- hsets -/ theorem is_hset.mk (A : Type) (H : ∀(x y : A) (p q : x = y), p = q) : is_hset A := @is_trunc_succ_intro _ _ (λ x y, is_hprop.mk (H x y)) definition is_hset.elim [H : is_hset A] ⦃x y : A⦄ (p q : x = y) : p = q := !is_hprop.elim /- instances -/ definition is_contr_sigma_eq [instance] [priority 800] {A : Type} (a : A) : is_contr (Σ(x : A), a = x) := is_contr.mk (sigma.mk a idp) (λp, sigma.rec_on p (λ b q, eq.rec_on q idp)) definition is_contr_sigma_eq' [instance] [priority 800] {A : Type} (a : A) : is_contr (Σ(x : A), x = a) := is_contr.mk (sigma.mk a idp) (λp, sigma.rec_on p (λ b q, eq.rec_on q idp)) definition is_contr_unit : is_contr unit := is_contr.mk star (λp, unit.rec_on p idp) definition is_hprop_empty : is_hprop empty := is_hprop.mk (λx, !empty.elim x) local attribute is_contr_unit is_hprop_empty [instance] definition is_trunc_unit [instance] (n : trunc_index) : is_trunc n unit := !is_trunc_of_is_contr definition is_trunc_empty [instance] (n : trunc_index) : is_trunc (n.+1) empty := !is_trunc_succ_of_is_hprop /- interaction with equivalences -/ section open is_equiv equiv --should we remove the following two theorems as they are special cases of --"is_trunc_is_equiv_closed" definition is_contr_is_equiv_closed (f : A → B) [Hf : is_equiv f] [HA: is_contr A] : (is_contr B) := is_contr.mk (f (center A)) (λp, eq_of_eq_inv !center_eq) definition is_contr_equiv_closed (H : A ≃ B) [HA: is_contr A] : is_contr B := is_contr_is_equiv_closed (to_fun H) definition equiv_of_is_contr_of_is_contr [HA : is_contr A] [HB : is_contr B] : A ≃ B := equiv.mk (λa, center B) (is_equiv.adjointify (λa, center B) (λb, center A) center_eq center_eq) theorem is_trunc_is_equiv_closed (n : trunc_index) (f : A → B) [H : is_equiv f] [HA : is_trunc n A] : is_trunc n B := trunc_index.rec_on n (λA (HA : is_contr A) B f (H : is_equiv f), is_contr_is_equiv_closed f) (λn IH A (HA : is_trunc n.+1 A) B f (H : is_equiv f), @is_trunc_succ_intro _ _ (λ x y : B, IH (f⁻¹ x = f⁻¹ y) _ (x = y) (ap f⁻¹)⁻¹ !is_equiv_inv)) A HA B f H definition is_trunc_is_equiv_closed_rev (n : trunc_index) (f : A → B) [H : is_equiv f] [HA : is_trunc n B] : is_trunc n A := is_trunc_is_equiv_closed n f⁻¹ definition is_trunc_equiv_closed (n : trunc_index) (f : A ≃ B) [HA : is_trunc n A] : is_trunc n B := is_trunc_is_equiv_closed n (to_fun f) definition is_trunc_equiv_closed_rev (n : trunc_index) (f : A ≃ B) [HA : is_trunc n B] : is_trunc n A := is_trunc_is_equiv_closed n (to_inv f) definition is_equiv_of_is_hprop [constructor] [HA : is_hprop A] [HB : is_hprop B] (f : A → B) (g : B → A) : is_equiv f := is_equiv.mk f g (λb, !is_hprop.elim) (λa, !is_hprop.elim) (λa, !is_hset.elim) definition equiv_of_is_hprop [constructor] [HA : is_hprop A] [HB : is_hprop B] (f : A → B) (g : B → A) : A ≃ B := equiv.mk f (is_equiv_of_is_hprop f g) definition equiv_of_iff_of_is_hprop [unfold 5] [HA : is_hprop A] [HB : is_hprop B] (H : A ↔ B) : A ≃ B := equiv_of_is_hprop (iff.elim_left H) (iff.elim_right H) /- truncatedness of lift -/ definition is_trunc_lift [instance] [priority 1450] (A : Type) (n : trunc_index) [H : is_trunc n A] : is_trunc n (lift A) := is_trunc_equiv_closed _ !equiv_lift end /- interaction with the Unit type -/ open equiv -- A contractible type is equivalent to [Unit]. *) variable (A) definition equiv_unit_of_is_contr [H : is_contr A] : A ≃ unit := equiv.MK (λ (x : A), ⋆) (λ (u : unit), center A) (λ (u : unit), unit.rec_on u idp) (λ (x : A), center_eq x) /- interaction with pathovers -/ variable {A} variables {C : A → Type} {a a₂ : A} (p : a = a₂) (c : C a) (c₂ : C a₂) definition is_hprop.elimo [H : is_hprop (C a)] : c =[p] c₂ := pathover_of_eq_tr !is_hprop.elim definition is_trunc_pathover [instance] (n : trunc_index) [H : is_trunc (n.+1) (C a)] : is_trunc n (c =[p] c₂) := is_trunc_equiv_closed_rev n !pathover_equiv_eq_tr variables {p c c₂} theorem is_hset.elimo (q q' : c =[p] c₂) [H : is_hset (C a)] : q = q' := !is_hprop.elim -- TODO: port "Truncated morphisms" /- truncated universe -/ -- TODO: move to root namespace? structure trunctype (n : trunc_index) := (carrier : Type) (struct : is_trunc n carrier) attribute trunctype.carrier [coercion] attribute trunctype.struct [instance] [priority 1400] notation n `-Type` := trunctype n abbreviation hprop := -1-Type abbreviation hset := 0-Type protected abbreviation hprop.mk := @trunctype.mk -1 protected abbreviation hset.mk := @trunctype.mk (-1.+1) protected abbreviation trunctype.mk' [parsing_only] (n : trunc_index) (A : Type) [H : is_trunc n A] : n-Type := trunctype.mk A H definition tlift.{u v} [constructor] {n : trunc_index} (A : trunctype.{u} n) : trunctype.{max u v} n := trunctype.mk (lift A) (is_trunc_lift _ _) end is_trunc
154a16d1978a362d5c16b93f559c6a0ab60c3aab
21c6ba3d88e3d63bc4dc2369086afcea71fdab70
/.config.nor.lean
2b80473b1a60326f89879414849a89f7383f70e4
[ "MIT" ]
permissive
panda7887x2/OpenWrt_AR750S
a3b527a07c5d13001207658b965b5888907df36b
178dfd579c661259a1fa4444c5274544cff3dd06
refs/heads/main
1,693,700,189,495
1,637,408,343,000
1,637,408,343,000
430,083,044
2
0
MIT
1,637,407,336,000
1,637,407,335,000
null
UTF-8
Lean
false
false
250,326
lean
# # Automatically generated file; DO NOT EDIT. # OpenWrt Configuration # CONFIG_MODULES=y CONFIG_HAVE_DOT_CONFIG=y # CONFIG_TARGET_sunxi is not set # CONFIG_TARGET_apm821xx is not set # CONFIG_TARGET_ath25 is not set CONFIG_TARGET_ar71xx=y # CONFIG_TARGET_ath79 is not set # CONFIG_TARGET_bcm27xx is not set # CONFIG_TARGET_bcm53xx is not set # CONFIG_TARGET_bcm47xx is not set # CONFIG_TARGET_bcm63xx is not set # CONFIG_TARGET_cns3xxx is not set # CONFIG_TARGET_octeon is not set # CONFIG_TARGET_gemini is not set # CONFIG_TARGET_mpc85xx is not set # CONFIG_TARGET_imx6 is not set # CONFIG_TARGET_mxs is not set # CONFIG_TARGET_lantiq is not set # CONFIG_TARGET_malta is not set # CONFIG_TARGET_pistachio is not set # CONFIG_TARGET_mvebu is not set # CONFIG_TARGET_kirkwood is not set # CONFIG_TARGET_mediatek is not set # CONFIG_TARGET_ramips is not set # CONFIG_TARGET_at91 is not set # CONFIG_TARGET_rb532 is not set # CONFIG_TARGET_tegra is not set # CONFIG_TARGET_layerscape is not set # CONFIG_TARGET_octeontx is not set # CONFIG_TARGET_oxnas is not set # CONFIG_TARGET_armvirt is not set # CONFIG_TARGET_ipq40xx is not set # CONFIG_TARGET_ipq806x is not set # CONFIG_TARGET_ipq807x is not set # CONFIG_TARGET_rockchip is not set # CONFIG_TARGET_samsung is not set # CONFIG_TARGET_arc770 is not set # CONFIG_TARGET_archs38 is not set # CONFIG_TARGET_omap is not set # CONFIG_TARGET_uml is not set # CONFIG_TARGET_zynq is not set # CONFIG_TARGET_x86 is not set CONFIG_TARGET_ar71xx_generic=y # CONFIG_TARGET_ar71xx_tiny is not set # CONFIG_TARGET_ar71xx_nand is not set # CONFIG_TARGET_ar71xx_mikrotik is not set # CONFIG_TARGET_MULTI_PROFILE is not set # CONFIG_TARGET_ar71xx_generic_Default is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_carambola2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_lima is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ALFAAP120C is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ap121f is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ALFAAP96 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_HORNETUB is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_HORNETUBx2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ALFANX is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_n5q is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_r36a is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_TUBE2H16M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_TUBE2H8M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_fritz4020 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_fritz300e is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_fritz450e is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_sc1750 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_sc300m is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_sc450 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_c-55 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ALL0258N is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ALL0305 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ALL0315N is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_antminer-s1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_antminer-s3 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_antrouter-r1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_arduino-yun is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_AP121_16M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_AP121_8M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_AP132 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_AP135 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_AP136_010 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_AP136_020 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_AP96 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_DB120 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_PB42 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_PB44 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_BXU2000N2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_WZR450HP2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_WZR600DHP is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_WZRHPAG300H is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_WZRHPG300NH is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_WZRHPG300NH2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_WZRHPG450H is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cf-e316n-v2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cf-e320n-v2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cf-e355ac-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cf-e355ac-v2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cf-e375ac is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cf-e380ac-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cf-e380ac-v2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cf-e385ac is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cf-e520n is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cf-e530n is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_WP543_16M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_WP543_8M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_WPE72_16M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_WPE72_8M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_wpj342 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_wpj344 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_wpj531 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_wpj558 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_wpj563 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_dap-1330-a1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_dap-2695-a1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_DGL5500A1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_DHP1565A1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_DIR505A1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_DIR825B1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_DIR825C1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_DIR835A1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_dir-869-a1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_dragino2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_el-m150 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_el-mini is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ew-balin is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ew-dorin is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ew-dorin-router is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_EAP300V2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_EPG5000 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ESR1750 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ESR900 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_gl-inet-6408A-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_gl-inet-6416A-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_gl-domino is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_gl-ar150 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_gl-ar300 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_gl-ar300m is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_gl-ar750 is not set CONFIG_TARGET_ar71xx_generic_DEVICE_gl-ar750s=y # CONFIG_TARGET_ar71xx_generic_DEVICE_gl-mifi is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_gl-usb150 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_minibox-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_oolite-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_oolite-v5.2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_oolite-v5.2-dev is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_minibox-v3.2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_lan-turtle is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_packet-squirrel is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_wifi-pineapple-nano is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_hiwifi-hc6361 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_WRT160NL is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_WRT400N is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_mr12 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_mr16 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_mc-mac1200r is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_mw4530r-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_smart-300 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_WNDAP360 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_wndr3700 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_wndr3700v2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_wndr3800 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_wndr3800ch is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_wndrmac is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_wndrmacv2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_WNR2200 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_koala is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_omy-g1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_omy-x1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_onion-omega is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_som9331 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_A60 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_MR1750 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_MR600 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_MR900 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_OM2P is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_OM5PAC is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_OM5P is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cpe505n is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_r602n is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ts-d084 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_pqi-air-pen is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_MZKW04NU is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_MZKW300NH is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cap324 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cr3000 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cr5000 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_DLRTDEV01 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_qihoo-c301 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_AP143_16M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_AP143_8M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_AP147_010 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_AP152_16M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_e1700ac-v2-16M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_e1700ac-v2-8M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_e558-v2-16M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_e558-v2-8M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_e600g-v2-16M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_e600g-v2-8M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_e600gac-v2-16M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_e600gac-v2-8M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_e750a-v4-16M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_e750a-v4-8M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_e750g-v8-16M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_e750g-v8-8M is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ap531b0 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_wam250 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_CAP4200AG is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_EAP7660D is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_wlr8100 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_bsb is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_archer-c25-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_archer-c5-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_archer-c58-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_archer-c59-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_archer-c59-v2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_archer-c60-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_archer-c60-v2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_archer-c7-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_archer-c7-v2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_archer-c7-v2-il is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wdr7500-v3 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_archer-c7-v4 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_archer-c7-v5 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cpe210-v2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cpe210-v3 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cpe210-220-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cpe510-v2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cpe510-520-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_eap120-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_re355-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_re450-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-mr6400-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wdr3500-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wdr3600-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wdr4300-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wdr4300-v1-il is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wdr4310-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wdr4900-v2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wdr6500-v2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wpa8630-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wr1043n-v5 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wr1043nd-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wr1043nd-v2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wr1043nd-v3 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wr1043nd-v4 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wr2543-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wr710n-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wr710n-v2.1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wr810n-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wr810n-v2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wr842n-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wr842n-v2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wr842n-v3 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wr902ac-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tl-wr942n-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_wbs210-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_wbs510-v1 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_TEW673GRU is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_TEW732BR is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_TEW823DRU is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_tellstick-znet-lite is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_rut900 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-air-gateway is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-air-gateway-pro is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-airrouter is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-bullet-m is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-bullet-m-xw is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-ls-sr71 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-lbe-m5 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-loco-m-xw is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-nano-m-xw is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-nano-m is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_rw2458n is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-rocket-m-ti is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-rocket-m-xw is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-rocket-m is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-rs is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-rspro is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-uap-pro is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-unifi is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-unifiac-lr is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-unifiac-lite is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-unifiac-mesh is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-unifiac-mesh-pro is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-unifiac-pro is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-unifi-outdoor is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubnt-unifi-outdoor-plus is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ubdev01 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_wrtnode2q is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_dr342 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_dr531 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_weio is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_mynet-n600 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_mynet-n750 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_MYNETREXT is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ap90q is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cpe830 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_cpe870 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_sr3200 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_t830 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_xd3200 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ZCN1523H28 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_ZCN1523H516 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_NBG6616 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_dLAN_Hotspot is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_dLAN_pro_1200_ac is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_dLAN_pro_500_wp is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_rme-eg200 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_JA76PF is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_JA76PF2 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_JWAP003 is not set # CONFIG_TARGET_ar71xx_generic_DEVICE_jwap230 is not set CONFIG_HAS_SUBTARGETS=y CONFIG_HAS_DEVICES=y CONFIG_TARGET_BOARD="ar71xx" CONFIG_TARGET_SUBTARGET="generic" CONFIG_TARGET_PROFILE="DEVICE_gl-ar750s" CONFIG_TARGET_ARCH_PACKAGES="mips_24kc" CONFIG_DEFAULT_TARGET_OPTIMIZATION="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc" CONFIG_CPU_TYPE="24kc" CONFIG_LINUX_4_14=y CONFIG_DEFAULT_ath10k-firmware-qca9887-ct=y CONFIG_DEFAULT_base-files=y CONFIG_DEFAULT_block-mount=y CONFIG_DEFAULT_busybox=y CONFIG_DEFAULT_ca-certificates=y CONFIG_DEFAULT_coremark=y CONFIG_DEFAULT_ddns-scripts_aliyun=y CONFIG_DEFAULT_ddns-scripts_dnspod=y CONFIG_DEFAULT_default-settings=y CONFIG_DEFAULT_dnsmasq-full=y CONFIG_DEFAULT_dropbear=y CONFIG_DEFAULT_firewall=y CONFIG_DEFAULT_fstools=y CONFIG_DEFAULT_iptables=y CONFIG_DEFAULT_iwinfo=y CONFIG_DEFAULT_kmod-ath10k-ct=y CONFIG_DEFAULT_kmod-ath9k=y CONFIG_DEFAULT_kmod-gpio-button-hotplug=y CONFIG_DEFAULT_kmod-ipt-raw=y CONFIG_DEFAULT_kmod-nf-nathelper=y CONFIG_DEFAULT_kmod-nf-nathelper-extra=y CONFIG_DEFAULT_kmod-usb-storage=y CONFIG_DEFAULT_kmod-usb2=y CONFIG_DEFAULT_libc=y CONFIG_DEFAULT_libgcc=y CONFIG_DEFAULT_libustream-openssl=y CONFIG_DEFAULT_logd=y CONFIG_DEFAULT_luci=y CONFIG_DEFAULT_luci-app-accesscontrol=y CONFIG_DEFAULT_luci-app-arpbind=y CONFIG_DEFAULT_luci-app-autoreboot=y CONFIG_DEFAULT_luci-app-cpufreq=y CONFIG_DEFAULT_luci-app-ddns=y CONFIG_DEFAULT_luci-app-filetransfer=y CONFIG_DEFAULT_luci-app-nlbwmon=y CONFIG_DEFAULT_luci-app-ramfree=y CONFIG_DEFAULT_luci-app-sfe=y CONFIG_DEFAULT_luci-app-ssr-plus=y CONFIG_DEFAULT_luci-app-unblockmusic=y CONFIG_DEFAULT_luci-app-upnp=y CONFIG_DEFAULT_luci-app-vlmcsd=y CONFIG_DEFAULT_luci-app-vsftpd=y CONFIG_DEFAULT_luci-app-webadmin=y CONFIG_DEFAULT_luci-app-wol=y CONFIG_DEFAULT_mtd=y CONFIG_DEFAULT_netifd=y CONFIG_DEFAULT_opkg=y CONFIG_DEFAULT_ppp=y CONFIG_DEFAULT_ppp-mod-pppoe=y CONFIG_DEFAULT_swconfig=y CONFIG_DEFAULT_uboot-envtools=y CONFIG_DEFAULT_uci=y CONFIG_DEFAULT_uclient-fetch=y CONFIG_DEFAULT_urandom-seed=y CONFIG_DEFAULT_urngd=y CONFIG_DEFAULT_wget=y CONFIG_DEFAULT_wpad-basic=y CONFIG_AUDIO_SUPPORT=y CONFIG_GPIO_SUPPORT=y CONFIG_PCI_SUPPORT=y CONFIG_USB_SUPPORT=y CONFIG_USB_GADGET_SUPPORT=y CONFIG_BIG_ENDIAN=y CONFIG_USES_SQUASHFS=y CONFIG_HAS_MIPS16=y CONFIG_mips=y CONFIG_ARCH="mips" # # Target Images # # CONFIG_TARGET_ROOTFS_INITRAMFS is not set CONFIG_EXTERNAL_CPIO="" # # Root filesystem archives # # CONFIG_TARGET_ROOTFS_CPIOGZ is not set # CONFIG_TARGET_ROOTFS_TARGZ is not set # # Root filesystem images # # CONFIG_TARGET_ROOTFS_EXT4FS is not set CONFIG_TARGET_ROOTFS_SQUASHFS=y CONFIG_TARGET_SQUASHFS_BLOCK_SIZE=256 CONFIG_TARGET_UBIFS_FREE_SPACE_FIXUP=y CONFIG_TARGET_UBIFS_JOURNAL_SIZE="" # # Image Options # # end of Target Images # # Global build settings # # CONFIG_JSON_OVERVIEW_IMAGE_INFO is not set # CONFIG_ALL_NONSHARED is not set # CONFIG_ALL_KMODS is not set # CONFIG_ALL is not set # CONFIG_BUILDBOT is not set CONFIG_SIGNED_PACKAGES=y CONFIG_SIGNATURE_CHECK=y # # General build options # # CONFIG_DISPLAY_SUPPORT is not set # CONFIG_BUILD_PATENTED is not set # CONFIG_BUILD_NLS is not set CONFIG_SHADOW_PASSWORDS=y # CONFIG_CLEAN_IPKG is not set # CONFIG_IPK_FILES_CHECKSUMS is not set # CONFIG_INCLUDE_CONFIG is not set # CONFIG_COLLECT_KERNEL_DEBUG is not set # # Kernel build options # CONFIG_KERNEL_BUILD_USER="" CONFIG_KERNEL_BUILD_DOMAIN="" CONFIG_KERNEL_PRINTK=y CONFIG_KERNEL_CRASHLOG=y CONFIG_KERNEL_SWAP=y CONFIG_KERNEL_DEBUG_FS=y CONFIG_KERNEL_MIPS_FPU_EMULATOR=y CONFIG_KERNEL_MIPS_FP_SUPPORT=y # CONFIG_KERNEL_PERF_EVENTS is not set # CONFIG_KERNEL_PROFILING is not set # CONFIG_KERNEL_UBSAN is not set # CONFIG_KERNEL_KCOV is not set # CONFIG_KERNEL_TASKSTATS is not set CONFIG_KERNEL_KALLSYMS=y # CONFIG_KERNEL_FTRACE is not set CONFIG_KERNEL_DEBUG_KERNEL=y CONFIG_KERNEL_DEBUG_INFO=y # CONFIG_KERNEL_DYNAMIC_DEBUG is not set # CONFIG_KERNEL_KPROBES is not set CONFIG_KERNEL_AIO=y CONFIG_KERNEL_FHANDLE=y CONFIG_KERNEL_FANOTIFY=y # CONFIG_KERNEL_BLK_DEV_BSG is not set CONFIG_KERNEL_MAGIC_SYSRQ=y # CONFIG_KERNEL_DEBUG_PINCTRL is not set # CONFIG_KERNEL_DEBUG_GPIO is not set CONFIG_KERNEL_COREDUMP=y CONFIG_KERNEL_ELF_CORE=y # CONFIG_KERNEL_PROVE_LOCKING is not set # CONFIG_KERNEL_LOCKUP_DETECTOR is not set # CONFIG_KERNEL_DETECT_HUNG_TASK is not set # CONFIG_KERNEL_WQ_WATCHDOG is not set # CONFIG_KERNEL_DEBUG_ATOMIC_SLEEP is not set # CONFIG_KERNEL_DEBUG_VM is not set CONFIG_KERNEL_PRINTK_TIME=y # CONFIG_KERNEL_SLABINFO is not set # CONFIG_KERNEL_PROC_PAGE_MONITOR is not set # CONFIG_KERNEL_KEXEC is not set # CONFIG_USE_RFKILL is not set # CONFIG_USE_SPARSE is not set # CONFIG_KERNEL_DEVTMPFS is not set # CONFIG_KERNEL_KEYS is not set CONFIG_KERNEL_CGROUPS=y # CONFIG_KERNEL_CGROUP_DEBUG is not set CONFIG_KERNEL_FREEZER=y CONFIG_KERNEL_CGROUP_FREEZER=y CONFIG_KERNEL_CGROUP_DEVICE=y CONFIG_KERNEL_CGROUP_PIDS=y CONFIG_KERNEL_CPUSETS=y # CONFIG_KERNEL_PROC_PID_CPUSET is not set CONFIG_KERNEL_CGROUP_CPUACCT=y CONFIG_KERNEL_RESOURCE_COUNTERS=y CONFIG_KERNEL_MM_OWNER=y CONFIG_KERNEL_MEMCG=y # CONFIG_KERNEL_MEMCG_SWAP is not set CONFIG_KERNEL_MEMCG_KMEM=y # CONFIG_KERNEL_CGROUP_PERF is not set CONFIG_KERNEL_CGROUP_SCHED=y CONFIG_KERNEL_FAIR_GROUP_SCHED=y # CONFIG_KERNEL_CFS_BANDWIDTH is not set CONFIG_KERNEL_RT_GROUP_SCHED=y CONFIG_KERNEL_BLK_CGROUP=y # CONFIG_KERNEL_CFQ_GROUP_IOSCHED is not set # CONFIG_KERNEL_BLK_DEV_THROTTLING is not set # CONFIG_KERNEL_DEBUG_BLK_CGROUP is not set CONFIG_KERNEL_NET_CLS_CGROUP=y CONFIG_KERNEL_CGROUP_NET_PRIO=y CONFIG_KERNEL_NAMESPACES=y CONFIG_KERNEL_UTS_NS=y CONFIG_KERNEL_IPC_NS=y CONFIG_KERNEL_USER_NS=y CONFIG_KERNEL_PID_NS=y CONFIG_KERNEL_NET_NS=y CONFIG_KERNEL_DEVPTS_MULTIPLE_INSTANCES=y CONFIG_KERNEL_POSIX_MQUEUE=y CONFIG_KERNEL_SECCOMP_FILTER=y CONFIG_KERNEL_SECCOMP=y CONFIG_KERNEL_IP_MROUTE=y CONFIG_KERNEL_IPV6=y CONFIG_KERNEL_IPV6_MULTIPLE_TABLES=y CONFIG_KERNEL_IPV6_SUBTREES=y CONFIG_KERNEL_IPV6_MROUTE=y # CONFIG_KERNEL_IPV6_PIMSM_V2 is not set # CONFIG_KERNEL_IP_PNP is not set # # Filesystem ACL and attr support options # # CONFIG_USE_FS_ACL_ATTR is not set # CONFIG_KERNEL_FS_POSIX_ACL is not set # CONFIG_KERNEL_BTRFS_FS_POSIX_ACL is not set # CONFIG_KERNEL_EXT4_FS_POSIX_ACL is not set # CONFIG_KERNEL_F2FS_FS_POSIX_ACL is not set # CONFIG_KERNEL_JFFS2_FS_POSIX_ACL is not set # CONFIG_KERNEL_TMPFS_POSIX_ACL is not set # CONFIG_KERNEL_CIFS_ACL is not set # CONFIG_KERNEL_HFS_FS_POSIX_ACL is not set # CONFIG_KERNEL_HFSPLUS_FS_POSIX_ACL is not set # CONFIG_KERNEL_NFS_ACL_SUPPORT is not set # CONFIG_KERNEL_NFS_V3_ACL_SUPPORT is not set # CONFIG_KERNEL_NFSD_V2_ACL_SUPPORT is not set # CONFIG_KERNEL_NFSD_V3_ACL_SUPPORT is not set # CONFIG_KERNEL_REISER_FS_POSIX_ACL is not set # CONFIG_KERNEL_XFS_POSIX_ACL is not set # CONFIG_KERNEL_JFS_POSIX_ACL is not set # end of Filesystem ACL and attr support options # CONFIG_KERNEL_DEVMEM is not set # CONFIG_KERNEL_DEVKMEM is not set CONFIG_KERNEL_SQUASHFS_FRAGMENT_CACHE_SIZE=3 CONFIG_KERNEL_CC_OPTIMIZE_FOR_PERFORMANCE=y # CONFIG_KERNEL_CC_OPTIMIZE_FOR_SIZE is not set # end of Kernel build options # # Package build options # # CONFIG_DEBUG is not set CONFIG_IPV6=y # # Stripping options # # CONFIG_NO_STRIP is not set # CONFIG_USE_STRIP is not set CONFIG_USE_SSTRIP=y # CONFIG_STRIP_KERNEL_EXPORTS is not set # CONFIG_USE_MKLIBS is not set CONFIG_USE_UCLIBCXX=y # CONFIG_USE_LIBCXX is not set # CONFIG_USE_LIBSTDCXX is not set # # Hardening build options # CONFIG_PKG_CHECK_FORMAT_SECURITY=y # CONFIG_PKG_ASLR_PIE_NONE is not set CONFIG_PKG_ASLR_PIE_REGULAR=y # CONFIG_PKG_ASLR_PIE_ALL is not set # CONFIG_PKG_CC_STACKPROTECTOR_NONE is not set CONFIG_PKG_CC_STACKPROTECTOR_REGULAR=y # CONFIG_KERNEL_CC_STACKPROTECTOR_NONE is not set CONFIG_KERNEL_CC_STACKPROTECTOR_REGULAR=y # CONFIG_KERNEL_CC_STACKPROTECTOR_STRONG is not set CONFIG_KERNEL_STACKPROTECTOR=y # CONFIG_KERNEL_STACKPROTECTOR_STRONG is not set # CONFIG_PKG_FORTIFY_SOURCE_NONE is not set CONFIG_PKG_FORTIFY_SOURCE_1=y # CONFIG_PKG_FORTIFY_SOURCE_2 is not set # CONFIG_PKG_RELRO_NONE is not set # CONFIG_PKG_RELRO_PARTIAL is not set CONFIG_PKG_RELRO_FULL=y # end of Global build settings # CONFIG_DEVEL is not set # CONFIG_BROKEN is not set CONFIG_BINARY_FOLDER="" CONFIG_DOWNLOAD_FOLDER="" CONFIG_LOCALMIRROR="" CONFIG_AUTOREBUILD=y # CONFIG_AUTOREMOVE is not set CONFIG_BUILD_SUFFIX="" CONFIG_TARGET_ROOTFS_DIR="" # CONFIG_CCACHE is not set CONFIG_EXTERNAL_KERNEL_TREE="" CONFIG_KERNEL_GIT_CLONE_URI="" CONFIG_BUILD_LOG_DIR="" CONFIG_EXTRA_OPTIMIZATION="-fno-caller-saves -fno-plt" CONFIG_TARGET_OPTIMIZATION="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc" CONFIG_SOFT_FLOAT=y CONFIG_USE_MIPS16=y # CONFIG_EXTRA_TARGET_ARCH is not set CONFIG_EXTRA_BINUTILS_CONFIG_OPTIONS="" CONFIG_EXTRA_GCC_CONFIG_OPTIONS="" # CONFIG_GCC_DEFAULT_PIE is not set # CONFIG_GCC_DEFAULT_SSP is not set # CONFIG_SJLJ_EXCEPTIONS is not set # CONFIG_INSTALL_GFORTRAN is not set CONFIG_GDB=y CONFIG_USE_MUSL=y CONFIG_SSP_SUPPORT=y CONFIG_BINUTILS_VERSION_2_31_1=y CONFIG_BINUTILS_VERSION="2.31.1" CONFIG_GCC_VERSION="8.4.0" # CONFIG_GCC_USE_IREMAP is not set CONFIG_LIBC="musl" CONFIG_TARGET_SUFFIX="musl" # CONFIG_IB is not set # CONFIG_SDK is not set # CONFIG_MAKE_TOOLCHAIN is not set # CONFIG_IMAGEOPT is not set # CONFIG_PREINITOPT is not set CONFIG_TARGET_PREINIT_SUPPRESS_STDERR=y # CONFIG_TARGET_PREINIT_DISABLE_FAILSAFE is not set CONFIG_TARGET_PREINIT_TIMEOUT=2 # CONFIG_TARGET_PREINIT_SHOW_NETMSG is not set # CONFIG_TARGET_PREINIT_SUPPRESS_FAILSAFE_NETMSG is not set CONFIG_TARGET_PREINIT_IFNAME="" CONFIG_TARGET_PREINIT_IP="192.168.2.1" CONFIG_TARGET_PREINIT_NETMASK="255.255.255.0" CONFIG_TARGET_PREINIT_BROADCAST="192.168.2.255" # CONFIG_INITOPT is not set CONFIG_TARGET_INIT_PATH="/usr/sbin:/usr/bin:/sbin:/bin" CONFIG_TARGET_INIT_ENV="" CONFIG_TARGET_INIT_CMD="/sbin/init" CONFIG_TARGET_INIT_SUPPRESS_STDERR=y # CONFIG_VERSIONOPT is not set CONFIG_PER_FEED_REPO=y CONFIG_FEED_packages=y CONFIG_FEED_luci=y CONFIG_FEED_routing=y CONFIG_FEED_telephony=y CONFIG_FEED_freifunk=y CONFIG_FEED_helloworld=y # # Base system # # CONFIG_PACKAGE_attendedsysupgrade-common is not set # CONFIG_PACKAGE_auc is not set CONFIG_PACKAGE_base-files=y CONFIG_PACKAGE_block-mount=y # CONFIG_PACKAGE_blockd is not set # CONFIG_PACKAGE_bridge is not set CONFIG_PACKAGE_busybox=y # CONFIG_BUSYBOX_CUSTOM is not set CONFIG_BUSYBOX_DEFAULT_HAVE_DOT_CONFIG=y # CONFIG_BUSYBOX_DEFAULT_DESKTOP is not set # CONFIG_BUSYBOX_DEFAULT_EXTRA_COMPAT is not set # CONFIG_BUSYBOX_DEFAULT_FEDORA_COMPAT is not set CONFIG_BUSYBOX_DEFAULT_INCLUDE_SUSv2=y CONFIG_BUSYBOX_DEFAULT_LONG_OPTS=y CONFIG_BUSYBOX_DEFAULT_SHOW_USAGE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VERBOSE_USAGE=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_COMPRESS_USAGE is not set CONFIG_BUSYBOX_DEFAULT_LFS=y # CONFIG_BUSYBOX_DEFAULT_PAM is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_DEVPTS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_UTMP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WTMP is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_PIDFILE=y CONFIG_BUSYBOX_DEFAULT_PID_FILE_PATH="/var/run" # CONFIG_BUSYBOX_DEFAULT_BUSYBOX is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SHOW_SCRIPT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSTALLER is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL_NO_USR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SUID is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SUID_CONFIG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SUID_CONFIG_QUIET is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_PREFER_APPLETS=y CONFIG_BUSYBOX_DEFAULT_BUSYBOX_EXEC_PATH="/proc/self/exe" # CONFIG_BUSYBOX_DEFAULT_SELINUX is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CLEAN_UP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOG_INFO is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOG=y CONFIG_BUSYBOX_DEFAULT_PLATFORM_LINUX=y # CONFIG_BUSYBOX_DEFAULT_STATIC is not set # CONFIG_BUSYBOX_DEFAULT_PIE is not set # CONFIG_BUSYBOX_DEFAULT_NOMMU is not set # CONFIG_BUSYBOX_DEFAULT_BUILD_LIBBUSYBOX is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LIBBUSYBOX_STATIC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INDIVIDUAL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SHARED_BUSYBOX is not set CONFIG_BUSYBOX_DEFAULT_CROSS_COMPILER_PREFIX="" CONFIG_BUSYBOX_DEFAULT_SYSROOT="" CONFIG_BUSYBOX_DEFAULT_EXTRA_CFLAGS="" CONFIG_BUSYBOX_DEFAULT_EXTRA_LDFLAGS="" CONFIG_BUSYBOX_DEFAULT_EXTRA_LDLIBS="" # CONFIG_BUSYBOX_DEFAULT_USE_PORTABLE_CODE is not set # CONFIG_BUSYBOX_DEFAULT_STACK_OPTIMIZATION_386 is not set CONFIG_BUSYBOX_DEFAULT_INSTALL_APPLET_SYMLINKS=y # CONFIG_BUSYBOX_DEFAULT_INSTALL_APPLET_HARDLINKS is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL_APPLET_SCRIPT_WRAPPERS is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL_APPLET_DONT is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL_SH_APPLET_SYMLINK is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL_SH_APPLET_HARDLINK is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL_SH_APPLET_SCRIPT_WRAPPER is not set CONFIG_BUSYBOX_DEFAULT_PREFIX="./_install" # CONFIG_BUSYBOX_DEFAULT_DEBUG is not set # CONFIG_BUSYBOX_DEFAULT_DEBUG_PESSIMIZE is not set # CONFIG_BUSYBOX_DEFAULT_DEBUG_SANITIZE is not set # CONFIG_BUSYBOX_DEFAULT_UNIT_TEST is not set # CONFIG_BUSYBOX_DEFAULT_WERROR is not set CONFIG_BUSYBOX_DEFAULT_NO_DEBUG_LIB=y # CONFIG_BUSYBOX_DEFAULT_DMALLOC is not set # CONFIG_BUSYBOX_DEFAULT_EFENCE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_USE_BSS_TAIL is not set # CONFIG_BUSYBOX_DEFAULT_FLOAT_DURATION is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_RTMINMAX is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_BUFFERS_USE_MALLOC is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_BUFFERS_GO_ON_STACK=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_BUFFERS_GO_IN_BSS is not set CONFIG_BUSYBOX_DEFAULT_PASSWORD_MINLEN=6 CONFIG_BUSYBOX_DEFAULT_MD5_SMALL=1 CONFIG_BUSYBOX_DEFAULT_SHA3_SMALL=1 CONFIG_BUSYBOX_DEFAULT_FEATURE_FAST_TOP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_ETC_NETWORKS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_ETC_SERVICES is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING=y CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_MAX_LEN=512 # CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_VI is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_HISTORY=256 # CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_SAVEHISTORY is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_SAVE_ON_EXIT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_REVERSE_SEARCH is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_TAB_COMPLETION=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_USERNAME_COMPLETION is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_FANCY_PROMPT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_WINCH is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_ASK_TERMINAL is not set # CONFIG_BUSYBOX_DEFAULT_LOCALE_SUPPORT is not set # CONFIG_BUSYBOX_DEFAULT_UNICODE_SUPPORT is not set # CONFIG_BUSYBOX_DEFAULT_UNICODE_USING_LOCALE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHECK_UNICODE_IN_ENV is not set CONFIG_BUSYBOX_DEFAULT_SUBST_WCHAR=0 CONFIG_BUSYBOX_DEFAULT_LAST_SUPPORTED_WCHAR=0 # CONFIG_BUSYBOX_DEFAULT_UNICODE_COMBINING_WCHARS is not set # CONFIG_BUSYBOX_DEFAULT_UNICODE_WIDE_WCHARS is not set # CONFIG_BUSYBOX_DEFAULT_UNICODE_BIDI_SUPPORT is not set # CONFIG_BUSYBOX_DEFAULT_UNICODE_NEUTRAL_TABLE is not set # CONFIG_BUSYBOX_DEFAULT_UNICODE_PRESERVE_BROKEN is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_NON_POSIX_CP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_VERBOSE_CP_MESSAGE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_USE_SENDFILE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_COPYBUF_KB=4 # CONFIG_BUSYBOX_DEFAULT_FEATURE_SKIP_ROOTFS is not set CONFIG_BUSYBOX_DEFAULT_MONOTONIC_SYSCALL=y CONFIG_BUSYBOX_DEFAULT_IOCTL_HEX2STR_ERROR=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_HWIB is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SEAMLESS_XZ is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SEAMLESS_LZMA is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SEAMLESS_BZ2 is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_SEAMLESS_GZ=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_SEAMLESS_Z is not set # CONFIG_BUSYBOX_DEFAULT_AR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_AR_LONG_FILENAMES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_AR_CREATE is not set # CONFIG_BUSYBOX_DEFAULT_UNCOMPRESS is not set CONFIG_BUSYBOX_DEFAULT_GUNZIP=y CONFIG_BUSYBOX_DEFAULT_ZCAT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_GUNZIP_LONG_OPTIONS is not set CONFIG_BUSYBOX_DEFAULT_BUNZIP2=y CONFIG_BUSYBOX_DEFAULT_BZCAT=y # CONFIG_BUSYBOX_DEFAULT_UNLZMA is not set # CONFIG_BUSYBOX_DEFAULT_LZCAT is not set # CONFIG_BUSYBOX_DEFAULT_LZMA is not set # CONFIG_BUSYBOX_DEFAULT_UNXZ is not set # CONFIG_BUSYBOX_DEFAULT_XZCAT is not set # CONFIG_BUSYBOX_DEFAULT_XZ is not set # CONFIG_BUSYBOX_DEFAULT_BZIP2 is not set CONFIG_BUSYBOX_DEFAULT_BZIP2_SMALL=0 CONFIG_BUSYBOX_DEFAULT_FEATURE_BZIP2_DECOMPRESS=y # CONFIG_BUSYBOX_DEFAULT_CPIO is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CPIO_O is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CPIO_P is not set # CONFIG_BUSYBOX_DEFAULT_DPKG is not set # CONFIG_BUSYBOX_DEFAULT_DPKG_DEB is not set CONFIG_BUSYBOX_DEFAULT_GZIP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_GZIP_LONG_OPTIONS is not set CONFIG_BUSYBOX_DEFAULT_GZIP_FAST=0 # CONFIG_BUSYBOX_DEFAULT_FEATURE_GZIP_LEVELS is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_GZIP_DECOMPRESS=y # CONFIG_BUSYBOX_DEFAULT_LZOP is not set # CONFIG_BUSYBOX_DEFAULT_UNLZOP is not set # CONFIG_BUSYBOX_DEFAULT_LZOPCAT is not set # CONFIG_BUSYBOX_DEFAULT_LZOP_COMPR_HIGH is not set # CONFIG_BUSYBOX_DEFAULT_RPM is not set # CONFIG_BUSYBOX_DEFAULT_RPM2CPIO is not set CONFIG_BUSYBOX_DEFAULT_TAR=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_LONG_OPTIONS is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_CREATE=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_AUTODETECT is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_FROM=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_OLDGNU_COMPATIBILITY is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_OLDSUN_COMPATIBILITY is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_GNU_EXTENSIONS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_TO_COMMAND is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_UNAME_GNAME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_NOPRESERVE_TIME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_SELINUX is not set # CONFIG_BUSYBOX_DEFAULT_UNZIP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UNZIP_CDF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UNZIP_BZIP2 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UNZIP_LZMA is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UNZIP_XZ is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LZMA_FAST is not set CONFIG_BUSYBOX_DEFAULT_BASENAME=y CONFIG_BUSYBOX_DEFAULT_CAT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_CATN is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CATV is not set CONFIG_BUSYBOX_DEFAULT_CHGRP=y CONFIG_BUSYBOX_DEFAULT_CHMOD=y CONFIG_BUSYBOX_DEFAULT_CHOWN=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHOWN_LONG_OPTIONS is not set CONFIG_BUSYBOX_DEFAULT_CHROOT=y # CONFIG_BUSYBOX_DEFAULT_CKSUM is not set # CONFIG_BUSYBOX_DEFAULT_COMM is not set CONFIG_BUSYBOX_DEFAULT_CP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_CP_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CP_REFLINK is not set CONFIG_BUSYBOX_DEFAULT_CUT=y CONFIG_BUSYBOX_DEFAULT_DATE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_DATE_ISOFMT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_DATE_NANO is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DATE_COMPAT is not set CONFIG_BUSYBOX_DEFAULT_DD=y CONFIG_BUSYBOX_DEFAULT_FEATURE_DD_SIGNAL_HANDLING=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_DD_THIRD_STATUS_LINE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_DD_IBS_OBS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_DD_STATUS is not set CONFIG_BUSYBOX_DEFAULT_DF=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_DF_FANCY is not set CONFIG_BUSYBOX_DEFAULT_DIRNAME=y # CONFIG_BUSYBOX_DEFAULT_DOS2UNIX is not set # CONFIG_BUSYBOX_DEFAULT_UNIX2DOS is not set CONFIG_BUSYBOX_DEFAULT_DU=y CONFIG_BUSYBOX_DEFAULT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K=y CONFIG_BUSYBOX_DEFAULT_ECHO=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FANCY_ECHO=y CONFIG_BUSYBOX_DEFAULT_ENV=y # CONFIG_BUSYBOX_DEFAULT_EXPAND is not set # CONFIG_BUSYBOX_DEFAULT_UNEXPAND is not set CONFIG_BUSYBOX_DEFAULT_EXPR=y CONFIG_BUSYBOX_DEFAULT_EXPR_MATH_SUPPORT_64=y # CONFIG_BUSYBOX_DEFAULT_FACTOR is not set CONFIG_BUSYBOX_DEFAULT_FALSE=y # CONFIG_BUSYBOX_DEFAULT_FOLD is not set CONFIG_BUSYBOX_DEFAULT_HEAD=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FANCY_HEAD=y # CONFIG_BUSYBOX_DEFAULT_HOSTID is not set CONFIG_BUSYBOX_DEFAULT_ID=y # CONFIG_BUSYBOX_DEFAULT_GROUPS is not set # CONFIG_BUSYBOX_DEFAULT_INSTALL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSTALL_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_LINK is not set CONFIG_BUSYBOX_DEFAULT_LN=y # CONFIG_BUSYBOX_DEFAULT_LOGNAME is not set CONFIG_BUSYBOX_DEFAULT_LS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_FILETYPES=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_FOLLOWLINKS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_RECURSIVE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_WIDTH=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_SORTFILES=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_TIMESTAMPS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_USERNAME=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_COLOR=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_COLOR_IS_DEFAULT=y CONFIG_BUSYBOX_DEFAULT_MD5SUM=y # CONFIG_BUSYBOX_DEFAULT_SHA1SUM is not set CONFIG_BUSYBOX_DEFAULT_SHA256SUM=y # CONFIG_BUSYBOX_DEFAULT_SHA512SUM is not set # CONFIG_BUSYBOX_DEFAULT_SHA3SUM is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_MD5_SHA1_SUM_CHECK=y CONFIG_BUSYBOX_DEFAULT_MKDIR=y CONFIG_BUSYBOX_DEFAULT_MKFIFO=y CONFIG_BUSYBOX_DEFAULT_MKNOD=y CONFIG_BUSYBOX_DEFAULT_MKTEMP=y CONFIG_BUSYBOX_DEFAULT_MV=y CONFIG_BUSYBOX_DEFAULT_NICE=y # CONFIG_BUSYBOX_DEFAULT_NL is not set # CONFIG_BUSYBOX_DEFAULT_NOHUP is not set # CONFIG_BUSYBOX_DEFAULT_NPROC is not set # CONFIG_BUSYBOX_DEFAULT_OD is not set # CONFIG_BUSYBOX_DEFAULT_PASTE is not set # CONFIG_BUSYBOX_DEFAULT_PRINTENV is not set CONFIG_BUSYBOX_DEFAULT_PRINTF=y CONFIG_BUSYBOX_DEFAULT_PWD=y CONFIG_BUSYBOX_DEFAULT_READLINK=y CONFIG_BUSYBOX_DEFAULT_FEATURE_READLINK_FOLLOW=y # CONFIG_BUSYBOX_DEFAULT_REALPATH is not set CONFIG_BUSYBOX_DEFAULT_RM=y CONFIG_BUSYBOX_DEFAULT_RMDIR=y CONFIG_BUSYBOX_DEFAULT_SEQ=y # CONFIG_BUSYBOX_DEFAULT_SHRED is not set # CONFIG_BUSYBOX_DEFAULT_SHUF is not set CONFIG_BUSYBOX_DEFAULT_SLEEP=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FANCY_SLEEP=y CONFIG_BUSYBOX_DEFAULT_SORT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_SORT_BIG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SORT_OPTIMIZE_MEMORY is not set # CONFIG_BUSYBOX_DEFAULT_SPLIT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SPLIT_FANCY is not set # CONFIG_BUSYBOX_DEFAULT_STAT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_STAT_FORMAT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_STAT_FILESYSTEM is not set # CONFIG_BUSYBOX_DEFAULT_STTY is not set # CONFIG_BUSYBOX_DEFAULT_SUM is not set CONFIG_BUSYBOX_DEFAULT_SYNC=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_SYNC_FANCY is not set CONFIG_BUSYBOX_DEFAULT_FSYNC=y # CONFIG_BUSYBOX_DEFAULT_TAC is not set CONFIG_BUSYBOX_DEFAULT_TAIL=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FANCY_TAIL=y CONFIG_BUSYBOX_DEFAULT_TEE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_TEE_USE_BLOCK_IO=y CONFIG_BUSYBOX_DEFAULT_TEST=y CONFIG_BUSYBOX_DEFAULT_TEST1=y CONFIG_BUSYBOX_DEFAULT_TEST2=y CONFIG_BUSYBOX_DEFAULT_FEATURE_TEST_64=y # CONFIG_BUSYBOX_DEFAULT_TIMEOUT is not set CONFIG_BUSYBOX_DEFAULT_TOUCH=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TOUCH_NODEREF is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_TOUCH_SUSV3=y CONFIG_BUSYBOX_DEFAULT_TR=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TR_CLASSES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TR_EQUIV is not set CONFIG_BUSYBOX_DEFAULT_TRUE=y # CONFIG_BUSYBOX_DEFAULT_TRUNCATE is not set # CONFIG_BUSYBOX_DEFAULT_TTY is not set CONFIG_BUSYBOX_DEFAULT_UNAME=y CONFIG_BUSYBOX_DEFAULT_UNAME_OSNAME="GNU/Linux" # CONFIG_BUSYBOX_DEFAULT_BB_ARCH is not set CONFIG_BUSYBOX_DEFAULT_UNIQ=y # CONFIG_BUSYBOX_DEFAULT_UNLINK is not set # CONFIG_BUSYBOX_DEFAULT_USLEEP is not set # CONFIG_BUSYBOX_DEFAULT_UUDECODE is not set # CONFIG_BUSYBOX_DEFAULT_BASE64 is not set # CONFIG_BUSYBOX_DEFAULT_UUENCODE is not set CONFIG_BUSYBOX_DEFAULT_WC=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_WC_LARGE is not set # CONFIG_BUSYBOX_DEFAULT_WHO is not set # CONFIG_BUSYBOX_DEFAULT_W is not set # CONFIG_BUSYBOX_DEFAULT_USERS is not set # CONFIG_BUSYBOX_DEFAULT_WHOAMI is not set CONFIG_BUSYBOX_DEFAULT_YES=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_VERBOSE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_PRESERVE_HARDLINKS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_HUMAN_READABLE=y # CONFIG_BUSYBOX_DEFAULT_CHVT is not set CONFIG_BUSYBOX_DEFAULT_CLEAR=y # CONFIG_BUSYBOX_DEFAULT_DEALLOCVT is not set # CONFIG_BUSYBOX_DEFAULT_DUMPKMAP is not set # CONFIG_BUSYBOX_DEFAULT_FGCONSOLE is not set # CONFIG_BUSYBOX_DEFAULT_KBD_MODE is not set # CONFIG_BUSYBOX_DEFAULT_LOADFONT is not set # CONFIG_BUSYBOX_DEFAULT_SETFONT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SETFONT_TEXTUAL_MAP is not set CONFIG_BUSYBOX_DEFAULT_DEFAULT_SETFONT_DIR="" # CONFIG_BUSYBOX_DEFAULT_FEATURE_LOADFONT_PSF2 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LOADFONT_RAW is not set # CONFIG_BUSYBOX_DEFAULT_LOADKMAP is not set # CONFIG_BUSYBOX_DEFAULT_OPENVT is not set CONFIG_BUSYBOX_DEFAULT_RESET=y # CONFIG_BUSYBOX_DEFAULT_RESIZE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_RESIZE_PRINT is not set # CONFIG_BUSYBOX_DEFAULT_SETCONSOLE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SETCONSOLE_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_SETKEYCODES is not set # CONFIG_BUSYBOX_DEFAULT_SETLOGCONS is not set # CONFIG_BUSYBOX_DEFAULT_SHOWKEY is not set # CONFIG_BUSYBOX_DEFAULT_PIPE_PROGRESS is not set # CONFIG_BUSYBOX_DEFAULT_RUN_PARTS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_RUN_PARTS_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_RUN_PARTS_FANCY is not set CONFIG_BUSYBOX_DEFAULT_START_STOP_DAEMON=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_START_STOP_DAEMON_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_START_STOP_DAEMON_FANCY is not set CONFIG_BUSYBOX_DEFAULT_WHICH=y # CONFIG_BUSYBOX_DEFAULT_MINIPS is not set # CONFIG_BUSYBOX_DEFAULT_NUKE is not set # CONFIG_BUSYBOX_DEFAULT_RESUME is not set # CONFIG_BUSYBOX_DEFAULT_RUN_INIT is not set CONFIG_BUSYBOX_DEFAULT_AWK=y CONFIG_BUSYBOX_DEFAULT_FEATURE_AWK_LIBM=y CONFIG_BUSYBOX_DEFAULT_FEATURE_AWK_GNU_EXTENSIONS=y CONFIG_BUSYBOX_DEFAULT_CMP=y # CONFIG_BUSYBOX_DEFAULT_DIFF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DIFF_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DIFF_DIR is not set # CONFIG_BUSYBOX_DEFAULT_ED is not set # CONFIG_BUSYBOX_DEFAULT_PATCH is not set CONFIG_BUSYBOX_DEFAULT_SED=y CONFIG_BUSYBOX_DEFAULT_VI=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_MAX_LEN=1024 # CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_8BIT is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_COLON=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_YANKMARK=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_SEARCH=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_REGEX_SEARCH is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_USE_SIGNALS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_DOT_CMD=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_READONLY=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_SETOPTS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_SET=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_WIN_RESIZE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_ASK_TERMINAL=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_UNDO is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_UNDO_QUEUE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_UNDO_QUEUE_MAX=0 CONFIG_BUSYBOX_DEFAULT_FEATURE_ALLOW_EXEC=y CONFIG_BUSYBOX_DEFAULT_FIND=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_PRINT0=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_MTIME=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_MMIN is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_PERM=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_TYPE=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_EXECUTABLE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_XDEV=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_MAXDEPTH=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_NEWER=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_INUM is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_EXEC=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_EXEC_PLUS is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_USER=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_GROUP=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_NOT=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_DEPTH=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_PAREN=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_SIZE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_PRUNE=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_QUIT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_DELETE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_PATH=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_REGEX=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_CONTEXT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_LINKS is not set CONFIG_BUSYBOX_DEFAULT_GREP=y CONFIG_BUSYBOX_DEFAULT_EGREP=y CONFIG_BUSYBOX_DEFAULT_FGREP=y CONFIG_BUSYBOX_DEFAULT_FEATURE_GREP_CONTEXT=y CONFIG_BUSYBOX_DEFAULT_XARGS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_CONFIRMATION=y CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_QUOTES=y CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_TERMOPT=y CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_ZERO_TERM=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_REPL_STR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_PARALLEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_ARGS_FILE is not set # CONFIG_BUSYBOX_DEFAULT_BOOTCHARTD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_BOOTCHARTD_BLOATED_HEADER is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_BOOTCHARTD_CONFIG_FILE is not set CONFIG_BUSYBOX_DEFAULT_HALT=y CONFIG_BUSYBOX_DEFAULT_POWEROFF=y CONFIG_BUSYBOX_DEFAULT_REBOOT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_WAIT_FOR_INIT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CALL_TELINIT is not set CONFIG_BUSYBOX_DEFAULT_TELINIT_PATH="" # CONFIG_BUSYBOX_DEFAULT_INIT is not set # CONFIG_BUSYBOX_DEFAULT_LINUXRC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_USE_INITTAB is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_KILL_REMOVED is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_KILL_DELAY=0 # CONFIG_BUSYBOX_DEFAULT_FEATURE_INIT_SCTTY is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INIT_SYSLOG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INIT_QUIET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INIT_COREDUMPS is not set CONFIG_BUSYBOX_DEFAULT_INIT_TERMINAL_TYPE="" # CONFIG_BUSYBOX_DEFAULT_FEATURE_INIT_MODIFY_CMDLINE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_SHADOWPASSWDS=y # CONFIG_BUSYBOX_DEFAULT_USE_BB_PWD_GRP is not set # CONFIG_BUSYBOX_DEFAULT_USE_BB_SHADOW is not set # CONFIG_BUSYBOX_DEFAULT_USE_BB_CRYPT is not set # CONFIG_BUSYBOX_DEFAULT_USE_BB_CRYPT_SHA is not set # CONFIG_BUSYBOX_DEFAULT_ADD_SHELL is not set # CONFIG_BUSYBOX_DEFAULT_REMOVE_SHELL is not set # CONFIG_BUSYBOX_DEFAULT_ADDGROUP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_ADDUSER_TO_GROUP is not set # CONFIG_BUSYBOX_DEFAULT_ADDUSER is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHECK_NAMES is not set CONFIG_BUSYBOX_DEFAULT_LAST_ID=0 CONFIG_BUSYBOX_DEFAULT_FIRST_SYSTEM_ID=0 CONFIG_BUSYBOX_DEFAULT_LAST_SYSTEM_ID=0 # CONFIG_BUSYBOX_DEFAULT_CHPASSWD is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_DEFAULT_PASSWD_ALGO="md5" # CONFIG_BUSYBOX_DEFAULT_CRYPTPW is not set # CONFIG_BUSYBOX_DEFAULT_MKPASSWD is not set # CONFIG_BUSYBOX_DEFAULT_DELUSER is not set # CONFIG_BUSYBOX_DEFAULT_DELGROUP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DEL_USER_FROM_GROUP is not set # CONFIG_BUSYBOX_DEFAULT_GETTY is not set CONFIG_BUSYBOX_DEFAULT_LOGIN=y CONFIG_BUSYBOX_DEFAULT_LOGIN_SESSION_AS_CHILD=y # CONFIG_BUSYBOX_DEFAULT_LOGIN_SCRIPTS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_NOLOGIN is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SECURETTY is not set CONFIG_BUSYBOX_DEFAULT_PASSWD=y CONFIG_BUSYBOX_DEFAULT_FEATURE_PASSWD_WEAK_CHECK=y # CONFIG_BUSYBOX_DEFAULT_SU is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SU_SYSLOG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SU_CHECKS_SHELLS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SU_BLANK_PW_NEEDS_SECURE_TTY is not set # CONFIG_BUSYBOX_DEFAULT_SULOGIN is not set # CONFIG_BUSYBOX_DEFAULT_VLOCK is not set # CONFIG_BUSYBOX_DEFAULT_CHATTR is not set # CONFIG_BUSYBOX_DEFAULT_FSCK is not set # CONFIG_BUSYBOX_DEFAULT_LSATTR is not set # CONFIG_BUSYBOX_DEFAULT_TUNE2FS is not set # CONFIG_BUSYBOX_DEFAULT_MODPROBE_SMALL is not set # CONFIG_BUSYBOX_DEFAULT_DEPMOD is not set # CONFIG_BUSYBOX_DEFAULT_INSMOD is not set # CONFIG_BUSYBOX_DEFAULT_LSMOD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LSMOD_PRETTY_2_6_OUTPUT is not set # CONFIG_BUSYBOX_DEFAULT_MODINFO is not set # CONFIG_BUSYBOX_DEFAULT_MODPROBE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MODPROBE_BLACKLIST is not set # CONFIG_BUSYBOX_DEFAULT_RMMOD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CMDLINE_MODULE_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_2_4_MODULES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_VERSION_CHECKING is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_LOADINKMEM is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_LOAD_MAP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_LOAD_MAP_FULL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHECK_TAINTED_MODULE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_TRY_MMAP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MODUTILS_ALIAS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MODUTILS_SYMBOLS is not set CONFIG_BUSYBOX_DEFAULT_DEFAULT_MODULES_DIR="" CONFIG_BUSYBOX_DEFAULT_DEFAULT_DEPMOD_FILE="" # CONFIG_BUSYBOX_DEFAULT_ACPID is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_ACPID_COMPAT is not set # CONFIG_BUSYBOX_DEFAULT_BLKDISCARD is not set # CONFIG_BUSYBOX_DEFAULT_BLKID is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_BLKID_TYPE is not set # CONFIG_BUSYBOX_DEFAULT_BLOCKDEV is not set # CONFIG_BUSYBOX_DEFAULT_CAL is not set # CONFIG_BUSYBOX_DEFAULT_CHRT is not set CONFIG_BUSYBOX_DEFAULT_DMESG=y CONFIG_BUSYBOX_DEFAULT_FEATURE_DMESG_PRETTY=y # CONFIG_BUSYBOX_DEFAULT_EJECT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_EJECT_SCSI is not set # CONFIG_BUSYBOX_DEFAULT_FALLOCATE is not set # CONFIG_BUSYBOX_DEFAULT_FATATTR is not set # CONFIG_BUSYBOX_DEFAULT_FBSET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FBSET_FANCY is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FBSET_READMODE is not set # CONFIG_BUSYBOX_DEFAULT_FDFORMAT is not set # CONFIG_BUSYBOX_DEFAULT_FDISK is not set # CONFIG_BUSYBOX_DEFAULT_FDISK_SUPPORT_LARGE_DISKS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FDISK_WRITABLE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_AIX_LABEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SGI_LABEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SUN_LABEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_OSF_LABEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_GPT_LABEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FDISK_ADVANCED is not set # CONFIG_BUSYBOX_DEFAULT_FINDFS is not set CONFIG_BUSYBOX_DEFAULT_FLOCK=y # CONFIG_BUSYBOX_DEFAULT_FDFLUSH is not set # CONFIG_BUSYBOX_DEFAULT_FREERAMDISK is not set # CONFIG_BUSYBOX_DEFAULT_FSCK_MINIX is not set # CONFIG_BUSYBOX_DEFAULT_FSFREEZE is not set # CONFIG_BUSYBOX_DEFAULT_FSTRIM is not set # CONFIG_BUSYBOX_DEFAULT_GETOPT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_GETOPT_LONG is not set CONFIG_BUSYBOX_DEFAULT_HEXDUMP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_HEXDUMP_REVERSE is not set # CONFIG_BUSYBOX_DEFAULT_HD is not set # CONFIG_BUSYBOX_DEFAULT_XXD is not set CONFIG_BUSYBOX_DEFAULT_HWCLOCK=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_HWCLOCK_ADJTIME_FHS is not set # CONFIG_BUSYBOX_DEFAULT_IONICE is not set # CONFIG_BUSYBOX_DEFAULT_IPCRM is not set # CONFIG_BUSYBOX_DEFAULT_IPCS is not set # CONFIG_BUSYBOX_DEFAULT_LAST is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LAST_FANCY is not set # CONFIG_BUSYBOX_DEFAULT_LOSETUP is not set # CONFIG_BUSYBOX_DEFAULT_LSPCI is not set # CONFIG_BUSYBOX_DEFAULT_LSUSB is not set # CONFIG_BUSYBOX_DEFAULT_MDEV is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_CONF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_RENAME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_RENAME_REGEXP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_EXEC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_LOAD_FIRMWARE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_DAEMON is not set # CONFIG_BUSYBOX_DEFAULT_MESG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MESG_ENABLE_ONLY_GROUP is not set # CONFIG_BUSYBOX_DEFAULT_MKE2FS is not set # CONFIG_BUSYBOX_DEFAULT_MKFS_EXT2 is not set # CONFIG_BUSYBOX_DEFAULT_MKFS_MINIX is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MINIX2 is not set # CONFIG_BUSYBOX_DEFAULT_MKFS_REISER is not set # CONFIG_BUSYBOX_DEFAULT_MKDOSFS is not set # CONFIG_BUSYBOX_DEFAULT_MKFS_VFAT is not set CONFIG_BUSYBOX_DEFAULT_MKSWAP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_MKSWAP_UUID is not set # CONFIG_BUSYBOX_DEFAULT_MORE is not set CONFIG_BUSYBOX_DEFAULT_MOUNT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_FAKE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_VERBOSE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_HELPERS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_LABEL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_NFS is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_CIFS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_FLAGS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_FSTAB=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_OTHERTAB is not set # CONFIG_BUSYBOX_DEFAULT_MOUNTPOINT is not set # CONFIG_BUSYBOX_DEFAULT_NOLOGIN is not set # CONFIG_BUSYBOX_DEFAULT_NOLOGIN_DEPENDENCIES is not set # CONFIG_BUSYBOX_DEFAULT_NSENTER is not set CONFIG_BUSYBOX_DEFAULT_PIVOT_ROOT=y # CONFIG_BUSYBOX_DEFAULT_RDATE is not set # CONFIG_BUSYBOX_DEFAULT_RDEV is not set # CONFIG_BUSYBOX_DEFAULT_READPROFILE is not set # CONFIG_BUSYBOX_DEFAULT_RENICE is not set # CONFIG_BUSYBOX_DEFAULT_REV is not set # CONFIG_BUSYBOX_DEFAULT_RTCWAKE is not set # CONFIG_BUSYBOX_DEFAULT_SCRIPT is not set # CONFIG_BUSYBOX_DEFAULT_SCRIPTREPLAY is not set # CONFIG_BUSYBOX_DEFAULT_SETARCH is not set # CONFIG_BUSYBOX_DEFAULT_LINUX32 is not set # CONFIG_BUSYBOX_DEFAULT_LINUX64 is not set # CONFIG_BUSYBOX_DEFAULT_SETPRIV is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SETPRIV_DUMP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SETPRIV_CAPABILITIES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SETPRIV_CAPABILITY_NAMES is not set # CONFIG_BUSYBOX_DEFAULT_SETSID is not set CONFIG_BUSYBOX_DEFAULT_SWAPON=y CONFIG_BUSYBOX_DEFAULT_FEATURE_SWAPON_DISCARD=y CONFIG_BUSYBOX_DEFAULT_FEATURE_SWAPON_PRI=y CONFIG_BUSYBOX_DEFAULT_SWAPOFF=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_SWAPONOFF_LABEL is not set CONFIG_BUSYBOX_DEFAULT_SWITCH_ROOT=y # CONFIG_BUSYBOX_DEFAULT_TASKSET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TASKSET_FANCY is not set # CONFIG_BUSYBOX_DEFAULT_UEVENT is not set CONFIG_BUSYBOX_DEFAULT_UMOUNT=y CONFIG_BUSYBOX_DEFAULT_FEATURE_UMOUNT_ALL=y # CONFIG_BUSYBOX_DEFAULT_UNSHARE is not set # CONFIG_BUSYBOX_DEFAULT_WALL is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_LOOP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_LOOP_CREATE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MTAB_SUPPORT is not set # CONFIG_BUSYBOX_DEFAULT_VOLUMEID is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_BCACHE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_BTRFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_CRAMFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_EXFAT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_EXT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_F2FS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_FAT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_HFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_ISO9660 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_JFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_LFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_LINUXRAID is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_LINUXSWAP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_LUKS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_MINIX is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_NILFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_NTFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_OCFS2 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_REISERFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_ROMFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_SQUASHFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_SYSV is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_UBIFS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_UDF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_XFS is not set # CONFIG_BUSYBOX_DEFAULT_ADJTIMEX is not set # CONFIG_BUSYBOX_DEFAULT_BBCONFIG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_COMPRESS_BBCONFIG is not set # CONFIG_BUSYBOX_DEFAULT_BC is not set # CONFIG_BUSYBOX_DEFAULT_DC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DC_BIG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DC_LIBM is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_BC_INTERACTIVE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_BC_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_BEEP is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_BEEP_FREQ=0 CONFIG_BUSYBOX_DEFAULT_FEATURE_BEEP_LENGTH_MS=0 # CONFIG_BUSYBOX_DEFAULT_CHAT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_NOFAIL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_TTY_HIFI is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_IMPLICIT_CR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_SWALLOW_OPTS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_SEND_ESCAPES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_VAR_ABORT_LEN is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_CLR_ABORT is not set # CONFIG_BUSYBOX_DEFAULT_CONSPY is not set CONFIG_BUSYBOX_DEFAULT_CROND=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_CROND_D is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CROND_CALL_SENDMAIL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_CROND_SPECIAL_TIMES is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_CROND_DIR="/etc" CONFIG_BUSYBOX_DEFAULT_CRONTAB=y # CONFIG_BUSYBOX_DEFAULT_DEVFSD is not set # CONFIG_BUSYBOX_DEFAULT_DEVFSD_MODLOAD is not set # CONFIG_BUSYBOX_DEFAULT_DEVFSD_FG_NP is not set # CONFIG_BUSYBOX_DEFAULT_DEVFSD_VERBOSE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_DEVFS is not set # CONFIG_BUSYBOX_DEFAULT_DEVMEM is not set # CONFIG_BUSYBOX_DEFAULT_FBSPLASH is not set # CONFIG_BUSYBOX_DEFAULT_FLASH_ERASEALL is not set # CONFIG_BUSYBOX_DEFAULT_FLASH_LOCK is not set # CONFIG_BUSYBOX_DEFAULT_FLASH_UNLOCK is not set # CONFIG_BUSYBOX_DEFAULT_FLASHCP is not set # CONFIG_BUSYBOX_DEFAULT_HDPARM is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_GET_IDENTITY is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_HDIO_SCAN_HWIF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_HDIO_DRIVE_RESET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_HDIO_TRISTATE_HWIF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_HDIO_GETSET_DMA is not set # CONFIG_BUSYBOX_DEFAULT_HEXEDIT is not set # CONFIG_BUSYBOX_DEFAULT_I2CGET is not set # CONFIG_BUSYBOX_DEFAULT_I2CSET is not set # CONFIG_BUSYBOX_DEFAULT_I2CDUMP is not set # CONFIG_BUSYBOX_DEFAULT_I2CDETECT is not set # CONFIG_BUSYBOX_DEFAULT_I2CTRANSFER is not set # CONFIG_BUSYBOX_DEFAULT_INOTIFYD is not set CONFIG_BUSYBOX_DEFAULT_LESS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_MAXLINES=9999999 # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_BRACKETS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_FLAGS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_TRUNCATE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_MARKS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_REGEXP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_WINCH is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_ASK_TERMINAL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_DASHCMD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_LINENUMS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_RAW is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_ENV is not set CONFIG_BUSYBOX_DEFAULT_LOCK=y # CONFIG_BUSYBOX_DEFAULT_LSSCSI is not set # CONFIG_BUSYBOX_DEFAULT_MAKEDEVS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MAKEDEVS_LEAF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_MAKEDEVS_TABLE is not set # CONFIG_BUSYBOX_DEFAULT_MAN is not set # CONFIG_BUSYBOX_DEFAULT_MICROCOM is not set # CONFIG_BUSYBOX_DEFAULT_MT is not set # CONFIG_BUSYBOX_DEFAULT_NANDWRITE is not set # CONFIG_BUSYBOX_DEFAULT_NANDDUMP is not set # CONFIG_BUSYBOX_DEFAULT_PARTPROBE is not set # CONFIG_BUSYBOX_DEFAULT_RAIDAUTORUN is not set # CONFIG_BUSYBOX_DEFAULT_READAHEAD is not set # CONFIG_BUSYBOX_DEFAULT_RFKILL is not set # CONFIG_BUSYBOX_DEFAULT_RUNLEVEL is not set # CONFIG_BUSYBOX_DEFAULT_RX is not set # CONFIG_BUSYBOX_DEFAULT_SETFATTR is not set # CONFIG_BUSYBOX_DEFAULT_SETSERIAL is not set CONFIG_BUSYBOX_DEFAULT_STRINGS=y CONFIG_BUSYBOX_DEFAULT_TIME=y # CONFIG_BUSYBOX_DEFAULT_TS is not set # CONFIG_BUSYBOX_DEFAULT_TTYSIZE is not set # CONFIG_BUSYBOX_DEFAULT_UBIATTACH is not set # CONFIG_BUSYBOX_DEFAULT_UBIDETACH is not set # CONFIG_BUSYBOX_DEFAULT_UBIMKVOL is not set # CONFIG_BUSYBOX_DEFAULT_UBIRMVOL is not set # CONFIG_BUSYBOX_DEFAULT_UBIRSVOL is not set # CONFIG_BUSYBOX_DEFAULT_UBIUPDATEVOL is not set # CONFIG_BUSYBOX_DEFAULT_UBIRENAME is not set # CONFIG_BUSYBOX_DEFAULT_VOLNAME is not set # CONFIG_BUSYBOX_DEFAULT_WATCHDOG is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_IPV6=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_UNIX_LOCAL is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_PREFER_IPV4_ADDRESS=y CONFIG_BUSYBOX_DEFAULT_VERBOSE_RESOLUTION_ERRORS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TLS_SHA1 is not set # CONFIG_BUSYBOX_DEFAULT_ARP is not set # CONFIG_BUSYBOX_DEFAULT_ARPING is not set CONFIG_BUSYBOX_DEFAULT_BRCTL=y CONFIG_BUSYBOX_DEFAULT_FEATURE_BRCTL_FANCY=y CONFIG_BUSYBOX_DEFAULT_FEATURE_BRCTL_SHOW=y # CONFIG_BUSYBOX_DEFAULT_DNSD is not set # CONFIG_BUSYBOX_DEFAULT_ETHER_WAKE is not set # CONFIG_BUSYBOX_DEFAULT_FTPD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FTPD_WRITE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FTPD_ACCEPT_BROKEN_LIST is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FTPD_AUTHENTICATION is not set # CONFIG_BUSYBOX_DEFAULT_FTPGET is not set # CONFIG_BUSYBOX_DEFAULT_FTPPUT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_FTPGETPUT_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_HOSTNAME is not set # CONFIG_BUSYBOX_DEFAULT_DNSDOMAINNAME is not set # CONFIG_BUSYBOX_DEFAULT_HTTPD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_RANGES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_SETUID is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_BASIC_AUTH is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_AUTH_MD5 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_CGI is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_ENCODE_URL_STR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_ERROR_PAGES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_PROXY is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_GZIP is not set CONFIG_BUSYBOX_DEFAULT_IFCONFIG=y CONFIG_BUSYBOX_DEFAULT_FEATURE_IFCONFIG_STATUS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFCONFIG_SLIP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_IFCONFIG_HW=y CONFIG_BUSYBOX_DEFAULT_FEATURE_IFCONFIG_BROADCAST_PLUS=y # CONFIG_BUSYBOX_DEFAULT_IFENSLAVE is not set # CONFIG_BUSYBOX_DEFAULT_IFPLUGD is not set # CONFIG_BUSYBOX_DEFAULT_IFUP is not set # CONFIG_BUSYBOX_DEFAULT_IFDOWN is not set CONFIG_BUSYBOX_DEFAULT_IFUPDOWN_IFSTATE_PATH="" # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFUPDOWN_IP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFUPDOWN_IPV4 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFUPDOWN_IPV6 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFUPDOWN_MAPPING is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IFUPDOWN_EXTERNAL_DHCP is not set # CONFIG_BUSYBOX_DEFAULT_INETD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_SUPPORT_BUILTIN_ECHO is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_SUPPORT_BUILTIN_TIME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_SUPPORT_BUILTIN_DAYTIME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_SUPPORT_BUILTIN_CHARGEN is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_RPC is not set CONFIG_BUSYBOX_DEFAULT_IP=y # CONFIG_BUSYBOX_DEFAULT_IPADDR is not set # CONFIG_BUSYBOX_DEFAULT_IPLINK is not set # CONFIG_BUSYBOX_DEFAULT_IPROUTE is not set # CONFIG_BUSYBOX_DEFAULT_IPTUNNEL is not set # CONFIG_BUSYBOX_DEFAULT_IPRULE is not set # CONFIG_BUSYBOX_DEFAULT_IPNEIGH is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_ADDRESS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_LINK=y CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_ROUTE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_ROUTE_DIR="/etc/iproute2" # CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_TUNNEL is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_RULE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_NEIGH=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_RARE_PROTOCOLS is not set # CONFIG_BUSYBOX_DEFAULT_IPCALC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IPCALC_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_IPCALC_FANCY is not set # CONFIG_BUSYBOX_DEFAULT_FAKEIDENTD is not set # CONFIG_BUSYBOX_DEFAULT_NAMEIF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_NAMEIF_EXTENDED is not set # CONFIG_BUSYBOX_DEFAULT_NBDCLIENT is not set CONFIG_BUSYBOX_DEFAULT_NC=y # CONFIG_BUSYBOX_DEFAULT_NETCAT is not set # CONFIG_BUSYBOX_DEFAULT_NC_SERVER is not set # CONFIG_BUSYBOX_DEFAULT_NC_EXTRA is not set # CONFIG_BUSYBOX_DEFAULT_NC_110_COMPAT is not set CONFIG_BUSYBOX_DEFAULT_NETMSG=y CONFIG_BUSYBOX_DEFAULT_NETSTAT=y CONFIG_BUSYBOX_DEFAULT_FEATURE_NETSTAT_WIDE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_NETSTAT_PRG=y # CONFIG_BUSYBOX_DEFAULT_NSLOOKUP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_NSLOOKUP_BIG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_NSLOOKUP_LONG_OPTIONS is not set CONFIG_BUSYBOX_DEFAULT_NSLOOKUP_OPENWRT=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_NSLOOKUP_OPENWRT_LONG_OPTIONS is not set CONFIG_BUSYBOX_DEFAULT_NTPD=y CONFIG_BUSYBOX_DEFAULT_FEATURE_NTPD_SERVER=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_NTPD_CONF is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_NTP_AUTH is not set CONFIG_BUSYBOX_DEFAULT_PING=y CONFIG_BUSYBOX_DEFAULT_PING6=y CONFIG_BUSYBOX_DEFAULT_FEATURE_FANCY_PING=y # CONFIG_BUSYBOX_DEFAULT_PSCAN is not set CONFIG_BUSYBOX_DEFAULT_ROUTE=y # CONFIG_BUSYBOX_DEFAULT_SLATTACH is not set # CONFIG_BUSYBOX_DEFAULT_SSL_CLIENT is not set # CONFIG_BUSYBOX_DEFAULT_TC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TC_INGRESS is not set # CONFIG_BUSYBOX_DEFAULT_TCPSVD is not set # CONFIG_BUSYBOX_DEFAULT_UDPSVD is not set # CONFIG_BUSYBOX_DEFAULT_TELNET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TELNET_TTYPE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TELNET_AUTOLOGIN is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TELNET_WIDTH is not set # CONFIG_BUSYBOX_DEFAULT_TELNETD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TELNETD_STANDALONE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TELNETD_INETD_WAIT is not set # CONFIG_BUSYBOX_DEFAULT_TFTP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TFTP_PROGRESS_BAR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TFTP_HPA_COMPAT is not set # CONFIG_BUSYBOX_DEFAULT_TFTPD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TFTP_GET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TFTP_PUT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TFTP_BLOCKSIZE is not set # CONFIG_BUSYBOX_DEFAULT_TFTP_DEBUG is not set # CONFIG_BUSYBOX_DEFAULT_TLS is not set CONFIG_BUSYBOX_DEFAULT_TRACEROUTE=y CONFIG_BUSYBOX_DEFAULT_TRACEROUTE6=y CONFIG_BUSYBOX_DEFAULT_FEATURE_TRACEROUTE_VERBOSE=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TRACEROUTE_USE_ICMP is not set # CONFIG_BUSYBOX_DEFAULT_TUNCTL is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TUNCTL_UG is not set # CONFIG_BUSYBOX_DEFAULT_VCONFIG is not set # CONFIG_BUSYBOX_DEFAULT_WGET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_LONG_OPTIONS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_STATUSBAR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_AUTHENTICATION is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_TIMEOUT is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_HTTPS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_OPENSSL is not set # CONFIG_BUSYBOX_DEFAULT_WHOIS is not set # CONFIG_BUSYBOX_DEFAULT_ZCIP is not set # CONFIG_BUSYBOX_DEFAULT_UDHCPD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPD_BASE_IP_ON_MAC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPD_WRITE_LEASES_EARLY is not set CONFIG_BUSYBOX_DEFAULT_DHCPD_LEASES_FILE="" # CONFIG_BUSYBOX_DEFAULT_DUMPLEASES is not set # CONFIG_BUSYBOX_DEFAULT_DHCPRELAY is not set CONFIG_BUSYBOX_DEFAULT_UDHCPC=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC_ARPING is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC_SANITIZEOPT is not set CONFIG_BUSYBOX_DEFAULT_UDHCPC_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script" # CONFIG_BUSYBOX_DEFAULT_UDHCPC6 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC6_RFC3646 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC6_RFC4704 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC6_RFC4833 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC6_RFC5970 is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCP_PORT is not set CONFIG_BUSYBOX_DEFAULT_UDHCP_DEBUG=0 CONFIG_BUSYBOX_DEFAULT_UDHCPC_SLACK_FOR_BUGGY_SERVERS=80 CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCP_RFC3397=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCP_8021Q is not set CONFIG_BUSYBOX_DEFAULT_IFUPDOWN_UDHCPC_CMD_OPTIONS="" # CONFIG_BUSYBOX_DEFAULT_LPD is not set # CONFIG_BUSYBOX_DEFAULT_LPR is not set # CONFIG_BUSYBOX_DEFAULT_LPQ is not set # CONFIG_BUSYBOX_DEFAULT_MAKEMIME is not set # CONFIG_BUSYBOX_DEFAULT_POPMAILDIR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_POPMAILDIR_DELIVERY is not set # CONFIG_BUSYBOX_DEFAULT_REFORMIME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_REFORMIME_COMPAT is not set # CONFIG_BUSYBOX_DEFAULT_SENDMAIL is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_MIME_CHARSET="" CONFIG_BUSYBOX_DEFAULT_FREE=y # CONFIG_BUSYBOX_DEFAULT_FUSER is not set # CONFIG_BUSYBOX_DEFAULT_IOSTAT is not set CONFIG_BUSYBOX_DEFAULT_KILL=y CONFIG_BUSYBOX_DEFAULT_KILLALL=y # CONFIG_BUSYBOX_DEFAULT_KILLALL5 is not set # CONFIG_BUSYBOX_DEFAULT_LSOF is not set # CONFIG_BUSYBOX_DEFAULT_MPSTAT is not set # CONFIG_BUSYBOX_DEFAULT_NMETER is not set CONFIG_BUSYBOX_DEFAULT_PGREP=y # CONFIG_BUSYBOX_DEFAULT_PKILL is not set CONFIG_BUSYBOX_DEFAULT_PIDOF=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_PIDOF_SINGLE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_PIDOF_OMIT is not set # CONFIG_BUSYBOX_DEFAULT_PMAP is not set # CONFIG_BUSYBOX_DEFAULT_POWERTOP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_POWERTOP_INTERACTIVE is not set CONFIG_BUSYBOX_DEFAULT_PS=y CONFIG_BUSYBOX_DEFAULT_FEATURE_PS_WIDE=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_PS_LONG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_PS_TIME is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_PS_UNUSUAL_SYSTEMS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_PS_ADDITIONAL_COLUMNS is not set # CONFIG_BUSYBOX_DEFAULT_PSTREE is not set # CONFIG_BUSYBOX_DEFAULT_PWDX is not set # CONFIG_BUSYBOX_DEFAULT_SMEMCAP is not set CONFIG_BUSYBOX_DEFAULT_BB_SYSCTL=y CONFIG_BUSYBOX_DEFAULT_TOP=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_INTERACTIVE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_SMP_CPU is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_DECIMALS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_SMP_PROCESS is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_TOPMEM is not set CONFIG_BUSYBOX_DEFAULT_UPTIME=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_UPTIME_UTMP_SUPPORT is not set # CONFIG_BUSYBOX_DEFAULT_WATCH is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SHOW_THREADS is not set # CONFIG_BUSYBOX_DEFAULT_CHPST is not set # CONFIG_BUSYBOX_DEFAULT_SETUIDGID is not set # CONFIG_BUSYBOX_DEFAULT_ENVUIDGID is not set # CONFIG_BUSYBOX_DEFAULT_ENVDIR is not set # CONFIG_BUSYBOX_DEFAULT_SOFTLIMIT is not set # CONFIG_BUSYBOX_DEFAULT_RUNSV is not set # CONFIG_BUSYBOX_DEFAULT_RUNSVDIR is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_RUNSVDIR_LOG is not set # CONFIG_BUSYBOX_DEFAULT_SV is not set CONFIG_BUSYBOX_DEFAULT_SV_DEFAULT_SERVICE_DIR="" # CONFIG_BUSYBOX_DEFAULT_SVC is not set # CONFIG_BUSYBOX_DEFAULT_SVOK is not set # CONFIG_BUSYBOX_DEFAULT_SVLOGD is not set # CONFIG_BUSYBOX_DEFAULT_CHCON is not set # CONFIG_BUSYBOX_DEFAULT_GETENFORCE is not set # CONFIG_BUSYBOX_DEFAULT_GETSEBOOL is not set # CONFIG_BUSYBOX_DEFAULT_LOAD_POLICY is not set # CONFIG_BUSYBOX_DEFAULT_MATCHPATHCON is not set # CONFIG_BUSYBOX_DEFAULT_RUNCON is not set # CONFIG_BUSYBOX_DEFAULT_SELINUXENABLED is not set # CONFIG_BUSYBOX_DEFAULT_SESTATUS is not set # CONFIG_BUSYBOX_DEFAULT_SETENFORCE is not set # CONFIG_BUSYBOX_DEFAULT_SETFILES is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SETFILES_CHECK_OPTION is not set # CONFIG_BUSYBOX_DEFAULT_RESTORECON is not set # CONFIG_BUSYBOX_DEFAULT_SETSEBOOL is not set CONFIG_BUSYBOX_DEFAULT_SH_IS_ASH=y # CONFIG_BUSYBOX_DEFAULT_SH_IS_HUSH is not set # CONFIG_BUSYBOX_DEFAULT_SH_IS_NONE is not set # CONFIG_BUSYBOX_DEFAULT_BASH_IS_ASH is not set # CONFIG_BUSYBOX_DEFAULT_BASH_IS_HUSH is not set CONFIG_BUSYBOX_DEFAULT_BASH_IS_NONE=y CONFIG_BUSYBOX_DEFAULT_ASH=y # CONFIG_BUSYBOX_DEFAULT_ASH_OPTIMIZE_FOR_SIZE is not set CONFIG_BUSYBOX_DEFAULT_ASH_INTERNAL_GLOB=y CONFIG_BUSYBOX_DEFAULT_ASH_BASH_COMPAT=y # CONFIG_BUSYBOX_DEFAULT_ASH_BASH_SOURCE_CURDIR is not set # CONFIG_BUSYBOX_DEFAULT_ASH_BASH_NOT_FOUND_HOOK is not set CONFIG_BUSYBOX_DEFAULT_ASH_JOB_CONTROL=y CONFIG_BUSYBOX_DEFAULT_ASH_ALIAS=y # CONFIG_BUSYBOX_DEFAULT_ASH_RANDOM_SUPPORT is not set CONFIG_BUSYBOX_DEFAULT_ASH_EXPAND_PRMT=y # CONFIG_BUSYBOX_DEFAULT_ASH_IDLE_TIMEOUT is not set # CONFIG_BUSYBOX_DEFAULT_ASH_MAIL is not set CONFIG_BUSYBOX_DEFAULT_ASH_ECHO=y CONFIG_BUSYBOX_DEFAULT_ASH_PRINTF=y CONFIG_BUSYBOX_DEFAULT_ASH_TEST=y # CONFIG_BUSYBOX_DEFAULT_ASH_HELP is not set CONFIG_BUSYBOX_DEFAULT_ASH_GETOPTS=y CONFIG_BUSYBOX_DEFAULT_ASH_CMDCMD=y # CONFIG_BUSYBOX_DEFAULT_CTTYHACK is not set # CONFIG_BUSYBOX_DEFAULT_HUSH is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_BASH_COMPAT is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_BRACE_EXPANSION is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_LINENO_VAR is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_BASH_SOURCE_CURDIR is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_INTERACTIVE is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_SAVEHISTORY is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_JOB is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_TICK is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_IF is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_LOOPS is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_CASE is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_FUNCTIONS is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_LOCAL is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_RANDOM_SUPPORT is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_MODE_X is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_ECHO is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_PRINTF is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_TEST is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_HELP is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_EXPORT is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_EXPORT_N is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_READONLY is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_KILL is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_WAIT is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_COMMAND is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_TRAP is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_TYPE is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_TIMES is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_READ is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_SET is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_UNSET is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_ULIMIT is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_UMASK is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_GETOPTS is not set # CONFIG_BUSYBOX_DEFAULT_HUSH_MEMLEAK is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_MATH=y CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_MATH_64=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_MATH_BASE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_EXTRA_QUIET is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_STANDALONE is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_NOFORK=y # CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_READ_FRAC is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_HISTFILESIZE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_EMBEDDED_SCRIPTS is not set # CONFIG_BUSYBOX_DEFAULT_KLOGD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_KLOGD_KLOGCTL is not set CONFIG_BUSYBOX_DEFAULT_LOGGER=y # CONFIG_BUSYBOX_DEFAULT_LOGREAD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_LOGREAD_REDUCED_LOCKING is not set # CONFIG_BUSYBOX_DEFAULT_SYSLOGD is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_ROTATE_LOGFILE is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_REMOTE_LOG is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOGD_DUP is not set # CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOGD_CFG is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOGD_READ_BUFFER_SIZE=0 # CONFIG_BUSYBOX_DEFAULT_FEATURE_IPC_SYSLOG is not set CONFIG_BUSYBOX_DEFAULT_FEATURE_IPC_SYSLOG_BUFFER_SIZE=0 # CONFIG_BUSYBOX_DEFAULT_FEATURE_KMSG_SYSLOG is not set # CONFIG_PACKAGE_ca-bundle is not set CONFIG_PACKAGE_ca-certificates=y # CONFIG_PACKAGE_dnsmasq is not set # CONFIG_PACKAGE_dnsmasq-dhcpv6 is not set CONFIG_PACKAGE_dnsmasq-full=y CONFIG_PACKAGE_dnsmasq_full_dhcp=y # CONFIG_PACKAGE_dnsmasq_full_dhcpv6 is not set # CONFIG_PACKAGE_dnsmasq_full_dnssec is not set # CONFIG_PACKAGE_dnsmasq_full_auth is not set CONFIG_PACKAGE_dnsmasq_full_ipset=y # CONFIG_PACKAGE_dnsmasq_full_conntrack is not set # CONFIG_PACKAGE_dnsmasq_full_noid is not set # CONFIG_PACKAGE_dnsmasq_full_broken_rtc is not set CONFIG_PACKAGE_dnsmasq_full_tftp=y CONFIG_PACKAGE_dropbear=y # # Configuration # CONFIG_DROPBEAR_CURVE25519=y # CONFIG_DROPBEAR_ECC is not set # CONFIG_DROPBEAR_ED25519 is not set CONFIG_DROPBEAR_CHACHA20POLY1305=y # CONFIG_DROPBEAR_ZLIB is not set CONFIG_DROPBEAR_DBCLIENT=y # end of Configuration # CONFIG_PACKAGE_ead is not set CONFIG_PACKAGE_firewall=y CONFIG_PACKAGE_fstools=y # CONFIG_FSTOOLS_OVL_MOUNT_FULL_ACCESS_TIME is not set # CONFIG_FSTOOLS_OVL_MOUNT_COMPRESS_ZLIB is not set CONFIG_PACKAGE_fwtool=y CONFIG_PACKAGE_getrandom=y CONFIG_PACKAGE_jsonfilter=y # CONFIG_PACKAGE_libatomic is not set CONFIG_PACKAGE_libc=y CONFIG_PACKAGE_libgcc=y # CONFIG_PACKAGE_libgomp is not set CONFIG_PACKAGE_libpthread=y CONFIG_PACKAGE_librt=y # CONFIG_PACKAGE_libstdcpp is not set CONFIG_PACKAGE_logd=y CONFIG_PACKAGE_mtd=y CONFIG_PACKAGE_netifd=y # CONFIG_PACKAGE_nft-qos is not set # CONFIG_PACKAGE_nvram is not set # CONFIG_PACKAGE_om-watchdog is not set CONFIG_PACKAGE_openwrt-keyring=y CONFIG_PACKAGE_opkg=y CONFIG_PACKAGE_procd=y # # Configuration # # CONFIG_PROCD_SHOW_BOOT is not set # CONFIG_PROCD_ZRAM_TMPFS is not set # end of Configuration # CONFIG_PACKAGE_procd-seccomp is not set # CONFIG_PACKAGE_procd-ujail is not set # CONFIG_PACKAGE_procd-ujail-console is not set # CONFIG_PACKAGE_qos-scripts is not set CONFIG_PACKAGE_resolveip=y CONFIG_PACKAGE_rpcd=y # CONFIG_PACKAGE_rpcd-mod-file is not set # CONFIG_PACKAGE_rpcd-mod-iwinfo is not set # CONFIG_PACKAGE_rpcd-mod-rpcsys is not set # CONFIG_PACKAGE_snapshot-tool is not set # CONFIG_PACKAGE_sqm-scripts is not set # CONFIG_PACKAGE_sqm-scripts-extra is not set CONFIG_PACKAGE_swconfig=y CONFIG_PACKAGE_ubox=y CONFIG_PACKAGE_ubus=y CONFIG_PACKAGE_ubusd=y # CONFIG_PACKAGE_ucert is not set # CONFIG_PACKAGE_ucert-full is not set CONFIG_PACKAGE_uci=y CONFIG_PACKAGE_urandom-seed=y CONFIG_PACKAGE_urngd=y CONFIG_PACKAGE_usign=y # CONFIG_PACKAGE_wireless-tools is not set # CONFIG_PACKAGE_zram-swap is not set # end of Base system # # Administration # # # OpenWISP # # CONFIG_PACKAGE_openwisp-config-cyassl is not set # CONFIG_PACKAGE_openwisp-config-mbedtls is not set # CONFIG_PACKAGE_openwisp-config-nossl is not set # CONFIG_PACKAGE_openwisp-config-openssl is not set # end of OpenWISP # # Zabbix # # CONFIG_PACKAGE_zabbix-agentd is not set # # SSL support # # CONFIG_ZABBIX_OPENSSL is not set # CONFIG_ZABBIX_GNUTLS is not set CONFIG_ZABBIX_NOSSL=y # CONFIG_PACKAGE_zabbix-extra-mac80211 is not set # CONFIG_PACKAGE_zabbix-extra-network is not set # CONFIG_PACKAGE_zabbix-extra-wifi is not set # CONFIG_PACKAGE_zabbix-get is not set # CONFIG_PACKAGE_zabbix-proxy is not set # CONFIG_PACKAGE_zabbix-sender is not set # CONFIG_PACKAGE_zabbix-server is not set # # Database Software # # CONFIG_ZABBIX_MYSQL is not set CONFIG_ZABBIX_POSTGRESQL=y # CONFIG_PACKAGE_zabbix-server-frontend is not set # end of Zabbix # CONFIG_PACKAGE_atop is not set # CONFIG_PACKAGE_backuppc is not set # CONFIG_PACKAGE_debootstrap is not set # CONFIG_PACKAGE_gkrellmd is not set CONFIG_PACKAGE_htop=y # CONFIG_PACKAGE_ipmitool is not set # CONFIG_PACKAGE_monit is not set # CONFIG_PACKAGE_monit-nossl is not set # CONFIG_PACKAGE_muninlite is not set # CONFIG_PACKAGE_netatop is not set # CONFIG_PACKAGE_netdata is not set # CONFIG_PACKAGE_nyx is not set # CONFIG_PACKAGE_schroot is not set # # Configuration # # CONFIG_SCHROOT_BTRFS is not set # CONFIG_SCHROOT_LOOPBACK is not set # CONFIG_SCHROOT_LVM is not set # CONFIG_SCHROOT_UUID is not set # end of Configuration # CONFIG_PACKAGE_sudo is not set # CONFIG_PACKAGE_syslog-ng is not set # end of Administration # # Boot Loaders # # end of Boot Loaders # # Development # # # Libraries # # CONFIG_PACKAGE_libncurses-dev is not set # CONFIG_PACKAGE_libxml2-dev is not set # CONFIG_PACKAGE_zlib-dev is not set # end of Libraries # CONFIG_PACKAGE_ar is not set # CONFIG_PACKAGE_autoconf is not set # CONFIG_PACKAGE_automake is not set # CONFIG_PACKAGE_binutils is not set # CONFIG_PACKAGE_diffutils is not set # CONFIG_PACKAGE_gcc is not set # CONFIG_PACKAGE_gdb is not set # CONFIG_PACKAGE_gdbserver is not set # CONFIG_PACKAGE_libtool-bin is not set # CONFIG_PACKAGE_lpc21isp is not set # CONFIG_PACKAGE_lttng-tools is not set # CONFIG_PACKAGE_m4 is not set # CONFIG_PACKAGE_make is not set # CONFIG_PACKAGE_meson is not set # CONFIG_PACKAGE_ninja is not set # CONFIG_PACKAGE_objdump is not set # CONFIG_PACKAGE_patch is not set # CONFIG_PACKAGE_pkg-config is not set # CONFIG_PACKAGE_pkgconf is not set # CONFIG_PACKAGE_trace-cmd is not set # CONFIG_PACKAGE_trace-cmd-extra is not set # CONFIG_PACKAGE_valgrind is not set # end of Development # # Extra packages # # CONFIG_PACKAGE_automount is not set # CONFIG_PACKAGE_autosamba is not set # CONFIG_PACKAGE_ipv6helper is not set # CONFIG_PACKAGE_jose is not set # CONFIG_PACKAGE_k3wifi is not set # CONFIG_PACKAGE_libjose is not set # CONFIG_PACKAGE_tang is not set # CONFIG_PACKAGE_wireguard-tools is not set # end of Extra packages # # Firmware # # # ath10k Board-Specific Overrides # # end of ath10k Board-Specific Overrides # CONFIG_PACKAGE_aircard-pcmcia-firmware is not set # CONFIG_PACKAGE_amdgpu-firmware is not set # CONFIG_PACKAGE_ar3k-firmware is not set # CONFIG_PACKAGE_ath10k-board-qca4019 is not set CONFIG_PACKAGE_ath10k-board-qca9887=y # CONFIG_PACKAGE_ath10k-board-qca9888 is not set # CONFIG_PACKAGE_ath10k-board-qca988x is not set # CONFIG_PACKAGE_ath10k-board-qca9984 is not set # CONFIG_PACKAGE_ath10k-board-qca99x0 is not set # CONFIG_PACKAGE_ath10k-firmware-qca4019 is not set # CONFIG_PACKAGE_ath10k-firmware-qca4019-ct is not set # CONFIG_PACKAGE_ath10k-firmware-qca4019-ct-full-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca4019-ct-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca6174 is not set CONFIG_PACKAGE_ath10k-firmware-qca9887=y CONFIG_PACKAGE_ath10k-firmware-qca9887-ct=y # CONFIG_PACKAGE_ath10k-firmware-qca9887-ct-full-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca9888 is not set # CONFIG_PACKAGE_ath10k-firmware-qca9888-ct is not set # CONFIG_PACKAGE_ath10k-firmware-qca9888-ct-full-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca9888-ct-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca988x is not set # CONFIG_PACKAGE_ath10k-firmware-qca988x-ct is not set # CONFIG_PACKAGE_ath10k-firmware-qca988x-ct-full-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca9984 is not set # CONFIG_PACKAGE_ath10k-firmware-qca9984-ct is not set # CONFIG_PACKAGE_ath10k-firmware-qca9984-ct-full-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca9984-ct-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca99x0 is not set # CONFIG_PACKAGE_ath10k-firmware-qca99x0-ct is not set # CONFIG_PACKAGE_ath10k-firmware-qca99x0-ct-full-htt is not set # CONFIG_PACKAGE_ath10k-firmware-qca99x0-ct-htt is not set # CONFIG_PACKAGE_ath6k-firmware is not set # CONFIG_PACKAGE_ath9k-htc-firmware is not set # CONFIG_PACKAGE_b43legacy-firmware is not set # CONFIG_PACKAGE_bnx2-firmware is not set # CONFIG_PACKAGE_bnx2x-firmware is not set # CONFIG_PACKAGE_brcmfmac-firmware-4329-sdio is not set # CONFIG_PACKAGE_brcmfmac-firmware-43362-sdio is not set # CONFIG_PACKAGE_brcmfmac-firmware-43430-sdio is not set # CONFIG_PACKAGE_brcmfmac-firmware-43430-sdio-rpi-3b is not set # CONFIG_PACKAGE_brcmfmac-firmware-43430-sdio-rpi-zero-w is not set # CONFIG_PACKAGE_brcmfmac-firmware-43430a0-sdio is not set # CONFIG_PACKAGE_brcmfmac-firmware-43455-sdio is not set # CONFIG_PACKAGE_brcmfmac-firmware-43455-sdio-rpi-3b-plus is not set # CONFIG_PACKAGE_brcmfmac-firmware-43455-sdio-rpi-4b is not set # CONFIG_PACKAGE_brcmfmac-firmware-43602a1-pcie is not set # CONFIG_PACKAGE_brcmfmac-firmware-4366b1-pcie is not set # CONFIG_PACKAGE_brcmfmac-firmware-4366c0-pcie is not set # CONFIG_PACKAGE_brcmfmac-firmware-usb is not set # CONFIG_PACKAGE_brcmsmac-firmware is not set # CONFIG_PACKAGE_carl9170-firmware is not set # CONFIG_PACKAGE_cypress-firmware-43012-sdio is not set # CONFIG_PACKAGE_cypress-firmware-43340-sdio is not set # CONFIG_PACKAGE_cypress-firmware-43362-sdio is not set # CONFIG_PACKAGE_cypress-firmware-4339-sdio is not set # CONFIG_PACKAGE_cypress-firmware-43430-sdio is not set # CONFIG_PACKAGE_cypress-firmware-43455-sdio is not set # CONFIG_PACKAGE_cypress-firmware-4354-sdio is not set # CONFIG_PACKAGE_cypress-firmware-4356-pcie is not set # CONFIG_PACKAGE_cypress-firmware-4356-sdio is not set # CONFIG_PACKAGE_cypress-firmware-43570-pcie is not set # CONFIG_PACKAGE_cypress-firmware-4359-pcie is not set # CONFIG_PACKAGE_cypress-firmware-4359-sdio is not set # CONFIG_PACKAGE_cypress-firmware-4373-sdio is not set # CONFIG_PACKAGE_cypress-firmware-4373-usb is not set # CONFIG_PACKAGE_cypress-firmware-54591-pcie is not set # CONFIG_PACKAGE_cypress-firmware-89459-pcie is not set # CONFIG_PACKAGE_e100-firmware is not set # CONFIG_PACKAGE_edgeport-firmware is not set # CONFIG_PACKAGE_eip197-mini-firmware is not set # CONFIG_PACKAGE_ibt-firmware is not set # CONFIG_PACKAGE_iwl3945-firmware is not set # CONFIG_PACKAGE_iwl4965-firmware is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl100 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl1000 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl105 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl135 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl2000 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl2030 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl3160 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl3168 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl5000 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl5150 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl6000g2 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl6000g2a is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl6000g2b is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl6050 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl7260 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl7265 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl7265d is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl8260c is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl8265 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl9000 is not set # CONFIG_PACKAGE_iwlwifi-firmware-iwl9260 is not set # CONFIG_PACKAGE_libertas-sdio-firmware is not set # CONFIG_PACKAGE_libertas-spi-firmware is not set # CONFIG_PACKAGE_libertas-usb-firmware is not set # CONFIG_PACKAGE_mt7601u-firmware is not set # CONFIG_PACKAGE_mt7622bt-firmware is not set # CONFIG_PACKAGE_mwifiex-pcie-firmware is not set # CONFIG_PACKAGE_mwifiex-sdio-firmware is not set # CONFIG_PACKAGE_mwl8k-firmware is not set # CONFIG_PACKAGE_p54-pci-firmware is not set # CONFIG_PACKAGE_p54-spi-firmware is not set # CONFIG_PACKAGE_p54-usb-firmware is not set # CONFIG_PACKAGE_prism54-firmware is not set # CONFIG_PACKAGE_r8169-firmware is not set # CONFIG_PACKAGE_radeon-firmware is not set # CONFIG_PACKAGE_rs9113-firmware is not set # CONFIG_PACKAGE_rt2800-pci-firmware is not set # CONFIG_PACKAGE_rt2800-usb-firmware is not set # CONFIG_PACKAGE_rt61-pci-firmware is not set # CONFIG_PACKAGE_rt73-usb-firmware is not set # CONFIG_PACKAGE_rtl8188eu-firmware is not set # CONFIG_PACKAGE_rtl8192ce-firmware is not set # CONFIG_PACKAGE_rtl8192cu-firmware is not set # CONFIG_PACKAGE_rtl8192de-firmware is not set # CONFIG_PACKAGE_rtl8192eu-firmware is not set # CONFIG_PACKAGE_rtl8192se-firmware is not set # CONFIG_PACKAGE_rtl8192su-firmware is not set # CONFIG_PACKAGE_rtl8723au-firmware is not set # CONFIG_PACKAGE_rtl8723bs-firmware is not set # CONFIG_PACKAGE_rtl8723bu-firmware is not set # CONFIG_PACKAGE_rtl8821ae-firmware is not set # CONFIG_PACKAGE_rtl8822be-firmware is not set # CONFIG_PACKAGE_rtl8822ce-firmware is not set # CONFIG_PACKAGE_ti-3410-firmware is not set # CONFIG_PACKAGE_ti-5052-firmware is not set CONFIG_PACKAGE_wireless-regdb=y # CONFIG_PACKAGE_wl12xx-firmware is not set # CONFIG_PACKAGE_wl18xx-firmware is not set # end of Firmware # # Fonts # # # DejaVu # # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuMathTeXGyre is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSans is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSans-Bold is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSans-BoldOblique is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSans-ExtraLight is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSans-Oblique is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansCondensed is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansCondensed-Bold is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansCondensed-BoldOblique is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansCondensed-Oblique is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansMono is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansMono-Bold is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansMono-BoldOblique is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansMono-Oblique is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerif is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerif-Bold is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerif-BoldItalic is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerif-Italic is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerifCondensed is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerifCondensed-Bold is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerifCondensed-BoldItalic is not set # CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerifCondensed-Italic is not set # end of DejaVu # end of Fonts # # Kernel modules # # # Block Devices # # CONFIG_PACKAGE_kmod-aoe is not set # CONFIG_PACKAGE_kmod-ata-ahci is not set # CONFIG_PACKAGE_kmod-ata-artop is not set # CONFIG_PACKAGE_kmod-ata-core is not set # CONFIG_PACKAGE_kmod-ata-marvell-sata is not set # CONFIG_PACKAGE_kmod-ata-nvidia-sata is not set # CONFIG_PACKAGE_kmod-ata-pdc202xx-old is not set # CONFIG_PACKAGE_kmod-ata-piix is not set # CONFIG_PACKAGE_kmod-ata-sil is not set # CONFIG_PACKAGE_kmod-ata-sil24 is not set # CONFIG_PACKAGE_kmod-ata-via-sata is not set # CONFIG_PACKAGE_kmod-block2mtd is not set # CONFIG_PACKAGE_kmod-dax is not set # CONFIG_PACKAGE_kmod-dm is not set # CONFIG_PACKAGE_kmod-dm-raid is not set # CONFIG_PACKAGE_kmod-iosched-bfq is not set # CONFIG_PACKAGE_kmod-iscsi-initiator is not set # CONFIG_PACKAGE_kmod-loop is not set # CONFIG_PACKAGE_kmod-md-mod is not set # CONFIG_PACKAGE_kmod-nbd is not set # CONFIG_PACKAGE_kmod-scsi-cdrom is not set CONFIG_PACKAGE_kmod-scsi-core=y # CONFIG_PACKAGE_kmod-scsi-generic is not set # CONFIG_PACKAGE_kmod-scsi-tape is not set # end of Block Devices # # CAN Support # # CONFIG_PACKAGE_kmod-can is not set # end of CAN Support # # Cryptographic API modules # CONFIG_PACKAGE_kmod-crypto-aead=y CONFIG_PACKAGE_kmod-crypto-arc4=y CONFIG_PACKAGE_kmod-crypto-authenc=y # CONFIG_PACKAGE_kmod-crypto-cbc is not set # CONFIG_PACKAGE_kmod-crypto-ccm is not set # CONFIG_PACKAGE_kmod-crypto-cmac is not set CONFIG_PACKAGE_kmod-crypto-crc32c=y # CONFIG_PACKAGE_kmod-crypto-ctr is not set # CONFIG_PACKAGE_kmod-crypto-cts is not set # CONFIG_PACKAGE_kmod-crypto-deflate is not set # CONFIG_PACKAGE_kmod-crypto-des is not set CONFIG_PACKAGE_kmod-crypto-ecb=y # CONFIG_PACKAGE_kmod-crypto-ecdh is not set # CONFIG_PACKAGE_kmod-crypto-echainiv is not set # CONFIG_PACKAGE_kmod-crypto-fcrypt is not set # CONFIG_PACKAGE_kmod-crypto-gcm is not set # CONFIG_PACKAGE_kmod-crypto-gf128 is not set # CONFIG_PACKAGE_kmod-crypto-ghash is not set CONFIG_PACKAGE_kmod-crypto-hash=y # CONFIG_PACKAGE_kmod-crypto-hmac is not set # CONFIG_PACKAGE_kmod-crypto-hw-ccp is not set # CONFIG_PACKAGE_kmod-crypto-hw-geode is not set # CONFIG_PACKAGE_kmod-crypto-hw-hifn-795x is not set # CONFIG_PACKAGE_kmod-crypto-hw-padlock is not set # CONFIG_PACKAGE_kmod-crypto-hw-talitos is not set CONFIG_PACKAGE_kmod-crypto-manager=y # CONFIG_PACKAGE_kmod-crypto-md4 is not set # CONFIG_PACKAGE_kmod-crypto-md5 is not set # CONFIG_PACKAGE_kmod-crypto-michael-mic is not set # CONFIG_PACKAGE_kmod-crypto-misc is not set CONFIG_PACKAGE_kmod-crypto-null=y # CONFIG_PACKAGE_kmod-crypto-pcbc is not set CONFIG_PACKAGE_kmod-crypto-pcompress=y # CONFIG_PACKAGE_kmod-crypto-rmd160 is not set # CONFIG_PACKAGE_kmod-crypto-rng is not set # CONFIG_PACKAGE_kmod-crypto-seqiv is not set CONFIG_PACKAGE_kmod-crypto-sha1=y # CONFIG_PACKAGE_kmod-crypto-sha256 is not set # CONFIG_PACKAGE_kmod-crypto-sha512 is not set # CONFIG_PACKAGE_kmod-crypto-test is not set CONFIG_PACKAGE_kmod-crypto-user=y # CONFIG_PACKAGE_kmod-crypto-wq is not set # CONFIG_PACKAGE_kmod-crypto-xcbc is not set # CONFIG_PACKAGE_kmod-crypto-xts is not set CONFIG_PACKAGE_kmod-cryptodev=y # end of Cryptographic API modules # # Filesystems # # CONFIG_PACKAGE_kmod-fs-afs is not set # CONFIG_PACKAGE_kmod-fs-antfs is not set # CONFIG_PACKAGE_kmod-fs-autofs4 is not set # CONFIG_PACKAGE_kmod-fs-btrfs is not set # CONFIG_PACKAGE_kmod-fs-cifs is not set # CONFIG_PACKAGE_kmod-fs-configfs is not set # CONFIG_PACKAGE_kmod-fs-cramfs is not set CONFIG_PACKAGE_kmod-fs-exfat=y # CONFIG_PACKAGE_kmod-fs-exfat0 is not set # CONFIG_PACKAGE_kmod-fs-exportfs is not set CONFIG_PACKAGE_kmod-fs-ext4=y # CONFIG_PACKAGE_kmod-fs-f2fs is not set # CONFIG_PACKAGE_kmod-fs-fscache is not set # CONFIG_PACKAGE_kmod-fs-hfs is not set # CONFIG_PACKAGE_kmod-fs-hfsplus is not set # CONFIG_PACKAGE_kmod-fs-isofs is not set # CONFIG_PACKAGE_kmod-fs-jfs is not set # CONFIG_PACKAGE_kmod-fs-ksmbd is not set # CONFIG_PACKAGE_kmod-fs-minix is not set # CONFIG_PACKAGE_kmod-fs-msdos is not set # CONFIG_PACKAGE_kmod-fs-nfs is not set # CONFIG_PACKAGE_kmod-fs-nfs-common is not set # CONFIG_PACKAGE_kmod-fs-nfs-common-rpcsec is not set # CONFIG_PACKAGE_kmod-fs-nfs-v3 is not set # CONFIG_PACKAGE_kmod-fs-nfs-v4 is not set # CONFIG_PACKAGE_kmod-fs-nfsd is not set CONFIG_PACKAGE_kmod-fs-ntfs=y # CONFIG_PACKAGE_kmod-fs-reiserfs is not set # CONFIG_PACKAGE_kmod-fs-squashfs is not set # CONFIG_PACKAGE_kmod-fs-udf is not set CONFIG_PACKAGE_kmod-fs-vfat=y # CONFIG_PACKAGE_kmod-fs-xfs is not set # CONFIG_PACKAGE_kmod-fuse is not set # end of Filesystems # # FireWire support # # CONFIG_PACKAGE_kmod-firewire is not set # end of FireWire support # # Hardware Monitoring Support # # CONFIG_PACKAGE_kmod-hwmon-ad7418 is not set # CONFIG_PACKAGE_kmod-hwmon-adcxx is not set # CONFIG_PACKAGE_kmod-hwmon-ads1015 is not set # CONFIG_PACKAGE_kmod-hwmon-adt7410 is not set # CONFIG_PACKAGE_kmod-hwmon-adt7475 is not set CONFIG_PACKAGE_kmod-hwmon-core=y # CONFIG_PACKAGE_kmod-hwmon-dme1737 is not set # CONFIG_PACKAGE_kmod-hwmon-drivetemp is not set # CONFIG_PACKAGE_kmod-hwmon-gpiofan is not set # CONFIG_PACKAGE_kmod-hwmon-ina209 is not set # CONFIG_PACKAGE_kmod-hwmon-ina2xx is not set # CONFIG_PACKAGE_kmod-hwmon-it87 is not set # CONFIG_PACKAGE_kmod-hwmon-lm63 is not set # CONFIG_PACKAGE_kmod-hwmon-lm75 is not set # CONFIG_PACKAGE_kmod-hwmon-lm77 is not set # CONFIG_PACKAGE_kmod-hwmon-lm85 is not set # CONFIG_PACKAGE_kmod-hwmon-lm90 is not set # CONFIG_PACKAGE_kmod-hwmon-lm92 is not set # CONFIG_PACKAGE_kmod-hwmon-lm95241 is not set # CONFIG_PACKAGE_kmod-hwmon-ltc4151 is not set # CONFIG_PACKAGE_kmod-hwmon-mcp3021 is not set # CONFIG_PACKAGE_kmod-hwmon-pwmfan is not set # CONFIG_PACKAGE_kmod-hwmon-sch5627 is not set # CONFIG_PACKAGE_kmod-hwmon-sht21 is not set # CONFIG_PACKAGE_kmod-hwmon-tmp102 is not set # CONFIG_PACKAGE_kmod-hwmon-tmp103 is not set # CONFIG_PACKAGE_kmod-hwmon-tmp421 is not set # CONFIG_PACKAGE_kmod-hwmon-vid is not set # CONFIG_PACKAGE_kmod-hwmon-w83793 is not set # CONFIG_PACKAGE_kmod-pmbus-core is not set # CONFIG_PACKAGE_kmod-pmbus-zl6100 is not set # end of Hardware Monitoring Support # # I2C support # # CONFIG_PACKAGE_kmod-i2c-algo-bit is not set # CONFIG_PACKAGE_kmod-i2c-algo-pca is not set # CONFIG_PACKAGE_kmod-i2c-algo-pcf is not set # CONFIG_PACKAGE_kmod-i2c-core is not set # CONFIG_PACKAGE_kmod-i2c-gpio is not set # CONFIG_PACKAGE_kmod-i2c-gpio-custom is not set # CONFIG_PACKAGE_kmod-i2c-mux is not set # CONFIG_PACKAGE_kmod-i2c-mux-gpio is not set # CONFIG_PACKAGE_kmod-i2c-mux-pca9541 is not set # CONFIG_PACKAGE_kmod-i2c-mux-pca954x is not set # CONFIG_PACKAGE_kmod-i2c-pxa is not set # CONFIG_PACKAGE_kmod-i2c-smbus is not set # CONFIG_PACKAGE_kmod-i2c-tiny-usb is not set # end of I2C support # # Industrial I/O Modules # # CONFIG_PACKAGE_kmod-iio-ad799x is not set # CONFIG_PACKAGE_kmod-iio-am2315 is not set # CONFIG_PACKAGE_kmod-iio-bh1750 is not set # CONFIG_PACKAGE_kmod-iio-bmp280 is not set # CONFIG_PACKAGE_kmod-iio-bmp280-i2c is not set # CONFIG_PACKAGE_kmod-iio-bmp280-spi is not set # CONFIG_PACKAGE_kmod-iio-ccs811 is not set # CONFIG_PACKAGE_kmod-iio-core is not set # CONFIG_PACKAGE_kmod-iio-fxos8700 is not set # CONFIG_PACKAGE_kmod-iio-fxos8700-i2c is not set # CONFIG_PACKAGE_kmod-iio-fxos8700-spi is not set # CONFIG_PACKAGE_kmod-iio-hmc5843 is not set # CONFIG_PACKAGE_kmod-iio-htu21 is not set # CONFIG_PACKAGE_kmod-iio-kfifo-buf is not set # CONFIG_PACKAGE_kmod-iio-lsm6dsx is not set # CONFIG_PACKAGE_kmod-iio-lsm6dsx-i2c is not set # CONFIG_PACKAGE_kmod-iio-lsm6dsx-spi is not set # CONFIG_PACKAGE_kmod-iio-si7020 is not set # CONFIG_PACKAGE_kmod-iio-st_accel is not set # CONFIG_PACKAGE_kmod-iio-st_accel-i2c is not set # CONFIG_PACKAGE_kmod-iio-st_accel-spi is not set # CONFIG_PACKAGE_kmod-iio-tsl4531 is not set # CONFIG_PACKAGE_kmod-industrialio-triggered-buffer is not set # end of Industrial I/O Modules # # Input modules # # CONFIG_PACKAGE_kmod-hid is not set # CONFIG_PACKAGE_kmod-hid-generic is not set # CONFIG_PACKAGE_kmod-input-core is not set # CONFIG_PACKAGE_kmod-input-evdev is not set # CONFIG_PACKAGE_kmod-input-gpio-encoder is not set # CONFIG_PACKAGE_kmod-input-gpio-keys is not set # CONFIG_PACKAGE_kmod-input-gpio-keys-polled is not set # CONFIG_PACKAGE_kmod-input-joydev is not set # CONFIG_PACKAGE_kmod-input-matrixkmap is not set # CONFIG_PACKAGE_kmod-input-polldev is not set # CONFIG_PACKAGE_kmod-input-touchscreen-ads7846 is not set # CONFIG_PACKAGE_kmod-input-uinput is not set # end of Input modules # # LED modules # # CONFIG_PACKAGE_kmod-leds-gpio is not set # CONFIG_PACKAGE_kmod-leds-nu801 is not set # CONFIG_PACKAGE_kmod-leds-pca963x is not set # CONFIG_PACKAGE_kmod-leds-rb750 is not set # CONFIG_PACKAGE_kmod-leds-wndr3700-usb is not set # CONFIG_PACKAGE_kmod-ledtrig-activity is not set # CONFIG_PACKAGE_kmod-ledtrig-default-on is not set # CONFIG_PACKAGE_kmod-ledtrig-gpio is not set # CONFIG_PACKAGE_kmod-ledtrig-heartbeat is not set # CONFIG_PACKAGE_kmod-ledtrig-netdev is not set # CONFIG_PACKAGE_kmod-ledtrig-oneshot is not set # CONFIG_PACKAGE_kmod-ledtrig-timer is not set # CONFIG_PACKAGE_kmod-ledtrig-transient is not set # end of LED modules # # Libraries # # CONFIG_PACKAGE_kmod-lib-cordic is not set CONFIG_PACKAGE_kmod-lib-crc-ccitt=y # CONFIG_PACKAGE_kmod-lib-crc-itu-t is not set CONFIG_PACKAGE_kmod-lib-crc16=y # CONFIG_PACKAGE_kmod-lib-crc32c is not set # CONFIG_PACKAGE_kmod-lib-crc7 is not set # CONFIG_PACKAGE_kmod-lib-crc8 is not set # CONFIG_PACKAGE_kmod-lib-lz4 is not set CONFIG_PACKAGE_kmod-lib-textsearch=y # end of Libraries # # Native Language Support # CONFIG_PACKAGE_kmod-nls-base=y # CONFIG_PACKAGE_kmod-nls-cp1250 is not set # CONFIG_PACKAGE_kmod-nls-cp1251 is not set CONFIG_PACKAGE_kmod-nls-cp437=y # CONFIG_PACKAGE_kmod-nls-cp775 is not set # CONFIG_PACKAGE_kmod-nls-cp850 is not set # CONFIG_PACKAGE_kmod-nls-cp852 is not set # CONFIG_PACKAGE_kmod-nls-cp862 is not set # CONFIG_PACKAGE_kmod-nls-cp864 is not set # CONFIG_PACKAGE_kmod-nls-cp866 is not set # CONFIG_PACKAGE_kmod-nls-cp932 is not set # CONFIG_PACKAGE_kmod-nls-cp936 is not set # CONFIG_PACKAGE_kmod-nls-cp950 is not set CONFIG_PACKAGE_kmod-nls-iso8859-1=y # CONFIG_PACKAGE_kmod-nls-iso8859-13 is not set # CONFIG_PACKAGE_kmod-nls-iso8859-15 is not set # CONFIG_PACKAGE_kmod-nls-iso8859-2 is not set # CONFIG_PACKAGE_kmod-nls-iso8859-6 is not set # CONFIG_PACKAGE_kmod-nls-iso8859-8 is not set # CONFIG_PACKAGE_kmod-nls-koi8r is not set CONFIG_PACKAGE_kmod-nls-utf8=y # end of Native Language Support # # Netfilter Extensions # # CONFIG_PACKAGE_kmod-arptables is not set # CONFIG_PACKAGE_kmod-br-netfilter is not set # CONFIG_PACKAGE_kmod-ebtables is not set # CONFIG_PACKAGE_kmod-ebtables-ipv4 is not set # CONFIG_PACKAGE_kmod-ebtables-ipv6 is not set # CONFIG_PACKAGE_kmod-ebtables-watchers is not set CONFIG_PACKAGE_kmod-ip6tables=y # CONFIG_PACKAGE_kmod-ip6tables-extra is not set # CONFIG_PACKAGE_kmod-ipt-account is not set # CONFIG_PACKAGE_kmod-ipt-chaos is not set # CONFIG_PACKAGE_kmod-ipt-checksum is not set # CONFIG_PACKAGE_kmod-ipt-cluster is not set # CONFIG_PACKAGE_kmod-ipt-clusterip is not set # CONFIG_PACKAGE_kmod-ipt-compat-xtables is not set # CONFIG_PACKAGE_kmod-ipt-condition is not set CONFIG_PACKAGE_kmod-ipt-conntrack=y # CONFIG_PACKAGE_kmod-ipt-conntrack-extra is not set # CONFIG_PACKAGE_kmod-ipt-conntrack-label is not set CONFIG_PACKAGE_kmod-ipt-core=y # CONFIG_PACKAGE_kmod-ipt-debug is not set # CONFIG_PACKAGE_kmod-ipt-delude is not set # CONFIG_PACKAGE_kmod-ipt-dhcpmac is not set # CONFIG_PACKAGE_kmod-ipt-dnetmap is not set # CONFIG_PACKAGE_kmod-ipt-extra is not set # CONFIG_PACKAGE_kmod-ipt-filter is not set CONFIG_PACKAGE_kmod-ipt-fullconenat=y # CONFIG_PACKAGE_kmod-ipt-fuzzy is not set # CONFIG_PACKAGE_kmod-ipt-geoip is not set # CONFIG_PACKAGE_kmod-ipt-hashlimit is not set # CONFIG_PACKAGE_kmod-ipt-iface is not set # CONFIG_PACKAGE_kmod-ipt-ipmark is not set # CONFIG_PACKAGE_kmod-ipt-ipopt is not set # CONFIG_PACKAGE_kmod-ipt-ipp2p is not set # CONFIG_PACKAGE_kmod-ipt-iprange is not set # CONFIG_PACKAGE_kmod-ipt-ipsec is not set CONFIG_PACKAGE_kmod-ipt-ipset=y # CONFIG_PACKAGE_kmod-ipt-ipv4options is not set # CONFIG_PACKAGE_kmod-ipt-led is not set # CONFIG_PACKAGE_kmod-ipt-length2 is not set # CONFIG_PACKAGE_kmod-ipt-logmark is not set # CONFIG_PACKAGE_kmod-ipt-lscan is not set # CONFIG_PACKAGE_kmod-ipt-lua is not set CONFIG_PACKAGE_kmod-ipt-nat=y # CONFIG_PACKAGE_kmod-ipt-nat-extra is not set # CONFIG_PACKAGE_kmod-ipt-nat6 is not set # CONFIG_PACKAGE_kmod-ipt-nathelper-rtsp is not set # CONFIG_PACKAGE_kmod-ipt-nflog is not set # CONFIG_PACKAGE_kmod-ipt-nfqueue is not set # CONFIG_PACKAGE_kmod-ipt-offload is not set # CONFIG_PACKAGE_kmod-ipt-physdev is not set # CONFIG_PACKAGE_kmod-ipt-proto is not set # CONFIG_PACKAGE_kmod-ipt-psd is not set # CONFIG_PACKAGE_kmod-ipt-quota2 is not set CONFIG_PACKAGE_kmod-ipt-raw=y # CONFIG_PACKAGE_kmod-ipt-raw6 is not set # CONFIG_PACKAGE_kmod-ipt-rpfilter is not set # CONFIG_PACKAGE_kmod-ipt-rtpengine is not set # CONFIG_PACKAGE_kmod-ipt-sysrq is not set # CONFIG_PACKAGE_kmod-ipt-tarpit is not set # CONFIG_PACKAGE_kmod-ipt-tee is not set CONFIG_PACKAGE_kmod-ipt-tproxy=y # CONFIG_PACKAGE_kmod-ipt-u32 is not set # CONFIG_PACKAGE_kmod-ipt-ulog is not set # CONFIG_PACKAGE_kmod-netatop is not set CONFIG_PACKAGE_kmod-nf-conntrack=y # CONFIG_PACKAGE_kmod-nf-conntrack-netlink is not set CONFIG_PACKAGE_kmod-nf-conntrack6=y # CONFIG_PACKAGE_kmod-nf-flow is not set CONFIG_PACKAGE_kmod-nf-ipt=y CONFIG_PACKAGE_kmod-nf-ipt6=y # CONFIG_PACKAGE_kmod-nf-ipvs is not set CONFIG_PACKAGE_kmod-nf-nat=y # CONFIG_PACKAGE_kmod-nf-nat6 is not set CONFIG_PACKAGE_kmod-nf-nathelper=y CONFIG_PACKAGE_kmod-nf-nathelper-extra=y CONFIG_PACKAGE_kmod-nf-reject=y CONFIG_PACKAGE_kmod-nf-reject6=y CONFIG_PACKAGE_kmod-nfnetlink=y # CONFIG_PACKAGE_kmod-nfnetlink-log is not set # CONFIG_PACKAGE_kmod-nfnetlink-queue is not set # CONFIG_PACKAGE_kmod-nft-arp is not set # CONFIG_PACKAGE_kmod-nft-bridge is not set # CONFIG_PACKAGE_kmod-nft-core is not set # CONFIG_PACKAGE_kmod-nft-fib is not set # CONFIG_PACKAGE_kmod-nft-nat is not set # CONFIG_PACKAGE_kmod-nft-nat6 is not set # CONFIG_PACKAGE_kmod-nft-netdev is not set # CONFIG_PACKAGE_kmod-nft-offload is not set # end of Netfilter Extensions # # Network Devices # # CONFIG_PACKAGE_kmod-3c59x is not set # CONFIG_PACKAGE_kmod-8139cp is not set # CONFIG_PACKAGE_kmod-8139too is not set # CONFIG_PACKAGE_kmod-alx is not set # CONFIG_PACKAGE_kmod-atl1 is not set # CONFIG_PACKAGE_kmod-atl1c is not set # CONFIG_PACKAGE_kmod-atl1e is not set # CONFIG_PACKAGE_kmod-atl2 is not set # CONFIG_PACKAGE_kmod-b44 is not set # CONFIG_PACKAGE_kmod-be2net is not set # CONFIG_PACKAGE_kmod-bnx2 is not set # CONFIG_PACKAGE_kmod-bnx2x is not set # CONFIG_PACKAGE_kmod-dm9000 is not set # CONFIG_PACKAGE_kmod-dummy is not set # CONFIG_PACKAGE_kmod-e100 is not set # CONFIG_PACKAGE_kmod-e1000 is not set # CONFIG_PACKAGE_kmod-et131x is not set # CONFIG_PACKAGE_kmod-ethoc is not set # CONFIG_PACKAGE_kmod-forcedeth is not set # CONFIG_PACKAGE_kmod-gigaset is not set # CONFIG_PACKAGE_kmod-hfcmulti is not set # CONFIG_PACKAGE_kmod-hfcpci is not set # CONFIG_PACKAGE_kmod-i40e is not set # CONFIG_PACKAGE_kmod-iavf is not set # CONFIG_PACKAGE_kmod-ifb is not set # CONFIG_PACKAGE_kmod-igb is not set # CONFIG_PACKAGE_kmod-ixgbe is not set # CONFIG_PACKAGE_kmod-ixgbevf is not set # CONFIG_PACKAGE_kmod-libphy is not set CONFIG_PACKAGE_kmod-macvlan=y # CONFIG_PACKAGE_kmod-mdio-gpio is not set # CONFIG_PACKAGE_kmod-mii is not set # CONFIG_PACKAGE_kmod-mlx4-core is not set # CONFIG_PACKAGE_kmod-mlx5-core is not set # CONFIG_PACKAGE_kmod-natsemi is not set # CONFIG_PACKAGE_kmod-ne2k-pci is not set # CONFIG_PACKAGE_kmod-niu is not set # CONFIG_PACKAGE_kmod-of-mdio is not set # CONFIG_PACKAGE_kmod-pcnet32 is not set # CONFIG_PACKAGE_kmod-phy-bcm84881 is not set # CONFIG_PACKAGE_kmod-phy-broadcom is not set # CONFIG_PACKAGE_kmod-phy-realtek is not set # CONFIG_PACKAGE_kmod-phylink is not set # CONFIG_PACKAGE_kmod-r6040 is not set # CONFIG_PACKAGE_kmod-r8125 is not set # CONFIG_PACKAGE_kmod-r8168 is not set # CONFIG_PACKAGE_kmod-r8169 is not set # CONFIG_PACKAGE_kmod-sfp is not set # CONFIG_PACKAGE_kmod-siit is not set # CONFIG_PACKAGE_kmod-sis190 is not set # CONFIG_PACKAGE_kmod-sis900 is not set # CONFIG_PACKAGE_kmod-skge is not set # CONFIG_PACKAGE_kmod-sky2 is not set # CONFIG_PACKAGE_kmod-solos-pci is not set # CONFIG_PACKAGE_kmod-spi-ks8995 is not set # CONFIG_PACKAGE_kmod-swconfig is not set # CONFIG_PACKAGE_kmod-switch-bcm53xx is not set # CONFIG_PACKAGE_kmod-switch-bcm53xx-mdio is not set # CONFIG_PACKAGE_kmod-switch-ip17xx is not set # CONFIG_PACKAGE_kmod-switch-mvsw61xx is not set # CONFIG_PACKAGE_kmod-switch-rtl8306 is not set # CONFIG_PACKAGE_kmod-switch-rtl8366-smi is not set # CONFIG_PACKAGE_kmod-switch-rtl8366rb is not set # CONFIG_PACKAGE_kmod-switch-rtl8366s is not set # CONFIG_PACKAGE_kmod-switch-rtl8367b is not set # CONFIG_PACKAGE_kmod-tg3 is not set # CONFIG_PACKAGE_kmod-tulip is not set # CONFIG_PACKAGE_kmod-via-rhine is not set # CONFIG_PACKAGE_kmod-via-velocity is not set # CONFIG_PACKAGE_kmod-vmxnet3 is not set # end of Network Devices # # Network Support # # CONFIG_PACKAGE_kmod-atm is not set # CONFIG_PACKAGE_kmod-ax25 is not set # CONFIG_PACKAGE_kmod-batman-adv is not set # CONFIG_PACKAGE_kmod-bonding is not set # CONFIG_PACKAGE_kmod-bpf-test is not set # CONFIG_PACKAGE_kmod-capi is not set # CONFIG_PACKAGE_kmod-dnsresolver is not set # CONFIG_PACKAGE_kmod-fast-classifier is not set # CONFIG_PACKAGE_kmod-fast-classifier-noload is not set # CONFIG_PACKAGE_kmod-fou is not set # CONFIG_PACKAGE_kmod-fou6 is not set # CONFIG_PACKAGE_kmod-geneve is not set # CONFIG_PACKAGE_kmod-gre is not set # CONFIG_PACKAGE_kmod-gre6 is not set # CONFIG_PACKAGE_kmod-ip6-tunnel is not set # CONFIG_PACKAGE_kmod-ipip is not set # CONFIG_PACKAGE_kmod-ipsec is not set # CONFIG_PACKAGE_kmod-iptunnel6 is not set # CONFIG_PACKAGE_kmod-isdn4linux is not set # CONFIG_PACKAGE_kmod-jool is not set # CONFIG_PACKAGE_kmod-l2tp is not set # CONFIG_PACKAGE_kmod-l2tp-eth is not set # CONFIG_PACKAGE_kmod-l2tp-ip is not set # CONFIG_PACKAGE_kmod-macremapper is not set # CONFIG_PACKAGE_kmod-macsec is not set # CONFIG_PACKAGE_kmod-misdn is not set # CONFIG_PACKAGE_kmod-mpls is not set # CONFIG_PACKAGE_kmod-nat46 is not set # CONFIG_PACKAGE_kmod-netem is not set # CONFIG_PACKAGE_kmod-netlink-diag is not set # CONFIG_PACKAGE_kmod-nlmon is not set # CONFIG_PACKAGE_kmod-nsh is not set # CONFIG_PACKAGE_kmod-openvswitch is not set # CONFIG_PACKAGE_kmod-openvswitch-geneve is not set # CONFIG_PACKAGE_kmod-openvswitch-gre is not set # CONFIG_PACKAGE_kmod-openvswitch-vxlan is not set # CONFIG_PACKAGE_kmod-pf-ring is not set # CONFIG_PACKAGE_kmod-pktgen is not set CONFIG_PACKAGE_kmod-ppp=y CONFIG_PACKAGE_kmod-mppe=y # CONFIG_PACKAGE_kmod-ppp-synctty is not set # CONFIG_PACKAGE_kmod-pppoa is not set CONFIG_PACKAGE_kmod-pppoe=y # CONFIG_PACKAGE_kmod-pppol2tp is not set CONFIG_PACKAGE_kmod-pppox=y # CONFIG_PACKAGE_kmod-pptp is not set # CONFIG_PACKAGE_kmod-sched is not set # CONFIG_PACKAGE_kmod-sched-act-vlan is not set # CONFIG_PACKAGE_kmod-sched-bpf is not set # CONFIG_PACKAGE_kmod-sched-cake-oot is not set # CONFIG_PACKAGE_kmod-sched-cake-virtual is not set # CONFIG_PACKAGE_kmod-sched-connmark is not set # CONFIG_PACKAGE_kmod-sched-core is not set # CONFIG_PACKAGE_kmod-sched-ctinfo is not set # CONFIG_PACKAGE_kmod-sched-flower is not set # CONFIG_PACKAGE_kmod-sched-ipset is not set # CONFIG_PACKAGE_kmod-sched-mqprio is not set # CONFIG_PACKAGE_kmod-sctp is not set # CONFIG_PACKAGE_kmod-shortcut-fe is not set # CONFIG_PACKAGE_kmod-shortcut-fe-cm is not set # CONFIG_PACKAGE_kmod-sit is not set CONFIG_PACKAGE_kmod-slhc=y # CONFIG_PACKAGE_kmod-slip is not set # CONFIG_PACKAGE_kmod-tcp-bbr is not set # CONFIG_PACKAGE_kmod-trelay is not set # CONFIG_PACKAGE_kmod-tun is not set # CONFIG_PACKAGE_kmod-veth is not set # CONFIG_PACKAGE_kmod-vxlan is not set # CONFIG_PACKAGE_kmod-wireguard is not set # end of Network Support # # Other modules # # CONFIG_PACKAGE_kmod-6lowpan is not set # CONFIG_PACKAGE_kmod-ath3k is not set # CONFIG_PACKAGE_kmod-bcma is not set # CONFIG_PACKAGE_kmod-bluetooth is not set # CONFIG_PACKAGE_kmod-bluetooth-6lowpan is not set # CONFIG_PACKAGE_kmod-bmp085 is not set # CONFIG_PACKAGE_kmod-bmp085-i2c is not set # CONFIG_PACKAGE_kmod-bmp085-spi is not set # CONFIG_PACKAGE_kmod-btmrvl is not set # CONFIG_PACKAGE_kmod-button-hotplug is not set # CONFIG_PACKAGE_kmod-echo is not set # CONFIG_PACKAGE_kmod-eeprom-93cx6 is not set # CONFIG_PACKAGE_kmod-eeprom-at24 is not set # CONFIG_PACKAGE_kmod-eeprom-at25 is not set # CONFIG_PACKAGE_kmod-gpio-beeper is not set CONFIG_PACKAGE_kmod-gpio-button-hotplug=y # CONFIG_PACKAGE_kmod-gpio-dev is not set # CONFIG_PACKAGE_kmod-gpio-mcp23s08 is not set # CONFIG_PACKAGE_kmod-gpio-nxp-74hc164 is not set # CONFIG_PACKAGE_kmod-gpio-pca953x is not set # CONFIG_PACKAGE_kmod-gpio-pcf857x is not set # CONFIG_PACKAGE_kmod-ikconfig is not set # CONFIG_PACKAGE_kmod-it87-wdt is not set # CONFIG_PACKAGE_kmod-itco-wdt is not set # CONFIG_PACKAGE_kmod-lp is not set # CONFIG_PACKAGE_kmod-mmc is not set # CONFIG_PACKAGE_kmod-mtd-rw is not set # CONFIG_PACKAGE_kmod-mtdoops is not set # CONFIG_PACKAGE_kmod-mtdram is not set # CONFIG_PACKAGE_kmod-mtdtests is not set # CONFIG_PACKAGE_kmod-parport-pc is not set # CONFIG_PACKAGE_kmod-ppdev is not set # CONFIG_PACKAGE_kmod-pps is not set # CONFIG_PACKAGE_kmod-pps-gpio is not set # CONFIG_PACKAGE_kmod-pps-ldisc is not set # CONFIG_PACKAGE_kmod-ptp is not set # CONFIG_PACKAGE_kmod-random-core is not set # CONFIG_PACKAGE_kmod-random-tpm is not set # CONFIG_PACKAGE_kmod-rtc-ds1307 is not set # CONFIG_PACKAGE_kmod-rtc-ds1374 is not set # CONFIG_PACKAGE_kmod-rtc-ds1672 is not set # CONFIG_PACKAGE_kmod-rtc-em3027 is not set # CONFIG_PACKAGE_kmod-rtc-isl1208 is not set # CONFIG_PACKAGE_kmod-rtc-pcf2123 is not set # CONFIG_PACKAGE_kmod-rtc-pcf2127 is not set # CONFIG_PACKAGE_kmod-rtc-pcf8563 is not set # CONFIG_PACKAGE_kmod-rtc-pt7c4338 is not set # CONFIG_PACKAGE_kmod-rtc-rs5c372a is not set # CONFIG_PACKAGE_kmod-rtc-rx8025 is not set # CONFIG_PACKAGE_kmod-rtc-s35390a is not set # CONFIG_PACKAGE_kmod-sdhci is not set # CONFIG_PACKAGE_kmod-serial-8250 is not set # CONFIG_PACKAGE_kmod-serial-8250-exar is not set # CONFIG_PACKAGE_kmod-softdog is not set # CONFIG_PACKAGE_kmod-ssb is not set # CONFIG_PACKAGE_kmod-tpm is not set # CONFIG_PACKAGE_kmod-tpm-i2c-atmel is not set # CONFIG_PACKAGE_kmod-tpm-i2c-infineon is not set # CONFIG_PACKAGE_kmod-w83627hf-wdt is not set # CONFIG_PACKAGE_kmod-zram is not set # end of Other modules # # PCMCIA support # # end of PCMCIA support # # SPI Support # # CONFIG_PACKAGE_kmod-mmc-spi is not set # CONFIG_PACKAGE_kmod-spi-bitbang is not set # CONFIG_PACKAGE_kmod-spi-dev is not set # CONFIG_PACKAGE_kmod-spi-gpio is not set # CONFIG_PACKAGE_kmod-spi-gpio-custom is not set # CONFIG_PACKAGE_kmod-spi-vsc7385 is not set # end of SPI Support # # Sound Support # # CONFIG_PACKAGE_kmod-sound-core is not set # end of Sound Support # # USB Support # # CONFIG_PACKAGE_kmod-chaoskey is not set # CONFIG_PACKAGE_kmod-usb-acm is not set # CONFIG_PACKAGE_kmod-usb-atm is not set # CONFIG_PACKAGE_kmod-usb-chipidea is not set # CONFIG_PACKAGE_kmod-usb-chipidea2 is not set # CONFIG_PACKAGE_kmod-usb-cm109 is not set CONFIG_PACKAGE_kmod-usb-core=y # CONFIG_PACKAGE_kmod-usb-dwc2 is not set # CONFIG_PACKAGE_kmod-usb-dwc3 is not set CONFIG_PACKAGE_kmod-usb-ehci=y # CONFIG_PACKAGE_kmod-usb-gadget-cdc-composite is not set # CONFIG_PACKAGE_kmod-usb-gadget-ehci-debug is not set # CONFIG_PACKAGE_kmod-usb-gadget-eth is not set # CONFIG_PACKAGE_kmod-usb-gadget-hid is not set # CONFIG_PACKAGE_kmod-usb-gadget-mass-storage is not set # CONFIG_PACKAGE_kmod-usb-gadget-serial is not set # CONFIG_PACKAGE_kmod-usb-hid is not set # CONFIG_PACKAGE_kmod-usb-ledtrig-usbport is not set CONFIG_PACKAGE_kmod-usb-net=y # CONFIG_PACKAGE_kmod-usb-net-asix is not set # CONFIG_PACKAGE_kmod-usb-net-asix-ax88179 is not set # CONFIG_PACKAGE_kmod-usb-net-cdc-eem is not set CONFIG_PACKAGE_kmod-usb-net-cdc-ether=y # CONFIG_PACKAGE_kmod-usb-net-cdc-mbim is not set CONFIG_PACKAGE_kmod-usb-net-cdc-ncm=y # CONFIG_PACKAGE_kmod-usb-net-cdc-subset is not set # CONFIG_PACKAGE_kmod-usb-net-dm9601-ether is not set # CONFIG_PACKAGE_kmod-usb-net-hso is not set CONFIG_PACKAGE_kmod-usb-net-huawei-cdc-ncm=y # CONFIG_PACKAGE_kmod-usb-net-ipheth is not set # CONFIG_PACKAGE_kmod-usb-net-kalmia is not set # CONFIG_PACKAGE_kmod-usb-net-kaweth is not set # CONFIG_PACKAGE_kmod-usb-net-mcs7830 is not set # CONFIG_PACKAGE_kmod-usb-net-pegasus is not set # CONFIG_PACKAGE_kmod-usb-net-pl is not set # CONFIG_PACKAGE_kmod-usb-net-qmi-wwan is not set CONFIG_PACKAGE_kmod-usb-net-rndis=y # CONFIG_PACKAGE_kmod-usb-net-rtl8150 is not set # CONFIG_PACKAGE_kmod-usb-net-rtl8152 is not set # CONFIG_PACKAGE_kmod-usb-net-sierrawireless is not set # CONFIG_PACKAGE_kmod-usb-net-smsc95xx is not set # CONFIG_PACKAGE_kmod-usb-net-sr9700 is not set # CONFIG_PACKAGE_kmod-usb-net2280 is not set # CONFIG_PACKAGE_kmod-usb-ohci is not set # CONFIG_PACKAGE_kmod-usb-ohci-pci is not set # CONFIG_PACKAGE_kmod-usb-printer is not set # CONFIG_PACKAGE_kmod-usb-serial is not set CONFIG_PACKAGE_kmod-usb-storage=y # CONFIG_PACKAGE_kmod-usb-storage-extras is not set # CONFIG_PACKAGE_kmod-usb-storage-uas is not set # CONFIG_PACKAGE_kmod-usb-uhci is not set # CONFIG_PACKAGE_kmod-usb-wdm is not set # CONFIG_PACKAGE_kmod-usb-yealink is not set CONFIG_PACKAGE_kmod-usb2=y # CONFIG_PACKAGE_kmod-usb2-pci is not set # CONFIG_PACKAGE_kmod-usb3 is not set # CONFIG_PACKAGE_kmod-usbip is not set # CONFIG_PACKAGE_kmod-usbip-client is not set # CONFIG_PACKAGE_kmod-usbip-server is not set # CONFIG_PACKAGE_kmod-usbmon is not set # end of USB Support # # Video Support # # CONFIG_PACKAGE_kmod-video-core is not set # end of Video Support # # Virtualization # # end of Virtualization # # Voice over IP # # end of Voice over IP # # W1 support # # CONFIG_PACKAGE_kmod-w1 is not set # end of W1 support # # WPAN 802.15.4 Support # # CONFIG_PACKAGE_kmod-at86rf230 is not set # CONFIG_PACKAGE_kmod-atusb is not set # CONFIG_PACKAGE_kmod-ca8210 is not set # CONFIG_PACKAGE_kmod-cc2520 is not set # CONFIG_PACKAGE_kmod-fakelb is not set # CONFIG_PACKAGE_kmod-ieee802154 is not set # CONFIG_PACKAGE_kmod-ieee802154-6lowpan is not set # CONFIG_PACKAGE_kmod-mac802154 is not set # CONFIG_PACKAGE_kmod-mrf24j40 is not set # end of WPAN 802.15.4 Support # # Wireless Drivers # # CONFIG_PACKAGE_kmod-adm8211 is not set # CONFIG_PACKAGE_kmod-ar5523 is not set CONFIG_PACKAGE_kmod-ath=y CONFIG_ATH_USER_REGD=y # CONFIG_PACKAGE_ATH_DEBUG is not set CONFIG_PACKAGE_ATH_DFS=y # CONFIG_PACKAGE_ATH_DYNACK is not set # CONFIG_PACKAGE_kmod-ath10k is not set CONFIG_PACKAGE_kmod-ath10k-ct=y CONFIG_ATH10K-CT_LEDS=y # CONFIG_PACKAGE_kmod-ath10k-ct-smallbuffers is not set # CONFIG_PACKAGE_kmod-ath5k is not set # CONFIG_PACKAGE_kmod-ath6kl-sdio is not set # CONFIG_PACKAGE_kmod-ath6kl-usb is not set CONFIG_PACKAGE_kmod-ath9k=y # CONFIG_ATH9K_HWRNG is not set # CONFIG_ATH9K_SUPPORT_PCOEM is not set # CONFIG_ATH9K_TX99 is not set CONFIG_ATH9K_UBNTHSR=y CONFIG_PACKAGE_kmod-ath9k-common=y # CONFIG_PACKAGE_kmod-ath9k-htc is not set # CONFIG_PACKAGE_kmod-b43 is not set # CONFIG_PACKAGE_kmod-b43legacy is not set # CONFIG_PACKAGE_kmod-brcmfmac is not set # CONFIG_PACKAGE_kmod-brcmsmac is not set # CONFIG_PACKAGE_kmod-brcmutil is not set # CONFIG_PACKAGE_kmod-carl9170 is not set CONFIG_PACKAGE_kmod-cfg80211=y # CONFIG_PACKAGE_CFG80211_TESTMODE is not set # CONFIG_PACKAGE_kmod-hermes is not set # CONFIG_PACKAGE_kmod-hermes-pci is not set # CONFIG_PACKAGE_kmod-hermes-plx is not set # CONFIG_PACKAGE_kmod-iwl-legacy is not set # CONFIG_PACKAGE_kmod-iwl3945 is not set # CONFIG_PACKAGE_kmod-iwl4965 is not set # CONFIG_PACKAGE_kmod-iwlwifi is not set # CONFIG_PACKAGE_kmod-lib80211 is not set # CONFIG_PACKAGE_kmod-libertas-sdio is not set # CONFIG_PACKAGE_kmod-libertas-spi is not set # CONFIG_PACKAGE_kmod-libertas-usb is not set CONFIG_PACKAGE_kmod-mac80211=y CONFIG_PACKAGE_MAC80211_DEBUGFS=y # CONFIG_PACKAGE_MAC80211_TRACING is not set CONFIG_PACKAGE_MAC80211_MESH=y # CONFIG_PACKAGE_kmod-mac80211-hwsim is not set # CONFIG_PACKAGE_kmod-mt76 is not set # CONFIG_PACKAGE_kmod-mt7601u is not set # CONFIG_PACKAGE_kmod-mt7603 is not set # CONFIG_PACKAGE_kmod-mt7615-firmware is not set # CONFIG_PACKAGE_kmod-mt7615e is not set # CONFIG_PACKAGE_kmod-mt7663-firmware-ap is not set # CONFIG_PACKAGE_kmod-mt7663-firmware-sta is not set # CONFIG_PACKAGE_kmod-mt7663s is not set # CONFIG_PACKAGE_kmod-mt7663u is not set # CONFIG_PACKAGE_kmod-mt76x0e is not set # CONFIG_PACKAGE_kmod-mt76x0u is not set # CONFIG_PACKAGE_kmod-mt76x2 is not set # CONFIG_PACKAGE_kmod-mt76x2u is not set # CONFIG_PACKAGE_kmod-mt7915e is not set # CONFIG_PACKAGE_kmod-mwifiex-pcie is not set # CONFIG_PACKAGE_kmod-mwifiex-sdio is not set # CONFIG_PACKAGE_kmod-mwl8k is not set # CONFIG_PACKAGE_kmod-net-prism54 is not set # CONFIG_PACKAGE_kmod-net-rtl8192su is not set # CONFIG_PACKAGE_kmod-owl-loader is not set # CONFIG_PACKAGE_kmod-p54-common is not set # CONFIG_PACKAGE_kmod-p54-pci is not set # CONFIG_PACKAGE_kmod-p54-usb is not set # CONFIG_PACKAGE_kmod-rsi91x is not set # CONFIG_PACKAGE_kmod-rsi91x-sdio is not set # CONFIG_PACKAGE_kmod-rsi91x-usb is not set # CONFIG_PACKAGE_kmod-rt2400-pci is not set # CONFIG_PACKAGE_kmod-rt2500-pci is not set # CONFIG_PACKAGE_kmod-rt2500-usb is not set # CONFIG_PACKAGE_kmod-rt2800-pci is not set # CONFIG_PACKAGE_kmod-rt2800-usb is not set # CONFIG_PACKAGE_kmod-rt2x00-lib is not set # CONFIG_PACKAGE_kmod-rt61-pci is not set # CONFIG_PACKAGE_kmod-rt73-usb is not set # CONFIG_PACKAGE_kmod-rtl8180 is not set # CONFIG_PACKAGE_kmod-rtl8187 is not set # CONFIG_PACKAGE_kmod-rtl8192ce is not set # CONFIG_PACKAGE_kmod-rtl8192cu is not set # CONFIG_PACKAGE_kmod-rtl8192de is not set # CONFIG_PACKAGE_kmod-rtl8192se is not set # CONFIG_PACKAGE_kmod-rtl8723bs is not set # CONFIG_PACKAGE_kmod-rtl8812au-ct is not set # CONFIG_PACKAGE_kmod-rtl8821ae is not set # CONFIG_PACKAGE_kmod-rtl8xxxu is not set # CONFIG_PACKAGE_kmod-rtw88 is not set # CONFIG_PACKAGE_kmod-wl12xx is not set # CONFIG_PACKAGE_kmod-wl18xx is not set # CONFIG_PACKAGE_kmod-wlcore is not set # CONFIG_PACKAGE_kmod-zd1211rw is not set # end of Wireless Drivers # end of Kernel modules # # Languages # # # Erlang # # CONFIG_PACKAGE_erlang is not set # CONFIG_PACKAGE_erlang-asn1 is not set # CONFIG_PACKAGE_erlang-compiler is not set # CONFIG_PACKAGE_erlang-crypto is not set # CONFIG_PACKAGE_erlang-erl-interface is not set # CONFIG_PACKAGE_erlang-hipe is not set # CONFIG_PACKAGE_erlang-inets is not set # CONFIG_PACKAGE_erlang-mnesia is not set # CONFIG_PACKAGE_erlang-os_mon is not set # CONFIG_PACKAGE_erlang-public-key is not set # CONFIG_PACKAGE_erlang-reltool is not set # CONFIG_PACKAGE_erlang-runtime-tools is not set # CONFIG_PACKAGE_erlang-snmp is not set # CONFIG_PACKAGE_erlang-ssh is not set # CONFIG_PACKAGE_erlang-ssl is not set # CONFIG_PACKAGE_erlang-syntax-tools is not set # CONFIG_PACKAGE_erlang-tools is not set # CONFIG_PACKAGE_erlang-xmerl is not set # end of Erlang # # Go # # CONFIG_PACKAGE_golang is not set # # Configuration # CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT="" CONFIG_GOLANG_BUILD_CACHE_DIR="" # CONFIG_GOLANG_MOD_CACHE_WORLD_READABLE is not set # end of Configuration # CONFIG_PACKAGE_golang-doc is not set # CONFIG_PACKAGE_golang-github-jedisct1-dnscrypt-proxy2-dev is not set # CONFIG_PACKAGE_golang-github-nextdns-nextdns-dev is not set # CONFIG_PACKAGE_golang-gitlab-yawning-obfs4-dev is not set # CONFIG_PACKAGE_golang-src is not set # CONFIG_PACKAGE_golang-torproject-tor-fw-helper-dev is not set # end of Go # # Lua # # CONFIG_PACKAGE_dkjson is not set # CONFIG_PACKAGE_json4lua is not set # CONFIG_PACKAGE_ldbus is not set CONFIG_PACKAGE_libiwinfo-lua=y # CONFIG_PACKAGE_lpeg is not set # CONFIG_PACKAGE_lsqlite3 is not set CONFIG_PACKAGE_lua=y # CONFIG_PACKAGE_lua-bencode is not set # CONFIG_PACKAGE_lua-bit32 is not set # CONFIG_PACKAGE_lua-cjson is not set # CONFIG_PACKAGE_lua-copas is not set # CONFIG_PACKAGE_lua-coxpcall is not set # CONFIG_PACKAGE_lua-ev is not set # CONFIG_PACKAGE_lua-examples is not set # CONFIG_PACKAGE_lua-libmodbus is not set # CONFIG_PACKAGE_lua-lzlib is not set # CONFIG_PACKAGE_lua-md5 is not set # CONFIG_PACKAGE_lua-mobdebug is not set # CONFIG_PACKAGE_lua-mosquitto is not set # CONFIG_PACKAGE_lua-openssl is not set # CONFIG_PACKAGE_lua-penlight is not set # CONFIG_PACKAGE_lua-rings is not set # CONFIG_PACKAGE_lua-rs232 is not set # CONFIG_PACKAGE_lua-sha2 is not set # CONFIG_PACKAGE_lua-wsapi-base is not set # CONFIG_PACKAGE_lua-wsapi-xavante is not set # CONFIG_PACKAGE_lua-xavante is not set # CONFIG_PACKAGE_lua5.3 is not set # CONFIG_PACKAGE_luabitop is not set # CONFIG_PACKAGE_luac is not set # CONFIG_PACKAGE_luac5.3 is not set # CONFIG_PACKAGE_luaexpat is not set # CONFIG_PACKAGE_luafilesystem is not set # CONFIG_PACKAGE_luajit is not set # CONFIG_PACKAGE_lualanes is not set # CONFIG_PACKAGE_luaposix is not set # CONFIG_PACKAGE_luarocks is not set # CONFIG_PACKAGE_luasec is not set # CONFIG_PACKAGE_luasoap is not set # CONFIG_PACKAGE_luasocket is not set # CONFIG_PACKAGE_luasocket5.3 is not set # CONFIG_PACKAGE_luasql-mysql is not set # CONFIG_PACKAGE_luasql-pgsql is not set # CONFIG_PACKAGE_luasql-sqlite3 is not set # CONFIG_PACKAGE_luasrcdiet is not set CONFIG_PACKAGE_luci-lib-fs=y # CONFIG_PACKAGE_luv is not set # CONFIG_PACKAGE_lzmq is not set # CONFIG_PACKAGE_uuid is not set # end of Lua # # Node.js # # CONFIG_PACKAGE_node is not set # CONFIG_PACKAGE_node-arduino-firmata is not set # CONFIG_PACKAGE_node-cylon is not set # CONFIG_PACKAGE_node-cylon-firmata is not set # CONFIG_PACKAGE_node-cylon-gpio is not set # CONFIG_PACKAGE_node-cylon-i2c is not set # CONFIG_PACKAGE_node-hid is not set # CONFIG_PACKAGE_node-homebridge is not set # CONFIG_PACKAGE_node-javascript-obfuscator is not set # CONFIG_PACKAGE_node-npm is not set # CONFIG_PACKAGE_node-serialport is not set # CONFIG_PACKAGE_node-serialport-bindings is not set # end of Node.js # # PHP # # CONFIG_PACKAGE_php7 is not set # end of PHP # # Perl # # CONFIG_PACKAGE_perl is not set # end of Perl # # Python # # CONFIG_PACKAGE_gunicorn3 is not set # CONFIG_PACKAGE_micropython is not set # CONFIG_PACKAGE_micropython-lib is not set # CONFIG_PACKAGE_python-pip-conf is not set # CONFIG_PACKAGE_python3 is not set # CONFIG_PACKAGE_python3-aiohttp is not set # CONFIG_PACKAGE_python3-aiohttp-cors is not set # CONFIG_PACKAGE_python3-appdirs is not set # CONFIG_PACKAGE_python3-asgiref is not set # CONFIG_PACKAGE_python3-asn1crypto is not set # CONFIG_PACKAGE_python3-astral is not set # CONFIG_PACKAGE_python3-async-timeout is not set # CONFIG_PACKAGE_python3-asyncio is not set # CONFIG_PACKAGE_python3-atomicwrites is not set # CONFIG_PACKAGE_python3-attrs is not set # CONFIG_PACKAGE_python3-automat is not set # CONFIG_PACKAGE_python3-awscli is not set # CONFIG_PACKAGE_python3-base is not set # CONFIG_PACKAGE_python3-bcrypt is not set # CONFIG_PACKAGE_python3-boto3 is not set # CONFIG_PACKAGE_python3-botocore is not set # CONFIG_PACKAGE_python3-bottle is not set # CONFIG_PACKAGE_python3-cached-property is not set # CONFIG_PACKAGE_python3-cachelib is not set # CONFIG_PACKAGE_python3-cachetools is not set # CONFIG_PACKAGE_python3-certifi is not set # CONFIG_PACKAGE_python3-cffi is not set # CONFIG_PACKAGE_python3-cgi is not set # CONFIG_PACKAGE_python3-cgitb is not set # CONFIG_PACKAGE_python3-chardet is not set # CONFIG_PACKAGE_python3-click is not set # CONFIG_PACKAGE_python3-click-log is not set # CONFIG_PACKAGE_python3-codecs is not set # CONFIG_PACKAGE_python3-colorama is not set # CONFIG_PACKAGE_python3-constantly is not set # CONFIG_PACKAGE_python3-contextlib2 is not set # CONFIG_PACKAGE_python3-cryptodome is not set # CONFIG_PACKAGE_python3-cryptodomex is not set # CONFIG_PACKAGE_python3-cryptography is not set # CONFIG_PACKAGE_python3-ctypes is not set # CONFIG_PACKAGE_python3-curl is not set # CONFIG_PACKAGE_python3-dateutil is not set # CONFIG_PACKAGE_python3-dbm is not set # CONFIG_PACKAGE_python3-decimal is not set # CONFIG_PACKAGE_python3-decorator is not set # CONFIG_PACKAGE_python3-defusedxml is not set # CONFIG_PACKAGE_python3-dev is not set # CONFIG_PACKAGE_python3-distro is not set # CONFIG_PACKAGE_python3-distutils is not set # CONFIG_PACKAGE_python3-django is not set # CONFIG_PACKAGE_python3-django-appconf is not set # CONFIG_PACKAGE_python3-django-compressor is not set # CONFIG_PACKAGE_python3-django-cors-headers is not set # CONFIG_PACKAGE_python3-django-etesync-journal is not set # CONFIG_PACKAGE_python3-django-formtools is not set # CONFIG_PACKAGE_python3-django-jsonfield is not set # CONFIG_PACKAGE_python3-django-jsonfield2 is not set # CONFIG_PACKAGE_python3-django-picklefield is not set # CONFIG_PACKAGE_python3-django-postoffice is not set # CONFIG_PACKAGE_python3-django-ranged-response is not set # CONFIG_PACKAGE_python3-django-restframework is not set # CONFIG_PACKAGE_python3-django-restframework39 is not set # CONFIG_PACKAGE_python3-django-simple-captcha is not set # CONFIG_PACKAGE_python3-django-statici18n is not set # CONFIG_PACKAGE_python3-django-webpack-loader is not set # CONFIG_PACKAGE_python3-django1 is not set # CONFIG_PACKAGE_python3-dns is not set # CONFIG_PACKAGE_python3-docker is not set # CONFIG_PACKAGE_python3-dockerpty is not set # CONFIG_PACKAGE_python3-docopt is not set # CONFIG_PACKAGE_python3-docutils is not set # CONFIG_PACKAGE_python3-dotenv is not set # CONFIG_PACKAGE_python3-drf-nested-routers is not set # CONFIG_PACKAGE_python3-email is not set # CONFIG_PACKAGE_python3-et_xmlfile is not set # CONFIG_PACKAGE_python3-evdev is not set # CONFIG_PACKAGE_python3-flask is not set # CONFIG_PACKAGE_python3-flask-login is not set # CONFIG_PACKAGE_python3-gdbm is not set # CONFIG_PACKAGE_python3-gmpy2 is not set # CONFIG_PACKAGE_python3-gnupg is not set # CONFIG_PACKAGE_python3-gpiod is not set # CONFIG_PACKAGE_python3-gunicorn is not set # CONFIG_PACKAGE_python3-hyperlink is not set # CONFIG_PACKAGE_python3-idna is not set # CONFIG_PACKAGE_python3-ifaddr is not set # CONFIG_PACKAGE_python3-incremental is not set # CONFIG_PACKAGE_python3-influxdb is not set # CONFIG_PACKAGE_python3-intelhex is not set # CONFIG_PACKAGE_python3-itsdangerous is not set # CONFIG_PACKAGE_python3-jdcal is not set # CONFIG_PACKAGE_python3-jinja2 is not set # CONFIG_PACKAGE_python3-jmespath is not set # CONFIG_PACKAGE_python3-jsonpath-ng is not set # CONFIG_PACKAGE_python3-jsonschema is not set # CONFIG_PACKAGE_python3-lib2to3 is not set # CONFIG_PACKAGE_python3-libmodbus is not set # CONFIG_PACKAGE_python3-light is not set # # Configuration # # CONFIG_PYTHON3_BLUETOOTH_SUPPORT is not set # end of Configuration # CONFIG_PACKAGE_python3-logging is not set # CONFIG_PACKAGE_python3-lxml is not set # CONFIG_PACKAGE_python3-lzma is not set # CONFIG_PACKAGE_python3-markdown is not set # CONFIG_PACKAGE_python3-markupsafe is not set # CONFIG_PACKAGE_python3-maxminddb is not set # CONFIG_PACKAGE_python3-more-itertools is not set # CONFIG_PACKAGE_python3-multidict is not set # CONFIG_PACKAGE_python3-multiprocessing is not set # CONFIG_PACKAGE_python3-mysqlclient is not set # CONFIG_PACKAGE_python3-ncurses is not set # CONFIG_PACKAGE_python3-netdisco is not set # CONFIG_PACKAGE_python3-netifaces is not set # CONFIG_PACKAGE_python3-newt is not set # CONFIG_PACKAGE_python3-oauthlib is not set # CONFIG_PACKAGE_python3-openpyxl is not set # CONFIG_PACKAGE_python3-openssl is not set # CONFIG_PACKAGE_python3-packaging is not set # CONFIG_PACKAGE_python3-paho-mqtt is not set # CONFIG_PACKAGE_python3-paramiko is not set # CONFIG_PACKAGE_python3-parsley is not set # CONFIG_PACKAGE_python3-passlib is not set # CONFIG_PACKAGE_python3-pillow is not set # CONFIG_PACKAGE_python3-pip is not set # CONFIG_PACKAGE_python3-pkg-resources is not set # CONFIG_PACKAGE_python3-pluggy is not set # CONFIG_PACKAGE_python3-ply is not set # CONFIG_PACKAGE_python3-py is not set # CONFIG_PACKAGE_python3-pyasn1 is not set # CONFIG_PACKAGE_python3-pyasn1-modules is not set # CONFIG_PACKAGE_python3-pycparser is not set # CONFIG_PACKAGE_python3-pydoc is not set # CONFIG_PACKAGE_python3-pyjwt is not set # CONFIG_PACKAGE_python3-pymysql is not set # CONFIG_PACKAGE_python3-pynacl is not set # CONFIG_PACKAGE_python3-pyodbc is not set # CONFIG_PACKAGE_python3-pyopenssl is not set # CONFIG_PACKAGE_python3-pyotp is not set # CONFIG_PACKAGE_python3-pyparsing is not set # CONFIG_PACKAGE_python3-pyroute2 is not set # CONFIG_PACKAGE_python3-pyrsistent is not set # CONFIG_PACKAGE_python3-pyserial is not set # CONFIG_PACKAGE_python3-pytest is not set # CONFIG_PACKAGE_python3-pytz is not set # CONFIG_PACKAGE_python3-qrcode is not set # CONFIG_PACKAGE_python3-rcssmin is not set # CONFIG_PACKAGE_python3-requests is not set # CONFIG_PACKAGE_python3-requests-oauthlib is not set # CONFIG_PACKAGE_python3-rsa is not set # CONFIG_PACKAGE_python3-ruamel-yaml is not set # CONFIG_PACKAGE_python3-s3transfer is not set # CONFIG_PACKAGE_python3-schedule is not set # CONFIG_PACKAGE_python3-schema is not set # CONFIG_PACKAGE_python3-seafile-ccnet is not set # CONFIG_PACKAGE_python3-seafile-server is not set # CONFIG_PACKAGE_python3-searpc is not set # CONFIG_PACKAGE_python3-sentry-sdk is not set # CONFIG_PACKAGE_python3-service-identity is not set # CONFIG_PACKAGE_python3-setuptools is not set # CONFIG_PACKAGE_python3-simplejson is not set # CONFIG_PACKAGE_python3-six is not set # CONFIG_PACKAGE_python3-slugify is not set # CONFIG_PACKAGE_python3-smbus is not set # CONFIG_PACKAGE_python3-speedtest-cli is not set # CONFIG_PACKAGE_python3-sqlalchemy is not set # CONFIG_PACKAGE_python3-sqlite3 is not set # CONFIG_PACKAGE_python3-sqlparse is not set # CONFIG_PACKAGE_python3-stem is not set # CONFIG_PACKAGE_python3-sysrepo is not set # CONFIG_PACKAGE_python3-text-unidecode is not set # CONFIG_PACKAGE_python3-texttable is not set # CONFIG_PACKAGE_python3-twisted is not set # CONFIG_PACKAGE_python3-unidecode is not set # CONFIG_PACKAGE_python3-unittest is not set # CONFIG_PACKAGE_python3-urllib is not set # CONFIG_PACKAGE_python3-urllib3 is not set # CONFIG_PACKAGE_python3-vobject is not set # CONFIG_PACKAGE_python3-voluptuous is not set # CONFIG_PACKAGE_python3-voluptuous-serialize is not set # CONFIG_PACKAGE_python3-wcwidth is not set # CONFIG_PACKAGE_python3-websocket-client is not set # CONFIG_PACKAGE_python3-werkzeug is not set # CONFIG_PACKAGE_python3-xml is not set # CONFIG_PACKAGE_python3-xmltodict is not set # CONFIG_PACKAGE_python3-yaml is not set # CONFIG_PACKAGE_python3-yarl is not set # CONFIG_PACKAGE_python3-zeroconf is not set # CONFIG_PACKAGE_python3-zipp is not set # CONFIG_PACKAGE_python3-zope-interface is not set # end of Python # # Ruby # # CONFIG_PACKAGE_ruby is not set # end of Ruby # # Tcl # # CONFIG_PACKAGE_tcl is not set # end of Tcl # CONFIG_PACKAGE_chicken-scheme-full is not set # CONFIG_PACKAGE_chicken-scheme-interpreter is not set # CONFIG_PACKAGE_slsh is not set # end of Languages # # Libraries # # # Compression # # CONFIG_PACKAGE_libbz2 is not set # CONFIG_PACKAGE_liblz4 is not set # CONFIG_PACKAGE_liblzma is not set # CONFIG_PACKAGE_libunrar is not set # CONFIG_PACKAGE_libzip-gnutls is not set # CONFIG_PACKAGE_libzip-mbedtls is not set # CONFIG_PACKAGE_libzip-nossl is not set # CONFIG_PACKAGE_libzip-openssl is not set # CONFIG_PACKAGE_libzstd is not set # end of Compression # # Database # # CONFIG_PACKAGE_libmariadb is not set # CONFIG_PACKAGE_libpq is not set # CONFIG_PACKAGE_libsqlite3 is not set # CONFIG_PACKAGE_pgsqlodbc is not set # CONFIG_PACKAGE_psqlodbca is not set # CONFIG_PACKAGE_psqlodbcw is not set # CONFIG_PACKAGE_redis-cli is not set # CONFIG_PACKAGE_redis-full is not set # CONFIG_PACKAGE_redis-server is not set # CONFIG_PACKAGE_redis-utils is not set # CONFIG_PACKAGE_tdb is not set # CONFIG_PACKAGE_unixodbc is not set # end of Database # # Filesystem # # CONFIG_PACKAGE_libacl is not set # CONFIG_PACKAGE_libattr is not set # CONFIG_PACKAGE_libfuse is not set # CONFIG_PACKAGE_libfuse3 is not set # CONFIG_PACKAGE_libow is not set # CONFIG_PACKAGE_libow-capi is not set # CONFIG_PACKAGE_libsysfs is not set # end of Filesystem # # Firewall # # CONFIG_PACKAGE_libfko is not set CONFIG_PACKAGE_libip4tc=y CONFIG_PACKAGE_libip6tc=y CONFIG_PACKAGE_libxtables=y # CONFIG_PACKAGE_libxtables-nft is not set # end of Firewall # # Instant Messaging # # CONFIG_PACKAGE_quasselc is not set # end of Instant Messaging # # IoT # # CONFIG_PACKAGE_libmraa is not set # CONFIG_PACKAGE_libmraa-node is not set # CONFIG_PACKAGE_libupm-a110x is not set # CONFIG_PACKAGE_libupm-a110x-node is not set # CONFIG_PACKAGE_libupm-abp is not set # CONFIG_PACKAGE_libupm-abp-node is not set # CONFIG_PACKAGE_libupm-ad8232 is not set # CONFIG_PACKAGE_libupm-ad8232-node is not set # CONFIG_PACKAGE_libupm-adafruitms1438 is not set # CONFIG_PACKAGE_libupm-adafruitms1438-node is not set # CONFIG_PACKAGE_libupm-adafruitss is not set # CONFIG_PACKAGE_libupm-adafruitss-node is not set # CONFIG_PACKAGE_libupm-adc121c021 is not set # CONFIG_PACKAGE_libupm-adc121c021-node is not set # CONFIG_PACKAGE_libupm-adis16448 is not set # CONFIG_PACKAGE_libupm-adis16448-node is not set # CONFIG_PACKAGE_libupm-ads1x15 is not set # CONFIG_PACKAGE_libupm-ads1x15-node is not set # CONFIG_PACKAGE_libupm-adxl335 is not set # CONFIG_PACKAGE_libupm-adxl335-node is not set # CONFIG_PACKAGE_libupm-adxl345 is not set # CONFIG_PACKAGE_libupm-adxl345-node is not set # CONFIG_PACKAGE_libupm-adxrs610 is not set # CONFIG_PACKAGE_libupm-adxrs610-node is not set # CONFIG_PACKAGE_libupm-am2315 is not set # CONFIG_PACKAGE_libupm-am2315-node is not set # CONFIG_PACKAGE_libupm-apa102 is not set # CONFIG_PACKAGE_libupm-apa102-node is not set # CONFIG_PACKAGE_libupm-apds9002 is not set # CONFIG_PACKAGE_libupm-apds9002-node is not set # CONFIG_PACKAGE_libupm-apds9930 is not set # CONFIG_PACKAGE_libupm-apds9930-node is not set # CONFIG_PACKAGE_libupm-at42qt1070 is not set # CONFIG_PACKAGE_libupm-at42qt1070-node is not set # CONFIG_PACKAGE_libupm-bh1749 is not set # CONFIG_PACKAGE_libupm-bh1749-node is not set # CONFIG_PACKAGE_libupm-bh1750 is not set # CONFIG_PACKAGE_libupm-bh1750-node is not set # CONFIG_PACKAGE_libupm-bh1792 is not set # CONFIG_PACKAGE_libupm-bh1792-node is not set # CONFIG_PACKAGE_libupm-biss0001 is not set # CONFIG_PACKAGE_libupm-biss0001-node is not set # CONFIG_PACKAGE_libupm-bma220 is not set # CONFIG_PACKAGE_libupm-bma220-node is not set # CONFIG_PACKAGE_libupm-bma250e is not set # CONFIG_PACKAGE_libupm-bma250e-node is not set # CONFIG_PACKAGE_libupm-bmg160 is not set # CONFIG_PACKAGE_libupm-bmg160-node is not set # CONFIG_PACKAGE_libupm-bmi160 is not set # CONFIG_PACKAGE_libupm-bmi160-node is not set # CONFIG_PACKAGE_libupm-bmm150 is not set # CONFIG_PACKAGE_libupm-bmm150-node is not set # CONFIG_PACKAGE_libupm-bmp280 is not set # CONFIG_PACKAGE_libupm-bmp280-node is not set # CONFIG_PACKAGE_libupm-bmpx8x is not set # CONFIG_PACKAGE_libupm-bmpx8x-node is not set # CONFIG_PACKAGE_libupm-bmx055 is not set # CONFIG_PACKAGE_libupm-bmx055-node is not set # CONFIG_PACKAGE_libupm-bno055 is not set # CONFIG_PACKAGE_libupm-bno055-node is not set # CONFIG_PACKAGE_libupm-button is not set # CONFIG_PACKAGE_libupm-button-node is not set # CONFIG_PACKAGE_libupm-buzzer is not set # CONFIG_PACKAGE_libupm-buzzer-node is not set # CONFIG_PACKAGE_libupm-cjq4435 is not set # CONFIG_PACKAGE_libupm-cjq4435-node is not set # CONFIG_PACKAGE_libupm-collision is not set # CONFIG_PACKAGE_libupm-collision-node is not set # CONFIG_PACKAGE_libupm-curieimu is not set # CONFIG_PACKAGE_libupm-curieimu-node is not set # CONFIG_PACKAGE_libupm-cwlsxxa is not set # CONFIG_PACKAGE_libupm-cwlsxxa-node is not set # CONFIG_PACKAGE_libupm-dfrec is not set # CONFIG_PACKAGE_libupm-dfrec-node is not set # CONFIG_PACKAGE_libupm-dfrorp is not set # CONFIG_PACKAGE_libupm-dfrorp-node is not set # CONFIG_PACKAGE_libupm-dfrph is not set # CONFIG_PACKAGE_libupm-dfrph-node is not set # CONFIG_PACKAGE_libupm-ds1307 is not set # CONFIG_PACKAGE_libupm-ds1307-node is not set # CONFIG_PACKAGE_libupm-ds1808lc is not set # CONFIG_PACKAGE_libupm-ds1808lc-node is not set # CONFIG_PACKAGE_libupm-ds18b20 is not set # CONFIG_PACKAGE_libupm-ds18b20-node is not set # CONFIG_PACKAGE_libupm-ds2413 is not set # CONFIG_PACKAGE_libupm-ds2413-node is not set # CONFIG_PACKAGE_libupm-ecezo is not set # CONFIG_PACKAGE_libupm-ecezo-node is not set # CONFIG_PACKAGE_libupm-ecs1030 is not set # CONFIG_PACKAGE_libupm-ecs1030-node is not set # CONFIG_PACKAGE_libupm-ehr is not set # CONFIG_PACKAGE_libupm-ehr-node is not set # CONFIG_PACKAGE_libupm-eldriver is not set # CONFIG_PACKAGE_libupm-eldriver-node is not set # CONFIG_PACKAGE_libupm-electromagnet is not set # CONFIG_PACKAGE_libupm-electromagnet-node is not set # CONFIG_PACKAGE_libupm-emg is not set # CONFIG_PACKAGE_libupm-emg-node is not set # CONFIG_PACKAGE_libupm-enc03r is not set # CONFIG_PACKAGE_libupm-enc03r-node is not set # CONFIG_PACKAGE_libupm-flex is not set # CONFIG_PACKAGE_libupm-flex-node is not set # CONFIG_PACKAGE_libupm-gas is not set # CONFIG_PACKAGE_libupm-gas-node is not set # CONFIG_PACKAGE_libupm-gp2y0a is not set # CONFIG_PACKAGE_libupm-gp2y0a-node is not set # CONFIG_PACKAGE_libupm-gprs is not set # CONFIG_PACKAGE_libupm-gprs-node is not set # CONFIG_PACKAGE_libupm-gsr is not set # CONFIG_PACKAGE_libupm-gsr-node is not set # CONFIG_PACKAGE_libupm-guvas12d is not set # CONFIG_PACKAGE_libupm-guvas12d-node is not set # CONFIG_PACKAGE_libupm-h3lis331dl is not set # CONFIG_PACKAGE_libupm-h3lis331dl-node is not set # CONFIG_PACKAGE_libupm-h803x is not set # CONFIG_PACKAGE_libupm-h803x-node is not set # CONFIG_PACKAGE_libupm-hcsr04 is not set # CONFIG_PACKAGE_libupm-hcsr04-node is not set # CONFIG_PACKAGE_libupm-hdc1000 is not set # CONFIG_PACKAGE_libupm-hdc1000-node is not set # CONFIG_PACKAGE_libupm-hdxxvxta is not set # CONFIG_PACKAGE_libupm-hdxxvxta-node is not set # CONFIG_PACKAGE_libupm-hka5 is not set # CONFIG_PACKAGE_libupm-hka5-node is not set # CONFIG_PACKAGE_libupm-hlg150h is not set # CONFIG_PACKAGE_libupm-hlg150h-node is not set # CONFIG_PACKAGE_libupm-hm11 is not set # CONFIG_PACKAGE_libupm-hm11-node is not set # CONFIG_PACKAGE_libupm-hmc5883l is not set # CONFIG_PACKAGE_libupm-hmc5883l-node is not set # CONFIG_PACKAGE_libupm-hmtrp is not set # CONFIG_PACKAGE_libupm-hmtrp-node is not set # CONFIG_PACKAGE_libupm-hp20x is not set # CONFIG_PACKAGE_libupm-hp20x-node is not set # CONFIG_PACKAGE_libupm-ht9170 is not set # CONFIG_PACKAGE_libupm-ht9170-node is not set # CONFIG_PACKAGE_libupm-htu21d is not set # CONFIG_PACKAGE_libupm-htu21d-node is not set # CONFIG_PACKAGE_libupm-hwxpxx is not set # CONFIG_PACKAGE_libupm-hwxpxx-node is not set # CONFIG_PACKAGE_libupm-hx711 is not set # CONFIG_PACKAGE_libupm-hx711-node is not set # CONFIG_PACKAGE_libupm-ili9341 is not set # CONFIG_PACKAGE_libupm-ili9341-node is not set # CONFIG_PACKAGE_libupm-ims is not set # CONFIG_PACKAGE_libupm-ims-node is not set # CONFIG_PACKAGE_libupm-ina132 is not set # CONFIG_PACKAGE_libupm-ina132-node is not set # CONFIG_PACKAGE_libupm-interfaces is not set # CONFIG_PACKAGE_libupm-interfaces-node is not set # CONFIG_PACKAGE_libupm-isd1820 is not set # CONFIG_PACKAGE_libupm-isd1820-node is not set # CONFIG_PACKAGE_libupm-itg3200 is not set # CONFIG_PACKAGE_libupm-itg3200-node is not set # CONFIG_PACKAGE_libupm-jhd1313m1 is not set # CONFIG_PACKAGE_libupm-jhd1313m1-node is not set # CONFIG_PACKAGE_libupm-joystick12 is not set # CONFIG_PACKAGE_libupm-joystick12-node is not set # CONFIG_PACKAGE_libupm-kx122 is not set # CONFIG_PACKAGE_libupm-kx122-node is not set # CONFIG_PACKAGE_libupm-kxcjk1013 is not set # CONFIG_PACKAGE_libupm-kxcjk1013-node is not set # CONFIG_PACKAGE_libupm-kxtj3 is not set # CONFIG_PACKAGE_libupm-kxtj3-node is not set # CONFIG_PACKAGE_libupm-l298 is not set # CONFIG_PACKAGE_libupm-l298-node is not set # CONFIG_PACKAGE_libupm-l3gd20 is not set # CONFIG_PACKAGE_libupm-l3gd20-node is not set # CONFIG_PACKAGE_libupm-lcd is not set # CONFIG_PACKAGE_libupm-lcd-node is not set # CONFIG_PACKAGE_libupm-lcdks is not set # CONFIG_PACKAGE_libupm-lcdks-node is not set # CONFIG_PACKAGE_libupm-lcm1602 is not set # CONFIG_PACKAGE_libupm-lcm1602-node is not set # CONFIG_PACKAGE_libupm-ldt0028 is not set # CONFIG_PACKAGE_libupm-ldt0028-node is not set # CONFIG_PACKAGE_libupm-led is not set # CONFIG_PACKAGE_libupm-led-node is not set # CONFIG_PACKAGE_libupm-lidarlitev3 is not set # CONFIG_PACKAGE_libupm-lidarlitev3-node is not set # CONFIG_PACKAGE_libupm-light is not set # CONFIG_PACKAGE_libupm-light-node is not set # CONFIG_PACKAGE_libupm-linefinder is not set # CONFIG_PACKAGE_libupm-linefinder-node is not set # CONFIG_PACKAGE_libupm-lis2ds12 is not set # CONFIG_PACKAGE_libupm-lis2ds12-node is not set # CONFIG_PACKAGE_libupm-lis3dh is not set # CONFIG_PACKAGE_libupm-lis3dh-node is not set # CONFIG_PACKAGE_libupm-lm35 is not set # CONFIG_PACKAGE_libupm-lm35-node is not set # CONFIG_PACKAGE_libupm-lol is not set # CONFIG_PACKAGE_libupm-lol-node is not set # CONFIG_PACKAGE_libupm-loudness is not set # CONFIG_PACKAGE_libupm-loudness-node is not set # CONFIG_PACKAGE_libupm-lp8860 is not set # CONFIG_PACKAGE_libupm-lp8860-node is not set # CONFIG_PACKAGE_libupm-lpd8806 is not set # CONFIG_PACKAGE_libupm-lpd8806-node is not set # CONFIG_PACKAGE_libupm-lsm303agr is not set # CONFIG_PACKAGE_libupm-lsm303agr-node is not set # CONFIG_PACKAGE_libupm-lsm303d is not set # CONFIG_PACKAGE_libupm-lsm303d-node is not set # CONFIG_PACKAGE_libupm-lsm303dlh is not set # CONFIG_PACKAGE_libupm-lsm303dlh-node is not set # CONFIG_PACKAGE_libupm-lsm6ds3h is not set # CONFIG_PACKAGE_libupm-lsm6ds3h-node is not set # CONFIG_PACKAGE_libupm-lsm6dsl is not set # CONFIG_PACKAGE_libupm-lsm6dsl-node is not set # CONFIG_PACKAGE_libupm-lsm9ds0 is not set # CONFIG_PACKAGE_libupm-lsm9ds0-node is not set # CONFIG_PACKAGE_libupm-m24lr64e is not set # CONFIG_PACKAGE_libupm-m24lr64e-node is not set # CONFIG_PACKAGE_libupm-mag3110 is not set # CONFIG_PACKAGE_libupm-mag3110-node is not set # CONFIG_PACKAGE_libupm-max30100 is not set # CONFIG_PACKAGE_libupm-max30100-node is not set # CONFIG_PACKAGE_libupm-max31723 is not set # CONFIG_PACKAGE_libupm-max31723-node is not set # CONFIG_PACKAGE_libupm-max31855 is not set # CONFIG_PACKAGE_libupm-max31855-node is not set # CONFIG_PACKAGE_libupm-max44000 is not set # CONFIG_PACKAGE_libupm-max44000-node is not set # CONFIG_PACKAGE_libupm-max44009 is not set # CONFIG_PACKAGE_libupm-max44009-node is not set # CONFIG_PACKAGE_libupm-max5487 is not set # CONFIG_PACKAGE_libupm-max5487-node is not set # CONFIG_PACKAGE_libupm-maxds3231m is not set # CONFIG_PACKAGE_libupm-maxds3231m-node is not set # CONFIG_PACKAGE_libupm-maxsonarez is not set # CONFIG_PACKAGE_libupm-maxsonarez-node is not set # CONFIG_PACKAGE_libupm-mb704x is not set # CONFIG_PACKAGE_libupm-mb704x-node is not set # CONFIG_PACKAGE_libupm-mcp2515 is not set # CONFIG_PACKAGE_libupm-mcp2515-node is not set # CONFIG_PACKAGE_libupm-mcp9808 is not set # CONFIG_PACKAGE_libupm-mcp9808-node is not set # CONFIG_PACKAGE_libupm-md is not set # CONFIG_PACKAGE_libupm-md-node is not set # CONFIG_PACKAGE_libupm-mg811 is not set # CONFIG_PACKAGE_libupm-mg811-node is not set # CONFIG_PACKAGE_libupm-mhz16 is not set # CONFIG_PACKAGE_libupm-mhz16-node is not set # CONFIG_PACKAGE_libupm-mic is not set # CONFIG_PACKAGE_libupm-mic-node is not set # CONFIG_PACKAGE_libupm-micsv89 is not set # CONFIG_PACKAGE_libupm-micsv89-node is not set # CONFIG_PACKAGE_libupm-mlx90614 is not set # CONFIG_PACKAGE_libupm-mlx90614-node is not set # CONFIG_PACKAGE_libupm-mma7361 is not set # CONFIG_PACKAGE_libupm-mma7361-node is not set # CONFIG_PACKAGE_libupm-mma7455 is not set # CONFIG_PACKAGE_libupm-mma7455-node is not set # CONFIG_PACKAGE_libupm-mma7660 is not set # CONFIG_PACKAGE_libupm-mma7660-node is not set # CONFIG_PACKAGE_libupm-mma8x5x is not set # CONFIG_PACKAGE_libupm-mma8x5x-node is not set # CONFIG_PACKAGE_libupm-mmc35240 is not set # CONFIG_PACKAGE_libupm-mmc35240-node is not set # CONFIG_PACKAGE_libupm-moisture is not set # CONFIG_PACKAGE_libupm-moisture-node is not set # CONFIG_PACKAGE_libupm-mpl3115a2 is not set # CONFIG_PACKAGE_libupm-mpl3115a2-node is not set # CONFIG_PACKAGE_libupm-mpr121 is not set # CONFIG_PACKAGE_libupm-mpr121-node is not set # CONFIG_PACKAGE_libupm-mpu9150 is not set # CONFIG_PACKAGE_libupm-mpu9150-node is not set # CONFIG_PACKAGE_libupm-mq303a is not set # CONFIG_PACKAGE_libupm-mq303a-node is not set # CONFIG_PACKAGE_libupm-ms5611 is not set # CONFIG_PACKAGE_libupm-ms5611-node is not set # CONFIG_PACKAGE_libupm-ms5803 is not set # CONFIG_PACKAGE_libupm-ms5803-node is not set # CONFIG_PACKAGE_libupm-my9221 is not set # CONFIG_PACKAGE_libupm-my9221-node is not set # CONFIG_PACKAGE_libupm-nlgpio16 is not set # CONFIG_PACKAGE_libupm-nlgpio16-node is not set # CONFIG_PACKAGE_libupm-nmea_gps is not set # CONFIG_PACKAGE_libupm-nmea_gps-node is not set # CONFIG_PACKAGE_libupm-nrf24l01 is not set # CONFIG_PACKAGE_libupm-nrf24l01-node is not set # CONFIG_PACKAGE_libupm-nrf8001 is not set # CONFIG_PACKAGE_libupm-nrf8001-node is not set # CONFIG_PACKAGE_libupm-nunchuck is not set # CONFIG_PACKAGE_libupm-nunchuck-node is not set # CONFIG_PACKAGE_libupm-o2 is not set # CONFIG_PACKAGE_libupm-o2-node is not set # CONFIG_PACKAGE_libupm-otp538u is not set # CONFIG_PACKAGE_libupm-otp538u-node is not set # CONFIG_PACKAGE_libupm-ozw is not set # CONFIG_PACKAGE_libupm-ozw-node is not set # CONFIG_PACKAGE_libupm-p9813 is not set # CONFIG_PACKAGE_libupm-p9813-node is not set # CONFIG_PACKAGE_libupm-pca9685 is not set # CONFIG_PACKAGE_libupm-pca9685-node is not set # CONFIG_PACKAGE_libupm-pn532 is not set # CONFIG_PACKAGE_libupm-pn532-node is not set # CONFIG_PACKAGE_libupm-ppd42ns is not set # CONFIG_PACKAGE_libupm-ppd42ns-node is not set # CONFIG_PACKAGE_libupm-pulsensor is not set # CONFIG_PACKAGE_libupm-pulsensor-node is not set # CONFIG_PACKAGE_libupm-relay is not set # CONFIG_PACKAGE_libupm-relay-node is not set # CONFIG_PACKAGE_libupm-rf22 is not set # CONFIG_PACKAGE_libupm-rf22-node is not set # CONFIG_PACKAGE_libupm-rfr359f is not set # CONFIG_PACKAGE_libupm-rfr359f-node is not set # CONFIG_PACKAGE_libupm-rgbringcoder is not set # CONFIG_PACKAGE_libupm-rgbringcoder-node is not set # CONFIG_PACKAGE_libupm-rhusb is not set # CONFIG_PACKAGE_libupm-rhusb-node is not set # CONFIG_PACKAGE_libupm-rn2903 is not set # CONFIG_PACKAGE_libupm-rn2903-node is not set # CONFIG_PACKAGE_libupm-rotary is not set # CONFIG_PACKAGE_libupm-rotary-node is not set # CONFIG_PACKAGE_libupm-rotaryencoder is not set # CONFIG_PACKAGE_libupm-rotaryencoder-node is not set # CONFIG_PACKAGE_libupm-rpr220 is not set # CONFIG_PACKAGE_libupm-rpr220-node is not set # CONFIG_PACKAGE_libupm-rsc is not set # CONFIG_PACKAGE_libupm-rsc-node is not set # CONFIG_PACKAGE_libupm-scam is not set # CONFIG_PACKAGE_libupm-scam-node is not set # CONFIG_PACKAGE_libupm-sensortemplate is not set # CONFIG_PACKAGE_libupm-sensortemplate-node is not set # CONFIG_PACKAGE_libupm-servo is not set # CONFIG_PACKAGE_libupm-servo-node is not set # CONFIG_PACKAGE_libupm-sht1x is not set # CONFIG_PACKAGE_libupm-sht1x-node is not set # CONFIG_PACKAGE_libupm-si1132 is not set # CONFIG_PACKAGE_libupm-si1132-node is not set # CONFIG_PACKAGE_libupm-si114x is not set # CONFIG_PACKAGE_libupm-si114x-node is not set # CONFIG_PACKAGE_libupm-si7005 is not set # CONFIG_PACKAGE_libupm-si7005-node is not set # CONFIG_PACKAGE_libupm-slide is not set # CONFIG_PACKAGE_libupm-slide-node is not set # CONFIG_PACKAGE_libupm-sm130 is not set # CONFIG_PACKAGE_libupm-sm130-node is not set # CONFIG_PACKAGE_libupm-smartdrive is not set # CONFIG_PACKAGE_libupm-smartdrive-node is not set # CONFIG_PACKAGE_libupm-speaker is not set # CONFIG_PACKAGE_libupm-speaker-node is not set # CONFIG_PACKAGE_libupm-ssd1351 is not set # CONFIG_PACKAGE_libupm-ssd1351-node is not set # CONFIG_PACKAGE_libupm-st7735 is not set # CONFIG_PACKAGE_libupm-st7735-node is not set # CONFIG_PACKAGE_libupm-stepmotor is not set # CONFIG_PACKAGE_libupm-stepmotor-node is not set # CONFIG_PACKAGE_libupm-sx1276 is not set # CONFIG_PACKAGE_libupm-sx1276-node is not set # CONFIG_PACKAGE_libupm-sx6119 is not set # CONFIG_PACKAGE_libupm-sx6119-node is not set # CONFIG_PACKAGE_libupm-t3311 is not set # CONFIG_PACKAGE_libupm-t3311-node is not set # CONFIG_PACKAGE_libupm-t6713 is not set # CONFIG_PACKAGE_libupm-t6713-node is not set # CONFIG_PACKAGE_libupm-ta12200 is not set # CONFIG_PACKAGE_libupm-ta12200-node is not set # CONFIG_PACKAGE_libupm-tca9548a is not set # CONFIG_PACKAGE_libupm-tca9548a-node is not set # CONFIG_PACKAGE_libupm-tcs3414cs is not set # CONFIG_PACKAGE_libupm-tcs3414cs-node is not set # CONFIG_PACKAGE_libupm-tcs37727 is not set # CONFIG_PACKAGE_libupm-tcs37727-node is not set # CONFIG_PACKAGE_libupm-teams is not set # CONFIG_PACKAGE_libupm-teams-node is not set # CONFIG_PACKAGE_libupm-temperature is not set # CONFIG_PACKAGE_libupm-temperature-node is not set # CONFIG_PACKAGE_libupm-tex00 is not set # CONFIG_PACKAGE_libupm-tex00-node is not set # CONFIG_PACKAGE_libupm-th02 is not set # CONFIG_PACKAGE_libupm-th02-node is not set # CONFIG_PACKAGE_libupm-tm1637 is not set # CONFIG_PACKAGE_libupm-tm1637-node is not set # CONFIG_PACKAGE_libupm-tmp006 is not set # CONFIG_PACKAGE_libupm-tmp006-node is not set # CONFIG_PACKAGE_libupm-tsl2561 is not set # CONFIG_PACKAGE_libupm-tsl2561-node is not set # CONFIG_PACKAGE_libupm-ttp223 is not set # CONFIG_PACKAGE_libupm-ttp223-node is not set # CONFIG_PACKAGE_libupm-uartat is not set # CONFIG_PACKAGE_libupm-uartat-node is not set # CONFIG_PACKAGE_libupm-uln200xa is not set # CONFIG_PACKAGE_libupm-uln200xa-node is not set # CONFIG_PACKAGE_libupm-ultrasonic is not set # CONFIG_PACKAGE_libupm-ultrasonic-node is not set # CONFIG_PACKAGE_libupm-urm37 is not set # CONFIG_PACKAGE_libupm-urm37-node is not set # CONFIG_PACKAGE_libupm-utilities is not set # CONFIG_PACKAGE_libupm-utilities-node is not set # CONFIG_PACKAGE_libupm-vcap is not set # CONFIG_PACKAGE_libupm-vcap-node is not set # CONFIG_PACKAGE_libupm-vdiv is not set # CONFIG_PACKAGE_libupm-vdiv-node is not set # CONFIG_PACKAGE_libupm-veml6070 is not set # CONFIG_PACKAGE_libupm-veml6070-node is not set # CONFIG_PACKAGE_libupm-water is not set # CONFIG_PACKAGE_libupm-water-node is not set # CONFIG_PACKAGE_libupm-waterlevel is not set # CONFIG_PACKAGE_libupm-waterlevel-node is not set # CONFIG_PACKAGE_libupm-wfs is not set # CONFIG_PACKAGE_libupm-wfs-node is not set # CONFIG_PACKAGE_libupm-wheelencoder is not set # CONFIG_PACKAGE_libupm-wheelencoder-node is not set # CONFIG_PACKAGE_libupm-wt5001 is not set # CONFIG_PACKAGE_libupm-wt5001-node is not set # CONFIG_PACKAGE_libupm-xbee is not set # CONFIG_PACKAGE_libupm-xbee-node is not set # CONFIG_PACKAGE_libupm-yg1006 is not set # CONFIG_PACKAGE_libupm-yg1006-node is not set # CONFIG_PACKAGE_libupm-zfm20 is not set # CONFIG_PACKAGE_libupm-zfm20-node is not set # end of IoT # # Languages # # CONFIG_PACKAGE_libyaml is not set # end of Languages # # LibElektra # # CONFIG_PACKAGE_libelektra-boost is not set # CONFIG_PACKAGE_libelektra-core is not set # CONFIG_PACKAGE_libelektra-cpp is not set # CONFIG_PACKAGE_libelektra-crypto is not set # CONFIG_PACKAGE_libelektra-curlget is not set # CONFIG_PACKAGE_libelektra-dbus is not set # CONFIG_PACKAGE_libelektra-extra is not set # CONFIG_PACKAGE_libelektra-lua is not set # CONFIG_PACKAGE_libelektra-plugins is not set # CONFIG_PACKAGE_libelektra-python3 is not set # CONFIG_PACKAGE_libelektra-resolvers is not set # CONFIG_PACKAGE_libelektra-xerces is not set # CONFIG_PACKAGE_libelektra-xml is not set # CONFIG_PACKAGE_libelektra-yajl is not set # CONFIG_PACKAGE_libelektra-yamlcpp is not set # CONFIG_PACKAGE_libelektra-zmq is not set # end of LibElektra # # Networking # # CONFIG_PACKAGE_libdcwproto is not set # CONFIG_PACKAGE_libdcwsocket is not set # CONFIG_PACKAGE_libsctp is not set # CONFIG_PACKAGE_libuhttpd-mbedtls is not set # CONFIG_PACKAGE_libuhttpd-nossl is not set # CONFIG_PACKAGE_libuhttpd-openssl is not set # CONFIG_PACKAGE_libuhttpd-wolfssl is not set # CONFIG_PACKAGE_libulfius-gnutls is not set # CONFIG_PACKAGE_libulfius-nossl is not set # CONFIG_PACKAGE_libunbound is not set # CONFIG_PACKAGE_libuwsc-mbedtls is not set # CONFIG_PACKAGE_libuwsc-nossl is not set # CONFIG_PACKAGE_libuwsc-openssl is not set # CONFIG_PACKAGE_libuwsc-wolfssl is not set # end of Networking # # Qt5 # # CONFIG_PACKAGE_qt5-core is not set # CONFIG_PACKAGE_qt5-network is not set # CONFIG_PACKAGE_qt5-sql is not set # CONFIG_PACKAGE_qt5-xml is not set # end of Qt5 # # SSL # # CONFIG_PACKAGE_libgnutls is not set CONFIG_PACKAGE_libmbedtls=y # CONFIG_LIBMBEDTLS_DEBUG_C is not set # CONFIG_PACKAGE_libnss is not set CONFIG_PACKAGE_libopenssl=y # # Build Options # CONFIG_OPENSSL_OPTIMIZE_SPEED=y CONFIG_OPENSSL_WITH_ASM=y CONFIG_OPENSSL_WITH_DEPRECATED=y # CONFIG_OPENSSL_NO_DEPRECATED is not set CONFIG_OPENSSL_WITH_ERROR_MESSAGES=y # # Protocol Support # CONFIG_OPENSSL_WITH_TLS13=y # CONFIG_OPENSSL_WITH_DTLS is not set # CONFIG_OPENSSL_WITH_NPN is not set CONFIG_OPENSSL_WITH_SRP=y CONFIG_OPENSSL_WITH_CMS=y # # Algorithm Selection # # CONFIG_OPENSSL_WITH_EC2M is not set CONFIG_OPENSSL_WITH_CHACHA_POLY1305=y CONFIG_OPENSSL_PREFER_CHACHA_OVER_GCM=y CONFIG_OPENSSL_WITH_PSK=y # # Less commonly used build options # # CONFIG_OPENSSL_WITH_ARIA is not set # CONFIG_OPENSSL_WITH_CAMELLIA is not set # CONFIG_OPENSSL_WITH_IDEA is not set # CONFIG_OPENSSL_WITH_SEED is not set # CONFIG_OPENSSL_WITH_SM234 is not set # CONFIG_OPENSSL_WITH_BLAKE2 is not set # CONFIG_OPENSSL_WITH_MDC2 is not set # CONFIG_OPENSSL_WITH_WHIRLPOOL is not set # CONFIG_OPENSSL_WITH_COMPRESSION is not set # CONFIG_OPENSSL_WITH_RFC3779 is not set # # Engine/Hardware Support # CONFIG_OPENSSL_ENGINE=y CONFIG_OPENSSL_ENGINE_BUILTIN=y CONFIG_OPENSSL_ENGINE_BUILTIN_AFALG=y CONFIG_OPENSSL_ENGINE_BUILTIN_DEVCRYPTO=y # CONFIG_OPENSSL_WITH_GOST is not set CONFIG_PACKAGE_libopenssl-conf=y # CONFIG_PACKAGE_libopenssl-devcrypto is not set # CONFIG_PACKAGE_libpolarssl is not set # CONFIG_PACKAGE_libwolfssl is not set # end of SSL # # Sound # # CONFIG_PACKAGE_liblo is not set # end of Sound # # Telephony # # CONFIG_PACKAGE_bcg729 is not set # CONFIG_PACKAGE_gsmlib is not set # CONFIG_PACKAGE_libctb is not set # CONFIG_PACKAGE_libfreetdm is not set # CONFIG_PACKAGE_libiksemel is not set # CONFIG_PACKAGE_libks is not set # CONFIG_PACKAGE_libosip2 is not set # CONFIG_PACKAGE_libpj is not set # CONFIG_PACKAGE_libpjlib-util is not set # CONFIG_PACKAGE_libpjmedia is not set # CONFIG_PACKAGE_libpjnath is not set # CONFIG_PACKAGE_libpjsip is not set # CONFIG_PACKAGE_libpjsip-simple is not set # CONFIG_PACKAGE_libpjsip-ua is not set # CONFIG_PACKAGE_libpjsua is not set # CONFIG_PACKAGE_libpjsua2 is not set # CONFIG_PACKAGE_libre is not set # CONFIG_PACKAGE_librem is not set # CONFIG_PACKAGE_libspandsp is not set # CONFIG_PACKAGE_libspandsp3 is not set # CONFIG_PACKAGE_libsrtp2 is not set # CONFIG_PACKAGE_signalwire-client-c is not set # CONFIG_PACKAGE_sofia-sip is not set # end of Telephony # # libimobiledevice # # CONFIG_PACKAGE_libimobiledevice is not set # CONFIG_PACKAGE_libirecovery is not set # CONFIG_PACKAGE_libplist is not set # CONFIG_PACKAGE_libplistcxx is not set # CONFIG_PACKAGE_libusbmuxd is not set # end of libimobiledevice # CONFIG_PACKAGE_alsa-lib is not set # CONFIG_PACKAGE_argp-standalone is not set # CONFIG_PACKAGE_bind-libs is not set # CONFIG_PACKAGE_bluez-libs is not set # CONFIG_PACKAGE_boost is not set # CONFIG_boost-context-exclude is not set # CONFIG_boost-coroutine-exclude is not set # CONFIG_boost-fiber-exclude is not set # CONFIG_PACKAGE_ccid is not set # CONFIG_PACKAGE_check is not set # CONFIG_PACKAGE_confuse is not set # CONFIG_PACKAGE_czmq is not set # CONFIG_PACKAGE_dtndht is not set # CONFIG_PACKAGE_getdns is not set # CONFIG_PACKAGE_giflib is not set # CONFIG_PACKAGE_glib2 is not set # CONFIG_PACKAGE_google-authenticator-libpam is not set # CONFIG_PACKAGE_hidapi is not set # CONFIG_PACKAGE_ibrcommon is not set # CONFIG_PACKAGE_ibrdtn is not set # CONFIG_PACKAGE_icu is not set # CONFIG_PACKAGE_icu-data-tools is not set # CONFIG_PACKAGE_icu-full-data is not set # CONFIG_PACKAGE_jansson is not set # CONFIG_PACKAGE_json-glib is not set # CONFIG_PACKAGE_jsoncpp is not set # CONFIG_PACKAGE_knot-libs is not set # CONFIG_PACKAGE_knot-libzscanner is not set # CONFIG_PACKAGE_libaio is not set # CONFIG_PACKAGE_libantlr3c is not set # CONFIG_PACKAGE_libao is not set # CONFIG_PACKAGE_libapr is not set # CONFIG_PACKAGE_libaprutil is not set # CONFIG_PACKAGE_libarchive is not set # CONFIG_PACKAGE_libarchive-noopenssl is not set # CONFIG_PACKAGE_libasm is not set # CONFIG_PACKAGE_libavahi-client is not set # CONFIG_PACKAGE_libavahi-compat-libdnssd is not set # CONFIG_PACKAGE_libavahi-dbus-support is not set # CONFIG_PACKAGE_libavahi-nodbus-support is not set # CONFIG_PACKAGE_libbfd is not set # CONFIG_PACKAGE_libblkid is not set CONFIG_PACKAGE_libblobmsg-json=y # CONFIG_PACKAGE_libbsd is not set CONFIG_PACKAGE_libcap=y # CONFIG_PACKAGE_libcap-bin is not set # CONFIG_PACKAGE_libcap-ng is not set # CONFIG_PACKAGE_libcares is not set # CONFIG_PACKAGE_libcgroup is not set # CONFIG_PACKAGE_libcharset is not set # CONFIG_PACKAGE_libcoap is not set # CONFIG_PACKAGE_libcomerr is not set # CONFIG_PACKAGE_libconfig is not set # CONFIG_PACKAGE_libcryptopp is not set # CONFIG_PACKAGE_libcups is not set # CONFIG_PACKAGE_libcurl is not set # CONFIG_PACKAGE_libcxx is not set # CONFIG_PACKAGE_libdaemon is not set # CONFIG_PACKAGE_libdaq is not set # CONFIG_PACKAGE_libdb47 is not set # CONFIG_PACKAGE_libdb47xx is not set # CONFIG_PACKAGE_libdbi is not set # CONFIG_PACKAGE_libdbus is not set # CONFIG_PACKAGE_libdevmapper is not set # CONFIG_PACKAGE_libdmapsharing is not set # CONFIG_PACKAGE_libdnet is not set # CONFIG_PACKAGE_libdouble-conversion is not set # CONFIG_PACKAGE_libdrm is not set # CONFIG_PACKAGE_libdw is not set # CONFIG_PACKAGE_libecdsautil is not set # CONFIG_PACKAGE_libedit is not set CONFIG_PACKAGE_libelf=y # CONFIG_PACKAGE_libesmtp is not set # CONFIG_PACKAGE_libestr is not set CONFIG_PACKAGE_libev=y # CONFIG_PACKAGE_libevdev is not set # CONFIG_PACKAGE_libevent2 is not set # CONFIG_PACKAGE_libevent2-core is not set # CONFIG_PACKAGE_libevent2-extra is not set # CONFIG_PACKAGE_libevent2-openssl is not set # CONFIG_PACKAGE_libevent2-pthreads is not set # CONFIG_PACKAGE_libevhtp is not set # CONFIG_LIBEVHTP_BUILD_DEPENDS is not set # CONFIG_PACKAGE_libexif is not set # CONFIG_PACKAGE_libexpat is not set # CONFIG_PACKAGE_libexslt is not set # CONFIG_PACKAGE_libext2fs is not set # CONFIG_PACKAGE_libextractor is not set # CONFIG_PACKAGE_libf2fs is not set # CONFIG_PACKAGE_libfaad2 is not set # CONFIG_PACKAGE_libfastjson is not set # CONFIG_PACKAGE_libfdisk is not set # CONFIG_PACKAGE_libfdt is not set # CONFIG_PACKAGE_libffi is not set # CONFIG_PACKAGE_libffmpeg-audio-dec is not set # CONFIG_PACKAGE_libffmpeg-custom is not set # CONFIG_PACKAGE_libffmpeg-full is not set # CONFIG_PACKAGE_libffmpeg-mini is not set # CONFIG_PACKAGE_libflac is not set # CONFIG_PACKAGE_libfmt is not set # CONFIG_PACKAGE_libfreetype is not set # CONFIG_PACKAGE_libfstrm is not set # CONFIG_PACKAGE_libftdi is not set # CONFIG_PACKAGE_libftdi1 is not set # CONFIG_PACKAGE_libgabe is not set # CONFIG_PACKAGE_libgcrypt is not set # CONFIG_PACKAGE_libgd is not set # CONFIG_PACKAGE_libgd-full is not set # CONFIG_PACKAGE_libgdbm is not set # CONFIG_PACKAGE_libgee is not set # CONFIG_PACKAGE_libgmp is not set # CONFIG_PACKAGE_libgnurl is not set # CONFIG_PACKAGE_libgpg-error is not set # CONFIG_PACKAGE_libgphoto2 is not set # CONFIG_PACKAGE_libgpiod is not set # CONFIG_PACKAGE_libgps is not set # CONFIG_PACKAGE_libh2o is not set # CONFIG_PACKAGE_libh2o-evloop is not set # CONFIG_PACKAGE_libhamlib is not set # CONFIG_PACKAGE_libhavege is not set # CONFIG_PACKAGE_libhiredis is not set # CONFIG_PACKAGE_libhttp-parser is not set # CONFIG_PACKAGE_libhwloc is not set # CONFIG_PACKAGE_libi2c is not set # CONFIG_PACKAGE_libical is not set # CONFIG_PACKAGE_libiconv is not set # CONFIG_PACKAGE_libiconv-full is not set # CONFIG_PACKAGE_libid3tag is not set # CONFIG_PACKAGE_libidn is not set # CONFIG_PACKAGE_libidn2 is not set # CONFIG_PACKAGE_libiio is not set # CONFIG_PACKAGE_libinotifytools is not set # CONFIG_PACKAGE_libinput is not set # CONFIG_PACKAGE_libintl is not set # CONFIG_PACKAGE_libintl-full is not set # CONFIG_PACKAGE_libipfs-http-client is not set # CONFIG_PACKAGE_libiw is not set CONFIG_PACKAGE_libiwinfo=y # CONFIG_PACKAGE_libjpeg-turbo is not set CONFIG_PACKAGE_libjson-c=y # CONFIG_PACKAGE_libkeyutils is not set # CONFIG_PACKAGE_libkmod is not set # CONFIG_PACKAGE_libldns is not set # CONFIG_PACKAGE_libleptonica is not set # CONFIG_PACKAGE_libloragw is not set # CONFIG_PACKAGE_libltdl is not set CONFIG_PACKAGE_liblua=y # CONFIG_PACKAGE_liblua5.3 is not set # CONFIG_PACKAGE_liblzo is not set # CONFIG_PACKAGE_libmad is not set # CONFIG_PACKAGE_libmagic is not set # CONFIG_PACKAGE_libmaxminddb is not set # CONFIG_PACKAGE_libmbim is not set # CONFIG_PACKAGE_libmcrypt is not set # CONFIG_PACKAGE_libmicrohttpd-no-ssl is not set # CONFIG_PACKAGE_libmicrohttpd-ssl is not set # CONFIG_PACKAGE_libmilter-sendmail is not set # CONFIG_PACKAGE_libminiupnpc is not set # CONFIG_PACKAGE_libmms is not set CONFIG_PACKAGE_libmnl=y # CONFIG_PACKAGE_libmodbus is not set # CONFIG_PACKAGE_libmosquitto-nossl is not set # CONFIG_PACKAGE_libmosquitto-ssl is not set # CONFIG_PACKAGE_libmount is not set # CONFIG_PACKAGE_libmpdclient is not set # CONFIG_PACKAGE_libmpeg2 is not set # CONFIG_PACKAGE_libmpg123 is not set # CONFIG_PACKAGE_libnatpmp is not set CONFIG_PACKAGE_libncurses=y # CONFIG_PACKAGE_libndpi is not set # CONFIG_PACKAGE_libneon is not set # CONFIG_PACKAGE_libnet-1.2.x is not set # CONFIG_PACKAGE_libnetconf2 is not set # CONFIG_PACKAGE_libnetfilter-acct is not set # CONFIG_PACKAGE_libnetfilter-conntrack is not set # CONFIG_PACKAGE_libnetfilter-cthelper is not set # CONFIG_PACKAGE_libnetfilter-cttimeout is not set # CONFIG_PACKAGE_libnetfilter-log is not set # CONFIG_PACKAGE_libnetfilter-queue is not set # CONFIG_PACKAGE_libnetsnmp is not set # CONFIG_PACKAGE_libnettle is not set # CONFIG_PACKAGE_libnewt is not set # CONFIG_PACKAGE_libnfnetlink is not set # CONFIG_PACKAGE_libnftnl is not set # CONFIG_PACKAGE_libnghttp2 is not set # CONFIG_PACKAGE_libnl is not set # CONFIG_PACKAGE_libnl-core is not set # CONFIG_PACKAGE_libnl-genl is not set # CONFIG_PACKAGE_libnl-nf is not set # CONFIG_PACKAGE_libnl-route is not set CONFIG_PACKAGE_libnl-tiny=y # CONFIG_PACKAGE_libnopoll is not set # CONFIG_PACKAGE_libnpupnp is not set # CONFIG_PACKAGE_libogg is not set # CONFIG_PACKAGE_liboil is not set # CONFIG_PACKAGE_libopcodes is not set # CONFIG_PACKAGE_libopendkim is not set # CONFIG_PACKAGE_libopenobex is not set # CONFIG_PACKAGE_libopensc is not set # CONFIG_PACKAGE_libopenzwave is not set # CONFIG_PACKAGE_liboping is not set # CONFIG_PACKAGE_libopus is not set # CONFIG_PACKAGE_libopusenc is not set # CONFIG_PACKAGE_libopusfile is not set # CONFIG_PACKAGE_liborcania is not set # CONFIG_PACKAGE_libout123 is not set # CONFIG_PACKAGE_libowfat is not set # CONFIG_PACKAGE_libp11 is not set # CONFIG_PACKAGE_libpagekite is not set # CONFIG_PACKAGE_libpam is not set # CONFIG_PACKAGE_libpbc is not set # CONFIG_PACKAGE_libpcap is not set # CONFIG_PACKAGE_libpci is not set # CONFIG_PACKAGE_libpciaccess is not set CONFIG_PACKAGE_libpcre=y # CONFIG_PCRE_JIT_ENABLED is not set # CONFIG_PACKAGE_libpcre16 is not set # CONFIG_PACKAGE_libpcre2 is not set # CONFIG_PACKAGE_libpcre2-16 is not set # CONFIG_PACKAGE_libpcre2-32 is not set # CONFIG_PACKAGE_libpcre32 is not set # CONFIG_PACKAGE_libpcrecpp is not set # CONFIG_PACKAGE_libpcsclite is not set # CONFIG_PACKAGE_libpfring is not set # CONFIG_PACKAGE_libpkcs11-spy is not set # CONFIG_PACKAGE_libpkgconf is not set # CONFIG_PACKAGE_libpng is not set # CONFIG_PACKAGE_libpopt is not set # CONFIG_PACKAGE_libprotobuf-c is not set # CONFIG_PACKAGE_libpsl is not set # CONFIG_PACKAGE_libqmi is not set # CONFIG_PACKAGE_libqrencode is not set # CONFIG_PACKAGE_libradcli is not set # CONFIG_PACKAGE_libradiotap is not set # CONFIG_PACKAGE_libreadline is not set # CONFIG_PACKAGE_libredblack is not set # CONFIG_PACKAGE_librouteros is not set # CONFIG_PACKAGE_libroxml is not set # CONFIG_PACKAGE_librrd1 is not set # CONFIG_PACKAGE_librtlsdr is not set # CONFIG_PACKAGE_libruby is not set # CONFIG_PACKAGE_libsamplerate is not set # CONFIG_PACKAGE_libsane is not set # CONFIG_PACKAGE_libsasl2 is not set # CONFIG_PACKAGE_libsearpc is not set # CONFIG_PACKAGE_libseccomp is not set # CONFIG_PACKAGE_libselinux is not set # CONFIG_PACKAGE_libsensors is not set # CONFIG_PACKAGE_libsepol is not set # CONFIG_PACKAGE_libshout is not set # CONFIG_PACKAGE_libshout-full is not set # CONFIG_PACKAGE_libshout-nossl is not set # CONFIG_PACKAGE_libsispmctl is not set # CONFIG_PACKAGE_libslang2 is not set # CONFIG_PACKAGE_libslang2-mod-base64 is not set # CONFIG_PACKAGE_libslang2-mod-chksum is not set # CONFIG_PACKAGE_libslang2-mod-csv is not set # CONFIG_PACKAGE_libslang2-mod-fcntl is not set # CONFIG_PACKAGE_libslang2-mod-fork is not set # CONFIG_PACKAGE_libslang2-mod-histogram is not set # CONFIG_PACKAGE_libslang2-mod-iconv is not set # CONFIG_PACKAGE_libslang2-mod-json is not set # CONFIG_PACKAGE_libslang2-mod-onig is not set # CONFIG_PACKAGE_libslang2-mod-pcre is not set # CONFIG_PACKAGE_libslang2-mod-png is not set # CONFIG_PACKAGE_libslang2-mod-rand is not set # CONFIG_PACKAGE_libslang2-mod-select is not set # CONFIG_PACKAGE_libslang2-mod-slsmg is not set # CONFIG_PACKAGE_libslang2-mod-socket is not set # CONFIG_PACKAGE_libslang2-mod-stats is not set # CONFIG_PACKAGE_libslang2-mod-sysconf is not set # CONFIG_PACKAGE_libslang2-mod-termios is not set # CONFIG_PACKAGE_libslang2-mod-varray is not set # CONFIG_PACKAGE_libslang2-mod-zlib is not set # CONFIG_PACKAGE_libslang2-modules is not set # CONFIG_PACKAGE_libsmartcols is not set # CONFIG_PACKAGE_libsndfile is not set # CONFIG_PACKAGE_libsoc is not set # CONFIG_PACKAGE_libsocks is not set CONFIG_PACKAGE_libsodium=y # # Configuration # CONFIG_LIBSODIUM_MINIMAL=y # end of Configuration # CONFIG_PACKAGE_libsoup is not set # CONFIG_PACKAGE_libsoxr is not set # CONFIG_PACKAGE_libspeex is not set # CONFIG_PACKAGE_libspeexdsp is not set # CONFIG_PACKAGE_libspice-server is not set # CONFIG_PACKAGE_libss is not set # CONFIG_PACKAGE_libssh is not set # CONFIG_PACKAGE_libssh2 is not set # CONFIG_PACKAGE_libstoken is not set # CONFIG_PACKAGE_libstrophe is not set # CONFIG_PACKAGE_libsysrepo is not set # CONFIG_PACKAGE_libtalloc is not set # CONFIG_PACKAGE_libtasn1 is not set # CONFIG_PACKAGE_libtheora is not set # CONFIG_PACKAGE_libtiff is not set # CONFIG_PACKAGE_libtiffxx is not set # CONFIG_PACKAGE_libtins is not set # CONFIG_PACKAGE_libtirpc is not set # CONFIG_PACKAGE_libtorrent is not set CONFIG_PACKAGE_libubox=y # CONFIG_PACKAGE_libubox-lua is not set CONFIG_PACKAGE_libubus=y CONFIG_PACKAGE_libubus-lua=y CONFIG_PACKAGE_libuci=y CONFIG_PACKAGE_libuci-lua=y CONFIG_PACKAGE_libuclient=y # CONFIG_PACKAGE_libudev-fbsd is not set # CONFIG_PACKAGE_libudns is not set # CONFIG_PACKAGE_libuecc is not set # CONFIG_PACKAGE_libugpio is not set # CONFIG_PACKAGE_libunistring is not set # CONFIG_PACKAGE_libunwind is not set # CONFIG_PACKAGE_libupnp is not set # CONFIG_PACKAGE_libupnpp is not set # CONFIG_PACKAGE_liburcu is not set # CONFIG_PACKAGE_liburing is not set # CONFIG_PACKAGE_libusb-1.0 is not set # CONFIG_PACKAGE_libusb-compat is not set # CONFIG_PACKAGE_libustream-mbedtls is not set CONFIG_PACKAGE_libustream-openssl=y # CONFIG_PACKAGE_libustream-wolfssl is not set CONFIG_PACKAGE_libuuid=y CONFIG_PACKAGE_libuv=y # CONFIG_PACKAGE_libuwifi is not set # CONFIG_PACKAGE_libv4l is not set # CONFIG_PACKAGE_libvorbis is not set # CONFIG_PACKAGE_libvorbisidec is not set # CONFIG_PACKAGE_libvpx is not set # CONFIG_PACKAGE_libwebcam is not set # CONFIG_PACKAGE_libwebp is not set CONFIG_PACKAGE_libwebsockets-full=y # CONFIG_PACKAGE_libwebsockets-mbedtls is not set # CONFIG_PACKAGE_libwebsockets-openssl is not set # CONFIG_PACKAGE_libwrap is not set # CONFIG_PACKAGE_libwslay is not set # CONFIG_PACKAGE_libwxbase is not set # CONFIG_PACKAGE_libxerces-c is not set # CONFIG_PACKAGE_libxerces-c-samples is not set # CONFIG_PACKAGE_libxml2 is not set # CONFIG_PACKAGE_libxslt is not set # CONFIG_PACKAGE_libyaml-cpp is not set # CONFIG_PACKAGE_libyang is not set # CONFIG_PACKAGE_libyang-cpp is not set # CONFIG_PACKAGE_libyubikey is not set # CONFIG_PACKAGE_libzmq-curve is not set # CONFIG_PACKAGE_libzmq-nc is not set # CONFIG_PACKAGE_linux-atm is not set # CONFIG_PACKAGE_lmdb is not set # CONFIG_PACKAGE_log4cplus is not set # CONFIG_PACKAGE_loudmouth is not set # CONFIG_PACKAGE_lttng-ust is not set # CONFIG_PACKAGE_measurement-kit is not set # CONFIG_MEASUREMENT_KIT_BUILD_DEPENDS is not set # CONFIG_PACKAGE_minizip is not set # CONFIG_PACKAGE_mtdev is not set # CONFIG_PACKAGE_musl-fts is not set # CONFIG_PACKAGE_mxml is not set # CONFIG_PACKAGE_nacl is not set # CONFIG_PACKAGE_nlohmannjson is not set # CONFIG_PACKAGE_nspr is not set # CONFIG_PACKAGE_oniguruma is not set # CONFIG_PACKAGE_open-isns is not set # CONFIG_PACKAGE_p11-kit is not set # CONFIG_PACKAGE_pixman is not set # CONFIG_PACKAGE_poco is not set # CONFIG_PACKAGE_poco-all is not set # CONFIG_PACKAGE_protobuf is not set # CONFIG_PACKAGE_protobuf-lite is not set # CONFIG_PACKAGE_pthsem is not set # CONFIG_PACKAGE_rblibtorrent is not set # CONFIG_PACKAGE_re2 is not set CONFIG_PACKAGE_rpcd-mod-rrdns=y # CONFIG_PACKAGE_sbc is not set # CONFIG_PACKAGE_serdisplib is not set # CONFIG_PACKAGE_spice-protocol is not set CONFIG_PACKAGE_terminfo=y # CONFIG_PACKAGE_tinycdb is not set # CONFIG_PACKAGE_uclibcxx is not set # CONFIG_PACKAGE_uw-imap is not set # CONFIG_PACKAGE_xmlrpc-c is not set # CONFIG_PACKAGE_xmlrpc-c-client is not set # CONFIG_PACKAGE_xmlrpc-c-server is not set # CONFIG_PACKAGE_yajl is not set # CONFIG_PACKAGE_yubico-pam is not set CONFIG_PACKAGE_zlib=y # # Configuration # # CONFIG_ZLIB_OPTIMIZE_SPEED is not set # end of Configuration # end of Libraries # # LuCI # # # 1. Collections # CONFIG_PACKAGE_luci=y # CONFIG_PACKAGE_luci-nginx is not set # CONFIG_PACKAGE_luci-ssl-nginx is not set # CONFIG_PACKAGE_luci-ssl-openssl is not set # end of 1. Collections # # 2. Modules # CONFIG_PACKAGE_luci-base=y # CONFIG_LUCI_SRCDIET is not set # # Translations # # CONFIG_LUCI_LANG_hu is not set # CONFIG_LUCI_LANG_pt is not set # CONFIG_LUCI_LANG_no is not set # CONFIG_LUCI_LANG_sk is not set # CONFIG_LUCI_LANG_el is not set # CONFIG_LUCI_LANG_uk is not set # CONFIG_LUCI_LANG_ru is not set # CONFIG_LUCI_LANG_vi is not set # CONFIG_LUCI_LANG_de is not set # CONFIG_LUCI_LANG_ro is not set # CONFIG_LUCI_LANG_ms is not set # CONFIG_LUCI_LANG_pl is not set CONFIG_LUCI_LANG_zh-cn=y # CONFIG_LUCI_LANG_ko is not set # CONFIG_LUCI_LANG_he is not set # CONFIG_LUCI_LANG_zh-tw is not set # CONFIG_LUCI_LANG_tr is not set # CONFIG_LUCI_LANG_sv is not set # CONFIG_LUCI_LANG_ja is not set # CONFIG_LUCI_LANG_pt-br is not set # CONFIG_LUCI_LANG_ca is not set # CONFIG_LUCI_LANG_en is not set # CONFIG_LUCI_LANG_es is not set # CONFIG_LUCI_LANG_cs is not set # CONFIG_LUCI_LANG_fr is not set # CONFIG_LUCI_LANG_it is not set # end of Translations CONFIG_PACKAGE_luci-compat=y CONFIG_PACKAGE_luci-mod-admin-full=y # CONFIG_PACKAGE_luci-mod-failsafe is not set # CONFIG_PACKAGE_luci-mod-freifunk is not set # CONFIG_PACKAGE_luci-mod-freifunk-community is not set # CONFIG_PACKAGE_luci-mod-rpc is not set # end of 2. Modules # # 3. Applications # # CONFIG_PACKAGE_luci-app-accesscontrol is not set # CONFIG_PACKAGE_luci-app-adblock is not set CONFIG_PACKAGE_luci-app-adbyby-plus=y # CONFIG_PACKAGE_luci-app-advanced-reboot is not set # CONFIG_PACKAGE_luci-app-ahcp is not set # CONFIG_PACKAGE_luci-app-airplay2 is not set # CONFIG_PACKAGE_luci-app-amule is not set # CONFIG_PACKAGE_luci-app-aria2 is not set # CONFIG_PACKAGE_luci-app-arpbind is not set # CONFIG_PACKAGE_luci-app-asterisk is not set # CONFIG_PACKAGE_luci-app-attendedsysupgrade is not set # CONFIG_PACKAGE_luci-app-autoreboot is not set # CONFIG_PACKAGE_luci-app-baidupcs-web is not set # CONFIG_PACKAGE_luci-app-bcp38 is not set # CONFIG_PACKAGE_luci-app-bird1-ipv4 is not set # CONFIG_PACKAGE_luci-app-bird1-ipv6 is not set # CONFIG_PACKAGE_luci-app-bmx6 is not set # CONFIG_PACKAGE_luci-app-cifs-mount is not set # CONFIG_PACKAGE_luci-app-cifsd is not set # CONFIG_PACKAGE_luci-app-cjdns is not set # CONFIG_PACKAGE_luci-app-clamav is not set # CONFIG_PACKAGE_luci-app-commands is not set # CONFIG_PACKAGE_luci-app-cshark is not set # CONFIG_PACKAGE_luci-app-ddns is not set # CONFIG_PACKAGE_luci-app-diag-core is not set # CONFIG_PACKAGE_luci-app-diskman is not set # CONFIG_PACKAGE_luci-app-diskman_INCLUDE_btrfs_progs is not set # CONFIG_PACKAGE_luci-app-diskman_INCLUDE_lsblk is not set # CONFIG_PACKAGE_luci-app-diskman_INCLUDE_mdadm is not set # CONFIG_PACKAGE_luci-app-dnscrypt-proxy is not set # CONFIG_PACKAGE_luci-app-dnsforwarder is not set # CONFIG_PACKAGE_luci-app-dump1090 is not set # CONFIG_PACKAGE_luci-app-dynapoint is not set # CONFIG_PACKAGE_luci-app-e2guardian is not set # CONFIG_PACKAGE_luci-app-familycloud is not set CONFIG_PACKAGE_luci-app-filetransfer=y CONFIG_PACKAGE_luci-app-firewall=y # CONFIG_PACKAGE_luci-app-flowoffload is not set # CONFIG_PACKAGE_luci-app-freifunk-diagnostics is not set # CONFIG_PACKAGE_luci-app-freifunk-policyrouting is not set # CONFIG_PACKAGE_luci-app-freifunk-widgets is not set # CONFIG_PACKAGE_luci-app-frpc is not set # CONFIG_PACKAGE_luci-app-frps is not set # CONFIG_PACKAGE_luci-app-fwknopd is not set # CONFIG_PACKAGE_luci-app-guest-wifi is not set # CONFIG_PACKAGE_luci-app-haproxy-tcp is not set CONFIG_PACKAGE_luci-app-hd-idle=y # CONFIG_PACKAGE_luci-app-hnet is not set # CONFIG_PACKAGE_luci-app-https-dns-proxy is not set # CONFIG_PACKAGE_luci-app-ipsec-vpnd is not set # CONFIG_PACKAGE_luci-app-kodexplorer is not set # CONFIG_PACKAGE_luci-app-lxc is not set # CONFIG_PACKAGE_luci-app-meshwizard is not set # CONFIG_PACKAGE_luci-app-minidlna is not set # CONFIG_PACKAGE_luci-app-mjpg-streamer is not set # CONFIG_PACKAGE_luci-app-music-remote-center is not set # CONFIG_PACKAGE_luci-app-mwan3 is not set # CONFIG_PACKAGE_luci-app-mwan3helper is not set # CONFIG_PACKAGE_luci-app-n2n_v2 is not set # CONFIG_PACKAGE_luci-app-netdata is not set # CONFIG_PACKAGE_luci-app-nfs is not set # CONFIG_PACKAGE_luci-app-nft-qos is not set # CONFIG_PACKAGE_luci-app-nlbwmon is not set # CONFIG_PACKAGE_luci-app-noddos is not set # CONFIG_PACKAGE_luci-app-nps is not set # CONFIG_PACKAGE_luci-app-ntpc is not set # CONFIG_PACKAGE_luci-app-ocserv is not set # CONFIG_PACKAGE_luci-app-olsr is not set # CONFIG_PACKAGE_luci-app-olsr-services is not set # CONFIG_PACKAGE_luci-app-olsr-viz is not set # CONFIG_PACKAGE_luci-app-openvpn is not set # CONFIG_PACKAGE_luci-app-openvpn-server is not set # CONFIG_PACKAGE_luci-app-p910nd is not set # CONFIG_PACKAGE_luci-app-pagekitec is not set # CONFIG_PACKAGE_luci-app-polipo is not set # CONFIG_PACKAGE_luci-app-pppoe-relay is not set # CONFIG_PACKAGE_luci-app-privoxy is not set # CONFIG_PACKAGE_luci-app-ps3netsrv is not set # CONFIG_PACKAGE_luci-app-qbittorrent is not set # CONFIG_PACKAGE_luci-app-qos is not set # CONFIG_PACKAGE_luci-app-radicale is not set CONFIG_PACKAGE_luci-app-ramfree=y # CONFIG_PACKAGE_luci-app-rclone is not set # CONFIG_PACKAGE_luci-app-rclone_INCLUDE_rclone-webui is not set # CONFIG_PACKAGE_luci-app-rclone_INCLUDE_rclone-ng is not set # CONFIG_PACKAGE_luci-app-rclone_INCLUDE_fuse-utils is not set # CONFIG_PACKAGE_luci-app-rp-pppoe-server is not set CONFIG_PACKAGE_luci-app-samba=y # CONFIG_PACKAGE_luci-app-samba4 is not set # CONFIG_PACKAGE_luci-app-sfe is not set # CONFIG_PACKAGE_luci-app-shadowsocks-libev is not set # CONFIG_PACKAGE_luci-app-shairplay is not set # CONFIG_PACKAGE_luci-app-siitwizard is not set # CONFIG_PACKAGE_luci-app-simple-adblock is not set # CONFIG_PACKAGE_luci-app-softethervpn is not set # CONFIG_PACKAGE_luci-app-splash is not set # CONFIG_PACKAGE_luci-app-sqm is not set # CONFIG_PACKAGE_luci-app-squid is not set CONFIG_PACKAGE_luci-app-ssr-plus=y # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_V2ray_plugin is not set CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Xray=y # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Trojan is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Redsocks2 is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_V2ray is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Kcptun is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_ShadowsocksR_Server is not set # CONFIG_PACKAGE_luci-app-ssrserver-python is not set # CONFIG_PACKAGE_luci-app-statistics is not set # CONFIG_PACKAGE_luci-app-syncdial is not set # CONFIG_PACKAGE_luci-app-tinyproxy is not set CONFIG_PACKAGE_luci-app-transmission=y # CONFIG_PACKAGE_luci-app-travelmate is not set # CONFIG_PACKAGE_luci-app-ttyd is not set # CONFIG_PACKAGE_luci-app-udpxy is not set # CONFIG_PACKAGE_luci-app-uhttpd is not set CONFIG_PACKAGE_luci-app-unblockmusic=y CONFIG_UnblockNeteaseMusic_Go=y # CONFIG_UnblockNeteaseMusic_NodeJS is not set # CONFIG_PACKAGE_luci-app-unbound is not set CONFIG_PACKAGE_luci-app-upnp=y # CONFIG_PACKAGE_luci-app-usb-printer is not set # CONFIG_PACKAGE_luci-app-v2ray-server is not set # CONFIG_PACKAGE_luci-app-verysync is not set CONFIG_PACKAGE_luci-app-vlmcsd=y # CONFIG_PACKAGE_luci-app-vnstat is not set # CONFIG_PACKAGE_luci-app-vpnbypass is not set # CONFIG_PACKAGE_luci-app-vsftpd is not set # CONFIG_PACKAGE_luci-app-watchcat is not set # CONFIG_PACKAGE_luci-app-webadmin is not set # CONFIG_PACKAGE_luci-app-wifischedule is not set # CONFIG_PACKAGE_luci-app-wireguard is not set # CONFIG_PACKAGE_luci-app-wol is not set # CONFIG_PACKAGE_luci-app-wrtbwmon is not set # CONFIG_PACKAGE_luci-app-xlnetacc is not set # CONFIG_PACKAGE_luci-app-zerotier is not set # end of 3. Applications # # 4. Themes # # CONFIG_PACKAGE_luci-theme-argon is not set CONFIG_PACKAGE_luci-theme-bootstrap=y # CONFIG_PACKAGE_luci-theme-freifunk-generic is not set # CONFIG_PACKAGE_luci-theme-material is not set CONFIG_PACKAGE_luci-theme-netgear=y # end of 4. Themes # # 5. Protocols # # CONFIG_PACKAGE_luci-proto-3g is not set # CONFIG_PACKAGE_luci-proto-bonding is not set # CONFIG_PACKAGE_luci-proto-ipip is not set # CONFIG_PACKAGE_luci-proto-ipv6 is not set # CONFIG_PACKAGE_luci-proto-openconnect is not set CONFIG_PACKAGE_luci-proto-ppp=y # CONFIG_PACKAGE_luci-proto-qmi is not set # CONFIG_PACKAGE_luci-proto-relay is not set # CONFIG_PACKAGE_luci-proto-vpnc is not set # CONFIG_PACKAGE_luci-proto-wireguard is not set # end of 5. Protocols # # 6. Libraries # # CONFIG_PACKAGE_luci-lib-docker is not set # CONFIG_PACKAGE_luci-lib-dracula is not set # CONFIG_PACKAGE_luci-lib-httpclient is not set # CONFIG_PACKAGE_luci-lib-httpprotoutils is not set CONFIG_PACKAGE_luci-lib-ip=y # CONFIG_PACKAGE_luci-lib-iptparser is not set # CONFIG_PACKAGE_luci-lib-jquery-1-4 is not set # CONFIG_PACKAGE_luci-lib-json is not set CONFIG_PACKAGE_luci-lib-jsonc=y # CONFIG_PACKAGE_luci-lib-luaneightbl is not set CONFIG_PACKAGE_luci-lib-nixio=y # CONFIG_PACKAGE_luci-lib-px5g is not set # end of 6. Libraries # # 9. Freifunk # # CONFIG_PACKAGE_freifunk-common is not set # CONFIG_PACKAGE_freifunk-firewall is not set # CONFIG_PACKAGE_freifunk-policyrouting is not set # CONFIG_PACKAGE_freifunk-watchdog is not set # CONFIG_PACKAGE_meshwizard is not set # end of 9. Freifunk CONFIG_PACKAGE_default-settings=y CONFIG_PACKAGE_luci-i18n-adbyby-plus-zh-cn=y # CONFIG_PACKAGE_luci-i18n-base-ca is not set # CONFIG_PACKAGE_luci-i18n-base-cs is not set # CONFIG_PACKAGE_luci-i18n-base-de is not set # CONFIG_PACKAGE_luci-i18n-base-el is not set # CONFIG_PACKAGE_luci-i18n-base-en is not set # CONFIG_PACKAGE_luci-i18n-base-es is not set # CONFIG_PACKAGE_luci-i18n-base-fr is not set # CONFIG_PACKAGE_luci-i18n-base-he is not set # CONFIG_PACKAGE_luci-i18n-base-hu is not set # CONFIG_PACKAGE_luci-i18n-base-it is not set # CONFIG_PACKAGE_luci-i18n-base-ja is not set # CONFIG_PACKAGE_luci-i18n-base-ko is not set # CONFIG_PACKAGE_luci-i18n-base-ms is not set # CONFIG_PACKAGE_luci-i18n-base-no is not set # CONFIG_PACKAGE_luci-i18n-base-pl is not set # CONFIG_PACKAGE_luci-i18n-base-pt is not set # CONFIG_PACKAGE_luci-i18n-base-pt-br is not set # CONFIG_PACKAGE_luci-i18n-base-ro is not set # CONFIG_PACKAGE_luci-i18n-base-ru is not set # CONFIG_PACKAGE_luci-i18n-base-sk is not set # CONFIG_PACKAGE_luci-i18n-base-sv is not set # CONFIG_PACKAGE_luci-i18n-base-tr is not set # CONFIG_PACKAGE_luci-i18n-base-uk is not set # CONFIG_PACKAGE_luci-i18n-base-vi is not set CONFIG_PACKAGE_luci-i18n-base-zh-cn=y # CONFIG_PACKAGE_luci-i18n-base-zh-tw is not set CONFIG_PACKAGE_luci-i18n-filetransfer-zh-cn=y # CONFIG_PACKAGE_luci-i18n-firewall-ca is not set # CONFIG_PACKAGE_luci-i18n-firewall-cs is not set # CONFIG_PACKAGE_luci-i18n-firewall-de is not set # CONFIG_PACKAGE_luci-i18n-firewall-el is not set # CONFIG_PACKAGE_luci-i18n-firewall-en is not set # CONFIG_PACKAGE_luci-i18n-firewall-es is not set # CONFIG_PACKAGE_luci-i18n-firewall-fr is not set # CONFIG_PACKAGE_luci-i18n-firewall-he is not set # CONFIG_PACKAGE_luci-i18n-firewall-hu is not set # CONFIG_PACKAGE_luci-i18n-firewall-it is not set # CONFIG_PACKAGE_luci-i18n-firewall-ja is not set # CONFIG_PACKAGE_luci-i18n-firewall-ko is not set # CONFIG_PACKAGE_luci-i18n-firewall-ms is not set # CONFIG_PACKAGE_luci-i18n-firewall-no is not set # CONFIG_PACKAGE_luci-i18n-firewall-pl is not set # CONFIG_PACKAGE_luci-i18n-firewall-pt is not set # CONFIG_PACKAGE_luci-i18n-firewall-pt-br is not set # CONFIG_PACKAGE_luci-i18n-firewall-ro is not set # CONFIG_PACKAGE_luci-i18n-firewall-ru is not set # CONFIG_PACKAGE_luci-i18n-firewall-sk is not set # CONFIG_PACKAGE_luci-i18n-firewall-sv is not set # CONFIG_PACKAGE_luci-i18n-firewall-tr is not set # CONFIG_PACKAGE_luci-i18n-firewall-uk is not set # CONFIG_PACKAGE_luci-i18n-firewall-vi is not set CONFIG_PACKAGE_luci-i18n-firewall-zh-cn=y # CONFIG_PACKAGE_luci-i18n-firewall-zh-tw is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-ca is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-cs is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-de is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-el is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-en is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-es is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-fr is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-he is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-hu is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-it is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-ja is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-ms is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-no is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-pl is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-pt is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-pt-br is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-ro is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-ru is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-sk is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-sv is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-tr is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-uk is not set # CONFIG_PACKAGE_luci-i18n-hd-idle-vi is not set CONFIG_PACKAGE_luci-i18n-hd-idle-zh-cn=y # CONFIG_PACKAGE_luci-i18n-hd-idle-zh-tw is not set CONFIG_PACKAGE_luci-i18n-ramfree-zh-cn=y # CONFIG_PACKAGE_luci-i18n-samba-ca is not set # CONFIG_PACKAGE_luci-i18n-samba-cs is not set # CONFIG_PACKAGE_luci-i18n-samba-de is not set # CONFIG_PACKAGE_luci-i18n-samba-el is not set # CONFIG_PACKAGE_luci-i18n-samba-en is not set # CONFIG_PACKAGE_luci-i18n-samba-es is not set # CONFIG_PACKAGE_luci-i18n-samba-fr is not set # CONFIG_PACKAGE_luci-i18n-samba-he is not set # CONFIG_PACKAGE_luci-i18n-samba-hu is not set # CONFIG_PACKAGE_luci-i18n-samba-it is not set # CONFIG_PACKAGE_luci-i18n-samba-ja is not set # CONFIG_PACKAGE_luci-i18n-samba-ms is not set # CONFIG_PACKAGE_luci-i18n-samba-no is not set # CONFIG_PACKAGE_luci-i18n-samba-pl is not set # CONFIG_PACKAGE_luci-i18n-samba-pt is not set # CONFIG_PACKAGE_luci-i18n-samba-pt-br is not set # CONFIG_PACKAGE_luci-i18n-samba-ro is not set # CONFIG_PACKAGE_luci-i18n-samba-ru is not set # CONFIG_PACKAGE_luci-i18n-samba-sk is not set # CONFIG_PACKAGE_luci-i18n-samba-sv is not set # CONFIG_PACKAGE_luci-i18n-samba-tr is not set # CONFIG_PACKAGE_luci-i18n-samba-uk is not set # CONFIG_PACKAGE_luci-i18n-samba-vi is not set CONFIG_PACKAGE_luci-i18n-samba-zh-cn=y # CONFIG_PACKAGE_luci-i18n-samba-zh-tw is not set CONFIG_PACKAGE_luci-i18n-ssr-plus-zh-cn=y # CONFIG_PACKAGE_luci-i18n-ssr-plus-zh_Hans is not set # CONFIG_PACKAGE_luci-i18n-travelmate-ja is not set # CONFIG_PACKAGE_luci-i18n-travelmate-pt-br is not set # CONFIG_PACKAGE_luci-i18n-travelmate-ru is not set CONFIG_PACKAGE_luci-i18n-ttyd-zh-cn=y # CONFIG_PACKAGE_luci-i18n-upnp-ca is not set # CONFIG_PACKAGE_luci-i18n-upnp-cs is not set # CONFIG_PACKAGE_luci-i18n-upnp-de is not set # CONFIG_PACKAGE_luci-i18n-upnp-el is not set # CONFIG_PACKAGE_luci-i18n-upnp-en is not set # CONFIG_PACKAGE_luci-i18n-upnp-es is not set # CONFIG_PACKAGE_luci-i18n-upnp-fr is not set # CONFIG_PACKAGE_luci-i18n-upnp-he is not set # CONFIG_PACKAGE_luci-i18n-upnp-hu is not set # CONFIG_PACKAGE_luci-i18n-upnp-it is not set # CONFIG_PACKAGE_luci-i18n-upnp-ja is not set # CONFIG_PACKAGE_luci-i18n-upnp-ms is not set # CONFIG_PACKAGE_luci-i18n-upnp-no is not set # CONFIG_PACKAGE_luci-i18n-upnp-pl is not set # CONFIG_PACKAGE_luci-i18n-upnp-pt is not set # CONFIG_PACKAGE_luci-i18n-upnp-pt-br is not set # CONFIG_PACKAGE_luci-i18n-upnp-ro is not set # CONFIG_PACKAGE_luci-i18n-upnp-ru is not set # CONFIG_PACKAGE_luci-i18n-upnp-sk is not set # CONFIG_PACKAGE_luci-i18n-upnp-sv is not set # CONFIG_PACKAGE_luci-i18n-upnp-tr is not set # CONFIG_PACKAGE_luci-i18n-upnp-uk is not set # CONFIG_PACKAGE_luci-i18n-upnp-vi is not set CONFIG_PACKAGE_luci-i18n-upnp-zh-cn=y # CONFIG_PACKAGE_luci-i18n-upnp-zh-tw is not set CONFIG_PACKAGE_luci-i18n-vsftpd-zh-cn=y # CONFIG_PACKAGE_luci-i18n-wifischedule-it is not set # CONFIG_PACKAGE_luci-i18n-wifischedule-ja is not set # CONFIG_PACKAGE_luci-i18n-wifischedule-pt-br is not set # CONFIG_PACKAGE_luci-i18n-wifischedule-ru is not set # CONFIG_PACKAGE_luci-i18n-wifischedule-sv is not set CONFIG_PACKAGE_luci-i18n-wifischedule-zh-cn=y # end of LuCI # # Mail # # CONFIG_PACKAGE_alpine is not set # CONFIG_PACKAGE_alpine-nossl is not set # CONFIG_PACKAGE_bogofilter is not set # CONFIG_PACKAGE_clamsmtp is not set # CONFIG_PACKAGE_dovecot is not set # CONFIG_PACKAGE_dovecot-pigeonhole is not set # CONFIG_PACKAGE_dovecot-utils is not set # CONFIG_PACKAGE_emailrelay is not set # CONFIG_PACKAGE_fdm is not set # CONFIG_PACKAGE_greyfix is not set # CONFIG_PACKAGE_mailsend is not set # CONFIG_PACKAGE_mailsend-nossl is not set # CONFIG_PACKAGE_msmtp is not set # CONFIG_PACKAGE_msmtp-mta is not set # CONFIG_PACKAGE_msmtp-nossl is not set # CONFIG_PACKAGE_msmtp-queue is not set # CONFIG_PACKAGE_mutt is not set # CONFIG_PACKAGE_nail is not set # CONFIG_PACKAGE_opendkim is not set # CONFIG_PACKAGE_opendkim-tools is not set # CONFIG_PACKAGE_postfix is not set # # Select postfix build options # CONFIG_POSTFIX_TLS=y CONFIG_POSTFIX_SASL=y CONFIG_POSTFIX_LDAP=y # CONFIG_POSTFIX_DB is not set CONFIG_POSTFIX_CDB=y CONFIG_POSTFIX_SQLITE=y # CONFIG_POSTFIX_MYSQL is not set # CONFIG_POSTFIX_PGSQL is not set CONFIG_POSTFIX_PCRE=y # CONFIG_POSTFIX_EAI is not set # end of Select postfix build options # CONFIG_PACKAGE_ssmtp is not set # end of Mail # # Multimedia # # # Streaming # # CONFIG_PACKAGE_oggfwd is not set # end of Streaming # CONFIG_PACKAGE_ffmpeg is not set # CONFIG_PACKAGE_ffprobe is not set # CONFIG_PACKAGE_fswebcam is not set # CONFIG_PACKAGE_gerbera is not set # CONFIG_PACKAGE_gmediarender is not set # CONFIG_PACKAGE_gphoto2 is not set # CONFIG_PACKAGE_graphicsmagick is not set # CONFIG_PACKAGE_grilo is not set # CONFIG_PACKAGE_grilo-plugins is not set # CONFIG_PACKAGE_gst1-libav is not set # CONFIG_PACKAGE_gstreamer1-libs is not set # CONFIG_PACKAGE_gstreamer1-plugins-bad is not set # CONFIG_PACKAGE_gstreamer1-plugins-base is not set # CONFIG_PACKAGE_gstreamer1-plugins-good is not set # CONFIG_PACKAGE_gstreamer1-plugins-ugly is not set # CONFIG_PACKAGE_gstreamer1-utils is not set # CONFIG_PACKAGE_icecast is not set # CONFIG_PACKAGE_imagemagick is not set # CONFIG_PACKAGE_lcdgrilo is not set # CONFIG_PACKAGE_minidlna is not set # CONFIG_PACKAGE_minisatip is not set # CONFIG_PACKAGE_mjpg-streamer is not set # CONFIG_PACKAGE_motion is not set # CONFIG_PACKAGE_tvheadend is not set # CONFIG_PACKAGE_v4l2rtspserver is not set # CONFIG_PACKAGE_vips is not set # CONFIG_PACKAGE_xupnpd is not set # CONFIG_PACKAGE_youtube-dl is not set # end of Multimedia # # Network # # # BitTorrent # # CONFIG_PACKAGE_mktorrent is not set # CONFIG_PACKAGE_opentracker is not set # CONFIG_PACKAGE_opentracker6 is not set # CONFIG_PACKAGE_qBittorrent is not set # CONFIG_PACKAGE_rtorrent is not set # CONFIG_PACKAGE_rtorrent-rpc is not set # CONFIG_PACKAGE_transmission-cli-openssl is not set # CONFIG_PACKAGE_transmission-daemon-openssl is not set # CONFIG_PACKAGE_transmission-remote-openssl is not set # CONFIG_PACKAGE_transmission-web is not set # CONFIG_PACKAGE_transmission-web-control is not set # end of BitTorrent # # Captive Portals # # CONFIG_PACKAGE_apfree-wifidog is not set # CONFIG_PACKAGE_coova-chilli is not set # CONFIG_PACKAGE_nodogsplash is not set # CONFIG_PACKAGE_opennds is not set # CONFIG_PACKAGE_wifidog is not set # CONFIG_PACKAGE_wifidog-tls is not set # end of Captive Portals # # Cloud Manager # # CONFIG_PACKAGE_rclone-ng is not set # CONFIG_PACKAGE_rclone-webui-react is not set # end of Cloud Manager # # Dial-in/up # # CONFIG_PACKAGE_rp-pppoe-common is not set # CONFIG_PACKAGE_rp-pppoe-relay is not set # CONFIG_PACKAGE_rp-pppoe-server is not set # end of Dial-in/up # # Download Manager # # CONFIG_PACKAGE_ariang is not set # CONFIG_PACKAGE_ariang-nginx is not set # CONFIG_PACKAGE_leech is not set # CONFIG_PACKAGE_webui-aria2 is not set # end of Download Manager # # File Transfer # # CONFIG_PACKAGE_aria2 is not set # CONFIG_PACKAGE_atftp is not set # CONFIG_PACKAGE_atftpd is not set # CONFIG_PACKAGE_curl is not set # CONFIG_PACKAGE_gnurl is not set # CONFIG_PACKAGE_lftp is not set # CONFIG_PACKAGE_ps3netsrv is not set # CONFIG_PACKAGE_rosy-file-server is not set # CONFIG_PACKAGE_rsync is not set # CONFIG_PACKAGE_rsyncd is not set # CONFIG_PACKAGE_vsftpd is not set CONFIG_PACKAGE_vsftpd-alt=y CONFIG_VSFTPD_USE_UCI_SCRIPTS=y # CONFIG_PACKAGE_vsftpd-tls is not set CONFIG_PACKAGE_wget=y # CONFIG_PACKAGE_wget-nossl is not set # end of File Transfer # # Filesystem # # CONFIG_PACKAGE_davfs2 is not set # CONFIG_PACKAGE_ksmbd-avahi-service is not set # CONFIG_PACKAGE_ksmbd-server is not set # CONFIG_PACKAGE_ksmbd-utils is not set # CONFIG_PACKAGE_netatalk is not set # CONFIG_PACKAGE_nfs-kernel-server is not set # CONFIG_PACKAGE_owftpd is not set # CONFIG_PACKAGE_owhttpd is not set # CONFIG_PACKAGE_owserver is not set # CONFIG_PACKAGE_sshfs is not set # end of Filesystem # # Firewall # # CONFIG_PACKAGE_arptables is not set # CONFIG_PACKAGE_conntrack is not set # CONFIG_PACKAGE_conntrackd is not set # CONFIG_PACKAGE_ebtables is not set # CONFIG_PACKAGE_fwknop is not set # CONFIG_PACKAGE_fwknopd is not set # CONFIG_PACKAGE_ip6tables is not set CONFIG_PACKAGE_iptables=y # CONFIG_IPTABLES_CONNLABEL is not set # CONFIG_IPTABLES_NFTABLES is not set # CONFIG_PACKAGE_iptables-mod-account is not set # CONFIG_PACKAGE_iptables-mod-chaos is not set # CONFIG_PACKAGE_iptables-mod-checksum is not set # CONFIG_PACKAGE_iptables-mod-cluster is not set # CONFIG_PACKAGE_iptables-mod-clusterip is not set # CONFIG_PACKAGE_iptables-mod-condition is not set # CONFIG_PACKAGE_iptables-mod-conntrack-extra is not set # CONFIG_PACKAGE_iptables-mod-delude is not set # CONFIG_PACKAGE_iptables-mod-dhcpmac is not set # CONFIG_PACKAGE_iptables-mod-dnetmap is not set # CONFIG_PACKAGE_iptables-mod-extra is not set # CONFIG_PACKAGE_iptables-mod-filter is not set CONFIG_PACKAGE_iptables-mod-fullconenat=y # CONFIG_PACKAGE_iptables-mod-fuzzy is not set # CONFIG_PACKAGE_iptables-mod-geoip is not set # CONFIG_PACKAGE_iptables-mod-hashlimit is not set # CONFIG_PACKAGE_iptables-mod-iface is not set # CONFIG_PACKAGE_iptables-mod-ipmark is not set # CONFIG_PACKAGE_iptables-mod-ipopt is not set # CONFIG_PACKAGE_iptables-mod-ipp2p is not set # CONFIG_PACKAGE_iptables-mod-iprange is not set # CONFIG_PACKAGE_iptables-mod-ipsec is not set # CONFIG_PACKAGE_iptables-mod-ipv4options is not set # CONFIG_PACKAGE_iptables-mod-led is not set # CONFIG_PACKAGE_iptables-mod-length2 is not set # CONFIG_PACKAGE_iptables-mod-logmark is not set # CONFIG_PACKAGE_iptables-mod-lscan is not set # CONFIG_PACKAGE_iptables-mod-lua is not set # CONFIG_PACKAGE_iptables-mod-nat-extra is not set # CONFIG_PACKAGE_iptables-mod-nflog is not set # CONFIG_PACKAGE_iptables-mod-nfqueue is not set # CONFIG_PACKAGE_iptables-mod-physdev is not set # CONFIG_PACKAGE_iptables-mod-proto is not set # CONFIG_PACKAGE_iptables-mod-psd is not set # CONFIG_PACKAGE_iptables-mod-quota2 is not set # CONFIG_PACKAGE_iptables-mod-rpfilter is not set # CONFIG_PACKAGE_iptables-mod-rtpengine is not set # CONFIG_PACKAGE_iptables-mod-sysrq is not set # CONFIG_PACKAGE_iptables-mod-tarpit is not set # CONFIG_PACKAGE_iptables-mod-tee is not set CONFIG_PACKAGE_iptables-mod-tproxy=y # CONFIG_PACKAGE_iptables-mod-trace is not set # CONFIG_PACKAGE_iptables-mod-u32 is not set # CONFIG_PACKAGE_iptables-mod-ulog is not set # CONFIG_PACKAGE_iptaccount is not set # CONFIG_PACKAGE_iptgeoip is not set # CONFIG_PACKAGE_miniupnpc is not set CONFIG_PACKAGE_miniupnpd=y # CONFIG_MINIUPNPD_IGDv2 is not set # CONFIG_PACKAGE_natpmpc is not set # CONFIG_PACKAGE_nftables-json is not set # CONFIG_PACKAGE_nftables-nojson is not set # CONFIG_PACKAGE_shorewall is not set # CONFIG_PACKAGE_shorewall-core is not set # CONFIG_PACKAGE_shorewall-lite is not set # CONFIG_PACKAGE_shorewall6 is not set # CONFIG_PACKAGE_shorewall6-lite is not set # CONFIG_PACKAGE_snort is not set # CONFIG_PACKAGE_snort3 is not set # end of Firewall # # Firewall Tunnel # # CONFIG_PACKAGE_iodine is not set # CONFIG_PACKAGE_iodined is not set # end of Firewall Tunnel # # FreeRADIUS (version 3) # # CONFIG_PACKAGE_freeradius3 is not set # CONFIG_PACKAGE_freeradius3-common is not set # CONFIG_PACKAGE_freeradius3-utils is not set # end of FreeRADIUS (version 3) # # IP Addresses and Names # # CONFIG_PACKAGE_aggregate is not set # CONFIG_PACKAGE_announce is not set # CONFIG_PACKAGE_avahi-autoipd is not set # CONFIG_PACKAGE_avahi-daemon-service-http is not set # CONFIG_PACKAGE_avahi-daemon-service-ssh is not set # CONFIG_PACKAGE_avahi-dbus-daemon is not set # CONFIG_PACKAGE_avahi-dnsconfd is not set # CONFIG_PACKAGE_avahi-nodbus-daemon is not set # CONFIG_PACKAGE_avahi-utils is not set # CONFIG_PACKAGE_bind-check is not set # CONFIG_PACKAGE_bind-client is not set # CONFIG_PACKAGE_bind-dig is not set # CONFIG_PACKAGE_bind-dnssec is not set # CONFIG_PACKAGE_bind-host is not set # CONFIG_PACKAGE_bind-nslookup is not set # CONFIG_PACKAGE_bind-rndc is not set # CONFIG_PACKAGE_bind-server is not set # CONFIG_PACKAGE_bind-tools is not set CONFIG_PACKAGE_ddns-scripts=y CONFIG_PACKAGE_ddns-scripts_aliyun=y # CONFIG_PACKAGE_ddns-scripts_cloudflare.com-v4 is not set CONFIG_PACKAGE_ddns-scripts_dnspod=y # CONFIG_PACKAGE_ddns-scripts_freedns_42_pl is not set # CONFIG_PACKAGE_ddns-scripts_godaddy.com-v1 is not set # CONFIG_PACKAGE_ddns-scripts_no-ip_com is not set # CONFIG_PACKAGE_ddns-scripts_nsupdate is not set # CONFIG_PACKAGE_ddns-scripts_route53-v1 is not set # CONFIG_PACKAGE_dhcp-forwarder is not set CONFIG_PACKAGE_dns2socks=y # CONFIG_PACKAGE_dnscrypt-proxy is not set # CONFIG_PACKAGE_dnscrypt-proxy-resolvers is not set # CONFIG_PACKAGE_dnsdist is not set # CONFIG_PACKAGE_drill is not set # CONFIG_PACKAGE_hostip is not set # CONFIG_PACKAGE_idn is not set # CONFIG_PACKAGE_idn2 is not set # CONFIG_PACKAGE_inadyn is not set # CONFIG_PACKAGE_isc-dhcp-client-ipv4 is not set # CONFIG_PACKAGE_isc-dhcp-client-ipv6 is not set # CONFIG_PACKAGE_isc-dhcp-omshell-ipv4 is not set # CONFIG_PACKAGE_isc-dhcp-omshell-ipv6 is not set # CONFIG_PACKAGE_isc-dhcp-relay-ipv4 is not set # CONFIG_PACKAGE_isc-dhcp-relay-ipv6 is not set # CONFIG_PACKAGE_isc-dhcp-server-ipv4 is not set # CONFIG_PACKAGE_isc-dhcp-server-ipv6 is not set # CONFIG_PACKAGE_kadnode is not set # CONFIG_PACKAGE_kea-admin is not set # CONFIG_PACKAGE_kea-ctrl is not set # CONFIG_PACKAGE_kea-dhcp-ddns is not set # CONFIG_PACKAGE_kea-dhcp4 is not set # CONFIG_PACKAGE_kea-dhcp6 is not set # CONFIG_PACKAGE_kea-lfc is not set # CONFIG_PACKAGE_kea-libs is not set # CONFIG_PACKAGE_kea-perfdhcp is not set # CONFIG_PACKAGE_knot is not set # CONFIG_PACKAGE_knot-dig is not set # CONFIG_PACKAGE_knot-host is not set # CONFIG_PACKAGE_knot-keymgr is not set # CONFIG_PACKAGE_knot-nsupdate is not set # CONFIG_PACKAGE_knot-tests is not set # CONFIG_PACKAGE_knot-zonecheck is not set # CONFIG_PACKAGE_ldns-examples is not set # CONFIG_PACKAGE_mdns-utils is not set # CONFIG_PACKAGE_mdnsd is not set # CONFIG_PACKAGE_mdnsresponder is not set # CONFIG_PACKAGE_nsd is not set # CONFIG_PACKAGE_nsd-control is not set # CONFIG_PACKAGE_nsd-control-setup is not set # CONFIG_PACKAGE_nsd-nossl is not set # CONFIG_PACKAGE_ohybridproxy is not set # CONFIG_PACKAGE_overture is not set # CONFIG_PACKAGE_pdns is not set # CONFIG_PACKAGE_pdns-ixfrdist is not set # CONFIG_PACKAGE_pdns-recursor is not set # CONFIG_PACKAGE_pdns-tools is not set # CONFIG_PACKAGE_stubby is not set # CONFIG_PACKAGE_tor-hs is not set # CONFIG_PACKAGE_torsocks is not set # CONFIG_PACKAGE_unbound-anchor is not set # CONFIG_PACKAGE_unbound-checkconf is not set # CONFIG_PACKAGE_unbound-control is not set # CONFIG_PACKAGE_unbound-control-setup is not set # CONFIG_PACKAGE_unbound-daemon is not set # CONFIG_PACKAGE_unbound-host is not set # CONFIG_PACKAGE_wsdd2 is not set # CONFIG_PACKAGE_zonestitcher is not set # end of IP Addresses and Names # # Instant Messaging # # CONFIG_PACKAGE_bitlbee is not set # CONFIG_PACKAGE_irssi is not set # CONFIG_PACKAGE_ngircd is not set # CONFIG_PACKAGE_ngircd-nossl is not set # CONFIG_PACKAGE_prosody is not set # CONFIG_PACKAGE_quassel-irssi is not set # CONFIG_PACKAGE_umurmur-mbedtls is not set # CONFIG_PACKAGE_umurmur-openssl is not set # CONFIG_PACKAGE_znc is not set # end of Instant Messaging # # Linux ATM tools # # CONFIG_PACKAGE_atm-aread is not set # CONFIG_PACKAGE_atm-atmaddr is not set # CONFIG_PACKAGE_atm-atmdiag is not set # CONFIG_PACKAGE_atm-atmdump is not set # CONFIG_PACKAGE_atm-atmloop is not set # CONFIG_PACKAGE_atm-atmsigd is not set # CONFIG_PACKAGE_atm-atmswitch is not set # CONFIG_PACKAGE_atm-atmtcp is not set # CONFIG_PACKAGE_atm-awrite is not set # CONFIG_PACKAGE_atm-bus is not set # CONFIG_PACKAGE_atm-debug-tools is not set # CONFIG_PACKAGE_atm-diagnostics is not set # CONFIG_PACKAGE_atm-esi is not set # CONFIG_PACKAGE_atm-ilmid is not set # CONFIG_PACKAGE_atm-ilmidiag is not set # CONFIG_PACKAGE_atm-lecs is not set # CONFIG_PACKAGE_atm-les is not set # CONFIG_PACKAGE_atm-mpcd is not set # CONFIG_PACKAGE_atm-saaldump is not set # CONFIG_PACKAGE_atm-sonetdiag is not set # CONFIG_PACKAGE_atm-svc_recv is not set # CONFIG_PACKAGE_atm-svc_send is not set # CONFIG_PACKAGE_atm-tools is not set # CONFIG_PACKAGE_atm-ttcp_atm is not set # CONFIG_PACKAGE_atm-zeppelin is not set # CONFIG_PACKAGE_br2684ctl is not set # end of Linux ATM tools # # LoRaWAN # # CONFIG_PACKAGE_libloragw-tests is not set # CONFIG_PACKAGE_libloragw-utils is not set # end of LoRaWAN # # NMAP Suite # # CONFIG_PACKAGE_ncat is not set # CONFIG_PACKAGE_ncat-full is not set # CONFIG_PACKAGE_ncat-ssl is not set # CONFIG_PACKAGE_ndiff is not set # CONFIG_PACKAGE_nmap is not set # CONFIG_PACKAGE_nmap-full is not set # CONFIG_PACKAGE_nmap-ssl is not set # CONFIG_PACKAGE_nping is not set # CONFIG_PACKAGE_nping-ssl is not set # end of NMAP Suite # # NTRIP # # CONFIG_PACKAGE_ntripcaster is not set # CONFIG_PACKAGE_ntripclient is not set # CONFIG_PACKAGE_ntripserver is not set # end of NTRIP # # NeteaseMusic # # CONFIG_PACKAGE_UnblockNeteaseMusic is not set # CONFIG_PACKAGE_UnblockNeteaseMusicGo is not set CONFIG_UnblockNeteaseMusicGo_INCLUDE_GOPROXY=y # end of NeteaseMusic # # OLSR.org network framework # # CONFIG_PACKAGE_oonf-dlep-proxy is not set # CONFIG_PACKAGE_oonf-dlep-radio is not set # CONFIG_PACKAGE_oonf-init-scripts is not set # CONFIG_PACKAGE_oonf-olsrd2 is not set # end of OLSR.org network framework # # Open vSwitch # # CONFIG_PACKAGE_openvswitch is not set # CONFIG_PACKAGE_openvswitch-ovn-host is not set # CONFIG_PACKAGE_openvswitch-ovn-north is not set # CONFIG_PACKAGE_openvswitch-python3 is not set # end of Open vSwitch # # OpenLDAP # # CONFIG_PACKAGE_libopenldap is not set CONFIG_OPENLDAP_DEBUG=y # CONFIG_OPENLDAP_CRYPT is not set # CONFIG_OPENLDAP_MONITOR is not set # CONFIG_OPENLDAP_DB47 is not set # CONFIG_OPENLDAP_ICU is not set # CONFIG_PACKAGE_openldap-server is not set # CONFIG_PACKAGE_openldap-utils is not set # end of OpenLDAP # # P2P # # CONFIG_PACKAGE_amule is not set # CONFIG_AMULE_CRYPTOPP_STATIC_LINKING is not set # CONFIG_PACKAGE_antileech is not set # end of P2P # # Printing # # CONFIG_PACKAGE_p910nd is not set # end of Printing # # Project V # # CONFIG_PACKAGE_v2ray is not set # CONFIG_PACKAGE_v2ray-plugin is not set CONFIG_v2ray-plugin_INCLUDE_GOPROXY=y # end of Project V # # Project X # CONFIG_PACKAGE_xray=y # # Xray Configuration # # CONFIG_XRAY_COMPRESS_GOPROXY is not set CONFIG_XRAY_EXCLUDE_ASSETS=y CONFIG_XRAY_COMPRESS_UPX=y # CONFIG_XRAY_COMPATIBILITY_MODE is not set # end of Xray Configuration # end of Project X # # Routing and Redirection # # CONFIG_PACKAGE_babel-pinger is not set # CONFIG_PACKAGE_babeld is not set # CONFIG_PACKAGE_batmand is not set # CONFIG_PACKAGE_bcp38 is not set # CONFIG_PACKAGE_bfdd is not set # CONFIG_PACKAGE_bird1-ipv4 is not set # CONFIG_PACKAGE_bird1-ipv4-uci is not set # CONFIG_PACKAGE_bird1-ipv6 is not set # CONFIG_PACKAGE_bird1-ipv6-uci is not set # CONFIG_PACKAGE_bird1c-ipv4 is not set # CONFIG_PACKAGE_bird1c-ipv6 is not set # CONFIG_PACKAGE_bird1cl-ipv4 is not set # CONFIG_PACKAGE_bird1cl-ipv6 is not set # CONFIG_PACKAGE_bird2 is not set # CONFIG_PACKAGE_bird2c is not set # CONFIG_PACKAGE_bird2cl is not set # CONFIG_PACKAGE_bmx6 is not set # CONFIG_PACKAGE_bmx7 is not set # CONFIG_PACKAGE_cjdns is not set # CONFIG_PACKAGE_cjdns-tests is not set # CONFIG_PACKAGE_dcstad is not set # CONFIG_PACKAGE_dcwapd is not set # CONFIG_PACKAGE_devlink is not set # CONFIG_PACKAGE_frr is not set # CONFIG_PACKAGE_genl is not set # CONFIG_PACKAGE_igmpproxy is not set # CONFIG_PACKAGE_ip-bridge is not set CONFIG_PACKAGE_ip-full=y # CONFIG_PACKAGE_ip-tiny is not set # CONFIG_PACKAGE_lldpd is not set # CONFIG_PACKAGE_mcproxy is not set # CONFIG_PACKAGE_mrmctl is not set # CONFIG_PACKAGE_mwan3 is not set # CONFIG_PACKAGE_nstat is not set # CONFIG_PACKAGE_olsrd is not set # CONFIG_PACKAGE_prince is not set # CONFIG_PACKAGE_quagga is not set # CONFIG_PACKAGE_rdma is not set # CONFIG_PACKAGE_relayd is not set # CONFIG_PACKAGE_smcroute is not set # CONFIG_PACKAGE_ss is not set # CONFIG_PACKAGE_sslh is not set # CONFIG_PACKAGE_tc is not set # CONFIG_PACKAGE_tcpproxy is not set # CONFIG_PACKAGE_vis is not set # CONFIG_PACKAGE_yggdrasil is not set # end of Routing and Redirection # # SSH # # CONFIG_PACKAGE_autossh is not set # CONFIG_PACKAGE_openssh-client is not set # CONFIG_PACKAGE_openssh-client-utils is not set # CONFIG_PACKAGE_openssh-keygen is not set # CONFIG_PACKAGE_openssh-moduli is not set # CONFIG_PACKAGE_openssh-server is not set # CONFIG_PACKAGE_openssh-server-pam is not set # CONFIG_PACKAGE_openssh-sftp-avahi-service is not set # CONFIG_PACKAGE_openssh-sftp-client is not set # CONFIG_PACKAGE_openssh-sftp-server is not set # CONFIG_PACKAGE_sshtunnel is not set # end of SSH # # THC-IPv6 attack and analyzing toolkit # # CONFIG_PACKAGE_thc-ipv6-address6 is not set # CONFIG_PACKAGE_thc-ipv6-alive6 is not set # CONFIG_PACKAGE_thc-ipv6-covert-send6 is not set # CONFIG_PACKAGE_thc-ipv6-covert-send6d is not set # CONFIG_PACKAGE_thc-ipv6-denial6 is not set # CONFIG_PACKAGE_thc-ipv6-detect-new-ip6 is not set # CONFIG_PACKAGE_thc-ipv6-detect-sniffer6 is not set # CONFIG_PACKAGE_thc-ipv6-dnsdict6 is not set # CONFIG_PACKAGE_thc-ipv6-dnsrevenum6 is not set # CONFIG_PACKAGE_thc-ipv6-dos-new-ip6 is not set # CONFIG_PACKAGE_thc-ipv6-dump-router6 is not set # CONFIG_PACKAGE_thc-ipv6-exploit6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-advertise6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-dhcps6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-dns6d is not set # CONFIG_PACKAGE_thc-ipv6-fake-dnsupdate6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-mipv6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-mld26 is not set # CONFIG_PACKAGE_thc-ipv6-fake-mld6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-mldrouter6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-router26 is not set # CONFIG_PACKAGE_thc-ipv6-fake-router6 is not set # CONFIG_PACKAGE_thc-ipv6-fake-solicitate6 is not set # CONFIG_PACKAGE_thc-ipv6-flood-advertise6 is not set # CONFIG_PACKAGE_thc-ipv6-flood-dhcpc6 is not set # CONFIG_PACKAGE_thc-ipv6-flood-mld26 is not set # CONFIG_PACKAGE_thc-ipv6-flood-mld6 is not set # CONFIG_PACKAGE_thc-ipv6-flood-mldrouter6 is not set # CONFIG_PACKAGE_thc-ipv6-flood-router26 is not set # CONFIG_PACKAGE_thc-ipv6-flood-router6 is not set # CONFIG_PACKAGE_thc-ipv6-flood-solicitate6 is not set # CONFIG_PACKAGE_thc-ipv6-fragmentation6 is not set # CONFIG_PACKAGE_thc-ipv6-fuzz-dhcpc6 is not set # CONFIG_PACKAGE_thc-ipv6-fuzz-dhcps6 is not set # CONFIG_PACKAGE_thc-ipv6-fuzz-ip6 is not set # CONFIG_PACKAGE_thc-ipv6-implementation6 is not set # CONFIG_PACKAGE_thc-ipv6-implementation6d is not set # CONFIG_PACKAGE_thc-ipv6-inverse-lookup6 is not set # CONFIG_PACKAGE_thc-ipv6-kill-router6 is not set # CONFIG_PACKAGE_thc-ipv6-ndpexhaust6 is not set # CONFIG_PACKAGE_thc-ipv6-node-query6 is not set # CONFIG_PACKAGE_thc-ipv6-parasite6 is not set # CONFIG_PACKAGE_thc-ipv6-passive-discovery6 is not set # CONFIG_PACKAGE_thc-ipv6-randicmp6 is not set # CONFIG_PACKAGE_thc-ipv6-redir6 is not set # CONFIG_PACKAGE_thc-ipv6-rsmurf6 is not set # CONFIG_PACKAGE_thc-ipv6-sendpees6 is not set # CONFIG_PACKAGE_thc-ipv6-sendpeesmp6 is not set # CONFIG_PACKAGE_thc-ipv6-smurf6 is not set # CONFIG_PACKAGE_thc-ipv6-thcping6 is not set # CONFIG_PACKAGE_thc-ipv6-toobig6 is not set # CONFIG_PACKAGE_thc-ipv6-trace6 is not set # end of THC-IPv6 attack and analyzing toolkit # # Tcpreplay # # CONFIG_PACKAGE_tcpbridge is not set # CONFIG_PACKAGE_tcpcapinfo is not set # CONFIG_PACKAGE_tcpliveplay is not set # CONFIG_PACKAGE_tcpprep is not set # CONFIG_PACKAGE_tcpreplay is not set # CONFIG_PACKAGE_tcpreplay-all is not set # CONFIG_PACKAGE_tcpreplay-edit is not set # CONFIG_PACKAGE_tcprewrite is not set # end of Tcpreplay # # Telephony # # CONFIG_PACKAGE_asterisk is not set # CONFIG_PACKAGE_baresip is not set # CONFIG_PACKAGE_freeswitch is not set # CONFIG_PACKAGE_kamailio5 is not set # CONFIG_PACKAGE_miax is not set # CONFIG_PACKAGE_pcapsipdump is not set # CONFIG_PACKAGE_restund is not set # CONFIG_PACKAGE_rtpengine is not set # CONFIG_PACKAGE_rtpengine-no-transcode is not set # CONFIG_PACKAGE_rtpengine-recording is not set # CONFIG_PACKAGE_rtpproxy is not set # CONFIG_PACKAGE_sipp is not set # CONFIG_PACKAGE_siproxd is not set # CONFIG_PACKAGE_yate is not set # end of Telephony # # Telephony Lantiq # # end of Telephony Lantiq # # Time Synchronization # # CONFIG_PACKAGE_chrony is not set # CONFIG_PACKAGE_htpdate is not set # CONFIG_PACKAGE_linuxptp is not set # CONFIG_PACKAGE_ntp-keygen is not set # CONFIG_PACKAGE_ntp-utils is not set # CONFIG_PACKAGE_ntpclient is not set # CONFIG_PACKAGE_ntpd is not set # CONFIG_PACKAGE_ntpdate is not set # end of Time Synchronization # # VPN # # CONFIG_PACKAGE_chaosvpn is not set # CONFIG_PACKAGE_fastd is not set # CONFIG_PACKAGE_libreswan is not set # CONFIG_PACKAGE_n2n-edge is not set # CONFIG_PACKAGE_n2n-supernode is not set # CONFIG_PACKAGE_ocserv is not set # CONFIG_PACKAGE_openconnect is not set # CONFIG_PACKAGE_openfortivpn is not set # CONFIG_PACKAGE_openvpn-easy-rsa is not set # CONFIG_PACKAGE_openvpn-mbedtls is not set # CONFIG_PACKAGE_openvpn-nossl is not set # CONFIG_PACKAGE_openvpn-openssl is not set # CONFIG_PACKAGE_pptpd is not set # CONFIG_PACKAGE_softethervpn-base is not set # CONFIG_PACKAGE_softethervpn-bridge is not set # CONFIG_PACKAGE_softethervpn-client is not set # CONFIG_PACKAGE_softethervpn-server is not set # CONFIG_PACKAGE_softethervpn5-bridge is not set # CONFIG_PACKAGE_softethervpn5-client is not set # CONFIG_PACKAGE_softethervpn5-server is not set # CONFIG_PACKAGE_sstp-client is not set # CONFIG_PACKAGE_strongswan is not set # CONFIG_PACKAGE_tinc is not set # CONFIG_PACKAGE_uanytun is not set # CONFIG_PACKAGE_uanytun-nettle is not set # CONFIG_PACKAGE_uanytun-nocrypt is not set # CONFIG_PACKAGE_uanytun-sslcrypt is not set # CONFIG_PACKAGE_vpnc is not set # CONFIG_PACKAGE_vpnc-scripts is not set # CONFIG_PACKAGE_wireguard is not set # CONFIG_PACKAGE_xl2tpd is not set # CONFIG_PACKAGE_zerotier is not set # end of VPN # # Version Control Systems # # CONFIG_PACKAGE_git is not set # CONFIG_PACKAGE_git-http is not set # CONFIG_PACKAGE_subversion-client is not set # CONFIG_PACKAGE_subversion-libs is not set # CONFIG_PACKAGE_subversion-server is not set # end of Version Control Systems # # WWAN # # CONFIG_PACKAGE_adb-enablemodem is not set # CONFIG_PACKAGE_comgt is not set # CONFIG_PACKAGE_comgt-directip is not set # CONFIG_PACKAGE_umbim is not set # CONFIG_PACKAGE_uqmi is not set # end of WWAN # # Web Servers/Proxies # # CONFIG_PACKAGE_apache is not set # CONFIG_PACKAGE_cgi-io is not set # CONFIG_PACKAGE_clamav is not set # CONFIG_PACKAGE_e2guardian is not set # CONFIG_PACKAGE_etesync-server is not set # CONFIG_PACKAGE_freshclam is not set # CONFIG_PACKAGE_frpc is not set # CONFIG_PACKAGE_frps is not set # CONFIG_PACKAGE_haproxy is not set # CONFIG_PACKAGE_haproxy-nossl is not set # CONFIG_PACKAGE_kcptun-client is not set # CONFIG_PACKAGE_kcptun-server is not set # CONFIG_PACKAGE_lighttpd is not set CONFIG_PACKAGE_microsocks=y # CONFIG_PACKAGE_nginx is not set CONFIG_NGINX_NOPCRE=y # CONFIG_PACKAGE_nginx-all-module is not set # CONFIG_PACKAGE_nginx-mod-luci is not set # CONFIG_PACKAGE_nginx-mod-luci-ssl is not set # CONFIG_PACKAGE_nginx-ssl is not set # CONFIG_PACKAGE_nginx-ssl-util is not set # CONFIG_PACKAGE_nginx-ssl-util-nopcre is not set # CONFIG_PACKAGE_nginx-util is not set CONFIG_PACKAGE_pdnsd-alt=y # CONFIG_PACKAGE_polipo is not set # CONFIG_PACKAGE_privoxy is not set # CONFIG_PACKAGE_radicale is not set # CONFIG_PACKAGE_radicale2 is not set # CONFIG_PACKAGE_radicale2-examples is not set # CONFIG_PACKAGE_redsocks2 is not set # CONFIG_PACKAGE_shadowsocks-libev-config is not set CONFIG_PACKAGE_shadowsocks-libev-ss-local=y CONFIG_PACKAGE_shadowsocks-libev-ss-redir=y # CONFIG_PACKAGE_shadowsocks-libev-ss-rules is not set # CONFIG_PACKAGE_shadowsocks-libev-ss-server is not set # CONFIG_PACKAGE_shadowsocks-libev-ss-tunnel is not set # CONFIG_PACKAGE_shadowsocksr-libev is not set CONFIG_PACKAGE_shadowsocksr-libev-alt=y # CONFIG_PACKAGE_shadowsocksr-libev-server is not set CONFIG_PACKAGE_shadowsocksr-libev-ssr-local=y CONFIG_PACKAGE_simple-obfs=y # CONFIG_PACKAGE_simple-obfs-server is not set # # Simple-obfs Compile Configuration # # CONFIG_SIMPLE_OBFS_STATIC_LINK is not set # end of Simple-obfs Compile Configuration # CONFIG_PACKAGE_sockd is not set # CONFIG_PACKAGE_socksify is not set # CONFIG_PACKAGE_spawn-fcgi is not set # CONFIG_PACKAGE_squid is not set # CONFIG_PACKAGE_srelay is not set # CONFIG_PACKAGE_tinyproxy is not set # CONFIG_PACKAGE_trojan is not set CONFIG_PACKAGE_uhttpd=y # CONFIG_PACKAGE_uhttpd-mod-lua is not set CONFIG_PACKAGE_uhttpd-mod-ubus=y # CONFIG_PACKAGE_uwsgi is not set # end of Web Servers/Proxies # # Wireless # # CONFIG_PACKAGE_aircrack-ng is not set # CONFIG_PACKAGE_airmon-ng is not set # CONFIG_PACKAGE_dynapoint is not set # CONFIG_PACKAGE_hcxdumptool is not set # CONFIG_PACKAGE_hcxtools is not set # CONFIG_PACKAGE_horst is not set # CONFIG_PACKAGE_kismet-client is not set # CONFIG_PACKAGE_kismet-drone is not set # CONFIG_PACKAGE_kismet-server is not set # CONFIG_PACKAGE_pixiewps is not set # CONFIG_PACKAGE_reaver is not set # CONFIG_PACKAGE_wavemon is not set CONFIG_PACKAGE_wifischedule=y # end of Wireless # # WirelessAPD # # CONFIG_PACKAGE_eapol-test is not set # CONFIG_PACKAGE_eapol-test-openssl is not set # CONFIG_PACKAGE_eapol-test-wolfssl is not set # CONFIG_PACKAGE_hostapd is not set # CONFIG_PACKAGE_hostapd-basic is not set # CONFIG_PACKAGE_hostapd-basic-openssl is not set # CONFIG_PACKAGE_hostapd-basic-wolfssl is not set CONFIG_PACKAGE_hostapd-common=y # CONFIG_PACKAGE_hostapd-mini is not set # CONFIG_PACKAGE_hostapd-openssl is not set # CONFIG_PACKAGE_hostapd-utils is not set # CONFIG_PACKAGE_hostapd-wolfssl is not set # CONFIG_PACKAGE_wpa-cli is not set # CONFIG_PACKAGE_wpa-supplicant is not set # CONFIG_WPA_RFKILL_SUPPORT is not set CONFIG_WPA_MSG_MIN_PRIORITY=3 # CONFIG_WPA_WOLFSSL is not set # CONFIG_DRIVER_WEXT_SUPPORT is not set CONFIG_DRIVER_11N_SUPPORT=y CONFIG_DRIVER_11AC_SUPPORT=y # CONFIG_DRIVER_11AX_SUPPORT is not set CONFIG_DRIVER_11W_SUPPORT=y # CONFIG_WPA_ENABLE_WEP is not set # CONFIG_PACKAGE_wpa-supplicant-basic is not set # CONFIG_PACKAGE_wpa-supplicant-mesh-openssl is not set # CONFIG_PACKAGE_wpa-supplicant-mesh-wolfssl is not set # CONFIG_PACKAGE_wpa-supplicant-mini is not set # CONFIG_PACKAGE_wpa-supplicant-openssl is not set # CONFIG_PACKAGE_wpa-supplicant-p2p is not set # CONFIG_PACKAGE_wpa-supplicant-wolfssl is not set # CONFIG_PACKAGE_wpad is not set CONFIG_PACKAGE_wpad-basic=y # CONFIG_PACKAGE_wpad-basic-openssl is not set # CONFIG_PACKAGE_wpad-basic-wolfssl is not set # CONFIG_PACKAGE_wpad-mesh-openssl is not set # CONFIG_PACKAGE_wpad-mesh-wolfssl is not set # CONFIG_PACKAGE_wpad-mini is not set # CONFIG_PACKAGE_wpad-openssl is not set # CONFIG_PACKAGE_wpad-wolfssl is not set # end of WirelessAPD # # arp-scan # # CONFIG_PACKAGE_arp-scan is not set # CONFIG_PACKAGE_arp-scan-database is not set # end of arp-scan # CONFIG_PACKAGE_464xlat is not set # CONFIG_PACKAGE_6in4 is not set # CONFIG_PACKAGE_6rd is not set # CONFIG_PACKAGE_6to4 is not set # CONFIG_PACKAGE_acme is not set # CONFIG_PACKAGE_acme-dnsapi is not set # CONFIG_PACKAGE_adblock is not set CONFIG_PACKAGE_adbyby=y # CONFIG_PACKAGE_addrwatch is not set # CONFIG_PACKAGE_ahcpd is not set # CONFIG_PACKAGE_alfred is not set # CONFIG_PACKAGE_apcupsd is not set # CONFIG_PACKAGE_apcupsd-cgi is not set # CONFIG_PACKAGE_apinger is not set # CONFIG_PACKAGE_baidupcs-web is not set # CONFIG_PACKAGE_banip is not set # CONFIG_PACKAGE_batctl-default is not set # CONFIG_PACKAGE_batctl-full is not set # CONFIG_PACKAGE_batctl-tiny is not set # CONFIG_PACKAGE_beanstalkd is not set # CONFIG_PACKAGE_bmon is not set # CONFIG_PACKAGE_boinc is not set # CONFIG_PACKAGE_bwm-ng is not set # CONFIG_PACKAGE_bwping is not set # CONFIG_PACKAGE_chat is not set # CONFIG_PACKAGE_cifsmount is not set # CONFIG_PACKAGE_coap-server is not set # CONFIG_PACKAGE_conserver is not set # CONFIG_PACKAGE_cshark is not set # CONFIG_PACKAGE_daemonlogger is not set # CONFIG_PACKAGE_darkstat is not set # CONFIG_PACKAGE_dawn is not set # CONFIG_PACKAGE_dhcpcd is not set # CONFIG_PACKAGE_dmapd is not set # CONFIG_PACKAGE_dnscrypt-proxy2 is not set # CONFIG_PACKAGE_dnsforwarder is not set # CONFIG_PACKAGE_dnstop is not set # CONFIG_PACKAGE_ds-lite is not set # CONFIG_PACKAGE_dsmboot is not set # CONFIG_PACKAGE_esniper is not set # CONFIG_PACKAGE_etherwake is not set # CONFIG_PACKAGE_etherwake-nfqueue is not set # CONFIG_PACKAGE_ethtool is not set # CONFIG_PACKAGE_fakeidentd is not set # CONFIG_PACKAGE_family-dns is not set # CONFIG_PACKAGE_foolsm is not set # CONFIG_PACKAGE_fping is not set # CONFIG_PACKAGE_geth is not set # CONFIG_PACKAGE_gnunet is not set # CONFIG_PACKAGE_gre is not set # CONFIG_PACKAGE_hnet-full is not set # CONFIG_PACKAGE_hnet-full-l2tp is not set # CONFIG_PACKAGE_hnet-full-secure is not set # CONFIG_PACKAGE_hnetd-nossl is not set # CONFIG_PACKAGE_hnetd-openssl is not set # CONFIG_PACKAGE_httping is not set # CONFIG_PACKAGE_httping-nossl is not set # CONFIG_PACKAGE_https-dns-proxy is not set # CONFIG_PACKAGE_i2pd is not set # CONFIG_PACKAGE_ibrdtn-tools is not set # CONFIG_PACKAGE_ibrdtnd is not set # CONFIG_PACKAGE_ifstat is not set # CONFIG_PACKAGE_iftop is not set # CONFIG_PACKAGE_iiod is not set # CONFIG_PACKAGE_iperf is not set # CONFIG_PACKAGE_iperf3 is not set # CONFIG_PACKAGE_iperf3-ssl is not set # CONFIG_PACKAGE_ipip is not set CONFIG_PACKAGE_ipset=y # CONFIG_PACKAGE_ipset-dns is not set # CONFIG_PACKAGE_ipt2socks is not set # CONFIG_PACKAGE_iptraf-ng is not set # CONFIG_PACKAGE_iputils-arping is not set # CONFIG_PACKAGE_iputils-clockdiff is not set # CONFIG_PACKAGE_iputils-ping is not set # CONFIG_PACKAGE_iputils-ping6 is not set # CONFIG_PACKAGE_iputils-tftpd is not set # CONFIG_PACKAGE_iputils-tracepath is not set # CONFIG_PACKAGE_iputils-tracepath6 is not set # CONFIG_PACKAGE_iputils-traceroute6 is not set # CONFIG_PACKAGE_ipvsadm is not set CONFIG_PACKAGE_iw=y # CONFIG_PACKAGE_iw-full is not set # CONFIG_PACKAGE_jool is not set # CONFIG_PACKAGE_jool-tools is not set # CONFIG_PACKAGE_keepalived is not set # CONFIG_PACKAGE_knxd is not set # CONFIG_PACKAGE_kplex is not set # CONFIG_PACKAGE_krb5-client is not set # CONFIG_PACKAGE_krb5-libs is not set # CONFIG_PACKAGE_krb5-server is not set # CONFIG_PACKAGE_krb5-server-extras is not set CONFIG_PACKAGE_libipset=y # CONFIG_PACKAGE_libndp is not set # CONFIG_PACKAGE_linknx is not set # CONFIG_PACKAGE_lynx is not set # CONFIG_PACKAGE_mac-telnet-client is not set # CONFIG_PACKAGE_mac-telnet-discover is not set # CONFIG_PACKAGE_mac-telnet-ping is not set # CONFIG_PACKAGE_mac-telnet-server is not set # CONFIG_PACKAGE_map is not set # CONFIG_PACKAGE_memcached is not set # CONFIG_PACKAGE_mii-tool is not set # CONFIG_PACKAGE_mikrotik-btest is not set # CONFIG_PACKAGE_mini_snmpd is not set # CONFIG_PACKAGE_minimalist-pcproxy is not set # CONFIG_PACKAGE_miredo is not set # CONFIG_PACKAGE_modemmanager is not set # CONFIG_PACKAGE_mosquitto-client-nossl is not set # CONFIG_PACKAGE_mosquitto-client-ssl is not set # CONFIG_PACKAGE_mosquitto-nossl is not set # CONFIG_PACKAGE_mosquitto-ssl is not set # CONFIG_PACKAGE_mrd6 is not set # CONFIG_PACKAGE_mstpd is not set # CONFIG_PACKAGE_mtr is not set # CONFIG_PACKAGE_nbd is not set # CONFIG_PACKAGE_nbd-server is not set # CONFIG_PACKAGE_ncp is not set # CONFIG_PACKAGE_ndppd is not set # CONFIG_PACKAGE_ndptool is not set # CONFIG_PACKAGE_net-tools-route is not set # CONFIG_PACKAGE_netcat is not set # CONFIG_PACKAGE_netdiscover is not set # CONFIG_PACKAGE_netifyd is not set # CONFIG_PACKAGE_netperf is not set # CONFIG_PACKAGE_netsniff-ng is not set # CONFIG_PACKAGE_nextdns is not set # CONFIG_PACKAGE_nfdump is not set # CONFIG_PACKAGE_nlbwmon is not set # CONFIG_PACKAGE_noddos is not set # CONFIG_PACKAGE_noping is not set # CONFIG_PACKAGE_npc is not set # CONFIG_PACKAGE_nut is not set # CONFIG_PACKAGE_obfs4proxy is not set # CONFIG_PACKAGE_odhcp6c is not set # CONFIG_PACKAGE_odhcpd is not set # CONFIG_PACKAGE_odhcpd-ipv6only is not set # CONFIG_PACKAGE_ola is not set # CONFIG_PACKAGE_omcproxy is not set # CONFIG_PACKAGE_oor is not set # CONFIG_PACKAGE_oping is not set # CONFIG_PACKAGE_ostiary is not set # CONFIG_PACKAGE_pagekitec is not set # CONFIG_PACKAGE_pen is not set # CONFIG_PACKAGE_phantap is not set # CONFIG_PACKAGE_pimbd is not set # CONFIG_PACKAGE_pingcheck is not set # CONFIG_PACKAGE_port-mirroring is not set CONFIG_PACKAGE_ppp=y # CONFIG_PACKAGE_ppp-mod-passwordfd is not set # CONFIG_PACKAGE_ppp-mod-pppoa is not set CONFIG_PACKAGE_ppp-mod-pppoe=y # CONFIG_PACKAGE_ppp-mod-pppol2tp is not set # CONFIG_PACKAGE_ppp-mod-pptp is not set # CONFIG_PACKAGE_ppp-mod-radius is not set # CONFIG_PACKAGE_ppp-multilink is not set # CONFIG_PACKAGE_pppdump is not set # CONFIG_PACKAGE_pppoe-discovery is not set # CONFIG_PACKAGE_pppossh is not set # CONFIG_PACKAGE_pppstats is not set # CONFIG_PACKAGE_proto-bonding is not set # CONFIG_PACKAGE_proxychains-ng is not set # CONFIG_PACKAGE_ptunnel-ng is not set # CONFIG_PACKAGE_radsecproxy is not set # CONFIG_PACKAGE_ratechecker is not set # CONFIG_PACKAGE_redsocks is not set # CONFIG_PACKAGE_remserial is not set # CONFIG_PACKAGE_restic-rest-server is not set # CONFIG_PACKAGE_rpcbind is not set # CONFIG_PACKAGE_rssileds is not set # CONFIG_PACKAGE_rsyslog is not set # CONFIG_PACKAGE_safe-search is not set # CONFIG_PACKAGE_samba36-client is not set # CONFIG_PACKAGE_samba36-net is not set CONFIG_PACKAGE_samba36-server=y CONFIG_PACKAGE_SAMBA_MAX_DEBUG_LEVEL=-1 # CONFIG_PACKAGE_samba4-admin is not set # CONFIG_PACKAGE_samba4-client is not set # CONFIG_PACKAGE_samba4-libs is not set # CONFIG_PACKAGE_samba4-server is not set # CONFIG_PACKAGE_samba4-utils is not set # CONFIG_PACKAGE_scapy is not set # CONFIG_PACKAGE_sctp is not set # CONFIG_PACKAGE_sctp-tools is not set # CONFIG_PACKAGE_seafile-ccnet is not set # CONFIG_PACKAGE_seafile-seahub is not set # CONFIG_PACKAGE_seafile-server is not set # CONFIG_PACKAGE_seafile-server-fuse is not set # CONFIG_PACKAGE_ser2net is not set # CONFIG_PACKAGE_simple-adblock is not set # CONFIG_PACKAGE_smartdns is not set # CONFIG_PACKAGE_smartsnmpd is not set # CONFIG_PACKAGE_smbinfo is not set # CONFIG_PACKAGE_snmp-mibs is not set # CONFIG_PACKAGE_snmp-utils is not set # CONFIG_PACKAGE_snmpd is not set # CONFIG_PACKAGE_snmpd-static is not set # CONFIG_PACKAGE_snmptrapd is not set # CONFIG_PACKAGE_socat is not set # CONFIG_PACKAGE_softflowd is not set # CONFIG_PACKAGE_soloscli is not set # CONFIG_PACKAGE_speedtest-netperf is not set # CONFIG_PACKAGE_spoofer is not set # CONFIG_PACKAGE_stunnel is not set # CONFIG_PACKAGE_switchdev-poller is not set # CONFIG_PACKAGE_tac_plus is not set # CONFIG_PACKAGE_tac_plus-pam is not set # CONFIG_PACKAGE_tayga is not set # CONFIG_PACKAGE_tcpdump is not set # CONFIG_PACKAGE_tcpdump-mini is not set CONFIG_PACKAGE_tcping=y # CONFIG_PACKAGE_tcpping is not set # CONFIG_PACKAGE_tgt is not set # CONFIG_PACKAGE_tor is not set # CONFIG_PACKAGE_tor-fw-helper is not set # CONFIG_PACKAGE_tor-gencert is not set # CONFIG_PACKAGE_tor-geoip is not set # CONFIG_PACKAGE_tor-resolve is not set CONFIG_PACKAGE_travelmate=y # CONFIG_PACKAGE_u2pnpd is not set # CONFIG_PACKAGE_uacme is not set CONFIG_PACKAGE_uclient-fetch=y # CONFIG_PACKAGE_udptunnel is not set # CONFIG_PACKAGE_udpxy is not set # CONFIG_PACKAGE_ulogd is not set # CONFIG_PACKAGE_umdns is not set # CONFIG_PACKAGE_usbip is not set # CONFIG_PACKAGE_vallumd is not set # CONFIG_PACKAGE_verysync is not set # CONFIG_PACKAGE_vlmcsd is not set # CONFIG_PACKAGE_vncrepeater is not set # CONFIG_PACKAGE_vnstat is not set # CONFIG_PACKAGE_vnstat2 is not set # CONFIG_PACKAGE_vpn-policy-routing is not set # CONFIG_PACKAGE_vpnbypass is not set # CONFIG_PACKAGE_vsc7385-ucode-pb44 is not set # CONFIG_PACKAGE_vsc7395-ucode-pb44 is not set # CONFIG_PACKAGE_vti is not set # CONFIG_PACKAGE_vxlan is not set # CONFIG_PACKAGE_wakeonlan is not set # CONFIG_PACKAGE_wol is not set # CONFIG_PACKAGE_wpan-tools is not set # CONFIG_PACKAGE_wwan is not set # CONFIG_PACKAGE_xinetd is not set # end of Network # # Sound # # CONFIG_PACKAGE_alsa-utils is not set # CONFIG_PACKAGE_alsa-utils-seq is not set # CONFIG_PACKAGE_alsa-utils-tests is not set # CONFIG_PACKAGE_aserver is not set # CONFIG_PACKAGE_espeak is not set # CONFIG_PACKAGE_faad2 is not set # CONFIG_PACKAGE_fdk-aac is not set # CONFIG_PACKAGE_forked-daapd is not set # CONFIG_PACKAGE_ices is not set # CONFIG_PACKAGE_lame is not set # CONFIG_PACKAGE_lame-lib is not set # CONFIG_PACKAGE_liblo-utils is not set # CONFIG_PACKAGE_madplay is not set # CONFIG_PACKAGE_madplay-alsa is not set # CONFIG_PACKAGE_moc is not set # CONFIG_PACKAGE_mpc is not set # CONFIG_PACKAGE_mpd-avahi-service is not set # CONFIG_PACKAGE_mpd-full is not set # CONFIG_PACKAGE_mpd-mini is not set # CONFIG_PACKAGE_mpg123 is not set # CONFIG_PACKAGE_opus-tools is not set # CONFIG_PACKAGE_pianod is not set # CONFIG_PACKAGE_pianod-client is not set # CONFIG_PACKAGE_portaudio is not set # CONFIG_PACKAGE_pulseaudio-daemon is not set # CONFIG_PACKAGE_pulseaudio-daemon-avahi is not set # CONFIG_PACKAGE_shairplay is not set # CONFIG_PACKAGE_shairport-sync-mbedtls is not set # CONFIG_PACKAGE_shairport-sync-mini is not set # CONFIG_PACKAGE_shairport-sync-openssl is not set # CONFIG_PACKAGE_shine is not set # CONFIG_PACKAGE_sox is not set # CONFIG_PACKAGE_squeezelite-full is not set # CONFIG_PACKAGE_squeezelite-mini is not set # CONFIG_PACKAGE_svox is not set # CONFIG_PACKAGE_upmpdcli is not set # end of Sound # # Utilities # # # BigClown # # CONFIG_PACKAGE_bigclown-control-tool is not set # CONFIG_PACKAGE_bigclown-firmware-tool is not set # CONFIG_PACKAGE_bigclown-mqtt2influxdb is not set # end of BigClown # # Boot Loaders # # CONFIG_PACKAGE_fconfig is not set CONFIG_PACKAGE_uboot-envtools=y # end of Boot Loaders # # Compression # # CONFIG_PACKAGE_bsdtar is not set # CONFIG_PACKAGE_bsdtar-noopenssl is not set # CONFIG_PACKAGE_bzip2 is not set # CONFIG_PACKAGE_gzip is not set # CONFIG_PACKAGE_lz4 is not set # CONFIG_PACKAGE_pigz is not set # CONFIG_PACKAGE_unrar is not set # CONFIG_PACKAGE_unzip is not set # CONFIG_PACKAGE_xz-utils is not set # CONFIG_PACKAGE_zipcmp is not set # CONFIG_PACKAGE_zipmerge is not set # CONFIG_PACKAGE_ziptool is not set # CONFIG_PACKAGE_zstd is not set # end of Compression # # Database # # CONFIG_PACKAGE_mariadb-common is not set # CONFIG_PACKAGE_pgsql-cli is not set # CONFIG_PACKAGE_pgsql-cli-extra is not set # CONFIG_PACKAGE_pgsql-server is not set # CONFIG_PACKAGE_rrdcgi1 is not set # CONFIG_PACKAGE_rrdtool1 is not set # CONFIG_PACKAGE_sqlite3-cli is not set # CONFIG_PACKAGE_unixodbc-tools is not set # end of Database # # Disc # # CONFIG_PACKAGE_blkdiscard is not set # CONFIG_PACKAGE_blkid is not set # CONFIG_PACKAGE_blockdev is not set # CONFIG_PACKAGE_cfdisk is not set # CONFIG_PACKAGE_cgdisk is not set # CONFIG_PACKAGE_eject is not set # CONFIG_PACKAGE_fdisk is not set # CONFIG_PACKAGE_findfs is not set # CONFIG_PACKAGE_fio is not set # CONFIG_PACKAGE_fixparts is not set # CONFIG_PACKAGE_gdisk is not set CONFIG_PACKAGE_hd-idle=y # CONFIG_PACKAGE_hdparm is not set # CONFIG_PACKAGE_lsblk is not set # CONFIG_PACKAGE_lvm2 is not set # CONFIG_PACKAGE_mdadm is not set # CONFIG_PACKAGE_parted is not set # CONFIG_PACKAGE_partx-utils is not set # CONFIG_PACKAGE_sfdisk is not set # CONFIG_PACKAGE_sgdisk is not set # CONFIG_PACKAGE_wipefs is not set # end of Disc # # Editors # # CONFIG_PACKAGE_joe is not set # CONFIG_PACKAGE_jupp is not set # CONFIG_PACKAGE_mg is not set # CONFIG_PACKAGE_nano is not set # CONFIG_PACKAGE_vim is not set # CONFIG_PACKAGE_vim-full is not set # CONFIG_PACKAGE_vim-fuller is not set # CONFIG_PACKAGE_vim-help is not set # CONFIG_PACKAGE_vim-runtime is not set # CONFIG_PACKAGE_zile is not set # end of Editors # # Encryption # # CONFIG_PACKAGE_ccrypt is not set # CONFIG_PACKAGE_certtool is not set # CONFIG_PACKAGE_cryptsetup is not set # CONFIG_PACKAGE_gnupg is not set # CONFIG_PACKAGE_gnutls-utils is not set # CONFIG_PACKAGE_gpgv is not set # CONFIG_PACKAGE_keyctl is not set # CONFIG_PACKAGE_px5g-mbedtls is not set # CONFIG_PACKAGE_px5g-standalone is not set # CONFIG_PACKAGE_stoken is not set # end of Encryption # # Filesystem # # CONFIG_PACKAGE_acl is not set # CONFIG_PACKAGE_antfs-mount is not set # CONFIG_PACKAGE_attr is not set # CONFIG_PACKAGE_badblocks is not set # CONFIG_PACKAGE_btrfs-progs is not set # CONFIG_PACKAGE_chattr is not set # CONFIG_PACKAGE_debugfs is not set # CONFIG_PACKAGE_dosfstools is not set # CONFIG_PACKAGE_dumpe2fs is not set # CONFIG_PACKAGE_e2freefrag is not set # CONFIG_PACKAGE_e2fsprogs is not set # CONFIG_PACKAGE_e4crypt is not set # CONFIG_PACKAGE_exfat-fsck is not set # CONFIG_PACKAGE_exfat-mkfs is not set # CONFIG_PACKAGE_f2fs-tools is not set # CONFIG_PACKAGE_f2fsck is not set # CONFIG_PACKAGE_filefrag is not set # CONFIG_PACKAGE_fstrim is not set # CONFIG_PACKAGE_fuse-utils is not set # CONFIG_PACKAGE_hfsfsck is not set # CONFIG_PACKAGE_lsattr is not set # CONFIG_PACKAGE_mkf2fs is not set # CONFIG_PACKAGE_mkhfs is not set # CONFIG_PACKAGE_ncdu is not set # CONFIG_PACKAGE_nfs-utils is not set # CONFIG_PACKAGE_nfs-utils-libs is not set # CONFIG_PACKAGE_ntfs-3g is not set # CONFIG_PACKAGE_ntfs-3g-low is not set # CONFIG_PACKAGE_ntfs-3g-utils is not set # CONFIG_PACKAGE_owfs is not set # CONFIG_PACKAGE_owshell is not set # CONFIG_PACKAGE_resize2fs is not set # CONFIG_PACKAGE_squashfs-tools-mksquashfs is not set # CONFIG_PACKAGE_squashfs-tools-unsquashfs is not set # CONFIG_PACKAGE_swap-utils is not set # CONFIG_PACKAGE_sysfsutils is not set # CONFIG_PACKAGE_tune2fs is not set # CONFIG_PACKAGE_xfs-admin is not set # CONFIG_PACKAGE_xfs-fsck is not set # CONFIG_PACKAGE_xfs-growfs is not set # CONFIG_PACKAGE_xfs-mkfs is not set # end of Filesystem # # Image Manipulation # # CONFIG_PACKAGE_libjpeg-turbo-utils is not set # CONFIG_PACKAGE_tiff-utils is not set # end of Image Manipulation # # Microcontroller programming # # CONFIG_PACKAGE_avrdude is not set # CONFIG_PACKAGE_dfu-programmer is not set # CONFIG_PACKAGE_stm32flash is not set # end of Microcontroller programming # # RTKLIB Suite # # CONFIG_PACKAGE_convbin is not set # CONFIG_PACKAGE_pos2kml is not set # CONFIG_PACKAGE_rnx2rtkp is not set # CONFIG_PACKAGE_rtkrcv is not set # CONFIG_PACKAGE_str2str is not set # end of RTKLIB Suite # # Shells # # CONFIG_PACKAGE_bash is not set # CONFIG_PACKAGE_fish is not set # CONFIG_PACKAGE_klish is not set # CONFIG_PACKAGE_mksh is not set # CONFIG_PACKAGE_tcsh is not set # CONFIG_PACKAGE_zsh is not set # end of Shells # # Telephony # # CONFIG_PACKAGE_gsm-utils is not set # CONFIG_PACKAGE_sipgrep is not set # CONFIG_PACKAGE_sngrep is not set # end of Telephony # # Terminal # # CONFIG_PACKAGE_agetty is not set # CONFIG_PACKAGE_dvtm is not set # CONFIG_PACKAGE_minicom is not set # CONFIG_PACKAGE_picocom is not set # CONFIG_PACKAGE_rtty-mbedtls is not set # CONFIG_PACKAGE_rtty-nossl is not set # CONFIG_PACKAGE_rtty-openssl is not set # CONFIG_PACKAGE_rtty-wolfssl is not set # CONFIG_PACKAGE_screen is not set # CONFIG_PACKAGE_script-utils is not set # CONFIG_PACKAGE_serialconsole is not set # CONFIG_PACKAGE_setterm is not set # CONFIG_PACKAGE_tio is not set # CONFIG_PACKAGE_tmux is not set CONFIG_PACKAGE_ttyd=y # CONFIG_PACKAGE_wall is not set # end of Terminal # # Virtualization # # end of Virtualization # # Zoneinfo # # CONFIG_PACKAGE_zoneinfo-africa is not set # CONFIG_PACKAGE_zoneinfo-all is not set # CONFIG_PACKAGE_zoneinfo-asia is not set # CONFIG_PACKAGE_zoneinfo-atlantic is not set # CONFIG_PACKAGE_zoneinfo-australia-nz is not set # CONFIG_PACKAGE_zoneinfo-core is not set # CONFIG_PACKAGE_zoneinfo-europe is not set # CONFIG_PACKAGE_zoneinfo-india is not set # CONFIG_PACKAGE_zoneinfo-northamerica is not set # CONFIG_PACKAGE_zoneinfo-pacific is not set # CONFIG_PACKAGE_zoneinfo-poles is not set # CONFIG_PACKAGE_zoneinfo-simple is not set # CONFIG_PACKAGE_zoneinfo-southamerica is not set # end of Zoneinfo # # libimobiledevice # # CONFIG_PACKAGE_idevicerestore is not set # CONFIG_PACKAGE_irecovery is not set # CONFIG_PACKAGE_libimobiledevice-utils is not set # CONFIG_PACKAGE_libusbmuxd-utils is not set # CONFIG_PACKAGE_plistutil is not set # CONFIG_PACKAGE_usbmuxd is not set # end of libimobiledevice # CONFIG_PACKAGE_acpid is not set # CONFIG_PACKAGE_adb is not set # CONFIG_PACKAGE_ap51-flash is not set # CONFIG_PACKAGE_at is not set # CONFIG_PACKAGE_bandwidthd is not set # CONFIG_PACKAGE_bandwidthd-pgsql is not set # CONFIG_PACKAGE_bandwidthd-php is not set # CONFIG_PACKAGE_bandwidthd-sqlite is not set # CONFIG_PACKAGE_banhostlist is not set # CONFIG_PACKAGE_bc is not set # CONFIG_PACKAGE_bluelog is not set # CONFIG_PACKAGE_bluez-daemon is not set # CONFIG_PACKAGE_bluez-utils is not set # CONFIG_PACKAGE_bluez-utils-extra is not set # CONFIG_PACKAGE_bonniexx is not set # CONFIG_PACKAGE_bsdiff is not set # CONFIG_PACKAGE_bspatch is not set # CONFIG_PACKAGE_byobu is not set # CONFIG_PACKAGE_byobu-utils is not set # CONFIG_PACKAGE_cache-domains-mbedtls is not set # CONFIG_PACKAGE_cache-domains-openssl is not set # CONFIG_PACKAGE_cal is not set # CONFIG_PACKAGE_canutils is not set # CONFIG_PACKAGE_cgroup-tools is not set # CONFIG_PACKAGE_cgroupfs-mount is not set # CONFIG_PACKAGE_cmdpad is not set # CONFIG_PACKAGE_coap-client is not set # CONFIG_PACKAGE_collectd is not set CONFIG_PACKAGE_coremark=y CONFIG_PACKAGE_coreutils=y # CONFIG_PACKAGE_coreutils-b2sum is not set # CONFIG_PACKAGE_coreutils-base32 is not set CONFIG_PACKAGE_coreutils-base64=y # CONFIG_PACKAGE_coreutils-basename is not set # CONFIG_PACKAGE_coreutils-basenc is not set # CONFIG_PACKAGE_coreutils-cat is not set # CONFIG_PACKAGE_coreutils-chcon is not set # CONFIG_PACKAGE_coreutils-chgrp is not set # CONFIG_PACKAGE_coreutils-chmod is not set # CONFIG_PACKAGE_coreutils-chown is not set # CONFIG_PACKAGE_coreutils-chroot is not set # CONFIG_PACKAGE_coreutils-cksum is not set # CONFIG_PACKAGE_coreutils-comm is not set # CONFIG_PACKAGE_coreutils-cp is not set # CONFIG_PACKAGE_coreutils-csplit is not set # CONFIG_PACKAGE_coreutils-cut is not set # CONFIG_PACKAGE_coreutils-date is not set # CONFIG_PACKAGE_coreutils-dd is not set # CONFIG_PACKAGE_coreutils-df is not set # CONFIG_PACKAGE_coreutils-dir is not set # CONFIG_PACKAGE_coreutils-dircolors is not set # CONFIG_PACKAGE_coreutils-dirname is not set # CONFIG_PACKAGE_coreutils-du is not set # CONFIG_PACKAGE_coreutils-echo is not set # CONFIG_PACKAGE_coreutils-env is not set # CONFIG_PACKAGE_coreutils-expand is not set # CONFIG_PACKAGE_coreutils-expr is not set # CONFIG_PACKAGE_coreutils-factor is not set # CONFIG_PACKAGE_coreutils-false is not set # CONFIG_PACKAGE_coreutils-fmt is not set # CONFIG_PACKAGE_coreutils-fold is not set # CONFIG_PACKAGE_coreutils-groups is not set # CONFIG_PACKAGE_coreutils-head is not set # CONFIG_PACKAGE_coreutils-hostid is not set # CONFIG_PACKAGE_coreutils-id is not set # CONFIG_PACKAGE_coreutils-install is not set # CONFIG_PACKAGE_coreutils-join is not set # CONFIG_PACKAGE_coreutils-kill is not set # CONFIG_PACKAGE_coreutils-link is not set # CONFIG_PACKAGE_coreutils-ln is not set # CONFIG_PACKAGE_coreutils-logname is not set # CONFIG_PACKAGE_coreutils-ls is not set # CONFIG_PACKAGE_coreutils-md5sum is not set # CONFIG_PACKAGE_coreutils-mkdir is not set # CONFIG_PACKAGE_coreutils-mkfifo is not set # CONFIG_PACKAGE_coreutils-mknod is not set # CONFIG_PACKAGE_coreutils-mktemp is not set # CONFIG_PACKAGE_coreutils-mv is not set # CONFIG_PACKAGE_coreutils-nice is not set # CONFIG_PACKAGE_coreutils-nl is not set # CONFIG_PACKAGE_coreutils-nohup is not set # CONFIG_PACKAGE_coreutils-nproc is not set # CONFIG_PACKAGE_coreutils-numfmt is not set # CONFIG_PACKAGE_coreutils-od is not set # CONFIG_PACKAGE_coreutils-paste is not set # CONFIG_PACKAGE_coreutils-pathchk is not set # CONFIG_PACKAGE_coreutils-pinky is not set # CONFIG_PACKAGE_coreutils-pr is not set # CONFIG_PACKAGE_coreutils-printenv is not set # CONFIG_PACKAGE_coreutils-printf is not set # CONFIG_PACKAGE_coreutils-ptx is not set # CONFIG_PACKAGE_coreutils-pwd is not set # CONFIG_PACKAGE_coreutils-readlink is not set # CONFIG_PACKAGE_coreutils-realpath is not set # CONFIG_PACKAGE_coreutils-rm is not set # CONFIG_PACKAGE_coreutils-rmdir is not set # CONFIG_PACKAGE_coreutils-runcon is not set # CONFIG_PACKAGE_coreutils-seq is not set # CONFIG_PACKAGE_coreutils-sha1sum is not set # CONFIG_PACKAGE_coreutils-sha224sum is not set # CONFIG_PACKAGE_coreutils-sha256sum is not set # CONFIG_PACKAGE_coreutils-sha384sum is not set # CONFIG_PACKAGE_coreutils-sha512sum is not set # CONFIG_PACKAGE_coreutils-shred is not set # CONFIG_PACKAGE_coreutils-shuf is not set # CONFIG_PACKAGE_coreutils-sleep is not set # CONFIG_PACKAGE_coreutils-sort is not set # CONFIG_PACKAGE_coreutils-split is not set # CONFIG_PACKAGE_coreutils-stat is not set # CONFIG_PACKAGE_coreutils-stdbuf is not set # CONFIG_PACKAGE_coreutils-stty is not set # CONFIG_PACKAGE_coreutils-sum is not set # CONFIG_PACKAGE_coreutils-sync is not set # CONFIG_PACKAGE_coreutils-tac is not set # CONFIG_PACKAGE_coreutils-tail is not set # CONFIG_PACKAGE_coreutils-tee is not set # CONFIG_PACKAGE_coreutils-test is not set # CONFIG_PACKAGE_coreutils-timeout is not set # CONFIG_PACKAGE_coreutils-touch is not set # CONFIG_PACKAGE_coreutils-tr is not set # CONFIG_PACKAGE_coreutils-true is not set # CONFIG_PACKAGE_coreutils-truncate is not set # CONFIG_PACKAGE_coreutils-tsort is not set # CONFIG_PACKAGE_coreutils-tty is not set # CONFIG_PACKAGE_coreutils-uname is not set # CONFIG_PACKAGE_coreutils-unexpand is not set # CONFIG_PACKAGE_coreutils-uniq is not set # CONFIG_PACKAGE_coreutils-unlink is not set # CONFIG_PACKAGE_coreutils-uptime is not set # CONFIG_PACKAGE_coreutils-users is not set # CONFIG_PACKAGE_coreutils-vdir is not set # CONFIG_PACKAGE_coreutils-wc is not set # CONFIG_PACKAGE_coreutils-who is not set # CONFIG_PACKAGE_coreutils-whoami is not set # CONFIG_PACKAGE_coreutils-yes is not set # CONFIG_PACKAGE_crconf is not set # CONFIG_PACKAGE_crelay is not set # CONFIG_PACKAGE_csstidy is not set # CONFIG_PACKAGE_ct-bugcheck is not set # CONFIG_PACKAGE_dbus is not set # CONFIG_PACKAGE_dbus-utils is not set # CONFIG_PACKAGE_device-observatory is not set # CONFIG_PACKAGE_dfu-util is not set # CONFIG_PACKAGE_digitemp is not set # CONFIG_PACKAGE_digitemp-usb is not set # CONFIG_PACKAGE_dmesg is not set # CONFIG_PACKAGE_domoticz is not set # CONFIG_PACKAGE_dropbearconvert is not set # CONFIG_PACKAGE_dtc is not set # CONFIG_PACKAGE_dump1090 is not set # CONFIG_PACKAGE_ecdsautils is not set # CONFIG_PACKAGE_elektra-kdb is not set # CONFIG_PACKAGE_evtest is not set # CONFIG_PACKAGE_extract is not set # CONFIG_PACKAGE_fdt-utils is not set # CONFIG_PACKAGE_file is not set # CONFIG_PACKAGE_findutils is not set # CONFIG_PACKAGE_findutils-find is not set # CONFIG_PACKAGE_findutils-locate is not set # CONFIG_PACKAGE_findutils-xargs is not set # CONFIG_PACKAGE_flashrom is not set # CONFIG_PACKAGE_flashrom-pci is not set # CONFIG_PACKAGE_flashrom-spi is not set # CONFIG_PACKAGE_flashrom-usb is not set # CONFIG_PACKAGE_flent-tools is not set # CONFIG_PACKAGE_flock is not set # CONFIG_PACKAGE_fritz-caldata is not set # CONFIG_PACKAGE_fritz-tffs is not set # CONFIG_PACKAGE_fritz-tffs-nand is not set # CONFIG_PACKAGE_ftdi_eeprom is not set # CONFIG_PACKAGE_gammu is not set # CONFIG_PACKAGE_gawk is not set # CONFIG_PACKAGE_gddrescue is not set # CONFIG_PACKAGE_getopt is not set # CONFIG_PACKAGE_giflib-utils is not set # CONFIG_PACKAGE_gkermit is not set # CONFIG_PACKAGE_gnuplot is not set # CONFIG_PACKAGE_gpioctl-sysfs is not set # CONFIG_PACKAGE_gpiod-tools is not set # CONFIG_PACKAGE_gpsd is not set # CONFIG_PACKAGE_gpsd-clients is not set # CONFIG_PACKAGE_grep is not set # CONFIG_PACKAGE_hamlib is not set # CONFIG_PACKAGE_haserl is not set # CONFIG_PACKAGE_hashdeep is not set # CONFIG_PACKAGE_haveged is not set # CONFIG_PACKAGE_hplip-common is not set # CONFIG_PACKAGE_hplip-sane is not set # CONFIG_PACKAGE_hub-ctrl is not set # CONFIG_PACKAGE_hwclock is not set # CONFIG_PACKAGE_hwinfo is not set # CONFIG_PACKAGE_hwloc-utils is not set # CONFIG_PACKAGE_i2c-tools is not set # CONFIG_PACKAGE_iconv is not set # CONFIG_PACKAGE_iio-utils is not set # CONFIG_PACKAGE_inotifywait is not set # CONFIG_PACKAGE_inotifywatch is not set # CONFIG_PACKAGE_io is not set # CONFIG_PACKAGE_ipfs-http-client-tests is not set # CONFIG_PACKAGE_irqbalance is not set # CONFIG_PACKAGE_iwcap is not set CONFIG_PACKAGE_iwinfo=y # CONFIG_PACKAGE_jq is not set CONFIG_PACKAGE_jshn=y # CONFIG_PACKAGE_kmod is not set # CONFIG_PACKAGE_lcd4linux-custom is not set # CONFIG_PACKAGE_lcdproc-clients is not set # CONFIG_PACKAGE_lcdproc-drivers is not set # CONFIG_PACKAGE_lcdproc-server is not set # CONFIG_PACKAGE_less is not set # CONFIG_PACKAGE_less-wide is not set CONFIG_PACKAGE_libjson-script=y # CONFIG_PACKAGE_libxml2-utils is not set # CONFIG_PACKAGE_lm-sensors is not set # CONFIG_PACKAGE_lm-sensors-detect is not set # CONFIG_PACKAGE_logger is not set # CONFIG_PACKAGE_logrotate is not set # CONFIG_PACKAGE_look is not set # CONFIG_PACKAGE_losetup is not set # CONFIG_PACKAGE_lrzsz is not set # CONFIG_PACKAGE_lscpu is not set # CONFIG_PACKAGE_lsof is not set # CONFIG_PACKAGE_lxc is not set # CONFIG_PACKAGE_maccalc is not set # CONFIG_PACKAGE_macchanger is not set # CONFIG_PACKAGE_mbedtls-util is not set # CONFIG_PACKAGE_mbim-utils is not set # CONFIG_PACKAGE_mbtools is not set # CONFIG_PACKAGE_mc is not set # CONFIG_PACKAGE_mcookie is not set # CONFIG_PACKAGE_micrond is not set # CONFIG_PACKAGE_mmc-utils is not set # CONFIG_PACKAGE_more is not set # CONFIG_PACKAGE_moreutils is not set # CONFIG_PACKAGE_mosh-client is not set # CONFIG_PACKAGE_mosh-server is not set # CONFIG_PACKAGE_mount-utils is not set # CONFIG_PACKAGE_mpack is not set # CONFIG_PACKAGE_mt-st is not set # CONFIG_PACKAGE_namei is not set # CONFIG_PACKAGE_netopeer2-cli is not set # CONFIG_PACKAGE_netopeer2-keystored is not set # CONFIG_PACKAGE_netopeer2-server is not set # CONFIG_PACKAGE_netwhere is not set # CONFIG_PACKAGE_nnn is not set # CONFIG_PACKAGE_nsenter is not set # CONFIG_PACKAGE_nss-utils is not set # CONFIG_PACKAGE_oath-toolkit is not set # CONFIG_PACKAGE_open-plc-utils is not set # CONFIG_PACKAGE_open2300 is not set # CONFIG_PACKAGE_openobex is not set # CONFIG_PACKAGE_openobex-apps is not set # CONFIG_PACKAGE_openocd is not set # CONFIG_PACKAGE_opensc-utils is not set CONFIG_PACKAGE_openssl-util=y # CONFIG_PACKAGE_openzwave is not set # CONFIG_PACKAGE_openzwave-config is not set # CONFIG_PACKAGE_owipcalc is not set # CONFIG_PACKAGE_pciutils is not set # CONFIG_PACKAGE_pcsc-tools is not set # CONFIG_PACKAGE_pcscd is not set # CONFIG_PACKAGE_powertop is not set # CONFIG_PACKAGE_pps-tools is not set # CONFIG_PACKAGE_prlimit is not set # CONFIG_PACKAGE_procps-ng is not set # CONFIG_PACKAGE_progress is not set # CONFIG_PACKAGE_prometheus is not set # CONFIG_PACKAGE_prometheus-node-exporter-lua is not set # CONFIG_PACKAGE_prometheus-statsd-exporter is not set # CONFIG_PACKAGE_pservice is not set # CONFIG_PACKAGE_pv is not set # CONFIG_PACKAGE_qmi-utils is not set # CONFIG_PACKAGE_qrencode is not set # CONFIG_PACKAGE_quota is not set # CONFIG_PACKAGE_ravpower-mcu is not set # CONFIG_PACKAGE_rclone is not set # CONFIG_PACKAGE_readsb is not set # CONFIG_PACKAGE_relayctl is not set # CONFIG_PACKAGE_rename is not set # CONFIG_PACKAGE_restic is not set # CONFIG_PACKAGE_rng-tools is not set # CONFIG_PACKAGE_rtl-ais is not set # CONFIG_PACKAGE_rtl-sdr is not set # CONFIG_PACKAGE_rtl_433 is not set # CONFIG_PACKAGE_sane-backends is not set # CONFIG_PACKAGE_sane-daemon is not set # CONFIG_PACKAGE_sane-frontends is not set # CONFIG_PACKAGE_sed is not set # CONFIG_PACKAGE_serdisplib-tools is not set # CONFIG_PACKAGE_setserial is not set # CONFIG_PACKAGE_shadow-utils is not set CONFIG_PACKAGE_shellsync=y # CONFIG_PACKAGE_sispmctl is not set # CONFIG_PACKAGE_slide-switch is not set # CONFIG_PACKAGE_smartd is not set # CONFIG_PACKAGE_smartd-mail is not set # CONFIG_PACKAGE_smartmontools is not set # CONFIG_PACKAGE_smartmontools-drivedb is not set # CONFIG_PACKAGE_smstools3 is not set # CONFIG_PACKAGE_sockread is not set # CONFIG_PACKAGE_spi-tools is not set # CONFIG_PACKAGE_spidev-test is not set # CONFIG_PACKAGE_ssdeep is not set # CONFIG_PACKAGE_sshpass is not set # CONFIG_PACKAGE_strace is not set CONFIG_STRACE_NONE=y # CONFIG_STRACE_LIBDW is not set # CONFIG_STRACE_LIBUNWIND is not set # CONFIG_PACKAGE_stress is not set # CONFIG_PACKAGE_sumo is not set # CONFIG_PACKAGE_syncthing is not set # CONFIG_PACKAGE_sysrepo is not set # CONFIG_PACKAGE_sysrepocfg is not set # CONFIG_PACKAGE_sysrepoctl is not set # CONFIG_PACKAGE_sysstat is not set # CONFIG_PACKAGE_tar is not set # CONFIG_PACKAGE_taskwarrior is not set # CONFIG_PACKAGE_telldus-core is not set # CONFIG_PACKAGE_temperusb is not set # CONFIG_PACKAGE_tesseract is not set # CONFIG_PACKAGE_tini is not set # CONFIG_PACKAGE_tracertools is not set # CONFIG_PACKAGE_tree is not set # CONFIG_PACKAGE_triggerhappy is not set # CONFIG_PACKAGE_udns-dnsget is not set # CONFIG_PACKAGE_udns-ex-rdns is not set # CONFIG_PACKAGE_udns-rblcheck is not set # CONFIG_PACKAGE_ugps is not set # CONFIG_PACKAGE_uledd is not set # CONFIG_PACKAGE_unshare is not set CONFIG_PACKAGE_usb-modeswitch=y # CONFIG_PACKAGE_usbreset is not set # CONFIG_PACKAGE_usbutils is not set # CONFIG_PACKAGE_uuidd is not set # CONFIG_PACKAGE_uuidgen is not set # CONFIG_PACKAGE_uvcdynctrl is not set # CONFIG_PACKAGE_v4l-utils is not set # CONFIG_PACKAGE_view1090 is not set # CONFIG_PACKAGE_viewadsb is not set # CONFIG_PACKAGE_watchcat is not set # CONFIG_PACKAGE_whereis is not set # CONFIG_PACKAGE_which is not set # CONFIG_PACKAGE_whiptail is not set # CONFIG_PACKAGE_wifitoggle is not set # CONFIG_PACKAGE_wipe is not set # CONFIG_PACKAGE_xsltproc is not set # CONFIG_PACKAGE_xxd is not set # CONFIG_PACKAGE_yanglint is not set # CONFIG_PACKAGE_yara is not set # CONFIG_PACKAGE_ykpers is not set # end of Utilities # # Xorg # # # Font-Utils # # CONFIG_PACKAGE_fontconfig is not set # end of Font-Utils # end of Xorg
d1bdfb905ea0ba3d316e1aeee2be0a373b2f96e5
cf39355caa609c0f33405126beee2739aa3cb77e
/library/init/meta/widget/tactic_component.lean
0e667311bdde66bdd5c363d4aee8cb3511a43124
[ "Apache-2.0" ]
permissive
leanprover-community/lean
12b87f69d92e614daea8bcc9d4de9a9ace089d0e
cce7990ea86a78bdb383e38ed7f9b5ba93c60ce0
refs/heads/master
1,687,508,156,644
1,684,951,104,000
1,684,951,104,000
169,960,991
457
107
Apache-2.0
1,686,744,372,000
1,549,790,268,000
C++
UTF-8
Lean
false
false
2,454
lean
/- Copyright (c) E.W.Ayers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: E.W.Ayers -/ prelude import init.meta.widget.basic namespace widget /-- A component that implicitly depends on tactic_state. For efficiency we always assume that the tactic_state is unchanged between component renderings. -/ meta def tc (π : Type) (α : Type) := component (tactic_state × π) (α) namespace tc variables {π ρ α β : Type} meta def of_component : component π α → tc π α := component.map_props prod.snd meta def map_action (f : α → β) : tc π α → tc π β := component.map_action f meta def map_props (f : π → ρ) : tc ρ α → tc π α := component.map_props (prod.map id f) open interaction_monad open interaction_monad.result /-- Make a tactic component from some init, update, views which are expecting a tactic. The tactic_state never mutates. -/ meta def mk_simple [decidable_eq π] (β σ : Type) (init : π → tactic σ) (update : π → σ → β → tactic (σ × option α)) (view : π → σ → tactic (list (html β))) : tc π α := component.with_should_update (λ ⟨_,old_p⟩ ⟨_,new_p⟩, old_p ≠ new_p) $ @component.stateful (tactic_state × π) α β (interaction_monad.result tactic_state σ) (λ ⟨ts,p⟩ last, match last with | (some x) := x | none := init p ts end) (λ ⟨ts,p⟩ s b, match s with | (success s _) := match update p s b ts with | (success ⟨s,a⟩ _) := prod.mk (success s ts) (a) | (exception m p ts') := prod.mk (exception m p ts') none end | x := ⟨x,none⟩ end ) (λ ⟨ts,p⟩ s, match s with | (success s _) := match view p s ts with | (success h _) := h | (exception msg pos s) := ["rendering tactic failed "] end | (exception msg pos s) := ["state of tactic component has failed!"] end ) meta def stateless [decidable_eq π] (view : π → tactic (list (html α))) : tc π α := tc.mk_simple α unit (λ p, pure ()) (λ _ _ b, pure ((),some b)) (λ p _, view p) meta def to_html : tc π α → π → tactic (html α) | c p ts := success (html.of_component (ts,p) c) ts meta def to_component : tc unit α → component tactic_state α | c := component.map_props (λ tc, (tc,())) c meta instance : has_coe_to_fun (tc π α) (λ x, π → tactic (html α)) := ⟨to_html⟩ end tc end widget
974bda87ebb81bd77fa5c68f04a94a6d1dbaaaf3
9cba98daa30c0804090f963f9024147a50292fa0
/old/metrology/unit.lean
bd4d75624e9819fe4b5955791de2ba311fc8a3c3
[]
no_license
kevinsullivan/phys
dcb192f7b3033797541b980f0b4a7e75d84cea1a
ebc2df3779d3605ff7a9b47eeda25c2a551e011f
refs/heads/master
1,637,490,575,500
1,629,899,064,000
1,629,899,064,000
168,012,884
0
3
null
1,629,644,436,000
1,548,699,832,000
Lean
UTF-8
Lean
false
false
313
lean
namespace unit inductive length : Type | meter | centimeter | foot inductive mass : Type | kilogram | pound inductive time : Type | second inductive current : Type | ampere inductive temperature : Type | kelvin | fahrenheit inductive quantity : Type | mole inductive intensity : Type | candela end unit
7ff4368170b8b8e51e2a4a8ef6192929bb73cb5f
88fb7558b0636ec6b181f2a548ac11ad3919f8a5
/library/data/hash_map.lean
b4969259e1ab40a6380674101155406dbd804e22
[ "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
4,601
lean
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura -/ universes u v w def bucket_array (α : Type u) (β : α → Type v) (n : nat) := array (list (Σ a, β a)) n structure hash_map (α : Type u) [decidable_eq α] (β : α → Type v) := (hash_fn : α → nat) (size nbuckets : nat) (nz_buckets : nbuckets > 0) (buckets : bucket_array α β nbuckets) def mk_hash_map {α : Type u} [decidable_eq α] {β : α → Type v} (hash_fn : α → nat) (nbuckets := 8) : hash_map α β := let n := if nbuckets = 0 then 8 else nbuckets in {hash_fn := hash_fn, size := 0, nbuckets := n, nz_buckets := by abstract {dsimp, cases nbuckets, {simp, tactic.comp_val}, simp [if_pos, nat.succ_ne_zero], apply nat.zero_lt_succ}, buckets := mk_array n [] } namespace hash_map variables {α : Type u} {β : α → Type v} {δ : Type w} def mk_idx {n : nat} (h : n > 0) (i : nat) : fin n := ⟨i % n, nat.mod_lt _ h⟩ def reinsert_aux (hash_fn : α → nat) {n : nat} (h : n > 0) (data : bucket_array α β n) (a : α) (b : β a) : bucket_array α β n := let bidx := mk_idx h (hash_fn a) in data.write bidx (⟨a, b⟩ :: data.read bidx) def fold_buckets {n : nat} (data : bucket_array α β n) (d : δ) (f : δ → Π a, β a → δ) : δ := data.foldl d (λ b d, b.foldl (λ r (p : Σ a, β a), f r p.1 p.2) d) variable [decidable_eq α] def find_aux (a : α) : list (Σ a, β a) → option (β a) | [] := none | (⟨a',b⟩::t) := if h : a' = a then some (eq.rec_on h b) else find_aux t def contains_aux (a : α) (l : list (Σ a, β a)) : bool := (find_aux a l).is_some def find (m : hash_map α β) (a : α) : option (β a) := match m with | ⟨hash_fn, _, nbuckets, nz, buckets⟩ := find_aux a (buckets.read (mk_idx nz (hash_fn a))) end def contains (m : hash_map α β) (a : α) : bool := (find m a).is_some def fold [decidable_eq α] (m : hash_map α β) (d : δ) (f : δ → Π a, β a → δ) : δ := fold_buckets m.buckets d f def replace_aux (a : α) (b : β a) : list (Σ a, β a) → list (Σ a, β a) | [] := [] | (⟨a', b'⟩::t) := if a' = a then ⟨a, b⟩::t else ⟨a', b'⟩ :: replace_aux t def erase_aux (a : α) : list (Σ a, β a) → list (Σ a, β a) | [] := [] | (⟨a', b'⟩::t) := if a' = a then t else ⟨a', b'⟩ :: erase_aux t def insert (m : hash_map α β) (a : α) (b : β a) : hash_map α β := match m with | ⟨hash_fn, size, nbuckets, nz, buckets⟩ := let bidx := mk_idx nz (hash_fn a) in let bkt := buckets.read bidx in if contains_aux a bkt then ⟨hash_fn, size, nbuckets, nz, buckets.write bidx (replace_aux a b bkt)⟩ else let size' := size + 1 in let buckets' := buckets.write bidx (⟨a, b⟩::bkt) in if size' <= nbuckets then ⟨hash_fn, size', nbuckets, nz, buckets'⟩ else let nbuckets' := nbuckets * 2 in let nz' : nbuckets' > 0 := mul_pos nz dec_trivial in ⟨hash_fn, size', nbuckets', nz', fold_buckets buckets' (mk_array nbuckets' []) $ λ r a b, reinsert_aux hash_fn nz' r a b⟩ end def erase (m : hash_map α β) (a : α) : hash_map α β := match m with | ⟨hash_fn, size, nbuckets, nz, buckets⟩ := let bidx : fin nbuckets := ⟨hash_fn a % nbuckets, nat.mod_lt _ nz⟩ in let bkt := buckets.read bidx in if contains_aux a bkt then ⟨hash_fn, size - 1, nbuckets, nz, buckets.write bidx $ erase_aux a bkt⟩ else m end section string variables [has_to_string α] [∀ a, has_to_string (β a)] open prod private def key_data_to_string (a : α) (b : β a) (first : bool) : string := (if first then "" else ", ") ++ to_string a ++ " ← " ++ to_string b private def to_string (m : hash_map α β) : string := "⟨" ++ (fst (fold m ("", tt) (λ p a b, (fst p ++ key_data_to_string a b (snd p), ff)))) ++ "⟩" instance : has_to_string (hash_map α β) := ⟨to_string⟩ end string section format open format prod variables [has_to_format α] [∀ a, has_to_format (β a)] private meta def format_key_data (a : α) (b : β a) (first : bool) : format := (if first then to_fmt "" else to_fmt "," ++ line) ++ to_fmt a ++ space ++ to_fmt "←" ++ space ++ to_fmt b private meta def to_format (m : hash_map α β) : format := group $ to_fmt "⟨" ++ nest 1 (fst (fold m (to_fmt "", tt) (λ p a b, (fst p ++ format_key_data a b (snd p), ff)))) ++ to_fmt "⟩" meta instance : has_to_format (hash_map α β) := ⟨to_format⟩ end format end hash_map
d7cfc52a0d3faebbaf18e625d4219956ff70fe63
6305b69bc7636a761e1a1947508bb5ebad93cb7e
/leanpkg/leanpkg/main.lean
7024c203db3ea4abc84415429da4fed3d52dcc89
[ "Apache-2.0" ]
permissive
HGldJ1966/lean
e7f0068f8a69fde3593b77d8a44609ae446d7738
049d940167c419cd5935d12b459c0695d8615ae9
refs/heads/master
1,611,340,395,700
1,503,103,829,000
1,503,103,829,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
7,699
lean
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Gabriel Ebner -/ import leanpkg.resolve variable [io.interface] namespace leanpkg def write_file (fn : string) (cnts : string) (mode := io.mode.write) : io unit := do h ← io.mk_file_handle fn io.mode.write, io.fs.write h cnts.to_char_buffer, io.fs.close h def read_manifest : io manifest := manifest.from_file leanpkg_toml_fn def write_manifest (d : manifest) (fn := leanpkg_toml_fn) : io unit := write_file fn (repr d) -- TODO(gabriel): implement a cross-platform api def get_dot_lean_dir : io string := do some home ← io.env.get "HOME" | io.fail "environment variable HOME is not set", return $ home ++ "/.lean" -- TODO(gabriel): file existence testing def exists_file (f : string) : io bool := do ch ← io.proc.spawn { cmd := "test", args := ["-f", f] }, ev ← io.proc.wait ch, return $ ev = 0 -- TODO(gabriel): io.env.get_current_directory def get_current_directory : io string := do cwd ← io.cmd { cmd := "pwd" }, return cwd.pop_back -- remove final newline def mk_path_file : ∀ (paths : list string), string | [] := "builtin_path\n" | (x :: xs) := mk_path_file xs ++ "path " ++ x ++ "\n" def configure : io unit := do d ← read_manifest, io.put_str_ln $ "configuring " ++ d.name ++ " " ++ d.version, assg ← solve_deps d, path_file_cnts ← mk_path_file <$> construct_path assg, write_file "leanpkg.path" path_file_cnts def make (lean_args : list string) : io unit := do manifest ← read_manifest, exec_cmd { cmd := "lean", args := (match manifest.timeout with some t := ["-T", repr t] | none := [] end) ++ ["--make"] ++ manifest.effective_path ++ lean_args, env := [("LEAN_PATH", none)] } def build (lean_args : list string) := configure >> make lean_args def make_test (lean_args : list string) : io unit := exec_cmd { cmd := "lean", args := ["--make", "test"] ++ lean_args, env := [("LEAN_PATH", none)] } def test (lean_args : list string) := build lean_args >> make_test lean_args def init_gitignore_contents := "*.olean /_target /leanpkg.path " def init_pkg (n : string) (dir : string) : io unit := do write_manifest { name := n, version := "0.1" } (dir ++ "/" ++ leanpkg_toml_fn), write_file (dir ++ "/.gitignore") init_gitignore_contents io.mode.append, exec_cmd {cmd := "leanpkg", args := ["configure"], cwd := dir} def init (n : string) := init_pkg n "." -- TODO(gabriel): windows def basename (s : string) : string := s.fold "" $ λ s c, if c = '/' then "" else s.str c def add_dep_to_manifest (dep : dependency) : io unit := do d ← read_manifest, let d' := { d with dependencies := d.dependencies.filter (λ old_dep, old_dep.name ≠ dep.name) ++ [dep] }, write_manifest d' def strip_dot_git (url : string) : string := if url.backn 4 = ".git" then url.popn_back 4 else url def looks_like_git_url (dep : string) : bool := ':' ∈ dep.to_list def absolutize_add_dep (dep : string) : io string := if looks_like_git_url dep then return dep else resolve_dir dep <$> get_current_directory def parse_add_dep (dep : string) : dependency := if looks_like_git_url dep then { name := basename (strip_dot_git dep), src := source.git dep "master" } else { name := basename dep, src := source.path dep } def git_head_revision (git_repo_dir : string) : io string := do rev ← io.cmd {cmd := "git", args := ["rev-parse", "HEAD"], cwd := git_repo_dir}, return rev.pop_back -- remove newline at end def git_latest_origin_revision (git_repo_dir : string) : io string := do io.cmd {cmd := "git", args := ["fetch"], cwd := git_repo_dir}, rev ← io.cmd {cmd := "git", args := ["rev-parse", "origin/master"], cwd := git_repo_dir}, return rev.pop_back -- remove newline at end def fixup_git_version (dir : string) : ∀ (src : source), io source | (source.git url _) := source.git url <$> git_head_revision dir | src := return src def add (dep : string) : io unit := do let dep := parse_add_dep dep, (_, assg) ← materialize "." dep assignment.empty, some downloaded_path ← return (assg.find dep.name), manif ← manifest.from_file (downloaded_path ++ "/" ++ leanpkg_toml_fn), src ← fixup_git_version downloaded_path dep.src, let dep := { dep with name := manif.name, src := src }, add_dep_to_manifest dep, configure def new (dir : string) := do ex ← dir_exists dir, when ex $ io.fail $ "directory already exists: " ++ dir, exec_cmd {cmd := "mkdir", args := ["-p", dir]}, init_pkg (basename dir) dir def upgrade_dep (assg : assignment) (d : dependency) : io dependency := match d.src with | (source.git url rev) := (do some path ← return (assg.find d.name) | io.fail "unresolved dependency", new_rev ← git_latest_origin_revision path, return {d with src := source.git url new_rev}) <|> return d | _ := return d end def upgrade := do m ← read_manifest, assg ← solve_deps m, ds' ← m.dependencies.mmap (upgrade_dep assg), write_manifest {m with dependencies := ds'}, configure def usage := " Usage: leanpkg <command> configure download dependencies build [-- <lean-args>] download dependencies and build *.olean files test [-- <lean-args>] download dependencies, build *.olean files, and run test files new <dir> creates a lean package in the specified directory init <name> adds a leanpkg.toml file to the current directory, and sets up .gitignore add <url> adds a dependency from a git repository (uses current master revision) add <dir> adds a local dependency upgrade upgrades all git dependencies to the latest upstream version install <url> installs a user-wide package from git install <dir> installs a user-wide package from a local directory dump prints the parsed leanpkg.toml file (for debugging) " def main : ∀ (cmd : string) (leanpkg_args lean_args : list string), io unit | "configure" [] [] := configure | "build" _ lean_args := build lean_args | "test" _ lean_args := test lean_args | "new" [dir] [] := new dir | "init" [name] [] := init name | "add" [dep] [] := add dep | "upgrade" [] [] := upgrade | "install" [dep] [] := do dep ← absolutize_add_dep dep, dot_lean_dir ← get_dot_lean_dir, exec_cmd {cmd := "mkdir", args := ["-p", dot_lean_dir]}, let user_toml_fn := dot_lean_dir ++ "/" ++ leanpkg_toml_fn, ex ← exists_file user_toml_fn, when (¬ ex) $ write_manifest { name := "_user_local_packages", version := "1" } user_toml_fn, exec_cmd {cmd := "leanpkg", args := ["add", dep], cwd := dot_lean_dir}, exec_cmd {cmd := "leanpkg", args := ["build"], cwd := dot_lean_dir} | "dump" [] [] := read_manifest >>= io.print_ln ∘ repr | _ _ _ := io.fail usage private def split_cmdline_args_core : list string → list string × list string | [] := ([], []) | (arg::args) := if arg = "--" then ([], args) else match split_cmdline_args_core args with | (outer_args, inner_args) := (arg::outer_args, inner_args) end def split_cmdline_args : list string → io (string × list string × list string) | [] := io.fail usage | [cmd] := return (cmd, [], []) | (cmd::rest) := match split_cmdline_args_core rest with | (outer_args, inner_args) := return (cmd, outer_args, inner_args) end end leanpkg def main : io unit := do (cmd, outer_args, inner_args) ← io.cmdline_args >>= leanpkg.split_cmdline_args, leanpkg.main cmd outer_args inner_args
f28a8dc63d02c05a98d6d892da6c9e7592d6b093
076f5040b63237c6dd928c6401329ed5adcb0e44
/instructor-notes/2019.10.14.prop_logic/semantic_validity.lean
1250064ab1aea0aead7c8b51377dfb12e33f5c95
[]
no_license
kevinsullivan/uva-cs-dm-f19
0f123689cf6cb078f263950b18382a7086bf30be
09a950752884bd7ade4be33e9e89a2c4b1927167
refs/heads/master
1,594,771,841,541
1,575,853,850,000
1,575,853,850,000
205,433,890
4
9
null
1,571,592,121,000
1,567,188,539,000
Lean
UTF-8
Lean
false
false
711
lean
import .prop_logic open prop_logic open prop_logic.var open prop_logic.unOp open prop_logic.binOp open prop_logic.pExp def isModel (i: var → bool) (e : pExp) := pEval e i = tt def valid (e : pExp) := ∀ (i : var → bool), isModel i e def satisfiable (e : pExp) := ∃ (i : var → bool), isModel i e def unsatisfiable (e : pExp) := ∀ (i : var → bool), ¬ isModel i e def unsatisfiable' (e : pExp) := ¬ ∃ (i : var → bool), isModel i e def unsatisfiable'' (e : pExp) := ¬ satisfiable e def satisfiable_but_not_valid (e : pExp) := (satisfiable e) ∧ ¬ (valid e) -- def puzzle := ∃ (e : pExp), (satisfiable e) ∧ ¬ (valid e)
fe29d45336be199f9f18ffa7902b002488e491a9
c777c32c8e484e195053731103c5e52af26a25d1
/src/analysis/normed_space/spectrum.lean
cab94d955eebbf242a3f8b08c38ee9ca21dc8074
[ "Apache-2.0" ]
permissive
kbuzzard/mathlib
2ff9e85dfe2a46f4b291927f983afec17e946eb8
58537299e922f9c77df76cb613910914a479c1f7
refs/heads/master
1,685,313,702,744
1,683,974,212,000
1,683,974,212,000
128,185,277
1
0
null
1,522,920,600,000
1,522,920,600,000
null
UTF-8
Lean
false
false
27,796
lean
/- Copyright (c) 2021 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import algebra.algebra.spectrum import analysis.special_functions.pow import analysis.complex.liouville import analysis.complex.polynomial import analysis.analytic.radius_liminf import topology.algebra.module.character_space import analysis.normed_space.exponential /-! # The spectrum of elements in a complete normed algebra This file contains the basic theory for the resolvent and spectrum of a Banach algebra. ## Main definitions * `spectral_radius : ℝ≥0∞`: supremum of `‖k‖₊` for all `k ∈ spectrum 𝕜 a` * `normed_ring.alg_equiv_complex_of_complete`: **Gelfand-Mazur theorem** For a complex Banach division algebra, the natural `algebra_map ℂ A` is an algebra isomorphism whose inverse is given by selecting the (unique) element of `spectrum ℂ a` ## Main statements * `spectrum.is_open_resolvent_set`: the resolvent set is open. * `spectrum.is_closed`: the spectrum is closed. * `spectrum.subset_closed_ball_norm`: the spectrum is a subset of closed disk of radius equal to the norm. * `spectrum.is_compact`: the spectrum is compact. * `spectrum.spectral_radius_le_nnnorm`: the spectral radius is bounded above by the norm. * `spectrum.has_deriv_at_resolvent`: the resolvent function is differentiable on the resolvent set. * `spectrum.pow_nnnorm_pow_one_div_tendsto_nhds_spectral_radius`: Gelfand's formula for the spectral radius in Banach algebras over `ℂ`. * `spectrum.nonempty`: the spectrum of any element in a complex Banach algebra is nonempty. ## TODO * compute all derivatives of `resolvent a`. -/ open_locale ennreal nnreal /-- The *spectral radius* is the supremum of the `nnnorm` (`‖⬝‖₊`) of elements in the spectrum, coerced into an element of `ℝ≥0∞`. Note that it is possible for `spectrum 𝕜 a = ∅`. In this case, `spectral_radius a = 0`. It is also possible that `spectrum 𝕜 a` be unbounded (though not for Banach algebras, see `spectrum.is_bounded`, below). In this case, `spectral_radius a = ∞`. -/ noncomputable def spectral_radius (𝕜 : Type*) {A : Type*} [normed_field 𝕜] [ring A] [algebra 𝕜 A] (a : A) : ℝ≥0∞ := ⨆ k ∈ spectrum 𝕜 a, ‖k‖₊ variables {𝕜 : Type*} {A : Type*} namespace spectrum section spectrum_compact open filter variables [normed_field 𝕜] [normed_ring A] [normed_algebra 𝕜 A] local notation `σ` := spectrum 𝕜 local notation `ρ` := resolvent_set 𝕜 local notation `↑ₐ` := algebra_map 𝕜 A @[simp] lemma spectral_radius.of_subsingleton [subsingleton A] (a : A) : spectral_radius 𝕜 a = 0 := by simp [spectral_radius] @[simp] lemma spectral_radius_zero : spectral_radius 𝕜 (0 : A) = 0 := by { nontriviality A, simp [spectral_radius] } lemma mem_resolvent_set_of_spectral_radius_lt {a : A} {k : 𝕜} (h : spectral_radius 𝕜 a < ‖k‖₊) : k ∈ ρ a := not_not.mp $ λ hn, h.not_le $ le_supr₂ k hn variable [complete_space A] lemma is_open_resolvent_set (a : A) : is_open (ρ a) := units.is_open.preimage ((continuous_algebra_map 𝕜 A).sub continuous_const) protected lemma is_closed (a : A) : is_closed (σ a) := (is_open_resolvent_set a).is_closed_compl lemma mem_resolvent_set_of_norm_lt_mul {a : A} {k : 𝕜} (h : ‖a‖ * ‖(1 : A)‖ < ‖k‖) : k ∈ ρ a := begin rw [resolvent_set, set.mem_set_of_eq, algebra.algebra_map_eq_smul_one], nontriviality A, have hk : k ≠ 0, from ne_zero_of_norm_ne_zero ((mul_nonneg (norm_nonneg _) (norm_nonneg _)).trans_lt h).ne', let ku := units.map (↑ₐ).to_monoid_hom (units.mk0 k hk), rw [←inv_inv (‖(1 : A)‖), mul_inv_lt_iff (inv_pos.2 $ norm_pos_iff.2 (one_ne_zero : (1 : A) ≠ 0))] at h, have hku : ‖-a‖ < ‖(↑ku⁻¹:A)‖⁻¹ := by simpa [ku, norm_algebra_map] using h, simpa [ku, sub_eq_add_neg, algebra.algebra_map_eq_smul_one] using (ku.add (-a) hku).is_unit, end lemma mem_resolvent_set_of_norm_lt [norm_one_class A] {a : A} {k : 𝕜} (h : ‖a‖ < ‖k‖) : k ∈ ρ a := mem_resolvent_set_of_norm_lt_mul (by rwa [norm_one, mul_one]) lemma norm_le_norm_mul_of_mem {a : A} {k : 𝕜} (hk : k ∈ σ a) : ‖k‖ ≤ ‖a‖ * ‖(1 : A)‖ := le_of_not_lt $ mt mem_resolvent_set_of_norm_lt_mul hk lemma norm_le_norm_of_mem [norm_one_class A] {a : A} {k : 𝕜} (hk : k ∈ σ a) : ‖k‖ ≤ ‖a‖ := le_of_not_lt $ mt mem_resolvent_set_of_norm_lt hk lemma subset_closed_ball_norm_mul (a : A) : σ a ⊆ metric.closed_ball (0 : 𝕜) (‖a‖ * ‖(1 : A)‖) := λ k hk, by simp [norm_le_norm_mul_of_mem hk] lemma subset_closed_ball_norm [norm_one_class A] (a : A) : σ a ⊆ metric.closed_ball (0 : 𝕜) (‖a‖) := λ k hk, by simp [norm_le_norm_of_mem hk] lemma is_bounded (a : A) : metric.bounded (σ a) := (metric.bounded_iff_subset_ball 0).mpr ⟨‖a‖ * ‖(1 : A)‖, subset_closed_ball_norm_mul a⟩ protected theorem is_compact [proper_space 𝕜] (a : A) : is_compact (σ a) := metric.is_compact_of_is_closed_bounded (spectrum.is_closed a) (is_bounded a) theorem spectral_radius_le_nnnorm [norm_one_class A] (a : A) : spectral_radius 𝕜 a ≤ ‖a‖₊ := by { refine supr₂_le (λ k hk, _), exact_mod_cast norm_le_norm_of_mem hk } lemma exists_nnnorm_eq_spectral_radius_of_nonempty [proper_space 𝕜] {a : A} (ha : (σ a).nonempty) : ∃ k ∈ σ a, (‖k‖₊ : ℝ≥0∞) = spectral_radius 𝕜 a := begin obtain ⟨k, hk, h⟩ := (spectrum.is_compact a).exists_forall_ge ha continuous_nnnorm.continuous_on, exact ⟨k, hk, le_antisymm (le_supr₂ k hk) (supr₂_le $ by exact_mod_cast h)⟩, end lemma spectral_radius_lt_of_forall_lt_of_nonempty [proper_space 𝕜] {a : A} (ha : (σ a).nonempty) {r : ℝ≥0} (hr : ∀ k ∈ σ a, ‖k‖₊ < r) : spectral_radius 𝕜 a < r := Sup_image.symm.trans_lt $ ((spectrum.is_compact a).Sup_lt_iff_of_continuous ha (ennreal.continuous_coe.comp continuous_nnnorm).continuous_on (r : ℝ≥0∞)).mpr (by exact_mod_cast hr) open ennreal polynomial variable (𝕜) theorem spectral_radius_le_pow_nnnorm_pow_one_div (a : A) (n : ℕ) : spectral_radius 𝕜 a ≤ (‖a ^ (n + 1)‖₊) ^ (1 / (n + 1) : ℝ) * (‖(1 : A)‖₊) ^ (1 / (n + 1) : ℝ) := begin refine supr₂_le (λ k hk, _), /- apply easy direction of the spectral mapping theorem for polynomials -/ have pow_mem : k ^ (n + 1) ∈ σ (a ^ (n + 1)), by simpa only [one_mul, algebra.algebra_map_eq_smul_one, one_smul, aeval_monomial, one_mul, eval_monomial] using subset_polynomial_aeval a (monomial (n + 1) (1 : 𝕜)) ⟨k, hk, rfl⟩, /- power of the norm is bounded by norm of the power -/ have nnnorm_pow_le : (↑(‖k‖₊ ^ (n + 1)) : ℝ≥0∞) ≤ ‖a ^ (n + 1)‖₊ * ‖(1 : A)‖₊, { simpa only [real.to_nnreal_mul (norm_nonneg _), norm_to_nnreal, nnnorm_pow k (n + 1), ennreal.coe_mul] using coe_mono (real.to_nnreal_mono (norm_le_norm_mul_of_mem pow_mem)) }, /- take (n + 1)ᵗʰ roots and clean up the left-hand side -/ have hn : 0 < ((n + 1 : ℕ) : ℝ), by exact_mod_cast nat.succ_pos', convert monotone_rpow_of_nonneg (one_div_pos.mpr hn).le nnnorm_pow_le, erw [coe_pow, ←rpow_nat_cast, ←rpow_mul, mul_one_div_cancel hn.ne', rpow_one], rw [nat.cast_succ, ennreal.coe_mul_rpow], end theorem spectral_radius_le_liminf_pow_nnnorm_pow_one_div (a : A) : spectral_radius 𝕜 a ≤ at_top.liminf (λ n : ℕ, (‖a ^ n‖₊ : ℝ≥0∞) ^ (1 / n : ℝ)) := begin refine ennreal.le_of_forall_lt_one_mul_le (λ ε hε, _), by_cases ε = 0, { simp only [h, zero_mul, zero_le'] }, have hε' : ε⁻¹ ≠ ∞, from λ h', h (by simpa only [inv_inv, inv_top] using congr_arg (λ (x : ℝ≥0∞), x⁻¹) h'), simp only [ennreal.mul_le_iff_le_inv h (hε.trans_le le_top).ne, mul_comm ε⁻¹, liminf_eq_supr_infi_of_nat', ennreal.supr_mul, ennreal.infi_mul hε'], rw [←ennreal.inv_lt_inv, inv_one] at hε, obtain ⟨N, hN⟩ := eventually_at_top.mp (ennreal.eventually_pow_one_div_le (ennreal.coe_ne_top : ↑‖(1 : A)‖₊ ≠ ∞) hε), refine (le_trans _ (le_supr _ (N + 1))), refine le_infi (λ n, _), simp only [←add_assoc], refine (spectral_radius_le_pow_nnnorm_pow_one_div 𝕜 a (n + N)).trans _, norm_cast, exact mul_le_mul_left' (hN (n + N + 1) (by linarith)) _, end end spectrum_compact section resolvent open filter asymptotics variables [nontrivially_normed_field 𝕜] [normed_ring A] [normed_algebra 𝕜 A] [complete_space A] local notation `ρ` := resolvent_set 𝕜 local notation `↑ₐ` := algebra_map 𝕜 A theorem has_deriv_at_resolvent {a : A} {k : 𝕜} (hk : k ∈ ρ a) : has_deriv_at (resolvent a) (-(resolvent a k) ^ 2) k := begin have H₁ : has_fderiv_at ring.inverse _ (↑ₐk - a) := has_fderiv_at_ring_inverse hk.unit, have H₂ : has_deriv_at (λ k, ↑ₐk - a) 1 k, { simpa using (algebra.linear_map 𝕜 A).has_deriv_at.sub_const a }, simpa [resolvent, sq, hk.unit_spec, ← ring.inverse_unit hk.unit] using H₁.comp_has_deriv_at k H₂, end /- TODO: Once there is sufficient API for bornology, we should get a nice filter / asymptotics version of this, for example: `tendsto (resolvent a) (cobounded 𝕜) (𝓝 0)` or more specifically `(resolvent a) =O[cobounded 𝕜] (λ z, z⁻¹)`. -/ lemma norm_resolvent_le_forall (a : A) : ∀ ε > 0, ∃ R > 0, ∀ z : 𝕜, R ≤ ‖z‖ → ‖resolvent a z‖ ≤ ε := begin obtain ⟨c, c_pos, hc⟩ := (@normed_ring.inverse_one_sub_norm A _ _).exists_pos, rw [is_O_with_iff, eventually_iff, metric.mem_nhds_iff] at hc, rcases hc with ⟨δ, δ_pos, hδ⟩, simp only [cstar_ring.norm_one, mul_one] at hδ, intros ε hε, have ha₁ : 0 < ‖a‖ + 1 := lt_of_le_of_lt (norm_nonneg a) (lt_add_one _), have min_pos : 0 < min (δ * (‖a‖ + 1)⁻¹) (ε * c⁻¹), from lt_min (mul_pos δ_pos (inv_pos.mpr ha₁)) (mul_pos hε (inv_pos.mpr c_pos)), refine ⟨(min (δ * (‖a‖ + 1)⁻¹) (ε * c⁻¹))⁻¹, inv_pos.mpr min_pos, (λ z hz, _)⟩, have hnz : z ≠ 0 := norm_pos_iff.mp (lt_of_lt_of_le (inv_pos.mpr min_pos) hz), replace hz := inv_le_of_inv_le min_pos hz, rcases (⟨units.mk0 z hnz, units.coe_mk0 hnz⟩ : is_unit z) with ⟨z, rfl⟩, have lt_δ : ‖z⁻¹ • a‖ < δ, { rw [units.smul_def, norm_smul, units.coe_inv, norm_inv], calc ‖(z : 𝕜)‖⁻¹ * ‖a‖ ≤ δ * (‖a‖ + 1)⁻¹ * ‖a‖ : mul_le_mul_of_nonneg_right (hz.trans (min_le_left _ _)) (norm_nonneg _) ... < δ : by { conv { rw mul_assoc, to_rhs, rw (mul_one δ).symm }, exact mul_lt_mul_of_pos_left ((inv_mul_lt_iff ha₁).mpr ((mul_one (‖a‖ + 1)).symm ▸ (lt_add_one _))) δ_pos } }, rw [←inv_smul_smul z (resolvent a (z : 𝕜)), units_smul_resolvent_self, resolvent, algebra.algebra_map_eq_smul_one, one_smul, units.smul_def, norm_smul, units.coe_inv, norm_inv], calc _ ≤ ε * c⁻¹ * c : mul_le_mul (hz.trans (min_le_right _ _)) (hδ (mem_ball_zero_iff.mpr lt_δ)) (norm_nonneg _) (mul_pos hε (inv_pos.mpr c_pos)).le ... = _ : inv_mul_cancel_right₀ c_pos.ne.symm ε, end end resolvent section one_sub_smul open continuous_multilinear_map ennreal formal_multilinear_series open_locale nnreal ennreal variables [nontrivially_normed_field 𝕜] [normed_ring A] [normed_algebra 𝕜 A] variable (𝕜) /-- In a Banach algebra `A` over a nontrivially normed field `𝕜`, for any `a : A` the power series with coefficients `a ^ n` represents the function `(1 - z • a)⁻¹` in a disk of radius `‖a‖₊⁻¹`. -/ lemma has_fpower_series_on_ball_inverse_one_sub_smul [complete_space A] (a : A) : has_fpower_series_on_ball (λ z : 𝕜, ring.inverse (1 - z • a)) (λ n, continuous_multilinear_map.mk_pi_field 𝕜 (fin n) (a ^ n)) 0 (‖a‖₊)⁻¹ := { r_le := begin refine le_of_forall_nnreal_lt (λ r hr, le_radius_of_bound_nnreal _ (max 1 ‖(1 : A)‖₊) (λ n, _)), rw [←norm_to_nnreal, norm_mk_pi_field, norm_to_nnreal], cases n, { simp only [le_refl, mul_one, or_true, le_max_iff, pow_zero] }, { refine le_trans (le_trans (mul_le_mul_right' (nnnorm_pow_le' a n.succ_pos) (r ^ n.succ)) _) (le_max_left _ _), { by_cases ‖a‖₊ = 0, { simp only [h, zero_mul, zero_le', pow_succ], }, { rw [←coe_inv h, coe_lt_coe, nnreal.lt_inv_iff_mul_lt h] at hr, simpa only [←mul_pow, mul_comm] using pow_le_one' hr.le n.succ } } } end, r_pos := ennreal.inv_pos.mpr coe_ne_top, has_sum := λ y hy, begin have norm_lt : ‖y • a‖ < 1, { by_cases h : ‖a‖₊ = 0, { simp only [nnnorm_eq_zero.mp h, norm_zero, zero_lt_one, smul_zero] }, { have nnnorm_lt : ‖y‖₊ < ‖a‖₊⁻¹, by simpa only [←coe_inv h, mem_ball_zero_iff, metric.emetric_ball_nnreal] using hy, rwa [←coe_nnnorm, ←real.lt_to_nnreal_iff_coe_lt, real.to_nnreal_one, nnnorm_smul, ←nnreal.lt_inv_iff_mul_lt h] } }, simpa [←smul_pow, (normed_ring.summable_geometric_of_norm_lt_1 _ norm_lt).has_sum_iff] using (normed_ring.inverse_one_sub _ norm_lt).symm, end } variable {𝕜} lemma is_unit_one_sub_smul_of_lt_inv_radius {a : A} {z : 𝕜} (h : ↑‖z‖₊ < (spectral_radius 𝕜 a)⁻¹) : is_unit (1 - z • a) := begin by_cases hz : z = 0, { simp only [hz, is_unit_one, sub_zero, zero_smul] }, { let u := units.mk0 z hz, suffices hu : is_unit (u⁻¹ • 1 - a), { rwa [is_unit.smul_sub_iff_sub_inv_smul, inv_inv u] at hu }, { rw [units.smul_def, ←algebra.algebra_map_eq_smul_one, ←mem_resolvent_set_iff], refine mem_resolvent_set_of_spectral_radius_lt _, rwa [units.coe_inv, nnnorm_inv, coe_inv (nnnorm_ne_zero_iff.mpr (units.coe_mk0 hz ▸ hz : (u : 𝕜) ≠ 0)), lt_inv_iff_lt_inv] } } end /-- In a Banach algebra `A` over `𝕜`, for `a : A` the function `λ z, (1 - z • a)⁻¹` is differentiable on any closed ball centered at zero of radius `r < (spectral_radius 𝕜 a)⁻¹`. -/ theorem differentiable_on_inverse_one_sub_smul [complete_space A] {a : A} {r : ℝ≥0} (hr : (r : ℝ≥0∞) < (spectral_radius 𝕜 a)⁻¹) : differentiable_on 𝕜 (λ z : 𝕜, ring.inverse (1 - z • a)) (metric.closed_ball 0 r) := begin intros z z_mem, apply differentiable_at.differentiable_within_at, have hu : is_unit (1 - z • a), { refine is_unit_one_sub_smul_of_lt_inv_radius (lt_of_le_of_lt (coe_mono _) hr), simpa only [norm_to_nnreal, real.to_nnreal_coe] using real.to_nnreal_mono (mem_closed_ball_zero_iff.mp z_mem) }, have H₁ : differentiable 𝕜 (λ w : 𝕜, 1 - w • a) := (differentiable_id.smul_const a).const_sub 1, exact differentiable_at.comp z (differentiable_at_inverse hu.unit) (H₁.differentiable_at), end end one_sub_smul section gelfand_formula open filter ennreal continuous_multilinear_map open_locale topology variables [normed_ring A] [normed_algebra ℂ A] [complete_space A] /-- The `limsup` relationship for the spectral radius used to prove `spectrum.gelfand_formula`. -/ lemma limsup_pow_nnnorm_pow_one_div_le_spectral_radius (a : A) : limsup (λ n : ℕ, ↑‖a ^ n‖₊ ^ (1 / n : ℝ)) at_top ≤ spectral_radius ℂ a := begin refine ennreal.inv_le_inv.mp (le_of_forall_pos_nnreal_lt (λ r r_pos r_lt, _)), simp_rw [inv_limsup, ←one_div], let p : formal_multilinear_series ℂ ℂ A := λ n, continuous_multilinear_map.mk_pi_field ℂ (fin n) (a ^ n), suffices h : (r : ℝ≥0∞) ≤ p.radius, { convert h, simp only [p.radius_eq_liminf, ←norm_to_nnreal, norm_mk_pi_field], congr, ext n, rw [norm_to_nnreal, ennreal.coe_rpow_def (‖a ^ n‖₊) (1 / n : ℝ), if_neg], exact λ ha, by linarith [ha.2, (one_div_nonneg.mpr n.cast_nonneg : 0 ≤ (1 / n : ℝ))], }, { have H₁ := (differentiable_on_inverse_one_sub_smul r_lt).has_fpower_series_on_ball r_pos, exact ((has_fpower_series_on_ball_inverse_one_sub_smul ℂ a).exchange_radius H₁).r_le, } end /-- **Gelfand's formula**: Given an element `a : A` of a complex Banach algebra, the `spectral_radius` of `a` is the limit of the sequence `‖a ^ n‖₊ ^ (1 / n)` -/ theorem pow_nnnorm_pow_one_div_tendsto_nhds_spectral_radius (a : A) : tendsto (λ n : ℕ, ((‖a ^ n‖₊ ^ (1 / n : ℝ)) : ℝ≥0∞)) at_top (𝓝 (spectral_radius ℂ a)) := tendsto_of_le_liminf_of_limsup_le (spectral_radius_le_liminf_pow_nnnorm_pow_one_div ℂ a) (limsup_pow_nnnorm_pow_one_div_le_spectral_radius a) /- This is the same as `pow_nnnorm_pow_one_div_tendsto_nhds_spectral_radius` but for `norm` instead of `nnnorm`. -/ /-- **Gelfand's formula**: Given an element `a : A` of a complex Banach algebra, the `spectral_radius` of `a` is the limit of the sequence `‖a ^ n‖₊ ^ (1 / n)` -/ theorem pow_norm_pow_one_div_tendsto_nhds_spectral_radius (a : A) : tendsto (λ n : ℕ, ennreal.of_real (‖a ^ n‖ ^ (1 / n : ℝ))) at_top (𝓝 (spectral_radius ℂ a)) := begin convert pow_nnnorm_pow_one_div_tendsto_nhds_spectral_radius a, ext1, rw [←of_real_rpow_of_nonneg (norm_nonneg _) _, ←coe_nnnorm, coe_nnreal_eq], exact one_div_nonneg.mpr (by exact_mod_cast zero_le _), end end gelfand_formula section nonempty_spectrum variables [normed_ring A] [normed_algebra ℂ A] [complete_space A] [nontrivial A] (a : A) /-- In a (nontrivial) complex Banach algebra, every element has nonempty spectrum. -/ protected theorem nonempty : (spectrum ℂ a).nonempty := begin /- Suppose `σ a = ∅`, then resolvent set is `ℂ`, any `(z • 1 - a)` is a unit, and `resolvent` is differentiable on `ℂ`. -/ rw set.nonempty_iff_ne_empty, by_contra h, have H₀ : resolvent_set ℂ a = set.univ, by rwa [spectrum, set.compl_empty_iff] at h, have H₁ : differentiable ℂ (λ z : ℂ, resolvent a z), from λ z, (has_deriv_at_resolvent (H₀.symm ▸ set.mem_univ z : z ∈ resolvent_set ℂ a)).differentiable_at, /- The norm of the resolvent is small for all sufficently large `z`, and by compactness and continuity it is bounded on the complement of a large ball, thus uniformly bounded on `ℂ`. By Liouville's theorem `λ z, resolvent a z` is constant -/ have H₂ := norm_resolvent_le_forall a, have H₃ : ∀ z : ℂ, resolvent a z = resolvent a (0 : ℂ), { refine λ z, H₁.apply_eq_apply_of_bounded (bounded_iff_forall_norm_le.mpr _) z 0, rcases H₂ 1 zero_lt_one with ⟨R, R_pos, hR⟩, rcases (proper_space.is_compact_closed_ball (0 : ℂ) R).exists_bound_of_continuous_on H₁.continuous.continuous_on with ⟨C, hC⟩, use max C 1, rintros _ ⟨w, rfl⟩, refine or.elim (em (‖w‖ ≤ R)) (λ hw, _) (λ hw, _), { exact (hC w (mem_closed_ball_zero_iff.mpr hw)).trans (le_max_left _ _) }, { exact (hR w (not_le.mp hw).le).trans (le_max_right _ _), }, }, /- `resolvent a 0 = 0`, which is a contradition because it isn't a unit. -/ have H₅ : resolvent a (0 : ℂ) = 0, { refine norm_eq_zero.mp (le_antisymm (le_of_forall_pos_le_add (λ ε hε, _)) (norm_nonneg _)), rcases H₂ ε hε with ⟨R, R_pos, hR⟩, simpa only [H₃ R] using (zero_add ε).symm.subst (hR R (by exact_mod_cast (real.norm_of_nonneg R_pos.lt.le).symm.le)), }, /- `not_is_unit_zero` is where we need `nontrivial A`, it is unavoidable. -/ exact not_is_unit_zero (H₅.subst (is_unit_resolvent.mp (mem_resolvent_set_iff.mp (H₀.symm ▸ set.mem_univ 0)))), end /-- In a complex Banach algebra, the spectral radius is always attained by some element of the spectrum. -/ lemma exists_nnnorm_eq_spectral_radius : ∃ z ∈ spectrum ℂ a, (‖z‖₊ : ℝ≥0∞) = spectral_radius ℂ a := exists_nnnorm_eq_spectral_radius_of_nonempty (spectrum.nonempty a) /-- In a complex Banach algebra, if every element of the spectrum has norm strictly less than `r : ℝ≥0`, then the spectral radius is also strictly less than `r`. -/ lemma spectral_radius_lt_of_forall_lt {r : ℝ≥0} (hr : ∀ z ∈ spectrum ℂ a, ‖z‖₊ < r) : spectral_radius ℂ a < r := spectral_radius_lt_of_forall_lt_of_nonempty (spectrum.nonempty a) hr open_locale polynomial open polynomial /-- The **spectral mapping theorem** for polynomials in a Banach algebra over `ℂ`. -/ lemma map_polynomial_aeval (p : ℂ[X]) : spectrum ℂ (aeval a p) = (λ k, eval k p) '' (spectrum ℂ a) := map_polynomial_aeval_of_nonempty a p (spectrum.nonempty a) /-- A specialization of the spectral mapping theorem for polynomials in a Banach algebra over `ℂ` to monic monomials. -/ protected lemma map_pow (n : ℕ) : spectrum ℂ (a ^ n) = (λ x, x ^ n) '' (spectrum ℂ a) := by simpa only [aeval_X_pow, eval_pow, eval_X] using map_polynomial_aeval a (X ^ n) end nonempty_spectrum section gelfand_mazur_isomorphism variables [normed_ring A] [normed_algebra ℂ A] (hA : ∀ {a : A}, is_unit a ↔ a ≠ 0) include hA local notation `σ` := spectrum ℂ lemma algebra_map_eq_of_mem {a : A} {z : ℂ} (h : z ∈ σ a) : algebra_map ℂ A z = a := by rwa [mem_iff, hA, not_not, sub_eq_zero] at h /-- **Gelfand-Mazur theorem**: For a complex Banach division algebra, the natural `algebra_map ℂ A` is an algebra isomorphism whose inverse is given by selecting the (unique) element of `spectrum ℂ a`. In addition, `algebra_map_isometry` guarantees this map is an isometry. Note: because `normed_division_ring` requires the field `norm_mul' : ∀ a b, ‖a * b‖ = ‖a‖ * ‖b‖`, we don't use this type class and instead opt for a `normed_ring` in which the nonzero elements are precisely the units. This allows for the application of this isomorphism in broader contexts, e.g., to the quotient of a complex Banach algebra by a maximal ideal. In the case when `A` is actually a `normed_division_ring`, one may fill in the argument `hA` with the lemma `is_unit_iff_ne_zero`. -/ @[simps] noncomputable def _root_.normed_ring.alg_equiv_complex_of_complete [complete_space A] : ℂ ≃ₐ[ℂ] A := let nt : nontrivial A := ⟨⟨1, 0, hA.mp ⟨⟨1, 1, mul_one _, mul_one _⟩, rfl⟩⟩⟩ in { to_fun := algebra_map ℂ A, inv_fun := λ a, (@spectrum.nonempty _ _ _ _ nt a).some, left_inv := λ z, by simpa only [@scalar_eq _ _ _ _ _ nt _] using (@spectrum.nonempty _ _ _ _ nt $ algebra_map ℂ A z).some_mem, right_inv := λ a, algebra_map_eq_of_mem @hA (@spectrum.nonempty _ _ _ _ nt a).some_mem, ..algebra.of_id ℂ A } end gelfand_mazur_isomorphism section exp_mapping local notation `↑ₐ` := algebra_map 𝕜 A /-- For `𝕜 = ℝ` or `𝕜 = ℂ`, `exp 𝕜` maps the spectrum of `a` into the spectrum of `exp 𝕜 a`. -/ theorem exp_mem_exp [is_R_or_C 𝕜] [normed_ring A] [normed_algebra 𝕜 A] [complete_space A] (a : A) {z : 𝕜} (hz : z ∈ spectrum 𝕜 a) : exp 𝕜 z ∈ spectrum 𝕜 (exp 𝕜 a) := begin have hexpmul : exp 𝕜 a = exp 𝕜 (a - ↑ₐ z) * ↑ₐ (exp 𝕜 z), { rw [algebra_map_exp_comm z, ←exp_add_of_commute (algebra.commutes z (a - ↑ₐz)).symm, sub_add_cancel] }, let b := ∑' n : ℕ, ((n + 1).factorial⁻¹ : 𝕜) • (a - ↑ₐz) ^ n, have hb : summable (λ n : ℕ, ((n + 1).factorial⁻¹ : 𝕜) • (a - ↑ₐz) ^ n), { refine summable_of_norm_bounded_eventually _ (real.summable_pow_div_factorial ‖a - ↑ₐz‖) _, filter_upwards [filter.eventually_cofinite_ne 0] with n hn, rw [norm_smul, mul_comm, norm_inv, is_R_or_C.norm_nat_cast, ← div_eq_mul_inv], exact div_le_div (pow_nonneg (norm_nonneg _) n) (norm_pow_le' (a - ↑ₐz) (zero_lt_iff.mpr hn)) (by exact_mod_cast nat.factorial_pos n) (by exact_mod_cast nat.factorial_le (lt_add_one n).le) }, have h₀ : ∑' n : ℕ, ((n + 1).factorial⁻¹ : 𝕜) • (a - ↑ₐz) ^ (n + 1) = (a - ↑ₐz) * b, { simpa only [mul_smul_comm, pow_succ] using hb.tsum_mul_left (a - ↑ₐz) }, have h₁ : ∑' n : ℕ, ((n + 1).factorial⁻¹ : 𝕜) • (a - ↑ₐz) ^ (n + 1) = b * (a - ↑ₐz), { simpa only [pow_succ', algebra.smul_mul_assoc] using hb.tsum_mul_right (a - ↑ₐz) }, have h₃ : exp 𝕜 (a - ↑ₐz) = 1 + (a - ↑ₐz) * b, { rw exp_eq_tsum, convert tsum_eq_zero_add (exp_series_summable' (a - ↑ₐz)), simp only [nat.factorial_zero, nat.cast_one, inv_one, pow_zero, one_smul], exact h₀.symm }, rw [spectrum.mem_iff, is_unit.sub_iff, ←one_mul (↑ₐ(exp 𝕜 z)), hexpmul, ←_root_.sub_mul, commute.is_unit_mul_iff (algebra.commutes (exp 𝕜 z) (exp 𝕜 (a - ↑ₐz) - 1)).symm, sub_eq_iff_eq_add'.mpr h₃, commute.is_unit_mul_iff (h₀ ▸ h₁ : (a - ↑ₐz) * b = b * (a - ↑ₐz))], exact not_and_of_not_left _ (not_and_of_not_left _ ((not_iff_not.mpr is_unit.sub_iff).mp hz)), end end exp_mapping end spectrum namespace alg_hom section normed_field variables {F : Type*} [normed_field 𝕜] [normed_ring A] [normed_algebra 𝕜 A] [complete_space A] local notation `↑ₐ` := algebra_map 𝕜 A /-- An algebra homomorphism into the base field, as a continuous linear map (since it is automatically bounded). See note [lower instance priority] -/ @[priority 100] instance [alg_hom_class F 𝕜 A 𝕜] : continuous_linear_map_class F 𝕜 A 𝕜 := { map_continuous := λ φ, add_monoid_hom_class.continuous_of_bound φ ‖(1 : A)‖ $ λ a, (mul_comm ‖a‖ ‖(1 : A)‖) ▸ spectrum.norm_le_norm_mul_of_mem (apply_mem_spectrum φ _), .. alg_hom_class.linear_map_class } /-- An algebra homomorphism into the base field, as a continuous linear map (since it is automatically bounded). -/ def to_continuous_linear_map (φ : A →ₐ[𝕜] 𝕜) : A →L[𝕜] 𝕜 := { cont := map_continuous φ, .. φ.to_linear_map } @[simp] lemma coe_to_continuous_linear_map (φ : A →ₐ[𝕜] 𝕜) : ⇑φ.to_continuous_linear_map = φ := rfl lemma norm_apply_le_self_mul_norm_one [alg_hom_class F 𝕜 A 𝕜] (f : F) (a : A) : ‖f a‖ ≤ ‖a‖ * ‖(1 : A)‖ := spectrum.norm_le_norm_mul_of_mem (apply_mem_spectrum f _) lemma norm_apply_le_self [norm_one_class A] [alg_hom_class F 𝕜 A 𝕜] (f : F) (a : A) : ‖f a‖ ≤ ‖a‖ := spectrum.norm_le_norm_of_mem (apply_mem_spectrum f _) end normed_field section nontrivially_normed_field variables [nontrivially_normed_field 𝕜] [normed_ring A] [normed_algebra 𝕜 A] [complete_space A] local notation `↑ₐ` := algebra_map 𝕜 A @[simp] lemma to_continuous_linear_map_norm [norm_one_class A] (φ : A →ₐ[𝕜] 𝕜) : ‖φ.to_continuous_linear_map‖ = 1 := continuous_linear_map.op_norm_eq_of_bounds zero_le_one (λ a, (one_mul ‖a‖).symm ▸ spectrum.norm_le_norm_of_mem (apply_mem_spectrum φ _)) (λ _ _ h, by simpa only [coe_to_continuous_linear_map, map_one, norm_one, mul_one] using h 1) end nontrivially_normed_field end alg_hom namespace weak_dual namespace character_space variables [nontrivially_normed_field 𝕜] [normed_ring A] [complete_space A] variables [normed_algebra 𝕜 A] /-- The equivalence between characters and algebra homomorphisms into the base field. -/ def equiv_alg_hom : (character_space 𝕜 A) ≃ (A →ₐ[𝕜] 𝕜) := { to_fun := to_alg_hom, inv_fun := λ f, { val := f.to_continuous_linear_map, property := by { rw eq_set_map_one_map_mul, exact ⟨map_one f, map_mul f⟩ } }, left_inv := λ f, subtype.ext $ continuous_linear_map.ext $ λ x, rfl, right_inv := λ f, alg_hom.ext $ λ x, rfl } @[simp] lemma equiv_alg_hom_coe (f : character_space 𝕜 A) : ⇑(equiv_alg_hom f) = f := rfl @[simp] lemma equiv_alg_hom_symm_coe (f : A →ₐ[𝕜] 𝕜) : ⇑(equiv_alg_hom.symm f) = f := rfl end character_space end weak_dual
5f1b0a9927ac6f5b675c2fedecdc8360021e6e86
69d4931b605e11ca61881fc4f66db50a0a875e39
/test/matrix.lean
2e8111d228b75d4450f501bda1f42c8c1cbd29ee
[ "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
3,421
lean
import data.matrix.notation import linear_algebra.matrix.determinant import group_theory.perm.fin import tactic.norm_swap variables {α β : Type} [semiring α] [ring β] namespace matrix open_locale matrix example {a a' b b' c c' d d' : α} : ![![a, b], ![c, d]] + ![![a', b'], ![c', d']] = ![![a + a', b + b'], ![c + c', d + d']] := by simp example {a a' b b' c c' d d' : β} : ![![a, b], ![c, d]] - ![![a', b'], ![c', d']] = ![![a - a', b - b'], ![c - c', d - d']] := by simp example {a a' b b' c c' d d' : α} : ![![a, b], ![c, d]] ⬝ ![![a', b'], ![c', d']] = ![![a * a' + b * c', a * b' + b * d'], ![c * a' + d * c', c * b' + d * d']] := by simp example {a b c d x y : α} : mul_vec ![![a, b], ![c, d]] ![x, y] = ![a * x + b * y, c * x + d * y] := by simp example {a b c d : α} : minor ![![a, b], ![c, d]] ![1, 0] ![0] = ![![c], ![a]] := by { ext, simp } example {a b c : α} : ![a, b, c] 0 = a := by simp example {a b c : α} : ![a, b, c] 1 = b := by simp example {a b c : α} : ![a, b, c] 2 = c := by simp example {a b c d : α} : ![a, b, c, d] 0 = a := by simp example {a b c d : α} : ![a, b, c, d] 1 = b := by simp example {a b c d : α} : ![a, b, c, d] 2 = c := by simp example {a b c d : α} : ![a, b, c, d] 3 = d := by simp example {a b c d : α} : ![a, b, c, d] 42 = c := by simp example {a b c d e : α} : ![a, b, c, d, e] 0 = a := by simp example {a b c d e : α} : ![a, b, c, d, e] 1 = b := by simp example {a b c d e : α} : ![a, b, c, d, e] 2 = c := by simp example {a b c d e : α} : ![a, b, c, d, e] 3 = d := by simp example {a b c d e : α} : ![a, b, c, d, e] 4 = e := by simp example {a b c d e : α} : ![a, b, c, d, e] 5 = a := by simp example {a b c d e : α} : ![a, b, c, d, e] 6 = b := by simp example {a b c d e : α} : ![a, b, c, d, e] 7 = c := by simp example {a b c d e : α} : ![a, b, c, d, e] 8 = d := by simp example {a b c d e : α} : ![a, b, c, d, e] 9 = e := by simp example {a b c d e : α} : ![a, b, c, d, e] 123 = d := by simp example {a b c d e : α} : ![a, b, c, d, e] 123456789 = e := by simp example {a b c d e f g h : α} : ![a, b, c, d, e, f, g, h] 5 = f := by simp example {a b c d e f g h : α} : ![a, b, c, d, e, f, g, h] 7 = h := by simp example {a b c d e f g h : α} : ![a, b, c, d, e, f, g, h] 37 = f := by simp example {a b c d e f g h : α} : ![a, b, c, d, e, f, g, h] 99 = d := by simp example {α : Type*} [comm_ring α] {a b c d : α} : matrix.det ![![a, b], ![c, d]] = a * d - b * c := begin simp [matrix.det_succ_row_zero, fin.sum_univ_succ], /- Try this: simp only [matrix.det_succ_row_zero, fin.sum_univ_succ, det_fin_zero, finset.sum_singleton, fin.sum_univ_zero, minor_apply, cons_val_zero, cons_val_succ, fin.succ_above_zero, fin.coe_succ, fin.coe_zero], -/ ring end example {α : Type*} [comm_ring α] (A : matrix (fin 3) (fin 3) α) {a b c d e f g h i : α} : matrix.det ![![a, b, c], ![d, e, f], ![g, h, i]] = a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g := begin simp [matrix.det_succ_row_zero, fin.sum_univ_succ], /- Try this: simp only [matrix.det_succ_row_zero, fin.sum_univ_succ, det_fin_zero, finset.sum_singleton, fin.sum_univ_zero, minor_apply, cons_val_zero, cons_val_succ, fin.succ_above_zero, fin.succ_succ_above_zero, fin.succ_succ_above_succ, fin.coe_zero, fin.coe_succ, pow_zero, pow_add], -/ ring end end matrix
2455e45bf41696d494b42f5eaf5b81712461374d
80746c6dba6a866de5431094bf9f8f841b043d77
/src/algebra/order_functions.lean
6fea01de1d334942d4269bc44a222ce1bca9335c
[ "Apache-2.0" ]
permissive
leanprover-fork/mathlib-backup
8b5c95c535b148fca858f7e8db75a76252e32987
0eb9db6a1a8a605f0cf9e33873d0450f9f0ae9b0
refs/heads/master
1,585,156,056,139
1,548,864,430,000
1,548,864,438,000
143,964,213
0
0
Apache-2.0
1,550,795,966,000
1,533,705,322,000
Lean
UTF-8
Lean
false
false
8,116
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 algebra.ordered_group order.lattice open lattice universes u v variables {α : Type u} {β : Type v} attribute [simp] max_eq_left max_eq_right min_eq_left min_eq_right section variables [decidable_linear_order α] [decidable_linear_order β] {f : α → β} {a b c d : α} -- translate from lattices to linear orders (sup → max, inf → min) @[simp] lemma le_min_iff : c ≤ min a b ↔ c ≤ a ∧ c ≤ b := le_inf_iff @[simp] lemma max_le_iff : max a b ≤ c ↔ a ≤ c ∧ b ≤ c := sup_le_iff lemma max_le_max : a ≤ c → b ≤ d → max a b ≤ max c d := sup_le_sup lemma min_le_min : a ≤ c → b ≤ d → min a b ≤ min c d := inf_le_inf lemma le_max_left_of_le : a ≤ b → a ≤ max b c := le_sup_left_of_le lemma le_max_right_of_le : a ≤ c → a ≤ max b c := le_sup_right_of_le lemma min_le_left_of_le : a ≤ c → min a b ≤ c := inf_le_left_of_le lemma min_le_right_of_le : b ≤ c → min a b ≤ c := inf_le_right_of_le lemma max_min_distrib_left : max a (min b c) = min (max a b) (max a c) := sup_inf_left lemma max_min_distrib_right : max (min a b) c = min (max a c) (max b c) := sup_inf_right lemma min_max_distrib_left : min a (max b c) = max (min a b) (min a c) := inf_sup_left lemma min_max_distrib_right : min (max a b) c = max (min a c) (min b c) := inf_sup_right instance max_idem : is_idempotent α max := by apply_instance instance min_idem : is_idempotent α min := by apply_instance @[simp] lemma min_le_iff : min a b ≤ c ↔ a ≤ c ∨ b ≤ c := have a ≤ b → (a ≤ c ∨ b ≤ c ↔ a ≤ c), from assume h, or_iff_left_of_imp $ le_trans h, have b ≤ a → (a ≤ c ∨ b ≤ c ↔ b ≤ c), from assume h, or_iff_right_of_imp $ le_trans h, by cases le_total a b; simp * @[simp] lemma le_max_iff : a ≤ max b c ↔ a ≤ b ∨ a ≤ c := have b ≤ c → (a ≤ b ∨ a ≤ c ↔ a ≤ c), from assume h, or_iff_right_of_imp $ assume h', le_trans h' h, have c ≤ b → (a ≤ b ∨ a ≤ c ↔ a ≤ b), from assume h, or_iff_left_of_imp $ assume h', le_trans h' h, by cases le_total b c; simp * @[simp] lemma max_lt_iff : max a b < c ↔ (a < c ∧ b < c) := by rw [lt_iff_not_ge]; simp [(≥), le_max_iff, not_or_distrib] @[simp] lemma lt_min_iff : a < min b c ↔ (a < b ∧ a < c) := by rw [lt_iff_not_ge]; simp [(≥), min_le_iff, not_or_distrib] @[simp] lemma lt_max_iff : a < max b c ↔ a < b ∨ a < c := by rw [lt_iff_not_ge]; simp [(≥), max_le_iff, not_and_distrib] @[simp] lemma min_lt_iff : min a b < c ↔ a < c ∨ b < c := by rw [lt_iff_not_ge]; simp [(≥), le_min_iff, not_and_distrib] theorem min_right_comm (a b c : α) : min (min a b) c = min (min a c) b := right_comm min min_comm min_assoc a b c theorem max.left_comm (a b c : α) : max a (max b c) = max b (max a c) := left_comm max max_comm max_assoc a b c theorem max.right_comm (a b c : α) : max (max a b) c = max (max a c) b := right_comm max max_comm max_assoc a b c lemma max_distrib_of_monotone (hf : monotone f) : f (max a b) = max (f a) (f b) := by cases le_total a b; simp [h, hf h] lemma min_distrib_of_monotone (hf : monotone f) : f (min a b) = min (f a) (f b) := by cases le_total a b; simp [h, hf h] theorem min_choice (a b : α) : min a b = a ∨ min a b = b := by by_cases h : a ≤ b; simp [min, h] theorem max_choice (a b : α) : max a b = a ∨ max a b = b := by by_cases h : a ≤ b; simp [max, h] lemma le_of_max_le_left {a b c : α} (h : max a b ≤ c) : a ≤ c := le_trans (le_max_left _ _) h lemma le_of_max_le_right {a b c : α} (h : max a b ≤ c) : b ≤ c := le_trans (le_max_right _ _) h end lemma min_add {α : Type u} [decidable_linear_ordered_comm_group α] (a b c : α) : min a b + c = min (a + c) (b + c) := if hle : a ≤ b then have a - c ≤ b - c, from sub_le_sub hle (le_refl _), by simp * at * else have b - c ≤ a - c, from sub_le_sub (le_of_lt (lt_of_not_ge hle)) (le_refl _), by simp * at * lemma min_sub {α : Type u} [decidable_linear_ordered_comm_group α] (a b c : α) : min a b - c = min (a - c) (b - c) := by simp [min_add, sub_eq_add_neg] section decidable_linear_ordered_comm_group variables [decidable_linear_ordered_comm_group α] {a b c : α} attribute [simp] abs_zero abs_neg def abs_add := @abs_add_le_abs_add_abs theorem abs_le : abs a ≤ b ↔ - b ≤ a ∧ a ≤ b := ⟨assume h, ⟨neg_le_of_neg_le $ le_trans (neg_le_abs_self _) h, le_trans (le_abs_self _) h⟩, assume ⟨h₁, h₂⟩, abs_le_of_le_of_neg_le h₂ $ neg_le_of_neg_le h₁⟩ lemma abs_lt : abs a < b ↔ - b < a ∧ a < b := ⟨assume h, ⟨neg_lt_of_neg_lt $ lt_of_le_of_lt (neg_le_abs_self _) h, lt_of_le_of_lt (le_abs_self _) h⟩, assume ⟨h₁, h₂⟩, abs_lt_of_lt_of_neg_lt h₂ $ neg_lt_of_neg_lt h₁⟩ lemma abs_sub_le_iff : abs (a - b) ≤ c ↔ a - b ≤ c ∧ b - a ≤ c := by rw [abs_le, neg_le_sub_iff_le_add, @sub_le_iff_le_add' _ _ b, and_comm] lemma abs_sub_lt_iff : abs (a - b) < c ↔ a - b < c ∧ b - a < c := by rw [abs_lt, neg_lt_sub_iff_lt_add, @sub_lt_iff_lt_add' _ _ b, and_comm] def sub_abs_le_abs_sub := @abs_sub_abs_le_abs_sub lemma abs_abs_sub_le_abs_sub (a b : α) : abs (abs a - abs b) ≤ abs (a - b) := abs_sub_le_iff.2 ⟨sub_abs_le_abs_sub _ _, by rw abs_sub; apply sub_abs_le_abs_sub⟩ lemma abs_eq (hb : b ≥ 0) : abs a = b ↔ a = b ∨ a = -b := iff.intro begin cases le_total a 0 with a_nonpos a_nonneg, { rw [abs_of_nonpos a_nonpos, neg_eq_iff_neg_eq, eq_comm], exact or.inr }, { rw [abs_of_nonneg a_nonneg, eq_comm], exact or.inl } end (by intro h; cases h; subst h; try { rw abs_neg }; exact abs_of_nonneg hb) @[simp] lemma abs_eq_zero : abs a = 0 ↔ a = 0 := ⟨eq_zero_of_abs_eq_zero, λ e, e.symm ▸ abs_zero⟩ lemma abs_pos_iff {a : α} : 0 < abs a ↔ a ≠ 0 := ⟨λ h, mt abs_eq_zero.2 (ne_of_gt h), abs_pos_of_ne_zero⟩ lemma abs_le_max_abs_abs (hab : a ≤ b) (hbc : b ≤ c) : abs b ≤ max (abs a) (abs c) := abs_le_of_le_of_neg_le (by simp [le_max_iff, le_trans hbc (le_abs_self c)]) (by simp [le_max_iff, le_trans (neg_le_neg hab) (neg_le_abs_self a)]) theorem abs_le_abs {α : Type*} [decidable_linear_ordered_comm_group α] {a b : α} (h₀ : a ≤ b) (h₁ : -a ≤ b) : abs a ≤ abs b := calc abs a ≤ b : by { apply abs_le_of_le_of_neg_le; assumption } ... ≤ abs b : le_abs_self _ lemma min_le_add_of_nonneg_right {a b : α} (hb : b ≥ 0) : min a b ≤ a + b := calc min a b ≤ a : by apply min_le_left ... ≤ a + b : le_add_of_nonneg_right hb lemma min_le_add_of_nonneg_left {a b : α} (ha : a ≥ 0) : min a b ≤ a + b := calc min a b ≤ b : by apply min_le_right ... ≤ a + b : le_add_of_nonneg_left ha lemma max_le_add_of_nonneg {a b : α} (ha : a ≥ 0) (hb : b ≥ 0) : max a b ≤ a + b := max_le_iff.2 (by split; simpa) end decidable_linear_ordered_comm_group section decidable_linear_ordered_comm_ring variables [decidable_linear_ordered_comm_ring α] {a b c d : α} @[simp] lemma abs_one : abs (1 : α) = 1 := abs_of_pos zero_lt_one lemma monotone_mul_of_nonneg (ha : 0 ≤ a) : monotone (λ x, a*x) := assume b c b_le_c, mul_le_mul_of_nonneg_left b_le_c ha lemma mul_max_of_nonneg (b c : α) (ha : 0 ≤ a) : a * max b c = max (a * b) (a * c) := max_distrib_of_monotone (monotone_mul_of_nonneg ha) lemma mul_min_of_nonneg (b c : α) (ha : 0 ≤ a) : a * min b c = min (a * b) (a * c) := min_distrib_of_monotone (monotone_mul_of_nonneg ha) lemma max_mul_mul_le_max_mul_max (b c : α) (ha : 0 ≤ a) (hd: 0 ≤ d) : max (a * b) (d * c) ≤ max a c * max d b := have ba : b * a ≤ max d b * max c a, from mul_le_mul (le_max_right d b) (le_max_right c a) ha (le_trans hd (le_max_left d b)), have cd : c * d ≤ max a c * max b d, from mul_le_mul (le_max_right a c) (le_max_right b d) hd (le_trans ha (le_max_left a c)), max_le (by simpa [mul_comm, max_comm] using ba) (by simpa [mul_comm, max_comm] using cd) end decidable_linear_ordered_comm_ring
879fe5da703e177258baa06a9fcdcbbf1e0dcb0f
88fb7558b0636ec6b181f2a548ac11ad3919f8a5
/library/init/data/sigma/lex.lean
5f8225223d1c5ecc0f7e58f1c6167ffe5c1153df
[ "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
5,589
lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura -/ prelude import init.data.sigma.basic init.meta universes u v namespace sigma section variables {α : Type u} {β : α → Type v} variable (r : α → α → Prop) variable (s : ∀ a, β a → β a → Prop) -- Lexicographical order based on r and s inductive lex : sigma β → sigma β → Prop | left : ∀ {a₁ : α} (b₁ : β a₁) {a₂ : α} (b₂ : β a₂), r a₁ a₂ → lex (sigma.mk a₁ b₁) (sigma.mk a₂ b₂) | right : ∀ (a : α) {b₁ b₂ : β a}, s a b₁ b₂ → lex (sigma.mk a b₁) (sigma.mk a b₂) end section open well_founded tactic parameters {α : Type u} {β : α → Type v} parameters {r : α → α → Prop} {s : Π a : α, β a → β a → Prop} local infix `≺`:50 := lex r s def lex_accessible {a} (aca : acc r a) (acb : ∀ a, well_founded (s a)) : ∀ (b : β a), acc (lex r s) (sigma.mk a b) := acc.rec_on aca (λ xa aca (iha : ∀ y, r y xa → ∀ b : β y, acc (lex r s) (sigma.mk y b)), λ b : β xa, acc.rec_on (well_founded.apply (acb xa) b) (λ xb acb (ihb : ∀ (y : β xa), s xa y xb → acc (lex r s) (sigma.mk xa y)), acc.intro (sigma.mk xa xb) (λ p (lt : p ≺ (sigma.mk xa xb)), have aux : xa = xa → xb == xb → acc (lex r s) p, from @sigma.lex.rec_on α β r s (λ p₁ p₂, p₂.1 = xa → p₂.2 == xb → acc (lex r s) p₁) p (sigma.mk xa xb) lt (λ (a₁ : α) (b₁ : β a₁) (a₂ : α) (b₂ : β a₂) (h : r a₁ a₂) (eq₂ : a₂ = xa) (eq₃ : b₂ == xb), begin subst eq₂, exact iha a₁ h b₁ end) (λ (a : α) (b₁ b₂ : β a) (h : s a b₁ b₂) (eq₂ : a = xa) (eq₃ : b₂ == xb), begin subst eq₂, note new_eq₃ := eq_of_heq eq₃, subst new_eq₃, exact ihb b₁ h end), aux rfl (heq.refl xb)))) -- The lexicographical order of well founded relations is well-founded def lex_wf (ha : well_founded r) (hb : ∀ x, well_founded (s x)) : well_founded (lex r s) := well_founded.intro (λ p, cases_on p (λ a b, lex_accessible (well_founded.apply ha a) hb b)) end section parameters {α : Type u} {β : Type v} def lex_ndep (r : α → α → Prop) (s : β → β → Prop) := lex r (λ a : α, s) def lex_ndep_wf {r : α → α → Prop} {s : β → β → Prop} (ha : well_founded r) (hb : well_founded s) : well_founded (lex_ndep r s) := well_founded.intro (λ p, cases_on p (λ a b, lex_accessible (well_founded.apply ha a) (λ x, hb) b)) end section variables {α : Type u} {β : Type v} variable (r : α → α → Prop) variable (s : β → β → Prop) -- Reverse lexicographical order based on r and s inductive rev_lex : @sigma α (λ a, β) → @sigma α (λ a, β) → Prop | left : ∀ {a₁ a₂ : α} (b : β), r a₁ a₂ → rev_lex (sigma.mk a₁ b) (sigma.mk a₂ b) | right : ∀ (a₁ : α) {b₁ : β} (a₂ : α) {b₂ : β}, s b₁ b₂ → rev_lex (sigma.mk a₁ b₁) (sigma.mk a₂ b₂) end section open well_founded tactic parameters {α : Type u} {β : Type v} parameters {r : α → α → Prop} {s : β → β → Prop} local infix `≺`:50 := rev_lex r s def rev_lex_accessible {b} (acb : acc s b) (aca : ∀ a, acc r a): ∀ a, acc (rev_lex r s) (sigma.mk a b) := acc.rec_on acb (λ xb acb (ihb : ∀ y, s y xb → ∀ a, acc (rev_lex r s) (sigma.mk a y)), λ a, acc.rec_on (aca a) (λ xa aca (iha : ∀ y, r y xa → acc (rev_lex r s) (mk y xb)), acc.intro (sigma.mk xa xb) (λ p (lt : p ≺ (sigma.mk xa xb)), have aux : xa = xa → xb = xb → acc (rev_lex r s) p, from @rev_lex.rec_on α β r s (λ p₁ p₂, fst p₂ = xa → snd p₂ = xb → acc (rev_lex r s) p₁) p (sigma.mk xa xb) lt (λ a₁ a₂ b (h : r a₁ a₂) (eq₂ : a₂ = xa) (eq₃ : b = xb), show acc (rev_lex r s) (sigma.mk a₁ b), from have r₁ : r a₁ xa, from eq.rec_on eq₂ h, have aux : acc (rev_lex r s) (sigma.mk a₁ xb), from iha a₁ r₁, eq.rec_on (eq.symm eq₃) aux) (λ a₁ b₁ a₂ b₂ (h : s b₁ b₂) (eq₂ : a₂ = xa) (eq₃ : b₂ = xb), show acc (rev_lex r s) (mk a₁ b₁), from have s₁ : s b₁ xb, from eq.rec_on eq₃ h, ihb b₁ s₁ a₁), aux rfl rfl))) def rev_lex_wf (ha : well_founded r) (hb : well_founded s) : well_founded (rev_lex r s) := well_founded.intro (λ p, cases_on p (λ a b, rev_lex_accessible (apply hb b) (well_founded.apply ha) a)) end section def skip_left (α : Type u) {β : Type v} (s : β → β → Prop) : @sigma α (λ a, β) → @sigma α (λ a, β) → Prop := rev_lex empty_relation s def skip_left_wf (α : Type u) {β : Type v} {s : β → β → Prop} (hb : well_founded s) : well_founded (skip_left α s) := rev_lex_wf empty_wf hb def mk_skip_left {α : Type u} {β : Type v} {b₁ b₂ : β} {s : β → β → Prop} (a₁ a₂ : α) (h : s b₁ b₂) : skip_left α s (sigma.mk a₁ b₁) (sigma.mk a₂ b₂) := rev_lex.right _ _ _ h end end sigma
4cbb4a25e5ee777dfdaeb88a56e6c05efe6f86f3
94e33a31faa76775069b071adea97e86e218a8ee
/src/geometry/manifold/cont_mdiff.lean
2c1c12497729721142e4efb76da944ee33044655
[ "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
85,008
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 geometry.manifold.mfderiv import geometry.manifold.local_invariant_properties /-! # Smooth functions between smooth manifolds We define `Cⁿ` functions between smooth manifolds, as functions which are `Cⁿ` in charts, and prove basic properties of these notions. ## Main definitions and statements Let `M ` and `M'` be two smooth manifolds, with respect to model with corners `I` and `I'`. Let `f : M → M'`. * `cont_mdiff_within_at I I' n f s x` states that the function `f` is `Cⁿ` within the set `s` around the point `x`. * `cont_mdiff_at I I' n f x` states that the function `f` is `Cⁿ` around `x`. * `cont_mdiff_on I I' n f s` states that the function `f` is `Cⁿ` on the set `s` * `cont_mdiff I I' n f` states that the function `f` is `Cⁿ`. * `cont_mdiff_on.comp` gives the invariance of the `Cⁿ` property under composition * `cont_mdiff_on.cont_mdiff_on_tangent_map_within` states that the bundled derivative of a `Cⁿ` function in a domain is `Cᵐ` when `m + 1 ≤ n`. * `cont_mdiff.cont_mdiff_tangent_map` states that the bundled derivative of a `Cⁿ` function is `Cᵐ` when `m + 1 ≤ n`. * `cont_mdiff_iff_cont_diff` states that, for functions between vector spaces, manifold-smoothness is equivalent to usual smoothness. We also give many basic properties of smooth functions between manifolds, following the API of smooth functions between vector spaces. ## Implementation details Many properties follow for free from the corresponding properties of functions in vector spaces, as being `Cⁿ` is a local property invariant under the smooth groupoid. We take advantage of the general machinery developed in `local_invariant_properties.lean` to get these properties automatically. For instance, the fact that being `Cⁿ` does not depend on the chart one considers is given by `lift_prop_within_at_indep_chart`. For this to work, the definition of `cont_mdiff_within_at` and friends has to follow definitionally the setup of local invariant properties. Still, we recast the definition in terms of extended charts in `cont_mdiff_on_iff` and `cont_mdiff_iff`. -/ open set function filter charted_space smooth_manifold_with_corners open_locale topological_space manifold /-! ### Definition of smooth functions between manifolds -/ variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜] -- declare a smooth manifold `M` over the pair `(E, H)`. {E : Type*} [normed_group E] [normed_space 𝕜 E] {H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H) {M : Type*} [topological_space M] [charted_space H M] [Is : smooth_manifold_with_corners I M] -- declare a smooth manifold `M'` over the pair `(E', H')`. {E' : Type*} [normed_group E'] [normed_space 𝕜 E'] {H' : Type*} [topological_space H'] (I' : model_with_corners 𝕜 E' H') {M' : Type*} [topological_space M'] [charted_space H' M'] [I's : smooth_manifold_with_corners I' M'] -- declare a smooth manifold `N` over the pair `(F, G)`. {F : Type*} [normed_group F] [normed_space 𝕜 F] {G : Type*} [topological_space G] {J : model_with_corners 𝕜 F G} {N : Type*} [topological_space N] [charted_space G N] [Js : smooth_manifold_with_corners J N] -- declare a smooth manifold `N'` over the pair `(F', G')`. {F' : Type*} [normed_group F'] [normed_space 𝕜 F'] {G' : Type*} [topological_space G'] {J' : model_with_corners 𝕜 F' G'} {N' : Type*} [topological_space N'] [charted_space G' N'] [J's : smooth_manifold_with_corners J' N'] -- declare functions, sets, points and smoothness indices {f f₁ : M → M'} {s s₁ t : set M} {x : M} {m n : with_top ℕ} /-- Property in the model space of a model with corners of being `C^n` within at set at a point, when read in the model vector space. This property will be lifted to manifolds to define smooth functions between manifolds. -/ def cont_diff_within_at_prop (n : with_top ℕ) (f : H → H') (s : set H) (x : H) : Prop := cont_diff_within_at 𝕜 n (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) (I x) /-- Being `Cⁿ` in the model space is a local property, invariant under smooth maps. Therefore, it will lift nicely to manifolds. -/ lemma cont_diff_within_at_local_invariant_prop (n : with_top ℕ) : (cont_diff_groupoid ∞ I).local_invariant_prop (cont_diff_groupoid ∞ I') (cont_diff_within_at_prop I I' n) := { is_local := begin assume s x u f u_open xu, have : I.symm ⁻¹' (s ∩ u) ∩ range I = (I.symm ⁻¹' s ∩ range I) ∩ I.symm ⁻¹' u, by simp only [inter_right_comm, preimage_inter], rw [cont_diff_within_at_prop, cont_diff_within_at_prop, this], symmetry, apply cont_diff_within_at_inter, have : u ∈ 𝓝 (I.symm (I x)), by { rw [model_with_corners.left_inv], exact is_open.mem_nhds u_open xu }, apply continuous_at.preimage_mem_nhds I.continuous_symm.continuous_at this, end, right_invariance := begin assume s x f e he hx h, rw cont_diff_within_at_prop at h ⊢, have : I x = (I ∘ e.symm ∘ I.symm) (I (e x)), by simp only [hx] with mfld_simps, rw this at h, have : I (e x) ∈ (I.symm) ⁻¹' e.target ∩ range I, by simp only [hx] with mfld_simps, have := ((mem_groupoid_of_pregroupoid.2 he).2.cont_diff_within_at this).of_le le_top, convert (h.comp' _ this).mono_of_mem _ using 1, { ext y, simp only with mfld_simps }, refine mem_nhds_within.mpr ⟨I.symm ⁻¹' e.target, e.open_target.preimage I.continuous_symm, by simp_rw [mem_preimage, I.left_inv, e.maps_to hx], _⟩, mfld_set_tac end, congr_of_forall := begin assume s x f g h hx hf, apply hf.congr, { assume y hy, simp only with mfld_simps at hy, simp only [h, hy] with mfld_simps }, { simp only [hx] with mfld_simps } end, left_invariance' := begin assume s x f e' he' hs hx h, rw cont_diff_within_at_prop at h ⊢, have A : (I' ∘ f ∘ I.symm) (I x) ∈ (I'.symm ⁻¹' e'.source ∩ range I'), by simp only [hx] with mfld_simps, have := ((mem_groupoid_of_pregroupoid.2 he').1.cont_diff_within_at A).of_le le_top, convert this.comp _ h _, { ext y, simp only with mfld_simps }, { assume y hy, simp only with mfld_simps at hy, simpa only [hy] with mfld_simps using hs hy.1 } end } lemma cont_diff_within_at_prop_mono (n : with_top ℕ) ⦃s x t⦄ ⦃f : H → H'⦄ (hts : t ⊆ s) (h : cont_diff_within_at_prop I I' n f s x) : cont_diff_within_at_prop I I' n f t x := begin apply h.mono (λ y hy, _), simp only with mfld_simps at hy, simp only [hy, hts _] with mfld_simps end lemma cont_diff_within_at_prop_id (x : H) : cont_diff_within_at_prop I I ∞ id univ x := begin simp [cont_diff_within_at_prop], have : cont_diff_within_at 𝕜 ∞ id (range I) (I x) := cont_diff_id.cont_diff_at.cont_diff_within_at, apply this.congr (λ y hy, _), { simp only with mfld_simps }, { simp only [model_with_corners.right_inv I hy] with mfld_simps } end /-- A function is `n` times continuously differentiable within a set at a point in a manifold if it is continuous and it is `n` times continuously differentiable in this set around this point, when read in the preferred chart at this point. -/ def cont_mdiff_within_at (n : with_top ℕ) (f : M → M') (s : set M) (x : M) := lift_prop_within_at (cont_diff_within_at_prop I I' n) f s x /-- Abbreviation for `cont_mdiff_within_at I I' ⊤ f s x`. See also documentation for `smooth`. -/ @[reducible] def smooth_within_at (f : M → M') (s : set M) (x : M) := cont_mdiff_within_at I I' ⊤ f s x /-- A function is `n` times continuously differentiable at a point in a manifold if it is continuous and it is `n` times continuously differentiable around this point, when read in the preferred chart at this point. -/ def cont_mdiff_at (n : with_top ℕ) (f : M → M') (x : M) := cont_mdiff_within_at I I' n f univ x lemma cont_mdiff_at_iff {n : with_top ℕ} {f : M → M'} {x : M} : cont_mdiff_at I I' n f x ↔ continuous_at f x ∧ cont_diff_within_at 𝕜 n (ext_chart_at I' (f x) ∘ f ∘ (ext_chart_at I x).symm) (range I) (ext_chart_at I x x) := lift_prop_at_iff.trans $ by { rw [cont_diff_within_at_prop, preimage_univ, univ_inter], refl } /-- Abbreviation for `cont_mdiff_at I I' ⊤ f x`. See also documentation for `smooth`. -/ @[reducible] def smooth_at (f : M → M') (x : M) := cont_mdiff_at I I' ⊤ f x /-- A function is `n` times continuously differentiable in a set of a manifold if it is continuous and, for any pair of points, it is `n` times continuously differentiable on this set in the charts around these points. -/ def cont_mdiff_on (n : with_top ℕ) (f : M → M') (s : set M) := ∀ x ∈ s, cont_mdiff_within_at I I' n f s x /-- Abbreviation for `cont_mdiff_on I I' ⊤ f s`. See also documentation for `smooth`. -/ @[reducible] def smooth_on (f : M → M') (s : set M) := cont_mdiff_on I I' ⊤ f s /-- A function is `n` times continuously differentiable in a manifold if it is continuous and, for any pair of points, it is `n` times continuously differentiable in the charts around these points. -/ def cont_mdiff (n : with_top ℕ) (f : M → M') := ∀ x, cont_mdiff_at I I' n f x /-- Abbreviation for `cont_mdiff I I' ⊤ f`. Short note to work with these abbreviations: a lemma of the form `cont_mdiff_foo.bar` will apply fine to an assumption `smooth_foo` using dot notation or normal notation. If the consequence `bar` of the lemma involves `cont_diff`, it is still better to restate the lemma replacing `cont_diff` with `smooth` both in the assumption and in the conclusion, to make it possible to use `smooth` consistently. This also applies to `smooth_at`, `smooth_on` and `smooth_within_at`.-/ @[reducible] def smooth (f : M → M') := cont_mdiff I I' ⊤ f /-! ### Basic properties of smooth functions between manifolds -/ variables {I I'} lemma cont_mdiff.smooth (h : cont_mdiff I I' ⊤ f) : smooth I I' f := h lemma smooth.cont_mdiff (h : smooth I I' f) : cont_mdiff I I' ⊤ f := h lemma cont_mdiff_on.smooth_on (h : cont_mdiff_on I I' ⊤ f s) : smooth_on I I' f s := h lemma smooth_on.cont_mdiff_on (h : smooth_on I I' f s) : cont_mdiff_on I I' ⊤ f s := h lemma cont_mdiff_at.smooth_at (h : cont_mdiff_at I I' ⊤ f x) : smooth_at I I' f x := h lemma smooth_at.cont_mdiff_at (h : smooth_at I I' f x) : cont_mdiff_at I I' ⊤ f x := h lemma cont_mdiff_within_at.smooth_within_at (h : cont_mdiff_within_at I I' ⊤ f s x) : smooth_within_at I I' f s x := h lemma smooth_within_at.cont_mdiff_within_at (h : smooth_within_at I I' f s x) : cont_mdiff_within_at I I' ⊤ f s x := h lemma cont_mdiff.cont_mdiff_at (h : cont_mdiff I I' n f) : cont_mdiff_at I I' n f x := h x lemma smooth.smooth_at (h : smooth I I' f) : smooth_at I I' f x := cont_mdiff.cont_mdiff_at h lemma cont_mdiff_within_at_univ : cont_mdiff_within_at I I' n f univ x ↔ cont_mdiff_at I I' n f x := iff.rfl lemma smooth_at_univ : smooth_within_at I I' f univ x ↔ smooth_at I I' f x := cont_mdiff_within_at_univ lemma cont_mdiff_on_univ : cont_mdiff_on I I' n f univ ↔ cont_mdiff I I' n f := by simp only [cont_mdiff_on, cont_mdiff, cont_mdiff_within_at_univ, forall_prop_of_true, mem_univ] lemma smooth_on_univ : smooth_on I I' f univ ↔ smooth I I' f := cont_mdiff_on_univ /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in the corresponding extended chart. -/ lemma cont_mdiff_within_at_iff : cont_mdiff_within_at I I' n f s x ↔ continuous_within_at f s x ∧ cont_diff_within_at 𝕜 n ((ext_chart_at I' (f x)) ∘ f ∘ (ext_chart_at I x).symm) ((ext_chart_at I x).symm ⁻¹' s ∩ range I) (ext_chart_at I x x) := iff.rfl /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in the corresponding extended chart. This form states smoothness of `f` written in such a way that the set is restricted to lie within the domain/codomain of the corresponding charts. Even though this expression is more complicated than the one in `cont_mdiff_within_at_iff`, it is a smaller set, but their germs at `ext_chart_at I x x` are equal. It is sometimes useful to rewrite using this in the goal. -/ lemma cont_mdiff_within_at_iff' : cont_mdiff_within_at I I' n f s x ↔ continuous_within_at f s x ∧ cont_diff_within_at 𝕜 n ((ext_chart_at I' (f x)) ∘ f ∘ (ext_chart_at I x).symm) ((ext_chart_at I x).target ∩ (ext_chart_at I x).symm ⁻¹' (s ∩ f ⁻¹' (ext_chart_at I' (f x)).source)) (ext_chart_at I x x) := begin rw [cont_mdiff_within_at_iff, and.congr_right_iff], set e := ext_chart_at I x, set e' := ext_chart_at I' (f x), refine λ hc, cont_diff_within_at_congr_nhds _, rw [← e.image_source_inter_eq', ← ext_chart_at_map_nhds_within_eq_image, ← ext_chart_at_map_nhds_within, inter_comm, nhds_within_inter_of_mem], exact hc (ext_chart_at_source_mem_nhds _ _) end /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in the corresponding extended chart in the target. -/ lemma cont_mdiff_within_at_iff_target : cont_mdiff_within_at I I' n f s x ↔ continuous_within_at f s x ∧ cont_mdiff_within_at I 𝓘(𝕜, E') n (ext_chart_at I' (f x) ∘ f) s x := begin simp_rw [cont_mdiff_within_at, lift_prop_within_at, ← and_assoc], have cont : (continuous_within_at f s x ∧ continuous_within_at (ext_chart_at I' (f x) ∘ f) s x) ↔ continuous_within_at f s x, { refine ⟨λ h, h.1, λ h, ⟨h, _⟩⟩, have h₂ := (chart_at H' (f x)).continuous_to_fun.continuous_within_at (mem_chart_source _ _), refine ((I'.continuous_at.comp_continuous_within_at h₂).comp' h).mono_of_mem _, exact inter_mem self_mem_nhds_within (h.preimage_mem_nhds_within $ (chart_at _ _).open_source.mem_nhds $ mem_chart_source _ _) }, simp_rw [cont, cont_diff_within_at_prop, ext_chart_at, local_equiv.coe_trans, model_with_corners.to_local_equiv_coe, local_homeomorph.coe_coe, model_with_corners_self_coe, chart_at_self_eq, local_homeomorph.refl_apply, comp.left_id] end lemma smooth_within_at_iff : smooth_within_at I I' f s x ↔ continuous_within_at f s x ∧ cont_diff_within_at 𝕜 ∞ (ext_chart_at I' (f x) ∘ f ∘ (ext_chart_at I x).symm) ((ext_chart_at I x).symm ⁻¹' s ∩ range I) (ext_chart_at I x x) := cont_mdiff_within_at_iff lemma smooth_within_at_iff_target : smooth_within_at I I' f s x ↔ continuous_within_at f s x ∧ smooth_within_at I 𝓘(𝕜, E') (ext_chart_at I' (f x) ∘ f) s x := cont_mdiff_within_at_iff_target include Is I's /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in any chart containing that point. -/ lemma cont_mdiff_within_at_iff_of_mem_source {x' : M} {y : M'} (hx : x' ∈ (chart_at H x).source) (hy : f x' ∈ (chart_at H' y).source) : cont_mdiff_within_at I I' n f s x' ↔ continuous_within_at f s x' ∧ cont_diff_within_at 𝕜 n (ext_chart_at I' y ∘ f ∘ (ext_chart_at I x).symm) ((ext_chart_at I x).symm ⁻¹' s ∩ range I) (ext_chart_at I x x') := (cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_indep_chart (structure_groupoid.chart_mem_maximal_atlas _ x) hx (structure_groupoid.chart_mem_maximal_atlas _ y) hy lemma cont_mdiff_within_at_iff_of_mem_source' {x' : M} {y : M'} (hx : x' ∈ (chart_at H x).source) (hy : f x' ∈ (chart_at H' y).source) : cont_mdiff_within_at I I' n f s x' ↔ continuous_within_at f s x' ∧ cont_diff_within_at 𝕜 n ((ext_chart_at I' y) ∘ f ∘ (ext_chart_at I x).symm) ((ext_chart_at I x).target ∩ (ext_chart_at I x).symm ⁻¹' (s ∩ f ⁻¹' (ext_chart_at I' y).source)) (ext_chart_at I x x') := begin refine (cont_mdiff_within_at_iff_of_mem_source hx hy).trans _, rw [← ext_chart_at_source I] at hx, rw [← ext_chart_at_source I'] at hy, rw [and.congr_right_iff], set e := ext_chart_at I x, set e' := ext_chart_at I' (f x), refine λ hc, cont_diff_within_at_congr_nhds _, rw [← e.image_source_inter_eq', ← ext_chart_at_map_nhds_within_eq_image' I x hx, ← ext_chart_at_map_nhds_within' I x hx, inter_comm, nhds_within_inter_of_mem], exact hc ((ext_chart_at_open_source _ _).mem_nhds hy) end lemma cont_mdiff_at_iff_of_mem_source {x' : M} {y : M'} (hx : x' ∈ (chart_at H x).source) (hy : f x' ∈ (chart_at H' y).source) : cont_mdiff_at I I' n f x' ↔ continuous_at f x' ∧ cont_diff_within_at 𝕜 n (ext_chart_at I' y ∘ f ∘ (ext_chart_at I x).symm) (range I) (ext_chart_at I x x') := (cont_mdiff_within_at_iff_of_mem_source hx hy).trans $ by rw [continuous_within_at_univ, preimage_univ, univ_inter] omit I's lemma cont_mdiff_at_ext_chart_at' {x' : M} (h : x' ∈ (chart_at H x).source) : cont_mdiff_at I 𝓘(𝕜, E) n (ext_chart_at I x) x' := begin refine (cont_mdiff_at_iff_of_mem_source h (mem_chart_source _ _)).mpr _, rw [← ext_chart_at_source I] at h, refine ⟨ext_chart_at_continuous_at' _ _ h, _⟩, refine cont_diff_within_at_id.congr_of_eventually_eq _ _, { refine eventually_eq_of_mem (ext_chart_at_target_mem_nhds_within' I x h) (λ x₂ hx₂, _), simp_rw [function.comp_apply, (ext_chart_at I x).right_inv hx₂], refl }, simp_rw [function.comp_apply, (ext_chart_at I x).right_inv ((ext_chart_at I x).maps_to h)], refl end lemma cont_mdiff_at_ext_chart_at : cont_mdiff_at I 𝓘(𝕜, E) n (ext_chart_at I x) x := cont_mdiff_at_ext_chart_at' $ mem_chart_source H x include I's /-- One can reformulate smoothness on a set as continuity on this set, and smoothness in any extended chart. -/ lemma cont_mdiff_on_iff : cont_mdiff_on I I' n f s ↔ continuous_on f s ∧ ∀ (x : M) (y : M'), cont_diff_on 𝕜 n (ext_chart_at I' y ∘ f ∘ (ext_chart_at I x).symm) ((ext_chart_at I x).target ∩ (ext_chart_at I x).symm ⁻¹' (s ∩ f ⁻¹' (ext_chart_at I' y).source)) := begin split, { assume h, refine ⟨λ x hx, (h x hx).1, λ x y z hz, _⟩, simp only with mfld_simps at hz, let w := (ext_chart_at I x).symm z, have : w ∈ s, by simp only [w, hz] with mfld_simps, specialize h w this, have w1 : w ∈ (chart_at H x).source, by simp only [w, hz] with mfld_simps, have w2 : f w ∈ (chart_at H' y).source, by simp only [w, hz] with mfld_simps, convert ((cont_mdiff_within_at_iff_of_mem_source w1 w2).mp h).2.mono _, { simp only [w, hz] with mfld_simps }, { mfld_set_tac } }, { rintros ⟨hcont, hdiff⟩ x hx, refine ((cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_iff $ hcont x hx).mpr _, dsimp [cont_diff_within_at_prop], convert hdiff x (f x) (ext_chart_at I x x) (by simp only [hx] with mfld_simps) using 1, mfld_set_tac } end /-- One can reformulate smoothness on a set as continuity on this set, and smoothness in any extended chart in the target. -/ lemma cont_mdiff_on_iff_target : cont_mdiff_on I I' n f s ↔ continuous_on f s ∧ ∀ (y : M'), cont_mdiff_on I 𝓘(𝕜, E') n (ext_chart_at I' y ∘ f) (s ∩ f ⁻¹' (ext_chart_at I' y).source) := begin inhabit E', simp only [cont_mdiff_on_iff, model_with_corners.source_eq, chart_at_self_eq, local_homeomorph.refl_local_equiv, local_equiv.refl_trans, ext_chart_at.equations._eqn_1, set.preimage_univ, set.inter_univ, and.congr_right_iff], intros h, split, { refine λ h' y, ⟨_, λ x _, h' x y⟩, have h'' : continuous_on _ univ := (model_with_corners.continuous I').continuous_on, convert (h''.comp' (chart_at H' y).continuous_to_fun).comp' h, simp }, { exact λ h' x y, (h' y).2 x default } end lemma smooth_on_iff : smooth_on I I' f s ↔ continuous_on f s ∧ ∀ (x : M) (y : M'), cont_diff_on 𝕜 ⊤ (ext_chart_at I' y ∘ f ∘ (ext_chart_at I x).symm) ((ext_chart_at I x).target ∩ (ext_chart_at I x).symm ⁻¹' (s ∩ f ⁻¹' (ext_chart_at I' y).source)) := cont_mdiff_on_iff lemma smooth_on_iff_target : smooth_on I I' f s ↔ continuous_on f s ∧ ∀ (y : M'), smooth_on I 𝓘(𝕜, E') (ext_chart_at I' y ∘ f) (s ∩ f ⁻¹' (ext_chart_at I' y).source) := cont_mdiff_on_iff_target /-- One can reformulate smoothness as continuity and smoothness in any extended chart. -/ lemma cont_mdiff_iff : cont_mdiff I I' n f ↔ continuous f ∧ ∀ (x : M) (y : M'), cont_diff_on 𝕜 n (ext_chart_at I' y ∘ f ∘ (ext_chart_at I x).symm) ((ext_chart_at I x).target ∩ (ext_chart_at I x).symm ⁻¹' (f ⁻¹' (ext_chart_at I' y).source)) := by simp [← cont_mdiff_on_univ, cont_mdiff_on_iff, continuous_iff_continuous_on_univ] /-- One can reformulate smoothness as continuity and smoothness in any extended chart in the target. -/ lemma cont_mdiff_iff_target : cont_mdiff I I' n f ↔ continuous f ∧ ∀ (y : M'), cont_mdiff_on I 𝓘(𝕜, E') n (ext_chart_at I' y ∘ f) (f ⁻¹' (ext_chart_at I' y).source) := begin rw [← cont_mdiff_on_univ, cont_mdiff_on_iff_target], simp [continuous_iff_continuous_on_univ] end lemma smooth_iff : smooth I I' f ↔ continuous f ∧ ∀ (x : M) (y : M'), cont_diff_on 𝕜 ⊤ (ext_chart_at I' y ∘ f ∘ (ext_chart_at I x).symm) ((ext_chart_at I x).target ∩ (ext_chart_at I x).symm ⁻¹' (f ⁻¹' (ext_chart_at I' y).source)) := cont_mdiff_iff lemma smooth_iff_target : smooth I I' f ↔ continuous f ∧ ∀ (y : M'), smooth_on I 𝓘(𝕜, E') (ext_chart_at I' y ∘ f) (f ⁻¹' (ext_chart_at I' y).source) := cont_mdiff_iff_target omit Is I's /-! ### Deducing smoothness from higher smoothness -/ lemma cont_mdiff_within_at.of_le (hf : cont_mdiff_within_at I I' n f s x) (le : m ≤ n) : cont_mdiff_within_at I I' m f s x := ⟨hf.1, hf.2.of_le le⟩ lemma cont_mdiff_at.of_le (hf : cont_mdiff_at I I' n f x) (le : m ≤ n) : cont_mdiff_at I I' m f x := cont_mdiff_within_at.of_le hf le lemma cont_mdiff_on.of_le (hf : cont_mdiff_on I I' n f s) (le : m ≤ n) : cont_mdiff_on I I' m f s := λ x hx, (hf x hx).of_le le lemma cont_mdiff.of_le (hf : cont_mdiff I I' n f) (le : m ≤ n) : cont_mdiff I I' m f := λ x, (hf x).of_le le /-! ### Deducing smoothness from smoothness one step beyond -/ lemma cont_mdiff_within_at.of_succ {n : ℕ} (h : cont_mdiff_within_at I I' n.succ f s x) : cont_mdiff_within_at I I' n f s x := h.of_le (with_top.coe_le_coe.2 (nat.le_succ n)) lemma cont_mdiff_at.of_succ {n : ℕ} (h : cont_mdiff_at I I' n.succ f x) : cont_mdiff_at I I' n f x := cont_mdiff_within_at.of_succ h lemma cont_mdiff_on.of_succ {n : ℕ} (h : cont_mdiff_on I I' n.succ f s) : cont_mdiff_on I I' n f s := λ x hx, (h x hx).of_succ lemma cont_mdiff.of_succ {n : ℕ} (h : cont_mdiff I I' n.succ f) : cont_mdiff I I' n f := λ x, (h x).of_succ /-! ### Deducing continuity from smoothness-/ lemma cont_mdiff_within_at.continuous_within_at (hf : cont_mdiff_within_at I I' n f s x) : continuous_within_at f s x := hf.1 lemma cont_mdiff_at.continuous_at (hf : cont_mdiff_at I I' n f x) : continuous_at f x := (continuous_within_at_univ _ _ ).1 $ cont_mdiff_within_at.continuous_within_at hf lemma cont_mdiff_on.continuous_on (hf : cont_mdiff_on I I' n f s) : continuous_on f s := λ x hx, (hf x hx).continuous_within_at lemma cont_mdiff.continuous (hf : cont_mdiff I I' n f) : continuous f := continuous_iff_continuous_at.2 $ λ x, (hf x).continuous_at /-! ### Deducing differentiability from smoothness -/ lemma cont_mdiff_within_at.mdifferentiable_within_at (hf : cont_mdiff_within_at I I' n f s x) (hn : 1 ≤ n) : mdifferentiable_within_at I I' f s x := begin suffices h : mdifferentiable_within_at I I' f (s ∩ (f ⁻¹' (ext_chart_at I' (f x)).source)) x, { rwa mdifferentiable_within_at_inter' at h, apply (hf.1).preimage_mem_nhds_within, exact is_open.mem_nhds (ext_chart_at_open_source I' (f x)) (mem_ext_chart_source I' (f x)) }, rw mdifferentiable_within_at_iff, exact ⟨hf.1.mono (inter_subset_left _ _), (hf.2.differentiable_within_at hn).mono (by mfld_set_tac)⟩, end lemma cont_mdiff_at.mdifferentiable_at (hf : cont_mdiff_at I I' n f x) (hn : 1 ≤ n) : mdifferentiable_at I I' f x := mdifferentiable_within_at_univ.1 $ cont_mdiff_within_at.mdifferentiable_within_at hf hn lemma cont_mdiff_on.mdifferentiable_on (hf : cont_mdiff_on I I' n f s) (hn : 1 ≤ n) : mdifferentiable_on I I' f s := λ x hx, (hf x hx).mdifferentiable_within_at hn lemma cont_mdiff.mdifferentiable (hf : cont_mdiff I I' n f) (hn : 1 ≤ n) : mdifferentiable I I' f := λ x, (hf x).mdifferentiable_at hn lemma smooth.mdifferentiable (hf : smooth I I' f) : mdifferentiable I I' f := cont_mdiff.mdifferentiable hf le_top lemma smooth.mdifferentiable_at (hf : smooth I I' f) : mdifferentiable_at I I' f x := hf.mdifferentiable x lemma smooth.mdifferentiable_within_at (hf : smooth I I' f) : mdifferentiable_within_at I I' f s x := hf.mdifferentiable_at.mdifferentiable_within_at /-! ### `C^∞` smoothness -/ lemma cont_mdiff_within_at_top : smooth_within_at I I' f s x ↔ (∀n:ℕ, cont_mdiff_within_at I I' n f s x) := ⟨λ h n, ⟨h.1, cont_diff_within_at_top.1 h.2 n⟩, λ H, ⟨(H 0).1, cont_diff_within_at_top.2 (λ n, (H n).2)⟩⟩ lemma cont_mdiff_at_top : smooth_at I I' f x ↔ (∀n:ℕ, cont_mdiff_at I I' n f x) := cont_mdiff_within_at_top lemma cont_mdiff_on_top : smooth_on I I' f s ↔ (∀n:ℕ, cont_mdiff_on I I' n f s) := ⟨λ h n, h.of_le le_top, λ h x hx, cont_mdiff_within_at_top.2 (λ n, h n x hx)⟩ lemma cont_mdiff_top : smooth I I' f ↔ (∀n:ℕ, cont_mdiff I I' n f) := ⟨λ h n, h.of_le le_top, λ h x, cont_mdiff_within_at_top.2 (λ n, h n x)⟩ lemma cont_mdiff_within_at_iff_nat : cont_mdiff_within_at I I' n f s x ↔ (∀m:ℕ, (m : with_top ℕ) ≤ n → cont_mdiff_within_at I I' m f s x) := begin refine ⟨λ h m hm, h.of_le hm, λ h, _⟩, cases n, { exact cont_mdiff_within_at_top.2 (λ n, h n le_top) }, { exact h n le_rfl } end /-! ### Restriction to a smaller set -/ lemma cont_mdiff_within_at.mono (hf : cont_mdiff_within_at I I' n f s x) (hts : t ⊆ s) : cont_mdiff_within_at I I' n f t x := structure_groupoid.local_invariant_prop.lift_prop_within_at_mono (cont_diff_within_at_prop_mono I I' n) hf hts lemma cont_mdiff_at.cont_mdiff_within_at (hf : cont_mdiff_at I I' n f x) : cont_mdiff_within_at I I' n f s x := cont_mdiff_within_at.mono hf (subset_univ _) lemma smooth_at.smooth_within_at (hf : smooth_at I I' f x) : smooth_within_at I I' f s x := cont_mdiff_at.cont_mdiff_within_at hf lemma cont_mdiff_on.mono (hf : cont_mdiff_on I I' n f s) (hts : t ⊆ s) : cont_mdiff_on I I' n f t := λ x hx, (hf x (hts hx)).mono hts lemma cont_mdiff.cont_mdiff_on (hf : cont_mdiff I I' n f) : cont_mdiff_on I I' n f s := λ x hx, (hf x).cont_mdiff_within_at lemma smooth.smooth_on (hf : smooth I I' f) : smooth_on I I' f s := cont_mdiff.cont_mdiff_on hf lemma cont_mdiff_within_at_inter' (ht : t ∈ 𝓝[s] x) : cont_mdiff_within_at I I' n f (s ∩ t) x ↔ cont_mdiff_within_at I I' n f s x := (cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_inter' ht lemma cont_mdiff_within_at_inter (ht : t ∈ 𝓝 x) : cont_mdiff_within_at I I' n f (s ∩ t) x ↔ cont_mdiff_within_at I I' n f s x := (cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_inter ht lemma cont_mdiff_within_at.cont_mdiff_at (h : cont_mdiff_within_at I I' n f s x) (ht : s ∈ 𝓝 x) : cont_mdiff_at I I' n f x := (cont_diff_within_at_local_invariant_prop I I' n).lift_prop_at_of_lift_prop_within_at h ht lemma smooth_within_at.smooth_at (h : smooth_within_at I I' f s x) (ht : s ∈ 𝓝 x) : smooth_at I I' f x := cont_mdiff_within_at.cont_mdiff_at h ht include Is lemma cont_mdiff_on_ext_chart_at : cont_mdiff_on I 𝓘(𝕜, E) n (ext_chart_at I x) (chart_at H x).source := λ x' hx', (cont_mdiff_at_ext_chart_at' hx').cont_mdiff_within_at include I's /-- A function is `C^n` within a set at a point, for `n : ℕ`, if and only if it is `C^n` on a neighborhood of this point. -/ lemma cont_mdiff_within_at_iff_cont_mdiff_on_nhds {n : ℕ} : cont_mdiff_within_at I I' n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, cont_mdiff_on I I' n f u := begin split, { assume h, -- the property is true in charts. We will pull such a good neighborhood in the chart to the -- manifold. For this, we need to restrict to a small enough set where everything makes sense obtain ⟨o, o_open, xo, ho, h'o⟩ : ∃ (o : set M), is_open o ∧ x ∈ o ∧ o ⊆ (chart_at H x).source ∧ o ∩ s ⊆ f ⁻¹' (chart_at H' (f x)).source, { have : (chart_at H' (f x)).source ∈ 𝓝 (f x) := is_open.mem_nhds (local_homeomorph.open_source _) (mem_chart_source H' (f x)), rcases mem_nhds_within.1 (h.1.preimage_mem_nhds_within this) with ⟨u, u_open, xu, hu⟩, refine ⟨u ∩ (chart_at H x).source, _, ⟨xu, mem_chart_source _ _⟩, _, _⟩, { exact is_open.inter u_open (local_homeomorph.open_source _) }, { assume y hy, exact hy.2 }, { assume y hy, exact hu ⟨hy.1.1, hy.2⟩ } }, have h' : cont_mdiff_within_at I I' n f (s ∩ o) x := h.mono (inter_subset_left _ _), simp only [cont_mdiff_within_at, lift_prop_within_at, cont_diff_within_at_prop] at h', -- let `u` be a good neighborhood in the chart where the function is smooth rcases h.2.cont_diff_on le_rfl with ⟨u, u_nhds, u_subset, hu⟩, -- pull it back to the manifold, and intersect with a suitable neighborhood of `x`, to get the -- desired good neighborhood `v`. let v := ((insert x s) ∩ o) ∩ (ext_chart_at I x) ⁻¹' u, have v_incl : v ⊆ (chart_at H x).source := λ y hy, ho hy.1.2, have v_incl' : ∀ y ∈ v, f y ∈ (chart_at H' (f x)).source, { assume y hy, rcases hy.1.1 with rfl|h', { simp only with mfld_simps }, { apply h'o ⟨hy.1.2, h'⟩ } }, refine ⟨v, _, _⟩, show v ∈ 𝓝[insert x s] x, { rw nhds_within_restrict _ xo o_open, refine filter.inter_mem self_mem_nhds_within _, suffices : u ∈ 𝓝[(ext_chart_at I x) '' (insert x s ∩ o)] (ext_chart_at I x x), from (ext_chart_at_continuous_at I x).continuous_within_at.preimage_mem_nhds_within' this, apply nhds_within_mono _ _ u_nhds, rw image_subset_iff, assume y hy, rcases hy.1 with rfl|h', { simp only [mem_insert_iff] with mfld_simps }, { simp only [mem_insert_iff, ho hy.2, h', h'o ⟨hy.2, h'⟩] with mfld_simps } }, show cont_mdiff_on I I' n f v, { assume y hy, have : continuous_within_at f v y, { apply (((ext_chart_at_continuous_on_symm I' (f x) _ _).comp' (hu _ hy.2).continuous_within_at).comp' (ext_chart_at_continuous_on I x _ _)).congr_mono, { assume z hz, simp only [v_incl hz, v_incl' z hz] with mfld_simps }, { assume z hz, simp only [v_incl hz, v_incl' z hz] with mfld_simps, exact hz.2 }, { simp only [v_incl hy, v_incl' y hy] with mfld_simps }, { simp only [v_incl hy, v_incl' y hy] with mfld_simps }, { simp only [v_incl hy] with mfld_simps } }, refine (cont_mdiff_within_at_iff_of_mem_source' (v_incl hy) (v_incl' y hy)).mpr ⟨this, _⟩, { apply hu.mono, { assume z hz, simp only [v] with mfld_simps at hz, have : I ((chart_at H x) (((chart_at H x).symm) (I.symm z))) ∈ u, by simp only [hz], simpa only [hz] with mfld_simps using this }, { have exty : I (chart_at H x y) ∈ u := hy.2, simp only [v_incl hy, v_incl' y hy, exty, hy.1.1, hy.1.2] with mfld_simps } } } }, { rintros ⟨u, u_nhds, hu⟩, have : cont_mdiff_within_at I I' ↑n f (insert x s ∩ u) x, { have : x ∈ insert x s := mem_insert x s, exact hu.mono (inter_subset_right _ _) _ ⟨this, mem_of_mem_nhds_within this u_nhds⟩ }, rw cont_mdiff_within_at_inter' u_nhds at this, exact this.mono (subset_insert x s) } end /-- A function is `C^n` at a point, for `n : ℕ`, if and only if it is `C^n` on a neighborhood of this point. -/ lemma cont_mdiff_at_iff_cont_mdiff_on_nhds {n : ℕ} : cont_mdiff_at I I' n f x ↔ ∃ u ∈ 𝓝 x, cont_mdiff_on I I' n f u := by simp [← cont_mdiff_within_at_univ, cont_mdiff_within_at_iff_cont_mdiff_on_nhds, nhds_within_univ] omit Is I's /-! ### Congruence lemmas -/ lemma cont_mdiff_within_at.congr (h : cont_mdiff_within_at I I' n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : cont_mdiff_within_at I I' n f₁ s x := (cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_congr h h₁ hx lemma cont_mdiff_within_at_congr (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : cont_mdiff_within_at I I' n f₁ s x ↔ cont_mdiff_within_at I I' n f s x := (cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_congr_iff h₁ hx lemma cont_mdiff_within_at.congr_of_eventually_eq (h : cont_mdiff_within_at I I' n f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : cont_mdiff_within_at I I' n f₁ s x := (cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_congr_of_eventually_eq h h₁ hx lemma filter.eventually_eq.cont_mdiff_within_at_iff (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : cont_mdiff_within_at I I' n f₁ s x ↔ cont_mdiff_within_at I I' n f s x := (cont_diff_within_at_local_invariant_prop I I' n) .lift_prop_within_at_congr_iff_of_eventually_eq h₁ hx lemma cont_mdiff_at.congr_of_eventually_eq (h : cont_mdiff_at I I' n f x) (h₁ : f₁ =ᶠ[𝓝 x] f) : cont_mdiff_at I I' n f₁ x := (cont_diff_within_at_local_invariant_prop I I' n).lift_prop_at_congr_of_eventually_eq h h₁ lemma filter.eventually_eq.cont_mdiff_at_iff (h₁ : f₁ =ᶠ[𝓝 x] f) : cont_mdiff_at I I' n f₁ x ↔ cont_mdiff_at I I' n f x := (cont_diff_within_at_local_invariant_prop I I' n).lift_prop_at_congr_iff_of_eventually_eq h₁ lemma cont_mdiff_on.congr (h : cont_mdiff_on I I' n f s) (h₁ : ∀ y ∈ s, f₁ y = f y) : cont_mdiff_on I I' n f₁ s := (cont_diff_within_at_local_invariant_prop I I' n).lift_prop_on_congr h h₁ lemma cont_mdiff_on_congr (h₁ : ∀ y ∈ s, f₁ y = f y) : cont_mdiff_on I I' n f₁ s ↔ cont_mdiff_on I I' n f s := (cont_diff_within_at_local_invariant_prop I I' n).lift_prop_on_congr_iff h₁ /-! ### Locality -/ /-- Being `C^n` is a local property. -/ lemma cont_mdiff_on_of_locally_cont_mdiff_on (h : ∀x∈s, ∃u, is_open u ∧ x ∈ u ∧ cont_mdiff_on I I' n f (s ∩ u)) : cont_mdiff_on I I' n f s := (cont_diff_within_at_local_invariant_prop I I' n).lift_prop_on_of_locally_lift_prop_on h lemma cont_mdiff_of_locally_cont_mdiff_on (h : ∀x, ∃u, is_open u ∧ x ∈ u ∧ cont_mdiff_on I I' n f u) : cont_mdiff I I' n f := (cont_diff_within_at_local_invariant_prop I I' n).lift_prop_of_locally_lift_prop_on h /-! ### Smoothness of the composition of smooth functions between manifolds -/ section composition variables {E'' : Type*} [normed_group E''] [normed_space 𝕜 E''] {H'' : Type*} [topological_space H''] {I'' : model_with_corners 𝕜 E'' H''} {M'' : Type*} [topological_space M''] [charted_space H'' M''] /-- The composition of `C^n` functions within domains at points is `C^n`. -/ lemma cont_mdiff_within_at.comp {t : set M'} {g : M' → M''} (x : M) (hg : cont_mdiff_within_at I' I'' n g t (f x)) (hf : cont_mdiff_within_at I I' n f s x) (st : maps_to f s t) : cont_mdiff_within_at I I'' n (g ∘ f) s x := begin rw cont_mdiff_within_at_iff at hg hf ⊢, refine ⟨hg.1.comp hf.1 st, _⟩, set e := ext_chart_at I x, set e' := ext_chart_at I' (f x), set e'' := ext_chart_at I'' (g (f x)), have : e' (f x) = (written_in_ext_chart_at I I' x f) (e x), by simp only [e, e'] with mfld_simps, rw this at hg, have A : ∀ᶠ y in 𝓝[e.symm ⁻¹' s ∩ range I] e x, y ∈ e.target ∧ f (e.symm y) ∈ t ∧ f (e.symm y) ∈ e'.source ∧ g (f (e.symm y)) ∈ e''.source, { simp only [← ext_chart_at_map_nhds_within, eventually_map], filter_upwards [hf.1.tendsto (ext_chart_at_source_mem_nhds I' (f x)), (hg.1.comp hf.1 st).tendsto (ext_chart_at_source_mem_nhds I'' (g (f x))), (inter_mem_nhds_within s (ext_chart_at_source_mem_nhds I x))], rintros x' (hfx' : f x' ∈ _) (hgfx' : g (f x') ∈ _) ⟨hx's, hx'⟩, simp only [e.map_source hx', true_and, e.left_inv hx', st hx's, *] }, refine ((hg.2.comp _ (hf.2.mono (inter_subset_right _ _)) (inter_subset_left _ _)).mono_of_mem (inter_mem _ self_mem_nhds_within)).congr_of_eventually_eq _ _, { filter_upwards [A], rintro x' ⟨hx', ht, hfx', hgfx'⟩, simp only [*, mem_preimage, written_in_ext_chart_at, (∘), mem_inter_eq, e'.left_inv, true_and], exact mem_range_self _ }, { filter_upwards [A], rintro x' ⟨hx', ht, hfx', hgfx'⟩, simp only [*, (∘), written_in_ext_chart_at, e'.left_inv] }, { simp only [written_in_ext_chart_at, (∘), mem_ext_chart_source, e.left_inv, e'.left_inv] } end /-- The composition of `C^n` functions on domains is `C^n`. -/ lemma cont_mdiff_on.comp {t : set M'} {g : M' → M''} (hg : cont_mdiff_on I' I'' n g t) (hf : cont_mdiff_on I I' n f s) (st : s ⊆ f ⁻¹' t) : cont_mdiff_on I I'' n (g ∘ f) s := λ x hx, (hg _ (st hx)).comp x (hf x hx) st /-- The composition of `C^n` functions on domains is `C^n`. -/ lemma cont_mdiff_on.comp' {t : set M'} {g : M' → M''} (hg : cont_mdiff_on I' I'' n g t) (hf : cont_mdiff_on I I' n f s) : cont_mdiff_on I I'' n (g ∘ f) (s ∩ f ⁻¹' t) := hg.comp (hf.mono (inter_subset_left _ _)) (inter_subset_right _ _) /-- The composition of `C^n` functions is `C^n`. -/ lemma cont_mdiff.comp {g : M' → M''} (hg : cont_mdiff I' I'' n g) (hf : cont_mdiff I I' n f) : cont_mdiff I I'' n (g ∘ f) := begin rw ← cont_mdiff_on_univ at hf hg ⊢, exact hg.comp hf subset_preimage_univ, end /-- The composition of `C^n` functions within domains at points is `C^n`. -/ lemma cont_mdiff_within_at.comp' {t : set M'} {g : M' → M''} (x : M) (hg : cont_mdiff_within_at I' I'' n g t (f x)) (hf : cont_mdiff_within_at I I' n f s x) : cont_mdiff_within_at I I'' n (g ∘ f) (s ∩ f⁻¹' t) x := hg.comp x (hf.mono (inter_subset_left _ _)) (inter_subset_right _ _) /-- `g ∘ f` is `C^n` within `s` at `x` if `g` is `C^n` at `f x` and `f` is `C^n` within `s` at `x`. -/ lemma cont_mdiff_at.comp_cont_mdiff_within_at {g : M' → M''} (x : M) (hg : cont_mdiff_at I' I'' n g (f x)) (hf : cont_mdiff_within_at I I' n f s x) : cont_mdiff_within_at I I'' n (g ∘ f) s x := hg.comp x hf (maps_to_univ _ _) /-- The composition of `C^n` functions at points is `C^n`. -/ lemma cont_mdiff_at.comp {g : M' → M''} (x : M) (hg : cont_mdiff_at I' I'' n g (f x)) (hf : cont_mdiff_at I I' n f x) : cont_mdiff_at I I'' n (g ∘ f) x := hg.comp x hf (maps_to_univ _ _) lemma cont_mdiff.comp_cont_mdiff_on {f : M → M'} {g : M' → M''} {s : set M} (hg : cont_mdiff I' I'' n g) (hf : cont_mdiff_on I I' n f s) : cont_mdiff_on I I'' n (g ∘ f) s := hg.cont_mdiff_on.comp hf set.subset_preimage_univ lemma smooth.comp_smooth_on {f : M → M'} {g : M' → M''} {s : set M} (hg : smooth I' I'' g) (hf : smooth_on I I' f s) : smooth_on I I'' (g ∘ f) s := hg.smooth_on.comp hf set.subset_preimage_univ lemma cont_mdiff_on.comp_cont_mdiff {t : set M'} {g : M' → M''} (hg : cont_mdiff_on I' I'' n g t) (hf : cont_mdiff I I' n f) (ht : ∀ x, f x ∈ t) : cont_mdiff I I'' n (g ∘ f) := cont_mdiff_on_univ.mp $ hg.comp hf.cont_mdiff_on (λ x _, ht x) lemma smooth_on.comp_smooth {t : set M'} {g : M' → M''} (hg : smooth_on I' I'' g t) (hf : smooth I I' f) (ht : ∀ x, f x ∈ t) : smooth I I'' (g ∘ f) := hg.comp_cont_mdiff hf ht end composition /-! ### Atlas members are smooth -/ section atlas variables {e : local_homeomorph M H} include Is /-- An atlas member is `C^n` for any `n`. -/ lemma cont_mdiff_on_of_mem_maximal_atlas (h : e ∈ maximal_atlas I M) : cont_mdiff_on I I n e e.source := cont_mdiff_on.of_le ((cont_diff_within_at_local_invariant_prop I I ∞).lift_prop_on_of_mem_maximal_atlas (cont_diff_within_at_prop_id I) h) le_top /-- The inverse of an atlas member is `C^n` for any `n`. -/ lemma cont_mdiff_on_symm_of_mem_maximal_atlas (h : e ∈ maximal_atlas I M) : cont_mdiff_on I I n e.symm e.target := cont_mdiff_on.of_le ((cont_diff_within_at_local_invariant_prop I I ∞).lift_prop_on_symm_of_mem_maximal_atlas (cont_diff_within_at_prop_id I) h) le_top lemma cont_mdiff_on_chart : cont_mdiff_on I I n (chart_at H x) (chart_at H x).source := cont_mdiff_on_of_mem_maximal_atlas ((cont_diff_groupoid ⊤ I).chart_mem_maximal_atlas x) lemma cont_mdiff_on_chart_symm : cont_mdiff_on I I n (chart_at H x).symm (chart_at H x).target := cont_mdiff_on_symm_of_mem_maximal_atlas ((cont_diff_groupoid ⊤ I).chart_mem_maximal_atlas x) end atlas /-! ### The identity is smooth -/ section id lemma cont_mdiff_id : cont_mdiff I I n (id : M → M) := cont_mdiff.of_le ((cont_diff_within_at_local_invariant_prop I I ∞).lift_prop_id (cont_diff_within_at_prop_id I)) le_top lemma smooth_id : smooth I I (id : M → M) := cont_mdiff_id lemma cont_mdiff_on_id : cont_mdiff_on I I n (id : M → M) s := cont_mdiff_id.cont_mdiff_on lemma smooth_on_id : smooth_on I I (id : M → M) s := cont_mdiff_on_id lemma cont_mdiff_at_id : cont_mdiff_at I I n (id : M → M) x := cont_mdiff_id.cont_mdiff_at lemma smooth_at_id : smooth_at I I (id : M → M) x := cont_mdiff_at_id lemma cont_mdiff_within_at_id : cont_mdiff_within_at I I n (id : M → M) s x := cont_mdiff_at_id.cont_mdiff_within_at lemma smooth_within_at_id : smooth_within_at I I (id : M → M) s x := cont_mdiff_within_at_id end id /-! ### Constants are smooth -/ section id variable {c : M'} lemma cont_mdiff_const : cont_mdiff I I' n (λ (x : M), c) := begin assume x, refine ⟨continuous_within_at_const, _⟩, simp only [cont_diff_within_at_prop, (∘)], exact cont_diff_within_at_const, end @[to_additive] lemma cont_mdiff_one [has_one M'] : cont_mdiff I I' n (1 : M → M') := by simp only [pi.one_def, cont_mdiff_const] lemma smooth_const : smooth I I' (λ (x : M), c) := cont_mdiff_const @[to_additive] lemma smooth_one [has_one M'] : smooth I I' (1 : M → M') := by simp only [pi.one_def, smooth_const] lemma cont_mdiff_on_const : cont_mdiff_on I I' n (λ (x : M), c) s := cont_mdiff_const.cont_mdiff_on @[to_additive] lemma cont_mdiff_on_one [has_one M'] : cont_mdiff_on I I' n (1 : M → M') s := cont_mdiff_one.cont_mdiff_on lemma smooth_on_const : smooth_on I I' (λ (x : M), c) s := cont_mdiff_on_const @[to_additive] lemma smooth_on_one [has_one M'] : smooth_on I I' (1 : M → M') s := cont_mdiff_on_one lemma cont_mdiff_at_const : cont_mdiff_at I I' n (λ (x : M), c) x := cont_mdiff_const.cont_mdiff_at @[to_additive] lemma cont_mdiff_at_one [has_one M'] : cont_mdiff_at I I' n (1 : M → M') x := cont_mdiff_one.cont_mdiff_at lemma smooth_at_const : smooth_at I I' (λ (x : M), c) x := cont_mdiff_at_const @[to_additive] lemma smooth_at_one [has_one M'] : smooth_at I I' (1 : M → M') x := cont_mdiff_at_one lemma cont_mdiff_within_at_const : cont_mdiff_within_at I I' n (λ (x : M), c) s x := cont_mdiff_at_const.cont_mdiff_within_at @[to_additive] lemma cont_mdiff_within_at_one [has_one M'] : cont_mdiff_within_at I I' n (1 : M → M') s x := cont_mdiff_at_const.cont_mdiff_within_at lemma smooth_within_at_const : smooth_within_at I I' (λ (x : M), c) s x := cont_mdiff_within_at_const @[to_additive] lemma smooth_within_at_one [has_one M'] : smooth_within_at I I' (1 : M → M') s x := cont_mdiff_within_at_one end id lemma cont_mdiff_of_support {f : M → F} (hf : ∀ x ∈ tsupport f, cont_mdiff_at I 𝓘(𝕜, F) n f x) : cont_mdiff I 𝓘(𝕜, F) n f := begin intro x, by_cases hx : x ∈ tsupport f, { exact hf x hx }, { refine cont_mdiff_at.congr_of_eventually_eq _ (eventually_eq_zero_nhds.2 hx), exact cont_mdiff_at_const } end /-! ### Equivalence with the basic definition for functions between vector spaces -/ section module lemma cont_mdiff_within_at_iff_cont_diff_within_at {f : E → E'} {s : set E} {x : E} : cont_mdiff_within_at 𝓘(𝕜, E) 𝓘(𝕜, E') n f s x ↔ cont_diff_within_at 𝕜 n f s x := begin simp only [cont_mdiff_within_at, lift_prop_within_at, cont_diff_within_at_prop, iff_def] with mfld_simps {contextual := tt}, exact cont_diff_within_at.continuous_within_at end alias cont_mdiff_within_at_iff_cont_diff_within_at ↔ cont_mdiff_within_at.cont_diff_within_at cont_diff_within_at.cont_mdiff_within_at lemma cont_mdiff_at_iff_cont_diff_at {f : E → E'} {x : E} : cont_mdiff_at 𝓘(𝕜, E) 𝓘(𝕜, E') n f x ↔ cont_diff_at 𝕜 n f x := by rw [← cont_mdiff_within_at_univ, cont_mdiff_within_at_iff_cont_diff_within_at, cont_diff_within_at_univ] alias cont_mdiff_at_iff_cont_diff_at ↔ cont_mdiff_at.cont_diff_at cont_diff_at.cont_mdiff_at lemma cont_mdiff_on_iff_cont_diff_on {f : E → E'} {s : set E} : cont_mdiff_on 𝓘(𝕜, E) 𝓘(𝕜, E') n f s ↔ cont_diff_on 𝕜 n f s := forall_congr $ by simp [cont_mdiff_within_at_iff_cont_diff_within_at] alias cont_mdiff_on_iff_cont_diff_on ↔ cont_mdiff_on.cont_diff_on cont_diff_on.cont_mdiff_on lemma cont_mdiff_iff_cont_diff {f : E → E'} : cont_mdiff 𝓘(𝕜, E) 𝓘(𝕜, E') n f ↔ cont_diff 𝕜 n f := by rw [← cont_diff_on_univ, ← cont_mdiff_on_univ, cont_mdiff_on_iff_cont_diff_on] alias cont_mdiff_iff_cont_diff ↔ cont_mdiff.cont_diff cont_diff.cont_mdiff end module /-! ### The tangent map of a smooth function is smooth -/ section tangent_map /-- If a function is `C^n` with `1 ≤ n` on a domain with unique derivatives, then its bundled derivative is continuous. In this auxiliary lemma, we prove this fact when the source and target space are model spaces in models with corners. The general fact is proved in `cont_mdiff_on.continuous_on_tangent_map_within`-/ lemma cont_mdiff_on.continuous_on_tangent_map_within_aux {f : H → H'} {s : set H} (hf : cont_mdiff_on I I' n f s) (hn : 1 ≤ n) (hs : unique_mdiff_on I s) : continuous_on (tangent_map_within I I' f s) ((tangent_bundle.proj I H) ⁻¹' s) := begin suffices h : continuous_on (λ (p : H × E), (f p.fst, (fderiv_within 𝕜 (written_in_ext_chart_at I I' p.fst f) (I.symm ⁻¹' s ∩ range I) ((ext_chart_at I p.fst) p.fst) : E →L[𝕜] E') p.snd)) (prod.fst ⁻¹' s), { have A := (tangent_bundle_model_space_homeomorph H I).continuous, rw continuous_iff_continuous_on_univ at A, have B := ((tangent_bundle_model_space_homeomorph H' I').symm.continuous.comp_continuous_on h) .comp' A, have : (univ ∩ ⇑(tangent_bundle_model_space_homeomorph H I) ⁻¹' (prod.fst ⁻¹' s)) = tangent_bundle.proj I H ⁻¹' s, by { ext ⟨x, v⟩, simp only with mfld_simps }, rw this at B, apply B.congr, rintros ⟨x, v⟩ hx, dsimp [tangent_map_within], ext, { refl }, simp only with mfld_simps, apply congr_fun, apply congr_arg, rw mdifferentiable_within_at.mfderiv_within (hf.mdifferentiable_on hn x hx), refl }, suffices h : continuous_on (λ (p : H × E), (fderiv_within 𝕜 (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) (I p.fst) : E →L[𝕜] E') p.snd) (prod.fst ⁻¹' s), { dsimp [written_in_ext_chart_at, ext_chart_at], apply continuous_on.prod (continuous_on.comp hf.continuous_on continuous_fst.continuous_on (subset.refl _)), apply h.congr, assume p hp, refl }, suffices h : continuous_on (fderiv_within 𝕜 (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I)) (I '' s), { have C := continuous_on.comp h I.continuous_to_fun.continuous_on (subset.refl _), have A : continuous (λq : (E →L[𝕜] E') × E, q.1 q.2) := is_bounded_bilinear_map_apply.continuous, have B : continuous_on (λp : H × E, (fderiv_within 𝕜 (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) (I p.1), p.2)) (prod.fst ⁻¹' s), { apply continuous_on.prod _ continuous_snd.continuous_on, refine (continuous_on.comp C continuous_fst.continuous_on _ : _), exact preimage_mono (subset_preimage_image _ _) }, exact A.comp_continuous_on B }, rw cont_mdiff_on_iff at hf, let x : H := I.symm (0 : E), let y : H' := I'.symm (0 : E'), have A := hf.2 x y, simp only [I.image_eq, inter_comm] with mfld_simps at A ⊢, apply A.continuous_on_fderiv_within _ hn, convert hs.unique_diff_on_target_inter x using 1, simp only [inter_comm] with mfld_simps end /-- If a function is `C^n` on a domain with unique derivatives, then its bundled derivative is `C^m` when `m+1 ≤ n`. In this auxiliary lemma, we prove this fact when the source and target space are model spaces in models with corners. The general fact is proved in `cont_mdiff_on.cont_mdiff_on_tangent_map_within` -/ lemma cont_mdiff_on.cont_mdiff_on_tangent_map_within_aux {f : H → H'} {s : set H} (hf : cont_mdiff_on I I' n f s) (hmn : m + 1 ≤ n) (hs : unique_mdiff_on I s) : cont_mdiff_on I.tangent I'.tangent m (tangent_map_within I I' f s) ((tangent_bundle.proj I H) ⁻¹' s) := begin have m_le_n : m ≤ n, { apply le_trans _ hmn, have : m + 0 ≤ m + 1 := add_le_add_left (zero_le _) _, simpa only [add_zero] using this }, have one_le_n : 1 ≤ n, { apply le_trans _ hmn, change 0 + 1 ≤ m + 1, exact add_le_add_right (zero_le _) _ }, have U': unique_diff_on 𝕜 (range I ∩ I.symm ⁻¹' s), { assume y hy, simpa only [unique_mdiff_on, unique_mdiff_within_at, hy.1, inter_comm] with mfld_simps using hs (I.symm y) hy.2 }, have U : unique_diff_on 𝕜 ((range I ∩ I.symm ⁻¹' s) ×ˢ (univ : set E)) := U'.prod unique_diff_on_univ, rw cont_mdiff_on_iff, refine ⟨hf.continuous_on_tangent_map_within_aux one_le_n hs, λp q, _⟩, have A : range I ×ˢ (univ : set E) ∩ ((equiv.sigma_equiv_prod H E).symm ∘ λ (p : E × E), ((I.symm) p.fst, p.snd)) ⁻¹' (tangent_bundle.proj I H ⁻¹' s) = (range I ∩ I.symm ⁻¹' s) ×ˢ (univ : set E), by { ext ⟨x, v⟩, simp only with mfld_simps }, suffices h : cont_diff_on 𝕜 m (((λ (p : H' × E'), (I' p.fst, p.snd)) ∘ (equiv.sigma_equiv_prod H' E')) ∘ tangent_map_within I I' f s ∘ ((equiv.sigma_equiv_prod H E).symm) ∘ λ (p : E × E), (I.symm p.fst, p.snd)) ((range ⇑I ∩ ⇑(I.symm) ⁻¹' s) ×ˢ (univ : set E)), by simpa [A] using h, change cont_diff_on 𝕜 m (λ (p : E × E), ((I' (f (I.symm p.fst)), ((mfderiv_within I I' f s (I.symm p.fst)) : E → E') p.snd) : E' × E')) ((range I ∩ I.symm ⁻¹' s) ×ˢ (univ : set E)), -- check that all bits in this formula are `C^n` have hf' := cont_mdiff_on_iff.1 hf, have A : cont_diff_on 𝕜 m (I' ∘ f ∘ I.symm) (range I ∩ I.symm ⁻¹' s) := by simpa only with mfld_simps using (hf'.2 (I.symm 0) (I'.symm 0)).of_le m_le_n, have B : cont_diff_on 𝕜 m ((I' ∘ f ∘ I.symm) ∘ prod.fst) ((range I ∩ I.symm ⁻¹' s) ×ˢ (univ : set E)) := A.comp (cont_diff_fst.cont_diff_on) (prod_subset_preimage_fst _ _), suffices C : cont_diff_on 𝕜 m (λ (p : E × E), ((fderiv_within 𝕜 (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) p.1 : _) p.2)) ((range I ∩ I.symm ⁻¹' s) ×ˢ (univ : set E)), { apply cont_diff_on.prod B _, apply C.congr (λp hp, _), simp only with mfld_simps at hp, simp only [mfderiv_within, hf.mdifferentiable_on one_le_n _ hp.2, hp.1, dif_pos] with mfld_simps }, have D : cont_diff_on 𝕜 m (λ x, (fderiv_within 𝕜 (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) x)) (range I ∩ I.symm ⁻¹' s), { have : cont_diff_on 𝕜 n (I' ∘ f ∘ I.symm) (range I ∩ I.symm ⁻¹' s) := by simpa only with mfld_simps using (hf'.2 (I.symm 0) (I'.symm 0)), simpa only [inter_comm] using this.fderiv_within U' hmn }, have := D.comp (cont_diff_fst.cont_diff_on) (prod_subset_preimage_fst _ _), have := cont_diff_on.prod this (cont_diff_snd.cont_diff_on), exact is_bounded_bilinear_map_apply.cont_diff.comp_cont_diff_on this, end include Is I's /-- If a function is `C^n` on a domain with unique derivatives, then its bundled derivative is `C^m` when `m+1 ≤ n`. -/ theorem cont_mdiff_on.cont_mdiff_on_tangent_map_within (hf : cont_mdiff_on I I' n f s) (hmn : m + 1 ≤ n) (hs : unique_mdiff_on I s) : cont_mdiff_on I.tangent I'.tangent m (tangent_map_within I I' f s) ((tangent_bundle.proj I M) ⁻¹' s) := begin /- The strategy of the proof is to avoid unfolding the definitions, and reduce by functoriality to the case of functions on the model spaces, where we have already proved the result. Let `l` and `r` be the charts to the left and to the right, so that we have ``` l^{-1} f r H --------> M ---> M' ---> H' ``` Then the tangent map `T(r ∘ f ∘ l)` is smooth by a previous result. Consider the composition ``` Tl T(r ∘ f ∘ l^{-1}) Tr^{-1} TM -----> TH -------------------> TH' ---------> TM' ``` where `Tr^{-1}` and `Tl` are the tangent maps of `r^{-1}` and `l`. Writing `Tl` and `Tr^{-1}` as composition of charts (called `Dl` and `il` for `l` and `Dr` and `ir` in the proof below), it follows that they are smooth. The composition of all these maps is `Tf`, and is therefore smooth as a composition of smooth maps. -/ have m_le_n : m ≤ n, { apply le_trans _ hmn, have : m + 0 ≤ m + 1 := add_le_add_left (zero_le _) _, simpa only [add_zero] }, have one_le_n : 1 ≤ n, { apply le_trans _ hmn, change 0 + 1 ≤ m + 1, exact add_le_add_right (zero_le _) _ }, /- First step: local reduction on the space, to a set `s'` which is contained in chart domains. -/ refine cont_mdiff_on_of_locally_cont_mdiff_on (λp hp, _), have hf' := cont_mdiff_on_iff.1 hf, simp [tangent_bundle.proj] at hp, let l := chart_at H p.1, set Dl := chart_at (model_prod H E) p with hDl, let r := chart_at H' (f p.1), let Dr := chart_at (model_prod H' E') (tangent_map_within I I' f s p), let il := chart_at (model_prod H E) (tangent_map I I l p), let ir := chart_at (model_prod H' E') (tangent_map I I' (r ∘ f) p), let s' := f ⁻¹' r.source ∩ s ∩ l.source, let s'_lift := (tangent_bundle.proj I M)⁻¹' s', let s'l := l.target ∩ l.symm ⁻¹' s', let s'l_lift := (tangent_bundle.proj I H) ⁻¹' s'l, rcases continuous_on_iff'.1 hf'.1 r.source r.open_source with ⟨o, o_open, ho⟩, suffices h : cont_mdiff_on I.tangent I'.tangent m (tangent_map_within I I' f s) s'_lift, { refine ⟨(tangent_bundle.proj I M)⁻¹' (o ∩ l.source), _, _, _⟩, show is_open ((tangent_bundle.proj I M)⁻¹' (o ∩ l.source)), from (is_open.inter o_open l.open_source).preimage (tangent_bundle_proj_continuous _ _) , show p ∈ tangent_bundle.proj I M ⁻¹' (o ∩ l.source), { simp [tangent_bundle.proj] at ⊢, have : p.1 ∈ f ⁻¹' r.source ∩ s, by simp [hp], rw ho at this, exact this.1 }, { have : tangent_bundle.proj I M ⁻¹' s ∩ tangent_bundle.proj I M ⁻¹' (o ∩ l.source) = s'_lift, { dsimp only [s'_lift, s'], rw [ho], mfld_set_tac }, rw this, exact h } }, /- Second step: check that all functions are smooth, and use the chain rule to write the bundled derivative as a composition of a function between model spaces and of charts. Convention: statements about the differentiability of `a ∘ b ∘ c` are named `diff_abc`. Statements about differentiability in the bundle have a `_lift` suffix. -/ have U' : unique_mdiff_on I s', { apply unique_mdiff_on.inter _ l.open_source, rw [ho, inter_comm], exact hs.inter o_open }, have U'l : unique_mdiff_on I s'l := U'.unique_mdiff_on_preimage (mdifferentiable_chart _ _), have diff_f : cont_mdiff_on I I' n f s' := hf.mono (by mfld_set_tac), have diff_r : cont_mdiff_on I' I' n r r.source := cont_mdiff_on_chart, have diff_rf : cont_mdiff_on I I' n (r ∘ f) s', { apply cont_mdiff_on.comp diff_r diff_f (λx hx, _), simp only [s'] with mfld_simps at hx, simp only [hx] with mfld_simps }, have diff_l : cont_mdiff_on I I n l.symm s'l, { have A : cont_mdiff_on I I n l.symm l.target := cont_mdiff_on_chart_symm, exact A.mono (by mfld_set_tac) }, have diff_rfl : cont_mdiff_on I I' n (r ∘ f ∘ l.symm) s'l, { apply cont_mdiff_on.comp diff_rf diff_l, mfld_set_tac }, have diff_rfl_lift : cont_mdiff_on I.tangent I'.tangent m (tangent_map_within I I' (r ∘ f ∘ l.symm) s'l) s'l_lift := diff_rfl.cont_mdiff_on_tangent_map_within_aux hmn U'l, have diff_irrfl_lift : cont_mdiff_on I.tangent I'.tangent m (ir ∘ (tangent_map_within I I' (r ∘ f ∘ l.symm) s'l)) s'l_lift, { have A : cont_mdiff_on I'.tangent I'.tangent m ir ir.source := cont_mdiff_on_chart, exact cont_mdiff_on.comp A diff_rfl_lift (λp hp, by simp only [ir] with mfld_simps) }, have diff_Drirrfl_lift : cont_mdiff_on I.tangent I'.tangent m (Dr.symm ∘ (ir ∘ (tangent_map_within I I' (r ∘ f ∘ l.symm) s'l))) s'l_lift, { have A : cont_mdiff_on I'.tangent I'.tangent m Dr.symm Dr.target := cont_mdiff_on_chart_symm, apply cont_mdiff_on.comp A diff_irrfl_lift (λp hp, _), simp only [s'l_lift, tangent_bundle.proj] with mfld_simps at hp, simp only [ir, @local_equiv.refl_coe (model_prod H' E'), hp] with mfld_simps }, -- conclusion of this step: the composition of all the maps above is smooth have diff_DrirrflilDl : cont_mdiff_on I.tangent I'.tangent m (Dr.symm ∘ (ir ∘ (tangent_map_within I I' (r ∘ f ∘ l.symm) s'l)) ∘ (il.symm ∘ Dl)) s'_lift, { have A : cont_mdiff_on I.tangent I.tangent m Dl Dl.source := cont_mdiff_on_chart, have A' : cont_mdiff_on I.tangent I.tangent m Dl s'_lift, { apply A.mono (λp hp, _), simp only [s'_lift, tangent_bundle.proj] with mfld_simps at hp, simp only [Dl, hp] with mfld_simps }, have B : cont_mdiff_on I.tangent I.tangent m il.symm il.target := cont_mdiff_on_chart_symm, have C : cont_mdiff_on I.tangent I.tangent m (il.symm ∘ Dl) s'_lift := cont_mdiff_on.comp B A' (λp hp, by simp only [il] with mfld_simps), apply cont_mdiff_on.comp diff_Drirrfl_lift C (λp hp, _), simp only [s'_lift, tangent_bundle.proj] with mfld_simps at hp, simp only [il, s'l_lift, hp, tangent_bundle.proj] with mfld_simps }, /- Third step: check that the composition of all the maps indeed coincides with the derivative we are looking for -/ have eq_comp : ∀q ∈ s'_lift, tangent_map_within I I' f s q = (Dr.symm ∘ ir ∘ (tangent_map_within I I' (r ∘ f ∘ l.symm) s'l) ∘ (il.symm ∘ Dl)) q, { assume q hq, simp only [s'_lift, tangent_bundle.proj] with mfld_simps at hq, have U'q : unique_mdiff_within_at I s' q.1, by { apply U', simp only [hq, s'] with mfld_simps }, have U'lq : unique_mdiff_within_at I s'l (Dl q).1, by { apply U'l, simp only [hq, s'l] with mfld_simps }, have A : tangent_map_within I I' ((r ∘ f) ∘ l.symm) s'l (il.symm (Dl q)) = tangent_map_within I I' (r ∘ f) s' (tangent_map_within I I l.symm s'l (il.symm (Dl q))), { refine tangent_map_within_comp_at (il.symm (Dl q)) _ _ (λp hp, _) U'lq, { apply diff_rf.mdifferentiable_on one_le_n, simp only [hq] with mfld_simps }, { apply diff_l.mdifferentiable_on one_le_n, simp only [s'l, hq] with mfld_simps }, { simp only with mfld_simps at hp, simp only [hp] with mfld_simps } }, have B : tangent_map_within I I l.symm s'l (il.symm (Dl q)) = q, { have : tangent_map_within I I l.symm s'l (il.symm (Dl q)) = tangent_map I I l.symm (il.symm (Dl q)), { refine tangent_map_within_eq_tangent_map U'lq _, refine mdifferentiable_at_atlas_symm _ (chart_mem_atlas _ _) _, simp only [hq] with mfld_simps }, rw [this, tangent_map_chart_symm, hDl], { simp only [hq] with mfld_simps, have : q ∈ (chart_at (model_prod H E) p).source, by simp only [hq] with mfld_simps, exact (chart_at (model_prod H E) p).left_inv this }, { simp only [hq] with mfld_simps } }, have C : tangent_map_within I I' (r ∘ f) s' q = tangent_map_within I' I' r r.source (tangent_map_within I I' f s' q), { refine tangent_map_within_comp_at q _ _ (λr hr, _) U'q, { apply diff_r.mdifferentiable_on one_le_n, simp only [hq] with mfld_simps }, { apply diff_f.mdifferentiable_on one_le_n, simp only [hq] with mfld_simps }, { simp only [s'] with mfld_simps at hr, simp only [hr] with mfld_simps } }, have D : Dr.symm (ir (tangent_map_within I' I' r r.source (tangent_map_within I I' f s' q))) = tangent_map_within I I' f s' q, { have A : tangent_map_within I' I' r r.source (tangent_map_within I I' f s' q) = tangent_map I' I' r (tangent_map_within I I' f s' q), { apply tangent_map_within_eq_tangent_map, { apply is_open.unique_mdiff_within_at _ r.open_source, simp [hq] }, { refine mdifferentiable_at_atlas _ (chart_mem_atlas _ _) _, simp only [hq] with mfld_simps } }, have : f p.1 = (tangent_map_within I I' f s p).1 := rfl, rw [A], dsimp [r, Dr], rw [this, tangent_map_chart], { simp only [hq] with mfld_simps, have : tangent_map_within I I' f s' q ∈ (chart_at (model_prod H' E') (tangent_map_within I I' f s p)).source, by simp only [hq] with mfld_simps, exact (chart_at (model_prod H' E') (tangent_map_within I I' f s p)).left_inv this }, { simp only [hq] with mfld_simps } }, have E : tangent_map_within I I' f s' q = tangent_map_within I I' f s q, { refine tangent_map_within_subset (by mfld_set_tac) U'q _, apply hf.mdifferentiable_on one_le_n, simp only [hq] with mfld_simps }, simp only [(∘), A, B, C, D, E.symm] }, exact diff_DrirrflilDl.congr eq_comp, end /-- If a function is `C^n` on a domain with unique derivatives, with `1 ≤ n`, then its bundled derivative is continuous there. -/ theorem cont_mdiff_on.continuous_on_tangent_map_within (hf : cont_mdiff_on I I' n f s) (hmn : 1 ≤ n) (hs : unique_mdiff_on I s) : continuous_on (tangent_map_within I I' f s) ((tangent_bundle.proj I M) ⁻¹' s) := begin have : cont_mdiff_on I.tangent I'.tangent 0 (tangent_map_within I I' f s) ((tangent_bundle.proj I M) ⁻¹' s) := hf.cont_mdiff_on_tangent_map_within hmn hs, exact this.continuous_on end /-- If a function is `C^n`, then its bundled derivative is `C^m` when `m+1 ≤ n`. -/ theorem cont_mdiff.cont_mdiff_tangent_map (hf : cont_mdiff I I' n f) (hmn : m + 1 ≤ n) : cont_mdiff I.tangent I'.tangent m (tangent_map I I' f) := begin rw ← cont_mdiff_on_univ at hf ⊢, convert hf.cont_mdiff_on_tangent_map_within hmn unique_mdiff_on_univ, rw tangent_map_within_univ end /-- If a function is `C^n`, with `1 ≤ n`, then its bundled derivative is continuous. -/ theorem cont_mdiff.continuous_tangent_map (hf : cont_mdiff I I' n f) (hmn : 1 ≤ n) : continuous (tangent_map I I' f) := begin rw ← cont_mdiff_on_univ at hf, rw continuous_iff_continuous_on_univ, convert hf.continuous_on_tangent_map_within hmn unique_mdiff_on_univ, rw tangent_map_within_univ end end tangent_map /-! ### Smoothness of the projection in a basic smooth bundle -/ namespace basic_smooth_vector_bundle_core variables (Z : basic_smooth_vector_bundle_core I M E') lemma cont_mdiff_proj : cont_mdiff (I.prod 𝓘(𝕜, E')) I n Z.to_topological_vector_bundle_core.proj := begin assume x, rw [cont_mdiff_at, cont_mdiff_within_at_iff'], refine ⟨Z.to_topological_vector_bundle_core.continuous_proj.continuous_within_at, _⟩, simp only [(∘), chart_at, chart] with mfld_simps, apply cont_diff_within_at_fst.congr, { rintros ⟨a, b⟩ hab, simp only with mfld_simps at hab, simp only [hab] with mfld_simps }, { simp only with mfld_simps } end lemma smooth_proj : smooth (I.prod 𝓘(𝕜, E')) I Z.to_topological_vector_bundle_core.proj := cont_mdiff_proj Z lemma cont_mdiff_on_proj {s : set (Z.to_topological_vector_bundle_core.total_space)} : cont_mdiff_on (I.prod 𝓘(𝕜, E')) I n Z.to_topological_vector_bundle_core.proj s := Z.cont_mdiff_proj.cont_mdiff_on lemma smooth_on_proj {s : set (Z.to_topological_vector_bundle_core.total_space)} : smooth_on (I.prod 𝓘(𝕜, E')) I Z.to_topological_vector_bundle_core.proj s := cont_mdiff_on_proj Z lemma cont_mdiff_at_proj {p : Z.to_topological_vector_bundle_core.total_space} : cont_mdiff_at (I.prod 𝓘(𝕜, E')) I n Z.to_topological_vector_bundle_core.proj p := Z.cont_mdiff_proj.cont_mdiff_at lemma smooth_at_proj {p : Z.to_topological_vector_bundle_core.total_space} : smooth_at (I.prod 𝓘(𝕜, E')) I Z.to_topological_vector_bundle_core.proj p := Z.cont_mdiff_at_proj lemma cont_mdiff_within_at_proj {s : set (Z.to_topological_vector_bundle_core.total_space)} {p : Z.to_topological_vector_bundle_core.total_space} : cont_mdiff_within_at (I.prod 𝓘(𝕜, E')) I n Z.to_topological_vector_bundle_core.proj s p := Z.cont_mdiff_at_proj.cont_mdiff_within_at lemma smooth_within_at_proj {s : set (Z.to_topological_vector_bundle_core.total_space)} {p : Z.to_topological_vector_bundle_core.total_space} : smooth_within_at (I.prod 𝓘(𝕜, E')) I Z.to_topological_vector_bundle_core.proj s p := Z.cont_mdiff_within_at_proj /-- If an element of `E'` is invariant under all coordinate changes, then one can define a corresponding section of the fiber bundle, which is smooth. This applies in particular to the zero section of a vector bundle. Another example (not yet defined) would be the identity section of the endomorphism bundle of a vector bundle. -/ lemma smooth_const_section (v : E') (h : ∀ (i j : atlas H M), ∀ x ∈ i.1.source ∩ j.1.source, Z.coord_change i j (i.1 x) v = v) : smooth I (I.prod 𝓘(𝕜, E')) (show M → Z.to_topological_vector_bundle_core.total_space, from λ x, ⟨x, v⟩) := begin assume x, rw [cont_mdiff_at, cont_mdiff_within_at_iff'], split, { apply continuous.continuous_within_at, apply topological_fiber_bundle_core.continuous_const_section, assume i j y hy, exact h _ _ _ hy }, { have : cont_diff 𝕜 ⊤ (λ (y : E), (y, v)) := cont_diff_id.prod cont_diff_const, apply this.cont_diff_within_at.congr, { assume y hy, simp only with mfld_simps at hy, simp only [chart, hy, chart_at, prod.mk.inj_iff, to_topological_vector_bundle_core] with mfld_simps, apply h, simp only [hy, subtype.val_eq_coe] with mfld_simps, exact mem_chart_source H (((chart_at H x).symm) ((model_with_corners.symm I) y)) }, { simp only [chart, chart_at, prod.mk.inj_iff, to_topological_vector_bundle_core] with mfld_simps, apply h, simp only [subtype.val_eq_coe] with mfld_simps, exact mem_chart_source H x, } } end end basic_smooth_vector_bundle_core /-! ### Smoothness of the tangent bundle projection -/ namespace tangent_bundle include Is lemma cont_mdiff_proj : cont_mdiff I.tangent I n (proj I M) := basic_smooth_vector_bundle_core.cont_mdiff_proj _ lemma smooth_proj : smooth I.tangent I (proj I M) := basic_smooth_vector_bundle_core.smooth_proj _ lemma cont_mdiff_on_proj {s : set (tangent_bundle I M)} : cont_mdiff_on I.tangent I n (proj I M) s := basic_smooth_vector_bundle_core.cont_mdiff_on_proj _ lemma smooth_on_proj {s : set (tangent_bundle I M)} : smooth_on I.tangent I (proj I M) s := basic_smooth_vector_bundle_core.smooth_on_proj _ lemma cont_mdiff_at_proj {p : tangent_bundle I M} : cont_mdiff_at I.tangent I n (proj I M) p := basic_smooth_vector_bundle_core.cont_mdiff_at_proj _ lemma smooth_at_proj {p : tangent_bundle I M} : smooth_at I.tangent I (proj I M) p := basic_smooth_vector_bundle_core.smooth_at_proj _ lemma cont_mdiff_within_at_proj {s : set (tangent_bundle I M)} {p : tangent_bundle I M} : cont_mdiff_within_at I.tangent I n (proj I M) s p := basic_smooth_vector_bundle_core.cont_mdiff_within_at_proj _ lemma smooth_within_at_proj {s : set (tangent_bundle I M)} {p : tangent_bundle I M} : smooth_within_at I.tangent I (proj I M) s p := basic_smooth_vector_bundle_core.smooth_within_at_proj _ variables (I M) /-- The zero section of the tangent bundle -/ def zero_section : M → tangent_bundle I M := λ x, ⟨x, 0⟩ variables {I M} lemma smooth_zero_section : smooth I I.tangent (zero_section I M) := begin apply basic_smooth_vector_bundle_core.smooth_const_section (tangent_bundle_core I M) 0, assume i j x hx, simp only [tangent_bundle_core, continuous_linear_map.map_zero, continuous_linear_map.coe_coe] with mfld_simps, end open bundle /-- The derivative of the zero section of the tangent bundle maps `⟨x, v⟩` to `⟨⟨x, 0⟩, ⟨v, 0⟩⟩`. Note that, as currently framed, this is a statement in coordinates, thus reliant on the choice of the coordinate system we use on the tangent bundle. However, the result itself is coordinate-dependent only to the extent that the coordinates determine a splitting of the tangent bundle. Moreover, there is a canonical splitting at each point of the zero section (since there is a canonical horizontal space there, the tangent space to the zero section, in addition to the canonical vertical space which is the kernel of the derivative of the projection), and this canonical splitting is also the one that comes from the coordinates on the tangent bundle in our definitions. So this statement is not as crazy as it may seem. TODO define splittings of vector bundles; state this result invariantly. -/ lemma tangent_map_tangent_bundle_pure (p : tangent_bundle I M) : tangent_map I I.tangent (tangent_bundle.zero_section I M) p = ⟨⟨p.1, 0⟩, ⟨p.2, 0⟩⟩ := begin rcases p with ⟨x, v⟩, have N : I.symm ⁻¹' (chart_at H x).target ∈ 𝓝 (I ((chart_at H x) x)), { apply is_open.mem_nhds, apply (local_homeomorph.open_target _).preimage I.continuous_inv_fun, simp only with mfld_simps }, have A : mdifferentiable_at I I.tangent (λ x, @total_space_mk M (tangent_space I) x 0) x := tangent_bundle.smooth_zero_section.mdifferentiable_at, have B : fderiv_within 𝕜 (λ (x_1 : E), (x_1, (0 : E))) (set.range ⇑I) (I ((chart_at H x) x)) v = (v, 0), { rw [fderiv_within_eq_fderiv, differentiable_at.fderiv_prod], { simp }, { exact differentiable_at_id' }, { exact differentiable_at_const _ }, { exact model_with_corners.unique_diff_at_image I }, { exact differentiable_at_id'.prod (differentiable_at_const _) } }, simp only [tangent_bundle.zero_section, tangent_map, mfderiv, A, dif_pos, chart_at, basic_smooth_vector_bundle_core.chart, basic_smooth_vector_bundle_core.to_topological_vector_bundle_core, tangent_bundle_core, function.comp, continuous_linear_map.map_zero] with mfld_simps, rw ← fderiv_within_inter N (I.unique_diff (I ((chart_at H x) x)) (set.mem_range_self _)) at B, rw [← fderiv_within_inter N (I.unique_diff (I ((chart_at H x) x)) (set.mem_range_self _)), ← B], congr' 2, apply fderiv_within_congr _ (λ y hy, _), { simp only [prod.mk.inj_iff] with mfld_simps, exact ((tangent_bundle_core I M).to_topological_vector_bundle_core.coord_change ((tangent_bundle_core I M).to_topological_vector_bundle_core.index_at (((chart_at H x).symm) (I.symm (I ((chart_at H x) x))))) ⟨chart_at H x, _⟩ (((chart_at H x).symm) (I.symm (I ((chart_at H x) x))))).map_zero, }, { apply unique_diff_within_at.inter (I.unique_diff _ _) N, simp only with mfld_simps }, { simp only with mfld_simps at hy, simp only [hy, prod.mk.inj_iff] with mfld_simps, exact ((tangent_bundle_core I M).to_topological_vector_bundle_core.coord_change ((tangent_bundle_core I M).to_topological_vector_bundle_core.index_at (((chart_at H x).symm) (I.symm y))) ⟨chart_at H x, _⟩ (((chart_at H x).symm) (I.symm y))).map_zero, }, end end tangent_bundle /-! ### Smoothness of standard maps associated to the product of manifolds -/ section prod_mk lemma cont_mdiff_within_at.prod_mk {f : M → M'} {g : M → N'} (hf : cont_mdiff_within_at I I' n f s x) (hg : cont_mdiff_within_at I J' n g s x) : cont_mdiff_within_at I (I'.prod J') n (λ x, (f x, g x)) s x := begin rw cont_mdiff_within_at_iff at *, exact ⟨hf.1.prod hg.1, hf.2.prod hg.2⟩, end lemma cont_mdiff_within_at.prod_mk_space {f : M → E'} {g : M → F'} (hf : cont_mdiff_within_at I 𝓘(𝕜, E') n f s x) (hg : cont_mdiff_within_at I 𝓘(𝕜, F') n g s x) : cont_mdiff_within_at I 𝓘(𝕜, E' × F') n (λ x, (f x, g x)) s x := begin rw cont_mdiff_within_at_iff at *, exact ⟨hf.1.prod hg.1, hf.2.prod hg.2⟩, end lemma cont_mdiff_at.prod_mk {f : M → M'} {g : M → N'} (hf : cont_mdiff_at I I' n f x) (hg : cont_mdiff_at I J' n g x) : cont_mdiff_at I (I'.prod J') n (λ x, (f x, g x)) x := hf.prod_mk hg lemma cont_mdiff_at.prod_mk_space {f : M → E'} {g : M → F'} (hf : cont_mdiff_at I 𝓘(𝕜, E') n f x) (hg : cont_mdiff_at I 𝓘(𝕜, F') n g x) : cont_mdiff_at I 𝓘(𝕜, E' × F') n (λ x, (f x, g x)) x := hf.prod_mk_space hg lemma cont_mdiff_on.prod_mk {f : M → M'} {g : M → N'} (hf : cont_mdiff_on I I' n f s) (hg : cont_mdiff_on I J' n g s) : cont_mdiff_on I (I'.prod J') n (λ x, (f x, g x)) s := λ x hx, (hf x hx).prod_mk (hg x hx) lemma cont_mdiff_on.prod_mk_space {f : M → E'} {g : M → F'} (hf : cont_mdiff_on I 𝓘(𝕜, E') n f s) (hg : cont_mdiff_on I 𝓘(𝕜, F') n g s) : cont_mdiff_on I 𝓘(𝕜, E' × F') n (λ x, (f x, g x)) s := λ x hx, (hf x hx).prod_mk_space (hg x hx) lemma cont_mdiff.prod_mk {f : M → M'} {g : M → N'} (hf : cont_mdiff I I' n f) (hg : cont_mdiff I J' n g) : cont_mdiff I (I'.prod J') n (λ x, (f x, g x)) := λ x, (hf x).prod_mk (hg x) lemma cont_mdiff.prod_mk_space {f : M → E'} {g : M → F'} (hf : cont_mdiff I 𝓘(𝕜, E') n f) (hg : cont_mdiff I 𝓘(𝕜, F') n g) : cont_mdiff I 𝓘(𝕜, E' × F') n (λ x, (f x, g x)) := λ x, (hf x).prod_mk_space (hg x) lemma smooth_within_at.prod_mk {f : M → M'} {g : M → N'} (hf : smooth_within_at I I' f s x) (hg : smooth_within_at I J' g s x) : smooth_within_at I (I'.prod J') (λ x, (f x, g x)) s x := hf.prod_mk hg lemma smooth_within_at.prod_mk_space {f : M → E'} {g : M → F'} (hf : smooth_within_at I 𝓘(𝕜, E') f s x) (hg : smooth_within_at I 𝓘(𝕜, F') g s x) : smooth_within_at I 𝓘(𝕜, E' × F') (λ x, (f x, g x)) s x := hf.prod_mk_space hg lemma smooth_at.prod_mk {f : M → M'} {g : M → N'} (hf : smooth_at I I' f x) (hg : smooth_at I J' g x) : smooth_at I (I'.prod J') (λ x, (f x, g x)) x := hf.prod_mk hg lemma smooth_at.prod_mk_space {f : M → E'} {g : M → F'} (hf : smooth_at I 𝓘(𝕜, E') f x) (hg : smooth_at I 𝓘(𝕜, F') g x) : smooth_at I 𝓘(𝕜, E' × F') (λ x, (f x, g x)) x := hf.prod_mk_space hg lemma smooth_on.prod_mk {f : M → M'} {g : M → N'} (hf : smooth_on I I' f s) (hg : smooth_on I J' g s) : smooth_on I (I'.prod J') (λ x, (f x, g x)) s := hf.prod_mk hg lemma smooth_on.prod_mk_space {f : M → E'} {g : M → F'} (hf : smooth_on I 𝓘(𝕜, E') f s) (hg : smooth_on I 𝓘(𝕜, F') g s) : smooth_on I 𝓘(𝕜, E' × F') (λ x, (f x, g x)) s := hf.prod_mk_space hg lemma smooth.prod_mk {f : M → M'} {g : M → N'} (hf : smooth I I' f) (hg : smooth I J' g) : smooth I (I'.prod J') (λ x, (f x, g x)) := hf.prod_mk hg lemma smooth.prod_mk_space {f : M → E'} {g : M → F'} (hf : smooth I 𝓘(𝕜, E') f) (hg : smooth I 𝓘(𝕜, F') g) : smooth I 𝓘(𝕜, E' × F') (λ x, (f x, g x)) := hf.prod_mk_space hg end prod_mk section projections lemma cont_mdiff_within_at_fst {s : set (M × N)} {p : M × N} : cont_mdiff_within_at (I.prod J) I n prod.fst s p := begin rw cont_mdiff_within_at_iff', refine ⟨continuous_within_at_fst, _⟩, refine cont_diff_within_at_fst.congr (λ y hy, _) _, { simp only with mfld_simps at hy, simp only [hy] with mfld_simps }, { simp only with mfld_simps } end lemma cont_mdiff_at_fst {p : M × N} : cont_mdiff_at (I.prod J) I n prod.fst p := cont_mdiff_within_at_fst lemma cont_mdiff_on_fst {s : set (M × N)} : cont_mdiff_on (I.prod J) I n prod.fst s := λ x hx, cont_mdiff_within_at_fst lemma cont_mdiff_fst : cont_mdiff (I.prod J) I n (@prod.fst M N) := λ x, cont_mdiff_at_fst lemma smooth_within_at_fst {s : set (M × N)} {p : M × N} : smooth_within_at (I.prod J) I prod.fst s p := cont_mdiff_within_at_fst lemma smooth_at_fst {p : M × N} : smooth_at (I.prod J) I prod.fst p := cont_mdiff_at_fst lemma smooth_on_fst {s : set (M × N)} : smooth_on (I.prod J) I prod.fst s := cont_mdiff_on_fst lemma smooth_fst : smooth (I.prod J) I (@prod.fst M N) := cont_mdiff_fst lemma cont_mdiff_within_at_snd {s : set (M × N)} {p : M × N} : cont_mdiff_within_at (I.prod J) J n prod.snd s p := begin rw cont_mdiff_within_at_iff', refine ⟨continuous_within_at_snd, _⟩, refine cont_diff_within_at_snd.congr (λ y hy, _) _, { simp only with mfld_simps at hy, simp only [hy] with mfld_simps }, { simp only with mfld_simps } end lemma cont_mdiff_at_snd {p : M × N} : cont_mdiff_at (I.prod J) J n prod.snd p := cont_mdiff_within_at_snd lemma cont_mdiff_on_snd {s : set (M × N)} : cont_mdiff_on (I.prod J) J n prod.snd s := λ x hx, cont_mdiff_within_at_snd lemma cont_mdiff_snd : cont_mdiff (I.prod J) J n (@prod.snd M N) := λ x, cont_mdiff_at_snd lemma smooth_within_at_snd {s : set (M × N)} {p : M × N} : smooth_within_at (I.prod J) J prod.snd s p := cont_mdiff_within_at_snd lemma smooth_at_snd {p : M × N} : smooth_at (I.prod J) J prod.snd p := cont_mdiff_at_snd lemma smooth_on_snd {s : set (M × N)} : smooth_on (I.prod J) J prod.snd s := cont_mdiff_on_snd lemma smooth_snd : smooth (I.prod J) J (@prod.snd M N) := cont_mdiff_snd lemma smooth_iff_proj_smooth {f : M → M' × N'} : (smooth I (I'.prod J') f) ↔ (smooth I I' (prod.fst ∘ f)) ∧ (smooth I J' (prod.snd ∘ f)) := begin split, { intro h, exact ⟨smooth_fst.comp h, smooth_snd.comp h⟩ }, { rintro ⟨h_fst, h_snd⟩, simpa only [prod.mk.eta] using h_fst.prod_mk h_snd, } end end projections section prod_map variables {g : N → N'} {r : set N} {y : N} /-- The product map of two `C^n` functions within a set at a point is `C^n` within the product set at the product point. -/ lemma cont_mdiff_within_at.prod_map' {p : M × N} (hf : cont_mdiff_within_at I I' n f s p.1) (hg : cont_mdiff_within_at J J' n g r p.2) : cont_mdiff_within_at (I.prod J) (I'.prod J') n (prod.map f g) (s ×ˢ r) p := (hf.comp p cont_mdiff_within_at_fst (prod_subset_preimage_fst _ _)).prod_mk $ hg.comp p cont_mdiff_within_at_snd (prod_subset_preimage_snd _ _) lemma cont_mdiff_within_at.prod_map (hf : cont_mdiff_within_at I I' n f s x) (hg : cont_mdiff_within_at J J' n g r y) : cont_mdiff_within_at (I.prod J) (I'.prod J') n (prod.map f g) (s ×ˢ r) (x, y) := cont_mdiff_within_at.prod_map' hf hg lemma cont_mdiff_at.prod_map (hf : cont_mdiff_at I I' n f x) (hg : cont_mdiff_at J J' n g y) : cont_mdiff_at (I.prod J) (I'.prod J') n (prod.map f g) (x, y) := begin rw ← cont_mdiff_within_at_univ at *, convert hf.prod_map hg, exact univ_prod_univ.symm end lemma cont_mdiff_at.prod_map' {p : M × N} (hf : cont_mdiff_at I I' n f p.1) (hg : cont_mdiff_at J J' n g p.2) : cont_mdiff_at (I.prod J) (I'.prod J') n (prod.map f g) p := begin rcases p, exact hf.prod_map hg end lemma cont_mdiff_on.prod_map (hf : cont_mdiff_on I I' n f s) (hg : cont_mdiff_on J J' n g r) : cont_mdiff_on (I.prod J) (I'.prod J') n (prod.map f g) (s ×ˢ r) := (hf.comp cont_mdiff_on_fst (prod_subset_preimage_fst _ _)).prod_mk $ hg.comp (cont_mdiff_on_snd) (prod_subset_preimage_snd _ _) lemma cont_mdiff.prod_map (hf : cont_mdiff I I' n f) (hg : cont_mdiff J J' n g) : cont_mdiff (I.prod J) (I'.prod J') n (prod.map f g) := begin assume p, exact (hf p.1).prod_map' (hg p.2) end lemma smooth_within_at.prod_map (hf : smooth_within_at I I' f s x) (hg : smooth_within_at J J' g r y) : smooth_within_at (I.prod J) (I'.prod J') (prod.map f g) (s ×ˢ r) (x, y) := hf.prod_map hg lemma smooth_at.prod_map (hf : smooth_at I I' f x) (hg : smooth_at J J' g y) : smooth_at (I.prod J) (I'.prod J') (prod.map f g) (x, y) := hf.prod_map hg lemma smooth_on.prod_map (hf : smooth_on I I' f s) (hg : smooth_on J J' g r) : smooth_on (I.prod J) (I'.prod J') (prod.map f g) (s ×ˢ r) := hf.prod_map hg lemma smooth.prod_map (hf : smooth I I' f) (hg : smooth J J' g) : smooth (I.prod J) (I'.prod J') (prod.map f g) := hf.prod_map hg end prod_map section pi_space /-! ### Smoothness of functions with codomain `Π i, F i` We have no `model_with_corners.pi` yet, so we prove lemmas about functions `f : M → Π i, F i` and use `𝓘(𝕜, Π i, F i)` as the model space. -/ variables {ι : Type*} [fintype ι] {Fi : ι → Type*} [Π i, normed_group (Fi i)] [Π i, normed_space 𝕜 (Fi i)] {φ : M → Π i, Fi i} lemma cont_mdiff_within_at_pi_space : cont_mdiff_within_at I (𝓘(𝕜, Π i, Fi i)) n φ s x ↔ ∀ i, cont_mdiff_within_at I (𝓘(𝕜, Fi i)) n (λ x, φ x i) s x := by simp only [cont_mdiff_within_at_iff, continuous_within_at_pi, cont_diff_within_at_pi, forall_and_distrib, written_in_ext_chart_at, ext_chart_model_space_eq_id, (∘), local_equiv.refl_coe, id] lemma cont_mdiff_on_pi_space : cont_mdiff_on I (𝓘(𝕜, Π i, Fi i)) n φ s ↔ ∀ i, cont_mdiff_on I (𝓘(𝕜, Fi i)) n (λ x, φ x i) s := ⟨λ h i x hx, cont_mdiff_within_at_pi_space.1 (h x hx) i, λ h x hx, cont_mdiff_within_at_pi_space.2 (λ i, h i x hx)⟩ lemma cont_mdiff_at_pi_space : cont_mdiff_at I (𝓘(𝕜, Π i, Fi i)) n φ x ↔ ∀ i, cont_mdiff_at I (𝓘(𝕜, Fi i)) n (λ x, φ x i) x := cont_mdiff_within_at_pi_space lemma cont_mdiff_pi_space : cont_mdiff I (𝓘(𝕜, Π i, Fi i)) n φ ↔ ∀ i, cont_mdiff I (𝓘(𝕜, Fi i)) n (λ x, φ x i) := ⟨λ h i x, cont_mdiff_at_pi_space.1 (h x) i, λ h x, cont_mdiff_at_pi_space.2 (λ i, h i x)⟩ lemma smooth_within_at_pi_space : smooth_within_at I (𝓘(𝕜, Π i, Fi i)) φ s x ↔ ∀ i, smooth_within_at I (𝓘(𝕜, Fi i)) (λ x, φ x i) s x := cont_mdiff_within_at_pi_space lemma smooth_on_pi_space : smooth_on I (𝓘(𝕜, Π i, Fi i)) φ s ↔ ∀ i, smooth_on I (𝓘(𝕜, Fi i)) (λ x, φ x i) s := cont_mdiff_on_pi_space lemma smooth_at_pi_space : smooth_at I (𝓘(𝕜, Π i, Fi i)) φ x ↔ ∀ i, smooth_at I (𝓘(𝕜, Fi i)) (λ x, φ x i) x := cont_mdiff_at_pi_space lemma smooth_pi_space : smooth I (𝓘(𝕜, Π i, Fi i)) φ ↔ ∀ i, smooth I (𝓘(𝕜, Fi i)) (λ x, φ x i) := cont_mdiff_pi_space end pi_space /-! ### Linear maps between normed spaces are smooth -/ lemma continuous_linear_map.cont_mdiff (L : E →L[𝕜] F) : cont_mdiff 𝓘(𝕜, E) 𝓘(𝕜, F) n L := L.cont_diff.cont_mdiff /-! ### Smoothness of standard operations -/ variables {V : Type*} [normed_group V] [normed_space 𝕜 V] /-- On any vector space, multiplication by a scalar is a smooth operation. -/ lemma smooth_smul : smooth (𝓘(𝕜).prod 𝓘(𝕜, V)) 𝓘(𝕜, V) (λp : 𝕜 × V, p.1 • p.2) := smooth_iff.2 ⟨continuous_smul, λ x y, cont_diff_smul.cont_diff_on⟩ lemma smooth.smul {N : Type*} [topological_space N] [charted_space H N] {f : N → 𝕜} {g : N → V} (hf : smooth I 𝓘(𝕜) f) (hg : smooth I 𝓘(𝕜, V) g) : smooth I 𝓘(𝕜, V) (λ p, f p • g p) := smooth_smul.comp (hf.prod_mk hg) lemma smooth_on.smul {N : Type*} [topological_space N] [charted_space H N] {f : N → 𝕜} {g : N → V} {s : set N} (hf : smooth_on I 𝓘(𝕜) f s) (hg : smooth_on I 𝓘(𝕜, V) g s) : smooth_on I 𝓘(𝕜, V) (λ p, f p • g p) s := smooth_smul.comp_smooth_on (hf.prod_mk hg) lemma smooth_at.smul {N : Type*} [topological_space N] [charted_space H N] {f : N → 𝕜} {g : N → V} {x : N} (hf : smooth_at I 𝓘(𝕜) f x) (hg : smooth_at I 𝓘(𝕜, V) g x) : smooth_at I 𝓘(𝕜, V) (λ p, f p • g p) x := smooth_smul.smooth_at.comp _ (hf.prod_mk hg)
e1d5c658642a1c39d21e68e0e96c05c87d643504
271e26e338b0c14544a889c31c30b39c989f2e0f
/tests/lean/run/expr_maps.lean
d098bc0dd2c8e845ebd5451ba2047d511e76df5c
[ "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
2,919
lean
import Init.Lean.Expr open Lean def exprType : Expr := mkSort levelOne def biDef := BinderInfo.default def exprNat := mkConst `Nat [] -- Type -> Type def TypeArrowType := mkForall `α biDef exprType exprType -- Type -> Type def TypeArrowType2 := mkForall `β biDef exprType exprType -- fun (x : Nat) => x def exprT1 := mkLambda `x biDef exprNat (mkBVar 0) -- fun (y : Nat) => x def exprT2 := mkLambda `y biDef exprNat (mkBVar 0) -- fun (x : Nat) => (f x) def exprT3 := mkLambda `x biDef exprNat (mkApp (mkConst `f []) (mkBVar 0)) -- fun (x : Nat) => (f x) def exprT4 := mkLambda `x BinderInfo.implicit exprNat (mkApp (mkConst `f []) (mkBVar 0)) def check (b : Bool) : IO Unit := unless b (throw "failed") def tst1 : IO Unit := do IO.println TypeArrowType; IO.println exprT1; IO.println exprT2; IO.println exprT3; IO.println exprT4; check (TypeArrowType == TypeArrowType2); check (ExprStructEq.mk TypeArrowType != ExprStructEq.mk TypeArrowType2); check (!Expr.equal TypeArrowType TypeArrowType2); check (exprT1 == exprT2); check (ExprStructEq.mk exprT1 != ExprStructEq.mk exprT2); check (ExprStructEq.mk exprT1 == ExprStructEq.mk exprT1); check (exprT3 == exprT4); check (ExprStructEq.mk exprT3 != ExprStructEq.mk exprT4); pure () #eval tst1 def tst2 : IO Unit := do let m1 : ExprMap Nat := {}; let m1 := m1.insert exprT1 10; check (m1.find? exprT1 == some 10); check (m1.find? exprT2 == some 10); check (m1.find? exprT3 == none); let m1 := m1.insert exprT4 20; check (m1.find? exprT1 == some 10); check (m1.find? exprT3 == some 20); IO.println (m1.find? exprT1); pure () #eval tst2 def tst3 : IO Unit := do let m1 : ExprStructMap Nat := {}; let m1 := m1.insert exprT1 10; check (m1.find? exprT1 == some 10); check (m1.find? exprT2 == none); check (m1.find? exprT3 == none); let m1 := m1.insert exprT4 20; check (m1.find? exprT1 == some 10); check (m1.find? exprT4 == some 20); check (m1.find? exprT3 == none); IO.println (m1.find? exprT1); pure () #eval tst3 def tst4 : IO Unit := do let m1 : PersistentExprMap Nat := {}; let m1 := m1.insert exprT1 10; check (m1.find? exprT1 == some 10); check (m1.find? exprT2 == some 10); check (m1.find? exprT3 == none); let m1 := m1.insert exprT4 20; check (m1.find? exprT1 == some 10); check (m1.find? exprT3 == some 20); IO.println (m1.find? exprT1); pure () #eval tst4 def tst5 : IO Unit := do let m1 : PersistentExprStructMap Nat := {}; let m1 := m1.insert exprT1 10; check (m1.find? exprT1 == some 10); check (m1.find? exprT2 == none); check (m1.find? exprT3 == none); let m1 := m1.insert exprT4 20; check (m1.find? exprT1 == some 10); check (m1.find? exprT4 == some 20); check (m1.find? exprT3 == none); IO.println (m1.find? exprT1); pure () #eval tst5
926f144f5a70f6c06f4c13f30a55cbd0d60271f1
c777c32c8e484e195053731103c5e52af26a25d1
/src/number_theory/pell.lean
b8eae0615add60667ff66848e7f5404eaf0fcc65
[ "Apache-2.0" ]
permissive
kbuzzard/mathlib
2ff9e85dfe2a46f4b291927f983afec17e946eb8
58537299e922f9c77df76cb613910914a479c1f7
refs/heads/master
1,685,313,702,744
1,683,974,212,000
1,683,974,212,000
128,185,277
1
0
null
1,522,920,600,000
1,522,920,600,000
null
UTF-8
Lean
false
false
29,355
lean
/- Copyright (c) 2023 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Geißer, Michael Stoll -/ import tactic.qify import data.zmod.basic import number_theory.diophantine_approximation import number_theory.zsqrtd.basic /-! # Pell's Equation *Pell's Equation* is the equation $x^2 - d y^2 = 1$, where $d$ is a positive integer that is not a square, and one is interested in solutions in integers $x$ and $y$. In this file, we aim at providing all of the essential theory of Pell's Equation for general $d$ (as opposed to the contents of `number_theory.pell_matiyasevic`, which is specific to the case $d = a^2 - 1$ for some $a > 1$). We begin by defining a type `pell.solution₁ d` for solutions of the equation, show that it has a natural structure as an abelian group, and prove some basic properties. We then prove the following **Theorem.** Let $d$ be a positive integer that is not a square. Then the equation $x^2 - d y^2 = 1$ has a nontrivial (i.e., with $y \ne 0$) solution in integers. See `pell.exists_of_not_is_square` and `pell.exists_nontrivial_of_not_is_square`. We then define the *fundamental solution* to be the solution with smallest $x$ among all solutions satisfying $x > 1$ and $y > 0$. We show that every solution is a power (in the sense of the group structure mentioned above) of the fundamental solution up to a (common) sign, see `pell.fundamental.eq_zpow_or_neg_zpow`, and that a (positive) solution has this property if and only if it is fundamental, see `pell.pos_generator_iff_fundamental`. ## References * [K. Ireland, M. Rosen, *A classical introduction to modern number theory* (Section 17.5)][IrelandRosen1990] ## Tags Pell's equation ## TODO * Extend to `x ^ 2 - d * y ^ 2 = -1` and further generalizations. * Connect solutions to the continued fraction expansion of `√d`. -/ namespace pell /-! ### Group structure of the solution set We define a structure of a commutative multiplicative group with distributive negation on the set of all solutions to the Pell equation `x^2 - d*y^2 = 1`. The type of such solutions is `pell.solution₁ d`. It corresponds to a pair of integers `x` and `y` and a proof that `(x, y)` is indeed a solution. The multiplication is given by `(x, y) * (x', y') = (x*y' + d*y*y', x*y' + y*x')`. This is obtained by mapping `(x, y)` to `x + y*√d` and multiplying the results. In fact, we define `pell.solution₁ d` to be `↥(unitary (ℤ√d))` and transport the "commutative group with distributive negation" structure from `↥(unitary (ℤ√d))`. We then set up an API for `pell.solution₁ d`. -/ open zsqrtd /-- An element of `ℤ√d` has norm one (i.e., `a.re^2 - d*a.im^2 = 1`) if and only if it is contained in the submonoid of unitary elements. TODO: merge this result with `pell.is_pell_iff_mem_unitary`. -/ lemma is_pell_solution_iff_mem_unitary {d : ℤ} {a : ℤ√d} : a.re ^ 2 - d * a.im ^ 2 = 1 ↔ a ∈ unitary ℤ√d := by rw [← norm_eq_one_iff_mem_unitary, norm_def, sq, sq, ← mul_assoc] -- We use `solution₁ d` to allow for a more general structure `solution d m` that -- encodes solutions to `x^2 - d*y^2 = m` to be added later. /-- `pell.solution₁ d` is the type of solutions to the Pell equation `x^2 - d*y^2 = 1`. We define this in terms of elements of `ℤ√d` of norm one. -/ @[derive [comm_group, has_distrib_neg, inhabited]] def solution₁ (d : ℤ) : Type := ↥(unitary ℤ√d) namespace solution₁ variables {d : ℤ} instance : has_coe (solution₁ d) ℤ√d := { coe := subtype.val } /-- The `x` component of a solution to the Pell equation `x^2 - d*y^2 = 1` -/ protected def x (a : solution₁ d) : ℤ := (a : ℤ√d).re /-- The `y` component of a solution to the Pell equation `x^2 - d*y^2 = 1` -/ protected def y (a : solution₁ d) : ℤ := (a : ℤ√d).im /-- The proof that `a` is a solution to the Pell equation `x^2 - d*y^2 = 1` -/ lemma prop (a : solution₁ d) : a.x ^ 2 - d * a.y ^ 2 = 1 := is_pell_solution_iff_mem_unitary.mpr a.property /-- An alternative form of the equation, suitable for rewriting `x^2`. -/ lemma prop_x (a : solution₁ d) : a.x ^ 2 = 1 + d * a.y ^ 2 := by {rw ← a.prop, ring} /-- An alternative form of the equation, suitable for rewriting `d * y^2`. -/ lemma prop_y (a : solution₁ d) : d * a.y ^ 2 = a.x ^ 2 - 1 := by {rw ← a.prop, ring} /-- Two solutions are equal if their `x` and `y` components are equal. -/ @[ext] lemma ext {a b : solution₁ d} (hx : a.x = b.x) (hy : a.y = b.y) : a = b := subtype.ext $ ext.mpr ⟨hx, hy⟩ /-- Construct a solution from `x`, `y` and a proof that the equation is satisfied. -/ def mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : solution₁ d := { val := ⟨x, y⟩, property := is_pell_solution_iff_mem_unitary.mp prop } @[simp] lemma x_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (mk x y prop).x = x := rfl @[simp] lemma y_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (mk x y prop).y = y := rfl @[simp] lemma coe_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (↑(mk x y prop) : ℤ√d) = ⟨x,y⟩ := zsqrtd.ext.mpr ⟨x_mk x y prop, y_mk x y prop⟩ @[simp] lemma x_one : (1 : solution₁ d).x = 1 := rfl @[simp] lemma y_one : (1 : solution₁ d).y = 0 := rfl @[simp] lemma x_mul (a b : solution₁ d) : (a * b).x = a.x * b.x + d * (a.y * b.y) := by {rw ← mul_assoc, refl} @[simp] lemma y_mul (a b : solution₁ d) : (a * b).y = a.x * b.y + a.y * b.x := rfl @[simp] lemma x_inv (a : solution₁ d) : a⁻¹.x = a.x := rfl @[simp] lemma y_inv (a : solution₁ d) : a⁻¹.y = -a.y := rfl @[simp] lemma x_neg (a : solution₁ d) : (-a).x = -a.x := rfl @[simp] lemma y_neg (a : solution₁ d) : (-a).y = -a.y := rfl /-- When `d` is negative, then `x` or `y` must be zero in a solution. -/ lemma eq_zero_of_d_neg (h₀ : d < 0) (a : solution₁ d) : a.x = 0 ∨ a.y = 0 := begin have h := a.prop, contrapose! h, have h1 := sq_pos_of_ne_zero a.x h.1, have h2 := sq_pos_of_ne_zero a.y h.2, nlinarith, end /-- A solution has `x ≠ 0`. -/ lemma x_ne_zero (h₀ : 0 ≤ d) (a : solution₁ d) : a.x ≠ 0 := begin intro hx, have h : 0 ≤ d * a.y ^ 2 := mul_nonneg h₀ (sq_nonneg _), rw [a.prop_y, hx, sq, zero_mul, zero_sub] at h, exact not_le.mpr (neg_one_lt_zero : (-1 : ℤ) < 0) h, end /-- A solution with `x > 1` must have `y ≠ 0`. -/ lemma y_ne_zero_of_one_lt_x {a : solution₁ d} (ha : 1 < a.x) : a.y ≠ 0 := begin intro hy, have prop := a.prop, rw [hy, sq (0 : ℤ), zero_mul, mul_zero, sub_zero] at prop, exact lt_irrefl _ (((one_lt_sq_iff $ zero_le_one.trans ha.le).mpr ha).trans_eq prop), end /-- If a solution has `x > 1`, then `d` is positive. -/ lemma d_pos_of_one_lt_x {a : solution₁ d} (ha : 1 < a.x) : 0 < d := begin refine pos_of_mul_pos_left _ (sq_nonneg a.y), rw [a.prop_y, sub_pos], exact one_lt_pow ha two_ne_zero, end /-- If a solution has `x > 1`, then `d` is not a square. -/ lemma d_nonsquare_of_one_lt_x {a : solution₁ d} (ha : 1 < a.x) : ¬ is_square d := begin have hp := a.prop, rintros ⟨b, rfl⟩, simp_rw [← sq, ← mul_pow, sq_sub_sq, int.mul_eq_one_iff_eq_one_or_neg_one] at hp, rcases hp with ⟨hp₁, hp₂⟩ | ⟨hp₁, hp₂⟩; linarith [ha, hp₁, hp₂], end /-- A solution with `x = 1` is trivial. -/ lemma eq_one_of_x_eq_one (h₀ : d ≠ 0) {a : solution₁ d} (ha : a.x = 1) : a = 1 := begin have prop := a.prop_y, rw [ha, one_pow, sub_self, mul_eq_zero, or_iff_right h₀, sq_eq_zero_iff] at prop, exact ext ha prop, end /-- A solution is `1` or `-1` if and only if `y = 0`. -/ lemma eq_one_or_neg_one_iff_y_eq_zero {a : solution₁ d} : a = 1 ∨ a = -1 ↔ a.y = 0 := begin refine ⟨λ H, H.elim (λ h, by simp [h]) (λ h, by simp [h]), λ H, _⟩, have prop := a.prop, rw [H, sq (0 : ℤ), mul_zero, mul_zero, sub_zero, sq_eq_one_iff] at prop, exact prop.imp (λ h, ext h H) (λ h, ext h H), end /-- The set of solutions with `x > 0` is closed under multiplication. -/ lemma x_mul_pos {a b : solution₁ d} (ha : 0 < a.x) (hb : 0 < b.x) : 0 < (a * b).x := begin simp only [x_mul], refine neg_lt_iff_pos_add'.mp (abs_lt.mp _).1, rw [← abs_of_pos ha, ← abs_of_pos hb, ← abs_mul, ← sq_lt_sq, mul_pow a.x, a.prop_x, b.prop_x, ← sub_pos], ring_nf, cases le_or_lt 0 d with h h, { positivity, }, { rw [(eq_zero_of_d_neg h a).resolve_left ha.ne', (eq_zero_of_d_neg h b).resolve_left hb.ne', zero_pow two_pos, zero_add, zero_mul, zero_add], exact one_pos, }, end /-- The set of solutions with `x` and `y` positive is closed under multiplication. -/ lemma y_mul_pos {a b : solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) (hbx : 0 < b.x) (hby : 0 < b.y) : 0 < (a * b).y := begin simp only [y_mul], positivity, end /-- If `(x, y)` is a solution with `x` positive, then all its powers with natural exponents have positive `x`. -/ lemma x_pow_pos {a : solution₁ d} (hax : 0 < a.x) (n : ℕ) : 0 < (a ^ n).x := begin induction n with n ih, { simp only [pow_zero, x_one, zero_lt_one], }, { rw [pow_succ], exact x_mul_pos hax ih, } end /-- If `(x, y)` is a solution with `x` and `y` positive, then all its powers with positive natural exponents have positive `y`. -/ lemma y_pow_succ_pos {a : solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) (n : ℕ) : 0 < (a ^ n.succ).y := begin induction n with n ih, { simp only [hay, pow_one], }, { rw [pow_succ], exact y_mul_pos hax hay (x_pow_pos hax _) ih, } end /-- If `(x, y)` is a solution with `x` and `y` positive, then all its powers with positive exponents have positive `y`. -/ lemma y_zpow_pos {a : solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) {n : ℤ} (hn : 0 < n) : 0 < (a ^ n).y := begin lift n to ℕ using hn.le, norm_cast at hn ⊢, rw ← nat.succ_pred_eq_of_pos hn, exact y_pow_succ_pos hax hay _, end /-- If `(x, y)` is a solution with `x` positive, then all its powers have positive `x`. -/ lemma x_zpow_pos {a : solution₁ d} (hax : 0 < a.x) (n : ℤ) : 0 < (a ^ n).x := begin cases n, { rw zpow_of_nat, exact x_pow_pos hax n }, { rw zpow_neg_succ_of_nat, exact x_pow_pos hax (n + 1) }, end /-- If `(x, y)` is a solution with `x` and `y` positive, then the `y` component of any power has the same sign as the exponent. -/ lemma sign_y_zpow_eq_sign_of_x_pos_of_y_pos {a : solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) (n : ℤ) : (a ^ n).y.sign = n.sign := begin rcases n with (_ | _) | _, { refl }, { rw zpow_of_nat, exact int.sign_eq_one_of_pos (y_pow_succ_pos hax hay n) }, { rw zpow_neg_succ_of_nat, exact int.sign_eq_neg_one_of_neg (neg_neg_of_pos (y_pow_succ_pos hax hay n)) }, end /-- If `a` is any solution, then one of `a`, `a⁻¹`, `-a`, `-a⁻¹` has positive `x` and nonnegative `y`. -/ lemma exists_pos_variant (h₀ : 0 < d) (a : solution₁ d) : ∃ b : solution₁ d, 0 < b.x ∧ 0 ≤ b.y ∧ a ∈ ({b, b⁻¹, -b, -b⁻¹} : set (solution₁ d)) := begin refine (lt_or_gt_of_ne (a.x_ne_zero h₀.le)).elim ((le_total 0 a.y).elim (λ hy hx, ⟨-a⁻¹, _, _, _⟩) (λ hy hx, ⟨-a, _, _, _⟩)) ((le_total 0 a.y).elim (λ hy hx, ⟨a, hx, hy, _⟩) (λ hy hx, ⟨a⁻¹, hx, _, _⟩)); simp only [neg_neg, inv_inv, neg_inv, set.mem_insert_iff, set.mem_singleton_iff, true_or, eq_self_iff_true, x_neg, x_inv, y_neg, y_inv, neg_pos, neg_nonneg, or_true]; assumption, end end solution₁ section existence /-! ### Existence of nontrivial solutions -/ variables {d : ℤ} open set real /-- If `d` is a positive integer that is not a square, then there is a nontrivial solution to the Pell equation `x^2 - d*y^2 = 1`. -/ theorem exists_of_not_is_square (h₀ : 0 < d) (hd : ¬ is_square d) : ∃ x y : ℤ, x ^ 2 - d * y ^ 2 = 1 ∧ y ≠ 0 := begin let ξ : ℝ := sqrt d, have hξ : irrational ξ, { refine irrational_nrt_of_notint_nrt 2 d (sq_sqrt $ int.cast_nonneg.mpr h₀.le) _ two_pos, rintro ⟨x, hx⟩, refine hd ⟨x, @int.cast_injective ℝ _ _ d (x * x) _⟩, rw [← sq_sqrt $ int.cast_nonneg.mpr h₀.le, int.cast_mul, ← hx, sq], }, obtain ⟨M, hM₁⟩ := exists_int_gt (2 * |ξ| + 1), have hM : {q : ℚ | |q.1 ^ 2 - d * q.2 ^ 2| < M}.infinite, { refine infinite.mono (λ q h, _) (infinite_rat_abs_sub_lt_one_div_denom_sq_of_irrational hξ), have h0 : 0 < (q.2 : ℝ) ^ 2 := pow_pos (nat.cast_pos.mpr q.pos) 2, have h1 : (q.num : ℝ) / (q.denom : ℝ) = q := by exact_mod_cast q.num_div_denom, rw [mem_set_of, abs_sub_comm, ← @int.cast_lt ℝ, ← div_lt_div_right (abs_pos_of_pos h0)], push_cast, rw [← abs_div, abs_sq, sub_div, mul_div_cancel _ h0.ne', ← div_pow, h1, ← sq_sqrt (int.cast_pos.mpr h₀).le, sq_sub_sq, abs_mul, ← mul_one_div], refine mul_lt_mul'' (((abs_add ξ q).trans _).trans_lt hM₁) h (abs_nonneg _) (abs_nonneg _), rw [two_mul, add_assoc, add_le_add_iff_left, ← sub_le_iff_le_add'], rw [mem_set_of, abs_sub_comm] at h, refine (abs_sub_abs_le_abs_sub (q : ℝ) ξ).trans (h.le.trans _), rw [div_le_one h0, one_le_sq_iff_one_le_abs, nat.abs_cast, nat.one_le_cast], exact q.pos, }, obtain ⟨m, hm⟩ : ∃ m : ℤ, {q : ℚ | q.1 ^ 2 - d * q.2 ^ 2 = m}.infinite, { contrapose! hM, simp only [not_infinite] at hM ⊢, refine (congr_arg _ (ext (λ x, _))).mp (finite.bUnion (finite_Ioo (-M) M) (λ m _, hM m)), simp only [abs_lt, mem_set_of_eq, mem_Ioo, mem_Union, exists_prop, exists_eq_right'], }, have hm₀ : m ≠ 0, { rintro rfl, obtain ⟨q, hq⟩ := hm.nonempty, rw [mem_set_of, sub_eq_zero, mul_comm] at hq, obtain ⟨a, ha⟩ := (int.pow_dvd_pow_iff two_pos).mp ⟨d, hq⟩, rw [ha, mul_pow, mul_right_inj' (pow_pos (int.coe_nat_pos.mpr q.pos) 2).ne'] at hq, exact hd ⟨a, sq a ▸ hq.symm⟩, }, haveI := ne_zero_iff.mpr (int.nat_abs_ne_zero.mpr hm₀), let f : ℚ → (zmod m.nat_abs) × (zmod m.nat_abs) := λ q, (q.1, q.2), obtain ⟨q₁, h₁ : q₁.1 ^ 2 - d * q₁.2 ^ 2 = m, q₂, h₂ : q₂.1 ^ 2 - d * q₂.2 ^ 2 = m, hne, hqf⟩ := hm.exists_ne_map_eq_of_maps_to (maps_to_univ f _) finite_univ, obtain ⟨hq1 : (q₁.1 : zmod m.nat_abs) = q₂.1, hq2 : (q₁.2 : zmod m.nat_abs) = q₂.2⟩ := prod.ext_iff.mp hqf, have hd₁ : m ∣ q₁.1 * q₂.1 - d * (q₁.2 * q₂.2), { rw [← int.nat_abs_dvd, ← zmod.int_coe_zmod_eq_zero_iff_dvd], push_cast, rw [hq1, hq2, ← sq, ← sq], norm_cast, rw [zmod.int_coe_zmod_eq_zero_iff_dvd, int.nat_abs_dvd, nat.cast_pow, ← h₂], }, have hd₂ : m ∣ q₁.1 * q₂.2 - q₂.1 * q₁.2, { rw [← int.nat_abs_dvd, ← zmod.int_coe_eq_int_coe_iff_dvd_sub], push_cast, rw [hq1, hq2], }, replace hm₀ : (m : ℚ) ≠ 0 := int.cast_ne_zero.mpr hm₀, refine ⟨(q₁.1 * q₂.1 - d * (q₁.2 * q₂.2)) / m, (q₁.1 * q₂.2 - q₂.1 * q₁.2) / m, _, _⟩, { qify [hd₁, hd₂], field_simp [hm₀], norm_cast, conv_rhs {congr, rw sq, congr, rw ← h₁, skip, rw ← h₂}, push_cast, ring, }, { qify [hd₂], refine div_ne_zero_iff.mpr ⟨_, hm₀⟩, exact_mod_cast mt sub_eq_zero.mp (mt rat.eq_iff_mul_eq_mul.mpr hne), }, end /-- If `d` is a positive integer, then there is a nontrivial solution to the Pell equation `x^2 - d*y^2 = 1` if and only if `d` is not a square. -/ theorem exists_iff_not_is_square (h₀ : 0 < d) : (∃ x y : ℤ, x ^ 2 - d * y ^ 2 = 1 ∧ y ≠ 0) ↔ ¬ is_square d := begin refine ⟨_, exists_of_not_is_square h₀⟩, rintros ⟨x, y, hxy, hy⟩ ⟨a, rfl⟩, rw [← sq, ← mul_pow, sq_sub_sq] at hxy, simpa [mul_self_pos.mp h₀, sub_eq_add_neg, eq_neg_self_iff] using int.eq_of_mul_eq_one hxy, end namespace solution₁ /-- If `d` is a positive integer that is not a square, then there exists a nontrivial solution to the Pell equation `x^2 - d*y^2 = 1`. -/ theorem exists_nontrivial_of_not_is_square (h₀ : 0 < d) (hd : ¬ is_square d) : ∃ a : solution₁ d, a ≠ 1 ∧ a ≠ -1 := begin obtain ⟨x, y, prop, hy⟩ := exists_of_not_is_square h₀ hd, refine ⟨mk x y prop, λ H, _, λ H, _⟩; apply_fun solution₁.y at H; simpa only [hy] using H, end /-- If `d` is a positive integer that is not a square, then there exists a solution to the Pell equation `x^2 - d*y^2 = 1` with `x > 1` and `y > 0`. -/ lemma exists_pos_of_not_is_square (h₀ : 0 < d) (hd : ¬ is_square d) : ∃ a : solution₁ d, 1 < a.x ∧ 0 < a.y := begin obtain ⟨x, y, h, hy⟩ := exists_of_not_is_square h₀ hd, refine ⟨mk (|x|) (|y|) (by rwa [sq_abs, sq_abs]), _, abs_pos.mpr hy⟩, rw [x_mk, ← one_lt_sq_iff_one_lt_abs, eq_add_of_sub_eq h, lt_add_iff_pos_right], exact mul_pos h₀ (sq_pos_of_ne_zero y hy), end end solution₁ end existence /-! ### Fundamental solutions We define the notion of a *fundamental solution* of Pell's equation and show that it exists and is unique (when `d` is positive and non-square) and generates the group of solutions up to sign. -/ variables {d : ℤ} /-- We define a solution to be *fundamental* if it has `x > 1` and `y > 0` and its `x` is the smallest possible among solutions with `x > 1`. -/ def is_fundamental (a : solution₁ d) : Prop := 1 < a.x ∧ 0 < a.y ∧ ∀ {b : solution₁ d}, 1 < b.x → a.x ≤ b.x namespace is_fundamental open solution₁ /-- A fundamental solution has positive `x`. -/ lemma x_pos {a : solution₁ d} (h : is_fundamental a) : 0 < a.x := zero_lt_one.trans h.1 /-- If a fundamental solution exists, then `d` must be positive. -/ lemma d_pos {a : solution₁ d} (h : is_fundamental a) : 0 < d := d_pos_of_one_lt_x h.1 /-- If a fundamental solution exists, then `d` must be a non-square. -/ lemma d_nonsquare {a : solution₁ d} (h : is_fundamental a) : ¬ is_square d := d_nonsquare_of_one_lt_x h.1 /-- If there is a fundamental solution, it is unique. -/ lemma subsingleton {a b : solution₁ d} (ha : is_fundamental a) (hb : is_fundamental b) : a = b := begin have hx := le_antisymm (ha.2.2 hb.1) (hb.2.2 ha.1), refine solution₁.ext hx _, have : d * a.y ^ 2 = d * b.y ^ 2 := by rw [a.prop_y, b.prop_y, hx], exact (sq_eq_sq ha.2.1.le hb.2.1.le).mp (int.eq_of_mul_eq_mul_left ha.d_pos.ne' this), end /-- If `d` is positive and not a square, then a fundamental solution exists. -/ lemma exists_of_not_is_square (h₀ : 0 < d) (hd : ¬ is_square d) : ∃ a : solution₁ d, is_fundamental a := begin obtain ⟨a, ha₁, ha₂⟩ := exists_pos_of_not_is_square h₀ hd, -- convert to `x : ℕ` to be able to use `nat.find` have P : ∃ x' : ℕ, 1 < x' ∧ ∃ y' : ℤ, 0 < y' ∧ (x' : ℤ) ^ 2 - d * y' ^ 2 = 1, { have hax := a.prop, lift a.x to ℕ using (by positivity) with ax, norm_cast at ha₁, exact ⟨ax, ha₁, a.y, ha₂, hax⟩, }, classical, -- to avoid having to show that the predicate is decidable let x₁ := nat.find P, obtain ⟨hx, y₁, hy₀, hy₁⟩ := nat.find_spec P, refine ⟨mk x₁ y₁ hy₁, (by {rw x_mk, exact_mod_cast hx}), hy₀, λ b hb, _⟩, rw x_mk, have hb' := (int.to_nat_of_nonneg $ zero_le_one.trans hb.le).symm, have hb'' := hb, rw hb' at hb ⊢, norm_cast at hb ⊢, refine nat.find_min' P ⟨hb, |b.y|, abs_pos.mpr $ y_ne_zero_of_one_lt_x hb'', _⟩, rw [← hb', sq_abs], exact b.prop, end /-- The map sending an integer `n` to the `y`-coordinate of `a^n` for a fundamental solution `a` is stritcly increasing. -/ lemma y_strict_mono {a : solution₁ d} (h : is_fundamental a) : strict_mono (λ (n : ℤ), (a ^ n).y) := begin have H : ∀ (n : ℤ), 0 ≤ n → (a ^ n).y < (a ^ (n + 1)).y, { intros n hn, rw [← sub_pos, zpow_add, zpow_one, y_mul, add_sub_assoc], rw show (a ^ n).y * a.x - (a ^ n).y = (a ^ n).y * (a.x - 1), from by ring, refine add_pos_of_pos_of_nonneg (mul_pos (x_zpow_pos h.x_pos _) h.2.1) (mul_nonneg _ (by {rw sub_nonneg, exact h.1.le})), rcases hn.eq_or_lt with rfl | hn, { simp only [zpow_zero, y_one], }, { exact (y_zpow_pos h.x_pos h.2.1 hn).le, } }, refine strict_mono_int_of_lt_succ (λ n, _), cases le_or_lt 0 n with hn hn, { exact H n hn, }, { let m : ℤ := -n - 1, have hm : n = -m - 1 := by simp only [neg_sub, sub_neg_eq_add, add_tsub_cancel_left], rw [hm, sub_add_cancel, ← neg_add', zpow_neg, zpow_neg, y_inv, y_inv, neg_lt_neg_iff], exact H _ (by linarith [hn]), } end /-- If `a` is a fundamental solution, then `(a^m).y < (a^n).y` if and only if `m < n`. -/ lemma zpow_y_lt_iff_lt {a : solution₁ d} (h : is_fundamental a) (m n : ℤ) : (a ^ m).y < (a ^ n).y ↔ m < n := begin refine ⟨λ H, _, λ H, h.y_strict_mono H⟩, contrapose! H, exact h.y_strict_mono.monotone H, end /-- The `n`th power of a fundamental solution is trivial if and only if `n = 0`. -/ lemma zpow_eq_one_iff {a : solution₁ d} (h : is_fundamental a) (n : ℤ) : a ^ n = 1 ↔ n = 0 := begin rw ← zpow_zero a, exact ⟨λ H, h.y_strict_mono.injective (congr_arg solution₁.y H), λ H, H ▸ rfl⟩, end /-- A power of a fundamental solution is never equal to the negative of a power of this fundamental solution. -/ lemma zpow_ne_neg_zpow {a : solution₁ d} (h : is_fundamental a) {n n' : ℤ} : a ^ n ≠ -a ^ n' := begin intro hf, apply_fun solution₁.x at hf, have H := x_zpow_pos h.x_pos n, rw [hf, x_neg, lt_neg, neg_zero] at H, exact lt_irrefl _ ((x_zpow_pos h.x_pos n').trans H), end /-- The `x`-coordinate of a fundamental solution is a lower bound for the `x`-coordinate of any positive solution. -/ lemma x_le_x {a₁ : solution₁ d} (h : is_fundamental a₁) {a : solution₁ d} (hax : 1 < a.x) : a₁.x ≤ a.x := h.2.2 hax /-- The `y`-coordinate of a fundamental solution is a lower bound for the `y`-coordinate of any positive solution. -/ lemma y_le_y {a₁ : solution₁ d} (h : is_fundamental a₁) {a : solution₁ d} (hax : 1 < a.x) (hay : 0 < a.y) : a₁.y ≤ a.y := begin have H : d * (a₁.y ^ 2 - a.y ^ 2) = a₁.x ^ 2 - a.x ^ 2 := by { rw [a.prop_x, a₁.prop_x], ring }, rw [← abs_of_pos hay, ← abs_of_pos h.2.1, ← sq_le_sq, ← mul_le_mul_left h.d_pos, ← sub_nonpos, ← mul_sub, H, sub_nonpos, sq_le_sq, abs_of_pos (zero_lt_one.trans h.1), abs_of_pos (zero_lt_one.trans hax)], exact h.x_le_x hax, end -- helper lemma for the next three results lemma x_mul_y_le_y_mul_x {a₁ : solution₁ d} (h : is_fundamental a₁) {a : solution₁ d} (hax : 1 < a.x) (hay : 0 < a.y) : a.x * a₁.y ≤ a.y * a₁.x := begin rw [← abs_of_pos $ zero_lt_one.trans hax, ← abs_of_pos hay, ← abs_of_pos h.x_pos, ← abs_of_pos h.2.1, ← abs_mul, ← abs_mul, ← sq_le_sq, mul_pow, mul_pow, a.prop_x, a₁.prop_x, ← sub_nonneg], ring_nf, rw [sub_nonneg, sq_le_sq, abs_of_pos hay, abs_of_pos h.2.1], exact h.y_le_y hax hay, end /-- If we multiply a positive solution with the inverse of a fundamental solution, the `y`-coordinate remains nonnegative. -/ lemma mul_inv_y_nonneg {a₁ : solution₁ d} (h : is_fundamental a₁) {a : solution₁ d} (hax : 1 < a.x) (hay : 0 < a.y) : 0 ≤ (a * a₁⁻¹).y := by simpa only [y_inv, mul_neg, y_mul, le_neg_add_iff_add_le, add_zero] using h.x_mul_y_le_y_mul_x hax hay /-- If we multiply a positive solution with the inverse of a fundamental solution, the `x`-coordinate stays positive. -/ lemma mul_inv_x_pos {a₁ : solution₁ d} (h : is_fundamental a₁) {a : solution₁ d} (hax : 1 < a.x) (hay : 0 < a.y) : 0 < (a * a₁⁻¹).x := begin simp only [x_mul, x_inv, y_inv, mul_neg, lt_add_neg_iff_add_lt, zero_add], refine (mul_lt_mul_left $ zero_lt_one.trans hax).mp _, rw [(by ring : a.x * (d * (a.y * a₁.y)) = (d * a.y) * (a.x * a₁.y))], refine ((mul_le_mul_left $ mul_pos h.d_pos hay).mpr $ x_mul_y_le_y_mul_x h hax hay).trans_lt _, rw [← mul_assoc, mul_assoc d, ← sq, a.prop_y, ← sub_pos], ring_nf, exact zero_lt_one.trans h.1, end /-- If we multiply a positive solution with the inverse of a fundamental solution, the `x`-coordinate decreases. -/ lemma mul_inv_x_lt_x {a₁ : solution₁ d} (h : is_fundamental a₁) {a : solution₁ d} (hax : 1 < a.x) (hay : 0 < a.y) : (a * a₁⁻¹).x < a.x := begin simp only [x_mul, x_inv, y_inv, mul_neg, add_neg_lt_iff_le_add'], refine (mul_lt_mul_left h.2.1).mp _, rw [(by ring : a₁.y * (a.x * a₁.x) = a.x * a₁.y * a₁.x)], refine ((mul_le_mul_right $ zero_lt_one.trans h.1).mpr $ x_mul_y_le_y_mul_x h hax hay).trans_lt _, rw [mul_assoc, ← sq, a₁.prop_x, ← sub_neg], ring_nf, rw [sub_neg, ← abs_of_pos hay, ← abs_of_pos h.2.1, ← abs_of_pos $ zero_lt_one.trans hax, ← abs_mul, ← sq_lt_sq, mul_pow, a.prop_x], calc a.y ^ 2 = 1 * a.y ^ 2 : (one_mul _).symm ... ≤ d * a.y ^ 2 : (mul_le_mul_right $ sq_pos_of_pos hay).mpr h.d_pos ... < d * a.y ^ 2 + 1 : lt_add_one _ ... = (1 + d * a.y ^ 2) * 1 : by rw [add_comm, mul_one] ... ≤ (1 + d * a.y ^ 2) * a₁.y ^ 2 : (mul_le_mul_left (by {have := h.d_pos, positivity})).mpr (sq_pos_of_pos h.2.1), end /-- Any nonnegative solution is a power with nonnegative exponent of a fundamental solution. -/ lemma eq_pow_of_nonneg {a₁ : solution₁ d} (h : is_fundamental a₁) {a : solution₁ d} (hax : 0 < a.x) (hay : 0 ≤ a.y) : ∃ n : ℕ, a = a₁ ^ n := begin lift a.x to ℕ using hax.le with ax hax', induction ax using nat.strong_induction_on with x ih generalizing a, cases hay.eq_or_lt with hy hy, { -- case 1: `a = 1` refine ⟨0, _⟩, simp only [pow_zero], ext; simp only [x_one, y_one], { have prop := a.prop, rw [← hy, sq (0 : ℤ), zero_mul, mul_zero, sub_zero, sq_eq_one_iff] at prop, refine prop.resolve_right (λ hf, _), have := (hax.trans_eq hax').le.trans_eq hf, norm_num at this, }, { exact hy.symm, } }, { -- case 2: `a ≥ a₁` have hx₁ : 1 < a.x := by nlinarith [a.prop, h.d_pos], have hxx₁ := h.mul_inv_x_pos hx₁ hy, have hxx₂ := h.mul_inv_x_lt_x hx₁ hy, have hyy := h.mul_inv_y_nonneg hx₁ hy, lift (a * a₁⁻¹).x to ℕ using hxx₁.le with x' hx', obtain ⟨n, hn⟩ := ih x' (by exact_mod_cast hxx₂.trans_eq hax'.symm) hxx₁ hyy hx', exact ⟨n + 1, by rw [pow_succ, ← hn, mul_comm a, ← mul_assoc, mul_inv_self, one_mul]⟩, }, end /-- Every solution is, up to a sign, a power of a given fundamental solution. -/ lemma eq_zpow_or_neg_zpow {a₁ : solution₁ d} (h : is_fundamental a₁) (a : solution₁ d) : ∃ n : ℤ, a = a₁ ^ n ∨ a = -a₁ ^ n := begin obtain ⟨b, hbx, hby, hb⟩ := exists_pos_variant h.d_pos a, obtain ⟨n, hn⟩ := h.eq_pow_of_nonneg hbx hby, rcases hb with rfl | rfl | rfl | hb, { exact ⟨n, or.inl (by exact_mod_cast hn)⟩, }, { exact ⟨-n, or.inl (by simp [hn])⟩, }, { exact ⟨n, or.inr (by simp [hn])⟩, }, { rw set.mem_singleton_iff at hb, rw hb, exact ⟨-n, or.inr (by simp [hn])⟩, } end end is_fundamental open solution₁ is_fundamental /-- When `d` is positive and not a square, then the group of solutions to the Pell equation `x^2 - d*y^2 = 1` has a unique positive generator (up to sign). -/ theorem exists_unique_pos_generator (h₀ : 0 < d) (hd : ¬ is_square d) : ∃! a₁ : solution₁ d, 1 < a₁.x ∧ 0 < a₁.y ∧ ∀ a : solution₁ d, ∃ n : ℤ, a = a₁ ^ n ∨ a = -a₁ ^ n := begin obtain ⟨a₁, ha₁⟩ := is_fundamental.exists_of_not_is_square h₀ hd, refine ⟨a₁, ⟨ha₁.1, ha₁.2.1, ha₁.eq_zpow_or_neg_zpow⟩, λ a (H : 1 < _ ∧ _), _⟩, obtain ⟨Hx, Hy, H⟩ := H, obtain ⟨n₁, hn₁⟩ := H a₁, obtain ⟨n₂, hn₂⟩ := ha₁.eq_zpow_or_neg_zpow a, rcases hn₂ with rfl | rfl, { rw [← zpow_mul, eq_comm, @eq_comm _ a₁, ← mul_inv_eq_one, ← @mul_inv_eq_one _ _ _ a₁, ← zpow_neg_one, neg_mul, ← zpow_add, ← sub_eq_add_neg] at hn₁, cases hn₁, { rcases int.is_unit_iff.mp (is_unit_of_mul_eq_one _ _ $ sub_eq_zero.mp $ (ha₁.zpow_eq_one_iff (n₂ * n₁ - 1)).mp hn₁) with rfl | rfl, { rw zpow_one, }, { rw [zpow_neg_one, y_inv, lt_neg, neg_zero] at Hy, exact false.elim (lt_irrefl _ $ ha₁.2.1.trans Hy), } }, { rw [← zpow_zero a₁, eq_comm] at hn₁, exact false.elim (ha₁.zpow_ne_neg_zpow hn₁), } }, { rw [x_neg, lt_neg] at Hx, have := (x_zpow_pos (zero_lt_one.trans ha₁.1) n₂).trans Hx, norm_num at this, } end /-- A positive solution is a generator (up to sign) of the group of all solutions to the Pell equation `x^2 - d*y^2 = 1` if and only if it is a fundamental solution. -/ theorem pos_generator_iff_fundamental (a : solution₁ d) : (1 < a.x ∧ 0 < a.y ∧ ∀ b : solution₁ d, ∃ n : ℤ, b = a ^ n ∨ b = -a ^ n) ↔ is_fundamental a := begin refine ⟨λ h, _, λ H, ⟨H.1, H.2.1, H.eq_zpow_or_neg_zpow⟩⟩, have h₀ := d_pos_of_one_lt_x h.1, have hd := d_nonsquare_of_one_lt_x h.1, obtain ⟨a₁, ha₁⟩ := is_fundamental.exists_of_not_is_square h₀ hd, obtain ⟨b, hb₁, hb₂⟩ := exists_unique_pos_generator h₀ hd, rwa [hb₂ a h, ← hb₂ a₁ ⟨ha₁.1, ha₁.2.1, ha₁.eq_zpow_or_neg_zpow⟩], end end pell
e050edb8eb1ef6be67bade8ae59991f65bd47404
77c5b91fae1b966ddd1db969ba37b6f0e4901e88
/src/data/list/perm.lean
21c02102f2ce988a2a4295d313667d0478cbac16
[ "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
54,122
lean
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro -/ import data.list.bag_inter import data.list.erase_dup import data.list.zip import logic.relation /-! # List Permutations This file introduces the `list.perm` relation, which is true if two lists are permutations of one another. ## Notation The notation `~` is used for permutation equivalence. -/ open_locale nat namespace list universe variables uu vv variables {α : Type uu} {β : Type vv} /-- `perm l₁ l₂` or `l₁ ~ l₂` asserts that `l₁` and `l₂` are permutations of each other. This is defined by induction using pairwise swaps. -/ inductive perm : list α → list α → Prop | nil : perm [] [] | cons : Π (x : α) {l₁ l₂ : list α}, perm l₁ l₂ → perm (x::l₁) (x::l₂) | swap : Π (x y : α) (l : list α), perm (y::x::l) (x::y::l) | trans : Π {l₁ l₂ l₃ : list α}, perm l₁ l₂ → perm l₂ l₃ → perm l₁ l₃ open perm (swap) infix ` ~ `:50 := perm @[refl] protected theorem perm.refl : ∀ (l : list α), l ~ l | [] := perm.nil | (x::xs) := (perm.refl xs).cons x @[symm] protected theorem perm.symm {l₁ l₂ : list α} (p : l₁ ~ l₂) : l₂ ~ l₁ := perm.rec_on p perm.nil (λ x l₁ l₂ p₁ r₁, r₁.cons x) (λ x y l, swap y x l) (λ l₁ l₂ l₃ p₁ p₂ r₁ r₂, r₂.trans r₁) theorem perm_comm {l₁ l₂ : list α} : l₁ ~ l₂ ↔ l₂ ~ l₁ := ⟨perm.symm, perm.symm⟩ theorem perm.swap' (x y : α) {l₁ l₂ : list α} (p : l₁ ~ l₂) : y::x::l₁ ~ x::y::l₂ := (swap _ _ _).trans ((p.cons _).cons _) attribute [trans] perm.trans theorem perm.eqv (α) : equivalence (@perm α) := mk_equivalence (@perm α) (@perm.refl α) (@perm.symm α) (@perm.trans α) instance is_setoid (α) : setoid (list α) := setoid.mk (@perm α) (perm.eqv α) theorem perm.subset {l₁ l₂ : list α} (p : l₁ ~ l₂) : l₁ ⊆ l₂ := λ a, perm.rec_on p (λ h, h) (λ x l₁ l₂ p₁ r₁ i, or.elim i (λ ax, by simp [ax]) (λ al₁, or.inr (r₁ al₁))) (λ x y l ayxl, or.elim ayxl (λ ay, by simp [ay]) (λ axl, or.elim axl (λ ax, by simp [ax]) (λ al, or.inr (or.inr al)))) (λ l₁ l₂ l₃ p₁ p₂ r₁ r₂ ainl₁, r₂ (r₁ ainl₁)) theorem perm.mem_iff {a : α} {l₁ l₂ : list α} (h : l₁ ~ l₂) : a ∈ l₁ ↔ a ∈ l₂ := iff.intro (λ m, h.subset m) (λ m, h.symm.subset m) theorem perm.append_right {l₁ l₂ : list α} (t₁ : list α) (p : l₁ ~ l₂) : l₁++t₁ ~ l₂++t₁ := perm.rec_on p (perm.refl ([] ++ t₁)) (λ x l₁ l₂ p₁ r₁, r₁.cons x) (λ x y l, swap x y _) (λ l₁ l₂ l₃ p₁ p₂ r₁ r₂, r₁.trans r₂) theorem perm.append_left {t₁ t₂ : list α} : ∀ (l : list α), t₁ ~ t₂ → l++t₁ ~ l++t₂ | [] p := p | (x::xs) p := (perm.append_left xs p).cons x theorem perm.append {l₁ l₂ t₁ t₂ : list α} (p₁ : l₁ ~ l₂) (p₂ : t₁ ~ t₂) : l₁++t₁ ~ l₂++t₂ := (p₁.append_right t₁).trans (p₂.append_left l₂) theorem perm.append_cons (a : α) {h₁ h₂ t₁ t₂ : list α} (p₁ : h₁ ~ h₂) (p₂ : t₁ ~ t₂) : h₁ ++ a::t₁ ~ h₂ ++ a::t₂ := p₁.append (p₂.cons a) @[simp] theorem perm_middle {a : α} : ∀ {l₁ l₂ : list α}, l₁++a::l₂ ~ a::(l₁++l₂) | [] l₂ := perm.refl _ | (b::l₁) l₂ := ((@perm_middle l₁ l₂).cons _).trans (swap a b _) @[simp] theorem perm_append_singleton (a : α) (l : list α) : l ++ [a] ~ a::l := perm_middle.trans $ by rw [append_nil] theorem perm_append_comm : ∀ {l₁ l₂ : list α}, (l₁++l₂) ~ (l₂++l₁) | [] l₂ := by simp | (a::t) l₂ := (perm_append_comm.cons _).trans perm_middle.symm theorem concat_perm (l : list α) (a : α) : concat l a ~ a :: l := by simp theorem perm.length_eq {l₁ l₂ : list α} (p : l₁ ~ l₂) : length l₁ = length l₂ := perm.rec_on p rfl (λ x l₁ l₂ p r, by simp[r]) (λ x y l, by simp) (λ l₁ l₂ l₃ p₁ p₂ r₁ r₂, eq.trans r₁ r₂) theorem perm.eq_nil {l : list α} (p : l ~ []) : l = [] := eq_nil_of_length_eq_zero p.length_eq theorem perm.nil_eq {l : list α} (p : [] ~ l) : [] = l := p.symm.eq_nil.symm @[simp] theorem perm_nil {l₁ : list α} : l₁ ~ [] ↔ l₁ = [] := ⟨λ p, p.eq_nil, λ e, e ▸ perm.refl _⟩ @[simp] theorem nil_perm {l₁ : list α} : [] ~ l₁ ↔ l₁ = [] := perm_comm.trans perm_nil theorem not_perm_nil_cons (x : α) (l : list α) : ¬ [] ~ x::l | p := by injection p.symm.eq_nil @[simp] theorem reverse_perm : ∀ (l : list α), reverse l ~ l | [] := perm.nil | (a::l) := by { rw reverse_cons, exact (perm_append_singleton _ _).trans ((reverse_perm l).cons a) } theorem perm_cons_append_cons {l l₁ l₂ : list α} (a : α) (p : l ~ l₁++l₂) : a::l ~ l₁++(a::l₂) := (p.cons a).trans perm_middle.symm @[simp] theorem perm_repeat {a : α} {n : ℕ} {l : list α} : l ~ repeat a n ↔ l = repeat a n := ⟨λ p, (eq_repeat.2 ⟨p.length_eq.trans $ length_repeat _ _, λ b m, eq_of_mem_repeat $ p.subset m⟩), λ h, h ▸ perm.refl _⟩ @[simp] theorem repeat_perm {a : α} {n : ℕ} {l : list α} : repeat a n ~ l ↔ repeat a n = l := (perm_comm.trans perm_repeat).trans eq_comm @[simp] theorem perm_singleton {a : α} {l : list α} : l ~ [a] ↔ l = [a] := @perm_repeat α a 1 l @[simp] theorem singleton_perm {a : α} {l : list α} : [a] ~ l ↔ [a] = l := @repeat_perm α a 1 l theorem perm.eq_singleton {a : α} {l : list α} (p : l ~ [a]) : l = [a] := perm_singleton.1 p theorem perm.singleton_eq {a : α} {l : list α} (p : [a] ~ l) : [a] = l := p.symm.eq_singleton.symm theorem singleton_perm_singleton {a b : α} : [a] ~ [b] ↔ a = b := by simp theorem perm_cons_erase [decidable_eq α] {a : α} {l : list α} (h : a ∈ l) : l ~ a :: l.erase a := let ⟨l₁, l₂, _, e₁, e₂⟩ := exists_erase_eq h in e₂.symm ▸ e₁.symm ▸ perm_middle @[elab_as_eliminator] theorem perm_induction_on {P : list α → list α → Prop} {l₁ l₂ : list α} (p : l₁ ~ l₂) (h₁ : P [] []) (h₂ : ∀ x l₁ l₂, l₁ ~ l₂ → P l₁ l₂ → P (x::l₁) (x::l₂)) (h₃ : ∀ x y l₁ l₂, l₁ ~ l₂ → P l₁ l₂ → P (y::x::l₁) (x::y::l₂)) (h₄ : ∀ l₁ l₂ l₃, l₁ ~ l₂ → l₂ ~ l₃ → P l₁ l₂ → P l₂ l₃ → P l₁ l₃) : P l₁ l₂ := have P_refl : ∀ l, P l l, from assume l, list.rec_on l h₁ (λ x xs ih, h₂ x xs xs (perm.refl xs) ih), perm.rec_on p h₁ h₂ (λ x y l, h₃ x y l l (perm.refl l) (P_refl l)) h₄ @[congr] theorem perm.filter_map (f : α → option β) {l₁ l₂ : list α} (p : l₁ ~ l₂) : filter_map f l₁ ~ filter_map f l₂ := begin induction p with x l₂ l₂' p IH x y l₂ l₂ m₂ r₂ p₁ p₂ IH₁ IH₂, { simp }, { simp only [filter_map], cases f x with a; simp [filter_map, IH, perm.cons] }, { simp only [filter_map], cases f x with a; cases f y with b; simp [filter_map, swap] }, { exact IH₁.trans IH₂ } end @[congr] theorem perm.map (f : α → β) {l₁ l₂ : list α} (p : l₁ ~ l₂) : map f l₁ ~ map f l₂ := filter_map_eq_map f ▸ p.filter_map _ theorem perm.pmap {p : α → Prop} (f : Π a, p a → β) {l₁ l₂ : list α} (p : l₁ ~ l₂) {H₁ H₂} : pmap f l₁ H₁ ~ pmap f l₂ H₂ := begin induction p with x l₂ l₂' p IH x y l₂ l₂ m₂ r₂ p₁ p₂ IH₁ IH₂, { simp }, { simp [IH, perm.cons] }, { simp [swap] }, { refine IH₁.trans IH₂, exact λ a m, H₂ a (p₂.subset m) } end theorem perm.filter (p : α → Prop) [decidable_pred p] {l₁ l₂ : list α} (s : l₁ ~ l₂) : filter p l₁ ~ filter p l₂ := by rw ← filter_map_eq_filter; apply s.filter_map _ theorem exists_perm_sublist {l₁ l₂ l₂' : list α} (s : l₁ <+ l₂) (p : l₂ ~ l₂') : ∃ l₁' ~ l₁, l₁' <+ l₂' := begin induction p with x l₂ l₂' p IH x y l₂ l₂ m₂ r₂ p₁ p₂ IH₁ IH₂ generalizing l₁ s, { exact ⟨[], eq_nil_of_sublist_nil s ▸ perm.refl _, nil_sublist _⟩ }, { cases s with _ _ _ s l₁ _ _ s, { exact let ⟨l₁', p', s'⟩ := IH s in ⟨l₁', p', s'.cons _ _ _⟩ }, { exact let ⟨l₁', p', s'⟩ := IH s in ⟨x::l₁', p'.cons x, s'.cons2 _ _ _⟩ } }, { cases s with _ _ _ s l₁ _ _ s; cases s with _ _ _ s l₁ _ _ s, { exact ⟨l₁, perm.refl _, (s.cons _ _ _).cons _ _ _⟩ }, { exact ⟨x::l₁, perm.refl _, (s.cons _ _ _).cons2 _ _ _⟩ }, { exact ⟨y::l₁, perm.refl _, (s.cons2 _ _ _).cons _ _ _⟩ }, { exact ⟨x::y::l₁, perm.swap _ _ _, (s.cons2 _ _ _).cons2 _ _ _⟩ } }, { exact let ⟨m₁, pm, sm⟩ := IH₁ s, ⟨r₁, pr, sr⟩ := IH₂ sm in ⟨r₁, pr.trans pm, sr⟩ } end theorem perm.sizeof_eq_sizeof [has_sizeof α] {l₁ l₂ : list α} (h : l₁ ~ l₂) : l₁.sizeof = l₂.sizeof := begin induction h with hd l₁ l₂ h₁₂ h_sz₁₂ a b l l₁ l₂ l₃ h₁₂ h₂₃ h_sz₁₂ h_sz₂₃, { refl }, { simp only [list.sizeof, h_sz₁₂] }, { simp only [list.sizeof, add_left_comm] }, { simp only [h_sz₁₂, h_sz₂₃] } end section rel open relator variables {γ : Type*} {δ : Type*} {r : α → β → Prop} {p : γ → δ → Prop} local infixr ` ∘r ` : 80 := relation.comp lemma perm_comp_perm : (perm ∘r perm : list α → list α → Prop) = perm := begin funext a c, apply propext, split, { exact assume ⟨b, hab, hba⟩, perm.trans hab hba }, { exact assume h, ⟨a, perm.refl a, h⟩ } end lemma perm_comp_forall₂ {l u v} (hlu : perm l u) (huv : forall₂ r u v) : (forall₂ r ∘r perm) l v := begin induction hlu generalizing v, case perm.nil { cases huv, exact ⟨[], forall₂.nil, perm.nil⟩ }, case perm.cons : a l u hlu ih { cases huv with _ b _ v hab huv', rcases ih huv' with ⟨l₂, h₁₂, h₂₃⟩, exact ⟨b::l₂, forall₂.cons hab h₁₂, h₂₃.cons _⟩ }, case perm.swap : a₁ a₂ l₁ l₂ h₂₃ { cases h₂₃ with _ b₁ _ l₂ h₁ hr_₂₃, cases hr_₂₃ with _ b₂ _ l₂ h₂ h₁₂, exact ⟨b₂::b₁::l₂, forall₂.cons h₂ (forall₂.cons h₁ h₁₂), perm.swap _ _ _⟩ }, case perm.trans : la₁ la₂ la₃ _ _ ih₁ ih₂ { rcases ih₂ huv with ⟨lb₂, hab₂, h₂₃⟩, rcases ih₁ hab₂ with ⟨lb₁, hab₁, h₁₂⟩, exact ⟨lb₁, hab₁, perm.trans h₁₂ h₂₃⟩ } end lemma forall₂_comp_perm_eq_perm_comp_forall₂ : forall₂ r ∘r perm = perm ∘r forall₂ r := begin funext l₁ l₃, apply propext, split, { assume h, rcases h with ⟨l₂, h₁₂, h₂₃⟩, have : forall₂ (flip r) l₂ l₁, from h₁₂.flip , rcases perm_comp_forall₂ h₂₃.symm this with ⟨l', h₁, h₂⟩, exact ⟨l', h₂.symm, h₁.flip⟩ }, { exact assume ⟨l₂, h₁₂, h₂₃⟩, perm_comp_forall₂ h₁₂ h₂₃ } end lemma rel_perm_imp (hr : right_unique r) : (forall₂ r ⇒ forall₂ r ⇒ implies) perm perm := assume a b h₁ c d h₂ h, have (flip (forall₂ r) ∘r (perm ∘r forall₂ r)) b d, from ⟨a, h₁, c, h, h₂⟩, have ((flip (forall₂ r) ∘r forall₂ r) ∘r perm) b d, by rwa [← forall₂_comp_perm_eq_perm_comp_forall₂, ← relation.comp_assoc] at this, let ⟨b', ⟨c', hbc, hcb⟩, hbd⟩ := this in have b' = b, from right_unique_forall₂' hr hcb hbc, this ▸ hbd lemma rel_perm (hr : bi_unique r) : (forall₂ r ⇒ forall₂ r ⇒ (↔)) perm perm := assume a b hab c d hcd, iff.intro (rel_perm_imp hr.2 hab hcd) (rel_perm_imp hr.left.flip hab.flip hcd.flip) end rel section subperm /-- `subperm l₁ l₂`, denoted `l₁ <+~ l₂`, means that `l₁` is a sublist of a permutation of `l₂`. This is an analogue of `l₁ ⊆ l₂` which respects multiplicities of elements, and is used for the `≤` relation on multisets. -/ def subperm (l₁ l₂ : list α) : Prop := ∃ l ~ l₁, l <+ l₂ infix ` <+~ `:50 := subperm theorem nil_subperm {l : list α} : [] <+~ l := ⟨[], perm.nil, by simp⟩ theorem perm.subperm_left {l l₁ l₂ : list α} (p : l₁ ~ l₂) : l <+~ l₁ ↔ l <+~ l₂ := suffices ∀ {l₁ l₂ : list α}, l₁ ~ l₂ → l <+~ l₁ → l <+~ l₂, from ⟨this p, this p.symm⟩, λ l₁ l₂ p ⟨u, pu, su⟩, let ⟨v, pv, sv⟩ := exists_perm_sublist su p in ⟨v, pv.trans pu, sv⟩ theorem perm.subperm_right {l₁ l₂ l : list α} (p : l₁ ~ l₂) : l₁ <+~ l ↔ l₂ <+~ l := ⟨λ ⟨u, pu, su⟩, ⟨u, pu.trans p, su⟩, λ ⟨u, pu, su⟩, ⟨u, pu.trans p.symm, su⟩⟩ theorem sublist.subperm {l₁ l₂ : list α} (s : l₁ <+ l₂) : l₁ <+~ l₂ := ⟨l₁, perm.refl _, s⟩ theorem perm.subperm {l₁ l₂ : list α} (p : l₁ ~ l₂) : l₁ <+~ l₂ := ⟨l₂, p.symm, sublist.refl _⟩ @[refl] theorem subperm.refl (l : list α) : l <+~ l := (perm.refl _).subperm @[trans] theorem subperm.trans {l₁ l₂ l₃ : list α} : l₁ <+~ l₂ → l₂ <+~ l₃ → l₁ <+~ l₃ | s ⟨l₂', p₂, s₂⟩ := let ⟨l₁', p₁, s₁⟩ := p₂.subperm_left.2 s in ⟨l₁', p₁, s₁.trans s₂⟩ theorem subperm.length_le {l₁ l₂ : list α} : l₁ <+~ l₂ → length l₁ ≤ length l₂ | ⟨l, p, s⟩ := p.length_eq ▸ length_le_of_sublist s theorem subperm.perm_of_length_le {l₁ l₂ : list α} : l₁ <+~ l₂ → length l₂ ≤ length l₁ → l₁ ~ l₂ | ⟨l, p, s⟩ h := suffices l = l₂, from this ▸ p.symm, eq_of_sublist_of_length_le s $ p.symm.length_eq ▸ h theorem subperm.antisymm {l₁ l₂ : list α} (h₁ : l₁ <+~ l₂) (h₂ : l₂ <+~ l₁) : l₁ ~ l₂ := h₁.perm_of_length_le h₂.length_le theorem subperm.subset {l₁ l₂ : list α} : l₁ <+~ l₂ → l₁ ⊆ l₂ | ⟨l, p, s⟩ := subset.trans p.symm.subset s.subset lemma subperm.filter (p : α → Prop) [decidable_pred p] ⦃l l' : list α⦄ (h : l <+~ l') : filter p l <+~ filter p l' := begin obtain ⟨xs, hp, h⟩ := h, exact ⟨_, hp.filter p, h.filter p⟩ end end subperm theorem sublist.exists_perm_append : ∀ {l₁ l₂ : list α}, l₁ <+ l₂ → ∃ l, l₂ ~ l₁ ++ l | ._ ._ sublist.slnil := ⟨nil, perm.refl _⟩ | ._ ._ (sublist.cons l₁ l₂ a s) := let ⟨l, p⟩ := sublist.exists_perm_append s in ⟨a::l, (p.cons a).trans perm_middle.symm⟩ | ._ ._ (sublist.cons2 l₁ l₂ a s) := let ⟨l, p⟩ := sublist.exists_perm_append s in ⟨l, p.cons a⟩ theorem perm.countp_eq (p : α → Prop) [decidable_pred p] {l₁ l₂ : list α} (s : l₁ ~ l₂) : countp p l₁ = countp p l₂ := by rw [countp_eq_length_filter, countp_eq_length_filter]; exact (s.filter _).length_eq theorem subperm.countp_le (p : α → Prop) [decidable_pred p] {l₁ l₂ : list α} : l₁ <+~ l₂ → countp p l₁ ≤ countp p l₂ | ⟨l, p', s⟩ := p'.countp_eq p ▸ countp_le_of_sublist p s theorem perm.count_eq [decidable_eq α] {l₁ l₂ : list α} (p : l₁ ~ l₂) (a) : count a l₁ = count a l₂ := p.countp_eq _ theorem subperm.count_le [decidable_eq α] {l₁ l₂ : list α} (s : l₁ <+~ l₂) (a) : count a l₁ ≤ count a l₂ := s.countp_le _ theorem perm.foldl_eq' {f : β → α → β} {l₁ l₂ : list α} (p : l₁ ~ l₂) : (∀ (x ∈ l₁) (y ∈ l₁) z, f (f z x) y = f (f z y) x) → ∀ b, foldl f b l₁ = foldl f b l₂ := perm_induction_on p (λ H b, rfl) (λ x t₁ t₂ p r H b, r (λ x hx y hy, H _ (or.inr hx) _ (or.inr hy)) _) (λ x y t₁ t₂ p r H b, begin simp only [foldl], rw [H x (or.inr $ or.inl rfl) y (or.inl rfl)], exact r (λ x hx y hy, H _ (or.inr $ or.inr hx) _ (or.inr $ or.inr hy)) _ end) (λ t₁ t₂ t₃ p₁ p₂ r₁ r₂ H b, eq.trans (r₁ H b) (r₂ (λ x hx y hy, H _ (p₁.symm.subset hx) _ (p₁.symm.subset hy)) b)) theorem perm.foldl_eq {f : β → α → β} {l₁ l₂ : list α} (rcomm : right_commutative f) (p : l₁ ~ l₂) : ∀ b, foldl f b l₁ = foldl f b l₂ := p.foldl_eq' $ λ x hx y hy z, rcomm z x y theorem perm.foldr_eq {f : α → β → β} {l₁ l₂ : list α} (lcomm : left_commutative f) (p : l₁ ~ l₂) : ∀ b, foldr f b l₁ = foldr f b l₂ := perm_induction_on p (λ b, rfl) (λ x t₁ t₂ p r b, by simp; rw [r b]) (λ x y t₁ t₂ p r b, by simp; rw [lcomm, r b]) (λ t₁ t₂ t₃ p₁ p₂ r₁ r₂ a, eq.trans (r₁ a) (r₂ a)) lemma perm.rec_heq {β : list α → Sort*} {f : Πa l, β l → β (a::l)} {b : β []} {l l' : list α} (hl : perm l l') (f_congr : ∀{a l l' b b'}, perm l l' → b == b' → f a l b == f a l' b') (f_swap : ∀{a a' l b}, f a (a'::l) (f a' l b) == f a' (a::l) (f a l b)) : @list.rec α β b f l == @list.rec α β b f l' := begin induction hl, case list.perm.nil { refl }, case list.perm.cons : a l l' h ih { exact f_congr h ih }, case list.perm.swap : a a' l { exact f_swap }, case list.perm.trans : l₁ l₂ l₃ h₁ h₂ ih₁ ih₂ { exact heq.trans ih₁ ih₂ } end section variables {op : α → α → α} [is_associative α op] [is_commutative α op] local notation a * b := op a b local notation l <*> a := foldl op a l lemma perm.fold_op_eq {l₁ l₂ : list α} {a : α} (h : l₁ ~ l₂) : l₁ <*> a = l₂ <*> a := h.foldl_eq (right_comm _ is_commutative.comm is_associative.assoc) _ end section comm_monoid /-- If elements of a list commute with each other, then their product does not depend on the order of elements-/ @[to_additive] lemma perm.prod_eq' [monoid α] {l₁ l₂ : list α} (h : l₁ ~ l₂) (hc : l₁.pairwise (λ x y, x * y = y * x)) : l₁.prod = l₂.prod := h.foldl_eq' (forall_of_forall_of_pairwise (λ x y h z, (h z).symm) (λ x hx z, rfl) $ hc.imp $ λ x y h z, by simp only [mul_assoc, h]) _ variable [comm_monoid α] @[to_additive] lemma perm.prod_eq {l₁ l₂ : list α} (h : perm l₁ l₂) : prod l₁ = prod l₂ := h.fold_op_eq @[to_additive] lemma prod_reverse (l : list α) : prod l.reverse = prod l := (reverse_perm l).prod_eq end comm_monoid theorem perm_inv_core {a : α} {l₁ l₂ r₁ r₂ : list α} : l₁++a::r₁ ~ l₂++a::r₂ → l₁++r₁ ~ l₂++r₂ := begin generalize e₁ : l₁++a::r₁ = s₁, generalize e₂ : l₂++a::r₂ = s₂, intro p, revert l₁ l₂ r₁ r₂ e₁ e₂, refine perm_induction_on p _ (λ x t₁ t₂ p IH, _) (λ x y t₁ t₂ p IH, _) (λ t₁ t₂ t₃ p₁ p₂ IH₁ IH₂, _); intros l₁ l₂ r₁ r₂ e₁ e₂, { apply (not_mem_nil a).elim, rw ← e₁, simp }, { cases l₁ with y l₁; cases l₂ with z l₂; dsimp at e₁ e₂; injections; subst x, { substs t₁ t₂, exact p }, { substs z t₁ t₂, exact p.trans perm_middle }, { substs y t₁ t₂, exact perm_middle.symm.trans p }, { substs z t₁ t₂, exact (IH rfl rfl).cons y } }, { rcases l₁ with _|⟨y, _|⟨z, l₁⟩⟩; rcases l₂ with _|⟨u, _|⟨v, l₂⟩⟩; dsimp at e₁ e₂; injections; substs x y, { substs r₁ r₂, exact p.cons a }, { substs r₁ r₂, exact p.cons u }, { substs r₁ v t₂, exact (p.trans perm_middle).cons u }, { substs r₁ r₂, exact p.cons y }, { substs r₁ r₂ y u, exact p.cons a }, { substs r₁ u v t₂, exact ((p.trans perm_middle).cons y).trans (swap _ _ _) }, { substs r₂ z t₁, exact (perm_middle.symm.trans p).cons y }, { substs r₂ y z t₁, exact (swap _ _ _).trans ((perm_middle.symm.trans p).cons u) }, { substs u v t₁ t₂, exact (IH rfl rfl).swap' _ _ } }, { substs t₁ t₃, have : a ∈ t₂ := p₁.subset (by simp), rcases mem_split this with ⟨l₂, r₂, e₂⟩, subst t₂, exact (IH₁ rfl rfl).trans (IH₂ rfl rfl) } end theorem perm.cons_inv {a : α} {l₁ l₂ : list α} : a::l₁ ~ a::l₂ → l₁ ~ l₂ := @perm_inv_core _ _ [] [] _ _ @[simp] theorem perm_cons (a : α) {l₁ l₂ : list α} : a::l₁ ~ a::l₂ ↔ l₁ ~ l₂ := ⟨perm.cons_inv, perm.cons a⟩ theorem perm_append_left_iff {l₁ l₂ : list α} : ∀ l, l++l₁ ~ l++l₂ ↔ l₁ ~ l₂ | [] := iff.rfl | (a::l) := (perm_cons a).trans (perm_append_left_iff l) theorem perm_append_right_iff {l₁ l₂ : list α} (l) : l₁++l ~ l₂++l ↔ l₁ ~ l₂ := ⟨λ p, (perm_append_left_iff _).1 $ perm_append_comm.trans $ p.trans perm_append_comm, perm.append_right _⟩ theorem perm_option_to_list {o₁ o₂ : option α} : o₁.to_list ~ o₂.to_list ↔ o₁ = o₂ := begin refine ⟨λ p, _, λ e, e ▸ perm.refl _⟩, cases o₁ with a; cases o₂ with b, {refl}, { cases p.length_eq }, { cases p.length_eq }, { exact option.mem_to_list.1 (p.symm.subset $ by simp) } end theorem subperm_cons (a : α) {l₁ l₂ : list α} : a::l₁ <+~ a::l₂ ↔ l₁ <+~ l₂ := ⟨λ ⟨l, p, s⟩, begin cases s with _ _ _ s' u _ _ s', { exact (p.subperm_left.2 $ (sublist_cons _ _).subperm).trans s'.subperm }, { exact ⟨u, p.cons_inv, s'⟩ } end, λ ⟨l, p, s⟩, ⟨a::l, p.cons a, s.cons2 _ _ _⟩⟩ theorem cons_subperm_of_mem {a : α} {l₁ l₂ : list α} (d₁ : nodup l₁) (h₁ : a ∉ l₁) (h₂ : a ∈ l₂) (s : l₁ <+~ l₂) : a :: l₁ <+~ l₂ := begin rcases s with ⟨l, p, s⟩, induction s generalizing l₁, case list.sublist.slnil { cases h₂ }, case list.sublist.cons : r₁ r₂ b s' ih { simp at h₂, cases h₂ with e m, { subst b, exact ⟨a::r₁, p.cons a, s'.cons2 _ _ _⟩ }, { rcases ih m d₁ h₁ p with ⟨t, p', s'⟩, exact ⟨t, p', s'.cons _ _ _⟩ } }, case list.sublist.cons2 : r₁ r₂ b s' ih { have bm : b ∈ l₁ := (p.subset $ mem_cons_self _ _), have am : a ∈ r₂ := h₂.resolve_left (λ e, h₁ $ e.symm ▸ bm), rcases mem_split bm with ⟨t₁, t₂, rfl⟩, have st : t₁ ++ t₂ <+ t₁ ++ b :: t₂ := by simp, rcases ih am (nodup_of_sublist st d₁) (mt (λ x, st.subset x) h₁) (perm.cons_inv $ p.trans perm_middle) with ⟨t, p', s'⟩, exact ⟨b::t, (p'.cons b).trans $ (swap _ _ _).trans (perm_middle.symm.cons a), s'.cons2 _ _ _⟩ } end theorem subperm_append_left {l₁ l₂ : list α} : ∀ l, l++l₁ <+~ l++l₂ ↔ l₁ <+~ l₂ | [] := iff.rfl | (a::l) := (subperm_cons a).trans (subperm_append_left l) theorem subperm_append_right {l₁ l₂ : list α} (l) : l₁++l <+~ l₂++l ↔ l₁ <+~ l₂ := (perm_append_comm.subperm_left.trans perm_append_comm.subperm_right).trans (subperm_append_left l) theorem subperm.exists_of_length_lt {l₁ l₂ : list α} : l₁ <+~ l₂ → length l₁ < length l₂ → ∃ a, a :: l₁ <+~ l₂ | ⟨l, p, s⟩ h := suffices length l < length l₂ → ∃ (a : α), a :: l <+~ l₂, from (this $ p.symm.length_eq ▸ h).imp (λ a, (p.cons a).subperm_right.1), begin clear subperm.exists_of_length_lt p h l₁, rename l₂ u, induction s with l₁ l₂ a s IH _ _ b s IH; intro h, { cases h }, { cases lt_or_eq_of_le (nat.le_of_lt_succ h : length l₁ ≤ length l₂) with h h, { exact (IH h).imp (λ a s, s.trans (sublist_cons _ _).subperm) }, { exact ⟨a, eq_of_sublist_of_length_eq s h ▸ subperm.refl _⟩ } }, { exact (IH $ nat.lt_of_succ_lt_succ h).imp (λ a s, (swap _ _ _).subperm_right.1 $ (subperm_cons _).2 s) } end theorem subperm_of_subset_nodup {l₁ l₂ : list α} (d : nodup l₁) (H : l₁ ⊆ l₂) : l₁ <+~ l₂ := begin induction d with a l₁' h d IH, { exact ⟨nil, perm.nil, nil_sublist _⟩ }, { cases forall_mem_cons.1 H with H₁ H₂, simp at h, exact cons_subperm_of_mem d h H₁ (IH H₂) } end theorem perm_ext {l₁ l₂ : list α} (d₁ : nodup l₁) (d₂ : nodup l₂) : l₁ ~ l₂ ↔ ∀a, a ∈ l₁ ↔ a ∈ l₂ := ⟨λ p a, p.mem_iff, λ H, subperm.antisymm (subperm_of_subset_nodup d₁ (λ a, (H a).1)) (subperm_of_subset_nodup d₂ (λ a, (H a).2))⟩ theorem nodup.sublist_ext {l₁ l₂ l : list α} (d : nodup l) (s₁ : l₁ <+ l) (s₂ : l₂ <+ l) : l₁ ~ l₂ ↔ l₁ = l₂ := ⟨λ h, begin induction s₂ with l₂ l a s₂ IH l₂ l a s₂ IH generalizing l₁, { exact h.eq_nil }, { simp at d, cases s₁ with _ _ _ s₁ l₁ _ _ s₁, { exact IH d.2 s₁ h }, { apply d.1.elim, exact subperm.subset ⟨_, h.symm, s₂⟩ (mem_cons_self _ _) } }, { simp at d, cases s₁ with _ _ _ s₁ l₁ _ _ s₁, { apply d.1.elim, exact subperm.subset ⟨_, h, s₁⟩ (mem_cons_self _ _) }, { rw IH d.2 s₁ h.cons_inv } } end, λ h, by rw h⟩ section variable [decidable_eq α] -- attribute [congr] theorem perm.erase (a : α) {l₁ l₂ : list α} (p : l₁ ~ l₂) : l₁.erase a ~ l₂.erase a := if h₁ : a ∈ l₁ then have h₂ : a ∈ l₂, from p.subset h₁, perm.cons_inv $ (perm_cons_erase h₁).symm.trans $ p.trans (perm_cons_erase h₂) else have h₂ : a ∉ l₂, from mt p.mem_iff.2 h₁, by rw [erase_of_not_mem h₁, erase_of_not_mem h₂]; exact p theorem subperm_cons_erase (a : α) (l : list α) : l <+~ a :: l.erase a := begin by_cases h : a ∈ l, { exact (perm_cons_erase h).subperm }, { rw [erase_of_not_mem h], exact (sublist_cons _ _).subperm } end theorem erase_subperm (a : α) (l : list α) : l.erase a <+~ l := (erase_sublist _ _).subperm theorem subperm.erase {l₁ l₂ : list α} (a : α) (h : l₁ <+~ l₂) : l₁.erase a <+~ l₂.erase a := let ⟨l, hp, hs⟩ := h in ⟨l.erase a, hp.erase _, hs.erase _⟩ theorem perm.diff_right {l₁ l₂ : list α} (t : list α) (h : l₁ ~ l₂) : l₁.diff t ~ l₂.diff t := by induction t generalizing l₁ l₂ h; simp [*, perm.erase] theorem perm.diff_left (l : list α) {t₁ t₂ : list α} (h : t₁ ~ t₂) : l.diff t₁ = l.diff t₂ := by induction h generalizing l; simp [*, perm.erase, erase_comm] <|> exact (ih_1 _).trans (ih_2 _) theorem perm.diff {l₁ l₂ t₁ t₂ : list α} (hl : l₁ ~ l₂) (ht : t₁ ~ t₂) : l₁.diff t₁ ~ l₂.diff t₂ := ht.diff_left l₂ ▸ hl.diff_right _ theorem subperm.diff_right {l₁ l₂ : list α} (h : l₁ <+~ l₂) (t : list α) : l₁.diff t <+~ l₂.diff t := by induction t generalizing l₁ l₂ h; simp [*, subperm.erase] theorem erase_cons_subperm_cons_erase (a b : α) (l : list α) : (a :: l).erase b <+~ a :: l.erase b := begin by_cases h : a = b, { subst b, rw [erase_cons_head], apply subperm_cons_erase }, { rw [erase_cons_tail _ h] } end theorem subperm_cons_diff {a : α} : ∀ {l₁ l₂ : list α}, (a :: l₁).diff l₂ <+~ a :: l₁.diff l₂ | l₁ [] := ⟨a::l₁, by simp⟩ | l₁ (b::l₂) := begin simp only [diff_cons], refine ((erase_cons_subperm_cons_erase a b l₁).diff_right l₂).trans _, apply subperm_cons_diff end theorem subset_cons_diff {a : α} {l₁ l₂ : list α} : (a :: l₁).diff l₂ ⊆ a :: l₁.diff l₂ := subperm_cons_diff.subset theorem perm.bag_inter_right {l₁ l₂ : list α} (t : list α) (h : l₁ ~ l₂) : l₁.bag_inter t ~ l₂.bag_inter t := begin induction h with x _ _ _ _ x y _ _ _ _ _ _ ih_1 ih_2 generalizing t, {simp}, { by_cases x ∈ t; simp [*, perm.cons] }, { by_cases x = y, {simp [h]}, by_cases xt : x ∈ t; by_cases yt : y ∈ t, { simp [xt, yt, mem_erase_of_ne h, mem_erase_of_ne (ne.symm h), erase_comm, swap] }, { simp [xt, yt, mt mem_of_mem_erase, perm.cons] }, { simp [xt, yt, mt mem_of_mem_erase, perm.cons] }, { simp [xt, yt] } }, { exact (ih_1 _).trans (ih_2 _) } end theorem perm.bag_inter_left (l : list α) {t₁ t₂ : list α} (p : t₁ ~ t₂) : l.bag_inter t₁ = l.bag_inter t₂ := begin induction l with a l IH generalizing t₁ t₂ p, {simp}, by_cases a ∈ t₁, { simp [h, p.subset h, IH (p.erase _)] }, { simp [h, mt p.mem_iff.2 h, IH p] } end theorem perm.bag_inter {l₁ l₂ t₁ t₂ : list α} (hl : l₁ ~ l₂) (ht : t₁ ~ t₂) : l₁.bag_inter t₁ ~ l₂.bag_inter t₂ := ht.bag_inter_left l₂ ▸ hl.bag_inter_right _ theorem cons_perm_iff_perm_erase {a : α} {l₁ l₂ : list α} : a::l₁ ~ l₂ ↔ a ∈ l₂ ∧ l₁ ~ l₂.erase a := ⟨λ h, have a ∈ l₂, from h.subset (mem_cons_self a l₁), ⟨this, (h.trans $ perm_cons_erase this).cons_inv⟩, λ ⟨m, h⟩, (h.cons a).trans (perm_cons_erase m).symm⟩ theorem perm_iff_count {l₁ l₂ : list α} : l₁ ~ l₂ ↔ ∀ a, count a l₁ = count a l₂ := ⟨perm.count_eq, λ H, begin induction l₁ with a l₁ IH generalizing l₂, { cases l₂ with b l₂, {refl}, specialize H b, simp at H, contradiction }, { have : a ∈ l₂ := count_pos.1 (by rw ← H; simp; apply nat.succ_pos), refine ((IH $ λ b, _).cons a).trans (perm_cons_erase this).symm, specialize H b, rw (perm_cons_erase this).count_eq at H, by_cases b = a; simp [h] at H ⊢; assumption } end⟩ lemma subperm.cons_right {α : Type*} {l l' : list α} (x : α) (h : l <+~ l') : l <+~ x :: l' := h.trans (sublist_cons x l').subperm /-- The list version of `multiset.add_sub_of_le`. -/ lemma subperm_append_diff_self_of_count_le {l₁ l₂ : list α} (h : ∀ x ∈ l₁, count x l₁ ≤ count x l₂) : l₁ ++ l₂.diff l₁ ~ l₂ := begin induction l₁ with hd tl IH generalizing l₂, { simp }, { have : hd ∈ l₂, { rw ←count_pos, exact lt_of_lt_of_le (count_pos.mpr (mem_cons_self _ _)) (h hd (mem_cons_self _ _)) }, replace this : l₂ ~ hd :: l₂.erase hd := perm_cons_erase this, refine perm.trans _ this.symm, rw [cons_append, diff_cons, perm_cons], refine IH (λ x hx, _), specialize h x (mem_cons_of_mem _ hx), rw (perm_iff_count.mp this) at h, by_cases hx : x = hd, { subst hd, simpa [nat.succ_le_succ_iff] using h }, { simpa [hx] using h } }, end /-- The list version of `multiset.le_iff_count`. -/ lemma subperm_ext_iff {l₁ l₂ : list α} : l₁ <+~ l₂ ↔ ∀ x ∈ l₁, count x l₁ ≤ count x l₂ := begin refine ⟨λ h x hx, subperm.count_le h x, λ h, _⟩, suffices : l₁ <+~ (l₂.diff l₁ ++ l₁), { refine this.trans (perm.subperm _), exact perm_append_comm.trans (subperm_append_diff_self_of_count_le h) }, convert (subperm_append_right _).mpr nil_subperm using 1 end lemma subperm.cons_left {l₁ l₂ : list α} (h : l₁ <+~ l₂) (x : α) (hx : count x l₁ < count x l₂) : x :: l₁ <+~ l₂ := begin rw subperm_ext_iff at h ⊢, intros y hy, by_cases hy' : y = x, { subst x, simpa using nat.succ_le_of_lt hx }, { rw count_cons_of_ne hy', refine h y _, simpa [hy'] using hy } end instance decidable_perm : ∀ (l₁ l₂ : list α), decidable (l₁ ~ l₂) | [] [] := is_true $ perm.refl _ | [] (b::l₂) := is_false $ λ h, by have := h.nil_eq; contradiction | (a::l₁) l₂ := by haveI := decidable_perm l₁ (l₂.erase a); exact decidable_of_iff' _ cons_perm_iff_perm_erase -- @[congr] theorem perm.erase_dup {l₁ l₂ : list α} (p : l₁ ~ l₂) : erase_dup l₁ ~ erase_dup l₂ := perm_iff_count.2 $ λ a, if h : a ∈ l₁ then by simp [nodup_erase_dup, h, p.subset h] else by simp [h, mt p.mem_iff.2 h] -- attribute [congr] theorem perm.insert (a : α) {l₁ l₂ : list α} (p : l₁ ~ l₂) : insert a l₁ ~ insert a l₂ := if h : a ∈ l₁ then by simpa [h, p.subset h] using p else by simpa [h, mt p.mem_iff.2 h] using p.cons a theorem perm_insert_swap (x y : α) (l : list α) : insert x (insert y l) ~ insert y (insert x l) := begin by_cases xl : x ∈ l; by_cases yl : y ∈ l; simp [xl, yl], by_cases xy : x = y, { simp [xy] }, simp [not_mem_cons_of_ne_of_not_mem xy xl, not_mem_cons_of_ne_of_not_mem (ne.symm xy) yl], constructor end theorem perm_insert_nth {α} (x : α) (l : list α) {n} (h : n ≤ l.length) : insert_nth n x l ~ x :: l := begin induction l generalizing n, { cases n, refl, cases h }, cases n, { simp [insert_nth] }, { simp only [insert_nth, modify_nth_tail], transitivity, { apply perm.cons, apply l_ih, apply nat.le_of_succ_le_succ h }, { apply perm.swap } } end theorem perm.union_right {l₁ l₂ : list α} (t₁ : list α) (h : l₁ ~ l₂) : l₁ ∪ t₁ ~ l₂ ∪ t₁ := begin induction h with a _ _ _ ih _ _ _ _ _ _ _ _ ih_1 ih_2; try {simp}, { exact ih.insert a }, { apply perm_insert_swap }, { exact ih_1.trans ih_2 } end theorem perm.union_left (l : list α) {t₁ t₂ : list α} (h : t₁ ~ t₂) : l ∪ t₁ ~ l ∪ t₂ := by induction l; simp [*, perm.insert] -- @[congr] theorem perm.union {l₁ l₂ t₁ t₂ : list α} (p₁ : l₁ ~ l₂) (p₂ : t₁ ~ t₂) : l₁ ∪ t₁ ~ l₂ ∪ t₂ := (p₁.union_right t₁).trans (p₂.union_left l₂) theorem perm.inter_right {l₁ l₂ : list α} (t₁ : list α) : l₁ ~ l₂ → l₁ ∩ t₁ ~ l₂ ∩ t₁ := perm.filter _ theorem perm.inter_left (l : list α) {t₁ t₂ : list α} (p : t₁ ~ t₂) : l ∩ t₁ = l ∩ t₂ := by { dsimp [(∩), list.inter], congr, funext a, rw [p.mem_iff] } -- @[congr] theorem perm.inter {l₁ l₂ t₁ t₂ : list α} (p₁ : l₁ ~ l₂) (p₂ : t₁ ~ t₂) : l₁ ∩ t₁ ~ l₂ ∩ t₂ := p₂.inter_left l₂ ▸ p₁.inter_right t₁ theorem perm.inter_append {l t₁ t₂ : list α} (h : disjoint t₁ t₂) : l ∩ (t₁ ++ t₂) ~ l ∩ t₁ ++ l ∩ t₂ := begin induction l, case list.nil { simp }, case list.cons : x xs l_ih { by_cases h₁ : x ∈ t₁, { have h₂ : x ∉ t₂ := h h₁, simp * }, by_cases h₂ : x ∈ t₂, { simp only [*, inter_cons_of_not_mem, false_or, mem_append, inter_cons_of_mem, not_false_iff], transitivity, { apply perm.cons _ l_ih, }, change [x] ++ xs ∩ t₁ ++ xs ∩ t₂ ~ xs ∩ t₁ ++ ([x] ++ xs ∩ t₂), rw [← list.append_assoc], solve_by_elim [perm.append_right, perm_append_comm] }, { simp * } }, end end theorem perm.pairwise_iff {R : α → α → Prop} (S : symmetric R) : ∀ {l₁ l₂ : list α} (p : l₁ ~ l₂), pairwise R l₁ ↔ pairwise R l₂ := suffices ∀ {l₁ l₂}, l₁ ~ l₂ → pairwise R l₁ → pairwise R l₂, from λ l₁ l₂ p, ⟨this p, this p.symm⟩, λ l₁ l₂ p d, begin induction d with a l₁ h d IH generalizing l₂, { rw ← p.nil_eq, constructor }, { have : a ∈ l₂ := p.subset (mem_cons_self _ _), rcases mem_split this with ⟨s₂, t₂, rfl⟩, have p' := (p.trans perm_middle).cons_inv, refine (pairwise_middle S).2 (pairwise_cons.2 ⟨λ b m, _, IH _ p'⟩), exact h _ (p'.symm.subset m) } end theorem perm.nodup_iff {l₁ l₂ : list α} : l₁ ~ l₂ → (nodup l₁ ↔ nodup l₂) := perm.pairwise_iff $ @ne.symm α theorem perm.bind_right {l₁ l₂ : list α} (f : α → list β) (p : l₁ ~ l₂) : l₁.bind f ~ l₂.bind f := begin induction p with a l₁ l₂ p IH a b l l₁ l₂ l₃ p₁ p₂ IH₁ IH₂, {simp}, { simp, exact IH.append_left _ }, { simp, rw [← append_assoc, ← append_assoc], exact perm_append_comm.append_right _ }, { exact IH₁.trans IH₂ } end theorem perm.bind_left (l : list α) {f g : α → list β} (h : ∀ a, f a ~ g a) : l.bind f ~ l.bind g := by induction l with a l IH; simp; exact (h a).append IH theorem bind_append_perm (l : list α) (f g : α → list β) : l.bind f ++ l.bind g ~ l.bind (λ x, f x ++ g x) := begin induction l with a l IH; simp, refine (perm.trans _ (IH.append_left _)).append_left _, rw [← append_assoc, ← append_assoc], exact perm_append_comm.append_right _ end theorem perm.product_right {l₁ l₂ : list α} (t₁ : list β) (p : l₁ ~ l₂) : product l₁ t₁ ~ product l₂ t₁ := p.bind_right _ theorem perm.product_left (l : list α) {t₁ t₂ : list β} (p : t₁ ~ t₂) : product l t₁ ~ product l t₂ := perm.bind_left _ $ λ a, p.map _ @[congr] theorem perm.product {l₁ l₂ : list α} {t₁ t₂ : list β} (p₁ : l₁ ~ l₂) (p₂ : t₁ ~ t₂) : product l₁ t₁ ~ product l₂ t₂ := (p₁.product_right t₁).trans (p₂.product_left l₂) theorem sublists_cons_perm_append (a : α) (l : list α) : sublists (a :: l) ~ sublists l ++ map (cons a) (sublists l) := begin simp only [sublists, sublists_aux_cons_cons, cons_append, perm_cons], refine (perm.cons _ _).trans perm_middle.symm, induction sublists_aux l cons with b l IH; simp, exact (IH.cons _).trans perm_middle.symm end theorem sublists_perm_sublists' : ∀ l : list α, sublists l ~ sublists' l | [] := perm.refl _ | (a::l) := let IH := sublists_perm_sublists' l in by rw sublists'_cons; exact (sublists_cons_perm_append _ _).trans (IH.append (IH.map _)) theorem revzip_sublists (l : list α) : ∀ l₁ l₂, (l₁, l₂) ∈ revzip l.sublists → l₁ ++ l₂ ~ l := begin rw revzip, apply list.reverse_rec_on l, { intros l₁ l₂ h, simp at h, simp [h] }, { intros l a IH l₁ l₂ h, rw [sublists_concat, reverse_append, zip_append, ← map_reverse, zip_map_right, zip_map_left] at h; [skip, {simp}], simp only [prod.mk.inj_iff, mem_map, mem_append, prod.map_mk, prod.exists] at h, rcases h with ⟨l₁, l₂', h, rfl, rfl⟩ | ⟨l₁', l₂, h, rfl, rfl⟩, { rw ← append_assoc, exact (IH _ _ h).append_right _ }, { rw append_assoc, apply (perm_append_comm.append_left _).trans, rw ← append_assoc, exact (IH _ _ h).append_right _ } } end theorem revzip_sublists' (l : list α) : ∀ l₁ l₂, (l₁, l₂) ∈ revzip l.sublists' → l₁ ++ l₂ ~ l := begin rw revzip, induction l with a l IH; intros l₁ l₂ h, { simp at h, simp [h] }, { rw [sublists'_cons, reverse_append, zip_append, ← map_reverse, zip_map_right, zip_map_left] at h; [simp at h, simp], rcases h with ⟨l₁, l₂', h, rfl, rfl⟩ | ⟨l₁', h, rfl⟩, { exact perm_middle.trans ((IH _ _ h).cons _) }, { exact (IH _ _ h).cons _ } } end theorem perm_lookmap (f : α → option α) {l₁ l₂ : list α} (H : pairwise (λ a b, ∀ (c ∈ f a) (d ∈ f b), a = b ∧ c = d) l₁) (p : l₁ ~ l₂) : lookmap f l₁ ~ lookmap f l₂ := begin let F := λ a b, ∀ (c ∈ f a) (d ∈ f b), a = b ∧ c = d, change pairwise F l₁ at H, induction p with a l₁ l₂ p IH a b l l₁ l₂ l₃ p₁ p₂ IH₁ IH₂, {simp}, { cases h : f a, { simp [h], exact IH (pairwise_cons.1 H).2 }, { simp [lookmap_cons_some _ _ h, p] } }, { cases h₁ : f a with c; cases h₂ : f b with d, { simp [h₁, h₂], apply swap }, { simp [h₁, lookmap_cons_some _ _ h₂], apply swap }, { simp [lookmap_cons_some _ _ h₁, h₂], apply swap }, { simp [lookmap_cons_some _ _ h₁, lookmap_cons_some _ _ h₂], rcases (pairwise_cons.1 H).1 _ (or.inl rfl) _ h₂ _ h₁ with ⟨rfl, rfl⟩, refl } }, { refine (IH₁ H).trans (IH₂ ((p₁.pairwise_iff _).1 H)), exact λ a b h c h₁ d h₂, (h d h₂ c h₁).imp eq.symm eq.symm } end theorem perm.erasep (f : α → Prop) [decidable_pred f] {l₁ l₂ : list α} (H : pairwise (λ a b, f a → f b → false) l₁) (p : l₁ ~ l₂) : erasep f l₁ ~ erasep f l₂ := begin let F := λ a b, f a → f b → false, change pairwise F l₁ at H, induction p with a l₁ l₂ p IH a b l l₁ l₂ l₃ p₁ p₂ IH₁ IH₂, {simp}, { by_cases h : f a, { simp [h, p] }, { simp [h], exact IH (pairwise_cons.1 H).2 } }, { by_cases h₁ : f a; by_cases h₂ : f b; simp [h₁, h₂], { cases (pairwise_cons.1 H).1 _ (or.inl rfl) h₂ h₁ }, { apply swap } }, { refine (IH₁ H).trans (IH₂ ((p₁.pairwise_iff _).1 H)), exact λ a b h h₁ h₂, h h₂ h₁ } end lemma perm.take_inter {α} [decidable_eq α] {xs ys : list α} (n : ℕ) (h : xs ~ ys) (h' : ys.nodup) : xs.take n ~ ys.inter (xs.take n) := begin simp only [list.inter] at *, induction h generalizing n, case list.perm.nil : n { simp only [not_mem_nil, filter_false, take_nil] }, case list.perm.cons : h_x h_l₁ h_l₂ h_a h_ih n { cases n; simp only [mem_cons_iff, true_or, eq_self_iff_true, filter_cons_of_pos, perm_cons, take, not_mem_nil, filter_false], cases h' with _ _ h₁ h₂, convert h_ih h₂ n using 1, apply filter_congr, introv h, simp only [(h₁ x h).symm, false_or], }, case list.perm.swap : h_x h_y h_l n { cases h' with _ _ h₁ h₂, cases h₂ with _ _ h₂ h₃, have := h₁ _ (or.inl rfl), cases n; simp only [mem_cons_iff, not_mem_nil, filter_false, take], cases n; simp only [mem_cons_iff, false_or, true_or, filter, *, nat.nat_zero_eq_zero, if_true, not_mem_nil, eq_self_iff_true, or_false, if_false, perm_cons, take], { rw filter_eq_nil.2, intros, solve_by_elim [ne.symm], }, { convert perm.swap _ _ _, rw @filter_congr _ _ (∈ take n h_l), { clear h₁, induction n generalizing h_l; simp only [not_mem_nil, filter_false, take], cases h_l; simp only [mem_cons_iff, true_or, eq_self_iff_true, filter_cons_of_pos, true_and, take, not_mem_nil, filter_false, take_nil], cases h₃ with _ _ h₃ h₄, rwa [@filter_congr _ _ (∈ take n_n h_l_tl), n_ih], { introv h, apply h₂ _ (or.inr h), }, { introv h, simp only [(h₃ x h).symm, false_or], }, }, { introv h, simp only [(h₂ x h).symm, (h₁ x (or.inr h)).symm, false_or], } } }, case list.perm.trans : h_l₁ h_l₂ h_l₃ h₀ h₁ h_ih₀ h_ih₁ n { transitivity, { apply h_ih₀, rwa h₁.nodup_iff }, { apply perm.filter _ h₁, } }, end lemma perm.drop_inter {α} [decidable_eq α] {xs ys : list α} (n : ℕ) (h : xs ~ ys) (h' : ys.nodup) : xs.drop n ~ ys.inter (xs.drop n) := begin by_cases h'' : n ≤ xs.length, { let n' := xs.length - n, have h₀ : n = xs.length - n', { dsimp [n'], rwa nat.sub_sub_self, } , have h₁ : n' ≤ xs.length, { apply nat.sub_le_self }, have h₂ : xs.drop n = (xs.reverse.take n').reverse, { rw [reverse_take _ h₁, h₀, reverse_reverse], }, rw [h₂], apply (reverse_perm _).trans, rw inter_reverse, apply perm.take_inter _ _ h', apply (reverse_perm _).trans; assumption, }, { have : drop n xs = [], { apply eq_nil_of_length_eq_zero, rw [length_drop, nat.sub_eq_zero_iff_le], apply le_of_not_ge h'' }, simp [this, list.inter], } end lemma perm.slice_inter {α} [decidable_eq α] {xs ys : list α} (n m : ℕ) (h : xs ~ ys) (h' : ys.nodup) : list.slice n m xs ~ ys ∩ (list.slice n m xs) := begin simp only [slice_eq], have : n ≤ n + m := nat.le_add_right _ _, have := h.nodup_iff.2 h', apply perm.trans _ (perm.inter_append _).symm; solve_by_elim [perm.append, perm.drop_inter, perm.take_inter, disjoint_take_drop, h, h'] { max_depth := 7 }, end /- enumerating permutations -/ section permutations theorem perm_of_mem_permutations_aux : ∀ {ts is l : list α}, l ∈ permutations_aux ts is → l ~ ts ++ is := begin refine permutations_aux.rec (by simp) _, introv IH1 IH2 m, rw [permutations_aux_cons, permutations, mem_foldr_permutations_aux2] at m, rcases m with m | ⟨l₁, l₂, m, _, e⟩, { exact (IH1 m).trans perm_middle }, { subst e, have p : l₁ ++ l₂ ~ is, { simp [permutations] at m, cases m with e m, {simp [e]}, exact is.append_nil ▸ IH2 m }, exact ((perm_middle.trans (p.cons _)).append_right _).trans (perm_append_comm.cons _) } end theorem perm_of_mem_permutations {l₁ l₂ : list α} (h : l₁ ∈ permutations l₂) : l₁ ~ l₂ := (eq_or_mem_of_mem_cons h).elim (λ e, e ▸ perm.refl _) (λ m, append_nil l₂ ▸ perm_of_mem_permutations_aux m) theorem length_permutations_aux : ∀ ts is : list α, length (permutations_aux ts is) + is.length! = (length ts + length is)! := begin refine permutations_aux.rec (by simp) _, intros t ts is IH1 IH2, have IH2 : length (permutations_aux is nil) + 1 = is.length!, { simpa using IH2 }, simp [-add_comm, nat.factorial, nat.add_succ, mul_comm] at IH1, rw [permutations_aux_cons, length_foldr_permutations_aux2' _ _ _ _ _ (λ l m, (perm_of_mem_permutations m).length_eq), permutations, length, length, IH2, nat.succ_add, nat.factorial_succ, mul_comm (nat.succ _), ← IH1, add_comm (_*_), add_assoc, nat.mul_succ, mul_comm] end theorem length_permutations (l : list α) : length (permutations l) = (length l)! := length_permutations_aux l [] theorem mem_permutations_of_perm_lemma {is l : list α} (H : l ~ [] ++ is → (∃ ts' ~ [], l = ts' ++ is) ∨ l ∈ permutations_aux is []) : l ~ is → l ∈ permutations is := by simpa [permutations, perm_nil] using H theorem mem_permutations_aux_of_perm : ∀ {ts is l : list α}, l ~ is ++ ts → (∃ is' ~ is, l = is' ++ ts) ∨ l ∈ permutations_aux ts is := begin refine permutations_aux.rec (by simp) _, intros t ts is IH1 IH2 l p, rw [permutations_aux_cons, mem_foldr_permutations_aux2], rcases IH1 (p.trans perm_middle) with ⟨is', p', e⟩ | m, { clear p, subst e, rcases mem_split (p'.symm.subset (mem_cons_self _ _)) with ⟨l₁, l₂, e⟩, subst is', have p := (perm_middle.symm.trans p').cons_inv, cases l₂ with a l₂', { exact or.inl ⟨l₁, by simpa using p⟩ }, { exact or.inr (or.inr ⟨l₁, a::l₂', mem_permutations_of_perm_lemma IH2 p, by simp⟩) } }, { exact or.inr (or.inl m) } end @[simp] theorem mem_permutations {s t : list α} : s ∈ permutations t ↔ s ~ t := ⟨perm_of_mem_permutations, mem_permutations_of_perm_lemma mem_permutations_aux_of_perm⟩ theorem perm_permutations'_aux_comm (a b : α) (l : list α) : (permutations'_aux a l).bind (permutations'_aux b) ~ (permutations'_aux b l).bind (permutations'_aux a) := begin induction l with c l ih, {simp [swap]}, simp [permutations'_aux], apply perm.swap', have : ∀ a b, (map (cons c) (permutations'_aux a l)).bind (permutations'_aux b) ~ map (cons b ∘ cons c) (permutations'_aux a l) ++ map (cons c) ((permutations'_aux a l).bind (permutations'_aux b)), { intros, simp only [map_bind, permutations'_aux], refine (bind_append_perm _ (λ x, [_]) _).symm.trans _, rw [← map_eq_bind, ← bind_map] }, refine (((this _ _).append_left _).trans _).trans ((this _ _).append_left _).symm, rw [← append_assoc, ← append_assoc], exact perm_append_comm.append (ih.map _), end theorem perm.permutations' {s t : list α} (p : s ~ t) : permutations' s ~ permutations' t := begin induction p with a s t p IH a b l s t u p₁ p₂ IH₁ IH₂, {simp}, { simp only [permutations'], exact IH.bind_right _ }, { simp only [permutations'], rw [bind_assoc, bind_assoc], apply perm.bind_left, apply perm_permutations'_aux_comm }, { exact IH₁.trans IH₂ } end theorem permutations_perm_permutations' (ts : list α) : ts.permutations ~ ts.permutations' := begin obtain ⟨n, h⟩ : ∃ n, length ts < n := ⟨_, nat.lt_succ_self _⟩, induction n with n IH generalizing ts, {cases h}, refine list.reverse_rec_on ts (λ h, _) (λ ts t _ h, _) h, {simp [permutations]}, rw [← concat_eq_append, length_concat, nat.succ_lt_succ_iff] at h, have IH₂ := (IH ts.reverse (by rwa [length_reverse])).trans (reverse_perm _).permutations', simp only [permutations_append, foldr_permutations_aux2, permutations_aux_nil, permutations_aux_cons, append_nil], refine (perm_append_comm.trans ((IH₂.bind_right _).append ((IH _ h).map _))).trans (perm.trans _ perm_append_comm.permutations'), rw [map_eq_bind, singleton_append, permutations'], convert bind_append_perm _ _ _, funext ys, rw [permutations'_aux_eq_permutations_aux2, permutations_aux2_append] end @[simp] theorem mem_permutations' {s t : list α} : s ∈ permutations' t ↔ s ~ t := (permutations_perm_permutations' _).symm.mem_iff.trans mem_permutations theorem perm.permutations {s t : list α} (h : s ~ t) : permutations s ~ permutations t := (permutations_perm_permutations' _).trans $ h.permutations'.trans (permutations_perm_permutations' _).symm @[simp] theorem perm_permutations_iff {s t : list α} : permutations s ~ permutations t ↔ s ~ t := ⟨λ h, mem_permutations.1 $ h.mem_iff.1 $ mem_permutations.2 (perm.refl _), perm.permutations⟩ @[simp] theorem perm_permutations'_iff {s t : list α} : permutations' s ~ permutations' t ↔ s ~ t := ⟨λ h, mem_permutations'.1 $ h.mem_iff.1 $ mem_permutations'.2 (perm.refl _), perm.permutations'⟩ lemma nth_le_permutations'_aux (s : list α) (x : α) (n : ℕ) (hn : n < length (permutations'_aux x s)) : (permutations'_aux x s).nth_le n hn = s.insert_nth n x := begin induction s with y s IH generalizing n, { simp only [length, permutations'_aux, nat.lt_one_iff] at hn, simp [hn] }, { cases n, { simp }, { simpa using IH _ _ } } end lemma count_permutations'_aux_self [decidable_eq α] (l : list α) (x : α) : count (x :: l) (permutations'_aux x l) = length (take_while ((=) x) l) + 1 := begin induction l with y l IH generalizing x, { simp [take_while], }, { rw [permutations'_aux, count_cons_self], by_cases hx : x = y, { subst hx, simpa [take_while, nat.succ_inj'] using IH _ }, { rw take_while, rw if_neg hx, cases permutations'_aux x l with a as, { simp }, { rw [count_eq_zero_of_not_mem, length, zero_add], simp [hx, ne.symm hx] } } } end @[simp] lemma length_permutations'_aux (s : list α) (x : α) : length (permutations'_aux x s) = length s + 1 := begin induction s with y s IH, { simp }, { simpa using IH } end @[simp] lemma permutations'_aux_nth_le_zero (s : list α) (x : α) (hn : 0 < length (permutations'_aux x s) := by simp) : (permutations'_aux x s).nth_le 0 hn = x :: s := nth_le_permutations'_aux _ _ _ _ lemma injective_permutations'_aux (x : α) : function.injective (permutations'_aux x) := begin intros s t h, apply insert_nth_injective s.length x, have hl : s.length = t.length := by simpa using congr_arg length h, rw [←nth_le_permutations'_aux s x s.length (by simp), ←nth_le_permutations'_aux t x s.length (by simp [hl])], simp [h, hl] end lemma nodup_permutations'_aux_of_not_mem (s : list α) (x : α) (hx : x ∉ s) : nodup (permutations'_aux x s) := begin induction s with y s IH, { simp }, { simp only [not_or_distrib, mem_cons_iff] at hx, simp only [not_and, exists_eq_right_right, mem_map, permutations'_aux, nodup_cons], refine ⟨λ _, ne.symm hx.left, _⟩, rw nodup_map_iff, { exact IH hx.right }, { simp } } end lemma nodup_permutations'_aux_iff {s : list α} {x : α} : nodup (permutations'_aux x s) ↔ x ∉ s := begin refine ⟨λ h, _, nodup_permutations'_aux_of_not_mem _ _⟩, intro H, obtain ⟨k, hk, hk'⟩ := nth_le_of_mem H, rw nodup_iff_nth_le_inj at h, suffices : k = k + 1, { simpa using this }, refine h k (k + 1) _ _ _, { simpa [nat.lt_succ_iff] using hk.le }, { simpa using hk }, rw [nth_le_permutations'_aux, nth_le_permutations'_aux], have hl : length (insert_nth k x s) = length (insert_nth (k + 1) x s), { rw [length_insert_nth _ _ hk.le, length_insert_nth _ _ (nat.succ_le_of_lt hk)] }, refine ext_le hl (λ n hn hn', _), rcases lt_trichotomy n k with H|rfl|H, { rw [nth_le_insert_nth_of_lt _ _ _ _ H (H.trans hk), nth_le_insert_nth_of_lt _ _ _ _ (H.trans (nat.lt_succ_self _))] }, { rw [nth_le_insert_nth_self _ _ _ hk.le, nth_le_insert_nth_of_lt _ _ _ _ (nat.lt_succ_self _) hk, hk'] }, { rcases (nat.succ_le_of_lt H).eq_or_lt with rfl|H', { rw [nth_le_insert_nth_self _ _ _ (nat.succ_le_of_lt hk)], convert hk' using 1, convert nth_le_insert_nth_add_succ _ _ _ 0 _, simpa using hk }, { obtain ⟨m, rfl⟩ := nat.exists_eq_add_of_lt H', rw [length_insert_nth _ _ hk.le, nat.succ_lt_succ_iff, nat.succ_add] at hn, rw nth_le_insert_nth_add_succ, convert nth_le_insert_nth_add_succ s x k m.succ _ using 2, { simp [nat.add_succ, nat.succ_add] }, { simp [add_left_comm, add_comm] }, { simpa [nat.add_succ] using hn }, { simpa [nat.succ_add] using hn } } } end lemma nodup_permutations (s : list α) (hs : nodup s) : nodup s.permutations := begin rw (permutations_perm_permutations' s).nodup_iff, induction hs with x l h h' IH, { simp }, { rw [permutations'], rw nodup_bind, split, { intros ys hy, rw mem_permutations' at hy, rw [nodup_permutations'_aux_iff, hy.mem_iff], exact λ H, h x H rfl }, { refine IH.pairwise_of_forall_ne (λ as ha bs hb H, _), rw disjoint_iff_ne, rintro a ha' b hb' rfl, obtain ⟨n, hn, hn'⟩ := nth_le_of_mem ha', obtain ⟨m, hm, hm'⟩ := nth_le_of_mem hb', rw mem_permutations' at ha hb, have hl : as.length = bs.length := (ha.trans hb.symm).length_eq, simp only [nat.lt_succ_iff, length_permutations'_aux] at hn hm, rw nth_le_permutations'_aux at hn' hm', have hx : nth_le (insert_nth n x as) m (by rwa [length_insert_nth _ _ hn, nat.lt_succ_iff, hl]) = x, { simp [hn', ←hm', hm] }, have hx' : nth_le (insert_nth m x bs) n (by rwa [length_insert_nth _ _ hm, nat.lt_succ_iff, ←hl]) = x, { simp [hm', ←hn', hn] }, rcases lt_trichotomy n m with ht|ht|ht, { suffices : x ∈ bs, { exact h x (hb.subset this) rfl }, rw [←hx', nth_le_insert_nth_of_lt _ _ _ _ ht (ht.trans_le hm)], exact nth_le_mem _ _ _ }, { simp only [ht] at hm' hn', rw ←hm' at hn', exact H (insert_nth_injective _ _ hn') }, { suffices : x ∈ as, { exact h x (ha.subset this) rfl }, rw [←hx, nth_le_insert_nth_of_lt _ _ _ _ ht (ht.trans_le hn)], exact nth_le_mem _ _ _ } } } end -- TODO: `nodup s.permutations ↔ nodup s` -- TODO: `count s s.permutations = (zip_with count s s.tails).prod` end permutations end list
a673e72ce475925ea8d90447b7d4b02e2de16197
7fc0ec5c526f706107537a6e2e34ac4cdf88d232
/src/group_theory/representation/bilinear_form.lean
9d0a79fd6a829ff2cd6f2a28e33d91868707c8e8
[ "Apache-2.0" ]
permissive
fpvandoorn/group-representations
7440a81f2ac9e0d2defa44dc1643c3167f7a2d99
bd9d72311749187d3bd4f542d5eab83e8341856c
refs/heads/master
1,684,128,141,684
1,623,338,135,000
1,623,338,135,000
256,117,709
0
2
null
null
null
null
UTF-8
Lean
false
false
6,159
lean
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Douglas, Floris van Doorn -/ import .basic /- everything we have done that uses bilinear forms-/ universe variables u v w w' w'' open linear_map variables {G : Type u} {R : Type v} {M : Type w} {M' : Type w'} {M'' : Type w''} [group G] [comm_ring R] [add_comm_group M] [module R M] [add_comm_group M'] [module R M'] [add_comm_group M''] [module R M''] namespace submodule /-- `π` is a projection with as range `N` -/ def is_projection_on_submodule (N : submodule R M) (π : M →ₗ[R] M) : Prop := is_projection π ∧ range π = N def is_orthogonal_projection_on_submodule (B : bilin_form R M) (N : submodule R M) (π : M →ₗ[R] M) : Prop := is_projection_on_submodule N π ∧ ∀ x : M, ∀ y : N, bilin_form.is_ortho B x y → π x = 0 lemma exists_orthogonal_projection_on_submodule (B : bilin_form R M) (N : submodule R M) : ∃ π : M →ₗ[R] M, is_orthogonal_projection_on_submodule B N π := sorry lemma orthogonal_projection_on_submodule_range (B : bilin_form R M) (N : submodule R M) (π : M →ₗ[R] M) : is_projection_on_submodule N π → ∀ x : M, π x ∈ N := begin unfold is_projection_on_submodule, unfold is_projection, intro, sorry, end /-- A bilinear form is nondegenerate if `B x (-)` is the zero function only if `x` is zero. -/ def nondegenerate (B : bilin_form R M) : Prop := ∀ x : M, (∀ y : M, B x y = 0) → x = 0 lemma nondegenerate_bilinear_form_exists : ∃ B : bilin_form R M, nondegenerate B := sorry /- sum over a noncanonical basis - does this require R to be a field ? -/ /- `is_orthogonal B N N'` states that `N` and `N'` are orthogonal w.r.t. bilinear form `B`. -/ def is_orthogonal (B : bilin_form R M) (N N' : submodule R M) : Prop := ∀ x y, x ∈ N → y ∈ N' → bilin_form.is_ortho B x y /- The orthogonal complement of a submodule w.r.t. a bilinear form. -/ @[simps] def orthogonal_complement (B : bilin_form R M) (N : submodule R M) : submodule R M := { carrier := {x:M|∀ y ∈ N, bilin_form.is_ortho B x y}, zero := λ y hy, bilin_form.ortho_zero y, add := λ x y hx hy z hz, begin unfold bilin_form.is_ortho at *, simp [bilin_form.add_left], simp [hx z hz, hy z hz], end, smul := λ r x hx y hy, by { unfold bilin_form.is_ortho at *, rw [bilin_form.smul_left, hx y hy, mul_zero] } } --lemma orthogonal_complement_bijective_to_quotient {B : bilin_form R M} (N : submodule R M) : -- linear_algebra.of_bijective _ _ := sorry lemma orthogonal_projection_on_submodule_coker (B : bilin_form R M) (N : submodule R M) (π : M →ₗ[R] M) : is_projection_on_submodule N π → ∀ x : M, x - π x ∈ orthogonal_complement B N := begin unfold is_projection_on_submodule, unfold is_projection, intro, sorry, end /- A bilinear form is definite if `B x x = 0` only when `x = 0`. -/ def is_definite (B : bilin_form R M) : Prop := ∀ x, B x x = 0 → x = 0 lemma orthogonal_complement_is_complementary (B : bilin_form R M) (N : submodule R M) (hB : is_definite B) : complementary N (orthogonal_complement B N) := begin intros, split, rcases exists_orthogonal_projection_on_submodule B N with ⟨π, hπ⟩, { rw [covering_iff, eq_top_iff'], intro, rw mem_sup, simp, use π x, split, apply orthogonal_projection_on_submodule_range B _ _ hπ.1, use (x - π x), simp [orthogonal_projection_on_submodule_coker, hπ.1] }, { rw [disjoint_def], intros x hx h2x, apply hB, apply h2x, exact hx } end lemma is_orthogonal_orthogonal_complement (B : bilin_form R M) (N : submodule R M) : is_orthogonal B (orthogonal_complement B N) N := by { intros x y hx hy, exact hx y hy } def conjugated_bilinear_form (ρ : group_representation G R M) (B : bilin_form R M) (g : G) : bilin_form R M := B.comp (ρ g) (ρ g) /-- A bilinear form `B` is invariant under a representation `ρ` if `B = B ∘ (ρ g × ρ g)` for all `g`. -/ def is_invariant (ρ : group_representation G R M) (B : bilin_form R M) : Prop := ∀ g : G, B = B.comp (ρ g) (ρ g) /-- The standard bilinear form for a finite group `G`, defined by summing over all group elements. -/ def standard_invariant_bilinear_form [fintype G] (ρ : group_representation G R M) (B : bilin_form R M) : bilin_form R M := finset.univ.sum (λ g : G, B.comp (ρ g) (ρ g)) lemma sum_apply {α} (s : finset α) (f : α → bilin_form R M) (m m' : M) : s.sum f m m' = s.sum (λ x, f x m m') := begin sorry end lemma is_invariant_standard_invariant_bilinear_form [fintype G] (ρ : group_representation G R M) (B : bilin_form R M) : is_invariant ρ (standard_invariant_bilinear_form ρ B) := begin unfold standard_invariant_bilinear_form, intro g1, ext, simp [sum_apply], symmetry, apply finset.sum_bij (λ g _, g * g1), { intros, apply finset.mem_univ }, { intros, apply bilin_form.coe_fn_congr, repeat { dsimp, rw ρ.map_mul, refl } }, { intros g g' _ _ h, simpa using h }, { intros, use b * g1⁻¹, simp } end lemma is_invariant_orthogonal_complement {ρ : group_representation G R M} (B : bilin_form R M) : ∀ N N' : submodule R M, is_invariant ρ B → N.invariant_under ρ → is_orthogonal B N' N → N'.invariant_under ρ := begin unfold is_invariant, unfold invariant_under, unfold is_orthogonal, intros N N' hρ hN hN' x g, dsimp, unfold bilin_form.is_ortho at hN', rw [hρ g] at hN', dsimp at hN', -- at this point hN with hN' imply that ρ g x is in the orthogonal complement. by definition this is N'. sorry end theorem maschke [fintype G] (ρ : group_representation G R M) (B : bilin_form R M) : ∀ N : submodule R M, N.invariant_under ρ → ∃ N' : submodule R M, N'.invariant_under ρ ∧ complementary N N' := begin intros N hN, let std := standard_invariant_bilinear_form ρ B, let N' := orthogonal_complement std N, have h := is_invariant_orthogonal_complement std N N' (is_invariant_standard_invariant_bilinear_form ρ B) hN (is_orthogonal_orthogonal_complement _ _), use N', use h, apply orthogonal_complement_is_complementary, sorry, end end submodule
bf8e8af005974cd063983b8815f39c084f64e249
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/linear_algebra/bilinear_form.lean
aee58fb963f49105022a5f23c59d2c91827c4f36
[ "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
63,014
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.nonsingular_inverse import linear_algebra.matrix.to_lin 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₂ ≃ₗ _) = bilin_form.to_lin := rfl @[simp] lemma bilin_form.to_lin_symm : (bilin_form.to_lin.symm : _ ≃ₗ 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 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*} [fintype n] [fintype o] 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 (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 [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 } 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₃ ≃ₗ _) = matrix.to_bilin' := rfl @[simp] lemma matrix.to_bilin'_symm : (matrix.to_bilin'.symm : _ ≃ₗ 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] 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, exact hm x } end /-- 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_ker_eq_bot (nondegenerate_iff_ker_eq_bot.mp b) 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 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 end bilin_form
2d97702c7f77b40c5207beedd4a143fd2db374c4
4727251e0cd73359b15b664c3170e5d754078599
/src/order/galois_connection.lean
dc208135463b37626b2d448705976124e0e6f5e5
[ "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
31,286
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 order.complete_lattice import order.synonym /-! # Galois connections, insertions and coinsertions Galois connections are order theoretic adjoints, i.e. a pair of functions `u` and `l`, such that `∀ a b, l a ≤ b ↔ a ≤ u b`. ## Main definitions * `galois_connection`: A Galois connection is a pair of functions `l` and `u` satisfying `l a ≤ b ↔ a ≤ u b`. They are special cases of adjoint functors in category theory, but do not depend on the category theory library in mathlib. * `galois_insertion`: A Galois insertion is a Galois connection where `l ∘ u = id` * `galois_coinsertion`: A Galois coinsertion is a Galois connection where `u ∘ l = id` ## Implementation details Galois insertions can be used to lift order structures from one type to another. For example if `α` is a complete lattice, and `l : α → β`, and `u : β → α` form a Galois insertion, then `β` is also a complete lattice. `l` is the lower adjoint and `u` is the upper adjoint. An example of a Galois insertion is in group theory. If `G` is a group, then there is a Galois insertion between the set of subsets of `G`, `set G`, and the set of subgroups of `G`, `subgroup G`. The lower adjoint is `subgroup.closure`, taking the `subgroup` generated by a `set`, and the upper adjoint is the coercion from `subgroup G` to `set G`, taking the underlying set of a subgroup. Naively lifting a lattice structure along this Galois insertion would mean that the definition of `inf` on subgroups would be `subgroup.closure (↑S ∩ ↑T)`. This is an undesirable definition because the intersection of subgroups is already a subgroup, so there is no need to take the closure. For this reason a `choice` function is added as a field to the `galois_insertion` structure. It has type `Π S : set G, ↑(closure S) ≤ S → subgroup G`. When `↑(closure S) ≤ S`, then `S` is already a subgroup, so this function can be defined using `subgroup.mk` and not `closure`. This means the infimum of subgroups will be defined to be the intersection of sets, paired with a proof that intersection of subgroups is a subgroup, rather than the closure of the intersection. -/ open function order_dual set universes u v w x variables {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} {κ : ι → Sort*} {a a₁ a₂ : α} {b b₁ b₂ : β} /-- A Galois connection is a pair of functions `l` and `u` satisfying `l a ≤ b ↔ a ≤ u b`. They are special cases of adjoint functors in category theory, but do not depend on the category theory library in mathlib. -/ def galois_connection [preorder α] [preorder β] (l : α → β) (u : β → α) := ∀ a b, l a ≤ b ↔ a ≤ u b /-- Makes a Galois connection from an order-preserving bijection. -/ theorem order_iso.to_galois_connection [preorder α] [preorder β] (oi : α ≃o β) : galois_connection oi oi.symm := λ b g, oi.rel_symm_apply.symm namespace galois_connection section variables [preorder α] [preorder β] {l : α → β} {u : β → α} (gc : galois_connection l u) lemma monotone_intro (hu : monotone u) (hl : monotone l) (hul : ∀ a, a ≤ u (l a)) (hlu : ∀ a, l (u a) ≤ a) : galois_connection l u := λ a b, ⟨λ h, (hul _).trans (hu h), λ h, (hl h).trans (hlu _)⟩ include gc protected lemma dual {l : α → β} {u : β → α} (gc : galois_connection l u) : galois_connection (order_dual.to_dual ∘ u ∘ order_dual.of_dual) (order_dual.to_dual ∘ l ∘ order_dual.of_dual) := λ a b, (gc b a).symm lemma le_iff_le {a : α} {b : β} : l a ≤ b ↔ a ≤ u b := gc _ _ lemma l_le {a : α} {b : β} : a ≤ u b → l a ≤ b := (gc _ _).mpr lemma le_u {a : α} {b : β} : l a ≤ b → a ≤ u b := (gc _ _).mp lemma le_u_l (a) : a ≤ u (l a) := gc.le_u $ le_rfl lemma l_u_le (a) : l (u a) ≤ a := gc.l_le $ le_rfl lemma monotone_u : monotone u := λ a b H, gc.le_u ((gc.l_u_le a).trans H) lemma monotone_l : monotone l := gc.dual.monotone_u.dual lemma upper_bounds_l_image (s : set α) : upper_bounds (l '' s) = u ⁻¹' upper_bounds s := set.ext $ λ b, by simp [upper_bounds, gc _ _] lemma lower_bounds_u_image (s : set β) : lower_bounds (u '' s) = l ⁻¹' lower_bounds s := gc.dual.upper_bounds_l_image s lemma bdd_above_l_image {s : set α} : bdd_above (l '' s) ↔ bdd_above s := ⟨λ ⟨x, hx⟩, ⟨u x, by rwa [gc.upper_bounds_l_image] at hx⟩, gc.monotone_l.map_bdd_above⟩ lemma bdd_below_u_image {s : set β} : bdd_below (u '' s) ↔ bdd_below s := gc.dual.bdd_above_l_image lemma is_lub_l_image {s : set α} {a : α} (h : is_lub s a) : is_lub (l '' s) (l a) := ⟨gc.monotone_l.mem_upper_bounds_image h.left, λ b hb, gc.l_le $ h.right $ by rwa [gc.upper_bounds_l_image] at hb⟩ lemma is_glb_u_image {s : set β} {b : β} (h : is_glb s b) : is_glb (u '' s) (u b) := gc.dual.is_lub_l_image h lemma is_least_l {a : α} : is_least {b | a ≤ u b} (l a) := ⟨gc.le_u_l _, λ b hb, gc.l_le hb⟩ lemma is_greatest_u {b : β} : is_greatest {a | l a ≤ b} (u b) := gc.dual.is_least_l lemma is_glb_l {a : α} : is_glb {b | a ≤ u b} (l a) := gc.is_least_l.is_glb lemma is_lub_u {b : β} : is_lub { a | l a ≤ b } (u b) := gc.is_greatest_u.is_lub /-- If `(l, u)` is a Galois connection, then the relation `x ≤ u (l y)` is a transitive relation. If `l` is a closure operator (`submodule.span`, `subgroup.closure`, ...) and `u` is the coercion to `set`, this reads as "if `U` is in the closure of `V` and `V` is in the closure of `W` then `U` is in the closure of `W`". -/ lemma le_u_l_trans {x y z : α} (hxy : x ≤ u (l y)) (hyz : y ≤ u (l z)) : x ≤ u (l z) := hxy.trans (gc.monotone_u $ gc.l_le hyz) lemma l_u_le_trans {x y z : β} (hxy : l (u x) ≤ y) (hyz : l (u y) ≤ z) : l (u x) ≤ z := (gc.monotone_l $ gc.le_u hxy).trans hyz end section partial_order variables [partial_order α] [preorder β] {l : α → β} {u : β → α} (gc : galois_connection l u) include gc lemma u_l_u_eq_u (b : β) : u (l (u b)) = u b := (gc.monotone_u (gc.l_u_le _)).antisymm (gc.le_u_l _) lemma u_l_u_eq_u' : u ∘ l ∘ u = u := funext gc.u_l_u_eq_u lemma u_unique {l' : α → β} {u' : β → α} (gc' : galois_connection l' u') (hl : ∀ a, l a = l' a) {b : β} : u b = u' b := le_antisymm (gc'.le_u $ hl (u b) ▸ gc.l_u_le _) (gc.le_u $ (hl (u' b)).symm ▸ gc'.l_u_le _) /-- If there exists a `b` such that `a = u a`, then `b = l a` is one such element. -/ lemma exists_eq_u (a : α) : (∃ b : β, a = u b) ↔ a = u (l a) := ⟨λ ⟨S, hS⟩, hS.symm ▸ (gc.u_l_u_eq_u _).symm, λ HI, ⟨_, HI⟩ ⟩ lemma u_eq {z : α} {y : β} : u y = z ↔ ∀ x, x ≤ z ↔ l x ≤ y := begin split, { rintros rfl x, exact (gc x y).symm }, { intros H, exact ((H $ u y).mpr (gc.l_u_le y)).antisymm ((gc _ _).mp $ (H z).mp le_rfl) } end end partial_order section partial_order variables [preorder α] [partial_order β] {l : α → β} {u : β → α} (gc : galois_connection l u) include gc lemma l_u_l_eq_l (a : α) : l (u (l a)) = l a := (gc.l_u_le _).antisymm (gc.monotone_l (gc.le_u_l _)) lemma l_u_l_eq_l' : l ∘ u ∘ l = l := funext gc.l_u_l_eq_l lemma l_unique {l' : α → β} {u' : β → α} (gc' : galois_connection l' u') (hu : ∀ b, u b = u' b) {a : α} : l a = l' a := le_antisymm (gc.l_le $ (hu (l' a)).symm ▸ gc'.le_u_l _) (gc'.l_le $ hu (l a) ▸ gc.le_u_l _) /-- If there exists an `a` such that `b = l a`, then `a = u b` is one such element. -/ lemma exists_eq_l (b : β) : (∃ a : α, b = l a) ↔ b = l (u b) := ⟨λ ⟨S, hS⟩, hS.symm ▸ (gc.l_u_l_eq_l _).symm, λ HI, ⟨_, HI⟩ ⟩ lemma l_eq {x : α} {z : β} : l x = z ↔ ∀ y, z ≤ y ↔ x ≤ u y := begin split, { rintros rfl y, exact gc x y }, { intros H, exact ((gc _ _).mpr $ (H z).mp le_rfl).antisymm ((H $ l x).mpr (gc.le_u_l x)) } end end partial_order section order_top variables [partial_order α] [preorder β] [order_top α] [order_top β] {l : α → β} {u : β → α} (gc : galois_connection l u) include gc lemma u_top : u ⊤ = ⊤ := top_unique $ gc.le_u le_top end order_top section order_bot variables [preorder α] [partial_order β] [order_bot α] [order_bot β] {l : α → β} {u : β → α} (gc : galois_connection l u) include gc lemma l_bot : l ⊥ = ⊥ := gc.dual.u_top end order_bot section semilattice_sup variables [semilattice_sup α] [semilattice_sup β] {l : α → β} {u : β → α} (gc : galois_connection l u) include gc lemma l_sup : l (a₁ ⊔ a₂) = l a₁ ⊔ l a₂ := (gc.is_lub_l_image is_lub_pair).unique $ by simp only [image_pair, is_lub_pair] end semilattice_sup section semilattice_inf variables [semilattice_inf α] [semilattice_inf β] {l : α → β} {u : β → α} (gc : galois_connection l u) include gc lemma u_inf : u (b₁ ⊓ b₂) = u b₁ ⊓ u b₂ := gc.dual.l_sup end semilattice_inf section complete_lattice variables [complete_lattice α] [complete_lattice β] {l : α → β} {u : β → α} (gc : galois_connection l u) include gc lemma l_supr {f : ι → α} : l (supr f) = ⨆ i, l (f i) := eq.symm $ is_lub.supr_eq $ show is_lub (range (l ∘ f)) (l (supr f)), by rw [range_comp, ← Sup_range]; exact gc.is_lub_l_image (is_lub_Sup _) lemma l_supr₂ {f : Π i, κ i → α} : l (⨆ i j, f i j) = ⨆ i j, l (f i j) := by simp_rw gc.l_supr lemma u_infi {f : ι → β} : u (infi f) = ⨅ i, u (f i) := gc.dual.l_supr lemma u_infi₂ {f : Π i, κ i → β} : u (⨅ i j, f i j) = ⨅ i j, u (f i j) := gc.dual.l_supr₂ lemma l_Sup {s : set α} : l (Sup s) = ⨆ a ∈ s, l a := by simp only [Sup_eq_supr, gc.l_supr] lemma u_Inf {s : set β} : u (Inf s) = ⨅ a ∈ s, u a := gc.dual.l_Sup end complete_lattice section linear_order variables [linear_order α] [linear_order β] {l : α → β} {u : β → α} (gc : galois_connection l u) lemma lt_iff_lt {a : α} {b : β} : b < l a ↔ u b < a := lt_iff_lt_of_le_iff_le (gc a b) end linear_order /- Constructing Galois connections -/ section constructions protected lemma id [pα : preorder α] : @galois_connection α α pα pα id id := λ a b, iff.intro (λ x, x) (λ x, x) protected lemma compose [preorder α] [preorder β] [preorder γ] {l1 : α → β} {u1 : β → α} {l2 : β → γ} {u2 : γ → β} (gc1 : galois_connection l1 u1) (gc2 : galois_connection l2 u2) : galois_connection (l2 ∘ l1) (u1 ∘ u2) := by intros a b; rw [gc2, gc1] protected lemma dfun {ι : Type u} {α : ι → Type v} {β : ι → Type w} [∀ i, preorder (α i)] [∀ i, preorder (β i)] (l : Πi, α i → β i) (u : Πi, β i → α i) (gc : ∀ i, galois_connection (l i) (u i)) : galois_connection (λ (a : Π i, α i) i, l i (a i)) (λ b i, u i (b i)) := λ a b, forall_congr $ λ i, gc i (a i) (b i) end constructions lemma l_comm_of_u_comm {X : Type*} [preorder X] {Y : Type*} [preorder Y] {Z : Type*} [preorder Z] {W : Type*} [partial_order W] {lYX : X → Y} {uXY : Y → X} (hXY : galois_connection lYX uXY) {lWZ : Z → W} {uZW : W → Z} (hZW : galois_connection lWZ uZW) {lWY : Y → W} {uYW : W → Y} (hWY : galois_connection lWY uYW) {lZX : X → Z} {uXZ : Z → X} (hXZ : galois_connection lZX uXZ) (h : ∀ w, uXZ (uZW w) = uXY (uYW w)) {x : X} : lWZ (lZX x) = lWY (lYX x) := (hXZ.compose hZW).l_unique (hXY.compose hWY) h lemma u_comm_of_l_comm {X : Type*} [partial_order X] {Y : Type*} [preorder Y] {Z : Type*} [preorder Z] {W : Type*} [preorder W] {lYX : X → Y} {uXY : Y → X} (hXY : galois_connection lYX uXY) {lWZ : Z → W} {uZW : W → Z} (hZW : galois_connection lWZ uZW) {lWY : Y → W} {uYW : W → Y} (hWY : galois_connection lWY uYW) {lZX : X → Z} {uXZ : Z → X} (hXZ : galois_connection lZX uXZ) (h : ∀ x, lWZ (lZX x) = lWY (lYX x)) {w : W} : uXZ (uZW w) = uXY (uYW w) := (hXZ.compose hZW).u_unique (hXY.compose hWY) h lemma l_comm_iff_u_comm {X : Type*} [partial_order X] {Y : Type*} [preorder Y] {Z : Type*} [preorder Z] {W : Type*} [partial_order W] {lYX : X → Y} {uXY : Y → X} (hXY : galois_connection lYX uXY) {lWZ : Z → W} {uZW : W → Z} (hZW : galois_connection lWZ uZW) {lWY : Y → W} {uYW : W → Y} (hWY : galois_connection lWY uYW) {lZX : X → Z} {uXZ : Z → X} (hXZ : galois_connection lZX uXZ) : (∀ w : W, uXZ (uZW w) = uXY (uYW w)) ↔ ∀ x : X, lWZ (lZX x) = lWY (lYX x) := ⟨hXY.l_comm_of_u_comm hZW hWY hXZ, hXY.u_comm_of_l_comm hZW hWY hXZ⟩ end galois_connection namespace order_iso variables [preorder α] [preorder β] @[simp] lemma bdd_above_image (e : α ≃o β) {s : set α} : bdd_above (e '' s) ↔ bdd_above s := e.to_galois_connection.bdd_above_l_image @[simp] lemma bdd_below_image (e : α ≃o β) {s : set α} : bdd_below (e '' s) ↔ bdd_below s := e.dual.bdd_above_image @[simp] lemma bdd_above_preimage (e : α ≃o β) {s : set β} : bdd_above (e ⁻¹' s) ↔ bdd_above s := by rw [← e.bdd_above_image, e.image_preimage] @[simp] lemma bdd_below_preimage (e : α ≃o β) {s : set β} : bdd_below (e ⁻¹' s) ↔ bdd_below s := by rw [← e.bdd_below_image, e.image_preimage] end order_iso namespace nat lemma galois_connection_mul_div {k : ℕ} (h : 0 < k) : galois_connection (λ n, n * k) (λ n, n / k) := λ x y, (le_div_iff_mul_le x y h).symm end nat /-- A Galois insertion is a Galois connection where `l ∘ u = id`. It also contains a constructive choice function, to give better definitional equalities when lifting order structures. Dual to `galois_coinsertion` -/ @[nolint has_inhabited_instance] structure galois_insertion {α β : Type*} [preorder α] [preorder β] (l : α → β) (u : β → α) := (choice : Πx : α, u (l x) ≤ x → β) (gc : galois_connection l u) (le_l_u : ∀ x, x ≤ l (u x)) (choice_eq : ∀ a h, choice a h = l a) /-- A constructor for a Galois insertion with the trivial `choice` function. -/ def galois_insertion.monotone_intro {α β : Type*} [preorder α] [preorder β] {l : α → β} {u : β → α} (hu : monotone u) (hl : monotone l) (hul : ∀ a, a ≤ u (l a)) (hlu : ∀ b, l (u b) = b) : galois_insertion l u := { choice := λ x _, l x, gc := galois_connection.monotone_intro hu hl hul (λ b, le_of_eq (hlu b)), le_l_u := λ b, le_of_eq $ (hlu b).symm, choice_eq := λ _ _, rfl } /-- Makes a Galois insertion from an order-preserving bijection. -/ protected def order_iso.to_galois_insertion [preorder α] [preorder β] (oi : α ≃o β) : galois_insertion oi oi.symm := { choice := λ b h, oi b, gc := oi.to_galois_connection, le_l_u := λ g, le_of_eq (oi.right_inv g).symm, choice_eq := λ b h, rfl } /-- Make a `galois_insertion l u` from a `galois_connection l u` such that `∀ b, b ≤ l (u b)` -/ def galois_connection.to_galois_insertion {α β : Type*} [preorder α] [preorder β] {l : α → β} {u : β → α} (gc : galois_connection l u) (h : ∀ b, b ≤ l (u b)) : galois_insertion l u := { choice := λ x _, l x, gc := gc, le_l_u := h, choice_eq := λ _ _, rfl } /-- Lift the bottom along a Galois connection -/ def galois_connection.lift_order_bot {α β : Type*} [preorder α] [order_bot α] [partial_order β] {l : α → β} {u : β → α} (gc : galois_connection l u) : order_bot β := { bot := l ⊥, bot_le := λ b, gc.l_le $ bot_le } namespace galois_insertion variables {l : α → β} {u : β → α} lemma l_u_eq [preorder α] [partial_order β] (gi : galois_insertion l u) (b : β) : l (u b) = b := (gi.gc.l_u_le _).antisymm (gi.le_l_u _) lemma left_inverse_l_u [preorder α] [partial_order β] (gi : galois_insertion l u) : left_inverse l u := gi.l_u_eq lemma l_surjective [preorder α] [partial_order β] (gi : galois_insertion l u) : surjective l := gi.left_inverse_l_u.surjective lemma u_injective [preorder α] [partial_order β] (gi : galois_insertion l u) : injective u := gi.left_inverse_l_u.injective lemma l_sup_u [semilattice_sup α] [semilattice_sup β] (gi : galois_insertion l u) (a b : β) : l (u a ⊔ u b) = a ⊔ b := calc l (u a ⊔ u b) = l (u a) ⊔ l (u b) : gi.gc.l_sup ... = a ⊔ b : by simp only [gi.l_u_eq] lemma l_supr_u [complete_lattice α] [complete_lattice β] (gi : galois_insertion l u) {ι : Sort x} (f : ι → β) : l (⨆ i, u (f i)) = ⨆ i, (f i) := calc l (⨆ (i : ι), u (f i)) = ⨆ (i : ι), l (u (f i)) : gi.gc.l_supr ... = ⨆ (i : ι), f i : congr_arg _ $ funext $ λ i, gi.l_u_eq (f i) lemma l_bsupr_u [complete_lattice α] [complete_lattice β] (gi : galois_insertion l u) {ι : Sort x} {p : ι → Prop} (f : Π i (hi : p i), β) : l (⨆ i hi, u (f i hi)) = ⨆ i hi, f i hi := by simp only [supr_subtype', gi.l_supr_u] lemma l_Sup_u_image [complete_lattice α] [complete_lattice β] (gi : galois_insertion l u) (s : set β) : l (Sup (u '' s)) = Sup s := by rw [Sup_image, gi.l_bsupr_u, Sup_eq_supr] lemma l_inf_u [semilattice_inf α] [semilattice_inf β] (gi : galois_insertion l u) (a b : β) : l (u a ⊓ u b) = a ⊓ b := calc l (u a ⊓ u b) = l (u (a ⊓ b)) : congr_arg l gi.gc.u_inf.symm ... = a ⊓ b : by simp only [gi.l_u_eq] lemma l_infi_u [complete_lattice α] [complete_lattice β] (gi : galois_insertion l u) {ι : Sort x} (f : ι → β) : l (⨅ i, u (f i)) = ⨅ i, f i := calc l (⨅ (i : ι), u (f i)) = l (u (⨅ (i : ι), (f i))) : congr_arg l gi.gc.u_infi.symm ... = ⨅ (i : ι), f i : gi.l_u_eq _ lemma l_binfi_u [complete_lattice α] [complete_lattice β] (gi : galois_insertion l u) {ι : Sort x} {p : ι → Prop} (f : Π i (hi : p i), β) : l (⨅ i hi, u (f i hi)) = ⨅ i hi, f i hi := by simp only [infi_subtype', gi.l_infi_u] lemma l_Inf_u_image [complete_lattice α] [complete_lattice β] (gi : galois_insertion l u) (s : set β) : l (Inf (u '' s)) = Inf s := by rw [Inf_image, gi.l_binfi_u, Inf_eq_infi] lemma l_infi_of_ul_eq_self [complete_lattice α] [complete_lattice β] (gi : galois_insertion l u) {ι : Sort x} (f : ι → α) (hf : ∀ i, u (l (f i)) = f i) : l (⨅ i, f i) = ⨅ i, l (f i) := calc l (⨅ i, (f i)) = l ⨅ (i : ι), (u (l (f i))) : by simp [hf] ... = ⨅ i, l (f i) : gi.l_infi_u _ lemma l_binfi_of_ul_eq_self [complete_lattice α] [complete_lattice β] (gi : galois_insertion l u) {ι : Sort x} {p : ι → Prop} (f : Π i (hi : p i), α) (hf : ∀ i hi, u (l (f i hi)) = f i hi) : l (⨅ i hi, f i hi) = ⨅ i hi, l (f i hi) := by { rw [infi_subtype', infi_subtype'], exact gi.l_infi_of_ul_eq_self _ (λ _, hf _ _) } lemma u_le_u_iff [preorder α] [preorder β] (gi : galois_insertion l u) {a b} : u a ≤ u b ↔ a ≤ b := ⟨λ h, (gi.le_l_u _).trans (gi.gc.l_le h), λ h, gi.gc.monotone_u h⟩ lemma strict_mono_u [preorder α] [preorder β] (gi : galois_insertion l u) : strict_mono u := strict_mono_of_le_iff_le $ λ _ _, gi.u_le_u_iff.symm lemma is_lub_of_u_image [preorder α] [preorder β] (gi : galois_insertion l u) {s : set β} {a : α} (hs : is_lub (u '' s) a) : is_lub s (l a) := ⟨λ x hx, (gi.le_l_u x).trans $ gi.gc.monotone_l $ hs.1 $ mem_image_of_mem _ hx, λ x hx, gi.gc.l_le $ hs.2 $ gi.gc.monotone_u.mem_upper_bounds_image hx⟩ lemma is_glb_of_u_image [preorder α] [preorder β] (gi : galois_insertion l u) {s : set β} {a : α} (hs : is_glb (u '' s) a) : is_glb s (l a) := ⟨λ x hx, gi.gc.l_le $ hs.1 $ mem_image_of_mem _ hx, λ x hx, (gi.le_l_u x).trans $ gi.gc.monotone_l $ hs.2 $ gi.gc.monotone_u.mem_lower_bounds_image hx⟩ section lift variables [partial_order β] /-- Lift the suprema along a Galois insertion -/ @[reducible] -- See note [reducible non instances] def lift_semilattice_sup [semilattice_sup α] (gi : galois_insertion l u) : semilattice_sup β := { sup := λ a b, l (u a ⊔ u b), le_sup_left := λ a b, (gi.le_l_u a).trans $ gi.gc.monotone_l $ le_sup_left, le_sup_right := λ a b, (gi.le_l_u b).trans $ gi.gc.monotone_l $ le_sup_right, sup_le := λ a b c hac hbc, gi.gc.l_le $ sup_le (gi.gc.monotone_u hac) (gi.gc.monotone_u hbc), .. ‹partial_order β› } /-- Lift the infima along a Galois insertion -/ @[reducible] -- See note [reducible non instances] def lift_semilattice_inf [semilattice_inf α] (gi : galois_insertion l u) : semilattice_inf β := { inf := λ a b, gi.choice (u a ⊓ u b) $ (le_inf (gi.gc.monotone_u $ gi.gc.l_le $ inf_le_left) (gi.gc.monotone_u $ gi.gc.l_le $ inf_le_right)), inf_le_left := by simp only [gi.choice_eq]; exact λ a b, gi.gc.l_le inf_le_left, inf_le_right := by simp only [gi.choice_eq]; exact λ a b, gi.gc.l_le inf_le_right, le_inf := by simp only [gi.choice_eq]; exact λ a b c hac hbc, (gi.le_l_u a).trans $ gi.gc.monotone_l $ le_inf (gi.gc.monotone_u hac) (gi.gc.monotone_u hbc), .. ‹partial_order β› } /-- Lift the suprema and infima along a Galois insertion -/ @[reducible] -- See note [reducible non instances] def lift_lattice [lattice α] (gi : galois_insertion l u) : lattice β := { .. gi.lift_semilattice_sup, .. gi.lift_semilattice_inf } /-- Lift the top along a Galois insertion -/ @[reducible] -- See note [reducible non instances] def lift_order_top [preorder α] [order_top α] (gi : galois_insertion l u) : order_top β := { top := gi.choice ⊤ $ le_top, le_top := by simp only [gi.choice_eq]; exact λ b, (gi.le_l_u b).trans (gi.gc.monotone_l le_top) } /-- Lift the top, bottom, suprema, and infima along a Galois insertion -/ @[reducible] -- See note [reducible non instances] def lift_bounded_order [preorder α] [bounded_order α] (gi : galois_insertion l u) : bounded_order β := { .. gi.lift_order_top, .. gi.gc.lift_order_bot } /-- Lift all suprema and infima along a Galois insertion -/ @[reducible] -- See note [reducible non instances] def lift_complete_lattice [complete_lattice α] (gi : galois_insertion l u) : complete_lattice β := { Sup := λ s, l (Sup (u '' s)), Sup_le := λ s, (gi.is_lub_of_u_image (is_lub_Sup _)).2, le_Sup := λ s, (gi.is_lub_of_u_image (is_lub_Sup _)).1, Inf := λ s, gi.choice (Inf (u '' s)) $ gi.gc.monotone_u.le_is_glb_image (gi.is_glb_of_u_image $ is_glb_Inf _) (is_glb_Inf _), Inf_le := λ s, by { rw gi.choice_eq, exact (gi.is_glb_of_u_image (is_glb_Inf _)).1 }, le_Inf := λ s, by { rw gi.choice_eq, exact (gi.is_glb_of_u_image (is_glb_Inf _)).2 }, .. gi.lift_bounded_order, .. gi.lift_lattice } end lift end galois_insertion /-- A Galois coinsertion is a Galois connection where `u ∘ l = id`. It also contains a constructive choice function, to give better definitional equalities when lifting order structures. Dual to `galois_insertion` -/ @[nolint has_inhabited_instance] structure galois_coinsertion [preorder α] [preorder β] (l : α → β) (u : β → α) := (choice : Πx : β, x ≤ l (u x) → α) (gc : galois_connection l u) (u_l_le : ∀ x, u (l x) ≤ x) (choice_eq : ∀ a h, choice a h = u a) /-- Make a `galois_insertion` between `αᵒᵈ` and `βᵒᵈ` from a `galois_coinsertion` between `α` and `β`. -/ def galois_coinsertion.dual [preorder α] [preorder β] {l : α → β} {u : β → α} : galois_coinsertion l u → galois_insertion (to_dual ∘ u ∘ of_dual) (to_dual ∘ l ∘ of_dual) := λ x, ⟨x.1, x.2.dual, x.3, x.4⟩ /-- Make a `galois_coinsertion` between `αᵒᵈ` and `βᵒᵈ` from a `galois_insertion` between `α` and `β`. -/ def galois_insertion.dual [preorder α] [preorder β] {l : α → β} {u : β → α} : galois_insertion l u → galois_coinsertion (to_dual ∘ u ∘ of_dual) (to_dual ∘ l ∘ of_dual) := λ x, ⟨x.1, x.2.dual, x.3, x.4⟩ /-- Make a `galois_insertion` between `α` and `β` from a `galois_coinsertion` between `αᵒᵈ` and `βᵒᵈ`. -/ def galois_coinsertion.of_dual [preorder α] [preorder β] {l : αᵒᵈ → βᵒᵈ} {u : βᵒᵈ → αᵒᵈ} : galois_coinsertion l u → galois_insertion (of_dual ∘ u ∘ to_dual) (of_dual ∘ l ∘ to_dual) := λ x, ⟨x.1, x.2.dual, x.3, x.4⟩ /-- Make a `galois_coinsertion` between `α` and `β` from a `galois_insertion` between `αᵒᵈ` and `βᵒᵈ`. -/ def galois_insertion.of_dual [preorder α] [preorder β] {l : αᵒᵈ → βᵒᵈ} {u : βᵒᵈ → αᵒᵈ} : galois_insertion l u → galois_coinsertion (of_dual ∘ u ∘ to_dual) (of_dual ∘ l ∘ to_dual) := λ x, ⟨x.1, x.2.dual, x.3, x.4⟩ /-- Makes a Galois coinsertion from an order-preserving bijection. -/ protected def order_iso.to_galois_coinsertion [preorder α] [preorder β] (oi : α ≃o β) : galois_coinsertion oi oi.symm := { choice := λ b h, oi.symm b, gc := oi.to_galois_connection, u_l_le := λ g, le_of_eq (oi.left_inv g), choice_eq := λ b h, rfl } /-- A constructor for a Galois coinsertion with the trivial `choice` function. -/ def galois_coinsertion.monotone_intro [preorder α] [preorder β] {l : α → β} {u : β → α} (hu : monotone u) (hl : monotone l) (hlu : ∀ b, l (u b) ≤ b) (hul : ∀ a, u (l a) = a) : galois_coinsertion l u := (galois_insertion.monotone_intro hl.dual hu.dual hlu hul).of_dual /-- Make a `galois_coinsertion l u` from a `galois_connection l u` such that `∀ b, b ≤ l (u b)` -/ def galois_connection.to_galois_coinsertion {α β : Type*} [preorder α] [preorder β] {l : α → β} {u : β → α} (gc : galois_connection l u) (h : ∀ a, u (l a) ≤ a) : galois_coinsertion l u := { choice := λ x _, u x, gc := gc, u_l_le := h, choice_eq := λ _ _, rfl } /-- Lift the top along a Galois connection -/ def galois_connection.lift_order_top {α β : Type*} [partial_order α] [preorder β] [order_top β] {l : α → β} {u : β → α} (gc : galois_connection l u) : order_top α := { top := u ⊤, le_top := λ b, gc.le_u $ le_top } namespace galois_coinsertion variables {l : α → β} {u : β → α} lemma u_l_eq [partial_order α] [preorder β] (gi : galois_coinsertion l u) (a : α) : u (l a) = a := gi.dual.l_u_eq a lemma u_l_left_inverse [partial_order α] [preorder β] (gi : galois_coinsertion l u) : left_inverse u l := gi.u_l_eq lemma u_surjective [partial_order α] [preorder β] (gi : galois_coinsertion l u) : surjective u := gi.dual.l_surjective lemma l_injective [partial_order α] [preorder β] (gi : galois_coinsertion l u) : injective l := gi.dual.u_injective lemma u_inf_l [semilattice_inf α] [semilattice_inf β] (gi : galois_coinsertion l u) (a b : α) : u (l a ⊓ l b) = a ⊓ b := gi.dual.l_sup_u a b lemma u_infi_l [complete_lattice α] [complete_lattice β] (gi : galois_coinsertion l u) {ι : Sort x} (f : ι → α) : u (⨅ i, l (f i)) = ⨅ i, (f i) := gi.dual.l_supr_u _ lemma u_Inf_l_image [complete_lattice α] [complete_lattice β] (gi : galois_coinsertion l u) (s : set α) : u (Inf (l '' s)) = Inf s := gi.dual.l_Sup_u_image _ lemma u_sup_l [semilattice_sup α] [semilattice_sup β] (gi : galois_coinsertion l u) (a b : α) : u (l a ⊔ l b) = a ⊔ b := gi.dual.l_inf_u _ _ lemma u_supr_l [complete_lattice α] [complete_lattice β] (gi : galois_coinsertion l u) {ι : Sort x} (f : ι → α) : u (⨆ i, l (f i)) = ⨆ i, (f i) := gi.dual.l_infi_u _ lemma u_bsupr_l [complete_lattice α] [complete_lattice β] (gi : galois_coinsertion l u) {ι : Sort x} {p : ι → Prop} (f : Π i (hi : p i), α) : u (⨆ i hi, l (f i hi)) = ⨆ i hi, f i hi := gi.dual.l_binfi_u _ lemma u_Sup_l_image [complete_lattice α] [complete_lattice β] (gi : galois_coinsertion l u) (s : set α) : u (Sup (l '' s)) = Sup s := gi.dual.l_Inf_u_image _ lemma u_supr_of_lu_eq_self [complete_lattice α] [complete_lattice β] (gi : galois_coinsertion l u) {ι : Sort x} (f : ι → β) (hf : ∀ i, l (u (f i)) = f i) : u (⨆ i, (f i)) = ⨆ i, u (f i) := gi.dual.l_infi_of_ul_eq_self _ hf lemma u_bsupr_of_lu_eq_self [complete_lattice α] [complete_lattice β] (gi : galois_coinsertion l u) {ι : Sort x} {p : ι → Prop} (f : Π i (hi : p i), β) (hf : ∀ i hi, l (u (f i hi)) = f i hi) : u (⨆ i hi, f i hi) = ⨆ i hi, u (f i hi) := gi.dual.l_binfi_of_ul_eq_self _ hf lemma l_le_l_iff [preorder α] [preorder β] (gi : galois_coinsertion l u) {a b} : l a ≤ l b ↔ a ≤ b := gi.dual.u_le_u_iff lemma strict_mono_l [preorder α] [preorder β] (gi : galois_coinsertion l u) : strict_mono l := λ a b h, gi.dual.strict_mono_u h lemma is_glb_of_l_image [preorder α] [preorder β] (gi : galois_coinsertion l u) {s : set α} {a : β} (hs : is_glb (l '' s) a) : is_glb s (u a) := gi.dual.is_lub_of_u_image hs lemma is_lub_of_l_image [preorder α] [preorder β] (gi : galois_coinsertion l u) {s : set α} {a : β} (hs : is_lub (l '' s) a) : is_lub s (u a) := gi.dual.is_glb_of_u_image hs section lift variables [partial_order α] /-- Lift the infima along a Galois coinsertion -/ @[reducible] -- See note [reducible non instances] def lift_semilattice_inf [semilattice_inf β] (gi : galois_coinsertion l u) : semilattice_inf α := { inf := λ a b, u (l a ⊓ l b), .. ‹partial_order α›, .. @order_dual.semilattice_inf _ gi.dual.lift_semilattice_sup } /-- Lift the suprema along a Galois coinsertion -/ @[reducible] -- See note [reducible non instances] def lift_semilattice_sup [semilattice_sup β] (gi : galois_coinsertion l u) : semilattice_sup α := { sup := λ a b, gi.choice (l a ⊔ l b) $ (sup_le (gi.gc.monotone_l $ gi.gc.le_u $ le_sup_left) (gi.gc.monotone_l $ gi.gc.le_u $ le_sup_right)), .. ‹partial_order α›, .. @order_dual.semilattice_sup _ gi.dual.lift_semilattice_inf } /-- Lift the suprema and infima along a Galois coinsertion -/ @[reducible] -- See note [reducible non instances] def lift_lattice [lattice β] (gi : galois_coinsertion l u) : lattice α := { .. gi.lift_semilattice_sup, .. gi.lift_semilattice_inf } /-- Lift the bot along a Galois coinsertion -/ @[reducible] -- See note [reducible non instances] def lift_order_bot [preorder β] [order_bot β] (gi : galois_coinsertion l u) : order_bot α := { bot := gi.choice ⊥ $ bot_le, .. @order_dual.order_bot _ _ gi.dual.lift_order_top } /-- Lift the top, bottom, suprema, and infima along a Galois coinsertion -/ @[reducible] -- See note [reducible non instances] def lift_bounded_order [preorder β] [bounded_order β] (gi : galois_coinsertion l u) : bounded_order α := { .. gi.lift_order_bot, .. gi.gc.lift_order_top } /-- Lift all suprema and infima along a Galois coinsertion -/ @[reducible] -- See note [reducible non instances] def lift_complete_lattice [complete_lattice β] (gi : galois_coinsertion l u) : complete_lattice α := { Inf := λ s, u (Inf (l '' s)), Sup := λ s, gi.choice (Sup (l '' s)) _, .. @order_dual.complete_lattice _ gi.dual.lift_complete_lattice } end lift end galois_coinsertion /-- If `α` is a partial order with bottom element (e.g., `ℕ`, `ℝ≥0`), then `λ o : with_bot α, o.get_or_else ⊥` and coercion form a Galois insertion. -/ def with_bot.gi_get_or_else_bot [preorder α] [order_bot α] : galois_insertion (λ o : with_bot α, o.get_or_else ⊥) coe := { gc := λ a b, with_bot.get_or_else_bot_le_iff, le_l_u := λ a, le_rfl, choice := λ o ho, _, choice_eq := λ _ _, rfl }
531348768287d38e5af13389d1501f95ca073b5d
26ac254ecb57ffcb886ff709cf018390161a9225
/src/ring_theory/localization.lean
440733d20775a2284bf65b6d0c934245a38ee490
[ "Apache-2.0" ]
permissive
eric-wieser/mathlib
42842584f584359bbe1fc8b88b3ff937c8acd72d
d0df6b81cd0920ad569158c06a3fd5abb9e63301
refs/heads/master
1,669,546,404,255
1,595,254,668,000
1,595,254,668,000
281,173,504
0
0
Apache-2.0
1,595,263,582,000
1,595,263,581,000
null
UTF-8
Lean
false
false
49,262
lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston -/ import data.equiv.ring import tactic.ring_exp import ring_theory.ideal_operations import group_theory.monoid_localization import ring_theory.algebraic import ring_theory.integral_closure /-! # Localizations of commutative rings We characterize the localization of a commutative ring `R` at a submonoid `M` up to isomorphism; that is, a commutative ring `S` is the localization of `R` at `M` iff we can find a ring homomorphism `f : R →+* S` satisfying 3 properties: 1. For all `y ∈ M`, `f y` is a unit; 2. For all `z : S`, there exists `(x, y) : R × M` such that `z * f y = f x`; 3. For all `x, y : R`, `f x = f y` iff there exists `c ∈ M` such that `x * c = y * c`. Given such a localization map `f : R →+* S`, we can define the surjection `localization_map.mk'` sending `(x, y) : R × M` to `f x * (f y)⁻¹`, and `localization_map.lift`, the homomorphism from `S` induced by a homomorphism from `R` which maps elements of `M` to invertible elements of the codomain. Similarly, given commutative rings `P, Q`, a submonoid `T` of `P` and a localization map for `T` from `P` to `Q`, then a homomorphism `g : R →+* P` such that `g(M) ⊆ T` induces a homomorphism of localizations, `localization_map.map`, from `S` to `Q`. We show the localization as a quotient type, defined in `group_theory.monoid_localization` as `submonoid.localization`, is a `comm_ring` and that the natural ring hom `of : R →+* localization M` is a localization map. We show that a localization at the complement of a prime ideal is a local ring. We prove some lemmas about the `R`-algebra structure of `S`. When `R` is an integral domain, we define `fraction_map R K` as an abbreviation for `localization (non_zero_divisors R) K`, the natural map to `R`'s field of fractions. We show that a `comm_ring` `K` which is the localization of an integral domain `R` at `R \ {0}` is a field. We use this to show the field of fractions as a quotient type, `fraction_ring`, is a field. ## Implementation notes In maths it is natural to reason up to isomorphism, but in Lean we cannot naturally `rewrite` one structure with an isomorphic one; one way around this is to isolate a predicate characterizing a structure up to isomorphism, and reason about things that satisfy the predicate. A ring localization map is defined to be a localization map of the underlying `comm_monoid` (a `submonoid.localization_map`) which is also a ring hom. To prove most lemmas about a `localization_map` `f` in this file we invoke the corresponding proof for the underlying `comm_monoid` localization map `f.to_localization_map`, which can be found in `group_theory.monoid_localization` and the namespace `submonoid.localization_map`. To apply a localization map `f` as a function, we use `f.to_map`, as coercions don't work well for this structure. To reason about the localization as a quotient type, use `mk_eq_of_mk'` and associated lemmas. These show the quotient map `mk : R → M → localization M` equals the surjection `localization_map.mk'` induced by the map `of : localization_map M (localization M)` (where `of` establishes the localization as a quotient type satisfies the characteristic predicate). The lemma `mk_eq_of_mk'` hence gives you access to the results in the rest of the file, which are about the `localization_map.mk'` induced by any localization map. We define a copy of the localization map `f`'s codomain `S` carrying the data of `f` so that instances on `S` induced by `f` can 'know' the map needed to induce the instance. The proof that "a `comm_ring` `K` which is the localization of an integral domain `R` at `R \ {0}` is a field" is a `def` rather than an `instance`, so if you want to reason about a field of fractions `K`, assume `[field K]` instead of just `[comm_ring K]`. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ variables {R : Type*} [comm_ring R] (M : submonoid R) (S : Type*) [comm_ring S] {P : Type*} [comm_ring P] open function set_option old_structure_cmd true /-- The type of ring homomorphisms satisfying the characteristic predicate: if `f : R →+* S` satisfies this predicate, then `S` is isomorphic to the localization of `R` at `M`. We later define an instance coercing a localization map `f` to its codomain `S` so that instances on `S` induced by `f` can 'know' the map needed to induce the instance. -/ @[nolint has_inhabited_instance] structure localization_map extends ring_hom R S, submonoid.localization_map M S /-- The ring hom underlying a `localization_map`. -/ add_decl_doc localization_map.to_ring_hom /-- The `comm_monoid` `localization_map` underlying a `comm_ring` `localization_map`. See `group_theory.monoid_localization` for its definition. -/ add_decl_doc localization_map.to_localization_map variables {M S} namespace ring_hom /-- Makes a localization map from a `comm_ring` hom satisfying the characteristic predicate. -/ def to_localization_map (f : R →+* S) (H1 : ∀ y : M, is_unit (f y)) (H2 : ∀ z, ∃ x : R × M, z * f x.2 = f x.1) (H3 : ∀ x y, f x = f y ↔ ∃ c : M, x * c = y * c) : localization_map M S := { map_units' := H1, surj' := H2, eq_iff_exists' := H3, .. f } end ring_hom /-- Makes a `comm_ring` localization map from an additive `comm_monoid` localization map of `comm_ring`s. -/ def submonoid.localization_map.to_ring_localization (f : submonoid.localization_map M S) (h : ∀ x y, f.to_map (x + y) = f.to_map x + f.to_map y) : localization_map M S := { ..ring_hom.mk' f.to_monoid_hom h, ..f } namespace localization_map variables (f : localization_map M S) /-- We define a copy of the localization map `f`'s codomain `S` carrying the data of `f` so that instances on `S` induced by `f` can 'know` the map needed to induce the instance. -/ @[nolint unused_arguments has_inhabited_instance] def codomain (f : localization_map M S) := S instance : comm_ring f.codomain := by assumption instance {K : Type*} [field K] (f : localization_map M K) : field f.codomain := by assumption /-- Short for `to_ring_hom`; used for applying a localization map as a function. -/ abbreviation to_map := f.to_ring_hom lemma map_units (y : M) : is_unit (f.to_map y) := f.6 y lemma surj (z) : ∃ x : R × M, z * f.to_map x.2 = f.to_map x.1 := f.7 z lemma eq_iff_exists {x y} : f.to_map x = f.to_map y ↔ ∃ c : M, x * c = y * c := f.8 x y @[ext] lemma ext {f g : localization_map M S} (h : ∀ x, f.to_map x = g.to_map x) : f = g := begin cases f, cases g, simp only at *, exact funext h end lemma ext_iff {f g : localization_map M S} : f = g ↔ ∀ x, f.to_map x = g.to_map x := ⟨λ h x, h ▸ rfl, ext⟩ lemma to_map_injective : injective (@localization_map.to_map _ _ M S _) := λ _ _ h, ext $ ring_hom.ext_iff.1 h /-- Given `a : S`, `S` a localization of `R`, `is_integer a` iff `a` is in the image of the localization map from `R` to `S`. -/ def is_integer (a : S) : Prop := a ∈ set.range f.to_map variables {f} lemma is_integer_add {a b} (ha : f.is_integer a) (hb : f.is_integer b) : f.is_integer (a + b) := begin rcases ha with ⟨a', ha⟩, rcases hb with ⟨b', hb⟩, use a' + b', rw [f.to_map.map_add, ha, hb] end lemma is_integer_mul {a b} (ha : f.is_integer a) (hb : f.is_integer b) : f.is_integer (a * b) := begin rcases ha with ⟨a', ha⟩, rcases hb with ⟨b', hb⟩, use a' * b', rw [f.to_map.map_mul, ha, hb] end lemma is_integer_smul {a : R} {b} (hb : f.is_integer b) : f.is_integer (f.to_map a * b) := begin rcases hb with ⟨b', hb⟩, use a * b', rw [←hb, f.to_map.map_mul] end variables (f) /-- Each element `a : S` has an `M`-multiple which is an integer. This version multiplies `a` on the right, matching the argument order in `localization_map.surj`. -/ lemma exists_integer_multiple' (a : S) : ∃ (b : M), is_integer f (a * f.to_map b) := let ⟨⟨num, denom⟩, h⟩ := f.surj a in ⟨denom, set.mem_range.mpr ⟨num, h.symm⟩⟩ /-- Each element `a : S` has an `M`-multiple which is an integer. This version multiplies `a` on the left, matching the argument order in the `has_scalar` instance. -/ lemma exists_integer_multiple (a : S) : ∃ (b : M), is_integer f (f.to_map b * a) := by { simp_rw mul_comm _ a, apply exists_integer_multiple' } /-- Given `z : S`, `f.to_localization_map.sec z` is defined to be a pair `(x, y) : R × M` such that `z * f y = f x` (so this lemma is true by definition). -/ lemma sec_spec {f : localization_map M S} (z : S) : z * f.to_map (f.to_localization_map.sec z).2 = f.to_map (f.to_localization_map.sec z).1 := classical.some_spec $ f.surj z /-- Given `z : S`, `f.to_localization_map.sec z` is defined to be a pair `(x, y) : R × M` such that `z * f y = f x`, so this lemma is just an application of `S`'s commutativity. -/ lemma sec_spec' {f : localization_map M S} (z : S) : f.to_map (f.to_localization_map.sec z).1 = f.to_map (f.to_localization_map.sec z).2 * z := by rw [mul_comm, sec_spec] open_locale big_operators /-- We can clear the denominators of a finite set of fractions. -/ lemma exist_integer_multiples_of_finset (s : finset S) : ∃ (b : M), ∀ a ∈ s, is_integer f (f.to_map b * a) := begin haveI := classical.prop_decidable, use ∏ a in s, (f.to_localization_map.sec a).2, intros a ha, use (∏ x in s.erase a, (f.to_localization_map.sec x).2) * (f.to_localization_map.sec a).1, rw [ring_hom.map_mul, sec_spec', ←mul_assoc, ←f.to_map.map_mul], congr' 2, refine trans _ ((submonoid.subtype M).map_prod _ _).symm, rw [mul_comm, ←finset.prod_insert (s.not_mem_erase a), finset.insert_erase ha], refl, end lemma map_right_cancel {x y} {c : M} (h : f.to_map (c * x) = f.to_map (c * y)) : f.to_map x = f.to_map y := f.to_localization_map.map_right_cancel h lemma map_left_cancel {x y} {c : M} (h : f.to_map (x * c) = f.to_map (y * c)) : f.to_map x = f.to_map y := f.to_localization_map.map_left_cancel h lemma eq_zero_of_fst_eq_zero {z x} {y : M} (h : z * f.to_map y = f.to_map x) (hx : x = 0) : z = 0 := by rw [hx, f.to_map.map_zero] at h; exact (f.map_units y).mul_left_eq_zero.1 h /-- Given a localization map `f : R →+* S`, the surjection sending `(x, y) : R × M` to `f x * (f y)⁻¹`. -/ noncomputable def mk' (f : localization_map M S) (x : R) (y : M) : S := f.to_localization_map.mk' x y @[simp] lemma mk'_sec (z : S) : f.mk' (f.to_localization_map.sec z).1 (f.to_localization_map.sec z).2 = z := f.to_localization_map.mk'_sec _ lemma mk'_mul (x₁ x₂ : R) (y₁ y₂ : M) : f.mk' (x₁ * x₂) (y₁ * y₂) = f.mk' x₁ y₁ * f.mk' x₂ y₂ := f.to_localization_map.mk'_mul _ _ _ _ lemma mk'_one (x) : f.mk' x (1 : M) = f.to_map x := f.to_localization_map.mk'_one _ lemma mk'_spec (x) (y : M) : f.mk' x y * f.to_map y = f.to_map x := f.to_localization_map.mk'_spec _ _ lemma mk'_spec' (x) (y : M) : f.to_map y * f.mk' x y = f.to_map x := f.to_localization_map.mk'_spec' _ _ theorem eq_mk'_iff_mul_eq {x} {y : M} {z} : z = f.mk' x y ↔ z * f.to_map y = f.to_map x := f.to_localization_map.eq_mk'_iff_mul_eq theorem mk'_eq_iff_eq_mul {x} {y : M} {z} : f.mk' x y = z ↔ f.to_map x = z * f.to_map y := f.to_localization_map.mk'_eq_iff_eq_mul lemma mk'_surjective (z : S) : ∃ x (y : M), f.mk' x y = z := let ⟨r, hr⟩ := f.surj z in ⟨r.1, r.2, (f.eq_mk'_iff_mul_eq.2 hr).symm⟩ lemma mk'_eq_iff_eq {x₁ x₂} {y₁ y₂ : M} : f.mk' x₁ y₁ = f.mk' x₂ y₂ ↔ f.to_map (x₁ * y₂) = f.to_map (x₂ * y₁) := f.to_localization_map.mk'_eq_iff_eq protected lemma eq {a₁ b₁} {a₂ b₂ : M} : f.mk' a₁ a₂ = f.mk' b₁ b₂ ↔ ∃ c : M, a₁ * b₂ * c = b₁ * a₂ * c := f.to_localization_map.eq lemma eq_iff_eq (g : localization_map M P) {x y} : f.to_map x = f.to_map y ↔ g.to_map x = g.to_map y := f.to_localization_map.eq_iff_eq g.to_localization_map lemma mk'_eq_iff_mk'_eq (g : localization_map M P) {x₁ x₂} {y₁ y₂ : M} : f.mk' x₁ y₁ = f.mk' x₂ y₂ ↔ g.mk' x₁ y₁ = g.mk' x₂ y₂ := f.to_localization_map.mk'_eq_iff_mk'_eq g.to_localization_map lemma mk'_eq_of_eq {a₁ b₁ : R} {a₂ b₂ : M} (H : b₁ * a₂ = a₁ * b₂) : f.mk' a₁ a₂ = f.mk' b₁ b₂ := f.to_localization_map.mk'_eq_of_eq H @[simp] lemma mk'_self {x : R} (hx : x ∈ M) : f.mk' x ⟨x, hx⟩ = 1 := f.to_localization_map.mk'_self' _ hx @[simp] lemma mk'_self' {x : M} : f.mk' x x = 1 := f.to_localization_map.mk'_self _ lemma mk'_self'' {x : M} : f.mk' x.1 x = 1 := f.mk'_self' lemma mul_mk'_eq_mk'_of_mul (x y : R) (z : M) : f.to_map x * f.mk' y z = f.mk' (x * y) z := f.to_localization_map.mul_mk'_eq_mk'_of_mul _ _ _ lemma mk'_eq_mul_mk'_one (x : R) (y : M) : f.mk' x y = f.to_map x * f.mk' 1 y := (f.to_localization_map.mul_mk'_one_eq_mk' _ _).symm @[simp] lemma mk'_mul_cancel_left (x : R) (y : M) : f.mk' (y * x) y = f.to_map x := f.to_localization_map.mk'_mul_cancel_left _ _ lemma mk'_mul_cancel_right (x : R) (y : M) : f.mk' (x * y) y = f.to_map x := f.to_localization_map.mk'_mul_cancel_right _ _ @[simp] lemma mk'_mul_mk'_eq_one (x y : M) : f.mk' x y * f.mk' y x = 1 := by rw [←f.mk'_mul, mul_comm]; exact f.mk'_self _ lemma mk'_mul_mk'_eq_one' (x : R) (y : M) (h : x ∈ M) : f.mk' x y * f.mk' y ⟨x, h⟩ = 1 := f.mk'_mul_mk'_eq_one ⟨x, h⟩ _ lemma is_unit_comp (j : S →+* P) (y : M) : is_unit (j.comp f.to_map y) := f.to_localization_map.is_unit_comp j.to_monoid_hom _ /-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `comm_ring`s `g : R →+* P` such that `g(M) ⊆ units P`, `f x = f y → g x = g y` for all `x y : R`. -/ lemma eq_of_eq {g : R →+* P} (hg : ∀ y : M, is_unit (g y)) {x y} (h : f.to_map x = f.to_map y) : g x = g y := @submonoid.localization_map.eq_of_eq _ _ _ _ _ _ _ f.to_localization_map g.to_monoid_hom hg _ _ h lemma mk'_add (x₁ x₂ : R) (y₁ y₂ : M) : f.mk' (x₁ * y₂ + x₂ * y₁) (y₁ * y₂) = f.mk' x₁ y₁ + f.mk' x₂ y₂ := f.mk'_eq_iff_eq_mul.2 $ eq.symm begin rw [mul_comm (_ + _), mul_add, mul_mk'_eq_mk'_of_mul, ←eq_sub_iff_add_eq, mk'_eq_iff_eq_mul, mul_comm _ (f.to_map _), mul_sub, eq_sub_iff_add_eq, ←eq_sub_iff_add_eq', ←mul_assoc, ←f.to_map.map_mul, mul_mk'_eq_mk'_of_mul, mk'_eq_iff_eq_mul], simp only [f.to_map.map_add, submonoid.coe_mul, f.to_map.map_mul], ring_exp, end /-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `comm_ring`s `g : R →+* P` such that `g y` is invertible for all `y : M`, the homomorphism induced from `S` to `P` sending `z : S` to `g x * (g y)⁻¹`, where `(x, y) : R × M` are such that `z = f x * (f y)⁻¹`. -/ noncomputable def lift {g : R →+* P} (hg : ∀ y : M, is_unit (g y)) : S →+* P := ring_hom.mk' (@submonoid.localization_map.lift _ _ _ _ _ _ _ f.to_localization_map g.to_monoid_hom hg) $ begin intros x y, rw [f.to_localization_map.lift_spec, mul_comm, add_mul, ←sub_eq_iff_eq_add, eq_comm, f.to_localization_map.lift_spec_mul, mul_comm _ (_ - _), sub_mul, eq_sub_iff_add_eq', ←eq_sub_iff_add_eq, mul_assoc, f.to_localization_map.lift_spec_mul], show g _ * (g _ * g _) = g _ * (g _ * g _ - g _ * g _), repeat {rw ←g.map_mul}, rw [←g.map_sub, ←g.map_mul], apply f.eq_of_eq hg, erw [f.to_map.map_mul, sec_spec', mul_sub, f.to_map.map_sub], simp only [f.to_map.map_mul, sec_spec'], ring_exp, end variables {g : R →+* P} (hg : ∀ y : M, is_unit (g y)) /-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `comm_ring`s `g : R →* P` such that `g y` is invertible for all `y : M`, the homomorphism induced from `S` to `P` maps `f x * (f y)⁻¹` to `g x * (g y)⁻¹` for all `x : R, y ∈ M`. -/ lemma lift_mk' (x y) : f.lift hg (f.mk' x y) = g x * ↑(is_unit.lift_right (g.to_monoid_hom.mrestrict M) hg y)⁻¹ := f.to_localization_map.lift_mk' _ _ _ lemma lift_mk'_spec (x v) (y : M) : f.lift hg (f.mk' x y) = v ↔ g x = g y * v := f.to_localization_map.lift_mk'_spec _ _ _ _ @[simp] lemma lift_eq (x : R) : f.lift hg (f.to_map x) = g x := f.to_localization_map.lift_eq _ _ lemma lift_eq_iff {x y : R × M} : f.lift hg (f.mk' x.1 x.2) = f.lift hg (f.mk' y.1 y.2) ↔ g (x.1 * y.2) = g (y.1 * x.2) := f.to_localization_map.lift_eq_iff _ @[simp] lemma lift_comp : (f.lift hg).comp f.to_map = g := ring_hom.ext $ monoid_hom.ext_iff.1 $ f.to_localization_map.lift_comp _ @[simp] lemma lift_of_comp (j : S →+* P) : f.lift (f.is_unit_comp j) = j := ring_hom.ext $ monoid_hom.ext_iff.1 $ f.to_localization_map.lift_of_comp j.to_monoid_hom lemma epic_of_localization_map {j k : S →+* P} (h : ∀ a, j.comp f.to_map a = k.comp f.to_map a) : j = k := ring_hom.ext $ monoid_hom.ext_iff.1 $ @submonoid.localization_map.epic_of_localization_map _ _ _ _ _ _ _ f.to_localization_map j.to_monoid_hom k.to_monoid_hom h lemma lift_unique {j : S →+* P} (hj : ∀ x, j (f.to_map x) = g x) : f.lift hg = j := ring_hom.ext $ monoid_hom.ext_iff.1 $ @submonoid.localization_map.lift_unique _ _ _ _ _ _ _ f.to_localization_map g.to_monoid_hom hg j.to_monoid_hom hj @[simp] lemma lift_id (x) : f.lift f.map_units x = x := f.to_localization_map.lift_id _ /-- Given two localization maps `f : R →+* S, k : R →+* P` for a submonoid `M ⊆ R`, the hom from `P` to `S` induced by `f` is left inverse to the hom from `S` to `P` induced by `k`. -/ @[simp] lemma lift_left_inverse {k : localization_map M S} (z : S) : k.lift f.map_units (f.lift k.map_units z) = z := f.to_localization_map.lift_left_inverse _ lemma lift_surjective_iff : surjective (f.lift hg) ↔ ∀ v : P, ∃ x : R × M, v * g x.2 = g x.1 := f.to_localization_map.lift_surjective_iff hg lemma lift_injective_iff : injective (f.lift hg) ↔ ∀ x y, f.to_map x = f.to_map y ↔ g x = g y := f.to_localization_map.lift_injective_iff hg variables {T : submonoid P} (hy : ∀ y : M, g y ∈ T) {Q : Type*} [comm_ring Q] (k : localization_map T Q) /-- Given a `comm_ring` homomorphism `g : R →+* P` where for submonoids `M ⊆ R, T ⊆ P` we have `g(M) ⊆ T`, the induced ring homomorphism from the localization of `R` at `M` to the localization of `P` at `T`: if `f : R →+* S` and `k : P →+* Q` are localization maps for `M` and `T` respectively, we send `z : S` to `k (g x) * (k (g y))⁻¹`, where `(x, y) : R × M` are such that `z = f x * (f y)⁻¹`. -/ noncomputable def map : S →+* Q := @lift _ _ _ _ _ _ _ f (k.to_map.comp g) $ λ y, k.map_units ⟨g y, hy y⟩ variables {k} lemma map_eq (x) : f.map hy k (f.to_map x) = k.to_map (g x) := f.lift_eq (λ y, k.map_units ⟨g y, hy y⟩) x @[simp] lemma map_comp : (f.map hy k).comp f.to_map = k.to_map.comp g := f.lift_comp $ λ y, k.map_units ⟨g y, hy y⟩ lemma map_mk' (x) (y : M) : f.map hy k (f.mk' x y) = k.mk' (g x) ⟨g y, hy y⟩ := @submonoid.localization_map.map_mk' _ _ _ _ _ _ _ f.to_localization_map g.to_monoid_hom _ hy _ _ k.to_localization_map _ _ @[simp] lemma map_id (z : S) : f.map (λ y, show ring_hom.id R y ∈ M, from y.2) f z = z := f.lift_id _ /-- If `comm_ring` homs `g : R →+* P, l : P →+* A` induce maps of localizations, the composition of the induced maps equals the map of localizations induced by `l ∘ g`. -/ lemma map_comp_map {A : Type*} [comm_ring A] {U : submonoid A} {W} [comm_ring W] (j : localization_map U W) {l : P →+* A} (hl : ∀ w : T, l w ∈ U) : (k.map hl j).comp (f.map hy k) = f.map (λ x, show l.comp g x ∈ U, from hl ⟨g x, hy x⟩) j := ring_hom.ext $ monoid_hom.ext_iff.1 $ @submonoid.localization_map.map_comp_map _ _ _ _ _ _ _ f.to_localization_map g.to_monoid_hom _ hy _ _ k.to_localization_map _ _ _ _ _ j.to_localization_map l.to_monoid_hom hl /-- If `comm_ring` homs `g : R →+* P, l : P →+* A` induce maps of localizations, the composition of the induced maps equals the map of localizations induced by `l ∘ g`. -/ lemma map_map {A : Type*} [comm_ring A] {U : submonoid A} {W} [comm_ring W] (j : localization_map U W) {l : P →+* A} (hl : ∀ w : T, l w ∈ U) (x) : k.map hl j (f.map hy k x) = f.map (λ x, show l.comp g x ∈ U, from hl ⟨g x, hy x⟩) j x := by rw ←f.map_comp_map hy j hl; refl /-- Given localization maps `f : R →+* S, k : P →+* Q` for submonoids `M, T` respectively, an isomorphism `j : R ≃+* P` such that `j(M) = T` induces an isomorphism of localizations `S ≃+* Q`. -/ noncomputable def ring_equiv_of_ring_equiv (k : localization_map T Q) (h : R ≃+* P) (H : M.map h.to_monoid_hom = T) : S ≃+* Q := (f.to_localization_map.mul_equiv_of_mul_equiv k.to_localization_map H).to_ring_equiv $ (@lift _ _ _ _ _ _ _ f (k.to_map.comp h.to_ring_hom) (λ y, k.map_units ⟨(h y), H ▸ set.mem_image_of_mem h y.2⟩)).map_add @[simp] lemma ring_equiv_of_ring_equiv_eq_map_apply {j : R ≃+* P} (H : M.map j.to_monoid_hom = T) (x) : f.ring_equiv_of_ring_equiv k j H x = f.map (λ y : M, show j.to_monoid_hom y ∈ T, from H ▸ set.mem_image_of_mem j y.2) k x := rfl lemma ring_equiv_of_ring_equiv_eq_map {j : R ≃+* P} (H : M.map j.to_monoid_hom = T) : (f.ring_equiv_of_ring_equiv k j H).to_monoid_hom = f.map (λ y : M, show j.to_monoid_hom y ∈ T, from H ▸ set.mem_image_of_mem j y.2) k := rfl @[simp] lemma ring_equiv_of_ring_equiv_eq {j : R ≃+* P} (H : M.map j.to_monoid_hom = T) (x) : f.ring_equiv_of_ring_equiv k j H (f.to_map x) = k.to_map (j x) := f.to_localization_map.mul_equiv_of_mul_equiv_eq H _ lemma ring_equiv_of_ring_equiv_mk' {j : R ≃+* P} (H : M.map j.to_monoid_hom = T) (x y) : f.ring_equiv_of_ring_equiv k j H (f.mk' x y) = k.mk' (j x) ⟨j y, H ▸ set.mem_image_of_mem j y.2⟩ := f.to_localization_map.mul_equiv_of_mul_equiv_mk' H _ _ end localization_map namespace localization variables {M} instance : has_add (localization M) := ⟨λ z w, con.lift_on₂ z w (λ x y : R × M, mk ((x.2 : R) * y.1 + y.2 * x.1) (x.2 * y.2)) $ λ r1 r2 r3 r4 h1 h2, (con.eq _).2 begin rw r_eq_r' at h1 h2 ⊢, cases h1 with t₅ ht₅, cases h2 with t₆ ht₆, use t₆ * t₅, calc ((r1.2 : R) * r2.1 + r2.2 * r1.1) * (r3.2 * r4.2) * (t₆ * t₅) = (r2.1 * r4.2 * t₆) * (r1.2 * r3.2 * t₅) + (r1.1 * r3.2 * t₅) * (r2.2 * r4.2 * t₆) : by ring ... = (r3.2 * r4.1 + r4.2 * r3.1) * (r1.2 * r2.2) * (t₆ * t₅) : by rw [ht₆, ht₅]; ring end⟩ instance : has_neg (localization M) := ⟨λ z, con.lift_on z (λ x : R × M, mk (-x.1) x.2) $ λ r1 r2 h, (con.eq _).2 begin rw r_eq_r' at h ⊢, cases h with t ht, use t, rw [neg_mul_eq_neg_mul_symm, neg_mul_eq_neg_mul_symm, ht], ring, end⟩ instance : has_zero (localization M) := ⟨mk 0 1⟩ private meta def tac := `[{ intros, refine quotient.sound' (r_of_eq _), simp only [prod.snd_mul, prod.fst_mul, submonoid.coe_mul], ring }] instance : comm_ring (localization M) := { zero := 0, one := 1, add := (+), mul := (*), add_assoc := λ m n k, quotient.induction_on₃' m n k (by tac), zero_add := λ y, quotient.induction_on' y (by tac), add_zero := λ y, quotient.induction_on' y (by tac), neg := has_neg.neg, add_left_neg := λ y, quotient.induction_on' y (by tac), add_comm := λ y z, quotient.induction_on₂' z y (by tac), left_distrib := λ m n k, quotient.induction_on₃' m n k (by tac), right_distrib := λ m n k, quotient.induction_on₃' m n k (by tac), ..localization.comm_monoid M } variables (M) /-- Natural hom sending `x : R`, `R` a `comm_ring`, to the equivalence class of `(x, 1)` in the localization of `R` at a submonoid. -/ def of : localization_map M (localization M) := (localization.monoid_of M).to_ring_localization $ λ x y, (con.eq _).2 $ r_of_eq $ by simp [add_comm] variables {M} lemma monoid_of_eq_of (x) : (monoid_of M).to_map x = (of M).to_map x := rfl lemma mk_one_eq_of (x) : mk x 1 = (of M).to_map x := rfl lemma mk_eq_mk'_apply (x y) : mk x y = (of M).mk' x y := mk_eq_monoid_of_mk'_apply _ _ @[simp] lemma mk_eq_mk' : mk = (of M).mk' := mk_eq_monoid_of_mk' variables (f : localization_map M S) /-- Given a localization map `f : R →+* S` for a submonoid `M`, we get an isomorphism between the localization of `R` at `M` as a quotient type and `S`. -/ noncomputable def ring_equiv_of_quotient : localization M ≃+* S := (mul_equiv_of_quotient f.to_localization_map).to_ring_equiv $ ((of M).lift f.map_units).map_add variables {f} @[simp] lemma ring_equiv_of_quotient_apply (x) : ring_equiv_of_quotient f x = (of M).lift f.map_units x := rfl @[simp] lemma ring_equiv_of_quotient_mk' (x y) : ring_equiv_of_quotient f ((of M).mk' x y) = f.mk' x y := mul_equiv_of_quotient_mk' _ _ lemma ring_equiv_of_quotient_mk (x y) : ring_equiv_of_quotient f (mk x y) = f.mk' x y := mul_equiv_of_quotient_mk _ _ @[simp] lemma ring_equiv_of_quotient_of (x) : ring_equiv_of_quotient f ((of M).to_map x) = f.to_map x := mul_equiv_of_quotient_monoid_of _ @[simp] lemma ring_equiv_of_quotient_symm_mk' (x y) : (ring_equiv_of_quotient f).symm (f.mk' x y) = (of M).mk' x y := mul_equiv_of_quotient_symm_mk' _ _ lemma ring_equiv_of_quotient_symm_mk (x y) : (ring_equiv_of_quotient f).symm (f.mk' x y) = mk x y := mul_equiv_of_quotient_symm_mk _ _ @[simp] lemma ring_equiv_of_quotient_symm_of (x) : (ring_equiv_of_quotient f).symm (f.to_map x) = (of M).to_map x := mul_equiv_of_quotient_symm_monoid_of _ end localization variables {M} section at_prime variables (I : ideal R) [hp : I.is_prime] include hp namespace ideal /-- The complement of a prime ideal `I ⊆ R` is a submonoid of `R`. -/ def prime_compl : submonoid R := { carrier := (Iᶜ : set R), one_mem' := by convert I.ne_top_iff_one.1 hp.1; refl, mul_mem' := λ x y hnx hny hxy, or.cases_on (hp.2 hxy) hnx hny } end ideal namespace localization_map variables (S) /-- A localization map from `R` to `S` where the submonoid is the complement of a prime ideal of `R`. -/ @[reducible] def at_prime := localization_map I.prime_compl S end localization_map namespace localization /-- The localization of `R` at the complement of a prime ideal, as a quotient type. -/ @[reducible] def at_prime := localization I.prime_compl end localization namespace localization_map variables {I} /-- When `f` is a localization map from `R` at the complement of a prime ideal `I`, we use a copy of the localization map `f`'s codomain `S` carrying the data of `f` so that the `local_ring` instance on `S` can 'know' the map needed to induce the instance. -/ instance at_prime.local_ring (f : at_prime S I) : local_ring f.codomain := local_of_nonunits_ideal (λ hze, begin rw [←f.to_map.map_one, ←f.to_map.map_zero] at hze, obtain ⟨t, ht⟩ := f.eq_iff_exists.1 hze, exact ((show (t : R) ∉ I, from t.2) (have htz : (t : R) = 0, by simpa using ht.symm, htz.symm ▸ I.zero_mem)) end) (begin intros x y hx hy hu, cases is_unit_iff_exists_inv.1 hu with z hxyz, have : ∀ {r s}, f.mk' r s ∈ nonunits S → r ∈ I, from λ r s, (@not_imp_comm _ _ (classical.dec _) (classical.dec _)).1 (λ nr, is_unit_iff_exists_inv.2 ⟨f.mk' s ⟨r, nr⟩, f.mk'_mul_mk'_eq_one' _ _ nr⟩), rcases f.mk'_surjective x with ⟨rx, sx, hrx⟩, rcases f.mk'_surjective y with ⟨ry, sy, hry⟩, rcases f.mk'_surjective z with ⟨rz, sz, hrz⟩, rw [←hrx, ←hry, ←hrz, ←f.mk'_add, ←f.mk'_mul, ←f.mk'_self I.prime_compl.one_mem] at hxyz, rw ←hrx at hx, rw ←hry at hy, cases f.eq.1 hxyz with t ht, simp only [mul_one, one_mul, submonoid.coe_mul, subtype.coe_mk] at ht, rw [←sub_eq_zero, ←sub_mul] at ht, have hr := (hp.mem_or_mem_of_mul_eq_zero ht).resolve_right t.2, have := I.neg_mem_iff.1 ((ideal.add_mem_iff_right _ _).1 hr), { exact not_or (mt hp.mem_or_mem (not_or sx.2 sy.2)) sz.2 (hp.mem_or_mem this)}, { exact I.mul_mem_right (I.add_mem (I.mul_mem_right (this hx)) (I.mul_mem_right (this hy)))} end) end localization_map namespace localization /-- The localization of `R` at the complement of a prime ideal is a local ring. -/ instance at_prime.local_ring : local_ring (localization I.prime_compl) := localization_map.at_prime.local_ring (of I.prime_compl) end localization end at_prime namespace localization_map variables (f : localization_map M S) section ideals theorem map_comap (J : ideal S) : ideal.map f.to_map (ideal.comap f.to_map J) = J := le_antisymm (ideal.map_le_iff_le_comap.2 (le_refl _)) $ λ x hJ, begin obtain ⟨r, s, hx⟩ := f.mk'_surjective x, rw ←hx at ⊢ hJ, exact ideal.mul_mem_right _ (ideal.mem_map_of_mem (show f.to_map r ∈ J, from f.mk'_spec r s ▸ @ideal.mul_mem_right _ _ J (f.mk' r s) (f.to_map s) hJ)), end /-- If `S` is the localization of `R` at a submonoid, the ordering of ideals of `S` is embedded in the ordering of ideals of `R`. -/ def le_order_embedding : ((≤) : ideal S → ideal S → Prop) ≼o ((≤) : ideal R → ideal R → Prop) := { to_fun := λ J, ideal.comap f.to_map J, inj' := function.left_inverse.injective f.map_comap, ord' := λ J₁ J₂, ⟨ideal.comap_mono, λ hJ, f.map_comap J₁ ▸ f.map_comap J₂ ▸ ideal.map_mono hJ⟩ } end ideals /-! ### `algebra` section Defines the `R`-algebra instance on a copy of `S` carrying the data of the localization map `f` needed to induce the `R`-algebra structure. -/ /-- We use a copy of the localization map `f`'s codomain `S` carrying the data of `f` so that the `R`-algebra instance on `S` can 'know' the map needed to induce the `R`-algebra structure. -/ instance : algebra R f.codomain := f.to_map.to_algebra end localization_map namespace localization instance : algebra R (localization M) := localization_map.algebra (of M) end localization namespace localization_map variables (f : localization_map M S) @[simp] lemma of_id (a : R) : (algebra.of_id R f.codomain) a = f.to_map a := rfl @[simp] lemma algebra_map_eq : algebra_map R f.codomain = f.to_map := rfl variables (f) /-- Localization map `f` from `R` to `S` as an `R`-linear map. -/ def lin_coe : R →ₗ[R] f.codomain := { to_fun := f.to_map, map_add' := f.to_map.map_add, map_smul' := f.to_map.map_mul } variables {f} instance coe_submodules : has_coe (ideal R) (submodule R f.codomain) := ⟨λ I, submodule.map f.lin_coe I⟩ lemma mem_coe (I : ideal R) {x : S} : x ∈ (I : submodule R f.codomain) ↔ ∃ y : R, y ∈ I ∧ f.to_map y = x := iff.rfl @[simp] lemma lin_coe_apply {x} : f.lin_coe x = f.to_map x := rfl variables {g : R →+* P} variables {T : submonoid P} (hy : ∀ y : M, g y ∈ T) {Q : Type*} [comm_ring Q] (k : localization_map T Q) lemma map_smul (x : f.codomain) (z : R) : f.map hy k (z • x : f.codomain) = @has_scalar.smul P k.codomain _ (g z) (f.map hy k x) := show f.map hy k (f.to_map z * x) = k.to_map (g z) * f.map hy k x, by rw [ring_hom.map_mul, map_eq] section integer_normalization open finsupp polynomial open_locale classical /-- `coeff_integer_normalization p` gives the coefficients of the polynomial `integer_normalization p` -/ noncomputable def coeff_integer_normalization (p : polynomial f.codomain) (i : ℕ) : R := if hi : i ∈ p.support then classical.some (classical.some_spec (f.exist_integer_multiples_of_finset (p.support.image p.coeff)) (p.coeff i) (finset.mem_image.mpr ⟨i, hi, rfl⟩)) else 0 lemma coeff_integer_normalization_mem_support (p : polynomial f.codomain) (i : ℕ) (h : coeff_integer_normalization p i ≠ 0) : i ∈ p.support := begin contrapose h, rw [ne.def, not_not, coeff_integer_normalization, dif_neg h] end /-- `integer_normalization g` normalizes `g` to have integer coefficients by clearing the denominators -/ noncomputable def integer_normalization : polynomial f.codomain → polynomial R := λ p, on_finset p.support (coeff_integer_normalization p) (coeff_integer_normalization_mem_support p) @[simp] lemma integer_normalization_coeff (p : polynomial f.codomain) (i : ℕ) : (integer_normalization p).coeff i = coeff_integer_normalization p i := rfl lemma integer_normalization_spec (p : polynomial f.codomain) : ∃ (b : M), ∀ i, f.to_map ((integer_normalization p).coeff i) = f.to_map b * p.coeff i := begin use classical.some (f.exist_integer_multiples_of_finset (p.support.image p.coeff)), intro i, rw [integer_normalization_coeff, coeff_integer_normalization], split_ifs with hi, { exact classical.some_spec (classical.some_spec (f.exist_integer_multiples_of_finset (p.support.image p.coeff)) (p.coeff i) (finset.mem_image.mpr ⟨i, hi, rfl⟩)) }, { convert (_root_.mul_zero (f.to_map _)).symm, { exact f.to_ring_hom.map_zero }, { exact finsupp.not_mem_support_iff.mp hi } } end lemma integer_normalization_map_to_map (p : polynomial f.codomain) : ∃ (b : M), (integer_normalization p).map f.to_map = f.to_map b • p := let ⟨b, hb⟩ := integer_normalization_spec p in ⟨b, polynomial.ext (λ i, by { rw coeff_map, exact hb i })⟩ variables {R' : Type*} [comm_ring R'] lemma integer_normalization_eval₂_eq_zero (g : f.codomain →+* R') (p : polynomial f.codomain) {x : R'} (hx : eval₂ g x p = 0) : eval₂ (g.comp f.to_map) x (integer_normalization p) = 0 := let ⟨b, hb⟩ := integer_normalization_map_to_map p in trans (eval₂_map f.to_map g x).symm (by rw [hb, eval₂_smul, hx, smul_zero]) lemma integer_normalization_aeval_eq_zero [algebra R R'] [algebra f.codomain R'] [is_algebra_tower R f.codomain R'] (p : polynomial f.codomain) {x : R'} (hx : aeval _ _ x p = 0) : aeval _ R' x (integer_normalization p) = 0 := by rw [aeval_def, is_algebra_tower.algebra_map_eq R f.codomain R', algebra_map_eq, integer_normalization_eval₂_eq_zero _ _ hx] end integer_normalization end localization_map variables (R) /-- The submonoid of non-zero-divisors of a `comm_ring` `R`. -/ def non_zero_divisors : submonoid R := { carrier := {x | ∀ z, z * x = 0 → z = 0}, one_mem' := λ z hz, by rwa mul_one at hz, mul_mem' := λ x₁ x₂ hx₁ hx₂ z hz, have z * x₁ * x₂ = 0, by rwa mul_assoc, hx₁ z $ hx₂ (z * x₁) this } variables {R} lemma mul_mem_non_zero_divisors {a b : R} : a * b ∈ non_zero_divisors R ↔ a ∈ non_zero_divisors R ∧ b ∈ non_zero_divisors R := begin split, { intro h, split; intros x h'; apply h, { rw [←mul_assoc, h', zero_mul] }, { rw [mul_comm a b, ←mul_assoc, h', zero_mul] } }, { rintros ⟨ha, hb⟩ x hx, apply ha, apply hb, rw [mul_assoc, hx] }, end variables (R) {A : Type*} [integral_domain A] lemma eq_zero_of_ne_zero_of_mul_eq_zero {x y : A} (hnx : x ≠ 0) (hxy : y * x = 0) : y = 0 := or.resolve_right (eq_zero_or_eq_zero_of_mul_eq_zero hxy) hnx lemma mem_non_zero_divisors_iff_ne_zero {x : A} : x ∈ non_zero_divisors A ↔ x ≠ 0 := ⟨λ hm hz, zero_ne_one (hm 1 $ by rw [hz, one_mul]).symm, λ hnx z, eq_zero_of_ne_zero_of_mul_eq_zero hnx⟩ lemma map_ne_zero_of_mem_non_zero_divisors {B : Type*} [ring B] {g : A →+* B} (hg : injective g) {x : non_zero_divisors A} : g x ≠ 0 := λ h0, mem_non_zero_divisors_iff_ne_zero.1 x.2 $ g.injective_iff.1 hg x h0 lemma map_mem_non_zero_divisors {B : Type*} [integral_domain B] {g : A →+* B} (hg : injective g) {x : non_zero_divisors A} : g x ∈ non_zero_divisors B := λ z hz, eq_zero_of_ne_zero_of_mul_eq_zero (map_ne_zero_of_mem_non_zero_divisors hg) hz variables (K : Type*) /-- Localization map from an integral domain `R` to its field of fractions. -/ @[reducible] def fraction_map [comm_ring K] := localization_map (non_zero_divisors R) K namespace fraction_map open localization_map variables {R K} lemma to_map_eq_zero_iff [comm_ring K] (φ : fraction_map R K) {x : R} : x = 0 ↔ φ.to_map x = 0 := begin rw ← φ.to_map.map_zero, split; intro h, { rw h }, { cases φ.eq_iff_exists.mp h with c hc, rw zero_mul at hc, exact c.2 x hc } end protected theorem injective [comm_ring K] (φ : fraction_map R K) : injective φ.to_map := φ.to_map.injective_iff.2 (λ _ h, φ.to_map_eq_zero_iff.mpr h) protected lemma map_ne_zero_of_mem_non_zero_divisors [comm_ring K] (φ : fraction_map A K) (x : non_zero_divisors A) : φ.to_map x ≠ 0 := map_ne_zero_of_mem_non_zero_divisors φ.injective local attribute [instance] classical.dec_eq /-- A `comm_ring` `K` which is the localization of an integral domain `R` at `R - {0}` is an integral domain. -/ def to_integral_domain [comm_ring K] (φ : fraction_map A K) : integral_domain K := { eq_zero_or_eq_zero_of_mul_eq_zero := begin intros z w h, cases φ.surj z with x hx, cases φ.surj w with y hy, have : z * w * φ.to_map y.2 * φ.to_map x.2 = φ.to_map x.1 * φ.to_map y.1, by rw [mul_assoc z, hy, ←hx]; ac_refl, erw h at this, rw [zero_mul, zero_mul, ←φ.to_map.map_mul] at this, cases eq_zero_or_eq_zero_of_mul_eq_zero (φ.to_map_eq_zero_iff.mpr this.symm) with H H, { exact or.inl (φ.eq_zero_of_fst_eq_zero hx H) }, { exact or.inr (φ.eq_zero_of_fst_eq_zero hy H) }, end, exists_pair_ne := ⟨φ.to_map 0, φ.to_map 1, λ h, zero_ne_one (φ.injective h)⟩, ..(infer_instance : comm_ring K) } /-- The inverse of an element in the field of fractions of an integral domain. -/ protected noncomputable def inv [comm_ring K] (φ : fraction_map A K) (z : K) : K := if h : z = 0 then 0 else φ.mk' (φ.to_localization_map.sec z).2 ⟨(φ.to_localization_map.sec z).1, mem_non_zero_divisors_iff_ne_zero.2 $ λ h0, h $ φ.eq_zero_of_fst_eq_zero (sec_spec z) h0⟩ protected lemma mul_inv_cancel [comm_ring K] (φ : fraction_map A K) (x : K) (hx : x ≠ 0) : x * φ.inv x = 1 := show x * dite _ _ _ = 1, by rw [dif_neg hx, ←is_unit.mul_left_inj (φ.map_units ⟨(φ.to_localization_map.sec x).1, mem_non_zero_divisors_iff_ne_zero.2 $ λ h0, hx $ φ.eq_zero_of_fst_eq_zero (sec_spec x) h0⟩), one_mul, mul_assoc, mk'_spec, ←eq_mk'_iff_mul_eq]; exact (φ.mk'_sec x).symm /-- A `comm_ring` `K` which is the localization of an integral domain `R` at `R - {0}` is a field. -/ noncomputable def to_field [comm_ring K] (φ : fraction_map A K) : field K := { inv := φ.inv, mul_inv_cancel := φ.mul_inv_cancel, inv_zero := dif_pos rfl, ..φ.to_integral_domain } variables {B : Type*} [integral_domain B] [field K] {L : Type*} [field L] (f : fraction_map A K) {g : A →+* L} lemma mk'_eq_div {r s} : f.mk' r s = f.to_map r / f.to_map s := f.mk'_eq_iff_eq_mul.2 $ (div_mul_cancel _ (f.map_ne_zero_of_mem_non_zero_divisors _)).symm lemma is_unit_map_of_injective (hg : injective g) (y : non_zero_divisors A) : is_unit (g y) := is_unit.mk0 (g y) $ map_ne_zero_of_mem_non_zero_divisors hg /-- Given an integral domain `A`, a localization map to its fields of fractions `f : A →+* K`, and an injective ring hom `g : A →+* L` where `L` is a field, we get a field hom sending `z : K` to `g x * (g y)⁻¹`, where `(x, y) : A × (non_zero_divisors A)` are such that `z = f x * (f y)⁻¹`. -/ noncomputable def lift (hg : injective g) : K →+* L := f.lift $ is_unit_map_of_injective hg /-- Given an integral domain `A`, a localization map to its fields of fractions `f : A →+* K`, and an injective ring hom `g : A →+* L` where `L` is a field, field hom induced from `K` to `L` maps `f x / f y` to `g x / g y` for all `x : A, y ∈ non_zero_divisors A`. -/ @[simp] lemma lift_mk' (hg : injective g) (x y) : f.lift hg (f.mk' x y) = g x / g y := begin erw f.lift_mk' (is_unit_map_of_injective hg), erw submonoid.localization_map.mul_inv_left (λ y : non_zero_divisors A, show is_unit (g.to_monoid_hom y), from is_unit_map_of_injective hg y), exact (mul_div_cancel' _ (map_ne_zero_of_mem_non_zero_divisors hg)).symm, end /-- Given integral domains `A, B` and localization maps to their fields of fractions `f : A →+* K, g : B →+* L` and an injective ring hom `j : A →+* B`, we get a field hom sending `z : K` to `g (j x) * (g (j y))⁻¹`, where `(x, y) : A × (non_zero_divisors A)` are such that `z = f x * (f y)⁻¹`. -/ noncomputable def map (g : fraction_map B L) {j : A →+* B} (hj : injective j) : K →+* L := f.map (λ y, mem_non_zero_divisors_iff_ne_zero.2 $ map_ne_zero_of_mem_non_zero_divisors hj) g /-- Given integral domains `A, B` and localization maps to their fields of fractions `f : A →+* K, g : B →+* L`, an isomorphism `j : A ≃+* B` induces an isomorphism of fields of fractions `K ≃+* L`. -/ noncomputable def field_equiv_of_ring_equiv (g : fraction_map B L) (h : A ≃+* B) : K ≃+* L := f.ring_equiv_of_ring_equiv g h begin ext b, show b ∈ h.to_equiv '' _ ↔ _, erw [h.to_equiv.image_eq_preimage, set.preimage, set.mem_set_of_eq, mem_non_zero_divisors_iff_ne_zero, mem_non_zero_divisors_iff_ne_zero], exact h.symm.map_ne_zero_iff end /-- The cast from `int` to `rat` as a `fraction_map`. -/ def int.fraction_map : fraction_map ℤ ℚ := { to_fun := coe, map_units' := begin rintro ⟨x, hx⟩, rw [submonoid.mem_carrier, mem_non_zero_divisors_iff_ne_zero] at hx, simpa only [is_unit_iff_ne_zero, int.cast_eq_zero, ne.def, subtype.coe_mk] using hx, end, surj' := begin rintro ⟨n, d, hd, h⟩, refine ⟨⟨n, ⟨d, _⟩⟩, rat.mul_denom_eq_num⟩, rwa [submonoid.mem_carrier, mem_non_zero_divisors_iff_ne_zero, int.coe_nat_ne_zero_iff_pos] end, eq_iff_exists' := begin intros x y, rw [int.cast_inj], refine ⟨by { rintro rfl, use 1 }, _⟩, rintro ⟨⟨c, hc⟩, h⟩, apply int.eq_of_mul_eq_mul_right _ h, rwa [submonoid.mem_carrier, mem_non_zero_divisors_iff_ne_zero] at hc, end, ..int.cast_ring_hom ℚ } lemma integer_normalization_eq_zero_iff {p : polynomial f.codomain} : integer_normalization p = 0 ↔ p = 0 := begin refine (polynomial.ext_iff.trans (polynomial.ext_iff.trans _).symm), obtain ⟨⟨b, nonzero⟩, hb⟩ := integer_normalization_spec p, split; intros h i, { apply f.to_map_eq_zero_iff.mpr, rw [hb i, h i], exact _root_.mul_zero _ }, { have hi := h i, rw [polynomial.coeff_zero, f.to_map_eq_zero_iff, hb i] at hi, apply or.resolve_left (eq_zero_or_eq_zero_of_mul_eq_zero hi), intro h, apply mem_non_zero_divisors_iff_ne_zero.mp nonzero, exact f.to_map_eq_zero_iff.mpr h } end /-- A field is algebraic over the ring `A` iff it is algebraic over the field of fractions of `A`. -/ lemma comap_is_algebraic_iff [algebra A L] [algebra f.codomain L] [is_algebra_tower A f.codomain L] : algebra.is_algebraic A L ↔ algebra.is_algebraic f.codomain L := begin split; intros h x; obtain ⟨p, hp, px⟩ := h x, { refine ⟨p.map f.to_map, λ h, hp (polynomial.ext (λ i, _)), _⟩, { have : f.to_map (p.coeff i) = 0 := trans (polynomial.coeff_map _ _).symm (by simp [h]), exact f.to_map_eq_zero_iff.mpr this }, { rwa [is_algebra_tower.aeval_apply _ f.codomain, algebra_map_eq] at px } }, { exact ⟨integer_normalization p, mt f.integer_normalization_eq_zero_iff.mp hp, integer_normalization_aeval_eq_zero p px⟩ }, end section num_denom variables [unique_factorization_domain A] (φ : fraction_map A K) lemma exists_reduced_fraction (x : φ.codomain) : ∃ (a : A) (b : non_zero_divisors A), (∀ {d}, d ∣ a → d ∣ b → is_unit d) ∧ φ.mk' a b = x := begin obtain ⟨⟨b, b_nonzero⟩, a, hab⟩ := φ.exists_integer_multiple x, obtain ⟨a', b', c', no_factor, rfl, rfl⟩ := unique_factorization_domain.exists_reduced_factors' a b (mem_non_zero_divisors_iff_ne_zero.mp b_nonzero), obtain ⟨c'_nonzero, b'_nonzero⟩ := mul_mem_non_zero_divisors.mp b_nonzero, refine ⟨a', ⟨b', b'_nonzero⟩, @no_factor, _⟩, apply mul_left_cancel' (φ.map_ne_zero_of_mem_non_zero_divisors ⟨c' * b', b_nonzero⟩), simp only [subtype.coe_mk, φ.to_map.map_mul] at *, erw [←hab, mul_assoc, φ.mk'_spec' a' ⟨b', b'_nonzero⟩], end /-- `f.num x` is the numerator of `x : f.codomain` as a reduced fraction. -/ noncomputable def num (x : φ.codomain) : A := classical.some (φ.exists_reduced_fraction x) /-- `f.num x` is the denominator of `x : f.codomain` as a reduced fraction. -/ noncomputable def denom (x : φ.codomain) : non_zero_divisors A := classical.some (classical.some_spec (φ.exists_reduced_fraction x)) lemma num_denom_reduced (x : φ.codomain) : ∀ {d}, d ∣ φ.num x → d ∣ φ.denom x → is_unit d := (classical.some_spec (classical.some_spec (φ.exists_reduced_fraction x))).1 @[simp] lemma mk'_num_denom (x : φ.codomain) : φ.mk' (φ.num x) (φ.denom x) = x := (classical.some_spec (classical.some_spec (φ.exists_reduced_fraction x))).2 lemma num_mul_denom_eq_num_iff_eq {x y : φ.codomain} : x * φ.to_map (φ.denom y) = φ.to_map (φ.num y) ↔ x = y := ⟨ λ h, by simpa only [mk'_num_denom] using φ.eq_mk'_iff_mul_eq.mpr h, λ h, φ.eq_mk'_iff_mul_eq.mp (by rw [h, mk'_num_denom]) ⟩ lemma num_mul_denom_eq_num_iff_eq' {x y : φ.codomain} : y * φ.to_map (φ.denom x) = φ.to_map (φ.num x) ↔ x = y := ⟨ λ h, by simpa only [eq_comm, mk'_num_denom] using φ.eq_mk'_iff_mul_eq.mpr h, λ h, φ.eq_mk'_iff_mul_eq.mp (by rw [h, mk'_num_denom]) ⟩ lemma num_mul_denom_eq_num_mul_denom_iff_eq {x y : φ.codomain} : φ.num y * φ.denom x = φ.num x * φ.denom y ↔ x = y := ⟨ λ h, by simpa only [mk'_num_denom] using φ.mk'_eq_of_eq h, λ h, by rw h ⟩ lemma eq_zero_of_num_eq_zero {x : φ.codomain} (h : φ.num x = 0) : x = 0 := φ.num_mul_denom_eq_num_iff_eq'.mp (by rw [zero_mul, h, ring_hom.map_zero]) lemma is_integer_of_is_unit_denom {x : φ.codomain} (h : is_unit (φ.denom x : A)) : φ.is_integer x := begin cases h with d hd, have d_ne_zero : φ.to_map (φ.denom x) ≠ 0 := φ.map_ne_zero_of_mem_non_zero_divisors (φ.denom x), use ↑d⁻¹ * φ.num x, refine trans _ (φ.mk'_num_denom x), rw [φ.to_map.map_mul, φ.to_map.map_units_inv, hd], apply mul_left_cancel' d_ne_zero, rw [←mul_assoc, mul_inv_cancel d_ne_zero, one_mul, φ.mk'_spec'] end lemma is_unit_denom_of_num_eq_zero {x : φ.codomain} (h : φ.num x = 0) : is_unit (φ.denom x : A) := φ.num_denom_reduced x (h.symm ▸ dvd_zero _) (dvd_refl _) end num_denom end fraction_map namespace integral_closure variables {L : Type*} [field K] [field L] {f : fraction_map A K} open algebra /-- If the field `L` is an algebraic extension of the integral domain `A`, the integral closure of `A` in `L` has fraction field `L`. -/ def fraction_map_of_algebraic [algebra A L] (alg : is_algebraic A L) (inj : ∀ x, algebra_map A L x = 0 → x = 0) : fraction_map (integral_closure A L) L := (algebra_map (integral_closure A L) L).to_localization_map (λ ⟨⟨y, integral⟩, nonzero⟩, have y ≠ 0 := λ h, mem_non_zero_divisors_iff_ne_zero.mp nonzero (subtype.ext_iff_val.mpr h), show is_unit y, from ⟨⟨y, y⁻¹, mul_inv_cancel this, inv_mul_cancel this⟩, rfl⟩) (λ z, let ⟨x, y, hy, hxy⟩ := exists_integral_multiple (alg z) inj in ⟨⟨x, ⟨y, mem_non_zero_divisors_iff_ne_zero.mpr hy⟩⟩, hxy⟩) (λ x y, ⟨ λ (h : x.1 = y.1), ⟨1, by simpa using subtype.ext_iff_val.mpr h⟩, λ ⟨c, hc⟩, congr_arg (algebra_map _ L) (mul_right_cancel' (mem_non_zero_divisors_iff_ne_zero.mp c.2) hc) ⟩) /-- If the field `L` is a finite extension of the fraction field of the integral domain `A`, the integral closure of `A` in `L` has fraction field `L`. -/ def fraction_map_of_finite_extension [algebra A L] [algebra f.codomain L] [is_algebra_tower A f.codomain L] [finite_dimensional f.codomain L] : fraction_map (integral_closure A L) L := fraction_map_of_algebraic (f.comap_is_algebraic_iff.mpr is_algebraic_of_finite) (λ x hx, f.to_map_eq_zero_iff.mpr ((algebra_map f.codomain L).map_eq_zero.mp $ (is_algebra_tower.algebra_map_apply _ _ _ _).symm.trans hx)) end integral_closure variables (A) /-- The fraction field of an integral domain as a quotient type. -/ @[reducible] def fraction_ring := localization (non_zero_divisors A) /-- Natural hom sending `x : A`, `A` an integral domain, to the equivalence class of `(x, 1)` in the field of fractions of `A`. -/ def of : fraction_map A (localization (non_zero_divisors A)) := localization.of (non_zero_divisors A) namespace fraction_ring variables {A} noncomputable instance : field (fraction_ring A) := (of A).to_field @[simp] lemma mk_eq_div {r s} : (localization.mk r s : fraction_ring A) = ((of A).to_map r / (of A).to_map s : fraction_ring A) := by erw [localization.mk_eq_mk', (of A).mk'_eq_div] /-- Given an integral domain `A` and a localization map to a field of fractions `f : A →+* K`, we get an isomorphism between the field of fractions of `A` as a quotient type and `K`. -/ noncomputable def field_equiv_of_quotient {K : Type*} [field K] (f : fraction_map A K) : fraction_ring A ≃+* K := localization.ring_equiv_of_quotient f end fraction_ring
f2cda7109523b77d683c102e6f4916f037b7a579
9dc8cecdf3c4634764a18254e94d43da07142918
/src/data/finset/interval.lean
7fee4058a7f0bd44ac2ba8e08ef935177823e902
[ "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
3,611
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 -/ import data.finset.locally_finite /-! # Intervals of finsets as finsets This file provides the `locally_finite_order` instance for `finset α` and calculates the cardinality of finite intervals of finsets. If `s t : finset α`, then `finset.Icc s t` is the finset of finsets which include `s` and are included in `t`. For example, `finset.Icc {0, 1} {0, 1, 2, 3} = {{0, 1}, {0, 1, 2}, {0, 1, 3}, {0, 1, 2, 3}}` and `finset.Icc {0, 1, 2} {0, 1, 3} = {}`. -/ variables {α : Type*} namespace finset variables [decidable_eq α] (s t : finset α) instance : locally_finite_order (finset α) := { finset_Icc := λ s t, t.powerset.filter ((⊆) s), finset_Ico := λ s t, t.ssubsets.filter ((⊆) s), finset_Ioc := λ s t, t.powerset.filter ((⊂) s), finset_Ioo := λ s t, t.ssubsets.filter ((⊂) s), finset_mem_Icc := λ s t u, by {rw [mem_filter, mem_powerset], exact and_comm _ _ }, finset_mem_Ico := λ s t u, by {rw [mem_filter, mem_ssubsets], exact and_comm _ _ }, finset_mem_Ioc := λ s t u, by {rw [mem_filter, mem_powerset], exact and_comm _ _ }, finset_mem_Ioo := λ s t u, by {rw [mem_filter, mem_ssubsets], exact and_comm _ _ } } lemma Icc_eq_filter_powerset : Icc s t = t.powerset.filter ((⊆) s) := rfl lemma Ico_eq_filter_ssubsets : Ico s t = t.ssubsets.filter ((⊆) s) := rfl lemma Ioc_eq_filter_powerset : Ioc s t = t.powerset.filter ((⊂) s) := rfl lemma Ioo_eq_filter_ssubsets : Ioo s t = t.ssubsets.filter ((⊂) s) := rfl lemma Iic_eq_powerset : Iic s = s.powerset := filter_true_of_mem $ λ t _, empty_subset t lemma Iio_eq_ssubsets : Iio s = s.ssubsets := filter_true_of_mem $ λ t _, empty_subset t variables {s t} lemma Icc_eq_image_powerset (h : s ⊆ t) : Icc s t = (t \ s).powerset.image ((∪) s) := begin ext u, simp_rw [mem_Icc, mem_image, exists_prop, mem_powerset], split, { rintro ⟨hs, ht⟩, exact ⟨u \ s, sdiff_le_sdiff_right ht, sup_sdiff_cancel_right hs⟩ }, { rintro ⟨v, hv, rfl⟩, exact ⟨le_sup_left, union_subset h $ hv.trans $ sdiff_subset _ _⟩ } end lemma Ico_eq_image_ssubsets (h : s ⊆ t) : Ico s t = (t \ s).ssubsets.image ((∪) s) := begin ext u, simp_rw [mem_Ico, mem_image, exists_prop, mem_ssubsets], split, { rintro ⟨hs, ht⟩, exact ⟨u \ s, sdiff_lt_sdiff_right ht hs, sup_sdiff_cancel_right hs⟩ }, { rintro ⟨v, hv, rfl⟩, exact ⟨le_sup_left, sup_lt_of_lt_sdiff_left hv h⟩ } end /-- Cardinality of a non-empty `Icc` of finsets. -/ lemma card_Icc_finset (h : s ⊆ t) : (Icc s t).card = 2 ^ (t.card - s.card) := begin rw [←card_sdiff h, ←card_powerset, Icc_eq_image_powerset h, finset.card_image_iff], rintro u hu v hv (huv : s ⊔ u = s ⊔ v), rw [mem_coe, mem_powerset] at hu hv, rw [←(disjoint_sdiff.mono_right hu : disjoint s u).sup_sdiff_cancel_left, ←(disjoint_sdiff.mono_right hv : disjoint s v).sup_sdiff_cancel_left, huv], end /-- Cardinality of an `Ico` of finsets. -/ lemma card_Ico_finset (h : s ⊆ t) : (Ico s t).card = 2 ^ (t.card - s.card) - 1 := by rw [card_Ico_eq_card_Icc_sub_one, card_Icc_finset h] /-- Cardinality of an `Ioc` of finsets. -/ lemma card_Ioc_finset (h : s ⊆ t) : (Ioc s t).card = 2 ^ (t.card - s.card) - 1 := by rw [card_Ioc_eq_card_Icc_sub_one, card_Icc_finset h] /-- Cardinality of an `Ioo` of finsets. -/ lemma card_Ioo_finset (h : s ⊆ t) : (Ioo s t).card = 2 ^ (t.card - s.card) - 2 := by rw [card_Ioo_eq_card_Icc_sub_two, card_Icc_finset h] end finset
e1ae2d678a531d3c83272fd04088620cfcfdd4d5
5749d8999a76f3a8fddceca1f6941981e33aaa96
/src/group_theory/perm/sign.lean
c64a896e877cbd7ec9de52772d775fea549f497e
[ "Apache-2.0" ]
permissive
jdsalchow/mathlib
13ab43ef0d0515a17e550b16d09bd14b76125276
497e692b946d93906900bb33a51fd243e7649406
refs/heads/master
1,585,819,143,348
1,580,072,892,000
1,580,072,892,000
154,287,128
0
0
Apache-2.0
1,540,281,610,000
1,540,281,609,000
null
UTF-8
Lean
false
false
32,921
lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import data.fintype universes u v open equiv function fintype finset variables {α : Type u} {β : Type v} namespace equiv.perm def subtype_perm (f : perm α) {p : α → Prop} (h : ∀ x, p x ↔ p (f x)) : perm {x // p x} := ⟨λ x, ⟨f x, (h _).1 x.2⟩, λ x, ⟨f⁻¹ x, (h (f⁻¹ x)).2 $ by simpa using x.2⟩, λ _, by simp, λ _, by simp⟩ @[simp] lemma subtype_perm_one (p : α → Prop) (h : ∀ x, p x ↔ p ((1 : perm α) x)) : @subtype_perm α 1 p h = 1 := equiv.ext _ _ $ λ ⟨_, _⟩, rfl def of_subtype {p : α → Prop} [decidable_pred p] (f : perm (subtype p)) : perm α := ⟨λ x, if h : p x then f ⟨x, h⟩ else x, λ x, if h : p x then f⁻¹ ⟨x, h⟩ else x, λ x, have h : ∀ h : p x, p (f ⟨x, h⟩), from λ h, (f ⟨x, h⟩).2, by simp; split_ifs at *; simp * at *, λ x, have h : ∀ h : p x, p (f⁻¹ ⟨x, h⟩), from λ h, (f⁻¹ ⟨x, h⟩).2, by simp; split_ifs at *; simp * at *⟩ instance of_subtype.is_group_hom {p : α → Prop} [decidable_pred p] : is_group_hom (@of_subtype α p _) := { map_mul := λ f g, equiv.ext _ _ $ λ x, begin rw [of_subtype, of_subtype, of_subtype], by_cases h : p x, { have h₁ : p (f (g ⟨x, h⟩)), from (f (g ⟨x, h⟩)).2, have h₂ : p (g ⟨x, h⟩), from (g ⟨x, h⟩).2, simp [h, h₁, h₂] }, { simp [h] } end } @[simp] lemma of_subtype_one (p : α → Prop) [decidable_pred p] : @of_subtype α p _ 1 = 1 := is_group_hom.map_one of_subtype lemma eq_inv_iff_eq {f : perm α} {x y : α} : x = f⁻¹ y ↔ f x = y := by conv {to_lhs, rw [← injective.eq_iff f.injective, apply_inv_self]} lemma inv_eq_iff_eq {f : perm α} {x y : α} : f⁻¹ x = y ↔ x = f y := by rw [eq_comm, eq_inv_iff_eq, eq_comm] def disjoint (f g : perm α) := ∀ x, f x = x ∨ g x = x @[symm] lemma disjoint.symm {f g : perm α} : disjoint f g → disjoint g f := by simp [disjoint, or.comm] lemma disjoint_comm {f g : perm α} : disjoint f g ↔ disjoint g f := ⟨disjoint.symm, disjoint.symm⟩ lemma disjoint_mul_comm {f g : perm α} (h : disjoint f g) : f * g = g * f := equiv.ext _ _ $ λ x, (h x).elim (λ hf, (h (g x)).elim (λ hg, by simp [mul_apply, hf, hg]) (λ hg, by simp [mul_apply, hf, g.injective hg])) (λ hg, (h (f x)).elim (λ hf, by simp [mul_apply, f.injective hf, hg]) (λ hf, by simp [mul_apply, hf, hg])) @[simp] lemma disjoint_one_left (f : perm α) : disjoint 1 f := λ _, or.inl rfl @[simp] lemma disjoint_one_right (f : perm α) : disjoint f 1 := λ _, or.inr rfl lemma disjoint_mul_left {f g h : perm α} (H1 : disjoint f h) (H2 : disjoint g h) : disjoint (f * g) h := λ x, by cases H1 x; cases H2 x; simp * lemma disjoint_mul_right {f g h : perm α} (H1 : disjoint f g) (H2 : disjoint f h) : disjoint f (g * h) := by rw disjoint_comm; exact disjoint_mul_left H1.symm H2.symm lemma disjoint_prod_right {f : perm α} (l : list (perm α)) (h : ∀ g ∈ l, disjoint f g) : disjoint f l.prod := begin induction l with g l ih, { exact disjoint_one_right _ }, { rw list.prod_cons; exact disjoint_mul_right (h _ (list.mem_cons_self _ _)) (ih (λ g hg, h g (list.mem_cons_of_mem _ hg))) } end lemma disjoint_prod_perm {l₁ l₂ : list (perm α)} (hl : l₁.pairwise disjoint) (hp : l₁ ~ l₂) : l₁.prod = l₂.prod := begin induction hp, { refl }, { rw [list.prod_cons, list.prod_cons, hp_ih (list.pairwise_cons.1 hl).2] }, { simp [list.prod_cons, disjoint_mul_comm, (mul_assoc _ _ _).symm, *, list.pairwise_cons] at * }, { rw [hp_ih_a hl, hp_ih_a_1 ((list.perm_pairwise (λ x y (h : disjoint x y), disjoint.symm h) hp_a).1 hl)] } end lemma of_subtype_subtype_perm {f : perm α} {p : α → Prop} [decidable_pred p] (h₁ : ∀ x, p x ↔ p (f x)) (h₂ : ∀ x, f x ≠ x → p x) : of_subtype (subtype_perm f h₁) = f := equiv.ext _ _ $ λ x, begin rw [of_subtype, subtype_perm], by_cases hx : p x, { simp [hx] }, { haveI := classical.prop_decidable, simp [hx, not_not.1 (mt (h₂ x) hx)] } end lemma of_subtype_apply_of_not_mem {p : α → Prop} [decidable_pred p] (f : perm (subtype p)) {x : α} (hx : ¬ p x) : of_subtype f x = x := dif_neg hx lemma mem_iff_of_subtype_apply_mem {p : α → Prop} [decidable_pred p] (f : perm (subtype p)) (x : α) : p x ↔ p ((of_subtype f : α → α) x) := if h : p x then by dsimp [of_subtype]; simpa [h] using (f ⟨x, h⟩).2 else by simp [h, of_subtype_apply_of_not_mem f h] @[simp] lemma subtype_perm_of_subtype {p : α → Prop} [decidable_pred p] (f : perm (subtype p)) : subtype_perm (of_subtype f) (mem_iff_of_subtype_apply_mem f) = f := equiv.ext _ _ $ λ ⟨x, hx⟩, by dsimp [subtype_perm, of_subtype]; simp [show p x, from hx] lemma pow_apply_eq_self_of_apply_eq_self {f : perm α} {x : α} (hfx : f x = x) : ∀ n : ℕ, (f ^ n) x = x | 0 := rfl | (n+1) := by rw [pow_succ', mul_apply, hfx, pow_apply_eq_self_of_apply_eq_self] lemma gpow_apply_eq_self_of_apply_eq_self {f : perm α} {x : α} (hfx : f x = x) : ∀ n : ℤ, (f ^ n) x = x | (n : ℕ) := pow_apply_eq_self_of_apply_eq_self hfx n | -[1+ n] := by rw [gpow_neg_succ, inv_eq_iff_eq, pow_apply_eq_self_of_apply_eq_self hfx] lemma pow_apply_eq_of_apply_apply_eq_self {f : perm α} {x : α} (hffx : f (f x) = x) : ∀ n : ℕ, (f ^ n) x = x ∨ (f ^ n) x = f x | 0 := or.inl rfl | (n+1) := (pow_apply_eq_of_apply_apply_eq_self n).elim (λ h, or.inr (by rw [pow_succ, mul_apply, h])) (λ h, or.inl (by rw [pow_succ, mul_apply, h, hffx])) lemma gpow_apply_eq_of_apply_apply_eq_self {f : perm α} {x : α} (hffx : f (f x) = x) : ∀ i : ℤ, (f ^ i) x = x ∨ (f ^ i) x = f x | (n : ℕ) := pow_apply_eq_of_apply_apply_eq_self hffx n | -[1+ n] := by rw [gpow_neg_succ, inv_eq_iff_eq, ← injective.eq_iff f.injective, ← mul_apply, ← pow_succ, eq_comm, inv_eq_iff_eq, ← mul_apply, ← pow_succ', @eq_comm _ x, or.comm]; exact pow_apply_eq_of_apply_apply_eq_self hffx _ variable [decidable_eq α] def support [fintype α] (f : perm α) := univ.filter (λ x, f x ≠ x) @[simp] lemma mem_support [fintype α] {f : perm α} {x : α} : x ∈ f.support ↔ f x ≠ x := by simp [support] def is_swap (f : perm α) := ∃ x y, x ≠ y ∧ f = swap x y lemma swap_mul_eq_mul_swap (f : perm α) (x y : α) : swap x y * f = f * swap (f⁻¹ x) (f⁻¹ y) := equiv.ext _ _ $ λ z, begin simp [mul_apply, swap_apply_def], split_ifs; simp [*, eq_inv_iff_eq] at * <|> cc end lemma mul_swap_eq_swap_mul (f : perm α) (x y : α) : f * swap x y = swap (f x) (f y) * f := by rw [swap_mul_eq_mul_swap, inv_apply_self, inv_apply_self] @[simp] lemma swap_mul_self (i j : α) : equiv.swap i j * equiv.swap i j = 1 := equiv.swap_swap i j @[simp] lemma swap_swap_apply (i j k : α) : equiv.swap i j (equiv.swap i j k) = k := equiv.swap_core_swap_core k i j lemma is_swap_of_subtype {p : α → Prop} [decidable_pred p] {f : perm (subtype p)} (h : is_swap f) : is_swap (of_subtype f) := let ⟨⟨x, hx⟩, ⟨y, hy⟩, hxy⟩ := h in ⟨x, y, by simp at hxy; tauto, equiv.ext _ _ $ λ z, begin rw [hxy.2, of_subtype], simp [swap_apply_def], split_ifs; cc <|> simp * at * end⟩ lemma ne_and_ne_of_swap_mul_apply_ne_self {f : perm α} {x y : α} (hy : (swap x (f x) * f) y ≠ y) : f y ≠ y ∧ y ≠ x := begin simp only [swap_apply_def, mul_apply, injective.eq_iff f.injective] at *, by_cases h : f y = x, { split; intro; simp * at * }, { split_ifs at hy; cc } end lemma support_swap_mul_eq [fintype α] {f : perm α} {x : α} (hffx : f (f x) ≠ x) : (swap x (f x) * f).support = f.support.erase x := have hfx : f x ≠ x, from λ hfx, by simpa [hfx] using hffx, finset.ext.2 $ λ y, ⟨λ hy, have hy' : (swap x (f x) * f) y ≠ y, from mem_support.1 hy, mem_erase.2 ⟨λ hyx, by simp [hyx, mul_apply, *] at *, mem_support.2 $ λ hfy, by simp only [mul_apply, swap_apply_def, hfy] at hy'; split_ifs at hy'; simp * at *⟩, λ hy, by simp only [mem_erase, mem_support, swap_apply_def, mul_apply] at *; intro; split_ifs at *; simp * at *⟩ lemma card_support_swap_mul [fintype α] {f : perm α} {x : α} (hx : f x ≠ x) : (swap x (f x) * f).support.card < f.support.card := finset.card_lt_card ⟨λ z hz, mem_support.2 (ne_and_ne_of_swap_mul_apply_ne_self (mem_support.1 hz)).1, λ h, absurd (h (mem_support.2 hx)) (mt mem_support.1 (by simp))⟩ def swap_factors_aux : Π (l : list α) (f : perm α), (∀ {x}, f x ≠ x → x ∈ l) → {l : list (perm α) // l.prod = f ∧ ∀ g ∈ l, is_swap g} | [] := λ f h, ⟨[], equiv.ext _ _ $ λ x, by rw [list.prod_nil]; exact eq.symm (not_not.1 (mt h (list.not_mem_nil _))), by simp⟩ | (x :: l) := λ f h, if hfx : x = f x then swap_factors_aux l f (λ y hy, list.mem_of_ne_of_mem (λ h : y = x, by simpa [h, hfx.symm] using hy) (h hy)) else let m := swap_factors_aux l (swap x (f x) * f) (λ y hy, have f y ≠ y ∧ y ≠ x, from ne_and_ne_of_swap_mul_apply_ne_self hy, list.mem_of_ne_of_mem this.2 (h this.1)) in ⟨swap x (f x) :: m.1, by rw [list.prod_cons, m.2.1, ← mul_assoc, mul_def (swap x (f x)), swap_swap, ← one_def, one_mul], λ g hg, ((list.mem_cons_iff _ _ _).1 hg).elim (λ h, ⟨x, f x, hfx, h⟩) (m.2.2 _)⟩ /-- `swap_factors` represents a permutation as a product of a list of transpositions. The representation is non unique and depends on the linear order structure. For types without linear order `trunc_swap_factors` can be used -/ def swap_factors [fintype α] [decidable_linear_order α] (f : perm α) : {l : list (perm α) // l.prod = f ∧ ∀ g ∈ l, is_swap g} := swap_factors_aux ((@univ α _).sort (≤)) f (λ _ _, (mem_sort _).2 (mem_univ _)) def trunc_swap_factors [fintype α] (f : perm α) : trunc {l : list (perm α) // l.prod = f ∧ ∀ g ∈ l, is_swap g} := quotient.rec_on_subsingleton (@univ α _).1 (λ l h, trunc.mk (swap_factors_aux l f h)) (show ∀ x, f x ≠ x → x ∈ (@univ α _).1, from λ _ _, mem_univ _) @[elab_as_eliminator] lemma swap_induction_on [fintype α] {P : perm α → Prop} (f : perm α) : P 1 → (∀ f x y, x ≠ y → P f → P (swap x y * f)) → P f := begin cases trunc.out (trunc_swap_factors f) with l hl, induction l with g l ih generalizing f, { simp [hl.1.symm] {contextual := tt} }, { assume h1 hmul_swap, rcases hl.2 g (by simp) with ⟨x, y, hxy⟩, rw [← hl.1, list.prod_cons, hxy.2], exact hmul_swap _ _ _ hxy.1 (ih _ ⟨rfl, λ v hv, hl.2 _ (list.mem_cons_of_mem _ hv)⟩ h1 hmul_swap) } end lemma swap_mul_swap_mul_swap {x y z : α} (hwz: x ≠ y) (hxz : x ≠ z) : swap y z * swap x y * swap y z = swap z x := equiv.ext _ _ $ λ n, by simp only [swap_apply_def, mul_apply]; split_ifs; cc lemma is_conj_swap {w x y z : α} (hwx : w ≠ x) (hyz : y ≠ z) : is_conj (swap w x) (swap y z) := have h : ∀ {y z : α}, y ≠ z → w ≠ z → (swap w y * swap x z) * swap w x * (swap w y * swap x z)⁻¹ = swap y z := λ y z hyz hwz, by rw [mul_inv_rev, swap_inv, swap_inv, mul_assoc (swap w y), mul_assoc (swap w y), ← mul_assoc _ (swap x z), swap_mul_swap_mul_swap hwx hwz, ← mul_assoc, swap_mul_swap_mul_swap hwz.symm hyz.symm], if hwz : w = z then have hwy : w ≠ y, by cc, ⟨swap w z * swap x y, by rw [swap_comm y z, h hyz.symm hwy]⟩ else ⟨swap w y * swap x z, h hyz hwz⟩ /-- set of all pairs (⟨a, b⟩ : Σ a : fin n, fin n) such that b < a -/ def fin_pairs_lt (n : ℕ) : finset (Σ a : fin n, fin n) := (univ : finset (fin n)).sigma (λ a, (range a.1).attach_fin (λ m hm, lt_trans (mem_range.1 hm) a.2)) lemma mem_fin_pairs_lt {n : ℕ} {a : Σ a : fin n, fin n} : a ∈ fin_pairs_lt n ↔ a.2 < a.1 := by simp [fin_pairs_lt, fin.lt_def] def sign_aux {n : ℕ} (a : perm (fin n)) : units ℤ := (fin_pairs_lt n).prod (λ x, if a x.1 ≤ a x.2 then -1 else 1) @[simp] lemma sign_aux_one (n : ℕ) : sign_aux (1 : perm (fin n)) = 1 := begin unfold sign_aux, conv { to_rhs, rw ← @finset.prod_const_one _ (units ℤ) (fin_pairs_lt n) }, exact finset.prod_congr rfl (λ a ha, if_neg (not_le_of_gt (mem_fin_pairs_lt.1 ha))) end def sign_bij_aux {n : ℕ} (f : perm (fin n)) (a : Σ a : fin n, fin n) : Σ a : fin n, fin n := if hxa : f a.2 < f a.1 then ⟨f a.1, f a.2⟩ else ⟨f a.2, f a.1⟩ lemma sign_bij_aux_inj {n : ℕ} {f : perm (fin n)} : ∀ a b : Σ a : fin n, fin n, a ∈ fin_pairs_lt n → b ∈ fin_pairs_lt n → sign_bij_aux f a = sign_bij_aux f b → a = b := λ ⟨a₁, a₂⟩ ⟨b₁, b₂⟩ ha hb h, begin unfold sign_bij_aux at h, rw mem_fin_pairs_lt at *, have : ¬b₁ < b₂ := not_lt_of_ge (le_of_lt hb), split_ifs at h; simp [*, injective.eq_iff f.injective, sigma.mk.inj_eq] at * end lemma sign_bij_aux_surj {n : ℕ} {f : perm (fin n)} : ∀ a ∈ fin_pairs_lt n, ∃ b ∈ fin_pairs_lt n, a = sign_bij_aux f b := λ ⟨a₁, a₂⟩ ha, if hxa : f⁻¹ a₂ < f⁻¹ a₁ then ⟨⟨f⁻¹ a₁, f⁻¹ a₂⟩, mem_fin_pairs_lt.2 hxa, by dsimp [sign_bij_aux]; rw [apply_inv_self, apply_inv_self, dif_pos (mem_fin_pairs_lt.1 ha)]⟩ else ⟨⟨f⁻¹ a₂, f⁻¹ a₁⟩, mem_fin_pairs_lt.2 $ lt_of_le_of_ne (le_of_not_gt hxa) $ λ h, by simpa [mem_fin_pairs_lt, (f⁻¹).injective h, lt_irrefl] using ha, by dsimp [sign_bij_aux]; rw [apply_inv_self, apply_inv_self, dif_neg (not_lt_of_ge (le_of_lt (mem_fin_pairs_lt.1 ha)))]⟩ lemma sign_bij_aux_mem {n : ℕ} {f : perm (fin n)}: ∀ a : Σ a : fin n, fin n, a ∈ fin_pairs_lt n → sign_bij_aux f a ∈ fin_pairs_lt n := λ ⟨a₁, a₂⟩ ha, begin unfold sign_bij_aux, split_ifs with h, { exact mem_fin_pairs_lt.2 h }, { exact mem_fin_pairs_lt.2 (lt_of_le_of_ne (le_of_not_gt h) (λ h, ne_of_lt (mem_fin_pairs_lt.1 ha) (f.injective h.symm))) } end @[simp] lemma sign_aux_inv {n : ℕ} (f : perm (fin n)) : sign_aux f⁻¹ = sign_aux f := prod_bij (λ a ha, sign_bij_aux f⁻¹ a) sign_bij_aux_mem (λ ⟨a, b⟩ hab, if h : f⁻¹ b < f⁻¹ a then by rw [sign_bij_aux, dif_pos h, if_neg (not_le_of_gt h), apply_inv_self, apply_inv_self, if_neg (not_le_of_gt $ mem_fin_pairs_lt.1 hab)] else by rw [sign_bij_aux, if_pos (le_of_not_gt h), dif_neg h, apply_inv_self, apply_inv_self, if_pos (le_of_lt $ mem_fin_pairs_lt.1 hab)]) sign_bij_aux_inj sign_bij_aux_surj lemma sign_aux_mul {n : ℕ} (f g : perm (fin n)) : sign_aux (f * g) = sign_aux f * sign_aux g := begin rw ← sign_aux_inv g, unfold sign_aux, rw ← prod_mul_distrib, refine prod_bij (λ a ha, sign_bij_aux g a) sign_bij_aux_mem _ sign_bij_aux_inj sign_bij_aux_surj, rintros ⟨a, b⟩ hab, rw [sign_bij_aux, mul_apply, mul_apply], rw mem_fin_pairs_lt at hab, by_cases h : g b < g a, { rw dif_pos h, simp [not_le_of_gt hab]; congr }, { rw [dif_neg h, inv_apply_self, inv_apply_self, if_pos (le_of_lt hab)], by_cases h₁ : f (g b) ≤ f (g a), { have : f (g b) ≠ f (g a), { rw [ne.def, injective.eq_iff f.injective, injective.eq_iff g.injective]; exact ne_of_lt hab }, rw [if_pos h₁, if_neg (not_le_of_gt (lt_of_le_of_ne h₁ this))], refl }, { rw [if_neg h₁, if_pos (le_of_lt (lt_of_not_ge h₁))], refl } } end instance sign_aux.is_group_hom {n : ℕ} : is_group_hom (@sign_aux n) := { map_mul := sign_aux_mul } private lemma sign_aux_swap_zero_one {n : ℕ} (hn : 2 ≤ n) : sign_aux (swap (⟨0, lt_of_lt_of_le dec_trivial hn⟩ : fin n) ⟨1, lt_of_lt_of_le dec_trivial hn⟩) = -1 := let zero : fin n := ⟨0, lt_of_lt_of_le dec_trivial hn⟩ in let one : fin n := ⟨1, lt_of_lt_of_le dec_trivial hn⟩ in have hzo : zero < one := dec_trivial, show _ = (finset.singleton (⟨one, zero⟩ : Σ a : fin n, fin n)).prod (λ x : Σ a : fin n, fin n, if (equiv.swap zero one) x.1 ≤ swap zero one x.2 then (-1 : units ℤ) else 1), begin refine eq.symm (prod_subset (λ ⟨x₁, x₂⟩, by simp [mem_fin_pairs_lt, hzo] {contextual := tt}) (λ a ha₁ ha₂, _)), rcases a with ⟨⟨a₁, ha₁⟩, ⟨a₂, ha₂⟩⟩, replace ha₁ : a₂ < a₁ := mem_fin_pairs_lt.1 ha₁, simp only [swap_apply_def], have : ¬ 1 ≤ a₂ → a₂ = 0, from λ h, nat.le_zero_iff.1 (nat.le_of_lt_succ (lt_of_not_ge h)), have : a₁ ≤ 1 → a₁ = 0 ∨ a₁ = 1, from nat.cases_on a₁ (λ _, or.inl rfl) (λ a₁, nat.cases_on a₁ (λ _, or.inr rfl) (λ _ h, absurd h dec_trivial)), split_ifs; simp [*, lt_irrefl, -not_lt, not_le.symm, -not_le, le_refl, fin.lt_def, fin.le_def, nat.zero_le, zero, one, iff.intro fin.veq_of_eq fin.eq_of_veq, nat.le_zero_iff] at *, end lemma sign_aux_swap : ∀ {n : ℕ} {x y : fin n} (hxy : x ≠ y), sign_aux (swap x y) = -1 | 0 := dec_trivial | 1 := dec_trivial | (n+2) := λ x y hxy, have h2n : 2 ≤ n + 2 := dec_trivial, by rw [← is_conj_iff_eq, ← sign_aux_swap_zero_one h2n]; exact is_group_hom.is_conj _ (is_conj_swap hxy dec_trivial) def sign_aux2 : list α → perm α → units ℤ | [] f := 1 | (x::l) f := if x = f x then sign_aux2 l f else -sign_aux2 l (swap x (f x) * f) lemma sign_aux_eq_sign_aux2 {n : ℕ} : ∀ (l : list α) (f : perm α) (e : α ≃ fin n) (h : ∀ x, f x ≠ x → x ∈ l), sign_aux ((e.symm.trans f).trans e) = sign_aux2 l f | [] f e h := have f = 1, from equiv.ext _ _ $ λ y, not_not.1 (mt (h y) (list.not_mem_nil _)), by rw [this, one_def, equiv.trans_refl, equiv.symm_trans, ← one_def, sign_aux_one, sign_aux2] | (x::l) f e h := begin rw sign_aux2, by_cases hfx : x = f x, { rw if_pos hfx, exact sign_aux_eq_sign_aux2 l f _ (λ y (hy : f y ≠ y), list.mem_of_ne_of_mem (λ h : y = x, by simpa [h, hfx.symm] using hy) (h y hy) ) }, { have hy : ∀ y : α, (swap x (f x) * f) y ≠ y → y ∈ l, from λ y hy, have f y ≠ y ∧ y ≠ x, from ne_and_ne_of_swap_mul_apply_ne_self hy, list.mem_of_ne_of_mem this.2 (h _ this.1), have : (e.symm.trans (swap x (f x) * f)).trans e = (swap (e x) (e (f x))) * (e.symm.trans f).trans e, from equiv.ext _ _ (λ z, by rw ← equiv.symm_trans_swap_trans; simp [mul_def]), have hefx : e x ≠ e (f x), from mt (injective.eq_iff e.injective).1 hfx, rw [if_neg hfx, ← sign_aux_eq_sign_aux2 _ _ e hy, this, sign_aux_mul, sign_aux_swap hefx], simp } end def sign_aux3 [fintype α] (f : perm α) {s : multiset α} : (∀ x, x ∈ s) → units ℤ := quotient.hrec_on s (λ l h, sign_aux2 l f) (trunc.induction_on (equiv_fin α) (λ e l₁ l₂ h, function.hfunext (show (∀ x, x ∈ l₁) = ∀ x, x ∈ l₂, by simp [list.mem_of_perm h]) (λ h₁ h₂ _, by rw [← sign_aux_eq_sign_aux2 _ _ e (λ _ _, h₁ _), ← sign_aux_eq_sign_aux2 _ _ e (λ _ _, h₂ _)]))) lemma sign_aux3_mul_and_swap [fintype α] (f g : perm α) (s : multiset α) (hs : ∀ x, x ∈ s) : sign_aux3 (f * g) hs = sign_aux3 f hs * sign_aux3 g hs ∧ ∀ x y, x ≠ y → sign_aux3 (swap x y) hs = -1 := let ⟨l, hl⟩ := quotient.exists_rep s in let ⟨e, _⟩ := trunc.exists_rep (equiv_fin α) in begin clear _let_match _let_match, subst hl, show sign_aux2 l (f * g) = sign_aux2 l f * sign_aux2 l g ∧ ∀ x y, x ≠ y → sign_aux2 l (swap x y) = -1, have hfg : (e.symm.trans (f * g)).trans e = (e.symm.trans f).trans e * (e.symm.trans g).trans e, from equiv.ext _ _ (λ h, by simp [mul_apply]), split, { rw [← sign_aux_eq_sign_aux2 _ _ e (λ _ _, hs _), ← sign_aux_eq_sign_aux2 _ _ e (λ _ _, hs _), ← sign_aux_eq_sign_aux2 _ _ e (λ _ _, hs _), hfg, sign_aux_mul] }, { assume x y hxy, have hexy : e x ≠ e y, from mt (injective.eq_iff e.injective).1 hxy, rw [← sign_aux_eq_sign_aux2 _ _ e (λ _ _, hs _), equiv.symm_trans_swap_trans, sign_aux_swap hexy] } end /-- `sign` of a permutation returns the signature or parity of a permutation, `1` for even permutations, `-1` for odd permutations. It is the unique surjective group homomorphism from `perm α` to the group with two elements.-/ def sign [fintype α] (f : perm α) := sign_aux3 f mem_univ instance sign.is_group_hom [fintype α] : is_group_hom (@sign α _ _) := { map_mul := λ f g, (sign_aux3_mul_and_swap f g _ mem_univ).1 } section sign variable [fintype α] @[simp] lemma sign_mul (f g : perm α) : sign (f * g) = sign f * sign g := is_mul_hom.map_mul sign _ _ @[simp] lemma sign_one : (sign (1 : perm α)) = 1 := is_group_hom.map_one sign @[simp] lemma sign_refl : sign (equiv.refl α) = 1 := is_group_hom.map_one sign @[simp] lemma sign_inv (f : perm α) : sign f⁻¹ = sign f := by rw [is_group_hom.map_inv sign, int.units_inv_eq_self]; apply_instance lemma sign_swap {x y : α} (h : x ≠ y) : sign (swap x y) = -1 := (sign_aux3_mul_and_swap 1 1 _ mem_univ).2 x y h @[simp] lemma sign_swap' {x y : α} : (swap x y).sign = if x = y then 1 else -1 := if H : x = y then by simp [H, swap_self] else by simp [sign_swap H, H] lemma sign_eq_of_is_swap {f : perm α} (h : is_swap f) : sign f = -1 := let ⟨x, y, hxy⟩ := h in hxy.2.symm ▸ sign_swap hxy.1 lemma sign_aux3_symm_trans_trans [decidable_eq β] [fintype β] (f : perm α) (e : α ≃ β) {s : multiset α} {t : multiset β} (hs : ∀ x, x ∈ s) (ht : ∀ x, x ∈ t) : sign_aux3 ((e.symm.trans f).trans e) ht = sign_aux3 f hs := quotient.induction_on₂ t s (λ l₁ l₂ h₁ h₂, show sign_aux2 _ _ = sign_aux2 _ _, from let n := trunc.out (equiv_fin β) in by rw [← sign_aux_eq_sign_aux2 _ _ n (λ _ _, h₁ _), ← sign_aux_eq_sign_aux2 _ _ (e.trans n) (λ _ _, h₂ _)]; exact congr_arg sign_aux (equiv.ext _ _ (λ x, by simp))) ht hs lemma sign_symm_trans_trans [decidable_eq β] [fintype β] (f : perm α) (e : α ≃ β) : sign ((e.symm.trans f).trans e) = sign f := sign_aux3_symm_trans_trans f e mem_univ mem_univ lemma sign_prod_list_swap {l : list (perm α)} (hl : ∀ g ∈ l, is_swap g) : sign l.prod = -1 ^ l.length := have h₁ : l.map sign = list.repeat (-1) l.length := list.eq_repeat.2 ⟨by simp, λ u hu, let ⟨g, hg⟩ := list.mem_map.1 hu in hg.2 ▸ sign_eq_of_is_swap (hl _ hg.1)⟩, by rw [← list.prod_repeat, ← h₁, list.prod_hom _ (@sign α _ _)] lemma sign_surjective (hα : 1 < fintype.card α) : function.surjective (sign : perm α → units ℤ) := λ a, (int.units_eq_one_or a).elim (λ h, ⟨1, by simp [h]⟩) (λ h, let ⟨x⟩ := fintype.card_pos_iff.1 (lt_trans zero_lt_one hα) in let ⟨y, hxy⟩ := fintype.exists_ne_of_one_lt_card hα x in ⟨swap y x, by rw [sign_swap hxy, h]⟩ ) lemma eq_sign_of_surjective_hom {s : perm α → units ℤ} [is_group_hom s] (hs : surjective s) : s = sign := have ∀ {f}, is_swap f → s f = -1 := λ f ⟨x, y, hxy, hxy'⟩, hxy'.symm ▸ by_contradiction (λ h, have ∀ f, is_swap f → s f = 1 := λ f ⟨a, b, hab, hab'⟩, by rw [← is_conj_iff_eq, ← or.resolve_right (int.units_eq_one_or _) h, hab']; exact is_group_hom.is_conj _ (is_conj_swap hab hxy), let ⟨g, hg⟩ := hs (-1) in let ⟨l, hl⟩ := trunc.out (trunc_swap_factors g) in have ∀ a ∈ l.map s, a = (1 : units ℤ) := λ a ha, let ⟨g, hg⟩ := list.mem_map.1 ha in hg.2 ▸ this _ (hl.2 _ hg.1), have s l.prod = 1, by rw [← l.prod_hom s, list.eq_repeat'.2 this, list.prod_repeat, one_pow], by rw [hl.1, hg] at this; exact absurd this dec_trivial), funext $ λ f, let ⟨l, hl₁, hl₂⟩ := trunc.out (trunc_swap_factors f) in have hsl : ∀ a ∈ l.map s, a = (-1 : units ℤ) := λ a ha, let ⟨g, hg⟩ := list.mem_map.1 ha in hg.2 ▸ this (hl₂ _ hg.1), by rw [← hl₁, ← l.prod_hom s, list.eq_repeat'.2 hsl, list.length_map, list.prod_repeat, sign_prod_list_swap hl₂] lemma sign_subtype_perm (f : perm α) {p : α → Prop} [decidable_pred p] (h₁ : ∀ x, p x ↔ p (f x)) (h₂ : ∀ x, f x ≠ x → p x) : sign (subtype_perm f h₁) = sign f := let l := trunc.out (trunc_swap_factors (subtype_perm f h₁)) in have hl' : ∀ g' ∈ l.1.map of_subtype, is_swap g' := λ g' hg', let ⟨g, hg⟩ := list.mem_map.1 hg' in hg.2 ▸ is_swap_of_subtype (l.2.2 _ hg.1), have hl'₂ : (l.1.map of_subtype).prod = f, by rw [l.1.prod_hom of_subtype, l.2.1, of_subtype_subtype_perm _ h₂], by conv {congr, rw ← l.2.1, skip, rw ← hl'₂}; rw [sign_prod_list_swap l.2.2, sign_prod_list_swap hl', list.length_map] @[simp] lemma sign_of_subtype {p : α → Prop} [decidable_pred p] (f : perm (subtype p)) : sign (of_subtype f) = sign f := have ∀ x, of_subtype f x ≠ x → p x, from λ x, not_imp_comm.1 (of_subtype_apply_of_not_mem f), by conv {to_rhs, rw [← subtype_perm_of_subtype f, sign_subtype_perm _ _ this]} lemma sign_eq_sign_of_equiv [decidable_eq β] [fintype β] (f : perm α) (g : perm β) (e : α ≃ β) (h : ∀ x, e (f x) = g (e x)) : sign f = sign g := have hg : g = (e.symm.trans f).trans e, from equiv.ext _ _ $ by simp [h], by rw [hg, sign_symm_trans_trans] lemma sign_bij [decidable_eq β] [fintype β] {f : perm α} {g : perm β} (i : Π x : α, f x ≠ x → β) (h : ∀ x hx hx', i (f x) hx' = g (i x hx)) (hi : ∀ x₁ x₂ hx₁ hx₂, i x₁ hx₁ = i x₂ hx₂ → x₁ = x₂) (hg : ∀ y, g y ≠ y → ∃ x hx, i x hx = y) : sign f = sign g := calc sign f = sign (@subtype_perm _ f (λ x, f x ≠ x) (by simp)) : eq.symm (sign_subtype_perm _ _ (λ _, id)) ... = sign (@subtype_perm _ g (λ x, g x ≠ x) (by simp)) : sign_eq_sign_of_equiv _ _ (equiv.of_bijective (show function.bijective (λ x : {x // f x ≠ x}, (⟨i x.1 x.2, have f (f x) ≠ f x, from mt (λ h, f.injective h) x.2, by rw [← h _ x.2 this]; exact mt (hi _ _ this x.2) x.2⟩ : {y // g y ≠ y})), from ⟨λ ⟨x, hx⟩ ⟨y, hy⟩ h, subtype.eq (hi _ _ _ _ (subtype.mk.inj h)), λ ⟨y, hy⟩, let ⟨x, hfx, hx⟩ := hg y hy in ⟨⟨x, hfx⟩, subtype.eq hx⟩⟩)) (λ ⟨x, _⟩, subtype.eq (h x _ _)) ... = sign g : sign_subtype_perm _ _ (λ _, id) def is_cycle (f : perm β) := ∃ x, f x ≠ x ∧ ∀ y, f y ≠ y → ∃ i : ℤ, (f ^ i) x = y lemma is_cycle_swap {x y : α} (hxy : x ≠ y) : is_cycle (swap x y) := ⟨y, by rwa swap_apply_right, λ a (ha : ite (a = x) y (ite (a = y) x a) ≠ a), if hya : y = a then ⟨0, hya⟩ else ⟨1, by rw [gpow_one, swap_apply_def]; split_ifs at *; cc⟩⟩ lemma is_cycle_inv {f : perm β} (hf : is_cycle f) : is_cycle (f⁻¹) := let ⟨x, hx⟩ := hf in ⟨x, by simp [eq_inv_iff_eq, inv_eq_iff_eq, *] at *; cc, λ y hy, let ⟨i, hi⟩ := hx.2 y (by simp [eq_inv_iff_eq, inv_eq_iff_eq, *] at *; cc) in ⟨-i, by rwa [gpow_neg, inv_gpow, inv_inv]⟩⟩ lemma exists_gpow_eq_of_is_cycle {f : perm β} (hf : is_cycle f) {x y : β} (hx : f x ≠ x) (hy : f y ≠ y) : ∃ i : ℤ, (f ^ i) x = y := let ⟨g, hg⟩ := hf in let ⟨a, ha⟩ := hg.2 x hx in let ⟨b, hb⟩ := hg.2 y hy in ⟨b - a, by rw [← ha, ← mul_apply, ← gpow_add, sub_add_cancel, hb]⟩ lemma is_cycle_swap_mul_aux₁ : ∀ (n : ℕ) {b x : α} {f : perm α} (hb : (swap x (f x) * f) b ≠ b) (h : (f ^ n) (f x) = b), ∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b | 0 := λ b x f hb h, ⟨0, h⟩ | (n+1 : ℕ) := λ b x f hb h, if hfbx : f x = b then ⟨0, hfbx⟩ else have f b ≠ b ∧ b ≠ x, from ne_and_ne_of_swap_mul_apply_ne_self hb, have hb' : (swap x (f x) * f) (f⁻¹ b) ≠ f⁻¹ b, by rw [mul_apply, apply_inv_self, swap_apply_of_ne_of_ne this.2 (ne.symm hfbx), ne.def, ← injective.eq_iff f.injective, apply_inv_self]; exact this.1, let ⟨i, hi⟩ := is_cycle_swap_mul_aux₁ n hb' (f.injective $ by rw [apply_inv_self]; rwa [pow_succ, mul_apply] at h) in ⟨i + 1, by rw [add_comm, gpow_add, mul_apply, hi, gpow_one, mul_apply, apply_inv_self, swap_apply_of_ne_of_ne (ne_and_ne_of_swap_mul_apply_ne_self hb).2 (ne.symm hfbx)]⟩ lemma is_cycle_swap_mul_aux₂ : ∀ (n : ℤ) {b x : α} {f : perm α} (hb : (swap x (f x) * f) b ≠ b) (h : (f ^ n) (f x) = b), ∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b | (n : ℕ) := λ b x f, is_cycle_swap_mul_aux₁ n | -[1+ n] := λ b x f hb h, if hfbx : f⁻¹ x = b then ⟨-1, by rwa [gpow_neg, gpow_one, mul_inv_rev, mul_apply, swap_inv, swap_apply_right]⟩ else if hfbx' : f x = b then ⟨0, hfbx'⟩ else have f b ≠ b ∧ b ≠ x := ne_and_ne_of_swap_mul_apply_ne_self hb, have hb : (swap x (f⁻¹ x) * f⁻¹) (f⁻¹ b) ≠ f⁻¹ b, by rw [mul_apply, swap_apply_def]; split_ifs; simp [inv_eq_iff_eq, eq_inv_iff_eq] at *; cc, let ⟨i, hi⟩ := is_cycle_swap_mul_aux₁ n hb (show (f⁻¹ ^ n) (f⁻¹ x) = f⁻¹ b, by rw [← gpow_coe_nat, ← h, ← mul_apply, ← mul_apply, ← mul_apply, gpow_neg_succ, ← inv_pow, pow_succ', mul_assoc, mul_assoc, inv_mul_self, mul_one, gpow_coe_nat, ← pow_succ', ← pow_succ]) in have h : (swap x (f⁻¹ x) * f⁻¹) (f x) = f⁻¹ x, by rw [mul_apply, inv_apply_self, swap_apply_left], ⟨-i, by rw [← add_sub_cancel i 1, neg_sub, sub_eq_add_neg, gpow_add, gpow_one, gpow_neg, ← inv_gpow, mul_inv_rev, swap_inv, mul_swap_eq_swap_mul, inv_apply_self, swap_comm _ x, gpow_add, gpow_one, mul_apply, mul_apply (_ ^ i), h, hi, mul_apply, apply_inv_self, swap_apply_of_ne_of_ne this.2 (ne.symm hfbx')]⟩ lemma eq_swap_of_is_cycle_of_apply_apply_eq_self {f : perm α} (hf : is_cycle f) {x : α} (hfx : f x ≠ x) (hffx : f (f x) = x) : f = swap x (f x) := equiv.ext _ _ $ λ y, let ⟨z, hz⟩ := hf in let ⟨i, hi⟩ := hz.2 x hfx in if hyx : y = x then by simp [hyx] else if hfyx : y = f x then by simp [hfyx, hffx] else begin rw [swap_apply_of_ne_of_ne hyx hfyx], refine by_contradiction (λ hy, _), cases hz.2 y hy with j hj, rw [← sub_add_cancel j i, gpow_add, mul_apply, hi] at hj, cases gpow_apply_eq_of_apply_apply_eq_self hffx (j - i) with hji hji, { rw [← hj, hji] at hyx, cc }, { rw [← hj, hji] at hfyx, cc } end lemma is_cycle_swap_mul {f : perm α} (hf : is_cycle f) {x : α} (hx : f x ≠ x) (hffx : f (f x) ≠ x) : is_cycle (swap x (f x) * f) := ⟨f x, by simp only [swap_apply_def, mul_apply]; split_ifs; simp [injective.eq_iff f.injective] at *; cc, λ y hy, let ⟨i, hi⟩ := exists_gpow_eq_of_is_cycle hf hx (ne_and_ne_of_swap_mul_apply_ne_self hy).1 in have hi : (f ^ (i - 1)) (f x) = y, from calc (f ^ (i - 1)) (f x) = (f ^ (i - 1) * f ^ (1 : ℤ)) x : by rw [gpow_one, mul_apply] ... = y : by rwa [← gpow_add, sub_add_cancel], is_cycle_swap_mul_aux₂ (i - 1) hy hi⟩ @[simp] lemma support_swap [fintype α] {x y : α} (hxy : x ≠ y) : (swap x y).support = {x, y} := finset.ext.2 $ λ a, by simp [swap_apply_def]; split_ifs; cc lemma card_support_swap [fintype α] {x y : α} (hxy : x ≠ y) : (swap x y).support.card = 2 := show (swap x y).support.card = finset.card ⟨x::y::0, by simp [hxy]⟩, from congr_arg card $ by rw [support_swap hxy]; simp [*, finset.ext]; cc lemma sign_cycle [fintype α] : ∀ {f : perm α} (hf : is_cycle f), sign f = -(-1 ^ f.support.card) | f := λ hf, let ⟨x, hx⟩ := hf in calc sign f = sign (swap x (f x) * (swap x (f x) * f)) : by rw [← mul_assoc, mul_def, mul_def, swap_swap, trans_refl] ... = -(-1 ^ f.support.card) : if h1 : f (f x) = x then have h : swap x (f x) * f = 1, by conv in (f) {rw eq_swap_of_is_cycle_of_apply_apply_eq_self hf hx.1 h1 }; simp [mul_def, one_def], by rw [sign_mul, sign_swap hx.1.symm, h, sign_one, eq_swap_of_is_cycle_of_apply_apply_eq_self hf hx.1 h1, card_support_swap hx.1.symm]; refl else have h : card (support (swap x (f x) * f)) + 1 = card (support f), by rw [← insert_erase (mem_support.2 hx.1), support_swap_mul_eq h1, card_insert_of_not_mem (not_mem_erase _ _)], have wf : card (support (swap x (f x) * f)) < card (support f), from card_support_swap_mul hx.1, by rw [sign_mul, sign_swap hx.1.symm, sign_cycle (is_cycle_swap_mul hf hx.1 h1), ← h]; simp [pow_add] using_well_founded {rel_tac := λ _ _, `[exact ⟨_, measure_wf (λ f, f.support.card)⟩]} end sign end equiv.perm lemma finset.prod_univ_perm [fintype α] [comm_monoid β] {f : α → β} (σ : perm α) : (univ : finset α).prod f = univ.prod (λ z, f (σ z)) := eq.symm $ prod_bij (λ z _, σ z) (λ _ _, mem_univ _) (λ _ _, rfl) (λ _ _ _ _ H, σ.injective H) (λ b _, ⟨σ⁻¹ b, mem_univ _, by simp⟩) lemma finset.sum_univ_perm [fintype α] [add_comm_monoid β] {f : α → β} (σ : perm α) : (univ : finset α).sum f = univ.sum (λ z, f (σ z)) := @finset.prod_univ_perm _ (multiplicative β) _ _ f σ attribute [to_additive] finset.prod_univ_perm
ec297cbcb7dfa28d9417de1fbaae39b002396907
ce6917c5bacabee346655160b74a307b4a5ab620
/src/ch5/ex0413.lean
f0a24f6879c94b55e8f551686cda72c04e373326
[]
no_license
Ailrun/Theorem_Proving_in_Lean
ae6a23f3c54d62d401314d6a771e8ff8b4132db2
2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68
refs/heads/master
1,609,838,270,467
1,586,846,743,000
1,586,846,743,000
240,967,761
1
0
null
null
null
null
UTF-8
Lean
false
false
490
lean
example (p q r : Prop) : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) := begin apply iff.intro, { intro h, cases h.right with hq hr, { show (p ∧ q) ∨ (p ∧ r), exact or.inl ⟨h.left, hq⟩ }, show (p ∧ q) ∨ (p ∧ r), exact or.inr ⟨h.left, hr⟩ }, intro h, cases h with hpq hpr, { show p ∧ (q ∨ r), exact ⟨hpq.left, or.inl hpq.right⟩ }, show p ∧ (q ∨ r), exact ⟨hpr.left, or.inr hpr.right⟩ end
2d2568bac8fef2d052bd80eb0480829e4126003c
c777c32c8e484e195053731103c5e52af26a25d1
/src/order/lattice.lean
e3877be97db81ad80c49397865cfe9d744c14d61
[ "Apache-2.0" ]
permissive
kbuzzard/mathlib
2ff9e85dfe2a46f4b291927f983afec17e946eb8
58537299e922f9c77df76cb613910914a479c1f7
refs/heads/master
1,685,313,702,744
1,683,974,212,000
1,683,974,212,000
128,185,277
1
0
null
1,522,920,600,000
1,522,920,600,000
null
UTF-8
Lean
false
false
44,920
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 order.monotone.basic import tactic.simps import tactic.pi_instances /-! # (Semi-)lattices > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or meet (least upper bound, or `inf`) operations. Lattices are posets that are both join-semilattices and meet-semilattices. Distributive lattices are lattices which satisfy any of four equivalent distributivity properties, of `sup` over `inf`, on the left or on the right. ## Main declarations * `semilattice_sup`: a type class for join semilattices * `semilattice_sup.mk'`: an alternative constructor for `semilattice_sup` via proofs that `⊔` is commutative, associative and idempotent. * `semilattice_inf`: a type class for meet semilattices * `semilattice_sup.mk'`: an alternative constructor for `semilattice_inf` via proofs that `⊓` is commutative, associative and idempotent. * `lattice`: a type class for lattices * `lattice.mk'`: an alternative constructor for `lattice` via profs that `⊔` and `⊓` are commutative, associative and satisfy a pair of "absorption laws". * `distrib_lattice`: a type class for distributive lattices. ## Notations * `a ⊔ b`: the supremum or join of `a` and `b` * `a ⊓ b`: the infimum or meet of `a` and `b` ## TODO * (Semi-)lattice homomorphisms * Alternative constructors for distributive lattices from the other distributive properties ## Tags semilattice, lattice -/ set_option old_structure_cmd true universes u v w variables {α : Type u} {β : Type v} -- TODO: move this eventually, if we decide to use them attribute [ematch] le_trans lt_of_le_of_lt lt_of_lt_of_le lt_trans section -- TODO: this seems crazy, but it also seems to work reasonably well @[ematch] theorem le_antisymm' [partial_order α] : ∀ {a b : α}, (: a ≤ b :) → b ≤ a → a = b := @le_antisymm _ _ end /- TODO: automatic construction of dual definitions / theorems -/ /-! ### Join-semilattices -/ /-- A `semilattice_sup` is a join-semilattice, that is, a partial order with a join (a.k.a. lub / least upper bound, sup / supremum) operation `⊔` which is the least element larger than both factors. -/ @[protect_proj, ancestor has_sup partial_order] class semilattice_sup (α : Type u) extends has_sup α, partial_order α := (le_sup_left : ∀ a b : α, a ≤ a ⊔ b) (le_sup_right : ∀ a b : α, b ≤ a ⊔ b) (sup_le : ∀ a b c : α, a ≤ c → b ≤ c → a ⊔ b ≤ c) /-- A type with a commutative, associative and idempotent binary `sup` operation has the structure of a join-semilattice. The partial order is defined so that `a ≤ b` unfolds to `a ⊔ b = b`; cf. `sup_eq_right`. -/ def semilattice_sup.mk' {α : Type*} [has_sup α] (sup_comm : ∀ (a b : α), a ⊔ b = b ⊔ a) (sup_assoc : ∀ (a b c : α), a ⊔ b ⊔ c = a ⊔ (b ⊔ c)) (sup_idem : ∀ (a : α), a ⊔ a = a) : semilattice_sup α := { sup := (⊔), le := λ a b, a ⊔ b = b, le_refl := sup_idem, le_trans := λ a b c hab hbc, begin dsimp only [(≤)] at *, rwa [←hbc, ←sup_assoc, hab], end, le_antisymm := λ a b hab hba, begin dsimp only [(≤)] at *, rwa [←hba, sup_comm], end, le_sup_left := λ a b, show a ⊔ (a ⊔ b) = (a ⊔ b), by rw [←sup_assoc, sup_idem], le_sup_right := λ a b, show b ⊔ (a ⊔ b) = (a ⊔ b), by rw [sup_comm, sup_assoc, sup_idem], sup_le := λ a b c hac hbc, begin dsimp only [(≤), preorder.le] at *, rwa [sup_assoc, hbc], end } instance (α : Type*) [has_inf α] : has_sup αᵒᵈ := ⟨((⊓) : α → α → α)⟩ instance (α : Type*) [has_sup α] : has_inf αᵒᵈ := ⟨((⊔) : α → α → α)⟩ section semilattice_sup variables [semilattice_sup α] {a b c d : α} @[simp] theorem le_sup_left : a ≤ a ⊔ b := semilattice_sup.le_sup_left a b @[ematch] theorem le_sup_left' : a ≤ (: a ⊔ b :) := le_sup_left @[simp] theorem le_sup_right : b ≤ a ⊔ b := semilattice_sup.le_sup_right a b @[ematch] theorem le_sup_right' : b ≤ (: a ⊔ b :) := le_sup_right theorem le_sup_of_le_left (h : c ≤ a) : c ≤ a ⊔ b := le_trans h le_sup_left theorem le_sup_of_le_right (h : c ≤ b) : c ≤ a ⊔ b := le_trans h le_sup_right theorem lt_sup_of_lt_left (h : c < a) : c < a ⊔ b := h.trans_le le_sup_left theorem lt_sup_of_lt_right (h : c < b) : c < a ⊔ b := h.trans_le le_sup_right theorem sup_le : a ≤ c → b ≤ c → a ⊔ b ≤ c := semilattice_sup.sup_le a b c @[simp] theorem sup_le_iff : a ⊔ b ≤ c ↔ a ≤ c ∧ b ≤ c := ⟨assume h : a ⊔ b ≤ c, ⟨le_trans le_sup_left h, le_trans le_sup_right h⟩, assume ⟨h₁, h₂⟩, sup_le h₁ h₂⟩ @[simp] lemma sup_eq_left : a ⊔ b = a ↔ b ≤ a := le_antisymm_iff.trans $ by simp [le_rfl] @[simp] lemma sup_eq_right : a ⊔ b = b ↔ a ≤ b := le_antisymm_iff.trans $ by simp [le_rfl] @[simp] lemma left_eq_sup : a = a ⊔ b ↔ b ≤ a := eq_comm.trans sup_eq_left @[simp] lemma right_eq_sup : b = a ⊔ b ↔ a ≤ b := eq_comm.trans sup_eq_right alias sup_eq_left ↔ _ sup_of_le_left alias sup_eq_right ↔ le_of_sup_eq sup_of_le_right attribute [simp] sup_of_le_left sup_of_le_right @[simp] theorem left_lt_sup : a < a ⊔ b ↔ ¬b ≤ a := le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup @[simp] theorem right_lt_sup : b < a ⊔ b ↔ ¬a ≤ b := le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup lemma left_or_right_lt_sup (h : a ≠ b) : (a < a ⊔ b ∨ b < a ⊔ b) := h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2 theorem le_iff_exists_sup : a ≤ b ↔ ∃ c, b = a ⊔ c := begin split, { intro h, exact ⟨b, (sup_eq_right.mpr h).symm⟩ }, { rintro ⟨c, (rfl : _ = _ ⊔ _)⟩, exact le_sup_left } end theorem sup_le_sup (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊔ c ≤ b ⊔ d := sup_le (le_sup_of_le_left h₁) (le_sup_of_le_right h₂) theorem sup_le_sup_left (h₁ : a ≤ b) (c) : c ⊔ a ≤ c ⊔ b := sup_le_sup le_rfl h₁ theorem sup_le_sup_right (h₁ : a ≤ b) (c) : a ⊔ c ≤ b ⊔ c := sup_le_sup h₁ le_rfl @[simp] theorem sup_idem : a ⊔ a = a := by apply le_antisymm; simp instance sup_is_idempotent : is_idempotent α (⊔) := ⟨@sup_idem _ _⟩ theorem sup_comm : a ⊔ b = b ⊔ a := by apply le_antisymm; simp instance sup_is_commutative : is_commutative α (⊔) := ⟨@sup_comm _ _⟩ theorem sup_assoc : a ⊔ b ⊔ c = a ⊔ (b ⊔ c) := eq_of_forall_ge_iff $ λ x, by simp only [sup_le_iff, and_assoc] instance sup_is_associative : is_associative α (⊔) := ⟨@sup_assoc _ _⟩ lemma sup_left_right_swap (a b c : α) : a ⊔ b ⊔ c = c ⊔ b ⊔ a := by rw [sup_comm, @sup_comm _ _ a, sup_assoc] @[simp] lemma sup_left_idem : a ⊔ (a ⊔ b) = a ⊔ b := by rw [← sup_assoc, sup_idem] @[simp] lemma sup_right_idem : (a ⊔ b) ⊔ b = a ⊔ b := by rw [sup_assoc, sup_idem] lemma sup_left_comm (a b c : α) : a ⊔ (b ⊔ c) = b ⊔ (a ⊔ c) := by rw [← sup_assoc, ← sup_assoc, @sup_comm α _ a] lemma sup_right_comm (a b c : α) : a ⊔ b ⊔ c = a ⊔ c ⊔ b := by rw [sup_assoc, sup_assoc, @sup_comm _ _ b] lemma sup_sup_sup_comm (a b c d : α) : a ⊔ b ⊔ (c ⊔ d) = a ⊔ c ⊔ (b ⊔ d) := by rw [sup_assoc, sup_left_comm b, ←sup_assoc] lemma sup_sup_distrib_left (a b c : α) : a ⊔ (b ⊔ c) = (a ⊔ b) ⊔ (a ⊔ c) := by rw [sup_sup_sup_comm, sup_idem] lemma sup_sup_distrib_right (a b c : α) : (a ⊔ b) ⊔ c = (a ⊔ c) ⊔ (b ⊔ c) := by rw [sup_sup_sup_comm, sup_idem] lemma sup_congr_left (hb : b ≤ a ⊔ c) (hc : c ≤ a ⊔ b) : a ⊔ b = a ⊔ c := (sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc lemma sup_congr_right (ha : a ≤ b ⊔ c) (hb : b ≤ a ⊔ c) : a ⊔ c = b ⊔ c := (sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right lemma sup_eq_sup_iff_left : a ⊔ b = a ⊔ c ↔ b ≤ a ⊔ c ∧ c ≤ a ⊔ b := ⟨λ h, ⟨h ▸ le_sup_right, h.symm ▸ le_sup_right⟩, λ h, sup_congr_left h.1 h.2⟩ lemma sup_eq_sup_iff_right : a ⊔ c = b ⊔ c ↔ a ≤ b ⊔ c ∧ b ≤ a ⊔ c := ⟨λ h, ⟨h ▸ le_sup_left, h.symm ▸ le_sup_left⟩, λ h, sup_congr_right h.1 h.2⟩ lemma ne.lt_sup_or_lt_sup (hab : a ≠ b) : a < a ⊔ b ∨ b < a ⊔ b := hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2 /-- If `f` is monotone, `g` is antitone, and `f ≤ g`, then for all `a`, `b` we have `f a ≤ g b`. -/ theorem monotone.forall_le_of_antitone {β : Type*} [preorder β] {f g : α → β} (hf : monotone f) (hg : antitone g) (h : f ≤ g) (m n : α) : f m ≤ g n := calc f m ≤ f (m ⊔ n) : hf le_sup_left ... ≤ g (m ⊔ n) : h _ ... ≤ g n : hg le_sup_right theorem semilattice_sup.ext_sup {α} {A B : semilattice_sup α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) (x y : α) : (by haveI := A; exact (x ⊔ y)) = x ⊔ y := eq_of_forall_ge_iff $ λ c, by simp only [sup_le_iff]; rw [← H, @sup_le_iff α A, H, H] theorem semilattice_sup.ext {α} {A B : semilattice_sup α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := begin have := partial_order.ext H, have ss := funext (λ x, funext $ semilattice_sup.ext_sup H x), casesI A, casesI B, injection this; congr' end lemma ite_le_sup (s s' : α) (P : Prop) [decidable P] : ite P s s' ≤ s ⊔ s' := if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right end semilattice_sup /-! ### Meet-semilattices -/ /-- A `semilattice_inf` is a meet-semilattice, that is, a partial order with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation `⊓` which is the greatest element smaller than both factors. -/ @[protect_proj, ancestor has_inf partial_order] class semilattice_inf (α : Type u) extends has_inf α, partial_order α := (inf_le_left : ∀ a b : α, a ⊓ b ≤ a) (inf_le_right : ∀ a b : α, a ⊓ b ≤ b) (le_inf : ∀ a b c : α, a ≤ b → a ≤ c → a ≤ b ⊓ c) instance (α) [semilattice_inf α] : semilattice_sup αᵒᵈ := { le_sup_left := semilattice_inf.inf_le_left, le_sup_right := semilattice_inf.inf_le_right, sup_le := assume a b c hca hcb, @semilattice_inf.le_inf α _ _ _ _ hca hcb, .. order_dual.partial_order α, .. order_dual.has_sup α } instance (α) [semilattice_sup α] : semilattice_inf αᵒᵈ := { inf_le_left := @le_sup_left α _, inf_le_right := @le_sup_right α _, le_inf := assume a b c hca hcb, @sup_le α _ _ _ _ hca hcb, .. order_dual.partial_order α, .. order_dual.has_inf α } theorem semilattice_sup.dual_dual (α : Type*) [H : semilattice_sup α] : order_dual.semilattice_sup αᵒᵈ = H := semilattice_sup.ext $ λ _ _, iff.rfl section semilattice_inf variables [semilattice_inf α] {a b c d : α} @[simp] theorem inf_le_left : a ⊓ b ≤ a := semilattice_inf.inf_le_left a b @[ematch] theorem inf_le_left' : (: a ⊓ b :) ≤ a := semilattice_inf.inf_le_left a b @[simp] theorem inf_le_right : a ⊓ b ≤ b := semilattice_inf.inf_le_right a b @[ematch] theorem inf_le_right' : (: a ⊓ b :) ≤ b := semilattice_inf.inf_le_right a b theorem le_inf : a ≤ b → a ≤ c → a ≤ b ⊓ c := semilattice_inf.le_inf a b c theorem inf_le_of_left_le (h : a ≤ c) : a ⊓ b ≤ c := le_trans inf_le_left h theorem inf_le_of_right_le (h : b ≤ c) : a ⊓ b ≤ c := le_trans inf_le_right h theorem inf_lt_of_left_lt (h : a < c) : a ⊓ b < c := lt_of_le_of_lt inf_le_left h theorem inf_lt_of_right_lt (h : b < c) : a ⊓ b < c := lt_of_le_of_lt inf_le_right h @[simp] theorem le_inf_iff : a ≤ b ⊓ c ↔ a ≤ b ∧ a ≤ c := @sup_le_iff αᵒᵈ _ _ _ _ @[simp] lemma inf_eq_left : a ⊓ b = a ↔ a ≤ b := le_antisymm_iff.trans $ by simp [le_rfl] @[simp] lemma inf_eq_right : a ⊓ b = b ↔ b ≤ a := le_antisymm_iff.trans $ by simp [le_rfl] @[simp] lemma left_eq_inf : a = a ⊓ b ↔ a ≤ b := eq_comm.trans inf_eq_left @[simp] lemma right_eq_inf : b = a ⊓ b ↔ b ≤ a := eq_comm.trans inf_eq_right alias inf_eq_left ↔ le_of_inf_eq inf_of_le_left alias inf_eq_right ↔ _ inf_of_le_right attribute [simp] inf_of_le_left inf_of_le_right @[simp] theorem inf_lt_left : a ⊓ b < a ↔ ¬a ≤ b := @left_lt_sup αᵒᵈ _ _ _ @[simp] theorem inf_lt_right : a ⊓ b < b ↔ ¬b ≤ a := @right_lt_sup αᵒᵈ _ _ _ theorem inf_lt_left_or_right (h : a ≠ b) : a ⊓ b < a ∨ a ⊓ b < b := @left_or_right_lt_sup αᵒᵈ _ _ _ h theorem inf_le_inf (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊓ c ≤ b ⊓ d := @sup_le_sup αᵒᵈ _ _ _ _ _ h₁ h₂ lemma inf_le_inf_right (a : α) {b c : α} (h : b ≤ c) : b ⊓ a ≤ c ⊓ a := inf_le_inf h le_rfl lemma inf_le_inf_left (a : α) {b c : α} (h : b ≤ c) : a ⊓ b ≤ a ⊓ c := inf_le_inf le_rfl h @[simp] lemma inf_idem : a ⊓ a = a := @sup_idem αᵒᵈ _ _ instance inf_is_idempotent : is_idempotent α (⊓) := ⟨@inf_idem _ _⟩ lemma inf_comm : a ⊓ b = b ⊓ a := @sup_comm αᵒᵈ _ _ _ instance inf_is_commutative : is_commutative α (⊓) := ⟨@inf_comm _ _⟩ lemma inf_assoc : a ⊓ b ⊓ c = a ⊓ (b ⊓ c) := @sup_assoc αᵒᵈ _ a b c instance inf_is_associative : is_associative α (⊓) := ⟨@inf_assoc _ _⟩ lemma inf_left_right_swap (a b c : α) : a ⊓ b ⊓ c = c ⊓ b ⊓ a := @sup_left_right_swap αᵒᵈ _ _ _ _ @[simp] lemma inf_left_idem : a ⊓ (a ⊓ b) = a ⊓ b := @sup_left_idem αᵒᵈ _ a b @[simp] lemma inf_right_idem : (a ⊓ b) ⊓ b = a ⊓ b := @sup_right_idem αᵒᵈ _ a b lemma inf_left_comm (a b c : α) : a ⊓ (b ⊓ c) = b ⊓ (a ⊓ c) := @sup_left_comm αᵒᵈ _ a b c lemma inf_right_comm (a b c : α) : a ⊓ b ⊓ c = a ⊓ c ⊓ b := @sup_right_comm αᵒᵈ _ a b c lemma inf_inf_inf_comm (a b c d : α) : a ⊓ b ⊓ (c ⊓ d) = a ⊓ c ⊓ (b ⊓ d) := @sup_sup_sup_comm αᵒᵈ _ _ _ _ _ lemma inf_inf_distrib_left (a b c : α) : a ⊓ (b ⊓ c) = (a ⊓ b) ⊓ (a ⊓ c) := @sup_sup_distrib_left αᵒᵈ _ _ _ _ lemma inf_inf_distrib_right (a b c : α) : (a ⊓ b) ⊓ c = (a ⊓ c) ⊓ (b ⊓ c) := @sup_sup_distrib_right αᵒᵈ _ _ _ _ lemma inf_congr_left (hb : a ⊓ c ≤ b) (hc : a ⊓ b ≤ c) : a ⊓ b = a ⊓ c := @sup_congr_left αᵒᵈ _ _ _ _ hb hc lemma inf_congr_right (h1 : b ⊓ c ≤ a) (h2 : a ⊓ c ≤ b) : a ⊓ c = b ⊓ c := @sup_congr_right αᵒᵈ _ _ _ _ h1 h2 lemma inf_eq_inf_iff_left : a ⊓ b = a ⊓ c ↔ a ⊓ c ≤ b ∧ a ⊓ b ≤ c := @sup_eq_sup_iff_left αᵒᵈ _ _ _ _ lemma inf_eq_inf_iff_right : a ⊓ c = b ⊓ c ↔ b ⊓ c ≤ a ∧ a ⊓ c ≤ b := @sup_eq_sup_iff_right αᵒᵈ _ _ _ _ lemma ne.inf_lt_or_inf_lt : a ≠ b → a ⊓ b < a ∨ a ⊓ b < b := @ne.lt_sup_or_lt_sup αᵒᵈ _ _ _ theorem semilattice_inf.ext_inf {α} {A B : semilattice_inf α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) (x y : α) : (by haveI := A; exact (x ⊓ y)) = x ⊓ y := eq_of_forall_le_iff $ λ c, by simp only [le_inf_iff]; rw [← H, @le_inf_iff α A, H, H] theorem semilattice_inf.ext {α} {A B : semilattice_inf α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := begin have := partial_order.ext H, have ss := funext (λ x, funext $ semilattice_inf.ext_inf H x), casesI A, casesI B, injection this; congr' end theorem semilattice_inf.dual_dual (α : Type*) [H : semilattice_inf α] : order_dual.semilattice_inf αᵒᵈ = H := semilattice_inf.ext $ λ _ _, iff.rfl lemma inf_le_ite (s s' : α) (P : Prop) [decidable P] : s ⊓ s' ≤ ite P s s' := @ite_le_sup αᵒᵈ _ _ _ _ _ end semilattice_inf /-- A type with a commutative, associative and idempotent binary `inf` operation has the structure of a meet-semilattice. The partial order is defined so that `a ≤ b` unfolds to `b ⊓ a = a`; cf. `inf_eq_right`. -/ def semilattice_inf.mk' {α : Type*} [has_inf α] (inf_comm : ∀ (a b : α), a ⊓ b = b ⊓ a) (inf_assoc : ∀ (a b c : α), a ⊓ b ⊓ c = a ⊓ (b ⊓ c)) (inf_idem : ∀ (a : α), a ⊓ a = a) : semilattice_inf α := begin haveI : semilattice_sup αᵒᵈ := semilattice_sup.mk' inf_comm inf_assoc inf_idem, haveI i := order_dual.semilattice_inf αᵒᵈ, exact i, end /-! ### Lattices -/ /-- A lattice is a join-semilattice which is also a meet-semilattice. -/ @[protect_proj, ancestor semilattice_sup semilattice_inf] class lattice (α : Type u) extends semilattice_sup α, semilattice_inf α instance (α) [lattice α] : lattice αᵒᵈ := { .. order_dual.semilattice_sup α, .. order_dual.semilattice_inf α } /-- The partial orders from `semilattice_sup_mk'` and `semilattice_inf_mk'` agree if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a ⊔ a ⊓ b = a`) and `inf_sup_self` (`a ⊓ (a ⊔ b) = a`). -/ lemma semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order {α : Type*} [has_sup α] [has_inf α] (sup_comm : ∀ (a b : α), a ⊔ b = b ⊔ a) (sup_assoc : ∀ (a b c : α), a ⊔ b ⊔ c = a ⊔ (b ⊔ c)) (sup_idem : ∀ (a : α), a ⊔ a = a) (inf_comm : ∀ (a b : α), a ⊓ b = b ⊓ a) (inf_assoc : ∀ (a b c : α), a ⊓ b ⊓ c = a ⊓ (b ⊓ c)) (inf_idem : ∀ (a : α), a ⊓ a = a) (sup_inf_self : ∀ (a b : α), a ⊔ a ⊓ b = a) (inf_sup_self : ∀ (a b : α), a ⊓ (a ⊔ b) = a) : @semilattice_sup.to_partial_order _ (semilattice_sup.mk' sup_comm sup_assoc sup_idem) = @semilattice_inf.to_partial_order _ (semilattice_inf.mk' inf_comm inf_assoc inf_idem) := partial_order.ext $ λ a b, show a ⊔ b = b ↔ b ⊓ a = a, from ⟨λ h, by rw [←h, inf_comm, inf_sup_self], λ h, by rw [←h, sup_comm, sup_inf_self]⟩ /-- A type with a pair of commutative and associative binary operations which satisfy two absorption laws relating the two operations has the structure of a lattice. The partial order is defined so that `a ≤ b` unfolds to `a ⊔ b = b`; cf. `sup_eq_right`. -/ def lattice.mk' {α : Type*} [has_sup α] [has_inf α] (sup_comm : ∀ (a b : α), a ⊔ b = b ⊔ a) (sup_assoc : ∀ (a b c : α), a ⊔ b ⊔ c = a ⊔ (b ⊔ c)) (inf_comm : ∀ (a b : α), a ⊓ b = b ⊓ a) (inf_assoc : ∀ (a b c : α), a ⊓ b ⊓ c = a ⊓ (b ⊓ c)) (sup_inf_self : ∀ (a b : α), a ⊔ a ⊓ b = a) (inf_sup_self : ∀ (a b : α), a ⊓ (a ⊔ b) = a) : lattice α := have sup_idem : ∀ (b : α), b ⊔ b = b := λ b, calc b ⊔ b = b ⊔ b ⊓ (b ⊔ b) : by rw inf_sup_self ... = b : by rw sup_inf_self, have inf_idem : ∀ (b : α), b ⊓ b = b := λ b, calc b ⊓ b = b ⊓ (b ⊔ b ⊓ b) : by rw sup_inf_self ... = b : by rw inf_sup_self, let semilatt_inf_inst := semilattice_inf.mk' inf_comm inf_assoc inf_idem, semilatt_sup_inst := semilattice_sup.mk' sup_comm sup_assoc sup_idem, -- here we help Lean to see that the two partial orders are equal partial_order_inst := @semilattice_sup.to_partial_order _ semilatt_sup_inst in have partial_order_eq : partial_order_inst = @semilattice_inf.to_partial_order _ semilatt_inf_inst := semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order _ _ _ _ _ _ sup_inf_self inf_sup_self, { inf_le_left := λ a b, by { rw partial_order_eq, apply inf_le_left }, inf_le_right := λ a b, by { rw partial_order_eq, apply inf_le_right }, le_inf := λ a b c, by { rw partial_order_eq, apply le_inf }, ..partial_order_inst, ..semilatt_sup_inst, ..semilatt_inf_inst, } section lattice variables [lattice α] {a b c d : α} lemma inf_le_sup : a ⊓ b ≤ a ⊔ b := inf_le_left.trans le_sup_left @[simp] lemma sup_le_inf : a ⊔ b ≤ a ⊓ b ↔ a = b := ⟨λ h, le_antisymm (le_sup_left.trans $ h.trans inf_le_right) (le_sup_right.trans $ h.trans inf_le_left), by { rintro rfl, simp }⟩ @[simp] lemma inf_eq_sup : a ⊓ b = a ⊔ b ↔ a = b := by rw [←inf_le_sup.ge_iff_eq, sup_le_inf] @[simp] lemma sup_eq_inf : a ⊔ b = a ⊓ b ↔ a = b := eq_comm.trans inf_eq_sup @[simp] lemma inf_lt_sup : a ⊓ b < a ⊔ b ↔ a ≠ b := by rw [inf_le_sup.lt_iff_ne, ne.def, inf_eq_sup] lemma inf_eq_and_sup_eq_iff : a ⊓ b = c ∧ a ⊔ b = c ↔ a = c ∧ b = c := begin refine ⟨λ h, _, _⟩, { obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm), simpa using h }, { rintro ⟨rfl, rfl⟩, exact ⟨inf_idem, sup_idem⟩ } end /-! #### Distributivity laws -/ /- TODO: better names? -/ theorem sup_inf_le : a ⊔ (b ⊓ c) ≤ (a ⊔ b) ⊓ (a ⊔ c) := le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _) theorem le_inf_sup : (a ⊓ b) ⊔ (a ⊓ c) ≤ a ⊓ (b ⊔ c) := sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right) theorem inf_sup_self : a ⊓ (a ⊔ b) = a := by simp theorem sup_inf_self : a ⊔ (a ⊓ b) = a := by simp theorem sup_eq_iff_inf_eq : a ⊔ b = b ↔ a ⊓ b = a := by rw [sup_eq_right, ←inf_eq_left] theorem lattice.ext {α} {A B : lattice α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := begin have SS : @lattice.to_semilattice_sup α A = @lattice.to_semilattice_sup α B := semilattice_sup.ext H, have II := semilattice_inf.ext H, casesI A, casesI B, injection SS; injection II; congr' end end lattice /-! ### Distributive lattices -/ /-- A distributive lattice is a lattice that satisfies any of four equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`, on the left or right). The definition here chooses `le_sup_inf`: `(x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ (y ⊓ z)`. To prove distributivity from the dual law, use `distrib_lattice.of_inf_sup_le`. A classic example of a distributive lattice is the lattice of subsets of a set, and in fact this example is generic in the sense that every distributive lattice is realizable as a sublattice of a powerset lattice. -/ @[protect_proj, ancestor lattice] class distrib_lattice α extends lattice α := (le_sup_inf : ∀x y z : α, (x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ (y ⊓ z)) section distrib_lattice variables [distrib_lattice α] {x y z : α} theorem le_sup_inf : ∀{x y z : α}, (x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ (y ⊓ z) := distrib_lattice.le_sup_inf theorem sup_inf_left : x ⊔ (y ⊓ z) = (x ⊔ y) ⊓ (x ⊔ z) := le_antisymm sup_inf_le le_sup_inf theorem sup_inf_right : (y ⊓ z) ⊔ x = (y ⊔ x) ⊓ (z ⊔ x) := by simp only [sup_inf_left, λy:α, @sup_comm α _ y x, eq_self_iff_true] theorem inf_sup_left : x ⊓ (y ⊔ z) = (x ⊓ y) ⊔ (x ⊓ z) := calc x ⊓ (y ⊔ z) = (x ⊓ (x ⊔ z)) ⊓ (y ⊔ z) : by rw [inf_sup_self] ... = x ⊓ ((x ⊓ y) ⊔ z) : by simp only [inf_assoc, sup_inf_right, eq_self_iff_true] ... = (x ⊔ (x ⊓ y)) ⊓ ((x ⊓ y) ⊔ z) : by rw [sup_inf_self] ... = ((x ⊓ y) ⊔ x) ⊓ ((x ⊓ y) ⊔ z) : by rw [sup_comm] ... = (x ⊓ y) ⊔ (x ⊓ z) : by rw [sup_inf_left] instance (α : Type*) [distrib_lattice α] : distrib_lattice αᵒᵈ := { le_sup_inf := assume x y z, le_of_eq inf_sup_left.symm, .. order_dual.lattice α } theorem inf_sup_right : (y ⊔ z) ⊓ x = (y ⊓ x) ⊔ (z ⊓ x) := by simp only [inf_sup_left, λy:α, @inf_comm α _ y x, eq_self_iff_true] lemma le_of_inf_le_sup_le (h₁ : x ⊓ z ≤ y ⊓ z) (h₂ : x ⊔ z ≤ y ⊔ z) : x ≤ y := calc x ≤ (y ⊓ z) ⊔ x : le_sup_right ... = (y ⊔ x) ⊓ (x ⊔ z) : by rw [sup_inf_right, @sup_comm _ _ x] ... ≤ (y ⊔ x) ⊓ (y ⊔ z) : inf_le_inf_left _ h₂ ... = y ⊔ (x ⊓ z) : sup_inf_left.symm ... ≤ y ⊔ (y ⊓ z) : sup_le_sup_left h₁ _ ... ≤ _ : sup_le (le_refl y) inf_le_left lemma eq_of_inf_eq_sup_eq {α : Type u} [distrib_lattice α] {a b c : α} (h₁ : b ⊓ a = c ⊓ a) (h₂ : b ⊔ a = c ⊔ a) : b = c := le_antisymm (le_of_inf_le_sup_le (le_of_eq h₁) (le_of_eq h₂)) (le_of_inf_le_sup_le (le_of_eq h₁.symm) (le_of_eq h₂.symm)) end distrib_lattice /-- Prove distributivity of an existing lattice from the dual distributive law. -/ @[reducible] -- See note [reducible non-instances] def distrib_lattice.of_inf_sup_le [lattice α] (inf_sup_le : ∀ a b c : α, a ⊓ (b ⊔ c) ≤ (a ⊓ b) ⊔ (a ⊓ c)) : distrib_lattice α := { ..‹lattice α›, ..@order_dual.distrib_lattice αᵒᵈ { le_sup_inf := inf_sup_le, ..order_dual.lattice _ } } /-! ### Lattices derived from linear orders -/ @[priority 100] -- see Note [lower instance priority] instance linear_order.to_lattice {α : Type u} [o : linear_order α] : lattice α := { sup := max, le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := assume a b c, max_le, inf := min, inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := assume a b c, le_min, ..o } section linear_order variables [linear_order α] {a b c d : α} lemma sup_eq_max : a ⊔ b = max a b := rfl lemma inf_eq_min : a ⊓ b = min a b := rfl lemma sup_ind (a b : α) {p : α → Prop} (ha : p a) (hb : p b) : p (a ⊔ b) := (is_total.total a b).elim (λ h : a ≤ b, by rwa sup_eq_right.2 h) (λ h, by rwa sup_eq_left.2 h) @[simp] lemma le_sup_iff : a ≤ b ⊔ c ↔ a ≤ b ∨ a ≤ c := ⟨λ h, (total_of (≤) c b).imp (λ bc, by rwa sup_eq_left.2 bc at h) (λ bc, by rwa sup_eq_right.2 bc at h), λ h, h.elim le_sup_of_le_left le_sup_of_le_right⟩ @[simp] lemma lt_sup_iff : a < b ⊔ c ↔ a < b ∨ a < c := ⟨λ h, (total_of (≤) c b).imp (λ bc, by rwa sup_eq_left.2 bc at h) (λ bc, by rwa sup_eq_right.2 bc at h), λ h, h.elim lt_sup_of_lt_left lt_sup_of_lt_right⟩ @[simp] lemma sup_lt_iff : b ⊔ c < a ↔ b < a ∧ c < a := ⟨λ h, ⟨le_sup_left.trans_lt h, le_sup_right.trans_lt h⟩, λ h, sup_ind b c h.1 h.2⟩ lemma inf_ind (a b : α) {p : α → Prop} : p a → p b → p (a ⊓ b) := @sup_ind αᵒᵈ _ _ _ _ @[simp] lemma inf_le_iff : b ⊓ c ≤ a ↔ b ≤ a ∨ c ≤ a := @le_sup_iff αᵒᵈ _ _ _ _ @[simp] lemma inf_lt_iff : b ⊓ c < a ↔ b < a ∨ c < a := @lt_sup_iff αᵒᵈ _ _ _ _ @[simp] lemma lt_inf_iff : a < b ⊓ c ↔ a < b ∧ a < c := @sup_lt_iff αᵒᵈ _ _ _ _ variables (a b c d) lemma max_max_max_comm : max (max a b) (max c d) = max (max a c) (max b d) := sup_sup_sup_comm _ _ _ _ lemma min_min_min_comm : min (min a b) (min c d) = min (min a c) (min b d) := inf_inf_inf_comm _ _ _ _ end linear_order lemma sup_eq_max_default [semilattice_sup α] [decidable_rel ((≤) : α → α → Prop)] [is_total α (≤)] : (⊔) = (max_default : α → α → α) := begin ext x y, dunfold max_default, split_ifs with h', exacts [sup_of_le_right h', sup_of_le_left $ (total_of (≤) x y).resolve_left h'] end lemma inf_eq_min_default [semilattice_inf α] [decidable_rel ((≤) : α → α → Prop)] [is_total α (≤)] : (⊓) = (min_default : α → α → α) := begin ext x y, dunfold min_default, split_ifs with h', exacts [inf_of_le_left h', inf_of_le_right $ (total_of (≤) x y).resolve_left h'] end /-- A lattice with total order is a linear order. See note [reducible non-instances]. -/ @[reducible] def lattice.to_linear_order (α : Type u) [lattice α] [decidable_eq α] [decidable_rel ((≤) : α → α → Prop)] [decidable_rel ((<) : α → α → Prop)] [is_total α (≤)] : linear_order α := { decidable_le := ‹_›, decidable_eq := ‹_›, decidable_lt := ‹_›, le_total := total_of (≤), max := (⊔), max_def := sup_eq_max_default, min := (⊓), min_def := inf_eq_min_default, ..‹lattice α› } @[priority 100] -- see Note [lower instance priority] instance linear_order.to_distrib_lattice {α : Type u} [o : linear_order α] : distrib_lattice α := { le_sup_inf := assume a b c, match le_total b c with | or.inl h := inf_le_of_left_le $ sup_le_sup_left (le_inf (le_refl b) h) _ | or.inr h := inf_le_of_right_le $ sup_le_sup_left (le_inf h (le_refl c)) _ end, ..linear_order.to_lattice } instance nat.distrib_lattice : distrib_lattice ℕ := by apply_instance /-! ### Dual order -/ open order_dual @[simp] lemma of_dual_inf [has_sup α] (a b: αᵒᵈ) : of_dual (a ⊓ b) = of_dual a ⊔ of_dual b := rfl @[simp] lemma of_dual_sup [has_inf α] (a b : αᵒᵈ) : of_dual (a ⊔ b) = of_dual a ⊓ of_dual b := rfl @[simp] lemma to_dual_inf [has_inf α] (a b : α) : to_dual (a ⊓ b) = to_dual a ⊔ to_dual b := rfl @[simp] lemma to_dual_sup [has_sup α] (a b : α) : to_dual (a ⊔ b) = to_dual a ⊓ to_dual b := rfl section linear_order variables [linear_order α] @[simp] lemma of_dual_min (a b : αᵒᵈ) : of_dual (min a b) = max (of_dual a) (of_dual b) := rfl @[simp] lemma of_dual_max (a b : αᵒᵈ) : of_dual (max a b) = min (of_dual a) (of_dual b) := rfl @[simp] lemma to_dual_min (a b : α) : to_dual (min a b) = max (to_dual a) (to_dual b) := rfl @[simp] lemma to_dual_max (a b : α) : to_dual (max a b) = min (to_dual a) (to_dual b) := rfl end linear_order /-! ### Function lattices -/ namespace pi variables {ι : Type*} {α' : ι → Type*} instance [Π i, has_sup (α' i)] : has_sup (Π i, α' i) := ⟨λ f g i, f i ⊔ g i⟩ @[simp] lemma sup_apply [Π i, has_sup (α' i)] (f g : Π i, α' i) (i : ι) : (f ⊔ g) i = f i ⊔ g i := rfl lemma sup_def [Π i, has_sup (α' i)] (f g : Π i, α' i) : f ⊔ g = λ i, f i ⊔ g i := rfl instance [Π i, has_inf (α' i)] : has_inf (Π i, α' i) := ⟨λ f g i, f i ⊓ g i⟩ @[simp] lemma inf_apply [Π i, has_inf (α' i)] (f g : Π i, α' i) (i : ι) : (f ⊓ g) i = f i ⊓ g i := rfl lemma inf_def [Π i, has_inf (α' i)] (f g : Π i, α' i) : f ⊓ g = λ i, f i ⊓ g i := rfl instance [Π i, semilattice_sup (α' i)] : semilattice_sup (Π i, α' i) := by refine_struct { sup := (⊔), .. pi.partial_order }; tactic.pi_instance_derive_field instance [Π i, semilattice_inf (α' i)] : semilattice_inf (Π i, α' i) := by refine_struct { inf := (⊓), .. pi.partial_order }; tactic.pi_instance_derive_field instance [Π i, lattice (α' i)] : lattice (Π i, α' i) := { .. pi.semilattice_sup, .. pi.semilattice_inf } instance [Π i, distrib_lattice (α' i)] : distrib_lattice (Π i, α' i) := by refine_struct { .. pi.lattice }; tactic.pi_instance_derive_field end pi namespace function variables {ι : Type*} {π : ι → Type*} [decidable_eq ι] lemma update_sup [Π i, semilattice_sup (π i)] (f : Π i, π i) (i : ι) (a b : π i) : f.update i (a ⊔ b) = f.update i a ⊔ f.update i b := funext $ λ j, by obtain rfl | hji := eq_or_ne j i; simp [update_noteq, *] lemma update_inf [Π i, semilattice_inf (π i)] (f : Π i, π i) (i : ι) (a b : π i) : f.update i (a ⊓ b) = f.update i a ⊓ f.update i b := funext $ λ j, by obtain rfl | hji := eq_or_ne j i; simp [update_noteq, *] end function /-! ### Monotone functions and lattices -/ namespace monotone /-- Pointwise supremum of two monotone functions is a monotone function. -/ protected lemma sup [preorder α] [semilattice_sup β] {f g : α → β} (hf : monotone f) (hg : monotone g) : monotone (f ⊔ g) := λ x y h, sup_le_sup (hf h) (hg h) /-- Pointwise infimum of two monotone functions is a monotone function. -/ protected lemma inf [preorder α] [semilattice_inf β] {f g : α → β} (hf : monotone f) (hg : monotone g) : monotone (f ⊓ g) := λ x y h, inf_le_inf (hf h) (hg h) /-- Pointwise maximum of two monotone functions is a monotone function. -/ protected lemma max [preorder α] [linear_order β] {f g : α → β} (hf : monotone f) (hg : monotone g) : monotone (λ x, max (f x) (g x)) := hf.sup hg /-- Pointwise minimum of two monotone functions is a monotone function. -/ protected lemma min [preorder α] [linear_order β] {f g : α → β} (hf : monotone f) (hg : monotone g) : monotone (λ x, min (f x) (g x)) := hf.inf hg lemma le_map_sup [semilattice_sup α] [semilattice_sup β] {f : α → β} (h : monotone f) (x y : α) : f x ⊔ f y ≤ f (x ⊔ y) := sup_le (h le_sup_left) (h le_sup_right) lemma map_inf_le [semilattice_inf α] [semilattice_inf β] {f : α → β} (h : monotone f) (x y : α) : f (x ⊓ y) ≤ f x ⊓ f y := le_inf (h inf_le_left) (h inf_le_right) lemma of_map_inf [semilattice_inf α] [semilattice_inf β] {f : α → β} (h : ∀ x y, f (x ⊓ y) = f x ⊓ f y) : monotone f := λ x y hxy, inf_eq_left.1 $ by rw [← h, inf_eq_left.2 hxy] lemma of_map_sup [semilattice_sup α] [semilattice_sup β] {f : α → β} (h : ∀ x y, f (x ⊔ y) = f x ⊔ f y) : monotone f := (@of_map_inf (order_dual α) (order_dual β) _ _ _ h).dual variables [linear_order α] lemma map_sup [semilattice_sup β] {f : α → β} (hf : monotone f) (x y : α) : f (x ⊔ y) = f x ⊔ f y := (is_total.total x y).elim (λ h : x ≤ y, by simp only [h, hf h, sup_of_le_right]) (λ h, by simp only [h, hf h, sup_of_le_left]) lemma map_inf [semilattice_inf β] {f : α → β} (hf : monotone f) (x y : α) : f (x ⊓ y) = f x ⊓ f y := hf.dual.map_sup _ _ end monotone namespace monotone_on /-- Pointwise supremum of two monotone functions is a monotone function. -/ protected lemma sup [preorder α] [semilattice_sup β] {f g : α → β} {s : set α} (hf : monotone_on f s) (hg : monotone_on g s) : monotone_on (f ⊔ g) s := λ x hx y hy h, sup_le_sup (hf hx hy h) (hg hx hy h) /-- Pointwise infimum of two monotone functions is a monotone function. -/ protected lemma inf [preorder α] [semilattice_inf β] {f g : α → β} {s : set α} (hf : monotone_on f s) (hg : monotone_on g s) : monotone_on (f ⊓ g) s := (hf.dual.sup hg.dual).dual /-- Pointwise maximum of two monotone functions is a monotone function. -/ protected lemma max [preorder α] [linear_order β] {f g : α → β} {s : set α} (hf : monotone_on f s) (hg : monotone_on g s) : monotone_on (λ x, max (f x) (g x)) s := hf.sup hg /-- Pointwise minimum of two monotone functions is a monotone function. -/ protected lemma min [preorder α] [linear_order β] {f g : α → β} {s : set α} (hf : monotone_on f s) (hg : monotone_on g s) : monotone_on (λ x, min (f x) (g x)) s := hf.inf hg end monotone_on namespace antitone /-- Pointwise supremum of two monotone functions is a monotone function. -/ protected lemma sup [preorder α] [semilattice_sup β] {f g : α → β} (hf : antitone f) (hg : antitone g) : antitone (f ⊔ g) := λ x y h, sup_le_sup (hf h) (hg h) /-- Pointwise infimum of two monotone functions is a monotone function. -/ protected lemma inf [preorder α] [semilattice_inf β] {f g : α → β} (hf : antitone f) (hg : antitone g) : antitone (f ⊓ g) := λ x y h, inf_le_inf (hf h) (hg h) /-- Pointwise maximum of two monotone functions is a monotone function. -/ protected lemma max [preorder α] [linear_order β] {f g : α → β} (hf : antitone f) (hg : antitone g) : antitone (λ x, max (f x) (g x)) := hf.sup hg /-- Pointwise minimum of two monotone functions is a monotone function. -/ protected lemma min [preorder α] [linear_order β] {f g : α → β} (hf : antitone f) (hg : antitone g) : antitone (λ x, min (f x) (g x)) := hf.inf hg lemma map_sup_le [semilattice_sup α] [semilattice_inf β] {f : α → β} (h : antitone f) (x y : α) : f (x ⊔ y) ≤ f x ⊓ f y := h.dual_right.le_map_sup x y lemma le_map_inf [semilattice_inf α] [semilattice_sup β] {f : α → β} (h : antitone f) (x y : α) : f x ⊔ f y ≤ f (x ⊓ y) := h.dual_right.map_inf_le x y variables [linear_order α] lemma map_sup [semilattice_inf β] {f : α → β} (hf : antitone f) (x y : α) : f (x ⊔ y) = f x ⊓ f y := hf.dual_right.map_sup x y lemma map_inf [semilattice_sup β] {f : α → β} (hf : antitone f) (x y : α) : f (x ⊓ y) = f x ⊔ f y := hf.dual_right.map_inf x y end antitone namespace antitone_on /-- Pointwise supremum of two antitone functions is a antitone function. -/ protected lemma sup [preorder α] [semilattice_sup β] {f g : α → β} {s : set α} (hf : antitone_on f s) (hg : antitone_on g s) : antitone_on (f ⊔ g) s := λ x hx y hy h, sup_le_sup (hf hx hy h) (hg hx hy h) /-- Pointwise infimum of two antitone functions is a antitone function. -/ protected lemma inf [preorder α] [semilattice_inf β] {f g : α → β} {s : set α} (hf : antitone_on f s) (hg : antitone_on g s) : antitone_on (f ⊓ g) s := (hf.dual.sup hg.dual).dual /-- Pointwise maximum of two antitone functions is a antitone function. -/ protected lemma max [preorder α] [linear_order β] {f g : α → β} {s : set α} (hf : antitone_on f s) (hg : antitone_on g s) : antitone_on (λ x, max (f x) (g x)) s := hf.sup hg /-- Pointwise minimum of two antitone functions is a antitone function. -/ protected lemma min [preorder α] [linear_order β] {f g : α → β} {s : set α} (hf : antitone_on f s) (hg : antitone_on g s) : antitone_on (λ x, min (f x) (g x)) s := hf.inf hg end antitone_on /-! ### Products of (semi-)lattices -/ namespace prod variables (α β) instance [has_sup α] [has_sup β] : has_sup (α × β) := ⟨λp q, ⟨p.1 ⊔ q.1, p.2 ⊔ q.2⟩⟩ instance [has_inf α] [has_inf β] : has_inf (α × β) := ⟨λp q, ⟨p.1 ⊓ q.1, p.2 ⊓ q.2⟩⟩ @[simp] lemma mk_sup_mk [has_sup α] [has_sup β] (a₁ a₂ : α) (b₁ b₂ : β) : (a₁, b₁) ⊔ (a₂, b₂) = (a₁ ⊔ a₂, b₁ ⊔ b₂) := rfl @[simp] lemma mk_inf_mk [has_inf α] [has_inf β] (a₁ a₂ : α) (b₁ b₂ : β) : (a₁, b₁) ⊓ (a₂, b₂) = (a₁ ⊓ a₂, b₁ ⊓ b₂) := rfl @[simp] lemma fst_sup [has_sup α] [has_sup β] (p q : α × β) : (p ⊔ q).fst = p.fst ⊔ q.fst := rfl @[simp] lemma fst_inf [has_inf α] [has_inf β] (p q : α × β) : (p ⊓ q).fst = p.fst ⊓ q.fst := rfl @[simp] lemma snd_sup [has_sup α] [has_sup β] (p q : α × β) : (p ⊔ q).snd = p.snd ⊔ q.snd := rfl @[simp] lemma snd_inf [has_inf α] [has_inf β] (p q : α × β) : (p ⊓ q).snd = p.snd ⊓ q.snd := rfl @[simp] lemma swap_sup [has_sup α] [has_sup β] (p q : α × β) : (p ⊔ q).swap = p.swap ⊔ q.swap := rfl @[simp] lemma swap_inf [has_inf α] [has_inf β] (p q : α × β) : (p ⊓ q).swap = p.swap ⊓ q.swap := rfl lemma sup_def [has_sup α] [has_sup β] (p q : α × β) : p ⊔ q = (p.fst ⊔ q.fst, p.snd ⊔ q.snd) := rfl lemma inf_def [has_inf α] [has_inf β] (p q : α × β) : p ⊓ q = (p.fst ⊓ q.fst, p.snd ⊓ q.snd) := rfl instance [semilattice_sup α] [semilattice_sup β] : semilattice_sup (α × β) := { sup_le := assume a b c h₁ h₂, ⟨sup_le h₁.1 h₂.1, sup_le h₁.2 h₂.2⟩, le_sup_left := assume a b, ⟨le_sup_left, le_sup_left⟩, le_sup_right := assume a b, ⟨le_sup_right, le_sup_right⟩, .. prod.partial_order α β, .. prod.has_sup α β } instance [semilattice_inf α] [semilattice_inf β] : semilattice_inf (α × β) := { le_inf := assume a b c h₁ h₂, ⟨le_inf h₁.1 h₂.1, le_inf h₁.2 h₂.2⟩, inf_le_left := assume a b, ⟨inf_le_left, inf_le_left⟩, inf_le_right := assume a b, ⟨inf_le_right, inf_le_right⟩, .. prod.partial_order α β, .. prod.has_inf α β } instance [lattice α] [lattice β] : lattice (α × β) := { .. prod.semilattice_inf α β, .. prod.semilattice_sup α β } instance [distrib_lattice α] [distrib_lattice β] : distrib_lattice (α × β) := { le_sup_inf := assume a b c, ⟨le_sup_inf, le_sup_inf⟩, .. prod.lattice α β } end prod /-! ### Subtypes of (semi-)lattices -/ namespace subtype /-- A subtype forms a `⊔`-semilattice if `⊔` preserves the property. See note [reducible non-instances]. -/ @[reducible] protected def semilattice_sup [semilattice_sup α] {P : α → Prop} (Psup : ∀⦃x y⦄, P x → P y → P (x ⊔ y)) : semilattice_sup {x : α // P x} := { sup := λ x y, ⟨x.1 ⊔ y.1, Psup x.2 y.2⟩, le_sup_left := λ x y, @le_sup_left _ _ (x : α) y, le_sup_right := λ x y, @le_sup_right _ _ (x : α) y, sup_le := λ x y z h1 h2, @sup_le α _ _ _ _ h1 h2, ..subtype.partial_order P } /-- A subtype forms a `⊓`-semilattice if `⊓` preserves the property. See note [reducible non-instances]. -/ @[reducible] protected def semilattice_inf [semilattice_inf α] {P : α → Prop} (Pinf : ∀⦃x y⦄, P x → P y → P (x ⊓ y)) : semilattice_inf {x : α // P x} := { inf := λ x y, ⟨x.1 ⊓ y.1, Pinf x.2 y.2⟩, inf_le_left := λ x y, @inf_le_left _ _ (x : α) y, inf_le_right := λ x y, @inf_le_right _ _ (x : α) y, le_inf := λ x y z h1 h2, @le_inf α _ _ _ _ h1 h2, ..subtype.partial_order P } /-- A subtype forms a lattice if `⊔` and `⊓` preserve the property. See note [reducible non-instances]. -/ @[reducible] protected def lattice [lattice α] {P : α → Prop} (Psup : ∀⦃x y⦄, P x → P y → P (x ⊔ y)) (Pinf : ∀⦃x y⦄, P x → P y → P (x ⊓ y)) : lattice {x : α // P x} := { ..subtype.semilattice_inf Pinf, ..subtype.semilattice_sup Psup } @[simp, norm_cast] lemma coe_sup [semilattice_sup α] {P : α → Prop} (Psup : ∀⦃x y⦄, P x → P y → P (x ⊔ y)) (x y : subtype P) : (by {haveI := subtype.semilattice_sup Psup, exact (x ⊔ y : subtype P)} : α) = x ⊔ y := rfl @[simp, norm_cast] lemma coe_inf [semilattice_inf α] {P : α → Prop} (Pinf : ∀⦃x y⦄, P x → P y → P (x ⊓ y)) (x y : subtype P) : (by {haveI := subtype.semilattice_inf Pinf, exact (x ⊓ y : subtype P)} : α) = x ⊓ y := rfl @[simp] lemma mk_sup_mk [semilattice_sup α] {P : α → Prop} (Psup : ∀⦃x y⦄, P x → P y → P (x ⊔ y)) {x y : α} (hx : P x) (hy : P y) : (by {haveI := subtype.semilattice_sup Psup, exact (⟨x, hx⟩ ⊔ ⟨y, hy⟩ : subtype P)}) = ⟨x ⊔ y, Psup hx hy⟩ := rfl @[simp] lemma mk_inf_mk [semilattice_inf α] {P : α → Prop} (Pinf : ∀⦃x y⦄, P x → P y → P (x ⊓ y)) {x y : α} (hx : P x) (hy : P y) : (by {haveI := subtype.semilattice_inf Pinf, exact (⟨x, hx⟩ ⊓ ⟨y, hy⟩ : subtype P)}) = ⟨x ⊓ y, Pinf hx hy⟩ := rfl end subtype section lift /-- A type endowed with `⊔` is a `semilattice_sup`, if it admits an injective map that preserves `⊔` to a `semilattice_sup`. See note [reducible non-instances]. -/ @[reducible] protected def function.injective.semilattice_sup [has_sup α] [semilattice_sup β] (f : α → β) (hf_inj : function.injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) : semilattice_sup α := { sup := has_sup.sup, le_sup_left := λ a b, by { change f a ≤ f (a ⊔ b), rw map_sup, exact le_sup_left, }, le_sup_right := λ a b, by { change f b ≤ f (a ⊔ b), rw map_sup, exact le_sup_right, }, sup_le := λ a b c ha hb, by { change f (a ⊔ b) ≤ f c, rw map_sup, exact sup_le ha hb, }, ..partial_order.lift f hf_inj} /-- A type endowed with `⊓` is a `semilattice_inf`, if it admits an injective map that preserves `⊓` to a `semilattice_inf`. See note [reducible non-instances]. -/ @[reducible] protected def function.injective.semilattice_inf [has_inf α] [semilattice_inf β] (f : α → β) (hf_inj : function.injective f) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) : semilattice_inf α := { inf := has_inf.inf, inf_le_left := λ a b, by { change f (a ⊓ b) ≤ f a, rw map_inf, exact inf_le_left, }, inf_le_right := λ a b, by { change f (a ⊓ b) ≤ f b, rw map_inf, exact inf_le_right, }, le_inf := λ a b c ha hb, by { change f a ≤ f (b ⊓ c), rw map_inf, exact le_inf ha hb, }, ..partial_order.lift f hf_inj} /-- A type endowed with `⊔` and `⊓` is a `lattice`, if it admits an injective map that preserves `⊔` and `⊓` to a `lattice`. See note [reducible non-instances]. -/ @[reducible] protected def function.injective.lattice [has_sup α] [has_inf α] [lattice β] (f : α → β) (hf_inj : function.injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) : lattice α := { ..hf_inj.semilattice_sup f map_sup, ..hf_inj.semilattice_inf f map_inf} /-- A type endowed with `⊔` and `⊓` is a `distrib_lattice`, if it admits an injective map that preserves `⊔` and `⊓` to a `distrib_lattice`. See note [reducible non-instances]. -/ @[reducible] protected def function.injective.distrib_lattice [has_sup α] [has_inf α] [distrib_lattice β] (f : α → β) (hf_inj : function.injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) : distrib_lattice α := { le_sup_inf := λ a b c, by { change f ((a ⊔ b) ⊓ (a ⊔ c)) ≤ f (a ⊔ b ⊓ c), rw [map_inf, map_sup, map_sup, map_sup, map_inf], exact le_sup_inf, }, ..hf_inj.lattice f map_sup map_inf, } end lift --To avoid noncomputability poisoning from `bool.complete_boolean_algebra` instance : distrib_lattice bool := linear_order.to_distrib_lattice
242e85e58c8cc4420fa869e7598ca4570a0ac0fd
8e381650eb2c1c5361be64ff97e47d956bf2ab9f
/src/spectrum_of_a_ring/spec.lean
8fe699d416446f367ed44cfaf851aa8bbeb48eb7
[]
no_license
alreadydone/lean-scheme
04c51ab08eca7ccf6c21344d45d202780fa667af
52d7624f57415eea27ed4dfa916cd94189221a1c
refs/heads/master
1,599,418,221,423
1,562,248,559,000
1,562,248,559,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
746
lean
/- Definition of Spec(R). https://stacks.math.columbia.edu/tag/00DZ -/ import topology.opens import ring_theory.ideals universe u section spectrum parameters (α : Type u) [comm_ring α] -- Spec(R). def Spec := {P : ideal α // ideal.is_prime P} parameter {α} -- General definitions. def Spec.V : set α → set Spec := λ E, {P | E ⊆ P.val} def Spec.V' : α → set Spec := λ f, {P | f ∈ P.val} def Spec.D : set α → set Spec := λ E, -Spec.V(E) def Spec.D' : α → set Spec := λ f, -Spec.V'(f) parameter (α) def Spec.univ := @set.univ Spec def Spec.empty := (∅ : set Spec) def Spec.open : set (set Spec) := {A | ∃ U, Spec.D U = A} def Spec.closed : set (set Spec) := {A | ∃ E, Spec.V E = A} end spectrum
bc7c762b99f6ce063614714af5da92897c7fd4bd
4727251e0cd73359b15b664c3170e5d754078599
/src/data/list/count.lean
e918fc3ef6aa917655ae27e988c22570503f3947
[ "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,602
lean
/- Copyright (c) 2014 Parikshit Khanna. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro -/ import data.list.big_operators /-! # Counting in lists This file proves basic properties of `list.countp` and `list.count`, which count the number of elements of a list satisfying a predicate and equal to a given element respectively. Their definitions can be found in [`data.list.defs`](./defs). -/ open nat variables {α β : Type*} {l l₁ l₂ : list α} namespace list section countp variables (p : α → Prop) [decidable_pred p] @[simp] lemma countp_nil : countp p [] = 0 := rfl @[simp] lemma countp_cons_of_pos {a : α} (l) (pa : p a) : countp p (a::l) = countp p l + 1 := if_pos pa @[simp] lemma countp_cons_of_neg {a : α} (l) (pa : ¬ p a) : countp p (a::l) = countp p l := if_neg pa lemma length_eq_countp_add_countp (l) : length l = countp p l + countp (λ a, ¬p a) l := by induction l with x h ih; [refl, by_cases p x]; [simp only [countp_cons_of_pos _ _ h, countp_cons_of_neg (λ a, ¬p a) _ (decidable.not_not.2 h), ih, length], simp only [countp_cons_of_pos (λ a, ¬p a) _ h, countp_cons_of_neg _ _ h, ih, length]]; ac_refl lemma countp_eq_length_filter (l) : countp p l = length (filter p l) := by induction l with x l ih; [refl, by_cases (p x)]; [simp only [filter_cons_of_pos _ h, countp, ih, if_pos h], simp only [countp_cons_of_neg _ _ h, ih, filter_cons_of_neg _ h]]; refl lemma countp_le_length : countp p l ≤ l.length := by simpa only [countp_eq_length_filter] using length_le_of_sublist (filter_sublist _) @[simp] lemma countp_append (l₁ l₂) : countp p (l₁ ++ l₂) = countp p l₁ + countp p l₂ := by simp only [countp_eq_length_filter, filter_append, length_append] lemma countp_pos {l} : 0 < countp p l ↔ ∃ a ∈ l, p a := by simp only [countp_eq_length_filter, length_pos_iff_exists_mem, mem_filter, exists_prop] lemma countp_eq_length {l} : countp p l = l.length ↔ ∀ a ∈ l, p a := by rw [countp_eq_length_filter, filter_length_eq_length] lemma length_filter_lt_length_iff_exists (l) : length (filter p l) < length l ↔ ∃ x ∈ l, ¬p x := by rw [length_eq_countp_add_countp p l, ← countp_pos, countp_eq_length_filter, lt_add_iff_pos_right] lemma sublist.countp_le (s : l₁ <+ l₂) : countp p l₁ ≤ countp p l₂ := by simpa only [countp_eq_length_filter] using length_le_of_sublist (s.filter p) @[simp] lemma countp_filter {q} [decidable_pred q] (l : list α) : countp p (filter q l) = countp (λ a, p a ∧ q a) l := by simp only [countp_eq_length_filter, filter_filter] @[simp] lemma countp_true : l.countp (λ _, true) = l.length := by simp [countp_eq_length_filter] @[simp] lemma countp_false : l.countp (λ _, false) = 0 := by simp [countp_eq_length_filter] end countp /-! ### count -/ section count variables [decidable_eq α] @[simp] lemma count_nil (a : α) : count a [] = 0 := rfl lemma count_cons (a b : α) (l : list α) : count a (b :: l) = if a = b then succ (count a l) else count a l := rfl lemma count_cons' (a b : α) (l : list α) : count a (b :: l) = count a l + (if a = b then 1 else 0) := begin rw count_cons, split_ifs; refl end @[simp] lemma count_cons_self (a : α) (l : list α) : count a (a::l) = succ (count a l) := if_pos rfl @[simp, priority 990] lemma count_cons_of_ne {a b : α} (h : a ≠ b) (l : list α) : count a (b::l) = count a l := if_neg h lemma count_tail : Π (l : list α) (a : α) (h : 0 < l.length), l.tail.count a = l.count a - ite (a = list.nth_le l 0 h) 1 0 | (_ :: _) a h := by { rw [count_cons], split_ifs; simp } lemma count_le_length (a : α) (l : list α) : count a l ≤ l.length := countp_le_length _ lemma sublist.count_le (h : l₁ <+ l₂) (a : α) : count a l₁ ≤ count a l₂ := h.countp_le _ lemma count_le_count_cons (a b : α) (l : list α) : count a l ≤ count a (b :: l) := (sublist_cons _ _).count_le _ lemma count_singleton (a : α) : count a [a] = 1 := if_pos rfl lemma count_singleton' (a b : α) : count a [b] = ite (a = b) 1 0 := rfl @[simp] lemma count_append (a : α) : ∀ l₁ l₂, count a (l₁ ++ l₂) = count a l₁ + count a l₂ := countp_append _ lemma count_concat (a : α) (l : list α) : count a (concat l a) = succ (count a l) := by simp [-add_comm] @[simp] lemma count_pos {a : α} {l : list α} : 0 < count a l ↔ a ∈ l := by simp only [count, countp_pos, exists_prop, exists_eq_right'] @[simp] lemma one_le_count_iff_mem {a : α} {l : list α} : 1 ≤ count a l ↔ a ∈ l := count_pos @[simp, priority 980] lemma count_eq_zero_of_not_mem {a : α} {l : list α} (h : a ∉ l) : count a l = 0 := decidable.by_contradiction $ λ h', h $ count_pos.1 (nat.pos_of_ne_zero h') lemma not_mem_of_count_eq_zero {a : α} {l : list α} (h : count a l = 0) : a ∉ l := λ h', (count_pos.2 h').ne' h lemma count_eq_length {a : α} {l} : count a l = l.length ↔ ∀ b ∈ l, a = b := by rw [count, countp_eq_length] @[simp] lemma count_repeat (a : α) (n : ℕ) : count a (repeat a n) = n := by rw [count, countp_eq_length_filter, filter_eq_self.2, length_repeat]; exact λ b m, (eq_of_mem_repeat m).symm lemma le_count_iff_repeat_sublist {a : α} {l : list α} {n : ℕ} : n ≤ count a l ↔ repeat a n <+ l := ⟨λ h, ((repeat_sublist_repeat a).2 h).trans $ have filter (eq a) l = repeat a (count a l), from eq_repeat.2 ⟨by simp only [count, countp_eq_length_filter], λ b m, (of_mem_filter m).symm⟩, by rw ← this; apply filter_sublist, λ h, by simpa only [count_repeat] using h.count_le a⟩ lemma repeat_count_eq_of_count_eq_length {a : α} {l : list α} (h : count a l = length l) : repeat a (count a l) = l := eq_of_sublist_of_length_eq (le_count_iff_repeat_sublist.mp (le_refl (count a l))) (eq.trans (length_repeat a (count a l)) h) @[simp] lemma count_filter {p} [decidable_pred p] {a} {l : list α} (h : p a) : count a (filter p l) = count a l := by simp only [count, countp_filter, show (λ b, a = b ∧ p b) = eq a, by { ext b, constructor; cc }] lemma count_bind {α β} [decidable_eq β] (l : list α) (f : α → list β) (x : β) : count x (l.bind f) = sum (map (count x ∘ f) l) := begin induction l with hd tl IH, { simp }, { simpa } end @[simp] lemma count_map_of_injective {α β} [decidable_eq α] [decidable_eq β] (l : list α) (f : α → β) (hf : function.injective f) (x : α) : count (f x) (map f l) = count x l := begin induction l with y l IH generalizing x, { simp }, { simp [map_cons, count_cons', IH, hf.eq_iff] } end lemma count_le_count_map [decidable_eq β] (l : list α) (f : α → β) (x : α) : count x l ≤ count (f x) (map f l) := begin induction l with a as IH, { simp }, rcases eq_or_ne x a with rfl | hxa, { simp [succ_le_succ IH] }, { simp [hxa, le_add_right IH, count_cons'] } end @[simp] lemma count_erase_self (a : α) : ∀ (s : list α), count a (list.erase s a) = pred (count a s) | [] := by simp | (h :: t) := begin rw erase_cons, by_cases p : h = a, { rw [if_pos p, count_cons', if_pos p.symm], simp }, { rw [if_neg p, count_cons', count_cons', if_neg (λ x : a = h, p x.symm), count_erase_self], simp } end @[simp] lemma count_erase_of_ne {a b : α} (ab : a ≠ b) : ∀ (s : list α), count a (list.erase s b) = count a s | [] := by simp | (x :: xs) := begin rw erase_cons, split_ifs with h, { rw [count_cons', h, if_neg ab], simp }, { rw [count_cons', count_cons', count_erase_of_ne] } end end count end list
e66305212d96a61a492525e854294210065a803f
9dc8cecdf3c4634764a18254e94d43da07142918
/src/topology/sets/closeds.lean
4ca4f1b2c2ff5e669ea188bae7fdbe41a28915ed
[ "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,039
lean
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Yaël Dillies -/ import topology.sets.opens /-! # Closed sets We define a few types of closed sets in a topological space. ## Main Definitions For a topological space `α`, * `closeds α`: The type of closed sets. * `clopens α`: The type of clopen sets. -/ open order order_dual set variables {ι α β : Type*} [topological_space α] [topological_space β] namespace topological_space /-! ### Closed sets -/ /-- The type of closed subsets of a topological space. -/ structure closeds (α : Type*) [topological_space α] := (carrier : set α) (closed' : is_closed carrier) namespace closeds variables {α} instance : set_like (closeds α) α := { coe := closeds.carrier, coe_injective' := λ s t h, by { cases s, cases t, congr' } } lemma closed (s : closeds α) : is_closed (s : set α) := s.closed' @[ext] protected lemma ext {s t : closeds α} (h : (s : set α) = t) : s = t := set_like.ext' h @[simp] lemma coe_mk (s : set α) (h) : (mk s h : set α) = s := rfl /-- The closure of a set, as an element of `closeds`. -/ protected def closure (s : set α) : closeds α := ⟨closure s, is_closed_closure⟩ lemma gc : galois_connection closeds.closure (coe : closeds α → set α) := λ s U, ⟨subset_closure.trans, λ h, closure_minimal h U.closed⟩ /-- The galois coinsertion between sets and opens. -/ def gi : galois_insertion (@closeds.closure α _) coe := { choice := λ s hs, ⟨s, closure_eq_iff_is_closed.1 $ hs.antisymm subset_closure⟩, gc := gc, le_l_u := λ _, subset_closure, choice_eq := λ s hs, set_like.coe_injective $ subset_closure.antisymm hs } instance : complete_lattice (closeds α) := complete_lattice.copy (galois_insertion.lift_complete_lattice gi) /- le -/ _ rfl /- top -/ ⟨univ, is_closed_univ⟩ rfl /- bot -/ ⟨∅, is_closed_empty⟩ (set_like.coe_injective closure_empty.symm) /- sup -/ (λ s t, ⟨s ∪ t, s.2.union t.2⟩) (funext $ λ s, funext $ λ t, set_like.coe_injective (s.2.union t.2).closure_eq.symm) /- inf -/ (λ s t, ⟨s ∩ t, s.2.inter t.2⟩) rfl /- Sup -/ _ rfl /- Inf -/ (λ S, ⟨⋂ s ∈ S, ↑s, is_closed_bInter $ λ s _, s.2⟩) (funext $ λ S, set_like.coe_injective Inf_image.symm) /-- The type of closed sets is inhabited, with default element the empty set. -/ instance : inhabited (closeds α) := ⟨⊥⟩ @[simp, norm_cast] lemma coe_sup (s t : closeds α) : (↑(s ⊔ t) : set α) = s ∪ t := rfl @[simp, norm_cast] lemma coe_inf (s t : closeds α) : (↑(s ⊓ t) : set α) = s ∩ t := rfl @[simp, norm_cast] lemma coe_top : (↑(⊤ : closeds α) : set α) = univ := rfl @[simp, norm_cast] lemma coe_bot : (↑(⊥ : closeds α) : set α) = ∅ := rfl @[simp, norm_cast] lemma coe_Inf {S : set (closeds α)} : (↑(Inf S) : set α) = ⋂ i ∈ S, ↑i := rfl @[simp, norm_cast] lemma coe_finset_sup (f : ι → closeds α) (s : finset ι) : (↑(s.sup f) : set α) = s.sup (coe ∘ f) := map_finset_sup (⟨⟨coe, coe_sup⟩, coe_bot⟩ : sup_bot_hom (closeds α) (set α)) _ _ @[simp, norm_cast] lemma coe_finset_inf (f : ι → closeds α) (s : finset ι) : (↑(s.inf f) : set α) = s.inf (coe ∘ f) := map_finset_inf (⟨⟨coe, coe_inf⟩, coe_top⟩ : inf_top_hom (closeds α) (set α)) _ _ lemma infi_def {ι} (s : ι → closeds α) : (⨅ i, s i) = ⟨⋂ i, s i, is_closed_Inter $ λ i, (s i).2⟩ := by { ext, simp only [infi, coe_Inf, bInter_range], refl } @[simp] lemma infi_mk {ι} (s : ι → set α) (h : ∀ i, is_closed (s i)) : (⨅ i, ⟨s i, h i⟩ : closeds α) = ⟨⋂ i, s i, is_closed_Inter h⟩ := by simp [infi_def] @[simp, norm_cast] lemma coe_infi {ι} (s : ι → closeds α) : ((⨅ i, s i : closeds α) : set α) = ⋂ i, s i := by simp [infi_def] @[simp] lemma mem_infi {ι} {x : α} {s : ι → closeds α} : x ∈ infi s ↔ ∀ i, x ∈ s i := by simp [←set_like.mem_coe] @[simp] lemma mem_Inf {S : set (closeds α)} {x : α} : x ∈ Inf S ↔ ∀ s ∈ S, x ∈ s := by simp_rw [Inf_eq_infi, mem_infi] instance : coframe (closeds α) := { Inf := Inf, infi_sup_le_sup_Inf := λ a s, (set_like.coe_injective $ by simp only [coe_sup, coe_infi, coe_Inf, set.union_Inter₂]).le, ..closeds.complete_lattice } end closeds /-- The complement of a closed set as an open set. -/ @[simps] def closeds.compl (s : closeds α) : opens α := ⟨sᶜ, s.2.is_open_compl⟩ /-- The complement of an open set as a closed set. -/ @[simps] def opens.compl (s : opens α) : closeds α := ⟨sᶜ, s.2.is_closed_compl⟩ lemma closeds.compl_compl (s : closeds α) : s.compl.compl = s := closeds.ext (compl_compl s) lemma opens.compl_compl (s : opens α) : s.compl.compl = s := opens.ext (compl_compl s) lemma closeds.compl_bijective : function.bijective (@closeds.compl α _) := function.bijective_iff_has_inverse.mpr ⟨opens.compl, closeds.compl_compl, opens.compl_compl⟩ lemma opens.compl_bijective : function.bijective (@opens.compl α _) := function.bijective_iff_has_inverse.mpr ⟨closeds.compl, opens.compl_compl, closeds.compl_compl⟩ /-! ### Clopen sets -/ /-- The type of clopen sets of a topological space. -/ structure clopens (α : Type*) [topological_space α] := (carrier : set α) (clopen' : is_clopen carrier) namespace clopens instance : set_like (clopens α) α := { coe := λ s, s.carrier, coe_injective' := λ s t h, by { cases s, cases t, congr' } } lemma clopen (s : clopens α) : is_clopen (s : set α) := s.clopen' /-- Reinterpret a compact open as an open. -/ @[simps] def to_opens (s : clopens α) : opens α := ⟨s, s.clopen.is_open⟩ @[ext] protected lemma ext {s t : clopens α} (h : (s : set α) = t) : s = t := set_like.ext' h @[simp] lemma coe_mk (s : set α) (h) : (mk s h : set α) = s := rfl instance : has_sup (clopens α) := ⟨λ s t, ⟨s ∪ t, s.clopen.union t.clopen⟩⟩ instance : has_inf (clopens α) := ⟨λ s t, ⟨s ∩ t, s.clopen.inter t.clopen⟩⟩ instance : has_top (clopens α) := ⟨⟨⊤, is_clopen_univ⟩⟩ instance : has_bot (clopens α) := ⟨⟨⊥, is_clopen_empty⟩⟩ instance : has_sdiff (clopens α) := ⟨λ s t, ⟨s \ t, s.clopen.diff t.clopen⟩⟩ instance : has_compl (clopens α) := ⟨λ s, ⟨sᶜ, s.clopen.compl⟩⟩ instance : boolean_algebra (clopens α) := set_like.coe_injective.boolean_algebra _ (λ _ _, rfl) (λ _ _, rfl) rfl rfl (λ _, rfl) (λ _ _, rfl) @[simp] lemma coe_sup (s t : clopens α) : (↑(s ⊔ t) : set α) = s ∪ t := rfl @[simp] lemma coe_inf (s t : clopens α) : (↑(s ⊓ t) : set α) = s ∩ t := rfl @[simp] lemma coe_top : (↑(⊤ : clopens α) : set α) = univ := rfl @[simp] lemma coe_bot : (↑(⊥ : clopens α) : set α) = ∅ := rfl @[simp] lemma coe_sdiff (s t : clopens α) : (↑(s \ t) : set α) = s \ t := rfl @[simp] lemma coe_compl (s : clopens α) : (↑sᶜ : set α) = sᶜ := rfl instance : inhabited (clopens α) := ⟨⊥⟩ end clopens end topological_space
88e332f64588c0589b2318fc601e7114ce923064
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/tactic/hint.lean
691ae5fdc3b9b234b567f098ac606d58bc64f447
[]
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
998
lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.tactic.solve_by_elim import Mathlib.tactic.interactive import Mathlib.PostPort namespace Mathlib namespace tactic namespace hint /-- An attribute marking a `tactic unit` or `tactic string` which should be used by the `hint` tactic. -/ /-- `add_hint_tactic t` runs the tactic `t` whenever `hint` is invoked. The typical use case is `add_hint_tactic "foo"` for some interactive tactic `foo`. -/ end hint /-- Report a list of tactics that can make progress against the current goal, and for each such tactic, the number of remaining goals afterwards. -/ namespace interactive /-- Report a list of tactics that can make progress against the current goal. -/ /-- `hint` lists possible tactics which will make progress (that is, not fail) against the current goal.
49ea5366dc42612c6b0c142a68655fb9b4e34d98
b7f22e51856f4989b970961f794f1c435f9b8f78
/tests/lean/calc_assistant.lean
d3cd41b4d52275bb521f4a69113e729a65edba5b
[ "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
800
lean
import logic open eq.ops set_option elaborator.calc_assistant false theorem tst1 (a b c : num) (H₁ : ∀ x, b = x) (H₂ : c = b) : a = c := calc a = b : H₁ -- error because calc assistant is off ... = c : H₂ theorem tst2 (a b c : num) (H₁ : ∀ x, b = x) (H₂ : c = b) : a = c := calc a = b : !H₁⁻¹ ... = c : H₂ -- error because calc assistant is off theorem tst3 (a b c : num) (H₁ : ∀ x, b = x) (H₂ : c = b) : a = c := calc a = b : !H₁⁻¹ ... = c : H₂⁻¹ theorem tst4 (a b c : num) (H₁ : ∀ x, b = x) (H₂ : c = b) : a = c := calc a = b : eq.symm (H₁ a) ... = c : eq.symm H₂ set_option elaborator.calc_assistant true theorem tst5 (a b c : num) (H₁ : ∀ x, b = x) (H₂ : c = b) : a = c := calc a = b : H₁ ... = c : H₂
3de50ec4c2ae80cfc3f6b506a5b0d179d78e4e6e
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/number_theory/class_number/admissible_abs.lean
b93949539f36993a17d8e56de520c5ad49d2a014
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
2,677
lean
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import algebra.algebra.basic import number_theory.class_number.admissible_absolute_value /-! # Admissible absolute value on the integers > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file defines an admissible absolute value `absolute_value.abs_is_admissible` which we use to show the class number of the ring of integers of a number field is finite. ## Main results * `absolute_value.abs_is_admissible` shows the "standard" absolute value on `ℤ`, mapping negative `x` to `-x`, is admissible. -/ namespace absolute_value open int /-- We can partition a finite family into `partition_card ε` sets, such that the remainders in each set are close together. -/ lemma exists_partition_int (n : ℕ) {ε : ℝ} (hε : 0 < ε) {b : ℤ} (hb : b ≠ 0) (A : fin n → ℤ) : ∃ (t : fin n → fin ⌈1 / ε⌉₊), ∀ i₀ i₁, t i₀ = t i₁ → ↑(abs (A i₁ % b - A i₀ % b)) < abs b • ε := begin have hb' : (0 : ℝ) < ↑(abs b) := int.cast_pos.mpr (abs_pos.mpr hb), have hbε : 0 < abs b • ε, { rw algebra.smul_def, exact mul_pos hb' hε }, have hfloor : ∀ i, 0 ≤ floor ((A i % b : ℤ) / (abs b • ε) : ℝ), { intro i, exact floor_nonneg.mpr (div_nonneg (cast_nonneg.mpr (mod_nonneg _ hb)) hbε.le) }, refine ⟨λ i, ⟨nat_abs (floor ((A i % b : ℤ) / (abs b • ε) : ℝ)), _⟩, _⟩, { rw [← coe_nat_lt, nat_abs_of_nonneg (hfloor i), floor_lt], apply lt_of_lt_of_le _ (nat.le_ceil _), rw [algebra.smul_def, eq_int_cast, ← div_div, div_lt_div_right hε, div_lt_iff hb', one_mul, cast_lt], exact int.mod_lt _ hb }, intros i₀ i₁ hi, have hi : (⌊↑(A i₀ % b) / abs b • ε⌋.nat_abs : ℤ) = ⌊↑(A i₁ % b) / abs b • ε⌋.nat_abs := congr_arg (coe : ℕ → ℤ) (fin.mk_eq_mk.mp hi), rw [nat_abs_of_nonneg (hfloor i₀), nat_abs_of_nonneg (hfloor i₁)] at hi, have hi := abs_sub_lt_one_of_floor_eq_floor hi, rw [abs_sub_comm, ← sub_div, abs_div, abs_of_nonneg hbε.le, div_lt_iff hbε, one_mul] at hi, rwa [int.cast_abs, int.cast_sub] end /-- `abs : ℤ → ℤ` is an admissible absolute value -/ noncomputable def abs_is_admissible : is_admissible absolute_value.abs := { card := λ ε, ⌈1 / ε⌉₊, exists_partition' := λ n ε hε b hb, exists_partition_int n hε hb, .. absolute_value.abs_is_euclidean } noncomputable instance : inhabited (is_admissible absolute_value.abs) := ⟨abs_is_admissible⟩ end absolute_value
161fd7091d38df505d622a4086d3914e65780205
fe84e287c662151bb313504482b218a503b972f3
/src/poset/subdiv.lean
73bb752a3cce1f1b7dca688a9c362b87d66d8e44
[]
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,561
lean
/- Copyright (c) 2019 Neil Strickland. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Neil Strickland Given a poset `P`, we define `subdiv P` to be the poset of finite nonempty chains `s ⊆ P`. Any such `s` has a largest element, and the map `max : (subdiv P) → P` is a morphism of posets. There is an approach to the homotopy theory of finite complexes based on finite posets, and the above map `max` plays a key role in this. -/ import data.list.sort data.fintype.basic import poset.basic order.sort_rank universes uP uQ uR uS variables (P : Type uP) [partial_order P] [decidable_eq P] variables (Q : Type uQ) [partial_order Q] [decidable_eq Q] variables (R : Type uR) [partial_order R] [decidable_eq R] variables (S : Type uS) [partial_order S] [decidable_eq S] variable [decidable_rel (has_le.le : P → P → Prop)] variable [decidable_rel (has_le.le : Q → Q → Prop)] variable [decidable_rel (has_le.le : R → R → Prop)] variable [decidable_rel (has_le.le : S → S → Prop)] namespace poset open poset variables {P} [fintype P] /-- Definition of chains LaTeX: defn-subdiv -/ def is_chain (s : finset P) : Prop := ∀ (p ∈ s) (q ∈ s), (p ≤ q ∨ q ≤ p) instance decidable_is_chain (s : finset P) : decidable (is_chain s) := by { unfold is_chain, apply_instance } /-- Definition of simplices as nonempty chains LaTeX: defn-subdiv -/ def is_simplex (s : finset P) : Prop := s.nonempty ∧ (is_chain s) instance decidable_is_simplex (s : finset P) : decidable (is_simplex s) := by { unfold is_simplex, unfold finset.nonempty, apply_instance } variable (P) /-- Definition of subdiv P as a type LaTeX: defn-subdiv -/ def subdiv := {s : finset P // is_simplex s} instance : has_coe (subdiv P) (finset P) := ⟨subtype.val⟩ /-- Vertices as 0-simplices -/ variable {P} def vertex (p : P) : subdiv P := ⟨ {p}, begin split, {exact ⟨p,finset.mem_singleton_self p⟩}, {intros x hx y hy, rw [finset.mem_singleton.mp hx, finset.mem_singleton.mp hy], left, exact le_refl p } end⟩ variable (P) namespace subdiv instance : decidable_eq (subdiv P) := by { unfold subdiv, apply_instance } /-- Definition of the partial order on subdiv P LaTeX: defn-subdiv -/ instance : partial_order (subdiv P) := { le := λ s t, s.val ⊆ t.val, le_refl := λ s, (le_refl s.val), le_antisymm := λ s t hst hts, subtype.eq (le_antisymm hst hts), le_trans := λ s t u (hst : s.val ⊆ t.val) (htu : t.val ⊆ u.val) p hs, (htu (hst hs)) } instance decidable_le : decidable_rel (has_le.le : (subdiv P) → (subdiv P) → Prop) := λ s t, by { apply_instance } variable {P} /-- Definition of the dimension of a simplex, as one less than the cardinality. We use the predecessor operation on natural numbers, which sends zero to zero. Because of this, we need a small argument to show that the cardinality is strictly positive and thus equal to one more than the dimension. LaTeX: defn-subdiv -/ def dim (s : subdiv P) : ℕ := (s : finset P).card.pred lemma card_eq (s : subdiv P) : (s : finset P).card = s.dim.succ := begin by_cases h : s.val.card = 0, { exfalso, have h₀ := s.property.left, rw[finset.card_eq_zero.mp h] at h₀, exact finset.not_nonempty_empty h₀}, { replace h := nat.pos_of_ne_zero h, exact (nat.succ_pred_eq_of_pos h).symm } end /-- The dimension function dim : subdiv P → ℕ is monotone. -/ lemma dim_mono : monotone (dim : (subdiv P) → ℕ) := begin intros s t hst, let h : (s : finset P).card ≤ (t : finset P).card := finset.card_le_of_subset hst, rw[card_eq,card_eq] at h, exact nat.le_of_succ_le_succ h end /-- If we have simplices s ≤ t with dim s ≥ dim t then s = t. -/ lemma eq_of_le_of_dim_ge (s t : subdiv P) (hst : s ≤ t) (hd : s.dim ≥ t.dim) : s = t := begin let hc := nat.succ_le_succ hd, rw [← card_eq, ← card_eq] at hc, exact subtype.eq (finset.eq_of_subset_of_card_le hst hc) end /-- This allows us to treat a simplex as a type in its own right. -/ instance : has_coe_to_sort (subdiv P) (Type uP) := ⟨λ s, {p : P // p ∈ s.val}⟩ section els variable (s : subdiv P) instance els_decidable_eq : decidable_eq s := by { apply_instance } instance els_fintype : fintype s := by { apply_instance } lemma card_eq' : fintype.card s = s.dim.succ := begin rw[← s.card_eq], rw[← fintype.card_coe],congr end /-- If s is a simplex, we can treat it as a linearly ordered set. -/ instance els_order : linear_order s := { le := λ p q,p.val ≤ q.val, le_refl := λ p, ((le_refl (p.val : P)) : p.val ≤ p.val), le_antisymm := λ p q (hpq : p.val ≤ q.val) (hqp : q.val ≤ p.val), subtype.eq (le_antisymm hpq hqp), le_trans := λ p q r (hpq : p.val ≤ q.val) (hqr : q.val ≤ r.val), le_trans hpq hqr, le_total := λ p q,s.property.right p.val p.property q.val q.property, lt := λ p q,p.val < q.val, lt_iff_le_not_le := λ p q, begin change p.val < q.val ↔ p.val ≤ q.val ∧ ¬ q.val ≤ p.val, apply lt_iff_le_not_le, end, decidable_le := λ p q, by { apply_instance } } variable {s} /-- The inclusion of a simplex in the full poset P. -/ def inc : s → P := λ p, p.val /-- The inclusion map is injective. -/ lemma inc_inj (p₀ p₁ : s) : (inc p₀) = (inc p₁) → p₀ = p₁ := subtype.eq /-- The inclusion map is monotone. -/ lemma inc_mono : monotone (inc : s → P) := λ p₀ p₁ hp, hp variable (s) variables {d : ℕ} (e : s.dim = d) /-- If dim s = d, then we have a canonical bijection from s to the set fin d.succ = { 0,1,...,d }. We define rank_equiv s to be a package consisting of this bijection and its inverse. We define seq s and rank s to be auxiliary functions defined in terms of rank_equiv s, and we prove some lemmas about the behaviour of these. -/ def rank_equiv : s ≃ fin d.succ := fintype.rank_equiv (s.card_eq'.trans (congr_arg nat.succ e)) def seq : (fin d.succ) → P := λ i, inc ((rank_equiv s e).inv_fun i) def rank (p : P) (hp : p ∈ s.val) : fin d.succ := (rank_equiv s e).to_fun ⟨p,hp⟩ lemma seq_mem (i : fin d.succ) : seq s e i ∈ s.val := ((rank_equiv s e).inv_fun i).property lemma seq_rank (p : P) (hp : p ∈ s.val) : seq s e (rank s e p hp) = p := congr_arg inc ((rank_equiv s e).left_inv ⟨p,hp⟩) lemma seq_eq (i : fin d.succ) : ((rank_equiv s e).symm i) = ⟨seq s e i,seq_mem s e i⟩ := by { apply subtype.eq, refl } lemma rank_seq (i : fin d.succ) : rank s e (seq s e i) (seq_mem s e i) = i := begin dsimp [rank], rw [← (seq_eq s e i)], exact (rank_equiv s e).right_inv i, end lemma seq_le (i₀ i₁ : fin d.succ) : i₀ ≤ i₁ ↔ seq s e i₀ ≤ seq s e i₁ := fintype.seq_le (s.card_eq'.trans (congr_arg nat.succ e)) i₀ i₁ lemma seq_lt (i₀ i₁ : fin d.succ) : i₀ < i₁ ↔ seq s e i₀ < seq s e i₁ := fintype.seq_lt (s.card_eq'.trans (congr_arg nat.succ e)) i₀ i₁ variables {P Q} [fintype Q] def map (f : poset.hom P Q) : (poset.hom (subdiv P) (subdiv Q)) := begin let sf : subdiv P → subdiv Q := λ s, begin let t0 : finset Q := s.val.image f.val, have : is_simplex t0 := begin split, { rcases s.property.1 with ⟨p,p_in_s⟩, exact ⟨_,(finset.mem_image_of_mem f.val p_in_s)⟩ }, { intros q₀ hq₀ q₁ hq₁, rcases finset.mem_image.mp hq₀ with ⟨p₀,hp₀,hfp₀⟩, rcases finset.mem_image.mp hq₁ with ⟨p₁,hp₁,hfp₁⟩, rw [← hfp₀, ← hfp₁], rcases s.property.2 p₀ hp₀ p₁ hp₁ with h₀₁ | h₁₀, { left, exact f.property h₀₁ }, { right, exact f.property h₁₀ } } end, exact ⟨t0,this⟩ end, have : monotone sf := λ s₀ s₁ hs, begin change s₀.val.image f.val ⊆ s₁.val.image f.val, intros q hq, rcases finset.mem_image.mp hq with ⟨p,hp,hfp⟩, exact finset.mem_image.mpr ⟨p,hs hp,hfp⟩ end, exact ⟨sf, this⟩ end lemma map_val (f : poset.hom P Q) (s : subdiv P) : ((subdiv.map f).val s).val = s.val.image f.val := rfl section interleave variables [fintype P] {f g : poset.hom P Q} (hfg : f ≤ g) include hfg def interleave : ∀ (r : fin_ranking P) (m : ℕ), hom (subdiv P) (subdiv Q) | ⟨n,r,r_mono⟩ m := ⟨ λ (σ : subdiv P), ⟨ ((σ.val.filter (λ p, 2 * (r p).val < m)).image f) ∪ ((σ.val.filter (λ p, 2 * (r p).val + 1 ≥ m)).image g), begin split, { rcases σ.property.1 with ⟨p, p_in_σ⟩, by_cases h : 2 * (r p).val < m, { use f p, apply finset.mem_union_left, apply finset.mem_image_of_mem, rw [finset.mem_filter], exact ⟨p_in_σ, h⟩ }, { replace h := le_trans (le_of_not_gt h) (nat.le_succ _), use (g p), apply finset.mem_union_right, apply finset.mem_image_of_mem, rw [finset.mem_filter], exact ⟨p_in_σ, h⟩ } }, { intros q₀ h₀ q₁ h₁, rcases finset.mem_union.mp h₀ with h₀ | h₀; rcases finset.mem_union.mp h₁ with h₁ | h₁; rcases finset.mem_image.mp h₀ with ⟨p₀,hf₀,he₀⟩; rcases finset.mem_image.mp h₁ with ⟨p₁,hf₁,he₁⟩; rw [finset.mem_filter] at hf₀ hf₁; rw [← he₀, ← he₁]; let r₀ := (r p₀).val ; let r₁ := (r p₁).val ; rcases σ.property.right p₀ hf₀.1 p₁ hf₁.1 with hpp | hpp; let hfpp := f.property hpp; let hgpp := g.property hpp, { left , exact hfpp }, { right, exact hfpp }, { left , exact le_trans hfpp (hfg p₁) }, { by_cases hrr : r₀ = r₁, { rw [r.injective (fin.eq_of_veq hrr)], left, exact hfg p₁ }, { exfalso, change r₀ ≠ r₁ at hrr, replace hrr : r₁ < r₀ := lt_of_le_of_ne (r_mono hpp) hrr.symm, change r₁ + 1 ≤ r₀ at hrr, have := calc 2 * r₁ + 2 = 2 * (r₁ + 1) : by rw [mul_add, mul_one] ... ≤ 2 * r₀ : nat.mul_le_mul_left 2 hrr ... < m : hf₀.2 ... ≤ 2 * r₁ + 1 : hf₁.2 ... < 2 * r₁ + 2 : nat.lt_succ_self _, exact lt_irrefl _ this } }, { by_cases hrr : r₀ = r₁, { rw [r.injective (fin.eq_of_veq hrr)], right, exact hfg p₁ }, { exfalso, change r₀ ≠ r₁ at hrr, replace hrr : r₀ < r₁ := lt_of_le_of_ne (r_mono hpp) hrr, change r₀ + 1 ≤ r₁ at hrr, have := calc 2 * r₁ < m : hf₁.2 ... ≤ 2 * r₀ + 1 : hf₀.2 ... < 2 * r₀ + 2 : nat.lt_succ_self _ ... = 2 * (r₀ + 1) : by rw [mul_add, mul_one] ... ≤ 2 * r₁ : nat.mul_le_mul_left 2 hrr, exact lt_irrefl _ this } }, { right, exact le_trans hfpp (hfg p₀) }, { left , exact hgpp }, { right, exact hgpp } } end ⟩, begin intros σ₀ σ₁ h_le q hq, rw [finset.mem_union] at hq ⊢, rcases hq with hq | hq; rcases finset.mem_image.mp hq with ⟨p,hm,he⟩; rw [← he]; rw [finset.mem_filter] at hm; replace hm := and.intro (h_le hm.1) hm.2, { left , apply finset.mem_image_of_mem, rw [finset.mem_filter], exact hm }, { right, apply finset.mem_image_of_mem, rw [finset.mem_filter], exact hm } end ⟩ lemma interleave_start : ∀ (r : fin_ranking P), interleave hfg r 0 = subdiv.map g | ⟨n,r,r_mono⟩ := begin ext1 σ, apply subtype.eq, change _ ∪ _ = σ.val.image g.val, ext q, have : σ.val.filter (λ (p : P), 2 * (r p).val < 0) = ∅ := begin ext p, rw [finset.mem_filter], simp [nat.not_lt_zero, finset.not_mem_empty] end, rw [this, finset.image_empty], have : σ.val.filter (λ (p : P), 2 * (r p).val + 1 ≥ 0) = σ.val := begin ext p, rw [finset.mem_filter], have : _ ≥ 0 := nat.zero_le (2 * (r p).val + 1), simp only [this, and_true] end, rw [this, finset.mem_union], have : (g : P → Q) = g.val := rfl, rw [this], simp [finset.not_mem_empty], end lemma interleave_end : ∀ (r : fin_ranking P) (m : ℕ) (hm : m ≥ 2 * r.card), interleave hfg r m = subdiv.map f | ⟨n,r,r_mono⟩ m hm := begin change m ≥ 2 * n at hm, ext1 σ, apply subtype.eq, change _ ∪ _ = σ.val.image f.val, ext q, have : σ.val.filter (λ (p : P), 2 * (r p).val < m) = σ.val := begin ext p, rw [finset.mem_filter], have := calc 2 * (r p).val < 2 * n : nat.mul_lt_mul_of_pos_left (r p).is_lt (dec_trivial : 2 > 0) ... ≤ m : hm, simp only [this,and_true], end, rw [this], have : σ.val.filter (λ (p : P), 2 * (r p).val + 1 ≥ m) = ∅ := begin ext p, rw [finset.mem_filter], have := calc 2 * (r p).val + 1 < 2 * (r p).val + 2 : nat.lt_succ_self _ ... = 2 * ((r p).val + 1) : by rw [mul_add, mul_one] ... ≤ 2 * n : nat.mul_le_mul_left 2 (r p).is_lt ... ≤ m : hm, have : ¬ (_ ≥ m) := not_le_of_gt this, simp only [this, finset.not_mem_empty, and_false] end, rw [this, finset.image_empty, finset.union_empty], have : (f : P → Q) = f.val := rfl, rw [this] end lemma interleave_even_step : ∀ (r : fin_ranking P) (k : ℕ), interleave hfg r (2 * k) ≤ interleave hfg r (2 * k + 1) | ⟨n,r,r_mono⟩ k := begin intros σ q h, change q ∈ _ ∪ _ at h, change q ∈ _ ∪ _, rw [finset.mem_union] at h ⊢, rcases h with h | h; rcases finset.mem_image.mp h with ⟨p,hf,he⟩; rw [finset.mem_filter] at hf; rw [← he], { left, apply finset.mem_image_of_mem, rw [finset.mem_filter], exact ⟨hf.1, lt_trans hf.2 (nat.lt_succ_self _)⟩ }, { right, apply finset.mem_image_of_mem, rw [finset.mem_filter], rcases le_or_gt k (r p).val with hk | hk, { exact ⟨hf.1, nat.succ_le_succ (nat.mul_le_mul_left 2 hk)⟩ }, { exfalso, have := calc 2 * (r p).val + 2 = 2 * ((r p).val + 1) : by rw [mul_add, mul_one] ... ≤ 2 * k : nat.mul_le_mul_left 2 hk ... ≤ 2 * (r p).val + 1 : hf.2 ... < 2 * (r p).val + 2 : nat.lt_succ_self _, exact lt_irrefl _ this } } end lemma interleave_odd_step : ∀ (r : fin_ranking P) (k : ℕ), interleave hfg r (2 * k + 2) ≤ interleave hfg r (2 * k + 1) | ⟨n,r,r_mono⟩ k := begin intros σ q h, change q ∈ _ ∪ _ at h, change q ∈ _ ∪ _, rw [finset.mem_union] at h ⊢, rcases h with h | h; rcases finset.mem_image.mp h with ⟨p,hf,he⟩; rw [finset.mem_filter] at hf; rw [← he], { left, apply finset.mem_image_of_mem, rw [finset.mem_filter], rcases le_or_gt (r p).val k with hk | hk, { have := calc 2 * (r p).val ≤ 2 * k : nat.mul_le_mul_left 2 hk ... < 2 * k + 1 : nat.lt_succ_self _, exact ⟨hf.1, this⟩ }, { exfalso, have := calc 2 * k + 2 = 2 * (k + 1) : by rw [mul_add, mul_one] ... ≤ 2 * (r p).val : nat.mul_le_mul_left 2 hk ... < 2 * k + 2 : hf.2, exact lt_irrefl _ this } }, { right, apply finset.mem_image_of_mem, rw [finset.mem_filter], exact ⟨hf.1, le_trans (le_of_lt (nat.lt_succ_self (2 * k + 1))) hf.2⟩ } end lemma interleave_component (r : fin_ranking P) (m : ℕ) : component (interleave hfg r m) = component (interleave hfg r 0) := zigzag (interleave hfg r) (interleave_even_step hfg r) (interleave_odd_step hfg r) m end interleave def subdiv.mapₕ [fintype P] : π₀ (hom P Q) → π₀ (hom (subdiv P) (subdiv Q)) := π₀.lift (λ f, component (subdiv.map f)) begin intros f g hfg, rcases exists_fin_ranking P with ⟨r⟩, let n := r.card, let c := interleave hfg r, have : c 0 = subdiv.map g := interleave_start hfg r, rw [← this], have : c (2 * n) = subdiv.map f := interleave_end hfg r (2 * n) (le_refl _), rw [← this], apply interleave_component end /-- For a simplex s, we define max s to be the largest element. -/ def max₀ : P := seq s rfl (fin.last s.dim) lemma max₀_mem : s.max₀ ∈ s.val := seq_mem s rfl (fin.last s.dim) lemma le_max₀ (p : P) (hp : p ∈ s.val) : p ≤ s.max₀ := begin rw [← seq_rank s rfl p hp], apply (seq_le s rfl (rank s rfl p hp) (fin.last s.dim)).mp, apply fin.le_last end end els /-- The function max : subdiv P → P is monotone. -/ lemma max₀_mono : monotone (max₀ : subdiv P → P) := λ s t hst, t.le_max₀ s.max₀ (hst s.max₀_mem) variable (P) def max : hom (subdiv P) P := ⟨max₀,max₀_mono⟩ lemma max_mem (s : subdiv P) : max P s ∈ s.val := max₀_mem s lemma le_max (s : subdiv P) (p : P) (hp : p ∈ s.val) : p ≤ max P s := le_max₀ s p hp lemma max_vertex (p : P) : max P (vertex p) = p := finset.mem_singleton.mp (max₀_mem (vertex p)) lemma max_cofinal : cofinalₕ (max P) := begin intro p, let C := comma (max P) p, let c : C := ⟨vertex p,by {rw[max_vertex]}⟩, let T := punit.{uP + 1}, let f : hom C T := const C punit.star, let g : hom T C := const T c, have hfg : comp f g = id T := by { ext t, rcases t, refl }, let m₀ : C → C := λ x, begin let τ₀ := x.val.val ∪ {p}, have h₀ : τ₀.nonempty := ⟨_,(finset.mem_union_right _ (finset.mem_singleton_self p))⟩, have h₁ : is_chain τ₀ := λ a ha b hb, begin rcases finset.mem_union.mp ha with hax | hap; rcases finset.mem_union.mp hb with hbx | hbp, { exact x.val.property.2 a hax b hbx }, { left, rw [finset.mem_singleton.mp hbp], exact le_trans (le_max P x.val a hax) x.property }, { right, rw [finset.mem_singleton.mp hap], exact le_trans (le_max P x.val b hbx) x.property }, { left, rw [finset.mem_singleton.mp hbp], rw [finset.mem_singleton.mp hap] } end, let τ : subdiv P := ⟨τ₀,⟨h₀,h₁⟩⟩, have h₂ : max P τ ≤ p := begin rcases finset.mem_union.mp (max_mem P τ) with h | h, { exact le_trans (le_max P x.val _ h) x.property }, { rw [finset.mem_singleton.mp h] } end, exact ⟨τ,h₂⟩ end, have m₀_mono : monotone m₀ := λ x₀ x₁ h, begin change x₀.val.val ⊆ x₁.val.val at h, change x₀.val.val ∪ {p} ⊆ x₁.val.val ∪ {p}, intros a ha, rcases finset.mem_union.mp ha with hax | hap, { exact finset.mem_union_left _ (h hax) }, { exact finset.mem_union_right _ hap } end, let m : hom C C := ⟨m₀,m₀_mono⟩, have hm₀ : comp g f ≤ m := λ x a ha, begin change a ∈ {p} at ha, change a ∈ x.val.val ∪ {p}, exact finset.mem_union_right _ ha end, have hm₁ : id C ≤ m := λ x a ha, begin change a ∈ x.val.val at ha, change a ∈ x.val.val ∪ {p}, exact finset.mem_union_left _ ha end, let hgf := (π₀.sound hm₀).trans (π₀.sound hm₁).symm, have e : equivₕ C T := { to_fun := component f, inv_fun := component g, left_inv := hgf, right_inv := congr_arg component hfg }, exact ⟨e⟩ end end subdiv end poset
d6669ff340f03906c9b9b604f1a19cdcb276354c
4727251e0cd73359b15b664c3170e5d754078599
/src/dynamics/fixed_points/basic.lean
27623adab88023f091d1f8968be7d1f732e1bd63
[ "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
5,655
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 data.set.function import logic.function.iterate /-! # Fixed points of a self-map In this file we define * the predicate `is_fixed_pt f x := f x = x`; * the set `fixed_points f` of fixed points of a self-map `f`. We also prove some simple lemmas about `is_fixed_pt` and `∘`, `iterate`, and `semiconj`. ## Tags fixed point -/ universes u v variables {α : Type u} {β : Type v} {f fa g : α → α} {x y : α} {fb : β → β} {m n k : ℕ} namespace function /-- A point `x` is a fixed point of `f : α → α` if `f x = x`. -/ def is_fixed_pt (f : α → α) (x : α) := f x = x /-- Every point is a fixed point of `id`. -/ lemma is_fixed_pt_id (x : α) : is_fixed_pt id x := (rfl : _) namespace is_fixed_pt instance [h : decidable_eq α] {f : α → α} {x : α} : decidable (is_fixed_pt f x) := h (f x) x /-- If `x` is a fixed point of `f`, then `f x = x`. This is useful, e.g., for `rw` or `simp`.-/ protected lemma eq (hf : is_fixed_pt f x) : f x = x := hf /-- If `x` is a fixed point of `f` and `g`, then it is a fixed point of `f ∘ g`. -/ protected lemma comp (hf : is_fixed_pt f x) (hg : is_fixed_pt g x) : is_fixed_pt (f ∘ g) x := calc f (g x) = f x : congr_arg f hg ... = x : hf /-- If `x` is a fixed point of `f`, then it is a fixed point of `f^[n]`. -/ protected lemma iterate (hf : is_fixed_pt f x) (n : ℕ) : is_fixed_pt (f^[n]) x := iterate_fixed hf n /-- If `x` is a fixed point of `f ∘ g` and `g`, then it is a fixed point of `f`. -/ lemma left_of_comp (hfg : is_fixed_pt (f ∘ g) x) (hg : is_fixed_pt g x) : is_fixed_pt f x := calc f x = f (g x) : congr_arg f hg.symm ... = x : hfg /-- If `x` is a fixed point of `f` and `g` is a left inverse of `f`, then `x` is a fixed point of `g`. -/ lemma to_left_inverse (hf : is_fixed_pt f x) (h : left_inverse g f) : is_fixed_pt g x := calc g x = g (f x) : congr_arg g hf.symm ... = x : h x /-- If `g` (semi)conjugates `fa` to `fb`, then it sends fixed points of `fa` to fixed points of `fb`. -/ protected lemma map {x : α} (hx : is_fixed_pt fa x) {g : α → β} (h : semiconj g fa fb) : is_fixed_pt fb (g x) := calc fb (g x) = g (fa x) : (h.eq x).symm ... = g x : congr_arg g hx protected lemma apply {x : α} (hx : is_fixed_pt f x) : is_fixed_pt f (f x) := by convert hx end is_fixed_pt @[simp] lemma injective.is_fixed_pt_apply_iff (hf : injective f) {x : α} : is_fixed_pt f (f x) ↔ is_fixed_pt f x := ⟨λ h, hf h.eq, is_fixed_pt.apply⟩ /-- The set of fixed points of a map `f : α → α`. -/ def fixed_points (f : α → α) : set α := {x : α | is_fixed_pt f x} instance fixed_points.decidable [decidable_eq α] (f : α → α) (x : α) : decidable (x ∈ fixed_points f) := is_fixed_pt.decidable @[simp] lemma mem_fixed_points : x ∈ fixed_points f ↔ is_fixed_pt f x := iff.rfl lemma mem_fixed_points_iff {α : Type*} {f : α → α} {x : α} : x ∈ fixed_points f ↔ f x = x := by refl @[simp] lemma fixed_points_id : fixed_points (@id α) = set.univ := set.ext $ λ _, by simpa using is_fixed_pt_id _ lemma fixed_points_subset_range : fixed_points f ⊆ set.range f := λ x hx, ⟨x, hx⟩ /-- If `g` semiconjugates `fa` to `fb`, then it sends fixed points of `fa` to fixed points of `fb`. -/ lemma semiconj.maps_to_fixed_pts {g : α → β} (h : semiconj g fa fb) : set.maps_to g (fixed_points fa) (fixed_points fb) := λ x hx, hx.map h /-- Any two maps `f : α → β` and `g : β → α` are inverse of each other on the sets of fixed points of `f ∘ g` and `g ∘ f`, respectively. -/ lemma inv_on_fixed_pts_comp (f : α → β) (g : β → α) : set.inv_on f g (fixed_points $ f ∘ g) (fixed_points $ g ∘ f) := ⟨λ x, id, λ x, id⟩ /-- Any map `f` sends fixed points of `g ∘ f` to fixed points of `f ∘ g`. -/ lemma maps_to_fixed_pts_comp (f : α → β) (g : β → α) : set.maps_to f (fixed_points $ g ∘ f) (fixed_points $ f ∘ g) := λ x hx, hx.map $ λ x, rfl /-- Given two maps `f : α → β` and `g : β → α`, `g` is a bijective map between the fixed points of `f ∘ g` and the fixed points of `g ∘ f`. The inverse map is `f`, see `inv_on_fixed_pts_comp`. -/ lemma bij_on_fixed_pts_comp (f : α → β) (g : β → α) : set.bij_on g (fixed_points $ f ∘ g) (fixed_points $ g ∘ f) := (inv_on_fixed_pts_comp f g).bij_on (maps_to_fixed_pts_comp g f) (maps_to_fixed_pts_comp f g) /-- If self-maps `f` and `g` commute, then they are inverse of each other on the set of fixed points of `f ∘ g`. This is a particular case of `function.inv_on_fixed_pts_comp`. -/ lemma commute.inv_on_fixed_pts_comp (h : commute f g) : set.inv_on f g (fixed_points $ f ∘ g) (fixed_points $ f ∘ g) := by simpa only [h.comp_eq] using inv_on_fixed_pts_comp f g /-- If self-maps `f` and `g` commute, then `f` is bijective on the set of fixed points of `f ∘ g`. This is a particular case of `function.bij_on_fixed_pts_comp`. -/ lemma commute.left_bij_on_fixed_pts_comp (h : commute f g) : set.bij_on f (fixed_points $ f ∘ g) (fixed_points $ f ∘ g) := by simpa only [h.comp_eq] using bij_on_fixed_pts_comp g f /-- If self-maps `f` and `g` commute, then `g` is bijective on the set of fixed points of `f ∘ g`. This is a particular case of `function.bij_on_fixed_pts_comp`. -/ lemma commute.right_bij_on_fixed_pts_comp (h : commute f g) : set.bij_on g (fixed_points $ f ∘ g) (fixed_points $ f ∘ g) := by simpa only [h.comp_eq] using bij_on_fixed_pts_comp f g end function
d969402989fa39352d0c7c5ef5b5c4a8f8bbe8d3
7cef822f3b952965621309e88eadf618da0c8ae9
/src/category_theory/limits/limits.lean
182a5ef204cda94b6b9dd942f6c4a030d82af634
[ "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
36,891
lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Scott Morrison, Floris van Doorn -/ import category_theory.whiskering import category_theory.yoneda import category_theory.limits.cones import category_theory.eq_to_hom open category_theory category_theory.category category_theory.functor opposite namespace category_theory.limits universes v u u' u'' w -- declare the `v`'s first; see `category_theory.category` for an explanation -- See the notes at the top of cones.lean, explaining why we can't allow `J : Prop` here. variables {J K : Type v} [small_category J] [small_category K] variables {C : Type u} [𝒞 : category.{v} C] include 𝒞 variables {F : J ⥤ C} /-- A cone `t` on `F` is a limit cone if each cone on `F` admits a unique cone morphism to `t`. -/ structure is_limit (t : cone F) := (lift : Π (s : cone F), s.X ⟶ t.X) (fac' : ∀ (s : cone F) (j : J), lift s ≫ t.π.app j = s.π.app j . obviously) (uniq' : ∀ (s : cone F) (m : s.X ⟶ t.X) (w : ∀ j : J, m ≫ t.π.app j = s.π.app j), m = lift s . obviously) restate_axiom is_limit.fac' attribute [simp] is_limit.fac restate_axiom is_limit.uniq' namespace is_limit instance subsingleton {t : cone F} : subsingleton (is_limit t) := ⟨by intros P Q; cases P; cases Q; congr; ext; solve_by_elim⟩ /- Repackaging the definition in terms of cone morphisms. -/ def lift_cone_morphism {t : cone F} (h : is_limit t) (s : cone F) : s ⟶ t := { hom := h.lift s } lemma uniq_cone_morphism {s t : cone F} (h : is_limit t) {f f' : s ⟶ t} : f = f' := have ∀ {g : s ⟶ t}, g = h.lift_cone_morphism s, by intro g; ext; exact h.uniq _ _ g.w, this.trans this.symm def mk_cone_morphism {t : cone F} (lift : Π (s : cone F), s ⟶ t) (uniq' : ∀ (s : cone F) (m : s ⟶ t), m = lift s) : is_limit t := { lift := λ s, (lift s).hom, uniq' := λ s m w, have cone_morphism.mk m w = lift s, by apply uniq', congr_arg cone_morphism.hom this } /-- Limit cones on `F` are unique up to isomorphism. -/ def unique_up_to_iso {s t : cone F} (P : is_limit s) (Q : is_limit t) : s ≅ t := { hom := Q.lift_cone_morphism s, inv := P.lift_cone_morphism t, hom_inv_id' := P.uniq_cone_morphism, inv_hom_id' := Q.uniq_cone_morphism } def of_iso_limit {r t : cone F} (P : is_limit r) (i : r ≅ t) : is_limit t := is_limit.mk_cone_morphism (λ s, P.lift_cone_morphism s ≫ i.hom) (λ s m, by rw ←i.comp_inv_eq; apply P.uniq_cone_morphism) variables {t : cone F} lemma hom_lift (h : is_limit t) {W : C} (m : W ⟶ t.X) : m = h.lift { X := W, π := { app := λ b, m ≫ t.π.app b } } := h.uniq { X := W, π := { app := λ b, m ≫ t.π.app b } } m (λ b, rfl) /-- Two morphisms into a limit are equal if their compositions with each cone morphism are equal. -/ lemma hom_ext (h : is_limit t) {W : C} {f f' : W ⟶ t.X} (w : ∀ j, f ≫ t.π.app j = f' ≫ t.π.app j) : f = f' := by rw [h.hom_lift f, h.hom_lift f']; congr; exact funext w /-- The universal property of a limit cone: a map `W ⟶ X` is the same as a cone on `F` with vertex `W`. -/ def hom_iso (h : is_limit t) (W : C) : (W ⟶ t.X) ≅ ((const J).obj W ⟶ F) := { hom := λ f, (t.extend f).π, inv := λ π, h.lift { X := W, π := π }, hom_inv_id' := by ext f; apply h.hom_ext; intro j; simp; dsimp; refl } @[simp] lemma hom_iso_hom (h : is_limit t) {W : C} (f : W ⟶ t.X) : (is_limit.hom_iso h W).hom f = (t.extend f).π := rfl /-- The limit of `F` represents the functor taking `W` to the set of cones on `F` with vertex `W`. -/ def nat_iso (h : is_limit t) : yoneda.obj t.X ≅ F.cones := nat_iso.of_components (λ W, is_limit.hom_iso h (unop W)) (by tidy). def hom_iso' (h : is_limit t) (W : C) : ((W ⟶ t.X) : Type v) ≅ { p : Π j, W ⟶ F.obj j // ∀ {j j'} (f : j ⟶ j'), p j ≫ F.map f = p j' } := h.hom_iso W ≪≫ { hom := λ π, ⟨λ j, π.app j, λ j j' f, by convert ←(π.naturality f).symm; apply id_comp⟩, inv := λ p, { app := λ j, p.1 j, naturality' := λ j j' f, begin dsimp, rw [id_comp], exact (p.2 f).symm end } } /-- If G : C → D is a faithful functor which sends t to a limit cone, then it suffices to check that the induced maps for the image of t can be lifted to maps of C. -/ def of_faithful {t : cone F} {D : Type u'} [category.{v} D] (G : C ⥤ D) [faithful G] (ht : is_limit (G.map_cone t)) (lift : Π (s : cone F), s.X ⟶ t.X) (h : ∀ s, G.map (lift s) = ht.lift (G.map_cone s)) : is_limit t := { lift := lift, fac' := λ s j, by apply G.injectivity; rw [G.map_comp, h]; apply ht.fac, uniq' := λ s m w, begin apply G.injectivity, rw h, refine ht.uniq (G.map_cone s) _ (λ j, _), convert ←congr_arg (λ f, G.map f) (w j), apply G.map_comp end } def iso_unique_cone_morphism {t : cone F} : is_limit t ≅ Π s, unique (s ⟶ t) := { hom := λ h s, { default := h.lift_cone_morphism s, uniq := λ _, h.uniq_cone_morphism }, inv := λ h, { lift := λ s, (h s).default.hom, uniq' := λ s f w, congr_arg cone_morphism.hom ((h s).uniq ⟨f, w⟩) } } namespace of_nat_iso variables {X : C} (h : yoneda.obj X ≅ F.cones) /-- If `F.cones` is represented by `X`, each morphism `f : Y ⟶ X` gives a cone with cone point `Y`. -/ def cone_of_hom {Y : C} (f : Y ⟶ X) : cone F := { X := Y, π := h.hom.app (op Y) f } /-- If `F.cones` is represented by `X`, each cone `s` gives a morphism `s.X ⟶ X`. -/ def hom_of_cone (s : cone F) : s.X ⟶ X := h.inv.app (op s.X) s.π @[simp] lemma cone_of_hom_of_cone (s : cone F) : cone_of_hom h (hom_of_cone h s) = s := begin dsimp [cone_of_hom, hom_of_cone], cases s, congr, dsimp, exact congr_fun (congr_fun (congr_arg nat_trans.app h.inv_hom_id) (op s_X)) s_π, end @[simp] lemma hom_of_cone_of_hom {Y : C} (f : Y ⟶ X) : hom_of_cone h (cone_of_hom h f) = f := congr_fun (congr_fun (congr_arg nat_trans.app h.hom_inv_id) (op Y)) f /-- If `F.cones` is represented by `X`, the cone corresponding to the identity morphism on `X` will be a limit cone. -/ def limit_cone : cone F := cone_of_hom h (𝟙 X) /-- If `F.cones` is represented by `X`, the cone corresponding to a morphism `f : Y ⟶ X` is the limit cone extended by `f`. -/ lemma cone_of_hom_fac {Y : C} (f : Y ⟶ X) : cone_of_hom h f = (limit_cone h).extend f := begin dsimp [cone_of_hom, limit_cone, cone.extend], congr, ext j, have t := congr_fun (h.hom.naturality f.op) (𝟙 X), dsimp at t, simp only [comp_id] at t, rw congr_fun (congr_arg nat_trans.app t) j, refl, end /-- If `F.cones` is represented by `X`, any cone is the extension of the limit cone by the corresponding morphism. -/ lemma cone_fac (s : cone F) : (limit_cone h).extend (hom_of_cone h s) = s := begin rw ←cone_of_hom_of_cone h s, conv_lhs { simp only [hom_of_cone_of_hom] }, apply (cone_of_hom_fac _ _).symm, end end of_nat_iso section open of_nat_iso /-- If `F.cones` is representable, then the cone corresponding to the identity morphism on the representing object is a limit cone. -/ def of_nat_iso {X : C} (h : yoneda.obj X ≅ F.cones) : is_limit (limit_cone h) := { lift := λ s, hom_of_cone h s, fac' := λ s j, begin have h := cone_fac h s, cases s, injection h with h₁ h₂, simp only [heq_iff_eq] at h₂, conv_rhs { rw ← h₂ }, refl, end, uniq' := λ s m w, begin rw ←hom_of_cone_of_hom h m, congr, rw cone_of_hom_fac, dsimp, cases s, congr, ext j, exact w j, end } end end is_limit /-- A cocone `t` on `F` is a colimit cocone if each cocone on `F` admits a unique cocone morphism from `t`. -/ structure is_colimit (t : cocone F) := (desc : Π (s : cocone F), t.X ⟶ s.X) (fac' : ∀ (s : cocone F) (j : J), t.ι.app j ≫ desc s = s.ι.app j . obviously) (uniq' : ∀ (s : cocone F) (m : t.X ⟶ s.X) (w : ∀ j : J, t.ι.app j ≫ m = s.ι.app j), m = desc s . obviously) restate_axiom is_colimit.fac' attribute [simp] is_colimit.fac restate_axiom is_colimit.uniq' namespace is_colimit instance subsingleton {t : cocone F} : subsingleton (is_colimit t) := ⟨by intros P Q; cases P; cases Q; congr; ext; solve_by_elim⟩ /- Repackaging the definition in terms of cone morphisms. -/ def desc_cocone_morphism {t : cocone F} (h : is_colimit t) (s : cocone F) : t ⟶ s := { hom := h.desc s } lemma uniq_cocone_morphism {s t : cocone F} (h : is_colimit t) {f f' : t ⟶ s} : f = f' := have ∀ {g : t ⟶ s}, g = h.desc_cocone_morphism s, by intro g; ext; exact h.uniq _ _ g.w, this.trans this.symm def mk_cocone_morphism {t : cocone F} (desc : Π (s : cocone F), t ⟶ s) (uniq' : ∀ (s : cocone F) (m : t ⟶ s), m = desc s) : is_colimit t := { desc := λ s, (desc s).hom, uniq' := λ s m w, have cocone_morphism.mk m w = desc s, by apply uniq', congr_arg cocone_morphism.hom this } /-- Limit cones on `F` are unique up to isomorphism. -/ def unique_up_to_iso {s t : cocone F} (P : is_colimit s) (Q : is_colimit t) : s ≅ t := { hom := P.desc_cocone_morphism t, inv := Q.desc_cocone_morphism s, hom_inv_id' := P.uniq_cocone_morphism, inv_hom_id' := Q.uniq_cocone_morphism } def of_iso_colimit {r t : cocone F} (P : is_colimit r) (i : r ≅ t) : is_colimit t := is_colimit.mk_cocone_morphism (λ s, i.inv ≫ P.desc_cocone_morphism s) (λ s m, by rw i.eq_inv_comp; apply P.uniq_cocone_morphism) variables {t : cocone F} lemma hom_desc (h : is_colimit t) {W : C} (m : t.X ⟶ W) : m = h.desc { X := W, ι := { app := λ b, t.ι.app b ≫ m, naturality' := by intros; erw [←assoc, t.ι.naturality, comp_id, comp_id] } } := h.uniq { X := W, ι := { app := λ b, t.ι.app b ≫ m, naturality' := _ } } m (λ b, rfl) /-- Two morphisms out of a colimit are equal if their compositions with each cocone morphism are equal. -/ lemma hom_ext (h : is_colimit t) {W : C} {f f' : t.X ⟶ W} (w : ∀ j, t.ι.app j ≫ f = t.ι.app j ≫ f') : f = f' := by rw [h.hom_desc f, h.hom_desc f']; congr; exact funext w /-- The universal property of a colimit cocone: a map `X ⟶ W` is the same as a cocone on `F` with vertex `W`. -/ def hom_iso (h : is_colimit t) (W : C) : (t.X ⟶ W) ≅ (F ⟶ (const J).obj W) := { hom := λ f, (t.extend f).ι, inv := λ ι, h.desc { X := W, ι := ι }, hom_inv_id' := by ext f; apply h.hom_ext; intro j; simp; dsimp; refl } @[simp] lemma hom_iso_hom (h : is_colimit t) {W : C} (f : t.X ⟶ W) : (is_colimit.hom_iso h W).hom f = (t.extend f).ι := rfl /-- The colimit of `F` represents the functor taking `W` to the set of cocones on `F` with vertex `W`. -/ def nat_iso (h : is_colimit t) : coyoneda.obj (op t.X) ≅ F.cocones := nat_iso.of_components (is_colimit.hom_iso h) (by intros; ext; dsimp; rw ←assoc; refl) def hom_iso' (h : is_colimit t) (W : C) : ((t.X ⟶ W) : Type v) ≅ { p : Π j, F.obj j ⟶ W // ∀ {j j' : J} (f : j ⟶ j'), F.map f ≫ p j' = p j } := h.hom_iso W ≪≫ { hom := λ ι, ⟨λ j, ι.app j, λ j j' f, by convert ←(ι.naturality f); apply comp_id⟩, inv := λ p, { app := λ j, p.1 j, naturality' := λ j j' f, begin dsimp, rw [comp_id], exact (p.2 f) end } } /-- If G : C → D is a faithful functor which sends t to a colimit cocone, then it suffices to check that the induced maps for the image of t can be lifted to maps of C. -/ def of_faithful {t : cocone F} {D : Type u'} [category.{v} D] (G : C ⥤ D) [faithful G] (ht : is_colimit (G.map_cocone t)) (desc : Π (s : cocone F), t.X ⟶ s.X) (h : ∀ s, G.map (desc s) = ht.desc (G.map_cocone s)) : is_colimit t := { desc := desc, fac' := λ s j, by apply G.injectivity; rw [G.map_comp, h]; apply ht.fac, uniq' := λ s m w, begin apply G.injectivity, rw h, refine ht.uniq (G.map_cocone s) _ (λ j, _), convert ←congr_arg (λ f, G.map f) (w j), apply G.map_comp end } def iso_unique_cocone_morphism {t : cocone F} : is_colimit t ≅ Π s, unique (t ⟶ s) := { hom := λ h s, { default := h.desc_cocone_morphism s, uniq := λ _, h.uniq_cocone_morphism }, inv := λ h, { desc := λ s, (h s).default.hom, uniq' := λ s f w, congr_arg cocone_morphism.hom ((h s).uniq ⟨f, w⟩) } } namespace of_nat_iso variables {X : C} (h : coyoneda.obj (op X) ≅ F.cocones) /-- If `F.cocones` is corepresented by `X`, each morphism `f : X ⟶ Y` gives a cocone with cone point `Y`. -/ def cocone_of_hom {Y : C} (f : X ⟶ Y) : cocone F := { X := Y, ι := h.hom.app Y f } /-- If `F.cocones` is corepresented by `X`, each cocone `s` gives a morphism `X ⟶ s.X`. -/ def hom_of_cocone (s : cocone F) : X ⟶ s.X := h.inv.app s.X s.ι @[simp] lemma cocone_of_hom_of_cocone (s : cocone F) : cocone_of_hom h (hom_of_cocone h s) = s := begin dsimp [cocone_of_hom, hom_of_cocone], cases s, congr, dsimp, exact congr_fun (congr_fun (congr_arg nat_trans.app h.inv_hom_id) s_X) s_ι, end @[simp] lemma hom_of_cocone_of_hom {Y : C} (f : X ⟶ Y) : hom_of_cocone h (cocone_of_hom h f) = f := congr_fun (congr_fun (congr_arg nat_trans.app h.hom_inv_id) Y) f /-- If `F.cocones` is corepresented by `X`, the cocone corresponding to the identity morphism on `X` will be a colimit cocone. -/ def colimit_cocone : cocone F := cocone_of_hom h (𝟙 X) /-- If `F.cocones` is corepresented by `X`, the cocone corresponding to a morphism `f : Y ⟶ X` is the colimit cocone extended by `f`. -/ lemma cocone_of_hom_fac {Y : C} (f : X ⟶ Y) : cocone_of_hom h f = (colimit_cocone h).extend f := begin dsimp [cocone_of_hom, colimit_cocone, cocone.extend], congr, ext j, have t := congr_fun (h.hom.naturality f) (𝟙 X), dsimp at t, simp only [id_comp] at t, rw congr_fun (congr_arg nat_trans.app t) j, refl, end /-- If `F.cocones` is corepresented by `X`, any cocone is the extension of the colimit cocone by the corresponding morphism. -/ lemma cocone_fac (s : cocone F) : (colimit_cocone h).extend (hom_of_cocone h s) = s := begin rw ←cocone_of_hom_of_cocone h s, conv_lhs { simp only [hom_of_cocone_of_hom] }, apply (cocone_of_hom_fac _ _).symm, end end of_nat_iso section open of_nat_iso /-- If `F.cocones` is corepresentable, then the cocone corresponding to the identity morphism on the representing object is a colimit cocone. -/ def of_nat_iso {X : C} (h : coyoneda.obj (op X) ≅ F.cocones) : is_colimit (colimit_cocone h) := { desc := λ s, hom_of_cocone h s, fac' := λ s j, begin have h := cocone_fac h s, cases s, injection h with h₁ h₂, simp only [heq_iff_eq] at h₂, conv_rhs { rw ← h₂ }, refl, end, uniq' := λ s m w, begin rw ←hom_of_cocone_of_hom h m, congr, rw cocone_of_hom_fac, dsimp, cases s, congr, ext j, exact w j, end } end end is_colimit section limit /-- `has_limit F` represents a particular chosen limit of the diagram `F`. -/ class has_limit (F : J ⥤ C) := (cone : cone F) (is_limit : is_limit cone . tactic.apply_instance) variables (J C) /-- `C` has limits of shape `J` if we have chosen a particular limit of every functor `F : J ⥤ C`. -/ class has_limits_of_shape := (has_limit : Π F : J ⥤ C, has_limit F) /-- `C` has all (small) limits if it has limits of every shape. -/ class has_limits := (has_limits_of_shape : Π (J : Type v) [𝒥 : small_category J], has_limits_of_shape J C) variables {J C} @[priority 100] -- see Note [lower instance priority] instance has_limit_of_has_limits_of_shape {J : Type v} [small_category J] [H : has_limits_of_shape J C] (F : J ⥤ C) : has_limit F := has_limits_of_shape.has_limit F @[priority 100] -- see Note [lower instance priority] instance has_limits_of_shape_of_has_limits {J : Type v} [small_category J] [H : has_limits.{v} C] : has_limits_of_shape J C := has_limits.has_limits_of_shape C J /- Interface to the `has_limit` class. -/ def limit.cone (F : J ⥤ C) [has_limit F] : cone F := has_limit.cone F def limit (F : J ⥤ C) [has_limit F] := (limit.cone F).X def limit.π (F : J ⥤ C) [has_limit F] (j : J) : limit F ⟶ F.obj j := (limit.cone F).π.app j @[simp] lemma limit.cone_π {F : J ⥤ C} [has_limit F] (j : J) : (limit.cone F).π.app j = limit.π _ j := rfl @[simp] lemma limit.w (F : J ⥤ C) [has_limit F] {j j' : J} (f : j ⟶ j') : limit.π F j ≫ F.map f = limit.π F j' := (limit.cone F).w f def limit.is_limit (F : J ⥤ C) [has_limit F] : is_limit (limit.cone F) := has_limit.is_limit.{v} F def limit.lift (F : J ⥤ C) [has_limit F] (c : cone F) : c.X ⟶ limit F := (limit.is_limit F).lift c @[simp] lemma limit.is_limit_lift {F : J ⥤ C} [has_limit F] (c : cone F) : (limit.is_limit F).lift c = limit.lift F c := rfl @[simp, reassoc] lemma limit.lift_π {F : J ⥤ C} [has_limit F] (c : cone F) (j : J) : limit.lift F c ≫ limit.π F j = c.π.app j := is_limit.fac _ c j def limit.cone_morphism {F : J ⥤ C} [has_limit F] (c : cone F) : cone_morphism c (limit.cone F) := (limit.is_limit F).lift_cone_morphism c @[simp] lemma limit.cone_morphism_hom {F : J ⥤ C} [has_limit F] (c : cone F) : (limit.cone_morphism c).hom = limit.lift F c := rfl @[simp] lemma limit.cone_morphism_π {F : J ⥤ C} [has_limit F] (c : cone F) (j : J) : (limit.cone_morphism c).hom ≫ limit.π F j = c.π.app j := by erw is_limit.fac @[ext] lemma limit.hom_ext {F : J ⥤ C} [has_limit F] {X : C} {f f' : X ⟶ limit F} (w : ∀ j, f ≫ limit.π F j = f' ≫ limit.π F j) : f = f' := (limit.is_limit F).hom_ext w def limit.hom_iso (F : J ⥤ C) [has_limit F] (W : C) : (W ⟶ limit F) ≅ (F.cones.obj (op W)) := (limit.is_limit F).hom_iso W @[simp] lemma limit.hom_iso_hom (F : J ⥤ C) [has_limit F] {W : C} (f : W ⟶ limit F) : (limit.hom_iso F W).hom f = (const J).map f ≫ (limit.cone F).π := (limit.is_limit F).hom_iso_hom f def limit.hom_iso' (F : J ⥤ C) [has_limit F] (W : C) : ((W ⟶ limit F) : Type v) ≅ { p : Π j, W ⟶ F.obj j // ∀ {j j' : J} (f : j ⟶ j'), p j ≫ F.map f = p j' } := (limit.is_limit F).hom_iso' W lemma limit.lift_extend {F : J ⥤ C} [has_limit F] (c : cone F) {X : C} (f : X ⟶ c.X) : limit.lift F (c.extend f) = f ≫ limit.lift F c := by obviously def has_limit_of_iso {F G : J ⥤ C} [has_limit F] (α : F ≅ G) : has_limit G := { cone := (cones.postcompose α.hom).obj (limit.cone F), is_limit := { lift := λ s, limit.lift F ((cones.postcompose α.inv).obj s), fac' := λ s j, begin rw [cones.postcompose_obj_π, nat_trans.comp_app, limit.cone_π, ←category.assoc, limit.lift_π], simp end, uniq' := λ s m w, begin apply limit.hom_ext, intro j, rw [limit.lift_π, cones.postcompose_obj_π, nat_trans.comp_app, ←nat_iso.app_inv, iso.eq_comp_inv], simpa using w j end } } /-- If a functor `G` has the same collection of cones as a functor `F` which has a limit, then `G` also has a limit. -/ -- See the construction of limits from products and equalizers -- for an example usage. def has_limit.of_cones_iso {J K : Type v} [small_category J] [small_category K] (F : J ⥤ C) (G : K ⥤ C) (h : F.cones ≅ G.cones) [has_limit F] : has_limit G := ⟨_, is_limit.of_nat_iso ((is_limit.nat_iso (limit.is_limit F)) ≪≫ h)⟩ section pre variables (F) [has_limit F] (E : K ⥤ J) [has_limit (E ⋙ F)] def limit.pre : limit F ⟶ limit (E ⋙ F) := limit.lift (E ⋙ F) { X := limit F, π := { app := λ k, limit.π F (E.obj k) } } @[simp] lemma limit.pre_π (k : K) : limit.pre F E ≫ limit.π (E ⋙ F) k = limit.π F (E.obj k) := by erw is_limit.fac @[simp] lemma limit.lift_pre (c : cone F) : limit.lift F c ≫ limit.pre F E = limit.lift (E ⋙ F) (c.whisker E) := by ext; simp variables {L : Type v} [small_category L] variables (D : L ⥤ K) [has_limit (D ⋙ E ⋙ F)] @[simp] lemma limit.pre_pre : limit.pre F E ≫ limit.pre (E ⋙ F) D = limit.pre F (D ⋙ E) := by ext j; erw [assoc, limit.pre_π, limit.pre_π, limit.pre_π]; refl end pre section post variables {D : Type u'} [𝒟 : category.{v} D] include 𝒟 variables (F) [has_limit F] (G : C ⥤ D) [has_limit (F ⋙ G)] def limit.post : G.obj (limit F) ⟶ limit (F ⋙ G) := limit.lift (F ⋙ G) { X := G.obj (limit F), π := { app := λ j, G.map (limit.π F j), naturality' := by intros j j' f; erw [←G.map_comp, limits.cone.w, id_comp]; refl } } @[simp] lemma limit.post_π (j : J) : limit.post F G ≫ limit.π (F ⋙ G) j = G.map (limit.π F j) := by erw is_limit.fac @[simp] lemma limit.lift_post (c : cone F) : G.map (limit.lift F c) ≫ limit.post F G = limit.lift (F ⋙ G) (G.map_cone c) := by ext; rw [assoc, limit.post_π, ←G.map_comp, limit.lift_π, limit.lift_π]; refl @[simp] lemma limit.post_post {E : Type u''} [category.{v} E] (H : D ⥤ E) [has_limit ((F ⋙ G) ⋙ H)] : /- H G (limit F) ⟶ H (limit (F ⋙ G)) ⟶ limit ((F ⋙ G) ⋙ H) equals -/ /- H G (limit F) ⟶ limit (F ⋙ (G ⋙ H)) -/ H.map (limit.post F G) ≫ limit.post (F ⋙ G) H = limit.post F (G ⋙ H) := by ext; erw [assoc, limit.post_π, ←H.map_comp, limit.post_π, limit.post_π]; refl end post lemma limit.pre_post {D : Type u'} [category.{v} D] (E : K ⥤ J) (F : J ⥤ C) (G : C ⥤ D) [has_limit F] [has_limit (E ⋙ F)] [has_limit (F ⋙ G)] [has_limit ((E ⋙ F) ⋙ G)] : /- G (limit F) ⟶ G (limit (E ⋙ F)) ⟶ limit ((E ⋙ F) ⋙ G) vs -/ /- G (limit F) ⟶ limit F ⋙ G ⟶ limit (E ⋙ (F ⋙ G)) or -/ G.map (limit.pre F E) ≫ limit.post (E ⋙ F) G = limit.post F G ≫ limit.pre (F ⋙ G) E := by ext; erw [assoc, limit.post_π, ←G.map_comp, limit.pre_π, assoc, limit.pre_π, limit.post_π]; refl open category_theory.equivalence instance has_limit_equivalence_comp (e : K ≌ J) [has_limit F] : has_limit (e.functor ⋙ F) := { cone := cone.whisker e.functor (limit.cone F), is_limit := let e' := cones.postcompose (e.inv_fun_id_assoc F).hom in { lift := λ s, limit.lift F (e'.obj (cone.whisker e.inverse s)), fac' := λ s j, begin dsimp, rw [limit.lift_π], dsimp [e'], erw [inv_fun_id_assoc_hom_app, counit_functor, ←s.π.naturality, id_comp] end, uniq' := λ s m w, begin apply limit.hom_ext, intro j, erw [limit.lift_π, ←limit.w F (e.counit_iso.hom.app j)], slice_lhs 1 2 { erw [w (e.inverse.obj j)] }, simp end } } local attribute [elab_simple] inv_fun_id_assoc -- not entirely sure why this is needed def has_limit_of_equivalence_comp (e : K ≌ J) [has_limit (e.functor ⋙ F)] : has_limit F := begin haveI : has_limit (e.inverse ⋙ e.functor ⋙ F) := limits.has_limit_equivalence_comp e.symm, apply has_limit_of_iso (e.inv_fun_id_assoc F), end -- `has_limit_comp_equivalence` and `has_limit_of_comp_equivalence` -- are proved in `category_theory/adjunction/limits.lean`. section lim_functor variables [has_limits_of_shape J C] /-- `limit F` is functorial in `F`, when `C` has all limits of shape `J`. -/ def lim : (J ⥤ C) ⥤ C := { obj := λ F, limit F, map := λ F G α, limit.lift G { X := limit F, π := { app := λ j, limit.π F j ≫ α.app j, naturality' := λ j j' f, by erw [id_comp, assoc, ←α.naturality, ←assoc, limit.w] } }, map_comp' := λ F G H α β, by ext; erw [assoc, is_limit.fac, is_limit.fac, ←assoc, is_limit.fac, assoc]; refl } variables {F} {G : J ⥤ C} (α : F ⟶ G) @[simp, reassoc] lemma lim.map_π (j : J) : lim.map α ≫ limit.π G j = limit.π F j ≫ α.app j := by apply is_limit.fac @[simp] lemma limit.lift_map (c : cone F) : limit.lift F c ≫ lim.map α = limit.lift G ((cones.postcompose α).obj c) := by ext; rw [assoc, lim.map_π, ←assoc, limit.lift_π, limit.lift_π]; refl lemma limit.map_pre [has_limits_of_shape K C] (E : K ⥤ J) : lim.map α ≫ limit.pre G E = limit.pre F E ≫ lim.map (whisker_left E α) := by ext; rw [assoc, limit.pre_π, lim.map_π, assoc, lim.map_π, ←assoc, limit.pre_π]; refl lemma limit.map_pre' [has_limits_of_shape.{v} K C] (F : J ⥤ C) {E₁ E₂ : K ⥤ J} (α : E₁ ⟶ E₂) : limit.pre F E₂ = limit.pre F E₁ ≫ lim.map (whisker_right α F) := by ext1; simp [(category.assoc _ _ _ _).symm] lemma limit.id_pre (F : J ⥤ C) : limit.pre F (𝟭 _) = lim.map (functor.left_unitor F).inv := by tidy lemma limit.map_post {D : Type u'} [category.{v} D] [has_limits_of_shape J D] (H : C ⥤ D) : /- H (limit F) ⟶ H (limit G) ⟶ limit (G ⋙ H) vs H (limit F) ⟶ limit (F ⋙ H) ⟶ limit (G ⋙ H) -/ H.map (lim.map α) ≫ limit.post G H = limit.post F H ≫ lim.map (whisker_right α H) := begin ext, rw [assoc, limit.post_π, ←H.map_comp, lim.map_π, H.map_comp], rw [assoc, lim.map_π, ←assoc, limit.post_π], refl end def lim_yoneda : lim ⋙ yoneda ≅ category_theory.cones J C := nat_iso.of_components (λ F, nat_iso.of_components (λ W, limit.hom_iso F (unop W)) (by tidy)) (by tidy) end lim_functor def has_limits_of_shape_of_equivalence {J' : Type v} [small_category J'] (e : J ≌ J') [has_limits_of_shape J C] : has_limits_of_shape J' C := by { constructor, intro F, apply has_limit_of_equivalence_comp e, apply_instance } end limit section colimit /-- `has_colimit F` represents a particular chosen colimit of the diagram `F`. -/ class has_colimit (F : J ⥤ C) := (cocone : cocone F) (is_colimit : is_colimit cocone . tactic.apply_instance) variables (J C) /-- `C` has colimits of shape `J` if we have chosen a particular colimit of every functor `F : J ⥤ C`. -/ class has_colimits_of_shape := (has_colimit : Π F : J ⥤ C, has_colimit F) /-- `C` has all (small) colimits if it has colimits of every shape. -/ class has_colimits := (has_colimits_of_shape : Π (J : Type v) [𝒥 : small_category J], has_colimits_of_shape J C) variables {J C} @[priority 100] -- see Note [lower instance priority] instance has_colimit_of_has_colimits_of_shape {J : Type v} [small_category J] [H : has_colimits_of_shape J C] (F : J ⥤ C) : has_colimit F := has_colimits_of_shape.has_colimit F @[priority 100] -- see Note [lower instance priority] instance has_colimits_of_shape_of_has_colimits {J : Type v} [small_category J] [H : has_colimits.{v} C] : has_colimits_of_shape J C := has_colimits.has_colimits_of_shape C J /- Interface to the `has_colimit` class. -/ def colimit.cocone (F : J ⥤ C) [has_colimit F] : cocone F := has_colimit.cocone F def colimit (F : J ⥤ C) [has_colimit F] := (colimit.cocone F).X def colimit.ι (F : J ⥤ C) [has_colimit F] (j : J) : F.obj j ⟶ colimit F := (colimit.cocone F).ι.app j @[simp] lemma colimit.cocone_ι {F : J ⥤ C} [has_colimit F] (j : J) : (colimit.cocone F).ι.app j = colimit.ι _ j := rfl @[simp] lemma colimit.w (F : J ⥤ C) [has_colimit F] {j j' : J} (f : j ⟶ j') : F.map f ≫ colimit.ι F j' = colimit.ι F j := (colimit.cocone F).w f def colimit.is_colimit (F : J ⥤ C) [has_colimit F] : is_colimit (colimit.cocone F) := has_colimit.is_colimit.{v} F def colimit.desc (F : J ⥤ C) [has_colimit F] (c : cocone F) : colimit F ⟶ c.X := (colimit.is_colimit F).desc c @[simp] lemma colimit.is_colimit_desc {F : J ⥤ C} [has_colimit F] (c : cocone F) : (colimit.is_colimit F).desc c = colimit.desc F c := rfl /-- We have lots of lemmas describing how to simplify `colimit.ι F j ≫ _`, and combined with `colimit.ext` we rely on these lemmas for many calculations. However, since `category.assoc` is a `@[simp]` lemma, often expressions are right associated, and it's hard to apply these lemmas about `colimit.ι`. We thus use `reassoc` to define additional `@[simp]` lemmas, with an arbitrary extra morphism. (see `tactic/reassoc_axiom.lean`) -/ @[simp, reassoc] lemma colimit.ι_desc {F : J ⥤ C} [has_colimit F] (c : cocone F) (j : J) : colimit.ι F j ≫ colimit.desc F c = c.ι.app j := is_colimit.fac _ c j def colimit.cocone_morphism {F : J ⥤ C} [has_colimit F] (c : cocone F) : cocone_morphism (colimit.cocone F) c := (colimit.is_colimit F).desc_cocone_morphism c @[simp] lemma colimit.cocone_morphism_hom {F : J ⥤ C} [has_colimit F] (c : cocone F) : (colimit.cocone_morphism c).hom = colimit.desc F c := rfl @[simp] lemma colimit.ι_cocone_morphism {F : J ⥤ C} [has_colimit F] (c : cocone F) (j : J) : colimit.ι F j ≫ (colimit.cocone_morphism c).hom = c.ι.app j := by erw is_colimit.fac @[ext] lemma colimit.hom_ext {F : J ⥤ C} [has_colimit F] {X : C} {f f' : colimit F ⟶ X} (w : ∀ j, colimit.ι F j ≫ f = colimit.ι F j ≫ f') : f = f' := (colimit.is_colimit F).hom_ext w def colimit.hom_iso (F : J ⥤ C) [has_colimit F] (W : C) : (colimit F ⟶ W) ≅ (F.cocones.obj W) := (colimit.is_colimit F).hom_iso W @[simp] lemma colimit.hom_iso_hom (F : J ⥤ C) [has_colimit F] {W : C} (f : colimit F ⟶ W) : (colimit.hom_iso F W).hom f = (colimit.cocone F).ι ≫ (const J).map f := (colimit.is_colimit F).hom_iso_hom f def colimit.hom_iso' (F : J ⥤ C) [has_colimit F] (W : C) : ((colimit F ⟶ W) : Type v) ≅ { p : Π j, F.obj j ⟶ W // ∀ {j j'} (f : j ⟶ j'), F.map f ≫ p j' = p j } := (colimit.is_colimit F).hom_iso' W lemma colimit.desc_extend (F : J ⥤ C) [has_colimit F] (c : cocone F) {X : C} (f : c.X ⟶ X) : colimit.desc F (c.extend f) = colimit.desc F c ≫ f := begin ext1, rw [←category.assoc], simp end def has_colimit_of_iso {F G : J ⥤ C} [has_colimit F] (α : G ≅ F) : has_colimit G := { cocone := (cocones.precompose α.hom).obj (colimit.cocone F), is_colimit := { desc := λ s, colimit.desc F ((cocones.precompose α.inv).obj s), fac' := λ s j, begin rw [cocones.precompose_obj_ι, nat_trans.comp_app, colimit.cocone_ι], rw [category.assoc, colimit.ι_desc, ←nat_iso.app_hom, ←iso.eq_inv_comp], refl end, uniq' := λ s m w, begin apply colimit.hom_ext, intro j, rw [colimit.ι_desc, cocones.precompose_obj_ι, nat_trans.comp_app, ←nat_iso.app_inv, iso.eq_inv_comp], simpa using w j end } } /-- If a functor `G` has the same collection of cocones as a functor `F` which has a colimit, then `G` also has a colimit. -/ def has_colimit.of_cocones_iso {J K : Type v} [small_category J] [small_category K] (F : J ⥤ C) (G : K ⥤ C) (h : F.cocones ≅ G.cocones) [has_colimit F] : has_colimit G := ⟨_, is_colimit.of_nat_iso ((is_colimit.nat_iso (colimit.is_colimit F)) ≪≫ h)⟩ section pre variables (F) [has_colimit F] (E : K ⥤ J) [has_colimit (E ⋙ F)] def colimit.pre : colimit (E ⋙ F) ⟶ colimit F := colimit.desc (E ⋙ F) { X := colimit F, ι := { app := λ k, colimit.ι F (E.obj k) } } @[simp, reassoc] lemma colimit.ι_pre (k : K) : colimit.ι (E ⋙ F) k ≫ colimit.pre F E = colimit.ι F (E.obj k) := by erw is_colimit.fac @[simp] lemma colimit.pre_desc (c : cocone F) : colimit.pre F E ≫ colimit.desc F c = colimit.desc (E ⋙ F) (c.whisker E) := by ext; rw [←assoc, colimit.ι_pre]; simp variables {L : Type v} [small_category L] variables (D : L ⥤ K) [has_colimit (D ⋙ E ⋙ F)] @[simp] lemma colimit.pre_pre : colimit.pre (E ⋙ F) D ≫ colimit.pre F E = colimit.pre F (D ⋙ E) := begin ext j, rw [←assoc, colimit.ι_pre, colimit.ι_pre], letI : has_colimit ((D ⋙ E) ⋙ F) := show has_colimit (D ⋙ E ⋙ F), by apply_instance, exact (colimit.ι_pre F (D ⋙ E) j).symm end end pre section post variables {D : Type u'} [𝒟 : category.{v} D] include 𝒟 variables (F) [has_colimit F] (G : C ⥤ D) [has_colimit (F ⋙ G)] def colimit.post : colimit (F ⋙ G) ⟶ G.obj (colimit F) := colimit.desc (F ⋙ G) { X := G.obj (colimit F), ι := { app := λ j, G.map (colimit.ι F j), naturality' := by intros j j' f; erw [←G.map_comp, limits.cocone.w, comp_id]; refl } } @[simp, reassoc] lemma colimit.ι_post (j : J) : colimit.ι (F ⋙ G) j ≫ colimit.post F G = G.map (colimit.ι F j) := by erw is_colimit.fac @[simp] lemma colimit.post_desc (c : cocone F) : colimit.post F G ≫ G.map (colimit.desc F c) = colimit.desc (F ⋙ G) (G.map_cocone c) := by ext; rw [←assoc, colimit.ι_post, ←G.map_comp, colimit.ι_desc, colimit.ι_desc]; refl @[simp] lemma colimit.post_post {E : Type u''} [category.{v} E] (H : D ⥤ E) [has_colimit ((F ⋙ G) ⋙ H)] : /- H G (colimit F) ⟶ H (colimit (F ⋙ G)) ⟶ colimit ((F ⋙ G) ⋙ H) equals -/ /- H G (colimit F) ⟶ colimit (F ⋙ (G ⋙ H)) -/ colimit.post (F ⋙ G) H ≫ H.map (colimit.post F G) = colimit.post F (G ⋙ H) := begin ext, rw [←assoc, colimit.ι_post, ←H.map_comp, colimit.ι_post], exact (colimit.ι_post F (G ⋙ H) j).symm end end post lemma colimit.pre_post {D : Type u'} [category.{v} D] (E : K ⥤ J) (F : J ⥤ C) (G : C ⥤ D) [has_colimit F] [has_colimit (E ⋙ F)] [has_colimit (F ⋙ G)] [has_colimit ((E ⋙ F) ⋙ G)] : /- G (colimit F) ⟶ G (colimit (E ⋙ F)) ⟶ colimit ((E ⋙ F) ⋙ G) vs -/ /- G (colimit F) ⟶ colimit F ⋙ G ⟶ colimit (E ⋙ (F ⋙ G)) or -/ colimit.post (E ⋙ F) G ≫ G.map (colimit.pre F E) = colimit.pre (F ⋙ G) E ≫ colimit.post F G := begin ext, rw [←assoc, colimit.ι_post, ←G.map_comp, colimit.ι_pre, ←assoc], letI : has_colimit (E ⋙ F ⋙ G) := show has_colimit ((E ⋙ F) ⋙ G), by apply_instance, erw [colimit.ι_pre (F ⋙ G) E j, colimit.ι_post] end open category_theory.equivalence instance has_colimit_equivalence_comp (e : K ≌ J) [has_colimit F] : has_colimit (e.functor ⋙ F) := { cocone := cocone.whisker e.functor (colimit.cocone F), is_colimit := let e' := cocones.precompose (e.inv_fun_id_assoc F).inv in { desc := λ s, colimit.desc F (e'.obj (cocone.whisker e.inverse s)), fac' := λ s j, begin dsimp, rw [colimit.ι_desc], dsimp [e'], erw [inv_fun_id_assoc_inv_app, ←functor_unit, s.ι.naturality, comp_id], refl end, uniq' := λ s m w, begin apply colimit.hom_ext, intro j, erw [colimit.ι_desc], have := w (e.inverse.obj j), simp at this, erw [←colimit.w F (e.counit_iso.hom.app j)] at this, erw [assoc, ←iso.eq_inv_comp (F.map_iso $ e.counit_iso.app j)] at this, erw [this], simp end } } def has_colimit_of_equivalence_comp (e : K ≌ J) [has_colimit (e.functor ⋙ F)] : has_colimit F := begin haveI : has_colimit (e.inverse ⋙ e.functor ⋙ F) := limits.has_colimit_equivalence_comp e.symm, apply has_colimit_of_iso (e.inv_fun_id_assoc F).symm, end section colim_functor variables [has_colimits_of_shape J C] /-- `colimit F` is functorial in `F`, when `C` has all colimits of shape `J`. -/ def colim : (J ⥤ C) ⥤ C := { obj := λ F, colimit F, map := λ F G α, colimit.desc F { X := colimit G, ι := { app := λ j, α.app j ≫ colimit.ι G j, naturality' := λ j j' f, by erw [comp_id, ←assoc, α.naturality, assoc, colimit.w] } }, map_comp' := λ F G H α β, by ext; erw [←assoc, is_colimit.fac, is_colimit.fac, assoc, is_colimit.fac, ←assoc]; refl } variables {F} {G : J ⥤ C} (α : F ⟶ G) @[simp, reassoc] lemma colim.ι_map (j : J) : colimit.ι F j ≫ colim.map α = α.app j ≫ colimit.ι G j := by apply is_colimit.fac @[simp] lemma colimit.map_desc (c : cocone G) : colim.map α ≫ colimit.desc G c = colimit.desc F ((cocones.precompose α).obj c) := by ext; rw [←assoc, colim.ι_map, assoc, colimit.ι_desc, colimit.ι_desc]; refl lemma colimit.pre_map [has_colimits_of_shape K C] (E : K ⥤ J) : colimit.pre F E ≫ colim.map α = colim.map (whisker_left E α) ≫ colimit.pre G E := by ext; rw [←assoc, colimit.ι_pre, colim.ι_map, ←assoc, colim.ι_map, assoc, colimit.ι_pre]; refl lemma colimit.pre_map' [has_colimits_of_shape.{v} K C] (F : J ⥤ C) {E₁ E₂ : K ⥤ J} (α : E₁ ⟶ E₂) : colimit.pre F E₁ = colim.map (whisker_right α F) ≫ colimit.pre F E₂ := by ext1; simp [(category.assoc _ _ _ _).symm] lemma colimit.pre_id (F : J ⥤ C) : colimit.pre F (𝟭 _) = colim.map (functor.left_unitor F).hom := by tidy lemma colimit.map_post {D : Type u'} [category.{v} D] [has_colimits_of_shape J D] (H : C ⥤ D) : /- H (colimit F) ⟶ H (colimit G) ⟶ colimit (G ⋙ H) vs H (colimit F) ⟶ colimit (F ⋙ H) ⟶ colimit (G ⋙ H) -/ colimit.post F H ≫ H.map (colim.map α) = colim.map (whisker_right α H) ≫ colimit.post G H:= begin ext, rw [←assoc, colimit.ι_post, ←H.map_comp, colim.ι_map, H.map_comp], rw [←assoc, colim.ι_map, assoc, colimit.ι_post], refl end def colim_coyoneda : colim.op ⋙ coyoneda ≅ category_theory.cocones J C := nat_iso.of_components (λ F, nat_iso.of_components (colimit.hom_iso (unop F)) (by tidy)) (by tidy) end colim_functor def has_colimits_of_shape_of_equivalence {J' : Type v} [small_category J'] (e : J ≌ J') [has_colimits_of_shape J C] : has_colimits_of_shape J' C := by { constructor, intro F, apply has_colimit_of_equivalence_comp e, apply_instance } end colimit end category_theory.limits
6785a8411b7aff226f1517d1180fc87f2a80c3b7
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/Lean3Lib/init/data/sum/instances.lean
e8f746bf2a16c7ce77b227df22a4a422075e74ca
[]
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
985
lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.meta.mk_dec_eq_instance universes u v namespace Mathlib protected instance sum.decidable_eq {α : Type u} {β : Type v} [DecidableEq α] [DecidableEq β] : DecidableEq (α ⊕ β) := id fun (_v : α ⊕ β) => sum.cases_on _v (fun (val : α) (w : α ⊕ β) => sum.cases_on w (fun (w : α) => decidable.by_cases (fun (ᾰ : val = w) => Eq._oldrec (is_true sorry) ᾰ) fun (ᾰ : ¬val = w) => isFalse sorry) fun (w : β) => isFalse sorry) fun (val : β) (w : α ⊕ β) => sum.cases_on w (fun (w : α) => isFalse sorry) fun (w : β) => decidable.by_cases (fun (ᾰ : val = w) => Eq._oldrec (is_true sorry) ᾰ) fun (ᾰ : ¬val = w) => isFalse sorry
43340c6072455e4114a8eae343cedde5e8558ca1
aa3f8992ef7806974bc1ffd468baa0c79f4d6643
/tests/lean/run/class_coe.lean
52151aa59d0c88a86590870d5034ed4ed1175612
[ "Apache-2.0" ]
permissive
codyroux/lean
7f8dff750722c5382bdd0a9a9275dc4bb2c58dd3
0cca265db19f7296531e339192e9b9bae4a31f8b
refs/heads/master
1,610,909,964,159
1,407,084,399,000
1,416,857,075,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
1,299
lean
import data.num constants int nat real : Type.{1} constant nat_add : nat → nat → nat constant int_add : int → int → int constant real_add : real → real → real inductive add_struct [class] (A : Type) := mk : (A → A → A) → add_struct A definition add {A : Type} {S : add_struct A} (a b : A) : A := add_struct.rec (λ m, m) S a b infixl `+` := add definition add_nat_struct [instance] : add_struct nat := add_struct.mk nat_add definition add_int_struct [instance] : add_struct int := add_struct.mk int_add definition add_real_struct [instance] : add_struct real := add_struct.mk real_add constants n m : nat constants i j : int constants x y : real constant num_to_nat : num → nat constant nat_to_int : nat → int constant int_to_real : int → real coercion num_to_nat coercion nat_to_int coercion int_to_real set_option pp.implicit true set_option pp.coercions true check n + m check i + j check x + y check i + n check i + x check n + i check x + i check n + x check x + n check x + i + n check n + 0 check 0 + n check 0 + i check i + 0 check 0 + x check x + 0 namespace foo constant eq {A : Type} : A → A → Prop infixl `=` := eq definition id (A : Type) (a : A) := a notation A `=` B `:` C := @eq C A B check nat_to_int n + nat_to_int m = (n + m) : int end foo